'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 = $('') .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); } that.css = function(css) { that.$element.css(css); self.$screen && self.$screen.css(css); self.$image.css(css); return that; }; return that; };