A.W.H.
Posts: 0
Joined: Sat Jun 20, 2015 7:02 am

Run Time setting of themes - color schemes

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.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Run Time setting of themes - color schemes

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.

A.W.H.
Posts: 0
Joined: Sat Jun 20, 2015 7:02 am

Run Time setting of themes - color schemes

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

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Run Time setting of themes - color schemes

Hello,

Your problem is not clear at this time.

Please specify more details about your problem.

Regards.

Return to “Issues”