Sha256: ae6d35e73491924e6b285e715d76ebd9e0535116b3de71266e5cae08a58acd75

Contents?: true

Size: 1.71 KB

Versions: 24

Compression:

Stored size: 1.71 KB

Contents

// ==========================================================================
// Project:   SproutCore - JavaScript Application Framework
// Copyright: ©2006-2011 Strobe Inc. and contributors.
//            ©2008-2011 Apple Inc. All rights reserved.
// License:   Licensed under MIT license (see license.js)
// ==========================================================================

sc_require('views/template');

/** @class */

SC.Checkbox = SC.TemplateView.extend(
  /** @scope SC.Checkbox.prototype */ {

  title: null,
  value: null,

  displayTitle: function() {
    var title = this.get('title');
    return title ? SC.String.loc(title) : null;
  }.property('title').cacheable(),

  classNames: ['sc-checkbox'],
  template: SC.Handlebars.compile('<label><input type="checkbox">{{displayTitle}}</label>'),

  didCreateLayer: function() {
    var self = this;

    this.$('input').bind('change', function() {
      self.domValueDidChange(this);
    });
  },

  domValueDidChange: function(node) {
    this.set('value', $(node).prop('checked'));
  },

  value: function(key, value) {
    if (value !== undefined) {
      this.$('input').prop('checked', value);
    } else {
      value = this.$('input').prop('checked');
    }

    return value;
  }.property()
});

SC.CheckboxSupport = /** @scope SC.CheckboxSupport */{
  didCreateLayer: function() {
    this.$('input').change(jQuery.proxy(function() {
      SC.RunLoop.begin();
      this.notifyPropertyChange('value');
      SC.RunLoop.end();
    }, this));
  },

  value: function(key, value) {
    if (value !== undefined) {
      this.$('input').prop('checked', value);
    } else {
      value = this.$('input').prop('checked');
    }

    return value;
  }.property().idempotent()
};

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
sproutcore-1.11.0 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.11.0.rc3 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.11.0.rc2 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.11.0.rc1 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.10.3.1 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.10.2 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.10.1 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.10.0 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.10.0.rc.3 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.10.0.rc.2 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.10.0.rc.1 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.9.2 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.9.1 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.9.0 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.8.2.1 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.8.1 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.8.0 lib/frameworks/sproutcore/frameworks/template_view/mixins/template_helpers/checkbox_support.js
sproutcore-1.7.1.beta-java lib/frameworks/sproutcore/frameworks/core_foundation/mixins/template_helpers/checkbox_support.js
sproutcore-1.7.1.beta lib/frameworks/sproutcore/frameworks/core_foundation/mixins/template_helpers/checkbox_support.js
sproutcore-1.6.0.1-java lib/frameworks/sproutcore/frameworks/core_foundation/mixins/template_helpers/checkbox_support.js