From c62273126004f057de40ce91ecda5606643f4c92 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 20 Apr 2012 16:37:47 -0700 Subject: reverting old template to current working status. New template work. Signed-off-by: Valerio Virgillito --- .../layout/bread-crumb.reel/bread-crumb.js | 4 +- js/controllers/document-controller.js | 38 ++- js/document/controllers/document.js | 2 +- js/document/document-html.js | 304 ++++++++++++++++++++- js/document/html-document.js | 223 +-------------- js/document/models/base.js | 4 + js/document/models/html.js | 4 +- js/document/templates/montage-web/default_html.css | 11 - js/document/templates/montage-web/index.html | 10 +- js/ninja.reel/ninja.js | 22 +- js/panels/properties.reel/properties.js | 2 +- 11 files changed, 365 insertions(+), 259 deletions(-) diff --git a/js/components/layout/bread-crumb.reel/bread-crumb.js b/js/components/layout/bread-crumb.reel/bread-crumb.js index 45a4d217..f35972b6 100755 --- a/js/components/layout/bread-crumb.reel/bread-crumb.js +++ b/js/components/layout/bread-crumb.reel/bread-crumb.js @@ -58,7 +58,7 @@ exports.Breadcrumb = Montage.create(Component, { createContainerElements: { value: function() { var parentNode; -/* + this.containerElements.length = 0; parentNode = this.container; @@ -70,7 +70,7 @@ exports.Breadcrumb = Montage.create(Component, { // This is always the top container which is now hardcoded to body this.containerElements.unshift({"node": parentNode, "nodeUuid":parentNode.uuid, "label": "Body"}); -*/ + } diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 1fcdf6d0..a7aa0de6 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -11,6 +11,9 @@ var Montage = require("montage/core/core").Montage, Uuid = require("montage/core/uuid").Uuid, HTMLDocument = require("js/document/html-document").HTMLDocument, TextDocument = require("js/document/text-document").TextDocument; + + // New Document Objects +var Document = require("js/document/document-html").HtmlDocument; //////////////////////////////////////////////////////////////////////// // var DocumentController = exports.DocumentController = Montage.create(Component, { @@ -289,7 +292,12 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.isNewFilePath = false;//reset path identifier flag //Sending full response object - this.openDocument(response); + // TODO: Unify those 2 methods. Using if/else for the new template + if(this.webTemplate) { + this.openWebDocument(response); + } else { + this.openDocument(response); + } } else if (!!response && (response.status === 404)){ alert("Unable to open file.\n [Error: File does not exist]"); } else if (!!response && (response.status === 500)){ @@ -334,7 +342,31 @@ var DocumentController = exports.DocumentController = Montage.create(Component, switch (doc.extension) { case 'html': //Open in designer view - Montage.create(HTMLDocument).initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument.bind(this), this.webTemplate); + Montage.create(HTMLDocument).initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument.bind(this)); + break; + default: + //Open in code view + var code = Montage.create(TextDocument, {"source": {value: doc.content}}), docuuid = Uuid.generate(), textArea; + textArea = this.application.ninja.stage.stageView.createTextAreaElement(docuuid); + code.initialize(doc, docuuid, textArea, textArea.parentNode); + //code.init(doc.name, doc.uri, doc.extension, null, docuuid); + code.textArea.value = doc.content; + this.application.ninja.stage.stageView.createTextView(code); + break; + } + } + }, + openWebDocument: { + value: function(doc) { + // TODO: HACKS to remove + this.documentHackReference = doc; + document.getElementById("iframeContainer").style.overflow = "hidden"; + // + switch (doc.extension) { + case 'html': + //Open in designer view + this._hackRootFlag = false; + Montage.create(Document).init(doc, this, this._onOpenDocument); break; default: //Open in code view @@ -453,8 +485,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this._showCurrentDocument(); NJevent("onOpenDocument", doc); -// appDelegateModule.MyAppDelegate.onSetActiveDocument(); - } }, diff --git a/js/document/controllers/document.js b/js/document/controllers/document.js index f7260957..feba3e0e 100755 --- a/js/document/controllers/document.js +++ b/js/document/controllers/document.js @@ -16,7 +16,7 @@ exports.DocumentController = Montage.create(Component, { hasTemplate: { enumerable: false, value: false - } + }, //////////////////////////////////////////////////////////////////// // save: { diff --git a/js/document/document-html.js b/js/document/document-html.js index b48e004a..841e66ed 100755 --- a/js/document/document-html.js +++ b/js/document/document-html.js @@ -6,8 +6,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot //////////////////////////////////////////////////////////////////////// // -var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component; +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component; + HtmlDocumentModel = require("js/document/models/html").HtmlDocumentModel; //////////////////////////////////////////////////////////////////////// // exports.HtmlDocument = Montage.create(Component, { @@ -16,9 +17,306 @@ exports.HtmlDocument = Montage.create(Component, { hasTemplate: { enumerable: false, value: false - } + }, + + model: { + value: null + }, + + loadDelegate: { + value: null + }, + + delegateContext: { + value: null + }, + + // Getters for the model. + // TODO: Change how these properties are accessed through Ninja + name: { + get: function() { + return this.model._name; + }, + set: function(value) { + this.model._name = value; + } + }, + + // View Properties + // TODO: Move those into a view object - for now dump it here + iframe: { + value: null + }, + + uuid: { + get: function() { + return this._uuid; + } + }, //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// + init: { + value:function(file, context, callback) { + this.model = Montage.create(HtmlDocumentModel, { + file: { + value: file + } + }); + + this.name = file.name; + + // this.init(file.name, file.uri, file.extension, iframe, uuid, callback); + + this.iframe = this.createView(); + this.iframe.addEventListener("load", this.handleWebTemplateLoad.bind(this), true); + + //this.selectionExclude = ["HTML", "BODY", "Viewport", "UserContent", "stageBG"]; + //this.currentView = "design"; + // + + this.delegateContext = context; + this.loadDelegate = callback; + } + }, + + // Create View + // Move this into a base view object + createView: { + value: function() { + var ifr = document.createElement("iframe"); + ifr.id = "document_" + this._uuid; + + + ifr.style.border = "none"; + ifr.style.background = "#FFF"; + ifr.style.height = "100%"; + ifr.style.width = "100%"; + + // TODO: Reable opacity to display only when done loading +// ifr.style.opacity = 0; + + ifr.src = "js/document/templates/montage-web/index.html"; + + return document.getElementById("iframeContainer").appendChild(ifr); + } + }, + + handleWebTemplateLoad: { + value: function(event) { + //TODO: Remove, also for prototyping + this.application.ninja.documentController._hackRootFlag = true; + + + //TODO: Clean up, using for prototyping save +// this._templateDocument = {}; +// this._templateDocument.html = this.iframe.contentWindow.document; +// this._templateDocument.body = + + this._window = this.iframe.contentWindow; + this._document = this.iframe.contentWindow.document; + this.documentRoot = this.iframe.contentWindow.document.body; + + for (var k in this._document.styleSheets) { + if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.setAttribute) { + this._document.styleSheets[k].ownerNode.setAttribute('data-ninja-template', 'true'); + } + } + + // TODO: We don't need this anymore -> need to setup the main container still + //Adding a handler for the main user document reel to finish loading + //this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); + this.documentRoot.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); + + // Live node list of the current loaded document + this._liveNodeList = this.documentRoot.getElementsByTagName('*'); + + // TODO Move this to the appropriate location + /* + var len = this._liveNodeList.length; + + for(var i = 0; i < len; i++) { + NJUtils.makeModelFromElement(this._liveNodeList[i]); + } + */ + + setTimeout(function () { + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + if(this._document.styleSheets.length) { + //Checking all styleSheets in document + for (var i in this._document.styleSheets) { + //If rules are null, assuming cross-origin issue + if(this._document.styleSheets[i].rules === null) { + //TODO: Revisit URLs and URI creation logic, very hack right now + var fileUri, cssUrl, cssData, query, prefixUrl, fileCouldDirUrl, docRootUrl; + // + docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); + //TODO: Parse out relative URLs and map them to absolute + if (this._document.styleSheets[i].href.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { + // + cssUrl = this._document.styleSheets[i].href.split(this.application.ninja.coreIoApi.rootUrl)[1]; + fileUri = this.application.ninja.coreIoApi.cloudData.root+cssUrl; + //TODO: Add error handling for reading file + cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); + // + var tag = this.iframe.contentWindow.document.createElement('style'); + tag.setAttribute('type', 'text/css'); + tag.setAttribute('data-ninja-uri', fileUri); + tag.setAttribute('data-ninja-file-url', cssUrl); + tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly); + tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]); + //Copying attributes to maintain same properties as the + for (var n in this._document.styleSheets[i].ownerNode.attributes) { + if (this._document.styleSheets[i].ownerNode.attributes[n].value && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled' && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled') { + if (this._document.styleSheets[i].ownerNode.attributes[n].value.indexOf(docRootUrl) !== -1) { + tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value.split(docRootUrl)[1]); + } else { + tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value); + } + } + } + // + fileCouldDirUrl = this._document.styleSheets[i].href.split(this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1])[0]; + + //TODO: Make public version of this.application.ninja.ioMediator.getNinjaPropUrlRedirect with dynamic ROOT + tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, detectUrl); + + function detectUrl (prop) { + return prop.replace(/[^()\\""\\'']+/g, prefixUrl);; + } + + function prefixUrl (url) { + if (url !== 'url') { + if (!url.match(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi)) { + url = fileCouldDirUrl+url; + } + } + return url; + } + + //Looping through DOM to insert style tag at location of link element + query = this._templateDocument.html.querySelectorAll(['link']); + for (var j in query) { + if (query[j].href === this._document.styleSheets[i].href) { + //Disabling style sheet to reload via inserting in style tag + query[j].setAttribute('disabled', 'true'); + //Inserting tag + this._templateDocument.head.insertBefore(tag, query[j]); + } + } + } else { + console.log('ERROR: Cross-Domain-Stylesheet detected, unable to load in Ninja'); + //None local stylesheet, probably on a CDN (locked) + var tag = this.iframe.contentWindow.document.createElement('style'); + tag.setAttribute('type', 'text/css'); + tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); + tag.setAttribute('data-ninja-file-read-only', "true"); + tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]); + //Copying attributes to maintain same properties as the + for (var n in this._document.styleSheets[i].ownerNode.attributes) { + if (this._document.styleSheets[i].ownerNode.attributes[n].value && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled' && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled') { + if (this._document.styleSheets[i].ownerNode.attributes[n].value.indexOf(docRootUrl) !== -1) { + tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value.split(docRootUrl)[1]); + } else { + tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value); + } + } + } + /* + + //TODO: Figure out cross-domain XHR issue, might need cloud to handle + var xhr = new XMLHttpRequest(); + xhr.open("GET", this._document.styleSheets[i].href, true); + xhr.send(); + // + if (xhr.readyState === 4) { + console.log(xhr); + } + //tag.innerHTML = xhr.responseText //xhr.response; + */ + //Temp rule so it's registered in the array + tag.innerHTML = 'noRULEjustHACK{background: #000}'; + //Disabling external style sheets + query = this._templateDocument.html.querySelectorAll(['link']); + for (var k in query) { + if (query[k].href === this._document.styleSheets[i].href) { + + //TODO: Removed the temp insertion of the stylesheet + //because it wasn't the proper way to do it + //need to be handled via XHR with proxy in Cloud Sim + + //Disabling style sheet to reload via inserting in style tag + //var tempCSS = query[k].cloneNode(true); + //tempCSS.setAttribute('data-ninja-template', 'true'); + query[k].setAttribute('disabled', 'true'); + //this.iframe.contentWindow.document.head.appendChild(tempCSS); + //Inserting tag + this._templateDocument.head.insertBefore(tag, query[k]); + } + } + } + } + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + //TODO: Check if this is needed + this._stylesheets = this._document.styleSheets; + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + //TODO Finish this implementation once we start caching Core Elements + // Assign a model to the UserContent and add the ViewPort reference to it. + document.application.njUtils.makeElementModel(this.documentRoot, "Stage", "stage"); + + for(i = 0; i < this._stylesheets.length; i++) { + if(this._stylesheets[i].ownerNode.id === "nj-stage-stylesheet") { + this.documentRoot.elementModel.defaultRule = this._stylesheets[i]; + break; + } + } + + //Temporary create properties for each rule we need to save the index of the rule + var len = this.documentRoot.elementModel.defaultRule.cssRules.length; + for(var j = 0; j < len; j++) { + if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "*") { + this.documentRoot.elementModel.transitionStopRule = this.documentRoot.elementModel.defaultRule.cssRules[j]; + } + } + + + this.loadDelegate.call(this.delegateContext, this); + + //Setting webGL data + /* + if (this._templateDocument.webgl) { + this.glData = this._templateDocument.webgl; + } + */ + } + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + + + + }.bind(this), 1000); + } + }, + + // Handler for user content main reel. Gets called once the main reel of the template + // gets deserialized. + // Setting up the currentSelectedContainer to the document body. + userTemplateDidLoad: { + value: function(){ + this.application.ninja.currentSelectedContainer = this.documentRoot; + } + } }); //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/js/document/html-document.js b/js/document/html-document.js index b79281e4..9873fdd1 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -17,7 +17,6 @@ exports.HTMLDocument = Montage.create(TextDocument, { _selectionExclude: { value: null, enumerable: false }, _htmlTemplateUrl: { value: "js/document/templates/montage-html/index.html", enumerable: false}, - _webTemplateUrl: { value: "js/document/templates/montage-web/index.html", enumerable: false}, _iframe: { value: null, enumerable: false }, _server: { value: null, enumerable: false }, _templateDocument: { value: null, enumerable: false }, @@ -394,7 +393,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { //////////////////////////////////////////////////////////////////// // initialize: { - value: function(file, uuid, iframe, callback, webTemplate) { + value: function(file, uuid, iframe, callback) { this.application.ninja.documentController._hackRootFlag = false; // this._userDocument = file; @@ -405,13 +404,9 @@ exports.HTMLDocument = Montage.create(TextDocument, { this.selectionExclude = ["HTML", "BODY", "Viewport", "UserContent", "stageBG"]; this.currentView = "design"; // - if(webTemplate) { - this.iframe.src = this._webTemplateUrl; - this.iframe.addEventListener("load", this.handleWebTemplateLoad.bind(this), true); - } else { - this.iframe.src = this._htmlTemplateUrl; - this.iframe.addEventListener("load", this, true); - } + + this.iframe.src = this._htmlTemplateUrl; + this.iframe.addEventListener("load", this, true); } }, //////////////////////////////////////////////////////////////////// @@ -534,216 +529,6 @@ exports.HTMLDocument = Montage.create(TextDocument, { value: 0 }, */ - handleWebTemplateLoad: { - value: function(event) { - //TODO: Clean up, using for prototyping save - this._templateDocument = {}; - this._templateDocument.html = this.iframe.contentWindow.document; -// this._templateDocument.head = this.iframe.contentWindow.document.getElementById("userHead"); - this._templateDocument.body = this.documentRoot = this.iframe.contentWindow.document.body; - //TODO: Remove, also for prototyping - this.application.ninja.documentController._hackRootFlag = true; - // -// this.stageBG = this.iframe.contentWindow.document.getElementById("stageBG"); - this._document = this.iframe.contentWindow.document; - this._window = this.iframe.contentWindow; - - for (var k in this._document.styleSheets) { - if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.setAttribute) { - this._document.styleSheets[k].ownerNode.setAttribute('data-ninja-template', 'true'); - } - } - - //Adding a handler for the main user document reel to finish loading - this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); - - // Live node list of the current loaded document - this._liveNodeList = this.documentRoot.getElementsByTagName('*'); - - // TODO Move this to the appropriate location - var len = this._liveNodeList.length; - - for(var i = 0; i < len; i++) { - NJUtils.makeModelFromElement(this._liveNodeList[i]); - } - - setTimeout(function () { - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - if(this._document.styleSheets.length) { - //Checking all styleSheets in document - for (var i in this._document.styleSheets) { - //If rules are null, assuming cross-origin issue - if(this._document.styleSheets[i].rules === null) { - //TODO: Revisit URLs and URI creation logic, very hack right now - var fileUri, cssUrl, cssData, query, prefixUrl, fileCouldDirUrl, docRootUrl; - // - docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); - //TODO: Parse out relative URLs and map them to absolute - if (this._document.styleSheets[i].href.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { - // - cssUrl = this._document.styleSheets[i].href.split(this.application.ninja.coreIoApi.rootUrl)[1]; - fileUri = this.application.ninja.coreIoApi.cloudData.root+cssUrl; - //TODO: Add error handling for reading file - cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); - // - var tag = this.iframe.contentWindow.document.createElement('style'); - tag.setAttribute('type', 'text/css'); - tag.setAttribute('data-ninja-uri', fileUri); - tag.setAttribute('data-ninja-file-url', cssUrl); - tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly); - tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]); - //Copying attributes to maintain same properties as the - for (var n in this._document.styleSheets[i].ownerNode.attributes) { - if (this._document.styleSheets[i].ownerNode.attributes[n].value && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled' && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled') { - if (this._document.styleSheets[i].ownerNode.attributes[n].value.indexOf(docRootUrl) !== -1) { - tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value.split(docRootUrl)[1]); - } else { - tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value); - } - } - } - // - fileCouldDirUrl = this._document.styleSheets[i].href.split(this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1])[0]; - - //TODO: Make public version of this.application.ninja.ioMediator.getNinjaPropUrlRedirect with dynamic ROOT - tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, detectUrl); - - function detectUrl (prop) { - return prop.replace(/[^()\\""\\'']+/g, prefixUrl);; - } - - function prefixUrl (url) { - if (url !== 'url') { - if (!url.match(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi)) { - url = fileCouldDirUrl+url; - } - } - return url; - } - - //Looping through DOM to insert style tag at location of link element - query = this._templateDocument.html.querySelectorAll(['link']); - for (var j in query) { - if (query[j].href === this._document.styleSheets[i].href) { - //Disabling style sheet to reload via inserting in style tag - query[j].setAttribute('disabled', 'true'); - //Inserting tag - this._templateDocument.head.insertBefore(tag, query[j]); - } - } - } else { - console.log('ERROR: Cross-Domain-Stylesheet detected, unable to load in Ninja'); - //None local stylesheet, probably on a CDN (locked) - var tag = this.iframe.contentWindow.document.createElement('style'); - tag.setAttribute('type', 'text/css'); - tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); - tag.setAttribute('data-ninja-file-read-only', "true"); - tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]); - //Copying attributes to maintain same properties as the - for (var n in this._document.styleSheets[i].ownerNode.attributes) { - if (this._document.styleSheets[i].ownerNode.attributes[n].value && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled' && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled') { - if (this._document.styleSheets[i].ownerNode.attributes[n].value.indexOf(docRootUrl) !== -1) { - tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value.split(docRootUrl)[1]); - } else { - tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value); - } - } - } - /* - - //TODO: Figure out cross-domain XHR issue, might need cloud to handle - var xhr = new XMLHttpRequest(); - xhr.open("GET", this._document.styleSheets[i].href, true); - xhr.send(); - // - if (xhr.readyState === 4) { - console.log(xhr); - } - //tag.innerHTML = xhr.responseText //xhr.response; - */ - //Temp rule so it's registered in the array - tag.innerHTML = 'noRULEjustHACK{background: #000}'; - //Disabling external style sheets - query = this._templateDocument.html.querySelectorAll(['link']); - for (var k in query) { - if (query[k].href === this._document.styleSheets[i].href) { - - //TODO: Removed the temp insertion of the stylesheet - //because it wasn't the proper way to do it - //need to be handled via XHR with proxy in Cloud Sim - - //Disabling style sheet to reload via inserting in style tag - //var tempCSS = query[k].cloneNode(true); - //tempCSS.setAttribute('data-ninja-template', 'true'); - query[k].setAttribute('disabled', 'true'); - //this.iframe.contentWindow.document.head.appendChild(tempCSS); - //Inserting tag - this._templateDocument.head.insertBefore(tag, query[k]); - } - } - } - } - } - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - - //TODO: Check if this is needed - this._stylesheets = this._document.styleSheets; - - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - - //TODO Finish this implementation once we start caching Core Elements - // Assign a model to the UserContent and add the ViewPort reference to it. - NJUtils.makeElementModel(this.documentRoot, "Stage", "stage"); - //this.documentRoot.elementModel.viewPort = this.iframe.contentWindow.document.getElementById("Viewport"); - - - - for(i = 0; i < this._stylesheets.length; i++) { - if(this._stylesheets[i].ownerNode.id === this._stageStyleSheetId) { - this.documentRoot.elementModel.defaultRule = this._stylesheets[i]; - break; - } - } - - //Temporary create properties for each rule we need to save the index of the rule - var len = this.documentRoot.elementModel.defaultRule.cssRules.length; - for(var j = 0; j < len; j++) { - //console.log(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText); - if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "*") { - - this.documentRoot.elementModel.transitionStopRule = this.documentRoot.elementModel.defaultRule.cssRules[j]; - - } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "body") { - - this.documentRoot.elementModel.body = this.documentRoot.elementModel.defaultRule.cssRules[j]; - - } - } - - this.callback(this); - - //Setting webGL data - if (this._templateDocument.webgl) { - this.glData = this._templateDocument.webgl; - } - } - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - - - - - }.bind(this), 1000); - } - }, - //////////////////////////////////////////////////////////////////// // handleEvent: { diff --git a/js/document/models/base.js b/js/document/models/base.js index 96156e64..8925fc40 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js @@ -21,6 +21,10 @@ exports.BaseDocumentModel = Montage.create(Montage, { file: { value: null }, + + _name: { + value: null + }, //////////////////////////////////////////////////////////////////// // njdata: { diff --git a/js/document/models/html.js b/js/document/models/html.js index 5882d389..ff57454b 100755 --- a/js/document/models/html.js +++ b/js/document/models/html.js @@ -7,10 +7,10 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot //////////////////////////////////////////////////////////////////////// // var Montage = require("montage/core/core").Montage, - TextDocumentModel = require("js/document/models/text").TextDocumentModel; + BaseDocumentModel = require("js/document/models/base").BaseDocumentModel; //////////////////////////////////////////////////////////////////////// // -exports.HtmlDocumentModel = Montage.create(TextDocumentModel, { +exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, { //////////////////////////////////////////////////////////////////// // hasTemplate: { diff --git a/js/document/templates/montage-web/default_html.css b/js/document/templates/montage-web/default_html.css index 05165898..db069d4e 100755 --- a/js/document/templates/montage-web/default_html.css +++ b/js/document/templates/montage-web/default_html.css @@ -10,17 +10,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot -webkit-animation-name: none !important; } -html{ - /*overflow:hidden;*/ -} - -body -{ - width: 100%; - height: 100%; - background: pink; -} - .active-element-outline { outline: #adff2f solid 2px; } diff --git a/js/document/templates/montage-web/index.html b/js/document/templates/montage-web/index.html index 60946aac..90b0f7fd 100755 --- a/js/document/templates/montage-web/index.html +++ b/js/document/templates/montage-web/index.html @@ -30,11 +30,19 @@ } + + - +
IPSUM
diff --git a/js/ninja.reel/ninja.js b/js/ninja.reel/ninja.js index 9b5081dd..2fedd71d 100755 --- a/js/ninja.reel/ninja.js +++ b/js/ninja.reel/ninja.js @@ -10,6 +10,7 @@ var Montage = require("montage/core/core").Montage, AppData = require("js/data/appdata").AppData; var matrix = require("js/lib/math/matrix"); +var NjUtils = require("js/lib/NJUtils").NJUtils; exports.Ninja = Montage.create(Component, { @@ -143,6 +144,7 @@ exports.Ninja = Montage.create(Component, { value: function() { this.ninjaVersion = window.ninjaVersion.ninja.version; this.undoManager = document.application.undoManager = UndoManager.create(); + document.application.njUtils = NjUtils; } }, @@ -187,28 +189,18 @@ exports.Ninja = Montage.create(Component, { willDraw: { value: function() { - } }, draw: { value: function() { if(this.isResizing) { - if (this.height - this._resizedHeight < 46) { - this.timelineSplitter.collapsed = true; - } else { - this.timelineSplitter.collapsed = false; - } - - if (this.width - this._resizedWidth < 30) { - this.panelSplitter.collapsed = true; - } else { - this.panelSplitter.collapsed = false; - } - + this.timelineSplitter.collapsed = this.height - this._resizedHeight < 46; + this.panelSplitter.collapsed = this.width - this._resizedWidth < 30; } - this.rightPanelContainer.style.width = (this.width - this._resizedWidth) + "px"; - this.timeline.element.style.height = (this.height - this._resizedHeight) + "px"; + + this.rightPanelContainer.style.width = (this.width - this._resizedWidth) + "px"; + this.timeline.element.style.height = (this.height - this._resizedHeight) + "px"; } }, diff --git a/js/panels/properties.reel/properties.js b/js/panels/properties.reel/properties.js index 7fab1eb0..f57982b6 100755 --- a/js/panels/properties.reel/properties.js +++ b/js/panels/properties.reel/properties.js @@ -187,7 +187,7 @@ exports.Properties = Montage.create(Component, { displayStageProperties: { value: function() { - /* + var stage = this.application.ninja.currentDocument.documentRoot; //this is test code please remove this.elementName.value = "Stage"; -- cgit v1.2.3