diff options
Diffstat (limited to 'js/document')
19 files changed, 1354 insertions, 658 deletions
diff --git a/js/document/document-html.js b/js/document/document-html.js index 89717dd6..56d9db02 100755 --- a/js/document/document-html.js +++ b/js/document/document-html.js | |||
@@ -7,360 +7,162 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
7 | //////////////////////////////////////////////////////////////////////// | 7 | //////////////////////////////////////////////////////////////////////// |
8 | // | 8 | // |
9 | var Montage = require("montage/core/core").Montage, | 9 | var Montage = require("montage/core/core").Montage, |
10 | Component = require("montage/ui/component").Component; | 10 | Component = require("montage/ui/component").Component, |
11 | HtmlDocumentModel = require("js/document/models/html").HtmlDocumentModel; | 11 | HtmlDocumentModel = require("js/document/models/html").HtmlDocumentModel, |
12 | DesignDocumentView = require("js/document/views/design").DesignDocumentView; | ||
12 | //////////////////////////////////////////////////////////////////////// | 13 | //////////////////////////////////////////////////////////////////////// |
13 | // | 14 | // |
14 | exports.HtmlDocument = Montage.create(Component, { | 15 | exports.HtmlDocument = Montage.create(Component, { |
15 | //////////////////////////////////////////////////////////////////// | 16 | //////////////////////////////////////////////////////////////////// |
16 | // | 17 | // |
17 | hasTemplate: { | 18 | hasTemplate: { |
18 | enumerable: false, | ||
19 | value: false | 19 | value: false |
20 | }, | 20 | }, |
21 | 21 | //////////////////////////////////////////////////////////////////// | |
22 | // | ||
22 | model: { | 23 | model: { |
23 | value: null | 24 | value: null |
24 | }, | 25 | }, |
25 | 26 | //////////////////////////////////////////////////////////////////// | |
26 | loadDelegate: { | 27 | // |
27 | value: null | 28 | loaded: { |
29 | value: {callback: null, context: null} | ||
28 | }, | 30 | }, |
29 | 31 | //////////////////////////////////////////////////////////////////// | |
30 | delegateContext: { | 32 | // |
33 | _observer: { | ||
31 | value: null | 34 | value: null |
32 | }, | 35 | }, |
33 | 36 | //////////////////////////////////////////////////////////////////// | |
34 | exclusionList: { | 37 | // |
35 | value: ["HTML", "BODY"] | 38 | _document: { |
36 | }, | 39 | value: null //TODO: Figure out if this will be needed, probably not |
37 | |||
38 | // Getters for the model. | ||
39 | // TODO: Change how these properties are accessed through Ninja | ||
40 | name: { | ||
41 | get: function() { | ||
42 | return this.model._name; | ||
43 | }, | ||
44 | set: function(value) { | ||
45 | this.model._name = value; | ||
46 | } | ||
47 | }, | ||
48 | |||
49 | isActive: { | ||
50 | get: function() { | ||
51 | return this.model._isActive; | ||
52 | }, | ||
53 | set: function(value) { | ||
54 | this.model._isActive = value; | ||
55 | } | ||
56 | }, | ||
57 | |||
58 | needsSave: { | ||
59 | get: function() { | ||
60 | return this.model._needsSave; | ||
61 | }, | ||
62 | set: function(value) { | ||
63 | this.model._needsSave = value; | ||
64 | } | ||
65 | }, | 40 | }, |
66 | 41 | //////////////////////////////////////////////////////////////////// | |
67 | // View Properties | 42 | // |
68 | // TODO: Move those into a view object - for now dump it here | 43 | exclusionList: { |
69 | iframe: { | 44 | value: ["HTML", "BODY", "NINJA-CONTENT"] //TODO: Update to correct list |
70 | value: null | ||
71 | }, | 45 | }, |
72 | 46 | //////////////////////////////////////////////////////////////////// | |
73 | uuid: { | 47 | // |
74 | get: function() { | 48 | inExclusion: { |
75 | return this._uuid; | 49 | value: function(element) { |
50 | if(this.exclusionList.indexOf(element.nodeName) === -1) { | ||
51 | return -1; | ||
52 | } | ||
53 | return 1; | ||
76 | } | 54 | } |
77 | }, | 55 | }, |
78 | |||
79 | currentView: { | ||
80 | value: "design" | ||
81 | }, | ||
82 | //////////////////////////////////////////////////////////////////// | ||
83 | //////////////////////////////////////////////////////////////////// | 56 | //////////////////////////////////////////////////////////////////// |
57 | // | ||
84 | init: { | 58 | init: { |
85 | value:function(file, context, callback) { | 59 | value:function(file, context, callback, view, template) { |
86 | this.model = Montage.create(HtmlDocumentModel, { | 60 | //Storing callback data for loaded dispatch |
87 | file: { | 61 | this.loaded.callback = callback; |
88 | value: file | 62 | this.loaded.context = context; |
89 | } | 63 | //Creating instance of HTML Document Model |
64 | this.model = Montage.create(HtmlDocumentModel,{ | ||
65 | file: {value: file}, | ||
66 | fileTemplate: {value: template}, | ||
67 | parentContainer: {value: document.getElementById("iframeContainer")}, //Saving reference to parent container of all views (should be changed to buckets approach | ||
68 | views: {value: {'design': DesignDocumentView.create(), 'code': null}} //TODO: Add code view logic | ||
90 | }); | 69 | }); |
91 | 70 | //Initiliazing views and hiding | |
92 | this.name = file.name; | 71 | if (this.model.views.design.initialize(this.model.parentContainer)) { |
93 | 72 | //Hiding iFrame, just initiliazing | |
94 | // this.init(file.name, file.uri, file.extension, iframe, uuid, callback); | 73 | this.model.views.design.hide(); |
95 | 74 | } else { | |
96 | 75 | //ERROR: Design View not initilized | |
97 | this.iframe = this.createView(); | 76 | } |
98 | |||
99 | //this.selectionExclude = ["HTML", "BODY", "Viewport", "UserContent", "stageBG"]; | ||
100 | //this.currentView = "design"; | ||
101 | // | 77 | // |
102 | 78 | if (view === 'design') { | |
103 | this.delegateContext = context; | 79 | //TODO: Remove reference and use as part of model |
104 | this.loadDelegate = callback; | 80 | this.currentView = 'design'; |
105 | } | 81 | //Setting current view object to design |
106 | }, | 82 | this.model.currentView = this.model.views.design; |
107 | 83 | //Showing design iFrame | |
108 | // Create View | 84 | this.model.views.design.show(); |
109 | // Move this into a base view object | 85 | this.model.views.design.iframe.style.opacity = 0; |
110 | createView: { | 86 | this.model.views.design.content = this.model.file.content; |
111 | value: function() { | 87 | //TODO: Improve reference |
112 | var ifr = document.createElement("iframe"); | 88 | this.model.views.design.model = this.model; |
113 | ifr.id = "document_" + this._uuid; | 89 | // |
114 | 90 | //TODO: Clean up | |
115 | 91 | this.model.views.design.render(function () { | |
116 | ifr.style.border = "none"; | 92 | //TODO: Identify and remove usage of '_document' |
117 | ifr.style.background = "#FFF"; | 93 | this._document = this.model.views.design.document; |
118 | ifr.style.height = "100%"; | 94 | //TODO: Remove usage, seems as not needed |
119 | ifr.style.width = "100%"; | 95 | if (template && template.type === 'banner') { |
120 | 96 | this.documentRoot = this.model.views.design.document.body.getElementsByTagName('ninja-content')[0]; | |
121 | // TODO: Reable opacity to display only when done loading | 97 | } else { |
122 | // ifr.style.opacity = 0; | 98 | this.documentRoot = this.model.views.design.document.body; |
123 | 99 | } | |
124 | ifr.src = "js/document/templates/montage-web/index.html"; | 100 | //TODO: Why is this needed? |
125 | ifr.addEventListener("load", this.handleWebTemplateLoad.bind(this), true); | 101 | this._liveNodeList = this.documentRoot.getElementsByTagName('*'); |
126 | 102 | //Initiliazing document model | |
127 | return document.getElementById("iframeContainer").appendChild(ifr); | 103 | document.application.njUtils.makeElementModel(this.documentRoot, "Body", "body"); |
128 | } | 104 | //Adding observer to know when template is ready |
129 | }, | 105 | this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); |
130 | 106 | this._observer.observe(this.model.views.design.document.head, {childList: true}); | |
131 | handleWebTemplateLoad: { | 107 | }.bind(this), template); |
132 | value: function(event) { | 108 | } else { |
133 | //TODO: Remove, also for prototyping | 109 | //TODO: Identify default view (probably code) |
134 | this.application.ninja.documentController._hackRootFlag = true; | ||
135 | |||
136 | |||
137 | //TODO: Clean up, using for prototyping save | ||
138 | // this._templateDocument = {}; | ||
139 | // this._templateDocument.html = this.iframe.contentWindow.document; | ||
140 | // this._templateDocument.body = | ||
141 | |||
142 | this._window = this.iframe.contentWindow; | ||
143 |