| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- AUI.add('aui-component', function(A) {
- /**
- * The Component Utility
- *
- * @module aui-component
- */
-
- var Lang = A.Lang,
- AArray = A.Array,
-
- concat = function(arr, arr2) {
- return (arr || []).concat(arr2 || []);
- },
-
- ClassNameManager = A.ClassNameManager,
-
- _getClassName = ClassNameManager.getClassName,
- _getWidgetClassName = A.Widget.getClassName,
-
- getClassName = A.getClassName,
-
- NAME = 'component',
-
- CSS_HELPER_HIDDEN = getClassName('helper', 'hidden'),
- CONSTRUCTOR_OBJECT = A.config.win.Object.prototype.constructor,
- STR_BLANK = ' ';
-
- /**
- * A base class for Component, providing:
- * <ul>
- * <li>Widget Lifecycle (initializer, renderUI, bindUI, syncUI, destructor)</li>
- * <li></li>
- * </ul>
- *
- * Check the list of <a href="Component.html#configattributes">Configuration Attributes</a> available for
- * Component.
- *
- * @param config {Object} Object literal specifying widget configuration properties.
- *
- * @class Component
- * @constructor
- * @extends Widget
- */
- var Component = function(config) {
- var instance = this;
-
- instance._originalConfig = config;
-
- instance._setRender(config);
-
- Component.superclass.constructor.apply(this, arguments);
-
- INSTANCES[instance.get('id')] = instance;
- };
-
- var INSTANCES = Component._INSTANCES = {};
-
- /**
- * Static property provides a string to identify the class.
- *
- * @property Component.NAME
- * @type String
- * @static
- */
- Component.NAME = 'component';
-
- /**
- * Static property used to define the default attribute
- * configuration for the Component.
- *
- * @property Component.ATTRS
- * @type Object
- * @static
- */
- Component.ATTRS = {
- /**
- * Boolean indicating if use of the WAI-ARIA Roles and States should be
- * enabled for the Widget.
- *
- * @attribute useARIA
- * @readOnly
- * @writeOnce
- * @default true
- * @type boolean
- */
- useARIA: {
- writeOnce: true,
- value: false,
- validator: Lang.isBoolean
- },
-
- /**
- * CSS class to be automatically added to the <code>boundingBox</code>.
- *
- * @attribute cssClass
- * @default null
- * @type String
- */
- cssClass: {
- lazyAdd: false,
- value: null
- },
-
- /**
- * css class added to hide the <code>boundingBox</code> when
- * <a href="Component.html#config_visible">visible</a> is set to
- * <code>false</code>.
- *
- * @attribute hideClass
- * @default 'aui-helper-hidden'
- * @type String
- */
- hideClass: {
- value: CSS_HELPER_HIDDEN
- },
-
- /**
- * If <code>true</code> the render phase will be autimatically invoked
- * preventing the <code>.render()</code> manual call.
- *
- * @attribute render
- * @default false
- * @type boolean | Node
- */
- render: {
- value: false,
- writeOnce: true
- }
- };
-
- A.extend(
- Component,
- A.Widget,
- {
- /**
- * Construction logic executed during Component instantiation. Lifecycle.
- *
- * @method initializer
- * @protected
- */
- initializer: function(config) {
- var instance = this;
-
- if (config && config.cssClass) {
- instance._uiSetCssClass(config.cssClass);
- }
-
- instance.after('cssClassChange', instance._afterCssClassChange);
- },
-
- /**
- * 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);
- },
-
- /**
- * Toggle the visibility of the Panel toggling the value of the
- * <a href="Widget.html#config_visible">visible</a> attribute.
- *
- * @method toggle
- * @param visible Force the visibility of the component to this state.
- */
- toggle: function(visible) {
- var instance = this;
-
- if (!Lang.isBoolean(visible)) {
- visible = !instance.get('visible');
- }
-
- return instance.set('visible', visible);
- },
-
- _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_HELPER_HIDDEN, !value);
- }
- },
-
- /**
- * Fires after the value of the
- * <a href="Component.html#config_cssClass">cssClass</a> attribute change.
- *
- * @method _afterCssClassChange
- * @param {EventFacade} event
- * @protected
- */
- _afterCssClassChange: function(event) {
- var instance = this;
-
- instance._uiSetCssClass(event.newVal, event.prevVal);
- },
-
- /**
- * 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;
- }
- }
- },
-
- /**
- * Applies the CSS classes to the <code>boundingBox</code> and
- * <code>contentBox</code>.
- *
- * @method _uiSetCssClass
- * @protected
- * @param {String} newVal
- * @param {String} prevVal
- */
- _uiSetCssClass: function(newVal, prevVal) {
- var instance = this;
-
- var prevValContent = prevVal + '-content';
-
- var newValContent = newVal + '-content';
-
- var boundingBox = instance.get('boundingBox');
- var contentBox = instance.get('contentBox');
-
- boundingBox.replaceClass(prevVal, newVal);
- contentBox.replaceClass(prevValContent, newValContent);
- }
- }
- );
-
- Component.getById = function(id) {
- return INSTANCES[id];
- };
-
- var COMP_PROTO = Component.prototype;
-
- var DEFAULT_UI_ATTRS = A.Widget.prototype._UI_ATTRS;
-
- Component._applyCssPrefix = function(component) {
- if (component && component.NAME && !('CSS_PREFIX' in component)) {
- component.CSS_PREFIX = A.getClassName(String(component.NAME).toLowerCase());
- }
-
- return component;
- };
-
- 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;
- };
-
- Component.CSS_PREFIX = getClassName('component');
-
- var Base = A.Base;
-
- Component.build = function() {
- var component = Base.build.apply(Base, arguments);
-
- Component._applyCssPrefix(component);
-
- return component;
- };
-
- A.Component = Component;
-
- }, '@VERSION@' ,{skinnable:false, requires:['aui-classnamemanager','base-build','widget']});
|