styles/art_air_green/template/forum_fn.js
changeset 13 118ae93ae3fe
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/styles/art_air_green/template/forum_fn.js	Fri Mar 09 16:14:29 2012 +0400
     1.3 @@ -0,0 +1,447 @@
     1.4 +/**
     1.5 +* phpBB3 forum functions
     1.6 +*/
     1.7 +
     1.8 +/**
     1.9 +* Window popup
    1.10 +*/
    1.11 +function popup(url, width, height, name)
    1.12 +{
    1.13 +	if (!name)
    1.14 +	{
    1.15 +		name = '_popup';
    1.16 +	}
    1.17 +
    1.18 +	window.open(url.replace(/&/g, '&'), name, 'height=' + height + ',resizable=yes,scrollbars=yes, width=' + width);
    1.19 +	return false;
    1.20 +}
    1.21 +
    1.22 +/**
    1.23 +* Jump to page
    1.24 +*/
    1.25 +function jumpto()
    1.26 +{
    1.27 +	var page = prompt(jump_page, on_page);
    1.28 +
    1.29 +	if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0)
    1.30 +	{
    1.31 +		if (base_url.indexOf('?') == -1)
    1.32 +		{
    1.33 +			document.location.href = base_url + '?start=' + ((page - 1) * per_page);
    1.34 +		}
    1.35 +		else
    1.36 +		{
    1.37 +			document.location.href = base_url.replace(/&/g, '&') + '&start=' + ((page - 1) * per_page);
    1.38 +		}
    1.39 +	}
    1.40 +}
    1.41 +
    1.42 +/**
    1.43 +* Mark/unmark checklist
    1.44 +* id = ID of parent container, name = name prefix, state = state [true/false]
    1.45 +*/
    1.46 +function marklist(id, name, state)
    1.47 +{
    1.48 +	var parent = document.getElementById(id);
    1.49 +	if (!parent)
    1.50 +	{
    1.51 +		eval('parent = document.' + id);
    1.52 +	}
    1.53 +
    1.54 +	if (!parent)
    1.55 +	{
    1.56 +		return;
    1.57 +	}
    1.58 +
    1.59 +	var rb = parent.getElementsByTagName('input');
    1.60 +	
    1.61 +	for (var r = 0; r < rb.length; r++)
    1.62 +	{	
    1.63 +		if (rb[r].name.substr(0, name.length) == name)
    1.64 +		{
    1.65 +			rb[r].checked = state;
    1.66 +		}
    1.67 +	}
    1.68 +}
    1.69 +
    1.70 +/**
    1.71 +* Resize viewable area for attached image or topic review panel (possibly others to come)
    1.72 +* e = element
    1.73 +*/
    1.74 +function viewableArea(e, itself)
    1.75 +{
    1.76 +	if (!e) return;
    1.77 +	if (!itself)
    1.78 +	{
    1.79 +		e = e.parentNode;
    1.80 +	}
    1.81 +	
    1.82 +	if (!e.vaHeight)
    1.83 +	{
    1.84 +		// Store viewable area height before changing style to auto
    1.85 +		e.vaHeight = e.offsetHeight;
    1.86 +		e.vaMaxHeight = e.style.maxHeight;
    1.87 +		e.style.height = 'auto';
    1.88 +		e.style.maxHeight = 'none';
    1.89 +		e.style.overflow = 'visible';
    1.90 +	}
    1.91 +	else
    1.92 +	{
    1.93 +		// Restore viewable area height to the default
    1.94 +		e.style.height = e.vaHeight + 'px';
    1.95 +		e.style.overflow = 'auto';
    1.96 +		e.style.maxHeight = e.vaMaxHeight;
    1.97 +		e.vaHeight = false;
    1.98 +	}
    1.99 +}
   1.100 +
   1.101 +/**
   1.102 +* Set display of page element
   1.103 +* s[-1,0,1] = hide,toggle display,show
   1.104 +* type = string: inline, block, inline-block or other CSS "display" type
   1.105 +*/
   1.106 +function dE(n, s, type)
   1.107 +{
   1.108 +	if (!type)
   1.109 +	{
   1.110 +		type = 'block';
   1.111 +	}
   1.112 +
   1.113 +	var e = document.getElementById(n);
   1.114 +	if (!s)
   1.115 +	{
   1.116 +		s = (e.style.display == '' || e.style.display == type) ? -1 : 1;
   1.117 +	}
   1.118 +	e.style.display = (s == 1) ? type : 'none';
   1.119 +}
   1.120 +
   1.121 +/**
   1.122 +* Alternate display of subPanels
   1.123 +*/
   1.124 +function subPanels(p)
   1.125 +{
   1.126 +	var i, e, t;
   1.127 +	
   1.128 +	if (typeof(p) == 'string')
   1.129 +	{
   1.130 +		show_panel = p;
   1.131 +	}
   1.132 +
   1.133 +	for (i = 0; i < panels.length; i++)
   1.134 +	{
   1.135 +		e = document.getElementById(panels[i]);
   1.136 +		t = document.getElementById(panels[i] + '-tab');
   1.137 +
   1.138 +		if (e)
   1.139 +		{
   1.140 +			if (panels[i] == show_panel)
   1.141 +			{
   1.142 +				e.style.display = 'block';
   1.143 +				if (t)
   1.144 +				{
   1.145 +				    /* CA: fixed tabs */
   1.146 +				    if(jquery_present) $(t).addClass('activetab');
   1.147 +					else t.className = 'activetab';
   1.148 +				}
   1.149 +			}
   1.150 +			else
   1.151 +			{
   1.152 +				e.style.display = 'none';
   1.153 +				if (t)
   1.154 +				{
   1.155 +				    /* CA: fixed tabs */
   1.156 +				    if(jquery_present) $(t).removeClass('activetab');
   1.157 +					else t.className = '';
   1.158 +				}
   1.159 +			}
   1.160 +		}
   1.161 +	}
   1.162 +}
   1.163 +
   1.164 +/**
   1.165 +* Call print preview
   1.166 +*/
   1.167 +function printPage()
   1.168 +{
   1.169 +	if (is_ie)
   1.170 +	{
   1.171 +		printPreview();
   1.172 +	}
   1.173 +	else
   1.174 +	{
   1.175 +		window.print();
   1.176 +	}
   1.177 +}
   1.178 +
   1.179 +/**
   1.180 +* Show/hide groups of blocks
   1.181 +* c = CSS style name
   1.182 +* e = checkbox element
   1.183 +* t = toggle dispay state (used to show 'grip-show' image in the profile block when hiding the profiles) 
   1.184 +*/
   1.185 +function displayBlocks(c, e, t)
   1.186 +{
   1.187 +	var s = (e.checked == true) ?  1 : -1;
   1.188 +
   1.189 +	if (t)
   1.190 +	{
   1.191 +		s *= -1;
   1.192 +	}
   1.193 +
   1.194 +	var divs = document.getElementsByTagName("DIV");
   1.195 +
   1.196 +	for (var d = 0; d < divs.length; d++)
   1.197 +	{
   1.198 +		if (divs[d].className.indexOf(c) == 0)
   1.199 +		{
   1.200 +			divs[d].style.display = (s == 1) ? 'none' : 'block';
   1.201 +		}
   1.202 +	}
   1.203 +}
   1.204 +
   1.205 +function selectCode(a)
   1.206 +{
   1.207 +	// Get ID of code block
   1.208 +	var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
   1.209 +
   1.210 +	// Not IE and IE9+
   1.211 +	if (window.getSelection)
   1.212 +	{
   1.213 +		var s = window.getSelection();
   1.214 +		// Safari
   1.215 +		if (s.setBaseAndExtent)
   1.216 +		{
   1.217 +			s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
   1.218 +		}
   1.219 +		// Firefox and Opera
   1.220 +		else
   1.221 +		{
   1.222 +			// workaround for bug # 42885
   1.223 +			if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) == '<BR>')
   1.224 +			{
   1.225 +				e.innerHTML = e.innerHTML + '&nbsp;';
   1.226 +			}
   1.227 +
   1.228 +			var r = document.createRange();
   1.229 +			r.selectNodeContents(e);
   1.230 +			s.removeAllRanges();
   1.231 +			s.addRange(r);
   1.232 +		}
   1.233 +	}
   1.234 +	// Some older browsers
   1.235 +	else if (document.getSelection)
   1.236 +	{
   1.237 +		var s = document.getSelection();
   1.238 +		var r = document.createRange();
   1.239 +		r.selectNodeContents(e);
   1.240 +		s.removeAllRanges();
   1.241 +		s.addRange(r);
   1.242 +	}
   1.243 +	// IE
   1.244 +	else if (document.selection)
   1.245 +	{
   1.246 +		var r = document.body.createTextRange();
   1.247 +		r.moveToElementText(e);
   1.248 +		r.select();
   1.249 +	}
   1.250 +}
   1.251 +
   1.252 +/**
   1.253 +* Play quicktime file by determining it's width/height
   1.254 +* from the displayed rectangle area
   1.255 +*/
   1.256 +function play_qt_file(obj)
   1.257 +{
   1.258 +	var rectangle = obj.GetRectangle();
   1.259 +
   1.260 +	if (rectangle)
   1.261 +	{
   1.262 +		rectangle = rectangle.split(',');
   1.263 +		var x1 = parseInt(rectangle[0]);
   1.264 +		var x2 = parseInt(rectangle[2]);
   1.265 +		var y1 = parseInt(rectangle[1]);
   1.266 +		var y2 = parseInt(rectangle[3]);
   1.267 +
   1.268 +		var width = (x1 < 0) ? (x1 * -1) + x2 : x2 - x1;
   1.269 +		var height = (y1 < 0) ? (y1 * -1) + y2 : y2 - y1;
   1.270 +	}
   1.271 +	else
   1.272 +	{
   1.273 +		var width = 200;
   1.274 +		var height = 0;
   1.275 +	}
   1.276 +
   1.277 +	obj.width = width;
   1.278 +	obj.height = height + 16;
   1.279 +
   1.280 +	obj.SetControllerVisible(true);
   1.281 +	obj.Play();
   1.282 +}
   1.283 +
   1.284 +/**
   1.285 +* Check if the nodeName of elem is name
   1.286 +* @author jQuery
   1.287 +*/
   1.288 +function is_node_name(elem, name)
   1.289 +{
   1.290 +	return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
   1.291 +}
   1.292 +
   1.293 +/**
   1.294 +* Check if elem is in array, return position
   1.295 +* @author jQuery
   1.296 +*/
   1.297 +function is_in_array(elem, array)
   1.298 +{
   1.299 +	for (var i = 0, length = array.length; i < length; i++)
   1.300 +		// === is correct (IE)
   1.301 +		if (array[i] === elem)
   1.302 +			return i;
   1.303 +
   1.304 +	return -1;
   1.305 +}
   1.306 +
   1.307 +/**
   1.308 +* Find Element, type and class in tree
   1.309 +* Not used, but may come in handy for those not using JQuery
   1.310 +* @author jQuery.find, Meik Sievertsen
   1.311 +*/
   1.312 +function find_in_tree(node, tag, type, class_name)
   1.313 +{
   1.314 +	var result, element, i = 0, length = node.childNodes.length;
   1.315 +
   1.316 +	for (element = node.childNodes[0]; i < length; element = node.childNodes[++i])
   1.317 +	{
   1.318 +		if (!element || element.nodeType != 1) continue;
   1.319 +
   1.320 +		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))
   1.321 +		{
   1.322 +			return element;
   1.323 +		}
   1.324 +
   1.325 +		if (element.childNodes.length)
   1.326 +			result = find_in_tree(element, tag, type, class_name);
   1.327 +
   1.328 +		if (result) return result;
   1.329 +	}
   1.330 +}
   1.331 +
   1.332 +var in_autocomplete = false;
   1.333 +var last_key_entered = '';
   1.334 +
   1.335 +/**
   1.336 +* Check event key
   1.337 +*/
   1.338 +function phpbb_check_key(event)
   1.339 +{
   1.340 +	// Keycode is array down or up?
   1.341 +	if (event.keyCode && (event.keyCode == 40 || event.keyCode == 38))
   1.342 +		in_autocomplete = true;
   1.343 +
   1.344 +	// Make sure we are not within an "autocompletion" field
   1.345 +	if (in_autocomplete)
   1.346 +	{
   1.347 +		// If return pressed and key changed we reset the autocompletion
   1.348 +		if (!last_key_entered || last_key_entered == event.which)
   1.349 +		{
   1.350 +			in_autocompletion = false;
   1.351 +			return true;
   1.352 +		}
   1.353 +	}
   1.354 +
   1.355 +	// Keycode is not return, then return. ;)
   1.356 +	if (event.which != 13)
   1.357 +	{
   1.358 +		last_key_entered = event.which;
   1.359 +		return true;
   1.360 +	}
   1.361 +
   1.362 +	return false;
   1.363 +}
   1.364 +
   1.365 +/**
   1.366 +* Usually used for onkeypress event, to submit a form on enter
   1.367 +*/
   1.368 +function submit_default_button(event, selector, class_name)
   1.369 +{
   1.370 +	// Add which for key events
   1.371 +	if (!event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode))
   1.372 +		event.which = event.charCode || event.keyCode;
   1.373 +
   1.374 +	if (phpbb_check_key(event))
   1.375 +		return true;
   1.376 +
   1.377 +	var current = selector['parentNode'];
   1.378 +
   1.379 +	// Search parent form element
   1.380 +	while (current && (!current.nodeName || current.nodeType != 1 || !is_node_name(current, 'form')) && current != document)
   1.381 +		current = current['parentNode'];
   1.382 +
   1.383 +	// Find the input submit button with the class name
   1.384 +	//current = find_in_tree(current, 'input', 'submit', class_name);
   1.385 +	var input_tags = current.getElementsByTagName('input');
   1.386 +	current = false;
   1.387 +
   1.388 +	for (var i = 0, element = input_tags[0]; i < input_tags.length; element = input_tags[++i])
   1.389 +	{
   1.390 +		if (element.type == 'submit' && is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1)
   1.391 +			current = element;
   1.392 +	}
   1.393 +
   1.394 +	if (!current)
   1.395 +		return true;
   1.396 +
   1.397 +	// Submit form
   1.398 +	current.focus();
   1.399 +	current.click();
   1.400 +	return false;
   1.401 +}
   1.402 +
   1.403 +/**
   1.404 +* Apply onkeypress event for forcing default submit button on ENTER key press
   1.405 +* The jQuery snippet used is based on http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/
   1.406 +* The non-jQuery code is a mimick of the jQuery code ;)
   1.407 +*/
   1.408 +function apply_onkeypress_event()
   1.409 +{
   1.410 +	// jQuery code in case jQuery is used
   1.411 +	if (jquery_present)
   1.412 +	{
   1.413 +		jQuery('form input[type=text], form input[type=password]').live('keypress', function (e)
   1.414 +		{
   1.415 +			var default_button = jQuery(this).parents('form').find('input[type=submit].default-submit-action');
   1.416 +			
   1.417 +			if (!default_button || default_button.length <= 0)
   1.418 +				return true;
   1.419 +
   1.420 +			if (phpbb_check_key(e))
   1.421 +				return true;
   1.422 +
   1.423 +			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
   1.424 +			{
   1.425 +				default_button.click();
   1.426 +				return false;
   1.427 +			}
   1.428 +
   1.429 +			return true;
   1.430 +		});
   1.431 +	
   1.432 +		return;
   1.433 +	}
   1.434 +
   1.435 +	var input_tags = document.getElementsByTagName('input');
   1.436 +
   1.437 +	for (var i = 0, element = input_tags[0]; i < input_tags.length ; element = input_tags[++i])
   1.438 +	{
   1.439 +		if (element.type == 'text' || element.type == 'password')
   1.440 +		{
   1.441 +			// onkeydown is possible too
   1.442 +			element.onkeypress = function (evt) { submit_default_button((evt || window.event), this, 'default-submit-action'); };
   1.443 +		}
   1.444 +	}
   1.445 +}
   1.446 +
   1.447 +/**
   1.448 +* Detect JQuery existance. We currently do not deliver it, but some styles do, so why not benefit from it. ;)
   1.449 +*/
   1.450 +var jquery_present = typeof jQuery == 'function';