diff --git a/src/ol/control/fullscreencontrol.js b/src/ol/control/fullscreencontrol.js index 2885544958..2955e37296 100644 --- a/src/ol/control/fullscreencontrol.js +++ b/src/ol/control/fullscreencontrol.js @@ -156,7 +156,7 @@ ol.control.FullScreen.prototype.setMap = function(map) { goog.base(this, 'setMap', map); if (map) { this.listenerKeys.push( - ol.events.listen(goog.global.document, goog.dom.fullscreen.EventType.CHANGE, + ol.events.listen(ol.global.document, goog.dom.fullscreen.EventType.CHANGE, this.handleFullScreenChange_, this) ); } diff --git a/src/ol/deviceorientation.js b/src/ol/deviceorientation.js index 8dd6a828c2..2d89edd793 100644 --- a/src/ol/deviceorientation.js +++ b/src/ol/deviceorientation.js @@ -207,7 +207,7 @@ ol.DeviceOrientation.prototype.handleTrackingChanged_ = function() { if (ol.has.DEVICE_ORIENTATION) { var tracking = this.getTracking(); if (tracking && !this.listenerKey_) { - this.listenerKey_ = ol.events.listen(goog.global, 'deviceorientation', + this.listenerKey_ = ol.events.listen(ol.global, 'deviceorientation', this.orientationChange_, this); } else if (!tracking && this.listenerKey_ !== null) { ol.events.unlistenByKey(this.listenerKey_); diff --git a/src/ol/dom/dom.js b/src/ol/dom/dom.js index 3310e9dc47..7119d9cc56 100644 --- a/src/ol/dom/dom.js +++ b/src/ol/dom/dom.js @@ -36,7 +36,7 @@ ol.dom.canUseCssTransform = (function() { if (canUseCssTransform === undefined) { goog.asserts.assert(document.body, 'document.body should not be null'); - goog.asserts.assert(goog.global.getComputedStyle, + goog.asserts.assert(ol.global.getComputedStyle, 'getComputedStyle is required (unsupported browser?)'); var el = document.createElement('P'), @@ -52,7 +52,7 @@ ol.dom.canUseCssTransform = (function() { for (var t in transforms) { if (t in el.style) { el.style[t] = 'translate(1px,1px)'; - has2d = goog.global.getComputedStyle(el).getPropertyValue( + has2d = ol.global.getComputedStyle(el).getPropertyValue( transforms[t]); } } @@ -77,7 +77,7 @@ ol.dom.canUseCssTransform3D = (function() { if (canUseCssTransform3D === undefined) { goog.asserts.assert(document.body, 'document.body should not be null'); - goog.asserts.assert(goog.global.getComputedStyle, + goog.asserts.assert(ol.global.getComputedStyle, 'getComputedStyle is required (unsupported browser?)'); var el = document.createElement('P'), @@ -93,7 +93,7 @@ ol.dom.canUseCssTransform3D = (function() { for (var t in transforms) { if (t in el.style) { el.style[t] = 'translate3d(1px,1px,1px)'; - has3d = goog.global.getComputedStyle(el).getPropertyValue( + has3d = ol.global.getComputedStyle(el).getPropertyValue( transforms[t]); } } @@ -192,7 +192,7 @@ ol.dom.transformElement2D = function(element, transform, opt_precision) { */ ol.dom.outerWidth = function(element) { var width = element.offsetWidth; - var style = element.currentStyle || goog.global.getComputedStyle(element); + var style = element.currentStyle || ol.global.getComputedStyle(element); width += parseInt(style.marginLeft, 10) + parseInt(style.marginRight, 10); return width; @@ -208,7 +208,7 @@ ol.dom.outerWidth = function(element) { */ ol.dom.outerHeight = function(element) { var height = element.offsetHeight; - var style = element.currentStyle || goog.global.getComputedStyle(element); + var style = element.currentStyle || ol.global.getComputedStyle(element); height += parseInt(style.marginTop, 10) + parseInt(style.marginBottom, 10); return height; diff --git a/src/ol/geolocation.js b/src/ol/geolocation.js index 7edcfdd148..14759081b4 100644 --- a/src/ol/geolocation.js +++ b/src/ol/geolocation.js @@ -135,12 +135,12 @@ ol.Geolocation.prototype.handleTrackingChanged_ = function() { if (ol.has.GEOLOCATION) { var tracking = this.getTracking(); if (tracking && this.watchId_ === undefined) { - this.watchId_ = goog.global.navigator.geolocation.watchPosition( + this.watchId_ = ol.global.navigator.geolocation.watchPosition( this.positionChange_.bind(this), this.positionError_.bind(this), this.getTrackingOptions()); } else if (!tracking && this.watchId_ !== undefined) { - goog.global.navigator.geolocation.clearWatch(this.watchId_); + ol.global.navigator.geolocation.clearWatch(this.watchId_); this.watchId_ = undefined; } } diff --git a/src/ol/has.js b/src/ol/has.js index b2b727ad42..34ce81b8d3 100644 --- a/src/ol/has.js +++ b/src/ol/has.js @@ -34,7 +34,7 @@ ol.has.MAC = ua.indexOf('macintosh') !== -1; * @type {number} * @api stable */ -ol.has.DEVICE_PIXEL_RATIO = goog.global.devicePixelRatio || 1; +ol.has.DEVICE_PIXEL_RATIO = ol.global.devicePixelRatio || 1; /** @@ -56,7 +56,7 @@ ol.has.CANVAS = ol.ENABLE_CANVAS && ( * @return {boolean} Canvas supported. */ function() { - if (!('HTMLCanvasElement' in goog.global)) { + if (!('HTMLCanvasElement' in ol.global)) { return false; } try { @@ -81,7 +81,7 @@ ol.has.CANVAS = ol.ENABLE_CANVAS && ( * @type {boolean} * @api stable */ -ol.has.DEVICE_ORIENTATION = 'DeviceOrientationEvent' in goog.global; +ol.has.DEVICE_ORIENTATION = 'DeviceOrientationEvent' in ol.global; /** @@ -98,7 +98,7 @@ ol.has.DOM = ol.ENABLE_DOM; * @type {boolean} * @api stable */ -ol.has.GEOLOCATION = 'geolocation' in goog.global.navigator; +ol.has.GEOLOCATION = 'geolocation' in ol.global.navigator; /** @@ -107,7 +107,7 @@ ol.has.GEOLOCATION = 'geolocation' in goog.global.navigator; * @type {boolean} * @api stable */ -ol.has.TOUCH = ol.ASSUME_TOUCH || 'ontouchstart' in goog.global; +ol.has.TOUCH = ol.ASSUME_TOUCH || 'ontouchstart' in ol.global; /** @@ -115,7 +115,7 @@ ol.has.TOUCH = ol.ASSUME_TOUCH || 'ontouchstart' in goog.global; * @const * @type {boolean} */ -ol.has.POINTER = 'PointerEvent' in goog.global; +ol.has.POINTER = 'PointerEvent' in ol.global; /** @@ -123,7 +123,7 @@ ol.has.POINTER = 'PointerEvent' in goog.global; * @const * @type {boolean} */ -ol.has.MSPOINTER = !!(goog.global.navigator.msPointerEnabled); +ol.has.MSPOINTER = !!(ol.global.navigator.msPointerEnabled); /** @@ -142,7 +142,7 @@ ol.has.WEBGL; var textureSize; var /** @type {Array.} */ extensions = []; - if ('WebGLRenderingContext' in goog.global) { + if ('WebGLRenderingContext' in ol.global) { try { var canvas = /** @type {HTMLCanvasElement} */ (document.createElement('CANVAS')); diff --git a/src/ol/interaction/mousewheelzoominteraction.js b/src/ol/interaction/mousewheelzoominteraction.js index bb3840345e..7690600fa5 100644 --- a/src/ol/interaction/mousewheelzoominteraction.js +++ b/src/ol/interaction/mousewheelzoominteraction.js @@ -91,10 +91,10 @@ ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) { if (mapBrowserEvent.type == ol.events.EventType.WHEEL) { delta = wheelEvent.deltaY; if (ol.has.FIREFOX && - wheelEvent.deltaMode === goog.global.WheelEvent.DOM_DELTA_PIXEL) { + wheelEvent.deltaMode === ol.global.WheelEvent.DOM_DELTA_PIXEL) { delta /= ol.has.DEVICE_PIXEL_RATIO; } - if (wheelEvent.deltaMode === goog.global.WheelEvent.DOM_DELTA_LINE) { + if (wheelEvent.deltaMode === ol.global.WheelEvent.DOM_DELTA_LINE) { delta *= 40; } } else if (mapBrowserEvent.type == ol.events.EventType.MOUSEWHEEL) { @@ -113,8 +113,8 @@ ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) { var duration = ol.MOUSEWHEELZOOM_TIMEOUT_DURATION; var timeLeft = Math.max(duration - (Date.now() - this.startTime_), 0); - goog.global.clearTimeout(this.timeoutId_); - this.timeoutId_ = goog.global.setTimeout( + ol.global.clearTimeout(this.timeoutId_); + this.timeoutId_ = ol.global.setTimeout( this.doZoom_.bind(this, map), timeLeft); mapBrowserEvent.preventDefault(); diff --git a/src/ol/map.js b/src/ol/map.js index c0bec0d241..887ad12021 100644 --- a/src/ol/map.js +++ b/src/ol/map.js @@ -578,12 +578,12 @@ ol.Map.prototype.disposeInternal = function() { ol.events.unlisten(this.viewport_, ol.events.EventType.MOUSEWHEEL, this.handleBrowserEvent, this); if (this.handleResize_ !== undefined) { - goog.global.removeEventListener(ol.events.EventType.RESIZE, + ol.global.removeEventListener(ol.events.EventType.RESIZE, this.handleResize_, false); this.handleResize_ = undefined; } if (this.animationDelayKey_) { - goog.global.cancelAnimationFrame(this.animationDelayKey_); + ol.global.cancelAnimationFrame(this.animationDelayKey_); this.animationDelayKey_ = undefined; } this.setTarget(null); @@ -1077,7 +1077,7 @@ ol.Map.prototype.handleTargetChanged_ = function() { if (!targetElement) { goog.dom.removeNode(this.viewport_); if (this.handleResize_ !== undefined) { - goog.global.removeEventListener(ol.events.EventType.RESIZE, + ol.global.removeEventListener(ol.events.EventType.RESIZE, this.handleResize_, false); this.handleResize_ = undefined; } @@ -1095,7 +1095,7 @@ ol.Map.prototype.handleTargetChanged_ = function() { if (!this.handleResize_) { this.handleResize_ = this.updateSize.bind(this); - goog.global.addEventListener(ol.events.EventType.RESIZE, + ol.global.addEventListener(ol.events.EventType.RESIZE, this.handleResize_, false); } } @@ -1199,7 +1199,7 @@ ol.Map.prototype.isRendered = function() { */ ol.Map.prototype.renderSync = function() { if (this.animationDelayKey_) { - goog.global.cancelAnimationFrame(this.animationDelayKey_); + ol.global.cancelAnimationFrame(this.animationDelayKey_); } this.animationDelay_(); }; @@ -1211,7 +1211,7 @@ ol.Map.prototype.renderSync = function() { */ ol.Map.prototype.render = function() { if (this.animationDelayKey_ === undefined) { - this.animationDelayKey_ = goog.global.requestAnimationFrame( + this.animationDelayKey_ = ol.global.requestAnimationFrame( this.animationDelay_); } }; diff --git a/src/ol/mapbrowserevent.js b/src/ol/mapbrowserevent.js index da4c3bf1c5..48292df702 100644 --- a/src/ol/mapbrowserevent.js +++ b/src/ol/mapbrowserevent.js @@ -223,14 +223,14 @@ ol.MapBrowserEventHandler.prototype.emulateClick_ = function(pointerEvent) { this.dispatchEvent(newEvent); if (this.clickTimeoutId_ !== 0) { // double-click - goog.global.clearTimeout(this.clickTimeoutId_); + ol.global.clearTimeout(this.clickTimeoutId_); this.clickTimeoutId_ = 0; newEvent = new ol.MapBrowserPointerEvent( ol.MapBrowserEvent.EventType.DBLCLICK, this.map_, pointerEvent); this.dispatchEvent(newEvent); } else { // click - this.clickTimeoutId_ = goog.global.setTimeout(function() { + this.clickTimeoutId_ = ol.global.setTimeout(function() { this.clickTimeoutId_ = 0; var newEvent = new ol.MapBrowserPointerEvent( ol.MapBrowserEvent.EventType.SINGLECLICK, this.map_, pointerEvent); diff --git a/src/ol/net.js b/src/ol/net.js index f43bc90b83..aad1d882aa 100644 --- a/src/ol/net.js +++ b/src/ol/net.js @@ -13,25 +13,25 @@ goog.provide('ol.net'); * callback. Default is 'callback'. */ ol.net.jsonp = function(url, callback, opt_errback, opt_callbackParam) { - var script = goog.global.document.createElement('script'); + var script = ol.global.document.createElement('script'); var key = 'olc_' + goog.getUid(callback); function cleanup() { - delete goog.global[key]; + delete ol.global[key]; script.parentNode.removeChild(script); } script.async = true; script.src = url + (url.indexOf('?') == -1 ? '?' : '&') + (opt_callbackParam || 'callback') + '=' + key; - var timer = goog.global.setTimeout(function() { + var timer = ol.global.setTimeout(function() { cleanup(); if (opt_errback) { opt_errback(); } }, 10000); - goog.global[key] = function(data) { - goog.global.clearTimeout(timer); + ol.global[key] = function(data) { + ol.global.clearTimeout(timer); cleanup(); callback(data); }; - goog.global.document.getElementsByTagName('head')[0].appendChild(script); + ol.global.document.getElementsByTagName('head')[0].appendChild(script); }; diff --git a/src/ol/ol.js b/src/ol/ol.js index a3b00d5047..e332d6473a 100644 --- a/src/ol/ol.js +++ b/src/ol/ol.js @@ -272,3 +272,6 @@ ol.inherits = * @return {undefined} Nothing. */ ol.nullFunction = function() {}; + + +ol.global = Function('return this')(); diff --git a/src/ol/pointer/touchsource.js b/src/ol/pointer/touchsource.js index d73786eca1..5a37435103 100644 --- a/src/ol/pointer/touchsource.js +++ b/src/ol/pointer/touchsource.js @@ -148,7 +148,7 @@ ol.pointer.TouchSource.prototype.removePrimaryPointer_ = function(inPointer) { * @private */ ol.pointer.TouchSource.prototype.resetClickCount_ = function() { - this.resetId_ = goog.global.setTimeout( + this.resetId_ = ol.global.setTimeout( this.resetClickCountHandler_.bind(this), ol.pointer.TouchSource.CLICK_COUNT_TIMEOUT); }; @@ -168,7 +168,7 @@ ol.pointer.TouchSource.prototype.resetClickCountHandler_ = function() { */ ol.pointer.TouchSource.prototype.cancelResetClickCount_ = function() { if (this.resetId_ !== undefined) { - goog.global.clearTimeout(this.resetId_); + ol.global.clearTimeout(this.resetId_); } }; @@ -440,7 +440,7 @@ ol.pointer.TouchSource.prototype.dedupSynthMouse_ = function(inEvent) { var lt = [t.clientX, t.clientY]; lts.push(lt); - goog.global.setTimeout(function() { + ol.global.setTimeout(function() { // remove touch after timeout ol.array.remove(lts, lt); }, ol.pointer.TouchSource.DEDUP_TIMEOUT); diff --git a/src/ol/proj/proj.js b/src/ol/proj/proj.js index 6b1bbc996d..61a000c5a4 100644 --- a/src/ol/proj/proj.js +++ b/src/ol/proj/proj.js @@ -153,7 +153,7 @@ ol.proj.Projection = function(options) { goog.asserts.assert(code !== undefined, 'Option "code" is required for constructing instance'); if (ol.ENABLE_PROJ4JS) { - var proj4js = ol.proj.proj4_ || goog.global['proj4']; + var proj4js = ol.proj.proj4_ || ol.global['proj4']; if (typeof proj4js == 'function' && projections[code] === undefined) { var def = proj4js.defs(code); if (def !== undefined) { @@ -684,7 +684,7 @@ ol.proj.get = function(projectionLike) { var code = projectionLike; projection = ol.proj.projections_[code]; if (ol.ENABLE_PROJ4JS) { - var proj4js = ol.proj.proj4_ || goog.global['proj4']; + var proj4js = ol.proj.proj4_ || ol.global['proj4']; if (projection === undefined && typeof proj4js == 'function' && proj4js.defs(code) !== undefined) { projection = new ol.proj.Projection({code: code}); diff --git a/src/ol/reproj/tile.js b/src/ol/reproj/tile.js index 722c78e31f..e20bf67dae 100644 --- a/src/ol/reproj/tile.js +++ b/src/ol/reproj/tile.js @@ -331,7 +331,7 @@ ol.reproj.Tile.prototype.load = function() { }); if (leftToLoad === 0) { - goog.global.setTimeout(this.reproject_.bind(this), 0); + ol.global.setTimeout(this.reproject_.bind(this), 0); } } }; diff --git a/test/spec/ol/interaction/draganddropinteraction.test.js b/test/spec/ol/interaction/draganddropinteraction.test.js index 16b353e941..e10066c7cb 100644 --- a/test/spec/ol/interaction/draganddropinteraction.test.js +++ b/test/spec/ol/interaction/draganddropinteraction.test.js @@ -62,7 +62,7 @@ describe('ol.interaction.DragAndDrop', function() { }); describe('#handleDrop_', function() { - var origFileReader = goog.global.FileReader; + var origFileReader = ol.global.FileReader; beforeEach(function() { FileReader = function() { @@ -76,7 +76,7 @@ describe('ol.interaction.DragAndDrop', function() { }); afterEach(function() { - goog.global.FileReader = origFileReader; + ol.global.FileReader = origFileReader; }); it('reads dropped files', function(done) { diff --git a/test/spec/ol/net.test.js b/test/spec/ol/net.test.js index 1c5879b77f..3ae9565793 100644 --- a/test/spec/ol/net.test.js +++ b/test/spec/ol/net.test.js @@ -4,10 +4,10 @@ goog.provide('ol.test.net'); describe('ol.net', function() { describe('jsonp()', function() { - var head = goog.global.document.getElementsByTagName('head')[0]; + var head = ol.global.document.getElementsByTagName('head')[0]; var origAppendChild = head.appendChild; var origCreateElement = document.createElement; - var origSetTimeout = goog.global.setTimeout; + var origSetTimeout = ol.global.setTimeout; var key, removeChild; function createCallback(url, done) { @@ -27,7 +27,7 @@ describe('ol.net', function() { if (arg == 'script') { return element; } else { - return origCreateElement.apply(goog.global.document, arguments); + return origCreateElement.apply(ol.global.document, arguments); } }; head.appendChild = function(el) { @@ -36,13 +36,13 @@ describe('ol.net', function() { removeChild: removeChild }; origSetTimeout(function() { - goog.global[key](element.src); + ol.global[key](element.src); }, 0); } else { origAppendChild.apply(head, arguments); } }; - goog.global.setTimeout = function(fn, time) { + ol.global.setTimeout = function(fn, time) { origSetTimeout(fn, 100); }; }); @@ -50,7 +50,7 @@ describe('ol.net', function() { afterEach(function() { document.createElement = origCreateElement; head.appendChild = origAppendChild; - goog.global.setTimeout = origSetTimeout; + ol.global.setTimeout = origSetTimeout; }); it('appends callback param to url, cleans up after call', function(done) { @@ -70,7 +70,7 @@ describe('ol.net', function() { expect.fail(); } function errback() { - expect(goog.global[key]).to.be(undefined); + expect(ol.global[key]).to.be(undefined); expect(removeChild.called).to.be(true); done(); }