[ticket/6466] Rename functions and clean up code

PHPBB3-6466
This commit is contained in:
Marc Alexander 2015-05-29 17:34:42 +02:00
parent abf0be4b4c
commit 120600e055

View file

@ -22,7 +22,7 @@ var tooltips = [];
* @param {string} headline Text that should appear on top of tooltip * @param {string} headline Text that should appear on top of tooltip
* @param {string} sub_id Sub ID that should only be using tooltips (optional) * @param {string} sub_id Sub ID that should only be using tooltips (optional)
*/ */
function enable_tooltips_select(id, headline, sub_id) { phpbb.enableTooltipsSelect = function (id, headline, sub_id) {
var $links, hold; var $links, hold;
hold = document.createElement('span'); hold = document.createElement('span');
@ -42,13 +42,13 @@ function enable_tooltips_select(id, headline, sub_id) {
if (sub_id) { if (sub_id) {
if ($this.parent().attr('id').substr(0, sub_id.length) === sub_id) { if ($this.parent().attr('id').substr(0, sub_id.length) === sub_id) {
prepare($this, headline); phpbb.prepareTooltips($this, headline);
} }
} else { } else {
prepare($this, headline); phpbb.prepareTooltips($this, headline);
} }
}); });
} };
/** /**
* Prepare elements to replace * Prepare elements to replace
@ -56,7 +56,7 @@ function enable_tooltips_select(id, headline, sub_id) {
* @param {object} $element Element to prepare for tooltips * @param {object} $element Element to prepare for tooltips
* @param {string} head_text Text heading to display * @param {string} head_text Text heading to display
*/ */
function prepare($element, head_text) { phpbb.prepareTooltips = function ($element, head_text) {
var tooltip, text, desc, title; var tooltip, text, desc, title;
text = $element.attr('data-title'); text = $element.attr('data-title');
@ -65,43 +65,43 @@ function prepare($element, head_text) {
return; return;
} }
title = create_element('span', 'top'); title = phpbb.createElement('span', 'top');
title.appendChild(document.createTextNode(head_text)); title.appendChild(document.createTextNode(head_text));
desc = create_element('span', 'bottom'); desc = phpbb.createElement('span', 'bottom');
desc.innerHTML = text; desc.innerHTML = text;
tooltip = create_element('span', 'tooltip'); tooltip = phpbb.createElement('span', 'tooltip');
tooltip.appendChild(title); tooltip.appendChild(title);
tooltip.appendChild(desc); tooltip.appendChild(desc);
tooltips[$element.attr('data-id')] = tooltip; tooltips[$element.attr('data-id')] = tooltip;
$element.on('mouseover', show_tooltip); $element.on('mouseover', phpbb.showTooltip);
$element.on('mouseout', hide_tooltip); $element.on('mouseout', phpbb.hideTooltip);
} };
/** /**
* Show tooltip * Show tooltip
* *
* @param {object} $element Element passed by .on() * @param {object} $element Element passed by .on()
*/ */
function show_tooltip($element) { phpbb.showTooltip = function ($element) {
var $this = $($element.target); var $this = $($element.target);
$('#_tooltip_container').append(tooltips[$this.attr('data-id')]); $('#_tooltip_container').append(tooltips[$this.attr('data-id')]);
locate($this); phpbb.positionTooltip($this);
} };
/** /**
* Hide tooltip * Hide tooltip
* *
* @param {object} $element Element passed by .on() * @param {object} $element Element passed by .on()
*/ */
function hide_tooltip($element) { phpbb.hideTooltip = function () {
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);
} }
} };
/** /**
* Create new element * Create new element
@ -111,19 +111,19 @@ function hide_tooltip($element) {
* *
* @return {object} Created element * @return {object} Created element
*/ */
function create_element(tag, c) { phpbb.createElement = function (tag, c) {
var x = document.createElement(tag); var x = document.createElement(tag);
x.className = c; x.className = c;
x.style.display = 'block'; x.style.display = 'block';
return x; return x;
} };
/** /**
* Correct positioning of tooltip container * Correct positioning of tooltip container
* *
* @param {object} $element Tooltip element that should be positioned * @param {object} $element Tooltip element that should be positioned
*/ */
function locate($element) { phpbb.positionTooltip = function ($element) {
var offset; var offset;
$element = $element.parent(); $element = $element.parent();
@ -133,25 +133,22 @@ function locate($element) {
top: offset.top + 30, top: offset.top + 30,
left: offset.left - 205 left: offset.left - 205
}); });
} };
$(function() { /**
var $options; * Prepare roles drop down select
*/
// Enable tooltips phpbb.prepareRolesDropdown = function () {
enable_tooltips_select('set-permissions', $('#set-permissions').attr('data-role-description'), 'role'); var $options = $('.roles-options li');
$options = $('.roles-options li');
// Prepare highlighting of select options and settings update // Prepare highlighting of select options and settings update
$options.each(function () { $options.each(function (element) {
var $this = $(this); var $this = $(this);
var $roles_options = $this.closest('.roles-options'); var $roles_options = $this.closest('.roles-options');
// Correctly show selected option // Correctly show selected option
if (typeof $this.attr('data-selected') !== 'undefined') { if (typeof $this.attr('data-selected') !== 'undefined') {
$this.closest('.roles-options').children('span').text($this.text()); $this.closest('.roles-options').children('span').text($this.text());
$('')
} }
$this.on('mouseover', function (e) { $this.on('mouseover', function (e) {
@ -173,6 +170,15 @@ $(function() {
$('body').trigger('click'); $('body').trigger('click');
}); });
}); });
};
// 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 })(jQuery); // Avoid conflicts with other libraries