- Use array literals instead of new Array(); (note that `new Array;` without () is...
authorDaniel Friesen <dantman@users.mediawiki.org>
Mon, 24 Aug 2009 17:15:32 +0000 (17:15 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Mon, 24 Aug 2009 17:15:32 +0000 (17:15 +0000)
- Use RegExp literals instead of new RegExp(...); when unnecessary.
- Fix bad use of object iteration on an array bug20376

skins/common/mwsuggest.js
skins/common/protect.js
skins/common/wikibits.js

index 77792b0..8e37a48 100644 (file)
@@ -24,8 +24,8 @@ var os_mouse_moved = false;
 // delay between keypress and suggestion (in ms)
 var os_search_timeout = 250;
 // these pairs of inputs/forms will be autoloaded at startup
-var os_autoload_inputs = new Array('searchInput', 'searchInput2', 'powerSearchText', 'searchText');
-var os_autoload_forms = new Array('searchform', 'searchform2', 'powersearch', 'search' );
+var os_autoload_inputs = ['searchInput', 'searchInput2', 'powerSearchText', 'searchText'];
+var os_autoload_forms = ['searchform', 'searchform2', 'powersearch', 'search'];
 // if we stopped the service
 var os_is_stopped = false;
 // max lines to show in suggest table
@@ -364,7 +364,7 @@ function os_createResultTable(r, results){
        var c = document.getElementById(r.container);
        var width = c.offsetWidth - os_operaWidthFix(c.offsetWidth);
        var html = "<table class=\"os-suggest-results\" id=\""+r.resultTable+"\" style=\"width: "+width+"px;\">";
-       r.results = new Array();
+       r.results = [];
        r.resultCount = results.length;
        for(i=0;i<results.length;i++){
                var title = os_decodeValue(results[i]);
index d9650c8..874f92e 100644 (file)
@@ -250,7 +250,7 @@ var ProtectionForm = {
         */
        'getLevelSelectors': function() {
                var all = document.getElementsByTagName("select");
-               var ours = new Array();
+               var ours = [];
                for (var i = 0; i < all.length; i++) {
                        var element = all[i];
                        if (element.id.match(/^mwProtect-level-/)) {
@@ -279,7 +279,7 @@ var ProtectionForm = {
         */
        'getExpiryInputs': function() {
                var all = document.getElementsByTagName("input");
-               var ours = new Array();
+               var ours = [];
                for (var i = 0; i < all.length; i++) {
                        var element = all[i];
                        if (element.name.match(/^mwProtect-expiry-/)) {
@@ -307,7 +307,7 @@ var ProtectionForm = {
         */
        'getExpirySelectors': function() {
                var all = document.getElementsByTagName("select");
-               var ours = new Array();
+               var ours = [];
                for (var i = 0; i < all.length; i++) {
                        var element = all[i];
                        if (element.id.match(/^mwProtectExpirySelection-/)) {
index ed58877..fa7387a 100644 (file)
@@ -181,23 +181,14 @@ var mwEditButtons = [];
 var mwCustomEditButtons = []; // eg to add in MediaWiki:Common.js
 
 function escapeQuotes(text) {
-       var re = new RegExp("'","g");
-       text = text.replace(re,"\\'");
-       re = new RegExp("\\n","g");
-       text = text.replace(re,"\\n");
-       return escapeQuotesHTML(text);
+       return escapeQuotesHTML(text.replace(/'/g,"\\'").replace(/\n/g,"\\n"));
 }
 
 function escapeQuotesHTML(text) {
-       var re = new RegExp('&',"g");
-       text = text.replace(re,"&amp;");
-       re = new RegExp('"',"g");
-       text = text.replace(re,"&quot;");
-       re = new RegExp('<',"g");
-       text = text.replace(re,"&lt;");
-       re = new RegExp('>',"g");
-       text = text.replace(re,"&gt;");
-       return text;
+       return text.replace(/&/g,"&amp;")
+               .replace(/"/g,"&quot;")
+               .replace(/</gre,"&lt;")
+               .replace(/>/g,"&gt;");
 }
 
 
@@ -308,7 +299,7 @@ function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) {
                link.setAttribute( "title", tooltip );
        }
        if ( accesskey && tooltip ) {
-               updateTooltipAccessKeys( new Array( link ) );
+               updateTooltipAccessKeys( [link] );
        }
 
        if ( nextnode && nextnode.parentNode == node )
@@ -354,7 +345,7 @@ function akeytt( doId ) {
        // A lot of user scripts (and some of the code below) break if
        // ta isn't defined, so we make sure it is.  Explictly using
        // window.ta avoids a "ta is not defined" error.
-       if (!window.ta) window.ta = new Array;
+       if (!window.ta) window.ta = [];
 
        // Make a local, possibly restricted, copy to avoid clobbering
        // the original.
@@ -367,7 +358,7 @@ function akeytt( doId ) {
 
        // Now deal with evil deprecated ta
        var watchCheckboxExists = document.getElementById( 'wpWatchthis' ) ? true : false;
-       for (var id in ta) {
+       for (var id = 0; id < ta.length; id++) {
                var n = document.getElementById(id);
                if (n) {
                        var a = null;
@@ -498,7 +489,7 @@ function toggle_element_check(ida,idb) {
        From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
 */
 function getElementsByClassName(oElm, strTagName, oClassNames){
-       var arrReturnElements = new Array();
+       var arrReturnElements = [];
        if ( typeof( oElm.getElementsByClassName ) == "function" ) {
                /* Use a native implementation where possible FF3, Saf3.2, Opera 9.5 */
                var arrNativeReturn = oElm.getElementsByClassName( oClassNames );
@@ -511,7 +502,7 @@ function getElementsByClassName(oElm, strTagName, oClassNames){
                return arrReturnElements;
        }
        var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
-       var arrRegExpClassNames = new Array();
+       var arrRegExpClassNames = [];
        if(typeof oClassNames == "object"){
                for(var i=0; i<oClassNames.length; i++){
                        arrRegExpClassNames[arrRegExpClassNames.length] =
@@ -680,8 +671,8 @@ function ts_resortTable(lnk) {
 
        var reverse = (span.getAttribute("sortdir") == 'down');
 
-       var newRows = new Array();
-       var staticRows = new Array();
+       var newRows = new [];
+       var staticRows = new [];
        for (var j = rowStart; j < table.rows.length; j++) {
                var row = table.rows[j];
                if((" "+row.className+" ").indexOf(" unsortable ") < 0) {
@@ -689,8 +680,8 @@ function ts_resortTable(lnk) {
                        var oldIndex = (reverse ? -j : j);
                        var preprocessed = preprocessor( keyText.replace(/^[\s\xa0]+/, "").replace(/[\s\xa0]+$/, "") );
 
-                       newRows[newRows.length] = new Array(row, preprocessed, oldIndex);
-               } else staticRows[staticRows.length] = new Array(row, false, j-rowStart);
+                       newRows[newRows.length] = new [row, preprocessed, oldIndex];
+               } else staticRows[staticRows.length] = [row, false, j-rowStart];
        }
 
        newRows.sort(sortfn);