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/
8 YUI.add('datatable-highlight', function (Y, NAME) {
11 Adds support for highlighting columns with the mouse in a DataTable
14 @submodule datatable-highlight
19 var getClassName = Y.ClassNameManager.getClassName;
22 @class DataTable.Highlight
25 function Highlight() {}
29 Setting this to true will create a delegate on the DataTable adding the
30 default classname to the row when the mouse is over the row.
32 @attribute highlightRows
38 setter: '_setHighlightRows',
39 validator: Y.Lang.isBoolean
43 Setting this to true will create a delegate on the DataTable adding the
44 default classname to the column when the mouse is over the column.
46 @attribute highlightCols
52 setter: '_setHighlightCols',
53 validator: Y.Lang.isBoolean
57 Setting this to true will create a delegate on the DataTable adding the
58 default classname to the cell when the mouse is over it.
60 @attribute highlightCells
66 setter: '_setHighlightCells',
67 validator: Y.Lang.isBoolean
72 Highlight.prototype = {
75 An object consisting of classnames for a `row`, a `col` and a `cell` to
76 be applied to their respective objects when the user moves the mouse over
77 the item and the attribute is set to true.
80 @property highlightClassNames
84 highlightClassNames: {
85 row: getClassName(NAME, 'row'),
86 col: getClassName(NAME, 'col'),
87 cell: getClassName(NAME, 'cell')
91 A string that is used to create a column selector when the column is has
92 the mouse over it. Can contain the css prefix (`{prefix}`) and the column
93 name (`{col}`). Further substitution will require `_highlightCol` to be
97 @property _colSelector
101 _colSelector: '.{prefix}-data .{prefix}-col-{col}',
104 A string that will be used to create Regular Expression when column
105 highlighting is set to true. Uses the css prefix (`{prefix}`) from the
106 DataTable object to populate.
109 @property _colNameRegex
113 _colNameRegex: '{prefix}-col-(\\S*)',
116 This object will contain any delegates created when their feature is
120 @property _highlightDelegates
124 _highlightDelegates: {},
127 Default setter method for row highlighting. If the value is true, a
128 delegate is created and stored in `this._highlightDelegates.row`. This
129 delegate will add/remove the row highlight classname to/from the row when
130 the mouse enters/leaves a row on the `tbody`
133 @method _setHighlightRows
138 _setHighlightRows: function (val) {
139 var del = this._highlightDelegates;
146 del.row = this.delegate('hover',
147 Y.bind(this._highlightRow, this),
148 Y.bind(this._highlightRow, this),
156 Default setter method for column highlighting. If the value is true, a
157 delegate is created and stored in `this._highlightDelegates.col`. This
158 delegate will add/remove the column highlight classname to/from the
159 column when the mouse enters/leaves a column on the `tbody`
162 @method _setHighlightCols
167 _setHighlightCols: function (val) {
168 var del = this._highlightDelegates;
175 this._buildColSelRegex();
177 del.col = this.delegate('hover',
178 Y.bind(this._highlightCol, this),
179 Y.bind(this._highlightCol, this),
185 Default setter method for cell highlighting. If the value is true, a
186 delegate is created and stored in `this._highlightDelegates.cell`. This
187 delegate will add/remove the cell highlight classname to/from the cell
188 when the mouse enters/leaves a cell on the `tbody`
191 @method _setHighlightCells
196 _setHighlightCells: function (val) {
197 var del = this._highlightDelegates;
205 del.cell = this.delegate('hover',
206 Y.bind(this._highlightCell, this),
207 Y.bind(this._highlightCell, this),
215 Method called to turn on or off the row highlighting when the mouse
216 enters or leaves the row. This is determined by the event phase of the
217 hover event. Where `over` will turn on the highlighting and anything else
221 @method _highlightRow
222 @param {EventFacade} e Event from the hover event
225 _highlightRow: function (e) {
226 e.currentTarget.toggleClass(this.highlightClassNames.row, (e.phase === 'over'));
230 Method called to turn on or off the column highlighting when the mouse
231 enters or leaves the column. This is determined by the event phase of the
232 hover event. Where `over` will turn on the highlighting and anything else
236 @method _highlightCol
237 @param {EventFacade} e Event from the hover event
240 _highlightCol: function(e) {
241 var colName = this._colNameRegex.exec(e.currentTarget.getAttribute('class')),
242 selector = Y.Lang.sub(this._colSelector, {
243 prefix: this._cssPrefix,
247 this.view.tableNode.all(selector).toggleClass(this.highlightClassNames.col, (e.phase === 'over'));
251 Method called to turn on or off the cell highlighting when the mouse
252 enters or leaves the cell. This is determined by the event phase of the
253 hover event. Where `over` will turn on the highlighting and anything else
257 @method _highlightCell
258 @param {EventFacade} e Event from the hover event
261 _highlightCell: function(e) {
262 e.currentTarget.toggleClass(this.highlightClassNames.cell, (e.phase === 'over'));
266 Used to transform the `_colNameRegex` to a Regular Expression when the
267 column highlighting is initially turned on. If `_colNameRegex` is not a
268 string when this method is called, no action is taken.
271 @method _buildColSelRegex
274 _buildColSelRegex: function () {
275 var str = this._colNameRegex,
278 if (typeof str === 'string') {
279 this._colNameRegex = new RegExp(Y.Lang.sub(str, { prefix: this._cssPrefix }));
284 Y.DataTable.Highlight = Highlight;
286 Y.Base.mix(Y.DataTable, [Y.DataTable.Highlight]);
289 }, '3.13.0', {"requires": ["datatable-base", "event-hover"], "skinnable": true});