Skip to content

Instantly share code, notes, and snippets.

@lifeinafolder
Created September 24, 2013 16:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lifeinafolder/6687233 to your computer and use it in GitHub Desktop.
Save lifeinafolder/6687233 to your computer and use it in GitHub Desktop.
An ember wrapper for the bootstrap-switch module.
//= require bootstrap-switch
UiControls = window.UiControls || Ember.Namespace.create();
/**
* Custom iPhone style ON-OFF switch control
*
* @class
* @memberOf UiControls
* @extends Ember.View
*
* @example
* {{view UiControls.OnoffSwitch status="true"}}
*/
UiControls.OnoffSwitch = Ember.View.extend({
classNames: ['switch'],
classNameBindings: ['size'],
/**
* One of ['switch-large', 'switch-small', 'switch-mini']
* @type {String}
*/
size: null,
/**
* Status of the switch
* @type {Boolean}
*/
status: false,
/**
* To disable the switch
* @type {Boolean}
*/
disabled: false,
template: Ember.Handlebars.compile('{{view Ember.Checkbox checkedBinding="view.status" disabledBinding="view.disabled"}}'),
toggleState: function () {
this.$().bootstrapSwitch('toggleState');
return this;
},
// dont bubble clicks
click: function () {
return false;
},
didInsertElement: function () {
this.$().bootstrapSwitch();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment