You are offline
'))};i.ajax({url:a,dataType:"json",success:function(i){console.log(arguments),n(i,y,c,!0)},error:v});var m=function(){var e=d.val();if(0!==e.length){try{r.abort()}catch(o){}r=i.ajax({url:l+"&q="+encodeURIComponent(e),dataType:"json",success:function(i){n(i,y,c,!0)},error:v})}},w=e(m,c.o.plugins.giphy.throttleDelay);d.on("input",w),d.focus(),f.one("click",function(){y.trigger(t)})}})}}}})}(jQuery); \ No newline at end of file +!function(i){"use strict";function e(i,e){var n,t;return function(){var o=this,l=+new Date,c=arguments;n&&lYou are offline
'))};i.ajax({url:a,dataType:"json",success:function(i){n(i,y,c,!0)},error:v});var m=function(){var e=d.val();if(0!==e.length){try{r.abort()}catch(t){}r=i.ajax({url:l+"&q="+encodeURIComponent(e),dataType:"json",success:function(i){n(i,y,c,!0)},error:v})}},w=e(m,c.o.plugins.giphy.throttleDelay);d.on("input",w),d.focus(),f.one("click",function(){y.trigger(o)})}})}}}})}(jQuery); \ No newline at end of file diff --git a/dist/plugins/giphy/ui/sass/trumbowyg.giphy.scss b/dist/plugins/giphy/ui/sass/trumbowyg.giphy.scss index 615668d39..ec5dc6cbb 100644 --- a/dist/plugins/giphy/ui/sass/trumbowyg.giphy.scss +++ b/dist/plugins/giphy/ui/sass/trumbowyg.giphy.scss @@ -1,5 +1,5 @@ /** - * Trumbowyg v2.20.0 - A lightweight WYSIWYG editor + * Trumbowyg v2.21.0 - A lightweight WYSIWYG editor * Default stylesheet for Trumbowyg editor plugin * ------------------------ * @link http://alex-d.github.io/Trumbowyg diff --git a/dist/plugins/giphy/ui/trumbowyg.giphy.css b/dist/plugins/giphy/ui/trumbowyg.giphy.css index e9e0d5013..5daaf9e70 100644 --- a/dist/plugins/giphy/ui/trumbowyg.giphy.css +++ b/dist/plugins/giphy/ui/trumbowyg.giphy.css @@ -1,5 +1,5 @@ /** - * Trumbowyg v2.20.0 - A lightweight WYSIWYG editor + * Trumbowyg v2.21.0 - A lightweight WYSIWYG editor * Trumbowyg plugin stylesheet * ------------------------ * @link http://alex-d.github.io/Trumbowyg diff --git a/dist/plugins/giphy/ui/trumbowyg.giphy.min.css b/dist/plugins/giphy/ui/trumbowyg.giphy.min.css index 9c6fc858a..b2bdacc52 100644 --- a/dist/plugins/giphy/ui/trumbowyg.giphy.min.css +++ b/dist/plugins/giphy/ui/trumbowyg.giphy.min.css @@ -1,2 +1,2 @@ -/** Trumbowyg v2.20.0 - A lightweight WYSIWYG editor - alex-d.github.io/Trumbowyg - License MIT - Author : Alexandre Demode (Alex-D) / alex-d.fr */ +/** Trumbowyg v2.21.0 - A lightweight WYSIWYG editor - alex-d.github.io/Trumbowyg - License MIT - Author : Alexandre Demode (Alex-D) / alex-d.fr */ .trumbowyg-giphy-button svg{transform:scale(1.22)}.trumbowyg-giphy-search{display:block;width:80%;margin:5%;padding-left:10px;padding-right:150px}.trumbowyg-giphy-close{position:absolute;top:calc(5% + 8px);right:calc(5% - 2px);width:30px;height:30px;background:0 0;border:1px solid transparent}.trumbowyg-giphy-close:focus,.trumbowyg-giphy-close:hover{outline:0;background:#ecf0f1}.trumbowyg-giphy-close:focus{border-color:rgba(0,0,0,.3)}.trumbowyg-powered-by-giphy{position:absolute;top:calc(5% + 12px);right:calc(15% + 10px);pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.trumbowyg-powered-by-giphy span{text-transform:uppercase;font-weight:700;font-size:10px;opacity:.6}.trumbowyg-powered-by-giphy svg{width:66px;height:15px;vertical-align:bottom;margin-left:6px;opacity:.45}.trumbowyg-giphy-modal-scroll{overflow:auto;overflow-x:hidden;height:240px}.trumbowyg-giphy-modal{padding:0 5%;-moz-columns:3;columns:3;-moz-column-gap:10px;column-gap:10px}.trumbowyg-giphy-modal .trumbowyg-giphy-no-result{width:250%;margin:13% 0 0 29%}.trumbowyg-giphy-modal .trumbowyg-giphy-offline{font-size:18px;width:305%;height:600px;margin-top:95px;text-align:center}.trumbowyg-giphy-modal .img-container{width:100%;margin-bottom:10px;background-color:#ecf0f1}.trumbowyg-giphy-modal .img-container img{width:100%;cursor:pointer;opacity:0;transition:opacity 150ms}.trumbowyg-giphy-modal .img-container img:focus,.trumbowyg-giphy-modal .img-container img:hover{border:3px solid #2ecc71}.trumbowyg-giphy-modal .img-container img.tbw-loaded{opacity:1} \ No newline at end of file diff --git a/dist/plugins/highlight/trumbowyg.highlight.js b/dist/plugins/highlight/trumbowyg.highlight.js index 95c51ee66..1ca737ca7 100644 --- a/dist/plugins/highlight/trumbowyg.highlight.js +++ b/dist/plugins/highlight/trumbowyg.highlight.js @@ -59,6 +59,7 @@ $.extend(true, $.trumbowyg, { // Add some translations langs: { + // jshint camelcase:false en: { highlight: 'Code syntax highlight' }, @@ -68,6 +69,7 @@ ko: { highlight: '코드 문법 하이라이트' }, + // jshint camelcase:true }, // Add our plugin to Trumbowyg registered plugins plugins: { diff --git a/dist/plugins/highlight/ui/sass/trumbowyg.highlight.scss b/dist/plugins/highlight/ui/sass/trumbowyg.highlight.scss index c10d26a00..80e8c2b6d 100644 --- a/dist/plugins/highlight/ui/sass/trumbowyg.highlight.scss +++ b/dist/plugins/highlight/ui/sass/trumbowyg.highlight.scss @@ -1,5 +1,5 @@ /** - * Trumbowyg v2.20.0 - A lightweight WYSIWYG editor + * Trumbowyg v2.21.0 - A lightweight WYSIWYG editor * Default stylesheet for Trumbowyg editor plugin * ------------------------ * @link http://alex-d.github.io/Trumbowyg diff --git a/dist/plugins/highlight/ui/trumbowyg.highlight.css b/dist/plugins/highlight/ui/trumbowyg.highlight.css index e22631419..e3abedfad 100644 --- a/dist/plugins/highlight/ui/trumbowyg.highlight.css +++ b/dist/plugins/highlight/ui/trumbowyg.highlight.css @@ -1,5 +1,5 @@ /** - * Trumbowyg v2.20.0 - A lightweight WYSIWYG editor + * Trumbowyg v2.21.0 - A lightweight WYSIWYG editor * Trumbowyg plugin stylesheet * ------------------------ * @link http://alex-d.github.io/Trumbowyg diff --git a/dist/plugins/highlight/ui/trumbowyg.highlight.min.css b/dist/plugins/highlight/ui/trumbowyg.highlight.min.css index 825ab38ea..358a44db0 100644 --- a/dist/plugins/highlight/ui/trumbowyg.highlight.min.css +++ b/dist/plugins/highlight/ui/trumbowyg.highlight.min.css @@ -1,2 +1,2 @@ -/** Trumbowyg v2.20.0 - A lightweight WYSIWYG editor - alex-d.github.io/Trumbowyg - License MIT - Author : Alexandre Demode (Alex-D) / alex-d.fr */ +/** Trumbowyg v2.21.0 - A lightweight WYSIWYG editor - alex-d.github.io/Trumbowyg - License MIT - Author : Alexandre Demode (Alex-D) / alex-d.fr */ .trumbowyg-highlight-form-group{margin:15px 10px}.trumbowyg-highlight-form-group .trumbowyg-highlight-form-control{width:100%;border:1px solid #DEDEDE;font-size:14px;padding:7px}.trumbowyg-highlight-form-group .trumbowyg-highlight-form-control.code{height:200px} \ No newline at end of file diff --git a/dist/plugins/history/trumbowyg.history.js b/dist/plugins/history/trumbowyg.history.js index 16e6828e2..a66769932 100644 --- a/dist/plugins/history/trumbowyg.history.js +++ b/dist/plugins/history/trumbowyg.history.js @@ -10,6 +10,7 @@ 'use strict'; $.extend(true, $.trumbowyg, { langs: { + // jshint camelcase:false de: { history: { redo: 'Wiederholen', @@ -52,6 +53,7 @@ undo: '되돌리기' } }, + // jshint camelcase:true }, plugins: { history: { diff --git a/dist/plugins/insertaudio/trumbowyg.insertaudio.js b/dist/plugins/insertaudio/trumbowyg.insertaudio.js index 1748fd362..eeda2db5e 100644 --- a/dist/plugins/insertaudio/trumbowyg.insertaudio.js +++ b/dist/plugins/insertaudio/trumbowyg.insertaudio.js @@ -33,6 +33,7 @@ $.extend(true, $.trumbowyg, { langs: { + // jshint camelcase:false en: { insertAudio: 'Insert Audio' }, @@ -57,6 +58,7 @@ ko: { insertAudio: '소리 넣기' }, + // jshint camelcase:true }, plugins: { insertAudio: { diff --git a/dist/plugins/mathml/ui/sass/trumbowyg.mathml.scss b/dist/plugins/mathml/ui/sass/trumbowyg.mathml.scss index e74942767..1dbaacea9 100644 --- a/dist/plugins/mathml/ui/sass/trumbowyg.mathml.scss +++ b/dist/plugins/mathml/ui/sass/trumbowyg.mathml.scss @@ -1,5 +1,5 @@ /** - * Trumbowyg v2.20.0 - A lightweight WYSIWYG editor + * Trumbowyg v2.21.0 - A lightweight WYSIWYG editor * Default stylesheet for Trumbowyg editor plugin * ------------------------ * @link http://alex-d.github.io/Trumbowyg diff --git a/dist/plugins/mathml/ui/trumbowyg.mathml.css b/dist/plugins/mathml/ui/trumbowyg.mathml.css index 886245f10..9d2b51d66 100644 --- a/dist/plugins/mathml/ui/trumbowyg.mathml.css +++ b/dist/plugins/mathml/ui/trumbowyg.mathml.css @@ -1,5 +1,5 @@ /** - * Trumbowyg v2.20.0 - A lightweight WYSIWYG editor + * Trumbowyg v2.21.0 - A lightweight WYSIWYG editor * Trumbowyg plugin stylesheet * ------------------------ * @link http://alex-d.github.io/Trumbowyg diff --git a/dist/plugins/mathml/ui/trumbowyg.mathml.min.css b/dist/plugins/mathml/ui/trumbowyg.mathml.min.css index bed769c03..8e251b68e 100644 --- a/dist/plugins/mathml/ui/trumbowyg.mathml.min.css +++ b/dist/plugins/mathml/ui/trumbowyg.mathml.min.css @@ -1,2 +1,2 @@ -/** Trumbowyg v2.20.0 - A lightweight WYSIWYG editor - alex-d.github.io/Trumbowyg - License MIT - Author : Alexandre Demode (Alex-D) / alex-d.fr */ +/** Trumbowyg v2.21.0 - A lightweight WYSIWYG editor - alex-d.github.io/Trumbowyg - License MIT - Author : Alexandre Demode (Alex-D) / alex-d.fr */ .mathMlContainer{position:relative}.mathMlContainer[inline=false]{display:block;width:100%}.mathMlContainer:hover{pointer-events:none}.mathMlContainer:hover::after{content:'\270E';position:absolute;top:0;right:0;bottom:0;left:0;background-color:rgba(255,255,255,.83);box-shadow:0 0 5px 5px rgba(255,255,255,.83);cursor:pointer;pointer-events:auto} \ No newline at end of file diff --git a/dist/plugins/mention/ui/sass/trumbowyg.mention.scss b/dist/plugins/mention/ui/sass/trumbowyg.mention.scss index d8e0bc23d..5391ec7c1 100644 --- a/dist/plugins/mention/ui/sass/trumbowyg.mention.scss +++ b/dist/plugins/mention/ui/sass/trumbowyg.mention.scss @@ -1,5 +1,5 @@ /** - * Trumbowyg v2.20.0 - A lightweight WYSIWYG editor + * Trumbowyg v2.21.0 - A lightweight WYSIWYG editor * Default stylesheet for Trumbowyg editor plugin * ------------------------ * @link http://alex-d.github.io/Trumbowyg diff --git a/dist/plugins/mention/ui/trumbowyg.mention.css b/dist/plugins/mention/ui/trumbowyg.mention.css index 4ddb2296c..8323e713a 100644 --- a/dist/plugins/mention/ui/trumbowyg.mention.css +++ b/dist/plugins/mention/ui/trumbowyg.mention.css @@ -1,5 +1,5 @@ /** - * Trumbowyg v2.20.0 - A lightweight WYSIWYG editor + * Trumbowyg v2.21.0 - A lightweight WYSIWYG editor * Trumbowyg plugin stylesheet * ------------------------ * @link http://alex-d.github.io/Trumbowyg diff --git a/dist/plugins/mention/ui/trumbowyg.mention.min.css b/dist/plugins/mention/ui/trumbowyg.mention.min.css index 761382b11..ca109f2ce 100644 --- a/dist/plugins/mention/ui/trumbowyg.mention.min.css +++ b/dist/plugins/mention/ui/trumbowyg.mention.min.css @@ -1,2 +1,2 @@ -/** Trumbowyg v2.20.0 - A lightweight WYSIWYG editor - alex-d.github.io/Trumbowyg - License MIT - Author : Alexandre Demode (Alex-D) / alex-d.fr */ +/** Trumbowyg v2.21.0 - A lightweight WYSIWYG editor - alex-d.github.io/Trumbowyg - License MIT - Author : Alexandre Demode (Alex-D) / alex-d.fr */ .trumbowyg-dropdown-mention button{position:relative;white-space:nowrap}.trumbowyg-dropdown-mention button:after{content:"";position:absolute;top:0;right:0;width:15%;height:100%;background-size:100%;background-image:linear-gradient(to right,rgba(255,255,255,0) 0,#fff 80%,#fff 100%);pointer-events:none} \ No newline at end of file diff --git a/dist/plugins/noembed/trumbowyg.noembed.js b/dist/plugins/noembed/trumbowyg.noembed.js index 20ba0ab11..212d6784f 100644 --- a/dist/plugins/noembed/trumbowyg.noembed.js +++ b/dist/plugins/noembed/trumbowyg.noembed.js @@ -19,6 +19,7 @@ $.extend(true, $.trumbowyg, { langs: { + // jshint camelcase:false en: { noembed: 'Noembed', noembedError: 'Error' @@ -56,6 +57,7 @@ noembed: 'oEmbed 넣기', noembedError: '에러' }, + // jshint camelcase:true }, plugins: { diff --git a/dist/plugins/resizimg/resizable-resolveconflict.js b/dist/plugins/resizimg/resizable-resolveconflict.js new file mode 100644 index 000000000..49a121158 --- /dev/null +++ b/dist/plugins/resizimg/resizable-resolveconflict.js @@ -0,0 +1,20 @@ +(function (factory, define, require, module) { + 'use strict'; + + if (typeof define === 'function' && define.amd) { + // AMD + define(['jquery'], factory); + } else if (typeof module === 'object' && typeof module.exports === 'object') { + // CommonJS + module.exports = factory(require('jquery')); + } else { + // Global jQuery + factory(jQuery); + } +}(function ($) { + 'use strict'; + + // rename to avoid conflict with jquery-resizable + $.fn.uiresizable = $.fn.resizable; + delete $.fn.resizable; +})); diff --git a/dist/plugins/resizimg/resizable-resolveconflict.min.js b/dist/plugins/resizimg/resizable-resolveconflict.min.js new file mode 100644 index 000000000..8420eb842 --- /dev/null +++ b/dist/plugins/resizimg/resizable-resolveconflict.min.js @@ -0,0 +1 @@ +!function(e,t,o,r){"use strict";"function"==typeof t&&t.amd?t(["jquery"],e):"object"==typeof r&&"object"==typeof r.exports?r.exports=e(o("jquery")):e(jQuery)}(function(e){"use strict";e.fn.uiresizable=e.fn.resizable,delete e.fn.resizable}); \ No newline at end of file diff --git a/dist/plugins/resizimg/trumbowyg.resizimg.js b/dist/plugins/resizimg/trumbowyg.resizimg.js index 1f97f54de..d62356985 100644 --- a/dist/plugins/resizimg/trumbowyg.resizimg.js +++ b/dist/plugins/resizimg/trumbowyg.resizimg.js @@ -1,21 +1,209 @@ -(function ($) { +;(function ($) { 'use strict'; var defaultOptions = { minSize: 32, - step: 4, + step: 4 }; - function preventDefault(ev) { - return ev.preventDefault(); + function preventDefault(e) { + e.stopPropagation(); + e.preventDefault(); } + var ResizeWithCanvas = function () { + // variable to create canvas and save img in resize mode + this.resizeCanvas = document.createElement('canvas'); + // to allow canvas to get focus + this.resizeCanvas.setAttribute('tabindex', '0'); + this.resizeCanvas.id = 'trumbowyg-resizimg-' + (+new Date()); + this.ctx = null; + this.resizeImg = null; + + this.pressEscape = function (obj) { + obj.reset(); + }; + this.pressBackspaceOrDelete = function (obj) { + $(obj.resizeCanvas).replaceWith(''); + obj.resizeImg = null; + }; + + // PRIVATE FUNCTION + var focusedNow = false; + var isCursorSeResize = false; + + // calculate offset to change mouse over square in the canvas + var offsetX, offsetY; + var reOffset = function (canvas) { + var BB = canvas.getBoundingClientRect(); + offsetX = BB.left; + offsetY = BB.top; + }; + + var drawRect = function (shapeData, ctx) { + // Inner + ctx.beginPath(); + ctx.fillStyle = 'rgb(255, 255, 255)'; + ctx.rect(shapeData.points.x, shapeData.points.y, shapeData.points.width, shapeData.points.height); + ctx.fill(); + ctx.stroke(); + }; + + var updateCanvas = function (canvas, ctx, img, canvasWidth, canvasHeight) { + ctx.translate(0.5, 0.5); + ctx.lineWidth = 1; + + // image + ctx.drawImage(img, 5, 5, canvasWidth - 10, canvasHeight - 10); + + // border + ctx.beginPath(); + ctx.rect(5, 5, canvasWidth - 10, canvasHeight - 10); + ctx.stroke(); + + // square in the angle + ctx.beginPath(); + ctx.fillStyle = 'rgb(255, 255, 255)'; + ctx.rect(canvasWidth - 10, canvasHeight - 10, 9, 9); + ctx.fill(); + ctx.stroke(); + + // get the offset to change the mouse cursor + reOffset(canvas); + + return ctx; + }; + + // PUBLIC FUNCTION + // necessary to correctly print cursor over square. Called once for instance. Useless with trumbowyg. + this.init = function () { + var _this = this; + $(window).on('scroll resize', function () { + _this.reCalcOffset(); + }); + }; + + this.reCalcOffset = function () { + reOffset(this.resizeCanvas); + }; + + this.canvasId = function () { + return this.resizeCanvas.id; + }; + + this.isActive = function () { + return this.resizeImg !== null; + }; + + this.isFocusedNow = function () { + return focusedNow; + }; + + this.blurNow = function () { + focusedNow = false; + }; + + // restore image in the HTML of the editor + this.reset = function () { + if (this.resizeImg === null) { + return; + } + + this.resizeImg.width = this.resizeCanvas.clientWidth - 10; + this.resizeImg.height = this.resizeCanvas.clientHeight - 10; + // clear style of image to avoid issue on resize because this attribute have priority over width and height attribute + this.resizeImg.removeAttribute('style'); + + $(this.resizeCanvas).replaceWith($(this.resizeImg)); + + // reset canvas style + this.resizeCanvas.removeAttribute('style'); + this.resizeImg = null; + }; + + // setup canvas with points and border to allow the resizing operation + this.setup = function (img, resizableOptions) { + this.resizeImg = img; + + if (!this.resizeCanvas.getContext) { + return false; + } + + focusedNow = true; + + // draw canvas + this.resizeCanvas.width = $(this.resizeImg).width() + 10; + this.resizeCanvas.height = $(this.resizeImg).height() + 10; + this.resizeCanvas.style.margin = '-5px'; + this.ctx = this.resizeCanvas.getContext('2d'); + + // replace image with canvas + $(this.resizeImg).replaceWith($(this.resizeCanvas)); + + updateCanvas(this.resizeCanvas, this.ctx, this.resizeImg, this.resizeCanvas.width, this.resizeCanvas.height); + + // enable resize + $(this.resizeCanvas).resizable(resizableOptions) + .on('mousedown', preventDefault); + + var _this = this; + $(this.resizeCanvas) + .on('mousemove', function (e) { + var mouseX = Math.round(e.clientX - offsetX); + var mouseY = Math.round(e.clientY - offsetY); + + var wasCursorSeResize = isCursorSeResize; + + _this.ctx.rect(_this.resizeCanvas.width - 10, _this.resizeCanvas.height - 10, 9, 9); + isCursorSeResize = _this.ctx.isPointInPath(mouseX, mouseY); + if (wasCursorSeResize !== isCursorSeResize) { + this.style.cursor = isCursorSeResize ? 'se-resize' : 'default'; + } + }) + .on('keydown', function (e) { + if (!_this.isActive()) { + return; + } + + var x = e.keyCode; + if (x === 27) { // ESC + _this.pressEscape(_this); + } else if (x === 8 || x === 46) { // BACKSPACE or DELETE + _this.pressBackspaceOrDelete(_this); + } + }) + .on('focus', preventDefault); + + this.resizeCanvas.focus(); + + return true; + }; + + // update the canvas after the resizing + this.refresh = function () { + if (!this.resizeCanvas.getContext) { + return; + } + + this.resizeCanvas.width = this.resizeCanvas.clientWidth; + this.resizeCanvas.height = this.resizeCanvas.clientHeight; + updateCanvas(this.resizeCanvas, this.ctx, this.resizeImg, this.resizeCanvas.width, this.resizeCanvas.height); + }; + }; + + // object to interact with canvas + var resizeWithCanvas = new ResizeWithCanvas(); + function destroyResizable(trumbowyg) { - trumbowyg.$ed.find('img.resizable') - .resizable('destroy') - .off('mousedown', preventDefault) - .removeClass('resizable'); - trumbowyg.syncTextarea(); + // clean html code + trumbowyg.$ed.find('canvas.resizable') + .resizable('destroy') + .off('mousedown', preventDefault) + .removeClass('resizable'); + + resizeWithCanvas.reset(); + + trumbowyg.syncCode(); } $.extend(true, $.trumbowyg, { @@ -46,6 +234,8 @@ return false; }, onDragEnd: function () { + // resize update canvas information + resizeWithCanvas.refresh(); trumbowyg.syncCode(); } } @@ -53,22 +243,55 @@ ); function initResizable() { - trumbowyg.$ed.find('img:not(.resizable)') - .resizable(trumbowyg.o.plugins.resizimg.resizable) - .on('mousedown', preventDefault); + trumbowyg.$ed.find('img') + .off('click') + .on('click', function (e) { + // if I'm already do a resize, reset it + if (resizeWithCanvas.isActive()) { + resizeWithCanvas.reset(); + } + // initialize resize of image + resizeWithCanvas.setup(this, trumbowyg.o.plugins.resizimg.resizable); + + preventDefault(e); + }); } - // Init - trumbowyg.$c.on('tbwinit', initResizable); - trumbowyg.$c.on('tbwfocus', initResizable); - trumbowyg.$c.on('tbwchange', initResizable); + trumbowyg.$c.on('tbwinit', function () { + initResizable(); + + // disable resize when click on other items + trumbowyg.$ed.on('click', function (e) { + // check if I've clicked out of canvas or image to reset it + if ($(e.target).is('img') || e.target.id === resizeWithCanvas.canvasId()) { + return; + } + + preventDefault(e); + resizeWithCanvas.reset(); + + // save changes + trumbowyg.$c.trigger('tbwchange'); + }); + + trumbowyg.$ed.on('scroll', function () { + resizeWithCanvas.reCalcOffset(); + }); + }); + + trumbowyg.$c.on('tbwfocus tbwchange', initResizable); + trumbowyg.$c.on('tbwresize', function () { + resizeWithCanvas.reCalcOffset(); + }); // Destroy trumbowyg.$c.on('tbwblur', function () { - destroyResizable(trumbowyg); - }); - trumbowyg.$c.on('tbwclose', function () { - destroyResizable(trumbowyg); + // if I have already focused the canvas avoid destroy + if (resizeWithCanvas.isFocusedNow()) { + resizeWithCanvas.blurNow(); + } else { + destroyResizable(trumbowyg); + } }); }, destroy: function (trumbowyg) { diff --git a/dist/plugins/resizimg/trumbowyg.resizimg.min.js b/dist/plugins/resizimg/trumbowyg.resizimg.min.js index c1547447e..77d1c8542 100644 --- a/dist/plugins/resizimg/trumbowyg.resizimg.min.js +++ b/dist/plugins/resizimg/trumbowyg.resizimg.min.js @@ -1 +1 @@ -!function(e){"use strict";function i(e){return e.preventDefault()}function n(e){e.$ed.find("img.resizable").resizable("destroy").off("mousedown",i).removeClass("resizable"),e.syncTextarea()}var t={minSize:32,step:4};e.extend(!0,e.trumbowyg,{plugins:{resizimg:{init:function(o){function r(){o.$ed.find("img:not(.resizable)").resizable(o.o.plugins.resizimg.resizable).on("mousedown",i)}o.o.plugins.resizimg=e.extend(!0,{},t,o.o.plugins.resizimg||{},{resizable:{resizeWidth:!1,onDragStart:function(e,i){var n=o.o.plugins.resizimg,t=e.pageX-i.offset().left,r=e.pageY-i.offset().top;if(t":"p";e.doc.execCommand("formatBlock",!1,t),e.syncCode()},0)}).on("cut drop",function(){setTimeout(function(){e.semanticCode(!1,!0),e.$c.trigger("tbwchange")},0)}).on("paste",function(n){if(e.o.removeformatPasted){n.preventDefault(),t.getSelection&&t.getSelection().deleteFromDocument&&t.getSelection().deleteFromDocument();try{var o=t.clipboardData.getData("Text");try{e.doc.selection.createRange().pasteHTML(o)}catch(r){e.doc.getSelection().getRangeAt(0).insertNode(e.doc.createTextNode(o))}e.$c.trigger("tbwchange",n)}catch(i){e.execCmd("insertText",(n.originalEvent||n).clipboardData.getData("text/plain"))}}a.each(e.pasteHandlers,function(e,t){t(n)}),setTimeout(function(){e.semanticCode(!1,!0),e.$c.trigger("tbwpaste",n),e.$c.trigger("tbwchange")},0)}),e.$ta.on("keyup",function(){e.$c.trigger("tbwchange")}).on("paste",function(){setTimeout(function(){e.$c.trigger("tbwchange")},0)}),a(e.doc.body).on("keydown",function(t){if(27===t.which&&a("."+n+"modal-box").length>=1)return e.closeModal(),!1})},autogrowEditorOnEnter:function(){var e=this;e.$ed.removeClass("autogrow-on-enter");var t=e.$ed[0].clientHeight;e.$ed.height("auto");var n=e.$ed[0].scrollHeight;e.$ed.addClass("autogrow-on-enter"),t!==n&&(e.$ed.height(t),setTimeout(function(){e.$ed.css({height:n}),e.$c.trigger("tbwresize")},0))},buildBtnPane:function(){var e=this,t=e.o.prefix,n=e.$btnPane=a("
",{"class":t+"button-pane"});a.each(e.o.btns,function(o,r){a.isArray(r)||(r=[r]);var i=a("",{"class":t+"button-group "+(r.indexOf("fullscreen")>=0?t+"right":"")});a.each(r,function(t,n){try{e.isSupportedBtn(n)&&i.append(e.buildBtn(n))}catch(a){}}),i.html().trim().length>0&&n.append(i)}),e.$box.prepend(n)},buildBtn:function(e){var t=this,n=t.o.prefix,o=t.btnsDef[e],r=o.dropdown,i=null==o.hasIcon||o.hasIcon,s=t.lang[e]||e,l=a("",{type:"button","class":n+e+"-button "+(o["class"]||"")+(i?"":" "+n+"textual-button"),html:t.hasSvg&&i?'':t.hideButtonTexts?"":o.text||o.title||t.lang[e]||e,title:(o.title||o.text||s)+(o.key?" ("+(t.isMac?"Cmd":"Ctrl")+" + "+o.key+")":""),tabindex:-1,mousedown:function(){return r&&!a("."+e+"-"+n+"dropdown",t.$box).is(":hidden")||a("body",t.doc).trigger("mousedown"),!((t.$btnPane.hasClass(n+"disable")||t.$box.hasClass(n+"disabled"))&&!a(this).hasClass(n+"active")&&!a(this).hasClass(n+"not-disable"))&&(t.execCmd(!!r&&"dropdown"||o.fn||e,o.param||e,o.forceCss),!1)}});if(r){l.addClass(n+"open-dropdown");var d=n+"dropdown",c={"class":d+"-"+e+" "+d+" "+n+"fixed-top "+(o.dropdownClass||"")};c["data-"+d]=e;var u=a("",c);a.each(r,function(e,n){t.btnsDef[n]&&t.isSupportedBtn(n)&&u.append(t.buildSubBtn(n))}),t.$box.append(u.hide())}else o.key&&(t.keys[o.key]={fn:o.fn||e,param:o.param||e});return r||(t.tagToButton[(o.tag||e).toLowerCase()]=e),l},buildSubBtn:function(e){var t=this,n=t.o.prefix,o=t.btnsDef[e],r=null==o.hasIcon||o.hasIcon;return o.key&&(t.keys[o.key]={fn:o.fn||e,param:o.param||e}),t.tagToButton[(o.tag||e).toLowerCase()]=e,a("",{type:"button","class":n+e+"-dropdown-button "+(o["class"]||"")+(o.ico?" "+n+o.ico+"-button":""),html:t.hasSvg&&r?''+(o.text||o.title||t.lang[e]||e):o.text||o.title||t.lang[e]||e,title:o.key?"("+(t.isMac?"Cmd":"Ctrl")+" + "+o.key+")":null,style:o.style||null,mousedown:function(){return a("body",t.doc).trigger("mousedown"),t.execCmd(o.fn||e,o.param||e,o.forceCss),!1}})},isSupportedBtn:function(e){try{return this.btnsDef[e].isSupported()}catch(t){}return!0},buildOverlay:function(){var e=this;return e.$overlay=a("",{"class":e.o.prefix+"overlay"}).appendTo(e.$box),e.$overlay},showOverlay:function(){var e=this;a(t).trigger("scroll"),e.$overlay.fadeIn(200),e.$box.addClass(e.o.prefix+"box-blur")},hideOverlay:function(){var e=this;e.$overlay.fadeOut(50),e.$box.removeClass(e.o.prefix+"box-blur")},fixedBtnPaneEvents:function(){var e=this,n=e.o.fixedFullWidth,o=e.$box;e.o.fixedBtnPane&&(e.isFixed=!1,a(t).on("scroll."+e.eventNamespace+" resize."+e.eventNamespace,function(){if(o){e.syncCode();var r=a(t).scrollTop(),i=o.offset().top+1,s=e.$btnPane,l=s.outerHeight()-2;r-i>0&&r-i-e.height<0?(e.isFixed||(e.isFixed=!0,s.css({position:"fixed",top:0,left:n?0:"auto",zIndex:7}),e.$box.css({paddingTop:s.height()})),s.css({width:n?"100%":o.width()-1}),a("."+e.o.prefix+"fixed-top",o).css({position:n?"fixed":"absolute",top:n?l:l+(r-i),zIndex:15})):e.isFixed&&(e.isFixed=!1,s.removeAttr("style"),e.$box.css({paddingTop:0}),a("."+e.o.prefix+"fixed-top",o).css({position:"absolute",top:l}))}}))},setDisabled:function(e){var t=this,n=t.o.prefix;t.disabled=e,e?t.$ta.attr("disabled",!0):t.$ta.removeAttr("disabled"),t.$box.toggleClass(n+"disabled",e),t.$ed.attr("contenteditable",!e)},destroy:function(){var e=this,n=e.o.prefix;e.isTextarea?e.$box.after(e.$ta.css({height:""}).val(e.html()).removeClass(n+"textarea").show()):e.$box.after(e.$ed.css({height:""}).removeClass(n+"editor").removeAttr("contenteditable").removeAttr("dir").html(e.html()).show()),e.$ed.off("dblclick","img"),e.destroyPlugins(),e.$box.remove(),e.$c.removeData("trumbowyg"),a("body").removeClass(n+"body-fullscreen"),e.$c.trigger("tbwclose"),a(t).off("scroll."+e.eventNamespace+" resize."+e.eventNamespace)},empty:function(){this.$ta.val(""),this.syncCode(!0)},toggle:function(){var e=this,t=e.o.prefix;e.o.autogrowOnEnter&&(e.autogrowOnEnterDontClose=!e.$box.hasClass(t+"editor-hidden")),e.semanticCode(!1,!0),e.$c.trigger("tbwchange"),setTimeout(function(){e.doc.activeElement.blur(),e.$box.toggleClass(t+"editor-hidden "+t+"editor-visible"),e.$btnPane.toggleClass(t+"disable"),a("."+t+"viewHTML-button",e.$btnPane).toggleClass(t+"active"),e.$box.hasClass(t+"editor-visible")?e.$ta.attr("tabindex",-1):e.$ta.removeAttr("tabindex"),e.o.autogrowOnEnter&&!e.autogrowOnEnterDontClose&&e.autogrowEditorOnEnter()},0)},dropdown:function(e){var n=this,o=a("body",n.doc),r=n.o.prefix,i=a("[data-"+r+"dropdown="+e+"]",n.$box),s=a("."+r+e+"-button",n.$btnPane),l=i.is(":hidden");if(o.trigger("mousedown"),l){var d=s.offset().left;s.addClass(r+"active"),i.css({position:"absolute",top:s.offset().top-n.$btnPane.offset().top+s.outerHeight(),left:n.o.fixedFullWidth&&n.isFixed?d:d-n.$btnPane.offset().left}).show(),a(t).trigger("scroll"),o.on("mousedown."+n.eventNamespace,function(e){i.is(e.target)||(a("."+r+"dropdown",n.$box).hide(),a("."+r+"active",n.$btnPane).removeClass(r+"active"),o.off("mousedown."+n.eventNamespace))})}},html:function(e){var t=this;return null!=e?(t.$ta.val(e),t.syncCode(!0),t.$c.trigger("tbwchange"),t):t.$ta.val()},syncTextarea:function(){var e=this;e.$ta.val(e.$ed.text().trim().length>0||e.$ed.find(e.o.tagsToKeep.join(",")).length>0?e.$ed.html():"")},syncCode:function(e){var t=this;if(!e&&t.$ed.is(":visible"))t.syncTextarea();else{var n=a("":"p";e.doc.execCommand("formatBlock",!1,t),e.syncCode()},0)}).on("cut drop",function(){setTimeout(function(){e.semanticCode(!1,!0),e.$c.trigger("tbwchange")},0)}).on("paste",function(n){if(e.o.removeformatPasted){n.preventDefault(),t.getSelection&&t.getSelection().deleteFromDocument&&t.getSelection().deleteFromDocument();try{var o=t.clipboardData.getData("Text");try{e.doc.selection.createRange().pasteHTML(o)}catch(r){e.doc.getSelection().getRangeAt(0).insertNode(e.doc.createTextNode(o))}e.$c.trigger("tbwchange",n)}catch(i){e.execCmd("insertText",(n.originalEvent||n).clipboardData.getData("text/plain"))}}a.each(e.pasteHandlers,function(e,t){t(n)}),setTimeout(function(){e.semanticCode(!1,!0),e.$c.trigger("tbwpaste",n),e.$c.trigger("tbwchange")},0)}),e.$ta.on("keyup",function(){e.$c.trigger("tbwchange")}).on("paste",function(){setTimeout(function(){e.$c.trigger("tbwchange")},0)}),a(e.doc.body).on("keydown."+e.eventNamespace,function(t){if(27===t.which&&a("."+n+"modal-box").length>=1)return e.closeModal(),!1})},autogrowEditorOnEnter:function(){var e=this;e.$ed.removeClass("autogrow-on-enter");var t=e.$ed[0].clientHeight;e.$ed.height("auto");var n=e.$ed[0].scrollHeight;e.$ed.addClass("autogrow-on-enter"),t!==n&&(e.$ed.height(t),setTimeout(function(){e.$ed.css({height:n}),e.$c.trigger("tbwresize")},0))},buildBtnPane:function(){var e=this,t=e.o.prefix,n=e.$btnPane=a("
",{"class":t+"button-pane"});a.each(e.o.btns,function(o,r){a.isArray(r)||(r=[r]);var i=a("",{"class":t+"button-group "+(r.indexOf("fullscreen")>=0?t+"right":"")});a.each(r,function(t,n){try{e.isSupportedBtn(n)&&i.append(e.buildBtn(n))}catch(a){}}),i.html().trim().length>0&&n.append(i)}),e.$box.prepend(n)},buildBtn:function(e){var t=this,n=t.o.prefix,o=t.btnsDef[e],r=o.dropdown,i=null==o.hasIcon||o.hasIcon,s=t.lang[e]||e,l=a("",{type:"button","class":n+e+"-button "+(o["class"]||"")+(i?"":" "+n+"textual-button"),html:t.hasSvg&&i?'':t.hideButtonTexts?"":o.text||o.title||t.lang[e]||e,title:(o.title||o.text||s)+(o.key?" ("+(t.isMac?"Cmd":"Ctrl")+" + "+o.key+")":""),tabindex:-1,mousedown:function(){return r&&!a("."+e+"-"+n+"dropdown",t.$box).is(":hidden")||a("body",t.doc).trigger("mousedown"),!((t.$btnPane.hasClass(n+"disable")||t.$box.hasClass(n+"disabled"))&&!a(this).hasClass(n+"active")&&!a(this).hasClass(n+"not-disable"))&&(t.execCmd(!!r&&"dropdown"||o.fn||e,o.param||e,o.forceCss),!1)}});if(r){l.addClass(n+"open-dropdown");var d=n+"dropdown",c={"class":d+"-"+e+" "+d+" "+n+"fixed-top "+(o.dropdownClass||"")};c["data-"+d]=e;var u=a("",c);a.each(r,function(e,n){t.btnsDef[n]&&t.isSupportedBtn(n)&&u.append(t.buildSubBtn(n))}),t.$box.append(u.hide())}else o.key&&(t.keys[o.key]={fn:o.fn||e,param:o.param||e});return r||(t.tagToButton[(o.tag||e).toLowerCase()]=e),l},buildSubBtn:function(e){var t=this,n=t.o.prefix,o=t.btnsDef[e],r=null==o.hasIcon||o.hasIcon;return o.key&&(t.keys[o.key]={fn:o.fn||e,param:o.param||e}),t.tagToButton[(o.tag||e).toLowerCase()]=e,a("",{type:"button","class":n+e+"-dropdown-button "+(o["class"]||"")+(o.ico?" "+n+o.ico+"-button":""),html:t.hasSvg&&r?''+(o.text||o.title||t.lang[e]||e):o.text||o.title||t.lang[e]||e,title:o.key?"("+(t.isMac?"Cmd":"Ctrl")+" + "+o.key+")":null,style:o.style||null,mousedown:function(){return a("body",t.doc).trigger("mousedown"),t.execCmd(o.fn||e,o.param||e,o.forceCss),!1}})},isSupportedBtn:function(e){try{return this.btnsDef[e].isSupported()}catch(t){}return!0},buildOverlay:function(){var e=this;return e.$overlay=a("",{"class":e.o.prefix+"overlay"}).appendTo(e.$box),e.$overlay},showOverlay:function(){var e=this;a(t).trigger("scroll"),e.$overlay.fadeIn(200),e.$box.addClass(e.o.prefix+"box-blur")},hideOverlay:function(){var e=this;e.$overlay.fadeOut(50),e.$box.removeClass(e.o.prefix+"box-blur")},fixedBtnPaneEvents:function(){var e=this,n=e.o.fixedFullWidth,o=e.$box;e.o.fixedBtnPane&&(e.isFixed=!1,a(t).on("scroll."+e.eventNamespace+" resize."+e.eventNamespace,function(){if(o){e.syncCode();var r=a(t).scrollTop(),i=o.offset().top+1,s=e.$btnPane,l=s.outerHeight()-2;r-i>0&&r-i-e.height<0?(e.isFixed||(e.isFixed=!0,s.css({position:"fixed",top:0,left:n?0:"auto",zIndex:7}),e.$box.css({paddingTop:s.height()})),s.css({width:n?"100%":o.width()-1}),a("."+e.o.prefix+"fixed-top",o).css({position:n?"fixed":"absolute",top:n?l:l+(r-i),zIndex:15})):e.isFixed&&(e.isFixed=!1,s.removeAttr("style"),e.$box.css({paddingTop:0}),a("."+e.o.prefix+"fixed-top",o).css({position:"absolute",top:l}))}}))},setDisabled:function(e){var t=this,n=t.o.prefix;t.disabled=e,e?t.$ta.attr("disabled",!0):t.$ta.removeAttr("disabled"),t.$box.toggleClass(n+"disabled",e),t.$ed.attr("contenteditable",!e)},destroy:function(){var e=this,n=e.o.prefix;e.isTextarea?e.$box.after(e.$ta.css({height:""}).val(e.html()).removeClass(n+"textarea").show()):e.$box.after(e.$ed.css({height:""}).removeClass(n+"editor").removeAttr("contenteditable").removeAttr("dir").html(e.html()).show()),e.$ed.off("dblclick","img"),e.destroyPlugins(),e.$box.remove(),e.$c.removeData("trumbowyg"),a("body").removeClass(n+"body-fullscreen"),e.$c.trigger("tbwclose"),a(t).off("scroll."+e.eventNamespace+" resize."+e.eventNamespace),a(e.doc.body).off("keydown."+e.eventNamespace)},empty:function(){this.$ta.val(""),this.syncCode(!0)},toggle:function(){var e=this,t=e.o.prefix;e.o.autogrowOnEnter&&(e.autogrowOnEnterDontClose=!e.$box.hasClass(t+"editor-hidden")),e.semanticCode(!1,!0),e.$c.trigger("tbwchange"),setTimeout(function(){e.doc.activeElement.blur(),e.$box.toggleClass(t+"editor-hidden "+t+"editor-visible"),e.$btnPane.toggleClass(t+"disable"),a("."+t+"viewHTML-button",e.$btnPane).toggleClass(t+"active"),e.$box.hasClass(t+"editor-visible")?e.$ta.attr("tabindex",-1):e.$ta.removeAttr("tabindex"),e.o.autogrowOnEnter&&!e.autogrowOnEnterDontClose&&e.autogrowEditorOnEnter()},0)},dropdown:function(e){var n=this,o=a("body",n.doc),r=n.o.prefix,i=a("[data-"+r+"dropdown="+e+"]",n.$box),s=a("."+r+e+"-button",n.$btnPane),l=i.is(":hidden");if(o.trigger("mousedown"),l){var d=s.offset().left;s.addClass(r+"active"),i.css({position:"absolute",top:s.offset().top-n.$btnPane.offset().top+s.outerHeight(),left:n.o.fixedFullWidth&&n.isFixed?d:d-n.$btnPane.offset().left}).show(),a(t).trigger("scroll"),o.on("mousedown."+n.eventNamespace,function(e){i.is(e.target)||(a("."+r+"dropdown",n.$box).hide(),a("."+r+"active",n.$btnPane).removeClass(r+"active"),o.off("mousedown."+n.eventNamespace))})}},html:function(e){var t=this;return null!=e?(t.$ta.val(e),t.syncCode(!0),t.$c.trigger("tbwchange"),t):t.$ta.val()},syncTextarea:function(){var e=this;e.$ta.val(e.$ed.text().trim().length>0||e.$ed.find(e.o.tagsToKeep.join(",")).length>0?e.$ed.html():"")},syncCode:function(e){var t=this;if(!e&&t.$ed.is(":visible"))t.syncTextarea();else{var n=a("