Page 2 of 2

Run Time setting of themes - color schemes

Posted: Sun Aug 02, 2015 9:18 pm
by A.W.H.

Ilya, could you please give an example code block for how one might do that? That's a lot of code and I don't want to mess something up.


Run Time setting of themes - color schemes

Posted: Mon Aug 10, 2015 4:58 am
by Yurii Orishchuk

Hi Ave,

Please try following solution:

1 Import needed themes.
Details: http://prntscr.com/82rygl/direct

2 Create new JS asset.

3 Populate it with following JS code:

precode

var themes = [
"dendrite",
"ios-like",
"gelato",
"flat-ui",
"ios7",
"jqm",
"jqm-classic",
"olive",
"pastel",
"winter"
];

var GetThemeUrl = function(themeName, isFull){
var currentAppPath = location.pathname.replace(/\/[\/]*$/gi, "");

Code: Select all

 var cssUrl = (isFull ? (currentAppPath + "/") : "") + "files/resources/lib/theme/" + themeName + "/" + themeName + ".css&quot 

 return cssUrl; 

};

var ActivateTheme = function(themeName){

Code: Select all

 //Remove all avaliable themes. 
 for(var i = 0; i < themes&#46;length; i++){ 
     var cssRelatedUrl = GetThemeUrl(themes[i]); 
     jQuery('link[href="' + cssRelatedUrl + '"]')&#46;remove(); 
     console&#46;log("cssRelatedUrl = " + cssRelatedUrl + " = " + themes[i]); 
 }; 

 &#47;&#47;Add new css&#46; 
 var goalThemeUrl = GetThemeUrl(themeName, true); 
 var newCss = jQuery("<link>"); 
 newCss&#46;attr("rel", "stylesheet"); 
 newCss&#46;attr("href", goalThemeUrl); 
 jQuery("head")&#46;append(newCss); 

};

/code/pre

4 Okay now you can use following code to change theme in runtime when you need on any event:

precode

&#47;&#47;to Activate "ios-like" theme&#46;
ActivateTheme("ios-like");
&#47;&#47;to Activate "winter" theme&#46;
&#47;&#47;ActivateTheme("winter");
&#47;&#47;You can use any theme name from array from 1st step&#46;

/code/pre

Regards.


Run Time setting of themes - color schemes

Posted: Tue Aug 11, 2015 8:32 pm
by A.W.H.

How do I make sure when the user reloads the app their preferences remain?


Run Time setting of themes - color schemes

Posted: Mon Aug 24, 2015 5:40 am
by Yurii Orishchuk

Hello,

Your problem is not clear at this time.

Please specify more details about your problem.

Regards.