~ted/lazr-js/annoying-debug-message

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2010-09-09 14:20:30 UTC
  • mfrom: (182.1.3 yui-3.2)
  • Revision ID: launchpad@pqm.canonical.com-20100909142030-13w6vo0ixfysxc15
[r=beuno] Update lazr-js to yui-3.2

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.2
6
 
build: 56
 
5
version: 3.2.0
 
6
build: 2676
7
7
*/
8
8
YUI.add('event-custom-base', function(Y) {
9
9
 
367
367
};
368
368
 
369
369
Y.EventHandle.prototype = {
 
370
    each: function(f) {
 
371
        f(this);
 
372
        if (Y.Lang.isArray(this.evt)) {
 
373
            Y.Array.each(this.evt, function(h) {
 
374
                h.each(f);
 
375
            });
 
376
        }
 
377
    },
370
378
 
371
379
    /**
372
380
     * Detaches this subscriber
741
749
     */
742
750
    on: function(fn, context) {
743
751
        var a = (arguments.length > 2) ? Y.Array(arguments, 2, true): null;
744
 
        this.host._monitor('attach', this.type, {
745
 
            args: arguments
746
 
        });
 
752
        if (this.host) {
 
753
            this.host._monitor('attach', this.type, {
 
754
                args: arguments
 
755
            });
 
756
        }
747
757
        return this._on(fn, context, a, true);
748
758
    },
749
759
 
777
787
            return fn.detach();
778
788
        }
779
789
 
780
 
        var found = 0, subs = this.subscribers, i, s;
 
790
        var i, s,
 
791
            found = 0, 
 
792
            subs  = Y.merge(this.subscribers, this.afters);
781
793
 
782
794
        for (i in subs) {
783
795
            if (subs.hasOwnProperty(i)) {
958
970
     */
959
971
    _delete: function(s) {
960
972
        if (s) {
 
973
            if (this.subscribers[s.id]) {
 
974
                delete this.subscribers[s.id];
 
975
                this.subCount--;
 
976
            }
 
977
            if (this.afters[s.id]) {
 
978
                delete this.afters[s.id];
 
979
                this.afterCount--;
 
980
            }
 
981
        }
 
982
 
 
983
        if (this.host) {
 
984
            this.host._monitor('detach', this.type, {
 
985
                ce: this, 
 
986
                sub: s
 
987
            });
 
988
        }
 
989
 
 
990
        if (s) {
961
991
            delete s.fn;
962
992
            delete s.context;
963
 
            delete this.subscribers[s.id];
964
 
            delete this.afters[s.id];
965
993
        }
966
 
 
967
 
        this.host._monitor('detach', this.type, {
968
 
            ce: this, 
969
 
            sub: s
970
 
        });
971
994
    }
972
995
};
973
996
 
1135
1158
    PREFIX_DELIMITER = ':',
1136
1159
    CATEGORY_DELIMITER = '|',
1137
1160
    AFTER_PREFIX = '~AFTER~',
 
1161
    YArray = Y.Array,
1138
1162
 
1139
1163
    _wildType = Y.cached(function(type) {
1140
1164
        return type.replace(/(.*)(:)(.*)/, "*$2$3");
1219
1243
                queuable: o.queuable,
1220
1244
                monitored: o.monitored,
1221
1245
                broadcast: o.broadcast,
1222
 
                defaultTargetOnly: o.defaulTargetOnly,
 
1246
                defaultTargetOnly: o.defaultTargetOnly,
1223
1247
                bubbles: ('bubbles' in o) ? o.bubbles : true
1224
1248
            }
1225
1249
        };
1242
1266
     */
1243
1267
    once: function() {
1244
1268
        var handle = this.on.apply(this, arguments);
1245
 
        handle.sub.once = true;
 
1269
        handle.each(function(hand) {
 
1270
            if (hand.sub) {
 
1271
                hand.sub.once = true;
 
1272
            }
 
1273
        });
1246
1274
        return handle;
1247
1275
    },
1248
1276
 
1276
1304
 
1277
1305
            f = fn; 
1278
1306
            c = context; 
1279
 
            args = Y.Array(arguments, 0, true);
1280
 
            ret = {};
 
1307
            args = YArray(arguments, 0, true);
 
1308
            ret = [];
1281
1309
 
1282
1310
            if (L.isArray(type)) {
1283
1311
                isArr = true;
1284
 
            } else {
1285
 
                after = type._after;
1286
 
                delete type._after;
1287
1312
            }
1288
1313
 
 
1314
            after = type._after;
 
1315
            delete type._after;
 
1316
 
1289
1317
            Y.each(type, function(v, k) {
1290
1318
 
1291
1319
                if (L.isObject(v)) {
1293
1321
                    c = v.context || c;
1294
1322
                }
1295
1323
 
1296
 
                args[0] = (isArr) ? v : ((after) ? AFTER_PREFIX + k : k);
 
1324
                var nv = (after) ? AFTER_PREFIX : '';
 
1325
 
 
1326
                args[0] = nv + ((isArr) ? v : k);
1297
1327
                args[1] = f;
1298
1328
                args[2] = c;
1299
1329
 
1300
 
                ret[k] = this.on.apply(this, args); 
 
1330
                ret.push(this.on.apply(this, args));
1301
1331
 
1302
1332
            }, this);
1303
1333
 
1311
1341
 
1312
1342
        // extra redirection so we catch adaptor events too.  take a look at this.
1313
1343
        if (Node && (this instanceof Node) && (shorttype in Node.DOM_EVENTS)) {
1314
 
            args = Y.Array(arguments, 0, true);
 
1344
            args = YArray(arguments, 0, true);
1315
1345
            args.splice(2, 0, Node.getDOMNode(this));
1316
1346
            return Y.on.apply(Y, args);
1317
1347
        }
1321
1351
        if (this instanceof YUI) {
1322
1352
 
1323
1353
            adapt = Y.Env.evt.plugins[type];
1324
 
            args  = Y.Array(arguments, 0, true);
 
1354
            args  = YArray(arguments, 0, true);
1325
1355
            args[0] = shorttype;
1326
1356
 
1327
1357
            if (Node) {
1352
1382
 
1353
1383
        if (!handle) {
1354
1384
            ce = this._yuievt.events[type] || this.publish(type);
1355
 
            handle = ce._on(fn, context, (arguments.length > 3) ? Y.Array(arguments, 3, true) : null, (after) ? 'after' : true);
 
1385
            handle = ce._on(fn, context, (arguments.length > 3) ? YArray(arguments, 3, true) : null, (after) ? 'after' : true);
1356
1386
        }
1357
1387
 
1358
1388
        if (detachcategory) {
1411
1441
        var parts = _parseType(type, this._yuievt.config.prefix), 
1412
1442
        detachcategory = L.isArray(parts) ? parts[0] : null,
1413
1443
        shorttype = (parts) ? parts[3] : null,
1414
 
        handle, adapt, store = Y.Env.evt.handles, cat, args,
 
1444
        adapt, store = Y.Env.evt.handles, detachhost, cat, args,
1415
1445
        ce,
1416
1446
 
1417
 
        keyDetacher = function(lcat, ltype) {
1418
 
            var handles = lcat[ltype];
 
1447
        keyDetacher = function(lcat, ltype, host) {
 
1448
            var handles = lcat[ltype], ce, i;
1419
1449
            if (handles) {
1420
 
                while (handles.length) {
1421
 
                    handle = handles.pop();
1422
 
                    handle.detach();
 
1450
                for (i = handles.length - 1; i >= 0; --i) {
 
1451
                    ce = handles[i].evt;
 
1452
                    if (ce.host === host || ce.el === host) {
 
1453
                        handles[i].detach();
 
1454
                    }
1423
1455
                }
1424
1456
            }
1425
1457
        };
1428
1460
 
1429
1461
            cat = store[detachcategory];
1430
1462
            type = parts[1];
 
1463
            detachhost = (isNode) ? Y.Node.getDOMNode(this) : this;
1431
1464
 
1432
1465
            if (cat) {
1433
1466
                if (type) {
1434
 
                    keyDetacher(cat, type);
 
1467
                    keyDetacher(cat, type, detachhost);
1435
1468
                } else {
1436
1469
                    for (i in cat) {
1437
1470
                        if (cat.hasOwnProperty(i)) {
1438
 
                            keyDetacher(cat, i);
 
1471
                            keyDetacher(cat, i, detachhost);
1439
1472
                        }
1440
1473
                    }
1441
1474
                }
1449
1482
            return this;
1450
1483
        // extra redirection so we catch adaptor events too.  take a look at this.
1451
1484
        } else if (isNode && ((!shorttype) || (shorttype in Node.DOM_EVENTS))) {
1452
 
            args = Y.Array(arguments, 0, true);
 
1485
            args = YArray(arguments, 0, true);
1453
1486
            args[2] = Node.getDOMNode(this);
1454
1487
            Y.detach.apply(Y, args);
1455
1488
            return this;
1459
1492
 
1460
1493
        // The YUI instance handles DOM events and adaptors
1461
1494
        if (this instanceof YUI) {
1462
 
            args = Y.Array(arguments, 0, true);
 
1495
            args = YArray(arguments, 0, true);
1463
1496
            // use the adaptor specific detach code if
1464
1497
            if (adapt && adapt.detach) {
1465
1498
                adapt.detach.apply(Y, args);
1548
1581
     *   the fire will be notified immediately.
1549
1582
     *    </li>
1550
1583
     *    <li>
 
1584
     *   'async': fireOnce event listeners will fire synchronously if the event has already
 
1585
     *    fired unless async is true.
 
1586
     *    </li>
 
1587
     *    <li>
1551
1588
     *   'preventable': whether or not preventDefault() has an effect (true)
1552
1589
     *    </li>
1553
1590
     *    <li>
1576
1613
     *
1577
1614
     */
1578
1615
    publish: function(type, opts) {
1579
 
        var events, ce, ret, pre = this._yuievt.config.prefix;
 
1616
        var events, ce, ret, defaults,
 
1617
            edata    = this._yuievt,
 
1618
            pre      = edata.config.prefix;
1580
1619
 
1581
1620
        type = (pre) ? _getType(type, pre) : type;
1582
1621
 
1593
1632
            return ret;
1594
1633
        }
1595
1634
 
1596
 
        events = this._yuievt.events; 
 
1635
        events = edata.events; 
1597
1636
        ce = events[type];
1598
1637
 
1599
1638
        if (ce) {
1602
1641
                ce.applyConfig(opts, true);
1603
1642
            }
1604
1643
        } else {
 
1644
 
 
1645
            defaults = edata.defaults;
 
1646
 
1605
1647
            // apply defaults
1606
 
            ce = new Y.CustomEvent(type, (opts) ? Y.mix(opts, this._yuievt.defaults) : this._yuievt.defaults);
 
1648
            ce = new Y.CustomEvent(type,
 
1649
                                  (opts) ? Y.merge(defaults, opts) : defaults);
1607
1650
            events[type] = ce;
1608
1651
        }
1609
1652
 
1670
1713
        var typeIncluded = L.isString(type),
1671
1714
            t = (typeIncluded) ? type : (type && type.type),
1672
1715
            ce, ret, pre = this._yuievt.config.prefix, ce2,
1673
 
            args = (typeIncluded) ? Y.Array(arguments, 1, true) : arguments;
 
1716
            args = (typeIncluded) ? YArray(arguments, 1, true) : arguments;
1674
1717
 
1675
1718
        t = (pre) ? _getType(t, pre) : t;
1676
1719
 
1752
1795
     */
1753
1796
    after: function(type, fn) {
1754
1797
 
1755
 
        var a = Y.Array(arguments, 0, true);
 
1798
        var a = YArray(arguments, 0, true);
1756
1799
 
1757
1800
        switch (L.type(type)) {
1758
1801
            case 'function':
1759
1802
                return Y.Do.after.apply(Y.Do, arguments);
 
1803
            case 'array':
 
1804
            //     YArray.each(a[0], function(v) {
 
1805
            //         v = AFTER_PREFIX + v;
 
1806
            //     });
 
1807
            //     break;
1760
1808
            case 'object':
1761
1809
                a[0]._after = true;
1762
1810
                break;
1814
1862
 
1815
1863
})();
1816
1864
 
1817
 
 
1818
1865
/**
1819
1866
 * <code>YUI</code>'s <code>on</code> method is a unified interface for subscribing to
1820
1867
 * most events exposed by YUI.  This includes custom events, DOM events, and 
1837
1884
 *     <li>0..n additional arguments to supply the callback.</li>
1838
1885
 *   </ul>
1839
1886
 *   Example: 
1840
 
 *   <code>Y.on('domready', function() { // start work });</code>
 
1887
 *   <code>Y.on('drag:drophit', function() { // start work });</code>
1841
1888
 * </li>
1842
1889
 * <li>DOM events.  These are moments reported by the browser related
1843
1890
 * to browser functionality and user interaction.
1875
1922
 * alias for <code>on</code>.
1876
1923
 *
1877
1924
 * @method on 
1878
 
 * @param type** event type (this parameter does not apply for function events)
 
1925
 * @param type event type (this parameter does not apply for function events)
1879
1926
 * @param fn the callback
1880
 
 * @param target** a descriptor for the target (applies to custom events only).
1881
 
 * For function events, this is the object that contains the function to
1882
 
 * execute.
1883
 
 * @param extra** 0..n Extra information a particular event may need.  These
1884
 
 * will be documented with the event.  In the case of function events, this
1885
 
 * is the name of the function to execute on the host.  In the case of
1886
 
 * delegate listeners, this is the event delegation specification.
1887
1927
 * @param context optionally change the value of 'this' in the callback
1888
1928
 * @param args* 0..n additional arguments to pass to the callback.
1889
1929
 * @return the event target or a detach handle per 'chain' config
1895
1935
  * the listener is immediately detached when executed.
1896
1936
  * @see on
1897
1937
  * @method once
1898
 
  * @param type** event type (this parameter does not apply for function events)
 
1938
  * @param type event type (this parameter does not apply for function events)
1899
1939
  * @param fn the callback
1900
 
  * @param target** a descriptor for the target (applies to custom events only).
1901
 
  * For function events, this is the object that contains the function to
1902
 
  * execute.
1903
 
  * @param extra** 0..n Extra information a particular event may need.  These
1904
 
  * will be documented with the event.  In the case of function events, this
1905
 
  * is the name of the function to execute on the host.  In the case of
1906
 
  * delegate listeners, this is the event delegation specification.
1907
1940
  * @param context optionally change the value of 'this' in the callback
1908
1941
  * @param args* 0..n additional arguments to pass to the callback.
1909
1942
  * @return the event target or a detach handle per 'chain' config
1920
1953
 * @method after
1921
1954
 * @param type event type (this parameter does not apply for function events)
1922
1955
 * @param fn the callback
1923
 
 * @param target a descriptor for the target (applies to custom events only).
1924
 
 * For function events, this is the object that contains the function to
1925
 
 * execute.
1926
 
 * @param extra 0..n Extra information a particular event may need.  These
1927
 
 * will be documented with the event.  In the case of function events, this
1928
 
 * is the name of the function to execute on the host.  In the case of
1929
 
 * delegate listeners, this is the event delegation specification.
1930
1956
 * @param context optionally change the value of 'this' in the callback
1931
1957
 * @param args* 0..n additional arguments to pass to the callback.
1932
1958
 * @return the event target or a detach handle per 'chain' config
1934
1960
 */
1935
1961
 
1936
1962
 
1937
 
}, '3.1.2' ,{requires:['oop']});
 
1963
}, '3.2.0' ,{requires:['oop']});