Skip to content

Commit

Permalink
Hide the characterReader inside the inputManager
Browse files Browse the repository at this point in the history
Nothing outside of the inputManager should know that its using a
hidden field to read the keys. This is still awkward, but its a step
in the right direcion
  • Loading branch information
rhburrows committed Jun 28, 2011
1 parent 8c8fb7d commit 6789e3e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
display.paint(editor);

$(display).bind('s2e:click', function(ev) {
$(inputManager.characterReader).focus();
inputManager.focus();
editor.movePointTo(ev.position);
});

Expand All @@ -58,12 +58,7 @@
textarea.trigger(extendEvent(e, editor, display));
});

$(inputManager.characterReader).keydown(inputManager.handler(editor));
$(inputManager.characterReader).css({
position: 'absolute',
left: '-300px',
top: '-300px'
});
inputManager.keydown(inputManager.handler(editor));

return editor;
});
Expand Down
13 changes: 13 additions & 0 deletions src/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
function InputManager() {
this.characterReader = document.createElement('input');
$(this.characterReader).attr('type', 'text');
$(this.characterReader).css({
position : 'absolute',
left : '-300px',
top : '-300px'
});
this.bindings = {};
}

Expand Down Expand Up @@ -121,6 +126,14 @@
return true;
}
};
},

focus : function() {
$(this.characterReader).focus();
},

keydown : function(f) {
$(this.characterReader).keydown(f);
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/inputTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module("input", {
setup: function() {
var nullEditor = {};
inputManager = new $.fn.s2e.config.InputManager(nullEditor);
inputManager = new $.fn.s2e.config.InputManager();
inputHandler = inputManager.handler();
}
});
Expand Down

0 comments on commit 6789e3e

Please sign in to comment.