2 jQuery utils - @VERSION
3 http://code.google.com/p/jquery-utils/
5 (c) Maxime Haineault <haineault@gmail.com>
8 MIT License (http://www.opensource.org/licenses/mit-license.php
13 $.extend($.expr[':'], {
14 // case insensitive version of :contains
15 icontains: function(a,i,m){return (a.textContent||a.innerText||jQuery(a).text()||"").toLowerCase().indexOf(m[3].toLowerCase())>=0;}
19 getText: function() { return $(this).text(); },
20 parseInt: function(v){ return parseInt(v, 10); }
25 // Returns a range object
26 // Author: Matthias Miller
27 // Site: http://blog.outofhanwell.com/2006/03/29/javascript-range-function/
29 if (!arguments.length) { return []; }
31 if (arguments.length == 1) {
37 // default step to 1 if it's zero or undefined
40 step = arguments[2] || 1;
42 // convert negative steps to positive and reverse min/max
43 if (step < 0 && min >= max) {
48 min += ((max-min) % step);
51 for (var i = min; i <= max; i += step) { a.push(i); }
55 // Taken from ui.core.js.
56 // Why are you keeping this gem for yourself guys ? :|
58 BACKSPACE: 8, CAPS_LOCK: 20, COMMA: 188, CONTROL: 17, DELETE: 46, DOWN: 40,
59 END: 35, ENTER: 13, ESCAPE: 27, HOME: 36, INSERT: 45, LEFT: 37,
60 NUMPAD_ADD: 107, NUMPAD_DECIMAL: 110, NUMPAD_DIVIDE: 111, NUMPAD_ENTER: 108,
61 NUMPAD_MULTIPLY: 106, NUMPAD_SUBTRACT: 109, PAGE_DOWN: 34, PAGE_UP: 33,
62 PERIOD: 190, RIGHT: 39, SHIFT: 16, SPACE: 32, TAB: 9, UP: 38
65 // Takes a keyboard event and return true if the keycode match the specified keycode
66 keyIs: function(k, e) {
67 return parseInt($.keyCode[k.toUpperCase()], 10) == parseInt((typeof(e) == 'number' )? e: e.keyCode, 10);
70 // Returns the key of an array
73 for (k in arr) { o.push(k); }
77 // Redirect to a specified url
78 redirect: function(url) {
79 window.location.href = url;
83 // Stop event shorthand
84 stop: function(e, preventDefault, stopPropagation) {
85 if (preventDefault) { e.preventDefault(); }
86 if (stopPropagation) { e.stopPropagation(); }
87 return preventDefault && false || true;
90 // Returns the basename of a path
91 basename: function(path) {
92 var t = path.split('/');
93 return t[t.length] === '' && s || t.slice(0, t.length).join('/');
96 // Returns the filename of a path
97 filename: function(path) {
98 return path.split('/').pop();
101 // Returns a formated file size
102 filesizeformat: function(bytes, suffixes){
103 var b = parseInt(bytes, 10);
104 var s = suffixes || ['byte', 'bytes', 'KB', 'MB', 'GB'];
105 if (isNaN(b) || b === 0) { return '0 ' + s[0]; }
106 if (b == 1) { return '1 ' + s[0]; }
107 if (b < 1024) { return b.toFixed(2) + ' ' + s[1]; }
108 if (b < 1048576) { return (b / 1024).toFixed(2) + ' ' + s[2]; }
109 if (b < 1073741824) { return (b / 1048576).toFixed(2) + ' '+ s[3]; }
110 else { return (b / 1073741824).toFixed(2) + ' '+ s[4]; }
113 fileExtension: function(s) {
114 var tokens = s.split('.');
115 return tokens[tokens.length-1] || false;
118 // Returns true if an object is a String
119 isString: function(o) {
120 return typeof(o) == 'string' && true || false;
123 // Returns true if an object is a RegExp
124 isRegExp: function(o) {
125 return o && o.constructor.toString().indexOf('RegExp()') != -1 || false;
128 isObject: function(o) {
129 return (typeof(o) == 'object');
132 // Convert input to currency (two decimal fixed number)
133 toCurrency: function(i) {
134 i = parseFloat(i, 10).toFixed(2);
135 return (i=='NaN') ? '0.00' : i;
138 /*--------------------------------------------------------------------
139 * javascript method: "pxToEm"
141 Scott Jehl (scott@filamentgroup.com)
142 Maggie Wachs (maggie@filamentgroup.com)
143 http://www.filamentgroup.com
145 * Copyright (c) 2008 Filament Group
146 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
148 * Description: pxToEm converts a pixel value to ems depending on inherited font size.
149 * Article: http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/
150 * Demo: http://www.filamentgroup.com/examples/pxToEm/
153 scope: string or jQuery selector for font-size scoping
154 reverse: Boolean, true reverses the conversion to em-px
155 * Dependencies: jQuery library
156 * Usage Example: myPixelValue.pxToEm(); or myPixelValue.pxToEm({'scope':'#navigation', reverse: true});
158 * Version: 2.1, 18.12.2008
160 * 08.02.2007 initial Version 1.0
161 * 08.01.2008 - fixed font-size calculation for IE
162 * 18.12.2008 - removed native object prototyping to stay in jQuery's spirit, jsLinted (Maxime Haineault <haineault@gmail.com>)
163 --------------------------------------------------------------------*/
165 pxToEm: function(i, settings){
167 settings = jQuery.extend({
172 var pxVal = (i === '') ? 0 : parseFloat(i);
174 var getWindowWidth = function(){
175 var de = document.documentElement;
176 return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
179 /* When a percentage-based font-size is set on the body, IE returns that percent of the window width as the font-size.
180 For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size.
181 When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size)
182 to get an accurate em value. */
184 if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
185 var calcFontSize = function(){
186 return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
188 scopeVal = calcFontSize();
190 else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); }
192 var result = (settings.reverse === true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
199 try { return $(this).get(0).nodeName.toLowerCase(); }
200 catch(e) { return false; }
202 // Select a text range in a textarea
203 selectRange: function(start, end){
204 // use only the first one since only one input can be focused
205 if ($(this).get(0).createTextRange) {
206 var range = $(this).get(0).createTextRange();
207 range.collapse(true);
208 range.moveEnd('character', end);
209 range.moveStart('character', start);
212 else if ($(this).get(0).setSelectionRange) {
213 $(this).bind('focus', function(e){
215 }).get(0).setSelectionRange(start, end);
220 /*--------------------------------------------------------------------
221 * JQuery Plugin: "EqualHeights"
222 * by: Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
224 * Copyright (c) 2008 Filament Group
225 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
227 * Description: Compares the heights or widths of the top-level children of a provided element
228 and sets their min-height to the tallest height (or width to widest width). Sets in em units
229 by default if pxToEm() method is available.
230 * Dependencies: jQuery library, pxToEm method (article:
231 http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)
232 * Usage Example: $(element).equalHeights();
233 Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
234 * Version: 2.1, 18.12.2008
236 * Note: Changed pxToEm call to call $.pxToEm instead, jsLinted (Maxime Haineault <haineault@gmail.com>)
237 --------------------------------------------------------------------*/
239 equalHeights: function(px){
240 $(this).each(function(){
241 var currentTallest = 0;
242 $(this).children().each(function(i){
243 if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
245 if (!px || !$.pxToEm) { currentTallest = $.pxToEm(currentTallest); } //use ems unless px is specified
246 // for ie6, set height since min-height isn't supported
247 if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
248 $(this).children().css({'min-height': currentTallest});
253 // Copyright (c) 2009 James Padolsey
254 // http://james.padolsey.com/javascript/jquery-delay-plugin/
255 delay: function(time, callback){
256 jQuery.fx.step.delay = function(){};
257 return this.animate({delay:1}, time, callback);
264 http://code.google.com/p/jquery-utils/
266 (c) Maxime Haineault <haineault@gmail.com>
269 MIT License (http://www.opensource.org/licenses/mit-license.php)
271 Implementation of Python3K advanced string formatting
272 http://www.python.org/dev/peps/pep-3101/
274 Documentation: http://code.google.com/p/jquery-utils/wiki/StringFormat
280 // tries to translate any objects type into string gracefully
282 switch(this.__getType(i)) {
283 case 'array':case 'date':case 'number':
285 case 'object': // Thanks to Richard Paul Lewis for the fix
288 for(var x=0;x<l;x++) {
289 o.push(x+': '+this.__repr(i[x]));
298 // like typeof but less vague
299 __getType: function(i) {
300 if (!i || !i.constructor) { return typeof(i); }
301 var match = i.constructor.toString().match(/Array|Number|String|Object|Date/);
302 return match && match[0].toLowerCase() || typeof(i);
304 // Jonas Raoni Soares Silva (http://jsfromhell.com/string/pad)
305 __pad: function(str, l, s, t){
308 if (l - str.length > 0) {
309 o = new Array(Math.ceil(l / p.length)).join(p).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2)) + str + p.substr(0, l - t);
313 __getInput: function(arg, args) {
314 var key = arg.getKey();
315 switch(this.__getType(args)){
316 case 'object': // Thanks to Jonathan Works for the patch
317 var keys = key.split('.');
319 for(var subkey = 0; subkey < keys.length; subkey++){
320 obj = obj[keys[subkey]];
322 if (typeof(obj) != 'undefined') {
323 if (strings.strConversion.__getType(obj) == 'array') {
324 return arg.getFormat().match(/\.\*/) && obj[1] || obj;
329 // TODO: try by numerical index
333 key = parseInt(key, 10);
334 if (arg.getFormat().match(/\.\*/) && typeof args[key+1] != 'undefined') { return args[key+1]; }
335 else if (typeof args[key] != 'undefined') { return args[key]; }
341 __formatToken: function(token, args) {
342 var arg = new Argument(token, args);
343 return strings.strConversion[arg.getFormat().slice(-1)](this.__getInput(arg, args), arg);
346 // Signed integer decimal.
347 d: function(input, arg){
348 var o = parseInt(input, 10); // enforce base 10
349 var p = arg.getPaddingLength();
350 if (p) { return this.__pad(o.toString(), p, arg.getPaddingString(), 0); }
353 // Signed integer decimal.
354 i: function(input, args){
355 return this.d(input, args);
358 o: function(input, arg){
359 var o = input.toString(8);
360 if (arg.isAlternate()) { o = this.__pad(o, o.length+1, '0', 0); }
361 return this.__pad(o, arg.getPaddingLength(), arg.getPaddingString(), 0);
364 u: function(input, args) {
365 return Math.abs(this.d(input, args));
367 // Unsigned hexadecimal (lowercase)
368 x: function(input, arg){
369 var o = parseInt(input, 10).toString(16);
370 o = this.__pad(o, arg.getPaddingLength(), arg.getPaddingString(),0);
371 return arg.isAlternate() ? '0x'+o : o;
373 // Unsigned hexadecimal (uppercase)
374 X: function(input, arg){
375 return this.x(input, arg).toUpperCase();
377 // Floating point exponential format (lowercase)
378 e: function(input, arg){
379 return parseFloat(input, 10).toExponential(arg.getPrecision());
381 // Floating point exponential format (uppercase)
382 E: function(input, arg){
383 return this.e(input, arg).toUpperCase();
385 // Floating point decimal format
386 f: function(input, arg){
387 return this.__pad(parseFloat(input, 10).toFixed(arg.getPrecision()), arg.getPaddingLength(), arg.getPaddingString(),0);
389 // Floating point decimal format (alias)
390 F: function(input, args){
391 return this.f(input, args);
393 // Floating point format. Uses exponential format if exponent is greater than -4 or less than precision, decimal format otherwise
394 g: function(input, arg){
395 var o = parseFloat(input, 10);
396 return (o.toString().length > 6) ? Math.round(o.toExponential(arg.getPrecision())): o;
398 // Floating point format. Uses exponential format if exponent is greater than -4 or less than precision, decimal format otherwise
399 G: function(input, args){
400 return this.g(input, args);
402 // Single character (accepts integer or single character string).
403 c: function(input, args) {
404 var match = input.match(/\w|\d/);
405 return match && match[0] || '';
407 // String (converts any JavaScript object to anotated format)
408 r: function(input, args) {
409 return this.__repr(input);
411 // String (converts any JavaScript object using object.toString())
412 s: function(input, args) {
413 return input.toString && input.toString() || ''+input;
417 format: function(str, args) {
423 var tmp = (str||'').split('');
424 for(start=0; start < tmp.length; start++) {
425 if (tmp[start] == '{' && tmp[start+1] !='{') {
426 end = str.indexOf('}', start);
427 token = tmp.slice(start+1, end).join('');
428 if (tmp[start-1] != '{' && tmp[end+1] != '}') {
429 var tokenArgs = (typeof arguments[1] != 'object')? arguments2Array(arguments, 2): args || [];
430 buffer.push(strings.strConversion.__formatToken(token, tokenArgs));
436 else if (start > end || buffer.length < 1) { buffer.push(tmp[start]); }
438 return (buffer.length > 1)? buffer.join(''): buffer[0];
441 calc: function(str, args) {
442 return eval(format(str, args));
445 repeat: function(s, n) {
446 return new Array(n+1).join(s);
449 UTF8encode: function(s) {
450 return unescape(encodeURIComponent(s));
453 UTF8decode: function(s) {
454 return decodeURIComponent(escape(s));
461 // $.tpl('ui.test', ['<span>', helloWorld ,'</span>']);
462 if (arguments.length == 2 && $.isArray(arguments[1])) {
463 this[arguments[0]] = arguments[1].join('');
464 return $(this[arguments[0]]);
466 // $.tpl('ui.test', '<span>hello world</span>');
467 if (arguments.length == 2 && $.isString(arguments[1])) {
468 this[arguments[0]] = arguments[1];
469 return $(this[arguments[0]]);
473 if (arguments.length == 1) {
474 return $(this[arguments[0]]);
476 // $.tpl('ui.test', false);
477 if (arguments.length == 2 && arguments[1] == false) {
478 return this[arguments[0]];
480 // $.tpl('ui.test', {value:blah});
481 if (arguments.length == 2 && $.isObject(arguments[1])) {
482 return $($.format(this[arguments[0]], arguments[1]));
484 // $.tpl('ui.test', {value:blah}, false);
485 if (arguments.length == 3 && $.isObject(arguments[1])) {
486 return (arguments[2] == true)
487 ? $.format(this[arguments[0]], arguments[1])
488 : $($.format(this[arguments[0]], arguments[1]));
493 var Argument = function(arg, args) {
496 this.__max_precision = parseFloat('1.'+ (new Array(32)).join('1'), 10).toString().length-3;
497 this.__def_precision = 6;
498 this.getString = function(){
501 this.getKey = function(){
502 return this.__arg.split(':')[0];
504 this.getFormat = function(){
505 var match = this.getString().split(':');
506 return (match && match[1])? match[1]: 's';
508 this.getPrecision = function(){
509 var match = this.getFormat().match(/\.(\d+|\*)/g);
510 if (!match) { return this.__def_precision; }
512 match = match[0].slice(1);
513 if (match != '*') { return parseInt(match, 10); }
514 else if(strings.strConversion.__getType(this.__args) == 'array') {
515 return this.__args[1] && this.__args[0] || this.__def_precision;
517 else if(strings.strConversion.__getType(this.__args) == 'object') {
518 return this.__args[this.getKey()] && this.__args[this.getKey()][0] || this.__def_precision;
520 else { return this.__def_precision; }
523 this.getPaddingLength = function(){
525 if (this.isAlternate()) {
526 match = this.getString().match(/0?#0?(\d+)/);
527 if (match && match[1]) { return parseInt(match[1], 10); }
529 match = this.getString().match(/(0|\.)(\d+|\*)/g);
530 return match && parseInt(match[0].slice(1), 10) || 0;
532 this.getPaddingString = function(){
534 if (this.isAlternate()) { o = ' '; }
535 // 0 take precedence on alternate format
536 if (this.getFormat().match(/#0|0#|^0|\.\d+/)) { o = '0'; }
539 this.getFlags = function(){
540 var match = this.getString().matc(/^(0|\#|\-|\+|\s)+/);
541 return match && match[0].split('') || [];
543 this.isAlternate = function() {
544 return !!this.getFormat().match(/^0?#/);
548 var arguments2Array = function(args, shift) {
550 for (l=args.length, x=(shift || 0)-1; x<l;x++) { o.push(args[x]); }
557 jQuery ui.timepickr - @VERSION
558 http://code.google.com/p/jquery-utils/
560 (c) Maxime Haineault <haineault@gmail.com>
563 MIT License (http://www.opensource.org/licenses/mit-license.php
565 Note: if you want the original experimental plugin checkout the rev 224
577 $.tpl('timepickr.menu', '<div class="ui-helper-reset ui-timepickr ui-widget" />');
578 $.tpl('timepickr.row', '<ol class="ui-timepickr-row ui-helper-clearfix" />');
579 $.tpl('timepickr.button', '<li class="{className:s}"><span class="ui-state-default">{label:s}</span></li>');
581 $.widget('ui.timepickr', {
583 _create: function() {
585 menu: $.tpl('timepickr.menu'),
586 row: $.tpl('timepickr.menu')
588 this._trigger('initialize');
589 this._trigger('initialized');
592 _trigger: function(type, e, ui) {
594 $.ui.plugin.call(this, type, [e, ui]);
595 return $.Widget.prototype._trigger.call(this, type, e, ui);
598 _createButton: function(i, format, className) {
599 var o = format && $.format(format, i) || i;
600 var cn = className && 'ui-timepickr-button '+ className || 'ui-timepickr-button';
601 return $.tpl('timepickr.button', {className: cn, label: o}).data('id', i)
602 .bind('mouseover', function(){
603 $(this).siblings().find('span')
604 .removeClass('ui-state-hover').end().end()
605 .find('span').addClass('ui-state-hover');
610 _addRow: function(range, format, className, insertAfter) {
613 var row = $.tpl('timepickr.row').bind('mouseover', function(){
614 $(this).next().show();
616 $.each(range, function(idx, val){
617 ui._createButton(val, format || false).appendTo(row);
620 $(row).addClass(className);
622 if (this.options.corners) {
623 row.find('span').addClass('ui-corner-'+ this.options.corners);
626 row.insertAfter(insertAfter);
629 ui._dom.menu.append(row);
634 _setVal: function(val) {
635 val = val || this._getVal();
636 if (!(val.h==='' && val.m==='')) {
637 this.element.data('timepickr.initialValue', val);
638 this.element.val(this._formatVal(val));
640 if(this._dom.menu.is(':hidden')) {
641 this.element.trigger('change');
645 _getVal: function() {
646 var ols = this._dom.menu.find('ol');
648 var u = ols.filter('.'+unit).find('.ui-state-hover:first').text();
649 return u || ols.filter('.'+unit+'li:first span').text();
657 f: this.options['format'+ this.c],
662 _formatVal: function(ival) {
663 var val = ival || this._getVal();
664 val.c = this.options.convention;
665 val.f = val.c === 12 && this.options.format12 || this.options.format24;
666 return (new Time(val)).getTime();
670 return this.element.blur();
674 return this.element.focus();
677 this._trigger('show');
678 this.element.trigger(this.options.trigger);
681 this._trigger('hide');
682 this._dom.menu.hide();
687 // These properties are shared accross every instances of timepickr
688 $.extend($.ui.timepickr.prototype, {
693 convention: 24, // 24, 12
694 trigger: 'mouseover',
695 format12: '{h:02.d}:{m:02.d} {z:s}',
696 format24: '{h:02.d}:{m:02.d}',
698 prefix: ['am', 'pm'],
699 suffix: ['am', 'pm'],
702 rangeHour12: $.range(1, 13),
703 rangeHour24: [$.range(0, 12), $.range(12, 24)],
704 rangeMin: $.range(0, 60, 15),
705 rangeSec: $.range(0, 60, 15),
720 $.ui.plugin.add('timepickr', 'core', {
721 initialized: function(e, ui) {
722 var menu = ui._dom.menu;
723 var pos = ui.element.position();
725 menu.insertAfter(ui.element).css('left', pos.left);
727 if (!$.boxModel) { // IE alignement fix
728 menu.css('margin-top', ui.element.height() + 8);
732 .bind(ui.options.trigger, function() {
734 ui._dom.menu.find('ol:first').show();
735 ui._trigger('focus');
736 if (ui.options.trigger != 'focus') {
739 ui._trigger('focus');
741 .bind('blur', function() {
746 menu.find('li').bind('mouseover.timepickr', function() {
747 ui._trigger('refresh');
750 refresh: function(e, ui) {
751 // Realign each menu layers
752 ui._dom.menu.find('ol').each(function(){
753 var p = $(this).prev('ol');
754 try { // .. to not fuckup IE
755 $(this).css('left', p.position().left + p.find('.ui-state-hover').position().left);
761 $.ui.plugin.add('timepickr', 'hours', {
762 initialize: function(e, ui) {
763 if (ui.options.convention === 24) {
764 // prefix is required in 24h mode
765 ui._dom.prefix = ui._addRow(ui.options.prefix, false, 'prefix');
768 if ($.isArray(ui.options.rangeHour24[0])) {
770 $.merge(range, ui.options.rangeHour24[0]);
771 $.merge(range, ui.options.rangeHour24[1]);
772 ui._dom.hours = ui._addRow(range, '{0:0.2d}', 'hours');
773 ui._dom.hours.find('li').slice(ui.options.rangeHour24[0].length, -1).hide();
774 var lis = ui._dom.hours.find('li');
778 lis.slice(ui.options.rangeHour24[0].length).hide().end()
779 .slice(0, ui.options.rangeHour24[0].length).show()
780 .filter(':visible:first').trigger('mouseover');
784 lis.slice(0, ui.options.rangeHour24[0].length).hide().end()
785 .slice(ui.options.rangeHour24[0].length).show()
786 .filter(':visible:first').trigger('mouseover');
790 ui._dom.prefix.find('li').bind('mouseover.timepickr', function(){
791 var index = ui._dom.menu.find('.prefix li').index(this);
796 ui._dom.hours = ui._addRow(ui.options.rangeHour24, '{0:0.2d}', 'hours');
797 ui._dom.hours.find('li').slice(12, -1).hide();
801 ui._dom.hours = ui._addRow(ui.options.rangeHour12, '{0:0.2d}', 'hours');
802 // suffix is required in 12h mode
803 ui._dom.suffix = ui._addRow(ui.options.suffix, false, 'suffix');
807 $.ui.plugin.add('timepickr', 'minutes', {
808 initialize: function(e, ui) {
809 var p = ui._dom.hours && ui._dom.hours || false;
810 ui._dom.minutes = ui._addRow(ui.options.rangeMin, '{0:0.2d}', 'minutes', p);
814 $.ui.plugin.add('timepickr', 'seconds', {
815 initialize: function(e, ui) {
816 var p = ui._dom.minutes && ui._dom.minutes || false;
817 ui._dom.seconds = ui._addRow(ui.options.rangeSec, '{0:0.2d}', 'seconds', p);
821 $.ui.plugin.add('timepickr', 'val', {
822 initialized: function(e, ui) {
823 ui._setVal(ui.options.val);
827 $.ui.plugin.add('timepickr', 'updateLive', {
828 refresh: function(e, ui) {
833 $.ui.plugin.add('timepickr', 'resetOnBlur', {
834 initialized: function(e, ui) {
835 ui.element.data('timepickr.initialValue', ui._getVal());
836 ui._dom.menu.find('li > span').bind('mousedown.timepickr', function(){
837 ui.element.data('timepickr.initialValue', ui._getVal());
840 blur: function(e, ui) {
841 ui._setVal(ui.element.data('timepickr.initialValue'));
845 $.ui.plugin.add('timepickr', 'handle', {
846 initialized: function(e, ui) {
847 $(ui.options.handle).bind(ui.options.handleEvent + '.timepickr', function(){
853 $.ui.plugin.add('timepickr', 'keyboardnav', {
854 initialized: function(e, ui) {
856 .bind('keydown', function(e) {
857 if ($.keyIs('enter', e)) {
861 else if ($.keyIs('escape', e)) {
868 var Time = function() { // arguments: h, m, s, c, z, f || time string
869 if (!(this instanceof arguments.callee)) {
870 throw Error("Constructor called as a function");
872 // arguments as literal object
873 if (arguments.length == 1 && $.isObject(arguments[0])) {
874 this.h = arguments[0].h || 0;
875 this.m = arguments[0].m || 0;
876 this.s = arguments[0].s || 0;
877 this.c = arguments[0].c && ($.inArray(arguments[0].c, [12, 24]) >= 0) && arguments[0].c || 24;
878 this.f = arguments[0].f || ((this.c == 12) && '{h:02.d}:{m:02.d} {z:02.d}' || '{h:02.d}:{m:02.d}');
879 this.z = arguments[0].z || 'am';
881 // arguments as string
882 else if (arguments.length < 4 && $.isString(arguments[1])) {
883 this.c = arguments[2] && ($.inArray(arguments[0], [12, 24]) >= 0) && arguments[0] || 24;
884 this.f = arguments[3] || ((this.c == 12) && '{h:02.d}:{m:02.d} {z:02.d}' || '{h:02.d}:{m:02.d}');
885 this.z = arguments[4] || 'am';
887 this.h = arguments[1] || 0; // parse
888 this.m = arguments[1] || 0; // parse
889 this.s = arguments[1] || 0; // parse
891 // no arguments (now)
892 else if (arguments.length === 0) {
895 // standards arguments
897 this.h = arguments[0] || 0;
898 this.m = arguments[1] || 0;
899 this.s = arguments[2] || 0;
900 this.c = arguments[3] && ($.inArray(arguments[3], [12, 24]) >= 0) && arguments[3] || 24;
901 this.f = this.f || ((this.c == 12) && '{h:02.d}:{m:02.d} {z:02.d}' || '{h:02.d}:{m:02.d}');
907 Time.prototype.get = function(p, f, u) { return u && this.h || $.format(f, this.h); };
908 Time.prototype.getHours = function(unformated) { return this.get('h', '{0:02.d}', unformated); };
909 Time.prototype.getMinutes = function(unformated) { return this.get('m', '{0:02.d}', unformated); };
910 Time.prototype.getSeconds = function(unformated) { return this.get('s', '{0:02.d}', unformated); };
911 Time.prototype.setFormat = function(format) { return this.f = format; };
912 Time.prototype.getObject = function() { return { h: this.h, m: this.m, s: this.s, c: this.c, f: this.f, z: this.z }; };
913 Time.prototype.getTime = function() { return $.format(this.f, {h: this.h, m: this.m, suffix: this.z}); }; // Thanks to Jackson for the fix.
914 Time.prototype.parse = function(str) {
917 // Supported formats: (can't find any *official* standards for 12h..)
918 // - [hh]:[mm]:[ss] [zz] | [hh]:[mm] [zz] | [hh] [zz]
919 // - [hh]:[mm]:[ss] [z.z.] | [hh]:[mm] [z.z.] | [hh] [z.z.]
920 this.tokens = str.split(/\s|:/);
921 this.h = this.tokens[0] || 0;
922 this.m = this.tokens[1] || 0;
923 this.s = this.tokens[2] || 0;
924 this.z = this.tokens[3] || '';
925 return this.getObject();
929 // Supported formats:
930 // - ISO 8601: [hh][mm][ss] | [hh][mm] | [hh]
931 // - ISO 8601 extended: [hh]:[mm]:[ss] | [hh]:[mm] | [hh]
932 this.tokens = /:/.test(str) && str.split(/:/) || str.match(/[0-9]{2}/g);
933 this.h = this.tokens[0] || 0;
934 this.m = this.tokens[1] || 0;
935 this.s = this.tokens[2] || 0;
936 this.z = this.tokens[3] || '';
937 return this.getObject();