From 0fa706bef844336f48d1c6dc9418c88dafb85b34 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Wed, 29 Jul 2009 16:50:00 +0200 Subject: [PATCH] Re-add horde.js as a container of commonly used prototype extensions. --- imp/js/src/DimpCore.js | 71 ------------------------ imp/lib/DIMP.php | 1 + kronolith/js/src/kronolith.js | 126 ++---------------------------------------- kronolith/lib/Kronolith.php | 1 + 4 files changed, 6 insertions(+), 193 deletions(-) diff --git a/imp/js/src/DimpCore.js b/imp/js/src/DimpCore.js index df6624d8a..471995aed 100644 --- a/imp/js/src/DimpCore.js +++ b/imp/js/src/DimpCore.js @@ -469,74 +469,3 @@ var DimpCore = { } }; - -/* Helper methods for setting/getting element text without mucking - * around with multiple TextNodes. */ -Element.addMethods({ - setText: function(element, text) - { - var t = 0; - $A(element.childNodes).each(function(node) { - if (node.nodeType == 3) { - if (t++) { - Element.remove(node); - } else { - node.nodeValue = text; - } - } - }); - - if (!t) { - $(element).insert(text); - } - }, - - getText: function(element, recursive) - { - var text = ''; - $A(element.childNodes).each(function(node) { - if (node.nodeType == 3) { - text += node.nodeValue; - } else if (recursive && node.hasChildNodes()) { - text += $(node).getText(true); - } - }); - return text; - } -}); - -/* Create some utility functions. */ -Object.extend(Array.prototype, { - // Need our own diff() function because prototypejs's without() function - // does not handle array input. - diff: function(values) - { - return this.select(function(value) { - return !values.include(value); - }); - }, - numericSort: function() - { - return this.collect(Number).sort(function(a,b) { - return (a > b) ? 1 : ((a < b) ? -1 : 0); - }); - } -}); - -Object.extend(String.prototype, { - // We define our own version of evalScripts() to make sure that all - // scripts are running in the same scope and that all functions are - // defined in the global scope. This is not the case when using - // prototype's evalScripts(). - evalScripts: function() - { - var re = /function\s+([^\s(]+)/g; - this.extractScripts().each(function(s) { - var func; - eval(s); - while (func = re.exec(s)) { - window[func[1]] = eval(func[1]); - } - }); - } -}); diff --git a/imp/lib/DIMP.php b/imp/lib/DIMP.php index 120819b91..59590099d 100644 --- a/imp/lib/DIMP.php +++ b/imp/lib/DIMP.php @@ -64,6 +64,7 @@ class DIMP // Need to include script files before we start output Horde::addScriptFile('prototype.js', 'horde', true); Horde::addScriptFile('effects.js', 'horde', true); + Horde::addScriptFile('horde.js', 'horde', true); // ContextSensitive must be loaded before DimpCore. while (list($key, $val) = each($scripts)) { diff --git a/kronolith/js/src/kronolith.js b/kronolith/js/src/kronolith.js index 754351347..9b04092f8 100644 --- a/kronolith/js/src/kronolith.js +++ b/kronolith/js/src/kronolith.js @@ -1497,14 +1497,14 @@ KronolithCore = { switch (view) { case 'week': - start.moveToBeginOfWeek(); - end.moveToEndOfWeek(); + start.moveToBeginOfWeek(Kronolith.conf.week_start); + end.moveToEndOfWeek(Kronolith.conf.week_start); break; case 'month': start.setDate(1); - start.moveToBeginOfWeek(); + start.moveToBeginOfWeek(Kronolith.conf.week_start); end.moveToLastDayOfMonth(); - end.moveToEndOfWeek(); + end.moveToEndOfWeek(Kronolith.conf.week_start); break; case 'year': start.setDate(1); @@ -2204,124 +2204,6 @@ KronolithCore = { }; -/* Helper methods for setting/getting element text without mucking - * around with multiple TextNodes. */ -Element.addMethods({ - setText: function(element, text) - { - var t = 0; - $A(element.childNodes).each(function(node) { - if (node.nodeType == 3) { - if (t++) { - Element.remove(node); - } else { - node.nodeValue = text; - } - } - }); - - if (!t) { - $(element).insert(text); - } - - return element; - }, - - getText: function(element, recursive) - { - var text = ''; - $A(element.childNodes).each(function(node) { - if (node.nodeType == 3) { - text += node.nodeValue; - } else if (recursive && node.hasChildNodes()) { - text += $(node).getText(true); - } - }); - return text; - } -}); - -/* Create some utility functions. */ -Object.extend(Array.prototype, { - // Need our own diff() function because prototypejs's without() function - // does not handle array input. - diff: function(values) - { - return this.select(function(value) { - return !values.include(value); - }); - }, - numericSort: function() - { - return this.collect(Number).sort(function(a,b) { - return (a > b) ? 1 : ((a < b) ? -1 : 0); - }); - } -}); - -Object.extend(String.prototype, { - // We define our own version of evalScripts() to make sure that all - // scripts are running in the same scope and that all functions are - // defined in the global scope. This is not the case when using - // prototype's evalScripts(). - evalScripts: function() - { - var re = /function\s+([^\s(]+)/g; - this.extractScripts().each(function(s) { - var func; - eval(s); - while (func = re.exec(s)) { - window[func[1]] = eval(func[1]); - } - }); - } -}); - -Object.extend(Date.prototype, { - /** - * Moves a date to the end of the corresponding week. - * - * @return Date The same Date object, now pointing to the end of the week. - */ - moveToEndOfWeek: function() - { - var weekEndDay = Kronolith.conf.week_start + 6; - if (weekEndDay > 6) { - weekEndDay -= 7; - } - if (this.getDay() != weekEndDay) { - this.moveToDayOfWeek(weekEndDay, 1); - } - return this; - }, - - /** - * Moves a date to the begin of the corresponding week. - * - * @return Date The same Date object, now pointing to the begin of the - * week. - */ - moveToBeginOfWeek: function() - { - if (this.getDay() != Kronolith.conf.week_start) { - this.moveToDayOfWeek(Kronolith.conf.week_start, -1); - } - return this; - }, - - /** - * Format date and time to be passed around as a short url parameter, - * cache id, etc. - * - * @return string Date and time. - */ - dateString: function() - { - return this.toString('yyyyMMdd'); - } - -}); - /* Initialize global event handlers. */ document.observe('dom:loaded', KronolithCore.onDomLoad.bind(KronolithCore)); Event.observe(window, 'resize', KronolithCore.onResize.bind(KronolithCore)); diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 51af8640b..02960397a 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -71,6 +71,7 @@ class Kronolith // Need to include script files before we start output Horde::addScriptFile('prototype.js', 'horde', true); Horde::addScriptFile('effects.js', 'horde', true); + Horde::addScriptFile('horde.js', 'horde', true); Horde::addScriptFile('dragdrop2.js', 'horde', true); Horde::addScriptFile('Growler.js', 'horde', true); -- 2.11.0