NOBUG: Fixed file access permissions
[moodle.git] / lib / yuilib / 3.13.0 / widget-skin / widget-skin.js
blobed3d8408e5a6da78c1f495218319ff44bdd572b4
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('widget-skin', function (Y, NAME) {
10 /**
11  * Provides skin related utlility methods.
12  *
13  * @module widget
14  * @submodule widget-skin
15  */
16 var BOUNDING_BOX = "boundingBox",
17     CONTENT_BOX = "contentBox",
18     SKIN = "skin",
19     _getClassName = Y.ClassNameManager.getClassName;
21 /**
22  * Returns the name of the skin that's currently applied to the widget.
23  *
24  * Searches up the Widget's ancestor axis for, by default, a class
25  * yui3-skin-(name), and returns the (name) portion. Otherwise, returns null.
26  *
27  * This is only really useful after the widget's DOM structure is in the
28  * document, either by render or by progressive enhancement.
29  *
30  * @method getSkinName
31  * @for Widget
32  * @param {String} [skinPrefix] The prefix which the implementation uses for the skin
33  * ("yui3-skin-" is the default).
34  *
35  * NOTE: skinPrefix will be used as part of a regular expression:
36  *
37  *     new RegExp('\\b' + skinPrefix + '(\\S+)')
38  *
39  * Although an unlikely use case, literal characters which may result in an invalid
40  * regular expression should be escaped.
41  *
42  * @return {String} The name of the skin, or null, if a matching skin class is not found.
43  */
45 Y.Widget.prototype.getSkinName = function (skinPrefix) {
47     var root = this.get( CONTENT_BOX ) || this.get( BOUNDING_BOX ),
48         match,
49         search;
51     skinPrefix = skinPrefix || _getClassName(SKIN, "");
53     search = new RegExp( '\\b' + skinPrefix + '(\\S+)' );
55     if ( root ) {
56         root.ancestor( function ( node ) {
57             match = node.get( 'className' ).match( search );
58             return match;
59         } );
60     }
62     return ( match ) ? match[1] : null;
66 }, '3.13.0', {"requires": ["widget-base"]});