11 lines
39 KiB
JavaScript
11 lines
39 KiB
JavaScript
/*!
|
|
* medium-editor-insert-plugin v2.4.1 - jQuery insert plugin for MediumEditor
|
|
*
|
|
* http://linkesch.com/medium-editor-insert-plugin
|
|
*
|
|
* Copyright (c) 2014 Pavel Linkesch (http://linkesch.com)
|
|
* Released under the MIT license
|
|
*/
|
|
|
|
!function(a){"function"==typeof define&&define.amd?define(["jquery","handlebars/runtime","medium-editor","blueimp-file-upload","jquery-sortable"],a):"object"==typeof module&&module.exports?module.exports=function(b){if("undefined"==typeof window)throw new Error("medium-editor-insert-plugin runs only in a browser.");return void 0===b&&(b=require("jquery")),window.jQuery=b,Handlebars=require("handlebars/runtime"),MediumEditor=require("medium-editor"),require("jquery-sortable"),require("blueimp-file-upload"),a(b,Handlebars,MediumEditor),b}:a(jQuery,Handlebars,MediumEditor)}(function(a,b,c){this.MediumInsert=this.MediumInsert||{},this.MediumInsert.Templates=this.MediumInsert.Templates||{},this.MediumInsert.Templates["src/js/templates/core-buttons.hbs"]=b.template({1:function(a,b,c,d,e){var f,g,h=null!=b?b:{},i=c.helperMissing,j="function";return' <li><button data-addon="'+a.escapeExpression((g=null!=(g=c.key||e&&e.key)?g:i,typeof g===j?g.call(h,{name:"key",hash:{},data:e}):g))+'" data-action="add" class="medium-insert-action" type="button">'+(null!=(g=null!=(g=c.label||(null!=b?b.label:b))?g:i,f=typeof g===j?g.call(h,{name:"label",hash:{},data:e}):g)?f:"")+"</button></li>\n"},compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){var f;return'<div class="medium-insert-buttons" contenteditable="false" style="display: none">\n <button class="medium-insert-buttons-show" type="button"><span>+</span></button>\n <ul class="medium-insert-buttons-addons" style="display: none">\n'+(null!=(f=c.each.call(null!=b?b:{},null!=b?b.addons:b,{name:"each",hash:{},fn:a.program(1,e,0),inverse:a.noop,data:e}))?f:"")+" </ul>\n</div>\n"},useData:!0}),this.MediumInsert.Templates["src/js/templates/core-caption.hbs"]=b.template({compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){var f;return'<figcaption contenteditable="true" class="medium-insert-caption-placeholder" data-placeholder="'+a.escapeExpression((f=null!=(f=c.placeholder||(null!=b?b.placeholder:b))?f:c.helperMissing,"function"==typeof f?f.call(null!=b?b:{},{name:"placeholder",hash:{},data:e}):f))+'"></figcaption>'},useData:!0}),this.MediumInsert.Templates["src/js/templates/core-empty-line.hbs"]=b.template({compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){return"<p><br></p>\n"},useData:!0}),this.MediumInsert.Templates["src/js/templates/embeds-toolbar.hbs"]=b.template({1:function(a,b,c,d,e){var f;return' <div class="medium-insert-embeds-toolbar medium-editor-toolbar medium-toolbar-arrow-under medium-editor-toolbar-active">\n <ul class="medium-editor-toolbar-actions clearfix">\n'+(null!=(f=c.each.call(null!=b?b:{},null!=b?b.styles:b,{name:"each",hash:{},fn:a.program(2,e,0),inverse:a.noop,data:e}))?f:"")+" </ul>\n </div>\n"},2:function(a,b,c,d,e){var f;return null!=(f=c.if.call(null!=b?b:{},null!=b?b.label:b,{name:"if",hash:{},fn:a.program(3,e,0),inverse:a.noop,data:e}))?f:""},3:function(a,b,c,d,e){var f,g,h=null!=b?b:{},i=c.helperMissing,j="function";return' <li>\n <button class="medium-editor-action" data-action="'+a.escapeExpression((g=null!=(g=c.key||e&&e.key)?g:i,typeof g===j?g.call(h,{name:"key",hash:{},data:e}):g))+'">'+(null!=(g=null!=(g=c.label||(null!=b?b.label:b))?g:i,f=typeof g===j?g.call(h,{name:"label",hash:{},data:e}):g)?f:"")+"</button>\n </li>\n"},5:function(a,b,c,d,e){var f;return' <div class="medium-insert-embeds-toolbar2 medium-editor-toolbar medium-editor-toolbar-active">\n <ul class="medium-editor-toolbar-actions clearfix">\n'+(null!=(f=c.each.call(null!=b?b:{},null!=b?b.actions:b,{name:"each",hash:{},fn:a.program(2,e,0),inverse:a.noop,data:e}))?f:"")+" </ul>\n </div>\n"},compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){var f,g=null!=b?b:{};return(null!=(f=c.if.call(g,null!=b?b.styles:b,{name:"if",hash:{},fn:a.program(1,e,0),inverse:a.noop,data:e}))?f:"")+"\n"+(null!=(f=c.if.call(g,null!=b?b.actions:b,{name:"if",hash:{},fn:a.program(5,e,0),inverse:a.noop,data:e}))?f:"")},useData:!0}),this.MediumInsert.Templates["src/js/templates/embeds-wrapper.hbs"]=b.template({compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){var f,g;return'<div class="medium-insert-embeds" contenteditable="false">\n\t<figure>\n\t\t<div class="medium-insert-embed">\n\t\t\t'+(null!=(g=null!=(g=c.html||(null!=b?b.html:b))?g:c.helperMissing,f="function"==typeof g?g.call(null!=b?b:{},{name:"html",hash:{},data:e}):g)?f:"")+'\n\t\t</div>\n\t</figure>\n\t<div class="medium-insert-embeds-overlay"></div>\n</div>'},useData:!0}),this.MediumInsert.Templates["src/js/templates/images-fileupload.hbs"]=b.template({compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){return'<input type="file" multiple>'},useData:!0}),this.MediumInsert.Templates["src/js/templates/images-image.hbs"]=b.template({1:function(a,b,c,d,e){return' <div class="medium-insert-images-progress"></div>\n'},compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){var f,g,h=null!=b?b:{};return'<figure contenteditable="false">\n <img src="'+a.escapeExpression((g=null!=(g=c.img||(null!=b?b.img:b))?g:c.helperMissing,"function"==typeof g?g.call(h,{name:"img",hash:{},data:e}):g))+'" alt="" />\n'+(null!=(f=c.if.call(h,null!=b?b.progress:b,{name:"if",hash:{},fn:a.program(1,e,0),inverse:a.noop,data:e}))?f:"")+"</figure>\n"},useData:!0}),this.MediumInsert.Templates["src/js/templates/images-progressbar.hbs"]=b.template({compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){return'<progress min="0" max="100" value="0">0</progress>'},useData:!0}),this.MediumInsert.Templates["src/js/templates/images-toolbar.hbs"]=b.template({1:function(a,b,c,d,e){var f;return null!=(f=c.if.call(null!=b?b:{},null!=b?b.label:b,{name:"if",hash:{},fn:a.program(2,e,0),inverse:a.noop,data:e}))?f:""},2:function(a,b,c,d,e){var f,g,h=null!=b?b:{},i=c.helperMissing,j="function";return' <li>\n <button class="medium-editor-action" data-action="'+a.escapeExpression((g=null!=(g=c.key||e&&e.key)?g:i,typeof g===j?g.call(h,{name:"key",hash:{},data:e}):g))+'">'+(null!=(g=null!=(g=c.label||(null!=b?b.label:b))?g:i,f=typeof g===j?g.call(h,{name:"label",hash:{},data:e}):g)?f:"")+"</button>\n </li>\n"},4:function(a,b,c,d,e){var f;return'\t<div class="medium-insert-images-toolbar2 medium-editor-toolbar medium-editor-toolbar-active">\n\t\t<ul class="medium-editor-toolbar-actions clearfix">\n'+(null!=(f=c.each.call(null!=b?b:{},null!=b?b.actions:b,{name:"each",hash:{},fn:a.program(5,e,0),inverse:a.noop,data:e}))?f:"")+" \t</ul>\n </div>\n"},5:function(a,b,c,d,e){var f;return null!=(f=c.if.call(null!=b?b:{},null!=b?b.label:b,{name:"if",hash:{},fn:a.program(6,e,0),inverse:a.noop,data:e}))?f:""},6:function(a,b,c,d,e){var f,g,h=null!=b?b:{},i=c.helperMissing,j="function";return' \t <li>\n \t <button class="medium-editor-action" data-action="'+a.escapeExpression((g=null!=(g=c.key||e&&e.key)?g:i,typeof g===j?g.call(h,{name:"key",hash:{},data:e}):g))+'">'+(null!=(g=null!=(g=c.label||(null!=b?b.label:b))?g:i,f=typeof g===j?g.call(h,{name:"label",hash:{},data:e}):g)?f:"")+"</button>\n \t </li>\n"},compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){var f,g=null!=b?b:{};return'<div class="medium-insert-images-toolbar medium-editor-toolbar medium-toolbar-arrow-under medium-editor-toolbar-active">\n <ul class="medium-editor-toolbar-actions clearfix">\n'+(null!=(f=c.each.call(g,null!=b?b.styles:b,{name:"each",hash:{},fn:a.program(1,e,0),inverse:a.noop,data:e}))?f:"")+" </ul>\n</div>\n\n"+(null!=(f=c.if.call(g,null!=b?b.actions:b,{name:"if",hash:{},fn:a.program(4,e,0),inverse:a.noop,data:e}))?f:"")},useData:!0}),function(a,b,c,d){"use strict";function e(a){return a.charAt(0).toUpperCase()+a.slice(1)}function f(c,e){var f;this.el=c,this.$el=a(c),this.templates=b.MediumInsert.Templates,e&&(f=e.editor,e.editor=null),this.options=a.extend(!0,{},h,e),this.options.editor=f,this._defaults=h,this._name=g,this.options&&this.options.editor&&(this.options.editor._serialize===d&&(this.options.editor._serialize=this.options.editor.serialize),this.options.editor._destroy===d&&(this.options.editor._destroy=this.options.editor.destroy),this.options.editor._setup===d&&(this.options.editor._setup=this.options.editor.setup),this.options.editor._hideInsertButtons=this.hideButtons,this.options.editor.serialize=this.editorSerialize,this.options.editor.destroy=this.editorDestroy,this.options.editor.setup=this.editorSetup,this.options.editor.getExtensionByName("placeholder")!==d&&(this.options.editor.getExtensionByName("placeholder").updatePlaceholder=this.editorUpdatePlaceholder))}var g="mediumInsert",h={editor:null,enabled:!0,addons:{images:!0,embeds:!0}};f.prototype.init=function(){this.$el.addClass("medium-editor-insert-plugin"),"object"==typeof this.options.addons&&0!==Object.keys(this.options.addons).length||this.disable(),this.initAddons(),this.clean(),this.events()},f.prototype.events=function(){var c=this;this.$el.on("dragover drop",function(a){a.preventDefault()}).on("keyup click",a.proxy(this,"toggleButtons")).on("selectstart mousedown",".medium-insert, .medium-insert-buttons",a.proxy(this,"disableSelection")).on("click",".medium-insert-buttons-show",a.proxy(this,"toggleAddons")).on("click",".medium-insert-action",a.proxy(this,"addonAction")).on("paste",".medium-insert-caption-placeholder",function(b){a.proxy(c,"removeCaptionPlaceholder")(a(b.target))}),a(b).on("resize",a.proxy(this,"positionButtons",null))},f.prototype.getEditor=function(){return this.options.editor},f.prototype.editorSerialize=function(){var b=this._serialize();return a.each(b,function(c){var d=a("<div />").html(b[c].value);d.find(".medium-insert-buttons").remove(),d.find(".medium-insert-active").removeClass("medium-insert-active"),d.find("[data-embed-code]").each(function(){var b=a(this),c=a("<div />").html(b.attr("data-embed-code")).text();b.html(c)}),b[c].value=d.html()}),b},f.prototype.editorDestroy=function(){a.each(this.elements,function(b,c){a(c).data("plugin_"+g)instanceof f&&a(c).data("plugin_"+g).disable()}),this._destroy()},f.prototype.editorSetup=function(){this._setup(),a.each(this.elements,function(b,c){a(c).data("plugin_"+g)instanceof f&&a(c).data("plugin_"+g).enable()})},f.prototype.editorUpdatePlaceholder=function(b,c){var d=a(b).children().not(".medium-insert-buttons").contents();c||1!==d.length||"br"!==d[0].nodeName.toLowerCase()?this.hidePlaceholder(b):(this.showPlaceholder(b),this.base._hideInsertButtons(a(b)))},f.prototype.triggerInput=function(){this.getEditor()&&this.getEditor().trigger("editableInput",null,this.el)},f.prototype.deselect=function(){c.getSelection().removeAllRanges()},f.prototype.disable=function(){this.options.enabled=!1,this.$el.find(".medium-insert-buttons").addClass("hide")},f.prototype.enable=function(){this.options.enabled=!0,this.$el.find(".medium-insert-buttons").removeClass("hide")},f.prototype.disableSelection=function(b){var c=a(b.target);(!1===c.is("img")||c.hasClass("medium-insert-buttons-show"))&&b.preventDefault()},f.prototype.initAddons=function(){var b=this;this.options.addons&&0!==this.options.addons.length&&a.each(this.options.addons,function(a,c){var d=g+e(a);if(!1===c)return void delete b.options.addons[a];b.$el[d](c),b.options.addons[a]=b.$el.data("plugin_"+d).options})},f.prototype.clean=function(){var b,c,d,e=this;!1!==this.options.enabled&&(0===this.$el.children().length&&this.$el.html(this.templates["src/js/templates/core-empty-line.hbs"]().trim()),d=this.$el.contents().filter(function(){return"#text"===this.nodeName&&""!==a.trim(a(this).text())||"br"===this.nodeName.toLowerCase()}),d.each(function(){a(this).wrap("<p />"),e.moveCaret(a(this).parent(),a(this).text().length)}),this.addButtons(),b=this.$el.find(".medium-insert-buttons"),c=b.prev(),c.attr("class")&&c.attr("class").match(/medium\-insert(?!\-active)/)&&b.before(this.templates["src/js/templates/core-empty-line.hbs"]().trim()))},f.prototype.getButtons=function(){if(!1!==this.options.enabled)return this.templates["src/js/templates/core-buttons.hbs"]({addons:this.options.addons}).trim()},f.prototype.addButtons=function(){0===this.$el.find(".medium-insert-buttons").length&&this.$el.append(this.getButtons())},f.prototype.toggleButtons=function(c){var d,e,f,g,h=a(c.target),i=b.getSelection(),j=this;!1!==this.options.enabled&&(i&&0!==i.rangeCount?(d=i.getRangeAt(0),e=a(d.commonAncestorContainer)):e=h,e.hasClass("medium-editor-insert-plugin")&&(e=e.find("p:first")),f=e.is("p")?e:e.closest("p"),this.clean(),!1===h.hasClass("medium-editor-placeholder")&&0===h.closest(".medium-insert-buttons").length&&0===e.closest(".medium-insert-buttons").length&&(this.$el.find(".medium-insert-active").removeClass("medium-insert-active"),a.each(this.options.addons,function(a){if(h.closest(".medium-insert-"+a).length&&(e=h),e.closest(".medium-insert-"+a).length)return f=e.closest(".medium-insert-"+a),void(g=a)}),f.length&&(""===f.text().trim()&&!g||"images"===g)?(f.addClass("medium-insert-active"),"images"===g?this.$el.find(".medium-insert-buttons").attr("data-active-addon",g):this.$el.find(".medium-insert-buttons").removeAttr("data-active-addon"),setTimeout(function(){j.positionButtons(g),j.showButtons(g)},g?100:0)):this.hideButtons()))},f.prototype.showButtons=function(a){var b=this.$el.find(".medium-insert-buttons");b.show(),b.find("li").show(),a&&(b.find("li").hide(),b.find('button[data-addon="'+a+'"]').parent().show())},f.prototype.hideButtons=function(a){a=a||this.$el,a.find(".medium-insert-buttons").hide(),a.find(".medium-insert-buttons-addons").hide(),a.find(".medium-insert-buttons-show").removeClass("medium-insert-buttons-rotate")},f.prototype.positionButtons=function(c){var d=this.$el.find(".medium-insert-buttons"),e=this.$el.find(".medium-insert-active"),f=e.hasClass("medium-insert-images-grid")?[]:e.find("figure:last figcaption"),g=this.getEditor()?this.getEditor().options.elementsContainer:a("body").get(0),h=["absolute","fixed"].indexOf(b.getComputedStyle(g).getPropertyValue("position"))>-1,i={};e.length&&(i.left=e.position().left,i.top=e.position().top,c?(i.left+=e.width()-d.find(".medium-insert-buttons-show").width()-10,i.top+=e.height()-20+(f.length?-f.height()-parseInt(f.css("margin-top"),10):10)):(i.left+=-parseInt(d.find(".medium-insert-buttons-addons").css("left"),10)-parseInt(d.find(".medium-insert-buttons-addons button:first").css("margin-left"),10),i.top+=parseInt(e.css("margin-top"),10)),h&&(i.top+=g.scrollTop),!1===this.$el.hasClass("medium-editor-placeholder")&&i.left<0&&(i.left=e.position().left),d.css(i))},f.prototype.toggleAddons=function(){if("images"===this.$el.find(".medium-insert-buttons").attr("data-active-addon"))return void this.$el.find(".medium-insert-buttons").find('button[data-addon="images"]').click();this.$el.find(".medium-insert-buttons-addons").fadeToggle(),this.$el.find(".medium-insert-buttons-show").toggleClass("medium-insert-buttons-rotate")},f.prototype.hideAddons=function(){this.$el.find(".medium-insert-buttons-addons").hide(),this.$el.find(".medium-insert-buttons-show").removeClass("medium-insert-buttons-rotate")},f.prototype.addonAction=function(b){var c=a(b.currentTarget),d=c.data("addon"),f=c.data("action");this.$el.data("plugin_"+g+e(d))[f]()},f.prototype.moveCaret=function(a,d){var e,f,g,h;d=d||0,e=c.createRange(),f=b.getSelection(),g=a.get(0),g.childNodes.length||(h=c.createTextNode(" "),g.appendChild(h)),e.setStart(g.childNodes[0],d),e.collapse(!0),f.removeAllRanges(),f.addRange(e)},f.prototype.addCaption=function(a,b){0===a.find("figcaption").length&&a.append(this.templates["src/js/templates/core-caption.hbs"]({placeholder:b}))},f.prototype.removeCaptions=function(b){var c=this.$el.find("figcaption");b&&(c=c.not(b)),c.each(function(){(a(this).hasClass("medium-insert-caption-placeholder")||""===a(this).text().trim())&&a(this).remove()})},f.prototype.removeCaptionPlaceholder=function(a){var b=a.is("figcaption")?a:a.find("figcaption");b.length&&b.removeClass("medium-insert-caption-placeholder").removeAttr("data-placeholder")},a.fn[g]=function(b){return this.each(function(){var c,d=this;a(d).is("textarea")&&(c=a(d).attr("medium-editor-textarea-id"),d=a(d).siblings('[medium-editor-textarea-id="'+c+'"]').get(0)),a.data(d,"plugin_"+g)?"string"==typeof b&&a.data(d,"plugin_"+g)[b]&&a.data(d,"plugin_"+g)[b]():(a.data(d,"plugin_"+g,new f(d,b)),a.data(d,"plugin_"+g).init())})}}(jQuery,window,document),function(a,b,c,d){"use strict";function e(c,d){this.el=c,this.$el=a(c),this.templates=b.MediumInsert.Templates,this.core=this.$el.data("plugin_"+f),this.options=a.extend(!0,{},h,d),this._defaults=h,this._name=f,this.core.getEditor()&&(this.core.getEditor()._serializePreEmbeds=this.core.getEditor().serialize,this.core.getEditor().serialize=this.editorSerialize),this.init()}var f="mediumInsert",g="Embeds",h={label:'<span class="fab fa-youtube-play"></span>',placeholder:"Paste a YouTube, Vimeo, Facebook, Twitter or Instagram link and press Enter",oembedProxy:"http://medium.iframe.ly/api/oembed?iframe=1",captions:!0,captionPlaceholder:"Type caption (optional)",storeMeta:!1,styles:{wide:{label:'<span class="fa fa-align-justify"></span>'},left:{label:'<span class="fa fa-align-left"></span>'},right:{label:'<span class="fa fa-align-right"></span>'}},actions:{remove:{label:'<span class="fa fa-times"></span>',clicked:function(){var b=a.Event("keydown");b.which=8,a(c).trigger(b)}}},parseOnPaste:!1};e.prototype.init=function(){var b=this.$el.find(".medium-insert-embeds");b.attr("contenteditable",!1),b.each(function(){0===a(this).find(".medium-insert-embeds-overlay").length&&a(this).append(a("<div />").addClass("medium-insert-embeds-overlay"))}),this.events(),this.backwardsCompatibility()},e.prototype.events=function(){a(c).on("click",a.proxy(this,"unselectEmbed")).on("keydown",a.proxy(this,"removeEmbed")).on("click",".medium-insert-embeds-toolbar .medium-editor-action",a.proxy(this,"toolbarAction")).on("click",".medium-insert-embeds-toolbar2 .medium-editor-action",a.proxy(this,"toolbar2Action")),this.$el.on("keyup click paste",a.proxy(this,"togglePlaceholder")).on("keydown",a.proxy(this,"processLink")).on("click",".medium-insert-embeds-overlay",a.proxy(this,"selectEmbed")).on("contextmenu",".medium-insert-embeds-placeholder",a.proxy(this,"fixRightClickOnPlaceholder")),this.options.parseOnPaste&&this.$el.on("paste",a.proxy(this,"processPasted")),a(b).on("resize",a.proxy(this,"autoRepositionToolbars"))},e.prototype.backwardsCompatibility=function(){var b=this;this.$el.find(".mediumInsert-embeds").removeClass("mediumInsert-embeds").addClass("medium-insert-embeds"),this.$el.find(".medium-insert-embeds").each(function(){0===a(this).find(".medium-insert-embed").length&&(a(this).after(b.templates["src/js/templates/embeds-wrapper.hbs"]({html:a(this).html()})),a(this).remove())})},e.prototype.editorSerialize=function(){var b=this._serializePreEmbeds();return a.each(b,function(c){var d=a("<div />").html(b[c].value);d.find(".medium-insert-embeds").removeAttr("contenteditable"),d.find(".medium-insert-embeds-overlay").remove(),b[c].value=d.html()}),b},e.prototype.add=function(){var a=this.$el.find(".medium-insert-active");a.html(this.templates["src/js/templates/core-empty-line.hbs"]().trim()),a.is("p")&&(a.replaceWith('<div class="medium-insert-active">'+a.html()+"</div>"),a=this.$el.find(".medium-insert-active"),this.core.moveCaret(a)),a.addClass("medium-insert-embeds medium-insert-embeds-input medium-insert-embeds-active"),this.togglePlaceholder({target:a.get(0)}),a.click(),this.core.hideButtons()},e.prototype.togglePlaceholder=function(c){var d,e,f,g=a(c.target),h=b.getSelection();h&&0!==h.rangeCount&&(d=h.getRangeAt(0),e=a(d.commonAncestorContainer),e.hasClass("medium-insert-embeds-active")?g=e:e.closest(".medium-insert-embeds-active").length&&(g=e.closest(".medium-insert-embeds-active")),g.hasClass("medium-insert-embeds-active")?(f=g.text().trim(),""===f&&!1===g.hasClass("medium-insert-embeds-placeholder")?g.addClass("medium-insert-embeds-placeholder").attr("data-placeholder",this.options.placeholder):""!==f&&g.hasClass("medium-insert-embeds-placeholder")&&g.removeClass("medium-insert-embeds-placeholder").removeAttr("data-placeholder")):this.$el.find(".medium-insert-embeds-active").remove())},e.prototype.fixRightClickOnPlaceholder=function(b){this.core.moveCaret(a(b.target))},e.prototype.processLink=function(a){var b,c=this.$el.find(".medium-insert-embeds-active");if(c.length){if(""===(b=c.text().trim())&&-1!==[8,46,13].indexOf(a.which))return void c.remove();13===a.which&&(a.preventDefault(),a.stopPropagation(),this.options.oembedProxy?this.oembed(b):this.parseUrl(b))}},e.prototype.processPasted=function(b){var c,d;a(".medium-insert-embeds-active").length||(c=b.originalEvent.clipboardData.getData("text"),d=new RegExp("^(http(s?):)?//","i"),d.test(c)&&(this.options.oembedProxy?this.oembed(c,!0):this.parseUrl(c,!0)))},e.prototype.oembed=function(c,d){var e=this;a.support.cors=!0,a.ajax({crossDomain:!0,cache:!1,url:this.options.oembedProxy,dataType:"json",data:{url:c},success:function(b){var f=b&&b.html;if(e.options.storeMeta&&(f+='<div class="medium-insert-embeds-meta"><script type="text/json">'+JSON.stringify(b)+"<\/script></div>"),b&&!f&&"photo"===b.type&&b.url&&(f='<img src="'+b.url+'" alt="">'),!f)return void a.proxy(e,"convertBadEmbed",c)();d?a.proxy(e,"embed",f,c)():a.proxy(e,"embed",f)()},error:function(d,f,g){var h=function(){try{return JSON.parse(d.responseText)}catch(a){}}();void 0!==b.console?b.console.log(h&&h.error||d.status||g.message):b.alert("Error requesting media from "+e.options.oembedProxy+" to insert: "+g+" (response status: "+d.status+")"),a.proxy(e,"convertBadEmbed",c)()}})},e.prototype.parseUrl=function(b,c){var d;return new RegExp(["youtube","youtu.be","vimeo","instagram","twitter","facebook"].join("|")).test(b)?(d=b.replace(/\n?/g,"").replace(/^((http(s)?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/(watch\?v=|v\/)?)([a-zA-Z0-9\-_]+)(.*)?$/,'<div class="video video-youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/$7" frameborder="0" allowfullscreen></iframe></div>').replace(/^https?:\/\/vimeo\.com(\/.+)?\/([0-9]+)$/,'<div class="video video-vimeo"><iframe src="//player.vimeo.com/video/$2" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>').replace(/^https:\/\/twitter\.com\/(\w+)\/status\/(\d+)\/?$/,'<blockquote class="twitter-tweet" align="center" lang="en"><a href="https://twitter.com/$1/statuses/$2"></a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"><\/script>').replace(/^(https:\/\/www\.facebook\.com\/(.*))$/,'<script src="//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.2" async><\/script><div class="fb-post" data-href="$1"><div class="fb-xfbml-parse-ignore"><a href="$1">Loading Facebook post...</a></div></div>').replace(/^https?:\/\/instagram\.com\/p\/(.+)\/?$/,'<span class="instagram"><iframe src="//instagram.com/p/$1/embed/" width="612" height="710" frameborder="0" scrolling="no" allowtransparency="true"></iframe></span>'),this.options.storeMeta&&(d+='<div class="medium-insert-embeds-meta"><script type="text/json">'+JSON.stringify({})+"<\/script></div>"),!1===/<("[^"]*"|'[^']*'|[^'">])*>/.test(d)?(a.proxy(this,"convertBadEmbed",b)(),!1):void(c?this.embed(d,b):this.embed(d))):(a.proxy(this,"convertBadEmbed",b)(),!1)},e.prototype.embed=function(b,c){var d,e=this.$el.find(".medium-insert-embeds-active");if(!b)return alert("Incorrect URL format specified"),!1;b.indexOf("<\/script>")>-1&&(d=a("<div>").attr("data-embed-code",a("<div />").text(b).html()).html(b),b=a("<div>").append(d).html()),c?(e=this.$el.find(":not(iframe, script, style)").contents().filter(function(){return 3===this.nodeType&&this.textContent.indexOf(c)>-1}).parent(),e.after(this.templates["src/js/templates/embeds-wrapper.hbs"]({html:b})),e.text(e.text().replace(c,""))):(e.after(this.templates["src/js/templates/embeds-wrapper.hbs"]({html:b})),e.remove()),this.core.triggerInput(),-1!==b.indexOf("facebook")&&"undefined"!=typeof FB&&setTimeout(function(){FB.XFBML.parse()},2e3)},e.prototype.convertBadEmbed=function(b){var c,d,e,f=this.templates["src/js/templates/core-empty-line.hbs"]().trim();c=this.$el.find(".medium-insert-embeds-active"),e=a(f),c.before(e),c.remove(),e.html(b),d=a(f),e.after(d),this.core.triggerInput(),this.core.moveCaret(d)},e.prototype.selectEmbed=function(b){var c,d=this;this.core.options.enabled&&(c=a(b.target).hasClass("medium-insert-embeds")?a(b.target):a(b.target).closest(".medium-insert-embeds"),c.addClass("medium-insert-embeds-selected"),setTimeout(function(){d.addToolbar(),d.options.captions&&d.core.addCaption(c.find("figure"),d.options.captionPlaceholder)},50))},e.prototype.unselectEmbed=function(b){var c=a(b.target).hasClass("medium-insert-embeds")?a(b.target):a(b.target).closest(".medium-insert-embeds"),d=this.$el.find(".medium-insert-embeds-selected");if(c.hasClass("medium-insert-embeds-selected"))return d.not(c).removeClass("medium-insert-embeds-selected"),a(".medium-insert-embeds-toolbar, .medium-insert-embeds-toolbar2").remove(),this.core.removeCaptions(c.find("figcaption")),void((a(b.target).is(".medium-insert-caption-placeholder")||a(b.target).is("figcaption"))&&(c.removeClass("medium-insert-embeds-selected"),this.core.removeCaptionPlaceholder(c.find("figure"))));d.removeClass("medium-insert-embeds-selected"),a(".medium-insert-embeds-toolbar, .medium-insert-embeds-toolbar2").remove(),a(b.target).is(".medium-insert-caption-placeholder")?this.core.removeCaptionPlaceholder(c.find("figure")):!1===a(b.target).is("figcaption")&&this.core.removeCaptions()},e.prototype.removeEmbed=function(b){var c,d;8!==b.which&&46!==b.which||(c=this.$el.find(".medium-insert-embeds-selected"),c.length&&(b.preventDefault(),a(".medium-insert-embeds-toolbar, .medium-insert-embeds-toolbar2").remove(),d=a(this.templates["src/js/templates/core-empty-line.hbs"]().trim()),c.before(d),c.remove(),this.core.hideAddons(),this.core.moveCaret(d),this.core.triggerInput()))},e.prototype.addToolbar=function(){var b,c,d,e,f=this.$el.find(".medium-insert-embeds-selected"),g=!1;0!==f.length&&(d=this.core.getEditor(),e=d.options.elementsContainer||"body",a(e).append(this.templates["src/js/templates/embeds-toolbar.hbs"]({styles:this.options.styles,actions:this.options.actions}).trim()),b=a(".medium-insert-embeds-toolbar"),c=a(".medium-insert-embeds-toolbar2"),b.find("button").each(function(){f.hasClass("medium-insert-embeds-"+a(this).data("action"))&&(a(this).addClass("medium-editor-button-active"),g=!0)}),!1===g&&b.find("button").first().addClass("medium-editor-button-active"),this.repositionToolbars(),b.fadeIn(),c.fadeIn())},e.prototype.autoRepositionToolbars=function(){setTimeout(function(){this.repositionToolbars(),this.repositionToolbars()}.bind(this),0)},e.prototype.repositionToolbars=function(){var c=a(".medium-insert-embeds-toolbar"),d=a(".medium-insert-embeds-toolbar2"),e=this.$el.find(".medium-insert-embeds-selected"),f=this.core.getEditor().options.elementsContainer,g=["absolute","fixed"].indexOf(b.getComputedStyle(f).getPropertyValue("position"))>-1,h=g?f.getBoundingClientRect():null,i=a(b).width(),j={};d.length&&(j.top=e.offset().top+2,j.left=e.offset().left+e.width()-d.width()-4,g&&(j.top+=f.scrollTop-h.top,j.left-=h.left,i=a(f).width()),j.left+d.width()>i&&(j.left=i-d.width()),d.css(j)),c.length&&(j.left=e.offset().left+e.width()/2-c.width()/2,j.top=e.offset().top-c.height()-8-2-5,g&&(j.top+=f.scrollTop-h.top,j.left-=h.left),j.top<0&&(j.top=0),c.css(j))},e.prototype.toolbarAction=function(b){var c=a(b.target).is("button")?a(b.target):a(b.target).closest("button"),d=c.closest("li"),e=d.closest("ul"),f=e.find("li"),g=this.$el.find(".medium-insert-embeds-selected"),h=this;c.addClass("medium-editor-button-active"),d.siblings().find(".medium-editor-button-active").removeClass("medium-editor-button-active"),f.find("button").each(function(){var b="medium-insert-embeds-"+a(this).data("action");a(this).hasClass("medium-editor-button-active")?(g.addClass(b),h.options.styles[a(this).data("action")].added&&h.options.styles[a(this).data("action")].added(g)):(g.removeClass(b),h.options.styles[a(this).data("action")].removed&&h.options.styles[a(this).data("action")].removed(g))}),this.core.triggerInput()},e.prototype.toolbar2Action=function(b){var c=a(b.target).is("button")?a(b.target):a(b.target).closest("button"),d=this.options.actions[c.data("action")].clicked;d&&d(this.$el.find(".medium-insert-embeds-selected")),this.core.triggerInput()},a.fn[f+g]=function(b){return this.each(function(){a.data(this,"plugin_"+f+g)||a.data(this,"plugin_"+f+g,new e(this,b))})}}(jQuery,window,document),function(a,b,d,e,f){"use strict";function g(c,d){this.el=c,this.$el=a(c),this.$currentImage=null,this.templates=b.MediumInsert.Templates,this.core=this.$el.data("plugin_"+h),this.options=a.extend(!0,{},j,d),this._defaults=j,this._name=h,this.options.preview&&!b.FileReader&&(this.options.preview=!1),this.core.getEditor()&&(this.core.getEditor()._serializePreImages=this.core.getEditor().serialize,this.core.getEditor().serialize=this.editorSerialize),this.init()}var h="mediumInsert",i="Images",j={label:'<span class="fa fa-camera"></span>',deleteMethod:"POST",deleteScript:"delete.php",preview:!0,captions:!0,captionPlaceholder:"Type caption for image (optional)",autoGrid:3,fileUploadOptions:{url:null,acceptFileTypes:/(\.|\/)(gif|jpe?g|png)$/i},fileDeleteOptions:{},styles:{wide:{label:'<span class="fa fa-align-justify"></span>'},left:{label:'<span class="fa fa-align-left"></span>'},right:{label:'<span class="fa fa-align-right"></span>'},grid:{label:'<span class="fa fa-th"></span>'}},actions:{remove:{label:'<span class="fa fa-times"></span>',clicked:function(){var b=a.Event("keydown");b.which=8,a(d).trigger(b)}}},sorting:function(){var b=this;a(".medium-insert-images").sortable({group:"medium-insert-images",containerSelector:".medium-insert-images",itemSelector:"figure",placeholder:'<figure class="placeholder">',handle:"img",nested:!1,vertical:!1,afterMove:function(){b.core.triggerInput()}})},messages:{acceptFileTypesError:"This file is not in a supported format: ",maxFileSizeError:"This file is too big: "}};g.prototype.init=function(){var a=this.$el.find(".medium-insert-images");a.find("figcaption").attr("contenteditable",!0),a.find("figure").attr("contenteditable",!1),this.events(),this.backwardsCompatibility(),this.sorting()},g.prototype.events=function(){a(d).on("click",a.proxy(this,"unselectImage")).on("keydown",a.proxy(this,"removeImage")).on("click",".medium-insert-images-toolbar .medium-editor-action",a.proxy(this,"toolbarAction")).on("click",".medium-insert-images-toolbar2 .medium-editor-action",a.proxy(this,"toolbar2Action")),this.$el.on("click",".medium-insert-images img",a.proxy(this,"selectImage")),a(b).on("resize",a.proxy(this,"autoRepositionToolbars"))},g.prototype.backwardsCompatibility=function(){this.$el.find(".mediumInsert").removeClass("mediumInsert").addClass("medium-insert-images"),this.$el.find(".medium-insert-images.small").removeClass("small").addClass("medium-insert-images-left")},g.prototype.editorSerialize=function(){var b=this._serializePreImages();return a.each(b,function(c){var d=a("<div />").html(b[c].value);d.find(".medium-insert-images").find("figcaption, figure").removeAttr("contenteditable"),d.find(".medium-insert-images-progress").remove(),b[c].value=d.html()}),b},g.prototype.add=function(){var b=this,c=a(this.templates["src/js/templates/images-fileupload.hbs"]()),d={dataType:"json",add:function(c,d){a.proxy(b,"uploadAdd",c,d)()},done:function(c,d){a.proxy(b,"uploadDone",c,d)()}};(new XMLHttpRequest).upload&&(d.progress=function(c,d){a.proxy(b,"uploadProgress",c,d)()},d.progressall=function(c,d){a.proxy(b,"uploadProgressall",c,d)()}),c.fileupload(a.extend(!0,{},this.options.fileUploadOptions,d)),c.click()},g.prototype.uploadAdd=function(b,c){
|
|
var d,e=this.$el.find(".medium-insert-active"),f=this,g=[],h=c.files[0],i=this.options.fileUploadOptions.acceptFileTypes,j=this.options.fileUploadOptions.maxFileSize;if(i&&!i.test(h.type)?g.push(this.options.messages.acceptFileTypesError+h.name):j&&h.size>j&&g.push(this.options.messages.maxFileSizeError+h.name),g.length>0)return this.options.uploadFailed&&"function"==typeof this.options.uploadFailed?void this.options.uploadFailed(g,c):void alert(g.join("\n"));this.core.hideButtons(),e.is("p")&&(e.replaceWith('<div class="medium-insert-active">'+e.html()+"</div>"),e=this.$el.find(".medium-insert-active"),e.next().is("p")?this.core.moveCaret(e.next()):(e.after("<p><br></p>"),this.core.moveCaret(e.next()))),e.addClass("medium-insert-images"),!1===this.options.preview&&0===e.find("progress").length&&(new XMLHttpRequest).upload&&e.append(this.templates["src/js/templates/images-progressbar.hbs"]()),(c.autoUpload||!1!==c.autoUpload&&a(b.target).fileupload("option","autoUpload"))&&c.process().done(function(){f.options.preview?(d=new FileReader,d.onload=function(b){a.proxy(f,"showImage",b.target.result,c)()},d.readAsDataURL(c.files[0])):c.submit()})},g.prototype.uploadProgressall=function(a,b){var c,d;!1===this.options.preview&&(c=parseInt(b.loaded/b.total*100,10),d=this.$el.find(".medium-insert-active").find("progress"),d.attr("value",c).text(c),100===c&&d.remove())},g.prototype.uploadProgress=function(a,b){var c,d;this.options.preview&&(c=100-parseInt(b.loaded/b.total*100,10),d=b.context.find(".medium-insert-images-progress"),d.css("width",c+"%"),0===c&&d.remove())},g.prototype.uploadDone=function(b,c){a.proxy(this,"showImage",c.result.files[0].url,c)(),this.core.clean(),this.sorting()},g.prototype.showImage=function(b,c){var d,e,f=this.$el.find(".medium-insert-active");return f.click(),e=this,this.options.preview&&c.context?(d=this.getDOMImage(),d.onload=function(){c.context.find("img").attr("src",d.src),this.options.uploadCompleted&&this.options.uploadCompleted(c.context,c),e.core.triggerInput()}.bind(this),d.src=b):(c.context=a(this.templates["src/js/templates/images-image.hbs"]({img:b,progress:this.options.preview})).appendTo(f),f.find("br").remove(),this.options.autoGrid&&f.find("figure").length>=this.options.autoGrid&&(a.each(this.options.styles,function(a,b){var c="medium-insert-images-"+a;f.removeClass(c),b.removed&&b.removed(f)}),f.addClass("medium-insert-images-grid"),this.options.styles.grid.added&&this.options.styles.grid.added(f)),this.options.preview?c.submit():this.options.uploadCompleted&&this.options.uploadCompleted(c.context,c)),this.core.triggerInput(),c.context},g.prototype.getDOMImage=function(){return new b.Image},g.prototype.selectImage=function(b){var c,d=this;this.core.options.enabled&&(c=a(b.target),this.$currentImage=c,this.$el.blur(),c.addClass("medium-insert-image-active"),c.closest(".medium-insert-images").addClass("medium-insert-active"),setTimeout(function(){d.addToolbar(),d.options.captions&&d.core.addCaption(c.closest("figure"),d.options.captionPlaceholder)},50))},g.prototype.unselectImage=function(b){var c=a(b.target),d=this.$el.find(".medium-insert-image-active");if(c.is("img")&&c.hasClass("medium-insert-image-active"))return d.not(c).removeClass("medium-insert-image-active"),a(".medium-insert-images-toolbar, .medium-insert-images-toolbar2").remove(),void this.core.removeCaptions(c);d.removeClass("medium-insert-image-active"),a(".medium-insert-images-toolbar, .medium-insert-images-toolbar2").remove(),c.is(".medium-insert-caption-placeholder")?this.core.removeCaptionPlaceholder(d.closest("figure")):!1===c.is("figcaption")&&this.core.removeCaptions(),this.$currentImage=null},g.prototype.removeImage=function(e){var f,g,h,i,j,k,l,m,n,o,p=[],q=this.$el.find(".medium-insert-image-active");if((8===e.which||46===e.which)&&(q.length&&p.push(q),h=b.getSelection(),h&&h.rangeCount&&(i=h.getRangeAt(0),j=i.commonAncestorContainer,l="#text"===j.nodeName?a(j).parent():a(j),k=c.selection.getCaretOffsets(j).left,8===e.which&&0===k?m=l.prev():46===e.which&&k===l.text().length&&(m=l.next()),m&&m.hasClass("medium-insert-images")&&p.push(m.find("img")),(n=c.selection.getSelectionHtml(d))&&a("<div></div>").html(n).find(".medium-insert-images img").each(function(){p.push(a(this))})),p.length)){for(o=0;o<p.length;o++)this.deleteFile(p[o].attr("src")),f=p[o].closest(".medium-insert-images"),p[o].closest("figure").remove(),0===f.find("figure").length&&(g=f.next(),!1!==g.is("p")&&""===g.text()||(g=a(this.templates["src/js/templates/core-empty-line.hbs"]().trim()),f.before(g)),f.remove());this.core.hideAddons(),!n&&g&&(e.preventDefault(),this.core.moveCaret(g)),a(".medium-insert-images-toolbar, .medium-insert-images-toolbar2").remove(),this.core.triggerInput()}},g.prototype.deleteFile=function(b){this.options.deleteScript&&a.ajax(a.extend(!0,{},{url:this.options.deleteScript,type:this.options.deleteMethod||"POST",data:{file:b}},this.options.fileDeleteOptions))},g.prototype.addToolbar=function(){var b,c,d=this.$el.find(".medium-insert-image-active"),e=d.closest(".medium-insert-images"),f=!1,g=this.core.getEditor(),h=g.options.elementsContainer||"body";a(h).append(this.templates["src/js/templates/images-toolbar.hbs"]({styles:this.options.styles,actions:this.options.actions}).trim()),b=a(".medium-insert-images-toolbar"),c=a(".medium-insert-images-toolbar2"),b.find("button").each(function(){e.hasClass("medium-insert-images-"+a(this).data("action"))&&(a(this).addClass("medium-editor-button-active"),f=!0)}),!1===f&&b.find("button").first().addClass("medium-editor-button-active"),this.repositionToolbars(),b.fadeIn(),c.fadeIn()},g.prototype.autoRepositionToolbars=function(){setTimeout(function(){this.repositionToolbars(),this.repositionToolbars()}.bind(this),0)},g.prototype.repositionToolbars=function(){var c=a(".medium-insert-images-toolbar"),d=a(".medium-insert-images-toolbar2"),e=this.$el.find(".medium-insert-image-active"),f=this.core.getEditor().options.elementsContainer,g=["absolute","fixed"].indexOf(b.getComputedStyle(f).getPropertyValue("position"))>-1,h=g?f.getBoundingClientRect():null,i=a(b).width(),j={};d.length&&(j.top=e.offset().top+2,j.left=e.offset().left+e.width()-d.width()-4,g&&(j.top+=f.scrollTop-h.top,j.left-=h.left,i=a(f).width()),j.left+d.width()>i&&(j.left=i-d.width()),d.css(j)),c.length&&(e.closest(".medium-insert-images-grid-active").length&&(e=e.closest(".medium-insert-images-grid-active")),j.top=e.offset().top-c.height()-8-2-5,j.left=e.offset().left+e.width()/2-c.width()/2,g&&(j.top+=f.scrollTop-h.top,j.left-=h.left),j.top<0&&(j.top=0),c.css(j))},g.prototype.toolbarAction=function(b){var c,d,e,f,g,h=this;null!==this.$currentImage&&(c=a(b.target).is("button")?a(b.target):a(b.target).closest("button"),d=c.closest("li"),e=d.closest("ul"),f=e.find("li"),g=this.$el.find(".medium-insert-active"),c.addClass("medium-editor-button-active"),d.siblings().find(".medium-editor-button-active").removeClass("medium-editor-button-active"),f.find("button").each(function(){var b="medium-insert-images-"+a(this).data("action");a(this).hasClass("medium-editor-button-active")?(g.addClass(b),h.options.styles[a(this).data("action")].added&&h.options.styles[a(this).data("action")].added(g)):(g.removeClass(b),h.options.styles[a(this).data("action")].removed&&h.options.styles[a(this).data("action")].removed(g))}),this.core.hideButtons(),this.core.triggerInput())},g.prototype.toolbar2Action=function(b){var c,d;null!==this.$currentImage&&(c=a(b.target).is("button")?a(b.target):a(b.target).closest("button"),d=this.options.actions[c.data("action")].clicked,d&&d(this.$el.find(".medium-insert-image-active")),this.core.hideButtons(),this.core.triggerInput())},g.prototype.sorting=function(){a.proxy(this.options.sorting,this)()},a.fn[h+i]=function(b){return this.each(function(){a.data(this,"plugin_"+h+i)||a.data(this,"plugin_"+h+i,new g(this,b))})}}(jQuery,window,document,c.util)}); |