simple toggle stuff

This commit is contained in:
Adam Bradley
2013-09-27 15:11:47 -05:00
parent d03d3aa106
commit d4f385f290
10 changed files with 594 additions and 527 deletions

View File

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