Skip to content

Commit

Permalink
Getting relative path for uploaded image, instead of absolute. BUILD
Browse files Browse the repository at this point in the history
  • Loading branch information
artshevtsov committed Feb 22, 2018
1 parent de0d95e commit fc088de
Show file tree
Hide file tree
Showing 4 changed files with 1,601 additions and 251 deletions.
71 changes: 42 additions & 29 deletions dist/js/medium-editor-insert-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ this["MediumInsert"] = this["MediumInsert"] || {};
this["MediumInsert"]["Templates"] = this["MediumInsert"]["Templates"] || {};

this["MediumInsert"]["Templates"]["src/js/templates/core-buttons.hbs"] = Handlebars.template({"1":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function";
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function";

return " <li><button data-addon=\""
+ container.escapeExpression(((helper = (helper = helpers.key || (data && data.key)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"key","hash":{},"data":data}) : helper)))
Expand All @@ -49,15 +49,15 @@ this["MediumInsert"]["Templates"]["src/js/templates/core-buttons.hbs"] = Handleb
var stack1;

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"
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.addons : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.addons : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </ul>\n</div>\n";
},"useData":true});

this["MediumInsert"]["Templates"]["src/js/templates/core-caption.hbs"] = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var helper;

return "<figcaption contenteditable=\"true\" class=\"medium-insert-caption-placeholder\" data-placeholder=\""
+ container.escapeExpression(((helper = (helper = helpers.placeholder || (depth0 != null ? depth0.placeholder : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"placeholder","hash":{},"data":data}) : helper)))
+ container.escapeExpression(((helper = (helper = helpers.placeholder || (depth0 != null ? depth0.placeholder : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"placeholder","hash":{},"data":data}) : helper)))
+ "\"></figcaption>";
},"useData":true});

Expand All @@ -69,14 +69,14 @@ this["MediumInsert"]["Templates"]["src/js/templates/embeds-toolbar.hbs"] = Handl
var stack1;

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"
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.styles : depth0),{"name":"each","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.styles : depth0),{"name":"each","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </ul>\n </div>\n";
},"2":function(container,depth0,helpers,partials,data) {
var stack1;

return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.label : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.label : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
},"3":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function";
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function";

return " <li>\n <button class=\"medium-editor-action\" data-action=\""
+ container.escapeExpression(((helper = (helper = helpers.key || (data && data.key)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"key","hash":{},"data":data}) : helper)))
Expand All @@ -87,10 +87,10 @@ this["MediumInsert"]["Templates"]["src/js/templates/embeds-toolbar.hbs"] = Handl
var stack1;

return " <div class=\"medium-insert-embeds-toolbar2 medium-editor-toolbar medium-editor-toolbar-active\">\n <ul class=\"medium-editor-toolbar-actions clearfix\">\n"
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.actions : depth0),{"name":"each","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.actions : depth0),{"name":"each","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </ul>\n </div>\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : {};
var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {});

return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.styles : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "\n"
Expand All @@ -101,7 +101,7 @@ this["MediumInsert"]["Templates"]["src/js/templates/embeds-wrapper.hbs"] = Handl
var stack1, helper;

return "<div class=\"medium-insert-embeds\" contenteditable=\"false\">\n <figure>\n <div class=\"medium-insert-embed\">\n "
+ ((stack1 = ((helper = (helper = helpers.html || (depth0 != null ? depth0.html : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"html","hash":{},"data":data}) : helper))) != null ? stack1 : "")
+ ((stack1 = ((helper = (helper = helpers.html || (depth0 != null ? depth0.html : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"html","hash":{},"data":data}) : helper))) != null ? stack1 : "")
+ "\n </div>\n </figure>\n <div class=\"medium-insert-embeds-overlay\"></div>\n</div>";
},"useData":true});

Expand All @@ -112,7 +112,7 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-fileupload.hbs"] = Ha
this["MediumInsert"]["Templates"]["src/js/templates/images-image.hbs"] = Handlebars.template({"1":function(container,depth0,helpers,partials,data) {
return " <div class=\"medium-insert-images-progress\"></div>\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {};
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {});

return "<figure contenteditable=\"false\">\n <img src=\""
+ container.escapeExpression(((helper = (helper = helpers.img || (depth0 != null ? depth0.img : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"img","hash":{},"data":data}) : helper)))
Expand All @@ -128,9 +128,9 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-progressbar.hbs"] = H
this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handlebars.template({"1":function(container,depth0,helpers,partials,data) {
var stack1;

return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.label : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.label : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
},"2":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function";
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function";

return " <li>\n <button class=\"medium-editor-action\" data-action=\""
+ container.escapeExpression(((helper = (helper = helpers.key || (data && data.key)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"key","hash":{},"data":data}) : helper)))
Expand All @@ -141,22 +141,22 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
var stack1;

return " <div class=\"medium-insert-images-toolbar2 medium-editor-toolbar medium-editor-toolbar-active\">\n <ul class=\"medium-editor-toolbar-actions clearfix\">\n"
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.actions : depth0),{"name":"each","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.actions : depth0),{"name":"each","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </ul>\n </div>\n";
},"5":function(container,depth0,helpers,partials,data) {
var stack1;

return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.label : depth0),{"name":"if","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.label : depth0),{"name":"if","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
},"6":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function";
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function";

return " <li>\n <button class=\"medium-editor-action\" data-action=\""
+ container.escapeExpression(((helper = (helper = helpers.key || (data && data.key)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"key","hash":{},"data":data}) : helper)))
+ "\">"
+ ((stack1 = ((helper = (helper = helpers.label || (depth0 != null ? depth0.label : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"label","hash":{},"data":data}) : helper))) != null ? stack1 : "")
+ "</button>\n </li>\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : {};
var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {});

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"
+ ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.styles : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
Expand Down Expand Up @@ -216,6 +216,9 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
}
this.options = $.extend(true, {}, defaults, options);
this.options.editor = editor;
if (options) {
options.editor = editor; // Restore original object definition
}

this._defaults = defaults;
this._name = pluginName;
Expand Down Expand Up @@ -473,7 +476,7 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
return;
}

if (this.$el.children().length === 0) {
if (this.$el.html().length === 0) {
this.$el.html(this.templates['src/js/templates/core-empty-line.hbs']().trim());
}

Expand Down Expand Up @@ -979,9 +982,11 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
var data = this._serializePreEmbeds();

$.each(data, function (key) {
var $data = $('<div />').html(data[key].value);
var $data = $('<div />').html(data[key].value),
$embeds = $data.find('.medium-insert-embeds');

$data.find('.medium-insert-embeds').removeAttr('contenteditable');
$embeds.removeAttr('contenteditable');
$embeds.find('figcaption').removeAttr('contenteditable');
$data.find('.medium-insert-embeds-overlay').remove();

data[key].value = $data.html();
Expand Down Expand Up @@ -1959,7 +1964,7 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
if (this.options.preview && data.context) {
domImage = this.getDOMImage();
domImage.onload = function () {
data.context.find('img').attr('src', domImage.src);
data.context.find('img').attr('src', domImage.getAttribute('src'));

if (this.options.uploadCompleted) {
this.options.uploadCompleted(data.context, data);
Expand Down Expand Up @@ -2093,7 +2098,7 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
if (selection && selection.rangeCount) {
range = selection.getRangeAt(0);
current = range.commonAncestorContainer;
$current = current.nodeName === '#text' ? $(current).parent() : $(current);
$current = current.nodeName === '#text' || current.nodeName === 'BR' ? $(current).parent() : $(current);
caretPosition = MediumEditor.selection.getCaretOffsets(current).left;

// Is backspace pressed and caret is at the beginning of a paragraph, get previous element
Expand All @@ -2119,7 +2124,7 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl

if (images.length) {
for (i = 0; i < images.length; i++) {
this.deleteFile(images[i].attr('src'));
this.deleteFile(images[i].attr('src'), images[i]);

$parent = images[i].closest('.medium-insert-images');
images[i].closest('figure').remove();
Expand Down Expand Up @@ -2150,17 +2155,25 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
/**
* Makes ajax call to deleteScript
*
* @param {String} file File name
* @param {string} file The name of the file to delete
* @param {jQuery} $el The jQuery element of the file to delete
* @returns {void}
*/

Images.prototype.deleteFile = function (file) {
Images.prototype.deleteFile = function (file, $el) {
// only take action if there is a truthy value
if (this.options.deleteScript) {
$.ajax($.extend(true, {}, {
url: this.options.deleteScript,
type: this.options.deleteMethod || 'POST',
data: { file: file }
}, this.options.fileDeleteOptions));
// try to run it as a callback
if (typeof this.options.deleteScript === 'function') {
this.options.deleteScript(file, $el);
// otherwise, it's probably a string, call it as ajax
} else {
$.ajax($.extend(true, {}, {
url: this.options.deleteScript,
type: this.options.deleteMethod || 'POST',
data: { file: file }
}, this.options.fileDeleteOptions));
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions dist/js/medium-editor-insert-plugin.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit fc088de

Please sign in to comment.