Sha256: d71aecb22fe19da56cbfb4ef091ed9fde41417689c142cc21d6e08d7142eb69d

Contents?: true

Size: 1.08 KB

Versions: 9

Compression:

Stored size: 1.08 KB

Contents

(function(ko, $, moment) {
  "use strict";

  ko.extenders.date = function(target, options) {

      options = options || {
        internal: 'YYYY-MM-DD',
        external: 'YYYY-MM-DD'
      };
      
      options.external = options.external || options.internal;

      target.date = ko.computed({
        read: function() {
          var m = moment(target(), options.internal);
          
          return m && m.isValid() ? m.format(options.external) : null;
        },
        write: function(newValue) {
          var m         = moment(newValue, options.external),
              formatted = m && m.isValid() ? m.format(options.internal) : newValue;
              
          target(formatted);
        }
      }, this);
      
      target.date.toMoment = function toMoment() {
        return moment(target(), options.internal);
      };
      
      target.date.fromMoment = function fromMoment(moment) {
        target( moment.format(options.internal) );
      };
      
      target.date.options = options;
   
      //return the original observable
      return target;
  };

})(ko, $, moment);

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kea-rails-2.0.0.pre.alpha14 app/assets/javascripts/kea/extenders/date.js
kea-rails-2.0.0.pre.alpha13 app/assets/javascripts/kea/extenders/date.js
kea-rails-2.0.0.pre.alpha12 app/assets/javascripts/kea/extenders/date.js
kea-rails-2.0.0.pre.alpha11 app/assets/javascripts/kea/extenders/date.js
kea-rails-2.0.0.pre.alpha10 app/assets/javascripts/kea/extenders/date.js
kea-rails-2.0.0.pre.alpha9 app/assets/javascripts/kea/extenders/date.js
kea-rails-2.0.0.pre.alpha8 app/assets/javascripts/kea/extenders/date.js
kea-rails-2.0.0.pre.alpha7 app/assets/javascripts/kea/extenders/date.js
kea-rails-2.0.0.pre.alpha6 app/assets/javascripts/kea/extenders/date.js