From 6a2a8653d634881e25b999e501431df454e8f315 Mon Sep 17 00:00:00 2001 From: Jerome Duncan Date: Fri, 29 Apr 2016 13:05:12 +0100 Subject: [PATCH] fix hidden element bug on firefox/IE --- bower.json | 2 +- dist/macy.js | 16 +++++++++------- dist/macy.min.js | 4 ++-- package.json | 2 +- src/macy.js | 14 ++++++++------ 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/bower.json b/bower.json index 5e55a4a..0ed2a62 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "macy", - "version": "1.1.1", + "version": "1.1.2", "homepage": "http://macyjs.com/", "author": { "name": "Big Bite Creative", diff --git a/dist/macy.js b/dist/macy.js index e848fa4..39f455c 100644 --- a/dist/macy.js +++ b/dist/macy.js @@ -1,5 +1,5 @@ /*! - * Macy.js v1.1.1 - Macy is a lightweight, dependency free, masonry layout library + * Macy.js v1.1.2 - Macy is a lightweight, dependency free, masonry layout library * Author: Copyright (c) Big Bite Creative <@bigbitecreative> * Url: http://macyjs.com/ * License: MIT @@ -39,7 +39,7 @@ return extended; }; var Macy = {}; - Macy.VERSION = "1.1.1"; + Macy.VERSION = "1.1.2"; Macy.settings = {}; var defaults = { columns: 3, @@ -100,12 +100,13 @@ }; var getTopValue = function(row, col, eles) { var totalHeight = 0; + var tempHeight; if (row === 0) { return 0; } for (var i = 0; i < row; i++) { - totalHeight += parseInt(getProperty(cache.elements[eles[i]], "height").replace("px", "")); - totalHeight += cache.options.margin; + tempHeight = parseInt(getProperty(cache.elements[eles[i]], "height").replace("px", ""), 10); + totalHeight += isNaN(tempHeight) ? 0 : tempHeight + cache.options.margin; } return totalHeight; }; @@ -169,10 +170,11 @@ }; var findIndexOfSmallestTotal = function(arr) { var runningTotal = 0; - var smallestIndex, smallest, lastSmall; + var smallestIndex, smallest, lastSmall, tempHeight; for (var i = 0, arrLen = arr.length; i < arrLen; i++) { for (var j = 0; j < arr[i].length; j++) { - runningTotal += parseInt(getProperty(cache.elements[arr[i][j]], "height").replace("px", "")); + tempHeight = parseInt(getProperty(cache.elements[arr[i][j]], "height").replace("px", ""), 10); + runningTotal += isNaN(tempHeight) ? 0 : tempHeight; } lastSmall = smallest; smallest = smallest === undefined ? runningTotal : smallest > runningTotal ? runningTotal : smallest; @@ -191,7 +193,7 @@ var highest = 0, runningTotal = 0; for (var i = 0, arrLen = arr.length; i < arrLen; i++) { for (var j = 0; j < arr[i].length; j++) { - runningTotal += parseInt(getProperty(cache.elements[arr[i][j]], "height").replace("px", "")); + runningTotal += parseInt(getProperty(cache.elements[arr[i][j]], "height").replace("px", ""), 10); runningTotal += j !== 0 ? cache.options.margin : 0; } highest = highest < runningTotal ? runningTotal : highest; diff --git a/dist/macy.min.js b/dist/macy.min.js index 3533c54..8296b2d 100644 --- a/dist/macy.min.js +++ b/dist/macy.min.js @@ -1,7 +1,7 @@ /*! - * Macy.js v1.1.1 - Macy is a lightweight, dependency free, masonry layout library + * Macy.js v1.1.2 - Macy is a lightweight, dependency free, masonry layout library * Author: Copyright (c) Big Bite Creative <@bigbitecreative> * Url: http://macyjs.com/ * License: MIT */ -!function(n,e){"function"==typeof define&&define.amd?define([],function(){return e()}):"object"==typeof exports?module.exports=e():n.Macy=e()}(this,function(){"use strict";var n=function(e){var t,r={},o=1,i=function(e){for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&("[object Object]"===Object.prototype.toString.call(e[t])?r[t]=n(r[t],e[t]):r[t]=e[t])};for(i(arguments[0]),o=1;oe){n=i.options.breakAt[t];break}return n||(n=i.options.columns),n},a=function(n){n="undefined"!=typeof n?n:!0;var e,t=u();return n?1===t?"100%":(e=(t-1)*i.options.margin/t,"calc("+100/t+"% - "+e+"px)"):100/t},c=function(){var n=a();I(i.elements,function(e,t){t.style.width=n,t.style.position="absolute"})},f=function(n){var e,t,r=u(),o=0;return n++,1===n?0:(e=(i.options.margin-(r-1)*i.options.margin/r)*(n-1),o+=a(!1)*(n-1),t="calc("+o+"% + "+e+"px)")},l=function(n,e,t){var r=0;if(0===n)return 0;for(var o=0;n>o;o++)r+=parseInt(h(i.elements[t[o]],"height").replace("px","")),r+=i.options.margin;return r},s=function(n){var e=0,t=[],r=[],o=[];I(i.elements,function(o){e++,e>n&&(e=1,t.push(r),r=[]),r.push(o)}),t.push(r);for(var u=0,a=t.length;a>u;u++)for(var c=t[u],f=0,l=c.length;l>f;f++)o[f]="undefined"==typeof o[f]?[]:o[f],o[f].push(c[f]);i.rows=o,p(!1)},v=function(n){for(var e=i.elements,t=[],r=[],o=0;n>o;o++)t[o]=[];for(var u=0;ua;a++){var f=d(t);t[f]="undefined"==typeof t[f]?[]:t[f],t[f].push(r[a])}i.rows=t,p(!0)},p=function(n){n=n||!1;for(var e=i.elements,t=i.rows,r=0,o=t.length;o>r;r++)for(var u=n?w(t[r]):t[r],a=0,c=u.length;c>a;a++){var s,v;s=f(r),v=l(a,r,u,n),e[u[a]].style.top=v+"px",e[u[a]].style.left=s}},d=function(n){for(var e,t,r,o=0,u=0,a=n.length;a>u;u++){for(var c=0;co?o:t,(void 0===r||r>t)&&(e=u),o=0}return e},h=function(n,e){return window.getComputedStyle(n,null).getPropertyValue(e)},g=function(){for(var n=i.rows,e=0,t=0,r=0,o=n.length;o>r;r++){for(var u=0;ue?t:e,t=0}return e},m=function(){var n=u();return 1===n?(i.container.style.height="auto",void I(i.elements,function(n,e){e.removeAttribute("style")})):(c(),i.elements=i.container.children,i.options.trueOrder?(s(n),void y()):(v(n),void y()))},y=function(){i.container.style.height=g()+"px"},w=function(n){for(var e=n,t=e.length-1,r=0;t>r;r++)for(var o=0;t>o;o++)if(e[o]>e[o+1]){var i=e[o];e[o]=e[o+1],e[o+1]=i}return e},b=function(n){return document.querySelector(n)},x=function(n){for(var e=document.querySelectorAll(n),t=[],r=e.length-1;r>=0;r--)null!==e[r].offsetParent&&t.unshift(e[r]);return t},I=function(n,e){for(var t=0,r=n.length;r>t;t++)e(t,n[t])},O=function(n,e){n=n||!1,e=e||!1,"function"==typeof n&&n(),r>=t&&"function"==typeof e&&e()},A=function(){I(i.container.children,function(n,e){e.removeAttribute("style")}),i.container.removeAttribute("style"),window.removeEventListener("resize",m)},j=function(n,e){var o=x("img");t=o.length-1,r=0,I(o,function(o,i){return i.complete?(r++,void O(n,e)):(i.addEventListener("load",function(){r++,O(n,e)}),void i.addEventListener("error",function(){t--,O(n,e)}))})};return e.init=function(e){return e.container&&(i.container=b(e.container),i.container)?(delete e.container,i.options=n(o,e),window.addEventListener("resize",m),i.container.style.position="relative",i.elements=i.container.children,i.options.waitForImages?void j(null,function(){m()}):(m(),void j(function(){m()}))):void 0},e.recalculate=m,e.onImageLoad=j,e.remove=A,e}); \ No newline at end of file +!function(n,e){"function"==typeof define&&define.amd?define([],function(){return e()}):"object"==typeof exports?module.exports=e():n.Macy=e()}(this,function(){"use strict";var n=function(e){var t,r={},o=1,i=function(e){for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&("[object Object]"===Object.prototype.toString.call(e[t])?r[t]=n(r[t],e[t]):r[t]=e[t])};for(i(arguments[0]),o=1;oe){n=i.options.breakAt[t];break}return n||(n=i.options.columns),n},a=function(n){n="undefined"!=typeof n?n:!0;var e,t=u();return n?1===t?"100%":(e=(t-1)*i.options.margin/t,"calc("+100/t+"% - "+e+"px)"):100/t},c=function(){var n=a();I(i.elements,function(e,t){t.style.width=n,t.style.position="absolute"})},f=function(n){var e,t,r=u(),o=0;return n++,1===n?0:(e=(i.options.margin-(r-1)*i.options.margin/r)*(n-1),o+=a(!1)*(n-1),t="calc("+o+"% + "+e+"px)")},s=function(n,e,t){var r,o=0;if(0===n)return 0;for(var u=0;n>u;u++)r=parseInt(h(i.elements[t[u]],"height").replace("px",""),10),o+=isNaN(r)?0:r+i.options.margin;return o},l=function(n){var e=0,t=[],r=[],o=[];I(i.elements,function(o){e++,e>n&&(e=1,t.push(r),r=[]),r.push(o)}),t.push(r);for(var u=0,a=t.length;a>u;u++)for(var c=t[u],f=0,s=c.length;s>f;f++)o[f]="undefined"==typeof o[f]?[]:o[f],o[f].push(c[f]);i.rows=o,p(!1)},v=function(n){for(var e=i.elements,t=[],r=[],o=0;n>o;o++)t[o]=[];for(var u=0;ua;a++){var f=d(t);t[f]="undefined"==typeof t[f]?[]:t[f],t[f].push(r[a])}i.rows=t,p(!0)},p=function(n){n=n||!1;for(var e=i.elements,t=i.rows,r=0,o=t.length;o>r;r++)for(var u=n?w(t[r]):t[r],a=0,c=u.length;c>a;a++){var l,v;l=f(r),v=s(a,r,u,n),e[u[a]].style.top=v+"px",e[u[a]].style.left=l}},d=function(n){for(var e,t,r,o,u=0,a=0,c=n.length;c>a;a++){for(var f=0;fu?u:t,(void 0===r||r>t)&&(e=a),u=0}return e},h=function(n,e){return window.getComputedStyle(n,null).getPropertyValue(e)},g=function(){for(var n=i.rows,e=0,t=0,r=0,o=n.length;o>r;r++){for(var u=0;ue?t:e,t=0}return e},m=function(){var n=u();return 1===n?(i.container.style.height="auto",void I(i.elements,function(n,e){e.removeAttribute("style")})):(c(),i.elements=i.container.children,i.options.trueOrder?(l(n),void y()):(v(n),void y()))},y=function(){i.container.style.height=g()+"px"},w=function(n){for(var e=n,t=e.length-1,r=0;t>r;r++)for(var o=0;t>o;o++)if(e[o]>e[o+1]){var i=e[o];e[o]=e[o+1],e[o+1]=i}return e},b=function(n){return document.querySelector(n)},x=function(n){for(var e=document.querySelectorAll(n),t=[],r=e.length-1;r>=0;r--)null!==e[r].offsetParent&&t.unshift(e[r]);return t},I=function(n,e){for(var t=0,r=n.length;r>t;t++)e(t,n[t])},O=function(n,e){n=n||!1,e=e||!1,"function"==typeof n&&n(),r>=t&&"function"==typeof e&&e()},A=function(){I(i.container.children,function(n,e){e.removeAttribute("style")}),i.container.removeAttribute("style"),window.removeEventListener("resize",m)},j=function(n,e){var o=x("img");t=o.length-1,r=0,I(o,function(o,i){return i.complete?(r++,void O(n,e)):(i.addEventListener("load",function(){r++,O(n,e)}),void i.addEventListener("error",function(){t--,O(n,e)}))})};return e.init=function(e){return e.container&&(i.container=b(e.container),i.container)?(delete e.container,i.options=n(o,e),window.addEventListener("resize",m),i.container.style.position="relative",i.elements=i.container.children,i.options.waitForImages?void j(null,function(){m()}):(m(),void j(function(){m()}))):void 0},e.recalculate=m,e.onImageLoad=j,e.remove=A,e}); \ No newline at end of file diff --git a/package.json b/package.json index 6644bd5..47526ac 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "macy", "description": "Macy is a lightweight, dependency free, masonry layout library", - "version": "1.1.1", + "version": "1.1.2", "author": { "name": "Big Bite Creative", "url": "http://bigbitecreative.com", diff --git a/src/macy.js b/src/macy.js index 4670166..aa6eed8 100644 --- a/src/macy.js +++ b/src/macy.js @@ -55,7 +55,7 @@ * Current version. * @type {String} */ - Macy.VERSION = '1.1.1'; + Macy.VERSION = '1.1.2'; /** * Expose settings. @@ -170,14 +170,15 @@ */ var getTopValue = function (row, col, eles) { var totalHeight = 0; + var tempHeight; if (row === 0) { return 0; } for (var i = 0; i < row; i++) { - totalHeight += parseInt(getProperty(cache.elements[eles[i]], 'height').replace('px', '')); - totalHeight += cache.options.margin; + tempHeight = parseInt(getProperty(cache.elements[eles[i]], 'height').replace('px', ''), 10); + totalHeight += isNaN(tempHeight) ? 0 : tempHeight + cache.options.margin; } return totalHeight; @@ -278,11 +279,12 @@ */ var findIndexOfSmallestTotal = function (arr) { var runningTotal = 0; - var smallestIndex, smallest, lastSmall; + var smallestIndex, smallest, lastSmall, tempHeight; for (var i = 0, arrLen = arr.length; i < arrLen; i++) { for (var j = 0; j < arr[i].length; j++) { - runningTotal += parseInt(getProperty(cache.elements[arr[i][j]], 'height').replace('px', '')); + tempHeight = parseInt(getProperty(cache.elements[arr[i][j]], 'height').replace('px', ''), 10); + runningTotal += isNaN(tempHeight) ? 0 : tempHeight; } lastSmall = smallest; @@ -317,7 +319,7 @@ for (var i = 0, arrLen = arr.length; i < arrLen; i++) { for (var j = 0; j < arr[i].length; j++) { - runningTotal += parseInt(getProperty(cache.elements[arr[i][j]], 'height').replace('px', '')); + runningTotal += parseInt(getProperty(cache.elements[arr[i][j]], 'height').replace('px', ''), 10); runningTotal += j !== 0 ? cache.options.margin : 0; }