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);
}
};
}, 'patched-v3.11.0', {"requires": ["event-custom-base"]});
YUI.add('event-custom-base', function (Y, NAME) {
/**
* Custom event engine, DOM event listener abstraction layer, synthetic DOM
* events.
* @module event-custom
*/
Y.Env.evt = {
handles: {},
plugins: {}
};
/**
* Custom event engine, DOM event listener abstraction layer, synthetic DOM
* events.
* @module event-custom
* @submodule event-custom-base
*/
/**
* Allows for the insertion of methods that are executed before or after
* a specified method
* @class Do
* @static
*/
var DO_BEFORE = 0,
DO_AFTER = 1,
DO = {
/**
* Cache of objects touched by the utility
* @property objs
* @static
* @deprecated Since 3.6.0. The `_yuiaop` property on the AOP'd object
* replaces the role of this property, but is considered to be private, and
* is only mentioned to provide a migration path.
*
* If you have a use case which warrants migration to the _yuiaop property,
* please file a ticket to let us know what it's used for and we can see if
* we need to expose hooks for that functionality more formally.
*/
objs: null,
/**
* Execute the supplied method before the specified function. Wrapping
* function may optionally return an instance of the following classes to
* further alter runtime behavior:
*
* Y.Do.Halt(message, returnValue)
* Immediatly stop execution and return
* returnValue
. No other wrapping functions will be
* executed.
* Y.Do.AlterArgs(message, newArgArray)
* Replace the arguments that the original function will be
* called with.
* Y.Do.Prevent(message)
* Don't execute the wrapped function. Other before phase
* wrappers will be executed.
*
*
* @method before
* @param fn {Function} the function to execute
* @param obj the object hosting the method to displace
* @param sFn {string} the name of the method to displace
* @param c The execution context for fn
* @param arg* {mixed} 0..n additional arguments to supply to the subscriber
* when the event fires.
* @return {string} handle for the subscription
* @static
*/
before: function(fn, obj, sFn, c) {
var f = fn, a;
if (c) {
a = [fn, c].concat(Y.Array(arguments, 4, true));
f = Y.rbind.apply(Y, a);
}
return this._inject(DO_BEFORE, f, obj, sFn);
},
/**
* Execute the supplied method after the specified function. Wrapping
* function may optionally return an instance of the following classes to
* further alter runtime behavior:
*
* Y.Do.Halt(message, returnValue)
* Immediatly stop execution and return
* returnValue
. No other wrapping functions will be
* executed.
* Y.Do.AlterReturn(message, returnValue)
* Return returnValue
instead of the wrapped
* method's original return value. This can be further altered by
* other after phase wrappers.
*
*
* The static properties Y.Do.originalRetVal
and
* Y.Do.currentRetVal
will be populated for reference.
*
* @method after
* @param fn {Function} the function to execute
* @param obj the object hosting the method to displace
* @param sFn {string} the name of the method to displace
* @param c The execution context for fn
* @param arg* {mixed} 0..n additional arguments to supply to the subscriber
* @return {string} handle for the subscription
* @static
*/
after: function(fn, obj, sFn, c) {
var f = fn, a;
if (c) {
a = [fn, c].concat(Y.Array(arguments, 4, true));
f = Y.rbind.apply(Y, a);
}
return this._inject(DO_AFTER, f, obj, sFn);
},
/**
* Execute the supplied method before or after the specified function.
* Used by before
and after
.
*
* @method _inject
* @param when {string} before or after
* @param fn {Function} the function to execute
* @param obj the object hosting the method to displace
* @param sFn {string} the name of the method to displace
* @param c The execution context for fn
* @return {string} handle for the subscription
* @private
* @static
*/
_inject: function(when, fn, obj, sFn) {
// object id
var id = Y.stamp(obj), o, sid;
if (!obj._yuiaop) {
// create a map entry for the obj if it doesn't exist, to hold overridden methods
obj._yuiaop = {};
}
o = obj._yuiaop;
if (!o[sFn]) {
// create a map entry for the method if it doesn't exist
o[sFn] = new Y.Do.Method(obj, sFn);
// re-route the method to our wrapper
obj[sFn] = function() {
return o[sFn].exec.apply(o[sFn], arguments);
};
}
// subscriber id
sid = id + Y.stamp(fn) + sFn;
// register the callback
o[sFn].register(sid, fn, when);
return new Y.EventHandle(o[sFn], sid);
},
/**
* Detach a before or after subscription.
*
* @method detach
* @param handle {string} the subscription handle
* @static
*/
detach: function(handle) {
if (handle.detach) {
handle.detach();
}
}
};
Y.Do = DO;
//////////////////////////////////////////////////////////////////////////
/**
* Contains the return value from the wrapped method, accessible
* by 'after' event listeners.
*
* @property originalRetVal
* @static
* @since 3.2.0
*/
/**
* Contains the current state of the return value, consumable by
* 'after' event listeners, and updated if an after subscriber
* changes the return value generated by the wrapped function.
*
* @property currentRetVal
* @static
* @since 3.2.0
*/
//////////////////////////////////////////////////////////////////////////
/**
* Wrapper for a displaced method with aop enabled
* @class Do.Method
* @constructor
* @param obj The object to operate on
* @param sFn The name of the method to displace
*/
DO.Method = function(obj, sFn) {
this.obj = obj;
this.methodName = sFn;
this.method = obj[sFn];
this.before = {};
this.after = {};
};
/**
* Register a aop subscriber
* @method register
* @param sid {string} the subscriber id
* @param fn {Function} the function to execute
* @param when {string} when to execute the function
*/
DO.Method.prototype.register = function (sid, fn, when) {
if (when) {
this.after[sid] = fn;
} else {
this.before[sid] = fn;
}
};
/**
* Unregister a aop subscriber
* @method delete
* @param sid {string} the subscriber id
* @param fn {Function} the function to execute
* @param when {string} when to execute the function
*/
DO.Method.prototype._delete = function (sid) {
delete this.before[sid];
delete this.after[sid];
};
/**
* Execute the wrapped method. All arguments are passed into the wrapping
* functions. If any of the before wrappers return an instance of
* Y.Do.Halt
or Y.Do.Prevent
, neither the wrapped
* function nor any after phase subscribers will be executed.
*
* The return value will be the return value of the wrapped function or one
* provided by a wrapper function via an instance of Y.Do.Halt
or
* Y.Do.AlterReturn
.
*
* @method exec
* @param arg* {any} Arguments are passed to the wrapping and wrapped functions
* @return {any} Return value of wrapped function unless overwritten (see above)
*/
DO.Method.prototype.exec = function () {
var args = Y.Array(arguments, 0, true),
i, ret, newRet,
bf = this.before,
af = this.after,
prevented = false;
// execute before
for (i in bf) {
if (bf.hasOwnProperty(i)) {
ret = bf[i].apply(this.obj, args);
if (ret) {
switch (ret.constructor) {
case DO.Halt:
return ret.retVal;
case DO.AlterArgs:
args = ret.newArgs;
break;
case DO.Prevent:
prevented = true;
break;
default:
}
}
}
}
// execute method
if (!prevented) {
ret = this.method.apply(this.obj, args);
}
DO.originalRetVal = ret;
DO.currentRetVal = ret;
// execute after methods.
for (i in af) {
if (af.hasOwnProperty(i)) {
newRet = af[i].apply(this.obj, args);
// Stop processing if a Halt object is returned
if (newRet && newRet.constructor === DO.Halt) {
return newRet.retVal;
// Check for a new return value
} else if (newRet && newRet.constructor === DO.AlterReturn) {
ret = newRet.newRetVal;
// Update the static retval state
DO.currentRetVal = ret;
}
}
}
return ret;
};
//////////////////////////////////////////////////////////////////////////
/**
* Return an AlterArgs object when you want to change the arguments that
* were passed into the function. Useful for Do.before subscribers. An
* example would be a service that scrubs out illegal characters prior to
* executing the core business logic.
* @class Do.AlterArgs
* @constructor
* @param msg {String} (optional) Explanation of the altered return value
* @param newArgs {Array} Call parameters to be used for the original method
* instead of the arguments originally passed in.
*/
DO.AlterArgs = function(msg, newArgs) {
this.msg = msg;
this.newArgs = newArgs;
};
/**
* Return an AlterReturn object when you want to change the result returned
* from the core method to the caller. Useful for Do.after subscribers.
* @class Do.AlterReturn
* @constructor
* @param msg {String} (optional) Explanation of the altered return value
* @param newRetVal {any} Return value passed to code that invoked the wrapped
* function.
*/
DO.AlterReturn = function(msg, newRetVal) {
this.msg = msg;
this.newRetVal = newRetVal;
};
/**
* Return a Halt object when you want to terminate the execution
* of all subsequent subscribers as well as the wrapped method
* if it has not exectued yet. Useful for Do.before subscribers.
* @class Do.Halt
* @constructor
* @param msg {String} (optional) Explanation of why the termination was done
* @param retVal {any} Return value passed to code that invoked the wrapped
* function.
*/
DO.Halt = function(msg, retVal) {
this.msg = msg;
this.retVal = retVal;
};
/**
* Return a Prevent object when you want to prevent the wrapped function
* from executing, but want the remaining listeners to execute. Useful
* for Do.before subscribers.
* @class Do.Prevent
* @constructor
* @param msg {String} (optional) Explanation of why the termination was done
*/
DO.Prevent = function(msg) {
this.msg = msg;
};
/**
* Return an Error object when you want to terminate the execution
* of all subsequent method calls.
* @class Do.Error
* @constructor
* @param msg {String} (optional) Explanation of the altered return value
* @param retVal {any} Return value passed to code that invoked the wrapped
* function.
* @deprecated use Y.Do.Halt or Y.Do.Prevent
*/
DO.Error = DO.Halt;
//////////////////////////////////////////////////////////////////////////
/**
* Custom event engine, DOM event listener abstraction layer, synthetic DOM
* events.
* @module event-custom
* @submodule event-custom-base
*/
// var onsubscribeType = "_event:onsub",
var YArray = Y.Array,
AFTER = 'after',
CONFIGS = [
'broadcast',
'monitored',
'bubbles',
'context',
'contextFn',
'currentTarget',
'defaultFn',
'defaultTargetOnly',
'details',
'emitFacade',
'fireOnce',
'async',
'host',
'preventable',
'preventedFn',
'queuable',
'silent',
'stoppedFn',
'target',
'type'
],
CONFIGS_HASH = YArray.hash(CONFIGS),
nativeSlice = Array.prototype.slice,
YUI3_SIGNATURE = 9,
YUI_LOG = 'yui:log',
mixConfigs = function(r, s, ov) {
var p;
for (p in s) {
if (CONFIGS_HASH[p] && (ov || !(p in r))) {
r[p] = s[p];
}
}
return r;
};
/**
* The CustomEvent class lets you define events for your application
* that can be subscribed to by one or more independent component.
*
* @param {String} type The type of event, which is passed to the callback
* when the event fires.
* @param {object} defaults configuration object.
* @class CustomEvent
* @constructor
*/
/**
* The type of event, returned to subscribers when the event fires
* @property type
* @type string
*/
/**
* By default all custom events are logged in the debug build, set silent
* to true to disable debug outpu for this event.
* @property silent
* @type boolean
*/
Y.CustomEvent = function(type, defaults) {
this._kds = Y.CustomEvent.keepDeprecatedSubs;
this.id = Y.guid();
this.type = type;
this.silent = this.logSystem = (type === YUI_LOG);
if (this._kds) {
/**
* The subscribers to this event
* @property subscribers
* @type Subscriber {}
* @deprecated
*/
/**
* 'After' subscribers
* @property afters
* @type Subscriber {}
* @deprecated
*/
this.subscribers = {};
this.afters = {};
}
if (defaults) {
mixConfigs(this, defaults, true);
}
};
/**
* Static flag to enable population of the `subscribers`
* and `afters` properties held on a `CustomEvent` instance.
*
* These properties were changed to private properties (`_subscribers` and `_afters`), and
* converted from objects to arrays for performance reasons.
*
* Setting this property to true will populate the deprecated `subscribers` and `afters`
* properties for people who may be using them (which is expected to be rare). There will
* be a performance hit, compared to the new array based implementation.
*
* If you are using these deprecated properties for a use case which the public API
* does not support, please file an enhancement request, and we can provide an alternate
* public implementation which doesn't have the performance cost required to maintiain the
* properties as objects.
*
* @property keepDeprecatedSubs
* @static
* @for CustomEvent
* @type boolean
* @default false
* @deprecated
*/
Y.CustomEvent.keepDeprecatedSubs = false;
Y.CustomEvent.mixConfigs = mixConfigs;
Y.CustomEvent.prototype = {
constructor: Y.CustomEvent,
/**
* Monitor when an event is attached or detached.
*
* @property monitored
* @type boolean
*/
/**
* If 0, this event does not broadcast. If 1, the YUI instance is notified
* every time this event fires. If 2, the YUI instance and the YUI global
* (if event is enabled on the global) are notified every time this event
* fires.
* @property broadcast
* @type int
*/
/**
* Specifies whether this event should be queued when the host is actively
* processing an event. This will effect exectution order of the callbacks
* for the various events.
* @property queuable
* @type boolean
* @default false
*/
/**
* This event has fired if true
*
* @property fired
* @type boolean
* @default false;
*/
/**
* An array containing the arguments the custom event
* was last fired with.
* @property firedWith
* @type Array
*/
/**
* This event should only fire one time if true, and if
* it has fired, any new subscribers should be notified
* immediately.
*
* @property fireOnce
* @type boolean
* @default false;
*/
/**
* fireOnce listeners will fire syncronously unless async
* is set to true
* @property async
* @type boolean
* @default false
*/
/**
* Flag for stopPropagation that is modified during fire()
* 1 means to stop propagation to bubble targets. 2 means
* to also stop additional subscribers on this target.
* @property stopped
* @type int
*/
/**
* Flag for preventDefault that is modified during fire().
* if it is not 0, the default behavior for this event
* @property prevented
* @type int
*/
/**
* Specifies the host for this custom event. This is used
* to enable event bubbling
* @property host
* @type EventTarget
*/
/**
* The default function to execute after event listeners
* have fire, but only if the default action was not
* prevented.
* @property defaultFn
* @type Function
*/
/**
* The function to execute if a subscriber calls
* stopPropagation or stopImmediatePropagation
* @property stoppedFn
* @type Function
*/
/**
* The function to execute if a subscriber calls
* preventDefault
* @property preventedFn
* @type Function
*/
/**
* The subscribers to this event
* @property _subscribers
* @type Subscriber []
* @private
*/
/**
* 'After' subscribers
* @property _afters
* @type Subscriber []
* @private
*/
/**
* If set to true, the custom event will deliver an EventFacade object
* that is similar to a DOM event object.
* @property emitFacade
* @type boolean
* @default false
*/
/**
* Supports multiple options for listener signatures in order to
* port YUI 2 apps.
* @property signature
* @type int
* @default 9
*/
signature : YUI3_SIGNATURE,
/**
* The context the the event will fire from by default. Defaults to the YUI
* instance.
* @property context
* @type object
*/
context : Y,
/**
* Specifies whether or not this event's default function
* can be cancelled by a subscriber by executing preventDefault()
* on the event facade
* @property preventable
* @type boolean
* @default true
*/
preventable : true,
/**
* Specifies whether or not a subscriber can stop the event propagation
* via stopPropagation(), stopImmediatePropagation(), or halt()
*
* Events can only bubble if emitFacade is true.
*
* @property bubbles
* @type boolean
* @default true
*/
bubbles : true,
/**
* Returns the number of subscribers for this event as the sum of the on()
* subscribers and after() subscribers.
*
* @method hasSubs
* @return Number
*/
hasSubs: function(when) {
var s = 0,
a = 0,
subs = this._subscribers,
afters = this._afters,
sib = this.sibling;
if (subs) {
s = subs.length;
}
if (afters) {
a = afters.length;
}
if (sib) {
subs = sib._subscribers;
afters = sib._afters;
if (subs) {
s += subs.length;
}
if (afters) {
a += afters.length;
}
}
if (when) {
return (when === 'after') ? a : s;
}
return (s + a);
},
/**
* Monitor the event state for the subscribed event. The first parameter
* is what should be monitored, the rest are the normal parameters when
* subscribing to an event.
* @method monitor
* @param what {string} what to monitor ('detach', 'attach', 'publish').
* @return {EventHandle} return value from the monitor event subscription.
*/
monitor: function(what) {
this.monitored = true;
var type = this.id + '|' + this.type + '_' + what,
args = nativeSlice.call(arguments, 0);
args[0] = type;
return this.host.on.apply(this.host, args);
},
/**
* Get all of the subscribers to this event and any sibling event
* @method getSubs
* @return {Array} first item is the on subscribers, second the after.
*/
getSubs: function() {
var sibling = this.sibling,
subs = this._subscribers,
afters = this._afters,
siblingSubs,
siblingAfters;
if (sibling) {
siblingSubs = sibling._subscribers;
siblingAfters = sibling._afters;
}
if (siblingSubs) {
if (subs) {
subs = subs.concat(siblingSubs);
} else {
subs = siblingSubs.concat();
}
} else {
if (subs) {
subs = subs.concat();
} else {
subs = [];
}
}
if (siblingAfters) {
if (afters) {
afters = afters.concat(siblingAfters);
} else {
afters = siblingAfters.concat();
}
} else {
if (afters) {
afters = afters.concat();
} else {
afters = [];
}
}
return [subs, afters];
},
/**
* Apply configuration properties. Only applies the CONFIG whitelist
* @method applyConfig
* @param o hash of properties to apply.
* @param force {boolean} if true, properties that exist on the event
* will be overwritten.
*/
applyConfig: function(o, force) {
mixConfigs(this, o, force);
},
/**
* Create the Subscription for subscribing function, context, and bound
* arguments. If this is a fireOnce event, the subscriber is immediately
* notified.
*
* @method _on
* @param fn {Function} Subscription callback
* @param [context] {Object} Override `this` in the callback
* @param [args] {Array} bound arguments that will be passed to the callback after the arguments generated by fire()
* @param [when] {String} "after" to slot into after subscribers
* @return {EventHandle}
* @protected
*/
_on: function(fn, context, args, when) {
var s = new Y.Subscriber(fn, context, args, when),
firedWith;
if (this.fireOnce && this.fired) {
firedWith = this.firedWith;
// It's a little ugly for this to know about facades,
// but given the current breakup, not much choice without
// moving a whole lot of stuff around.
if (this.emitFacade && this._addFacadeToArgs) {
this._addFacadeToArgs(firedWith);
}
if (this.async) {
setTimeout(Y.bind(this._notify, this, s, firedWith), 0);
} else {
this._notify(s, firedWith);
}
}
if (when === AFTER) {
if (!this._afters) {
this._afters = [];
}
this._afters.push(s);
} else {
if (!this._subscribers) {
this._subscribers = [];
}
this._subscribers.push(s);
}
if (this._kds) {
if (when === AFTER) {
this.afters[s.id] = s;
} else {
this.subscribers[s.id] = s;
}
}
return new Y.EventHandle(this, s);
},
/**
* Listen for this event
* @method subscribe
* @param {Function} fn The function to execute.
* @return {EventHandle} Unsubscribe handle.
* @deprecated use on.
*/
subscribe: function(fn, context) {
var a = (arguments.length > 2) ? nativeSlice.call(arguments, 2) : null;
return this._on(fn, context, a, true);
},
/**
* Listen for this event
* @method on
* @param {Function} fn The function to execute.
* @param {object} context optional execution context.
* @param {mixed} arg* 0..n additional arguments to supply to the subscriber
* when the event fires.
* @return {EventHandle} An object with a detach method to detch the handler(s).
*/
on: function(fn, context) {
var a = (arguments.length > 2) ? nativeSlice.call(arguments, 2) : null;
if (this.monitored && this.host) {
this.host._monitor('attach', this, {
args: arguments
});
}
return this._on(fn, context, a, true);
},
/**
* Listen for this event after the normal subscribers have been notified and
* the default behavior has been applied. If a normal subscriber prevents the
* default behavior, it also prevents after listeners from firing.
* @method after
* @param {Function} fn The function to execute.
* @param {object} context optional execution context.
* @param {mixed} arg* 0..n additional arguments to supply to the subscriber
* when the event fires.
* @return {EventHandle} handle Unsubscribe handle.
*/
after: function(fn, context) {
var a = (arguments.length > 2) ? nativeSlice.call(arguments, 2) : null;
return this._on(fn, context, a, AFTER);
},
/**
* Detach listeners.
* @method detach
* @param {Function} fn The subscribed function to remove, if not supplied
* all will be removed.
* @param {Object} context The context object passed to subscribe.
* @return {int} returns the number of subscribers unsubscribed.
*/
detach: function(fn, context) {
// unsubscribe handle
if (fn && fn.detach) {
return fn.detach();
}
var i, s,
found = 0,
subs = this._subscribers,
afters = this._afters;
if (subs) {
for (i = subs.length; i >= 0; i--) {
s = subs[i];
if (s && (!fn || fn === s.fn)) {
this._delete(s, subs, i);
found++;
}
}
}
if (afters) {
for (i = afters.length; i >= 0; i--) {
s = afters[i];
if (s && (!fn || fn === s.fn)) {
this._delete(s, afters, i);
found++;
}
}
}
return found;
},
/**
* Detach listeners.
* @method unsubscribe
* @param {Function} fn The subscribed function to remove, if not supplied
* all will be removed.
* @param {Object} context The context object passed to subscribe.
* @return {int|undefined} returns the number of subscribers unsubscribed.
* @deprecated use detach.
*/
unsubscribe: function() {
return this.detach.apply(this, arguments);
},
/**
* Notify a single subscriber
* @method _notify
* @param {Subscriber} s the subscriber.
* @param {Array} args the arguments array to apply to the listener.
* @protected
*/
_notify: function(s, args, ef) {
var ret;
ret = s.notify(args, this);
if (false === ret || this.stopped > 1) {
return false;
}
return true;
},
/**
* Logger abstraction to centralize the application of the silent flag
* @method log
* @param {string} msg message to log.
* @param {string} cat log category.
*/
log: function(msg, cat) {
},
/**
* Notifies the subscribers. The callback functions will be executed
* from the context specified when the event was created, and with the
* following parameters:
*
* The type of event
* All of the arguments fire() was executed with as an array
* The custom object (if any) that was passed into the subscribe()
* method
*
* @method fire
* @param {Object*} arguments an arbitrary set of parameters to pass to
* the handler.
* @return {boolean} false if one of the subscribers returned false,
* true otherwise.
*
*/
fire: function() {
// push is the fastest way to go from arguments to arrays
// for most browsers currently
// http://jsperf.com/push-vs-concat-vs-slice/2
var args = [];
args.push.apply(args, arguments);
return this._fire(args);
},
/**
* Private internal implementation for `fire`, which is can be used directly by
* `EventTarget` and other event module classes which have already converted from
* an `arguments` list to an array, to avoid the repeated overhead.
*
* @method _fire
* @private
* @param {Array} args The array of arguments passed to be passed to handlers.
* @return {boolean} false if one of the subscribers returned false, true otherwise.
*/
_fire: function(args) {
if (this.fireOnce && this.fired) {
return true;
} else {
// this doesn't happen if the event isn't published
// this.host._monitor('fire', this.type, args);
this.fired = true;
if (this.fireOnce) {
this.firedWith = args;
}
if (this.emitFacade) {
return this.fireComplex(args);
} else {
return this.fireSimple(args);
}
}
},
/**
* Set up for notifying subscribers of non-emitFacade events.
*
* @method fireSimple
* @param args {Array} Arguments passed to fire()
* @return Boolean false if a subscriber returned false
* @protected
*/
fireSimple: function(args) {
this.stopped = 0;
this.prevented = 0;
if (this.hasSubs()) {
var subs = this.getSubs();
this._procSubs(subs[0], args);
this._procSubs(subs[1], args);
}
if (this.broadcast) {
this._broadcast(args);
}
return this.stopped ? false : true;
},
// Requires the event-custom-complex module for full funcitonality.
fireComplex: function(args) {
args[0] = args[0] || {};
return this.fireSimple(args);
},
/**
* Notifies a list of subscribers.
*
* @method _procSubs
* @param subs {Array} List of subscribers
* @param args {Array} Arguments passed to fire()
* @param ef {}
* @return Boolean false if a subscriber returns false or stops the event
* propagation via e.stopPropagation(),
* e.stopImmediatePropagation(), or e.halt()
* @private
*/
_procSubs: function(subs, args, ef) {
var s, i, l;
for (i = 0, l = subs.length; i < l; i++) {
s = subs[i];
if (s && s.fn) {
if (false === this._notify(s, args, ef)) {
this.stopped = 2;
}
if (this.stopped === 2) {
return false;
}
}
}
return true;
},
/**
* Notifies the YUI instance if the event is configured with broadcast = 1,
* and both the YUI instance and Y.Global if configured with broadcast = 2.
*
* @method _broadcast
* @param args {Array} Arguments sent to fire()
* @private
*/
_broadcast: function(args) {
if (!this.stopped && this.broadcast) {
var a = args.concat();
a.unshift(this.type);
if (this.host !== Y) {
Y.fire.apply(Y, a);
}
if (this.broadcast === 2) {
Y.Global.fire.apply(Y.Global, a);
}
}
},
/**
* Removes all listeners
* @method unsubscribeAll
* @return {int} The number of listeners unsubscribed.
* @deprecated use detachAll.
*/
unsubscribeAll: function() {
return this.detachAll.apply(this, arguments);
},
/**
* Removes all listeners
* @method detachAll
* @return {int} The number of listeners unsubscribed.
*/
detachAll: function() {
return this.detach();
},
/**
* Deletes the subscriber from the internal store of on() and after()
* subscribers.
*
* @method _delete
* @param s subscriber object.
* @param subs (optional) on or after subscriber array
* @param index (optional) The index found.
* @private
*/
_delete: function(s, subs, i) {
var when = s._when;
if (!subs) {
subs = (when === AFTER) ? this._afters : this._subscribers;
}
if (subs) {
i = YArray.indexOf(subs, s, 0);
if (s && subs[i] === s) {
subs.splice(i, 1);
}
}
if (this._kds) {
if (when === AFTER) {
delete this.afters[s.id];
} else {
delete this.subscribers[s.id];
}
}
if (this.monitored && this.host) {
this.host._monitor('detach', this, {
ce: this,
sub: s
});
}
if (s) {
s.deleted = true;
}
}
};
/**
* Stores the subscriber information to be used when the event fires.
* @param {Function} fn The wrapped function to execute.
* @param {Object} context The value of the keyword 'this' in the listener.
* @param {Array} args* 0..n additional arguments to supply the listener.
*
* @class Subscriber
* @constructor
*/
Y.Subscriber = function(fn, context, args, when) {
/**
* The callback that will be execute when the event fires
* This is wrapped by Y.rbind if obj was supplied.
* @property fn
* @type Function
*/
this.fn = fn;
/**
* Optional 'this' keyword for the listener
* @property context
* @type Object
*/
this.context = context;
/**
* Unique subscriber id
* @property id
* @type String
*/
this.id = Y.guid();
/**
* Additional arguments to propagate to the subscriber
* @property args
* @type Array
*/
this.args = args;
this._when = when;
/**
* Custom events for a given fire transaction.
* @property events
* @type {EventTarget}
*/
// this.events = null;
/**
* This listener only reacts to the event once
* @property once
*/
// this.once = false;
};
Y.Subscriber.prototype = {
constructor: Y.Subscriber,
_notify: function(c, args, ce) {
if (this.deleted && !this.postponed) {
if (this.postponed) {
delete this.fn;
delete this.context;
} else {
delete this.postponed;
return null;
}
}
var a = this.args, ret;
switch (ce.signature) {
case 0:
ret = this.fn.call(c, ce.type, args, c);
break;
case 1:
ret = this.fn.call(c, args[0] || null, c);
break;
default:
if (a || args) {
args = args || [];
a = (a) ? args.concat(a) : args;
ret = this.fn.apply(c, a);
} else {
ret = this.fn.call(c);
}
}
if (this.once) {
ce._delete(this);
}
return ret;
},
/**
* Executes the subscriber.
* @method notify
* @param args {Array} Arguments array for the subscriber.
* @param ce {CustomEvent} The custom event that sent the notification.
*/
notify: function(args, ce) {
var c = this.context,
ret = true;
if (!c) {
c = (ce.contextFn) ? ce.contextFn() : ce.context;
}
// only catch errors if we will not re-throw them.
if (Y.config && Y.config.throwFail) {
ret = this._notify(c, args, ce);
} else {
try {
ret = this._notify(c, args, ce);
} catch (e) {
Y.error(this + ' failed: ' + e.message, e);
}
}
return ret;
},
/**
* Returns true if the fn and obj match this objects properties.
* Used by the unsubscribe method to match the right subscriber.
*
* @method contains
* @param {Function} fn the function to execute.
* @param {Object} context optional 'this' keyword for the listener.
* @return {boolean} true if the supplied arguments match this
* subscriber's signature.
*/
contains: function(fn, context) {
if (context) {
return ((this.fn === fn) && this.context === context);
} else {
return (this.fn === fn);
}
},
valueOf : function() {
return this.id;
}
};
/**
* Return value from all subscribe operations
* @class EventHandle
* @constructor
* @param {CustomEvent} evt the custom event.
* @param {Subscriber} sub the subscriber.
*/
Y.EventHandle = function(evt, sub) {
/**
* The custom event
*
* @property evt
* @type CustomEvent
*/
this.evt = evt;
/**
* The subscriber object
*
* @property sub
* @type Subscriber
*/
this.sub = sub;
};
Y.EventHandle.prototype = {
batch: function(f, c) {
f.call(c || this, this);
if (Y.Lang.isArray(this.evt)) {
Y.Array.each(this.evt, function(h) {
h.batch.call(c || h, f);
});
}
},
/**
* Detaches this subscriber
* @method detach
* @return {int} the number of detached listeners
*/
detach: function() {
var evt = this.evt, detached = 0, i;
if (evt) {
if (Y.Lang.isArray(evt)) {
for (i = 0; i < evt.length; i++) {
detached += evt[i].detach();
}
} else {
evt._delete(this.sub);
detached = 1;
}
}
return detached;
},
/**
* Monitor the event state for the subscribed event. The first parameter
* is what should be monitored, the rest are the normal parameters when
* subscribing to an event.
* @method monitor
* @param what {string} what to monitor ('attach', 'detach', 'publish').
* @return {EventHandle} return value from the monitor event subscription.
*/
monitor: function(what) {
return this.evt.monitor.apply(this.evt, arguments);
}
};
/**
* Custom event engine, DOM event listener abstraction layer, synthetic DOM
* events.
* @module event-custom
* @submodule event-custom-base
*/
/**
* EventTarget provides the implementation for any object to
* publish, subscribe and fire to custom events, and also
* alows other EventTargets to target the object with events
* sourced from the other object.
* EventTarget is designed to be used with Y.augment to wrap
* EventCustom in an interface that allows events to be listened to
* and fired by name. This makes it possible for implementing code to
* subscribe to an event that either has not been created yet, or will
* not be created at all.
* @class EventTarget
* @param opts a configuration object
* @config emitFacade {boolean} if true, all events will emit event
* facade payloads by default (default false)
* @config prefix {String} the prefix to apply to non-prefixed event names
*/
var L = Y.Lang,
PREFIX_DELIMITER = ':',
CATEGORY_DELIMITER = '|',
AFTER_PREFIX = '~AFTER~',
WILD_TYPE_RE = /(.*?)(:)(.*?)/,
_wildType = Y.cached(function(type) {
return type.replace(WILD_TYPE_RE, "*$2$3");
}),
/**
* If the instance has a prefix attribute and the
* event type is not prefixed, the instance prefix is
* applied to the supplied type.
* @method _getType
* @private
*/
_getType = function(type, pre) {
if (!pre || (typeof type !== "string") || type.indexOf(PREFIX_DELIMITER) > -1) {
return type;
}
return pre + PREFIX_DELIMITER + type;
},
/**
* Returns an array with the detach key (if provided),
* and the prefixed event name from _getType
* Y.on('detachcategory| menu:click', fn)
* @method _parseType
* @private
*/
_parseType = Y.cached(function(type, pre) {
var t = type, detachcategory, after, i;
if (!L.isString(t)) {
return t;
}
i = t.indexOf(AFTER_PREFIX);
if (i > -1) {
after = true;
t = t.substr(AFTER_PREFIX.length);
}
i = t.indexOf(CATEGORY_DELIMITER);
if (i > -1) {
detachcategory = t.substr(0, (i));
t = t.substr(i+1);
if (t === '*') {
t = null;
}
}
// detach category, full type with instance prefix, is this an after listener, short type
return [detachcategory, (pre) ? _getType(t, pre) : t, after, t];
}),
ET = function(opts) {
var etState = this._yuievt,
etConfig;
if (!etState) {
etState = this._yuievt = {
events: {}, // PERF: Not much point instantiating lazily. We're bound to have events
targets: null, // PERF: Instantiate lazily, if user actually adds target,
config: {
host: this,
context: this
},
chain: Y.config.chain
};
}
etConfig = etState.config;
if (opts) {
mixConfigs(etConfig, opts, true);
if (opts.chain !== undefined) {
etState.chain = opts.chain;
}
if (opts.prefix) {
etConfig.prefix = opts.prefix;
}
}
};
ET.prototype = {
constructor: ET,
/**
* Listen to a custom event hosted by this object one time.
* This is the equivalent to on
except the
* listener is immediatelly detached when it is executed.
* @method once
* @param {String} type The name of the event
* @param {Function} fn The callback to execute in response to the event
* @param {Object} [context] Override `this` object in callback
* @param {Any} [arg*] 0..n additional arguments to supply to the subscriber
* @return {EventHandle} A subscription handle capable of detaching the
* subscription
*/
once: function() {
var handle = this.on.apply(this, arguments);
handle.batch(function(hand) {
if (hand.sub) {
hand.sub.once = true;
}
});
return handle;
},
/**
* Listen to a custom event hosted by this object one time.
* This is the equivalent to after
except the
* listener is immediatelly detached when it is executed.
* @method onceAfter
* @param {String} type The name of the event
* @param {Function} fn The callback to execute in response to the event
* @param {Object} [context] Override `this` object in callback
* @param {Any} [arg*] 0..n additional arguments to supply to the subscriber
* @return {EventHandle} A subscription handle capable of detaching that
* subscription
*/
onceAfter: function() {
var handle = this.after.apply(this, arguments);
handle.batch(function(hand) {
if (hand.sub) {
hand.sub.once = true;
}
});
return handle;
},
/**
* Takes the type parameter passed to 'on' and parses out the
* various pieces that could be included in the type. If the
* event type is passed without a prefix, it will be expanded
* to include the prefix one is supplied or the event target
* is configured with a default prefix.
* @method parseType
* @param {String} type the type
* @param {String} [pre=this._yuievt.config.prefix] the prefix
* @since 3.3.0
* @return {Array} an array containing:
* * the detach category, if supplied,
* * the prefixed event type,
* * whether or not this is an after listener,
* * the supplied event type
*/
parseType: function(type, pre) {
return _parseType(type, pre || this._yuievt.config.prefix);
},
/**
* Subscribe a callback function to a custom event fired by this object or
* from an object that bubbles its events to this object.
*
* Callback functions for events published with `emitFacade = true` will
* receive an `EventFacade` as the first argument (typically named "e").
* These callbacks can then call `e.preventDefault()` to disable the
* behavior published to that event's `defaultFn`. See the `EventFacade`
* API for all available properties and methods. Subscribers to
* non-`emitFacade` events will receive the arguments passed to `fire()`
* after the event name.
*
* To subscribe to multiple events at once, pass an object as the first
* argument, where the key:value pairs correspond to the eventName:callback,
* or pass an array of event names as the first argument to subscribe to
* all listed events with the same callback.
*
* Returning `false` from a callback is supported as an alternative to
* calling `e.preventDefault(); e.stopPropagation();`. However, it is
* recommended to use the event methods whenever possible.
*
* @method on
* @param {String} type The name of the event
* @param {Function} fn The callback to execute in response to the event
* @param {Object} [context] Override `this` object in callback
* @param {Any} [arg*] 0..n additional arguments to supply to the subscriber
* @return {EventHandle} A subscription handle capable of detaching that
* subscription
*/
on: function(type, fn, context) {
var yuievt = this._yuievt,
parts = _parseType(type, yuievt.config.prefix), f, c, args, ret, ce,
detachcategory, handle, store = Y.Env.evt.handles, after, adapt, shorttype,
Node = Y.Node, n, domevent, isArr;
// full name, args, detachcategory, after
this._monitor('attach', parts[1], {
args: arguments,
category: parts[0],
after: parts[2]
});
if (L.isObject(type)) {
if (L.isFunction(type)) {
return Y.Do.before.apply(Y.Do, arguments);
}
f = fn;
c = context;
args = nativeSlice.call(arguments, 0);
ret = [];
if (L.isArray(type)) {
isArr = true;
}
after = type._after;
delete type._after;
Y.each(type, function(v, k) {
if (L.isObject(v)) {
f = v.fn || ((L.isFunction(v)) ? v : f);
c = v.context || c;
}
var nv = (after) ? AFTER_PREFIX : '';
args[0] = nv + ((isArr) ? v : k);
args[1] = f;
args[2] = c;
ret.push(this.on.apply(this, args));
}, this);
return (yuievt.chain) ? this : new Y.EventHandle(ret);
}
detachcategory = parts[0];
after = parts[2];
shorttype = parts[3];
// extra redirection so we catch adaptor events too. take a look at this.
if (Node && Y.instanceOf(this, Node) && (shorttype in Node.DOM_EVENTS)) {
args = nativeSlice.call(arguments, 0);
args.splice(2, 0, Node.getDOMNode(this));
return Y.on.apply(Y, args);
}
type = parts[1];
if (Y.instanceOf(this, YUI)) {
adapt = Y.Env.evt.plugins[type];
args = nativeSlice.call(arguments, 0);
args[0] = shorttype;
if (Node) {
n = args[2];
if (Y.instanceOf(n, Y.NodeList)) {
n = Y.NodeList.getDOMNodes(n);
} else if (Y.instanceOf(n, Node)) {
n = Node.getDOMNode(n);
}
domevent = (shorttype in Node.DOM_EVENTS);
// Captures both DOM events and event plugins.
if (domevent) {
args[2] = n;
}
}
// check for the existance of an event adaptor
if (adapt) {
handle = adapt.on.apply(Y, args);
} else if ((!type) || domevent) {
handle = Y.Event._attach(args);
}
}
if (!handle) {
ce = yuievt.events[type] || this.publish(type);
handle = ce._on(fn, context, (arguments.length > 3) ? nativeSlice.call(arguments, 3) : null, (after) ? 'after' : true);
// TODO: More robust regex, accounting for category
if (type.indexOf("*:") !== -1) {
this._hasSiblings = true;
}
}
if (detachcategory) {
store[detachcategory] = store[detachcategory] || {};
store[detachcategory][type] = store[detachcategory][type] || [];
store[detachcategory][type].push(handle);
}
return (yuievt.chain) ? this : handle;
},
/**
* subscribe to an event
* @method subscribe
* @deprecated use on
*/
subscribe: function() {
return this.on.apply(this, arguments);
},
/**
* Detach one or more listeners the from the specified event
* @method detach
* @param type {string|Object} Either the handle to the subscriber or the
* type of event. If the type
* is not specified, it will attempt to remove
* the listener from all hosted events.
* @param fn {Function} The subscribed function to unsubscribe, if not
* supplied, all subscribers will be removed.
* @param context {Object} The custom object passed to subscribe. This is
* optional, but if supplied will be used to
* disambiguate multiple listeners that are the same
* (e.g., you subscribe many object using a function
* that lives on the prototype)
* @return {EventTarget} the host
*/
detach: function(type, fn, context) {
var evts = this._yuievt.events,
i,
Node = Y.Node,
isNode = Node && (Y.instanceOf(this, Node));
// detachAll disabled on the Y instance.
if (!type && (this !== Y)) {
for (i in evts) {
if (evts.hasOwnProperty(i)) {
evts[i].detach(fn, context);
}
}
if (isNode) {
Y.Event.purgeElement(Node.getDOMNode(this));
}
return this;
}
var parts = _parseType(type, this._yuievt.config.prefix),
detachcategory = L.isArray(parts) ? parts[0] : null,
shorttype = (parts) ? parts[3] : null,
adapt, store = Y.Env.evt.handles, detachhost, cat, args,
ce,
keyDetacher = function(lcat, ltype, host) {
var handles = lcat[ltype], ce, i;
if (handles) {
for (i = handles.length - 1; i >= 0; --i) {
ce = handles[i].evt;
if (ce.host === host || ce.el === host) {
handles[i].detach();
}
}
}
};
if (detachcategory) {
cat = store[detachcategory];
type = parts[1];
detachhost = (isNode) ? Y.Node.getDOMNode(this) : this;
if (cat) {
if (type) {
keyDetacher(cat, type, detachhost);
} else {
for (i in cat) {
if (cat.hasOwnProperty(i)) {
keyDetacher(cat, i, detachhost);
}
}
}
return this;
}
// If this is an event handle, use it to detach
} else if (L.isObject(type) && type.detach) {
type.detach();
return this;
// extra redirection so we catch adaptor events too. take a look at this.
} else if (isNode && ((!shorttype) || (shorttype in Node.DOM_EVENTS))) {
args = nativeSlice.call(arguments, 0);
args[2] = Node.getDOMNode(this);
Y.detach.apply(Y, args);
return this;
}
adapt = Y.Env.evt.plugins[shorttype];
// The YUI instance handles DOM events and adaptors
if (Y.instanceOf(this, YUI)) {
args = nativeSlice.call(arguments, 0);
// use the adaptor specific detach code if
if (adapt && adapt.detach) {
adapt.detach.apply(Y, args);
return this;
// DOM event fork
} else if (!type || (!adapt && Node && (type in Node.DOM_EVENTS))) {
args[0] = type;
Y.Event.detach.apply(Y.Event, args);
return this;
}
}
// ce = evts[type];
ce = evts[parts[1]];
if (ce) {
ce.detach(fn, context);
}
return this;
},
/**
* detach a listener
* @method unsubscribe
* @deprecated use detach
*/
unsubscribe: function() {
return this.detach.apply(this, arguments);
},
/**
* Removes all listeners from the specified event. If the event type
* is not specified, all listeners from all hosted custom events will
* be removed.
* @method detachAll
* @param type {String} The type, or name of the event
*/
detachAll: function(type) {
return this.detach(type);
},
/**
* Removes all listeners from the specified event. If the event type
* is not specified, all listeners from all hosted custom events will
* be removed.
* @method unsubscribeAll
* @param type {String} The type, or name of the event
* @deprecated use detachAll
*/
unsubscribeAll: function() {
return this.detachAll.apply(this, arguments);
},
/**
* Creates a new custom event of the specified type. If a custom event
* by that name already exists, it will not be re-created. In either
* case the custom event is returned.
*
* @method publish
*
* @param type {String} the type, or name of the event
* @param opts {object} optional config params. Valid properties are:
*
*
*
* 'broadcast': whether or not the YUI instance and YUI global are notified when the event is fired (false)
*
*
* 'bubbles': whether or not this event bubbles (true)
* Events can only bubble if emitFacade is true.
*
*
* 'context': the default execution context for the listeners (this)
*
*
* 'defaultFn': the default function to execute when this event fires if preventDefault was not called
*
*
* 'emitFacade': whether or not this event emits a facade (false)
*
*
* 'prefix': the prefix for this targets events, e.g., 'menu' in 'menu:click'
*
*
* 'fireOnce': if an event is configured to fire once, new subscribers after
* the fire will be notified immediately.
*
*
* 'async': fireOnce event listeners will fire synchronously if the event has already
* fired unless async is true.
*
*
* 'preventable': whether or not preventDefault() has an effect (true)
*
*
* 'preventedFn': a function that is executed when preventDefault is called
*
*
* 'queuable': whether or not this event can be queued during bubbling (false)
*
*
* 'silent': if silent is true, debug messages are not provided for this event.
*
*
* 'stoppedFn': a function that is executed when stopPropagation is called
*
*
*
* 'monitored': specifies whether or not this event should send notifications about
* when the event has been attached, detached, or published.
*
*
* 'type': the event type (valid option if not provided as the first parameter to publish)
*
*
*
* @return {CustomEvent} the custom event
*
*/
publish: function(type, opts) {
var ret,
etState = this._yuievt,
etConfig = etState.config,
pre = etConfig.prefix;
if (typeof type === "string") {
if (pre) {
type = _getType(type, pre);
}
ret = this._publish(type, etConfig, opts);
} else {
ret = {};
Y.each(type, function(v, k) {
if (pre) {
k = _getType(k, pre);
}
ret[k] = this._publish(k, etConfig, v || opts);
}, this);
}
return ret;
},
/**
* Returns the fully qualified type, given a short type string.
* That is, returns "foo:bar" when given "bar" if "foo" is the configured prefix.
*
* NOTE: This method, unlike _getType, does no checking of the value passed in, and
* is designed to be used with the low level _publish() method, for critical path
* implementations which need to fast-track publish for performance reasons.
*
* @method _getFullType
* @private
* @param {String} type The short type to prefix
* @return {String} The prefixed type, if a prefix is set, otherwise the type passed in
*/
_getFullType : function(type) {
var pre = this._yuievt.config.prefix;
if (pre) {
return pre + PREFIX_DELIMITER + type;
} else {
return type;
}
},
/**
* The low level event publish implementation. It expects all the massaging to have been done
* outside of this method. e.g. the `type` to `fullType` conversion. It's designed to be a fast
* path publish, which can be used by critical code paths to improve performance.
*
* @method _publish
* @private
* @param {String} fullType The prefixed type of the event to publish.
* @param {Object} etOpts The EventTarget specific configuration to mix into the published event.
* @param {Object} ceOpts The publish specific configuration to mix into the published event.
* @return {CustomEvent} The published event. If called without `etOpts` or `ceOpts`, this will
* be the default `CustomEvent` instance, and can be configured independently.
*/
_publish : function(fullType, etOpts, ceOpts) {
var ce,
etState = this._yuievt,
etConfig = etState.config,
host = etConfig.host,
context = etConfig.context,
events = etState.events;
ce = events[fullType];
// PERF: Hate to pull the check out of monitor, but trying to keep critical path tight.
if ((etConfig.monitored && !ce) || (ce && ce.monitored)) {
this._monitor('publish', fullType, {
args: arguments
});
}
if (!ce) {
// Publish event
ce = events[fullType] = new Y.CustomEvent(fullType, etOpts);
if (!etOpts) {
ce.host = host;
ce.context = context;
}
}
if (ceOpts) {
mixConfigs(ce, ceOpts, true);
}
return ce;
},
/**
* This is the entry point for the event monitoring system.
* You can monitor 'attach', 'detach', 'fire', and 'publish'.
* When configured, these events generate an event. click ->
* click_attach, click_detach, click_publish -- these can
* be subscribed to like other events to monitor the event
* system. Inividual published events can have monitoring
* turned on or off (publish can't be turned off before it
* it published) by setting the events 'monitor' config.
*
* @method _monitor
* @param what {String} 'attach', 'detach', 'fire', or 'publish'
* @param eventType {String|CustomEvent} The prefixed name of the event being monitored, or the CustomEvent object.
* @param o {Object} Information about the event interaction, such as
* fire() args, subscription category, publish config
* @private
*/
_monitor: function(what, eventType, o) {
var monitorevt, ce, type;
if (eventType) {
if (typeof eventType === "string") {
type = eventType;
ce = this.getEvent(eventType, true);
} else {
ce = eventType;
type = eventType.type;
}
if ((this._yuievt.config.monitored && (!ce || ce.monitored)) || (ce && ce.monitored)) {
monitorevt = type + '_' + what;
o.monitored = what;
this.fire.call(this, monitorevt, o);
}
}
},
/**
* Fire a custom event by name. The callback functions will be executed
* from the context specified when the event was created, and with the
* following parameters.
*
* The first argument is the event type, and any additional arguments are
* passed to the listeners as parameters. If the first of these is an
* object literal, and the event is configured to emit an event facade,
* that object is mixed into the event facade and the facade is provided
* in place of the original object.
*
* If the custom event object hasn't been created, then the event hasn't
* been published and it has no subscribers. For performance sake, we
* immediate exit in this case. This means the event won't bubble, so
* if the intention is that a bubble target be notified, the event must
* be published on this object first.
*
* @method fire
* @param type {String|Object} The type of the event, or an object that contains
* a 'type' property.
* @param arguments {Object*} an arbitrary set of parameters to pass to
* the handler. If the first of these is an object literal and the event is
* configured to emit an event facade, the event facade will replace that
* parameter after the properties the object literal contains are copied to
* the event facade.
* @return {Boolean} True if the whole lifecycle of the event went through,
* false if at any point the event propagation was halted.
*/
fire: function(type) {
var typeIncluded = (typeof type === "string"),
argCount = arguments.length,
t = type,
yuievt = this._yuievt,
etConfig = yuievt.config,
pre = etConfig.prefix,
ret,
ce,
ce2,
args;
if (typeIncluded && argCount <= 3) {
// PERF: Try to avoid slice/iteration for the common signatures
// Most common
if (argCount === 2) {
args = [arguments[1]]; // fire("foo", {})
} else if (argCount === 3) {
args = [arguments[1], arguments[2]]; // fire("foo", {}, opts)
} else {
args = []; // fire("foo")
}
} else {
args = nativeSlice.call(arguments, ((typeIncluded) ? 1 : 0));
}
if (!typeIncluded) {
t = (type && type.type);
}
if (pre) {
t = _getType(t, pre);
}
ce = yuievt.events[t];
if (this._hasSiblings) {
ce2 = this.getSibling(t, ce);
if (ce2 && !ce) {
ce = this.publish(t);
}
}
// PERF: trying to avoid function call, since this is a critical path
if ((etConfig.monitored && (!ce || ce.monitored)) || (ce && ce.monitored)) {
this._monitor('fire', (ce || t), {
args: args
});
}
// this event has not been published or subscribed to
if (!ce) {
if (yuievt.hasTargets) {
return this.bubble({ type: t }, args, this);
}
// otherwise there is nothing to be done
ret = true;
} else {
if (ce2) {
ce.sibling = ce2;
}
ret = ce._fire(args);
}
return (yuievt.chain) ? this : ret;
},
getSibling: function(type, ce) {
var ce2;
// delegate to *:type events if there are subscribers
if (type.indexOf(PREFIX_DELIMITER) > -1) {
type = _wildType(type);
ce2 = this.getEvent(type, true);
if (ce2) {
ce2.applyConfig(ce);
ce2.bubbles = false;
ce2.broadcast = 0;
}
}
return ce2;
},
/**
* Returns the custom event of the provided type has been created, a
* falsy value otherwise
* @method getEvent
* @param type {String} the type, or name of the event
* @param prefixed {String} if true, the type is prefixed already
* @return {CustomEvent} the custom event or null
*/
getEvent: function(type, prefixed) {
var pre, e;
if (!prefixed) {
pre = this._yuievt.config.prefix;
type = (pre) ? _getType(type, pre) : type;
}
e = this._yuievt.events;
return e[type] || null;
},
/**
* Subscribe to a custom event hosted by this object. The
* supplied callback will execute after any listeners add
* via the subscribe method, and after the default function,
* if configured for the event, has executed.
*
* @method after
* @param {String} type The name of the event
* @param {Function} fn The callback to execute in response to the event
* @param {Object} [context] Override `this` object in callback
* @param {Any} [arg*] 0..n additional arguments to supply to the subscriber
* @return {EventHandle} A subscription handle capable of detaching the
* subscription
*/
after: function(type, fn) {
var a = nativeSlice.call(arguments, 0);
switch (L.type(type)) {
case 'function':
return Y.Do.after.apply(Y.Do, arguments);
case 'array':
// YArray.each(a[0], function(v) {
// v = AFTER_PREFIX + v;
// });
// break;
case 'object':
a[0]._after = true;
break;
default:
a[0] = AFTER_PREFIX + type;
}
return this.on.apply(this, a);
},
/**
* Executes the callback before a DOM event, custom event
* or method. If the first argument is a function, it
* is assumed the target is a method. For DOM and custom
* events, this is an alias for Y.on.
*
* For DOM and custom events:
* type, callback, context, 0-n arguments
*
* For methods:
* callback, object (method host), methodName, context, 0-n arguments
*
* @method before
* @return detach handle
*/
before: function() {
return this.on.apply(this, arguments);
}
};
Y.EventTarget = ET;
// make Y an event target
Y.mix(Y, ET.prototype);
ET.call(Y, { bubbles: false });
YUI.Env.globalEvents = YUI.Env.globalEvents || new ET();
/**
* Hosts YUI page level events. This is where events bubble to
* when the broadcast config is set to 2. This property is
* only available if the custom event module is loaded.
* @property Global
* @type EventTarget
* @for YUI
*/
Y.Global = YUI.Env.globalEvents;
// @TODO implement a global namespace function on Y.Global?
/**
`Y.on()` can do many things:
Subscribe to custom events `publish`ed and `fire`d from Y
Subscribe to custom events `publish`ed with `broadcast` 1 or 2 and
`fire`d from any object in the YUI instance sandbox
Subscribe to DOM events
Subscribe to the execution of a method on any object, effectively
treating that method as an event
For custom event subscriptions, pass the custom event name as the first argument
and callback as the second. The `this` object in the callback will be `Y` unless
an override is passed as the third argument.
Y.on('io:complete', function () {
Y.MyApp.updateStatus('Transaction complete');
});
To subscribe to DOM events, pass the name of a DOM event as the first argument
and a CSS selector string as the third argument after the callback function.
Alternately, the third argument can be a `Node`, `NodeList`, `HTMLElement`,
array, or simply omitted (the default is the `window` object).
Y.on('click', function (e) {
e.preventDefault();
// proceed with ajax form submission
var url = this.get('action');
...
}, '#my-form');
The `this` object in DOM event callbacks will be the `Node` targeted by the CSS
selector or other identifier.
`on()` subscribers for DOM events or custom events `publish`ed with a
`defaultFn` can prevent the default behavior with `e.preventDefault()` from the
event object passed as the first parameter to the subscription callback.
To subscribe to the execution of an object method, pass arguments corresponding to the call signature for
`Y.Do.before(...)` .
NOTE: The formal parameter list below is for events, not for function
injection. See `Y.Do.before` for that signature.
@method on
@param {String} type DOM or custom event name
@param {Function} fn The callback to execute in response to the event
@param {Object} [context] Override `this` object in callback
@param {Any} [arg*] 0..n additional arguments to supply to the subscriber
@return {EventHandle} A subscription handle capable of detaching the
subscription
@see Do.before
@for YUI
**/
/**
Listen for an event one time. Equivalent to `on()`, except that
the listener is immediately detached when executed.
See the `on()` method for additional subscription
options.
@see on
@method once
@param {String} type DOM or custom event name
@param {Function} fn The callback to execute in response to the event
@param {Object} [context] Override `this` object in callback
@param {Any} [arg*] 0..n additional arguments to supply to the subscriber
@return {EventHandle} A subscription handle capable of detaching the
subscription
@for YUI
**/
/**
Listen for an event one time. Equivalent to `once()`, except, like `after()`,
the subscription callback executes after all `on()` subscribers and the event's
`defaultFn` (if configured) have executed. Like `after()` if any `on()` phase
subscriber calls `e.preventDefault()`, neither the `defaultFn` nor the `after()`
subscribers will execute.
The listener is immediately detached when executed.
See the `on()` method for additional subscription
options.
@see once
@method onceAfter
@param {String} type The custom event name
@param {Function} fn The callback to execute in response to the event
@param {Object} [context] Override `this` object in callback
@param {Any} [arg*] 0..n additional arguments to supply to the subscriber
@return {EventHandle} A subscription handle capable of detaching the
subscription
@for YUI
**/
/**
Like `on()`, this method creates a subscription to a custom event or to the
execution of a method on an object.
For events, `after()` subscribers are executed after the event's
`defaultFn` unless `e.preventDefault()` was called from an `on()` subscriber.
See the `on()` method for additional subscription
options.
NOTE: The subscription signature shown is for events, not for function
injection. See `Y.Do.after`
for that signature.
@see on
@see Do.after
@method after
@param {String} type The custom event name
@param {Function} fn The callback to execute in response to the event
@param {Object} [context] Override `this` object in callback
@param {Any} [args*] 0..n additional arguments to supply to the subscriber
@return {EventHandle} A subscription handle capable of detaching the
subscription
@for YUI
**/
}, 'patched-v3.11.0', {"requires": ["oop"]});
YUI.add('event-custom-complex', function (Y, NAME) {
/**
* Adds event facades, preventable default behavior, and bubbling.
* events.
* @module event-custom
* @submodule event-custom-complex
*/
var FACADE,
FACADE_KEYS,
YObject = Y.Object,
key,
EMPTY = {},
CEProto = Y.CustomEvent.prototype,
ETProto = Y.EventTarget.prototype,
mixFacadeProps = function(facade, payload) {
var p;
for (p in payload) {
if (!(FACADE_KEYS.hasOwnProperty(p))) {
facade[p] = payload[p];
}
}
};
/**
* Wraps and protects a custom event for use when emitFacade is set to true.
* Requires the event-custom-complex module
* @class EventFacade
* @param e {Event} the custom event
* @param currentTarget {HTMLElement} the element the listener was attached to
*/
Y.EventFacade = function(e, currentTarget) {
if (!e) {
e = EMPTY;
}
this._event = e;
/**
* The arguments passed to fire
* @property details
* @type Array
*/
this.details = e.details;
/**
* The event type, this can be overridden by the fire() payload
* @property type
* @type string
*/
this.type = e.type;
/**
* The real event type
* @property _type
* @type string
* @private
*/
this._type = e.type;
//////////////////////////////////////////////////////
/**
* Node reference for the targeted eventtarget
* @property target
* @type Node
*/
this.target = e.target;
/**
* Node reference for the element that the listener was attached to.
* @property currentTarget
* @type Node
*/
this.currentTarget = currentTarget;
/**
* Node reference to the relatedTarget
* @property relatedTarget
* @type Node
*/
this.relatedTarget = e.relatedTarget;
};
Y.mix(Y.EventFacade.prototype, {
/**
* Stops the propagation to the next bubble target
* @method stopPropagation
*/
stopPropagation: function() {
this._event.stopPropagation();
this.stopped = 1;
},
/**
* Stops the propagation to the next bubble target and
* prevents any additional listeners from being exectued
* on the current target.
* @method stopImmediatePropagation
*/
stopImmediatePropagation: function() {
this._event.stopImmediatePropagation();
this.stopped = 2;
},
/**
* Prevents the event's default behavior
* @method preventDefault
*/
preventDefault: function() {
this._event.preventDefault();
this.prevented = 1;
},
/**
* 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
*/
halt: function(immediate) {
this._event.halt(immediate);
this.prevented = 1;
this.stopped = (immediate) ? 2 : 1;
}
});
CEProto.fireComplex = function(args) {
var es,
ef,
q,
queue,
ce,
ret = true,
events,
subs,
ons,
afters,
afterQueue,
postponed,
prevented,
preventedFn,
defaultFn,
self = this,
host = self.host || self,
next,
oldbubble,
stack = self.stack,
yuievt = host._yuievt,
hasPotentialSubscribers;
if (stack) {
// queue this event if the current item in the queue bubbles
if (self.queuable && self.type !== stack.next.type) {
if (!stack.queue) {
stack.queue = [];
}
stack.queue.push([self, args]);
return true;
}
}
hasPotentialSubscribers = self.hasSubs() || yuievt.hasTargets || self.broadcast;
self.target = self.target || host;
self.currentTarget = host;
self.details = args.concat();
if (hasPotentialSubscribers) {
es = stack || {
id: self.id, // id of the first event in the stack
next: self,
silent: self.silent,
stopped: 0,
prevented: 0,
bubbling: null,
type: self.type,
// defaultFnQueue: new Y.Queue(),
defaultTargetOnly: self.defaultTargetOnly
};
subs = self.getSubs();
ons = subs[0];
afters = subs[1];
self.stopped = (self.type !== es.type) ? 0 : es.stopped;
self.prevented = (self.type !== es.type) ? 0 : es.prevented;
if (self.stoppedFn) {
// PERF TODO: Can we replace with callback, like preventedFn. Look into history
events = new Y.EventTarget({
fireOnce: true,
context: host
});
self.events = events;
events.on('stopped', self.stoppedFn);
}
self._facade = null; // kill facade to eliminate stale properties
ef = self._createFacade(args);
if (ons) {
self._procSubs(ons, args, ef);
}
// bubble if this is hosted in an event target and propagation has not been stopped
if (self.bubbles && host.bubble && !self.stopped) {
oldbubble = es.bubbling;
es.bubbling = self.type;
if (es.type !== self.type) {
es.stopped = 0;
es.prevented = 0;
}
ret = host.bubble(self, args, null, es);
self.stopped = Math.max(self.stopped, es.stopped);
self.prevented = Math.max(self.prevented, es.prevented);
es.bubbling = oldbubble;
}
prevented = self.prevented;
if (prevented) {
preventedFn = self.preventedFn;
if (preventedFn) {
preventedFn.apply(host, args);
}
} else {
defaultFn = self.defaultFn;
if (defaultFn && ((!self.defaultTargetOnly && !es.defaultTargetOnly) || host === ef.target)) {
defaultFn.apply(host, args);
}
}
// broadcast listeners are fired as discreet events on the
// YUI instance and potentially the YUI global.
if (self.broadcast) {
self._broadcast(args);
}
if (afters && !self.prevented && self.stopped < 2) {
// Queue the after
afterQueue = es.afterQueue;
if (es.id === self.id || self.type !== yuievt.bubbling) {
self._procSubs(afters, args, ef);
if (afterQueue) {
while ((next = afterQueue.last())) {
next();
}
}
} else {
postponed = afters;
if (es.execDefaultCnt) {
postponed = Y.merge(postponed);
Y.each(postponed, function(s) {
s.postponed = true;
});
}
if (!afterQueue) {
es.afterQueue = new Y.Queue();
}
es.afterQueue.add(function() {
self._procSubs(postponed, args, ef);
});
}
}
self.target = null;
if (es.id === self.id) {
queue = es.queue;
if (queue) {
while (queue.length) {
q = queue.pop();
ce = q[0];
// set up stack to allow the next item to be processed
es.next = ce;
ce._fire(q[1]);
}
}
self.stack = null;
}
ret = !(self.stopped);
if (self.type !== yuievt.bubbling) {
es.stopped = 0;
es.prevented = 0;
self.stopped = 0;
self.prevented = 0;
}
} else {
defaultFn = self.defaultFn;
if(defaultFn) {
ef = self._createFacade(args);
if ((!self.defaultTargetOnly) || (host === ef.target)) {
defaultFn.apply(host, args);
}
}
}
// Kill the cached facade to free up memory.
// Otherwise we have the facade from the last fire, sitting around forever.
self._facade = null;
return ret;
};
/**
* @method _hasPotentialSubscribers
* @for CustomEvent
* @private
* @return {boolean} Whether the event has potential subscribers or not
*/
CEProto._hasPotentialSubscribers = function() {
return this.hasSubs() || this.host._yuievt.hasTargets || this.broadcast;
};
/**
* Internal utility method to create a new facade instance and
* insert it into the fire argument list, accounting for any payload
* merging which needs to happen.
*
* This used to be called `_getFacade`, but the name seemed inappropriate
* when it was used without a need for the return value.
*
* @method _createFacade
* @private
* @param fireArgs {Array} The arguments passed to "fire", which need to be
* shifted (and potentially merged) when the facade is added.
* @return {EventFacade} The event facade created.
*/
// TODO: Remove (private) _getFacade alias, once synthetic.js is updated.
CEProto._createFacade = CEProto._getFacade = function(fireArgs) {
var userArgs = this.details,
firstArg = userArgs && userArgs[0],
firstArgIsObj = (firstArg && (typeof firstArg === "object")),
ef = this._facade;
if (!ef) {
ef = new Y.EventFacade(this, this.currentTarget);
}
if (firstArgIsObj) {
// protect the event facade properties
mixFacadeProps(ef, firstArg);
// Allow the event type to be faked http://yuilibrary.com/projects/yui3/ticket/2528376
if (firstArg.type) {
ef.type = firstArg.type;
}
if (fireArgs) {
fireArgs[0] = ef;
}
} else {
if (fireArgs) {
fireArgs.unshift(ef);
}
}
// update the details field with the arguments
ef.details = this.details;
// use the original target when the event bubbled to this target
ef.target = this.originalTarget || this.target;
ef.currentTarget = this.currentTarget;
ef.stopped = 0;
ef.prevented = 0;
this._facade = ef;
return this._facade;
};
/**
* Utility method to manipulate the args array passed in, to add the event facade,
* if it's not already the first arg.
*
* @method _addFacadeToArgs
* @private
* @param {Array} The arguments to manipulate
*/
CEProto._addFacadeToArgs = function(args) {
var e = args[0];
// Trying not to use instanceof, just to avoid potential cross Y edge case issues.
if (!(e && e.halt && e.stopImmediatePropagation && e.stopPropagation && e._event)) {
this._createFacade(args);
}
};
/**
* Stop propagation to bubble targets
* @for CustomEvent
* @method stopPropagation
*/
CEProto.stopPropagation = function() {
this.stopped = 1;
if (this.stack) {
this.stack.stopped = 1;
}
if (this.events) {
this.events.fire('stopped', this);
}
};
/**
* Stops propagation to bubble targets, and prevents any remaining
* subscribers on the current target from executing.
* @method stopImmediatePropagation
*/
CEProto.stopImmediatePropagation = function() {
this.stopped = 2;
if (this.stack) {
this.stack.stopped = 2;
}
if (this.events) {
this.events.fire('stopped', this);
}
};
/**
* Prevents the execution of this event's defaultFn
* @method preventDefault
*/
CEProto.preventDefault = function() {
if (this.preventable) {
this.prevented = 1;
if (this.stack) {
this.stack.prevented = 1;
}
}
};
/**
* 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
*/
CEProto.halt = function(immediate) {
if (immediate) {
this.stopImmediatePropagation();
} else {
this.stopPropagation();
}
this.preventDefault();
};
/**
* Registers another EventTarget as a bubble target. Bubble order
* is determined by the order registered. Multiple targets can
* be specified.
*
* Events can only bubble if emitFacade is true.
*
* Included in the event-custom-complex submodule.
*
* @method addTarget
* @param o {EventTarget} the target to add
* @for EventTarget
*/
ETProto.addTarget = function(o) {
var etState = this._yuievt;
if (!etState.targets) {
etState.targets = {};
}
etState.targets[Y.stamp(o)] = o;
etState.hasTargets = true;
};
/**
* Returns an array of bubble targets for this object.
* @method getTargets
* @return EventTarget[]
*/
ETProto.getTargets = function() {
var targets = this._yuievt.targets;
return targets ? YObject.values(targets) : [];
};
/**
* Removes a bubble target
* @method removeTarget
* @param o {EventTarget} the target to remove
* @for EventTarget
*/
ETProto.removeTarget = function(o) {
var targets = this._yuievt.targets;
if (targets) {
delete targets[Y.stamp(o, true)];
if (YObject.size(targets) === 0) {
this._yuievt.hasTargets = false;
}
}
};
/**
* Propagate an event. Requires the event-custom-complex module.
* @method bubble
* @param evt {CustomEvent} the custom event to propagate
* @return {boolean} the aggregated return value from Event.Custom.fire
* @for EventTarget
*/
ETProto.bubble = function(evt, args, target, es) {
var targs = this._yuievt.targets,
ret = true,
t,
ce,
i,
bc,
ce2,
type = evt && evt.type,
originalTarget = target || (evt && evt.target) || this,
oldbubble;
if (!evt || ((!evt.stopped) && targs)) {
for (i in targs) {
if (targs.hasOwnProperty(i)) {
t = targs[i];
ce = t._yuievt.events[type];
if (t._hasSiblings) {
ce2 = t.getSibling(type, ce);
}
if (ce2 && !ce) {
ce = t.publish(type);
}
oldbubble = t._yuievt.bubbling;
t._yuievt.bubbling = type;
// if this event was not published on the bubble target,
// continue propagating the event.
if (!ce) {
if (t._yuievt.hasTargets) {
t.bubble(evt, args, originalTarget, es);
}
} else {
if (ce2) {
ce.sibling = ce2;
}
// set the original target to that the target payload on the facade is correct.
ce.target = originalTarget;
ce.originalTarget = originalTarget;
ce.currentTarget = t;
bc = ce.broadcast;
ce.broadcast = false;
// default publish may not have emitFacade true -- that
// shouldn't be what the implementer meant to do
ce.emitFacade = true;
ce.stack = es;
// TODO: See what's getting in the way of changing this to use
// the more performant ce._fire(args || evt.details || []).
// Something in Widget Parent/Child tests is not happy if we
// change it - maybe evt.details related?
ret = ret && ce.fire.apply(ce, args || evt.details || []);
ce.broadcast = bc;
ce.originalTarget = null;
// stopPropagation() was called
if (ce.stopped) {
break;
}
}
t._yuievt.bubbling = oldbubble;
}
}
}
return ret;
};
/**
* @method _hasPotentialSubscribers
* @for EventTarget
* @private
* @param {String} fullType The fully prefixed type name
* @return {boolean} Whether the event has potential subscribers or not
*/
ETProto._hasPotentialSubscribers = function(fullType) {
var etState = this._yuievt,
e = etState.events[fullType];
if (e) {
return e.hasSubs() || etState.hasTargets || e.broadcast;
} else {
return false;
}
};
FACADE = new Y.EventFacade();
FACADE_KEYS = {};
// Flatten whitelist
for (key in FACADE) {
FACADE_KEYS[key] = true;
}
}, 'patched-v3.11.0', {"requires": ["event-custom-base"]});
YUI.add('event-delegate', function (Y, NAME) {
/**
* Adds event delegation support to the library.
*
* @module event
* @submodule event-delegate
*/
var toArray = Y.Array,
YLang = Y.Lang,
isString = YLang.isString,
isObject = YLang.isObject,
isArray = YLang.isArray,
selectorTest = Y.Selector.test,
detachCategories = Y.Env.evt.handles;
/**
* Sets up event delegation on a container element. The delegated event
* will use a supplied selector or filtering function to test if the event
* references at least one node that should trigger the subscription
* callback.
*
* Selector string filters will trigger the callback if the event originated
* from a node that matches it or is contained in a node that matches it.
* Function filters are called for each Node up the parent axis to the
* subscribing container node, and receive at each level the Node and the event
* object. The function should return true (or a truthy value) if that Node
* should trigger the subscription callback. Note, it is possible for filters
* to match multiple Nodes for a single event. In this case, the delegate
* callback will be executed for each matching Node.
*
* For each matching Node, the callback will be executed with its 'this'
* object set to the Node matched by the filter (unless a specific context was
* provided during subscription), and the provided event's
* currentTarget
will also be set to the matching Node. The
* containing Node from which the subscription was originally made can be
* referenced as e.container
.
*
* @method delegate
* @param type {String} the event type to delegate
* @param fn {Function} the callback function to execute. This function
* will be provided the event object for the delegated event.
* @param el {String|node} the element that is the delegation container
* @param filter {string|Function} a selector that must match the target of the
* event or a function to test target and its parents for a match
* @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
* @static
* @for Event
*/
function delegate(type, fn, el, filter) {
var args = toArray(arguments, 0, true),
query = isString(el) ? el : null,
typeBits, synth, container, categories, cat, i, len, handles, handle;
// Support Y.delegate({ click: fnA, key: fnB }, el, filter, ...);
// and Y.delegate(['click', 'key'], fn, el, filter, ...);
if (isObject(type)) {
handles = [];
if (isArray(type)) {
for (i = 0, len = type.length; i < len; ++i) {
args[0] = type[i];
handles.push(Y.delegate.apply(Y, args));
}
} else {
// Y.delegate({'click', fn}, el, filter) =>
// Y.delegate('click', fn, el, filter)
args.unshift(null); // one arg becomes two; need to make space
for (i in type) {
if (type.hasOwnProperty(i)) {
args[0] = i;
args[1] = type[i];
handles.push(Y.delegate.apply(Y, args));
}
}
}
return new Y.EventHandle(handles);
}
typeBits = type.split(/\|/);
if (typeBits.length > 1) {
cat = typeBits.shift();
args[0] = type = typeBits.shift();
}
synth = Y.Node.DOM_EVENTS[type];
if (isObject(synth) && synth.delegate) {
handle = synth.delegate.apply(synth, arguments);
}
if (!handle) {
if (!type || !fn || !el || !filter) {
return;
}
container = (query) ? Y.Selector.query(query, null, true) : el;
if (!container && isString(el)) {
handle = Y.on('available', function () {
Y.mix(handle, Y.delegate.apply(Y, args), true);
}, el);
}
if (!handle && container) {
args.splice(2, 2, container); // remove the filter
handle = Y.Event._attach(args, { facade: false });
handle.sub.filter = filter;
handle.sub._notify = delegate.notifySub;
}
}
if (handle && cat) {
categories = detachCategories[cat] || (detachCategories[cat] = {});
categories = categories[type] || (categories[type] = []);
categories.push(handle);
}
return handle;
}
/**
Overrides the _notify
method on the normal DOM subscription to
inject the filtering logic and only proceed in the case of a match.
This method is hosted as a private property of the `delegate` method
(e.g. `Y.delegate.notifySub`)
@method notifySub
@param thisObj {Object} default 'this' object for the callback
@param args {Array} arguments passed to the event's fire()
@param ce {CustomEvent} the custom event managing the DOM subscriptions for
the subscribed event on the subscribing node.
@return {Boolean} false if the event was stopped
@private
@static
@since 3.2.0
**/
delegate.notifySub = function (thisObj, args, ce) {
// Preserve args for other subscribers
args = args.slice();
if (this.args) {
args.push.apply(args, this.args);
}
// Only notify subs if the event occurred on a targeted element
var currentTarget = delegate._applyFilter(this.filter, args, ce),
//container = e.currentTarget,
e, i, len, ret;
if (currentTarget) {
// Support multiple matches up the the container subtree
currentTarget = toArray(currentTarget);
// The second arg is the currentTarget, but we'll be reusing this
// facade, replacing the currentTarget for each use, so it doesn't
// matter what element we seed it with.
e = args[0] = new Y.DOMEventFacade(args[0], ce.el, ce);
e.container = Y.one(ce.el);
for (i = 0, len = currentTarget.length; i < len && !e.stopped; ++i) {
e.currentTarget = Y.one(currentTarget[i]);
ret = this.fn.apply(this.context || e.currentTarget, args);
if (ret === false) { // stop further notifications
break;
}
}
return ret;
}
};
/**
Compiles a selector string into a filter function to identify whether
Nodes along the parent axis of an event's target should trigger event
notification.
This function is memoized, so previously compiled filter functions are
returned if the same selector string is provided.
This function may be useful when defining synthetic events for delegate
handling.
Hosted as a property of the `delegate` method (e.g. `Y.delegate.compileFilter`).
@method compileFilter
@param selector {String} the selector string to base the filtration on
@return {Function}
@since 3.2.0
@static
**/
delegate.compileFilter = Y.cached(function (selector) {
return function (target, e) {
return selectorTest(target._node, selector,
(e.currentTarget === e.target) ? null : e.currentTarget._node);
};
});
/**
Regex to test for disabled elements during filtering. This is only relevant to
IE to normalize behavior with other browsers, which swallow events that occur
to disabled elements. IE fires the event from the parent element instead of the
original target, though it does preserve `event.srcElement` as the disabled
element. IE also supports disabled on ``, but the event still bubbles, so it
acts more like `e.preventDefault()` plus styling. That issue is not handled here
because other browsers fire the event on the ` `, so delegate is supported in
both cases.
@property _disabledRE
@type {RegExp}
@protected
@since 3.8.1
**/
delegate._disabledRE = /^(?:button|input|select|textarea)$/i;
/**
Walks up the parent axis of an event's target, and tests each element
against a supplied filter function. If any Nodes, including the container,
satisfy the filter, the delegated callback will be triggered for each.
Hosted as a protected property of the `delegate` method (e.g.
`Y.delegate._applyFilter`).
@method _applyFilter
@param filter {Function} boolean function to test for inclusion in event
notification
@param args {Array} the arguments that would be passed to subscribers
@param ce {CustomEvent} the DOM event wrapper
@return {Node|Node[]|undefined} The Node or Nodes that satisfy the filter
@protected
**/
delegate._applyFilter = function (filter, args, ce) {
var e = args[0],
container = ce.el, // facadeless events in IE, have no e.currentTarget
target = e.target || e.srcElement,
match = [],
isContainer = false;
// Resolve text nodes to their containing element
if (target.nodeType === 3) {
target = target.parentNode;
}
// For IE. IE propagates events from the parent element of disabled
// elements, where other browsers swallow the event entirely. To normalize
// this in IE, filtering for matching elements should abort if the target
// is a disabled form control.
if (target.disabled && delegate._disabledRE.test(target.nodeName)) {
return match;
}
// passing target as the first arg rather than leaving well enough alone
// making 'this' in the filter function refer to the target. This is to
// support bound filter functions.
args.unshift(target);
if (isString(filter)) {
while (target) {
isContainer = (target === container);
if (selectorTest(target, filter, (isContainer ? null: container))) {
match.push(target);
}
if (isContainer) {
break;
}
target = target.parentNode;
}
} else {
// filter functions are implementer code and should receive wrappers
args[0] = Y.one(target);
args[1] = new Y.DOMEventFacade(e, container, ce);
while (target) {
// filter(target, e, extra args...) - this === target
if (filter.apply(args[0], args)) {
match.push(target);
}
if (target === container) {
break;
}
target = target.parentNode;
args[0] = Y.one(target);
}
args[1] = e; // restore the raw DOM event
}
if (match.length <= 1) {
match = match[0]; // single match or undefined
}
// remove the target
args.shift();
return match;
};
/**
* Sets up event delegation on a container element. The delegated event
* will use a supplied filter to test if the callback should be executed.
* This filter can be either a selector string or a function that returns
* a Node to use as the currentTarget for the event.
*
* The event object for the delegated event is supplied to the callback
* function. It is modified slightly in order to support all properties
* that may be needed for event delegation. 'currentTarget' is set to
* the element that matched the selector string filter or the Node returned
* from the filter function. 'container' is set to the element that the
* listener is delegated from (this normally would be the 'currentTarget').
*
* Filter functions will be called with the arguments that would be passed to
* the callback function, including the event object as the first parameter.
* The function should return false (or a falsey value) if the success criteria
* aren't met, and the Node to use as the event's currentTarget and 'this'
* object if they are.
*
* @method delegate
* @param type {string} the event type to delegate
* @param fn {function} the callback function to execute. This function
* will be provided the event object for the delegated event.
* @param el {string|node} the element that is the delegation container
* @param filter {string|function} a selector that must match the target of the
* event or a function that returns a Node or false.
* @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.delegate = Y.Event.delegate = delegate;
}, 'patched-v3.11.0', {"requires": ["node-base"]});
YUI.add('event-focus', function (Y, NAME) {
/**
* Adds bubbling and delegation support to DOM events focus and blur.
*
* @module event
* @submodule event-focus
*/
var Event = Y.Event,
YLang = Y.Lang,
isString = YLang.isString,
arrayIndex = Y.Array.indexOf,
useActivate = (function() {
// Changing the structure of this test, so that it doesn't use inline JS in HTML,
// which throws an exception in Win8 packaged apps, due to additional security restrictions:
// http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx#differences
var supported = false,
doc = Y.config.doc,
p;
if (doc) {
p = doc.createElement("p");
p.setAttribute("onbeforeactivate", ";");
// onbeforeactivate is a function in IE8+.
// onbeforeactivate is a string in IE6,7 (unfortunate, otherwise we could have just checked for function below).
// onbeforeactivate is a function in IE10, in a Win8 App environment (no exception running the test).
// onbeforeactivate is undefined in Webkit/Gecko.
// onbeforeactivate is a function in Webkit/Gecko if it's a supported event (e.g. onclick).
supported = (p.onbeforeactivate !== undefined);
}
return supported;
}());
function define(type, proxy, directEvent) {
var nodeDataKey = '_' + type + 'Notifiers';
Y.Event.define(type, {
_useActivate : useActivate,
_attach: function (el, notifier, delegate) {
if (Y.DOM.isWindow(el)) {
return Event._attach([type, function (e) {
notifier.fire(e);
}, el]);
} else {
return Event._attach(
[proxy, this._proxy, el, this, notifier, delegate],
{ capture: true });
}
},
_proxy: function (e, notifier, delegate) {
var target = e.target,
currentTarget = e.currentTarget,
notifiers = target.getData(nodeDataKey),
yuid = Y.stamp(currentTarget._node),
defer = (useActivate || target !== currentTarget),
directSub;
notifier.currentTarget = (delegate) ? target : currentTarget;
notifier.container = (delegate) ? currentTarget : null;
// Maintain a list to handle subscriptions from nested
// containers div#a>div#b>input #a.on(focus..) #b.on(focus..),
// use one focus or blur subscription that fires notifiers from
// #b then #a to emulate bubble sequence.
if (!notifiers) {
notifiers = {};
target.setData(nodeDataKey, notifiers);
// only subscribe to the element's focus if the target is
// not the current target (
if (defer) {
directSub = Event._attach(
[directEvent, this._notify, target._node]).sub;
directSub.once = true;
}
} else {
// In old IE, defer is always true. In capture-phase browsers,
// The delegate subscriptions will be encountered first, which
// will establish the notifiers data and direct subscription
// on the node. If there is also a direct subscription to the
// node's focus/blur, it should not call _notify because the
// direct subscription from the delegate sub(s) exists, which
// will call _notify. So this avoids _notify being called
// twice, unnecessarily.
defer = true;
}
if (!notifiers[yuid]) {
notifiers[yuid] = [];
}
notifiers[yuid].push(notifier);
if (!defer) {
this._notify(e);
}
},
_notify: function (e, container) {
var currentTarget = e.currentTarget,
notifierData = currentTarget.getData(nodeDataKey),
axisNodes = currentTarget.ancestors(),
doc = currentTarget.get('ownerDocument'),
delegates = [],
// Used to escape loops when there are no more
// notifiers to consider
count = notifierData ?
Y.Object.keys(notifierData).length :
0,
target, notifiers, notifier, yuid, match, tmp, i, len, sub, ret;
// clear the notifications list (mainly for delegation)
currentTarget.clearData(nodeDataKey);
// Order the delegate subs by their placement in the parent axis
axisNodes.push(currentTarget);
// document.get('ownerDocument') returns null
// which we'll use to prevent having duplicate Nodes in the list
if (doc) {
axisNodes.unshift(doc);
}
// ancestors() returns the Nodes from top to bottom
axisNodes._nodes.reverse();
if (count) {
// Store the count for step 2
tmp = count;
axisNodes.some(function (node) {
var yuid = Y.stamp(node),
notifiers = notifierData[yuid],
i, len;
if (notifiers) {
count--;
for (i = 0, len = notifiers.length; i < len; ++i) {
if (notifiers[i].handle.sub.filter) {
delegates.push(notifiers[i]);
}
}
}
return !count;
});
count = tmp;
}
// Walk up the parent axis, notifying direct subscriptions and
// testing delegate filters.
while (count && (target = axisNodes.shift())) {
yuid = Y.stamp(target);
notifiers = notifierData[yuid];
if (notifiers) {
for (i = 0, len = notifiers.length; i < len; ++i) {
notifier = notifiers[i];
sub = notifier.handle.sub;
match = true;
e.currentTarget = target;
if (sub.filter) {
match = sub.filter.apply(target,
[target, e].concat(sub.args || []));
// No longer necessary to test against this
// delegate subscription for the nodes along
// the parent axis.
delegates.splice(
arrayIndex(delegates, notifier), 1);
}
if (match) {
// undefined for direct subs
e.container = notifier.container;
ret = notifier.fire(e);
}
if (ret === false || e.stopped === 2) {
break;
}
}
delete notifiers[yuid];
count--;
}
if (e.stopped !== 2) {
// delegates come after subs targeting this specific node
// because they would not normally report until they'd
// bubbled to the container node.
for (i = 0, len = delegates.length; i < len; ++i) {
notifier = delegates[i];
sub = notifier.handle.sub;
if (sub.filter.apply(target,
[target, e].concat(sub.args || []))) {
e.container = notifier.container;
e.currentTarget = target;
ret = notifier.fire(e);
}
if (ret === false || e.stopped === 2) {
break;
}
}
}
if (e.stopped) {
break;
}
}
},
on: function (node, sub, notifier) {
sub.handle = this._attach(node._node, notifier);
},
detach: function (node, sub) {
sub.handle.detach();
},
delegate: function (node, sub, notifier, filter) {
if (isString(filter)) {
sub.filter = function (target) {
return Y.Selector.test(target._node, filter,
node === target ? null : node._node);
};
}
sub.handle = this._attach(node._node, notifier, true);
},
detachDelegate: function (node, sub) {
sub.handle.detach();
}
}, true);
}
// For IE, we need to defer to focusin rather than focus because
// `el.focus(); doSomething();` executes el.onbeforeactivate, el.onactivate,
// el.onfocusin, doSomething, then el.onfocus. All others support capture
// phase focus, which executes before doSomething. To guarantee consistent
// behavior for this use case, IE's direct subscriptions are made against
// focusin so subscribers will be notified before js following el.focus() is
// executed.
if (useActivate) {
// name capture phase direct subscription
define("focus", "beforeactivate", "focusin");
define("blur", "beforedeactivate", "focusout");
} else {
define("focus", "focus", "focus");
define("blur", "blur", "blur");
}
}, 'patched-v3.11.0', {"requires": ["event-synthetic"]});
YUI.add('event-hover', function (Y, NAME) {
/**
* Adds support for a "hover" event. The event provides a convenience wrapper
* for subscribing separately to mouseenter and mouseleave. The signature for
* subscribing to the event is
*
* node.on("hover", overFn, outFn);
* node.delegate("hover", overFn, outFn, ".filterSelector");
* Y.on("hover", overFn, outFn, ".targetSelector");
* Y.delegate("hover", overFn, outFn, "#container", ".filterSelector");
*
*
* Additionally, for compatibility with a more typical subscription
* signature, the following are also supported:
*
* Y.on("hover", overFn, ".targetSelector", outFn);
* Y.delegate("hover", overFn, "#container", outFn, ".filterSelector");
*
*
* @module event
* @submodule event-hover
*/
var isFunction = Y.Lang.isFunction,
noop = function () {},
conf = {
processArgs: function (args) {
// Y.delegate('hover', over, out, '#container', '.filter')
// comes in as ['hover', over, out, '#container', '.filter'], but
// node.delegate('hover', over, out, '.filter')
// comes in as ['hover', over, containerEl, out, '.filter']
var i = isFunction(args[2]) ? 2 : 3;
return (isFunction(args[i])) ? args.splice(i,1)[0] : noop;
},
on: function (node, sub, notifier, filter) {
var args = (sub.args) ? sub.args.slice() : [];
args.unshift(null);
sub._detach = node[(filter) ? "delegate" : "on"]({
mouseenter: function (e) {
e.phase = 'over';
notifier.fire(e);
},
mouseleave: function (e) {
var thisObj = sub.context || this;
args[0] = e;
e.type = 'hover';
e.phase = 'out';
sub._extra.apply(thisObj, args);
}
}, filter);
},
detach: function (node, sub, notifier) {
sub._detach.detach();
}
};
conf.delegate = conf.on;
conf.detachDelegate = conf.detach;
Y.Event.define("hover", conf);
}, 'patched-v3.11.0', {"requires": ["event-mouseenter"]});
YUI.add('event-key', function (Y, NAME) {
/**
* Functionality to listen for one or more specific key combinations.
* @module event
* @submodule event-key
*/
var ALT = "+alt",
CTRL = "+ctrl",
META = "+meta",
SHIFT = "+shift",
trim = Y.Lang.trim,
eventDef = {
KEY_MAP: {
enter : 13,
esc : 27,
backspace: 8,
tab : 9,
pageup : 33,
pagedown : 34
},
_typeRE: /^(up|down|press):/,
_keysRE: /^(?:up|down|press):|\+(alt|ctrl|meta|shift)/g,
processArgs: function (args) {
var spec = args.splice(3,1)[0],
mods = Y.Array.hash(spec.match(/\+(?:alt|ctrl|meta|shift)\b/g) || []),
config = {
type: this._typeRE.test(spec) ? RegExp.$1 : null,
mods: mods,
keys: null
},
// strip type and modifiers from spec, leaving only keyCodes
bits = spec.replace(this._keysRE, ''),
chr, uc, lc, i;
if (bits) {
bits = bits.split(',');
config.keys = {};
// FIXME: need to support '65,esc' => keypress, keydown
for (i = bits.length - 1; i >= 0; --i) {
chr = trim(bits[i]);
// catch sloppy filters, trailing commas, etc 'a,,'
if (!chr) {
continue;
}
// non-numerics are single characters or key names
if (+chr == chr) {
config.keys[chr] = mods;
} else {
lc = chr.toLowerCase();
if (this.KEY_MAP[lc]) {
config.keys[this.KEY_MAP[lc]] = mods;
// FIXME: '65,enter' defaults keydown for both
if (!config.type) {
config.type = "down"; // safest
}
} else {
// FIXME: Character mapping only works for keypress
// events. Otherwise, it uses String.fromCharCode()
// from the keyCode, which is wrong.
chr = chr.charAt(0);
uc = chr.toUpperCase();
if (mods["+shift"]) {
chr = uc;
}
// FIXME: stupid assumption that
// the keycode of the lower case == the
// charCode of the upper case
// a (key:65,char:97), A (key:65,char:65)
config.keys[chr.charCodeAt(0)] =
(chr === uc) ?
// upper case chars get +shift free
Y.merge(mods, { "+shift": true }) :
mods;
}
}
}
}
if (!config.type) {
config.type = "press";
}
return config;
},
on: function (node, sub, notifier, filter) {
var spec = sub._extra,
type = "key" + spec.type,
keys = spec.keys,
method = (filter) ? "delegate" : "on";
// Note: without specifying any keyCodes, this becomes a
// horribly inefficient alias for 'keydown' (et al), but I
// can't abort this subscription for a simple
// Y.on('keypress', ...);
// Please use keyCodes or just subscribe directly to keydown,
// keyup, or keypress
sub._detach = node[method](type, function (e) {
var key = keys ? keys[e.which] : spec.mods;
if (key &&
(!key[ALT] || (key[ALT] && e.altKey)) &&
(!key[CTRL] || (key[CTRL] && e.ctrlKey)) &&
(!key[META] || (key[META] && e.metaKey)) &&
(!key[SHIFT] || (key[SHIFT] && e.shiftKey)))
{
notifier.fire(e);
}
}, filter);
},
detach: function (node, sub, notifier) {
sub._detach.detach();
}
};
eventDef.delegate = eventDef.on;
eventDef.detachDelegate = eventDef.detach;
/**
* Add a key listener. The listener will only be notified if the
* keystroke detected meets the supplied specification. The
* specification is a string that is defined as:
*
*
* spec
* [{type}:]{code}[,{code}]*
* type
* "down", "up", or "press"
* code
* {keyCode|character|keyName}[+{modifier}]*
* modifier
* "shift", "ctrl", "alt", or "meta"
* keyName
* "enter", "backspace", "esc", "tab", "pageup", or "pagedown"
*
*
* Examples:
*
* Y.on("key", callback, "press:12,65+shift+ctrl", "#my-input");
* Y.delegate("key", preventSubmit, "#forms", "enter", "input[type=text]");
* Y.one("doc").on("key", viNav, "j,k,l,;");
*
*
* @event key
* @for YUI
* @param type {string} 'key'
* @param fn {function} the function to execute
* @param id {string|HTMLElement|collection} the element(s) to bind
* @param spec {string} the keyCode and modifier specification
* @param o optional context object
* @param args 0..n additional arguments to provide to the listener.
* @return {Event.Handle} the detach handle
*/
Y.Event.define('key', eventDef, true);
}, 'patched-v3.11.0', {"requires": ["event-synthetic"]});
YUI.add('event-mouseenter', function (Y, NAME) {
/**
* Adds subscription and delegation support for mouseenter and mouseleave
* events. Unlike mouseover and mouseout, these events aren't fired from child
* elements of a subscribed node.
*
* This avoids receiving three mouseover notifications from a setup like
*
* div#container > p > a[href]
*
* where
*
* Y.one('#container').on('mouseover', callback)
*
* When the mouse moves over the link, one mouseover event is fired from
* #container, then when the mouse moves over the p, another mouseover event is
* fired and bubbles to #container, causing a second notification, and finally
* when the mouse moves over the link, a third mouseover event is fired and
* bubbles to #container for a third notification.
*
* By contrast, using mouseenter instead of mouseover, the callback would be
* executed only once when the mouse moves over #container.
*
* @module event
* @submodule event-mouseenter
*/
var domEventProxies = Y.Env.evt.dom_wrappers,
contains = Y.DOM.contains,
toArray = Y.Array,
noop = function () {},
config = {
proxyType: "mouseover",
relProperty: "fromElement",
_notify: function (e, property, notifier) {
var el = this._node,
related = e.relatedTarget || e[property];
if (el !== related && !contains(el, related)) {
notifier.fire(new Y.DOMEventFacade(e, el,
domEventProxies['event:' + Y.stamp(el) + e.type]));
}
},
on: function (node, sub, notifier) {
var el = Y.Node.getDOMNode(node),
args = [
this.proxyType,
this._notify,
el,
null,
this.relProperty,
notifier];
sub.handle = Y.Event._attach(args, { facade: false });
// node.on(this.proxyType, notify, null, notifier);
},
detach: function (node, sub) {
sub.handle.detach();
},
delegate: function (node, sub, notifier, filter) {
var el = Y.Node.getDOMNode(node),
args = [
this.proxyType,
noop,
el,
null,
notifier
];
sub.handle = Y.Event._attach(args, { facade: false });
sub.handle.sub.filter = filter;
sub.handle.sub.relProperty = this.relProperty;
sub.handle.sub._notify = this._filterNotify;
},
_filterNotify: function (thisObj, args, ce) {
args = args.slice();
if (this.args) {
args.push.apply(args, this.args);
}
var currentTarget = Y.delegate._applyFilter(this.filter, args, ce),
related = args[0].relatedTarget || args[0][this.relProperty],
e, i, len, ret, ct;
if (currentTarget) {
currentTarget = toArray(currentTarget);
for (i = 0, len = currentTarget.length && (!e || !e.stopped); i < len; ++i) {
ct = currentTarget[0];
if (!contains(ct, related)) {
if (!e) {
e = new Y.DOMEventFacade(args[0], ct, ce);
e.container = Y.one(ce.el);
}
e.currentTarget = Y.one(ct);
// TODO: where is notifier? args? this.notifier?
ret = args[1].fire(e);
if (ret === false) {
break;
}
}
}
}
return ret;
},
detachDelegate: function (node, sub) {
sub.handle.detach();
}
};
Y.Event.define("mouseenter", config, true);
Y.Event.define("mouseleave", Y.merge(config, {
proxyType: "mouseout",
relProperty: "toElement"
}), true);
}, 'patched-v3.11.0', {"requires": ["event-synthetic"]});
YUI.add('event-mousewheel', function (Y, NAME) {
/**
* Adds mousewheel event support
* @module event
* @submodule event-mousewheel
*/
var DOM_MOUSE_SCROLL = 'DOMMouseScroll',
fixArgs = function(args) {
var a = Y.Array(args, 0, true), target;
if (Y.UA.gecko) {
a[0] = DOM_MOUSE_SCROLL;
target = Y.config.win;
} else {
target = Y.config.doc;
}
if (a.length < 3) {
a[2] = target;
} else {
a.splice(2, 0, target);
}
return a;
};
/**
* Mousewheel event. This listener is automatically attached to the
* correct target, so one should not be supplied. Mouse wheel
* direction and velocity is stored in the 'wheelDelta' field.
* @event mousewheel
* @param type {string} 'mousewheel'
* @param fn {function} the callback to execute
* @param context optional context object
* @param args 0..n additional arguments to provide to the listener.
* @return {EventHandle} the detach handle
* @for YUI
*/
Y.Env.evt.plugins.mousewheel = {
on: function() {
return Y.Event._attach(fixArgs(arguments));
},
detach: function() {
return Y.Event.detach.apply(Y.Event, fixArgs(arguments));
}
};
}, 'patched-v3.11.0', {"requires": ["node-base"]});
YUI.add('event-outside', function (Y, NAME) {
/**
* Outside events are synthetic DOM events that fire when a corresponding native
* or synthetic DOM event occurs outside a bound element.
*
* The following outside events are pre-defined by this module:
*
* blur
* change
* click
* dblclick
* focus
* keydown
* keypress
* keyup
* mousedown
* mousemove
* mouseout
* mouseover
* mouseup
* select
* submit
*
*
* Define new outside events with
* Y.Event.defineOutside(eventType);
.
* By default, the created synthetic event name will be the name of the event
* with "outside" appended (e.g. "click" becomes "clickoutside"). If you want
* a different name for the created Event, pass it as a second argument like so:
* Y.Event.defineOutside(eventType, "yonderclick")
.
*
* This module was contributed by Brett Stimmerman, promoted from his
* gallery-outside-events module at
* http://yuilibrary.com/gallery/show/outside-events
*
* @module event
* @submodule event-outside
* @author brettstimmerman
* @since 3.4.0
*/
// Outside events are pre-defined for each of these native DOM events
var nativeEvents = [
'blur', 'change', 'click', 'dblclick', 'focus', 'keydown', 'keypress',
'keyup', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup',
'select', 'submit'
];
/**
* Defines a new outside event to correspond with the given DOM event.
*
* By default, the created synthetic event name will be the name of the event
* with "outside" appended (e.g. "click" becomes "clickoutside"). If you want
* a different name for the created Event, pass it as a second argument like so:
* Y.Event.defineOutside(eventType, "yonderclick")
.
*
* @method defineOutside
* @param {String} event DOM event
* @param {String} name (optional) custom outside event name
* @static
* @for Event
*/
Y.Event.defineOutside = function (event, name) {
name = name || (event + 'outside');
var config = {
on: function (node, sub, notifier) {
sub.handle = Y.one('doc').on(event, function(e) {
if (this.isOutside(node, e.target)) {
e.currentTarget = node;
notifier.fire(e);
}
}, this);
},
detach: function (node, sub, notifier) {
sub.handle.detach();
},
delegate: function (node, sub, notifier, filter) {
sub.handle = Y.one('doc').delegate(event, function (e) {
if (this.isOutside(node, e.target)) {
notifier.fire(e);
}
}, filter, this);
},
isOutside: function (node, target) {
return target !== node && !target.ancestor(function (p) {
return p === node;
});
}
};
config.detachDelegate = config.detach;
Y.Event.define(name, config);
};
// Define outside events for some common native DOM events
Y.Array.each(nativeEvents, function (event) {
Y.Event.defineOutside(event);
});
}, 'patched-v3.11.0', {"requires": ["event-synthetic"]});
YUI.add('event-resize', function (Y, NAME) {
/**
* Adds a window resize event that has its behavior normalized to fire at the
* end of the resize rather than constantly during the resize.
* @module event
* @submodule event-resize
*/
/**
* Old firefox fires the window resize event once when the resize action
* finishes, other browsers fire the event periodically during the
* resize. This code uses timeout logic to simulate the Firefox
* behavior in other browsers.
* @event windowresize
* @for YUI
*/
Y.Event.define('windowresize', {
on: (Y.UA.gecko && Y.UA.gecko < 1.91) ?
function (node, sub, notifier) {
sub._handle = Y.Event.attach('resize', function (e) {
notifier.fire(e);
});
} :
function (node, sub, notifier) {
// interval bumped from 40 to 100ms as of 3.4.1
var delay = Y.config.windowResizeDelay || 100;
sub._handle = Y.Event.attach('resize', function (e) {
if (sub._timer) {
sub._timer.cancel();
}
sub._timer = Y.later(delay, Y, function () {
notifier.fire(e);
});
});
},
detach: function (node, sub) {
if (sub._timer) {
sub._timer.cancel();
}
sub._handle.detach();
}
// delegate methods not defined because this only works for window
// subscriptions, so...yeah.
});
}, 'patched-v3.11.0', {"requires": ["node-base", "event-synthetic"]});
YUI.add('event-simulate', function (Y, NAME) {
(function() {
/**
* Simulate user interaction by generating native DOM events.
*
* @module event-simulate
* @requires event
*/
//shortcuts
var L = Y.Lang,
win = Y.config.win,
isFunction = L.isFunction,
isString = L.isString,
isBoolean = L.isBoolean,
isObject = L.isObject,
isNumber = L.isNumber,
//mouse events supported
mouseEvents = {
click: 1,
dblclick: 1,
mouseover: 1,
mouseout: 1,
mousedown: 1,
mouseup: 1,
mousemove: 1,
contextmenu:1
},
pointerEvents = (win && win.PointerEvent) ? {
pointerover: 1,
pointerout: 1,
pointerdown: 1,
pointerup: 1,
pointermove: 1
} : {
MSPointerOver: 1,
MSPointerOut: 1,
MSPointerDown: 1,
MSPointerUp: 1,
MSPointerMove: 1
},
//key events supported
keyEvents = {
keydown: 1,
keyup: 1,
keypress: 1
},
//HTML events supported
uiEvents = {
submit: 1,
blur: 1,
change: 1,
focus: 1,
resize: 1,
scroll: 1,
select: 1
},
//events that bubble by default
bubbleEvents = {
scroll: 1,
resize: 1,
reset: 1,
submit: 1,
change: 1,
select: 1,
error: 1,
abort: 1
},
//touch events supported
touchEvents = {
touchstart: 1,
touchmove: 1,
touchend: 1,
touchcancel: 1
},
gestureEvents = {
gesturestart: 1,
gesturechange: 1,
gestureend: 1
};
//all key, mouse and touch events bubble
Y.mix(bubbleEvents, mouseEvents);
Y.mix(bubbleEvents, keyEvents);
Y.mix(bubbleEvents, touchEvents);
/*
* Note: Intentionally not for YUIDoc generation.
* Simulates a key event using the given event information to populate
* the generated event object. This method does browser-equalizing
* calculations to account for differences in the DOM and IE event models
* as well as different browser quirks. Note: keydown causes Safari 2.x to
* crash.
* @method simulateKeyEvent
* @private
* @static
* @param {HTMLElement} target The target of the given event.
* @param {String} type The type of event to fire. This can be any one of
* the following: keyup, keydown, and keypress.
* @param {Boolean} bubbles (Optional) Indicates if the event can be
* bubbled up. DOM Level 3 specifies that all key events bubble by
* default. The default is true.
* @param {Boolean} cancelable (Optional) Indicates if the event can be
* canceled using preventDefault(). DOM Level 3 specifies that all
* key events can be cancelled. The default
* is true.
* @param {Window} view (Optional) The view containing the target. This is
* typically the window object. The default is window.
* @param {Boolean} ctrlKey (Optional) Indicates if one of the CTRL keys
* is pressed while the event is firing. The default is false.
* @param {Boolean} altKey (Optional) Indicates if one of the ALT keys
* is pressed while the event is firing. The default is false.
* @param {Boolean} shiftKey (Optional) Indicates if one of the SHIFT keys
* is pressed while the event is firing. The default is false.
* @param {Boolean} metaKey (Optional) Indicates if one of the META keys
* is pressed while the event is firing. The default is false.
* @param {int} keyCode (Optional) The code for the key that is in use.
* The default is 0.
* @param {int} charCode (Optional) The Unicode code for the character
* associated with the key being used. The default is 0.
*/
function simulateKeyEvent(target /*:HTMLElement*/, type /*:String*/,
bubbles /*:Boolean*/, cancelable /*:Boolean*/,
view /*:Window*/,
ctrlKey /*:Boolean*/, altKey /*:Boolean*/,
shiftKey /*:Boolean*/, metaKey /*:Boolean*/,
keyCode /*:int*/, charCode /*:int*/) /*:Void*/
{
//check target
if (!target){
Y.error("simulateKeyEvent(): Invalid target.");
}
//check event type
if (isString(type)){
type = type.toLowerCase();
switch(type){
case "textevent": //DOM Level 3
type = "keypress";
break;
case "keyup":
case "keydown":
case "keypress":
break;
default:
Y.error("simulateKeyEvent(): Event type '" + type + "' not supported.");
}
} else {
Y.error("simulateKeyEvent(): Event type must be a string.");
}
//setup default values
if (!isBoolean(bubbles)){
bubbles = true; //all key events bubble
}
if (!isBoolean(cancelable)){
cancelable = true; //all key events can be cancelled
}
if (!isObject(view)){
view = Y.config.win; //view is typically window
}
if (!isBoolean(ctrlKey)){
ctrlKey = false;
}
if (!isBoolean(altKey)){
altKey = false;
}
if (!isBoolean(shiftKey)){
shiftKey = false;
}
if (!isBoolean(metaKey)){
metaKey = false;
}
if (!isNumber(keyCode)){
keyCode = 0;
}
if (!isNumber(charCode)){
charCode = 0;
}
//try to create a mouse event
var customEvent /*:MouseEvent*/ = null;
//check for DOM-compliant browsers first
if (isFunction(Y.config.doc.createEvent)){
try {
//try to create key event
customEvent = Y.config.doc.createEvent("KeyEvents");
/*
* Interesting problem: Firefox implemented a non-standard
* version of initKeyEvent() based on DOM Level 2 specs.
* Key event was removed from DOM Level 2 and re-introduced
* in DOM Level 3 with a different interface. Firefox is the
* only browser with any implementation of Key Events, so for
* now, assume it's Firefox if the above line doesn't error.
*/
// @TODO: Decipher between Firefox's implementation and a correct one.
customEvent.initKeyEvent(type, bubbles, cancelable, view, ctrlKey,
altKey, shiftKey, metaKey, keyCode, charCode);
} catch (ex /*:Error*/){
/*
* If it got here, that means key events aren't officially supported.
* Safari/WebKit is a real problem now. WebKit 522 won't let you
* set keyCode, charCode, or other properties if you use a
* UIEvent, so we first must try to create a generic event. The
* fun part is that this will throw an error on Safari 2.x. The
* end result is that we need another try...catch statement just to
* deal with this mess.
*/
try {
//try to create generic event - will fail in Safari 2.x
customEvent = Y.config.doc.createEvent("Events");
} catch (uierror /*:Error*/){
//the above failed, so create a UIEvent for Safari 2.x
customEvent = Y.config.doc.createEvent("UIEvents");
} finally {
customEvent.initEvent(type, bubbles, cancelable);
//initialize
customEvent.view = view;
customEvent.altKey = altKey;
customEvent.ctrlKey = ctrlKey;
customEvent.shiftKey = shiftKey;
customEvent.metaKey = metaKey;
customEvent.keyCode = keyCode;
customEvent.charCode = charCode;
}
}
//fire the event
target.dispatchEvent(customEvent);
} else if (isObject(Y.config.doc.createEventObject)){ //IE
//create an IE event object
customEvent = Y.config.doc.createEventObject();
//assign available properties
customEvent.bubbles = bubbles;
customEvent.cancelable = cancelable;
customEvent.view = view;
customEvent.ctrlKey = ctrlKey;
customEvent.altKey = altKey;
customEvent.shiftKey = shiftKey;
customEvent.metaKey = metaKey;
/*
* IE doesn't support charCode explicitly. CharCode should
* take precedence over any keyCode value for accurate
* representation.
*/
customEvent.keyCode = (charCode > 0) ? charCode : keyCode;
//fire the event
target.fireEvent("on" + type, customEvent);
} else {
Y.error("simulateKeyEvent(): No event simulation framework present.");
}
}
/*
* Note: Intentionally not for YUIDoc generation.
* Simulates a mouse event using the given event information to populate
* the generated event object. This method does browser-equalizing
* calculations to account for differences in the DOM and IE event models
* as well as different browser quirks.
* @method simulateMouseEvent
* @private
* @static
* @param {HTMLElement} target The target of the given event.
* @param {String} type The type of event to fire. This can be any one of
* the following: click, dblclick, mousedown, mouseup, mouseout,
* mouseover, and mousemove.
* @param {Boolean} bubbles (Optional) Indicates if the event can be
* bubbled up. DOM Level 2 specifies that all mouse events bubble by
* default. The default is true.
* @param {Boolean} cancelable (Optional) Indicates if the event can be
* canceled using preventDefault(). DOM Level 2 specifies that all
* mouse events except mousemove can be cancelled. The default
* is true for all events except mousemove, for which the default
* is false.
* @param {Window} view (Optional) The view containing the target. This is
* typically the window object. The default is window.
* @param {int} detail (Optional) The number of times the mouse button has
* been used. The default value is 1.
* @param {int} screenX (Optional) The x-coordinate on the screen at which
* point the event occured. The default is 0.
* @param {int} screenY (Optional) The y-coordinate on the screen at which
* point the event occured. The default is 0.
* @param {int} clientX (Optional) The x-coordinate on the client at which
* point the event occured. The default is 0.
* @param {int} clientY (Optional) The y-coordinate on the client at which
* point the event occured. The default is 0.
* @param {Boolean} ctrlKey (Optional) Indicates if one of the CTRL keys
* is pressed while the event is firing. The default is false.
* @param {Boolean} altKey (Optional) Indicates if one of the ALT keys
* is pressed while the event is firing. The default is false.
* @param {Boolean} shiftKey (Optional) Indicates if one of the SHIFT keys
* is pressed while the event is firing. The default is false.
* @param {Boolean} metaKey (Optional) Indicates if one of the META keys
* is pressed while the event is firing. The default is false.
* @param {int} button (Optional) The button being pressed while the event
* is executing. The value should be 0 for the primary mouse button
* (typically the left button), 1 for the terciary mouse button
* (typically the middle button), and 2 for the secondary mouse button
* (typically the right button). The default is 0.
* @param {HTMLElement} relatedTarget (Optional) For mouseout events,
* this is the element that the mouse has moved to. For mouseover
* events, this is the element that the mouse has moved from. This
* argument is ignored for all other events. The default is null.
*/
function simulateMouseEvent(target /*:HTMLElement*/, type /*:String*/,
bubbles /*:Boolean*/, cancelable /*:Boolean*/,
view /*:Window*/, detail /*:int*/,
screenX /*:int*/, screenY /*:int*/,
clientX /*:int*/, clientY /*:int*/,
ctrlKey /*:Boolean*/, altKey /*:Boolean*/,
shiftKey /*:Boolean*/, metaKey /*:Boolean*/,
button /*:int*/, relatedTarget /*:HTMLElement*/) /*:Void*/
{
//check target
if (!target){
Y.error("simulateMouseEvent(): Invalid target.");
}
if (isString(type)){
//make sure it's a supported mouse event or an msPointerEvent.
if (!mouseEvents[type.toLowerCase()] && !pointerEvents[type]){
Y.error("simulateMouseEvent(): Event type '" + type + "' not supported.");
}
}
else {
Y.error("simulateMouseEvent(): Event type must be a string.");
}
//setup default values
if (!isBoolean(bubbles)){
bubbles = true; //all mouse events bubble
}
if (!isBoolean(cancelable)){
cancelable = (type !== "mousemove"); //mousemove is the only one that can't be cancelled
}
if (!isObject(view)){
view = Y.config.win; //view is typically window
}
if (!isNumber(detail)){
detail = 1; //number of mouse clicks must be at least one
}
if (!isNumber(screenX)){
screenX = 0;
}
if (!isNumber(screenY)){
screenY = 0;
}
if (!isNumber(clientX)){
clientX = 0;
}
if (!isNumber(clientY)){
clientY = 0;
}
if (!isBoolean(ctrlKey)){
ctrlKey = false;
}
if (!isBoolean(altKey)){
altKey = false;
}
if (!isBoolean(shiftKey)){
shiftKey = false;
}
if (!isBoolean(metaKey)){
metaKey = false;
}
if (!isNumber(button)){
button = 0;
}
relatedTarget = relatedTarget || null;
//try to create a mouse event
var customEvent /*:MouseEvent*/ = null;
//check for DOM-compliant browsers first
if (isFunction(Y.config.doc.createEvent)){
customEvent = Y.config.doc.createEvent("MouseEvents");
//Safari 2.x (WebKit 418) still doesn't implement initMouseEvent()
if (customEvent.initMouseEvent){
customEvent.initMouseEvent(type, bubbles, cancelable, view, detail,
screenX, screenY, clientX, clientY,
ctrlKey, altKey, shiftKey, metaKey,
button, relatedTarget);
} else { //Safari
//the closest thing available in Safari 2.x is UIEvents
customEvent = Y.config.doc.createEvent("UIEvents");
customEvent.initEvent(type, bubbles, cancelable);
customEvent.view = view;
customEvent.detail = detail;
customEvent.screenX = screenX;
customEvent.screenY = screenY;
customEvent.clientX = clientX;
customEvent.clientY = clientY;
customEvent.ctrlKey = ctrlKey;
customEvent.altKey = altKey;
customEvent.metaKey = metaKey;
customEvent.shiftKey = shiftKey;
customEvent.button = button;
customEvent.relatedTarget = relatedTarget;
}
/*
* Check to see if relatedTarget has been assigned. Firefox
* versions less than 2.0 don't allow it to be assigned via
* initMouseEvent() and the property is readonly after event
* creation, so in order to keep YAHOO.util.getRelatedTarget()
* working, assign to the IE proprietary toElement property
* for mouseout event and fromElement property for mouseover
* event.
*/
if (relatedTarget && !customEvent.relatedTarget){
if (type === "mouseout"){
customEvent.toElement = relatedTarget;
} else if (type === "mouseover"){
customEvent.fromElement = relatedTarget;
}
}
//fire the event
target.dispatchEvent(customEvent);
} else if (isObject(Y.config.doc.createEventObject)){ //IE
//create an IE event object
customEvent = Y.config.doc.createEventObject();
//assign available properties
customEvent.bubbles = bubbles;
customEvent.cancelable = cancelable;
customEvent.view = view;
customEvent.detail = detail;
customEvent.screenX = screenX;
customEvent.screenY = screenY;
customEvent.clientX = clientX;
customEvent.clientY = clientY;
customEvent.ctrlKey = ctrlKey;
customEvent.altKey = altKey;
customEvent.metaKey = metaKey;
customEvent.shiftKey = shiftKey;
//fix button property for IE's wacky implementation
switch(button){
case 0:
customEvent.button = 1;
break;
case 1:
customEvent.button = 4;
break;
case 2:
//leave as is
break;
default:
customEvent.button = 0;
}
/*
* Have to use relatedTarget because IE won't allow assignment
* to toElement or fromElement on generic events. This keeps
* YAHOO.util.customEvent.getRelatedTarget() functional.
*/
customEvent.relatedTarget = relatedTarget;
//fire the event
target.fireEvent("on" + type, customEvent);
} else {
Y.error("simulateMouseEvent(): No event simulation framework present.");
}
}
/*
* Note: Intentionally not for YUIDoc generation.
* Simulates a UI event using the given event information to populate
* the generated event object. This method does browser-equalizing
* calculations to account for differences in the DOM and IE event models
* as well as different browser quirks.
* @method simulateHTMLEvent
* @private
* @static
* @param {HTMLElement} target The target of the given event.
* @param {String} type The type of event to fire. This can be any one of
* the following: click, dblclick, mousedown, mouseup, mouseout,
* mouseover, and mousemove.
* @param {Boolean} bubbles (Optional) Indicates if the event can be
* bubbled up. DOM Level 2 specifies that all mouse events bubble by
* default. The default is true.
* @param {Boolean} cancelable (Optional) Indicates if the event can be
* canceled using preventDefault(). DOM Level 2 specifies that all
* mouse events except mousemove can be cancelled. The default
* is true for all events except mousemove, for which the default
* is false.
* @param {Window} view (Optional) The view containing the target. This is
* typically the window object. The default is window.
* @param {int} detail (Optional) The number of times the mouse button has
* been used. The default value is 1.
*/
function simulateUIEvent(target /*:HTMLElement*/, type /*:String*/,
bubbles /*:Boolean*/, cancelable /*:Boolean*/,
view /*:Window*/, detail /*:int*/) /*:Void*/
{
//check target
if (!target){
Y.error("simulateUIEvent(): Invalid target.");
}
//check event type
if (isString(type)){
type = type.toLowerCase();
//make sure it's a supported mouse event
if (!uiEvents[type]){
Y.error("simulateUIEvent(): Event type '" + type + "' not supported.");
}
} else {
Y.error("simulateUIEvent(): Event type must be a string.");
}
//try to create a mouse event
var customEvent = null;
//setup default values
if (!isBoolean(bubbles)){
bubbles = (type in bubbleEvents); //not all events bubble
}
if (!isBoolean(cancelable)){
cancelable = (type === "submit"); //submit is the only one that can be cancelled
}
if (!isObject(view)){
view = Y.config.win; //view is typically window
}
if (!isNumber(detail)){
detail = 1; //usually not used but defaulted to this
}
//check for DOM-compliant browsers first
if (isFunction(Y.config.doc.createEvent)){
//just a generic UI Event object is needed
customEvent = Y.config.doc.createEvent("UIEvents");
customEvent.initUIEvent(type, bubbles, cancelable, view, detail);
//fire the event
target.dispatchEvent(customEvent);
} else if (isObject(Y.config.doc.createEventObject)){ //IE
//create an IE event object
customEvent = Y.config.doc.createEventObject();
//assign available properties
customEvent.bubbles = bubbles;
customEvent.cancelable = cancelable;
customEvent.view = view;
customEvent.detail = detail;
//fire the event
target.fireEvent("on" + type, customEvent);
} else {
Y.error("simulateUIEvent(): No event simulation framework present.");
}
}
/*
* (iOS only) This is for creating native DOM gesture events which only iOS
* v2.0+ is supporting.
*
* @method simulateGestureEvent
* @private
* @param {HTMLElement} target The target of the given event.
* @param {String} type The type of event to fire. This can be any one of
* the following: touchstart, touchmove, touchend, touchcancel.
* @param {Boolean} bubbles (Optional) Indicates if the event can be
* bubbled up. DOM Level 2 specifies that all mouse events bubble by
* default. The default is true.
* @param {Boolean} cancelable (Optional) Indicates if the event can be
* canceled using preventDefault(). DOM Level 2 specifies that all
* touch events except touchcancel can be cancelled. The default
* is true for all events except touchcancel, for which the default
* is false.
* @param {Window} view (Optional) The view containing the target. This is
* typically the window object. The default is window.
* @param {int} detail (Optional) Specifies some detail information about
* the event depending on the type of event.
* @param {int} screenX (Optional) The x-coordinate on the screen at which
* point the event occured. The default is 0.
* @param {int} screenY (Optional) The y-coordinate on the screen at which
* point the event occured. The default is 0.
* @param {int} clientX (Optional) The x-coordinate on the client at which
* point the event occured. The default is 0.
* @param {int} clientY (Optional) The y-coordinate on the client at which
* point the event occured. The default is 0.
* @param {Boolean} ctrlKey (Optional) Indicates if one of the CTRL keys
* is pressed while the event is firing. The default is false.
* @param {Boolean} altKey (Optional) Indicates if one of the ALT keys
* is pressed while the event is firing. The default is false.
* @param {Boolean} shiftKey (Optional) Indicates if one of the SHIFT keys
* is pressed while the event is firing. The default is false.
* @param {Boolean} metaKey (Optional) Indicates if one of the META keys
* is pressed while the event is firing. The default is false.
* @param {float} scale (iOS v2+ only) The distance between two fingers
* since the start of an event as a multiplier of the initial distance.
* The default value is 1.0.
* @param {float} rotation (iOS v2+ only) The delta rotation since the start
* of an event, in degrees, where clockwise is positive and
* counter-clockwise is negative. The default value is 0.0.
*/
function simulateGestureEvent(target, type,
bubbles, // boolean
cancelable, // boolean
view, // DOMWindow
detail, // long
screenX, screenY, // long
clientX, clientY, // long
ctrlKey, altKey, shiftKey, metaKey, // boolean
scale, // float
rotation // float
) {
var customEvent;
if(!Y.UA.ios || Y.UA.ios<2.0) {
Y.error("simulateGestureEvent(): Native gesture DOM eventframe is not available in this platform.");
}
// check taget
if (!target){
Y.error("simulateGestureEvent(): Invalid target.");
}
//check event type
if (Y.Lang.isString(type)) {
type = type.toLowerCase();
//make sure it's a supported touch event
if (!gestureEvents[type]){
Y.error("simulateTouchEvent(): Event type '" + type + "' not supported.");
}
} else {
Y.error("simulateGestureEvent(): Event type must be a string.");
}
// setup default values
if (!Y.Lang.isBoolean(bubbles)) { bubbles = true; } // bubble by default
if (!Y.Lang.isBoolean(cancelable)) { cancelable = true; }
if (!Y.Lang.isObject(view)) { view = Y.config.win; }
if (!Y.Lang.isNumber(detail)) { detail = 2; } // usually not used.
if (!Y.Lang.isNumber(screenX)) { screenX = 0; }
if (!Y.Lang.isNumber(screenY)) { screenY = 0; }
if (!Y.Lang.isNumber(clientX)) { clientX = 0; }
if (!Y.Lang.isNumber(clientY)) { clientY = 0; }
if (!Y.Lang.isBoolean(ctrlKey)) { ctrlKey = false; }
if (!Y.Lang.isBoolean(altKey)) { altKey = false; }
if (!Y.Lang.isBoolean(shiftKey)){ shiftKey = false; }
if (!Y.Lang.isBoolean(metaKey)) { metaKey = false; }
if (!Y.Lang.isNumber(scale)){ scale = 1.0; }
if (!Y.Lang.isNumber(rotation)){ rotation = 0.0; }
customEvent = Y.config.doc.createEvent("GestureEvent");
customEvent.initGestureEvent(type, bubbles, cancelable, view, detail,
screenX, screenY, clientX, clientY,
ctrlKey, altKey, shiftKey, metaKey,
target, scale, rotation);
target.dispatchEvent(customEvent);
}
/*
* @method simulateTouchEvent
* @private
* @param {HTMLElement} target The target of the given event.
* @param {String} type The type of event to fire. This can be any one of
* the following: touchstart, touchmove, touchend, touchcancel.
* @param {Boolean} bubbles (Optional) Indicates if the event can be
* bubbled up. DOM Level 2 specifies that all mouse events bubble by
* default. The default is true.
* @param {Boolean} cancelable (Optional) Indicates if the event can be
* canceled using preventDefault(). DOM Level 2 specifies that all
* touch events except touchcancel can be cancelled. The default
* is true for all events except touchcancel, for which the default
* is false.
* @param {Window} view (Optional) The view containing the target. This is
* typically the window object. The default is window.
* @param {int} detail (Optional) Specifies some detail information about
* the event depending on the type of event.
* @param {int} screenX (Optional) The x-coordinate on the screen at which
* point the event occured. The default is 0.
* @param {int} screenY (Optional) The y-coordinate on the screen at which
* point the event occured. The default is 0.
* @param {int} clientX (Optional) The x-coordinate on the client at which
* point the event occured. The default is 0.
* @param {int} clientY (Optional) The y-coordinate on the client at which
* point the event occured. The default is 0.
* @param {Boolean} ctrlKey (Optional) Indicates if one of the CTRL keys
* is pressed while the event is firing. The default is false.
* @param {Boolean} altKey (Optional) Indicates if one of the ALT keys
* is pressed while the event is firing. The default is false.
* @param {Boolean} shiftKey (Optional) Indicates if one of the SHIFT keys
* is pressed while the event is firing. The default is false.
* @param {Boolean} metaKey (Optional) Indicates if one of the META keys
* is pressed while the event is firing. The default is false.
* @param {TouchList} touches A collection of Touch objects representing
* all touches associated with this event.
* @param {TouchList} targetTouches A collection of Touch objects
* representing all touches associated with this target.
* @param {TouchList} changedTouches A collection of Touch objects
* representing all touches that changed in this event.
* @param {float} scale (iOS v2+ only) The distance between two fingers
* since the start of an event as a multiplier of the initial distance.
* The default value is 1.0.
* @param {float} rotation (iOS v2+ only) The delta rotation since the start
* of an event, in degrees, where clockwise is positive and
* counter-clockwise is negative. The default value is 0.0.
*/
function simulateTouchEvent(target, type,
bubbles, // boolean
cancelable, // boolean
view, // DOMWindow
detail, // long
screenX, screenY, // long
clientX, clientY, // long
ctrlKey, altKey, shiftKey, metaKey, // boolean
touches, // TouchList
targetTouches, // TouchList
changedTouches, // TouchList
scale, // float
rotation // float
) {
var customEvent;
// check taget
if (!target){
Y.error("simulateTouchEvent(): Invalid target.");
}
//check event type
if (Y.Lang.isString(type)) {
type = type.toLowerCase();
//make sure it's a supported touch event
if (!touchEvents[type]){
Y.error("simulateTouchEvent(): Event type '" + type + "' not supported.");
}
} else {
Y.error("simulateTouchEvent(): Event type must be a string.");
}
// note that the caller is responsible to pass appropriate touch objects.
// check touch objects
// Android(even 4.0) doesn't define TouchList yet
/*if(type === 'touchstart' || type === 'touchmove') {
if(!touches instanceof TouchList) {
Y.error('simulateTouchEvent(): Invalid touches. It must be a TouchList');
} else {
if(touches.length === 0) {
Y.error('simulateTouchEvent(): No touch object found.');
}
}
} else if(type === 'touchend') {
if(!changedTouches instanceof TouchList) {
Y.error('simulateTouchEvent(): Invalid touches. It must be a TouchList');
} else {
if(changedTouches.length === 0) {
Y.error('simulateTouchEvent(): No touch object found.');
}
}
}*/
if(type === 'touchstart' || type === 'touchmove') {
if(touches.length === 0) {
Y.error('simulateTouchEvent(): No touch object in touches');
}
} else if(type === 'touchend') {
if(changedTouches.length === 0) {
Y.error('simulateTouchEvent(): No touch object in changedTouches');
}
}
// setup default values
if (!Y.Lang.isBoolean(bubbles)) { bubbles = true; } // bubble by default.
if (!Y.Lang.isBoolean(cancelable)) {
cancelable = (type !== "touchcancel"); // touchcancel is not cancelled
}
if (!Y.Lang.isObject(view)) { view = Y.config.win; }
if (!Y.Lang.isNumber(detail)) { detail = 1; } // usually not used. defaulted to # of touch objects.
if (!Y.Lang.isNumber(screenX)) { screenX = 0; }
if (!Y.Lang.isNumber(screenY)) { screenY = 0; }
if (!Y.Lang.isNumber(clientX)) { clientX = 0; }
if (!Y.Lang.isNumber(clientY)) { clientY = 0; }
if (!Y.Lang.isBoolean(ctrlKey)) { ctrlKey = false; }
if (!Y.Lang.isBoolean(altKey)) { altKey = false; }
if (!Y.Lang.isBoolean(shiftKey)){ shiftKey = false; }
if (!Y.Lang.isBoolean(metaKey)) { metaKey = false; }
if (!Y.Lang.isNumber(scale)) { scale = 1.0; }
if (!Y.Lang.isNumber(rotation)) { rotation = 0.0; }
//check for DOM-compliant browsers first
if (Y.Lang.isFunction(Y.config.doc.createEvent)) {
if (Y.UA.android) {
/*
* Couldn't find android start version that supports touch event.
* Assumed supported(btw APIs broken till icecream sandwitch)
* from the beginning.
*/
if(Y.UA.android < 4.0) {
/*
* Touch APIs are broken in androids older than 4.0. We will use
* simulated touch apis for these versions.
* App developer still can listen for touch events. This events
* will be dispatched with touch event types.
*
* (Note) Used target for the relatedTarget. Need to verify if
* it has a side effect.
*/
customEvent = Y.config.doc.createEvent("MouseEvents");
customEvent.initMouseEvent(type, bubbles, cancelable, view, detail,
screenX, screenY, clientX, clientY,
ctrlKey, altKey, shiftKey, metaKey,
0, target);
customEvent.touches = touches;
customEvent.targetTouches = targetTouches;
customEvent.changedTouches = changedTouches;
} else {
customEvent = Y.config.doc.createEvent("TouchEvent");
// Andoroid isn't compliant W3C initTouchEvent method signature.
customEvent.initTouchEvent(touches, targetTouches, changedTouches,
type, view,
screenX, screenY, clientX, clientY,
ctrlKey, altKey, shiftKey, metaKey);
}
} else if (Y.UA.ios) {
if(Y.UA.ios >= 2.0) {
customEvent = Y.config.doc.createEvent("TouchEvent");
// Available iOS 2.0 and later
customEvent.initTouchEvent(type, bubbles, cancelable, view, detail,
screenX, screenY, clientX, clientY,
ctrlKey, altKey, shiftKey, metaKey,
touches, targetTouches, changedTouches,
scale, rotation);
} else {
Y.error('simulateTouchEvent(): No touch event simulation framework present for iOS, '+Y.UA.ios+'.');
}
} else {
Y.error('simulateTouchEvent(): Not supported agent yet, '+Y.UA.userAgent);
}
//fire the event
target.dispatchEvent(customEvent);
//} else if (Y.Lang.isObject(doc.createEventObject)){ // Windows Mobile/IE, support later
} else {
Y.error('simulateTouchEvent(): No event simulation framework present.');
}
}
/**
* Simulates the event or gesture with the given name on a target.
* @param {HTMLElement} target The DOM element that's the target of the event.
* @param {String} type The type of event or name of the supported gesture to simulate
* (i.e., "click", "doubletap", "flick").
* @param {Object} options (Optional) Extra options to copy onto the event object.
* For gestures, options are used to refine the gesture behavior.
* @return {void}
* @for Event
* @method simulate
* @static
*/
Y.Event.simulate = function(target, type, options){
options = options || {};
if (mouseEvents[type] || pointerEvents[type]){
simulateMouseEvent(target, type, options.bubbles,
options.cancelable, options.view, options.detail, options.screenX,
options.screenY, options.clientX, options.clientY, options.ctrlKey,
options.altKey, options.shiftKey, options.metaKey, options.button,
options.relatedTarget);
} else if (keyEvents[type]){
simulateKeyEvent(target, type, options.bubbles,
options.cancelable, options.view, options.ctrlKey,
options.altKey, options.shiftKey, options.metaKey,
options.keyCode, options.charCode);
} else if (uiEvents[type]){
simulateUIEvent(target, type, options.bubbles,
options.cancelable, options.view, options.detail);
// touch low-level event simulation
} else if (touchEvents[type]) {
if((Y.config.win && ("ontouchstart" in Y.config.win)) && !(Y.UA.phantomjs) && !(Y.UA.chrome && Y.UA.chrome < 6)) {
simulateTouchEvent(target, type,
options.bubbles, options.cancelable, options.view, options.detail,
options.screenX, options.screenY, options.clientX, options.clientY,
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey,
options.touches, options.targetTouches, options.changedTouches,
options.scale, options.rotation);
} else {
Y.error("simulate(): Event '" + type + "' can't be simulated. Use gesture-simulate module instead.");
}
// ios gesture low-level event simulation (iOS v2+ only)
} else if(Y.UA.ios && Y.UA.ios >= 2.0 && gestureEvents[type]) {
simulateGestureEvent(target, type,
options.bubbles, options.cancelable, options.view, options.detail,
options.screenX, options.screenY, options.clientX, options.clientY,
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey,
options.scale, options.rotation);
// anything else
} else {
Y.error("simulate(): Event '" + type + "' can't be simulated.");
}
};
})();
}, 'patched-v3.11.0', {"requires": ["event-base"]});
YUI.add('event-synthetic', function (Y, NAME) {
/**
* Define new DOM events that can be subscribed to from Nodes.
*
* @module event
* @submodule event-synthetic
*/
var CustomEvent = Y.CustomEvent,
DOMMap = Y.Env.evt.dom_map,
toArray = Y.Array,
YLang = Y.Lang,
isObject = YLang.isObject,
isString = YLang.isString,
isArray = YLang.isArray,
query = Y.Selector.query,
noop = function () {};
/**
* The triggering mechanism used by SyntheticEvents.
*
* Implementers should not instantiate these directly. Use the Notifier
* provided to the event's implemented on(node, sub, notifier)
or
* delegate(node, sub, notifier, filter)
methods.
*
* @class SyntheticEvent.Notifier
* @constructor
* @param handle {EventHandle} the detach handle for the subscription to an
* internal custom event used to execute the callback passed to
* on(..) or delegate(..)
* @param emitFacade {Boolean} take steps to ensure the first arg received by
* the subscription callback is an event facade
* @private
* @since 3.2.0
*/
function Notifier(handle, emitFacade) {
this.handle = handle;
this.emitFacade = emitFacade;
}
/**
* Executes the subscription callback, passing the firing arguments as the
* first parameters to that callback. For events that are configured with
* emitFacade=true, it is common practice to pass the triggering DOMEventFacade
* as the first parameter. Barring a proper DOMEventFacade or EventFacade
* (from a CustomEvent), a new EventFacade will be generated. In that case, if
* fire() is called with a simple object, it will be mixed into the facade.
* Otherwise, the facade will be prepended to the callback parameters.
*
* For notifiers provided to delegate logic, the first argument should be an
* object with a "currentTarget" property to identify what object to
* default as 'this' in the callback. Typically this is gleaned from the
* DOMEventFacade or EventFacade, but if configured with emitFacade=false, an
* object must be provided. In that case, the object will be removed from the
* callback parameters.
*
* Additional arguments passed during event subscription will be
* automatically added after those passed to fire().
*
* @method fire
* @param e {EventFacade|DOMEventFacade|Object|any} (see description)
* @param arg* {any} additional arguments received by all subscriptions
* @private
*/
Notifier.prototype.fire = function (e) {
// first arg to delegate notifier should be an object with currentTarget
var args = toArray(arguments, 0, true),
handle = this.handle,
ce = handle.evt,
sub = handle.sub,
thisObj = sub.context,
delegate = sub.filter,
event = e || {},
ret;
if (this.emitFacade) {
if (!e || !e.preventDefault) {
event = ce._getFacade();
if (isObject(e) && !e.preventDefault) {
Y.mix(event, e, true);
args[0] = event;
} else {
args.unshift(event);
}
}
event.type = ce.type;
event.details = args.slice();
if (delegate) {
event.container = ce.host;
}
} else if (delegate && isObject(e) && e.currentTarget) {
args.shift();
}
sub.context = thisObj || event.currentTarget || ce.host;
ret = ce.fire.apply(ce, args);
sub.context = thisObj; // reset for future firing
// to capture callbacks that return false to stopPropagation.
// Useful for delegate implementations
return ret;
};
/**
* Manager object for synthetic event subscriptions to aggregate multiple synths on the
* same node without colliding with actual DOM subscription entries in the global map of
* DOM subscriptions. Also facilitates proper cleanup on page unload.
*
* @class SynthRegistry
* @constructor
* @param el {HTMLElement} the DOM element
* @param yuid {String} the yuid stamp for the element
* @param key {String} the generated id token used to identify an event type +
* element in the global DOM subscription map.
* @private
*/
function SynthRegistry(el, yuid, key) {
this.handles = [];
this.el = el;
this.key = key;
this.domkey = yuid;
}
SynthRegistry.prototype = {
constructor: SynthRegistry,
// A few object properties to fake the CustomEvent interface for page
// unload cleanup. DON'T TOUCH!
type : '_synth',
fn : noop,
capture : false,
/**
* Adds a subscription from the Notifier registry.
*
* @method register
* @param handle {EventHandle} the subscription
* @since 3.4.0
*/
register: function (handle) {
handle.evt.registry = this;
this.handles.push(handle);
},
/**
* Removes the subscription from the Notifier registry.
*
* @method _unregisterSub
* @param sub {Subscription} the subscription
* @since 3.4.0
*/
unregister: function (sub) {
var handles = this.handles,
events = DOMMap[this.domkey],
i;
for (i = handles.length - 1; i >= 0; --i) {
if (handles[i].sub === sub) {
handles.splice(i, 1);
break;
}
}
// Clean up left over objects when there are no more subscribers.
if (!handles.length) {
delete events[this.key];
if (!Y.Object.size(events)) {
delete DOMMap[this.domkey];
}
}
},
/**
* Used by the event system's unload cleanup process. When navigating
* away from the page, the event system iterates the global map of element
* subscriptions and detaches everything using detachAll(). Normally,
* the map is populated with custom events, so this object needs to
* at least support the detachAll method to duck type its way to
* cleanliness.
*
* @method detachAll
* @private
* @since 3.4.0
*/
detachAll : function () {
var handles = this.handles,
i = handles.length;
while (--i >= 0) {
handles[i].detach();
}
}
};
/**
* Wrapper class for the integration of new events into the YUI event
* infrastructure. Don't instantiate this object directly, use
* Y.Event.define(type, config)
. See that method for details.
*
* Properties that MAY or SHOULD be specified in the configuration are noted
* below and in the description of Y.Event.define
.
*
* @class SyntheticEvent
* @constructor
* @param cfg {Object} Implementation pieces and configuration
* @since 3.1.0
* @in event-synthetic
*/
function SyntheticEvent() {
this._init.apply(this, arguments);
}
Y.mix(SyntheticEvent, {
Notifier: Notifier,
SynthRegistry: SynthRegistry,
/**
* Returns the array of subscription handles for a node for the given event
* type. Passing true as the third argument will create a registry entry
* in the event system's DOM map to host the array if one doesn't yet exist.
*
* @method getRegistry
* @param node {Node} the node
* @param type {String} the event
* @param create {Boolean} create a registration entry to host a new array
* if one doesn't exist.
* @return {Array}
* @static
* @protected
* @since 3.2.0
*/
getRegistry: function (node, type, create) {
var el = node._node,
yuid = Y.stamp(el),
key = 'event:' + yuid + type + '_synth',
events = DOMMap[yuid];
if (create) {
if (!events) {
events = DOMMap[yuid] = {};
}
if (!events[key]) {
events[key] = new SynthRegistry(el, yuid, key);
}
}
return (events && events[key]) || null;
},
/**
* Alternate _delete()
method for the CustomEvent object
* created to manage SyntheticEvent subscriptions.
*
* @method _deleteSub
* @param sub {Subscription} the subscription to clean up
* @private
* @since 3.2.0
*/
_deleteSub: function (sub) {
if (sub && sub.fn) {
var synth = this.eventDef,
method = (sub.filter) ? 'detachDelegate' : 'detach';
this._subscribers = [];
if (CustomEvent.keepDeprecatedSubs) {
this.subscribers = {};
}
synth[method](sub.node, sub, this.notifier, sub.filter);
this.registry.unregister(sub);
delete sub.fn;
delete sub.node;
delete sub.context;
}
},
prototype: {
constructor: SyntheticEvent,
/**
* Construction logic for the event.
*
* @method _init
* @protected
*/
_init: function () {
var config = this.publishConfig || (this.publishConfig = {});
// The notification mechanism handles facade creation
this.emitFacade = ('emitFacade' in config) ?
config.emitFacade :
true;
config.emitFacade = false;
},
/**
* Implementers MAY provide this method definition.
*
* Implement this function if the event supports a different
* subscription signature. This function is used by both
* on()
and delegate()
. The second parameter
* indicates that the event is being subscribed via
* delegate()
.
*
* Implementations must remove extra arguments from the args list
* before returning. The required args for on()
* subscriptions are
* [type, callback, target, context, argN...]
*
* The required args for delegate()
* subscriptions are
*
* [type, callback, target, filter, context, argN...]
*
* The return value from this function will be stored on the
* subscription in the '_extra' property for reference elsewhere.
*
* @method processArgs
* @param args {Array} parmeters passed to Y.on(..) or Y.delegate(..)
* @param delegate {Boolean} true if the subscription is from Y.delegate
* @return {any}
*/
processArgs: noop,
/**
* Implementers MAY override this property.
*
* Whether to prevent multiple subscriptions to this event that are
* classified as being the same. By default, this means the subscribed
* callback is the same function. See the subMatch
* method. Setting this to true will impact performance for high volume
* events.
*
* @property preventDups
* @type {Boolean}
* @default false
*/
//preventDups : false,
/**
* Implementers SHOULD provide this method definition.
*
* Implementation logic for subscriptions done via node.on(type,
* fn)
or Y.on(type, fn, target)
. This
* function should set up the monitor(s) that will eventually fire the
* event. Typically this involves subscribing to at least one DOM
* event. It is recommended to store detach handles from any DOM
* subscriptions to make for easy cleanup in the detach
* method. Typically these handles are added to the sub
* object. Also for SyntheticEvents that leverage a single DOM
* subscription under the hood, it is recommended to pass the DOM event
* object to notifier.fire(e)
. (The event name on the
* object will be updated).
*
* @method on
* @param node {Node} the node the subscription is being applied to
* @param sub {Subscription} the object to track this subscription
* @param notifier {SyntheticEvent.Notifier} call notifier.fire(..) to
* trigger the execution of the subscribers
*/
on: noop,
/**
* Implementers SHOULD provide this method definition.
*
* Implementation logic for detaching subscriptions done via
* node.on(type, fn)
. This function should clean up any
* subscriptions made in the on()
phase.
*
* @method detach
* @param node {Node} the node the subscription was applied to
* @param sub {Subscription} the object tracking this subscription
* @param notifier {SyntheticEvent.Notifier} the Notifier used to
* trigger the execution of the subscribers
*/
detach: noop,
/**
* Implementers SHOULD provide this method definition.
*
* Implementation logic for subscriptions done via
* node.delegate(type, fn, filter)
or
* Y.delegate(type, fn, container, filter)
. Like with
* on()
above, this function should monitor the environment
* for the event being fired, and trigger subscription execution by
* calling notifier.fire(e)
.
*
* This function receives a fourth argument, which is the filter
* used to identify which Node's are of interest to the subscription.
* The filter will be either a boolean function that accepts a target
* Node for each hierarchy level as the event bubbles, or a selector
* string. To translate selector strings into filter functions, use
* Y.delegate.compileFilter(filter)
.
*
* @method delegate
* @param node {Node} the node the subscription is being applied to
* @param sub {Subscription} the object to track this subscription
* @param notifier {SyntheticEvent.Notifier} call notifier.fire(..) to
* trigger the execution of the subscribers
* @param filter {String|Function} Selector string or function that
* accepts an event object and returns null, a Node, or an
* array of Nodes matching the criteria for processing.
* @since 3.2.0
*/
delegate : noop,
/**
* Implementers SHOULD provide this method definition.
*
* Implementation logic for detaching subscriptions done via
* node.delegate(type, fn, filter)
or
* Y.delegate(type, fn, container, filter)
. This function
* should clean up any subscriptions made in the
* delegate()
phase.
*
* @method detachDelegate
* @param node {Node} the node the subscription was applied to
* @param sub {Subscription} the object tracking this subscription
* @param notifier {SyntheticEvent.Notifier} the Notifier used to
* trigger the execution of the subscribers
* @param filter {String|Function} Selector string or function that
* accepts an event object and returns null, a Node, or an
* array of Nodes matching the criteria for processing.
* @since 3.2.0
*/
detachDelegate : noop,
/**
* Sets up the boilerplate for detaching the event and facilitating the
* execution of subscriber callbacks.
*
* @method _on
* @param args {Array} array of arguments passed to
* Y.on(...)
or Y.delegate(...)
* @param delegate {Boolean} true if called from
* Y.delegate(...)
* @return {EventHandle} the detach handle for this subscription
* @private
* since 3.2.0
*/
_on: function (args, delegate) {
var handles = [],
originalArgs = args.slice(),
extra = this.processArgs(args, delegate),
selector = args[2],
method = delegate ? 'delegate' : 'on',
nodes, handle;
// Can't just use Y.all because it doesn't support window (yet?)
nodes = (isString(selector)) ?
query(selector) :
toArray(selector || Y.one(Y.config.win));
if (!nodes.length && isString(selector)) {
handle = Y.on('available', function () {
Y.mix(handle, Y[method].apply(Y, originalArgs), true);
}, selector);
return handle;
}
Y.Array.each(nodes, function (node) {
var subArgs = args.slice(),
filter;
node = Y.one(node);
if (node) {
if (delegate) {
filter = subArgs.splice(3, 1)[0];
}
// (type, fn, el, thisObj, ...) => (fn, thisObj, ...)
subArgs.splice(0, 4, subArgs[1], subArgs[3]);
if (!this.preventDups ||
!this.getSubs(node, args, null, true))
{
handles.push(this._subscribe(node, method, subArgs, extra, filter));
}
}
}, this);
return (handles.length === 1) ?
handles[0] :
new Y.EventHandle(handles);
},
/**
* Creates a new Notifier object for use by this event's
* on(...)
or delegate(...)
implementation
* and register the custom event proxy in the DOM system for cleanup.
*
* @method _subscribe
* @param node {Node} the Node hosting the event
* @param method {String} "on" or "delegate"
* @param args {Array} the subscription arguments passed to either
* Y.on(...)
or Y.delegate(...)
* after running through processArgs(args)
to
* normalize the argument signature
* @param extra {any} Extra data parsed from
* processArgs(args)
* @param filter {String|Function} the selector string or function
* filter passed to Y.delegate(...)
(not
* present when called from Y.on(...)
)
* @return {EventHandle}
* @private
* @since 3.2.0
*/
_subscribe: function (node, method, args, extra, filter) {
var dispatcher = new Y.CustomEvent(this.type, this.publishConfig),
handle = dispatcher.on.apply(dispatcher, args),
notifier = new Notifier(handle, this.emitFacade),
registry = SyntheticEvent.getRegistry(node, this.type, true),
sub = handle.sub;
sub.node = node;
sub.filter = filter;
if (extra) {
this.applyArgExtras(extra, sub);
}
Y.mix(dispatcher, {
eventDef : this,
notifier : notifier,
host : node, // I forget what this is for
currentTarget: node, // for generating facades
target : node, // for generating facades
el : node._node, // For category detach
_delete : SyntheticEvent._deleteSub
}, true);
handle.notifier = notifier;
registry.register(handle);
// Call the implementation's "on" or "delegate" method
this[method](node, sub, notifier, filter);
return handle;
},
/**
* Implementers MAY provide this method definition.
*
* Implement this function if you want extra data extracted during
* processArgs to be propagated to subscriptions on a per-node basis.
* That is to say, if you call Y.on('xyz', fn, xtra, 'div')
* the data returned from processArgs will be shared
* across the subscription objects for all the divs. If you want each
* subscription to receive unique information, do that processing
* here.
*
* The default implementation adds the data extracted by processArgs
* to the subscription object as sub._extra
.
*
* @method applyArgExtras
* @param extra {any} Any extra data extracted from processArgs
* @param sub {Subscription} the individual subscription
*/
applyArgExtras: function (extra, sub) {
sub._extra = extra;
},
/**
* Removes the subscription(s) from the internal subscription dispatch
* mechanism. See SyntheticEvent._deleteSub
.
*
* @method _detach
* @param args {Array} The arguments passed to
* node.detach(...)
* @private
* @since 3.2.0
*/
_detach: function (args) {
// Can't use Y.all because it doesn't support window (yet?)
// TODO: Does Y.all support window now?
var target = args[2],
els = (isString(target)) ?
query(target) : toArray(target),
node, i, len, handles, j;
// (type, fn, el, context, filter?) => (type, fn, context, filter?)
args.splice(2, 1);
for (i = 0, len = els.length; i < len; ++i) {
node = Y.one(els[i]);
if (node) {
handles = this.getSubs(node, args);
if (handles) {
for (j = handles.length - 1; j >= 0; --j) {
handles[j].detach();
}
}
}
}
},
/**
* Returns the detach handles of subscriptions on a node that satisfy a
* search/filter function. By default, the filter used is the
* subMatch
method.
*
* @method getSubs
* @param node {Node} the node hosting the event
* @param args {Array} the array of original subscription args passed
* to Y.on(...)
(before
* processArgs
* @param filter {Function} function used to identify a subscription
* for inclusion in the returned array
* @param first {Boolean} stop after the first match (used to check for
* duplicate subscriptions)
* @return {EventHandle[]} detach handles for the matching subscriptions
*/
getSubs: function (node, args, filter, first) {
var registry = SyntheticEvent.getRegistry(node, this.type),
handles = [],
allHandles, i, len, handle;
if (registry) {
allHandles = registry.handles;
if (!filter) {
filter = this.subMatch;
}
for (i = 0, len = allHandles.length; i < len; ++i) {
handle = allHandles[i];
if (filter.call(this, handle.sub, args)) {
if (first) {
return handle;
} else {
handles.push(allHandles[i]);
}
}
}
}
return handles.length && handles;
},
/**
* Implementers MAY override this to define what constitutes a
* "same" subscription. Override implementations should
* consider the lack of a comparator as a match, so calling
* getSubs()
with no arguments will return all subs.
*
* Compares a set of subscription arguments against a Subscription
* object to determine if they match. The default implementation
* compares the callback function against the second argument passed to
* Y.on(...)
or node.detach(...)
etc.
*
* @method subMatch
* @param sub {Subscription} the existing subscription
* @param args {Array} the calling arguments passed to
* Y.on(...)
etc.
* @return {Boolean} true if the sub can be described by the args
* present
* @since 3.2.0
*/
subMatch: function (sub, args) {
// Default detach cares only about the callback matching
return !args[1] || sub.fn === args[1];
}
}
}, true);
Y.SyntheticEvent = SyntheticEvent;
/**
* Defines a new event in the DOM event system. Implementers are
* responsible for monitoring for a scenario whereby the event is fired. A
* notifier object is provided to the functions identified below. When the
* criteria defining the event are met, call notifier.fire( [args] ); to
* execute event subscribers.
*
* The first parameter is the name of the event. The second parameter is a
* configuration object which define the behavior of the event system when the
* new event is subscribed to or detached from. The methods that should be
* defined in this configuration object are on
,
* detach
, delegate
, and detachDelegate
.
* You are free to define any other methods or properties needed to define your
* event. Be aware, however, that since the object is used to subclass
* SyntheticEvent, you should avoid method names used by SyntheticEvent unless
* your intention is to override the default behavior.
*
* This is a list of properties and methods that you can or should specify
* in the configuration object:
*
*
* on
* function (node, subscription, notifier)
The
* implementation logic for subscription. Any special setup you need to
* do to create the environment for the event being fired--E.g. native
* DOM event subscriptions. Store subscription related objects and
* state on the subscription
object. When the
* criteria have been met to fire the synthetic event, call
* notifier.fire(e)
. See Notifier's fire()
* method for details about what to pass as parameters.
*
* detach
* function (node, subscription, notifier)
The
* implementation logic for cleaning up a detached subscription. E.g.
* detach any DOM subscriptions added in on
.
*
* delegate
* function (node, subscription, notifier, filter)
The
* implementation logic for subscription via Y.delegate
or
* node.delegate
. The filter is typically either a selector
* string or a function. You can use
* Y.delegate.compileFilter(selectorString)
to create a
* filter function from a selector string if needed. The filter function
* expects an event object as input and should output either null, a
* matching Node, or an array of matching Nodes. Otherwise, this acts
* like on
DOM event subscriptions. Store subscription
* related objects and information on the subscription
* object. When the criteria have been met to fire the synthetic event,
* call notifier.fire(e)
as noted above.
*
* detachDelegate
* function (node, subscription, notifier)
The
* implementation logic for cleaning up a detached delegate subscription.
* E.g. detach any DOM delegate subscriptions added in
* delegate
.
*
* publishConfig
* (Object) The configuration object that will be used to instantiate
* the underlying CustomEvent. See Notifier's fire
method
* for details.
*
* processArgs
* function (argArray, fromDelegate)
Optional method
* to extract any additional arguments from the subscription
* signature. Using this allows on
or
* delegate
signatures like
* node.on("hover", overCallback,
* outCallback)
.
* When processing an atypical argument signature, make sure the
* args array is returned to the normal signature before returning
* from the function. For example, in the "hover" example
* above, the outCallback
needs to be splice
d
* out of the array. The expected signature of the args array for
* on()
subscriptions is:
*
* [type, callback, target, contextOverride, argN...]
*
* And for delegate()
:
*
* [type, callback, target, filter, contextOverride, argN...]
*
* where target
is the node the event is being
* subscribed for. You can see these signatures documented for
* Y.on()
and Y.delegate()
respectively.
* Whatever gets returned from the function will be stored on the
* subscription
object under
* subscription._extra
.
* subMatch
*
* function (sub, args)
Compares a set of
* subscription arguments against a Subscription object to determine
* if they match. The default implementation compares the callback
* function against the second argument passed to
* Y.on(...)
or node.detach(...)
etc.
*
*
*
* @method define
* @param type {String} the name of the event
* @param config {Object} the prototype definition for the new event (see above)
* @param force {Boolean} override an existing event (use with caution)
* @return {SyntheticEvent} the subclass implementation instance created to
* handle event subscriptions of this type
* @static
* @for Event
* @since 3.1.0
* @in event-synthetic
*/
Y.Event.define = function (type, config, force) {
var eventDef, Impl, synth;
if (type && type.type) {
eventDef = type;
force = config;
} else if (config) {
eventDef = Y.merge({ type: type }, config);
}
if (eventDef) {
if (force || !Y.Node.DOM_EVENTS[eventDef.type]) {
Impl = function () {
SyntheticEvent.apply(this, arguments);
};
Y.extend(Impl, SyntheticEvent, eventDef);
synth = new Impl();
type = synth.type;
Y.Node.DOM_EVENTS[type] = Y.Env.evt.plugins[type] = {
eventDef: synth,
on: function () {
return synth._on(toArray(arguments));
},
delegate: function () {
return synth._on(toArray(arguments), true);
},
detach: function () {
return synth._detach(toArray(arguments));
}
};
}
} else if (isString(type) || isArray(type)) {
Y.Array.each(toArray(type), function (t) {
Y.Node.DOM_EVENTS[t] = 1;
});
}
return synth;
};
}, 'patched-v3.11.0', {"requires": ["node-base", "event-custom-complex"]});
YUI.add('intl', function (Y, NAME) {
var _mods = {},
ROOT_LANG = "yuiRootLang",
ACTIVE_LANG = "yuiActiveLang",
NONE = [];
/**
* Provides utilities to support the management of localized resources (strings and formatting patterns).
*
* @module intl
*/
/**
* The Intl utility provides a central location for managing sets of localized resources (strings and formatting patterns).
*
* @class Intl
* @uses EventTarget
* @static
*/
Y.mix(Y.namespace("Intl"), {
/**
* Private method to retrieve the language hash for a given module.
*
* @method _mod
* @private
*
* @param {String} module The name of the module
* @return {Object} The hash of localized resources for the module, keyed by BCP language tag
*/
_mod : function(module) {
if (!_mods[module]) {
_mods[module] = {};
}
return _mods[module];
},
/**
* Sets the active language for the given module.
*
* Returns false on failure, which would happen if the language had not been registered through the add() method.
*
* @method setLang
*
* @param {String} module The module name.
* @param {String} lang The BCP 47 language tag.
* @return boolean true if successful, false if not.
*/
setLang : function(module, lang) {
var langs = this._mod(module),
currLang = langs[ACTIVE_LANG],
exists = !!langs[lang];
if (exists && lang !== currLang) {
langs[ACTIVE_LANG] = lang;
this.fire("intl:langChange", {module: module, prevVal: currLang, newVal: (lang === ROOT_LANG) ? "" : lang});
}
return exists;
},
/**
* Get the currently active language for the given module.
*
* @method getLang
*
* @param {String} module The module name.
* @return {String} The BCP 47 language tag.
*/
getLang : function(module) {
var lang = this._mod(module)[ACTIVE_LANG];
return (lang === ROOT_LANG) ? "" : lang;
},
/**
* Register a hash of localized resources for the given module and language
*
* @method add
*
* @param {String} module The module name.
* @param {String} lang The BCP 47 language tag.
* @param {Object} strings The hash of localized values, keyed by the string name.
*/
add : function(module, lang, strings) {
lang = lang || ROOT_LANG;
this._mod(module)[lang] = strings;
this.setLang(module, lang);
},
/**
* Gets the module's localized resources for the currently active language (as provided by the getLang method).
*
* Optionally, the localized resources for alternate languages which have been added to Intl (see the add method) can
* be retrieved by providing the BCP 47 language tag as the lang parameter.
*
* @method get
*
* @param {String} module The module name.
* @param {String} key Optional. A single resource key. If not provided, returns a copy (shallow clone) of all resources.
* @param {String} lang Optional. The BCP 47 language tag. If not provided, the module's currently active language is used.
* @return String | Object A copy of the module's localized resources, or a single value if key is provided.
*/
get : function(module, key, lang) {
var mod = this._mod(module),
strs;
lang = lang || mod[ACTIVE_LANG];
strs = mod[lang] || {};
return (key) ? strs[key] : Y.merge(strs);
},
/**
* Gets the list of languages for which localized resources are available for a given module, based on the module
* meta-data (part of loader). If loader is not on the page, returns an empty array.
*
* @method getAvailableLangs
* @param {String} module The name of the module
* @return {Array} The array of languages available.
*/
getAvailableLangs : function(module) {
var loader = Y.Env._loader,
mod = loader && loader.moduleInfo[module],
langs = mod && mod.lang;
return (langs) ? langs.concat() : NONE;
}
});
Y.augment(Y.Intl, Y.EventTarget);
/**
* Notification event to indicate when the lang for a module has changed. There is no default behavior associated with this event,
* so the on and after moments are equivalent.
*
* @event intl:langChange
* @param {EventFacade} e The event facade
* The event facade contains:
*
* module The name of the module for which the language changed
* newVal The new language tag
* prevVal The current language tag
*
*/
Y.Intl.publish("intl:langChange", {emitFacade:true});
}, 'patched-v3.11.0', {"requires": ["intl-base", "event-custom"]});
YUI.add('io-base', function (Y, NAME) {
/**
Base IO functionality. Provides basic XHR transport support.
@module io
@submodule io-base
@for IO
**/
var // List of events that comprise the IO event lifecycle.
EVENTS = ['start', 'complete', 'end', 'success', 'failure', 'progress'],
// Whitelist of used XHR response object properties.
XHR_PROPS = ['status', 'statusText', 'responseText', 'responseXML'],
win = Y.config.win,
uid = 0;
/**
The IO class is a utility that brokers HTTP requests through a simplified
interface. Specifically, it allows JavaScript to make HTTP requests to
a resource without a page reload. The underlying transport for making
same-domain requests is the XMLHttpRequest object. IO can also use
Flash, if specified as a transport, for cross-domain requests.
@class IO
@constructor
@param {Object} config Object of EventTarget's publish method configurations
used to configure IO's events.
**/
function IO (config) {
var io = this;
io._uid = 'io:' + uid++;
io._init(config);
Y.io._map[io._uid] = io;
}
IO.prototype = {
//--------------------------------------
// Properties
//--------------------------------------
/**
* A counter that increments for each transaction.
*
* @property _id
* @private
* @type {Number}
*/
_id: 0,
/**
* Object of IO HTTP headers sent with each transaction.
*
* @property _headers
* @private
* @type {Object}
*/
_headers: {
'X-Requested-With' : 'XMLHttpRequest'
},
/**
* Object that stores timeout values for any transaction with a defined
* "timeout" configuration property.
*
* @property _timeout
* @private
* @type {Object}
*/
_timeout: {},
//--------------------------------------
// Methods
//--------------------------------------
_init: function(config) {
var io = this, i, len;
io.cfg = config || {};
Y.augment(io, Y.EventTarget);
for (i = 0, len = EVENTS.length; i < len; ++i) {
// Publish IO global events with configurations, if any.
// IO global events are set to broadcast by default.
// These events use the "io:" namespace.
io.publish('io:' + EVENTS[i], Y.merge({ broadcast: 1 }, config));
// Publish IO transaction events with configurations, if
// any. These events use the "io-trn:" namespace.
io.publish('io-trn:' + EVENTS[i], config);
}
},
/**
* Method that creates a unique transaction object for each request.
*
* @method _create
* @private
* @param {Object} cfg Configuration object subset to determine if
* the transaction is an XDR or file upload,
* requiring an alternate transport.
* @param {Number} id Transaction id
* @return {Object} The transaction object
*/
_create: function(config, id) {
var io = this,
transaction = {
id : Y.Lang.isNumber(id) ? id : io._id++,
uid: io._uid
},
alt = config.xdr ? config.xdr.use : null,
form = config.form && config.form.upload ? 'iframe' : null,
use;
if (alt === 'native') {
// Non-IE and IE >= 10 can use XHR level 2 and not rely on an
// external transport.
alt = Y.UA.ie && !SUPPORTS_CORS ? 'xdr' : null;
// Prevent "pre-flight" OPTIONS request by removing the
// `X-Requested-With` HTTP header from CORS requests. This header
// can be added back on a per-request basis, if desired.
io.setHeader('X-Requested-With');
}
use = alt || form;
transaction = use ? Y.merge(Y.IO.customTransport(use), transaction) :
Y.merge(Y.IO.defaultTransport(), transaction);
if (transaction.notify) {
config.notify = function (e, t, c) { io.notify(e, t, c); };
}
if (!use) {
if (win && win.FormData && config.data instanceof win.FormData) {
transaction.c.upload.onprogress = function (e) {
io.progress(transaction, e, config);
};
transaction.c.onload = function (e) {
io.load(transaction, e, config);
};
transaction.c.onerror = function (e) {
io.error(transaction, e, config);
};
transaction.upload = true;
}
}
return transaction;
},
_destroy: function(transaction) {
if (win && !transaction.notify && !transaction.xdr) {
if (XHR && !transaction.upload) {
transaction.c.onreadystatechange = null;
} else if (transaction.upload) {
transaction.c.upload.onprogress = null;
transaction.c.onload = null;
transaction.c.onerror = null;
} else if (Y.UA.ie && !transaction.e) {
// IE, when using XMLHttpRequest as an ActiveX Object, will throw
// a "Type Mismatch" error if the event handler is set to "null".
transaction.c.abort();
}
}
transaction = transaction.c = null;
},
/**
* Method for creating and firing events.
*
* @method _evt
* @private
* @param {String} eventName Event to be published.
* @param {Object} transaction Transaction object.
* @param {Object} config Configuration data subset for event subscription.
*/
_evt: function(eventName, transaction, config) {
var io = this, params,
args = config['arguments'],
emitFacade = io.cfg.emitFacade,
globalEvent = "io:" + eventName,
trnEvent = "io-trn:" + eventName;
// Workaround for #2532107
this.detach(trnEvent);
if (transaction.e) {
transaction.c = { status: 0, statusText: transaction.e };
}
// Fire event with parameters or an Event Facade.
params = [ emitFacade ?
{
id: transaction.id,
data: transaction.c,
cfg: config,
'arguments': args
} :
transaction.id
];
if (!emitFacade) {
if (eventName === EVENTS[0] || eventName === EVENTS[2]) {
if (args) {
params.push(args);
}
} else {
if (transaction.evt) {
params.push(transaction.evt);
} else {
params.push(transaction.c);
}
if (args) {
params.push(args);
}
}
}
params.unshift(globalEvent);
// Fire global events.
io.fire.apply(io, params);
// Fire transaction events, if receivers are defined.
if (config.on) {
params[0] = trnEvent;
io.once(trnEvent, config.on[eventName], config.context || Y);
io.fire.apply(io, params);
}
},
/**
* Fires event "io:start" and creates, fires a transaction-specific
* start event, if `config.on.start` is defined.
*
* @method start
* @param {Object} transaction Transaction object.
* @param {Object} config Configuration object for the transaction.
*/
start: function(transaction, config) {
/**
* Signals the start of an IO request.
* @event io:start
*/
this._evt(EVENTS[0], transaction, config);
},
/**
* Fires event "io:complete" and creates, fires a
* transaction-specific "complete" event, if config.on.complete is
* defined.
*
* @method complete
* @param {Object} transaction Transaction object.
* @param {Object} config Configuration object for the transaction.
*/
complete: function(transaction, config) {
/**
* Signals the completion of the request-response phase of a
* transaction. Response status and data are accessible, if
* available, in this event.
* @event io:complete
*/
this._evt(EVENTS[1], transaction, config);
},
/**
* Fires event "io:end" and creates, fires a transaction-specific "end"
* event, if config.on.end is defined.
*
* @method end
* @param {Object} transaction Transaction object.
* @param {Object} config Configuration object for the transaction.
*/
end: function(transaction, config) {
/**
* Signals the end of the transaction lifecycle.
* @event io:end
*/
this._evt(EVENTS[2], transaction, config);
this._destroy(transaction);
},
/**
* Fires event "io:success" and creates, fires a transaction-specific
* "success" event, if config.on.success is defined.
*
* @method success
* @param {Object} transaction Transaction object.
* @param {Object} config Configuration object for the transaction.
*/
success: function(transaction, config) {
/**
* Signals an HTTP response with status in the 2xx range.
* Fires after io:complete.
* @event io:success
*/
this._evt(EVENTS[3], transaction, config);
this.end(transaction, config);
},
/**
* Fires event "io:failure" and creates, fires a transaction-specific
* "failure" event, if config.on.failure is defined.
*
* @method failure
* @param {Object} transaction Transaction object.
* @param {Object} config Configuration object for the transaction.
*/
failure: function(transaction, config) {
/**
* Signals an HTTP response with status outside of the 2xx range.
* Fires after io:complete.
* @event io:failure
*/
this._evt(EVENTS[4], transaction, config);
this.end(transaction, config);
},
/**
* Fires event "io:progress" and creates, fires a transaction-specific
* "progress" event -- for XMLHttpRequest file upload -- if
* config.on.progress is defined.
*
* @method progress
* @param {Object} transaction Transaction object.
* @param {Object} progress event.
* @param {Object} config Configuration object for the transaction.
*/
progress: function(transaction, e, config) {
/**
* Signals the interactive state during a file upload transaction.
* This event fires after io:start and before io:complete.
* @event io:progress
*/
transaction.evt = e;
this._evt(EVENTS[5], transaction, config);
},
/**
* Fires event "io:complete" and creates, fires a transaction-specific
* "complete" event -- for XMLHttpRequest file upload -- if
* config.on.complete is defined.
*
* @method load
* @param {Object} transaction Transaction object.
* @param {Object} load event.
* @param {Object} config Configuration object for the transaction.
*/
load: function (transaction, e, config) {
transaction.evt = e.target;
this._evt(EVENTS[1], transaction, config);
},
/**
* Fires event "io:failure" and creates, fires a transaction-specific
* "failure" event -- for XMLHttpRequest file upload -- if
* config.on.failure is defined.
*
* @method error
* @param {Object} transaction Transaction object.
* @param {Object} error event.
* @param {Object} config Configuration object for the transaction.
*/
error: function (transaction, e, config) {
transaction.evt = e;
this._evt(EVENTS[4], transaction, config);
},
/**
* Retry an XDR transaction, using the Flash tranport, if the native
* transport fails.
*
* @method _retry
* @private
* @param {Object} transaction Transaction object.
* @param {String} uri Qualified path to transaction resource.
* @param {Object} config Configuration object for the transaction.
*/
_retry: function(transaction, uri, config) {
this._destroy(transaction);
config.xdr.use = 'flash';
return this.send(uri, config, transaction.id);
},
/**
* Method that concatenates string data for HTTP GET transactions.
*
* @method _concat
* @private
* @param {String} uri URI or root data.
* @param {String} data Data to be concatenated onto URI.
* @return {String}
*/
_concat: function(uri, data) {
var fragment = '',
split;
if (uri.indexOf('#') !== -1) {
split = uri.split('#');
uri = split[0];
fragment = '#' + split[1];
}
uri += (uri.indexOf('?') === -1 ? '?' : '&') + data;
return uri + fragment;
},
/**
* Stores default client headers for all transactions. If a label is
* passed with no value argument, the header will be deleted.
*
* @method setHeader
* @param {String} name HTTP header
* @param {String} value HTTP header value
*/
setHeader: function(name, value) {
if (value) {
this._headers[name] = value;
} else {
delete this._headers[name];
}
},
/**
* Method that sets all HTTP headers to be sent in a transaction.
*
* @method _setHeaders
* @private
* @param {Object} transaction - XHR instance for the specific transaction.
* @param {Object} headers - HTTP headers for the specific transaction, as
* defined in the configuration object passed to YUI.io().
*/
_setHeaders: function(transaction, headers) {
headers = Y.merge(this._headers, headers);
Y.Object.each(headers, function(value, name) {
if (value !== 'disable') {
transaction.setRequestHeader(name, headers[name]);
}
});
},
/**
* Starts timeout count if the configuration object has a defined
* timeout property.
*
* @method _startTimeout
* @private
* @param {Object} transaction Transaction object generated by _create().
* @param {Object} timeout Timeout in milliseconds.
*/
_startTimeout: function(transaction, timeout) {
var io = this;
io._timeout[transaction.id] = setTimeout(function() {
io._abort(transaction, 'timeout');
}, timeout);
},
/**
* Clears the timeout interval started by _startTimeout().
*
* @method _clearTimeout
* @private
* @param {Number} id - Transaction id.
*/
_clearTimeout: function(id) {
clearTimeout(this._timeout[id]);
delete this._timeout[id];
},
/**
* Method that determines if a transaction response qualifies as success
* or failure, based on the response HTTP status code, and fires the
* appropriate success or failure events.
*
* @method _result
* @private
* @static
* @param {Object} transaction Transaction object generated by _create().
* @param {Object} config Configuration object passed to io().
*/
_result: function(transaction, config) {
var status;
// Firefox will throw an exception if attempting to access
// an XHR object's status property, after a request is aborted.
try {
status = transaction.c.status;
} catch(e) {
status = 0;
}
// IE reports HTTP 204 as HTTP 1223.
if (status >= 200 && status < 300 || status === 304 || status === 1223) {
this.success(transaction, config);
} else {
this.failure(transaction, config);
}
},
/**
* Event handler bound to onreadystatechange.
*
* @method _rS
* @private
* @param {Object} transaction Transaction object generated by _create().
* @param {Object} config Configuration object passed to YUI.io().
*/
_rS: function(transaction, config) {
var io = this;
if (transaction.c.readyState === 4) {
if (config.timeout) {
io._clearTimeout(transaction.id);
}
// Yield in the event of request timeout or abort.
setTimeout(function() {
io.complete(transaction, config);
io._result(transaction, config);
}, 0);
}
},
/**
* Terminates a transaction due to an explicit abort or timeout.
*
* @method _abort
* @private
* @param {Object} transaction Transaction object generated by _create().
* @param {String} type Identifies timed out or aborted transaction.
*/
_abort: function(transaction, type) {
if (transaction && transaction.c) {
transaction.e = type;
transaction.c.abort();
}
},
/**
* Requests a transaction. `send()` is implemented as `Y.io()`. Each
* transaction may include a configuration object. Its properties are:
*
*
* method
* HTTP method verb (e.g., GET or POST). If this property is not
* not defined, the default value will be GET.
*
* data
* This is the name-value string that will be sent as the
* transaction data. If the request is HTTP GET, the data become
* part of querystring. If HTTP POST, the data are sent in the
* message body.
*
* xdr
* Defines the transport to be used for cross-domain requests.
* By setting this property, the transaction will use the specified
* transport instead of XMLHttpRequest. The properties of the
* transport object are:
*
* use
* The transport to be used: 'flash' or 'native'
* dataType
* Set the value to 'XML' if that is the expected response
* content type.
* credentials
* Set the value to 'true' to set XHR.withCredentials property to true.
*
*
* form
* Form serialization configuration object. Its properties are:
*
* id
* Node object or id of HTML form
* useDisabled
* `true` to also serialize disabled form field values
* (defaults to `false`)
*
*
* on
* Assigns transaction event subscriptions. Available events are:
*
* start
* Fires when a request is sent to a resource.
* complete
* Fires when the transaction is complete.
* success
* Fires when the HTTP response status is within the 2xx
* range.
* failure
* Fires when the HTTP response status is outside the 2xx
* range, if an exception occurs, if the transation is aborted,
* or if the transaction exceeds a configured `timeout`.
* end
* Fires at the conclusion of the transaction
* lifecycle, after `success` or `failure`.
*
*
* Callback functions for `start` and `end` receive the id of the
* transaction as a first argument. For `complete`, `success`, and
* `failure`, callbacks receive the id and the response object
* (usually the XMLHttpRequest instance). If the `arguments`
* property was included in the configuration object passed to
* `Y.io()`, the configured data will be passed to all callbacks as
* the last argument.
*
*
* sync
* Pass `true` to make a same-domain transaction synchronous.
* CAVEAT : This will negatively impact the user
* experience. Have a very good reason if you intend to use
* this.
*
* context
* The "`this'" object for all configured event handlers. If a
* specific context is needed for individual callbacks, bind the
* callback to a context using `Y.bind()`.
*
* headers
* Object map of transaction headers to send to the server. The
* object keys are the header names and the values are the header
* values.
*
* timeout
* Millisecond threshold for the transaction before being
* automatically aborted.
*
* arguments
* User-defined data passed to all registered event handlers.
* This value is available as the second argument in the "start" and
* "end" event handlers. It is the third argument in the "complete",
* "success", and "failure" event handlers. Be sure to quote
* this property name in the transaction configuration as
* "arguments" is a reserved word in JavaScript (e.g.
* `Y.io({ ..., "arguments": stuff })`).
*
*
* @method send
* @public
* @param {String} uri Qualified path to transaction resource.
* @param {Object} config Configuration object for the transaction.
* @param {Number} id Transaction id, if already set.
* @return {Object}
*/
send: function(uri, config, id) {
var transaction, method, i, len, sync, data,
io = this,
u = uri,
response = {};
config = config ? Y.Object(config) : {};
transaction = io._create(config, id);
method = config.method ? config.method.toUpperCase() : 'GET';
sync = config.sync;
data = config.data;
// Serialize a map object into a key-value string using
// querystring-stringify-simple.
if ((Y.Lang.isObject(data) && !data.nodeType) && !transaction.upload) {
if (Y.QueryString && Y.QueryString.stringify) {
config.data = data = Y.QueryString.stringify(data);
} else {
}
}
if (config.form) {
if (config.form.upload) {
// This is a file upload transaction, calling
// upload() in io-upload-iframe.
return io.upload(transaction, uri, config);
} else {
// Serialize HTML form data into a key-value string.
data = io._serialize(config.form, data);
}
}
// Convert falsy values to an empty string. This way IE can't be
// rediculous and translate `undefined` to "undefined".
data || (data = '');
if (data) {
switch (method) {
case 'GET':
case 'HEAD':
case 'DELETE':
u = io._concat(u, data);
data = '';
break;
case 'POST':
case 'PUT':
// If Content-Type is defined in the configuration object, or
// or as a default header, it will be used instead of
// 'application/x-www-form-urlencoded; charset=UTF-8'
config.headers = Y.merge({
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}, config.headers);
break;
}
}
if (transaction.xdr) {
// Route data to io-xdr module for flash and XDomainRequest.
return io.xdr(u, transaction, config);
}
else if (transaction.notify) {
// Route data to custom transport
return transaction.c.send(transaction, uri, config);
}
if (!sync && !transaction.upload) {
transaction.c.onreadystatechange = function() {
io._rS(transaction, config);
};
}
try {
// Determine if request is to be set as
// synchronous or asynchronous.
transaction.c.open(method, u, !sync, config.username || null, config.password || null);
io._setHeaders(transaction.c, config.headers || {});
io.start(transaction, config);
// Will work only in browsers that implement the
// Cross-Origin Resource Sharing draft.
if (config.xdr && config.xdr.credentials && SUPPORTS_CORS) {
transaction.c.withCredentials = true;
}
// Using "null" with HTTP POST will result in a request
// with no Content-Length header defined.
transaction.c.send(data);
if (sync) {
// Create a response object for synchronous transactions,
// mixing id and arguments properties with the xhr
// properties whitelist.
for (i = 0, len = XHR_PROPS.length; i < len; ++i) {
response[XHR_PROPS[i]] = transaction.c[XHR_PROPS[i]];
}
response.getAllResponseHeaders = function() {
return transaction.c.getAllResponseHeaders();
};
response.getResponseHeader = function(name) {
return transaction.c.getResponseHeader(name);
};
io.complete(transaction, config);
io._result(transaction, config);
return response;
}
} catch(e) {
if (transaction.xdr) {
// This exception is usually thrown by browsers
// that do not support XMLHttpRequest Level 2.
// Retry the request with the XDR transport set
// to 'flash'. If the Flash transport is not
// initialized or available, the transaction
// will resolve to a transport error.
return io._retry(transaction, uri, config);
} else {
io.complete(transaction, config);
io._result(transaction, config);
}
}
// If config.timeout is defined, and the request is standard XHR,
// initialize timeout polling.
if (config.timeout) {
io._startTimeout(transaction, config.timeout);
}
return {
id: transaction.id,
abort: function() {
return transaction.c ? io._abort(transaction, 'abort') : false;
},
isInProgress: function() {
return transaction.c ? (transaction.c.readyState % 4) : false;
},
io: io
};
}
};
/**
Method for initiating an ajax call. The first argument is the url end
point for the call. The second argument is an object to configure the
transaction and attach event subscriptions. The configuration object
supports the following properties:
method
HTTP method verb (e.g., GET or POST). If this property is not
not defined, the default value will be GET.
data
This is the name-value string that will be sent as the
transaction data. If the request is HTTP GET, the data become
part of querystring. If HTTP POST, the data are sent in the
message body.
xdr
Defines the transport to be used for cross-domain requests.
By setting this property, the transaction will use the specified
transport instead of XMLHttpRequest. The properties of the
transport object are:
use
The transport to be used: 'flash' or 'native'
dataType
Set the value to 'XML' if that is the expected response
content type.
form
Form serialization configuration object. Its properties are:
id
Node object or id of HTML form
useDisabled
`true` to also serialize disabled form field values
(defaults to `false`)
on
Assigns transaction event subscriptions. Available events are:
start
Fires when a request is sent to a resource.
complete
Fires when the transaction is complete.
success
Fires when the HTTP response status is within the 2xx
range.
failure
Fires when the HTTP response status is outside the 2xx
range, if an exception occurs, if the transation is aborted,
or if the transaction exceeds a configured `timeout`.
end
Fires at the conclusion of the transaction
lifecycle, after `success` or `failure`.
Callback functions for `start` and `end` receive the id of the
transaction as a first argument. For `complete`, `success`, and
`failure`, callbacks receive the id and the response object
(usually the XMLHttpRequest instance). If the `arguments`
property was included in the configuration object passed to
`Y.io()`, the configured data will be passed to all callbacks as
the last argument.
sync
Pass `true` to make a same-domain transaction synchronous.
CAVEAT : This will negatively impact the user
experience. Have a very good reason if you intend to use
this.
context
The "`this'" object for all configured event handlers. If a
specific context is needed for individual callbacks, bind the
callback to a context using `Y.bind()`.
headers
Object map of transaction headers to send to the server. The
object keys are the header names and the values are the header
values.
timeout
Millisecond threshold for the transaction before being
automatically aborted.
arguments
User-defined data passed to all registered event handlers.
This value is available as the second argument in the "start" and
"end" event handlers. It is the third argument in the "complete",
"success", and "failure" event handlers. Be sure to quote
this property name in the transaction configuration as
"arguments" is a reserved word in JavaScript (e.g.
`Y.io({ ..., "arguments": stuff })`).
@method io
@static
@param {String} url qualified path to transaction resource.
@param {Object} config configuration object for the transaction.
@return {Object}
@for YUI
**/
Y.io = function(url, config) {
// Calling IO through the static interface will use and reuse
// an instance of IO.
var transaction = Y.io._map['io:0'] || new IO();
return transaction.send.apply(transaction, [url, config]);
};
/**
Method for setting and deleting IO HTTP headers to be sent with every
request.
Hosted as a property on the `io` function (e.g. `Y.io.header`).
@method header
@param {String} name HTTP header
@param {String} value HTTP header value
@static
**/
Y.io.header = function(name, value) {
// Calling IO through the static interface will use and reuse
// an instance of IO.
var transaction = Y.io._map['io:0'] || new IO();
transaction.setHeader(name, value);
};
Y.IO = IO;
// Map of all IO instances created.
Y.io._map = {};
var XHR = win && win.XMLHttpRequest,
XDR = win && win.XDomainRequest,
AX = win && win.ActiveXObject,
// Checks for the presence of the `withCredentials` in an XHR instance
// object, which will be present if the environment supports CORS.
SUPPORTS_CORS = XHR && 'withCredentials' in (new XMLHttpRequest());
Y.mix(Y.IO, {
/**
* The ID of the default IO transport, defaults to `xhr`
* @property _default
* @type {String}
* @static
*/
_default: 'xhr',
/**
*
* @method defaultTransport
* @static
* @param {String} [id] The transport to set as the default, if empty a new transport is created.
* @return {Object} The transport object with a `send` method
*/
defaultTransport: function(id) {
if (id) {
Y.IO._default = id;
} else {
var o = {
c: Y.IO.transports[Y.IO._default](),
notify: Y.IO._default === 'xhr' ? false : true
};
return o;
}
},
/**
* An object hash of custom transports available to IO
* @property transports
* @type {Object}
* @static
*/
transports: {
xhr: function () {
return XHR ? new XMLHttpRequest() :
AX ? new ActiveXObject('Microsoft.XMLHTTP') : null;
},
xdr: function () {
return XDR ? new XDomainRequest() : null;
},
iframe: function () { return {}; },
flash: null,
nodejs: null
},
/**
* Create a custom transport of type and return it's object
* @method customTransport
* @param {String} id The id of the transport to create.
* @static
*/
customTransport: function(id) {
var o = { c: Y.IO.transports[id]() };
o[(id === 'xdr' || id === 'flash') ? 'xdr' : 'notify'] = true;
return o;
}
});
Y.mix(Y.IO.prototype, {
/**
* Fired from the notify method of the transport which in turn fires
* the event on the IO object.
* @method notify
* @param {String} event The name of the event
* @param {Object} transaction The transaction object
* @param {Object} config The configuration object for this transaction
*/
notify: function(event, transaction, config) {
var io = this;
switch (event) {
case 'timeout':
case 'abort':
case 'transport error':
transaction.c = { status: 0, statusText: event };
event = 'failure';
default:
io[event].apply(io, [transaction, config]);
}
}
});
}, 'patched-v3.11.0', {"requires": ["event-custom-base", "querystring-stringify-simple"]});
YUI.add('io-form', function (Y, NAME) {
/**
* Extends IO to enable HTML form data serialization, when specified
* in the transaction's configuration object.
* @module io
* @submodule io-form
* @for IO
*/
var eUC = encodeURIComponent;
/**
* Enumerate through an HTML form's elements collection
* and return a string comprised of key-value pairs.
*
* @method stringify
* @static
* @param {Node|String} form YUI form node or HTML form id
* @param {Object} [options] Configuration options.
* @param {Boolean} [options.useDisabled=false] Whether to include disabled fields.
* @param {Object|String} [options.extra] Extra values to include. May be a query string or an object with key/value pairs.
* @return {String}
*/
Y.IO.stringify = function(form, options) {
options = options || {};
var s = Y.IO.prototype._serialize({
id: form,
useDisabled: options.useDisabled
},
options.extra && typeof options.extra === 'object' ? Y.QueryString.stringify(options.extra) : options.extra);
return s;
};
Y.mix(Y.IO.prototype, {
/**
* Enumerate through an HTML form's elements collection
* and return a string comprised of key-value pairs.
*
* @method _serialize
* @private
* @param {Object} c
* @param {String|Element} c.id YUI form node or HTML form id
* @param {Boolean} c.useDisabled `true` to include disabled fields
* @param {String} s Key-value data defined in the configuration object.
* @return {String}
*/
_serialize: function(c, s) {
var data = [],
df = c.useDisabled || false,
item = 0,
id = (typeof c.id === 'string') ? c.id : c.id.getAttribute('id'),
e, f, n, v, d, i, il, j, jl, o;
if (!id) {
id = Y.guid('io:');
c.id.setAttribute('id', id);
}
f = Y.config.doc.getElementById(id);
if (!f || !f.elements) {
return s || '';
}
// Iterate over the form elements collection to construct the
// label-value pairs.
for (i = 0, il = f.elements.length; i < il; ++i) {
e = f.elements[i];
d = e.disabled;
n = e.name;
if (df ? n : n && !d) {
n = eUC(n) + '=';
v = eUC(e.value);
switch (e.type) {
// Safari, Opera, FF all default options.value from .text if
// value attribute not specified in markup
case 'select-one':
if (e.selectedIndex > -1) {
o = e.options[e.selectedIndex];
data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
}
break;
case 'select-multiple':
if (e.selectedIndex > -1) {
for (j = e.selectedIndex, jl = e.options.length; j < jl; ++j) {
o = e.options[j];
if (o.selected) {
data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
}
}
}
break;
case 'radio':
case 'checkbox':
if (e.checked) {
data[item++] = n + v;
}
break;
case 'file':
// stub case as XMLHttpRequest will only send the file path as a string.
case undefined:
// stub case for fieldset element which returns undefined.
case 'reset':
// stub case for input type reset button.
case 'button':
// stub case for input type button elements.
break;
case 'submit':
default:
data[item++] = n + v;
}
}
}
if (s) {
data[item++] = s;
}
return data.join('&');
}
}, true);
}, 'patched-v3.11.0', {"requires": ["io-base", "node-base"]});
YUI.add('io-queue', function (Y, NAME) {
/**
Extends IO to implement Queue for synchronous
transaction processing.
@module io
@submodule io-queue
@for IO
**/
var io = Y.io._map['io:0'] || new Y.IO();
Y.mix(Y.IO.prototype, {
/**
* Array of transactions queued for processing
*
* @property _q
* @private
* @static
* @type {Object}
*/
_q: new Y.Queue(),
_qActiveId: null,
_qInit: false,
/**
* Property to determine whether the queue is set to
* 1 (active) or 0 (inactive). When inactive, transactions
* will be stored in the queue until the queue is set to active.
*
* @property _qState
* @private
* @static
* @type {Number}
*/
_qState: 1,
/**
* Method Process the first transaction from the
* queue in FIFO order.
*
* @method _qShift
* @private
* @static
*/
_qShift: function() {
var io = this,
o = io._q.next();
io._qActiveId = o.id;
io._qState = 0;
io.send(o.uri, o.cfg, o.id);
},
/**
* Method for queueing a transaction before the request is sent to the
* resource, to ensure sequential processing.
*
* @method queue
* @static
* @return {Object}
*/
queue: function(uri, c) {
var io = this,
o = { uri: uri, cfg:c, id: this._id++ };
if(!io._qInit) {
Y.on('io:complete', function(id, o) { io._qNext(id); }, io);
io._qInit = true;
}
io._q.add(o);
if (io._qState === 1) {
io._qShift();
}
return o;
},
_qNext: function(id) {
var io = this;
io._qState = 1;
if (io._qActiveId === id && io._q.size() > 0) {
io._qShift();
}
},
/**
* Method for promoting a transaction to the top of the queue.
*
* @method promote
* @static
*/
qPromote: function(o) {
this._q.promote(o);
},
/**
* Method for removing a specific, pending transaction from
* the queue.
*
* @method remove
* @private
* @static
*/
qRemove: function(o) {
this._q.remove(o);
},
/**
* Method for cancel all pending transaction from
* the queue.
*
* @method empty
* @static
* @since 3.7.3
*/
qEmpty: function() {
this._q = new Y.Queue();
},
qStart: function() {
var io = this;
io._qState = 1;
if (io._q.size() > 0) {
io._qShift();
}
},
/**
* Method for setting queue processing to inactive.
* Transaction requests to YUI.io.queue() will be stored in the queue, but
* not processed until the queue is reset to "active".
*
* @method _stop
* @private
* @static
*/
qStop: function() {
this._qState = 0;
},
/**
* Method to query the current size of the queue.
*
* @method _size
* @private
* @static
* @return {Number}
*/
qSize: function() {
return this._q.size();
}
}, true);
function _queue(u, c) {
return io.queue.apply(io, [u, c]);
}
_queue.start = function () { io.qStart(); };
_queue.stop = function () { io.qStop(); };
_queue.promote = function (o) { io.qPromote(o); };
_queue.remove = function (o) { io.qRemove(o); };
_queue.size = function () { io.qSize(); };
_queue.empty = function () { io.qEmpty(); };
Y.io.queue = _queue;
}, 'patched-v3.11.0', {"requires": ["io-base", "queue-promote"]});
YUI.add('io-upload-iframe', function (Y, NAME) {
/**
Extends the IO to enable file uploads, with HTML forms
using an iframe as the transport medium.
@module io
@submodule io-upload-iframe
@for IO
**/
var w = Y.config.win,
d = Y.config.doc,
_std = (d.documentMode && d.documentMode >= 8),
_d = decodeURIComponent,
_end = Y.IO.prototype.end;
/**
* Creates the iframe transported used in file upload
* transactions, and binds the response event handler.
*
* @method _cFrame
* @private
* @param {Object} o Transaction object generated by _create().
* @param {Object} c Configuration object passed to YUI.io().
* @param {Object} io
*/
function _cFrame(o, c, io) {
var i = Y.Node.create('');
i._node.style.position = 'absolute';
i._node.style.top = '-1000px';
i._node.style.left = '-1000px';
Y.one('body').appendChild(i);
// Bind the onload handler to the iframe to detect the file upload response.
Y.on("load", function() { io._uploadComplete(o, c); }, '#io_iframe' + o.id);
}
/**
* Removes the iframe transport used in the file upload
* transaction.
*
* @method _dFrame
* @private
* @param {Number} id The transaction ID used in the iframe's creation.
*/
function _dFrame(id) {
Y.Event.purgeElement('#io_iframe' + id, false);
Y.one('body').removeChild(Y.one('#io_iframe' + id));
}
Y.mix(Y.IO.prototype, {
/**
* Parses the POST data object and creates hidden form elements
* for each key-value, and appends them to the HTML form object.
* @method appendData
* @private
* @static
* @param {Object} f HTML form object.
* @param {String} s The key-value POST data.
* @return {Array} o Array of created fields.
*/
_addData: function(f, s) {
// Serialize an object into a key-value string using
// querystring-stringify-simple.
if (Y.Lang.isObject(s)) {
s = Y.QueryString.stringify(s);
}
var o = [],
m = s.split('='),
i, l;
for (i = 0, l = m.length - 1; i < l; i++) {
var name = _d(m[i].substring(m[i].lastIndexOf('&') + 1));
var input = f.elements[name];
if (!input) {
o[i] = d.createElement('input');
o[i].type = 'hidden';
o[i].name = name;
o[i].value = (i + 1 === l) ? _d(m[i + 1]) : _d(m[i + 1].substring(0, (m[i + 1].lastIndexOf('&'))));
f.appendChild(o[i]);
}
}
return o;
},
/**
* Removes the custom fields created to pass additional POST
* data, along with the HTML form fields.
* @method _removeData
* @private
* @static
* @param {Object} f HTML form object.
* @param {Object} o HTML form fields created from configuration.data.
*/
_removeData: function(f, o) {
var i, l;
for (i = 0, l = o.length; i < l; i++) {
f.removeChild(o[i]);
}
},
/**
* Sets the appropriate attributes and values to the HTML
* form, in preparation of a file upload transaction.
* @method _setAttrs
* @private
* @static
* @param {Object} f HTML form object.
* @param {Object} id The Transaction ID.
* @param {Object} uri Qualified path to transaction resource.
*/
_setAttrs: function(f, id, uri) {
// Track original HTML form attribute values.
this._originalFormAttrs = {
action: f.getAttribute('action'),
target: f.getAttribute('target')
};
f.setAttribute('action', uri);
f.setAttribute('method', 'POST');
f.setAttribute('target', 'io_iframe' + id );
f.setAttribute(Y.UA.ie && !_std ? 'encoding' : 'enctype', 'multipart/form-data');
},
/**
* Reset the HTML form attributes to their original values.
* @method _resetAttrs
* @private
* @static
* @param {Object} f HTML form object.
* @param {Object} a Object of original attributes.
*/
_resetAttrs: function(f, a) {
Y.Object.each(a, function(v, p) {
if (v) {
f.setAttribute(p, v);
}
else {
f.removeAttribute(p);
}
});
},
/**
* Starts timeout count if the configuration object
* has a defined timeout property.
*
* @method _startUploadTimeout
* @private
* @static
* @param {Object} o Transaction object generated by _create().
* @param {Object} c Configuration object passed to YUI.io().
*/
_startUploadTimeout: function(o, c) {
var io = this;
io._timeout[o.id] = w.setTimeout(
function() {
o.status = 0;
o.statusText = 'timeout';
io.complete(o, c);
io.end(o, c);
}, c.timeout);
},
/**
* Clears the timeout interval started by _startUploadTimeout().
* @method _clearUploadTimeout
* @private
* @static
* @param {Number} id - Transaction ID.
*/
_clearUploadTimeout: function(id) {
var io = this;
w.clearTimeout(io._timeout[id]);
delete io._timeout[id];
},
/**
* Bound to the iframe's Load event and processes
* the response data.
* @method _uploadComplete
* @private
* @static
* @param {Object} o The transaction object
* @param {Object} c Configuration object for the transaction.
*/
_uploadComplete: function(o, c) {
var io = this,
d = Y.one('#io_iframe' + o.id).get('contentWindow.document'),
b = d.one('body'),
p;
if (c.timeout) {
io._clearUploadTimeout(o.id);
}
try {
if (b) {
// When a response Content-Type of "text/plain" is used, Firefox and Safari
// will wrap the response string with .
p = b.one('pre:first-child');
o.c.responseText = p ? p.getHTML() : b.getHTML();
}
else {
o.c.responseXML = d._node;
}
}
catch (e) {
o.e = "upload failure";
}
io.complete(o, c);
io.end(o, c);
// The transaction is complete, so call _dFrame to remove
// the event listener bound to the iframe transport, and then
// destroy the iframe.
w.setTimeout( function() { _dFrame(o.id); }, 0);
},
/**
* Uploads HTML form data, inclusive of files/attachments,
* using the iframe created in _create to facilitate the transaction.
* @method _upload
* @private
* @static
* @param {Object} o The transaction object
* @param {Object} uri Qualified path to transaction resource.
* @param {Object} c Configuration object for the transaction.
*/
_upload: function(o, uri, c) {
var io = this,
f = (typeof c.form.id === 'string') ? d.getElementById(c.form.id) : Y.Node.getDOMNode(c.form.id),
fields;
// Initialize the HTML form properties in case they are
// not defined in the HTML form.
io._setAttrs(f, o.id, uri);
if (c.data) {
fields = io._addData(f, c.data);
}
// Start polling if a callback is present and the timeout
// property has been defined.
if (c.timeout) {
io._startUploadTimeout(o, c);
}
// Start file upload.
f.submit();
io.start(o, c);
if (c.data) {
var _onIoEndHandler = io.on('io:end', function (event) {
_onIoEndHandler.detach();
io._removeData(f, fields);
});
}
return {
id: o.id,
abort: function() {
o.status = 0;
o.statusText = 'abort';
if (Y.one('#io_iframe' + o.id)) {
_dFrame(o.id);
io.complete(o, c);
io.end(o, c);
}
else {
return false;
}
},
isInProgress: function() {
return Y.one('#io_iframe' + o.id) ? true : false;
},
io: io
};
},
upload: function(o, uri, c) {
_cFrame(o, c, this);
return this._upload(o, uri, c);
},
end: function(transaction, config) {
var form, io;
if (config) {
form = config.form;
if (form && form.upload) {
io = this;
// Restore HTML form attributes to their original values.
form = (typeof form.id === 'string') ? d.getElementById(form.id) : form.id;
io._resetAttrs(form, this._originalFormAttrs);
}
}
return _end.call(this, transaction, config);
}
}, true);
}, 'patched-v3.11.0', {"requires": ["io-base", "node-base"]});
YUI.add('io-xdr', function (Y, NAME) {
/**
Extends IO to provide an alternate, Flash transport, for making
cross-domain requests.
@module io
@submodule io-xdr
@for IO
**/
// Helpful resources when working with the mess that is XDomainRequest:
// http://www.cypressnorth.com/blog/web-programming-and-development/internet-explorer-aborting-ajax-requests-fixed/
// http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
/**
Fires when the XDR transport is ready for use.
@event io:xdrReady
**/
var E_XDR_READY = Y.publish('io:xdrReady', { fireOnce: true }),
/**
Map of stored configuration objects when using
Flash as the transport for cross-domain requests.
@property _cB
@private
@type {Object}
**/
_cB = {},
/**
Map of transaction simulated readyState values
when XDomainRequest is the transport.
@property _rS
@private
@type {Object}
**/
_rS = {},
// Document reference
d = Y.config.doc,
// Window reference
w = Y.config.win,
// XDomainRequest cross-origin request detection
xdr = w && w.XDomainRequest;
/**
Method that creates the Flash transport swf.
@method _swf
@private
@param {String} uri - location of io.swf.
@param {String} yid - YUI sandbox id.
@param {String} yid - IO instance id.
**/
function _swf(uri, yid, uid) {
var o = '' +
' ' +
' ' +
' ' +
' ',
c = d.createElement('div');
d.body.appendChild(c);
c.innerHTML = o;
}
/**
Creates a response object for XDR transactions, for success
and failure cases.
@method _data
@private
@param {Object} o - Transaction object generated by _create() in io-base.
@param {Boolean} u - Configuration xdr.use.
@param {Boolean} d - Configuration xdr.dataType.
@return {Object}
**/
function _data(o, u, d) {
if (u === 'flash') {
o.c.responseText = decodeURI(o.c.responseText);
}
if (d === 'xml') {
o.c.responseXML = Y.DataType.XML.parse(o.c.responseText);
}
return o;
}
/**
Method for intiating an XDR transaction abort.
@method _abort
@private
@param {Object} o - Transaction object generated by _create() in io-base.
@param {Object} c - configuration object for the transaction.
**/
function _abort(o, c) {
return o.c.abort(o.id, c);
}
/**
Method for determining if an XDR transaction has completed
and all data are received.
@method _isInProgress
@private
@param {Object} o - Transaction object generated by _create() in io-base.
**/
function _isInProgress(o) {
return xdr ? _rS[o.id] !== 4 : o.c.isInProgress(o.id);
}
Y.mix(Y.IO.prototype, {
/**
Map of io transports.
@property _transport
@private
@type {Object}
**/
_transport: {},
/**
Sets event handlers for XDomainRequest transactions.
@method _ieEvt
@private
@static
@param {Object} o - Transaction object generated by _create() in io-base.
@param {Object} c - configuration object for the transaction.
**/
_ieEvt: function(o, c) {
var io = this,
i = o.id,
t = 'timeout';
o.c.onprogress = function() { _rS[i] = 3; };
o.c.onload = function() {
_rS[i] = 4;
io.xdrResponse('success', o, c);
};
o.c.onerror = function() {
_rS[i] = 4;
io.xdrResponse('failure', o, c);
};
o.c.ontimeout = function() {
_rS[i] = 4;
io.xdrResponse(t, o, c);
};
o.c[t] = c[t] || 0;
},
/**
Method for accessing the transport's interface for making a
cross-domain transaction.
@method xdr
@param {String} uri - qualified path to transaction resource.
@param {Object} o - Transaction object generated by _create() in io-base.
@param {Object} c - configuration object for the transaction.
**/
xdr: function(uri, o, c) {
var io = this;
if (c.xdr.use === 'flash') {
// The configuration object cannot be serialized safely
// across Flash's ExternalInterface.
_cB[o.id] = c;
w.setTimeout(function() {
try {
o.c.send(uri, { id: o.id,
uid: o.uid,
method: c.method,
data: c.data,
headers: c.headers });
}
catch(e) {
io.xdrResponse('transport error', o, c);
delete _cB[o.id];
}
}, Y.io.xdr.delay);
}
else if (xdr) {
io._ieEvt(o, c);
o.c.open(c.method || 'GET', uri);
// Make async to protect against IE 8 oddities.
setTimeout(function() {
o.c.send(c.data);
}, 0);
}
else {
o.c.send(uri, o, c);
}
return {
id: o.id,
abort: function() {
return o.c ? _abort(o, c) : false;
},
isInProgress: function() {
return o.c ? _isInProgress(o.id) : false;
},
io: io
};
},
/**
Response controller for cross-domain requests when using the
Flash transport or IE8's XDomainRequest object.
@method xdrResponse
@param {String} e Event name
@param {Object} o Transaction object generated by _create() in io-base.
@param {Object} c Configuration object for the transaction.
@return {Object}
**/
xdrResponse: function(e, o, c) {
c = _cB[o.id] ? _cB[o.id] : c;
var io = this,
m = xdr ? _rS : _cB,
u = c.xdr.use,
d = c.xdr.dataType;
switch (e) {
case 'start':
io.start(o, c);
break;
//case 'complete':
//This case is not used by Flash or XDomainRequest.
//io.complete(o, c);
//break;
case 'success':
io.success(_data(o, u, d), c);
delete m[o.id];
break;
case 'timeout':
case 'abort':
case 'transport error':
o.c = { status: 0, statusText: e };
case 'failure':
io.failure(_data(o, u, d), c);
delete m[o.id];
break;
}
},
/**
Fires event "io:xdrReady"
@method _xdrReady
@private
@param {Number} yid - YUI sandbox id.
@param {Number} uid - IO instance id.
**/
_xdrReady: function(yid, uid) {
Y.fire(E_XDR_READY, yid, uid);
},
/**
Initializes the desired transport.
@method transport
@param {Object} o - object of transport configurations.
**/
transport: function(c) {
if (c.id === 'flash') {
_swf(Y.UA.ie ? c.src + '?d=' + new Date().valueOf().toString() : c.src, Y.id, c.uid);
Y.IO.transports.flash = function() { return d.getElementById('io_swf'); };
}
}
});
/**
Fires event "io:xdrReady"
@method xdrReady
@protected
@static
@param {Number} yid - YUI sandbox id.
@param {Number} uid - IO instance id.
**/
Y.io.xdrReady = function(yid, uid){
var io = Y.io._map[uid];
Y.io.xdr.delay = 0;
io._xdrReady.apply(io, [yid, uid]);
};
Y.io.xdrResponse = function(e, o, c){
var io = Y.io._map[o.uid];
io.xdrResponse.apply(io, [e, o, c]);
};
Y.io.transport = function(c){
var io = Y.io._map['io:0'] || new Y.IO();
c.uid = io._uid;
io.transport.apply(io, [c]);
};
/**
Delay value to calling the Flash transport, in the
event io.swf has not finished loading. Once the E_XDR_READY
event is fired, this value will be set to 0.
@property delay
@static
@type {Number}
**/
Y.io.xdr = { delay : 100 };
}, 'patched-v3.11.0', {"requires": ["io-base", "datatype-xml-parse"]});
YUI.add('json-parse', function (Y, NAME) {
var _JSON = Y.config.global.JSON;
Y.namespace('JSON').parse = function (obj, reviver, space) {
return _JSON.parse((typeof obj === 'string' ? obj : obj + ''), reviver, space);
};
}, 'patched-v3.11.0', {"requires": ["yui-base"]});
YUI.add('json-stringify', function (Y, NAME) {
/**
* Provides Y.JSON.stringify method for converting objects to JSON strings.
*
* @module json
* @submodule json-stringify
* @for JSON
* @static
*/
var COLON = ':',
_JSON = Y.config.global.JSON;
Y.mix(Y.namespace('JSON'), {
/**
* Serializes a Date instance as a UTC date string. Used internally by
* stringify. Override this method if you need Dates serialized in a
* different format.
*
* @method dateToString
* @param d {Date} The Date to serialize
* @return {String} stringified Date in UTC format YYYY-MM-DDTHH:mm:SSZ
* @deprecated Use a replacer function
* @static
*/
dateToString: function (d) {
function _zeroPad(v) {
return v < 10 ? '0' + v : v;
}
return d.getUTCFullYear() + '-' +
_zeroPad(d.getUTCMonth() + 1) + '-' +
_zeroPad(d.getUTCDate()) + 'T' +
_zeroPad(d.getUTCHours()) + COLON +
_zeroPad(d.getUTCMinutes()) + COLON +
_zeroPad(d.getUTCSeconds()) + 'Z';
},
/**
* Converts an arbitrary value to a JSON string representation.
*
* Objects with cyclical references will trigger an exception.
*
* If a whitelist is provided, only matching object keys will be
* included. Alternately, a replacer function may be passed as the
* second parameter. This function is executed on every value in the
* input, and its return value will be used in place of the original value.
* This is useful to serialize specialized objects or class instances.
*
* If a positive integer or non-empty string is passed as the third
* parameter, the output will be formatted with carriage returns and
* indentation for readability. If a String is passed (such as "\t") it
* will be used once for each indentation level. If a number is passed,
* that number of spaces will be used.
*
* @method stringify
* @param o {MIXED} any arbitrary value to convert to JSON string
* @param w {Array|Function} (optional) whitelist of acceptable object
* keys to include, or a replacer function to modify the
* raw value before serialization
* @param ind {Number|String} (optional) indentation character or depth of
* spaces to format the output.
* @return {string} JSON string representation of the input
* @static
*/
stringify: function () {
return _JSON.stringify.apply(_JSON, arguments);
},
/**
* Number of occurrences of a special character within a single call to
* stringify that should trigger promotion of that character to a dedicated
* preprocess step for future calls. This is only used in environments
* that don't support native JSON, or when useNativeJSONStringify is set to
* false.
*
* So, if set to 50 and an object is passed to stringify that includes
* strings containing the special character \x07 more than 50 times,
* subsequent calls to stringify will process object strings through a
* faster serialization path for \x07 before using the generic, slower,
* replacement process for all special characters.
*
* To prime the preprocessor cache, set this value to 1, then call
* Y.JSON.stringify("(all special characters to
* cache) ");
, then return this setting to a more conservative
* value.
*
* Special characters \ " \b \t \n \f \r are already cached.
*
* @property charCacheThreshold
* @static
* @default 100
* @type {Number}
*/
charCacheThreshold: 100
});
}, 'patched-v3.11.0', {"requires": ["yui-base"]});
YUI.add('node-base', function (Y, NAME) {
/**
* @module node
* @submodule node-base
*/
var methods = [
/**
* Determines whether each node has the given className.
* @method hasClass
* @for Node
* @param {String} className the class name to search for
* @return {Boolean} Whether or not the element has the specified class
*/
'hasClass',
/**
* Adds a class name to each node.
* @method addClass
* @param {String} className the class name to add to the node's class attribute
* @chainable
*/
'addClass',
/**
* Removes a class name from each node.
* @method removeClass
* @param {String} className the class name to remove from the node's class attribute
* @chainable
*/
'removeClass',
/**
* Replace a class with another class for each node.
* If no oldClassName is present, the newClassName is simply added.
* @method replaceClass
* @param {String} oldClassName the class name to be replaced
* @param {String} newClassName the class name that will be replacing the old class name
* @chainable
*/
'replaceClass',
/**
* If the className exists on the node it is removed, if it doesn't exist it is added.
* @method toggleClass
* @param {String} className the class name to be toggled
* @param {Boolean} force Option to force adding or removing the class.
* @chainable
*/
'toggleClass'
];
Y.Node.importMethod(Y.DOM, methods);
/**
* Determines whether each node has the given className.
* @method hasClass
* @see Node.hasClass
* @for NodeList
* @param {String} className the class name to search for
* @return {Array} An array of booleans for each node bound to the NodeList.
*/
/**
* Adds a class name to each node.
* @method addClass
* @see Node.addClass
* @param {String} className the class name to add to the node's class attribute
* @chainable
*/
/**
* Removes a class name from each node.
* @method removeClass
* @see Node.removeClass
* @param {String} className the class name to remove from the node's class attribute
* @chainable
*/
/**
* Replace a class with another class for each node.
* If no oldClassName is present, the newClassName is simply added.
* @method replaceClass
* @see Node.replaceClass
* @param {String} oldClassName the class name to be replaced
* @param {String} newClassName the class name that will be replacing the old class name
* @chainable
*/
/**
* If the className exists on the node it is removed, if it doesn't exist it is added.
* @method toggleClass
* @see Node.toggleClass
* @param {String} className the class name to be toggled
* @chainable
*/
Y.NodeList.importMethod(Y.Node.prototype, methods);
/**
* @module node
* @submodule node-base
*/
var Y_Node = Y.Node,
Y_DOM = Y.DOM;
/**
* Returns a new dom node using the provided markup string.
* @method create
* @static
* @param {String} html The markup used to create the element
* Use `Y.Escape.html()`
* to escape html content.
* @param {HTMLDocument} doc An optional document context
* @return {Node} A Node instance bound to a DOM node or fragment
* @for Node
*/
Y_Node.create = function(html, doc) {
if (doc && doc._node) {
doc = doc._node;
}
return Y.one(Y_DOM.create(html, doc));
};
Y.mix(Y_Node.prototype, {
/**
* Creates a new Node using the provided markup string.
* @method create
* @param {String} html The markup used to create the element.
* Use `Y.Escape.html()`
* to escape html content.
* @param {HTMLDocument} doc An optional document context
* @return {Node} A Node instance bound to a DOM node or fragment
*/
create: Y_Node.create,
/**
* Inserts the content before the reference node.
* @method insert
* @param {String | Node | HTMLElement | NodeList | HTMLCollection} content The content to insert
* Use `Y.Escape.html()`
* to escape html content.
* @param {Int | Node | HTMLElement | String} where The position to insert at.
* Possible "where" arguments
*
* Y.Node
* The Node to insert before
* HTMLElement
* The element to insert before
* Int
* The index of the child element to insert before
* "replace"
* Replaces the existing HTML
* "before"
* Inserts before the existing HTML
* "before"
* Inserts content before the node
* "after"
* Inserts content after the node
*
* @chainable
*/
insert: function(content, where) {
this._insert(content, where);
return this;
},
_insert: function(content, where) {
var node = this._node,
ret = null;
if (typeof where == 'number') { // allow index
where = this._node.childNodes[where];
} else if (where && where._node) { // Node
where = where._node;
}
if (content && typeof content != 'string') { // allow Node or NodeList/Array instances
content = content._node || content._nodes || content;
}
ret = Y_DOM.addHTML(node, content, where);
return ret;
},
/**
* Inserts the content as the firstChild of the node.
* @method prepend
* @param {String | Node | HTMLElement} content The content to insert
* Use `Y.Escape.html()`
* to escape html content.
* @chainable
*/
prepend: function(content) {
return this.insert(content, 0);
},
/**
* Inserts the content as the lastChild of the node.
* @method append
* @param {String | Node | HTMLElement} content The content to insert
* Use `Y.Escape.html()`
* to escape html content.
* @chainable
*/
append: function(content) {
return this.insert(content, null);
},
/**
* @method appendChild
* @param {String | HTMLElement | Node} node Node to be appended
* Use `Y.Escape.html()`
* to escape html content.
* @return {Node} The appended node
*/
appendChild: function(node) {
return Y_Node.scrubVal(this._insert(node));
},
/**
* @method insertBefore
* @param {String | HTMLElement | Node} newNode Node to be appended
* @param {HTMLElement | Node} refNode Node to be inserted before
* Use `Y.Escape.html()`
* to escape html content.
* @return {Node} The inserted node
*/
insertBefore: function(newNode, refNode) {
return Y.Node.scrubVal(this._insert(newNode, refNode));
},
/**
* Appends the node to the given node.
* @method appendTo
* @param {Node | HTMLElement} node The node to append to
* @chainable
*/
appendTo: function(node) {
Y.one(node).append(this);
return this;
},
/**
* Replaces the node's current content with the content.
* Note that this passes to innerHTML and is not escaped.
* Use `Y.Escape.html()`
* to escape html content or `set('text')` to add as text.
* @method setContent
* @deprecated Use setHTML
* @param {String | Node | HTMLElement | NodeList | HTMLCollection} content The content to insert
* @chainable
*/
setContent: function(content) {
this._insert(content, 'replace');
return this;
},
/**
* Returns the node's current content (e.g. innerHTML)
* @method getContent
* @deprecated Use getHTML
* @return {String} The current content
*/
getContent: function() {
var node = this;
if (node._node.nodeType === 11) { // 11 === Node.DOCUMENT_FRAGMENT_NODE
// "this", when it is a document fragment, must be cloned because
// the nodes contained in the fragment actually disappear once
// the fragment is appended anywhere
node = node.create("
").append(node.cloneNode(true));
}
return node.get("innerHTML");
}
});
/**
* Replaces the node's current html content with the content provided.
* Note that this passes to innerHTML and is not escaped.
* Use `Y.Escape.html()` to escape HTML, or `set('text')` to add as text.
* @method setHTML
* @param {String | HTML | Node | HTMLElement | NodeList | HTMLCollection} content The content to insert
* @chainable
*/
Y.Node.prototype.setHTML = Y.Node.prototype.setContent;
/**
* Returns the node's current html content (e.g. innerHTML)
* @method getHTML
* @return {String} The html content
*/
Y.Node.prototype.getHTML = Y.Node.prototype.getContent;
Y.NodeList.importMethod(Y.Node.prototype, [
/**
* Called on each Node instance
* @for NodeList
* @method append
* @see Node.append
*/
'append',
/**
* Called on each Node instance
* @for NodeList
* @method insert
* @see Node.insert
*/
'insert',
/**
* Called on each Node instance
* @for NodeList
* @method appendChild
* @see Node.appendChild
*/
'appendChild',
/**
* Called on each Node instance
* @for NodeList
* @method insertBefore
* @see Node.insertBefore
*/
'insertBefore',
/**
* Called on each Node instance
* @for NodeList
* @method prepend
* @see Node.prepend
*/
'prepend',
/**
* Called on each Node instance
* Note that this passes to innerHTML and is not escaped.
* Use `Y.Escape.html()` to escape HTML, or `set('text')` to add as text.
* @for NodeList
* @method setContent
* @deprecated Use setHTML
*/
'setContent',
/**
* Called on each Node instance
* @for NodeList
* @method getContent
* @deprecated Use getHTML
*/
'getContent',
/**
* Called on each Node instance
* Note that this passes to innerHTML and is not escaped.
* Use `Y.Escape.html()` to escape HTML, or `set('text')` to add as text.
* @for NodeList
* @method setHTML
* @see Node.setHTML
*/
'setHTML',
/**
* Called on each Node instance
* @for NodeList
* @method getHTML
* @see Node.getHTML
*/
'getHTML'
]);
/**
* @module node
* @submodule node-base
*/
var Y_Node = Y.Node,
Y_DOM = Y.DOM;
/**
* Static collection of configuration attributes for special handling
* @property ATTRS
* @static
* @type object
*/
Y_Node.ATTRS = {
/**
* Allows for getting and setting the text of an element.
* Formatting is preserved and special characters are treated literally.
* @config text
* @type String
*/
text: {
getter: function() {
return Y_DOM.getText(this._node);
},
setter: function(content) {
Y_DOM.setText(this._node, content);
return content;
}
},
/**
* Allows for getting and setting the text of an element.
* Formatting is preserved and special characters are treated literally.
* @config for
* @type String
*/
'for': {
getter: function() {
return Y_DOM.getAttribute(this._node, 'for');
},
setter: function(val) {
Y_DOM.setAttribute(this._node, 'for', val);
return val;
}
},
'options': {
getter: function() {
return this._node.getElementsByTagName('option');
}
},
/**
* Returns a NodeList instance of all HTMLElement children.
* @readOnly
* @config children
* @type NodeList
*/
'children': {
getter: function() {
var node = this._node,
children = node.children,
childNodes, i, len;
if (!children || (Y.UA.ie && Y.UA.ie < 9)) {
childNodes = node.childNodes;
children = [];
for (i = 0, len = childNodes.length; i < len; ++i) {
if (childNodes[i].tagName && (childNodes[i].nodeType === 1)) {
children[children.length] = childNodes[i];
}
}
}
return Y.all(children);
}
},
value: {
getter: function() {
return Y_DOM.getValue(this._node);
},
setter: function(val) {
Y_DOM.setValue(this._node, val);
return val;
}
}
};
Y.Node.importMethod(Y.DOM, [
/**
* Allows setting attributes on DOM nodes, normalizing in some cases.
* This passes through to the DOM node, allowing for custom attributes.
* @method setAttribute
* @for Node
* @for NodeList
* @chainable
* @param {string} name The attribute name
* @param {string} value The value to set
*/
'setAttribute',
/**
* Allows getting attributes on DOM nodes, normalizing in some cases.
* This passes through to the DOM node, allowing for custom attributes.
* @method getAttribute
* @for Node
* @for NodeList
* @param {string} name The attribute name
* @return {string} The attribute value
*/
'getAttribute'
]);
/**
* @module node
* @submodule node-base
*/
var Y_Node = Y.Node;
var Y_NodeList = Y.NodeList;
/**
* List of events that route to DOM events
* @static
* @property DOM_EVENTS
* @for Node
*/
Y_Node.DOM_EVENTS = {
abort: 1,
beforeunload: 1,
blur: 1,
change: 1,
click: 1,
close: 1,
command: 1,
contextmenu: 1,
dblclick: 1,
DOMMouseScroll: 1,
drag: 1,
dragstart: 1,
dragenter: 1,
dragover: 1,
dragleave: 1,
dragend: 1,
drop: 1,
error: 1,
focus: 1,
key: 1,
keydown: 1,
keypress: 1,
keyup: 1,
load: 1,
message: 1,
mousedown: 1,
mouseenter: 1,
mouseleave: 1,
mousemove: 1,
mousemultiwheel: 1,
mouseout: 1,
mouseover: 1,
mouseup: 1,
mousewheel: 1,
orientationchange: 1,
reset: 1,
resize: 1,
select: 1,
selectstart: 1,
submit: 1,
scroll: 1,
textInput: 1,
unload: 1
};
// Add custom event adaptors to this list. This will make it so
// that delegate, key, available, contentready, etc all will
// be available through Node.on
Y.mix(Y_Node.DOM_EVENTS, Y.Env.evt.plugins);
Y.augment(Y_Node, Y.EventTarget);
Y.mix(Y_Node.prototype, {
/**
* Removes event listeners from the node and (optionally) its subtree
* @method purge
* @param {Boolean} recurse (optional) Whether or not to remove listeners from the
* node's subtree
* @param {String} type (optional) Only remove listeners of the specified type
* @chainable
*
*/
purge: function(recurse, type) {
Y.Event.purgeElement(this._node, recurse, type);
return this;
}
});
Y.mix(Y.NodeList.prototype, {
_prepEvtArgs: function(type, fn, context) {
// map to Y.on/after signature (type, fn, nodes, context, arg1, arg2, etc)
var args = Y.Array(arguments, 0, true);
if (args.length < 2) { // type only (event hash) just add nodes
args[2] = this._nodes;
} else {
args.splice(2, 0, this._nodes);
}
args[3] = context || this; // default to NodeList instance as context
return args;
},
/**
Subscribe a callback function for each `Node` in the collection to execute
in response to a DOM event.
NOTE: Generally, the `on()` method should be avoided on `NodeLists`, in
favor of using event delegation from a parent Node. See the Event user
guide for details.
Most DOM events are associated with a preventable default behavior, such as
link clicks navigating to a new page. Callbacks are passed a
`DOMEventFacade` object as their first argument (usually called `e`) that
can be used to prevent this default behavior with `e.preventDefault()`. See
the `DOMEventFacade` API for all available properties and methods on the
object.
By default, the `this` object will be the `NodeList` that the subscription
came from, not the `Node` that received the event . Use
`e.currentTarget` to refer to the `Node`.
Returning `false` from a callback is supported as an alternative to calling
`e.preventDefault(); e.stopPropagation();`. However, it is recommended to
use the event methods.
@example
Y.all(".sku").on("keydown", function (e) {
if (e.keyCode === 13) {
e.preventDefault();
// Use e.currentTarget to refer to the individual Node
var item = Y.MyApp.searchInventory( e.currentTarget.get('value') );
// etc ...
}
});
@method on
@param {String} type The name of the event
@param {Function} fn The callback to execute in response to the event
@param {Object} [context] Override `this` object in callback
@param {Any} [arg*] 0..n additional arguments to supply to the subscriber
@return {EventHandle} A subscription handle capable of detaching that
subscription
@for NodeList
**/
on: function(type, fn, context) {
return Y.on.apply(Y, this._prepEvtArgs.apply(this, arguments));
},
/**
* Applies an one-time event listener to each Node bound to the NodeList.
* @method once
* @param {String} type The event being listened for
* @param {Function} fn The handler to call when the event fires
* @param {Object} context The context to call the handler with.
* Default is the NodeList instance.
* @return {EventHandle} A subscription handle capable of detaching that
* subscription
* @for NodeList
*/
once: function(type, fn, context) {
return Y.once.apply(Y, this._prepEvtArgs.apply(this, arguments));
},
/**
* Applies an event listener to each Node bound to the NodeList.
* The handler is called only after all on() handlers are called
* and the event is not prevented.
* @method after
* @param {String} type The event being listened for
* @param {Function} fn The handler to call when the event fires
* @param {Object} context The context to call the handler with.
* Default is the NodeList instance.
* @return {EventHandle} A subscription handle capable of detaching that
* subscription
* @for NodeList
*/
after: function(type, fn, context) {
return Y.after.apply(Y, this._prepEvtArgs.apply(this, arguments));
},
/**
* Applies an one-time event listener to each Node bound to the NodeList
* that will be called only after all on() handlers are called and the
* event is not prevented.
*
* @method onceAfter
* @param {String} type The event being listened for
* @param {Function} fn The handler to call when the event fires
* @param {Object} context The context to call the handler with.
* Default is the NodeList instance.
* @return {EventHandle} A subscription handle capable of detaching that
* subscription
* @for NodeList
*/
onceAfter: function(type, fn, context) {
return Y.onceAfter.apply(Y, this._prepEvtArgs.apply(this, arguments));
}
});
Y_NodeList.importMethod(Y.Node.prototype, [
/**
* Called on each Node instance
* @method detach
* @see Node.detach
* @for NodeList
*/
'detach',
/** Called on each Node instance
* @method detachAll
* @see Node.detachAll
* @for NodeList
*/
'detachAll'
]);
/**
Subscribe a callback function to execute in response to a DOM event or custom
event.
Most DOM events are associated with a preventable default behavior such as
link clicks navigating to a new page. Callbacks are passed a `DOMEventFacade`
object as their first argument (usually called `e`) that can be used to
prevent this default behavior with `e.preventDefault()`. See the
`DOMEventFacade` API for all available properties and methods on the object.
If the event name passed as the first parameter is not a whitelisted DOM event,
it will be treated as a custom event subscriptions, allowing
`node.fire('customEventName')` later in the code. Refer to the Event user guide
for the full DOM event whitelist.
By default, the `this` object in the callback will refer to the subscribed
`Node`.
Returning `false` from a callback is supported as an alternative to calling
`e.preventDefault(); e.stopPropagation();`. However, it is recommended to use
the event methods.
@example
Y.one("#my-form").on("submit", function (e) {
e.preventDefault();
// proceed with ajax form submission instead...
});
@method on
@param {String} type The name of the event
@param {Function} fn The callback to execute in response to the event
@param {Object} [context] Override `this` object in callback
@param {Any} [arg*] 0..n additional arguments to supply to the subscriber
@return {EventHandle} A subscription handle capable of detaching that
subscription
@for Node
**/
Y.mix(Y.Node.ATTRS, {
offsetHeight: {
setter: function(h) {
Y.DOM.setHeight(this._node, h);
return h;
},
getter: function() {
return this._node.offsetHeight;
}
},
offsetWidth: {
setter: function(w) {
Y.DOM.setWidth(this._node, w);
return w;
},
getter: function() {
return this._node.offsetWidth;
}
}
});
Y.mix(Y.Node.prototype, {
sizeTo: function(w, h) {
var node;
if (arguments.length < 2) {
node = Y.one(w);
w = node.get('offsetWidth');
h = node.get('offsetHeight');
}
this.setAttrs({
offsetWidth: w,
offsetHeight: h
});
}
});
/**
* @module node
* @submodule node-base
*/
var Y_Node = Y.Node;
Y.mix(Y_Node.prototype, {
/**
* Makes the node visible.
* If the "transition" module is loaded, show optionally
* animates the showing of the node using either the default
* transition effect ('fadeIn'), or the given named effect.
* @method show
* @for Node
* @param {String} name A named Transition effect to use as the show effect.
* @param {Object} config Options to use with the transition.
* @param {Function} callback An optional function to run after the transition completes.
* @chainable
*/
show: function(callback) {
callback = arguments[arguments.length - 1];
this.toggleView(true, callback);
return this;
},
/**
* The implementation for showing nodes.
* Default is to remove the hidden attribute and reset the CSS style.display property.
* @method _show
* @protected
* @chainable
*/
_show: function() {
this.removeAttribute('hidden');
// For back-compat we need to leave this in for browsers that
// do not visually hide a node via the hidden attribute
// and for users that check visibility based on style display.
this.setStyle('display', '');
},
_isHidden: function() {
return Y.DOM.getAttribute(this._node, 'hidden') === 'true';
},
/**
* Displays or hides the node.
* If the "transition" module is loaded, toggleView optionally
* animates the toggling of the node using given named effect.
* @method toggleView
* @for Node
* @param {String} [name] An optional string value to use as transition effect.
* @param {Boolean} [on] An optional boolean value to force the node to be shown or hidden
* @param {Function} [callback] An optional function to run after the transition completes.
* @chainable
*/
toggleView: function(on, callback) {
this._toggleView.apply(this, arguments);
return this;
},
_toggleView: function(on, callback) {
callback = arguments[arguments.length - 1];
// base on current state if not forcing
if (typeof on != 'boolean') {
on = (this._isHidden()) ? 1 : 0;
}
if (on) {
this._show();
} else {
this._hide();
}
if (typeof callback == 'function') {
callback.call(this);
}
return this;
},
/**
* Hides the node.
* If the "transition" module is loaded, hide optionally
* animates the hiding of the node using either the default
* transition effect ('fadeOut'), or the given named effect.
* @method hide
* @param {String} name A named Transition effect to use as the show effect.
* @param {Object} config Options to use with the transition.
* @param {Function} callback An optional function to run after the transition completes.
* @chainable
*/
hide: function(callback) {
callback = arguments[arguments.length - 1];
this.toggleView(false, callback);
return this;
},
/**
* The implementation for hiding nodes.
* Default is to set the hidden attribute to true and set the CSS style.display to 'none'.
* @method _hide
* @protected
* @chainable
*/
_hide: function() {
this.setAttribute('hidden', true);
// For back-compat we need to leave this in for browsers that
// do not visually hide a node via the hidden attribute
// and for users that check visibility based on style display.
this.setStyle('display', 'none');
}
});
Y.NodeList.importMethod(Y.Node.prototype, [
/**
* Makes each node visible.
* If the "transition" module is loaded, show optionally
* animates the showing of the node using either the default
* transition effect ('fadeIn'), or the given named effect.
* @method show
* @param {String} name A named Transition effect to use as the show effect.
* @param {Object} config Options to use with the transition.
* @param {Function} callback An optional function to run after the transition completes.
* @for NodeList
* @chainable
*/
'show',
/**
* Hides each node.
* If the "transition" module is loaded, hide optionally
* animates the hiding of the node using either the default
* transition effect ('fadeOut'), or the given named effect.
* @method hide
* @param {String} name A named Transition effect to use as the show effect.
* @param {Object} config Options to use with the transition.
* @param {Function} callback An optional function to run after the transition completes.
* @chainable
*/
'hide',
/**
* Displays or hides each node.
* If the "transition" module is loaded, toggleView optionally
* animates the toggling of the nodes using given named effect.
* @method toggleView
* @param {String} [name] An optional string value to use as transition effect.
* @param {Boolean} [on] An optional boolean value to force the nodes to be shown or hidden
* @param {Function} [callback] An optional function to run after the transition completes.
* @chainable
*/
'toggleView'
]);
if (!Y.config.doc.documentElement.hasAttribute) { // IE < 8
Y.Node.prototype.hasAttribute = function(attr) {
if (attr === 'value') {
if (this.get('value') !== "") { // IE < 8 fails to populate specified when set in HTML
return true;
}
}
return !!(this._node.attributes[attr] &&
this._node.attributes[attr].specified);
};
}
// IE throws an error when calling focus() on an element that's invisible, not
// displayed, or disabled.
Y.Node.prototype.focus = function () {
try {
this._node.focus();
} catch (e) {
}
return this;
};
// IE throws error when setting input.type = 'hidden',
// input.setAttribute('type', 'hidden') and input.attributes.type.value = 'hidden'
Y.Node.ATTRS.type = {
setter: function(val) {
if (val === 'hidden') {
try {
this._node.type = 'hidden';
} catch(e) {
this.setStyle('display', 'none');
this._inputType = 'hidden';
}
} else {
try { // IE errors when changing the type from "hidden'
this._node.type = val;
} catch (e) {
}
}
return val;
},
getter: function() {
return this._inputType || this._node.type;
},
_bypassProxy: true // don't update DOM when using with Attribute
};
if (Y.config.doc.createElement('form').elements.nodeType) {
// IE: elements collection is also FORM node which trips up scrubVal.
Y.Node.ATTRS.elements = {
getter: function() {
return this.all('input, textarea, button, select');
}
};
}
/**
* Provides methods for managing custom Node data.
*
* @module node
* @main node
* @submodule node-data
*/
Y.mix(Y.Node.prototype, {
_initData: function() {
if (! ('_data' in this)) {
this._data = {};
}
},
/**
* @method getData
* @for Node
* @description Retrieves arbitrary data stored on a Node instance.
* If no data is associated with the Node, it will attempt to retrieve
* a value from the corresponding HTML data attribute. (e.g. node.getData('foo')
* will check node.getAttribute('data-foo')).
* @param {string} name Optional name of the data field to retrieve.
* If no name is given, all data is returned.
* @return {any | Object} Whatever is stored at the given field,
* or an object hash of all fields.
*/
getData: function(name) {
this._initData();
var data = this._data,
ret = data;
if (arguments.length) { // single field
if (name in data) {
ret = data[name];
} else { // initialize from HTML attribute
ret = this._getDataAttribute(name);
}
} else if (typeof data == 'object' && data !== null) { // all fields
ret = {};
Y.Object.each(data, function(v, n) {
ret[n] = v;
});
ret = this._getDataAttributes(ret);
}
return ret;
},
_getDataAttributes: function(ret) {
ret = ret || {};
var i = 0,
attrs = this._node.attributes,
len = attrs.length,
prefix = this.DATA_PREFIX,
prefixLength = prefix.length,
name;
while (i < len) {
name = attrs[i].name;
if (name.indexOf(prefix) === 0) {
name = name.substr(prefixLength);
if (!(name in ret)) { // only merge if not already stored
ret[name] = this._getDataAttribute(name);
}
}
i += 1;
}
return ret;
},
_getDataAttribute: function(name) {
name = this.DATA_PREFIX + name;
var node = this._node,
attrs = node.attributes,
data = attrs && attrs[name] && attrs[name].value;
return data;
},
/**
* @method setData
* @for Node
* @description Stores arbitrary data on a Node instance.
* This is not stored with the DOM node.
* @param {string} name The name of the field to set. If no val
* is given, name is treated as the data and overrides any existing data.
* @param {any} val The value to be assigned to the field.
* @chainable
*/
setData: function(name, val) {
this._initData();
if (arguments.length > 1) {
this._data[name] = val;
} else {
this._data = name;
}
return this;
},
/**
* @method clearData
* @for Node
* @description Clears internally stored data.
* @param {string} name The name of the field to clear. If no name
* is given, all data is cleared.
* @chainable
*/
clearData: function(name) {
if ('_data' in this) {
if (typeof name != 'undefined') {
delete this._data[name];
} else {
delete this._data;
}
}
return this;
}
});
Y.mix(Y.NodeList.prototype, {
/**
* @method getData
* @for NodeList
* @description Retrieves arbitrary data stored on each Node instance
* bound to the NodeList.
* @see Node
* @param {string} name Optional name of the data field to retrieve.
* If no name is given, all data is returned.
* @return {Array} An array containing all of the data for each Node instance.
* or an object hash of all fields.
*/
getData: function(name) {
var args = (arguments.length) ? [name] : [];
return this._invoke('getData', args, true);
},
/**
* @method setData
* @for NodeList
* @description Stores arbitrary data on each Node instance bound to the
* NodeList. This is not stored with the DOM node.
* @param {string} name The name of the field to set. If no name
* is given, name is treated as the data and overrides any existing data.
* @param {any} val The value to be assigned to the field.
* @chainable
*/
setData: function(name, val) {
var args = (arguments.length > 1) ? [name, val] : [name];
return this._invoke('setData', args);
},
/**
* @method clearData
* @for NodeList
* @description Clears data on all Node instances bound to the NodeList.
* @param {string} name The name of the field to clear. If no name
* is given, all data is cleared.
* @chainable
*/
clearData: function(name) {
var args = (arguments.length) ? [name] : [];
return this._invoke('clearData', [name]);
}
});
}, 'patched-v3.11.0', {"requires": ["event-base", "node-core", "dom-base"]});
YUI.add('node-core', function (Y, NAME) {
/**
* The Node Utility provides a DOM-like interface for interacting with DOM nodes.
* @module node
* @main node
* @submodule node-core
*/
/**
* The Node class provides a wrapper for manipulating DOM Nodes.
* Node properties can be accessed via the set/get methods.
* Use `Y.one()` to retrieve Node instances.
*
* NOTE: Node properties are accessed using
* the set
and get
methods.
*
* @class Node
* @constructor
* @param {DOMNode} node the DOM node to be mapped to the Node instance.
* @uses EventTarget
*/
// "globals"
var DOT = '.',
NODE_NAME = 'nodeName',
NODE_TYPE = 'nodeType',
OWNER_DOCUMENT = 'ownerDocument',
TAG_NAME = 'tagName',
UID = '_yuid',
EMPTY_OBJ = {},
_slice = Array.prototype.slice,
Y_DOM = Y.DOM,
Y_Node = function(node) {
if (!this.getDOMNode) { // support optional "new"
return new Y_Node(node);
}
if (typeof node == 'string') {
node = Y_Node._fromString(node);
if (!node) {
return null; // NOTE: return
}
}
var uid = (node.nodeType !== 9) ? node.uniqueID : node[UID];
if (uid && Y_Node._instances[uid] && Y_Node._instances[uid]._node !== node) {
node[UID] = null; // unset existing uid to prevent collision (via clone or hack)
}
uid = uid || Y.stamp(node);
if (!uid) { // stamp failed; likely IE non-HTMLElement
uid = Y.guid();
}
this[UID] = uid;
/**
* The underlying DOM node bound to the Y.Node instance
* @property _node
* @type DOMNode
* @private
*/
this._node = node;
this._stateProxy = node; // when augmented with Attribute
if (this._initPlugins) { // when augmented with Plugin.Host
this._initPlugins();
}
},
// used with previous/next/ancestor tests
_wrapFn = function(fn) {
var ret = null;
if (fn) {
ret = (typeof fn == 'string') ?
function(n) {
return Y.Selector.test(n, fn);
} :
function(n) {
return fn(Y.one(n));
};
}
return ret;
};
// end "globals"
Y_Node.ATTRS = {};
Y_Node.DOM_EVENTS = {};
Y_Node._fromString = function(node) {
if (node) {
if (node.indexOf('doc') === 0) { // doc OR document
node = Y.config.doc;
} else if (node.indexOf('win') === 0) { // win OR window
node = Y.config.win;
} else {
node = Y.Selector.query(node, null, true);
}
}
return node || null;
};
/**
* The name of the component
* @static
* @type String
* @property NAME
*/
Y_Node.NAME = 'node';
/*
* The pattern used to identify ARIA attributes
*/
Y_Node.re_aria = /^(?:role$|aria-)/;
Y_Node.SHOW_TRANSITION = 'fadeIn';
Y_Node.HIDE_TRANSITION = 'fadeOut';
/**
* A list of Node instances that have been created
* @private
* @type Object
* @property _instances
* @static
*
*/
Y_Node._instances = {};
/**
* Retrieves the DOM node bound to a Node instance
* @method getDOMNode
* @static
*
* @param {Node | HTMLNode} node The Node instance or an HTMLNode
* @return {HTMLNode} The DOM node bound to the Node instance. If a DOM node is passed
* as the node argument, it is simply returned.
*/
Y_Node.getDOMNode = function(node) {
if (node) {
return (node.nodeType) ? node : node._node || null;
}
return null;
};
/**
* Checks Node return values and wraps DOM Nodes as Y.Node instances
* and DOM Collections / Arrays as Y.NodeList instances.
* Other return values just pass thru. If undefined is returned (e.g. no return)
* then the Node instance is returned for chainability.
* @method scrubVal
* @static
*
* @param {any} node The Node instance or an HTMLNode
* @return {Node | NodeList | Any} Depends on what is returned from the DOM node.
*/
Y_Node.scrubVal = function(val, node) {
if (val) { // only truthy values are risky
if (typeof val == 'object' || typeof val == 'function') { // safari nodeList === function
if (NODE_TYPE in val || Y_DOM.isWindow(val)) {// node || window
val = Y.one(val);
} else if ((val.item && !val._nodes) || // dom collection or Node instance
(val[0] && val[0][NODE_TYPE])) { // array of DOM Nodes
val = Y.all(val);
}
}
} else if (typeof val === 'undefined') {
val = node; // for chaining
} else if (val === null) {
val = null; // IE: DOM null not the same as null
}
return val;
};
/**
* Adds methods to the Y.Node prototype, routing through scrubVal.
* @method addMethod
* @static
*
* @param {String} name The name of the method to add
* @param {Function} fn The function that becomes the method
* @param {Object} context An optional context to call the method with
* (defaults to the Node instance)
* @return {any} Depends on what is returned from the DOM node.
*/
Y_Node.addMethod = function(name, fn, context) {
if (name && fn && typeof fn == 'function') {
Y_Node.prototype[name] = function() {
var args = _slice.call(arguments),
node = this,
ret;
if (args[0] && args[0]._node) {
args[0] = args[0]._node;
}
if (args[1] && args[1]._node) {
args[1] = args[1]._node;
}
args.unshift(node._node);
ret = fn.apply(node, args);
if (ret) { // scrub truthy
ret = Y_Node.scrubVal(ret, node);
}
(typeof ret != 'undefined') || (ret = node);
return ret;
};
} else {
}
};
/**
* Imports utility methods to be added as Y.Node methods.
* @method importMethod
* @static
*
* @param {Object} host The object that contains the method to import.
* @param {String} name The name of the method to import
* @param {String} altName An optional name to use in place of the host name
* @param {Object} context An optional context to call the method with
*/
Y_Node.importMethod = function(host, name, altName) {
if (typeof name == 'string') {
altName = altName || name;
Y_Node.addMethod(altName, host[name], host);
} else {
Y.Array.each(name, function(n) {
Y_Node.importMethod(host, n);
});
}
};
/**
* Retrieves a NodeList based on the given CSS selector.
* @method all
*
* @param {string} selector The CSS selector to test against.
* @return {NodeList} A NodeList instance for the matching HTMLCollection/Array.
* @for YUI
*/
/**
* Returns a single Node instance bound to the node or the
* first element matching the given selector. Returns null if no match found.
* Note: For chaining purposes you may want to
* use Y.all
, which returns a NodeList when no match is found.
* @method one
* @param {String | HTMLElement} node a node or Selector
* @return {Node | null} a Node instance or null if no match found.
* @for YUI
*/
/**
* Returns a single Node instance bound to the node or the
* first element matching the given selector. Returns null if no match found.
* Note: For chaining purposes you may want to
* use Y.all
, which returns a NodeList when no match is found.
* @method one
* @static
* @param {String | HTMLElement} node a node or Selector
* @return {Node | null} a Node instance or null if no match found.
* @for Node
*/
Y_Node.one = function(node) {
var instance = null,
cachedNode,
uid;
if (node) {
if (typeof node == 'string') {
node = Y_Node._fromString(node);
if (!node) {
return null; // NOTE: return
}
} else if (node.getDOMNode && Y.instanceOf(node, Y_Node)) {
return node; // NOTE: return
}
if (node.nodeType || Y.DOM.isWindow(node)) { // avoid bad input (numbers, boolean, etc)
uid = (node.uniqueID && node.nodeType !== 9) ? node.uniqueID : node._yuid;
instance = Y_Node._instances[uid]; // reuse exising instances
cachedNode = instance ? instance._node : null;
if (!instance || (cachedNode && node !== cachedNode)) { // new Node when nodes don't match
instance = new Y_Node(node);
if (node.nodeType != 11) { // dont cache document fragment
Y_Node._instances[instance[UID]] = instance; // cache node
}
}
}
}
return instance;
};
/**
* The default setter for DOM properties
* Called with instance context (this === the Node instance)
* @method DEFAULT_SETTER
* @static
* @param {String} name The attribute/property being set
* @param {any} val The value to be set
* @return {any} The value
*/
Y_Node.DEFAULT_SETTER = function(name, val) {
var node = this._stateProxy,
strPath;
if (name.indexOf(DOT) > -1) {
strPath = name;
name = name.split(DOT);
// only allow when defined on node
Y.Object.setValue(node, name, val);
} else if (typeof node[name] != 'undefined') { // pass thru DOM properties
node[name] = val;
}
return val;
};
/**
* The default getter for DOM properties
* Called with instance context (this === the Node instance)
* @method DEFAULT_GETTER
* @static
* @param {String} name The attribute/property to look up
* @return {any} The current value
*/
Y_Node.DEFAULT_GETTER = function(name) {
var node = this._stateProxy,
val;
if (name.indexOf && name.indexOf(DOT) > -1) {
val = Y.Object.getValue(node, name.split(DOT));
} else if (typeof node[name] != 'undefined') { // pass thru from DOM
val = node[name];
}
return val;
};
Y.mix(Y_Node.prototype, {
DATA_PREFIX: 'data-',
/**
* The method called when outputting Node instances as strings
* @method toString
* @return {String} A string representation of the Node instance
*/
toString: function() {
var str = this[UID] + ': not bound to a node',
node = this._node,
attrs, id, className;
if (node) {
attrs = node.attributes;
id = (attrs && attrs.id) ? node.getAttribute('id') : null;
className = (attrs && attrs.className) ? node.getAttribute('className') : null;
str = node[NODE_NAME];
if (id) {
str += '#' + id;
}
if (className) {
str += '.' + className.replace(' ', '.');
}
// TODO: add yuid?
str += ' ' + this[UID];
}
return str;
},
/**
* Returns an attribute value on the Node instance.
* Unless pre-configured (via `Node.ATTRS`), get hands
* off to the underlying DOM node. Only valid
* attributes/properties for the node will be queried.
* @method get
* @param {String} attr The attribute
* @return {any} The current value of the attribute
*/
get: function(attr) {
var val;
if (this._getAttr) { // use Attribute imple
val = this._getAttr(attr);
} else {
val = this._get(attr);
}
if (val) {
val = Y_Node.scrubVal(val, this);
} else if (val === null) {
val = null; // IE: DOM null is not true null (even though they ===)
}
return val;
},
/**
* Helper method for get.
* @method _get
* @private
* @param {String} attr The attribute
* @return {any} The current value of the attribute
*/
_get: function(attr) {
var attrConfig = Y_Node.ATTRS[attr],
val;
if (attrConfig && attrConfig.getter) {
val = attrConfig.getter.call(this);
} else if (Y_Node.re_aria.test(attr)) {
val = this._node.getAttribute(attr, 2);
} else {
val = Y_Node.DEFAULT_GETTER.apply(this, arguments);
}
return val;
},
/**
* Sets an attribute on the Node instance.
* Unless pre-configured (via Node.ATTRS), set hands
* off to the underlying DOM node. Only valid
* attributes/properties for the node will be set.
* To set custom attributes use setAttribute.
* @method set
* @param {String} attr The attribute to be set.
* @param {any} val The value to set the attribute to.
* @chainable
*/
set: function(attr, val) {
var attrConfig = Y_Node.ATTRS[attr];
if (this._setAttr) { // use Attribute imple
this._setAttr.apply(this, arguments);
} else { // use setters inline
if (attrConfig && attrConfig.setter) {
attrConfig.setter.call(this, val, attr);
} else if (Y_Node.re_aria.test(attr)) { // special case Aria
this._node.setAttribute(attr, val);
} else {
Y_Node.DEFAULT_SETTER.apply(this, arguments);
}
}
return this;
},
/**
* Sets multiple attributes.
* @method setAttrs
* @param {Object} attrMap an object of name/value pairs to set
* @chainable
*/
setAttrs: function(attrMap) {
if (this._setAttrs) { // use Attribute imple
this._setAttrs(attrMap);
} else { // use setters inline
Y.Object.each(attrMap, function(v, n) {
this.set(n, v);
}, this);
}
return this;
},
/**
* Returns an object containing the values for the requested attributes.
* @method getAttrs
* @param {Array} attrs an array of attributes to get values
* @return {Object} An object with attribute name/value pairs.
*/
getAttrs: function(attrs) {
var ret = {};
if (this._getAttrs) { // use Attribute imple
this._getAttrs(attrs);
} else { // use setters inline
Y.Array.each(attrs, function(v, n) {
ret[v] = this.get(v);
}, this);
}
return ret;
},
/**
* Compares nodes to determine if they match.
* Node instances can be compared to each other and/or HTMLElements.
* @method compareTo
* @param {HTMLElement | Node} refNode The reference node to compare to the node.
* @return {Boolean} True if the nodes match, false if they do not.
*/
compareTo: function(refNode) {
var node = this._node;
if (refNode && refNode._node) {
refNode = refNode._node;
}
return node === refNode;
},
/**
* Determines whether the node is appended to the document.
* @method inDoc
* @param {Node|HTMLElement} doc optional An optional document to check against.
* Defaults to current document.
* @return {Boolean} Whether or not this node is appended to the document.
*/
inDoc: function(doc) {
var node = this._node;
if (node) {
doc = (doc) ? doc._node || doc : node[OWNER_DOCUMENT];
if (doc.documentElement) {
return Y_DOM.contains(doc.documentElement, node);
}
}
return false;
},
getById: function(id) {
var node = this._node,
ret = Y_DOM.byId(id, node[OWNER_DOCUMENT]);
if (ret && Y_DOM.contains(node, ret)) {
ret = Y.one(ret);
} else {
ret = null;
}
return ret;
},
/**
* Returns the nearest ancestor that passes the test applied by supplied boolean method.
* @method ancestor
* @param {String | Function} fn A selector string or boolean method for testing elements.
* If a function is used, it receives the current node being tested as the only argument.
* If fn is not passed as an argument, the parent node will be returned.
* @param {Boolean} testSelf optional Whether or not to include the element in the scan
* @param {String | Function} stopFn optional A selector string or boolean
* method to indicate when the search should stop. The search bails when the function
* returns true or the selector matches.
* If a function is used, it receives the current node being tested as the only argument.
* @return {Node} The matching Node instance or null if not found
*/
ancestor: function(fn, testSelf, stopFn) {
// testSelf is optional, check for stopFn as 2nd arg
if (arguments.length === 2 &&
(typeof testSelf == 'string' || typeof testSelf == 'function')) {
stopFn = testSelf;
}
return Y.one(Y_DOM.ancestor(this._node, _wrapFn(fn), testSelf, _wrapFn(stopFn)));
},
/**
* Returns the ancestors that pass the test applied by supplied boolean method.
* @method ancestors
* @param {String | Function} fn A selector string or boolean method for testing elements.
* @param {Boolean} testSelf optional Whether or not to include the element in the scan
* If a function is used, it receives the current node being tested as the only argument.
* @return {NodeList} A NodeList instance containing the matching elements
*/
ancestors: function(fn, testSelf, stopFn) {
if (arguments.length === 2 &&
(typeof testSelf == 'string' || typeof testSelf == 'function')) {
stopFn = testSelf;
}
return Y.all(Y_DOM.ancestors(this._node, _wrapFn(fn), testSelf, _wrapFn(stopFn)));
},
/**
* Returns the previous matching sibling.
* Returns the nearest element node sibling if no method provided.
* @method previous
* @param {String | Function} fn A selector or boolean method for testing elements.
* If a function is used, it receives the current node being tested as the only argument.
* @return {Node} Node instance or null if not found
*/
previous: function(fn, all) {
return Y.one(Y_DOM.elementByAxis(this._node, 'previousSibling', _wrapFn(fn), all));
},
/**
* Returns the next matching sibling.
* Returns the nearest element node sibling if no method provided.
* @method next
* @param {String | Function} fn A selector or boolean method for testing elements.
* If a function is used, it receives the current node being tested as the only argument.
* @return {Node} Node instance or null if not found
*/
next: function(fn, all) {
return Y.one(Y_DOM.elementByAxis(this._node, 'nextSibling', _wrapFn(fn), all));
},
/**
* Returns all matching siblings.
* Returns all siblings if no method provided.
* @method siblings
* @param {String | Function} fn A selector or boolean method for testing elements.
* If a function is used, it receives the current node being tested as the only argument.
* @return {NodeList} NodeList instance bound to found siblings
*/
siblings: function(fn) {
return Y.all(Y_DOM.siblings(this._node, _wrapFn(fn)));
},
/**
* Retrieves a single Node instance, the first element matching the given
* CSS selector.
* Returns null if no match found.
* @method one
*
* @param {string} selector The CSS selector to test against.
* @return {Node | null} A Node instance for the matching HTMLElement or null
* if no match found.
*/
one: function(selector) {
return Y.one(Y.Selector.query(selector, this._node, true));
},
/**
* Retrieves a NodeList based on the given CSS selector.
* @method all
*
* @param {string} selector The CSS selector to test against.
* @return {NodeList} A NodeList instance for the matching HTMLCollection/Array.
*/
all: function(selector) {
var nodelist;
if (this._node) {
nodelist = Y.all(Y.Selector.query(selector, this._node));
nodelist._query = selector;
nodelist._queryRoot = this._node;
}
return nodelist || Y.all([]);
},
// TODO: allow fn test
/**
* Test if the supplied node matches the supplied selector.
* @method test
*
* @param {string} selector The CSS selector to test against.
* @return {boolean} Whether or not the node matches the selector.
*/
test: function(selector) {
return Y.Selector.test(this._node, selector);
},
/**
* Removes the node from its parent.
* Shortcut for myNode.get('parentNode').removeChild(myNode);
* @method remove
* @param {Boolean} destroy whether or not to call destroy() on the node
* after removal.
* @chainable
*
*/
remove: function(destroy) {
var node = this._node;
if (node && node.parentNode) {
node.parentNode.removeChild(node);
}
if (destroy) {
this.destroy();
}
return this;
},
/**
* Replace the node with the other node. This is a DOM update only
* and does not change the node bound to the Node instance.
* Shortcut for myNode.get('parentNode').replaceChild(newNode, myNode);
* @method replace
* @param {Node | HTMLNode} newNode Node to be inserted
* @chainable
*
*/
replace: function(newNode) {
var node = this._node;
if (typeof newNode == 'string') {
newNode = Y_Node.create(newNode);
}
node.parentNode.replaceChild(Y_Node.getDOMNode(newNode), node);
return this;
},
/**
* @method replaceChild
* @for Node
* @param {String | HTMLElement | Node} node Node to be inserted
* @param {HTMLElement | Node} refNode Node to be replaced
* @return {Node} The replaced node
*/
replaceChild: function(node, refNode) {
if (typeof node == 'string') {
node = Y_DOM.create(node);
}
return Y.one(this._node.replaceChild(Y_Node.getDOMNode(node), Y_Node.getDOMNode(refNode)));
},
/**
* Nulls internal node references, removes any plugins and event listeners.
* Note that destroy() will not remove the node from its parent or from the DOM. For that
* functionality, call remove(true).
* @method destroy
* @param {Boolean} recursivePurge (optional) Whether or not to remove listeners from the
* node's subtree (default is false)
*
*/
destroy: function(recursive) {
var UID = Y.config.doc.uniqueID ? 'uniqueID' : '_yuid',
instance;
this.purge(); // TODO: only remove events add via this Node
if (this.unplug) { // may not be a PluginHost
this.unplug();
}
this.clearData();
if (recursive) {
Y.NodeList.each(this.all('*'), function(node) {
instance = Y_Node._instances[node[UID]];
if (instance) {
instance.destroy();
} else { // purge in case added by other means
Y.Event.purgeElement(node);
}
});
}
this._node = null;
this._stateProxy = null;
delete Y_Node._instances[this._yuid];
},
/**
* Invokes a method on the Node instance
* @method invoke
* @param {String} method The name of the method to invoke
* @param {Any} a, b, c, etc. Arguments to invoke the method with.
* @return Whatever the underly method returns.
* DOM Nodes and Collections return values
* are converted to Node/NodeList instances.
*
*/
invoke: function(method, a, b, c, d, e) {
var node = this._node,
ret;
if (a && a._node) {
a = a._node;
}
if (b && b._node) {
b = b._node;
}
ret = node[method](a, b, c, d, e);
return Y_Node.scrubVal(ret, this);
},
/**
* @method swap
* @description Swap DOM locations with the given node.
* This does not change which DOM node each Node instance refers to.
* @param {Node} otherNode The node to swap with
* @chainable
*/
swap: Y.config.doc.documentElement.swapNode ?
function(otherNode) {
this._node.swapNode(Y_Node.getDOMNode(otherNode));
} :
function(otherNode) {
otherNode = Y_Node.getDOMNode(otherNode);
var node = this._node,
parent = otherNode.parentNode,
nextSibling = otherNode.nextSibling;
if (nextSibling === node) {
parent.insertBefore(node, otherNode);
} else if (otherNode === node.nextSibling) {
parent.insertBefore(otherNode, node);
} else {
node.parentNode.replaceChild(otherNode, node);
Y_DOM.addHTML(parent, node, nextSibling);
}
return this;
},
hasMethod: function(method) {
var node = this._node;
return !!(node && method in node &&
typeof node[method] != 'unknown' &&
(typeof node[method] == 'function' ||
String(node[method]).indexOf('function') === 1)); // IE reports as object, prepends space
},
isFragment: function() {
return (this.get('nodeType') === 11);
},
/**
* Removes and destroys all of the nodes within the node.
* @method empty
* @chainable
*/
empty: function() {
this.get('childNodes').remove().destroy(true);
return this;
},
/**
* Returns the DOM node bound to the Node instance
* @method getDOMNode
* @return {DOMNode}
*/
getDOMNode: function() {
return this._node;
}
}, true);
Y.Node = Y_Node;
Y.one = Y_Node.one;
/**
* The NodeList module provides support for managing collections of Nodes.
* @module node
* @submodule node-core
*/
/**
* The NodeList class provides a wrapper for manipulating DOM NodeLists.
* NodeList properties can be accessed via the set/get methods.
* Use Y.all() to retrieve NodeList instances.
*
* @class NodeList
* @constructor
* @param nodes {String|element|Node|Array} A selector, DOM element, Node, list of DOM elements, or list of Nodes with which to populate this NodeList.
*/
var NodeList = function(nodes) {
var tmp = [];
if (nodes) {
if (typeof nodes === 'string') { // selector query
this._query = nodes;
nodes = Y.Selector.query(nodes);
} else if (nodes.nodeType || Y_DOM.isWindow(nodes)) { // domNode || window
nodes = [nodes];
} else if (nodes._node) { // Y.Node
nodes = [nodes._node];
} else if (nodes[0] && nodes[0]._node) { // allow array of Y.Nodes
Y.Array.each(nodes, function(node) {
if (node._node) {
tmp.push(node._node);
}
});
nodes = tmp;
} else { // array of domNodes or domNodeList (no mixed array of Y.Node/domNodes)
nodes = Y.Array(nodes, 0, true);
}
}
/**
* The underlying array of DOM nodes bound to the Y.NodeList instance
* @property _nodes
* @private
*/
this._nodes = nodes || [];
};
NodeList.NAME = 'NodeList';
/**
* Retrieves the DOM nodes bound to a NodeList instance
* @method getDOMNodes
* @static
*
* @param {NodeList} nodelist The NodeList instance
* @return {Array} The array of DOM nodes bound to the NodeList
*/
NodeList.getDOMNodes = function(nodelist) {
return (nodelist && nodelist._nodes) ? nodelist._nodes : nodelist;
};
NodeList.each = function(instance, fn, context) {
var nodes = instance._nodes;
if (nodes && nodes.length) {
Y.Array.each(nodes, fn, context || instance);
} else {
}
};
NodeList.addMethod = function(name, fn, context) {
if (name && fn) {
NodeList.prototype[name] = function() {
var ret = [],
args = arguments;
Y.Array.each(this._nodes, function(node) {
var UID = (node.uniqueID && node.nodeType !== 9 ) ? 'uniqueID' : '_yuid',
instance = Y.Node._instances[node[UID]],
ctx,
result;
if (!instance) {
instance = NodeList._getTempNode(node);
}
ctx = context || instance;
result = fn.apply(ctx, args);
if (result !== undefined && result !== instance) {
ret[ret.length] = result;
}
});
// TODO: remove tmp pointer
return ret.length ? ret : this;
};
} else {
}
};
NodeList.importMethod = function(host, name, altName) {
if (typeof name === 'string') {
altName = altName || name;
NodeList.addMethod(name, host[name]);
} else {
Y.Array.each(name, function(n) {
NodeList.importMethod(host, n);
});
}
};
NodeList._getTempNode = function(node) {
var tmp = NodeList._tempNode;
if (!tmp) {
tmp = Y.Node.create('
');
NodeList._tempNode = tmp;
}
tmp._node = node;
tmp._stateProxy = node;
return tmp;
};
Y.mix(NodeList.prototype, {
_invoke: function(method, args, getter) {
var ret = (getter) ? [] : this;
this.each(function(node) {
var val = node[method].apply(node, args);
if (getter) {
ret.push(val);
}
});
return ret;
},
/**
* Retrieves the Node instance at the given index.
* @method item
*
* @param {Number} index The index of the target Node.
* @return {Node} The Node instance at the given index.
*/
item: function(index) {
return Y.one((this._nodes || [])[index]);
},
/**
* Applies the given function to each Node in the NodeList.
* @method each
* @param {Function} fn The function to apply. It receives 3 arguments:
* the current node instance, the node's index, and the NodeList instance
* @param {Object} context optional An optional context to apply the function with
* Default context is the current Node instance
* @chainable
*/
each: function(fn, context) {
var instance = this;
Y.Array.each(this._nodes, function(node, index) {
node = Y.one(node);
return fn.call(context || node, node, index, instance);
});
return instance;
},
batch: function(fn, context) {
var nodelist = this;
Y.Array.each(this._nodes, function(node, index) {
var instance = Y.Node._instances[node[UID]];
if (!instance) {
instance = NodeList._getTempNode(node);
}
return fn.call(context || instance, instance, index, nodelist);
});
return nodelist;
},
/**
* Executes the function once for each node until a true value is returned.
* @method some
* @param {Function} fn The function to apply. It receives 3 arguments:
* the current node instance, the node's index, and the NodeList instance
* @param {Object} context optional An optional context to execute the function from.
* Default context is the current Node instance
* @return {Boolean} Whether or not the function returned true for any node.
*/
some: function(fn, context) {
var instance = this;
return Y.Array.some(this._nodes, function(node, index) {
node = Y.one(node);
context = context || node;
return fn.call(context, node, index, instance);
});
},
/**
* Creates a documenFragment from the nodes bound to the NodeList instance
* @method toFrag
* @return {Node} a Node instance bound to the documentFragment
*/
toFrag: function() {
return Y.one(Y.DOM._nl2frag(this._nodes));
},
/**
* Returns the index of the node in the NodeList instance
* or -1 if the node isn't found.
* @method indexOf
* @param {Node | DOMNode} node the node to search for
* @return {Int} the index of the node value or -1 if not found
*/
indexOf: function(node) {
return Y.Array.indexOf(this._nodes, Y.Node.getDOMNode(node));
},
/**
* Filters the NodeList instance down to only nodes matching the given selector.
* @method filter
* @param {String} selector The selector to filter against
* @return {NodeList} NodeList containing the updated collection
* @see Selector
*/
filter: function(selector) {
return Y.all(Y.Selector.filter(this._nodes, selector));
},
/**
* Creates a new NodeList containing all nodes at every n indices, where
* remainder n % index equals r.
* (zero-based index).
* @method modulus
* @param {Int} n The offset to use (return every nth node)
* @param {Int} r An optional remainder to use with the modulus operation (defaults to zero)
* @return {NodeList} NodeList containing the updated collection
*/
modulus: function(n, r) {
r = r || 0;
var nodes = [];
NodeList.each(this, function(node, i) {
if (i % n === r) {
nodes.push(node);
}
});
return Y.all(nodes);
},
/**
* Creates a new NodeList containing all nodes at odd indices
* (zero-based index).
* @method odd
* @return {NodeList} NodeList containing the updated collection
*/
odd: function() {
return this.modulus(2, 1);
},
/**
* Creates a new NodeList containing all nodes at even indices
* (zero-based index), including zero.
* @method even
* @return {NodeList} NodeList containing the updated collection
*/
even: function() {
return this.modulus(2);
},
destructor: function() {
},
/**
* Reruns the initial query, when created using a selector query
* @method refresh
* @chainable
*/
refresh: function() {
var doc,
nodes = this._nodes,
query = this._query,
root = this._queryRoot;
if (query) {
if (!root) {
if (nodes && nodes[0] && nodes[0].ownerDocument) {
root = nodes[0].ownerDocument;
}
}
this._nodes = Y.Selector.query(query, root);
}
return this;
},
/**
* Returns the current number of items in the NodeList.
* @method size
* @return {Int} The number of items in the NodeList.
*/
size: function() {
return this._nodes.length;
},
/**
* Determines if the instance is bound to any nodes
* @method isEmpty
* @return {Boolean} Whether or not the NodeList is bound to any nodes
*/
isEmpty: function() {
return this._nodes.length < 1;
},
toString: function() {
var str = '',
errorMsg = this[UID] + ': not bound to any nodes',
nodes = this._nodes,
node;
if (nodes && nodes[0]) {
node = nodes[0];
str += node[NODE_NAME];
if (node.id) {
str += '#' + node.id;
}
if (node.className) {
str += '.' + node.className.replace(' ', '.');
}
if (nodes.length > 1) {
str += '...[' + nodes.length + ' items]';
}
}
return str || errorMsg;
},
/**
* Returns the DOM node bound to the Node instance
* @method getDOMNodes
* @return {Array}
*/
getDOMNodes: function() {
return this._nodes;
}
}, true);
NodeList.importMethod(Y.Node.prototype, [
/**
* Called on each Node instance. Nulls internal node references,
* removes any plugins and event listeners
* @method destroy
* @param {Boolean} recursivePurge (optional) Whether or not to
* remove listeners from the node's subtree (default is false)
* @see Node.destroy
*/
'destroy',
/**
* Called on each Node instance. Removes and destroys all of the nodes
* within the node
* @method empty
* @chainable
* @see Node.empty
*/
'empty',
/**
* Called on each Node instance. Removes the node from its parent.
* Shortcut for myNode.get('parentNode').removeChild(myNode);
* @method remove
* @param {Boolean} destroy whether or not to call destroy() on the node
* after removal.
* @chainable
* @see Node.remove
*/
'remove',
/**
* Called on each Node instance. Sets an attribute on the Node instance.
* Unless pre-configured (via Node.ATTRS), set hands
* off to the underlying DOM node. Only valid
* attributes/properties for the node will be set.
* To set custom attributes use setAttribute.
* @method set
* @param {String} attr The attribute to be set.
* @param {any} val The value to set the attribute to.
* @chainable
* @see Node.set
*/
'set'
]);
// one-off implementation to convert array of Nodes to NodeList
// e.g. Y.all('input').get('parentNode');
/** Called on each Node instance
* @method get
* @see Node
*/
NodeList.prototype.get = function(attr) {
var ret = [],
nodes = this._nodes,
isNodeList = false,
getTemp = NodeList._getTempNode,
instance,
val;
if (nodes[0]) {
instance = Y.Node._instances[nodes[0]._yuid] || getTemp(nodes[0]);
val = instance._get(attr);
if (val && val.nodeType) {
isNodeList = true;
}
}
Y.Array.each(nodes, function(node) {
instance = Y.Node._instances[node._yuid];
if (!instance) {
instance = getTemp(node);
}
val = instance._get(attr);
if (!isNodeList) { // convert array of Nodes to NodeList
val = Y.Node.scrubVal(val, instance);
}
ret.push(val);
});
return (isNodeList) ? Y.all(ret) : ret;
};
Y.NodeList = NodeList;
Y.all = function(nodes) {
return new NodeList(nodes);
};
Y.Node.all = Y.all;
/**
* @module node
* @submodule node-core
*/
var Y_NodeList = Y.NodeList,
ArrayProto = Array.prototype,
ArrayMethods = {
/** Returns a new NodeList combining the given NodeList(s)
* @for NodeList
* @method concat
* @param {NodeList | Array} valueN Arrays/NodeLists and/or values to
* concatenate to the resulting NodeList
* @return {NodeList} A new NodeList comprised of this NodeList joined with the input.
*/
'concat': 1,
/** Removes the last from the NodeList and returns it.
* @for NodeList
* @method pop
* @return {Node | null} The last item in the NodeList, or null if the list is empty.
*/
'pop': 0,
/** Adds the given Node(s) to the end of the NodeList.
* @for NodeList
* @method push
* @param {Node | DOMNode} nodes One or more nodes to add to the end of the NodeList.
*/
'push': 0,
/** Removes the first item from the NodeList and returns it.
* @for NodeList
* @method shift
* @return {Node | null} The first item in the NodeList, or null if the NodeList is empty.
*/
'shift': 0,
/** Returns a new NodeList comprising the Nodes in the given range.
* @for NodeList
* @method slice
* @param {Number} begin Zero-based index at which to begin extraction.
As a negative index, start indicates an offset from the end of the sequence. slice(-2) extracts the second-to-last element and the last element in the sequence.
* @param {Number} end Zero-based index at which to end extraction. slice extracts up to but not including end.
slice(1,4) extracts the second element through the fourth element (elements indexed 1, 2, and 3).
As a negative index, end indicates an offset from the end of the sequence. slice(2,-1) extracts the third element through the second-to-last element in the sequence.
If end is omitted, slice extracts to the end of the sequence.
* @return {NodeList} A new NodeList comprised of this NodeList joined with the input.
*/
'slice': 1,
/** Changes the content of the NodeList, adding new elements while removing old elements.
* @for NodeList
* @method splice
* @param {Number} index Index at which to start changing the array. If negative, will begin that many elements from the end.
* @param {Number} howMany An integer indicating the number of old array elements to remove. If howMany is 0, no elements are removed. In this case, you should specify at least one new element. If no howMany parameter is specified (second syntax above, which is a SpiderMonkey extension), all elements after index are removed.
* {Node | DOMNode| element1, ..., elementN
The elements to add to the array. If you don't specify any elements, splice simply removes elements from the array.
* @return {NodeList} The element(s) removed.
*/
'splice': 1,
/** Adds the given Node(s) to the beginning of the NodeList.
* @for NodeList
* @method unshift
* @param {Node | DOMNode} nodes One or more nodes to add to the NodeList.
*/
'unshift': 0
};
Y.Object.each(ArrayMethods, function(returnNodeList, name) {
Y_NodeList.prototype[name] = function() {
var args = [],
i = 0,
arg,
ret;
while (typeof (arg = arguments[i++]) != 'undefined') { // use DOM nodes/nodeLists
args.push(arg._node || arg._nodes || arg);
}
ret = ArrayProto[name].apply(this._nodes, args);
if (returnNodeList) {
ret = Y.all(ret);
} else {
ret = Y.Node.scrubVal(ret);
}
return ret;
};
});
/**
* @module node
* @submodule node-core
*/
Y.Array.each([
/**
* Passes through to DOM method.
* @for Node
* @method removeChild
* @param {HTMLElement | Node} node Node to be removed
* @return {Node} The removed node
*/
'removeChild',
/**
* Passes through to DOM method.
* @method hasChildNodes
* @return {Boolean} Whether or not the node has any childNodes
*/
'hasChildNodes',
/**
* Passes through to DOM method.
* @method cloneNode
* @param {Boolean} deep Whether or not to perform a deep clone, which includes
* subtree and attributes
* @return {Node} The clone
*/
'cloneNode',
/**
* Passes through to DOM method.
* @method hasAttribute
* @param {String} attribute The attribute to test for
* @return {Boolean} Whether or not the attribute is present
*/
'hasAttribute',
/**
* Passes through to DOM method.
* @method scrollIntoView
* @chainable
*/
'scrollIntoView',
/**
* Passes through to DOM method.
* @method getElementsByTagName
* @param {String} tagName The tagName to collect
* @return {NodeList} A NodeList representing the HTMLCollection
*/
'getElementsByTagName',
/**
* Passes through to DOM method.
* @method focus
* @chainable
*/
'focus',
/**
* Passes through to DOM method.
* @method blur
* @chainable
*/
'blur',
/**
* Passes through to DOM method.
* Only valid on FORM elements
* @method submit
* @chainable
*/
'submit',
/**
* Passes through to DOM method.
* Only valid on FORM elements
* @method reset
* @chainable
*/
'reset',
/**
* Passes through to DOM method.
* @method select
* @chainable
*/
'select',
/**
* Passes through to DOM method.
* Only valid on TABLE elements
* @method createCaption
* @chainable
*/
'createCaption'
], function(method) {
Y.Node.prototype[method] = function(arg1, arg2, arg3) {
var ret = this.invoke(method, arg1, arg2, arg3);
return ret;
};
});
/**
* Passes through to DOM method.
* @method removeAttribute
* @param {String} attribute The attribute to be removed
* @chainable
*/
// one-off implementation due to IE returning boolean, breaking chaining
Y.Node.prototype.removeAttribute = function(attr) {
var node = this._node;
if (node) {
node.removeAttribute(attr, 0); // comma zero for IE < 8 to force case-insensitive
}
return this;
};
Y.Node.importMethod(Y.DOM, [
/**
* Determines whether the node is an ancestor of another HTML element in the DOM hierarchy.
* @method contains
* @param {Node | HTMLElement} needle The possible node or descendent
* @return {Boolean} Whether or not this node is the needle its ancestor
*/
'contains',
/**
* Allows setting attributes on DOM nodes, normalizing in some cases.
* This passes through to the DOM node, allowing for custom attributes.
* @method setAttribute
* @for Node
* @chainable
* @param {string} name The attribute name
* @param {string} value The value to set
*/
'setAttribute',
/**
* Allows getting attributes on DOM nodes, normalizing in some cases.
* This passes through to the DOM node, allowing for custom attributes.
* @method getAttribute
* @for Node
* @param {string} name The attribute name
* @return {string} The attribute value
*/
'getAttribute',
/**
* Wraps the given HTML around the node.
* @method wrap
* @param {String} html The markup to wrap around the node.
* @chainable
* @for Node
*/
'wrap',
/**
* Removes the node's parent node.
* @method unwrap
* @chainable
*/
'unwrap',
/**
* Applies a unique ID to the node if none exists
* @method generateID
* @return {String} The existing or generated ID
*/
'generateID'
]);
Y.NodeList.importMethod(Y.Node.prototype, [
/**
* Allows getting attributes on DOM nodes, normalizing in some cases.
* This passes through to the DOM node, allowing for custom attributes.
* @method getAttribute
* @see Node
* @for NodeList
* @param {string} name The attribute name
* @return {string} The attribute value
*/
'getAttribute',
/**
* Allows setting attributes on DOM nodes, normalizing in some cases.
* This passes through to the DOM node, allowing for custom attributes.
* @method setAttribute
* @see Node
* @for NodeList
* @chainable
* @param {string} name The attribute name
* @param {string} value The value to set
*/
'setAttribute',
/**
* Allows for removing attributes on DOM nodes.
* This passes through to the DOM node, allowing for custom attributes.
* @method removeAttribute
* @see Node
* @for NodeList
* @param {string} name The attribute to remove
*/
'removeAttribute',
/**
* Removes the parent node from node in the list.
* @method unwrap
* @chainable
*/
'unwrap',
/**
* Wraps the given HTML around each node.
* @method wrap
* @param {String} html The markup to wrap around the node.
* @chainable
*/
'wrap',
/**
* Applies a unique ID to each node if none exists
* @method generateID
* @return {String} The existing or generated ID
*/
'generateID'
]);
}, 'patched-v3.11.0', {"requires": ["dom-core", "selector"]});
YUI.add('node-event-delegate', function (Y, NAME) {
/**
* Functionality to make the node a delegated event container
* @module node
* @submodule node-event-delegate
*/
/**
* Sets up a delegation listener for an event occurring inside the Node.
* The delegated event will be verified against a supplied selector or
* filtering function to test if the event references at least one node that
* should trigger the subscription callback.
*
* Selector string filters will trigger the callback if the event originated
* from a node that matches it or is contained in a node that matches it.
* Function filters are called for each Node up the parent axis to the
* subscribing container node, and receive at each level the Node and the event
* object. The function should return true (or a truthy value) if that Node
* should trigger the subscription callback. Note, it is possible for filters
* to match multiple Nodes for a single event. In this case, the delegate
* callback will be executed for each matching Node.
*
* For each matching Node, the callback will be executed with its 'this'
* object set to the Node matched by the filter (unless a specific context was
* provided during subscription), and the provided event's
* currentTarget
will also be set to the matching Node. The
* containing Node from which the subscription was originally made can be
* referenced as e.container
.
*
* @method delegate
* @param type {String} the event type to delegate
* @param fn {Function} the callback function to execute. This function
* will be provided the event object for the delegated event.
* @param spec {String|Function} a selector that must match the target of the
* event or a function to test target and its parents for a match
* @param context {Object} optional argument that specifies what 'this' refers to.
* @param args* {any} 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 Node
*/
Y.Node.prototype.delegate = function(type) {
var args = Y.Array(arguments, 0, true),
index = (Y.Lang.isObject(type) && !Y.Lang.isArray(type)) ? 1 : 2;
args.splice(index, 0, this._node);
return Y.delegate.apply(Y, args);
};
}, 'patched-v3.11.0', {"requires": ["node-base", "event-delegate"]});
YUI.add('node-event-simulate', function (Y, NAME) {
/**
* Adds functionality to simulate events.
* @module node
* @submodule node-event-simulate
*/
/**
* Simulates an event on the node.
* @param {String} type The type of event (i.e., "click").
* @param {Object} options (Optional) Extra options to copy onto the event object.
* @return {void}
* @for Node
* @method simulate
*/
Y.Node.prototype.simulate = function (type, options) {
Y.Event.simulate(Y.Node.getDOMNode(this), type, options);
};
/**
* Simulates the higher user level gesture of the given name on this node.
* This method generates a set of low level touch events(Apple specific gesture
* events as well for the iOS platforms) asynchronously. Note that gesture
* simulation is relying on `Y.Event.simulate()` method to generate
* the touch events under the hood. The `Y.Event.simulate()` method
* itself is a synchronous method.
*
* Supported gestures are `tap`, `doubletap`, `press`, `move`, `flick`, `pinch`
* and `rotate`.
*
* The `pinch` gesture is used to simulate the pinching and spreading of two
* fingers. During a pinch simulation, rotation is also possible. Essentially
* `pinch` and `rotate` simulations share the same base implementation to allow
* both pinching and rotation at the same time. The only difference is `pinch`
* requires `start` and `end` option properties while `rotate` requires `rotation`
* option property.
*
* The `pinch` and `rotate` gestures can be described as placing 2 fingers along a
* circle. Pinching and spreading can be described by start and end circles while
* rotation occurs on a single circle. If the radius of the start circle is greater
* than the end circle, the gesture becomes a pinch, otherwise it is a spread spread.
*
* @example
*
* var node = Y.one("#target");
*
* // double tap example
* node.simulateGesture("doubletap", function() {
* // my callback function
* });
*
* // flick example from the center of the node, move 50 pixels down for 50ms)
* node.simulateGesture("flick", {
* axis: y,
* distance: -100
* duration: 50
* }, function() {
* // my callback function
* });
*
* // simulate rotating a node 75 degrees counter-clockwise
* node.simulateGesture("rotate", {
* rotation: -75
* });
*
* // simulate a pinch and a rotation at the same time.
* // fingers start on a circle of radius 100 px, placed at top/bottom
* // fingers end on a circle of radius 50px, placed at right/left
* node.simulateGesture("pinch", {
* r1: 100,
* r2: 50,
* start: 0
* rotation: 90
* });
*
* @method simulateGesture
* @param {String} name The name of the supported gesture to simulate. The
* supported gesture name is one of "tap", "doubletap", "press", "move",
* "flick", "pinch" and "rotate".
* @param {Object} [options] Extra options used to define the gesture behavior:
*
* Valid options properties for the `tap` gesture:
*
* @param {Array} [options.point] (Optional) Indicates the [x,y] coordinates
* where the tap should be simulated. Default is the center of the node
* element.
* @param {Number} [options.hold=10] (Optional) The hold time in milliseconds.
* This is the time between `touchstart` and `touchend` event generation.
* @param {Number} [options.times=1] (Optional) Indicates the number of taps.
* @param {Number} [options.delay=10] (Optional) The number of milliseconds
* before the next tap simulation happens. This is valid only when `times`
* is more than 1.
*
* Valid options properties for the `doubletap` gesture:
*
* @param {Array} [options.point] (Optional) Indicates the [x,y] coordinates
* where the doubletap should be simulated. Default is the center of the
* node element.
*
* Valid options properties for the `press` gesture:
*
* @param {Array} [options.point] (Optional) Indicates the [x,y] coordinates
* where the press should be simulated. Default is the center of the node
* element.
* @param {Number} [options.hold=3000] (Optional) The hold time in milliseconds.
* This is the time between `touchstart` and `touchend` event generation.
* Default is 3000ms (3 seconds).
*
* Valid options properties for the `move` gesture:
*
* @param {Object} [options.path] (Optional) Indicates the path of the finger
* movement. It's an object with three optional properties: `point`,
* `xdist` and `ydist`.
* @param {Array} [options.path.point] A starting point of the gesture.
* Default is the center of the node element.
* @param {Number} [options.path.xdist=200] A distance to move in pixels
* along the X axis. A negative distance value indicates moving left.
* @param {Number} [options.path.ydist=0] A distance to move in pixels
* along the Y axis. A negative distance value indicates moving up.
* @param {Number} [options.duration=1000] (Optional) The duration of the
* gesture in milliseconds.
*
* Valid options properties for the `flick` gesture:
*
* @param {Array} [options.point] (Optional) Indicates the [x, y] coordinates
* where the flick should be simulated. Default is the center of the
* node element.
* @param {String} [options.axis='x'] (Optional) Valid values are either
* "x" or "y". Indicates axis to move along. The flick can move to one of
* 4 directions(left, right, up and down).
* @param {Number} [options.distance=200] (Optional) Distance to move in pixels
* @param {Number} [options.duration=1000] (Optional) The duration of the
* gesture in milliseconds. User given value could be automatically
* adjusted by the framework if it is below the minimum velocity to be
* a flick gesture.
*
* Valid options properties for the `pinch` gesture:
*
* @param {Array} [options.center] (Optional) The center of the circle where
* two fingers are placed. Default is the center of the node element.
* @param {Number} [options.r1] (Required) Pixel radius of the start circle
* where 2 fingers will be on when the gesture starts. The circles are
* centered at the center of the element.
* @param {Number} [options.r2] (Required) Pixel radius of the end circle
* when this gesture ends.
* @param {Number} [options.duration=1000] (Optional) The duration of the
* gesture in milliseconds.
* @param {Number} [options.start=0] (Optional) Starting degree of the first
* finger. The value is relative to the path of the north. Default is 0
* (i.e., 12:00 on a clock).
* @param {Number} [options.rotation=0] (Optional) Degrees to rotate from
* the starting degree. A negative value means rotation to the
* counter-clockwise direction.
*
* Valid options properties for the `rotate` gesture:
*
* @param {Array} [options.center] (Optional) The center of the circle where
* two fingers are placed. Default is the center of the node element.
* @param {Number} [options.r1] (Optional) Pixel radius of the start circle
* where 2 fingers will be on when the gesture starts. The circles are
* centered at the center of the element. Default is a fourth of the node
* element width or height, whichever is smaller.
* @param {Number} [options.r2] (Optional) Pixel radius of the end circle
* when this gesture ends. Default is a fourth of the node element width or
* height, whichever is smaller.
* @param {Number} [options.duration=1000] (Optional) The duration of the
* gesture in milliseconds.
* @param {Number} [options.start=0] (Optional) Starting degree of the first
* finger. The value is relative to the path of the north. Default is 0
* (i.e., 12:00 on a clock).
* @param {Number} [options.rotation] (Required) Degrees to rotate from
* the starting degree. A negative value means rotation to the
* counter-clockwise direction.
*
* @param {Function} [cb] The callback to execute when the asynchronouse gesture
* simulation is completed.
* @param {Error} cb.err An error object if the simulation is failed.
* @return {void}
* @for Node
*/
Y.Node.prototype.simulateGesture = function (name, options, cb) {
Y.Event.simulateGesture(this, name, options, cb);
};
}, 'patched-v3.11.0', {"requires": ["node-base", "event-simulate", "gesture-simulate"]});
YUI.add('node-focusmanager', function (Y, NAME) {
/**
*
The Focus Manager Node Plugin makes it easy to manage focus among
* a Node's descendants. Primarily intended to help with widget development,
* the Focus Manager Node Plugin can be used to improve the keyboard
* accessibility of widgets.
*
*
* When designing widgets that manage a set of descendant controls (i.e. buttons
* in a toolbar, tabs in a tablist, menuitems in a menu, etc.) it is important to
* limit the number of descendants in the browser's default tab flow. The fewer
* number of descendants in the default tab flow, the easier it is for keyboard
* users to navigate between widgets by pressing the tab key. When a widget has
* focus it should provide a set of shortcut keys (typically the arrow keys)
* to move focus among its descendants.
*
*
*
* To this end, the Focus Manager Node Plugin makes it easy to define a Node's
* focusable descendants, define which descendant should be in the default tab
* flow, and define the keys that move focus among each descendant.
* Additionally, as the CSS
* :focus
* pseudo class is not supported on all elements in all
* A-Grade browsers ,
* the Focus Manager Node Plugin provides an easy, cross-browser means of
* styling focus.
*
*
DEPRECATED: The FocusManager Node Plugin has been deprecated as of YUI 3.9.0. This module will be removed from the library in a future version. If you require functionality similar to the one provided by this module, consider taking a look at the various modules in the YUI Gallery .
* @module node-focusmanager
* @deprecated 3.9.0
*/
// Frequently used strings
var ACTIVE_DESCENDANT = "activeDescendant",
ID = "id",
DISABLED = "disabled",
TAB_INDEX = "tabIndex",
FOCUSED = "focused",
FOCUS_CLASS = "focusClass",
CIRCULAR = "circular",
UI = "UI",
KEY = "key",
ACTIVE_DESCENDANT_CHANGE = ACTIVE_DESCENDANT + "Change",
HOST = "host",
// Collection of keys that, when pressed, cause the browser viewport
// to scroll.
scrollKeys = {
37: true,
38: true,
39: true,
40: true
},
clickableElements = {
"a": true,
"button": true,
"input": true,
"object": true
},
// Library shortcuts
Lang = Y.Lang,
UA = Y.UA,
/**
* The NodeFocusManager class is a plugin for a Node instance. The class is used
* via the plug
method of Node
* and should not be instantiated directly.
* @namespace plugin
* @class NodeFocusManager
*/
NodeFocusManager = function () {
NodeFocusManager.superclass.constructor.apply(this, arguments);
};
NodeFocusManager.ATTRS = {
/**
* Boolean indicating that one of the descendants is focused.
*
* @attribute focused
* @readOnly
* @default false
* @type boolean
*/
focused: {
value: false,
readOnly: true
},
/**
* String representing the CSS selector used to define the descendant Nodes
* whose focus should be managed.
*
* @attribute descendants
* @type Y.NodeList
*/
descendants: {
getter: function (value) {
return this.get(HOST).all(value);
}
},
/**
* Node, or index of the Node, representing the descendant that is either
* focused or is focusable (tabIndex
attribute is set to 0).
* The value cannot represent a disabled descendant Node. Use a value of -1
* to remove all descendant Nodes from the default tab flow.
* If no value is specified, the active descendant will be inferred using
* the following criteria:
*
* Examining the tabIndex
attribute of each descendant and
* using the first descendant whose tabIndex
attribute is set
* to 0
* If no default can be inferred then the value is set to either 0 or
* the index of the first enabled descendant.
*
*
* @attribute activeDescendant
* @type Number
*/
activeDescendant: {
setter: function (value) {
var isNumber = Lang.isNumber,
INVALID_VALUE = Y.Attribute.INVALID_VALUE,
descendantsMap = this._descendantsMap,
descendants = this._descendants,
nodeIndex,
returnValue,
oNode;
if (isNumber(value)) {
nodeIndex = value;
returnValue = nodeIndex;
}
else if ((value instanceof Y.Node) && descendantsMap) {
nodeIndex = descendantsMap[value.get(ID)];
if (isNumber(nodeIndex)) {
returnValue = nodeIndex;
}
else {
// The user passed a reference to a Node that wasn't one
// of the descendants.
returnValue = INVALID_VALUE;
}
}
else {
returnValue = INVALID_VALUE;
}
if (descendants) {
oNode = descendants.item(nodeIndex);
if (oNode && oNode.get("disabled")) {
// Setting the "activeDescendant" attribute to the index
// of a disabled descendant is invalid.
returnValue = INVALID_VALUE;
}
}
return returnValue;
}
},
/**
* Object literal representing the keys to be used to navigate between the
* next/previous descendant. The format for the attribute's value is
* { next: "down:40", previous: "down:38" }
. The value for the
* "next" and "previous" properties are used to attach
* key
event listeners. See
* the Using the key Event section of
* the Event documentation for more information on "key" event listeners.
*
* @attribute keys
* @type Object
*/
keys: {
value: {
next: null,
previous: null
}
},
/**
* String representing the name of class applied to the focused active
* descendant Node. Can also be an object literal used to define both the
* class name, and the Node to which the class should be applied. If using
* an object literal, the format is:
* { className: "focus", fn: myFunction }
. The function
* referenced by the fn
property in the object literal will be
* passed a reference to the currently focused active descendant Node.
*
* @attribute focusClass
* @type String|Object
*/
focusClass: { },
/**
* Boolean indicating if focus should be set to the first/last descendant
* when the end or beginning of the descendants has been reached.
*
* @attribute circular
* @type Boolean
* @default true
*/
circular: {
value: true
}
};
Y.extend(NodeFocusManager, Y.Plugin.Base, {
// Protected properties
// Boolean indicating if the NodeFocusManager is active.
_stopped: true,
// NodeList representing the descendants selected via the
// "descendants" attribute.
_descendants: null,
// Object literal mapping the IDs of each descendant to its index in the
// "_descendants" NodeList.
_descendantsMap: null,
// Reference to the Node instance to which the focused class (defined
// by the "focusClass" attribute) is currently applied.
_focusedNode: null,
// Number representing the index of the last descendant Node.
_lastNodeIndex: 0,
// Array of handles for event handlers used for a NodeFocusManager instance.
_eventHandlers: null,
// Protected methods
/**
* @method _initDescendants
* @description Sets the tabIndex
attribute of all of the
* descendants to -1, except the active descendant, whose
* tabIndex
attribute is set to 0.
* @protected
*/
_initDescendants: function () {
var descendants = this.get("descendants"),
descendantsMap = {},
nFirstEnabled = -1,
nDescendants,
nActiveDescendant = this.get(ACTIVE_DESCENDANT),
oNode,
sID,
i = 0;
if (Lang.isUndefined(nActiveDescendant)) {
nActiveDescendant = -1;
}
if (descendants) {
nDescendants = descendants.size();
for (i = 0; i < nDescendants; i++) {
oNode = descendants.item(i);
if (nFirstEnabled === -1 && !oNode.get(DISABLED)) {
nFirstEnabled = i;
}
// If the user didn't specify a value for the
// "activeDescendant" attribute try to infer it from
// the markup.
// Need to pass "2" when using "getAttribute" for IE to get
// the attribute value as it is set in the markup.
// Need to use "parseInt" because IE always returns the
// value as a number, whereas all other browsers return
// the attribute as a string when accessed
// via "getAttribute".
if (nActiveDescendant < 0 &&
parseInt(oNode.getAttribute(TAB_INDEX, 2), 10) === 0) {
nActiveDescendant = i;
}
if (oNode) {
oNode.set(TAB_INDEX, -1);
}
sID = oNode.get(ID);
if (!sID) {
sID = Y.guid();
oNode.set(ID, sID);
}
descendantsMap[sID] = i;
}
// If the user didn't specify a value for the
// "activeDescendant" attribute and no default value could be
// determined from the markup, then default to 0.
if (nActiveDescendant < 0) {
nActiveDescendant = 0;
}
oNode = descendants.item(nActiveDescendant);
// Check to make sure the active descendant isn't disabled,
// and fall back to the first enabled descendant if it is.
if (!oNode || oNode.get(DISABLED)) {
oNode = descendants.item(nFirstEnabled);
nActiveDescendant = nFirstEnabled;
}
this._lastNodeIndex = nDescendants - 1;
this._descendants = descendants;
this._descendantsMap = descendantsMap;
this.set(ACTIVE_DESCENDANT, nActiveDescendant);
// Need to set the "tabIndex" attribute here, since the
// "activeDescendantChange" event handler used to manage
// the setting of the "tabIndex" attribute isn't wired up yet.
if (oNode) {
oNode.set(TAB_INDEX, 0);
}
}
},
/**
* @method _isDescendant
* @description Determines if the specified Node instance is a descendant
* managed by the Focus Manager.
* @param node {Node} Node instance to be checked.
* @return {Boolean} Boolean indicating if the specified Node instance is a
* descendant managed by the Focus Manager.
* @protected
*/
_isDescendant: function (node) {
return (node.get(ID) in this._descendantsMap);
},
/**
* @method _removeFocusClass
* @description Removes the class name representing focus (as specified by
* the "focusClass" attribute) from the Node instance to which it is
* currently applied.
* @protected
*/
_removeFocusClass: function () {
var oFocusedNode = this._focusedNode,
focusClass = this.get(FOCUS_CLASS),
sClassName;
if (focusClass) {
sClassName = Lang.isString(focusClass) ?
focusClass : focusClass.className;
}
if (oFocusedNode && sClassName) {
oFocusedNode.removeClass(sClassName);
}
},
/**
* @method _detachKeyHandler
* @description Detaches the "key" event handlers used to support the "keys"
* attribute.
* @protected
*/
_detachKeyHandler: function () {
var prevKeyHandler = this._prevKeyHandler,
nextKeyHandler = this._nextKeyHandler;
if (prevKeyHandler) {
prevKeyHandler.detach();
}
if (nextKeyHandler) {
nextKeyHandler.detach();
}
},
/**
* @method _preventScroll
* @description Prevents the viewport from scolling when the user presses
* the up, down, left, or right key.
* @protected
*/
_preventScroll: function (event) {
if (scrollKeys[event.keyCode] && this._isDescendant(event.target)) {
event.preventDefault();
}
},
/**
* @method _fireClick
* @description Fires the click event if the enter key is pressed while
* focused on an HTML element that is not natively clickable.
* @protected
*/
_fireClick: function (event) {
var oTarget = event.target,
sNodeName = oTarget.get("nodeName").toLowerCase();
if (event.keyCode === 13 && (!clickableElements[sNodeName] ||
(sNodeName === "a" && !oTarget.getAttribute("href")))) {
oTarget.simulate("click");
}
},
/**
* @method _attachKeyHandler
* @description Attaches the "key" event handlers used to support the "keys"
* attribute.
* @protected
*/
_attachKeyHandler: function () {
this._detachKeyHandler();
var sNextKey = this.get("keys.next"),
sPrevKey = this.get("keys.previous"),
oNode = this.get(HOST),
aHandlers = this._eventHandlers;
if (sPrevKey) {
this._prevKeyHandler =
Y.on(KEY, Y.bind(this._focusPrevious, this), oNode, sPrevKey);
}
if (sNextKey) {
this._nextKeyHandler =
Y.on(KEY, Y.bind(this._focusNext, this), oNode, sNextKey);
}
// In Opera it is necessary to call the "preventDefault" method in
// response to the user pressing the arrow keys in order to prevent
// the viewport from scrolling when the user is moving focus among
// the focusable descendants.
if (UA.opera) {
aHandlers.push(oNode.on("keypress", this._preventScroll, this));
}
// For all browsers except Opera: HTML elements that are not natively
// focusable but made focusable via the tabIndex attribute don't
// fire a click event when the user presses the enter key. It is
// possible to work around this problem by simplying dispatching a
// click event in response to the user pressing the enter key.
if (!UA.opera) {
aHandlers.push(oNode.on("keypress", this._fireClick, this));
}
},
/**
* @method _detachEventHandlers
* @description Detaches all event handlers used by the Focus Manager.
* @protected
*/
_detachEventHandlers: function () {
this._detachKeyHandler();
var aHandlers = this._eventHandlers;
if (aHandlers) {
Y.Array.each(aHandlers, function (handle) {
handle.detach();
});
this._eventHandlers = null;
}
},
/**
* @method _detachEventHandlers
* @description Attaches all event handlers used by the Focus Manager.
* @protected
*/
_attachEventHandlers: function () {
var descendants = this._descendants,
aHandlers,
oDocument,
handle;
if (descendants && descendants.size()) {
aHandlers = this._eventHandlers || [];
oDocument = this.get(HOST).get("ownerDocument");
if (aHandlers.length === 0) {
aHandlers.push(oDocument.on("focus", this._onDocFocus, this));
aHandlers.push(oDocument.on("mousedown",
this._onDocMouseDown, this));
aHandlers.push(
this.after("keysChange", this._attachKeyHandler));
aHandlers.push(
this.after("descendantsChange", this._initDescendants));
aHandlers.push(
this.after(ACTIVE_DESCENDANT_CHANGE,
this._afterActiveDescendantChange));
// For performance: defer attaching all key-related event
// handlers until the first time one of the specified
// descendants receives focus.
handle = this.after("focusedChange", Y.bind(function (event) {
if (event.newVal) {
this._attachKeyHandler();
// Detach this "focusedChange" handler so that the
// key-related handlers only get attached once.
handle.detach();
}
}, this));
aHandlers.push(handle);
}
this._eventHandlers = aHandlers;
}
},
// Protected event handlers
/**
* @method _onDocMouseDown
* @description "mousedown" event handler for the owner document of the
* Focus Manager's Node.
* @protected
* @param event {Object} Object representing the DOM event.
*/
_onDocMouseDown: function (event) {
var oHost = this.get(HOST),
oTarget = event.target,
bChildNode = oHost.contains(oTarget),
node,
getFocusable = function (node) {
var returnVal = false;
if (!node.compareTo(oHost)) {
returnVal = this._isDescendant(node) ? node :
getFocusable.call(this, node.get("parentNode"));
}
return returnVal;
};
if (bChildNode) {
// Check to make sure that the target isn't a child node of one
// of the focusable descendants.
node = getFocusable.call(this, oTarget);
if (node) {
oTarget = node;
}
else if (!node && this.get(FOCUSED)) {
// The target was a non-focusable descendant of the root
// node, so the "focused" attribute should be set to false.
this._set(FOCUSED, false);
this._onDocFocus(event);
}
}
if (bChildNode && this._isDescendant(oTarget)) {
// Fix general problem in Webkit: mousing down on a button or an
// anchor element doesn't focus it.
// For all browsers: makes sure that the descendant that
// was the target of the mousedown event is now considered the
// active descendant.
this.focus(oTarget);
}
else if (UA.webkit && this.get(FOCUSED) &&
(!bChildNode || (bChildNode && !this._isDescendant(oTarget)))) {
// Fix for Webkit:
// Document doesn't receive focus in Webkit when the user mouses
// down on it, so the "focused" attribute won't get set to the
// correct value.
// The goal is to force a blur if the user moused down on
// either: 1) A descendant node, but not one that managed by
// the FocusManager, or 2) an element outside of the
// FocusManager
this._set(FOCUSED, false);
this._onDocFocus(event);
}
},
/**
* @method _onDocFocus
* @description "focus" event handler for the owner document of the
* Focus Manager's Node.
* @protected
* @param event {Object} Object representing the DOM event.
*/
_onDocFocus: function (event) {
var oTarget = this._focusTarget || event.target,
bFocused = this.get(FOCUSED),
focusClass = this.get(FOCUS_CLASS),
oFocusedNode = this._focusedNode,
bInCollection;
if (this._focusTarget) {
this._focusTarget = null;
}
if (this.get(HOST).contains(oTarget)) {
// The target is a descendant of the root Node.
bInCollection = this._isDescendant(oTarget);
if (!bFocused && bInCollection) {
// The user has focused a focusable descendant.
bFocused = true;
}
else if (bFocused && !bInCollection) {
// The user has focused a child of the root Node that is
// not one of the descendants managed by this Focus Manager
// so clear the currently focused descendant.
bFocused = false;
}
}
else {
// The target is some other node in the document.
bFocused = false;
}
if (focusClass) {
if (oFocusedNode && (!oFocusedNode.compareTo(oTarget) || !bFocused)) {
this._removeFocusClass();
}
if (bInCollection && bFocused) {
if (focusClass.fn) {
oTarget = focusClass.fn(oTarget);
oTarget.addClass(focusClass.className);
}
else {
oTarget.addClass(focusClass);
}
this._focusedNode = oTarget;
}
}
this._set(FOCUSED, bFocused);
},
/**
* @method _focusNext
* @description Keydown event handler that moves focus to the next
* enabled descendant.
* @protected
* @param event {Object} Object representing the DOM event.
* @param activeDescendant {Number} Number representing the index of the
* next descendant to be focused
*/
_focusNext: function (event, activeDescendant) {
var nActiveDescendant = activeDescendant || this.get(ACTIVE_DESCENDANT),
oNode;
if (this._isDescendant(event.target) &&
(nActiveDescendant <= this._lastNodeIndex)) {
nActiveDescendant = nActiveDescendant + 1;
if (nActiveDescendant === (this._lastNodeIndex + 1) &&
this.get(CIRCULAR)) {
nActiveDescendant = 0;
}
oNode = this._descendants.item(nActiveDescendant);
if (oNode) {
if (oNode.get("disabled")) {
this._focusNext(event, nActiveDescendant);
}
else {
this.focus(nActiveDescendant);
}
}
}
this._preventScroll(event);
},
/**
* @method _focusPrevious
* @description Keydown event handler that moves focus to the previous
* enabled descendant.
* @protected
* @param event {Object} Object representing the DOM event.
* @param activeDescendant {Number} Number representing the index of the
* next descendant to be focused.
*/
_focusPrevious: function (event, activeDescendant) {
var nActiveDescendant = activeDescendant || this.get(ACTIVE_DESCENDANT),
oNode;
if (this._isDescendant(event.target) && nActiveDescendant >= 0) {
nActiveDescendant = nActiveDescendant - 1;
if (nActiveDescendant === -1 && this.get(CIRCULAR)) {
nActiveDescendant = this._lastNodeIndex;
}
oNode = this._descendants.item(nActiveDescendant);
if (oNode) {
if (oNode.get("disabled")) {
this._focusPrevious(event, nActiveDescendant);
}
else {
this.focus(nActiveDescendant);
}
}
}
this._preventScroll(event);
},
/**
* @method _afterActiveDescendantChange
* @description afterChange event handler for the
* "activeDescendant" attribute.
* @protected
* @param event {Object} Object representing the change event.
*/
_afterActiveDescendantChange: function (event) {
var oNode = this._descendants.item(event.prevVal);
if (oNode) {
oNode.set(TAB_INDEX, -1);
}
oNode = this._descendants.item(event.newVal);
if (oNode) {
oNode.set(TAB_INDEX, 0);
}
},
// Public methods
initializer: function (config) {
this.start();
},
destructor: function () {
this.stop();
this.get(HOST).focusManager = null;
},
/**
* @method focus
* @description Focuses the active descendant and sets the
* focused
attribute to true.
* @param index {Number} Optional. Number representing the index of the
* descendant to be set as the active descendant.
* @param index {Node} Optional. Node instance representing the
* descendant to be set as the active descendant.
*/
focus: function (index) {
if (Lang.isUndefined(index)) {
index = this.get(ACTIVE_DESCENDANT);
}
this.set(ACTIVE_DESCENDANT, index, { src: UI });
var oNode = this._descendants.item(this.get(ACTIVE_DESCENDANT));
if (oNode) {
oNode.focus();
// In Opera focusing a element programmatically
// will result in the document-level focus event handler
// "_onDocFocus" being called, resulting in the handler
// incorrectly setting the "focused" Attribute to false. To fix
// this, set a flag ("_focusTarget") that the "_onDocFocus" method
// can look for to properly handle this edge case.
if (UA.opera && oNode.get("nodeName").toLowerCase() === "button") {
this._focusTarget = oNode;
}
}
},
/**
* @method blur
* @description Blurs the current active descendant and sets the
* focused
attribute to false.
*/
blur: function () {
var oNode;
if (this.get(FOCUSED)) {
oNode = this._descendants.item(this.get(ACTIVE_DESCENDANT));
if (oNode) {
oNode.blur();
// For Opera and Webkit: Blurring an element in either browser
// doesn't result in another element (such as the document)
// being focused. Therefore, the "_onDocFocus" method
// responsible for managing the application and removal of the
// focus indicator class name is never called.
this._removeFocusClass();
}
this._set(FOCUSED, false, { src: UI });
}
},
/**
* @method start
* @description Enables the Focus Manager.
*/
start: function () {
if (this._stopped) {
this._initDescendants();
this._attachEventHandlers();
this._stopped = false;
}
},
/**
* @method stop
* @description Disables the Focus Manager by detaching all event handlers.
*/
stop: function () {
if (!this._stopped) {
this._detachEventHandlers();
this._descendants = null;
this._focusedNode = null;
this._lastNodeIndex = 0;
this._stopped = true;
}
},
/**
* @method refresh
* @description Refreshes the Focus Manager's descendants by re-executing the
* CSS selector query specified by the descendants
attribute.
*/
refresh: function () {
this._initDescendants();
if (!this._eventHandlers) {
this._attachEventHandlers();
}
}
});
NodeFocusManager.NAME = "nodeFocusManager";
NodeFocusManager.NS = "focusManager";
Y.namespace("Plugin");
Y.Plugin.NodeFocusManager = NodeFocusManager;
}, 'patched-v3.11.0', {"requires": ["attribute", "node", "plugin", "node-event-simulate", "event-key", "event-focus"]});
YUI.add('node-pluginhost', function (Y, NAME) {
/**
* @module node
* @submodule node-pluginhost
*/
/**
* Registers plugins to be instantiated at the class level (plugins
* which should be plugged into every instance of Node by default).
*
* @method plug
* @static
* @for Node
* @param {Function | Array} plugin Either the plugin class, an array of plugin classes or an array of objects (with fn and cfg properties defined)
* @param {Object} config (Optional) If plugin is the plugin class, the configuration for the plugin
*/
Y.Node.plug = function() {
var args = Y.Array(arguments);
args.unshift(Y.Node);
Y.Plugin.Host.plug.apply(Y.Base, args);
return Y.Node;
};
/**
* Unregisters any class level plugins which have been registered by the Node
*
* @method unplug
* @static
*
* @param {Function | Array} plugin The plugin class, or an array of plugin classes
*/
Y.Node.unplug = function() {
var args = Y.Array(arguments);
args.unshift(Y.Node);
Y.Plugin.Host.unplug.apply(Y.Base, args);
return Y.Node;
};
Y.mix(Y.Node, Y.Plugin.Host, false, null, 1);
// allow batching of plug/unplug via NodeList
// doesn't use NodeList.importMethod because we need real Nodes (not tmpNode)
/**
* Adds a plugin to each node in the NodeList.
* This will instantiate the plugin and attach it to the configured namespace on each node
* @method plug
* @for NodeList
* @param P {Function | Object |Array} Accepts the plugin class, or an
* object with a "fn" property specifying the plugin class and
* a "cfg" property specifying the configuration for the Plugin.
*
* Additionally an Array can also be passed in, with the above function or
* object values, allowing the user to add multiple plugins in a single call.
*
* @param config (Optional) If the first argument is the plugin class, the second argument
* can be the configuration for the plugin.
* @chainable
*/
Y.NodeList.prototype.plug = function() {
var args = arguments;
Y.NodeList.each(this, function(node) {
Y.Node.prototype.plug.apply(Y.one(node), args);
});
return this;
};
/**
* Removes a plugin from all nodes in the NodeList. This will destroy the
* plugin instance and delete the namespace each node.
* @method unplug
* @for NodeList
* @param {String | Function} plugin The namespace of the plugin, or the plugin class with the static NS namespace property defined. If not provided,
* all registered plugins are unplugged.
* @chainable
*/
Y.NodeList.prototype.unplug = function() {
var args = arguments;
Y.NodeList.each(this, function(node) {
Y.Node.prototype.unplug.apply(Y.one(node), args);
});
return this;
};
}, 'patched-v3.11.0', {"requires": ["node-base", "pluginhost"]});
YUI.add('node-screen', function (Y, NAME) {
/**
* Extended Node interface for managing regions and screen positioning.
* Adds support for positioning elements and normalizes window size and scroll detection.
* @module node
* @submodule node-screen
*/
// these are all "safe" returns, no wrapping required
Y.each([
/**
* Returns the inner width of the viewport (exludes scrollbar).
* @config winWidth
* @for Node
* @type {Int}
*/
'winWidth',
/**
* Returns the inner height of the viewport (exludes scrollbar).
* @config winHeight
* @type {Int}
*/
'winHeight',
/**
* Document width
* @config docWidth
* @type {Int}
*/
'docWidth',
/**
* Document height
* @config docHeight
* @type {Int}
*/
'docHeight',
/**
* Pixel distance the page has been scrolled horizontally
* @config docScrollX
* @type {Int}
*/
'docScrollX',
/**
* Pixel distance the page has been scrolled vertically
* @config docScrollY
* @type {Int}
*/
'docScrollY'
],
function(name) {
Y.Node.ATTRS[name] = {
getter: function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(Y.Node.getDOMNode(this));
return Y.DOM[name].apply(this, args);
}
};
}
);
Y.Node.ATTRS.scrollLeft = {
getter: function() {
var node = Y.Node.getDOMNode(this);
return ('scrollLeft' in node) ? node.scrollLeft : Y.DOM.docScrollX(node);
},
setter: function(val) {
var node = Y.Node.getDOMNode(this);
if (node) {
if ('scrollLeft' in node) {
node.scrollLeft = val;
} else if (node.document || node.nodeType === 9) {
Y.DOM._getWin(node).scrollTo(val, Y.DOM.docScrollY(node)); // scroll window if win or doc
}
} else {
}
}
};
Y.Node.ATTRS.scrollTop = {
getter: function() {
var node = Y.Node.getDOMNode(this);
return ('scrollTop' in node) ? node.scrollTop : Y.DOM.docScrollY(node);
},
setter: function(val) {
var node = Y.Node.getDOMNode(this);
if (node) {
if ('scrollTop' in node) {
node.scrollTop = val;
} else if (node.document || node.nodeType === 9) {
Y.DOM._getWin(node).scrollTo(Y.DOM.docScrollX(node), val); // scroll window if win or doc
}
} else {
}
}
};
Y.Node.importMethod(Y.DOM, [
/**
* Gets the current position of the node in page coordinates.
* @method getXY
* @for Node
* @return {Array} The XY position of the node
*/
'getXY',
/**
* Set the position of the node in page coordinates, regardless of how the node is positioned.
* @method setXY
* @param {Array} xy Contains X & Y values for new position (coordinates are page-based)
* @chainable
*/
'setXY',
/**
* Gets the current position of the node in page coordinates.
* @method getX
* @return {Int} The X position of the node
*/
'getX',
/**
* Set the position of the node in page coordinates, regardless of how the node is positioned.
* @method setX
* @param {Int} x X value for new position (coordinates are page-based)
* @chainable
*/
'setX',
/**
* Gets the current position of the node in page coordinates.
* @method getY
* @return {Int} The Y position of the node
*/
'getY',
/**
* Set the position of the node in page coordinates, regardless of how the node is positioned.
* @method setY
* @param {Int} y Y value for new position (coordinates are page-based)
* @chainable
*/
'setY',
/**
* Swaps the XY position of this node with another node.
* @method swapXY
* @param {Node | HTMLElement} otherNode The node to swap with.
* @chainable
*/
'swapXY'
]);
/**
* @module node
* @submodule node-screen
*/
/**
* Returns a region object for the node
* @config region
* @for Node
* @type Node
*/
Y.Node.ATTRS.region = {
getter: function() {
var node = this.getDOMNode(),
region;
if (node && !node.tagName) {
if (node.nodeType === 9) { // document
node = node.documentElement;
}
}
if (Y.DOM.isWindow(node)) {
region = Y.DOM.viewportRegion(node);
} else {
region = Y.DOM.region(node);
}
return region;
}
};
/**
* Returns a region object for the node's viewport
* @config viewportRegion
* @type Node
*/
Y.Node.ATTRS.viewportRegion = {
getter: function() {
return Y.DOM.viewportRegion(Y.Node.getDOMNode(this));
}
};
Y.Node.importMethod(Y.DOM, 'inViewportRegion');
// these need special treatment to extract 2nd node arg
/**
* Compares the intersection of the node with another node or region
* @method intersect
* @for Node
* @param {Node|Object} node2 The node or region to compare with.
* @param {Object} altRegion An alternate region to use (rather than this node's).
* @return {Object} An object representing the intersection of the regions.
*/
Y.Node.prototype.intersect = function(node2, altRegion) {
var node1 = Y.Node.getDOMNode(this);
if (Y.instanceOf(node2, Y.Node)) { // might be a region object
node2 = Y.Node.getDOMNode(node2);
}
return Y.DOM.intersect(node1, node2, altRegion);
};
/**
* Determines whether or not the node is within the giving region.
* @method inRegion
* @param {Node|Object} node2 The node or region to compare with.
* @param {Boolean} all Whether or not all of the node must be in the region.
* @param {Object} altRegion An alternate region to use (rather than this node's).
* @return {Boolean} True if in region, false if not.
*/
Y.Node.prototype.inRegion = function(node2, all, altRegion) {
var node1 = Y.Node.getDOMNode(this);
if (Y.instanceOf(node2, Y.Node)) { // might be a region object
node2 = Y.Node.getDOMNode(node2);
}
return Y.DOM.inRegion(node1, node2, all, altRegion);
};
}, 'patched-v3.11.0', {"requires": ["dom-screen", "node-base"]});
YUI.add('node-style', function (Y, NAME) {
(function(Y) {
/**
* Extended Node interface for managing node styles.
* @module node
* @submodule node-style
*/
Y.mix(Y.Node.prototype, {
/**
* Sets a style property of the node.
* Use camelCase (e.g. 'backgroundColor') for multi-word properties.
* @method setStyle
* @param {String} attr The style attribute to set.
* @param {String|Number} val The value.
* @chainable
*/
setStyle: function(attr, val) {
Y.DOM.setStyle(this._node, attr, val);
return this;
},
/**
* Sets multiple style properties on the node.
* Use camelCase (e.g. 'backgroundColor') for multi-word properties.
* @method setStyles
* @param {Object} hash An object literal of property:value pairs.
* @chainable
*/
setStyles: function(hash) {
Y.DOM.setStyles(this._node, hash);
return this;
},
/**
* Returns the style's current value.
* Use camelCase (e.g. 'backgroundColor') for multi-word properties.
* @method getStyle
* @for Node
* @param {String} attr The style attribute to retrieve.
* @return {String} The current value of the style property for the element.
*/
getStyle: function(attr) {
return Y.DOM.getStyle(this._node, attr);
},
/**
* Returns the computed value for the given style property.
* Use camelCase (e.g. 'backgroundColor') for multi-word properties.
* @method getComputedStyle
* @param {String} attr The style attribute to retrieve.
* @return {String} The computed value of the style property for the element.
*/
getComputedStyle: function(attr) {
return Y.DOM.getComputedStyle(this._node, attr);
}
});
/**
* Returns an array of values for each node.
* Use camelCase (e.g. 'backgroundColor') for multi-word properties.
* @method getStyle
* @for NodeList
* @see Node.getStyle
* @param {String} attr The style attribute to retrieve.
* @return {Array} The current values of the style property for the element.
*/
/**
* Returns an array of the computed value for each node.
* Use camelCase (e.g. 'backgroundColor') for multi-word properties.
* @method getComputedStyle
* @see Node.getComputedStyle
* @param {String} attr The style attribute to retrieve.
* @return {Array} The computed values for each node.
*/
/**
* Sets a style property on each node.
* Use camelCase (e.g. 'backgroundColor') for multi-word properties.
* @method setStyle
* @see Node.setStyle
* @param {String} attr The style attribute to set.
* @param {String|Number} val The value.
* @chainable
*/
/**
* Sets multiple style properties on each node.
* Use camelCase (e.g. 'backgroundColor') for multi-word properties.
* @method setStyles
* @see Node.setStyles
* @param {Object} hash An object literal of property:value pairs.
* @chainable
*/
// These are broken out to handle undefined return (avoid false positive for
// chainable)
Y.NodeList.importMethod(Y.Node.prototype, ['getStyle', 'getComputedStyle', 'setStyle', 'setStyles']);
})(Y);
}, 'patched-v3.11.0', {"requires": ["dom-style", "node-base"]});
YUI.add('oop', function (Y, NAME) {
/**
Adds object inheritance and manipulation utilities to the YUI instance. This
module is required by most YUI components.
@module oop
**/
var L = Y.Lang,
A = Y.Array,
OP = Object.prototype,
CLONE_MARKER = '_~yuim~_',
hasOwn = OP.hasOwnProperty,
toString = OP.toString;
function dispatch(o, f, c, proto, action) {
if (o && o[action] && o !== Y) {
return o[action].call(o, f, c);
} else {
switch (A.test(o)) {
case 1:
return A[action](o, f, c);
case 2:
return A[action](Y.Array(o, 0, true), f, c);
default:
return Y.Object[action](o, f, c, proto);
}
}
}
/**
Augments the _receiver_ with prototype properties from the _supplier_. The
receiver may be a constructor function or an object. The supplier must be a
constructor function.
If the _receiver_ is an object, then the _supplier_ constructor will be called
immediately after _receiver_ is augmented, with _receiver_ as the `this` object.
If the _receiver_ is a constructor function, then all prototype methods of
_supplier_ that are copied to _receiver_ will be sequestered, and the
_supplier_ constructor will not be called immediately. The first time any
sequestered method is called on the _receiver_'s prototype, all sequestered
methods will be immediately copied to the _receiver_'s prototype, the
_supplier_'s constructor will be executed, and finally the newly unsequestered
method that was called will be executed.
This sequestering logic sounds like a bunch of complicated voodoo, but it makes
it cheap to perform frequent augmentation by ensuring that suppliers'
constructors are only called if a supplied method is actually used. If none of
the supplied methods is ever used, then there's no need to take the performance
hit of calling the _supplier_'s constructor.
@method augment
@param {Function|Object} receiver Object or function to be augmented.
@param {Function} supplier Function that supplies the prototype properties with
which to augment the _receiver_.
@param {Boolean} [overwrite=false] If `true`, properties already on the receiver
will be overwritten if found on the supplier's prototype.
@param {String[]} [whitelist] An array of property names. If specified,
only the whitelisted prototype properties will be applied to the receiver, and
all others will be ignored.
@param {Array|any} [args] Argument or array of arguments to pass to the
supplier's constructor when initializing.
@return {Function} Augmented object.
@for YUI
**/
Y.augment = function (receiver, supplier, overwrite, whitelist, args) {
var rProto = receiver.prototype,
sequester = rProto && supplier,
sProto = supplier.prototype,
to = rProto || receiver,
copy,
newPrototype,
replacements,
sequestered,
unsequester;
args = args ? Y.Array(args) : [];
if (sequester) {
newPrototype = {};
replacements = {};
sequestered = {};
copy = function (value, key) {
if (overwrite || !(key in rProto)) {
if (toString.call(value) === '[object Function]') {
sequestered[key] = value;
newPrototype[key] = replacements[key] = function () {
return unsequester(this, value, arguments);
};
} else {
newPrototype[key] = value;
}
}
};
unsequester = function (instance, fn, fnArgs) {
// Unsequester all sequestered functions.
for (var key in sequestered) {
if (hasOwn.call(sequestered, key)
&& instance[key] === replacements[key]) {
instance[key] = sequestered[key];
}
}
// Execute the supplier constructor.
supplier.apply(instance, args);
// Finally, execute the original sequestered function.
return fn.apply(instance, fnArgs);
};
if (whitelist) {
Y.Array.each(whitelist, function (name) {
if (name in sProto) {
copy(sProto[name], name);
}
});
} else {
Y.Object.each(sProto, copy, null, true);
}
}
Y.mix(to, newPrototype || sProto, overwrite, whitelist);
if (!sequester) {
supplier.apply(to, args);
}
return receiver;
};
/**
* Copies object properties from the supplier to the receiver. If the target has
* the property, and the property is an object, the target object will be
* augmented with the supplier's value.
*
* @method aggregate
* @param {Object} receiver Object to receive the augmentation.
* @param {Object} supplier Object that supplies the properties with which to
* augment the receiver.
* @param {Boolean} [overwrite=false] If `true`, properties already on the receiver
* will be overwritten if found on the supplier.
* @param {String[]} [whitelist] Whitelist. If supplied, only properties in this
* list will be applied to the receiver.
* @return {Object} Augmented object.
*/
Y.aggregate = function(r, s, ov, wl) {
return Y.mix(r, s, ov, wl, 0, true);
};
/**
* Utility to set up the prototype, constructor and superclass properties to
* support an inheritance strategy that can chain constructors and methods.
* Static members will not be inherited.
*
* @method extend
* @param {function} r the object to modify.
* @param {function} s the object to inherit.
* @param {object} px prototype properties to add/override.
* @param {object} sx static properties to add/override.
* @return {object} the extended object.
*/
Y.extend = function(r, s, px, sx) {
if (!s || !r) {
Y.error('extend failed, verify dependencies');
}
var sp = s.prototype, rp = Y.Object(sp);
r.prototype = rp;
rp.constructor = r;
r.superclass = sp;
// assign constructor property
if (s != Object && sp.constructor == OP.constructor) {
sp.constructor = s;
}
// add prototype overrides
if (px) {
Y.mix(rp, px, true);
}
// add object overrides
if (sx) {
Y.mix(r, sx, true);
}
return r;
};
/**
* Executes the supplied function for each item in
* a collection. Supports arrays, objects, and
* NodeLists
* @method each
* @param {object} o the object to iterate.
* @param {function} f the function to execute. This function
* receives the value, key, and object as parameters.
* @param {object} c the execution context for the function.
* @param {boolean} proto if true, prototype properties are
* iterated on objects.
* @return {YUI} the YUI instance.
*/
Y.each = function(o, f, c, proto) {
return dispatch(o, f, c, proto, 'each');
};
/**
* Executes the supplied function for each item in
* a collection. The operation stops if the function
* returns true. Supports arrays, objects, and
* NodeLists.
* @method some
* @param {object} o the object to iterate.
* @param {function} f the function to execute. This function
* receives the value, key, and object as parameters.
* @param {object} c the execution context for the function.
* @param {boolean} proto if true, prototype properties are
* iterated on objects.
* @return {boolean} true if the function ever returns true,
* false otherwise.
*/
Y.some = function(o, f, c, proto) {
return dispatch(o, f, c, proto, 'some');
};
/**
Deep object/array copy. Function clones are actually wrappers around the
original function. Array-like objects are treated as arrays. Primitives are
returned untouched. Optionally, a function can be provided to handle other data
types, filter keys, validate values, etc.
**Note:** Cloning a non-trivial object is a reasonably heavy operation, due to
the need to recursively iterate down non-primitive properties. Clone should be
used only when a deep clone down to leaf level properties is explicitly
required. This method will also
In many cases (for example, when trying to isolate objects used as hashes for
configuration properties), a shallow copy, using `Y.merge()` is normally
sufficient. If more than one level of isolation is required, `Y.merge()` can be
used selectively at each level which needs to be isolated from the original
without going all the way to leaf properties.
@method clone
@param {object} o what to clone.
@param {boolean} safe if true, objects will not have prototype items from the
source. If false, they will. In this case, the original is initially
protected, but the clone is not completely immune from changes to the source
object prototype. Also, cloned prototype items that are deleted from the
clone will result in the value of the source prototype being exposed. If
operating on a non-safe clone, items should be nulled out rather than
deleted.
@param {function} f optional function to apply to each item in a collection; it
will be executed prior to applying the value to the new object.
Return false to prevent the copy.
@param {object} c optional execution context for f.
@param {object} owner Owner object passed when clone is iterating an object.
Used to set up context for cloned functions.
@param {object} cloned hash of previously cloned objects to avoid multiple
clones.
@return {Array|Object} the cloned object.
**/
Y.clone = function(o, safe, f, c, owner, cloned) {
var o2, marked, stamp;
// Does not attempt to clone:
//
// * Non-typeof-object values, "primitive" values don't need cloning.
//
// * YUI instances, cloning complex object like YUI instances is not
// advised, this is like cloning the world.
//
// * DOM nodes (#2528250), common host objects like DOM nodes cannot be
// "subclassed" in Firefox and old versions of IE. Trying to use
// `Object.create()` or `Y.extend()` on a DOM node will throw an error in
// these browsers.
//
// Instad, the passed-in `o` will be return as-is when it matches one of the
// above criteria.
if (!L.isObject(o) ||
Y.instanceOf(o, YUI) ||
(o.addEventListener || o.attachEvent)) {
return o;
}
marked = cloned || {};
switch (L.type(o)) {
case 'date':
return new Date(o);
case 'regexp':
// if we do this we need to set the flags too
// return new RegExp(o.source);
return o;
case 'function':
// o2 = Y.bind(o, owner);
// break;
return o;
case 'array':
o2 = [];
break;
default:
// #2528250 only one clone of a given object should be created.
if (o[CLONE_MARKER]) {
return marked[o[CLONE_MARKER]];
}
stamp = Y.guid();
o2 = (safe) ? {} : Y.Object(o);
o[CLONE_MARKER] = stamp;
marked[stamp] = o;
}
Y.each(o, function(v, k) {
if ((k || k === 0) && (!f || (f.call(c || this, v, k, this, o) !== false))) {
if (k !== CLONE_MARKER) {
if (k == 'prototype') {
// skip the prototype
// } else if (o[k] === o) {
// this[k] = this;
} else {
this[k] =
Y.clone(v, safe, f, c, owner || o, marked);
}
}
}
}, o2);
if (!cloned) {
Y.Object.each(marked, function(v, k) {
if (v[CLONE_MARKER]) {
try {
delete v[CLONE_MARKER];
} catch (e) {
v[CLONE_MARKER] = null;
}
}
}, this);
marked = null;
}
return o2;
};
/**
* Returns a function that will execute the supplied function in the
* supplied object's context, optionally adding any additional
* supplied parameters to the beginning of the arguments collection the
* supplied to the function.
*
* @method bind
* @param {Function|String} f the function to bind, or a function name
* to execute on the context object.
* @param {object} c the execution context.
* @param {any} args* 0..n arguments to include before the arguments the
* function is executed with.
* @return {function} the wrapped function.
*/
Y.bind = function(f, c) {
var xargs = arguments.length > 2 ?
Y.Array(arguments, 2, true) : null;
return function() {
var fn = L.isString(f) ? c[f] : f,
args = (xargs) ?
xargs.concat(Y.Array(arguments, 0, true)) : arguments;
return fn.apply(c || fn, args);
};
};
/**
* Returns a function that will execute the supplied function in the
* supplied object's context, optionally adding any additional
* supplied parameters to the end of the arguments the function
* is executed with.
*
* @method rbind
* @param {Function|String} f the function to bind, or a function name
* to execute on the context object.
* @param {object} c the execution context.
* @param {any} args* 0..n arguments to append to the end of
* arguments collection supplied to the function.
* @return {function} the wrapped function.
*/
Y.rbind = function(f, c) {
var xargs = arguments.length > 2 ? Y.Array(arguments, 2, true) : null;
return function() {
var fn = L.isString(f) ? c[f] : f,
args = (xargs) ?
Y.Array(arguments, 0, true).concat(xargs) : arguments;
return fn.apply(c || fn, args);
};
};
}, 'patched-v3.11.0', {"requires": ["yui-base"]});
YUI.add('plugin', function (Y, NAME) {
/**
* Provides the base Plugin class, which plugin developers should extend, when creating custom plugins
*
* @module plugin
*/
/**
* The base class for all Plugin instances.
*
* @class Plugin.Base
* @extends Base
* @param {Object} config Configuration object with property name/value pairs.
*/
function Plugin(config) {
if (! (this.hasImpl && this.hasImpl(Y.Plugin.Base)) ) {
Plugin.superclass.constructor.apply(this, arguments);
} else {
Plugin.prototype.initializer.apply(this, arguments);
}
}
/**
* Object defining the set of attributes supported by the Plugin.Base class
*
* @property ATTRS
* @type Object
* @static
*/
Plugin.ATTRS = {
/**
* The plugin's host object.
*
* @attribute host
* @writeonce
* @type Plugin.Host
*/
host : {
writeOnce: true
}
};
/**
* The string identifying the Plugin.Base class. Plugins extending
* Plugin.Base should set their own NAME value.
*
* @property NAME
* @type String
* @static
*/
Plugin.NAME = 'plugin';
/**
* The name of the property the the plugin will be attached to
* when plugged into a Plugin Host. Plugins extending Plugin.Base,
* should set their own NS value.
*
* @property NS
* @type String
* @static
*/
Plugin.NS = 'plugin';
Y.extend(Plugin, Y.Base, {
/**
* The list of event handles for event listeners or AOP injected methods
* applied by the plugin to the host object.
*
* @property _handles
* @private
* @type Array
* @value null
*/
_handles: null,
/**
* Initializer lifecycle implementation.
*
* @method initializer
* @param {Object} config Configuration object with property name/value pairs.
*/
initializer : function(config) {
this._handles = [];
},
/**
* Destructor lifecycle implementation.
*
* Removes any event listeners or injected methods applied by the Plugin
*
* @method destructor
*/
destructor: function() {
// remove all handles
if (this._handles) {
for (var i = 0, l = this._handles.length; i < l; i++) {
this._handles[i].detach();
}
}
},
/**
* Listens for the "on" moment of events fired by the host,
* or injects code "before" a given method on the host.
*
* @method doBefore
*
* @param strMethod {String} The event to listen for, or method to inject logic before.
* @param fn {Function} The handler function. For events, the "on" moment listener. For methods, the function to execute before the given method is executed.
* @param context {Object} An optional context to call the handler with. The default context is the plugin instance.
* @return handle {EventHandle} The detach handle for the handler.
*/
doBefore: function(strMethod, fn, context) {
var host = this.get("host"), handle;
if (strMethod in host) { // method
handle = this.beforeHostMethod(strMethod, fn, context);
} else if (host.on) { // event
handle = this.onHostEvent(strMethod, fn, context);
}
return handle;
},
/**
* Listens for the "after" moment of events fired by the host,
* or injects code "after" a given method on the host.
*
* @method doAfter
*
* @param strMethod {String} The event to listen for, or method to inject logic after.
* @param fn {Function} The handler function. For events, the "after" moment listener. For methods, the function to execute after the given method is executed.
* @param context {Object} An optional context to call the handler with. The default context is the plugin instance.
* @return handle {EventHandle} The detach handle for the listener.
*/
doAfter: function(strMethod, fn, context) {
var host = this.get("host"), handle;
if (strMethod in host) { // method
handle = this.afterHostMethod(strMethod, fn, context);
} else if (host.after) { // event
handle = this.afterHostEvent(strMethod, fn, context);
}
return handle;
},
/**
* Listens for the "on" moment of events fired by the host object.
*
* Listeners attached through this method will be detached when the plugin is unplugged.
*
* @method onHostEvent
* @param {String | Object} type The event type.
* @param {Function} fn The listener.
* @param {Object} context The execution context. Defaults to the plugin instance.
* @return handle {EventHandle} The detach handle for the listener.
*/
onHostEvent : function(type, fn, context) {
var handle = this.get("host").on(type, fn, context || this);
this._handles.push(handle);
return handle;
},
/**
* Listens for the "on" moment of events fired by the host object one time only.
* The listener is immediately detached when it is executed.
*
* Listeners attached through this method will be detached when the plugin is unplugged.
*
* @method onceHostEvent
* @param {String | Object} type The event type.
* @param {Function} fn The listener.
* @param {Object} context The execution context. Defaults to the plugin instance.
* @return handle {EventHandle} The detach handle for the listener.
*/
onceHostEvent : function(type, fn, context) {
var handle = this.get("host").once(type, fn, context || this);
this._handles.push(handle);
return handle;
},
/**
* Listens for the "after" moment of events fired by the host object.
*
* Listeners attached through this method will be detached when the plugin is unplugged.
*
* @method afterHostEvent
* @param {String | Object} type The event type.
* @param {Function} fn The listener.
* @param {Object} context The execution context. Defaults to the plugin instance.
* @return handle {EventHandle} The detach handle for the listener.
*/
afterHostEvent : function(type, fn, context) {
var handle = this.get("host").after(type, fn, context || this);
this._handles.push(handle);
return handle;
},
/**
* Listens for the "after" moment of events fired by the host object one time only.
* The listener is immediately detached when it is executed.
*
* Listeners attached through this method will be detached when the plugin is unplugged.
*
* @method onceAfterHostEvent
* @param {String | Object} type The event type.
* @param {Function} fn The listener.
* @param {Object} context The execution context. Defaults to the plugin instance.
* @return handle {EventHandle} The detach handle for the listener.
*/
onceAfterHostEvent : function(type, fn, context) {
var handle = this.get("host").onceAfter(type, fn, context || this);
this._handles.push(handle);
return handle;
},
/**
* Injects a function to be executed before a given method on host object.
*
* The function will be detached when the plugin is unplugged.
*
* @method beforeHostMethod
* @param {String} method The name of the method to inject the function before.
* @param {Function} fn The function to inject.
* @param {Object} context The execution context. Defaults to the plugin instance.
* @return handle {EventHandle} The detach handle for the injected function.
*/
beforeHostMethod : function(strMethod, fn, context) {
var handle = Y.Do.before(fn, this.get("host"), strMethod, context || this);
this._handles.push(handle);
return handle;
},
/**
* Injects a function to be executed after a given method on host object.
*
* The function will be detached when the plugin is unplugged.
*
* @method afterHostMethod
* @param {String} method The name of the method to inject the function after.
* @param {Function} fn The function to inject.
* @param {Object} context The execution context. Defaults to the plugin instance.
* @return handle {EventHandle} The detach handle for the injected function.
*/
afterHostMethod : function(strMethod, fn, context) {
var handle = Y.Do.after(fn, this.get("host"), strMethod, context || this);
this._handles.push(handle);
return handle;
},
toString: function() {
return this.constructor.NAME + '[' + this.constructor.NS + ']';
}
});
Y.namespace("Plugin").Base = Plugin;
}, 'patched-v3.11.0', {"requires": ["base-base"]});
YUI.add('pluginhost-base', function (Y, NAME) {
/**
* Provides the augmentable PluginHost interface, which can be added to any class.
* @module pluginhost
*/
/**
* Provides the augmentable PluginHost interface, which can be added to any class.
* @module pluginhost-base
*/
/**
*
* An augmentable class, which provides the augmented class with the ability to host plugins.
* It adds plug and unplug methods to the augmented class, which can
* be used to add or remove plugins from instances of the class.
*
*
* Plugins can also be added through the constructor configuration object passed to the host class' constructor using
* the "plugins" property. Supported values for the "plugins" property are those defined by the plug method.
*
* For example the following code would add the AnimPlugin and IOPlugin to Overlay (the plugin host):
*
* var o = new Overlay({plugins: [ AnimPlugin, {fn:IOPlugin, cfg:{section:"header"}}]});
*
*
*
* Plug.Host's protected _initPlugins and _destroyPlugins
* methods should be invoked by the host class at the appropriate point in the host's lifecyle.
*
*
* @class Plugin.Host
*/
var L = Y.Lang;
function PluginHost() {
this._plugins = {};
}
PluginHost.prototype = {
/**
* Adds a plugin to the host object. This will instantiate the
* plugin and attach it to the configured namespace on the host object.
*
* @method plug
* @chainable
* @param P {Function | Object |Array} Accepts the plugin class, or an
* object with a "fn" property specifying the plugin class and
* a "cfg" property specifying the configuration for the Plugin.
*
* Additionally an Array can also be passed in, with the above function or
* object values, allowing the user to add multiple plugins in a single call.
*
* @param config (Optional) If the first argument is the plugin class, the second argument
* can be the configuration for the plugin.
* @return {Base} A reference to the host object
*/
plug: function(Plugin, config) {
var i, ln, ns;
if (L.isArray(Plugin)) {
for (i = 0, ln = Plugin.length; i < ln; i++) {
this.plug(Plugin[i]);
}
} else {
if (Plugin && !L.isFunction(Plugin)) {
config = Plugin.cfg;
Plugin = Plugin.fn;
}
// Plugin should be fn by now
if (Plugin && Plugin.NS) {
ns = Plugin.NS;
config = config || {};
config.host = this;
if (this.hasPlugin(ns)) {
// Update config
if (this[ns].setAttrs) {
this[ns].setAttrs(config);
}
} else {
// Create new instance
this[ns] = new Plugin(config);
this._plugins[ns] = Plugin;
}
}
}
return this;
},
/**
* Removes a plugin from the host object. This will destroy the
* plugin instance and delete the namespace from the host object.
*
* @method unplug
* @param {String | Function} plugin The namespace of the plugin, or the plugin class with the static NS namespace property defined. If not provided,
* all registered plugins are unplugged.
* @return {Base} A reference to the host object
* @chainable
*/
unplug: function(plugin) {
var ns = plugin,
plugins = this._plugins;
if (plugin) {
if (L.isFunction(plugin)) {
ns = plugin.NS;
if (ns && (!plugins[ns] || plugins[ns] !== plugin)) {
ns = null;
}
}
if (ns) {
if (this[ns]) {
if (this[ns].destroy) {
this[ns].destroy();
}
delete this[ns];
}
if (plugins[ns]) {
delete plugins[ns];
}
}
} else {
for (ns in this._plugins) {
if (this._plugins.hasOwnProperty(ns)) {
this.unplug(ns);
}
}
}
return this;
},
/**
* Determines if a plugin has plugged into this host.
*
* @method hasPlugin
* @param {String} ns The plugin's namespace
* @return {Plugin} Returns a truthy value (the plugin instance) if present, or undefined if not.
*/
hasPlugin : function(ns) {
return (this._plugins[ns] && this[ns]);
},
/**
* Initializes static plugins registered on the host (using the
* Base.plug static method) and any plugins passed to the
* instance through the "plugins" configuration property.
*
* @method _initPlugins
* @param {Config} config The configuration object with property name/value pairs.
* @private
*/
_initPlugins: function(config) {
this._plugins = this._plugins || {};
if (this._initConfigPlugins) {
this._initConfigPlugins(config);
}
},
/**
* Unplugs and destroys all plugins on the host
* @method _destroyPlugins
* @private
*/
_destroyPlugins: function() {
this.unplug();
}
};
Y.namespace("Plugin").Host = PluginHost;
}, 'patched-v3.11.0', {"requires": ["yui-base"]});
YUI.add('pluginhost-config', function (Y, NAME) {
/**
* Adds pluginhost constructor configuration and static configuration support
* @submodule pluginhost-config
*/
var PluginHost = Y.Plugin.Host,
L = Y.Lang;
/**
* A protected initialization method, used by the host class to initialize
* plugin configurations passed the constructor, through the config object.
*
* Host objects should invoke this method at the appropriate time in their
* construction lifecycle.
*
* @method _initConfigPlugins
* @param {Object} config The configuration object passed to the constructor
* @protected
* @for Plugin.Host
*/
PluginHost.prototype._initConfigPlugins = function(config) {
// Class Configuration
var classes = (this._getClasses) ? this._getClasses() : [this.constructor],
plug = [],
unplug = {},
constructor, i, classPlug, classUnplug, pluginClassName;
// TODO: Room for optimization. Can we apply statically/unplug in same pass?
for (i = classes.length - 1; i >= 0; i--) {
constructor = classes[i];
classUnplug = constructor._UNPLUG;
if (classUnplug) {
// subclasses over-write
Y.mix(unplug, classUnplug, true);
}
classPlug = constructor._PLUG;
if (classPlug) {
// subclasses over-write
Y.mix(plug, classPlug, true);
}
}
for (pluginClassName in plug) {
if (plug.hasOwnProperty(pluginClassName)) {
if (!unplug[pluginClassName]) {
this.plug(plug[pluginClassName]);
}
}
}
// User Configuration
if (config && config.plugins) {
this.plug(config.plugins);
}
};
/**
* Registers plugins to be instantiated at the class level (plugins
* which should be plugged into every instance of the class by default).
*
* @method plug
* @static
*
* @param {Function} hostClass The host class on which to register the plugins
* @param {Function | Array} plugin Either the plugin class, an array of plugin classes or an array of objects (with fn and cfg properties defined)
* @param {Object} config (Optional) If plugin is the plugin class, the configuration for the plugin
* @for Plugin.Host
*/
PluginHost.plug = function(hostClass, plugin, config) {
// Cannot plug into Base, since Plugins derive from Base [ will cause infinite recurrsion ]
var p, i, l, name;
if (hostClass !== Y.Base) {
hostClass._PLUG = hostClass._PLUG || {};
if (!L.isArray(plugin)) {
if (config) {
plugin = {fn:plugin, cfg:config};
}
plugin = [plugin];
}
for (i = 0, l = plugin.length; i < l;i++) {
p = plugin[i];
name = p.NAME || p.fn.NAME;
hostClass._PLUG[name] = p;
}
}
};
/**
* Unregisters any class level plugins which have been registered by the host class, or any
* other class in the hierarchy.
*
* @method unplug
* @static
*
* @param {Function} hostClass The host class from which to unregister the plugins
* @param {Function | Array} plugin The plugin class, or an array of plugin classes
* @for Plugin.Host
*/
PluginHost.unplug = function(hostClass, plugin) {
var p, i, l, name;
if (hostClass !== Y.Base) {
hostClass._UNPLUG = hostClass._UNPLUG || {};
if (!L.isArray(plugin)) {
plugin = [plugin];
}
for (i = 0, l = plugin.length; i < l; i++) {
p = plugin[i];
name = p.NAME;
if (!hostClass._PLUG[name]) {
hostClass._UNPLUG[name] = p;
} else {
delete hostClass._PLUG[name];
}
}
}
};
}, 'patched-v3.11.0', {"requires": ["pluginhost-base"]});
YUI.add('querystring-stringify-simple', function (Y, NAME) {
/*global Y */
/**
* Provides Y.QueryString.stringify method for converting objects to Query Strings.
* This is a subset implementation of the full querystring-stringify.
* This module provides the bare minimum functionality (encoding a hash of simple values),
* without the additional support for nested data structures. Every key-value pair is
* encoded by encodeURIComponent.
* This module provides a minimalistic way for io to handle single-level objects
* as transaction data.
*
* @module querystring
* @submodule querystring-stringify-simple
*/
var QueryString = Y.namespace("QueryString"),
EUC = encodeURIComponent;
QueryString.stringify = function (obj, c) {
var qs = [],
// Default behavior is false; standard key notation.
s = c && c.arrayKey ? true : false,
key, i, l;
for (key in obj) {
if (obj.hasOwnProperty(key)) {
if (Y.Lang.isArray(obj[key])) {
for (i = 0, l = obj[key].length; i < l; i++) {
qs.push(EUC(s ? key + '[]' : key) + '=' + EUC(obj[key][i]));
}
}
else {
qs.push(EUC(key) + '=' + EUC(obj[key]));
}
}
}
return qs.join('&');
};
}, 'patched-v3.11.0', {"requires": ["yui-base"]});
YUI.add('queue-promote', function (Y, NAME) {
/**
* Adds methods promote, remove, and indexOf to Queue instances.
*
* @module queue-promote
* @for Queue
*/
Y.mix(Y.Queue.prototype, {
/**
* Returns the current index in the queue of the specified item
*
* @method indexOf
* @param needle {MIXED} the item to search for
* @return {Number} the index of the item or -1 if not found
*/
indexOf : function (callback) {
return Y.Array.indexOf(this._q, callback);
},
/**
* Moves the referenced item to the head of the queue
*
* @method promote
* @param item {MIXED} an item in the queue
*/
promote : function (callback) {
var index = this.indexOf(callback);
if (index > -1) {
this._q.unshift(this._q.splice(index,1)[0]);
}
},
/**
* Removes the referenced item from the queue
*
* @method remove
* @param item {MIXED} an item in the queue
*/
remove : function (callback) {
var index = this.indexOf(callback);
if (index > -1) {
this._q.splice(index,1);
}
}
});
}, 'patched-v3.11.0', {"requires": ["yui-base"]});
YUI.add('selector-css2', function (Y, NAME) {
/**
* The selector module provides helper methods allowing CSS2 Selectors to be used with DOM elements.
* @module dom
* @submodule selector-css2
* @for Selector
*/
/*
* Provides helper methods for collecting and filtering DOM elements.
*/
var PARENT_NODE = 'parentNode',
TAG_NAME = 'tagName',
ATTRIBUTES = 'attributes',
COMBINATOR = 'combinator',
PSEUDOS = 'pseudos',
Selector = Y.Selector,
SelectorCSS2 = {
_reRegExpTokens: /([\^\$\?\[\]\*\+\-\.\(\)\|\\])/,
SORT_RESULTS: true,
// TODO: better detection, document specific
_isXML: (function() {
var isXML = (Y.config.doc.createElement('div').tagName !== 'DIV');
return isXML;
}()),
/**
* Mapping of shorthand tokens to corresponding attribute selector
* @property shorthand
* @type object
*/
shorthand: {
'\\#(-?[_a-z0-9]+[-\\w\\uE000]*)': '[id=$1]',
'\\.(-?[_a-z]+[-\\w\\uE000]*)': '[className~=$1]'
},
/**
* List of operators and corresponding boolean functions.
* These functions are passed the attribute and the current node's value of the attribute.
* @property operators
* @type object
*/
operators: {
'': function(node, attr) { return Y.DOM.getAttribute(node, attr) !== ''; }, // Just test for existence of attribute
'~=': '(?:^|\\s+){val}(?:\\s+|$)', // space-delimited
'|=': '^{val}-?' // optional hyphen-delimited
},
pseudos: {
'first-child': function(node) {
return Y.DOM._children(node[PARENT_NODE])[0] === node;
}
},
_bruteQuery: function(selector, root, firstOnly) {
var ret = [],
nodes = [],
visited,
tokens = Selector._tokenize(selector),
token = tokens[tokens.length - 1],
rootDoc = Y.DOM._getDoc(root),
child,
id,
className,
tagName,
isUniversal;
if (token) {
// prefilter nodes
id = token.id;
className = token.className;
tagName = token.tagName || '*';
if (typeof root.getElementsByTagName !== "undefined") { // non-IE lacks DOM api on doc frags
// try ID first, unless no root.all && root not in document
// (root.all works off document, but not getElementById)
if (id && (root.all || (root.nodeType === 9 || Y.DOM.inDoc(root)))) {
nodes = Y.DOM.allById(id, root);
// try className
} else if (className) {
nodes = root.getElementsByClassName(className);
} else { // default to tagName
nodes = root.getElementsByTagName(tagName);
}
} else { // brute getElementsByTagName()
visited = [];
child = root.firstChild;
isUniversal = tagName === "*";
while (child) {
while (child) {
// IE 6-7 considers comment nodes as element nodes, and gives them the tagName "!".
// We can filter them out by checking if its tagName is > "@".
// This also avoids a superflous nodeType === 1 check.
if (child.tagName > "@" && (isUniversal || child.tagName === tagName)) {
nodes.push(child);
}
// We may need to traverse back up the tree to find more unvisited subtrees.
visited.push(child);
child = child.firstChild;
}
// Find the most recently visited node who has a next sibling.
while (visited.length > 0 && !child) {
child = visited.pop().nextSibling;
}
}
}
if (nodes.length) {
ret = Selector._filterNodes(nodes, tokens, firstOnly);
}
}
return ret;
},
_filterNodes: function(nodes, tokens, firstOnly) {
var i = 0,
j,
len = tokens.length,
n = len - 1,
result = [],
node = nodes[0],
tmpNode = node,
getters = Y.Selector.getters,
operator,
combinator,
token,
path,
pass,
value,
tests,
test;
for (i = 0; (tmpNode = node = nodes[i++]);) {
n = len - 1;
path = null;
testLoop:
while (tmpNode && tmpNode.tagName) {
token = tokens[n];
tests = token.tests;
j = tests.length;
if (j && !pass) {
while ((test = tests[--j])) {
operator = test[1];
if (getters[test[0]]) {
value = getters[test[0]](tmpNode, test[0]);
} else {
value = tmpNode[test[0]];
if (test[0] === 'tagName' && !Selector._isXML) {
value = value.toUpperCase();
}
if (typeof value != 'string' && value !== undefined && value.toString) {
value = value.toString(); // coerce for comparison
} else if (value === undefined && tmpNode.getAttribute) {
// use getAttribute for non-standard attributes
value = tmpNode.getAttribute(test[0], 2); // 2 === force string for IE
}
}
if ((operator === '=' && value !== test[2]) || // fast path for equality
(typeof operator !== 'string' && // protect against String.test monkey-patch (Moo)
operator.test && !operator.test(value)) || // regex test
(!operator.test && // protect against RegExp as function (webkit)
typeof operator === 'function' && !operator(tmpNode, test[0], test[2]))) { // function test
// skip non element nodes or non-matching tags
if ((tmpNode = tmpNode[path])) {
while (tmpNode &&
(!tmpNode.tagName ||
(token.tagName && token.tagName !== tmpNode.tagName))
) {
tmpNode = tmpNode[path];
}
}
continue testLoop;
}
}
}
n--; // move to next token
// now that we've passed the test, move up the tree by combinator
if (!pass && (combinator = token.combinator)) {
path = combinator.axis;
tmpNode = tmpNode[path];
// skip non element nodes
while (tmpNode && !tmpNode.tagName) {
tmpNode = tmpNode[path];
}
if (combinator.direct) { // one pass only
path = null;
}
} else { // success if we made it this far
result.push(node);
if (firstOnly) {
return result;
}
break;
}
}
}
node = tmpNode = null;
return result;
},
combinators: {
' ': {
axis: 'parentNode'
},
'>': {
axis: 'parentNode',
direct: true
},
'+': {
axis: 'previousSibling',
direct: true
}
},
_parsers: [
{
name: ATTRIBUTES,
re: /^\uE003(-?[a-z]+[\w\-]*)+([~\|\^\$\*!=]=?)?['"]?([^\uE004'"]*)['"]?\uE004/i,
fn: function(match, token) {
var operator = match[2] || '',
operators = Selector.operators,
escVal = (match[3]) ? match[3].replace(/\\/g, '') : '',
test;
// add prefiltering for ID and CLASS
if ((match[1] === 'id' && operator === '=') ||
(match[1] === 'className' &&
Y.config.doc.documentElement.getElementsByClassName &&
(operator === '~=' || operator === '='))) {
token.prefilter = match[1];
match[3] = escVal;
// escape all but ID for prefilter, which may run through QSA (via Dom.allById)
token[match[1]] = (match[1] === 'id') ? match[3] : escVal;
}
// add tests
if (operator in operators) {
test = operators[operator];
if (typeof test === 'string') {
match[3] = escVal.replace(Selector._reRegExpTokens, '\\$1');
test = new RegExp(test.replace('{val}', match[3]));
}
match[2] = test;
}
if (!token.last || token.prefilter !== match[1]) {
return match.slice(1);
}
}
},
{
name: TAG_NAME,
re: /^((?:-?[_a-z]+[\w-]*)|\*)/i,
fn: function(match, token) {
var tag = match[1];
if (!Selector._isXML) {
tag = tag.toUpperCase();
}
token.tagName = tag;
if (tag !== '*' && (!token.last || token.prefilter)) {
return [TAG_NAME, '=', tag];
}
if (!token.prefilter) {
token.prefilter = 'tagName';
}
}
},
{
name: COMBINATOR,
re: /^\s*([>+~]|\s)\s*/,
fn: function(match, token) {
}
},
{
name: PSEUDOS,
re: /^:([\-\w]+)(?:\uE005['"]?([^\uE005]*)['"]?\uE006)*/i,
fn: function(match, token) {
var test = Selector[PSEUDOS][match[1]];
if (test) { // reorder match array and unescape special chars for tests
if (match[2]) {
match[2] = match[2].replace(/\\/g, '');
}
return [match[2], test];
} else { // selector token not supported (possibly missing CSS3 module)
return false;
}
}
}
],
_getToken: function(token) {
return {
tagName: null,
id: null,
className: null,
attributes: {},
combinator: null,
tests: []
};
},
/*
Break selector into token units per simple selector.
Combinator is attached to the previous token.
*/
_tokenize: function(selector) {
selector = selector || '';
selector = Selector._parseSelector(Y.Lang.trim(selector));
var token = Selector._getToken(), // one token per simple selector (left selector holds combinator)
query = selector, // original query for debug report
tokens = [], // array of tokens
found = false, // whether or not any matches were found this pass
match, // the regex match
test,
i, parser;
/*
Search for selector patterns, store, and strip them from the selector string
until no patterns match (invalid selector) or we run out of chars.
Multiple attributes and pseudos are allowed, in any order.
for example:
'form:first-child[type=button]:not(button)[lang|=en]'
*/
outer:
do {
found = false; // reset after full pass
for (i = 0; (parser = Selector._parsers[i++]);) {
if ( (match = parser.re.exec(selector)) ) { // note assignment
if (parser.name !== COMBINATOR ) {
token.selector = selector;
}
selector = selector.replace(match[0], ''); // strip current match from selector
if (!selector.length) {
token.last = true;
}
if (Selector._attrFilters[match[1]]) { // convert class to className, etc.
match[1] = Selector._attrFilters[match[1]];
}
test = parser.fn(match, token);
if (test === false) { // selector not supported
found = false;
break outer;
} else if (test) {
token.tests.push(test);
}
if (!selector.length || parser.name === COMBINATOR) {
tokens.push(token);
token = Selector._getToken(token);
if (parser.name === COMBINATOR) {
token.combinator = Y.Selector.combinators[match[1]];
}
}
found = true;
}
}
} while (found && selector.length);
if (!found || selector.length) { // not fully parsed
tokens = [];
}
return tokens;
},
_replaceMarkers: function(selector) {
selector = selector.replace(/\[/g, '\uE003');
selector = selector.replace(/\]/g, '\uE004');
selector = selector.replace(/\(/g, '\uE005');
selector = selector.replace(/\)/g, '\uE006');
return selector;
},
_replaceShorthand: function(selector) {
var shorthand = Y.Selector.shorthand,
re;
for (re in shorthand) {
if (shorthand.hasOwnProperty(re)) {
selector = selector.replace(new RegExp(re, 'gi'), shorthand[re]);
}
}
return selector;
},
_parseSelector: function(selector) {
var replaced = Y.Selector._replaceSelector(selector),
selector = replaced.selector;
// replace shorthand (".foo, #bar") after pseudos and attrs
// to avoid replacing unescaped chars
selector = Y.Selector._replaceShorthand(selector);
selector = Y.Selector._restore('attr', selector, replaced.attrs);
selector = Y.Selector._restore('pseudo', selector, replaced.pseudos);
// replace braces and parens before restoring escaped chars
// to avoid replacing ecaped markers
selector = Y.Selector._replaceMarkers(selector);
selector = Y.Selector._restore('esc', selector, replaced.esc);
return selector;
},
_attrFilters: {
'class': 'className',
'for': 'htmlFor'
},
getters: {
href: function(node, attr) {
return Y.DOM.getAttribute(node, attr);
},
id: function(node, attr) {
return Y.DOM.getId(node);
}
}
};
Y.mix(Y.Selector, SelectorCSS2, true);
Y.Selector.getters.src = Y.Selector.getters.rel = Y.Selector.getters.href;
// IE wants class with native queries
if (Y.Selector.useNative && Y.config.doc.querySelector) {
Y.Selector.shorthand['\\.(-?[_a-z]+[-\\w]*)'] = '[class~=$1]';
}
}, 'patched-v3.11.0', {"requires": ["selector-native"]});
YUI.add('selector-css3', function (Y, NAME) {
/**
* The selector css3 module provides support for css3 selectors.
* @module dom
* @submodule selector-css3
* @for Selector
*/
/*
an+b = get every _a_th node starting at the _b_th
0n+b = no repeat ("0" and "n" may both be omitted (together) , e.g. "0n+1" or "1", not "0+1"), return only the _b_th element
1n+b = get every element starting from b ("1" may may be omitted, e.g. "1n+0" or "n+0" or "n")
an+0 = get every _a_th element, "0" may be omitted
*/
Y.Selector._reNth = /^(?:([\-]?\d*)(n){1}|(odd|even)$)*([\-+]?\d*)$/;
Y.Selector._getNth = function(node, expr, tag, reverse) {
Y.Selector._reNth.test(expr);
var a = parseInt(RegExp.$1, 10), // include every _a_ elements (zero means no repeat, just first _a_)
n = RegExp.$2, // "n"
oddeven = RegExp.$3, // "odd" or "even"
b = parseInt(RegExp.$4, 10) || 0, // start scan from element _b_
result = [],
siblings = Y.DOM._children(node.parentNode, tag),
op;
if (oddeven) {
a = 2; // always every other
op = '+';
n = 'n';
b = (oddeven === 'odd') ? 1 : 0;
} else if ( isNaN(a) ) {
a = (n) ? 1 : 0; // start from the first or no repeat
}
if (a === 0) { // just the first
if (reverse) {
b = siblings.length - b + 1;
}
if (siblings[b - 1] === node) {
return true;
} else {
return false;
}
} else if (a < 0) {
reverse = !!reverse;
a = Math.abs(a);
}
if (!reverse) {
for (var i = b - 1, len = siblings.length; i < len; i += a) {
if ( i >= 0 && siblings[i] === node ) {
return true;
}
}
} else {
for (var i = siblings.length - b, len = siblings.length; i >= 0; i -= a) {
if ( i < len && siblings[i] === node ) {
return true;
}
}
}
return false;
};
Y.mix(Y.Selector.pseudos, {
'root': function(node) {
return node === node.ownerDocument.documentElement;
},
'nth-child': function(node, expr) {
return Y.Selector._getNth(node, expr);
},
'nth-last-child': function(node, expr) {
return Y.Selector._getNth(node, expr, null, true);
},
'nth-of-type': function(node, expr) {
return Y.Selector._getNth(node, expr, node.tagName);
},
'nth-last-of-type': function(node, expr) {
return Y.Selector._getNth(node, expr, node.tagName, true);
},
'last-child': function(node) {
var children = Y.DOM._children(node.parentNode);
return children[children.length - 1] === node;
},
'first-of-type': function(node) {
return Y.DOM._children(node.parentNode, node.tagName)[0] === node;
},
'last-of-type': function(node) {
var children = Y.DOM._children(node.parentNode, node.tagName);
return children[children.length - 1] === node;
},
'only-child': function(node) {
var children = Y.DOM._children(node.parentNode);
return children.length === 1 && children[0] === node;
},
'only-of-type': function(node) {
var children = Y.DOM._children(node.parentNode, node.tagName);
return children.length === 1 && children[0] === node;
},
'empty': function(node) {
return node.childNodes.length === 0;
},
'not': function(node, expr) {
return !Y.Selector.test(node, expr);
},
'contains': function(node, expr) {
var text = node.innerText || node.textContent || '';
return text.indexOf(expr) > -1;
},
'checked': function(node) {
return (node.checked === true || node.selected === true);
},
enabled: function(node) {
return (node.disabled !== undefined && !node.disabled);
},
disabled: function(node) {
return (node.disabled);
}
});
Y.mix(Y.Selector.operators, {
'^=': '^{val}', // Match starts with value
'$=': '{val}$', // Match ends with value
'*=': '{val}' // Match contains value as substring
});
Y.Selector.combinators['~'] = {
axis: 'previousSibling'
};
}, 'patched-v3.11.0', {"requires": ["selector-native", "selector-css2"]});
YUI.add('selector-native', function (Y, NAME) {
(function(Y) {
/**
* The selector-native module provides support for native querySelector
* @module dom
* @submodule selector-native
* @for Selector
*/
/**
* Provides support for using CSS selectors to query the DOM
* @class Selector
* @static
* @for Selector
*/
Y.namespace('Selector'); // allow native module to standalone
var COMPARE_DOCUMENT_POSITION = 'compareDocumentPosition',
OWNER_DOCUMENT = 'ownerDocument';
var Selector = {
_types: {
esc: {
token: '\uE000',
re: /\\[:\[\]\(\)#\.\'\>+~"]/gi
},
attr: {
token: '\uE001',
re: /(\[[^\]]*\])/g
},
pseudo: {
token: '\uE002',
re: /(\([^\)]*\))/g
}
},
useNative: true,
_escapeId: function(id) {
if (id) {
id = id.replace(/([:\[\]\(\)#\.'<>+~"])/g,'\\$1');
}
return id;
},
_compare: ('sourceIndex' in Y.config.doc.documentElement) ?
function(nodeA, nodeB) {
var a = nodeA.sourceIndex,
b = nodeB.sourceIndex;
if (a === b) {
return 0;
} else if (a > b) {
return 1;
}
return -1;
} : (Y.config.doc.documentElement[COMPARE_DOCUMENT_POSITION] ?
function(nodeA, nodeB) {
if (nodeA[COMPARE_DOCUMENT_POSITION](nodeB) & 4) {
return -1;
} else {
return 1;
}
} :
function(nodeA, nodeB) {
var rangeA, rangeB, compare;
if (nodeA && nodeB) {
rangeA = nodeA[OWNER_DOCUMENT].createRange();
rangeA.setStart(nodeA, 0);
rangeB = nodeB[OWNER_DOCUMENT].createRange();
rangeB.setStart(nodeB, 0);
compare = rangeA.compareBoundaryPoints(1, rangeB); // 1 === Range.START_TO_END
}
return compare;
}),
_sort: function(nodes) {
if (nodes) {
nodes = Y.Array(nodes, 0, true);
if (nodes.sort) {
nodes.sort(Selector._compare);
}
}
return nodes;
},
_deDupe: function(nodes) {
var ret = [],
i, node;
for (i = 0; (node = nodes[i++]);) {
if (!node._found) {
ret[ret.length] = node;
node._found = true;
}
}
for (i = 0; (node = ret[i++]);) {
node._found = null;
node.removeAttribute('_found');
}
return ret;
},
/**
* Retrieves a set of nodes based on a given CSS selector.
* @method query
*
* @param {string} selector The CSS Selector to test the node against.
* @param {HTMLElement} root optional An HTMLElement to start the query from. Defaults to Y.config.doc
* @param {Boolean} firstOnly optional Whether or not to return only the first match.
* @return {Array} An array of nodes that match the given selector.
* @static
*/
query: function(selector, root, firstOnly, skipNative) {
root = root || Y.config.doc;
var ret = [],
useNative = (Y.Selector.useNative && Y.config.doc.querySelector && !skipNative),
queries = [[selector, root]],
query,
result,
i,
fn = (useNative) ? Y.Selector._nativeQuery : Y.Selector._bruteQuery;
if (selector && fn) {
// split group into seperate queries
if (!skipNative && // already done if skipping
(!useNative || root.tagName)) { // split native when element scoping is needed
queries = Selector._splitQueries(selector, root);
}
for (i = 0; (query = queries[i++]);) {
result = fn(query[0], query[1], firstOnly);
if (!firstOnly) { // coerce DOM Collection to Array
result = Y.Array(result, 0, true);
}
if (result) {
ret = ret.concat(result);
}
}
if (queries.length > 1) { // remove dupes and sort by doc order
ret = Selector._sort(Selector._deDupe(ret));
}
}
return (firstOnly) ? (ret[0] || null) : ret;
},
_replaceSelector: function(selector) {
var esc = Y.Selector._parse('esc', selector), // pull escaped colon, brackets, etc.
attrs,
pseudos;
// first replace escaped chars, which could be present in attrs or pseudos
selector = Y.Selector._replace('esc', selector);
// then replace pseudos before attrs to avoid replacing :not([foo])
pseudos = Y.Selector._parse('pseudo', selector);
selector = Selector._replace('pseudo', selector);
attrs = Y.Selector._parse('attr', selector);
selector = Y.Selector._replace('attr', selector);
return {
esc: esc,
attrs: attrs,
pseudos: pseudos,
selector: selector
};
},
_restoreSelector: function(replaced) {
var selector = replaced.selector;
selector = Y.Selector._restore('attr', selector, replaced.attrs);
selector = Y.Selector._restore('pseudo', selector, replaced.pseudos);
selector = Y.Selector._restore('esc', selector, replaced.esc);
return selector;
},
_replaceCommas: function(selector) {
var replaced = Y.Selector._replaceSelector(selector),
selector = replaced.selector;
if (selector) {
selector = selector.replace(/,/g, '\uE007');
replaced.selector = selector;
selector = Y.Selector._restoreSelector(replaced);
}
return selector;
},
// allows element scoped queries to begin with combinator
// e.g. query('> p', document.body) === query('body > p')
_splitQueries: function(selector, node) {
if (selector.indexOf(',') > -1) {
selector = Y.Selector._replaceCommas(selector);
}
var groups = selector.split('\uE007'), // split on replaced comma token
queries = [],
prefix = '',
id,
i,
len;
if (node) {
// enforce for element scoping
if (node.nodeType === 1) { // Elements only
id = Y.Selector._escapeId(Y.DOM.getId(node));
if (!id) {
id = Y.guid();
Y.DOM.setId(node, id);
}
prefix = '[id="' + id + '"] ';
}
for (i = 0, len = groups.length; i < len; ++i) {
selector = prefix + groups[i];
queries.push([selector, node]);
}
}
return queries;
},
_nativeQuery: function(selector, root, one) {
if (
(Y.UA.webkit || Y.UA.opera) && // webkit (chrome, safari) and Opera
selector.indexOf(':checked') > -1 && // fail to pick up "selected" with ":checked"
(Y.Selector.pseudos && Y.Selector.pseudos.checked)
) {
return Y.Selector.query(selector, root, one, true); // redo with skipNative true to try brute query
}
try {
return root['querySelector' + (one ? '' : 'All')](selector);
} catch(e) { // fallback to brute if available
return Y.Selector.query(selector, root, one, true); // redo with skipNative true
}
},
filter: function(nodes, selector) {
var ret = [],
i, node;
if (nodes && selector) {
for (i = 0; (node = nodes[i++]);) {
if (Y.Selector.test(node, selector)) {
ret[ret.length] = node;
}
}
} else {
}
return ret;
},
test: function(node, selector, root) {
var defaultId,
ret = false,
useFrag = false,
groups,
parent,
item,
items,
frag,
id,
i, j, group;
if (node && node.tagName) { // only test HTMLElements
if (typeof selector == 'function') { // test with function
ret = selector.call(node, node);
} else { // test with query
// we need a root if off-doc
groups = selector.split(',');
if (!root && !Y.DOM.inDoc(node)) {
parent = node.parentNode;
if (parent) {
root = parent;
} else { // only use frag when no parent to query
frag = node[OWNER_DOCUMENT].createDocumentFragment();
frag.appendChild(node);
root = frag;
useFrag = true;
}
}
root = root || node[OWNER_DOCUMENT];
id = Y.Selector._escapeId(Y.DOM.getId(node));
if (!id) {
defaultId = true;
id = Y.guid();
Y.DOM.setId(node, id);
}
for (i = 0; (group = groups[i++]);) { // TODO: off-dom test
group += '[id="' + id + '"]';
items = Y.Selector.query(group, root);
for (j = 0; item = items[j++];) {
if (item === node) {
ret = true;
break;
}
}
if (ret) {
break;
}
}
if (useFrag) { // cleanup
frag.removeChild(node);
}
if (defaultId) {
node.removeAttribute('id');
}
};
}
return ret;
},
/**
* A convenience function to emulate Y.Node's aNode.ancestor(selector).
* @param {HTMLElement} element An HTMLElement to start the query from.
* @param {String} selector The CSS selector to test the node against.
* @return {HTMLElement} The ancestor node matching the selector, or null.
* @param {Boolean} testSelf optional Whether or not to include the element in the scan
* @static
* @method ancestor
*/
ancestor: function (element, selector, testSelf) {
return Y.DOM.ancestor(element, function(n) {
return Y.Selector.test(n, selector);
}, testSelf);
},
_parse: function(name, selector) {
return selector.match(Y.Selector._types[name].re);
},
_replace: function(name, selector) {
var o = Y.Selector._types[name];
return selector.replace(o.re, o.token);
},
_restore: function(name, selector, items) {
if (items) {
var token = Y.Selector._types[name].token,
i, len;
for (i = 0, len = items.length; i < len; ++i) {
selector = selector.replace(token, items[i]);
}
}
return selector;
}
};
Y.mix(Y.Selector, Selector, true);
})(Y);
}, 'patched-v3.11.0', {"requires": ["dom-base"]});
YUI.add('selector', function (Y, NAME) {
}, 'patched-v3.11.0', {"requires": ["selector-native"]});
YUI.add('widget-base', function (Y, NAME) {
/**
* Provides the base Widget class, with HTML Parser support
*
* @module widget
* @main widget
*/
/**
* Provides the base Widget class
*
* @module widget
* @submodule widget-base
*/
var L = Y.Lang,
Node = Y.Node,
ClassNameManager = Y.ClassNameManager,
_getClassName = ClassNameManager.getClassName,
_getWidgetClassName,
_toInitialCap = Y.cached(function(str) {
return str.substring(0, 1).toUpperCase() + str.substring(1);
}),
// K-Weight, IE GC optimizations
CONTENT = "content",
VISIBLE = "visible",
HIDDEN = "hidden",
DISABLED = "disabled",
FOCUSED = "focused",
WIDTH = "width",
HEIGHT = "height",
BOUNDING_BOX = "boundingBox",
CONTENT_BOX = "contentBox",
PARENT_NODE = "parentNode",
OWNER_DOCUMENT = "ownerDocument",
AUTO = "auto",
SRC_NODE = "srcNode",
BODY = "body",
TAB_INDEX = "tabIndex",
ID = "id",
RENDER = "render",
RENDERED = "rendered",
DESTROYED = "destroyed",
STRINGS = "strings",
DIV = "
",
CHANGE = "Change",
LOADING = "loading",
_UISET = "_uiSet",
EMPTY_STR = "",
EMPTY_FN = function() {},
TRUE = true,
FALSE = false,
UI,
ATTRS = {},
UI_ATTRS = [VISIBLE, DISABLED, HEIGHT, WIDTH, FOCUSED, TAB_INDEX],
WEBKIT = Y.UA.webkit,
// Widget nodeid-to-instance map.
_instances = {};
/**
* A base class for widgets, providing:
*
* The render lifecycle method, in addition to the init and destroy
* lifecycle methods provide by Base
* Abstract methods to support consistent MVC structure across
* widgets: renderer, renderUI, bindUI, syncUI
* Support for common widget attributes, such as boundingBox, contentBox, visible,
* disabled, focused, strings
*
*
* @param config {Object} Object literal specifying widget configuration properties.
*
* @class Widget
* @constructor
* @extends Base
*/
function Widget(config) {
// kweight
var widget = this,
parentNode,
render,
constructor = widget.constructor;
widget._strs = {};
widget._cssPrefix = constructor.CSS_PREFIX || _getClassName(constructor.NAME.toLowerCase());
// We need a config for HTML_PARSER to work.
config = config || {};
Widget.superclass.constructor.call(widget, config);
render = widget.get(RENDER);
if (render) {
// Render could be a node or boolean
if (render !== TRUE) {
parentNode = render;
}
widget.render(parentNode);
}
}
/**
* Static property provides a string to identify the class.
*
* Currently used to apply class identifiers to the bounding box
* and to classify events fired by the widget.
*
*
* @property NAME
* @type String
* @static
*/
Widget.NAME = "widget";
/**
* Constant used to identify state changes originating from
* the DOM (as opposed to the JavaScript model).
*
* @property UI_SRC
* @type String
* @static
* @final
*/
UI = Widget.UI_SRC = "ui";
/**
* Static property used to define the default attribute
* configuration for the Widget.
*
* @property ATTRS
* @type Object
* @static
*/
Widget.ATTRS = ATTRS;
// Trying to optimize kweight by setting up attrs this way saves about 0.4K min'd
/**
* @attribute id
* @writeOnce
* @default Generated using guid()
* @type String
*/
ATTRS[ID] = {
valueFn: "_guid",
writeOnce: TRUE
};
/**
* Flag indicating whether or not this Widget
* has been through the render lifecycle phase.
*
* @attribute rendered
* @readOnly
* @default false
* @type boolean
*/
ATTRS[RENDERED] = {
value:FALSE,
readOnly: TRUE
};
/**
* @attribute boundingBox
* @description The outermost DOM node for the Widget, used for sizing and positioning
* of a Widget as well as a containing element for any decorator elements used
* for skinning.
* @type String | Node
* @writeOnce
*/
ATTRS[BOUNDING_BOX] = {
value:null,
setter: "_setBB",
writeOnce: TRUE
};
/**
* @attribute contentBox
* @description A DOM node that is a direct descendant of a Widget's bounding box that
* houses its content.
* @type String | Node
* @writeOnce
*/
ATTRS[CONTENT_BOX] = {
valueFn:"_defaultCB",
setter: "_setCB",
writeOnce: TRUE
};
/**
* @attribute tabIndex
* @description Number (between -32767 to 32767) indicating the widget's
* position in the default tab flow. The value is used to set the
* "tabIndex" attribute on the widget's bounding box. Negative values allow
* the widget to receive DOM focus programmatically (by calling the focus
* method), while being removed from the default tab flow. A value of
* null removes the "tabIndex" attribute from the widget's bounding box.
* @type Number
* @default null
*/
ATTRS[TAB_INDEX] = {
value: null,
validator: "_validTabIndex"
};
/**
* @attribute focused
* @description Boolean indicating if the Widget, or one of its descendants,
* has focus.
* @readOnly
* @default false
* @type boolean
*/
ATTRS[FOCUSED] = {
value: FALSE,
readOnly:TRUE
};
/**
* @attribute disabled
* @description Boolean indicating if the Widget should be disabled. The disabled implementation
* is left to the specific classes extending widget.
* @default false
* @type boolean
*/
ATTRS[DISABLED] = {
value: FALSE
};
/**
* @attribute visible
* @description Boolean indicating whether or not the Widget is visible.
* @default TRUE
* @type boolean
*/
ATTRS[VISIBLE] = {
value: TRUE
};
/**
* @attribute height
* @description String with units, or number, representing the height of the Widget. If a number is provided,
* the default unit, defined by the Widgets DEF_UNIT, property is used.
* @default EMPTY_STR
* @type {String | Number}
*/
ATTRS[HEIGHT] = {
value: EMPTY_STR
};
/**
* @attribute width
* @description String with units, or number, representing the width of the Widget. If a number is provided,
* the default unit, defined by the Widgets DEF_UNIT, property is used.
* @default EMPTY_STR
* @type {String | Number}
*/
ATTRS[WIDTH] = {
value: EMPTY_STR
};
/**
* @attribute strings
* @description Collection of strings used to label elements of the Widget's UI.
* @default null
* @type Object
*/
ATTRS[STRINGS] = {
value: {},
setter: "_strSetter",
getter: "_strGetter"
};
/**
* Whether or not to render the widget automatically after init, and optionally, to which parent node.
*
* @attribute render
* @type boolean | Node
* @writeOnce
*/
ATTRS[RENDER] = {
value:FALSE,
writeOnce:TRUE
};
/**
* The css prefix which the static Widget.getClassName method should use when constructing class names
*
* @property CSS_PREFIX
* @type String
* @default Widget.NAME.toLowerCase()
* @private
* @static
*/
Widget.CSS_PREFIX = _getClassName(Widget.NAME.toLowerCase());
/**
* Generate a standard prefixed classname for the Widget, prefixed by the default prefix defined
* by the Y.config.classNamePrefix
attribute used by ClassNameManager
and
* Widget.NAME.toLowerCase()
(e.g. "yui-widget-xxxxx-yyyyy", based on default values for
* the prefix and widget class name).
*
* The instance based version of this method can be used to generate standard prefixed classnames,
* based on the instances NAME, as opposed to Widget.NAME. This method should be used when you
* need to use a constant class name across different types instances.
*
* @method getClassName
* @param {String*} args* 0..n strings which should be concatenated, using the default separator defined by ClassNameManager, to create the class name
*/
Widget.getClassName = function() {
// arguments needs to be array'fied to concat
return _getClassName.apply(ClassNameManager, [Widget.CSS_PREFIX].concat(Y.Array(arguments), true));
};
_getWidgetClassName = Widget.getClassName;
/**
* Returns the widget instance whose bounding box contains, or is, the given node.
*
* In the case of nested widgets, the nearest bounding box ancestor is used to
* return the widget instance.
*
* @method getByNode
* @static
* @param node {Node | String} The node for which to return a Widget instance. If a selector
* string is passed in, which selects more than one node, the first node found is used.
* @return {Widget} Widget instance, or null if not found.
*/
Widget.getByNode = function(node) {
var widget,
widgetMarker = _getWidgetClassName();
node = Node.one(node);
if (node) {
node = node.ancestor("." + widgetMarker, true);
if (node) {
widget = _instances[Y.stamp(node, true)];
}
}
return widget || null;
};
Y.extend(Widget, Y.Base, {
/**
* Returns a class name prefixed with the the value of the
* YUI.config.classNamePrefix
attribute + the instances NAME
property.
* Uses YUI.config.classNameDelimiter
attribute to delimit the provided strings.
* e.g.
*
*
* // returns "yui-slider-foo-bar", for a slider instance
* var scn = slider.getClassName('foo','bar');
*
* // returns "yui-overlay-foo-bar", for an overlay instance
* var ocn = overlay.getClassName('foo','bar');
*
*
*
* @method getClassName
* @param {String}+ One or more classname bits to be joined and prefixed
*/
getClassName: function () {
return _getClassName.apply(ClassNameManager, [this._cssPrefix].concat(Y.Array(arguments), true));
},
/**
* Initializer lifecycle implementation for the Widget class. Registers the
* widget instance, and runs through the Widget's HTML_PARSER definition.
*
* @method initializer
* @protected
* @param config {Object} Configuration object literal for the widget
*/
initializer: function(config) {
var bb = this.get(BOUNDING_BOX);
if (bb instanceof Node) {
this._mapInstance(Y.stamp(bb));
}
/**
* Notification event, which widget implementations can fire, when
* they change the content of the widget. This event has no default
* behavior and cannot be prevented, so the "on" or "after"
* moments are effectively equivalent (with on listeners being invoked before
* after listeners).
*
* @event widget:contentUpdate
* @preventable false
* @param {EventFacade} e The Event Facade
*/
},
/**
* Utility method used to add an entry to the boundingBox id to instance map.
*
* This method can be used to populate the instance with lazily created boundingBox Node references.
*
* @method _mapInstance
* @param {String} The boundingBox id
* @protected
*/
_mapInstance : function(id) {
_instances[id] = this;
},
/**
* Destructor lifecycle implementation for the Widget class. Purges events attached
* to the bounding box and content box, removes them from the DOM and removes
* the Widget from the list of registered widgets.
*
* @method destructor
* @protected
*/
destructor: function() {
var boundingBox = this.get(BOUNDING_BOX),
bbGuid;
if (boundingBox instanceof Node) {
bbGuid = Y.stamp(boundingBox,true);
if (bbGuid in _instances) {
delete _instances[bbGuid];
}
this._destroyBox();
}
},
/**
*
* Destroy lifecycle method. Fires the destroy
* event, prior to invoking destructors for the
* class hierarchy.
*
* Overrides Base's implementation, to support arguments to destroy
*
*
* Subscribers to the destroy
* event can invoke preventDefault on the event object, to prevent destruction
* from proceeding.
*
* @method destroy
* @param destroyAllNodes {Boolean} If true, all nodes contained within the Widget are
* removed and destroyed. Defaults to false due to potentially high run-time cost.
* @return {Widget} A reference to this object
* @chainable
*/
destroy: function(destroyAllNodes) {
this._destroyAllNodes = destroyAllNodes;
return Widget.superclass.destroy.apply(this);
},
/**
* Removes and destroys the widgets rendered boundingBox, contentBox,
* and detaches bound UI events.
*
* @method _destroyBox
* @protected
*/
_destroyBox : function() {
var boundingBox = this.get(BOUNDING_BOX),
contentBox = this.get(CONTENT_BOX),
deep = this._destroyAllNodes,
same;
same = boundingBox && boundingBox.compareTo(contentBox);
if (this.UI_EVENTS) {
this._destroyUIEvents();
}
this._unbindUI(boundingBox);
if (contentBox) {
if (deep) {
contentBox.empty();
}
contentBox.remove(TRUE);
}
if (!same) {
if (deep) {
boundingBox.empty();
}
boundingBox.remove(TRUE);
}
},
/**
* Establishes the initial DOM for the widget. Invoking this
* method will lead to the creating of all DOM elements for
* the widget (or the manipulation of existing DOM elements
* for the progressive enhancement use case).
*
* This method should only be invoked once for an initialized
* widget.
*
*
* It delegates to the widget specific renderer method to do
* the actual work.
*
*
* @method render
* @chainable
* @final
* @param parentNode {Object | String} Optional. The Node under which the
* Widget is to be rendered. This can be a Node instance or a CSS selector string.
*
* If the selector string returns more than one Node, the first node will be used
* as the parentNode. NOTE: This argument is required if both the boundingBox and contentBox
* are not currently in the document. If it's not provided, the Widget will be rendered
* to the body of the current document in this case.
*
*/
render: function(parentNode) {
if (!this.get(DESTROYED) && !this.get(RENDERED)) {
/**
* Lifecycle event for the render phase, fired prior to rendering the UI
* for the widget (prior to invoking the widget's renderer method).
*
* Subscribers to the "on" moment of this event, will be notified
* before the widget is rendered.
*
*
* Subscribers to the "after" moment of this event, will be notified
* after rendering is complete.
*
*
* @event render
* @preventable _defRenderFn
* @param {EventFacade} e The Event Facade
*/
this.publish(RENDER, {
queuable:FALSE,
fireOnce:TRUE,
defaultTargetOnly:TRUE,
defaultFn: this._defRenderFn
});
this.fire(RENDER, {parentNode: (parentNode) ? Node.one(parentNode) : null});
}
return this;
},
/**
* Default render handler
*
* @method _defRenderFn
* @protected
* @param {EventFacade} e The Event object
* @param {Node} parentNode The parent node to render to, if passed in to the render
method
*/
_defRenderFn : function(e) {
this._parentNode = e.parentNode;
this.renderer();
this._set(RENDERED, TRUE);
this._removeLoadingClassNames();
},
/**
* Creates DOM (or manipulates DOM for progressive enhancement)
* This method is invoked by render() and is not chained
* automatically for the class hierarchy (unlike initializer, destructor)
* so it should be chained manually for subclasses if required.
*
* @method renderer
* @protected
*/
renderer: function() {
// kweight
var widget = this;
widget._renderUI();
widget.renderUI();
widget._bindUI();
widget.bindUI();
widget._syncUI();
widget.syncUI();
},
/**
* Configures/Sets up listeners to bind Widget State to UI/DOM
*
* This method is not called by framework and is not chained
* automatically for the class hierarchy.
*
* @method bindUI
* @protected
*/
bindUI: EMPTY_FN,
/**
* Adds nodes to the DOM
*
* This method is not called by framework and is not chained
* automatically for the class hierarchy.
*
* @method renderUI
* @protected
*/
renderUI: EMPTY_FN,
/**
* Refreshes the rendered UI, based on Widget State
*
* This method is not called by framework and is not chained
* automatically for the class hierarchy.
*
* @method syncUI
* @protected
*
*/
syncUI: EMPTY_FN,
/**
* @method hide
* @description Hides the Widget by setting the "visible" attribute to "false".
* @chainable
*/
hide: function() {
return this.set(VISIBLE, FALSE);
},
/**
* @method show
* @description Shows the Widget by setting the "visible" attribute to "true".
* @chainable
*/
show: function() {
return this.set(VISIBLE, TRUE);
},
/**
* @method focus
* @description Causes the Widget to receive the focus by setting the "focused"
* attribute to "true".
* @chainable
*/
focus: function () {
return this._set(FOCUSED, TRUE);
},
/**
* @method blur
* @description Causes the Widget to lose focus by setting the "focused" attribute
* to "false"
* @chainable
*/
blur: function () {
return this._set(FOCUSED, FALSE);
},
/**
* @method enable
* @description Set the Widget's "disabled" attribute to "false".
* @chainable
*/
enable: function() {
return this.set(DISABLED, FALSE);
},
/**
* @method disable
* @description Set the Widget's "disabled" attribute to "true".
* @chainable
*/
disable: function() {
return this.set(DISABLED, TRUE);
},
/**
* @method _uiSizeCB
* @protected
* @param {boolean} expand
*/
_uiSizeCB : function(expand) {
this.get(CONTENT_BOX).toggleClass(_getWidgetClassName(CONTENT, "expanded"), expand);
},
/**
* Helper method to collect the boundingBox and contentBox and append to the provided parentNode, if not
* already a child. The owner document of the boundingBox, or the owner document of the contentBox will be used
* as the document into which the Widget is rendered if a parentNode is node is not provided. If both the boundingBox and
* the contentBox are not currently in the document, and no parentNode is provided, the widget will be rendered
* to the current document's body.
*
* @method _renderBox
* @private
* @param {Node} parentNode The parentNode to render the widget to. If not provided, and both the boundingBox and
* the contentBox are not currently in the document, the widget will be rendered to the current document's body.
*/
_renderBox: function(parentNode) {
// TODO: Performance Optimization [ More effective algo to reduce Node refs, compares, replaces? ]
var widget = this, // kweight
contentBox = widget.get(CONTENT_BOX),
boundingBox = widget.get(BOUNDING_BOX),
srcNode = widget.get(SRC_NODE),
defParentNode = widget.DEF_PARENT_NODE,
doc = (srcNode && srcNode.get(OWNER_DOCUMENT)) || boundingBox.get(OWNER_DOCUMENT) || contentBox.get(OWNER_DOCUMENT);
// If srcNode (assume it's always in doc), have contentBox take its place (widget render responsible for re-use of srcNode contents)
if (srcNode && !srcNode.compareTo(contentBox) && !contentBox.inDoc(doc)) {
srcNode.replace(contentBox);
}
if (!boundingBox.compareTo(contentBox.get(PARENT_NODE)) && !boundingBox.compareTo(contentBox)) {
// If contentBox box is already in the document, have boundingBox box take it's place
if (contentBox.inDoc(doc)) {
contentBox.replace(boundingBox);
}
boundingBox.appendChild(contentBox);
}
parentNode = parentNode || (defParentNode && Node.one(defParentNode));
if (parentNode) {
parentNode.appendChild(boundingBox);
} else if (!boundingBox.inDoc(doc)) {
Node.one(BODY).insert(boundingBox, 0);
}
},
/**
* Setter for the boundingBox attribute
*
* @method _setBB
* @private
* @param Node/String
* @return Node
*/
_setBB: function(node) {
return this._setBox(this.get(ID), node, this.BOUNDING_TEMPLATE, true);
},
/**
* Setter for the contentBox attribute
*
* @method _setCB
* @private
* @param {Node|String} node
* @return Node
*/
_setCB: function(node) {
return (this.CONTENT_TEMPLATE === null) ? this.get(BOUNDING_BOX) : this._setBox(null, node, this.CONTENT_TEMPLATE, false);
},
/**
* Returns the default value for the contentBox attribute.
*
* For the Widget class, this will be the srcNode if provided, otherwise null (resulting in
* a new contentBox node instance being created)
*
* @method _defaultCB
* @protected
*/
_defaultCB : function(node) {
return this.get(SRC_NODE) || null;
},
/**
* Helper method to set the bounding/content box, or create it from
* the provided template if not found.
*
* @method _setBox
* @private
*
* @param {String} id The node's id attribute
* @param {Node|String} node The node reference
* @param {String} template HTML string template for the node
* @param {boolean} true if this is the boundingBox, false if it's the contentBox
* @return {Node} The node
*/
_setBox : function(id, node, template, isBounding) {
node = Node.one(node);
if (!node) {
node = Node.create(template);
if (isBounding) {
this._bbFromTemplate = true;
} else {
this._cbFromTemplate = true;
}
}
if (!node.get(ID)) {
node.set(ID, id || Y.guid());
}
return node;
},
/**
* Initializes the UI state for the Widget's bounding/content boxes.
*
* @method _renderUI
* @protected
*/
_renderUI: function() {
this._renderBoxClassNames();
this._renderBox(this._parentNode);
},
/**
* Applies standard class names to the boundingBox and contentBox
*
* @method _renderBoxClassNames
* @protected
*/
_renderBoxClassNames : function() {
var classes = this._getClasses(),
cl,
boundingBox = this.get(BOUNDING_BOX),
i;
boundingBox.addClass(_getWidgetClassName());
// Start from Widget Sub Class
for (i = classes.length-3; i >= 0; i--) {
cl = classes[i];
boundingBox.addClass(cl.CSS_PREFIX || _getClassName(cl.NAME.toLowerCase()));
}
// Use instance based name for content box
this.get(CONTENT_BOX).addClass(this.getClassName(CONTENT));
},
/**
* Removes class names representative of the widget's loading state from
* the boundingBox.
*
* @method _removeLoadingClassNames
* @protected
*/
_removeLoadingClassNames: function () {
var boundingBox = this.get(BOUNDING_BOX),
contentBox = this.get(CONTENT_BOX),
instClass = this.getClassName(LOADING),
widgetClass = _getWidgetClassName(LOADING);
boundingBox.removeClass(widgetClass)
.removeClass(instClass);
contentBox.removeClass(widgetClass)
.removeClass(instClass);
},
/**
* Sets up DOM and CustomEvent listeners for the widget.
*
* @method _bindUI
* @protected
*/
_bindUI: function() {
this._bindAttrUI(this._UI_ATTRS.BIND);
this._bindDOM();
},
/**
* @method _unbindUI
* @protected
*/
_unbindUI : function(boundingBox) {
this._unbindDOM(boundingBox);
},
/**
* Sets up DOM listeners, on elements rendered by the widget.
*
* @method _bindDOM
* @protected
*/
_bindDOM : function() {
var oDocument = this.get(BOUNDING_BOX).get(OWNER_DOCUMENT),
focusHandle = Widget._hDocFocus;
// Shared listener across all Widgets.
if (!focusHandle) {
focusHandle = Widget._hDocFocus = oDocument.on("focus", this._onDocFocus, this);
focusHandle.listeners = {
count: 0
};
}
focusHandle.listeners[Y.stamp(this, true)] = true;
focusHandle.listeners.count++;
// Fix for Webkit:
// Document doesn't receive focus in Webkit when the user mouses
// down on it, so the "focused" attribute won't get set to the
// correct value. Keeping this instance based for now, potential better performance.
// Otherwise we'll end up looking up widgets from the DOM on every mousedown.
if (WEBKIT){
this._hDocMouseDown = oDocument.on("mousedown", this._onDocMouseDown, this);
}
},
/**
* @method _unbindDOM
* @protected
*/
_unbindDOM : function(boundingBox) {
var focusHandle = Widget._hDocFocus,
yuid = Y.stamp(this, true),
focusListeners,
mouseHandle = this._hDocMouseDown;
if (focusHandle) {
focusListeners = focusHandle.listeners;
if (focusListeners[yuid]) {
delete focusListeners[yuid];
focusListeners.count--;
}
if (focusListeners.count === 0) {
focusHandle.detach();
Widget._hDocFocus = null;
}
}
if (WEBKIT && mouseHandle) {
mouseHandle.detach();
}
},
/**
* Updates the widget UI to reflect the attribute state.
*
* @method _syncUI
* @protected
*/
_syncUI: function() {
this._syncAttrUI(this._UI_ATTRS.SYNC);
},
/**
* Sets the height on the widget's bounding box element
*
* @method _uiSetHeight
* @protected
* @param {String | Number} val
*/
_uiSetHeight: function(val) {
this._uiSetDim(HEIGHT, val);
this._uiSizeCB((val !== EMPTY_STR && val !== AUTO));
},
/**
* Sets the width on the widget's bounding box element
*
* @method _uiSetWidth
* @protected
* @param {String | Number} val
*/
_uiSetWidth: function(val) {
this._uiSetDim(WIDTH, val);
},
/**
* @method _uiSetDim
* @private
* @param {String} dim The dimension - "width" or "height"
* @param {Number | String} val The value to set
*/
_uiSetDim: function(dimension, val) {
this.get(BOUNDING_BOX).setStyle(dimension, L.isNumber(val) ? val + this.DEF_UNIT : val);
},
/**
* Sets the visible state for the UI
*
* @method _uiSetVisible
* @protected
* @param {boolean} val
*/
_uiSetVisible: function(val) {
this.get(BOUNDING_BOX).toggleClass(this.getClassName(HIDDEN), !val);
},
/**
* Sets the disabled state for the UI
*
* @method _uiSetDisabled
* @protected
* @param {boolean} val
*/
_uiSetDisabled: function(val) {
this.get(BOUNDING_BOX).toggleClass(this.getClassName(DISABLED), val);
},
/**
* Sets the focused state for the UI
*
* @method _uiSetFocused
* @protected
* @param {boolean} val
* @param {string} src String representing the source that triggered an update to
* the UI.
*/
_uiSetFocused: function(val, src) {
var boundingBox = this.get(BOUNDING_BOX);
boundingBox.toggleClass(this.getClassName(FOCUSED), val);
if (src !== UI) {
if (val) {
boundingBox.focus();
} else {
boundingBox.blur();
}
}
},
/**
* Set the tabIndex on the widget's rendered UI
*
* @method _uiSetTabIndex
* @protected
* @param Number
*/
_uiSetTabIndex: function(index) {
var boundingBox = this.get(BOUNDING_BOX);
if (L.isNumber(index)) {
boundingBox.set(TAB_INDEX, index);
} else {
boundingBox.removeAttribute(TAB_INDEX);
}
},
/**
* @method _onDocMouseDown
* @description "mousedown" event handler for the owner document of the
* widget's bounding box.
* @protected
* @param {EventFacade} evt The event facade for the DOM focus event
*/
_onDocMouseDown: function (evt) {
if (this._domFocus) {
this._onDocFocus(evt);
}
},
/**
* DOM focus event handler, used to sync the state of the Widget with the DOM
*
* @method _onDocFocus
* @protected
* @param {EventFacade} evt The event facade for the DOM focus event
*/
_onDocFocus: function (evt) {
var widget = Widget.getByNode(evt.target),
activeWidget = Widget._active;
if (activeWidget && (activeWidget !== widget)) {
activeWidget._domFocus = false;
activeWidget._set(FOCUSED, false, {src:UI});
Widget._active = null;
}
if (widget) {
widget._domFocus = true;
widget._set(FOCUSED, true, {src:UI});
Widget._active = widget;
}
},
/**
* Generic toString implementation for all widgets.
*
* @method toString
* @return {String} The default string value for the widget [ displays the NAME of the instance, and the unique id ]
*/
toString: function() {
// Using deprecated name prop for kweight squeeze.
return this.name + "[" + this.get(ID) + "]";
},
/**
* Default unit to use for dimension values
*
* @property DEF_UNIT
* @type String
*/
DEF_UNIT : "px",
/**
* Default node to render the bounding box to. If not set,
* will default to the current document body.
*
* @property DEF_PARENT_NODE
* @type String | Node
*/
DEF_PARENT_NODE : null,
/**
* Property defining the markup template for content box. If your Widget doesn't
* need the dual boundingBox/contentBox structure, set CONTENT_TEMPLATE to null,
* and contentBox and boundingBox will both point to the same Node.
*
* @property CONTENT_TEMPLATE
* @type String
*/
CONTENT_TEMPLATE : DIV,
/**
* Property defining the markup template for bounding box.
*
* @property BOUNDING_TEMPLATE
* @type String
*/
BOUNDING_TEMPLATE : DIV,
/**
* @method _guid
* @protected
*/
_guid : function() {
return Y.guid();
},
/**
* @method _validTabIndex
* @protected
* @param {Number} tabIndex
*/
_validTabIndex : function (tabIndex) {
return (L.isNumber(tabIndex) || L.isNull(tabIndex));
},
/**
* Binds after listeners for the list of attributes provided
*
* @method _bindAttrUI
* @private
* @param {Array} attrs
*/
_bindAttrUI : function(attrs) {
var i,
l = attrs.length;
for (i = 0; i < l; i++) {
this.after(attrs[i] + CHANGE, this._setAttrUI);
}
},
/**
* Invokes the _uiSet=ATTR NAME> method for the list of attributes provided
*
* @method _syncAttrUI
* @private
* @param {Array} attrs
*/
_syncAttrUI : function(attrs) {
var i, l = attrs.length, attr;
for (i = 0; i < l; i++) {
attr = attrs[i];
this[_UISET + _toInitialCap(attr)](this.get(attr));
}
},
/**
* @method _setAttrUI
* @private
* @param {EventFacade} e
*/
_setAttrUI : function(e) {
if (e.target === this) {
this[_UISET + _toInitialCap(e.attrName)](e.newVal, e.src);
}
},
/**
* The default setter for the strings attribute. Merges partial sets
* into the full string set, to allow users to partial sets of strings
*
* @method _strSetter
* @protected
* @param {Object} strings
* @return {String} The full set of strings to set
*/
_strSetter : function(strings) {
return Y.merge(this.get(STRINGS), strings);
},
/**
* Helper method to get a specific string value
*
* @deprecated Used by deprecated WidgetLocale implementations.
* @method getString
* @param {String} key
* @return {String} The string
*/
getString : function(key) {
return this.get(STRINGS)[key];
},
/**
* Helper method to get the complete set of strings for the widget
*
* @deprecated Used by deprecated WidgetLocale implementations.
* @method getStrings
* @param {String} key
* @return {String} The strings
*/
getStrings : function() {
return this.get(STRINGS);
},
/**
* The lists of UI attributes to bind and sync for widget's _bindUI and _syncUI implementations
*
* @property _UI_ATTRS
* @type Object
* @private
*/
_UI_ATTRS : {
BIND: UI_ATTRS,
SYNC: UI_ATTRS
}
});
Y.Widget = Widget;
}, 'patched-v3.11.0', {
"requires": [
"attribute",
"base-base",
"base-pluginhost",
"classnamemanager",
"event-focus",
"node-base",
"node-style"
],
"skinnable": true
});
YUI.add('widget-htmlparser', function (Y, NAME) {
/**
* Adds HTML Parser support to the base Widget class
*
* @module widget
* @submodule widget-htmlparser
* @for Widget
*/
var Widget = Y.Widget,
Node = Y.Node,
Lang = Y.Lang,
SRC_NODE = "srcNode",
CONTENT_BOX = "contentBox";
/**
* Object hash, defining how attribute values are to be parsed from
* markup contained in the widget's content box. e.g.:
*
* {
* // Set single Node references using selector syntax
* // (selector is run through node.one)
* titleNode: "span.yui-title",
* // Set NodeList references using selector syntax
* // (array indicates selector is to be run through node.all)
* listNodes: ["li.yui-item"],
* // Set other attribute types, using a parse function.
* // Context is set to the widget instance.
* label: function(contentBox) {
* return contentBox.one("span.title").get("innerHTML");
* }
* }
*
*
* @property HTML_PARSER
* @type Object
* @static
*/
Widget.HTML_PARSER = {};
/**
* The build configuration for the Widget class.
*
* Defines the static fields which need to be aggregated,
* when this class is used as the main class passed to
* the Base.build method.
*
* @property _buildCfg
* @type Object
* @static
* @final
* @private
*/
Widget._buildCfg = {
aggregates : ["HTML_PARSER"]
};
/**
* The DOM node to parse for configuration values, passed to the Widget's HTML_PARSER definition
*
* @attribute srcNode
* @type String | Node
* @writeOnce
*/
Widget.ATTRS[SRC_NODE] = {
value: null,
setter: Node.one,
getter: "_getSrcNode",
writeOnce: true
};
Y.mix(Widget.prototype, {
/**
* @method _getSrcNode
* @protected
* @return {Node} The Node to apply HTML_PARSER to
*/
_getSrcNode : function(val) {
return val || this.get(CONTENT_BOX);
},
/**
* Implement the BaseCore _preAddAttrs method hook, to add
* the srcNode and related attributes, so that HTML_PARSER
* (which relies on `this.get("srcNode")`) can merge in it's
* results before the rest of the attributes are added.
*
* @method _preAddAttrs
* @protected
*
* @param attrs {Object} The full hash of statically defined ATTRS
* attributes being added for this instance
*
* @param userVals {Object} The hash of user values passed to
* the constructor
*
* @param lazy {boolean} Whether or not to add the attributes lazily
*/
_preAddAttrs : function(attrs, userVals, lazy) {
var preAttrs = {
id : attrs.id,
boundingBox : attrs.boundingBox,
contentBox : attrs.contentBox,
srcNode : attrs.srcNode
};
this.addAttrs(preAttrs, userVals, lazy);
delete attrs.boundingBox;
delete attrs.contentBox;
delete attrs.srcNode;
delete attrs.id;
if (this._applyParser) {
this._applyParser(userVals);
}
},
/**
* @method _applyParsedConfig
* @protected
* @return {Object} The merged configuration literal
*/
_applyParsedConfig : function(node, cfg, parsedCfg) {
return (parsedCfg) ? Y.mix(cfg, parsedCfg, false) : cfg;
},
/**
* Utility method used to apply the HTML_PARSER
configuration for the
* instance, to retrieve config data values.
*
* @method _applyParser
* @protected
* @param config {Object} User configuration object (will be populated with values from Node)
*/
_applyParser : function(config) {
var widget = this,
srcNode = this._getNodeToParse(),
schema = widget._getHtmlParser(),
parsedConfig,
val;
if (schema && srcNode) {
Y.Object.each(schema, function(v, k, o) {
val = null;
if (Lang.isFunction(v)) {
val = v.call(widget, srcNode);
} else {
if (Lang.isArray(v)) {
val = srcNode.all(v[0]);
if (val.isEmpty()) {
val = null;
}
} else {
val = srcNode.one(v);
}
}
if (val !== null && val !== undefined) {
parsedConfig = parsedConfig || {};
parsedConfig[k] = val;
}
});
}
config = widget._applyParsedConfig(srcNode, config, parsedConfig);
},
/**
* Determines whether we have a node reference which we should try and parse.
*
* The current implementation does not parse nodes generated from CONTENT_TEMPLATE,
* only explicitly set srcNode, or contentBox attributes.
*
* @method _getNodeToParse
* @return {Node} The node reference to apply HTML_PARSER to.
* @private
*/
_getNodeToParse : function() {
var srcNode = this.get("srcNode");
return (!this._cbFromTemplate) ? srcNode : null;
},
/**
* Gets the HTML_PARSER definition for this instance, by merging HTML_PARSER
* definitions across the class hierarchy.
*
* @private
* @method _getHtmlParser
* @return {Object} HTML_PARSER definition for this instance
*/
_getHtmlParser : function() {
// Removed caching for kweight. This is a private method
// and only called once so don't need to cache HTML_PARSER
var classes = this._getClasses(),
parser = {},
i, p;
for (i = classes.length - 1; i >= 0; i--) {
p = classes[i].HTML_PARSER;
if (p) {
Y.mix(parser, p, true);
}
}
return parser;
}
});
}, 'patched-v3.11.0', {"requires": ["widget-base"]});
YUI.add('widget-skin', function (Y, NAME) {
/**
* Provides skin related utlility methods.
*
* @module widget
* @submodule widget-skin
*/
var BOUNDING_BOX = "boundingBox",
CONTENT_BOX = "contentBox",
SKIN = "skin",
_getClassName = Y.ClassNameManager.getClassName;
/**
* Returns the name of the skin that's currently applied to the widget.
*
* Searches up the Widget's ancestor axis for, by default, a class
* yui3-skin-(name), and returns the (name) portion. Otherwise, returns null.
*
* This is only really useful after the widget's DOM structure is in the
* document, either by render or by progressive enhancement.
*
* @method getSkinName
* @for Widget
* @param {String} [skinPrefix] The prefix which the implementation uses for the skin
* ("yui3-skin-" is the default).
*
* NOTE: skinPrefix will be used as part of a regular expression:
*
* new RegExp('\\b' + skinPrefix + '(\\S+)')
*
* Although an unlikely use case, literal characters which may result in an invalid
* regular expression should be escaped.
*
* @return {String} The name of the skin, or null, if a matching skin class is not found.
*/
Y.Widget.prototype.getSkinName = function (skinPrefix) {
var root = this.get( CONTENT_BOX ) || this.get( BOUNDING_BOX ),
match,
search;
skinPrefix = skinPrefix || _getClassName(SKIN, "");
search = new RegExp( '\\b' + skinPrefix + '(\\S+)' );
if ( root ) {
root.ancestor( function ( node ) {
match = node.get( 'className' ).match( search );
return match;
} );
}
return ( match ) ? match[1] : null;
};
}, 'patched-v3.11.0', {"requires": ["widget-base"]});
YUI.add('widget-uievents', function (Y, NAME) {
/**
* Support for Widget UI Events (Custom Events fired by the widget, which wrap the underlying DOM events - e.g. widget:click, widget:mousedown)
*
* @module widget
* @submodule widget-uievents
*/
var BOUNDING_BOX = "boundingBox",
Widget = Y.Widget,
RENDER = "render",
L = Y.Lang,
EVENT_PREFIX_DELIMITER = ":",
// Map of Node instances serving as a delegation containers for a specific
// event type to Widget instances using that delegation container.
_uievts = Y.Widget._uievts = Y.Widget._uievts || {};
Y.mix(Widget.prototype, {
/**
* Destructor logic for UI event infrastructure,
* invoked during Widget destruction.
*
* @method _destroyUIEvents
* @for Widget
* @private
*/
_destroyUIEvents: function() {
var widgetGuid = Y.stamp(this, true);
Y.each(_uievts, function (info, key) {
if (info.instances[widgetGuid]) {
// Unregister this Widget instance as needing this delegated
// event listener.
delete info.instances[widgetGuid];
// There are no more Widget instances using this delegated
// event listener, so detach it.
if (Y.Object.isEmpty(info.instances)) {
info.handle.detach();
if (_uievts[key]) {
delete _uievts[key];
}
}
}
});
},
/**
* Map of DOM events that should be fired as Custom Events by the
* Widget instance.
*
* @property UI_EVENTS
* @for Widget
* @type Object
*/
UI_EVENTS: Y.Node.DOM_EVENTS,
/**
* Returns the node on which to bind delegate listeners.
*
* @method _getUIEventNode
* @for Widget
* @protected
*/
_getUIEventNode: function () {
return this.get(BOUNDING_BOX);
},
/**
* Binds a delegated DOM event listener of the specified type to the
* Widget's outtermost DOM element to facilitate the firing of a Custom
* Event of the same type for the Widget instance.
*
* @method _createUIEvent
* @for Widget
* @param type {String} String representing the name of the event
* @private
*/
_createUIEvent: function (type) {
var uiEvtNode = this._getUIEventNode(),
key = (Y.stamp(uiEvtNode) + type),
info = _uievts[key],
handle;
// For each Node instance: Ensure that there is only one delegated
// event listener used to fire Widget UI events.
if (!info) {
handle = uiEvtNode.delegate(type, function (evt) {
var widget = Widget.getByNode(this);
// Widget could be null if node instance belongs to
// another Y instance.
if (widget) {
if (widget._filterUIEvent(evt)) {
widget.fire(evt.type, { domEvent: evt });
}
}
}, "." + Y.Widget.getClassName());
_uievts[key] = info = { instances: {}, handle: handle };
}
// Register this Widget as using this Node as a delegation container.
info.instances[Y.stamp(this)] = 1;
},
/**
* This method is used to determine if we should fire
* the UI Event or not. The default implementation makes sure
* that for nested delegates (nested unrelated widgets), we don't
* fire the UI event listener more than once at each level.
*
* For example, without the additional filter, if you have nested
* widgets, each widget will have a delegate listener. If you
* click on the inner widget, the inner delegate listener's
* filter will match once, but the outer will match twice
* (based on delegate's design) - once for the inner widget,
* and once for the outer.
*
* @method _filterUIEvent
* @for Widget
* @param {DOMEventFacade} evt
* @return {boolean} true if it's OK to fire the custom UI event, false if not.
* @private
*
*/
_filterUIEvent: function(evt) {
// Either it's hitting this widget's delegate container (and not some other widget's),
// or the container it's hitting is handling this widget's ui events.
return (evt.currentTarget.compareTo(evt.container) || evt.container.compareTo(this._getUIEventNode()));
},
/**
* Determines if the specified event is a UI event.
*
* @private
* @method _isUIEvent
* @for Widget
* @param type {String} String representing the name of the event
* @return {String} Event Returns the name of the UI Event, otherwise
* undefined.
*/
_getUIEvent: function (type) {
if (L.isString(type)) {
var sType = this.parseType(type)[1],
iDelim,
returnVal;
if (sType) {
// TODO: Get delimiter from ET, or have ET support this.
iDelim = sType.indexOf(EVENT_PREFIX_DELIMITER);
if (iDelim > -1) {
sType = sType.substring(iDelim + EVENT_PREFIX_DELIMITER.length);
}
if (this.UI_EVENTS[sType]) {
returnVal = sType;
}
}
return returnVal;
}
},
/**
* Sets up infrastructure required to fire a UI event.
*
* @private
* @method _initUIEvent
* @for Widget
* @param type {String} String representing the name of the event
* @return {String}
*/
_initUIEvent: function (type) {
var sType = this._getUIEvent(type),
queue = this._uiEvtsInitQueue || {};
if (sType && !queue[sType]) {
this._uiEvtsInitQueue = queue[sType] = 1;
this.after(RENDER, function() {
this._createUIEvent(sType);
delete this._uiEvtsInitQueue[sType];
});
}
},
// Override of "on" from Base to facilitate the firing of Widget events
// based on DOM events of the same name/type (e.g. "click", "mouseover").
// Temporary solution until we have the ability to listen to when
// someone adds an event listener (bug 2528230)
on: function (type) {
this._initUIEvent(type);
return Widget.superclass.on.apply(this, arguments);
},
// Override of "publish" from Base to facilitate the firing of Widget events
// based on DOM events of the same name/type (e.g. "click", "mouseover").
// Temporary solution until we have the ability to listen to when
// someone publishes an event (bug 2528230)
publish: function (type, config) {
var sType = this._getUIEvent(type);
if (sType && config && config.defaultFn) {
this._initUIEvent(sType);
}
return Widget.superclass.publish.apply(this, arguments);
}
}, true); // overwrite existing EventTarget methods
}, 'patched-v3.11.0', {"requires": ["node-event-delegate", "widget-base"]});
YUI.add('yui-throttle', function (Y, NAME) {
/**
Throttles a call to a method based on the time between calls. This method is attached
to the `Y` object and is documented there .
var fn = Y.throttle(function() {
counter++;
});
for (i; i< 35000; i++) {
out++;
fn();
}
@module yui
@submodule yui-throttle
*/
/*! Based on work by Simon Willison: http://gist.github.com/292562 */
/**
* Throttles a call to a method based on the time between calls.
* @method throttle
* @for YUI
* @param fn {function} The function call to throttle.
* @param ms {int} The number of milliseconds to throttle the method call.
* Can set globally with Y.config.throttleTime or by call. Passing a -1 will
* disable the throttle. Defaults to 150.
* @return {function} Returns a wrapped function that calls fn throttled.
* @since 3.1.0
*/
Y.throttle = function(fn, ms) {
ms = (ms) ? ms : (Y.config.throttleTime || 150);
if (ms === -1) {
return function() {
fn.apply(this, arguments);
};
}
var last = Y.Lang.now();
return function() {
var now = Y.Lang.now();
if (now - last > ms) {
last = now;
fn.apply(this, arguments);
}
};
};
}, 'patched-v3.11.0', {"requires": ["yui-base"]});
YUI.add('aui-base-core', function (A, NAME) {
var Y = A;
YUI.Env.aliases = YUI.Env.aliases || {};
Y.mix(YUI.Env.aliases, {
"aui-autosize": ["aui-autosize-iframe"],
"aui-base": ["oop","yui-throttle","aui-classnamemanager","aui-debounce","aui-base-core","aui-base-lang","aui-node-base"],
"aui-base-deprecated": ["aui-base","aui-node","aui-component","aui-delayed-task-deprecated","aui-selector","aui-event-base"],
"aui-button": ["aui-button-core"],
"aui-collection": ["aui-map","aui-set","aui-linkedset"],
"aui-color-picker-deprecated": ["aui-color-picker-base-deprecated","aui-color-picker-grid-plugin-deprecated"],
"aui-datasource-control-deprecated": ["aui-datasource-control-base-deprecated","aui-input-text-control-deprecated"],
"aui-datatable": ["aui-datatable-edit","aui-datatable-highlight","aui-datatable-selection","aui-datatable-property-list"],
"aui-datepicker-deprecated": ["aui-datepicker-base-deprecated","aui-datepicker-select-deprecated"],
"aui-diagram-builder": ["aui-diagram-builder-base","aui-diagram-builder-connector","aui-diagram-builder-impl"],
"aui-event": ["aui-event-base"],
"aui-form-builder": ["aui-form-builder-base","aui-form-builder-field-base","aui-form-builder-field-button","aui-form-builder-field-checkbox","aui-form-builder-field-fieldset","aui-form-builder-field-file-upload","aui-form-builder-field-multiple-choice","aui-form-builder-field-radio","aui-form-builder-field-select","aui-form-builder-field-text","aui-form-builder-field-textarea","aui-tooltip-base"],
"aui-form-deprecated": ["aui-form-base-deprecated","aui-form-combobox-deprecated","aui-form-field-deprecated","aui-form-select-deprecated","aui-form-textarea-deprecated","aui-form-textfield-deprecated"],
"aui-image-viewer": ["aui-image-viewer-base","aui-image-viewer-gallery","aui-image-viewer-media"],
"aui-io": ["aui-io-request"],
"aui-io-deprecated": ["aui-io-request","aui-io-plugin-deprecated"],
"aui-node": ["aui-node-base"],
"aui-overlay-deprecated": ["aui-overlay-base-deprecated","aui-overlay-context-deprecated","aui-overlay-context-panel-deprecated","aui-overlay-manager-deprecated","aui-overlay-mask-deprecated"],
"aui-rating": ["aui-rating-base","aui-rating-thumb"],
"aui-resize-deprecated": ["aui-resize-base-deprecated","aui-resize-constrain-deprecated"],
"aui-scheduler": ["aui-scheduler-base","aui-scheduler-event-recorder","aui-scheduler-view-agenda","aui-scheduler-view-day","aui-scheduler-view-month","aui-scheduler-view-table-dd","aui-scheduler-view-table","aui-scheduler-view-week"],
"aui-search": ["aui-search-tst"],
"aui-sortable": ["aui-sortable-layout","aui-sortable-list"],
"aui-surface": ["aui-surface-app","aui-surface-screen"],
"aui-toggler": ["aui-toggler-base","aui-toggler-delegate"],
"aui-tooltip": ["aui-tooltip-base","aui-tooltip-delegate"],
"aui-tpl-snippets-deprecated": ["aui-tpl-snippets-base-deprecated","aui-tpl-snippets-checkbox-deprecated","aui-tpl-snippets-input-deprecated","aui-tpl-snippets-select-deprecated","aui-tpl-snippets-textarea-deprecated"],
"aui-tree": ["aui-tree-data","aui-tree-io","aui-tree-node","aui-tree-paginator","aui-tree-view"],
"aui-widget": ["aui-widget-cssclass","aui-widget-toolbars"],
"aui-widget-core": ["aui-widget-cssclass"]
});
/* This file is auto-generated by (yogi loader --yes --mix --js js/aui-loader.js --json js/aui-loader.json --start ../) */
/*jshint maxlen:900, eqeqeq: false */
/**
* YUI 3 module metadata
* @module loader
* @submodule loader-yui3
*/
YUI.Env[Y.version].modules = YUI.Env[Y.version].modules || {};
Y.mix(YUI.Env[Y.version].modules, {
"aui-ace-autocomplete-base": {
"requires": [
"aui-ace-editor"
]
},
"aui-ace-autocomplete-freemarker": {
"requires": [
"aui-ace-autocomplete-templateprocessor"
]
},
"aui-ace-autocomplete-list": {
"requires": [
"aui-ace-autocomplete-base",
"overlay",
"widget-autohide"
],
"skinnable": true
},
"aui-ace-autocomplete-plugin": {
"requires": [
"aui-ace-autocomplete-list",
"plugin"
]
},
"aui-ace-autocomplete-templateprocessor": {
"requires": [
"aui-ace-autocomplete-base"
]
},
"aui-ace-autocomplete-velocity": {
"requires": [
"aui-ace-autocomplete-templateprocessor"
]
},
"aui-ace-editor": {
"requires": [
"aui-node",
"aui-component"
]
},
"aui-aria": {
"requires": [
"plugin",
"aui-component"
]
},
"aui-arraysort": {
"requires": [
"arraysort"
]
},
"aui-audio": {
"requires": [
"aui-node",
"aui-component",
"querystring-stringify-simple"
],
"skinnable": true
},
"aui-autocomplete-deprecated": {
"requires": [
"aui-base-deprecated",
"aui-overlay-base-deprecated",
"datasource",
"dataschema",
"aui-form-combobox-deprecated"
],
"skinnable": true
},
"aui-autosize": {
"use": [
"aui-autosize-iframe"
]
},
"aui-autosize-deprecated": {
"requires": [
"event-valuechange",
"plugin",
"aui-base-deprecated"
],
"skinnable": true
},
"aui-autosize-iframe": {
"requires": [
"plugin",
"aui-component",
"aui-timer",
"aui-node-base"
]
},
"aui-base": {
"use": [
"oop",
"yui-throttle",
"aui-classnamemanager",
"aui-debounce",
"aui-base-core",
"aui-base-lang",
"aui-node-base"
]
},
"aui-base-core": {},
"aui-base-deprecated": {
"use": [
"aui-base",
"aui-node",
"aui-component",
"aui-delayed-task-deprecated",
"aui-selector",
"aui-event-base"
]
},
"aui-base-html5-shiv": {
"condition": {
"name": "aui-base-html5-shiv",
"trigger": "node-base",
"ua": "ie"
}
},
"aui-base-lang": {},
"aui-button": {
"use": [
"aui-button-core"
]
},
"aui-button-core": {
"requires": [
"button",
"button-group",
"button-plugin",
"aui-component",
"aui-widget-cssclass",
"aui-widget-toggle"
]
},
"aui-button-item-deprecated": {
"requires": [
"aui-base-deprecated",
"aui-state-interaction-deprecated",
"widget-child"
],
"skinnable": true
},
"aui-button-search-cancel": {
"requires": [
"array-invoke",
"base",
"base-build",
"event-focus",
"node-screen",
"node-event-delegate",
"aui-node-base",
"aui-classnamemanager",
"aui-event-input"
]
},
"aui-carousel": {
"requires": [
"anim",
"node-event-delegate",
"aui-component"
],
"skinnable": true
},
"aui-char-counter": {
"requires": [
"aui-node",
"aui-event-input",
"aui-component"
]
},
"aui-chart-deprecated": {
"requires": [
"datasource",
"json",
"aui-swf-deprecated"
]
},
"aui-classnamemanager": {
"requires": [
"classnamemanager"
]
},
"aui-collection": {
"use": [
"aui-map",
"aui-set",
"aui-linkedset"
]
},
"aui-color-palette": {
"requires": [
"array-extras",
"aui-palette",
"color-base",
"node-core",
"aui-widget-cssclass",
"aui-widget-toggle"
],
"skinnable": true
},
"aui-color-picker-base": {
"requires": [
"aui-color-palette",
"aui-hsva-palette-modal",
"event-outside"
],
"skinnable": true
},
"aui-color-picker-base-deprecated": {
"requires": [
"dd-drag",
"slider",
"aui-button-item-deprecated",
"aui-color-util-deprecated",
"aui-form-base-deprecated",
"aui-overlay-context-deprecated",
"aui-panel-deprecated"
],
"skinnable": true
},
"aui-color-picker-deprecated": {
"use": [
"aui-color-picker-base-deprecated",
"aui-color-picker-grid-plugin-deprecated"
]
},
"aui-color-picker-grid-plugin-deprecated": {
"requires": [
"plugin",
"aui-color-picker-base-deprecated"
],
"skinnable": true
},
"aui-color-picker-popover": {
"requires": [
"aui-color-picker-base",
"aui-popover",
"aui-widget-cssclass",
"aui-widget-toggle"
],
"skinnable": true
},
"aui-color-util-deprecated": {
"requires": []
},
"aui-component": {
"requires": [
"aui-classnamemanager",
"aui-widget-cssclass",
"aui-widget-toggle",
"base-build",
"widget-base"
]
},
"aui-data-set-deprecated": {
"requires": [
"oop",
"collection",
"base"
]
},
"aui-datasource-control-base-deprecated": {
"requires": [
"datasource",
"dataschema",
"aui-base-deprecated"
]
},
"aui-datasource-control-deprecated": {
"use": [
"aui-datasource-control-base-deprecated",
"aui-input-text-control-deprecated"
]
},
"aui-datatable": {
"use": [
"aui-datatable-edit",
"aui-datatable-highlight",
"aui-datatable-selection",
"aui-datatable-property-list"
]
},
"aui-datatable-core": {
"requires": [
"datatable-base",
"event-key",
"aui-event-base"
],
"skinnable": true
},
"aui-datatable-edit": {
"requires": [
"datatable-base",
"calendar",
"escape",
"overlay",
"sortable",
"aui-datatype",
"aui-toolbar",
"aui-form-validator",
"aui-datatable-core"
],
"skinnable": true
},
"aui-datatable-highlight": {
"requires": [
"aui-datatable-selection"
],
"skinnable": true
},
"aui-datatable-property-list": {
"requires": [
"datatable-scroll",
"datatable-sort",
"aui-datatable-core",
"aui-datatable-edit",
"aui-datatable-highlight",
"aui-datatable-selection",
"aui-widget-cssclass",
"aui-widget-toggle"
],
"skinnable": true
},
"aui-datatable-selection": {
"requires": [
"aui-datatable-core"
],
"skinnable": true
},
"aui-datatype": {
"requires": [
"datatype",
"aui-datatype-date-parse"
]
},
"aui-datatype-date-parse": {
"requires": [
"aui-base-lang",
"datatype-date-format",
"datatype-date-parse",
"intl"
]
},
"aui-datepicker": {
"requires": [
"calendar",
"base",
"base-build",
"aui-datepicker-delegate",
"aui-datepicker-popover"
],
"skinnable": true
},
"aui-datepicker-base-deprecated": {
"requires": [
"calendar",
"aui-datatype",
"aui-overlay-context-deprecated"
],
"skinnable": true
},
"aui-datepicker-delegate": {
"requires": [
"node-event-delegate",
"event-focus",
"aui-event-input",
"aui-datatype-date-parse"
]
},
"aui-datepicker-deprecated": {
"skinnable": true,
"use": [
"aui-datepicker-base-deprecated",
"aui-datepicker-select-deprecated"
]
},
"aui-datepicker-native": {
"requires": [
"base",
"base-build",
"aui-node-base",
"aui-datepicker-delegate"
]
},
"aui-datepicker-popover": {
"requires": [
"aui-classnamemanager",
"aui-popover"
]
},
"aui-datepicker-select-deprecated": {
"requires": [
"aui-datepicker-base-deprecated",
"aui-button-item-deprecated"
],
"skinnable": true
},
"aui-debounce": {},
"aui-delayed-task-deprecated": {
"requires": [
"yui-base"
]
},
"aui-diagram-builder": {
"use": [
"aui-diagram-builder-base",
"aui-diagram-builder-connector",
"aui-diagram-builder-impl"
]
},
"aui-diagram-builder-base": {
"requires": [
"dd",
"collection",
"aui-tabview",
"aui-datatable-property-list"
],
"skinnable": true
},
"aui-diagram-builder-connector": {
"requires": [
"arraylist-add",
"arraylist-filter",
"escape",
"json",
"graphics",
"dd"
],
"skinnable": true
},
"aui-diagram-builder-impl": {
"requires": [
"escape",
"overlay",
"aui-map",
"aui-diagram-builder-base",
"aui-diagram-builder-connector"
],
"skinnable": true
},
"aui-dialog-iframe-deprecated": {
"requires": [
"plugin",
"aui-base-deprecated",
"aui-loading-mask-deprecated"
],
"skinnable": true
},
"aui-editable-deprecated": {
"requires": [
"aui-base-deprecated",
"aui-form-combobox-deprecated",
"escape"
],
"skinnable": true
},
"aui-event": {
"use": [
"aui-event-base"
]
},
"aui-event-base": {
"requires": [
"event-base"
]
},
"aui-event-delegate-change": {
"condition": {
"name": "aui-event-delegate-change",
"trigger": "event-base-ie",
"ua": "ie"
},
"requires": [
"aui-event-base",
"event-delegate",
"event-synthetic"
]
},
"aui-event-delegate-submit": {
"condition": {
"name": "aui-event-delegate-submit",
"trigger": "event-base-ie",
"ua": "ie"
},
"requires": [
"aui-event-base",
"event-delegate",
"event-synthetic"
]
},
"aui-event-input": {
"condition": {
"name": "aui-event-input",
"test": function(A) {
var supportsDOMEvent = A.supportsDOMEvent,
testFeature = A.Features.test,
addFeature = A.Features.add;
if (testFeature('event', 'input') === undefined) {
addFeature('event', 'input', {
test: function() {
return supportsDOMEvent(document.createElement('textarea'), 'input');
}
});
}
return !testFeature('event', 'input');
},
"trigger": "aui-event-base"
},
"requires": [
"aui-event-base",
"event-delegate",
"event-synthetic"
]
},
"aui-form-base-deprecated": {
"requires": [
"io-form",
"querystring-parse",
"aui-base-deprecated",
"aui-data-set-deprecated",
"aui-form-field-deprecated"
]
},
"aui-form-builder": {
"skinnable": true,
"use": [
"aui-form-builder-base",
"aui-form-builder-field-base",
"aui-form-builder-field-button",
"aui-form-builder-field-checkbox",
"aui-form-builder-field-fieldset",
"aui-form-builder-field-file-upload",
"aui-form-builder-field-multiple-choice",
"aui-form-builder-field-radio",
"aui-form-builder-field-select",
"aui-form-builder-field-text",
"aui-form-builder-field-textarea",
"aui-tooltip-base"
]
},
"aui-form-builder-base": {
"requires": [
"escape",
"transition",
"aui-button",
"aui-collection",
"aui-diagram-builder-base",
"aui-sortable-list",
"aui-tabview"
],
"skinnable": true
},
"aui-form-builder-field-base": {
"requires": [
"panel",
"aui-datatype"
],
"skinnable": true
},
"aui-form-builder-field-button": {
"requires": [
"aui-form-builder-field-base"
]
},
"aui-form-builder-field-checkbox": {
"requires": [
"aui-form-builder-field-base"
]
},
"aui-form-builder-field-fieldset": {
"requires": [
"aui-form-builder-field-base"
]
},
"aui-form-builder-field-file-upload": {
"requires": [
"aui-form-builder-field-base"
]
},
"aui-form-builder-field-multiple-choice": {
"requires": [
"aui-form-builder-field-base"
]
},
"aui-form-builder-field-radio": {
"requires": [
"aui-form-builder-field-base"
]
},
"aui-form-builder-field-select": {
"requires": [
"aui-form-builder-field-base"
]
},
"aui-form-builder-field-text": {
"requires": [
"aui-form-builder-field-base"
]
},
"aui-form-builder-field-textarea": {
"requires": [
"aui-form-builder-field-base"
]
},
"aui-form-combobox-deprecated": {
"requires": [
"aui-form-textarea-deprecated",
"aui-toolbar"
],
"skinnable": true
},
"aui-form-deprecated": {
"use": [
"aui-form-base-deprecated",
"aui-form-combobox-deprecated",
"aui-form-field-deprecated",
"aui-form-select-deprecated",
"aui-form-textarea-deprecated",
"aui-form-textfield-deprecated"
]
},
"aui-form-field-deprecated": {
"requires": [
"aui-base-deprecated",
"aui-component"
]
},
"aui-form-select-deprecated": {
"requires": [
"aui-form-field-deprecated"
]
},
"aui-form-textarea-deprecated": {
"requires": [
"node-pluginhost",
"aui-autosize-deprecated",
"aui-form-textfield-deprecated"
]
},
"aui-form-textfield-deprecated": {
"requires": [
"aui-form-field-deprecated"
]
},
"aui-form-validator": {
"requires": [
"escape",
"selector-css3",
"node-event-delegate",
"aui-node",
"aui-component",
"aui-event-input"
]
},
"aui-hsv-palette": {
"requires": [
"aui-classnamemanager",
"aui-widget-cssclass",
"aui-widget-toggle",
"aui-event-input",
"base-build",
"clickable-rail",
"color-hsv",
"dd-constrain",
"slider",
"widget"
],
"skinnable": true
},
"aui-hsva-palette": {
"requires": [
"aui-hsv-palette"
],
"skinnable": true
},
"aui-hsva-palette-modal": {
"requires": [
"aui-hsva-palette",
"aui-modal"
],
"skinnable": true
},
"aui-image-cropper": {
"requires": [
"resize-base",
"resize-constrain",
"dd-constrain",
"aui-node-base",
"aui-component"
],
"skinnable": true
},
"aui-image-viewer": {
"use": [
"aui-image-viewer-base",
"aui-image-viewer-gallery",
"aui-image-viewer-media"
]
},
"aui-image-viewer-base": {
"requires": [
"anim",
"widget",
"widget-modality",
"widget-position",
"widget-position-align",
"widget-position-constrain",
"widget-stack",
"widget-stdmod",
"aui-event",
"aui-node-base",
"aui-widget-cssclass",
"aui-widget-toggle"
],
"skinnable": true
},
"aui-image-viewer-gallery": {
"requires": [
"aui-image-viewer-base",
"aui-pagination",
"aui-toolbar"
],
"skinnable": true
},
"aui-image-viewer-media": {
"requires": [
"plugin",
"aui-image-viewer-base",
"aui-pagination",
"aui-toolbar"
]
},
"aui-input-text-control-deprecated": {
"requires": [
"aui-base-deprecated",
"aui-datasource-control-base-deprecated",
"aui-form-combobox-deprecated"
]
},
"aui-io": {
"use": [
"aui-io-request"
]
},
"aui-io-deprecated": {
"use": [
"aui-io-request",
"aui-io-plugin-deprecated"
]
},
"aui-io-plugin-deprecated": {
"requires": [
"aui-overlay-base-deprecated",
"aui-parse-content",
"aui-io-request",
"aui-loading-mask-deprecated"
]
},
"aui-io-request": {
"requires": [
"io-base",
"json",
"plugin",
"querystring-stringify",
"aui-component"
]
},
"aui-io-request-deprecated": {
"requires": [
"io-base",
"json",
"plugin",
"querystring-stringify",
"aui-base-deprecated"
]
},
"aui-linkedset": {
"requires": [
"aui-set"
]
},
"aui-live-search-deprecated": {
"requires": [
"aui-base-deprecated"
]
},
"aui-loading-mask-deprecated": {
"requires": [
"plugin",
"aui-overlay-mask-deprecated"
],
"skinnable": true
},
"aui-map": {
"requires": [
"base-build"
]
},
"aui-messaging": {
"requires": [
"querystring",
"aui-timer"
]
},
"aui-modal": {
"requires": [
"widget",
"widget-autohide",
"widget-buttons",
"widget-modality",
"widget-position",
"widget-position-align",
"widget-position-constrain",
"widget-stack",
"widget-stdmod",
"dd-plugin",
"dd-constrain",
"resize-plugin",
"aui-classnamemanager",
"aui-widget-cssclass",
"aui-widget-toggle",
"aui-widget-toolbars"
]
},
"aui-node": {
"use": [
"aui-node-base"
]
},
"aui-node-base": {
"requires": [
"array-extras",
"aui-base-lang",
"aui-classnamemanager",
"aui-debounce",
"node"
]
},
"aui-node-html5": {
"condition": {
"name": "aui-node-html5",
"trigger": "aui-node",
"ua": "ie"
},
"requires": [
"collection",
"aui-node-base"
]
},
"aui-overlay-base-deprecated": {
"requires": [
"widget-position",
"widget-stack",
"widget-position-align",
"widget-position-constrain",
"widget-stdmod",
"aui-component"
]
},
"aui-overlay-context-deprecated": {
"requires": [
"aui-overlay-manager-deprecated",
"aui-delayed-task-deprecated",
"aui-aria"
]
},
"aui-overlay-context-panel-deprecated": {
"requires": [
"anim",
"aui-overlay-context-deprecated"
],
"skinnable": true
},
"aui-overlay-deprecated": {
"use": [
"aui-overlay-base-deprecated",
"aui-overlay-context-deprecated",
"aui-overlay-context-panel-deprecated",
"aui-overlay-manager-deprecated",
"aui-overlay-mask-deprecated"
]
},
"aui-overlay-manager-deprecated": {
"requires": [
"overlay",
"plugin",
"aui-base-deprecated",
"aui-overlay-base-deprecated"
]
},
"aui-overlay-mask-deprecated": {
"requires": [
"event-resize",
"aui-base-deprecated",
"aui-overlay-base-deprecated"
],
"skinnable": true
},
"aui-pagination": {
"requires": [
"node-event-delegate",
"aui-node",
"aui-component",
"widget-htmlparser"
]
},
"aui-palette": {
"requires": [
"base-build",
"event-hover",
"widget",
"aui-classnamemanager",
"aui-base",
"aui-widget-cssclass",
"aui-widget-toggle"
],
"skinnable": true
},
"aui-parse-content": {
"requires": [
"async-queue",
"plugin",
"io-base",
"aui-component",
"aui-node-base"
]
},
"aui-popover": {
"requires": [
"transition",
"widget",
"widget-autohide",
"widget-buttons",
"widget-modality",
"widget-position",
"widget-position-align",
"widget-position-constrain",
"widget-stack",
"widget-stdmod",
"aui-classnamemanager",
"aui-widget-cssclass",
"aui-widget-toggle",
"aui-widget-toolbars",
"aui-widget-trigger",
"aui-widget-position-align-suggestion",
"aui-component",
"aui-node-base"
]
},
"aui-progressbar": {
"requires": [
"aui-node",
"aui-component",
"aui-aria"
]
},
"aui-promise": {
"requires": [
"array-invoke",
"promise",
"oop"
]
},
"aui-rating": {
"use": [
"aui-rating-base",
"aui-rating-thumb"
]
},
"aui-rating-base": {
"requires": [
"widget-htmlparser",
"widget-uievents",
"aui-component",
"aui-node-base"
],
"skinnable": true
},
"aui-rating-thumb": {
"requires": [
"aui-rating-base"
]
},
"aui-resize-base-deprecated": {
"requires": [
"dd-drag",
"dd-delegate",
"dd-drop",
"aui-base-deprecated"
],
"skinnable": true
},
"aui-resize-constrain-deprecated": {
"requires": [
"dd-constrain",
"plugin",
"aui-resize-base-deprecated"
]
},
"aui-resize-deprecated": {
"skinnable": true,
"use": [
"aui-resize-base-deprecated",
"aui-resize-constrain-deprecated"
]
},
"aui-scheduler": {
"use": [
"aui-scheduler-base",
"aui-scheduler-event-recorder",
"aui-scheduler-view-agenda",
"aui-scheduler-view-day",
"aui-scheduler-view-month",
"aui-scheduler-view-table-dd",
"aui-scheduler-view-table",
"aui-scheduler-view-week"
]
},
"aui-scheduler-base": {
"requires": [
"model",
"model-list",
"widget-stdmod",
"color-hsl",
"aui-event-base",
"aui-node-base",
"aui-component",
"aui-datatype",
"aui-button"
],
"skinnable": true
},
"aui-scheduler-event-recorder": {
"requires": [
"querystring",
"io-form",
"overlay",
"aui-scheduler-base",
"aui-popover"
],
"skinnable": true
},
"aui-scheduler-view-agenda": {
"requires": [
"aui-scheduler-base"
],
"skinnable": true
},
"aui-scheduler-view-day": {
"requires": [
"dd-drag",
"dd-delegate",
"dd-drop",
"dd-constrain",
"aui-scheduler-view-table"
],
"skinnable": true
},
"aui-scheduler-view-month": {
"requires": [
"aui-scheduler-view-table"
],
"skinnable": true
},
"aui-scheduler-view-table": {
"requires": [
"overlay",
"aui-scheduler-base"
],
"skinnable": true
},
"aui-scheduler-view-table-dd": {
"requires": [
"dd-drag",
"dd-delegate",
"dd-drop",
"aui-scheduler-view-table"
]
},
"aui-scheduler-view-week": {
"requires": [
"aui-scheduler-view-day"
],
"skinnable": true
},
"aui-scroller-deprecated": {
"requires": [
"event-mouseenter",
"aui-base-deprecated",
"aui-simple-anim-deprecated"
],
"skinnable": true
},
"aui-search": {
"use": [
"aui-search-tst"
]
},
"aui-search-tst": {
"requires": [
"aui-component"
]
},
"aui-selector": {
"requires": [
"selector-css3",
"aui-classnamemanager"
]
},
"aui-set": {
"requires": [
"aui-map"
]
},
"aui-simple-anim-deprecated": {
"requires": [
"aui-base-deprecated"
]
},
"aui-skin-deprecated": {
"type": "css"
},
"aui-sortable": {
"use": [
"aui-sortable-layout",
"aui-sortable-list"
]
},
"aui-sortable-layout": {
"requires": [
"dd-delegate",
"dd-drag",
"dd-drop",
"dd-proxy",
"aui-node",
"aui-component"
],
"skinnable": true
},
"aui-sortable-list": {
"requires": [
"dd-drag",
"dd-drop",
"dd-proxy",
"aui-node",
"aui-component"
]
},
"aui-state-interaction-deprecated": {
"requires": [
"aui-base-deprecated",
"plugin"
]
},
"aui-surface": {
"use": [
"aui-surface-app",
"aui-surface-screen"
]
},
"aui-surface-app": {
"requires": [
"event-delegate",
"node-event-html5",
"aui-surface-base",
"aui-surface-screen",
"aui-surface-screen-route"
]
},
"aui-surface-base": {
"requires": [
"base-build",
"node-style",
"timers",
"aui-debounce",
"aui-promise",
"aui-parse-content"
]
},
"aui-surface-screen": {
"requires": [
"base-build"
]
},
"aui-surface-screen-html": {
"requires": [
"io",
"aui-promise",
"aui-surface-screen",
"aui-url"
]
},
"aui-surface-screen-route": {
"requires": [
"base-build"
]
},
"aui-swf-deprecated": {
"requires": [
"querystring-parse-simple",
"querystring-stringify-simple",
"aui-base-deprecated"
]
},
"aui-tabview": {
"requires": [
"selector-css3",
"tabview",
"aui-component"
]
},
"aui-template-deprecated": {
"requires": [
"aui-base-deprecated"
]
},
"aui-text-data-unicode": {
"requires": [
"text"
]
},
"aui-text-unicode": {
"requires": [
"aui-text-data-unicode"
]
},
"aui-textboxlist-deprecated": {
"requires": [
"anim-node-plugin",
"aui-autocomplete-deprecated",
"aui-button-item-deprecated",
"aui-data-set-deprecated",
"escape",
"node-focusmanager"
],
"skinnable": true
},
"aui-timepicker": {
"requires": [
"autocomplete",
"aui-datepicker-delegate",
"aui-datepicker-popover"
],
"skinnable": true
},
"aui-timepicker-native": {
"requires": [
"base",
"base-build",
"aui-node-base",
"aui-datepicker-delegate",
"aui-datepicker-native"
]
},
"aui-timer": {
"requires": [
"oop"
]
},
"aui-toggler": {
"use": [
"aui-toggler-base",
"aui-toggler-delegate"
]
},
"aui-toggler-base": {
"requires": [
"transition",
"aui-selector",
"aui-event-base",
"aui-node",
"aui-component"
],
"skinnable": true
},
"aui-toggler-delegate": {
"requires": [
"array-invoke",
"node-event-delegate",
"aui-toggler-base"
]
},
"aui-toolbar": {
"requires": [
"arraylist",
"arraylist-add",
"aui-component",
"aui-button-core"
]
},
"aui-tooltip": {
"use": [
"aui-tooltip-base",
"aui-tooltip-delegate"
]
},
"aui-tooltip-base": {
"requires": [
"escape",
"event-hover",
"transition",
"widget",
"widget-autohide",
"widget-position",
"widget-position-align",
"widget-position-constrain",
"widget-stack",
"widget-stdmod",
"aui-classnamemanager",
"aui-component",
"aui-widget-cssclass",
"aui-widget-toggle",
"aui-widget-trigger",
"aui-widget-position-align-suggestion",
"aui-node-base"
]
},
"aui-tooltip-delegate": {
"requires": [
"node-event-delegate",
"aui-tooltip-base"
]
},
"aui-tooltip-deprecated": {
"requires": [
"aui-overlay-context-panel-deprecated"
],
"skinnable": true
},
"aui-tpl-snippets-base-deprecated": {
"requires": [
"aui-template-deprecated"
]
},
"aui-tpl-snippets-checkbox-deprecated": {
"requires": [
"aui-tpl-snippets-base-deprecated"
]
},
"aui-tpl-snippets-deprecated": {
"use": [
"aui-tpl-snippets-base-deprecated",
"aui-tpl-snippets-checkbox-deprecated",
"aui-tpl-snippets-input-deprecated",
"aui-tpl-snippets-select-deprecated",
"aui-tpl-snippets-textarea-deprecated"
]
},
"aui-tpl-snippets-input-deprecated": {
"requires": [
"aui-tpl-snippets-base-deprecated"
]
},
"aui-tpl-snippets-select-deprecated": {
"requires": [
"aui-tpl-snippets-base-deprecated"
]
},
"aui-tpl-snippets-textarea-deprecated": {
"requires": [
"aui-tpl-snippets-base-deprecated"
]
},
"aui-tree": {
"use": [
"aui-tree-data",
"aui-tree-io",
"aui-tree-node",
"aui-tree-paginator",
"aui-tree-view"
]
},
"aui-tree-data": {
"requires": [
"aui-base-core",
"aui-base-lang",
"aui-node-base",
"aui-timer",
"aui-component"
]
},
"aui-tree-io": {
"requires": [
"aui-component",
"aui-io"
]
},
"aui-tree-node": {
"requires": [
"json",
"querystring-stringify",
"aui-tree-data",
"aui-tree-io",
"aui-tree-paginator"
]
},
"aui-tree-paginator": {
"requires": [
"yui-base"
]
},
"aui-tree-view": {
"requires": [
"dd-delegate",
"dd-proxy",
"aui-tree-node",
"aui-tree-paginator",
"aui-tree-io"
],
"skinnable": true
},
"aui-url": {
"requires": [
"oop",
"querystring-parse",
"querystring-stringify"
]
},
"aui-video": {
"requires": [
"querystring-stringify-simple",
"aui-node",
"aui-component",
"aui-debounce"
],
"skinnable": true
},
"aui-viewport": {
"requires": [
"aui-node",
"aui-component"
]
},
"aui-widget": {
"use": [
"aui-widget-cssclass",
"aui-widget-toolbars"
]
},
"aui-widget-core": {
"use": [
"aui-widget-cssclass"
]
},
"aui-widget-cssclass": {
"requires": [
"widget-base"
]
},
"aui-widget-position-align-suggestion": {
"requires": [
"widget-position-align",
"widget-stdmod"
]
},
"aui-widget-toggle": {},
"aui-widget-toolbars": {
"requires": [
"widget-stdmod",
"aui-toolbar"
]
},
"aui-widget-trigger": {
"requires": [
"node"
]
}
});
YUI.Env[Y.version].md5 = '61c8295230e4f1de4df2b86169983827';
/*
* Alloy JavaScript Library
* http://alloy.liferay.com/
*
* Copyright (c) 2010 Liferay Inc.
* http://alloy.liferay.com/LICENSE.txt
*
* Nate Cavanaugh (nathan.cavanaugh@liferay.com)
* Eduardo Lundgren (eduardo.lundgren@liferay.com)
*
* Attribution/Third-party licenses
* http://alloy.liferay.com/ATTRIBUTION.txt
*/
// Simple version of http://perfectionkills.com/detecting-event-support-without-browser-sniffing/
A.supportsDOMEvent = function(domNode, eventName) {
eventName = 'on' + eventName;
if (!(eventName in domNode)) {
if (!domNode.setAttribute) {
domNode = A.config.doc.createElement('div');
}
if (domNode.setAttribute) {
domNode.setAttribute(eventName, '');
return (typeof domNode[eventName] === 'function');
}
}
domNode = null;
return true;
};
(function() {
var slice = Array.prototype.slice;
YUI.prototype.ready = function() {
var instance = this,
xargs = arguments,
index = xargs.length - 1,
modules = slice.call(arguments, 0, index);
modules.unshift('event-base');
modules.push(function(instance) {
var args = arguments;
instance.on('domready', function() {
xargs[index].apply(this, args);
});
});
instance.use.apply(instance, modules);
};
}());
}, '2.0.0');
YUI.add('aui-base-lang', function (A, NAME) {
(function() {
var Lang = A.Lang,
AArray = A.Array,
AObject = A.Object,
isArray = Lang.isArray,
isNumber = Lang.isNumber,
isString = Lang.isString,
isUndefined = Lang.isUndefined,
owns = AObject.owns;
A.fn = function(fn, context, args) {
var wrappedFn,
dynamicLookup;
// Explicitly set function arguments
if (!isNumber(fn)) {
var xargs = arguments;
if (xargs.length > 2) {
xargs = AArray(xargs, 2, true);
}
dynamicLookup = (isString(fn) && context);
wrappedFn = function() {
var method = (!dynamicLookup) ? fn : context[fn];
return method.apply(context || fn, xargs);
};
}
else {
// Set function arity
var argLength = fn;
fn = context;
context = args;
dynamicLookup = (isString(fn) && context);
wrappedFn = function() {
var method = (!dynamicLookup) ? fn : context[fn],
returnValue;
context = context || method;
if (argLength > 0) {
returnValue = method.apply(context, AArray(arguments, 0, true).slice(0, argLength));
}
else {
returnValue = method.call(context);
}
return returnValue;
};
}
return wrappedFn;
};
/**
* A.Lang
*/
A.mix(Lang, {
constrain: function(num, min, max) {
return Math.min(Math.max(num, min), max);
},
emptyFn: function() {},
emptyFnFalse: function() {
return false;
},
emptyFnTrue: function() {
return true;
},
isGuid: function(id) {
return String(id).indexOf(A.Env._guidp) === 0;
},
toFloat: function(value, defaultValue) {
return parseFloat(value) || defaultValue || 0;
},
toInt: function(value, radix, defaultValue) {
return parseInt(value, radix || 10) || defaultValue || 0;
}
});
/**
* A.Array
*/
A.mix(AArray, {
remove: function(a, from, to) {
var rest = a.slice((to || from) + 1 || a.length);
a.length = (from < 0) ? (a.length + from) : from;
return a.push.apply(a, rest);
},
removeItem: function(a, item) {
var index = AArray.indexOf(a, item);
if (index > -1) {
return AArray.remove(a, index);
}
return a;
}
});
/**
* A.Labg.String
*/
var LString = A.namespace('Lang.String'),
DOC = A.config.doc,
INNER_HTML = 'innerHTML',
NORMALIZE = 'normalize',
REGEX_DASH = /-([a-z])/gi,
REGEX_ESCAPE_REGEX = /([.*+?^$(){}|[\]\/\\])/g,
REGEX_NL2BR = /\r?\n/g,
REGEX_STRIP_SCRIPTS = /(?:)((\n|\r|.)*?)(?:<\/script>)/gi,
REGEX_STRIP_TAGS = /<\/?[^>]+>/gi,
REGEX_UNCAMELIZE = /([a-zA-Z][a-zA-Z])([A-Z])([a-z])/g,
REGEX_UNCAMELIZE_REPLACE_SEPARATOR = /([a-z])([A-Z])/g,
STR_BLANK = '',
STR_AMP = '&',
STR_CHEVRON_LEFT = '<',
STR_ELLIPSIS = '...',
STR_END = 'end',
STR_HASH = '#',
STR_MIDDLE = 'middle',
STR_START = 'start',
STR_ZERO = '0',
STR_G = 'g',
STR_S = 's',
htmlUnescapedValues = [],
MAP_HTML_CHARS_ESCAPED = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
'\'': ''',
'/': '/',
'`': '`'
},
htmlChar,
MAP_HTML_CHARS_UNESCAPED = {};
for (htmlChar in MAP_HTML_CHARS_ESCAPED) {
if (MAP_HTML_CHARS_ESCAPED.hasOwnProperty(htmlChar)) {
var escapedValue = MAP_HTML_CHARS_ESCAPED[htmlChar];
MAP_HTML_CHARS_UNESCAPED[escapedValue] = htmlChar;
htmlUnescapedValues.push(htmlChar);
}
}
var REGEX_HTML_ESCAPE = new RegExp('[' + htmlUnescapedValues.join(STR_BLANK) + ']', 'g'),
REGEX_HTML_UNESCAPE = /&([^;]+);/g;
A.mix(LString, {
camelize: A.cached(
function(str, separator) {
var regex = REGEX_DASH;
str = String(str);
if (separator) {
regex = new RegExp(separator + '([a-z])', 'gi');
}
return str.replace(regex, LString._camelize);
}
),
capitalize: A.cached(
function(str) {
if (str) {
str = String(str);
str = str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();
}
return str;
}
),
contains: function(str, searchString) {
return str.indexOf(searchString) !== -1;
},
defaultValue: function(str, defaultValue) {
if (isUndefined(str) || str === STR_BLANK) {
if (isUndefined(defaultValue)) {
defaultValue = STR_BLANK;
}
str = defaultValue;
}
return str;
},
endsWith: function(str, suffix) {
var length = (str.length - suffix.length);
return ((length >= 0) && (str.indexOf(suffix, length) === length));
},
escapeHTML: function(str) {
return str.replace(REGEX_HTML_ESCAPE, LString._escapeHTML);
},
// Courtesy of: http://simonwillison.net/2006/Jan/20/escape/
escapeRegEx: function(str) {
return str.replace(REGEX_ESCAPE_REGEX, '\\$1');
},
nl2br: function(str) {
var instance = this;
return String(str).replace(REGEX_NL2BR, ' ');
},
padNumber: function(num, length, precision) {
var str = precision ? Number(num).toFixed(precision) : String(num);
var index = str.indexOf('.');
if (index === -1) {
index = str.length;
}
return LString.repeat(STR_ZERO, Math.max(0, length - index)) + str;
},
pluralize: function(count, singularVersion, pluralVersion) {
var suffix;
if (count === 1) {
suffix = singularVersion;
}
else {
suffix = pluralVersion || singularVersion + STR_S;
}
return count + ' ' + suffix;
},
prefix: function(prefix, str) {
str = String(str);
if (str.indexOf(prefix) !== 0) {
str = prefix + str;
}
return str;
},
remove: function(str, substitute, all) {
var re = new RegExp(LString.escapeRegEx(substitute), all ? STR_G : STR_BLANK);
return str.replace(re, STR_BLANK);
},
removeAll: function(str, substitute) {
return LString.remove(str, substitute, true);
},
repeat: function(str, length) {
return new Array(length + 1).join(str);
},
round: function(value, precision) {
value = Number(value);
if (isNumber(precision)) {
precision = Math.pow(10, precision);
value = Math.round(value * precision) / precision;
}
return value;
},
startsWith: function(str, prefix) {
return (str.lastIndexOf(prefix, 0) === 0);
},
stripScripts: function(str) {
if (str) {
str = String(str).replace(REGEX_STRIP_SCRIPTS, STR_BLANK);
}
return str;
},
stripTags: function(str) {
var instance = this;
if (str) {
str = String(str).replace(REGEX_STRIP_TAGS, STR_BLANK);
}
return str;
},
substr: function(str, start, length) {
return String(str).substr(start, length);
},
uncamelize: A.cached(
function(str, separator) {
separator = separator || ' ';
str = String(str);
str = str.replace(REGEX_UNCAMELIZE, '$1' + separator + '$2$3');
str = str.replace(REGEX_UNCAMELIZE_REPLACE_SEPARATOR, '$1' + separator + '$2');
return str;
}
),
toLowerCase: function(str) {
return String(str).toLowerCase();
},
toUpperCase: function(str) {
return String(str).toUpperCase();
},
trim: Lang.trim,
truncate: function(str, length, where) {
str = String(str);
var strLength = str.length;
if (str && strLength > length) {
where = where || STR_END;
if (where === STR_END) {
str = str.substr(0, length - STR_ELLIPSIS.length) + STR_ELLIPSIS;
}
else if (where === STR_MIDDLE) {
var middlePoint = Math.floor(length / 2);
str = str.substr(0, middlePoint) + STR_ELLIPSIS + str.substr(strLength - middlePoint);
}
else if (where === STR_START) {
str = STR_ELLIPSIS + str.substr(strLength - length);
}
}
return str;
},
undef: function(str) {
if (isUndefined(str)) {
str = STR_BLANK;
}
return str;
},
// inspired from Google unescape entities
unescapeEntities: function(str) {
if (LString.contains(str, STR_AMP)) {
if (DOC && !LString.contains(str, STR_CHEVRON_LEFT)) {
str = LString._unescapeEntitiesUsingDom(str);
}
else {
str = LString.unescapeHTML(str);
}
}
return str;
},
unescapeHTML: function(str) {
return str.replace(REGEX_HTML_UNESCAPE, LString._unescapeHTML);
},
_camelize: function(match0, match1) {
return match1.toUpperCase();
},
_escapeHTML: function(match) {
return MAP_HTML_CHARS_ESCAPED[match];
},
_unescapeHTML: function(match, entity) {
var value = MAP_HTML_CHARS_UNESCAPED[match] || match;
if (!value && entity.charAt(0) === STR_HASH) {
var charCode = Number(STR_ZERO + value.substr(1));
if (!isNaN(charCode)) {
value = String.fromCharCode(charCode);
}
}
return value;
},
_unescapeEntitiesUsingDom: function(str) {
var el = DOC.createElement('a');
el[INNER_HTML] = str;
if (el[NORMALIZE]) {
el[NORMALIZE]();
}
str = el.firstChild.nodeValue;
el[INNER_HTML] = STR_BLANK;
return str;
}
});
/**
* A.Object
*/
/**
* Maps an object to an array, using the return value of fn as the values
* for the new array.
*/
AObject.map = function(obj, fn, context) {
var map = [],
i;
for (i in obj) {
if (owns(obj, i)) {
map[map.length] = fn.call(context, obj[i], i, obj);
}
}
return map;
};
/**
* Maps an array or object to a resulting array, using the return value of
* fn as the values for the new array. Like A.each, this function can accept
* an object or an array.
*/
A.map = function(obj, fn, context) {
var module = AObject;
if (isArray(obj)) {
module = AArray;
}
return module.map.apply(this, arguments);
};
}());
}, '2.0.0');
YUI.add('aui-classnamemanager', function (A, NAME) {
var ClassNameManager = A.ClassNameManager,
_getClassName = ClassNameManager.getClassName;
A.getClassName = A.cached(
function() {
var args = A.Array(arguments, 0, true);
args[args.length] = true;
return _getClassName.apply(ClassNameManager, args);
}
);
}, '2.0.0', {"requires": ["classnamemanager"]});
YUI.add('aui-component', function (A, NAME) {
/**
* The Component Utility
*
* @module aui-component
*/
var Lang = A.Lang,
AArray = A.Array,
concat = function(arr, arr2) {
return (arr || []).concat(arr2 || []);
},
_NAME = 'component',
_INSTANCES = {},
_STR_BLANK = ' ',
_CONSTRUCTOR_OBJECT = A.config.win.Object.prototype.constructor,
ClassNameManager = A.ClassNameManager,
_getClassName = ClassNameManager.getClassName,
_getWidgetClassName = A.Widget.getClassName,
getClassName = A.getClassName,
CSS_HIDE = getClassName('hide');
/**
* A base class for Component, providing:
*
* Widget Lifecycle (initializer, renderUI, bindUI, syncUI, destructor)
*
*
* @class A.Component
* @extends A.Widget
* @uses A.WidgetCssClass, A.WidgetToggle
* @param config {Object} Object literal specifying widget configuration properties.
* @constructor
*/
var Component = A.Base.create(_NAME, A.Widget, [
A.WidgetCssClass,
A.WidgetToggle
], {
initializer: function(config) {
var instance = this;
instance._originalConfig = config;
instance._setRender(config);
_INSTANCES[instance.get('id')] = instance;
},
/**
* Clone the current Component.
*
* @method clone
* @param {Object} config
* @return {Widget} Cloned instance.
*/
clone: function(config) {
var instance = this;
config = config || {};
config.id = config.id || A.guid();
A.mix(config, instance._originalConfig);
return new instance.constructor(config);
},
/**
* Set the visibility on the UI.
*
* @method _uiSetVisible
* @param value
* @protected
*/
_uiSetVisible: function(value) {
var instance = this;
var superUISetVisible = Component.superclass._uiSetVisible;
if (superUISetVisible) {
superUISetVisible.apply(instance, arguments);
}
var hideClass = instance.get('hideClass');
if (hideClass !== false) {
var boundingBox = instance.get('boundingBox');
boundingBox.toggleClass(hideClass || CSS_HIDE, !value);
}
},
/**
* Applies standard class names to the boundingBox and contentBox
*
* @method _renderBoxClassNames
* @protected
*/
_renderBoxClassNames: function() {
var instance = this;
var boundingBoxNode = instance.get('boundingBox')._node;
var contentBoxNode = instance.get('contentBox')._node;
var boundingBoxNodeClassName = boundingBoxNode.className;
var contentBoxNodeClassName = contentBoxNode.className;
var boundingBoxBuffer = (boundingBoxNodeClassName) ? boundingBoxNodeClassName.split(_STR_BLANK) : [];
var contentBoxBuffer = (contentBoxNodeClassName) ? contentBoxNodeClassName.split(_STR_BLANK) : [];
var classes = instance._getClasses();
var classLength = classes.length;
var auiClassesLength = classLength - 4;
var classItem;
var classItemName;
boundingBoxBuffer.push(_getWidgetClassName());
for (var i = classLength - 3; i >= 0; i--) {
classItem = classes[i];
classItemName = String(classItem.NAME).toLowerCase();
boundingBoxBuffer.push(classItem.CSS_PREFIX || _getClassName(classItemName));
if (i <= auiClassesLength) {
classItemName = classItemName;
contentBoxBuffer.push(getClassName(classItemName, 'content'));
}
}
contentBoxBuffer.push(instance.getClassName('content'));
if (boundingBoxNode === contentBoxNode) {
contentBoxNodeClassName = AArray.dedupe(contentBoxBuffer.concat(boundingBoxBuffer)).join(_STR_BLANK);
}
else {
boundingBoxNode.className = AArray.dedupe(boundingBoxBuffer).join(_STR_BLANK);
contentBoxNodeClassName = AArray.dedupe(contentBoxBuffer).join(_STR_BLANK);
}
contentBoxNode.className = contentBoxNodeClassName;
},
/**
* Renders the Component based upon a passed in interaction.
*
* @method _renderInteraction
* @protected
*/
_renderInteraction: function(event, parentNode) {
var instance = this;
instance.render(parentNode);
var renderHandles = instance._renderHandles;
for (var i = renderHandles.length - 1; i >= 0; i--) {
var handle = renderHandles.pop();
handle.detach();
}
},
/**
* Set the interaction and render behavior based upon an object
* (intercepts the default rendering behavior).
*
* @method _setRender
* @protected
*/
_setRender: function(config) {
var instance = this;
var render = config && config.render;
if (render && render.constructor === _CONSTRUCTOR_OBJECT) {
var eventType = render.eventType || 'mousemove';
var parentNode = render.parentNode;
var selector = render.selector || parentNode;
if (selector) {
instance._renderHandles = [];
var renderHandles = instance._renderHandles;
if (!Lang.isArray(eventType)) {
eventType = [eventType];
}
var renderInteraction = A.rbind(instance._renderInteraction, instance, parentNode);
var interactionNode = A.one(selector);
for (var i = eventType.length - 1; i >= 0; i--) {
renderHandles[i] = interactionNode.once(eventType[i], renderInteraction);
}
delete config.render;
}
}
}
}, {
/**
* Static property used to define the default attribute
* configuration for the Component.
*
* @property Component.ATTRS
* @type Object
* @static
*/
ATTRS: {
/**
* Boolean indicating if use of the WAI-ARIA Roles and States should be
* enabled for the Widget.
*
* @attribute useARIA
* @default false
* @type Boolean
* @writeOnce
*/
useARIA: {
writeOnce: true,
value: false,
validator: Lang.isBoolean
},
/**
* CSS class added to hide the boundingBox
when
* visible is set to
* false
.
*
* @attribute hideClass
* @default 'aui-hide'
* @type String
*/
hideClass: {
value: CSS_HIDE
},
/**
* If true
the render phase will be autimatically invoked
* preventing the .render()
manual call.
*
* @attribute render
* @default false
* @type Boolean | Node
*/
render: {
value: false,
writeOnce: true
}
}
});
/**
* Static property used to define the map to store Component instances by id.
*
* @property Component._INSTANCES
* @type Object
* @static
*/
Component._INSTANCES = _INSTANCES;
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method getById
* @param id
*/
Component.getById = function(id) {
return _INSTANCES[id];
};
var DEFAULT_UI_ATTRS = A.Widget.prototype._UI_ATTRS;
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _applyCssPrefix
* @param component
* @protected
*/
Component._applyCssPrefix = function(component) {
if (component && component.NAME && !('CSS_PREFIX' in component)) {
component.CSS_PREFIX = A.getClassName(String(component.NAME).toLowerCase());
}
return component;
};
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method create
* @param config
*/
Component.create = function(config) {
config = config || {};
var extendsClass = config.EXTENDS || A.Component;
var component = config.constructor;
if (!A.Object.owns(config, 'constructor')) {
component = function() {
component.superclass.constructor.apply(this, arguments);
};
}
var configProto = config.prototype;
if (configProto) {
if (config.UI_ATTRS || config.BIND_UI_ATTRS || config.SYNC_UI_ATTRS) {
var BIND_UI_ATTRS = concat(config.BIND_UI_ATTRS, config.UI_ATTRS);
var SYNC_UI_ATTRS = concat(config.SYNC_UI_ATTRS, config.UI_ATTRS);
var extendsProto = extendsClass.prototype;
var extendsUIAttrs = (extendsProto && extendsProto._UI_ATTRS) || DEFAULT_UI_ATTRS;
BIND_UI_ATTRS = concat(extendsUIAttrs.BIND, BIND_UI_ATTRS);
SYNC_UI_ATTRS = concat(extendsUIAttrs.SYNC, SYNC_UI_ATTRS);
var configProtoUIAttrs = configProto._UI_ATTRS;
if (!configProtoUIAttrs) {
configProtoUIAttrs = configProto._UI_ATTRS = {};
}
if (BIND_UI_ATTRS.length) {
configProtoUIAttrs.BIND = BIND_UI_ATTRS;
}
if (SYNC_UI_ATTRS.length) {
configProtoUIAttrs.SYNC = SYNC_UI_ATTRS;
}
}
}
var augmentsClasses = config.AUGMENTS;
if (augmentsClasses && !Lang.isArray(augmentsClasses)) {
augmentsClasses = [augmentsClasses];
}
A.mix(component, config);
delete component.prototype;
A.extend(component, extendsClass, configProto);
if (augmentsClasses) {
component = A.Base.build(config.NAME, component, augmentsClasses, {
dynamic: false
});
}
Component._applyCssPrefix(component);
return component;
};
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @property Component.CSS_PREFIX
* @type String
* @static
*/
Component.CSS_PREFIX = getClassName('component');
var Base = A.Base;
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method build
*/
Component.build = function() {
var component = Base.build.apply(Base, arguments);
Component._applyCssPrefix(component);
return component;
};
A.Component = Component;
}, '2.0.0', {
"requires": [
"aui-classnamemanager",
"aui-widget-cssclass",
"aui-widget-toggle",
"base-build",
"widget-base"
]
});
YUI.add('aui-debounce', function (A, NAME) {
var Lang = A.Lang,
AArray = A.Array,
isArray = Lang.isArray,
isString = Lang.isString,
isUndefined = Lang.isUndefined,
DEFAULT_ARGS = [];
var toArray = function(arr, fallback, index, arrayLike) {
return !isUndefined(arr) ? AArray(arr, index || 0, (arrayLike !== false)) : fallback;
};
A.debounce = function(fn, delay, context, args) {
var id;
var tempArgs;
if (isString(fn) && context) {
fn = A.bind(fn, context);
}
delay = delay || 0;
args = toArray(arguments, DEFAULT_ARGS, 3);
var clearFn = function() {
clearInterval(id);
id = null;
};
var base = function() {
clearFn();
var result = fn.apply(context, tempArgs || args || DEFAULT_ARGS);
tempArgs = null;
return result;
};
var delayFn = function(delayTime, newArgs, newContext, newFn) {
wrapped.cancel();
delayTime = !isUndefined(delayTime) ? delayTime : delay;
fn = newFn || fn;
context = newContext || context;
if (newArgs !== args) {
tempArgs = toArray(newArgs, DEFAULT_ARGS, 0, false).concat(args);
}
if (delayTime > 0) {
id = setInterval(base, delayTime);
}
else {
return base();
}
};
var cancelFn = function() {
if (id) {
clearFn();
}
};
var setDelay = function(delay) {
cancelFn();
delay = delay || 0;
};
var wrapped = function() {
var currentArgs = arguments.length ? arguments : args;
return wrapped.delay(delay, currentArgs, context || this);
};
wrapped.cancel = cancelFn;
wrapped.delay = delayFn;
wrapped.setDelay = setDelay;
return wrapped;
};
}, '2.0.0');
YUI.add('aui-delayed-task-deprecated', function (A, NAME) {
/**
* The DelayedTask Utility - Executes the supplied function in the context of
* the supplied object 'when' milliseconds later
*
* @module aui-delayed-task
*/
/**
* A base class for DelayedTask, providing:
*
* Executes the supplied function in the context of the supplied object 'when' milliseconds later
*
*
* Quick Example:
*
* var delayed = new A.DelayedTask({
* function() {
* // This callback will be executed when the DelayedTask
be invoked
* },
* scope
* });
*
* // executes after 1000ms the callback
* delayed.delay(1000);
*
*
* Check the list of Configuration Attributes available for
* DelayedTask.
*
* @param config {Object} Object literal specifying widget configuration properties.
*
* @class DelayedTask
* @param {function} fn Callback
* @param {Object} scope Context object. Optional.
* @param args 0..n additional arguments that should be provided to the listener.
* @constructor
*/
var DelayedTask = function(fn, scope, args) {
var instance = this;
/**
* Stores the passed args
attribute.
*
* @property _args
* @type Object
* @protected
*/
instance._args = args;
/**
* Stores the passed delay
attribute.
*
* @property _delay
* @default 0
* @type Number
* @protected
*/
instance._delay = 0;
/**
* Stores the passed fn
attribute.
*
* @property _fn
* @type function
* @protected
*/
instance._fn = fn;
/**
* Stores the timer id
given from the setInterval
.
*
* @property _id
* @default null
* @type Number
* @protected
*/
instance._id = null;
/**
* Stores the passed scope
attribute.
*
* @property _scope
* @default instance
* @type Object
* @protected
*/
instance._scope = scope || instance;
/**
* Stores the current timestamp given from
* _getTime .
*
* @property _time
* @default 0
* @type Number
* @protected
*/
instance._time = 0;
instance._base = function() {
var now = instance._getTime();
if (now - instance._time >= instance._delay) {
clearInterval(instance._id);
instance._id = null;
instance._fn.apply(instance._scope, instance._args || []);
}
};
};
DelayedTask.prototype = {
/**
* This function is responsible to execute the user callback, passed in
* the constructor
after delay
milliseconds.
*
* Example:
*
* // executes after 1000ms the callback
* delayed.delay(1000);
*
* @method delay
* @param {Number} delay Delay in milliseconds.
* @param {function} newFn Callback.
* @param {Object} newScope Context object. Optional.
* @param newArgs 0..n additional arguments that should be provided to the listener.
*/
delay: function(delay, newFn, newScope, newArgs) {
var instance = this;
if (instance._id && instance._delay != delay) {
instance.cancel();
}
instance._delay = delay || instance._delay;
instance._time = instance._getTime();
instance._fn = newFn || instance._fn;
instance._scope = newScope || instance._scope;
instance._args = newArgs || instance._args;
if (!A.Lang.isArray(instance._args)) {
instance._args = [instance._args];
}
if (!instance._id) {
if (instance._delay > 0) {
instance._id = setInterval(instance._base, instance._delay);
}
else {
instance._base();
}
}
},
/**
* Cancel the delayed task in case it's running (i.e., clearInterval from
* the current running _id ).
*
* @method cancel
*/
cancel: function() {
var instance = this;
if (instance._id) {
clearInterval(instance._id);
instance._id = null;
}
},
/**
* Get the current timestamp (i.e., now).
*
* @method _getTime
* @protected
* @return {Number} Current timestamp
*/
_getTime: function() {
var instance = this;
return (+new Date());
}
};
A.DelayedTask = DelayedTask;
}, '2.0.0', {"requires": ["yui-base"]});
YUI.add('aui-event-base', function (A, NAME) {
/**
* The Event Base.
*
* @module aui-event
* @submodule aui-event-base
*/
var Lang = A.Lang,
AArray = A.Array,
DOMEventFacade = A.DOMEventFacade,
DOMEventFacadeProto = DOMEventFacade.prototype,
BACKSPACE = 'BACKSPACE',
CAPS_LOCK = 'CAPS_LOCK',
DOWN = 'DOWN',
ENTER = 'ENTER',
ESC = 'ESC',
INSERT = 'INSERT',
PAGE_UP = 'PAGE_UP',
PRINT_SCREEN = 'PRINT_SCREEN',
SHIFT = 'SHIFT',
TAB = 'TAB',
WIN_IME = 'WIN_IME',
STR_EMPTY = '';
var KeyMap = {
BACKSPACE: 8,
TAB: 9,
NUM_CENTER: 12,
ENTER: 13,
RETURN: 13,
SHIFT: 16,
CTRL: 17,
ALT: 18,
PAUSE: 19,
CAPS_LOCK: 20,
ESC: 27,
SPACE: 32,
PAGE_UP: 33,
PAGE_DOWN: 34,
END: 35,
HOME: 36,
LEFT: 37,
UP: 38,
RIGHT: 39,
DOWN: 40,
PRINT_SCREEN: 44,
INSERT: 45,
DELETE: 46,
ZERO: 48,
ONE: 49,
TWO: 50,
THREE: 51,
FOUR: 52,
FIVE: 53,
SIX: 54,
SEVEN: 55,
EIGHT: 56,
NINE: 57,
A: 65,
B: 66,
C: 67,
D: 68,
E: 69,
F: 70,
G: 71,
H: 72,
I: 73,
J: 74,
K: 75,
L: 76,
M: 77,
N: 78,
O: 79,
P: 80,
Q: 81,
R: 82,
S: 83,
T: 84,
U: 85,
V: 86,
W: 87,
X: 88,
Y: 89,
Z: 90,
CONTEXT_MENU: 93,
NUM_ZERO: 96,
NUM_ONE: 97,
NUM_TWO: 98,
NUM_THREE: 99,
NUM_FOUR: 100,
NUM_FIVE: 101,
NUM_SIX: 102,
NUM_SEVEN: 103,
NUM_EIGHT: 104,
NUM_NINE: 105,
NUM_MULTIPLY: 106,
NUM_PLUS: 107,
NUM_MINUS: 109,
NUM_PERIOD: 110,
NUM_DIVISION: 111,
F1: 112,
F2: 113,
F3: 114,
F4: 115,
F5: 116,
F6: 117,
F7: 118,
F8: 119,
F9: 120,
F10: 121,
F11: 122,
F12: 123,
NUM_LOCK: 144,
WIN_KEY: 224,
WIN_IME: 229,
hasModifier: function(event) {
var instance = this;
return event &&
(event.ctrlKey ||
event.altKey ||
event.shiftKey ||
event.metaKey);
},
isKey: function(keyCode, name) {
var instance = this;
return name && ((instance[name] || instance[name.toUpperCase()]) == keyCode);
},
isKeyInRange: function(keyCode, start, end) {
var instance = this;
var result = false;
if (start && end) {
var startKey = instance[start] || instance[start.toUpperCase()];
var endKey = instance[end] || instance[end.toUpperCase()];
result = startKey && endKey &&
(keyCode >= startKey && keyCode <= endKey);
}
return result;
},
isKeyInSet: function(keyCode, name) {
var instance = this;
var args = AArray(arguments, 1, true);
return instance._isKeyInSet(keyCode, args);
},
isNavKey: function(keyCode) {
var instance = this;
return instance.isKeyInRange(keyCode, PAGE_UP, DOWN) || instance.isKeyInSet(keyCode, ENTER, TAB, ESC);
},
isSpecialKey: function(keyCode, eventType) {
var instance = this;
var isCtrlPress = (eventType == 'keypress' && instance.ctrlKey);
return isCtrlPress ||
instance.isNavKey(keyCode) ||
instance.isKeyInRange(keyCode, SHIFT, CAPS_LOCK) ||
instance.isKeyInSet(keyCode, BACKSPACE, PRINT_SCREEN, INSERT, WIN_IME);
},
_isKeyInSet: function(keyCode, arr) {
var instance = this;
var i = arr.length;
var result = false;
var keyName;
var key;
while (i--) {
keyName = arr[i];
key = keyName && (instance[keyName] || instance[String(keyName).toUpperCase()]);
if (keyCode == key) {
result = true;
break;
}
}
return result;
}
};
A.mix(
DOMEventFacadeProto, {
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method hasModifier
*/
hasModifier: function() {
var instance = this;
return KeyMap.hasModifier(instance);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method isKey
* @param name
*/
isKey: function(name) {
var instance = this;
return KeyMap.isKey(instance.keyCode, name);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method isKeyInRange
* @param start
* @param end
*/
isKeyInRange: function(start, end) {
var instance = this;
return KeyMap.isKeyInRange(instance.keyCode, start, end);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method isKeyInSet
*/
isKeyInSet: function() {
var instance = this;
var args = AArray(arguments, 0, true);
return KeyMap._isKeyInSet(instance.keyCode, args);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method isNavKey
*/
isNavKey: function() {
var instance = this;
return KeyMap.isNavKey(instance.keyCode);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method isSpecialKey
*/
isSpecialKey: function() {
var instance = this;
return KeyMap.isSpecialKey(instance.keyCode, instance.type);
}
}
);
A.Event.KeyMap = KeyMap;
A.Event.supportsDOMEvent = A.supportsDOMEvent;
}, '2.0.0', {"requires": ["event-base"]});
YUI.add('aui-event-input', function (A, NAME) {
/**
* An object that encapsulates text changed events for textareas and input
* element of type text and password. This event only occurs when the element
* is focused.
*
* @module aui-event
* @submodule aui-event-input
*/
var DOM_EVENTS = A.Node.DOM_EVENTS;
// Input event feature check should be done on textareas. WebKit before
// version 531 (3.0.182.2) did not support input events for textareas.
// See http://dev.chromium.org/developers/webkit-version-table
if (A.Features.test('event', 'input')) {
// http://yuilibrary.com/projects/yui3/ticket/2533063
DOM_EVENTS.input = 1;
return;
}
DOM_EVENTS.cut = 1;
DOM_EVENTS.dragend = 1;
DOM_EVENTS.paste = 1;
var ACTIVE_ELEMENT = 'activeElement',
OWNER_DOCUMENT = 'ownerDocument',
_HANDLER_DATA_KEY = '~~aui|input|event~~',
_INPUT_EVENT_TYPE = ['keydown', 'paste', 'drop', 'cut'],
_SKIP_FOCUS_CHECK_MAP = {
cut: 1,
drop: 1,
paste: 1
};
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @event input
*/
A.Event.define('input', {
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method on
* @param node
* @param subscription
* @param notifier
*/
on: function(node, subscription, notifier) {
var instance = this;
subscription._handler = node.on(
_INPUT_EVENT_TYPE, A.bind(instance._dispatchEvent, instance, notifier));
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method delegate
* @param node
* @param subscription
* @param notifier
* @param filter
*/
delegate: function(node, subscription, notifier, filter) {
var instance = this;
subscription._handles = [];
subscription._handler = node.delegate('focus', function(event) {
var element = event.target,
handler = element.getData(_HANDLER_DATA_KEY);
if (!handler) {
handler = element.on(
_INPUT_EVENT_TYPE,
A.bind(instance._dispatchEvent, instance, notifier));
subscription._handles.push(handler);
element.setData(_HANDLER_DATA_KEY, handler);
}
}, filter);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method detach
* @param node
* @param subscription
* @param notifier
*/
detach: function(node, subscription, notifier) {
subscription._handler.detach();
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method detachDelegate
* @param node
* @param subscription
* @param notifier
*/
detachDelegate: function(node, subscription, notifier) {
A.Array.each(subscription._handles, function(handle) {
var element = A.one(handle.evt.el);
if (element) {
element.setData(_HANDLER_DATA_KEY, null);
}
handle.detach();
});
subscription._handler.detach();
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _dispatchEvent
* @param notifier
* @param event
* @protected
*/
_dispatchEvent: function(notifier, event) {
var instance = this,
input = event.target;
if ( // Since cut, drop and paste events fires before the element is focused, skip focus checking.
_SKIP_FOCUS_CHECK_MAP[event.type] ||
(input.get(OWNER_DOCUMENT).get(ACTIVE_ELEMENT) === input)) {
notifier.fire(event);
}
}
});
}, '2.0.0', {"requires": ["aui-event-base", "event-delegate", "event-synthetic"]});
YUI.add('aui-form-validator', function (A, NAME) {
/**
* The Form Validator Component
*
* @module aui-form-validator
*/
// API inspired on the amazing jQuery Form Validation - http://jquery.bassistance.de/validate/
var Lang = A.Lang,
AObject = A.Object,
isBoolean = Lang.isBoolean,
isDate = Lang.isDate,
isEmpty = AObject.isEmpty,
isFunction = Lang.isFunction,
isObject = Lang.isObject,
isString = Lang.isString,
trim = Lang.trim,
isNode = function(v) {
return (v instanceof A.Node);
},
defaults = A.namespace('config.FormValidator'),
getRegExp = A.DOM._getRegExp,
FORM_VALIDATOR = 'form-validator',
_DOT = '.',
_EMPTY_STR = '',
_EXCLUDE_FILE_INPUT_SELECTOR = 'input:not([type="file"]),select,textarea,button',
_FILE_INPUT_SELECTOR = 'input[type="file"]',
_FORM_ELEMENTS_SELECTOR = 'input,select,textarea,button',
_INVALID_DATE = 'Invalid Date',
_PIPE = '|',
_SPACE = ' ',
EV_BLUR = 'blur',
EV_CHANGE = 'change',
EV_ERROR_FIELD = 'errorField',
EV_INPUT = 'input',
EV_SUBMIT_ERROR = 'submitError',
EV_VALIDATE_FIELD = 'validateField',
EV_VALID_FIELD = 'validField',
ARIA_REQUIRED = 'aria-required',
BOUNDING_BOX = 'boundingBox',
CHECKBOX = 'checkbox',
CONTAINER_ERROR_CLASS = 'containerErrorClass',
CONTAINER_VALID_CLASS = 'containerValidClass',
CONTROL = 'control',
ERROR = 'error',
ERROR_CLASS = 'errorClass',
FIELD = 'field',
FIELD_CONTAINER = 'fieldContainer',
FIELD_STRINGS = 'fieldStrings',
FOCUS = 'focus',
GROUP = 'group',
HELP = 'help',
INLINE = 'inline',
LABEL_CSS_CLASS = 'labelCssClass',
MESSAGE_CONTAINER = 'messageContainer',
NAME = 'name',
RADIO = 'radio',
RULES = 'rules',
SELECT_TEXT = 'selectText',
SHOW_ALL_MESSAGES = 'showAllMessages',
SHOW_MESSAGES = 'showMessages',
STACK = 'stack',
STACK_ERROR_CONTAINER = 'stackErrorContainer',
STRINGS = 'strings',
SUBMIT = 'submit',
SUCCESS = 'success',
TYPE = 'type',
VALID_CLASS = 'validClass',
VALIDATE_ON_BLUR = 'validateOnBlur',
VALIDATE_ON_INPUT = 'validateOnInput',
getCN = A.getClassName,
CSS_CONTROL_GROUP = getCN(CONTROL, GROUP),
CSS_ERROR = getCN(ERROR),
CSS_ERROR_FIELD = getCN(ERROR, FIELD),
CSS_SUCCESS = getCN(SUCCESS),
CSS_SUCCESS_FIELD = getCN(SUCCESS, FIELD),
CSS_HELP_INLINE = getCN(HELP, INLINE),
CSS_STACK = getCN(FORM_VALIDATOR, STACK),
TPL_MESSAGE = '
',
TPL_STACK_ERROR = '
';
A.mix(defaults, {
STRINGS: {
DEFAULT: 'Please fix this field.',
acceptFiles: 'Please enter a value with a valid extension ({0}).',
alpha: 'Please enter only alpha characters.',
alphanum: 'Please enter only alphanumeric characters.',
date: 'Please enter a valid date.',
digits: 'Please enter only digits.',
email: 'Please enter a valid email address.',
equalTo: 'Please enter the same value again.',
iri: 'Please enter a valid IRI.',
max: 'Please enter a value less than or equal to {0}.',
maxLength: 'Please enter no more than {0} characters.',
min: 'Please enter a value greater than or equal to {0}.',
minLength: 'Please enter at least {0} characters.',
number: 'Please enter a valid number.',
range: 'Please enter a value between {0} and {1}.',
rangeLength: 'Please enter a value between {0} and {1} characters long.',
required: 'This field is required.',
url: 'Please enter a valid URL.'
},
REGEX: {
alpha: /^[a-z_]+$/i,
alphanum: /^\w+$/,
digits: /^\d+$/,
// Regex from Scott Gonzalez Email Address Validation: http://projects.scottsplayground.com/email_address_validation/
email: /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,
// Regex from Scott Gonzalez IRI: http://projects.scottsplayground.com/iri/demo/
iri: /^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i,
number: /^[+\-]?(\d+([.,]\d+)?)+([eE][+-]?\d+)?$/,
// Regex from Scott Gonzalez Common URL: http://projects.scottsplayground.com/iri/demo/common.html
url: /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i
},
RULES: {
acceptFiles: function(val, node, ruleValue) {
var regex = null;
if (isString(ruleValue)) {
var extensions = ruleValue.replace(/\./g, '').split(/,\s*|\b\s*/);
extensions = A.Array.map(extensions, A.Escape.regex);
regex = getRegExp('[.](' + extensions.join(_PIPE) + ')$', 'i');
}
return regex && regex.test(val);
},
date: function(val, node, ruleValue) {
var date = new Date(val);
return (isDate(date) && (date !== _INVALID_DATE) && !isNaN(date));
},
equalTo: function(val, node, ruleValue) {
var comparator = A.one(ruleValue);
return comparator && (trim(comparator.val()) === val);
},
hasValue: function(val, node) {
var instance = this;
if (A.FormValidator.isCheckable(node)) {
var name = node.get(NAME),
elements = A.all(instance.getFieldsByName(name));
return (elements.filter(':checked').size() > 0);
}
else {
return !!val;
}
},
max: function(val, node, ruleValue) {
return (Lang.toFloat(val) <= ruleValue);
},
maxLength: function(val, node, ruleValue) {
return (val.length <= ruleValue);
},
min: function(val, node, ruleValue) {
return (Lang.toFloat(val) >= ruleValue);
},
minLength: function(val, node, ruleValue) {
return (val.length >= ruleValue);
},
range: function(val, node, ruleValue) {
var num = Lang.toFloat(val);
return (num >= ruleValue[0]) && (num <= ruleValue[1]);
},
rangeLength: function(val, node, ruleValue) {
var length = val.length;
return (length >= ruleValue[0]) && (length <= ruleValue[1]);
},
required: function(val, node, ruleValue) {
var instance = this;
if (ruleValue === true) {
return defaults.RULES.hasValue.apply(instance, [val, node]);
}
else {
return true;
}
}
}
});
/**
* A base class for FormValidator.
*
* @class A.FormValidator
* @extends A.Base
* @param config {Object} Object literal specifying widget configuration properties.
* @constructor
*/
var FormValidator = A.Component.create({
/**
* Static property provides a string to identify the class.
*
* @property FormValidator.NAME
* @type String
* @static
*/
NAME: FORM_VALIDATOR,
/**
* Static property used to define the default attribute
* configuration for the FormValidator.
*
* @property FormValidator.ATTRS
* @type Object
* @static
*/
ATTRS: {
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute boundingBox
*/
boundingBox: {
setter: A.one
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute containerErrorClass
* @type String
*/
containerErrorClass: {
value: CSS_ERROR,
validator: isString
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute containerValidClass
* @type String
*/
containerValidClass: {
value: CSS_SUCCESS,
validator: isString
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute errorClass
* @type String
*/
errorClass: {
value: CSS_ERROR_FIELD,
validator: isString
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute extractRules
* @default true
* @type Boolean
*/
extractRules: {
value: true,
validator: isBoolean
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute fieldContainer
* @type String
*/
fieldContainer: {
value: _DOT + CSS_CONTROL_GROUP
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute fieldStrings
* @default {}
* @type Object
*/
fieldStrings: {
value: {},
validator: isObject
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute labelCssClass
* @type String
*/
labelCssClass: {
validator: isString,
value: 'control-label'
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute messageContainer
* @default '
'
*/
messageContainer: {
getter: function(val) {
return A.Node.create(val).clone();
},
value: TPL_MESSAGE
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute strings
*/
strings: {
valueFn: function() {
return defaults.STRINGS;
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute rules
* @default {}
* @type Object
*/
rules: {
getter: function(val) {
var instance = this;
if (!instance._rulesAlreadyExtracted) {
instance._extractRulesFromMarkup(val);
}
return val;
},
validator: isObject,
value: {}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute selectText
* @default true
* @type Boolean
*/
selectText: {
value: true,
validator: isBoolean
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute showMessages
* @default true
* @type Boolean
*/
showMessages: {
value: true,
validator: isBoolean
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute showAllMessages
* @default false
* @type Boolean
*/
showAllMessages: {
value: false,
validator: isBoolean
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute stackErrorContainer
*/
stackErrorContainer: {
getter: function(val) {
return A.Node.create(val).clone();
},
value: TPL_STACK_ERROR
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute validateOnBlur
* @default true
* @type Boolean
*/
validateOnBlur: {
value: true,
validator: isBoolean
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute validateOnInput
* @default false
* @type Boolean
*/
validateOnInput: {
value: false,
validator: isBoolean
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute validClass
* @type String
*/
validClass: {
value: CSS_SUCCESS_FIELD,
validator: isString
}
},
/**
* Creates custom rules from user input.
*
* @method _setCustomRules
* @param object
* @protected
*/
_setCustomRules: function(object) {
var instance = this;
A.each(
object,
function(rule, fieldName) {
A.config.FormValidator.RULES[fieldName] = rule.condition;
A.config.FormValidator.STRINGS[fieldName] = rule.errorMessage;
}
);
},
/**
* Ability to add custom validation rules.
*
* @method customRules
* @param object
* @public
* @static
*/
addCustomRules: function(object) {
var instance = this;
if (isObject(object)) {
instance._setCustomRules(object);
}
},
/**
* Checks if a node is a checkbox or radio input.
*
* @method isCheckable
* @param node
* @private
*/
isCheckable: function(node) {
var nodeType = node.get(TYPE).toLowerCase();
return (nodeType === CHECKBOX || nodeType === RADIO);
},
/**
* Static property used to define which component it extends.
*
* @property FormValidator.EXTENDS
* @type Object
* @static
*/
EXTENDS: A.Base,
prototype: {
/**
* Construction logic executed during FormValidator instantiation. Lifecycle.
*
* @method initializer
* @protected
*/
initializer: function() {
var instance = this;
instance.errors = {};
instance._blurHandlers = null;
instance._fileBlurHandlers = null;
instance._fileInputHandlers = null;
instance._inputHandlers = null;
instance._rulesAlreadyExtracted = false;
instance._stackErrorContainers = {};
instance.bindUI();
instance._uiSetValidateOnBlur(instance.get(VALIDATE_ON_BLUR));
instance._uiSetValidateOnInput(instance.get(VALIDATE_ON_INPUT));
},
/**
* Bind the events on the FormValidator UI. Lifecycle.
*
* @method bindUI
* @protected
*/
bindUI: function() {
var instance = this,
boundingBox = instance.get(BOUNDING_BOX);
var onceFocusHandler = boundingBox.delegate(FOCUS, function(event) {
instance._setARIARoles();
onceFocusHandler.detach();
}, _FORM_ELEMENTS_SELECTOR);
instance.publish({
errorField: {
defaultFn: instance._defErrorFieldFn
},
validField: {
defaultFn: instance._defValidFieldFn
},
validateField: {
defaultFn: instance._defValidateFieldFn
}
});
boundingBox.on({
reset: A.bind(instance._onFormReset, instance),
submit: A.bind(instance._onFormSubmit, instance)
});
instance.after({
extractRulesChange: instance._afterExtractRulesChange,
validateOnBlurChange: instance._afterValidateOnBlurChange,
validateOnInputChange: instance._afterValidateOnInputChange
});
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method addFieldError
* @param field
* @param ruleName
*/
addFieldError: function(field, ruleName) {
var instance = this,
errors = instance.errors,
name = field.get(NAME);
if (!errors[name]) {
errors[name] = [];
}
errors[name].push(ruleName);
},
/**
* Deletes the field from the errors property object.
*
* @method clearFieldError
* @param {Node|String} field
*/
clearFieldError: function(field) {
var fieldName = isNode(field) ? field.get('name') : field;
if (isString(fieldName)) {
delete this.errors[fieldName];
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method eachRule
* @param fn
*/
eachRule: function(fn) {
var instance = this;
A.each(
instance.get(RULES),
function(rule, fieldName) {
if (isFunction(fn)) {
fn.apply(instance, [rule, fieldName]);
}
}
);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method findFieldContainer
* @param field
*/
findFieldContainer: function(field) {
var instance = this,
fieldContainer = instance.get(FIELD_CONTAINER);
if (fieldContainer) {
return field.ancestor(fieldContainer);
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method focusInvalidField
*/
focusInvalidField: function() {
var instance = this,
boundingBox = instance.get(BOUNDING_BOX),
field = boundingBox.one(_DOT + CSS_ERROR);
if (field) {
if (instance.get(SELECT_TEXT)) {
field.selectText();
}
field.focus();
field.scrollIntoView();
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method getField
* @param fieldOrFieldName
*/
getField: function(fieldOrFieldName) {
var instance = this;
if (isString(fieldOrFieldName)) {
fieldOrFieldName = instance.getFieldsByName(fieldOrFieldName);
if (fieldOrFieldName && fieldOrFieldName.length && !fieldOrFieldName.name) {
fieldOrFieldName = fieldOrFieldName[0];
}
}
return A.one(fieldOrFieldName);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method getFieldsByName
* @param fieldName
*/
getFieldsByName: function(fieldName) {
var instance = this,
domBoundingBox = instance.get(BOUNDING_BOX).getDOM();
return domBoundingBox.elements[fieldName];
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method getFieldError
* @param field
*/
getFieldError: function(field) {
var instance = this;
return instance.errors[field.get(NAME)];
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method getFieldStackErrorContainer
* @param field
*/
getFieldStackErrorContainer: function(field) {
var instance = this,
name = isNode(field) ? field.get('name') : field,
stackContainers = instance._stackErrorContainers;
if (!stackContainers[name]) {
stackContainers[name] = instance.get(STACK_ERROR_CONTAINER);
}
return stackContainers[name];
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method getFieldErrorMessage
* @param field
* @param rule
*/
getFieldErrorMessage: function(field, rule) {
var instance = this,
fieldName = field.get(NAME),
fieldStrings = instance.get(FIELD_STRINGS)[fieldName] || {},
fieldRules = instance.get(RULES)[fieldName],
strings = instance.get(STRINGS),
substituteRulesMap = {};
if (rule in fieldRules) {
var ruleValue = A.Array(fieldRules[rule]);
A.each(
ruleValue,
function(value, index) {
substituteRulesMap[index] = [value].join(_EMPTY_STR);
}
);
}
var message = (fieldStrings[rule] || strings[rule] || strings.DEFAULT);
return Lang.sub(message, substituteRulesMap);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method hasErrors
*/
hasErrors: function() {
var instance = this;
return !isEmpty(instance.errors);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method highlight
* @param field
* @param valid
*/
highlight: function(field, valid) {
var instance = this,
fieldContainer,
fieldName,
namedFieldNodes;
if (field) {
fieldContainer = instance.findFieldContainer(field);
fieldName = field.get('name');
if (this.validatable(field)) {
namedFieldNodes = A.all(instance.getFieldsByName(fieldName));
namedFieldNodes.each(
function(node) {
instance._highlightHelper(
node,
instance.get(ERROR_CLASS),
instance.get(VALID_CLASS),
valid
);
}
);
if (fieldContainer) {
instance._highlightHelper(
fieldContainer,
instance.get(CONTAINER_ERROR_CLASS),
instance.get(CONTAINER_VALID_CLASS),
valid
);
}
}
else if (!field.val()) {
instance.resetField(fieldName);
}
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method normalizeRuleValue
* @param ruleValue
* @param {Node} field
*/
normalizeRuleValue: function(ruleValue, field) {
var instance = this;
return isFunction(ruleValue) ? ruleValue.apply(instance, [field]) : ruleValue;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method unhighlight
* @param field
*/
unhighlight: function(field) {
var instance = this;
instance.highlight(field, true);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method printStackError
* @param field
* @param container
* @param errors
*/
printStackError: function(field, container, errors) {
var instance = this;
if (!instance.get(SHOW_ALL_MESSAGES)) {
if (A.Array.indexOf(errors, 'required') !== -1) {
errors = ['required'];
}
else {
errors = errors.slice(0, 1);
}
}
container.empty();
A.Array.each(
errors,
function(error, index) {
var message = instance.getFieldErrorMessage(field, error),
messageEl = instance.get(MESSAGE_CONTAINER).addClass(error);
container.append(
messageEl.html(message)
);
}
);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method resetAllFields
*/
resetAllFields: function() {
var instance = this;
instance.eachRule(
function(rule, fieldName) {
instance.resetField(fieldName);
}
);
},
/**
* Resets the CSS class and error status of a field.
*
* @method resetField
* @param {Node|String} field
*/
resetField: function(field) {
var instance = this,
fieldName,
namedFieldNodes,
stackContainer;
fieldName = isNode(field) ? field.get('name') : field;
instance.clearFieldError(fieldName);
stackContainer = instance.getFieldStackErrorContainer(fieldName);
stackContainer.remove();
namedFieldNodes = A.all(instance.getFieldsByName(fieldName));
namedFieldNodes.each(
function(node) {
instance.resetFieldCss(node);
}
);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method resetFieldCss
* @param field
*/
resetFieldCss: function(field) {
var instance = this,
fieldContainer = instance.findFieldContainer(field);
var removeClasses = function(elem, classAttrs) {
if (elem) {
A.each(classAttrs, function(attrName) {
elem.removeClass(
instance.get(attrName)
);
});
}
};
removeClasses(field, [VALID_CLASS, ERROR_CLASS]);
removeClasses(fieldContainer, [CONTAINER_VALID_CLASS, CONTAINER_ERROR_CLASS]);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method validatable
* @param {Node} field
*/
validatable: function(field) {
var instance = this,
validatable = false,
fieldRules = instance.get(RULES)[field.get(NAME)];
if (fieldRules) {
validatable = fieldRules.custom ||
instance.normalizeRuleValue(fieldRules.required) ||
defaults.RULES.hasValue.apply(instance, [field.val(), field]);
}
return !!validatable;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method validate
*/
validate: function() {
var instance = this;
instance.eachRule(
function(rule, fieldName) {
instance.validateField(fieldName);
}
);
instance.focusInvalidField();
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method validateField
* @param field
*/
validateField: function(field) {
var instance = this,
fieldNode,
validatable;
instance.resetField(field);
fieldNode = isString(field) ? instance.getField(field) : field;
if (isNode(fieldNode)) {
validatable = instance.validatable(fieldNode);
if (validatable) {
instance.fire(EV_VALIDATE_FIELD, {
validator: {
field: fieldNode
}
});
}
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _afterExtractRulesChange
* @param event
* @protected
*/
_afterExtractRulesChange: function(event) {
var instance = this;
instance._uiSetExtractRules(event.newVal);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _afterValidateOnBlurChange
* @param event
* @protected
*/
_afterValidateOnBlurChange: function(event) {
var instance = this;
instance._uiSetValidateOnBlur(event.newVal);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _afterValidateOnInputChange
* @param event
* @protected
*/
_afterValidateOnInputChange: function(event) {
var instance = this;
instance._uiSetValidateOnInput(event.newVal);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _defErrorFieldFn
* @param event
* @protected
*/
_defErrorFieldFn: function(event) {
var instance = this,
field,
label,
stackContainer,
target,
validator;
label = instance.get(LABEL_CSS_CLASS);
validator = event.validator;
field = validator.field;
instance.highlight(field);
if (instance.get(SHOW_MESSAGES)) {
target = field;
stackContainer = instance.getFieldStackErrorContainer(field);
if (A.FormValidator.isCheckable(target)) {
target = field.ancestor('.' + CSS_ERROR).get('lastChild');
}
target.placeAfter(stackContainer);
instance.printStackError(
field,
stackContainer,
validator.errors
);
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _defValidFieldFn
* @param event
* @protected
*/
_defValidFieldFn: function(event) {
var instance = this;
var field = event.validator.field;
instance.unhighlight(field);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _defValidateFieldFn
* @param event
* @protected
*/
_defValidateFieldFn: function(event) {
var instance = this;
var field = event.validator.field;
var fieldRules = instance.get(RULES)[field.get(NAME)];
A.each(
fieldRules,
function(ruleValue, ruleName) {
var rule = defaults.RULES[ruleName];
var fieldValue = trim(field.val());
ruleValue = instance.normalizeRuleValue(ruleValue, field);
if (isFunction(rule) && !rule.apply(instance, [fieldValue, field, ruleValue])) {
instance.addFieldError(field, ruleName);
}
}
);
var fieldErrors = instance.getFieldError(field);
if (fieldErrors) {
instance.fire(EV_ERROR_FIELD, {
validator: {
field: field,
errors: fieldErrors
}
});
}
else {
instance.fire(EV_VALID_FIELD, {
validator: {
field: field
}
});
}
},
/**
* Finds the label text of a field if existing.
*
* @method _findFieldLabel
* @param field
* @return {String}
*/
_findFieldLabel: function(field) {
var labelCssClass = '.' + this.get('labelCssClass'),
label = A.one('label[for=' + field.get('id') + ']') ||
field.ancestor().previous(labelCssClass) ||
field.ancestor('.' + CSS_ERROR).one(labelCssClass);
if (label) {
return label.get('text');
}
},
/**
* Sets the error/success CSS classes based on the validation of a
* field.
*
* @method _highlightHelper
* @param field
* @param errorClass
* @param validClass
* @param valid
* @protected
*/
_highlightHelper: function(field, errorClass, validClass, valid) {
if (valid) {
field.removeClass(errorClass).addClass(validClass);
}
else {
field.removeClass(validClass).addClass(errorClass);
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _extractRulesFromMarkup
* @param rules
* @protected
*/
_extractRulesFromMarkup: function(rules) {
var instance = this,
domBoundingBox = instance.get(BOUNDING_BOX).getDOM(),
elements = domBoundingBox.elements,
defaultRulesKeys = AObject.keys(defaults.RULES),
defaultRulesJoin = defaultRulesKeys.join('|'),
regex = getRegExp('field-(' + defaultRulesJoin + ')', 'g'),
i,
length,
ruleNameMatch = [],
ruleMatcher = function(m1, m2) {
ruleNameMatch.push(m2);
};
for (i = 0, length = elements.length; i < length; i++) {
var el = elements[i],
fieldName = el.name;
el.className.replace(regex, ruleMatcher);
if (ruleNameMatch.length) {
var fieldRules = rules[fieldName],
j,
ruleNameLength;
if (!fieldRules) {
fieldRules = {};
rules[fieldName] = fieldRules;
}
for (j = 0, ruleNameLength = ruleNameMatch.length; j < ruleNameLength; j++) {
var rule = ruleNameMatch[j];
if (!(rule in fieldRules)) {
fieldRules[rule] = true;
}
}
ruleNameMatch.length = 0;
}
}
instance._rulesAlreadyExtracted = true;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _onFieldInput
* @param event
* @protected
*/
_onFieldInput: function(event) {
var instance = this;
instance.validateField(event.target);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _onFormSubmit
* @param event
* @protected
*/
_onFormSubmit: function(event) {
var instance = this;
var data = {
validator: {
formEvent: event
}
};
instance.validate();
if (instance.hasErrors()) {
data.validator.errors = instance.errors;
instance.fire(EV_SUBMIT_ERROR, data);
event.halt();
}
else {
instance.fire(SUBMIT, data);
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _onFormReset
* @param event
* @protected
*/
_onFormReset: function(event) {
var instance = this;
instance.resetAllFields();
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _setARIARoles
* @protected
*/
_setARIARoles: function() {
var instance = this;
instance.eachRule(
function(rule, fieldName) {
var field = instance.getField(fieldName);
var required = instance.normalizeRuleValue(rule.required, field);
if (required) {
if (field && !field.attr(ARIA_REQUIRED)) {
field.attr(ARIA_REQUIRED, true);
}
}
}
);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _uiSetExtractRules
* @param val
* @protected
*/
_uiSetExtractRules: function(val) {
var instance = this;
if (val) {
instance._extractRulesFromMarkup(instance.get(RULES));
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _uiSetValidateOnInput
* @param val
* @protected
*/
_uiSetValidateOnInput: function(val) {
var instance = this,
boundingBox = instance.get(BOUNDING_BOX);
if (val) {
if (!instance._inputHandlers) {
instance._inputHandlers = boundingBox.delegate(EV_INPUT, instance._onFieldInput,
_EXCLUDE_FILE_INPUT_SELECTOR, instance);
}
if (!instance._fileInputHandlers) {
instance._fileInputHandlers = boundingBox.delegate(EV_CHANGE, instance._onFieldInput,
_FILE_INPUT_SELECTOR, instance);
}
}
else {
if (instance._inputHandlers) {
instance._inputHandlers.detach();
}
if (instance._fileInputHandlers) {
instance._fileInputHandlers.detach();
}
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _uiSetValidateOnBlur
* @param val
* @protected
*/
_uiSetValidateOnBlur: function(val) {
var instance = this,
boundingBox = instance.get(BOUNDING_BOX);
if (val) {
if (!instance._blurHandlers) {
instance._blurHandlers = boundingBox.delegate(EV_BLUR, instance._onFieldInput,
_EXCLUDE_FILE_INPUT_SELECTOR, instance);
}
if (!instance._fileBlurHandlers) {
instance._fileBlurHandlers = boundingBox.delegate(EV_CHANGE, instance._onFieldInput,
_FILE_INPUT_SELECTOR, instance);
}
}
else {
if (instance._blurHandlers) {
instance._blurHandlers.detach();
}
if (instance._fileBlurHandlers) {
instance._fileBlurHandlers.detach();
}
}
}
}
});
A.each(
defaults.REGEX,
function(regex, key) {
defaults.RULES[key] = function(val, node, ruleValue) {
return defaults.REGEX[key].test(val);
};
}
);
A.FormValidator = FormValidator;
}, '2.0.0', {
"requires": [
"escape",
"selector-css3",
"node-event-delegate",
"aui-node",
"aui-component",
"aui-event-input"
]
});
YUI.add('aui-node-base', function (A, NAME) {
/**
* A set of utility methods to the Node.
*
* @module aui-node
* @submodule aui-node-base
*/
var Lang = A.Lang,
isArray = Lang.isArray,
isFunction = Lang.isFunction,
isObject = Lang.isObject,
isString = Lang.isString,
isUndefined = Lang.isUndefined,
isValue = Lang.isValue,
AArray = A.Array,
ANode = A.Node,
ANodeList = A.NodeList,
getClassName = A.getClassName,
getRegExp = A.DOM._getRegExp,
CONFIG = A.config,
DOC = CONFIG.doc,
WIN = CONFIG.win,
NODE_PROTO = ANode.prototype,
NODE_PROTO_HIDE = NODE_PROTO._hide,
NODE_PROTO_SHOW = NODE_PROTO._show,
NODELIST_PROTO = ANodeList.prototype,
STR_EMPTY = '',
ARRAY_EMPTY_STRINGS = [STR_EMPTY, STR_EMPTY],
OFFSET = 'offset',
CSS_FORCE_OFFSET = getClassName('force', OFFSET),
CSS_HIDE = getClassName('hide'),
CSS_UNSELECTABLE = getClassName('unselectable'),
CHILD_NODES = 'childNodes',
CREATE_DOCUMENT_FRAGMENT = 'createDocumentFragment',
INNER = 'inner',
INNER_HTML = 'innerHTML',
NEXT_SIBLING = 'nextSibling',
OUTER = 'outer',
PARENT_NODE = 'parentNode',
REGION = 'region',
SUPPORT_CLONED_EVENTS = false,
VALUE = 'value',
MAP_BORDER = {
b: 'borderBottomWidth',
l: 'borderLeftWidth',
r: 'borderRightWidth',
t: 'borderTopWidth'
},
MAP_MARGIN = {
b: 'marginBottom',
l: 'marginLeft',
r: 'marginRight',
t: 'marginTop'
},
MAP_PADDING = {
b: 'paddingBottom',
l: 'paddingLeft',
r: 'paddingRight',
t: 'paddingTop'
};
/*
Parts of this file are used from jQuery (http://jquery.com)
Dual-licensed under MIT/GPL
*/
var div = DOC.createElement('div');
div.style.display = 'none';
div.innerHTML = ' ';
if (div.attachEvent && div.fireEvent) {
div.attachEvent(
'onclick',
function() {
SUPPORT_CLONED_EVENTS = true;
div.detachEvent('onclick', arguments.callee);
}
);
div.cloneNode(true).fireEvent('onclick');
}
var SUPPORT_OPTIONAL_TBODY = !div.getElementsByTagName('tbody').length;
var REGEX_LEADING_WHITE_SPACE = /^\s+/,
REGEX_IE8_ACTION = /\=([^=\x27\x22>\s]+\/)>/g,
REGEX_TAGNAME = /<([\w:]+)/;
div = null;
var _setUnselectable = function(element, unselectable, noRecurse) {
var descendants,
value = unselectable ? 'on' : '',
i,
descendant;
element.setAttribute('unselectable', value);
if (!noRecurse) {
descendants = element.getElementsByTagName('*');
for (i = 0;
(descendant = descendants[i]); i++) {
descendant.setAttribute('unselectable', value);
}
}
};
/**
* Augment the YUI3 Node with more util methods.
*
* Check the [live demo](http://alloyui.com/examples/node/).
*
* @class A.Node
* @uses Node
* @constructor
*/
A.mix(NODE_PROTO, {
/**
* Return the current ancestors of the node element filtered by a className.
* This is an optimized method for finding ancestors by a specific CSS class name.
*
* Example:
*
*
* A.one('#nodeId').ancestorsByClassName('aui-hide');
*
*
* @method ancestorsByClassName
* @param {String} className A selector to filter the ancestor elements against.
* @param {Boolean} testSelf optional Whether or not to include the element
* in the scan
* @return {NodeList}
*/
ancestorsByClassName: function(className, testSelf) {
var instance = this;
var ancestors = [];
var cssRE = new RegExp('\\b' + className + '\\b');
var currentEl = instance.getDOM();
if (!testSelf) {
currentEl = currentEl.parentNode;
}
while (currentEl && currentEl.nodeType !== 9) {
if (currentEl.nodeType === 1 && cssRE.test(currentEl.className)) {
ancestors.push(currentEl);
}
currentEl = currentEl.parentNode;
}
return A.all(ancestors);
},
/**
* Get or Set the value of an attribute for the first element in the
* set of matched elements. If only the name
is passed it
* works as a getter.
*
* Example:
*
* var node = A.one('#nodeId');
* node.attr('title', 'Setting a new title attribute');
* // Alert the value of the title attribute: 'Setting a new title attribute'
* alert( node.attr('title') );
*
*
* @method attr
* @param {String} name The name of the attribute
* @param {String} value The value of the attribute to be set. Optional.
* @return {String}
*/
attr: function(name, value) {
var instance = this,
i;
if (!isUndefined(value)) {
var el = instance.getDOM();
if (name in el) {
instance.set(name, value);
}
else {
instance.setAttribute(name, value);
}
return instance;
}
else {
if (isObject(name)) {
for (i in name) {
instance.attr(i, name[i]);
}
return instance;
}
var currentValue = instance.get(name);
if (!Lang.isValue(currentValue)) {
currentValue = instance.getAttribute(name);
}
return currentValue;
}
},
/**
* Normalizes the behavior of cloning a node, which by default should not clone
* the events that are attached to it.
*
* Example:
*
* var node = A.one('#nodeId');
* node.clone().appendTo('body');
*
*
* @method clone
* @return {Node}
*/
clone: (function() {
var clone;
if (SUPPORT_CLONED_EVENTS) {
clone = function() {
var el = this.getDOM();
var clone;
if (el.nodeType !== 3) {
var outerHTML = this.outerHTML();
outerHTML = outerHTML.replace(REGEX_IE8_ACTION, '="$1">').replace(REGEX_LEADING_WHITE_SPACE,
STR_EMPTY);
clone = ANode.create(outerHTML);
}
else {
clone = A.one(el.cloneNode());
}
return clone;
};
}
else {
clone = function() {
return this.cloneNode(true);
};
}
return clone;
}()),
/**
* Centralize the current Node instance with the passed val
* Array, Node, String, or Region, if not specified, the body will be used.
*
* Example:
*
* var node = A.one('#nodeId');
* // Center the node
with the #container
.
* node.center('#container');
*
*
* @method center
* @chainable
* @param {Array | Node | Region | String} val Array, Node, String, or Region to center with
*/
center: function(val) {
var instance = this,
nodeRegion = instance.get(REGION),
x,
y;
if (isArray(val)) {
x = val[0];
y = val[1];
}
else {
var region;
if (isObject(val) && !A.instanceOf(val, ANode)) {
region = val;
}
else {
region = (A.one(val) || A.getBody()).get(REGION);
}
x = region.left + (region.width / 2);
y = region.top + (region.height / 2);
}
instance.setXY([x - (nodeRegion.width / 2), y - (nodeRegion.height / 2)]);
},
/**
* This method removes not only child (and other descendant) elements,
* but also any text within the set of matched elements. This is because,
* according to the DOM specification, any string of text within an element
* is considered a child node of that element.
*
* Example:
*
* var node = A.one('#nodeId');
* node.empty();
*
*
* @method empty
* @chainable
*/
empty: function() {
var instance = this;
instance.all('>*').remove().purge();
var el = ANode.getDOMNode(instance);
while (el.firstChild) {
el.removeChild(el.firstChild);
}
return instance;
},
/**
* Retrieves the DOM node bound to a Node instance. See
* getDOMNode .
*
* @method getDOM
* @return {HTMLNode} The DOM node bound to the Node instance.
*/
getDOM: function() {
var instance = this;
return ANode.getDOMNode(instance);
},
/**
* Return the combined width of the border for the specified sides.
*
* @method getBorderWidth
* @param {string} sides Can be t, r, b, l or any combination of
* those to represent the top, right, bottom, or left sides.
* @return {number}
*/
getBorderWidth: function(sides) {
var instance = this;
return instance._getBoxStyleAsNumber(sides, MAP_BORDER);
},
/**
* Get the current center position of the node in page coordinates.
*
* @method getCenterXY
* @for Node
* @return {Array} The XY position of the node
*/
getCenterXY: function() {
var instance = this;
var region = instance.get(REGION);
return [(region.left + region.width / 2), (region.top + region.height / 2)];
},
/**
* Return the combined size of the margin for the specified sides.
*
* @method getMargin
* @param {string} sides Can be t, r, b, l or any combination of
* those to represent the top, right, bottom, or left sides.
* @return {number}
*/
getMargin: function(sides) {
var instance = this;
return instance._getBoxStyleAsNumber(sides, MAP_MARGIN);
},
/**
* Return the combined width of the border for the specified sides.
*
* @method getPadding
* @param {string} sides Can be t, r, b, l or any combination of
* those to represent the top, right, bottom, or left sides.
* @return {number}
*/
getPadding: function(sides) {
var instance = this;
return instance._getBoxStyleAsNumber(sides, MAP_PADDING);
},
/**
* Set the id of the Node instance if the object does not have one. The
* generated id is based on a guid created by the
* stamp method.
*
* @method guid
* @return {String} The current id of the node
*/
guid: function() {
var instance = this;
var currentId = instance.get('id');
if (!currentId) {
currentId = A.stamp(instance);
instance.set('id', currentId);
}
return currentId;
},
/**
* Create a hover interaction.
*
* @method hover
* @param {string} overFn
* @param {string} outFn
* @return {Node} The current Node instance
*/
hover: function(overFn, outFn) {
var instance = this;
var hoverOptions;
var defaultHoverOptions = instance._defaultHoverOptions;
if (isObject(overFn, true)) {
hoverOptions = overFn;
hoverOptions = A.mix(hoverOptions, defaultHoverOptions);
overFn = hoverOptions.over;
outFn = hoverOptions.out;
}
else {
hoverOptions = A.mix({
over: overFn,
out: outFn
},
defaultHoverOptions
);
}
instance._hoverOptions = hoverOptions;
hoverOptions.overTask = A.debounce(instance._hoverOverTaskFn, null, instance);
hoverOptions.outTask = A.debounce(instance._hoverOutTaskFn, null, instance);
return new A.EventHandle(
[
instance.on(hoverOptions.overEventType, instance._hoverOverHandler, instance),
instance.on(hoverOptions.outEventType, instance._hoverOutHandler, instance)
]
);
},
/**
* Get or Set the HTML contents of the node. If the value
* is passed it's set the content of the element, otherwise it works as a
* getter for the current content.
*
* Example:
*
* var node = A.one('#nodeId');
* node.html('Setting new HTML');
* // Alert the value of the current content
* alert( node.html() );
*
*
* @method html
* @param {string} value A string of html to set as the content of the node instance.
*/
html: function() {
var args = arguments,
length = args.length;
if (length) {
this.set(INNER_HTML, args[0]);
}
else {
return this.get(INNER_HTML);
}
return this;
},
/**
* Get the outerHTML of a node, which islike innerHTML, except that it
* actually contains the HTML of the node itself.
*
* @method outerHTML
* @return {string} The outerHTML of the given element.
*/
outerHTML: function() {
var instance = this;
var domEl = instance.getDOM();
// IE, Opera and WebKit all have outerHTML.
if ('outerHTML' in domEl) {
return domEl.outerHTML;
}
var temp = ANode.create('
').append(
this.clone()
);
try {
return temp.html();
}
catch (e) {}
finally {
temp = null;
}
},
/**
* Inserts a newNode
after the node instance (i.e., as the next
* sibling). If the reference node has no parent, then does nothing.
*
* Example:
*
* var titleNode = A.one('#titleNode');
* var descriptionNode = A.one('#descriptionNode');
* // the description is usually shown after the title
* titleNode.placeAfter(descriptionNode);
*
*
* @method placeAfter
* @chainable
* @param {Node} newNode Node to insert.
*/
placeAfter: function(newNode) {
var instance = this;
return instance._place(newNode, instance.get(NEXT_SIBLING));
},
/**
* Inserts a newNode
before the node instance (i.e., as the previous
* sibling). If the reference node has no parent, then does nothing.
*
* Example:
*
* var descriptionNode = A.one('#descriptionNode');
* var titleNode = A.one('#titleNode');
* // the title is usually shown before the description
* descriptionNode.placeBefore(titleNode);
*
*
* @method placeBefore
* @chainable
* @param {Node} newNode Node to insert.
*/
placeBefore: function(newNode) {
var instance = this;
return instance._place(newNode, instance);
},
/**
* Inserts the node instance to the begining of the selector
* node (i.e., insert before the firstChild
of the
* selector
).
*
* Example:
*
* var node = A.one('#nodeId');
* node.prependTo('body');
*
*
* @method prependTo
* @chainable
* @param {Node | String} selector A selector, element, HTML string, Node
*/
prependTo: function(selector) {
var instance = this;
A.one(selector).prepend(instance);
return instance;
},
/**
* Add one or more CSS classes to an element and remove the class(es)
* from the siblings of the element.
*
* @method radioClass
* @chainable
* @param {String} cssClass
*/
radioClass: function(cssClass) {
var instance = this;
var siblings = instance.siblings();
if (isString(cssClass)) {
siblings.removeClass(cssClass);
instance.addClass(cssClass);
}
else if (isArray(cssClass)) {
var siblingNodes = siblings.getDOM();
var regex = getRegExp('(?:^|\\s+)(?:' + cssClass.join('|') + ')(?=\\s+|$)', 'g'),
node,
i;
for (i = siblingNodes.length - 1; i >= 0; i--) {
node = siblingNodes[i];
node.className = node.className.replace(regex, '');
}
instance.addClass(cssClass.join(' '));
}
return instance;
},
/**
* Generate an unique identifier and reset the id attribute of the node
* instance using the new value. Invokes the
* guid .
*
* @method resetId
* @chainable
* @param {String} prefix Optional prefix for the guid.
*/
resetId: function(prefix) {
var instance = this;
instance.attr('id', A.guid(prefix));
return instance;
},
/**
* Select a substring of text inside of the input element.
*
* @method selectText
* @param {Number} start The index to start the selection range from
* @param {Number} end The index to end the selection range at
*/
selectText: function(start, end) {
var instance = this;
var textField = instance.getDOM();
var length = instance.val().length;
end = isValue(end) ? end : length;
start = isValue(start) ? start : 0;
// Some form elements could throw a (NS_ERROR_FAILURE)
// [nsIDOMNSHTMLInputElement.setSelectionRange] error when invoke the
// setSelectionRange on firefox. Wrapping in a try/catch to prevent the error be thrown
try {
if (textField.setSelectionRange) {
textField.setSelectionRange(start, end);
}
else if (textField.createTextRange) {
var range = textField.createTextRange();
range.moveStart('character', start);
range.moveEnd('character', end - length);
range.select();
}
else {
textField.select();
}
if (textField !== DOC.activeElement) {
textField.focus();
}
}
catch (e) {}
return instance;
},
/**
* Enable text selection for this element (normalized across browsers).
*
* @method selectable
* @param noRecurse
* @chainable
*/
selectable: function(noRecurse) {
var instance = this;
instance.removeClass(CSS_UNSELECTABLE);
if (A.UA.ie || A.UA.opera) {
_setUnselectable(instance._node, false, noRecurse);
}
return instance;
},
/**
* Stop the specified event(s) from bubbling and optionally prevents the
* default action.
*
* Example:
*
* var anchor = A.one('a#anchorId');
* anchor.swallowEvent('click');
*
*
* @method swallowEvent
* @chainable
* @param {String/Array} eventName an event or array of events to stop from bubbling
* @param {Boolean} preventDefault (optional) true to prevent the default action too
*/
swallowEvent: function(eventName, preventDefault) {
var instance = this;
var fn = function(event) {
event.stopPropagation();
if (preventDefault) {
event.preventDefault();
event.halt();
}
return false;
};
if (isArray(eventName)) {
AArray.each(
eventName,
function(name) {
instance.on(name, fn);
}
);
return this;
}
else {
instance.on(eventName, fn);
}
return instance;
},
/**
* Get or Set the combined text contents of the node instance,
* including it's descendants. If the text
* is passed it's set the content of the element, otherwise it works as a
* getter for the current content.
*
* Example:
*
* var node = A.one('#nodeId');
* node.text('Setting new text content');
* // Alert the value of the current content
* alert( node.text() );
*
*
* @method text
* @param {String} text A string of text to set as the content of the node instance.
*/
text: function(text) {
var instance = this;
var el = instance.getDOM();
if (!isUndefined(text)) {
text = A.DOM._getDoc(el).createTextNode(text);
return instance.empty().append(text);
}
return instance._getText(el.childNodes);
},
/**
* Displays or hide the node instance.
*
* NOTE: This method assume that your node were hidden
* because of the 'aui-hide' css class were being used. This won't
* manipulate the inline style.display
property.
*
* @method toggle
* @chainable
* @param {Boolean} on Whether to force the toggle. Optional.
* @param {Function} callback A function to run after the visibility change. Optional.
*/
toggle: function(on, callback) {
var instance = this;
instance._toggleView.apply(instance, arguments);
return instance;
},
/**
* Disable text selection for this element (normalized across browsers).
*
* @method unselectable
* @param noRecurse
* @chainable
*/
unselectable: function(noRecurse) {
var instance = this;
instance.addClass(CSS_UNSELECTABLE);
if (A.UA.ie || A.UA.opera) {
_setUnselectable(instance._node, true, noRecurse);
}
return instance;
},
/**
* Get or Set the value attribute of the node instance. If the
* value
is passed it's set the value of the element,
* otherwise it works as a getter for the current value.
*
* Example:
*
* var input = A.one('#inputId');
* input.val('Setting new input value');
* // Alert the value of the input
* alert( input.val() );
*
*
* @method val
* @param {string} value Value to be set. Optional.
*/
val: function(value) {
var instance = this;
if (isUndefined(value)) {
return instance.get(VALUE);
}
else {
return instance.set(VALUE, value);
}
},
/**
* Return the combined size of the box style for the specified sides.
*
* @method _getBoxStyleAsNumber
* @param {string} sides Can be t, r, b, l or any combination of
* those to represent the top, right, bottom, or left sides.
* @param {string} map An object mapping mapping the "sides" param to the a CSS value to retrieve
* @return {number}
* @private
*/
_getBoxStyleAsNumber: function(sides, map) {
var instance = this;
var sidesArray = sides.match(/\w/g),
value = 0,
side,
sideKey,
i;
for (i = sidesArray.length - 1; i >= 0; i--) {
sideKey = sidesArray[i];
side = 0;
if (sideKey) {
side = parseFloat(instance.getComputedStyle(map[sideKey]));
side = Math.abs(side);
value += side || 0;
}
}
return value;
},
/**
* Extract text content from the passed nodes.
*
* @method _getText
* @private
* @param {Native NodeList} childNodes
*/
_getText: function(childNodes) {
var instance = this;
var length = childNodes.length,
childNode,
str = [],
i;
for (i = 0; i < length; i++) {
childNode = childNodes[i];
if (childNode && childNode.nodeType !== 8) {
if (childNode.nodeType !== 1) {
str.push(childNode.nodeValue);
}
if (childNode.childNodes) {
str.push(instance._getText(childNode.childNodes));
}
}
}
return str.join(STR_EMPTY);
},
/**
* Overrides Y.Node._hide. Adds aui-hide to the node's cssClass
*
* @method _hide
* @private
*/
_hide: function() {
var instance = this;
instance.addClass(CSS_HIDE);
return NODE_PROTO_HIDE.apply(instance, arguments);
},
/**
* The event handler for the "out" function that is fired for events attached via the hover method.
*
* @method _hoverOutHandler
* @private
* @param {EventFacade} event
*/
_hoverOutHandler: function(event) {
var instance = this;
var hoverOptions = instance._hoverOptions;
hoverOptions.outTask.delay(hoverOptions.outDelay, event);
},
/**
* The event handler for the "over" function that is fired for events attached via the hover method.
*
* @method _hoverOverHandler
* @private
* @param {EventFacade} event
*/
_hoverOverHandler: function(event) {
var instance = this;
var hoverOptions = instance._hoverOptions;
hoverOptions.overTask.delay(hoverOptions.overDelay, event);
},
/**
* Cancels the over task, and fires the users custom "out" function for the hover method
*
* @method _hoverOverHandler
* @private
* @param {EventFacade} event
*/
_hoverOutTaskFn: function(event) {
var instance = this;
var hoverOptions = instance._hoverOptions;
hoverOptions.overTask.cancel();
hoverOptions.out.apply(hoverOptions.context || event.currentTarget, arguments);
},
/**
* Cancels the out task, and fires the users custom "over" function for the hover method
*
* @method _hoverOverHandler
* @private
* @param {EventFacade} event
*/
_hoverOverTaskFn: function(event) {
var instance = this;
var hoverOptions = instance._hoverOptions;
hoverOptions.outTask.cancel();
hoverOptions.over.apply(hoverOptions.context || event.currentTarget, arguments);
},
/**
* Place a node or html string at a specific location
*
* @method _place
* @private
* @param {Node|String} newNode
* @param {Node} refNode
*/
_place: function(newNode, refNode) {
var instance = this;
var parent = instance.get(PARENT_NODE);
if (parent) {
if (isString(newNode)) {
newNode = ANode.create(newNode);
}
parent.insertBefore(newNode, refNode);
}
return instance;
},
/**
* Overrides Y.Node._show. Removes aui-hide from the node's cssClass
*
* @method _show
* @private
*/
_show: function() {
var instance = this;
instance.removeClass(CSS_HIDE);
return NODE_PROTO_SHOW.apply(instance, arguments);
},
_defaultHoverOptions: {
overEventType: 'mouseenter',
outEventType: 'mouseleave',
overDelay: 0,
outDelay: 0,
over: Lang.emptyFn,
out: Lang.emptyFn
}
}, true);
NODE_PROTO.__isHidden = NODE_PROTO._isHidden;
NODE_PROTO._isHidden = function() {
var instance = this;
return NODE_PROTO.__isHidden.call(instance) || instance.hasClass(instance._hideClass || CSS_HIDE);
};
/**
* Return the width of the content, not including
* the padding, border or margin. If a width is passed,
* the node's overall width is set to that size.
*
* Example:
*
* var node = A.one('#nodeId');
* node.width(); //return content width
* node.width(100); // sets box width
*
*
* @method width
* @return {number}
*/
/**
* Return the height of the content, not including
* the padding, border or margin. If a height is passed,
* the node's overall height is set to that size.
*
* Example:
*
* var node = A.one('#nodeId');
* node.height(); //return content height
* node.height(100); // sets box height
*
*
* @method height
* @return {number}
*/
/**
* Return the size of the box from inside of the border,
* which is the offsetWidth plus the padding on the left and right.
*
* Example:
*
* var node = A.one('#nodeId');
* node.innerWidth();
*
*
* @method innerWidth
* @return {number}
*/
/**
* Return the size of the box from inside of the border,
* which is offsetHeight plus the padding on the top and bottom.
*
* Example:
*
* var node = A.one('#nodeId');
* node.innerHeight();
*
*
* @method innerHeight
* @return {number}
*/
/**
* Return the outer width of the box including the border,
* if true is passed as the first argument, the margin is included.
*
* Example:
*
* var node = A.one('#nodeId');
* node.outerWidth();
* node.outerWidth(true); // includes margin
*
*
* @method outerWidth
* @return {number}
*/
/**
* Return the outer height of the box including the border,
* if true is passed as the first argument, the margin is included.
*
* Example:
*
* var node = A.one('#nodeId');
* node.outerHeight();
* node.outerHeight(true); // includes margin
*
*
* @method outerHeight
* @return {number}
*/
A.each(
['Height', 'Width'],
function(item, index, collection) {
var sides = index ? 'lr' : 'tb';
var dimensionType = item.toLowerCase();
NODE_PROTO[dimensionType] = function(size) {
var instance = this;
var returnValue = instance;
if (isUndefined(size)) {
var node = instance._node;
var dimension;
if (node) {
if ((!node.tagName && node.nodeType === 9) || node.alert) {
dimension = instance.get(REGION)[dimensionType];
}
else {
dimension = instance.get(OFFSET + item);
if (!dimension) {
instance.addClass(CSS_FORCE_OFFSET);
dimension = instance.get(OFFSET + item);
instance.removeClass(CSS_FORCE_OFFSET);
}
if (dimension) {
dimension -= (instance.getPadding(sides) + instance.getBorderWidth(sides));
}
}
}
returnValue = dimension;
}
else {
instance.setStyle(dimensionType, size);
}
return returnValue;
};
NODE_PROTO[INNER + item] = function() {
var instance = this;
return instance[dimensionType]() + instance.getPadding(sides);
};
NODE_PROTO[OUTER + item] = function(margin) {
var instance = this;
var innerSize = instance[INNER + item]();
var borderSize = instance.getBorderWidth(sides);
var size = innerSize + borderSize;
if (margin) {
size += instance.getMargin(sides);
}
return size;
};
}
);
if (!SUPPORT_OPTIONAL_TBODY) {
A.DOM._ADD_HTML = A.DOM.addHTML;
A.DOM.addHTML = function(node, content, where) {
var nodeName = (node.nodeName && node.nodeName.toLowerCase()) || STR_EMPTY;
var tagName = STR_EMPTY;
if (!isUndefined(content)) {
if (isString(content)) {
tagName = (REGEX_TAGNAME.exec(content) || ARRAY_EMPTY_STRINGS)[1];
}
else if (content.nodeType && content.nodeType === 11 && content.childNodes.length) { // a doc frag
tagName = content.childNodes[0].nodeName;
}
else if (content.nodeName) { // a node
tagName = content.nodeName;
}
tagName = tagName && tagName.toLowerCase();
}
if (nodeName === 'table' && tagName === 'tr') {
node = node.getElementsByTagName('tbody')[0] || node.appendChild(node.ownerDocument.createElement('tbody'));
var whereNodeName = ((where && where.nodeName) || STR_EMPTY).toLowerCase();
// Assuming if the "where" is a tbody node,
// we're trying to prepend to a table. Attempt to
// grab the first child of the tbody.
if (whereNodeName === 'tbody' && where.childNodes.length > 0) {
where = where.firstChild;
}
}
return A.DOM._ADD_HTML(node, content, where);
};
}
/**
* Augment the YUI3 NodeList with more util methods.
*
* Check the list of Methods available for
* AUI NodeList.
*
* @class A.NodeList
* @constructor
* @uses A.Node
*/
ANodeList.importMethod(
NODE_PROTO, [
'after',
'appendTo',
'attr',
'before',
'empty',
'getX',
'getXY',
'getY',
'hover',
'html',
'innerHeight',
'innerWidth',
'outerHeight',
'outerHTML',
'outerWidth',
'prepend',
'prependTo',
'purge',
'selectText',
'selectable',
'setX',
'setXY',
'setY',
'text',
'toggle',
'unselectable',
'val'
]
);
A.mix(
NODELIST_PROTO, {
/**
* See Node all .
*
* @method all
*/
all: function(selector) {
var instance = this,
newNodeList = [],
nodes = instance._nodes,
length = nodes.length,
subList,
i;
for (i = 0; i < length; i++) {
subList = A.Selector.query(selector, nodes[i]);
if (subList && subList.length) {
newNodeList.push.apply(newNodeList, subList);
}
}
newNodeList = AArray.unique(newNodeList);
return A.all(newNodeList);
},
/**
* Return the first element in the node list collection.
*
* @method first
* @return {Node}
*/
first: function() {
var instance = this;
return instance.item(0);
},
/**
* See Node getDOM .
*
* @method getDOM
*/
getDOM: function() {
var instance = this;
return ANodeList.getDOMNodes(this);
},
/**
* Return the last element in the node list collection.
*
* @method last
* @return {Node}
*/
last: function() {
var instance = this;
return instance.item(instance._nodes.length - 1);
},
/**
* See Node one .
*
* @method one
*/
one: function(selector) {
var instance = this,
newNode = null,
nodes = instance._nodes,
length = nodes.length,
i;
for (i = 0; i < length; i++) {
newNode = A.Selector.query(selector, nodes[i], true);
if (newNode) {
newNode = A.one(newNode);
break;
}
}
return newNode;
}
}
);
NODELIST_PROTO.__filter = NODELIST_PROTO.filter;
NODELIST_PROTO.filter = function(value, context) {
var instance = this;
var newNodeList;
if (isFunction(value)) {
var nodes = [];
instance.each(
function(item, index, collection) {
if (value.call(context || item, item, index, collection)) {
nodes.push(item._node);
}
}
);
newNodeList = A.all(nodes);
}
else {
newNodeList = NODELIST_PROTO.__filter.call(instance, value);
}
return newNodeList;
};
A.mix(
ANodeList, {
/**
* Converts the passed `html` into a `NodeList` and returns the result.
*
* @method create
* @param {String} html
* @return {NodeList}
*/
create: function(html) {
var docFrag = A.getDoc().invoke(CREATE_DOCUMENT_FRAGMENT);
return docFrag.append(html).get(CHILD_NODES);
}
}
);
A.mix(
A, {
/**
* Get the body node. Shortcut to A.one('body')
.
*
* @method getBody
*/
getBody: function() {
var instance = this;
if (!instance._bodyNode) {
instance._bodyNode = A.one(DOC.body);
}
return instance._bodyNode;
},
/**
* Get the document node. Shortcut to A.one(document)
.
*
* @method getDoc
*/
getDoc: function() {
var instance = this;
if (!instance._documentNode) {
instance._documentNode = A.one(DOC);
}
return instance._documentNode;
},
/**
* Get the window node. Shortcut to A.one(window)
.
*
* @method getWin
*/
getWin: function() {
var instance = this;
if (!instance._windowNode) {
instance._windowNode = A.one(WIN);
}
return instance._windowNode;
}
}
);
}, '2.0.0', {"requires": ["array-extras", "aui-base-lang", "aui-classnamemanager", "aui-debounce", "node"]});
YUI.add('aui-node-html5', function (A, NAME) {
/**
* Provides support for HTML shiv natively on the Alloy DOM
* methods. The HTML5 shiv just affects IE.
*
* @module aui-node
* @submodule aui-node-html5
*/
if (A.UA.ie) {
/**
* An object that encapsulates util methods for HTML5 shiving.
* What is a "shiv"?
* To the world, a shiv is a slang term for a sharp object used as a
* knife-like weapon. To Internet Explorer, a shiv is a script that, when
* executed, forces the browser to recognize HTML5 elements.
*
* @class A.HTML5
*/
var HTML5 = A.namespace('HTML5'),
DOM_create = A.DOM._create;
if (!HTML5._fragHTML5Shived) {
/**
* A global DocumentFragment already HTML5 shived, for performance
* reasons. (i.e., all nodes and its HTML5 children appended to this
* fragment iherits the styles on IE).
*
* @property A.HTML._fragHTML5Shived
* @type DocumentFragment (shived)
* @protected
*/
HTML5._fragHTML5Shived = A.html5shiv(
A.config.doc.createDocumentFragment()
);
}
A.mix(
HTML5, {
/**
* Receive a frag
and a HTML content. This method
* shivs the HTML5 nodes appended to a Node or fragment which is not
* on the document yet.
*
* @method IECreateFix
* @param {Node | DocumentFragment} frag Fragment to be fixed.
* @param {String} content HTML to be set (using innerHTML) on the frag
.
* @return {Node | DocumentFragment}
*/
IECreateFix: function(frag, content) {
var shivedFrag = HTML5._fragHTML5Shived;
shivedFrag.appendChild(frag);
frag.innerHTML = content;
shivedFrag.removeChild(frag);
return frag;
},
/**
* AOP listener to the A.DOM._create method. This method
* intercepts all the calls to the A.DOM._create and append the
* generated fragment to A.HTML._fragHTML5Shived ,
* this fixes the IE bug for painting the HTML5 nodes on the HTML
* fragment.
*
* @method _doBeforeCreate
* @param {String} html HTML content
* @param {String} doc
* @param {String} tag
* @protected
* @return {DocumentFragment}
*/
_doBeforeCreate: function(html, doc, tag) {
var createdFrag = DOM_create.apply(this, arguments);
var shivedFrag = HTML5.IECreateFix(createdFrag, html);
return new A.Do.Halt(null, shivedFrag);
}
}
);
A.Do.before(HTML5._doBeforeCreate, A.DOM, '_create', A.DOM);
}
/**
* The Node Utility.
*
* @module aui-node
* @submodule aui-node-html5-print
*/
var CONFIG = A.config,
DOC = CONFIG.doc,
WIN = CONFIG.win,
UA = A.UA,
IE = UA.ie,
isShivDisabled = function() {
return WIN.AUI_HTML5_IE === false;
};
if (!IE || IE >= 9 || isShivDisabled()) {
return;
}
var BUFFER_CSS_TEXT = [],
CSS_PRINTFIX = 'printfix',
CSS_PRINTFIX_PREFIX = 'printfix-',
LOCATION = WIN.location,
DOMAIN = LOCATION.protocol + '//' + LOCATION.host,
HTML = DOC.documentElement,
HTML5_ELEMENTS = A.HTML5_ELEMENTS,
HTML5_ELEMENTS_LENGTH = HTML5_ELEMENTS.length,
HTML5_ELEMENTS_LIST = HTML5_ELEMENTS.join('|'),
REGEX_CLONE_NODE_CLEANUP = new RegExp('<(/?):(' + HTML5_ELEMENTS_LIST + ')', 'gi'),
REGEX_ELEMENTS = new RegExp('(' + HTML5_ELEMENTS_LIST + ')', 'gi'),
REGEX_ELEMENTS_FAST = new RegExp('\\b(' + HTML5_ELEMENTS_LIST + ')\\b', 'i'),
REGEX_PRINT_MEDIA = /print|all/,
REGEX_RULE = new RegExp('(^|[^\\n{}]*?\\s)(' + HTML5_ELEMENTS_LIST + ').*?{([^}]*)}', 'gim'),
REGEX_TAG = new RegExp('<(\/*)(' + HTML5_ELEMENTS_LIST + ')', 'gi'),
SELECTOR_REPLACE_RULE = '.' + CSS_PRINTFIX_PREFIX + '$1',
STR_ALL = 'all',
STR_BLANK = ' ',
STR_EMPTY = '',
STR_BRACKET_OPEN = '{',
STR_BRACKET_CLOSE = '}',
STR_CHECKBOX = 'checkbox',
STR_CHECKED = 'checked',
STR_HTTPS = 'https',
STR_IFRAME = 'IFRAME',
STR_INPUT = 'INPUT',
STR_OPTION = 'OPTION',
STR_RADIO = 'radio',
STR_SELECTED = 'selected',
STR_STAR = '*',
STR_URL = 'url(',
STR_URL_DOMAIN = STR_URL + DOMAIN,
TAG_REPLACE_ORIGINAL = '<$1$2',
TAG_REPLACE_FONT = '<$1font';
var html5shiv = A.html5shiv,
// Yes, IE does this wackiness; converting an object
// to a string should never result in undefined, but
// IE's styleSheet object sometimes becomes inaccessible
// after trying to print the second time
isStylesheetDefined = function(obj) {
return obj && (obj + STR_EMPTY !== undefined);
},
toggleNode = function(node, origNode, prop) {
var state = origNode[prop];
if (state) {
node.setAttribute(prop, state);
}
else {
node.removeAttribute(prop);
}
};
html5shiv(DOC);
var PrintFix = function() {
var afterPrint = function() {
if (isShivDisabled()) {
destroy();
}
else {
PrintFix.onAfterPrint();
}
};
var beforePrint = function() {
if (isShivDisabled()) {
destroy();
}
else {
PrintFix.onBeforePrint();
}
};
var destroy = function() {
WIN.detachEvent('onafterprint', afterPrint);
WIN.detachEvent('onbeforeprint', beforePrint);
};
var init = function() {
WIN.attachEvent('onafterprint', afterPrint);
WIN.attachEvent('onbeforeprint', beforePrint);
};
init();
PrintFix.destroy = destroy;
PrintFix.init = init;
};
A.mix(
PrintFix, {
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method onAfterPrint
*/
onAfterPrint: function() {
var instance = this;
instance.restoreHTML();
var styleSheet = instance._getStyleSheet();
styleSheet.styleSheet.cssText = STR_EMPTY;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method onBeforePrint
*/
onBeforePrint: function() {
var instance = this;
var styleSheet = instance._getStyleSheet();
var cssRules = instance._getAllCSSText();
styleSheet.styleSheet.cssText = instance.parseCSS(cssRules);
instance.writeHTML();
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method parseCSS
* @param cssText
*/
parseCSS: function(cssText) {
var instance = this;
var css = STR_EMPTY;
var rules = cssText.match(REGEX_RULE);
if (rules) {
css = rules.join('\n').replace(REGEX_ELEMENTS, SELECTOR_REPLACE_RULE);
}
return css;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method restoreHTML
*/
restoreHTML: function() {
var instance = this;
var bodyClone = instance._getBodyClone();
var bodyEl = instance._getBodyEl();
var newNodes = bodyClone.getElementsByTagName(STR_IFRAME);
var originalNodes = bodyEl.getElementsByTagName(STR_IFRAME);
var length = originalNodes.length;
// Moving IFRAME nodes back to their original position
if (length === newNodes.length) {
while (length--) {
var newNode = newNodes[length];
var originalNode = originalNodes[length];
originalNode.swapNode(newNode);
}
}
bodyClone.innerHTML = STR_EMPTY;
HTML.removeChild(bodyClone);
HTML.appendChild(bodyEl);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method writeHTML
*/
writeHTML: function() {
var instance = this;
var i = -1;
var j;
var bodyEl = instance._getBodyEl();
var html5Element;
var cssClass;
var nodeList;
var nodeListLength;
var node;
var buffer = [];
while (++i < HTML5_ELEMENTS_LENGTH) {
html5Element = HTML5_ELEMENTS[i];
nodeList = DOC.getElementsByTagName(html5Element);
nodeListLength = nodeList.length;
j = -1;
while (++j < nodeListLength) {
node = nodeList[j];
cssClass = node.className;
if (cssClass.indexOf(CSS_PRINTFIX_PREFIX) == -1) {
buffer[0] = CSS_PRINTFIX_PREFIX + html5Element;
buffer[1] = cssClass;
node.className = buffer.join(STR_BLANK);
}
}
}
var docFrag = instance._getDocFrag();
var bodyClone = instance._getBodyClone();
docFrag.appendChild(bodyEl);
HTML.appendChild(bodyClone);
bodyClone.className = bodyEl.className;
bodyClone.id = bodyEl.id;
var originalNodes = bodyEl.getElementsByTagName(STR_STAR);
var length = originalNodes.length;
// IE will throw a mixed content warning when using https
// and calling clone node if the body contains elements with
// an inline background-image style that is relative to the domain.
if (UA.secure) {
var bodyElStyle = bodyEl.style;
var elStyle;
var backgroundImage;
bodyElStyle.display = 'none';
for (i = 0; i < length; i++) {
elStyle = originalNodes[i].style;
backgroundImage = elStyle.backgroundImage;
if (backgroundImage &&
backgroundImage.indexOf(STR_URL) > -1 &&
backgroundImage.indexOf(STR_HTTPS) == -1) {
elStyle.backgroundImage = backgroundImage.replace(STR_URL, STR_URL_DOMAIN);
}
}
bodyElStyle.display = STR_EMPTY;
}
var bodyElClone = bodyEl.cloneNode(true);
var newNodes = bodyElClone.getElementsByTagName(STR_STAR);
if (length == newNodes.length) {
while (length--) {
var newNode = newNodes[length];
var newNodeName = newNode.nodeName;
if (newNodeName == STR_INPUT || newNodeName == STR_OPTION || newNodeName === STR_IFRAME) {
var originalNode = originalNodes[length];
var originalNodeName = originalNode.nodeName;
if (originalNodeName == newNodeName) {
var prop = null;
if (newNodeName == STR_OPTION) {
prop = STR_SELECTED;
}
else if (newNodeName == STR_INPUT && (newNode.type == STR_CHECKBOX || newNode.type ==
STR_RADIO)) {
prop = STR_CHECKED;
}
else if (newNodeName === STR_IFRAME) {
newNode.src = STR_EMPTY;
}
if (prop !== null) {
toggleNode(newNode, originalNode, prop);
}
}
}
}
}
var bodyHTML = bodyElClone.innerHTML;
bodyHTML = bodyHTML.replace(REGEX_CLONE_NODE_CLEANUP, TAG_REPLACE_ORIGINAL).replace(REGEX_TAG,
TAG_REPLACE_FONT);
bodyClone.innerHTML = bodyHTML;
// Post processing the DOM in order to move IFRAME nodes
newNodes = bodyClone.getElementsByTagName(STR_IFRAME);
originalNodes = bodyEl.getElementsByTagName(STR_IFRAME);
length = originalNodes.length;
if (length === newNodes.length) {
while (length--) {
var newNodeIframe = newNodes[length];
var originalNodeIframe = originalNodes[length];
// According to quirksmode.org, swapNode is supported on all major IE versions
originalNodeIframe.swapNode(newNodeIframe);
}
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _getAllCSSText
* @protected
*/
_getAllCSSText: function() {
var instance = this;
var buffer = [];
var styleSheets = instance._getAllStyleSheets(DOC.styleSheets, STR_ALL);
var rule;
var cssText;
for (var i = 0; styleSheet = styleSheets[i]; i++) {
var rules = styleSheet.rules;
if (rules && rules.length) {
for (var j = 0, ruleLength = rules.length; j < ruleLength; j++) {
rule = rules[j];
if (!rule.href) {
cssText = instance._getCSSTextFromRule(rule);
buffer.push(cssText);
}
}
}
}
return buffer.join(STR_BLANK);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _getCSSTextFromRule
* @param rule
* @protected
*/
_getCSSTextFromRule: function(rule) {
var instance = this;
var cssText = STR_EMPTY;
var ruleStyle = rule.style;
var ruleCSSText;
var ruleSelectorText;
if (ruleStyle && (ruleCSSText = ruleStyle.cssText) && (ruleSelectorText = rule.selectorText) &&
REGEX_ELEMENTS_FAST.test(ruleSelectorText)) {
BUFFER_CSS_TEXT.length = 0;
BUFFER_CSS_TEXT.push(ruleSelectorText, STR_BRACKET_OPEN, ruleCSSText, STR_BRACKET_CLOSE);
cssText = BUFFER_CSS_TEXT.join(STR_BLANK);
}
return cssText;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _getAllStyleSheets
* @param styleSheet
* @param mediaType
* @param level
* @param buffer
* @protected
*/
_getAllStyleSheets: function(styleSheet, mediaType, level, buffer) {
var instance = this;
level = level || 1;
buffer = buffer || [];
var i;
if (isStylesheetDefined(styleSheet)) {
var imports = styleSheet.imports;
mediaType = styleSheet.mediaType || mediaType;
if (REGEX_PRINT_MEDIA.test(mediaType)) {
var length;
// IE can crash when trying to access imports more than 3 levels deep
if (level <= 3 && isStylesheetDefined(imports) && imports.length) {
for (i = 0, length = imports.length; i < length; i++) {
instance._getAllStyleSheets(imports[i], mediaType, level + 1, buffer);
}
}
else if (styleSheet.length) {
for (i = 0, length = styleSheet.length; i < length; i++) {
instance._getAllStyleSheets(styleSheet[i], mediaType, level, buffer);
}
}
else {
var rules = styleSheet.rules;
var ruleStyleSheet;
if (rules && rules.length) {
for (i = 0, length = rules.length; i < length; i++) {
ruleStyleSheet = rules[i].styleSheet;
if (ruleStyleSheet) {
instance._getAllStyleSheets(ruleStyleSheet, mediaType, level, buffer);
}
}
}
}
if (!styleSheet.disabled && styleSheet.rules) {
buffer.push(styleSheet);
}
}
}
mediaType = STR_ALL;
return buffer;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _getBodyEl
* @protected
*/
_getBodyEl: function() {
var instance = this;
var bodyEl = instance._bodyEl;
if (!bodyEl) {
bodyEl = DOC.body;
instance._bodyEl = bodyEl;
}
return bodyEl;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _getBodyClone
* @protected
*/
_getBodyClone: function() {
var instance = this;
var bodyClone = instance._bodyClone;
if (!bodyClone) {
bodyClone = DOC.createElement('body');
instance._bodyClone = bodyClone;
}
return bodyClone;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _getDocFrag
* @protected
*/
_getDocFrag: function() {
var instance = this;
var docFrag = instance._docFrag;
if (!docFrag) {
docFrag = DOC.createDocumentFragment();
html5shiv(docFrag);
instance._docFrag = docFrag;
}
return docFrag;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _getStyleSheet
* @protected
*/
_getStyleSheet: function() {
var instance = this;
var styleSheet = instance._styleSheet;
if (!styleSheet) {
styleSheet = DOC.createElement('style');
var head = DOC.documentElement.firstChild;
head.insertBefore(styleSheet, head.firstChild);
styleSheet.media = 'print';
styleSheet.className = CSS_PRINTFIX;
instance._styleSheet = styleSheet;
}
return styleSheet;
}
}
);
A.namespace('HTML5').PrintFix = PrintFix;
PrintFix();
}, '2.0.0', {"requires": ["collection", "aui-node-base"]});
YUI.add('aui-selector', function (A, NAME) {
/**
* The Selector Utility.
*
* @module aui-selector
*/
var Lang = A.Lang,
isString = Lang.isString,
SELECTOR = A.Selector,
getClassName = A.getClassName,
CSS_HIDE = A.getClassName('hide'),
REGEX_HIDDEN_CLASSNAMES = new RegExp(CSS_HIDE);
SELECTOR._isNodeHidden = function(node) {
var width = node.offsetWidth;
var height = node.offsetHeight;
var ignore = node.nodeName.toLowerCase() == 'tr';
var className = node.className;
var nodeStyle = node.style;
var hidden = false;
if (!ignore) {
if (width == 0 && height == 0) {
hidden = true;
}
else if (width > 0 && height > 0) {
hidden = false;
}
}
hidden = hidden || (nodeStyle.display == 'none' || nodeStyle.visibility == 'hidden') || REGEX_HIDDEN_CLASSNAMES.test(
className);
return hidden;
};
var testNodeType = function(type) {
return function(node) {
return node.type == type;
};
};
/**
* Augment the YUI3 Selector with more util methods.
*
* @class A.Selector
* @uses Selector
* @constructor
*/
A.mix(
SELECTOR.pseudos, {
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method button
* @param node
*/
button: function(node) {
return node.type === 'button' || node.nodeName.toLowerCase() === 'button';
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method checkbox
*/
checkbox: testNodeType('checkbox'),
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method checked
* @param node
*/
checked: function(node) {
return node.checked === true;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method disabled
* @param node
*/
disabled: function(node) {
return node.disabled === true;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method empty
* @param node
*/
empty: function(node) {
return !node.firstChild;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method enabled
* @param node
*/
enabled: function(node) {
return node.disabled === false && node.type !== 'hidden';
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method file
*/
file: testNodeType('file'),
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method header
* @param node
*/
header: function(node) {
return /h\d/i.test(node.nodeName);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method hidden
* @param node
*/
hidden: function(node) {
return SELECTOR._isNodeHidden(node);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method image
*/
image: testNodeType('image'),
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method input
* @param node
*/
input: function(node) {
return /input|select|textarea|button/i.test(node.nodeName);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method parent
* @param node
*/
parent: function(node) {
return !!node.firstChild;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method password
*/
password: testNodeType('password'),
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method radio
*/
radio: testNodeType('radio'),
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method reset
*/
reset: testNodeType('reset'),
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method selected
* @param node
*/
selected: function(node) {
node.parentNode.selectedIndex;
return node.selected === true;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method submit
*/
submit: testNodeType('submit'),
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method text
*/
text: testNodeType('text'),
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method visible
* @param node
*/
visible: function(node) {
return !SELECTOR._isNodeHidden(node);
}
}
);
}, '2.0.0', {"requires": ["selector-css3", "aui-classnamemanager"]});
YUI.add('aui-timer', function (A, NAME) {
/**
* Utility for timing logics.
*
* @module aui-timer
*/
var Lang = A.Lang,
now = Lang.now,
isEmpty = A.Object.isEmpty,
AArray = A.Array;
var Timer = {
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method clearInterval
* @param id
*/
clearInterval: function(id) {
var instance = Timer;
instance.unregister(true, id);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method clearTimeout
* @param id
*/
clearTimeout: function(id) {
var instance = Timer;
instance.unregister(false, id);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method intervalTime
* @param newInterval
*/
intervalTime: function(newInterval) {
var instance = Timer;
if (arguments.length) {
instance._INTERVAL = newInterval;
}
return instance._INTERVAL;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method isRepeatable
* @param task
*/
isRepeatable: function(task) {
var instance = Timer;
return task.repeats;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method setTimeout
* @param fn
* @param ms
* @param context
*/
setTimeout: function(fn, ms, context) {
var instance = Timer;
var args = AArray(arguments, 3, true);
return instance.register(false, fn, ms, context, args);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method setInterval
* @param fn
* @param ms
* @param context
*/
setInterval: function(fn, ms, context) {
var instance = Timer;
var args = AArray(arguments, 3, true);
return instance.register(true, fn, ms, context, args);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method register
* @param repeats
* @param fn
* @param ms
* @param context
* @param args
*/
register: function(repeats, fn, ms, context, args) {
var instance = Timer;
var id = (++A.Env._uidx);
args = args || [];
args.unshift(fn, context);
instance._TASKS[id] = instance._create(repeats, instance._getNearestInterval(ms), A.rbind.apply(A, args));
instance._lazyInit();
return id;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method run
* @param task
*/
run: function(task) {
var instance = Timer;
task.lastRunTime = now();
return task.fn();
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method unregister
* @param repeats
* @param id
*/
unregister: function(repeats, id) {
var instance = Timer;
var tasks = instance._TASKS;
var task = tasks[id];
instance._lazyDestroy();
return task && task.repeats === repeats && delete tasks[id];
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _create
* @param repeats
* @param ms
* @param fn
* @protected
*/
_create: function(repeats, ms, fn) {
var instance = Timer;
return {
fn: fn,
lastRunTime: now(),
next: ms,
repeats: repeats,
timeout: ms
};
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _decrementNextRunTime
* @param tasks
* @protected
*/
_decrementNextRunTime: function(task) {
var instance = Timer;
return task.next = task.timeout - (now() - task.lastRunTime);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _getNearestInterval
* @param num
* @protected
*/
_getNearestInterval: function(num) {
var instance = Timer;
var interval = instance._INTERVAL;
var delta = num % interval;
var nearestInterval;
if (delta < interval / 2) {
nearestInterval = num - delta;
}
else {
nearestInterval = num + interval - delta;
}
return nearestInterval;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _lazyDestroy
* @protected
*/
_lazyDestroy: function() {
var instance = Timer;
if (instance._initialized && isEmpty(instance._TASKS)) {
clearTimeout(instance._globalIntervalId);
instance._initialized = false;
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _lazyInit
* @protected
*/
_lazyInit: function() {
var instance = Timer;
if (!instance._initialized && !isEmpty(instance._TASKS)) {
instance._lastRunTime = now();
instance._globalIntervalId = setTimeout(instance._runner, instance._INTERVAL);
instance._initialized = true;
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _loop
* @param i
* @param pendingTasks
* @param length
* @protected
*/
_loop: function(i, pendingTasks, length) {
var instance = Timer;
var interval = instance._INTERVAL;
var tasks = instance._TASKS;
var halfInterval = interval / 2;
for (var start = now(); i < length && now() - start < 50; i++) {
var taskId = pendingTasks[i];
var task = tasks[taskId];
if (task && instance._decrementNextRunTime(task) < halfInterval) {
instance.run(task);
if (instance.isRepeatable(task)) {
instance._resetNextRunTime(task);
}
else {
instance.unregister(false, taskId);
}
}
}
if (instance._initialized) {
if (i < length) {
instance._globalIntervalId = setTimeout(instance._loop, 10);
}
else {
instance._globalIntervalId = setTimeout(instance._runner, interval);
}
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _runner
* @protected
*/
_runner: function() {
var instance = Timer;
var i = 0;
var pendingTasks = A.Object.keys(instance._TASKS);
var length = pendingTasks.length;
instance._loop(i, pendingTasks, length);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _resetNextRunTime
* @param task
* @protected
*/
_resetNextRunTime: function(task) {
var instance = Timer;
return task.next = task.timeout;
},
_INTERVAL: 50,
_TASKS: {},
_lastRunTime: 0,
_globalIntervalId: 0,
_initialized: false
};
A.clearInterval = Timer.clearInterval;
A.clearTimeout = Timer.clearTimeout;
A.setInterval = Timer.setInterval;
A.setTimeout = Timer.setTimeout;
A.Timer = Timer;
}, '2.0.0', {"requires": ["oop"]});
(function() {
var A = AUI().use('oop');
var usedModules = {};
var emptyFn = function() {};
var Dependency = {
provide: function(obj, methodName, methodFn, modules, proto) {
if (!A.Lang.isArray(modules)) {
modules = [modules];
}
var guid = A.guid();
var before;
if (A.Lang.isObject(methodFn, true)) {
var config = methodFn;
methodFn = config.fn;
before = config.before;
if (!A.Lang.isFunction(before)) {
before = null;
}
}
if (proto && A.Lang.isFunction(obj)) {
obj = obj.prototype;
}
var AOP = Dependency._getAOP(obj, methodName);
if (AOP) {
delete obj._yuiaop[methodName];
}
var proxy = function() {
var args = arguments;
var context = obj;
if (proto) {
context = this;
}
if (modules.length == 1) {
if (modules[0] in usedModules) {
Dependency._replaceMethod(obj, methodName, methodFn, context);
methodFn.apply(context, args);
return;
}
}
var queue = Dependency._proxyLoaders[guid];
var firstLoad = false;
if (!queue) {
firstLoad = true;
Dependency._proxyLoaders[guid] = new A.Queue();
queue = Dependency._proxyLoaders[guid];
}
queue.add(args);
if (firstLoad) {
modules.push(A.bind(Dependency._proxy, Liferay, obj, methodName, methodFn, context, guid, modules));
A.use.apply(A, modules);
}
};
proxy.toString = function() {
return methodFn.toString();
};
obj[methodName] = proxy;
},
_getAOP: function(obj, methodName) {
var instance = this;
return obj._yuiaop && obj._yuiaop[methodName];
},
_proxy: function(obj, methodName, methodFn, context, guid, modules, A) {
var queue = Dependency._proxyLoaders[guid];
var args;
Dependency._replaceMethod(obj, methodName, methodFn, context);
while ((args = queue.next())) {
methodFn.apply(context, args);
}
for (var i = modules.length - 1; i >= 0; i--) {
usedModules[modules[i]] = true;
}
},
_replaceMethod: function(obj, methodName, methodFn, context) {
var instance = this;
var AOP = Dependency._getAOP(obj, methodName);
var proxy = obj[methodName];
if (AOP) {
proxy = AOP.method;
AOP.method = methodFn;
}
else {
obj[methodName] = methodFn;
}
A.mix(methodFn, proxy);
},
_proxyLoaders: {}
};
Liferay.Dependency = Dependency;
Liferay.provide = Dependency.provide;
})();
Liferay.on = function(){};
Liferay.fire = function(){};
Liferay.detach = function(){};
;(function(A, Liferay) {
var CLICK_EVENTS = {};
var DOC = A.config.doc;
Liferay.provide(
Liferay,
'delegateClick',
function(id, fn) {
var el = DOC.getElementById(id);
if (!el || el.id != id) {
return;
}
var guid = A.one(el).addClass('lfr-delegate-click').guid();
CLICK_EVENTS[guid] = fn;
if (!Liferay._baseDelegateHandle) {
Liferay._baseDelegateHandle = A.getBody().delegate('click', Liferay._baseDelegate, '.lfr-delegate-click');
}
},
['aui-base']
);
Liferay._baseDelegate = function(event) {
var id = event.currentTarget.attr('id');
var fn = CLICK_EVENTS[id];
if (fn) {
fn.apply(this, arguments);
}
};
Liferay._CLICK_EVENTS = CLICK_EVENTS;
A.use(
'attribute',
'oop',
function(A) {
A.augment(Liferay, A.Attribute, true);
}
);
})(AUI(), Liferay);
;(function(A, Liferay) {
var Language = {};
Language.get = function(key) {
return key;
};
A.use(
'io-base',
function(A) {
Language.get = A.cached(
function(key, extraParams) {
var instance = this;
var url = themeDisplay.getPathContext() + '/language/' + themeDisplay.getLanguageId() + '/' + key + '/';
if (extraParams) {
if (typeof extraParams == 'string') {
url += extraParams;
}
else if (Liferay.Util.isArray(extraParams)) {
url += extraParams.join('/');
}
}
var headers = {
"X-CSRF-Token": Liferay.authToken
};
A.io(
url,
{
headers: headers,
method: 'GET',
on: {
complete: function(i, o) {
value = o.responseText;
}
},
sync: true
}
);
return value;
}
);
}
);
Liferay.Language = Language;
})(AUI(), Liferay);
Liferay = window.Liferay || {};
(function(A, Liferay) {
var Lang = A.Lang;
var owns = A.Object.owns;
var isNode = function(node) {
return node && (node._node || node.nodeType);
};
var REGEX_METHOD_GET = /^get$/i;
Liferay.namespace = A.namespace;
A.mix(
A.namespace('config.io'),
{
method: 'POST',
uriFormatter: function(value) {
return Liferay.Util.getURLWithSessionId(value);
}
},
true
);
/**
* OPTIONS
*
* Required
* service {string|object}: Either the service name, or an object with the keys as the service to call, and the value as the service configuration object.
*
* Optional
* data {object|node|string}: The data to send to the service. If the object passed is the ID of a form or a form element, the form fields will be serialized and used as the data.
* successCallback {function}: A function to execute when the server returns a response. It receives a JSON object as it's first parameter.
* exceptionCallback {function}: A function to execute when the response from the server contains a service exception. It receives a the exception message as it's first parameter.
*/
var Service = function() {
var instance = this;
var args = Service.parseInvokeArgs(arguments);
Service.invoke.apply(Service, args);
};
A.mix(
Service,
{
URL_INVOKE: themeDisplay.getPathContext() + '/api/jsonws/invoke',
bind: function() {
var instance = this;
var args = A.Array(arguments, 0, true);
args.unshift(Liferay.Service, Liferay);
return A.bind.apply(A, args);
},
parseInvokeArgs: function(args) {
var instance = this;
var payload = args[0];
var ioConfig = instance.parseIOConfig(args);
if (Lang.isString(payload)) {
payload = instance.parseStringPayload(args);
instance.parseIOFormConfig(ioConfig, args);
var lastArg = args[args.length - 1];
if (Lang.isObject(lastArg) && lastArg.method) {
ioConfig.method = lastArg.method;
}
}
return [payload, ioConfig];
},
parseIOConfig: function(args) {
var instance = this;
var payload = args[0];
var ioConfig = payload.io || {};
var form = args[1] || {};
delete payload.io;
if (!(ioConfig.on && (ioConfig.on.success || ioConfig.on.complete || ioConfig.on.failure))) {
var callbacks = A.Array.filter(args, Lang.isFunction);
var callbackSuccess = callbacks[0];
var callbackException = callbacks[1];
if (!callbackException) {
callbackException = callbackSuccess;
}
A.namespace.call(ioConfig, 'on');
if (form.enctype == 'multipart/form-data') {
ioConfig.on.complete = function(event) {
var responseText = event.details[1].responseText;
var responseData = JSON.parse(responseText);
if ((responseData !== null) && !owns(responseData, 'exception')) {
if (callbackSuccess) {
callbackSuccess.call(this, responseData);
}
}
else if (callbackException) {
var exception = responseData ? responseData.exception : 'The server returned an empty response';
callbackException.call(this, exception, responseData);
}
};
}
ioConfig.on.failure = function(event) {
var responseText = event.details[1].responseText;
var responseData = JSON.parse(responseText);
var exception = responseData ? responseData.exception : 'The server returned an empty response';
callbackException.call(this, exception, responseData);
};
ioConfig.on.success = function(event) {
var responseData = this.get('responseData');
if ((responseData !== null) && !owns(responseData, 'exception')) {
if (callbackSuccess) {
callbackSuccess.call(this, responseData);
}
}
};
}
if (!owns(ioConfig, 'cache') && REGEX_METHOD_GET.test(ioConfig.method)) {
ioConfig.cache = false;
}
if (Liferay.PropsValues.NTLM_AUTH_ENABLED && Liferay.Browser.isIe()) {
ioConfig.method = 'GET';
}
return ioConfig;
},
parseIOFormConfig: function(ioConfig, args) {
var instance = this;
var form = args[1];
if (isNode(form)) {
A.namespace.call(ioConfig, 'form');
ioConfig.form.id = form._node || form;
if (ioConfig.form.id.enctype == 'multipart/form-data') {
ioConfig.form.upload = true;
}
}
},
parseStringPayload: function(args) {
var instance = this;
var params = {};
var payload = {};
var config = args[1];
if (!Lang.isFunction(config) && !isNode(config)) {
params = config;
}
payload[args[0]] = params;
return payload;
}
},
true
);
Liferay.provide(
Service,
'invoke',
function(payload, ioConfig) {
var instance = this;
A.io.request(
instance.URL_INVOKE,
A.merge(
{
data: {
cmd: A.JSON.stringify(payload),
p_auth: Liferay.authToken
},
dataType: 'json'
},
ioConfig
)
);
},
['aui-io-request']
);
A.each(
['get', 'delete', 'post', 'put', 'update'],
function(item, index, collection) {
var methodName = item;
if (item === 'delete') {
methodName = 'del';
}
Service[methodName] = A.rbind(
'Service',
Liferay,
{
method: item
}
);
}
);
Liferay.Service = Service;
var components = {};
var componentsFn = {};
Liferay.component = function(id, value) {
var retVal;
if (arguments.length === 1) {
var component = components[id];
if (component && Lang.isFunction(component)) {
componentsFn[id] = component;
component = component();
components[id] = component;
}
retVal = component;
}
else {
retVal = (components[id] = value);
}
return retVal;
};
Liferay._components = components;
Liferay._componentsFn = components;
Liferay.Template = {
PORTLET: ''
};
})(AUI(), Liferay);
;(function(A, Liferay) {
A.use('aui-base-lang');
var Lang = A.Lang;
var AArray = A.Array;
var AObject = A.Object;
var AString = A.Lang.String;
var Browser = Liferay.Browser;
var isArray = Lang.isArray;
var arrayIndexOf = AArray.indexOf;
var prefix = AString.prefix;
var startsWith = AString.startsWith;
var EVENT_CLICK = 'click';
var htmlEscapedValues = [];
var htmlUnescapedValues = [];
var MAP_HTML_CHARS_ESCAPED = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
'\'': ''',
'/': '/',
'`': '`'
};
var MAP_HTML_CHARS_UNESCAPED = {};
AObject.each(
MAP_HTML_CHARS_ESCAPED,
function(item, index) {
MAP_HTML_CHARS_UNESCAPED[item] = index;
htmlEscapedValues.push(item);
htmlUnescapedValues.push(index);
}
);
var REGEX_DASH = /-([a-z])/gi;
var STR_LEFT_SQUARE_BRACKET = '[';
var STR_RIGHT_SQUARE_BRACKET = ']';
var REGEX_HTML_ESCAPE = new RegExp(STR_LEFT_SQUARE_BRACKET + htmlUnescapedValues.join('') + STR_RIGHT_SQUARE_BRACKET, 'g');
var REGEX_HTML_UNESCAPE = new RegExp(htmlEscapedValues.join('|'), 'gi');
var SRC_HIDE_LINK = {
src: 'hideLink'
};
var STR_CHECKED = 'checked';
var Window = {
_map: {}
};
var Util = {
submitCountdown: 0,
actsAsAspect: function(object) {
object.yield = null;
object.rv = {};
object.before = function(method, f) {
var original = eval('this.' + method);
this[method] = function() {
f.apply(this, arguments);
return original.apply(this, arguments);
};
};
object.after = function(method, f) {
var original = eval('this.' + method);
this[method] = function() {
this.rv[method] = original.apply(this, arguments);
return f.apply(this, arguments);
};
};
object.around = function(method, f) {
var original = eval('this.' + method);
this[method] = function() {
this.yield = original;
return f.apply(this, arguments);
};
};
},
addInputCancel: function() {
A.use(
'aui-button-search-cancel',
function(A) {
new A.ButtonSearchCancel(
{
trigger: 'input[type=password], input[type=search], input.clearable, input.search-query',
zIndex: Liferay.zIndex.WINDOW + 100
}
);
}
);
Util.addInputCancel = function(){};
},
addInputFocus: function() {
A.use(
'aui-base',
function(A) {
var handleFocus = function(event) {
var target = event.target;
var tagName = target.get('tagName');
if (tagName) {
tagName = tagName.toLowerCase();
}
var nodeType = target.get('type');
if (((tagName == 'input') && (/text|password/).test(nodeType)) ||
(tagName == 'textarea')) {
var action = 'addClass';
if (/blur|focusout/.test(event.type)) {
action = 'removeClass';
}
target[action]('focus');
}
};
A.on('focus', handleFocus, document);
A.on('blur', handleFocus, document);
}
);
Util.addInputFocus = function(){};
},
addInputType: function(el) {
Util.addInputType = Lang.emptyFn;
if (Browser.isIe() && Browser.getMajorVersion() < 7) {
Util.addInputType = function(el) {
var item;
if (el) {
el = A.one(el);
}
else {
el = A.one(document.body);
}
var defaultType = 'text';
el.all('input').each(
function(item, index, collection) {
var type = item.get('type') || defaultType;
item.addClass(type);
}
);
};
}
return Util.addInputType(el);
},
addParams: function(params, url) {
A.use('querystring-stringify-simple');
if (Lang.isObject(params)) {
params = A.QueryString.stringify(params);
}
else {
params = Lang.trim(params);
}
if (params) {
var loc = url || location.href;
var anchorHash;
var finalUrl;
if (loc.indexOf('#') > -1) {
var locationPieces = loc.split('#');
loc = locationPieces[0];
anchorHash = locationPieces[1];
}
if (loc.indexOf('?') == -1) {
params = '?' + params;
}
else {
params = '&' + params;
}
if (loc.indexOf(params) == -1) {
finalUrl = loc + params;
if (anchorHash) {
finalUrl += '#' + anchorHash;
}
if (!url) {
location.href = finalUrl;
}
return finalUrl;
}
}
},
camelize: function(value, separator) {
var regex = REGEX_DASH;
if (separator) {
regex = new RegExp(separator + '([a-z])', 'gi');
}
value = value.replace(
regex,
function(match0, match1) {
return match1.toUpperCase();
}
);
return value;
},
checkTab: function(box) {
if ((document.all) && (event.keyCode == 9)) {
box.selection = document.selection.createRange();
setTimeout(
function() {
Util.processTab(box.id);
},
0
);
}
},
clamp: function(value, min, max) {
return Math.min(Math.max(value, min), max);
},
disableEsc: function() {
if ((document.all) && (event.keyCode == 27)) {
event.returnValue = false;
}
},
disableFormButtons: function(inputs, form) {
inputs.set('disabled', true);
inputs.setStyle('opacity', 0.5);
if (A.UA.gecko) {
A.getWin().on(
'unload',
function(event) {
inputs.set('disabled', false);
}
);
}
else if (A.UA.safari) {
A.use(
'node-event-html5',
function(A) {
A.getWin().on(
'pagehide',
function(event) {
Util.enableFormButtons(inputs, form);
}
);
}
);
}
},
enableFormButtons: function(inputs, form) {
Util._submitLocked = null;
document.body.style.cursor = 'auto';
inputs.set('disabled', false);
inputs.setStyle('opacity', 1);
},
endsWith: function(str, x) {
return (str.lastIndexOf(x) === (str.length - x.length));
},
escapeCDATA: function(str) {
return str.replace(
//gi,
function(match) {
var str = '';
if (match == ']]>') {
str = ']]>';
}
else if (match == ' 0) ? window.innerWidth : screen.width;
},
getURLWithSessionId: function(url) {
if (!themeDisplay.isAddSessionIdToURL()) {
return url;
}
// LEP-4787
var x = url.indexOf(';');
if (x > -1) {
return url;
}
var sessionId = ';jsessionid=' + themeDisplay.getSessionId();
x = url.indexOf('?');
if (x > -1) {
return url.substring(0, x) + sessionId + url.substring(x);
}
// In IE6, http://www.abc.com;jsessionid=XYZ does not work, but
// http://www.abc.com/;jsessionid=XYZ does work.
x = url.indexOf('//');
if (x > -1) {
var y = url.lastIndexOf('/');
if (x + 1 == y) {
return url + '/' + sessionId;
}
}
return url + sessionId;
},
isArray: function(object) {
return !!(window.Array && object.constructor == window.Array);
},
isEditorPresent: function(editorImpl) {
return Liferay.EDITORS && Liferay.EDITORS[editorImpl];
},
isPhone: function() {
var instance = this;
return (instance.getWindowWidth() < Liferay.BREAKPOINTS.PHONE);
},
isTablet: function() {
var instance = this;
return (instance.getWindowWidth() < Liferay.BREAKPOINTS.TABLET);
},
ns: function(namespace, obj) {
var instance = this;
var value;
var ns = instance._ns;
if (!Lang.isObject(obj)) {
value = ns(namespace, obj);
}
else {
value = {};
A.Object.each(
obj,
function(item, index, collection) {
index = ns(namespace, index);
value[index] = item;
}
);
}
return value;
},
openInDialog: function(event) {
event.preventDefault();
var currentTarget = event.currentTarget;
var config = currentTarget.getData();
if (!config.uri) {
config.uri = currentTarget.getData('href') || currentTarget.attr('href');
}
if (!config.title) {
config.title = currentTarget.attr('title');
}
Liferay.Util.openWindow(config);
},
openWindow: function(config, callback) {
config.openingWindow = window;
var top = Util.getTop();
var topUtil = top.Liferay.Util;
topUtil._openWindowProvider(config, callback);
},
processTab: function(id) {
document.all[id].selection.text = String.fromCharCode(9);
document.all[id].focus();
},
randomInt: function() {
return (Math.ceil(Math.random() * (new Date()).getTime()));
},
randomMinMax: function(min, max) {
return (Math.round(Math.random() * (max - min))) + min;
},
selectAndCopy: function(el) {
el.focus();
el.select();
if (document.all) {
var textRange = el.createTextRange();
textRange.execCommand('copy');
}
},
setBox: function(oldBox, newBox) {
for (var i = oldBox.length - 1; i > -1; i--) {
oldBox.options[i] = null;
}
for (i = 0; i < newBox.length; i++) {
oldBox.options[i] = new Option(newBox[i].value, i);
}
oldBox.options[0].selected = true;
},
setCursorPosition: function(el, position) {
var instance = this;
instance.setSelectionRange(el, position, position);
},
setSelectionRange: function(el, selectionStart, selectionEnd) {
var instance = this;
if (Lang.isFunction(el.getDOM)) {
el = el.getDOM();
}
if (el.setSelectionRange) {
el.focus();
el.setSelectionRange(selectionStart, selectionEnd);
}
else if (el.createTextRange) {
var textRange = el.createTextRange();
textRange.collapse(true);
textRange.moveEnd('character', selectionEnd);
textRange.moveEnd('character', selectionStart);
textRange.select();
}
},
showCapsLock: function(event, span) {
var keyCode = event.keyCode ? event.keyCode : event.which;
var shiftKeyCode = ((keyCode == 16) ? true : false);
var shiftKey = event.shiftKey ? event.shiftKey : shiftKeyCode;
if (((keyCode >= 65 && keyCode <= 90) && !shiftKey) ||
((keyCode >= 97 && keyCode <= 122) && shiftKey)) {
document.getElementById(span).style.display = '';
}
else {
document.getElementById(span).style.display = 'none';
}
},
sortByAscending: function(a, b) {
a = a[1].toLowerCase();
b = b[1].toLowerCase();
if (a > b) {
return 1;
}
if (a < b) {
return -1;
}
return 0;
},
startsWith: function(str, x) {
return (str.indexOf(x) === 0);
},
textareaTabs: function(event) {
var el = event.currentTarget.getDOM();
var pressedKey = event.keyCode;
if (event.isKey('TAB')) {
event.halt();
var oldscroll = el.scrollTop;
if (el.setSelectionRange) {
var caretPos = el.selectionStart + 1;
var elValue = el.value;
el.value = elValue.substring(0, el.selectionStart) + '\t' + elValue.substring(el.selectionEnd, elValue.length);
setTimeout(
function() {
el.focus();
el.setSelectionRange(caretPos, caretPos);
}, 0);
}
else {
document.selection.createRange().text = '\t';
}
el.scrollTop = oldscroll;
return false;
}
},
toCharCode: A.cached(
function(name) {
var buffer = [];
for (var i = 0; i < name.length; i++) {
buffer[i] = name.charCodeAt(i);
}
return buffer.join('');
}
),
toNumber: function(value) {
return parseInt(value, 10) || 0;
},
uncamelize: function(value, separator) {
separator = separator || ' ';
value = value.replace(/([a-zA-Z][a-zA-Z])([A-Z])([a-z])/g, '$1' + separator + '$2$3');
value = value.replace(/([a-z])([A-Z])/g, '$1' + separator + '$2');
return value;
},
unescapeHTML: function(str, entities) {
var regex = REGEX_HTML_UNESCAPE;
var entitiesMap = MAP_HTML_CHARS_UNESCAPED;
if (entities) {
var entitiesValues = [];
entitiesMap = {};
AObject.each(
entities,
function(item, index) {
entitiesMap[item] = index;
entitiesValues.push(item);
}
);
regex = new RegExp(entitiesValues.join('|'), 'gi');
}
return str.replace(regex, A.bind('_unescapeHTML', Util, entitiesMap));
},
_defaultPreviewArticleFn: function(event) {
var instance = this;
event.preventDefault();
Liferay.Util.openWindow(
{
cache: false,
title: Liferay.Util.escapeHTML(event.title),
uri: event.uri
}
);
},
_defaultSubmitFormFn: function(event) {
var form = event.form;
var hasErrors = false;
if (event.validate) {
var liferayForm = Liferay.Form.get(form.attr('id'));
if (liferayForm) {
var validator = liferayForm.formValidator;
if (A.instanceOf(validator, A.FormValidator)) {
validator.validate();
hasErrors = validator.hasErrors();
if (hasErrors) {
validator.focusInvalidField();
}
}
}
}
if (!hasErrors) {
var action = event.action || form.attr('action');
var singleSubmit = event.singleSubmit;
var inputs = form.all('input[type=button], input[type=image], input[type=reset], input[type=submit]');
Util.disableFormButtons(inputs, form);
if (singleSubmit === false) {
Util._submitLocked = A.later(
1000,
Util,
Util.enableFormButtons,
[inputs, form]
);
}
else {
Util._submitLocked = true;
}
var actionURL = new A.Url(action);
var authToken = actionURL.getParameter('p_auth');
if (authToken) {
form.append(' ');
actionURL.removeParameter('p_auth');
action = actionURL.toString();
}
form.attr('action', action);
form.submit();
form.attr('target', '');
}
},
_escapeHTML: function(preventDoubleEscape, entities, entitiesValues, match) {
var result;
if (preventDoubleEscape) {
var arrayArgs = AArray(arguments);
var length = arrayArgs.length;
var string = arrayArgs[length - 1];
var offset = arrayArgs[length - 2];
var nextSemicolonIndex = string.indexOf(';', offset);
if (nextSemicolonIndex >= 0) {
var entity = string.substring(offset, nextSemicolonIndex + 1);
if (AArray.indexOf(entitiesValues, entity) >= 0) {
result = match;
}
}
}
if (!result) {
result = entities[match];
}
return result;
},
_getEditableInstance: function(title) {
var editable = Util._EDITABLE;
if (!editable) {
editable = new A.Editable(
{
after: {
contentTextChange: function(event) {
var instance = this;
if (!event.initial) {
var title = instance.get('node');
var portletTitleEditOptions = title.getData('portletTitleEditOptions');
Util.savePortletTitle(
{
doAsUserId: portletTitleEditOptions.doAsUserId,
plid: portletTitleEditOptions.plid,
portletId: portletTitleEditOptions.portletId,
title: event.newVal
}
);
}
},
startEditing: function(event) {
var instance = this;
var Layout = Liferay.Layout;
if (Layout) {
instance._dragListener = Layout.getLayoutHandler().on(
'drag:start',
function(event) {
instance.fire('save');
}
);
}
},
stopEditing: function(event) {
var instance = this;
if (instance._dragListener) {
instance._dragListener.detach();
}
}
},
cssClass: 'lfr-portlet-title-editable',
node: title
}
);
Util._EDITABLE = editable;
}
return editable;
},
_ns: A.cached(
function(namespace, str) {
var value = str;
if (!Lang.isUndefined(str) && !startsWith(str, namespace)) {
value = prefix(namespace, str);
}
return value;
}
),
_unescapeHTML: function(entities, match) {
return entities[match];
},
MAP_HTML_CHARS_ESCAPED: MAP_HTML_CHARS_ESCAPED
};
Liferay.provide(
Util,
'afterIframeLoaded',
function(event) {
var nodeInstances = A.Node._instances;
var docEl = event.doc;
var docUID = docEl._yuid;
if (docUID in nodeInstances) {
delete nodeInstances[docUID];
}
var iframeDocument = A.one(docEl);
var iframeBody = iframeDocument.one('body');
var dialog = event.dialog;
iframeBody.addClass('dialog-iframe-popup');
event.win.focus();
var detachEventHandles = function() {
AArray.invoke(eventHandles, 'detach');
iframeDocument.purge(true);
};
var eventHandles = [
iframeBody.delegate('submit', detachEventHandles, 'form'),
iframeBody.delegate(
EVENT_CLICK,
function() {
dialog.set('visible', false, SRC_HIDE_LINK);
detachEventHandles();
},
'.lfr-hide-dialog'
)
];
var cancelButton = iframeBody.one('.btn-cancel');
if (cancelButton) {
cancelButton.after(
EVENT_CLICK,
function() {
detachEventHandles();
dialog.hide();
}
);
}
var rolesSearchContainer = iframeBody.one('#rolesSearchContainerSearchContainer');
if (rolesSearchContainer) {
eventHandles.push(
rolesSearchContainer.delegate(
EVENT_CLICK,
function(event) {
event.preventDefault();
detachEventHandles();
submitForm(document.hrefFm, event.currentTarget.attr('href'));
},
'a'
)
);
}
},
['aui-base']
);
Liferay.provide(
Util,
'check',
function(form, name, checked) {
var checkbox = A.one(form[name]);
if (checkbox) {
checkbox.set(STR_CHECKED, checked);
}
},
['aui-base']
);
Liferay.provide(
Util,
'checkAll',
function(form, name, allBox, selectClassName) {
var selector;
if (isArray(name)) {
selector = 'input[name=' + name.join('], input[name=') + STR_RIGHT_SQUARE_BRACKET;
}
else {
selector = 'input[name=' + name + STR_RIGHT_SQUARE_BRACKET;
}
form = A.one(form);
form.all(selector).set(STR_CHECKED, A.one(allBox).get(STR_CHECKED));
if (selectClassName) {
form.all(selectClassName).toggleClass('info', A.one(allBox).get(STR_CHECKED));
}
},
['aui-base']
);
Liferay.provide(
Util,
'checkAllBox',
function(form, name, allBox) {
var totalBoxes = 0;
var totalOn = 0;
var inputs = A.one(form).all('input[type=checkbox]');
allBox = A.one(allBox) || A.one(form).one('input[name=' + allBox + STR_RIGHT_SQUARE_BRACKET);
if (!isArray(name)) {
name = [name];
}
inputs.each(
function(item, index, collection) {
if (!item.compareTo(allBox) && (arrayIndexOf(name, item.attr('name')) > -1)) {
totalBoxes++;
if (item.get(STR_CHECKED)) {
totalOn++;
}
}
}
);
allBox.set(STR_CHECKED, (totalBoxes == totalOn));
},
['aui-base']
);
Liferay.provide(
Util,
'createFlyouts',
function(options) {
options = options || {};
var flyout = A.one(options.container);
var containers = [];
if (flyout) {
var lis = flyout.all('li');
lis.each(
function(item, index, collection) {
var childUL = item.one('ul');
if (childUL) {
childUL.hide();
item.addClass('lfr-flyout');
item.addClass('has-children lfr-flyout-has-children');
}
}
);
var hideTask = A.debounce(
function(event) {
showTask.cancel();
var li = event.currentTarget;
if (li.hasClass('has-children')) {
var childUL = event.currentTarget.one('> ul');
if (childUL) {
childUL.hide();
if (options.mouseOut) {
options.mouseOut.apply(event.currentTarget, [event]);
}
}
}
},
300
);
var showTask = A.debounce(
function(event) {
hideTask.cancel();
var li = event.currentTarget;
if (li.hasClass('has-children')) {
var childUL = event.currentTarget.one('> ul');
if (childUL) {
childUL.show();
if (options.mouseOver) {
options.mouseOver.apply(event.currentTarget, [event]);
}
}
}
},
0
);
lis.on('mouseenter', showTask, 'li');
lis.on('mouseleave', hideTask, 'li');
}
},
['aui-base']
);
Liferay.provide(
Util,
'disableElements',
function(obj) {
var el = A.one(obj);
if (el) {
el = el.getDOM();
var children = el.getElementsByTagName('*');
var emptyFnFalse = Lang.emptyFnFalse;
var Event = A.Event;
for (var i = children.length - 1; i >= 0; i--) {
var item = children[i];
item.style.cursor = 'default';
el.onclick = emptyFnFalse;
el.onmouseover = emptyFnFalse;
el.onmouseout = emptyFnFalse;
el.onmouseenter = emptyFnFalse;
el.onmouseleave = emptyFnFalse;
Event.purgeElement(el, false);
item.action = '';
item.disabled = true;
item.href = 'javascript:;';
item.onsubmit = emptyFnFalse;
}
}
},
['aui-base']
);
Liferay.provide(
Util,
'disableSelectBoxes',
function(toggleBoxId, value, selectBoxId) {
var selectBox = A.one('#' + selectBoxId);
var toggleBox = A.one('#' + toggleBoxId);
if (selectBox && toggleBox) {
var dynamicValue = Lang.isFunction(value);
var disabled = function() {
var currentValue = selectBox.val();
var visible = (value == currentValue);
if (dynamicValue) {
visible = value(currentValue, value);
}
toggleBox.set('disabled', !visible);
};
disabled();
selectBox.on('change', disabled);
}
},
['aui-base']
);
Liferay.provide(
Util,
'disableTextareaTabs',
function(textarea) {
textarea = A.one(textarea);
if (textarea && textarea.attr('textareatabs') != 'enabled') {
textarea.attr('textareatabs', 'disabled');
textarea.detach('keydown', Util.textareaTabs);
}
},
['aui-base']
);
Liferay.provide(
Util,
'disableToggleBoxes',
function(checkBoxId, toggleBoxId, checkDisabled) {
var checkBox = A.one('#' + checkBoxId);
var toggleBox = A.one('#' + toggleBoxId);
if (checkBox && toggleBox) {
if (checkBox.get(STR_CHECKED) && checkDisabled) {
toggleBox.set('disabled', true);
}
else {
toggleBox.set('disabled', false);
}
checkBox.on(
EVENT_CLICK,
function() {
toggleBox.set('disabled', !toggleBox.get('disabled'));
}
);
}
},
['aui-base']
);
Liferay.provide(
Util,
'enableTextareaTabs',
function(textarea) {
textarea = A.one(textarea);
if (textarea && textarea.attr('textareatabs') != 'enabled') {
textarea.attr('textareatabs', 'disabled');
textarea.on('keydown', Util.textareaTabs);
}
},
['aui-base']
);
Liferay.provide(
Util,
'focusFormField',
function(el, caretPosition) {
Util.addInputFocus();
var interacting = false;
var clickHandle = A.getDoc().on(
EVENT_CLICK,
function(event) {
interacting = true;
clickHandle.detach();
}
);
if (!interacting) {
var focusable;
var form;
el = A.one(el);
if (el) {
form = el.ancestor('form', true);
if (form) {
form = form.getDOM();
}
el = el.getDOM();
focusable = !el.disabled && !el.hidden;
}
try {
if ((!form || !form.length) && focusable) {
el.focus();
}
else {
Liferay.once(
form.id + 'formReady',
function() {
el.focus();
}
);
}
}
catch (e) {
}
}
},
['aui-base']
);
Liferay.provide(
Util,
'forcePost',
function(link) {
link = A.one(link);
if (link) {
var url = link.attr('href');
var newWindow = (link.attr('target') == '_blank');
if (newWindow) {
A.one(document.hrefFm).attr('target', '_blank');
}
submitForm(document.hrefFm, url, !newWindow);
Util._submitLocked = null;
}
},
['aui-base']
);
Liferay.provide(
Util,
'moveItem',
function(fromBox, toBox, sort) {
fromBox = A.one(fromBox);
toBox = A.one(toBox);
var selectedIndex = fromBox.get('selectedIndex');
var selectedOption;
if (selectedIndex >= 0) {
var options = fromBox.all('option');
selectedOption = options.item(selectedIndex);
options.each(
function(item, index, collection) {
if (item.get('selected')) {
toBox.append(item);
}
}
);
}
if (selectedOption && selectedOption.text() != '' && sort == true) {
Util.sortBox(toBox);
}
},
['aui-base']
);
Liferay.provide(
Util,
'openDDMPortlet',
function(config, callback) {
var instance = this;
var defaultValues = {
eventName: 'selectStructure'
};
config = A.merge(defaultValues, config);
var ddmURL;
if (config.basePortletURL) {
ddmURL = Liferay.PortletURL.createURL(config.basePortletURL);
}
else {
ddmURL = Liferay.PortletURL.createRenderURL();
}
ddmURL.setEscapeXML(false);
ddmURL.setDoAsGroupId(config.doAsGroupId || themeDisplay.getScopeGroupId());
ddmURL.setParameter('classNameId', config.classNameId);
ddmURL.setParameter('classPK', config.classPK);
ddmURL.setParameter('eventName', config.eventName);
ddmURL.setParameter('groupId', config.groupId);
ddmURL.setParameter('mode', config.mode);
ddmURL.setParameter('portletResourceNamespace', config.portletResourceNamespace);
if ('redirect' in config) {
ddmURL.setParameter('redirect', config.redirect);
}
if ('refererPortletName' in config) {
ddmURL.setParameter('refererPortletName', config.refererPortletName);
}
if ('refererWebDAVToken' in config) {
ddmURL.setParameter('refererWebDAVToken', config.refererWebDAVToken);
}
ddmURL.setParameter('scopeTitle', config.title);
if ('showBackURL' in config) {
ddmURL.setParameter('showBackURL', config.showBackURL);
}
if ('showGlobalScope' in config) {
ddmURL.setParameter('showGlobalScope', config.showGlobalScope);
}
if ('showHeader' in config) {
ddmURL.setParameter('showHeader', config.showHeader);
}
if ('showManageTemplates' in config) {
ddmURL.setParameter('showManageTemplates', config.showManageTemplates);
}
if ('showToolbar' in config) {
ddmURL.setParameter('showToolbar', config.showToolbar);
}
ddmURL.setParameter('structureAvailableFields', config.structureAvailableFields);
if (config.struts_action) {
ddmURL.setParameter('struts_action', config.struts_action);
}
else {
ddmURL.setParameter('struts_action', '/dynamic_data_mapping/view');
}
ddmURL.setParameter('templateId', config.templateId);
ddmURL.setPortletId(166);
ddmURL.setWindowState('pop_up');
config.uri = ddmURL.toString();
var dialogConfig = config.dialog;
if (!dialogConfig) {
dialogConfig = {};
config.dialog = dialogConfig;
}
var eventHandles = [Liferay.once(config.eventName, callback)];
var detachSelectionOnHideFn = function(event) {
if (!event.newVal) {
(new A.EventHandle(eventHandles)).detach();
}
};
Util.openWindow(
config,
function(dialogWindow) {
eventHandles.push(dialogWindow.after(['destroy', 'visibleChange'], detachSelectionOnHideFn));
}
);
},
['liferay-portlet-url']
);
Liferay.provide(
Util,
'openDocument',
function(webDavUrl, onSuccess, onError) {
if (A.UA.ie) {
try {
var executor = new A.config.win.ActiveXObject('SharePoint.OpenDocuments');
executor.EditDocument(webDavUrl);
if (Lang.isFunction(onSuccess)) {
onSuccess();
}
}
catch (exception) {
if (Lang.isFunction(onError)) {
onError(exception);
}
}
}
},
['aui-base']
);
Liferay.provide(
Util,
'portletTitleEdit',
function(options) {
var obj = options.obj;
if (obj && !obj.hasClass('portlet-borderless')) {
var title = obj.one('.portlet-title-text');
if (title && !title.hasClass('not-editable')) {
title.addClass('portlet-title-editable');
title.on(
EVENT_CLICK,
function(event) {
var editable = Util._getEditableInstance(title);
var rendered = editable.get('rendered');
if (rendered) {
editable.fire('stopEditing');
}
editable.set('node', event.currentTarget);
if (rendered) {
editable.syncUI();
}
editable._startEditing(event);
}
);
title.setData('portletTitleEditOptions', options);
}
}
},
['aui-editable-deprecated']
);
Liferay.provide(
Util,
'removeEntitySelection',
function(entityIdString, entityNameString, removeEntityButton, namespace) {
A.byIdNS(namespace, entityIdString).val(0);
A.byIdNS(namespace, entityNameString).val('');
Liferay.Util.toggleDisabled(removeEntityButton, true);
Liferay.fire('entitySelectionRemoved');
},
['aui-base', 'liferay-node']
);
Liferay.provide(
Util,
'removeItem',
function(box, value) {
box = A.one(box);
var selectedIndex = box.get('selectedIndex');
if (!value) {
box.all('option').item(selectedIndex).remove(true);
}
else {
box.all('option[value=' + value + STR_RIGHT_SQUARE_BRACKET).item(selectedIndex).remove(true);
}
},
['aui-base']
);
Liferay.provide(
Util,
'reorder',
function(box, down) {
box = A.one(box);
var selectedIndex = box.get('selectedIndex');
if (selectedIndex == -1) {
box.set('selectedIndex', 0);
}
else {
var selectedItems = box.all(':selected');
var lastIndex = box.get('options').size() - 1;
var length = selectedItems.size();
if (down) {
while (length--) {
var item = selectedItems.item(length);
var itemIndex = item.get('index');
var referenceNode = box.get('firstChild');
if (itemIndex != lastIndex) {
var nextSibling = item.next();
if (nextSibling) {
referenceNode = nextSibling.next();
}
}
box.insertBefore(item, referenceNode);
}
}
else {
for (var i = 0; i < length; i++) {
var item = selectedItems.item(i);
var itemIndex = item.get('index');
if (itemIndex == 0) {
box.append(item);
}
else {
box.insertBefore(item, item.previous());
}
}
}
}
},
['aui-base']
);
Liferay.provide(
Util,
'resizeTextarea',
function(elString, usingRichEditor) {
var el = A.one('#' + elString);
if (!el) {
el = A.one('textarea[name=' + elString + STR_RIGHT_SQUARE_BRACKET);
}
if (el) {
var pageBody = A.getBody();
var diff;
var resize = function(event) {
var pageBodyHeight = pageBody.get('winHeight');
if (usingRichEditor) {
try {
if (el.get('nodeName').toLowerCase() != 'iframe') {
el = window[elString];
}
}
catch (e) {
}
}
if (!diff) {
var buttonRow = pageBody.one('.button-holder');
var templateEditor = pageBody.one('.lfr-template-editor');
if (buttonRow && templateEditor) {
var region = templateEditor.getXY();
diff = (buttonRow.outerHeight(true) + region[1]) + 25;
}
else {
diff = 170;
}
}
el = A.one(el);
var styles = {
width: '98%'
};
if (event) {
styles.height = (pageBodyHeight - diff);
}
if (usingRichEditor) {
if (!el || !A.DOM.inDoc(el)) {
A.on(
'available',
function(event) {
el = A.one(window[elString]);
if (el) {
el.setStyles(styles);
}
},
'#' + elString + '_cp'
);
return;
}
}
if (el) {
el.setStyles(styles);
}
};
resize();
var dialog = Liferay.Util.getWindow();
if (dialog) {
var resizeEventHandle = dialog.iframe.after('resizeiframe:heightChange', resize);
A.getWin().on('unload', resizeEventHandle.detach, resizeEventHandle);
}
}
},
['aui-base']
);
Liferay.provide(
Util,
'savePortletTitle',
function(params) {
A.mix(
params,
{
doAsUserId: 0,
plid: 0,
portletId: 0,
title: '',
url: themeDisplay.getPathMain() + '/portlet_configuration/update_title'
}
);
A.io.request(
params.url,
{
data: {
doAsUserId: params.doAsUserId,
p_auth: Liferay.authToken,
p_l_id: params.plid,
portletId: params.portletId,
title: params.title
}
}
);
},
['aui-io']
);
Liferay.provide(
Util,
'selectEntity',
function(config, callback) {
var dialog = Util.getWindow(config.id);
var eventName = config.eventName || config.id;
var eventHandles = [Liferay.on(eventName, callback)];
var selectedData = config.selectedData;
if (selectedData) {
config.dialog.destroyOnHide = true;
}
var detachSelectionOnHideFn = function(event) {
if (!event.newVal) {
(new A.EventHandle(eventHandles)).detach();
}
};
var disableSelectedAssets = function(event) {
if (selectedData && selectedData.length) {
var currentWindow = event.currentTarget.node.get('contentWindow.document');
var selectorButtons = currentWindow.all('.lfr-search-container .selector-button');
A.some(
selectorButtons,
function(item, index) {
var assetEntryId = item.attr('data-entityid') || item.attr('data-entityname');
var assetEntryIndex = A.Array.indexOf(selectedData, assetEntryId);
if (assetEntryIndex > -1) {
item.attr('data-prevent-selection', true);
item.attr('disabled', true);
selectedData.splice(assetEntryIndex, 1);
}
return !selectedData.length;
}
);
}
};
if (dialog) {
eventHandles.push(dialog.after(['destroy', 'visibleChange'], detachSelectionOnHideFn));
dialog.show();
}
else {
Util.openWindow(
config,
function(dialogWindow) {
eventHandles.push(
dialogWindow.after(['destroy', 'visibleChange'], detachSelectionOnHideFn),
dialogWindow.iframe.after(['load'], disableSelectedAssets)
);
}
);
}
},
['aui-base', 'liferay-util-window']
);
Liferay.provide(
Util,
'selectEntityHandler',
function(container, selectEventName, disableButton) {
var containerNode = A.one(container);
var openingLiferay = Util.getOpener().Liferay;
if (containerNode) {
var selectorButtons = containerNode.all('.selector-button');
containerNode.delegate(
'click',
function(event) {
var target = event.target;
if (!target.attr('data-prevent-selection')) {
var currentTarget = event.currentTarget;
if (disableButton !== false) {
selectorButtons.attr('disabled', false);
currentTarget.attr('disabled', true);
}
var result = Util.getAttributes(currentTarget, 'data-');
Util.getOpener().Liferay.fire(selectEventName, result);
Util.getWindow().hide();
}
},
'.selector-button'
);
openingLiferay.on(
'entitySelectionRemoved',
function(event) {
selectorButtons.attr('disabled', false);
}
);
}
},
['aui-base']
);
Liferay.provide(
Util,
'selectFolder',
function(folderData, namespace) {
A.byIdNS(namespace, folderData.idString).val(folderData.idValue);
var name = AString.unescapeEntities(folderData.nameValue);
A.byIdNS(namespace, folderData.nameString).val(name);
var button = A.byIdNS(namespace, 'removeFolderButton');
if (button) {
Liferay.Util.toggleDisabled(button, false);
}
},
['aui-base', 'liferay-node']
);
Liferay.provide(
Util,
'setSelectedValue',
function(col, value) {
var option = A.one(col).one('option[value=' + value + STR_RIGHT_SQUARE_BRACKET);
if (option) {
option.set('selected', true);
}
},
['aui-base']
);
Liferay.provide(
Util,
'sortBox',
function(box) {
var newBox = [];
var options = box.all('option');
for (var i = 0; i < options.size(); i++) {
newBox[i] = [options.item(i).val(), options.item(i).text()];
}
newBox.sort(Util.sortByAscending);
var boxObj = A.one(box);
boxObj.all('option').remove(true);
A.each(
newBox,
function(item, index, collection) {
boxObj.append('' + item[1] + ' ');
}
);
if (Browser.isIe()) {
var currentWidth = boxObj.getStyle('width');
if (currentWidth == 'auto') {
boxObj.setStyle('width', 'auto');
}
}
},
['aui-base']
);
/**
* OPTIONS
*
* Required
* uri {string}: The url to open that sets the editor.
*/
Liferay.provide(
Util,
'switchEditor',
function(options) {
var uri = options.uri;
var windowName = Liferay.Util.getWindowName();
var dialog = Liferay.Util.getWindow(windowName);
if (dialog) {
dialog.iframe.set('uri', uri);
}
},
['aui-io']
);
Liferay.provide(
Util,
'toggleBoxes',
function(checkBoxId, toggleBoxId, displayWhenUnchecked, toggleChildCheckboxes) {
var checkBox = A.one('#' + checkBoxId);
var toggleBox = A.one('#' + toggleBoxId);
if (checkBox && toggleBox) {
var checked = checkBox.get(STR_CHECKED);
if (checked) {
toggleBox.show();
}
else {
toggleBox.hide();
}
if (displayWhenUnchecked) {
toggleBox.toggle();
}
checkBox.on(
EVENT_CLICK,
function() {
toggleBox.toggle();
if (toggleChildCheckboxes) {
var childCheckboxes = toggleBox.all('input[type=checkbox]');
childCheckboxes.set(STR_CHECKED, checkBox.get(STR_CHECKED));
}
}
);
}
},
['aui-base']
);
Liferay.provide(
Util,
'toggleControls',
function(node) {
var docBody = A.getBody();
node = node || docBody;
var trigger = node.one('.toggle-controls');
if (trigger) {
var hiddenClass = 'controls-hidden';
var iconHiddenClass = 'icon-eye-close';
var iconVisibleClass = 'icon-eye-open';
var visibleClass = 'controls-visible';
var currentClass = visibleClass;
var currentIconClass = iconVisibleClass;
if (Liferay._editControlsState != 'visible') {
currentClass = hiddenClass;
currentIconClass = iconHiddenClass;
}
var icon = trigger.one('.controls-state-icon');
if (icon) {
icon.addClass(currentIconClass);
}
docBody.addClass(currentClass);
Liferay.fire(
'toggleControls',
{
enabled: (Liferay._editControlsState === 'visible')
}
);
trigger.on(
EVENT_CLICK,
function(event) {
if (icon) {
icon.toggleClass(iconVisibleClass).toggleClass(iconHiddenClass);
}
docBody.toggleClass(visibleClass).toggleClass(hiddenClass);
Liferay._editControlsState = (docBody.hasClass(visibleClass) ? 'visible' : 'hidden');
Liferay.Store('liferay_toggle_controls', Liferay._editControlsState);
Liferay.fire(
'toggleControls',
{
enabled: (Liferay._editControlsState === 'visible'),
src: 'ui'
}
);
}
);
}
},
['liferay-store']
);
Liferay.provide(
Util,
'toggleDisabled',
function(button, state) {
if (!A.instanceOf(button, A.NodeList)) {
button = A.all(button);
}
button.each(
function(item, index, collection) {
item.attr('disabled', state);
item.toggleClass('disabled', state);
}
);
},
['aui-base']
);
Liferay.provide(
Util,
'toggleRadio',
function(radioId, showBoxIds, hideBoxIds) {
var radioButton = A.one('#' + radioId);
if (radioButton) {
var checked = radioButton.get(STR_CHECKED);
var showBoxes;
if (Lang.isValue(showBoxIds)) {
if (Lang.isArray(showBoxIds)) {
showBoxIds = showBoxIds.join(',#');
}
showBoxes = A.all('#' + showBoxIds);
showBoxes.toggle(checked);
}
radioButton.on(
'change',
function() {
if (showBoxes) {
showBoxes.show();
}
if (Lang.isValue(hideBoxIds)) {
if (Lang.isArray(hideBoxIds)) {
hideBoxIds = hideBoxIds.join(',#');
}
A.all('#' + hideBoxIds).hide();
}
}
);
}
},
['aui-base', 'aui-event']
);
Liferay.provide(
Util,
'toggleSelectBox',
function(selectBoxId, value, toggleBoxId) {
var selectBox = A.one('#' + selectBoxId);
var toggleBox = A.one('#' + toggleBoxId);
if (selectBox && toggleBox) {
var dynamicValue = Lang.isFunction(value);
var toggle = function() {
var currentValue = selectBox.val();
var visible = (value == currentValue);
if (dynamicValue) {
visible = value(currentValue, value);
}
toggleBox.toggle(visible);
};
toggle();
selectBox.on('change', toggle);
}
},
['aui-base']
);
Liferay.provide(
Util,
'toggleSearchContainerButton',
function(buttonId, searchContainerId, form, ignoreFieldName) {
var searchContainer = A.one(searchContainerId);
if (searchContainer) {
searchContainer.delegate(
EVENT_CLICK,
function() {
Liferay.Util.toggleDisabled(buttonId, !Liferay.Util.listCheckedExcept(form, ignoreFieldName));
},
'input[type=checkbox]'
);
}
},
['aui-base', 'liferay-util-list-fields']
);
Liferay.provide(
Util,
'updateCheckboxValue',
function(checkbox) {
checkbox = A.one(checkbox);
if (checkbox) {
var checked = checkbox.attr(STR_CHECKED);
var value = 'false';
if (checked) {
value = checkbox.val();
if (value == 'false') {
value = 'true';
}
}
checkbox.previous().val(value);
}
},
['aui-base']
);
Liferay.provide(
window,
'submitForm',
function(form, action, singleSubmit, validate) {
if (!Util._submitLocked) {
Liferay.fire(
'submitForm',
{
form: A.one(form),
action: action,
singleSubmit: singleSubmit,
validate: validate !== false
}
);
}
},
['aui-base', 'aui-form-validator', 'aui-url', 'liferay-form']
);
Liferay.publish(
'submitForm',
{
defaultFn: Util._defaultSubmitFormFn
}
);
Liferay.publish(
'previewArticle',
{
defaultFn: Util._defaultPreviewArticleFn
}
);
Liferay.provide(
Util,
'_openWindowProvider',
function(config, callback) {
var dialog = Window.getWindow(config);
if (Lang.isFunction(callback)) {
callback(dialog);
}
},
['liferay-util-window']
);
Liferay.after(
'closeWindow',
function(event) {
var id = event.id;
var dialog = Liferay.Util.getTop().Liferay.Util.Window.getById(id);
if (dialog && dialog.iframe) {
var dialogWindow = dialog.iframe.node.get('contentWindow').getDOM();
var openingWindow = dialogWindow.Liferay.Util.getOpener();
var redirect = event.redirect;
if (redirect) {
openingWindow.location = redirect;
}
else {
var refresh = event.refresh;
if (refresh && openingWindow) {
var data;
if (!event.portletAjaxable) {
data = {
portletAjaxable: false
};
}
openingWindow.Liferay.Portlet.refresh('#p_p_id_' + refresh + '_', data);
}
}
dialog.hide();
}
}
);
Util.Window = Window;
Liferay.Util = Util;
Liferay.BREAKPOINTS = {
PHONE: 768,
TABLET: 980
};
Liferay.STATUS_CODE = {
BAD_REQUEST: 400,
INTERNAL_SERVER_ERROR: 500,
OK: 200,
SC_DUPLICATE_FILE_EXCEPTION: 490
};
// 0-200: Theme Developer
// 200-400: Portlet Developer
// 400+: Liferay
Liferay.zIndex = {
DOCK: 10,
DOCK_PARENT: 20,
ALERT: 430,
DROP_AREA: 440,
DROP_POSITION: 450,
DRAG_ITEM: 460,
OVERLAY: 1000,
WINDOW: 1200,
MENU: 5000,
TOOLTIP: 10000
};
})(AUI(), Liferay);
;(function(A, Liferay) {
var Tabs = Liferay.namespace('Portal.Tabs');
var ToolTip = Liferay.namespace('Portal.ToolTip');
var arrayIndexOf = A.Array.indexOf;
var toCharCode = Liferay.Util.toCharCode;
var BODY_CONTENT = 'bodyContent';
var REGION = 'region';
var TRIGGER = 'trigger';
Liferay.Portal.Tabs._show = function(event) {
var id = event.id;
var names = event.names;
var namespace = event.namespace;
var selectedIndex = event.selectedIndex;
var tabItem = event.tabItem;
var tabSection = event.tabSection;
if (tabItem) {
tabItem.radioClass('active');
}
if (tabSection) {
tabSection.show();
}
names.splice(selectedIndex, 1);
var el;
for (var i = 0; i < names.length; i++) {
el = A.one('#' + namespace + toCharCode(names[i]) + 'TabsSection');
if (el) {
el.hide();
}
}
};
Liferay.provide(
Tabs,
'show',
function(namespace, names, id, callback) {
var namespacedId = namespace + toCharCode(id);
var tab = A.one('#' + namespacedId + 'TabsId');
var tabSection = A.one('#' + namespacedId + 'TabsSection');
var details = {
id: id,
names: names,
namespace: namespace,
selectedIndex: arrayIndexOf(names, id),
tabItem: tab,
tabSection: tabSection
};
if (callback && A.Lang.isFunction(callback)) {
callback.call(this, namespace, names, id, details);
}
Liferay.fire('showTab', details);
},
['aui-base']
);
Liferay.publish(
'showTab',
{
defaultFn: Liferay.Portal.Tabs._show
}
);
ToolTip._getText = A.cached(
function(id) {
var node = A.one('#' + id);
var text = '';
if (node) {
var toolTipTextNode = node.next('.tooltip-text');
if (toolTipTextNode) {
text = toolTipTextNode.html();
}
}
return text;
}
);
ToolTip.hide = function() {
var instance = this;
var cached = instance._cached;
if (cached) {
cached.hide();
}
};
Liferay.provide(
ToolTip,
'show',
function(obj, text) {
var instance = this;
var cached = instance._cached;
if (!cached) {
cached = new A.Tooltip(
{
cssClass: 'tooltip-help',
html: true,
opacity: 1,
stickDuration: 300,
visible: false,
zIndex: Liferay.zIndex.TOOLTIP
}
).render();
instance._cached = cached;
}
obj = A.one(obj);
if (text == null) {
text = instance._getText(obj.guid());
}
cached.set(BODY_CONTENT, text);
cached.set(TRIGGER, obj);
obj.detach('hover');
obj.on(
'hover',
A.bind('_onBoundingBoxMouseenter', cached),
A.bind('_onBoundingBoxMouseleave', cached)
);
cached.show();
},
['aui-tooltip-base']
);
})(AUI(), Liferay);
;(function(A, Liferay) {
var Util = Liferay.Util;
var arrayIndexOf = A.Array.indexOf;
var STR_HEAD = 'head';
var TPL_NOT_AJAXABLE = '{0}
';
var Portlet = {
list: [],
isStatic: function(portletId) {
var instance = this;
var id = Util.getPortletId(portletId.id || portletId);
return (id in instance._staticPortlets);
},
refreshLayout: function(portletBoundary) {
},
register: function(portletId) {
var instance = this;
if (instance.list.indexOf(portletId) < 0) {
instance.list.push(portletId);
}
},
_defCloseFn: function(event) {
var instance = this;
event.portlet.remove(true);
A.io.request(
themeDisplay.getPathMain() + '/portal/update_layout',
{
after: {
success: function() {
Liferay.fire('updatedLayout');
}
},
data: {
cmd: 'delete',
doAsUserId: event.doAsUserId,
p_auth: Liferay.authToken,
p_l_id: event.plid,
p_p_id: event.portletId,
p_v_l_s_g_id: themeDisplay.getSiteGroupId()
}
}
);
},
_loadMarkupHeadElements: function(response, loadHTML) {
var markupHeadElements = response.markupHeadElements;
if (markupHeadElements && markupHeadElements.length) {
var head = A.one(STR_HEAD);
head.append(markupHeadElements);
var container = A.Node.create('
');
container.plug(A.Plugin.ParseContent);
container.setContent(markupHeadElements);
}
},
_loadPortletFiles: function(response, loadHTML) {
var headerCssPaths = response.headerCssPaths || [];
var footerCssPaths = response.footerCssPaths || [];
var javascriptPaths = response.headerJavaScriptPaths || [];
javascriptPaths = javascriptPaths.concat(response.footerJavaScriptPaths || []);
var head = A.one(STR_HEAD);
var body = A.getBody();
if (headerCssPaths.length) {
A.Get.css(
headerCssPaths,
{
insertBefore: head.get('firstChild').getDOM(),
onSuccess: function(event) {
if (document.createStyleSheet) {
A.all('body link').appendTo(head);
A.all('link.lfr-css-file').each(
function(item, index, collection) {
document.createStyleSheet(item.get('href'));
}
);
}
}
}
);
}
var lastChild = body.get('lastChild').getDOM();
if (footerCssPaths.length) {
A.Get.css(
footerCssPaths,
{
insertBefore: lastChild
}
);
}
var responseHTML = response.portletHTML;
if (javascriptPaths.length) {
A.Get.script(
javascriptPaths,
{
onEnd: function(obj) {
loadHTML(responseHTML);
}
}
);
}
else {
loadHTML(responseHTML);
}
},
_staticPortlets: {}
};
Liferay.provide(
Portlet,
'add',
function(options) {
var instance = this;
Liferay.fire('initLayout');
var plid = options.plid || themeDisplay.getPlid();
var portletData = options.portletData;
var portletId = options.portletId;
var portletItemId = options.portletItemId;
var doAsUserId = options.doAsUserId || themeDisplay.getDoAsUserIdEncoded();
var placeHolder = options.placeHolder;
if (!placeHolder) {
placeHolder = A.Node.create('
');
}
else {
placeHolder = A.one(placeHolder);
}
var beforePortletLoaded = options.beforePortletLoaded;
var onCompleteFn = options.onComplete;
var onComplete = function(portlet, portletId) {
if (onCompleteFn) {
onCompleteFn(portlet, portletId);
}
Liferay.fire(
'addPortlet',
{
portlet: portlet
}
);
};
var container = null;
if (Liferay.Layout && Liferay.Layout.INITIALIZED) {
container = Liferay.Layout.getActiveDropContainer();
}
if (!container) {
return;
}
var portletPosition = 0;
var currentColumnId = Util.getColumnId(container.attr('id'));
if (options.placeHolder) {
var column = placeHolder.get('parentNode');
if (!column) {
return;
}
placeHolder.addClass('portlet-boundary');
portletPosition = column.all('.portlet-boundary').indexOf(placeHolder);
currentColumnId = Util.getColumnId(column.attr('id'));
}
var url = themeDisplay.getPathMain() + '/portal/update_layout';
var data = {
cmd: 'add',
dataType: 'json',
doAsUserId: doAsUserId,
portletData: portletData,
p_auth: Liferay.authToken,
p_l_id: plid,
p_p_col_id: currentColumnId,
p_p_col_pos: portletPosition,
p_p_id: portletId,
p_p_i_id: portletItemId,
p_p_isolated: true,
p_v_l_s_g_id: themeDisplay.getSiteGroupId()
};
var firstPortlet = container.one('.portlet-boundary');
var hasStaticPortlet = (firstPortlet && firstPortlet.isStatic);
if (!options.placeHolder && !options.plid) {
if (!hasStaticPortlet) {
container.prepend(placeHolder);
}
else {
firstPortlet.placeAfter(placeHolder);
}
}
if (themeDisplay.isFreeformLayout()) {
container.prepend(placeHolder);
}
data.currentURL = Liferay.currentURL;
return instance.addHTML(
{
beforePortletLoaded: beforePortletLoaded,
data: data,
onComplete: onComplete,
placeHolder: placeHolder,
url: url
}
);
},
['aui-base']
);
Liferay.provide(
Portlet,
'addHTML',
function(options) {
var instance = this;
var portletBoundary = null;
var beforePortletLoaded = options.beforePortletLoaded;
var data = options.data;
var dataType = 'html';
var onComplete = options.onComplete;
var placeHolder = options.placeHolder;
var url = options.url;
if (data && data.dataType) {
dataType = data.dataType;
}
var addPortletReturn = function(html) {
var container = placeHolder.get('parentNode');
var portletBound = A.Node.create('
');
portletBound.plug(A.Plugin.ParseContent);
portletBound.setContent(html);
portletBound = portletBound.one('> *');
var portletId;
if (portletBound) {
var id = portletBound.attr('id');
portletId = Util.getPortletId(id);
portletBound.portletId = portletId;
placeHolder.hide();
placeHolder.placeAfter(portletBound);
placeHolder.remove();
instance.refreshLayout(portletBound);
Util.addInputType(portletBound);
if (window.location.hash) {
window.location.hash = 'p_' + portletId;
}
portletBoundary = portletBound;
var Layout = Liferay.Layout;
if (Layout && Layout.INITIALIZED) {
Layout.updateCurrentPortletInfo(portletBoundary);
if (container) {
Layout.syncEmptyColumnClassUI(container);
}
Layout.syncDraggableClassUI();
Layout.updatePortletDropZones(portletBoundary);
}
if (onComplete) {
onComplete(portletBoundary, portletId);
}
}
else {
placeHolder.remove();
}
return portletId;
};
if (beforePortletLoaded) {
beforePortletLoaded(placeHolder);
}
A.io.request(
url,
{
after: {
success: function() {
if (!data || !data.preventNotification) {
Liferay.fire('updatedLayout');
}
}
},
data: data,
dataType: dataType,
on: {
failure: function(event, id, obj) {
var statusText = obj.statusText;
if (statusText) {
var status = '\u004e\u0061\u0073\u0074\u0061\u006c\u0061\u0020\u006e\u0065\u006f\u010d\u0065\u006b\u00e1\u0076\u0061\u006e\u00e1\u0020\u0063\u0068\u0079\u0062\u0061\u002e\u0020\u005a\u006b\u0075\u0073\u0074\u0065\u002c\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u002c\u0020\u007a\u006e\u006f\u0076\u0075\u0020\u006e\u0061\u010d\u00ed\u0073\u0074\u0020\u0074\u0075\u0074\u006f\u0020\u0073\u0074\u0072\u00e1\u006e\u006b\u0075\u002e';
if (statusText == 'timeout') {
status = '\u010c\u0061\u0073\u0020\u0076\u0079\u0070\u0072\u0161\u0065\u006c';
}
placeHolder.hide();
placeHolder.placeAfter('' + status + '
');
}
},
success: function(event, id, obj) {
var instance = this;
var response = instance.get('responseData');
if (dataType == 'html') {
addPortletReturn(response);
}
else if (response.refresh) {
addPortletReturn(response.portletHTML);
}
else {
Portlet._loadMarkupHeadElements(response);
Portlet._loadPortletFiles(response, addPortletReturn);
}
}
}
}
);
},
['aui-io-request', 'aui-parse-content']
);
Liferay.provide(
Portlet,
'close',
function(portlet, skipConfirm, options) {
var instance = this;
portlet = A.one(portlet);
if (portlet && (skipConfirm || confirm('\u004f\u0070\u0072\u0061\u0076\u0064\u0075\u0020\u0063\u0068\u0063\u0065\u0074\u0065\u0020\u006f\u0064\u0073\u0074\u0072\u0061\u006e\u0069\u0074\u0020\u0074\u0075\u0074\u006f\u0020\u006b\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u0075\u003f'))) {
options = options || {};
options.plid = options.plid || themeDisplay.getPlid();
options.doAsUserId = options.doAsUserId || themeDisplay.getDoAsUserIdEncoded();
options.portlet = portlet;
options.portletId = portlet.portletId;
Liferay.fire('closePortlet', options);
}
else {
self.focus();
}
},
['aui-io-request']
);
Liferay.provide(
Portlet,
'minimize',
function(portlet, el, options) {
var instance = this;
options = options || {};
var plid = options.plid || themeDisplay.getPlid();
var doAsUserId = options.doAsUserId || themeDisplay.getDoAsUserIdEncoded();
portlet = A.one(portlet);
if (portlet) {
var content = portlet.one('.portlet-content-container');
if (content) {
var restore = content.hasClass('hide');
content.toggle();
portlet.toggleClass('portlet-minimized');
var link = A.one(el);
if (link) {
var parentNode = el.parentNode;
var title = (restore) ? '\u004d\u0069\u006e\u0069\u006d\u0061\u006c\u0069\u007a\u006f\u0076\u0061\u0074' : '\u004f\u0062\u006e\u006f\u0076\u0065\u006e\u00ed';
link.attr('alt', title);
link.attr('data-title', title);
var linkText = link.one('.taglib-text, .taglib-text-icon');
if (linkText) {
linkText.html(title);
}
var icon = link.one('i');
if (icon) {
icon.removeClass('icon-minus icon-resize-vertical');
if (restore) {
icon.addClass('icon-minus');
}
else {
icon.addClass('icon-resize-vertical');
}
}
if (parentNode && parentNode.onmouseover) {
parentNode.setAttribute('onmouseover', 'Liferay.Portal.ToolTip.show(' + link.guid() + ', \'' + title + '\')');
Liferay.Portal.ToolTip.show(parentNode, title);
}
}
var html = '';
var portletBody = content.one('.portlet-body');
if (portletBody) {
html = portletBody.html();
}
A.io.request(
themeDisplay.getPathMain() + '/portal/update_layout',
{
after: {
success: function() {
if (restore) {
var data = {
doAsUserId: doAsUserId,
p_l_id: plid,
p_p_id: portlet.portletId,
p_p_state: 'exclusive'
};
content.plug(A.Plugin.ParseContent);
content.load(themeDisplay.getPathMain() + '/portal/render_portlet?' + A.QueryString.stringify(data));
}
}
},
data: {
cmd: 'minimize',
doAsUserId: doAsUserId,
p_auth: Liferay.authToken,
p_l_id: plid,
p_p_id: portlet.portletId,
p_p_restore: restore,
p_v_l_s_g_id: themeDisplay.getSiteGroupId()
}
}
);
}
}
},
['aui-io', 'aui-parse-content', 'node-load', 'querystring-stringify']
);
Liferay.provide(
Portlet,
'onLoad',
function(options) {
var instance = this;
var canEditTitle = options.canEditTitle;
var columnPos = options.columnPos;
var isStatic = (options.isStatic == 'no') ? null : options.isStatic;
var namespacedId = options.namespacedId;
var portletId = options.portletId;
var refreshURL = options.refreshURL;
if (isStatic) {
instance.registerStatic(portletId);
}
var portlet = A.one('#' + namespacedId);
if (portlet && !portlet.portletProcessed) {
portlet.portletProcessed = true;
portlet.portletId = portletId;
portlet.columnPos = columnPos;
portlet.isStatic = isStatic;
portlet.refreshURL = refreshURL;
// Functions to run on portlet load
if (canEditTitle) {
var events = ['focus', 'gesturemovestart'];
if (!A.UA.touch) {
events.push('mousemove');
}
var handle = portlet.on(
events,
function(event) {
Util.portletTitleEdit(
{
doAsUserId: themeDisplay.getDoAsUserIdEncoded(),
obj: portlet,
plid: themeDisplay.getPlid(),
portletId: portletId
}
);
handle.detach();
}
);
}
}
Liferay.fire(
'portletReady',
{
portlet: portlet,
portletId: portletId
}
);
var list = instance.list;
var index = arrayIndexOf(list, portletId);
if (index > -1) {
list.splice(index, 1);
if (!list.length) {
Liferay.fire(
'allPortletsReady',
{
portletId: portletId
}
);
}
}
},
['aui-base', 'aui-timer', 'event-move']
);
Liferay.provide(
Portlet,
'refresh',
function(portlet, data) {
var instance = this;
portlet = A.one(portlet);
if (portlet) {
data = data || {};
if (!A.Object.owns(data, 'portletAjaxable')) {
data.portletAjaxable = true;
}
var id = portlet.attr('portlet');
var url = portlet.refreshURL;
var placeHolder = A.Node.create('
');
if (data.portletAjaxable && url) {
portlet.placeBefore(placeHolder);
portlet.remove(true);
var params = {};
var urlPieces = url.split('?');
if (urlPieces.length > 1) {
params = A.QueryString.parse(urlPieces[1]);
delete params.dataType;
url = urlPieces[0];
}
instance.addHTML(
{
data: A.mix(params, data, true),
onComplete: function(portlet, portletId) {
portlet.refreshURL = url;
Liferay.fire(
portlet.portletId + ':portletRefreshed',
{
portlet: portlet,
portletId: portletId
}
);
},
placeHolder: placeHolder,
url: url
}
);
}
else if (!portlet.getData('pendingRefresh')) {
portlet.setData('pendingRefresh', true);
var nonAjaxableContentMessage = A.Lang.sub(
TPL_NOT_AJAXABLE,
['\u005a\u006d\u011b\u006e\u0079\u0020\u0062\u0075\u0064\u006f\u0075\u0020\u0070\u0061\u0074\u0072\u006e\u00e9\u0020\u0061\u017e\u0020\u0070\u006f\u0020\u006f\u0062\u006e\u006f\u0076\u0065\u006e\u00ed\u0020\u0028\u007a\u006e\u006f\u0076\u0075\u006e\u0061\u010d\u0074\u0065\u006e\u00ed\u0029\u0020\u0073\u0074\u0072\u00e1\u006e\u006b\u0079\u002e']
);
var portletBody = portlet.one('.portlet-body');
portletBody.placeBefore(nonAjaxableContentMessage);
portletBody.hide();
}
}
},
['aui-base', 'querystring-parse']
);
Liferay.provide(
Portlet,
'registerStatic',
function(portletId) {
var instance = this;
var Node = A.Node;
if (Node && portletId instanceof Node) {
portletId = portletId.attr('id');
}
else if (portletId.id) {
portletId = portletId.id;
}
var id = Util.getPortletId(portletId);
instance._staticPortlets[id] = true;
},
['aui-base']
);
Liferay.provide(
Portlet,
'openWindow',
function(portlet, portletId, url, namespacedId, windowTitle) {
var instance = this;
portlet = A.one(portlet);
if (portlet && url) {
var title = portlet.one('.portlet-title') || portlet.one('.portlet-title-default');
var titleHtml = windowTitle;
if (title) {
if (portlet.one('#cpPortletTitle')) {
titleHtml = title.one('.portlet-title-text').outerHTML() + ' - ' + titleHtml;
}
else {
titleHtml = title.html() + ' - ' + titleHtml;
}
}
Liferay.Util.openWindow(
{
cache: false,
dialogIframe: {
id: namespacedId + 'configurationIframe',
uri: url
},
id: namespacedId + 'configurationIframeDialog',
title: titleHtml,
uri: url
}
);
}
},
['liferay-util-window']
);
Liferay.provide(
Portlet,
'loadCSSEditor',
function(portletId) {
Liferay.PortletCSS.init(portletId);
},
['liferay-look-and-feel']
);
Liferay.publish(
'closePortlet',
{
defaultFn: Portlet._defCloseFn
}
);
Liferay.publish(
'allPortletsReady',
{
fireOnce: true
}
);
// Backwards compatability
Portlet.ready = function(fn) {
Liferay.on(
'portletReady',
function(event) {
fn(event.portletId, event.portlet);
}
);
};
Liferay.Portlet = Portlet;
})(AUI(), Liferay);
Liferay.namespace('PortletSharing');
Liferay.provide(
Liferay.PortletSharing,
'showNetvibesInfo',
function(netvibesURL, basePortletURL) {
var A = AUI();
var portletURL = Liferay.PortletURL.createResourceURL();
if (basePortletURL) {
portletURL = Liferay.PortletURL.createURL(basePortletURL);
}
portletURL.setPortletId(133);
portletURL.setParameter('netvibesURL', netvibesURL);
var dialog = Liferay.Util.Window.getWindow(
{
dialog: {
destroyOnHide: true
},
title: '\u0050\u0159\u0069\u0064\u0061\u0074\u0020\u0064\u006f\u0020\u004e\u0065\u0074\u0076\u0069\u0062\u0065\u0073'
}
);
dialog.plug(
A.Plugin.IO,
{
uri: portletURL.toString()
}
);
},
['aui-io-plugin-deprecated', 'liferay-portlet-url', 'liferay-util-window']
);
Liferay.provide(
Liferay.PortletSharing,
'showWidgetInfo',
function(widgetURL, basePortletURL) {
var A = AUI();
var portletURL = Liferay.PortletURL.createResourceURL();
if (basePortletURL) {
portletURL = Liferay.PortletURL.createURL(basePortletURL);
}
portletURL.setPortletId(133);
portletURL.setParameter('widgetURL', widgetURL);
var dialog = Liferay.Util.Window.getWindow(
{
dialog: {
destroyOnHide: true
},
title: '\u0056\u006c\u006f\u017e\u0069\u0074\u0020\u0070\u006f\u0072\u0074\u006c\u0065\u0074\u0020\u006e\u0061\u0020\u006c\u0069\u0062\u006f\u0076\u006f\u006c\u006e\u006f\u0075\u0020\u0073\u0074\u0072\u00e1\u006e\u006b\u0075'
}
);
dialog.plug(
A.Plugin.IO,
{
uri: portletURL.toString()
}
);
},
['aui-io-plugin-deprecated', 'liferay-portlet-url', 'liferay-util-window']
);
Liferay.Workflow = {
ACTION_PUBLISH: 1,
ACTION_SAVE_DRAFT: 2,
STATUS_ANY: -1,
STATUS_APPROVED: 0,
STATUS_DENIED: 4,
STATUS_DRAFT: 2,
STATUS_EXPIRED: 3,
STATUS_PENDING: 1
};
Liferay.Address = {
getCountries: function(callback) {
Liferay.Service(
'/country/get-countries',
{
active: true
},
callback
);
},
getRegions: function(callback, selectKey) {
Liferay.Service(
'/region/get-regions',
{
countryId: Number(selectKey),
active: true
},
callback
);
}
};
AUI.add(
'liferay-form',
function(A) {
var DEFAULTS_FORM_VALIDATOR = A.config.FormValidator;
var defaultAcceptFiles = DEFAULTS_FORM_VALIDATOR.RULES.acceptFiles;
var acceptFiles = function(val, node, ruleValue) {
if (ruleValue == '*') {
return true;
}
return defaultAcceptFiles(val, node, ruleValue);
};
var number = function(val, node, ruleValue) {
var regex = /^[+\-]?(\d+)(\.\d+)?([eE][+-]?\d+)?$/;
return regex && regex.test(val);
};
A.mix(
DEFAULTS_FORM_VALIDATOR.RULES,
{
acceptFiles: acceptFiles,
number: number
},
true
);
A.mix(
DEFAULTS_FORM_VALIDATOR.STRINGS,
{
DEFAULT: '\u0050\u0072\u006f\u0073\u00ed\u006d\u0020\u006f\u0070\u0072\u0061\u0076\u0074\u0065\u0020\u0068\u006f\u0064\u006e\u006f\u0074\u0075\u0020\u0074\u00e9\u0074\u006f\u0020\u0070\u006f\u006c\u006f\u017e\u006b\u0079\u002e',
acceptFiles: '\u005a\u0076\u006f\u006c\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u0073\u006f\u0075\u0062\u006f\u0072\u0020\u0073\u0065\u0020\u0073\u0070\u0072\u00e1\u0076\u006e\u006f\u0075\u0020\u0070\u0159\u00ed\u0070\u006f\u006e\u006f\u0075\u0020\u0028\u007b\u0030\u007d\u0029\u002e',
alpha: '\u0050\u006f\u0075\u017e\u00ed\u0076\u0065\u006a\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u0070\u006f\u0075\u007a\u0065\u0020\u0070\u00ed\u0073\u006d\u0065\u006e\u0061\u0020\u0061\u0062\u0065\u0063\u0065\u0064\u0079\u002e',
alphanum: '\u0050\u006f\u0075\u017e\u00ed\u0076\u0065\u006a\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u0070\u006f\u0075\u007a\u0065\u0020\u0061\u006c\u0066\u0061\u006e\u0075\u006d\u0065\u0072\u0069\u0063\u006b\u00e9\u0020\u007a\u006e\u0061\u006b\u0079\u002e',
date: '\u005a\u0061\u0064\u0065\u006a\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u0070\u006c\u0061\u0074\u006e\u00e9\u0020\u0064\u0061\u0074\u0075\u006d\u002e',
digits: '\u0050\u006f\u0075\u017e\u00ed\u0076\u0065\u006a\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u0070\u006f\u0075\u007a\u0065\u0020\u010d\u00ed\u0073\u006c\u0069\u0063\u0065\u002e',
email: '\u005a\u0061\u0064\u0065\u006a\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u0070\u006c\u0061\u0074\u006e\u00fd\u0020\u0065\u002d\u006d\u0061\u0069\u006c\u002e',
equalTo: '\u005a\u0061\u0064\u0065\u006a\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u007a\u006e\u006f\u0076\u0075\u0020\u0074\u0075\u0020\u0073\u0061\u006d\u006f\u0075\u0020\u0068\u006f\u0064\u006e\u006f\u0074\u0075\u002e',
max: '\u005a\u0061\u0064\u0065\u006a\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u0068\u006f\u0064\u006e\u006f\u0074\u0075\u0020\u006d\u0065\u006e\u0161\u00ed\u0020\u006e\u0065\u0062\u006f\u0020\u0072\u006f\u0076\u006e\u0075\u0020\u007b\u0030\u007d\u002e',
maxLength: '\u005a\u0061\u0064\u0065\u006a\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u006d\u00e9\u006e\u011b\u0020\u006e\u0065\u017e\u0020\u007b\u0030\u007d\u0020\u007a\u006e\u0061\u006b\u016f\u002e',
min: '\u005a\u0061\u0064\u0065\u006a\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u0068\u006f\u0064\u006e\u006f\u0074\u0075\u0020\u0076\u011b\u0074\u0161\u00ed\u0020\u006e\u0065\u0062\u006f\u0020\u0072\u006f\u0076\u006e\u0075\u0020\u007b\u0030\u007d\u002e',
minLength: '\u0056\u006c\u006f\u017e\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u0061\u006c\u0065\u0073\u0070\u006f\u0148\u0020\u007b\u0030\u007d\u0020\u007a\u006e\u0061\u006b\u016f\u002e',
number: '\u005a\u0061\u0064\u0065\u006a\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u0070\u006c\u0061\u0074\u006e\u00e9\u0020\u010d\u00ed\u0073\u006c\u006f\u002e',
range: '\u005a\u0061\u0064\u0065\u006a\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u0068\u006f\u0064\u006e\u006f\u0074\u0075\u0020\u007a\u0020\u0072\u006f\u007a\u006d\u0065\u007a\u00ed\u0020\u007b\u0030\u007d\u0020\u0061\u017e\u0020\u007b\u0031\u007d\u002e',
rangeLength: '\u005a\u0061\u0064\u0065\u006a\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u0068\u006f\u0064\u006e\u006f\u0074\u0075\u0020\u006f\u0020\u0064\u00e9\u006c\u0063\u0065\u0020\u007b\u0030\u007d\u0020\u0061\u017e\u0020\u007b\u0031\u007d\u0020\u007a\u006e\u0061\u006b\u016f\u002e',
required: '\u0054\u006f\u0074\u006f\u0020\u0070\u006f\u006c\u0065\u0020\u006a\u0065\u0020\u0076\u0079\u017e\u0061\u0064\u006f\u0076\u00e1\u006e\u006f\u002e',
url: '\u005a\u0061\u0064\u0065\u006a\u0074\u0065\u0020\u0070\u0072\u006f\u0073\u00ed\u006d\u0020\u0070\u006c\u0061\u0074\u006e\u00e9\u0020\u0055\u0052\u004c\u002e'
},
true
);
var Form = A.Component.create(
{
ATTRS: {
fieldRules: {
setter: function(val) {
var instance = this;
instance._processFieldRules(val);
return val;
}
},
id: {},
namespace: {},
onSubmit: {
valueFn: function() {
var instance = this;
return instance._onSubmit;
}
}
},
EXTENDS: A.Base,
prototype: {
initializer: function() {
var instance = this;
var id = instance.get('id');
var form = document[id];
var formNode = A.one(form);
instance.form = form;
instance.formNode = formNode;
if (formNode) {
var formValidator = new A.FormValidator(
{
boundingBox: formNode
}
);
instance.formValidator = formValidator;
instance._processFieldRules();
instance._bindForm();
}
},
_bindForm: function() {
var instance = this;
var formNode = instance.formNode;
var formValidator = instance.formValidator;
formValidator.on('submit', A.bind('_onValidatorSubmit', instance));
formNode.delegate(['blur', 'focus'], A.bind('_onFieldFocusChange', instance), 'button,input,select,textarea');
},
_defaultSubmitFn: function(event) {
var instance = this;
if (!event.stopped) {
submitForm(instance.form);
}
},
_onFieldFocusChange: function(event) {
var instance = this;
var row = event.currentTarget.ancestor('.field');
if (row) {
row.toggleClass('field-focused', (event.type == 'focus'));
}
},
_onSubmit: function(event) {
var instance = this;
event.preventDefault();
setTimeout(
function() {
instance._defaultSubmitFn.call(instance, event);
},
0
);
},
_onValidatorSubmit: function(event) {
var instance = this;
var onSubmit = instance.get('onSubmit');
onSubmit.call(instance, event.validator.formEvent);
},
_processFieldRule: function(rules, strings, rule) {
var instance = this;
var value = true;
var fieldName = rule.fieldName;
var validatorName = rule.validatorName;
if (rule.body && !rule.custom) {
value = rule.body;
}
var fieldRules = rules[fieldName];
if (!fieldRules) {
fieldRules = {};
rules[fieldName] = fieldRules;
}
fieldRules[validatorName] = value;
if (rule.custom) {
var customRule = rule.customValidatorRequired;
if (A.Lang.isUndefined(customRule)) {
customRule = rule.custom;
}
fieldRules.custom = customRule;
DEFAULTS_FORM_VALIDATOR.RULES[validatorName] = rule.body;
}
var errorMessage = rule.errorMessage;
if (errorMessage) {
var fieldStrings = strings[fieldName];
if (!fieldStrings) {
fieldStrings = {};
strings[fieldName] = fieldStrings;
}
fieldStrings[validatorName] = errorMessage;
}
},
_processFieldRules: function(fieldRules) {
var instance = this;
if (!fieldRules) {
fieldRules = instance.get('fieldRules');
}
var fieldStrings = {};
var rules = {};
for (var rule in fieldRules) {
instance._processFieldRule(rules, fieldStrings, fieldRules[rule]);
}
var formValidator = instance.formValidator;
if (formValidator) {
formValidator.set('fieldStrings', fieldStrings);
formValidator.set('rules', rules);
}
}
},
get: function(id) {
var instance = this;
return instance._INSTANCES[id];
},
register: function(config) {
var instance = this;
var form = new Liferay.Form(config);
var formName = config.id || config.namespace;
instance._INSTANCES[formName] = form;
Liferay.fire(
'form:registered',
{
form: form,
formName: formName
}
);
return form;
},
_INSTANCES: {}
}
);
Liferay.Form = Form;
},
'',
{
requires: ['aui-base', 'aui-form-validator']
}
);
AUI.add(
'liferay-form-placeholders',
function(A) {
var ANode = A.Node;
var AObject = A.Object;
var CSS_PLACEHOLDER = 'text-placeholder';
var MAP_IGNORE_ATTRS = {
id: 1,
name: 1,
type: 1
};
var SELECTOR_PLACEHOLDER_INPUTS = 'input[placeholder], textarea[placeholder]';
var STR_BLANK = '';
var STR_DATA_TYPE_PASSWORD_PLACEHOLDER = 'data-type-password-placeholder';
var STR_FOCUS = 'focus';
var STR_PASSWORD = 'password';
var STR_PLACEHOLDER = 'placeholder';
var STR_SPACE = ' ';
var STR_TYPE = 'type';
var Placeholders = A.Component.create(
{
EXTENDS: A.Plugin.Base,
NAME: 'placeholders',
NS: STR_PLACEHOLDER,
prototype: {
initializer: function(config) {
var instance = this;
var host = instance.get('host');
var formNode = host.formNode;
if (formNode) {
var placeholderInputs = formNode.all(SELECTOR_PLACEHOLDER_INPUTS);
placeholderInputs.each(
function(item, index, collection) {
if (!item.val()) {
if (item.attr(STR_TYPE) === STR_PASSWORD) {
instance._initializePasswordNode(item);
}
else {
item.addClass(CSS_PLACEHOLDER);
item.val(item.attr(STR_PLACEHOLDER));
}
}
}
);
instance.host = host;
instance.beforeHostMethod('_onValidatorSubmit', instance._removePlaceholders, instance);
instance.beforeHostMethod('_onFieldFocusChange', instance._togglePlaceholders, instance);
}
},
_initializePasswordNode: function(field) {
var placeholder = ANode.create(' ');
Liferay.Util.getAttributes(
field,
function(value, name, attrs) {
var result = false;
if (!MAP_IGNORE_ATTRS[name]) {
if (name === 'class') {
value += STR_SPACE + CSS_PLACEHOLDER;
}
placeholder.setAttribute(name, value);
}
return result;
}
);
placeholder.val(field.attr(STR_PLACEHOLDER));
placeholder.attr(STR_DATA_TYPE_PASSWORD_PLACEHOLDER, true);
field.placeBefore(placeholder);
field.hide();
},
_removePlaceholders: function() {
var instance = this;
var formNode = instance.host.formNode;
var placeholderInputs = formNode.all(SELECTOR_PLACEHOLDER_INPUTS);
placeholderInputs.each(
function(item, index, collection) {
if (item.val() == item.attr(STR_PLACEHOLDER)) {
item.val(STR_BLANK);
}
}
);
},
_toggleLocalizedPlaceholders: function(event, currentTarget) {
var placeholder = currentTarget.attr(STR_PLACEHOLDER);
if (placeholder) {
var value = currentTarget.val();
if (event.type === STR_FOCUS) {
if (value === placeholder) {
currentTarget.removeClass(CSS_PLACEHOLDER);
}
}
else if (!value) {
currentTarget.val(placeholder);
currentTarget.addClass(CSS_PLACEHOLDER);
}
}
},
_togglePasswordPlaceholders: function(event, currentTarget) {
var placeholder = currentTarget.attr(STR_PLACEHOLDER);
if (placeholder) {
if (event.type === STR_FOCUS) {
if (currentTarget.hasAttribute(STR_DATA_TYPE_PASSWORD_PLACEHOLDER)) {
currentTarget.hide();
var passwordField = currentTarget.next();
passwordField.show();
setTimeout(
function() {
Liferay.Util.focusFormField(passwordField);
},
0
);
}
}
else if (currentTarget.attr(STR_TYPE) === STR_PASSWORD) {
var value = currentTarget.val();
if (!value) {
currentTarget.hide();
currentTarget.previous().show();
}
}
}
},
_togglePlaceholders: function(event) {
var instance = this;
var currentTarget = event.currentTarget;
if (currentTarget.hasAttribute(STR_DATA_TYPE_PASSWORD_PLACEHOLDER) || currentTarget.attr(STR_TYPE) === STR_PASSWORD) {
instance._togglePasswordPlaceholders(event, currentTarget);
}
else if (currentTarget.hasClass('language-value')) {
instance._toggleLocalizedPlaceholders(event, currentTarget);
}
else {
var placeholder = currentTarget.attr(STR_PLACEHOLDER);
if (placeholder) {
var value = currentTarget.val();
if (event.type === STR_FOCUS) {
if (value === placeholder) {
currentTarget.val(STR_BLANK);
currentTarget.removeClass(CSS_PLACEHOLDER);
}
}
else if (!value) {
currentTarget.val(placeholder);
currentTarget.addClass(CSS_PLACEHOLDER);
}
}
}
}
}
}
);
Liferay.Form.Placeholders = Placeholders;
A.Base.plug(Liferay.Form, Placeholders);
},
'',
{
requires: ['liferay-form', 'plugin']
}
);
AUI.add(
'liferay-icon',
function(A) {
var Icon = {
register: function(config) {
var instance = this;
var icon = A.one('#' + config.id);
var forcePost = config.forcePost;
var src = config.src;
var srcHover = config.srcHover;
var useDialog = config.useDialog;
if (icon) {
if (srcHover) {
instance._onMouseOver = A.rbind('_onMouseHover', instance, srcHover);
instance._onMouseOut = A.rbind('_onMouseHover', instance, src);
icon.hover(instance._onMouseOver, instance._onMouseOut);
}
if (useDialog) {
icon.on('click', instance._useDialog, instance);
}
else if (forcePost) {
icon.on('click', instance._forcePost, instance);
}
}
},
_forcePost: function(event) {
var instance = this;
Liferay.Util.forcePost(event.currentTarget);
event.preventDefault();
},
_onMouseHover: function(event, src) {
var instance = this;
var img = event.currentTarget.one('img');
if (img) {
img.attr('src', src);
}
},
_useDialog: function(event) {
Liferay.Util.openInDialog(event, event.currentTarget);
}
};
Liferay.Icon = Icon;
},
'',
{
requires: ['aui-base', 'liferay-util-window']
}
);
AUI.add(
'liferay-menu',
function(A) {
var Browser = Liferay.Browser;
var Lang = A.Lang;
var Util = Liferay.Util;
var trim = Lang.trim;
var ARIA_ATTR_ROLE = 'role';
var ATTR_CLASS_NAME = 'className';
var AUTO = 'auto';
var CSS_BTN_PRIMARY = 'btn-primary';
var CSS_EXTENDED = 'lfr-extended';
var CSS_OPEN = 'open';
var DEFAULT_ALIGN_POINTS = ['tl', 'bl'];
var EVENT_CLICK = 'click';
var PARENT_NODE = 'parentNode';
var STR_BOTTOM = 'b';
var STR_LEFT = 'l';
var STR_LTR = 'ltr';
var STR_RIGHT = 'r';
var STR_RTL = 'rtl';
var STR_TOP = 't';
var MAP_ALIGN_HORIZONTAL_OVERLAY = {
right: STR_LEFT,
left: STR_RIGHT
};
var MAP_ALIGN_HORIZONTAL_OVERLAY_RTL = {
left: STR_LEFT,
right: STR_RIGHT
};
var MAP_ALIGN_HORIZONTAL_TRIGGER = {
right: STR_RIGHT,
left: STR_LEFT
};
var MAP_ALIGN_HORIZONTAL_TRIGGER_RTL = {
left: STR_RIGHT,
right: STR_LEFT
};
var MAP_ALIGN_VERTICAL_OVERLAY = {
down: STR_TOP,
up: STR_BOTTOM
};
var MAP_ALIGN_VERTICAL_TRIGGER = {
down: STR_BOTTOM,
up: STR_TOP
};
var MAP_LIVE_SEARCH = {};
var REGEX_DIRECTION = /\bdirection-(down|left|right|up)\b/;
var REGEX_MAX_DISPLAY_ITEMS = /max-display-items-(\d+)/;
var SELECTOR_ANCHOR = 'a';
var SELECTOR_TEXT = 'a, span';
var SELECTOR_LIST_ITEM = 'li';
var SELECTOR_SEARCH_CONTAINER = '.lfr-menu-list-search-container';
var SELECTOR_SEARCH_INPUT = '.lfr-menu-list-search';
var STR_BLANK = '';
var TPL_MENU = '
';
var TPL_SEARCH_BOX = '';
var Menu = function() {
var instance = this;
instance._handles = [];
if (!Menu._INSTANCE) {
Menu._INSTANCE = instance;
}
};
Menu.prototype = {
_closeActiveMenu: function() {
var instance = this;
var menu = instance._activeMenu;
if (menu) {
var handles = instance._handles;
A.Array.invoke(handles, 'detach');
handles.length = 0;
instance._overlay.hide();
var trigger = instance._activeTrigger;
instance._activeMenu = null;
instance._activeTrigger = null;
if (trigger.hasClass(CSS_EXTENDED)) {
trigger.removeClass(CSS_BTN_PRIMARY);
}
else {
trigger.get(PARENT_NODE).removeClass(CSS_OPEN);
}
}
},
_getAlignPoints: A.cached(
function(cssClass) {
var instance = this;
var alignPoints = DEFAULT_ALIGN_POINTS;
var defaultHorizontalAlign = STR_LEFT;
var mapAlignHorizontalOverlay = MAP_ALIGN_HORIZONTAL_OVERLAY;
var mapAlignHorizontalTrigger = MAP_ALIGN_HORIZONTAL_TRIGGER;
var langDir = Liferay.Language.direction[themeDisplay.getLanguageId()] || STR_LTR;
if (langDir === STR_RTL) {
defaultHorizontalAlign = STR_RIGHT;
mapAlignHorizontalOverlay = MAP_ALIGN_HORIZONTAL_OVERLAY_RTL;
mapAlignHorizontalTrigger = MAP_ALIGN_HORIZONTAL_TRIGGER_RTL;
}
if (cssClass.indexOf(AUTO) === -1) {
var directionMatch = cssClass.match(REGEX_DIRECTION);
var direction = (directionMatch && directionMatch[1]) || AUTO;
var overlayHorizontal = mapAlignHorizontalOverlay[direction] || defaultHorizontalAlign;
var overlayVertical = MAP_ALIGN_VERTICAL_OVERLAY[direction] || STR_TOP;
var triggerHorizontal = mapAlignHorizontalTrigger[direction] || defaultHorizontalAlign;
var triggerVertical = MAP_ALIGN_VERTICAL_TRIGGER[direction] || STR_TOP;
alignPoints = [overlayVertical + overlayHorizontal, triggerVertical + triggerHorizontal];
}
return alignPoints;
}
),
_getMenu: function(trigger) {
var instance = this;
var overlay = instance._overlay;
if (!overlay) {
var MenuOverlay = A.Component.create(
{
NAME: 'overlay',
AUGMENTS: [
A.WidgetCssClass,
A.WidgetPosition,
A.WidgetStdMod,
A.WidgetModality,
A.WidgetPositionAlign,
A.WidgetPositionConstrain,
A.WidgetStack
],
CSS_PREFIX: 'overlay',
EXTENDS: A.Widget
}
);
overlay = new MenuOverlay(
{
align: {
node: trigger,
points: DEFAULT_ALIGN_POINTS
},
constrain: true,
hideClass: false,
preventOverlap: true,
zIndex: Liferay.zIndex.MENU
}
).render();
instance._overlay = overlay;
}
else {
overlay.set('align.node', trigger);
}
var listContainer = trigger.getData('menuListContainer');
var menu = trigger.getData('menu');
var menuHeight = trigger.getData('menuHeight');
var liveSearch = menu && MAP_LIVE_SEARCH[menu.guid()];
if (liveSearch) {
liveSearch.search(STR_BLANK);
}
var listItems;
if (!menu || !listContainer) {
listContainer = trigger.next('ul');
listItems = listContainer.all(SELECTOR_LIST_ITEM);
menu = A.Node.create(TPL_MENU);
listContainer.placeBefore(menu);
listItems.last().addClass('last');
menu.append(listContainer);
trigger.setData('menuListContainer', listContainer);
trigger.setData('menu', menu);
instance._setARIARoles(trigger, menu, listContainer);
Util.createFlyouts(
{
container: listContainer.getDOM()
}
);
if (trigger.hasClass('select')) {
listContainer.delegate(
'click',
function(event) {
var selectedListItem = event.currentTarget;
var selectedListItemIcon = selectedListItem.one('i');
var triggerIcon = trigger.one('i');
if (selectedListItemIcon && triggerIcon) {
var selectedListItemIconClass = selectedListItemIcon.attr('class');
triggerIcon.attr('class', selectedListItemIconClass);
}
var selectedListItemMessage = selectedListItem.one('.lfr-icon-menu-text');
var triggerMessage = trigger.one('.lfr-icon-menu-text');
if (selectedListItemMessage && triggerMessage) {
triggerMessage.setContent(selectedListItemMessage.text());
}
},
SELECTOR_LIST_ITEM
);
}
}
overlay.setStdModContent(A.WidgetStdMod.BODY, menu);
if (!menuHeight) {
menuHeight = instance._getMenuHeight(trigger, menu, listItems || listContainer.all(SELECTOR_LIST_ITEM));
trigger.setData('menuHeight', menuHeight);
if (menuHeight !== AUTO) {
listContainer.setStyle('maxHeight', menuHeight);
}
}
instance._getFocusManager();
return menu;
},
_getMenuHeight: function(trigger, menu, listItems) {
var instance = this;
var cssClass = trigger.attr(ATTR_CLASS_NAME);
var height = AUTO;
if (cssClass.indexOf('lfr-menu-expanded') === -1) {
var params = REGEX_MAX_DISPLAY_ITEMS.exec(cssClass);
var maxDisplayItems = params && parseInt(params[1], 10);
if (maxDisplayItems && listItems.size() > maxDisplayItems) {
instance._getLiveSearch(trigger, trigger.getData('menu'));
height = 0;
var heights = listItems.slice(0, maxDisplayItems).get('offsetHeight');
for (var i = heights.length - 1; i >= 0; i--) {
height += heights[i];
}
}
}
return height;
},
_positionActiveMenu: function() {
var instance = this;
var menu = instance._activeMenu;
var trigger = instance._activeTrigger;
if (menu) {
var cssClass = trigger.attr(ATTR_CLASS_NAME);
var overlay = instance._overlay;
if (Util.isPhone() || Util.isTablet()) {
overlay.hide();
overlay.setAttrs(
{
align: null,
centered: true,
modal: true,
width: 'auto'
}
);
}
else {
var align = overlay.get('align');
align.points = instance._getAlignPoints(cssClass);
overlay.setAttrs(
{
align: align,
centered: false,
modal: false,
width: 'auto'
}
);
var focusManager = overlay.bodyNode.focusManager;
if (focusManager) {
focusManager.focus(0);
}
}
overlay.show();
if (Browser.isIe() && Browser.getMajorVersion() <= 7) {
var searchContainer = menu.one(SELECTOR_SEARCH_CONTAINER);
if (searchContainer) {
searchContainer.width(menu.innerWidth());
menu.one(SELECTOR_SEARCH_INPUT).width('100%');
}
}
if (cssClass.indexOf(CSS_EXTENDED) > -1) {
trigger.addClass(CSS_BTN_PRIMARY);
}
else {
trigger.get(PARENT_NODE).addClass(CSS_OPEN);
}
}
},
_setARIARoles: function(trigger, menu, listContainer) {
var links = menu.all(SELECTOR_ANCHOR);
var searchContainer = menu.one(SELECTOR_SEARCH_CONTAINER);
var listNode = menu.one('ul');
var ariaListNodeAttr = 'menu';
var ariaLinksAttr = 'menuitem';
if (searchContainer) {
ariaListNodeAttr = 'listbox';
ariaListNodeAttr = 'option';
}
listNode.setAttribute(ARIA_ATTR_ROLE, ariaListNodeAttr);
links.set(ARIA_ATTR_ROLE, ariaLinksAttr);
trigger.attr(
{
'aria-haspopup': true,
role: 'button'
}
);
listNode.setAttribute('aria-labelledby', trigger.guid());
}
};
Menu.handleFocus = function(id) {
var node = A.one(id);
if (node) {
node.delegate('mouseenter', A.rbind(Menu._targetLink, node, 'focus'), SELECTOR_LIST_ITEM);
node.delegate('mouseleave', A.rbind(Menu._targetLink, node, 'blur'), SELECTOR_LIST_ITEM);
}
};
var buffer = [];
Menu.register = function(id) {
var menuNode = document.getElementById(id);
if (menuNode) {
if (!Menu._INSTANCE) {
new Menu();
}
buffer.push(menuNode);
Menu._registerTask();
}
};
Menu._registerTask = A.debounce(
function() {
var instance = Menu._INSTANCE;
if (buffer.length) {
var nodes = A.all(buffer);
nodes.on(EVENT_CLICK, A.bind('_registerMenu', Menu));
buffer.length = 0;
}
},
100
);
Menu._targetLink = function(event, action) {
var anchor = event.currentTarget.one(SELECTOR_ANCHOR);
if (anchor) {
anchor[action]();
}
};
Liferay.provide(
Menu,
'_getFocusManager',
function() {
var instance = Menu._INSTANCE;
var focusManager = instance._focusManager;
if (!focusManager) {
var bodyNode = instance._overlay.bodyNode;
bodyNode.plug(
A.Plugin.NodeFocusManager,
{
circular: true,
descendants: 'li:not(.hide) a,input',
focusClass: 'focus',
keys: {
next: 'down:40',
previous: 'down:38'
}
}
);
bodyNode.on(
'key',
function(event) {
var activeTrigger = instance._activeTrigger;
if (activeTrigger) {
instance._closeActiveMenu();
activeTrigger.focus();
}
},
'down:27,9'
);
focusManager = bodyNode.focusManager;
bodyNode.delegate(
'mouseenter',
function(event) {
if (focusManager.get('focused')) {
focusManager.focus(event.currentTarget.one(SELECTOR_ANCHOR));
}
},
SELECTOR_LIST_ITEM
);
focusManager.after(
'activeDescendantChange',
function(event) {
var descendants = focusManager.get('descendants');
var selectedItem = descendants.item(event.newVal);
bodyNode.one('ul').setAttribute('aria-activedescendant', selectedItem.guid());
}
);
instance._focusManager = focusManager;
}
focusManager.refresh();
},
['node-focusmanager'],
true
);
Liferay.provide(
Menu,
'_getLiveSearch',
function(trigger, menu) {
var instance = Menu._INSTANCE;
var id = menu.guid();
var liveSearch = MAP_LIVE_SEARCH[id];
if (!liveSearch) {
var searchId = A.guid();
var listNode = menu.one('ul');
var searchLabelNode = trigger.one(SELECTOR_ANCHOR) || trigger;
var searchBoxContent = Lang.sub(
TPL_SEARCH_BOX,
{
searchId: searchId,
searchLabeledBy: searchLabelNode.guid(),
searchOwns: listNode.guid()
}
);
var inputSearch = A.Node.create(searchBoxContent);
inputSearch.swallowEvent('click');
menu.prepend(inputSearch);
var options = {
data: function(node) {
return trim(node.one(SELECTOR_TEXT).text());
},
input: '#' + searchId,
nodes: '#' + listNode.guid() + ' > li'
};
liveSearch = new A.LiveSearch(options);
var bodyNode = instance._overlay.bodyNode;
liveSearch.after(
'search',
function(event) {
var focusManager = bodyNode.focusManager;
if (focusManager) {
focusManager.refresh();
}
var visibleItems = listNode.all('li:not([hidden])');
listNode.toggle(!!visibleItems.size());
}
);
MAP_LIVE_SEARCH[id] = liveSearch;
}
},
['aui-live-search-deprecated'],
true
);
Liferay.provide(
Menu,
'_registerMenu',
function(event) {
var instance = Menu._INSTANCE;
var handles = instance._handles;
var trigger = event.currentTarget;
var activeTrigger = instance._activeTrigger;
if (activeTrigger) {
if (activeTrigger != trigger) {
activeTrigger.removeClass(CSS_BTN_PRIMARY);
activeTrigger.get(PARENT_NODE).removeClass(CSS_OPEN);
}
else {
instance._closeActiveMenu();
return;
}
}
if (!trigger.hasClass('disabled')) {
var menu = instance._getMenu(trigger);
instance._activeMenu = menu;
instance._activeTrigger = trigger;
if (!handles.length) {
var listContainer = trigger.getData('menuListContainer');
handles.push(
A.getWin().on('resize', A.debounce(instance._positionActiveMenu, 200, instance)),
A.getDoc().on(EVENT_CLICK, instance._closeActiveMenu, instance),
listContainer.on('touchendoutside', instance._closeActiveMenu, instance)
);
var DDM = A.DD && A.DD.DDM;
if (DDM) {
handles.push(DDM.on('ddm:start', instance._closeActiveMenu, instance));
}
}
instance._positionActiveMenu();
event.halt();
}
},
['aui-widget-cssclass', 'event-outside', 'event-touch', 'widget', 'widget-modality', 'widget-position', 'widget-position-align', 'widget-position-constrain', 'widget-stack', 'widget-stdmod']
);
Liferay.Menu = Menu;
},
'',
{
requires: ['array-invoke', 'aui-debounce', 'aui-node', 'portal-available-languages']
}
);
AUI.add(
'liferay-notice',
function(A) {
var ADOM = A.DOM;
var ANode = A.Node;
var Do = A.Do;
var Lang = A.Lang;
var CSS_ALERTS = 'has-alerts';
var STR_CLICK = 'click';
var STR_EMPTY = '';
var STR_HIDE = 'hide';
var STR_PX = 'px';
var STR_SHOW = 'show';
/**
* @deprecated
*
* OPTIONS
*
* Required
* content {string}: The content of the toolbar.
*
* Optional
* animationConfig {Object}: The Transition config, defaults to {easing: 'ease-out', duration: 2, top: '50px'}. If 'left' property is not specified, it will be automatically calculated.
* closeText {string}: Use for the "close" button. Set to false to not have a close button. If set to false but in the provided markup (via content property) there is an element with class "close", a click listener on this element will be added. As result, the notice will be closed.
* noticeClass {string}: A class to add to the notice toolbar.
* timeout {Number}: The timeout in milliseconds, after it the notice will be automatically closed. Set it to -1, or do not add this property to disable this functionality.
* toggleText {object}: The text to use for the "hide" and "show" button. Set to false to not have a hide button.
* type {String}: One of 'warning' or 'notice'. If not set, default notice type will be 'notice'
* useAnimation {boolean}: To animate show/hide of the notice, defaults to true. If useAnimation is set to true, but there is no timeout, 5000 will be used as timeout.
*
* Callbacks
* onClose {function}: Called when the toolbar is closed.
*/
var Notice = function(options) {
var instance = this;
options = options || {};
instance._closeText = options.closeText;
instance._node = options.node;
instance._noticeType = options.type || 'notice';
instance._noticeClass = 'alert-block';
instance._onClose = options.onClose;
instance._useCloseButton = true;
if (options.useAnimation) {
instance._noticeClass += ' popup-alert-notice';
if (!Lang.isNumber(options.timeout)) {
options.timeout = 5000;
}
}
instance._animationConfig = options.animationConfig || {
duration: 2,
easing: 'ease-out',
top: '50px'
};
instance._useAnimation = options.useAnimation;
instance._timeout = options.timeout;
instance._body = A.getBody();
instance._useToggleButton = false;
instance._hideText = STR_EMPTY;
instance._showText = STR_EMPTY;
if (options.toggleText !== false) {
instance.toggleText = A.mix(
options.toggleText,
{
hide: null,
show: null
}
);
instance._useToggleButton = true;
}
if (instance._noticeType == 'warning') {
instance._noticeClass = 'alert-error popup-alert-warning';
}
if (options.noticeClass) {
instance._noticeClass += ' ' + options.noticeClass;
}
instance._content = options.content || STR_EMPTY;
instance._createHTML();
return instance._notice;
};
Notice.prototype = {
close: function() {
var instance = this;
var notice = instance._notice;
notice.hide();
instance._body.removeClass(CSS_ALERTS);
if (instance._onClose) {
instance._onClose();
}
},
setClosing: function() {
var instance = this;
var alerts = A.all('.popup-alert-notice, .popup-alert-warning');
if (alerts.size()) {
instance._useCloseButton = true;
if (!instance._body) {
instance._body = A.getBody();
}
instance._body.addClass(CSS_ALERTS);
alerts.each(instance._addCloseButton, instance);
}
},
_afterNoticeShow: function(event) {
var instance = this;
instance._preventHide();
var notice = instance._notice;
if (instance._useAnimation) {
var animationConfig = instance._animationConfig;
var left = animationConfig.left;
var top = animationConfig.top;
if (!left) {
var noticeRegion = ADOM.region(ANode.getDOMNode(notice));
left = (ADOM.winWidth() / 2) - (noticeRegion.width / 2);
top = -noticeRegion.height;
animationConfig.left = left + STR_PX;
}
notice.setXY([left, top]);
notice.transition(
instance._animationConfig,
function() {
instance._hideHandle = A.later(instance._timeout, notice, STR_HIDE);
}
);
}
else {
if (instance._timeout > -1) {
instance._hideHandle = A.later(instance._timeout, notice, STR_HIDE);
}
}
Liferay.fire(
'noticeShow',
{
notice: instance,
useAnimation: instance._useAnimation
}
);
},
_beforeNoticeHide: function(event) {
var instance = this;
var returnVal;
if (instance._useAnimation) {
var animationConfig = A.merge(
instance._animationConfig,
{
top: -instance._notice.get('offsetHeight') + STR_PX
}
);
instance._notice.transition(
animationConfig,
function() {
instance._notice.toggle(false);
}
);
returnVal = new Do.Halt(null);
}
Liferay.fire(
'noticeHide',
{
notice: instance,
useAnimation: instance._useAnimation
}
);
return returnVal;
},
_beforeNoticeShow: function(event) {
var instance = this;
instance._notice.toggle(true);
},
_createHTML: function() {
var instance = this;
var content = instance._content;
var node = A.one(instance._node);
var notice = node || ANode.create('
');
if (content) {
notice.html(content);
}
A.Array.each(
instance._noticeClass.split(' '),
function(item, index, collection) {
notice.addClass(item);
}
)
instance._addCloseButton(notice);
instance._addToggleButton(notice);
if (!node || (node && !node.inDoc())) {
instance._body.prepend(notice);
}
instance._body.addClass(CSS_ALERTS);
Do.before(instance._beforeNoticeHide, notice, STR_HIDE, instance);
Do.before(instance._beforeNoticeShow, notice, STR_SHOW, instance);
Do.after(instance._afterNoticeShow, notice, STR_SHOW, instance);
instance._notice = notice;
},
_addCloseButton: function(notice) {
var instance = this;
var closeButton;
if (instance._closeText !== false) {
instance._closeText = instance._closeText || '\u005a\u0061\u0076\u0159\u00ed\u0074';
}
else {
instance._useCloseButton = false;
instance._closeText = STR_EMPTY;
}
if (instance._useCloseButton) {
var html = '';
closeButton = notice.append(html);
}
else {
closeButton = notice.one('.close');
}
if (closeButton) {
closeButton.on(STR_CLICK, instance.close, instance);
}
},
_addToggleButton: function(notice) {
var instance = this;
if (instance._useToggleButton) {
instance._hideText = instance._toggleText.hide || Liferay.Language.get(STR_HIDE);
instance._showText = instance._toggleText.show || Liferay.Language.get(STR_SHOW);
var toggleButton = ANode.create('' + instance._hideText + ' ');
var toggleSpan = toggleButton.one('span');
var visible = 0;
var showText = instance._showText;
var hideText = instance._hideText;
toggleButton.on(
STR_CLICK,
function(event) {
var text = showText;
if (visible === 0) {
text = hideText;
visible = 1;
}
else {
visible = 0;
}
notice.toggle();
toggleSpan.text(text);
}
);
notice.append(toggleButton);
}
},
_preventHide: function() {
var instance = this;
if (instance._hideHandle) {
instance._hideHandle.cancel();
instance._hideHandle = null;
}
}
};
Liferay.Notice = Notice;
},
'',
{
requires: ['aui-base']
}
);
AUI.add(
'liferay-poller',
function(A) {
var AObject = A.Object;
var JSON = A.JSON;
var Util = Liferay.Util;
var owns = AObject.owns;
var _browserKey = Util.randomInt();
var _enabled = false;
var _supportsComet = false;
var _encryptedUserId = null;
var _delays = [1, 2, 3, 4, 5, 7, 10];
var _delayIndex = 0;
var _delayAccessCount = 0;
var _getEncryptedUserId = function() {
return _encryptedUserId;
};
var _frozen = false;
var _locked = false;
var _maxDelay = _delays.length - 1;
var _portletIdsMap = {};
var _metaData = {
browserKey: _browserKey,
companyId: themeDisplay.getCompanyId(),
portletIdsMap: _portletIdsMap,
startPolling: true
};
var _customDelay = null;
var _portlets = {};
var _requestDelay = _delays[0];
var _sendQueue = [];
var _suspended = false;
var _timerId = null;
var _url = themeDisplay.getPathContext() + '/poller';
var _receiveChannel = _url + '/receive';
var _sendChannel = _url + '/send';
var _closeCurlyBrace = '}';
var _escapedCloseCurlyBrace = '[$CLOSE_CURLY_BRACE$]';
var _openCurlyBrace = '{';
var _escapedOpenCurlyBrace = '[$OPEN_CURLY_BRACE$]';
var _cancelRequestTimer = function() {
clearTimeout(_timerId);
_timerId = null;
};
var _createRequestTimer = function() {
_cancelRequestTimer();
if (_enabled) {
if (Poller.isSupportsComet()) {
_receive();
}
else {
_timerId = setTimeout(_receive, Poller.getDelay());
}
}
};
var _freezeConnection = function() {
_frozen = true;
_cancelRequestTimer();
};
var _getReceiveUrl = function() {
return _receiveChannel;
};
var _getSendUrl = function() {
return _sendChannel;
};
var _processResponse = function(id, obj) {
var response = JSON.parse(obj.responseText);
var send = false;
if (Util.isArray(response)) {
var meta = response.shift();
for (var i = 0, length = response.length; i < length; i++) {
var chunk = response[i].payload;
var chunkData = chunk.data;
var portletId = chunk.portletId;
var portlet = _portlets[portletId];
if (portlet) {
var currentPortletId = _portletIdsMap[portletId];
if (chunkData && currentPortletId) {
chunkData.initialRequest = portlet.initialRequest;
}
portlet.listener.call(portlet.scope || Poller, chunkData, chunk.chunkId);
if (chunkData && chunkData.pollerHintHighConnectivity) {
_requestDelay = _delays[0];
_delayIndex = 0;
}
if (portlet.initialRequest && currentPortletId) {
send = true;
portlet.initialRequest = false;
}
}
}
if ('startPolling' in _metaData) {
delete _metaData.startPolling;
}
if (send) {
_send();
}
if (!meta.suspendPolling) {
_thawConnection();
}
else {
_freezeConnection();
}
}
};
var _receive = function() {
if (!_suspended && !_frozen) {
_metaData.userId = _getEncryptedUserId();
_metaData.timestamp = (new Date()).getTime();
AObject.each(_portlets, _updatePortletIdsMap);
var requestStr = JSON.stringify([_metaData]);
A.io(
_getReceiveUrl(),
{
data: {
pollerRequest: requestStr
},
method: A.config.io.method,
on: {
success: _processResponse
}
}
);
}
};
var _releaseLock = function() {
_locked = false;
};
var _sendComplete = function() {
_releaseLock();
_send();
};
var _send = function() {
if (_enabled && !_locked && _sendQueue.length && !_suspended && !_frozen) {
_locked = true;
var data = _sendQueue.shift();
_metaData.userId = _getEncryptedUserId();
_metaData.timestamp = (new Date()).getTime();
AObject.each(_portlets, _updatePortletIdsMap);
var requestStr = JSON.stringify([_metaData].concat(data));
A.io(
_getSendUrl(),
{
data: {
pollerRequest: requestStr
},
method: A.config.io.method,
on: {
complete: _sendComplete
}
}
);
}
};
var _thawConnection = function() {
_frozen = false;
_createRequestTimer();
};
var _updatePortletIdsMap = function(item, index, collection) {
_portletIdsMap[index] = item.initialRequest;
};
var Poller = {
init: function(options) {
var instance = this;
instance.setEncryptedUserId(options.encryptedUserId);
instance.setSupportsComet(options.supportsComet);
},
url: _url,
addListener: function(key, listener, scope) {
_portlets[key] = {
initialRequest: true,
listener: listener,
scope: scope
};
if (!_enabled) {
_enabled = true;
_receive();
}
},
cancelCustomDelay: function() {
_customDelay = null;
},
getDelay: function() {
if (_customDelay !== null) {
_requestDelay = _customDelay;
}
else if (_delayIndex <= _maxDelay) {
_requestDelay = _delays[_delayIndex];
_delayAccessCount++;
if (_delayAccessCount == 3) {
_delayIndex++;
_delayAccessCount = 0;
}
}
return _requestDelay * 1000;
},
getReceiveUrl: _getReceiveUrl,
getSendUrl: _getSendUrl,
isSupportsComet: function() {
return _supportsComet;
},
processResponse: _processResponse,
removeListener: function(key) {
var instance = this;
if (key in _portlets) {
delete _portlets[key];
}
if (AObject.keys(_portlets).length === 0) {
_enabled = false;
_cancelRequestTimer();
}
},
resume: function() {
_suspended = false;
_createRequestTimer();
},
setCustomDelay: function(delay) {
if (delay === null) {
_customDelay = delay;
}
else {
_customDelay = delay / 1000;
}
},
setDelay: function(delay) {
_requestDelay = delay / 1000;
},
setEncryptedUserId: function(encryptedUserId) {
_encryptedUserId = encryptedUserId;
},
setSupportsComet: function(supportsComet) {
_supportsComet = supportsComet;
},
setUrl: function(url) {
_url = url;
},
submitRequest: function(key, data, chunkId) {
if (!_frozen && (key in _portlets)) {
for (var i in data) {
if (owns(data, i)) {
var content = data[i];
if (content.replace) {
content = content.replace(_openCurlyBrace, _escapedOpenCurlyBrace);
content = content.replace(_closeCurlyBrace, _escapedCloseCurlyBrace);
data[i] = content;
}
}
}
var requestData = {
portletId: key,
data: data
};
if (chunkId) {
requestData.chunkId = chunkId;
}
_sendQueue.push(requestData);
_send();
}
},
suspend: function() {
_cancelRequestTimer();
_suspended = true;
}
};
A.getWin().on(
'focus',
function(event) {
_metaData.startPolling = true;
_thawConnection();
}
);
Liferay.Poller = Poller;
},
'',
{
requires: ['aui-base', 'io', 'json']
}
);
YUI.add('async-queue', function (Y, NAME) {
/**
* AsyncQueue allows you create a chain of function callbacks executed
* via setTimeout (or synchronously) that are guaranteed to run in order.
* Items in the queue can be promoted or removed. Start or resume the
* execution chain with run(). pause() to temporarily delay execution, or
* stop() to halt and clear the queue.
*
* @module async-queue
*/
/**
* A specialized queue class that supports scheduling callbacks to execute
* sequentially, iteratively, even asynchronously.
*
* Callbacks can be function refs or objects with the following keys. Only
* the fn
key is required.
*
*
* fn
-- The callback function
* context
-- The execution context for the callbackFn.
* args
-- Arguments to pass to callbackFn.
* timeout
-- Millisecond delay before executing callbackFn.
* (Applies to each iterative execution of callback)
* iterations
-- Number of times to repeat the callback.
* until
-- Repeat the callback until this function returns
* true. This setting trumps iterations.
* autoContinue
-- Set to false to prevent the AsyncQueue from
* executing the next callback in the Queue after
* the callback completes.
* id
-- Name that can be used to get, promote, get the
* indexOf, or delete this callback.
*
*
* @class AsyncQueue
* @extends EventTarget
* @constructor
* @param callback* {Function|Object} 0..n callbacks to seed the queue
*/
Y.AsyncQueue = function() {
this._init();
this.add.apply(this, arguments);
};
var Queue = Y.AsyncQueue,
EXECUTE = 'execute',
SHIFT = 'shift',
PROMOTE = 'promote',
REMOVE = 'remove',
isObject = Y.Lang.isObject,
isFunction = Y.Lang.isFunction;
/**
* Static default values used to populate callback configuration properties.
* Preconfigured defaults include:
*
*
* autoContinue
: true
* iterations
: 1
* timeout
: 10 (10ms between callbacks)
* until
: (function to run until iterations <= 0)
*
*
* @property defaults
* @type {Object}
* @static
*/
Queue.defaults = Y.mix({
autoContinue : true,
iterations : 1,
timeout : 10,
until : function () {
this.iterations |= 0;
return this.iterations <= 0;
}
}, Y.config.queueDefaults || {});
Y.extend(Queue, Y.EventTarget, {
/**
* Used to indicate the queue is currently executing a callback.
*
* @property _running
* @type {Boolean|Object} true for synchronous callback execution, the
* return handle from Y.later for async callbacks.
* Otherwise false.
* @protected
*/
_running : false,
/**
* Initializes the AsyncQueue instance properties and events.
*
* @method _init
* @protected
*/
_init : function () {
Y.EventTarget.call(this, { prefix: 'queue', emitFacade: true });
this._q = [];
/**
* Callback defaults for this instance. Static defaults that are not
* overridden are also included.
*
* @property defaults
* @type {Object}
*/
this.defaults = {};
this._initEvents();
},
/**
* Initializes the instance events.
*
* @method _initEvents
* @protected
*/
_initEvents : function () {
this.publish({
'execute' : { defaultFn : this._defExecFn, emitFacade: true },
'shift' : { defaultFn : this._defShiftFn, emitFacade: true },
'add' : { defaultFn : this._defAddFn, emitFacade: true },
'promote' : { defaultFn : this._defPromoteFn, emitFacade: true },
'remove' : { defaultFn : this._defRemoveFn, emitFacade: true }
});
},
/**
* Returns the next callback needing execution. If a callback is
* configured to repeat via iterations or until, it will be returned until
* the completion criteria is met.
*
* When the queue is empty, null is returned.
*
* @method next
* @return {Function} the callback to execute
*/
next : function () {
var callback;
while (this._q.length) {
callback = this._q[0] = this._prepare(this._q[0]);
if (callback && callback.until()) {
this.fire(SHIFT, { callback: callback });
callback = null;
} else {
break;
}
}
return callback || null;
},
/**
* Default functionality for the "shift" event. Shifts the
* callback stored in the event object's callback property from
* the queue if it is the first item.
*
* @method _defShiftFn
* @param e {Event} The event object
* @protected
*/
_defShiftFn : function (e) {
if (this.indexOf(e.callback) === 0) {
this._q.shift();
}
},
/**
* Creates a wrapper function to execute the callback using the aggregated
* configuration generated by combining the static AsyncQueue.defaults, the
* instance defaults, and the specified callback settings.
*
* The wrapper function is decorated with the callback configuration as
* properties for runtime modification.
*
* @method _prepare
* @param callback {Object|Function} the raw callback
* @return {Function} a decorated function wrapper to execute the callback
* @protected
*/
_prepare: function (callback) {
if (isFunction(callback) && callback._prepared) {
return callback;
}
var config = Y.merge(
Queue.defaults,
{ context : this, args: [], _prepared: true },
this.defaults,
(isFunction(callback) ? { fn: callback } : callback)),
wrapper = Y.bind(function () {
if (!wrapper._running) {
wrapper.iterations--;
}
if (isFunction(wrapper.fn)) {
wrapper.fn.apply(wrapper.context || Y,
Y.Array(wrapper.args));
}
}, this);
return Y.mix(wrapper, config);
},
/**
* Sets the queue in motion. All queued callbacks will be executed in
* order unless pause() or stop() is called or if one of the callbacks is
* configured with autoContinue: false.
*
* @method run
* @return {AsyncQueue} the AsyncQueue instance
* @chainable
*/
run : function () {
var callback,
cont = true;
if (this._executing) {
this._running = true;
return this;
}
for (callback = this.next();
callback && !this.isRunning();
callback = this.next())
{
cont = (callback.timeout < 0) ?
this._execute(callback) :
this._schedule(callback);
// Break to avoid an extra call to next (final-expression of the
// 'for' loop), because the until function of the next callback
// in the queue may return a wrong result if it depends on the
// not-yet-finished work of the previous callback.
if (!cont) {
break;
}
}
if (!callback) {
/**
* Event fired after the last queued callback is executed.
* @event complete
*/
this.fire('complete');
}
return this;
},
/**
* Handles the execution of callbacks. Returns a boolean indicating
* whether it is appropriate to continue running.
*
* @method _execute
* @param callback {Object} the callback object to execute
* @return {Boolean} whether the run loop should continue
* @protected
*/
_execute : function (callback) {
this._running = callback._running = true;
this._executing = callback;
callback.iterations--;
this.fire(EXECUTE, { callback: callback });
var cont = this._running && callback.autoContinue;
this._running = callback._running = false;
this._executing = false;
return cont;
},
/**
* Schedules the execution of asynchronous callbacks.
*
* @method _schedule
* @param callback {Object} the callback object to execute
* @return {Boolean} whether the run loop should continue
* @protected
*/
_schedule : function (callback) {
this._running = Y.later(callback.timeout, this, function () {
if (this._execute(callback)) {
this.run();
}
});
return false;
},
/**
* Determines if the queue is waiting for a callback to complete execution.
*
* @method isRunning
* @return {Boolean} true if queue is waiting for a
* from any initiated transactions
*/
isRunning : function () {
return !!this._running;
},
/**
* Default functionality for the "execute" event. Executes the
* callback function
*
* @method _defExecFn
* @param e {Event} the event object
* @protected
*/
_defExecFn : function (e) {
e.callback();
},
/**
* Add any number of callbacks to the end of the queue. Callbacks may be
* provided as functions or objects.
*
* @method add
* @param callback* {Function|Object} 0..n callbacks
* @return {AsyncQueue} the AsyncQueue instance
* @chainable
*/
add : function () {
this.fire('add', { callbacks: Y.Array(arguments,0,true) });
return this;
},
/**
* Default functionality for the "add" event. Adds the callbacks
* in the event facade to the queue. Callbacks successfully added to the
* queue are present in the event's added
property in the
* after phase.
*
* @method _defAddFn
* @param e {Event} the event object
* @protected
*/
_defAddFn : function(e) {
var _q = this._q,
added = [];
Y.Array.each(e.callbacks, function (c) {
if (isObject(c)) {
_q.push(c);
added.push(c);
}
});
e.added = added;
},
/**
* Pause the execution of the queue after the execution of the current
* callback completes. If called from code outside of a queued callback,
* clears the timeout for the pending callback. Paused queue can be
* restarted with q.run()
*
* @method pause
* @return {AsyncQueue} the AsyncQueue instance
* @chainable
*/
pause: function () {
if (this._running && isObject(this._running)) {
this._running.cancel();
}
this._running = false;
return this;
},
/**
* Stop and clear the queue after the current execution of the
* current callback completes.
*
* @method stop
* @return {AsyncQueue} the AsyncQueue instance
* @chainable
*/
stop : function () {
this._q = [];
if (this._running && isObject(this._running)) {
this._running.cancel();
this._running = false;
}
// otherwise don't systematically set this._running to false, because if
// stop has been called from inside a queued callback, the _execute method
// currenty running needs to call run() one more time for the 'complete'
// event to be fired.
return this;
},
/**
* Returns the current index of a callback. Pass in either the id or
* callback function from getCallback.
*
* @method indexOf
* @param callback {String|Function} the callback or its specified id
* @return {Number} index of the callback or -1 if not found
*/
indexOf : function (callback) {
var i = 0, len = this._q.length, c;
for (; i < len; ++i) {
c = this._q[i];
if (c === callback || c.id === callback) {
return i;
}
}
return -1;
},
/**
* Retrieve a callback by its id. Useful to modify the configuration
* while the queue is running.
*
* @method getCallback
* @param id {String} the id assigned to the callback
* @return {Object} the callback object
*/
getCallback : function (id) {
var i = this.indexOf(id);
return (i > -1) ? this._q[i] : null;
},
/**
* Promotes the named callback to the top of the queue. If a callback is
* currently executing or looping (via until or iterations), the promotion
* is scheduled to occur after the current callback has completed.
*
* @method promote
* @param callback {String|Object} the callback object or a callback's id
* @return {AsyncQueue} the AsyncQueue instance
* @chainable
*/
promote : function (callback) {
var payload = { callback : callback },e;
if (this.isRunning()) {
e = this.after(SHIFT, function () {
this.fire(PROMOTE, payload);
e.detach();
}, this);
} else {
this.fire(PROMOTE, payload);
}
return this;
},
/**
* Default functionality for the "promote" event. Promotes the
* named callback to the head of the queue.
*
* The event object will contain a property "callback", which
* holds the id of a callback or the callback object itself.
*
* @method _defPromoteFn
* @param e {Event} the custom event
* @protected
*/
_defPromoteFn : function (e) {
var i = this.indexOf(e.callback),
promoted = (i > -1) ? this._q.splice(i,1)[0] : null;
e.promoted = promoted;
if (promoted) {
this._q.unshift(promoted);
}
},
/**
* Removes the callback from the queue. If the queue is active, the
* removal is scheduled to occur after the current callback has completed.
*
* @method remove
* @param callback {String|Object} the callback object or a callback's id
* @return {AsyncQueue} the AsyncQueue instance
* @chainable
*/
remove : function (callback) {
var payload = { callback : callback },e;
// Can't return the removed callback because of the deferral until
// current callback is complete
if (this.isRunning()) {
e = this.after(SHIFT, function () {
this.fire(REMOVE, payload);
e.detach();
},this);
} else {
this.fire(REMOVE, payload);
}
return this;
},
/**
* Default functionality for the "remove" event. Removes the
* callback from the queue.
*
* The event object will contain a property "callback", which
* holds the id of a callback or the callback object itself.
*
* @method _defRemoveFn
* @param e {Event} the custom event
* @protected
*/
_defRemoveFn : function (e) {
var i = this.indexOf(e.callback);
e.removed = (i > -1) ? this._q.splice(i,1)[0] : null;
},
/**
* Returns the number of callbacks in the queue.
*
* @method size
* @return {Number}
*/
size : function () {
// next() flushes callbacks that have met their until() criteria and
// therefore shouldn't count since they wouldn't execute anyway.
if (!this.isRunning()) {
this.next();
}
return this._q.length;
}
});
}, 'patched-v3.11.0', {"requires": ["event-custom"]});
YUI.add('base-build', function (Y, NAME) {
/**
* The base-build submodule provides Base.build functionality, which
* can be used to create custom classes, by aggregating extensions onto
* a main class.
*
* @module base
* @submodule base-build
* @for Base
*/
var BaseCore = Y.BaseCore,
Base = Y.Base,
L = Y.Lang,
INITIALIZER = "initializer",
DESTRUCTOR = "destructor",
AGGREGATES = ["_PLUG", "_UNPLUG"],
build;
// Utility function used in `_buildCfg` to aggregate array values into a new
// array from the sender constructor to the receiver constructor.
function arrayAggregator(prop, r, s) {
if (s[prop]) {
r[prop] = (r[prop] || []).concat(s[prop]);
}
}
// Utility function used in `_buildCfg` to aggregate `_ATTR_CFG` array
// values from the sender constructor into a new array on receiver's
// constructor, and clear the cached hash.
function attrCfgAggregator(prop, r, s) {
if (s._ATTR_CFG) {
// Clear cached hash.
r._ATTR_CFG_HASH = null;
arrayAggregator.apply(null, arguments);
}
}
// Utility function used in `_buildCfg` to aggregate ATTRS configs from one
// the sender constructor to the receiver constructor.
function attrsAggregator(prop, r, s) {
BaseCore.modifyAttrs(r, s.ATTRS);
}
Base._build = function(name, main, extensions, px, sx, cfg) {
var build = Base._build,
builtClass = build._ctor(main, cfg),
buildCfg = build._cfg(main, cfg, extensions),
_mixCust = build._mixCust,
dynamic = builtClass._yuibuild.dynamic,
i, l, extClass, extProto,
initializer,
destructor;
// Augment/Aggregate
for (i = 0, l = extensions.length; i < l; i++) {
extClass = extensions[i];
extProto = extClass.prototype;
initializer = extProto[INITIALIZER];
destructor = extProto[DESTRUCTOR];
delete extProto[INITIALIZER];
delete extProto[DESTRUCTOR];
// Prototype, old non-displacing augment
Y.mix(builtClass, extClass, true, null, 1);
// Custom Statics
_mixCust(builtClass, extClass, buildCfg);
if (initializer) {
extProto[INITIALIZER] = initializer;
}
if (destructor) {
extProto[DESTRUCTOR] = destructor;
}
builtClass._yuibuild.exts.push(extClass);
}
if (px) {
Y.mix(builtClass.prototype, px, true);
}
if (sx) {
Y.mix(builtClass, build._clean(sx, buildCfg), true);
_mixCust(builtClass, sx, buildCfg);
}
builtClass.prototype.hasImpl = build._impl;
if (dynamic) {
builtClass.NAME = name;
builtClass.prototype.constructor = builtClass;
// Carry along the reference to `modifyAttrs()` from `main`.
builtClass.modifyAttrs = main.modifyAttrs;
}
return builtClass;
};
build = Base._build;
Y.mix(build, {
_mixCust: function(r, s, cfg) {
var aggregates,
custom,
statics,
aggr,
l,
i;
if (cfg) {
aggregates = cfg.aggregates;
custom = cfg.custom;
statics = cfg.statics;
}
if (statics) {
Y.mix(r, s, true, statics);
}
if (aggregates) {
for (i = 0, l = aggregates.length; i < l; i++) {
aggr = aggregates[i];
if (!r.hasOwnProperty(aggr) && s.hasOwnProperty(aggr)) {
r[aggr] = L.isArray(s[aggr]) ? [] : {};
}
Y.aggregate(r, s, true, [aggr]);
}
}
if (custom) {
for (i in custom) {
if (custom.hasOwnProperty(i)) {
custom[i](i, r, s);
}
}
}
},
_tmpl: function(main) {
function BuiltClass() {
BuiltClass.superclass.constructor.apply(this, arguments);
}
Y.extend(BuiltClass, main);
return BuiltClass;
},
_impl : function(extClass) {
var classes = this._getClasses(), i, l, cls, exts, ll, j;
for (i = 0, l = classes.length; i < l; i++) {
cls = classes[i];
if (cls._yuibuild) {
exts = cls._yuibuild.exts;
ll = exts.length;
for (j = 0; j < ll; j++) {
if (exts[j] === extClass) {
return true;
}
}
}
}
return false;
},
_ctor : function(main, cfg) {
var dynamic = (cfg && false === cfg.dynamic) ? false : true,
builtClass = (dynamic) ? build._tmpl(main) : main,
buildCfg = builtClass._yuibuild;
if (!buildCfg) {
buildCfg = builtClass._yuibuild = {};
}
buildCfg.id = buildCfg.id || null;
buildCfg.exts = buildCfg.exts || [];
buildCfg.dynamic = dynamic;
return builtClass;
},
_cfg : function(main, cfg, exts) {
var aggr = [],
cust = {},
statics = [],
buildCfg,
cfgAggr = (cfg && cfg.aggregates),
cfgCustBuild = (cfg && cfg.custom),
cfgStatics = (cfg && cfg.statics),
c = main,
i,
l;
// Prototype Chain
while (c && c.prototype) {
buildCfg = c._buildCfg;
if (buildCfg) {
if (buildCfg.aggregates) {
aggr = aggr.concat(buildCfg.aggregates);
}
if (buildCfg.custom) {
Y.mix(cust, buildCfg.custom, true);
}
if (buildCfg.statics) {
statics = statics.concat(buildCfg.statics);
}
}
c = c.superclass ? c.superclass.constructor : null;
}
// Exts
if (exts) {
for (i = 0, l = exts.length; i < l; i++) {
c = exts[i];
buildCfg = c._buildCfg;
if (buildCfg) {
if (buildCfg.aggregates) {
aggr = aggr.concat(buildCfg.aggregates);
}
if (buildCfg.custom) {
Y.mix(cust, buildCfg.custom, true);
}
if (buildCfg.statics) {
statics = statics.concat(buildCfg.statics);
}
}
}
}
if (cfgAggr) {
aggr = aggr.concat(cfgAggr);
}
if (cfgCustBuild) {
Y.mix(cust, cfg.cfgBuild, true);
}
if (cfgStatics) {
statics = statics.concat(cfgStatics);
}
return {
aggregates: aggr,
custom: cust,
statics: statics
};
},
_clean : function(sx, cfg) {
var prop, i, l, sxclone = Y.merge(sx),
aggregates = cfg.aggregates,
custom = cfg.custom;
for (prop in custom) {
if (sxclone.hasOwnProperty(prop)) {
delete sxclone[prop];
}
}
for (i = 0, l = aggregates.length; i < l; i++) {
prop = aggregates[i];
if (sxclone.hasOwnProperty(prop)) {
delete sxclone[prop];
}
}
return sxclone;
}
});
/**
*
* Builds a custom constructor function (class) from the
* main function, and array of extension functions (classes)
* provided. The NAME field for the constructor function is
* defined by the first argument passed in.
*
*
* The cfg object supports the following properties
*
*
* dynamic <boolean>
*
* If true (default), a completely new class
* is created which extends the main class, and acts as the
* host on which the extension classes are augmented.
* If false, the extensions classes are augmented directly to
* the main class, modifying the main class' prototype.
*
* aggregates <String[]>
* An array of static property names, which will get aggregated
* on to the built class, in addition to the default properties build
* will always aggregate as defined by the main class' static _buildCfg
* property.
*
*
*
* @method build
* @deprecated Use the more convenient Base.create and Base.mix methods instead
* @static
* @param {Function} name The name of the new class. Used to define the NAME property for the new class.
* @param {Function} main The main class on which to base the built class
* @param {Function[]} extensions The set of extension classes which will be
* augmented/aggregated to the built class.
* @param {Object} cfg Optional. Build configuration for the class (see description).
* @return {Function} A custom class, created from the provided main and extension classes
*/
Base.build = function(name, main, extensions, cfg) {
return build(name, main, extensions, null, null, cfg);
};
/**
* Creates a new class (constructor function) which extends the base class passed in as the second argument,
* and mixes in the array of extensions provided.
*
* Prototype properties or methods can be added to the new class, using the px argument (similar to Y.extend).
*
* Static properties or methods can be added to the new class, using the sx argument (similar to Y.extend).
*
* **NOTE FOR COMPONENT DEVELOPERS**: Both the `base` class, and `extensions` can define static a `_buildCfg`
* property, which acts as class creation meta-data, and drives how special static properties from the base
* class, or extensions should be copied, aggregated or (custom) mixed into the newly created class.
*
* The `_buildCfg` property is a hash with 3 supported properties: `statics`, `aggregates` and `custom`, e.g:
*
* // If the Base/Main class is the thing introducing the property:
*
* MyBaseClass._buildCfg = {
*
* // Static properties/methods to copy (Alias) to the built class.
* statics: ["CopyThisMethod", "CopyThisProperty"],
*
* // Static props to aggregate onto the built class.
* aggregates: ["AggregateThisProperty"],
*
* // Static properties which need custom handling (e.g. deep merge etc.)
* custom: {
* "CustomProperty" : function(property, Receiver, Supplier) {
* ...
* var triggers = Receiver.CustomProperty.triggers;
* Receiver.CustomProperty.triggers = triggers.concat(Supplier.CustomProperty.triggers);
* ...
* }
* }
* };
*
* MyBaseClass.CopyThisMethod = function() {...};
* MyBaseClass.CopyThisProperty = "foo";
* MyBaseClass.AggregateThisProperty = {...};
* MyBaseClass.CustomProperty = {
* triggers: [...]
* }
*
* // Or, if the Extension is the thing introducing the property:
*
* MyExtension._buildCfg = {
* statics : ...
* aggregates : ...
* custom : ...
* }
*
* This way, when users pass your base or extension class to `Y.Base.create` or `Y.Base.mix`, they don't need to
* know which properties need special handling. `Y.Base` has a buildCfg which defines `ATTRS` for custom mix handling
* (to protect the static config objects), and `Y.Widget` has a buildCfg which specifies `HTML_PARSER` for
* straight up aggregation.
*
* @method create
* @static
* @param {String} name The name of the newly created class. Used to define the NAME property for the new class.
* @param {Function} main The base class which the new class should extend.
* This class needs to be Base or a class derived from base (e.g. Widget).
* @param {Function[]} extensions The list of extensions which will be mixed into the built class.
* @param {Object} px The set of prototype properties/methods to add to the built class.
* @param {Object} sx The set of static properties/methods to add to the built class.
* @return {Function} The newly created class.
*/
Base.create = function(name, base, extensions, px, sx) {
return build(name, base, extensions, px, sx);
};
/**
* Mixes in a list of extensions to an existing class.
* @method mix
* @static
* @param {Function} main The existing class into which the extensions should be mixed.
* The class needs to be Base or a class derived from Base (e.g. Widget)
* @param {Function[]} extensions The set of extension classes which will mixed into the existing main class.
* @return {Function} The modified main class, with extensions mixed in.
*/
Base.mix = function(main, extensions) {
if (main._CACHED_CLASS_DATA) {
main._CACHED_CLASS_DATA = null;
}
return build(null, main, extensions, null, null, {dynamic:false});
};
/**
* The build configuration for the Base class.
*
* Defines the static fields which need to be aggregated when the Base class
* is used as the main class passed to the
* Base.build method.
*
* @property _buildCfg
* @type Object
* @static
* @final
* @private
*/
BaseCore._buildCfg = {
aggregates: AGGREGATES.concat(),
custom: {
ATTRS : attrsAggregator,
_ATTR_CFG : attrCfgAggregator,
_NON_ATTRS_CFG: arrayAggregator
}
};
// Makes sure Base and BaseCore use separate `_buildCfg` objects.
Base._buildCfg = {
aggregates: AGGREGATES.concat(),
custom: {
ATTRS : attrsAggregator,
_ATTR_CFG : attrCfgAggregator,
_NON_ATTRS_CFG: arrayAggregator
}
};
}, 'patched-v3.11.0', {"requires": ["base-base"]});
YUI.add('cookie', function (Y, NAME) {
/**
* Utilities for cookie management
* @module cookie
*/
//shortcuts
var L = Y.Lang,
O = Y.Object,
NULL = null,
//shortcuts to functions
isString = L.isString,
isObject = L.isObject,
isUndefined = L.isUndefined,
isFunction = L.isFunction,
encode = encodeURIComponent,
decode = decodeURIComponent,
//shortcut to document
doc = Y.config.doc;
/*
* Throws an error message.
*/
function error(message){
throw new TypeError(message);
}
/*
* Checks the validity of a cookie name.
*/
function validateCookieName(name){
if (!isString(name) || name === ""){
error("Cookie name must be a non-empty string.");
}
}
/*
* Checks the validity of a subcookie name.
*/
function validateSubcookieName(subName){
if (!isString(subName) || subName === ""){
error("Subcookie name must be a non-empty string.");
}
}
/**
* Cookie utility.
* @class Cookie
* @static
*/
Y.Cookie = {
//-------------------------------------------------------------------------
// Private Methods
//-------------------------------------------------------------------------
/**
* Creates a cookie string that can be assigned into document.cookie.
* @param {String} name The name of the cookie.
* @param {String} value The value of the cookie.
* @param {Boolean} encodeValue True to encode the value, false to leave as-is.
* @param {Object} options (Optional) Options for the cookie.
* @return {String} The formatted cookie string.
* @method _createCookieString
* @private
* @static
*/
_createCookieString : function (name /*:String*/, value /*:Variant*/, encodeValue /*:Boolean*/, options /*:Object*/) /*:String*/ {
options = options || {};
var text /*:String*/ = encode(name) + "=" + (encodeValue ? encode(value) : value),
expires = options.expires,
path = options.path,
domain = options.domain;
if (isObject(options)){
//expiration date
if (expires instanceof Date){
text += "; expires=" + expires.toUTCString();
}
//path
if (isString(path) && path !== ""){
text += "; path=" + path;
}
//domain
if (isString(domain) && domain !== ""){
text += "; domain=" + domain;
}
//secure
if (options.secure === true){
text += "; secure";
}
}
return text;
},
/**
* Formats a cookie value for an object containing multiple values.
* @param {Object} hash An object of key-value pairs to create a string for.
* @return {String} A string suitable for use as a cookie value.
* @method _createCookieHashString
* @private
* @static
*/
_createCookieHashString : function (hash /*:Object*/) /*:String*/ {
if (!isObject(hash)){
error("Cookie._createCookieHashString(): Argument must be an object.");
}
var text /*:Array*/ = [];
O.each(hash, function(value, key){
if (!isFunction(value) && !isUndefined(value)){
text.push(encode(key) + "=" + encode(String(value)));
}
});
return text.join("&");
},
/**
* Parses a cookie hash string into an object.
* @param {String} text The cookie hash string to parse (format: n1=v1&n2=v2).
* @return {Object} An object containing entries for each cookie value.
* @method _parseCookieHash
* @private
* @static
*/
_parseCookieHash : function (text) {
var hashParts = text.split("&"),
hashPart = NULL,
hash = {};
if (text.length){
for (var i=0, len=hashParts.length; i < len; i++){
hashPart = hashParts[i].split("=");
hash[decode(hashPart[0])] = decode(hashPart[1]);
}
}
return hash;
},
/**
* Parses a cookie string into an object representing all accessible cookies.
* @param {String} text The cookie string to parse.
* @param {Boolean} shouldDecode (Optional) Indicates if the cookie values should be decoded or not. Default is true.
* @param {Object} options (Optional) Contains settings for loading the cookie.
* @return {Object} An object containing entries for each accessible cookie.
* @method _parseCookieString
* @private
* @static
*/
_parseCookieString : function (text /*:String*/, shouldDecode /*:Boolean*/, options /*:Object*/) /*:Object*/ {
var cookies /*:Object*/ = {};
if (isString(text) && text.length > 0) {
var decodeValue = (shouldDecode === false ? function(s){return s;} : decode),
cookieParts = text.split(/;\s/g),
cookieName = NULL,
cookieValue = NULL,
cookieNameValue = NULL;
for (var i=0, len=cookieParts.length; i < len; i++){
//check for normally-formatted cookie (name-value)
cookieNameValue = cookieParts[i].match(/([^=]+)=/i);
if (cookieNameValue instanceof Array){
try {
cookieName = decode(cookieNameValue[1]);
cookieValue = decodeValue(cookieParts[i].substring(cookieNameValue[1].length+1));
} catch (ex){
//intentionally ignore the cookie - the encoding is wrong
}
} else {
//means the cookie does not have an "=", so treat it as a boolean flag
cookieName = decode(cookieParts[i]);
cookieValue = "";
}
// don't overwrite an already loaded cookie if set by option
if (!isUndefined(options) && options.reverseCookieLoading) {
if (isUndefined(cookies[cookieName])) {
cookies[cookieName] = cookieValue;
}
} else {
cookies[cookieName] = cookieValue;
}
}
}
return cookies;
},
/**
* Sets the document object that the cookie utility uses for setting
* cookies. This method is necessary to ensure that the cookie utility
* unit tests can pass even when run on a domain instead of locally.
* This method should not be used otherwise; you should use
* Y.config.doc
to change the document that the cookie
* utility uses for everyday purposes.
* @param {Object} newDoc The object to use as the document.
* @return {void}
* @method _setDoc
* @private
*/
_setDoc: function(newDoc){
doc = newDoc;
},
//-------------------------------------------------------------------------
// Public Methods
//-------------------------------------------------------------------------
/**
* Determines if the cookie with the given name exists. This is useful for
* Boolean cookies (those that do not follow the name=value convention).
* @param {String} name The name of the cookie to check.
* @return {Boolean} True if the cookie exists, false if not.
* @method exists
* @static
*/
exists: function(name) {
validateCookieName(name); //throws error
var cookies = this._parseCookieString(doc.cookie, true);
return cookies.hasOwnProperty(name);
},
/**
* Returns the cookie value for the given name.
* @param {String} name The name of the cookie to retrieve.
* @param {Function|Object} options (Optional) An object containing one or more
* cookie options: raw (true/false), reverseCookieLoading (true/false)
* and converter (a function).
* The converter function is run on the value before returning it. The
* function is not used if the cookie doesn't exist. The function can be
* passed instead of the options object for backwards compatibility. When
* raw is set to true, the cookie value is not URI decoded.
* @return {Variant} If no converter is specified, returns a string or null if
* the cookie doesn't exist. If the converter is specified, returns the value
* returned from the converter or null if the cookie doesn't exist.
* @method get
* @static
*/
get : function (name, options) {
validateCookieName(name); //throws error
var cookies,
cookie,
converter;
//if options is a function, then it's the converter
if (isFunction(options)) {
converter = options;
options = {};
} else if (isObject(options)) {
converter = options.converter;
} else {
options = {};
}
cookies = this._parseCookieString(doc.cookie, !options.raw, options);
cookie = cookies[name];
//should return null, not undefined if the cookie doesn't exist
if (isUndefined(cookie)) {
return NULL;
}
if (!isFunction(converter)){
return cookie;
} else {
return converter(cookie);
}
},
/**
* Returns the value of a subcookie.
* @param {String} name The name of the cookie to retrieve.
* @param {String} subName The name of the subcookie to retrieve.
* @param {Function} converter (Optional) A function to run on the value before returning
* it. The function is not used if the cookie doesn't exist.
* @param {Object} options (Optional) Containing one or more settings for cookie parsing.
* @return {Variant} If the cookie doesn't exist, null is returned. If the subcookie
* doesn't exist, null if also returned. If no converter is specified and the
* subcookie exists, a string is returned. If a converter is specified and the
* subcookie exists, the value returned from the converter is returned.
* @method getSub
* @static
*/
getSub : function (name /*:String*/, subName /*:String*/, converter /*:Function*/, options /*:Object*/) /*:Variant*/ {
var hash /*:Variant*/ = this.getSubs(name, options);
if (hash !== NULL) {
validateSubcookieName(subName); //throws error
if (isUndefined(hash[subName])){
return NULL;
}
if (!isFunction(converter)){
return hash[subName];
} else {
return converter(hash[subName]);
}
} else {
return NULL;
}
},
/**
* Returns an object containing name-value pairs stored in the cookie with the given name.
* @param {String} name The name of the cookie to retrieve.
* @param {Object} options (Optional) Containing one or more settings for cookie parsing.
* @return {Object} An object of name-value pairs if the cookie with the given name
* exists, null if it does not.
* @method getSubs
* @static
*/
getSubs : function (name /*:String*/, options /*:Object*/) {
validateCookieName(name); //throws error
var cookies = this._parseCookieString(doc.cookie, false, options);
if (isString(cookies[name])){
return this._parseCookieHash(cookies[name]);
}
return NULL;
},
/**
* Removes a cookie from the machine by setting its expiration date to
* sometime in the past.
* @param {String} name The name of the cookie to remove.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string),
* and secure (true/false). The expires option will be overwritten
* by the method.
* @return {String} The created cookie string.
* @method remove
* @static
*/
remove : function (name, options) {
validateCookieName(name); //throws error
//set options
options = Y.merge(options || {}, {
expires: new Date(0)
});
//set cookie
return this.set(name, "", options);
},
/**
* Removes a sub cookie with a given name.
* @param {String} name The name of the cookie in which the subcookie exists.
* @param {String} subName The name of the subcookie to remove.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string), expires (a Date object),
* removeIfEmpty (true/false), and secure (true/false). This must be the same
* settings as the original subcookie.
* @return {String} The created cookie string.
* @method removeSub
* @static
*/
removeSub : function(name, subName, options) {
validateCookieName(name); //throws error
validateSubcookieName(subName); //throws error
options = options || {};
//get all subcookies for this cookie
var subs = this.getSubs(name);
//delete the indicated subcookie
if (isObject(subs) && subs.hasOwnProperty(subName)){
delete subs[subName];
if (!options.removeIfEmpty) {
//reset the cookie
return this.setSubs(name, subs, options);
} else {
//reset the cookie if there are subcookies left, else remove
for (var key in subs){
if (subs.hasOwnProperty(key) && !isFunction(subs[key]) && !isUndefined(subs[key])){
return this.setSubs(name, subs, options);
}
}
return this.remove(name, options);
}
} else {
return "";
}
},
/**
* Sets a cookie with a given name and value.
* @param {String} name The name of the cookie to set.
* @param {Variant} value The value to set for the cookie.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string), expires (a Date object),
* secure (true/false), and raw (true/false). Setting raw to true indicates
* that the cookie should not be URI encoded before being set.
* @return {String} The created cookie string.
* @method set
* @static
*/
set : function (name, value, options) {
validateCookieName(name); //throws error
if (isUndefined(value)){
error("Cookie.set(): Value cannot be undefined.");
}
options = options || {};
var text = this._createCookieString(name, value, !options.raw, options);
doc.cookie = text;
return text;
},
/**
* Sets a sub cookie with a given name to a particular value.
* @param {String} name The name of the cookie to set.
* @param {String} subName The name of the subcookie to set.
* @param {Variant} value The value to set.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string), expires (a Date object),
* and secure (true/false).
* @return {String} The created cookie string.
* @method setSub
* @static
*/
setSub : function (name, subName, value, options) {
validateCookieName(name); //throws error
validateSubcookieName(subName); //throws error
if (isUndefined(value)){
error("Cookie.setSub(): Subcookie value cannot be undefined.");
}
var hash = this.getSubs(name);
if (!isObject(hash)){
hash = {};
}
hash[subName] = value;
return this.setSubs(name, hash, options);
},
/**
* Sets a cookie with a given name to contain a hash of name-value pairs.
* @param {String} name The name of the cookie to set.
* @param {Object} value An object containing name-value pairs.
* @param {Object} options (Optional) An object containing one or more
* cookie options: path (a string), domain (a string), expires (a Date object),
* and secure (true/false).
* @return {String} The created cookie string.
* @method setSubs
* @static
*/
setSubs : function (name, value, options) {
validateCookieName(name); //throws error
if (!isObject(value)){
error("Cookie.setSubs(): Cookie value must be an object.");
}
var text /*:String*/ = this._createCookieString(name, this._createCookieHashString(value), false, options);
doc.cookie = text;
return text;
}
};
}, 'patched-v3.11.0', {"requires": ["yui-base"]});
YUI.add('event-touch', function (Y, NAME) {
/**
Adds touch event facade normalization properties (touches, changedTouches, targetTouches etc.) to the DOM event facade. Adds
touch events to the DOM events whitelist.
@example
YUI().use('event-touch', function (Y) {
Y.one('#myDiv').on('touchstart', function(e) {
...
});
});
@module event
@submodule event-touch
*/
var SCALE = "scale",
ROTATION = "rotation",
IDENTIFIER = "identifier",
win = Y.config.win,
GESTURE_MAP = {};
/**
* Adds touch event facade normalization properties to the DOM event facade
*
* @method _touch
* @for DOMEventFacade
* @private
* @param ev {Event} the DOM event
* @param currentTarget {HTMLElement} the element the listener was attached to
* @param wrapper {Event.Custom} the custom event wrapper for this DOM event
*/
Y.DOMEventFacade.prototype._touch = function(e, currentTarget, wrapper) {
var i,l, etCached, et,touchCache;
if (e.touches) {
/**
* Array of individual touch events for touch points that are still in
* contact with the touch surface.
*
* @property touches
* @type {DOMEventFacade[]}
*/
this.touches = [];
touchCache = {};
for (i = 0, l = e.touches.length; i < l; ++i) {
et = e.touches[i];
touchCache[Y.stamp(et)] = this.touches[i] = new Y.DOMEventFacade(et, currentTarget, wrapper);
}
}
if (e.targetTouches) {
/**
* Array of individual touch events still in contact with the touch
* surface and whose `touchstart` event occurred inside the same taregt
* element as the current target element.
*
* @property targetTouches
* @type {DOMEventFacade[]}
*/
this.targetTouches = [];
for (i = 0, l = e.targetTouches.length; i < l; ++i) {
et = e.targetTouches[i];
etCached = touchCache && touchCache[Y.stamp(et, true)];
this.targetTouches[i] = etCached || new Y.DOMEventFacade(et, currentTarget, wrapper);
}
}
if (e.changedTouches) {
/**
An array of event-specific touch events.
For `touchstart`, the touch points that became active with the current
event.
For `touchmove`, the touch points that have changed since the last
event.
For `touchend`, the touch points that have been removed from the touch
surface.
@property changedTouches
@type {DOMEventFacade[]}
**/
this.changedTouches = [];
for (i = 0, l = e.changedTouches.length; i < l; ++i) {
et = e.changedTouches[i];
etCached = touchCache && touchCache[Y.stamp(et, true)];
this.changedTouches[i] = etCached || new Y.DOMEventFacade(et, currentTarget, wrapper);
}
}
if (SCALE in e) {
this[SCALE] = e[SCALE];
}
if (ROTATION in e) {
this[ROTATION] = e[ROTATION];
}
if (IDENTIFIER in e) {
this[IDENTIFIER] = e[IDENTIFIER];
}
};
//Adding MSPointer events to whitelisted DOM Events. MSPointer event payloads
//have the same properties as mouse events.
if (Y.Node.DOM_EVENTS) {
Y.mix(Y.Node.DOM_EVENTS, {
touchstart:1,
touchmove:1,
touchend:1,
touchcancel:1,
gesturestart:1,
gesturechange:1,
gestureend:1,
MSPointerDown:1,
MSPointerUp:1,
MSPointerMove:1,
MSPointerCancel:1,
pointerdown:1,
pointerup:1,
pointermove:1,
pointercancel:1
});
}
//Add properties to Y.EVENT.GESTURE_MAP based on feature detection.
if ((win && ("ontouchstart" in win)) && !(Y.UA.chrome && Y.UA.chrome < 6)) {
GESTURE_MAP.start = ["touchstart", "mousedown"];
GESTURE_MAP.end = ["touchend", "mouseup"];
GESTURE_MAP.move = ["touchmove", "mousemove"];
GESTURE_MAP.cancel = ["touchcancel", "mousecancel"];
}
else if (win && win.PointerEvent) {
GESTURE_MAP.start = "pointerdown";
GESTURE_MAP.end = "pointerup";
GESTURE_MAP.move = "pointermove";
GESTURE_MAP.cancel = "pointercancel";
}
else if (win && ("msPointerEnabled" in win.navigator)) {
GESTURE_MAP.start = "MSPointerDown";
GESTURE_MAP.end = "MSPointerUp";
GESTURE_MAP.move = "MSPointerMove";
GESTURE_MAP.cancel = "MSPointerCancel";
}
else {
GESTURE_MAP.start = "mousedown";
GESTURE_MAP.end = "mouseup";
GESTURE_MAP.move = "mousemove";
GESTURE_MAP.cancel = "mousecancel";
}
/**
* A object literal with keys "start", "end", and "move". The value for each key is a
* string representing the event for that environment. For touch environments, the respective
* values are "touchstart", "touchend" and "touchmove". Mouse and MSPointer environments are also
* supported via feature detection.
*
* @property _GESTURE_MAP
* @type Object
* @static
*/
Y.Event._GESTURE_MAP = GESTURE_MAP;
}, 'patched-v3.11.0', {"requires": ["node-base"]});
YUI.add('overlay', function (Y, NAME) {
/**
* Provides a basic Overlay widget, with Standard Module content support. The Overlay widget
* provides Page XY positioning support, alignment and centering support along with basic
* stackable support (z-index and shimming).
*
* @module overlay
*/
/**
* A basic Overlay Widget, which can be positioned based on Page XY co-ordinates and is stackable (z-index support).
* It also provides alignment and centering support and uses a standard module format for it's content, with header,
* body and footer section support.
*
* @class Overlay
* @constructor
* @extends Widget
* @uses WidgetStdMod
* @uses WidgetPosition
* @uses WidgetStack
* @uses WidgetPositionAlign
* @uses WidgetPositionConstrain
* @param {Object} object The user configuration for the instance.
*/
Y.Overlay = Y.Base.create("overlay", Y.Widget, [Y.WidgetStdMod, Y.WidgetPosition, Y.WidgetStack, Y.WidgetPositionAlign, Y.WidgetPositionConstrain]);
}, 'patched-v3.11.0', {
"requires": [
"widget",
"widget-stdmod",
"widget-position",
"widget-position-align",
"widget-stack",
"widget-position-constrain"
],
"skinnable": true
});
YUI.add('querystring-stringify', function (Y, NAME) {
/**
* Provides Y.QueryString.stringify method for converting objects to Query Strings.
*
* @module querystring
* @submodule querystring-stringify
*/
var QueryString = Y.namespace("QueryString"),
stack = [],
L = Y.Lang;
/**
* Provides Y.QueryString.escape method to be able to override default encoding
* method. This is important in cases where non-standard delimiters are used, if
* the delimiters would not normally be handled properly by the builtin
* (en|de)codeURIComponent functions.
* Default: encodeURIComponent
*
* @method escape
* @for QueryString
* @static
**/
QueryString.escape = encodeURIComponent;
/**
* Converts an arbitrary value to a Query String representation.
*
* Objects with cyclical references will trigger an exception.
*
* @method stringify
* @for QueryString
* @public
* @param obj {Variant} any arbitrary value to convert to query string
* @param cfg {Object} (optional) Configuration object. The three
* supported configurations are:
* sep: When defined, the value will be used as the key-value
* separator. The default value is "&".
* eq: When defined, the value will be used to join the key to
* the value. The default value is "=".
* arrayKey: When set to true, the key of an array will have the
* '[]' notation appended to the key. The default value is false.
*
* @param name {String} (optional) Name of the current key, for handling children recursively.
* @static
*/
QueryString.stringify = function (obj, c, name) {
var begin, end, i, l, n, s,
sep = c && c.sep ? c.sep : "&",
eq = c && c.eq ? c.eq : "=",
aK = c && c.arrayKey ? c.arrayKey : false;
if (L.isNull(obj) || L.isUndefined(obj) || L.isFunction(obj)) {
return name ? QueryString.escape(name) + eq : '';
}
if (L.isBoolean(obj) || Object.prototype.toString.call(obj) === '[object Boolean]') {
obj =+ obj;
}
if (L.isNumber(obj) || L.isString(obj)) {
return QueryString.escape(name) + eq + QueryString.escape(obj);
}
if (L.isArray(obj)) {
s = [];
name = aK ? name + '[]' : name;
l = obj.length;
for (i = 0; i < l; i++) {
s.push( QueryString.stringify(obj[i], c, name) );
}
return s.join(sep);
}
// now we know it's an object.
// Check for cyclical references in nested objects
for (i = stack.length - 1; i >= 0; --i) {
if (stack[i] === obj) {
throw new Error("QueryString.stringify. Cyclical reference");
}
}
stack.push(obj);
s = [];
begin = name ? name + '[' : '';
end = name ? ']' : '';
for (i in obj) {
if (obj.hasOwnProperty(i)) {
n = begin + i + end;
s.push(QueryString.stringify(obj[i], c, n));
}
}
stack.pop();
s = s.join(sep);
if (!s && name) {
return name + "=";
}
return s;
};
}, 'patched-v3.11.0', {"requires": ["yui-base"]});
YUI.add('widget-child', function (Y, NAME) {
/**
* Extension enabling a Widget to be a child of another Widget.
*
* @module widget-child
*/
var Lang = Y.Lang;
/**
* Widget extension providing functionality enabling a Widget to be a
* child of another Widget.
*
* @class WidgetChild
* @param {Object} config User configuration object.
*/
function Child() {
// Widget method overlap
Y.after(this._syncUIChild, this, "syncUI");
Y.after(this._bindUIChild, this, "bindUI");
}
Child.ATTRS = {
/**
* @attribute selected
* @type Number
* @default 0
*
* @description Number indicating if the Widget is selected. Possible
* values are:
*
* 0 (Default) Not selected
* 1 Fully selected
* 2 Partially selected
*
*/
selected: {
value: 0,
validator: Lang.isNumber
},
/**
* @attribute index
* @type Number
* @readOnly
*
* @description Number representing the Widget's ordinal position in its
* parent Widget.
*/
index: {
readOnly: true,
getter: function () {
var parent = this.get("parent"),
index = -1;
if (parent) {
index = parent.indexOf(this);
}
return index;
}
},
/**
* @attribute parent
* @type Widget
* @readOnly
*
* @description Retrieves the parent of the Widget in the object hierarchy.
*/
parent: {
readOnly: true
},
/**
* @attribute depth
* @type Number
* @default -1
* @readOnly
*
* @description Number representing the depth of this Widget relative to
* the root Widget in the object heirarchy.
*/
depth: {
readOnly: true,
getter: function () {
var parent = this.get("parent"),
root = this.get("root"),
depth = -1;
while (parent) {
depth = (depth + 1);
if (parent == root) {
break;
}
parent = parent.get("parent");
}
return depth;
}
},
/**
* @attribute root
* @type Widget
* @readOnly
*
* @description Returns the root Widget in the object hierarchy. If the
* ROOT_TYPE property is set, the search for the root Widget will be
* constrained to parent Widgets of the specified type.
*/
root: {
readOnly: true,
getter: function () {
var getParent = function (child) {
var parent = child.get("parent"),
FnRootType = child.ROOT_TYPE,
criteria = parent;
if (FnRootType) {
criteria = (parent && Y.instanceOf(parent, FnRootType));
}
return (criteria ? getParent(parent) : child);
};
return getParent(this);
}
}
};
Child.prototype = {
/**
* Constructor reference used to determine the root of a Widget-based
* object tree.
*
* Currently used to control the behavior of the root
* attribute so that recursing up the object heirarchy can be constrained
* to a specific type of Widget. Widget authors should set this property
* to the constructor function for a given Widget implementation.
*
*
* @property ROOT_TYPE
* @type Object
*/
ROOT_TYPE: null,
/**
* Returns the node on which to bind delegate listeners.
*
* Override of Widget's implementation of _getUIEventNode() to ensure that
* all event listeners are bound to the Widget's topmost DOM element.
* This ensures that the firing of each type of Widget UI event (click,
* mousedown, etc.) is facilitated by a single, top-level, delegated DOM
* event listener.
*
* @method _getUIEventNode
* @for Widget
* @protected
*/
_getUIEventNode: function () {
var root = this.get("root"),
returnVal;
if (root) {
returnVal = root.get("boundingBox");
}
return returnVal;
},
/**
* @method next
* @description Returns the Widget's next sibling.
* @param {Boolean} circular Boolean indicating if the parent's first child
* should be returned if the child has no next sibling.
* @return {Widget} Widget instance.
*/
next: function (circular) {
var parent = this.get("parent"),
sibling;
if (parent) {
sibling = parent.item((this.get("index")+1));
}
if (!sibling && circular) {
sibling = parent.item(0);
}
return sibling;
},
/**
* @method previous
* @description Returns the Widget's previous sibling.
* @param {Boolean} circular Boolean indicating if the parent's last child
* should be returned if the child has no previous sibling.
* @return {Widget} Widget instance.
*/
previous: function (circular) {
var parent = this.get("parent"),
index = this.get("index"),
sibling;
if (parent && index > 0) {
sibling = parent.item([(index-1)]);
}
if (!sibling && circular) {
sibling = parent.item((parent.size() - 1));
}
return sibling;
},
// Override of Y.WidgetParent.remove()
// Sugar implementation allowing a child to remove itself from its parent.
remove: function (index) {
var parent,
removed;
if (Lang.isNumber(index)) {
removed = Y.WidgetParent.prototype.remove.apply(this, arguments);
}
else {
parent = this.get("parent");
if (parent) {
removed = parent.remove(this.get("index"));
}
}
return removed;
},
/**
* @method isRoot
* @description Determines if the Widget is the root Widget in the
* object hierarchy.
* @return {Boolean} Boolean indicating if Widget is the root Widget in the
* object hierarchy.
*/
isRoot: function () {
return (this == this.get("root"));
},
/**
* @method ancestor
* @description Returns the Widget instance at the specified depth.
* @param {number} depth Number representing the depth of the ancestor.
* @return {Widget} Widget instance.
*/
ancestor: function (depth) {
var root = this.get("root"),
parent;
if (this.get("depth") > depth) {
parent = this.get("parent");
while (parent != root && parent.get("depth") > depth) {
parent = parent.get("parent");
}
}
return parent;
},
/**
* Updates the UI to reflect the selected
attribute value.
*
* @method _uiSetChildSelected
* @protected
* @param {number} selected The selected value to be reflected in the UI.
*/
_uiSetChildSelected: function (selected) {
var box = this.get("boundingBox"),
sClassName = this.getClassName("selected");
if (selected === 0) {
box.removeClass(sClassName);
}
else {
box.addClass(sClassName);
}
},
/**
* Default attribute change listener for the selected
* attribute, responsible for updating the UI, in response to
* attribute changes.
*
* @method _afterChildSelectedChange
* @protected
* @param {EventFacade} event The event facade for the attribute change.
*/
_afterChildSelectedChange: function (event) {
this._uiSetChildSelected(event.newVal);
},
/**
* Synchronizes the UI to match the WidgetChild state.
*
* This method is invoked after bindUI is invoked for the Widget class
* using YUI's aop infrastructure.
*
*
* @method _syncUIChild
* @protected
*/
_syncUIChild: function () {
this._uiSetChildSelected(this.get("selected"));
},
/**
* Binds event listeners responsible for updating the UI state in response
* to WidgetChild related state changes.
*
* This method is invoked after bindUI is invoked for the Widget class
* using YUI's aop infrastructure.
*
* @method _bindUIChild
* @protected
*/
_bindUIChild: function () {
this.after("selectedChange", this._afterChildSelectedChange);
}
};
Y.WidgetChild = Child;
}, 'patched-v3.11.0', {"requires": ["base-build", "widget"]});
YUI.add('widget-position-align', function (Y, NAME) {
/**
Provides extended/advanced XY positioning support for Widgets, through an
extension.
It builds on top of the `widget-position` module, to provide alignment and
centering support. Future releases aim to add constrained and fixed positioning
support.
@module widget-position-align
**/
var Lang = Y.Lang,
ALIGN = 'align',
ALIGN_ON = 'alignOn',
VISIBLE = 'visible',
BOUNDING_BOX = 'boundingBox',
OFFSET_WIDTH = 'offsetWidth',
OFFSET_HEIGHT = 'offsetHeight',
REGION = 'region',
VIEWPORT_REGION = 'viewportRegion';
/**
Widget extension, which can be used to add extended XY positioning support to
the base Widget class, through the `Base.create` method.
**Note:** This extension requires that the `WidgetPosition` extension be added
to the Widget (before `WidgetPositionAlign`, if part of the same extension list
passed to `Base.build`).
@class WidgetPositionAlign
@param {Object} config User configuration object.
@constructor
**/
function PositionAlign (config) {}
PositionAlign.ATTRS = {
/**
The alignment configuration for this widget.
The `align` attribute is used to align a reference point on the widget, with
the reference point on another `Node`, or the viewport. The object which
`align` expects has the following properties:
* __`node`__: The `Node` to which the widget is to be aligned. If set to
`null`, or not provided, the widget is aligned to the viewport.
* __`points`__: A two element Array, defining the two points on the widget
and `Node`/viewport which are to be aligned. The first element is the
point on the widget, and the second element is the point on the
`Node`/viewport. Supported alignment points are defined as static
properties on `WidgetPositionAlign`.
@example Aligns the top-right corner of the widget with the top-left corner
of the viewport:
myWidget.set('align', {
points: [Y.WidgetPositionAlign.TR, Y.WidgetPositionAlign.TL]
});
@attribute align
@type Object
@default null
**/
align: {
value: null
},
/**
A convenience Attribute, which can be used as a shortcut for the `align`
Attribute.
If set to `true`, the widget is centered in the viewport. If set to a `Node`
reference or valid selector String, the widget will be centered within the
`Node`. If set to `false`, no center positioning is applied.
@attribute centered
@type Boolean|Node
@default false
**/
centered: {
setter : '_setAlignCenter',
lazyAdd:false,
value :false
},
/**
An Array of Objects corresponding to the `Node`s and events that will cause
the alignment of this widget to be synced to the DOM.
The `alignOn` Attribute is expected to be an Array of Objects with the
following properties:
* __`eventName`__: The String event name to listen for.
* __`node`__: The optional `Node` that will fire the event, it can be a
`Node` reference or a selector String. This will default to the widget's
`boundingBox`.
@example Sync this widget's alignment on window resize:
myWidget.set('alignOn', [
{
node : Y.one('win'),
eventName: 'resize'
}
]);
@attribute alignOn
@type Array
@default []
**/
alignOn: {
value : [],
validator: Y.Lang.isArray
}
};
/**
Constant used to specify the top-left corner for alignment
@property TL
@type String
@value 'tl'
@static
**/
PositionAlign.TL = 'tl';
/**
Constant used to specify the top-right corner for alignment
@property TR
@type String
@value 'tr'
@static
**/
PositionAlign.TR = 'tr';
/**
Constant used to specify the bottom-left corner for alignment
@property BL
@type String
@value 'bl'
@static
**/
PositionAlign.BL = 'bl';
/**
Constant used to specify the bottom-right corner for alignment
@property BR
@type String
@value 'br'
@static
**/
PositionAlign.BR = 'br';
/**
Constant used to specify the top edge-center point for alignment
@property TC
@type String
@value 'tc'
@static
**/
PositionAlign.TC = 'tc';
/**
Constant used to specify the right edge, center point for alignment
@property RC
@type String
@value 'rc'
@static
**/
PositionAlign.RC = 'rc';
/**
Constant used to specify the bottom edge, center point for alignment
@property BC
@type String
@value 'bc'
@static
**/
PositionAlign.BC = 'bc';
/**
Constant used to specify the left edge, center point for alignment
@property LC
@type String
@value 'lc'
@static
**/
PositionAlign.LC = 'lc';
/**
Constant used to specify the center of widget/node/viewport for alignment
@property CC
@type String
@value 'cc'
@static
*/
PositionAlign.CC = 'cc';
PositionAlign.prototype = {
// -- Protected Properties -------------------------------------------------
initializer : function() {
if (!this._posNode) {
Y.error('WidgetPosition needs to be added to the Widget, ' +
'before WidgetPositionAlign is added');
}
Y.after(this._bindUIPosAlign, this, 'bindUI');
Y.after(this._syncUIPosAlign, this, 'syncUI');
},
/**
Holds the alignment-syncing event handles.
@property _posAlignUIHandles
@type Array
@default null
@protected
**/
_posAlignUIHandles: null,
// -- Lifecycle Methods ----------------------------------------------------
initializer: function() {
if ( ! this._posNode) {
Y.error('WidgetPosition needs to be added to the Widget, ' +
'before WidgetPositionAlign is added');
}
Y.after(this._bindUIPosAlign, this, 'bindUI');
Y.after(this._syncUIPosAlign, this, 'syncUI');
},
destructor: function () {
this._detachPosAlignUIHandles();
},
/**
Bind event listeners responsible for updating the UI state in response to
the widget's position-align related state changes.
This method is invoked after `bindUI` has been invoked for the `Widget`
class using the AOP infrastructure.
@method _bindUIPosAlign
@protected
**/
_bindUIPosAlign: function () {
this.after('alignChange', this._afterAlignChange);
this.after('alignOnChange', this._afterAlignOnChange);
this.after('visibleChange', this._syncUIPosAlign);
},
/**
Synchronizes the current `align` Attribute value to the DOM.
This method is invoked after `syncUI` has been invoked for the `Widget`
class using the AOP infrastructure.
@method _syncUIPosAlign
@protected
**/
_syncUIPosAlign: function () {
var align = this.get(ALIGN);
this._uiSetVisiblePosAlign(this.get(VISIBLE));
if (align) {
this._uiSetAlign(align.node, align.points);
}
},
// -- Public Methods -------------------------------------------------------
/**
Aligns this widget to the provided `Node` (or viewport) using the provided
points. This method can be invoked with no arguments which will cause the
widget's current `align` Attribute value to be synced to the DOM.
@example Aligning to the top-left corner of the ``:
myWidget.align('body',
[Y.WidgetPositionAlign.TL, Y.WidgetPositionAlign.TR]);
@method align
@param {Node|String|null} [node] A reference (or selector String) for the
`Node` which with the widget is to be aligned. If null is passed in, the
widget will be aligned with the viewport.
@param {Array[2]} [points] A two item array specifying the points on the
widget and `Node`/viewport which will to be aligned. The first entry is
the point on the widget, and the second entry is the point on the
`Node`/viewport. Valid point references are defined as static constants on
the `WidgetPositionAlign` extension.
@chainable
**/
align: function (node, points) {
if (arguments.length) {
// Set the `align` Attribute.
this.set(ALIGN, {
node : node,
points: points
});
} else {
// Sync the current `align` Attribute value to the DOM.
this._syncUIPosAlign();
}
return this;
},
/**
Centers the widget in the viewport, or if a `Node` is passed in, it will
be centered to that `Node`.
@method centered
@param {Node|String} [node] A `Node` reference or selector String defining
the `Node` which the widget should be centered. If a `Node` is not passed
in, then the widget will be centered to the viewport.
@chainable
**/
centered: function (node) {
return this.align(node, [PositionAlign.CC, PositionAlign.CC]);
},
// -- Protected Methods ----------------------------------------------------
/**
Returns coordinates realative to the passed `Node` alignment.
@method _getAlignToXY
@param {Node} 'Node' The node to align to.
@param {Array} [point] The node alignment points.
@param {Number} 'Node' x coordinate.
@param {Number} 'Node' y coordinate.
@return {Array} the coordinates.
@private
**/
_getAlignToXY: function (node, point, x, y) {
var xy;
switch (point) {
case PositionAlign.TL:
xy = [x, y];
break;
case PositionAlign.TR:
xy = [
x - node.get(OFFSET_WIDTH),
y
];
break;
case PositionAlign.BL:
xy = [
x,
y - node.get(OFFSET_HEIGHT)
];
break;
case PositionAlign.BR:
xy = [
x - node.get(OFFSET_WIDTH),
y - node.get(OFFSET_HEIGHT)
];
break;
case PositionAlign.TC:
xy = [
x - (node.get(OFFSET_WIDTH) / 2),
y
];
break;
case PositionAlign.BC:
xy = [
x - (node.get(OFFSET_WIDTH) / 2),
y - node.get(OFFSET_HEIGHT)
];
break;
case PositionAlign.LC:
xy = [
x,
y - (node.get(OFFSET_HEIGHT) / 2)
];
break;
case PositionAlign.RC:
xy = [
x - node.get(OFFSET_WIDTH),
y - (node.get(OFFSET_HEIGHT) / 2)
];
break;
case PositionAlign.CC:
xy = [
x - (node.get(OFFSET_WIDTH) / 2),
y - (node.get(OFFSET_HEIGHT) / 2)
];
break;
default:
break;
}
return xy;
},
/**
Returns `Widget` alignment coordinates realative to the given `Node`.
@method _getAlignedXY
@param {Node|String|null} [node] The node to align to, or null to indicate
the viewport.
@param {Array} points The alignment points.
@return {Array} the coordinates.
@protected
**/
_getAlignedXY: function (node, points) {
if ( ! Lang.isArray(points) || points.length !== 2) {
Y.error('align: Invalid Points Arguments');
return;
}
var nodeRegion = this._getRegion(node), nodePoint, xy;
if ( ! nodeRegion) {
// No-op, nothing to align to.
return;
}
nodePoint = points[1];
// TODO: Optimize KWeight - Would lookup table help?
switch (nodePoint) {
case PositionAlign.TL:
xy = [nodeRegion.left, nodeRegion.top];
break;
case PositionAlign.TR:
xy = [nodeRegion.right, nodeRegion.top];
break;
case PositionAlign.BL:
xy = [nodeRegion.left, nodeRegion.bottom];
break;
case PositionAlign.BR:
xy = [nodeRegion.right, nodeRegion.bottom];
break;
case PositionAlign.TC:
xy = [
nodeRegion.left + Math.floor(nodeRegion.width / 2),
nodeRegion.top
];
break;
case PositionAlign.BC:
xy = [
nodeRegion.left + Math.floor(nodeRegion.width / 2),
nodeRegion.bottom
];
break;
case PositionAlign.LC:
xy = [
nodeRegion.left,
nodeRegion.top + Math.floor(nodeRegion.height / 2)
];
break;
case PositionAlign.RC:
xy = [
nodeRegion.right,
nodeRegion.top + Math.floor(nodeRegion.height / 2)
];
break;
case PositionAlign.CC:
xy = [
nodeRegion.left + Math.floor(nodeRegion.width / 2),
nodeRegion.top + Math.floor(nodeRegion.height / 2)
];
break;
default:
break;
}
return this._getAlignToXY(this._posNode, points[0], xy[0], xy[1]);
},
/**
Default setter for `center` Attribute changes. Sets up the appropriate
value, and passes it through the to the align attribute.
@method _setAlignCenter
@param {Boolean|Node} val The Attribute value being set.
@return {Boolean|Node} the value passed in.
@protected
**/
_setAlignCenter: function (val) {
if (val) {
this.set(ALIGN, {
node : val === true ? null : val,
points: [PositionAlign.CC, PositionAlign.CC]
});
}
return val;
},
/**
Updates the UI to reflect the `align` value passed in.
**Note:** See the `align` Attribute documentation, for the Object structure
expected.
@method _uiSetAlign
@param {Node|String|null} [node] The node to align to, or null to indicate
the viewport.
@param {Array} points The alignment points.
@protected
**/
_uiSetAlign: function (node, points) {
var xy = this._getAlignedXY(node, points);
if (xy) {
this._doAlign(xy);
}
},
/**
Attaches or detaches alignment-syncing event handlers based on the widget's
`visible` Attribute state.
@method _uiSetVisiblePosAlign
@param {Boolean} visible The current value of the widget's `visible`
Attribute.
@protected
**/
_uiSetVisiblePosAlign: function (visible) {
if (visible) {
this._attachPosAlignUIHandles();
} else {
this._detachPosAlignUIHandles();
}
},
/**
Attaches the alignment-syncing event handlers.
@method _attachPosAlignUIHandles
@protected
**/
_attachPosAlignUIHandles: function () {
if (this._posAlignUIHandles) {
// No-op if we have already setup the event handlers.
return;
}
var bb = this.get(BOUNDING_BOX),
syncAlign = Y.bind(this._syncUIPosAlign, this),
handles = [];
Y.Array.each(this.get(ALIGN_ON), function (o) {
var event = o.eventName,
node = Y.one(o.node) || bb;
if (event) {
handles.push(node.on(event, syncAlign));
}
});
this._posAlignUIHandles = handles;
},
/**
Detaches the alignment-syncing event handlers.
@method _detachPosAlignUIHandles
@protected
**/
_detachPosAlignUIHandles: function () {
var handles = this._posAlignUIHandles;
if (handles) {
new Y.EventHandle(handles).detach();
this._posAlignUIHandles = null;
}
},
// -- Private Methods ------------------------------------------------------
/**
Helper method, used to align the given point on the widget, with the XY page
coordinates provided.
@method _doAlign
@param {Array} xy XY page coordinates to align to.
@private
**/
_doAlign: function(xy) {
if (xy) {
this.move(xy);
}
},
/**
Returns the region of the passed-in `Node`, or the viewport region if
calling with passing in a `Node`.
@method _getRegion
@param {Node} [node] The node to get the region of.
@return {Object} The node's region.
@private
**/
_getRegion: function (node) {
var nodeRegion;
if ( ! node) {
nodeRegion = this._posNode.get(VIEWPORT_REGION);
} else {
node = Y.Node.one(node);
if (node) {
nodeRegion = node.get(REGION);
}
}
return nodeRegion;
},
// -- Protected Event Handlers ---------------------------------------------
/**
Handles `alignChange` events by updating the UI in response to `align`
Attribute changes.
@method _afterAlignChange
@param {EventFacade} e
@protected
**/
_afterAlignChange: function (e) {
var align = e.newVal;
if (align) {
this._uiSetAlign(align.node, align.points);
}
},
/**
Handles `alignOnChange` events by updating the alignment-syncing event
handlers.
@method _afterAlignOnChange
@param {EventFacade} e
@protected
**/
_afterAlignOnChange: function(e) {
this._detachPosAlignUIHandles();
if (this.get(VISIBLE)) {
this._attachPosAlignUIHandles();
}
}
};
Y.WidgetPositionAlign = PositionAlign;
}, 'patched-v3.11.0', {"requires": ["widget-position"]});
YUI.add('widget-position-constrain', function (Y, NAME) {
/**
* Provides constrained xy positioning support for Widgets, through an extension.
*
* It builds on top of the widget-position module, to provide constrained positioning support.
*
* @module widget-position-constrain
*/
var CONSTRAIN = "constrain",
CONSTRAIN_XYCHANGE = "constrain|xyChange",
CONSTRAIN_CHANGE = "constrainChange",
PREVENT_OVERLAP = "preventOverlap",
ALIGN = "align",
EMPTY_STR = "",
BINDUI = "bindUI",
XY = "xy",
X_COORD = "x",
Y_COORD = "y",
Node = Y.Node,
VIEWPORT_REGION = "viewportRegion",
REGION = "region",
PREVENT_OVERLAP_MAP;
/**
* A widget extension, which can be used to add constrained xy positioning support to the base Widget class,
* through the Base.build method. This extension requires that
* the WidgetPosition extension be added to the Widget (before WidgetPositionConstrain, if part of the same
* extension list passed to Base.build).
*
* @class WidgetPositionConstrain
* @param {Object} User configuration object
*/
function PositionConstrain(config) {}
/**
* Static property used to define the default attribute
* configuration introduced by WidgetPositionConstrain.
*
* @property ATTRS
* @type Object
* @static
*/
PositionConstrain.ATTRS = {
/**
* @attribute constrain
* @type boolean | Node
* @default null
* @description The node to constrain the widget's bounding box to, when setting xy. Can also be
* set to true, to constrain to the viewport.
*/
constrain : {
value: null,
setter: "_setConstrain"
},
/**
* @attribute preventOverlap
* @type boolean
* @description If set to true, and WidgetPositionAlign is also added to the Widget,
* constrained positioning will attempt to prevent the widget's bounding box from overlapping
* the element to which it has been aligned, by flipping the orientation of the alignment
* for corner based alignments
*/
preventOverlap : {
value:false
}
};
/**
* @property _PREVENT_OVERLAP
* @static
* @protected
* @type Object
* @description The set of positions for which to prevent
* overlap.
*/
PREVENT_OVERLAP_MAP = PositionConstrain._PREVENT_OVERLAP = {
x: {
"tltr": 1,
"blbr": 1,
"brbl": 1,
"trtl": 1
},
y : {
"trbr": 1,
"tlbl": 1,
"bltl": 1,
"brtr": 1
}
};
PositionConstrain.prototype = {
initializer : function() {
if (!this._posNode) {
Y.error("WidgetPosition needs to be added to the Widget, before WidgetPositionConstrain is added");
}
Y.after(this._bindUIPosConstrained, this, BINDUI);
},
/**
* Calculates the constrained positions for the XY positions provided, using
* the provided node argument is passed in. If no node value is passed in, the value of
* the "constrain" attribute is used.
*
* @method getConstrainedXY
* @param {Array} xy The xy values to constrain
* @param {Node | boolean} node Optional. The node to constrain to, or true for the viewport
* @return {Array} The constrained xy values
*/
getConstrainedXY : function(xy, node) {
node = node || this.get(CONSTRAIN);
var constrainingRegion = this._getRegion((node === true) ? null : node),
nodeRegion = this._posNode.get(REGION);
return [
this._constrain(xy[0], X_COORD, nodeRegion, constrainingRegion),
this._constrain(xy[1], Y_COORD, nodeRegion, constrainingRegion)
];
},
/**
* Constrains the widget's bounding box to a node (or the viewport). If xy or node are not
* passed in, the current position and the value of "constrain" will be used respectively.
*
* The widget's position will be changed to the constrained position.
*
* @method constrain
* @param {Array} xy Optional. The xy values to constrain
* @param {Node | boolean} node Optional. The node to constrain to, or true for the viewport
*/
constrain : function(xy, node) {
var currentXY,
constrainedXY,
constraint = node || this.get(CONSTRAIN);
if (constraint) {
currentXY = xy || this.get(XY);
constrainedXY = this.getConstrainedXY(currentXY, constraint);
if (constrainedXY[0] !== currentXY[0] || constrainedXY[1] !== currentXY[1]) {
this.set(XY, constrainedXY, { constrained:true });
}
}
},
/**
* The setter implementation for the "constrain" attribute.
*
* @method _setConstrain
* @protected
* @param {Node | boolean} val The attribute value
*/
_setConstrain : function(val) {
return (val === true) ? val : Node.one(val);
},
/**
* The method which performs the actual constrain calculations for a given axis ("x" or "y") based
* on the regions provided.
*
* @method _constrain
* @protected
*
* @param {Number} val The value to constrain
* @param {String} axis The axis to use for constrainment
* @param {Region} nodeRegion The region of the node to constrain
* @param {Region} constrainingRegion The region of the node (or viewport) to constrain to
*
* @return {Number} The constrained value
*/
_constrain: function(val, axis, nodeRegion, constrainingRegion) {
if (constrainingRegion) {
if (this.get(PREVENT_OVERLAP)) {
val = this._preventOverlap(val, axis, nodeRegion, constrainingRegion);
}
var x = (axis == X_COORD),
regionSize = (x) ? constrainingRegion.width : constrainingRegion.height,
nodeSize = (x) ? nodeRegion.width : nodeRegion.height,
minConstraint = (x) ? constrainingRegion.left : constrainingRegion.top,
maxConstraint = (x) ? constrainingRegion.right - nodeSize : constrainingRegion.bottom - nodeSize;
if (val < minConstraint || val > maxConstraint) {
if (nodeSize < regionSize) {
if (val < minConstraint) {
val = minConstraint;
} else if (val > maxConstraint) {
val = maxConstraint;
}
} else {
val = minConstraint;
}
}
}
return val;
},
/**
* The method which performs the preventOverlap calculations for a given axis ("x" or "y") based
* on the value and regions provided.
*
* @method _preventOverlap
* @protected
*
* @param {Number} val The value being constrain
* @param {String} axis The axis to being constrained
* @param {Region} nodeRegion The region of the node being constrained
* @param {Region} constrainingRegion The region of the node (or viewport) we need to constrain to
*
* @return {Number} The constrained value
*/
_preventOverlap : function(val, axis, nodeRegion, constrainingRegion) {
var align = this.get(ALIGN),
x = (axis === X_COORD),
nodeSize,
alignRegion,
nearEdge,
farEdge,
spaceOnNearSide,
spaceOnFarSide;
if (align && align.points && PREVENT_OVERLAP_MAP[axis][align.points.join(EMPTY_STR)]) {
alignRegion = this._getRegion(align.node);
if (alignRegion) {
nodeSize = (x) ? nodeRegion.width : nodeRegion.height;
nearEdge = (x) ? alignRegion.left : alignRegion.top;
farEdge = (x) ? alignRegion.right : alignRegion.bottom;
spaceOnNearSide = (x) ? alignRegion.left - constrainingRegion.left : alignRegion.top - constrainingRegion.top;
spaceOnFarSide = (x) ? constrainingRegion.right - alignRegion.right : constrainingRegion.bottom - alignRegion.bottom;
}
if (val > nearEdge) {
if (spaceOnFarSide < nodeSize && spaceOnNearSide > nodeSize) {
val = nearEdge - nodeSize;
}
} else {
if (spaceOnNearSide < nodeSize && spaceOnFarSide > nodeSize) {
val = farEdge;
}
}
}
return val;
},
/**
* Binds event listeners responsible for updating the UI state in response to
* Widget constrained positioning related state changes.
*
* This method is invoked after bindUI is invoked for the Widget class
* using YUI's aop infrastructure.
*
*
* @method _bindUIPosConstrained
* @protected
*/
_bindUIPosConstrained : function() {
this.after(CONSTRAIN_CHANGE, this._afterConstrainChange);
this._enableConstraints(this.get(CONSTRAIN));
},
/**
* After change listener for the "constrain" attribute, responsible
* for updating the UI, in response to attribute changes.
*
* @method _afterConstrainChange
* @protected
* @param {EventFacade} e The event facade
*/
_afterConstrainChange : function(e) {
this._enableConstraints(e.newVal);
},
/**
* Updates the UI if enabling constraints, and sets up the xyChange event listeners
* to constrain whenever the widget is moved. Disabling constraints removes the listeners.
*
* @method enable or disable constraints listeners
* @private
* @param {boolean} enable Enable or disable constraints
*/
_enableConstraints : function(enable) {
if (enable) {
this.constrain();
this._cxyHandle = this._cxyHandle || this.on(CONSTRAIN_XYCHANGE, this._constrainOnXYChange);
} else if (this._cxyHandle) {
this._cxyHandle.detach();
this._cxyHandle = null;
}
},
/**
* The on change listener for the "xy" attribute. Modifies the event facade's
* newVal property with the constrained XY value.
*
* @method _constrainOnXYChange
* @protected
* @param {EventFacade} e The event facade for the attribute change
*/
_constrainOnXYChange : function(e) {
if (!e.constrained) {
e.newVal = this.getConstrainedXY(e.newVal);
}
},
/**
* Utility method to normalize region retrieval from a node instance,
* or the viewport, if no node is provided.
*
* @method _getRegion
* @private
* @param {Node} node Optional.
*/
_getRegion : function(node) {
var region;
if (!node) {
region = this._posNode.get(VIEWPORT_REGION);
} else {
node = Node.one(node);
if (node) {
region = node.get(REGION);
}
}
return region;
}
};
Y.WidgetPositionConstrain = PositionConstrain;
}, 'patched-v3.11.0', {"requires": ["widget-position"]});
YUI.add('widget-position', function (Y, NAME) {
/**
* Provides basic XY positioning support for Widgets, though an extension
*
* @module widget-position
*/
var Lang = Y.Lang,
Widget = Y.Widget,
XY_COORD = "xy",
POSITION = "position",
POSITIONED = "positioned",
BOUNDING_BOX = "boundingBox",
RELATIVE = "relative",
RENDERUI = "renderUI",
BINDUI = "bindUI",
SYNCUI = "syncUI",
UI = Widget.UI_SRC,
XYChange = "xyChange";
/**
* Widget extension, which can be used to add positioning support to the base Widget class,
* through the Base.build method.
*
* @class WidgetPosition
* @param {Object} config User configuration object
*/
function Position(config) {
}
/**
* Static property used to define the default attribute
* configuration introduced by WidgetPosition.
*
* @property ATTRS
* @static
* @type Object
*/
Position.ATTRS = {
/**
* @attribute x
* @type number
* @default 0
*
* @description Page X co-ordinate for the widget. This attribute acts as a facade for the
* xy attribute. Changes in position can be monitored by listening for xyChange events.
*/
x: {
setter: function(val) {
this._setX(val);
},
getter: function() {
return this._getX();
},
lazyAdd:false
},
/**
* @attribute y
* @type number
* @default 0
*
* @description Page Y co-ordinate for the widget. This attribute acts as a facade for the
* xy attribute. Changes in position can be monitored by listening for xyChange events.
*/
y: {
setter: function(val) {
this._setY(val);
},
getter: function() {
return this._getY();
},
lazyAdd: false
},
/**
* @attribute xy
* @type Array
* @default [0,0]
*
* @description Page XY co-ordinate pair for the widget.
*/
xy: {
value:[0,0],
validator: function(val) {
return this._validateXY(val);
}
}
};
/**
* Default class used to mark the boundingBox of a positioned widget.
*
* @property POSITIONED_CLASS_NAME
* @type String
* @default "yui-widget-positioned"
* @static
*/
Position.POSITIONED_CLASS_NAME = Widget.getClassName(POSITIONED);
Position.prototype = {
initializer : function() {
this._posNode = this.get(BOUNDING_BOX);
// WIDGET METHOD OVERLAP
Y.after(this._renderUIPosition, this, RENDERUI);
Y.after(this._syncUIPosition, this, SYNCUI);
Y.after(this._bindUIPosition, this, BINDUI);
},
/**
* Creates/Initializes the DOM to support xy page positioning.
*
* This method in invoked after renderUI is invoked for the Widget class
* using YUI's aop infrastructure.
*
* @method _renderUIPosition
* @protected
*/
_renderUIPosition : function() {
this._posNode.addClass(Position.POSITIONED_CLASS_NAME);
},
/**
* Synchronizes the UI to match the Widgets xy page position state.
*
* This method in invoked after syncUI is invoked for the Widget class
* using YUI's aop infrastructure.
*
* @method _syncUIPosition
* @protected
*/
_syncUIPosition : function() {
var posNode = this._posNode;
if (posNode.getStyle(POSITION) === RELATIVE) {
this.syncXY();
}
this._uiSetXY(this.get(XY_COORD));
},
/**
* Binds event listeners responsible for updating the UI state in response to
* Widget position related state changes.
*
* This method in invoked after bindUI is invoked for the Widget class
* using YUI's aop infrastructure.
*
* @method _bindUIPosition
* @protected
*/
_bindUIPosition :function() {
this.after(XYChange, this._afterXYChange);
},
/**
* Moves the Widget to the specified page xy co-ordinate position.
*
* @method move
*
* @param {Number} x The new x position
* @param {Number} y The new y position
* Or
* @param {Array} x, y values passed as an array ([x, y]), to support
* simple pass through of Node.getXY results
*/
move: function () {
var args = arguments,
coord = (Lang.isArray(args[0])) ? args[0] : [args[0], args[1]];
this.set(XY_COORD, coord);
},
/**
* Synchronizes the Panel's "xy", "x", and "y" properties with the
* Widget's position in the DOM.
*
* @method syncXY
*/
syncXY : function () {
this.set(XY_COORD, this._posNode.getXY(), {src: UI});
},
/**
* Default validator for the XY attribute
*
* @method _validateXY
* @protected
* @param {Array} val The XY page co-ordinate value which is being set.
* @return {boolean} true if valid, false if not.
*/
_validateXY : function(val) {
return (Lang.isArray(val) && Lang.isNumber(val[0]) && Lang.isNumber(val[1]));
},
/**
* Default setter for the X attribute. The setter passes the X value through
* to the XY attribute, which is the sole store for the XY state.
*
* @method _setX
* @protected
* @param {Number} val The X page co-ordinate value
*/
_setX : function(val) {
this.set(XY_COORD, [val, this.get(XY_COORD)[1]]);
},
/**
* Default setter for the Y attribute. The setter passes the Y value through
* to the XY attribute, which is the sole store for the XY state.
*
* @method _setY
* @protected
* @param {Number} val The Y page co-ordinate value
*/
_setY : function(val) {
this.set(XY_COORD, [this.get(XY_COORD)[0], val]);
},
/**
* Default getter for the X attribute. The value is retrieved from
* the XY attribute, which is the sole store for the XY state.
*
* @method _getX
* @protected
* @return {Number} The X page co-ordinate value
*/
_getX : function() {
return this.get(XY_COORD)[0];
},
/**
* Default getter for the Y attribute. The value is retrieved from
* the XY attribute, which is the sole store for the XY state.
*
* @method _getY
* @protected
* @return {Number} The Y page co-ordinate value
*/
_getY : function() {
return this.get(XY_COORD)[1];
},
/**
* Default attribute change listener for the xy attribute, responsible
* for updating the UI, in response to attribute changes.
*
* @method _afterXYChange
* @protected
* @param {EventFacade} e The event facade for the attribute change
*/
_afterXYChange : function(e) {
if (e.src != UI) {
this._uiSetXY(e.newVal);
}
},
/**
* Updates the UI to reflect the XY page co-ordinates passed in.
*
* @method _uiSetXY
* @protected
* @param {String} val The XY page co-ordinates value to be reflected in the UI
*/
_uiSetXY : function(val) {
this._posNode.setXY(val);
}
};
Y.WidgetPosition = Position;
}, 'patched-v3.11.0', {"requires": ["base-build", "node-screen", "widget"]});
YUI.add('widget-stack', function (Y, NAME) {
/**
* Provides stackable (z-index) support for Widgets through an extension.
*
* @module widget-stack
*/
var L = Y.Lang,
UA = Y.UA,
Node = Y.Node,
Widget = Y.Widget,
ZINDEX = "zIndex",
SHIM = "shim",
VISIBLE = "visible",
BOUNDING_BOX = "boundingBox",
RENDER_UI = "renderUI",
BIND_UI = "bindUI",
SYNC_UI = "syncUI",
OFFSET_WIDTH = "offsetWidth",
OFFSET_HEIGHT = "offsetHeight",
PARENT_NODE = "parentNode",
FIRST_CHILD = "firstChild",
OWNER_DOCUMENT = "ownerDocument",
WIDTH = "width",
HEIGHT = "height",
PX = "px",
// HANDLE KEYS
SHIM_DEFERRED = "shimdeferred",
SHIM_RESIZE = "shimresize",
// Events
VisibleChange = "visibleChange",
WidthChange = "widthChange",
HeightChange = "heightChange",
ShimChange = "shimChange",
ZIndexChange = "zIndexChange",
ContentUpdate = "contentUpdate",
// CSS
STACKED = "stacked";
/**
* Widget extension, which can be used to add stackable (z-index) support to the
* base Widget class along with a shimming solution, through the
* Base.build method.
*
* @class WidgetStack
* @param {Object} User configuration object
*/
function Stack(config) {}
// Static Properties
/**
* Static property used to define the default attribute
* configuration introduced by WidgetStack.
*
* @property ATTRS
* @type Object
* @static
*/
Stack.ATTRS = {
/**
* @attribute shim
* @type boolean
* @default false, for all browsers other than IE6, for which a shim is enabled by default.
*
* @description Boolean flag to indicate whether or not a shim should be added to the Widgets
* boundingBox, to protect it from select box bleedthrough.
*/
shim: {
value: (UA.ie == 6)
},
/**
* @attribute zIndex
* @type number
* @default 0
* @description The z-index to apply to the Widgets boundingBox. Non-numerical values for
* zIndex will be converted to 0
*/
zIndex: {
value : 0,
setter: '_setZIndex'
}
};
/**
* The HTML parsing rules for the WidgetStack class.
*
* @property HTML_PARSER
* @static
* @type Object
*/
Stack.HTML_PARSER = {
zIndex: function (srcNode) {
return this._parseZIndex(srcNode);
}
};
/**
* Default class used to mark the shim element
*
* @property SHIM_CLASS_NAME
* @type String
* @static
* @default "yui3-widget-shim"
*/
Stack.SHIM_CLASS_NAME = Widget.getClassName(SHIM);
/**
* Default class used to mark the boundingBox of a stacked widget.
*
* @property STACKED_CLASS_NAME
* @type String
* @static
* @default "yui3-widget-stacked"
*/
Stack.STACKED_CLASS_NAME = Widget.getClassName(STACKED);
/**
* Default markup template used to generate the shim element.
*
* @property SHIM_TEMPLATE
* @type String
* @static
*/
Stack.SHIM_TEMPLATE = '';
Stack.prototype = {
initializer : function() {
this._stackNode = this.get(BOUNDING_BOX);
this._stackHandles = {};
// WIDGET METHOD OVERLAP
Y.after(this._renderUIStack, this, RENDER_UI);
Y.after(this._syncUIStack, this, SYNC_UI);
Y.after(this._bindUIStack, this, BIND_UI);
},
/**
* Synchronizes the UI to match the Widgets stack state. This method in
* invoked after syncUI is invoked for the Widget class using YUI's aop infrastructure.
*
* @method _syncUIStack
* @protected
*/
_syncUIStack: function() {
this._uiSetShim(this.get(SHIM));
this._uiSetZIndex(this.get(ZINDEX));
},
/**
* Binds event listeners responsible for updating the UI state in response to
* Widget stack related state changes.
*
* This method is invoked after bindUI is invoked for the Widget class
* using YUI's aop infrastructure.
*
* @method _bindUIStack
* @protected
*/
_bindUIStack: function() {
this.after(ShimChange, this._afterShimChange);
this.after(ZIndexChange, this._afterZIndexChange);
},
/**
* Creates/Initializes the DOM to support stackability.
*
* This method in invoked after renderUI is invoked for the Widget class
* using YUI's aop infrastructure.
*
* @method _renderUIStack
* @protected
*/
_renderUIStack: function() {
this._stackNode.addClass(Stack.STACKED_CLASS_NAME);
},
/**
Parses a `zIndex` attribute value from this widget's `srcNode`.
@method _parseZIndex
@param {Node} srcNode The node to parse a `zIndex` value from.
@return {Mixed} The parsed `zIndex` value.
@protected
**/
_parseZIndex: function (srcNode) {
var zIndex;
// Prefers how WebKit handles `z-index` which better matches the
// spec:
//
// * http://www.w3.org/TR/CSS2/visuren.html#z-index
// * https://bugs.webkit.org/show_bug.cgi?id=15562
//
// When a node isn't rendered in the document, and/or when a
// node is not positioned, then it doesn't have a context to derive
// a valid `z-index` value from.
if (!srcNode.inDoc() || srcNode.getStyle('position') === 'static') {
zIndex = 'auto';
} else {
// Uses `getComputedStyle()` because it has greater accuracy in
// more browsers than `getStyle()` does for `z-index`.
zIndex = srcNode.getComputedStyle('zIndex');
}
// This extension adds a stacking context to widgets, therefore a
// `srcNode` witout a stacking context (i.e. "auto") will return
// `null` from this DOM parser. This way the widget's default or
// user provided value for `zIndex` will be used.
return zIndex === 'auto' ? null : zIndex;
},
/**
* Default setter for zIndex attribute changes. Normalizes zIndex values to
* numbers, converting non-numerical values to 0.
*
* @method _setZIndex
* @protected
* @param {String | Number} zIndex
* @return {Number} Normalized zIndex
*/
_setZIndex: function(zIndex) {
if (L.isString(zIndex)) {
zIndex = parseInt(zIndex, 10);
}
if (!L.isNumber(zIndex)) {
zIndex = 0;
}
return zIndex;
},
/**
* Default attribute change listener for the shim attribute, responsible
* for updating the UI, in response to attribute changes.
*
* @method _afterShimChange
* @protected
* @param {EventFacade} e The event facade for the attribute change
*/
_afterShimChange : function(e) {
this._uiSetShim(e.newVal);
},
/**
* Default attribute change listener for the zIndex attribute, responsible
* for updating the UI, in response to attribute changes.
*
* @method _afterZIndexChange
* @protected
* @param {EventFacade} e The event facade for the attribute change
*/
_afterZIndexChange : function(e) {
this._uiSetZIndex(e.newVal);
},
/**
* Updates the UI to reflect the zIndex value passed in.
*
* @method _uiSetZIndex
* @protected
* @param {number} zIndex The zindex to be reflected in the UI
*/
_uiSetZIndex: function (zIndex) {
this._stackNode.setStyle(ZINDEX, zIndex);
},
/**
* Updates the UI to enable/disable the shim. If the widget is not currently visible,
* creation of the shim is deferred until it is made visible, for performance reasons.
*
* @method _uiSetShim
* @protected
* @param {boolean} enable If true, creates/renders the shim, if false, removes it.
*/
_uiSetShim: function (enable) {
if (enable) {
// Lazy creation
if (this.get(VISIBLE)) {
this._renderShim();
} else {
this._renderShimDeferred();
}
// Eagerly attach resize handlers
//
// Required because of Event stack behavior, commit ref: cd8dddc
// Should be revisted after Ticket #2531067 is resolved.
if (UA.ie == 6) {
this._addShimResizeHandlers();
}
} else {
this._destroyShim();
}
},
/**
* Sets up change handlers for the visible attribute, to defer shim creation/rendering
* until the Widget is made visible.
*
* @method _renderShimDeferred
* @private
*/
_renderShimDeferred : function() {
this._stackHandles[SHIM_DEFERRED] = this._stackHandles[SHIM_DEFERRED] || [];
var handles = this._stackHandles[SHIM_DEFERRED],
createBeforeVisible = function(e) {
if (e.newVal) {
this._renderShim();
}
};
handles.push(this.on(VisibleChange, createBeforeVisible));
// Depending how how Ticket #2531067 is resolved, a reversal of
// commit ref: cd8dddc could lead to a more elagent solution, with
// the addition of this line here:
//
// handles.push(this.after(VisibleChange, this.sizeShim));
},
/**
* Sets up event listeners to resize the shim when the size of the Widget changes.
*
* NOTE: This method is only used for IE6 currently, since IE6 doesn't support a way to
* resize the shim purely through CSS, when the Widget does not have an explicit width/height
* set.
*
* @method _addShimResizeHandlers
* @private
*/
_addShimResizeHandlers : function() {
this._stackHandles[SHIM_RESIZE] = this._stackHandles[SHIM_RESIZE] || [];
var sizeShim = this.sizeShim,
handles = this._stackHandles[SHIM_RESIZE];
handles.push(this.after(VisibleChange, sizeShim));
handles.push(this.after(WidthChange, sizeShim));
handles.push(this.after(HeightChange, sizeShim));
handles.push(this.after(ContentUpdate, sizeShim));
},
/**
* Detaches any handles stored for the provided key
*
* @method _detachStackHandles
* @param String handleKey The key defining the group of handles which should be detached
* @private
*/
_detachStackHandles : function(handleKey) {
var handles = this._stackHandles[handleKey],
handle;
if (handles && handles.length > 0) {
while((handle = handles.pop())) {
handle.detach();
}
}
},
/**
* Creates the shim element and adds it to the DOM
*
* @method _renderShim
* @private
*/
_renderShim : function() {
var shimEl = this._shimNode,
stackEl = this._stackNode;
if (!shimEl) {
shimEl = this._shimNode = this._getShimTemplate();
stackEl.insertBefore(shimEl, stackEl.get(FIRST_CHILD));
this._detachStackHandles(SHIM_DEFERRED);
this.sizeShim();
}
},
/**
* Removes the shim from the DOM, and detaches any related event
* listeners.
*
* @method _destroyShim
* @private
*/
_destroyShim : function() {
if (this._shimNode) {
this._shimNode.get(PARENT_NODE).removeChild(this._shimNode);
this._shimNode = null;
this._detachStackHandles(SHIM_DEFERRED);
this._detachStackHandles(SHIM_RESIZE);
}
},
/**
* For IE6, synchronizes the size and position of iframe shim to that of
* Widget bounding box which it is protecting. For all other browsers,
* this method does not do anything.
*
* @method sizeShim
*/
sizeShim: function () {
var shim = this._shimNode,
node = this._stackNode;
if (shim && UA.ie === 6 && this.get(VISIBLE)) {
shim.setStyle(WIDTH, node.get(OFFSET_WIDTH) + PX);
shim.setStyle(HEIGHT, node.get(OFFSET_HEIGHT) + PX);
}
},
/**
* Creates a cloned shim node, using the SHIM_TEMPLATE html template, for use on a new instance.
*
* @method _getShimTemplate
* @private
* @return {Node} node A new shim Node instance.
*/
_getShimTemplate : function() {
return Node.create(Stack.SHIM_TEMPLATE, this._stackNode.get(OWNER_DOCUMENT));
}
};
Y.WidgetStack = Stack;
}, 'patched-v3.11.0', {"requires": ["base-build", "widget"], "skinnable": true});
YUI.add('widget-stdmod', function (Y, NAME) {
/**
* Provides standard module support for Widgets through an extension.
*
* @module widget-stdmod
*/
var L = Y.Lang,
Node = Y.Node,
UA = Y.UA,
Widget = Y.Widget,
EMPTY = "",
HD = "hd",
BD = "bd",
FT = "ft",
HEADER = "header",
BODY = "body",
FOOTER = "footer",
FILL_HEIGHT = "fillHeight",
STDMOD = "stdmod",
NODE_SUFFIX = "Node",
CONTENT_SUFFIX = "Content",
FIRST_CHILD = "firstChild",
CHILD_NODES = "childNodes",
OWNER_DOCUMENT = "ownerDocument",
CONTENT_BOX = "contentBox",
HEIGHT = "height",
OFFSET_HEIGHT = "offsetHeight",
AUTO = "auto",
HeaderChange = "headerContentChange",
BodyChange = "bodyContentChange",
FooterChange = "footerContentChange",
FillHeightChange = "fillHeightChange",
HeightChange = "heightChange",
ContentUpdate = "contentUpdate",
RENDERUI = "renderUI",
BINDUI = "bindUI",
SYNCUI = "syncUI",
APPLY_PARSED_CONFIG = "_applyParsedConfig",
UI = Y.Widget.UI_SRC;
/**
* Widget extension, which can be used to add Standard Module support to the
* base Widget class, through the Base.build
* method.
*
* The extension adds header, body and footer sections to the Widget's content box and
* provides the corresponding methods and attributes to modify the contents of these sections.
*
* @class WidgetStdMod
* @param {Object} The user configuration object
*/
function StdMod(config) {}
/**
* Constant used to refer the the standard module header, in methods which expect a section specifier
*
* @property HEADER
* @static
* @type String
*/
StdMod.HEADER = HEADER;
/**
* Constant used to refer the the standard module body, in methods which expect a section specifier
*
* @property BODY
* @static
* @type String
*/
StdMod.BODY = BODY;
/**
* Constant used to refer the the standard module footer, in methods which expect a section specifier
*
* @property FOOTER
* @static
* @type String
*/
StdMod.FOOTER = FOOTER;
/**
* Constant used to specify insertion position, when adding content to sections of the standard module in
* methods which expect a "where" argument.
*
* Inserts new content before the sections existing content.
*
* @property AFTER
* @static
* @type String
*/
StdMod.AFTER = "after";
/**
* Constant used to specify insertion position, when adding content to sections of the standard module in
* methods which expect a "where" argument.
*
* Inserts new content before the sections existing content.
*
* @property BEFORE
* @static
* @type String
*/
StdMod.BEFORE = "before";
/**
* Constant used to specify insertion position, when adding content to sections of the standard module in
* methods which expect a "where" argument.
*
* Replaces the sections existing content, with new content.
*
* @property REPLACE
* @static
* @type String
*/
StdMod.REPLACE = "replace";
var STD_HEADER = StdMod.HEADER,
STD_BODY = StdMod.BODY,
STD_FOOTER = StdMod.FOOTER,
HEADER_CONTENT = STD_HEADER + CONTENT_SUFFIX,
FOOTER_CONTENT = STD_FOOTER + CONTENT_SUFFIX,
BODY_CONTENT = STD_BODY + CONTENT_SUFFIX;
/**
* Static property used to define the default attribute
* configuration introduced by WidgetStdMod.
*
* @property ATTRS
* @type Object
* @static
*/
StdMod.ATTRS = {
/**
* @attribute headerContent
* @type HTML
* @default undefined
* @description The content to be added to the header section. This will replace any existing content
* in the header. If you want to append, or insert new content, use the setStdModContent method.
*/
headerContent: {
value:null
},
/**
* @attribute footerContent
* @type HTML
* @default undefined
* @description The content to be added to the footer section. This will replace any existing content
* in the footer. If you want to append, or insert new content, use the setStdModContent method.
*/
footerContent: {
value:null
},
/**
* @attribute bodyContent
* @type HTML
* @default undefined
* @description The content to be added to the body section. This will replace any existing content
* in the body. If you want to append, or insert new content, use the setStdModContent method.
*/
bodyContent: {
value:null
},
/**
* @attribute fillHeight
* @type {String}
* @default WidgetStdMod.BODY
* @description The section (WidgetStdMod.HEADER, WidgetStdMod.BODY or WidgetStdMod.FOOTER) which should be resized to fill the height of the standard module, when a
* height is set on the Widget. If a height is not set on the widget, then all sections are sized based on
* their content.
*/
fillHeight: {
value: StdMod.BODY,
validator: function(val) {
return this._validateFillHeight(val);
}
}
};
/**
* The HTML parsing rules for the WidgetStdMod class.
*
* @property HTML_PARSER
* @static
* @type Object
*/
StdMod.HTML_PARSER = {
headerContent: function(contentBox) {
return this._parseStdModHTML(STD_HEADER);
},
bodyContent: function(contentBox) {
return this._parseStdModHTML(STD_BODY);
},
footerContent : function(contentBox) {
return this._parseStdModHTML(STD_FOOTER);
}
};
/**
* Static hash of default class names used for the header,
* body and footer sections of the standard module, keyed by
* the section identifier (WidgetStdMod.STD_HEADER, WidgetStdMod.STD_BODY, WidgetStdMod.STD_FOOTER)
*
* @property SECTION_CLASS_NAMES
* @static
* @type Object
*/
StdMod.SECTION_CLASS_NAMES = {
header: Widget.getClassName(HD),
body: Widget.getClassName(BD),
footer: Widget.getClassName(FT)
};
/**
* The template HTML strings for each of the standard module sections. Section entries are keyed by the section constants,
* WidgetStdMod.HEADER, WidgetStdMod.BODY, WidgetStdMod.FOOTER, and contain the HTML to be added for each section.
* e.g.
*
* {
* header : '<div class="yui-widget-hd"></div>',
* body : '<div class="yui-widget-bd"></div>',
* footer : '<div class="yui-widget-ft"></div>'
* }
*
* @property TEMPLATES
* @type Object
* @static
*/
StdMod.TEMPLATES = {
header : '',
body : '
',
footer : ''
};
StdMod.prototype = {
initializer : function() {
this._stdModNode = this.get(CONTENT_BOX);
Y.before(this._renderUIStdMod, this, RENDERUI);
Y.before(this._bindUIStdMod, this, BINDUI);
Y.before(this._syncUIStdMod, this, SYNCUI);
},
/**
* Synchronizes the UI to match the Widgets standard module state.
*
* This method is invoked after syncUI is invoked for the Widget class
* using YUI's aop infrastructure.
*
* @method _syncUIStdMod
* @protected
*/
_syncUIStdMod : function() {
var stdModParsed = this._stdModParsed;
if (!stdModParsed || !stdModParsed[HEADER_CONTENT]) {
this._uiSetStdMod(STD_HEADER, this.get(HEADER_CONTENT));
}
if (!stdModParsed || !stdModParsed[BODY_CONTENT]) {
this._uiSetStdMod(STD_BODY, this.get(BODY_CONTENT));
}
if (!stdModParsed || !stdModParsed[FOOTER_CONTENT]) {
this._uiSetStdMod(STD_FOOTER, this.get(FOOTER_CONTENT));
}
this._uiSetFillHeight(this.get(FILL_HEIGHT));
},
/**
* Creates/Initializes the DOM for standard module support.
*
* This method is invoked after renderUI is invoked for the Widget class
* using YUI's aop infrastructure.
*
* @method _renderUIStdMod
* @protected
*/
_renderUIStdMod : function() {
this._stdModNode.addClass(Widget.getClassName(STDMOD));
this._renderStdModSections();
//This normally goes in bindUI but in order to allow setStdModContent() to work before renderUI
//stage, these listeners should be set up at the earliest possible time.
this.after(HeaderChange, this._afterHeaderChange);
this.after(BodyChange, this._afterBodyChange);
this.after(FooterChange, this._afterFooterChange);
},
_renderStdModSections : function() {
if (L.isValue(this.get(HEADER_CONTENT))) { this._renderStdMod(STD_HEADER); }
if (L.isValue(this.get(BODY_CONTENT))) { this._renderStdMod(STD_BODY); }
if (L.isValue(this.get(FOOTER_CONTENT))) { this._renderStdMod(STD_FOOTER); }
},
/**
* Binds event listeners responsible for updating the UI state in response to
* Widget standard module related state changes.
*
* This method is invoked after bindUI is invoked for the Widget class
* using YUI's aop infrastructure.
*
* @method _bindUIStdMod
* @protected
*/
_bindUIStdMod : function() {
// this.after(HeaderChange, this._afterHeaderChange);
// this.after(BodyChange, this._afterBodyChange);
// this.after(FooterChange, this._afterFooterChange);
this.after(FillHeightChange, this._afterFillHeightChange);
this.after(HeightChange, this._fillHeight);
this.after(ContentUpdate, this._fillHeight);
},
/**
* Default attribute change listener for the headerContent attribute, responsible
* for updating the UI, in response to attribute changes.
*
* @method _afterHeaderChange
* @protected
* @param {EventFacade} e The event facade for the attribute change
*/
_afterHeaderChange : function(e) {
if (e.src !== UI) {
this._uiSetStdMod(STD_HEADER, e.newVal, e.stdModPosition);
}
},
/**
* Default attribute change listener for the bodyContent attribute, responsible
* for updating the UI, in response to attribute changes.
*
* @method _afterBodyChange
* @protected
* @param {EventFacade} e The event facade for the attribute change
*/
_afterBodyChange : function(e) {
if (e.src !== UI) {
this._uiSetStdMod(STD_BODY, e.newVal, e.stdModPosition);
}
},
/**
* Default attribute change listener for the footerContent attribute, responsible
* for updating the UI, in response to attribute changes.
*
* @method _afterFooterChange
* @protected
* @param {EventFacade} e The event facade for the attribute change
*/
_afterFooterChange : function(e) {
if (e.src !== UI) {
this._uiSetStdMod(STD_FOOTER, e.newVal, e.stdModPosition);
}
},
/**
* Default attribute change listener for the fillHeight attribute, responsible
* for updating the UI, in response to attribute changes.
*
* @method _afterFillHeightChange
* @protected
* @param {EventFacade} e The event facade for the attribute change
*/
_afterFillHeightChange: function (e) {
this._uiSetFillHeight(e.newVal);
},
/**
* Default validator for the fillHeight attribute. Verifies that the
* value set is a valid section specifier - one of WidgetStdMod.HEADER, WidgetStdMod.BODY or WidgetStdMod.FOOTER,
* or a falsey value if fillHeight is to be disabled.
*
* @method _validateFillHeight
* @protected
* @param {String} val The section which should be setup to fill height, or false/null to disable fillHeight
* @return true if valid, false if not
*/
_validateFillHeight : function(val) {
return !val || val == StdMod.BODY || val == StdMod.HEADER || val == StdMod.FOOTER;
},
/**
* Updates the rendered UI, to resize the provided section so that the standard module fills out
* the specified widget height. Note: This method does not check whether or not a height is set
* on the Widget.
*
* @method _uiSetFillHeight
* @protected
* @param {String} fillSection A valid section specifier - one of WidgetStdMod.HEADER, WidgetStdMod.BODY or WidgetStdMod.FOOTER
*/
_uiSetFillHeight : function(fillSection) {
var fillNode = this.getStdModNode(fillSection);
var currNode = this._currFillNode;
if (currNode && fillNode !== currNode){
currNode.setStyle(HEIGHT, EMPTY);
}
if (fillNode) {
this._currFillNode = fillNode;
}
this._fillHeight();
},
/**
* Updates the rendered UI, to resize the current section specified by the fillHeight attribute, so
* that the standard module fills out the Widget height. If a height has not been set on Widget,
* the section is not resized (height is set to "auto").
*
* @method _fillHeight
* @private
*/
_fillHeight : function() {
if (this.get(FILL_HEIGHT)) {
var height = this.get(HEIGHT);
if (height != EMPTY && height != AUTO) {
this.fillHeight(this.getStdModNode(this.get(FILL_HEIGHT)));
}
}
},
/**
* Updates the rendered UI, adding the provided content (either an HTML string, or node reference),
* to the specified section. The content is either added before, after or replaces existing content
* in the section, based on the value of the where
argument.
*
* @method _uiSetStdMod
* @protected
*
* @param {String} section The section to be updated. Either WidgetStdMod.HEADER, WidgetStdMod.BODY or WidgetStdMod.FOOTER.
* @param {String | Node} content The new content (either as an HTML string, or Node reference) to add to the section
* @param {String} where Optional. Either WidgetStdMod.AFTER, WidgetStdMod.BEFORE or WidgetStdMod.REPLACE.
* If not provided, the content will replace existing content in the section.
*/
_uiSetStdMod : function(section, content, where) {
// Using isValue, so that "" is valid content
if (L.isValue(content)) {
var node = this.getStdModNode(section, true);
this._addStdModContent(node, content, where);
this.set(section + CONTENT_SUFFIX, this._getStdModContent(section), {src:UI});
} else {
this._eraseStdMod(section);
}
this.fire(ContentUpdate);
},
/**
* Creates the DOM node for the given section, and inserts it into the correct location in the contentBox.
*
* @method _renderStdMod
* @protected
* @param {String} section The section to create/render. Either WidgetStdMod.HEADER, WidgetStdMod.BODY or WidgetStdMod.FOOTER.
* @return {Node} A reference to the added section node
*/
_renderStdMod : function(section) {
var contentBox = this.get(CONTENT_BOX),
sectionNode = this._findStdModSection(section);
if (!sectionNode) {
sectionNode = this._getStdModTemplate(section);
}
this._insertStdModSection(contentBox, section, sectionNode);
this[section + NODE_SUFFIX] = sectionNode;
return this[section + NODE_SUFFIX];
},
/**
* Removes the DOM node for the given section.
*
* @method _eraseStdMod
* @protected
* @param {String} section The section to remove. Either WidgetStdMod.HEADER, WidgetStdMod.BODY or WidgetStdMod.FOOTER.
*/
_eraseStdMod : function(section) {
var sectionNode = this.getStdModNode(section);
if (sectionNode) {
sectionNode.remove(true);
delete this[section + NODE_SUFFIX];
}
},
/**
* Helper method to insert the Node for the given section into the correct location in the contentBox.
*
* @method _insertStdModSection
* @private
* @param {Node} contentBox A reference to the Widgets content box.
* @param {String} section The section to create/render. Either WidgetStdMod.HEADER, WidgetStdMod.BODY or WidgetStdMod.FOOTER.
* @param {Node} sectionNode The Node for the section.
*/
_insertStdModSection : function(contentBox, section, sectionNode) {
var fc = contentBox.get(FIRST_CHILD);
if (section === STD_FOOTER || !fc) {
contentBox.appendChild(sectionNode);
} else {
if (section === STD_HEADER) {
contentBox.insertBefore(sectionNode, fc);
} else {
var footer = this[STD_FOOTER + NODE_SUFFIX];
if (footer) {
contentBox.insertBefore(sectionNode, footer);
} else {
contentBox.appendChild(sectionNode);
}
}
}
},
/**
* Gets a new Node reference for the given standard module section, by cloning
* the stored template node.
*
* @method _getStdModTemplate
* @protected
* @param {String} section The section to create a new node for. Either WidgetStdMod.HEADER, WidgetStdMod.BODY or WidgetStdMod.FOOTER.
* @return {Node} The new Node instance for the section
*/
_getStdModTemplate : function(section) {
return Node.create(StdMod.TEMPLATES[section], this._stdModNode.get(OWNER_DOCUMENT));
},
/**
* Helper method to add content to a StdMod section node.
* The content is added either before, after or replaces the existing node content
* based on the value of the where
argument.
*
* @method _addStdModContent
* @private
*
* @param {Node} node The section Node to be updated.
* @param {Node|NodeList|String} children The new content Node, NodeList or String to be added to section Node provided.
* @param {String} where Optional. Either WidgetStdMod.AFTER, WidgetStdMod.BEFORE or WidgetStdMod.REPLACE.
* If not provided, the content will replace existing content in the Node.
*/
_addStdModContent : function(node, children, where) {
// StdMod where to Node where
switch (where) {
case StdMod.BEFORE: // 0 is before fistChild
where = 0;
break;
case StdMod.AFTER: // undefined is appendChild
where = undefined;
break;
default: // replace is replace, not specified is replace
where = StdMod.REPLACE;
}
node.insert(children, where);
},
/**
* Helper method to obtain the precise height of the node provided, including padding and border.
* The height could be a sub-pixel value for certain browsers, such as Firefox 3.
*
* @method _getPreciseHeight
* @private
* @param {Node} node The node for which the precise height is required.
* @return {Number} The height of the Node including borders and padding, possibly a float.
*/
_getPreciseHeight : function(node) {
var height = (node) ? node.get(OFFSET_HEIGHT) : 0,
getBCR = "getBoundingClientRect";
if (node && node.hasMethod(getBCR)) {
var preciseRegion = node.invoke(getBCR);
if (preciseRegion) {
height = preciseRegion.bottom - preciseRegion.top;
}
}
return height;
},
/**
* Helper method to to find the rendered node for the given section,
* if it exists.
*
* @method _findStdModSection
* @private
* @param {String} section The section for which the render Node is to be found. Either WidgetStdMod.HEADER, WidgetStdMod.BODY or WidgetStdMod.FOOTER.
* @return {Node} The rendered node for the given section, or null if not found.
*/
_findStdModSection: function(section) {
return this.get(CONTENT_BOX).one("> ." + StdMod.SECTION_CLASS_NAMES[section]);
},
/**
* Utility method, used by WidgetStdMods HTML_PARSER implementation
* to extract data for each section from markup.
*
* @method _parseStdModHTML
* @private
* @param {String} section
* @return {String} Inner HTML string with the contents of the section
*/
_parseStdModHTML : function(section) {
var node = this._findStdModSection(section);
if (node) {
if (!this._stdModParsed) {
this._stdModParsed = {};
Y.before(this._applyStdModParsedConfig, this, APPLY_PARSED_CONFIG);
}
this._stdModParsed[section + CONTENT_SUFFIX] = 1;
return node.get("innerHTML");
}
return null;
},
/**
* This method is injected before the _applyParsedConfig step in
* the application of HTML_PARSER, and sets up the state to
* identify whether or not we should remove the current DOM content
* or not, based on whether or not the current content attribute value
* was extracted from the DOM, or provided by the user configuration
*
* @method _applyStdModParsedConfig
* @private
*/
_applyStdModParsedConfig : function(node, cfg, parsedCfg) {
var parsed = this._stdModParsed;
if (parsed) {
parsed[HEADER_CONTENT] = !(HEADER_CONTENT in cfg) && (HEADER_CONTENT in parsed);
parsed[BODY_CONTENT] = !(BODY_CONTENT in cfg) && (BODY_CONTENT in parsed);
parsed[FOOTER_CONTENT] = !(FOOTER_CONTENT in cfg) && (FOOTER_CONTENT in parsed);
}
},
/**
* Retrieves the child nodes (content) of a standard module section
*
* @method _getStdModContent
* @private
* @param {String} section The standard module section whose child nodes are to be retrieved. Either WidgetStdMod.HEADER, WidgetStdMod.BODY or WidgetStdMod.FOOTER.
* @return {Node} The child node collection of the standard module section.
*/
_getStdModContent : function(section) {
return (this[section + NODE_SUFFIX]) ? this[section + NODE_SUFFIX].get(CHILD_NODES) : null;
},
/**
* Updates the body section of the standard module with the content provided (either an HTML string, or node reference).
*
* This method can be used instead of the corresponding section content attribute if you'd like to retain the current content of the section,
* and insert content before or after it, by specifying the where
argument.
*
* @method setStdModContent
* @param {String} section The standard module section whose content is to be updated. Either WidgetStdMod.HEADER, WidgetStdMod.BODY or WidgetStdMod.FOOTER.
* @param {String | Node} content The content to be added, either an HTML string or a Node reference.
* @param {String} where Optional. Either WidgetStdMod.AFTER, WidgetStdMod.BEFORE or WidgetStdMod.REPLACE.
* If not provided, the content will replace existing content in the section.
*/
setStdModContent : function(section, content, where) {
//var node = this.getStdModNode(section) || this._renderStdMod(section);
this.set(section + CONTENT_SUFFIX, content, {stdModPosition:where});
//this._addStdModContent(node, content, where);
},
/**
Returns the node reference for the specified `section`.
**Note:** The DOM is not queried for the node reference. The reference
stored by the widget instance is returned if it was set. Passing a
truthy for `forceCreate` will create the section node if it does not
already exist.
@method getStdModNode
@param {String} section The section whose node reference is required.
Either `WidgetStdMod.HEADER`, `WidgetStdMod.BODY`, or
`WidgetStdMod.FOOTER`.
@param {Boolean} forceCreate Whether the section node should be created
if it does not already exist.
@return {Node} The node reference for the `section`, or null if not set.
**/
getStdModNode : function(section, forceCreate) {
var node = this[section + NODE_SUFFIX] || null;
if (!node && forceCreate) {
node = this._renderStdMod(section);
}
return node;
},
/**
* Sets the height on the provided header, body or footer element to
* fill out the height of the Widget. It determines the height of the
* widgets bounding box, based on it's configured height value, and
* sets the height of the provided section to fill out any
* space remaining after the other standard module section heights
* have been accounted for.
*
* NOTE: This method is not designed to work if an explicit
* height has not been set on the Widget, since for an "auto" height Widget,
* the heights of the header/body/footer will drive the height of the Widget.
*
* @method fillHeight
* @param {Node} node The node which should be resized to fill out the height
* of the Widget bounding box. Should be a standard module section node which belongs
* to the widget.
*/
fillHeight : function(node) {
if (node) {
var contentBox = this.get(CONTENT_BOX),
stdModNodes = [this.headerNode, this.bodyNode, this.footerNode],
stdModNode,
cbContentHeight,
filled = 0,
remaining = 0,
validNode = false;
for (var i = 0, l = stdModNodes.length; i < l; i++) {
stdModNode = stdModNodes[i];
if (stdModNode) {
if (stdModNode !== node) {
filled += this._getPreciseHeight(stdModNode);
} else {
validNode = true;
}
}
}
if (validNode) {
if (UA.ie || UA.opera) {
// Need to set height to 0, to allow height to be reduced
node.set(OFFSET_HEIGHT, 0);
}
cbContentHeight = contentBox.get(OFFSET_HEIGHT) -
parseInt(contentBox.getComputedStyle("paddingTop"), 10) -
parseInt(contentBox.getComputedStyle("paddingBottom"), 10) -
parseInt(contentBox.getComputedStyle("borderBottomWidth"), 10) -
parseInt(contentBox.getComputedStyle("borderTopWidth"), 10);
if (L.isNumber(cbContentHeight)) {
remaining = cbContentHeight - filled;
if (remaining >= 0) {
node.set(OFFSET_HEIGHT, remaining);
}
}
}
}
}
};
Y.WidgetStdMod = StdMod;
}, 'patched-v3.11.0', {"requires": ["base-build", "widget"]});
YUI.add('aui-aria', function (A, NAME) {
/**
* The Aria Component.
*
* @module aui-aria
*/
var Lang = A.Lang,
isBoolean = Lang.isBoolean,
isFunction = Lang.isFunction,
isObject = Lang.isObject,
isString = Lang.isString,
ATTRIBUTE_VALUE_FORMAT = 'attributeValueFormat',
ATTRIBUTES = 'attributes',
ARIA = 'aria',
ARIA_PREFIX = 'aria-',
ATTRIBUTE_NODE = 'attributeNode',
BOUNDING_BOX = 'boundingBox',
HOST = 'host',
ROLE = 'role',
ROLE_NAME = 'roleName',
ROLE_NODE = 'roleNode',
VALIDATE_W3C = 'validateW3C',
CHANGE_PREFIX = 'Change',
EMPTY_STR = '',
STR_REGEX = /([^a-z])/ig,
EV_PROCESS_ATTRIBUTE = 'aria:processAttribute',
_toAriaRole = A.cached(
function(str) {
return str.replace(STR_REGEX, function() {
return EMPTY_STR;
})
.toLowerCase();
}
);
/**
* A base class for Aria.
*
* @class A.Aria
* @extends A.Plugin.Base
* @param config {Object} Object literal specifying widget configuration properties.
* @constructor
*/
var Aria = A.Component.create({
/**
* Static property provides a string to identify the class.
*
* @property Aria.NAME
* @type String
* @static
*/
NAME: ARIA,
/**
* Static property provides a string to identify the namespace.
*
* @property Aria.NS
* @type String
* @static
*/
NS: ARIA,
/**
* Static property used to define the default attribute
* configuration for the Aria.
*
* @property Aria.ATTRS
* @type Object
* @static
*/
ATTRS: {
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute attributes
* @default {}
* @type Object
*/
attributes: {
value: {},
validator: isObject
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute attributeValueFormat
* @type Function
*/
attributeValueFormat: {
value: function(val) {
return val;
},
validator: isFunction
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute attributeNode
* @writeOnce
*/
attributeNode: {
writeOnce: true,
setter: A.one,
valueFn: function() {
return this.get(HOST).get(BOUNDING_BOX);
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute roleName
* @type String
*/
roleName: {
valueFn: function() {
var instance = this;
var host = instance.get(HOST);
var roleName = _toAriaRole(host.constructor.NAME || EMPTY_STR);
return (instance.isValidRole(roleName) ? roleName : EMPTY_STR);
},
validator: isString
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute roleNode
* @writeOnce
*/
roleNode: {
writeOnce: true,
setter: A.one,
valueFn: function() {
return this.get(HOST).get(BOUNDING_BOX);
}
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @attribute validateW3C
* @default true
* @type Boolean
*/
validateW3C: {
value: true,
validator: isBoolean
}
},
/**
* Static property used to define which component it extends.
*
* @property Aria.EXTENDS
* @type Object
* @static
*/
EXTENDS: A.Plugin.Base,
prototype: {
/**
* Construction logic executed during Aria instantiation. Lifecycle.
*
* @method initializer
* @protected
*/
initializer: function() {
var instance = this;
instance.publish(EV_PROCESS_ATTRIBUTE, {
defaultFn: instance._defProcessFn,
queuable: false,
emitFacade: true,
bubbles: true,
prefix: ARIA
});
instance._uiSetRoleName(
instance.get(ROLE_NAME)
);
instance.after('roleNameChange', instance._afterRoleNameChange);
instance._bindHostAttributes();
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method isValidAttribute
* @param attrName
*/
isValidAttribute: function(attrName) {
var instance = this;
return (instance.get(VALIDATE_W3C) ? A.Plugin.Aria.W3C_ATTRIBUTES[attrName] : true);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method isValidRole
* @param roleName
*/
isValidRole: function(roleName) {
var instance = this;
return (instance.get(VALIDATE_W3C) ? A.Plugin.Aria.W3C_ROLES[roleName] : true);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method setAttribute
* @param attrName
* @param attrValue
* @param node
*/
setAttribute: function(attrName, attrValue, node) {
var instance = this;
if (instance.isValidAttribute(attrName)) {
(node || instance.get(ATTRIBUTE_NODE)).set(ARIA_PREFIX + attrName, attrValue);
return true;
}
return false;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method setAttributes
* @param attributes
*/
setAttributes: function(attributes) {
var instance = this;
A.Array.each(attributes, function(attribute, index, attributes) {
instance.setAttribute(attribute.name, attribute.value, attribute.node);
});
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method setRole
* @param roleName
* @param node
*/
setRole: function(roleName, node) {
var instance = this;
if (instance.isValidRole(roleName)) {
(node || instance.get(ROLE_NODE)).set(ROLE, roleName);
return true;
}
return false;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method setRoles
* @param roles
*/
setRoles: function(roles) {
var instance = this;
A.Array.each(roles, function(role, index, roles) {
instance.setRole(role.name, role.node);
});
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _afterHostAttributeChange
* @param event
* @protected
*/
_afterHostAttributeChange: function(event) {
var instance = this;
instance._handleProcessAttribute(event);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _afterRoleNameChange
* @param event
* @protected
*/
_afterRoleNameChange: function(event) {
var instance = this;
instance._uiSetRoleName(event.newVal);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _bindHostAttributes
* @protected
*/
_bindHostAttributes: function() {
var instance = this;
var attributes = instance.get(ATTRIBUTES);
A.each(attributes, function(aria, attrName) {
var ariaAttr = instance._getAriaAttribute(aria, attrName);
instance._handleProcessAttribute({
aria: ariaAttr
});
instance.afterHostEvent(attrName + CHANGE_PREFIX, function(event) {
event.aria = ariaAttr;
instance._afterHostAttributeChange(event);
});
});
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _defProcessFn
* @param event
* @protected
*/
_defProcessFn: function(event) {
var instance = this;
instance._setAttribute(event.aria);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _getAriaAttribute
* @param aria
* @param attrName
* @protected
*/
_getAriaAttribute: function(aria, attrName) {
var instance = this;
var attributeValueFormat = instance.get(ATTRIBUTE_VALUE_FORMAT);
var prepared = {};
if (isString(aria)) {
prepared = A.merge(prepared, {
ariaName: aria,
attrName: attrName,
format: attributeValueFormat,
node: null
});
}
else if (isObject(aria)) {
prepared = A.mix(aria, {
ariaName: EMPTY_STR,
attrName: attrName,
format: attributeValueFormat,
node: null
});
}
return prepared;
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _handleProcessAttribute
* @param event
* @protected
*/
_handleProcessAttribute: function(event) {
var instance = this;
instance.fire(EV_PROCESS_ATTRIBUTE, {
aria: event.aria
});
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _setAttribute
* @param ariaAttr
* @protected
*/
_setAttribute: function(ariaAttr) {
var instance = this;
var host = instance.get(HOST);
var attrValue = host.get(ariaAttr.attrName);
var attrNode = ariaAttr.node;
if (isFunction(attrNode)) {
attrNode = attrNode.apply(instance, [ariaAttr]);
}
instance.setAttribute(
ariaAttr.ariaName,
ariaAttr.format.apply(instance, [attrValue, ariaAttr]),
attrNode
);
},
/**
* TODO. Wanna help? Please send a Pull Request.
*
* @method _uiSetRoleName
* @param val
* @protected
*/
_uiSetRoleName: function(val) {
var instance = this;
instance.setRole(val);
}
}
});
A.Plugin.Aria = Aria;
/*
* W3C - The Roles Model
* http://www.w3.org/TR/wai-aria/roles
*/
A.Plugin.Aria.W3C_ROLES = {
'alert': 1,
'alertdialog': 1,
'application': 1,
'article': 1,
'banner': 1,
'button': 1,
'checkbox': 1,
'columnheader': 1,
'combobox': 1,
'command': 1,
'complementary': 1,
'composite': 1,
'contentinfo': 1,
'definition': 1,
'dialog': 1,
'directory': 1,
'document': 1,
'form': 1,
'grid': 1,
'gridcell': 1,
'group': 1,
'heading': 1,
'img': 1,
'input': 1,
'landmark': 1,
'link': 1,
'list': 1,
'listbox': 1,
'listitem': 1,
'log': 1,
'main': 1,
'marquee': 1,
'math': 1,
'menu': 1,
'menubar': 1,
'menuitem': 1,
'menuitemcheckbox': 1,
'menuitemradio': 1,
'navigation': 1,
'note': 1,
'option': 1,
'presentation': 1,
'progressbar': 1,
'radio': 1,
'radiogroup': 1,
'range': 1,
'region': 1,
'roletype': 1,
'row': 1,
'rowheader': 1,
'scrollbar': 1,
'search': 1,
'section': 1,
'sectionhead': 1,
'select': 1,
'separator': 1,
'slider': 1,
'spinbutton': 1,
'status': 1,
'structure': 1,
'tab': 1,
'tablist': 1,
'tabpanel': 1,
'textbox': 1,
'timer': 1,
'toolbar': 1,
'tooltip': 1,
'tree': 1,
'treegrid': 1,
'treeitem': 1,
'widget': 1,
'window': 1
};
/*
* W3C - Supported States and Properties
* http://www.w3.org/TR/wai-aria/states_and_properties
*/
A.Plugin.Aria.W3C_ATTRIBUTES = {
'activedescendant': 1,
'atomic': 1,
'autocomplete': 1,
'busy': 1,
'checked': 1,
'controls': 1,
'describedby': 1,
'disabled': 1,
'dropeffect': 1,
'expanded': 1,
'flowto': 1,
'grabbed': 1,
'haspopup': 1,
'hidden': 1,
'invalid': 1,
'label': 1,
'labelledby': 1,
'level': 1,
'live': 1,
'multiline': 1,
'multiselectable': 1,
'orientation': 1,
'owns': 1,
'posinset': 1,
'pressed': 1,
'readonly': 1,
'relevant': 1,
'required': 1,
'selected': 1,
'setsize': 1,
'sort': 1,
'valuemax': 1,
'valuemin': 1,
'valuenow': 1,
'valuetext': 1
};
}, '2.0.0', {"requires": ["plugin", "aui-component"]});
YUI.add('aui-io-plugin-deprecated', function (A, NAME) {
/**
* The IOPlugin Utility - When plugged to a Node or Widget loads the content
* of a URI and set as its content, parsing the script
tags if
* present on the code.
*
* @module aui-io
* @submodule aui-io-plugin
*/
var L = A.Lang,
isBoolean = L.isBoolean,
isString = L.isString,
isNode = function(v) {
return (v instanceof A.Node);
},
StdMod = A.WidgetStdMod,
TYPE_NODE = 'Node',
TYPE_WIDGET = 'Widget',
EMPTY = '',
FAILURE = 'failure',
FAILURE_MESSAGE = 'failureMessage',
HOST = 'host',
ICON = 'icon',
IO = 'io',
IO_PLUGIN = 'IOPlugin',
LOADING = 'loading',
LOADING_MASK = 'loadingMask',
NODE = 'node',
OUTER = 'outer',
PARSE_CONTENT = 'parseContent',
QUEUE = 'queue',
RENDERED = 'rendered',
SECTION = 'section',
SHOW_LOADING = 'showLoading',
SUCCESS = 'success',
TYPE = 'type',
WHERE = 'where',
getCN = A.getClassName,
CSS_ICON_LOADING = getCN(ICON, LOADING);
/**
* A base class for IOPlugin, providing:
*
* Loads the content of a URI as content of a Node or Widget
* Use ParseContent to parse the JavaScript tags from the content and evaluate them
*
*
* Quick Example:
*
* A.one('#content').plug(A.Plugin.IO, { uri: 'assets/content.html', method: 'GET' });
*
* Check the list of Configuration Attributes available for
* IOPlugin.
*
* @param config {Object} Object literal specifying widget configuration properties.
*
* @class A.Plugin.IO
* @constructor
* @extends IORequest
*/
var IOPlugin = A.Component.create(
{
/**
* Static property provides a string to identify the class.
*
* @property A.Plugin.IO.NAME
* @type String
* @static
*/
NAME: IO_PLUGIN,
/**
* Static property provides a string to identify the namespace.
*
* @property A.Plugin.IO.NS
* @type String
* @static
*/
NS: IO,
/**
* Static property used to define the default attribute
* configuration for the A.Plugin.IO.
*
* @property A.Plugin.IO.ATTRS
* @type Object
* @static
*/
ATTRS: {
/**
* Plug IO in any object we want, the setContent will use the node to
* set the content.
*
* @attribute node
* @default null
* @type Node | String
*/
node: {
value: null,
getter: function(value) {
var instance = this;
if (!value) {
var host = instance.get(HOST);
var type = instance.get(TYPE);
if (type == TYPE_NODE) {
value = host;
}
else if (type == TYPE_WIDGET) {
var section = instance.get(SECTION);
// if there is no node for the SECTION, forces creation
if (!host.getStdModNode(section)) {
host.setStdModContent(section, EMPTY);
}
value = host.getStdModNode(section);
}
}
return A.one(value);
},
validator: isNode
},
/**
* Message to be set on the content when the transaction fails.
*
* @attribute failureMessage
* @default 'Failed to retrieve content'
* @type String
*/
failureMessage: {
value: 'Failed to retrieve content',
validator: isString
},
/**
* Options passed to the LoadingMask .
*
* @attribute loadingMask
* @default {}
* @type Object
*/
loadingMask: {
value: {}
},
/**
* If true the ParseContent plugin
* will be plugged to the node .
*
* @attribute parseContent
* @default true
* @type boolean
*/
parseContent: {
value: true,
validator: isBoolean
},
/**
* Show the LoadingMask covering the node while loading.
*
* @attribute showLoading
* @default true
* @type boolean
*/
showLoading: {
value: true,
validator: isBoolean
},
/**
* Section where the content will be set in case you are plugging it
* on a instace of WidgetStdMod .
*
* @attribute section
* @default StdMod.BODY
* @type String
*/
section: {
value: StdMod.BODY,
validator: function(val) {
return (!val || val == StdMod.BODY || val == StdMod.HEADER || val == StdMod.FOOTER);
}
},
/**
* Type of the instance
we are pluggin the A.Plugin.IO.
* Could be a Node, or a Widget.
*
* @attribute type
* @default 'Node'
* @readOnly
* @type String
*/
type: {
readOnly: true,
valueFn: function() {
var instance = this;
// NOTE: default type
var type = TYPE_NODE;
if (instance.get(HOST) instanceof A.Widget) {
type = TYPE_WIDGET;
}
return type;
},
validator: isString
},
/**
* Where to insert the content, AFTER, BEFORE or REPLACE. If you're plugging a Node, there is a fourth option called OUTER that will not only replace the entire node itself. This is different from REPLACE, in that REPLACE will replace the *contents* of the node, OUTER will replace the entire Node itself.
*
* @attribute where
* @default StdMod.REPLACE
* @type String
*/
where: {
value: StdMod.REPLACE,
validator: function(val) {
return (!val || val == StdMod.AFTER || val == StdMod.BEFORE || val == StdMod.REPLACE || val == OUTER);
}
}
},
EXTENDS: A.IORequest,
prototype: {
/**
* Bind the events on the A.Plugin.IO UI. Lifecycle.
*
* @method bindUI
* @protected
*/
bindUI: function() {
var instance = this;
instance.on('activeChange', instance._onActiveChange);
instance.on(SUCCESS, instance._successHandler);
instance.on(FAILURE, instance._failureHandler);
if ((instance.get(TYPE) == TYPE_WIDGET) && instance.get(SHOW_LOADING)) {
var host = instance.get(HOST);
host.after('heightChange', instance._syncLoadingMaskUI, instance);
host.after('widthChange', instance._syncLoadingMaskUI, instance);
}
},
/**
* Invoke the start
method (autoLoad attribute).
*
* @method _autoStart
* @protected
*/
_autoStart: function() {
var instance = this;
instance.bindUI();
IOPlugin.superclass._autoStart.apply(this, arguments);
},
/**
* Bind the ParseContent plugin on the instance
.
*
* @method _bindParseContent
* @protected
*/
_bindParseContent: function() {
var instance = this;
var node = instance.get(NODE);
if (node && !node.ParseContent && instance.get(PARSE_CONTENT)) {
node.plug(A.Plugin.ParseContent);
}
},
/**
* Invoke the OverlayMask hide method.
*
* @method hideLoading
*/
hideLoading: function() {
var instance = this;
var node = instance.get(NODE);
if (node.loadingmask) {
node.loadingmask.hide();
}
},
/**
* Set the content of the node .
*
* @method setContent
*/
setContent: function(content) {
var instance = this;
instance._bindParseContent();
instance._getContentSetterByType().apply(instance, [content]);
if (instance.overlayMaskBoundingBox) {
instance.overlayMaskBoundingBox.remove();
}
},
/**
* Invoke the OverlayMask show method.
*
* @method showLoading
*/
showLoading: function() {
var instance = this;
var node = instance.get(NODE);
if (node.loadingmask) {
if (instance.overlayMaskBoundingBox) {
node.append(instance.overlayMaskBoundingBox);
}
}
else {
node.plug(
A.LoadingMask,
instance.get(LOADING_MASK)
);
instance.overlayMaskBoundingBox = node.loadingmask.overlayMask.get('boundingBox');
}
node.loadingmask.show();
},
/**
* Overload to the IORequest
* start method. Check if the host
is already rendered,
* otherwise wait to after render phase and to show the LoadingMask.
*
* @method start
*/
start: function() {
var instance = this;
var host = instance.get(HOST);
if (!host.get(RENDERED)) {
host.after('render', function() {
instance._setLoadingUI(true);
});
}
IOPlugin.superclass.start.apply(instance, arguments);
},
/**
* Get the appropriated setContent function
* implementation for each type .
*
* @method _getContentSetterByType
* @protected
* @return {function}
*/
_getContentSetterByType: function() {
var instance = this;
var setters = {
// NOTE: default setter, see 'type' attribute definition
Node: function(content) {
var instance = this;
// when this.get(HOST) is a Node instance the NODE is the host
var node = instance.get(NODE);
if (content instanceof A.NodeList) {
content = content.toFrag();
}
if (content instanceof A.Node) {
content = content._node;
}
var where = instance.get(WHERE);
if (where == OUTER) {
node.replace(content);
}
else {
node.insert(content, where);
}
},
// Widget forces set the content on the SECTION node using setStdModContent method
Widget: function(content) {
var instance = this;
var host = instance.get(HOST);
host.setStdModContent.apply(host, [
instance.get(SECTION),
content,
instance.get(WHERE)
]);
}
};
return setters[this.get(TYPE)];
},
/**
* Whether the show
is true show the LoadingMask.
*
* @method _setLoadingUI
* @param {boolean} show
* @protected
*/
_setLoadingUI: function(show) {
var instance = this;
if (instance.get(SHOW_LOADING)) {
if (show) {
instance.showLoading();
}
else {
instance.hideLoading();
}
}
},
/**
* Sync the loading mask UI.
*
* @method _syncLoadingMaskUI
* @protected
*/
_syncLoadingMaskUI: function() {
var instance = this;
instance.get(NODE).loadingmask.refreshMask();
},
/**
* Internal success callback for the IO transaction.
*
* @method _successHandler
* @param {EventFavade} event
* @param {String} id Id of the IO transaction.
* @param {Object} obj XHR transaction Object.
* @protected
*/
_successHandler: function(event, id, xhr) {
var instance = this;
instance.setContent(
this.get('responseData')
);
},
/**
* Internal failure callback for the IO transaction.
*
* @method _failureHandler
* @param {EventFavade} event
* @param {String} id Id of the IO transaction.
* @param {Object} obj XHR transaction Object.
* @protected
*/
_failureHandler: function(event, id, xhr) {
var instance = this;
instance.setContent(
instance.get(FAILURE_MESSAGE)
);
},
/**
* Fires after the value of the
* active attribute change.
*
* @method _onActiveChange
* @param {EventFacade} event
* @protected
*/
_onActiveChange: function(event) {
var instance = this;
var host = instance.get(HOST);
var widget = instance.get(TYPE) == TYPE_WIDGET;
if (!widget || (widget && host && host.get(RENDERED))) {
instance._setLoadingUI(event.newVal);
}
}
}
}
);
A.Node.prototype.load = function(uri, config, callback) {
var instance = this;
var index = uri.indexOf(' ');
var selector;
if (index > 0) {
selector = uri.slice(index, uri.length);
uri = uri.slice(0, index);
}
if (L.isFunction(config)) {
callback = config;
config = null;
}
config = config || {};
if (callback) {
config.after = config.after || {};
config.after.success = callback;
}
var where = config.where;
config.uri = uri;
config.where = where;
if (selector) {
config.selector = selector;
config.where = where || 'replace';
}
instance.plug(A.Plugin.IO, config);
return instance;
};
A.namespace('Plugin').IO = IOPlugin;
}, '2.0.0', {
"requires": [
"aui-overlay-base-deprecated",
"aui-parse-content",
"aui-io-request",
"aui-loading-mask-deprecated"
]
});
YUI.add('aui-io-request', function (A, NAME) {
/**
* The IORequest Utility - Provides response data normalization for XML, JSON,
* JavaScript and cache option.
*
* @module aui-io
* @submodule aui-io-request
*/
var L = A.Lang,
isBoolean = L.isBoolean,
isFunction = L.isFunction,
isString = L.isString,
defaults = A.namespace('config.io'),
getDefault = function(attr) {
return function() {
return defaults[attr];
};
},
ACTIVE = 'active',
ARGUMENTS = 'arguments',
AUTO_LOAD = 'autoLoad',
CACHE = 'cache',
CFG = 'cfg',
COMPLETE = 'complete',
CONTENT_TYPE = 'content-type',
CONTEXT = 'context',
DATA = 'data',
DATA_TYPE = 'dataType',
EMPTY_STRING = '',
END = 'end',
FAILURE = 'failure',
FORM = 'form',
GET = 'get',
HEADERS = 'headers',
IO_REQUEST = 'IORequest',
JSON = 'json',
METHOD = 'method',
RESPONSE_DATA = 'responseData',
START = 'start',
SUCCESS = 'success',
SYNC = 'sync',
TIMEOUT = 'timeout',
TRANSACTION = 'transaction',
URI = 'uri',
XDR = 'xdr',
XML = 'xml',
PARSE_ERROR = 'Parser error: IO dataType is not correctly parsing',
ACCEPTS = {
all: '*/*',
html: 'text/html',
json: 'application/json, text/javascript',
text: 'text/plain',
xml: 'application/xml, text/xml'
};
/**
* A base class for IORequest, providing:
*
* Response data normalization for XML, JSON, JavaScript
* Cache options
*
*
* Check the [live demo](http://alloyui.com/examples/io/).
*
* @class A.IORequest
* @extends A.Plugin.Base
* @param config {Object} Object literal specifying widget configuration properties.
* @uses io
* @constructor
*/
var IORequest = A.Component.create({
/**
* Static property provides a string to identify the class.
*
* @property IORequest.NAME
* @type String
* @static
*/
NAME: IO_REQUEST,
/**
* Static property used to define the default attribute
* configuration for the IORequest.
*
* @property IORequest.ATTRS
* @type Object
* @static
*/
ATTRS: {
/**
* If true
invoke the
* start method
* automatically, initializing the IO transaction.
*
* @attribute autoLoad
* @default true
* @type Boolean
*/
autoLoad: {
value: true,
validator: isBoolean
},
/**
* If false
the current timestamp will be appended to the
* url, avoiding the url to be cached.
*
* @attribute cache
* @default true
* @type Boolean
*/
cache: {
value: true,
validator: isBoolean
},
/**
* The type of the request (i.e., could be xml, json, javascript, text).
*
* @attribute dataType
* @default null
* @type String
*/
dataType: {
setter: function(v) {
return (v || EMPTY_STRING).toLowerCase();
},
value: null,
validator: isString
},
/**
* This is a normalized attribute for the response data. It's useful
* to retrieve the correct type for the
* dataType (i.e., in json
* requests the responseData
) is a JSONObject.
*
* @attribute responseData
* @default null
* @type String | JSONObject | XMLDocument
*/
responseData: {
setter: function(v) {
return this._setResponseData(v);
},
value: null
},
/**
* URI to be requested using AJAX.
*
* @attribute uri
* @default null
* @type String
*/
uri: {
setter: function(v) {
return this._parseURL(v);
},
value: null,
validator: isString
},
// User readOnly variables
/**
* Whether the transaction is active or not.
*
* @attribute active
* @default false
* @type Boolean
*/
active: {
value: false,
validator: isBoolean
},
/**
* Object containing all the
* IO Configuration Attributes .
* This Object is passed to the A.io
internally.
*
* @attribute cfg
* @default Object containing all the
* IO Configuration Attributes .
* @readOnly
* @type String
*/
cfg: {
getter: function() {
var instance = this;
// keep the current cfg object always synchronized with the mapped public attributes
// when the user call .start() it always retrieve the last set values for each mapped attr
return {
arguments: instance.get(ARGUMENTS),
context: instance.get(CONTEXT),
data: instance.getFormattedData(),
form: instance.get(FORM),
headers: instance.get(HEADERS),
method: instance.get(METHOD),
on: {
complete: A.bind(instance.fire, instance, COMPLETE),
end: A.bind(instance._end, instance),
failure: A.bind(instance.fire, instance, FAILURE),
start: A.bind(instance.fire, instance, START),
success: A.bind(instance._success, instance)
},
sync: instance.get(SYNC),
timeout: instance.get(TIMEOUT),
xdr: instance.get(XDR)
};
},
readOnly: true
},
/**
* Stores the IO Object of the current transaction.
*
* @attribute transaction
* @default null
* @type Object
*/
transaction: {
value: null
},
// Configuration Object mapping
// To take advantages of the Attribute listeners of A.Base
// See: http://yuilibrary.com/yui/docs/io/
/**
* See IO
* Configuration .
*
* @attribute arguments
* @default Value mapped on YUI.AUI.defaults.io.
* @type Object
*/
arguments: {
valueFn: getDefault(ARGUMENTS)
},
/**
* See IO
* Configuration .
*
* @attribute context
* @default Value mapped on YUI.AUI.defaults.io.
* @type Object
*/
context: {
valueFn: getDefault(CONTEXT)
},
/**
* See IO
* Configuration .
*
* @attribute data
* @default Value mapped on YUI.AUI.defaults.io.
* @type Object
*/
data: {
valueFn: getDefault(DATA)
},
/**
* See IO
* Configuration .
*
* @attribute form
* @default Value mapped on YUI.AUI.defaults.io.
* @type Object
*/
form: {
valueFn: getDefault(FORM)
},
/**
* Set the correct ACCEPT header based on the dataType.
*
* @attribute headers
* @default Object
* @type Object
*/
headers: {
getter: function(value) {
var header = [];
var instance = this;
var dataType = instance.get(DATA_TYPE);
if (dataType) {
header.push(
ACCEPTS[dataType]
);
}
// always add *.* to the accept header
header.push(
ACCEPTS.all
);
return A.merge(
value, {
Accept: header.join(', ')
}
);
},
valueFn: getDefault(HEADERS)
},
/**
* See IO
* Configuration .
*
* @attribute method
* @default Value mapped on YUI.AUI.defaults.io.
* @type String
*/
method: {
valueFn: getDefault(METHOD)
},
/**
* A selector to be used to query against the response of the
* request. Only works if the response is XML or HTML.
*
* @attribute selector
* @default null
* @type String
*/
selector: {
value: null
},
/**
* See IO
* Configuration .
*
* @attribute sync
* @default Value mapped on YUI.AUI.defaults.io.
* @type Boolean
*/
sync: {
valueFn: getDefault(SYNC)
},
/**
* See IO
* Configuration .
*
* @attribute timeout
* @default Value mapped on YUI.AUI.defaults.io.
* @type Number
*/
timeout: {
valueFn: getDefault(TIMEOUT)
},
/**
* See IO
* Configuration .
*
* @attribute xdr
* @default Value mapped on YUI.AUI.defaults.io.
* @type Object
*/
xdr: {
valueFn: getDefault(XDR)
}
},
/**
* Static property used to define which component it extends.
*
* @property IORequest.EXTENDS
* @type Object
* @static
*/
EXTENDS: A.Plugin.Base,
prototype: {
/**
* Construction logic executed during IORequest instantiation. Lifecycle.
*
* @method initializer
* @param config
* @protected
*/
init: function(config) {
var instance = this;
IORequest.superclass.init.apply(this, arguments);
instance._autoStart();
},
/**
* Destructor lifecycle implementation for the IORequest class.
* Purges events attached to the node (and all child nodes).
*
* @method destructor
* @protected
*/
destructor: function() {
var instance = this;
instance.stop();
instance.set(TRANSACTION, null);
},
/**
* Applies the YUI.AUI.defaults.io.dataFormatter
if
* defined and return the formatted data.
*
* @method getFormattedData
* @return {String}
*/
getFormattedData: function() {
var instance = this;
var value = instance.get(DATA);
var dataFormatter = defaults.dataFormatter;
if (isFunction(dataFormatter)) {
value = dataFormatter.call(instance, value);
}
return value;
},
/**
* Starts the IO transaction. Used to refresh the content also.
*
* @method start
*/
start: function() {
var instance = this;
instance.destructor();
instance.set(ACTIVE, true);
var ioObj = instance._yuiIOObj;
if (!ioObj) {
ioObj = new A.IO();
instance._yuiIOObj = ioObj;
}
var transaction = ioObj.send(
instance.get(URI),
instance.get(CFG)
);
instance.set(TRANSACTION, transaction);
},
/**
* Stops the IO transaction.
*
* @method stop
*/
stop: function() {
var instance = this;
var transaction = instance.get(TRANSACTION);
if (transaction) {
transaction.abort();
}
},
/**
* Invoke the start
method (autoLoad attribute).
*
* @method _autoStart
* @protected
*/
_autoStart: function() {
var instance = this;
if (instance.get(AUTO_LOAD)) {
instance.start();
}
},
/**
* Parse the uri to add a
* timestamp if cache is
* true
. Also applies the
* YUI.AUI.defaults.io.uriFormatter
.
*
* @method _parseURL
* @param {String} url
* @protected
* @return {String}
*/
_parseURL: function(url) {
var instance = this;
var cache = instance.get(CACHE);
var method = instance.get(METHOD);
// reusing logic to add a timestamp on the url from jQuery 1.3.2
if ((cache === false) && (method == GET)) {
var ts = +new Date;
// try replacing _= if it is there
var ret = url.replace(/(\?|&)_=.*?(&|$)/, '$1_=' + ts + '$2');
// if nothing was replaced, add timestamp to the end
url = ret + ((ret == url) ? (url.match(/\?/) ? '&' : '?') + '_=' + ts : '');
}
// formatting the URL with the default uriFormatter after the cache timestamp was added
var uriFormatter = defaults.uriFormatter;
if (isFunction(uriFormatter)) {
url = uriFormatter.apply(instance, [url]);
}
return url;
},
/**
* Internal end callback for the IO transaction.
*
* @method _end
* @param {Number} id ID of the IO transaction.
* @param {Object} args Custom arguments, passed to the event handler. See IO
* @protected
*/
_end: function(id, args) {
var instance = this;
instance.set(ACTIVE, false);
instance.set(TRANSACTION, null);
instance.fire(END, id, args);
},
/**
* Internal success callback for the IO transaction.
*
* @method _success
* @param {Number} id ID of the IO transaction.
* @param {Object} obj IO transaction Object.
* @param {Object} args Custom arguments, passed to the event handler. See IO
* @protected
*/
_success: function(id, obj, args) {
var instance = this;
// update the responseData attribute with the new data from xhr
instance.set(RESPONSE_DATA, obj);
instance.fire(SUCCESS, id, obj, args);
},
/**
* Setter for responseData .
*
* @method _setResponseData
* @protected
* @param {Object} xhr XHR Object.
* @return {Object}
*/
_setResponseData: function(xhr) {
var data = null;
var instance = this;
if (xhr) {
var dataType = instance.get(DATA_TYPE);
var contentType = xhr.getResponseHeader(CONTENT_TYPE) || '';
// if the dataType or the content-type is XML...
if ((dataType == XML) ||
(!dataType && contentType.indexOf(XML) >= 0)) {
// use responseXML
data = xhr.responseXML;
// check if the XML was parsed correctly
if (data.documentElement.tagName == 'parsererror') {
throw PARSE_ERROR;
}
}
else {
// otherwise use the responseText
data = xhr.responseText;
}
// empty string is not a valid JSON, convert it to null
if (data === EMPTY_STRING) {
data = null;
}
// trying to parse to JSON if dataType is a valid json
if (dataType == JSON) {
try {
data = A.JSON.parse(data);
}
catch (e) {
// throw PARSE_ERROR;
}
}
else {
var selector = instance.get('selector');
if (data && selector) {
var tempRoot;
if (data.documentElement) {
tempRoot = A.one(data);
}
else {
tempRoot = A.Node.create(data);
}
data = tempRoot.all(selector);
}
}
}
return data;
}
}
});
A.IORequest = IORequest;
/**
* Alloy IO extension
*
* @class A.io
* @static
*/
/**
* Static method to invoke the IORequest .
* Likewise io .
*
* @method A.io.request
* @for A.io
* @param {String} uri URI to be requested.
* @param {Object} config Configuration Object for the IO .
* @return {IORequest}
*/
A.io.request = function(uri, config) {
return new A.IORequest(
A.merge(config, {
uri: uri
})
);
};
}, '2.0.0', {"requires": ["io-base", "json", "plugin", "querystring-stringify", "aui-component"]});
YUI.add('aui-loading-mask-deprecated', function (A, NAME) {
/**
* The LoadingMask Utility
*
* @module aui-loading-mask
*/
var Lang = A.Lang,
BOUNDING_BOX = 'boundingBox',
CONTENT_BOX = 'contentBox',
HIDE = 'hide',
HOST = 'host',
MESSAGE_EL = 'messageEl',
NAME = 'loadingmask',
POSITION = 'position',
SHOW = 'show',
STATIC = 'static',
STRINGS = 'strings',
TARGET = 'target',
TOGGLE = 'toggle',
getClassName = A.getClassName,
CSS_LOADINGMASK = getClassName(NAME),
CSS_MASKED = getClassName(NAME, 'masked'),
CSS_MASKED_RELATIVE = getClassName(NAME, 'masked', 'relative'),
CSS_MESSAGE_LOADING = getClassName(NAME, 'message'),
CSS_MESSAGE_LOADING_CONTENT = getClassName(NAME, 'message', 'content'),
TPL_MESSAGE_LOADING = '';
/**
*
*
* A base class for LoadingMask, providing:
*
* Cross browser mask functionality to cover an element or the entire page
* Customizable mask (i.e., background, opacity)
* Display a centered "loading" message on the masked node
*
*
* Quick Example:
*
* node.plug(A.LoadingMask, { background: '#000' });
*
* Check the list of Configuration Attributes available for
* LoadingMask.
*
* @param config {Object} Object literal specifying widget configuration properties.
*
* @class LoadingMask
* @constructor
* @extends Plugin.Base
*/
var LoadingMask = A.Component.create(
{
/**
* Static property provides a string to identify the class.
*
* @property LoadingMask.NAME
* @type String
* @static
*/
NAME: NAME,
/**
* Static property provides a string to identify the namespace.
*
* @property LoadingMask.NS
* @type String
* @static
*/
NS: NAME,
/**
* Static property used to define the default attribute
* configuration for the LoadingMask.
*
* @property LoadingMask.ATTRS
* @type Object
* @static
*/
ATTRS: {
/**
* Node element to display the message.
*
* @attribute messageEl
* @default Generated HTML div element.
* @type String
*/
messageEl: {
valueFn: function(val) {
var instance = this;
var strings = instance.get(STRINGS);
return A.Node.create(
Lang.sub(TPL_MESSAGE_LOADING, [strings.loading])
);
}
},
/**
* Strings used on the LoadingMask. See
* strings .
*
* @attribute strings
* @default { loading: 'Loading…' }
* @type Object
*/
strings: {
value: {
loading: 'Loading…'
}
},
/**
* Node where the mask will be positioned and re-dimensioned.
*
* @attribute target
* @default null
* @type Node | Widget
*/
target: {
setter: function() {
var instance = this;
var target = instance.get(HOST);
if (target instanceof A.Widget) {
target = target.get(CONTENT_BOX);
}
return target;
},
value: null
}
},
EXTENDS: A.Plugin.Base,
prototype: {
/**
* Construction logic executed during LoadingMask instantiation. Lifecycle.
*
* @method initializer
* @protected
*/
initializer: function(config) {
var instance = this;
instance.IGNORED_ATTRS = A.merge(
{
host: true
},
LoadingMask.ATTRS
);
instance.renderUI();
instance.bindUI();
instance._createDynamicAttrs(config);
},
/**
* Create the DOM structure for the LoadingMask. Lifecycle.
*
* @method renderUI
* @protected
*/
renderUI: function() {
var instance = this;
var strings = instance.get(STRINGS);
instance._renderOverlayMask();
instance.overlayMask.get(BOUNDING_BOX).append(
instance.get(MESSAGE_EL)
);
},
/**
* Bind the events on the LoadingMask UI. Lifecycle.
*
* @method bindUI
* @protected
*/
bindUI: function() {
var instance = this;
instance._bindOverlayMaskUI();
},
/**
* Bind events to the
* overlayMask .
*
* @method _bindOverlayMaskUI
* @protected
*/
_bindOverlayMaskUI: function() {
var instance = this;
instance.overlayMask.after('visibleChange', instance._afterVisibleChange, instance);
},
/**
* Center the
* messageEl with the
* target node.
*
* @method centerMessage
*/
centerMessage: function() {
var instance = this;
instance.get(MESSAGE_EL).center(
instance.overlayMask.get(BOUNDING_BOX)
);
},
/**
* Invoke the
* overlayMask
* refreshMask
method.
*
* @method refreshMask
*/
refreshMask: function() {
var instance = this;
instance.overlayMask.refreshMask();
instance.centerMessage();
},
/**
* Fires after the value of the
* visible attribute change.
*
* @method _afterVisibleChange
* @param {EventFacade} event
* @protected
*/
_afterVisibleChange: function(event) {
var instance = this;
var target = instance.get(TARGET);
var isStaticPositioned = (target.getStyle(POSITION) == STATIC);
target.toggleClass(CSS_MASKED, (event.newVal));
target.toggleClass(CSS_MASKED_RELATIVE, (event.newVal && isStaticPositioned));
if (event.newVal) {
instance.refreshMask();
}
},
/**
* Render
* overlayMask
* instance.
*
* @method _renderOverlayMask
* @protected
*/
_renderOverlayMask: function() {
var instance = this;
var target = instance.get(TARGET);
/**
* Stores the OverlayMask used
* internally.
*
* @property overlayMask
* @type OverlayMask
* @protected
*/
instance.overlayMask = new A.OverlayMask(
{
target: target,
cssClass: CSS_LOADINGMASK
}
).render(target);
},
/**
* Create dynamic attributes listeners to invoke the setter on
* overlayMask after
* the attribute is set on the LoadingMask instance.
*
* @method _createDynamicAttrs
* @param {Object} config Object literal specifying widget configuration properties.
* @protected
*/
_createDynamicAttrs: function(config) {
var instance = this;
A.each(config, function(value, key) {
var ignoredAttr = instance.IGNORED_ATTRS[key];
if (!ignoredAttr) {
instance.addAttr(key, {
setter: function(val) {
this.overlayMask.set(key, val);
return val;
},
value: value
});
}
});
}
}
}
);
A.each([HIDE, SHOW, TOGGLE], function(method) {
/**
* Invoke the
* overlayMask
* hide
method.
*
* @method hide
*/
/**
* Invoke the
* overlayMask
* show
method.
*
* @method show
*/
/**
* Invoke the
* overlayMask
* toggle
method.
*
* @method toggle
*/
LoadingMask.prototype[method] = function() {
this.overlayMask[method]();
};
});
A.LoadingMask = LoadingMask;
}, '2.0.0', {"requires": ["plugin", "aui-overlay-mask-deprecated"], "skinnable": true});
YUI.add('aui-overlay-base-deprecated', function (A, NAME) {
/**
* Provides a basic Overlay widget, with Standard Module content support. The Overlay widget
* provides Page XY positioning support, alignment and centering support along with basic
* stackable support (z-index and shimming).
*
* @module aui-overlay
* @submodule aui-overlay-base
*/
/**
* A basic Overlay Widget, which can be positioned based on Page XY co-ordinates and is stackable (z-index support).
* It also provides alignment and centering support and uses a standard module format for it's content, with header,
* body and footer section support.
*
* @class OverlayBase
* @constructor
* @extends Component
* @uses WidgetStdMod
* @uses WidgetPosition
* @uses WidgetStack
* @uses WidgetPositionAlign
* @uses WidgetPositionConstrain
* @param {Object} object The user configuration for the instance.
*/
A.OverlayBase = A.Component.create(
{
NAME: 'overlay',
ATTRS: {
hideClass: {
value: false
}
},
AUGMENTS: [A.WidgetPosition, A.WidgetStack, A.WidgetPositionAlign, A.WidgetPositionConstrain, A.WidgetStdMod]
}
);
}, '2.0.0', {
"requires": [
"widget-position",
"widget-stack",
"widget-position-align",
"widget-position-constrain",
"widget-stdmod",
"aui-component"
]
});
YUI.add('aui-overlay-context-deprecated', function (A, NAME) {
/**
* The OverlayContext Utility
*
* @module aui-overlay
* @submodule aui-overlay-context
*/
var L = A.Lang,
isString = L.isString,
isNumber = L.isNumber,
isObject = L.isObject,
isBoolean = L.isBoolean,
isNodeList = function(v) {
return (v instanceof A.NodeList);
},
ALIGN = 'align',
BL = 'bl',
BOUNDING_BOX = 'boundingBox',
CANCELLABLE_HIDE = 'cancellableHide',
OVERLAY_CONTEXT = 'overlaycontext',
CURRENT_NODE = 'currentNode',
FOCUSED = 'focused',
HIDE = 'hide',
HIDE_DELAY = 'hideDelay',
HIDE_ON = 'hideOn',
HIDE_ON_DOCUMENT_CLICK = 'hideOnDocumentClick',
MOUSEDOWN = 'mousedown',
SHOW = 'show',
SHOW_DELAY = 'showDelay',
SHOW_ON = 'showOn',
TL = 'tl',
TRIGGER = 'trigger',
USE_ARIA = 'useARIA',
VISIBLE = 'visible';
/**
*
*
* A base class for OverlayContext, providing:
*
* Widget Lifecycle (initializer, renderUI, bindUI, syncUI, destructor)
* Able to display an Overlay at a specified corner of an element trigger
*
*
* Quick Example:
*
* var instance = new A.OverlayContext({
* boundingBox: '#OverlayBoundingBox',
* hideOn: 'mouseleave',
* showOn: 'mouseenter',
* trigger: '.menu-trigger'
* }).render();
*
*
* Check the list of Configuration Attributes available for
* OverlayContext.
*
* @class OverlayContext
* @constructor
* @extends OverlayBase
* @param config {Object} Object literal specifying widget configuration properties.
*/
var OverlayContext = A.Component.create(
{
/**
* Static property provides a string to identify the class.
*
* @property OverlayContext.NAME
* @type String
* @static
*/
NAME: OVERLAY_CONTEXT,
/**
* Static property used to define the default attribute
* configuration for the OverlayContext.
*
* @property OverlayContext.ATTRS
* @type Object
* @static
*/
ATTRS: {
/**
* Inherited from Overlay .
*
* @attribute align
* @default { node: null, points: [ TL, BL ] }
* @type Object
*/
align: {
value: { node: null, points: [ TL, BL ] }
},
/**
* Cancel auto hide delay if the user interact with the Overlay
* (focus, click, mouseover)
*
* @attribute cancellableHide
* @default true
* @type boolean
*/
cancellableHide: {
value: true,
validator: isBoolean
},
/**
* OverlayContext allow multiple elements to be the
* trigger , the
* currentNode stores the current active one.
*
* @attribute currentNode
* @default First item of the
* trigger NodeList.
* @type Node
*/
currentNode: {
valueFn: function() {
// define default currentNode as the first item from trigger
return this.get(TRIGGER).item(0);
}
},
delay: {
value: null,
validator: isObject
},
/**
* The event which is responsible to hide the OverlayContext.
*
* @attribute hideOn
* @default mouseout
* @type String
*/
hideOn: {
lazyAdd: false,
value: 'mouseout',
setter: function(v) {
return this._setHideOn(v);
}
},
/**
* If true the instance is registered on the
* OverlayContextManager static
* class and will be hide when the user click on document.
*
* @attribute hideOnDocumentClick
* @default true
* @type boolean
*/
hideOnDocumentClick: {
lazyAdd: false,
setter: function(v) {
return this._setHideOnDocumentClick(v);
},
value: true,
validator: isBoolean
},
/**
* Number of milliseconds after the hide method is invoked to hide the
* OverlayContext.
*
* @attribute hideDelay
* @default 0
* @type Number
*/
hideDelay: {
lazyAdd: false,
setter: '_setHideDelay',
value: 0,
validator: isNumber
},
/**
* The event which is responsible to show the OverlayContext.
*
* @attribute showOn
* @default mouseover
* @type String
*/
showOn: {
lazyAdd: false,
value: 'mouseover',
setter: function(v) {
return this._setShowOn(v);
}
},
/**
* Number of milliseconds after the show method is invoked to show the
* OverlayContext.
*
* @attribute showDelay
* @default 0
* @type Number
*/
showDelay: {
lazyAdd: false,
setter: '_setShowDelay',
value: 0,
validator: isNumber
},
/**
* Node, NodeList or Selector which will be used as trigger elements
* to show or hide the OverlayContext.
*
* @attribute trigger
* @default null
* @type {Node | NodeList | String}
*/
trigger: {
lazyAdd: false,
setter: function(v) {
if (isNodeList(v)) {
return v;
}
else if (isString(v)) {
return A.all(v);
}
return new A.NodeList([v]);
}
},
/**
* True if Overlay should use ARIA plugin
*
* @attribute useARIA
* @default true
* @type Boolean
*/
useARIA: {
value: true
},
/**
* If true the OverlayContext is visible by default after the render phase.
* Inherited from Overlay .
*
* @attribute visible
* @default false
* @type boolean
*/
visible: {
value: false
}
},
EXTENDS: A.OverlayBase,
constructor: function(config) {
var instance = this;
instance._showCallback = null;
instance._hideCallback = null;
OverlayContext.superclass.constructor.apply(this, arguments);
},
prototype: {
/**
* Construction logic executed during OverlayContext instantiation. Lifecycle.
*
* @method initializer
* @protected
*/
initializer: function() {
var instance = this;
var trigger = instance.get(TRIGGER);
if (trigger && trigger.size()) {
instance.set('align.node', trigger.item(0));
}
},
/**
* Bind the events on the OverlayContext UI. Lifecycle.
*
* @method bindUI
* @protected
*/
bindUI: function(){
var instance = this;
var boundingBox = instance.get(BOUNDING_BOX);
boundingBox.on(MOUSEDOWN, instance._stopTriggerEventPropagation);
instance.before('triggerChange', instance._beforeTriggerChange);
instance.before('showOnChange', instance._beforeShowOnChange);
instance.before('hideOnChange', instance._beforeHideOnChange);
instance.after('triggerChange', instance._afterTriggerChange);
instance.after('showOnChange', instance._afterShowOnChange);
instance.after('hideOnChange', instance._afterHideOnChange);
boundingBox.on('click', A.bind(instance._cancelAutoHide, instance));
boundingBox.on('mouseenter', A.bind(instance._cancelAutoHide, instance));
boundingBox.on('mouseleave', A.bind(instance._invokeHideTaskOnInteraction, instance));
instance.after('focusedChange', A.bind(instance._invokeHideTaskOnInteraction, instance));
instance.on('visibleChange', instance._onVisibleChangeOverlayContext);
},
/**
* Hides the OverlayContext.
*
* @method hide
*/
hide: function() {
var instance = this;
instance.clearIntervals();
instance.fire('hide');
OverlayContext.superclass.hide.apply(instance, arguments);
},
/**
* Shows the OverlayContext.
*
* @method hide
*/
show: function(event) {
var instance = this;
instance.clearIntervals();
instance.updateCurrentNode(event);
instance.fire('show');
OverlayContext.superclass.show.apply(instance, arguments);
instance.refreshAlign();
},
/**
* Refreshes the rendered UI, based on Widget State
*
* @method syncUI
* @protected
*
*/
syncUI: function() {
var instance = this;
if (instance.get(USE_ARIA)) {
instance.plug(A.Plugin.Aria, {
attributes: {
trigger: {
ariaName: 'controls',
format: function(value) {
var id = instance.get(BOUNDING_BOX).generateID();
return id;
},
node: function() {
return instance.get(TRIGGER);
}
},
visible: {
ariaName: 'hidden',
format: function(value) {
return !value;
}
}
},
roleName: 'dialog'
});
}
},
/**
* Toggles visibility of the OverlayContext.
*
* @method toggle
* @param {EventFacade} event
*/
toggle: function(event) {
var instance = this;
if (instance.get(VISIBLE)) {
instance._hideTask(event);
}
else {
instance._showTask(event);
}
},
/**
* Clear the intervals to show or hide the OverlayContext. See
* hideDelay and
* showDelay .
*
* @method clearIntervals
*/
clearIntervals: function() {
this._hideTask.cancel();
this._showTask.cancel();
},
/**
* Refreshes the alignment of the OverlayContext with the
* currentNode . See
* also align .
*
* @method refreshAlign
*/
refreshAlign: function() {
var instance = this;
var align = instance.get(ALIGN);
var currentNode = instance.get(CURRENT_NODE);
if (currentNode) {
instance._uiSetAlign(currentNode, align.points);
}
},
/**
* Update the
* currentNode with the
* align node or the
* event.currentTarget and in last case with the first item of the
* trigger .
*
* @method updateCurrentNode
* @param {EventFacade} event
*/
updateCurrentNode: function(event) {
var instance = this;
var align = instance.get(ALIGN);
var trigger = instance.get(TRIGGER);
var currentTarget = null;
if (event) {
currentTarget = event.currentTarget;
}
var node = currentTarget || trigger.item(0) || align.node;
if (node) {
instance.set(CURRENT_NODE, node);
}
},
/**
* Handles the logic for the
* toggle .
*
* @method _toggle
* @param {EventFacade} event
* @protected
*/
_toggle: function(event) {
var instance = this;
if (instance.get('disabled')) {
return;
}
var currentTarget = event.currentTarget;
// check if the target is different and simulate a .hide() before toggle
if (instance._lastTarget != currentTarget) {
instance.hide();
}
instance.toggle(event);
event.stopPropagation();
instance._lastTarget = currentTarget;
},
/**
* Fires after the showOn
* attribute change.
*
* @method _afterShowOnChange
* @param {EventFacade} event
* @protected
*/
_afterShowOnChange: function(event) {
var instance = this;
var wasToggle = event.prevVal == instance.get(HIDE_ON);
if (wasToggle) {
var trigger = instance.get(TRIGGER);
// if wasToggle remove the toggle callback
trigger.detach(event.prevVal, instance._hideCallback);
// and re attach the hide event
instance._setHideOn( instance.get(HIDE_ON) );
}
},
/**
* Fires after the hideOn
* attribute change.
*
* @method _afterHideOnChange
* @param {EventFacade} event
* @protected
*/
_afterHideOnChange: function(event) {
var instance = this;
var wasToggle = event.prevVal == instance.get(SHOW_ON);
if (wasToggle) {
var trigger = instance.get(TRIGGER);
// if wasToggle remove the toggle callback
trigger.detach(event.prevVal, instance._showCallback);
// and re attach the show event
instance._setShowOn( instance.get(SHOW_ON) );
}
},
/**
* Fires after the trigger
* attribute change.
*
* @method _afterTriggerChange
* @param {EventFacade} event
* @protected
*/
_afterTriggerChange: function(event) {
var instance = this;
instance._setShowOn( instance.get(SHOW_ON) );
instance._setHideOn( instance.get(HIDE_ON) );
},
/**
* Fires before the showOn
* attribute change.
*
* @method _beforeShowOnChange
* @param {EventFacade} event
* @protected
*/
_beforeShowOnChange: function(event) {
var instance = this;
var trigger = instance.get(TRIGGER);
// detach the old callback
trigger.detach(event.prevVal, instance._showCallback);
},
/**
* Fires before the hideOn
* attribute change.
*
* @method _beforeHideOnChange
* @param {EventFacade} event
* @protected
*/
_beforeHideOnChange: function(event) {
var instance = this;
var trigger = instance.get(TRIGGER);
// detach the old callback
trigger.detach(event.prevVal, instance._hideCallback);
},
/**
* Fires before the trigger
* attribute change.
*
* @method _beforeTriggerChange
* @param {EventFacade} event
* @protected
*/
_beforeTriggerChange: function(event) {
var instance = this;
var trigger = instance.get(TRIGGER);
var showOn = instance.get(SHOW_ON);
var hideOn = instance.get(HIDE_ON);
trigger.detach(showOn, instance._showCallback);
trigger.detach(hideOn, instance._hideCallback);
trigger.detach(MOUSEDOWN, instance._stopTriggerEventPropagation);
},
/**
* Cancel hide event if the user does some interaction with the
* OverlayContext (focus, click or mouseover).
*
* @method _cancelAutoHide
* @param {EventFacade} event
* @protected
*/
_cancelAutoHide: function(event) {
var instance = this;
if (instance.get(CANCELLABLE_HIDE)) {
instance.clearIntervals();
}
event.stopPropagation();
},
/**
* Invoke the hide event when the OverlayContext looses the focus.
*
* @method _invokeHideTaskOnInteraction
* @param {EventFacade} event
* @protected
*/
_invokeHideTaskOnInteraction: function(event) {
var instance = this;
var cancellableHide = instance.get(CANCELLABLE_HIDE);
var focused = instance.get(FOCUSED);
if (!focused && !cancellableHide) {
instance._hideTask();
}
},
/**
* Fires when the visible
* attribute changes.
*
* @method _onVisibleChangeOverlayContext
* @param {EventFacade} event
* @protected
*/
_onVisibleChangeOverlayContext: function(event) {
var instance = this;
if (event.newVal && instance.get('disabled')) {
event.preventDefault();
}
},
/**
* Helper method to invoke event.stopPropagation().
*
* @method _stopTriggerEventPropagation
* @param {EventFacade} event
* @protected
*/
_stopTriggerEventPropagation: function(event) {
event.stopPropagation();
},
/**
* Setter for the
* hideDelay
* attribute.
*
* @method _setHideDelay
* @param {number} val
* @protected
* @return {number}
*/
_setHideDelay: function(val) {
var instance = this;
instance._hideTask = A.debounce(instance.hide, val, instance);
return val;
},
/**
* Setter for the hideOn
* attribute.
*
* @method _setHideOn
* @param {String} eventType Event type
* @protected
* @return {String}
*/
_setHideOn: function(eventType) {
var instance = this;
var trigger = instance.get(TRIGGER);
var toggle = eventType == instance.get(SHOW_ON);
if (toggle) {
instance._hideCallback = A.bind(instance._toggle, instance);
// only one attached event is enough for toggle
trigger.detach(eventType, instance._showCallback);
}
else {
var delay = instance.get(HIDE_DELAY);
instance._hideCallback = function(event) {
instance._hideTask(event);
event.stopPropagation();
};
}
trigger.on(eventType, instance._hideCallback);
return eventType;
},
/**
* Setter for the
* hideOnDocumentClick
* attribute.
*
* @method _setHideOn
* @param {boolean} value
* @protected
* @return {boolean}
*/
_setHideOnDocumentClick: function(value) {
var instance = this;
if (value) {
A.OverlayContextManager.register(instance);
}
else {
A.OverlayContextManager.remove(instance);
}
return value;
},
/**
* Setter for the
* showDelay
* attribute.
*
* @method _setShowDelay
* @param {number} val
* @protected
* @return {number}
*/
_setShowDelay: function(val) {
var instance = this;
instance._showTask = A.debounce(instance.show, val, instance);
return val;
},
/**
* Setter for the showOn
* attribute.
*
* @method _setShowOn
* @param {String} eventType Event type
* @protected
* @return {String}
*/
_setShowOn: function(eventType) {
var instance = this;
var trigger = instance.get(TRIGGER);
var toggle = eventType == instance.get(HIDE_ON);
if (toggle) {
instance._showCallback = A.bind(instance._toggle, instance);
// only one attached event is enough for toggle
trigger.detach(eventType, instance._hideCallback);
}
else {
var delay = instance.get(SHOW_DELAY);
instance._showCallback = function(event) {
instance._showTask(event);
event.stopPropagation();
};
}
if (eventType != MOUSEDOWN) {
trigger.on(MOUSEDOWN, instance._stopTriggerEventPropagation);
}
else {
trigger.detach(MOUSEDOWN, instance._stopTriggerEventPropagation);
}
trigger.on(eventType, instance._showCallback);
return eventType;
}
}
}
);
A.OverlayContext = OverlayContext;
/**
* A base class for OverlayContextManager:
*
* @param config {Object} Object literal specifying widget configuration properties.
*
* @class OverlayContextManager
* @constructor
* @extends OverlayManager
* @static
*/
A.OverlayContextManager = new A.OverlayManager({});
A.on(MOUSEDOWN, function() { A.OverlayContextManager.hideAll(); }, A.getDoc());
}, '2.0.0', {"requires": ["aui-overlay-manager-deprecated", "aui-delayed-task-deprecated", "aui-aria"]});
YUI.add('aui-overlay-manager-deprecated', function (A, NAME) {
/**
* The OverlayManager Utility
*
* @module aui-overlay
* @submodule aui-overlay-manager
*/
var Lang = A.Lang,
isArray = Lang.isArray,
isBoolean = Lang.isBoolean,
isNumber = Lang.isNumber,
isString = Lang.isString,
BOUNDING_BOX = 'boundingBox',
DEFAULT = 'default',
HOST = 'host',
OVERLAY_MANAGER = 'OverlayManager',
GROUP = 'group',
Z_INDEX = 'zIndex',
Z_INDEX_BASE = 'zIndexBase';
/**
*
*
* A base class for OverlayManager, providing:
*
* Grouping overlays
* Show or hide the entire group of registered overlays
* Basic Overlay Stackability (zIndex support)
*
*
* Quick Example:
*
* var groupOverlayManager = new A.OverlayManager();
* groupOverlayManager.register([overlay1, overlay2, overlay3]);
* groupOverlayManager.hideAll();
*
*
* Check the list of Configuration Attributes available for
* OverlayManager.
*
* @param config {Object} Object literal specifying widget configuration properties.
*
* @class OverlayManager
* @constructor
* @extends Base
*/
var OverlayManager = A.Component.create(
{
/**
* Static property provides a string to identify the class.
*
* @property OverlayManager.NAME
* @type String
* @static
*/
NAME: OVERLAY_MANAGER.toLowerCase(),
/**
* Static property used to define the default attribute
* configuration for the OverlayManager.
*
* @property OverlayManager.ATTRS
* @type Object
* @static
*/
ATTRS: {
/**
* The zIndex base to be used on the stacking for all overlays
* registered on the OverlayManager.
*
* @attribute zIndexBase
* @default 1000
* @type Number
*/
zIndexBase: {
value: 1000,
validator: isNumber,
setter: Lang.toInt
}
},
EXTENDS: A.Base,
prototype: {
/**
* Construction logic executed during OverlayManager instantiation. Lifecycle.
*
* @method initializer
* @protected
*/
initializer: function() {
var instance = this;
instance._overlays = [];
},
/**
* Set the passed overlay zIndex to the highest value.
*
* @method bringToTop
* @param {Overlay} overlay Instance of
* Overlay .
*/
bringToTop: function(overlay) {
var instance = this;
var overlays = instance._overlays.sort(instance.sortByZIndexDesc);
var highest = overlays[0];
if (highest !== overlay) {
var overlayZ = overlay.get(Z_INDEX);
var highestZ = highest.get(Z_INDEX);
overlay.set(Z_INDEX, highestZ + 1);
overlay.set('focused', true);
}
},
/**
* Destructor lifecycle implementation for the OverlayManager class.
* Purges events attached to the node (and all child nodes).
*
* @method destructor
* @protected
*/
destructor: function() {
var instance = this;
instance._overlays = [];
},
/**
* Register the passed Overlay to this
* OverlayManager.
*
* @method register
* @param {Overlay} overlay Overlay instance to be registered
* @return {Array} Registered overlays
*/
register: function (overlay) {
var instance = this;
var overlays = instance._overlays;
if (isArray(overlay)) {
A.Array.each(overlay, function(o) {
instance.register(o);
});
}
else {
var zIndexBase = instance.get(Z_INDEX_BASE);
var registered = instance._registered(overlay);
if (
!registered && overlay &&
((overlay instanceof A.Overlay) ||
(A.Component && overlay instanceof A.Component))
) {
var boundingBox = overlay.get(BOUNDING_BOX);
overlays.push(overlay);
var zIndex = overlay.get(Z_INDEX) || 0;
var newZIndex = overlays.length + zIndex + zIndexBase;
overlay.set(Z_INDEX, newZIndex);
overlay.on('focusedChange', instance._onFocusedChange, instance);
boundingBox.on('mousedown', instance._onMouseDown, instance);
}
}
return overlays;
},
/**
* Remove the passed Overlay from this
* OverlayManager.
*
* @method remove
* @param {Overlay} overlay Overlay instance to be removed
* @return {null}
*/
remove: function (overlay) {
var instance = this;
var overlays = instance._overlays;
if (overlays.length) {
return A.Array.removeItem(overlays, overlay);
}
return null;
},
/**
* Loop through all registered Overlay and
* execute a callback.
*
* @method each
* @param {function} fn Callback to be executed on the
* Array.each
* @return {null}
*/
each: function(fn) {
var instance = this;
var overlays = instance._overlays;
A.Array.each(overlays, fn);
},
/**
* Invoke the show method from
* all registered Overlays.
*
* @method showAll
*/
showAll: function() {
this.each(
function(overlay) {
overlay.show();
}
);
},
/**
* Invoke the hide method from
* all registered Overlays.
*
* @method hideAll
*/
hideAll: function() {
this.each(
function(overlay) {
overlay.hide();
}
);
},
/**
* zIndex comparator. Used on Array.sort.
*
* @method sortByZIndexDesc
* @param {Overlay} a Overlay
* @param {Overlay} b Overlay
* @return {Number}
*/
sortByZIndexDesc: function(a, b) {
if (!a || !b || !a.hasImpl(A.WidgetStack) || !b.hasImpl(A.WidgetStack)) {
return 0;
}
else {
var aZ = a.get(Z_INDEX);
var bZ = b.get(Z_INDEX);
if (aZ > bZ) {
return -1;
} else if (aZ < bZ) {
return 1;
} else {
return 0;
}
}
},
/**
* Check if the overlay is registered.
*
* @method _registered
* @param {Overlay} overlay Overlay
* @protected
* @return {boolean}
*/
_registered: function(overlay) {
var instance = this;
return A.Array.indexOf(instance._overlays, overlay) != -1;
},
/**
* Mousedown event handler, used to invoke
* bringToTop .
*
* @method _onMouseDown
* @param {EventFacade} event
* @protected
*/
_onMouseDown: function(event) {
var instance = this;
var overlay = A.Widget.getByNode(event.currentTarget || event.target);
var registered = instance._registered(overlay);
if (overlay && registered) {
instance.bringToTop(overlay);
}
},
/**
* Fires when the focused
* attribute change. Used to invoke
* bringToTop .
*
* @method _onFocusedChange
* @param {EventFacade} event
* @protected
*/
_onFocusedChange: function(event) {
var instance = this;
if (event.newVal) {
var overlay = event.currentTarget || event.target;
var registered = instance._registered(overlay);
if (overlay && registered) {
instance.bringToTop(overlay);
}
}
}
}
}
);
A.OverlayManager = OverlayManager;
}, '2.0.0', {"requires": ["overlay", "plugin", "aui-base-deprecated", "aui-overlay-base-deprecated"]});
YUI.add('aui-overlay-mask-deprecated', function (A, NAME) {
/**
* The OverlayMask Utility
*
* @module aui-overlay
* @submodule aui-overlay-mask
*/
var L = A.Lang,
isArray = L.isArray,
isString = L.isString,
isNumber = L.isNumber,
isValue = L.isValue,
CONFIG = A.config,
UA = A.UA,
IE6 = (UA.ie <= 6),
ABSOLUTE = 'absolute',
ALIGN_POINTS = 'alignPoints',
BACKGROUND = 'background',
BOUNDING_BOX = 'boundingBox',
CONTENT_BOX = 'contentBox',
FIXED = 'fixed',
HEIGHT = 'height',
OFFSET_HEIGHT = 'offsetHeight',
OFFSET_WIDTH = 'offsetWidth',
OPACITY = 'opacity',
OVERLAY_MASK = 'overlaymask',
POSITION = 'position',
TARGET = 'target',
WIDTH = 'width';
/**
* A base class for OverlayMask, providing:
*
* Widget Lifecycle (initializer, renderUI, bindUI, syncUI, destructor)
* Cross browser mask functionality to cover an element or the entire page
* Customizable mask (i.e., background, opacity)
*
*
* Quick Example:
*
* var instance = new A.OverlayMask().render();
*
* Check the list of Configuration Attributes available for
* OverlayMask.
*
* @param config {Object} Object literal specifying widget configuration properties.
*
* @class OverlayMask
* @constructor
* @extends OverlayBase
*/
var OverlayMask = A.Component.create(
{
/**
* Static property provides a string to identify the class.
*
* @property OverlayMask.NAME
* @type String
* @static
*/
NAME: OVERLAY_MASK,
/**
* Static property used to define the default attribute
* configuration for the OverlayMask.
*
* @property OverlayMask.ATTRS
* @type Object
* @static
*/
ATTRS: {
/**
* Points to align the Overlay used as
* mask.
*
* @attribute alignPoints
* @default [ 'tl', 'tl' ]
* @type Array
*/
alignPoints: {
value: [ 'tl', 'tl' ],
validator: isArray
},
/**
* Background color of the mask.
*
* @attribute background
* @default null
* @type String
*/
background: {
lazyAdd: false,
value: null,
validator: isString,
setter: function(v) {
if (v) {
this.get(CONTENT_BOX).setStyle(BACKGROUND, v);
}
return v;
}
},
/**
* Node where the mask will be positioned and re-dimensioned. The
* default is the document, which means that if not specified the mask
* takes the full screen.
*
* @attribute target
* @default document
* @type Node | String
*/
target: {
cloneDefaultValue: false,
lazyAdd: false,
value: CONFIG.doc,
setter: function(v) {
var instance = this;
var target = A.one(v);
var isDoc = instance._isDoc = target.compareTo(CONFIG.doc);
var isWin = instance._isWin = target.compareTo(CONFIG.win);
instance._fullPage = isDoc || isWin;
return target;
}
},
/**
* CSS opacity of the mask.
*
* @attribute opacity
* @default .5
* @type Number
*/
opacity: {
value: 0.5,
validator: isNumber,
setter: function(v) {
return this._setOpacity(v);
}
},
/**
* Use shim option.
*
* @attribute shim
* @default True on IE.
* @type boolean
*/
shim: {
value: A.UA.ie
},
/**
* If true the Overlay is visible by default after the render phase.
* Inherited from Overlay .
*
* @attribute visible
* @default false
* @type boolean
*/
visible: {
value: false
},
/**
* zIndex of the OverlayMask.
*
* @attribute zIndex
* @default 1000
* @type Number
*/
zIndex: {
value: 1000
}
},
EXTENDS: A.OverlayBase,
prototype: {
/**
* Bind the events on the OverlayMask UI. Lifecycle.
*
* @method bindUI
* @protected
*/
bindUI: function() {
var instance = this;
OverlayMask.superclass.bindUI.apply(this, arguments);
instance.after('targetChange', instance._afterTargetChange);
instance.after('visibleChange', instance._afterVisibleChange);
// window:resize YUI normalized event is not working, bug?
A.on('windowresize', A.bind(instance.refreshMask, instance));
},
/**
* Sync the OverlayMask UI. Lifecycle.
*
* @method syncUI
* @protected
*/
syncUI: function() {
var instance = this;
instance.refreshMask();
},
/**
* Get the size of the
* target . Used to dimension
* the mask node.
*
* @method getTargetSize
* @return {Object} Object containing the { height: height, width: width }.
*/
getTargetSize: function() {
var instance = this;
var target = instance.get(TARGET);
var isDoc = instance._isDoc;
var isWin = instance._isWin;
var height = target.get(OFFSET_HEIGHT);
var width = target.get(OFFSET_WIDTH);
if (IE6) {
// IE6 doesn't support height/width 100% on doc/win
if (isWin) {
width = A.DOM.winWidth();
height = A.DOM.winHeight();
}
else if (isDoc) {
width = A.DOM.docWidth();
height = A.DOM.docHeight();
}
}
// good browsers...
else if (instance._fullPage) {
height = '100%';
width = '100%';
}
return { height: height, width: width };
},
/**
* Repaint the OverlayMask UI, respecting the
* target size and the
* alignPoints .
*
* @method refreshMask
*/
refreshMask: function() {
var instance = this;
var alignPoints = instance.get(ALIGN_POINTS);
var target = instance.get(TARGET);
var boundingBox = instance.get(BOUNDING_BOX);
var targetSize = instance.getTargetSize();
var fullPage = instance._fullPage;
boundingBox.setStyles({
position: (IE6 || !fullPage) ? ABSOLUTE : FIXED,
left: 0,
top: 0
});
var height = targetSize.height;
var width = targetSize.width;
if (isValue(height)) {
instance.set(HEIGHT, height);
}
if (isValue(width)) {
instance.set(WIDTH, width);
}
// if its not a full mask...
if ( !fullPage ) {
// if the target is not document|window align the overlay
instance.align(target, alignPoints);
}
},
/**
* Setter for opacity .
*
* @method _setOpacity
* @protected
* @param {Number} v
* @return {Number}
*/
_setOpacity: function(v) {
var instance = this;
instance.get(CONTENT_BOX).setStyle(OPACITY, v);
return v;
},
/**
* Invoke the OverlayMask.superclass._uiSetVisible
. Used to
* reset the opacity
to work around IE bugs when set opacity
* of hidden elements.
*
* @method _uiSetVisible
* @param {boolean} val
* @protected
*/
_uiSetVisible: function(val) {
var instance = this;
OverlayMask.superclass._uiSetVisible.apply(this, arguments);
if (val) {
instance._setOpacity(
instance.get(OPACITY)
);
}
},
/**
* Fires after the value of the
* target attribute change.
*
* @method _afterTargetChange
* @param {EventFacade} event
* @protected
*/
_afterTargetChange: function(event) {
var instance = this;
instance.refreshMask();
},
/**
* Fires after the value of the
* visible attribute change.
*
* @method _afterVisibleChange
* @param {EventFacade} event
* @protected
*/
_afterVisibleChange: function(event) {
var instance = this;
instance._uiSetVisible(event.newVal);
},
/**
* UI Setter for the
* XY attribute.
*
* @method _uiSetXY
* @param {EventFacade} event
* @protected
*/
_uiSetXY: function() {
var instance = this;
if (!instance._fullPage || IE6) {
OverlayMask.superclass._uiSetXY.apply(instance, arguments);
}
}
}
}
);
A.OverlayMask = OverlayMask;
}, '2.0.0', {"requires": ["event-resize", "aui-base-deprecated", "aui-overlay-base-deprecated"], "skinnable": true});
YUI.add('aui-parse-content', function (A, NAME) {
/**
* The ParseContent Utility - Parse the content of a Node so that all of the
* javascript contained in that Node will be executed according to the order
* that it appears.
*
* @module aui-parse-content
*/
/*
* NOTE: The inspiration of ParseContent cames from the "Caridy Patino" Node
* Dispatcher Plugin http://github.com/caridy/yui3-gallery/blob/master/src
* /gallery-dispatcher/
*/
var L = A.Lang,
isString = L.isString,
DOC = A.config.doc,
PADDING_NODE = '_
',
SCRIPT_TYPES = {
'': 1,
'text/javascript': 1,
'text/parsed': 1
};
/**
* A base class for ParseContent, providing:
*
* - After plug ParseContent on a A.Node instance the javascript chunks will be
* executed (remote and inline scripts)
* - All the javascripts within a content will be executed according to the
* order of apparition
*
* **NOTE:** For performance reasons on DOM manipulation,
* ParseContent only parses the content passed to the
* [setContent](Node.html#method_setContent),
* [prepend](Node.html#method_prepend) and
* [append](Node.html#method_append) methods.
*
* Quick Example:
*
* ```
* node.plug(A.Plugin.ParseContent);
* ```
*
* @class A.ParseContent
* @extends Plugin.Base
* @param {Object} config Object literal specifying widget configuration
* properties.
* @constructor
*/
var ParseContent = A.Component.create({
/**
* Static property provides a string to identify the class.
*
* @property NAME
* @type String
* @static
*/
NAME: 'ParseContent',
/**
* Static property provides a string to identify the namespace.
*
* @property NS
* @type String
* @static
*/
NS: 'ParseContent',
/**
* Static property used to define the default attribute
* configuration for the ParseContent.
*
* @property ATTRS
* @type Object
* @static
*/
ATTRS: {
/**
* A queue of elements to be parsed.
*
* @attribute queue
* @default null
*/
queue: {
value: null
},
/**
* When true, script nodes will not be removed from original content,
* instead the script type attribute will be set to `text/plain`.
*
* @attribute preserveScriptNodes
* @default false
*/
preserveScriptNodes: {
validator: L.isBoolean,
value: false
}
},
/**
* Static property used to define which component it extends.
*
* @property EXTENDS
* @type Object
* @static
*/
EXTENDS: A.Plugin.Base,
prototype: {
/**
* Construction logic executed during ParseContent instantiation.
* Lifecycle.
*
* @method initializer
* @protected
*/
initializer: function() {
var instance = this;
ParseContent.superclass.initializer.apply(this, arguments);
instance.set(
'queue',
new A.AsyncQueue()
);
instance._bindAOP();
},
/**
* Global eval the data passed.
*
* @method globalEval
* @param {String} data JavaScript String.
*/
globalEval: function(data) {
var doc = A.getDoc();
var head = doc.one('head') || doc.get('documentElement');
// NOTE: A.Node.create('') doesn't work correctly
// on Opera
var newScript = DOC.createElement('script');
newScript.type = 'text/javascript';
if (data) {
// NOTE: newScript.set(TEXT, data) breaks on IE, YUI BUG.
newScript.text = L.trim(data);
}
//removes the script node immediately after executing it
head.appendChild(newScript).remove();
},
/**
* Extract the `script` tags from the string content and
* evaluate the chunks.
*
* @method parseContent
* @param {String} content HTML string
* @return {String}
*/
parseContent: function(content) {
var instance = this;
var output = instance._extractScripts(content);
instance._dispatch(output);
return output;
},
/**
* Add inline script data to the queue.
*
* @method _addInlineScript
* @param {String} data The script content which should be added to the
* queue
* @protected
*/
_addInlineScript: function(data) {
var instance = this;
instance.get('queue').add({
args: data,
context: instance,
fn: instance.globalEval,
timeout: 0
});
},
/**
* Bind listeners on the `insert` and `setContent` methods of the Node
* instance where you are plugging the ParseContent. These listeners are
* responsible for intercept the HTML passed and parse them.
*
* @method _bindAOP
* @protected
*/
_bindAOP: function() {
var instance = this;
var cleanFirstArg = function(content) {
var args = Array.prototype.slice.call(arguments);
var output = instance.parseContent(content);
// replace the first argument with the clean fragment
args.splice(0, 1, output.fragment);
return new A.Do.AlterArgs(null, args);
};
this.doBefore('insert', cleanFirstArg);
this.doBefore('replaceChild', cleanFirstArg);
var cleanArgs = function(content) {
var output = instance.parseContent(content);
return new A.Do.AlterArgs(null, [output.fragment]);
};
this.doBefore('replace', cleanArgs);
this.doBefore('setContent', cleanArgs);
},
/**
* Create an HTML fragment with the String passed, extract all the
* script tags and return an Object with a reference for the extracted
* scripts and the fragment.
*
* @method clean
* @param {String} content HTML content.
* @protected
* @return {Object}
*/
_extractScripts: function(content) {
var instance = this,
fragment = A.Node.create('
'),
output = {},
preserveScriptNodes = instance.get('preserveScriptNodes');
// For PADDING_NODE, instead of fixing all tags in the content to be
// "XHTML"-style, we make the firstChild be a valid non-empty tag,
// then we remove it later
if (isString(content)) {
content = PADDING_NODE + content;
// create fragment from {String}
A.DOM.addHTML(fragment, content, 'append');
}
else {
fragment.append(PADDING_NODE);
// create fragment from {Y.Node | HTMLElement}
fragment.append(content);
}
output.js = fragment.all('script').filter(function(script) {
var includeScript = SCRIPT_TYPES[script.getAttribute('type').toLowerCase()];
if (preserveScriptNodes) {
script.setAttribute('type', 'text/parsed');
}
return includeScript;
});
if (!preserveScriptNodes) {
output.js.each(
function(node) {
node.remove();
}
);
}
// remove PADDING_NODE
fragment.get('firstChild').remove();
output.fragment = fragment.get('childNodes').toFrag();
return output;
},
/**
* Loop trough all extracted `script` tags and evaluate them.
*
* @method _dispatch
* @param {Object} output Object containing the reference for the
* fragment and the extracted `script` tags.
* @protected
* @return {String}
*/
_dispatch: function(output) {
var instance = this;
var queue = instance.get('queue');
var scriptContent = [];
output.js.each(function(node) {
var src = node.get('src');
if (src) {
if (scriptContent.length) {
instance._addInlineScript(scriptContent.join(';'));
scriptContent.length = 0;
}
queue.add({
autoContinue: false,
fn: function() {
A.Get.script(src, {
onEnd: function(o) {
//removes the script node immediately after
//executing it
o.purge();
queue.run();
}
});
},
timeout: 0
});
}
else {
var dom = node._node;
scriptContent.push(dom.text || dom.textContent || dom.innerHTML || '');
}
});
if (scriptContent.length) {
instance._addInlineScript(scriptContent.join(';'));
}
queue.run();
}
}
});
A.namespace('Plugin').ParseContent = ParseContent;
}, '2.0.0', {"requires": ["async-queue", "plugin", "io-base", "aui-component", "aui-node-base"]});
AUI.add(
'liferay-dockbar',
function(A) {
var AObject = A.Object;
var Lang = A.Lang;
var Util = Liferay.Util;
var BODY = A.getBody();
var CSS_ADD_CONTENT = 'lfr-has-add-content';
var CSS_EDIT_LAYOUT_CONTENT = 'lfr-has-edit-layout';
var CSS_DOCKBAR_ITEM = 'dockbar-item';
var CSS_PREVIEW_CONTENT = 'lfr-has-device-preview';
var SELECTOR_NAV_ACCOUNT_CONTROLS = '.nav-account-controls';
var SELECTOR_NAV_ADD_CONTROLS = '.nav-add-controls';
var STR_ADD_PANEL = 'addPanel';
var STR_EDIT_LAYOUT_PANEL = 'editLayoutPanel';
var STR_PREVIEW_PANEL = 'previewPanel';
var TPL_ADD_CONTENT = '
';
var TPL_EDIT_LAYOUT_PANEL = '
';
var TPL_PREVIEW_PANEL = '
';
var TPL_LOADING = '
';
var Dockbar = {
init: function(containerId) {
var instance = this;
var dockBar = A.one(containerId);
if (dockBar) {
instance.dockBar = dockBar;
instance._namespace = dockBar.attr('data-namespace');
Liferay.once('initDockbar', instance._init, instance);
var eventHandle = dockBar.on(
['focus', 'mousemove', 'touchstart'],
function(event) {
var target = event.target;
var type = event.type;
Liferay.fire('initDockbar');
eventHandle.detach();
if (themeDisplay.isSignedIn() && !A.UA.touch) {
instance._initInteraction(target, type);
}
}
);
BODY.addClass('dockbar-ready');
Liferay.on(['noticeHide', 'noticeShow'], instance._toggleControlsOffset, instance);
}
},
getPanelNode: function(panelId) {
var instance = this;
var panelNode = null;
var panel = DOCKBAR_PANELS[panelId];
if (panel) {
panelNode = panel.node;
if (!panelNode) {
var namespace = instance._namespace;
var panelSidebarId = namespace + panelId + 'Sidebar';
panelNode = A.one('#' + panelSidebarId);
if (!panelNode) {
panelNode = A.Node.create(Lang.sub(panel.tpl, [namespace]));
panelNode.plug(A.Plugin.ParseContent);
BODY.prepend(panelNode);
panelNode.set('id', panelSidebarId);
panel.node = panelNode;
}
}
}
return panelNode;
},
togglePreviewPanel: function() {
var instance = this;
Dockbar._togglePanel(STR_PREVIEW_PANEL);
},
toggleAddPanel: function() {
var instance = this;
Dockbar._togglePanel(STR_ADD_PANEL);
},
toggleEditLayoutPanel: function() {
var instance = this;
Dockbar._togglePanel(STR_EDIT_LAYOUT_PANEL);
},
_registerPanels: function() {
var instance = this;
var namespace = instance._namespace;
AObject.each(
DOCKBAR_PANELS,
function(item, index, collection) {
var panelId = item.id;
var panelTrigger = A.one('#' + namespace + panelId);
if (panelTrigger) {
panelTrigger.on(
'click',
function(event) {
event.halt();
instance._togglePanel(panelId);
}
);
}
}
);
},
_setLoadingAnimation: function(panel) {
var instance = this;
instance.getPanelNode(panel).html(TPL_LOADING);
},
_toggleAppShortcut: function(item, force) {
var instance = this;
item.toggleClass('lfr-portlet-used', force);
instance._addContentNode.focusManager.refresh();
},
_toggleControlsOffset: function(event) {
if (!event.useAnimation) {
var instance = this;
var force = false;
if (event.type === 'noticeShow') {
force = true;
}
var namespace = instance._namespace;
var navAccountControls = A.one('#' + namespace + 'navAccountControls');
if (navAccountControls) {
navAccountControls.toggleClass('nav-account-controls-notice', force);
}
var navAddControls = A.one('#' + namespace + 'navAddControls');
if (navAddControls) {
navAddControls.toggleClass('nav-add-controls-notice', force);
}
}
},
_togglePanel: function(panelId) {
var instance = this;
AObject.each(
DOCKBAR_PANELS,
function(item, index, collection) {
if (item.id !== panelId) {
BODY.removeClass(item.css);
if (item.node) {
item.node.hide();
BODY.detach('layoutControlsEsc|key');
}
}
}
);
var panel = DOCKBAR_PANELS[panelId];
if (panel) {
var panelNode = panel.node;
if (!panelNode) {
panelNode = instance.getPanelNode(panel.id);
}
BODY.toggleClass(panel.css);
var panelDisplayEvent = 'dockbarHidePanel';
var panelVisible = false;
if (panelNode && BODY.hasClass(panel.css)) {
panel.showFn(panelId);
panelDisplayEvent = 'dockbarShowPanel';
panelVisible = true;
BODY.on(
'layoutControlsEsc|key',
function(event) {
if (panelId !== STR_PREVIEW_PANEL) {
instance._togglePanel(panelId);
}
var navAddControls = A.one('#' + instance._namespace + 'navAddControls');
if (navAddControls) {
var layoutControl;
if (panelId == STR_ADD_PANEL) {
layoutControl = navAddControls.one('.site-add-controls > a');
}
else if (panelId == STR_EDIT_LAYOUT_PANEL) {
layoutControl = navAddControls.one('.page-edit-controls > a');
}
else if (panelId == STR_PREVIEW_PANEL) {
layoutControl = navAddControls.one('.page-preview-controls > a');
}
if (layoutControl) {
layoutControl.focus();
}
}
},
'down:27'
);
}
Liferay.fire(
'dockbaraddpage:previewPageTitle',
{
data: {
hidden: true
}
}
);
Liferay.fire(
panelDisplayEvent,
{
id: panelId
}
);
if (!panelVisible) {
BODY.detach('layoutControlsEsc|key');
}
panelNode.toggle(panelVisible);
}
}
};
Liferay.provide(
Dockbar,
'_init',
function() {
var instance = this;
var dockBar = instance.dockBar;
var namespace = instance._namespace;
Liferay.Util.toggleControls(dockBar);
instance._toolbarItems = {};
Liferay.fire('initLayout');
Liferay.fire('initNavigation');
instance._registerPanels();
var btnNavigation = A.oneNS(namespace, '#navSiteNavigationNavbarBtn');
var navigation = A.one(Liferay.Data.NAV_SELECTOR);
if (btnNavigation && navigation) {
btnNavigation.on(
'tap',
function(event) {
navigation.toggleClass('open');
}
);
}
Liferay.fire('dockbarLoaded');
},
['aui-io-request', 'event-tap', 'liferay-node', 'liferay-store', 'node-focusmanager']
);
Liferay.provide(
Dockbar,
'_initInteraction',
function(target, type) {
var instance = this;
var dockBar = instance.dockBar;
var navAccountControls = dockBar.one(SELECTOR_NAV_ACCOUNT_CONTROLS);
var navAddControls = dockBar.one(SELECTOR_NAV_ADD_CONTROLS);
if (navAccountControls) {
var stagingBar = navAccountControls.one('.staging-bar');
if (stagingBar) {
stagingBar.all('> li').addClass(CSS_DOCKBAR_ITEM);
}
navAccountControls.all('> li > a').get('parentNode').addClass(CSS_DOCKBAR_ITEM);
}
if (BODY.hasClass('dockbar-split')) {
if (navAccountControls) {
navAccountControls.plug(Liferay.DockbarKeyboardInteraction);
}
if (navAddControls) {
navAddControls.plug(
A.Plugin.NodeFocusManager,
{
circular: true,
descendants: 'li a',
keys: {
next: 'down:39,40',
previous: 'down:37,38'
}
}
);
navAddControls.focusManager.after(
'focusedChange',
function(event) {
var instance = this;
if (!event.newVal) {
instance.set('activeDescendant', 0);
}
}
);
}
}
else if (navAddControls) {
var brand = dockBar.one('.brand');
if (brand) {
brand.all('a').get('parentNode').addClass(CSS_DOCKBAR_ITEM);
}
navAddControls.all('> li').addClass(CSS_DOCKBAR_ITEM);
dockBar.plug(Liferay.DockbarKeyboardInteraction);
}
if (type === 'focus') {
var navAccountControlsAncestor = target.ancestor(SELECTOR_NAV_ACCOUNT_CONTROLS);
var navLink = target;
if (navAccountControlsAncestor) {
navLink = navAccountControlsAncestor.one('li a');
}
navLink.blur();
navLink.focus();
}
},
['liferay-dockbar-keyboard-interaction', 'node-focusmanager']
);
Liferay.provide(
Dockbar,
'_showPanel',
function(panelId) {
var instance = this;
instance._setLoadingAnimation(panelId);
var panel = A.one('#' + instance._namespace + panelId);
if (panel) {
var uri = panel.ancestor().attr('data-panelURL');
A.io.request(
uri,
{
after: {
success: function(event, id, obj) {
var response = this.get('responseData');
var panelNode = instance.getPanelNode(panelId);
panelNode.plug(A.Plugin.ParseContent);
panelNode.setContent(response);
}
}
}
);
}
},
['aui-io-request', 'aui-parse-content', 'event-outside']
);
var showPanelFn = A.bind('_showPanel', Dockbar);
var DOCKBAR_PANELS = {
'addPanel': {
css: CSS_ADD_CONTENT,
id: STR_ADD_PANEL,
node: null,
showFn: showPanelFn,
tpl: TPL_ADD_CONTENT
},
'editLayoutPanel': {
css: CSS_EDIT_LAYOUT_CONTENT,
id: STR_EDIT_LAYOUT_PANEL,
node: null,
showFn: showPanelFn,
tpl: TPL_EDIT_LAYOUT_PANEL
},
'previewPanel': {
css: CSS_PREVIEW_CONTENT,
id: STR_PREVIEW_PANEL,
node: null,
showFn: showPanelFn,
tpl: TPL_PREVIEW_PANEL
}
};
Liferay.Dockbar = Dockbar;
Liferay.Dockbar.ADD_PANEL = STR_ADD_PANEL;
Liferay.Dockbar.PREVIEW_PANEL = STR_PREVIEW_PANEL;
},
'',
{
requires: ['aui-node', 'aui-overlay-mask-deprecated', 'event-touch']
}
);
;(function(A, Liferay) {
var LayoutExporter = {
icons: {
minus: themeDisplay.getPathThemeImages() + '/arrows/01_minus.png',
plus: themeDisplay.getPathThemeImages() + '/arrows/01_plus.png'
}
};
Liferay.provide(
LayoutExporter,
'all',
function(options) {
options = options || {};
var obj = options.obj;
var pane = options.pane;
if (obj && obj.checked) {
pane = A.one(pane);
if (pane) {
pane.hide();
}
}
},
['aui-base']
);
Liferay.provide(
LayoutExporter,
'details',
function(options) {
options = options || {};
var detail = A.one(options.detail);
var img = A.one(options.toggle);
if (detail && img) {
var icon = LayoutExporter.icons.plus;
if (detail.hasClass('hide')) {
detail.show();
icon = LayoutExporter.icons.minus;
}
else {
detail.hide();
}
img.attr('src', icon);
}
},
['aui-base']
);
Liferay.provide(
LayoutExporter,
'proposeLayout',
function(options) {
options = options || {};
var namespace = options.namespace;
var reviewers = options.reviewers;
var contents =
"" +
"" +
"
";
Liferay.Util.openWindow(
{
dialog: {
destroyOnHide: true
},
title: contents
}
);
},
['liferay-util-window']
);
Liferay.provide(
LayoutExporter,
'publishToLive',
function(options) {
options = options || {};
Liferay.Util.openWindow(
{
dialog: {
constrain: true,
modal: true,
on: {
visibleChange: function(event) {
var instance = this;
if (!event.newVal) {
instance.destroy();
}
}
}
},
title: options.title,
uri: options.url
}
);
}
);
Liferay.provide(
LayoutExporter,
'selected',
function(options) {
options = options || {};
var obj = options.obj;
var pane = options.pane;
if (obj && obj.checked) {
pane = A.one(pane);
if (pane) {
pane.show();
}
}
},
['aui-base']
);
Liferay.LayoutExporter = LayoutExporter;
})(AUI(), Liferay);
AUI.add(
'liferay-session',
function(A) {
var Lang = A.Lang;
var BUFFER_TIME = [];
var CONFIG = A.config;
var DOC = CONFIG.doc;
var MAP_SESSION_STATE_EVENTS = {
active: 'activated'
};
var SRC = {};
var SRC_EVENT_OBJ = {
src: SRC
};
var URL_BASE = themeDisplay.getPathMain() + '/portal/';
var SessionBase = A.Component.create(
{
ATTRS: {
autoExtend: {
value: false
},
redirectUrl: {
value: ''
},
redirectOnExpire: {
value: true
},
sessionState: {
value: 'active'
},
sessionLength: {
getter: '_getLengthInMillis',
value: 0
},
timestamp: {
getter: '_getTimestamp',
setter: '_setTimestamp',
value: 0
},
warningLength: {
getter: '_getLengthInMillis',
setter: '_setWarningLength',
value: 0
},
warningTime: {
getter: '_getWarningTime',
value: 0
}
},
EXTENDS: A.Base,
NAME: 'liferaysession',
prototype: {
initializer: function(config) {
var instance = this;
instance._cookieOptions = {
path: '/',
secure: A.UA.secure
};
instance._registered = {};
instance.set('timestamp');
instance._initEvents();
instance._startTimer();
},
registerInterval: function(fn) {
var instance = this;
var fnId;
var registered = instance._registered;
if (Lang.isFunction(fn)) {
fnId = A.stamp(fn);
registered[fnId] = fn;
}
return fnId;
},
resetInterval: function() {
var instance = this;
instance._stopTimer();
instance._startTimer();
},
unregisterInterval: function(fnId) {
var instance = this;
var registered = instance._registered;
if (A.Object.owns(registered, fnId)) {
delete registered[fnId];
}
return fnId;
},
expire: function() {
var instance = this;
instance.set('sessionState', 'expired', SRC_EVENT_OBJ);
},
extend: function() {
var instance = this;
instance.set('sessionState', 'active', SRC_EVENT_OBJ);
},
warn: function() {
var instance = this;
instance.set('sessionState', 'warned', SRC_EVENT_OBJ);
},
_afterSessionStateChange: function(event) {
var instance = this;
var newVal = event.newVal;
var src = null;
if (('src' in event) && event.details.length) {
src = event.details[0];
}
instance.fire(MAP_SESSION_STATE_EVENTS[newVal] || newVal, src);
},
_defActivatedFn: function(event) {
var instance = this;
instance.set('timestamp');
if (event.src == SRC) {
instance._getExtendIO().start();
}
},
_defExpiredFn: function(event) {
var instance = this;
A.clearInterval(instance._intervalId);
instance.set('timestamp', 'expired');
if (event.src === SRC) {
instance._getExpireIO().start();
}
},
_getExpireIO: function() {
var instance = this;
var expireIO = instance._expireIO;
if (!expireIO) {
expireIO = A.io.request(
URL_BASE + 'expire_session',
{
autoLoad: false,
on: {
success: function(event, id, obj) {
Liferay.fire('sessionExpired');
if (instance.get('redirectOnExpire')) {
location.href = instance.get('redirectUrl');
}
}
}
}
);
instance._expireIO = expireIO;
}
return expireIO;
},
_getExtendIO: function() {
var instance = this;
var extendIO = instance._extendIO;
if (!extendIO) {
extendIO = A.io.request(
URL_BASE + 'extend_session',
{
autoLoad: false
}
);
instance._extendIO = extendIO;
}
return extendIO;
},
_getLengthInMillis: function(value) {
var instance = this;
return value * 1000;
},
_getTimestamp: function(value) {
var instance = this;
return A.Cookie.get(instance._cookieKey, instance._cookieOptions) || 0;
},
_getWarningTime: function() {
var instance = this;
return instance.get('sessionLength') - instance.get('warningLength');
},
_initEvents: function() {
var instance = this;
instance.on('sessionStateChange', instance._onSessionStateChange);
instance.after('sessionStateChange', instance._afterSessionStateChange);
instance.publish(
'activated',
{
defaultFn: A.bind('_defActivatedFn', instance)
}
);
instance.publish(
'expired',
{
defaultFn: A.bind('_defExpiredFn', instance)
}
);
instance.publish('warned');
},
_onSessionStateChange: function(event) {
var instance = this;
var newVal = event.newVal;
var prevVal = event.prevVal;
if (prevVal == 'expired' && prevVal != newVal) {
event.preventDefault();
}
else if (prevVal == 'active' && prevVal == newVal) {
instance._afterSessionStateChange(event);
}
},
_setTimestamp: function(value) {
var instance = this;
value = String(value || Lang.now());
return A.Cookie.set(instance._cookieKey, value, instance._cookieOptions);
},
_setWarningLength: function(value) {
var instance = this;
return Math.min(instance.get('sessionLength'), value);
},
_startTimer: function() {
var instance = this;
var warningTime = instance.get('warningTime');
var sessionLength = instance.get('sessionLength');
var registered = instance._registered;
var interval = 1000;
instance._intervalId = A.setInterval(
function() {
var timeOffset;
var timestamp = instance.get('timestamp');
var elapsed = sessionLength;
if (Lang.toInt(timestamp)) {
timeOffset = Math.floor((Lang.now() - timestamp) / 1000) * 1000;
elapsed = timeOffset;
}
else {
timestamp = 'expired';
}
var extend = instance.get('autoExtend');
var isExpirationMoment = false;
var isWarningMoment = false;
var hasExpired = (elapsed >= sessionLength);
var hasWarned = (elapsed >= warningTime);
if (hasWarned) {
if (timestamp == 'expired') {
extend = false;
isExpirationMoment = true;
hasExpired = true;
}
var sessionState = instance.get('sessionState');
if (hasExpired && sessionState != 'expired') {
if (extend) {
hasExpired = false;
hasWarned = false;
isExpirationMoment = false;
isWarningMoment = false;
instance.extend();
}
else {
instance.expire();
isExpirationMoment = true;
}
}
else if (!extend && hasWarned && !hasExpired && sessionState != 'warned') {
instance.warn();
isWarningMoment = true;
}
}
for (var i in registered) {
registered[i](elapsed, interval, hasWarned, hasExpired, isWarningMoment, isExpirationMoment);
}
},
interval
);
},
_stopTimer: function() {
var instance = this;
A.clearInterval(instance._intervalId);
},
_cookieKey: 'LFR_SESSION_STATE_' + themeDisplay.getUserId()
}
}
);
SessionBase.SRC = SRC;
var SessionDisplay = A.Component.create(
{
ATTRS: {
pageTitle: {
value: DOC.title
}
},
EXTENDS: A.Plugin.Base,
NAME: 'liferaysessiondisplay',
NS: 'display',
prototype: {
initializer: function(config) {
var instance = this;
var host = instance.get('host');
if (Liferay.Util.getTop() == CONFIG.win) {
instance._host = host;
instance._toggleText = {
hide: '\u0053\u006b\u0072\u00fd\u0074',
show: '\u005a\u006f\u0062\u0072\u0061\u007a\u0069\u0074'
};
// CUSTOMIZATION ONEPORTAL-4075 start
// replace default content with kahl placeholder
//instance._expiredText = '\u0055\u0070\u006f\u007a\u006f\u0072\u006e\u011b\u006e\u00ed\u003a\u0020\u0044\u006c\u006f\u0075\u0068\u006f\u0020\u006e\u0065\u0076\u0079\u006b\u0061\u007a\u0075\u006a\u0065\u0074\u0065\u0020\u017e\u00e1\u0064\u006e\u006f\u0075\u0020\u0061\u006b\u0074\u0069\u0076\u0069\u0074\u0075\u002c\u0020\u0070\u0072\u006f\u0074\u006f\u0020\u0064\u006f\u0161\u006c\u006f\u0020\u006b\u0020\u006f\u0064\u0068\u006c\u00e1\u0161\u0065\u006e\u00ed\u002e\u0020\u0050\u0072\u006f\u0073\u00ed\u006d\u002c\u0020\u0075\u006c\u006f\u017e\u0074\u0065\u0020\u0073\u0069\u0020\u006e\u0065\u007a\u00e1\u0076\u0069\u0073\u006c\u0065\u0020\u0076\u0161\u0065\u0063\u0068\u006e\u0061\u0020\u0064\u0061\u0074\u0061\u002c\u0020\u006b\u0074\u0065\u0072\u00e1\u0020\u0062\u0079\u006c\u0061\u0020\u007a\u0061\u0064\u00e1\u006e\u0061\u0020\u0061\u0020\u006f\u0020\u006b\u0074\u0065\u0072\u00e1\u0020\u006e\u0065\u0063\u0068\u0063\u0065\u0074\u0065\u0020\u0070\u0159\u0069\u006a\u00ed\u0074\u0020\u0070\u0159\u0069\u0020\u006f\u0062\u006e\u006f\u0076\u0065\u006e\u00ed\u0020\u0073\u0074\u0072\u00e1\u006e\u006b\u0079\u002e'
instance._expiredText = '
';
// CUSTOMIZATION end
instance._extendText = '\u0050\u0072\u006f\u0064\u006c\u006f\u0075\u017e\u0069\u0074';
instance._warningText = '\u0055\u0070\u006f\u007a\u006f\u0072\u006e\u011b\u006e\u00ed\u003a\u0020\u0044\u006c\u006f\u0075\u0068\u006f\u0020\u006e\u0065\u0076\u0079\u006b\u0061\u007a\u0075\u006a\u0065\u0074\u0065\u0020\u017e\u00e1\u0064\u006e\u006f\u0075\u0020\u0061\u006b\u0074\u0069\u0076\u0069\u0074\u0075\u002c\u0020\u0070\u0072\u006f\u0074\u006f\u0020\u0064\u006f\u006a\u0064\u0065\u0020\u007a\u0061\u0020\u007b\u0030\u007d\u0020\u006b\u0020\u006f\u0064\u0068\u006c\u00e1\u0161\u0065\u006e\u00ed\u002e\u0020\u0054\u006c\u0061\u010d\u00ed\u0074\u006b\u0065\u006d\u0020\u003c\u0065\u006d\u003e\u0050\u0072\u006f\u0064\u006c\u006f\u0075\u017e\u0069\u0074\u003c\u002f\u0065\u006d\u003e\u0020\u006f\u0064\u006c\u006f\u017e\u00ed\u0074\u0065\u0020\u006f\u0064\u0068\u006c\u00e1\u0161\u0065\u006e\u00ed\u0020\u006f\u0020\u007b\u0031\u007d\u0020\u006d\u0069\u006e\u0075\u0074\u002e';
instance._warningText = Lang.sub(instance._warningText, ['{0} ', host.get('sessionLength') / 60000]);
host.on('sessionStateChange', instance._onHostSessionStateChange, instance);
instance.afterHostMethod('_defActivatedFn', instance._afterDefActivatedFn);
instance.afterHostMethod('_defExpiredFn', instance._afterDefExpiredFn);
}
else {
host.unplug(instance);
}
},
_afterDefActivatedFn: function(event) {
var instance = this;
instance._uiSetActivated();
},
_afterDefExpiredFn: function(event) {
var instance = this;
instance._host.unregisterInterval(instance._intervalId);
instance._uiSetExpired();
},
_beforeHostWarned: function(event) {
var instance = this;
var host = instance._host;
var sessionLength = host.get('sessionLength');
var timestamp = host.get('timestamp');
var warningLength = host.get('warningLength');
var elapsed = sessionLength;
if (Lang.toInt(timestamp)) {
elapsed = Math.floor((Lang.now() - timestamp) / 1000) * 1000;
}
var remainingTime = sessionLength - elapsed;
if (remainingTime > warningLength) {
remainingTime = warningLength;
}
var banner = instance._getBanner();
var counterTextNode = banner.one('.countdown-timer');
instance._uiSetRemainingTime(remainingTime, counterTextNode);
banner.show();
// CUSTOMIZATION ONEPORTAL-4075 start
// hide whole banner
$('.popup-alert-notice').css('visibility','hidden');
// CUSTOMIZATION end
instance._intervalId = host.registerInterval(
function(elapsed, interval, hasWarned, hasExpired, isWarningMoment, isExpirationMoment) {
if (!hasWarned) {
instance._uiSetActivated();
}
else if (!hasExpired) {
if (isWarningMoment) {
if (remainingTime <= 0) {
remainingTime = warningLength;
}
banner.show();
}
elapsed = Math.floor((Lang.now() - timestamp) / 1000) * 1000;
remainingTime = sessionLength - elapsed;
instance._uiSetRemainingTime(remainingTime, counterTextNode);
}
remainingTime -= interval;
}
);
},
_getBanner: function() {
var instance = this;
var banner = instance._banner;
if (!banner) {
banner = new Liferay.Notice(
{
closeText: instance._extendText,
content: instance._warningText,
noticeClass: 'popup-alert-notice',
onClose: function() {
instance._host.extend();
},
toggleText: false
}
);
instance._banner = banner;
}
return banner;
},
_onHostSessionStateChange: function(event) {
var instance = this;
if (event.newVal == 'warned') {
instance._beforeHostWarned(event);
}
},
_uiSetActivated: function() {
var instance = this;
DOC.title = instance.reset('pageTitle').get('pageTitle');
instance._host.unregisterInterval(instance._intervalId);
var banner = instance._getBanner();
if (banner) {
banner.hide();
}
},
_uiSetExpired: function() {
var instance = this;
var banner = instance._getBanner();
banner.html(instance._expiredText);
banner.replaceClass('popup-alert-notice', 'popup-alert-warning');
banner.addClass('alert-error');
banner.show();
DOC.title = instance.get('pageTitle');
// CUSTOMIZATION ONEPORTAL-4075 start
$('#o2-session-timeout-kahl').html('
').trigger('contentready.o2util');
setInterval(function(){ window.location.href = "/web/o2/login?context=sessiontimeout"; }, 300000);
// CUSTOMIZATION end
},
_uiSetRemainingTime: function(remainingTime, counterTextNode) {
var instance = this;
var banner = instance._getBanner();
counterTextNode = counterTextNode || banner.one('.countdown-timer');
counterTextNode.text(instance._formatTime(remainingTime));
DOC.title = banner.text();
},
_formatNumber: function(value) {
var instance = this;
var floor = Math.floor;
var padNumber = Lang.String.padNumber;
return Lang.String.padNumber(Math.floor(value), 2);
},
_formatTime: function(time) {
var instance = this;
time = Number(time);
if (Lang.isNumber(time) && time > 0) {
time /= 1000;
BUFFER_TIME[0] = instance._formatNumber(time / 3600);
time %= 3600;
BUFFER_TIME[1] = instance._formatNumber(time / 60);
time %= 60;
BUFFER_TIME[2] = instance._formatNumber(time);
time = BUFFER_TIME.join(':');
}
else {
time = 0;
}
return time;
}
}
}
);
Liferay.SessionBase = SessionBase;
Liferay.SessionDisplay = SessionDisplay;
},
'',
{
requires: ['aui-io-request', 'aui-timer', 'cookie', 'liferay-notice']
}
);
// For details about this file see: LPS-2155
// LPS-5741
Liferay.namespace('Util');
Liferay.Util.checkMaxLength = function(box, maxLength) {
if ((box.value.length) >= maxLength) {
box.value = box.value.substring(0, maxLength - 1);
}
};
// LPS-5802
Liferay.namespace('Events');
Liferay.bind = Liferay.on;
Liferay.trigger = Liferay.fire;
Liferay.unbind = Liferay.detach;
Liferay.Events.on = Liferay.on;
Liferay.Events.trigger = Liferay.fire;
Liferay.Events.unbind = Liferay.detach;
// LPS-6237
Liferay.Popup = function(){};