Merge pull request #1184 from marc1706/ticket/11314

[ticket/11314] Improve readability and code cleanup in new JavaScript files
This commit is contained in:
Nils Adermann 2013-04-12 06:32:13 -07:00
commit c25dfef770
12 changed files with 511 additions and 866 deletions

View file

@ -115,9 +115,9 @@ phpbb.addAjaxCallback('activate_deactivate', function(res) {
el.text(res.text); el.text(res.text);
if (newHref.indexOf('deactivate') !== -1) { if (newHref.indexOf('deactivate') !== -1) {
newHref = newHref.replace('deactivate', 'activate') newHref = newHref.replace('deactivate', 'activate');
} else { } else {
newHref = newHref.replace('activate', 'deactivate') newHref = newHref.replace('activate', 'deactivate');
} }
el.attr('href', newHref); el.attr('href', newHref);

View file

@ -10,18 +10,16 @@ var theSelection = false;
// Check for Browser & Platform for PC & IE specific bits // Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html // More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version var clientVer = parseInt(navigator.appVersion, 10); // Get browser version
var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));
var is_ie = ((clientPC.indexOf('msie') !== -1) && (clientPC.indexOf('opera') === -1));
var is_win = ((clientPC.indexOf('win') !== -1) || (clientPC.indexOf('16bit') !== -1));
var baseHeight; var baseHeight;
/** /**
* Shows the help messages in the helpline window * Shows the help messages in the helpline window
*/ */
function helpline(help) function helpline(help) {
{
document.forms[form_name].helpbox.value = help_line[help]; document.forms[form_name].helpbox.value = help_line[help];
} }
@ -29,26 +27,22 @@ function helpline(help)
* Fix a bug involving the TextRange object. From * Fix a bug involving the TextRange object. From
* http://www.frostjedi.com/terra/scripts/demo/caretBug.html * http://www.frostjedi.com/terra/scripts/demo/caretBug.html
*/ */
function initInsertions() function initInsertions() {
{
var doc; var doc;
if(document.forms[form_name])
{ if (document.forms[form_name]) {
doc = document; doc = document;
} } else {
else
{
doc = opener.document; doc = opener.document;
} }
var textarea = doc.forms[form_name].elements[text_name]; var textarea = doc.forms[form_name].elements[text_name];
if (is_ie && typeof(baseHeight) != 'number')
{ if (is_ie && typeof(baseHeight) !== 'number') {
textarea.focus(); textarea.focus();
baseHeight = doc.selection.createRange().duplicate().boundingHeight; baseHeight = doc.selection.createRange().duplicate().boundingHeight;
if (!document.forms[form_name]) if (!document.forms[form_name]) {
{
document.body.focus(); document.body.focus();
} }
} }
@ -57,69 +51,59 @@ function initInsertions()
/** /**
* bbstyle * bbstyle
*/ */
function bbstyle(bbnumber) function bbstyle(bbnumber) {
{ if (bbnumber !== -1) {
if (bbnumber != -1)
{
bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]); bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]);
} } else {
else
{
insert_text('[*]'); insert_text('[*]');
document.forms[form_name].elements[text_name].focus(); document.forms[form_name].elements[text_name].focus();
} }
} }
/** /**
* Apply bbcodes * Apply bbcodes
*/ */
function bbfontstyle(bbopen, bbclose) function bbfontstyle(bbopen, bbclose) {
{
theSelection = false; theSelection = false;
var textarea = document.forms[form_name].elements[text_name]; var textarea = document.forms[form_name].elements[text_name];
textarea.focus(); textarea.focus();
if ((clientVer >= 4) && is_ie && is_win) if ((clientVer >= 4) && is_ie && is_win) {
{
// Get text selection // Get text selection
theSelection = document.selection.createRange().text; theSelection = document.selection.createRange().text;
if (theSelection) if (theSelection) {
{
// Add tags around selection // Add tags around selection
document.selection.createRange().text = bbopen + theSelection + bbclose; document.selection.createRange().text = bbopen + theSelection + bbclose;
document.forms[form_name].elements[text_name].focus(); document.forms[form_name].elements[text_name].focus();
theSelection = ''; theSelection = '';
return; return;
} }
} } else if (document.forms[form_name].elements[text_name].selectionEnd
else if (document.forms[form_name].elements[text_name].selectionEnd && (document.forms[form_name].elements[text_name].selectionEnd - document.forms[form_name].elements[text_name].selectionStart > 0)) && (document.forms[form_name].elements[text_name].selectionEnd - document.forms[form_name].elements[text_name].selectionStart > 0)) {
{
mozWrap(document.forms[form_name].elements[text_name], bbopen, bbclose); mozWrap(document.forms[form_name].elements[text_name], bbopen, bbclose);
document.forms[form_name].elements[text_name].focus(); document.forms[form_name].elements[text_name].focus();
theSelection = ''; theSelection = '';
return; return;
} }
//The new position for the cursor after adding the bbcode //The new position for the cursor after adding the bbcode
var caret_pos = getCaretPosition(textarea).start; var caret_pos = getCaretPosition(textarea).start;
var new_pos = caret_pos + bbopen.length; var new_pos = caret_pos + bbopen.length;
// Open tag // Open tag
insert_text(bbopen + bbclose); insert_text(bbopen + bbclose);
// Center the cursor when we don't have a selection // Center the cursor when we don't have a selection
// Gecko and proper browsers // Gecko and proper browsers
if (!isNaN(textarea.selectionStart)) if (!isNaN(textarea.selectionStart)) {
{
textarea.selectionStart = new_pos; textarea.selectionStart = new_pos;
textarea.selectionEnd = new_pos; textarea.selectionEnd = new_pos;
} }
// IE // IE
else if (document.selection) else if (document.selection) {
{
var range = textarea.createTextRange(); var range = textarea.createTextRange();
range.move("character", new_pos); range.move("character", new_pos);
range.select(); range.select();
@ -133,62 +117,47 @@ function bbfontstyle(bbopen, bbclose)
/** /**
* Insert text at position * Insert text at position
*/ */
function insert_text(text, spaces, popup) function insert_text(text, spaces, popup) {
{
var textarea; var textarea;
if (!popup) if (!popup) {
{
textarea = document.forms[form_name].elements[text_name]; textarea = document.forms[form_name].elements[text_name];
} } else {
else
{
textarea = opener.document.forms[form_name].elements[text_name]; textarea = opener.document.forms[form_name].elements[text_name];
} }
if (spaces) if (spaces) {
{
text = ' ' + text + ' '; text = ' ' + text + ' ';
} }
if (!isNaN(textarea.selectionStart)) if (!isNaN(textarea.selectionStart)) {
{
var sel_start = textarea.selectionStart; var sel_start = textarea.selectionStart;
var sel_end = textarea.selectionEnd; var sel_end = textarea.selectionEnd;
mozWrap(textarea, text, ''); mozWrap(textarea, text, '');
textarea.selectionStart = sel_start + text.length; textarea.selectionStart = sel_start + text.length;
textarea.selectionEnd = sel_end + text.length; textarea.selectionEnd = sel_end + text.length;
} } else if (textarea.createTextRange && textarea.caretPos) {
if (baseHeight !== textarea.caretPos.boundingHeight) {
else if (textarea.createTextRange && textarea.caretPos)
{
if (baseHeight != textarea.caretPos.boundingHeight)
{
textarea.focus(); textarea.focus();
storeCaret(textarea); storeCaret(textarea);
} }
var caret_pos = textarea.caretPos; var caret_pos = textarea.caretPos;
caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text; caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) === ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
} else {
}
else
{
textarea.value = textarea.value + text; textarea.value = textarea.value + text;
} }
if (!popup) if (!popup) {
{
textarea.focus(); textarea.focus();
} }
} }
/** /**
* Add inline attachment at position * Add inline attachment at position
*/ */
function attach_inline(index, filename) function attach_inline(index, filename) {
{
insert_text('[attachment=' + index + ']' + filename + '[/attachment]'); insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
document.forms[form_name].elements[text_name].focus(); document.forms[form_name].elements[text_name].focus();
} }
@ -202,56 +171,39 @@ function addquote(post_id, username)
var theSelection = ''; var theSelection = '';
var divarea = false; var divarea = false;
if (document.all) if (document.all) {
{
divarea = document.all[message_name]; divarea = document.all[message_name];
} } else {
else
{
divarea = document.getElementById(message_name); divarea = document.getElementById(message_name);
} }
// Get text selection - not only the post content :( // Get text selection - not only the post content :(
if (window.getSelection) if (window.getSelection) {
{
theSelection = window.getSelection().toString(); theSelection = window.getSelection().toString();
} } else if (document.getSelection) {
else if (document.getSelection)
{
theSelection = document.getSelection(); theSelection = document.getSelection();
} } else if (document.selection) {
else if (document.selection)
{
theSelection = document.selection.createRange().text; theSelection = document.selection.createRange().text;
} }
if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null) if (theSelection === '' || typeof theSelection === 'undefined' || theSelection === null) {
{ if (divarea.innerHTML) {
if (divarea.innerHTML)
{
theSelection = divarea.innerHTML.replace(/<br>/ig, '\n'); theSelection = divarea.innerHTML.replace(/<br>/ig, '\n');
theSelection = theSelection.replace(/<br\/>/ig, '\n'); theSelection = theSelection.replace(/<br\/>/ig, '\n');
theSelection = theSelection.replace(/&lt\;/ig, '<'); theSelection = theSelection.replace(/&lt\;/ig, '<');
theSelection = theSelection.replace(/&gt\;/ig, '>'); theSelection = theSelection.replace(/&gt\;/ig, '>');
theSelection = theSelection.replace(/&amp\;/ig, '&'); theSelection = theSelection.replace(/&amp\;/ig, '&');
theSelection = theSelection.replace(/&nbsp\;/ig, ' '); theSelection = theSelection.replace(/&nbsp\;/ig, ' ');
} } else if (document.all) {
else if (document.all)
{
theSelection = divarea.innerText; theSelection = divarea.innerText;
} } else if (divarea.textContent) {
else if (divarea.textContent)
{
theSelection = divarea.textContent; theSelection = divarea.textContent;
} } else if (divarea.firstChild.nodeValue) {
else if (divarea.firstChild.nodeValue)
{
theSelection = divarea.firstChild.nodeValue; theSelection = divarea.firstChild.nodeValue;
} }
} }
if (theSelection) if (theSelection) {
{
insert_text('[quote="' + username + '"]' + theSelection + '[/quote]'); insert_text('[quote="' + username + '"]' + theSelection + '[/quote]');
} }
@ -261,15 +213,13 @@ function addquote(post_id, username)
/** /**
* From http://www.massless.org/mozedit/ * From http://www.massless.org/mozedit/
*/ */
function mozWrap(txtarea, open, close) function mozWrap(txtarea, open, close) {
{ var selLength = (typeof(txtarea.textLength) === 'undefined') ? txtarea.value.length : txtarea.textLength;
var selLength = (typeof(txtarea.textLength) == 'undefined') ? txtarea.value.length : txtarea.textLength;
var selStart = txtarea.selectionStart; var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd; var selEnd = txtarea.selectionEnd;
var scrollTop = txtarea.scrollTop; var scrollTop = txtarea.scrollTop;
if (selEnd == 1 || selEnd == 2) if (selEnd === 1 || selEnd === 2) {
{
selEnd = selLength; selEnd = selLength;
} }
@ -290,10 +240,8 @@ function mozWrap(txtarea, open, close)
* Insert at Caret position. Code from * Insert at Caret position. Code from
* http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130 * http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
*/ */
function storeCaret(textEl) function storeCaret(textEl) {
{ if (textEl.createTextRange) {
if (textEl.createTextRange)
{
textEl.caretPos = document.selection.createRange().duplicate(); textEl.caretPos = document.selection.createRange().duplicate();
} }
} }
@ -301,8 +249,7 @@ function storeCaret(textEl)
/** /**
* Color pallette * Color pallette
*/ */
function colorPalette(dir, width, height) function colorPalette(dir, width, height) {
{
var r = 0, g = 0, b = 0; var r = 0, g = 0, b = 0;
var numberList = new Array(6); var numberList = new Array(6);
var color = ''; var color = '';
@ -315,88 +262,74 @@ function colorPalette(dir, width, height)
document.writeln('<table class="type2">'); document.writeln('<table class="type2">');
for (r = 0; r < 5; r++) for (r = 0; r < 5; r++) {
{ if (dir === 'h') {
if (dir == 'h')
{
document.writeln('<tr>'); document.writeln('<tr>');
} }
for (g = 0; g < 5; g++) for (g = 0; g < 5; g++) {
{ if (dir === 'v') {
if (dir == 'v')
{
document.writeln('<tr>'); document.writeln('<tr>');
} }
for (b = 0; b < 5; b++) for (b = 0; b < 5; b++) {
{
color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]); color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
document.write('<td bgcolor="#' + color + '" style="width: ' + width + 'px; height: ' + height + 'px;">'); document.write('<td bgcolor="#' + color + '" style="width: ' + width + 'px; height: ' + height + 'px;">');
document.write('<a href="#" onclick="bbfontstyle(\'[color=#' + color + ']\', \'[/color]\'); return false;"><img src="images/spacer.gif" width="' + width + '" height="' + height + '" alt="#' + color + '" title="#' + color + '" /></a>'); document.write('<a href="#" onclick="bbfontstyle(\'[color=#' + color + ']\', \'[/color]\'); return false;"><img src="images/spacer.gif" width="' + width + '" height="' + height + '" alt="#' + color + '" title="#' + color + '" /></a>');
document.writeln('</td>'); document.writeln('</td>');
} }
if (dir == 'v') if (dir === 'v') {
{
document.writeln('</tr>'); document.writeln('</tr>');
} }
} }
if (dir == 'h') if (dir === 'h') {
{
document.writeln('</tr>'); document.writeln('</tr>');
} }
} }
document.writeln('</table>'); document.writeln('</table>');
} }
/** /**
* Caret Position object * Caret Position object
*/ */
function caretPosition() function caretPosition() {
{
var start = null; var start = null;
var end = null; var end = null;
} }
/** /**
* Get the caret position in an textarea * Get the caret position in an textarea
*/ */
function getCaretPosition(txtarea) function getCaretPosition(txtarea) {
{
var caretPos = new caretPosition(); var caretPos = new caretPosition();
// simple Gecko/Opera way // simple Gecko/Opera way
if (txtarea.selectionStart || txtarea.selectionStart == 0) if (txtarea.selectionStart || txtarea.selectionStart === 0) {
{
caretPos.start = txtarea.selectionStart; caretPos.start = txtarea.selectionStart;
caretPos.end = txtarea.selectionEnd; caretPos.end = txtarea.selectionEnd;
} }
// dirty and slow IE way // dirty and slow IE way
else if (document.selection) else if (document.selection) {
{
// get current selection // get current selection
var range = document.selection.createRange(); var range = document.selection.createRange();
// a new selection of the whole textarea // a new selection of the whole textarea
var range_all = document.body.createTextRange(); var range_all = document.body.createTextRange();
range_all.moveToElementText(txtarea); range_all.moveToElementText(txtarea);
// calculate selection start point by moving beginning of range_all to beginning of range // calculate selection start point by moving beginning of range_all to beginning of range
var sel_start; var sel_start;
for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++) for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++) {
{
range_all.moveStart('character', 1); range_all.moveStart('character', 1);
} }
txtarea.sel_start = sel_start; txtarea.sel_start = sel_start;
// we ignore the end value for IE, this is already dirty enough and we don't need it // we ignore the end value for IE, this is already dirty enough and we don't need it
caretPos.start = txtarea.sel_start; caretPos.start = txtarea.sel_start;
caretPos.end = txtarea.sel_start; caretPos.end = txtarea.sel_start;
} }
return caretPos; return caretPos;

View file

@ -2,35 +2,27 @@
* Hide and show all checkboxes * Hide and show all checkboxes
* status = true (show boxes), false (hide boxes) * status = true (show boxes), false (hide boxes)
*/ */
function display_checkboxes(status) function display_checkboxes(status) {
{
var form = document.getElementById('set-permissions'); var form = document.getElementById('set-permissions');
var cb = document.getElementsByTagName('input'); var cb = document.getElementsByTagName('input');
var display; var display;
//show //show
if (status) if (status) {
{
display = 'inline'; display = 'inline';
} }
//hide //hide
else else {
{
display = 'none'; display = 'none';
} }
for (var i = 0; i < cb.length; i++ ) for (var i = 0; i < cb.length; i++ ) {
{ if (cb[i].className === 'permissions-checkbox') {
if (cb[i].className == 'permissions-checkbox')
{
cb[i].style.display = display; cb[i].style.display = display;
} }
}
}
} }
/** /**
* Change opacity of element * Change opacity of element
* e = element * e = element
@ -38,7 +30,7 @@ function display_checkboxes(status)
*/ */
function set_opacity(e, value) { function set_opacity(e, value) {
e.style.opacity = value/10; e.style.opacity = value/10;
//IE opacity currently turned off, because of its astronomical stupidity //IE opacity currently turned off, because of its astronomical stupidity
//e.style.filter = 'alpha(opacity=' + value*10 + ')'; //e.style.filter = 'alpha(opacity=' + value*10 + ')';
} }
@ -50,13 +42,10 @@ function set_opacity(e, value) {
function toggle_opacity(block_id) { function toggle_opacity(block_id) {
var cb = document.getElementById('checkbox' + block_id); var cb = document.getElementById('checkbox' + block_id);
var fs = document.getElementById('perm' + block_id); var fs = document.getElementById('perm' + block_id);
if (cb.checked) if (cb.checked) {
{
set_opacity(fs, 5); set_opacity(fs, 5);
} } else {
else
{
set_opacity(fs, 10); set_opacity(fs, 10);
} }
} }
@ -71,21 +60,17 @@ function reset_opacity(status, except_id) {
var fs = perm.getElementsByTagName('fieldset'); var fs = perm.getElementsByTagName('fieldset');
var opacity = 5; var opacity = 5;
if (status) if (status) {
{ opacity = 10;
opacity = 10;
} }
for (var i = 0; i < fs.length; i++ ) for (var i = 0; i < fs.length; i++ ) {
{ if (fs[i].className !== 'quick') {
if (fs[i].className != 'quick')
{
set_opacity(fs[i], opacity); set_opacity(fs[i], opacity);
} }
} }
if (typeof(except_id) != 'undefined') if (typeof(except_id) !== 'undefined') {
{
set_opacity(document.getElementById('perm' + except_id), 10); set_opacity(document.getElementById('perm' + except_id), 10);
} }
@ -93,20 +78,15 @@ function reset_opacity(status, except_id) {
marklist('set-permissions', 'inherit', !status); marklist('set-permissions', 'inherit', !status);
} }
/** /**
* Check whether we have a full radiobutton row of true * Check whether we have a full radiobutton row of true
* index = offset for the row of inputs (0 == first row, 1 == second, 2 == third), * index = offset for the row of inputs (0 == first row, 1 == second, 2 == third),
* rb = array of radiobuttons * rb = array of radiobuttons
*/ */
function get_radio_status(index, rb) function get_radio_status(index, rb) {
{ for (var i = index; i < rb.length; i = i + 3 ) {
for (var i = index; i < rb.length; i = i + 3 ) if (rb[i].checked !== true) {
{ if (i > index) {
if (rb[i].checked != true)
{
if (i > index)
{
//at least one is true, but not all (custom) //at least one is true, but not all (custom)
return 2; return 2;
} }
@ -121,17 +101,15 @@ function get_radio_status(index, rb)
/** /**
* Set tab colours * Set tab colours
* id = panel the tab needs to be set for, * id = panel the tab needs to be set for,
* init = initialising on open, * init = initialising on open,
* quick = If no calculation needed, this contains the colour * quick = If no calculation needed, this contains the colour
*/ */
function set_colours(id, init, quick) function set_colours(id, init, quick) {
{
var table = document.getElementById('table' + id); var table = document.getElementById('table' + id);
var tab = document.getElementById('tab' + id); var tab = document.getElementById('tab' + id);
if (typeof(quick) != 'undefined') if (typeof(quick) !== 'undefined') {
{
tab.className = 'permissions-preset-' + quick + ' activetab'; tab.className = 'permissions-preset-' + quick + ' activetab';
return; return;
} }
@ -141,37 +119,27 @@ function set_colours(id, init, quick)
var status = get_radio_status(0, rb); var status = get_radio_status(0, rb);
if (status == 1) if (status === 1) {
{
colour = 'yes'; colour = 'yes';
} } else if (status === 0) {
else if (status == 0)
{
// We move on to No // We move on to No
status = get_radio_status(1, rb); status = get_radio_status(1, rb);
if (status == 1) if (status === 1) {
{
colour = 'no'; colour = 'no';
} } else if (status === 0) {
else if (status == 0)
{
// We move on to Never // We move on to Never
status = get_radio_status(2, rb); status = get_radio_status(2, rb);
if (status == 1) if (status === 1) {
{
colour = 'never'; colour = 'never';
} }
} }
} }
if (init) if (init) {
{
tab.className = 'permissions-preset-' + colour; tab.className = 'permissions-preset-' + colour;
} } else {
else
{
tab.className = 'permissions-preset-' + colour + ' activetab'; tab.className = 'permissions-preset-' + colour + ' activetab';
} }
} }
@ -180,16 +148,13 @@ function set_colours(id, init, quick)
* Initialise advanced tab colours on first load * Initialise advanced tab colours on first load
* block_id = block that is opened * block_id = block that is opened
*/ */
function init_colours(block_id) function init_colours(block_id) {
{
var block = document.getElementById('advanced' + block_id); var block = document.getElementById('advanced' + block_id);
var panels = block.getElementsByTagName('div'); var panels = block.getElementsByTagName('div');
var tab = document.getElementById('tab' + id); var tab = document.getElementById('tab' + id);
for (var i = 0; i < panels.length; i++) for (var i = 0; i < panels.length; i++) {
{ if (panels[i].className === 'permissions-panel') {
if(panels[i].className == 'permissions-panel')
{
set_colours(panels[i].id.replace(/options/, ''), true); set_colours(panels[i].id.replace(/options/, ''), true);
} }
} }
@ -203,17 +168,15 @@ function init_colours(block_id)
* adv = we are opening advanced permissions * adv = we are opening advanced permissions
* view = called from view permissions * view = called from view permissions
*/ */
function swap_options(pmask, fmask, cat, adv, view) function swap_options(pmask, fmask, cat, adv, view) {
{
id = pmask + fmask + cat; id = pmask + fmask + cat;
active_option = active_pmask + active_fmask + active_cat; active_option = active_pmask + active_fmask + active_cat;
var old_tab = document.getElementById('tab' + active_option); var old_tab = document.getElementById('tab' + active_option);
var new_tab = document.getElementById('tab' + id); var new_tab = document.getElementById('tab' + id);
var adv_block = document.getElementById('advanced' + pmask + fmask); var adv_block = document.getElementById('advanced' + pmask + fmask);
if (adv_block.style.display == 'block' && adv == true) if (adv_block.style.display === 'block' && adv === true) {
{
dE('advanced' + pmask + fmask, -1); dE('advanced' + pmask + fmask, -1);
reset_opacity(1); reset_opacity(1);
display_checkboxes(false); display_checkboxes(false);
@ -221,20 +184,16 @@ function swap_options(pmask, fmask, cat, adv, view)
} }
// no need to set anything if we are clicking on the same tab again // no need to set anything if we are clicking on the same tab again
if (new_tab == old_tab && !adv) if (new_tab === old_tab && !adv) {
{
return; return;
} }
// init colours // init colours
if (adv && (pmask + fmask) != (active_pmask + active_fmask)) if (adv && (pmask + fmask) !== (active_pmask + active_fmask)) {
{
init_colours(pmask + fmask); init_colours(pmask + fmask);
display_checkboxes(true); display_checkboxes(true);
reset_opacity(1); reset_opacity(1);
} } else if (adv) {
else if (adv)
{
//Checkbox might have been clicked, but we need full visibility //Checkbox might have been clicked, but we need full visibility
display_checkboxes(true); display_checkboxes(true);
reset_opacity(1); reset_opacity(1);
@ -244,31 +203,26 @@ function swap_options(pmask, fmask, cat, adv, view)
old_tab.className = old_tab.className.replace(/\ activetab/g, ''); old_tab.className = old_tab.className.replace(/\ activetab/g, '');
new_tab.className = new_tab.className + ' activetab'; new_tab.className = new_tab.className + ' activetab';
if (id == active_option && adv != true) if (id === active_option && adv !== true) {
{
return; return;
} }
dE('options' + active_option, -1); dE('options' + active_option, -1);
//hiding and showing the checkbox //hiding and showing the checkbox
if (document.getElementById('checkbox' + active_pmask + active_fmask)) if (document.getElementById('checkbox' + active_pmask + active_fmask)) {
{ dE('checkbox' + pmask + fmask, -1);
dE('checkbox' + pmask + fmask, -1);
if ((pmask + fmask) !== (active_pmask + active_fmask)) {
if ((pmask + fmask) != (active_pmask + active_fmask))
{
document.getElementById('checkbox' + active_pmask + active_fmask).style.display = 'inline'; document.getElementById('checkbox' + active_pmask + active_fmask).style.display = 'inline';
} }
} }
if (!view) if (!view) {
{
dE('advanced' + active_pmask + active_fmask, -1); dE('advanced' + active_pmask + active_fmask, -1);
} }
if (!view) if (!view) {
{
dE('advanced' + pmask + fmask, 1); dE('advanced' + pmask + fmask, 1);
} }
dE('options' + id, 1); dE('options' + id, 1);
@ -282,41 +236,33 @@ function swap_options(pmask, fmask, cat, adv, view)
* Mark all radio buttons in one panel * Mark all radio buttons in one panel
* id = table ID container, s = status ['y'/'u'/'n'] * id = table ID container, s = status ['y'/'u'/'n']
*/ */
function mark_options(id, s) function mark_options(id, s) {
{
var t = document.getElementById(id); var t = document.getElementById(id);
if (!t) if (!t) {
{
return; return;
} }
var rb = t.getElementsByTagName('input'); var rb = t.getElementsByTagName('input');
for (var r = 0; r < rb.length; r++) for (var r = 0; r < rb.length; r++) {
{ if (rb[r].id.substr(rb[r].id.length-1) === s) {
if (rb[r].id.substr(rb[r].id.length-1) == s)
{
rb[r].checked = true; rb[r].checked = true;
} }
} }
} }
function mark_one_option(id, field_name, s) function mark_one_option(id, field_name, s) {
{
var t = document.getElementById(id); var t = document.getElementById(id);
if (!t) if (!t) {
{
return; return;
} }
var rb = t.getElementsByTagName('input'); var rb = t.getElementsByTagName('input');
for (var r = 0; r < rb.length; r++) for (var r = 0; r < rb.length; r++) {
{ if (rb[r].id.substr(rb[r].id.length-field_name.length-3, field_name.length) === field_name && rb[r].id.substr(rb[r].id.length-1) === s) {
if (rb[r].id.substr(rb[r].id.length-field_name.length-3, field_name.length) == field_name && rb[r].id.substr(rb[r].id.length-1) == s)
{
rb[r].checked = true; rb[r].checked = true;
} }
} }
@ -325,12 +271,10 @@ function mark_one_option(id, field_name, s)
/** /**
* Reset role dropdown field to Select role... if an option gets changed * Reset role dropdown field to Select role... if an option gets changed
*/ */
function reset_role(id) function reset_role(id) {
{
var t = document.getElementById(id); var t = document.getElementById(id);
if (!t) if (!t) {
{
return; return;
} }
@ -340,20 +284,17 @@ function reset_role(id)
/** /**
* Load role and set options accordingly * Load role and set options accordingly
*/ */
function set_role_settings(role_id, target_id) function set_role_settings(role_id, target_id) {
{
settings = role_options[role_id]; settings = role_options[role_id];
if (!settings) if (!settings) {
{
return; return;
} }
// Mark all options to no (unset) first... // Mark all options to no (unset) first...
mark_options(target_id, 'u'); mark_options(target_id, 'u');
for (var r in settings) for (var r in settings) {
{ mark_one_option(target_id, r, (settings[r] === 1) ? 'y' : 'n');
mark_one_option(target_id, r, (settings[r] == 1) ? 'y' : 'n');
} }
} }

View file

@ -1,5 +1,7 @@
(function($) { // Avoid conflicts with other libraries (function($) { // Avoid conflicts with other libraries
"use strict";
$('#tz_date').change(function() { $('#tz_date').change(function() {
phpbb.timezoneSwitchDate(false); phpbb.timezoneSwitchDate(false);
}); });

View file

@ -1,6 +1,6 @@
/* /*
javascript for Bubble Tooltips by Alessandro Fulciniti javascript for Bubble Tooltips by Alessandro Fulciniti
- http://pro.html.it - http://web-graphics.com - http://pro.html.it - http://web-graphics.com
obtained from: http://web-graphics.com/mtarchive/001717.php obtained from: http://web-graphics.com/mtarchive/001717.php
phpBB Development Team: phpBB Development Team:
@ -15,14 +15,12 @@ var head_text, tooltip_mode;
/** /**
* Enable tooltip replacements for links * Enable tooltip replacements for links
*/ */
function enable_tooltips_link(id, headline, sub_id) function enable_tooltips_link(id, headline, sub_id) {
{
var links, i, hold; var links, i, hold;
head_text = headline; head_text = headline;
if (!document.getElementById || !document.getElementsByTagName) if (!document.getElementById || !document.getElementsByTagName) {
{
return; return;
} }
@ -33,26 +31,18 @@ function enable_tooltips_link(id, headline, sub_id)
document.getElementsByTagName('body')[0].appendChild(hold); document.getElementsByTagName('body')[0].appendChild(hold);
if (id == null) if (id === null) {
{
links = document.getElementsByTagName('a'); links = document.getElementsByTagName('a');
} } else {
else
{
links = document.getElementById(id).getElementsByTagName('a'); links = document.getElementById(id).getElementsByTagName('a');
} }
for (i = 0; i < links.length; i++) for (i = 0; i < links.length; i++) {
{ if (sub_id) {
if (sub_id) if (links[i].id.substr(0, sub_id.length) === sub_id) {
{
if (links[i].id.substr(0, sub_id.length) == sub_id)
{
prepare(links[i]); prepare(links[i]);
} }
} } else {
else
{
prepare(links[i]); prepare(links[i]);
} }
} }
@ -63,14 +53,12 @@ function enable_tooltips_link(id, headline, sub_id)
/** /**
* Enable tooltip replacements for selects * Enable tooltip replacements for selects
*/ */
function enable_tooltips_select(id, headline, sub_id) function enable_tooltips_select(id, headline, sub_id) {
{
var links, i, hold; var links, i, hold;
head_text = headline; head_text = headline;
if (!document.getElementById || !document.getElementsByTagName) if (!document.getElementById || !document.getElementsByTagName) {
{
return; return;
} }
@ -81,26 +69,18 @@ function enable_tooltips_select(id, headline, sub_id)
document.getElementsByTagName('body')[0].appendChild(hold); document.getElementsByTagName('body')[0].appendChild(hold);
if (id == null) if (id === null) {
{
links = document.getElementsByTagName('option'); links = document.getElementsByTagName('option');
} } else {
else
{
links = document.getElementById(id).getElementsByTagName('option'); links = document.getElementById(id).getElementsByTagName('option');
} }
for (i = 0; i < links.length; i++) for (i = 0; i < links.length; i++) {
{ if (sub_id) {
if (sub_id) if (links[i].parentNode.id.substr(0, sub_id.length) === sub_id) {
{
if (links[i].parentNode.id.substr(0, sub_id.length) == sub_id)
{
prepare(links[i]); prepare(links[i]);
} }
} } else {
else
{
prepare(links[i]); prepare(links[i]);
} }
} }
@ -111,14 +91,12 @@ function enable_tooltips_select(id, headline, sub_id)
/** /**
* Prepare elements to replace * Prepare elements to replace
*/ */
function prepare(element) function prepare(element) {
{
var tooltip, text, desc, title; var tooltip, text, desc, title;
text = element.getAttribute('title'); text = element.getAttribute('title');
if (text == null || text.length == 0) if (text === null || text.length === 0) {
{
return; return;
} }
@ -139,8 +117,7 @@ function prepare(element)
element.onmouseover = show_tooltip; element.onmouseover = show_tooltip;
element.onmouseout = hide_tooltip; element.onmouseout = hide_tooltip;
if (tooltip_mode == 'link') if (tooltip_mode === 'link') {
{
element.onmousemove = locate; element.onmousemove = locate;
} }
} }
@ -148,8 +125,7 @@ function prepare(element)
/** /**
* Show tooltip * Show tooltip
*/ */
function show_tooltip(e) function show_tooltip(e) {
{
document.getElementById('_tooltip_container').appendChild(this.tooltip); document.getElementById('_tooltip_container').appendChild(this.tooltip);
locate(this); locate(this);
} }
@ -157,11 +133,9 @@ function show_tooltip(e)
/** /**
* Hide tooltip * Hide tooltip
*/ */
function hide_tooltip(e) function hide_tooltip(e) {
{
var d = document.getElementById('_tooltip_container'); var d = document.getElementById('_tooltip_container');
if (d.childNodes.length > 0) if (d.childNodes.length > 0) {
{
d.removeChild(d.firstChild); d.removeChild(d.firstChild);
} }
} }
@ -169,8 +143,7 @@ function hide_tooltip(e)
/** /**
* Set opacity on tooltip element * Set opacity on tooltip element
*/ */
function set_opacity(element) function set_opacity(element) {
{
element.style.filter = 'alpha(opacity:95)'; element.style.filter = 'alpha(opacity:95)';
element.style.KHTMLOpacity = '0.95'; element.style.KHTMLOpacity = '0.95';
element.style.MozOpacity = '0.95'; element.style.MozOpacity = '0.95';
@ -180,8 +153,7 @@ function set_opacity(element)
/** /**
* Create new element * Create new element
*/ */
function create_element(tag, c) function create_element(tag, c) {
{
var x = document.createElement(tag); var x = document.createElement(tag);
x.className = c; x.className = c;
x.style.display = 'block'; x.style.display = 'block';
@ -191,34 +163,26 @@ function create_element(tag, c)
/** /**
* Correct positioning of tooltip container * Correct positioning of tooltip container
*/ */
function locate(e) function locate(e) {
{
var posx = 0; var posx = 0;
var posy = 0; var posy = 0;
e = e.parentNode; e = e.parentNode;
if (e.offsetParent) if (e.offsetParent) {
{ for (posx = 0, posy = 0; e.offsetParent; e = e.offsetParent) {
for (var posx = 0, posy = 0; e.offsetParent; e = e.offsetParent)
{
posx += e.offsetLeft; posx += e.offsetLeft;
posy += e.offsetTop; posy += e.offsetTop;
} }
} } else {
else
{
posx = e.offsetLeft; posx = e.offsetLeft;
posy = e.offsetTop; posy = e.offsetTop;
} }
if (tooltip_mode == 'link') if (tooltip_mode === 'link') {
{
document.getElementById('_tooltip_container').style.top=(posy+20) + 'px'; document.getElementById('_tooltip_container').style.top=(posy+20) + 'px';
document.getElementById('_tooltip_container').style.left=(posx-20) + 'px'; document.getElementById('_tooltip_container').style.left=(posx-20) + 'px';
} } else {
else
{
document.getElementById('_tooltip_container').style.top=(posy+30) + 'px'; document.getElementById('_tooltip_container').style.top=(posy+30) + 'px';
document.getElementById('_tooltip_container').style.left=(posx-205) + 'px'; document.getElementById('_tooltip_container').style.left=(posx-205) + 'px';
} }

View file

@ -57,7 +57,7 @@ phpbb.clearLoadingTimeout = function() {
* @param string title Title of the message, eg "Information" (HTML). * @param string title Title of the message, eg "Information" (HTML).
* @param string msg Message to display (HTML). * @param string msg Message to display (HTML).
* @param bool fadedark Remove the dark background when done? Defaults * @param bool fadedark Remove the dark background when done? Defaults
* to yes. * to yes.
* *
* @returns object Returns the div created. * @returns object Returns the div created.
*/ */
@ -121,9 +121,9 @@ phpbb.alert = function(title, msg, fadedark) {
* *
* @param string msg Message to display (HTML). * @param string msg Message to display (HTML).
* @param function callback Callback. Bool param, whether the user pressed * @param function callback Callback. Bool param, whether the user pressed
* yes or no (or whatever their language is). * yes or no (or whatever their language is).
* @param bool fadedark Remove the dark background when done? Defaults * @param bool fadedark Remove the dark background when done? Defaults
* to yes. * to yes.
* *
* @returns object Returns the div created. * @returns object Returns the div created.
*/ */
@ -232,10 +232,10 @@ phpbb.parseQuerystring = function(string) {
* *
* @param object options Options. * @param object options Options.
* @param bool/function refresh If we are sent back a refresh, should it be * @param bool/function refresh If we are sent back a refresh, should it be
* acted upon? This can either be true / false / a function. * acted upon? This can either be true / false / a function.
* @param function callback Callback to call on completion of event. Has * @param function callback Callback to call on completion of event. Has
* three parameters: the element that the event was evoked from, the JSON * three parameters: the element that the event was evoked from, the JSON
* that was returned and (if it is a form) the form action. * that was returned and (if it is a form) the form action.
*/ */
phpbb.ajaxify = function(options) { phpbb.ajaxify = function(options) {
var elements = $(options.selector), var elements = $(options.selector),
@ -252,6 +252,11 @@ phpbb.ajaxify = function(options) {
return; return;
} }
function errorHandler() {
phpbb.clearLoadingTimeout();
phpbb.alert(dark.attr('data-ajax-error-title'), dark.attr('data-ajax-error-text'));
}
/** /**
* This is a private function used to handle the callbacks, refreshes * This is a private function used to handle the callbacks, refreshes
* and alert. It calls the callback, refreshes the page if necessary, and * and alert. It calls the callback, refreshes the page if necessary, and
@ -320,13 +325,6 @@ phpbb.ajaxify = function(options) {
} }
} }
function errorHandler() {
var alert;
phpbb.clearLoadingTimeout();
alert = phpbb.alert(dark.attr('data-ajax-error-title'), dark.attr('data-ajax-error-text'));
}
// If the element is a form, POST must be used and some extra data must // If the element is a form, POST must be used and some extra data must
// be taken from the form. // be taken from the form.
var runFilter = (typeof options.filter === 'function'); var runFilter = (typeof options.filter === 'function');
@ -355,8 +353,7 @@ phpbb.ajaxify = function(options) {
return; return;
} }
if (overlay && (typeof $this.attr('data-overlay') === 'undefined' || $this.attr('data-overlay') == 'true')) if (overlay && (typeof $this.attr('data-overlay') === 'undefined' || $this.attr('data-overlay') === 'true')) {
{
phpbb.loadingAlert(); phpbb.loadingAlert();
} }
@ -389,7 +386,7 @@ phpbb.ajaxify = function(options) {
* @param bool keepSelection Shall we keep the value selected, or shall the user be forced to repick one. * @param bool keepSelection Shall we keep the value selected, or shall the user be forced to repick one.
*/ */
phpbb.timezoneSwitchDate = function(keepSelection) { phpbb.timezoneSwitchDate = function(keepSelection) {
if ($('#timezone_copy').length == 0) { if ($('#timezone_copy').length === 0) {
// We make a backup of the original dropdown, so we can remove optgroups // We make a backup of the original dropdown, so we can remove optgroups
// instead of setting display to none, because IE and chrome will not // instead of setting display to none, because IE and chrome will not
// hide options inside of optgroups and selects via css // hide options inside of optgroups and selects via css
@ -399,17 +396,17 @@ phpbb.timezoneSwitchDate = function(keepSelection) {
$('#timezone').replaceWith($('#timezone_copy').clone().attr('id', 'timezone').css('display', 'block').attr('name', 'tz')); $('#timezone').replaceWith($('#timezone_copy').clone().attr('id', 'timezone').css('display', 'block').attr('name', 'tz'));
} }
if ($('#tz_date').val() != '') { if ($('#tz_date').val() !== '') {
$('#timezone > optgroup').remove(":not([label='" + $('#tz_date').val() + "'])"); $('#timezone > optgroup').remove(":not([label='" + $('#tz_date').val() + "'])");
} }
if ($('#tz_date').val() == $('#tz_select_date_suggest').attr('data-suggested-tz')) { if ($('#tz_date').val() === $('#tz_select_date_suggest').attr('data-suggested-tz')) {
$('#tz_select_date_suggest').css('display', 'none'); $('#tz_select_date_suggest').css('display', 'none');
} else { } else {
$('#tz_select_date_suggest').css('display', 'inline'); $('#tz_select_date_suggest').css('display', 'inline');
} }
if ($("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option").size() == 1) { if ($("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option").size() === 1) {
// If there is only one timezone for the selected date, we just select that automatically. // If there is only one timezone for the selected date, we just select that automatically.
$("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option:first").attr('selected', true); $("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option:first").attr('selected', true);
keepSelection = true; keepSelection = true;
@ -440,12 +437,11 @@ phpbb.timezonePreselectSelect = function(forceSelector) {
// The offset returned here is in minutes and negated. // The offset returned here is in minutes and negated.
// http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp // http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp
var offset = (new Date()).getTimezoneOffset(); var offset = (new Date()).getTimezoneOffset();
var sign = '-';
if (offset < 0) { if (offset < 0) {
var sign = '+'; sign = '+';
offset = -offset; offset = -offset;
} else {
var sign = '-';
} }
var minutes = offset % 60; var minutes = offset % 60;
@ -466,12 +462,13 @@ phpbb.timezonePreselectSelect = function(forceSelector) {
var prefix = 'GMT' + sign + hours + ':' + minutes; var prefix = 'GMT' + sign + hours + ':' + minutes;
var prefixLength = prefix.length; var prefixLength = prefix.length;
var selectorOptions = $('#tz_date > option'); var selectorOptions = $('#tz_date > option');
var i;
for (var i = 0; i < selectorOptions.length; ++i) { for (i = 0; i < selectorOptions.length; ++i) {
var option = selectorOptions[i]; var option = selectorOptions[i];
if (option.value.substring(0, prefixLength) == prefix) { if (option.value.substring(0, prefixLength) === prefix) {
if ($('#tz_date').val() != option.value && !forceSelector) { if ($('#tz_date').val() !== option.value && !forceSelector) {
// We do not select the option for the user, but notify him, // We do not select the option for the user, but notify him,
// that we would suggest a different setting. // that we would suggest a different setting.
phpbb.timezoneSwitchDate(true); phpbb.timezoneSwitchDate(true);

View file

@ -39,7 +39,7 @@ phpbb.addAjaxCallback('mark_forums_read', function(res) {
// Mark topics read if we are watching a category and showing active topics // Mark topics read if we are watching a category and showing active topics
if ($('#active_topics').length) { if ($('#active_topics').length) {
phpbb.ajaxCallbacks['mark_topics_read'].call(this, res, false); phpbb.ajaxCallbacks.mark_topics_read.call(this, res, false);
} }
// Update mark forums read links // Update mark forums read links
@ -75,7 +75,7 @@ phpbb.addAjaxCallback('mark_topics_read', function(res, update_topic_links) {
$.each(iconsArray, function(unreadClass, readClass) { $.each(iconsArray, function(unreadClass, readClass) {
$.each(iconsState, function(key, value) { $.each(iconsState, function(key, value) {
// Only topics can be hot // Only topics can be hot
if ((value == '_hot' || value == '_hot_mine') && unreadClass != 'topic_unread') { if ((value === '_hot' || value === '_hot_mine') && unreadClass !== 'topic_unread') {
return true; return true;
} }
classMap[unreadClass + value] = readClass + value; classMap[unreadClass + value] = readClass + value;
@ -217,7 +217,7 @@ $('#quick-mod-select').change(function () {
*/ */
$('#member_search').click(function () { $('#member_search').click(function () {
$('#memberlist_search').slideToggle('fast'); $('#memberlist_search').slideToggle('fast');
phpbb.ajax_callbacks['alt_text'].call(this); phpbb.ajax_callbacks.alt_text.call(this);
// Focus on the username textbox if it's available and displayed // Focus on the username textbox if it's available and displayed
if ($('#memberlist_search').is(':visible')) { if ($('#memberlist_search').is(':visible')) {
$('#username').focus(); $('#username').focus();

View file

@ -6,22 +6,21 @@
// Startup variables // Startup variables
var imageTag = false; var imageTag = false;
var theSelection = false; var theSelection = false;
var bbcodeEnabled = true; var bbcodeEnabled = true;
// Check for Browser & Platform for PC & IE specific bits // Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html // More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version var clientVer = parseInt(navigator.appVersion, 10); // Get browser version
var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1)); var is_ie = ((clientPC.indexOf('msie') !== -1) && (clientPC.indexOf('opera') === -1));
var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1)); var is_win = ((clientPC.indexOf('win') !== -1) || (clientPC.indexOf('16bit') !== -1));
var baseHeight; var baseHeight;
/** /**
* Shows the help messages in the helpline window * Shows the help messages in the helpline window
*/ */
function helpline(help) function helpline(help) {
{
document.forms[form_name].helpbox.value = help_line[help]; document.forms[form_name].helpbox.value = help_line[help];
} }
@ -29,28 +28,22 @@ function helpline(help)
* Fix a bug involving the TextRange object. From * Fix a bug involving the TextRange object. From
* http://www.frostjedi.com/terra/scripts/demo/caretBug.html * http://www.frostjedi.com/terra/scripts/demo/caretBug.html
*/ */
function initInsertions() function initInsertions() {
{
var doc; var doc;
if (document.forms[form_name]) if (document.forms[form_name]) {
{
doc = document; doc = document;
} } else {
else
{
doc = opener.document; doc = opener.document;
} }
var textarea = doc.forms[form_name].elements[text_name]; var textarea = doc.forms[form_name].elements[text_name];
if (is_ie && typeof(baseHeight) != 'number') if (is_ie && typeof(baseHeight) !== 'number') {
{
textarea.focus(); textarea.focus();
baseHeight = doc.selection.createRange().duplicate().boundingHeight; baseHeight = doc.selection.createRange().duplicate().boundingHeight;
if (!document.forms[form_name]) if (!document.forms[form_name]) {
{
document.body.focus(); document.body.focus();
} }
} }
@ -59,14 +52,10 @@ function initInsertions()
/** /**
* bbstyle * bbstyle
*/ */
function bbstyle(bbnumber) function bbstyle(bbnumber) {
{ if (bbnumber !== -1) {
if (bbnumber != -1)
{
bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]); bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]);
} } else {
else
{
insert_text('[*]'); insert_text('[*]');
document.forms[form_name].elements[text_name].focus(); document.forms[form_name].elements[text_name].focus();
} }
@ -75,53 +64,47 @@ function bbstyle(bbnumber)
/** /**
* Apply bbcodes * Apply bbcodes
*/ */
function bbfontstyle(bbopen, bbclose) function bbfontstyle(bbopen, bbclose) {
{
theSelection = false; theSelection = false;
var textarea = document.forms[form_name].elements[text_name]; var textarea = document.forms[form_name].elements[text_name];
textarea.focus(); textarea.focus();
if ((clientVer >= 4) && is_ie && is_win) if ((clientVer >= 4) && is_ie && is_win) {
{
// Get text selection // Get text selection
theSelection = document.selection.createRange().text; theSelection = document.selection.createRange().text;
if (theSelection) if (theSelection) {
{
// Add tags around selection // Add tags around selection
document.selection.createRange().text = bbopen + theSelection + bbclose; document.selection.createRange().text = bbopen + theSelection + bbclose;
document.forms[form_name].elements[text_name].focus(); document.forms[form_name].elements[text_name].focus();
theSelection = ''; theSelection = '';
return; return;
} }
} } else if (document.forms[form_name].elements[text_name].selectionEnd
else if (document.forms[form_name].elements[text_name].selectionEnd && (document.forms[form_name].elements[text_name].selectionEnd - document.forms[form_name].elements[text_name].selectionStart > 0)) && (document.forms[form_name].elements[text_name].selectionEnd - document.forms[form_name].elements[text_name].selectionStart > 0)) {
{
mozWrap(document.forms[form_name].elements[text_name], bbopen, bbclose); mozWrap(document.forms[form_name].elements[text_name], bbopen, bbclose);
document.forms[form_name].elements[text_name].focus(); document.forms[form_name].elements[text_name].focus();
theSelection = ''; theSelection = '';
return; return;
} }
//The new position for the cursor after adding the bbcode //The new position for the cursor after adding the bbcode
var caret_pos = getCaretPosition(textarea).start; var caret_pos = getCaretPosition(textarea).start;
var new_pos = caret_pos + bbopen.length; var new_pos = caret_pos + bbopen.length;
// Open tag // Open tag
insert_text(bbopen + bbclose); insert_text(bbopen + bbclose);
// Center the cursor when we don't have a selection // Center the cursor when we don't have a selection
// Gecko and proper browsers // Gecko and proper browsers
if (!isNaN(textarea.selectionStart)) if (!isNaN(textarea.selectionStart)) {
{
textarea.selectionStart = new_pos; textarea.selectionStart = new_pos;
textarea.selectionEnd = new_pos; textarea.selectionEnd = new_pos;
} }
// IE // IE
else if (document.selection) else if (document.selection) {
{
var range = textarea.createTextRange(); var range = textarea.createTextRange();
range.move("character", new_pos); range.move("character", new_pos);
range.select(); range.select();
@ -135,51 +118,41 @@ function bbfontstyle(bbopen, bbclose)
/** /**
* Insert text at position * Insert text at position
*/ */
function insert_text(text, spaces, popup) function insert_text(text, spaces, popup) {
{
var textarea; var textarea;
if (!popup) if (!popup) {
{
textarea = document.forms[form_name].elements[text_name]; textarea = document.forms[form_name].elements[text_name];
} } else {
else
{
textarea = opener.document.forms[form_name].elements[text_name]; textarea = opener.document.forms[form_name].elements[text_name];
} }
if (spaces)
{ if (spaces) {
text = ' ' + text + ' '; text = ' ' + text + ' ';
} }
// Since IE9, IE also has textarea.selectionStart, but it still needs to be treated the old way. // Since IE9, IE also has textarea.selectionStart, but it still needs to be treated the old way.
// Therefore we simply add a !is_ie here until IE fixes the text-selection completely. // Therefore we simply add a !is_ie here until IE fixes the text-selection completely.
if (!isNaN(textarea.selectionStart) && !is_ie) if (!isNaN(textarea.selectionStart) && !is_ie) {
{
var sel_start = textarea.selectionStart; var sel_start = textarea.selectionStart;
var sel_end = textarea.selectionEnd; var sel_end = textarea.selectionEnd;
mozWrap(textarea, text, ''); mozWrap(textarea, text, '');
textarea.selectionStart = sel_start + text.length; textarea.selectionStart = sel_start + text.length;
textarea.selectionEnd = sel_end + text.length; textarea.selectionEnd = sel_end + text.length;
} } else if (textarea.createTextRange && textarea.caretPos) {
else if (textarea.createTextRange && textarea.caretPos) if (baseHeight !== textarea.caretPos.boundingHeight) {
{
if (baseHeight != textarea.caretPos.boundingHeight)
{
textarea.focus(); textarea.focus();
storeCaret(textarea); storeCaret(textarea);
} }
var caret_pos = textarea.caretPos; var caret_pos = textarea.caretPos;
caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text; caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) === ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
} } else {
else
{
textarea.value = textarea.value + text; textarea.value = textarea.value + text;
} }
if (!popup)
{ if (!popup) {
textarea.focus(); textarea.focus();
} }
} }
@ -187,8 +160,7 @@ function insert_text(text, spaces, popup)
/** /**
* Add inline attachment at position * Add inline attachment at position
*/ */
function attach_inline(index, filename) function attach_inline(index, filename) {
{
insert_text('[attachment=' + index + ']' + filename + '[/attachment]'); insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
document.forms[form_name].elements[text_name].focus(); document.forms[form_name].elements[text_name].focus();
} }
@ -196,79 +168,57 @@ function attach_inline(index, filename)
/** /**
* Add quote text to message * Add quote text to message
*/ */
function addquote(post_id, username, l_wrote) function addquote(post_id, username, l_wrote) {
{
var message_name = 'message_' + post_id; var message_name = 'message_' + post_id;
var theSelection = ''; var theSelection = '';
var divarea = false; var divarea = false;
var i;
if (l_wrote === undefined) if (l_wrote === undefined) {
{
// Backwards compatibility // Backwards compatibility
l_wrote = 'wrote'; l_wrote = 'wrote';
} }
if (document.all) if (document.all) {
{
divarea = document.all[message_name]; divarea = document.all[message_name];
} } else {
else
{
divarea = document.getElementById(message_name); divarea = document.getElementById(message_name);
} }
// Get text selection - not only the post content :( // Get text selection - not only the post content :(
// IE9 must use the document.selection method but has the *.getSelection so we just force no IE // IE9 must use the document.selection method but has the *.getSelection so we just force no IE
if (window.getSelection && !is_ie && !window.opera) if (window.getSelection && !is_ie && !window.opera) {
{
theSelection = window.getSelection().toString(); theSelection = window.getSelection().toString();
} } else if (document.getSelection && !is_ie) {
else if (document.getSelection && !is_ie)
{
theSelection = document.getSelection(); theSelection = document.getSelection();
} } else if (document.selection) {
else if (document.selection)
{
theSelection = document.selection.createRange().text; theSelection = document.selection.createRange().text;
} }
if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null) if (theSelection === '' || typeof theSelection === 'undefined' || theSelection === null) {
{ if (divarea.innerHTML) {
if (divarea.innerHTML)
{
theSelection = divarea.innerHTML.replace(/<br>/ig, '\n'); theSelection = divarea.innerHTML.replace(/<br>/ig, '\n');
theSelection = theSelection.replace(/<br\/>/ig, '\n'); theSelection = theSelection.replace(/<br\/>/ig, '\n');
theSelection = theSelection.replace(/&lt\;/ig, '<'); theSelection = theSelection.replace(/&lt\;/ig, '<');
theSelection = theSelection.replace(/&gt\;/ig, '>'); theSelection = theSelection.replace(/&gt\;/ig, '>');
theSelection = theSelection.replace(/&amp\;/ig, '&'); theSelection = theSelection.replace(/&amp\;/ig, '&');
theSelection = theSelection.replace(/&nbsp\;/ig, ' '); theSelection = theSelection.replace(/&nbsp\;/ig, ' ');
} } else if (document.all) {
else if (document.all)
{
theSelection = divarea.innerText; theSelection = divarea.innerText;
} } else if (divarea.textContent) {
else if (divarea.textContent)
{
theSelection = divarea.textContent; theSelection = divarea.textContent;
} } else if (divarea.firstChild.nodeValue) {
else if (divarea.firstChild.nodeValue)
{
theSelection = divarea.firstChild.nodeValue; theSelection = divarea.firstChild.nodeValue;
} }
} }
if (theSelection) if (theSelection) {
{ if (bbcodeEnabled) {
if (bbcodeEnabled)
{
insert_text('[quote="' + username + '"]' + theSelection + '[/quote]'); insert_text('[quote="' + username + '"]' + theSelection + '[/quote]');
} } else {
else
{
insert_text(username + ' ' + l_wrote + ':' + '\n'); insert_text(username + ' ' + l_wrote + ':' + '\n');
var lines = split_lines(theSelection); var lines = split_lines(theSelection);
for (i = 0; i < lines.length; i++) for (i = 0; i < lines.length; i++) {
{
insert_text('> ' + lines[i] + '\n'); insert_text('> ' + lines[i] + '\n');
} }
} }
@ -277,54 +227,47 @@ function addquote(post_id, username, l_wrote)
return; return;
} }
function split_lines(text) function split_lines(text) {
{
var lines = text.split('\n'); var lines = text.split('\n');
var splitLines = new Array(); var splitLines = new Array();
var j = 0; var j = 0;
for(i = 0; i < lines.length; i++) var i;
{
if (lines[i].length <= 80) for(i = 0; i < lines.length; i++) {
{ if (lines[i].length <= 80) {
splitLines[j] = lines[i]; splitLines[j] = lines[i];
j++; j++;
} } else {
else
{
var line = lines[i]; var line = lines[i];
do var splitAt;
{ do {
var splitAt = line.indexOf(' ', 80); splitAt = line.indexOf(' ', 80);
if (splitAt == -1) if (splitAt === -1) {
{
splitLines[j] = line; splitLines[j] = line;
j++; j++;
} } else {
else
{
splitLines[j] = line.substring(0, splitAt); splitLines[j] = line.substring(0, splitAt);
line = line.substring(splitAt); line = line.substring(splitAt);
j++; j++;
} }
} }
while(splitAt != -1); while(splitAt !== -1);
} }
} }
return splitLines; return splitLines;
} }
/** /**
* From http://www.massless.org/mozedit/ * From http://www.massless.org/mozedit/
*/ */
function mozWrap(txtarea, open, close) function mozWrap(txtarea, open, close) {
{ var selLength = (typeof(txtarea.textLength) === 'undefined') ? txtarea.value.length : txtarea.textLength;
var selLength = (typeof(txtarea.textLength) == 'undefined') ? txtarea.value.length : txtarea.textLength;
var selStart = txtarea.selectionStart; var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd; var selEnd = txtarea.selectionEnd;
var scrollTop = txtarea.scrollTop; var scrollTop = txtarea.scrollTop;
if (selEnd == 1 || selEnd == 2) if (selEnd === 1 || selEnd === 2) {
{
selEnd = selLength; selEnd = selLength;
} }
@ -345,10 +288,8 @@ function mozWrap(txtarea, open, close)
* Insert at Caret position. Code from * Insert at Caret position. Code from
* http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130 * http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
*/ */
function storeCaret(textEl) function storeCaret(textEl) {
{ if (textEl.createTextRange) {
if (textEl.createTextRange)
{
textEl.caretPos = document.selection.createRange().duplicate(); textEl.caretPos = document.selection.createRange().duplicate();
} }
} }
@ -356,8 +297,7 @@ function storeCaret(textEl)
/** /**
* Color pallette * Color pallette
*/ */
function colorPalette(dir, width, height) function colorPalette(dir, width, height) {
{
var r = 0, g = 0, b = 0; var r = 0, g = 0, b = 0;
var numberList = new Array(6); var numberList = new Array(6);
var color = ''; var color = '';
@ -370,89 +310,74 @@ function colorPalette(dir, width, height)
document.writeln('<table cellspacing="1" cellpadding="0" border="0">'); document.writeln('<table cellspacing="1" cellpadding="0" border="0">');
for (r = 0; r < 5; r++) for (r = 0; r < 5; r++) {
{ if (dir === 'h') {
if (dir == 'h')
{
document.writeln('<tr>'); document.writeln('<tr>');
} }
for (g = 0; g < 5; g++) for (g = 0; g < 5; g++) {
{ if (dir === 'v') {
if (dir == 'v')
{
document.writeln('<tr>'); document.writeln('<tr>');
} }
for (b = 0; b < 5; b++) for (b = 0; b < 5; b++) {
{
color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]); color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
document.write('<td bgcolor="#' + color + '" style="width: ' + width + 'px; height: ' + height + 'px;">'); document.write('<td bgcolor="#' + color + '" style="width: ' + width + 'px; height: ' + height + 'px;">');
document.write('<a href="#" onclick="bbfontstyle(\'[color=#' + color + ']\', \'[/color]\'); return false;"><img src="images/spacer.gif" width="' + width + '" height="' + height + '" alt="#' + color + '" title="#' + color + '" /></a>'); document.write('<a href="#" onclick="bbfontstyle(\'[color=#' + color + ']\', \'[/color]\'); return false;"><img src="images/spacer.gif" width="' + width + '" height="' + height + '" alt="#' + color + '" title="#' + color + '" /></a>');
document.writeln('</td>'); document.writeln('</td>');
} }
if (dir == 'v') if (dir === 'v') {
{
document.writeln('</tr>'); document.writeln('</tr>');
} }
} }
if (dir == 'h') if (dir === 'h') {
{
document.writeln('</tr>'); document.writeln('</tr>');
} }
} }
document.writeln('</table>'); document.writeln('</table>');
} }
/** /**
* Caret Position object * Caret Position object
*/ */
function caretPosition() function caretPosition() {
{
var start = null; var start = null;
var end = null; var end = null;
} }
/** /**
* Get the caret position in an textarea * Get the caret position in an textarea
*/ */
function getCaretPosition(txtarea) function getCaretPosition(txtarea) {
{
var caretPos = new caretPosition(); var caretPos = new caretPosition();
// simple Gecko/Opera way // simple Gecko/Opera way
if(txtarea.selectionStart || txtarea.selectionStart == 0) if (txtarea.selectionStart || txtarea.selectionStart === 0) {
{
caretPos.start = txtarea.selectionStart; caretPos.start = txtarea.selectionStart;
caretPos.end = txtarea.selectionEnd; caretPos.end = txtarea.selectionEnd;
} }
// dirty and slow IE way // dirty and slow IE way
else if(document.selection) else if (document.selection) {
{
// get current selection // get current selection
var range = document.selection.createRange(); var range = document.selection.createRange();
// a new selection of the whole textarea // a new selection of the whole textarea
var range_all = document.body.createTextRange(); var range_all = document.body.createTextRange();
range_all.moveToElementText(txtarea); range_all.moveToElementText(txtarea);
// calculate selection start point by moving beginning of range_all to beginning of range // calculate selection start point by moving beginning of range_all to beginning of range
var sel_start; var sel_start;
for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++) for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++) {
{
range_all.moveStart('character', 1); range_all.moveStart('character', 1);
} }
txtarea.sel_start = sel_start; txtarea.sel_start = sel_start;
// we ignore the end value for IE, this is already dirty enough and we don't need it // we ignore the end value for IE, this is already dirty enough and we don't need it
caretPos.start = txtarea.sel_start; caretPos.start = txtarea.sel_start;
caretPos.end = txtarea.sel_start; caretPos.end = txtarea.sel_start;
} }
return caretPos; return caretPos;

View file

@ -5,10 +5,8 @@
/** /**
* Window popup * Window popup
*/ */
function popup(url, width, height, name) function popup(url, width, height, name) {
{ if (!name) {
if (!name)
{
name = '_popup'; name = '_popup';
} }
@ -19,18 +17,13 @@ function popup(url, width, height, name)
/** /**
* Jump to page * Jump to page
*/ */
function jumpto() function jumpto() {
{
var page = prompt(jump_page, on_page); var page = prompt(jump_page, on_page);
if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0) if (page !== null && !isNaN(page) && page === Math.floor(page) && page > 0) {
{ if (base_url.indexOf('?') === -1) {
if (base_url.indexOf('?') == -1)
{
document.location.href = base_url + '?start=' + ((page - 1) * per_page); document.location.href = base_url + '?start=' + ((page - 1) * per_page);
} } else {
else
{
document.location.href = base_url.replace(/&amp;/g, '&') + '&start=' + ((page - 1) * per_page); document.location.href = base_url.replace(/&amp;/g, '&') + '&start=' + ((page - 1) * per_page);
} }
} }
@ -40,21 +33,17 @@ function jumpto()
* Mark/unmark checklist * Mark/unmark checklist
* id = ID of parent container, name = name prefix, state = state [true/false] * id = ID of parent container, name = name prefix, state = state [true/false]
*/ */
function marklist(id, name, state) function marklist(id, name, state) {
{
var parent = document.getElementById(id) || document[id]; var parent = document.getElementById(id) || document[id];
if (!parent) if (!parent) {
{
return; return;
} }
var rb = parent.getElementsByTagName('input'); var rb = parent.getElementsByTagName('input');
for (var r = 0; r < rb.length; r++) for (var r = 0; r < rb.length; r++) {
{ if (rb[r].name.substr(0, name.length) === name) {
if (rb[r].name.substr(0, name.length) == name)
{
rb[r].checked = state; rb[r].checked = state;
} }
} }
@ -64,25 +53,23 @@ function marklist(id, name, state)
* Resize viewable area for attached image or topic review panel (possibly others to come) * Resize viewable area for attached image or topic review panel (possibly others to come)
* e = element * e = element
*/ */
function viewableArea(e, itself) function viewableArea(e, itself) {
{ if (!e) {
if (!e) return; return;
if (!itself) }
{
if (!itself) {
e = e.parentNode; e = e.parentNode;
} }
if (!e.vaHeight) if (!e.vaHeight) {
{
// Store viewable area height before changing style to auto // Store viewable area height before changing style to auto
e.vaHeight = e.offsetHeight; e.vaHeight = e.offsetHeight;
e.vaMaxHeight = e.style.maxHeight; e.vaMaxHeight = e.style.maxHeight;
e.style.height = 'auto'; e.style.height = 'auto';
e.style.maxHeight = 'none'; e.style.maxHeight = 'none';
e.style.overflow = 'visible'; e.style.overflow = 'visible';
} } else {
else
{
// Restore viewable area height to the default // Restore viewable area height to the default
e.style.height = e.vaHeight + 'px'; e.style.height = e.vaHeight + 'px';
e.style.overflow = 'auto'; e.style.overflow = 'auto';
@ -96,53 +83,41 @@ function viewableArea(e, itself)
* s[-1,0,1] = hide,toggle display,show * s[-1,0,1] = hide,toggle display,show
* type = string: inline, block, inline-block or other CSS "display" type * type = string: inline, block, inline-block or other CSS "display" type
*/ */
function dE(n, s, type) function dE(n, s, type) {
{ if (!type) {
if (!type)
{
type = 'block'; type = 'block';
} }
var e = document.getElementById(n); var e = document.getElementById(n);
if (!s) if (!s) {
{ s = (e.style.display === '' || e.style.display === type) ? -1 : 1;
s = (e.style.display == '' || e.style.display == type) ? -1 : 1;
} }
e.style.display = (s == 1) ? type : 'none'; e.style.display = (s === 1) ? type : 'none';
} }
/** /**
* Alternate display of subPanels * Alternate display of subPanels
*/ */
function subPanels(p) function subPanels(p) {
{
var i, e, t; var i, e, t;
if (typeof(p) == 'string') if (typeof(p) === 'string') {
{
show_panel = p; show_panel = p;
} }
for (i = 0; i < panels.length; i++) for (i = 0; i < panels.length; i++) {
{
e = document.getElementById(panels[i]); e = document.getElementById(panels[i]);
t = document.getElementById(panels[i] + '-tab'); t = document.getElementById(panels[i] + '-tab');
if (e) if (e) {
{ if (panels[i] === show_panel) {
if (panels[i] == show_panel)
{
e.style.display = 'block'; e.style.display = 'block';
if (t) if (t) {
{
t.className = 'activetab'; t.className = 'activetab';
} }
} } else {
else
{
e.style.display = 'none'; e.style.display = 'none';
if (t) if (t) {
{
t.className = ''; t.className = '';
} }
} }
@ -153,14 +128,10 @@ function subPanels(p)
/** /**
* Call print preview * Call print preview
*/ */
function printPage() function printPage() {
{ if (is_ie) {
if (is_ie)
{
printPreview(); printPreview();
} } else {
else
{
window.print(); window.print();
} }
} }
@ -169,70 +140,60 @@ function printPage()
* Show/hide groups of blocks * Show/hide groups of blocks
* c = CSS style name * c = CSS style name
* e = checkbox element * e = checkbox element
* t = toggle dispay state (used to show 'grip-show' image in the profile block when hiding the profiles) * t = toggle dispay state (used to show 'grip-show' image in the profile block when hiding the profiles)
*/ */
function displayBlocks(c, e, t) function displayBlocks(c, e, t) {
{ var s = (e.checked === true) ? 1 : -1;
var s = (e.checked == true) ? 1 : -1;
if (t) if (t) {
{
s *= -1; s *= -1;
} }
var divs = document.getElementsByTagName("DIV"); var divs = document.getElementsByTagName("DIV");
for (var d = 0; d < divs.length; d++) for (var d = 0; d < divs.length; d++) {
{ if (divs[d].className.indexOf(c) === 0) {
if (divs[d].className.indexOf(c) == 0) divs[d].style.display = (s === 1) ? 'none' : 'block';
{
divs[d].style.display = (s == 1) ? 'none' : 'block';
} }
} }
} }
function selectCode(a) function selectCode(a) {
{
// Get ID of code block // Get ID of code block
var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0]; var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
var s, r;
// Not IE and IE9+ // Not IE and IE9+
if (window.getSelection) if (window.getSelection) {
{ s = window.getSelection();
var s = window.getSelection();
// Safari // Safari
if (s.setBaseAndExtent) if (s.setBaseAndExtent) {
{
s.setBaseAndExtent(e, 0, e, e.innerText.length - 1); s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
} }
// Firefox and Opera // Firefox and Opera
else else {
{
// workaround for bug # 42885 // workaround for bug # 42885
if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) == '<BR>') if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) === '<BR>') {
{
e.innerHTML = e.innerHTML + '&nbsp;'; e.innerHTML = e.innerHTML + '&nbsp;';
} }
var r = document.createRange(); r = document.createRange();
r.selectNodeContents(e); r.selectNodeContents(e);
s.removeAllRanges(); s.removeAllRanges();
s.addRange(r); s.addRange(r);
} }
} }
// Some older browsers // Some older browsers
else if (document.getSelection) else if (document.getSelection) {
{ s = document.getSelection();
var s = document.getSelection(); r = document.createRange();
var r = document.createRange();
r.selectNodeContents(e); r.selectNodeContents(e);
s.removeAllRanges(); s.removeAllRanges();
s.addRange(r); s.addRange(r);
} }
// IE // IE
else if (document.selection) else if (document.selection) {
{ r = document.body.createTextRange();
var r = document.body.createTextRange();
r.moveToElementText(e); r.moveToElementText(e);
r.select(); r.select();
} }
@ -242,25 +203,22 @@ function selectCode(a)
* Play quicktime file by determining it's width/height * Play quicktime file by determining it's width/height
* from the displayed rectangle area * from the displayed rectangle area
*/ */
function play_qt_file(obj) function play_qt_file(obj) {
{
var rectangle = obj.GetRectangle(); var rectangle = obj.GetRectangle();
var width, height;
if (rectangle) if (rectangle) {
{
rectangle = rectangle.split(','); rectangle = rectangle.split(',');
var x1 = parseInt(rectangle[0]); var x1 = parseInt(rectangle[0], 10);
var x2 = parseInt(rectangle[2]); var x2 = parseInt(rectangle[2], 10);
var y1 = parseInt(rectangle[1]); var y1 = parseInt(rectangle[1], 10);
var y2 = parseInt(rectangle[3]); var y2 = parseInt(rectangle[3], 10);
var width = (x1 < 0) ? (x1 * -1) + x2 : x2 - x1; width = (x1 < 0) ? (x1 * -1) + x2 : x2 - x1;
var height = (y1 < 0) ? (y1 * -1) + y2 : y2 - y1; height = (y1 < 0) ? (y1 * -1) + y2 : y2 - y1;
} } else {
else width = 200;
{ height = 0;
var width = 200;
var height = 0;
} }
obj.width = width; obj.width = width;
@ -274,21 +232,21 @@ function play_qt_file(obj)
* Check if the nodeName of elem is name * Check if the nodeName of elem is name
* @author jQuery * @author jQuery
*/ */
function is_node_name(elem, name) function is_node_name(elem, name) {
{ return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
} }
/** /**
* Check if elem is in array, return position * Check if elem is in array, return position
* @author jQuery * @author jQuery
*/ */
function is_in_array(elem, array) function is_in_array(elem, array) {
{ for (var i = 0, length = array.length; i < length; i++) {
for (var i = 0, length = array.length; i < length; i++)
// === is correct (IE) // === is correct (IE)
if (array[i] === elem) if (array[i] === elem) {
return i; return i;
}
}
return -1; return -1;
} }
@ -298,23 +256,26 @@ function is_in_array(elem, array)
* Not used, but may come in handy for those not using JQuery * Not used, but may come in handy for those not using JQuery
* @author jQuery.find, Meik Sievertsen * @author jQuery.find, Meik Sievertsen
*/ */
function find_in_tree(node, tag, type, class_name) function find_in_tree(node, tag, type, class_name) {
{
var result, element, i = 0, length = node.childNodes.length; var result, element, i = 0, length = node.childNodes.length;
for (element = node.childNodes[0]; i < length; element = node.childNodes[++i]) for (element = node.childNodes[0]; i < length; element = node.childNodes[++i]) {
{ if (!element || element.nodeType !== 1) {
if (!element || element.nodeType != 1) continue; continue;
}
if ((!tag || is_node_name(element, tag)) && (!type || element.type == type) && (!class_name || is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1)) if ((!tag || is_node_name(element, tag)) && (!type || element.type === type)
{ && (!class_name || is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1)) {
return element; return element;
} }
if (element.childNodes.length) if (element.childNodes.length) {
result = find_in_tree(element, tag, type, class_name); result = find_in_tree(element, tag, type, class_name);
}
if (result) return result; if (result) {
return result;
}
} }
} }
@ -324,26 +285,23 @@ var last_key_entered = '';
/** /**
* Check event key * Check event key
*/ */
function phpbb_check_key(event) function phpbb_check_key(event) {
{
// Keycode is array down or up? // Keycode is array down or up?
if (event.keyCode && (event.keyCode == 40 || event.keyCode == 38)) if (event.keyCode && (event.keyCode === 40 || event.keyCode === 38)) {
in_autocomplete = true; in_autocomplete = true;
}
// Make sure we are not within an "autocompletion" field // Make sure we are not within an "autocompletion" field
if (in_autocomplete) if (in_autocomplete) {
{
// If return pressed and key changed we reset the autocompletion // If return pressed and key changed we reset the autocompletion
if (!last_key_entered || last_key_entered == event.which) if (!last_key_entered || last_key_entered === event.which) {
{
in_autocompletion = false; in_autocompletion = false;
return true; return true;
} }
} }
// Keycode is not return, then return. ;) // Keycode is not return, then return. ;)
if (event.which != 13) if (event.which !== 13) {
{
last_key_entered = event.which; last_key_entered = event.which;
return true; return true;
} }
@ -354,34 +312,37 @@ function phpbb_check_key(event)
/** /**
* Usually used for onkeypress event, to submit a form on enter * Usually used for onkeypress event, to submit a form on enter
*/ */
function submit_default_button(event, selector, class_name) function submit_default_button(event, selector, class_name) {
{
// Add which for key events // Add which for key events
if (!event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode)) if (!event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode)) {
event.which = event.charCode || event.keyCode; event.which = event.charCode || event.keyCode;
}
if (phpbb_check_key(event)) if (phpbb_check_key(event)) {
return true; return true;
}
var current = selector['parentNode']; var current = selector.parentNode;
// Search parent form element // Search parent form element
while (current && (!current.nodeName || current.nodeType != 1 || !is_node_name(current, 'form')) && current != document) while (current && (!current.nodeName || current.nodeType !== 1 || !is_node_name(current, 'form')) && current !== document) {
current = current['parentNode']; current = current.parentNode;
}
// Find the input submit button with the class name // Find the input submit button with the class name
//current = find_in_tree(current, 'input', 'submit', class_name); //current = find_in_tree(current, 'input', 'submit', class_name);
var input_tags = current.getElementsByTagName('input'); var input_tags = current.getElementsByTagName('input');
current = false; current = false;
for (var i = 0, element = input_tags[0]; i < input_tags.length; element = input_tags[++i]) for (var i = 0, element = input_tags[0]; i < input_tags.length; element = input_tags[++i]) {
{ if (element.type === 'submit' && is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1) {
if (element.type == 'submit' && is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1)
current = element; current = element;
}
} }
if (!current) if (!current) {
return true; return true;
}
// Submit form // Submit form
current.focus(); current.focus();
@ -394,39 +355,35 @@ function submit_default_button(event, selector, class_name)
* The jQuery snippet used is based on http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/ * The jQuery snippet used is based on http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/
* The non-jQuery code is a mimick of the jQuery code ;) * The non-jQuery code is a mimick of the jQuery code ;)
*/ */
function apply_onkeypress_event() function apply_onkeypress_event() {
{
// jQuery code in case jQuery is used // jQuery code in case jQuery is used
if (jquery_present) if (jquery_present) {
{ jQuery('form input[type=text], form input[type=password]').live('keypress', function (e) {
jQuery('form input[type=text], form input[type=password]').live('keypress', function (e)
{
var default_button = jQuery(this).parents('form').find('input[type=submit].default-submit-action'); 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)) if (!default_button || default_button.length <= 0) {
return true; return true;
}
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) if (phpbb_check_key(e)) {
{ return true;
}
if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {
default_button.click(); default_button.click();
return false; return false;
} }
return true; return true;
}); });
return; return;
} }
var input_tags = document.getElementsByTagName('input'); var input_tags = document.getElementsByTagName('input');
for (var i = 0, element = input_tags[0]; i < input_tags.length ; element = input_tags[++i]) for (var i = 0, element = input_tags[0]; i < input_tags.length ; element = input_tags[++i]) {
{ if (element.type === 'text' || element.type === 'password') {
if (element.type == 'text' || element.type == 'password')
{
// onkeydown is possible too // onkeydown is possible too
element.onkeypress = function (evt) { submit_default_button((evt || window.event), this, 'default-submit-action'); }; element.onkeypress = function (evt) { submit_default_button((evt || window.event), this, 'default-submit-action'); };
} }
@ -436,4 +393,4 @@ function apply_onkeypress_event()
/** /**
* Detect JQuery existance. We currently do not deliver it, but some styles do, so why not benefit from it. ;) * Detect JQuery existance. We currently do not deliver it, but some styles do, so why not benefit from it. ;)
*/ */
var jquery_present = typeof jQuery == 'function'; var jquery_present = typeof jQuery === 'function';

View file

@ -1,5 +1,7 @@
(function($) { // Avoid conflicts with other libraries (function($) { // Avoid conflicts with other libraries
"use strict";
$('#tz_date').change(function() { $('#tz_date').change(function() {
phpbb.timezoneSwitchDate(false); phpbb.timezoneSwitchDate(false);
}); });
@ -13,7 +15,7 @@ $(document).ready(
); );
$(document).ready( $(document).ready(
phpbb.timezonePreselectSelect($('#tz_select_date_suggest').attr('timezone-preselect') == 'true') phpbb.timezonePreselectSelect($('#tz_select_date_suggest').attr('timezone-preselect') === 'true')
); );
})(jQuery); // Avoid conflicts with other libraries })(jQuery); // Avoid conflicts with other libraries

View file

@ -11,18 +11,16 @@ var bbcodeEnabled = true;
// Check for Browser & Platform for PC & IE specific bits // Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html // More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version var clientVer = parseInt(navigator.appVersion, 10); // Get browser version
var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));
var is_ie = ((clientPC.indexOf('msie') !== -1) && (clientPC.indexOf('opera') === -1));
var is_win = ((clientPC.indexOf('win') !== -1) || (clientPC.indexOf('16bit') !== -1));
var baseHeight; var baseHeight;
/** /**
* Shows the help messages in the helpline window * Shows the help messages in the helpline window
*/ */
function helpline(help) function helpline(help) {
{
document.forms[form_name].helpbox.value = help_line[help]; document.forms[form_name].helpbox.value = help_line[help];
} }
@ -30,27 +28,22 @@ function helpline(help)
* Fix a bug involving the TextRange object. From * Fix a bug involving the TextRange object. From
* http://www.frostjedi.com/terra/scripts/demo/caretBug.html * http://www.frostjedi.com/terra/scripts/demo/caretBug.html
*/ */
function initInsertions() function initInsertions() {
{
var doc; var doc;
if (document.forms[form_name]) if (document.forms[form_name]) {
{
doc = document; doc = document;
} } else {
else
{
doc = opener.document; doc = opener.document;
} }
var textarea = doc.forms[form_name].elements[text_name]; var textarea = doc.forms[form_name].elements[text_name];
if (is_ie && typeof(baseHeight) != 'number')
{ if (is_ie && typeof(baseHeight) !== 'number') {
textarea.focus(); textarea.focus();
baseHeight = doc.selection.createRange().duplicate().boundingHeight; baseHeight = doc.selection.createRange().duplicate().boundingHeight;
if (!document.forms[form_name]) if (!document.forms[form_name]) {
{
document.body.focus(); document.body.focus();
} }
} }
@ -59,14 +52,10 @@ function initInsertions()
/** /**
* bbstyle * bbstyle
*/ */
function bbstyle(bbnumber) function bbstyle(bbnumber) {
{ if (bbnumber !== -1) {
if (bbnumber != -1)
{
bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]); bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]);
} } else {
else
{
insert_text('[*]'); insert_text('[*]');
document.forms[form_name].elements[text_name].focus(); document.forms[form_name].elements[text_name].focus();
} }
@ -75,36 +64,32 @@ function bbstyle(bbnumber)
/** /**
* Apply bbcodes * Apply bbcodes
*/ */
function bbfontstyle(bbopen, bbclose) function bbfontstyle(bbopen, bbclose) {
{
theSelection = false; theSelection = false;
var textarea = document.forms[form_name].elements[text_name]; var textarea = document.forms[form_name].elements[text_name];
textarea.focus(); textarea.focus();
if ((clientVer >= 4) && is_ie && is_win) if ((clientVer >= 4) && is_ie && is_win) {
{
// Get text selection // Get text selection
theSelection = document.selection.createRange().text; theSelection = document.selection.createRange().text;
if (theSelection) if (theSelection) {
{
// Add tags around selection // Add tags around selection
document.selection.createRange().text = bbopen + theSelection + bbclose; document.selection.createRange().text = bbopen + theSelection + bbclose;
document.forms[form_name].elements[text_name].focus(); document.forms[form_name].elements[text_name].focus();
theSelection = ''; theSelection = '';
return; return;
} }
} } else if (document.forms[form_name].elements[text_name].selectionEnd
else if (document.forms[form_name].elements[text_name].selectionEnd && (document.forms[form_name].elements[text_name].selectionEnd - document.forms[form_name].elements[text_name].selectionStart > 0)) && (document.forms[form_name].elements[text_name].selectionEnd - document.forms[form_name].elements[text_name].selectionStart > 0)) {
{
mozWrap(document.forms[form_name].elements[text_name], bbopen, bbclose); mozWrap(document.forms[form_name].elements[text_name], bbopen, bbclose);
document.forms[form_name].elements[text_name].focus(); document.forms[form_name].elements[text_name].focus();
theSelection = ''; theSelection = '';
return; return;
} }
//The new position for the cursor after adding the bbcode //The new position for the cursor after adding the bbcode
var caret_pos = getCaretPosition(textarea).start; var caret_pos = getCaretPosition(textarea).start;
var new_pos = caret_pos + bbopen.length; var new_pos = caret_pos + bbopen.length;
@ -114,14 +99,12 @@ function bbfontstyle(bbopen, bbclose)
// Center the cursor when we don't have a selection // Center the cursor when we don't have a selection
// Gecko and proper browsers // Gecko and proper browsers
if (!isNaN(textarea.selectionStart)) if (!isNaN(textarea.selectionStart)) {
{
textarea.selectionStart = new_pos; textarea.selectionStart = new_pos;
textarea.selectionEnd = new_pos; textarea.selectionEnd = new_pos;
} }
// IE // IE
else if (document.selection) else if (document.selection) {
{
var range = textarea.createTextRange(); var range = textarea.createTextRange();
range.move("character", new_pos); range.move("character", new_pos);
range.select(); range.select();
@ -135,62 +118,49 @@ function bbfontstyle(bbopen, bbclose)
/** /**
* Insert text at position * Insert text at position
*/ */
function insert_text(text, spaces, popup) function insert_text(text, spaces, popup) {
{
var textarea; var textarea;
if (!popup) if (!popup) {
{
textarea = document.forms[form_name].elements[text_name]; textarea = document.forms[form_name].elements[text_name];
} } else {
else
{
textarea = opener.document.forms[form_name].elements[text_name]; textarea = opener.document.forms[form_name].elements[text_name];
} }
if (spaces)
{ if (spaces) {
text = ' ' + text + ' '; text = ' ' + text + ' ';
} }
// Since IE9, IE also has textarea.selectionStart, but it still needs to be treated the old way. // Since IE9, IE also has textarea.selectionStart, but it still needs to be treated the old way.
// Therefore we simply add a !is_ie here until IE fixes the text-selection completely. // Therefore we simply add a !is_ie here until IE fixes the text-selection completely.
if (!isNaN(textarea.selectionStart) && !is_ie) if (!isNaN(textarea.selectionStart) && !is_ie) {
{
var sel_start = textarea.selectionStart; var sel_start = textarea.selectionStart;
var sel_end = textarea.selectionEnd; var sel_end = textarea.selectionEnd;
mozWrap(textarea, text, ''); mozWrap(textarea, text, '');
textarea.selectionStart = sel_start + text.length; textarea.selectionStart = sel_start + text.length;
textarea.selectionEnd = sel_end + text.length; textarea.selectionEnd = sel_end + text.length;
} } else if (textarea.createTextRange && textarea.caretPos) {
if (baseHeight !== textarea.caretPos.boundingHeight) {
else if (textarea.createTextRange && textarea.caretPos)
{
if (baseHeight != textarea.caretPos.boundingHeight)
{
textarea.focus(); textarea.focus();
storeCaret(textarea); storeCaret(textarea);
} }
var caret_pos = textarea.caretPos; var caret_pos = textarea.caretPos;
caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text; caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) === ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
} else {
}
else
{
textarea.value = textarea.value + text; textarea.value = textarea.value + text;
} }
if (!popup)
{
textarea.focus();
}
if (!popup) {
textarea.focus();
}
} }
/** /**
* Add inline attachment at position * Add inline attachment at position
*/ */
function attach_inline(index, filename) function attach_inline(index, filename) {
{
insert_text('[attachment=' + index + ']' + filename + '[/attachment]'); insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
document.forms[form_name].elements[text_name].focus(); document.forms[form_name].elements[text_name].focus();
} }
@ -198,79 +168,57 @@ function attach_inline(index, filename)
/** /**
* Add quote text to message * Add quote text to message
*/ */
function addquote(post_id, username, l_wrote) function addquote(post_id, username, l_wrote) {
{
var message_name = 'message_' + post_id; var message_name = 'message_' + post_id;
var theSelection = ''; var theSelection = '';
var divarea = false; var divarea = false;
var i;
if (l_wrote === undefined) if (l_wrote === undefined) {
{
// Backwards compatibility // Backwards compatibility
l_wrote = 'wrote'; l_wrote = 'wrote';
} }
if (document.all) if (document.all) {
{
divarea = document.all[message_name]; divarea = document.all[message_name];
} } else {
else
{
divarea = document.getElementById(message_name); divarea = document.getElementById(message_name);
} }
// Get text selection - not only the post content :( // Get text selection - not only the post content :(
// IE9 must use the document.selection method but has the *.getSelection so we just force no IE // IE9 must use the document.selection method but has the *.getSelection so we just force no IE
if (window.getSelection && !is_ie && !window.opera) if (window.getSelection && !is_ie && !window.opera) {
{
theSelection = window.getSelection().toString(); theSelection = window.getSelection().toString();
} } else if (document.getSelection && !is_ie) {
else if (document.getSelection && !is_ie)
{
theSelection = document.getSelection(); theSelection = document.getSelection();
} } else if (document.selection) {
else if (document.selection)
{
theSelection = document.selection.createRange().text; theSelection = document.selection.createRange().text;
} }
if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null) if (theSelection === '' || typeof theSelection === 'undefined' || theSelection === null) {
{ if (divarea.innerHTML) {
if (divarea.innerHTML)
{
theSelection = divarea.innerHTML.replace(/<br>/ig, '\n'); theSelection = divarea.innerHTML.replace(/<br>/ig, '\n');
theSelection = theSelection.replace(/<br\/>/ig, '\n'); theSelection = theSelection.replace(/<br\/>/ig, '\n');
theSelection = theSelection.replace(/&lt\;/ig, '<'); theSelection = theSelection.replace(/&lt\;/ig, '<');
theSelection = theSelection.replace(/&gt\;/ig, '>'); theSelection = theSelection.replace(/&gt\;/ig, '>');
theSelection = theSelection.replace(/&amp\;/ig, '&'); theSelection = theSelection.replace(/&amp\;/ig, '&');
theSelection = theSelection.replace(/&nbsp\;/ig, ' '); theSelection = theSelection.replace(/&nbsp\;/ig, ' ');
} } else if (document.all) {
else if (document.all)
{
theSelection = divarea.innerText; theSelection = divarea.innerText;
} } else if (divarea.textContent) {
else if (divarea.textContent)
{
theSelection = divarea.textContent; theSelection = divarea.textContent;
} } else if (divarea.firstChild.nodeValue) {
else if (divarea.firstChild.nodeValue)
{
theSelection = divarea.firstChild.nodeValue; theSelection = divarea.firstChild.nodeValue;
} }
} }
if (theSelection) if (theSelection) {
{ if (bbcodeEnabled) {
if (bbcodeEnabled)
{
insert_text('[quote="' + username + '"]' + theSelection + '[/quote]'); insert_text('[quote="' + username + '"]' + theSelection + '[/quote]');
} } else {
else
{
insert_text(username + ' ' + l_wrote + ':' + '\n'); insert_text(username + ' ' + l_wrote + ':' + '\n');
var lines = split_lines(theSelection); var lines = split_lines(theSelection);
for (i = 0; i < lines.length; i++) for (i = 0; i < lines.length; i++) {
{
insert_text('> ' + lines[i] + '\n'); insert_text('> ' + lines[i] + '\n');
} }
} }
@ -279,39 +227,32 @@ function addquote(post_id, username, l_wrote)
return; return;
} }
function split_lines(text) {
function split_lines(text)
{
var lines = text.split('\n'); var lines = text.split('\n');
var splitLines = new Array(); var splitLines = new Array();
var j = 0; var j = 0;
for(i = 0; i < lines.length; i++) var i;
{
if (lines[i].length <= 80) for(i = 0; i < lines.length; i++) {
{ if (lines[i].length <= 80) {
splitLines[j] = lines[i]; splitLines[j] = lines[i];
j++; j++;
} } else {
else
{
var line = lines[i]; var line = lines[i];
do var splitAt;
{ do {
var splitAt = line.indexOf(' ', 80); splitAt = line.indexOf(' ', 80);
if (splitAt == -1) if (splitAt === -1) {
{
splitLines[j] = line; splitLines[j] = line;
j++; j++;
} } else {
else
{
splitLines[j] = line.substring(0, splitAt); splitLines[j] = line.substring(0, splitAt);
line = line.substring(splitAt); line = line.substring(splitAt);
j++; j++;
} }
} }
while(splitAt != -1); while(splitAt !== -1);
} }
} }
return splitLines; return splitLines;
@ -320,15 +261,13 @@ function split_lines(text)
/** /**
* From http://www.massless.org/mozedit/ * From http://www.massless.org/mozedit/
*/ */
function mozWrap(txtarea, open, close) function mozWrap(txtarea, open, close) {
{ var selLength = (typeof(txtarea.textLength) === 'undefined') ? txtarea.value.length : txtarea.textLength;
var selLength = (typeof(txtarea.textLength) == 'undefined') ? txtarea.value.length : txtarea.textLength;
var selStart = txtarea.selectionStart; var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd; var selEnd = txtarea.selectionEnd;
var scrollTop = txtarea.scrollTop; var scrollTop = txtarea.scrollTop;
if (selEnd == 1 || selEnd == 2) if (selEnd === 1 || selEnd === 2) {
{
selEnd = selLength; selEnd = selLength;
} }
@ -349,10 +288,8 @@ function mozWrap(txtarea, open, close)
* Insert at Caret position. Code from * Insert at Caret position. Code from
* http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130 * http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
*/ */
function storeCaret(textEl) function storeCaret(textEl) {
{ if (textEl.createTextRange) {
if (textEl.createTextRange)
{
textEl.caretPos = document.selection.createRange().duplicate(); textEl.caretPos = document.selection.createRange().duplicate();
} }
} }
@ -360,8 +297,7 @@ function storeCaret(textEl)
/** /**
* Color pallette * Color pallette
*/ */
function colorPalette(dir, width, height) function colorPalette(dir, width, height) {
{
var r = 0, g = 0, b = 0; var r = 0, g = 0, b = 0;
var numberList = new Array(6); var numberList = new Array(6);
var color = ''; var color = '';
@ -374,85 +310,71 @@ function colorPalette(dir, width, height)
document.writeln('<table cellspacing="1" cellpadding="0" border="0">'); document.writeln('<table cellspacing="1" cellpadding="0" border="0">');
for (r = 0; r < 5; r++) for (r = 0; r < 5; r++) {
{ if (dir === 'h') {
if (dir == 'h')
{
document.writeln('<tr>'); document.writeln('<tr>');
} }
for (g = 0; g < 5; g++) for (g = 0; g < 5; g++) {
{ if (dir === 'v') {
if (dir == 'v')
{
document.writeln('<tr>'); document.writeln('<tr>');
} }
for (b = 0; b < 5; b++) for (b = 0; b < 5; b++) {
{
color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]); color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
document.write('<td bgcolor="#' + color + '" style="width: ' + width + 'px; height: ' + height + 'px;">'); document.write('<td bgcolor="#' + color + '" style="width: ' + width + 'px; height: ' + height + 'px;">');
document.write('<a href="#" onclick="bbfontstyle(\'[color=#' + color + ']\', \'[/color]\'); return false;"><img src="images/spacer.gif" width="' + width + '" height="' + height + '" alt="#' + color + '" title="#' + color + '" /></a>'); document.write('<a href="#" onclick="bbfontstyle(\'[color=#' + color + ']\', \'[/color]\'); return false;"><img src="images/spacer.gif" width="' + width + '" height="' + height + '" alt="#' + color + '" title="#' + color + '" /></a>');
document.writeln('</td>'); document.writeln('</td>');
} }
if (dir == 'v') if (dir === 'v') {
{
document.writeln('</tr>'); document.writeln('</tr>');
} }
} }
if (dir == 'h') if (dir === 'h') {
{
document.writeln('</tr>'); document.writeln('</tr>');
} }
} }
document.writeln('</table>'); document.writeln('</table>');
} }
/** /**
* Caret Position object * Caret Position object
*/ */
function caretPosition() function caretPosition() {
{
var start = null; var start = null;
var end = null; var end = null;
} }
/** /**
* Get the caret position in an textarea * Get the caret position in an textarea
*/ */
function getCaretPosition(txtarea) function getCaretPosition(txtarea) {
{
var caretPos = new caretPosition(); var caretPos = new caretPosition();
// simple Gecko/Opera way // simple Gecko/Opera way
if(txtarea.selectionStart || txtarea.selectionStart == 0) if (txtarea.selectionStart || txtarea.selectionStart === 0) {
{
caretPos.start = txtarea.selectionStart; caretPos.start = txtarea.selectionStart;
caretPos.end = txtarea.selectionEnd; caretPos.end = txtarea.selectionEnd;
} }
// dirty and slow IE way // dirty and slow IE way
else if(document.selection) else if (document.selection) {
{
// get current selection // get current selection
var range = document.selection.createRange(); var range = document.selection.createRange();
// a new selection of the whole textarea // a new selection of the whole textarea
var range_all = document.body.createTextRange(); var range_all = document.body.createTextRange();
range_all.moveToElementText(txtarea); range_all.moveToElementText(txtarea);
// calculate selection start point by moving beginning of range_all to beginning of range // calculate selection start point by moving beginning of range_all to beginning of range
var sel_start; var sel_start;
for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++) for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++) {
{
range_all.moveStart('character', 1); range_all.moveStart('character', 1);
} }
txtarea.sel_start = sel_start; txtarea.sel_start = sel_start;
// we ignore the end value for IE, this is already dirty enough and we don't need it // we ignore the end value for IE, this is already dirty enough and we don't need it
caretPos.start = txtarea.sel_start; caretPos.start = txtarea.sel_start;
caretPos.end = txtarea.sel_start; caretPos.end = txtarea.sel_start;

View file

@ -1,5 +1,7 @@
(function($) { // Avoid conflicts with other libraries (function($) { // Avoid conflicts with other libraries
"use strict";
$('#tz_date').change(function() { $('#tz_date').change(function() {
phpbb.timezoneSwitchDate(false); phpbb.timezoneSwitchDate(false);
}); });