From e75383c07de0191e97a4fb207e86b3eaf346d4c0 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Thu, 17 Jan 2013 14:03:09 -0500
Subject: [PATCH] Moved document ready functions to ends of files for jslint
 compliance (avoid undeclared errors).

---
 themes/blueprint/js/bulk_actions.js         |   8 +-
 themes/blueprint/js/check_item_statuses.js  |   8 +-
 themes/blueprint/js/check_save_statuses.js  |  36 +--
 themes/blueprint/js/collection_record.js    |   8 +-
 themes/blueprint/js/hierarchyTree_JSTree.js | 245 ++++++++++----------
 themes/blueprint/js/openurl.js              |  38 +--
 themes/blueprint/js/preview.js              |  16 +-
 themes/blueprint/js/pubdate_slider.js       |  20 +-
 themes/blueprint/js/record.js               | 125 +++++-----
 9 files changed, 253 insertions(+), 251 deletions(-)

diff --git a/themes/blueprint/js/bulk_actions.js b/themes/blueprint/js/bulk_actions.js
index 1be143a75b6..961f4aca5ad 100644
--- a/themes/blueprint/js/bulk_actions.js
+++ b/themes/blueprint/js/bulk_actions.js
@@ -1,7 +1,3 @@
-$(document).ready(function(){
-    registerBulkActions();
-});
-
 function registerBulkActions() {
     $('form[name="bulkActionForm"] input[type="submit"]').unbind('click').click(function(){
         var ids = $.map($(this.form).find('input.checkbox_ui:checked'), function(i) {
@@ -70,3 +66,7 @@ function registerBulkActions() {
         return false;
     });
 }
+
+$(document).ready(function(){
+    registerBulkActions();
+});
\ No newline at end of file
diff --git a/themes/blueprint/js/check_item_statuses.js b/themes/blueprint/js/check_item_statuses.js
index 60f27db547e..4f20108d667 100644
--- a/themes/blueprint/js/check_item_statuses.js
+++ b/themes/blueprint/js/check_item_statuses.js
@@ -1,7 +1,3 @@
-$(document).ready(function() {
-    checkItemStatuses();
-});
-
 function checkItemStatuses() {
     var id = $.map($('.ajaxItemId'), function(i) {
         return $(i).find('.hiddenId')[0].value;
@@ -77,3 +73,7 @@ function checkItemStatuses() {
         });
     }
 }
+
+$(document).ready(function() {
+    checkItemStatuses();
+});
\ No newline at end of file
diff --git a/themes/blueprint/js/check_save_statuses.js b/themes/blueprint/js/check_save_statuses.js
index 97dc92b0154..c5bb654f84c 100644
--- a/themes/blueprint/js/check_save_statuses.js
+++ b/themes/blueprint/js/check_save_statuses.js
@@ -1,21 +1,3 @@
-$(document).ready(function() {
-    checkSaveStatuses();
-    // attach click event to the save record link
-    $('a.saveRecord').click(function() {
-        var id = $(this).parents('.recordId').find('.hiddenId');
-        if (id.length > 0) {
-            // search results:
-            id = id[0].value;
-        } else {
-            // record view:
-            id = document.getElementById('record_id').value;
-        }
-        var controller = extractController(this);
-        var $dialog = getLightbox(controller, 'Save', id, null, this.title, controller, 'Save', id);
-        return false;
-    });
-});
-
 function checkSaveStatuses() {
     var data = $.map($('.recordId'), function(i) {
         return {'id':$(i).find('.hiddenId')[0].value, 'source':extractSource(i)};
@@ -54,3 +36,21 @@ function checkSaveStatuses() {
         });
     }
 }
+
+$(document).ready(function() {
+    checkSaveStatuses();
+    // attach click event to the save record link
+    $('a.saveRecord').click(function() {
+        var id = $(this).parents('.recordId').find('.hiddenId');
+        if (id.length > 0) {
+            // search results:
+            id = id[0].value;
+        } else {
+            // record view:
+            id = document.getElementById('record_id').value;
+        }
+        var controller = extractController(this);
+        var $dialog = getLightbox(controller, 'Save', id, null, this.title, controller, 'Save', id);
+        return false;
+    });
+});
\ No newline at end of file
diff --git a/themes/blueprint/js/collection_record.js b/themes/blueprint/js/collection_record.js
index aaaa2ef23f0..6d1f6ca42f6 100644
--- a/themes/blueprint/js/collection_record.js
+++ b/themes/blueprint/js/collection_record.js
@@ -1,7 +1,3 @@
-$(document).ready(function() {
-    showMoreInfoToggle();
-});
-
 function showMoreInfoToggle() {
     toggleCollectionInfo();
     $("#moreInfoToggle").show();
@@ -14,3 +10,7 @@ function showMoreInfoToggle() {
 function toggleCollectionInfo() {
     $("#collectionInfo").toggle();
 }
+
+$(document).ready(function() {
+    showMoreInfoToggle();
+});
\ No newline at end of file
diff --git a/themes/blueprint/js/hierarchyTree_JSTree.js b/themes/blueprint/js/hierarchyTree_JSTree.js
index e5486269a7c..04caee393ac 100644
--- a/themes/blueprint/js/hierarchyTree_JSTree.js
+++ b/themes/blueprint/js/hierarchyTree_JSTree.js
@@ -1,127 +1,5 @@
 var hierarchyID;
 var baseTreeSearchFullURL;
-$(document).ready(function()
-{
-    hierarchyID = $("#hierarchyTree").find(".hiddenHierarchyId")[0].value;
-    var recordID = $("#hierarchyTree").find(".hiddenRecordId")[0].value;
-    var scroller = hierarchySettings.lightboxMode ? '#modalDialog' : '#hierarchyTree';
-    var context = $("#hierarchyTree").find(".hiddenContext")[0].value;
-
-    if (!hierarchySettings.fullHierarchy) {
-        // Set Up Partial Hierarchy View Toggle
-        $('#hierarchyTree').parent().prepend('<a href="#" id="toggleTree" class="closed">' + vufindString.showTree + '</a>');
-        $('#toggleTree').click(function(e)
-        {
-            e.preventDefault();
-            $(this).toggleClass("open");
-            $(this).hasClass("open") ? scroll(scroller, "show") : scroll(scroller, "hide");
-            $("#hierarchyTree").jstree("toggle_dots");
-        });
-    }
-
-    $("#hierarchyTree")
-    .bind("loaded.jstree", function (event, data)
-    {
-        var idList = $('#hierarchyTree .JSTreeID');
-        $(idList).each(function()
-        {
-            var id = $.trim($(this).text());
-            $(this).before('<input type="hidden" class="jsTreeID '+context+ '" value="'+id+'" />');
-            $(this).remove();
-        });
-
-        $(".Collection").each(function()
-        {
-            var id = $(this).attr("value");
-            $(this).next("a").click(function(e)
-            {
-                e.preventDefault();
-                $("#hierarchyTree a").removeClass("jstree-clicked");
-                $(this).addClass("jstree-clicked");
-                // Open this node
-                $(this).parent().removeClass("jstree-closed").addClass("jstree-open");
-                getRecord(id);
-                return false;
-            });
-        });
-
-        $("#hierarchyTree a").click(function(e)
-        {
-            e.preventDefault();
-            if (context == "Record") {
-                window.location = $(this).attr("href");
-            }
-            if ($('#toggleTree').length > 0 && !$('#toggleTree').hasClass("open")) {
-                hideFullHierarchy($(this).parent());
-            }
-        });
-
-        var jsTreeNode = $(".jsTreeID:input[value='"+recordID+"']").parent();
-        // Open Nodes to Current Path
-        jsTreeNode.parents("li").removeClass("jstree-closed").addClass("jstree-open");
-        // Initially Open Current node too
-        jsTreeNode.removeClass("jstree-closed").addClass("jstree-open");
-        // Add clicked class
-        $("> a", jsTreeNode).addClass("jstree-clicked");
-        // Add highlight class to parents
-        jsTreeNode.parents("li").children("a").addClass("jstree-highlight");
-
-        if (!hierarchySettings.fullHierarchy) {
-            // Initial hide of nodes outside current path
-            hideFullHierarchy(jsTreeNode);
-            $("#hierarchyTree").jstree("toggle_dots");
-        }
-        // Scroll to the current record
-        $(scroller).delay(250).animate({
-            scrollTop: jsTreeNode.offset().top - $(scroller).offset().top + $(scroller).scrollTop()
-        });
-    })
-    .jstree({
-        "xml_data" : {
-            "ajax" : {
-                "url" : path + '/Hierarchy/GetTree?' + $.param({'hierarchyID': hierarchyID, 'id': recordID, 'context': context, mode: "Tree"}),
-                success: function(data)
-                {
-                    // Necessary as data is a string
-                    var dataAsXML = $.parseXML(data);
-                    if(dataAsXML) {
-                        var error = $(dataAsXML).find("error");
-                        if (error.length > 0) {
-                            showTreeError($(error).text());
-                            return false;
-                        } else {
-                            return data;
-                        }
-                    } else {
-                        showTreeError("Unable to Parse XML");
-                    }
-                },
-                failure: function()
-                {
-                    showTreeError("Unable to Load Tree");
-                }
-            },
-            "xsl" : "nest"
-        },
-        "plugins" : [ "themes", "xml_data", "ui" ],
-        "themes" : {
-            "url": path + '/themes/blueprint/js/jsTree/themes/vufind/style.css'
-        }
-    }).bind("open_node.jstree close_node.jstree", function (e, data)
-    {
-        $(data.args[0]).find("li").show();
-    });
-
-    $('#treeSearch').show();
-    $('#treeSearchText').bind('keypress', function(e)
-    {
-        var code = (e.keyCode ? e.keyCode : e.which);
-        if(code == 13) {
-            // Enter keycode should call the search code
-            doTreeSearch();
-        }
-    });
-});
 
 function showTreeError(msg)
 {
@@ -257,4 +135,127 @@ $(function ()
                 break;
         }
     });
+});
+
+$(document).ready(function()
+{
+    hierarchyID = $("#hierarchyTree").find(".hiddenHierarchyId")[0].value;
+    var recordID = $("#hierarchyTree").find(".hiddenRecordId")[0].value;
+    var scroller = hierarchySettings.lightboxMode ? '#modalDialog' : '#hierarchyTree';
+    var context = $("#hierarchyTree").find(".hiddenContext")[0].value;
+
+    if (!hierarchySettings.fullHierarchy) {
+        // Set Up Partial Hierarchy View Toggle
+        $('#hierarchyTree').parent().prepend('<a href="#" id="toggleTree" class="closed">' + vufindString.showTree + '</a>');
+        $('#toggleTree').click(function(e)
+        {
+            e.preventDefault();
+            $(this).toggleClass("open");
+            $(this).hasClass("open") ? scroll(scroller, "show") : scroll(scroller, "hide");
+            $("#hierarchyTree").jstree("toggle_dots");
+        });
+    }
+
+    $("#hierarchyTree")
+    .bind("loaded.jstree", function (event, data)
+    {
+        var idList = $('#hierarchyTree .JSTreeID');
+        $(idList).each(function()
+        {
+            var id = $.trim($(this).text());
+            $(this).before('<input type="hidden" class="jsTreeID '+context+ '" value="'+id+'" />');
+            $(this).remove();
+        });
+
+        $(".Collection").each(function()
+        {
+            var id = $(this).attr("value");
+            $(this).next("a").click(function(e)
+            {
+                e.preventDefault();
+                $("#hierarchyTree a").removeClass("jstree-clicked");
+                $(this).addClass("jstree-clicked");
+                // Open this node
+                $(this).parent().removeClass("jstree-closed").addClass("jstree-open");
+                getRecord(id);
+                return false;
+            });
+        });
+
+        $("#hierarchyTree a").click(function(e)
+        {
+            e.preventDefault();
+            if (context == "Record") {
+                window.location = $(this).attr("href");
+            }
+            if ($('#toggleTree').length > 0 && !$('#toggleTree').hasClass("open")) {
+                hideFullHierarchy($(this).parent());
+            }
+        });
+
+        var jsTreeNode = $(".jsTreeID:input[value='"+recordID+"']").parent();
+        // Open Nodes to Current Path
+        jsTreeNode.parents("li").removeClass("jstree-closed").addClass("jstree-open");
+        // Initially Open Current node too
+        jsTreeNode.removeClass("jstree-closed").addClass("jstree-open");
+        // Add clicked class
+        $("> a", jsTreeNode).addClass("jstree-clicked");
+        // Add highlight class to parents
+        jsTreeNode.parents("li").children("a").addClass("jstree-highlight");
+
+        if (!hierarchySettings.fullHierarchy) {
+            // Initial hide of nodes outside current path
+            hideFullHierarchy(jsTreeNode);
+            $("#hierarchyTree").jstree("toggle_dots");
+        }
+        // Scroll to the current record
+        $(scroller).delay(250).animate({
+            scrollTop: jsTreeNode.offset().top - $(scroller).offset().top + $(scroller).scrollTop()
+        });
+    })
+    .jstree({
+        "xml_data" : {
+            "ajax" : {
+                "url" : path + '/Hierarchy/GetTree?' + $.param({'hierarchyID': hierarchyID, 'id': recordID, 'context': context, mode: "Tree"}),
+                success: function(data)
+                {
+                    // Necessary as data is a string
+                    var dataAsXML = $.parseXML(data);
+                    if(dataAsXML) {
+                        var error = $(dataAsXML).find("error");
+                        if (error.length > 0) {
+                            showTreeError($(error).text());
+                            return false;
+                        } else {
+                            return data;
+                        }
+                    } else {
+                        showTreeError("Unable to Parse XML");
+                    }
+                },
+                failure: function()
+                {
+                    showTreeError("Unable to Load Tree");
+                }
+            },
+            "xsl" : "nest"
+        },
+        "plugins" : [ "themes", "xml_data", "ui" ],
+        "themes" : {
+            "url": path + '/themes/blueprint/js/jsTree/themes/vufind/style.css'
+        }
+    }).bind("open_node.jstree close_node.jstree", function (e, data)
+    {
+        $(data.args[0]).find("li").show();
+    });
+
+    $('#treeSearch').show();
+    $('#treeSearchText').bind('keypress', function(e)
+    {
+        var code = (e.keyCode ? e.keyCode : e.which);
+        if(code == 13) {
+            // Enter keycode should call the search code
+            doTreeSearch();
+        }
+    });
 });
\ No newline at end of file
diff --git a/themes/blueprint/js/openurl.js b/themes/blueprint/js/openurl.js
index 7d6fc9ab910..d2ee6306423 100644
--- a/themes/blueprint/js/openurl.js
+++ b/themes/blueprint/js/openurl.js
@@ -1,22 +1,3 @@
-$(document).ready(function() {
-    // assign action to the openUrlWindow link class
-    $('a.openUrlWindow').click(function(){
-        var params = extractParams($(this).attr('class'));
-        var settings = params.window_settings;
-        window.open($(this).attr('href'), 'openurl', settings);
-        return false;
-    });
-
-    // assign action to the openUrlEmbed link class
-    $('a.openUrlEmbed').click(function(){
-        var params = extractParams($(this).attr('class'));
-        var openUrl = $(this).children('span.openUrl:first').attr('title');
-        $(this).hide();
-        loadResolverLinks($('#openUrlEmbed'+params.openurl_id).show(), openUrl);
-        return false;
-    });
-});
-
 function loadResolverLinks($target, openUrl) {
     $target.addClass('ajax_availability');
     var url = path + '/AJAX/JSON?' + $.param({method:'getResolverLinks',openurl:openUrl});
@@ -34,3 +15,22 @@ function loadResolverLinks($target, openUrl) {
         }
     });
 }
+
+$(document).ready(function() {
+    // assign action to the openUrlWindow link class
+    $('a.openUrlWindow').click(function(){
+        var params = extractParams($(this).attr('class'));
+        var settings = params.window_settings;
+        window.open($(this).attr('href'), 'openurl', settings);
+        return false;
+    });
+
+    // assign action to the openUrlEmbed link class
+    $('a.openUrlEmbed').click(function(){
+        var params = extractParams($(this).attr('class'));
+        var openUrl = $(this).children('span.openUrl:first').attr('title');
+        $(this).hide();
+        loadResolverLinks($('#openUrlEmbed'+params.openurl_id).show(), openUrl);
+        return false;
+    });
+});
\ No newline at end of file
diff --git a/themes/blueprint/js/preview.js b/themes/blueprint/js/preview.js
index 14a804b7a3a..216ce58fdca 100644
--- a/themes/blueprint/js/preview.js
+++ b/themes/blueprint/js/preview.js
@@ -1,10 +1,3 @@
-$(document).ready(function() {
-    if (!Array.prototype.indexOf) {
-        setIndexOf();
-    }
-    getBookPreviews();
-});
-
 function getBookPreviews() {
     var skeys = '';
     $('.previewBibkeys').each(function(){
@@ -158,4 +151,11 @@ function setIndexOf() {
         }
         return -1;
     }
-}
\ No newline at end of file
+}
+
+$(document).ready(function() {
+    if (!Array.prototype.indexOf) {
+        setIndexOf();
+    }
+    getBookPreviews();
+});
\ No newline at end of file
diff --git a/themes/blueprint/js/pubdate_slider.js b/themes/blueprint/js/pubdate_slider.js
index 37c29f1c3e1..0f2eebf7575 100644
--- a/themes/blueprint/js/pubdate_slider.js
+++ b/themes/blueprint/js/pubdate_slider.js
@@ -1,12 +1,3 @@
-$(document).ready(function(){
-    // create the slider for the publish date facet
-    $('.dateSlider').each(function(i) {
-        var myId = $(this).attr('id');
-        var prefix = myId.substr(0, myId.length - 6);
-        makePublishDateSlider(prefix);
-    });
-});
-
 function makePublishDateSlider(prefix) {
     // create the slider widget
     $('#' + prefix + 'Slider').slider({
@@ -49,4 +40,13 @@ function updatePublishDateSlider(prefix) {
     $('#' + prefix + 'Slider').slider('option', {
         min: min, max: max, values: [from, to]
     });
-}
\ No newline at end of file
+}
+
+$(document).ready(function(){
+    // create the slider for the publish date facet
+    $('.dateSlider').each(function(i) {
+        var myId = $(this).attr('id');
+        var prefix = myId.substr(0, myId.length - 6);
+        makePublishDateSlider(prefix);
+    });
+});
\ No newline at end of file
diff --git a/themes/blueprint/js/record.js b/themes/blueprint/js/record.js
index 8bde4929a44..3cc1085f7ae 100644
--- a/themes/blueprint/js/record.js
+++ b/themes/blueprint/js/record.js
@@ -1,68 +1,6 @@
 /**
  * Functions and event handlers specific to record pages.
  */
-$(document).ready(function(){
-    // register the record comment form to be submitted via AJAX
-    registerAjaxCommentRecord();
-
-    // bind click action to export record menu
-    $('a.exportMenu').click(function(){
-        toggleMenu('exportMenu');
-        return false;
-    });
-
-    var id = document.getElementById('record_id').value;
-
-    // bind click action on toolbar links
-    $('a.citeRecord').click(function() {
-        var controller = extractController(this);
-        var $dialog = getLightbox(controller, 'Cite', id, null, this.title);
-        return false;
-    });
-    $('a.smsRecord').click(function() {
-        var controller = extractController(this);
-        var $dialog = getLightbox(controller, 'SMS', id, null, this.title);
-        return false;
-    });
-    $('a.mailRecord').click(function() {
-        var controller = extractController(this);
-        var $dialog = getLightbox(controller, 'Email', id, null, this.title, controller, 'Email', id);
-        return false;
-    });
-    $('a.tagRecord').click(function() {
-        var controller = extractController(this);
-        var $dialog = getLightbox(controller, 'AddTag', id, null, this.title, controller, 'AddTag', id);
-        return false;
-    });
-    $('a.deleteRecordComment').click(function() {
-        var commentId = this.id.substr('recordComment'.length);
-        var recordSource = extractSource(this);
-        deleteRecordComment(id, recordSource, commentId);
-        return false;
-    });
-
-    // add highlighting to subject headings when mouseover
-    $('a.subjectHeading').mouseover(function() {
-        var subjectHeadings = $(this).parent().children('a.subjectHeading');
-        for(var i = 0; i < subjectHeadings.length; i++) {
-            $(subjectHeadings[i]).addClass('highlight');
-            if ($(this).text() == $(subjectHeadings[i]).text()) {
-                break;
-            }
-        }
-    });
-    $('a.subjectHeading').mouseout(function() {
-        $('.subjectHeading').removeClass('highlight');
-    });
-
-    $('.checkRequest').each(function(i) {
-        if($(this).hasClass('checkRequest')) {
-            $(this).addClass('ajax_hold_availability');
-        }
-    });
-
-    setUpCheckRequest();
-});
 
 function setUpCheckRequest() {
     $('.checkRequest').each(function(i) {
@@ -170,3 +108,66 @@ function deleteRecordComment(recordId, recordSource, commentId) {
         }
     });
 }
+
+$(document).ready(function(){
+    // register the record comment form to be submitted via AJAX
+    registerAjaxCommentRecord();
+
+    // bind click action to export record menu
+    $('a.exportMenu').click(function(){
+        toggleMenu('exportMenu');
+        return false;
+    });
+
+    var id = document.getElementById('record_id').value;
+
+    // bind click action on toolbar links
+    $('a.citeRecord').click(function() {
+        var controller = extractController(this);
+        var $dialog = getLightbox(controller, 'Cite', id, null, this.title);
+        return false;
+    });
+    $('a.smsRecord').click(function() {
+        var controller = extractController(this);
+        var $dialog = getLightbox(controller, 'SMS', id, null, this.title);
+        return false;
+    });
+    $('a.mailRecord').click(function() {
+        var controller = extractController(this);
+        var $dialog = getLightbox(controller, 'Email', id, null, this.title, controller, 'Email', id);
+        return false;
+    });
+    $('a.tagRecord').click(function() {
+        var controller = extractController(this);
+        var $dialog = getLightbox(controller, 'AddTag', id, null, this.title, controller, 'AddTag', id);
+        return false;
+    });
+    $('a.deleteRecordComment').click(function() {
+        var commentId = this.id.substr('recordComment'.length);
+        var recordSource = extractSource(this);
+        deleteRecordComment(id, recordSource, commentId);
+        return false;
+    });
+
+    // add highlighting to subject headings when mouseover
+    $('a.subjectHeading').mouseover(function() {
+        var subjectHeadings = $(this).parent().children('a.subjectHeading');
+        for(var i = 0; i < subjectHeadings.length; i++) {
+            $(subjectHeadings[i]).addClass('highlight');
+            if ($(this).text() == $(subjectHeadings[i]).text()) {
+                break;
+            }
+        }
+    });
+    $('a.subjectHeading').mouseout(function() {
+        $('.subjectHeading').removeClass('highlight');
+    });
+
+    $('.checkRequest').each(function(i) {
+        if($(this).hasClass('checkRequest')) {
+            $(this).addClass('ajax_hold_availability');
+        }
+    });
+
+    setUpCheckRequest();
+});
\ No newline at end of file
-- 
GitLab