Skip to content

Commit

Permalink
Updated from jquerytools/jquerytools.git
Browse files Browse the repository at this point in the history
  • Loading branch information
Duc Tri Le authored and default_git_name committed Feb 25, 2012
2 parents 46b8662 + f28847f commit 786d7fb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
37 changes: 26 additions & 11 deletions src/dateinput/dateinput.js
Expand Up @@ -17,8 +17,9 @@


$.tools = $.tools || {version: '@VERSION'}; $.tools = $.tools || {version: '@VERSION'};


var instances = [], var instances = [],
tool, formatters = {},
tool,


// h=72, j=74, k=75, l=76, down=40, left=37, up=38, right=39 // h=72, j=74, k=75, l=76, down=40, left=37, up=38, right=39
KEYS = [75, 76, 38, 39, 74, 72, 40, 37], KEYS = [75, 76, 38, 39, 74, 72, 40, 37],
Expand All @@ -28,6 +29,7 @@


conf: { conf: {
format: 'mm/dd/yy', format: 'mm/dd/yy',
formatter: 'default',
selectors: false, selectors: false,
yearRange: [-5, 5], yearRange: [-5, 5],
lang: 'en', lang: 'en',
Expand Down Expand Up @@ -70,6 +72,10 @@
} }
}, },


addFormatter: function(name, fn) {
formatters[name] = fn;
},

localize: function(language, labels) { localize: function(language, labels) {
$.each(labels, function(key, val) { $.each(labels, function(key, val) {
labels[key] = val.split(","); labels[key] = val.split(",");
Expand Down Expand Up @@ -103,10 +109,9 @@
} }


// thanks: http://stevenlevithan.com/assets/misc/date.format.js // thanks: http://stevenlevithan.com/assets/misc/date.format.js
var Re = /d{1,4}|m{1,4}|yy(?:yy)?|"[^"]*"|'[^']*'/g, tmpTag = $("<a/>"); var tmpTag = $("<a/>");


function format(date, fmt, lang) { function format(formatter, date, text, lang) {

var d = date.getDate(), var d = date.getDate(),
D = date.getDay(), D = date.getDay(),
m = date.getMonth(), m = date.getMonth(),
Expand All @@ -124,16 +129,26 @@
yy: String(y).slice(2), yy: String(y).slice(2),
yyyy: y yyyy: y
}; };


var ret = fmt.replace(Re, function ($0) { var ret = formatters[formatter](text, date, flags, lang);
return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
});


// a small trick to handle special characters // a small trick to handle special characters
return tmpTag.html(ret).html(); return tmpTag.html(ret).html();


} }


tool.addFormatter('default', function(text, date, flags, lang) {
return text.replace(/d{1,4}|m{1,4}|yy(?:yy)?|"[^"]*"|'[^']*'/g, function ($0) {
return $0 in flags ? flags[$0] : $0;
});
});

tool.addFormatter('prefixed', function(text, date, flags, lang) {
return text.replace(/%(d{1,4}|m{1,4}|yy(?:yy)?|"[^"]*"|'[^']*')/g, function ($0, $1) {
return $1 in flags ? flags[$1] : $0;
});
});

function integer(val) { function integer(val) {
return parseInt(val, 10); return parseInt(val, 10);
} }
Expand Down Expand Up @@ -296,7 +311,7 @@
if (e.isDefaultPrevented()) { return; } if (e.isDefaultPrevented()) { return; }


// formatting // formatting
input.val(format(date, conf.format, conf.lang)); input.val(format(conf.formatter, date, conf.format, conf.lang));


// change // change
e.type = "change"; e.type = "change";
Expand Down Expand Up @@ -699,7 +714,7 @@
}, },


getValue: function(dateFormat) { getValue: function(dateFormat) {
return dateFormat ? format(value, dateFormat, conf.lang) : value; return dateFormat ? format(conf.formatter, value, dateFormat, conf.lang) : value;
}, },


isOpen: function() { isOpen: function() {
Expand Down
2 changes: 2 additions & 0 deletions src/scrollable/scrollable.autoscroll.js
Expand Up @@ -44,6 +44,8 @@
* Fixes this bug: http://flowplayer.org/tools/forum/25/72029 * Fixes this bug: http://flowplayer.org/tools/forum/25/72029
*/ */
function scroll(){ function scroll(){
// Fixes https://github.com/jquerytools/jquerytools/issues/591
if (timer) clearTimeout(timer); // reset timeout, especially for onSeek event
timer = setTimeout(function(){ timer = setTimeout(function(){
api.next(); api.next();
}, opts.interval); }, opts.interval);
Expand Down
13 changes: 6 additions & 7 deletions src/validator/validator.js
Expand Up @@ -254,14 +254,13 @@
return !!v; return !!v;
}); });


v.fn("[pattern]", function(el) { v.fn("[pattern]", function(el, v) {
var p = new RegExp("^" + el.attr("pattern") + "$"); return v === '' || new RegExp("^" + el.attr("pattern") + "$").test(v);
return p.test(el.val());
}); });


v.fn(":radio", "Please select an option.", function(el) { v.fn(":radio", "Please select an option.", function(el) {
var checked = false; var checked = false;
var els = $("[name=" + el.attr("name") + "]").each(function(i, el) { var els = $("[name='" + el.attr("name") + "']").each(function(i, el) {
if ($(el).is(":checked")) { if ($(el).is(":checked")) {
checked = true; checked = true;
} }
Expand Down Expand Up @@ -382,7 +381,7 @@
msg.remove(); msg.remove();
$(this).data("msg.el", null); $(this).data("msg.el", null);
} }
}).unbind(conf.errorInputEvent || ''); }).unbind(conf.errorInputEvent + '.v' || '');
return self; return self;
}, },


Expand Down Expand Up @@ -578,7 +577,7 @@


// get radio groups by name // get radio groups by name
inputs.filter(":radio[required]").bind("change.V", function(e) { inputs.filter(":radio[required]").bind("change.V", function(e) {
var els = $("[name=" + $(e.srcElement).attr("name") + "]"); var els = $("[name='" + $(e.srcElement).attr("name") + "']");
if ((els != null) && (els.length != 0)) { if ((els != null) && (els.length != 0)) {
self.checkValidity(els, e); self.checkValidity(els, e);
} }
Expand Down Expand Up @@ -621,4 +620,4 @@


}; };


})(jQuery); })(jQuery);

0 comments on commit 786d7fb

Please sign in to comment.