diff options
author | Valerio Virgillito | 2012-02-23 01:55:14 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-23 01:55:14 -0800 |
commit | 64a971f63333d74ca89690892a52948b3bd4283a (patch) | |
tree | 61bac34de22852efd2b9b8880f62210685b16297 /js/controllers | |
parent | aaa8d05cc3cfd94322d356e265b94b0abb9f6305 (diff) | |
parent | d264092596ba697cd04738566184270dc608be63 (diff) | |
download | ninja-64a971f63333d74ca89690892a52948b3bd4283a.tar.gz |
Merge branch 'FileIO' of github.com:joseeight/ninja-internal into file-io
Diffstat (limited to 'js/controllers')
-rwxr-xr-x | js/controllers/document-controller.js | 57 | ||||
-rwxr-xr-x | js/controllers/styles-controller.js | 44 |
2 files changed, 64 insertions, 37 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index fa611de4..3a77ed5f 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js | |||
@@ -58,6 +58,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
58 | this.eventManager.addEventListener("executeFileOpen", this, false); | 58 | this.eventManager.addEventListener("executeFileOpen", this, false); |
59 | this.eventManager.addEventListener("executeNewFile", this, false); | 59 | this.eventManager.addEventListener("executeNewFile", this, false); |
60 | this.eventManager.addEventListener("executeSave", this, false); | 60 | this.eventManager.addEventListener("executeSave", this, false); |
61 | this.eventManager.addEventListener("executeSaveAs", this, false); | ||
62 | this.eventManager.addEventListener("executeSaveAll", this, false); | ||
61 | 63 | ||
62 | this.eventManager.addEventListener("recordStyleChanged", this, false); | 64 | this.eventManager.addEventListener("recordStyleChanged", this, false); |
63 | 65 | ||
@@ -84,9 +86,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
84 | // | 86 | // |
85 | handleAppLoaded: { | 87 | handleAppLoaded: { |
86 | value: function() { | 88 | value: function() { |
87 | //Adding an intercept to resources loaded to ensure user assets load from cloud simulator | 89 | //Checking for app not to be loaded via http/https to add app only listener |
88 | if (window.chrome.app.isInstalled) { | 90 | if (window.location.protocol !== 'http:' && window.location.protocol !== 'https:') { |
89 | chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: ["<all_urls>"]}, ["blocking"]); | 91 | //Adding an intercept to resources loaded to ensure user assets load from cloud simulator |
92 | chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: ["<all_urls>"]}, ["blocking"]); | ||
90 | } | 93 | } |
91 | } | 94 | } |
92 | }, | 95 | }, |
@@ -102,33 +105,57 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
102 | handleExecuteFileOpen: { | 105 | handleExecuteFileOpen: { |
103 | value: function(event) { | 106 | value: function(event) { |
104 | var pickerSettings = event._event.settings || {}; | 107 | var pickerSettings = event._event.settings || {}; |
105 | pickerSettings.callback = this.openFileWithURI.bind(this); | 108 | if (this.application.ninja.coreIoApi.cloudAvailable()) { |
106 | pickerSettings.pickerMode = "read"; | 109 | pickerSettings.callback = this.openFileWithURI.bind(this); |
107 | pickerSettings.inFileMode = true; | 110 | pickerSettings.pickerMode = "read"; |
108 | this.application.ninja.filePickerController.showFilePicker(pickerSettings); | 111 | pickerSettings.inFileMode = true; |
112 | this.application.ninja.filePickerController.showFilePicker(pickerSettings); | ||
113 | } | ||
109 | } | 114 | } |
110 | }, | 115 | }, |
111 | 116 | ||
112 | handleExecuteNewFile: { | 117 | handleExecuteNewFile: { |
113 | value: function(event) { | 118 | value: function(event) { |
114 | var newFileSettings = event._event.settings || {}; | 119 | var newFileSettings = event._event.settings || {}; |
115 | newFileSettings.callback = this.createNewFile.bind(this); | 120 | if (this.application.ninja.coreIoApi.cloudAvailable()) { |
116 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | 121 | newFileSettings.callback = this.createNewFile.bind(this); |
122 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | ||
123 | } | ||
117 | } | 124 | } |
118 | }, | 125 | }, |
119 | |||
120 | |||
121 | //////////////////////////////////////////////////////////////////// | 126 | //////////////////////////////////////////////////////////////////// |
122 | //TODO: Check for appropiate structures | 127 | //TODO: Check for appropiate structures |
123 | handleExecuteSave: { | 128 | handleExecuteSave: { |
124 | value: function(event) { | 129 | value: function(event) { |
125 | if(!!this.activeDocument){ | 130 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ |
126 | //Text and HTML document classes should return the same save object for fileSave | 131 | //Text and HTML document classes should return the same save object for fileSave |
127 | this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); | 132 | this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); |
133 | } | ||
128 | } | 134 | } |
135 | }, | ||
136 | //////////////////////////////////////////////////////////////////// | ||
137 | //TODO: Check for appropiate structures | ||
138 | handleExecuteSaveAll: { | ||
139 | value: function(event) { | ||
140 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | ||
141 | //Text and HTML document classes should return the same save object for fileSave | ||
142 | this.application.ninja.ioMediator.fileSave(this.activeDocument.saveAll(), this.fileSaveResult.bind(this)); | ||
143 | } | ||
129 | } | 144 | } |
130 | }, | 145 | }, |
131 | //////////////////////////////////////////////////////////////////// | 146 | //////////////////////////////////////////////////////////////////// |
147 | handleExecuteSaveAs: { | ||
148 | value: function(event) { | ||
149 | var saveAsSettings = event._event.settings || {}; | ||
150 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | ||
151 | saveAsSettings.fileName = this.activeDocument.name; | ||
152 | saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/")); | ||
153 | //add callback | ||
154 | this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); | ||
155 | } | ||
156 | } | ||
157 | }, | ||
158 | |||
132 | // | 159 | // |
133 | fileSaveResult: { | 160 | fileSaveResult: { |
134 | value: function (result) { | 161 | value: function (result) { |
@@ -287,7 +314,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
287 | if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab | 314 | if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab |
288 | var nextDocumentIndex = -1 ; | 315 | var nextDocumentIndex = -1 ; |
289 | if((this._documents.length > 0) && (closeDocumentIndex === 0)){ | 316 | if((this._documents.length > 0) && (closeDocumentIndex === 0)){ |
290 | nextDocumentIndex = 1; | 317 | nextDocumentIndex = 0; |
291 | }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ | 318 | }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ |
292 | nextDocumentIndex = closeDocumentIndex - 1; | 319 | nextDocumentIndex = closeDocumentIndex - 1; |
293 | } | 320 | } |
diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 885d710f..662816f5 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js | |||
@@ -317,7 +317,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { | |||
317 | isInlineStyle : true, | 317 | isInlineStyle : true, |
318 | style : element.style | 318 | style : element.style |
319 | }; | 319 | }; |
320 | 320 | ||
321 | ///// Now splice it into the matched rules | 321 | ///// Now splice it into the matched rules |
322 | ///// By inserting the inline style at the beginning, | 322 | ///// By inserting the inline style at the beginning, |
323 | ///// we keep the correct order of specificity | 323 | ///// we keep the correct order of specificity |
@@ -572,37 +572,36 @@ var stylesController = exports.StylesController = Montage.create(Component, { | |||
572 | win = element.ownerDocument.defaultView, | 572 | win = element.ownerDocument.defaultView, |
573 | self = this; | 573 | self = this; |
574 | 574 | ||
575 | if(!win) { | ||
576 | return null; | ||
577 | } | ||
578 | |||
579 | if(!omitPseudos) { | 575 | if(!omitPseudos) { |
580 | pseudos.concat(['link', 'visited', 'active', 'hover', 'focus', 'first-letter', | 576 | pseudos.concat(['link', 'visited', 'active', 'hover', 'focus', 'first-letter', |
581 | 'first-line', 'first-child', 'before', 'after', 'lang', 'target']); | 577 | 'first-line', 'first-child', 'before', 'after', 'lang', 'target']); |
582 | } | 578 | } |
583 | 579 | ||
584 | pseudos.forEach(function(pseudo) { | 580 | try { |
585 | rules = rules.concat(nj.toArray(win.getMatchedCSSRules(element, pseudo)).filter(function(rule) { | 581 | pseudos.forEach(function(pseudo) { |
586 | //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, | 582 | rules = rules.concat(nj.toArray(win.getMatchedCSSRules(element, pseudo)).filter(function(rule) { |
587 | //// or only use rules for other stylesheets | 583 | //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, |
588 | 584 | //// or only use rules for other stylesheets | |
589 | var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null, | ||
590 | isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID; | ||
591 | 585 | ||
592 | ///// filter out (return false) depending on flag | 586 | var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null, |
593 | if(useStageStyleSheet && !isStageStyleSheet) { return false; } | 587 | isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID; |
594 | if(!useStageStyleSheet && isStageStyleSheet) { return false; } | ||
595 | 588 | ||
596 | ///// Non-filter code - just assigning specificity to the rule | 589 | ///// filter out (return false) depending on flag |
597 | if(!rule[this.CONST.SPECIFICITY_KEY]) { | 590 | if(useStageStyleSheet && !isStageStyleSheet) { return false; } |
598 | rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); | 591 | if(!useStageStyleSheet && isStageStyleSheet) { return false; } |
599 | } | ||
600 | 592 | ||
601 | return true; | 593 | ///// Non-filter code - just assigning specificity to the rule |
594 | if(!rule[this.CONST.SPECIFICITY_KEY]) { | ||
595 | rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); | ||
596 | } | ||
602 | 597 | ||
603 | }, this)); | 598 | return true; |
604 | }, this); | ||
605 | 599 | ||
600 | }, this)); | ||
601 | }, this); | ||
602 | } catch(ERROR) { | ||
603 | console.warn('StylesController::getMatchingRules - Un-attached element queried.'); | ||
604 | } | ||
606 | ///// Function for sorting by specificity values | 605 | ///// Function for sorting by specificity values |
607 | function sorter(ruleA, ruleB) { | 606 | function sorter(ruleA, ruleB) { |
608 | var a, b, order, sheetAIndex, sheetBIndex, ruleAIndex, ruleBIndex; | 607 | var a, b, order, sheetAIndex, sheetBIndex, ruleAIndex, ruleBIndex; |
@@ -981,6 +980,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { | |||
981 | ///// Pass "true" to method to return an override object, which | 980 | ///// Pass "true" to method to return an override object, which |
982 | ///// has the rule to override, and whether the !important flag is needed | 981 | ///// has the rule to override, and whether the !important flag is needed |
983 | dominantRule = this.getDominantRuleForElement(element, property, true, isStageElement); | 982 | dominantRule = this.getDominantRuleForElement(element, property, true, isStageElement); |
983 | |||
984 | } | 984 | } |
985 | 985 | ||
986 | ///// Did we find a dominant rule? | 986 | ///// Did we find a dominant rule? |