2016-05-21 19:21:19 +00:00
! function ( a ) { "function" == typeof define && define . amd ? define ( [ "jquery" ] , a ) : "object" == typeof module && module . exports ? module . exports = function ( b , c ) { return void 0 === c && ( c = "undefined" != typeof window ? require ( "jquery" ) : require ( "jquery" ) ( b ) ) , a ( c ) , c } : a ( jQuery ) } ( function ( a ) { "use strict" ; var b = function ( c , d ) { this . id = ++ a . FE . ID , this . opts = a . extend ( ! 0 , { } , a . extend ( { } , b . DEFAULTS , "object" == typeof d && d ) ) ; var e = JSON . stringify ( this . opts ) ; a . FE . OPTS _MAPPING [ e ] = a . FE . OPTS _MAPPING [ e ] || this . id , this . sid = a . FE . OPTS _MAPPING [ e ] , a . FE . SHARED [ this . sid ] = a . FE . SHARED [ this . sid ] || { } , this . shared = a . FE . SHARED [ this . sid ] , this . shared . count = ( this . shared . count || 0 ) + 1 , this . $oel = a ( c ) , this . $oel . data ( "froala.editor" , this ) , this . o _doc = c . ownerDocument , this . o _win = "defaultView" in this . o _doc ? this . o _doc . defaultView : this . o _doc . parentWindow ; var f = a ( this . o _win ) . scrollTop ( ) ; this . $oel . on ( "froala.doInit" , a . proxy ( function ( ) { this . $oel . off ( "froala.doInit" ) , this . doc = this . $el . get ( 0 ) . ownerDocument , this . win = "defaultView" in this . doc ? this . doc . defaultView : this . doc . parentWindow , this . $doc = a ( this . doc ) , this . $win = a ( this . win ) , this . opts . pluginsEnabled || ( this . opts . pluginsEnabled = Object . keys ( a . FE . PLUGINS ) ) , this . opts . initOnClick ? ( this . load ( a . FE . MODULES ) , this . $el . on ( "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 || 0 === 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 . events . trigger ( "initialized" ) } } , this ) ) ) : ( this . load ( a . FE . MODULES ) , this . load ( a . FE . PLUGINS ) , a ( this . o _win ) . scrollTop ( f ) , "undefined" == typeof this . ul && this . destroy ( ) , this . events . trigger ( "initialized" ) ) } , this ) ) , this . _init ( ) } ; b . DEFAULTS = { initOnClick : ! 1 , pluginsEnabled : null } , b . MODULES = { } , b . PLUGINS = { } , b . VERSION = "2.3.0" , b . INSTANCES = [ ] , b . OPTS _MAPPING = { } , b . SHARED = { } , b . ID = 0 , b . prototype . _init = function ( ) { var b = this . $oel . prop ( "tagName" ) , c = a . proxy ( function ( ) { this . _original _html = this . _original _html || this . $oel . html ( ) , this . $box = this . $box || this . $oel , this . opts . fullPage && ( this . opts . iframe = ! 0 ) , this . opts . iframe ? ( this . $iframe = a ( '<iframe src="about:blank" frameBorder="0">' ) , this . $wp = a ( "<div></div>" ) , this . $box . html ( this . $wp ) , this . $wp . append ( this . $iframe ) , this . $iframe . get ( 0 ) . contentWindow . document . open ( ) , this . $iframe . get ( 0 ) . contentWindow . document . write ( "<!DOCTYPE html>" ) , this . $iframe . get ( 0 ) . contentWindow . document . write ( "<html><head></head><body></body></html>" ) , this . $iframe . get ( 0 ) . contentWindow . document . close ( ) , this . $el = this . $iframe . contents ( ) . find ( "body" ) , this . $head = this . $iframe . contents ( ) . find ( "head" ) , this . $html = this . $iframe . contents ( ) . find ( "html" ) , this . iframe _document = this . $iframe . get ( 0 ) . contentWindow . document , this . $oel . trigger ( "froala.doInit" ) ) : ( this . $el = a ( "<div></div>" ) , this . $wp = a ( "<div></div>" ) . append ( this . $el ) , this . $box . html ( this . $wp ) , this . $oel . trigger ( "froala.doInit" ) ) } , this ) , d = a . proxy ( function ( ) { this . $box = a ( "<div>" ) , this . $oel . before ( this . $box ) . hide ( ) , this . _original _html = this . $oel . val ( ) , this . $oel . parents ( "form" ) . on ( "submit." + this . id , a . proxy ( function ( ) { this . events . trigger ( "form.submit" ) } , this ) ) , this . $oel . parents ( "form" ) . on ( "reset." + this . id , a . proxy ( function ( ) { this . events . trigger ( "form.reset" ) } , this ) ) , c ( ) } , this ) , e = a . proxy ( function ( ) { this . $el = this . $oel , this . $el . attr ( "contenteditable" , ! 0 ) . css ( "outline" , "none" ) . css ( "display" , "inline-block" ) , this . opts . multiLine = ! 1 , this . opts . toolbarInline = ! 1 , this . $oel . trigger ( "froala.doInit" ) } , this ) , f = a . proxy ( function ( ) { this . $el = this . $oel , this . opts . toolbarInline = ! 1 , this . $oel . trigger ( "froala.doInit" ) } , this ) , g = a . proxy ( function ( ) { this . $el = this . $oel , this . opts . tool
2016-05-19 18:35:40 +00:00
else { jQuery = require ( 'jquery' ) ( root ) ; } }
factory ( jQuery ) ; return jQuery ; } ; } else { factory ( jQuery ) ; } } ( function ( $ ) { 'use strict' ; $ . FE . PLUGINS . fullscreen = function ( editor ) { var old _scroll ; function isActive ( ) { return editor . $box . hasClass ( 'fr-fullscreen' ) ; }
var $placeholder ; var height ; var max _height ; function _on ( ) { old _scroll = $ ( editor . o _win ) . scrollTop ( ) ; editor . $box . toggleClass ( 'fr-fullscreen' ) ; $ ( 'body' ) . toggleClass ( 'fr-fullscreen' ) ; $placeholder = $ ( '<div style="display: none;"></div>' ) ; editor . $box . after ( $placeholder ) ; if ( editor . helpers . isMobile ( ) ) { editor . $tb . data ( 'parent' , editor . $tb . parent ( ) ) ; editor . $tb . prependTo ( editor . $box ) ; if ( editor . $tb . data ( 'sticky-dummy' ) ) { editor . $tb . after ( editor . $tb . data ( 'sticky-dummy' ) ) ; } }
height = editor . opts . height ; max _height = editor . opts . heightMax ; editor . opts . height = editor . o _win . innerHeight - ( editor . opts . toolbarInline ? 0 : editor . $tb . outerHeight ( ) ) ; editor . size . refresh ( ) ; if ( editor . opts . toolbarInline ) editor . toolbar . showInline ( ) ; editor . events . trigger ( 'charCounter.update' ) ; editor . $win . trigger ( 'scroll' ) ; }
function _off ( ) { editor . $box . toggleClass ( 'fr-fullscreen' ) ; $ ( 'body' ) . toggleClass ( 'fr-fullscreen' ) ; editor . $tb . prependTo ( editor . $tb . data ( 'parent' ) ) ; if ( editor . $tb . data ( 'sticky-dummy' ) ) { editor . $tb . after ( editor . $tb . data ( 'sticky-dummy' ) ) ; }
editor . opts . height = height ; editor . opts . heightMax = max _height ; editor . size . refresh ( ) ; $ ( editor . o _win ) . scrollTop ( old _scroll )
if ( editor . opts . toolbarInline ) editor . toolbar . showInline ( ) ; editor . events . trigger ( 'charCounter.update' ) ; if ( editor . opts . toolbarSticky ) { if ( editor . opts . toolbarStickyOffset ) { if ( editor . opts . toolbarBottom ) { editor . $tb . css ( 'bottom' , editor . opts . toolbarStickyOffset ) . data ( 'bottom' , editor . opts . toolbarStickyOffset ) ; }
else { editor . $tb . css ( 'top' , editor . opts . toolbarStickyOffset ) . data ( 'top' , editor . opts . toolbarStickyOffset ) ; } } }
editor . $win . trigger ( 'scroll' ) ; }
function toggle ( ) { if ( ! isActive ( ) ) { _on ( ) ; }
else { _off ( ) ; }
refresh ( editor . $tb . find ( '.fr-command[data-cmd="fullscreen"]' ) ) ; $ ( window ) . trigger ( 'oc.updateUi' ) }
2016-05-21 21:24:04 +00:00
function refresh ( $btn ) { var active = isActive ( ) ; $btn . toggleClass ( 'fr-active' , active ) ; $btn . find ( '> *' ) . replaceWith ( ! active ? editor . icon . create ( 'fullscreen' ) : editor . icon . create ( 'fullscreenCompress' ) ) ; }
2016-05-19 18:35:40 +00:00
function _init ( ) { if ( ! editor . $wp ) return false ; editor . events . $on ( $ ( editor . o _win ) , 'resize' , function ( ) { if ( isActive ( ) ) { _off ( ) ; _on ( ) ; } } ) ; editor . events . on ( 'toolbar.hide' , function ( ) { if ( isActive ( ) && editor . helpers . isMobile ( ) ) return false ; } ) }
return { _init : _init , toggle : toggle , refresh : refresh , isActive : isActive } }
$ . FE . RegisterCommand ( 'fullscreen' , { title : 'Fullscreen' , undo : false , focus : false , forcedRefresh : true , callback : function ( ) { this . fullscreen . toggle ( ) ; } , refresh : function ( $btn ) { this . fullscreen . refresh ( $btn ) ; } , plugin : 'fullscreen' } )
2016-05-21 21:24:04 +00:00
$ . 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' ) ; }
2016-05-19 18:35:40 +00:00
else { jQuery = require ( 'jquery' ) ( root ) ; } }
factory ( jQuery ) ; return jQuery ; } ; } else { factory ( jQuery ) ; } } ( function ( $ ) { 'use strict' ; $ . extend ( $ . FE . DEFAULTS , { aceEditor : true , aceEditorOptions : { showLineNumbers : true , useSoftTabs : false , wrap : true , mode : 'ace/mode/html' , tabSize : 2 } , codeBeautifierOptions : { end _with _newline : true , indent _inner _html : true , extra _liners : [ 'p' , 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' , 'blockquote' , 'pre' , 'ul' , 'ol' , 'table' , 'dl' ] , brace _style : 'expand' , indent _char : '\t' , indent _size : 1 , wrap _line _length : 0 } } )
$ . FE . PLUGINS . codeView = function ( editor ) { var $html _area ; var ace _editor ; function isActive ( ) { return editor . $box . hasClass ( 'fr-code-view' ) ; }
function get ( ) { if ( ace _editor ) { return ace _editor . getValue ( ) ; } else { return $html _area . val ( ) ; } }
function _showText ( $btn ) { var html = get ( ) ; editor . html . set ( html ) ; editor . $el . blur ( ) ; editor . $tb . find ( ' > .fr-command' ) . not ( $btn ) . removeClass ( 'fr-disabled' ) ; $btn . removeClass ( 'fr-active' ) ; editor . events . focus ( true ) ; editor . placeholder . refresh ( ) ; editor . undo . saveStep ( ) ; }
2016-05-21 21:24:04 +00:00
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 _editor . setOptions ( editor . opts . aceEditorOptions ) ; }
editor . undo . saveStep ( ) ; editor . html . cleanEmptyTags ( ) ; editor . html . cleanWhiteTags ( true ) ; if ( editor . core . hasFocus ( ) ) { if ( ! editor . core . isEmpty ( ) ) { editor . selection . save ( ) ; editor . $el . find ( '.fr-marker[data-type="true"]:first' ) . replaceWith ( '<span class="fr-tmp fr-sm">F</span>' ) ; editor . $el . find ( '.fr-marker[data-type="false"]:last' ) . replaceWith ( '<span class="fr-tmp fr-em">F</span>' ) ; } }
var html = editor . html . get ( false , true ) ; editor . $el . find ( 'span.fr-tmp' ) . remove ( ) ; 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 ) ; }
2016-05-19 18:35:40 +00:00
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 ( ) ; }
2016-05-21 21:24:04 +00:00
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 || editor . opts . heightMax ) { $html _area . css ( 'max-height' , editor . opts . height || editor . opts . heightMax ) ; }
2016-05-19 18:35:40 +00:00
$html _area . val ( html . replace ( /FROALA-SM/g , '' ) . replace ( /FROALA-EM/g , '' ) ) ; $html _area . focus ( ) ; $html _area . get ( 0 ) . setSelectionRange ( s _index , e _index ) ; }
editor . $tb . find ( ' > .fr-command' ) . not ( $btn ) . addClass ( 'fr-disabled' ) ; $btn . addClass ( 'fr-active' ) ; if ( ! editor . helpers . isMobile ( ) && editor . opts . toolbarInline ) { editor . toolbar . hide ( ) ; } }
2016-05-21 21:24:04 +00:00
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 ( ) ; editor . $box . toggleClass ( 'fr-code-view' , true ) ; _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 ; } }
2016-05-19 18:35:40 +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 . opts . toolbarInline ) { $back _button = $ ( '<a data-cmd="html" title="Code View" class="fr-command fr-btn html-switch' + ( editor . helpers . isMobile ( ) ? '' : ' fr-desktop' ) + '" role="button" tabindex="-1"><i class="fa fa-code"></i></button>' ) ; editor . $box . append ( $back _button ) ; editor . events . bindClick ( editor . $box , 'a.html-switch' , function ( ) { toggle ( false ) ; } ) ; }
var cancel = function ( ) { return ! isActive ( ) ; }
editor . events . on ( 'buttons.refresh' , cancel ) ; editor . events . on ( 'copy' , cancel , true ) ; editor . events . on ( 'cut' , cancel , true ) ; editor . events . on ( 'paste' , cancel , true ) ; editor . events . on ( 'destroy' , _destroy , true ) ; editor . events . on ( 'html.set' , function ( ) { if ( isActive ( ) ) toggle ( true ) ; } ) ; editor . events . on ( 'form.submit' , function ( ) { if ( isActive ( ) ) { editor . html . set ( get ( ) ) ; editor . events . trigger ( 'contentChanged' , [ ] , true ) ; } } , true ) ; }
var $back _button ; function _init ( ) { if ( ! editor . $wp ) return false ; }
return { _init : _init , toggle : toggle , isActive : isActive , get : get } } ; $ . FE . RegisterCommand ( 'html' , { title : 'Code View' , undo : false , focus : false , forcedRefresh : true , callback : function ( ) { this . codeView . toggle ( ) ; } , plugin : 'codeView' } )
2016-05-21 19:21:19 +00:00
$ . FE . DefineIcon ( 'html' , { NAME : 'code' } ) ; } ) ) ; ! function ( a ) { "function" == typeof define && define . amd ? define ( [ "jquery" ] , a ) : "object" == typeof module && module . exports ? module . exports = function ( b , c ) { return void 0 === c && ( c = "undefined" != typeof window ? require ( "jquery" ) : require ( "jquery" ) ( b ) ) , a ( c ) , c } : a ( jQuery ) } ( function ( a ) { "use strict" ; a . extend ( a . FE . DEFAULTS , { paragraphFormat : { N : "Normal" , H1 : "Heading 1" , H2 : "Heading 2" , H3 : "Heading 3" , H4 : "Heading 4" , PRE : "Code" } , paragraphFormatSelection : ! 1 } ) , a . FE . PLUGINS . paragraphFormat = function ( b ) { function c ( c , d ) { var e = b . html . defaultTag ( ) ; if ( d && d . toLowerCase ( ) != e ) if ( c . find ( "ul, ol" ) . length > 0 ) { var f = a ( "<" + d + ">" ) ; c . prepend ( f ) ; for ( var g = b . node . contents ( c . get ( 0 ) ) [ 0 ] ; g && [ "UL" , "OL" ] . indexOf ( g . tagName ) < 0 ; ) { var h = g . nextSibling ; f . append ( g ) , g = h } } else c . html ( "<" + d + ">" + c . html ( ) + "</" + d + ">" ) } function d ( c , d ) { var e = b . html . defaultTag ( ) ; d || ( d = 'div class="fr-temp-div" data-empty="true"' ) , d . toLowerCase ( ) == e ? c . replaceWith ( c . html ( ) ) : c . replaceWith ( a ( "<" + d + ">" ) . html ( c . html ( ) ) ) } function e ( c , d ) { var e = b . html . defaultTag ( ) ; d || ( d = 'div class="fr-temp-div"' + ( b . node . isEmpty ( c . get ( 0 ) , ! 0 ) ? ' data-empty="true"' : "" ) ) , d . toLowerCase ( ) == e ? ( b . node . isEmpty ( c . get ( 0 ) , ! 0 ) || c . append ( "<br/>" ) , c . replaceWith ( c . html ( ) ) ) : c . replaceWith ( a ( "<" + d + ">" ) . html ( c . html ( ) ) ) } function f ( c , d ) { d || ( d = 'div class="fr-temp-div"' + ( b . node . isEmpty ( c . get ( 0 ) , ! 0 ) ? ' data-empty="true"' : "" ) ) , c . replaceWith ( a ( "<" + d + " " + b . node . attributes ( c . get ( 0 ) ) + ">" ) . html ( c . html ( ) ) ) } function g ( g ) { "N" == g && ( g = b . html . defaultTag ( ) ) , b . selection . save ( ) , b . html . wrap ( ! 0 , ! 0 , ! 0 , ! 0 ) , b . selection . restore ( ) ; var h = b . selection . blocks ( ) ; b . selection . save ( ) , b . $el . find ( "pre" ) . attr ( "skip" , ! 0 ) ; for ( var i = 0 ; i < h . length ; i ++ ) if ( h [ i ] . tagName != g && ! b . node . isList ( h [ i ] ) ) { var j = a ( h [ i ] ) ; "LI" == h [ i ] . tagName ? c ( j , g ) : "LI" == h [ i ] . parentNode . tagName && h [ i ] ? d ( j , g ) : [ "TD" , "TH" ] . indexOf ( h [ i ] . parentNode . tagName ) >= 0 ? e ( j , g ) : f ( j , g ) } b . $el . find ( 'pre:not([skip="true"]) + pre:not([skip="true"])' ) . each ( function ( ) { a ( this ) . prev ( ) . append ( "<br>" + a ( this ) . html ( ) ) , a ( this ) . remove ( ) } ) , b . $el . find ( "pre" ) . removeAttr ( "skip" ) , b . html . unwrap ( ) , b . selection . restore ( ) } function h ( a , c ) { var d = b . selection . blocks ( ) ; if ( d . length ) { var e = d [ 0 ] , f = "N" , g = b . html . defaultTag ( ) ; e . tagName . toLowerCase ( ) != g && e != b . $el . get ( 0 ) && ( f = e . tagName ) , c . find ( '.fr-command[data-param1="' + f + '"]' ) . addClass ( "fr-active" ) } else c . find ( '.fr-command[data-param1="N"]' ) . addClass ( "fr-active" ) } function i ( a ) { if ( b . opts . paragraphFormatSelection ) { var c = b . selection . blocks ( ) ; if ( c . length ) { var d = c [ 0 ] , e = "N" , f = b . html . defaultTag ( ) ; d . tagName . toLowerCase ( ) != f && d != b . $el . get ( 0 ) && ( e = d . tagName ) , [ "LI" , "TD" , "TH" ] . indexOf ( e ) >= 0 && ( e = "N" ) , a . find ( "> span" ) . text ( b . opts . paragraphFormat [ e ] ) } else a . find ( "> span" ) . text ( edior . opts . paragraphFormat . N ) } } return { apply : g , refreshOnShow : h , refresh : i } } , a . FE . RegisterShortcut ( a . FE . KEYCODE . ZERO , "paragraphFormat" , "N" , "0" , ! 1 , ! 0 ) , a . FE . RegisterShortcut ( a . FE . KEYCODE . ONE , "paragraphFormat" , "H1" , "1" , ! 1 , ! 0 ) , a . FE . RegisterShortcut ( a . FE . KEYCODE . TWO , "paragraphFormat" , "H2" , "2" , ! 1 , ! 0 ) , a . FE . RegisterShortcut ( a . FE . KEYCODE . THREE , "paragraphFormat" , "H3" , "3" , ! 1 , ! 0 ) , a . FE . RegisterShortcut ( a . FE . KEYCODE . FOUR , "paragraphFormat" , "H4" , "4" , ! 1 , ! 0 ) , a . FE . RegisterCommand ( "paragraphFormat" , { type : "dropdown" , displaySelection : function ( a ) { return a . opts . paragraphFormatSelection } , defaultSelection : "Normal" , displaySelectionWidth : 100 , html : function ( ) { var a = '<ul class="fr-dropdown-list">' , b = this . opts . paragraphFormat ; for ( var c in b ) if ( b . hasOwnProperty ( c ) ) { var d = this . shortcuts . get ( "paragraphFormat." + c ) ; d = d ? '<span class="fr-shortcut">' + d + "</span>" : "" , a += "<li><" + ( "N" == c ? this . html . defaultTag ( ) || "DIV" : c ) + ' style="padding: 0 !important; margin: 0 !important;"><a class="fr-command" data-cmd="paragraphFormat" data-param1="' + c + '" title="' + this . language . translate ( b [ c ] ) + '">' + this . language . translate ( b [ c ] ) + "</a></" + ( "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 ) { " func
2016-05-21 02:38:04 +00:00
else { jQuery = require ( 'jquery' ) ( root ) ; } }
factory ( jQuery ) ; return jQuery ; } ; } else { factory ( jQuery ) ; } } ( function ( $ ) { 'use strict' ; $ . 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 ( ) ) ; } }
2016-05-21 21:24:04 +00:00
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 ) ; }
2016-05-21 02:38:04 +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 . popups . show ( 'file.insert' , null , null ) ; } } }
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' ) ; } } }
2016-05-21 21:24:04 +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' )
2016-05-21 02:38:04 +00:00
$layer . find ( 'h3' ) . text ( message ) ; }
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 ( ) ; } }
function insert ( link , text , response ) { editor . edit . on ( ) ; editor . events . focus ( true ) ; editor . selection . restore ( ) ; editor . html . insert ( '<a href="' + link + '" id="fr-inserted-file" class="fr-file">' + ( text || editor . selection . text ( ) ) + '</a>' ) ; var $file = editor . $el . find ( '#fr-inserted-file' ) ; $file . removeAttr ( 'id' ) ; editor . popups . hide ( 'file.insert' ) ; editor . undo . saveStep ( ) ; 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 ) ; }
function upload ( files ) { if ( editor . events . trigger ( 'file.beforeUpload' , [ files ] ) === false ) { return false ; }
if ( typeof files != 'undefined' && files . length > 0 ) { 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 ] ) ; } }
form _data . append ( editor . opts . fileUploadParam , file ) ; var url = editor . opts . fileUploadURL ; if ( editor . opts . fileUploadToS3 ) { 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 , [ ( editor . opts . fileUseSelectedText ? null : 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 = '' ; }
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"></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>' }
var progress _bar _layer = '<div class="fr-file-progress-bar-layer fr-layer"><h3 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" data-cmd="fileDismissError" tabIndex="2">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 ( $ ( link ) . hasClass ( '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 . opts . scrollableContainer ) ) ; editor . popups . show ( 'file.insert' , e . originalEvent . pageX , e . originalEvent . pageY ) ; showProgressBar ( ) ; upload ( dt . files ) ; e . preventDefault ( ) ; e . stopPropagation ( ) ; return false ; } } } }
2016-05-21 21:24:04 +00:00
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' ) ; } } ) ; }
2016-05-21 02:38:04 +00:00
function back ( ) { editor . events . disableBlur ( ) ; editor . selection . restore ( ) ; editor . events . enableBlur ( ) ; editor . popups . hide ( 'file.insert' ) ; editor . toolbar . showInline ( ) ; }
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' ) ; } }
function _init ( ) { _initEvents ( ) ; editor . events . on ( 'link.beforeRemove' , _onRemove ) ; _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 ( ) ; }
else { if ( this . $el . find ( '.fr-marker' ) ) { 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' ) ; }
2016-05-21 19:21:19 +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 ) { "use strict" ; 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 : "http://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 : { "fr-rounded" : "Rounded" , "fr-bordered" : "Bordered" } , imageMove : ! 0 , imageMultipleStyles : ! 0 , imageTextNear : ! 0 , imagePaste : ! 0 , imagePasteProcess : ! 1 , imageMinWidth : 16 , imageOutputSize : ! 1 } ) , 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 ( "" ) , qa && c . val ( qa . 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 = L ( ) ) , r ( ) , ! 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 c = b . popups . get ( "image.edit" ) ; c || ( c = p ( ) ) , b . popups . setContainer ( "image.edit" , a ( b . opts . scrollableContainer ) ) , b . popups . refresh ( "image.edit" ) ; var d = qa . offset ( ) . left + qa . outerWidth ( ) / 2 , e = qa . offset ( ) . top + qa . outerHeight ( ) ; b . popups . show ( "image.edit" , d , e , qa . outerHeight ( ) ) } function f ( ) { r ( ) } function g ( a ) { if ( ! a . hasClass ( "fr-dii" ) && ! a . hasClass ( "fr-dib" ) ) { var c = a . css ( "float" ) ; a . css ( "float" , "none" ) , "block" == a . css ( "display" ) ? ( a . css ( "float" , c ) , b . opts . imageEditButtons . indexOf ( "imageAlign" ) >= 0 && ( 0 === parseInt ( a . css ( "margin-left" ) , 10 ) && ( a . attr ( "style" ) || "" ) . indexOf ( "margin-right: auto" ) >= 0 ? a . addClass ( "fr-fil" ) : 0 === parseInt ( a . css ( "margin-right" ) , 10 ) && ( a . attr ( "style" ) || "" ) . indexOf ( "margin-left: auto" ) >= 0 && a . addClass ( "fr-fir" ) ) , a . addClass ( "fr-dib" ) ) : ( a . css ( "float" , c ) , b . opts . imageEditButtons . indexOf ( "imageAlign" ) >= 0 && ( "left" == a . css ( "float" ) ? a . addClass ( "fr-fil" ) : "right" == a . css ( "float" ) && a . addClass ( "fr-fir" ) ) , a . addClass ( "fr-dii" ) ) , 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 ( ) { for ( var c = "IMG" == b . $el . get ( 0 ) . tagName ? [ b . $el . get ( 0 ) ] : b . $el . get ( 0 ) . querySelectorAll ( "img" ) , d = 0 ; d < c . length ; d ++ ) { var e = a ( c [ d ] ) ; ( b . opts . imageEditButtons . indexOf ( "imageAlign" ) >= 0 || b . opts . imageEditButtons . indexOf ( "imageDisplay" ) >= 0 ) && g ( e ) , e . attr ( "width" ) && ( e . css ( "width" , e . width ( ) ) , e . removeAttr ( "width" ) ) , b . opts . imageTextNear || e . removeClass ( "fr-dii" ) . addClass ( "fr-dib" ) , b . opts . iframe && e . on ( "load" , b . size . syncIframe ) } } function i ( ) { var c , d = Array . prototype . slice . call ( b . $el . get ( 0 ) . 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 ] . className && d [ c ] . removeAttribute ( "class" ) , "" === d [ c ] . getAttribute ( "style" ) && d [ c ] . removeAttribute ( "style" ) ; if ( Da ) for ( c = 0 ; c < Da . length ; c ++ ) e . indexOf ( Da [ c ] . getAttribute ( "src" ) ) < 0 && b . ev
2016-05-19 18:35:40 +00:00
else { jQuery = require ( 'jquery' ) ( root ) ; } }
factory ( jQuery ) ; return jQuery ; } ; } else { factory ( jQuery ) ; } } ( function ( $ ) { 'use strict' ; $ . extend ( $ . FE . POPUP _TEMPLATES , { 'link.edit' : '[_BUTTONS_]' , 'link.insert' : '[_BUTTONS_][_INPUT_LAYER_]' } )
$ . extend ( $ . FE . DEFAULTS , { linkEditButtons : [ 'linkOpen' , 'linkStyle' , 'linkEdit' , 'linkRemove' ] , linkInsertButtons : [ 'linkBack' , '|' , 'linkList' ] , linkAttributes : { } , linkAutoPrefix : 'http://' , linkStyles : { 'fr-green' : 'Green' , 'fr-strong' : 'Thick' } , linkMultipleStyles : true , linkConvertEmailAddress : true , linkAlwaysBlank : false , linkAlwaysNoFollow : false , linkList : [ { text : 'Froala' , href : 'https://froala.com' , target : '_blank' } , { text : 'Google' , href : 'https://google.com' , target : '_blank' } , { displayText : 'Facebook' , href : 'https://facebook.com' } ] , linkText : true } ) ; $ . FE . PLUGINS . link = function ( editor ) { function get ( ) { var $current _image = editor . image ? editor . image . get ( ) : null ; if ( ! $current _image && editor . $wp ) { var s _el = editor . selection . element ( ) ; var e _el = editor . selection . endElement ( ) ; if ( s _el . tagName != 'A' ) { s _el = $ ( s _el ) . parents ( 'a:first' ) . get ( 0 ) ; }
if ( e _el . tagName != 'A' ) { e _el = $ ( e _el ) . parents ( 'a:first' ) . get ( 0 ) ; }
if ( e _el && e _el == s _el ) { return s _el ; }
return null ; }
else if ( editor . $el . get ( 0 ) . tagName == 'A' && editor . core . hasFocus ( ) ) { return editor . $el . get ( 0 ) ; }
else { if ( $current _image && $current _image . get ( 0 ) . parentNode && $current _image . get ( 0 ) . parentNode . tagName == 'A' ) { return $current _image . get ( 0 ) . parentNode ; } } }
function allSelected ( ) { var $current _image = editor . image ? editor . image . get ( ) : null ; var selectedLinks = [ ] ; if ( $current _image ) { if ( $current _image . get ( 0 ) . parentNode . tagName == 'A' ) { selectedLinks . push ( $current _image . get ( 0 ) . parentNode ) ; } }
else { var range ; var containerEl ; var links ; var linkRange ; if ( editor . win . getSelection ) { var sel = editor . win . getSelection ( ) ; if ( sel . getRangeAt && sel . rangeCount ) { linkRange = editor . doc . createRange ( ) ; for ( var r = 0 ; r < sel . rangeCount ; ++ r ) { range = sel . getRangeAt ( r ) ; containerEl = range . commonAncestorContainer ; if ( containerEl && containerEl . nodeType != 1 ) { containerEl = containerEl . parentNode ; }
if ( containerEl && containerEl . nodeName . toLowerCase ( ) == 'a' ) { selectedLinks . push ( containerEl ) ; } else { links = containerEl . getElementsByTagName ( 'a' ) ; for ( var i = 0 ; i < links . length ; ++ i ) { linkRange . selectNodeContents ( links [ i ] ) ; if ( linkRange . compareBoundaryPoints ( range . END _TO _START , range ) < 1 && linkRange . compareBoundaryPoints ( range . START _TO _END , range ) > - 1 ) { selectedLinks . push ( links [ i ] ) ; } } } } } } else if ( editor . doc . selection && editor . doc . selection . type != 'Control' ) { range = editor . doc . selection . createRange ( ) ; containerEl = range . parentElement ( ) ; if ( containerEl . nodeName . toLowerCase ( ) == 'a' ) { selectedLinks . push ( containerEl ) ; } else { links = containerEl . getElementsByTagName ( 'a' ) ; linkRange = editor . doc . body . createTextRange ( ) ; for ( var j = 0 ; j < links . length ; ++ j ) { linkRange . moveToElementText ( links [ j ] ) ; if ( linkRange . compareEndPoints ( 'StartToEnd' , range ) > - 1 && linkRange . compareEndPoints ( 'EndToStart' , range ) < 1 ) { selectedLinks . push ( links [ j ] ) ; } } } } }
return selectedLinks ; }
function _edit ( e ) { _hideEditPopup ( ) ; setTimeout ( function ( ) { if ( ! e || ( e && ( e . which == 1 || e . type != 'mouseup' ) ) ) { var link = get ( ) ; var $current _image = editor . image ? editor . image . get ( ) : null ; if ( link && ! $current _image ) { if ( editor . image ) { var contents = editor . node . contents ( link ) ; if ( contents . length == 1 && contents [ 0 ] . tagName == 'IMG' ) { var range = editor . selection . ranges ( 0 ) ; if ( range . startOffset === 0 && range . endOffset === 0 ) { $ ( link ) . before ( $ . FE . MARKERS ) ; }
else { $ ( link ) . after ( $ . FE . MARKERS ) ; }
editor . selection . restore ( ) ; return false ; } }
if ( e ) { e . stopPropagation ( ) ; }
_showEditPopup ( link ) ; } } } , editor . helpers . isIOS ( ) ? 100 : 0 ) ; }
function _showEditPopup ( link ) { var $popup = editor . popups . get ( 'link.edit' ) ; if ( ! $popup ) $popup = _initEditPopup ( ) ; var $link = $ ( link ) ; if ( ! editor . popups . isVisible ( 'link.edit' ) ) { editor . popups . refresh ( 'link.edit' ) ; }
editor . popups . setContainer ( 'link.edit' , $ ( editor . opts . scrollableContainer ) ) ; var left = $link . offset ( ) . left + $ ( link ) . outerWidth ( ) / 2 ; var top = $link . offset ( ) . top + $link . outerHeight ( ) ; editor . popups . show ( 'link.edit' , left , top , $link . outerHeight ( ) ) ; }
function _hideEditPopup ( ) { editor . popups . hide ( 'link.edit' ) ; }
function _initEditPopup ( ) { var link _buttons = '' ; if ( editor . opts . linkEditButtons . length > 1 ) { if ( editor . $el . get ( 0 ) . tagName == 'A' && editor . opts . linkEditButtons . indexOf ( 'linkRemove' ) >= 0 ) { editor . opts . linkEditButtons . splice ( editor . opts . linkEditButtons . indexOf ( 'linkRemove' ) , 1 ) ; }
link _buttons = '<div class="fr-buttons">' + editor . button . buildList ( editor . opts . linkEditButtons ) + '</div>' ; }
var template = { buttons : link _buttons } ; var $popup = editor . popups . create ( 'link.edit' , template ) ; if ( editor . $wp ) { editor . events . $on ( editor . $wp , 'scroll.link-edit' , function ( ) { if ( get ( ) && editor . popups . isVisible ( 'link.edit' ) ) { _showEditPopup ( get ( ) ) ; } } ) ; }
return $popup ; }
function _hideInsertPopup ( ) { }
function _refreshInsertPopup ( ) { var $popup = editor . popups . get ( 'link.insert' ) ; var link = get ( ) ; if ( link ) { var $link = $ ( link ) ; var text _inputs = $popup . find ( 'input.fr-link-attr[type="text"]' ) ; var check _inputs = $popup . find ( 'input.fr-link-attr[type="checkbox"]' ) ; var i ; var $input ; for ( i = 0 ; i < text _inputs . length ; i ++ ) { $input = $ ( text _inputs [ i ] ) ; $input . val ( $link . attr ( $input . attr ( 'name' ) || '' ) ) ; }
check _inputs . prop ( 'checked' , false ) ; for ( i = 0 ; i < check _inputs . length ; i ++ ) { $input = $ ( check _inputs [ i ] ) ; if ( $link . attr ( $input . attr ( 'name' ) ) == $input . data ( 'checked' ) ) { $input . prop ( 'checked' , true ) ; } }
$popup . find ( 'input.fr-link-attr[type="text"][name="text"]' ) . val ( $link . text ( ) ) ; }
else { $popup . find ( 'input.fr-link-attr[type="text"]' ) . val ( '' ) ; $popup . find ( 'input.fr-link-attr[type="checkbox"]' ) . prop ( 'checked' , false ) ; $popup . find ( 'input.fr-link-attr[type="text"][name="text"]' ) . val ( editor . selection . text ( ) ) ; }
$popup . find ( 'input.fr-link-attr' ) . trigger ( 'change' ) ; var $current _image = editor . image ? editor . image . get ( ) : null ; if ( $current _image ) { $popup . find ( '.fr-link-attr[name="text"]' ) . parent ( ) . hide ( ) ; }
else { $popup . find ( '.fr-link-attr[name="text"]' ) . parent ( ) . show ( ) ; } }
function _showInsertPopup ( ) { var $btn = editor . $tb . find ( '.fr-command[data-cmd="insertLink"]' ) ; var $popup = editor . popups . get ( 'link.insert' ) ; if ( ! $popup ) $popup = _initInsertPopup ( ) ; if ( ! $popup . hasClass ( 'fr-active' ) ) { editor . popups . refresh ( 'link.insert' ) ; editor . popups . setContainer ( 'link.insert' , editor . $tb || $ ( editor . opts . scrollableContainer ) ) ; if ( $btn . is ( ':visible' ) ) { var left = $btn . offset ( ) . left + $btn . outerWidth ( ) / 2 ; var top = $btn . offset ( ) . top + ( editor . opts . toolbarBottom ? 10 : $btn . outerHeight ( ) - 10 ) ; editor . popups . show ( 'link.insert' , left , top , $btn . outerHeight ( ) ) ; }
else { editor . position . forSelection ( $popup ) ; editor . popups . show ( 'link.insert' ) ; } } }
function _initInsertPopup ( delayed ) { if ( delayed ) { editor . popups . onRefresh ( 'link.insert' , _refreshInsertPopup ) ; editor . popups . onHide ( 'link.insert' , _hideInsertPopup ) ; return true ; }
var link _buttons = '' ; if ( editor . opts . linkInsertButtons . length >= 1 ) { link _buttons = '<div class="fr-buttons">' + editor . button . buildList ( editor . opts . linkInsertButtons ) + '</div>' ; }
var checkmark = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="10" height="10" viewBox="0 0 32 32"><path d="M27 4l-15 15-7-7-5 5 12 12 20-20z" fill="#FFF"></path></svg>' ; var input _layer = '' ; var tab _idx = 0 ; input _layer = '<div class="fr-link-insert-layer fr-layer fr-active" id="fr-link-insert-layer-' + editor . id + '">' ; input _layer += '<div class="fr-input-line"><input name="href" type="text" class="fr-link-attr" placeholder="URL" tabIndex="' + ( ++ tab _idx ) + '"></div>' ; if ( editor . opts . linkText ) { input _layer += '<div class="fr-input-line"><input name="text" type="text" class="fr-link-attr" placeholder="' + editor . language . translate ( 'Text' ) + '" tabIndex="' + ( ++ tab _idx ) + '"></div>' ; }
for ( var attr in editor . opts . linkAttributes ) { if ( editor . opts . linkAttributes . hasOwnProperty ( attr ) ) { var placeholder = editor . opts . linkAttributes [ attr ] ; input _layer += '<div class="fr-input-line"><input name="' + attr + '" type="text" class="fr-link-attr" placeholder="' + editor . language . translate ( placeholder ) + '" tabIndex="' + ( ++ tab _idx ) + '"></div>' ; } }
if ( ! editor . opts . linkAlwaysBlank ) { input _layer += '<div class="fr-checkbox-line"><span class="fr-checkbox"><input name="target" class="fr-link-attr" data-checked="_blank" type="checkbox" id="fr-link-target-' + editor . id + '" tabIndex="' + ( ++ tab _idx ) + '"><span>' + checkmark + '</span></span><label for="fr-link-target-' + editor . id + '">' + editor . language . translate ( 'Open in new tab' ) + '</label></div>' ; }
input _layer += '<div class="fr-action-buttons"><button class="fr-command fr-submit" data-cmd="linkInsert" href="#" tabIndex="' + ( ++ tab _idx ) + '" type="button">' + editor . language . translate ( 'Insert' ) + '</button></div></div>'
var template = { buttons : link _buttons , input _layer : input _layer }
var $popup = editor . popups . create ( 'link.insert' , template ) ; if ( editor . $wp ) { editor . events . $on ( editor . $wp , 'scroll.link-insert' , function ( ) { var $current _image = editor . image ? editor . image . get ( ) : null ; if ( $current _image && editor . popups . isVisible ( 'link.insert' ) ) { imageLink ( ) ; }
if ( get && editor . popups . isVisible ( 'link.insert' ) ) { update ( ) ; } } ) ; }
return $popup ; }
function remove ( ) { var link = get ( ) ; var $current _image = editor . image ? editor . image . get ( ) : null ; if ( editor . events . trigger ( 'link.beforeRemove' , [ link ] ) === false ) return false ; if ( $current _image && link ) { $current _image . unwrap ( ) ; editor . image . edit ( $current _image ) ; }
else if ( link ) { editor . selection . save ( ) ; $ ( link ) . replaceWith ( $ ( link ) . html ( ) ) ; editor . selection . restore ( ) ; _hideEditPopup ( ) ; } }
function _init ( ) { editor . events . on ( 'keyup' , function ( e ) { if ( e . which != $ . FE . KEYCODE . ESC ) { _edit ( e ) ; } } ) ; editor . events . on ( 'window.mouseup' , _edit ) ; if ( editor . helpers . isMobile ( ) ) { editor . events . $on ( editor . $doc , 'selectionchange' , _edit ) ; }
_initInsertPopup ( true ) ; if ( editor . $el . get ( 0 ) . tagName == 'A' ) { editor . $el . addClass ( 'fr-view' ) ; } }
function usePredefined ( val ) { var link = editor . opts . linkList [ val ] ; var $popup = editor . popups . get ( 'link.insert' ) ; var text _inputs = $popup . find ( 'input.fr-link-attr[type="text"]' ) ; var check _inputs = $popup . find ( 'input.fr-link-attr[type="checkbox"]' ) ; var $input ; var i ; for ( i = 0 ; i < text _inputs . length ; i ++ ) { $input = $ ( text _inputs [ i ] ) ; if ( link [ $input . attr ( 'name' ) ] ) { $input . val ( link [ $input . attr ( 'name' ) ] ) ; }
else if ( $input . attr ( 'name' ) != 'text' ) { $input . val ( '' ) ; } }
for ( i = 0 ; i < check _inputs . length ; i ++ ) { $input = $ ( check _inputs [ i ] ) ; $input . prop ( 'checked' , $input . data ( 'checked' ) == link [ $input . attr ( 'name' ) ] ) ; } }
function insertCallback ( ) { var $popup = editor . popups . get ( 'link.insert' ) ; var text _inputs = $popup . find ( 'input.fr-link-attr[type="text"]' ) ; var check _inputs = $popup . find ( 'input.fr-link-attr[type="checkbox"]' ) ; var href = text _inputs . filter ( '[name="href"]' ) . val ( ) ; var text = text _inputs . filter ( '[name="text"]' ) . val ( ) ; var attrs = { } ; var $input ; var i ; for ( i = 0 ; i < text _inputs . length ; i ++ ) { $input = $ ( text _inputs [ i ] ) ; if ( [ 'href' , 'text' ] . indexOf ( $input . attr ( 'name' ) ) < 0 ) { attrs [ $input . attr ( 'name' ) ] = $input . val ( ) ; } }
for ( i = 0 ; i < check _inputs . length ; i ++ ) { $input = $ ( check _inputs [ i ] ) ; if ( $input . is ( ':checked' ) ) { attrs [ $input . attr ( 'name' ) ] = $input . data ( 'checked' ) ; }
else { attrs [ $input . attr ( 'name' ) ] = $input . data ( 'unchecked' ) ; } }
var t = $ ( editor . o _win ) . scrollTop ( ) ; insert ( href , text , attrs ) ; $ ( editor . o _win ) . scrollTop ( t ) ; }
function _split ( ) { if ( ! editor . selection . isCollapsed ( ) ) { editor . selection . save ( ) ; var markers = editor . $el . find ( '.fr-marker' ) . addClass ( 'fr-unprocessed' ) . toArray ( ) ; while ( markers . length ) { var $marker = $ ( markers . pop ( ) ) ; $marker . removeClass ( 'fr-unprocessed' ) ; var deep _parent = editor . node . deepestParent ( $marker . get ( 0 ) ) ; if ( deep _parent ) { var node = $marker . get ( 0 ) ; var close _str = '' ; var open _str = '' ; do { node = node . parentNode ; if ( ! editor . node . isBlock ( node ) ) { close _str = close _str + editor . node . closeTagString ( node ) ; open _str = editor . node . openTagString ( node ) + open _str ; } } while ( node != deep _parent ) ; var marker _str = editor . node . openTagString ( $marker . get ( 0 ) ) + $marker . html ( ) + editor . node . closeTagString ( $marker . get ( 0 ) ) ; $marker . replaceWith ( '<span id="fr-break"></span>' ) ; var h = $ ( deep _parent ) . html ( ) ; h = h . replace ( /<span id="fr-break"><\/span>/g , close _str + marker _str + open _str ) ; $ ( deep _parent ) . html ( h ) ; }
markers = editor . $el . find ( '.fr-marker.fr-unprocessed' ) . toArray ( ) ; }
editor . selection . restore ( ) ; } }
function insert ( href , text , attrs ) { if ( typeof attrs == 'undefined' ) attrs = { } ; var $current _image = editor . image ? editor . image . get ( ) : null ; if ( ! $current _image && editor . $el . get ( 0 ) . tagName != 'A' ) { editor . selection . restore ( ) ; editor . popups . hide ( 'link.insert' ) ; }
else if ( editor . $el . get ( 0 ) . tagName == 'A' ) { editor . $el . focus ( ) ; }
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?:|)\/\//i . test ( href ) ) { if ( [ '/' , '{' , '[' , '#' , '(' ] . indexOf ( ( href || '' ) [ 0 ] ) < 0 ) { href = editor . opts . linkAutoPrefix + href ; } }
2016-05-19 18:35:40 +00:00
href = editor . helpers . sanitizeURL ( href ) ; if ( editor . opts . linkAlwaysBlank ) attrs . target = '_blank' ; if ( editor . opts . linkAlwaysNoFollow ) attrs . rel = 'nofollow' ; text = text || '' ; if ( href === editor . opts . linkAutoPrefix ) { var $popup = editor . popups . get ( 'link.insert' ) ; $popup . find ( 'input[name="href"]' ) . addClass ( 'fr-error' ) ; editor . events . trigger ( 'link.bad' , [ original _href ] ) ; return false ; }
var link = get ( ) ; var $link ; if ( link ) { $link = $ ( link ) ; var a _list = editor . node . rawAttributes ( link ) ; for ( var attr in a _list ) { if ( a _list . hasOwnProperty ( attr ) ) { if ( attr != 'class' && attr != 'style' ) { $link . removeAttr ( attr ) ; } } }
$link . attr ( 'href' , href ) ; if ( text . length > 0 && $link . text ( ) != text && ! $current _image ) { $link . text ( text ) ; }
if ( ! $current _image ) { $link . prepend ( $ . FE . START _MARKER ) . append ( $ . FE . END _MARKER ) ; }
$link . attr ( attrs ) ; if ( ! $current _image ) { editor . selection . restore ( ) ; } }
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 } ) ; } } }
2016-05-19 18:35:40 +00:00
else { $current _image . wrap ( '<a href="' + href + '"></a>' ) ; }
var links = allSelected ( ) ; for ( var i = 0 ; i < links . length ; i ++ ) { $link = $ ( links [ i ] ) ; $link . attr ( attrs ) ; $link . removeAttr ( '_moz_dirty' ) ; }
if ( links . length == 1 && editor . $wp && ! $current _image ) { $ ( links [ 0 ] ) . prepend ( $ . FE . START _MARKER ) . append ( $ . FE . END _MARKER ) ; editor . selection . restore ( ) ; } }
if ( ! $current _image ) { _edit ( ) ; }
else { var $pop = editor . popups . get ( 'link.insert' ) ; $pop . find ( 'input:focus' ) . blur ( ) ; editor . image . edit ( $current _image ) ; } }
function update ( ) { _hideEditPopup ( ) ; var link = get ( ) ; if ( link ) { var $popup = editor . popups . get ( 'link.insert' ) ; if ( ! $popup ) $popup = _initInsertPopup ( ) ; if ( ! editor . popups . isVisible ( 'link.insert' ) ) { editor . popups . refresh ( 'link.insert' ) ; editor . selection . save ( ) ; if ( editor . helpers . isMobile ( ) ) { editor . events . disableBlur ( ) ; editor . $el . blur ( ) ; editor . events . enableBlur ( ) ; } }
editor . popups . setContainer ( 'link.insert' , $ ( editor . opts . scrollableContainer ) ) ; var $ref = ( editor . image ? editor . image . get ( ) : null ) || $ ( link ) ; var left = $ref . offset ( ) . left + $ref . outerWidth ( ) / 2 ; var top = $ref . offset ( ) . top + $ref . outerHeight ( ) ; editor . popups . show ( 'link.insert' , left , top , $ref . outerHeight ( ) ) ; } }
function back ( ) { var $current _image = editor . image ? editor . image . get ( ) : null ; if ( ! $current _image ) { editor . events . disableBlur ( ) ; editor . selection . restore ( ) ; editor . events . enableBlur ( ) ; var link = get ( ) ; if ( link && editor . $wp ) { editor . selection . restore ( ) ; _hideEditPopup ( ) ; _edit ( ) ; }
else if ( editor . $el . get ( 0 ) . tagName == 'A' ) { editor . $el . focus ( ) ; _edit ( ) ; }
else { editor . popups . hide ( 'link.insert' ) ; editor . toolbar . showInline ( ) ; } }
else { editor . image . back ( ) ; } }
function imageLink ( ) { var $current _image = editor . image ? editor . image . get ( ) : null ; if ( $current _image ) { var $popup = editor . popups . get ( 'link.insert' ) ; if ( ! $popup ) $popup = _initInsertPopup ( ) ; _refreshInsertPopup ( true ) ; editor . popups . setContainer ( 'link.insert' , $ ( editor . opts . scrollableContainer ) ) ; var left = $current _image . offset ( ) . left + $current _image . outerWidth ( ) / 2 ; var top = $current _image . offset ( ) . top + $current _image . outerHeight ( ) ; editor . popups . show ( 'link.insert' , left , top , $current _image . outerHeight ( ) ) ; } }
function applyStyle ( val , linkStyles , multipleStyles ) { if ( typeof multipleStyles == 'undefined' ) multipleStyles = editor . opts . linkMultipleStyles ; if ( typeof linkStyles == 'undefined' ) linkStyles = editor . opts . linkStyles ; var link = get ( ) ; if ( ! link ) return false ; if ( ! multipleStyles ) { var styles = Object . keys ( linkStyles ) ; styles . splice ( styles . indexOf ( val ) , 1 ) ; $ ( link ) . removeClass ( styles . join ( ' ' ) ) ; }
$ ( link ) . toggleClass ( val ) ; _edit ( ) ; }
return { _init : _init , remove : remove , showInsertPopup : _showInsertPopup , usePredefined : usePredefined , insertCallback : insertCallback , insert : insert , update : update , get : get , allSelected : allSelected , back : back , imageLink : imageLink , applyStyle : applyStyle } }
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 ( ) ; }
2016-05-19 18:35:40 +00:00
else { if ( this . $el . find ( '.fr-marker' ) ) { this . events . disableBlur ( ) ; this . selection . restore ( ) ; }
this . popups . hide ( 'link.insert' ) ; } } , plugin : 'link' } )
$ . FE . DefineIcon ( 'linkOpen' , { NAME : 'external-link' } ) ; $ . FE . RegisterCommand ( 'linkOpen' , { title : 'Open Link' , undo : false , refresh : function ( $btn ) { var link = this . link . get ( ) ; if ( link ) { $btn . removeClass ( 'fr-hidden' ) ; }
else { $btn . addClass ( 'fr-hidden' ) ; } } , callback : function ( ) { var link = this . link . get ( ) ; if ( link ) { this . o _win . open ( link . href ) ; } } } )
$ . FE . DefineIcon ( 'linkEdit' , { NAME : 'edit' } ) ; $ . FE . RegisterCommand ( 'linkEdit' , { title : 'Edit Link' , undo : false , refreshAfterCallback : false , callback : function ( ) { this . link . update ( ) ; } , refresh : function ( $btn ) { var link = this . link . get ( ) ; if ( link ) { $btn . removeClass ( 'fr-hidden' ) ; }
else { $btn . addClass ( 'fr-hidden' ) ; } } } )
$ . FE . DefineIcon ( 'linkRemove' , { NAME : 'unlink' } ) ; $ . FE . RegisterCommand ( 'linkRemove' , { title : 'Unlink' , callback : function ( ) { this . link . remove ( ) ; } , refresh : function ( $btn ) { var link = this . link . get ( ) ; if ( link ) { $btn . removeClass ( 'fr-hidden' ) ; }
else { $btn . addClass ( 'fr-hidden' ) ; } } } )
$ . FE . DefineIcon ( 'linkBack' , { NAME : 'arrow-left' } ) ; $ . FE . RegisterCommand ( 'linkBack' , { title : 'Back' , undo : false , focus : false , back : true , refreshAfterCallback : false , callback : function ( ) { this . link . back ( ) ; } , refresh : function ( $btn ) { var link = this . link . get ( ) ; var $current _image = this . image ? this . image . get ( ) : null ; if ( ! $current _image && ! link && ! this . opts . toolbarInline ) { $btn . addClass ( 'fr-hidden' ) ; $btn . next ( '.fr-separator' ) . addClass ( 'fr-hidden' ) ; }
else { $btn . removeClass ( 'fr-hidden' ) ; $btn . next ( '.fr-separator' ) . removeClass ( 'fr-hidden' ) ; } } } ) ; $ . FE . DefineIcon ( 'linkList' , { NAME : 'search' } ) ; $ . FE . RegisterCommand ( 'linkList' , { title : 'Choose Link' , type : 'dropdown' , focus : false , undo : false , refreshAfterCallback : false , html : function ( ) { var c = '<ul class="fr-dropdown-list">' ; var options = this . opts . linkList ; for ( var i = 0 ; i < options . length ; i ++ ) { c += '<li><a class="fr-command" data-cmd="linkList" data-param1="' + i + '">' + ( options [ i ] . displayText || options [ i ] . text ) + '</a></li>' ; }
c += '</ul>' ; return c ; } , callback : function ( cmd , val ) { this . link . usePredefined ( val ) ; } } )
$ . FE . RegisterCommand ( 'linkInsert' , { focus : false , refreshAfterCallback : false , callback : function ( ) { this . link . insertCallback ( ) ; } , refresh : function ( $btn ) { var link = this . link . get ( ) ; if ( link ) { $btn . text ( this . language . translate ( 'Update' ) ) ; }
else { $btn . text ( this . language . translate ( 'Insert' ) ) ; } } } )
$ . FE . DefineIcon ( 'imageLink' , { NAME : 'link' } )
$ . FE . RegisterCommand ( 'imageLink' , { title : 'Insert Link' , undo : false , focus : false , callback : function ( ) { this . link . imageLink ( ) ; } , refresh : function ( $btn ) { var link = this . link . get ( ) ; var $prev ; if ( link ) { $prev = $btn . prev ( ) ; if ( $prev . hasClass ( 'fr-separator' ) ) { $prev . removeClass ( 'fr-hidden' ) ; }
$btn . addClass ( 'fr-hidden' ) ; }
else { $prev = $btn . prev ( ) ; if ( $prev . hasClass ( 'fr-separator' ) ) { $prev . addClass ( 'fr-hidden' ) ; }
$btn . removeClass ( 'fr-hidden' ) ; } } } )
$ . FE . DefineIcon ( 'linkStyle' , { NAME : 'magic' } )
$ . FE . RegisterCommand ( 'linkStyle' , { title : 'Style' , type : 'dropdown' , html : function ( ) { var c = '<ul class="fr-dropdown-list">' ; var options = this . opts . linkStyles ; for ( var cls in options ) { if ( options . hasOwnProperty ( cls ) ) { c += '<li><a class="fr-command" data-cmd="linkStyle" data-param1="' + cls + '">' + this . language . translate ( options [ cls ] ) + '</a></li>' ; } }
2016-05-21 19:21:19 +00:00
c += '</ul>' ; return c ; } , callback : function ( cmd , val ) { this . link . applyStyle ( val ) ; } , refreshOnShow : function ( $btn , $dropdown ) { var link = this . link . get ( ) ; if ( link ) { var $link = $ ( link ) ; $dropdown . find ( '.fr-command' ) . each ( function ( ) { var cls = $ ( this ) . data ( 'param1' ) ; $ ( this ) . toggleClass ( 'fr-active' , $link . hasClass ( cls ) ) ; } ) } } } ) } ) ) ; ! function ( a ) { "function" == typeof define && define . amd ? define ( [ "jquery" ] , a ) : "object" == typeof module && module . exports ? module . exports = function ( b , c ) { return void 0 === c && ( c = "undefined" != typeof window ? require ( "jquery" ) : require ( "jquery" ) ( b ) ) , a ( c ) , c } : a ( jQuery ) } ( function ( a ) { "use strict" ; a . extend ( a . FE . POPUP _TEMPLATES , { "table.insert" : "[_BUTTONS_][_ROWS_COLUMNS_]" , "table.edit" : "[_BUTTONS_]" , "table.colors" : "[_BUTTONS_][_COLORS_]" } ) , a . extend ( a . FE . DEFAULTS , { tableInsertMaxSize : 10 , tableEditButtons : [ "tableHeader" , "tableRemove" , "|" , "tableRows" , "tableColumns" , "tableStyle" , "-" , "tableCells" , "tableCellBackground" , "tableCellVerticalAlign" , "tableCellHorizontalAlign" , "tableCellStyle" ] , tableInsertButtons : [ "tableBack" , "|" ] , tableResizerOffset : 5 , tableResizingLimit : 30 , tableColorsButtons : [ "tableBack" , "|" ] , tableColors : [ "#61BD6D" , "#1ABC9C" , "#54ACD2" , "#2C82C9" , "#9365B8" , "#475577" , "#CCCCCC" , "#41A85F" , "#00A885" , "#3D8EB9" , "#2969B0" , "#553982" , "#28324E" , "#000000" , "#F7DA64" , "#FBA026" , "#EB6B56" , "#E25041" , "#A38F84" , "#EFEFEF" , "#FFFFFF" , "#FAC51C" , "#F37934" , "#D14841" , "#B8312F" , "#7C706B" , "#D1D5D8" , "REMOVE" ] , tableColorsStep : 7 , tableCellStyles : { "fr-highlighted" : "Highlighted" , "fr-thick" : "Thick" } , tableStyles : { "fr-dashed-borders" : "Dashed Borders" , "fr-alternate-rows" : "Alternate Rows" } , tableCellMultipleStyles : ! 0 , tableMultipleStyles : ! 0 , tableInsertHelper : ! 0 , tableInsertHelperOffset : 15 } ) , a . FE . PLUGINS . table = function ( b ) { function c ( ) { var a = b . $tb . find ( '.fr-command[data-cmd="insertTable"]' ) , c = b . popups . get ( "table.insert" ) ; if ( c || ( c = g ( ) ) , ! c . hasClass ( "fr-active" ) ) { b . popups . refresh ( "table.insert" ) , b . popups . setContainer ( "table.insert" , b . $tb ) ; var d = a . offset ( ) . left + a . outerWidth ( ) / 2 , e = a . offset ( ) . top + ( b . opts . toolbarBottom ? 10 : a . outerHeight ( ) - 10 ) ; b . popups . show ( "table.insert" , d , e , a . outerHeight ( ) ) } } function d ( ) { var c = B ( ) ; if ( c ) { var d = b . popups . get ( "table.edit" ) ; d || ( d = i ( ) ) , b . popups . setContainer ( "table.edit" , a ( b . opts . scrollableContainer ) ) ; var e = I ( c ) , f = ( e . left + e . right ) / 2 , g = e . bottom ; b . popups . show ( "table.edit" , f , g , e . bottom - e . top ) , b . edit . isDisabled ( ) && ( b . toolbar . disable ( ) , b . $el . removeClass ( "fr-no-selection" ) , b . edit . on ( ) , b . selection . setAtEnd ( b . $el . find ( ".fr-selected-cell:last" ) . get ( 0 ) ) , b . selection . restore ( ) , b . button . bulkRefresh ( ) ) } } function e ( ) { var c = B ( ) ; if ( c ) { var d = b . popups . get ( "table.colors" ) ; d || ( d = j ( ) ) , b . popups . setContainer ( "table.colors" , a ( b . opts . scrollableContainer ) ) ; var e = I ( c ) , f = ( e . left + e . right ) / 2 , g = e . bottom ; l ( ) , b . popups . show ( "table.colors" , f , g , e . bottom - e . top ) } } function f ( ) { 0 === ga ( ) . length && b . toolbar . enable ( ) } function g ( c ) { if ( c ) return b . popups . onHide ( "table.insert" , function ( ) { b . popups . get ( "table.insert" ) . find ( '.fr-table-size .fr-select-table-size > span[data-row="1"][data-col="1"]' ) . trigger ( "mouseenter" ) } ) , ! 0 ; var d = "" ; b . opts . tableInsertButtons . length > 0 && ( d = '<div class="fr-buttons">' + b . button . buildList ( b . opts . tableInsertButtons ) + "</div>" ) ; var e = { buttons : d , rows _columns : h ( ) } , f = b . popups . create ( "table.insert" , e ) ; return b . events . $on ( f , "mouseenter" , ".fr-table-size .fr-select-table-size .fr-table-cell" , function ( c ) { var d = a ( c . currentTarget ) , e = d . data ( "row" ) , f = d . data ( "col" ) , g = d . parent ( ) ; g . siblings ( ".fr-table-size-info" ) . html ( e + " × " + f ) , g . find ( "> span" ) . removeClass ( "hover" ) ; for ( var h = 1 ; h <= b . opts . tableInsertMaxSize ; h ++ ) for ( var i = 0 ; i <= b . opts . tableInsertMaxSize ; i ++ ) { var j = g . find ( '> span[data-row="' + h + '"][data-col="' + i + '"]' ) ; e >= h && f >= i ? j . addClass ( "hover" ) : e + 1 >= h || 2 >= h && ! b . helpers . isMobile ( ) ? j . css ( "display" , "inline-block" ) : h > 2 && ! b . helpers . isMobile ( ) && j . css ( "display" , "none" ) } } , ! 0 ) , f } function h ( ) { for ( var a = '<div class="fr-table-size"><div class="fr-table-size-info">1 × 1</div><div class="fr-select-table-size">' , c = 1 ; c <= b . opts . tableInsertMaxSize ; c ++ ) { for ( var d = 1 ; d <= b . opts . tableInsertMaxSize ; d ++ ) { var e = "inline-block" ; c > 2 && ! b . helpers . isMobile ( ) && ( e = "none" ) ; var f = "fr-table-cell " ; 1 == c && 1 == d && ( f += " hover" ) , a += ' < span
2016-05-21 02:38:04 +00:00
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 ) ; }
2016-05-21 21:24:04 +00:00
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 ) ; } ) ; }
2016-05-21 02:38:04 +00:00
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 ) ; } ) ; }
2016-05-21 21:24:04 +00:00
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>' ; }
2016-05-21 02:38:04 +00:00
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' ) ; }
2016-05-21 19:21:19 +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 ) { "use strict" ; a . FE . PLUGINS . quote = function ( b ) { function c ( a ) { for ( ; a . parentNode && a . parentNode != b . $el . get ( 0 ) ; ) 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 ) { "use strict" ; 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" ) , d . find ( '.fr-command[data-param1="' + e + '"]' ) . addClass ( "fr-active" ) ; 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">' , b = this . opts . fontSize , c = 0 ; c < b . length ; c ++ ) { var d = b [ c ] ; a += '<li><a class="fr-command" 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 ) { "use strict" ; 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 ) } function d ( a , b ) { b . find ( ".fr-command.fr-active" ) . removeClass ( "fr-active" ) , b . fin
2016-05-21 02:38:04 +00:00
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 ) }
2016-05-21 21:24:04 +00:00
function _destroy ( ) { }
2016-05-21 02:38:04 +00:00
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' } )
2016-05-24 19:19:12 +00:00
$ . FE . DefineIcon ( 'mmAudioManager' , { NAME : 'folder' } ) ; } ) ( jQuery ) ; var richeditorPageLinksPlugin
function richeditorPageLinksSelectPage ( $form ) { richeditorPageLinksPlugin . setLinkValueFromPopup ( $form ) }
2016-05-26 19:21:50 +00:00
$ . 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 )
2016-05-24 19:19:12 +00:00
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
2016-05-26 19:21:50 +00:00
editor . $el . popup ( { handler : editor . opts . pageLinksHandler } ) }
2016-05-24 19:19:12 +00:00
function _init ( ) { }
return { _init : _init , setLinkValueFromPopup : setLinkValueFromPopup , setLinkValue : setLinkValue , insertLink : insertLink } }
2016-05-26 19:21:50 +00:00
$ . FE . DEFAULTS . linkInsertButtons = [ 'linkBack' , '|' , 'linkPageLinks' ]
2016-05-24 19:19:12 +00:00
$ . 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 ( )
2016-05-21 02:38:04 +00:00
editor . events . focus ( true )
2016-05-20 20:58:34 +00:00
editor . selection . restore ( )
2016-05-21 02:38:04 +00:00
editor . html . insert ( html )
2016-05-20 20:58:34 +00:00
editor . html . cleanEmptyTags ( )
$ ( 'figure' , editor . $el ) . each ( function ( ) { var $this = $ ( this ) , $parent = $this . parent ( 'p' ) , $next = $this . next ( 'p' )
2016-05-21 02:38:04 +00:00
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"> </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 ) }
2016-05-26 19:21:50 +00:00
function _initUiBlocks ( ) { $ ( '[data-video], [data-audio]' , editor . $el ) . each ( function ( ) { $ ( this ) . addClass ( 'fr-draggable' ) . attr ( { 'data-ui-block' : 'true' , 'draggable' : 'true' , 'tabindex' : '0' } ) . html ( ' ' )
2016-05-20 20:58:34 +00:00
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>' )
2016-05-26 19:21:50 +00:00
$domTree . find ( '[data-video], [data-audio]' ) . each ( function ( ) { $ ( this ) . removeAttr ( 'contenteditable data-ui-block tabindex draggable' ) . removeClass ( 'fr-draggable fr-dragging' ) } )
2016-05-20 20:58:34 +00:00
return $domTree . html ( ) }
function _init ( ) { editor . events . on ( 'initialized' , _initUiBlocks )
2016-05-21 02:38:04 +00:00
editor . events . on ( 'html.set' , _initUiBlocks )
2016-05-20 20:58:34 +00:00
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 ) }
2016-05-21 02:38:04 +00:00
return { _init : _init , insert : insertElement , insertVideo : insertVideo , insertAudio : insertAudio } } } ) ( jQuery ) ; + function ( $ ) { "use strict" ; var Base = $ . oc . foundation . base , BaseProto = Base . prototype
2015-04-25 21:07:22 +00:00
var RichEditor = function ( element , options ) { this . options = options
2015-02-14 05:40:50 +00:00
this . $el = $ ( element )
this . $textarea = this . $el . find ( '>textarea:first' )
this . $form = this . $el . closest ( 'form' )
2016-05-20 20:58:34 +00:00
this . editor = null
2015-04-26 05:48:49 +00:00
$ . oc . foundation . controlUtils . markDisposable ( element )
2015-04-25 21:07:22 +00:00
Base . call ( this )
2015-04-29 03:13:04 +00:00
this . init ( ) }
2015-04-25 21:07:22 +00:00
RichEditor . prototype = Object . create ( BaseProto )
RichEditor . prototype . constructor = RichEditor
2016-05-23 19:33:32 +00:00
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 }
2015-04-25 21:07:22 +00:00
RichEditor . prototype . init = function ( ) { var self = this ; this . $el . one ( 'dispose-control' , this . proxy ( this . dispose ) )
2015-02-14 05:40:50 +00:00
if ( ! this . $textarea . attr ( 'id' ) ) { this . $textarea . attr ( 'id' , 'element-' + Math . random ( ) . toString ( 36 ) . substring ( 7 ) ) }
2016-05-19 18:35:40 +00:00
this . initFroala ( ) }
2016-05-26 19:21:50 +00:00
RichEditor . prototype . initFroala = function ( ) { var froalaOptions = { editorClass : 'control-richeditor' , language : this . options . editorLang , fullPage : this . options . fullpage , pageLinksHandler : this . options . linksHandler }
2016-05-19 18:35:40 +00:00
if ( this . options . toolbarButtons ) { froalaOptions . toolbarButtons = this . options . toolbarButtons . split ( ',' ) }
2016-05-21 02:38:04 +00:00
else { froalaOptions . toolbarButtons = [ 'paragraphFormat' , 'paragraphStyle' , 'quote' , 'bold' , 'italic' , 'align' , 'formatOL' , 'formatUL' , 'insertTable' , 'insertLink' , 'insertImage' , 'insertVideo' , 'insertAudio' , 'insertFile' , 'insertHR' , 'fullscreen' , 'html' ] }
2016-05-23 19:33:32 +00:00
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' }
2016-05-19 18:35:40 +00:00
froalaOptions . toolbarButtonsMD = froalaOptions . toolbarButtons
froalaOptions . toolbarButtonsSM = froalaOptions . toolbarButtons
froalaOptions . toolbarButtonsXS = froalaOptions . toolbarButtons
2016-05-23 19:33:32 +00:00
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,]+/ ) }
2016-05-20 20:58:34 +00:00
froalaOptions . lineBreakerTags = [ 'figure' , 'table' , 'hr' , 'iframe' , 'form' , 'dl' ]
froalaOptions . shortcutsEnabled = [ 'show' , 'bold' , 'italic' , 'underline' , 'indent' , 'outdent' , 'undo' , 'redo' ]
2016-05-21 21:24:04 +00:00
froalaOptions . imageUploadURL = froalaOptions . fileUploadURL = window . location
froalaOptions . imageUploadParam = froalaOptions . fileUploadParam = 'file_data'
froalaOptions . imageUploadParams = froalaOptions . fileUploadParams = { X _OCTOBER _MEDIA _MANAGER _QUICK _UPLOAD : 1 }
2016-05-19 18:35:40 +00:00
var placeholder = this . $textarea . attr ( 'placeholder' )
froalaOptions . placeholderText = placeholder ? placeholder : ''
froalaOptions . height = this . $el . hasClass ( 'stretch' ) ? Infinity : $ ( '.height-indicator' , this . $el ) . height ( )
$ . FroalaEditor . ICON _TEMPLATES = { font _awesome : '<i class="icon-[NAME]"></i>' , text : '<span style="text-align: center;">[NAME]</span>' , image : '<img src=[SRC] alt=[ALT] />' }
this . $textarea . on ( 'froalaEditor.initialized' , this . proxy ( this . build ) )
2016-05-20 20:58:34 +00:00
this . $textarea . on ( 'froalaEditor.contentChanged' , this . proxy ( this . onChange ) )
this . $textarea . on ( 'froalaEditor.keydown' , this . proxy ( this . onKeydown ) )
this . $textarea . on ( 'froalaEditor.html.get' , this . proxy ( this . onSyncContent ) )
this . $textarea . on ( 'froalaEditor.html.set' , this . proxy ( this . onSetContent ) )
this . $textarea . froalaEditor ( froalaOptions )
this . editor = this . $textarea . data ( 'froala.editor' )
this . $el . on ( 'keydown' , '.fr-view figure' , this . proxy ( this . onFigureKeydown ) ) }
2015-04-25 21:07:22 +00:00
RichEditor . prototype . dispose = function ( ) { this . unregisterHandlers ( )
2016-05-19 18:35:40 +00:00
this . $textarea . froalaEditor ( 'destroy' )
2015-04-29 03:13:04 +00:00
this . $el . removeData ( 'oc.richEditor' )
2015-04-25 21:07:22 +00:00
this . options = null
this . $el = null
this . $textarea = null
this . $form = null
2016-05-20 20:58:34 +00:00
this . editor = null
2015-04-25 21:07:22 +00:00
BaseProto . dispose . call ( this ) }
2016-05-20 20:58:34 +00:00
RichEditor . prototype . unregisterHandlers = function ( ) { this . $el . off ( 'keydown' , '.fr-view figure' , this . proxy ( this . onFigureKeydown ) )
this . $textarea . off ( 'froalaEditor.initialized' , this . proxy ( this . build ) )
this . $textarea . off ( 'froalaEditor.contentChanged' , this . proxy ( this . onChange ) )
this . $textarea . off ( 'froalaEditor.keydown' , this . proxy ( this . onKeydown ) )
this . $textarea . off ( 'froalaEditor.html.get' , this . proxy ( this . onSyncContent ) )
this . $textarea . off ( 'froalaEditor.html.set' , this . proxy ( this . onSetContent ) )
$ ( window ) . off ( 'resize' , this . proxy ( this . updateLayout ) )
2015-04-25 21:07:22 +00:00
$ ( window ) . off ( 'oc.updateUi' , this . proxy ( this . updateLayout ) )
this . $el . off ( 'dispose-control' , this . proxy ( this . dispose ) ) }
2016-05-19 18:35:40 +00:00
RichEditor . prototype . build = function ( event , editor ) { this . updateLayout ( )
2015-04-25 21:07:22 +00:00
$ ( window ) . on ( 'resize' , this . proxy ( this . updateLayout ) )
$ ( window ) . on ( 'oc.updateUi' , this . proxy ( this . updateLayout ) )
2016-05-20 20:58:34 +00:00
this . $textarea . trigger ( 'init.oc.richeditor' , [ this ] ) }
2016-03-23 09:10:55 +00:00
RichEditor . prototype . getElement = function ( ) { return this . $el }
2016-05-20 20:58:34 +00:00
RichEditor . prototype . getEditor = function ( ) { return this . editor }
2016-03-23 09:10:55 +00:00
RichEditor . prototype . getTextarea = function ( ) { return this . $textarea }
2016-05-20 20:58:34 +00:00
RichEditor . prototype . getContent = function ( ) { return this . $textarea . froalaEditor ( 'html.get' ) }
RichEditor . prototype . setContent = function ( html ) { this . $textarea . froalaEditor ( 'html.set' , html ) }
RichEditor . prototype . syncContent = function ( ) { this . editor . events . trigger ( 'contentChanged' ) }
2016-05-19 18:35:40 +00:00
RichEditor . prototype . updateLayout = function ( ) { var $editor = $ ( '.fr-wrapper' , this . $el ) , $codeEditor = $ ( '.fr-code' , this . $el ) , $toolbar = $ ( '.fr-toolbar' , this . $el ) , $box = $ ( '.fr-box' , this . $el )
2016-02-13 01:59:49 +00:00
if ( ! $editor . length ) { return }
2016-05-19 18:35:40 +00:00
if ( this . $el . hasClass ( 'stretch' ) && ! $box . hasClass ( 'fr-fullscreen' ) ) { var height = $toolbar . outerHeight ( true )
2015-02-14 05:40:50 +00:00
$editor . css ( 'top' , height + 1 )
2016-05-19 18:35:40 +00:00
$codeEditor . css ( 'top' , height ) }
else { $editor . css ( 'top' , '' )
$codeEditor . css ( 'top' , '' ) } }
2016-05-20 20:58:34 +00:00
RichEditor . prototype . insertHtml = function ( html ) { this . editor . html . insert ( html )
this . editor . selection . restore ( ) }
RichEditor . prototype . insertElement = function ( $el ) { this . insertHtml ( $ ( '<div />' ) . append ( $el . clone ( ) ) . remove ( ) . html ( ) ) }
RichEditor . prototype . insertUiBlock = function ( $node ) { this . $textarea . froalaEditor ( 'figures.insert' , $node ) }
2016-05-21 02:38:04 +00:00
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 ) }
2016-05-20 20:58:34 +00:00
RichEditor . prototype . onSetContent = function ( ev , editor ) { this . $textarea . trigger ( 'setContent.oc.richeditor' , [ this ] ) }
RichEditor . prototype . onSyncContent = function ( ev , editor , html ) { var container = { html : html }
this . $textarea . trigger ( 'syncContent.oc.richeditor' , [ this , container ] )
return container . html }
2015-04-25 21:07:22 +00:00
RichEditor . prototype . onFocus = function ( ) { this . $el . addClass ( 'editor-focus' ) }
RichEditor . prototype . onBlur = function ( ) { this . $el . removeClass ( 'editor-focus' ) }
2016-05-20 20:58:34 +00:00
RichEditor . prototype . onFigureKeydown = function ( ev ) { this . $textarea . trigger ( 'figureKeydown.oc.richeditor' , [ ev , this ] ) }
RichEditor . prototype . onKeydown = function ( ev , editor , keyEv ) { this . $textarea . trigger ( 'keydown.oc.richeditor' , [ keyEv , this ] )
2016-02-13 01:59:49 +00:00
if ( ev . isDefaultPrevented ( ) ) { return false } }
2016-05-20 20:58:34 +00:00
RichEditor . prototype . onChange = function ( ev ) { this . $form . trigger ( 'change' ) }
2015-02-14 05:40:50 +00:00
var old = $ . fn . richEditor
2016-03-23 09:10:55 +00:00
$ . fn . richEditor = function ( option ) { var args = Array . prototype . slice . call ( arguments , 1 ) , result
this . each ( function ( ) { var $this = $ ( this )
2015-02-14 05:40:50 +00:00
var data = $this . data ( 'oc.richEditor' )
var options = $ . extend ( { } , RichEditor . DEFAULTS , $this . data ( ) , typeof option == 'object' && option )
if ( ! data ) $this . data ( 'oc.richEditor' , ( data = new RichEditor ( this , options ) ) )
2016-03-23 09:10:55 +00:00
if ( typeof option == 'string' ) result = data [ option ] . apply ( data , args )
if ( typeof result != 'undefined' ) return false } )
return result ? result : this }
2015-02-14 05:40:50 +00:00
$ . fn . richEditor . Constructor = RichEditor
$ . fn . richEditor . noConflict = function ( ) { $ . fn . richEditor = old
return this }
2016-02-13 01:59:49 +00:00
$ ( document ) . render ( function ( ) { $ ( '[data-control="richeditor"]' ) . richEditor ( ) } ) } ( window . jQuery ) ;