Files
2013-10-17 11:46:48 -05:00

37 lines
865 B
JavaScript

(function(ionic) {
ionic.registerComponent({
isComponent: function(el) {
// this is a Toggle component if it has a "toggle" classname
return el.classList.contains("toggle");
},
init: function(el) {
if(!el) { return; }
// check if we've already created a Toggle instance for this element
if(!el.component) {
// find all the required elements that make up a toggle
var opts = {
el: el,
checkbox: el.querySelector("input[type='checkbox']"),
handle: el.querySelector(".handle")
};
// validate its a well formed toggle with the required pieces
if(!opts.checkbox || !opts.handle) return;
// initialize an instance of a Toggle
el.component = new ionic.views.Toggle(opts);
}
return el.component;
}
});
})(ionic);