112 lines
4.1 KiB
JavaScript
Executable file
112 lines
4.1 KiB
JavaScript
Executable file
(function(factory)
|
|
{
|
|
/* global define */
|
|
if (typeof define === 'function' && define.amd)
|
|
{
|
|
// AMD. Register as an anonymous module.
|
|
define(['jquery'], factory);
|
|
}
|
|
else if (typeof module === 'object' && module.exports)
|
|
{
|
|
// Node/CommonJS
|
|
module.exports = factory(require('jquery'));
|
|
}
|
|
else
|
|
{
|
|
// Browser globals
|
|
factory(window.jQuery);
|
|
}
|
|
}(function($)
|
|
{
|
|
|
|
// Extends plugins for adding gallery.
|
|
// - plugin is external module for customizing.
|
|
$.extend($.summernote.plugins,
|
|
{
|
|
/**
|
|
* @param {Object} context - context object has status of editor.
|
|
*/
|
|
'placeholders': function(context)
|
|
{
|
|
var self = this;
|
|
|
|
var options = context.options.placeholderList;
|
|
var defaultOptions = {
|
|
label: "Platzhalter",
|
|
tooltip: "Platzhalter einfügen",
|
|
blockChar : '#',
|
|
};
|
|
for (var propertyName in defaultOptions) {
|
|
if (options && propertyName && options.hasOwnProperty(propertyName) === false) {
|
|
options[propertyName] = defaultOptions[propertyName];
|
|
}
|
|
}
|
|
var ui = $.summernote.ui;
|
|
|
|
// add gallery button
|
|
context.memo('button.placeholders', function()
|
|
{
|
|
|
|
var placeholdersButton = ui.buttonGroup([
|
|
ui.button({
|
|
className: 'dropdown-toggle',
|
|
contents: '<span class="template"/> ' + options.label + ' <span class="caret"></span>',
|
|
tooltip: options.tooltip,
|
|
data: {
|
|
toggle: 'dropdown'
|
|
},
|
|
click: function () {
|
|
console.log('placeholders button click');
|
|
context.invoke('editor.saveRange');
|
|
}
|
|
}),
|
|
ui.dropdown({
|
|
className: 'dropdown-style',
|
|
items: options.items,
|
|
callback: function($dropdown) {
|
|
//console.log('$dropdown callback');
|
|
},
|
|
click: function (event) {
|
|
event.preventDefault();
|
|
var $button = $(event.target);
|
|
var value = $button.data('value');
|
|
var text = options.blockChar + value + options.blockChar;
|
|
context.invoke('editor.insertText', text);
|
|
//console.log('$dropdown click : ' + options.blockChar + value + options.blockChar);
|
|
},
|
|
template: function(item)
|
|
{
|
|
var content = (typeof item === 'string') ? item : (item.content || item.value || '');
|
|
return content;
|
|
}
|
|
})
|
|
]).render();
|
|
return placeholdersButton;
|
|
});
|
|
|
|
// This events will be attached when editor is initialized.
|
|
this.events = {
|
|
// This will be called after modules are initialized.
|
|
'summernote.init': function(we, e) {
|
|
|
|
//console.log('summernote initialized', we, e);
|
|
},
|
|
// This will be called when user releases a key on editable.
|
|
'summernote.keyup': function(we, e) {
|
|
|
|
//console.log('summernote keyup', we, e);
|
|
}
|
|
|
|
};
|
|
|
|
// This methods will be called when editor is destroyed by $('..').summernote('destroy');
|
|
// You should remove elements on `initialize`.
|
|
this.destroy = function()
|
|
{
|
|
console.log("destroy");
|
|
// this.$panel.remove();
|
|
// this.$panel = null;
|
|
};
|
|
}
|
|
});
|
|
}));
|