/*
_/ _/_/ _/_/_/_/_/ _/
_/ _/ _/ _/_/ _/ _/ _/_/_/ _/_/_/
_/ _/ _/_/ _/ _/ _/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
_/ _/_/ _/ _/ _/_/ _/_/_/ _/_/_/ _/ _/
_/
_/
Documentation and issue tracking on Google Code
(c) 2011 by jQTouch project members.
See LICENSE.txt for license.
*/
(function($) {
if ($.jQTouch) {
var scriptpath = $("script").last().attr("src").split('?')[0].split('/').slice(0, -1).join('/')+'/';
$.jQTouch.addExtension(function ThemeSwitcher(jQT) {
var current,
link,
titles = {},
defaults = {
themeStyleSelector: 'link[rel="stylesheet"][title]',
themeIncluded: [
{title: 'jQTouch', href: scriptpath + '../themes/css/jqtouch.css'},
{title: 'Apple', href: scriptpath + '../themes/css/apple.css'},
{title: 'Vanilla', href: scriptpath + '../themes/css/vanilla.css'}
]
},
options = $.extend({}, defaults, jQT.settings);
function setStyleState(item, title) {
var $item = $(item);
if ($item.attr('title') === title) {
item.disabled = false; // workaround for Firefox on Zepto
$item.removeAttr('disabled');
} else {
item.disabled = true; // workaround for Firefox on Zepto
$item.attr('disabled', true);
}
}
function initializeStyleState(item, title) {
// and, workaround for WebKit by initializing the 'disabled' attribute
if (!current) {
current = title;
}
setStyleState(item, current);
}
// public
function switchStyle(title) {
current = title;
$(options.themeStyleSelector).each(function(i, item) {
setStyleState(item, title);
});
}
// collect title names, from
$(options.themeStyleSelector).each(function(i, item) {
var $item = $(item);
var title = $item.attr('title');
titles[title] = true;
initializeStyleState(item, title);
});
// add included theme
for (var i=0; i < options.themeIncluded.length; i++) {
var hash = options.themeIncluded[i];
if (!(hash.title in titles)) {
link = $('');
$('head').append($(link));
titles[hash.title] = true;
initializeStyleState(link, hash.title);
}
}
if (options.themeSelectionSelector) {
// create UI items
for (var title in titles) {
var $item = $('