Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit e8952e8

Browse files
committed
add support for textarea
1 parent eff9b4d commit e8952e8

File tree

3 files changed

+118
-92
lines changed

3 files changed

+118
-92
lines changed

src/js/core.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,13 +597,21 @@
597597

598598
$.fn[pluginName] = function (options) {
599599
return this.each(function () {
600-
if (!$.data(this, 'plugin_' + pluginName)) {
600+
var that = this,
601+
textareaId;
602+
603+
if ($(that).is('textarea')) {
604+
textareaId = $(that).attr('medium-editor-textarea-id');
605+
that = $(that).siblings('[medium-editor-textarea-id="'+ textareaId +'"]').get(0);
606+
}
607+
608+
if (!$.data(that, 'plugin_' + pluginName)) {
601609
// Plugin initialization
602-
$.data(this, 'plugin_' + pluginName, new Core(this, options));
603-
$.data(this, 'plugin_' + pluginName).init();
604-
} else if (typeof options === 'string' && $.data(this, 'plugin_' + pluginName)[options]) {
610+
$.data(that, 'plugin_' + pluginName, new Core(that, options));
611+
$.data(that, 'plugin_' + pluginName).init();
612+
} else if (typeof options === 'string' && $.data(that, 'plugin_' + pluginName)[options]) {
605613
// Method call
606-
$.data(this, 'plugin_' + pluginName)[options]();
614+
$.data(that, 'plugin_' + pluginName)[options]();
607615
}
608616
});
609617
};

src/js/templates.js

Lines changed: 91 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,123 +2,128 @@ this["MediumInsert"] = this["MediumInsert"] || {};
22
this["MediumInsert"]["Templates"] = this["MediumInsert"]["Templates"] || {};
33

44
this["MediumInsert"]["Templates"]["src/js/templates/core-buttons.hbs"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
5-
var stack1, helper, lambda=this.lambda, escapeExpression=this.escapeExpression, functionType="function", helperMissing=helpers.helperMissing, buffer = " <li><a data-addon=\""
6-
+ escapeExpression(lambda((data && data.key), depth0))
7-
+ "\" data-action=\"add\" class=\"medium-insert-action\">";
8-
stack1 = ((helper = (helper = helpers.label || (depth0 != null ? depth0.label : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"label","hash":{},"data":data}) : helper));
9-
if (stack1 != null) { buffer += stack1; }
10-
return buffer + "</a></li>\n";
5+
var stack1, helper, alias1=helpers.helperMissing, alias2="function";
6+
7+
return " <li><a data-addon=\""
8+
+ this.escapeExpression(((helper = (helper = helpers.key || (data && data.key)) != null ? helper : alias1),(typeof helper === alias2 ? helper.call(depth0,{"name":"key","hash":{},"data":data}) : helper)))
9+
+ "\" data-action=\"add\" class=\"medium-insert-action\">"
10+
+ ((stack1 = ((helper = (helper = helpers.label || (depth0 != null ? depth0.label : depth0)) != null ? helper : alias1),(typeof helper === alias2 ? helper.call(depth0,{"name":"label","hash":{},"data":data}) : helper))) != null ? stack1 : "")
11+
+ "</a></li>\n";
1112
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
12-
var stack1, buffer = "<div class=\"medium-insert-buttons\" contenteditable=\"false\" style=\"display: none\">\n <a class=\"medium-insert-buttons-show\">+</a>\n <ul class=\"medium-insert-buttons-addons\" style=\"display: none\">\n";
13-
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.addons : depth0), {"name":"each","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data});
14-
if (stack1 != null) { buffer += stack1; }
15-
return buffer + " </ul>\n</div>\n";
13+
var stack1;
14+
15+
return "<div class=\"medium-insert-buttons\" contenteditable=\"false\" style=\"display: none\">\n <a class=\"medium-insert-buttons-show\">+</a>\n <ul class=\"medium-insert-buttons-addons\" style=\"display: none\">\n"
16+
+ ((stack1 = helpers.each.call(depth0,(depth0 != null ? depth0.addons : depth0),{"name":"each","hash":{},"fn":this.program(1, data, 0),"inverse":this.noop,"data":data})) != null ? stack1 : "")
17+
+ " </ul>\n</div>\n";
1618
},"useData":true});
1719

1820
this["MediumInsert"]["Templates"]["src/js/templates/core-caption.hbs"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
19-
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
21+
var helper;
22+
2023
return "<figcaption contenteditable=\"true\" class=\"medium-insert-caption-placeholder\" data-placeholder=\""
21-
+ escapeExpression(((helper = (helper = helpers.placeholder || (depth0 != null ? depth0.placeholder : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"placeholder","hash":{},"data":data}) : helper)))
24+
+ this.escapeExpression(((helper = (helper = helpers.placeholder || (depth0 != null ? depth0.placeholder : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0,{"name":"placeholder","hash":{},"data":data}) : helper)))
2225
+ "\"></figcaption>";
2326
},"useData":true});
2427

2528
this["MediumInsert"]["Templates"]["src/js/templates/core-empty-line.hbs"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
26-
return "<p><br></p>\n";
27-
},"useData":true});
29+
return "<p><br></p>\n";
30+
},"useData":true});
2831

2932
this["MediumInsert"]["Templates"]["src/js/templates/embeds-toolbar.hbs"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
30-
var stack1, buffer = " <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";
31-
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.styles : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
32-
if (stack1 != null) { buffer += stack1; }
33-
return buffer + " </ul>\n </div>\n";
33+
var stack1;
34+
35+
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"
36+
+ ((stack1 = helpers.each.call(depth0,(depth0 != null ? depth0.styles : depth0),{"name":"each","hash":{},"fn":this.program(2, data, 0),"inverse":this.noop,"data":data})) != null ? stack1 : "")
37+
+ " </ul>\n </div>\n";
3438
},"2":function(depth0,helpers,partials,data) {
35-
var stack1, buffer = "";
36-
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.label : depth0), {"name":"if","hash":{},"fn":this.program(3, data),"inverse":this.noop,"data":data});
37-
if (stack1 != null) { buffer += stack1; }
38-
return buffer;
39+
var stack1;
40+
41+
return ((stack1 = helpers['if'].call(depth0,(depth0 != null ? depth0.label : depth0),{"name":"if","hash":{},"fn":this.program(3, data, 0),"inverse":this.noop,"data":data})) != null ? stack1 : "");
3942
},"3":function(depth0,helpers,partials,data) {
40-
var stack1, helper, lambda=this.lambda, escapeExpression=this.escapeExpression, functionType="function", helperMissing=helpers.helperMissing, buffer = " <li>\n <button class=\"medium-editor-action\" data-action=\""
41-
+ escapeExpression(lambda((data && data.key), depth0))
42-
+ "\">";
43-
stack1 = ((helper = (helper = helpers.label || (depth0 != null ? depth0.label : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"label","hash":{},"data":data}) : helper));
44-
if (stack1 != null) { buffer += stack1; }
45-
return buffer + "</button>\n </li>\n";
43+
var stack1, helper, alias1=helpers.helperMissing, alias2="function";
44+
45+
return " <li>\n <button class=\"medium-editor-action\" data-action=\""
46+
+ this.escapeExpression(((helper = (helper = helpers.key || (data && data.key)) != null ? helper : alias1),(typeof helper === alias2 ? helper.call(depth0,{"name":"key","hash":{},"data":data}) : helper)))
47+
+ "\">"
48+
+ ((stack1 = ((helper = (helper = helpers.label || (depth0 != null ? depth0.label : depth0)) != null ? helper : alias1),(typeof helper === alias2 ? helper.call(depth0,{"name":"label","hash":{},"data":data}) : helper))) != null ? stack1 : "")
49+
+ "</button>\n </li>\n";
4650
},"5":function(depth0,helpers,partials,data) {
47-
var stack1, buffer = " <div class=\"medium-insert-embeds-toolbar2 medium-editor-toolbar medium-editor-toolbar-active\">\n <ul class=\"medium-editor-toolbar-actions clearfix\">\n";
48-
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.actions : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
49-
if (stack1 != null) { buffer += stack1; }
50-
return buffer + " </ul>\n </div>\n";
51+
var stack1;
52+
53+
return " <div class=\"medium-insert-embeds-toolbar2 medium-editor-toolbar medium-editor-toolbar-active\">\n <ul class=\"medium-editor-toolbar-actions clearfix\">\n"
54+
+ ((stack1 = helpers.each.call(depth0,(depth0 != null ? depth0.actions : depth0),{"name":"each","hash":{},"fn":this.program(2, data, 0),"inverse":this.noop,"data":data})) != null ? stack1 : "")
55+
+ " </ul>\n </div>\n";
5156
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
52-
var stack1, buffer = "";
53-
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.styles : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data});
54-
if (stack1 != null) { buffer += stack1; }
55-
buffer += "\n";
56-
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.actions : depth0), {"name":"if","hash":{},"fn":this.program(5, data),"inverse":this.noop,"data":data});
57-
if (stack1 != null) { buffer += stack1; }
58-
return buffer;
57+
var stack1;
58+
59+
return ((stack1 = helpers['if'].call(depth0,(depth0 != null ? depth0.styles : depth0),{"name":"if","hash":{},"fn":this.program(1, data, 0),"inverse":this.noop,"data":data})) != null ? stack1 : "")
60+
+ "\n"
61+
+ ((stack1 = helpers['if'].call(depth0,(depth0 != null ? depth0.actions : depth0),{"name":"if","hash":{},"fn":this.program(5, data, 0),"inverse":this.noop,"data":data})) != null ? stack1 : "");
5962
},"useData":true});
6063

6164
this["MediumInsert"]["Templates"]["src/js/templates/embeds-wrapper.hbs"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
62-
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, buffer = "<div class=\"medium-insert-embeds\" contenteditable=\"false\">\n <figure>\n <div class=\"medium-insert-embed\">\n ";
63-
stack1 = ((helper = (helper = helpers.html || (depth0 != null ? depth0.html : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"html","hash":{},"data":data}) : helper));
64-
if (stack1 != null) { buffer += stack1; }
65-
return buffer + "\n </div>\n </figure>\n <div class=\"medium-insert-embeds-overlay\"></div>\n</div>";
65+
var stack1, helper;
66+
67+
return "<div class=\"medium-insert-embeds\" contenteditable=\"false\">\n <figure>\n <div class=\"medium-insert-embed\">\n "
68+
+ ((stack1 = ((helper = (helper = helpers.html || (depth0 != null ? depth0.html : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0,{"name":"html","hash":{},"data":data}) : helper))) != null ? stack1 : "")
69+
+ "\n </div>\n </figure>\n <div class=\"medium-insert-embeds-overlay\"></div>\n</div>";
6670
},"useData":true});
6771

6872
this["MediumInsert"]["Templates"]["src/js/templates/images-fileupload.hbs"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
69-
return "<input type=\"file\" multiple>";
70-
},"useData":true});
73+
return "<input type=\"file\" multiple>";
74+
},"useData":true});
7175

7276
this["MediumInsert"]["Templates"]["src/js/templates/images-image.hbs"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
73-
return " <div class=\"medium-insert-images-progress\"></div>\n";
74-
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
75-
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<figure contenteditable=\"false\">\n <img src=\""
76-
+ escapeExpression(((helper = (helper = helpers.img || (depth0 != null ? depth0.img : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"img","hash":{},"data":data}) : helper)))
77-
+ "\" alt=\"\">\n";
78-
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.progress : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data});
79-
if (stack1 != null) { buffer += stack1; }
80-
return buffer + "</figure>";
77+
return " <div class=\"medium-insert-images-progress\"></div>\n";
78+
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
79+
var stack1, helper;
80+
81+
return "<figure contenteditable=\"false\">\n <img src=\""
82+
+ this.escapeExpression(((helper = (helper = helpers.img || (depth0 != null ? depth0.img : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0,{"name":"img","hash":{},"data":data}) : helper)))
83+
+ "\" alt=\"\">\n"
84+
+ ((stack1 = helpers['if'].call(depth0,(depth0 != null ? depth0.progress : depth0),{"name":"if","hash":{},"fn":this.program(1, data, 0),"inverse":this.noop,"data":data})) != null ? stack1 : "")
85+
+ "</figure>";
8186
},"useData":true});
8287

8388
this["MediumInsert"]["Templates"]["src/js/templates/images-progressbar.hbs"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
84-
return "<progress min=\"0\" max=\"100\" value=\"0\">0</progress>";
85-
},"useData":true});
89+
return "<progress min=\"0\" max=\"100\" value=\"0\">0</progress>";
90+
},"useData":true});
8691

8792
this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
88-
var stack1, buffer = "";
89-
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.label : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
90-
if (stack1 != null) { buffer += stack1; }
91-
return buffer;
93+
var stack1;
94+
95+
return ((stack1 = helpers['if'].call(depth0,(depth0 != null ? depth0.label : depth0),{"name":"if","hash":{},"fn":this.program(2, data, 0),"inverse":this.noop,"data":data})) != null ? stack1 : "");
9296
},"2":function(depth0,helpers,partials,data) {
93-
var stack1, helper, lambda=this.lambda, escapeExpression=this.escapeExpression, functionType="function", helperMissing=helpers.helperMissing, buffer = " <li>\n <button class=\"medium-editor-action\" data-action=\""
94-
+ escapeExpression(lambda((data && data.key), depth0))
95-
+ "\">";
96-
stack1 = ((helper = (helper = helpers.label || (depth0 != null ? depth0.label : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"label","hash":{},"data":data}) : helper));
97-
if (stack1 != null) { buffer += stack1; }
98-
return buffer + "</button>\n </li>\n";
97+
var stack1, helper, alias1=helpers.helperMissing, alias2="function";
98+
99+
return " <li>\n <button class=\"medium-editor-action\" data-action=\""
100+
+ this.escapeExpression(((helper = (helper = helpers.key || (data && data.key)) != null ? helper : alias1),(typeof helper === alias2 ? helper.call(depth0,{"name":"key","hash":{},"data":data}) : helper)))
101+
+ "\">"
102+
+ ((stack1 = ((helper = (helper = helpers.label || (depth0 != null ? depth0.label : depth0)) != null ? helper : alias1),(typeof helper === alias2 ? helper.call(depth0,{"name":"label","hash":{},"data":data}) : helper))) != null ? stack1 : "")
103+
+ "</button>\n </li>\n";
99104
},"4":function(depth0,helpers,partials,data) {
100-
var stack1, buffer = " <div class=\"medium-insert-images-toolbar2 medium-editor-toolbar medium-editor-toolbar-active\">\n <ul class=\"medium-editor-toolbar-actions clearfix\">\n";
101-
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.actions : depth0), {"name":"each","hash":{},"fn":this.program(5, data),"inverse":this.noop,"data":data});
102-
if (stack1 != null) { buffer += stack1; }
103-
return buffer + " </ul>\n </div>\n";
105+
var stack1;
106+
107+
return " <div class=\"medium-insert-images-toolbar2 medium-editor-toolbar medium-editor-toolbar-active\">\n <ul class=\"medium-editor-toolbar-actions clearfix\">\n"
108+
+ ((stack1 = helpers.each.call(depth0,(depth0 != null ? depth0.actions : depth0),{"name":"each","hash":{},"fn":this.program(5, data, 0),"inverse":this.noop,"data":data})) != null ? stack1 : "")
109+
+ " </ul>\n </div>\n";
104110
},"5":function(depth0,helpers,partials,data) {
105-
var stack1, buffer = "";
106-
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.label : depth0), {"name":"if","hash":{},"fn":this.program(6, data),"inverse":this.noop,"data":data});
107-
if (stack1 != null) { buffer += stack1; }
108-
return buffer;
111+
var stack1;
112+
113+
return ((stack1 = helpers['if'].call(depth0,(depth0 != null ? depth0.label : depth0),{"name":"if","hash":{},"fn":this.program(6, data, 0),"inverse":this.noop,"data":data})) != null ? stack1 : "");
109114
},"6":function(depth0,helpers,partials,data) {
110-
var stack1, helper, lambda=this.lambda, escapeExpression=this.escapeExpression, functionType="function", helperMissing=helpers.helperMissing, buffer = " <li>\n <button class=\"medium-editor-action\" data-action=\""
111-
+ escapeExpression(lambda((data && data.key), depth0))
112-
+ "\">";
113-
stack1 = ((helper = (helper = helpers.label || (depth0 != null ? depth0.label : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"label","hash":{},"data":data}) : helper));
114-
if (stack1 != null) { buffer += stack1; }
115-
return buffer + "</button>\n </li>\n";
115+
var stack1, helper, alias1=helpers.helperMissing, alias2="function";
116+
117+
return " <li>\n <button class=\"medium-editor-action\" data-action=\""
118+
+ this.escapeExpression(((helper = (helper = helpers.key || (data && data.key)) != null ? helper : alias1),(typeof helper === alias2 ? helper.call(depth0,{"name":"key","hash":{},"data":data}) : helper)))
119+
+ "\">"
120+
+ ((stack1 = ((helper = (helper = helpers.label || (depth0 != null ? depth0.label : depth0)) != null ? helper : alias1),(typeof helper === alias2 ? helper.call(depth0,{"name":"label","hash":{},"data":data}) : helper))) != null ? stack1 : "")
121+
+ "</button>\n </li>\n";
116122
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
117-
var stack1, buffer = "<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";
118-
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.styles : depth0), {"name":"each","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data});
119-
if (stack1 != null) { buffer += stack1; }
120-
buffer += " </ul>\n</div>\n\n";
121-
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.actions : depth0), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.noop,"data":data});
122-
if (stack1 != null) { buffer += stack1; }
123-
return buffer;
123+
var stack1;
124+
125+
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"
126+
+ ((stack1 = helpers.each.call(depth0,(depth0 != null ? depth0.styles : depth0),{"name":"each","hash":{},"fn":this.program(1, data, 0),"inverse":this.noop,"data":data})) != null ? stack1 : "")
127+
+ " </ul>\n</div>\n\n"
128+
+ ((stack1 = helpers['if'].call(depth0,(depth0 != null ? depth0.actions : depth0),{"name":"if","hash":{},"fn":this.program(4, data, 0),"inverse":this.noop,"data":data})) != null ? stack1 : "");
124129
},"useData":true});

0 commit comments

Comments
 (0)