aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/adm/style/tooltip.js
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/adm/style/tooltip.js')
-rw-r--r--phpBB/adm/style/tooltip.js304
1 files changed, 147 insertions, 157 deletions
diff --git a/phpBB/adm/style/tooltip.js b/phpBB/adm/style/tooltip.js
index 3a89008706..68964034f0 100644
--- a/phpBB/adm/style/tooltip.js
+++ b/phpBB/adm/style/tooltip.js
@@ -10,206 +10,196 @@ phpBB Development Team:
- further adjustements
*/
-var head_text, tooltip_mode;
+(function($) { // Avoid conflicts with other libraries
-/**
-* Enable tooltip replacements for links
-*/
-function enable_tooltips_link(id, headline, sub_id) {
- var links, i, hold;
-
- head_text = headline;
-
- if (!document.getElementById || !document.getElementsByTagName) {
- return;
- }
-
- hold = document.createElement('span');
- hold.id = '_tooltip_container';
- hold.setAttribute('id', '_tooltip_container');
- hold.style.position = 'absolute';
+'use strict';
- document.getElementsByTagName('body')[0].appendChild(hold);
-
- if (id === null) {
- links = document.getElementsByTagName('a');
- } else {
- links = document.getElementById(id).getElementsByTagName('a');
- }
-
- for (i = 0; i < links.length; i++) {
- if (sub_id) {
- if (links[i].id.substr(0, sub_id.length) === sub_id) {
- prepare(links[i]);
- }
- } else {
- prepare(links[i]);
- }
- }
-
- tooltip_mode = 'link';
-}
+var tooltips = [];
/**
-* 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} [subId] Sub ID that should only be using tooltips (optional)
*/
-function enable_tooltips_select(id, headline, sub_id) {
- var links, i, hold;
-
- head_text = headline;
-
- if (!document.getElementById || !document.getElementsByTagName) {
- return;
- }
+phpbb.enableTooltipsSelect = function (id, headline, subId) {
+ var $links, hold;
- hold = document.createElement('span');
- hold.id = '_tooltip_container';
- hold.setAttribute('id', '_tooltip_container');
- hold.style.position = 'absolute';
+ hold = $('<span />', {
+ id: '_tooltip_container',
+ css: {
+ position: 'absolute'
+ }
+ });
- document.getElementsByTagName('body')[0].appendChild(hold);
+ $('body').append(hold);
- if (id === null) {
- links = document.getElementsByTagName('option');
+ if (!id) {
+ $links = $('.roles-options li');
} else {
- links = document.getElementById(id).getElementsByTagName('option');
+ $links = $('.roles-options li', '#' + id);
}
- for (i = 0; i < links.length; i++) {
- if (sub_id) {
- if (links[i].parentNode.id.substr(0, sub_id.length) === sub_id) {
- prepare(links[i]);
+ $links.each(function () {
+ var $this = $(this);
+
+ if (subId) {
+ if ($this.parent().attr('id').substr(0, subId.length) === subId) {
+ phpbb.prepareTooltips($this, headline);
}
} else {
- prepare(links[i]);
+ phpbb.prepareTooltips($this, headline);
}
- }
-
- tooltip_mode = 'select';
-}
+ });
+};
/**
-* Prepare elements to replace
+ * Prepare elements to replace
+ *
+ * @param {jQuery} $element Element to prepare for tooltips
+ * @param {string} headText Text heading to display
*/
-function prepare(element) {
- var tooltip, text, desc, title;
+phpbb.prepareTooltips = function ($element, headText) {
+ var $tooltip, text, $desc, $title;
- text = element.getAttribute('title');
+ text = $element.attr('data-title');
if (text === null || text.length === 0) {
return;
}
- element.removeAttribute('title');
- tooltip = create_element('span', 'tooltip');
-
- title = create_element('span', 'top');
- title.appendChild(document.createTextNode(head_text));
- tooltip.appendChild(title);
-
- desc = create_element('span', 'bottom');
- desc.innerHTML = text;
- tooltip.appendChild(desc);
-
- set_opacity(tooltip);
+ $title = $('<span />', {
+ class: 'top',
+ css: {
+ display: 'block'
+ }
+ })
+ .append(document.createTextNode(headText));
+
+ $desc = $('<span />', {
+ class: 'bottom',
+ html: text,
+ css: {
+ display: 'block'
+ }
+ });
- element.tooltip = tooltip;
- element.onmouseover = show_tooltip;
- element.onmouseout = hide_tooltip;
+ $tooltip = $('<span />', {
+ class: 'tooltip',
+ css: {
+ display: 'block'
+ }
+ })
+ .append($title)
+ .append($desc);
- if (tooltip_mode === 'link') {
- element.onmousemove = locate;
- }
-}
+ tooltips[$element.attr('data-id')] = $tooltip;
+ $element.on('mouseover', phpbb.showTooltip);
+ $element.on('mouseout', phpbb.hideTooltip);
+};
/**
-* Show tooltip
+ * Show tooltip
+ *
+ * @param {object} $element Element passed by .on()
*/
-function show_tooltip(e) {
- document.getElementById('_tooltip_container').appendChild(this.tooltip);
- locate(this);
-}
+phpbb.showTooltip = function ($element) {
+ var $this = $($element.target);
+ $('#_tooltip_container').append(tooltips[$this.attr('data-id')]);
+ phpbb.positionTooltip($this);
+};
/**
-* Hide tooltip
+ * Hide tooltip
*/
-function hide_tooltip(e) {
+phpbb.hideTooltip = function () {
var d = document.getElementById('_tooltip_container');
if (d.childNodes.length > 0) {
d.removeChild(d.firstChild);
}
-}
+};
/**
-* Set opacity on tooltip element
+ * Correct positioning of tooltip container
+ *
+ * @param {jQuery} $element Tooltip element that should be positioned
*/
-function set_opacity(element) {
- element.style.filter = 'alpha(opacity:95)';
- element.style.KHTMLOpacity = '0.95';
- element.style.MozOpacity = '0.95';
- element.style.opacity = '0.95';
-}
+phpbb.positionTooltip = function ($element) {
+ var offset;
-/**
-* Create new element
-*/
-function create_element(tag, c) {
- var x = document.createElement(tag);
- x.className = c;
- x.style.display = 'block';
- return x;
-}
-
-/**
-* Correct positioning of tooltip container
-*/
-function locate(e) {
- var posx = 0;
- var posy = 0;
+ $element = $element.parent();
+ offset = $element.offset();
- e = e.parentNode;
+ $('#_tooltip_container').css({
+ top: offset.top + 30,
+ left: offset.left - 205
+ });
+};
- if (e.offsetParent) {
- for (posx = 0, posy = 0; e.offsetParent; e = e.offsetParent) {
- posx += e.offsetLeft;
- posy += e.offsetTop;
+/**
+ * Prepare roles drop down select
+ */
+phpbb.prepareRolesDropdown = function () {
+ var $options = $('.roles-options li');
+ var $rolesOptions = $options.closest('.roles-options');
+ var $span = $rolesOptions.children('span');
+
+ // Prepare highlighting of select options and settings update
+ $options.each(function () {
+ var $this = $(this);
+
+ // Correctly show selected option
+ if (typeof $this.attr('data-selected') !== 'undefined') {
+ $rolesOptions.closest('.roles-options')
+ .children('span')
+ .text($this.text())
+ .attr('data-default', $this.text())
+ .attr('data-default-val', $this.attr('data-id'));
}
- } else {
- posx = e.offsetLeft;
- posy = e.offsetTop;
- }
- if (tooltip_mode === 'link') {
- document.getElementById('_tooltip_container').style.top=(posy+20) + 'px';
- document.getElementById('_tooltip_container').style.left=(posx-20) + 'px';
- } else {
- document.getElementById('_tooltip_container').style.top=(posy+30) + 'px';
- document.getElementById('_tooltip_container').style.left=(posx-205) + 'px';
+ $this.on('mouseover', function () {
+ var $this = $(this);
+ $options.removeClass('roles-highlight');
+ $this.addClass('roles-highlight');
+ }).on('click', function () {
+ var $this = $(this);
+
+ // Update settings
+ set_role_settings($this.attr('data-id'), $this.attr('data-target-id'));
+ init_colours($this.attr('data-target-id').replace('advanced', ''));
+
+ // Set selected setting
+ $rolesOptions.children('span')
+ .text($this.text());
+ $rolesOptions.children('input[type=hidden]')
+ .val($this.attr('data-id'));
+
+ // Trigger hiding of selection options
+ $('body').trigger('click');
+ });
+ });
+
+ // Save default text of drop down if there is no default set yet
+ if (typeof $span.attr('data-default') === 'undefined') {
+ $span.attr('data-default', $span.text());
}
-/*
- if (e == null)
- {
- e = window.event;
- }
+ // Prepare resetting drop down on form reset
+ $options.closest('form').on('reset', function () {
+ $span.text($span.attr('data-default'));
+ $rolesOptions.children('input[type=hidden]')
+ .val($span.attr('data-id'));
+ });
- if (e.pageX || e.pageY)
- {
- posx = e.pageX;
- posy = e.pageY;
- }
- else if (e.clientX || e.clientY)
- {
- if (document.documentElement.scrollTop)
- {
- posx = e.clientX+document.documentElement.scrollLeft;
- posy = e.clientY+document.documentElement.scrollTop;
- }
- else
- {
- posx = e.clientX+document.body.scrollLeft;
- posy = e.clientY+document.body.scrollTop;
- }
- }
-*/
-}
+};
+
+// Run onload functions for RolesDropdown and tooltips
+$(function() {
+ // Enable tooltips
+ phpbb.enableTooltipsSelect('set-permissions', $('#set-permissions').attr('data-role-description'), 'role');
+
+ // Prepare dropdown
+ phpbb.prepareRolesDropdown();
+});
+
+})(jQuery); // Avoid conflicts with other libraries