Added: roller/trunk/app/src/main/webapp/roller-ui/yui3/event-base/event-base.js URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/webapp/roller-ui/yui3/event-base/event-base.js?rev=1609737&view=auto ============================================================================== --- roller/trunk/app/src/main/webapp/roller-ui/yui3/event-base/event-base.js (added) +++ roller/trunk/app/src/main/webapp/roller-ui/yui3/event-base/event-base.js Fri Jul 11 16:23:25 2014 @@ -0,0 +1,1370 @@ +/* +YUI 3.17.2 (build 9c3c78e) +Copyright 2014 Yahoo! Inc. All rights reserved. +Licensed under the BSD License. +http://yuilibrary.com/license/ +*/ + +YUI.add('event-base', function (Y, NAME) { + +/* + * DOM event listener abstraction layer + * @module event + * @submodule event-base + */ + +/** + * The domready event fires at the moment the browser's DOM is + * usable. In most cases, this is before images are fully + * downloaded, allowing you to provide a more responsive user + * interface. + * + * In YUI 3, domready subscribers will be notified immediately if + * that moment has already passed when the subscription is created. + * + * One exception is if the yui.js file is dynamically injected into + * the page. If this is done, you must tell the YUI instance that + * you did this in order for DOMReady (and window load events) to + * fire normally. That configuration option is 'injected' -- set + * it to true if the yui.js script is not included inline. + * + * This method is part of the 'event-ready' module, which is a + * submodule of 'event'. + * + * @event domready + * @for YUI + */ +Y.publish('domready', { + fireOnce: true, + async: true +}); + +if (YUI.Env.DOMReady) { + Y.fire('domready'); +} else { + Y.Do.before(function() { Y.fire('domready'); }, YUI.Env, '_ready'); +} + +/** + * Custom event engine, DOM event listener abstraction layer, synthetic DOM + * events. + * @module event + * @submodule event-base + */ + +/** + * Wraps a DOM event, properties requiring browser abstraction are + * fixed here. Provids a security layer when required. + * @class DOMEventFacade + * @param ev {Event} the DOM event + * @param currentTarget {HTMLElement} the element the listener was attached to + * @param wrapper {CustomEvent} the custom event wrapper for this DOM event + */ + + var ua = Y.UA, + + EMPTY = {}, + + /** + * webkit key remapping required for Safari < 3.1 + * @property webkitKeymap + * @private + */ + webkitKeymap = { + 63232: 38, // up + 63233: 40, // down + 63234: 37, // left + 63235: 39, // right + 63276: 33, // page up + 63277: 34, // page down + 25: 9, // SHIFT-TAB (Safari provides a different key code in + // this case, even though the shiftKey modifier is set) + 63272: 46, // delete + 63273: 36, // home + 63275: 35 // end + }, + + /** + * Returns a wrapped node. Intended to be used on event targets, + * so it will return the node's parent if the target is a text + * node. + * + * If accessing a property of the node throws an error, this is + * probably the anonymous div wrapper Gecko adds inside text + * nodes. This likely will only occur when attempting to access + * the relatedTarget. In this case, we now return null because + * the anonymous div is completely useless and we do not know + * what the related target was because we can't even get to + * the element's parent node. + * + * @method resolve + * @private + */ + resolve = function(n) { + if (!n) { + return n; + } + try { + if (n && 3 == n.nodeType) { + n = n.parentNode; + } + } catch(e) { + return null; + } + + return Y.one(n); + }, + + DOMEventFacade = function(ev, currentTarget, wrapper) { + this._event = ev; + this._currentTarget = currentTarget; + this._wrapper = wrapper || EMPTY; + + // if not lazy init + this.init(); + }; + +Y.extend(DOMEventFacade, Object, { + + init: function() { + + var e = this._event, + overrides = this._wrapper.overrides, + x = e.pageX, + y = e.pageY, + c, + currentTarget = this._currentTarget; + + this.altKey = e.altKey; + this.ctrlKey = e.ctrlKey; + this.metaKey = e.metaKey; + this.shiftKey = e.shiftKey; + this.type = (overrides && overrides.type) || e.type; + this.clientX = e.clientX; + this.clientY = e.clientY; + + this.pageX = x; + this.pageY = y; + + // charCode is unknown in keyup, keydown. keyCode is unknown in keypress. + // FF 3.6 - 8+? pass 0 for keyCode in keypress events. + // Webkit, FF 3.6-8+?, and IE9+? pass 0 for charCode in keydown, keyup. + // Webkit and IE9+? duplicate charCode in keyCode. + // Opera never sets charCode, always keyCode (though with the charCode). + // IE6-8 don't set charCode or which. + // All browsers other than IE6-8 set which=keyCode in keydown, keyup, and + // which=charCode in keypress. + // + // Moral of the story: (e.which || e.keyCode) will always return the + // known code for that key event phase. e.keyCode is often different in + // keypress from keydown and keyup. + c = e.keyCode || e.charCode; + + if (ua.webkit && (c in webkitKeymap)) { + c = webkitKeymap[c]; + } + + this.keyCode = c; + this.charCode = c; + // Fill in e.which for IE - implementers should always use this over + // e.keyCode or e.charCode. + this.which = e.which || e.charCode || c; + // this.button = e.button; + this.button = this.which; + + this.target = resolve(e.target); + this.currentTarget = resolve(currentTarget); + this.relatedTarget = resolve(e.relatedTarget); + + if (e.type == "mousewheel" || e.type == "DOMMouseScroll") { + this.wheelDelta = (e.detail) ? (e.detail * -1) : Math.round(e.wheelDelta / 80) || ((e.wheelDelta < 0) ? -1 : 1); + } + + if (this._touch) { + this._touch(e, currentTarget, this._wrapper); + } + }, + + stopPropagation: function() { + this._event.stopPropagation(); + this._wrapper.stopped = 1; + this.stopped = 1; + }, + + stopImmediatePropagation: function() { + var e = this._event; + if (e.stopImmediatePropagation) { + e.stopImmediatePropagation(); + } else { + this.stopPropagation(); + } + this._wrapper.stopped = 2; + this.stopped = 2; + }, + + preventDefault: function(returnValue) { + var e = this._event; + e.preventDefault(); + if (returnValue) { + e.returnValue = returnValue; + } + this._wrapper.prevented = 1; + this.prevented = 1; + }, + + halt: function(immediate) { + if (immediate) { + this.stopImmediatePropagation(); + } else { + this.stopPropagation(); + } + + this.preventDefault(); + } + +}); + +DOMEventFacade.resolve = resolve; +Y.DOM2EventFacade = DOMEventFacade; +Y.DOMEventFacade = DOMEventFacade; + + /** + * The native event + * @property _event + * @type {DOMEvent} + * @private + */ + + /** + The name of the event (e.g. "click") + + @property type + @type {String} + **/ + + /** + `true` if the "alt" or "option" key is pressed. + + @property altKey + @type {Boolean} + **/ + + /** + `true` if the shift key is pressed. + + @property shiftKey + @type {Boolean} + **/ + + /** + `true` if the "Windows" key on a Windows keyboard, "command" key on an + Apple keyboard, or "meta" key on other keyboards is pressed. + + @property metaKey + @type {Boolean} + **/ + + /** + `true` if the "Ctrl" or "control" key is pressed. + + @property ctrlKey + @type {Boolean} + **/ + + /** + * The X location of the event on the page (including scroll) + * @property pageX + * @type {Number} + */ + + /** + * The Y location of the event on the page (including scroll) + * @property pageY + * @type {Number} + */ + + /** + * The X location of the event in the viewport + * @property clientX + * @type {Number} + */ + + /** + * The Y location of the event in the viewport + * @property clientY + * @type {Number} + */ + + /** + * The keyCode for key events. Uses charCode if keyCode is not available + * @property keyCode + * @type {Number} + */ + + /** + * The charCode for key events. Same as keyCode + * @property charCode + * @type {Number} + */ + + /** + * The button that was pushed. 1 for left click, 2 for middle click, 3 for + * right click. This is only reliably populated on `mouseup` events. + * @property button + * @type {Number} + */ + + /** + * The button that was pushed. Same as button. + * @property which + * @type {Number} + */ + + /** + * Node reference for the targeted element + * @property target + * @type {Node} + */ + + /** + * Node reference for the element that the listener was attached to. + * @property currentTarget + * @type {Node} + */ + + /** + * Node reference to the relatedTarget + * @property relatedTarget + * @type {Node} + */ + + /** + * Number representing the direction and velocity of the movement of the mousewheel. + * Negative is down, the higher the number, the faster. Applies to the mousewheel event. + * @property wheelDelta + * @type {Number} + */ + + /** + * Stops the propagation to the next bubble target + * @method stopPropagation + */ + + /** + * Stops the propagation to the next bubble target and + * prevents any additional listeners from being exectued + * on the current target. + * @method stopImmediatePropagation + */ + + /** + * Prevents the event's default behavior + * @method preventDefault + * @param returnValue {string} sets the returnValue of the event to this value + * (rather than the default false value). This can be used to add a customized + * confirmation query to the beforeunload event). + */ + + /** + * Stops the event propagation and prevents the default + * event behavior. + * @method halt + * @param immediate {boolean} if true additional listeners + * on the current target will not be executed + */ +(function() { + +/** + * The event utility provides functions to add and remove event listeners, + * event cleansing. It also tries to automatically remove listeners it + * registers during the unload event. + * @module event + * @main event + * @submodule event-base + */ + +/** + * The event utility provides functions to add and remove event listeners, + * event cleansing. It also tries to automatically remove listeners it + * registers during the unload event. + * + * @class Event + * @static + */ + +Y.Env.evt.dom_wrappers = {}; +Y.Env.evt.dom_map = {}; + +var _eventenv = Y.Env.evt, + config = Y.config, + win = config.win, + add = YUI.Env.add, + remove = YUI.Env.remove, + + onLoad = function() { + YUI.Env.windowLoaded = true; + Y.Event._load(); + remove(win, "load", onLoad); + }, + + onUnload = function() { + Y.Event._unload(); + }, + + EVENT_READY = 'domready', + + COMPAT_ARG = '~yui|2|compat~', + + shouldIterate = function(o) { + try { + // TODO: See if there's a more performant way to return true early on this, for the common case + return (o && typeof o !== "string" && Y.Lang.isNumber(o.length) && !o.tagName && !Y.DOM.isWindow(o)); + } catch(ex) { + return false; + } + }, + + // aliases to support DOM event subscription clean up when the last + // subscriber is detached. deleteAndClean overrides the DOM event's wrapper + // CustomEvent _delete method. + _ceProtoDelete = Y.CustomEvent.prototype._delete, + _deleteAndClean = function(s) { + var ret = _ceProtoDelete.apply(this, arguments); + + if (!this.hasSubs()) { + Y.Event._clean(this); + } + + return ret; + }, + +Event = function() { + + /** + * True after the onload event has fired + * @property _loadComplete + * @type boolean + * @static + * @private + */ + var _loadComplete = false, + + /** + * The number of times to poll after window.onload. This number is + * increased if additional late-bound handlers are requested after + * the page load. + * @property _retryCount + * @static + * @private + */ + _retryCount = 0, + + /** + * onAvailable listeners + * @property _avail + * @static + * @private + */ + _avail = [], + + /** + * Custom event wrappers for DOM events. Key is + * 'event:' + Element uid stamp + event type + * @property _wrappers + * @type CustomEvent + * @static + * @private + */ + _wrappers = _eventenv.dom_wrappers, + + _windowLoadKey = null, + + /** + * Custom event wrapper map DOM events. Key is + * Element uid stamp. Each item is a hash of custom event + * wrappers as provided in the _wrappers collection. This + * provides the infrastructure for getListeners. + * @property _el_events + * @static + * @private + */ + _el_events = _eventenv.dom_map; + + return { + + /** + * The number of times we should look for elements that are not + * in the DOM at the time the event is requested after the document + * has been loaded. The default is 1000@amp;40 ms, so it will poll + * for 40 seconds or until all outstanding handlers are bound + * (whichever comes first). + * @property POLL_RETRYS + * @type int + * @static + * @final + */ + POLL_RETRYS: 1000, + + /** + * The poll interval in milliseconds + * @property POLL_INTERVAL + * @type int + * @static + * @final + */ + POLL_INTERVAL: 40, + + /** + * addListener/removeListener can throw errors in unexpected scenarios. + * These errors are suppressed, the method returns false, and this property + * is set + * @property lastError + * @static + * @type Error + */ + lastError: null, + + + /** + * poll handle + * @property _interval + * @static + * @private + */ + _interval: null, + + /** + * document readystate poll handle + * @property _dri + * @static + * @private + */ + _dri: null, + + /** + * True when the document is initially usable + * @property DOMReady + * @type boolean + * @static + */ + DOMReady: false, + + /** + * @method startInterval + * @static + * @private + */ + startInterval: function() { + if (!Event._interval) { +Event._interval = setInterval(Event._poll, Event.POLL_INTERVAL); + } + }, + + /** + * Executes the supplied callback when the item with the supplied + * id is found. This is meant to be used to execute behavior as + * soon as possible as the page loads. If you use this after the + * initial page load it will poll for a fixed time for the element. + * The number of times it will poll and the frequency are + * configurable. By default it will poll for 10 seconds. + * + * <p>The callback is executed with a single parameter: + * the custom object parameter, if provided.</p> + * + * @method onAvailable + * + * @param {string||string[]} id the id of the element, or an array + * of ids to look for. + * @param {function} fn what to execute when the element is found. + * @param {object} p_obj an optional object to be passed back as + * a parameter to fn. + * @param {boolean|object} p_override If set to true, fn will execute + * in the context of p_obj, if set to an object it + * will execute in the context of that object + * @param checkContent {boolean} check child node readiness (onContentReady) + * @static + * @deprecated Use Y.on("available") + */ + // @TODO fix arguments + onAvailable: function(id, fn, p_obj, p_override, checkContent, compat) { + + var a = Y.Array(id), i, availHandle; + + for (i=0; i<a.length; i=i+1) { + _avail.push({ + id: a[i], + fn: fn, + obj: p_obj, + override: p_override, + checkReady: checkContent, + compat: compat + }); + } + _retryCount = this.POLL_RETRYS; + + // We want the first test to be immediate, but async + setTimeout(Event._poll, 0); + + availHandle = new Y.EventHandle({ + + _delete: function() { + // set by the event system for lazy DOM listeners + if (availHandle.handle) { + availHandle.handle.detach(); + return; + } + + var i, j; + + // otherwise try to remove the onAvailable listener(s) + for (i = 0; i < a.length; i++) { + for (j = 0; j < _avail.length; j++) { + if (a[i] === _avail[j].id) { + _avail.splice(j, 1); + } + } + } + } + + }); + + return availHandle; + }, + + /** + * Works the same way as onAvailable, but additionally checks the + * state of sibling elements to determine if the content of the + * available element is safe to modify. + * + * <p>The callback is executed with a single parameter: + * the custom object parameter, if provided.</p> + * + * @method onContentReady + * + * @param {string} id the id of the element to look for. + * @param {function} fn what to execute when the element is ready. + * @param {object} obj an optional object to be passed back as + * a parameter to fn. + * @param {boolean|object} override If set to true, fn will execute + * in the context of p_obj. If an object, fn will + * exectute in the context of that object + * + * @static + * @deprecated Use Y.on("contentready") + */ + // @TODO fix arguments + onContentReady: function(id, fn, obj, override, compat) { + return Event.onAvailable(id, fn, obj, override, true, compat); + }, + + /** + * Adds an event listener + * + * @method attach + * + * @param {String} type The type of event to append + * @param {Function} fn The method the event invokes + * @param {String|HTMLElement|Array|NodeList} el An id, an element + * reference, or a collection of ids and/or elements to assign the + * listener to. + * @param {Object} context optional context object + * @param {Boolean|object} args 0..n arguments to pass to the callback + * @return {EventHandle} an object to that can be used to detach the listener + * + * @static + */ + + attach: function(type, fn, el, context) { + return Event._attach(Y.Array(arguments, 0, true)); + }, + + _createWrapper: function (el, type, capture, compat, facade) { + + var cewrapper, + ek = Y.stamp(el), + key = 'event:' + ek + type; + + if (false === facade) { + key += 'native'; + } + if (capture) { + key += 'capture'; + } + + + cewrapper = _wrappers[key]; + + + if (!cewrapper) { + // create CE wrapper + cewrapper = Y.publish(key, { + silent: true, + bubbles: false, + emitFacade:false, + contextFn: function() { + if (compat) { + return cewrapper.el; + } else { + cewrapper.nodeRef = cewrapper.nodeRef || Y.one(cewrapper.el); + return cewrapper.nodeRef; + } + } + }); + + cewrapper.overrides = {}; + + // for later removeListener calls + cewrapper.el = el; + cewrapper.key = key; + cewrapper.domkey = ek; + cewrapper.type = type; + cewrapper.fn = function(e) { + cewrapper.fire(Event.getEvent(e, el, (compat || (false === facade)))); + }; + cewrapper.capture = capture; + + if (el == win && type == "load") { + // window load happens once + cewrapper.fireOnce = true; + _windowLoadKey = key; + } + cewrapper._delete = _deleteAndClean; + + _wrappers[key] = cewrapper; + _el_events[ek] = _el_events[ek] || {}; + _el_events[ek][key] = cewrapper; + + add(el, type, cewrapper.fn, capture); + } + + return cewrapper; + + }, + + _attach: function(args, conf) { + + var compat, + handles, oEl, cewrapper, context, + fireNow = false, ret, + type = args[0], + fn = args[1], + el = args[2] || win, + facade = conf && conf.facade, + capture = conf && conf.capture, + overrides = conf && conf.overrides; + + if (args[args.length-1] === COMPAT_ARG) { + compat = true; + } + + if (!fn || !fn.call) { + return false; + } + + // The el argument can be an array of elements or element ids. + if (shouldIterate(el)) { + + handles=[]; + + Y.each(el, function(v, k) { + args[2] = v; + handles.push(Event._attach(args.slice(), conf)); + }); + + // return (handles.length === 1) ? handles[0] : handles; + return new Y.EventHandle(handles); + + // If the el argument is a string, we assume it is + // actually the id of the element. If the page is loaded + // we convert el to the actual element, otherwise we + // defer attaching the event until the element is + // ready + } else if (Y.Lang.isString(el)) { + + // oEl = (compat) ? Y.DOM.byId(el) : Y.Selector.query(el); + + if (compat) { + oEl = Y.DOM.byId(el); + } else { + + oEl = Y.Selector.query(el); + + switch (oEl.length) { + case 0: + oEl = null; + break; + case 1: + oEl = oEl[0]; + break; + default: + args[2] = oEl; + return Event._attach(args, conf); + } + } + + if (oEl) { + + el = oEl; + + // Not found = defer adding the event until the element is available + } else { + + ret = Event.onAvailable(el, function() { + + ret.handle = Event._attach(args, conf); + + }, Event, true, false, compat); + + return ret; + + } + } + + // Element should be an html element or node + if (!el) { + return false; + } + + if (Y.Node && Y.instanceOf(el, Y.Node)) { + el = Y.Node.getDOMNode(el); + } + + cewrapper = Event._createWrapper(el, type, capture, compat, facade); + if (overrides) { + Y.mix(cewrapper.overrides, overrides); + } + + if (el == win && type == "load") { + + // if the load is complete, fire immediately. + // all subscribers, including the current one + // will be notified. + if (YUI.Env.windowLoaded) { + fireNow = true; + } + } + + if (compat) { + args.pop(); + } + + context = args[3]; + + // set context to the Node if not specified + // ret = cewrapper.on.apply(cewrapper, trimmedArgs); + ret = cewrapper._on(fn, context, (args.length > 4) ? args.slice(4) : null); + + if (fireNow) { + cewrapper.fire(); + } + + return ret; + + }, + + /** + * Removes an event listener. Supports the signature the event was bound + * with, but the preferred way to remove listeners is using the handle + * that is returned when using Y.on + * + * @method detach + * + * @param {String} type the type of event to remove. + * @param {Function} fn the method the event invokes. If fn is + * undefined, then all event handlers for the type of event are + * removed. + * @param {String|HTMLElement|Array|NodeList|EventHandle} el An + * event handle, an id, an element reference, or a collection + * of ids and/or elements to remove the listener from. + * @return {boolean} true if the unbind was successful, false otherwise. + * @static + */ + detach: function(type, fn, el, obj) { + + var args=Y.Array(arguments, 0, true), compat, l, ok, i, + id, ce; + + if (args[args.length-1] === COMPAT_ARG) { + compat = true; + // args.pop(); + } + + if (type && type.detach) { + return type.detach(); + } + + // The el argument can be a string + if (typeof el == "string") { + + // el = (compat) ? Y.DOM.byId(el) : Y.all(el); + if (compat) { + el = Y.DOM.byId(el); + } else { + el = Y.Selector.query(el); + l = el.length; + if (l < 1) { + el = null; + } else if (l == 1) { + el = el[0]; + } + } + // return Event.detach.apply(Event, args); + } + + if (!el) { + return false; + } + + if (el.detach) { + args.splice(2, 1); + return el.detach.apply(el, args); + // The el argument can be an array of elements or element ids. + } else if (shouldIterate(el)) { + ok = true; + for (i=0, l=el.length; i<l; ++i) { + args[2] = el[i]; + ok = ( Y.Event.detach.apply(Y.Event, args) && ok ); + } + + return ok; + } + + if (!type || !fn || !fn.call) { + return Event.purgeElement(el, false, type); + } + + id = 'event:' + Y.stamp(el) + type; + ce = _wrappers[id]; + + if (ce) { + return ce.detach(fn); + } else { + return false; + } + + }, + + /** + * Finds the event in the window object, the caller's arguments, or + * in the arguments of another method in the callstack. This is + * executed automatically for events registered through the event + * manager, so the implementer should not normally need to execute + * this function at all. + * @method getEvent + * @param {Event} e the event parameter from the handler + * @param {HTMLElement} el the element the listener was attached to + * @return {Event} the event + * @static + */ + getEvent: function(e, el, noFacade) { + var ev = e || win.event; + + return (noFacade) ? ev : + new Y.DOMEventFacade(ev, el, _wrappers['event:' + Y.stamp(el) + e.type]); + }, + + /** + * Generates an unique ID for the element if it does not already + * have one. + * @method generateId + * @param el the element to create the id for + * @return {string} the resulting id of the element + * @static + */ + generateId: function(el) { + return Y.DOM.generateID(el); + }, + + /** + * We want to be able to use getElementsByTagName as a collection + * to attach a group of events to. Unfortunately, different + * browsers return different types of collections. This function + * tests to determine if the object is array-like. It will also + * fail if the object is an array, but is empty. + * @method _isValidCollection + * @param o the object to test + * @return {boolean} true if the object is array-like and populated + * @deprecated was not meant to be used directly + * @static + * @private + */ + _isValidCollection: shouldIterate, + + /** + * hook up any deferred listeners + * @method _load + * @static + * @private + */ + _load: function(e) { + if (!_loadComplete) { + _loadComplete = true; + + // Just in case DOMReady did not go off for some reason + // E._ready(); + if (Y.fire) { + Y.fire(EVENT_READY); + } + + // Available elements may not have been detected before the + // window load event fires. Try to find them now so that the + // the user is more likely to get the onAvailable notifications + // before the window load notification + Event._poll(); + } + }, + + /** + * Polling function that runs before the onload event fires, + * attempting to attach to DOM Nodes as soon as they are + * available + * @method _poll + * @static + * @private + */ + _poll: function() { + if (Event.locked) { + return; + } + + if (Y.UA.ie && !YUI.Env.DOMReady) { + // Hold off if DOMReady has not fired and check current + // readyState to protect against the IE operation aborted + // issue. + Event.startInterval(); + return; + } + + Event.locked = true; + + // keep trying until after the page is loaded. We need to + // check the page load state prior to trying to bind the + // elements so that we can be certain all elements have been + // tested appropriately + var i, len, item, el, notAvail, executeItem, + tryAgain = !_loadComplete; + + if (!tryAgain) { + tryAgain = (_retryCount > 0); + } + + // onAvailable + notAvail = []; + + executeItem = function (el, item) { + var context, ov = item.override; + try { + if (item.compat) { + if (item.override) { + if (ov === true) { + context = item.obj; + } else { + context = ov; + } + } else { + context = el; + } + item.fn.call(context, item.obj); + } else { + context = item.obj || Y.one(el); + item.fn.apply(context, (Y.Lang.isArray(ov)) ? ov : []); + } + } catch (e) { + } + }; + + // onAvailable + for (i=0,len=_avail.length; i<len; ++i) { + item = _avail[i]; + if (item && !item.checkReady) { + + // el = (item.compat) ? Y.DOM.byId(item.id) : Y.one(item.id); + el = (item.compat) ? Y.DOM.byId(item.id) : Y.Selector.query(item.id, null, true); + + if (el) { + executeItem(el, item); + _avail[i] = null; + } else { + notAvail.push(item); + } + } + } + + // onContentReady + for (i=0,len=_avail.length; i<len; ++i) { + item = _avail[i]; + if (item && item.checkReady) { + + // el = (item.compat) ? Y.DOM.byId(item.id) : Y.one(item.id); + el = (item.compat) ? Y.DOM.byId(item.id) : Y.Selector.query(item.id, null, true); + + if (el) { + // The element is available, but not necessarily ready + // @todo should we test parentNode.nextSibling? + if (_loadComplete || (el.get && el.get('nextSibling')) || el.nextSibling) { + executeItem(el, item); + _avail[i] = null; + } + } else { + notAvail.push(item); + } + } + } + + _retryCount = (notAvail.length === 0) ? 0 : _retryCount - 1; + + if (tryAgain) { + // we may need to strip the nulled out items here + Event.startInterval(); + } else { + clearInterval(Event._interval); + Event._interval = null; + } + + Event.locked = false; + + return; + + }, + + /** + * Removes all listeners attached to the given element via addListener. + * Optionally, the node's children can also be purged. + * Optionally, you can specify a specific type of event to remove. + * @method purgeElement + * @param {HTMLElement} el the element to purge + * @param {boolean} recurse recursively purge this element's children + * as well. Use with caution. + * @param {string} type optional type of listener to purge. If + * left out, all listeners will be removed + * @static + */ + purgeElement: function(el, recurse, type) { + // var oEl = (Y.Lang.isString(el)) ? Y.one(el) : el, + var oEl = (Y.Lang.isString(el)) ? Y.Selector.query(el, null, true) : el, + lis = Event.getListeners(oEl, type), i, len, children, child; + + if (recurse && oEl) { + lis = lis || []; + children = Y.Selector.query('*', oEl); + len = children.length; + for (i = 0; i < len; ++i) { + child = Event.getListeners(children[i], type); + if (child) { + lis = lis.concat(child); + } + } + } + + if (lis) { + for (i = 0, len = lis.length; i < len; ++i) { + lis[i].detachAll(); + } + } + + }, + + /** + * Removes all object references and the DOM proxy subscription for + * a given event for a DOM node. + * + * @method _clean + * @param wrapper {CustomEvent} Custom event proxy for the DOM + * subscription + * @private + * @static + * @since 3.4.0 + */ + _clean: function (wrapper) { + var key = wrapper.key, + domkey = wrapper.domkey; + + remove(wrapper.el, wrapper.type, wrapper.fn, wrapper.capture); + delete _wrappers[key]; + delete Y._yuievt.events[key]; + if (_el_events[domkey]) { + delete _el_events[domkey][key]; + if (!Y.Object.size(_el_events[domkey])) { + delete _el_events[domkey]; + } + } + }, + + /** + * Returns all listeners attached to the given element via addListener. + * Optionally, you can specify a specific type of event to return. + * @method getListeners + * @param el {HTMLElement|string} the element or element id to inspect + * @param type {string} optional type of listener to return. If + * left out, all listeners will be returned + * @return {CustomEvent} the custom event wrapper for the DOM event(s) + * @static + */ + getListeners: function(el, type) { + var ek = Y.stamp(el, true), evts = _el_events[ek], + results=[] , key = (type) ? 'event:' + ek + type : null, + adapters = _eventenv.plugins; + + if (!evts) { + return null; + } + + if (key) { + // look for synthetic events + if (adapters[type] && adapters[type].eventDef) { + key += '_synth'; + } + + if (evts[key]) { + results.push(evts[key]); + } + + // get native events as well + key += 'native'; + if (evts[key]) { + results.push(evts[key]); + } + + } else { + Y.each(evts, function(v, k) { + results.push(v); + }); + } + + return (results.length) ? results : null; + }, + + /** + * Removes all listeners registered by pe.event. Called + * automatically during the unload event. + * @method _unload + * @static + * @private + */ + _unload: function(e) { + Y.each(_wrappers, function(v, k) { + if (v.type == 'unload') { + v.fire(e); + } + v.detachAll(); + }); + remove(win, "unload", onUnload); + }, + + /** + * Adds a DOM event directly without the caching, cleanup, context adj, etc + * + * @method nativeAdd + * @param {HTMLElement} el the element to bind the handler to + * @param {string} type the type of event handler + * @param {function} fn the callback to invoke + * @param {Boolean} capture capture or bubble phase + * @static + * @private + */ + nativeAdd: add, + + /** + * Basic remove listener + * + * @method nativeRemove + * @param {HTMLElement} el the element to bind the handler to + * @param {string} type the type of event handler + * @param {function} fn the callback to invoke + * @param {Boolean} capture capture or bubble phase + * @static + * @private + */ + nativeRemove: remove + }; + +}(); + +Y.Event = Event; + +if (config.injected || YUI.Env.windowLoaded) { + onLoad(); +} else { + add(win, "load", onLoad); +} + +// Process onAvailable/onContentReady items when when the DOM is ready in IE +if (Y.UA.ie) { + Y.on(EVENT_READY, Event._poll); + + // In IE6 and below, detach event handlers when the page is unloaded in + // order to try and prevent cross-page memory leaks. This isn't done in + // other browsers because a) it's not necessary, and b) it breaks the + // back/forward cache. + if (Y.UA.ie < 7) { + try { + add(win, "unload", onUnload); + } catch(e) { + } + } +} + +Event.Custom = Y.CustomEvent; +Event.Subscriber = Y.Subscriber; +Event.Target = Y.EventTarget; +Event.Handle = Y.EventHandle; +Event.Facade = Y.EventFacade; + +Event._poll(); + +}()); + +/** + * DOM event listener abstraction layer + * @module event + * @submodule event-base + */ + +/** + * Executes the callback as soon as the specified element + * is detected in the DOM. This function expects a selector + * string for the element(s) to detect. If you already have + * an element reference, you don't need this event. + * @event available + * @param type {string} 'available' + * @param fn {function} the callback function to execute. + * @param el {string} an selector for the element(s) to attach + * @param context optional argument that specifies what 'this' refers to. + * @param args* 0..n additional arguments to pass on to the callback function. + * These arguments will be added after the event object. + * @return {EventHandle} the detach handle + * @for YUI + */ +Y.Env.evt.plugins.available = { + on: function(type, fn, id, o) { + var a = arguments.length > 4 ? Y.Array(arguments, 4, true) : null; + return Y.Event.onAvailable.call(Y.Event, id, fn, o, a); + } +}; + +/** + * Executes the callback as soon as the specified element + * is detected in the DOM with a nextSibling property + * (indicating that the element's children are available). + * This function expects a selector + * string for the element(s) to detect. If you already have + * an element reference, you don't need this event. + * @event contentready + * @param type {string} 'contentready' + * @param fn {function} the callback function to execute. + * @param el {string} an selector for the element(s) to attach. + * @param context optional argument that specifies what 'this' refers to. + * @param args* 0..n additional arguments to pass on to the callback function. + * These arguments will be added after the event object. + * @return {EventHandle} the detach handle + * @for YUI + */ +Y.Env.evt.plugins.contentready = { + on: function(type, fn, id, o) { + var a = arguments.length > 4 ? Y.Array(arguments, 4, true) : null; + return Y.Event.onContentReady.call(Y.Event, id, fn, o, a); + } +}; + + +}, '3.17.2', {"requires": ["event-custom-base"]});
Added: roller/trunk/app/src/main/webapp/roller-ui/yui3/event-custom-base/event-custom-base-min.js URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/webapp/roller-ui/yui3/event-custom-base/event-custom-base-min.js?rev=1609737&view=auto ============================================================================== --- roller/trunk/app/src/main/webapp/roller-ui/yui3/event-custom-base/event-custom-base-min.js (added) +++ roller/trunk/app/src/main/webapp/roller-ui/yui3/event-custom-base/event-custom-base-min.js Fri Jul 11 16:23:25 2014 @@ -0,0 +1,10 @@ +/* +YUI 3.17.2 (build 9c3c78e) +Copyright 2014 Yahoo! Inc. All rights reserved. +Licensed under the BSD License. +http://yuilibrary.com/license/ +*/ + +YUI.add("event-custom-base",function(e,t){e.Env.evt={handles:{},plugins:{}};var n=0,r=1,i={objs:null,before:function(t,r,i,s){var o=t,u;return s&&(u=[t,s].concat(e.Array(arguments,4,!0)),o=e.rbind.apply(e,u)),this._inject(n,o,r,i)},after:function(t,n,i,s){var o=t,u;return s&&(u=[t,s].concat(e.Array(arguments,4,!0)),o=e.rbind.apply(e,u)),this._inject(r,o,n,i)},_inject:function(t,n,r,i){var s=e.stamp(r),o,u;return r._yuiaop||(r._yuiaop={}),o=r._yuiaop,o[i]||(o[i]=new e.Do.Method(r,i),r[i]=function(){return o[i].exec.apply(o[i],arguments)}),u=s+e.stamp(n)+i,o[i].register(u,n,t),new e.EventHandle(o[i],u)},detach:function(e){e.detach&&e.detach()}};e.Do=i,i.Method=function(e,t){this.obj=e,this.methodName=t,this.method=e[t],this.before={},this.after={}},i.Method.prototype.register=function(e,t,n){n?this.after[e]=t:this.before[e]=t},i.Method.prototype._delete=function(e){delete this.before[e],delete this.after[e]},i.Method.prototype.exec=function(){var t=e.Array(arguments,0,!0),n,r,s,o=this .before,u=this.after,a=!1;for(n in o)if(o.hasOwnProperty(n)){r=o[n].apply(this.obj,t);if(r)switch(r.constructor){case i.Halt:return r.retVal;case i.AlterArgs:t=r.newArgs;break;case i.Prevent:a=!0;break;default:}}a||(r=this.method.apply(this.obj,t)),i.originalRetVal=r,i.currentRetVal=r;for(n in u)if(u.hasOwnProperty(n)){s=u[n].apply(this.obj,t);if(s&&s.constructor===i.Halt)return s.retVal;s&&s.constructor===i.AlterReturn&&(r=s.newRetVal,i.currentRetVal=r)}return r},i.AlterArgs=function(e,t){this.msg=e,this.newArgs=t},i.AlterReturn=function(e,t){this.msg=e,this.newRetVal=t},i.Halt=function(e,t){this.msg=e,this.retVal=t},i.Prevent=function(e){this.msg=e},i.Error=i.Halt;var s=e.Array,o="after",u=["broadcast","monitored","bubbles","context","contextFn","currentTarget","defaultFn","defaultTargetOnly","details","emitFacade","fireOnce","async","host","preventable","preventedFn","queuable","silent","stoppedFn","target","type"],a=s.hash(u),f=Array.prototype.slice,l=9,c="yui:log",h=function(e, t,n){var r;for(r in t)a[r]&&(n||!(r in e))&&(e[r]=t[r]);return e};e.CustomEvent=function(t,n){this._kds=e.CustomEvent.keepDeprecatedSubs,this.id=e.guid(),this.type=t,this.silent=this.logSystem=t===c,this._kds&&(this.subscribers={},this.afters={}),n&&h(this,n,!0)},e.CustomEvent.keepDeprecatedSubs=!1,e.CustomEvent.mixConfigs=h,e.CustomEvent.prototype={constructor:e.CustomEvent,signature:l,context:e,preventable:!0,bubbles:!0,hasSubs:function(e){var t=0,n=0,r=this._subscribers,i=this._afters,s=this.sibling;return r&&(t=r.length),i&&(n=i.length),s&&(r=s._subscribers,i=s._afters,r&&(t+=r.length),i&&(n+=i.length)),e?e==="after"?n:t:t+n},monitor:function(e){this.monitored=!0;var t=this.id+"|"+this.type+"_"+e,n=f.call(arguments,0);return n[0]=t,this.host.on.apply(this.host,n)},getSubs:function(){var e=this.sibling,t=this._subscribers,n=this._afters,r,i;return e&&(r=e._subscribers,i=e._afters),r?t?t=t.concat(r):t=r.concat():t?t=t.concat():t=[],i?n?n=n.concat(i):n=i.concat():n?n=n.concat():n=[ ],[t,n]},applyConfig:function(e,t){h(this,e,t)},_on:function(t,n,r,i){var s=new e.Subscriber(t,n,r,i),u;return this.fireOnce&&this.fired&&(u=this.firedWith,this.emitFacade&&this._addFacadeToArgs&&this._addFacadeToArgs(u),this.async?setTimeout(e.bind(this._notify,this,s,u),0):this._notify(s,u)),i===o?(this._afters||(this._afters=[]),this._afters.push(s)):(this._subscribers||(this._subscribers=[]),this._subscribers.push(s)),this._kds&&(i===o?this.afters[s.id]=s:this.subscribers[s.id]=s),new e.EventHandle(this,s)},subscribe:function(e,t){var n=arguments.length>2?f.call(arguments,2):null;return this._on(e,t,n,!0)},on:function(e,t){var n=arguments.length>2?f.call(arguments,2):null;return this.monitored&&this.host&&this.host._monitor("attach",this,{args:arguments}),this._on(e,t,n,!0)},after:function(e,t){var n=arguments.length>2?f.call(arguments,2):null;return this._on(e,t,n,o)},detach:function(e,t){if(e&&e.detach)return e.detach();var n,r,i=0,s=this._subscribers,o=this._afters;if(s)for(n =s.length;n>=0;n--)r=s[n],r&&(!e||e===r.fn)&&(this._delete(r,s,n),i++);if(o)for(n=o.length;n>=0;n--)r=o[n],r&&(!e||e===r.fn)&&(this._delete(r,o,n),i++);return i},unsubscribe:function(){return this.detach.apply(this,arguments)},_notify:function(e,t,n){var r;return r=e.notify(t,this),!1===r||this.stopped>1?!1:!0},log:function(e,t){},fire:function(){var e=[];return e.push.apply(e,arguments),this._fire(e)},_fire:function(e){return this.fireOnce&&this.fired?!0:(this.fired=!0,this.fireOnce&&(this.firedWith=e),this.emitFacade?this.fireComplex(e):this.fireSimple(e))},fireSimple:function(e){this.stopped=0,this.prevented=0;if(this.hasSubs()){var t=this.getSubs();this._procSubs(t[0],e),this._procSubs(t[1],e)}return this.broadcast&&this._broadcast(e),this.stopped?!1:!0},fireComplex:function(e){return e[0]=e[0]||{},this.fireSimple(e)},_procSubs:function(e,t,n){var r,i,s;for(i=0,s=e.length;i<s;i++){r=e[i];if(r&&r.fn){!1===this._notify(r,t,n)&&(this.stopped=2);if(this.stopped===2)return!1}}return! 0},_broadcast:function(t){if(!this.stopped&&this.broadcast){var n=t.concat();n.unshift(this.type),this.host!==e&&e.fire.apply(e,n),this.broadcast===2&&e.Global.fire.apply(e.Global,n)}},unsubscribeAll:function(){return this.detachAll.apply(this,arguments)},detachAll:function(){return this.detach()},_delete:function(e,t,n){var r=e._when;t||(t=r===o?this._afters:this._subscribers),t&&(n=s.indexOf(t,e,0),e&&t[n]===e&&t.splice(n,1)),this._kds&&(r===o?delete this.afters[e.id]:delete this.subscribers[e.id]),this.monitored&&this.host&&this.host._monitor("detach",this,{ce:this,sub:e}),e&&(e.deleted=!0)}},e.Subscriber=function(t,n,r,i){this.fn=t,this.context=n,this.id=e.guid(),this.args=r,this._when=i},e.Subscriber.prototype={constructor:e.Subscriber,_notify:function(e,t,n){if(this.deleted&&!this.postponed){if(!this.postponed)return delete this.postponed,null;delete this.fn,delete this.context}var r=this.args,i;switch(n.signature){case 0:i=this.fn.call(e,n.type,t,e);break;case 1:i=this.fn.cal l(e,t[0]||null,e);break; +default:r||t?(t=t||[],r=r?t.concat(r):t,i=this.fn.apply(e,r)):i=this.fn.call(e)}return this.once&&n._delete(this),i},notify:function(t,n){var r=this.context,i=!0;r||(r=n.contextFn?n.contextFn():n.context);if(e.config&&e.config.throwFail)i=this._notify(r,t,n);else try{i=this._notify(r,t,n)}catch(s){e.error(this+" failed: "+s.message,s)}return i},contains:function(e,t){return t?this.fn===e&&this.context===t:this.fn===e},valueOf:function(){return this.id}},e.EventHandle=function(e,t){this.evt=e,this.sub=t},e.EventHandle.prototype={batch:function(t,n){t.call(n||this,this),e.Lang.isArray(this.evt)&&e.Array.each(this.evt,function(e){e.batch.call(n||e,t)})},detach:function(){var t=this.evt,n=0,r;if(t)if(e.Lang.isArray(t))for(r=0;r<t.length;r++)n+=t[r].detach();else t._delete(this.sub),n=1;return n},monitor:function(e){return this.evt.monitor.apply(this.evt,arguments)}};var p=e.Lang,d=":",v="|",m="~AFTER~",g=/(.*?)(:)(.*?)/,y=e.cached(function(e){return e.replace(g,"*$2$3")}),b=function(e,t ){return!t||!e||e.indexOf(d)>-1?e:t+d+e},w=e.cached(function(e,t){var n=e,r,i,s;return p.isString(n)?(s=n.indexOf(m),s>-1&&(i=!0,n=n.substr(m.length)),s=n.indexOf(v),s>-1&&(r=n.substr(0,s),n=n.substr(s+1),n==="*"&&(n=null)),[r,t?b(n,t):n,i,n]):n}),E=function(t){var n=this._yuievt,r;n||(n=this._yuievt={events:{},targets:null,config:{host:this,context:this},chain:e.config.chain}),r=n.config,t&&(h(r,t,!0),t.chain!==undefined&&(n.chain=t.chain),t.prefix&&(r.prefix=t.prefix))};E.prototype={constructor:E,once:function(){var e=this.on.apply(this,arguments);return e.batch(function(e){e.sub&&(e.sub.once=!0)}),e},onceAfter:function(){var e=this.after.apply(this,arguments);return e.batch(function(e){e.sub&&(e.sub.once=!0)}),e},parseType:function(e,t){return w(e,t||this._yuievt.config.prefix)},on:function(t,n,r){var i=this._yuievt,s=w(t,i.config.prefix),o,u,a,l,c,h,d,v=e.Env.evt.handles,g,y,b,E=e.Node,S,x,T;this._monitor("attach",s[1],{args:arguments,category:s[0],after:s[2]});if(p.isObject(t)) return p.isFunction(t)?e.Do.before.apply(e.Do,arguments):(o=n,u=r,a=f.call(arguments,0),l=[],p.isArray(t)&&(T=!0),g=t._after,delete t._after,e.each(t,function(e,t){p.isObject(e)&&(o=e.fn||(p.isFunction(e)?e:o),u=e.context||u);var n=g?m:"";a[0]=n+(T?e:t),a[1]=o,a[2]=u,l.push(this.on.apply(this,a))},this),i.chain?this:new e.EventHandle(l));h=s[0],g=s[2],b=s[3];if(E&&e.instanceOf(this,E)&&b in E.DOM_EVENTS)return a=f.call(arguments,0),a.splice(2,0,E.getDOMNode(this)),e.on.apply(e,a);t=s[1];if(e.instanceOf(this,YUI)){y=e.Env.evt.plugins[t],a=f.call(arguments,0),a[0]=b,E&&(S=a[2],e.instanceOf(S,e.NodeList)?S=e.NodeList.getDOMNodes(S):e.instanceOf(S,E)&&(S=E.getDOMNode(S)),x=b in E.DOM_EVENTS,x&&(a[2]=S));if(y)d=y.on.apply(e,a);else if(!t||x)d=e.Event._attach(a)}return d||(c=i.events[t]||this.publish(t),d=c._on(n,r,arguments.length>3?f.call(arguments,3):null,g?"after":!0),t.indexOf("*:")!==-1&&(this._hasSiblings=!0)),h&&(v[h]=v[h]||{},v[h][t]=v[h][t]||[],v[h][t].push(d)),i.chain?this:d},s ubscribe:function(){return this.on.apply(this,arguments)},detach:function(t,n,r){var i=this._yuievt.events,s,o=e.Node,u=o&&e.instanceOf(this,o);if(!t&&this!==e){for(s in i)i.hasOwnProperty(s)&&i[s].detach(n,r);return u&&e.Event.purgeElement(o.getDOMNode(this)),this}var a=w(t,this._yuievt.config.prefix),l=p.isArray(a)?a[0]:null,c=a?a[3]:null,h,d=e.Env.evt.handles,v,m,g,y,b=function(e,t,n){var r=e[t],i,s;if(r)for(s=r.length-1;s>=0;--s)i=r[s].evt,(i.host===n||i.el===n)&&r[s].detach()};if(l){m=d[l],t=a[1],v=u?e.Node.getDOMNode(this):this;if(m){if(t)b(m,t,v);else for(s in m)m.hasOwnProperty(s)&&b(m,s,v);return this}}else{if(p.isObject(t)&&t.detach)return t.detach(),this;if(u&&(!c||c in o.DOM_EVENTS))return g=f.call(arguments,0),g[2]=o.getDOMNode(this),e.detach.apply(e,g),this}h=e.Env.evt.plugins[c];if(e.instanceOf(this,YUI)){g=f.call(arguments,0);if(h&&h.detach)return h.detach.apply(e,g),this;if(!t||!h&&o&&t in o.DOM_EVENTS)return g[0]=t,e.Event.detach.apply(e.Event,g),this}return y=i[a[ 1]],y&&y.detach(n,r),this},unsubscribe:function(){return this.detach.apply(this,arguments)},detachAll:function(e){return this.detach(e)},unsubscribeAll:function(){return this.detachAll.apply(this,arguments)},publish:function(t,n){var r,i=this._yuievt,s=i.config,o=s.prefix;return typeof t=="string"?(o&&(t=b(t,o)),r=this._publish(t,s,n)):(r={},e.each(t,function(e,t){o&&(t=b(t,o)),r[t]=this._publish(t,s,e||n)},this)),r},_getFullType:function(e){var t=this._yuievt.config.prefix;return t?t+d+e:e},_publish:function(t,n,r){var i,s=this._yuievt,o=s.config,u=o.host,a=o.context,f=s.events;return i=f[t],(o.monitored&&!i||i&&i.monitored)&&this._monitor("publish",t,{args:arguments}),i||(i=f[t]=new e.CustomEvent(t,n),n||(i.host=u,i.context=a)),r&&h(i,r,!0),i},_monitor:function(e,t,n){var r,i,s;if(t){typeof t=="string"?(s=t,i=this.getEvent(t,!0)):(i=t,s=t.type);if(this._yuievt.config.monitored&&(!i||i.monitored)||i&&i.monitored)r=s+"_"+e,n.monitored=e,this.fire.call(this,r,n)}},fire:function(e){va r t=typeof e=="string",n=arguments.length,r=e,i=this._yuievt,s=i.config,o=s.prefix,u,a,l,c;t&&n<=3?n===2?c=[arguments[1]]:n===3?c=[arguments[1],arguments[2]]:c=[]:c=f.call(arguments,t?1:0),t||(r=e&&e.type),o&&(r=b(r,o)),a=i.events[r],this._hasSiblings&&(l=this.getSibling(r,a),l&&!a&&(a=this.publish(r))),(s.monitored&&(!a||a.monitored)||a&&a.monitored)&&this._monitor("fire",a||r,{args:c});if(!a){if(i.hasTargets)return this.bubble({type:r},c,this);u=!0}else l&&(a.sibling=l),u=a._fire(c);return i.chain?this:u},getSibling:function(e,t){var n;return e.indexOf(d)>-1&&(e=y(e),n=this.getEvent(e,!0),n&&(n.applyConfig(t),n.bubbles=!1,n.broadcast=0)),n},getEvent:function(e,t){var n,r;return t||(n=this._yuievt.config.prefix,e=n?b(e,n):e),r=this._yuievt.events,r[e]||null},after:function(t,n){var r=f.call(arguments,0);switch(p.type(t)){case"function":return e.Do.after.apply(e.Do,arguments);case"array":case"object":r[0]._after=!0;break;default:r[0]=m+t}return this.on.apply(this,r)},before:function (){return this.on.apply +(this,arguments)}},e.EventTarget=E,e.mix(e,E.prototype),E.call(e,{bubbles:!1}),YUI.Env.globalEvents=YUI.Env.globalEvents||new E,e.Global=YUI.Env.globalEvents},"3.17.2",{requires:["oop"]});
