phpBB

Code Changes

File: assets/javascript/core.js

  Unmodified   Added   Modified   Removed
Line 1Line 1
 
/* global bbfontstyle */


var phpbb = {};
phpbb.alertTime = 100;


var phpbb = {};
phpbb.alertTime = 100;


Line 13Line 15
};

var $dark = $('#darkenwrapper');

};

var $dark = $('#darkenwrapper');

var $loadingIndicator = $('#loading_indicator');

var $loadingIndicator;

var phpbbAlertTimer = null;

phpbb.isTouch = (window && typeof window.ontouchstart !== 'undefined');

var phpbbAlertTimer = null;

phpbb.isTouch = (window && typeof window.ontouchstart !== 'undefined');

Line 21Line 23
/**
* Display a loading screen
*

/**
* Display a loading screen
*

 * @returns object Returns loadingIndicator.

 * @returns {object} Returns loadingIndicator.

 */
phpbb.loadingIndicator = function() {

 */
phpbb.loadingIndicator = function() {

 
	if (!$loadingIndicator) {
$loadingIndicator = $('<div />', { id: 'loading_indicator' });
$loadingIndicator.appendTo('#page-footer');
}


	if (!$loadingIndicator.is(':visible')) {
$loadingIndicator.fadeIn(phpbb.alertTime);

	if (!$loadingIndicator.is(':visible')) {
$loadingIndicator.fadeIn(phpbb.alertTime);

		// Wait fifteen seconds and display an error if nothing has been returned by then.

		// Wait 60 seconds and display an error if nothing has been returned by then.

		phpbb.clearLoadingTimeout();
phpbbAlertTimer = setTimeout(function() {

		phpbb.clearLoadingTimeout();
phpbbAlertTimer = setTimeout(function() {

 
			phpbb.showTimeoutMessage();
}, 60000);
}

return $loadingIndicator;
};

/**
* Show timeout message
*/
phpbb.showTimeoutMessage = function () {

			var $alert = $('#phpbb_alert');

if ($loadingIndicator.is(':visible')) {
phpbb.alert($alert.attr('data-l-err'), $alert.attr('data-l-timeout-processing-req'));
}

			var $alert = $('#phpbb_alert');

if ($loadingIndicator.is(':visible')) {
phpbb.alert($alert.attr('data-l-err'), $alert.attr('data-l-timeout-processing-req'));
}

		}, 15000);
}

return $loadingIndicator;

 
};

/**

};

/**

Line 54Line 68
/**
* Close popup alert after a specified delay
*

/**
* Close popup alert after a specified delay
*

* @param int Delay in ms until darkenwrapper's click event is triggered

* @param {int} delay Delay in ms until darkenwrapper's click event is triggered

*/
phpbb.closeDarkenWrapper = function(delay) {
phpbbAlertTimer = setTimeout(function() {

*/
phpbb.closeDarkenWrapper = function(delay) {
phpbbAlertTimer = setTimeout(function() {

Line 67Line 81
 *
* You can only call one alert or confirm box at any one time.
*

 *
* You can only call one alert or confirm box at any one time.
*

 * @param string title Title of the message, eg "Information" (HTML).
* @param string msg Message to display (HTML).
* @param bool fadedark Remove the dark background when done? Defaults
* to yes.

 * @param {string} title Title of the message, eg "Information" (HTML).
* @param {string} msg Message to display (HTML).



 *

 *

 * @returns object Returns the div created.

 * @returns {object} Returns the div created.

 */

 */

phpbb.alert = function(title, msg, fadedark) {

phpbb.alert = function(title, msg) {

	var $alert = $('#phpbb_alert');
$alert.find('.alert_title').html(title);
$alert.find('.alert_text').html(msg);

	var $alert = $('#phpbb_alert');
$alert.find('.alert_title').html(title);
$alert.find('.alert_text').html(msg);

Line 94Line 106
/**
* Handler for opening an alert box.
*

/**
* Handler for opening an alert box.
*

* @param jQuery $alert			jQuery object.

* @param {jQuery} $alert jQuery object.

*/
phpbb.alert.open = function($alert) {
if (!$dark.is(':visible')) {
$dark.fadeIn(phpbb.alertTime);
}


*/
phpbb.alert.open = function($alert) {
if (!$dark.is(':visible')) {
$dark.fadeIn(phpbb.alertTime);
}


	if ($loadingIndicator.is(':visible')) {

	if ($loadingIndicator && $loadingIndicator.is(':visible')) {

		$loadingIndicator.fadeOut(phpbb.alertTime, function() {
$dark.append($alert);
$alert.fadeIn(phpbb.alertTime);

		$loadingIndicator.fadeOut(phpbb.alertTime, function() {
$dark.append($alert);
$alert.fadeIn(phpbb.alertTime);

Line 134Line 146
/**
* Handler for closing an alert box.
*

/**
* Handler for closing an alert box.
*

* @param jQuery $alert			jQuery object.
* @param bool fadedark Whether to remove dark background.

* @param {jQuery} $alert jQuery object.
* @param {bool} fadedark Whether to remove dark background.

*/
phpbb.alert.close = function($alert, fadedark) {
var $fade = (fadedark) ? $dark : $alert;

*/
phpbb.alert.close = function($alert, fadedark) {
var $fade = (fadedark) ? $dark : $alert;

Line 153Line 165
 *
* You can only call one alert or confirm box at any one time.
*

 *
* You can only call one alert or confirm box at any one time.
*

 * @param string msg Message to display (HTML).
* @param function callback Callback. Bool param, whether the user pressed

 * @param {string} msg Message to display (HTML).
* @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.

 */
phpbb.confirm = function(msg, callback, fadedark) {
var $confirmDiv = $('#phpbb_confirm');

 */
phpbb.confirm = function(msg, callback, fadedark) {
var $confirmDiv = $('#phpbb_confirm');

Line 197Line 209
/**
* Turn a querystring into an array.
*

/**
* Turn a querystring into an array.
*

 * @argument string string The querystring to parse.
* @returns object The object created.

 * @argument {string} string The querystring to parse.
* @returns {object} The object created.

 */
phpbb.parseQuerystring = function(string) {
var params = {}, i, split;

 */
phpbb.parseQuerystring = function(string) {
var params = {}, i, split;

Line 223Line 235
 * For more info, view the following page on the phpBB wiki:
* http://wiki.phpbb.com/JavaScript_Function.phpbb.ajaxify
*

 * For more info, view the following page on the phpBB wiki:
* http://wiki.phpbb.com/JavaScript_Function.phpbb.ajaxify
*

 * @param object options Options.
* @param bool/function refresh If we are sent back a refresh, should it be
* acted upon? This can either be true / false / a function.
* @param function callback Callback to call on completion of event. Has
* three parameters: the element that the event was evoked from, the JSON
* that was returned and (if it is a form) the form action.

 * @param {object} options Options.






 */
phpbb.ajaxify = function(options) {
var $elements = $(options.selector),

 */
phpbb.ajaxify = function(options) {
var $elements = $(options.selector),

Line 262Line 269
				console.log('AJAX error. status: ' + textStatus + ', message: ' + errorThrown);
}
phpbb.clearLoadingTimeout();

				console.log('AJAX error. status: ' + textStatus + ', message: ' + errorThrown);
}
phpbb.clearLoadingTimeout();

			var errorText = false;
if (typeof errorThrown === 'string' && errorThrown.length > 0) {







			var responseText, errorText = false;
try {
responseText = JSON.parse(jqXHR.responseText);
responseText = responseText.message;
} catch (e) {}
if (typeof responseText === 'string' && responseText.length > 0) {
errorText = responseText;
} else if (typeof errorThrown === 'string' && errorThrown.length > 0) {

				errorText = errorThrown;

				errorText = errorThrown;

			}
else {

			} else {


				errorText = $dark.attr('data-ajax-error-text-' + textStatus);
if (typeof errorText !== 'string' || !errorText.length) {
errorText = $dark.attr('data-ajax-error-text');

				errorText = $dark.attr('data-ajax-error-text-' + textStatus);
if (typeof errorText !== 'string' || !errorText.length) {
errorText = $dark.attr('data-ajax-error-text');

Line 283Line 295
		 * It cannot be called from outside this function, and is purely here to
* avoid repetition of code.
*

		 * It cannot be called from outside this function, and is purely here to
* avoid repetition of code.
*

		 * @param object res The object sent back by the server.

		 * @param {object} res The object sent back by the server.

		 */
function returnHandler(res) {
var alert;

		 */
function returnHandler(res) {
var alert;

Line 298Line 310
					alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
} else {
$dark.fadeOut(phpbb.alertTime);

					alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
} else {
$dark.fadeOut(phpbb.alertTime);

 

if ($loadingIndicator) {
$loadingIndicator.fadeOut(phpbb.alertTime);
}

				}

if (typeof phpbb.ajaxCallbacks[callback] === 'function') {

				}

if (typeof phpbb.ajaxCallbacks[callback] === 'function') {

Line 386Line 402
				type: method,
data: data,
success: returnHandler,

				type: method,
data: data,
success: returnHandler,

				error: errorHandler


				error: errorHandler,
cache: false

			});

			});

 


			request.always(function() {

			request.always(function() {

 
				if ($loadingIndicator && $loadingIndicator.is(':visible')) {

				$loadingIndicator.fadeOut(phpbb.alertTime);

				$loadingIndicator.fadeOut(phpbb.alertTime);

 
				}

			});
};


			});
};


Line 407Line 427
		$elements.find('input:submit').click(function () {
var $this = $(this);


		$elements.find('input:submit').click(function () {
var $this = $(this);


			$this.siblings('[data-clicked]').removeAttr('data-clicked');



			// Remove data-clicked attribute from any submit button of form
$this.parents('form:first').find('input:submit[data-clicked]').removeAttr('data-clicked');


			$this.attr('data-clicked', 'true');
});
}

			$this.attr('data-clicked', 'true');
});
}

Line 426Line 448
/**
* Get cached search data.
*

/**
* Get cached search data.
*

 * @param string id		Search ID.
* @return bool|object. Cached data object. Returns false if no data exists.

 * @param {string} id Search ID.
* @returns {bool|object} Cached data object. Returns false if no data exists.

 */
phpbb.search.cache.get = function(id) {
if (this.data[id]) {

 */
phpbb.search.cache.get = function(id) {
if (this.data[id]) {

Line 439Line 461
/**
* Set search cache data value.
*

/**
* Set search cache data value.
*

 * @param string id		Search ID.
* @param string key Data key.
* @param string value Data value.
*
* @return undefined

 * @param {string} id		Search ID.
* @param {string} key Data key.
* @param {string} value Data value.



 */
phpbb.search.cache.set = function(id, key, value) {
if (!this.data[id]) {

 */
phpbb.search.cache.set = function(id, key, value) {
if (!this.data[id]) {

		this.data[id] = {results: []};

		this.data[id] = { results: [] };

	}
this.data[id][key] = value;
};

	}
this.data[id][key] = value;
};

Line 455Line 475
/**
* Cache search result.
*

/**
* Cache search result.
*

 * @param string id			Search ID.
* @param string keyword Keyword.
* @param array results Search results.
*
* @return undefined

 * @param {string} id		Search ID.
* @param {string} keyword Keyword.
* @param {Array} results Search results.



 */

 */

phpbb.search.cache.setResults = function(id, keyword, value) {
this.data[id].results[keyword] = value;

phpbb.search.cache.setResults = function(id, keyword, results) {
this.data[id].results[keyword] = results;

};

/**
* Trim spaces from keyword and lower its case.
*

};

/**
* Trim spaces from keyword and lower its case.
*

 * @param string keyword	Search keyword to clean.
* @return string Cleaned string.

 * @param {string} keyword Search keyword to clean.
* @returns {string} Cleaned string.

 */
phpbb.search.cleanKeyword = function(keyword) {
return $.trim(keyword).toLowerCase();

 */
phpbb.search.cleanKeyword = function(keyword) {
return $.trim(keyword).toLowerCase();

Line 479Line 497
 * Get clean version of search keyword. If textarea supports several keywords
* (one per line), it fetches the current keyword based on the caret position.
*

 * Get clean version of search keyword. If textarea supports several keywords
* (one per line), it fetches the current keyword based on the caret position.
*

 * @param jQuery $input		Search input|textarea.
* @param string keyword Input|textarea value.
* @param bool multiline Whether textarea supports multiple search keywords.

 * @param {jQuery} $input	Search input|textarea.
* @param {string} keyword Input|textarea value.
* @param {bool} multiline Whether textarea supports multiple search keywords.

 *

 *

 * @return string Clean string.

 * @returns string Clean string.

 */
phpbb.search.getKeyword = function($input, keyword, multiline) {
if (multiline) {

 */
phpbb.search.getKeyword = function($input, keyword, multiline) {
if (multiline) {

Line 497Line 515
 * Get the textarea line number on which the keyword resides - for textareas
* that support multiple keywords (one per line).
*

 * Get the textarea line number on which the keyword resides - for textareas
* that support multiple keywords (one per line).
*

 * @param jQuery $textarea	Search textarea.
* @return int

 * @param {jQuery} $textarea Search textarea.
* @returns {int} The line number.

 */
phpbb.search.getKeywordLine = function ($textarea) {
var selectionStart = $textarea.get(0).selectionStart;

 */
phpbb.search.getKeywordLine = function ($textarea) {
var selectionStart = $textarea.get(0).selectionStart;

Line 509Line 527
 * Set the value on the input|textarea. If textarea supports multiple
* keywords, only the active keyword is replaced.
*

 * Set the value on the input|textarea. If textarea supports multiple
* keywords, only the active keyword is replaced.
*

 * @param jQuery $input		Search input|textarea.
* @param string value Value to set.
* @param bool multiline Whether textarea supports multiple search keywords.
*
* @return undefined

 * @param {jQuery} $input	Search input|textarea.
* @param {string} value Value to set.
* @param {bool} multiline Whether textarea supports multiple search keywords.



 */
phpbb.search.setValue = function($input, value, multiline) {
if (multiline) {

 */
phpbb.search.setValue = function($input, value, multiline) {
if (multiline) {

Line 526Line 542
};

/**

};

/**

 * Sets the onclick event to set the value on the input|textarea to the selected search result. 


 * Sets the onclick event to set the value on the input|textarea to the
* selected search result.

 *

 *

 * @param jQuery $input		Search input|textarea.
* @param object value Result object.
* @param jQuery $row Result element.
* @param jQuery $container jQuery object for the search container.
*
* @return undefined

 * @param {jQuery} $input		Search input|textarea.
* @param {object} value Result object.
* @param {jQuery} $row Result element.
* @param {jQuery} $container jQuery object for the search container.



 */
phpbb.search.setValueOnClick = function($input, value, $row, $container) {
$row.click(function() {

 */
phpbb.search.setValueOnClick = function($input, value, $row, $container) {
$row.click(function() {

Line 548Line 563
 * already, those are displayed instead. Executes the AJAX request function
* itself due to the need to use a timeout to limit the number of requests.
*

 * already, those are displayed instead. Executes the AJAX request function
* itself due to the need to use a timeout to limit the number of requests.
*

 * @param array data			Data to be sent to the server.
* @param object event Onkeyup event object.
* @param function sendRequest Function to execute AJAX request.

 * @param {Array} data				Data to be sent to the server.
* @param {object} event Onkeyup event object.
* @param {function} sendRequest Function to execute AJAX request.

 *

 *

 * @return bool Returns false.

 * @returns {bool} Returns false.

 */
phpbb.search.filter = function(data, event, sendRequest) {
var $this = $(this),
dataName = ($this.attr('data-name') !== undefined) ? $this.attr('data-name') : $this.attr('name'),

 */
phpbb.search.filter = function(data, event, sendRequest) {
var $this = $(this),
dataName = ($this.attr('data-name') !== undefined) ? $this.attr('data-name') : $this.attr('name'),

		minLength = parseInt($this.attr('data-min-length')),

		minLength = parseInt($this.attr('data-min-length'), 10),

		searchID = $this.attr('data-results'),
keyword = phpbb.search.getKeyword($this, data[dataName], $this.attr('data-multiline')),
cache = phpbb.search.cache.get(searchID),

		searchID = $this.attr('data-results'),
keyword = phpbb.search.getKeyword($this, data[dataName], $this.attr('data-multiline')),
cache = phpbb.search.cache.get(searchID),

Line 579Line 594
			} else {
// Do we already have results for this?
if (cache.results[keyword]) {

			} else {
// Do we already have results for this?
if (cache.results[keyword]) {

					var response = {keyword: keyword, results: cache.results[keyword]};




					var response = {
keyword: keyword,
results: cache.results[keyword]
};

					phpbb.search.handleResponse(response, $this, true);
proceed = false;
}

					phpbb.search.handleResponse(response, $this, true);
proceed = false;
}

Line 606Line 624
/**
* Handle search result response.
*

/**
* Handle search result response.
*

 * @param object res		Data received from server.
* @param jQuery $input Search input|textarea.
* @param bool fromCache Whether the results are from the cache.
* @param function callback Optional callback to run when assigning each search result.
*
* @return undefined

 * @param {object} res			Data received from server.
* @param {jQuery} $input Search input|textarea.
* @param {bool} fromCache Whether the results are from the cache.
* @param {function} callback Optional callback to run when assigning each search result.



 */
phpbb.search.handleResponse = function(res, $input, fromCache, callback) {
if (typeof res !== 'object') {

 */
phpbb.search.handleResponse = function(res, $input, fromCache, callback) {
if (typeof res !== 'object') {

Line 638Line 654
/**
* Show search results.
*

/**
* Show search results.
*

 * @param array results		Search results.
* @param jQuery $input Search input|textarea.
* @param jQuery $container Search results container element.
* @param function callback Optional callback to run when assigning each search result.
*
* @return undefined

 * @param {Array} results		Search results.
* @param {jQuery} $input Search input|textarea.
* @param {jQuery} $container Search results container element.
* @param {function} callback Optional callback to run when assigning each search result.



 */
phpbb.search.showResults = function(results, $input, $container, callback) {
var $resultContainer = $('.search-results', $container);

 */
phpbb.search.showResults = function(results, $input, $container, callback) {
var $resultContainer = $('.search-results', $container);

Line 680Line 694
/**
* Clear search results.
*

/**
* Clear search results.
*

 * @param jQuery $container	Search results container.
* @return undefined

 * @param {jQuery} $container Search results container.


 */
phpbb.search.clearResults = function($container) {
$container.children(':not(.search-result-tpl)').remove();

 */
phpbb.search.clearResults = function($container) {
$container.children(':not(.search-result-tpl)').remove();

Line 700Line 713
/**
* Check whether a method in the native history object is supported.
*

/**
* Check whether a method in the native history object is supported.
*

* @param string fn	Method name.
* @return bool Returns true if the method is supported.

* @param {string} fn Method name.
* @returns {bool} Returns true if the method is supported.

*/
phpbb.history.isSupported = function(fn) {
return !(typeof history === 'undefined' || typeof history[fn] === 'undefined');

*/
phpbb.history.isSupported = function(fn) {
return !(typeof history === 'undefined' || typeof history[fn] === 'undefined');

Line 711Line 724
* Wrapper for the pushState and replaceState methods of the
* native history object.
*

* Wrapper for the pushState and replaceState methods of the
* native history object.
*

* @param string mode	Mode. Either push or replace.
* @param string url New URL.
* @param string title Optional page title.
* @patam object obj Optional state object.
*
* @return undefined

* @param {string} mode		Mode. Either push or replace.
* @param {string} url New URL.
* @param {string} [title] Optional page title.
* @param {object} [obj] Optional state object.



*/
phpbb.history.alterUrl = function(mode, url, title, obj) {
var fn = mode + 'State';

*/
phpbb.history.alterUrl = function(mode, url, title, obj) {
var fn = mode + 'State';

Line 737Line 748
/**
* Wrapper for the native history.replaceState method.
*

/**
* Wrapper for the native history.replaceState method.
*

* @param string url	New URL.
* @param string title Optional page title.
* @patam object obj Optional state object.
*
* @return undefined

* @param {string} url		New URL.
* @param {string} [title] Optional page title.
* @param {object} [obj] Optional state object.



*/
phpbb.history.replaceUrl = function(url, title, obj) {
phpbb.history.alterUrl('replace', url, title, obj);

*/
phpbb.history.replaceUrl = function(url, title, obj) {
phpbb.history.alterUrl('replace', url, title, obj);

Line 750Line 759
/**
* Wrapper for the native history.pushState method.
*

/**
* Wrapper for the native history.pushState method.
*

* @param string url	New URL.
* @param string title Optional page title.
* @patam object obj Optional state object.
*
* @return undefined

* @param {string} url		New URL.
* @param {string} [title] Optional page title.
* @param {object} [obj] Optional state object.



*/
phpbb.history.pushUrl = function(url, title, obj) {
phpbb.history.alterUrl('push', url, title, obj);

*/
phpbb.history.pushUrl = function(url, title, obj) {
phpbb.history.alterUrl('push', url, title, obj);

Line 763Line 770
/**
* Hide the optgroups that are not the selected timezone
*

/**
* Hide the optgroups that are not the selected timezone
*

* @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) {
var $timezoneCopy = $('#timezone_copy');

*/
phpbb.timezoneSwitchDate = function(keepSelection) {
var $timezoneCopy = $('#timezone_copy');

Line 786Line 794
	}

if ($tzDate.val() !== '') {

	}

if ($tzDate.val() !== '') {

		$timezone.children('optgroup').remove(':not([data-tz-value="' + $('#tz_date').val() + '"])');

		$timezone.children('optgroup').remove(':not([data-tz-value="' + $tzDate.val() + '"])');

	}

if ($tzDate.val() === $tzSelectDateSuggest.attr('data-suggested-tz')) {

	}

if ($tzDate.val() === $tzSelectDateSuggest.attr('data-suggested-tz')) {

Line 821Line 829
/**
* Preselect a date/time or suggest one, if it is not picked.
*

/**
* Preselect a date/time or suggest one, if it is not picked.
*

* @param	bool	forceSelector		Shall we select the suggestion?

* @param {bool} forceSelector Shall we select the suggestion?

*/
phpbb.timezonePreselectSelect = function(forceSelector) {


*/
phpbb.timezonePreselectSelect = function(forceSelector) {


Line 890Line 898
 *
* See the phpbb.ajaxify comments for information on stuff like parameters.
*

 *
* See the phpbb.ajaxify comments for information on stuff like parameters.
*

 * @param string id The name of the callback.
* @param function callback The callback to be called.

 * @param {string} id The name of the callback.
* @param {function} callback The callback to be called.

 */
phpbb.addAjaxCallback = function(id, callback) {
if (typeof callback === 'function') {

 */
phpbb.addAjaxCallback = function(id, callback) {
if (typeof callback === 'function') {

Line 982Line 990
* types text.
*
* @param {jQuery} $items jQuery object(s) to resize

* types text.
*
* @param {jQuery} $items jQuery object(s) to resize

* @param {object} options Optional parameter that adjusts default

* @param {object} [options] Optional parameter that adjusts default

* 	configuration. See configuration variable
*
* Optional parameters:

* 	configuration. See configuration variable
*
* Optional parameters:

Line 1019Line 1027
	function resetAutoResize(item) {
var $item = $(item);
if ($item.hasClass('auto-resized')) {

	function resetAutoResize(item) {
var $item = $(item);
if ($item.hasClass('auto-resized')) {

			$(item).css({height: '', resize: ''}).removeClass('auto-resized');



			$(item)
.css({ height: '', resize: '' })
.removeClass('auto-resized');

			configuration.resetCallback.call(item, $item);
}
}

function autoResize(item) {
function setHeight(height) {

			configuration.resetCallback.call(item, $item);
}
}

function autoResize(item) {
function setHeight(height) {

			height += parseInt($item.css('height')) - $item.height();
$item.css({height: height + 'px', resize: 'none'}).addClass('auto-resized');



			height += parseInt($item.css('height'), 10) - $item.innerHeight();
$item
.css({ height: height + 'px', resize: 'none' })
.addClass('auto-resized');

			configuration.resizeCallback.call(item, $item);
}


			configuration.resizeCallback.call(item, $item);
}


Line 1043Line 1055
				configuration.maxHeight
),
$item = $(item),

				configuration.maxHeight
),
$item = $(item),

			height = parseInt($item.height()),

			height = parseInt($item.innerHeight(), 10),

			scrollHeight = (item.scrollHeight) ? item.scrollHeight : 0;

if (height < 0) {

			scrollHeight = (item.scrollHeight) ? item.scrollHeight : 0;

if (height < 0) {

Line 1052Line 1064

if (height > maxHeight) {
setHeight(maxHeight);


if (height > maxHeight) {
setHeight(maxHeight);

		}
else if (scrollHeight > (height + 5)) {

		} else if (scrollHeight > (height + 5)) {


			setHeight(Math.min(maxHeight, scrollHeight));
}
}

			setHeight(Math.min(maxHeight, scrollHeight));
}
}

Line 1082Line 1093
* @param {Array} endTags List of end tags to look for
* For example, Array('[/code]')
*

* @param {Array} endTags List of end tags to look for
* For example, Array('[/code]')
*

* @return {boolean} True if cursor is in bbcode tag

* @returns {boolean} True if cursor is in bbcode tag

*/
phpbb.inBBCodeTag = function(textarea, startTags, endTags) {
var start = textarea.selectionStart,

*/
phpbb.inBBCodeTag = function(textarea, startTags, endTags) {
var start = textarea.selectionStart,

Line 1154Line 1165
	* @param {boolean} stripCodeStart If true, only part of line
* after [code] tag will be returned.
*

	* @param {boolean} stripCodeStart If true, only part of line
* after [code] tag will be returned.
*

	* @return {string} Line of text

	* @returns {string} Line of text

	*/
function getLastLine(stripCodeStart) {
var start = textarea.selectionStart,

	*/
function getLastLine(stripCodeStart) {
var start = textarea.selectionStart,

Line 1170Line 1181
					var tagLength = startTags[i].length;

value = value.substring(index + tagLength);

					var tagLength = startTags[i].length;

value = value.substring(index + tagLength);

					if (startTags[i].lastIndexOf(startTagsEnd) != tagLength) {

					if (startTags[i].lastIndexOf(startTagsEnd) !== tagLength) {

						index = value.indexOf(startTagsEnd);

if (index >= 0) {

						index = value.indexOf(startTagsEnd);

if (index >= 0) {

Line 1187Line 1198
	/**
* Append text at cursor position
*

	/**
* Append text at cursor position
*

	* @param {string} Text Text to append

	* @param {string} text Text to append

	*/
function appendText(text) {
var start = textarea.selectionStart,

	*/
function appendText(text) {
var start = textarea.selectionStart,

Line 1226Line 1237
				}
}
}

				}
}
}

 
	});
};

/**
* Show drag and drop animation when textarea is present
*
* This function will enable the drag and drop animation for a specified
* textarea.
*
* @param {HTMLElement} textarea Textarea DOM object to apply editor to
*/
phpbb.showDragNDrop = function(textarea) {
if (!textarea) {
return;
}

$('body').on('dragenter dragover', function () {
$(textarea).addClass('drag-n-drop');
}).on('dragleave dragout dragend drop', function() {
$(textarea).removeClass('drag-n-drop');
});
$(textarea).on('dragenter dragover', function () {
$(textarea).addClass('drag-n-drop-highlight');
}).on('dragleave dragout dragend drop', function() {
$(textarea).removeClass('drag-n-drop-highlight');

	});
};


	});
};


Line 1321Line 1357
					fullFreeSpace = freeSpace + parent.outerWidth();

options.dropdown.find('.dropdown-contents').each(function() {

					fullFreeSpace = freeSpace + parent.outerWidth();

options.dropdown.find('.dropdown-contents').each(function() {

					contentWidth = parseInt($(this).outerWidth());
$(this).css({marginLeft: 0, left: 0});

					contentWidth = parseInt($(this).outerWidth(), 10);
$(this).css({ marginLeft: 0, left: 0 });

				});

var maxOffset = Math.min(contentWidth, fullFreeSpace) + 'px';

				});

var maxOffset = Math.min(contentWidth, fullFreeSpace) + 'px';

				options.dropdown.css({'width': maxOffset, 'margin-left': '-' + maxOffset});




				options.dropdown.css({
width: maxOffset,
marginLeft: -maxOffset
});

			}
} else {
options.dropdown.css('margin-right', '-' + (windowWidth + freeSpace) + 'px');

			}
} else {
options.dropdown.css('margin-right', '-' + (windowWidth + freeSpace) + 'px');

Line 1388Line 1427
/**
* Get the HTML for a color palette table.
*

/**
* Get the HTML for a color palette table.
*

* @param string dir Palette direction - either v or h
* @param int width Palette cell width.
* @param int height Palette cell height.

* @param {string} dir Palette direction - either v or h
* @param {int} width Palette cell width.
* @param {int} height Palette cell height.

*/
phpbb.colorPalette = function(dir, width, height) {

*/
phpbb.colorPalette = function(dir, width, height) {

	var r = 0, 
g = 0,
b = 0,

	var r, g, b,



		numberList = new Array(6),
color = '',
html = '';

		numberList = new Array(6),
color = '',
html = '';

Line 1406Line 1443
	numberList[3] = 'BF';
numberList[4] = 'FF';


	numberList[3] = 'BF';
numberList[4] = 'FF';


	var tableClass = (dir == 'h') ? 'horizontal-palette' : 'vertical-palette';

	var tableClass = (dir === 'h') ? 'horizontal-palette' : 'vertical-palette';

	html += '<table class="not-responsive colour-palette ' + tableClass + '" style="width: auto;">';

for (r = 0; r < 5; r++) {

	html += '<table class="not-responsive colour-palette ' + tableClass + '" style="width: auto;">';

for (r = 0; r < 5; r++) {

		if (dir == 'h') {

		if (dir === 'h') {

			html += '<tr>';
}

for (g = 0; g < 5; g++) {

			html += '<tr>';
}

for (g = 0; g < 5; g++) {

			if (dir == 'v') {

			if (dir === 'v') {

				html += '<tr>';
}

for (b = 0; b < 5; b++) {

				html += '<tr>';
}

for (b = 0; b < 5; b++) {

				color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
html += '<td style="background-color: #' + color + '; width: ' + width + 'px; height: ' + height + 'px;">';
html += '<a href="#" data-color="' + color + '" style="display: block; width: ' + width + 'px; height: ' + height + 'px; " alt="#' + color + '" title="#' + color + '"></a>';


				color = '' + numberList[r] + numberList[g] + numberList[b];
html += '<td style="background-color: #' + color + '; width: ' + width + 'px; height: ' +
height + 'px;"><a href="#" data-color="' + color + '" style="display: block; width: ' +
width + 'px; height: ' + height + 'px; " alt="#' + color + '" title="#' + color + '"></a>';

				html += '</td>';
}


				html += '</td>';
}


			if (dir == 'v') {

			if (dir === 'v') {

				html += '</tr>';
}
}


				html += '</tr>';
}
}


		if (dir == 'h') {

		if (dir === 'h') {

			html += '</tr>';
}
}

			html += '</tr>';
}
}

Line 1442Line 1480
/**
* Register a color palette.
*

/**
* Register a color palette.
*

* @param object el jQuery object for the palette container.

* @param {jQuery} el jQuery object for the palette container.

*/
phpbb.registerPalette = function(el) {
var orientation = el.attr('data-orientation'),

*/
phpbb.registerPalette = function(el) {
var orientation = el.attr('data-orientation'),

Line 1471Line 1509
		}
e.preventDefault();
});

		}
e.preventDefault();
});

}

};


/**
* Set display of page element
*


/**
* Set display of page element
*

* @param string	id	The ID of the element to change
* @param int action Set to 0 if element display should be toggled, -1 for

* @param {string} id The ID of the element to change
* @param {int} action Set to 0 if element display should be toggled, -1 for

*			hiding the element, and 1 for showing it.

*			hiding the element, and 1 for showing it.

* @param string	type	Display type that should be used, e.g. inline, block or

* @param {string} type Display type that should be used, e.g. inline, block or

*			other CSS "display" types
*/
phpbb.toggleDisplay = function(id, action, type) {

*			other CSS "display" types
*/
phpbb.toggleDisplay = function(id, action, type) {

Line 1500Line 1538
* Toggle additional settings based on the selected
* option of select element.
*

* Toggle additional settings based on the selected
* option of select element.
*

* @param jQuery el jQuery select element object.
* @return undefined

* @param {jQuery} el jQuery select element object.


*/
phpbb.toggleSelectSettings = function(el) {
el.children().each(function() {
var $this = $(this),
$setting = $($this.data('toggle-setting'));
$setting.toggle($this.is(':selected'));

*/
phpbb.toggleSelectSettings = function(el) {
el.children().each(function() {
var $this = $(this),
$setting = $($this.data('toggle-setting'));
$setting.toggle($this.is(':selected'));

 

// Disable any input elements that are not visible right now
if ($this.is(':selected')) {
$($this.data('toggle-setting') + ' input').prop('disabled', false);
} else {
$($this.data('toggle-setting') + ' input').prop('disabled', true);
}

	});
};


	});
};


Line 1515Line 1559
* Get function from name.
* Based on http://stackoverflow.com/a/359910
*

* Get function from name.
* Based on http://stackoverflow.com/a/359910
*

* @param string functionName Function to get.
* @return function

* @param {string} functionName Function to get.
* @returns function

*/
phpbb.getFunctionByName = function (functionName) {
var namespaces = functionName.split('.'),

*/
phpbb.getFunctionByName = function (functionName) {
var namespaces = functionName.split('.'),

Line 1583Line 1627
		}
});
};

		}
});
};

 

/**
* Handle avatars to be lazy loaded.
*/
phpbb.lazyLoadAvatars = function loadAvatars() {
$('.avatar[data-src]').each(function () {
var $avatar = $(this);

$avatar
.attr('src', $avatar.data('src'))
.removeAttr('data-src');
});
};

$(window).load(phpbb.lazyLoadAvatars);


/**
* Apply code editor to all textarea elements with data-bbcode attribute


/**
* Apply code editor to all textarea elements with data-bbcode attribute