/*
yasep/dev/compact.js created by whygee at f-cpu.org
This file is distributed under terms of the Affero GPL v3 license or later, see http://yasep.org
created 2011-11-14 from yasep/defora/gen_asm.js
jeu. sept. 6 12:19:38 CEST 2012 : changed the .replace,
using string location/copy/paste instead.
Add a menu button, with key "compact", to create a window that
creates and saves compacted versions of the CSS and JS source code.
*/
INIT(compact={
getCSS: function() {
s="";
for (var i in css_list)
s+=import_data(css_list[i]+'.css')+"\n";
return s;
},
getJS: function() {
var s="";
for (var i in js_list)
if (js_list[i][1]==1) // prod ?
s+=import_data(js_list[i][2]+'.js')+";";
return s;
},
start: function() {
var pre = dcE('pre'),
s=I8N("s")+" ";
pre.innerHTML=' '
+' '
+' '
+' '
+' '
+' '
+' Debug \\n ';
compact.dbg=getById("minimize_dbg",null,pre);
// hook the actions :
getById("save_CSS",null,pre).onclick=function(){
SaveFile.save("index.prod.css",minimize(compact.getCSS(), "noSubst", compact.dbg.checked, true));
};
getById("save_JS",null,pre).onclick=function(){
SaveFile.save("index.prod.js",minimize(compact.getJS(), null, compact.dbg.checked, false));
};
getById("save_JSns",null,pre).onclick=function(){
SaveFile.save("index.prod.ns.js",minimize(compact.getJS(), "noSubst", compact.dbg.checked, false));
};
getById("save_report",null,pre).onclick=function(){
SaveFile.save("index.prod.js.txt",minimize(compact.getJS(), "report", false));
};
getById("save_HTML",null,pre).onclick=function(){
var i, tag='',
html=import_data("index.dev.html");
if (!html) // REMOVE
return Al8N("rhg","",html);
i=html.indexOf(tag);
if (i<0)
return Al8N("ftag");
html=html.slice(0,i)
+'"
+html.slice(i+tag.length);
SaveFile.save("index.html",html);
};
getById("save_nano",null,pre).onclick=function(){
var nanorc=import_data("js.nanorc");
var nanoKeyWords = "color green \"\\<(" + JSkeyWords.replace(/ /g,"|") + ")\\>\"";
var nanoAliasable = "color red \"\\<(" + Aliasable.replace(/ /g,"|") + ")\\>\"";
var nanoMethods = "color magenta \"\\<(" + (JS_Methods+" "+DynamicBlackListWords).replace(/ /g,"|") + ")\\>\"";
nanorc = nanorc.replace(/color green .*/ , nanoKeyWords);
nanorc = nanorc.replace(/color red .*/ , nanoAliasable);
nanorc = nanorc.replace(/color magenta .*/ , nanoMethods);
SaveFile.save("js.nanorc",nanorc); // \r\n is added instead of just \n and nano complains
};
return(compact.win= ygwm.new_window( "Compact the website's files", null, pre,
350, 300, 350, 70, false, true, true, true, false, "doc_gryl"));
},
INIT_func: function() {
menu.subMenuItem(menu.list["Dev"], i8n.cpt, "compact");
}
});
// not to be registered when the site is already compacted
winman.register_key("compact",compact.start,1);