aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
authorArmen Kesablyan2012-05-15 16:34:46 -0700
committerArmen Kesablyan2012-05-15 16:34:46 -0700
commitc8d61c8e72e0eba266575f9df54325fa77fde73d (patch)
tree556cafd76ab9b2cf4cc2b4cc3ea17b12ce690b69 /js/document
parent15a3aaebb56cb2c9409bfe55c862868726c7fd44 (diff)
parent46bd3712329cd3c9311e50ed9ee4c2245bd1be5a (diff)
downloadninja-c8d61c8e72e0eba266575f9df54325fa77fde73d.tar.gz
Merge branch 'dom-architecture' of github.com:Motorola-Mobility/ninja-internal into binding
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/document-html.js54
-rwxr-xr-xjs/document/models/base.js127
-rwxr-xr-xjs/document/models/html.js28
-rwxr-xr-xjs/document/templates/banner/index.html108
-rw-r--r--js/document/templates/banner/main.js (renamed from js/document/templates/montage-web/main.js)0
-rwxr-xr-xjs/document/templates/banner/package.json (renamed from js/document/templates/montage-html/package.json)0
-rwxr-xr-xjs/document/templates/html/index.html (renamed from js/document/templates/montage-web/index.html)30
-rw-r--r--js/document/templates/html/main.js (renamed from js/document/templates/montage-html/main.reel/main.js)3
-rwxr-xr-xjs/document/templates/html/package.json (renamed from js/document/templates/montage-web/package.json)0
-rwxr-xr-xjs/document/templates/montage-html/default_html.css74
-rwxr-xr-xjs/document/templates/montage-html/index.html48
-rwxr-xr-xjs/document/views/design.js155
12 files changed, 455 insertions, 172 deletions
diff --git a/js/document/document-html.js b/js/document/document-html.js
index 567e4455..9bbea4c9 100755
--- a/js/document/document-html.js
+++ b/js/document/document-html.js
@@ -63,17 +63,19 @@ exports.HtmlDocument = Montage.create(Component, {
63 //////////////////////////////////////////////////////////////////// 63 ////////////////////////////////////////////////////////////////////
64 // 64 //
65 init: { 65 init: {
66 value:function(file, context, callback, view, template) { //TODO: Add template support logic 66 value:function(file, context, callback, view, template) {
67 //Storing callback data for loaded dispatch 67 //Storing callback data for loaded dispatch
68 this.loaded.callback = callback; 68 this.loaded.callback = callback;
69 this.loaded.context = context; 69 this.loaded.context = context;
70 //Creating instance of HTML Document Model 70 //Creating instance of HTML Document Model
71 this.model = Montage.create(HtmlDocumentModel,{ 71 this.model = Montage.create(HtmlDocumentModel,{
72 file: {value: file}, 72 file: {value: file},
73 fileTemplate: {value: template},
74 parentContainer: {value: document.getElementById("iframeContainer")}, //Saving reference to parent container of all views (should be changed to buckets approach
73 views: {value: {'design': DesignDocumentView.create(), 'code': null}} //TODO: Add code view logic 75 views: {value: {'design': DesignDocumentView.create(), 'code': null}} //TODO: Add code view logic
74 }); 76 });
75 //Initiliazing views and hiding 77 //Initiliazing views and hiding
76 if (this.model.views.design.initialize(document.getElementById("iframeContainer"))) { 78 if (this.model.views.design.initialize(this.model.parentContainer)) {
77 //Hiding iFrame, just initiliazing 79 //Hiding iFrame, just initiliazing
78 this.model.views.design.hide(); 80 this.model.views.design.hide();
79 } else { 81 } else {
@@ -96,16 +98,20 @@ exports.HtmlDocument = Montage.create(Component, {
96 this.model.views.design.render(function () { 98 this.model.views.design.render(function () {
97 //TODO: Identify and remove usage of '_document' 99 //TODO: Identify and remove usage of '_document'
98 this._document = this.model.views.design.document; 100 this._document = this.model.views.design.document;
99 //TODO: Remove usage, seems as not needed 101 //TODO: Remove usage, seems as not needed
100 this.documentRoot = this.model.views.design.document.body; 102 if (template && template.type === 'banner') {
103 this.documentRoot = this.model.views.design.document.body.getElementsByTagName('ninja-content')[0];
104 } else {
105 this.documentRoot = this.model.views.design.document.body;
106 }
101 //TODO: Why is this needed? 107 //TODO: Why is this needed?
102 this._liveNodeList = this.model.views.design.document.body.getElementsByTagName('*'); 108 this._liveNodeList = this.documentRoot.getElementsByTagName('*');
103 //Initiliazing document model 109 //Initiliazing document model
104 document.application.njUtils.makeElementModel(this.model.views.design.document.body, "Body", "body"); 110 document.application.njUtils.makeElementModel(this.documentRoot, "Body", "body");
105 //Adding observer to know when template is ready 111 //Adding observer to know when template is ready
106 this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); 112 this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this));
107 this._observer.observe(this.model.views.design.document.head, {childList: true}); 113 this._observer.observe(this.model.views.design.document.head, {childList: true});
108 }.bind(this)); 114 }.bind(this), template);
109 } else { 115 } else {
110 //TODO: Identify default view (probably code) 116 //TODO: Identify default view (probably code)
111 } 117 }
@@ -123,6 +129,40 @@ exports.HtmlDocument = Montage.create(Component, {
123 //Setting opacity to be viewable after load 129 //Setting opacity to be viewable after load
124 this.model.views.design.iframe.style.opacity = 1; 130 this.model.views.design.iframe.style.opacity = 1;
125 } 131 }
132 },
133 ////////////////////////////////////////////////////////////////////
134 //
135 closeDocument: {
136 value: function () {
137 //
138 this.model.close(null, this.handleCloseDocument.bind(this));
139 }
140 },
141 ////////////////////////////////////////////////////////////////////
142 //
143 handleCloseDocument: {
144 value: function (success) {
145 //TODO: Add logic for handling success or failure
146 //
147 this.application.ninja.documentController._documents.splice(this.uuid, 1);
148 //
149 NJevent("closeDocument", this.model.file.uri);
150 //TODO: Delete object here
151 }
152 },
153 ////////////////////////////////////////////////////////////////////
154 //
155 saveAppState: {
156 value: function () {
157 //TODO: Import functionality
158 }
159 },
160 ////////////////////////////////////////////////////////////////////
161 //
162 restoreAppState: {
163 value: function () {
164 //TODO: Import functionality
165 }
126 } 166 }
127 //////////////////////////////////////////////////////////////////// 167 ////////////////////////////////////////////////////////////////////
128 //////////////////////////////////////////////////////////////////// 168 ////////////////////////////////////////////////////////////////////
diff --git a/js/document/models/base.js b/js/document/models/base.js
index 746922ad..5f2a5893 100755
--- a/js/document/models/base.js
+++ b/js/document/models/base.js
@@ -62,55 +62,154 @@ exports.BaseDocumentModel = Montage.create(Component, {
62 }, 62 },
63 //////////////////////////////////////////////////////////////////// 63 ////////////////////////////////////////////////////////////////////
64 // 64 //
65 fileTemplate: {
66 value: null
67 },
68 ////////////////////////////////////////////////////////////////////
69 //
70 parentContainer: {
71 value: null
72 },
73 ////////////////////////////////////////////////////////////////////
74 //
65 views: { 75 views: {
66 value: null 76 value: null
67 }, 77 },
68 //////////////////////////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////
69 // 79 //
70 switchViewTo: { 80 switchViewTo: {
71 value: function () { 81 value: function (view) {
72 // 82 //
73 } 83 }
74 }, 84 },
75 //////////////////////////////////////////////////////////////////// 85 ////////////////////////////////////////////////////////////////////
76 // 86 //TODO: Add API to allow other browser support
77 browserPreview: { 87 browserPreview: {
78 value: function (browser) { 88 value: function (browser) {
79 // 89 //Generating URL for document
80 switch (browser) { 90 var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1];
81 case 'chrome': 91 //TODO: Add logic to prompt user to save (all) before preview
82 break; 92 this.saveAll(function (result) {
83 default: 93 //Currently only supporting current browser (Chrome, obviously)
84 break; 94 switch (this.browser) {
85 } 95 case 'chrome':
96 window.open(this.url);
97 break;
98 default:
99 window.open(this.url);
100 break;
101 }
102 }.bind({browser: browser, url: url}));
86 } 103 }
87 }, 104 },
88 //////////////////////////////////////////////////////////////////// 105 ////////////////////////////////////////////////////////////////////
89 // 106 //
107 getStyleSheets: {
108 value: function () {
109 //
110 var styles = [];
111 //
112 for (var k in this.views.design.iframe.contentWindow.document.styleSheets) {
113 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode && this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute) {
114 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute('data-ninja-template') === null) {
115 styles.push(this.views.design.iframe.contentWindow.document.styleSheets[k]);
116 }
117 }
118 }
119 //
120 return styles;
121 }
122 },
123 ////////////////////////////////////////////////////////////////////
124 //
90 save: { 125 save: {
91 value: function () { 126 value: function (callback) {
127 //
128 if (this.needsSave) {
129 //Save
130 } else {
131 //Ignore command
132 }
92 // 133 //
134 if (this.currentView === this.views.design) {
135 //
136 this.application.ninja.ioMediator.fileSave({
137 mode: 'html',
138 file: this.file,
139 webgl: this.webGlHelper.glData,
140 styles: this.getStyleSheets(),
141 template: this.fileTemplate,