Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5fec4815c8
Fetching contributors…

Cannot retrieve contributors at this time

88 lines (75 sloc) 2.219 kb
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Example - stopImmediatePropagation</title>
<script src="../../build/packages/ks-core-min.js"></script>
</head>
<body>
<div class="test-container" rel="1">
<div class="test-container" rel="2">
<a class="test-link" href="#" rel="1">preventDefault</a>
<a class="test-link" href="#" rel="2">stopPropagation</a>
<a class="test-link" href="#" rel="3">stopImmediatePropagation</a>
</div>
</div>
<div id="log"></div>
<script>
(function() {
var S = KISSY, DOM = S.DOM, Event = S.Event,
isIE = S.UA.ie,
CLICK = 'click',
links = S.query('.test-link'),
containers = S.query('.test-container'),
log = S.get('#log');
function print(info) {
log.innerHTML += info + '<br>';
}
print.clear = function() {
log.innerHTML = '';
return this;
};
Event.on(containers, CLICK, function() {
print('container ' + DOM.attr(this, 'rel') + ' is clicked');
});
S.each(links, function(link) {
Event._simpleAdd(link, CLICK, function() {
if(!isIE) print.clear();
print(0 + ' attach via ' + (S.UA.ie ? 'attachEvent' : 'addEventListener'));
});
});
Event.on(links, CLICK, function(ev) {
ev.preventDefault();
print(1 + ' call preventDefault');
});
Event.on(links, CLICK, function() {
print(2);
});
Event.on(links, CLICK, function(ev) {
var rel = DOM.attr(ev.target, 'rel'), ret = '';
if(rel == 2) {
ev.stopPropagation();
ret = ' call stopPropagation';
}
else if(rel == 3) {
ev.stopImmediatePropagation();
ret = ' call stopImmediatePropagation';
}
print(3 + ret);
});
Event.on(links, CLICK, function() {
print(4);
});
Event.on(links, CLICK, function() {
print(5);
});
S.each(links, function(link) {
Event._simpleAdd(link, CLICK, function() {
if(isIE) print.clear();
print(6 + ' attach via ' + (S.UA.ie ? 'attachEvent' : 'addEventListener'));
});
});
})();
</script>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.