(function (factory) { if (typeof define === 'function' && define.amd) { define(['jquery'], factory); } else if (typeof module === 'object' && module.exports) { module.exports = factory(require('jquery')); } else { factory(window.jQuery); } }(function ($) { $.extend($.summernote.plugins, { 'emoji': function (context) { var self = this; var ui = $.summernote.ui; var emojis = ['1', '2', '3', '4', '5','6']; var chunk = function (val, chunkSize) { var R = []; for (var i = 0; i < val.length; i += chunkSize) R.push(val.slice(i, i + chunkSize)); return R; }; /*IE polyfill*/ if (!Array.prototype.filter) { Array.prototype.filter = function (fun /*, thisp*/) { var len = this.length >>> 0; if (typeof fun != "function") throw new TypeError(); var res = []; var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in this) { var val = this[i]; if (fun.call(thisp, val, i, this)) res.push(val); } } return res; }; } var addListener = function () { $(document).on('click', '.closeEmoji', function(){ $('#emoji-dropdown').modal('hide'); }); $(document).on('click', '.selectEmoji', function(){ var img = new Image(); img.src = '/plugins/pubs/summernote/plugin/emojis/'+$(this).attr('data-value')+'.png'; img.alt = $(this).attr('data-value'); img.className = 'emoji-icon-inline'; context.invoke('editor.insertNode', img); }); }; var render = function (emojis) { var emoList = ''; /*limit list to 24 images*/ var emojis = emojis; var chunks = chunk(emojis, 6); for (j = 0; j < chunks.length; j++) { emoList += '
'; for (var i = 0; i < chunks[j].length; i++) { var emo = chunks[j][i]; emoList += '
' + //'' + '' + '
'; } emoList += '
'; } return emoList; }; var filterEmoji = function (value) { var filtered = emojis.filter(function (el) { return el.indexOf(value) > -1; }); return render(filtered); }; // add emoji button context.memo('button.emoji', function () { // create button var button = ui.button({ contents: '', //tooltip: 'emoji', click: function () { if(document.emojiSource === undefined) document.emojiSource = ''; //self.$panel.show(); $('#emoji-dropdown').modal('show'); } }); // create jQuery object from button instance. var $emoji = button.render(); return $emoji; }); // This events will be attached when editor is initialized. this.events = { // This will be called after modules are initialized. 'summernote.init': function (we, e) { addListener(); }, // This will be called when user releases a key on editable. 'summernote.keyup': function (we, e) { } }; // This method will be called when editor is initialized by $('..').summernote(); // You can create elements for plugin this.initialize = function () { this.$panel = $('').hide(); this.$panel.appendTo('body'); }; this.destroy = function () { this.$panel.remove(); this.$panel = null; }; } }); }));