MCPcopy Create free account
hub / github.com/SpringRoll/SpringRoll / constructor

Method constructor

src/scale-manager/ResizeHelper.js:37–69  ·  view source on GitHub ↗

*Creates an instance of ResizeHelper. * @param {function} resizeCallback * @memberof ResizeHelper

(resizeCallback)

Source from the content-addressed store, hash-verified

35 * @memberof ResizeHelper
36 */
37 constructor(resizeCallback) {
38 this._enabled = true;
39 this.resizeCallback = resizeCallback;
40
41 // Setup a listener for the 'resize' event from the window's event system.
42 window.addEventListener('resize', this.onWindowResize.bind(this));
43
44 // Defaulted to needing a resize loop on iOS devices due to a potential bug where
45 // the window resize event isn't dispatched at the correct time.
46 let requiresResizeLoop = this.iOS;
47
48 // Setup environment specific resize event variables
49 if (typeof Event === 'function') {
50 this.resize();
51 }
52 else {
53 this.resizeEvent = window.document.createEvent('UIEvents');
54 this.resizeEvent.initUIEvent('resize', true, false, window, 0);
55 requiresResizeLoop = true;
56 }
57
58 if (requiresResizeLoop) {
59 // The resize loop will observe the aspect ratio of the window and will dispatch events anytime it changes.
60 this.aspectRatio = new Property(0);
61 this.aspectRatio.subscribe(this.resize.bind(this));
62
63 // Call the first resize tick.
64 this.resizeTick();
65
66 // Check for aspect ratio change every 50 milliseconds.
67 setInterval(this.resizeTick.bind(this), 50);
68 }
69 }
70
71 /**
72 * For older browsers, specifically for IE11, starts a loop making sure resize events are fired.

Callers

nothing calls this directly

Calls 3

resizeMethod · 0.95
resizeTickMethod · 0.95
subscribeMethod · 0.45

Tested by

no test coverage detected