Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bubble display events through the editor

  • Loading branch information...
commit 4464d012b028fdca9baee3f1a1d45fc4ea47d608 1 parent f48b62e
@rhburrows authored
View
7 src/display.js
@@ -290,5 +290,12 @@
}
};
+ Display.Events = [
+ 's2e:mousedown',
+ 's2e:mousemove',
+ 's2e:mouseup',
+ 's2e:click'
+ ];
+
$.fn.s2e.Display = Display;
})(jQuery);
View
6 src/editor.js
@@ -13,6 +13,12 @@
movePoint(this, -initialText.length);
var edit = this;
+
+ var displayEvents = $.fn.s2e.Display.Events.join(' ');
+ $(display).bind(displayEvents, function(ev){
+ $(edit).trigger(ev);
+ });
+
$.each(extraInitializers, function(_, i){
i.call(edit);
});
View
7 src/extras/selection.js
@@ -99,21 +99,20 @@
}
});
- var d = this.display;
- $(d).bind('s2e:mousedown', function(ev){
+ $(e).bind('s2e:mousedown', function(ev){
if (!e.selectionActive) {
e.movePointTo(ev.position);
e.toggleSelection();
}
});
- $(d).bind('s2e:mousemove', function(ev){
+ $(e).bind('s2e:mousemove', function(ev){
if (e.selectionActive) {
e.movePointTo(ev.position);
}
});
- $(d).bind('s2e:mouseup', function(ev){
+ $(e).bind('s2e:mouseup', function(ev){
if (e.selectionActive) {
e.toggleSelection();
}
View
13 test/editorTest.js
@@ -1,10 +1,12 @@
module("editor", {
setup: function() {
- editor = new $.fn.s2e.Editor("");
+ display = {};
+ editor = new $.fn.s2e.Editor("", display);
}
});
var editor;
+var display;
function countEvent(event) {
$(editor).bind(event, function(){
@@ -455,4 +457,13 @@ test("slice", function(){
equals(editor.slice(1,4), "ell",
"It works if the point is in the middle of the slice");
+});
+
+test("display events", function(){
+ $(editor).bind('s2e:click', function(e){
+ ok("Display events are bubbled through the editor");
+ });
+
+ expect(1);
+ $(display).trigger('s2e:click');
});

0 comments on commit 4464d01

Please sign in to comment.
Something went wrong with that request. Please try again.