| 1 |
(function($) { |
| 2 |
$(document).on('tinymce-editor-setup', function(event, editor) { |
| 3 |
|
| 4 |
if( void 0 === wbcr_inp_shortcode_snippets ) { |
| 5 |
console.log('Unknown error.'); |
| 6 |
return; |
| 7 |
} |
| 8 |
|
| 9 |
if( $.isEmptyObject(wbcr_inp_shortcode_snippets) ) { |
| 10 |
return; |
| 11 |
} |
| 12 |
|
| 13 |
editor.settings.toolbar1 += ',wbcr_insert_php_button'; |
| 14 |
|
| 15 |
var menu = []; |
| 16 |
|
| 17 |
$.each(wbcr_inp_shortcode_snippets, function(index, item) { |
| 18 |
menu.push({ |
| 19 |
text: item.title, |
| 20 |
value: item.id, |
| 21 |
onclick: function() { |
| 22 |
editor.selection.setContent('[wbcr_php_snippet id="' + item.id + '" title="' + item.title + '"]'); |
| 23 |
} |
| 24 |
}); |
| 25 |
}); |
| 26 |
|
| 27 |
editor.addButton('wbcr_insert_php_button', { |
| 28 |
title: wbcr_inp_tinymce_snippets_button_title, |
| 29 |
type: 'menubutton', |
| 30 |
icon: 'icon wbcr-inp-shortcode-icon', |
| 31 |
menu: menu |
| 32 |
}); |
| 33 |
|
| 34 |
}); |
| 35 |
})(jQuery); |