Visitar URL original
Extract Functions.tooltip() into modules/tooltip.js · phpmyadmin/phpmyadmin@93e7f10 · GitHub
Skip to content

Commit 93e7f10

Browse files
committed
Extract Functions.tooltip() into modules/tooltip.js
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent f807786 commit 93e7f10

6 files changed

Lines changed: 43 additions & 65 deletions

File tree

‎js/src/database/structure.js‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AJAX } from '../modules/ajax.js';
33
import { Functions } from '../modules/functions.js';
44
import { Navigation } from '../modules/navigation.js';
55
import { CommonParams } from '../modules/common.js';
6+
import tooltip from '../modules/tooltip.js';
67

78
/**
89
* @fileoverview functions used on the database structure page
@@ -424,11 +425,7 @@ AJAX.registerOnload('database/structure.js', function () {
424425

425426
// Add tooltip to favorite icons.
426427
$('.favorite_table_anchor').each(function () {
427-
Functions.tooltip(
428-
$(this),
429-
'a',
430-
$(this).attr('title')
431-
);
428+
tooltip($(this), 'a', $(this).attr('title'));
432429
});
433430

434431
// Get real row count via Ajax.

‎js/src/makegrid.js‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import $ from 'jquery';
22
import { AJAX } from './modules/ajax.js';
33
import { Functions } from './modules/functions.js';
44
import { CommonParams } from './modules/common.js';
5+
import tooltip from './modules/tooltip.js';
56

67
/* global Sql */
78
/* global firstDayOfCalendar */ // templates/javascript/variables.twig
@@ -1738,11 +1739,7 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
17381739
// make sure we have more than one column
17391740
if ($firstRowCols.length > 1) {
17401741
var $colVisibTh = $(g.t).find('th:not(.draggable)').slice(0, 1);
1741-
Functions.tooltip(
1742-
$colVisibTh,
1743-
'th',
1744-
window.Messages.strColVisibHint
1745-
);
1742+
tooltip($colVisibTh, 'th', window.Messages.strColVisibHint);
17461743

17471744
// create column visibility drop-down arrow(s)
17481745
$colVisibTh.each(function () {
@@ -2252,11 +2249,7 @@ window.makeGrid = function (t, enableResize, enableReorder, enableVisib, enableG
22522249
}
22532250

22542251
// create tooltip for each <th> with draggable class
2255-
Functions.tooltip(
2256-
$(t).find('th.draggable'),
2257-
'th',
2258-
g.updateHint()
2259-
);
2252+
tooltip($(t).find('th.draggable'), 'th', g.updateHint());
22602253

22612254
// register events for hint tooltip (anchors inside draggable th)
22622255
$(t).find('th.draggable a')

‎js/src/modules/functions.js‎

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { mysqlDocKeyword, mysqlDocBuiltin } from './doc-links.js';
66
import { Indexes } from './indexes.js';
77
import { Config } from './config.js';
88
import { resizeTopMenu } from './menu-resizer.js';
9+
import tooltip from './tooltip.js';
910

1011
/* global ChartType, ColumnType, DataTable, JQPlotChartFactory */ // js/chart.js
1112
/* global DatabaseStructure */ // js/database/structure.js
@@ -198,7 +199,7 @@ Functions.addDatepicker = function ($thisElement, type, options) {
198199
if (type === 'time') {
199200
$thisElement.timepicker($.extend(defaultOptions, options));
200201
// Add a tip regarding entering MySQL allowed-values for TIME data-type
201-
Functions.tooltip($thisElement, 'input', window.Messages.strMysqlAllowedValuesTipTime);
202+
tooltip($thisElement, 'input', window.Messages.strMysqlAllowedValuesTipTime);
202203
} else {
203204
$thisElement.datetimepicker($.extend(defaultOptions, options));
204205
}
@@ -242,9 +243,9 @@ Functions.addDateTimePicker = function () {
242243
// Add a tip regarding entering MySQL allowed-values
243244
// for TIME and DATE data-type
244245
if ($(this).hasClass('timefield')) {
245-
Functions.tooltip($(this), 'input', window.Messages.strMysqlAllowedValuesTipTime);
246+
tooltip($(this), 'input', window.Messages.strMysqlAllowedValuesTipTime);
246247
} else if ($(this).hasClass('datefield')) {
247-
Functions.tooltip($(this), 'input', window.Messages.strMysqlAllowedValuesTipDate);
248+
tooltip($(this), 'input', window.Messages.strMysqlAllowedValuesTipDate);
248249
}
249250
});
250251
}
@@ -364,33 +365,6 @@ Functions.clearSelection = function () {
364365
}
365366
};
366367

367-
/**
368-
* Create a jQuery UI tooltip
369-
*
370-
* @param $elements jQuery object representing the elements
371-
* @param item the item
372-
* (see https://api.jqueryui.com/tooltip/#option-items)
373-
* @param myContent content of the tooltip
374-
* @param additionalOptions to override the default options
375-
*
376-
*/
377-
Functions.tooltip = function ($elements, item, myContent, additionalOptions) {
378-
if ($('#no_hint').length > 0) {
379-
return;
380-
}
381-
382-
var defaultOptions = {
383-
content: myContent,
384-
items: item,
385-
tooltipClass: 'tooltip',
386-
track: true,
387-
show: false,
388-
hide: false
389-
};
390-
391-
$elements.uiTooltip($.extend(true, defaultOptions, additionalOptions));
392-
};
393-
394368
/**
395369
* @param {string} value
396370
* @return {string}
@@ -1675,11 +1649,7 @@ Functions.ajaxShowMessage = function (message = null, timeout = null, type = nul
16751649
* Add a tooltip to the notification to let the user know that they
16761650
* can dismiss the ajax notification by clicking on it.
16771651
*/
1678-
Functions.tooltip(
1679-
$retval,
1680-
'span',
1681-
window.Messages.strDismiss
1682-
);
1652+
tooltip($retval, 'span', window.Messages.strDismiss);
16831653
}
16841654
// Hide spinner if this is not a loading message
16851655
if (msg !== window.Messages.strLoading) {
@@ -3293,11 +3263,7 @@ Functions.showHints = function ($div) {
32933263
$newDiv = $('body');
32943264
}
32953265
$newDiv.find('.pma_hint').each(function () {
3296-
Functions.tooltip(
3297-
$(this).children('img'),
3298-
'img',
3299-
$(this).children('span').html()
3300-
);
3266+
tooltip($(this).children('img'), 'img', $(this).children('span').html());
33013267
});
33023268
};
33033269

‎js/src/modules/navigation.js‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Functions } from './functions.js';
33
import { CommonParams } from './common.js';
44
import { Config } from './config.js';
55
import { resizeTopMenu } from './menu-resizer.js';
6+
import tooltip from './tooltip.js';
67

78
/**
89
* function used in or for navigation panel
@@ -547,11 +548,7 @@ Navigation.onload = () => function () {
547548
if (data.changes) {
548549
$('#pma_favorite_list').html(data.list);
549550
$('#' + anchorId).parent().html(data.anchor);
550-
Functions.tooltip(
551-
$('#' + anchorId),
552-
'a',
553-
$('#' + anchorId).attr('title')
554-
);
551+
tooltip($('#' + anchorId), 'a', $('#' + anchorId).attr('title'));
555552
// Update localStorage.
556553
if (Config.isStorageSupported('localStorage')) {
557554
window.localStorage.favoriteTables = data.favoriteTables;

‎js/src/modules/tooltip.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import $ from 'jquery';
2+
3+
/**
4+
* Create a jQuery UI tooltip
5+
*
6+
* @param $elements jQuery object representing the elements
7+
* @param {string} item the item (see https://api.jqueryui.com/tooltip/#option-items)
8+
* @param myContent content of the tooltip
9+
* @param {Object} additionalOptions to override the default options
10+
*
11+
* @return {void}
12+
*/
13+
export default function tooltip ($elements, item, myContent, additionalOptions = {}) {
14+
if ($('#no_hint').length > 0) {
15+
return;
16+
}
17+
18+
const defaultOptions = {
19+
content: myContent,
20+
items: item,
21+
tooltipClass: 'tooltip',
22+
track: true,
23+
show: false,
24+
hide: false
25+
};
26+
27+
$elements.uiTooltip($.extend(true, defaultOptions, additionalOptions));
28+
}

‎js/src/server/status/monitor.js‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AJAX } from '../../modules/ajax.js';
33
import { Functions } from '../../modules/functions.js';
44
import { CommonParams } from '../../modules/common.js';
55
import { Config } from '../../modules/config.js';
6+
import tooltip from '../../modules/tooltip.js';
67

78
/**
89
* @fileoverview Javascript functions used in server status monitor page
@@ -2089,11 +2090,7 @@ AJAX.registerOnload('server/status/monitor.js', function () {
20892090
tooltipContent += '<p>' + window.Messages.strMoreCountColumnExplanation + '</p>';
20902091
}
20912092

2092-
Functions.tooltip(
2093-
$('img.qroupedQueryInfoIcon'),
2094-
'img',
2095-
tooltipContent
2096-
);
2093+
tooltip($('img.qroupedQueryInfoIcon'), 'img', tooltipContent);
20972094
}
20982095

20992096
$('#logTable').find('table').tablesorter({

0 commit comments

Comments
 (0)