From 113ed223e9848d9838e574c67720d524653e704c Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 8 Jun 2012 17:09:24 -0700 Subject: - fixed multiple paste displacement Signed-off-by: Ananya Sen --- js/mediators/keyboard-mediator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/mediators') diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js index 4fd4bd4c..73cea6de 100755 --- a/js/mediators/keyboard-mediator.js +++ b/js/mediators/keyboard-mediator.js @@ -109,7 +109,7 @@ exports.KeyboardMediator = Montage.create(Component, { // Shortcut for Selection Tool is V - if(evt.keyCode === Keyboard.V) { + if((evt.keyCode === Keyboard.V) && !(evt.ctrlKey || evt.metaKey)) { evt.preventDefault(); this.application.ninja.handleSelectTool({ "detail": this.application.ninja.toolsData.defaultToolsData[this.application.ninja.toolsData.selectionToolIndex] }); return; -- cgit v1.2.3 From 8e5cfac34edc9772ba89e0206890c23afa0a6fcc Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Wed, 13 Jun 2012 16:36:39 -0700 Subject: - Eric Guzman's styles-controller fix for relatively positioned Signed-off-by: Ananya Sen --- js/mediators/io-mediator.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'js/mediators') diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index c487fef5..c9ea0468 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -205,9 +205,15 @@ exports.IoMediator = Montage.create(Component, { value: function (file, callback) { //TODO: Implement Delete functionality } - } + }, //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// + createFileFromBinary:{ + enumerable: false, + value: function(blob, filename){ + + } + } }); //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// \ No newline at end of file -- cgit v1.2.3 From 8db9e73ca68c006769af3997034959f6b7008add Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 21 Jun 2012 11:02:55 -0700 Subject: - added io api to generate file from binary - refactoring and cleanup Signed-off-by: Ananya Sen --- js/mediators/drag-drop-mediator.js | 108 ++++++++++++++----------------------- js/mediators/io-mediator.js | 53 +++++++++++++++++- 2 files changed, 93 insertions(+), 68 deletions(-) (limited to 'js/mediators') diff --git a/js/mediators/drag-drop-mediator.js b/js/mediators/drag-drop-mediator.js index 14bdb0eb..049424f3 100755 --- a/js/mediators/drag-drop-mediator.js +++ b/js/mediators/drag-drop-mediator.js @@ -57,9 +57,7 @@ exports.DragDropMediator = Montage.create(Component, { handleDropEvent: { value: function(e){ // - var i, files = e.dataTransfer.files, position = {x: e.offsetX, y: e.offsetY}, - rootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])), - rootUri = this.application.ninja.documentController.documentHackReference.root; + var i, files = e.dataTransfer.files, position = {x: e.offsetX, y: e.offsetY}, self = this; var xferString = e.dataTransfer.getData("text/plain"); if(xferString) { @@ -74,70 +72,8 @@ exports.DragDropMediator = Montage.create(Component, { // for (i=0; files[i]; i++) { if (files[i].type.indexOf('image') !== -1) { - var reader = new FileReader(), file = reader.readAsArrayBuffer(files[i]); - reader.fileName = files[i].name, reader.fileType = files[i].type, reader.rootUrl = rootUrl, reader.rootUri = rootUri, reader.filePosition = position; - reader.onload = function (e) { - // - var url, uri, dir, save, counter, tempName, element, rules, fileName; - if (this.application.ninja.coreIoApi.directoryExists({uri: e.currentTarget.rootUri+'images'}).status === 204) { - uri = e.currentTarget.rootUri+'images'; - url = e.currentTarget.rootUrl+'images'; - } else if (this.application.ninja.coreIoApi.directoryExists({uri: e.currentTarget.rootUri+'img'}).status === 204) { - uri = e.currentTarget.rootUri+'img'; - url = e.currentTarget.rootUrl+'img'; - } else { - dir = this.application.ninja.coreIoApi.createDirectory({uri: e.currentTarget.rootUri+'images'}); - if (dir.success && dir.status === 201) { - uri = e.currentTarget.rootUri+'images'; - url = e.currentTarget.rootUrl+'images'; - } else { - //TODO: HANDLE ERROR ON CREATING FOLDER - } - } - // - if (this.application.ninja.coreIoApi.fileExists({uri: uri+'/'+e.currentTarget.fileName}).status === 404) { - save = this.application.ninja.coreIoApi.createFile({uri: uri+'/'+e.currentTarget.fileName, contents: e.currentTarget.result, contentType: e.currentTarget.fileType}); - fileName = e.currentTarget.fileName; - } else { - counter = 1; - tempName = e.currentTarget.fileName.split('.'+(e.currentTarget.fileName.split('.')[e.currentTarget.fileName.split('.').length-1]))[0]; - tempName += '_'+counter+'.'+(e.currentTarget.fileName.split('.')[e.currentTarget.fileName.split('.').length-1]); - while (this.application.ninja.coreIoApi.fileExists({uri: uri+'/'+tempName}).status !== 404) { - counter++; - tempName = e.currentTarget.fileName.split('.'+(e.currentTarget.fileName.split('.')[e.currentTarget.fileName.split('.').length-1]))[0]; - tempName += '_'+counter+'.'+(e.currentTarget.fileName.split('.')[e.currentTarget.fileName.split('.').length-1]); - } - save = this.application.ninja.coreIoApi.createFile({uri: uri+'/'+tempName, contents: e.currentTarget.result, contentType: e.currentTarget.fileType}); - fileName = tempName; - } - if (save && save.success && save.status === 201) { - var self = this; - // - if (e.currentTarget.fileType.indexOf('svg') !== -1) { - element = NJUtils.make('embed', null, this.application.ninja.currentDocument);//TODO: Verify this is proper - element.type = 'image/svg+xml'; - element.src = url+'/'+fileName; - } else { - element = NJUtils.make('image', null, this.application.ninja.currentDocument); - element.src = url+'/'+fileName; - } - //Adding element once it is loaded - element.onload = function () { - element.onload = null; - self.application.ninja.elementMediator.addElements(element, rules, true); - }; - //Setting rules of element - rules = { - 'position': 'absolute', - 'top' : (parseInt(e.currentTarget.filePosition.y) - parseInt(this.application.ninja.stage.userContentTop)) + 'px', - 'left' : (parseInt(e.currentTarget.filePosition.x) - parseInt(this.application.ninja.stage.userContentLeft)) + 'px' - }; - // - self.application.ninja.elementMediator.addElements(element, rules, false); - } else { - //TODO: HANDLE ERROR ON SAVING FILE TO BE ADDED AS ELEMENT - } - }.bind(this); + this.application.ninja.ioMediator.createFileFromBinary(files[i], {"addFileToStage" : self.addImageElement.bind(self), "position": position}); + } else { //TODO: NOT AN IMAGE, HANDLE SPECIAL CASE } @@ -145,5 +81,43 @@ exports.DragDropMediator = Montage.create(Component, { //Not sure why return value should be, seemed as false to work return false; } + }, + + addImageElement:{ + value: function(status){ + var save = status.save, + fileName = status.filename, + url = status.url, + element, rules, self = this, + fileType = status.fileType, + filePosition = status.filePosition ? status.filePosition : {x: "100", y: "100"}; + + if (save && save.success && save.status === 201) { + // + if (fileType.indexOf('svg') !== -1) { + element = NJUtils.make('embed', null, this.application.ninja.currentDocument);//TODO: Verify this is proper + element.type = 'image/svg+xml'; + element.src = url+'/'+fileName; + } else { + element = NJUtils.make('image', null, this.application.ninja.currentDocument); + element.src = url+'/'+fileName; + } + //Adding element once it is loaded + element.onload = function () { + element.onload = null; + self.application.ninja.elementMediator.addElements(element, rules, true); + }; + //Setting rules of element + rules = { + 'position': 'absolute', + 'top' : (parseInt(filePosition.y) - parseInt(this.application.ninja.stage.userContentTop)) + 'px', + 'left' : (parseInt(filePosition.x) - parseInt(this.application.ninja.stage.userContentLeft)) + 'px' + }; + // + self.application.ninja.elementMediator.addElements(element, rules, false); + } else { + //TODO: HANDLE ERROR ON SAVING FILE TO BE ADDED AS ELEMENT + } + } } }); diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index c9ea0468..c6e7d960 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -210,7 +210,58 @@ exports.IoMediator = Montage.create(Component, { //////////////////////////////////////////////////////////////////// createFileFromBinary:{ enumerable: false, - value: function(blob, filename){ + value: function(blob, callback){ + var reader = new FileReader(), file = reader.readAsArrayBuffer(blob), url, uri, dir, save, counter, tempName, element, rules, fileName, fileNameOverride, + rootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])), + rootUri = this.application.ninja.documentController.documentHackReference.root; + + reader.fileName = blob.name, reader.fileType = blob.type, reader.rootUrl = rootUrl, reader.rootUri = rootUri; + if(callback && callback.position){reader.filePosition = callback.position;} + + reader.onload = function (e) { + if(e.currentTarget.fileType.indexOf('image') !== -1 ){ + if (this.application.ninja.coreIoApi.directoryExists({uri: e.currentTarget.rootUri+'images'}).status === 204) { + uri = e.currentTarget.rootUri+'images'; + url = e.currentTarget.rootUrl+'images'; + } else if (this.application.ninja.coreIoApi.directoryExists({uri: e.currentTarget.rootUri+'img'}).status === 204) { + uri = e.currentTarget.rootUri+'img'; + url = e.currentTarget.rootUrl+'img'; + } else { + dir = this.application.ninja.coreIoApi.createDirectory({uri: e.currentTarget.rootUri+'images'}); + if (dir.success && dir.status === 201) { + uri = e.currentTarget.rootUri+'images'; + url = e.currentTarget.rootUrl+'images'; + } else { + //TODO: HANDLE ERROR ON CREATING FOLDER + } + } + //fileName is undefined while pasting image from clipboard + fileNameOverride = e.currentTarget.fileName ? e.currentTarget.fileName : ("image." + e.currentTarget.fileType.substring((e.currentTarget.fileType.indexOf("/")+1), e.currentTarget.fileType.length));//like image.png + + if (this.application.ninja.coreIoApi.fileExists({uri: uri+'/'+fileNameOverride}).status === 404) { + save = this.application.ninja.coreIoApi.createFile({uri: uri+'/'+fileNameOverride, contents: e.currentTarget.result, contentType: e.currentTarget.fileType}); + fileName = fileNameOverride; + } else { + counter = 1; + tempName = fileNameOverride.split('.'+(fileNameOverride.split('.')[fileNameOverride.split('.').length-1]))[0]; + tempName += '_'+counter+'.'+(fileNameOverride.split('.')[fileNameOverride.split('.').length-1]); + while (this.application.ninja.coreIoApi.fileExists({uri: uri+'/'+tempName}).status !== 404) { + counter++; + tempName = fileNameOverride.split('.'+(fileNameOverride.split('.')[fileNameOverride.split('.').length-1]))[0]; + tempName += '_'+counter+'.'+(fileNameOverride.split('.')[fileNameOverride.split('.').length-1]); + } + save = this.application.ninja.coreIoApi.createFile({uri: uri+'/'+tempName, contents: e.currentTarget.result, contentType: e.currentTarget.fileType}); + fileName = tempName; + } + + if(callback && callback.addFileToStage && (typeof callback.addFileToStage === "function")){ + callback.addFileToStage({"save": save, "url": url, "filename": fileName, "filePosition": e.currentTarget.filePosition, "fileType":e.currentTarget.fileType}); + } + + }else{ + //TODO: HANDLE NOT AN IMAGE + } + }.bind(this); } } -- cgit v1.2.3 From 04f206173530b6efde16b934b1f959b255d18441 Mon Sep 17 00:00:00 2001 From: Jonathan Duran Date: Fri, 22 Jun 2012 01:33:58 -0700 Subject: FIx - can't delete keyframes F5 now deletes the selected keyframe Signed-off-by: Jonathan Duran --- js/mediators/keyboard-mediator.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'js/mediators') diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js index cce053bc..f0afff13 100755 --- a/js/mediators/keyboard-mediator.js +++ b/js/mediators/keyboard-mediator.js @@ -50,6 +50,7 @@ var Keyboard = exports.Keyboard = { X:88, Y:89, Z:90, + F5:116, F6:117, PLUS:187, MINUS:189 @@ -218,7 +219,11 @@ exports.KeyboardMediator = Montage.create(Component, { // F6 keyboard shortcut to add a keyframe to the timeline if (evt.keyCode == Keyboard.F6) { - this.application.ninja.timeline.handleKeyframeShortcut(); + this.application.ninja.timeline.handleKeyframeShortcut("insert"); + return; + } + if (evt.keyCode == Keyboard.F5) { + this.application.ninja.timeline.handleKeyframeShortcut("remove"); return; } -- cgit v1.2.3