~ahasenack/lazr-js/lazr-js-11.03-packaging

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/event-custom/event-custom-debug.js

  • Committer: Sidnei da Silva
  • Date: 2010-09-18 14:54:13 UTC
  • mfrom: (166.11.12 toolchain)
  • Revision ID: sidnei.da.silva@canonical.com-20100918145413-8scojue3rodcm0f4
- Merge from lazr-js trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
3
Code licensed under the BSD License:
4
4
http://developer.yahoo.com/yui/license.html
5
 
version: 3.1.1
6
 
build: 47
 
5
version: 3.2.0
 
6
build: 2676
7
7
*/
8
8
YUI.add('event-custom-base', function(Y) {
9
9
 
369
369
};
370
370
 
371
371
Y.EventHandle.prototype = {
 
372
    each: function(f) {
 
373
        f(this);
 
374
        if (Y.Lang.isArray(this.evt)) {
 
375
            Y.Array.each(this.evt, function(h) {
 
376
                h.each(f);
 
377
            });
 
378
        }
 
379
    },
372
380
 
373
381
    /**
374
382
     * Detaches this subscriber
745
753
     */
746
754
    on: function(fn, context) {
747
755
        var a = (arguments.length > 2) ? Y.Array(arguments, 2, true): null;
748
 
        this.host._monitor('attach', this.type, {
749
 
            args: arguments
750
 
        });
 
756
        if (this.host) {
 
757
            this.host._monitor('attach', this.type, {
 
758
                args: arguments
 
759
            });
 
760
        }
751
761
        return this._on(fn, context, a, true);
752
762
    },
753
763
 
781
791
            return fn.detach();
782
792
        }
783
793
 
784
 
        var found = 0, subs = this.subscribers, i, s;
 
794
        var i, s,
 
795
            found = 0, 
 
796
            subs  = Y.merge(this.subscribers, this.afters);
785
797
 
786
798
        for (i in subs) {
787
799
            if (subs.hasOwnProperty(i)) {
964
976
     */
965
977
    _delete: function(s) {
966
978
        if (s) {
 
979
            if (this.subscribers[s.id]) {
 
980
                delete this.subscribers[s.id];
 
981
                this.subCount--;
 
982
            }
 
983
            if (this.afters[s.id]) {
 
984
                delete this.afters[s.id];
 
985
                this.afterCount--;
 
986
            }
 
987
        }
 
988
 
 
989
        if (this.host) {
 
990
            this.host._monitor('detach', this.type, {
 
991
                ce: this, 
 
992
                sub: s
 
993
            });
 
994
        }
 
995
 
 
996
        if (s) {
967
997
            delete s.fn;
968
998
            delete s.context;
969
 
            delete this.subscribers[s.id];
970
 
            delete this.afters[s.id];
971
999
        }
972
 
 
973
 
        this.host._monitor('detach', this.type, {
974
 
            ce: this, 
975
 
            sub: s
976
 
        });
977
1000
    }
978
1001
};
979
1002
 
1141
1164
    PREFIX_DELIMITER = ':',
1142
1165
    CATEGORY_DELIMITER = '|',
1143
1166
    AFTER_PREFIX = '~AFTER~',
 
1167
    YArray = Y.Array,
1144
1168
 
1145
1169
    _wildType = Y.cached(function(type) {
1146
1170
        return type.replace(/(.*)(:)(.*)/, "*$2$3");
1227
1251
                queuable: o.queuable,
1228
1252
                monitored: o.monitored,
1229
1253
                broadcast: o.broadcast,
1230
 
                defaultTargetOnly: o.defaulTargetOnly,
 
1254
                defaultTargetOnly: o.defaultTargetOnly,
1231
1255
                bubbles: ('bubbles' in o) ? o.bubbles : true
1232
1256
            }
1233
1257
        };
1250
1274
     */
1251
1275
    once: function() {
1252
1276
        var handle = this.on.apply(this, arguments);
1253
 
        handle.sub.once = true;
 
1277
        handle.each(function(hand) {
 
1278
            if (hand.sub) {
 
1279
                hand.sub.once = true;
 
1280
            }
 
1281
        });
1254
1282
        return handle;
1255
1283
    },
1256
1284
 
1284
1312
 
1285
1313
            f = fn; 
1286
1314
            c = context; 
1287
 
            args = Y.Array(arguments, 0, true);
1288
 
            ret = {};
 
1315
            args = YArray(arguments, 0, true);
 
1316
            ret = [];
1289
1317
 
1290
1318
            if (L.isArray(type)) {
1291
1319
                isArr = true;
1292
 
            } else {
1293
 
                after = type._after;
1294
 
                delete type._after;
1295
1320
            }
1296
1321
 
 
1322
            after = type._after;
 
1323
            delete type._after;
 
1324
 
1297
1325
            Y.each(type, function(v, k) {
1298
1326
 
1299
1327
                if (L.isObject(v)) {
1301
1329
                    c = v.context || c;
1302
1330
                }
1303
1331
 
1304
 
                args[0] = (isArr) ? v : ((after) ? AFTER_PREFIX + k : k);
 
1332
                var nv = (after) ? AFTER_PREFIX : '';
 
1333
 
 
1334
                args[0] = nv + ((isArr) ? v : k);
1305
1335
                args[1] = f;
1306
1336
                args[2] = c;
1307
1337
 
1308
 
                ret[k] = this.on.apply(this, args); 
 
1338
                ret.push(this.on.apply(this, args));
1309
1339
 
1310
1340
            }, this);
1311
1341
 
1319
1349
 
1320
1350
        // extra redirection so we catch adaptor events too.  take a look at this.
1321
1351
        if (Node && (this instanceof Node) && (shorttype in Node.DOM_EVENTS)) {
1322
 
            args = Y.Array(arguments, 0, true);
 
1352
            args = YArray(arguments, 0, true);
1323
1353
            args.splice(2, 0, Node.getDOMNode(this));
1324
1354
            // Y.log("Node detected, redirecting with these args: " + args);
1325
1355
            return Y.on.apply(Y, args);
1330
1360
        if (this instanceof YUI) {
1331
1361
 
1332
1362
            adapt = Y.Env.evt.plugins[type];
1333
 
            args  = Y.Array(arguments, 0, true);
 
1363
            args  = YArray(arguments, 0, true);
1334
1364
            args[0] = shorttype;
1335
1365
 
1336
1366
            if (Node) {
1362
1392
 
1363
1393
        if (!handle) {
1364
1394
            ce = this._yuievt.events[type] || this.publish(type);
1365
 
            handle = ce._on(fn, context, (arguments.length > 3) ? Y.Array(arguments, 3, true) : null, (after) ? 'after' : true);
 
1395
            handle = ce._on(fn, context, (arguments.length > 3) ? YArray(arguments, 3, true) : null, (after) ? 'after' : true);
1366
1396
        }
1367
1397
 
1368
1398
        if (detachcategory) {
1422
1452
        var parts = _parseType(type, this._yuievt.config.prefix), 
1423
1453
        detachcategory = L.isArray(parts) ? parts[0] : null,
1424
1454
        shorttype = (parts) ? parts[3] : null,
1425
 
        handle, adapt, store = Y.Env.evt.handles, cat, args,
 
1455
        adapt, store = Y.Env.evt.handles, detachhost, cat, args,
1426
1456
        ce,
1427
1457
 
1428
 
        keyDetacher = function(lcat, ltype) {
1429
 
            var handles = lcat[ltype];
 
1458
        keyDetacher = function(lcat, ltype, host) {
 
1459
            var handles = lcat[ltype], ce, i;
1430
1460
            if (handles) {
1431
 
                while (handles.length) {
1432
 
                    handle = handles.pop();
1433
 
                    handle.detach();
 
1461
                for (i = handles.length - 1; i >= 0; --i) {
 
1462
                    ce = handles[i].evt;
 
1463
                    if (ce.host === host || ce.el === host) {
 
1464
                        handles[i].detach();
 
1465
                    }
1434
1466
                }
1435
1467
            }
1436
1468
        };
1439
1471
 
1440
1472
            cat = store[detachcategory];
1441
1473
            type = parts[1];
 
1474
            detachhost = (isNode) ? Y.Node.getDOMNode(this) : this;
1442
1475
 
1443
1476
            if (cat) {
1444
1477
                if (type) {
1445
 
                    keyDetacher(cat, type);
 
1478
                    keyDetacher(cat, type, detachhost);
1446
1479
                } else {
1447
1480
                    for (i in cat) {
1448
1481
                        if (cat.hasOwnProperty(i)) {
1449
 
                            keyDetacher(cat, i);
 
1482
                            keyDetacher(cat, i, detachhost);
1450
1483
                        }
1451
1484
                    }
1452
1485
                }
1460
1493
            return this;
1461
1494
        // extra redirection so we catch adaptor events too.  take a look at this.
1462
1495
        } else if (isNode && ((!shorttype) || (shorttype in Node.DOM_EVENTS))) {
1463
 
            args = Y.Array(arguments, 0, true);
 
1496
            args = YArray(arguments, 0, true);
1464
1497
            args[2] = Node.getDOMNode(this);
1465
1498
            Y.detach.apply(Y, args);
1466
1499
            return this;
1470
1503
 
1471
1504
        // The YUI instance handles DOM events and adaptors
1472
1505
        if (this instanceof YUI) {
1473
 
            args = Y.Array(arguments, 0, true);
 
1506
            args = YArray(arguments, 0, true);
1474
1507
            // use the adaptor specific detach code if
1475
1508
            if (adapt && adapt.detach) {
1476
1509
                adapt.detach.apply(Y, args);
1561
1594
     *   the fire will be notified immediately.
1562
1595
     *    </li>
1563
1596
     *    <li>
 
1597
     *   'async': fireOnce event listeners will fire synchronously if the event has already
 
1598
     *    fired unless async is true.
 
1599
     *    </li>
 
1600
     *    <li>
1564
1601
     *   'preventable': whether or not preventDefault() has an effect (true)
1565
1602
     *    </li>
1566
1603
     *    <li>
1589
1626
     *
1590
1627
     */
1591
1628
    publish: function(type, opts) {
1592
 
        var events, ce, ret, pre = this._yuievt.config.prefix;
 
1629
        var events, ce, ret, defaults,
 
1630
            edata    = this._yuievt,
 
1631
            pre      = edata.config.prefix;
1593
1632
 
1594
1633
        type = (pre) ? _getType(type, pre) : type;
1595
1634
 
1606
1645
            return ret;
1607
1646
        }
1608
1647
 
1609
 
        events = this._yuievt.events; 
 
1648
        events = edata.events; 
1610
1649
        ce = events[type];
1611
1650
 
1612
1651
        if (ce) {
1615
1654
                ce.applyConfig(opts, true);
1616
1655
            }
1617
1656
        } else {
 
1657
 
 
1658
            defaults = edata.defaults;
 
1659
 
1618
1660
            // apply defaults
1619
 
            ce = new Y.CustomEvent(type, (opts) ? Y.mix(opts, this._yuievt.defaults) : this._yuievt.defaults);
 
1661
            ce = new Y.CustomEvent(type,
 
1662
                                  (opts) ? Y.merge(defaults, opts) : defaults);
1620
1663
            events[type] = ce;
1621
1664
        }
1622
1665
 
1684
1727
        var typeIncluded = L.isString(type),
1685
1728
            t = (typeIncluded) ? type : (type && type.type),
1686
1729
            ce, ret, pre = this._yuievt.config.prefix, ce2,
1687
 
            args = (typeIncluded) ? Y.Array(arguments, 1, true) : arguments;
 
1730
            args = (typeIncluded) ? YArray(arguments, 1, true) : arguments;
1688
1731
 
1689
1732
        t = (pre) ? _getType(t, pre) : t;
1690
1733
 
1766
1809
     */
1767
1810
    after: function(type, fn) {
1768
1811
 
1769
 
        var a = Y.Array(arguments, 0, true);
 
1812
        var a = YArray(arguments, 0, true);
1770
1813
 
1771
1814
        switch (L.type(type)) {
1772
1815
            case 'function':
1773
1816
                return Y.Do.after.apply(Y.Do, arguments);
 
1817
            case 'array':
 
1818
            //     YArray.each(a[0], function(v) {
 
1819
            //         v = AFTER_PREFIX + v;
 
1820
            //     });
 
1821
            //     break;
1774
1822
            case 'object':
1775
1823
                a[0]._after = true;
1776
1824
                break;
1828
1876
 
1829
1877
})();
1830
1878
 
1831
 
 
1832
1879
/**
1833
1880
 * <code>YUI</code>'s <code>on</code> method is a unified interface for subscribing to
1834
1881
 * most events exposed by YUI.  This includes custom events, DOM events, and 
1851
1898
 *     <li>0..n additional arguments to supply the callback.</li>
1852
1899
 *   </ul>
1853
1900
 *   Example: 
1854
 
 *   <code>Y.on('domready', function() { // start work });</code>
 
1901
 *   <code>Y.on('drag:drophit', function() { // start work });</code>
1855
1902
 * </li>
1856
1903
 * <li>DOM events.  These are moments reported by the browser related
1857
1904
 * to browser functionality and user interaction.
1889
1936
 * alias for <code>on</code>.
1890
1937
 *
1891
1938
 * @method on 
1892
 
 * @param type** event type (this parameter does not apply for function events)
 
1939
 * @param type event type (this parameter does not apply for function events)
1893
1940
 * @param fn the callback
1894
 
 * @param target** a descriptor for the target (applies to custom events only).
1895
 
 * For function events, this is the object that contains the function to
1896
 
 * execute.
1897
 
 * @param extra** 0..n Extra information a particular event may need.  These
1898
 
 * will be documented with the event.  In the case of function events, this
1899
 
 * is the name of the function to execute on the host.  In the case of
1900
 
 * delegate listeners, this is the event delegation specification.
1901
1941
 * @param context optionally change the value of 'this' in the callback
1902
1942
 * @param args* 0..n additional arguments to pass to the callback.
1903
1943
 * @return the event target or a detach handle per 'chain' config
1909
1949
  * the listener is immediately detached when executed.
1910
1950
  * @see on
1911
1951
  * @method once
1912
 
  * @param type** event type (this parameter does not apply for function events)
 
1952
  * @param type event type (this parameter does not apply for function events)
1913
1953
  * @param fn the callback
1914
 
  * @param target** a descriptor for the target (applies to custom events only).
1915
 
  * For function events, this is the object that contains the function to
1916
 
  * execute.
1917
 
  * @param extra** 0..n Extra information a particular event may need.  These
1918
 
  * will be documented with the event.  In the case of function events, this
1919
 
  * is the name of the function to execute on the host.  In the case of
1920
 
  * delegate listeners, this is the event delegation specification.
1921
1954
  * @param context optionally change the value of 'this' in the callback
1922
1955
  * @param args* 0..n additional arguments to pass to the callback.
1923
1956
  * @return the event target or a detach handle per 'chain' config
1934
1967
 * @method after
1935
1968
 * @param type event type (this parameter does not apply for function events)
1936
1969
 * @param fn the callback
1937
 
 * @param target a descriptor for the target (applies to custom events only).
1938
 
 * For function events, this is the object that contains the function to
1939
 
 * execute.
1940
 
 * @param extra 0..n Extra information a particular event may need.  These
1941
 
 * will be documented with the event.  In the case of function events, this
1942
 
 * is the name of the function to execute on the host.  In the case of
1943
 
 * delegate listeners, this is the event delegation specification.
1944
1970
 * @param context optionally change the value of 'this' in the callback
1945
1971
 * @param args* 0..n additional arguments to pass to the callback.
1946
1972
 * @return the event target or a detach handle per 'chain' config
1948
1974
 */
1949
1975
 
1950
1976
 
1951
 
}, '3.1.1' ,{requires:['oop']});
 
1977
}, '3.2.0' ,{requires:['oop']});
1952
1978
YUI.add('event-custom-complex', function(Y) {
1953
1979
 
1954
1980
 
2026
2052
     */
2027
2053
    this.stopPropagation = function() {
2028
2054
        e.stopPropagation();
 
2055
        this.stopped = 1;
2029
2056
    };
2030
2057
 
2031
2058
    /**
2036
2063
     */
2037
2064
    this.stopImmediatePropagation = function() {
2038
2065
        e.stopImmediatePropagation();
 
2066
        this.stopped = 2;
2039
2067
    };
2040
2068
 
2041
2069
    /**
2044
2072
     */
2045
2073
    this.preventDefault = function() {
2046
2074
        e.preventDefault();
 
2075
        this.prevented = 1;
2047
2076
    };
2048
2077
 
2049
2078
    /**
2055
2084
     */
2056
2085
    this.halt = function(immediate) {
2057
2086
        e.halt(immediate);
 
2087
        this.prevented = 1;
 
2088
        this.stopped = (immediate) ? 2 : 1;
2058
2089
    };
2059
2090
 
2060
2091
};
2419
2450
                    ce.currentTarget = t;
2420
2451
                    bc = ce.broadcast;
2421
2452
                    ce.broadcast = false;
 
2453
 
 
2454
                    // default publish may not have emitFacade true -- that
 
2455
                    // shouldn't be what the implementer meant to do
 
2456
                    ce.emitFacade = true;
 
2457
 
2422
2458
                    ret = ret && ce.fire.apply(ce, args || evt.details || []);
2423
2459
                    ce.broadcast = bc;
2424
2460
                    ce.originalTarget = null;
2425
2461
 
 
2462
 
2426
2463
                    // stopPropagation() was called
2427
2464
                    if (ce.stopped) {
2428
2465
                        break;
2444
2481
})();
2445
2482
 
2446
2483
 
2447
 
}, '3.1.1' ,{requires:['event-custom-base']});
2448
 
 
2449
 
 
2450
 
YUI.add('event-custom', function(Y){}, '3.1.1' ,{use:['event-custom-base', 'event-custom-complex']});
 
2484
}, '3.2.0' ,{requires:['event-custom-base']});
 
2485
 
 
2486
 
 
2487
YUI.add('event-custom', function(Y){}, '3.2.0' ,{use:['event-custom-base', 'event-custom-complex']});
2451
2488