2011-04-25 09:12:02 +00:00
|
|
|
Ox.load.UI = function(options, callback) {
|
|
|
|
|
|
|
|
options = Ox.extend({
|
2011-04-27 19:24:33 +00:00
|
|
|
debug: false,
|
2011-04-25 09:12:02 +00:00
|
|
|
hideScreen: true,
|
2011-04-27 19:24:33 +00:00
|
|
|
loadImages: true,
|
2011-04-25 09:12:02 +00:00
|
|
|
showScreen: false,
|
|
|
|
theme: 'classic'
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
var browsers = [
|
|
|
|
{
|
|
|
|
name: 'Chrome',
|
|
|
|
regexp: /Chrome\/(\d+)\./,
|
|
|
|
url: 'http://www.google.com/chrome/',
|
|
|
|
version: 10
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Firefox',
|
|
|
|
regexp: /Firefox\/(\d+)\./,
|
|
|
|
url: 'http://www.mozilla.org/firefox/',
|
|
|
|
version: 4
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Safari',
|
|
|
|
regexp: /Version\/(\d+).*? Safari/,
|
|
|
|
url: 'http://www.apple.com/safari/',
|
|
|
|
version: 5
|
|
|
|
}
|
|
|
|
],
|
2011-04-25 13:38:47 +00:00
|
|
|
browserSupported = false,
|
2011-08-09 17:00:39 +00:00
|
|
|
imageNames = {},
|
|
|
|
imageURLs = {},
|
2011-04-25 13:38:47 +00:00
|
|
|
loadingInterval;
|
2011-04-25 09:12:02 +00:00
|
|
|
|
|
|
|
browsers.forEach(function(browser) {
|
2011-04-25 13:38:47 +00:00
|
|
|
var match = browser.regexp.exec(navigator.userAgent);
|
2011-04-25 09:12:02 +00:00
|
|
|
if (match && match[1] >= browser.version) {
|
|
|
|
browserSupported = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Ox.documentReady(function() {
|
2011-05-07 15:56:29 +00:00
|
|
|
Ox.element('body')
|
|
|
|
.addClass('OxTheme' + Ox.toTitleCase(options.theme || 'classic'));
|
2011-04-25 09:12:02 +00:00
|
|
|
options.showScreen && showScreen();
|
|
|
|
});
|
|
|
|
|
|
|
|
loadFiles();
|
|
|
|
|
|
|
|
function showScreen() {
|
|
|
|
|
2011-05-07 15:56:29 +00:00
|
|
|
var body = Ox.element('body'),
|
2011-04-25 09:12:02 +00:00
|
|
|
css = {
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
margin: 'auto',
|
|
|
|
MozUserSelect: 'none',
|
|
|
|
WebkitUserSelect: 'none'
|
|
|
|
},
|
|
|
|
div = Ox.element('<div>')
|
|
|
|
.addClass('OxLoadingScreen')
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
padding: '4px',
|
|
|
|
background: 'rgb(' + (
|
|
|
|
options.theme == 'classic' ? '240, 240, 240' : '16, 16, 16')
|
|
|
|
+ ')',
|
|
|
|
opacity: 1,
|
|
|
|
zIndex: 1000
|
|
|
|
})
|
|
|
|
.appendTo(body);
|
|
|
|
|
|
|
|
browserSupported ? showIcon() : showWarning();
|
|
|
|
|
|
|
|
function showIcon() {
|
2011-04-27 19:24:33 +00:00
|
|
|
// SVG transform performs worse than CSS transform
|
2011-04-25 13:26:17 +00:00
|
|
|
/*
|
2011-04-27 19:24:33 +00:00
|
|
|
var src = Ox.PATH + 'Ox.UI/themes/' + options.theme + '/svg/symbolLoadingAnimated.svg'
|
2011-04-25 09:12:02 +00:00
|
|
|
Ox.loadFile(src, function() {
|
|
|
|
Ox.element('<img>')
|
|
|
|
.attr({
|
|
|
|
src: src
|
|
|
|
})
|
|
|
|
.css(Ox.extend({
|
|
|
|
width: '32px',
|
2011-04-25 13:06:26 +00:00
|
|
|
height: '32px'
|
2011-04-25 09:12:02 +00:00
|
|
|
}, css))
|
|
|
|
.mousedown(function(e) {
|
|
|
|
e.preventDefault()
|
|
|
|
})
|
|
|
|
.appendTo(div);
|
|
|
|
});
|
2011-04-25 13:26:17 +00:00
|
|
|
*/
|
2011-04-25 13:38:47 +00:00
|
|
|
var deg = 0,
|
|
|
|
element,
|
2011-04-27 19:24:33 +00:00
|
|
|
src = Ox.PATH + 'Ox.UI/themes/' + options.theme + '/svg/symbolLoading.svg'
|
2011-04-25 13:06:26 +00:00
|
|
|
Ox.loadFile(src, function() {
|
|
|
|
element = Ox.element('<img>')
|
|
|
|
.attr({
|
|
|
|
src: src
|
|
|
|
})
|
2011-04-25 13:26:17 +00:00
|
|
|
.css(Ox.extend({
|
2011-04-25 13:06:26 +00:00
|
|
|
width: '32px',
|
|
|
|
height: '32px'
|
2011-04-25 13:26:17 +00:00
|
|
|
}, css))
|
2011-04-25 13:06:26 +00:00
|
|
|
.mousedown(function(e) {
|
|
|
|
e.preventDefault()
|
|
|
|
})
|
|
|
|
.appendTo(div);
|
2011-04-25 13:38:47 +00:00
|
|
|
loadingInterval = setInterval(function() {
|
2011-04-25 13:06:26 +00:00
|
|
|
deg = (deg + 30) % 360;
|
|
|
|
element.css({
|
|
|
|
MozTransform: 'rotate(' + deg + 'deg)',
|
|
|
|
WebkitTransform: 'rotate(' + deg + 'deg)'
|
|
|
|
});
|
|
|
|
}, 83);
|
|
|
|
});
|
2011-04-25 09:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showWarning() {
|
|
|
|
var counter = 0,
|
|
|
|
message = 'Browser not supported, use ' + browsers.map(function(browser, i) {
|
|
|
|
return browser.name + (
|
|
|
|
i == browsers.length - 1 ? '.' :
|
|
|
|
i == browsers.length - 2 ? ' or' : ','
|
|
|
|
);
|
|
|
|
}).join(' ');
|
|
|
|
div.addClass('OxError');
|
|
|
|
browsers.forEach(function(browser) {
|
2011-04-27 19:24:33 +00:00
|
|
|
browser.src = Ox.PATH + 'Ox.UI/png/browser' + browser.name + '128.png';
|
2011-04-25 09:12:02 +00:00
|
|
|
Ox.loadFile(browser.src, function() {
|
|
|
|
++counter == browsers.length && showIcons();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
function showIcons() {
|
|
|
|
var box = Ox.element('<div>')
|
|
|
|
.css(Ox.extend({
|
|
|
|
width: (browsers.length * 72) + 'px',
|
|
|
|
height: '72px'
|
|
|
|
}, css))
|
|
|
|
.appendTo(div);
|
|
|
|
browsers.forEach(function(browser, i) {
|
|
|
|
var link = Ox.element('<a>')
|
|
|
|
.attr({
|
|
|
|
href: browser.url,
|
|
|
|
title: browser.name + ' ' + browser.version
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
left: (i * 72) + 'px',
|
|
|
|
width: '72px',
|
|
|
|
height: '72px',
|
|
|
|
})
|
|
|
|
.appendTo(box);
|
|
|
|
Ox.element('<img>')
|
|
|
|
.attr({
|
|
|
|
src: browser.src
|
|
|
|
})
|
|
|
|
.css(Ox.extend({
|
|
|
|
width: '64px',
|
|
|
|
height: '64px',
|
|
|
|
border: 0,
|
|
|
|
cursor: 'pointer'
|
|
|
|
}, css))
|
|
|
|
.mousedown(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
})
|
|
|
|
.appendTo(link);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadFiles() {
|
|
|
|
|
2011-04-27 19:24:33 +00:00
|
|
|
Ox.loadFile(Ox.PATH + 'jquery/jquery' + (options.debug ? '' : '.min') + '.js', function() {
|
2011-04-25 09:12:02 +00:00
|
|
|
initUI();
|
2011-08-09 17:00:39 +00:00
|
|
|
Ox.getJSON(Ox.UI.PATH + 'json/Ox.UI.files.json', function(files) {
|
2011-04-25 10:07:09 +00:00
|
|
|
var promises = [];
|
2011-04-27 19:24:33 +00:00
|
|
|
if (options.debug == false) {
|
|
|
|
files = files.filter(function(file) {
|
|
|
|
return !Ox.startsWith(file, 'Ox.UI/js/');
|
|
|
|
});
|
|
|
|
files.push('Ox.UI/js/Ox.UI.js');
|
|
|
|
}
|
2011-04-25 09:12:02 +00:00
|
|
|
files.forEach(function(file) {
|
2011-04-25 11:08:06 +00:00
|
|
|
// fixme: opera doesnt fire onload for svg
|
|
|
|
if ($.browser.opera && Ox.endsWith(file, '.svg')) {
|
|
|
|
return;
|
|
|
|
}
|
2011-04-25 10:07:09 +00:00
|
|
|
var dfd = new $.Deferred();
|
2011-08-09 17:00:39 +00:00
|
|
|
promises.push(dfd.promise());
|
2011-04-25 09:12:02 +00:00
|
|
|
Ox.loadFile(Ox.PATH + file, function() {
|
2011-04-25 10:07:09 +00:00
|
|
|
dfd.resolve();
|
|
|
|
});
|
|
|
|
});
|
2011-08-09 17:00:39 +00:00
|
|
|
var dfd = new $.Deferred();
|
|
|
|
promises.push(dfd.promise());
|
|
|
|
Ox.getJSON(Ox.UI.PATH + 'json/Ox.UI.image' + (
|
|
|
|
options.loadImages ? 'Data' : ''
|
|
|
|
) + 'URLs.json', function(images) {
|
|
|
|
imageURLs = images;
|
|
|
|
Ox.forEach(imageURLs, function(url, key) {
|
|
|
|
imageNames[url] = key.split('/')[1];
|
|
|
|
});
|
|
|
|
dfd.resolve();
|
|
|
|
});
|
2011-04-25 10:07:09 +00:00
|
|
|
$.when.apply(null, promises)
|
|
|
|
.done(function() {
|
|
|
|
$(function() {
|
2011-04-25 11:08:06 +00:00
|
|
|
if (options.showScreen && options.hideScreen) {
|
|
|
|
Ox.UI.hideLoadingScreen();
|
2011-04-25 09:12:02 +00:00
|
|
|
}
|
|
|
|
callback(browserSupported);
|
|
|
|
});
|
2011-04-25 10:07:09 +00:00
|
|
|
})
|
|
|
|
.fail(function() {
|
|
|
|
throw new Error('File not found.')
|
2011-04-25 09:12:02 +00:00
|
|
|
});
|
2011-08-09 17:00:39 +00:00
|
|
|
|
|
|
|
});
|
2011-04-25 09:12:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function initUI() {
|
|
|
|
|
|
|
|
Ox.UI = {};
|
|
|
|
|
|
|
|
Ox.UI.ready = (function() {
|
|
|
|
var callbacks = [];
|
|
|
|
$(function() {
|
|
|
|
Ox.UI.$body = $('body');
|
|
|
|
Ox.UI.$document = $(document);
|
|
|
|
Ox.UI.$head = $('head');
|
|
|
|
Ox.UI.$window = $(window);
|
|
|
|
callbacks.forEach(function(callback) {
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
delete callbacks;
|
|
|
|
});
|
|
|
|
return function(callback) {
|
|
|
|
if (Ox.UI.$window) {
|
|
|
|
callback();
|
|
|
|
} else {
|
|
|
|
callbacks.push(callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}());
|
|
|
|
|
|
|
|
Ox.UI.DEFAULT_THEME = 'classic'; // fixme: needed?
|
|
|
|
Ox.UI.DIMENSIONS = {
|
|
|
|
horizontal: ['width', 'height'],
|
|
|
|
vertical: ['height', 'width']
|
|
|
|
};
|
|
|
|
Ox.UI.EDGES = {
|
|
|
|
horizontal: ['left', 'right', 'top', 'bottom'],
|
|
|
|
vertical: ['top', 'bottom', 'left', 'right']
|
|
|
|
};
|
2011-04-25 11:08:06 +00:00
|
|
|
Ox.UI.elements = {};
|
2011-08-09 17:00:39 +00:00
|
|
|
Ox.UI.getImageName = function(url) {
|
|
|
|
return imageNames[url];
|
|
|
|
};
|
|
|
|
Ox.UI.getImageURL = function(name, theme) {
|
|
|
|
theme = theme || Ox.Theme();
|
2011-04-25 09:12:02 +00:00
|
|
|
// fixme: not the best idea to do this here
|
2011-08-09 17:00:39 +00:00
|
|
|
if (name == 'symbolPlay') {
|
|
|
|
name = 'symbolRight';
|
2011-04-25 09:12:02 +00:00
|
|
|
}
|
2011-08-09 17:00:39 +00:00
|
|
|
return imageURLs[theme + '/' + name];
|
2011-04-25 09:12:02 +00:00
|
|
|
};
|
2011-08-19 14:44:03 +00:00
|
|
|
Ox.UI.getVideoFormat = function(formats) {
|
|
|
|
var aliases = {
|
|
|
|
'mp4': 'h264',
|
|
|
|
'm4v': 'h264',
|
|
|
|
'ogv': 'ogg'
|
|
|
|
},
|
|
|
|
format,
|
|
|
|
tests = {
|
|
|
|
'h264': 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"',
|
|
|
|
'ogg': 'video/ogg; codecs="theora, vorbis"',
|
|
|
|
'webm': 'video/webm; codecs="vp8, vorbis"'
|
|
|
|
},
|
|
|
|
userAgent = navigator.userAgent.toLowerCase();
|
|
|
|
video = document.createElement('video');
|
|
|
|
Ox.forEach(formats, function(f) {
|
|
|
|
var alias = aliases[f] || f;
|
|
|
|
if (!!(video.canPlayType && video.canPlayType(tests[alias]).replace('no', ''))) {
|
|
|
|
// disable WebM on Safari/Perian, seeking does not work
|
|
|
|
if (!(
|
|
|
|
alias == 'webm' && /safari/.test(userAgent)
|
|
|
|
&& !/chrome/.test(userAgent) && !/linux/.test(userAgent)
|
|
|
|
)) {
|
|
|
|
format = f;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return format;
|
|
|
|
},
|
2011-04-25 11:08:06 +00:00
|
|
|
Ox.UI.hideLoadingScreen = function() {
|
2011-04-29 22:56:46 +00:00
|
|
|
//Ox.print('hideLoadingScreen')
|
2011-04-25 11:08:06 +00:00
|
|
|
var $div = $('.OxLoadingScreen'),
|
|
|
|
error = $div.is('.OxError');
|
|
|
|
//$div.find('img').remove();
|
|
|
|
$div.animate({
|
|
|
|
opacity: error ? 0.9 : 0
|
|
|
|
}, 1000, function() {
|
|
|
|
if (error) {
|
|
|
|
$div.click(function() {
|
2011-08-24 21:05:39 +00:00
|
|
|
$div.remove();
|
|
|
|
});
|
2011-04-25 11:08:06 +00:00
|
|
|
} else {
|
2011-04-25 13:38:47 +00:00
|
|
|
clearInterval(loadingInterval);
|
2011-04-25 11:08:06 +00:00
|
|
|
$div.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2011-04-25 09:12:02 +00:00
|
|
|
Ox.UI.IMAGE_CACHE = [];
|
2011-04-27 19:24:33 +00:00
|
|
|
Ox.UI.PATH = Ox.PATH + 'Ox.UI/';
|
2011-04-25 09:12:02 +00:00
|
|
|
Ox.UI.SCROLLBAR_SIZE = $.browser.mozilla ? 16 : 12;
|
|
|
|
// fixme: the follwing should be deprecated
|
|
|
|
Ox.UI.getBarSize = function(size) {
|
|
|
|
var sizes = {
|
|
|
|
small: 20,
|
|
|
|
medium: 24,
|
|
|
|
large: 28
|
|
|
|
};
|
|
|
|
return sizes[size];
|
|
|
|
};
|
|
|
|
Ox.UI.symbols = {
|
|
|
|
alt: '\u2325',
|
|
|
|
apple: '\uF8FF',
|
|
|
|
arrow_down: '\u2193',
|
|
|
|
arrow_left: '\u2190',
|
|
|
|
arrow_right: '\u2192',
|
|
|
|
arrow_up: '\u2191',
|
|
|
|
backspace: '\u232B',
|
|
|
|
backup: '\u2707',
|
|
|
|
ballot: '\u2717',
|
|
|
|
black_star: '\u2605',
|
|
|
|
burn: '\u2622',
|
|
|
|
caps_lock: '\u21EA',
|
|
|
|
check: '\u2713',
|
|
|
|
//clear: '\u2327',
|
|
|
|
clear: '\u00D7',
|
|
|
|
click: '\uF803',
|
|
|
|
close: '\u2715',
|
|
|
|
command: '\u2318',
|
|
|
|
control: '\u2303',
|
|
|
|
cut: '\u2702',
|
|
|
|
'delete': '\u2326',
|
|
|
|
diamond: '\u25C6',
|
|
|
|
edit: '\uF802',
|
|
|
|
eject: '\u23CF',
|
|
|
|
escape: '\u238B',
|
|
|
|
end: '\u2198',
|
|
|
|
enter: '\u2324',
|
|
|
|
fly: '\u2708',
|
|
|
|
gear: '\u2699',
|
|
|
|
home: '\u2196',
|
|
|
|
info: '\u24D8',
|
|
|
|
navigate: '\u2388',
|
|
|
|
option: '\u2387',
|
|
|
|
page_up: '\u21DE',
|
|
|
|
page_down: '\u21DF',
|
|
|
|
redo: '\u21BA',
|
|
|
|
'return': '\u21A9',
|
|
|
|
//select: '\u21D5',
|
|
|
|
select: '\u25BE',
|
|
|
|
shift: '\u21E7',
|
|
|
|
sound: '\u266B',
|
|
|
|
space: '\u2423',
|
|
|
|
tab: '\u21E5',
|
|
|
|
trash: '\u267A',
|
|
|
|
triangle_down: '\u25BC',
|
|
|
|
triangle_left: '\u25C0',
|
|
|
|
triangle_right: '\u25BA',
|
|
|
|
triangle_up: '\u25B2',
|
|
|
|
undo: '\u21BB',
|
|
|
|
voltage: '\u26A1',
|
|
|
|
warning: '\u26A0',
|
|
|
|
white_star: '\u2606'
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|