My favorites
▼
|
Sign in
epiclock
jQuery Plugin to create and manage Javascript Clocks
Project Home
Downloads
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
12
attachment: parser.epiclock.js
(1.6 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* dateParser - For use with epiClock 2.1
* http://code.google.com/p/epiclock
*
* Copyright (c) 2008 Eric Garside (http://eric.garside.name)
* Dual licensed under:
* MIT: http://www.opensource.org/licenses/mit-license.php
* GPLv3: http://www.opensource.org/licenses/gpl-3.0.html
*/
function dateParser(format, ec){
var format = format.split(''),
buffer = '',
isBuffering = false,
x = '';
$.each(format, function(){
x = this+'';
switch (x){
case ' ':
buffer += x;
break;
case '{':
isBuffering = true;
break;
case '}':
isBuffering = false;
break;
default:
// If we're buffering, this is label text
if (isBuffering) buffer += x;
// If it's a special character, it will be span updated
else if (Date.prototype[x] || ec[x]) {
buffer += ($.isFunction(ec.now[x]) ? ec.now[x]() : ec[x]()) + ''
}
// If it's anything else, it's a single char label seperator
else
buffer += x;
break;
}
});
return buffer;
}
/* Example Usage
------------------------- */
$(function(){
// The first argument to dateparse is a string that uses the same formatting
// which epiClock uses to render the clock. Only, instead of generating
// DOMElements, this merely just parses the clock into the provided format
// and returns a string representing the current value of the clock.
// The following example is for a countdown clock, but really, any clock
// format will work. Just grab the jQuery Element which you used to create
// the clock, and call data('epiClock') on it to get the proper object
// reference.
dateParse('[x:i:s]', jQuery('#clock').data('epiClock'));
});
Powered by
Google Project Hosting