From 77310ad863340d7b4c0fda6c0dd8260c3006b0ad Mon Sep 17 00:00:00 2001 From: Lukasz Sielski Date: Mon, 26 Sep 2016 14:23:07 +0100 Subject: [PATCH] Improve for requirejs --- dist/js/medium-editor-tables.js | 8 ++++---- dist/js/medium-editor-tables.min.js | 2 +- src/js/plugin.js | 2 +- src/wrappers/end.js | 2 +- src/wrappers/start.js | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dist/js/medium-editor-tables.js b/dist/js/medium-editor-tables.js index 0f50fff..e168cb8 100644 --- a/dist/js/medium-editor-tables.js +++ b/dist/js/medium-editor-tables.js @@ -8,9 +8,9 @@ return factory; }); } else { - root.MediumEditorTable = factory; + root.MediumEditorTable = factory(root); } -}(this, function () { +}(this, function (root) { 'use strict'; @@ -516,7 +516,7 @@ var COLUMN_WIDTH = 16, BORDER_WIDTH = 1, MediumEditorTable; -MediumEditorTable = MediumEditor.extensions.form.extend({ +MediumEditorTable = root.MediumEditor.extensions.form.extend({ name: 'table', aria: 'create table', @@ -572,4 +572,4 @@ MediumEditorTable = MediumEditor.extensions.form.extend({ }); return MediumEditorTable; -}())); +})); diff --git a/dist/js/medium-editor-tables.min.js b/dist/js/medium-editor-tables.min.js index bd01eab..036e72f 100644 --- a/dist/js/medium-editor-tables.min.js +++ b/dist/js/medium-editor-tables.min.js @@ -1 +1 @@ -!function(a,b){"use strict";var c="object"==typeof module&&process&&process.versions&&process.versions.electron;c||"object"!=typeof module?"function"==typeof define&&define.amd?define(function(){return b}):a.MediumEditorTable=b:module.exports=b}(this,function(){"use strict";function a(a){return a.getSelection?a.getSelection().toString():a.selection&&"Control"!==a.selection.type?a.selection.createRange().text:""}function b(a){var b=a.getSelection().anchorNode,c=b&&3===b.nodeType?b.parentNode:b;return c}function c(a,b,c){if(void 0!==a.getSelection&&b){var d=a.createRange(),e=a.getSelection();c?d.setStartBefore(b):d.setStartAfter(b),d.collapse(!0),e.removeAllRanges(),e.addRange(d)}}function d(a,b){if(!a)return!1;for(var c=a.parentNode,d=c.tagName.toLowerCase();"body"!==d;){if(d===b)return!0;if(c=c.parentNode,!c||!c.tagName)return!1;d=c.tagName.toLowerCase()}return!1}function e(a,b){var c=!(!a||!a.tagName)&&a.tagName.toLowerCase();if(!c)return!1;for(;c&&"body"!==c;){if(c===b)return a;a=a.parentNode,c=!(!a||!a.tagName)&&a.tagName.toLowerCase()}}function f(a,b,c,d){return this.init(a,b,c,d)}function g(a){return this.init(a)}function h(a){return this.init(a)}f.prototype={init:function(a,b,c,d){return this._root=a,this._callback=b,this.rows=c,this.columns=d,this._render()},setCurrentCell:function(a){this._currentCell=a},markCells:function(){[].forEach.call(this._cellsElements,function(a){var b={column:parseInt(a.dataset.column,10),row:parseInt(a.dataset.row,10)},c=this._currentCell&&b.row<=this._currentCell.row&&b.column<=this._currentCell.column;c===!0?a.classList.add("active"):a.classList.remove("active")}.bind(this))},_generateCells:function(){var a=-1;this._cells=[];for(var b=0;b';return c+=this._cellsHTML(),c+=""},_cellsHTML:function(){var a="";return this._generateCells(),this._cells.map(function(b){a+='',a+=""}),a},_render:function(){this._root.innerHTML=this._html(),this._cellsElements=this._root.querySelectorAll("a"),this._bindEvents()},_bindEvents:function(){[].forEach.call(this._cellsElements,function(a){this._onMouseEnter(a),this._onClick(a)}.bind(this))},_onMouseEnter:function(a){var b,c=this;a.addEventListener("mouseenter",function(){clearTimeout(b);var a=this.dataset;b=setTimeout(function(){c._currentCell={column:parseInt(a.column,10),row:parseInt(a.row,10)},c.markCells()},50)})},_onClick:function(a){var b=this;a.addEventListener("click",function(a){a.preventDefault(),b._callback(this.dataset.row,this.dataset.column)})}},g.prototype={init:function(a){this.options=a,this._doc=a.ownerDocument||document,this._root=this._doc.createElement("div"),this._root.className="medium-editor-table-builder",this.grid=new f(this._root,this.options.onClick,this.options.rows,this.options.columns),this._range=null,this._toolbar=this._doc.createElement("div"),this._toolbar.className="medium-editor-table-builder-toolbar";var b=this._doc.createElement("span");b.innerHTML="Row:",this._toolbar.appendChild(b);var c=this._doc.createElement("button");c.title="Add row before",c.innerHTML='',c.onclick=this.addRow.bind(this,!0),this._toolbar.appendChild(c);var d=this._doc.createElement("button");d.title="Add row after",d.innerHTML='',d.onclick=this.addRow.bind(this,!1),this._toolbar.appendChild(d);var e=this._doc.createElement("button");e.title="Remove row",e.innerHTML='',e.onclick=this.removeRow.bind(this),this._toolbar.appendChild(e);var g=this._doc.createElement("span");g.innerHTML="Column:",this._toolbar.appendChild(g);var h=this._doc.createElement("button");h.title="Add column before",h.innerHTML='',h.onclick=this.addColumn.bind(this,!0),this._toolbar.appendChild(h);var i=this._doc.createElement("button");i.title="Add column after",i.innerHTML='',i.onclick=this.addColumn.bind(this,!1),this._toolbar.appendChild(i);var j=this._doc.createElement("button");j.title="Remove column",j.innerHTML='',j.onclick=this.removeColumn.bind(this),this._toolbar.appendChild(j);var k=this._doc.createElement("button");k.title="Remove table",k.innerHTML='',k.onclick=this.removeTable.bind(this),this._toolbar.appendChild(k);var l=this._root.childNodes[0];this._root.insertBefore(this._toolbar,l)},getElement:function(){return this._root},hide:function(){this._root.style.display="",this.grid.setCurrentCell({column:-1,row:-1}),this.grid.markCells()},show:function(a){this._root.style.display="block",this._root.style.left=a+"px"},setEditor:function(a){this._range=a,this._toolbar.style.display="block"},setBuilder:function(){this._range=null,this._toolbar.style.display="none";for(var a=this._doc.getElementsByClassName("medium-editor-table-builder-grid"),b=0;b'+d+"",{cleanAttrs:[],cleanTags:[]});var e=this._doc.getElementById("medium-editor-table");e.removeAttribute("id"),c(this._doc,e.querySelector("td"),!0),this._editor.checkSelection()},_html:function(b,c){var d,e,f="",g=a(this._doc);for(d=0;d<=b;d++){for(f+="",e=0;e<=c;e++)f+=""+(0===d&&0===e?g:"
")+"";f+=""}return f},_bindTabBehavior:function(){var a=this;[].forEach.call(this._editor.elements,function(b){b.addEventListener("keydown",function(b){a._onKeyDown(b)})})},_onKeyDown:function(a){var f,g=b(this._doc);a.which===i&&d(g,"table")&&(a.preventDefault(),a.stopPropagation(),f=this._getTableElements(g),a.shiftKey?this._tabBackwards(g.previousSibling,f.row):(this._isLastCell(g,f.row,f.root)&&this._insertRow(e(g,"tbody"),f.row.cells.length),c(this._doc,g)))},_getTableElements:function(a){return{cell:e(a,"td"),row:e(a,"tr"),root:e(a,"table")}},_tabBackwards:function(a,b){a=a||this._getPreviousRowLastCell(b),c(this._doc,a,!0)},_insertRow:function(a,b){var c,d=document.createElement("tr"),e="";for(c=0;c
";d.innerHTML=e,a.appendChild(d)},_isLastCell:function(a,b,c){return b.cells.length-1===a.cellIndex&&c.rows.length-1===b.rowIndex},_getPreviousRowLastCell:function(a){if(a=a.previousSibling)return a.cells[a.cells.length-1]}};var j,k=16,l=1;return j=MediumEditor.extensions.form.extend({name:"table",aria:"create table",action:"table",contentDefault:"TBL",contentFA:'',handleClick:function(a){a.preventDefault(),a.stopPropagation(),this[this.isActive()===!0?"hide":"show"]()},hide:function(){this.setInactive(),this.builder.hide()},show:function(){this.setActive();var a=MediumEditor.selection.getSelectionRange(this.document);"td"===a.startContainer.nodeName.toLowerCase()||"td"===a.endContainer.nodeName.toLowerCase()||MediumEditor.util.getClosestTag(MediumEditor.selection.getSelectedParentElement(a),"td")?this.builder.setEditor(MediumEditor.selection.getSelectedParentElement(a)):this.builder.setBuilder(),this.builder.show(this.button.offsetLeft)},getForm:function(){return this.builder||(this.builder=new g({onClick:function(a,b){(a>0||b>0)&&this.table.insert(a,b),this.hide()}.bind(this),ownerDocument:this.document,rows:this.rows||10,columns:this.columns||10}),this.table=new h(this.base)),this.builder.getElement()}})}()); \ No newline at end of file +!function(a,b){"use strict";var c="object"==typeof module&&process&&process.versions&&process.versions.electron;c||"object"!=typeof module?"function"==typeof define&&define.amd?define(function(){return b}):a.MediumEditorTable=b(a):module.exports=b}(this,function(a){"use strict";function b(a){return a.getSelection?a.getSelection().toString():a.selection&&"Control"!==a.selection.type?a.selection.createRange().text:""}function c(a){var b=a.getSelection().anchorNode,c=b&&3===b.nodeType?b.parentNode:b;return c}function d(a,b,c){if(void 0!==a.getSelection&&b){var d=a.createRange(),e=a.getSelection();c?d.setStartBefore(b):d.setStartAfter(b),d.collapse(!0),e.removeAllRanges(),e.addRange(d)}}function e(a,b){if(!a)return!1;for(var c=a.parentNode,d=c.tagName.toLowerCase();"body"!==d;){if(d===b)return!0;if(c=c.parentNode,!c||!c.tagName)return!1;d=c.tagName.toLowerCase()}return!1}function f(a,b){var c=!(!a||!a.tagName)&&a.tagName.toLowerCase();if(!c)return!1;for(;c&&"body"!==c;){if(c===b)return a;a=a.parentNode,c=!(!a||!a.tagName)&&a.tagName.toLowerCase()}}function g(a,b,c,d){return this.init(a,b,c,d)}function h(a){return this.init(a)}function i(a){return this.init(a)}g.prototype={init:function(a,b,c,d){return this._root=a,this._callback=b,this.rows=c,this.columns=d,this._render()},setCurrentCell:function(a){this._currentCell=a},markCells:function(){[].forEach.call(this._cellsElements,function(a){var b={column:parseInt(a.dataset.column,10),row:parseInt(a.dataset.row,10)},c=this._currentCell&&b.row<=this._currentCell.row&&b.column<=this._currentCell.column;c===!0?a.classList.add("active"):a.classList.remove("active")}.bind(this))},_generateCells:function(){var a=-1;this._cells=[];for(var b=0;b';return c+=this._cellsHTML(),c+=""},_cellsHTML:function(){var a="";return this._generateCells(),this._cells.map(function(b){a+='',a+=""}),a},_render:function(){this._root.innerHTML=this._html(),this._cellsElements=this._root.querySelectorAll("a"),this._bindEvents()},_bindEvents:function(){[].forEach.call(this._cellsElements,function(a){this._onMouseEnter(a),this._onClick(a)}.bind(this))},_onMouseEnter:function(a){var b,c=this;a.addEventListener("mouseenter",function(){clearTimeout(b);var a=this.dataset;b=setTimeout(function(){c._currentCell={column:parseInt(a.column,10),row:parseInt(a.row,10)},c.markCells()},50)})},_onClick:function(a){var b=this;a.addEventListener("click",function(a){a.preventDefault(),b._callback(this.dataset.row,this.dataset.column)})}},h.prototype={init:function(a){this.options=a,this._doc=a.ownerDocument||document,this._root=this._doc.createElement("div"),this._root.className="medium-editor-table-builder",this.grid=new g(this._root,this.options.onClick,this.options.rows,this.options.columns),this._range=null,this._toolbar=this._doc.createElement("div"),this._toolbar.className="medium-editor-table-builder-toolbar";var b=this._doc.createElement("span");b.innerHTML="Row:",this._toolbar.appendChild(b);var c=this._doc.createElement("button");c.title="Add row before",c.innerHTML='',c.onclick=this.addRow.bind(this,!0),this._toolbar.appendChild(c);var d=this._doc.createElement("button");d.title="Add row after",d.innerHTML='',d.onclick=this.addRow.bind(this,!1),this._toolbar.appendChild(d);var e=this._doc.createElement("button");e.title="Remove row",e.innerHTML='',e.onclick=this.removeRow.bind(this),this._toolbar.appendChild(e);var f=this._doc.createElement("span");f.innerHTML="Column:",this._toolbar.appendChild(f);var h=this._doc.createElement("button");h.title="Add column before",h.innerHTML='',h.onclick=this.addColumn.bind(this,!0),this._toolbar.appendChild(h);var i=this._doc.createElement("button");i.title="Add column after",i.innerHTML='',i.onclick=this.addColumn.bind(this,!1),this._toolbar.appendChild(i);var j=this._doc.createElement("button");j.title="Remove column",j.innerHTML='',j.onclick=this.removeColumn.bind(this),this._toolbar.appendChild(j);var k=this._doc.createElement("button");k.title="Remove table",k.innerHTML='',k.onclick=this.removeTable.bind(this),this._toolbar.appendChild(k);var l=this._root.childNodes[0];this._root.insertBefore(this._toolbar,l)},getElement:function(){return this._root},hide:function(){this._root.style.display="",this.grid.setCurrentCell({column:-1,row:-1}),this.grid.markCells()},show:function(a){this._root.style.display="block",this._root.style.left=a+"px"},setEditor:function(a){this._range=a,this._toolbar.style.display="block"},setBuilder:function(){this._range=null,this._toolbar.style.display="none";for(var a=this._doc.getElementsByClassName("medium-editor-table-builder-grid"),b=0;b'+c+"",{cleanAttrs:[],cleanTags:[]});var e=this._doc.getElementById("medium-editor-table");e.removeAttribute("id"),d(this._doc,e.querySelector("td"),!0),this._editor.checkSelection()},_html:function(a,c){var d,e,f="",g=b(this._doc);for(d=0;d<=a;d++){for(f+="",e=0;e<=c;e++)f+=""+(0===d&&0===e?g:"
")+"";f+=""}return f},_bindTabBehavior:function(){var a=this;[].forEach.call(this._editor.elements,function(b){b.addEventListener("keydown",function(b){a._onKeyDown(b)})})},_onKeyDown:function(a){var b,g=c(this._doc);a.which===j&&e(g,"table")&&(a.preventDefault(),a.stopPropagation(),b=this._getTableElements(g),a.shiftKey?this._tabBackwards(g.previousSibling,b.row):(this._isLastCell(g,b.row,b.root)&&this._insertRow(f(g,"tbody"),b.row.cells.length),d(this._doc,g)))},_getTableElements:function(a){return{cell:f(a,"td"),row:f(a,"tr"),root:f(a,"table")}},_tabBackwards:function(a,b){a=a||this._getPreviousRowLastCell(b),d(this._doc,a,!0)},_insertRow:function(a,b){var c,d=document.createElement("tr"),e="";for(c=0;c
";d.innerHTML=e,a.appendChild(d)},_isLastCell:function(a,b,c){return b.cells.length-1===a.cellIndex&&c.rows.length-1===b.rowIndex},_getPreviousRowLastCell:function(a){if(a=a.previousSibling)return a.cells[a.cells.length-1]}};var k,l=16,m=1;return k=a.MediumEditor.extensions.form.extend({name:"table",aria:"create table",action:"table",contentDefault:"TBL",contentFA:'',handleClick:function(a){a.preventDefault(),a.stopPropagation(),this[this.isActive()===!0?"hide":"show"]()},hide:function(){this.setInactive(),this.builder.hide()},show:function(){this.setActive();var a=MediumEditor.selection.getSelectionRange(this.document);"td"===a.startContainer.nodeName.toLowerCase()||"td"===a.endContainer.nodeName.toLowerCase()||MediumEditor.util.getClosestTag(MediumEditor.selection.getSelectedParentElement(a),"td")?this.builder.setEditor(MediumEditor.selection.getSelectedParentElement(a)):this.builder.setBuilder(),this.builder.show(this.button.offsetLeft)},getForm:function(){return this.builder||(this.builder=new h({onClick:function(a,b){(a>0||b>0)&&this.table.insert(a,b),this.hide()}.bind(this),ownerDocument:this.document,rows:this.rows||10,columns:this.columns||10}),this.table=new i(this.base)),this.builder.getElement()}})}); \ No newline at end of file diff --git a/src/js/plugin.js b/src/js/plugin.js index 9ee5a43..8014a35 100644 --- a/src/js/plugin.js +++ b/src/js/plugin.js @@ -2,7 +2,7 @@ var COLUMN_WIDTH = 16, BORDER_WIDTH = 1, MediumEditorTable; -MediumEditorTable = MediumEditor.extensions.form.extend({ +MediumEditorTable = root.MediumEditor.extensions.form.extend({ name: 'table', aria: 'create table', diff --git a/src/wrappers/end.js b/src/wrappers/end.js index ae613b3..5319404 100644 --- a/src/wrappers/end.js +++ b/src/wrappers/end.js @@ -1,2 +1,2 @@ return MediumEditorTable; -}())); +})); diff --git a/src/wrappers/start.js b/src/wrappers/start.js index 577b07d..74d705e 100644 --- a/src/wrappers/start.js +++ b/src/wrappers/start.js @@ -8,8 +8,8 @@ return factory; }); } else { - root.MediumEditorTable = factory; + root.MediumEditorTable = factory(root); } -}(this, function () { +}(this, function (root) { 'use strict';