2013-03-07 07:20:54 +00:00
|
|
|
'use strict';
|
|
|
|
|
2013-03-08 08:48:49 +00:00
|
|
|
/*@
|
|
|
|
Ox.ImageElement <f> Simple image element with loading indication
|
|
|
|
@*/
|
|
|
|
|
2013-03-07 07:20:54 +00:00
|
|
|
Ox.ImageElement = function(options, self) {
|
|
|
|
|
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
|
|
|
.defaults({
|
|
|
|
height: 0,
|
|
|
|
src: '',
|
|
|
|
width: 0
|
|
|
|
})
|
|
|
|
.options(options || {})
|
|
|
|
.update({
|
2013-03-08 08:48:49 +00:00
|
|
|
height: function() {
|
|
|
|
!self.isAuto && setSizes();
|
|
|
|
},
|
2013-03-07 07:20:54 +00:00
|
|
|
src: loadImage,
|
2013-03-08 08:48:49 +00:00
|
|
|
width: function() {
|
|
|
|
!self.isAuto && setSizes();
|
|
|
|
}
|
2013-03-07 07:20:54 +00:00
|
|
|
})
|
|
|
|
.addClass('OxImageElement');
|
|
|
|
|
2013-03-08 08:48:49 +00:00
|
|
|
self.isAuto = !self.options.width && !self.options.height;
|
|
|
|
|
|
|
|
self.$screen = Ox.LoadingScreen({
|
|
|
|
size: 16,
|
|
|
|
width: self.options.width,
|
|
|
|
height: self.options.height
|
|
|
|
})
|
2013-11-20 08:11:53 +00:00
|
|
|
.start()
|
2013-03-08 08:48:49 +00:00
|
|
|
.appendTo(that);
|
2013-03-07 07:20:54 +00:00
|
|
|
|
|
|
|
loadImage();
|
2013-03-08 08:48:49 +00:00
|
|
|
!self.isAuto && setSizes();
|
2013-03-07 07:20:54 +00:00
|
|
|
|
|
|
|
function loadImage() {
|
|
|
|
if (self.$image) {
|
|
|
|
self.$image.off({load: showImage}).remove();
|
|
|
|
}
|
|
|
|
self.$image = $('<img>')
|
2013-11-20 08:11:53 +00:00
|
|
|
.one({
|
|
|
|
error: stopLoading,
|
|
|
|
load: showImage
|
|
|
|
})
|
2013-03-07 07:20:54 +00:00
|
|
|
.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() {
|
2013-11-20 08:11:53 +00:00
|
|
|
self.$screen.stop().remove();
|
2013-03-07 07:20:54 +00:00
|
|
|
self.$image.appendTo(that);
|
|
|
|
}
|
|
|
|
|
2013-11-20 08:11:53 +00:00
|
|
|
function stopLoading() {
|
|
|
|
self.$screen.stop();
|
|
|
|
}
|
|
|
|
|
2013-03-07 07:56:22 +00:00
|
|
|
that.css = function(css) {
|
|
|
|
that.$element.css(css);
|
|
|
|
self.$screen && self.$screen.css(css);
|
|
|
|
self.$image.css(css);
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2013-03-07 07:20:54 +00:00
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|