mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/12982] Refactoring: Cleaned up forum_fn.js
PHPBB3-12982
This commit is contained in:
parent
9578fdf7d7
commit
9e3db526d5
1 changed files with 220 additions and 235 deletions
|
@ -1,3 +1,5 @@
|
|||
/* global phpbb */
|
||||
|
||||
/**
|
||||
* phpBB3 forum functions
|
||||
*/
|
||||
|
@ -6,6 +8,8 @@
|
|||
* Find a member
|
||||
*/
|
||||
function find_username(url) {
|
||||
'use strict';
|
||||
|
||||
popup(url, 760, 570, '_usersearch');
|
||||
return false;
|
||||
}
|
||||
|
@ -14,6 +18,8 @@ function find_username(url) {
|
|||
* Window popup
|
||||
*/
|
||||
function popup(url, width, height, name) {
|
||||
'use strict';
|
||||
|
||||
if (!name) {
|
||||
name = '_popup';
|
||||
}
|
||||
|
@ -26,17 +32,18 @@ function popup(url, width, height, name) {
|
|||
* Jump to page
|
||||
*/
|
||||
function pageJump(item) {
|
||||
'use strict';
|
||||
|
||||
var page = item.val(),
|
||||
per_page = item.attr('data-per-page'),
|
||||
base_url = item.attr('data-base-url'),
|
||||
start_name = item.attr('data-start-name');
|
||||
perPage = item.attr('data-per-page'),
|
||||
baseUrl = item.attr('data-base-url'),
|
||||
startName = item.attr('data-start-name');
|
||||
|
||||
if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0) {
|
||||
if (base_url.indexOf('?') === -1) {
|
||||
document.location.href = base_url + '?' + start_name + '=' + ((page - 1) * per_page);
|
||||
if (baseUrl.indexOf('?') === -1) {
|
||||
document.location.href = baseUrl + '?' + startName + '=' + ((page - 1) * perPage);
|
||||
} else {
|
||||
document.location.href = base_url.replace(/&/g, '&') + '&' + start_name + '=' + ((page - 1) * per_page);
|
||||
document.location.href = baseUrl.replace(/&/g, '&') + '&' + startName + '=' + ((page - 1) * perPage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,9 +53,11 @@ function pageJump(item) {
|
|||
* id = ID of parent container, name = name prefix, state = state [true/false]
|
||||
*/
|
||||
function marklist(id, name, state) {
|
||||
'use strict';
|
||||
|
||||
jQuery('#' + id + ' input[type=checkbox][name]').each(function() {
|
||||
var $this = jQuery(this);
|
||||
if ($this.attr('name').substr(0, name.length) == name) {
|
||||
if ($this.attr('name').substr(0, name.length) === name) {
|
||||
$this.prop('checked', state);
|
||||
}
|
||||
});
|
||||
|
@ -59,6 +68,8 @@ function marklist(id, name, state) {
|
|||
* e = element
|
||||
*/
|
||||
function viewableArea(e, itself) {
|
||||
'use strict';
|
||||
|
||||
if (!e) {
|
||||
return;
|
||||
}
|
||||
|
@ -86,18 +97,20 @@ function viewableArea(e, itself) {
|
|||
/**
|
||||
* Alternate display of subPanels
|
||||
*/
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('.sub-panels').each(function() {
|
||||
jQuery(function($) {
|
||||
'use strict';
|
||||
|
||||
var panels = [],
|
||||
childNodes = jQuery('a[data-subpanel]', this).each(function() {
|
||||
panels.push(this.getAttribute('data-subpanel'));
|
||||
$('.sub-panels').each(function() {
|
||||
|
||||
var $childNodes = $('a[data-subpanel]', this),
|
||||
panels = $childNodes.map(function () {
|
||||
return this.getAttribute('data-subpanel');
|
||||
}),
|
||||
show_panel = this.getAttribute('data-show-panel');
|
||||
showPanel = this.getAttribute('data-show-panel');
|
||||
|
||||
if (panels.length) {
|
||||
activateSubPanel(show_panel, panels);
|
||||
childNodes.click(function () {
|
||||
activateSubPanel(showPanel, panels);
|
||||
$childNodes.click(function () {
|
||||
activateSubPanel(this.getAttribute('data-subpanel'), panels);
|
||||
return false;
|
||||
});
|
||||
|
@ -109,60 +122,30 @@ jQuery(document).ready(function() {
|
|||
* Activate specific subPanel
|
||||
*/
|
||||
function activateSubPanel(p, panels) {
|
||||
var i;
|
||||
'use strict';
|
||||
|
||||
var i, showPanel;
|
||||
|
||||
if (typeof(p) === 'string') {
|
||||
show_panel = p;
|
||||
showPanel = p;
|
||||
}
|
||||
$('input[name="show_panel"]').val(show_panel);
|
||||
$('input[name="show_panel"]').val(showPanel);
|
||||
|
||||
if (typeof(panels) === 'undefined') {
|
||||
panels = [];
|
||||
jQuery('.sub-panels a[data-subpanel]').each(function() {
|
||||
panels.push(this.getAttribute('data-subpanel'));
|
||||
if (typeof panels === 'undefined') {
|
||||
panels = jQuery('.sub-panels a[data-subpanel]').map(function() {
|
||||
return this.getAttribute('data-subpanel');
|
||||
});
|
||||
}
|
||||
|
||||
for (i = 0; i < panels.length; i++) {
|
||||
jQuery('#' + panels[i]).css('display', panels[i] === show_panel ? 'block' : 'none');
|
||||
jQuery('#' + panels[i] + '-tab').toggleClass('activetab', panels[i] === show_panel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call print preview
|
||||
*/
|
||||
function printPage() {
|
||||
if (is_ie) {
|
||||
printPreview();
|
||||
} else {
|
||||
window.print();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show/hide groups of blocks
|
||||
* c = CSS style name
|
||||
* e = checkbox element
|
||||
* t = toggle dispay state (used to show 'grip-show' image in the profile block when hiding the profiles)
|
||||
*/
|
||||
function displayBlocks(c, e, t) {
|
||||
var s = (e.checked === true) ? 1 : -1;
|
||||
|
||||
if (t) {
|
||||
s *= -1;
|
||||
}
|
||||
|
||||
var divs = document.getElementsByTagName("DIV");
|
||||
|
||||
for (var d = 0; d < divs.length; d++) {
|
||||
if (divs[d].className.indexOf(c) === 0) {
|
||||
divs[d].style.display = (s === 1) ? 'none' : 'block';
|
||||
}
|
||||
jQuery('#' + panels[i]).css('display', panels[i] === showPanel ? 'block' : 'none');
|
||||
jQuery('#' + panels[i] + '-tab').toggleClass('activetab', panels[i] === showPanel);
|
||||
}
|
||||
}
|
||||
|
||||
function selectCode(a) {
|
||||
'use strict';
|
||||
|
||||
// Get ID of code block
|
||||
var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
|
||||
var s, r;
|
||||
|
@ -209,6 +192,8 @@ function selectCode(a) {
|
|||
* from the displayed rectangle area
|
||||
*/
|
||||
function play_qt_file(obj) {
|
||||
'use strict';
|
||||
|
||||
var rectangle = obj.GetRectangle();
|
||||
var width, height;
|
||||
|
||||
|
@ -233,30 +218,32 @@ function play_qt_file(obj) {
|
|||
obj.Play();
|
||||
}
|
||||
|
||||
var in_autocomplete = false;
|
||||
var last_key_entered = '';
|
||||
var inAutocomplete = false;
|
||||
var lastKeyEntered = '';
|
||||
|
||||
/**
|
||||
* Check event key
|
||||
*/
|
||||
function phpbb_check_key(event) {
|
||||
function phpbbCheckKey(event) {
|
||||
'use strict';
|
||||
|
||||
// Keycode is array down or up?
|
||||
if (event.keyCode && (event.keyCode === 40 || event.keyCode === 38)) {
|
||||
in_autocomplete = true;
|
||||
inAutocomplete = true;
|
||||
}
|
||||
|
||||
// Make sure we are not within an "autocompletion" field
|
||||
if (in_autocomplete) {
|
||||
if (inAutocomplete) {
|
||||
// If return pressed and key changed we reset the autocompletion
|
||||
if (!last_key_entered || last_key_entered === event.which) {
|
||||
in_autocompletion = false;
|
||||
if (!lastKeyEntered || lastKeyEntered === event.which) {
|
||||
inAutocomplete = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Keycode is not return, then return. ;)
|
||||
if (event.which !== 13) {
|
||||
last_key_entered = event.which;
|
||||
lastKeyEntered = event.which;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -266,28 +253,28 @@ function phpbb_check_key(event) {
|
|||
/**
|
||||
* Apply onkeypress event for forcing default submit button on ENTER key press
|
||||
*/
|
||||
function apply_onkeypress_event() {
|
||||
jQuery('form input[type=text], form input[type=password]').on('keypress', function (e) {
|
||||
var default_button = jQuery(this).parents('form').find('input[type=submit].default-submit-action');
|
||||
jQuery(function($) {
|
||||
'use strict';
|
||||
|
||||
if (!default_button || default_button.length <= 0) {
|
||||
$('form input[type=text], form input[type=password]').on('keypress', function (e) {
|
||||
var defaultButton = $(this).parents('form').find('input[type=submit].default-submit-action');
|
||||
|
||||
if (!defaultButton || defaultButton.length <= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (phpbb_check_key(e)) {
|
||||
if (phpbbCheckKey(e)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {
|
||||
default_button.click();
|
||||
defaultButton.click();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
jQuery(document).ready(apply_onkeypress_event);
|
||||
});
|
||||
|
||||
/**
|
||||
* Functions for user search popup
|
||||
|
@ -300,7 +287,7 @@ function insert_user(formId, value)
|
|||
item = opener.document.forms[formName][fieldName];
|
||||
|
||||
if (item.value.length && item.type == 'textarea') {
|
||||
value = item.value + "\n" + value;
|
||||
value = item.value + '\n' + value;
|
||||
}
|
||||
|
||||
item.value = value;
|
||||
|
@ -331,50 +318,49 @@ function insert_marked_users(formId, users)
|
|||
|
||||
function insert_single_user(formId, user)
|
||||
{
|
||||
insert_user(formId, user);
|
||||
insertUser(formId, user);
|
||||
self.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse document block
|
||||
*/
|
||||
function parse_document(container)
|
||||
{
|
||||
function parseDocument($container) {
|
||||
'use strict';
|
||||
|
||||
var test = document.createElement('div'),
|
||||
oldBrowser = (typeof test.style.borderRadius == 'undefined');
|
||||
|
||||
delete test;
|
||||
|
||||
/**
|
||||
* Reset avatar dimensions when changing URL or EMAIL
|
||||
*/
|
||||
container.find('input[data-reset-on-edit]').bind('keyup', function() {
|
||||
$container.find('input[data-reset-on-edit]').on('keyup', function() {
|
||||
$(this.getAttribute('data-reset-on-edit')).val('');
|
||||
});
|
||||
|
||||
/**
|
||||
* Pagination
|
||||
*/
|
||||
container.find('.pagination .page-jump-form :button').click(function() {
|
||||
$input = $(this).siblings('input.inputbox');
|
||||
$container.find('.pagination .page-jump-form :button').click(function() {
|
||||
var $input = $(this).siblings('input.inputbox');
|
||||
pageJump($input);
|
||||
});
|
||||
|
||||
container.find('.pagination .page-jump-form input.inputbox').on('keypress', function(event) {
|
||||
if (event.which == 13 || event.keyCode == 13) {
|
||||
$container.find('.pagination .page-jump-form input.inputbox').on('keypress', function(event) {
|
||||
if (event.which === 13 || event.keyCode === 13) {
|
||||
event.preventDefault();
|
||||
pageJump($(this));
|
||||
}
|
||||
});
|
||||
|
||||
container.find('.pagination .dropdown-trigger').click(function() {
|
||||
$dropdown_container = $(this).parent();
|
||||
$container.find('.pagination .dropdown-trigger').click(function() {
|
||||
var $dropdownContainer = $(this).parent();
|
||||
// Wait a little bit to make sure the dropdown has activated
|
||||
setTimeout(function() {
|
||||
if ($dropdown_container.hasClass('dropdown-visible')) {
|
||||
$dropdown_container.find('input.inputbox').focus();
|
||||
if ($dropdownContainer.hasClass('dropdown-visible')) {
|
||||
$dropdownContainer.find('input.inputbox').focus();
|
||||
}
|
||||
},100);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -382,27 +368,29 @@ function parse_document(container)
|
|||
*/
|
||||
if (oldBrowser) {
|
||||
// Fix .linklist.bulletin lists
|
||||
container.find('ul.linklist.bulletin > li:first-child, ul.linklist.bulletin > li.rightside:last-child').addClass('no-bulletin');
|
||||
$container.find('ul.linklist.bulletin > li:first-child, ul.linklist.bulletin > li.rightside:last-child').addClass('no-bulletin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize navigation block to keep all links on same line
|
||||
*/
|
||||
container.find('.navlinks').each(function() {
|
||||
$container.find('.navlinks').each(function() {
|
||||
var $this = $(this),
|
||||
left = $this.children().not('.rightside'),
|
||||
right = $this.children('.rightside');
|
||||
$left = $this.children().not('.rightside'),
|
||||
$right = $this.children('.rightside');
|
||||
|
||||
if (left.length !== 1 || !right.length) return;
|
||||
if ($left.length !== 1 || !$right.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
function resize() {
|
||||
var width = 0,
|
||||
diff = left.outerWidth(true) - left.width();
|
||||
diff = $left.outerWidth(true) - $left.width();
|
||||
|
||||
right.each(function() {
|
||||
$right.each(function() {
|
||||
width += $(this).outerWidth(true);
|
||||
});
|
||||
left.css('max-width', Math.floor($this.width() - width - diff) + 'px');
|
||||
$left.css('max-width', Math.floor($this.width() - width - diff) + 'px');
|
||||
}
|
||||
|
||||
resize();
|
||||
|
@ -412,11 +400,11 @@ function parse_document(container)
|
|||
/**
|
||||
* Makes breadcrumbs responsive
|
||||
*/
|
||||
container.find('.breadcrumbs:not([data-skip-responsive])').each(function() {
|
||||
$container.find('.breadcrumbs:not([data-skip-responsive])').each(function() {
|
||||
var $this = $(this),
|
||||
$body = $('body'),
|
||||
links = $this.find('.crumb'),
|
||||
length = links.length,
|
||||
$links = $this.find('.crumb'),
|
||||
length = $links.length,
|
||||
classes = ['wrapped-max', 'wrapped-wide', 'wrapped-medium', 'wrapped-small', 'wrapped-tiny'],
|
||||
classesLength = classes.length,
|
||||
maxHeight = 0,
|
||||
|
@ -429,14 +417,13 @@ function parse_document(container)
|
|||
$link.attr('title', $link.text());
|
||||
});
|
||||
|
||||
// Funciton that checks breadcrumbs
|
||||
// Function that checks breadcrumbs
|
||||
function check() {
|
||||
var height = $this.height(),
|
||||
width = $body.width(),
|
||||
link, i, j;
|
||||
width = $body.width();
|
||||
|
||||
maxHeight = parseInt($this.css('line-height')) | 0;
|
||||
links.each(function() {
|
||||
maxHeight = parseInt($this.css('line-height'));
|
||||
$links.each(function() {
|
||||
if ($(this).height() > 0) {
|
||||
maxHeight = Math.max(maxHeight, $(this).outerHeight(true));
|
||||
}
|
||||
|
@ -444,7 +431,6 @@ function parse_document(container)
|
|||
|
||||
if (height <= maxHeight) {
|
||||
if (!wrapped || lastWidth === false || lastWidth >= width) {
|
||||
lastWidth = width;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -452,7 +438,6 @@ function parse_document(container)
|
|||
|
||||
if (wrapped) {
|
||||
$this.removeClass('wrapped').find('.crumb.wrapped').removeClass('wrapped ' + classes.join(' '));
|
||||
wrapped = false;
|
||||
if ($this.height() <= maxHeight) {
|
||||
return;
|
||||
}
|
||||
|
@ -464,9 +449,9 @@ function parse_document(container)
|
|||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < classesLength; i ++) {
|
||||
for (j = length - 1; j >= 0; j --) {
|
||||
links.eq(j).addClass('wrapped ' + classes[i]);
|
||||
for (var i = 0; i < classesLength; i ++) {
|
||||
for (var j = length - 1; j >= 0; j --) {
|
||||
$links.eq(j).addClass('wrapped ' + classes[i]);
|
||||
if ($this.height() <= maxHeight) {
|
||||
return;
|
||||
}
|
||||
|
@ -482,32 +467,29 @@ function parse_document(container)
|
|||
/**
|
||||
* Responsive link lists
|
||||
*/
|
||||
container.find('.linklist:not(.navlinks, [data-skip-responsive]), .postbody .post-buttons:not([data-skip-responsive])').each(function() {
|
||||
$container.find('.linklist:not(.navlinks, [data-skip-responsive]), .postbody .post-buttons:not([data-skip-responsive])').each(function() {
|
||||
var $this = $(this),
|
||||
$body = $('body'),
|
||||
filterSkip = '.breadcrumbs, [data-skip-responsive]',
|
||||
filterLast = '.edit-icon, .quote-icon, [data-last-responsive]',
|
||||
persist = $this.attr('id') == 'nav-main',
|
||||
allLinks = $this.children(),
|
||||
links = allLinks.not(filterSkip),
|
||||
$allLinks = $this.children(),
|
||||
$links = $allLinks.not(filterSkip),
|
||||
html = '<li class="responsive-menu" style="display:none;"><a href="javascript:void(0);" class="responsive-menu-link"> </a><div class="dropdown" style="display:none;"><div class="pointer"><div class="pointer-inner" /></div><ul class="dropdown-contents" /></div></li>',
|
||||
filterLastList = links.filter(filterLast),
|
||||
$filterLastList = $links.filter(filterLast),
|
||||
slack = 1; // Vertical slack space (in pixels). Determines how sensitive the script is in determining whether a line-break has occured.
|
||||
|
||||
if (!persist) {
|
||||
if (links.is('.rightside'))
|
||||
{
|
||||
links.filter('.rightside:first').before(html);
|
||||
if ($links.is('.rightside')) {
|
||||
$links.filter('.rightside:first').before(html);
|
||||
$this.children('.responsive-menu').addClass('rightside');
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$this.append(html);
|
||||
}
|
||||
}
|
||||
|
||||
var item = $this.children('.responsive-menu'),
|
||||
menu = item.find('.dropdown-contents'),
|
||||
var $item = $this.children('.responsive-menu'),
|
||||
$menu = $item.find('.dropdown-contents'),
|
||||
lastWidth = false,
|
||||
compact = false,
|
||||
responsive = false,
|
||||
|
@ -521,29 +503,31 @@ function parse_document(container)
|
|||
|
||||
// Unhide the quick-links menu if it has content
|
||||
if (persist) {
|
||||
item.addClass('hidden');
|
||||
if (menu.find('li:not(.separator, .clone)').length || (responsive && menu.find('li.clone').length)) {
|
||||
item.removeClass('hidden');
|
||||
$item.addClass('hidden');
|
||||
if ($menu.find('li:not(.separator, .clone)').length || (responsive && $menu.find('li.clone').length)) {
|
||||
$item.removeClass('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// Reset responsive and compact layout
|
||||
if (responsive) {
|
||||
responsive = false;
|
||||
$this.removeClass('responsive');
|
||||
links.css('display', '');
|
||||
if (!persist) item.css('display', 'none');
|
||||
$links.css('display', '');
|
||||
if (!persist) {
|
||||
$item.css('display', 'none');
|
||||
}
|
||||
}
|
||||
|
||||
if (compact) {
|
||||
compact = false;
|
||||
$this.removeClass('compact');
|
||||
}
|
||||
|
||||
// Find tallest element
|
||||
var maxHeight = 0;
|
||||
allLinks.each(function() {
|
||||
if (!$(this).height()) return;
|
||||
$allLinks.each(function() {
|
||||
if (!$(this).height()) {
|
||||
return;
|
||||
}
|
||||
maxHeight = Math.max(maxHeight, $(this).outerHeight(true));
|
||||
});
|
||||
|
||||
|
@ -557,12 +541,13 @@ function parse_document(container)
|
|||
}
|
||||
|
||||
// Enable compact layout, find tallest element, compare to height of whole block
|
||||
compact = true;
|
||||
$this.addClass('compact');
|
||||
|
||||
var compactMaxHeight = 0;
|
||||
allLinks.each(function() {
|
||||
if (!$(this).height()) return;
|
||||
$allLinks.each(function() {
|
||||
if (!$(this).height()) {
|
||||
return;
|
||||
}
|
||||
compactMaxHeight = Math.max(compactMaxHeight, $(this).outerHeight(true));
|
||||
});
|
||||
|
||||
|
@ -571,51 +556,51 @@ function parse_document(container)
|
|||
}
|
||||
|
||||
// Compact layout did not resize block enough, switch to responsive layout
|
||||
compact = false;
|
||||
$this.removeClass('compact');
|
||||
responsive = true;
|
||||
|
||||
if (!copied) {
|
||||
var clone = links.clone(true);
|
||||
var clone = $links.clone(true);
|
||||
clone.filter('.rightside').each(function() {
|
||||
if (persist) $(this).addClass('clone');
|
||||
menu.prepend(this);
|
||||
if (persist) {
|
||||
$(this).addClass('clone');
|
||||
}
|
||||
$menu.prepend(this);
|
||||
});
|
||||
|
||||
if (persist) {
|
||||
menu.prepend(clone.not('.rightside').addClass('clone'));
|
||||
$menu.prepend(clone.not('.rightside').addClass('clone'));
|
||||
} else {
|
||||
menu.prepend(clone.not('.rightside'));
|
||||
$menu.prepend(clone.not('.rightside'));
|
||||
}
|
||||
|
||||
menu.find('li.leftside, li.rightside').removeClass('leftside rightside');
|
||||
menu.find('.inputbox').parents('li:first').css('white-space', 'normal');
|
||||
$menu.find('li.leftside, li.rightside').removeClass('leftside rightside');
|
||||
$menu.find('.inputbox').parents('li:first').css('white-space', 'normal');
|
||||
|
||||
if ($this.hasClass('post-buttons')) {
|
||||
$('.button', menu).removeClass('button icon-button');
|
||||
$('.responsive-menu-link', item).addClass('button icon-button').prepend('<span></span>');
|
||||
$('.button', $menu).removeClass('button icon-button');
|
||||
$('.responsive-menu-link', $item).addClass('button icon-button').prepend('<span></span>');
|
||||
}
|
||||
copied = true;
|
||||
}
|
||||
else {
|
||||
menu.children().css('display', '');
|
||||
} else {
|
||||
$menu.children().css('display', '');
|
||||
}
|
||||
|
||||
item.css('display', '');
|
||||
$item.css('display', '');
|
||||
$this.addClass('responsive');
|
||||
|
||||
// Try to not hide filtered items
|
||||
if (filterLastList.length) {
|
||||
links.not(filterLast).css('display', 'none');
|
||||
if ($filterLastList.length) {
|
||||
$links.not(filterLast).css('display', 'none');
|
||||
|
||||
maxHeight = 0;
|
||||
filterLastList.each(function() {
|
||||
$filterLastList.each(function() {
|
||||
if (!$(this).height()) return;
|
||||
maxHeight = Math.max(maxHeight, $(this).outerHeight(true));
|
||||
});
|
||||
|
||||
if ($this.height() <= (maxHeight + slack)) {
|
||||
menu.children().filter(filterLast).css('display', 'none');
|
||||
$menu.children().filter(filterLast).css('display', 'none');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -624,10 +609,12 @@ function parse_document(container)
|
|||
compact = true;
|
||||
$this.addClass('compact');
|
||||
|
||||
links.css('display', 'none');
|
||||
$links.css('display', 'none');
|
||||
}
|
||||
|
||||
if (!persist) phpbb.registerDropdown(item.find('a.responsive-menu-link'), item.find('.dropdown'));
|
||||
if (!persist) {
|
||||
phpbb.registerDropdown($item.find('a.responsive-menu-link'), $item.find('.dropdown'));
|
||||
}
|
||||
|
||||
check();
|
||||
$(window).resize(check);
|
||||
|
@ -643,7 +630,7 @@ function parse_document(container)
|
|||
/**
|
||||
* Adjust topiclist lists with check boxes
|
||||
*/
|
||||
container.find('ul.topiclist dd.mark').siblings('dt').children('.list-inner').addClass('with-mark');
|
||||
$container.find('ul.topiclist dd.mark').siblings('dt').children('.list-inner').addClass('with-mark');
|
||||
|
||||
/**
|
||||
* Appends contents of all extra columns to first column in
|
||||
|
@ -652,31 +639,30 @@ function parse_document(container)
|
|||
* To add that functionality to .topiclist list simply add
|
||||
* responsive-show-all to list of classes
|
||||
*/
|
||||
container.find('.topiclist.responsive-show-all > li > dl').each(function() {
|
||||
$container.find('.topiclist.responsive-show-all > li > dl').each(function() {
|
||||
var $this = $(this),
|
||||
block = $this.find('dt .responsive-show:last-child'),
|
||||
$block = $this.find('dt .responsive-show:last-child'),
|
||||
first = true;
|
||||
|
||||
// Create block that is visible only on mobile devices
|
||||
if (!block.length) {
|
||||
if (!$block.length) {
|
||||
$this.find('dt > .list-inner').append('<div class="responsive-show" style="display:none;" />');
|
||||
block = $this.find('dt .responsive-show:last-child');
|
||||
}
|
||||
else {
|
||||
first = ($.trim(block.text()).length == 0);
|
||||
$block = $this.find('dt .responsive-show:last-child');
|
||||
} else {
|
||||
first = ($.trim($block.text()).length === 0);
|
||||
}
|
||||
|
||||
// Copy contents of each column
|
||||
$this.find('dd').not('.mark').each(function() {
|
||||
var column = $(this),
|
||||
children = column.children(),
|
||||
$children = column.children(),
|
||||
html = column.html();
|
||||
|
||||
if (children.length == 1 && children.text() == column.text()) {
|
||||
html = children.html();
|
||||
if ($children.length == 1 && $children.text() == column.text()) {
|
||||
html = $children.html();
|
||||
}
|
||||
|
||||
block.append((first ? '' : '<br />') + html);
|
||||
$block.append((first ? '' : '<br />') + html);
|
||||
|
||||
first = false;
|
||||
});
|
||||
|
@ -689,15 +675,15 @@ function parse_document(container)
|
|||
* To add that functionality to .topiclist list simply add
|
||||
* responsive-show-columns to list of classes
|
||||
*/
|
||||
container.find('.topiclist.responsive-show-columns').each(function() {
|
||||
var list = $(this),
|
||||
$container.find('.topiclist.responsive-show-columns').each(function() {
|
||||
var $list = $(this),
|
||||
headers = [],
|
||||
headersLength = 0;
|
||||
|
||||
// Find all headers, get contents
|
||||
list.prev('.topiclist').find('li.header dd').not('.mark').each(function() {
|
||||
$list.prev('.topiclist').find('li.header dd').not('.mark').each(function() {
|
||||
headers.push($(this).text());
|
||||
headersLength ++;
|
||||
headersLength++;
|
||||
});
|
||||
|
||||
if (!headersLength) {
|
||||
|
@ -705,18 +691,18 @@ function parse_document(container)
|
|||
}
|
||||
|
||||
// Parse each row
|
||||
list.find('dl').each(function() {
|
||||
$list.find('dl').each(function() {
|
||||
var $this = $(this),
|
||||
block = $this.find('dt .responsive-show:last-child'),
|
||||
$block = $this.find('dt .responsive-show:last-child'),
|
||||
first = true;
|
||||
|
||||
// Create block that is visible only on mobile devices
|
||||
if (!block.length) {
|
||||
if (!$block.length) {
|
||||
$this.find('dt > .list-inner').append('<div class="responsive-show" style="display:none;" />');
|
||||
block = $this.find('dt .responsive-show:last-child');
|
||||
$block = $this.find('dt .responsive-show:last-child');
|
||||
}
|
||||
else {
|
||||
first = ($.trim(block.text()).length == 0);
|
||||
first = ($.trim($block.text()).length === 0);
|
||||
}
|
||||
|
||||
// Copy contents of each column
|
||||
|
@ -734,7 +720,7 @@ function parse_document(container)
|
|||
html = headers[i] + ': <strong>' + html + '</strong>';
|
||||
}
|
||||
|
||||
block.append((first ? '' : '<br />') + html);
|
||||
$block.append((first ? '' : '<br />') + html);
|
||||
|
||||
first = false;
|
||||
});
|
||||
|
@ -744,16 +730,15 @@ function parse_document(container)
|
|||
/**
|
||||
* Responsive tables
|
||||
*/
|
||||
container.find('table.table1').not('.not-responsive').each(function() {
|
||||
$container.find('table.table1').not('.not-responsive').each(function() {
|
||||
var $this = $(this),
|
||||
th = $this.find('thead > tr > th'),
|
||||
columns = th.length,
|
||||
$th = $this.find('thead > tr > th'),
|
||||
headers = [],
|
||||
totalHeaders = 0,
|
||||
i, headersLength;
|
||||
|
||||
// Find each header
|
||||
th.each(function(column) {
|
||||
$th.each(function(column) {
|
||||
var cell = $(this),
|
||||
colspan = parseInt(cell.attr('colspan')),
|
||||
dfn = cell.attr('data-dfn'),
|
||||
|
@ -761,10 +746,10 @@ function parse_document(container)
|
|||
|
||||
colspan = isNaN(colspan) || colspan < 1 ? 1 : colspan;
|
||||
|
||||
for (i=0; i<colspan; i++) {
|
||||
for (i = 0; i < colspan; i++) {
|
||||
headers.push(text);
|
||||
}
|
||||
totalHeaders ++;
|
||||
totalHeaders++;
|
||||
|
||||
if (dfn && !column) {
|
||||
$this.addClass('show-header');
|
||||
|
@ -802,8 +787,7 @@ function parse_document(container)
|
|||
|
||||
if ((text.length && text !== '-') || cell.children().length) {
|
||||
cell.prepend('<dfn style="display: none;">' + headers[column] + '</dfn>');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cell.addClass('empty');
|
||||
}
|
||||
|
||||
|
@ -816,10 +800,9 @@ function parse_document(container)
|
|||
/**
|
||||
* Hide empty responsive tables
|
||||
*/
|
||||
container.find('table.responsive > tbody').not('.responsive-skip-empty').each(function() {
|
||||
var items = $(this).children('tr');
|
||||
if (items.length == 0)
|
||||
{
|
||||
$container.find('table.responsive > tbody').not('.responsive-skip-empty').each(function() {
|
||||
var $items = $(this).children('tr');
|
||||
if (!$items.length) {
|
||||
$(this).parent('table:first').addClass('responsive-hide');
|
||||
}
|
||||
});
|
||||
|
@ -827,65 +810,64 @@ function parse_document(container)
|
|||
/**
|
||||
* Responsive tabs
|
||||
*/
|
||||
container.find('#tabs, #minitabs').not('[data-skip-responsive]').each(function() {
|
||||
$container.find('#tabs, #minitabs').not('[data-skip-responsive]').each(function() {
|
||||
var $this = $(this),
|
||||
$body = $('body'),
|
||||
ul = $this.children(),
|
||||
tabs = ul.children().not('[data-skip-responsive]'),
|
||||
links = tabs.children('a'),
|
||||
item = ul.append('<li class="tab responsive-tab" style="display:none;"><a href="javascript:void(0);" class="responsive-tab-link"> </a><div class="dropdown tab-dropdown" style="display: none;"><div class="pointer"><div class="pointer-inner" /></div><ul class="dropdown-contents" /></div></li>').find('li.responsive-tab'),
|
||||
menu = item.find('.dropdown-contents'),
|
||||
$ul = $this.children(),
|
||||
$tabs = $ul.children().not('[data-skip-responsive]'),
|
||||
$links = $tabs.children('a'),
|
||||
$item = $ul.append('<li class="tab responsive-tab" style="display:none;"><a href="javascript:void(0);" class="responsive-tab-link"> </a><div class="dropdown tab-dropdown" style="display: none;"><div class="pointer"><div class="pointer-inner" /></div><ul class="dropdown-contents" /></div></li>').find('li.responsive-tab'),
|
||||
$menu = $item.find('.dropdown-contents'),
|
||||
maxHeight = 0,
|
||||
lastWidth = false,
|
||||
responsive = false;
|
||||
|
||||
links.each(function() {
|
||||
var link = $(this);
|
||||
maxHeight = Math.max(maxHeight, Math.max(link.outerHeight(true), link.parent().outerHeight(true)));
|
||||
})
|
||||
$links.each(function() {
|
||||
var $this = $(this);
|
||||
maxHeight = Math.max(maxHeight, Math.max($this.outerHeight(true), $this.parent().outerHeight(true)));
|
||||
});
|
||||
|
||||
function check() {
|
||||
var width = $body.width(),
|
||||
height = $this.height();
|
||||
|
||||
if (arguments.length == 0 && (!responsive || width <= lastWidth) && height <= maxHeight) {
|
||||
if (!arguments.length && (!responsive || width <= lastWidth) && height <= maxHeight) {
|
||||
return;
|
||||
}
|
||||
|
||||
tabs.show();
|
||||
item.hide();
|
||||
$tabs.show();
|
||||
$item.hide();
|
||||
|
||||
lastWidth = width;
|
||||
height = $this.height();
|
||||
if (height <= maxHeight) {
|
||||
responsive = false;
|
||||
if (item.hasClass('dropdown-visible')) {
|
||||
phpbb.toggleDropdown.call(item.find('a.responsive-tab-link').get(0));
|
||||
if ($item.hasClass('dropdown-visible')) {
|
||||
phpbb.toggleDropdown.call($item.find('a.responsive-tab-link').get(0));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
responsive = true;
|
||||
item.show();
|
||||
menu.html('');
|
||||
$item.show();
|
||||
$menu.html('');
|
||||
|
||||
var availableTabs = tabs.filter(':not(.activetab, .responsive-tab)'),
|
||||
total = availableTabs.length,
|
||||
i, tab;
|
||||
var $availableTabs = $tabs.filter(':not(.activetab, .responsive-tab)'),
|
||||
total = $availableTabs.length,
|
||||
i, $tab;
|
||||
|
||||
for (i = total - 1; i >= 0; i --) {
|
||||
tab = availableTabs.eq(i);
|
||||
menu.prepend(tab.clone(true).removeClass('tab'));
|
||||
tab.hide();
|
||||
$tab = $availableTabs.eq(i);
|
||||
$menu.prepend($tab.clone(true).removeClass('tab'));
|
||||
$tab.hide();
|
||||
if ($this.height() <= maxHeight) {
|
||||
menu.find('a').click(function() { check(true); });
|
||||
$menu.find('a').click(function() { check(true); });
|
||||
return;
|
||||
}
|
||||
}
|
||||
menu.find('a').click(function() { check(true); });
|
||||
$menu.find('a').click(function() { check(true); });
|
||||
}
|
||||
|
||||
phpbb.registerDropdown(item.find('a.responsive-tab-link'), item.find('.dropdown'), {visibleClass: 'activetab'});
|
||||
phpbb.registerDropdown($item.find('a.responsive-tab-link'), $item.find('.dropdown'), {visibleClass: 'activetab'});
|
||||
|
||||
check(true);
|
||||
$(window).resize(check);
|
||||
|
@ -894,10 +876,9 @@ function parse_document(container)
|
|||
/**
|
||||
* Hide UCP/MCP navigation if there is only 1 item
|
||||
*/
|
||||
container.find('#navigation').each(function() {
|
||||
var items = $(this).children('ol, ul').children('li');
|
||||
if (items.length == 1)
|
||||
{
|
||||
$container.find('#navigation').each(function() {
|
||||
var $items = $(this).children('ol, ul').children('li');
|
||||
if ($items.length === 1) {
|
||||
$(this).addClass('responsive-hide');
|
||||
}
|
||||
});
|
||||
|
@ -905,7 +886,7 @@ function parse_document(container)
|
|||
/**
|
||||
* Replace responsive text
|
||||
*/
|
||||
container.find('[data-responsive-text]').each(function() {
|
||||
$container.find('[data-responsive-text]').each(function() {
|
||||
var $this = $(this),
|
||||
fullText = $this.text(),
|
||||
responsiveText = $this.attr('data-responsive-text'),
|
||||
|
@ -913,12 +894,16 @@ function parse_document(container)
|
|||
|
||||
function check() {
|
||||
if ($(window).width() > 700) {
|
||||
if (!responsive) return;
|
||||
if (!responsive) {
|
||||
return;
|
||||
}
|
||||
$this.text(fullText);
|
||||
responsive = false;
|
||||
return;
|
||||
}
|
||||
if (responsive) return;
|
||||
if (responsive) {
|
||||
return;
|
||||
}
|
||||
$this.text(responsiveText);
|
||||
responsive = true;
|
||||
}
|
||||
|
@ -931,8 +916,9 @@ function parse_document(container)
|
|||
/**
|
||||
* Run onload functions
|
||||
*/
|
||||
(function($) {
|
||||
$(document).ready(function() {
|
||||
jQuery(function($) {
|
||||
'use strict';
|
||||
|
||||
// Swap .nojs and .hasjs
|
||||
$('#phpbb.nojs').toggleClass('nojs hasjs');
|
||||
$('#phpbb').toggleClass('hastouch', phpbb.isTouch);
|
||||
|
@ -943,6 +929,5 @@ function parse_document(container)
|
|||
$('#' + this.getAttribute('data-focus')).focus();
|
||||
});
|
||||
|
||||
parse_document($('body'));
|
||||
});
|
||||
})(jQuery);
|
||||
parseDocument($('body'));
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue