2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2012-06-20 16:30:06 +00:00
|
|
|
(function(global) {
|
2011-04-27 19:39:56 +00:00
|
|
|
|
2012-06-20 16:30:06 +00:00
|
|
|
global.Ox = {
|
2011-04-27 19:39:56 +00:00
|
|
|
|
2012-06-20 16:30:06 +00:00
|
|
|
load: function() {
|
2011-04-27 19:39:56 +00:00
|
|
|
|
2012-06-20 16:30:06 +00:00
|
|
|
var args = arguments,
|
|
|
|
callback = args[args.length - 1],
|
|
|
|
path = getPath(),
|
2013-12-04 22:46:20 +00:00
|
|
|
regexp = /dev\/$/,
|
2014-01-22 10:19:03 +00:00
|
|
|
version = +new Date();
|
2011-10-01 02:21:55 +00:00
|
|
|
|
2013-12-04 22:46:20 +00:00
|
|
|
if (args[0] === true && regexp.test(path)) {
|
2014-09-26 16:57:12 +00:00
|
|
|
path = path.replace(regexp, 'min/');
|
2012-06-26 17:17:27 +00:00
|
|
|
loadScript('Ox.js', function() {
|
2014-09-26 16:57:12 +00:00
|
|
|
Ox.MODE = 'min';
|
2012-06-26 18:10:31 +00:00
|
|
|
Ox.PATH = path;
|
2012-06-26 17:17:27 +00:00
|
|
|
Ox.load.apply(null, Ox.slice(args, 1));
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
loadJSON(function(data) {
|
|
|
|
var previousOx = global.Ox;
|
2014-01-22 10:15:29 +00:00
|
|
|
version = data.version;
|
2012-06-26 17:17:27 +00:00
|
|
|
loadScriptsSerial(data.files, function() {
|
2013-05-09 19:38:47 +00:00
|
|
|
Ox.LOCALES = data.locales;
|
2012-06-26 17:17:27 +00:00
|
|
|
Ox.VERSION = data.version;
|
|
|
|
Ox.forEach(previousOx, function(value, key) {
|
|
|
|
if (Ox.isUndefined(Ox[key])) {
|
|
|
|
Ox[key] = value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Ox.load.apply(null, args);
|
2012-06-25 19:22:20 +00:00
|
|
|
});
|
2012-06-20 16:30:06 +00:00
|
|
|
});
|
2012-06-26 17:17:27 +00:00
|
|
|
}
|
2011-04-27 19:39:56 +00:00
|
|
|
|
2012-06-20 16:30:06 +00:00
|
|
|
function getPath() {
|
2024-02-17 14:15:34 +00:00
|
|
|
var index, regexp = /Ox\.js(\?[\d\.]+|)$/,
|
2013-12-04 16:24:48 +00:00
|
|
|
scripts = document.getElementsByTagName('script'), src;
|
|
|
|
for (index = scripts.length - 1; index >= 0; index--) {
|
|
|
|
src = scripts[index].src;
|
|
|
|
if (regexp.test(src)) {
|
|
|
|
return src.replace(regexp, '');
|
2012-06-20 16:30:06 +00:00
|
|
|
}
|
2011-04-27 19:39:56 +00:00
|
|
|
}
|
2011-10-07 01:04:47 +00:00
|
|
|
}
|
2011-05-06 23:30:32 +00:00
|
|
|
|
2012-06-20 16:30:06 +00:00
|
|
|
function loadJSON(callback) {
|
2014-01-22 10:15:29 +00:00
|
|
|
var request = new XMLHttpRequest(),
|
|
|
|
time = +new Date();
|
2012-06-20 16:30:06 +00:00
|
|
|
request.open('GET', path + 'Ox/json/Ox.json?' + time, true);
|
|
|
|
request.onreadystatechange = function() {
|
|
|
|
if (request.readyState == 4) {
|
|
|
|
if (request.status == 200) {
|
|
|
|
callback(JSON.parse(request.responseText));
|
|
|
|
}
|
2011-05-07 15:56:29 +00:00
|
|
|
}
|
2012-06-20 16:30:06 +00:00
|
|
|
};
|
|
|
|
request.send();
|
|
|
|
}
|
2011-05-08 12:14:07 +00:00
|
|
|
|
2013-12-04 16:24:48 +00:00
|
|
|
function loadScript(script, callback) {
|
|
|
|
var element = document.createElement('script'),
|
|
|
|
head = document.head
|
|
|
|
|| document.getElementsByTagName('head')[0]
|
|
|
|
|| document.documentElement;
|
|
|
|
element.onload = element.onreadystatechange = function() {
|
|
|
|
if (
|
|
|
|
!this.readyState
|
|
|
|
|| this.readyState == 'loaded'
|
|
|
|
|| this.readyState == 'complete'
|
|
|
|
) {
|
2012-06-20 16:30:06 +00:00
|
|
|
callback();
|
|
|
|
}
|
2013-12-04 16:24:48 +00:00
|
|
|
}
|
2014-01-22 10:15:29 +00:00
|
|
|
element.src = path + script + '?' + version;
|
2013-12-04 16:24:48 +00:00
|
|
|
element.type = 'text/javascript';
|
|
|
|
head.appendChild(element);
|
2012-06-20 16:30:06 +00:00
|
|
|
}
|
2011-05-07 15:56:29 +00:00
|
|
|
|
2012-06-20 16:30:06 +00:00
|
|
|
function loadScriptsParallel(scripts, callback) {
|
2013-12-04 16:24:48 +00:00
|
|
|
var i = 0, n = scripts.length;
|
2012-06-20 16:30:06 +00:00
|
|
|
while (scripts.length) {
|
|
|
|
loadScript(scripts.shift(), function() {
|
2013-12-04 16:24:48 +00:00
|
|
|
++i == n && callback();
|
2012-06-20 16:30:06 +00:00
|
|
|
});
|
2011-05-07 15:56:29 +00:00
|
|
|
}
|
2011-05-19 07:06:42 +00:00
|
|
|
}
|
2011-04-27 19:39:56 +00:00
|
|
|
|
2013-12-04 16:24:48 +00:00
|
|
|
function loadScriptsSerial(scripts, callback) {
|
|
|
|
loadScriptsParallel(scripts.shift(), function() {
|
|
|
|
if (scripts.length) {
|
|
|
|
loadScriptsSerial(scripts, callback);
|
|
|
|
} else {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
2012-05-25 16:28:05 +00:00
|
|
|
}
|
2012-06-20 16:30:06 +00:00
|
|
|
|
2011-04-27 19:39:56 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 16:30:06 +00:00
|
|
|
};
|
2011-04-27 19:39:56 +00:00
|
|
|
|
2012-06-20 16:30:06 +00:00
|
|
|
}(this));
|