How to change the theme of an existing application developed using jquery-mobile? - jquery-mobile

I am building an application using jquery mobile and phone gap. As I am about to start the application, have a doubt on how to change the theme of an application on the fly or with minimum changes involved so that I can use the same app with different themes for different client.
Please let me know is there a configuration or common place available to update/change the theme of an entire application at any moment during the development.
EDIT: sorry to confuse a bit, the question is with how to switch between the themes provided by default by jquery mobile like a, b, c, d and e without doing any or much code change.
Thanks.

jQuery Mobile has 3 different CSS files, you can get them when you download whole package.
jQuery Mobile CSS file
jQuery Mobile Structure CSS file
jQuery Mobile Theme CSS file
If you want to use different themes all you need to do is use second and third mentioned file. Structure CSS holds jQuery Mobile structure CSS and it is a backbone of whole structure. What you need to change is jQuery Mobile theme CSS file. This is a file you get when you create a new theme.
On the other hand jQuery Mobile will have several more CSS files but logic is the same. If you download jQuery Mobile from this link: http://jquerymobile.com/
You will find these files:
jquery.mobile.external-png-1.4.2.min.css
jquery.mobile.icons-1.4.2.min.css
jquery.mobile.inline-png-1.4.2.min.css
jquery.mobile.inline-svg-1.4.2.min.css
jquery.mobile.structure-1.4.2.min.css
jquery.mobile.theme-1.4.2.min.css
jquery.mobile-1.4.2.min.css
If you want to use customized themes you will need to remove jquery.mobile-1.4.2.min.css and jquery.mobile.theme-1.4.2.min.css. Theme builder will give you new jquery.mobile.theme-1.4.2.min.css file, or even if you download it from somewhere you will get alternative jquery.mobile.theme-1.4.2.min.css file.
Update
Working example: http://jsfiddle.net/Gajotres/LfLFm/
JavaScript:
$(document).on('pagebeforecreate', '#index',function (e, ui) {
$(this).removeClass('ui-page-theme-a').addClass('ui-page-theme-b');
});
or even better: http://jsfiddle.net/Gajotres/ML2F6/
$(document).on('pagebeforecreate', '#index',function (e, ui) {
$(this).page({theme:'b'});
});

You can simply do it through .page({ theme : "a, b, c" }) widget. It will change the whole page's theme.
$(document).on("pagecreate", function () {
$(".selector").on("click", function () {
$.mobile.pageContainer.pagecontainer("getActivePage").page({
theme: "b"
});
});
});
Demo

Related

How can i disable link styling?

How can I completely disable jquery mobile styling for certain container?
I am using data-enhance="false" for container along with javascript code:
$(document).bind("mobileinit", function() {
$.mobile.ignoreContentEnabled = true;
});
Yet some jquery mobile styling remains, for example link color:
.ui-page-theme-a a{
color: #38C;
font-weight: 700;}
I had to overwrite these css rules manually, it is pretty cumbersome.
if you have less CSS to overwrite, then overwriting same classes in our css with !important is best way.
If you are overwriting many classes then don't include jQuery mobile theme CSS just use jQuery mobile structure CSS as its requires for some functionalities such as transition and all.
One more option modify Jquery theme CSS as requires means remove unwanted class as jquery mobile is open source you are good on this.

styling "pseudo-element" using Dart lang

I'm building a ctusom element with DART, and styling it without using seperate css file, using the ..style as below:
innerInput = new InputElement()
..style.color= '#FF8F66'
..style.fontFamily='openSansItalic';
I want to use "pseudo-element" styling, like styling the 'placeholder', 'before', 'after' ,... is there a way to do it using dart, or I've to use separate css file, thanks
Seems these can only be read using code innerInput.getComputedStyle(':after').content but not changed but you can create stylesheet rules by code (like the one built from CSS) How to create CSS keyframe rule in Dart

Jquery UI datepicker not working with handsontable

I have a page with handsontable and the jquery UI datapicker component ?
By themselves, they work fine.
Jquery UI datepicker, http://jsfiddle.net/7Bvap/355/
$( "#datepicker" ).datepicker();
Handsontable , http://jsfiddle.net/ngpxZ/
But when I put them together,
the datepicker doesnt work (as in the calendar doesnt pop out)
http://jsfiddle.net/cuj3V/
I found a similar problem here,
https://github.com/warpech/jquery-handsontable/issues/498
For page with handsontable as workaround I'm reloading jquery ui css after handson table css and works fine.
So I placed the handsontable.css before the jqueryui.css. But still no avail. Anyone can help ?
Looks like there was a problem with the jsFiddle including the scripts/styles in the css section. You should not need to use the CSS section to include external files. Use the "External Resources" menu instead
external resources
Datepicker and handsontable jsFiddle

How to dynamically import css with backbone?

I'm developing a app, using backbone, underscore, and jquerymobile. Following jqmobile's way, I have an index page which loads every visited page in special divs tags, flagged with the attribute data-role="page". For each page, i have its corresponding style file (or code snippet embedded in a style html tag). My problem is that the names of my stylable stuff started to collide. Other thing is that I would not like unnecessary style files loaded for each page. Is there any way of dynamically import only the required css for the current page?
I am accomplishing exactly what you ask using RequireJS and the RequireCSS plugin.
Here is a snippet from one of my views:
define([
'jquery',
'underscore',
'backbone',
'views/company/form',
'text!templates/company/company.html',
'css!../../../css/company/company',
], function($, _, Backbone, Form, pageTemplate) {
var Page = Backbone.View.extend({
...
});
return Page;
});
Line 7, 'css!../../../css/company/company' is where the css file becomes a requirement for loading this view.
Once the company.css stylesheet is loaded, it's in the browser even when other "pages" load because there are no actual page refreshes. Thus I have my main page views toggle a class on the <html> element:
// remove any old route-* classes existing on the html element
$('html').removeClassRegEx(/^route-.*/);
// add in the company's top-level class name
$('html').addClass('route-company');
And all my page-specific styles for the company page are scoped to the .route-company class.
You can find the jQuery plugin removeClassRegEx here.
One way of doing that is with jquery (which you 90% are already using with backbone), and its load or get ajax functions, or whatever, plus callbacks.
Then you can call such functions from your backbone app if you need to, and simply inject that css inside <style> tags into your document, as a template.
Or I think there are also specialized jquery functions.
Another way I can think of doing that would be with require.js and it's plugins (it has text plugin, I believe, which will also enable you to load your javascript templates).

Nothing works! jquery conflict magento

I am trying to use jquery UI based transition sliders on my homepage. I tried different jquery plugins but I always get an error in the console : jQuery is not a function or some function error related to jQuery . Plugins i have tried are Lof JSliderNews 1.0,featured-content-slider, etc..
Even after following several posts on the web , iam not able to make the plugin work at all. Jquery part doesn't work. I have used carousels and other plugins with jquery.noConflict but this time nothing works!
Here's what iam doing:
jQuery.noConflict();
jQuery(document).ready(function(){
jQuery("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
});
I also tried replacing all $ with jQuery in the included scripts but that too doesn't work in magento. Please help, i need to finish the project soon
Have you tried putting all the jQuery stuff into a function and map the window.jQuery variable as an argument? Like so:
(function($){
//... do your jQuery thing here
})(jQuery);
BTW: "jQuery is not a function" might also be a hint that you forgot to load the jQuery library into your project.
Do you have "JS file merging" enabled? If yes, try to disable it, clear your cache and try again. It helped me once when I had a smiliar issue.
Regards

Resources