annotate rhodecode/public/js/yui/element-delegate/element-delegate-debug.js @ 1073:289ff43cc190 beta

update YUI dev libs to latest version
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 20 Feb 2011 20:58:07 +0100
parents 1e757ac98988
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
1 /*
1073
289ff43cc190 update YUI dev libs to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
3 Code licensed under the BSD License:
1073
289ff43cc190 update YUI dev libs to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
4 http://developer.yahoo.com/yui/license.html
289ff43cc190 update YUI dev libs to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
5 version: 2.8.2r1
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
6 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
7 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
8 * Augments the Element Utility with a <code>delegate</code> method that
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
9 * facilitates easy creation of delegated event listeners. (Note: Using CSS
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
10 * selectors as the filtering criteria for delegated event listeners requires
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
11 * inclusion of the Selector Utility.)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
12 *
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
13 * @module element-delegate
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
14 * @title Element Event Delegation Module
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
15 * @namespace YAHOO.util
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
16 * @requires element, event-delegate
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
17 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
18
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
19 (function () {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
20
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
21 var Event = YAHOO.util.Event,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
22 delegates = [],
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
23 specialTypes = {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
24 mouseenter: true,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
25 mouseleave: true
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
26 };
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
27
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
28 YAHOO.lang.augmentObject(YAHOO.util.Element.prototype, {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
29
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
30 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
31 * Appends a delegated event listener. Delegated event listeners
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
32 * receive two arguments by default: the DOM event and the element
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
33 * specified by the filtering function or CSS selector.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
34 * (Note: Using the delegate method requires the element-delegate
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
35 * module. Using CSS selectors as the filtering criteria for delegated
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
36 * event listeners requires inclusion of the Selector Utility.)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
37 * @method delegate
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
38 * @param {String} type The name of the event to listen for
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
39 * @param {Function} fn The handler to call when the event fires
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
40 * @param {Function|string} filter Function or CSS selector used to
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
41 * determine for what element(s) the event listener should be called.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
42 * When a function is specified, the function should return an
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
43 * HTML element. Using a CSS Selector requires the inclusion of the
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
44 * CSS Selector Utility.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
45 * @param {Any} obj A variable to pass to the handler
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
46 * @param {Object} scope The object to use for the scope of the handler
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
47 * @return {boolean} Returns true if the delegated event listener
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
48 * was added successfully
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
49 * @for Element
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
50 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
51 delegate: function (type, fn, filter, obj, overrideContext) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
52
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
53 if (YAHOO.lang.isString(filter) && !YAHOO.util.Selector) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
54 YAHOO.log("Using a CSS selector to define the filtering criteria for a delegated listener requires the Selector Utility.", "error", "Element");
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
55 return false;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
56 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
57
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
58 if (!Event._createDelegate) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
59 YAHOO.log("Using delegate functionality requires the event-delegate module.", "error", "Element");
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
60 return false;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
61 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
62
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
63 var sType = Event._getType(type),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
64 el = this.get("element"),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
65 fnDelegate,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
66 fnMouseDelegate,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
67
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
68 fnWrapper = function (e) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
69
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
70 return fnDelegate.call(el, e);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
71
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
72 };
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
73
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
74 if (specialTypes[type]) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
75
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
76 if (!Event._createMouseDelegate) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
77 YAHOO.log("Delegating a " + type + " event requires the event-mouseleave module.", "error", "Element");
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
78 return false;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
79 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
80
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
81 fnMouseDelegate = Event._createMouseDelegate(fn, obj, overrideContext);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
82
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
83 fnDelegate = Event._createDelegate(function (event, matchedEl, container) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
84
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
85 return fnMouseDelegate.call(matchedEl, event, container);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
86
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
87 }, filter, obj, overrideContext);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
88
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
89 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
90 else {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
91 fnDelegate = Event._createDelegate(fn, filter, obj, overrideContext);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
92 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
93
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
94
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
95 delegates.push([el, sType, fn, fnWrapper]);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
96
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
97 return this.on(sType, fnWrapper);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
98
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
99 },
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
100
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
101
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
102 /**
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
103 * Remove a delegated event listener
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
104 * @method removeDelegate
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
105 * @param {String} type The name of the event to listen for
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
106 * @param {Function} fn The function call when the event fires
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
107 * @return {boolean} Returns true if the unbind was successful, false
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
108 * otherwise.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
109 * @for Element
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
110 */
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
111 removeDelegate: function (type, fn) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
112
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
113 var sType = Event._getType(type),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
114 index = Event._getCacheIndex(delegates, this.get("element"), sType, fn),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
115 returnVal,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
116 cacheItem;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
117
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
118 if (index >= 0) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
119 cacheItem = delegates[index];
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
120 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
121
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
122 if (cacheItem) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
123
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
124 returnVal = this.removeListener(cacheItem[1], cacheItem[3]);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
125
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
126 if (returnVal) {
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
127 delete delegates[index][2];
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
128 delete delegates[index][3];
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
129 delegates.splice(index, 1);
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
130 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
131
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
132 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
133
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
134 return returnVal;
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
135
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
136 }
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
137
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
138 });
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
139
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
140 }());
1073
289ff43cc190 update YUI dev libs to latest version
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
141 YAHOO.register("element-delegate", YAHOO.util.Element, {version: "2.8.2r1", build: "7"});