[ticket/6466] Improved code in tooltip.js

PHPBB3-6466
This commit is contained in:
Marc Alexander 2015-05-29 17:06:14 +02:00
parent 4d827b5b99
commit faa5ab5899

View file

@ -12,7 +12,7 @@ phpBB Development Team:
(function($) { // Avoid conflicts with other libraries (function($) { // Avoid conflicts with other libraries
"use strict"; 'use strict';
var head_text, tooltip_mode, tooltips; var head_text, tooltip_mode, tooltips;
tooltips = []; tooltips = [];
@ -57,6 +57,9 @@ function enable_tooltips_link(id, headline, sub_id) {
/** /**
* Enable tooltip replacements for selects * Enable tooltip replacements for selects
* @param {string} id ID tag of select
* @param {string} headline Text that should appear on top of tooltip
* @param {string} sub_id Sub ID that should only be using tooltips (optional)
*/ */
function enable_tooltips_select(id, headline, sub_id) { function enable_tooltips_select(id, headline, sub_id) {
var $links, hold; var $links, hold;
@ -76,7 +79,7 @@ function enable_tooltips_select(id, headline, sub_id) {
if (id === null) { if (id === null) {
$links = $('.roles-options li'); $links = $('.roles-options li');
} else { } else {
$links = $('#' + id + ' .roles-options li'); $links = $('.roles-options li', '#' + id);
} }
$links.each(function () { $links.each(function () {
@ -96,6 +99,8 @@ function enable_tooltips_select(id, headline, sub_id) {
/** /**
* Prepare elements to replace * Prepare elements to replace
*
* @param {object} $element Element to prepare for tooltips
*/ */
function prepare($element) { function prepare($element) {
var tooltip, text, desc, title; var tooltip, text, desc, title;
@ -129,17 +134,21 @@ function prepare($element) {
/** /**
* Show tooltip * Show tooltip
*
* @param {object} $element Element passed by .on()
*/ */
function show_tooltip(e) { function show_tooltip($element) {
var $this = $(e.target); var $this = $($element.target);
$('#_tooltip_container').append(tooltips[$this.attr('data-id')]); $('#_tooltip_container').append(tooltips[$this.attr('data-id')]);
locate($this); locate($this);
} }
/** /**
* Hide tooltip * Hide tooltip
*
* @param {object} $element Element passed by .on()
*/ */
function hide_tooltip(e) { function hide_tooltip($element) {
var d = document.getElementById('_tooltip_container'); var d = document.getElementById('_tooltip_container');
if (d.childNodes.length > 0) { if (d.childNodes.length > 0) {
d.removeChild(d.firstChild); d.removeChild(d.firstChild);
@ -168,12 +177,14 @@ function create_element(tag, c) {
/** /**
* Correct positioning of tooltip container * Correct positioning of tooltip container
*
* @param {object} $element Tooltip element that should be positioned
*/ */
function locate(e) { function locate($element) {
var offset; var offset;
e = e.parent(); $element = $element.parent();
offset = e.offset(); offset = $element.offset();
if (tooltip_mode === 'link') { if (tooltip_mode === 'link') {
$('#_tooltip_container').css({ $('#_tooltip_container').css({