// https://civicrm.org/licensing (function($, _) { "use strict"; /* jshint validthis: true */ var icons = [], loaded; $.fn.crmIconPicker = function() { function loadIcons() { if (!loaded) { loaded = $.Deferred(); CRM.$.get(CRM.config.resourceBase + 'bower_components/font-awesome/css/font-awesome.css').done(function(data) { var match, regex = /\.(fa-[-a-zA-Z0-9]+):before {/g; while((match = regex.exec(data)) !== null) { icons.push(match[1]); } loaded.resolve(); }); } return loaded; } return this.each(function() { if ($(this).hasClass('iconpicker-widget')) { return; } var $input = $(this), classes = ($input.attr('class') || '').replace('crm-icon-picker', ''), $button = $('').button().removeClass('ui-corner-all').attr('title', $input.attr('title')), $style = $('').addClass(classes), options = [ {key: 'fa-rotate-90', value: ts('Rotate right')}, {key: 'fa-rotate-270', value: ts('Rotate left')}, {key: 'fa-rotate-180', value: ts('Rotate 180')}, {key: 'fa-flip-horizontal', value: ts('Flip horizontal')}, {key: 'fa-flip-vertical', value: ts('Flip vertical')} ]; function formatButton() { var val = $input.val().replace('fa ', ''); val = val.replace('crm-i ', ''); var split = val.split(' '); $button.button('option', { label: split[0] || ts('None'), icons: {primary: val ? val : 'fa-'} }); $style.toggle(!!split[0]).val(split[1] || ''); } $input.hide().addClass('iconpicker-widget').after($style).after(' ').after($button).change(formatButton); CRM.utils.setOptions($style, options, ts('Normal')); formatButton(); $style.change(function() { if ($input.val()) { var split = $input.val().split(' '), style = $style.val(); $input.val(split[0] + (style ? ' ' + style : '')).change(); } }); $button.click(function(e) { var dialog; function displayIcons() { var term = $('input[name=search]', dialog).val().replace(/-/g, '').toLowerCase(), $place = $('div.icons', dialog).html(''); $.each(icons, function(i, icon) { if (!term.length || icon.replace(/-/g, '').indexOf(term) > -1) { var item = $('').button({ icons: {primary: icon + ' ' + $style.val()} }); $place.append(item); } }); } function displayDialog() { dialog.append('' + '