From cc288c7f6f05533efbb741f180a2e982200e933f Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Wed, 17 Nov 2010 15:46:33 -0500 Subject: [PATCH] Move general jquery-safe javascript to it's own file --- horde/js/horde-jquery.js | 79 ++++++++++++++++++++++++++++++++ kronolith/js/mobile.js | 78 +------------------------------ kronolith/templates/mobile/head.html.php | 1 + 3 files changed, 81 insertions(+), 77 deletions(-) create mode 100644 horde/js/horde-jquery.js diff --git a/horde/js/horde-jquery.js b/horde/js/horde-jquery.js new file mode 100644 index 000000000..324fc2d94 --- /dev/null +++ b/horde/js/horde-jquery.js @@ -0,0 +1,79 @@ +/** + * Some general javascript code, prototypejs free, safe to use with jquery. + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + */ +Date.prototype.getRealWeek = function() +{ + var monday = this; + if (monday.getDay() < 1) { + monday = monday.clone().next().monday(); + } + return monday.getWeek(); +}; + +/** + * Moves a date to the end of the corresponding week. + * + * @return Date The same Date object, now pointing to the end of the week. + */ +Date.prototype.moveToEndOfWeek = function(weekStart) +{ + var weekEndDay = weekStart + 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. + */ +Date.prototype.moveToBeginOfWeek = function(weekStart) +{ + if (this.getDay() != weekStart) { + this.moveToDayOfWeek(weekStart, -1); + } + return this; +}; + +/** + * Format date and time to be passed around as a short url parameter, + * cache id, etc. + * + * @return string Date and time. + */ +Date.prototype.dateString = function() +{ + return this.toString('yyyyMMdd'); +}; + +Number.prototype.toPaddedString = function(len,pad) +{ + len=(len) ? Number(len) : 2; + if (isNaN(len)) { + return null; + } + var dflt = (isNaN(this.toString())) ? " " : "0"; + pad = (pad) ? pad.toString().substr(0,1) : dflt; + var str = this.toString(); + if (dflt=="0") { + while (str.length < len) { + str=pad+str; + } + } else { + while (str.length < len) { + str += pad; + } + } + return str; +}; + +String.prototype.toPaddedString = Number.prototype.toPaddedString; \ No newline at end of file diff --git a/kronolith/js/mobile.js b/kronolith/js/mobile.js index da75ff485..9d5fb7c4e 100644 --- a/kronolith/js/mobile.js +++ b/kronolith/js/mobile.js @@ -615,80 +615,4 @@ }; // JQuery Mobile setup -$(KronolithMobile.onDocumentReady); - -// Some Date extensions from horde.js that can't be included because of it's -// use of prototype.js -Date.prototype.getRealWeek = function() -{ - var monday = this; - if (monday.getDay() < 1) { - monday = monday.clone().next().monday(); - } - return monday.getWeek(); -}; - -/** - * Moves a date to the end of the corresponding week. - * - * @return Date The same Date object, now pointing to the end of the week. - */ -Date.prototype.moveToEndOfWeek = function(weekStart) -{ - var weekEndDay = weekStart + 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. - */ -Date.prototype.moveToBeginOfWeek = function(weekStart) -{ - if (this.getDay() != weekStart) { - this.moveToDayOfWeek(weekStart, -1); - } - return this; -}; - -/** - * Format date and time to be passed around as a short url parameter, - * cache id, etc. - * - * @return string Date and time. - */ -Date.prototype.dateString = function() -{ - return this.toString('yyyyMMdd'); -}; - -Number.prototype.toPaddedString = function(len,pad) -{ - len=(len) ? Number(len) : 2; - if (isNaN(len)) { - return null; - } - var dflt = (isNaN(this.toString())) ? " " : "0"; - pad = (pad) ? pad.toString().substr(0,1) : dflt; - var str = this.toString(); - if (dflt=="0") { - while (str.length < len) { - str=pad+str; - } - } else { - while (str.length < len) { - str += pad; - } - } - return str; -}; - -String.prototype.toPaddedString = Number.prototype.toPaddedString; \ No newline at end of file +$(KronolithMobile.onDocumentReady); \ No newline at end of file diff --git a/kronolith/templates/mobile/head.html.php b/kronolith/templates/mobile/head.html.php index 261e41fb6..b151e9605 100644 --- a/kronolith/templates/mobile/head.html.php +++ b/kronolith/templates/mobile/head.html.php @@ -1,4 +1,5 @@ + -- 2.11.0