/usr/share/javascript/yui3/attribute-events/attribute-events.js is in libjs-yui3-full 3.5.1-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | /*
YUI 3.5.1 (build 22)
Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add('attribute-events', function(Y) {
/**
* The attribute module provides an augmentable Attribute implementation, which
* adds configurable attributes and attribute change events to the class being
* augmented. It also provides a State class, which is used internally by Attribute,
* but can also be used independently to provide a name/property/value data structure to
* store state.
*
* @module attribute
*/
/**
* The attribute-events submodule provides augmentable attribute change event support
* for AttributeCore based implementations.
*
* @module attribute
* @submodule attribute-events
*/
var EventTarget = Y.EventTarget,
CHANGE = "Change",
BROADCAST = "broadcast",
PUBLISHED = "published";
/**
* Provides an augmentable implementation of attribute change events for
* AttributeCore.
*
* @class AttributeEvents
* @uses EventTarget
*/
function AttributeEvents() {
// Perf tweak - avoid creating event literals if not required.
this._ATTR_E_FACADE = {};
EventTarget.call(this, {emitFacade:true});
}
AttributeEvents._ATTR_CFG = [BROADCAST];
AttributeEvents.prototype = {
/**
* Sets the value of an attribute.
*
* @method set
* @chainable
*
* @param {String} name The name of the attribute. If the
* current value of the attribute is an Object, dot notation can be used
* to set the value of a property within the object (e.g. <code>set("x.y.z", 5)</code>).
*
* @param {Any} value The value to set the attribute to.
*
* @param {Object} opts (Optional) Optional event data to be mixed into
* the event facade passed to subscribers of the attribute's change event. This
* can be used as a flexible way to identify the source of a call to set, allowing
* the developer to distinguish between set called internally by the host, vs.
* set called externally by the application developer.
*
* @return {Object} A reference to the host object.
*/
set : function(name, val, opts) {
return this._setAttr(name, val, opts);
},
/**
* Allows setting of readOnly/writeOnce attributes. See <a href="#method_set">set</a> for argument details.
*
* @method _set
* @protected
* @chainable
*
* @param {String} name The name of the attribute.
* @param {Any} val The value to set the attribute to.
* @param {Object} opts (Optional) Optional event data to be mixed into
* the event facade passed to subscribers of the attribute's change event.
* @return {Object} A reference to the host object.
*/
_set : function(name, val, opts) {
return this._setAttr(name, val, opts, true);
},
/**
* Sets multiple attribute values.
*
* @method setAttrs
* @param {Object} attrs An object with attributes name/value pairs.
* @return {Object} A reference to the host object.
* @chainable
*/
setAttrs : function(attrs, opts) {
return this._setAttrs(attrs, opts);
},
/**
* Utility method to help setup the event payload and fire the attribute change event.
*
* @method _fireAttrChange
* @private
* @param {String} attrName The name of the attribute
* @param {String} subAttrName The full path of the property being changed,
* if this is a sub-attribute value being change. Otherwise null.
* @param {Any} currVal The current value of the attribute
* @param {Any} newVal The new value of the attribute
* @param {Object} opts Any additional event data to mix into the attribute change event's event facade.
*/
_fireAttrChange : function(attrName, subAttrName, currVal, newVal, opts) {
var host = this,
eventName = attrName + CHANGE,
state = host._state,
facade,
broadcast,
evtCfg;
if (!state.get(attrName, PUBLISHED)) {
evtCfg = {
queuable:false,
defaultTargetOnly: true,
defaultFn:host._defAttrChangeFn,
silent:true
};
broadcast = state.get(attrName, BROADCAST);
if (broadcast !== undefined) {
evtCfg.broadcast = broadcast;
}
host.publish(eventName, evtCfg);
state.add(attrName, PUBLISHED, true);
}
facade = (opts) ? Y.merge(opts) : host._ATTR_E_FACADE;
// Not using the single object signature for fire({type:..., newVal:...}), since
// we don't want to override type. Changed to the fire(type, {newVal:...}) signature.
// facade.type = eventName;
facade.attrName = attrName;
facade.subAttrName = subAttrName;
facade.prevVal = currVal;
facade.newVal = newVal;
// host.fire(facade);
host.fire(eventName, facade);
},
/**
* Default function for attribute change events.
*
* @private
* @method _defAttrChangeFn
* @param {EventFacade} e The event object for attribute change events.
*/
_defAttrChangeFn : function(e) {
if (!this._setAttrVal(e.attrName, e.subAttrName, e.prevVal, e.newVal)) {
// Prevent "after" listeners from being invoked since nothing changed.
e.stopImmediatePropagation();
} else {
e.newVal = this.get(e.attrName);
}
}
};
// Basic prototype augment - no lazy constructor invocation.
Y.mix(AttributeEvents, EventTarget, false, null, 1);
Y.AttributeEvents = AttributeEvents;
}, '3.5.1' ,{requires:['event-custom']});
|