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

Commit e39e509

Browse files
authored
use buttons instead of links to avoid medium-editor conflicts (#355)
1 parent facb89f commit e39e509

File tree

5 files changed

+27
-37
lines changed

5 files changed

+27
-37
lines changed

spec/core.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe('Core', function () {
115115
jasmine.clock().tick(101);
116116

117117
expect(this.$el.find('.medium-insert-buttons').css('display')).toBe('block');
118-
expect(this.$el.find('.medium-insert-buttons a[data-addon="embeds"]').parent().css('display')).toBe('none');
118+
expect(this.$el.find('.medium-insert-buttons button[data-addon="embeds"]').parent().css('display')).toBe('none');
119119
});
120120

121121
it('hides plugin\'s buttons after clicking on non-empty paragraph', function () {

src/js/core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@
440440

441441
if (activeAddon) {
442442
$buttons.find('li').hide();
443-
$buttons.find('a[data-addon="' + activeAddon + '"]').parent().show();
443+
$buttons.find('button[data-addon="' + activeAddon + '"]').parent().show();
444444
}
445445
};
446446

@@ -523,7 +523,7 @@
523523
*/
524524

525525
Core.prototype.addonAction = function (e) {
526-
var $a = $(e.target).is('a') ? $(e.target) : $(e.target).closest('a'),
526+
var $a = $(e.currentTarget),
527527
addon = $a.data('addon'),
528528
action = $a.data('action');
529529

src/js/templates.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ this["MediumInsert"]["Templates"] = this["MediumInsert"]["Templates"] || {};
44
this["MediumInsert"]["Templates"]["src/js/templates/core-buttons.hbs"] = Handlebars.template({"1":function(container,depth0,helpers,partials,data) {
55
var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function";
66

7-
return " <li><a data-addon=\""
7+
return " <li><button data-addon=\""
88
+ container.escapeExpression(((helper = (helper = helpers.key || (data && data.key)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"key","hash":{},"data":data}) : helper)))
99
+ "\" data-action=\"add\" class=\"medium-insert-action\">"
1010
+ ((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 : "")
11-
+ "</a></li>\n";
11+
+ "</button></li>\n";
1212
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
1313
var stack1;
1414

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"
15+
return "<div class=\"medium-insert-buttons\" contenteditable=\"false\" style=\"display: none\">\n <button class=\"medium-insert-buttons-show\"><span>+</span></button>\n <ul class=\"medium-insert-buttons-addons\" style=\"display: none\">\n"
1616
+ ((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 : "")
1717
+ " </ul>\n</div>\n";
1818
},"useData":true});

src/js/templates/core-buttons.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="medium-insert-buttons" contenteditable="false" style="display: none">
2-
<a class="medium-insert-buttons-show">+</a>
2+
<button class="medium-insert-buttons-show"><span>+</span></button>
33
<ul class="medium-insert-buttons-addons" style="display: none">
44
{{#each addons}}
5-
<li><a data-addon="{{@key}}" data-action="add" class="medium-insert-action">{{{label}}}</a></li>
5+
<li><button data-addon="{{@key}}" data-action="add" class="medium-insert-action">{{{label}}}</button></li>
66
{{/each}}
77
</ul>
88
</div>

src/sass/_core.scss

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,29 @@
3131
position: absolute;
3232
color: #ddd;
3333
font-size: 0.9em;
34-
a {
35-
text-decoration: underline;
36-
cursor: pointer;
37-
}
38-
39-
.medium-insert-buttons-show {
40-
box-sizing: border-box;
34+
button {
4135
display: block;
36+
cursor: pointer;
37+
color: #ddd;
38+
background: #fff;
4239
width: 32px;
4340
height: 32px;
44-
margin-top: -5px;
41+
box-sizing: border-box;
4542
border-radius: 20px;
46-
border: 1px solid;
47-
font-size: 25px;
48-
line-height: 28px;
43+
border: 1px solid #ddd;
44+
line-height: 30px;
4945
text-align: center;
50-
text-decoration: none;
51-
background: #fff;
46+
padding: 0;
47+
}
48+
49+
.medium-insert-buttons-show {
50+
font-size: 25px;
5251
transform: rotate(0);
5352
transition: transform 100ms;
54-
53+
span {
54+
display: block;
55+
margin-top: -4px;
56+
}
5557
&.medium-insert-buttons-rotate {
5658
transition: transform 250ms;
5759
transform: rotate(45deg);
@@ -69,21 +71,9 @@
6971
top: -32px;
7072
li {
7173
display: inline-block;
72-
background-color: #fff;
73-
a {
74-
box-sizing: border-box;
75-
display: inline-block;
76-
margin: 0 5px;
77-
width: 32px;
78-
height: 32px;
79-
border-radius: 20px;
80-
border: 1px solid;
81-
font-size: 20px;
82-
line-height: 28px;
83-
text-align: center;
84-
.fa {
85-
font-size: 15px;
86-
}
74+
margin: 0 5px;
75+
.fa {
76+
font-size: 15px;
8777
}
8878
}
8979
}

0 commit comments

Comments
 (0)