From 1fd4a853da349a216e9530e019424bcaabeaea12 Mon Sep 17 00:00:00 2001 From: Luigi De Rosa Date: Fri, 5 Sep 2014 02:36:38 +0200 Subject: [PATCH] Calculate automatically width and height of an image if is not specified --- demos/grid/bird.html | 4 +--- js/jquery.focuspoint.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/demos/grid/bird.html b/demos/grid/bird.html index fc35268..2bcaab5 100644 --- a/demos/grid/bird.html +++ b/demos/grid/bird.html @@ -36,9 +36,7 @@
+ data-focus-y="-0.284">
diff --git a/js/jquery.focuspoint.js b/js/jquery.focuspoint.js index c2cfee7..072e6bc 100755 --- a/js/jquery.focuspoint.js +++ b/js/jquery.focuspoint.js @@ -58,6 +58,25 @@ image = $(this).find('img').first(); imageW = $(this).data('imageW'); imageH = $(this).data('imageH'); + + if (!imageW || !imageH) { + var self = this, + imageTmp = new Image(); + + imageTmp.onload = function(){ + + $(self).data('imageW', this.width); + $(self).data('imageH', this.height); + + $(self).adjustFocus(); + }; + + imageTmp.src = image.attr('src'); + + return false; + } + + if (!(containerW > 0 && containerH > 0 && imageW > 0 && imageH > 0)) { //Need dimensions to proceed return false;