Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

element-resize-detector

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

element-resize-detector - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

287

dist/element-resize-detector.js
/*!
* element-resize-detector 0.2.8 (2015-04-12, 18:14)
* element-resize-detector 0.3.0 (2015-04-13, 14:53)
* https://github.com/wnr/element-resize-detector

@@ -12,77 +12,84 @@ * Licensed under MIT

module.exports = function batchUpdaterMaker(options) {
options = options || {};
module.exports = function batchProcessorMaker(options) {
options = options || {};
var reporter = options.reporter;
var async = utils.getOption(options, "async", true);
var autoUpdate = utils.getOption(options, "auto", true);
var autoProcess = utils.getOption(options, "auto", true);
if(autoUpdate && !async) {
reporter.warn("Invalid options combination. auto=true and async=false is invalid. Setting async=true.");
if(autoProcess && !async) {
reporter && reporter.warn("Invalid options combination. auto=true and async=false is invalid. Setting async=true.");
async = true;
}
if(!reporter) {
throw new Error("Reporter required.");
}
var batch;
var batchSize;
var topLevel;
var bottomLevel;
var batchSize = 0;
var batch = {};
var handler;
var onProcessedCallback = function() {};
clearBatch();
function queueUpdate(element, updater) {
if(autoUpdate && async && batchSize === 0) {
updateBatchAsync();
var asyncFrameHandler;
function addFunction(level, fn) {
if(!fn) {
fn = level;
level = 0;
}
if(!batch[element]) {
batch[element] = [];
if(level > topLevel) {
topLevel = level;
} else if(level < bottomLevel) {
bottomLevel = level;
}
batch[element].push(updater);
if(!batch[level]) {
batch[level] = [];
}
if(autoProcess && async && batchSize === 0) {
processBatchAsync();
}
batch[level].push(fn);
batchSize++;
}
function forceUpdateBatch(updateAsync) {
if(updateAsync === undefined) {
updateAsync = async;
function forceProcessBatch(processAsync) {
if(processAsync === undefined) {
processAsync = async;
}
if(handler) {
cancelFrame(handler);
handler = null;
if(asyncFrameHandler) {
cancelFrame(asyncFrameHandler);
asyncFrameHandler = null;
}
if(async) {
updateBatchAsync();
processBatchAsync();
} else {
updateBatch();
processBatch();
}
}
function updateBatch() {
for(var element in batch) {
if(batch.hasOwnProperty(element)) {
var updaters = batch[element];
function processBatch() {
for(var level = bottomLevel; level <= topLevel; level++) {
var fns = batch[level];
for(var i = 0; i < updaters.length; i++) {
var updater = updaters[i];
updater();
}
for(var i = 0; i < fns.length; i++) {
var fn = fns[i];
fn();
}
}
clearBatch();
onProcessedCallback();
}
function updateBatchAsync() {
handler = requestFrame(function performUpdate() {
updateBatch();
});
function processBatchAsync() {
asyncFrameHandler = requestFrame(processBatch);
}
function clearBatch() {
batchSize = 0;
batch = {};
batch = {};
batchSize = 0;
topLevel = 0;
bottomLevel = 0;
}

@@ -102,10 +109,5 @@

function onProcessed(callback) {
onProcessedCallback = callback || function() {};
}
return {
update: queueUpdate,
force: forceUpdateBatch,
onProcessed: onProcessed
add: addFunction,
force: forceProcessBatch
};

@@ -167,2 +169,6 @@ };

detector.isLegacyOpera = function() {
return !!window.opera;
}
},{}],4:[function(require,module,exports){

@@ -197,3 +203,2 @@ "use strict";

var forEach = require("../collection-utils").forEach;
var browserDetector = require("../browser-detector");

@@ -203,10 +208,5 @@

options = options || {};
var idHandler = options.idHandler;
var reporter = options.reporter;
var batchUpdater = options.batchUpdater;
var batchProcessor = options.batchProcessor;
if(!idHandler) {
throw new Error("Missing required dependency: idHandler.");
}
if(!reporter) {

@@ -247,3 +247,3 @@ throw new Error("Missing required dependency: reporter.");

function makeDetectable(element, callback) {
function injectObject(id, element, callback) {
function injectObject(element, callback) {
var OBJECT_STYLE = "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;";

@@ -322,3 +322,2 @@

object.onload = onObjectLoad;
object._erdObjectId = id;

@@ -332,2 +331,3 @@ //Safari: This must occur before adding the object to the DOM.

element.appendChild(object);
element._erdObject = object;

@@ -340,4 +340,4 @@ //IE: This must occur after adding the object to the DOM.

if(batchUpdater) {
batchUpdater.update(id, mutateDom);
if(batchProcessor) {
batchProcessor.add(mutateDom);
} else {

@@ -348,5 +348,2 @@ mutateDom();

//Obtain the id of the element (will be generated if not present), so that event listeners can be identified to this element.
var id = idHandler.get(element);
if(browserDetector.isIE(8)) {

@@ -358,3 +355,3 @@ //IE 8 does not support objects properly. Luckily they do support the resize event.

} else {
injectObject(id, element, callback);
injectObject(element, callback);
}

@@ -370,7 +367,3 @@ }

function getObject(element) {
return forEach(element.children, function isObject(child) {
if(child._erdObjectId !== undefined && child._erdObjectId !== null) {
return child;
}
});
return element._erdObject;
}

@@ -384,3 +377,3 @@

},{"../browser-detector":3,"../collection-utils":4}],6:[function(require,module,exports){
},{"../browser-detector":3}],6:[function(require,module,exports){
/**

@@ -393,27 +386,7 @@ * Resize detection strategy that injects divs to elements in order to detect resize events on scroll events.

var batchUpdaterMaker = require("batch-updater");
module.exports = function(options) {
options = options || {};
var idHandler = options.idHandler;
var reporter = options.reporter;
var batchUpdater = options.batchUpdater;
var batchProcessor = options.batchProcessor;
//TODO: This is ugly. The batch updator should support leveled batches or something similar.
var testBatchUpdater = batchUpdaterMaker({
reporter: reporter
});
var testBatchUpdater2 = batchUpdaterMaker({
reporter: reporter
});
//TODO: This should probably be DI, or atleast the maker function so that other frameworks can share the batch-updater code. It might not make sense to share a batch updater, since batches can interfere with each other.
var scrollbarsBatchUpdater = batchUpdaterMaker({
reporter: reporter
});
if(!idHandler) {
throw new Error("Missing required dependency: idHandler.");
}
if(!reporter) {

@@ -423,2 +396,5 @@ throw new Error("Missing required dependency: reporter.");

//TODO: Could this perhaps be done at installation time?
var scrollbarSizes = getScrollbarSizes();
/**

@@ -435,12 +411,12 @@ * Adds a resize event listener to the element.

var height = parseSize(elementStyle.height);
var id = idHandler.get(element);
testBatchUpdater.update(id, function updateDetectorElements() {
batchProcessor.add(function updateDetectorElements() {
updateChildSizes(element, width, height);
storeCurrentSize(element, width, height);
testBatchUpdater2.update(id, function updateScrollbars() {
positionScrollbars(element, width, height);
listener(element);
});
});
batchProcessor.add(1, function updateScrollbars() {
positionScrollbars(element, width, height);
listener(element);
});
};

@@ -477,6 +453,15 @@

function makeDetectable(element, callback) {
var elementStyle = getComputedStyle(element);
var width = parseSize(elementStyle.width);
var height = parseSize(elementStyle.height);
var elementStyle = getComputedStyle(element);
var width = parseSize(elementStyle.width);
var height = parseSize(elementStyle.height);
var readyExpandScroll = false;
var readyShrinkScroll = false;
var readyOverall = false;
function ready() {
if(readyExpandScroll && readyShrinkScroll && readyOverall) {
callback(element);
}
}
function mutateDom() {

@@ -507,21 +492,15 @@ if(elementStyle.position === "static") {

function getContainerCssText(left, top) {
function getContainerCssText(left, top, bottom, right) {
left = (!left ? "0" : (left + "px"));
top = (!top ? "0" : (top + "px"));
bottom = (!bottom ? "0" : (bottom + "px"));
right = (!right ? "0" : (right + "px"));
return "position: absolute; left: " + left + "; top: " + top + "; right: 0; bottom: 0; overflow: scroll; z-index: -1; visibility: hidden;";
return "position: absolute; left: " + left + "; top: " + top + "; right: " + right + "; bottom: " + bottom + "; overflow: scroll; z-index: -1; visibility: hidden;";
}
var readyExpandScroll = false;
var readyShrinkScroll = false;
var readyOverall = false;
function ready() {
if(readyExpandScroll && readyShrinkScroll && readyOverall) {
callback(element);
}
}
var containerStyle = getContainerCssText(-1, -1);
var shrinkExpandstyle = getContainerCssText(0, 0);
var scrollbarWidth = scrollbarSizes.width;
var scrollbarHeight = scrollbarSizes.height;
var containerStyle = getContainerCssText(-1, -1, -scrollbarHeight, -scrollbarWidth);
var shrinkExpandstyle = getContainerCssText(0, 0, -scrollbarHeight, -scrollbarWidth);
var shrinkExpandChildStyle = "position: absolute; left: 0; top: 0;";

@@ -561,17 +540,17 @@

updateChildSizes(element, width, height);
}
scrollbarsBatchUpdater.update(id, function finalize() {
storeCurrentSize(element, width, height);
positionScrollbars(element, width, height);
readyOverall = true;
ready();
});
function finalizeDomMutation() {
storeCurrentSize(element, width, height);
positionScrollbars(element, width, height);
readyOverall = true;
ready();
}
var id = idHandler.get(element);
if(batchUpdater) {
batchUpdater.update(id, mutateDom);
if(batchProcessor) {
batchProcessor.add(mutateDom);
batchProcessor.add(1, finalizeDomMutation);
} else {
mutateDom();
finalizeDomMutation();
}

@@ -642,2 +621,31 @@ }

function parseSize(size) {
return parseFloat(size.replace(/px/, ""));
}
function getScrollbarSizes() {
var width = 500;
var height = 500;
var child = document.createElement("div");
child.style.cssText = "position: absolute; width: " + width*2 + "px; height: " + height*2 + "px; visibility: hidden;";
var container = document.createElement("div");
container.style.cssText = "position: absolute; width: " + width + "px; height: " + height + "px; overflow: scroll; visibility: none; top: " + -width*3 + "px; left: " + -height*3 + "px; visibility: hidden;";
container.appendChild(child);
document.body.insertBefore(container, document.body.firstChild);
var widthSize = width - container.clientWidth;
var heightSize = height - container.clientHeight;
document.body.removeChild(container);
return {
width: widthSize,
height: heightSize
};
}
return {

@@ -649,9 +657,3 @@ makeDetectable: makeDetectable,

function parseSize(size) {
return parseFloat(size.replace(/px/, ""));
}
},{"batch-updater":1}],7:[function(require,module,exports){
//Heavily inspired by http://www.backalleycoder.com/2013/03/18/cross-browser-event-based-element-resize-detection/
},{}],7:[function(require,module,exports){
"use strict";

@@ -665,3 +667,4 @@

var reporterMaker = require("./reporter");
var batchUpdaterMaker = require("batch-updater");
var browserDetector = require("./browser-detector");
var batchProcessorMaker = require("batch-processor");

@@ -718,4 +721,4 @@ //Detection strategies.

//batchUpdater is currently not an option to the listenTo function, so it should not be added to globalOptions.
var batchUpdater = getOption(options, "batchUpdater", batchUpdaterMaker({ reporter: reporter }));
//batchProcessor is currently not an option to the listenTo function, so it should not be added to globalOptions.
var batchProcessor = getOption(options, "batchProcessor", batchProcessorMaker({ reporter: reporter }));

@@ -733,7 +736,11 @@ //Options to be used as default for the listenTo function.

var strategyOptions = {
idHandler: idHandler,
reporter: reporter,
batchUpdater: batchUpdater
batchProcessor: batchProcessor
};
if(desiredStrategy === "scroll" && browserDetector.isLegacyOpera()) {
reporter.warn("Scroll strategy is not supported on legacy Opera. Changing to object strategy.");
desiredStrategy = "object";
}
if(desiredStrategy === "scroll") {

@@ -803,2 +810,4 @@ detectionStrategy = scrollStrategyMaker(strategyOptions);

forEach(elements, function attachListenerToElement(element) {
var id = idHandler.get(element);
if(!elementUtils.isDetectable(element)) {

@@ -809,3 +818,2 @@ if(elementUtils.isBusy(element)) {

addListener(callOnAdd, element, listener);
var id = idHandler.get(element);
onReadyCallbacks[id] = onReadyCallbacks[id] || [];

@@ -835,3 +843,2 @@ onReadyCallbacks[id].push(function onReady() {

var id = idHandler.get(element);
if(onReadyCallbacks[id]) {

@@ -871,3 +878,3 @@ forEach(onReadyCallbacks[id], function(callback) {

},{"./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-updater":1}],8:[function(require,module,exports){
},{"./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(require,module,exports){
"use strict";

@@ -874,0 +881,0 @@

/*!
* element-resize-detector 0.2.8 (2015-04-12, 18:14)
* element-resize-detector 0.3.0 (2015-04-13, 14:53)
* 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){m&&l&&0===o&&f(),p[a]||(p[a]=[]),p[a].push(b),o++}function d(a){void 0===a&&(a=l),n&&(h(n),n=null),l?f():e()}function e(){for(var a in p)if(p.hasOwnProperty(a))for(var b=p[a],c=0;c<b.length;c++){var d=b[c];d()}g(),q()}function f(){n=i(function(){e()})}function g(){o=0,p={}}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)}function j(a){q=a||function(){}}a=a||{};var k=a.reporter,l=c.getOption(a,"async",!0),m=c.getOption(a,"auto",!0);if(m&&!l&&(k.warn("Invalid options combination. auto=true and async=false is invalid. Setting async=true."),l=!0),!k)throw new Error("Reporter required.");var n,o=0,p={},q=function(){};return{update:b,force:d,onProcessed:j}}},{"./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}},{}],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("../collection-utils").forEach,d=a("../browser-detector");b.exports=function(a){function b(a,b){function c(){b(a)}if(!f(a))throw new Error("Element is not detectable by this strategy.");if(d.isIE(8))a.attachEvent("onresize",c);else{var e=f(a);e.contentDocument.defaultView.addEventListener("resize",c)}}function e(a,b){function c(a,b,c){function e(){function a(b,c){return b.contentDocument?void c(b.contentDocument):void setTimeout(function(){a(b,c)},100)}var d=this;a(d,function(a){var d=a.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; }",a.head.appendChild(d),c(b)})}function f(){if("static"===k){b.style.position="relative";var c=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)};c(h,b,j,"top"),c(h,b,j,"right"),c(h,b,j,"bottom"),c(h,b,j,"left")}var f=document.createElement("object");f.style.cssText=g,f.type="text/html",f.onload=e,f._erdObjectId=a,d.isIE()||(f.data="about:blank"),b.appendChild(f),d.isIE()&&(f.data="about:blank")}var g="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;",j=getComputedStyle(b),k=j.position;i?i.update(a,f):f()}var e=g.get(a);d.isIE(8)?b(a):c(e,a,b)}function f(a){return c(a.children,function(a){return void 0!==a._erdObjectId&&null!==a._erdObjectId?a:void 0})}a=a||{};var g=a.idHandler,h=a.reporter,i=a.batchUpdater;if(!g)throw new Error("Missing required dependency: idHandler.");if(!h)throw new Error("Missing required dependency: reporter.");return{makeDetectable:e,addListener:b}}},{"../browser-detector":3,"../collection-utils":4}],6:[function(a,b){"use strict";function c(a){return parseFloat(a.replace(/px/,""))}var d=a("batch-updater");b.exports=function(a){function b(a,b){var d=function(){var d=getComputedStyle(a),e=c(d.width),f=c(d.height),g=p.get(a);s.update(g,function(){k(a,e,f),l(a,e,f),t.update(g,function(){m(a,e,f),b(a)})})},e=f(a),g=h(a);n(e,"scroll",function(){var b=getComputedStyle(a),e=c(b.width),f=c(b.height);(e>a.lastWidth||f>a.lastHeight)&&d()}),n(g,"scroll",function(){var b=getComputedStyle(a),e=c(b.width),f=c(b.height);(e<a.lastWidth||f<a.lastHeight)&&d()})}function e(a,b){function d(){function c(a,b){return a=a?a+"px":"0",b=b?b+"px":"0","position: absolute; left: "+a+"; top: "+b+"; right: 0; bottom: 0; overflow: scroll; z-index: -1; visibility: hidden;"}function d(){j&&p&&r&&b(a)}if("static"===e.position){a.style.position="relative";var i=function(a,b,c,d){function f(a){return a.replace(/[^-\d\.]/g,"")}var g=e[d];"auto"!==g&&"0"!==f(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)};i(q,a,e,"top"),i(q,a,e,"right"),i(q,a,e,"bottom"),i(q,a,e,"left")}var j=!1,p=!1,r=!1,s=c(-1,-1),t=c(0,0),v="position: absolute; left: 0; top: 0;",w=document.createElement("div"),x=document.createElement("div"),y=document.createElement("div"),z=document.createElement("div"),A=document.createElement("div");w.style.cssText=s,x.style.cssText=t,y.style.cssText=v,z.style.cssText=t,A.style.cssText=v+" width: 200%; height: 200%;",x.appendChild(y),z.appendChild(A),w.appendChild(x),w.appendChild(z),a.appendChild(w),a._erdElement=w,n(x,"scroll",function B(){o(x,"scroll",B),j=!0,d()}),n(z,"scroll",function C(){o(z,"scroll",C),p=!0,d()}),k(a,f,g),u.update(h,function(){l(a,f,g),m(a,f,g),r=!0,d()})}var e=getComputedStyle(a),f=c(e.width),g=c(e.height),h=p.get(a);r?r.update(h,d):d()}function f(a){return a._erdElement.childNodes[0]}function g(a){return f(a).childNodes[0]}function h(a){return a._erdElement.childNodes[1]}function i(a){return a+10}function j(a){return 2*a}function k(a,b,c){var d=g(a),e=i(b),f=i(c);d.style.width=e+"px",d.style.height=f+"px"}function l(a,b,c){a.lastWidth=b,a.lastHeight=c}function m(a,b,c){var d=f(a),e=h(a),g=i(b),k=i(c),l=j(b),m=j(c);d.scrollLeft=g,d.scrollTop=k,e.scrollLeft=l,e.scrollTop=m}function n(a,b,c){a.attachEvent?a.attachEvent("on"+b,c):a.addEventListener(b,c)}function o(a,b,c){a.attachEvent?a.detachEvent("on"+b,c):a.removeEventListener(b,c)}a=a||{};var p=a.idHandler,q=a.reporter,r=a.batchUpdater,s=d({reporter:q}),t=d({reporter:q}),u=d({reporter:q});if(!p)throw new Error("Missing required dependency: idHandler.");if(!q)throw new Error("Missing required dependency: reporter.");return{makeDetectable:e,addListener:b}}},{"batch-updater":1}],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("batch-updater"),k=a("./detection-strategy/object.js"),l=a("./detection-strategy/scroll.js");b.exports=function(a){function b(a,b,e){function f(a){var b=u.get(a);d(b,function(b){b(a)})}function g(a,b,c){u.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",s.callOnAdd),j=c(a,"onReady",function(){});d(b,function(a){if(!v.isDetectable(a)){if(v.isBusy(a)){g(i,a,e);var c=m.get(a);return y[c]=y[c]||[],void y[c].push(function(){h++,h===b.length&&j()})}return v.markBusy(a,!0),t.makeDetectable(a,function(a){v.markAsDetectable(a),v.markBusy(a,!1),t.addListener(a,f),g(i,a,e),h++,h===b.length&&j();var c=m.get(a);y[c]&&(d(y[c],function(a){a()}),delete y[c])})}g(i,a,e),h++}),h===b.length&&j()}a=a||{};var m=a.idHandler;if(!m){var n=g(),o=h(n);m=o}var p=a.reporter;if(!p){var q=p===!1;p=i(q)}var r=c(a,"batchUpdater",j({reporter:p})),s={};s.callOnAdd=!!c(a,"callOnAdd",!0);var t,u=f(m),v=e(),w=c(a,"strategy","object"),x={idHandler:m,reporter:p,batchUpdater:r};if("scroll"===w)t=l(x);else{if("object"!==w)throw new Error("Invalid strategy name: "+w);t=k(x)}var y={};return{listenTo:b}}},{"./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-updater":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(){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)});

@@ -130,2 +130,3 @@ "use strict";

captureTimeout: 5*60*1000,
browserNoActivityTimeout: 60*1000,

@@ -132,0 +133,0 @@ sauceLabs: {

{
"name": "element-resize-detector",
"version": "0.3.0",
"version": "0.3.1",
"description": "resize event emitter for elements.",

@@ -32,3 +32,2 @@ "homepage": "https://github.com/wnr/element-resize-detector",

"karma-firefox-launcher": "^0.1.4",
"karma-ievms": "0.0.4",
"karma-jasmine": "^0.3.5",

@@ -35,0 +34,0 @@ "karma-safari-launcher": "^0.1.1",

@@ -36,1 +36,5 @@ "use strict";

};
detector.isLegacyOpera = function() {
return !!window.opera;
}

@@ -8,3 +8,2 @@ /**

var forEach = require("../collection-utils").forEach;
var browserDetector = require("../browser-detector");

@@ -14,10 +13,5 @@

options = options || {};
var idHandler = options.idHandler;
var reporter = options.reporter;
var batchProcessor = options.batchProcessor;
if(!idHandler) {
throw new Error("Missing required dependency: idHandler.");
}
if(!reporter) {

@@ -58,3 +52,3 @@ throw new Error("Missing required dependency: reporter.");

function makeDetectable(element, callback) {
function injectObject(id, element, callback) {
function injectObject(element, callback) {
var OBJECT_STYLE = "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;";

@@ -133,3 +127,2 @@

object.onload = onObjectLoad;
object._erdObjectId = id;

@@ -143,2 +136,3 @@ //Safari: This must occur before adding the object to the DOM.

element.appendChild(object);
element._erdObject = object;

@@ -158,5 +152,2 @@ //IE: This must occur after adding the object to the DOM.

//Obtain the id of the element (will be generated if not present), so that event listeners can be identified to this element.
var id = idHandler.get(element);
if(browserDetector.isIE(8)) {

@@ -168,3 +159,3 @@ //IE 8 does not support objects properly. Luckily they do support the resize event.

} else {
injectObject(id, element, callback);
injectObject(element, callback);
}

@@ -180,7 +171,3 @@ }

function getObject(element) {
return forEach(element.children, function isObject(child) {
if(child._erdObjectId !== undefined && child._erdObjectId !== null) {
return child;
}
});
return element._erdObject;
}

@@ -187,0 +174,0 @@

@@ -10,10 +10,5 @@ /**

options = options || {};
var idHandler = options.idHandler;
var reporter = options.reporter;
var batchProcessor = options.batchProcessor;
if(!idHandler) {
throw new Error("Missing required dependency: idHandler.");
}
if(!reporter) {

@@ -23,2 +18,5 @@ throw new Error("Missing required dependency: reporter.");

//TODO: Could this perhaps be done at installation time?
var scrollbarSizes = getScrollbarSizes();
/**

@@ -83,6 +81,2 @@ * Adds a resize event listener to the element.

//TODO: Remove this.
//Currently the API demands that an id should be generated for each element, which the strategy has to do.g
idHandler.get(element);
function ready() {

@@ -119,11 +113,15 @@ if(readyExpandScroll && readyShrinkScroll && readyOverall) {

function getContainerCssText(left, top) {
function getContainerCssText(left, top, bottom, right) {
left = (!left ? "0" : (left + "px"));
top = (!top ? "0" : (top + "px"));
bottom = (!bottom ? "0" : (bottom + "px"));
right = (!right ? "0" : (right + "px"));
return "position: absolute; left: " + left + "; top: " + top + "; right: 0; bottom: 0; overflow: scroll; z-index: -1; visibility: hidden;";
return "position: absolute; left: " + left + "; top: " + top + "; right: " + right + "; bottom: " + bottom + "; overflow: scroll; z-index: -1; visibility: hidden;";
}
var containerStyle = getContainerCssText(-1, -1);
var shrinkExpandstyle = getContainerCssText(0, 0);
var scrollbarWidth = scrollbarSizes.width;
var scrollbarHeight = scrollbarSizes.height;
var containerStyle = getContainerCssText(-1, -1, -scrollbarHeight, -scrollbarWidth);
var shrinkExpandstyle = getContainerCssText(0, 0, -scrollbarHeight, -scrollbarWidth);
var shrinkExpandChildStyle = "position: absolute; left: 0; top: 0;";

@@ -243,2 +241,31 @@

function parseSize(size) {
return parseFloat(size.replace(/px/, ""));
}
function getScrollbarSizes() {
var width = 500;
var height = 500;
var child = document.createElement("div");
child.style.cssText = "position: absolute; width: " + width*2 + "px; height: " + height*2 + "px; visibility: hidden;";
var container = document.createElement("div");
container.style.cssText = "position: absolute; width: " + width + "px; height: " + height + "px; overflow: scroll; visibility: none; top: " + -width*3 + "px; left: " + -height*3 + "px; visibility: hidden;";
container.appendChild(child);
document.body.insertBefore(container, document.body.firstChild);
var widthSize = width - container.clientWidth;
var heightSize = height - container.clientHeight;
document.body.removeChild(container);
return {
width: widthSize,
height: heightSize
};
}
return {

@@ -249,5 +276,1 @@ makeDetectable: makeDetectable,

};
function parseSize(size) {
return parseFloat(size.replace(/px/, ""));
}

@@ -1,3 +0,1 @@

//Heavily inspired by http://www.backalleycoder.com/2013/03/18/cross-browser-event-based-element-resize-detection/
"use strict";

@@ -11,3 +9,4 @@

var reporterMaker = require("./reporter");
var batchProcessorMaker = require("batch-processor");
var browserDetector = require("./browser-detector");
var batchProcessorMaker = require("batch-processor");

@@ -78,3 +77,2 @@ //Detection strategies.

var strategyOptions = {
idHandler: idHandler,
reporter: reporter,

@@ -84,2 +82,7 @@ batchProcessor: batchProcessor

if(desiredStrategy === "scroll" && browserDetector.isLegacyOpera()) {
reporter.warn("Scroll strategy is not supported on legacy Opera. Changing to object strategy.");
desiredStrategy = "object";
}
if(desiredStrategy === "scroll") {

@@ -149,2 +152,4 @@ detectionStrategy = scrollStrategyMaker(strategyOptions);

forEach(elements, function attachListenerToElement(element) {
var id = idHandler.get(element);
if(!elementUtils.isDetectable(element)) {

@@ -155,3 +160,2 @@ if(elementUtils.isBusy(element)) {

addListener(callOnAdd, element, listener);
var id = idHandler.get(element);
onReadyCallbacks[id] = onReadyCallbacks[id] || [];

@@ -181,3 +185,2 @@ onReadyCallbacks[id].push(function onReady() {

var id = idHandler.get(element);
if(onReadyCallbacks[id]) {

@@ -184,0 +187,0 @@ forEach(onReadyCallbacks[id], function(callback) {

@@ -438,3 +438,7 @@ /* global describe:false, it:false, beforeEach:false, expect:false, elementResizeDetectorMaker:false, _:false, $:false, jasmine:false */

listenToTest("object");
listenToTest("scroll");
//Scroll only supported on non-opera browsers.
if(!window.opera) {
listenToTest("scroll");
}
});

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc