diff options
author | Jose Antonio Marquez | 2012-05-08 17:33:13 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-05-08 17:33:13 -0700 |
commit | a1e8540f5656e62db6a89f3af7829be6b259b7ed (patch) | |
tree | 1b8a445cf5c145a9622813da88555596640e7e37 /js/document | |
parent | 4504972c1f3b9bf1d02a4484a07a8a85cf9ccee2 (diff) | |
download | ninja-a1e8540f5656e62db6a89f3af7829be6b259b7ed.tar.gz |
Adding SAVE for I/O
Adding save functionality to new template. Need to implement user UI for prompts and also clean up...
Diffstat (limited to 'js/document')
-rwxr-xr-x | js/document/models/base.js | 102 | ||||
-rwxr-xr-x | js/document/templates/montage-web/index.html | 17 | ||||
-rwxr-xr-x | js/document/views/design.js | 7 |
3 files changed, 105 insertions, 21 deletions
diff --git a/js/document/models/base.js b/js/document/models/base.js index 5667fb24..2bbbe501 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js | |||
@@ -76,39 +76,104 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
76 | //TODO: Add API to allow other browser support | 76 | //TODO: Add API to allow other browser support |
77 | browserPreview: { | 77 | browserPreview: { |
78 | value: function (browser) { | 78 | value: function (browser) { |
79 | 79 | //Generating URL for document | |
80 | //TODO: Add file save before previewing | 80 | var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]; |
81 | 81 | //TODO: Add logic to prompt user to save (all) before preview | |
82 | //Currently only supporting current browser (Chrome, obviously) | 82 | this.saveAll(function (result) { |
83 | switch (browser) { | 83 | //Currently only supporting current browser (Chrome, obviously) |
84 | case 'chrome': | 84 | switch (this.browser) { |
85 | window.open(this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]); | 85 | case 'chrome': |
86 | break; | 86 | window.open(this.url); |
87 | default: | 87 | break; |
88 | window.open(this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]); | 88 | default: |
89 | break; | 89 | window.open(this.url); |
90 | } | 90 | break; |
91 | } | ||
92 | }.bind({browser: browser, url: url})); | ||
91 | } | 93 | } |
92 | }, | 94 | }, |
93 | //////////////////////////////////////////////////////////////////// | 95 | //////////////////////////////////////////////////////////////////// |
94 | // | 96 | // |
97 | getStyleSheets: { | ||
98 | value: function () { | ||
99 | // | ||
100 | var styles = []; | ||
101 | // | ||
102 | for (var k in this.views.design.iframe.contentWindow.document.styleSheets) { | ||
103 | if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode && this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute) { | ||
104 | if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute('data-ninja-template') === null) { | ||
105 | styles.push(this.views.design.iframe.contentWindow.document.styleSheets[k]); | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | // | ||
110 | return styles; | ||
111 | } | ||
112 | }, | ||
113 | //////////////////////////////////////////////////////////////////// | ||
114 | // | ||
95 | save: { | 115 | save: { |
96 | value: function () { | 116 | value: function (callback) { |
97 | // | 117 | // |
118 | if (this.currentView === this.views.design) { | ||
119 | // | ||
120 | this.application.ninja.ioMediator.fileSave({ | ||
121 | mode: 'html', | ||
122 | file: this.file, | ||
123 | webgl: this.webGlHelper.glData, | ||
124 | styles: this.getStyleSheets(), | ||
125 | document: this.views.design.iframe.contentWindow.document, | ||
126 | head: this.views.design.iframe.contentWindow.document.head, | ||
127 | body: this.views.design.iframe.contentWindow.document.body | ||
128 | }, callback.bind(this)); | ||
129 | } else { | ||
130 | //TODO: Add logic to save code view data | ||
131 | } | ||
132 | // | ||
133 | if (this.needsSave) { | ||
134 | //Save | ||
135 | } else { | ||
136 | //Ignore command | ||
137 | } | ||
98 | } | 138 | } |
99 | }, | 139 | }, |
100 | //////////////////////////////////////////////////////////////////// | 140 | //////////////////////////////////////////////////////////////////// |
101 | // | 141 | // |
102 | saveAs: { | 142 | saveAll: { |
103 | value: function () { | 143 | value: function (callback) { |
144 | // | ||
145 | if (this.currentView === this.views.design) { | ||
146 | // | ||
147 | this.application.ninja.ioMediator.fileSave({ | ||
148 | mode: 'html', | ||
149 | file: this.file, | ||
150 | webgl: this.webGlHelper.glData, | ||
151 | css: this.getStyleSheets(), | ||
152 | document: this.views.design.iframe.contentWindow.document, | ||
153 | head: this.views.design.iframe.contentWindow.document.head, | ||
154 | body: this.views.design.iframe.contentWindow.document.body | ||
155 | }, callback.bind(this)); | ||
156 | } else { | ||
157 | //TODO: Add logic to save code view data | ||
158 | } | ||
104 | // | 159 | // |
160 | if (this.needsSave) { | ||
161 | //Save | ||
162 | } else { | ||
163 | //Ignore command | ||
164 | } | ||
105 | } | 165 | } |
106 | }, | 166 | }, |
107 | //////////////////////////////////////////////////////////////////// | 167 | //////////////////////////////////////////////////////////////////// |
108 | // | 168 | // |
109 | saveAll: { | 169 | saveAs: { |
110 | value: function () { | 170 | value: function () { |
111 | // | 171 | // |
172 | if (this.needsSave) { | ||
173 | //Save current file on memory | ||
174 | } else { | ||
175 | //Copy file from disk | ||
176 | } | ||
112 | } | 177 | } |
113 | }, | 178 | }, |
114 | //////////////////////////////////////////////////////////////////// | 179 | //////////////////////////////////////////////////////////////////// |
@@ -116,6 +181,11 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
116 | close: { | 181 | close: { |
117 | value: function () { | 182 | value: function () { |
118 | // | 183 | // |
184 | if (this.needsSave) { | ||
185 | //Prompt user to save of lose data | ||
186 | } else { | ||
187 | //Close file | ||
188 | } | ||
119 | } | 189 | } |
120 | } | 190 | } |
121 | //////////////////////////////////////////////////////////////////// | 191 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/document/templates/montage-web/index.html b/js/document/templates/montage-web/index.html index 47964ae4..3d550768 100755 --- a/js/document/templates/montage-web/index.html +++ b/js/document/templates/montage-web/index.html | |||
@@ -5,13 +5,20 @@ | |||
5 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 5 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
6 | </copyright> --> | 6 | </copyright> --> |
7 | 7 | ||
8 | |||
9 | <!-- | ||
10 | NOTE(s): | ||
11 | All elements in the head of the document to be exclude from I/O | ||
12 | must set the 'data-ninja-template' | ||
13 | data-ninja-template="true" | ||
14 | --> | ||
8 | <html> | 15 | <html> |
9 | 16 | ||
10 | <head> | 17 | <head> |
11 | 18 | ||
12 | <title>Ninja Prototype</title> | 19 | <title data-ninja-template="true">Ninja Prototype</title> |
13 | 20 | ||
14 | <style type="text/css" id="nj-stage-stylesheet"> | 21 | <style type="text/css" id="nj-stage-stylesheet" data-ninja-template="true"> |
15 | * { | 22 | * { |
16 | -webkit-transition-duration: 0s !important; | 23 | -webkit-transition-duration: 0s !important; |
17 | -webkit-animation-duration: 0s !important; | 24 | -webkit-animation-duration: 0s !important; |
@@ -44,15 +51,15 @@ | |||
44 | } | 51 | } |
45 | </style> | 52 | </style> |
46 | 53 | ||
47 | <script type="text/javascript" data-package="." src="../../../../node_modules/montage/montage.js"></script> | 54 | <script type="text/javascript" data-package="." src="../../../../node_modules/montage/montage.js" data-ninja-template="true"></script> |
48 | 55 | ||
49 | <script type="text/javascript"> | 56 | <script type="text/javascript" data-ninja-template="true"> |
50 | function getElement(x,y) { | 57 | function getElement(x,y) { |
51 | return document.elementFromPoint(x,y); | 58 | return document.elementFromPoint(x,y); |
52 | } | 59 | } |
53 | </script> | 60 | </script> |
54 | 61 | ||
55 | <script type="text/montage-serialization"> | 62 | <script type="text/montage-serialization" data-ninja-template="true"> |
56 | { | 63 | { |
57 | "owner": { | 64 | "owner": { |
58 | "prototype": "main" | 65 | "prototype": "main" |
diff --git a/js/document/views/design.js b/js/document/views/design.js index df6e9b53..9ad088cb 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js | |||
@@ -100,6 +100,13 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { | |||
100 | this._observer.body.observe(this.document.body, {childList: true}); | 100 | this._observer.body.observe(this.document.body, {childList: true}); |
101 | //Inserting <body> HTML and parsing URLs via mediator method | 101 | //Inserting <body> HTML and parsing URLs via mediator method |
102 | this.document.body.innerHTML += '<ninjaloadinghack></ninjaloadinghack>'+(this.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator)); | 102 | this.document.body.innerHTML += '<ninjaloadinghack></ninjaloadinghack>'+(this.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator)); |
103 | //Copying attributes to maintain same properties as the <body> | ||
104 | for (var n in this.content.document.body.attributes) { | ||
105 | if (this.content.document.body.attributes[n].value) { | ||
106 | this.document.body.setAttribute(this.content.document.body.attributes[n].name, this.content.document.body.attributes[n].value); | ||
107 | } | ||
108 | } | ||
109 | //TODO: Add attribute copying for <HEAD> and <HTML> | ||
103 | } | 110 | } |
104 | }, | 111 | }, |
105 | //////////////////////////////////////////////////////////////////// | 112 | //////////////////////////////////////////////////////////////////// |