1
0
Fork 0
forked from 0x2620/oxjs

add Ox.LoadingScreen and Ox.ImageElement, update CSS

This commit is contained in:
rolux 2013-03-07 12:50:54 +05:30
commit 0d784b3dc4
8 changed files with 139 additions and 0 deletions

View file

@ -0,0 +1,54 @@
'use strict';
Ox.ImageElement = function(options, self) {
self = self || {};
var that = Ox.Element({}, self)
.defaults({
height: 0,
src: '',
width: 0
})
.options(options || {})
.update({
height: setSizes,
src: loadImage,
width: setSizes
})
.addClass('OxImageElement');
self.$screen = Ox.LoadingScreen({size: 16}).appendTo(that);
loadImage();
setSizes();
function loadImage() {
if (self.$image) {
self.$image.off({load: showImage}).remove();
}
self.$image = $('<img>')
.one({load: showImage})
.attr({src: self.options.src});
}
function setSizes() {
var css = {
width: self.options.width,
height: self.options.height
};
self.$screen && self.$screen.options(css);
css = Ox.map(css, function(value) {
return value + 'px';
});
that.css(css);
self.$image.css(css);
}
function showImage() {
self.$screen.remove();
self.$image.appendTo(that);
}
return that;
};

View file

@ -0,0 +1,60 @@
'use strict';
Ox.LoadingScreen = function(options, self) {
self = self || {};
var that = Ox.Element({}, self)
.defaults({
height: 256,
size: 32,
text: '',
width: 256
})
.options(options || {})
.update({
height: setSizes,
text: function() {
self.$text && self.$text.html(self.options.text);
},
width: setSizes
})
.addClass('OxLoadingScreen');
self.$box = $('<div>').appendTo(that);
setSizes();
$('<img>')
.attr({src: Ox.UI.getImageURL('symbolLoadingAnimated')})
.css({
width: self.options.size + 'px',
height: self.options.size + 'px'
})
.appendTo(self.$box);
if (self.options.text) {
self.$text = $('<div>')
.html(self.options.text)
.appendTo(self.$box);
}
function setSizes() {
var css = {
width: (self.options.text ? 256 : self.options.size),
height: self.options.size + (self.options.text ? 24 : 0)
};
css.left = Math.floor((self.options.width - css.width) / 2);
css.top = Math.floor((self.options.height - css.height) / 2);
css = Ox.map(css, function(value) {
return value + 'px';
});
that.css({
width: self.options.width + 'px',
height: self.options.height + 'px'
});
self.$box.css(css);
}
return that;
};