From 8acdde3e87f8cabd179a068c54fe5b78fa38e40d Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 5 Apr 2012 22:54:53 -0700 Subject: - using Montage TextField component to handle any edits like keyup, paste, cut. - optimized Enter and Esc key handling Signed-off-by: Ananya Sen --- .../file-input-field.reel/file-input-field.js | 37 ++++++++++------------ 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'js/io/ui/file-picker/file-input-field.reel/file-input-field.js') diff --git a/js/io/ui/file-picker/file-input-field.reel/file-input-field.js b/js/io/ui/file-picker/file-input-field.reel/file-input-field.js index 0f66468a..9e77759f 100755 --- a/js/io/ui/file-picker/file-input-field.reel/file-input-field.js +++ b/js/io/ui/file-picker/file-input-field.reel/file-input-field.js @@ -14,14 +14,10 @@ var FileInputField = exports.FileInputField = Montage.create(Component, { value: function() { var that = this; this.findDirectory.identifier = "findDirectory"; - this.findDirectory.addEventListener("click", this, false); - - this.eventManager.addEventListener("pickerSelectionsDone", function(evt){that.handleFileInputPickerSelectionsDone(evt);}, false); - - this.newFileDirectory.addEventListener("keyup", function(evt){that.handleNewFileDirectoryOnkeyup(evt);}, false); - this.newFileDirectory.addEventListener("paste", this, false); - this.newFileDirectory.addEventListener("search", this, false); + this.eventManager.addEventListener("pickerSelectionsDone", this.handleFileInputPickerSelectionsDone, false); + this.addEventListener("change@newFileDirectory.value", this.handleNewFileDirectoryChange, false); + this.newFileDirectory.element.addEventListener("keyup", this, false); } }, @@ -65,15 +61,7 @@ var FileInputField = exports.FileInputField = Montage.create(Component, { } }, - handlePaste:{ - value:function(evt){ - evt.preventDefault(); - evt.target.value = evt.clipboardData.getData("Text"); - this.handleNewFileDirectoryOnkeyup(evt); - } - }, - - handleNewFileDirectoryOnkeyup:{ + handleNewFileDirectoryChange:{ value:function(evt){ var newFileDirectorySetEvent = document.createEvent("Events"); newFileDirectorySetEvent.initEvent("newFileDirectorySet", false, false); @@ -83,9 +71,18 @@ var FileInputField = exports.FileInputField = Montage.create(Component, { } }, - handleSearch:{ - value:function(evt){ - this.handleNewFileDirectoryOnkeyup(evt); + + handleKeyup:{ + value: function(evt){ + if(evt.keyCode === 13){ + var enterKeyupEvent = document.createEvent("Events"); + enterKeyupEvent.initEvent("enterKey", false, false); + this.eventManager.dispatchEvent(enterKeyupEvent); + }else if(evt.keyCode === 27){ + var escKeyupEvent = document.createEvent("Events"); + escKeyupEvent.initEvent("escKey", false, false); + this.eventManager.dispatchEvent(escKeyupEvent); + } } }, @@ -110,7 +107,7 @@ var FileInputField = exports.FileInputField = Montage.create(Component, { if(!!obj && obj.uri && obj.uri.length > 0){ selectedUri = obj.uri[0]; this.newFileDirectory.value = selectedUri; - this.newFileDirectory.focus(); + this.newFileDirectory.element.focus(); var newFileDirectorySetEvent = document.createEvent("Events"); newFileDirectorySetEvent.initEvent("newFileDirectorySet", false, false); newFileDirectorySetEvent.newFileDirectory = this.newFileDirectory.value; -- cgit v1.2.3