zoom level continue

This commit is contained in:
Peter Cottle 2013-01-01 20:24:00 -08:00
parent f60b97307a
commit 7750bae1b4
2 changed files with 66 additions and 3 deletions

View file

@ -1,10 +1,31 @@
var _ = require('underscore');
var warnOnce = true;
function detectZoom() {
/**
* Note: this method has only been tested on Chrome
* but seems to work. A much more elaborate library is available here:
* https://github.com/yonran/detect-zoom
* but seems to return a "2" zoom level for my computer (who knows)
* so I can't use it. The ecosystem for zoom level detection is a mess
*/
if (!window.outerWidth || !window.innerWidth) {
if (warnOnce) {
console.warn("Can't detect zoom level correctly :-/");
warnOnce = false;
}
return 1;
}
return window.outerWidth / window.innerWidth;
}
var setupZoomPoll = function(callback, context) {
var currentZoom = 0;
setInterval(function() {
var newZoom = window.outerWidth / window.innerWidth;
var newZoom = detectZoom();
if (newZoom !== currentZoom) {
currentZoom = newZoom;
callback.apply(context, [newZoom]);