From 0fc7d9a0a4aa094c6295ee1f0d43d97831e322dc Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 28 Jun 2013 14:46:44 -0400 Subject: [PATCH] Bug 10522: fix Javascript error on acquisition pages: YAHOO is not defined acq.js includes an immediately invoked function expression, which means that it runs whether or not it is called. Because this function tries to reference the YAHOO object, it triggers an error on pages which don't include the main YAHOO assets. Only the basketgroups page uses this function and YAHOO assets. It's probably possible to make this a regular function, but I propose simply wrapping it in a check for the YAHOO object so that it only executes on pages where YAHOO exists--the basketgroups page. To test, apply the patch, clear your browser cache, and test on both the basketgroups page and at least one page which also includes acq.js (addorderiso2709.pl, neworderempty.pl, aqbudgets.pl, suggestion.pl, etc.) and confirm that the browser reports no JavaScript errors. Signed-off-by: Jonathan Druart Signed-off-by: Chris Cormack Signed-off-by: Galen Charlton --- koha-tmpl/intranet-tmpl/prog/en/js/acq.js | 320 +++++++++++----------- 1 file changed, 160 insertions(+), 160 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js index 067cd08642..b9039ea9a6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js @@ -60,181 +60,181 @@ function isNum(v,maybenull) { //======================================================================= // Functions for drag-and-drop functionality +if( typeof(YAHOO) === "object"){ + (function() { -(function() { + var Dom = YAHOO.util.Dom; + var Event = YAHOO.util.Event; + var DDM = YAHOO.util.DragDropMgr; -var Dom = YAHOO.util.Dom; -var Event = YAHOO.util.Event; -var DDM = YAHOO.util.DragDropMgr; - -DDApp = { - init: function() { - var uls = document.getElementsByTagName('ul'); - var i,j; - var ddtarget; - for (i=0; i this.lastY) { + this.goingUp = false; + } + this.lastY = y; + }, + + onDragOver: function(e, id) { + + var srcEl = this.getEl(); + var destEl = Dom.get(id); + + // We are only concerned with list items, we ignore the dragover + // notifications for the list. + if (destEl.nodeName.toLowerCase() == "li") { + var orig_p = srcEl.parentNode; + var p = destEl.parentNode; + + if (this.goingUp) { + p.insertBefore(srcEl, destEl); // insert above + } else { + p.insertBefore(srcEl, destEl.nextSibling); // insert below + } - // Check to see if we are over the source element's location. We will - // append to the bottom of the list once we are sure it was a drop in - // the negative space (the area of the list without any list items) - if (!region.intersect(pt)) { - var destEl = Dom.get(id); - var destDD = DDM.getDDById(id); - destEl.appendChild(this.getEl()); - destDD.isEmpty = false; DDM.refreshCache(); } } - }, - - onDrag: function(e) { - - // Keep track of the direction of the drag for use during onDragOver - var y = Event.getPageY(e); - - if (y < this.lastY) { - this.goingUp = true; - } else if (y > this.lastY) { - this.goingUp = false; - } - this.lastY = y; - }, - - onDragOver: function(e, id) { - - var srcEl = this.getEl(); - var destEl = Dom.get(id); - - // We are only concerned with list items, we ignore the dragover - // notifications for the list. - if (destEl.nodeName.toLowerCase() == "li") { - var orig_p = srcEl.parentNode; - var p = destEl.parentNode; - - if (this.goingUp) { - p.insertBefore(srcEl, destEl); // insert above - } else { - p.insertBefore(srcEl, destEl.nextSibling); // insert below - } - - DDM.refreshCache(); - } - } -}); -})(); - + }); + })(); +}