simple toggle

This commit is contained in:
Adam Bradley
2013-09-27 13:19:01 -05:00
parent 0823b58d8e
commit d03d3aa106
16 changed files with 242 additions and 70 deletions

83
dist/ionic-simple.js vendored
View File

@ -1,12 +1,41 @@
(function(window, document, ionic) {
ionic.Components = {};
ionic.Components = [];
ionic.registerComponent = function(name, className) {
this.Components[name] = className;
ionic.registerComponent = function(instance) {
ionic.Components.push(instance);
};
function onTap(e) {
if (!e.gesture || !e.gesture.srcEvent || !e.gesture.srcEvent.target) return;
var
x,
e = e.gesture.srcEvent,
el = e.target,
component;
while(el) {
// climb up the tree looking to see if the target
// is or is in a registered component
for(x = 0; x < ionic.Components.length; x++) {
if( ionic.Components[x].isComponent(el) ) {
// this element is a component
// create its view and call it's event handler
component = ionic.Components[x].create(el);
component && component.tap && component.tap(e);
return;
}
}
// not sure if this element is a component yet,
// keep climbing up the tree and check again
el = el.parentElement;
}
}
ionic.on("tap", onTap, window);
function initalize() {
// remove the ready listeners
document.removeEventListener( "DOMContentLoaded", initalize, false );
@ -27,12 +56,48 @@
}
})(this, document, ionic);;
(function(window, document, ionic) {
(function(ionic) {
function initalize() {
ionic.registerComponent("toggle", "toggle");
}
ionic.registerComponent({
ionic.on("domready", initalize);
name: "listview",
})(window, document, ionic);
isComponent: function(element) {
return false;
},
tap: function(e) {
}
});
})(ionic);;
(function(ionic) {
ionic.registerComponent({
isComponent: function(el) {
return el.classList.contains("toggle");
},
create: function(el) {
if(el) {
if(!el._instance) {
el._instance = new ionic.views.Toggle({
el: el,
checkbox: el.querySelector("input[type='checkbox']"),
track: el.querySelector(".track"),
handle: el.querySelector(".handle")
});
}
return el._instance;
}
}
});
})(ionic);