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