[Koha-patches] [PATCH] Bug 9424 - Move JavaScript out of header include

Owen Leonard oleonard at myacpl.org
Fri Jan 18 16:37:05 CET 2013


This patch removes JavaScript "onlick" attributes from header.inc and
moves the functionality to staff-global.js. This is in keeping with the
idea of progressive enhancement.

This patch also makes a couple of minor changes to staff-global.js to
fix jsHint warnings.

To test, be sure to clear your browser cache after applying the patch.
Test the logout link under several conditions:

- intranetbookbag enabled, virtualshelves enabled
- intranetbookbag enabled, virtualshelves disabled
- intranetbookbag disabled, virtualshelves enabled
- intranetbookbag disabled, virtualshelves disabled

Logout should be successful with no JavaScript errors. This array of
tests is required because of the Cart-clearing action of logging out and
the changes made in this patch to the way Car/Lists JavaScript is
included.
---
 .../prog/en/includes/doc-head-close.inc            |   31 ++++++++++----------
 .../intranet-tmpl/prog/en/includes/header.inc      |    8 ++---
 koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js |   25 +++++++++++++---
 3 files changed, 38 insertions(+), 26 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc
index 32eae21..5d6f16b 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc
@@ -40,25 +40,24 @@
     //]]>
     </script>
 [% END %]
+[% IF ( virtualshelves || intranetbookbag ) %]
 <script type="text/javascript" language="javascript">
     //<![CDATA[
-    [% IF ( intranetbookbag ) %]var MSG_BASKET_EMPTY = _("Your cart is currently empty");
-        var MSG_RECORD_IN_BASKET = _("This item is already in your cart");
-        var MSG_RECORD_ADDED = _("This item has been added to your cart");
-        var MSG_NRECORDS_ADDED = _(" item(s) added to your cart");
-        var MSG_NRECORDS_IN_BASKET = _("already in your cart");
-        var MSG_NO_RECORD_SELECTED = _("No item was selected");
-        var MSG_NO_RECORD_ADDED = _("No item was added to your cart");
-        var MSG_CONFIRM_DEL_BASKET = _("Are you sure you want to empty your cart?");
-        var MSG_CONFIRM_DEL_RECORDS = _("Are you sure you want to remove the selected items?");
-        var MSG_IN_YOUR_CART = _("Items in your cart: ");
-        var MSG_NON_RESERVES_SELECTED = _("One or more selected items cannot be reserved.");
-    [% END %]
+    var MSG_BASKET_EMPTY = _("Your cart is currently empty");
+    var MSG_RECORD_IN_BASKET = _("This item is already in your cart");
+    var MSG_RECORD_ADDED = _("This item has been added to your cart");
+    var MSG_NRECORDS_ADDED = _(" item(s) added to your cart");
+    var MSG_NRECORDS_IN_BASKET = _("already in your cart");
+    var MSG_NO_RECORD_SELECTED = _("No item was selected");
+    var MSG_NO_RECORD_ADDED = _("No item was added to your cart");
+    var MSG_CONFIRM_DEL_BASKET = _("Are you sure you want to empty your cart?");
+    var MSG_CONFIRM_DEL_RECORDS = _("Are you sure you want to remove the selected items?");
+    var MSG_IN_YOUR_CART = _("Items in your cart: ");
+    var MSG_NON_RESERVES_SELECTED = _("One or more selected items cannot be reserved.");
     //]]>
-    </script>
-    [% IF ( virtualshelves || intranetbookbag ) %]
-        <script type="text/javascript" language="javascript" src="[% themelang %]/js/basket.js"></script>
-    [% END %]
+</script>
+<script type="text/javascript" language="javascript" src="[% themelang %]/js/basket.js"></script>
+[% END %]
 [% IF LocalCoverImages %]
 <script type="text/javascript" language="javascript" src="[% themelang %]/js/localcovers.js"></script>
 <script type="text/javascript" language="javascript">
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
index eaf1481..f941481 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
@@ -70,14 +70,10 @@
             <span class="loggedinusername">
                 [% loggedinusername %]
             </span>
-            [% IF ( intranetbookbag ) %]
-            ( <a class="toplinks" href="/cgi-bin/koha/mainpage.pl?logout.x=1" onclick="clearHoldFor(); delBasket('main', true);">Log out</a> ) |
-            [% ELSE %]
-            ( <a class="toplinks" href="/cgi-bin/koha/mainpage.pl?logout.x=1" onclick="clearHoldFor();">Log out</a> ) |
-            [% END %]
+            ( <a id="logout" class="toplinks" href="/cgi-bin/koha/mainpage.pl?logout.x=1">Log out</a> ) |
         [% ELSE %]
             You are not logged in |
         [% END %]
-        <a class="toplinks" href="/cgi-bin/koha/help.pl" id="helper" onclick="var link=window.open('','Koha_Help','width=600,height=600,toolbar=false,scrollbars=yes'); link.location='/cgi-bin/koha/help.pl'; return false;">Help</a>
+        <a class="toplinks" href="/cgi-bin/koha/help.pl" id="helper">Help</a>
     </div>
 </div>	
diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js
index 125cd52..f267a0e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js
+++ b/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js
@@ -1,7 +1,7 @@
 // staff-global.js
 if ( KOHA === undefined ) var KOHA = {};
 
-function _(s) { return s } // dummy function for gettext
+function _(s) { return s; } // dummy function for gettext
 
  $(document).ready(function() {
     $('#header_search').tabs().bind('tabsshow', function(e, ui) { $('#header_search > div:not(.ui-tabs-hide)').find('input').eq(0).focus(); });
@@ -10,9 +10,15 @@ function _(s) { return s } // dummy function for gettext
     if($("#header_search #circ_search").length > 0){ $(document).bind('keydown','Alt+u',function (){ $("#header_search").tabs("select","#circ_search"); $("#findborrower").focus(); }); } else { $(document).bind('keydown','Alt+u',function(){ location.href="/cgi-bin/koha/circ/circulation.pl"; }); }
     if($("#header_search #catalog_search").length > 0){ $(document).bind('keydown','Alt+q',function (){ $("#header_search").tabs("select","#catalog_search"); $("#search-form").focus(); }); } else { $(document).bind('keydown','Alt+q',function(){ location.href="/cgi-bin/koha/catalogue/search.pl"; }); }
     $(".focus").focus();
+    $("#logout").click(function(){
+        logOut();
+    });
+    $("#helper").click(function(){
+        openHelp();
+        return false;
+    });
  });
 
- 
              YAHOO.util.Event.onContentReady("header", function () {
 				var oMoremenu = new YAHOO.widget.Menu("moremenu", { zindex: 2 });
 
@@ -48,7 +54,7 @@ function _(s) { return s } // dummy function for gettext
 YAHOO.util.Event.onContentReady("changelanguage", function () {
 	$(".sublangs").each(function(){
 		var menuid = $(this).attr("id");
-		var menuid = menuid.replace("show","");
+        menuid = menuid.replace("show","");
 
 		var oMenu = new YAHOO.widget.Menu("sub"+menuid, { zindex: 2 });
 		function positionoMenu() {
@@ -72,7 +78,7 @@ YAHOO.util.Event.onContentReady("changelanguage", function () {
 		YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionoMenu);
 	});
 });
-			
+
 // http://jennifermadden.com/javascript/stringEnterKeyDetector.html
 function checkEnter(e){ //e is event object passed from function invocation
 	var characterCode; // literal character code will be stored in this variable
@@ -95,6 +101,17 @@ function clearHoldFor(){
 	$.cookie("holdfor",null, { path: "/", expires: 0 });
 }
 
+function logOut(){
+    if( typeof delBasket == 'function' ){
+        delBasket('main', true);
+    }
+    clearHoldFor();
+}
+
+function openHelp(){
+    openWindow("/cgi-bin/koha/help.pl","Koha help",600,600);
+}
+
 jQuery.fn.preventDoubleFormSubmit = function() {
     jQuery(this).submit(function() {
         if (this.beenSubmitted)
-- 
1.7.9.5


More information about the Koha-patches mailing list