Index: lams_central/web/css/jquery.countdown.css =================================================================== diff -u --- lams_central/web/css/jquery.countdown.css (revision 0) +++ lams_central/web/css/jquery.countdown.css (revision b652cf47563185ee684068696c5af1bb96f8b0fa) @@ -0,0 +1,47 @@ +/* jQuery Countdown styles */ +.hasCountdown { + border: 1px solid #ccc; + background-color: #eee; +} +.countdown_rtl { + direction: rtl; +} +.countdown_holding div { + background-color: #ccc; +} +.countdown_row { + clear: both; + width: 100%; + text-align: center; +} +.countdown_show1 div { + width: 100%; +} +.countdown_show2 div { + width: 50%; +} +.countdown_show3 div { + width: 33%; +} +.countdown_show4 div { + width: 25%; +} +.countdown_show5 div { + width: 20%; +} +.countdown_show6 div { + width: 16%; +} +.countdown_show7 div { + width: 14%; +} +.countdown_section { + float: left; + font-size: 75% +} +.countdown_amount { + font-size: 200%; +} +.countdown_descr { + width: 100%; +} Index: lams_central/web/includes/javascript/jquery.countdown.js =================================================================== diff -u --- lams_central/web/includes/javascript/jquery.countdown.js (revision 0) +++ lams_central/web/includes/javascript/jquery.countdown.js (revision b652cf47563185ee684068696c5af1bb96f8b0fa) @@ -0,0 +1,505 @@ +/* http://keith-wood.name/countdown.html + Countdown for jQuery v1.4.3. + Written by Keith Wood (kbwood@virginbroadband.com.au) January 2008. + Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and + MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. + Please attribute the author if you use it. */ + +/* Display a countdown timer. + Attach it with options like: + $('div selector').countdown( + {until: new Date(2009, 1 - 1, 1, 0, 0, 0), onExpiry: happyNewYear}); */ + +(function($) { // Hide scope, no $ conflict + +/* Countdown manager. */ +function Countdown() { + this.regional = []; // Available regional settings, indexed by language code + this.regional[''] = { // Default regional settings + // The display texts for the counters + labels: ['Years', 'Months', 'Weeks', 'Days', 'Hours', 'Minutes', 'Seconds'], + // The display texts for the counters if only one + labels1: ['Year', 'Month', 'Week', 'Day', 'Hour', 'Minute', 'Second'], + compactLabels: ['y', 'm', 'w', 'd'], // The compact texts for the counters + timeSeparator: ':', // Separator for time periods + isRTL: false // True for right-to-left languages, false for left-to-right + }; + this._defaults = { + format: 'dHMS', // Format for display - upper case for always, lower case only if non-zero, + // 'Y' years, 'O' months, 'W' weeks, 'D' days, 'H' hours, 'M' minutes, 'S' seconds + layout: '', // Build your own layout for the countdown + compact: false, // True to display in a compact format, false for an expanded one + description: '', // The description displayed for the countdown + expiryUrl: null, // A URL to load upon expiry, replacing the current page + alwaysExpire: false, // True to trigger onExpiry even if never counted down + onExpiry: null, // Callback when the countdown expires - + // receives no parameters and 'this' is the containing division + onTick: null, // Callback when the countdown is updated - + // receives int[7] being the breakdown by period (based on format) + // and 'this' is the containing division + serverTime: null // The current time on the server, to calculate an offset for other time zones + }; + $.extend(this._defaults, this.regional['']); +} + +var PROP_NAME = 'countdown'; + +var Y = 0; // Years +var O = 1; // Months +var W = 2; // Weeks +var D = 3; // Days +var H = 4; // Hours +var M = 5; // Minutes +var S = 6; // Seconds + +$.extend(Countdown.prototype, { + /* Class name added to elements to indicate already configured with countdown. */ + markerClassName: 'hasCountdown', + + /* Override the default settings for all instances of the countdown widget. + @param options (object) the new settings to use as defaults */ + setDefaults: function(options) { + this._resetExtraLabels(this._defaults, options); + extendRemove(this._defaults, options || {}); + }, + + /* Attach the countdown widget to a div. + @param target (element) the containing division + @param options (object) the initial settings for the countdown */ + _attachCountdown: function(target, options) { + target = $(target); + if (target.hasClass(this.markerClassName)) { + return; + } + target.addClass(this.markerClassName); + var inst = {}; + inst.options = $.extend({}, options); + inst._periods = [0, 0, 0, 0, 0, 0, 0]; + this._adjustSettings(inst); + $.data(target[0], PROP_NAME, inst); + this._updateCountdown(target, inst); + }, + + /* Redisplay the countdown with an updated display. + @param target (jQuery) the containing division + @param inst (object) the current settings for this instance */ + _updateCountdown: function(target, inst) { + var target = $(target); + inst = inst || $.data(target[0], PROP_NAME); + if (!inst) { + return; + } + target.html(this._generateHTML(inst)); + target[(this._get(inst, 'isRTL') ? 'add' : 'remove') + 'Class']('countdown_rtl'); + var onTick = this._get(inst, 'onTick'); + if (onTick) { + onTick.apply(target[0], [inst._hold != 'lap' ? inst._periods : + this._calculatePeriods(inst, inst._show, new Date())]); + } + var expired = inst._hold != 'pause' && + (inst._since ? inst._now.getTime() <= inst._since.getTime() : + inst._now.getTime() >= inst._until.getTime()); + if (expired) { + if (inst._timer || this._get(inst, 'alwaysExpire')) { + var onExpiry = this._get(inst, 'onExpiry'); + if (onExpiry) { + onExpiry.apply(target[0], []); + } + var expiryUrl = this._get(inst, 'expiryUrl'); + if (expiryUrl) { + window.location = expiryUrl; + } + } + inst._timer = null; + } + else if (inst._hold == 'pause') { + inst._timer = null; + } + else { + var format = this._get(inst, 'format'); + inst._timer = setTimeout(function() { $.countdown._updateCountdown(target); }, + (format.match('s|S') ? 1 : (format.match('m|M') ? 30 : 600)) * 980); // just under the full time + } + $.data(target[0], PROP_NAME, inst); + }, + + /* Reconfigure the settings for a countdown div. + @param target (element) the containing division + @param options (object) the new settings for the countdown */ + _changeCountdown: function(target, options) { + var inst = $.data(target, PROP_NAME); + if (inst) { + this._resetExtraLabels(inst.options, options); + extendRemove(inst.options, options || {}); + this._adjustSettings(inst); + $.data(target, PROP_NAME, inst); + this._updateCountdown(target, inst); + } + }, + + /* Reset any extra labelsn and compactLabelsn entries if changing labels. + @param base (object) the options to be updated + @param options (object) the new option values */ + _resetExtraLabels: function(base, options) { + var changingLabels = false; + for (var n in options) { + if (n.match(/[Ll]abels/)) { + changingLabels = true; + break; + } + } + if (changingLabels) { + for (var n in base) { // Remove custom numbered labels + if (n.match(/[Ll]abels[0-9]/)) { + base[n] = null; + } + } + } + }, + + /* Remove the countdown widget from a div. + @param target (element) the containing division */ + _destroyCountdown: function(target) { + target = $(target); + if (!target.hasClass(this.markerClassName)) { + return; + } + target.removeClass(this.markerClassName).empty(); + var inst = $.data(target[0], PROP_NAME); + if (inst._timer) { + clearTimeout(inst._timer); + } + $.removeData(target[0], PROP_NAME); + }, + + /* Pause a countdown widget at the current time. + Stop it running but remember and display the current time. + @param target (element) the containing division */ + _pauseCountdown: function(target) { + this._hold(target, 'pause'); + }, + + /* Pause a countdown widget at the current time. + Stop the display but keep the countdown running. + @param target (element) the containing division */ + _lapCountdown: function(target) { + this._hold(target, 'lap'); + }, + + /* Resume a paused countdown widget. + @param target (element) the containing division */ + _resumeCountdown: function(target) { + this._hold(target, null); + }, + + /* Pause or resume a countdown widget. + @param target (element) the containing division + @param hold (string) the new hold setting */ + _hold: function(target, hold) { + var inst = $.data(target, PROP_NAME); + if (inst) { + if (inst._hold == 'pause' && !hold) { + inst._periods = inst._savePeriods; + var sign = (inst._since ? '-' : '+'); + inst[inst._since ? '_since' : '_until'] = + this._determineTime(sign + inst._periods[0] + 'Y' + + sign + inst._periods[1] + 'O' + sign + inst._periods[2] + 'W' + + sign + inst._periods[3] + 'D' + sign + inst._periods[4] + 'H' + + sign + inst._periods[5] + 'M' + sign + inst._periods[6] + 'S'); + } + inst._hold = hold; + inst._savePeriods = (hold == 'pause' ? inst._periods : null); + $.data(target, PROP_NAME, inst); + this._updateCountdown(target, inst); + } + }, + + /* Return the current time periods. + @param target (element) the containing division + @return (number[7]) the current periods for the countdown */ + _getTimesCountdown: function(target) { + var inst = $.data(target, PROP_NAME); + return (!inst ? null : (!inst._hold ? inst._periods : + this._calculatePeriods(inst, inst._show, new Date()))); + }, + + /* Get a setting value, defaulting if necessary. + @param inst (object) the current settings for this instance + @param name (string) the name of the required setting + @return (any) the setting's value or a default if not overridden */ + _get: function(inst, name) { + return (inst.options[name] != null ? + inst.options[name] : $.countdown._defaults[name]); + }, + + /* Calculate interal settings for an instance. + @param inst (object) the current settings for this instance */ + _adjustSettings: function(inst) { + var now = new Date(); + var serverTime = this._get(inst, 'serverTime'); + inst._offset = (serverTime ? serverTime.getTime() - now.getTime() : 0); + inst._since = this._get(inst, 'since'); + if (inst._since) { + inst._since = this._determineTime(inst._since, null); + } + inst._until = this._determineTime(this._get(inst, 'until'), now); + inst._show = this._determineShow(inst); + }, + + /* A time may be specified as an exact value or a relative one. + @param setting (string or number or Date) - the date/time value + as a relative or absolute value + @param defaultTime (Date) the date/time to use if no other is supplied + @return (Date) the corresponding date/time */ + _determineTime: function(setting, defaultTime) { + var offsetNumeric = function(offset) { // e.g. +300, -2 + var time = new Date(); + time.setTime(time.getTime() + offset * 1000); + return time; + }; + var getDaysInMonth = function(year, month) { + return 32 - new Date(year, month, 32).getDate(); + }; + var offsetString = function(offset) { // e.g. '+2d', '-4w', '+3h +30m' + var time = new Date(); + var year = time.getFullYear(); + var month = time.getMonth(); + var day = time.getDate(); + var hour = time.getHours(); + var minute = time.getMinutes(); + var second = time.getSeconds(); + var pattern = /([+-]?[0-9]+)\s*(s|S|m|M|h|H|d|D|w|W|o|O|y|Y)?/g; + var matches = pattern.exec(offset); + while (matches) { + switch (matches[2] || 's') { + case 's' : case 'S' : + second += parseInt(matches[1], 10); break; + case 'm' : case 'M' : + minute += parseInt(matches[1], 10); break; + case 'h' : case 'H' : + hour += parseInt(matches[1], 10); break; + case 'd' : case 'D' : + day += parseInt(matches[1], 10); break; + case 'w' : case 'W' : + day += parseInt(matches[1], 10) * 7; break; + case 'o' : case 'O' : + month += parseInt(matches[1], 10); + day = Math.min(day, getDaysInMonth(year, month)); + break; + case 'y': case 'Y' : + year += parseInt(matches[1], 10); + day = Math.min(day, getDaysInMonth(year, month)); + break; + } + matches = pattern.exec(offset); + } + time = new Date(year, month, day, hour, minute, second, 0); + return time; + }; + var time = (setting == null ? defaultTime : + (typeof setting == 'string' ? offsetString(setting) : + (typeof setting == 'number' ? offsetNumeric(setting) : setting))); + if (time) time.setMilliseconds(0); + return time; + }, + + /* Generate the HTML to display the countdown widget. + @param inst (object) the current settings for this instance + @return (string) the new HTML for the countdown display */ + _generateHTML: function(inst) { + // Determine what to show + inst._periods = periods = (inst._hold ? inst._periods : + this._calculatePeriods(inst, inst._show, new Date())); + // Show all 'asNeeded' after first non-zero value + var shownNonZero = false; + var showCount = 0; + for (var period = 0; period < inst._show.length; period++) { + shownNonZero |= (inst._show[period] == '?' && periods[period] > 0); + inst._show[period] = (inst._show[period] == '?' && !shownNonZero ? null : inst._show[period]); + showCount += (inst._show[period] ? 1 : 0); + } + var compact = this._get(inst, 'compact'); + var layout = this._get(inst, 'layout'); + var labels = (compact ? this._get(inst, 'compactLabels') : this._get(inst, 'labels')); + var timeSeparator = this._get(inst, 'timeSeparator'); + var description = this._get(inst, 'description') || ''; + var twoDigits = function(value) { + return (value < 10 ? '0' : '') + value; + }; + var showCompact = function(period) { + var labelsNum = $.countdown._get(inst, 'compactLabels' + periods[period]); + return (inst._show[period] ? periods[period] + + (labelsNum ? labelsNum[period] : labels[period]) + ' ' : ''); + }; + var showFull = function(period) { + var labelsNum = $.countdown._get(inst, 'labels' + periods[period]); + return (inst._show[period] ? + '