| 1 |
(function(factory) { |
| 2 |
if (typeof define === 'function' && define.amd) { |
| 3 |
// AMD. Register as an anonymous module. |
| 4 |
define(['jquery'], factory); |
| 5 |
} else if (typeof module === 'object' && module.exports) { |
| 6 |
// Node/CommonJS |
| 7 |
module.exports = factory(require('jquery')); |
| 8 |
} else { |
| 9 |
// Browser globals |
| 10 |
factory(window.jQuery); |
| 11 |
} |
| 12 |
}(function($) { |
| 13 |
// Extends plugins for adding hello. |
| 14 |
// - plugin is external module for customizing. |
| 15 |
$.extend($.summernote.plugins, { |
| 16 |
/** |
| 17 |
* @param {Object} context - context object has status of editor. |
| 18 |
*/ |
| 19 |
'hello': function(context) { |
| 20 |
var self = this; |
| 21 |
|
| 22 |
// ui has renders to build ui elements. |
| 23 |
// - you can create a button with `ui.button` |
| 24 |
var ui = $.summernote.ui; |
| 25 |
|
| 26 |
// add hello button |
| 27 |
context.memo('button.hello', function() { |
| 28 |
// create button |
| 29 |
var button = ui.button({ |
| 30 |
contents: '<i class="fa fa-child"/> Hello', |
| 31 |
tooltip: 'hello', |
| 32 |
click: function() { |
| 33 |
self.$panel.show(); |
| 34 |
self.$panel.hide(500); |
| 35 |
// invoke insertText method with 'hello' on editor module. |
| 36 |
context.invoke('editor.insertText', 'hello'); |
| 37 |
}, |
| 38 |
}); |
| 39 |
|
| 40 |
// create jQuery object from button instance. |
| 41 |
var $hello = button.render(); |
| 42 |
return $hello; |
| 43 |
}); |
| 44 |
|
| 45 |
// This events will be attached when editor is initialized. |
| 46 |
this.events = { |
| 47 |
// This will be called after modules are initialized. |
| 48 |
'summernote.init': function(we, e) { |
| 49 |
// eslint-disable-next-line |
| 50 |
console.log('summernote initialized', we, e); |
| 51 |
}, |
| 52 |
// This will be called when user releases a key on editable. |
| 53 |
'summernote.keyup': function(we, e) { |
| 54 |
// eslint-disable-next-line |
| 55 |
console.log('summernote keyup', we, e); |
| 56 |
}, |
| 57 |
}; |
| 58 |
|
| 59 |
// This method will be called when editor is initialized by $('..').summernote(); |
| 60 |
// You can create elements for plugin |
| 61 |
this.initialize = function() { |
| 62 |
this.$panel = $('<div class="hello-panel"/>').css({ |
| 63 |
position: 'absolute', |
| 64 |
width: 100, |
| 65 |
height: 100, |
| 66 |
left: '50%', |
| 67 |
top: '50%', |
| 68 |
background: 'red', |
| 69 |
}).hide(); |
| 70 |
|
| 71 |
this.$panel.appendTo('body'); |
| 72 |
}; |
| 73 |
|
| 74 |
// This methods will be called when editor is destroyed by $('..').summernote('destroy'); |
| 75 |
// You should remove elements on `initialize`. |
| 76 |
this.destroy = function() { |
| 77 |
this.$panel.remove(); |
| 78 |
this.$panel = null; |
| 79 |
}; |
| 80 |
}, |
| 81 |
}); |
| 82 |
})); |
| 83 |
|