mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 06:57:02 +08:00
start of nav stuff
This commit is contained in:
@ -0,0 +1,83 @@
|
||||
(function(window, document, location, framework) {
|
||||
|
||||
var
|
||||
x;
|
||||
|
||||
// Add listeners to each link in the document
|
||||
framework.addLinkListeners = function() {
|
||||
for(x = 0; x < document.links.length; x++) {
|
||||
document.links[x].addEventListener('click', linkClick, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove listeners to each link in the document
|
||||
framework.removeLinkListeners = function() {
|
||||
for(x = 0; x < document.links.length; x++) {
|
||||
document.links[x].removeEventListener('click', linkClick, false);
|
||||
}
|
||||
}
|
||||
|
||||
// A link has been clicked
|
||||
function linkClick(e) {
|
||||
var
|
||||
target = e.target,
|
||||
href = target.getAttribute("href");
|
||||
|
||||
// data-previous="true"
|
||||
// shortcut if they just want to go to the previous page
|
||||
if(target.dataset.previous === "true") {
|
||||
window.history.back();
|
||||
return preventDefault(e);
|
||||
}
|
||||
|
||||
// if they clicked a link while scrolling don't nav to it
|
||||
if(framework.isScrolling || href === "#") {
|
||||
return preventDefault(e);
|
||||
}
|
||||
|
||||
// only intercept the nav click if they're going to the same domain
|
||||
if (location.protocol === target.protocol && location.host === target.host) {
|
||||
// this link is an anchor to the same page
|
||||
if(href.indexOf("#") === 0) {
|
||||
hashLinkClick(target, href);
|
||||
} else {
|
||||
pageLinkClick(target, href);
|
||||
}
|
||||
return preventDefault(e);
|
||||
}
|
||||
}
|
||||
|
||||
// they are navigating to another URL within the same domain
|
||||
function pageLinkClick(target, href) {
|
||||
console.log("pageLinkClick, get:", href);
|
||||
}
|
||||
|
||||
// they are navigation to an anchor within the same page
|
||||
function hashLinkClick(target, href) {
|
||||
console.log("hashLinkClick, get:", href);
|
||||
}
|
||||
|
||||
function touchEnd(e) {
|
||||
framework.trigger("touchEnd");
|
||||
}
|
||||
|
||||
function popstate(e) {
|
||||
|
||||
}
|
||||
|
||||
function preventDefault(e) {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
framework.on("ready", function(){
|
||||
// DOM is ready
|
||||
framework.addLinkListeners();
|
||||
});
|
||||
|
||||
window.addEventListener('touchstart', function () { framework.isScrolling = false; });
|
||||
window.addEventListener('touchmove', function () { framework.isScrolling = true; })
|
||||
window.addEventListener('touchend', touchEnd);
|
||||
window.addEventListener('popstate', popstate);
|
||||
|
||||
})(this, document, location, this.FM = this.FM || {});
|
||||
@ -1,17 +1,5 @@
|
||||
(function(window, document, framework) {
|
||||
|
||||
framework.get = function(id) {
|
||||
return document.getElementById(id);
|
||||
};
|
||||
|
||||
framework.getByClass = function(classname) {
|
||||
return document.getElementByClassName(classname);
|
||||
};
|
||||
|
||||
framework.getByTag = function(tagName) {
|
||||
return document.getElementsByTagName(tagName);
|
||||
};
|
||||
|
||||
framework.trigger = function(type, data) {
|
||||
window.dispatchEvent( new CustomEvent(type, data) );
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user