Skip to content
This repository

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

file 88 lines (75 sloc) 2.219 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
<!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>
Something went wrong with that request. Please try again.