set theme on load

This commit is contained in:
rolux 2011-04-23 18:45:50 +02:00
parent b58c7b0ce7
commit d8d14cffe7
79 changed files with 136 additions and 97 deletions

View file

@ -2,12 +2,12 @@ console.log('calling Ox.UI()')
//console.log('Ox =', Ox) //console.log('Ox =', Ox)
//console.log('Ox.UI =', Ox.UI) //console.log('Ox.UI =', Ox.UI)
Ox.UI({display: 'modern'}, function() { Ox.UI({display: 'icon', theme: 'modern'}, function() {
console.log('running Ox.UI()') console.log('running Ox.UI()')
//console.log('Ox =', Ox) //console.log('Ox =', Ox)
Ox.theme('modern'); // Ox.theme('modern');
//Ox.print('$$$$', Ox.Calendar) //Ox.print('$$$$', Ox.Calendar)

View file

@ -10,6 +10,39 @@
set theme to 'foo' set theme to 'foo'
*/ */
Ox.Theme = function(theme) {
return theme ? setTheme(theme) : getTheme();
function getTheme() {
var theme = '';
Ox.forEach(Ox.UI.$body.attr('class').split(' '), function(className) {
if (Ox.startsWith(className, 'OxTheme')) {
theme = className.replace('OxTheme', '').toLowerCase();
return false;
}
});
return theme;
}
function setTheme(theme) {
var currentTheme = getTheme();
if (theme != currentTheme) {
Ox.UI.$body.addClass('OxTheme' + Ox.toTitleCase(theme));
$('img').add('input[type=image]').each(function() {
var $this = $(this);
$this.attr({
src: $this.attr('src')
.replace('ox.ui.' + currentTheme, 'ox.ui.' + theme)
});
});
}
return Ox.Theme;
}
};
/*
Ox.UI.ready(function() { Ox.UI.ready(function() {
Ox.theme = function() { Ox.theme = function() {
@ -63,4 +96,4 @@ Ox.UI.ready(function() {
}); });
*/

View file

@ -22,13 +22,19 @@ Provides function Ox.UI([options], callback) that fires when
head = document.getElementsByTagName('head')[0], head = document.getElementsByTagName('head')[0],
logs = [], logs = [],
oxUICallback = function() {}, oxUICallback = function() {},
oxUIDefaults = {
// 'classic', 'modern', 'console' or 'none'
display: 'classic'
},
oxUIFunction = function(options, callback) { oxUIFunction = function(options, callback) {
var key;
oxUICallback = arguments.length == 2 ? callback : options; oxUICallback = arguments.length == 2 ? callback : options;
oxUIOptions = arguments.length == 2 && options ? options : oxUIDefaults; if (arguments.length == 2) {
for (key in oxUIOptions) {
oxUIOptions[key] = options[key] || oxUIOptions[key];
}
}
},
oxUIOptions = {
// 'icon', 'console' or 'none'
display: 'none',
theme: 'classic'
}; };
files.forEach(function(file, i) { files.forEach(function(file, i) {
@ -200,10 +206,9 @@ Provides function Ox.UI([options], callback) that fires when
{name: 'Chrome', url: 'http://www.google.com/chrome/', version: 10}, {name: 'Chrome', url: 'http://www.google.com/chrome/', version: 10},
{name: 'Firefox', url: 'http://www.mozilla.org/firefox/', version: 4}, {name: 'Firefox', url: 'http://www.mozilla.org/firefox/', version: 4},
{name: 'Safari', url: 'http://www.apple.com/safari/', version: 5} {name: 'Safari', url: 'http://www.apple.com/safari/', version: 5}
], ]
options = oxUIOptions || oxUIDefaults;
if (options.display != 'none') { if (oxUIOptions.display != 'none') {
body = getElement('body'); body = getElement('body');
css = { css = {
position: 'absolute', position: 'absolute',
@ -216,7 +221,7 @@ Provides function Ox.UI([options], callback) that fires when
WebkitUserSelect: 'none' WebkitUserSelect: 'none'
}; };
div = getElement('<div>') div = getElement('<div>')
.addClass(options.display == 'console' ? 'console' : '') .addClass(oxUIOptions.display == 'console' ? 'console' : '')
.css({ .css({
position: 'absolute', position: 'absolute',
left: 0, left: 0,
@ -225,10 +230,10 @@ Provides function Ox.UI([options], callback) that fires when
bottom: 0, bottom: 0,
padding: '4px', padding: '4px',
background: 'rgb(' + ( background: 'rgb(' + (
options.display == 'classic' ? '240, 240, 240' : '16, 16, 16') oxUIOptions.theme == 'classic' ? '240, 240, 240' : '16, 16, 16')
+ ')', + ')',
opacity: 1, opacity: 1,
overflow: options.display == 'console' ? 'auto' : 'hidden', overflow: oxUIOptions.display == 'console' ? 'auto' : 'hidden',
zIndex: 1000 zIndex: 1000
}) })
.appendTo(body); .appendTo(body);
@ -255,11 +260,11 @@ Provides function Ox.UI([options], callback) that fires when
function start() { function start() {
var image, src; var image, src;
if (options.display == 'console') { if (oxUIOptions.display == 'console') {
log('Loading additional scripts and images...') log('Loading additional scripts and images...')
} else { } else if (oxUIOptions.display == 'icon') {
image = new Image(), image = new Image(),
src = path + 'svg/ox.ui.' + options.display + '/symbolLoading.svg'; src = path + 'svg/ox.ui.' + oxUIOptions.theme + '/symbolLoading.svg';
image.onload = function() { image.onload = function() {
getElement('<img>') getElement('<img>')
.attr({ .attr({
@ -287,11 +292,11 @@ Provides function Ox.UI([options], callback) that fires when
i == userAgents.length - 2 ? ' or' : ',' i == userAgents.length - 2 ? ' or' : ','
); );
}).join(' '); }).join(' ');
if (options.display == 'none') { if (oxUIOptions.display == 'none') {
throw new Error(message); throw new Error(message);
} else { } else {
div.addClass('error'); div.addClass('error');
if (options.display == 'console') { if (oxUIOptions.display == 'console') {
log(message); log(message);
log = function() {}; log = function() {};
} else { } else {
@ -421,6 +426,7 @@ Provides function Ox.UI([options], callback) that fires when
Ox.UI.$document = $(document); Ox.UI.$document = $(document);
Ox.UI.$head = $('head'); Ox.UI.$head = $('head');
Ox.UI.$window = $(window); Ox.UI.$window = $(window);
Ox.UI.$body.addClass('OxTheme' + Ox.toTitleCase(oxUIOptions.theme));
documentReadyCallbacks.forEach(function(callback) { documentReadyCallbacks.forEach(function(callback) {
callback(); callback();
}); });