aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--credits.html9
-rwxr-xr-xjs/document/html-document.js4
-rw-r--r--js/mediators/io-mediator.js61
-rwxr-xr-xjs/mediators/keyboard-mediator.js2
4 files changed, 45 insertions, 31 deletions
diff --git a/credits.html b/credits.html
index 1cc36c78..082eefd4 100644
--- a/credits.html
+++ b/credits.html
@@ -95,5 +95,14 @@
95 <li>License: <a href="http://www.opensource.org/licenses/mit-license.php" target="_blank">http://www.opensource.org/licenses/mit-license.php</a></li> 95 <li>License: <a href="http://www.opensource.org/licenses/mit-license.php" target="_blank">http://www.opensource.org/licenses/mit-license.php</a></li>
96 </ul> 96 </ul>
97 </div> 97 </div>
98
99 <div>
100 js-beautify
101 <ul>
102 <li>Written by Einar Lielmanis, <a href="mailto:einar@jsbeautifier.org">einar@jsbeautifier.org</a>. Python version flourished by <a href="http://github.com/satufk">Stefano Sanfilippo</a> with help from <a href="http://jason.diamond.name/weblog/">Jason&nbsp;Diamond</a>, Patrick&nbsp;Hof, Nochum&nbsp;Sossonko, Andreas&nbsp;Schneider, Dave&nbsp;Vasilevsky, <a href="http://my.opera.com/Vital/blog/">Vital&nbsp;Batmanov,</a> Ron&nbsp;Baldwin, Gabriel&nbsp;Harrison, <a href="http://shullian.com">Chris&nbsp;J.&nbsp;Shull</a>, <a href="http://mathiasbynens.be/">Mathias Bynens</a> and others.</li>
103 <li>Code from: <a href="https://github.com/einars/js-beautify" target="_blank">https://github.com/einars/js-beautify</a></li>
104 <li>License: <a href="https://github.com/einars/js-beautify/blob/master/license.txt" target="_blank">https://github.com/einars/js-beautify/blob/master/license.txt</a></li>
105 </ul>
106 </div>
98 </body> 107 </body>
99</html> \ No newline at end of file 108</html> \ No newline at end of file
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 76436732..75628731 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -679,6 +679,8 @@ exports.HTMLDocument = Montage.create(TextDocument, {
679 if(typeof this.application.ninja.selectedElements !== 'undefined'){ 679 if(typeof this.application.ninja.selectedElements !== 'undefined'){
680 this.selectionModel = this.application.ninja.selectedElements; 680 this.selectionModel = this.application.ninja.selectedElements;
681 } 681 }
682
683 this.draw3DGrid = this.application.ninja.appModel.show3dGrid;
682 } 684 }
683 }, 685 },
684 686
@@ -700,6 +702,8 @@ exports.HTMLDocument = Montage.create(TextDocument, {
700 this.application.ninja.stage._scrollLeft = this.savedTopScroll; 702 this.application.ninja.stage._scrollLeft = this.savedTopScroll;
701 } 703 }
702 this.application.ninja.stage.handleScroll(); 704 this.application.ninja.stage.handleScroll();
705
706 this.application.ninja.appModel.show3dGrid = this.draw3DGrid;
703 } 707 }
704 } 708 }
705 //////////////////////////////////////////////////////////////////// 709 ////////////////////////////////////////////////////////////////////
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 30180155..733e44b2 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -146,22 +146,27 @@ exports.IoMediator = Montage.create(Component, {
146 //Copy webGL library if needed 146 //Copy webGL library if needed
147 if (file.webgl.length > 0) { 147 if (file.webgl.length > 0) {
148 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { 148 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
149 //if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Assets' || this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') { 149 //Checking for RDGE library to be available
150 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') { 150 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') {
151 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(file.document.root, (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase()); 151 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(file.document.root, (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase());
152 } else {
153 //TODO: Error handle no available library to copy
152 } 154 }
153 } 155 }
154 } 156 }
155 // 157
158 //TODO: Add check for Monatage library to copy
159
160 //Getting content from function to properly handle saving assets (as in external if flagged)
156 contents = this.parseNinjaTemplateToHtml(file); 161 contents = this.parseNinjaTemplateToHtml(file);
157 break; 162 break;
158 default: 163 default:
159 contents = file.content; 164 contents = file.content;
160 break; 165 break;
161 } 166 }
162 // 167 //Making call to save file
163 save = this.fio.saveFile({uri: file.document.uri, contents: contents}); 168 save = this.fio.saveFile({uri: file.document.uri, contents: contents});
164 // 169 //Checking for callback
165 if (callback) callback(save); 170 if (callback) callback(save);
166 } 171 }
167 }, 172 },
@@ -170,7 +175,7 @@ exports.IoMediator = Montage.create(Component, {
170 fileSaveAs: { 175 fileSaveAs: {
171 enumerable: false, 176 enumerable: false,
172 value: function (copyTo, copyFrom, callback) { 177 value: function (copyTo, copyFrom, callback) {
173 // 178 //TODO: Implement Save As functionality
174 } 179 }
175 }, 180 },
176 //////////////////////////////////////////////////////////////////// 181 ////////////////////////////////////////////////////////////////////
@@ -178,7 +183,7 @@ exports.IoMediator = Montage.create(Component, {
178 fileDelete: { 183 fileDelete: {
179 enumerable: false, 184 enumerable: false,
180 value: function (file, callback) { 185 value: function (file, callback) {
181 // 186 //TODO: Implement Delete functionality
182 } 187 }
183 }, 188 },
184 //////////////////////////////////////////////////////////////////// 189 ////////////////////////////////////////////////////////////////////
@@ -205,7 +210,7 @@ exports.IoMediator = Montage.create(Component, {
205 //Getting all CSS (style or link) tags 210 //Getting all CSS (style or link) tags
206 var styletags = template.document.content.document.getElementsByTagName('style'), 211 var styletags = template.document.content.document.getElementsByTagName('style'),
207 linktags = template.document.content.document.getElementsByTagName('link'), 212 linktags = template.document.content.document.getElementsByTagName('link'),
208 url = new RegExp(chrome.extension.getURL('js/document/templates/montage-html/'), 'gi'); 213 url = new RegExp(chrome.extension.getURL('js/document/templates/montage-html/'), 'gi'); //TODO: Make public into var
209 //Looping through link tags and removing file recreated elements 214 //Looping through link tags and removing file recreated elements
210 for (var j in styletags) { 215 for (var j in styletags) {
211 if (styletags[j].getAttribute) { 216 if (styletags[j].getAttribute) {
@@ -313,7 +318,7 @@ exports.IoMediator = Montage.create(Component, {
313 webgltag.innerHTML = json; 318 webgltag.innerHTML = json;
314 } 319 }
315 // 320 //
316 return this.getPretyHtml(template.document.content.document.documentElement.outerHTML.replace(url, '')); 321 return this.getPrettyHtml(template.document.content.document.documentElement.outerHTML.replace(url, ''));
317 } 322 }
318 }, 323 },
319 //////////////////////////////////////////////////////////////////// 324 ////////////////////////////////////////////////////////////////////
@@ -333,14 +338,19 @@ exports.IoMediator = Montage.create(Component, {
333 //TODO: Add better logic for creating this string 338 //TODO: Add better logic for creating this string
334 url = new RegExp(chrome.extension.getURL('js/document/templates/montage-html/'), 'gi'); 339 url = new RegExp(chrome.extension.getURL('js/document/templates/montage-html/'), 'gi');
335 //Returning the CSS string 340 //Returning the CSS string
336 return this.getPretyCss(css.replace(url, '')); 341 return this.getPrettyCss(css.replace(url, ''));
337 } 342 }
338 }, 343 },
339 //////////////////////////////////////////////////////////////////// 344 ////////////////////////////////////////////////////////////////////
340 //Using prettification code from http://jsbeautifier.org 345 ////////////////////////////////////////////////////////////////////
346 //Pretty methods (minified)
341 /* 347 /*
342 Copyright (c) 2009 - 2011, Einar Lielmanis 348 is-beautify javascript code courtesy of Einar Lielmanis:
343 349 Code from https://github.com/einars/js-beautify
350 License https://github.com/einars/js-beautify/blob/master/license.txt
351 Used with author's permission, as stated below
352
353 Copyright (c) 2009 - 2011, Einar Lielmanis
344 Permission is hereby granted, free of charge, to any person 354 Permission is hereby granted, free of charge, to any person
345 obtaining a copy of this software and associated documentation 355 obtaining a copy of this software and associated documentation
346 files (the "Software"), to deal in the Software without 356 files (the "Software"), to deal in the Software without
@@ -348,30 +358,21 @@ exports.IoMediator = Montage.create(Component, {
348 copy, modify, merge, publish, distribute, sublicense, and/or sell 358 copy, modify, merge, publish, distribute, sublicense, and/or sell
349 copies of the Software, and to permit persons to whom the 359 copies of the Software, and to permit persons to whom the
350 Software is furnished to do so, subject to the following 360 Software is furnished to do so, subject to the following
351 conditions: 361 conditions:The above copyright notice and this permission notice shall be
352
353 The above copyright notice and this permission notice shall be
354 included in all copies or substantial portions of the Software. 362 included in all copies or substantial portions of the Software.
355 363 */
356 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 364 //For HTML, including any JS or CSS (single string/file)
357 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 365 getPrettyHtml: {
358 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
359 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
360 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
361 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
362 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
363 OTHER DEALINGS IN THE SOFTWARE.
364 */
365 getPretyHtml: {
366 enumerable: false, 366 enumerable: false,
367 value: function style_html(a,b){function h(){this.pos=0;this.token="";this.current_mode="CONTENT";this.tags={parent:"parent1",parentcount:1,parent1:""};this.tag_type="";this.token_text=this.last_token=this.last_text=this.token_type="";this.Utils={whitespace:"\n\r\t ".split(""),single_token:"br,input,link,meta,!doctype,basefont,base,area,hr,wbr,param,img,isindex,?xml,embed".split(","),extra_liners:"head,body,/html".split(","),in_array:function(a,b){for(var c=0;c<b.length;c++){if(a===b[c]){return true}}return false}};this.get_content=function(){var a="";var b=[];var c=false;while(this.input.charAt(this.pos)!=="<"){if(this.pos>=this.input.length){return b.length?b.join(""):["","TK_EOF"]}a=this.input.charAt(this.pos);this.pos++;this.line_char_count++;if(this.Utils.in_array(a,this.Utils.whitespace)){if(b.length){c=true}this.line_char_count--;continue}else if(c){if(this.line_char_count>=this.max_char){b.push("\n");for(var d=0;d<this.indent_level;d++){b.push(this.indent_string)}this.line_char_count=0}else{b.push(" ");this.line_char_count++}c=false}b.push(a)}return b.length?b.join(""):""};this.get_contents_to=function(a){if(this.pos==this.input.length){return["","TK_EOF"]}var b="";var c="";var d=new RegExp("</"+a+"\\s*>","igm");d.lastIndex=this.pos;var e=d.exec(this.input);var f=e?e.index:this.input.length;if(this.pos<f){c=this.input.substring(this.pos,f);this.pos=f}return c};this.record_tag=function(a){if(this.tags[a+"count"]){this.tags[a+"count"]++;this.tags[a+this.tags[a+"count"]]=this.indent_level}else{this.tags[a+"count"]=1;this.tags[a+this.tags[a+"count"]]=this.indent_level}this.tags[a+this.tags[a+"count"]+"parent"]=this.tags.parent;this.tags.parent=a+this.tags[a+"count"]};this.retrieve_tag=function(a){if(this.tags[a+"count"]){var b=this.tags.parent;while(b){if(a+this.tags[a+"count"]===b){break}b=this.tags[b+"parent"]}if(b){this.indent_level=this.tags[a+this.tags[a+"count"]];this.tags.parent=this.tags[b+"parent"]}delete this.tags[a+this.tags[a+"count"]+"parent"];delete this.tags[a+this.tags[a+"count"]];if(this.tags[a+"count"]==1){delete this.tags[a+"count"]}else{this.tags[a+"count"]--}}};this.get_tag=function(){var a="";var b=[];var c=false;do{if(this.pos>=this.input.length){return b.length?b.join(""):["","TK_EOF"]}a=this.input.charAt(this.pos);this.pos++;this.line_char_count++;if(this.Utils.in_array(a,this.Utils.whitespace)){c=true;this.line_char_count--;continue}if(a==="'"||a==='"'){if(!b[1]||b[1]!=="!"){a+=this.get_unformatted(a);c=true}}if(a==="="){c=false}if(b.length&&b[b.length-1]!=="="&&a!==">"&&c){if(this.line_char_count>=this.max_char){this.print_newline(false,b);this.line_char_count=0}else{b.push(" ");this.line_char_count++}c=false}b.push(a)}while(a!==">");var d=b.join("");var e;if(d.indexOf(" ")!=-1){e=d.indexOf(" ")}else{e=d.indexOf(">")}var f=d.substring(1,e).toLowerCase();if(d.charAt(d.length-2)==="/"||this.Utils.in_array(f,this.Utils.single_token)){this.tag_type="SINGLE"}else if(f==="script"){this.record_tag(f);this.tag_type="SCRIPT"}else if(f==="style"){this.record_tag(f);this.tag_type="STYLE"}else if(this.Utils.in_array(f,unformatted)){var g=this.get_unformatted("</"+f+">",d);b.push(g);this.tag_type="SINGLE"}else if(f.charAt(0)==="!"){if(f.indexOf("[if")!=-1){if(d.indexOf("!IE")!=-1){var g=this.get_unformatted("-->",d);b.push(g)}this.tag_type="START"}else if(f.indexOf("[endif")!=-1){this.tag_type="END";this.unindent()}else if(f.indexOf("[cdata[")!=-1){var g=this.get_unformatted("]]>",d);b.push(g);this.tag_type="SINGLE"}else{var g=this.get_unformatted("-->",d);b.push(g);this.tag_type="SINGLE"}}else{if(f.charAt(0)==="/"){this.retrieve_tag(f.substring(1));this.tag_type="END"}else{this.record_tag(f);this.tag_type="START"}if(this.Utils.in_array(f,this.Utils.extra_liners)){this.print_newline(true,this.output)}}return b.join("")};this.get_unformatted=function(a,b){if(b&&b.indexOf(a)!=-1){return""}var c="";var d="";var e=true;do{if(this.pos>=this.input.length){return d}c=this.input.charAt(this.pos);this.pos++;if(this.Utils.in_array(c,this.Utils.whitespace)){if(!e){this.line_char_count--;continue}if(c==="\n"||c==="\r"){d+="\n";this.line_char_count=0;continue}}d+=c;this.line_char_count++;e=true}while(d.indexOf(a)==-1);return d};this.get_token=function(){var a;if(this.last_token==="TK_TAG_SCRIPT"||this.last_token==="TK_TAG_STYLE"){var b=this.last_token.substr(7);a=this.get_contents_to(b);if(typeof a!=="string"){return a}return[a,"TK_"+b]}if(this.current_mode==="CONTENT"){a=this.get_content();if(typeof a!=="string"){return a}else{return[a,"TK_CONTENT"]}}if(this.current_mode==="TAG"){a=this.get_tag();if(typeof a!=="string"){return a}else{var c="TK_TAG_"+this.tag_type;return[a,c]}}};this.get_full_indent=function(a){a=this.indent_level+a||0;if(a<1)return"";return Array(a+1).join(this.indent_string)};this.printer=function(a,b,c,d,e){this.input=a||"";this.output=[];this.indent_character=b;this.indent_string="";this.indent_size=c;this.brace_style=e;this.indent_level=0;this.max_char=d;this.line_char_count=0;for(var f=0;f<this.indent_size;f++){this.indent_string+=this.indent_character}this.print_newline=function(a,b){this.line_char_count=0;if(!b||!b.length){return}if(!a){while(this.Utils.in_array(b[b.length-1],this.Utils.whitespace)){b.pop()}}b.push("\n");for(var c=0;c<this.indent_level;c++){b.push(this.indent_string)}};this.print_token=function(a){this.output.push(a)};this.indent=function(){this.indent_level++};this.unindent=function(){if(this.indent_level>0){this.indent_level--}}};return this}var c,d,e,f,g;b=b||{};d=b.indent_size||4;e=b.indent_char||" ";g=b.brace_style||"collapse";f=b.max_char||"70";unformatted=b.unformatted||["a"];c=new h;c.printer(a,e,d,f,g);while(true){var i=c.get_token();c.token_text=i[0];c.token_type=i[1];if(c.token_type==="TK_EOF"){break}switch(c.token_type){case"TK_TAG_START":c.print_newline(false,c.output);c.print_token(c.token_text);c.indent();c.current_mode="CONTENT";break;case"TK_TAG_STYLE":case"TK_TAG_SCRIPT":c.print_newline(false,c.output);c.print_token(c.token_text);c.current_mode="CONTENT";break;case"TK_TAG_END":if(c.last_token==="TK_CONTENT"&&c.last_text===""){var j=c.token_text.match(/\w+/)[0];var k=c.output[c.output.length-1].match(/<\s*(\w+)/);if(k===null||k[1]!==j)c.print_newline(true,c.output)}c.print_token(c.token_text);c.current_mode="CONTENT";break;case"TK_TAG_SINGLE":c.print_newline(false,c.output);c.print_token(c.token_text);c.current_mode="CONTENT";break;case"TK_CONTENT":if(c.token_text!==""){c.print_token(c.token_text)}c.current_mode="TAG";break;case"TK_STYLE":case"TK_SCRIPT":if(c.token_text!==""){c.output.push("\n");var l=c.token_text;if(c.token_type=="TK_SCRIPT"){var m=typeof js_beautify=="function"&&js_beautify}else if(c.token_type=="TK_STYLE"){var m=typeof css_beautify=="function"&&css_beautify}if(b.indent_scripts=="keep"){var n=0}else if(b.indent_scripts=="separate"){var n=-c.indent_level}else{var n=1}var o=c.get_full_indent(n);if(m){l=m(l.replace(/^\s*/,o),b)}else{var p=l.match(/^\s*/)[0];var q=p.match(/[^\n\r]*$/)[0].split(c.indent_string).length-1;var r=c.get_full_indent(n-q);l=l.replace(/^\s*/,o).replace(/\r\n|\r|\n/g,"\n"+r).replace(/\s*$/,"")}if(l){c.print_token(l);c.print_newline(true,c.output)}}c.current_mode="TAG";break}c.last_token=c.token_type;c.last_text=c.token_text}return c.output.join("")} 367 value: function (a,b){function h(){this.pos=0;this.token="";this.current_mode="CONTENT";this.tags={parent:"parent1",parentcount:1,parent1:""};this.tag_type="";this.token_text=this.last_token=this.last_text=this.token_type="";this.Utils={whitespace:"\n\r\t ".split(""),single_token:"br,input,link,meta,!doctype,basefont,base,area,hr,wbr,param,img,isindex,?xml,embed".split(","),extra_liners:"head,body,/html".split(","),in_array:function(a,b){for(var c=0;c<b.length;c++){if(a===b[c]){return true}}return false}};this.get_content=function(){var a="";var b=[];var c=false;while(this.input.charAt(this.pos)!=="<"){if(this.pos>=this.input.length){return b.length?b.join(""):["","TK_EOF"]}a=this.input.charAt(this.pos);this.pos++;this.line_char_count++;if(this.Utils.in_array(a,this.Utils.whitespace)){if(b.length){c=true}this.line_char_count--;continue}else if(c){if(this.line_char_count>=this.max_char){b.push("\n");for(var d=0;d<this.indent_level;d++){b.push(this.indent_string)}this.line_char_count=0}else{b.push(" ");this.line_char_count++}c=false}b.push(a)}return b.length?b.join(""):""};this.get_contents_to=function(a){if(this.pos==this.input.length){return["","TK_EOF"]}var b="";var c="";var d=new RegExp("</"+a+"\\s*>","igm");d.lastIndex=this.pos;var e=d.exec(this.input);var f=e?e.index:this.input.length;if(this.pos<f){c=this.input.substring(this.pos,f);this.pos=f}return c};this.record_tag=function(a){if(this.tags[a+"count"]){this.tags[a+"count"]++;this.tags[a+this.tags[a+"count"]]=this.indent_level}else{this.tags[a+"count"]=1;this.tags[a+this.tags[a+"count"]]=this.indent_level}this.tags[a+this.tags[a+"count"