Skip to content

Commit

Permalink
reintrudoces hasChaged attribute
Browse files Browse the repository at this point in the history
in oder to fix event listeners on events other than tick
  • Loading branch information
meodai committed Apr 7, 2015
1 parent d6afab2 commit 0498a2e
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions ticktack.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
callbacks = {};
registeredCallbacks = [];


/**
* capitalize the fist letter of a string
* @param {string} string
* @returns {string} capitalized string
*/
capitalize = function (string) {
return string.charAt(0).toUpperCase() + string.slice(1);
};

/**
* runCallbacks : loops callbacks and calls them
* @param {Object} obj object produced by getTimeObject, will be passed to the callback
Expand Down Expand Up @@ -101,25 +111,16 @@
}
];

/**
* capitalize the fist letter of a string
* @param {string} string
* @returns {string} capitalized string
*/
capitalize = function (string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}

/**
* getTimeObject: produces an object containing all values and relative values for every digit in Date()
* @param {Object} previousDigits object previously obtained by getTimeObject to know what values did change
* @returns {Object} value and progress for every digit in Date()
*/
getTimeObject = function (previousDigits) {
var now, timeInMilliseconds;

now = new Date();
timeInMilliseconds = now.getTime() - now.getTimezoneOffset() * 60000;
previousDigits = previousDigits || {};

return (function () {
var digits, cache, getDate;
Expand All @@ -128,7 +129,7 @@
digits = {};

units.forEach(function (propertyDefinition) {
var property, functionName, value;
var property, functionName, value, hasChanged;
property = propertyDefinition.property;
functionName = 'get' + capitalize(property);

Expand All @@ -139,13 +140,16 @@

value = now[propertyDefinition.dateMethod]();

hasChanged = !previousDigits[property] || previousDigits[property].value !== value;

return cache[property] = {
value: value,
progress: propertyDefinition.progressFunction(
value,
now,
timeInMilliseconds
)
),
hasChanged: hasChanged
}
};

Expand Down

0 comments on commit 0498a2e

Please sign in to comment.