From ee737577f7c3efdcdffacab89982beacb927ab5f Mon Sep 17 00:00:00 2001 From: ahocevar Date: Sat, 24 Oct 2009 09:23:24 +0000 Subject: [PATCH] 2170_anonfuncs.diff: created functions returning true and false instead of using anonymous functions all over. p=rcoup, r=me (see #2170) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9759 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/BaseTypes.js | 32 ++++++++++++++++++++++++ lib/OpenLayers/Control.js | 2 +- lib/OpenLayers/Control/MouseDefaults.js | 2 +- lib/OpenLayers/Control/MouseToolbar.js | 2 +- lib/OpenLayers/Control/Navigation.js | 2 +- lib/OpenLayers/Handler/Drag.js | 6 ++--- lib/OpenLayers/Handler/Point.js | 2 +- lib/OpenLayers/Handler/RegularPolygon.js | 2 +- lib/OpenLayers/Layer/VirtualEarth.js | 2 +- lib/OpenLayers/Renderer/VML.js | 2 +- 10 files changed, 43 insertions(+), 11 deletions(-) diff --git a/lib/OpenLayers/BaseTypes.js b/lib/OpenLayers/BaseTypes.js index 615ef1de3e..5cbefc20ea 100644 --- a/lib/OpenLayers/BaseTypes.js +++ b/lib/OpenLayers/BaseTypes.js @@ -431,6 +431,38 @@ OpenLayers.Function = { return function(event) { return func.call(object, event || window.event); }; + }, + + /** + * APIFunction: False + * A simple function to that just does "return false". We use this to + * avoid attaching anonymous functions to DOM event handlers, which + * causes "issues" on IE<8. + * + * Usage: + * document.onclick = OpenLayers.Function.False; + * + * Returns: + * {Boolean} + */ + False : function() { + return false; + }, + + /** + * APIFunction: True + * A simple function to that just does "return true". We use this to + * avoid attaching anonymous functions to DOM event handlers, which + * causes "issues" on IE<8. + * + * Usage: + * document.onclick = OpenLayers.Function.True; + * + * Returns: + * {Boolean} + */ + True : function() { + return true; } }; diff --git a/lib/OpenLayers/Control.js b/lib/OpenLayers/Control.js index 57997667a2..9bae56580e 100644 --- a/lib/OpenLayers/Control.js +++ b/lib/OpenLayers/Control.js @@ -265,7 +265,7 @@ OpenLayers.Control = OpenLayers.Class({ if (!this.allowSelection) { this.div.className += " olControlNoSelect"; this.div.setAttribute("unselectable", "on", 0); - this.div.onselectstart = function() { return(false); }; + this.div.onselectstart = OpenLayers.Function.False; } if (this.title != "") { this.div.title = this.title; diff --git a/lib/OpenLayers/Control/MouseDefaults.js b/lib/OpenLayers/Control/MouseDefaults.js index d1296975eb..e25360cedd 100644 --- a/lib/OpenLayers/Control/MouseDefaults.js +++ b/lib/OpenLayers/Control/MouseDefaults.js @@ -166,7 +166,7 @@ OpenLayers.Control.MouseDefaults = OpenLayers.Class(OpenLayers.Control, { this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; this.map.viewPortDiv.appendChild(this.zoomBox); } - document.onselectstart=function() { return false; }; + document.onselectstart = OpenLayers.Function.False; OpenLayers.Event.stop(evt); }, diff --git a/lib/OpenLayers/Control/MouseToolbar.js b/lib/OpenLayers/Control/MouseToolbar.js index 957b6da235..c960608df7 100644 --- a/lib/OpenLayers/Control/MouseToolbar.js +++ b/lib/OpenLayers/Control/MouseToolbar.js @@ -254,7 +254,7 @@ OpenLayers.Control.MouseToolbar = OpenLayers.Class( this.map.div.style.cursor = "move"; break; } - document.onselectstart = function() { return false; }; + document.onselectstart = OpenLayers.Function.False; OpenLayers.Event.stop(evt); }, diff --git a/lib/OpenLayers/Control/Navigation.js b/lib/OpenLayers/Control/Navigation.js index f671ff85e9..b3c2209d0b 100644 --- a/lib/OpenLayers/Control/Navigation.js +++ b/lib/OpenLayers/Control/Navigation.js @@ -136,7 +136,7 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { draw: function() { // disable right mouse context menu for support of right click events if (this.handleRightClicks) { - this.map.viewPortDiv.oncontextmenu = function () { return false;}; + this.map.viewPortDiv.oncontextmenu = OpenLayers.Function.False; } var clickCallbacks = { diff --git a/lib/OpenLayers/Handler/Drag.js b/lib/OpenLayers/Handler/Drag.js index b52c5c6cb1..6f0cdb3d84 100644 --- a/lib/OpenLayers/Handler/Drag.js +++ b/lib/OpenLayers/Handler/Drag.js @@ -185,8 +185,8 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, { OpenLayers.Event.stop(evt); if(!this.oldOnselectstart) { - this.oldOnselectstart = (document.onselectstart) ? document.onselectstart : function() { return true; }; - document.onselectstart = function() {return false;}; + this.oldOnselectstart = (document.onselectstart) ? document.onselectstart : OpenLayers.Function.True; + document.onselectstart = OpenLayers.Function.False; } propagate = !this.stopDown; @@ -218,7 +218,7 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, { this.callback("move", [evt.xy]); if(!this.oldOnselectstart) { this.oldOnselectstart = document.onselectstart; - document.onselectstart = function() {return false;}; + document.onselectstart = OpenLayers.Function.False; } this.last = this.evt.xy; } diff --git a/lib/OpenLayers/Handler/Point.js b/lib/OpenLayers/Handler/Point.js index 3ad06faaa2..1efce7bd96 100644 --- a/lib/OpenLayers/Handler/Point.js +++ b/lib/OpenLayers/Handler/Point.js @@ -125,7 +125,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, { // without this, resolution properties must be specified at the // map-level for this temporary layer to init its resolutions // correctly - calculateInRange: function() { return true; } + calculateInRange: OpenLayers.Function.True }, this.layerOptions); this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options); this.map.addLayer(this.layer); diff --git a/lib/OpenLayers/Handler/RegularPolygon.js b/lib/OpenLayers/Handler/RegularPolygon.js index 88ae5f8dcb..cfe41707bf 100644 --- a/lib/OpenLayers/Handler/RegularPolygon.js +++ b/lib/OpenLayers/Handler/RegularPolygon.js @@ -165,7 +165,7 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, { // without this, resolution properties must be specified at the // map-level for this temporary layer to init its resolutions // correctly - calculateInRange: function() { return true; } + calculateInRange: OpenLayers.Function.True }; this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options); this.map.addLayer(this.layer); diff --git a/lib/OpenLayers/Layer/VirtualEarth.js b/lib/OpenLayers/Layer/VirtualEarth.js index e29bc366e2..93ff9d8390 100644 --- a/lib/OpenLayers/Layer/VirtualEarth.js +++ b/lib/OpenLayers/Layer/VirtualEarth.js @@ -121,7 +121,7 @@ OpenLayers.Layer.VirtualEarth = OpenLayers.Class( // http://blogs.msdn.com/virtualearth/archive/2007/09/28/locking-a-virtual-earth-map.aspx // this.mapObject.LoadMap(null, null, this.type, true); - this.mapObject.AttachEvent("onmousedown", function() {return true; }); + this.mapObject.AttachEvent("onmousedown", OpenLayers.Function.True); } catch (e) { } this.mapObject.HideDashboard(); diff --git a/lib/OpenLayers/Renderer/VML.js b/lib/OpenLayers/Renderer/VML.js index 287a29b7c3..d9a6593c07 100644 --- a/lib/OpenLayers/Renderer/VML.js +++ b/lib/OpenLayers/Renderer/VML.js @@ -554,7 +554,7 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, { // IE hack to make elements unselectable, to prevent 'blue flash' // while dragging vectors; #1410 node.unselectable = 'on'; - node.onselectstart = function() { return(false); }; + node.onselectstart = OpenLayers.Function.False; return node; },