Skip to content
Browse files

added date binding

  • Loading branch information...
1 parent 2c8c17c commit 1ceb04f2566220f79bad621ff6a3566ab1071dc2 politician committed Jul 1, 2012
Showing with 49 additions and 0 deletions.
  1. +49 −0 outback.js
View
49 outback.js
@@ -1086,4 +1086,53 @@
}
})();
+ /* The "date" binding
+
+ Usage:
+ data-bind="date: @modelAttr, dateOptions: { format: <formatspec> }"
+
+ formatspec is a string which describes how a date must be
+ rendered. This string is used with Date.prototype.toString.
+
+ The default format specifier is 'yyyy-MM-dd'.
+
+ Purpose: The date binding causes the associated DOM element to
+ display the text value of the bound symbol formatted as a date.
+ */
+ Backbone.outback.bindingHandlers['date'] = (function () {
+ function optionsFor(valueAccessor, allBindingsAccessor) {
+ var config, options;
+
+ config = {
+ format: 'yyyy-MM-dd'
+ };
+
+ options = allBindingsAccessor('dateOptions');
+ if (options && hop(options, 'format')) {
+ config.format = options.format;
+ }
+
+ return config;
+ }
+
+ function formatDate(value, format) {
+ var d;
+ d = Date.parse(value);
+ return _.isNaN(d) || !d ? '' : d.toString(format);
+ }
+
+ return {
+ update: function (element, valueAccessor, allBindingsAccessor, view) {
+ var config, value;
+ config = optionsFor(valueAccessor, allBindingsAccessor);
+
+ value = valueAccessor()();
+ value = formatDate(value, config.format);
+
+ $(element).text(value);
+ }
+ };
+
+ })();
+
}));

0 comments on commit 1ceb04f

Please sign in to comment.
Something went wrong with that request. Please try again.