Georg Brandl avatar Georg Brandl committed 46d0815

Correct some JS issues found by JSHint.

Comments (0)

Files changed (2)

sphinx/themes/basic/static/doctools.js

  */
 jQuery.urldecode = function(x) {
   return decodeURIComponent(x).replace(/\+/g, ' ');
-}
+};
 
 /**
  * small helper function to urlencode strings

sphinx/themes/basic/static/searchtools.js_t

       Search.dots.text(dotString);
       if (Search._pulse_status > -1)
         window.setTimeout(pulse, 500);
-    };
+    }
     pulse();
   },
 
     var tmp = query.split(/\s+/);
     var objectterms = [];
     for (i = 0; i < tmp.length; i++) {
-      if (tmp[i] != "") {
+      if (tmp[i] !== "") {
           objectterms.push(tmp[i].toLowerCase());
       }
 
       if ($u.indexOf(stopwords, tmp[i]) != -1 || tmp[i].match(/^\d+$/) ||
-          tmp[i] == "") {
+          tmp[i] === "") {
         // skip this "word"
         continue;
       }
       // stem the word
       var word = stemmer.stemWord(tmp[i]).toLowerCase();
+      var toAppend;
       // select the correct list
       if (word[0] == '-') {
-        var toAppend = excluded;
+        toAppend = excluded;
         word = word.substr(1);
       }
       else {
-        var toAppend = searchterms;
+        toAppend = searchterms;
         hlterms.push(tmp[i].toLowerCase());
       }
       // only add if not already in the list
     // console.info('excluded: ', excluded);
 
     // prepare search
-    var filenames = this._index.filenames;
-    var titles = this._index.titles;
     var terms = this._index.terms;
     var titleterms = this._index.titleterms;
 
-    var files = null;
-
     // array of [filename, title, anchor, descr, score]
     var results = [];
     $('#search-progress').empty();
     // lookup as object
     for (i = 0; i < objectterms.length; i++) {
       var others = [].concat(objectterms.slice(0, i),
-                             objectterms.slice(i+1, objectterms.length))
+                             objectterms.slice(i+1, objectterms.length));
       results = results.concat(this.performObjectSearch(objectterms[i], others));
     }
 
     results = results.concat(this.performTermsSearch(searchterms, excluded, terms, Scorer.term))
                      .concat(this.performTermsSearch(searchterms, excluded, titleterms, Scorer.title));
 
-    // delete unused variables in order to not waste memory until list is
-    // retrieved completely
-    delete filenames, titles, terms, titleterms;
-
     // let the scorer override scores with a custom scoring function
     if (Scorer.score) {
       for (i = 0; i < results.length; i++)
       if (results.length) {
         var item = results.pop();
         var listItem = $('<li style="display:none"></li>');
-        if (DOCUMENTATION_OPTIONS.FILE_SUFFIX == '') {
+        if (DOCUMENTATION_OPTIONS.FILE_SUFFIX === '') {
           // dirhtml builder
           var dirname = item[0] + '/';
           if (dirname.match(/\/index\/$/)) {
         } else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
           $.get(DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/' +
                 item[0] + '.txt', function(data) {
-            if (data != '') {
+            if (data !== '') {
               listItem.append(Search.makeSearchSummary(data, searchterms, hlterms));
               Search.output.append(listItem);
             }
           }
           var descr = objname + _(', in ') + title;
 
-          anchor = match[3];
-          if (anchor == '')
+          var anchor = match[3];
+          if (anchor === '')
             anchor = fullname;
           else if (anchor == '-')
             anchor = objnames[match[1]][1] + '-' + fullname;
     var filenames = this._index.filenames;
     var titles = this._index.titles;
 
-    var i;
+    var i, j, file, files;
     var fileMap = {};
     var results = [];
 
     for (i = 0; i < searchterms.length; i++) {
       var word = searchterms[i];
       // no match but word was a required one
-      if ((files = terms[word]) == null)
+      if ((files = terms[word]) === null)
         break;
-      if (files.length == undefined) {
+      if (files.length === undefined) {
         files = [files];
       }
       // create the mapping
-      for (var j = 0; j < files.length; j++) {
-        var file = files[j];
+      for (j = 0; j < files.length; j++) {
+        file = files[j];
         if (file in fileMap)
           fileMap[file].push(word);
         else
     }
 
     // now check if the files don't contain excluded terms
-    for (var file in fileMap) {
+    for (file in fileMap) {
       var valid = true;
 
       // check if all requirements are matched
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.