2016-05-19 18:35:40 +00:00
|
|
|
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&module.exports?module.exports=function(b,c){return void 0===c&&(c="undefined"!=typeof window?require("jquery"):require("jquery")(b)),a(c),c}:a(jQuery)}(function(a){"use strict";var b=function(c,d){this.id=++a.FE.ID,this.opts=a.extend(!0,{},a.extend({},b.DEFAULTS,"object"==typeof d&&d));var e=JSON.stringify(this.opts);a.FE.OPTS_MAPPING[e]=a.FE.OPTS_MAPPING[e]||this.id,this.sid=a.FE.OPTS_MAPPING[e],a.FE.SHARED[this.sid]=a.FE.SHARED[this.sid]||{},this.shared=a.FE.SHARED[this.sid],this.shared.count=(this.shared.count||0)+1,this.$oel=a(c),this.$oel.data("froala.editor",this),this.o_doc=c.ownerDocument,this.o_win="defaultView"in this.o_doc?this.o_doc.defaultView:this.o_doc.parentWindow;var f=a(this.o_win).scrollTop();this.$oel.on("froala.doInit",a.proxy(function(){this.$oel.off("froala.doInit"),this.doc=this.$el.get(0).ownerDocument,this.win="defaultView"in this.doc?this.doc.defaultView:this.doc.parentWindow,this.$doc=a(this.doc),this.$win=a(this.win),this.opts.pluginsEnabled||(this.opts.pluginsEnabled=Object.keys(a.FE.PLUGINS)),this.opts.initOnClick?(this.load(a.FE.MODULES),this.$el.on("mousedown.init touchstart.init dragenter.init focus.init",a.proxy(function(b){if(1===b.which||0===b.which){this.$el.off("mousedown.init dragenter.init focus.init touchstart.init"),this.load(a.FE.MODULES),this.load(a.FE.PLUGINS);var c=b.originalEvent&&b.originalEvent.originalTarget;c&&"IMG"==c.tagName&&a(c).trigger("mousedown"),"undefined"==typeof this.ul&&this.destroy(),this.events.trigger("initialized")}},this))):(this.load(a.FE.MODULES),this.load(a.FE.PLUGINS),a(this.o_win).scrollTop(f),"undefined"==typeof this.ul&&this.destroy(),this.events.trigger("initialized"))},this)),this._init()};b.DEFAULTS={initOnClick:!1,pluginsEnabled:null},b.MODULES={},b.PLUGINS={},b.VERSION="2.2.4",b.INSTANCES=[],b.OPTS_MAPPING={},b.SHARED={},b.ID=0,b.prototype._init=function(){var b=this.$oel.prop("tagName"),c=a.proxy(function(){this._original_html=this._original_html||this.$oel.html(),this.$box=this.$box||this.$oel,this.opts.fullPage&&(this.opts.iframe=!0),this.opts.iframe?(this.$iframe=a('<iframe src="about:blank" frameBorder="0">'),this.$wp=a("<div></div>"),this.$box.html(this.$wp),this.$wp.append(this.$iframe),this.$iframe.get(0).contentWindow.document.open(),this.$iframe.get(0).contentWindow.document.write("<!DOCTYPE html>"),this.$iframe.get(0).contentWindow.document.write("<html><head></head><body></body></html>"),this.$iframe.get(0).contentWindow.document.close(),this.$el=this.$iframe.contents().find("body"),this.$head=this.$iframe.contents().find("head"),this.$html=this.$iframe.contents().find("html"),this.iframe_document=this.$iframe.get(0).contentWindow.document,this.$oel.trigger("froala.doInit")):(this.$el=a("<div></div>"),this.$wp=a("<div></div>").append(this.$el),this.$box.html(this.$wp),this.$oel.trigger("froala.doInit"))},this),d=a.proxy(function(){this.$box=a("<div>"),this.$oel.before(this.$box).hide(),this._original_html=this.$oel.val(),this.$oel.parents("form").on("submit."+this.id,a.proxy(function(){this.events.trigger("form.submit")},this)),this.$oel.parents("form").on("reset."+this.id,a.proxy(function(){this.events.trigger("form.reset")},this)),c()},this),e=a.proxy(function(){this.$el=this.$oel,this.$el.attr("contenteditable",!0).css("outline","none").css("display","inline-block"),this.opts.multiLine=!1,this.opts.toolbarInline=!1,this.$oel.trigger("froala.doInit")},this),f=a.proxy(function(){this.$el=this.$oel,this.opts.toolbarInline=!1,this.$oel.trigger("froala.doInit")},this),g=a.proxy(function(){this.$el=this.$oel,this.opts.toolbarInline=!1,this.$oel.on("click.popup",function(a){a.preventDefault()}),this.$oel.trigger("froala.doInit")},this);this.opts.editInPopup?g():"TEXTAREA"==b?d():"A"==b?e():"IMG"==b?f():"BUTTON"==b||"INPUT"==b?(this.opts.editInPopup=!0,this.opts.toolbarInline=!1,g()):c()},b.prototype.load=function(b){for(var c in b)if(b.hasOwnProperty(c)){if(this[c])continue;if(a.FE.PLUGINS[c]&&this.opts.pluginsEnabled.indexOf(c)<0)contin
|
|
|
|
|
else{jQuery=require('jquery')(root);}}
|
|
|
|
|
factory(jQuery);return jQuery;};}else{factory(jQuery);}}(function($){'use strict';$.FE.PLUGINS.fullscreen=function(editor){var old_scroll;function isActive(){return editor.$box.hasClass('fr-fullscreen');}
|
|
|
|
|
var $placeholder;var height;var max_height;function _on(){old_scroll=$(editor.o_win).scrollTop();editor.$box.toggleClass('fr-fullscreen');$('body').toggleClass('fr-fullscreen');$placeholder=$('<div style="display: none;"></div>');editor.$box.after($placeholder);if(editor.helpers.isMobile()){editor.$tb.data('parent',editor.$tb.parent());editor.$tb.prependTo(editor.$box);if(editor.$tb.data('sticky-dummy')){editor.$tb.after(editor.$tb.data('sticky-dummy'));}}
|
|
|
|
|
height=editor.opts.height;max_height=editor.opts.heightMax;editor.opts.height=editor.o_win.innerHeight-(editor.opts.toolbarInline?0:editor.$tb.outerHeight());editor.size.refresh();if(editor.opts.toolbarInline)editor.toolbar.showInline();editor.events.trigger('charCounter.update');editor.$win.trigger('scroll');}
|
|
|
|
|
function _off(){editor.$box.toggleClass('fr-fullscreen');$('body').toggleClass('fr-fullscreen');editor.$tb.prependTo(editor.$tb.data('parent'));if(editor.$tb.data('sticky-dummy')){editor.$tb.after(editor.$tb.data('sticky-dummy'));}
|
|
|
|
|
editor.opts.height=height;editor.opts.heightMax=max_height;editor.size.refresh();$(editor.o_win).scrollTop(old_scroll)
|
|
|
|
|
if(editor.opts.toolbarInline)editor.toolbar.showInline();editor.events.trigger('charCounter.update');if(editor.opts.toolbarSticky){if(editor.opts.toolbarStickyOffset){if(editor.opts.toolbarBottom){editor.$tb.css('bottom',editor.opts.toolbarStickyOffset).data('bottom',editor.opts.toolbarStickyOffset);}
|
|
|
|
|
else{editor.$tb.css('top',editor.opts.toolbarStickyOffset).data('top',editor.opts.toolbarStickyOffset);}}}
|
|
|
|
|
editor.$win.trigger('scroll');}
|
|
|
|
|
function toggle(){if(!isActive()){_on();}
|
|
|
|
|
else{_off();}
|
|
|
|
|
refresh(editor.$tb.find('.fr-command[data-cmd="fullscreen"]'));$(window).trigger('oc.updateUi')}
|
|
|
|
|
function refresh($btn){var active=isActive();$btn.toggleClass('fr-active',active);$btn.find('i').toggleClass('fa-expand',!active).toggleClass('fa-compress',active);}
|
|
|
|
|
function _init(){if(!editor.$wp)return false;editor.events.$on($(editor.o_win),'resize',function(){if(isActive()){_off();_on();}});editor.events.on('toolbar.hide',function(){if(isActive()&&editor.helpers.isMobile())return false;})}
|
|
|
|
|
return{_init:_init,toggle:toggle,refresh:refresh,isActive:isActive}}
|
|
|
|
|
$.FE.RegisterCommand('fullscreen',{title:'Fullscreen',undo:false,focus:false,forcedRefresh:true,callback:function(){this.fullscreen.toggle();},refresh:function($btn){this.fullscreen.refresh($btn);},plugin:'fullscreen'})
|
|
|
|
|
$.FE.DefineIcon('fullscreen',{NAME:'expand'});}));(function(factory){if(typeof define==='function'&&define.amd){define(['jquery'],factory);}else if(typeof module==='object'&&module.exports){module.exports=function(root,jQuery){if(jQuery===undefined){if(typeof window!=='undefined'){jQuery=require('jquery');}
|
|
|
|
|
else{jQuery=require('jquery')(root);}}
|
|
|
|
|
factory(jQuery);return jQuery;};}else{factory(jQuery);}}(function($){'use strict';$.extend($.FE.DEFAULTS,{aceEditor:true,aceEditorOptions:{showLineNumbers:true,useSoftTabs:false,wrap:true,mode:'ace/mode/html',tabSize:2},codeBeautifierOptions:{end_with_newline:true,indent_inner_html:true,extra_liners:['p','h1','h2','h3','h4','h5','h6','blockquote','pre','ul','ol','table','dl'],brace_style:'expand',indent_char:'\t',indent_size:1,wrap_line_length:0}})
|
|
|
|
|
$.FE.PLUGINS.codeView=function(editor){var $html_area;var ace_editor;function isActive(){return editor.$box.hasClass('fr-code-view');}
|
|
|
|
|
function get(){if(ace_editor){return ace_editor.getValue();}else{return $html_area.val();}}
|
|
|
|
|
function _showText($btn){var html=get();editor.html.set(html);editor.$el.blur();editor.$tb.find(' > .fr-command').not($btn).removeClass('fr-disabled');$btn.removeClass('fr-active');editor.events.focus(true);editor.placeholder.refresh();editor.undo.saveStep();}
|
|
|
|
|
function _showHTML($btn,height){if(!$html_area)_initArea();if(!ace_editor&&editor.opts.aceEditor&&typeof ace!='undefined'){ace_editor=ace.edit($html_area.get(0));ace_editor.setOptions(editor.opts.aceEditorOptions);}
|
|
|
|
|
editor.undo.saveStep();editor.html.cleanEmptyTags();editor.html.cleanWhiteTags(true);if(editor.core.hasFocus()){if(!editor.core.isEmpty()){editor.selection.save();editor.$el.find('.fr-marker[data-type="true"]:first').replaceWith('<span class="fr-tmp fr-sm">F</span>');editor.$el.find('.fr-marker[data-type="false"]:last').replaceWith('<span class="fr-tmp fr-em">F</span>');}
|
|
|
|
|
editor.$el.blur();}
|
|
|
|
|
var html=editor.html.get(false,true);editor.$el.find('span.fr-tmp').remove();html=html.replace(/<span class="fr-tmp fr-sm">F<\/span>/,'FROALA-SM');html=html.replace(/<span class="fr-tmp fr-em">F<\/span>/,'FROALA-EM');if(editor.codeBeautifier){html=editor.codeBeautifier.run(html,editor.opts.codeBeautifierOptions);}
|
|
|
|
|
var s_index;var e_index;if(ace_editor){s_index=html.indexOf('FROALA-SM');e_index=html.indexOf('FROALA-EM');if(s_index>e_index){s_index=e_index;}
|
|
|
|
|
else{e_index=e_index-9;}
|
|
|
|
|
html=html.replace(/FROALA-SM/g,'').replace(/FROALA-EM/g,'')
|
|
|
|
|
var s_line=html.substring(0,s_index).length-html.substring(0,s_index).replace(/\n/g,'').length;var e_line=html.substring(0,e_index).length-html.substring(0,e_index).replace(/\n/g,'').length;s_index=html.substring(0,s_index).length-html.substring(0,html.substring(0,s_index).lastIndexOf('\n')+1).length;e_index=html.substring(0,e_index).length-html.substring(0,html.substring(0,e_index).lastIndexOf('\n')+1).length;ace_editor.$blockScrolling=Infinity
|
|
|
|
|
ace_editor.getSession().setValue(html);ace_editor.focus();ace_editor.selection.moveCursorToPosition({row:s_line,column:s_index});ace_editor.selection.selectToPosition({row:e_line,column:e_index});ace_editor.resize();ace_editor.session.getUndoManager().reset();}
|
|
|
|
|
else{s_index=html.indexOf('FROALA-SM');e_index=html.indexOf('FROALA-EM')-9;$html_area.css('height',height);if(editor.opts.height||editor.opts.heightMax){$html_area.css('max-height',editor.opts.height||editor.opts.heightMax);}
|
|
|
|
|
$html_area.val(html.replace(/FROALA-SM/g,'').replace(/FROALA-EM/g,''));$html_area.focus();$html_area.get(0).setSelectionRange(s_index,e_index);}
|
|
|
|
|
editor.$tb.find(' > .fr-command').not($btn).addClass('fr-disabled');$btn.addClass('fr-active');if(!editor.helpers.isMobile()&&editor.opts.toolbarInline){editor.toolbar.hide();}}
|
|
|
|
|
function toggle(val){if(typeof val=='undefined')val=!isActive();var $btn=editor.$tb.find('.fr-command[data-cmd="html"]');if(!val){editor.$box.toggleClass('fr-code-view',false);_showText($btn);}else{editor.popups.hideAll();var height=editor.$wp.outerHeight();editor.$box.toggleClass('fr-code-view',true);_showHTML($btn,height);}}
|
|
|
|
|
function _destroy(){if(isActive()){toggle(editor.$tb.find('button[data-cmd="html"]'));$html_area.val('').removeData().remove();}
|
|
|
|
|
if($back_button)$back_button.remove();}
|
|
|
|
|
function _initArea(){$html_area=$('<textarea class="fr-code" tabindex="-1">');editor.$wp.append($html_area);$html_area.attr('dir',editor.opts.direction);if(editor.opts.toolbarInline){$back_button=$('<a data-cmd="html" title="Code View" class="fr-command fr-btn html-switch'+(editor.helpers.isMobile()?'':' fr-desktop')+'" role="button" tabindex="-1"><i class="fa fa-code"></i></button>');editor.$box.append($back_button);editor.events.bindClick(editor.$box,'a.html-switch',function(){toggle(false);});}
|
|
|
|
|
var cancel=function(){return!isActive();}
|
|
|
|
|
editor.events.on('buttons.refresh',cancel);editor.events.on('copy',cancel,true);editor.events.on('cut',cancel,true);editor.events.on('paste',cancel,true);editor.events.on('destroy',_destroy,true);editor.events.on('html.set',function(){if(isActive())toggle(true);});editor.events.on('form.submit',function(){if(isActive()){editor.html.set(get());editor.events.trigger('contentChanged',[],true);}},true);}
|
|
|
|
|
var $back_button;function _init(){if(!editor.$wp)return false;}
|
|
|
|
|
return{_init:_init,toggle:toggle,isActive:isActive,get:get}};$.FE.RegisterCommand('html',{title:'Code View',undo:false,focus:false,forcedRefresh:true,callback:function(){this.codeView.toggle();},plugin:'codeView'})
|
|
|
|
|
$.FE.DefineIcon('html',{NAME:'code'});}));!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&module.exports?module.exports=function(b,c){return void 0===c&&(c="undefined"!=typeof window?require("jquery"):require("jquery")(b)),a(c),c}:a(jQuery)}(function(a){"use strict";a.extend(a.FE.DEFAULTS,{paragraphFormat:{N:"Normal",H1:"Heading 1",H2:"Heading 2",H3:"Heading 3",H4:"Heading 4",PRE:"Code"},paragraphFormatSelection:!1}),a.FE.PLUGINS.paragraphFormat=function(b){function c(c,d){var e=b.html.defaultTag();if(d&&d.toLowerCase()!=e)if(c.find("ul, ol").length>0){var f=a("<"+d+">");c.prepend(f);for(var g=b.node.contents(c.get(0))[0];g&&["UL","OL"].indexOf(g.tagName)<0;){var h=g.nextSibling;f.append(g),g=h}}else c.html("<"+d+">"+c.html()+"</"+d+">")}function d(c,d){var e=b.html.defaultTag();d||(d='div class="fr-temp-div" data-empty="true"'),d.toLowerCase()==e?c.replaceWith(c.html()):c.replaceWith(a("<"+d+">").html(c.html()))}function e(c,d){var e=b.html.defaultTag();d||(d='div class="fr-temp-div"'+(b.node.isEmpty(c.get(0),!0)?' data-empty="true"':"")),d.toLowerCase()==e?(b.node.isEmpty(c.get(0),!0)||c.append("<br/>"),c.replaceWith(c.html())):c.replaceWith(a("<"+d+">").html(c.html()))}function f(c,d){d||(d='div class="fr-temp-div"'+(b.node.isEmpty(c.get(0),!0)?' data-empty="true"':"")),c.replaceWith(a("<"+d+" "+b.node.attributes(c.get(0))+">").html(c.html()))}function g(g){"N"==g&&(g=b.html.defaultTag()),b.selection.save(),b.html.wrap(!0,!0,!0,!0),b.selection.restore();var h=b.selection.blocks();b.selection.save(),b.$el.find("pre").attr("skip",!0);for(var i=0;i<h.length;i++)if(h[i].tagName!=g&&!b.node.isList(h[i])){var j=a(h[i]);"LI"==h[i].tagName?c(j,g):"LI"==h[i].parentNode.tagName&&h[i]?d(j,g):["TD","TH"].indexOf(h[i].parentNode.tagName)>=0?e(j,g):f(j,g)}b.$el.find('pre:not([skip="true"]) + pre:not([skip="true"])').each(function(){a(this).prev().append("<br>"+a(this).html()),a(this).remove()}),b.$el.find("pre").removeAttr("skip"),b.html.unwrap(),b.selection.restore()}function h(a,c){var d=b.selection.blocks();if(d.length){var e=d[0],f="N",g=b.html.defaultTag();e.tagName.toLowerCase()!=g&&e!=b.$el.get(0)&&(f=e.tagName),c.find('.fr-command[data-param1="'+f+'"]').addClass("fr-active")}else c.find('.fr-command[data-param1="N"]').addClass("fr-active")}function i(a){if(b.opts.paragraphFormatSelection){var c=b.selection.blocks();if(c.length){var d=c[0],e="N",f=b.html.defaultTag();d.tagName.toLowerCase()!=f&&d!=b.$el.get(0)&&(e=d.tagName),["LI","TD","TH"].indexOf(e)>=0&&(e="N"),a.find("> span").text(b.opts.paragraphFormat[e])}else a.find("> span").text(edior.opts.paragraphFormat.N)}}return{apply:g,refreshOnShow:h,refresh:i}},a.FE.RegisterCommand("paragraphFormat",{type:"dropdown",displaySelection:function(a){return a.opts.paragraphFormatSelection},defaultSelection:"Normal",displaySelectionWidth:100,html:function(){var a='<ul class="fr-dropdown-list">',b=this.opts.paragraphFormat;for(var c in b)b.hasOwnProperty(c)&&(a+="<li><"+c+' style="padding: 0 !important; margin: 0 !important;"><a class="fr-command" data-cmd="paragraphFormat" data-param1="'+c+'" title="'+this.language.translate(b[c])+'">'+this.language.translate(b[c])+"</a></"+c+"></li>");return a+="</ul>"},title:"Paragraph Format",callback:function(a,b){this.paragraphFormat.apply(b)},refresh:function(a){this.paragraphFormat.refresh(a)},refreshOnShow:function(a,b){this.paragraphFormat.refreshOnShow(a,b)},plugin:"paragraphFormat"}),a.FE.DefineIcon("paragraphFormat",{NAME:"paragraph"})});!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&module.exports?module.exports=function(b,c){return void 0===c&&(c="undefined"!=typeof window?require("jquery"):require("jquery")(b)),a(c),c}:a(jQuery)}(function(a){"use strict";a.FE.PLUGINS.align=function(b){function c(c){b.selection.save(),b.html.wrap(!0,!0,!0,!0),b.selection.restore();for(var d=b.selection.blocks(),e=0;e<d.length;e++)a(d[e]).css("text-align",c).removeClass("fr-temp-div"),""===a(d[e]).attr("class")&&a(d[e]).removeAttr("class");b.selection.sa
|
|
|
|
|
else{jQuery=require('jquery')(root);}}
|
|
|
|
|
factory(jQuery);return jQuery;};}else{factory(jQuery);}}(function($){'use strict';$.extend($.FE.POPUP_TEMPLATES,{'link.edit':'[_BUTTONS_]','link.insert':'[_BUTTONS_][_INPUT_LAYER_]'})
|
|
|
|
|
$.extend($.FE.DEFAULTS,{linkEditButtons:['linkOpen','linkStyle','linkEdit','linkRemove'],linkInsertButtons:['linkBack','|','linkList'],linkAttributes:{},linkAutoPrefix:'http://',linkStyles:{'fr-green':'Green','fr-strong':'Thick'},linkMultipleStyles:true,linkConvertEmailAddress:true,linkAlwaysBlank:false,linkAlwaysNoFollow:false,linkList:[{text:'Froala',href:'https://froala.com',target:'_blank'},{text:'Google',href:'https://google.com',target:'_blank'},{displayText:'Facebook',href:'https://facebook.com'}],linkText:true});$.FE.PLUGINS.link=function(editor){function get(){var $current_image=editor.image?editor.image.get():null;if(!$current_image&&editor.$wp){var s_el=editor.selection.element();var e_el=editor.selection.endElement();if(s_el.tagName!='A'){s_el=$(s_el).parents('a:first').get(0);}
|
|
|
|
|
if(e_el.tagName!='A'){e_el=$(e_el).parents('a:first').get(0);}
|
|
|
|
|
if(e_el&&e_el==s_el){return s_el;}
|
|
|
|
|
return null;}
|
|
|
|
|
else if(editor.$el.get(0).tagName=='A'&&editor.core.hasFocus()){return editor.$el.get(0);}
|
|
|
|
|
else{if($current_image&&$current_image.get(0).parentNode&&$current_image.get(0).parentNode.tagName=='A'){return $current_image.get(0).parentNode;}}}
|
|
|
|
|
function allSelected(){var $current_image=editor.image?editor.image.get():null;var selectedLinks=[];if($current_image){if($current_image.get(0).parentNode.tagName=='A'){selectedLinks.push($current_image.get(0).parentNode);}}
|
|
|
|
|
else{var range;var containerEl;var links;var linkRange;if(editor.win.getSelection){var sel=editor.win.getSelection();if(sel.getRangeAt&&sel.rangeCount){linkRange=editor.doc.createRange();for(var r=0;r<sel.rangeCount;++r){range=sel.getRangeAt(r);containerEl=range.commonAncestorContainer;if(containerEl&&containerEl.nodeType!=1){containerEl=containerEl.parentNode;}
|
|
|
|
|
if(containerEl&&containerEl.nodeName.toLowerCase()=='a'){selectedLinks.push(containerEl);}else{links=containerEl.getElementsByTagName('a');for(var i=0;i<links.length;++i){linkRange.selectNodeContents(links[i]);if(linkRange.compareBoundaryPoints(range.END_TO_START,range)<1&&linkRange.compareBoundaryPoints(range.START_TO_END,range)>-1){selectedLinks.push(links[i]);}}}}}}else if(editor.doc.selection&&editor.doc.selection.type!='Control'){range=editor.doc.selection.createRange();containerEl=range.parentElement();if(containerEl.nodeName.toLowerCase()=='a'){selectedLinks.push(containerEl);}else{links=containerEl.getElementsByTagName('a');linkRange=editor.doc.body.createTextRange();for(var j=0;j<links.length;++j){linkRange.moveToElementText(links[j]);if(linkRange.compareEndPoints('StartToEnd',range)>-1&&linkRange.compareEndPoints('EndToStart',range)<1){selectedLinks.push(links[j]);}}}}}
|
|
|
|
|
return selectedLinks;}
|
|
|
|
|
function _edit(e){_hideEditPopup();setTimeout(function(){if(!e||(e&&(e.which==1||e.type!='mouseup'))){var link=get();var $current_image=editor.image?editor.image.get():null;if(link&&!$current_image){if(editor.image){var contents=editor.node.contents(link);if(contents.length==1&&contents[0].tagName=='IMG'){var range=editor.selection.ranges(0);if(range.startOffset===0&&range.endOffset===0){$(link).before($.FE.MARKERS);}
|
|
|
|
|
else{$(link).after($.FE.MARKERS);}
|
|
|
|
|
editor.selection.restore();return false;}}
|
|
|
|
|
if(e){e.stopPropagation();}
|
|
|
|
|
_showEditPopup(link);}}},editor.helpers.isIOS()?100:0);}
|
|
|
|
|
function _showEditPopup(link){var $popup=editor.popups.get('link.edit');if(!$popup)$popup=_initEditPopup();var $link=$(link);if(!editor.popups.isVisible('link.edit')){editor.popups.refresh('link.edit');}
|
|
|
|
|
editor.popups.setContainer('link.edit',$(editor.opts.scrollableContainer));var left=$link.offset().left+$(link).outerWidth()/2;var top=$link.offset().top+$link.outerHeight();editor.popups.show('link.edit',left,top,$link.outerHeight());}
|
|
|
|
|
function _hideEditPopup(){editor.popups.hide('link.edit');}
|
|
|
|
|
function _initEditPopup(){var link_buttons='';if(editor.opts.linkEditButtons.length>1){if(editor.$el.get(0).tagName=='A'&&editor.opts.linkEditButtons.indexOf('linkRemove')>=0){editor.opts.linkEditButtons.splice(editor.opts.linkEditButtons.indexOf('linkRemove'),1);}
|
|
|
|
|
link_buttons='<div class="fr-buttons">'+editor.button.buildList(editor.opts.linkEditButtons)+'</div>';}
|
|
|
|
|
var template={buttons:link_buttons};var $popup=editor.popups.create('link.edit',template);if(editor.$wp){editor.events.$on(editor.$wp,'scroll.link-edit',function(){if(get()&&editor.popups.isVisible('link.edit')){_showEditPopup(get());}});}
|
|
|
|
|
return $popup;}
|
|
|
|
|
function _hideInsertPopup(){}
|
|
|
|
|
function _refreshInsertPopup(){var $popup=editor.popups.get('link.insert');var link=get();if(link){var $link=$(link);var text_inputs=$popup.find('input.fr-link-attr[type="text"]');var check_inputs=$popup.find('input.fr-link-attr[type="checkbox"]');var i;var $input;for(i=0;i<text_inputs.length;i++){$input=$(text_inputs[i]);$input.val($link.attr($input.attr('name')||''));}
|
|
|
|
|
check_inputs.prop('checked',false);for(i=0;i<check_inputs.length;i++){$input=$(check_inputs[i]);if($link.attr($input.attr('name'))==$input.data('checked')){$input.prop('checked',true);}}
|
|
|
|
|
$popup.find('input.fr-link-attr[type="text"][name="text"]').val($link.text());}
|
|
|
|
|
else{$popup.find('input.fr-link-attr[type="text"]').val('');$popup.find('input.fr-link-attr[type="checkbox"]').prop('checked',false);$popup.find('input.fr-link-attr[type="text"][name="text"]').val(editor.selection.text());}
|
|
|
|
|
$popup.find('input.fr-link-attr').trigger('change');var $current_image=editor.image?editor.image.get():null;if($current_image){$popup.find('.fr-link-attr[name="text"]').parent().hide();}
|
|
|
|
|
else{$popup.find('.fr-link-attr[name="text"]').parent().show();}}
|
|
|
|
|
function _showInsertPopup(){var $btn=editor.$tb.find('.fr-command[data-cmd="insertLink"]');var $popup=editor.popups.get('link.insert');if(!$popup)$popup=_initInsertPopup();if(!$popup.hasClass('fr-active')){editor.popups.refresh('link.insert');editor.popups.setContainer('link.insert',editor.$tb||$(editor.opts.scrollableContainer));if($btn.is(':visible')){var left=$btn.offset().left+$btn.outerWidth()/2;var top=$btn.offset().top+(editor.opts.toolbarBottom?10:$btn.outerHeight()-10);editor.popups.show('link.insert',left,top,$btn.outerHeight());}
|
|
|
|
|
else{editor.position.forSelection($popup);editor.popups.show('link.insert');}}}
|
|
|
|
|
function _initInsertPopup(delayed){if(delayed){editor.popups.onRefresh('link.insert',_refreshInsertPopup);editor.popups.onHide('link.insert',_hideInsertPopup);return true;}
|
|
|
|
|
var link_buttons='';if(editor.opts.linkInsertButtons.length>=1){link_buttons='<div class="fr-buttons">'+editor.button.buildList(editor.opts.linkInsertButtons)+'</div>';}
|
|
|
|
|
var checkmark='<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="10" height="10" viewBox="0 0 32 32"><path d="M27 4l-15 15-7-7-5 5 12 12 20-20z" fill="#FFF"></path></svg>';var input_layer='';var tab_idx=0;input_layer='<div class="fr-link-insert-layer fr-layer fr-active" id="fr-link-insert-layer-'+editor.id+'">';input_layer+='<div class="fr-input-line"><input name="href" type="text" class="fr-link-attr" placeholder="URL" tabIndex="'+(++tab_idx)+'"></div>';if(editor.opts.linkText){input_layer+='<div class="fr-input-line"><input name="text" type="text" class="fr-link-attr" placeholder="'+editor.language.translate('Text')+'" tabIndex="'+(++tab_idx)+'"></div>';}
|
|
|
|
|
for(var attr in editor.opts.linkAttributes){if(editor.opts.linkAttributes.hasOwnProperty(attr)){var placeholder=editor.opts.linkAttributes[attr];input_layer+='<div class="fr-input-line"><input name="'+attr+'" type="text" class="fr-link-attr" placeholder="'+editor.language.translate(placeholder)+'" tabIndex="'+(++tab_idx)+'"></div>';}}
|
|
|
|
|
if(!editor.opts.linkAlwaysBlank){input_layer+='<div class="fr-checkbox-line"><span class="fr-checkbox"><input name="target" class="fr-link-attr" data-checked="_blank" type="checkbox" id="fr-link-target-'+editor.id+'" tabIndex="'+(++tab_idx)+'"><span>'+checkmark+'</span></span><label for="fr-link-target-'+editor.id+'">'+editor.language.translate('Open in new tab')+'</label></div>';}
|
|
|
|
|
input_layer+='<div class="fr-action-buttons"><button class="fr-command fr-submit" data-cmd="linkInsert" href="#" tabIndex="'+(++tab_idx)+'" type="button">'+editor.language.translate('Insert')+'</button></div></div>'
|
|
|
|
|
var template={buttons:link_buttons,input_layer:input_layer}
|
|
|
|
|
var $popup=editor.popups.create('link.insert',template);if(editor.$wp){editor.events.$on(editor.$wp,'scroll.link-insert',function(){var $current_image=editor.image?editor.image.get():null;if($current_image&&editor.popups.isVisible('link.insert')){imageLink();}
|
|
|
|
|
if(get&&editor.popups.isVisible('link.insert')){update();}});}
|
|
|
|
|
return $popup;}
|
|
|
|
|
function remove(){var link=get();var $current_image=editor.image?editor.image.get():null;if(editor.events.trigger('link.beforeRemove',[link])===false)return false;if($current_image&&link){$current_image.unwrap();editor.image.edit($current_image);}
|
|
|
|
|
else if(link){editor.selection.save();$(link).replaceWith($(link).html());editor.selection.restore();_hideEditPopup();}}
|
|
|
|
|
function _init(){editor.events.on('keyup',function(e){if(e.which!=$.FE.KEYCODE.ESC){_edit(e);}});editor.events.on('window.mouseup',_edit);if(editor.helpers.isMobile()){editor.events.$on(editor.$doc,'selectionchange',_edit);}
|
|
|
|
|
_initInsertPopup(true);if(editor.$el.get(0).tagName=='A'){editor.$el.addClass('fr-view');}}
|
|
|
|
|
function usePredefined(val){var link=editor.opts.linkList[val];var $popup=editor.popups.get('link.insert');var text_inputs=$popup.find('input.fr-link-attr[type="text"]');var check_inputs=$popup.find('input.fr-link-attr[type="checkbox"]');var $input;var i;for(i=0;i<text_inputs.length;i++){$input=$(text_inputs[i]);if(link[$input.attr('name')]){$input.val(link[$input.attr('name')]);}
|
|
|
|
|
else if($input.attr('name')!='text'){$input.val('');}}
|
|
|
|
|
for(i=0;i<check_inputs.length;i++){$input=$(check_inputs[i]);$input.prop('checked',$input.data('checked')==link[$input.attr('name')]);}}
|
|
|
|
|
function insertCallback(){var $popup=editor.popups.get('link.insert');var text_inputs=$popup.find('input.fr-link-attr[type="text"]');var check_inputs=$popup.find('input.fr-link-attr[type="checkbox"]');var href=text_inputs.filter('[name="href"]').val();var text=text_inputs.filter('[name="text"]').val();var attrs={};var $input;var i;for(i=0;i<text_inputs.length;i++){$input=$(text_inputs[i]);if(['href','text'].indexOf($input.attr('name'))<0){attrs[$input.attr('name')]=$input.val();}}
|
|
|
|
|
for(i=0;i<check_inputs.length;i++){$input=$(check_inputs[i]);if($input.is(':checked')){attrs[$input.attr('name')]=$input.data('checked');}
|
|
|
|
|
else{attrs[$input.attr('name')]=$input.data('unchecked');}}
|
|
|
|
|
var t=$(editor.o_win).scrollTop();insert(href,text,attrs);$(editor.o_win).scrollTop(t);}
|
|
|
|
|
function _split(){if(!editor.selection.isCollapsed()){editor.selection.save();var markers=editor.$el.find('.fr-marker').addClass('fr-unprocessed').toArray();while(markers.length){var $marker=$(markers.pop());$marker.removeClass('fr-unprocessed');var deep_parent=editor.node.deepestParent($marker.get(0));if(deep_parent){var node=$marker.get(0);var close_str='';var open_str='';do{node=node.parentNode;if(!editor.node.isBlock(node)){close_str=close_str+editor.node.closeTagString(node);open_str=editor.node.openTagString(node)+open_str;}}while(node!=deep_parent);var marker_str=editor.node.openTagString($marker.get(0))+$marker.html()+editor.node.closeTagString($marker.get(0));$marker.replaceWith('<span id="fr-break"></span>');var h=$(deep_parent).html();h=h.replace(/<span id="fr-break"><\/span>/g,close_str+marker_str+open_str);$(deep_parent).html(h);}
|
|
|
|
|
markers=editor.$el.find('.fr-marker.fr-unprocessed').toArray();}
|
|
|
|
|
editor.selection.restore();}}
|
|
|
|
|
function insert(href,text,attrs){if(typeof attrs=='undefined')attrs={};var $current_image=editor.image?editor.image.get():null;if(!$current_image&&editor.$el.get(0).tagName!='A'){editor.selection.restore();editor.popups.hide('link.insert');}
|
|
|
|
|
else if(editor.$el.get(0).tagName=='A'){editor.$el.focus();}
|
|
|
|
|
var original_href=href;if(editor.opts.linkConvertEmailAddress){var regex=/^[\w._]+@[a-zA-Z0-9_-]+?\.[a-zA-Z0-9]{2,3}$/i;if(regex.test(href)&&href.indexOf('mailto:')!==0){href='mailto:'+href;}}
|
|
|
|
|
if(href.indexOf('tel:')!==0&&href.indexOf('sms:')!==0&&href.indexOf('mailto:')!==0&&href.indexOf('notes:')!==0&&href.indexOf('data:image')!==0&&editor.opts.linkAutoPrefix!==''&&!/^(https?:|ftps?:|)\/\//.test(href)){if(editor.opts.linkAutoPrefix[editor.opts.linkAutoPrefix.length-1]=='/'){href=href.replace(/^\/*/g,'');}
|
|
|
|
|
href=editor.opts.linkAutoPrefix+href;}
|
|
|
|
|
href=editor.helpers.sanitizeURL(href);if(editor.opts.linkAlwaysBlank)attrs.target='_blank';if(editor.opts.linkAlwaysNoFollow)attrs.rel='nofollow';text=text||'';if(href===editor.opts.linkAutoPrefix){var $popup=editor.popups.get('link.insert');$popup.find('input[name="href"]').addClass('fr-error');editor.events.trigger('link.bad',[original_href]);return false;}
|
|
|
|
|
var link=get();var $link;if(link){$link=$(link);var a_list=editor.node.rawAttributes(link);for(var attr in a_list){if(a_list.hasOwnProperty(attr)){if(attr!='class'&&attr!='style'){$link.removeAttr(attr);}}}
|
|
|
|
|
$link.attr('href',href);if(text.length>0&&$link.text()!=text&&!$current_image){$link.text(text);}
|
|
|
|
|
if(!$current_image){$link.prepend($.FE.START_MARKER).append($.FE.END_MARKER);}
|
|
|
|
|
$link.attr(attrs);if(!$current_image){editor.selection.restore();}}
|
|
|
|
|
else{if(!$current_image){editor.doc.execCommand('unlink',false,false);if(editor.selection.isCollapsed()){text=(text.length===0?original_href:text);editor.html.insert('<a href="'+href+'">'+$.FE.START_MARKER+text+$.FE.END_MARKER+'</a>');editor.selection.restore();}
|
|
|
|
|
else{if(text.length>0&&text!=editor.selection.text()){editor.selection.remove();editor.html.insert('<a href="'+href+'">'+$.FE.START_MARKER+text+$.FE.END_MARKER+'</a>');editor.selection.restore();}
|
|
|
|
|
else{_split();editor.doc.execCommand('createLink',false,href);}}}
|
|
|
|
|
else{$current_image.wrap('<a href="'+href+'"></a>');}
|
|
|
|
|
var links=allSelected();for(var i=0;i<links.length;i++){$link=$(links[i]);$link.attr(attrs);$link.removeAttr('_moz_dirty');}
|
|
|
|
|
if(links.length==1&&editor.$wp&&!$current_image){$(links[0]).prepend($.FE.START_MARKER).append($.FE.END_MARKER);editor.selection.restore();}}
|
|
|
|
|
if(!$current_image){_edit();}
|
|
|
|
|
else{var $pop=editor.popups.get('link.insert');$pop.find('input:focus').blur();editor.image.edit($current_image);}}
|
|
|
|
|
function update(){_hideEditPopup();var link=get();if(link){var $popup=editor.popups.get('link.insert');if(!$popup)$popup=_initInsertPopup();if(!editor.popups.isVisible('link.insert')){editor.popups.refresh('link.insert');editor.selection.save();if(editor.helpers.isMobile()){editor.events.disableBlur();editor.$el.blur();editor.events.enableBlur();}}
|
|
|
|
|
editor.popups.setContainer('link.insert',$(editor.opts.scrollableContainer));var $ref=(editor.image?editor.image.get():null)||$(link);var left=$ref.offset().left+$ref.outerWidth()/2;var top=$ref.offset().top+$ref.outerHeight();editor.popups.show('link.insert',left,top,$ref.outerHeight());}}
|
|
|
|
|
function back(){var $current_image=editor.image?editor.image.get():null;if(!$current_image){editor.events.disableBlur();editor.selection.restore();editor.events.enableBlur();var link=get();if(link&&editor.$wp){editor.selection.restore();_hideEditPopup();_edit();}
|
|
|
|
|
else if(editor.$el.get(0).tagName=='A'){editor.$el.focus();_edit();}
|
|
|
|
|
else{editor.popups.hide('link.insert');editor.toolbar.showInline();}}
|
|
|
|
|
else{editor.image.back();}}
|
|
|
|
|
function imageLink(){var $current_image=editor.image?editor.image.get():null;if($current_image){var $popup=editor.popups.get('link.insert');if(!$popup)$popup=_initInsertPopup();_refreshInsertPopup(true);editor.popups.setContainer('link.insert',$(editor.opts.scrollableContainer));var left=$current_image.offset().left+$current_image.outerWidth()/2;var top=$current_image.offset().top+$current_image.outerHeight();editor.popups.show('link.insert',left,top,$current_image.outerHeight());}}
|
|
|
|
|
function applyStyle(val,linkStyles,multipleStyles){if(typeof multipleStyles=='undefined')multipleStyles=editor.opts.linkMultipleStyles;if(typeof linkStyles=='undefined')linkStyles=editor.opts.linkStyles;var link=get();if(!link)return false;if(!multipleStyles){var styles=Object.keys(linkStyles);styles.splice(styles.indexOf(val),1);$(link).removeClass(styles.join(' '));}
|
|
|
|
|
$(link).toggleClass(val);_edit();}
|
|
|
|
|
return{_init:_init,remove:remove,showInsertPopup:_showInsertPopup,usePredefined:usePredefined,insertCallback:insertCallback,insert:insert,update:update,get:get,allSelected:allSelected,back:back,imageLink:imageLink,applyStyle:applyStyle}}
|
|
|
|
|
$.FE.DefineIcon('insertLink',{NAME:'link'});$.FE.RegisterShortcut(75,'insertLink');$.FE.RegisterCommand('insertLink',{title:'Insert Link',undo:false,focus:true,refreshOnCallback:false,popup:true,callback:function(){if(!this.popups.isVisible('link.insert')){this.link.showInsertPopup();}
|
|
|
|
|
else{if(this.$el.find('.fr-marker')){this.events.disableBlur();this.selection.restore();}
|
|
|
|
|
this.popups.hide('link.insert');}},plugin:'link'})
|
|
|
|
|
$.FE.DefineIcon('linkOpen',{NAME:'external-link'});$.FE.RegisterCommand('linkOpen',{title:'Open Link',undo:false,refresh:function($btn){var link=this.link.get();if(link){$btn.removeClass('fr-hidden');}
|
|
|
|
|
else{$btn.addClass('fr-hidden');}},callback:function(){var link=this.link.get();if(link){this.o_win.open(link.href);}}})
|
|
|
|
|
$.FE.DefineIcon('linkEdit',{NAME:'edit'});$.FE.RegisterCommand('linkEdit',{title:'Edit Link',undo:false,refreshAfterCallback:false,callback:function(){this.link.update();},refresh:function($btn){var link=this.link.get();if(link){$btn.removeClass('fr-hidden');}
|
|
|
|
|
else{$btn.addClass('fr-hidden');}}})
|
|
|
|
|
$.FE.DefineIcon('linkRemove',{NAME:'unlink'});$.FE.RegisterCommand('linkRemove',{title:'Unlink',callback:function(){this.link.remove();},refresh:function($btn){var link=this.link.get();if(link){$btn.removeClass('fr-hidden');}
|
|
|
|
|
else{$btn.addClass('fr-hidden');}}})
|
|
|
|
|
$.FE.DefineIcon('linkBack',{NAME:'arrow-left'});$.FE.RegisterCommand('linkBack',{title:'Back',undo:false,focus:false,back:true,refreshAfterCallback:false,callback:function(){this.link.back();},refresh:function($btn){var link=this.link.get();var $current_image=this.image?this.image.get():null;if(!$current_image&&!link&&!this.opts.toolbarInline){$btn.addClass('fr-hidden');$btn.next('.fr-separator').addClass('fr-hidden');}
|
|
|
|
|
else{$btn.removeClass('fr-hidden');$btn.next('.fr-separator').removeClass('fr-hidden');}}});$.FE.DefineIcon('linkList',{NAME:'search'});$.FE.RegisterCommand('linkList',{title:'Choose Link',type:'dropdown',focus:false,undo:false,refreshAfterCallback:false,html:function(){var c='<ul class="fr-dropdown-list">';var options=this.opts.linkList;for(var i=0;i<options.length;i++){c+='<li><a class="fr-command" data-cmd="linkList" data-param1="'+i+'">'+(options[i].displayText||options[i].text)+'</a></li>';}
|
|
|
|
|
c+='</ul>';return c;},callback:function(cmd,val){this.link.usePredefined(val);}})
|
|
|
|
|
$.FE.RegisterCommand('linkInsert',{focus:false,refreshAfterCallback:false,callback:function(){this.link.insertCallback();},refresh:function($btn){var link=this.link.get();if(link){$btn.text(this.language.translate('Update'));}
|
|
|
|
|
else{$btn.text(this.language.translate('Insert'));}}})
|
|
|
|
|
$.FE.DefineIcon('imageLink',{NAME:'link'})
|
|
|
|
|
$.FE.RegisterCommand('imageLink',{title:'Insert Link',undo:false,focus:false,callback:function(){this.link.imageLink();},refresh:function($btn){var link=this.link.get();var $prev;if(link){$prev=$btn.prev();if($prev.hasClass('fr-separator')){$prev.removeClass('fr-hidden');}
|
|
|
|
|
$btn.addClass('fr-hidden');}
|
|
|
|
|
else{$prev=$btn.prev();if($prev.hasClass('fr-separator')){$prev.addClass('fr-hidden');}
|
|
|
|
|
$btn.removeClass('fr-hidden');}}})
|
|
|
|
|
$.FE.DefineIcon('linkStyle',{NAME:'magic'})
|
|
|
|
|
$.FE.RegisterCommand('linkStyle',{title:'Style',type:'dropdown',html:function(){var c='<ul class="fr-dropdown-list">';var options=this.opts.linkStyles;for(var cls in options){if(options.hasOwnProperty(cls)){c+='<li><a class="fr-command" data-cmd="linkStyle" data-param1="'+cls+'">'+this.language.translate(options[cls])+'</a></li>';}}
|
2016-05-20 20:58:34 +00:00
|
|
|
c+='</ul>';return c;},callback:function(cmd,val){this.link.applyStyle(val);},refreshOnShow:function($btn,$dropdown){var link=this.link.get();if(link){var $link=$(link);$dropdown.find('.fr-command').each(function(){var cls=$(this).data('param1');$(this).toggleClass('fr-active',$link.hasClass(cls));})}}})}));!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&module.exports?module.exports=function(b,c){return void 0===c&&(c="undefined"!=typeof window?require("jquery"):require("jquery")(b)),a(c),c}:a(jQuery)}(function(a){"use strict";a.extend(a.FE.POPUP_TEMPLATES,{"table.insert":"[_BUTTONS_][_ROWS_COLUMNS_]","table.edit":"[_BUTTONS_]","table.colors":"[_BUTTONS_][_COLORS_]"}),a.extend(a.FE.DEFAULTS,{tableInsertMaxSize:10,tableEditButtons:["tableHeader","tableRemove","|","tableRows","tableColumns","tableStyle","-","tableCells","tableCellBackground","tableCellVerticalAlign","tableCellHorizontalAlign","tableCellStyle"],tableInsertButtons:["tableBack","|"],tableResizerOffset:5,tableResizingLimit:30,tableColorsButtons:["tableBack","|"],tableColors:["#61BD6D","#1ABC9C","#54ACD2","#2C82C9","#9365B8","#475577","#CCCCCC","#41A85F","#00A885","#3D8EB9","#2969B0","#553982","#28324E","#000000","#F7DA64","#FBA026","#EB6B56","#E25041","#A38F84","#EFEFEF","#FFFFFF","#FAC51C","#F37934","#D14841","#B8312F","#7C706B","#D1D5D8","REMOVE"],tableColorsStep:7,tableCellStyles:{"fr-highlighted":"Highlighted","fr-thick":"Thick"},tableStyles:{"fr-dashed-borders":"Dashed Borders","fr-alternate-rows":"Alternate Rows"},tableCellMultipleStyles:!0,tableMultipleStyles:!0,tableInsertHelper:!0,tableInsertHelperOffset:15}),a.FE.PLUGINS.table=function(b){function c(){var a=b.$tb.find('.fr-command[data-cmd="insertTable"]'),c=b.popups.get("table.insert");if(c||(c=g()),!c.hasClass("fr-active")){b.popups.refresh("table.insert"),b.popups.setContainer("table.insert",b.$tb);var d=a.offset().left+a.outerWidth()/2,e=a.offset().top+(b.opts.toolbarBottom?10:a.outerHeight()-10);b.popups.show("table.insert",d,e,a.outerHeight())}}function d(){var c=B();if(c){var d=b.popups.get("table.edit");d||(d=i()),b.popups.setContainer("table.edit",a(b.opts.scrollableContainer));var e=I(c),f=(e.left+e.right)/2,g=e.bottom;b.popups.show("table.edit",f,g,e.bottom-e.top),ga().length>1&&(b.toolbar.disable(),b.$el.removeClass("fr-no-selection"),b.edit.on(),b.selection.setAtEnd(b.$el.find(".fr-selected-cell:last").get(0)),b.selection.restore(),b.button.bulkRefresh())}}function e(){var c=B();if(c){var d=b.popups.get("table.colors");d||(d=j()),b.popups.setContainer("table.colors",a(b.opts.scrollableContainer));var e=I(c),f=(e.left+e.right)/2,g=e.bottom;l(),b.popups.show("table.colors",f,g,e.bottom-e.top)}}function f(){0===ga().length&&b.toolbar.enable()}function g(c){if(c)return b.popups.onHide("table.insert",function(){b.popups.get("table.insert").find('.fr-table-size .fr-select-table-size > span[data-row="1"][data-col="1"]').trigger("mouseenter")}),!0;var d="";b.opts.tableInsertButtons.length>0&&(d='<div class="fr-buttons">'+b.button.buildList(b.opts.tableInsertButtons)+"</div>");var e={buttons:d,rows_columns:h()},f=b.popups.create("table.insert",e);return b.events.$on(f,"mouseenter",".fr-table-size .fr-select-table-size .fr-table-cell",function(c){var d=a(c.currentTarget),e=d.data("row"),f=d.data("col"),g=d.parent();g.siblings(".fr-table-size-info").html(e+" × "+f),g.find("> span").removeClass("hover");for(var h=1;h<=b.opts.tableInsertMaxSize;h++)for(var i=0;i<=b.opts.tableInsertMaxSize;i++){var j=g.find('> span[data-row="'+h+'"][data-col="'+i+'"]');e>=h&&f>=i?j.addClass("hover"):e+1>=h||2>=h&&!b.helpers.isMobile()?j.css("display","inline-block"):h>2&&!b.helpers.isMobile()&&j.css("display","none")}},!0),f}function h(){for(var a='<div class="fr-table-size"><div class="fr-table-size-info">1 × 1</div><div class="fr-select-table-size">',c=1;c<=b.opts.tableInsertMaxSize;c++){for(var d=1;d<=b.opts.tableInsertMaxSize;d++){var e="inline-block";c>2&&!b.helpers.isMobile()&&(e="none");var f="fr-table-cell ";1==c&&1==d&&(f+=" hover"),a+='<span class
|
|
|
|
|
editor.html.insert(html)
|
|
|
|
|
editor.selection.restore()
|
|
|
|
|
editor.html.cleanEmptyTags()
|
|
|
|
|
$('figure',editor.$el).each(function(){var $this=$(this),$parent=$this.parent('p'),$next=$this.next('p')
|
|
|
|
|
if(!!$parent.length){$this.unwrap()}
|
|
|
|
|
if(!!$next.length&&$.trim($next.text()).length==0){$next.remove()}})}
|
|
|
|
|
function _initUiBlocks(){$('[data-video], [data-audio]',editor.$el).each(function(){$(this).attr({'data-ui-block':true,'tabindex':'0'})
|
|
|
|
|
this.contentEditable=false})}
|
|
|
|
|
function _handleUiBlocksKeydown(ev){if(ev.which==40||ev.which==38||ev.which==8||ev.which==46){var $block=$(editor.selection.element())
|
|
|
|
|
if($block.is('br')){$block=$block.parent()}
|
|
|
|
|
if(!!$block.length){switch(ev.which){case 38:_handleUiBlockCaretIn($block.prev())
|
|
|
|
|
break
|
|
|
|
|
case 40:_handleUiBlockCaretIn($block.next())
|
|
|
|
|
break
|
|
|
|
|
case 46:_handleUiBlockCaretClearEmpty($block.next(),$block)
|
|
|
|
|
break
|
|
|
|
|
case 8:_handleUiBlockCaretClearEmpty($block.prev(),$block)
|
|
|
|
|
break}}}}
|
|
|
|
|
function _handleUiBlockCaretClearEmpty($block,$p){if($block.attr('data-ui-block')!==undefined&&$.trim($p.text()).length==0){$p.remove()
|
|
|
|
|
_handleUiBlockCaretIn($block)
|
|
|
|
|
editor.undo.saveStep()}}
|
|
|
|
|
function _handleUiBlockCaretIn($block){if($block.attr('data-ui-block')!==undefined){$block.focus()
|
|
|
|
|
editor.selection.clear()
|
|
|
|
|
return true}
|
|
|
|
|
return false}
|
|
|
|
|
function _uiBlockKeyDown(ev,block){if(ev.which==40||ev.which==38||ev.which==13||ev.which==8||ev.which==46){switch(ev.which){case 40:_focusUiBlockOrText($(block).next(),true)
|
|
|
|
|
break
|
|
|
|
|
case 38:_focusUiBlockOrText($(block).prev(),false)
|
|
|
|
|
break
|
|
|
|
|
case 13:var $paragraph=$('<p><br/></p>')
|
|
|
|
|
$paragraph.insertAfter(block)
|
|
|
|
|
editor.selection.setAfter(block)
|
|
|
|
|
editor.selection.restore()
|
|
|
|
|
editor.undo.saveStep()
|
|
|
|
|
break
|
|
|
|
|
case 8:case 46:var $nextFocus=$(block).next(),gotoStart=true
|
|
|
|
|
if($nextFocus.length==0){$nextFocus=$(block).prev()
|
|
|
|
|
gotoStart=false}
|
|
|
|
|
_focusUiBlockOrText($nextFocus,gotoStart)
|
|
|
|
|
$(block).remove()
|
|
|
|
|
editor.undo.saveStep()
|
|
|
|
|
break}
|
|
|
|
|
ev.preventDefault()}}
|
|
|
|
|
function _focusUiBlockOrText($block,gotoStart){if(!!$block.length){if(!_handleUiBlockCaretIn($block)){if(gotoStart){editor.selection.setAtStart($block.get(0))
|
|
|
|
|
editor.selection.restore()}
|
|
|
|
|
else{editor.selection.setAtEnd($block.get(0))
|
|
|
|
|
editor.selection.restore()}}}}
|
|
|
|
|
function _onKeydown(ev){_handleUiBlocksKeydown(ev)
|
|
|
|
|
if(ev.isDefaultPrevented()){return false}}
|
|
|
|
|
function _onFigureKeydown(ev){if(ev.target&&$(ev.target).attr('data-ui-block')!==undefined){_uiBlockKeyDown(ev,ev.target)}
|
|
|
|
|
if(ev.isDefaultPrevented()){return false}}
|
|
|
|
|
function _onSync(html){var $domTree=$('<div>'+html+'</div>')
|
|
|
|
|
$domTree.find('[data-video], [data-audio]').each(function(){$(this).removeAttr('contenteditable data-ui-block tabindex')})
|
|
|
|
|
return $domTree.html()}
|
|
|
|
|
function _init(){editor.events.on('initialized',_initUiBlocks)
|
|
|
|
|
editor.events.on('html.get',_onSync)
|
|
|
|
|
editor.events.on('keydown',_onKeydown)
|
|
|
|
|
editor.events.on('destroy',_destroy,true)
|
|
|
|
|
editor.$el.on('keydown','figure',_onFigureKeydown)}
|
|
|
|
|
function _destroy(){editor.$el.off('keydown','figure',_onFigureKeydown)}
|
|
|
|
|
return{_init:_init,insert:insert}}})(jQuery);+function($){"use strict";var Base=$.oc.foundation.base,BaseProto=Base.prototype
|
2015-04-25 21:07:22 +00:00
|
|
|
var RichEditor=function(element,options){this.options=options
|
2015-02-14 05:40:50 +00:00
|
|
|
this.$el=$(element)
|
|
|
|
|
this.$textarea=this.$el.find('>textarea:first')
|
|
|
|
|
this.$form=this.$el.closest('form')
|
2016-05-20 20:58:34 +00:00
|
|
|
this.editor=null
|
2015-04-26 05:48:49 +00:00
|
|
|
$.oc.foundation.controlUtils.markDisposable(element)
|
2015-04-25 21:07:22 +00:00
|
|
|
Base.call(this)
|
2015-04-29 03:13:04 +00:00
|
|
|
this.init()}
|
2015-04-25 21:07:22 +00:00
|
|
|
RichEditor.prototype=Object.create(BaseProto)
|
|
|
|
|
RichEditor.prototype.constructor=RichEditor
|
2016-05-19 18:35:40 +00:00
|
|
|
RichEditor.DEFAULTS={linksHandler:null,stylesheet:null,fullpage:false,editorLang:'en',toolbarButtons:null}
|
2015-04-25 21:07:22 +00:00
|
|
|
RichEditor.prototype.init=function(){var self=this;this.$el.one('dispose-control',this.proxy(this.dispose))
|
2015-02-14 05:40:50 +00:00
|
|
|
if(!this.$textarea.attr('id')){this.$textarea.attr('id','element-'+Math.random().toString(36).substring(7))}
|
2016-05-19 18:35:40 +00:00
|
|
|
this.initFroala()}
|
|
|
|
|
RichEditor.prototype.initFroala=function(){var froalaOptions={editorClass:'control-richeditor'}
|
|
|
|
|
if(this.options.toolbarButtons){froalaOptions.toolbarButtons=this.options.toolbarButtons.split(',')}
|
|
|
|
|
else{froalaOptions.toolbarButtons=['paragraphFormat','paragraphStyle','quote','bold','italic','align','formatOL','formatUL','insertTable','insertLink','insertImage','insertVideo','insertFile','insertHR','fullscreen','html']}
|
|
|
|
|
froalaOptions.toolbarButtonsMD=froalaOptions.toolbarButtons
|
|
|
|
|
froalaOptions.toolbarButtonsSM=froalaOptions.toolbarButtons
|
|
|
|
|
froalaOptions.toolbarButtonsXS=froalaOptions.toolbarButtons
|
|
|
|
|
froalaOptions.htmlAllowedEmptyTags=['figure','textarea','a','iframe','object','video','style','script']
|
|
|
|
|
froalaOptions.htmlDoNotWrapTags=['figure','script','style']
|
2016-05-20 20:58:34 +00:00
|
|
|
froalaOptions.lineBreakerTags=['figure','table','hr','iframe','form','dl']
|
|
|
|
|
froalaOptions.shortcutsEnabled=['show','bold','italic','underline','indent','outdent','undo','redo']
|
2016-05-19 18:35:40 +00:00
|
|
|
var placeholder=this.$textarea.attr('placeholder')
|
|
|
|
|
froalaOptions.placeholderText=placeholder?placeholder:''
|
|
|
|
|
froalaOptions.height=this.$el.hasClass('stretch')?Infinity:$('.height-indicator',this.$el).height()
|
|
|
|
|
$.FroalaEditor.ICON_TEMPLATES={font_awesome:'<i class="icon-[NAME]"></i>',text:'<span style="text-align: center;">[NAME]</span>',image:'<img src=[SRC] alt=[ALT] />'}
|
|
|
|
|
this.$textarea.on('froalaEditor.initialized',this.proxy(this.build))
|
2016-05-20 20:58:34 +00:00
|
|
|
this.$textarea.on('froalaEditor.contentChanged',this.proxy(this.onChange))
|
|
|
|
|
this.$textarea.on('froalaEditor.keydown',this.proxy(this.onKeydown))
|
|
|
|
|
this.$textarea.on('froalaEditor.html.get',this.proxy(this.onSyncContent))
|
|
|
|
|
this.$textarea.on('froalaEditor.html.set',this.proxy(this.onSetContent))
|
|
|
|
|
this.$textarea.froalaEditor(froalaOptions)
|
|
|
|
|
this.editor=this.$textarea.data('froala.editor')
|
|
|
|
|
this.$el.on('keydown','.fr-view figure',this.proxy(this.onFigureKeydown))}
|
2015-04-25 21:07:22 +00:00
|
|
|
RichEditor.prototype.dispose=function(){this.unregisterHandlers()
|
2016-05-19 18:35:40 +00:00
|
|
|
this.$textarea.froalaEditor('destroy')
|
2015-04-29 03:13:04 +00:00
|
|
|
this.$el.removeData('oc.richEditor')
|
2015-04-25 21:07:22 +00:00
|
|
|
this.options=null
|
|
|
|
|
this.$el=null
|
|
|
|
|
this.$textarea=null
|
|
|
|
|
this.$form=null
|
2016-05-20 20:58:34 +00:00
|
|
|
this.editor=null
|
2015-04-25 21:07:22 +00:00
|
|
|
BaseProto.dispose.call(this)}
|
2016-05-20 20:58:34 +00:00
|
|
|
RichEditor.prototype.unregisterHandlers=function(){this.$el.off('keydown','.fr-view figure',this.proxy(this.onFigureKeydown))
|
|
|
|
|
this.$textarea.off('froalaEditor.initialized',this.proxy(this.build))
|
|
|
|
|
this.$textarea.off('froalaEditor.contentChanged',this.proxy(this.onChange))
|
|
|
|
|
this.$textarea.off('froalaEditor.keydown',this.proxy(this.onKeydown))
|
|
|
|
|
this.$textarea.off('froalaEditor.html.get',this.proxy(this.onSyncContent))
|
|
|
|
|
this.$textarea.off('froalaEditor.html.set',this.proxy(this.onSetContent))
|
|
|
|
|
$(window).off('resize',this.proxy(this.updateLayout))
|
2015-04-25 21:07:22 +00:00
|
|
|
$(window).off('oc.updateUi',this.proxy(this.updateLayout))
|
|
|
|
|
this.$el.off('dispose-control',this.proxy(this.dispose))}
|
2016-05-19 18:35:40 +00:00
|
|
|
RichEditor.prototype.build=function(event,editor){this.updateLayout()
|
2015-04-25 21:07:22 +00:00
|
|
|
$(window).on('resize',this.proxy(this.updateLayout))
|
|
|
|
|
$(window).on('oc.updateUi',this.proxy(this.updateLayout))
|
2016-05-20 20:58:34 +00:00
|
|
|
this.$textarea.trigger('init.oc.richeditor',[this])}
|
2016-03-23 09:10:55 +00:00
|
|
|
RichEditor.prototype.getElement=function(){return this.$el}
|
2016-05-20 20:58:34 +00:00
|
|
|
RichEditor.prototype.getEditor=function(){return this.editor}
|
2016-03-23 09:10:55 +00:00
|
|
|
RichEditor.prototype.getTextarea=function(){return this.$textarea}
|
2016-05-20 20:58:34 +00:00
|
|
|
RichEditor.prototype.getContent=function(){return this.$textarea.froalaEditor('html.get')}
|
|
|
|
|
RichEditor.prototype.setContent=function(html){this.$textarea.froalaEditor('html.set',html)}
|
|
|
|
|
RichEditor.prototype.syncContent=function(){this.editor.events.trigger('contentChanged')}
|
2016-05-19 18:35:40 +00:00
|
|
|
RichEditor.prototype.updateLayout=function(){var $editor=$('.fr-wrapper',this.$el),$codeEditor=$('.fr-code',this.$el),$toolbar=$('.fr-toolbar',this.$el),$box=$('.fr-box',this.$el)
|
2016-02-13 01:59:49 +00:00
|
|
|
if(!$editor.length){return}
|
2016-05-19 18:35:40 +00:00
|
|
|
if(this.$el.hasClass('stretch')&&!$box.hasClass('fr-fullscreen')){var height=$toolbar.outerHeight(true)
|
2015-02-14 05:40:50 +00:00
|
|
|
$editor.css('top',height+1)
|
2016-05-19 18:35:40 +00:00
|
|
|
$codeEditor.css('top',height)}
|
|
|
|
|
else{$editor.css('top','')
|
|
|
|
|
$codeEditor.css('top','')}}
|
2016-05-20 20:58:34 +00:00
|
|
|
RichEditor.prototype.insertHtml=function(html){this.editor.html.insert(html)
|
|
|
|
|
this.editor.selection.restore()}
|
|
|
|
|
RichEditor.prototype.insertElement=function($el){this.insertHtml($('<div />').append($el.clone()).remove().html())}
|
|
|
|
|
RichEditor.prototype.insertUiBlock=function($node){this.$textarea.froalaEditor('figures.insert',$node)}
|
|
|
|
|
RichEditor.prototype.onSetContent=function(ev,editor){this.$textarea.trigger('setContent.oc.richeditor',[this])}
|
|
|
|
|
RichEditor.prototype.onSyncContent=function(ev,editor,html){var container={html:html}
|
|
|
|
|
this.$textarea.trigger('syncContent.oc.richeditor',[this,container])
|
|
|
|
|
return container.html}
|
2015-04-25 21:07:22 +00:00
|
|
|
RichEditor.prototype.onFocus=function(){this.$el.addClass('editor-focus')}
|
|
|
|
|
RichEditor.prototype.onBlur=function(){this.$el.removeClass('editor-focus')}
|
2016-05-20 20:58:34 +00:00
|
|
|
RichEditor.prototype.onFigureKeydown=function(ev){this.$textarea.trigger('figureKeydown.oc.richeditor',[ev,this])}
|
|
|
|
|
RichEditor.prototype.onKeydown=function(ev,editor,keyEv){this.$textarea.trigger('keydown.oc.richeditor',[keyEv,this])
|
2016-02-13 01:59:49 +00:00
|
|
|
if(ev.isDefaultPrevented()){return false}}
|
2016-05-20 20:58:34 +00:00
|
|
|
RichEditor.prototype.onChange=function(ev){this.$form.trigger('change')}
|
2015-02-14 05:40:50 +00:00
|
|
|
var old=$.fn.richEditor
|
2016-03-23 09:10:55 +00:00
|
|
|
$.fn.richEditor=function(option){var args=Array.prototype.slice.call(arguments,1),result
|
|
|
|
|
this.each(function(){var $this=$(this)
|
2015-02-14 05:40:50 +00:00
|
|
|
var data=$this.data('oc.richEditor')
|
|
|
|
|
var options=$.extend({},RichEditor.DEFAULTS,$this.data(),typeof option=='object'&&option)
|
|
|
|
|
if(!data)$this.data('oc.richEditor',(data=new RichEditor(this,options)))
|
2016-03-23 09:10:55 +00:00
|
|
|
if(typeof option=='string')result=data[option].apply(data,args)
|
|
|
|
|
if(typeof result!='undefined')return false})
|
|
|
|
|
return result?result:this}
|
2015-02-14 05:40:50 +00:00
|
|
|
$.fn.richEditor.Constructor=RichEditor
|
|
|
|
|
$.fn.richEditor.noConflict=function(){$.fn.richEditor=old
|
|
|
|
|
return this}
|
2016-02-13 01:59:49 +00:00
|
|
|
$(document).render(function(){$('[data-control="richeditor"]').richEditor()})}(window.jQuery);
|