/************** LESS modifyVars 1.3 *************** Copyright (c) 2012, Zoran Kenda Licensed under the Apache 2.0 License. Modified version of less.js is required. I tried to keep modifications at minumum to ensure future versions compatibility. Modifications in less.js (v.1.3): --- function loadStyleSheets(callback, reload) { less.roots = []; //modification 1 ln 3224 --- function loadStyleSheet( ... }).parse(data, function (e, root) { if (e) { return error(e, href) } try { less.roots.push({root: root, sheet : sheet}); //modification 2 ln:3267 <--- Usage: var modifications= { "@baseRotation": function(){ index+=3; return index; }, "@headerColor": "#08c", "@footerColor":{value:"spin(@headerColor,150 + @baseRotation)",type:"expression"}, "@focusImage":"focus1.png?a.h=@{baseRotation}" } less.modify(modifications); ************************************************/ (function (window, undefined) { if(!less){ console.log("Less.js not loaded. exiting"); return; } less.modify = function(modifications){ if(!less.roots || less.roots.length==0) less.refresh(true); if(!less.roots) { console.log("less.roots is null. Are you using an unmodified version of less.js?"); return; } for(var i = 0;i0)) && value.charAt(0)=="#"){ //barva je variable.value = getColor(value); modified = true; } else if(type=="expression"){ new( less.Parser)().parse("@tempExpr:"+value+";",function(e,f){ variable.value = f.variable("@tempExpr").value; }); modified = true; } else if(type =="string"){ //barva je variable.value = getLiteral(value); modified = true; } else{ console.log("ni rbg, ni number, ni literal"); } }catch(e){ console.log(e); } console.log("modified var "+name); } } if(modified) createCSS(root.toCSS(), sheet); } } /* values to expressions */ function getValue(val){ return new(less.tree.Value)([new(less.tree.Expression)([val])]); } function getDimension(val){ return getValue(new(less.tree.Dimension)(val)); } function getColor(val){ var rgb; if ( (val.charAt(0) === '#') && (rgb = (/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})/).exec(val)) ) { val = rgb[1]; } return getValue(new(less.tree.Color)(val)); } function getLiteral(val){ return getValue(new(less.tree.Quoted)("'",val,false)); } /******************* Slightly modified functions taken from less.js ***************/ //copied from less.js and modified a little (removed cache update code) function createCSS(styles, sheet) { var css; // Strip the query-string var href = sheet.href ? sheet.href.replace(/\?.*$/, '') : ''; // If there is no title set, use the filename, minus the extension var id = 'less:' + (sheet.title || extractId(href)); // If the stylesheet doesn't exist, create a new node if ((css = document.getElementById(id)) === null) { css = document.createElement('style'); css.type = 'text/css'; css.media = sheet.media || 'screen'; css.id = id; document.getElementsByTagName('head')[0].appendChild(css); } if (css.styleSheet) { // IE try { css.styleSheet.cssText = styles; } catch (e) { throw new(Error)("Couldn't reassign styleSheet.cssText."); } } else { (function (node) { if (css.childNodes.length > 0) { if (css.firstChild.nodeValue !== node.nodeValue) { css.replaceChild(node, css.firstChild); } } else { css.appendChild(node); } })(document.createTextNode(styles)); } } //copied from less.js 1.3 function extractId(href) { return href.replace(/^[a-z]+:\/\/?[^\/]+/, '' ) // Remove protocol & domain .replace(/^\//, '' ) // Remove root / .replace(/\?.*$/, '' ) // Remove query .replace(/\.[^\.\/]+$/, '' ) // Remove file extension .replace(/[^\.\w-]+/g, '-') // Replace illegal characters .replace(/\./g, ':'); // Replace dots with colons(for valid id) } })(window);