mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 06:57:02 +08:00
simple toggle
This commit is contained in:
83
dist/ionic-simple.js
vendored
83
dist/ionic-simple.js
vendored
@ -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);
|
||||
Reference in New Issue
Block a user