Add nine ###-comments arising from code-read with Heikki.
[mkws-moved-to-github.git] / tools / htdocs / mkws.js
index 75a88c7..8ffc6f9 100644 (file)
@@ -228,11 +228,13 @@ function team($, teamName) {
     m_sort = mkws_config.sort_default;
     debug("copied mkws_config.sort_default '" + mkws_config.sort_default + "' to m_sort");
 
+    // ### should be in global code
     if (mkws_config.query_width < 5 || mkws_config.query_width > 150) {
        debug("Reset query width: " + mkws_config.query_width);
        mkws_config.query_width = 50;
     }
 
+    // ### should be in global code
     for (var key in mkws_config) {
        if (mkws_config.hasOwnProperty(key)) {
            if (key.match(/^language_/)) {
@@ -286,6 +288,7 @@ function team($, teamName) {
        debug("show");
        m_totalRec = data.merged;
 
+       // ### Here and elsewhere we should use a findnode() utility function
        var pager = $(".mkwsPager.mkwsTeam_" + m_teamName);
        if (pager.length) {
            pager.html(drawPager(data))
@@ -449,6 +452,7 @@ function team($, teamName) {
 
 
     // when search button pressed
+    // ### This is closure, so can always just operate on its own team
     function onFormSubmitEventHandler()
     {
        mkws.handle_node_with_team(this, function (tname) {
@@ -460,6 +464,8 @@ function team($, teamName) {
     }
 
 
+    // ### won't need to be externally visible once onFormSubmitEventHandler() is fixed.
+    // ### doesn't need windowid
     that.newSearch = function(query, sort, targets, windowid)
     {
        debug("newSearch: " + query);
@@ -496,6 +502,7 @@ function team($, teamName) {
     }
 
 
+    // ### doesn't need windowid
     function triggerSearch (query, sort, targets, windowid)
     {
        var pp2filter = "";
@@ -911,22 +918,20 @@ function team($, teamName) {
      * All the HTML stuff to render the search forms and
      * result pages.
      */
+    // ### This and other multi-word identifiers should be camelCase
     function mkws_html_all() {
        mkws_set_lang();
        if (mkws_config.show_lang)
            mkws_html_lang();
 
        debug("HTML search form");
-       // ### There is only one match here by design: fix not to bother looping
-       $('.mkwsSearch.mkwsTeam_' + m_teamName).each(function (i, obj) {
-           var node = this;
-           mkws.handle_node_with_team(this, function(tname) {
-               $(node).html('\
+       mkws.handle_node_with_team($('.mkwsSearch.mkwsTeam_' + m_teamName),
+                                  function(tname) {
+           this.html('\
 <form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_' + tname + '" action="" >\
   <input class="mkwsQuery mkwsTeam_' + tname + '" type="text" size="' + mkws_config.query_width + '" />\
   <input class="mkwsButton mkwsTeam_' + tname + '" type="submit" value="' + M('Search') + '" />\
 </form>');
-           });
        });
 
        debug("HTML records");
@@ -987,15 +992,10 @@ function team($, teamName) {
            $(document).ready(function() { mkws.resize_page() });
        }
 
-       $('.mkwsSearchForm.mkwsTeam_' + m_teamName).each(function (i, obj) {
-           debug("adding search-forms for team '" + m_teamName + "'");
-           var node = this;
-           mkws.handle_node_with_team(this, function(tname) {
-               debug("adding search-form '" + tname + "' for team '" + m_teamName + "'");
-               $(node).submit(onFormSubmitEventHandler);
-           });
-       });
-
+       var node;
+       node = $('.mkwsSearchForm.mkwsTeam_' + m_teamName);
+       if (node.length)
+           node.submit(onFormSubmitEventHandler);
        node = $('.mkwsSort.mkwsTeam_' + m_teamName);
        if (node.length)
            node.change(onSelectDdChange);
@@ -1006,7 +1006,7 @@ function team($, teamName) {
        // on first page, hide the termlist
        $(document).ready(function() { $(".mkwsTermlists.mkwsTeam_" + m_teamName).hide(); });
        var motd = $(".mkwsMOTD.mkwsTeam_" + m_teamName);
-       var container = $(".mkwsMOTDContainer.mkwsTeam_" + m_teamName);
+        var container = $(".mkwsMOTDContainer.mkwsTeam_" + m_teamName);
        if (motd.length && container.length) {
            // Move the MOTD from the provided element down into the container
            motd.appendTo(container);
@@ -1180,6 +1180,7 @@ function team($, teamName) {
 
     // This function is taken from a StackOverflow answer
     // http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144
+    // ### should we unify this and parseQuerystring()?
     function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
        var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
@@ -1432,7 +1433,7 @@ function team($, teamName) {
        // elements that have the old magic IDs.
        var ids = [ "Switch", "Lang", "Search", "Pager", "Navi",
                    "Results", "Records", "Targets", "Ranking",
-                   "Termlists", "Stat" ];
+                   "Termlists", "Stat", "MOTD" ];
        for (var i = 0; i < ids.length; i++) {
            var id = 'mkws' + ids[i];
            var node = $('#' + id);