From 3ff2b65edf0cef11f0b4d909fb898a49d4de3a43 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 11 Apr 2017 10:23:03 +0200 Subject: [PATCH] v2.4.1 --- CHANGES.md | 5 +++++ bower.json | 2 +- dist/js/medium-editor-insert-plugin.js | 10 +++++++++- dist/js/medium-editor-insert-plugin.min.js | 6 +++--- package.json | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 521848947..33f37126e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,9 @@ +2.4.1. / 2017-04-11 +================== + + * Ability to add upload failed callback to options #377 + 2.4.0. / 2016-08-08 ================== diff --git a/bower.json b/bower.json index d2a24a5fa..cd968bbdc 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "medium-editor-insert-plugin", - "version": "2.4.0", + "version": "2.4.1", "description": "jQuery insert plugin for MediumEditor", "homepage": "http://linkesch.com/medium-editor-insert-plugin", "main": [ diff --git a/dist/js/medium-editor-insert-plugin.js b/dist/js/medium-editor-insert-plugin.js index 851703726..8c2dfe054 100644 --- a/dist/js/medium-editor-insert-plugin.js +++ b/dist/js/medium-editor-insert-plugin.js @@ -1,5 +1,5 @@ /*! - * medium-editor-insert-plugin v2.4.0 - jQuery insert plugin for MediumEditor + * medium-editor-insert-plugin v2.4.1 - jQuery insert plugin for MediumEditor * * http://linkesch.com/medium-editor-insert-plugin * @@ -1646,6 +1646,7 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl acceptFileTypesError: 'This file is not in a supported format: ', maxFileSizeError: 'This file is too big: ' } + // uploadError: function($el, data) {} // uploadCompleted: function ($el, data) {} }; @@ -1822,7 +1823,14 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl uploadErrors.push(this.options.messages.maxFileSizeError + file.name); } if (uploadErrors.length > 0) { + if (this.options.uploadFailed && typeof this.options.uploadFailed === "function") { + this.options.uploadFailed(uploadErrors, data); + + return; + } + alert(uploadErrors.join("\n")); + return; } diff --git a/dist/js/medium-editor-insert-plugin.min.js b/dist/js/medium-editor-insert-plugin.min.js index 5cd5af461..57486fced 100644 --- a/dist/js/medium-editor-insert-plugin.min.js +++ b/dist/js/medium-editor-insert-plugin.min.js @@ -1,5 +1,5 @@ /*! - * medium-editor-insert-plugin v2.4.0 - jQuery insert plugin for MediumEditor + * medium-editor-insert-plugin v2.4.1 - jQuery insert plugin for MediumEditor * * http://linkesch.com/medium-editor-insert-plugin * @@ -7,5 +7,5 @@ * 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'
  • \n"},compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){var f;return'\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'
    '},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"


    \n"},useData:!0}),this.MediumInsert.Templates["src/js/templates/embeds-toolbar.hbs"]=b.template({1:function(a,b,c,d,e){var f;return'
    \n \n
    \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'
  • \n \n
  • \n"},5:function(a,b,c,d,e){var f;return'
    \n \n
    \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'
    \n
    \n
    \n '+(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
    \n
    \n
    \n
    '},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''},useData:!0}),this.MediumInsert.Templates["src/js/templates/images-image.hbs"]=b.template({1:function(a,b,c,d,e){return'
    \n'},compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){var f,g,h=null!=b?b:{};return'
    \n \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:"")+"
    \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'0'},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'
  • \n \n
  • \n"},4:function(a,b,c,d,e){var f;return'
    \n \n
    \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'
  • \n \n
  • \n"},compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){var f,g=null!=b?b:{};return'
    \n \n
    \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("
    ").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("
    ").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);(c.is("img")===!1||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);return c===!1?void delete b.options.addons[a]:(b.$el[d](c),void(b.options.addons[a]=b.$el.data("plugin_"+d).options))})},f.prototype.clean=function(){var b,c,d,e=this;this.options.enabled!==!1&&(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("

    "),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(){return this.options.enabled!==!1?this.templates["src/js/templates/core-buttons.hbs"]({addons:this.options.addons}).trim():void 0},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;this.options.enabled!==!1&&(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(),h.hasClass("medium-editor-placeholder")===!1&&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){return h.closest(".medium-insert-"+a).length&&(e=h),e.closest(".medium-insert-"+a).length?(f=e.closest(".medium-insert-"+a),void(g=a)):void 0}),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),this.$el.hasClass("medium-editor-placeholder")===!1&&i.left<0&&(i.left=e.position().left),d.css(i))},f.prototype.toggleAddons=function(){return"images"===this.$el.find(".medium-insert-buttons").attr("data-active-addon")?void this.$el.find(".medium-insert-buttons").find('button[data-addon="images"]').click():(this.$el.find(".medium-insert-buttons-addons").fadeToggle(),void 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){var c=a.find("figcaption");0===c.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:'',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:''},left:{label:''},right:{label:''}},actions:{remove:{label:'',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("

    ").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("
    ").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('
    '+a.html()+"
    "),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&&g.hasClass("medium-insert-embeds-placeholder")===!1?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)return b=c.text().trim(),""===b&&-1!==[8,46,13].indexOf(a.which)?void c.remove():void(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;return e.options.storeMeta&&(f+='
    "),b&&!f&&"photo"===b.type&&b.url&&(f=''),f?void(d?a.proxy(e,"embed",f,c)():a.proxy(e,"embed",f)()):void a.proxy(e,"convertBadEmbed",c)()},error:function(d,f,g){var h=function(){try{return JSON.parse(d.responseText)}catch(a){}}();"undefined"!=typeof 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\-_]+)(.*)?$/,'
    ').replace(/^https?:\/\/vimeo\.com(\/.+)?\/([0-9]+)$/,'
    ').replace(/^https:\/\/twitter\.com\/(\w+)\/status\/(\d+)\/?$/,'').replace(/^(https:\/\/www\.facebook\.com\/(.*))$/,'
    ').replace(/^https?:\/\/instagram\.com\/p\/(.+)\/?$/,''),this.options.storeMeta&&(d+='
    "),/<("[^"]*"|'[^']*'|[^'">])*>/.test(d)===!1?(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");return b?(b.indexOf("")>-1&&(d=a("
    ").attr("data-embed-code",a("
    ").text(b).html()).html(b),b=a("
    ").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),void 0):(alert("Incorrect URL format specified"),!1)},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");return c.hasClass("medium-insert-embeds-selected")?(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(),void(a(b.target).is(".medium-insert-caption-placeholder")?this.core.removeCaptionPlaceholder(c.find("figure")):a(b.target).is("figcaption")===!1&&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)}),g===!1&&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:'',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:''},left:{label:''},right:{label:''},grid:{label:''}},actions:{remove:{label:'',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:'
    ',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("
    ").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;return 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?void alert(g.join("\n")):(this.core.hideButtons(),e.is("p")&&(e.replaceWith('
    '+e.html()+"
    "),e=this.$el.find(".medium-insert-active"),e.next().is("p")?this.core.moveCaret(e.next()):(e.after("


    "),this.core.moveCaret(e.next()))),e.addClass("medium-insert-images"),this.options.preview===!1&&0===e.find("progress").length&&(new XMLHttpRequest).upload&&e.append(this.templates["src/js/templates/images-progressbar.hbs"]()),void((c.autoUpload||c.autoUpload!==!1&&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;this.options.preview===!1&&(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");return c.is("img")&&c.hasClass("medium-insert-image-active")?(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")):c.is("figcaption")===!1&&this.core.removeCaptions(),void(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),n&&a("
    ").html(n).find(".medium-insert-images img").each(function(){p.push(a(this))})),p.length)){for(o=0;o-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)}); \ No newline at end of file +!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'
  • \n"},compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){var f;return'\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'
    '},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"


    \n"},useData:!0}),this.MediumInsert.Templates["src/js/templates/embeds-toolbar.hbs"]=b.template({1:function(a,b,c,d,e){var f;return'
    \n
      \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:"")+"
    \n
    \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'
  • \n \n
  • \n"},5:function(a,b,c,d,e){var f;return'
    \n
      \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:"")+"
    \n
    \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'
    \n\t
    \n\t\t
    \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
    \n\t
    \n\t
    \n
    '},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''},useData:!0}),this.MediumInsert.Templates["src/js/templates/images-image.hbs"]=b.template({1:function(a,b,c,d,e){return'
    \n'},compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){var f,g,h=null!=b?b:{};return'
    \n \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:"")+"
    \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'0'},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'
  • \n \n
  • \n"},4:function(a,b,c,d,e){var f;return'\t
    \n\t\t
      \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
    \n
    \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
  • \n \t \n \t
  • \n"},compiler:[7,">= 4.0.0"],main:function(a,b,c,d,e){var f,g=null!=b?b:{};return'
    \n
      \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:"")+"
    \n
    \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("
    ").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("
    ").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("

    "),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:'',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:''},left:{label:''},right:{label:''}},actions:{remove:{label:'',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("

    ").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("
    ").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('
    '+a.html()+"
    "),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+='