1 // https://civicrm.org/licensing
4 /* jshint validthis: true */
6 var configRowTpl
= _
.template($('#config-row-tpl').html()),
9 // Weird conflict with drupal styles
10 $('body').removeClass('toolbar');
12 function format(item
) {
13 var icon
= '<span class="ui-icon ui-icon-gear"></span>';
15 icon
= '<img src="' + CRM
.config
.resourceBase
+ item
.icon
+ '" />';
17 return icon
+ ' ' + item
.text
;
20 function initOptions(data
) {
21 options
= _
.filter(data
, function(n
) {
22 return $.inArray(n
.id
, CRM
.vars
.ckConfig
.blacklist
) < 0;
25 $.each(CRM
.vars
.ckConfig
.settings
, function(key
, val
) {
26 if ($.inArray(key
, CRM
.vars
.ckConfig
.blacklist
) < 0) {
27 var $opt
= $('.crm-config-option-row:last input.crm-config-option-name');
28 $opt
.val(key
).change();
29 $opt
.siblings('span').find(':input').val(val
);
34 function changeOptionName() {
37 $el
.next('span').remove();
39 if (($('input.crm-config-option-name').filter(function() {return !this.value
;})).length
< 1) {
42 var type
= $el
.select2('data').type
;
43 if (type
=== 'Boolean') {
44 $el
.after('<span> = <select class="crm-form-select" name="config_' + name
+ '"><option value="false">false</option><option value="true">true</option></select></span>');
47 $el
.after('<span> = <input class="crm-form-text ' + (type
==='Number' ? 'eight" type="number"' : 'huge" type="text"') + ' name="config_' + name
+ '"/></span>');
48 $el
.next('span').find('input.crm-form-text[type=text]').change(validateJson
);
51 $el
.closest('div').remove();
55 function getOptionList() {
57 _
.forEach(options
, function(option
) {
58 var opt
= _
.cloneDeep(option
);
59 if ($('[name="config_' + opt
.id
+ '"]').length
) {
64 return {results
: list
, text
: 'id'};
67 function validateJson() {
68 // TODO: strict json isn't required so we can't use JSON.parse for error checking. Need something like angular.eval.
71 function addOption() {
72 $('#crm-custom-config-options').append($(configRowTpl({})));
73 $('.crm-config-option-row:last input.crm-config-option-name', '#crm-custom-config-options').crmSelect2({
75 formatSelection: function(field
) {
76 return '<strong>' + field
.id
+ '</strong> (' + field
.type
+ ')';
78 formatResult: function(field
) {
79 return '<strong>' + field
.id
+ '</strong> (' + field
.type
+ ')' +
80 '<div class="api-field-desc">' + field
.description
+ '</div>';
85 $('#extraPlugins').crmSelect2({
88 data
: CRM
.vars
.ckConfig
.plugins
,
89 escapeMarkup
: _
.identity
,
91 formatSelection
: format
94 var toolbarModifier
= new ToolbarConfigurator
.ToolbarModifier( 'editor-basic' );
96 toolbarModifier
.init(_
.noop
);
98 CKEDITOR
.document
.getById( 'toolbarModifierWrapper' ).append( toolbarModifier
.mainContainer
);
101 var selectorOpen
= false,
102 changedWhileOpen
= false;
105 .on('submit', function(e
) {
106 $('.toolbar button:last', '#toolbarModifierWrapper')[0].click();
107 $('.configContainer textarea', '#toolbarModifierWrapper').attr('name', 'config');
109 .on('change', '.config-param', function(e
) {
110 changedWhileOpen
= true;
112 $('#_qf_CKEditorConfig_submit-bottom').click();
113 $('#CKEditorConfig').block();
116 .on('change', 'input.crm-config-option-name', changeOptionName
)
117 // Debounce the change event so it only fires after the multiselect is closed
118 .on('select2-open', 'input.config-param', function(e
) {
120 changedWhileOpen
= false;
122 .on('select2-close', 'input.config-param', function(e
) {
123 selectorOpen
= false;
124 if (changedWhileOpen
) {
129 $.getJSON(CRM
.config
.resourceBase
+ 'js/wysiwyg/ck-options.json', null, initOptions
);