OpenLayers OpenLayers

Ticket #712: namespace.patch

File namespace.patch, 46.8 kB (added by tschaub, 1 year ago)

Remove and deprecate the use of prototype extensions

  • tests/test_Util.html

    old new  
    1111                    "getImagesLocation()" ); 
    1212    } 
    1313 
    14     function test_02_Util_Strings(t) { 
    15         t.plan(5); 
    16          
    17         var str = "  chicken pox  "; 
    18  
    19         t.ok(str.contains("chicken"), "contains() function correctly finds an embedded string"); 
    20         t.ok(!str.contains("marsupial"), "contains() function correctly does not finds an random string"); 
    21          
    22  
    23         var trimmedStr = str.trim();         
    24  
    25         t.eq(trimmedStr, "chicken pox", "String.trim works correctly"); 
    26  
    27         t.eq(trimmedStr.startsWith("chicken"), true, "String.startsWith correctly finds chicken"); 
    28         t.eq(trimmedStr.startsWith("dolphin"), false, "String.startsWith correctly does not find turkey"); 
    29  
    30  
    31     } 
    32  
    3314    function test_03_Util_Array(t) { 
    3415        t.plan( 1 ); 
    3516 
     
    423404        t.plan(2); 
    424405         
    425406        var id = OpenLayers.Util.createUniqueID(); 
    426         t.ok( id.startsWith("id_"), "default OpenLayers.Util.createUniqueID starts id correctly"); 
     407        t.ok(OpenLayers.String.startsWith(id, "id_"), 
     408             "default OpenLayers.Util.createUniqueID starts id correctly"); 
    427409 
    428410        var id = OpenLayers.Util.createUniqueID("chicken"); 
    429         t.ok( id.startsWith("chicken"), "OpenLayers.Util.createUniqueID starts id correctly"); 
     411        t.ok(OpenLayers.String.startsWith(id, "chicken"), 
     412             "OpenLayers.Util.createUniqueID starts id correctly"); 
    430413    } 
    431      
    432     function test_12_Util_limitSigDigs(t) { 
    433         t.plan(7); 
    434  
    435         var x; 
    436  
    437         x = 123456; 
    438         t.eq(x.limitSigDigs(3), 123000, "correctly rounds down"); 
    439  
    440         x = 555555; 
    441         t.eq(x.limitSigDigs(3), 556000, "correctly rounds up"); 
    442  
    443         x = 66; 
    444         t.eq(x.limitSigDigs(3), 66, "correctly handles number smaller than sigdig"); 
    445  
    446         t.eq(x.limitSigDigs(null), 0, "correctly handles null sigdig"); 
    447         t.eq(x.limitSigDigs(0), 0, "correctly handles 0 sigdig"); 
    448         t.eq(x.limitSigDigs(-1), 0, "correctly handles negative sigdig"); 
    449  
    450         x = 0; 
    451         t.eq(x.limitSigDigs(2), 0, "correctly handles 0 number"); 
    452     } 
    453      
     414         
    454415    function test_13_Util_normalizeScale(t) { 
    455416        t.plan(2);  
    456417         
  • tests/test_Geometry.html

    old new  
    1010        var g = new OpenLayers.Geometry(); 
    1111         
    1212        t.eq(g.CLASS_NAME, "OpenLayers.Geometry", "correct CLASS_NAME") 
    13         t.ok(g.id.startsWith("OpenLayers.Geometry_"), "id correctly set"); 
     13        t.ok(OpenLayers.String.startsWith(g.id, "OpenLayers.Geometry_"), 
     14             "id correctly set"); 
    1415    } 
    1516 
    1617 
     
    2021        var clone = geometry.clone(); 
    2122 
    2223        t.eq(clone.CLASS_NAME, "OpenLayers.Geometry", "correct CLASS_NAME") 
    23         t.ok(clone.id.startsWith("OpenLayers.Geometry_"), "id correctly set"); 
     24        t.ok(OpenLayers.String.startsWith(clone.id, "OpenLayers.Geometry_"), 
     25             "id correctly set"); 
    2426    } 
    2527 
    2628    function test_02_Geometry_setBounds(t) { 
  • tests/test_BaseTypes.html

    old new  
    1111        var test1 = "chicken"; 
    1212        var test2 = "beet"; 
    1313 
    14         t.ok(str.startsWith("chicken"), " 'chickenHead' starts with 'chicken'"); 
    15         t.ok(!str.startsWith("Head"), " 'chickenHead' contains 'Head' but does *not* start with it"); 
    16         t.ok(!str.startsWith("beet"), "'chickenHead' doesnt start with 'beet'"); 
     14        t.ok(OpenLayers.String.startsWith(str, "chicken"), 
     15             "'chickenHead' starts with 'chicken'"); 
     16        t.ok(!OpenLayers.String.startsWith(str, "Head"), 
     17             "'chickenHead' does not start with 'Head'"); 
     18        t.ok(!OpenLayers.String.startsWith(str, "beet"), 
     19             "'chickenHead' doesnt start with 'beet'"); 
    1720    } 
    1821     
    1922    function test_02_String_contains(t) { 
     
    2124         
    2225        var str = "chickenHead"; 
    2326 
    24         t.ok(str.contains("chicken"), "(beginning) 'chickenHead' contains with 'chicken'"); 
    25         t.ok(str.contains("ick"), "(middle) 'chickenHead' contains with 'ick'"); 
    26         t.ok(str.contains("Head"), "(end) 'chickenHead' contains with 'Head'"); 
    27         t.ok(!str.startsWith("beet"), "'chickenHead' doesnt start with 'beet'"); 
     27        t.ok(OpenLayers.String.contains(str, "chicken"), 
     28             "(beginning) 'chickenHead' contains with 'chicken'"); 
     29        t.ok(OpenLayers.String.contains(str, "ick"), 
     30             "(middle) 'chickenHead' contains with 'ick'"); 
     31        t.ok(OpenLayers.String.contains(str, "Head"), 
     32             "(end) 'chickenHead' contains with 'Head'"); 
     33        t.ok(!OpenLayers.String.startsWith(str, "beet"), 
     34             "'chickenHead' doesnt start with 'beet'"); 
    2835    } 
    2936     
    3037    function test_03_String_trim(t) { 
    3138        t.plan(5); 
    3239         
    3340        var str = "chickenHead"; 
    34         t.eq(str.trim(), "chickenHead", "string with no extra whitespace is left alone"); 
     41        t.eq(OpenLayers.String.trim(str), 
     42             "chickenHead", "string with no extra whitespace is left alone"); 
    3543 
    3644        str = "  chickenHead"; 
    37         t.eq(str.trim(), "chickenHead", "string with extra whitespace at beginning is trimmed correctly"); 
     45        t.eq(OpenLayers.String.trim(str), 
     46             "chickenHead", "string with extra whitespace at beginning is trimmed correctly"); 
    3847 
    3948        str = "chickenHead    "; 
    40         t.eq(str.trim(), "chickenHead", "string with extra whitespace at end is trimmed correctly"); 
     49        t.eq(OpenLayers.String.trim(str), 
     50             "chickenHead", "string with extra whitespace at end is trimmed correctly"); 
    4151 
    4252        str = "  chickenHead    "; 
    43         t.eq(str.trim(), "chickenHead", "string with extra whitespace at beginning and end is trimmed correctly"); 
     53        t.eq(OpenLayers.String.trim(str), 
     54             "chickenHead", "string with extra whitespace at beginning and end is trimmed correctly"); 
    4455 
    4556        str = " "; 
    46         t.eq(str.trim(), "", "whitespace string is trimmed correctly"); 
     57        t.eq(OpenLayers.String.trim(str), "", "whitespace string is trimmed correctly"); 
    4758    } 
    4859         
    4960    function test_05_String_camelize(t) { 
    5061        t.plan(7); 
    5162         
    5263        var str = "chickenhead"; 
    53         t.eq(str.camelize(), "chickenhead", "string with no hyphens is left alone"); 
     64        t.eq(OpenLayers.String.camelize(str), "chickenhead", "string with no hyphens is left alone"); 
    5465 
    5566        str = "chicken-head"; 
    56         t.eq(str.camelize(), "chickenHead", "string with one middle hyphen is camelized correctly"); 
     67        t.eq(OpenLayers.String.camelize(str), "chickenHead", "string with one middle hyphen is camelized correctly"); 
    5768 
    5869        str = "chicken-head-man"; 
    59         t.eq(str.camelize(), "chickenHeadMan", "string with multiple middle hyphens is camelized correctly"); 
     70        t.eq(OpenLayers.String.camelize(str), "chickenHeadMan", "string with multiple middle hyphens is camelized correctly"); 
    6071 
    6172        str = "-chickenhead"; 
    62         t.eq(str.camelize(), "Chickenhead", "string with starting hyphen is camelized correctly (capitalized)"); 
     73        t.eq(OpenLayers.String.camelize(str), "Chickenhead", "string with starting hyphen is camelized correctly (capitalized)"); 
    6374 
    6475        str = "-chicken-head-man"; 
    65         t.eq(str.camelize(), "ChickenHeadMan", "string with starting hypen and multiple middle hyphens is camelized correctly"); 
     76        t.eq(OpenLayers.String.camelize(str), "ChickenHeadMan", "string with starting hypen and multiple middle hyphens is camelized correctly"); 
    6677 
    6778        str = "chicken-"; 
    68         t.eq(str.camelize(), "chicken", "string ending in hyphen is camelized correctly (hyphen dropped)"); 
     79        t.eq(OpenLayers.String.camelize(str), "chicken", "string ending in hyphen is camelized correctly (hyphen dropped)"); 
    6980 
    7081        str = "chicken-head-man-"; 
    71         t.eq(str.camelize(), "chickenHeadMan", "string with multiple middle hyphens and end hyphen is camelized correctly (end hyphen dropped)"); 
     82        t.eq(OpenLayers.String.camelize(str), "chickenHeadMan", "string with multiple middle hyphens and end hyphen is camelized correctly (end hyphen dropped)"); 
    7283 
    7384 
    7485   } 
    7586    
    7687    function test_06_Number_limitSigDigs(t) { 
    77         t.plan(10); 
     88        t.plan(9); 
    7889       
    7990        var num = 123456789;  
    80         t.eq(num.limitSigDigs(), 0, "passing 'null' as sig returns 0"); 
    81         t.eq(num.limitSigDigs(-1), 0, "passing -1 as sig returns 0"); 
    82         t.eq(num.limitSigDigs(0), 0, "passing 0 as sig returns 0"); 
     91        t.eq(OpenLayers.Number.limitSigDigs(num), 0, "passing 'null' as sig returns 0"); 
     92        t.eq(OpenLayers.Number.limitSigDigs(num, -1), 0, "passing -1 as sig returns 0"); 
     93        t.eq(OpenLayers.Number.limitSigDigs(num, 0), 0, "passing 0 as sig returns 0"); 
    8394         
    84         t.eq(num.limitSigDigs(15), 123456789, "passing sig greater than num digits in number returns number unmodified"); 
     95        t.eq(OpenLayers.Number.limitSigDigs(num, 15), 123456789, "passing sig greater than num digits in number returns number unmodified"); 
    8596         
    86         t.eq(num.limitSigDigs(1), 100000000, "passing sig 1 works"); 
    87         t.eq(num.limitSigDigs(3), 123000000, "passing middle sig works (rounds down)"); 
    88         t.eq(num.limitSigDigs(5), 123460000, "passing middle sig works (rounds up)"); 
    89         t.eq(num.limitSigDigs(9), 123456789, "passing sig equal to num digits in number works"); 
     97        t.eq(OpenLayers.Number.limitSigDigs(num, 1), 100000000, "passing sig 1 works"); 
     98        t.eq(OpenLayers.Number.limitSigDigs(num, 3), 123000000, "passing middle sig works (rounds down)"); 
     99        t.eq(OpenLayers.Number.limitSigDigs(num, 5), 123460000, "passing middle sig works (rounds up)"); 
     100        t.eq(OpenLayers.Number.limitSigDigs(num, 9), 123456789, "passing sig equal to num digits in number works"); 
    90101 
    91         var temp = OpenLayers.Console.error; 
    92         OpenLayers.Console.error = function() { 
    93             t.ok(true, "error reported when run on floating point number") 
    94         } 
    95102        num = 1234.56789; 
    96         t.ok(num.limitSigDigs(5) == null, "running limSigDig() on a floating point number returns null"); 
     103        t.eq(OpenLayers.Number.limitSigDigs(num, 5), 1234.6, "running limSigDig() on a floating point number works fine"); 
    97104         
    98         OpenLayers.Console.error = temp; 
    99105    } 
    100106 
    101107    function test_07_Function_bind(t) { 
     
    115121            t.eq(arguments.length, 4, "correct number of arguments ((regression test for #876))"); 
    116122        }; 
    117123 
    118         var newFoo = foo.bind(g_obj, g_Arg1, g_Arg2); 
     124        var newFoo = OpenLayers.Function.bind(foo, g_obj, g_Arg1, g_Arg2); 
    119125 
    120126        newFoo(g_Arg3, g_Arg4); 
    121127         
     
    135141            g_X = x; 
    136142        }; 
    137143 
    138         var newFoo = foo.bindAsEventListener(g_obj); 
     144        var newFoo = OpenLayers.Function.bindAsEventListener(foo, g_obj); 
    139145         
    140146 
    141147        g_X = null; 
  • tests/test_Popup.html

    old new  
    1313        popup = new OpenLayers.Popup(); 
    1414 
    1515        t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" ); 
    16         t.ok(popup.id.startsWith("OpenLayers.Popup"), "valid default popupid"); 
     16        t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers.Popup"), 
     17             "valid default popupid"); 
    1718        var firstID = popup.id; 
    1819        t.ok(popup.size.equals(size), "good default popup.size"); 
    1920        t.eq(popup.contentHTML, "", "good default popup.contentHTML"); 
  • tests/Geometry/test_Surface.html

    old new  
    99        var g = new OpenLayers.Geometry.Surface(); 
    1010         
    1111        t.eq(g.CLASS_NAME, "OpenLayers.Geometry.Surface", "correct CLASS_NAME") 
    12         t.ok(g.id.startsWith("OpenLayers.Geometry.Surface_"), "id correctly set"); 
     12        t.ok(OpenLayers.String.startsWith(g.id, "OpenLayers.Geometry.Surface_"), 
     13             "id correctly set"); 
    1314    } 
    1415 
    1516 
  • tests/test_Feature.html

    old new  
    2121 
    2222        t.ok( feature instanceof OpenLayers.Feature, "new OpenLayers.Feature returns Feature object" ); 
    2323        t.eq( feature.layer, layer, "feature.layer set correctly" ); 
    24         t.ok( feature.id.startsWith("OpenLayers.Feature_"), "feature.id set correctly" ); 
     24        t.ok(OpenLayers.String.startsWith(feature.id, "OpenLayers.Feature_"), 
     25             "feature.id set correctly"); 
    2526        t.ok( feature.lonlat.equals(lonlat), "feature.lonlat set correctly" ); 
    2627        t.eq( feature.data.iconURL, iconURL, "feature.data.iconURL set correctly" ); 
    2728        t.ok( feature.data.iconSize.equals(iconSize), "feature.data.iconSize set correctly" ); 
  • tests/test_Tile.html

    old new  
    2323        t.ok( tile.size.equals(size), "tile.size is set correctly" ); 
    2424 
    2525        t.ok( tile.id != null, "tile is given an id"); 
    26         t.ok( tile.id.startsWith("Tile_"), "tile's id starts correctly"); 
     26        t.ok(OpenLayers.String.startsWith(tile.id, "Tile_"), 
     27             "tile's id starts correctly"); 
    2728        t.ok( tile.events != null, "tile's events intitialized"); 
    2829    } 
    2930 
  • lib/OpenLayers/Events.js

    old new  
    404404 
    405405        // keep a bound copy of handleBrowserEvent() so that we can 
    406406        // pass the same function to both Event.observe() and .stopObserving() 
    407         this.eventHandler = this.handleBrowserEvent.bindAsEventListener(this); 
     407        this.eventHandler = OpenLayers.Function.bindAsEventListener( 
     408            this.handleBrowserEvent, this 
     409        ); 
    408410 
    409411        // if eventTypes is specified, create a listeners list for each  
    410412        // custom application event. 
  • lib/OpenLayers/Control/OverviewMap.js

    old new  
    218218                                        'absolute'); 
    219219            this.maximizeDiv.style.display = 'none'; 
    220220            this.maximizeDiv.className = this.displayClass + 'MaximizeButton'; 
    221             OpenLayers.Event.observe(this.maximizeDiv,  
    222                           'click',  
    223                           this.maximizeControl.bindAsEventListener(this)); 
     221            OpenLayers.Event.observe(this.maximizeDiv, 'click',  
     222                OpenLayers.Function.bindAsEventListener(this.maximizeControl, 
     223                                                        this) 
     224            ); 
    224225            this.div.appendChild(this.maximizeDiv); 
    225226     
    226227            // minimize button div 
     
    233234                                        'absolute'); 
    234235            this.minimizeDiv.style.display = 'none'; 
    235236            this.minimizeDiv.className = this.displayClass + 'MinimizeButton'; 
    236             OpenLayers.Event.observe(this.minimizeDiv,  
    237                           'click',  
    238                           this.minimizeControl.bindAsEventListener(this)); 
     237            OpenLayers.Event.observe(this.minimizeDiv, 'click',  
     238                OpenLayers.Function.bindAsEventListener(this.minimizeControl, 
     239                                                        this) 
     240            ); 
    239241            this.div.appendChild(this.minimizeDiv); 
    240242             
    241243            var eventsToStop = ['dblclick','mousedown']; 
  • lib/OpenLayers/Control/MouseDefaults.js

    old new  
    8484     */ 
    8585    registerWheelEvents: function() { 
    8686 
    87         this.wheelObserver = this.onWheelEvent.bindAsEventListener(this); 
     87        this.wheelObserver = OpenLayers.Function.bindAsEventListener( 
     88            this.onWheelEvent, this 
     89        ); 
    8890         
    8991        //register mousewheel events specifically on the window and document 
    9092        OpenLayers.Event.observe(window, "DOMMouseScroll", this.wheelObserver); 
  • lib/OpenLayers/Control/PanZoom.js

    old new  
    112112        this.div.appendChild(btn); 
    113113 
    114114        OpenLayers.Event.observe(btn, "mousedown",  
    115                                  this.buttonDown.bindAsEventListener(btn)); 
     115            OpenLayers.Function.bindAsEventListener(this.buttonDown, btn)); 
    116116        OpenLayers.Event.observe(btn, "dblclick",  
    117                                  this.doubleClick.bindAsEventListener(btn)); 
     117            OpenLayers.Function.bindAsEventListener(this.doubleClick, btn)); 
    118118        OpenLayers.Event.observe(btn, "click",  
    119                                  this.doubleClick.bindAsEventListener(btn)); 
     119            OpenLayers.Function.bindAsEventListener(this.doubleClick, btn)); 
    120120        btn.action = id; 
    121121        btn.map = this.map; 
    122122        btn.slideFactor = this.slideFactor; 
  • lib/OpenLayers/Control/LayerSwitcher.js

    old new  
    279279                    'layerSwitcher': this 
    280280                } 
    281281                OpenLayers.Event.observe(inputElem, "mouseup",  
    282                               this.onInputClick.bindAsEventListener(context)); 
     282                    OpenLayers.Function.bindAsEventListener(this.onInputClick, 
     283                                                            context) 
     284                ); 
    283285                 
    284286                // create span 
    285287                var labelSpan = document.createElement("span"); 
     
    290292                labelSpan.style.verticalAlign = (baseLayer) ? "bottom"  
    291293                                                            : "baseline"; 
    292294                OpenLayers.Event.observe(labelSpan, "click",  
    293                               this.onInputClick.bindAsEventListener(context)); 
     295                    OpenLayers.Function.bindAsEventListener(this.onInputClick, 
     296                                                            context) 
     297                ); 
    294298                // create line break 
    295299                var br = document.createElement("br"); 
    296300     
     
    463467        this.div.style.backgroundColor = "transparent"; 
    464468     
    465469        OpenLayers.Event.observe(this.div, "mouseup",  
    466                       this.mouseUp.bindAsEventListener(this)); 
     470            OpenLayers.Function.bindAsEventListener(this.mouseUp, this)); 
    467471        OpenLayers.Event.observe(this.div, "click", 
    468472                      this.ignoreEvent); 
    469473        OpenLayers.Event.observe(this.div, "mousedown", 
    470                       this.mouseDown.bindAsEventListener(this)); 
     474            OpenLayers.Function.bindAsEventListener(this.mouseDown, this)); 
    471475        OpenLayers.Event.observe(this.div, "dblclick", this.ignoreEvent); 
    472476 
    473477 
     
    496500        this.baseLayersDiv = document.createElement("div"); 
    497501        this.baseLayersDiv.style.paddingLeft = "10px"; 
    498502        /*OpenLayers.Event.observe(this.baseLayersDiv, "click",  
    499                       this.onLayerClick.bindAsEventListener(this)); 
     503            OpenLayers.Function.bindAsEventListener(this.onLayerClick, this)); 
    500504        */ 
    501505                      
    502506 
     
    545549        this.maximizeDiv.style.right = "0px"; 
    546550        this.maximizeDiv.style.left = ""; 
    547551        this.maximizeDiv.style.display = "none"; 
    548         OpenLayers.Event.observe(this.maximizeDiv,  
    549                       "click",  
    550                       this.maximizeControl.bindAsEventListener(this)); 
     552        OpenLayers.Event.observe(this.maximizeDiv, "click",  
     553            OpenLayers.Function.bindAsEventListener(this.maximizeControl, this) 
     554        ); 
    551555         
    552556        this.div.appendChild(this.maximizeDiv); 
    553557 
     
    564568        this.minimizeDiv.style.right = "0px"; 
    565569        this.minimizeDiv.style.left = ""; 
    566570        this.minimizeDiv.style.display = "none"; 
    567         OpenLayers.Event.observe(this.minimizeDiv,  
    568                       "click",  
    569                       this.minimizeControl.bindAsEventListener(this)); 
     571        OpenLayers.Event.observe(this.minimizeDiv, "click",  
     572            OpenLayers.Function.bindAsEventListener(this.minimizeControl, this) 
     573        ); 
    570574 
    571575        this.div.appendChild(this.minimizeDiv); 
    572576    }, 
  • lib/OpenLayers/Control/Panel.js

    old new  
    170170            var textNode = document.createTextNode(" "); 
    171171            controls[i].panel_div = element; 
    172172            OpenLayers.Event.observe(controls[i].panel_div, "click",  
    173                                      this.onClick.bind(this, controls[i])); 
     173                OpenLayers.Function.bind(this.onClick, this, controls[i])); 
    174174            OpenLayers.Event.observe(controls[i].panel_div, "mousedown",  
    175                               OpenLayers.Event.stop.bindAsEventListener()); 
     175                OpenLayers.Function.bindAsEventListener(OpenLayers.Event.stop)); 
    176176        }     
    177177 
    178178        if (this.map) { // map.addControl() has already been called on the panel 
  • lib/OpenLayers/Util.js

    old new  
    255255    if(delayDisplay) { 
    256256        image.style.display = "none"; 
    257257        OpenLayers.Event.observe(image, "load",  
    258                       OpenLayers.Util.onImageLoad.bind(image)); 
     258            OpenLayers.Function.bind(OpenLayers.Util.onImageLoad, image)); 
    259259        OpenLayers.Event.observe(image, "error",  
    260                       OpenLayers.Util.onImageLoadError.bind(image)); 
     260            OpenLayers.Function.bind(OpenLayers.Util.onImageLoadError, image)); 
    261261         
    262262    } 
    263263     
     
    453453    if (delayDisplay) { 
    454454        img.style.display = "none"; 
    455455        OpenLayers.Event.observe(img, "load", 
    456                       OpenLayers.Util.onImageLoad.bind(div)); 
     456            OpenLayers.Function.bind(OpenLayers.Util.onImageLoad, div)); 
    457457        OpenLayers.Event.observe(img, "error", 
    458                       OpenLayers.Util.onImageLoadError.bind(div)); 
     458            OpenLayers.Function.bind(OpenLayers.Util.onImageLoadError, div)); 
    459459    } 
    460460 
    461461    OpenLayers.Util.modifyAlphaImageDiv(div, id, px, sz, imgURL, position,  
     
    791791 
    792792    //parse out parameters portion of url string 
    793793    var paramsString = ""; 
    794     if (url.contains('?')) { 
     794    if (OpenLayers.String.contains(url, '?')) { 
    795795        var start = url.indexOf('?') + 1; 
    796         var end = url.contains("#") ? url.indexOf('#') : url.length; 
     796        var end = OpenLayers.String.contains(url, "#") ? 
     797                    url.indexOf('#') : url.length; 
    797798        paramsString = url.substring(start, end); 
    798799    } 
    799800         
  • lib/OpenLayers/Map.js

    old new  
    301301 
    302302        // Because Mozilla does not support the "resize" event for elements  
    303303        // other than "window", we need to put a hack here.  
    304         if (navigator.appName.contains("Microsoft")) { 
     304        if (OpenLayers.String.contains(navigator.appName, "Microsoft")) { 
    305305            // If IE, register the resize on the div 
    306306            this.events.register("resize", this, this.updateSize); 
    307307        } else { 
    308308            // Else updateSize on catching the window's resize 
    309309            //  Note that this is ok, as updateSize() does nothing if the  
    310310            //  map's size has not actually changed. 
    311             OpenLayers.Event.observe(window, 'resize',  
    312                           this.updateSize.bind(this)); 
     311            OpenLayers.Event.observe(window, 'resize', 
     312                            OpenLayers.Function.bind(this.updateSize, this)); 
    313313        } 
    314314         
    315315        // only append link stylesheet if the theme property is set 
     
    354354 
    355355        this.popups = []; 
    356356 
    357         this.unloadDestroy = this.destroy.bind(this); 
     357        this.unloadDestroy = OpenLayers.Function.bind(this.destroy, this); 
    358358         
    359359 
    360360        // always call map.destroy() 
  • lib/OpenLayers/Format/WKT.js

    old new  
    208208         * @private 
    209209         */ 
    210210        'point': function(str) { 
    211             var coords = str.trim().split(this.regExes.spaces); 
     211            var coords = OpenLayers.String.trim(str).split(this.regExes.spaces); 
    212212            return new OpenLayers.Feature.Vector( 
    213213                new OpenLayers.Geometry.Point(coords[0], coords[1]) 
    214214            ); 
     
    221221         * @private 
    222222         */ 
    223223        'multipoint': function(str) { 
    224             var points = str.trim().split(','); 
     224            var points = OpenLayers.String.trim(str).split(','); 
    225225            var components = []; 
    226226            for(var i=0; i<points.length; ++i) { 
    227227                components.push(this.parse.point.apply(this, [points[i]]).geometry); 
     
    238238         * @private 
    239239         */ 
    240240        'linestring': function(str) { 
    241             var points = str.trim().split(','); 
     241            var points = OpenLayers.String.trim(str).split(','); 
    242242            var components = []; 
    243243            for(var i=0; i<points.length; ++i) { 
    244244                components.push(this.parse.point.apply(this, [points[i]]).geometry); 
     
    256256         */ 
    257257        'multilinestring': function(str) { 
    258258            var line; 
    259             var lines = str.trim().split(this.regExes.parenComma); 
     259            var lines = OpenLayers.String.trim(str).split(this.regExes.parenComma); 
    260260            var components = []; 
    261261            for(var i=0; i<lines.length; ++i) { 
    262262                line = lines[i].replace(this.regExes.trimParens, '$1'); 
     
    275275         */ 
    276276        'polygon': function(str) { 
    277277            var ring, linestring, linearring; 
    278             var rings = str.trim().split(this.regExes.parenComma); 
     278            var rings = OpenLayers.String.trim(str).split(this.regExes.parenComma); 
    279279            var components = []; 
    280280            for(var i=0; i<rings.length; ++i) { 
    281281                ring = rings[i].replace(this.regExes.trimParens, '$1'); 
     
    296296         */ 
    297297        'multipolygon': function(str) { 
    298298            var polygon; 
    299             var polygons = str.trim().split(this.regExes.doubleParenComma); 
     299            var polygons = OpenLayers.String.trim(str).split(this.regExes.doubleParenComma); 
    300300            var components = []; 
    301301            for(var i=0; i<polygons.length; ++i) { 
    302302                polygon = polygons[i].replace(this.regExes.trimParens, '$1'); 
     
    316316        'geometrycollection': function(str) { 
    317317            // separate components of the collection with | 
    318318            str = str.replace(/,\s*([A-Za-z])/g, '|$1'); 
    319             var wktArray = str.trim().split('|'); 
     319            var wktArray = OpenLayers.String.trim(str).split('|'); 
    320320            var components = []; 
    321321            for(var i=0; i<wktArray.length; ++i) { 
    322322                components.push(OpenLayers.Format.WKT.prototype.read.apply(this,[wktArray[i]])); 
  • lib/OpenLayers/Format/XML.js

    old new  
    6060            text = text.substring(index); 
    6161        } 
    6262        var node = OpenLayers.Util.Try( 
    63             (function() { 
    64                 var xmldom; 
    65                 /** 
    66                  * Since we want to be able to call this method on the prototype 
    67                  * itself, this.xmldom may not exist even if in IE. 
    68                  */ 
    69                 if(window.ActiveXObject && !this.xmldom) { 
    70                     xmldom = new ActiveXObject("Microsoft.XMLDOM"); 
    71                 } else { 
    72                     xmldom = this.xmldom; 
    73                      
     63            OpenLayers.Function.bind(( 
     64                function() { 
     65                    var xmldom; 
     66                    /** 
     67                     * Since we want to be able to call this method on the prototype 
     68                     * itself, this.xmldom may not exist even if in IE. 
     69                     */ 
     70                    if(window.ActiveXObject && !this.xmldom) { 
     71                        xmldom = new ActiveXObject("Microsoft.XMLDOM"); 
     72                    } else { 
     73                        xmldom = this.xmldom; 
     74                         
     75                    } 
     76                    xmldom.loadXML(text); 
     77                    return xmldom; 
    7478                } 
    75                 xmldom.loadXML(text); 
    76                 return xmldom; 
    77             }).bind(this), 
     79            ), this), 
    7880            function() { 
    7981                return new DOMParser().parseFromString(text, 'text/xml'); 
    8082            }, 
  • lib/OpenLayers/Tile/Image.js

    old new  
    177177           http://openlayers.org/pipermail/dev/2007-January/000205.html 
    178178 
    179179        OpenLayers.Event.observe( this.imgDiv, "load", 
    180                         this.checkImgURL.bind(this) ); 
     180            OpenLayers.Function.bind(this.checkImgURL, this) ); 
    181181        */ 
    182182        this.frame.appendChild(this.imgDiv);  
    183183        this.layer.div.appendChild(this.frame);  
     
    206206                this.events.triggerEvent("loadend");  
    207207            } 
    208208        } 
    209         OpenLayers.Event.observe(this.imgDiv, 'load', onload.bind(this)); 
     209        OpenLayers.Event.observe(this.imgDiv, 'load', 
     210                                 OpenLayers.Function.bind(onload, this)); 
    210211 
    211212    }, 
    212213 
  • lib/OpenLayers/Ajax.js

    old new  
    5353OpenLayers.loadURL = function(uri, params, caller, 
    5454                                  onComplete, onFailure) { 
    5555 
    56     if (OpenLayers.ProxyHost && uri.startsWith("http")) { 
     56    if (OpenLayers.ProxyHost && OpenLayers.String.startsWith(uri, "http")) { 
    5757        uri = OpenLayers.ProxyHost + escape(uri); 
    5858    } 
    5959 
    60     var success = (onComplete) ? onComplete.bind(caller) 
     60    var success = (onComplete) ? OpenLayers.Function.bind(onComplete, caller) 
    6161                                : OpenLayers.nullHandler; 
    6262 
    63     var failure = (onFailure) ? onFailure.bind(caller) 
     63    var failure = (onFailure) ? OpenLayers.Function.bind(onFailure, caller) 
    6464                           : OpenLayers.nullHandler; 
    6565 
    6666    // from prototype.js 
     
    307307     
    308308            if (this.options.asynchronous) { 
    309309                this.transport.onreadystatechange =  
    310                     this.onStateChange.bind(this); 
     310                    OpenLayers.Function.bind(this.onStateChange, this); 
    311311                 
    312                 setTimeout((function() { 
    313                     this.respondToReadyState(1) 
    314                 }).bind(this), 10); 
     312                setTimeout(OpenLayers.Function.bind( 
     313                    (function() {this.respondToReadyState(1)}),this), 10 
     314                ); 
    315315            } 
    316316     
    317317            this.setRequestHeaders(); 
  • lib/OpenLayers/BaseTypes/Element.js

    old new  
    135135     */ 
    136136    getStyle: function(element, style) { 
    137137        element = OpenLayers.Util.getElement(element); 
    138         var value = element.style[style.camelize()]; 
     138        var value = element.style[OpenLayers.String.camelize(style)]; 
    139139        if (!value) { 
    140140            if (document.defaultView &&  
    141141                document.defaultView.getComputedStyle) { 
     
    143143                var css = document.defaultView.getComputedStyle(element, null); 
    144144                value = css ? css.getPropertyValue(style) : null; 
    145145            } else if (element.currentStyle) { 
    146                 value = element.currentStyle[style.camelize()]; 
     146                value = element.currentStyle[OpenLayers.String.camelize(style)]; 
    147147            } 
    148148        } 
    149149     
  • lib/OpenLayers/BaseTypes.js

    old new  
    44 
    55/** 
    66 * Header: OpenLayers Base Types 
    7  * Modifications to standard JavaScript types are described here. 
     7 * OpenLayers custom string, number and function functions are described here. 
    88 */ 
    99 
    1010/********************* 
     
    1313 *                   *  
    1414 *********************/ 
    1515 
     16OpenLayers.String = { 
     17    /** 
     18     * APIMethod: OpenLayers.String.startsWith 
     19     * Whether or not a string starts with another string.  
     20     *  
     21     * Parameters: 
     22     * str - {String} The string to test. 
     23     * sub - {Sring} The substring to look for. 
     24     *   
     25     * Returns: 
     26     * {Boolean} The first string starts with the second. 
     27     */ 
     28    startsWith: function(str, sub) { 
     29        return (str.indexOf(sub) == 0); 
     30    }, 
    1631 
     32    /** 
     33     * APIMethod: OpenLayers.String.contains 
     34     * Whether or not a string contains another string. 
     35     *  
     36     * Parameters: 
     37     * str - {String} The string to test. 
     38     * sub - {String} The substring to look for. 
     39     *  
     40     * Returns: 
     41     * {Boolean} The first string contains the second. 
     42     */ 
     43    contains: function(str, sub) { 
     44        return (str.indexOf(sub) != -1); 
     45    }, 
     46     
     47    /** 
     48     * APIMethod: OpenLayers.String.trim 
     49     * Removes leading and trailing whitespace characters from a string. 
     50     *  
     51     * Parameters: 
     52     * str - {String} The (potentially) space padded string.  This string is not 
     53     *     modified. 
     54     *  
     55     * Returns: 
     56     * {String} A trimmed version of the string - all leading and  
     57     *     trailing spaces removed. 
     58     */ 
     59    trim: function(str) { 
     60        return str.replace(/^\s*(.*?)\s*$/, "$1");     
     61    }, 
     62     
     63    /** 
     64     * APIMethod: OpenLayers.String.camelize 
     65     * Camel-case a hyphenated string.  
     66     *     Ex. "chicken-head" becomes "chickenHead", and 
     67     *     "-chicken-head" becomes "ChickenHead". 
     68     * 
     69     * Parameters: 
     70     * str - {String} The string to be camelized.  The original is not modified. 
     71     *  
     72     * Returns: 
     73     * {String} The string, camelized 
     74     */ 
     75    camelize: function(str) { 
     76        var oStringList = str.split('-'); 
     77        var camelizedString = oStringList[0]; 
     78        for (var i = 1; i < oStringList.length; i++) { 
     79            var s = oStringList[i]; 
     80            camelizedString += s.charAt(0).toUpperCase() + s.substring(1); 
     81        } 
     82        return camelizedString; 
     83    } 
     84}; 
     85 
    1786/** 
    1887 * APIMethod: String.startsWith 
    19  * Whether or not a string starts with another string.  
     88 * Deprecated. Whether or not a string starts with another string.  
    2089 *  
    2190 * Parameters: 
    2291 * sStart - {Sring} The string we're testing for. 
     
    2594 * {Boolean} Whether or not this string starts with the string passed in. 
    2695 */ 
    2796String.prototype.startsWith = function(sStart) { 
    28     return (this.substr(0,sStart.length) == sStart); 
     97    OpenLayers.Console.warn( 
     98        "This method has been deprecated and will be removed in 3.0. " + 
     99        "Please use OpenLayers.String.startsWith instead" 
     100    ); 
     101    return OpenLayers.String.startsWith(this, sStart); 
    29102}; 
    30103 
    31104/** 
    32105 * APIMethod: String.contains 
    33  * Whether or not a string contains another string. 
     106 * Deprecated. Whether or not a string contains another string. 
    34107 *  
    35108 * Parameters: 
    36109 * str - {String} The string that we're testing for. 
     
    39112 * {Boolean} Whether or not this string contains with the string passed in. 
    40113 */ 
    41114String.prototype.contains = function(str) { 
    42     return (this.indexOf(str) != -1); 
     115    OpenLayers.Console.warn( 
     116        "This method has been deprecated and will be removed in 3.0. " + 
     117        "Please use OpenLayers.String.contains instead" 
     118    ); 
     119    return OpenLayers.String.contains(this, str); 
    43120}; 
    44121 
    45122/** 
    46123 * APIMethod: String.trim 
    47  * Removes leading and trailing whitespace characters from a string. 
     124 * Deprecated. Removes leading and trailing whitespace characters from a string. 
    48125 *  
    49126 * Returns: 
    50127 * {String} A trimmed version of the string - all leading and  
    51128 *          trailing spaces removed 
    52129 */ 
    53130String.prototype.trim = function() { 
    54     return this.replace(/^\s+/, '').replace(/\s+$/, '');     
     131    OpenLayers.Console.warn( 
     132        "This method has been deprecated and will be removed in 3.0. " + 
     133        "Please use OpenLayers.String.trim instead" 
     134    ); 
     135    return OpenLayers.String.trim(this); 
    55136}; 
    56137 
    57138/** 
    58139 * APIMethod: camelize 
    59  * Camel-case a hyphenated string.  
     140 * Deprecated. Camel-case a hyphenated string.  
    60141 *     Ex. "chicken-head" becomes "chickenHead", and 
    61142 *     "-chicken-head" becomes "ChickenHead". 
    62143 *  
     
    64145 * {String} The string, camelized 
    65146 */ 
    66147String.prototype.camelize = function() { 
    67     var oStringList = this.split('-'); 
    68     var camelizedString = oStringList[0]; 
    69     for (var i = 1; i < oStringList.length; i++) { 
    70         var s = oStringList[i]; 
    71         camelizedString += s.charAt(0).toUpperCase() + s.substring(1); 
    72     } 
    73     return camelizedString; 
     148    OpenLayers.Console.warn( 
     149        "This method has been deprecated and will be removed in 3.0. " + 
     150        "Please use OpenLayers.String.camelize instead" 
     151    ); 
     152    return OpenLayers.String.camelize(this); 
    74153}; 
    75154 
    76155 
     
    80159 *                   *  
    81160 *********************/ 
    82161 
     162OpenLayers.Number = { 
     163    /** 
     164     * APIMethod: OpenLayers.Number.limitSigDigs 
     165     * Limit the number of significant digits on an integer. 
     166     *  
     167     * Parameters: 
     168     * num - {Integer} 
     169     * sig - {Integer} 
     170     *  
     171     * Returns: 
     172     * {Integer} The number, rounded to the specified number of significant 
     173     *     digits. 
     174     */ 
     175    limitSigDigs: function(num, sig) { 
     176        var fig; 
     177        if(sig > 0) { 
     178            fig = parseFloat(num.toPrecision(sig)); 
     179        } else { 
     180            fig = 0; 
     181        } 
     182        return fig; 
     183    } 
     184}; 
     185 
    83186/** 
    84187 * APIMethod: Number.limitSigDigs 
    85  * Limit the number of significant digits on an integer. Does *not* work  
    86  *     with floats! 
     188 * Deprecated. Limit the number of significant digits on an integer. Does *not* 
     189 *     work with floats! 
    87190 *  
    88191 * Parameters: 
    89192 * sig - {Integer} 
     
    93196 *           If null, 0, or negative value passed in, returns 0 
    94197 */ 
    95198Number.prototype.limitSigDigs = function(sig) { 
    96     var numStr = (sig > 0) ? this.toString() : "0"; 
    97     if (numStr.contains(".")) { 
    98         var msg = "limitSigDig can not be called on a floating point number"; 
    99         OpenLayers.Console.error(msg); 
    100         return null; 
    101     } 
    102     if ( (sig > 0) && (sig < numStr.length) ) { 
    103         var exp = numStr.length - sig; 
    104         numStr = Math.round( this / Math.pow(10, exp)) * Math.pow(10, exp); 
    105     } 
    106     return parseInt(numStr); 
     199    OpenLayers.Console.warn( 
     200        "This method has been deprecated and will be removed in 3.0. " + 
     201        "Please use OpenLayers.Number.limitSigDigs inst