element-resize-event
Advanced tools
Comparing version 2.0.7 to 2.0.8
@@ -97,2 +97,19 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
module.exports.unbind = function(element, fn){ | ||
var attachEvent = document.attachEvent | ||
if (fn) { | ||
element.__resizeListeners__.splice(element.__resizeListeners__.indexOf(fn), 1) | ||
} else { | ||
element.__resizeListeners__ = [] | ||
} | ||
if (!element.__resizeListeners__.length) { | ||
if (attachEvent) { | ||
element.detachEvent('onresize', resizeListener) | ||
} else { | ||
element.__resizeTrigger__.contentDocument.defaultView.removeEventListener('resize', resizeListener) | ||
element.__resizeTrigger__ = !element.removeChild(element.__resizeTrigger__) | ||
} | ||
} | ||
} | ||
},{}]},{},[1]); |
113
index.js
@@ -0,1 +1,36 @@ | ||
var requestFrame = (function () { | ||
var raf = window.requestAnimationFrame || | ||
window.mozRequestAnimationFrame || | ||
window.webkitRequestAnimationFrame || | ||
function fallbackRAF(func) { | ||
return window.setTimeout(func, 20) | ||
} | ||
return function requestFrameFunction(func) { | ||
return raf(func) | ||
} | ||
})() | ||
var cancelFrame = (function () { | ||
var cancel = window.cancelAnimationFrame || | ||
window.mozCancelAnimationFrame || | ||
window.webkitCancelAnimationFrame || | ||
window.clearTimeout | ||
return function cancelFrameFunction(id) { | ||
return cancel(id) | ||
} | ||
})() | ||
function resizeListener(e) { | ||
var win = e.target || e.srcElement | ||
if (win.__resizeRAF__) { | ||
cancelFrame(win.__resizeRAF__) | ||
} | ||
win.__resizeRAF__ = requestFrame(function () { | ||
var trigger = win.__resizeTrigger__ | ||
trigger.__resizeListeners__.forEach(function (fn) { | ||
fn.call(trigger, e) | ||
}) | ||
}) | ||
} | ||
var exports = function exports(element, fn) { | ||
@@ -5,46 +40,9 @@ var window = this | ||
var isIE | ||
var requestFrame | ||
var attachEvent = document.attachEvent | ||
if (typeof navigator !== 'undefined') { | ||
isIE = navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/Edge/) | ||
isIE = navigator.userAgent.match(/Trident/) || | ||
navigator.userAgent.match(/Edge/) | ||
} | ||
requestFrame = (function () { | ||
var raf = window.requestAnimationFrame || | ||
window.mozRequestAnimationFrame || | ||
window.webkitRequestAnimationFrame || | ||
function fallbackRAF(func) { | ||
return window.setTimeout(func, 20) | ||
} | ||
return function requestFrameFunction(func) { | ||
return raf(func) | ||
} | ||
})() | ||
var cancelFrame = (function () { | ||
var cancel = window.cancelAnimationFrame || | ||
window.mozCancelAnimationFrame || | ||
window.webkitCancelAnimationFrame || | ||
window.clearTimeout | ||
return function cancelFrameFunction(id) { | ||
return cancel(id) | ||
} | ||
})() | ||
function resizeListener(e) { | ||
var win = e.target || e.srcElement | ||
if (win.__resizeRAF__) { | ||
cancelFrame(win.__resizeRAF__) | ||
} | ||
win.__resizeRAF__ = requestFrame(function () { | ||
var trigger = win.__resizeTrigger__ | ||
if(trigger !== undefined) { | ||
trigger.__resizeListeners__.forEach(function (fn) { | ||
fn.call(trigger, e) | ||
}) | ||
} | ||
}) | ||
} | ||
function objectLoad() { | ||
@@ -64,4 +62,7 @@ this.contentDocument.defaultView.__resizeTrigger__ = this.__resizeElement__ | ||
} | ||
var obj = element.__resizeTrigger__ = document.createElement('object') | ||
obj.setAttribute('style', 'display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1; opacity: 0;') | ||
var obj = (element.__resizeTrigger__ = document.createElement('object')) | ||
obj.setAttribute( | ||
'style', | ||
'display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1; opacity: 0;' | ||
) | ||
obj.setAttribute('class', 'resize-sensor') | ||
@@ -83,15 +84,29 @@ obj.__resizeElement__ = element | ||
exports.unbind = function(element, fn){ | ||
var attachEvent = document.attachEvent; | ||
element.__resizeListeners__.splice(element.__resizeListeners__.indexOf(fn), 1); | ||
module.exports = typeof window === 'undefined' ? exports : exports.bind(window) | ||
module.exports.unbind = function (element, fn) { | ||
var attachEvent = document.attachEvent | ||
if (fn) { | ||
element.__resizeListeners__.splice( | ||
element.__resizeListeners__.indexOf(fn), | ||
1 | ||
) | ||
} else { | ||
element.__resizeListeners__ = [] | ||
} | ||
if (!element.__resizeListeners__.length) { | ||
if (attachEvent) { | ||
element.detachEvent('onresize', resizeListener); | ||
element.detachEvent('onresize', resizeListener) | ||
} else { | ||
element.__resizeTrigger__.contentDocument.defaultView.removeEventListener('resize', resizeListener); | ||
element.__resizeTrigger__ = !element.removeChild(element.__resizeTrigger__); | ||
element.__resizeTrigger__.contentDocument.defaultView.removeEventListener( | ||
'resize', | ||
resizeListener | ||
) | ||
delete element.__resizeTrigger__.contentDocument.defaultView.__resizeTrigger__ | ||
element.__resizeTrigger__ = !element.removeChild( | ||
element.__resizeTrigger__ | ||
) | ||
} | ||
delete element.__resizeListeners__ | ||
} | ||
} | ||
module.exports = (typeof window === 'undefined') ? exports : exports.bind(window) |
{ | ||
"name": "element-resize-event", | ||
"description": "Polyfill to make it easy to listen for element resize events", | ||
"version": "2.0.7", | ||
"version": "2.0.8", | ||
"author": "Kyle Mathews <mathews.kyle@gmail.com>", | ||
@@ -6,0 +6,0 @@ "bugs": { |
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
86256
217