ORIENT/modules/backend/formwidgets/richeditor/assets/js/build-min.js

718 lines
457 KiB
JavaScript
Raw Normal View History

2017-02-08 08:10:24 +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){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("touchstart.init",function(){a(this).data("touched",!0)}),this.$el.on("touchmove.init",function(){a(this).removeData("touched")}),this.$el.on("mousedown.init touchend.init dragenter.init focus.init",a.proxy(function(b){if("touchend"==b.type&&!this.$el.data("touched"))return!0;if(1===b.which||!b.which){this.$el.off("mousedown.init touchstart.init touchmove.init touchend.init dragenter.init focus.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(),"touchend"==b.type&&this.image&&b.originalEvent&&b.originalEvent.target&&a(b.originalEvent.target).is("img")&&setTimeout(a.proxy(function(){this.image.edit(a(b.originalEvent.target))},this),100),this.ready=!0,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.ready=!0,this.events.trigger("initialized"))},this)),this._init()};b.DEFAULTS={initOnClick:!1,pluginsEnabled:null},b.MODULES={},b.PLUGINS={},b.VERSION="2.4.2",b.INSTANCES=[],b.OPTS_MAPPING={},b.SHARED={},b.ID=0,b.prototype._init=function(){var b=this.$oel.prop("tagName"),c=a.proxy(function(){"TEXTAREA"!=b&&(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.el=this.$el.get(0),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.el=this.$el.get(0),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=this.$el.get(0),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.el=this.$el.get(0
else{jQuery=require('jquery')(root);}}
2017-02-08 08:10:24 +00:00
factory(jQuery);return jQuery;};}else{factory(jQuery);}}(function($){$.FE.PLUGINS.fullscreen=function(editor){var old_scroll;function isActive(){return editor.$box.hasClass('fr-fullscreen');}
var $placeholder;var height;var max_height;var z_index;function _on(){old_scroll=editor.helpers.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;z_index=editor.opts.zIndex;editor.opts.height=editor.o_win.innerHeight-(editor.opts.toolbarInline?0:editor.$tb.outerHeight());editor.opts.zIndex=9990;editor.opts.heightMax=null;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'));}
2017-02-08 08:10:24 +00:00
editor.opts.height=height;editor.opts.heightMax=max_height;editor.opts.zIndex=z_index;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')}
2017-02-08 08:10:24 +00:00
function refresh($btn){var active=isActive();$btn.toggleClass('fr-active',active).attr('aria-pressed',active);$btn.find('> *:not(.fr-sr-only)').replaceWith(!active?editor.icon.create('fullscreen'):editor.icon.create('fullscreenCompress'));}
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}}
2017-02-08 08:10:24 +00:00
$.FE.RegisterCommand('fullscreen',{title:'Fullscreen',undo:false,focus:false,accessibilityFocus:true,forcedRefresh:true,toggle:true,callback:function(){this.fullscreen.toggle();},refresh:function($btn){this.fullscreen.refresh($btn);},plugin:'fullscreen'})
$.FE.DefineIcon('fullscreen',{NAME:'expand'});$.FE.DefineIcon('fullscreenCompress',{NAME:'compress'});}));(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);}}
2017-02-08 08:10:24 +00:00
factory(jQuery);return jQuery;};}else{factory(jQuery);}}(function($){$.extend($.FE.DEFAULTS,{aceEditor:true,aceEditorVendorPath:'/',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},codeViewKeepActiveButtons:['fullscreen']})
$.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();}}
2017-02-08 08:10:24 +00:00
function _showText($btn){var html=get();editor.html.set(html);editor.$el.blur();editor.$tb.find(' > .fr-command').not($btn).removeClass('fr-disabled').attr('aria-disabled',false);$btn.removeClass('fr-active').attr('aria-pressed',false);editor.events.focus(true);editor.placeholder.refresh();editor.undo.saveStep();}
function _showHTML($btn){if(!$html_area){_initArea();if(!ace_editor&&editor.opts.aceEditor&&typeof ace!='undefined'){ace_editor=ace.edit($html_area.get(0));ace.require('ace/config').set('basePath',editor.opts.aceEditorVendorPath);ace_editor.setOptions(editor.opts.aceEditorOptions);}
else{editor.events.$on($html_area,'keydown keyup change input',function(){if(!editor.opts.height){if(!this.rows){this.rows=1;}
if(this.value.length===0){this.rows=1;}
else{this.style.height='auto';while(this.rows>1&&this.scrollHeight<=this.offsetHeight){this.rows-=1;}
while(this.scrollHeight>this.offsetHeight&&(!editor.opts.heightMax||this.offsetHeight<editor.opts.heightMax)){this.rows+=1;}}}
2017-02-08 08:10:24 +00:00
else{this.removeAttribute('rows')}});}}
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>');}}
2017-02-08 08:10:24 +00:00
var html=editor.html.get(false,true);editor.$el.find('span.fr-tmp').remove();editor.$box.toggleClass('fr-code-view',true);if(editor.core.hasFocus())editor.$el.blur();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;if(editor.opts.heightMin){$html_area.css('min-height',editor.opts.heightMin);}
if(editor.opts.height){$html_area.css('height',editor.opts.height);}
if(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,'')).trigger('change');var scroll_top=$(editor.o_doc).scrollTop();$html_area.focus();$html_area.get(0).setSelectionRange(s_index,e_index);$(editor.o_doc).scrollTop(scroll_top);}
2017-02-08 08:10:24 +00:00
editor.$tb.find(' > .fr-command').not($btn).filter(function(){return editor.opts.codeViewKeepActiveButtons.indexOf($(this).data('cmd'))<0;}).addClass('fr-disabled').attr('aria-disabled',true);$btn.addClass('fr-active').attr('aria-pressed',true);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();_showHTML($btn);}}
function _destroy(){if(isActive()){toggle(editor.$tb.find('button[data-cmd="html"]'));}
$html_area.val('').removeData().remove();$html_area=null;if($back_button){$back_button.remove();$back_button=null;}}
2017-02-08 08:10:24 +00:00
function _initArea(){$html_area=$('<textarea class="fr-code" tabIndex="-1">');editor.$wp.append($html_area);$html_area.attr('dir',editor.opts.direction);if(!editor.$box.hasClass('fr-basic')){$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;}
2017-02-08 08:10:24 +00:00
return{_init:_init,toggle:toggle,isActive:isActive,get:get}};$.FE.RegisterCommand('html',{title:'Code View',undo:false,focus:false,forcedRefresh:true,toggle: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){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&&(f=e.tagName),c.find('.fr-command[data-param1="'+f+'"]').addClass("fr-active").attr("aria-selected",!0)}else c.find('.fr-command[data-param1="N"]').addClass("fr-active").attr("aria-selected",!0)}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&&(e=d.tagName),["LI","TD","TH"].indexOf(e)>=0&&(e="N"),a.find("> span").text(b.opts.paragraphFormat[e])}else a.find("> span").text(b.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" role="presentation">',b=this.opts.paragraphFormat;for(var c in b)if(b.hasOwnProperty(c)){var d=this.shortcuts.get("paragraphFormat."+c);d=d?'<span class="fr-shortcut">'+d+"</span>":"",a+='<li role="presentation"><'+("N"==c?this.html.defaultTag()||"DIV":c)+' style="padding: 0 !important; margin: 0 !important;" role="presentation"><a class="fr-command" tabIndex="-1" role="option" data-cmd="paragraphFormat" data-param1="'+c+'" title="'+this.language.translate(b[c])+'">'+this.language.translate(b[c])+"</a></"+("N"==c?this.html.defaultTag()||"DIV":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){a.FE.PLUGINS.align=f
else{jQuery=require('jquery')(root);}}
2017-02-08 08:10:24 +00:00
factory(jQuery);return jQuery;};}else{factory(jQuery);}}(function($){$.extend($.FE.POPUP_TEMPLATES,{'file.insert':'[_BUTTONS_][_UPLOAD_LAYER_][_BY_URL_LAYER_][_PROGRESS_BAR_]'})
$.extend($.FE.DEFAULTS,{fileUploadURL:'http://i.froala.com/upload',fileUploadParam:'file',fileUploadParams:{},fileUploadToS3:false,fileUploadMethod:'POST',fileMaxSize:10*1024*1024,fileAllowedTypes:['*'],fileInsertButtons:['fileBack','|','fileUpload','fileByURL'],fileUseSelectedText:false});$.FE.PLUGINS.file=function(editor){var BAD_LINK=1;var MISSING_LINK=2;var ERROR_DURING_UPLOAD=3;var BAD_RESPONSE=4;var MAX_SIZE_EXCEEDED=5;var BAD_FILE_TYPE=6;var NO_CORS_IE=7;var error_messages={};error_messages[BAD_LINK]='File cannot be loaded from the passed link.';error_messages[MISSING_LINK]='No link in upload response.';error_messages[ERROR_DURING_UPLOAD]='Error during file upload.';error_messages[BAD_RESPONSE]='Parsing response failed.';error_messages[MAX_SIZE_EXCEEDED]='File is too large.';error_messages[BAD_FILE_TYPE]='File file type is invalid.';error_messages[NO_CORS_IE]='Files can be uploaded only to same domain in IE 8 and IE 9.';function showInsertPopup(){var $btn=editor.$tb.find('.fr-command[data-cmd="insertFile"]');var $popup=editor.popups.get('file.insert');if(!$popup)$popup=_initInsertPopup();hideProgressBar();if(!$popup.hasClass('fr-active')){editor.popups.refresh('file.insert');editor.popups.setContainer('file.insert',editor.$tb);var left=$btn.offset().left+$btn.outerWidth()/2;var top=$btn.offset().top+(editor.opts.toolbarBottom?10:$btn.outerHeight()-10);editor.popups.show('file.insert',left,top,$btn.outerHeight());}}
function showProgressBar(){var $popup=editor.popups.get('file.insert');if(!$popup)$popup=_initInsertPopup();$popup.find('.fr-layer.fr-active').removeClass('fr-active').addClass('fr-pactive');$popup.find('.fr-file-progress-bar-layer').addClass('fr-active');$popup.find('.fr-buttons').hide();_setProgressMessage('Uploading',0);}
2017-02-08 08:10:24 +00:00
function hideProgressBar(dismiss){var $popup=editor.popups.get('file.insert');if($popup){$popup.find('.fr-layer.fr-pactive').addClass('fr-active').removeClass('fr-pactive');$popup.find('.fr-file-progress-bar-layer').removeClass('fr-active');$popup.find('.fr-buttons').show();if(dismiss){editor.events.focus();editor.popups.hide('file.insert');}}}
function _setProgressMessage(message,progress){var $popup=editor.popups.get('file.insert');if($popup){var $layer=$popup.find('.fr-file-progress-bar-layer');$layer.find('h3').text(message+(progress?' '+progress+'%':''));$layer.removeClass('fr-error');if(progress){$layer.find('div').removeClass('fr-indeterminate');$layer.find('div > span').css('width',progress+'%');}
else{$layer.find('div').addClass('fr-indeterminate');}}}
2017-02-08 08:10:24 +00:00
function _showErrorMessage(message){showProgressBar();var $popup=editor.popups.get('file.insert');var $layer=$popup.find('.fr-file-progress-bar-layer');$layer.addClass('fr-error');var $message_header=$layer.find('h3');$message_header.text(message);editor.events.disableBlur();$message_header.focus();}
function insertByURL(){var $popup=editor.popups.get('file.insert');var $input=$popup.find('.fr-file-by-url-layer input');var url=$input.val()
if(url.length>0){var filename=url.substring(url.lastIndexOf('/')+1);insert(editor.helpers.sanitizeURL($input.val()),filename,[]);$input.val('');$input.blur();}}
2017-02-08 08:10:24 +00:00
function insert(link,text,response){editor.edit.on();editor.events.focus(true);editor.selection.restore();if(editor.opts.fileUseSelectedText&&editor.selection.text().length){text=editor.selection.text();}
editor.html.insert('<a href="'+link+'" id="fr-inserted-file" class="fr-file">'+text+'</a>');var $file=editor.$el.find('#fr-inserted-file');$file.removeAttr('id');editor.popups.hide('file.insert');editor.undo.saveStep();_syncFiles();editor.events.trigger('file.inserted',[$file,response]);}
function _parseResponse(response){try{if(editor.events.trigger('file.uploaded',[response],true)===false){editor.edit.on();return false;}
var resp=$.parseJSON(response);if(resp.link){return resp;}else{_throwError(MISSING_LINK,response);return false;}}catch(ex){_throwError(BAD_RESPONSE,response);return false;}}
function _parseXMLResponse(response){try{var link=$(response).find('Location').text();var key=$(response).find('Key').text();if(editor.events.trigger('file.uploadedToS3',[link,key,response],true)===false){editor.edit.on();return false;}
return link;}catch(ex){_throwError(BAD_RESPONSE,response);return false;}}
function _fileUploaded(text){var status=this.status;var response=this.response;var responseXML=this.responseXML;var responseText=this.responseText;try{if(editor.opts.fileUploadToS3){if(status==201){var link=_parseXMLResponse(responseXML);if(link){insert(link,text,response||responseXML);}}else{_throwError(BAD_RESPONSE,response||responseXML);}}
else{if(status>=200&&status<300){var resp=_parseResponse(responseText);if(resp){insert(resp.link,text,response||responseText);}}
else{_throwError(ERROR_DURING_UPLOAD,response||responseText);}}}catch(ex){_throwError(BAD_RESPONSE,response||responseText);}}
function _fileUploadError(){_throwError(BAD_RESPONSE,this.response||this.responseText||this.responseXML);}
function _fileUploadProgress(e){if(e.lengthComputable){var complete=(e.loaded/e.total*100|0);_setProgressMessage('Uploading',complete);}}
function _throwError(code,response){editor.edit.on();_showErrorMessage(editor.language.translate('Something went wrong. Please try again.'));editor.events.trigger('file.error',[{code:code,message:error_messages[code]},response]);}
function _fileUploadAborted(){editor.edit.on();hideProgressBar(true);}
2017-02-08 08:10:24 +00:00
function upload(files){if(typeof files!='undefined'&&files.length>0){if(editor.events.trigger('file.beforeUpload',[files])===false){return false;}
var file=files[0];if(file.size>editor.opts.fileMaxSize){_throwError(MAX_SIZE_EXCEEDED);return false;}
if(editor.opts.fileAllowedTypes.indexOf('*')<0&&editor.opts.fileAllowedTypes.indexOf(file.type.replace(/file\//g,''))<0){_throwError(BAD_FILE_TYPE);return false;}
var form_data;if(editor.drag_support.formdata){form_data=editor.drag_support.formdata?new FormData():null;}
if(form_data){var key;if(editor.opts.fileUploadToS3!==false){form_data.append('key',editor.opts.fileUploadToS3.keyStart+(new Date()).getTime()+'-'+(file.name||'untitled'));form_data.append('success_action_status','201');form_data.append('X-Requested-With','xhr');form_data.append('Content-Type',file.type);for(key in editor.opts.fileUploadToS3.params){if(editor.opts.fileUploadToS3.params.hasOwnProperty(key)){form_data.append(key,editor.opts.fileUploadToS3.params[key]);}}}
for(key in editor.opts.fileUploadParams){if(editor.opts.fileUploadParams.hasOwnProperty(key)){form_data.append(key,editor.opts.fileUploadParams[key]);}}
2017-02-08 08:10:24 +00:00
form_data.append(editor.opts.fileUploadParam,file);var url=editor.opts.fileUploadURL;if(editor.opts.fileUploadToS3){if(editor.opts.fileUploadToS3.uploadURL){url=editor.opts.fileUploadToS3.uploadURL;}
else{url='https://'+editor.opts.fileUploadToS3.region+'.amazonaws.com/'+editor.opts.fileUploadToS3.bucket;}}
var xhr=editor.core.getXHR(url,editor.opts.fileUploadMethod);xhr.onload=function(){_fileUploaded.call(xhr,file.name);};xhr.onerror=_fileUploadError;xhr.upload.onprogress=_fileUploadProgress;xhr.onabort=_fileUploadAborted;showProgressBar();editor.edit.off();var $popup=editor.popups.get('file.insert');if($popup){$popup.off('abortUpload').on('abortUpload',function(){if(xhr.readyState!=4){xhr.abort();}})}
xhr.send(form_data);}}}
function _bindInsertEvents($popup){editor.events.$on($popup,'dragover dragenter','.fr-file-upload-layer',function(){$(this).addClass('fr-drop');return false;},true);editor.events.$on($popup,'dragleave dragend','.fr-file-upload-layer',function(){$(this).removeClass('fr-drop');return false;},true);editor.events.$on($popup,'drop','.fr-file-upload-layer',function(e){e.preventDefault();e.stopPropagation();$(this).removeClass('fr-drop');var dt=e.originalEvent.dataTransfer;if(dt&&dt.files){var inst=$popup.data('instance')||editor;inst.file.upload(dt.files);}},true);editor.events.$on($popup,'change','.fr-file-upload-layer input[type="file"]',function(){if(this.files){var inst=$popup.data('instance')||editor;inst.file.upload(this.files);}
$(this).val('');},true);}
function _hideInsertPopup(){hideProgressBar();}
function _initInsertPopup(delayed){if(delayed){editor.popups.onHide('file.insert',_hideInsertPopup);return true;}
var active;var file_buttons='';if(editor.opts.fileInsertButtons.length>1){file_buttons='<div class="fr-buttons">'+editor.button.buildList(editor.opts.fileInsertButtons)+'</div>';}
var uploadIndex=editor.opts.fileInsertButtons.indexOf('fileUpload');var urlIndex=editor.opts.fileInsertButtons.indexOf('fileByURL');var upload_layer='';if(uploadIndex>=0){active=' fr-active';if(urlIndex>=0&&uploadIndex>urlIndex){active='';}
2017-02-08 08:10:24 +00:00
upload_layer='<div class="fr-file-upload-layer'+active+' fr-layer fr-active" id="fr-file-upload-layer-'+editor.id+'"><strong>'+editor.language.translate('Drop file')+'</strong><br>('+editor.language.translate('or click')+')<div class="fr-form"><input type="file" name="'+editor.opts.fileUploadParam+'" accept="/*" tabIndex="-1" aria-labelledby="fr-file-upload-layer-'+editor.id+'" role="button"></div></div>'}
var by_url_layer='';if(urlIndex>=0){active=' fr-active';if(uploadIndex>=0&&urlIndex>uploadIndex){active='';}
by_url_layer='<div class="fr-file-by-url-layer'+active+' fr-layer" id="fr-file-by-url-layer-'+editor.id+'"><div class="fr-input-line"><input type="text" placeholder="http://" tabIndex="1"></div><div class="fr-action-buttons"><button type="button" class="fr-command fr-submit" data-cmd="fileInsertByURL" tabIndex="2">'+editor.language.translate('Insert')+'</button></div></div>'}
2017-02-08 08:10:24 +00:00
var progress_bar_layer='<div class="fr-file-progress-bar-layer fr-layer"><h3 tabIndex="-1" class="fr-message">Uploading</h3><div class="fr-loader"><span class="fr-progress"></span></div><div class="fr-action-buttons"><button type="button" class="fr-command fr-dismiss" data-cmd="fileDismissError" tabIndex="2" role="button">OK</button></div></div>';var template={buttons:file_buttons,upload_layer:upload_layer,by_url_layer:by_url_layer,progress_bar:progress_bar_layer};var $popup=editor.popups.create('file.insert',template);_bindInsertEvents($popup);return $popup;}
function _onRemove(link){if(editor.node.hasClass(link,'fr-file')){return editor.events.trigger('file.unlink',[link]);}}
function _drop(e){var dt=e.originalEvent.dataTransfer;if(dt&&dt.files&&dt.files.length){var file=dt.files[0];if(file&&typeof file.type!='undefined'){if(file.type.indexOf('image')<0&&(editor.opts.fileAllowedTypes.indexOf(file.type)>=0||editor.opts.fileAllowedTypes.indexOf('*')>=0)){editor.markers.remove();editor.markers.insertAtPoint(e.originalEvent);editor.$el.find('.fr-marker').replaceWith($.FE.MARKERS);editor.popups.hideAll();var $popup=editor.popups.get('file.insert');if(!$popup)$popup=_initInsertPopup();editor.popups.setContainer('file.insert',editor.$sc);editor.popups.show('file.insert',e.originalEvent.pageX,e.originalEvent.pageY);showProgressBar();upload(dt.files);e.preventDefault();e.stopPropagation();return false;}}}}
function _initEvents(){editor.events.on('drop',_drop);editor.events.$on(editor.$win,'keydown',function(e){var key_code=e.which;var $popup=editor.popups.get('file.insert');if($popup&&key_code==$.FE.KEYCODE.ESC){$popup.trigger('abortUpload');}});editor.events.on('destroy',function(){var $popup=editor.popups.get('file.insert');if($popup){$popup.trigger('abortUpload');}});}
function back(){editor.events.disableBlur();editor.selection.restore();editor.events.enableBlur();editor.popups.hide('file.insert');editor.toolbar.showInline();}
2017-02-08 08:10:24 +00:00
var files;function _syncFiles(){var c_files=Array.prototype.slice.call(editor.el.querySelectorAll('a.fr-file'));var file_srcs=[];var i;for(i=0;i<c_files.length;i++){file_srcs.push(c_files[i].getAttribute('href'));}
if(files){for(i=0;i<files.length;i++){if(file_srcs.indexOf(files[i].getAttribute('href'))<0){editor.events.trigger('file.unlink',[files[i]]);}}}
files=c_files;}
function showLayer(name){var $popup=editor.popups.get('file.insert');var left;var top;if(!editor.opts.toolbarInline){var $btn=editor.$tb.find('.fr-command[data-cmd="insertFile"]');left=$btn.offset().left+$btn.outerWidth()/2;top=$btn.offset().top+(editor.opts.toolbarBottom?10:$btn.outerHeight()-10);}
else{top=$popup.offset().top-editor.helpers.getPX($popup.css('margin-top'));if($popup.hasClass('fr-above')){top+=$popup.outerHeight();}}
$popup.find('.fr-layer').removeClass('fr-active');$popup.find('.fr-'+name+'-layer').addClass('fr-active');editor.popups.show('file.insert',left,top,0);}
function refreshUploadButton($btn){var $popup=editor.popups.get('file.insert');if($popup.find('.fr-file-upload-layer').hasClass('fr-active')){$btn.addClass('fr-active');}}
function refreshByURLButton($btn){var $popup=editor.popups.get('file.insert');if($popup.find('.fr-file-by-url-layer').hasClass('fr-active')){$btn.addClass('fr-active');}}
2017-02-08 08:10:24 +00:00
function _init(){_initEvents();editor.events.on('link.beforeRemove',_onRemove);if(editor.$wp){_syncFiles();editor.events.on('contentChanged',_syncFiles);}
_initInsertPopup(true);}
return{_init:_init,showInsertPopup:showInsertPopup,showLayer:showLayer,refreshUploadButton:refreshUploadButton,refreshByURLButton:refreshByURLButton,insertByURL:insertByURL,upload:upload,insert:insert,back:back,hideProgressBar:hideProgressBar}}
$.FE.DefineIcon('insertFile',{NAME:'file-o'});$.FE.RegisterCommand('insertFile',{title:'Insert File',undo:false,focus:true,refreshAfterCallback:false,popup:true,callback:function(){if(!this.popups.isVisible('file.insert')){this.file.showInsertPopup();}
2017-02-08 08:10:24 +00:00
else{if(this.$el.find('.fr-marker').length){this.events.disableBlur();this.selection.restore();}
this.popups.hide('file.insert');}},plugin:'file'});$.FE.DefineIcon('fileUpload',{NAME:'upload'});$.FE.RegisterCommand('fileUpload',{title:'Upload File',undo:false,focus:false,callback:function(){this.file.showLayer('file-upload');},refresh:function($btn){this.file.refreshUploadButton($btn);}});$.FE.DefineIcon('fileByURL',{NAME:'link'});$.FE.RegisterCommand('fileByURL',{title:'By URL',undo:false,focus:false,callback:function(){this.file.showLayer('file-by-url');},refresh:function($btn){this.file.refreshByURLButton($btn);}})
$.FE.RegisterCommand('fileInsertByURL',{title:'Insert File',undo:true,refreshAfterCallback:false,callback:function(){this.file.insertByURL();},refresh:function($btn){$btn.text(this.language.translate('Insert'));}})
$.FE.DefineIcon('fileBack',{NAME:'arrow-left'});$.FE.RegisterCommand('fileBack',{title:'Back',undo:false,focus:false,back:true,refreshAfterCallback:false,callback:function(){this.file.back();},refresh:function($btn){if(!this.opts.toolbarInline){$btn.addClass('fr-hidden');$btn.next('.fr-separator').addClass('fr-hidden');}
2017-02-08 08:10:24 +00:00
else{$btn.removeClass('fr-hidden');$btn.next('.fr-separator').removeClass('fr-hidden');}}});$.FE.RegisterCommand('fileDismissError',{title:'OK',callback:function(){this.file.hideProgressBar(true);}})}));!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){a.extend(a.FE.POPUP_TEMPLATES,{"image.insert":"[_BUTTONS_][_UPLOAD_LAYER_][_BY_URL_LAYER_][_PROGRESS_BAR_]","image.edit":"[_BUTTONS_]","image.alt":"[_BUTTONS_][_ALT_LAYER_]","image.size":"[_BUTTONS_][_SIZE_LAYER_]"}),a.extend(a.FE.DEFAULTS,{imageInsertButtons:["imageBack","|","imageUpload","imageByURL"],imageEditButtons:["imageReplace","imageAlign","imageRemove","|","imageLink","linkOpen","linkEdit","linkRemove","-","imageDisplay","imageStyle","imageAlt","imageSize"],imageAltButtons:["imageBack","|"],imageSizeButtons:["imageBack","|"],imageUploadURL:"https://i.froala.com/upload",imageUploadParam:"file",imageUploadParams:{},imageUploadToS3:!1,imageUploadMethod:"POST",imageMaxSize:10485760,imageAllowedTypes:["jpeg","jpg","png","gif","svg+xml"],imageResize:!0,imageResizeWithPercent:!1,imageRoundPercent:!1,imageDefaultWidth:300,imageDefaultAlign:"center",imageDefaultDisplay:"block",imageSplitHTML:!1,imageStyles:{"ft-rounded":"Rounded","fr-bordered":"Bordered"},imageMove:!0,imageMultipleStyles:!0,imageTextNear:!0,imagePaste:!0,imagePasteProcess:!1,imageMinWidth:16,imageOutputSize:!1,imageDefaultMargin:5}),a.FE.PLUGINS.image=function(b){function c(){var a=b.popups.get("image.insert"),c=a.find(".fr-image-by-url-layer input");c.val(""),xa&&c.val(xa.attr("src")),c.trigger("change")}function d(){var a=b.$tb.find('.fr-command[data-cmd="insertImage"]'),c=b.popups.get("image.insert");if(c||(c=M()),s(),!c.hasClass("fr-active"))if(b.popups.refresh("image.insert"),b.popups.setContainer("image.insert",b.$tb),a.is(":visible")){var d=a.offset().left+a.outerWidth()/2,e=a.offset().top+(b.opts.toolbarBottom?10:a.outerHeight()-10);b.popups.show("image.insert",d,e,a.outerHeight())}else b.position.forSelection(c),b.popups.show("image.insert")}function e(){var a=b.popups.get("image.edit");if(a||(a=q()),a){b.popups.setContainer("image.edit",b.$sc),b.popups.refresh("image.edit");var c=xa.offset().left+xa.outerWidth()/2,d=xa.offset().top+xa.outerHeight();b.popups.show("image.edit",c,d,xa.outerHeight())}}function f(){s()}function g(a){a.hasClass("fr-dii")||a.hasClass("fr-dib")||(a.addClass("fr-fi"+ma(a)[0]),a.addClass("fr-di"+na(a)[0]),a.css("margin",""),a.css("float",""),a.css("display",""),a.css("z-index",""),a.css("position",""),a.css("overflow",""),a.css("vertical-align",""))}function h(a){var b=a.hasClass("fr-dib")?"block":a.hasClass("fr-dii")?"inline":null,c=a.hasClass("fr-fil")?"left":a.hasClass("fr-fir")?"right":ma(a);ka(a,b,c),a.removeClass("fr-dib fr-dii fr-fir fr-fil")}function i(){for(var c="IMG"==b.el.tagName?[b.el]:b.el.querySelectorAll("img"),d=0;d<c.length;d++){var e=a(c[d]);!b.opts.htmlUntouched&&b.opts.useClasses?((b.opts.imageEditButtons.indexOf("imageAlign")>=0||b.opts.imageEditButtons.indexOf("imageDisplay")>=0)&&g(e),b.opts.imageTextNear||e.removeClass("fr-dii").addClass("fr-dib")):b.opts.htmlUntouched||b.opts.useClasses||(b.opts.imageEditButtons.indexOf("imageAlign")>=0||b.opts.imageEditButtons.indexOf("imageDisplay")>=0)&&h(e),b.opts.iframe&&e.on("load",b.size.syncIframe)}}function j(){var c,d=Array.prototype.slice.call(b.el.querySelectorAll("img")),e=[];for(c=0;c<d.length;c++)e.push(d[c].getAttribute("src")),a(d[c]).toggleClass("fr-draggable",b.opts.imageMove),""===d[c].getAttribute("class")&&d[c].removeAttribute("class"),""===d[c].getAttribute("style")&&d[c].removeAttribute("style");if(Ka)for(c=0;c<Ka.length;c++)e.indexOf(Ka[c].getAttribute("src"))<0&&b.events.trigger("image.removed",[a(Ka[c])]);Ka=d}function k(){ya||Z();var a=b.$wp||b.$sc;a.append(ya),ya.data("instance",b);var c=a.scrollTop()-("static"!=a.css("position")?a.offset().top:0),d=a.scrollLeft()-("static"!=a
else{jQuery=require('jquery')(root);}}
2017-02-08 08:10:24 +00:00
factory(jQuery);return jQuery;};}else{factory(jQuery);}}(function($){$.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 c_el=editor.selection.ranges(0).commonAncestorContainer;if(c_el&&(c_el.contains&&c_el.contains(editor.el)||!editor.el.contains(c_el)||editor.el==c_el))c_el=null;if(c_el&&c_el.tagName==='A')return c_el;var s_el=editor.selection.element();var e_el=editor.selection.endElement();if(s_el.tagName!='A'&&!editor.node.isElement(s_el)){s_el=$(s_el).parentsUntil(editor.$el,'a:first').get(0);}
if(e_el.tagName!='A'&&!editor.node.isElement(e_el)){e_el=$(e_el).parentsUntil(editor.$el,'a:first').get(0);}
2017-02-08 08:10:24 +00:00
if(e_el&&(e_el.contains&&e_el.contains(editor.el)||!editor.el.contains(e_el)||editor.el==e_el))e_el=null;if(s_el&&(s_el.contains&&s_el.contains(editor.el)||!editor.el.contains(s_el)||editor.el==s_el))s_el=null;if(e_el&&e_el==s_el&&e_el.tagName=='A'){return s_el;}
return null;}
2017-02-08 08:10:24 +00:00
else if(editor.el.tagName=='A'){return editor.el;}
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');}
2017-02-08 08:10:24 +00:00
editor.popups.setContainer('link.edit',editor.$sc);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');}
2017-02-08 08:10:24 +00:00
function _initEditPopup(){var link_buttons='';if(editor.opts.linkEditButtons.length>1){if(editor.el.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();}}
2017-02-08 08:10:24 +00:00
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.$sc);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>';}
2017-02-08 08:10:24 +00:00
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 id="fr-link-insert-layer-url-'+editor.id+'" 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 id="fr-link-insert-layer-text-'+editor.id+'" 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>';}
2017-02-08 08:10:24 +00:00
input_layer+='<div class="fr-action-buttons"><button class="fr-command fr-submit" role="button" 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);}
2017-02-08 08:10:24 +00:00
_initInsertPopup(true);if(editor.el.tagName=='A'){editor.$el.addClass('fr-view');}
editor.events.on('toolbar.esc',function(){if(editor.popups.isVisible('link.edit')){editor.events.disableBlur();editor.events.focus();return false;}},true);}
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('');}}
2017-02-08 08:10:24 +00:00
for(i=0;i<check_inputs.length;i++){$input=$(check_inputs[i]);$input.prop('checked',$input.data('checked')==link[$input.attr('name')]);}
editor.accessibility.focusPopup($popup);}
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');}
2017-02-08 08:10:24 +00:00
else{attrs[$input.attr('name')]=$input.data('unchecked')||null;}}
var t=editor.helpers.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();}}
2017-02-08 08:10:24 +00:00
function insert(href,text,attrs){if(typeof attrs=='undefined')attrs={};if(editor.events.trigger('link.beforeInsert',[href,text,attrs])===false)return false;var $current_image=editor.image?editor.image.get():null;if(!$current_image&&editor.el.tagName!='A'){editor.selection.restore();editor.popups.hide('link.insert');}
else if(editor.el.tagName=='A'){editor.$el.focus();}
2016-05-21 19:21:19 +00:00
var original_href=href;if(editor.opts.linkConvertEmailAddress){var regex=/^[\w._]+@[a-z\u00a1-\uffff0-9_-]+?\.[a-z\u00a1-\uffff0-9]{2,}$/i;if(regex.test(href)&&!/^mailto:.*/i.test(href)){href='mailto:'+href;}}
if(editor.opts.linkAutoPrefix!==''&&!/^(mailto|tel|sms|notes|data):.*/i.test(href)&&!/^data:image.*/i.test(href)&&!/^(https?:|ftps?:|file:|)\/\//i.test(href)){if(['/','{','[','#','('].indexOf((href||'')[0])<0){href=editor.opts.linkAutoPrefix+href;}}
2017-02-08 08:10:24 +00:00
href=editor.helpers.sanitizeURL(href);if(editor.opts.linkAlwaysBlank)attrs.target='_blank';if(editor.opts.linkAlwaysNoFollow)attrs.rel='nofollow';if(attrs.target=='_blank'){if(!attrs.rel)attrs.rel='noopener noreferrer';else attrs.rel+=' noopener noreferrer';}
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);$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();}}
2016-05-21 19:21:19 +00:00
else{if(!$current_image){editor.format.remove('a');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().replace(/\n/g,'')){editor.selection.remove();editor.html.insert('<a href="'+href+'">'+$.FE.START_MARKER+text+$.FE.END_MARKER+'</a>');editor.selection.restore();}
else{_split();editor.format.apply('a',{href: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();}}
2017-02-08 08:10:24 +00:00
editor.popups.setContainer('link.insert',editor.$sc);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();}
2017-02-08 08:10:24 +00:00
else if(editor.el.tagName=='A'){editor.$el.focus();_edit();}
else{editor.popups.hide('link.insert');editor.toolbar.showInline();}}
else{editor.image.back();}}
2017-02-08 08:10:24 +00:00
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.$sc);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}}
2016-05-21 19:21:19 +00:00
$.FE.DefineIcon('insertLink',{NAME:'link'});$.FE.RegisterShortcut($.FE.KEYCODE.K,'insertLink',null,'K');$.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();}
2017-02-08 08:10:24 +00:00
else{if(this.$el.find('.fr-marker').length){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);}}})
2017-02-08 08:10:24 +00:00
$.FE.DefineIcon('linkEdit',{NAME:'edit'});$.FE.RegisterCommand('linkEdit',{title:'Edit Link',undo:false,refreshAfterCallback:false,popup:true,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');}}})
2017-02-08 08:10:24 +00:00
$.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()&&this.doc.hasFocus();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" role="presentation">';var options=this.opts.linkList;for(var i=0;i<options.length;i++){c+='<li role="presentation"><a class="fr-command" tabIndex="-1" role="option" 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'})
2017-02-08 08:10:24 +00:00
$.FE.RegisterCommand('imageLink',{title:'Insert Link',undo:false,focus:false,popup:true,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'})
2017-02-08 08:10:24 +00:00
$.FE.RegisterCommand('linkStyle',{title:'Style',type:'dropdown',html:function(){var c='<ul class="fr-dropdown-list" role="presentation">';var options=this.opts.linkStyles;for(var cls in options){if(options.hasOwnProperty(cls)){c+='<li role="presentation"><a class="fr-command" tabIndex="-1" role="option" data-cmd="linkStyle" data-param1="'+cls+'">'+this.language.translate(options[cls])+'</a></li>';}}
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');var active=$link.hasClass(cls);$(this).toggleClass('fr-active',active).attr('aria-selected',active);})}}})}));!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){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","|"],tableResizer:!0,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 a=I();if(a){var c=b.popups.get("table.edit");c||(c=k()),b.popups.setContainer("table.edit",b.$sc);var d=P(a),e=(d.left+d.right)/2,f=d.bottom;b.popups.show("table.edit",e,f,d.bottom-d.top),b.edit.isDisabled()&&(b.toolbar.disable(),b.$el.removeClass("fr-no-selection"),b.edit.on(),b.button.bulkRefresh(),b.selection.setAtEnd(b.$el.find(".fr-selected-cell:last").get(0)),b.$el.focus(),b.selection.restore())}}function e(){var a=I();if(a){var c=b.popups.get("table.colors");c||(c=l()),b.popups.setContainer("table.colors",b.$sc);var d=P(a),e=(d.left+d.right)/2,f=d.bottom;o(),b.popups.show("table.colors",e,f,d.bottom-d.top)}}function f(){0===ra().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:i()},f=b.popups.create("table.insert",e);return b.events.$on(f,"mouseenter",".fr-table-size .fr-select-table-size .fr-table-cell",function(b){h(a(b.currentTarget))},!0),j(f),f}function h(a){var c=a.data("row"),d=a.data("col"),e=a.parent();e.siblings(".fr-table-size-info").html(c+" &times; "+d),e.find("> span").removeClass("hover fr-active-item");for(var f=1;f<=b.opts.tableInsertMaxSize;f++)for(var g=0;g<=b.opts.tableInsertMaxSize;g++){var h=e.find('> span[data-row="'+f+'"][data-col="'+g+'"]');f<=c&&g<=d?h.addClass("hover"):f<=c+1||f<=2&&!b.helpers.isMobile()?h.css("display","inline-block"):f>2&&!b.helpers.isMobile()&&h.css("display","none")}a.addClass("fr-active-item")}function i(){for(var a='<div class="fr-table-size"><div class="fr-table-size-info">1 &times; 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.is
else{jQuery=require('jquery')(root);}}
factory(jQuery);return jQuery;};}else{factory(jQuery);}}(function($){'use strict';$.extend($.FE.POPUP_TEMPLATES,{'video.insert':'[_BUTTONS_][_BY_URL_LAYER_][_EMBED_LAYER_]','video.edit':'[_BUTTONS_]','video.size':'[_BUTTONS_][_SIZE_LAYER_]'})
$.extend($.FE.DEFAULTS,{videoInsertButtons:['videoBack','|','videoByURL','videoEmbed'],videoEditButtons:['videoDisplay','videoAlign','videoSize','videoRemove'],videoResize:true,videoSizeButtons:['videoBack','|'],videoSplitHTML:false,videoTextNear:true,videoDefaultAlign:'center',videoDefaultDisplay:'block',videoMove:true});$.FE.VIDEO_PROVIDERS=[{test_regex:/^.*((youtu.be)|(youtube.com))\/((v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))?\??v?=?([^#\&\?]*).*/,url_regex:/(?:https?:\/\/)?(?:www\.)?(?:m\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=|embed\/)?([0-9a-zA-Z_\-]+)(.+)?/g,url_text:'//www.youtube.com/embed/$1',html:'<iframe width="640" height="360" src="{url}?wmode=opaque" frameborder="0" allowfullscreen></iframe>'},{test_regex:/^.*(vimeo\.com\/)((channels\/[A-z]+\/)|(groups\/[A-z]+\/videos\/))?([0-9]+)/,url_regex:/(?:https?:\/\/)?(?:www\.)?(?:vimeo\.com)\/(?:channels\/[A-z]+\/|groups\/[A-z]+\/videos\/)?(.+)/g,url_text:'//player.vimeo.com/video/$1',html:'<iframe width="640" height="360" src="{url}" frameborder="0" allowfullscreen></iframe>'},{test_regex:/^.+(dailymotion.com|dai.ly)\/(video|hub)?\/?([^_]+)[^#]*(#video=([^_&]+))?/,url_regex:/(?:https?:\/\/)?(?:www\.)?(?:dailymotion\.com|dai\.ly)\/(?:video|hub)?\/?(.+)/g,url_text:'//www.dailymotion.com/embed/video/$1',html:'<iframe width="640" height="360" src="{url}" frameborder="0" allowfullscreen></iframe>'},{test_regex:/^.+(screen.yahoo.com)\/[^_&]+/,url_regex:'',url_text:'',html:'<iframe width="640" height="360" src="{url}?format=embed" frameborder="0" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" allowtransparency="true"></iframe>'},{test_regex:/^.+(rutube.ru)\/[^_&]+/,url_regex:/(?:https?:\/\/)?(?:www\.)?(?:rutube\.ru)\/(?:video)?\/?(.+)/g,url_text:'//rutube.ru/play/embed/$1',html:'<iframe width="640" height="360" src="{url}" frameborder="0" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" allowtransparency="true"></iframe>'}];$.FE.VIDEO_EMBED_REGEX=/^\W*((<iframe.*><\/iframe>)|(<embed.*>))\W*$/i;$.FE.PLUGINS.video=function(editor){var $overlay;var $handler;var $video_resizer;var $current_video;function _refreshInsertPopup(){var $popup=editor.popups.get('video.insert');var $url_input=$popup.find('.fr-video-by-url-layer input');$url_input.val('').trigger('change');var $embed_area=$popup.find('.fr-video-embed-layer textarea');$embed_area.val('').trigger('change');}
function showInsertPopup(){var $btn=editor.$tb.find('.fr-command[data-cmd="insertVideo"]');var $popup=editor.popups.get('video.insert');if(!$popup)$popup=_initInsertPopup();if(!$popup.hasClass('fr-active')){editor.popups.refresh('video.insert');editor.popups.setContainer('video.insert',editor.$tb);var left=$btn.offset().left+$btn.outerWidth()/2;var top=$btn.offset().top+(editor.opts.toolbarBottom?10:$btn.outerHeight()-10);editor.popups.show('video.insert',left,top,$btn.outerHeight());}}
function _showEditPopup(){var $popup=editor.popups.get('video.edit');if(!$popup)$popup=_initEditPopup();editor.popups.setContainer('video.edit',$(editor.opts.scrollableContainer));editor.popups.refresh('video.edit');var $video_obj=$current_video.find('iframe, embed, video');var left=$video_obj.offset().left+$video_obj.outerWidth()/2;var top=$video_obj.offset().top+$video_obj.outerHeight();editor.popups.show('video.edit',left,top,$video_obj.outerHeight());}
function _initInsertPopup(delayed){if(delayed){editor.popups.onRefresh('video.insert',_refreshInsertPopup);return true;}
var video_buttons='';if(editor.opts.videoInsertButtons.length>1){video_buttons='<div class="fr-buttons">'+editor.button.buildList(editor.opts.videoInsertButtons)+'</div>';}
var by_url_layer='';if(editor.opts.videoInsertButtons.indexOf('videoByURL')>=0){by_url_layer='<div class="fr-video-by-url-layer fr-layer fr-active" id="fr-video-by-url-layer-'+editor.id+'"><div class="fr-input-line"><input type="text" placeholder="http://" tabIndex="1"></div><div class="fr-action-buttons"><button type="button" class="fr-command fr-submit" data-cmd="videoInsertByURL" tabIndex="2">'+editor.language.translate('Insert')+'</button></div></div>'}
var embed_layer='';if(editor.opts.videoInsertButtons.indexOf('videoEmbed')>=0){embed_layer='<div class="fr-video-embed-layer fr-layer" id="fr-video-embed-layer-'+editor.id+'"><div class="fr-input-line"><textarea type="text" placeholder="'+editor.language.translate('Embedded Code')+'" tabIndex="1" rows="5"></textarea></div><div class="fr-action-buttons"><button type="button" class="fr-command fr-submit" data-cmd="videoInsertEmbed" tabIndex="2">'+editor.language.translate('Insert')+'</button></div></div>'}
var template={buttons:video_buttons,by_url_layer:by_url_layer,embed_layer:embed_layer}
var $popup=editor.popups.create('video.insert',template);return $popup;}
function showLayer(name){var $popup=editor.popups.get('video.insert');var left;var top;if(!$current_video&&!editor.opts.toolbarInline){var $btn=editor.$tb.find('.fr-command[data-cmd="insertVideo"]');left=$btn.offset().left+$btn.outerWidth()/2;top=$btn.offset().top+(editor.opts.toolbarBottom?10:$btn.outerHeight()-10);}
if(editor.opts.toolbarInline){top=$popup.offset().top-editor.helpers.getPX($popup.css('margin-top'));if($popup.hasClass('fr-above')){top+=$popup.outerHeight();}}
$popup.find('.fr-layer').removeClass('fr-active');$popup.find('.fr-'+name+'-layer').addClass('fr-active');editor.popups.show('video.insert',left,top,0);}
function refreshByURLButton($btn){var $popup=editor.popups.get('video.insert');if($popup.find('.fr-video-by-url-layer').hasClass('fr-active')){$btn.addClass('fr-active');}}
function refreshEmbedButton($btn){var $popup=editor.popups.get('video.insert');if($popup.find('.fr-video-embed-layer').hasClass('fr-active')){$btn.addClass('fr-active');}}
function insert(embedded_code){editor.events.focus(true);editor.selection.restore();editor.html.insert('<span contenteditable="false" draggable="true" class="fr-jiv fr-video fr-dv'+(editor.opts.videoDefaultDisplay[0])+(editor.opts.videoDefaultAlign!='center'?' fr-fv'+editor.opts.videoDefaultAlign[0]:'')+'">'+embedded_code+'</span>',false,editor.opts.videoSplitHTML);editor.popups.hide('video.insert');var $video=editor.$el.find('.fr-jiv');$video.removeClass('fr-jiv');$video.toggleClass('fr-draggable',editor.opts.videoMove);editor.events.trigger('video.inserted',[$video]);}
function insertByURL(link){if(typeof link=='undefined'){var $popup=editor.popups.get('video.insert');link=$popup.find('.fr-video-by-url-layer input[type="text"]').val()||'';}
var video=null;if(editor.helpers.isURL(link)){for(var i=0;i<$.FE.VIDEO_PROVIDERS.length;i++){var vp=$.FE.VIDEO_PROVIDERS[i];if(vp.test_regex.test(link)){video=link.replace(vp.url_regex,vp.url_text);video=vp.html.replace(/\{url\}/,video);break;}}}
if(video){insert(video);}
else{editor.events.trigger('video.linkError',[link]);}}
function insertEmbed(code){if(typeof code=='undefined'){var $popup=editor.popups.get('video.insert');code=$popup.find('.fr-video-embed-layer textarea').val()||'';}
if(code.length===0||!$.FE.VIDEO_EMBED_REGEX.test(code)){editor.events.trigger('video.codeError',[code]);}
else{insert(code);}}
function _handlerMousedown(e){if(!editor.core.sameInstance($video_resizer))return true;e.preventDefault();e.stopPropagation();var c_x=e.pageX||(e.originalEvent.touches?e.originalEvent.touches[0].pageX:null);var c_y=e.pageY||(e.originalEvent.touches?e.originalEvent.touches[0].pageY:null);if(!c_x||!c_y){return false;}
if(!editor.undo.canDo())editor.undo.saveStep();$handler=$(this);$handler.data('start-x',c_x);$handler.data('start-y',c_y);$overlay.show();editor.popups.hideAll();_unmarkExit();}
function _handlerMousemove(e){if(!editor.core.sameInstance($video_resizer))return true;if($handler){e.preventDefault()
var c_x=e.pageX||(e.originalEvent.touches?e.originalEvent.touches[0].pageX:null);var c_y=e.pageY||(e.originalEvent.touches?e.originalEvent.touches[0].pageY:null);if(!c_x||!c_y){return false;}
var s_x=$handler.data('start-x');var s_y=$handler.data('start-y');$handler.data('start-x',c_x);$handler.data('start-y',c_y);var diff_x=c_x-s_x;var diff_y=c_y-s_y;var $video_obj=$current_video.find('iframe, embed, video');var width=$video_obj.width();var height=$video_obj.height();if($handler.hasClass('fr-hnw')||$handler.hasClass('fr-hsw')){diff_x=0-diff_x;}
if($handler.hasClass('fr-hnw')||$handler.hasClass('fr-hne')){diff_y=0-diff_y;}
$video_obj.css('width',width+diff_x);$video_obj.css('height',height+diff_y);$video_obj.removeAttr('width');$video_obj.removeAttr('height');_repositionResizer();}}
function _handlerMouseup(e){if(!editor.core.sameInstance($video_resizer))return true;if($handler&&$current_video){if(e)e.stopPropagation();$handler=null;$overlay.hide();_repositionResizer();_showEditPopup();editor.undo.saveStep();}}
function _getHandler(pos){return'<div class="fr-handler fr-h'+pos+'"></div>';}
function _initResizer(){var doc;if(!editor.shared.$video_resizer){editor.shared.$video_resizer=$('<div class="fr-video-resizer"></div>');$video_resizer=editor.shared.$video_resizer;editor.events.$on($video_resizer,'mousedown',function(e){e.stopPropagation();},true);if(editor.opts.videoResize){$video_resizer.append(_getHandler('nw')+_getHandler('ne')+_getHandler('sw')+_getHandler('se'));editor.shared.$vid_overlay=$('<div class="fr-video-overlay"></div>');$overlay=editor.shared.$vid_overlay;doc=$video_resizer.get(0).ownerDocument;$(doc).find('body').append($overlay);}}else{$video_resizer=editor.shared.$video_resizer;$overlay=editor.shared.$vid_overlay;editor.events.on('destroy',function(){$video_resizer.removeClass('fr-active').appendTo($('body'));},true);}
editor.events.on('shared.destroy',function(){$video_resizer.html('').removeData().remove();$video_resizer=null;if(editor.opts.videoResize){$overlay.remove();$overlay=null;}},true);if(!editor.helpers.isMobile()){editor.events.$on($(editor.o_win),'resize.video',function(){_exitEdit(true);});}
if(editor.opts.videoResize){doc=$video_resizer.get(0).ownerDocument;editor.events.$on($video_resizer,editor._mousedown,'.fr-handler',_handlerMousedown);editor.events.$on($(doc),editor._mousemove,_handlerMousemove);editor.events.$on($(doc.defaultView||doc.parentWindow),editor._mouseup,_handlerMouseup);editor.events.$on($overlay,'mouseleave',_handlerMouseup);}}
function _repositionResizer(){if(!$video_resizer)_initResizer();(editor.$wp||$(editor.opts.scrollableContainer)).append($video_resizer);$video_resizer.data('instance',editor);var $video_obj=$current_video.find('iframe, embed, video');$video_resizer.css('top',(editor.opts.iframe?$video_obj.offset().top-1:$video_obj.offset().top-editor.$wp.offset().top-1)+editor.$wp.scrollTop()).css('left',(editor.opts.iframe?$video_obj.offset().left-1:$video_obj.offset().left-editor.$wp.offset().left-1)+editor.$wp.scrollLeft()).css('width',$video_obj.outerWidth()).css('height',$video_obj.height()).addClass('fr-active')}
var touchScroll;function _edit(e){if(e&&e.type=='touchend'&&touchScroll){return true;}
e.preventDefault();e.stopPropagation();if(editor.edit.isDisabled()){return false;}
for(var i=0;i<$.FE.INSTANCES.length;i++){if($.FE.INSTANCES[i]!=editor){$.FE.INSTANCES[i].events.trigger('video.hideResizer');}}
editor.toolbar.disable();if(editor.helpers.isMobile()){editor.events.disableBlur();editor.$el.blur();editor.events.enableBlur();}
$current_video=$(this);$(this).addClass('fr-active');if(editor.opts.iframe){editor.size.syncIframe();}
_repositionResizer();_showEditPopup();editor.selection.clear();editor.button.bulkRefresh();editor.events.trigger('image.hideResizer');}
function _exitEdit(force_exit){if($current_video&&(_canExit()||force_exit===true)){$video_resizer.removeClass('fr-active');editor.toolbar.enable();$current_video.removeClass('fr-active');$current_video=null;_unmarkExit();}}
editor.shared.vid_exit_flag=false;function _markExit(){editor.shared.vid_exit_flag=true;}
function _unmarkExit(){editor.shared.vid_exit_flag=false;}
function _canExit(){return editor.shared.vid_exit_flag;}
function _initEvents(){editor.events.on('mousedown window.mousedown',_markExit);editor.events.on('window.touchmove',_unmarkExit);editor.events.on('mouseup window.mouseup',_exitEdit);editor.events.on('commands.mousedown',function($btn){if($btn.parents('.fr-toolbar').length>0){_exitEdit();}});editor.events.on('blur video.hideResizer commands.undo commands.redo element.dropped',function(){_exitEdit(true);});}
function _initEditPopup(){var video_buttons='';if(editor.opts.videoEditButtons.length>=1){video_buttons+='<div class="fr-buttons">';video_buttons+=editor.button.buildList(editor.opts.videoEditButtons);video_buttons+='</div>';}
var template={buttons:video_buttons}
var $popup=editor.popups.create('video.edit',template);editor.events.$on(editor.$wp,'scroll.video-edit',function(){if($current_video&&editor.popups.isVisible('video.edit')){_showEditPopup();}});return $popup;}
function _refreshSizePopup(){if($current_video){var $popup=editor.popups.get('video.size');var $video_obj=$current_video.find('iframe, embed, video')
$popup.find('input[name="width"]').val($video_obj.get(0).style.width||$video_obj.attr('width')).trigger('change');$popup.find('input[name="height"]').val($video_obj.get(0).style.height||$video_obj.attr('height')).trigger('change');}}
function showSizePopup(){var $popup=editor.popups.get('video.size');if(!$popup)$popup=_initSizePopup();editor.popups.refresh('video.size');editor.popups.setContainer('video.size',$(editor.opts.scrollableContainer));var $video_obj=$current_video.find('iframe, embed, video')
var left=$video_obj.offset().left+$video_obj.width()/2;var top=$video_obj.offset().top+$video_obj.height();editor.popups.show('video.size',left,top,$video_obj.height());}
function _initSizePopup(delayed){if(delayed){editor.popups.onRefresh('video.size',_refreshSizePopup);return true;}
var video_buttons='';video_buttons='<div class="fr-buttons">'+editor.button.buildList(editor.opts.videoSizeButtons)+'</div>';var size_layer='';size_layer='<div class="fr-video-size-layer fr-layer fr-active" id="fr-video-size-layer-'+editor.id+'"><div class="fr-video-group"><div class="fr-input-line"><input type="text" name="width" placeholder="'+editor.language.translate('Width')+'" tabIndex="1"></div><div class="fr-input-line"><input type="text" name="height" placeholder="'+editor.language.translate('Height')+'" tabIndex="1"></div></div><div class="fr-action-buttons"><button type="button" class="fr-command fr-submit" data-cmd="videoSetSize" tabIndex="2">'+editor.language.translate('Update')+'</button></div></div>';var template={buttons:video_buttons,size_layer:size_layer}
var $popup=editor.popups.create('video.size',template);editor.events.$on(editor.$wp,'scroll',function(){if($current_video&&editor.popups.isVisible('video.size')){showSizePopup();}});return $popup;}
function align(val){$current_video.removeClass('fr-fvr fr-fvl');if(val=='left'){$current_video.addClass('fr-fvl');}
else if(val=='right'){$current_video.addClass('fr-fvr');}
_repositionResizer();_showEditPopup();}
function refreshAlign($btn){if(!$current_video)return false;if($current_video.hasClass('fr-fvl')){$btn.find('> *:first').replaceWith(editor.icon.create('align-left'));}
else if($current_video.hasClass('fr-fvr')){$btn.find('> *:first').replaceWith(editor.icon.create('align-right'));}
else{$btn.find('> *:first').replaceWith(editor.icon.create('align-justify'));}}
function refreshAlignOnShow($btn,$dropdown){var alignment='justify';if($current_video.hasClass('fr-fvl')){alignment='left';}
else if($current_video.hasClass('fr-fvr')){alignment='right';}
$dropdown.find('.fr-command[data-param1="'+alignment+'"]').addClass('fr-active');}
function display(val){$current_video.removeClass('fr-dvi fr-dvb');if(val=='inline'){$current_video.addClass('fr-dvi');}
else if(val=='block'){$current_video.addClass('fr-dvb');}
_repositionResizer();_showEditPopup();}
function refreshDisplayOnShow($btn,$dropdown){var d='block';if($current_video.hasClass('fr-dvi')){d='inline';}
$dropdown.find('.fr-command[data-param1="'+d+'"]').addClass('fr-active');}
function remove(){if($current_video){if(editor.events.trigger('video.beforeRemove',[$current_video])!==false){var $video=$current_video;editor.popups.hideAll();_exitEdit(true);editor.selection.setBefore($video.get(0))||editor.selection.setAfter($video.get(0));$video.remove();editor.selection.restore();editor.html.fillEmptyBlocks();editor.events.trigger('video.removed',[$video]);}}}
function _convertStyleToClasses($video){if(!$video.hasClass('fr-dvi')&&!$video.hasClass('fr-dvb')){var flt=$video.css('float');$video.css('float','none');if($video.css('display')=='block'){$video.css('float',flt);if(parseInt($video.css('margin-left'),10)===0&&($video.attr('style')||'').indexOf('margin-right: auto')>=0){$video.addClass('fr-fvl');}
else if(parseInt($video.css('margin-right'),10)===0&&($video.attr('style')||'').indexOf('margin-left: auto')>=0){$video.addClass('fr-fvr');}
$video.addClass('fr-dvb');}
else{$video.css('float',flt);if($video.css('float')=='left'){$video.addClass('fr-fvl');}
else if($video.css('float')=='right'){$video.addClass('fr-fvr');}
$video.addClass('fr-dvi');}
$video.css('margin','');$video.css('float','');$video.css('display','');$video.css('z-index','');$video.css('position','');$video.css('overflow','');$video.css('vertical-align','');}
if(!editor.opts.videoTextNear){$video.removeClass('fr-dvi').addClass('fr-dvb');}}
function _refreshVideoList(){editor.$el.find('video').filter(function(){return $(this).parents('span.fr-video').length===0;}).wrap('<span class="fr-video" contenteditable="false"></span>');editor.$el.find('embed, iframe').filter(function(){if(editor.browser.safari&&this.getAttribute('src')){this.setAttribute('src',this.src);}
if($(this).parents('span.fr-video').length>0)return false;var link=$(this).attr('src');for(var i=0;i<$.FE.VIDEO_PROVIDERS.length;i++){var vp=$.FE.VIDEO_PROVIDERS[i];if(vp.test_regex.test(link)){return true;}}
return false;}).map(function(){return $(this).parents('object').length===0?this:$(this).parents('object').get(0);}).wrap('<span class="fr-video" contenteditable="false"></span>');var videos=editor.$el.find('span.fr-video');for(var i=0;i<videos.length;i++){_convertStyleToClasses($(videos[i]));}
videos.toggleClass('fr-draggable',editor.opts.videoMove);}
function _init(){_initEvents();if(editor.helpers.isMobile()){editor.events.$on(editor.$el,'touchstart','span.fr-video',function(){touchScroll=false;})
editor.events.$on(editor.$el,'touchmove',function(){touchScroll=true;});}
editor.events.on('html.set',_refreshVideoList);_refreshVideoList();editor.events.$on(editor.$el,'mousedown','span.fr-video',function(e){e.stopPropagation();})
editor.events.$on(editor.$el,'click touchend','span.fr-video',_edit);editor.events.on('keydown',function(e){var key_code=e.which;if($current_video&&(key_code==$.FE.KEYCODE.BACKSPACE||key_code==$.FE.KEYCODE.DELETE)){e.preventDefault();remove();return false;}
if($current_video&&key_code==$.FE.KEYCODE.ESC){_exitEdit(true);e.preventDefault();return false;}
if($current_video&&!editor.keys.ctrlKey(e)){e.preventDefault();return false;}},true);editor.events.on('keydown',function(){editor.$el.find('span.fr-video:empty').remove();})
_initInsertPopup(true);_initSizePopup(true);}
function back(){if($current_video){$current_video.trigger('click');}
else{editor.events.disableBlur();editor.selection.restore();editor.events.enableBlur();editor.popups.hide('video.insert');editor.toolbar.showInline();}}
function setSize(width,height){if($current_video){var $popup=editor.popups.get('video.size');var $video_obj=$current_video.find('iframe, embed, video');$video_obj.css('width',width||$popup.find('input[name="width"]').val());$video_obj.css('height',height||$popup.find('input[name="height"]').val());if($video_obj.get(0).style.width)$video_obj.removeAttr('width');if($video_obj.get(0).style.height)$video_obj.removeAttr('height');$popup.find('input').blur();setTimeout(function(){$current_video.trigger('click');},editor.helpers.isAndroid()?50:0);}}
function get(){return $current_video;}
return{_init:_init,showInsertPopup:showInsertPopup,showLayer:showLayer,refreshByURLButton:refreshByURLButton,refreshEmbedButton:refreshEmbedButton,insertByURL:insertByURL,insertEmbed:insertEmbed,insert:insert,align:align,refreshAlign:refreshAlign,refreshAlignOnShow:refreshAlignOnShow,display:display,refreshDisplayOnShow:refreshDisplayOnShow,remove:remove,showSizePopup:showSizePopup,back:back,setSize:setSize,get:get}}
$.FE.RegisterCommand('insertVideo',{title:'Insert Video',undo:false,focus:true,refreshAfterCallback:false,popup:true,callback:function(){if(!this.popups.isVisible('video.insert')){this.video.showInsertPopup();}
else{if(this.$el.find('.fr-marker')){this.events.disableBlur();this.selection.restore();}
this.popups.hide('video.insert');}},plugin:'video'})
$.FE.DefineIcon('insertVideo',{NAME:'video-camera'});$.FE.DefineIcon('videoByURL',{NAME:'link'});$.FE.RegisterCommand('videoByURL',{title:'By URL',undo:false,focus:false,callback:function(){this.video.showLayer('video-by-url');},refresh:function($btn){this.video.refreshByURLButton($btn);}})
$.FE.DefineIcon('videoEmbed',{NAME:'code'});$.FE.RegisterCommand('videoEmbed',{title:'Embedded Code',undo:false,focus:false,callback:function(){this.video.showLayer('video-embed');},refresh:function($btn){this.video.refreshEmbedButton($btn);}})
$.FE.RegisterCommand('videoInsertByURL',{undo:true,focus:true,callback:function(){this.video.insertByURL();}})
$.FE.RegisterCommand('videoInsertEmbed',{undo:true,focus:true,callback:function(){this.video.insertEmbed();}})
$.FE.DefineIcon('videoDisplay',{NAME:'star'})
$.FE.RegisterCommand('videoDisplay',{title:'Display',type:'dropdown',options:{inline:'Inline',block:'Break Text'},callback:function(cmd,val){this.video.display(val);},refresh:function($btn){if(!this.opts.videoTextNear)$btn.addClass('fr-hidden');},refreshOnShow:function($btn,$dropdown){this.video.refreshDisplayOnShow($btn,$dropdown);}})
$.FE.DefineIcon('videoAlign',{NAME:'align-center'})
$.FE.RegisterCommand('videoAlign',{type:'dropdown',title:'Align',options:{left:'Align Left',justify:'None',right:'Align Right'},html:function(){var c='<ul class="fr-dropdown-list">';var options=$.FE.COMMANDS.videoAlign.options;for(var val in options){if(options.hasOwnProperty(val)){c+='<li><a class="fr-command fr-title" data-cmd="videoAlign" data-param1="'+val+'" title="'+this.language.translate(options[val])+'">'+this.icon.create('align-'+val)+'</a></li>';}}
c+='</ul>';return c;},callback:function(cmd,val){this.video.align(val);},refresh:function($btn){this.video.refreshAlign($btn);},refreshOnShow:function($btn,$dropdown){this.video.refreshAlignOnShow($btn,$dropdown);}})
$.FE.DefineIcon('videoRemove',{NAME:'trash'})
$.FE.RegisterCommand('videoRemove',{title:'Remove',callback:function(){this.video.remove();}})
$.FE.DefineIcon('videoSize',{NAME:'arrows-alt'})
$.FE.RegisterCommand('videoSize',{undo:false,focus:false,title:'Change Size',callback:function(){this.video.showSizePopup();}});$.FE.DefineIcon('videoBack',{NAME:'arrow-left'});$.FE.RegisterCommand('videoBack',{title:'Back',undo:false,focus:false,back:true,callback:function(){this.video.back();},refresh:function($btn){var $current_video=this.video.get();if(!$current_video&&!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.RegisterCommand('videoSetSize',{undo:true,focus:false,callback:function(){this.video.setSize();}})}));(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.POPUP_TEMPLATES,{'audio.insert':'[_BUTTONS_][_BY_URL_LAYER_][_EMBED_LAYER_]','audio.edit':'[_BUTTONS_]','audio.size':'[_BUTTONS_][_SIZE_LAYER_]'})
$.extend($.FE.DEFAULTS,{audioInsertButtons:['audioBack','|','audioByURL','audioEmbed'],audioEditButtons:['audioDisplay','audioAlign','audioSize','audioRemove'],audioResize:true,audioSizeButtons:['audioBack','|'],audioSplitHTML:false,audioTextNear:true,audioDefaultAlign:'center',audioDefaultDisplay:'block',audioMove:true});$.FE.VIDEO_PROVIDERS=[];$.FE.VIDEO_EMBED_REGEX=/^\W*((<iframe.*><\/iframe>)|(<embed.*>))\W*$/i;$.FE.PLUGINS.audio=function(editor){var $overlay;var $handler;var $audio_resizer;var $current_audio;function _refreshInsertPopup(){var $popup=editor.popups.get('audio.insert');var $url_input=$popup.find('.fr-audio-by-url-layer input');$url_input.val('').trigger('change');var $embed_area=$popup.find('.fr-audio-embed-layer textarea');$embed_area.val('').trigger('change');}
function showInsertPopup(){var $btn=editor.$tb.find('.fr-command[data-cmd="insertAudio"]');var $popup=editor.popups.get('audio.insert');if(!$popup)$popup=_initInsertPopup();if(!$popup.hasClass('fr-active')){editor.popups.refresh('audio.insert');editor.popups.setContainer('audio.insert',editor.$tb);var left=$btn.offset().left+$btn.outerWidth()/2;var top=$btn.offset().top+(editor.opts.toolbarBottom?10:$btn.outerHeight()-10);editor.popups.show('audio.insert',left,top,$btn.outerHeight());}}
function _showEditPopup(){var $popup=editor.popups.get('audio.edit');if(!$popup)$popup=_initEditPopup();editor.popups.setContainer('audio.edit',$(editor.opts.scrollableContainer));editor.popups.refresh('audio.edit');var $audio_obj=$current_audio.find('iframe, embed, audio');var left=$audio_obj.offset().left+$audio_obj.outerWidth()/2;var top=$audio_obj.offset().top+$audio_obj.outerHeight();editor.popups.show('audio.edit',left,top,$audio_obj.outerHeight());}
function _initInsertPopup(delayed){if(delayed){editor.popups.onRefresh('audio.insert',_refreshInsertPopup);return true;}
var audio_buttons='';if(editor.opts.audioInsertButtons.length>1){audio_buttons='<div class="fr-buttons">'+editor.button.buildList(editor.opts.audioInsertButtons)+'</div>';}
var by_url_layer='';if(editor.opts.audioInsertButtons.indexOf('audioByURL')>=0){by_url_layer='<div class="fr-audio-by-url-layer fr-layer fr-active" id="fr-audio-by-url-layer-'+editor.id+'"><div class="fr-input-line"><input type="text" placeholder="http://" tabIndex="1"></div><div class="fr-action-buttons"><button type="button" class="fr-command fr-submit" data-cmd="audioInsertByURL" tabIndex="2">'+editor.language.translate('Insert')+'</button></div></div>'}
var embed_layer='';if(editor.opts.audioInsertButtons.indexOf('audioEmbed')>=0){embed_layer='<div class="fr-audio-embed-layer fr-layer" id="fr-audio-embed-layer-'+editor.id+'"><div class="fr-input-line"><textarea type="text" placeholder="'+editor.language.translate('Embedded Code')+'" tabIndex="1" rows="5"></textarea></div><div class="fr-action-buttons"><button type="button" class="fr-command fr-submit" data-cmd="audioInsertEmbed" tabIndex="2">'+editor.language.translate('Insert')+'</button></div></div>'}
var template={buttons:audio_buttons,by_url_layer:by_url_layer,embed_layer:embed_layer}
var $popup=editor.popups.create('audio.insert',template);return $popup;}
function showLayer(name){var $popup=editor.popups.get('audio.insert');var left;var top;if(!$current_audio&&!editor.opts.toolbarInline){var $btn=editor.$tb.find('.fr-command[data-cmd="insertAudio"]');left=$btn.offset().left+$btn.outerWidth()/2;top=$btn.offset().top+(editor.opts.toolbarBottom?10:$btn.outerHeight()-10);}
if(editor.opts.toolbarInline){top=$popup.offset().top-editor.helpers.getPX($popup.css('margin-top'));if($popup.hasClass('fr-above')){top+=$popup.outerHeight();}}
$popup.find('.fr-layer').removeClass('fr-active');$popup.find('.fr-'+name+'-layer').addClass('fr-active');editor.popups.show('audio.insert',left,top,0);}
function refreshByURLButton($btn){var $popup=editor.popups.get('audio.insert');if($popup.find('.fr-audio-by-url-layer').hasClass('fr-active')){$btn.addClass('fr-active');}}
function refreshEmbedButton($btn){var $popup=editor.popups.get('audio.insert');if($popup.find('.fr-audio-embed-layer').hasClass('fr-active')){$btn.addClass('fr-active');}}
function insert(embedded_code){editor.events.focus(true);editor.selection.restore();editor.html.insert('<span contenteditable="false" draggable="true" class="fr-jiv fr-video fr-dv'+(editor.opts.audioDefaultDisplay[0])+(editor.opts.audioDefaultAlign!='center'?' fr-fv'+editor.opts.audioDefaultAlign[0]:'')+'">'+embedded_code+'</span>',false,editor.opts.audioSplitHTML);editor.popups.hide('audio.insert');var $audio=editor.$el.find('.fr-jiv');$audio.removeClass('fr-jiv');$audio.toggleClass('fr-draggable',editor.opts.audioMove);editor.events.trigger('audio.inserted',[$audio]);}
function insertByURL(link){if(typeof link=='undefined'){var $popup=editor.popups.get('audio.insert');link=$popup.find('.fr-audio-by-url-layer input[type="text"]').val()||'';}
var audio=null;if(editor.helpers.isURL(link)){for(var i=0;i<$.FE.VIDEO_PROVIDERS.length;i++){var vp=$.FE.VIDEO_PROVIDERS[i];if(vp.test_regex.test(link)){audio=link.replace(vp.url_regex,vp.url_text);audio=vp.html.replace(/\{url\}/,audio);break;}}}
if(audio){insert(audio);}
else{editor.events.trigger('audio.linkError',[link]);}}
function insertEmbed(code){if(typeof code=='undefined'){var $popup=editor.popups.get('audio.insert');code=$popup.find('.fr-audio-embed-layer textarea').val()||'';}
if(code.length===0||!$.FE.VIDEO_EMBED_REGEX.test(code)){editor.events.trigger('audio.codeError',[code]);}
else{insert(code);}}
function _handlerMousedown(e){if(!editor.core.sameInstance($audio_resizer))return true;e.preventDefault();e.stopPropagation();var c_x=e.pageX||(e.originalEvent.touches?e.originalEvent.touches[0].pageX:null);var c_y=e.pageY||(e.originalEvent.touches?e.originalEvent.touches[0].pageY:null);if(!c_x||!c_y){return false;}
if(!editor.undo.canDo())editor.undo.saveStep();$handler=$(this);$handler.data('start-x',c_x);$handler.data('start-y',c_y);$overlay.show();editor.popups.hideAll();_unmarkExit();}
function _handlerMousemove(e){if(!editor.core.sameInstance($audio_resizer))return true;if($handler){e.preventDefault()
var c_x=e.pageX||(e.originalEvent.touches?e.originalEvent.touches[0].pageX:null);var c_y=e.pageY||(e.originalEvent.touches?e.originalEvent.touches[0].pageY:null);if(!c_x||!c_y){return false;}
var s_x=$handler.data('start-x');var s_y=$handler.data('start-y');$handler.data('start-x',c_x);$handler.data('start-y',c_y);var diff_x=c_x-s_x;var diff_y=c_y-s_y;var $audio_obj=$current_audio.find('iframe, embed, audio');var width=$audio_obj.width();var height=$audio_obj.height();if($handler.hasClass('fr-hnw')||$handler.hasClass('fr-hsw')){diff_x=0-diff_x;}
if($handler.hasClass('fr-hnw')||$handler.hasClass('fr-hne')){diff_y=0-diff_y;}
$audio_obj.css('width',width+diff_x);$audio_obj.css('height',height+diff_y);$audio_obj.removeAttr('width');$audio_obj.removeAttr('height');_repositionResizer();}}
function _handlerMouseup(e){if(!editor.core.sameInstance($audio_resizer))return true;if($handler&&$current_audio){if(e)e.stopPropagation();$handler=null;$overlay.hide();_repositionResizer();_showEditPopup();editor.undo.saveStep();}}
function _getHandler(pos){return'<div class="fr-handler fr-h'+pos+'"></div>';}
function _initResizer(){var doc;if(!editor.shared.$audio_resizer){editor.shared.$audio_resizer=$('<div class="fr-video-resizer"></div>');$audio_resizer=editor.shared.$audio_resizer;editor.events.$on($audio_resizer,'mousedown',function(e){e.stopPropagation();},true);if(editor.opts.audioResize){$audio_resizer.append(_getHandler('nw')+_getHandler('ne')+_getHandler('sw')+_getHandler('se'));editor.shared.$audio_overlay=$('<div class="fr-video-overlay"></div>');$overlay=editor.shared.$audio_overlay;doc=$audio_resizer.get(0).ownerDocument;$(doc).find('body').append($overlay);}}else{$audio_resizer=editor.shared.$audio_resizer;$overlay=editor.shared.$audio_overlay;editor.events.on('destroy',function(){$audio_resizer.removeClass('fr-active').appendTo($('body'));},true);}
editor.events.on('shared.destroy',function(){$audio_resizer.html('').removeData().remove();$audio_resizer=null;if(editor.opts.audioResize){$overlay.remove();$overlay=null;}},true);if(!editor.helpers.isMobile()){editor.events.$on($(editor.o_win),'resize.audio',function(){_exitEdit(true);});}
if(editor.opts.audioResize){doc=$audio_resizer.get(0).ownerDocument;editor.events.$on($audio_resizer,editor._mousedown,'.fr-handler',_handlerMousedown);editor.events.$on($(doc),editor._mousemove,_handlerMousemove);editor.events.$on($(doc.defaultView||doc.parentWindow),editor._mouseup,_handlerMouseup);editor.events.$on($overlay,'mouseleave',_handlerMouseup);}}
function _repositionResizer(){if(!$audio_resizer)_initResizer();(editor.$wp||$(editor.opts.scrollableContainer)).append($audio_resizer);$audio_resizer.data('instance',editor);var $audio_obj=$current_audio.find('iframe, embed, audio');$audio_resizer.css('top',(editor.opts.iframe?$audio_obj.offset().top-1:$audio_obj.offset().top-editor.$wp.offset().top-1)+editor.$wp.scrollTop()).css('left',(editor.opts.iframe?$audio_obj.offset().left-1:$audio_obj.offset().left-editor.$wp.offset().left-1)+editor.$wp.scrollLeft()).css('width',$audio_obj.outerWidth()).css('height',$audio_obj.height()).addClass('fr-active')}
var touchScroll;function _edit(e){if(e&&e.type=='touchend'&&touchScroll){return true;}
e.preventDefault();e.stopPropagation();if(editor.edit.isDisabled()){return false;}
for(var i=0;i<$.FE.INSTANCES.length;i++){if($.FE.INSTANCES[i]!=editor){$.FE.INSTANCES[i].events.trigger('audio.hideResizer');}}
editor.toolbar.disable();if(editor.helpers.isMobile()){editor.events.disableBlur();editor.$el.blur();editor.events.enableBlur();}
$current_audio=$(this);$(this).addClass('fr-active');if(editor.opts.iframe){editor.size.syncIframe();}
_repositionResizer();_showEditPopup();editor.selection.clear();editor.button.bulkRefresh();editor.events.trigger('image.hideResizer');}
function _exitEdit(force_exit){if($current_audio&&(_canExit()||force_exit===true)){$audio_resizer.removeClass('fr-active');editor.toolbar.enable();$current_audio.removeClass('fr-active');$current_audio=null;_unmarkExit();}}
editor.shared.audio_exit_flag=false;function _markExit(){editor.shared.audio_exit_flag=true;}
function _unmarkExit(){editor.shared.audio_exit_flag=false;}
function _canExit(){return editor.shared.audio_exit_flag;}
function _initEvents(){editor.events.on('mousedown window.mousedown',_markExit);editor.events.on('window.touchmove',_unmarkExit);editor.events.on('mouseup window.mouseup',_exitEdit);editor.events.on('commands.mousedown',function($btn){if($btn.parents('.fr-toolbar').length>0){_exitEdit();}});editor.events.on('blur audio.hideResizer commands.undo commands.redo element.dropped',function(){_exitEdit(true);});}
function _initEditPopup(){var audio_buttons='';if(editor.opts.audioEditButtons.length>=1){audio_buttons+='<div class="fr-buttons">';audio_buttons+=editor.button.buildList(editor.opts.audioEditButtons);audio_buttons+='</div>';}
var template={buttons:audio_buttons}
var $popup=editor.popups.create('audio.edit',template);editor.events.$on(editor.$wp,'scroll.audio-edit',function(){if($current_audio&&editor.popups.isVisible('audio.edit')){_showEditPopup();}});return $popup;}
function _refreshSizePopup(){if($current_audio){var $popup=editor.popups.get('audio.size');var $audio_obj=$current_audio.find('iframe, embed, audio')
$popup.find('input[name="width"]').val($audio_obj.get(0).style.width||$audio_obj.attr('width')).trigger('change');$popup.find('input[name="height"]').val($audio_obj.get(0).style.height||$audio_obj.attr('height')).trigger('change');}}
function showSizePopup(){var $popup=editor.popups.get('audio.size');if(!$popup)$popup=_initSizePopup();editor.popups.refresh('audio.size');editor.popups.setContainer('audio.size',$(editor.opts.scrollableContainer));var $audio_obj=$current_audio.find('iframe, embed, audio')
var left=$audio_obj.offset().left+$audio_obj.width()/2;var top=$audio_obj.offset().top+$audio_obj.height();editor.popups.show('audio.size',left,top,$audio_obj.height());}
function _initSizePopup(delayed){if(delayed){editor.popups.onRefresh('audio.size',_refreshSizePopup);return true;}
var audio_buttons='';audio_buttons='<div class="fr-buttons">'+editor.button.buildList(editor.opts.audioSizeButtons)+'</div>';var size_layer='';size_layer='<div class="fr-video-size-layer fr-layer fr-active" id="fr-video-size-layer-'+editor.id+'"><div class="fr-audio-group"><div class="fr-input-line"><input type="text" name="width" placeholder="'+editor.language.translate('Width')+'" tabIndex="1"></div><div class="fr-input-line"><input type="text" name="height" placeholder="'+editor.language.translate('Height')+'" tabIndex="1"></div></div><div class="fr-action-buttons"><button type="button" class="fr-command fr-submit" data-cmd="audioSetSize" tabIndex="2">'+editor.language.translate('Update')+'</button></div></div>';var template={buttons:audio_buttons,size_layer:size_layer}
var $popup=editor.popups.create('audio.size',template);editor.events.$on(editor.$wp,'scroll',function(){if($current_audio&&editor.popups.isVisible('audio.size')){showSizePopup();}});return $popup;}
function align(val){$current_audio.removeClass('fr-fvr fr-fvl');if(val=='left'){$current_audio.addClass('fr-fvl');}
else if(val=='right'){$current_audio.addClass('fr-fvr');}
_repositionResizer();_showEditPopup();}
function refreshAlign($btn){if(!$current_audio)return false;if($current_audio.hasClass('fr-fvl')){$btn.find('> *:first').replaceWith(editor.icon.create('align-left'));}
else if($current_audio.hasClass('fr-fvr')){$btn.find('> *:first').replaceWith(editor.icon.create('align-right'));}
else{$btn.find('> *:first').replaceWith(editor.icon.create('align-justify'));}}
function refreshAlignOnShow($btn,$dropdown){var alignment='justify';if($current_audio.hasClass('fr-fvl')){alignment='left';}
else if($current_audio.hasClass('fr-fvr')){alignment='right';}
$dropdown.find('.fr-command[data-param1="'+alignment+'"]').addClass('fr-active');}
function display(val){$current_audio.removeClass('fr-dvi fr-dvb');if(val=='inline'){$current_audio.addClass('fr-dvi');}
else if(val=='block'){$current_audio.addClass('fr-dvb');}
_repositionResizer();_showEditPopup();}
function refreshDisplayOnShow($btn,$dropdown){var d='block';if($current_audio.hasClass('fr-dvi')){d='inline';}
$dropdown.find('.fr-command[data-param1="'+d+'"]').addClass('fr-active');}
function remove(){if($current_audio){if(editor.events.trigger('audio.beforeRemove',[$current_audio])!==false){var $audio=$current_audio;editor.popups.hideAll();_exitEdit(true);editor.selection.setBefore($audio.get(0))||editor.selection.setAfter($audio.get(0));$audio.remove();editor.selection.restore();editor.html.fillEmptyBlocks();editor.events.trigger('audio.removed',[$audio]);}}}
function _convertStyleToClasses($audio){if(!$audio.hasClass('fr-dvi')&&!$audio.hasClass('fr-dvb')){var flt=$audio.css('float');$audio.css('float','none');if($audio.css('display')=='block'){$audio.css('float',flt);if(parseInt($audio.css('margin-left'),10)===0&&($audio.attr('style')||'').indexOf('margin-right: auto')>=0){$audio.addClass('fr-fvl');}
else if(parseInt($audio.css('margin-right'),10)===0&&($audio.attr('style')||'').indexOf('margin-left: auto')>=0){$audio.addClass('fr-fvr');}
$audio.addClass('fr-dvb');}
else{$audio.css('float',flt);if($audio.css('float')=='left'){$audio.addClass('fr-fvl');}
else if($audio.css('float')=='right'){$audio.addClass('fr-fvr');}
$audio.addClass('fr-dvi');}
$audio.css('margin','');$audio.css('float','');$audio.css('display','');$audio.css('z-index','');$audio.css('position','');$audio.css('overflow','');$audio.css('vertical-align','');}
if(!editor.opts.audioTextNear){$audio.removeClass('fr-dvi').addClass('fr-dvb');}}
function _refreshAudioList(){editor.$el.find('audio').filter(function(){return $(this).parents('span.fr-video').length===0;}).wrap('<span class="fr-video" contenteditable="false"></span>');editor.$el.find('embed, iframe').filter(function(){if(editor.browser.safari&&this.getAttribute('src')){this.setAttribute('src',this.src);}
if($(this).parents('span.fr-video').length>0)return false;var link=$(this).attr('src');for(var i=0;i<$.FE.VIDEO_PROVIDERS.length;i++){var vp=$.FE.VIDEO_PROVIDERS[i];if(vp.test_regex.test(link)){return true;}}
return false;}).map(function(){return $(this).parents('object').length===0?this:$(this).parents('object').get(0);}).wrap('<span class="fr-video" contenteditable="false"></span>');var audios=editor.$el.find('span.fr-video');for(var i=0;i<audios.length;i++){_convertStyleToClasses($(audios[i]));}
audios.toggleClass('fr-draggable',editor.opts.audioMove);}
function _init(){_initEvents();if(editor.helpers.isMobile()){editor.events.$on(editor.$el,'touchstart','span.fr-video',function(){touchScroll=false;})
editor.events.$on(editor.$el,'touchmove',function(){touchScroll=true;});}
editor.events.on('html.set',_refreshAudioList);_refreshAudioList();editor.events.$on(editor.$el,'mousedown','span.fr-video',function(e){e.stopPropagation();})
editor.events.$on(editor.$el,'click touchend','span.fr-video',_edit);editor.events.on('keydown',function(e){var key_code=e.which;if($current_audio&&(key_code==$.FE.KEYCODE.BACKSPACE||key_code==$.FE.KEYCODE.DELETE)){e.preventDefault();remove();return false;}
if($current_audio&&key_code==$.FE.KEYCODE.ESC){_exitEdit(true);e.preventDefault();return false;}
if($current_audio&&!editor.keys.ctrlKey(e)){e.preventDefault();return false;}},true);editor.events.on('keydown',function(){editor.$el.find('span.fr-video:empty').remove();})
_initInsertPopup(true);_initSizePopup(true);}
function back(){if($current_audio){$current_audio.trigger('click');}
else{editor.events.disableBlur();editor.selection.restore();editor.events.enableBlur();editor.popups.hide('audio.insert');editor.toolbar.showInline();}}
function setSize(width,height){if($current_audio){var $popup=editor.popups.get('audio.size');var $audio_obj=$current_audio.find('iframe, embed, audio');$audio_obj.css('width',width||$popup.find('input[name="width"]').val());$audio_obj.css('height',height||$popup.find('input[name="height"]').val());if($audio_obj.get(0).style.width)$audio_obj.removeAttr('width');if($audio_obj.get(0).style.height)$audio_obj.removeAttr('height');$popup.find('input').blur();setTimeout(function(){$current_audio.trigger('click');},editor.helpers.isAndroid()?50:0);}}
function get(){return $current_audio;}
return{_init:_init,showInsertPopup:showInsertPopup,showLayer:showLayer,refreshByURLButton:refreshByURLButton,refreshEmbedButton:refreshEmbedButton,insertByURL:insertByURL,insertEmbed:insertEmbed,insert:insert,align:align,refreshAlign:refreshAlign,refreshAlignOnShow:refreshAlignOnShow,display:display,refreshDisplayOnShow:refreshDisplayOnShow,remove:remove,showSizePopup:showSizePopup,back:back,setSize:setSize,get:get}}
$.FE.RegisterCommand('insertAudio',{title:'Insert Audio',undo:false,focus:true,refreshAfterCallback:false,popup:true,callback:function(){if(!this.popups.isVisible('audio.insert')){this.audio.showInsertPopup();}
else{if(this.$el.find('.fr-marker')){this.events.disableBlur();this.selection.restore();}
this.popups.hide('audio.insert');}},plugin:'audio'})
$.FE.DefineIcon('insertAudio',{NAME:'volume-up'});$.FE.DefineIcon('audioByURL',{NAME:'link'});$.FE.RegisterCommand('audioByURL',{title:'By URL',undo:false,focus:false,callback:function(){this.audio.showLayer('audio-by-url');},refresh:function($btn){this.audio.refreshByURLButton($btn);}})
$.FE.DefineIcon('audioEmbed',{NAME:'code'});$.FE.RegisterCommand('audioEmbed',{title:'Embedded Code',undo:false,focus:false,callback:function(){this.audio.showLayer('audio-embed');},refresh:function($btn){this.audio.refreshEmbedButton($btn);}})
$.FE.RegisterCommand('audioInsertByURL',{undo:true,focus:true,callback:function(){this.audio.insertByURL();}})
$.FE.RegisterCommand('audioInsertEmbed',{undo:true,focus:true,callback:function(){this.audio.insertEmbed();}})
$.FE.DefineIcon('audioDisplay',{NAME:'star'})
$.FE.RegisterCommand('audioDisplay',{title:'Display',type:'dropdown',options:{inline:'Inline',block:'Break Text'},callback:function(cmd,val){this.audio.display(val);},refresh:function($btn){if(!this.opts.audioTextNear)$btn.addClass('fr-hidden');},refreshOnShow:function($btn,$dropdown){this.audio.refreshDisplayOnShow($btn,$dropdown);}})
$.FE.DefineIcon('audioAlign',{NAME:'align-center'})
$.FE.RegisterCommand('audioAlign',{type:'dropdown',title:'Align',options:{left:'Align Left',justify:'None',right:'Align Right'},html:function(){var c='<ul class="fr-dropdown-list">';var options=$.FE.COMMANDS.audioAlign.options;for(var val in options){if(options.hasOwnProperty(val)){c+='<li><a class="fr-command fr-title" data-cmd="audioAlign" data-param1="'+val+'" title="'+this.language.translate(options[val])+'">'+this.icon.create('align-'+val)+'</a></li>';}}
c+='</ul>';return c;},callback:function(cmd,val){this.audio.align(val);},refresh:function($btn){this.audio.refreshAlign($btn);},refreshOnShow:function($btn,$dropdown){this.audio.refreshAlignOnShow($btn,$dropdown);}})
$.FE.DefineIcon('audioRemove',{NAME:'trash'})
$.FE.RegisterCommand('audioRemove',{title:'Remove',callback:function(){this.audio.remove();}})
$.FE.DefineIcon('audioSize',{NAME:'arrows-alt'})
$.FE.RegisterCommand('audioSize',{undo:false,focus:false,title:'Change Size',callback:function(){this.audio.showSizePopup();}});$.FE.DefineIcon('audioBack',{NAME:'arrow-left'});$.FE.RegisterCommand('audioBack',{title:'Back',undo:false,focus:false,back:true,callback:function(){this.audio.back();},refresh:function($btn){var $current_audio=this.audio.get();if(!$current_audio&&!this.opts.toolbarInline){$btn.addClass('fr-hidden');$btn.next('.fr-separator').addClass('fr-hidden');}
2017-02-08 08:10:24 +00:00
else{$btn.removeClass('fr-hidden');$btn.next('.fr-separator').removeClass('fr-hidden');}}});$.FE.RegisterCommand('audioSetSize',{undo:true,focus:false,callback:function(){this.audio.setSize();}})}));!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){a.FE.PLUGINS.quote=function(b){function c(a){for(;a.parentNode&&a.parentNode!=b.el;)a=a.parentNode;return a}function d(){var d,e=b.selection.blocks();for(d=0;d<e.length;d++)e[d]=c(e[d]);b.selection.save();var f=a("<blockquote>");for(f.insertBefore(e[0]),d=0;d<e.length;d++)f.append(e[d]);b.html.unwrap(),b.selection.restore()}function e(){var c,d=b.selection.blocks();for(c=0;c<d.length;c++)"BLOCKQUOTE"!=d[c].tagName&&(d[c]=a(d[c]).parentsUntil(b.$el,"BLOCKQUOTE").get(0));for(b.selection.save(),c=0;c<d.length;c++)d[c]&&a(d[c]).replaceWith(d[c].innerHTML);b.html.unwrap(),b.selection.restore()}function f(a){b.selection.save(),b.html.wrap(!0,!0,!0,!0),b.selection.restore(),"increase"==a?d():"decrease"==a&&e()}return{apply:f}},a.FE.RegisterShortcut(a.FE.KEYCODE.SINGLE_QUOTE,"quote","increase","'"),a.FE.RegisterShortcut(a.FE.KEYCODE.SINGLE_QUOTE,"quote","decrease","'",!0),a.FE.RegisterCommand("quote",{title:"Quote",type:"dropdown",options:{increase:"Increase",decrease:"Decrease"},callback:function(a,b){this.quote.apply(b)},plugin:"quote"}),a.FE.DefineIcon("quote",{NAME:"quote-left"})});!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){a.extend(a.FE.DEFAULTS,{fontSize:["8","9","10","11","12","14","18","24","30","36","48","60","72","96"],fontSizeSelection:!1,fontSizeDefaultSelection:"12"}),a.FE.PLUGINS.fontSize=function(b){function c(a){b.format.applyStyle("font-size",a)}function d(c,d){var e=a(b.selection.element()).css("font-size");d.find(".fr-command.fr-active").removeClass("fr-active").attr("aria-selected",!1),d.find('.fr-command[data-param1="'+e+'"]').addClass("fr-active").attr("aria-selected",!0);var f=d.find(".fr-dropdown-list"),g=d.find(".fr-active").parent();g.length?f.parent().scrollTop(g.offset().top-f.offset().top-(f.parent().outerHeight()/2-g.outerHeight()/2)):f.parent().scrollTop(0)}function e(c){if(b.opts.fontSizeSelection){var d=b.helpers.getPX(a(b.selection.element()).css("font-size"));c.find("> span").text(d)}}return{apply:c,refreshOnShow:d,refresh:e}},a.FE.RegisterCommand("fontSize",{type:"dropdown",title:"Font Size",displaySelection:function(a){return a.opts.fontSizeSelection},displaySelectionWidth:30,defaultSelection:function(a){return a.opts.fontSizeDefaultSelection},html:function(){for(var a='<ul class="fr-dropdown-list" role="presentation">',b=this.opts.fontSize,c=0;c<b.length;c++){var d=b[c];a+='<li role="presentation"><a class="fr-command" tabIndex="-1" role="option" data-cmd="fontSize" data-param1="'+d+'px" title="'+d+'">'+d+"</a></li>"}return a+="</ul>"},callback:function(a,b){this.fontSize.apply(b)},refresh:function(a){this.fontSize.refresh(a)},refreshOnShow:function(a,b){this.fontSize.refreshOnShow(a,b)},plugin:"fontSize"}),a.FE.DefineIcon("fontSize",{NAME:"text-height"})});!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){a.extend(a.FE.DEFAULTS,{fontFamily:{"Arial,Helvetica,sans-serif":"Arial","Georgia,serif":"Georgia","Impact,Charcoal,sans-serif":"Impact","Tahoma,Geneva,sans-serif":"Tahoma","Times New Roman,Times,serif":"Times New Roman","Verdana,Geneva,sans-serif":"Verdana"},fontFamilySelection:!1,fontFamilyDefaultSelection:"Font Family"}),a.FE.PLUGINS.fontFamily=function(b){function c(a){b.format.applyStyle("font-family",a)}functio
return}
if(items.length>1){$.oc.alert($.oc.lang.get('mediamanager.invalid_file_single_insert'))
return}
var link,text=editor.selection.text(),textIsEmpty=$.trim(text)===''
for(var i=0,len=items.length;i<len;i++){var text=textIsEmpty?items[i].title:text
link=items[i].publicUrl}
editor.events.focus(true);editor.selection.restore();editor.html.insert('<a href="'+link+'" id="fr-inserted-file" class="fr-file">'+text+'</a>');var $file=editor.$el.find('#fr-inserted-file');$file.removeAttr('id');editor.undo.saveStep()
this.hide()}})}
function onInsertImage(){var $currentImage=editor.image.get()
new $.oc.mediaManager.popup({alias:'ocmediamanager',cropAndInsertButton:true,onInsert:function(items){if(!items.length){$.oc.alert($.oc.lang.get('mediamanager.invalid_image_empty_insert'))
return}
var imagesInserted=0
for(var i=0,len=items.length;i<len;i++){if(items[i].documentType!=='image'){$.oc.alert($.oc.lang.get('mediamanager.invalid_image_invalid_insert','The file "'+items[i].title+'" is not an image.'))
continue}
editor.image.insert(items[i].publicUrl,false,{},$currentImage)
imagesInserted++
if(imagesInserted==1){$currentImage=null}}
if(imagesInserted!==0){this.hide()
editor.undo.saveStep()}}})}
function onInsertVideo(){new $.oc.mediaManager.popup({alias:'ocmediamanager',cropAndInsertButton:false,onInsert:function(items){if(!items.length){$.oc.alert($.oc.lang.get('mediamanager.invalid_video_empty_insert'))
return}
if(items.length>1){$.oc.alert($.oc.lang.get('mediamanager.invalid_file_single_insert'))
return}
var item=items[0]
if(item.documentType!=='video'){$.oc.alert($.oc.lang.get('mediamanager.invalid_video_invalid_insert','The file "'+item.title+'" is not a video.'))
return}
var $richEditorNode=editor.$el.closest('[data-control="richeditor"]')
$richEditorNode.richEditor('insertVideo',item.publicUrl,item.title)
this.hide()}})}
function onInsertAudio(){new $.oc.mediaManager.popup({alias:'ocmediamanager',cropAndInsertButton:false,onInsert:function(items){if(!items.length){$.oc.alert($.oc.lang.get('mediamanager.invalid_audio_empty_insert'))
return}
if(items.length>1){$.oc.alert($.oc.lang.get('mediamanager.invalid_file_single_insert'))
return}
var item=items[0]
if(item.documentType!=='audio'){$.oc.alert($.oc.lang.get('mediamanager.invalid_audio_invalid_insert','The file "'+item.title+'" is not an audio file.'))
return}
var $richEditorNode=editor.$el.closest('[data-control="richeditor"]')
$richEditorNode.richEditor('insertAudio',item.publicUrl,item.title)
this.hide()}})}
function _insertVideoFallback(link){var $richEditorNode=editor.$el.closest('[data-control="richeditor"]')
var title=link.substring(link.lastIndexOf('/')+1)
$richEditorNode.richEditor('insertVideo',link,title)
editor.popups.hide('video.insert')}
function _insertAudioFallback(link){var $richEditorNode=editor.$el.closest('[data-control="richeditor"]')
var title=link.substring(link.lastIndexOf('/')+1)
$richEditorNode.richEditor('insertAudio',link,title)
editor.popups.hide('audio.insert')}
function _init(){editor.events.on('destroy',_destroy,true)
editor.events.on('video.linkError',_insertVideoFallback)
editor.events.on('audio.linkError',_insertAudioFallback)}
function _destroy(){}
return{_init:_init,insertFile:onInsertFile,insertImage:onInsertImage,insertVideo:onInsertVideo,insertAudio:onInsertAudio}}
if(!$.FE.PLUGINS.link||!$.FE.PLUGINS.file||!$.FE.PLUGINS.image||!$.FE.PLUGINS.video){throw new Error('Media manager plugin requires link, file, image and video plugin.');}
$.FE.DEFAULTS.imageInsertButtons.push('mmImageManager');$.FE.RegisterCommand('mmImageManager',{title:'Browse',undo:false,focus:false,callback:function(){this.mediaManager.insertImage();},plugin:'mediaManager'})
$.FE.DefineIcon('mmImageManager',{NAME:'folder'});$.FE.DEFAULTS.fileInsertButtons.push('mmFileManager');$.FE.RegisterCommand('mmFileManager',{title:'Browse',undo:false,focus:false,callback:function(){this.mediaManager.insertFile();},plugin:'mediaManager'})
$.FE.DefineIcon('mmFileManager',{NAME:'folder'});$.FE.DEFAULTS.videoInsertButtons.push('mmVideoManager');$.FE.RegisterCommand('mmVideoManager',{title:'Browse',undo:false,focus:false,callback:function(){this.mediaManager.insertVideo();},plugin:'mediaManager'})
$.FE.DefineIcon('mmVideoManager',{NAME:'folder'});$.FE.DEFAULTS.audioInsertButtons.push('mmAudioManager');$.FE.RegisterCommand('mmAudioManager',{title:'Browse',undo:false,focus:false,callback:function(){this.mediaManager.insertAudio();},plugin:'mediaManager'})
$.FE.DefineIcon('mmAudioManager',{NAME:'folder'});})(jQuery);var richeditorPageLinksPlugin
function richeditorPageLinksSelectPage($form){richeditorPageLinksPlugin.setLinkValueFromPopup($form)}
$.FroalaEditor.DEFAULTS=$.extend($.FroalaEditor.DEFAULTS,{pageLinksHandler:'onLoadPageLinksForm'});$.FroalaEditor.DEFAULTS.key='HHMDUGENKACTMXQL==';(function($){$.FroalaEditor.PLUGINS.pageLinks=function(editor){function setLinkValueFromPopup($form){var $select=$('select[name=pagelink]',$form)
var link={text:$('option:selected',$select).text().trim(),href:$select.val()}
setTimeout(function(){editor.popups.show('link.insert')
setLinkValue(link)},300)}
function setLinkValue(link){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 insertLink(){richeditorPageLinksPlugin=this
editor.$el.popup({handler:editor.opts.pageLinksHandler})}
function _init(){}
return{_init:_init,setLinkValueFromPopup:setLinkValueFromPopup,setLinkValue:setLinkValue,insertLink:insertLink}}
$.FE.DEFAULTS.linkInsertButtons=['linkBack','|','linkPageLinks']
$.FE.RegisterCommand('linkPageLinks',{title:'Choose Link',undo:false,focus:false,callback:function(){this.pageLinks.insertLink()},plugin:'pageLinks'})
$.FE.DefineIcon('linkPageLinks',{NAME:'search'});})(jQuery);(function($){$.FroalaEditor.PLUGINS.figures=function(editor){function insertElement($el){var html=$('<div />').append($el.clone()).remove().html()
editor.events.focus(true)
editor.selection.restore()
editor.html.insert(html)
editor.html.cleanEmptyTags()
$('figure',editor.$el).each(function(){var $this=$(this),$parent=$this.parent('p'),$next=$this.next('p')
if(!!$parent.length){$this.insertAfter($parent)}
if(!!$next.length&&$.trim($next.text()).length==0){$next.remove()}})
editor.undo.saveStep()}
function _makeUiBlockElement(){var $node=$('<figure contenteditable="false" tabindex="0" data-ui-block="true">&nbsp;</figure>')
$node.get(0).contentEditable=false
return $node}
function insertVideo(url,text){var $node=_makeUiBlockElement()
$node.attr('data-video',url)
$node.attr('data-label',text)
insertElement($node)}
function insertAudio(url,text){var $node=_makeUiBlockElement()
$node.attr('data-audio',url)
$node.attr('data-label',text)
insertElement($node)}
function _initUiBlocks(){$('[data-video], [data-audio]',editor.$el).each(function(){$(this).addClass('fr-draggable').attr({'data-ui-block':'true','draggable':'true','tabindex':'0'}).html('&nbsp;')
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 draggable').removeClass('fr-draggable fr-dragging')})
return $domTree.html()}
function _init(){editor.events.on('initialized',_initUiBlocks)
editor.events.on('html.set',_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:insertElement,insertVideo:insertVideo,insertAudio:insertAudio}}})(jQuery);+function($){"use strict";var Base=$.oc.foundation.base,BaseProto=Base.prototype
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')
this.editor=null
$.oc.foundation.controlUtils.markDisposable(element)
Base.call(this)
this.init()}
RichEditor.prototype=Object.create(BaseProto)
RichEditor.prototype.constructor=RichEditor
RichEditor.DEFAULTS={linksHandler:null,stylesheet:null,fullpage:false,editorLang:'en',toolbarButtons:null,allowEmptyTags:null,allowTags:null,noWrapTags:null,removeTags:null,imageStyles:null,linkStyles:null,paragraphStyles:null,tableStyles:null,tableCellStyles:null,aceVendorPath:'/'}
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))}
this.initFroala()}
2017-02-08 08:10:24 +00:00
RichEditor.prototype.initFroala=function(){var froalaOptions={editorClass:'control-richeditor',language:this.options.editorLang,fullPage:this.options.fullpage,pageLinksHandler:this.options.linksHandler,aceEditorVendorPath:this.options.aceVendorPath,toolbarSticky:false}
if(this.options.toolbarButtons){froalaOptions.toolbarButtons=this.options.toolbarButtons.split(',')}
else{froalaOptions.toolbarButtons=$.oc.richEditorButtons}
froalaOptions.imageStyles=this.options.imageStyles?this.options.imageStyles:{'oc-img-rounded':'Rounded','oc-img-bordered':'Bordered'}
froalaOptions.linkStyles=this.options.linkStyles?this.options.linkStyles:{'oc-link-green':'Green','oc-link-strong':'Thick'}
froalaOptions.paragraphStyles=this.options.paragraphStyles?this.options.paragraphStyles:{'oc-text-gray':'Gray','oc-text-bordered':'Bordered','oc-text-spaced':'Spaced','oc-text-uppercase':'Uppercase'}
froalaOptions.tableStyles=this.options.tableStyles?this.options.tableStyles:{'oc-dashed-borders':'Dashed Borders','oc-alternate-rows':'Alternate Rows'}
froalaOptions.tableCellStyles=this.options.tableCellStyles?this.options.tableCellStyles:{'oc-cell-highlighted':'Highlighted','oc-cell-thick-border':'Thick'}
froalaOptions.toolbarButtonsMD=froalaOptions.toolbarButtons
froalaOptions.toolbarButtonsSM=froalaOptions.toolbarButtons
froalaOptions.toolbarButtonsXS=froalaOptions.toolbarButtons
if(this.options.htmlAllowedEmptyTags){froalaOptions.allowEmptyTags=this.options.htmlAllowedEmptyTags.split(/[\s,]+/)}
if(this.options.allowTags){froalaOptions.htmlAllowedTags=this.options.allowTags.split(/[\s,]+/)}
froalaOptions.htmlDoNotWrapTags=this.options.noWrapTags?this.options.noWrapTags.split(/[\s,]+/):['figure','script','style']
if(this.options.removeTags){froalaOptions.htmlRemoveTags=this.options.removeTags.split(/[\s,]+/)}
froalaOptions.lineBreakerTags=['figure','table','hr','iframe','form','dl']
froalaOptions.shortcutsEnabled=['show','bold','italic','underline','indent','outdent','undo','redo']
froalaOptions.imageUploadURL=froalaOptions.fileUploadURL=window.location
froalaOptions.imageUploadParam=froalaOptions.fileUploadParam='file_data'
froalaOptions.imageUploadParams=froalaOptions.fileUploadParams={X_OCTOBER_MEDIA_MANAGER_QUICK_UPLOAD:1}
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))
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.$form.on('oc.beforeRequest',this.proxy(this.onFormBeforeRequest))
this.$textarea.froalaEditor(froalaOptions)
this.editor=this.$textarea.data('froala.editor')
this.$el.on('keydown','.fr-view figure',this.proxy(this.onFigureKeydown))}
RichEditor.prototype.dispose=function(){this.unregisterHandlers()
this.$textarea.froalaEditor('destroy')
this.$el.removeData('oc.richEditor')
this.options=null
this.$el=null
this.$textarea=null
this.$form=null
this.editor=null
BaseProto.dispose.call(this)}
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))
this.$form.off('oc.beforeRequest',this.proxy(this.onFormBeforeRequest))
$(window).off('resize',this.proxy(this.updateLayout))
$(window).off('oc.updateUi',this.proxy(this.updateLayout))
this.$el.off('dispose-control',this.proxy(this.dispose))}
RichEditor.prototype.build=function(event,editor){this.updateLayout()
$(window).on('resize',this.proxy(this.updateLayout))
$(window).on('oc.updateUi',this.proxy(this.updateLayout))
this.$textarea.trigger('init.oc.richeditor',[this])}
RichEditor.prototype.isCodeViewActive=function(){return this.editor&&this.editor.codeView&&this.editor.codeView.isActive()}
RichEditor.prototype.getElement=function(){return this.$el}
RichEditor.prototype.getEditor=function(){return this.editor}
RichEditor.prototype.getTextarea=function(){return this.$textarea}
2016-07-05 09:58:51 +00:00
RichEditor.prototype.getContent=function(){return this.editor.html.get()}
RichEditor.prototype.setContent=function(html){this.editor.html.set(html)}
RichEditor.prototype.syncContent=function(){this.editor.events.trigger('contentChanged')}
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)
if(!$editor.length){return}
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)
$codeEditor.css('top',height)}
else{$editor.css('top','')
$codeEditor.css('top','')}}
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.insertVideo=function(url,title){this.$textarea.froalaEditor('figures.insertVideo',url,title)}
RichEditor.prototype.insertAudio=function(url,title){this.$textarea.froalaEditor('figures.insertAudio',url,title)}
RichEditor.prototype.onSetContent=function(ev,editor){this.$textarea.trigger('setContent.oc.richeditor',[this])}
2016-07-05 09:58:51 +00:00
RichEditor.prototype.onSyncContent=function(ev,editor,html){if(editor.codeBeautifier){html=editor.codeBeautifier.run(html,editor.opts.codeBeautifierOptions)}
var container={html:html}
this.$textarea.trigger('syncContent.oc.richeditor',[this,container])
return container.html}
RichEditor.prototype.onFocus=function(){this.$el.addClass('editor-focus')}
RichEditor.prototype.onBlur=function(){this.$el.removeClass('editor-focus')}
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])
if(ev.isDefaultPrevented()){return false}}
RichEditor.prototype.onChange=function(ev){this.$form.trigger('change')}
RichEditor.prototype.onFormBeforeRequest=function(ev){if(!this.editor){return}
if(this.isCodeViewActive()){this.editor.html.set(this.editor.codeView.get())}
this.$textarea.val(this.editor.html.get())}
2015-02-14 05:40:50 +00:00
var old=$.fn.richEditor
$.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)))
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}
$(document).render(function(){$('[data-control="richeditor"]').richEditor()})
if($.oc===undefined)
$.oc={}
$.oc.richEditorButtons=['paragraphFormat','paragraphStyle','quote','bold','italic','align','formatOL','formatUL','insertTable','insertLink','insertImage','insertVideo','insertAudio','insertFile','insertHR','fullscreen','html']}(window.jQuery);