froala-editor
Version:
The next generation Javascript WYSIWYG HTML rich text editor made by devs for devs. High performance and modern design make it easy to use for developers and loved by users.
7 lines (6 loc) • 7.06 kB
JavaScript
/*!
* froala_editor v4.5.0 (https://www.froala.com/wysiwyg-editor)
* License https://froala.com/wysiwyg-editor/terms/
* Copyright 2014-2025 Froala Labs
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("froala-editor")):"function"==typeof define&&define.amd?define(["froala-editor"],t):t(e.FroalaEditor)}(this,function(v){"use strict";v=v&&v.hasOwnProperty("default")?v["default"]:v,Object.assign(v.DEFAULTS,{lineBreakerTags:["table","hr","form","dl","span.fr-video",".fr-embedly","img"],lineBreakerOffset:15,lineBreakerHorizontalOffset:10}),v.PLUGINS.lineBreaker=function(d){var m,t,r,h=d.$;function l(e,t){var n,a,r,o,i,s,l,f;if(null==e)i=(o=t.parent()).offset().top,n=(l=t.offset().top)-Math.min((l-i)/2,d.opts.lineBreakerOffset),r=o.outerWidth(),a=o.offset().left;else if(null==t)(s=(o=e.parent()).offset().top+o.outerHeight())<(f=e.offset().top+e.outerHeight())&&(s=(o=h(o).parent()).offset().top+o.outerHeight()),n=f+Math.min(Math.abs(s-f)/2,d.opts.lineBreakerOffset),r=o.outerWidth(),a=o.offset().left;else{o=e.parent();var p=e.offset().top+e.height(),c=t.offset().top;if(c<p)return!1;n=(p+c)/2,r=o.outerWidth(),a=o.offset().left}if(d.opts.iframe){var u=d.helpers.getPX(d.$wp.find(".fr-iframe").css("padding-top")),g=d.helpers.getPX(d.$wp.find(".fr-iframe").css("padding-left"));a+=d.$iframe.offset().left-d.helpers.scrollLeft()+g,n+=d.$iframe.offset().top-d.helpers.scrollTop()+u}d.$box.append(m),m.css("top",n-d.win.pageYOffset),m.css("left",a-d.win.pageXOffset),m.css("width",r),m.data("tag1",e),m.data("tag2",t),m.addClass("fr-visible").data("instance",d)}function f(e){if(e){var t=h(e);if(0===d.$el.find(t).length)return null;if(e.nodeType!=Node.TEXT_NODE&&t.is(d.opts.lineBreakerTags.join(",")))return t;if(0<t.parents(d.opts.lineBreakerTags.join(",")).length)return e=t.parents(d.opts.lineBreakerTags.join(",")).get(0),0!==d.$el.find(h(e)).length&&h(e).is(d.opts.lineBreakerTags.join(","))?h(e):null}return null}function o(e,t){var n=d.doc.elementFromPoint(e,t);return n&&!h(n).closest(".fr-line-breaker").length&&!d.node.isElement(n)&&n!=d.$wp.get(0)&&function a(e){if("undefined"!=typeof e.inFroalaWrapper)return e.inFroalaWrapper;for(var t=e;e.parentNode&&e.parentNode!==d.$wp.get(0);)e=e.parentNode;return t.inFroalaWrapper=e.parentNode==d.$wp.get(0),t.inFroalaWrapper}(n)?n:null}function i(e,t,n){for(var a=n,r=null;a<=d.opts.lineBreakerOffset&&!r;)(r=o(e,t-a))||(r=o(e,t+a)),a+=n;return r}function p(e,t,n){for(var a=null,r=100;!a&&e>d.$box.offset().left&&e<d.$box.offset().left+d.$box.outerWidth()&&0<r;)(a=o(e,t))||(a=i(e,t,5)),"left"==n?e-=d.opts.lineBreakerHorizontalOffset:e+=d.opts.lineBreakerHorizontalOffset,r-=d.opts.lineBreakerHorizontalOffset;return a}function n(e){var t=r=null,n=null,a=d.doc.elementFromPoint(e.pageX-d.win.pageXOffset,e.pageY-d.win.pageYOffset);(t=a&&("HTML"==a.tagName||"BODY"==a.tagName||d.node.isElement(a)||0<=(a.getAttribute("class")||"").indexOf("fr-line-breaker"))?((n=i(e.pageX-d.win.pageXOffset,e.pageY-d.win.pageYOffset,1))||(n=p(e.pageX-d.win.pageXOffset-d.opts.lineBreakerHorizontalOffset,e.pageY-d.win.pageYOffset,"left")),n||(n=p(e.pageX-d.win.pageXOffset+d.opts.lineBreakerHorizontalOffset,e.pageY-d.win.pageYOffset,"right")),f(n)):f(a))?function s(e,t){var n,a,r=e.offset().top,o=e.offset().top+e.outerHeight();if(Math.abs(o-t)<=d.opts.lineBreakerOffset||Math.abs(t-r)<=d.opts.lineBreakerOffset)if(Math.abs(o-t)<Math.abs(t-r)){var i=null;for((a=e.get(0)).nextSibling&&(i=a.nextSibling.offsetParent?a.nextSibling:null);i&&i.nodeType==Node.TEXT_NODE&&0===i.textContent.length;)i=i.nextSibling;if(!i)return l(e,null),!0;if(n=f(i))return l(e,n),!0}else{if(!(a=e.get(0)).previousSibling)return l(null,e),!0;if(n=f(a.previousSibling))return l(n,e),!0}m.removeClass("fr-visible").removeData("instance")}(t,e.pageY):d.core.sameInstance(m)&&m.removeClass("fr-visible").removeData("instance")}function a(e){return!(m.hasClass("fr-visible")&&!d.core.sameInstance(m))&&(d.popups.areVisible()||d.el.querySelector(".fr-selected-cell")?(m.removeClass("fr-visible"),!0):void(!1!==t||d.edit.isDisabled()||(r&&clearTimeout(r),r=setTimeout(n,30,e))))}function s(){r&&clearTimeout(r),m&&m.hasClass("fr-visible")&&m.removeClass("fr-visible").removeData("instance")}var c=function c(){t=!0,s()},u=function u(){t=!1};function g(e){e.preventDefault();var t=m.data("instance")||d;m.removeClass("fr-visible").removeData("instance");var n=m.data("tag1"),a=m.data("tag2"),r=d.html.defaultTag();if(null==n)if(d.opts.keepTextFormatOnTable&&a.children().get(0)!=undefined&&"TBODY"==a.children().get(0).tagName){var o=a.find("span"),i=null!=o[o.length-1]?o[o.length-1].getAttribute("style"):null,s=null!=i?"<"+o[o.length-1].nodeName.toLowerCase()+' style="'+i+'">':"<"+a.parent().get(0).nodeName.toLowerCase()+">",l=null!=i?"</"+o[o.length-1].nodeName.toLowerCase()+">":"</"+a.parent().get(0).nodeName.toLowerCase()+">";r?a.before("<".concat(r,">").concat(s).concat(v.MARKERS,"<br>").concat(l,"</").concat(r,">")):a.before("".concat(s).concat(v.MARKERS,"<br>").concat(l))}else r&&"TD"!=a.parent().get(0).tagName&&0===a.parents(r).length?a.before("<".concat(r,">").concat(v.MARKERS,"<br></").concat(r,">")):a.before("".concat(v.MARKERS,"<br>"));else if(d.opts.keepTextFormatOnTable&&n.children().get(0)!=undefined&&"TBODY"==n.children().get(0).tagName){var f=n.find("span"),p=null!=f[f.length-1]?f[f.length-1].getAttribute("style"):null,c=null!=p?"<"+f[f.length-1].nodeName.toLowerCase()+' style="'+p+'">':"<"+n.parent().get(0).nodeName.toLowerCase()+">",u=null!=p?"</"+f[f.length-1].nodeName.toLowerCase()+">":"</"+n.parent().get(0).nodeName.toLowerCase()+">";r?n.after("<".concat(r,">").concat(c).concat(v.MARKERS,"<br>").concat(u,"</").concat(r,">")):n.after("".concat(c).concat(v.MARKERS,"<br>").concat(u))}else r&&"TD"!=n.parent().get(0).tagName&&0===n.parents(r).length?n.after("<".concat(r,">").concat(v.MARKERS,"<br></").concat(r,">")):n.after("".concat(v.MARKERS,"<br>"));t.selection.restore(),d.toolbar.enable()}return{_init:function b(){if(!d.$wp)return!1;!function e(){d.shared.$line_breaker||(d.shared.$line_breaker=h(document.createElement("div")).attr("class","fr-line-breaker").html('<a class="fr-floating-btn" role="button" tabIndex="-1" title="'.concat(d.language.translate("Break"),'"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="17" y="7" width="2" height="8"/><rect x="10" y="13" width="7" height="2"/><path d="M10.000,10.000 L10.000,18.013 L5.000,14.031 L10.000,10.000 Z"/></svg></a>'))),m=d.shared.$line_breaker,d.events.on("shared.destroy",function(){m.html("").removeData().remove(),m=null},!0),d.events.on("destroy",function(){m.removeData("instance").removeClass("fr-visible"),h("body").first().append(m),clearTimeout(r)},!0),d.events.$on(m,"mousemove",function(e){e.stopPropagation()},!0),d.events.bindClick(m,"a",g)}(),t=!1,d.events.$on(d.$win,"mousemove",a),d.events.$on(h(d.win),"scroll",s),d.events.on("popups.show.table.edit",s),d.events.on("commands.after",s),d.events.$on(h(d.win),"mousedown",c),d.events.$on(h(d.win),"mouseup",u)}}}});