From 7750bae1b440846c49b7d5af8719bebfc31ef1d0 Mon Sep 17 00:00:00 2001 From: Peter Cottle Date: Tue, 1 Jan 2013 20:24:00 -0800 Subject: [PATCH] zoom level continue --- build/bundle.js | 46 ++++++++++++++++++++++++++++++++++++++-- src/js/util/zoomLevel.js | 23 +++++++++++++++++++- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/build/bundle.js b/build/bundle.js index d31c8981..3f1c2803 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -11523,11 +11523,32 @@ exports.EventBaton = EventBaton; require.define("/src/js/util/zoomLevel.js",function(require,module,exports,__dirname,__filename,process,global){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]); @@ -17348,11 +17369,32 @@ require("/src/js/util/mock.js"); require.define("/src/js/util/zoomLevel.js",function(require,module,exports,__dirname,__filename,process,global){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]); diff --git a/src/js/util/zoomLevel.js b/src/js/util/zoomLevel.js index 77335237..bb00fa5d 100644 --- a/src/js/util/zoomLevel.js +++ b/src/js/util/zoomLevel.js @@ -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]);