mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-15 03:55:23 +02:00
[ticket/11956] Move JS to reusable function
Move JS to reusable function that can be ran for all content added with JavaScript such as results of AJAX forms PHPBB3-11956
This commit is contained in:
parent
d2d4438db5
commit
431b4acb36
@ -410,46 +410,44 @@ function insert_single_user(formId, user)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run onload functions
|
* Parse document block
|
||||||
*/
|
*/
|
||||||
(function($) {
|
function parse_document(container)
|
||||||
$(document).ready(function() {
|
{
|
||||||
// Swap .nojs and .hasjs
|
var test = document.createElement('div'),
|
||||||
$('#phpbb.nojs').toggleClass('nojs hasjs');
|
oldBrowser = (typeof test.style.borderRadius == 'undefined');
|
||||||
|
|
||||||
// Focus forms
|
delete test;
|
||||||
$('form[data-focus]:first').each(function() {
|
|
||||||
$('#' + this.getAttribute('data-focus')).focus();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Reset avatar dimensions when changing URL or EMAIL
|
/**
|
||||||
$('input[data-reset-on-edit]').bind('keyup', function() {
|
* Reset avatar dimensions when changing URL or EMAIL
|
||||||
|
*/
|
||||||
|
container.find('input[data-reset-on-edit]').bind('keyup', function() {
|
||||||
$(this.getAttribute('data-reset-on-edit')).val('');
|
$(this.getAttribute('data-reset-on-edit')).val('');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pagination
|
/**
|
||||||
$('a.pagination-trigger').click(function() {
|
* Pagination
|
||||||
|
*/
|
||||||
|
container.find('a.pagination-trigger').click(function() {
|
||||||
jumpto($(this));
|
jumpto($(this));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Adjust HTML code for IE8 and older versions
|
/**
|
||||||
var test = document.createElement('div'),
|
* Adjust HTML code for IE8 and older versions
|
||||||
oldBrowser = (typeof test.style.borderRadius == 'undefined');
|
*/
|
||||||
delete test;
|
|
||||||
|
|
||||||
if (oldBrowser) {
|
if (oldBrowser) {
|
||||||
// Fix .linklist.bulletin lists
|
// Fix .linklist.bulletin lists
|
||||||
$('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');
|
||||||
|
|
||||||
// Do not run functions below for old browsers
|
// Do not run functions below for old browsers
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust topiclist lists with check boxes
|
/**
|
||||||
$('ul.topiclist dd.mark').siblings('dt').children('.list-inner').addClass('with-mark');
|
* Resize navigation block to keep all links on same line
|
||||||
|
*/
|
||||||
// Resize navigation block to keep all links on same line
|
container.find('.navlinks').each(function() {
|
||||||
$('.navlinks').each(function() {
|
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
left = $this.children().not('.rightside'),
|
left = $this.children().not('.rightside'),
|
||||||
right = $this.children('.rightside');
|
right = $this.children('.rightside');
|
||||||
@ -470,8 +468,10 @@ function insert_single_user(formId, user)
|
|||||||
$(window).resize(resize);
|
$(window).resize(resize);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Responsive breadcrumbs
|
/**
|
||||||
$('.breadcrumbs:not(.skip-responsive, .linklist.leftside .breadcrumbs)').each(function() {
|
* Makes breadcrumbs responsive
|
||||||
|
*/
|
||||||
|
container.find('.breadcrumbs:not(.skip-responsive, .linklist.leftside .breadcrumbs)').each(function() {
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
$body = $('body'),
|
$body = $('body'),
|
||||||
links = $this.find('.crumb'),
|
links = $this.find('.crumb'),
|
||||||
@ -536,12 +536,24 @@ function insert_single_user(formId, user)
|
|||||||
$(window).resize(check);
|
$(window).resize(check);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Responsive topic lists
|
/**
|
||||||
$('.topiclist.responsive-show-all > li > dl').each(function() {
|
* Adjust topiclist lists with check boxes
|
||||||
|
*/
|
||||||
|
container.find('ul.topiclist dd.mark').siblings('dt').children('.list-inner').addClass('with-mark');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends contents of all extra columns to first column in
|
||||||
|
* .topiclist lists for mobile devices. Copies contents as is.
|
||||||
|
*
|
||||||
|
* 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() {
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
block = $this.find('dt .responsive-show:last-child'),
|
block = $this.find('dt .responsive-show:last-child'),
|
||||||
first = true;
|
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;" />');
|
$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');
|
||||||
@ -550,6 +562,7 @@ function insert_single_user(formId, user)
|
|||||||
first = (block.text().trim().length == 0);
|
first = (block.text().trim().length == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy contents of each column
|
||||||
$this.find('dd').not('.mark').each(function() {
|
$this.find('dd').not('.mark').each(function() {
|
||||||
var column = $(this),
|
var column = $(this),
|
||||||
children = column.children(),
|
children = column.children(),
|
||||||
@ -565,11 +578,19 @@ function insert_single_user(formId, user)
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.topiclist.responsive-show-columns').each(function() {
|
/**
|
||||||
|
* Same as above, but prepends text from header to each
|
||||||
|
* column before contents of that column.
|
||||||
|
*
|
||||||
|
* 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),
|
var list = $(this),
|
||||||
headers = [],
|
headers = [],
|
||||||
headersLength = 0;
|
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());
|
headers.push($(this).text());
|
||||||
headersLength ++;
|
headersLength ++;
|
||||||
@ -579,11 +600,13 @@ function insert_single_user(formId, user)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse each row
|
||||||
list.find('dl').each(function() {
|
list.find('dl').each(function() {
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
block = $this.find('dt .responsive-show:last-child'),
|
block = $this.find('dt .responsive-show:last-child'),
|
||||||
first = true;
|
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;" />');
|
$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');
|
||||||
@ -592,6 +615,7 @@ function insert_single_user(formId, user)
|
|||||||
first = (block.text().trim().length == 0);
|
first = (block.text().trim().length == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy contents of each column
|
||||||
$this.find('dd').not('.mark').each(function(i) {
|
$this.find('dd').not('.mark').each(function(i) {
|
||||||
var column = $(this),
|
var column = $(this),
|
||||||
children = column.children(),
|
children = column.children(),
|
||||||
@ -601,6 +625,7 @@ function insert_single_user(formId, user)
|
|||||||
html = children.html();
|
html = children.html();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prepend contents of matching header before contents of column
|
||||||
if (i < headersLength) {
|
if (i < headersLength) {
|
||||||
html = headers[i] + ': <strong>' + html + '</strong>';
|
html = headers[i] + ': <strong>' + html + '</strong>';
|
||||||
}
|
}
|
||||||
@ -612,8 +637,10 @@ function insert_single_user(formId, user)
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Responsive tables
|
/**
|
||||||
$('table.table1').not('.not-responsive').each(function() {
|
* Responsive tables
|
||||||
|
*/
|
||||||
|
container.find('table.table1').not('.not-responsive').each(function() {
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
th = $this.find('thead > tr > th'),
|
th = $this.find('thead > tr > th'),
|
||||||
columns = th.length,
|
columns = th.length,
|
||||||
@ -682,8 +709,21 @@ function insert_single_user(formId, user)
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Responsive link lists
|
/**
|
||||||
$('.linklist:not(.navlinks, .skip-responsive), .postbody ul.profile-icons:not(.skip-responsive)').each(function() {
|
* Hide empty responsive tables
|
||||||
|
*/
|
||||||
|
container.find('table.responsive > tbody').each(function() {
|
||||||
|
var items = $(this).children('tr');
|
||||||
|
if (items.length == 0)
|
||||||
|
{
|
||||||
|
$(this).parent('table:first').addClass('responsive-hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Responsive link lists
|
||||||
|
*/
|
||||||
|
container.find('.linklist:not(.navlinks, .skip-responsive), .postbody ul.profile-icons:not(.skip-responsive)').each(function() {
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
$body = $('body'),
|
$body = $('body'),
|
||||||
links = $this.children().not('.skip-responsive'),
|
links = $this.children().not('.skip-responsive'),
|
||||||
@ -816,8 +856,10 @@ function insert_single_user(formId, user)
|
|||||||
$(window).resize(check);
|
$(window).resize(check);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Responsive tabs
|
/**
|
||||||
$('#tabs, #minitabs').not('.skip-responsive').each(function() {
|
* Responsive tabs
|
||||||
|
*/
|
||||||
|
container.find('#tabs, #minitabs').not('.skip-responsive').each(function() {
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
$body = $('body'),
|
$body = $('body'),
|
||||||
ul = $this.children(),
|
ul = $this.children(),
|
||||||
@ -881,6 +923,31 @@ function insert_single_user(formId, user)
|
|||||||
$(window).resize(check);
|
$(window).resize(check);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
$(this).addClass('responsive-hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run onload functions
|
||||||
|
*/
|
||||||
|
(function($) {
|
||||||
|
$(document).ready(function() {
|
||||||
|
// Swap .nojs and .hasjs
|
||||||
|
$('#phpbb.nojs').toggleClass('nojs hasjs');
|
||||||
|
|
||||||
|
// Focus forms
|
||||||
|
$('form[data-focus]:first').each(function() {
|
||||||
|
$('#' + this.getAttribute('data-focus')).focus();
|
||||||
|
});
|
||||||
|
|
||||||
// Hide responsive menu and tabs
|
// Hide responsive menu and tabs
|
||||||
$('#phpbb').click(function(e) {
|
$('#phpbb').click(function(e) {
|
||||||
var parents = $(e.target).parents();
|
var parents = $(e.target).parents();
|
||||||
@ -892,22 +959,6 @@ function insert_single_user(formId, user)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Hide *CP navigation if there is only 1 item
|
parse_document($('body'));
|
||||||
$('#navigation').each(function() {
|
|
||||||
var items = $(this).children('ol, ul').children('li');
|
|
||||||
if (items.length == 1)
|
|
||||||
{
|
|
||||||
$(this).addClass('responsive-hide');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Hide empty responsive tables
|
|
||||||
$('table.responsive > tbody').each(function() {
|
|
||||||
var items = $(this).children('tr');
|
|
||||||
if (items.length == 0)
|
|
||||||
{
|
|
||||||
$(this).parent('table:first').addClass('responsive-hide');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user