/**
* phpBB3 forum functions
*/
/**
* Find a member
*/
function find_username(url) {
popup(url, 760, 570, '_usersearch');
return false;
}
/**
* Window popup
*/
function popup(url, width, height, name) {
if (!name) {
name = '_popup';
}
window.open(url.replace(/&/g, '&'), name, 'height=' + height + ',resizable=yes,scrollbars=yes, width=' + width);
return false;
}
/**
* Jump to page
*/
function jumpto(item) {
if (!item || !item.length) {
item = $('a.pagination-trigger[data-lang-jump-page]');
if (!item.length) {
return;
}
}
var jump_page = item.attr('data-lang-jump-page'),
on_page = item.attr('data-on-page'),
per_page = item.attr('data-per-page'),
base_url = item.attr('data-base-url'),
page = prompt(jump_page, on_page);
if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0) {
if (base_url.indexOf('%d') === -1) {
if (base_url.indexOf('?') === -1) {
document.location.href = base_url + '?start=' + ((page - 1) * per_page);
} else {
document.location.href = base_url.replace(/&/g, '&') + '&start=' + ((page - 1) * per_page);
}
} else {
document.location.href = base_url.replace('%d', page);
}
}
}
/**
* Mark/unmark checklist
* id = ID of parent container, name = name prefix, state = state [true/false]
*/
function marklist(id, name, state) {
jQuery('#' + id + ' input[type=checkbox][name]').each(function() {
var $this = jQuery(this);
if ($this.attr('name').substr(0, name.length) == name) {
$this.prop('checked', state);
}
});
}
/**
* Resize viewable area for attached image or topic review panel (possibly others to come)
* e = element
*/
function viewableArea(e, itself) {
if (!e) {
return;
}
if (!itself) {
e = e.parentNode;
}
if (!e.vaHeight) {
// Store viewable area height before changing style to auto
e.vaHeight = e.offsetHeight;
e.vaMaxHeight = e.style.maxHeight;
e.style.height = 'auto';
e.style.maxHeight = 'none';
e.style.overflow = 'visible';
} else {
// Restore viewable area height to the default
e.style.height = e.vaHeight + 'px';
e.style.overflow = 'auto';
e.style.maxHeight = e.vaMaxHeight;
e.vaHeight = false;
}
}
/**
* Set display of page element
* s[-1,0,1] = hide,toggle display,show
* type = string: inline, block, inline-block or other CSS "display" type
*/
function dE(n, s, type) {
if (!type) {
type = 'block';
}
var e = document.getElementById(n);
if (!s) {
s = (e.style.display === '' || e.style.display === type) ? -1 : 1;
}
e.style.display = (s === 1) ? type : 'none';
}
/**
* Alternate display of subPanels
*/
jQuery(document).ready(function() {
jQuery('.sub-panels').each(function() {
var panels = [],
childNodes = jQuery('a[data-subpanel]', this).each(function() {
panels.push(this.getAttribute('data-subpanel'));
}),
show_panel = this.getAttribute('data-show-panel');
if (panels.length) {
subPanels(show_panel);
childNodes.click(function () {
subPanels(this.getAttribute('data-subpanel'));
return false;
});
}
function subPanels(p) {
var i;
if (typeof(p) === 'string') {
show_panel = p;
}
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';
}
}
}
function selectCode(a) {
// Get ID of code block
var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
var s, r;
// Not IE and IE9+
if (window.getSelection) {
s = window.getSelection();
// Safari
if (s.setBaseAndExtent) {
s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
}
// Firefox and Opera
else {
// workaround for bug # 42885
if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) === '
') {
e.innerHTML = e.innerHTML + ' ';
}
r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
}
// Some older browsers
else if (document.getSelection) {
s = document.getSelection();
r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
// IE
else if (document.selection) {
r = document.body.createTextRange();
r.moveToElementText(e);
r.select();
}
}
/**
* Play quicktime file by determining it's width/height
* from the displayed rectangle area
*/
function play_qt_file(obj) {
var rectangle = obj.GetRectangle();
var width, height;
if (rectangle) {
rectangle = rectangle.split(',');
var x1 = parseInt(rectangle[0], 10);
var x2 = parseInt(rectangle[2], 10);
var y1 = parseInt(rectangle[1], 10);
var y2 = parseInt(rectangle[3], 10);
width = (x1 < 0) ? (x1 * -1) + x2 : x2 - x1;
height = (y1 < 0) ? (y1 * -1) + y2 : y2 - y1;
} else {
width = 200;
height = 0;
}
obj.width = width;
obj.height = height + 16;
obj.SetControllerVisible(true);
obj.Play();
}
var in_autocomplete = false;
var last_key_entered = '';
/**
* Check event key
*/
function phpbb_check_key(event) {
// Keycode is array down or up?
if (event.keyCode && (event.keyCode === 40 || event.keyCode === 38)) {
in_autocomplete = true;
}
// Make sure we are not within an "autocompletion" field
if (in_autocomplete) {
// If return pressed and key changed we reset the autocompletion
if (!last_key_entered || last_key_entered === event.which) {
in_autocompletion = false;
return true;
}
}
// Keycode is not return, then return. ;)
if (event.which !== 13) {
last_key_entered = event.which;
return true;
}
return false;
}
/**
* 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');
if (!default_button || default_button.length <= 0) {
return true;
}
if (phpbb_check_key(e)) {
return true;
}
if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {
default_button.click();
return false;
}
return true;
});
}
jQuery(document).ready(apply_onkeypress_event);
/**
* Run MSN action
*/
function msn_action(action, address)
{
// Does the browser support the MSNM object?
var app = document.getElementById('objMessengerApp');
if (!app || !app.MyStatus) {
var lang = $('form[data-lang-im-msnm-browser]');
if (lang.length) {
alert(lang.attr('data-lang-im-msnm-browser'));
}
return false;
}
// Is MSNM connected?
if (app.MyStatus == 1) {
var lang = $('form[data-lang-im-msnm-connect]');
if (lang.length) {
alert(lang.attr('data-lang-im-msnm-connect'));
}
return false;
}
// Do stuff
try {
switch (action) {
case 'add':
app.AddContact(0, address);
break;
case 'im':
app.InstantMessage(address);
break;
}
}
catch (e) {
return;
}
}
/**
* Add to your contact list
*/
function add_contact(address)
{
msn_action('add', address);
}
/**
* Write IM to contact
*/
function im_contact(address)
{
msn_action('im', address);
}
/**
* Functions for user search popup
*/
function insert_user(formId, value)
{
var form = jQuery(formId),
formName = form.attr('data-form-name'),
fieldName = form.attr('data-field-name'),
item = opener.document.forms[formName][fieldName];
if (item.value.length && item.type == 'textarea') {
value = item.value + "\n" + value;
}
item.value = value;
}
function insert_marked_users(formId, users)
{
if (typeof(users.length) == "undefined")
{
if (users.checked)
{
insert_user(formId, users.value);
}
}
else if (users.length > 0)
{
for (i = 0; i < users.length; i++)
{
if (users[i].checked)
{
insert_user(formId, users[i].value);
}
}
}
self.close();
}
function insert_single_user(formId, user)
{
insert_user(formId, user);
self.close();
}
/**
* Parse document block
*/
function parse_document(container)
{
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() {
$(this.getAttribute('data-reset-on-edit')).val('');
});
/**
* Pagination
*/
container.find('a.pagination-trigger').click(function() {
jumpto($(this));
});
/**
* Dropdowns
*/
container.find('.dropdown-container').each(function() {
var $this = $(this),
trigger = $this.find('.dropdown-trigger:first'),
contents = $this.find('.dropdown'),
options = {
direction: 'auto',
verticalDirection: 'auto'
},
data;
if (!trigger.length) {
data = $this.attr('data-dropdown-trigger');
trigger = data ? $this.children(data) : $this.children('a:first');
}
if (!contents.length) {
data = $this.attr('data-dropdown-contents');
contents = data ? $this.children(data) : $this.children('div:first');
}
if (!trigger.length || !contents.length) return;
if ($this.hasClass('dropdown-up')) options.verticalDirection = 'up';
if ($this.hasClass('dropdown-down')) options.verticalDirection = 'down';
if ($this.hasClass('dropdown-left')) options.direction = 'left';
if ($this.hasClass('dropdown-right')) options.direction = 'right';
phpbb.registerDropdown(trigger, contents, options);
});
/**
* Adjust HTML code for IE8 and older versions
*/
if (oldBrowser) {
// Fix .linklist.bulletin lists
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
return;
}
/**
* Resize navigation block to keep all links on same line
*/
container.find('.navlinks').each(function() {
var $this = $(this),
left = $this.children().not('.rightside'),
right = $this.children('.rightside');
if (left.length !== 1 || !right.length) return;
function resize() {
var width = 0,
diff = left.outerWidth(true) - left.width();
right.each(function() {
width += $(this).outerWidth(true);
});
left.css('max-width', Math.floor($this.width() - width - diff) + 'px');
}
resize();
$(window).resize(resize);
});
/**
* Makes breadcrumbs responsive
*/
container.find('.breadcrumbs:not([data-skip-responsive])').each(function() {
var $this = $(this),
$body = $('body'),
links = $this.find('.crumb'),
length = links.length,
classes = ['wrapped-max', 'wrapped-wide', 'wrapped-medium', 'wrapped-small', 'wrapped-tiny'],
classesLength = classes.length,
maxHeight = 0,
lastWidth = false,
wrapped = false;
// Set tooltips
$this.find('a').each(function() {
var $link = $(this);
$link.attr('title', $link.text());
});
// Funciton that checks breadcrumbs
function check() {
var height = $this.height(),
width = $body.width(),
link, i, j;
maxHeight = parseInt($this.css('line-height')) | 0;
links.each(function() {
if ($(this).height() > 0) {
maxHeight = Math.max(maxHeight, $(this).outerHeight(true));
}
});
if (height <= maxHeight) {
if (!wrapped || lastWidth === false || lastWidth >= width) {
lastWidth = width;
return;
}
}
lastWidth = width;
if (wrapped) {
$this.removeClass('wrapped').find('.crumb.wrapped').removeClass('wrapped ' + classes.join(' '));
wrapped = false;
if ($this.height() <= maxHeight) {
return;
}
}
wrapped = true;
$this.addClass('wrapped');
if ($this.height() <= maxHeight) {
return;
}
for (i = 0; i < classesLength; i ++) {
for (j = length - 1; j >= 0; j --) {
links.eq(j).addClass('wrapped ' + classes[i]);
if ($this.height() <= maxHeight) {
return;
}
}
}
}
// Run function and set event
check();
$(window).resize(check);
});
/**
* 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),
block = $this.find('dt .responsive-show:last-child'),
first = true;
// Create block that is visible only on mobile devices
if (!block.length) {
$this.find('dt > .list-inner').append('