2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-04-25 09:12:02 +00:00
|
|
|
Ox.load.UI = function(options, callback) {
|
|
|
|
|
|
|
|
options = Ox.extend({
|
|
|
|
hideScreen: true,
|
2014-09-23 21:15:35 +00:00
|
|
|
loadCSS: true,
|
2011-04-25 09:12:02 +00:00
|
|
|
showScreen: false,
|
2013-02-10 11:45:37 +00:00
|
|
|
theme: 'oxlight'
|
2011-04-25 09:12:02 +00:00
|
|
|
}, options);
|
|
|
|
|
|
|
|
var browsers = [
|
2011-09-03 02:12:44 +00:00
|
|
|
{
|
|
|
|
name: 'Chrome Frame',
|
2012-05-26 15:48:19 +00:00
|
|
|
url: 'http://www.google.com/chromeframe/'
|
2011-09-03 02:12:44 +00:00
|
|
|
},
|
2011-04-25 09:12:02 +00:00
|
|
|
{
|
|
|
|
name: 'Chrome',
|
2012-07-11 14:30:31 +00:00
|
|
|
regexp: /Chrome\/(\d+)\./,
|
2011-04-25 09:12:02 +00:00
|
|
|
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-09-03 02:12:44 +00:00
|
|
|
},
|
2012-07-11 14:30:31 +00:00
|
|
|
{
|
|
|
|
name: 'WebKit',
|
|
|
|
regexp: /AppleWebKit\/(\d+)\./,
|
|
|
|
version: 534
|
|
|
|
},
|
2013-02-10 17:18:36 +00:00
|
|
|
{
|
|
|
|
name: 'Googlebot',
|
|
|
|
regexp: /Googlebot\/(\d+)\./,
|
|
|
|
version: 2
|
|
|
|
},
|
2011-09-03 02:12:44 +00:00
|
|
|
{
|
|
|
|
name: 'Internet Explorer',
|
|
|
|
url: 'http://windows.microsoft.com/en-US/internet-explorer/products/ie/home',
|
|
|
|
version: 9
|
2011-04-25 09:12:02 +00:00
|
|
|
}
|
|
|
|
],
|
2011-04-25 13:38:47 +00:00
|
|
|
browserSupported = false,
|
2014-09-25 16:28:13 +00:00
|
|
|
isInternetExplorer = /MSIE/.test(navigator.userAgent);
|
2011-04-25 09:12:02 +00:00
|
|
|
|
2014-09-25 17:08:03 +00:00
|
|
|
browsers.forEach(function(browser) {
|
|
|
|
var match = browser.regexp && browser.regexp.exec(navigator.userAgent);
|
|
|
|
if (match && match[1] >= browser.version) {
|
|
|
|
browserSupported = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-09-25 16:28:13 +00:00
|
|
|
Ox.UI = {}; // FIXME: remove
|
2011-04-25 09:12:02 +00:00
|
|
|
|
2014-09-25 17:14:05 +00:00
|
|
|
Ox.UILoadingScreen = (function() {
|
2011-04-25 09:12:02 +00:00
|
|
|
|
2014-09-25 16:28:13 +00:00
|
|
|
var $body = Ox.$('body'),
|
|
|
|
$screen = Ox.$('<div>')
|
2011-04-25 09:12:02 +00:00
|
|
|
.addClass('OxLoadingScreen')
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
padding: '4px',
|
|
|
|
background: 'rgb(' + (
|
2013-02-10 11:45:37 +00:00
|
|
|
options.theme == 'oxlight' ? '240, 240, 240'
|
|
|
|
: options.theme == 'oxmedium' ? '144, 144, 144'
|
|
|
|
: '16, 16, 16'
|
|
|
|
) + ')',
|
2011-04-25 09:12:02 +00:00
|
|
|
opacity: 1,
|
|
|
|
zIndex: 1000
|
2014-09-25 16:28:13 +00:00
|
|
|
}),
|
|
|
|
css = {
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
margin: 'auto',
|
|
|
|
MozUserSelect: 'none',
|
|
|
|
WebkitUserSelect: 'none'
|
|
|
|
},
|
|
|
|
loadingInterval
|
2011-04-25 09:12:02 +00:00
|
|
|
|
2012-12-29 16:54:58 +00:00
|
|
|
browserSupported ? showIcon() : showWarning();
|
2011-04-25 09:12:02 +00:00
|
|
|
|
|
|
|
function showIcon() {
|
2011-04-25 13:26:17 +00:00
|
|
|
/*
|
2012-01-04 09:50:07 +00:00
|
|
|
// SVG transform performs worse than CSS transform
|
2011-04-27 19:24:33 +00:00
|
|
|
var src = Ox.PATH + 'Ox.UI/themes/' + options.theme + '/svg/symbolLoadingAnimated.svg'
|
2012-06-17 13:37:21 +00:00
|
|
|
Ox.getFile(src, function() {
|
2012-04-15 12:17:19 +00:00
|
|
|
Ox.$('<img>')
|
2011-04-25 09:12:02 +00:00
|
|
|
.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))
|
2012-05-28 14:06:22 +00:00
|
|
|
.on({
|
2012-04-15 12:17:19 +00:00
|
|
|
mousedown: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2011-04-25 09:12:02 +00:00
|
|
|
})
|
|
|
|
.appendTo(div);
|
|
|
|
});
|
2011-04-25 13:26:17 +00:00
|
|
|
*/
|
2011-04-25 13:38:47 +00:00
|
|
|
var deg = 0,
|
2014-09-25 16:28:13 +00:00
|
|
|
$element,
|
2011-04-27 19:24:33 +00:00
|
|
|
src = Ox.PATH + 'Ox.UI/themes/' + options.theme + '/svg/symbolLoading.svg'
|
2012-06-17 13:37:21 +00:00
|
|
|
Ox.getFile(src, function() {
|
2014-09-25 16:28:13 +00:00
|
|
|
var $icon = Ox.$('<img>')
|
|
|
|
.attr({
|
|
|
|
src: src
|
|
|
|
})
|
|
|
|
.css(Ox.extend({
|
|
|
|
width: '32px',
|
|
|
|
height: '32px'
|
|
|
|
}, css))
|
|
|
|
.on({
|
|
|
|
mousedown: function(e) {
|
|
|
|
e.preventDefault()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.appendTo($screen),
|
|
|
|
deg = 0;
|
2011-04-25 13:38:47 +00:00
|
|
|
loadingInterval = setInterval(function() {
|
2011-04-25 13:06:26 +00:00
|
|
|
deg = (deg + 30) % 360;
|
2014-09-25 16:28:13 +00:00
|
|
|
$icon.css({
|
2011-04-25 13:06:26 +00:00
|
|
|
MozTransform: 'rotate(' + deg + 'deg)',
|
2012-05-24 17:13:25 +00:00
|
|
|
OTransform: 'rotate(' + deg + 'deg)',
|
2013-08-08 12:21:44 +00:00
|
|
|
WebkitTransform: 'rotate(' + deg + 'deg)',
|
|
|
|
transform: 'rotate(' + deg + 'deg)'
|
2011-04-25 13:06:26 +00:00
|
|
|
});
|
|
|
|
}, 83);
|
|
|
|
});
|
2011-04-25 09:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showWarning() {
|
2011-09-03 02:12:44 +00:00
|
|
|
var counter = 0;
|
2012-07-11 14:30:31 +00:00
|
|
|
browsers = browsers.filter(function(browser) {
|
|
|
|
return browser.url;
|
|
|
|
});
|
2012-12-29 16:54:58 +00:00
|
|
|
isInternetExplorer ? browsers.pop() : browsers.shift();
|
2011-04-25 09:12:02 +00:00
|
|
|
browsers.forEach(function(browser) {
|
2011-09-03 02:12:44 +00:00
|
|
|
browser.src = Ox.PATH + 'Ox.UI/png/browser' + browser.name.replace(' ', '') + '128.png';
|
2012-06-17 13:37:21 +00:00
|
|
|
Ox.getFile(browser.src, function() {
|
2011-04-25 09:12:02 +00:00
|
|
|
++counter == browsers.length && showIcons();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
function showIcons() {
|
2014-09-25 16:28:13 +00:00
|
|
|
var $box = Ox.$('<div>')
|
2011-04-25 09:12:02 +00:00
|
|
|
.css(Ox.extend({
|
|
|
|
width: (browsers.length * 72) + 'px',
|
|
|
|
height: '72px'
|
|
|
|
}, css))
|
2014-09-25 16:28:13 +00:00
|
|
|
.appendTo($screen);
|
2011-04-25 09:12:02 +00:00
|
|
|
browsers.forEach(function(browser, i) {
|
2014-09-25 16:28:13 +00:00
|
|
|
Ox.$('<a>')
|
2011-04-25 09:12:02 +00:00
|
|
|
.attr({
|
|
|
|
href: browser.url,
|
2014-09-25 16:28:13 +00:00
|
|
|
title: (
|
|
|
|
browser.name == 'Chrome Frame'
|
|
|
|
? Ox._('Install') : Ox._('Download')
|
|
|
|
) + ' ' + browser.name
|
2011-04-25 09:12:02 +00:00
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
left: (i * 72) + 'px',
|
|
|
|
width: '72px',
|
2012-05-26 15:48:19 +00:00
|
|
|
height: '72px'
|
2011-04-25 09:12:02 +00:00
|
|
|
})
|
2014-09-25 16:28:13 +00:00
|
|
|
.append(
|
|
|
|
Ox.$('<img>')
|
|
|
|
.attr({
|
|
|
|
src: browser.src
|
|
|
|
})
|
|
|
|
.css(Ox.extend({
|
|
|
|
width: '64px',
|
|
|
|
height: '64px',
|
|
|
|
border: 0,
|
|
|
|
cursor: 'pointer'
|
|
|
|
}, css))
|
|
|
|
.on({
|
|
|
|
mousedown: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.appendTo($box);
|
2011-04-25 09:12:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-25 16:28:13 +00:00
|
|
|
return {
|
|
|
|
hide: function() {
|
2014-09-25 17:08:03 +00:00
|
|
|
$screen.animate({
|
2014-09-25 16:28:13 +00:00
|
|
|
opacity: browserSupported ? 0 : 0.9
|
|
|
|
}, 1000, function() {
|
|
|
|
if (browserSupported) {
|
|
|
|
clearInterval(loadingInterval);
|
2014-09-25 17:08:03 +00:00
|
|
|
$screen.remove();
|
2014-09-25 16:28:13 +00:00
|
|
|
} else {
|
2014-09-25 17:08:03 +00:00
|
|
|
$screen.on({
|
2014-09-25 16:28:13 +00:00
|
|
|
click: function() {
|
2014-09-25 17:08:03 +00:00
|
|
|
$screen.remove();
|
2014-09-25 16:28:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
show: function() {
|
|
|
|
$screen.appendTo($body);
|
|
|
|
}
|
|
|
|
};
|
2011-04-25 09:12:02 +00:00
|
|
|
|
2014-09-25 16:28:13 +00:00
|
|
|
}());
|
2011-04-25 09:12:02 +00:00
|
|
|
|
2014-09-25 16:28:13 +00:00
|
|
|
Ox.documentReady(function() {
|
|
|
|
Ox.$('body').addClass('OxTheme' + Ox.toTitleCase(options.theme));
|
2014-09-25 17:14:05 +00:00
|
|
|
options.showScreen && Ox.UILoadingScreen.show();
|
2014-09-25 16:28:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
loadUI();
|
|
|
|
|
|
|
|
function loadUI() {
|
|
|
|
|
|
|
|
var path = Ox.PATH + 'Ox.UI/jquery/jquery.js?' + Ox.VERSION;
|
|
|
|
Ox.getFile(path, function() {
|
|
|
|
path = Ox.PATH + 'Ox.UI/json/Ox.UI.json?' + Ox.VERSION;
|
|
|
|
Ox.getJSON(path, function(data) {
|
2014-09-23 21:15:35 +00:00
|
|
|
var counter = 0, length;
|
|
|
|
if (!options.loadCSS) {
|
|
|
|
data.files = data.files.filter(function(file) {
|
|
|
|
return !Ox.endsWith(file, '.css');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
length = data.files.length;
|
2014-09-25 16:28:13 +00:00
|
|
|
Ox.IMAGES = data.images;
|
|
|
|
Ox.THEMES = {};
|
2012-12-28 17:21:26 +00:00
|
|
|
data.files.forEach(function(file) {
|
2014-09-25 16:28:13 +00:00
|
|
|
path = Ox.PATH + file + '?' + Ox.VERSION;
|
2012-12-28 17:21:26 +00:00
|
|
|
if (/\.jsonc$/.test(file)) {
|
2014-09-25 16:28:13 +00:00
|
|
|
Ox.getJSONC(path, function(data) {
|
2012-12-28 17:21:26 +00:00
|
|
|
var theme = /\/themes\/(\w+)\/json\//.exec(file)[1];
|
2014-09-25 16:28:13 +00:00
|
|
|
Ox.THEMES[theme] = data;
|
|
|
|
++counter == length && initUI();
|
2012-01-04 09:50:07 +00:00
|
|
|
});
|
|
|
|
} else {
|
2014-09-25 16:28:13 +00:00
|
|
|
Ox.getFile(path, function() {
|
|
|
|
++counter == length && initUI();
|
2012-01-04 09:50:07 +00:00
|
|
|
});
|
|
|
|
}
|
2011-04-25 10:07:09 +00:00
|
|
|
});
|
2011-08-09 17:00:39 +00:00
|
|
|
});
|
2011-04-25 09:12:02 +00:00
|
|
|
});
|
2012-12-28 17:21:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-25 16:28:13 +00:00
|
|
|
function initUI() {
|
2012-12-28 17:21:26 +00:00
|
|
|
|
2013-12-06 19:49:53 +00:00
|
|
|
Ox.documentReady(function() {
|
2014-09-25 16:28:13 +00:00
|
|
|
// FIXME: use Ox.$foo everywhere!
|
|
|
|
Ox.$body = Ox.UI.$body = $('body');
|
|
|
|
Ox.$document = Ox.UI.$document = $(document);
|
|
|
|
Ox.$head = Ox.UI.$head = $('head');
|
|
|
|
Ox.$window = Ox.UI.$window = $(window);
|
|
|
|
// fixme: is this the right place to do this?
|
|
|
|
$.browser.mozilla && Ox.$document.on('dragstart', function() {
|
|
|
|
return false;
|
|
|
|
});
|
2012-12-28 17:21:26 +00:00
|
|
|
if (options.showScreen && options.hideScreen) {
|
2014-09-25 17:14:05 +00:00
|
|
|
Ox.UILoadingScreen.hide();
|
2012-12-28 17:21:26 +00:00
|
|
|
}
|
|
|
|
callback(browserSupported);
|
|
|
|
});
|
|
|
|
|
2011-04-25 09:12:02 +00:00
|
|
|
}
|
|
|
|
|
2011-10-08 09:10:01 +00:00
|
|
|
};
|