NOBUG: Fixed file access permissions
[moodle.git] / lib / yuilib / 3.13.0 / scrollview-list / scrollview-list.js
blob5d8914c3b8f65c3e09b000951974060d5e4a2680
1 /*
2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
8 YUI.add('scrollview-list', function (Y, NAME) {
10 /**
11  * Provides a plugin, which adds support for a scroll indicator to ScrollView instances
12  *
13  * @module scrollview-list
14  */
15 var getCN = Y.ClassNameManager.getClassName,
16 SCROLLVIEW = 'scrollview',
17 LIST_CLASS = getCN(SCROLLVIEW, 'list'),
18 ITEM_CLASS = getCN(SCROLLVIEW, 'item'),
19 CONTENT_BOX = "contentBox",
20 HOST = "host";
22 /**
23  * ScrollView plugin that adds class names to immediate descendant "<li>" to
24  *  allow for easier styling through CSS
25  *
26  * @class ScrollViewList
27  * @namespace Plugin
28  * @extends Plugin.Base
29  * @constructor
30  */
31 function ListPlugin() {
32     ListPlugin.superclass.constructor.apply(this, arguments);
36 /**
37  * The identity of the plugin
38  *
39  * @property NAME
40  * @type String
41  * @default 'pluginList'
42  * @static
43  */
44 ListPlugin.NAME = 'pluginList';
46 /**
47  * The namespace on which the plugin will reside.
48  *
49  * @property NS
50  * @type String
51  * @default 'list'
52  * @static
53  */
54 ListPlugin.NS = 'list';
57 /**
58  * The default attribute configuration for the plugin
59  *
60  * @property ATTRS
61  * @type Object
62  * @static
63  */
64 ListPlugin.ATTRS = {
66     /**
67      * Specifies whether the list elements (the immediate <ul>'s and the
68      *  immediate <li>'s inside those <ul>'s) have class names attached to
69      *  them or not
70      *
71      * @attribute isAttached
72      * @type boolean
73      * @deprecated No real use for this attribute on the public API
74      */
75     isAttached: {
76         value:false,
77         validator: Y.Lang.isBoolean
78     }
81 Y.namespace("Plugin").ScrollViewList = Y.extend(ListPlugin, Y.Plugin.Base, {
83     /**
84      * Designated initializer
85      *
86      * @method initializer
87      */
88     initializer: function() {
89         this._host = this.get(HOST);
90         this.afterHostEvent("render", this._addClassesToList);
91     },
93     _addClassesToList: function() {
94         if (!this.get('isAttached')) {
95             var cb = this._host.get(CONTENT_BOX),
96             ulList,
97             liList;
99             if (cb.hasChildNodes()) {
100                 //get all direct descendants of the UL's that are directly under the content box.
101                 ulList = cb.all('> ul');
102                 liList = cb.all('> ul > li');
104                 //go through the UL's and add the class
105                 ulList.each(function(list) {
106                     list.addClass(LIST_CLASS);
107                 });
109                 //go through LI's and add the class
110                 liList.each(function(item) {
111                     item.addClass(ITEM_CLASS);
112                 });
114                 this.set('isAttached', true);
116                 // We need to call this again, since sv-list
117                 //  relies on the "-vert" class, to apply padding.
118                 //  [ 1st syncUI pass applies -vert, 2nd pass re-calcs dims ]
119                 this._host.syncUI();
120             }
121         }
122     }
137 }, '3.13.0', {"requires": ["plugin", "classnamemanager"], "skinnable": true});