Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/assets/js/lib/medium-editor-insert-plugin.min.js

11 lines
39 KiB
JavaScript
Raw Normal View History

2018-10-16 16:28:42 +00:00
/*!
* 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(
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("mediu