oxjs/source/UI/UI.js

306 lines
10 KiB
JavaScript
Raw Permalink Normal View History

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,
2015-02-22 13:43:25 +00:00
loadThemes: 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',
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
},
{
name: 'WebKit',
regexp: /AppleWebKit\/(\d+)\./,
version: 534
},
{
name: 'Googlebot',
regexp: /Googlebot\/(\d+)\./,
version: 2
},
2016-11-25 21:28:30 +00:00
{
name: 'YandexBot',
2016-11-25 21:34:17 +00:00
regexp: /YandexBot\/(\d+)\./,
version: 3
},
{
name: 'YandexMobileBot',
regexp: /YandexMobileBot\/(\d+)\./,
2016-11-25 21:28:30 +00:00
version: 3
},
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-26 12:18:11 +00:00
Ox.UI = {};
2011-04-25 09:12:02 +00:00
2014-09-26 12:18:11 +00:00
Ox.UI.LoadingScreen = (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,
$icon,
deg = 0;
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
/*
// SVG transform performs worse than CSS transform
var src = Ox.PATH + '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',
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
*/
var src = Ox.PATH + 'UI/themes/' + options.theme + '/svg/symbolLoading.svg'
2012-06-17 13:37:21 +00:00
Ox.getFile(src, function() {
$icon = Ox.$('<img>')
.attr({
src: src
})
.css(Ox.extend({
width: '32px',
height: '32px'
}, css))
.on({
mousedown: function(e) {
e.preventDefault()
}
})
.appendTo($screen);
});
2011-04-25 09:12:02 +00:00
}
function showWarning() {
2011-09-03 02:12:44 +00:00
var counter = 0;
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) {
browser.src = Ox.PATH + '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:42:11 +00:00
$('.OxLoadingScreen').animate({
2014-09-25 16:28:13 +00:00
opacity: browserSupported ? 0 : 0.9
}, 1000, function() {
if (browserSupported) {
clearInterval(loadingInterval);
loadingInterval = null;
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() {
if (!loadingInterval) {
loadingInterval = setInterval(function() {
if ($icon) {
deg = (deg + 30) % 360;
$icon.css({
MozTransform: 'rotate(' + deg + 'deg)',
OTransform: 'rotate(' + deg + 'deg)',
WebkitTransform: 'rotate(' + deg + 'deg)',
transform: 'rotate(' + deg + 'deg)'
});
}
}, 83);
}
2014-09-25 16:28:13 +00:00
$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-26 12:18:11 +00:00
options.showScreen && Ox.UI.LoadingScreen.show();
2014-09-25 16:28:13 +00:00
});
loadUI();
function loadUI() {
var path = Ox.PATH + 'UI/jquery/jquery.js?' + Ox.VERSION;
2014-09-25 16:28:13 +00:00
Ox.getFile(path, function() {
path = Ox.PATH + 'UI/json/UI.json?' + Ox.VERSION;
2014-09-25 16:28:13 +00:00
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');
});
}
2015-02-22 13:43:25 +00:00
if (!options.loadThemes) {
data.files = data.files.filter(function(file) {
return !Ox.contains(file, '/themes/');
});
}
2014-09-23 21:15:35 +00:00
length = data.files.length;
2014-09-26 12:31:20 +00:00
Ox.UI.IMAGES = data.images;
Ox.UI.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-26 12:31:20 +00:00
Ox.UI.THEMES[theme] = data;
2014-09-25 16:28:13 +00:00
++counter == length && initUI();
});
} else {
2014-09-25 16:28:13 +00:00
Ox.getFile(path, function() {
++counter == length && initUI();
});
}
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
Ox.documentReady(function() {
2014-09-25 16:28:13 +00:00
// 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-26 12:18:11 +00:00
Ox.UI.LoadingScreen.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
};