element-resize-detector
Advanced tools
Comparing version 0.3.1 to 0.3.2
/*! | ||
* element-resize-detector 0.3.0 (2015-04-13, 14:53) | ||
* element-resize-detector 0.3.1 (2015-05-10, 14:36) | ||
* https://github.com/wnr/element-resize-detector | ||
@@ -437,5 +437,11 @@ * Licensed under MIT | ||
function makeDetectable(element, callback) { | ||
// Reading properties of elementStyle will result in a forced getComputedStyle for some browsers, so read all values and store them as primitives here. | ||
var elementStyle = getComputedStyle(element); | ||
var position = elementStyle.position; | ||
var width = parseSize(elementStyle.width); | ||
var height = parseSize(elementStyle.height); | ||
var top = elementStyle.top; | ||
var right = elementStyle.right; | ||
var bottom = elementStyle.bottom; | ||
var left = elementStyle.left; | ||
var readyExpandScroll = false; | ||
@@ -452,6 +458,6 @@ var readyShrinkScroll = false; | ||
function mutateDom() { | ||
if(elementStyle.position === "static") { | ||
if(position === "static") { | ||
element.style.position = "relative"; | ||
var removeRelativeStyles = function(reporter, element, style, property) { | ||
var removeRelativeStyles = function(reporter, element, value, property) { | ||
function getNumericalValue(value) { | ||
@@ -461,4 +467,2 @@ return value.replace(/[^-\d\.]/g, ""); | ||
var value = elementStyle[property]; | ||
if(value !== "auto" && getNumericalValue(value) !== "0") { | ||
@@ -472,6 +476,6 @@ reporter.warn("An element that is positioned static has style." + property + "=" + value + " which is ignored due to the static positioning. The element will need to be positioned relative, so the style." + property + " will be set to 0. Element: ", element); | ||
//If there are any, set them to 0 (this should be okay with the user since the style properties did nothing before [since the element was positioned static] anyway). | ||
removeRelativeStyles(reporter, element, elementStyle, "top"); | ||
removeRelativeStyles(reporter, element, elementStyle, "right"); | ||
removeRelativeStyles(reporter, element, elementStyle, "bottom"); | ||
removeRelativeStyles(reporter, element, elementStyle, "left"); | ||
removeRelativeStyles(reporter, element, top, "top"); | ||
removeRelativeStyles(reporter, element, right, "right"); | ||
removeRelativeStyles(reporter, element, bottom, "bottom"); | ||
removeRelativeStyles(reporter, element, left, "left"); | ||
} | ||
@@ -478,0 +482,0 @@ |
/*! | ||
* element-resize-detector 0.3.0 (2015-04-13, 14:53) | ||
* element-resize-detector 0.3.1 (2015-05-10, 14:36) | ||
* https://github.com/wnr/element-resize-detector | ||
@@ -7,2 +7,2 @@ * Licensed under MIT | ||
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.elementResizeDetectorMaker=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){"use strict";var c=a("./utils");b.exports=function(a){function b(a,b){b||(b=a,a=0),a>o?o=a:p>a&&(p=a),m[a]||(m[a]=[]),l&&k&&0===n&&f(),m[a].push(b),n++}function d(a){void 0===a&&(a=k),q&&(h(q),q=null),k?f():e()}function e(){for(var a=p;o>=a;a++)for(var b=m[a],c=0;c<b.length;c++){var d=b[c];d()}g()}function f(){q=i(e)}function g(){m={},n=0,o=0,p=0}function h(a){var b=window.clearTimeout;return b(a)}function i(a){var b=function(a){return window.setTimeout(a,0)};return b(a)}a=a||{};var j=a.reporter,k=c.getOption(a,"async",!0),l=c.getOption(a,"auto",!0);l&&!k&&(j&&j.warn("Invalid options combination. auto=true and async=false is invalid. Setting async=true."),k=!0);var m,n,o,p;g();var q;return{add:b,force:d}}},{"./utils":2}],2:[function(a,b){"use strict";function c(a,b,c){var d=a[b];return void 0!==d&&null!==d||void 0===c?d:c}var d=b.exports={};d.getOption=c},{}],3:[function(a,b){"use strict";var c=b.exports={};c.isIE=function(a){function b(){var a=navigator.userAgent.toLowerCase();return-1!==a.indexOf("msie")||-1!==a.indexOf("trident")}if(!b())return!1;if(!a)return!0;var c=function(){var a,b=3,c=document.createElement("div"),d=c.getElementsByTagName("i");do c.innerHTML="<!--[if gt IE "+ ++b+"]><i></i><![endif]-->";while(d[0]);return b>4?b:a}();return a===c},c.isLegacyOpera=function(){return!!window.opera}},{}],4:[function(a,b){"use strict";var c=b.exports={};c.forEach=function(a,b){for(var c=0;c<a.length;c++){var d=b(a[c]);if(d)return d}}},{}],5:[function(a,b){"use strict";var c=a("../browser-detector");b.exports=function(a){function b(a,b){function d(){b(a)}if(!e(a))throw new Error("Element is not detectable by this strategy.");if(c.isIE(8))a.attachEvent("onresize",d);else{var f=e(a);f.contentDocument.defaultView.addEventListener("resize",d)}}function d(a,b){function d(a,b){function d(){function c(a,b){return a.contentDocument?void b(a.contentDocument):void setTimeout(function(){c(a,b)},100)}var d=this;c(d,function(c){var d=c.createElement("style");d.innerHTML="html, body { margin: 0; padding: 0 } div { -webkit-transition: opacity 0.01s; -ms-transition: opacity 0.01s; -o-transition: opacity 0.01s; transition: opacity 0.01s; opacity: 0; }",c.head.appendChild(d),b(a)})}function e(){if("static"===j){a.style.position="relative";var b=function(a,b,c,d){function e(a){return a.replace(/[^-\d\.]/g,"")}var f=c[d];"auto"!==f&&"0"!==e(f)&&(a.warn("An element that is positioned static has style."+d+"="+f+" which is ignored due to the static positioning. The element will need to be positioned relative, so the style."+d+" will be set to 0. Element: ",b),b.style[d]=0)};b(f,a,i,"top"),b(f,a,i,"right"),b(f,a,i,"bottom"),b(f,a,i,"left")}var e=document.createElement("object");e.style.cssText=h,e.type="text/html",e.onload=d,c.isIE()||(e.data="about:blank"),a.appendChild(e),a._erdObject=e,c.isIE()&&(e.data="about:blank")}var h="display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; padding: 0; margin: 0; opacity: 0; z-index: -1000; pointer-events: none;",i=getComputedStyle(a),j=i.position;g?g.add(e):e()}c.isIE(8)?b(a):d(a,b)}function e(a){return a._erdObject}a=a||{};var f=a.reporter,g=a.batchProcessor;if(!f)throw new Error("Missing required dependency: reporter.");return{makeDetectable:d,addListener:b}}},{"../browser-detector":3}],6:[function(a,b){"use strict";b.exports=function(a){function b(a,b){var c=function(){var c=getComputedStyle(a),d=n(c.width),e=n(c.height);q.add(function(){i(a,d,e),j(a,d,e)}),q.add(1,function(){k(a,d,e),b(a)})},e=d(a),g=f(a);l(e,"scroll",function(){var b=getComputedStyle(a),d=n(b.width),e=n(b.height);(d>a.lastWidth||e>a.lastHeight)&&c()}),l(g,"scroll",function(){var b=getComputedStyle(a),d=n(b.width),e=n(b.height);(d<a.lastWidth||e<a.lastHeight)&&c()})}function c(a,b){function c(){o&&s&&t&&b(a)}function d(){function b(a,b,c,d){return a=a?a+"px":"0",b=b?b+"px":"0",c=c?c+"px":"0",d=d?d+"px":"0","position: absolute; left: "+a+"; top: "+b+"; right: "+d+"; bottom: "+c+"; overflow: scroll; z-index: -1; visibility: hidden;"}if("static"===f.position){a.style.position="relative";var d=function(a,b,c,d){function e(a){return a.replace(/[^-\d\.]/g,"")}var g=f[d];"auto"!==g&&"0"!==e(g)&&(a.warn("An element that is positioned static has style."+d+"="+g+" which is ignored due to the static positioning. The element will need to be positioned relative, so the style."+d+" will be set to 0. Element: ",b),b.style[d]=0)};d(p,a,f,"top"),d(p,a,f,"right"),d(p,a,f,"bottom"),d(p,a,f,"left")}var e=r.width,j=r.height,k=b(-1,-1,-j,-e),n=b(0,0,-j,-e),q="position: absolute; left: 0; top: 0;",t=document.createElement("div"),u=document.createElement("div"),v=document.createElement("div"),w=document.createElement("div"),x=document.createElement("div");t.style.cssText=k,u.style.cssText=n,v.style.cssText=q,w.style.cssText=n,x.style.cssText=q+" width: 200%; height: 200%;",u.appendChild(v),w.appendChild(x),t.appendChild(u),t.appendChild(w),a.appendChild(t),a._erdElement=t,l(u,"scroll",function y(){m(u,"scroll",y),o=!0,c()}),l(w,"scroll",function z(){m(w,"scroll",z),s=!0,c()}),i(a,g,h)}function e(){j(a,g,h),k(a,g,h),t=!0,c()}var f=getComputedStyle(a),g=n(f.width),h=n(f.height),o=!1,s=!1,t=!1;q?(q.add(d),q.add(1,e)):(d(),e())}function d(a){return a._erdElement.childNodes[0]}function e(a){return d(a).childNodes[0]}function f(a){return a._erdElement.childNodes[1]}function g(a){return a+10}function h(a){return 2*a}function i(a,b,c){var d=e(a),f=g(b),h=g(c);d.style.width=f+"px",d.style.height=h+"px"}function j(a,b,c){a.lastWidth=b,a.lastHeight=c}function k(a,b,c){var e=d(a),i=f(a),j=g(b),k=g(c),l=h(b),m=h(c);e.scrollLeft=j,e.scrollTop=k,i.scrollLeft=l,i.scrollTop=m}function l(a,b,c){a.attachEvent?a.attachEvent("on"+b,c):a.addEventListener(b,c)}function m(a,b,c){a.attachEvent?a.detachEvent("on"+b,c):a.removeEventListener(b,c)}function n(a){return parseFloat(a.replace(/px/,""))}function o(){var a=500,b=500,c=document.createElement("div");c.style.cssText="position: absolute; width: "+2*a+"px; height: "+2*b+"px; visibility: hidden;";var d=document.createElement("div");d.style.cssText="position: absolute; width: "+a+"px; height: "+b+"px; overflow: scroll; visibility: none; top: "+3*-a+"px; left: "+3*-b+"px; visibility: hidden;",d.appendChild(c),document.body.insertBefore(d,document.body.firstChild);var e=a-d.clientWidth,f=b-d.clientHeight;return document.body.removeChild(d),{width:e,height:f}}a=a||{};var p=a.reporter,q=a.batchProcessor;if(!p)throw new Error("Missing required dependency: reporter.");var r=o();return{makeDetectable:c,addListener:b}}},{}],7:[function(a,b){"use strict";function c(a,b,c){var d=a[b];return void 0!==d&&null!==d||void 0===c?d:c}var d=a("./collection-utils").forEach,e=a("./element-utils"),f=a("./listener-handler"),g=a("./id-generator"),h=a("./id-handler"),i=a("./reporter"),j=a("./browser-detector"),k=a("batch-processor"),l=a("./detection-strategy/object.js"),m=a("./detection-strategy/scroll.js");b.exports=function(a){function b(a,b,e){function f(a){var b=v.get(a);d(b,function(b){b(a)})}function g(a,b,c){v.add(b,c),a&&c(b)}if(e||(e=b,b=a,a={}),!b)throw new Error("At least one element required.");if(!e)throw new Error("Listener required.");void 0===b.length&&(b=[b]);var h=0,i=c(a,"callOnAdd",t.callOnAdd),j=c(a,"onReady",function(){});d(b,function(a){var c=n.get(a);return w.isDetectable(a)?(g(i,a,e),void h++):w.isBusy(a)?(g(i,a,e),z[c]=z[c]||[],void z[c].push(function(){h++,h===b.length&&j()})):(w.markBusy(a,!0),u.makeDetectable(a,function(a){w.markAsDetectable(a),w.markBusy(a,!1),u.addListener(a,f),g(i,a,e),h++,h===b.length&&j(),z[c]&&(d(z[c],function(a){a()}),delete z[c])}))}),h===b.length&&j()}a=a||{};var n=a.idHandler;if(!n){var o=g(),p=h(o);n=p}var q=a.reporter;if(!q){var r=q===!1;q=i(r)}var s=c(a,"batchProcessor",k({reporter:q})),t={};t.callOnAdd=!!c(a,"callOnAdd",!0);var u,v=f(n),w=e(),x=c(a,"strategy","object"),y={reporter:q,batchProcessor:s};if("scroll"===x&&j.isLegacyOpera()&&(q.warn("Scroll strategy is not supported on legacy Opera. Changing to object strategy."),x="object"),"scroll"===x)u=m(y);else{if("object"!==x)throw new Error("Invalid strategy name: "+x);u=l(y)}var z={};return{listenTo:b}}},{"./browser-detector":3,"./collection-utils":4,"./detection-strategy/object.js":5,"./detection-strategy/scroll.js":6,"./element-utils":8,"./id-generator":9,"./id-handler":10,"./listener-handler":11,"./reporter":12,"batch-processor":1}],8:[function(a,b){"use strict";b.exports=function(){function a(a){return!!a._erdIsDetectable}function b(a){a._erdIsDetectable=!0}function c(a){return!!a._erdBusy}function d(a,b){a._erdBusy=!!b}return{isDetectable:a,markAsDetectable:b,isBusy:c,markBusy:d}}},{}],9:[function(a,b){"use strict";b.exports=function(){function a(){return b++}var b=1;return{generate:a}}},{}],10:[function(a,b){"use strict";b.exports=function(a){function b(a,b){return b||d(a)||c(a),a[e]}function c(b){var c=a.generate();return b[e]=c,c}function d(a){return void 0!==a[e]}var e="_erdTargetId";return{get:b}}},{}],11:[function(a,b){"use strict";b.exports=function(a){function b(b){return d[a.get(b)]}function c(b,c){var e=a.get(b);d[e]||(d[e]=[]),d[e].push(c)}var d={};return{get:b,add:c}}},{}],12:[function(a,b){"use strict";b.exports=function(a){function b(){}var c={log:b,warn:b,error:b};if(!a&&window.console){var d=function(a,b){a[b]=function(){console[b].apply(console,arguments)}};d(c,"log"),d(c,"warn"),d(c,"error")}return c}},{}]},{},[7])(7)}); | ||
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.elementResizeDetectorMaker=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){"use strict";var c=a("./utils");b.exports=function(a){function b(a,b){b||(b=a,a=0),a>o?o=a:p>a&&(p=a),m[a]||(m[a]=[]),l&&k&&0===n&&f(),m[a].push(b),n++}function d(a){void 0===a&&(a=k),q&&(h(q),q=null),k?f():e()}function e(){for(var a=p;o>=a;a++)for(var b=m[a],c=0;c<b.length;c++){var d=b[c];d()}g()}function f(){q=i(e)}function g(){m={},n=0,o=0,p=0}function h(a){var b=window.clearTimeout;return b(a)}function i(a){var b=function(a){return window.setTimeout(a,0)};return b(a)}a=a||{};var j=a.reporter,k=c.getOption(a,"async",!0),l=c.getOption(a,"auto",!0);l&&!k&&(j&&j.warn("Invalid options combination. auto=true and async=false is invalid. Setting async=true."),k=!0);var m,n,o,p;g();var q;return{add:b,force:d}}},{"./utils":2}],2:[function(a,b){"use strict";function c(a,b,c){var d=a[b];return void 0!==d&&null!==d||void 0===c?d:c}var d=b.exports={};d.getOption=c},{}],3:[function(a,b){"use strict";var c=b.exports={};c.isIE=function(a){function b(){var a=navigator.userAgent.toLowerCase();return-1!==a.indexOf("msie")||-1!==a.indexOf("trident")}if(!b())return!1;if(!a)return!0;var c=function(){var a,b=3,c=document.createElement("div"),d=c.getElementsByTagName("i");do c.innerHTML="<!--[if gt IE "+ ++b+"]><i></i><![endif]-->";while(d[0]);return b>4?b:a}();return a===c},c.isLegacyOpera=function(){return!!window.opera}},{}],4:[function(a,b){"use strict";var c=b.exports={};c.forEach=function(a,b){for(var c=0;c<a.length;c++){var d=b(a[c]);if(d)return d}}},{}],5:[function(a,b){"use strict";var c=a("../browser-detector");b.exports=function(a){function b(a,b){function d(){b(a)}if(!e(a))throw new Error("Element is not detectable by this strategy.");if(c.isIE(8))a.attachEvent("onresize",d);else{var f=e(a);f.contentDocument.defaultView.addEventListener("resize",d)}}function d(a,b){function d(a,b){function d(){function c(a,b){return a.contentDocument?void b(a.contentDocument):void setTimeout(function(){c(a,b)},100)}var d=this;c(d,function(c){var d=c.createElement("style");d.innerHTML="html, body { margin: 0; padding: 0 } div { -webkit-transition: opacity 0.01s; -ms-transition: opacity 0.01s; -o-transition: opacity 0.01s; transition: opacity 0.01s; opacity: 0; }",c.head.appendChild(d),b(a)})}function e(){if("static"===j){a.style.position="relative";var b=function(a,b,c,d){function e(a){return a.replace(/[^-\d\.]/g,"")}var f=c[d];"auto"!==f&&"0"!==e(f)&&(a.warn("An element that is positioned static has style."+d+"="+f+" which is ignored due to the static positioning. The element will need to be positioned relative, so the style."+d+" will be set to 0. Element: ",b),b.style[d]=0)};b(f,a,i,"top"),b(f,a,i,"right"),b(f,a,i,"bottom"),b(f,a,i,"left")}var e=document.createElement("object");e.style.cssText=h,e.type="text/html",e.onload=d,c.isIE()||(e.data="about:blank"),a.appendChild(e),a._erdObject=e,c.isIE()&&(e.data="about:blank")}var h="display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; padding: 0; margin: 0; opacity: 0; z-index: -1000; pointer-events: none;",i=getComputedStyle(a),j=i.position;g?g.add(e):e()}c.isIE(8)?b(a):d(a,b)}function e(a){return a._erdObject}a=a||{};var f=a.reporter,g=a.batchProcessor;if(!f)throw new Error("Missing required dependency: reporter.");return{makeDetectable:d,addListener:b}}},{"../browser-detector":3}],6:[function(a,b){"use strict";b.exports=function(a){function b(a,b){var c=function(){var c=getComputedStyle(a),d=n(c.width),e=n(c.height);q.add(function(){i(a,d,e),j(a,d,e)}),q.add(1,function(){k(a,d,e),b(a)})},e=d(a),g=f(a);l(e,"scroll",function(){var b=getComputedStyle(a),d=n(b.width),e=n(b.height);(d>a.lastWidth||e>a.lastHeight)&&c()}),l(g,"scroll",function(){var b=getComputedStyle(a),d=n(b.width),e=n(b.height);(d<a.lastWidth||e<a.lastHeight)&&c()})}function c(a,b){function c(){w&&x&&y&&b(a)}function d(){function b(a,b,c,d){return a=a?a+"px":"0",b=b?b+"px":"0",c=c?c+"px":"0",d=d?d+"px":"0","position: absolute; left: "+a+"; top: "+b+"; right: "+d+"; bottom: "+c+"; overflow: scroll; z-index: -1; visibility: hidden;"}if("static"===g){a.style.position="relative";var d=function(a,b,c,d){function e(a){return a.replace(/[^-\d\.]/g,"")}"auto"!==c&&"0"!==e(c)&&(a.warn("An element that is positioned static has style."+d+"="+c+" which is ignored due to the static positioning. The element will need to be positioned relative, so the style."+d+" will be set to 0. Element: ",b),b.style[d]=0)};d(p,a,s,"top"),d(p,a,t,"right"),d(p,a,u,"bottom"),d(p,a,v,"left")}var e=r.width,f=r.height,j=b(-1,-1,-f,-e),k=b(0,0,-f,-e),n="position: absolute; left: 0; top: 0;",q=document.createElement("div"),y=document.createElement("div"),z=document.createElement("div"),A=document.createElement("div"),B=document.createElement("div");q.style.cssText=j,y.style.cssText=k,z.style.cssText=n,A.style.cssText=k,B.style.cssText=n+" width: 200%; height: 200%;",y.appendChild(z),A.appendChild(B),q.appendChild(y),q.appendChild(A),a.appendChild(q),a._erdElement=q,l(y,"scroll",function C(){m(y,"scroll",C),w=!0,c()}),l(A,"scroll",function D(){m(A,"scroll",D),x=!0,c()}),i(a,h,o)}function e(){j(a,h,o),k(a,h,o),y=!0,c()}var f=getComputedStyle(a),g=f.position,h=n(f.width),o=n(f.height),s=f.top,t=f.right,u=f.bottom,v=f.left,w=!1,x=!1,y=!1;q?(q.add(d),q.add(1,e)):(d(),e())}function d(a){return a._erdElement.childNodes[0]}function e(a){return d(a).childNodes[0]}function f(a){return a._erdElement.childNodes[1]}function g(a){return a+10}function h(a){return 2*a}function i(a,b,c){var d=e(a),f=g(b),h=g(c);d.style.width=f+"px",d.style.height=h+"px"}function j(a,b,c){a.lastWidth=b,a.lastHeight=c}function k(a,b,c){var e=d(a),i=f(a),j=g(b),k=g(c),l=h(b),m=h(c);e.scrollLeft=j,e.scrollTop=k,i.scrollLeft=l,i.scrollTop=m}function l(a,b,c){a.attachEvent?a.attachEvent("on"+b,c):a.addEventListener(b,c)}function m(a,b,c){a.attachEvent?a.detachEvent("on"+b,c):a.removeEventListener(b,c)}function n(a){return parseFloat(a.replace(/px/,""))}function o(){var a=500,b=500,c=document.createElement("div");c.style.cssText="position: absolute; width: "+2*a+"px; height: "+2*b+"px; visibility: hidden;";var d=document.createElement("div");d.style.cssText="position: absolute; width: "+a+"px; height: "+b+"px; overflow: scroll; visibility: none; top: "+3*-a+"px; left: "+3*-b+"px; visibility: hidden;",d.appendChild(c),document.body.insertBefore(d,document.body.firstChild);var e=a-d.clientWidth,f=b-d.clientHeight;return document.body.removeChild(d),{width:e,height:f}}a=a||{};var p=a.reporter,q=a.batchProcessor;if(!p)throw new Error("Missing required dependency: reporter.");var r=o();return{makeDetectable:c,addListener:b}}},{}],7:[function(a,b){"use strict";function c(a,b,c){var d=a[b];return void 0!==d&&null!==d||void 0===c?d:c}var d=a("./collection-utils").forEach,e=a("./element-utils"),f=a("./listener-handler"),g=a("./id-generator"),h=a("./id-handler"),i=a("./reporter"),j=a("./browser-detector"),k=a("batch-processor"),l=a("./detection-strategy/object.js"),m=a("./detection-strategy/scroll.js");b.exports=function(a){function b(a,b,e){function f(a){var b=v.get(a);d(b,function(b){b(a)})}function g(a,b,c){v.add(b,c),a&&c(b)}if(e||(e=b,b=a,a={}),!b)throw new Error("At least one element required.");if(!e)throw new Error("Listener required.");void 0===b.length&&(b=[b]);var h=0,i=c(a,"callOnAdd",t.callOnAdd),j=c(a,"onReady",function(){});d(b,function(a){var c=n.get(a);return w.isDetectable(a)?(g(i,a,e),void h++):w.isBusy(a)?(g(i,a,e),z[c]=z[c]||[],void z[c].push(function(){h++,h===b.length&&j()})):(w.markBusy(a,!0),u.makeDetectable(a,function(a){w.markAsDetectable(a),w.markBusy(a,!1),u.addListener(a,f),g(i,a,e),h++,h===b.length&&j(),z[c]&&(d(z[c],function(a){a()}),delete z[c])}))}),h===b.length&&j()}a=a||{};var n=a.idHandler;if(!n){var o=g(),p=h(o);n=p}var q=a.reporter;if(!q){var r=q===!1;q=i(r)}var s=c(a,"batchProcessor",k({reporter:q})),t={};t.callOnAdd=!!c(a,"callOnAdd",!0);var u,v=f(n),w=e(),x=c(a,"strategy","object"),y={reporter:q,batchProcessor:s};if("scroll"===x&&j.isLegacyOpera()&&(q.warn("Scroll strategy is not supported on legacy Opera. Changing to object strategy."),x="object"),"scroll"===x)u=m(y);else{if("object"!==x)throw new Error("Invalid strategy name: "+x);u=l(y)}var z={};return{listenTo:b}}},{"./browser-detector":3,"./collection-utils":4,"./detection-strategy/object.js":5,"./detection-strategy/scroll.js":6,"./element-utils":8,"./id-generator":9,"./id-handler":10,"./listener-handler":11,"./reporter":12,"batch-processor":1}],8:[function(a,b){"use strict";b.exports=function(){function a(a){return!!a._erdIsDetectable}function b(a){a._erdIsDetectable=!0}function c(a){return!!a._erdBusy}function d(a,b){a._erdBusy=!!b}return{isDetectable:a,markAsDetectable:b,isBusy:c,markBusy:d}}},{}],9:[function(a,b){"use strict";b.exports=function(){function a(){return b++}var b=1;return{generate:a}}},{}],10:[function(a,b){"use strict";b.exports=function(a){function b(a,b){return b||d(a)||c(a),a[e]}function c(b){var c=a.generate();return b[e]=c,c}function d(a){return void 0!==a[e]}var e="_erdTargetId";return{get:b}}},{}],11:[function(a,b){"use strict";b.exports=function(a){function b(b){return d[a.get(b)]}function c(b,c){var e=a.get(b);d[e]||(d[e]=[]),d[e].push(c)}var d={};return{get:b,add:c}}},{}],12:[function(a,b){"use strict";b.exports=function(a){function b(){}var c={log:b,warn:b,error:b};if(!a&&window.console){var d=function(a,b){a[b]=function(){console[b].apply(console,arguments)}};d(c,"log"),d(c,"warn"),d(c,"error")}return c}},{}]},{},[7])(7)}); |
{ | ||
"name": "element-resize-detector", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "resize event emitter for elements.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/wnr/element-resize-detector", |
@@ -72,5 +72,11 @@ /** | ||
function makeDetectable(element, callback) { | ||
// Reading properties of elementStyle will result in a forced getComputedStyle for some browsers, so read all values and store them as primitives here. | ||
var elementStyle = getComputedStyle(element); | ||
var position = elementStyle.position; | ||
var width = parseSize(elementStyle.width); | ||
var height = parseSize(elementStyle.height); | ||
var top = elementStyle.top; | ||
var right = elementStyle.right; | ||
var bottom = elementStyle.bottom; | ||
var left = elementStyle.left; | ||
var readyExpandScroll = false; | ||
@@ -87,6 +93,6 @@ var readyShrinkScroll = false; | ||
function mutateDom() { | ||
if(elementStyle.position === "static") { | ||
if(position === "static") { | ||
element.style.position = "relative"; | ||
var removeRelativeStyles = function(reporter, element, style, property) { | ||
var removeRelativeStyles = function(reporter, element, value, property) { | ||
function getNumericalValue(value) { | ||
@@ -96,4 +102,2 @@ return value.replace(/[^-\d\.]/g, ""); | ||
var value = elementStyle[property]; | ||
if(value !== "auto" && getNumericalValue(value) !== "0") { | ||
@@ -107,6 +111,6 @@ reporter.warn("An element that is positioned static has style." + property + "=" + value + " which is ignored due to the static positioning. The element will need to be positioned relative, so the style." + property + " will be set to 0. Element: ", element); | ||
//If there are any, set them to 0 (this should be okay with the user since the style properties did nothing before [since the element was positioned static] anyway). | ||
removeRelativeStyles(reporter, element, elementStyle, "top"); | ||
removeRelativeStyles(reporter, element, elementStyle, "right"); | ||
removeRelativeStyles(reporter, element, elementStyle, "bottom"); | ||
removeRelativeStyles(reporter, element, elementStyle, "left"); | ||
removeRelativeStyles(reporter, element, top, "top"); | ||
removeRelativeStyles(reporter, element, right, "right"); | ||
removeRelativeStyles(reporter, element, bottom, "bottom"); | ||
removeRelativeStyles(reporter, element, left, "left"); | ||
} | ||
@@ -113,0 +117,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
232510
3685