Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

Commit

Permalink
viewport: ensure viewport is kept in sync with window size
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentbernat committed Nov 5, 2016
1 parent f9d2340 commit de74ad7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/scripts/receiver/viewport.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
module.exports = (function(window) {
'use strict';

window.addEventListener('resize', function() {
// On resize, find any element with a simulatedViewport attribute
// and update it. We ensure we start with the root one.
var de = window.document.documentElement;
var vps = de.querySelectorAll('[data-simulated-viewport]');
var root = new Viewport(de.dataset.simulatedViewport);

root.update();
for (var i = 0; i < vps.length; ++i) {
var vp = new Viewport(vps[i].dataset.simulatedViewport, vps[i]);
vp.update();
}
});

// Create a new viewport for the provide `el' element.
function Viewport(spec, el) {
this.el = el || window.document.documentElement;
Expand All @@ -9,6 +23,9 @@ module.exports = (function(window) {
var dimensions = spec.split('x');
this.width = dimensions[0] || null;
this.height = dimensions[1] || null;
this.el.dataset.simulatedViewport = spec;
} else {
delete this.el.dataset.simulatedViewport;
}
}

Expand Down

0 comments on commit de74ad7

Please sign in to comment.