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

Commit a1f91fd

Browse files
committed
Merge pull request #216 from orthes/feature-editableInput-event
Add support for editableInput event - closes #212
2 parents 0c69c1a + fd709c7 commit a1f91fd

File tree

6 files changed

+34
-20
lines changed

6 files changed

+34
-20
lines changed

.jshintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"globals": {
3+
"MediumEditor": true
4+
},
5+
26
"predef": {
37
"jQuery": false,
48
"document": false,
@@ -17,7 +21,6 @@
1721
"expect": false,
1822
"beforeEach": false,
1923
"afterEach": false,
20-
"MediumEditor": false,
2124
"jasmine": false,
2225
"spyOn": false,
2326
"placeCaret": false,

spec/embeds.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe("Embeds addon", function () {
115115
it('triggers input event after removing embed ', function (done) {
116116
var $event = $.Event('keydown');
117117

118-
this.$el.one('input', function () {
118+
this.editor.subscribe('editableInput', function () {
119119
expect(true).toBe(true);
120120
done();
121121
});
@@ -145,7 +145,7 @@ describe("Embeds addon", function () {
145145
it('triggers input event after changing embed style ', function (done) {
146146
this.$el.prepend('<div class="medium-insert-embeds medium-insert-embeds-left"><div class="medium-insert-embeds-overlay"></div></div>');
147147

148-
this.$el.one('input', function () {
148+
this.editor.subscribe('editableInput', function () {
149149
expect(true).toBe(true);
150150
done();
151151
});

spec/images.spec.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe("Images addon", function () {
150150
});
151151

152152
it('triggers input event on showImage', function (done) {
153-
this.$el.one('input', function () {
153+
this.editor.subscribe('editableInput', function () {
154154
expect(true).toBe(true);
155155
done();
156156
});
@@ -169,15 +169,14 @@ describe("Images addon", function () {
169169

170170
spyOn(this.addon, 'getDOMImage').and.returnValue(stubbedImage);
171171

172-
this.$el.on('input', function () {
172+
this.editor.subscribe('editableInput', function () {
173173
inputTriggerCount++;
174174

175175
if (inputTriggerCount === 2) {
176-
this.$el.off('input');
177176
expect(true).toBe(true);
178177
done();
179178
}
180-
}.bind(this));
179+
});
181180

182181
this.addon.showImage('http://image.co', {
183182
context: context
@@ -272,7 +271,7 @@ describe("Images addon", function () {
272271
it('triggers input event after removing image', function (done) {
273272
var $event = $.Event('keydown');
274273

275-
this.$el.one('input', function () {
274+
this.editor.subscribe('editableInput', function () {
276275
expect(true).toBe(true);
277276
done();
278277
});
@@ -322,7 +321,7 @@ describe("Images addon", function () {
322321
.attr('class', 'medium-insert-images medium-insert-active medium-insert-images-left')
323322
.append('<figure><img src="image1.jpg" alt=""></figure>');
324323

325-
this.$el.one('input', function () {
324+
this.editor.subscribe('editableInput', function () {
326325
expect(true).toBe(true);
327326
done();
328327
});

src/js/core.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@
193193
}
194194
};
195195

196+
/**
197+
* Trigger editableInput on editor
198+
*
199+
* @return {void}
200+
*/
201+
202+
Core.prototype.triggerInput = function () {
203+
if (this.getEditor()) {
204+
this.getEditor().trigger('editableInput', null, this.el);
205+
}
206+
};
207+
196208
/**
197209
* Deselects selected text
198210
*

src/js/embeds.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@
367367
}));
368368
$place.remove();
369369

370-
this.$el.trigger('input');
370+
this.core.triggerInput();
371371

372372
if (html.indexOf('facebook') !== -1) {
373373
if (typeof(FB) !== 'undefined') {
@@ -403,7 +403,7 @@
403403
$empty = $(emptyTemplate);
404404
$content.after($empty);
405405

406-
this.$el.trigger('input');
406+
this.core.triggerInput();
407407

408408
this.core.moveCaret($place);
409409
};
@@ -491,7 +491,7 @@
491491
this.core.hideAddons();
492492

493493
this.core.moveCaret($empty);
494-
this.$el.trigger('input');
494+
this.core.triggerInput();
495495
}
496496
}
497497
};
@@ -586,7 +586,7 @@
586586
}
587587
});
588588

589-
this.$el.trigger('input');
589+
this.core.triggerInput();
590590
};
591591

592592
/**
@@ -604,7 +604,7 @@
604604
callback(this.$el.find('.medium-insert-embeds-selected'));
605605
}
606606

607-
this.$el.trigger('input');
607+
this.core.triggerInput();
608608
};
609609

610610
/** Plugin initialization */

src/js/images.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
nested: false,
6565
vertical: false,
6666
afterMove: function () {
67-
that.$el.trigger('input');
67+
that.core.triggerInput();
6868
}
6969
});
7070
},
@@ -372,7 +372,7 @@
372372
domImage = this.getDOMImage();
373373
domImage.onload = function () {
374374
data.context.find('img').attr('src', domImage.src);
375-
that.$el.trigger('input');
375+
that.core.triggerInput();
376376
};
377377
domImage.src = img;
378378
} else {
@@ -406,7 +406,7 @@
406406
}
407407
}
408408

409-
this.$el.trigger('input');
409+
this.core.triggerInput();
410410

411411
return data.context;
412412
};
@@ -508,7 +508,7 @@
508508
this.core.moveCaret($empty);
509509
}
510510

511-
this.$el.trigger('input');
511+
this.core.triggerInput();
512512
}
513513
}
514514
};
@@ -622,7 +622,7 @@
622622

623623
this.core.hideButtons();
624624

625-
this.$el.trigger('input');
625+
this.core.triggerInput();
626626
};
627627

628628
/**
@@ -642,7 +642,7 @@
642642

643643
this.core.hideButtons();
644644

645-
this.$el.trigger('input');
645+
this.core.triggerInput();
646646
};
647647

648648
/**

0 commit comments

Comments
 (0)