3 $.extend(true, window, {
5 "AutoTooltips": AutoTooltips
10 * AutoTooltips plugin to show/hide tooltips when columns are too narrow to fit content.
12 * @param {boolean} [options.enableForCells=true] - Enable tooltip for grid cells
13 * @param {boolean} [options.enableForHeaderCells=false] - Enable tooltip for header cells
14 * @param {number} [options.maxToolTipLength=null] - The maximum length for a tooltip
16 function AutoTooltips(options) {
21 enableForHeaderCells: false,
22 maxToolTipLength: null
29 options = $.extend(true, {}, _defaults, options);
31 if (options.enableForCells) _grid.onMouseEnter.subscribe(handleMouseEnter);
32 if (options.enableForHeaderCells) _grid.onHeaderMouseEnter.subscribe(handleHeaderMouseEnter);
39 if (options.enableForCells) _grid.onMouseEnter.unsubscribe(handleMouseEnter);
40 if (options.enableForHeaderCells) _grid.onHeaderMouseEnter.unsubscribe(handleHeaderMouseEnter);
44 * Handle mouse entering grid cell to add/remove tooltip.
45 * @param {jQuery.Event} e - The event
47 function handleMouseEnter(e) {
48 var cell = _grid.getCellFromEvent(e);
50 var $node = $(_grid.getCellNode(cell.row, cell.cell));
52 if ($node.innerWidth() < $node[0].scrollWidth) {
53 text = $.trim($node.text());
54 if (options.maxToolTipLength && text.length > options.maxToolTipLength) {
55 text = text.substr(0, options.maxToolTipLength - 3) + "...";
60 $node.attr("title", text);
65 * Handle mouse entering header cell to add/remove tooltip.
66 * @param {jQuery.Event} e - The event
67 * @param {object} args.column - The column definition
69 function handleHeaderMouseEnter(e, args) {
70 var column = args.column,
71 $node = $(e.target).closest(".slick-header-column");
72 if (!column.toolTip) {
73 $node.attr("title", ($node.innerWidth() < $node[0].scrollWidth) ? column.name : "");