~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/event-valuechange/event-valuechange-debug.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('event-valuechange', function(Y) {
8
 
 
9
 
/**
10
 
 * Adds a synthetic <code>valueChange</code> event that fires when the
11
 
 * <code>value</code> property of an input field or textarea changes as a result
12
 
 * of a keystroke, mouse operation, or input method editor (IME) input event.
13
 
 *
14
 
 * @module event-valuechange
15
 
 */
16
 
 
17
 
/**
18
 
 * Provides the implementation for the synthetic <code>valueChange</code> event.
19
 
 *
20
 
 * @class ValueChange
21
 
 * @static
22
 
 */
23
 
 
24
 
var YArray = Y.Array,
25
 
 
26
 
    VALUE = 'value',
27
 
 
28
 
// Just a simple namespace to make methods overridable.
29
 
VC = {
30
 
    // -- Static Constants -----------------------------------------------------
31
 
 
32
 
    /**
33
 
     * Interval (in milliseconds) at which to poll for changes to the value of
34
 
     * an element with one or more <code>valueChange</code> subscribers when the
35
 
     * user is likely to be interacting with it.
36
 
     *
37
 
     * @property POLL_INTERVAL
38
 
     * @type Number
39
 
     * @default 50
40
 
     * @static
41
 
     */
42
 
    POLL_INTERVAL: 50,
43
 
 
44
 
    /**
45
 
     * Timeout (in milliseconds) after which to stop polling when there hasn't
46
 
     * been any new activity (keypresses, mouse clicks, etc.) on an element.
47
 
     *
48
 
     * @property TIMEOUT
49
 
     * @type Number
50
 
     * @default 10000
51
 
     * @static
52
 
     */
53
 
    TIMEOUT: 10000,
54
 
 
55
 
    // -- Protected Static Properties ------------------------------------------
56
 
    _history  : {},
57
 
    _intervals: {},
58
 
    _notifiers: {},
59
 
    _timeouts : {},
60
 
 
61
 
    // -- Protected Static Methods ---------------------------------------------
62
 
 
63
 
    /**
64
 
     * Called at an interval to poll for changes to the value of the specified
65
 
     * node.
66
 
     *
67
 
     * @method _poll
68
 
     * @param {Node} node
69
 
     * @param {String} stamp
70
 
     * @param {EventFacade} e
71
 
     * @protected
72
 
     * @static
73
 
     */
74
 
    _poll: function (node, stamp, e) {
75
 
        var domNode = node._node, // performance cheat; getValue() is a big hit when polling
76
 
            newVal  = domNode && domNode.value,
77
 
            prevVal = VC._history[stamp],
78
 
            facade;
79
 
 
80
 
        if (!domNode) {
81
 
            Y.log('_poll: node ' + stamp + ' disappeared; stopping polling.', 'warn', 'event-valuechange');
82
 
            VC._stopPolling(node, stamp);
83
 
            return;
84
 
        }
85
 
 
86
 
        if (newVal !== prevVal) {
87
 
            VC._history[stamp] = newVal;
88
 
 
89
 
            facade = {
90
 
                _event : e,
91
 
                newVal : newVal,
92
 
                prevVal: prevVal
93
 
            };
94
 
 
95
 
            YArray.each(VC._notifiers[stamp], function (notifier) {
96
 
                notifier.fire(facade);
97
 
            });
98
 
 
99
 
            VC._refreshTimeout(node, stamp);
100
 
        }
101
 
    },
102
 
 
103
 
    /**
104
 
     * Restarts the inactivity timeout for the specified node.
105
 
     *
106
 
     * @method _refreshTimeout
107
 
     * @param {Node} node
108
 
     * @param {String} stamp
109
 
     * @protected
110
 
     * @static
111
 
     */
112
 
    _refreshTimeout: function (node, stamp) {
113
 
        VC._stopTimeout(node, stamp); // avoid dupes
114
 
 
115
 
        // If we don't see any changes within the timeout period (10 seconds by
116
 
        // default), stop polling.
117
 
        VC._timeouts[stamp] = setTimeout(function () {
118
 
            VC._stopPolling(node, stamp);
119
 
        }, VC.TIMEOUT);
120
 
 
121
 
        Y.log('_refreshTimeout: ' + stamp, 'info', 'event-valuechange');
122
 
    },
123
 
 
124
 
    /**
125
 
     * Begins polling for changes to the <code>value</code> property of the
126
 
     * specified node. If polling is already underway for the specified node,
127
 
     * it will not be restarted unless the <i>force</i> parameter is
128
 
     * <code>true</code>
129
 
     *
130
 
     * @method _startPolling
131
 
     * @param {Node} node Node to watch.
132
 
     * @param {String} stamp (optional) Object stamp for the node. Will be
133
 
     *   generated if not provided (provide it to improve performance).
134
 
     * @param {EventFacade} e (optional) Event facade of the event that
135
 
     *   initiated the polling (if any).
136
 
     * @param {Boolean} force (optional) If <code>true</code>, polling will be
137
 
     *   restarted even if we're already polling this node.
138
 
     * @protected
139
 
     * @static
140
 
     */
141
 
    _startPolling: function (node, stamp, e, force) {
142
 
        if (!stamp) {
143
 
            stamp = Y.stamp(node);
144
 
        }
145
 
 
146
 
        // Don't bother continuing if we're already polling.
147
 
        if (!force && VC._intervals[stamp]) {
148
 
            return;
149
 
        }
150
 
 
151
 
        VC._stopPolling(node, stamp); // avoid dupes
152
 
 
153
 
        // Poll for changes to the node's value. We can't rely on keyboard
154
 
        // events for this, since the value may change due to a mouse-initiated
155
 
        // paste event, an IME input event, or for some other reason that
156
 
        // doesn't trigger a key event.
157
 
        VC._intervals[stamp] = setInterval(function () {
158
 
            VC._poll(node, stamp, e);
159
 
        }, VC.POLL_INTERVAL);
160
 
 
161
 
        VC._refreshTimeout(node, stamp, e);
162
 
 
163
 
        Y.log('_startPolling: ' + stamp, 'info', 'event-valuechange');
164
 
    },
165
 
 
166
 
    /**
167
 
     * Stops polling for changes to the specified node's <code>value</code>
168
 
     * attribute.
169
 
     *
170
 
     * @method _stopPolling
171
 
     * @param {Node} node
172
 
     * @param {String} stamp (optional)
173
 
     * @protected
174
 
     * @static
175
 
     */
176
 
    _stopPolling: function (node, stamp) {
177
 
        if (!stamp) {
178
 
            stamp = Y.stamp(node);
179
 
        }
180
 
 
181
 
        VC._intervals[stamp] = clearInterval(VC._intervals[stamp]);
182
 
        VC._stopTimeout(node, stamp);
183
 
 
184
 
        Y.log('_stopPolling: ' + stamp, 'info', 'event-valuechange');
185
 
    },
186
 
 
187
 
    /**
188
 
     * Clears the inactivity timeout for the specified node, if any.
189
 
     *
190
 
     * @method _stopTimeout
191
 
     * @param {Node} node
192
 
     * @param {String} stamp (optional)
193
 
     * @protected
194
 
     * @static
195
 
     */
196
 
    _stopTimeout: function (node, stamp) {
197
 
        if (!stamp) {
198
 
            stamp = Y.stamp(node);
199
 
        }
200
 
 
201
 
        VC._timeouts[stamp] = clearTimeout(VC._timeouts[stamp]);
202
 
    },
203
 
 
204
 
    // -- Protected Static Event Handlers --------------------------------------
205
 
 
206
 
    /**
207
 
     * Stops polling when a node's blur event fires.
208
 
     *
209
 
     * @method _onBlur
210
 
     * @param {EventFacade} e
211
 
     * @protected
212
 
     * @static
213
 
     */
214
 
    _onBlur: function (e) {
215
 
        VC._stopPolling(e.currentTarget);
216
 
    },
217
 
 
218
 
    /**
219
 
     * Resets a node's history and starts polling when a focus event occurs.
220
 
     *
221
 
     * @method _onFocus
222
 
     * @param {EventFacade} e
223
 
     * @protected
224
 
     * @static
225
 
     */
226
 
    _onFocus: function (e) {
227
 
        var node = e.currentTarget;
228
 
 
229
 
        VC._history[Y.stamp(node)] = node.get(VALUE);
230
 
        VC._startPolling(node, null, e);
231
 
    },
232
 
 
233
 
    /**
234
 
     * Starts polling when a node receives a keyDown event.
235
 
     *
236
 
     * @method _onKeyDown
237
 
     * @param {EventFacade} e
238
 
     * @protected
239
 
     * @static
240
 
     */
241
 
    _onKeyDown: function (e) {
242
 
        VC._startPolling(e.currentTarget, null, e);
243
 
    },
244
 
 
245
 
    /**
246
 
     * Starts polling when an IME-related keyUp event occurs on a node.
247
 
     *
248
 
     * @method _onKeyUp
249
 
     * @param {EventFacade} e
250
 
     * @protected
251
 
     * @static
252
 
     */
253
 
    _onKeyUp: function (e) {
254
 
        // These charCodes indicate that an IME has started. We'll restart
255
 
        // polling and give the IME up to 10 seconds (by default) to finish.
256
 
        if (e.charCode === 229 || e.charCode === 197) {
257
 
            VC._startPolling(e.currentTarget, null, e, true);
258
 
        }
259
 
    },
260
 
 
261
 
    /**
262
 
     * Starts polling when a node receives a mouseDown event.
263
 
     *
264
 
     * @method _onMouseDown
265
 
     * @param {EventFacade} e
266
 
     * @protected
267
 
     * @static
268
 
     */
269
 
    _onMouseDown: function (e) {
270
 
        VC._startPolling(e.currentTarget, null, e);
271
 
    },
272
 
 
273
 
    /**
274
 
     * Called when event-valuechange receives a new subscriber.
275
 
     *
276
 
     * @method _onSubscribe
277
 
     * @param {Node} node
278
 
     * @param {Subscription} subscription
279
 
     * @param {SyntheticEvent.Notifier} notifier
280
 
     * @protected
281
 
     * @static
282
 
     */
283
 
    _onSubscribe: function (node, subscription, notifier) {
284
 
        var stamp     = Y.stamp(node),
285
 
            notifiers = VC._notifiers[stamp];
286
 
 
287
 
        VC._history[stamp] = node.get(VALUE);
288
 
 
289
 
        notifier._handles = node.on({
290
 
            blur     : VC._onBlur,
291
 
            focus    : VC._onFocus,
292
 
            keydown  : VC._onKeyDown,
293
 
            keyup    : VC._onKeyUp,
294
 
            mousedown: VC._onMouseDown
295
 
        });
296
 
 
297
 
        if (!notifiers) {
298
 
            notifiers = VC._notifiers[stamp] = [];
299
 
        }
300
 
 
301
 
        notifiers.push(notifier);
302
 
    },
303
 
 
304
 
    /**
305
 
     * Called when event-valuechange loses a subscriber.
306
 
     *
307
 
     * @method _onUnsubscribe
308
 
     * @param {Node} node
309
 
     * @param {Subscription} subscription
310
 
     * @param {SyntheticEvent.Notifier} notifier
311
 
     * @protected
312
 
     * @static
313
 
     */
314
 
    _onUnsubscribe: function (node, subscription, notifier) {
315
 
        var stamp     = Y.stamp(node),
316
 
            notifiers = VC._notifiers[stamp],
317
 
            index     = YArray.indexOf(notifiers, notifier);
318
 
 
319
 
        notifier._handles.detach();
320
 
 
321
 
        if (index !== -1) {
322
 
            notifiers.splice(index, 1);
323
 
 
324
 
            if (!notifiers.length) {
325
 
                VC._stopPolling(node, stamp);
326
 
 
327
 
                delete VC._notifiers[stamp];
328
 
                delete VC._history[stamp];
329
 
            }
330
 
        }
331
 
    }
332
 
};
333
 
 
334
 
/**
335
 
 * <p>
336
 
 * Synthetic event that fires when the <code>value</code> property of an input
337
 
 * field or textarea changes as a result of a keystroke, mouse operation, or
338
 
 * input method editor (IME) input event.
339
 
 * </p>
340
 
 *
341
 
 * <p>
342
 
 * Unlike the <code>onchange</code> event, this event fires when the value
343
 
 * actually changes and not when the element loses focus. This event also
344
 
 * reports IME and multi-stroke input more reliably than <code>oninput</code> or
345
 
 * the various key events across browsers.
346
 
 * </p>
347
 
 *
348
 
 * @example
349
 
 *
350
 
 *     YUI().use('event-valuechange', function (Y) {
351
 
 *       Y.one('input').on('valueChange', function (e) {
352
 
 *         // Handle valueChange events on the first input element on the page.
353
 
 *       });
354
 
 *     });
355
 
 *
356
 
 * @event valueChange
357
 
 * @param {EventFacade} e Event facade with the following additional
358
 
 *   properties:
359
 
 *
360
 
 * <dl>
361
 
 *   <dt>prevVal (String)</dt>
362
 
 *   <dd>
363
 
 *     Previous value before the latest change.
364
 
 *   </dd>
365
 
 *
366
 
 *   <dt>newVal (String)</dt>
367
 
 *   <dd>
368
 
 *     New value after the latest change.
369
 
 *   </dd>
370
 
 * </dl>
371
 
 *
372
 
 * @for YUI
373
 
 */
374
 
 
375
 
Y.Event.define('valueChange', {
376
 
    detach: VC._onUnsubscribe,
377
 
    on    : VC._onSubscribe,
378
 
 
379
 
    publishConfig: {
380
 
        emitFacade: true
381
 
    }
382
 
});
383
 
 
384
 
Y.ValueChange = VC;
385
 
 
386
 
 
387
 
}, '3.4.1' ,{requires:['event-focus', 'event-synthetic']});