styles/art_air_green/template/forum_fn.js
author indvdum (gotoindvdum[at]gmail[dot]com)
Fri, 09 Mar 2012 16:14:29 +0400
changeset 13 118ae93ae3fe
permissions -rw-r--r--
Added Art Air Green style
     1 /**
     2 * phpBB3 forum functions
     3 */
     4 
     5 /**
     6 * Window popup
     7 */
     8 function popup(url, width, height, name)
     9 {
    10 	if (!name)
    11 	{
    12 		name = '_popup';
    13 	}
    14 
    15 	window.open(url.replace(/&/g, '&'), name, 'height=' + height + ',resizable=yes,scrollbars=yes, width=' + width);
    16 	return false;
    17 }
    18 
    19 /**
    20 * Jump to page
    21 */
    22 function jumpto()
    23 {
    24 	var page = prompt(jump_page, on_page);
    25 
    26 	if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0)
    27 	{
    28 		if (base_url.indexOf('?') == -1)
    29 		{
    30 			document.location.href = base_url + '?start=' + ((page - 1) * per_page);
    31 		}
    32 		else
    33 		{
    34 			document.location.href = base_url.replace(/&/g, '&') + '&start=' + ((page - 1) * per_page);
    35 		}
    36 	}
    37 }
    38 
    39 /**
    40 * Mark/unmark checklist
    41 * id = ID of parent container, name = name prefix, state = state [true/false]
    42 */
    43 function marklist(id, name, state)
    44 {
    45 	var parent = document.getElementById(id);
    46 	if (!parent)
    47 	{
    48 		eval('parent = document.' + id);
    49 	}
    50 
    51 	if (!parent)
    52 	{
    53 		return;
    54 	}
    55 
    56 	var rb = parent.getElementsByTagName('input');
    57 	
    58 	for (var r = 0; r < rb.length; r++)
    59 	{	
    60 		if (rb[r].name.substr(0, name.length) == name)
    61 		{
    62 			rb[r].checked = state;
    63 		}
    64 	}
    65 }
    66 
    67 /**
    68 * Resize viewable area for attached image or topic review panel (possibly others to come)
    69 * e = element
    70 */
    71 function viewableArea(e, itself)
    72 {
    73 	if (!e) return;
    74 	if (!itself)
    75 	{
    76 		e = e.parentNode;
    77 	}
    78 	
    79 	if (!e.vaHeight)
    80 	{
    81 		// Store viewable area height before changing style to auto
    82 		e.vaHeight = e.offsetHeight;
    83 		e.vaMaxHeight = e.style.maxHeight;
    84 		e.style.height = 'auto';
    85 		e.style.maxHeight = 'none';
    86 		e.style.overflow = 'visible';
    87 	}
    88 	else
    89 	{
    90 		// Restore viewable area height to the default
    91 		e.style.height = e.vaHeight + 'px';
    92 		e.style.overflow = 'auto';
    93 		e.style.maxHeight = e.vaMaxHeight;
    94 		e.vaHeight = false;
    95 	}
    96 }
    97 
    98 /**
    99 * Set display of page element
   100 * s[-1,0,1] = hide,toggle display,show
   101 * type = string: inline, block, inline-block or other CSS "display" type
   102 */
   103 function dE(n, s, type)
   104 {
   105 	if (!type)
   106 	{
   107 		type = 'block';
   108 	}
   109 
   110 	var e = document.getElementById(n);
   111 	if (!s)
   112 	{
   113 		s = (e.style.display == '' || e.style.display == type) ? -1 : 1;
   114 	}
   115 	e.style.display = (s == 1) ? type : 'none';
   116 }
   117 
   118 /**
   119 * Alternate display of subPanels
   120 */
   121 function subPanels(p)
   122 {
   123 	var i, e, t;
   124 	
   125 	if (typeof(p) == 'string')
   126 	{
   127 		show_panel = p;
   128 	}
   129 
   130 	for (i = 0; i < panels.length; i++)
   131 	{
   132 		e = document.getElementById(panels[i]);
   133 		t = document.getElementById(panels[i] + '-tab');
   134 
   135 		if (e)
   136 		{
   137 			if (panels[i] == show_panel)
   138 			{
   139 				e.style.display = 'block';
   140 				if (t)
   141 				{
   142 				    /* CA: fixed tabs */
   143 				    if(jquery_present) $(t).addClass('activetab');
   144 					else t.className = 'activetab';
   145 				}
   146 			}
   147 			else
   148 			{
   149 				e.style.display = 'none';
   150 				if (t)
   151 				{
   152 				    /* CA: fixed tabs */
   153 				    if(jquery_present) $(t).removeClass('activetab');
   154 					else t.className = '';
   155 				}
   156 			}
   157 		}
   158 	}
   159 }
   160 
   161 /**
   162 * Call print preview
   163 */
   164 function printPage()
   165 {
   166 	if (is_ie)
   167 	{
   168 		printPreview();
   169 	}
   170 	else
   171 	{
   172 		window.print();
   173 	}
   174 }
   175 
   176 /**
   177 * Show/hide groups of blocks
   178 * c = CSS style name
   179 * e = checkbox element
   180 * t = toggle dispay state (used to show 'grip-show' image in the profile block when hiding the profiles) 
   181 */
   182 function displayBlocks(c, e, t)
   183 {
   184 	var s = (e.checked == true) ?  1 : -1;
   185 
   186 	if (t)
   187 	{
   188 		s *= -1;
   189 	}
   190 
   191 	var divs = document.getElementsByTagName("DIV");
   192 
   193 	for (var d = 0; d < divs.length; d++)
   194 	{
   195 		if (divs[d].className.indexOf(c) == 0)
   196 		{
   197 			divs[d].style.display = (s == 1) ? 'none' : 'block';
   198 		}
   199 	}
   200 }
   201 
   202 function selectCode(a)
   203 {
   204 	// Get ID of code block
   205 	var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
   206 
   207 	// Not IE and IE9+
   208 	if (window.getSelection)
   209 	{
   210 		var s = window.getSelection();
   211 		// Safari
   212 		if (s.setBaseAndExtent)
   213 		{
   214 			s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
   215 		}
   216 		// Firefox and Opera
   217 		else
   218 		{
   219 			// workaround for bug # 42885
   220 			if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) == '<BR>')
   221 			{
   222 				e.innerHTML = e.innerHTML + '&nbsp;';
   223 			}
   224 
   225 			var r = document.createRange();
   226 			r.selectNodeContents(e);
   227 			s.removeAllRanges();
   228 			s.addRange(r);
   229 		}
   230 	}
   231 	// Some older browsers
   232 	else if (document.getSelection)
   233 	{
   234 		var s = document.getSelection();
   235 		var r = document.createRange();
   236 		r.selectNodeContents(e);
   237 		s.removeAllRanges();
   238 		s.addRange(r);
   239 	}
   240 	// IE
   241 	else if (document.selection)
   242 	{
   243 		var r = document.body.createTextRange();
   244 		r.moveToElementText(e);
   245 		r.select();
   246 	}
   247 }
   248 
   249 /**
   250 * Play quicktime file by determining it's width/height
   251 * from the displayed rectangle area
   252 */
   253 function play_qt_file(obj)
   254 {
   255 	var rectangle = obj.GetRectangle();
   256 
   257 	if (rectangle)
   258 	{
   259 		rectangle = rectangle.split(',');
   260 		var x1 = parseInt(rectangle[0]);
   261 		var x2 = parseInt(rectangle[2]);
   262 		var y1 = parseInt(rectangle[1]);
   263 		var y2 = parseInt(rectangle[3]);
   264 
   265 		var width = (x1 < 0) ? (x1 * -1) + x2 : x2 - x1;
   266 		var height = (y1 < 0) ? (y1 * -1) + y2 : y2 - y1;
   267 	}
   268 	else
   269 	{
   270 		var width = 200;
   271 		var height = 0;
   272 	}
   273 
   274 	obj.width = width;
   275 	obj.height = height + 16;
   276 
   277 	obj.SetControllerVisible(true);
   278 	obj.Play();
   279 }
   280 
   281 /**
   282 * Check if the nodeName of elem is name
   283 * @author jQuery
   284 */
   285 function is_node_name(elem, name)
   286 {
   287 	return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
   288 }
   289 
   290 /**
   291 * Check if elem is in array, return position
   292 * @author jQuery
   293 */
   294 function is_in_array(elem, array)
   295 {
   296 	for (var i = 0, length = array.length; i < length; i++)
   297 		// === is correct (IE)
   298 		if (array[i] === elem)
   299 			return i;
   300 
   301 	return -1;
   302 }
   303 
   304 /**
   305 * Find Element, type and class in tree
   306 * Not used, but may come in handy for those not using JQuery
   307 * @author jQuery.find, Meik Sievertsen
   308 */
   309 function find_in_tree(node, tag, type, class_name)
   310 {
   311 	var result, element, i = 0, length = node.childNodes.length;
   312 
   313 	for (element = node.childNodes[0]; i < length; element = node.childNodes[++i])
   314 	{
   315 		if (!element || element.nodeType != 1) continue;
   316 
   317 		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))
   318 		{
   319 			return element;
   320 		}
   321 
   322 		if (element.childNodes.length)
   323 			result = find_in_tree(element, tag, type, class_name);
   324 
   325 		if (result) return result;
   326 	}
   327 }
   328 
   329 var in_autocomplete = false;
   330 var last_key_entered = '';
   331 
   332 /**
   333 * Check event key
   334 */
   335 function phpbb_check_key(event)
   336 {
   337 	// Keycode is array down or up?
   338 	if (event.keyCode && (event.keyCode == 40 || event.keyCode == 38))
   339 		in_autocomplete = true;
   340 
   341 	// Make sure we are not within an "autocompletion" field
   342 	if (in_autocomplete)
   343 	{
   344 		// If return pressed and key changed we reset the autocompletion
   345 		if (!last_key_entered || last_key_entered == event.which)
   346 		{
   347 			in_autocompletion = false;
   348 			return true;
   349 		}
   350 	}
   351 
   352 	// Keycode is not return, then return. ;)
   353 	if (event.which != 13)
   354 	{
   355 		last_key_entered = event.which;
   356 		return true;
   357 	}
   358 
   359 	return false;
   360 }
   361 
   362 /**
   363 * Usually used for onkeypress event, to submit a form on enter
   364 */
   365 function submit_default_button(event, selector, class_name)
   366 {
   367 	// Add which for key events
   368 	if (!event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode))
   369 		event.which = event.charCode || event.keyCode;
   370 
   371 	if (phpbb_check_key(event))
   372 		return true;
   373 
   374 	var current = selector['parentNode'];
   375 
   376 	// Search parent form element
   377 	while (current && (!current.nodeName || current.nodeType != 1 || !is_node_name(current, 'form')) && current != document)
   378 		current = current['parentNode'];
   379 
   380 	// Find the input submit button with the class name
   381 	//current = find_in_tree(current, 'input', 'submit', class_name);
   382 	var input_tags = current.getElementsByTagName('input');
   383 	current = false;
   384 
   385 	for (var i = 0, element = input_tags[0]; i < input_tags.length; element = input_tags[++i])
   386 	{
   387 		if (element.type == 'submit' && is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1)
   388 			current = element;
   389 	}
   390 
   391 	if (!current)
   392 		return true;
   393 
   394 	// Submit form
   395 	current.focus();
   396 	current.click();
   397 	return false;
   398 }
   399 
   400 /**
   401 * Apply onkeypress event for forcing default submit button on ENTER key press
   402 * The jQuery snippet used is based on http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/
   403 * The non-jQuery code is a mimick of the jQuery code ;)
   404 */
   405 function apply_onkeypress_event()
   406 {
   407 	// jQuery code in case jQuery is used
   408 	if (jquery_present)
   409 	{
   410 		jQuery('form input[type=text], form input[type=password]').live('keypress', function (e)
   411 		{
   412 			var default_button = jQuery(this).parents('form').find('input[type=submit].default-submit-action');
   413 			
   414 			if (!default_button || default_button.length <= 0)
   415 				return true;
   416 
   417 			if (phpbb_check_key(e))
   418 				return true;
   419 
   420 			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
   421 			{
   422 				default_button.click();
   423 				return false;
   424 			}
   425 
   426 			return true;
   427 		});
   428 	
   429 		return;
   430 	}
   431 
   432 	var input_tags = document.getElementsByTagName('input');
   433 
   434 	for (var i = 0, element = input_tags[0]; i < input_tags.length ; element = input_tags[++i])
   435 	{
   436 		if (element.type == 'text' || element.type == 'password')
   437 		{
   438 			// onkeydown is possible too
   439 			element.onkeypress = function (evt) { submit_default_button((evt || window.event), this, 'default-submit-action'); };
   440 		}
   441 	}
   442 }
   443 
   444 /**
   445 * Detect JQuery existance. We currently do not deliver it, but some styles do, so why not benefit from it. ;)
   446 */
   447 var jquery_present = typeof jQuery == 'function';