oxjs/build/js/ox.load.js

163 lines
5.1 KiB
JavaScript
Raw Normal View History

2010-09-05 14:24:22 +00:00
$(function() {
var $body = $('body'),
2010-09-06 00:56:18 +00:00
$div = $('<div>')
.css({
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0,
background: 'rgb(240, 240, 240)',
opacity: 1,
zIndex: 1000
})
.appendTo($body),
2010-09-05 14:24:22 +00:00
css = {
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0,
margin: 'auto',
MozUserSelect: 'none',
WebkitUserSelect: 'none'
},
file = 'js/ox.load.js',
2011-02-22 19:02:07 +00:00
path = $('script[src*="' + file + '"]').attr('src').replace(file, ''),
2010-09-05 14:24:22 +00:00
userAgent,
userAgents = {
'Chrome': 'http://www.google.com/chrome/',
'Firefox': 'http://www.mozilla.org/firefox/',
'Internet Explorer': '',
2011-01-02 10:01:55 +00:00
'Opera': 'http://www.opera.com/',
2010-09-05 14:24:22 +00:00
'Safari': 'http://www.apple.com/safari/'
};
userAgent = getUserAgent();
userAgents[userAgent] ? start() : stop();
function getUserAgent() {
var userAgent = '';
$.each(userAgents, function(name, link) {
if (navigator.userAgent.indexOf(name) > -1) {
userAgent = name;
return false;
}
});
2011-03-01 11:06:37 +00:00
if (!userAgent && $.browser.mozilla) {
userAgent = 'Firefox';
}
if (!userAgent && $.browser.webkit) {
userAgent = 'Chrome';
}
2010-09-05 14:24:22 +00:00
return userAgent;
}
function start() {
var image = new Image(),
2011-03-07 22:31:46 +00:00
src = path + 'svg/ox.ui.classic/symbolLoading.svg';
2010-09-05 14:24:22 +00:00
image.src = src;
image.onload = function() {
var $img = $('<img>')
.attr({
src: src
})
.css($.extend(css, {
width: '32px',
height: '32px'
}))
.mousedown(function(e) {
e.preventDefault();
})
2011-03-07 22:31:46 +00:00
.appendTo($div);
/*
2010-09-05 14:24:22 +00:00
deg = 0,
interval = setInterval(function() {
deg = (deg + 30) % 360;
$img.css({
MozTransform: 'rotate(' + deg + 'deg)',
WebkitTransform: 'rotate(' + deg + 'deg)',
});
}, 83);
2011-03-07 22:31:46 +00:00
*/
2010-09-05 14:24:22 +00:00
};
}
function stop() {
var counter = 0,
length = 0,
src = {};
2011-04-19 14:11:04 +00:00
Ox.forEach(userAgents, function(link, name) {
2010-09-05 14:24:22 +00:00
if (link) {
length++;
}
});
2011-04-19 14:11:04 +00:00
Ox.forEach(userAgents, function(link, name) {
2010-09-05 14:24:22 +00:00
var image;
if (link) {
image = new Image();
src[name] = path + 'png/ox.ui/browser' + name + '128.png';
image.src = src[name];
image.onload = function() {
if (++counter == length) {
loaded();
}
}
}
});
2010-09-05 00:34:06 +00:00
function loaded() {
2010-09-06 00:56:18 +00:00
var $div_ = $('<div>')
2010-09-05 14:24:22 +00:00
.css($.extend(css, {
2010-09-05 15:51:11 +00:00
width: (length * 72) + 'px',
2010-09-05 14:24:22 +00:00
height: '72px'
2010-09-05 15:51:11 +00:00
})),
i = 0;
2010-09-05 14:24:22 +00:00
$.each(src, function(name, src) {
$('<a>')
.attr({
href: userAgents[name],
title: name
})
2010-09-05 15:51:11 +00:00
.css({
position: 'absolute',
left: (i++ * 72) + 'px',
width: '72px',
height: '72px',
})
2010-09-05 14:24:22 +00:00
.append(
$('<img>')
.attr({
src: src
})
2010-09-05 15:51:11 +00:00
.css($.extend(css, {
2010-09-05 14:24:22 +00:00
width: '64px',
height: '64px',
border: 0,
cursor: 'pointer'
2010-09-05 15:51:11 +00:00
}))
.mousedown(function(e) {
e.preventDefault();
})
2010-09-05 15:51:11 +00:00
.mouseenter(function() {
$(this).animate({
width: '72px',
height: '72px',
}, 250);
})
.mouseleave(function() {
$(this).animate({
width: '64px',
height: '64px',
}, 250);
2010-09-05 14:24:22 +00:00
})
)
2010-09-06 00:56:18 +00:00
.appendTo($div_);
2010-09-05 14:24:22 +00:00
});
2010-09-06 00:56:18 +00:00
$div_.appendTo($div);
2010-09-05 14:24:22 +00:00
//throw new Error('User Agent not supported.');
2010-09-05 00:34:06 +00:00
}
}
2010-09-05 14:24:22 +00:00
2010-12-28 15:32:48 +00:00
});