Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any easy way to switch themes dynamically with JQuery Mobile?

Like the question says, is there some way I can go about switching themes in JQuery Mobile dynamically. I just upgraded to beta 1 today and thought it would be cool if the user could pick there own theme if they want. I haven't seen anything in the documentation to do this specifically, but certainly there is some way to go about it, if someone could just point me in the right direction.

like image 810
Caimen Avatar asked Jun 22 '11 20:06

Caimen


People also ask

Is jQuery Mobile outdated?

The team announced that the cross-platform jQuery Mobile project under its umbrella will be fully deprecated as of October 7, 2021. New technologies for mobile app development have evolved since this project was launched in 2010, so we're encouraging developers to plan for this jQuery Mobile transition.

Does jQuery Mobile depend on jQuery?

However, jQuery Mobile is a full framework which is built on jQuery and jQuery UI foundation. It makes use of features of both jQuery and jQueryUI to provide both UI components and API features for building mobile-friendly sites.

How does jQuery Mobile work?

jQuery Mobile is a HTML5-based user interface system designed to make responsive web sites and apps that are accessible on all smartphone, tablet and desktop devices. It is built on the rock-solid jQuery and jQuery UI foundation, and offers Ajax navigation with page transitions, touch events, and various widgets.


2 Answers

Hardly sure, but it looks to me like jQuery Mobile's demo has a little theme switcher right inside it. Looks like this is the code that calls it:

$("#someElement").bind("vclick", function() {
    $.themeswitcher();
});

You can find the theme switcher's code right here.

Didn't mess around with it, but this sure looks like what you're talking about.

like image 195
Evan Hahn Avatar answered Oct 19 '22 18:10

Evan Hahn


I use a dropdown to allow my users to choose a theme. Here is the code I use for that:

  function changeTheme() {
    var theme = $("#ddlTheme :selected").val();
    var cssUrl = 'css/themes/' + theme + '/jquery-ui-1.8.13.custom.css';

    var themeStyle = $("#theme-style");
    themeStyle.attr({
        rel:  "stylesheet",
        type: "text/css",
        href: cssUrl
    }); 

  }

Create a <link> tag with the id "theme-style". Make it point to your default link.

I use theme roller to create my themes and add them to a sub directory under my css/themes directory named for the theme it represents. I place this value in the dropdown to display to the users.

like image 38
SRM Avatar answered Oct 19 '22 18:10

SRM