}
};
-
-/* 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]);
- }
- });
- }
-});
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);
};
-/* 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));