From 467c794b9779412cf2cc29deb42c232168989486 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 29 May 2015 16:05:16 +0200 Subject: [PATCH 01/13] [ticket/6466] Use jQuery and custom dropdown for permission roles tooltips PHPBB3-6466 --- phpBB/adm/style/acp_permissions.html | 9 +- phpBB/adm/style/admin.css | 33 +++++++ phpBB/adm/style/permission_mask.html | 13 ++- phpBB/adm/style/tooltip.js | 129 ++++++++++++++------------- phpBB/includes/acp/auth.php | 6 ++ 5 files changed, 119 insertions(+), 71 deletions(-) diff --git a/phpBB/adm/style/acp_permissions.html b/phpBB/adm/style/acp_permissions.html index 6dc9dca2e7..004027df41 100644 --- a/phpBB/adm/style/acp_permissions.html +++ b/phpBB/adm/style/acp_permissions.html @@ -327,14 +327,9 @@

- - + -
+ {S_HIDDEN_FIELDS} diff --git a/phpBB/adm/style/admin.css b/phpBB/adm/style/admin.css index b03cb0ba24..8ae39b7754 100644 --- a/phpBB/adm/style/admin.css +++ b/phpBB/adm/style/admin.css @@ -2435,6 +2435,39 @@ fieldset.permissions .padding { display: none !important; } +.roles-options > .dropdown { + left: auto; + top: 3em; + width: 250px; +} + +.roles-options { + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + -o-user-select: none; + user-select: none; + width: 250px; +} + +.roles-options > span { + border: 1px solid #DEDEDE; + border-radius: 3px; + padding: 4px; + width: 250px; + display: block; + background: url('../images/arrow_down.gif') no-repeat 245px .7em; +} + +.roles-options li { + list-style: none; +} + +.roles-highlight { + background-color: #1e90ff; + color: #fff; +} + /* Classes for additional tasks ---------------------------------------- */ diff --git a/phpBB/adm/style/permission_mask.html b/phpBB/adm/style/permission_mask.html index 7b5c071693..5aeafba476 100644 --- a/phpBB/adm/style/permission_mask.html +++ b/phpBB/adm/style/permission_mask.html @@ -40,7 +40,18 @@
-
+
+ +
{L_NO_ROLE_AVAILABLE}
diff --git a/phpBB/adm/style/tooltip.js b/phpBB/adm/style/tooltip.js index 3a89008706..ec170ef6b2 100644 --- a/phpBB/adm/style/tooltip.js +++ b/phpBB/adm/style/tooltip.js @@ -10,7 +10,12 @@ phpBB Development Team: - further adjustements */ -var head_text, tooltip_mode; +(function($) { // Avoid conflicts with other libraries + +"use strict"; + +var head_text, tooltip_mode, tooltips; +tooltips = []; /** * Enable tooltip replacements for links @@ -54,7 +59,7 @@ function enable_tooltips_link(id, headline, sub_id) { * Enable tooltip replacements for selects */ function enable_tooltips_select(id, headline, sub_id) { - var links, i, hold; + var $links, hold; head_text = headline; @@ -66,24 +71,25 @@ function enable_tooltips_select(id, headline, sub_id) { hold.id = '_tooltip_container'; hold.setAttribute('id', '_tooltip_container'); hold.style.position = 'absolute'; - - document.getElementsByTagName('body')[0].appendChild(hold); + $('body').append(hold); if (id === null) { - links = document.getElementsByTagName('option'); + $links = $('.roles-options li'); } else { - links = document.getElementById(id).getElementsByTagName('option'); + $links = $('#' + id + ' .roles-options li'); } - for (i = 0; i < links.length; i++) { + $links.each(function () { + var $this = $(this); + if (sub_id) { - if (links[i].parentNode.id.substr(0, sub_id.length) === sub_id) { - prepare(links[i]); + if ($this.parent().attr('id').substr(0, sub_id.length) === sub_id) { + prepare($this); } } else { - prepare(links[i]); + prepare($this); } - } + }); tooltip_mode = 'select'; } @@ -91,16 +97,15 @@ function enable_tooltips_select(id, headline, sub_id) { /** * Prepare elements to replace */ -function prepare(element) { +function prepare($element) { 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'); @@ -113,12 +118,12 @@ function prepare(element) { set_opacity(tooltip); - element.tooltip = tooltip; - element.onmouseover = show_tooltip; - element.onmouseout = hide_tooltip; + tooltips[$element.attr('data-id')] = tooltip; + $element.on('mouseover', show_tooltip); + $element.on('mouseout', hide_tooltip); if (tooltip_mode === 'link') { - element.onmousemove = locate; + $element.onmousemove = locate; } } @@ -126,8 +131,9 @@ function prepare(element) { * Show tooltip */ function show_tooltip(e) { - document.getElementById('_tooltip_container').appendChild(this.tooltip); - locate(this); + var $this = $(e.target); + $('#_tooltip_container').append(tooltips[$this.attr('data-id')]); + locate($this); } /** @@ -164,52 +170,49 @@ function create_element(tag, c) { * Correct positioning of tooltip container */ function locate(e) { - var posx = 0; - var posy = 0; + var offset; - e = e.parentNode; - - if (e.offsetParent) { - for (posx = 0, posy = 0; e.offsetParent; e = e.offsetParent) { - posx += e.offsetLeft; - posy += e.offsetTop; - } - } else { - posx = e.offsetLeft; - posy = e.offsetTop; - } + e = e.parent(); + offset = e.offset(); if (tooltip_mode === 'link') { - document.getElementById('_tooltip_container').style.top=(posy+20) + 'px'; - document.getElementById('_tooltip_container').style.left=(posx-20) + 'px'; + $('#_tooltip_container').css({ + top: offset.top + 20, + left: offset.left - 20 + }); } else { - document.getElementById('_tooltip_container').style.top=(posy+30) + 'px'; - document.getElementById('_tooltip_container').style.left=(posx-205) + 'px'; + $('#_tooltip_container').css({ + top: offset.top + 30, + left: offset.left - 205 + }); } - -/* - if (e == null) - { - e = window.event; - } - - 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; - } - } -*/ } + +$(function() { + var $options; + + // Enable tooltips + enable_tooltips_select('set-permissions', $('#set-permissions').attr('data-role-description'), 'role'); + + $options = $('.roles-options li'); + + // Prepare highlighting of select options and settings update + $options.each(function () { + $(this).on('mouseover', function (e) { + var $this = $(this); + $options.removeClass('roles-highlight'); + $this.addClass('roles-highlight'); + }).on('click', function (e) { + 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 + $this.closest('.roles-options').children('span').text($this.text()); + }); + }); +}); + +})(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/includes/acp/auth.php b/phpBB/includes/acp/auth.php index 644b1ac7a5..0f149ca907 100644 --- a/phpBB/includes/acp/auth.php +++ b/phpBB/includes/acp/auth.php @@ -480,6 +480,12 @@ class auth_admin extends \phpbb\auth\auth $title = ($role_description) ? ' title="' . $role_description . '"' : ''; $s_role_options .= ''; + $template->assign_block_vars('role_options', array( + 'ID' => $role_id, + 'ROLE_NAME' => $role_name, + 'TITLE' => $role_description, + 'SELECTED' => $role_id == $current_role_id, + )); } if ($s_role_options) From fc00447520d19ac2e0c6667f1c2cf5e7b41913a2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 29 May 2015 16:44:12 +0200 Subject: [PATCH 02/13] [ticket/6466] Improve behavior of select and properly save role PHPBB3-6466 --- phpBB/adm/style/permission_mask.html | 5 +++-- phpBB/adm/style/tooltip.js | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/phpBB/adm/style/permission_mask.html b/phpBB/adm/style/permission_mask.html index 5aeafba476..7569867f8c 100644 --- a/phpBB/adm/style/permission_mask.html +++ b/phpBB/adm/style/permission_mask.html @@ -44,12 +44,13 @@ diff --git a/phpBB/adm/style/tooltip.js b/phpBB/adm/style/tooltip.js index ec170ef6b2..60222e51d5 100644 --- a/phpBB/adm/style/tooltip.js +++ b/phpBB/adm/style/tooltip.js @@ -198,7 +198,16 @@ $(function() { // Prepare highlighting of select options and settings update $options.each(function () { - $(this).on('mouseover', function (e) { + var $this = $(this); + var $roles_options = $this.closest('.roles-options'); + + // Correctly show selected option + if (typeof $this.attr('data-selected') !== 'undefined') { + $this.closest('.roles-options').children('span').text($this.text()); + $('') + } + + $this.on('mouseover', function (e) { var $this = $(this); $options.removeClass('roles-highlight'); $this.addClass('roles-highlight'); @@ -210,7 +219,11 @@ $(function() { init_colours($this.attr('data-target-id').replace('advanced', '')); // Set selected setting - $this.closest('.roles-options').children('span').text($this.text()); + $roles_options.children('span').text($this.text()); + $roles_options.children('input[type=hidden]').val($this.attr('data-id')); + + // Trigger hiding of selection options + $('body').trigger('click'); }); }); }); From 4d827b5b994f5efa2ec79583a87facb01897727f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 29 May 2015 16:56:24 +0200 Subject: [PATCH 03/13] [ticket/6466] Remove remnants of old code PHPBB3-6466 --- phpBB/adm/style/permission_mask.html | 6 +++--- phpBB/includes/acp/auth.php | 26 ++++++-------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/phpBB/adm/style/permission_mask.html b/phpBB/adm/style/permission_mask.html index 7569867f8c..91894ebc77 100644 --- a/phpBB/adm/style/permission_mask.html +++ b/phpBB/adm/style/permission_mask.html @@ -39,7 +39,7 @@
- + {% if role_options %}
- + {% else %}
{L_NO_ROLE_AVAILABLE}
- + {% endif %}
diff --git a/phpBB/includes/acp/auth.php b/phpBB/includes/acp/auth.php index 0f149ca907..efb92685f6 100644 --- a/phpBB/includes/acp/auth.php +++ b/phpBB/includes/acp/auth.php @@ -470,16 +470,12 @@ class auth_admin extends \phpbb\auth\auth // Build role dropdown options $current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0; - $s_role_options = ''; - @reset($roles); while (list($role_id, $role_row) = each($roles)) { $role_description = (!empty($user->lang[$role_row['role_description']])) ? $user->lang[$role_row['role_description']] : nl2br($role_row['role_description']); $role_name = (!empty($user->lang[$role_row['role_name']])) ? $user->lang[$role_row['role_name']] : $role_row['role_name']; - $title = ($role_description) ? ' title="' . $role_description . '"' : ''; - $s_role_options .= ''; $template->assign_block_vars('role_options', array( 'ID' => $role_id, 'ROLE_NAME' => $role_name, @@ -488,11 +484,6 @@ class auth_admin extends \phpbb\auth\auth )); } - if ($s_role_options) - { - $s_role_options = '' . $s_role_options; - } - if (!$current_role_id && $mode != 'view') { $s_custom_permissions = false; @@ -513,7 +504,6 @@ class auth_admin extends \phpbb\auth\auth $template->assign_block_vars($tpl_pmask . '.' . $tpl_fmask, array( 'NAME' => $ug_names_ary[$ug_id], - 'S_ROLE_OPTIONS' => $s_role_options, 'UG_ID' => $ug_id, 'S_CUSTOM' => $s_custom_permissions, 'FORUM_ID' => $forum_id) @@ -562,21 +552,18 @@ class auth_admin extends \phpbb\auth\auth // Build role dropdown options $current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0; - $s_role_options = ''; - @reset($roles); while (list($role_id, $role_row) = each($roles)) { $role_description = (!empty($user->lang[$role_row['role_description']])) ? $user->lang[$role_row['role_description']] : nl2br($role_row['role_description']); $role_name = (!empty($user->lang[$role_row['role_name']])) ? $user->lang[$role_row['role_name']] : $role_row['role_name']; - $title = ($role_description) ? ' title="' . $role_description . '"' : ''; - $s_role_options .= ''; - } - - if ($s_role_options) - { - $s_role_options = '' . $s_role_options; + $template->assign_block_vars('role_options', array( + 'ID' => $role_id, + 'ROLE_NAME' => $role_name, + 'TITLE' => $role_description, + 'SELECTED' => $role_id == $current_role_id, + )); } if (!$current_role_id && $mode != 'view') @@ -600,7 +587,6 @@ class auth_admin extends \phpbb\auth\auth $template->assign_block_vars($tpl_pmask . '.' . $tpl_fmask, array( 'NAME' => ($forum_id == 0) ? $forum_names_ary[0] : $forum_names_ary[$forum_id]['forum_name'], 'PADDING' => ($forum_id == 0) ? '' : $forum_names_ary[$forum_id]['padding'], - 'S_ROLE_OPTIONS' => $s_role_options, 'S_CUSTOM' => $s_custom_permissions, 'UG_ID' => $ug_id, 'FORUM_ID' => $forum_id) From faa5ab5899afc1023c7b42bd835e98c42d70eaa4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 29 May 2015 17:06:14 +0200 Subject: [PATCH 04/13] [ticket/6466] Improved code in tooltip.js PHPBB3-6466 --- phpBB/adm/style/tooltip.js | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/phpBB/adm/style/tooltip.js b/phpBB/adm/style/tooltip.js index 60222e51d5..feaa698c9a 100644 --- a/phpBB/adm/style/tooltip.js +++ b/phpBB/adm/style/tooltip.js @@ -12,7 +12,7 @@ phpBB Development Team: (function($) { // Avoid conflicts with other libraries -"use strict"; +'use strict'; var head_text, tooltip_mode, tooltips; tooltips = []; @@ -56,7 +56,10 @@ 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) { var $links, hold; @@ -76,7 +79,7 @@ function enable_tooltips_select(id, headline, sub_id) { if (id === null) { $links = $('.roles-options li'); } else { - $links = $('#' + id + ' .roles-options li'); + $links = $('.roles-options li', '#' + id); } $links.each(function () { @@ -95,7 +98,9 @@ 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) { var tooltip, text, desc, title; @@ -128,18 +133,22 @@ function prepare($element) { } /** -* Show tooltip + * Show tooltip + * + * @param {object} $element Element passed by .on() */ -function show_tooltip(e) { - var $this = $(e.target); +function show_tooltip($element) { + var $this = $($element.target); $('#_tooltip_container').append(tooltips[$this.attr('data-id')]); 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'); if (d.childNodes.length > 0) { d.removeChild(d.firstChild); @@ -167,13 +176,15 @@ 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; - e = e.parent(); - offset = e.offset(); + $element = $element.parent(); + offset = $element.offset(); if (tooltip_mode === 'link') { $('#_tooltip_container').css({ From 795776db4b09195e098d5c9dfd1b2fc8b4012be4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 29 May 2015 17:07:47 +0200 Subject: [PATCH 05/13] [ticket/6466] Removed link tooltip It wasn't being used anymore and didn't work anymore. PHPBB3-6466 --- phpBB/adm/style/tooltip.js | 61 ++++---------------------------------- 1 file changed, 5 insertions(+), 56 deletions(-) diff --git a/phpBB/adm/style/tooltip.js b/phpBB/adm/style/tooltip.js index feaa698c9a..5850fa43c2 100644 --- a/phpBB/adm/style/tooltip.js +++ b/phpBB/adm/style/tooltip.js @@ -14,47 +14,9 @@ phpBB Development Team: 'use strict'; -var head_text, tooltip_mode, tooltips; +var head_text, tooltips; tooltips = []; -/** -* 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'; - - 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'; -} - /** * Enable tooltip replacements for selects * @param {string} id ID tag of select @@ -93,8 +55,6 @@ function enable_tooltips_select(id, headline, sub_id) { prepare($this); } }); - - tooltip_mode = 'select'; } /** @@ -126,10 +86,6 @@ function prepare($element) { tooltips[$element.attr('data-id')] = tooltip; $element.on('mouseover', show_tooltip); $element.on('mouseout', hide_tooltip); - - if (tooltip_mode === 'link') { - $element.onmousemove = locate; - } } /** @@ -186,17 +142,10 @@ function locate($element) { $element = $element.parent(); offset = $element.offset(); - if (tooltip_mode === 'link') { - $('#_tooltip_container').css({ - top: offset.top + 20, - left: offset.left - 20 - }); - } else { - $('#_tooltip_container').css({ - top: offset.top + 30, - left: offset.left - 205 - }); - } + $('#_tooltip_container').css({ + top: offset.top + 30, + left: offset.left - 205 + }); } $(function() { From 75e1cbdc7728329f1c5d7375417e891c8d764fb5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 29 May 2015 17:08:17 +0200 Subject: [PATCH 06/13] [ticket/6466] Remove double semicolon PHPBB3-6466 --- phpBB/adm/style/tooltip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/adm/style/tooltip.js b/phpBB/adm/style/tooltip.js index 5850fa43c2..89736e40f7 100644 --- a/phpBB/adm/style/tooltip.js +++ b/phpBB/adm/style/tooltip.js @@ -65,7 +65,7 @@ function enable_tooltips_select(id, headline, sub_id) { function prepare($element) { var tooltip, text, desc, title; - text = $element.attr('data-title');; + text = $element.attr('data-title'); if (text === null || text.length === 0) { return; From abf0be4b4c7c646ad35e5943fda1f0bb4a5e2a84 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 29 May 2015 17:18:03 +0200 Subject: [PATCH 07/13] [ticket/6466] Get rid of useless variables and functions in tooltip.js PHPBB3-6466 --- phpBB/adm/style/admin.css | 1 + phpBB/adm/style/tooltip.js | 41 +++++++++++++------------------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/phpBB/adm/style/admin.css b/phpBB/adm/style/admin.css index 8ae39b7754..145bcfaec1 100644 --- a/phpBB/adm/style/admin.css +++ b/phpBB/adm/style/admin.css @@ -1858,6 +1858,7 @@ li.pagination ul { color: #000; text-align: center; border: 1px solid #AAA; + opacity: .95; } .tooltip span.top { diff --git a/phpBB/adm/style/tooltip.js b/phpBB/adm/style/tooltip.js index 89736e40f7..8e05cec30b 100644 --- a/phpBB/adm/style/tooltip.js +++ b/phpBB/adm/style/tooltip.js @@ -14,8 +14,7 @@ phpBB Development Team: 'use strict'; -var head_text, tooltips; -tooltips = []; +var tooltips = []; /** * Enable tooltip replacements for selects @@ -26,12 +25,6 @@ tooltips = []; function enable_tooltips_select(id, headline, sub_id) { var $links, hold; - head_text = headline; - - if (!document.getElementById || !document.getElementsByTagName) { - return; - } - hold = document.createElement('span'); hold.id = '_tooltip_container'; hold.setAttribute('id', '_tooltip_container'); @@ -49,10 +42,10 @@ function enable_tooltips_select(id, headline, sub_id) { if (sub_id) { if ($this.parent().attr('id').substr(0, sub_id.length) === sub_id) { - prepare($this); + prepare($this, headline); } } else { - prepare($this); + prepare($this, headline); } }); } @@ -61,8 +54,9 @@ function enable_tooltips_select(id, headline, sub_id) { * Prepare elements to replace * * @param {object} $element Element to prepare for tooltips + * @param {string} head_text Text heading to display */ -function prepare($element) { +function prepare($element, head_text) { var tooltip, text, desc, title; text = $element.attr('data-title'); @@ -71,17 +65,15 @@ function prepare($element) { return; } - 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); + tooltip = create_element('span', 'tooltip'); + tooltip.appendChild(title); + tooltip.appendChild(desc); tooltips[$element.attr('data-id')] = tooltip; $element.on('mouseover', show_tooltip); @@ -112,17 +104,12 @@ function hide_tooltip($element) { } /** -* Set opacity on tooltip element -*/ -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'; -} - -/** -* Create new element + * Create new element + * + * @param {string} tag HTML tag + * @param {string} c Element's class + * + * @return {object} Created element */ function create_element(tag, c) { var x = document.createElement(tag); From 120600e055c9220982ff4639f114d6bd60eaa41f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 29 May 2015 17:34:42 +0200 Subject: [PATCH 08/13] [ticket/6466] Rename functions and clean up code PHPBB3-6466 --- phpBB/adm/style/tooltip.js | 64 +++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/phpBB/adm/style/tooltip.js b/phpBB/adm/style/tooltip.js index 8e05cec30b..2798592c3d 100644 --- a/phpBB/adm/style/tooltip.js +++ b/phpBB/adm/style/tooltip.js @@ -22,7 +22,7 @@ var tooltips = []; * @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) { +phpbb.enableTooltipsSelect = function (id, headline, sub_id) { var $links, hold; hold = document.createElement('span'); @@ -42,13 +42,13 @@ function enable_tooltips_select(id, headline, sub_id) { if (sub_id) { if ($this.parent().attr('id').substr(0, sub_id.length) === sub_id) { - prepare($this, headline); + phpbb.prepareTooltips($this, headline); } } else { - prepare($this, headline); + phpbb.prepareTooltips($this, headline); } }); -} +}; /** * 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 {string} head_text Text heading to display */ -function prepare($element, head_text) { +phpbb.prepareTooltips = function ($element, head_text) { var tooltip, text, desc, title; text = $element.attr('data-title'); @@ -65,43 +65,43 @@ function prepare($element, head_text) { return; } - title = create_element('span', 'top'); + title = phpbb.createElement('span', 'top'); title.appendChild(document.createTextNode(head_text)); - desc = create_element('span', 'bottom'); + desc = phpbb.createElement('span', 'bottom'); desc.innerHTML = text; - tooltip = create_element('span', 'tooltip'); + tooltip = phpbb.createElement('span', 'tooltip'); tooltip.appendChild(title); tooltip.appendChild(desc); tooltips[$element.attr('data-id')] = tooltip; - $element.on('mouseover', show_tooltip); - $element.on('mouseout', hide_tooltip); -} + $element.on('mouseover', phpbb.showTooltip); + $element.on('mouseout', phpbb.hideTooltip); +}; /** * Show tooltip * * @param {object} $element Element passed by .on() */ -function show_tooltip($element) { +phpbb.showTooltip = function ($element) { var $this = $($element.target); $('#_tooltip_container').append(tooltips[$this.attr('data-id')]); - locate($this); -} + phpbb.positionTooltip($this); +}; /** * Hide tooltip * * @param {object} $element Element passed by .on() */ -function hide_tooltip($element) { +phpbb.hideTooltip = function () { var d = document.getElementById('_tooltip_container'); if (d.childNodes.length > 0) { d.removeChild(d.firstChild); } -} +}; /** * Create new element @@ -111,19 +111,19 @@ function hide_tooltip($element) { * * @return {object} Created element */ -function create_element(tag, c) { +phpbb.createElement = function (tag, c) { var x = document.createElement(tag); x.className = c; x.style.display = 'block'; return x; -} +}; /** * Correct positioning of tooltip container * * @param {object} $element Tooltip element that should be positioned */ -function locate($element) { +phpbb.positionTooltip = function ($element) { var offset; $element = $element.parent(); @@ -133,25 +133,22 @@ function locate($element) { top: offset.top + 30, left: offset.left - 205 }); -} +}; -$(function() { - var $options; - - // Enable tooltips - enable_tooltips_select('set-permissions', $('#set-permissions').attr('data-role-description'), 'role'); - - $options = $('.roles-options li'); +/** + * Prepare roles drop down select + */ +phpbb.prepareRolesDropdown = function () { + var $options = $('.roles-options li'); // Prepare highlighting of select options and settings update - $options.each(function () { + $options.each(function (element) { var $this = $(this); var $roles_options = $this.closest('.roles-options'); // Correctly show selected option if (typeof $this.attr('data-selected') !== 'undefined') { $this.closest('.roles-options').children('span').text($this.text()); - $('') } $this.on('mouseover', function (e) { @@ -173,6 +170,15 @@ $(function() { $('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 From c8bb0fd24179f9c2d639e53c896dd28f7d5562f8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 29 May 2015 17:35:53 +0200 Subject: [PATCH 09/13] [ticket/6466] Improve code in tooltip.js PHPBB3-6466 --- phpBB/adm/style/tooltip.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/phpBB/adm/style/tooltip.js b/phpBB/adm/style/tooltip.js index 2798592c3d..68750b8663 100644 --- a/phpBB/adm/style/tooltip.js +++ b/phpBB/adm/style/tooltip.js @@ -93,8 +93,6 @@ phpbb.showTooltip = function ($element) { /** * Hide tooltip - * - * @param {object} $element Element passed by .on() */ phpbb.hideTooltip = function () { var d = document.getElementById('_tooltip_container'); @@ -142,7 +140,7 @@ phpbb.prepareRolesDropdown = function () { var $options = $('.roles-options li'); // Prepare highlighting of select options and settings update - $options.each(function (element) { + $options.each(function () { var $this = $(this); var $roles_options = $this.closest('.roles-options'); From 0d5f074f54caeeffcc9deea840fb1dc59911a596 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 29 May 2015 17:39:03 +0200 Subject: [PATCH 10/13] [ticket/6466] Rename variables and remove unused ones PHPBB3-6466 --- phpBB/adm/style/tooltip.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/phpBB/adm/style/tooltip.js b/phpBB/adm/style/tooltip.js index 68750b8663..f78e1da81f 100644 --- a/phpBB/adm/style/tooltip.js +++ b/phpBB/adm/style/tooltip.js @@ -20,9 +20,9 @@ var tooltips = []; * 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) + * @param {string} subId Sub ID that should only be using tooltips (optional) */ -phpbb.enableTooltipsSelect = function (id, headline, sub_id) { +phpbb.enableTooltipsSelect = function (id, headline, subId) { var $links, hold; hold = document.createElement('span'); @@ -31,7 +31,7 @@ phpbb.enableTooltipsSelect = function (id, headline, sub_id) { hold.style.position = 'absolute'; $('body').append(hold); - if (id === null) { + if (!id) { $links = $('.roles-options li'); } else { $links = $('.roles-options li', '#' + id); @@ -40,8 +40,8 @@ phpbb.enableTooltipsSelect = function (id, headline, sub_id) { $links.each(function () { var $this = $(this); - if (sub_id) { - if ($this.parent().attr('id').substr(0, sub_id.length) === sub_id) { + if (subId) { + if ($this.parent().attr('id').substr(0, subId.length) === subId) { phpbb.prepareTooltips($this, headline); } } else { @@ -54,9 +54,9 @@ phpbb.enableTooltipsSelect = function (id, headline, sub_id) { * Prepare elements to replace * * @param {object} $element Element to prepare for tooltips - * @param {string} head_text Text heading to display + * @param {string} headText Text heading to display */ -phpbb.prepareTooltips = function ($element, head_text) { +phpbb.prepareTooltips = function ($element, headText) { var tooltip, text, desc, title; text = $element.attr('data-title'); @@ -66,7 +66,7 @@ phpbb.prepareTooltips = function ($element, head_text) { } title = phpbb.createElement('span', 'top'); - title.appendChild(document.createTextNode(head_text)); + title.appendChild(document.createTextNode(headText)); desc = phpbb.createElement('span', 'bottom'); desc.innerHTML = text; @@ -142,18 +142,18 @@ phpbb.prepareRolesDropdown = function () { // Prepare highlighting of select options and settings update $options.each(function () { var $this = $(this); - var $roles_options = $this.closest('.roles-options'); + var $rolesOptions = $this.closest('.roles-options'); // Correctly show selected option if (typeof $this.attr('data-selected') !== 'undefined') { $this.closest('.roles-options').children('span').text($this.text()); } - $this.on('mouseover', function (e) { + $this.on('mouseover', function () { var $this = $(this); $options.removeClass('roles-highlight'); $this.addClass('roles-highlight'); - }).on('click', function (e) { + }).on('click', function () { var $this = $(this); // Update settings @@ -161,8 +161,8 @@ phpbb.prepareRolesDropdown = function () { init_colours($this.attr('data-target-id').replace('advanced', '')); // Set selected setting - $roles_options.children('span').text($this.text()); - $roles_options.children('input[type=hidden]').val($this.attr('data-id')); + $rolesOptions.children('span').text($this.text()); + $rolesOptions.children('input[type=hidden]').val($this.attr('data-id')); // Trigger hiding of selection options $('body').trigger('click'); From 89cb8a3217edf0f374122e678e48e65a5c86c998 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 29 May 2015 18:06:30 +0200 Subject: [PATCH 11/13] [ticket/6466] Minor documentation changes PHPBB3-6466 --- phpBB/adm/style/tooltip.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/adm/style/tooltip.js b/phpBB/adm/style/tooltip.js index f78e1da81f..a52fa36853 100644 --- a/phpBB/adm/style/tooltip.js +++ b/phpBB/adm/style/tooltip.js @@ -20,7 +20,7 @@ var tooltips = []; * 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) + * @param {string} [subId] Sub ID that should only be using tooltips (optional) */ phpbb.enableTooltipsSelect = function (id, headline, subId) { var $links, hold; @@ -53,7 +53,7 @@ phpbb.enableTooltipsSelect = function (id, headline, subId) { /** * Prepare elements to replace * - * @param {object} $element Element to prepare for tooltips + * @param {jQuery} $element Element to prepare for tooltips * @param {string} headText Text heading to display */ phpbb.prepareTooltips = function ($element, headText) { @@ -119,7 +119,7 @@ phpbb.createElement = function (tag, c) { /** * Correct positioning of tooltip container * - * @param {object} $element Tooltip element that should be positioned + * @param {jQuery} $element Tooltip element that should be positioned */ phpbb.positionTooltip = function ($element) { var offset; From 2e46bef2ecc42a225e53d27c9b7614107b878186 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 30 May 2015 10:54:32 +0200 Subject: [PATCH 12/13] [ticket/6466] Remove createElement function from tooltip.js PHPBB3-6466 --- phpBB/adm/style/tooltip.js | 59 ++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/phpBB/adm/style/tooltip.js b/phpBB/adm/style/tooltip.js index a52fa36853..641d82c80a 100644 --- a/phpBB/adm/style/tooltip.js +++ b/phpBB/adm/style/tooltip.js @@ -25,10 +25,13 @@ var tooltips = []; 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 = $('', { + id: '_tooltip_container', + css: { + position: 'absolute' + } + }); + $('body').append(hold); if (!id) { @@ -57,7 +60,7 @@ phpbb.enableTooltipsSelect = function (id, headline, subId) { * @param {string} headText Text heading to display */ phpbb.prepareTooltips = function ($element, headText) { - var tooltip, text, desc, title; + var $tooltip, text, $desc, $title; text = $element.attr('data-title'); @@ -65,17 +68,32 @@ phpbb.prepareTooltips = function ($element, headText) { return; } - title = phpbb.createElement('span', 'top'); - title.appendChild(document.createTextNode(headText)); + $title = $('', { + class: 'top', + css: { + display: 'block' + } + }) + .append(document.createTextNode(headText)); - desc = phpbb.createElement('span', 'bottom'); - desc.innerHTML = text; + $desc = $('', { + class: 'bottom', + html: text, + css: { + display: 'block' + } + }); - tooltip = phpbb.createElement('span', 'tooltip'); - tooltip.appendChild(title); - tooltip.appendChild(desc); + $tooltip = $('', { + class: 'tooltip', + css: { + display: 'block' + } + }) + .append($title) + .append($desc); - tooltips[$element.attr('data-id')] = tooltip; + tooltips[$element.attr('data-id')] = $tooltip; $element.on('mouseover', phpbb.showTooltip); $element.on('mouseout', phpbb.hideTooltip); }; @@ -101,21 +119,6 @@ phpbb.hideTooltip = function () { } }; -/** - * Create new element - * - * @param {string} tag HTML tag - * @param {string} c Element's class - * - * @return {object} Created element -*/ -phpbb.createElement = function (tag, c) { - var x = document.createElement(tag); - x.className = c; - x.style.display = 'block'; - return x; -}; - /** * Correct positioning of tooltip container * From 44b8dafb233cb07403a303b9c3a5eb72539365d2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 30 May 2015 11:20:04 +0200 Subject: [PATCH 13/13] [ticket/6466] Support form reset and do not loose role upon resubmit PHPBB3-6466 --- phpBB/adm/style/permission_mask.html | 2 +- phpBB/adm/style/tooltip.js | 28 ++++++++++++++++++++++++---- phpBB/includes/acp/auth.php | 6 ++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/phpBB/adm/style/permission_mask.html b/phpBB/adm/style/permission_mask.html index 91894ebc77..347da3181e 100644 --- a/phpBB/adm/style/permission_mask.html +++ b/phpBB/adm/style/permission_mask.html @@ -50,7 +50,7 @@ {% endfor %} - + {% else %} diff --git a/phpBB/adm/style/tooltip.js b/phpBB/adm/style/tooltip.js index 641d82c80a..68964034f0 100644 --- a/phpBB/adm/style/tooltip.js +++ b/phpBB/adm/style/tooltip.js @@ -141,15 +141,20 @@ phpbb.positionTooltip = function ($element) { */ 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); - var $rolesOptions = $this.closest('.roles-options'); // Correctly show selected option if (typeof $this.attr('data-selected') !== 'undefined') { - $this.closest('.roles-options').children('span').text($this.text()); + $rolesOptions.closest('.roles-options') + .children('span') + .text($this.text()) + .attr('data-default', $this.text()) + .attr('data-default-val', $this.attr('data-id')); } $this.on('mouseover', function () { @@ -164,13 +169,28 @@ phpbb.prepareRolesDropdown = function () { 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')); + $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()); + } + + // 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')); + }); + }; // Run onload functions for RolesDropdown and tooltips diff --git a/phpBB/includes/acp/auth.php b/phpBB/includes/acp/auth.php index efb92685f6..b13b1ee040 100644 --- a/phpBB/includes/acp/auth.php +++ b/phpBB/includes/acp/auth.php @@ -470,6 +470,9 @@ class auth_admin extends \phpbb\auth\auth // Build role dropdown options $current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0; + // Output current role id to template + $template->assign_var('S_ROLE_ID', $current_role_id); + @reset($roles); while (list($role_id, $role_row) = each($roles)) { @@ -552,6 +555,9 @@ class auth_admin extends \phpbb\auth\auth // Build role dropdown options $current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0; + // Output current role id to template + $template->assign_var('S_ROLE_ID', $current_role_id); + @reset($roles); while (list($role_id, $role_row) = each($roles)) {