Skip to content

Commit

Permalink
Don't call factory more than once in non node/amd environment; move e…
Browse files Browse the repository at this point in the history
…vent listeners into factory.
  • Loading branch information
Nickolay Ribal committed May 14, 2015
1 parent 17bcc69 commit 5d577b0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/iframeResizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,11 @@
}

function factory(){

setupRequestAnimationFrame();
addEventListener(window,'message',iFrameListener);
addEventListener(window,'resize', winResize);

function init(element, options){
if(!element.tagName) {
throw new TypeError('Object is not a valid DOM element');
Expand Down Expand Up @@ -590,18 +595,14 @@
};
}

setupRequestAnimationFrame();
addEventListener(window,'message',iFrameListener);
addEventListener(window,'resize', winResize);

if (window.jQuery) { createJQueryPublicMethod(jQuery); }

if (typeof define === 'function' && define.amd) {
define([],factory);
} else if (typeof module === 'object' && typeof module.exports === 'object') { //Node for browserfy
module.exports = factory();
} else {
window.iFrameResize = factory();
window.iFrameResize = window.iFrameResize || factory();
}

})();

0 comments on commit 5d577b0

Please sign in to comment.