From 43d5bee70a2d16464d74ecffbab0265c11ed61a4 Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 8 Mar 2013 08:48:49 +0000 Subject: [PATCH] add auto variant of loading screen and image element --- source/Ox.UI/css/Ox.UI.css | 13 +++++++++++ source/Ox.UI/js/Core/ImageElement.js | 25 ++++++++++++++++---- source/Ox.UI/js/Core/LoadingScreen.js | 33 +++++++++++++++++++-------- 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/source/Ox.UI/css/Ox.UI.css b/source/Ox.UI/css/Ox.UI.css index b80e5453..e9bf2c9b 100644 --- a/source/Ox.UI/css/Ox.UI.css +++ b/source/Ox.UI/css/Ox.UI.css @@ -2701,6 +2701,19 @@ Miscellaneous .OxLoadingScreen > div > div { margin-top: 4px; } +.OxLoadingScreen.OxAuto { + left: 0; + top: 0; + right: 0; + bottom: 0; +} +.OxLoadingScreen.OxAuto > div { + left: 0; + top: 0; + right: 0; + bottom: 0; + margin: auto; +} .OxSpecialLink { padding: 0 2px 0 2px; diff --git a/source/Ox.UI/js/Core/ImageElement.js b/source/Ox.UI/js/Core/ImageElement.js index 9cc5f532..d8b42101 100644 --- a/source/Ox.UI/js/Core/ImageElement.js +++ b/source/Ox.UI/js/Core/ImageElement.js @@ -1,5 +1,9 @@ 'use strict'; +/*@ +Ox.ImageElement Simple image element with loading indication +@*/ + Ox.ImageElement = function(options, self) { self = self || {}; @@ -11,16 +15,29 @@ Ox.ImageElement = function(options, self) { }) .options(options || {}) .update({ - height: setSizes, + height: function() { + !self.isAuto && setSizes(); + }, src: loadImage, - width: setSizes + width: function() { + !self.isAuto && setSizes(); + } }) .addClass('OxImageElement'); - self.$screen = Ox.LoadingScreen({size: 16}).appendTo(that); + self.isAuto = !self.options.width && !self.options.height; + + Ox.print('IMAGE OPTS', self.options, self.isAuto) + + self.$screen = Ox.LoadingScreen({ + size: 16, + width: self.options.width, + height: self.options.height + }) + .appendTo(that); loadImage(); - setSizes(); + !self.isAuto && setSizes(); function loadImage() { if (self.$image) { diff --git a/source/Ox.UI/js/Core/LoadingScreen.js b/source/Ox.UI/js/Core/LoadingScreen.js index 21d6244b..f3b69723 100644 --- a/source/Ox.UI/js/Core/LoadingScreen.js +++ b/source/Ox.UI/js/Core/LoadingScreen.js @@ -1,25 +1,36 @@ 'use strict'; +/*@ +Ox.LoadingScreen Simple loading screen +@*/ + Ox.LoadingScreen = function(options, self) { self = self || {}; var that = Ox.Element({}, self) .defaults({ - height: 256, + height: 0, size: 32, text: '', - width: 256 + width: 0 }) .options(options || {}) .update({ - height: setSizes, + height: function() { + !self.isAuto && setSizes(); + }, text: function() { self.$text && self.$text.html(self.options.text); }, - width: setSizes + width: function() { + !self.isAuto && setSizes(); + } }) .addClass('OxLoadingScreen'); + self.isAuto = !self.options.width && !self.options.height; + self.isAuto && that.addClass('OxAuto') + self.$box = $('
').appendTo(that); setSizes(); @@ -43,15 +54,17 @@ Ox.LoadingScreen = function(options, self) { 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); + if (!self.isAuto) { + css.left = Math.floor((self.options.width - css.width) / 2); + css.top = Math.floor((self.options.height - css.height) / 2); + that.css({ + width: self.options.width + 'px', + height: self.options.height + 'px' + }); + } 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); }