[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/styles/prosilver/template/ -> forum_fn.js (source)

   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                      t.className = 'activetab';
 143                  }
 144              }
 145              else
 146              {
 147                  e.style.display = 'none';
 148                  if (t)
 149                  {
 150                      t.className = '';
 151                  }
 152              }
 153          }
 154      }
 155  }
 156  
 157  /**
 158  * Call print preview
 159  */
 160  function printPage()
 161  {
 162      if (is_ie)
 163      {
 164          printPreview();
 165      }
 166      else
 167      {
 168          window.print();
 169      }
 170  }
 171  
 172  /**
 173  * Show/hide groups of blocks
 174  * c = CSS style name
 175  * e = checkbox element
 176  * t = toggle dispay state (used to show 'grip-show' image in the profile block when hiding the profiles) 
 177  */
 178  function displayBlocks(c, e, t)
 179  {
 180      var s = (e.checked == true) ?  1 : -1;
 181  
 182      if (t)
 183      {
 184          s *= -1;
 185      }
 186  
 187      var divs = document.getElementsByTagName("DIV");
 188  
 189      for (var d = 0; d < divs.length; d++)
 190      {
 191          if (divs[d].className.indexOf(c) == 0)
 192          {
 193              divs[d].style.display = (s == 1) ? 'none' : 'block';
 194          }
 195      }
 196  }
 197  
 198  function selectCode(a)
 199  {
 200      // Get ID of code block
 201      var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
 202  
 203      // Not IE and IE9+
 204      if (window.getSelection)
 205      {
 206          var s = window.getSelection();
 207          // Safari
 208          if (s.setBaseAndExtent)
 209          {
 210              s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
 211          }
 212          // Firefox and Opera
 213          else
 214          {
 215              // workaround for bug # 42885
 216              if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) == '<BR>')
 217              {
 218                  e.innerHTML = e.innerHTML + '&nbsp;';
 219              }
 220  
 221              var r = document.createRange();
 222              r.selectNodeContents(e);
 223              s.removeAllRanges();
 224              s.addRange(r);
 225          }
 226      }
 227      // Some older browsers
 228      else if (document.getSelection)
 229      {
 230          var s = document.getSelection();
 231          var r = document.createRange();
 232          r.selectNodeContents(e);
 233          s.removeAllRanges();
 234          s.addRange(r);
 235      }
 236      // IE
 237      else if (document.selection)
 238      {
 239          var r = document.body.createTextRange();
 240          r.moveToElementText(e);
 241          r.select();
 242      }
 243  }
 244  
 245  /**
 246  * Play quicktime file by determining it's width/height
 247  * from the displayed rectangle area
 248  */
 249  function play_qt_file(obj)
 250  {
 251      var rectangle = obj.GetRectangle();
 252  
 253      if (rectangle)
 254      {
 255          rectangle = rectangle.split(',');
 256          var x1 = parseInt(rectangle[0]);
 257          var x2 = parseInt(rectangle[2]);
 258          var y1 = parseInt(rectangle[1]);
 259          var y2 = parseInt(rectangle[3]);
 260  
 261          var width = (x1 < 0) ? (x1 * -1) + x2 : x2 - x1;
 262          var height = (y1 < 0) ? (y1 * -1) + y2 : y2 - y1;
 263      }
 264      else
 265      {
 266          var width = 200;
 267          var height = 0;
 268      }
 269  
 270      obj.width = width;
 271      obj.height = height + 16;
 272  
 273      obj.SetControllerVisible(true);
 274      obj.Play();
 275  }
 276  
 277  /**
 278  * Check if the nodeName of elem is name
 279  * @author jQuery
 280  */
 281  function is_node_name(elem, name)
 282  {
 283      return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
 284  }
 285  
 286  /**
 287  * Check if elem is in array, return position
 288  * @author jQuery
 289  */
 290  function is_in_array(elem, array)
 291  {
 292      for (var i = 0, length = array.length; i < length; i++)
 293          // === is correct (IE)
 294          if (array[i] === elem)
 295              return i;
 296  
 297      return -1;
 298  }
 299  
 300  /**
 301  * Find Element, type and class in tree
 302  * Not used, but may come in handy for those not using JQuery
 303  * @author jQuery.find, Meik Sievertsen
 304  */
 305  function find_in_tree(node, tag, type, class_name)
 306  {
 307      var result, element, i = 0, length = node.childNodes.length;
 308  
 309      for (element = node.childNodes[0]; i < length; element = node.childNodes[++i])
 310      {
 311          if (!element || element.nodeType != 1) continue;
 312  
 313          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))
 314          {
 315              return element;
 316          }
 317  
 318          if (element.childNodes.length)
 319              result = find_in_tree(element, tag, type, class_name);
 320  
 321          if (result) return result;
 322      }
 323  }
 324  
 325  var in_autocomplete = false;
 326  var last_key_entered = '';
 327  
 328  /**
 329  * Check event key
 330  */
 331  function phpbb_check_key(event)
 332  {
 333      // Keycode is array down or up?
 334      if (event.keyCode && (event.keyCode == 40 || event.keyCode == 38))
 335          in_autocomplete = true;
 336  
 337      // Make sure we are not within an "autocompletion" field
 338      if (in_autocomplete)
 339      {
 340          // If return pressed and key changed we reset the autocompletion
 341          if (!last_key_entered || last_key_entered == event.which)
 342          {
 343              in_autocompletion = false;
 344              return true;
 345          }
 346      }
 347  
 348      // Keycode is not return, then return. ;)
 349      if (event.which != 13)
 350      {
 351          last_key_entered = event.which;
 352          return true;
 353      }
 354  
 355      return false;
 356  }
 357  
 358  /**
 359  * Usually used for onkeypress event, to submit a form on enter
 360  */
 361  function submit_default_button(event, selector, class_name)
 362  {
 363      // Add which for key events
 364      if (!event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode))
 365          event.which = event.charCode || event.keyCode;
 366  
 367      if (phpbb_check_key(event))
 368          return true;
 369  
 370      var current = selector['parentNode'];
 371  
 372      // Search parent form element
 373      while (current && (!current.nodeName || current.nodeType != 1 || !is_node_name(current, 'form')) && current != document)
 374          current = current['parentNode'];
 375  
 376      // Find the input submit button with the class name
 377      //current = find_in_tree(current, 'input', 'submit', class_name);
 378      var input_tags = current.getElementsByTagName('input');
 379      current = false;
 380  
 381      for (var i = 0, element = input_tags[0]; i < input_tags.length; element = input_tags[++i])
 382      {
 383          if (element.type == 'submit' && is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1)
 384              current = element;
 385      }
 386  
 387      if (!current)
 388          return true;
 389  
 390      // Submit form
 391      current.focus();
 392      current.click();
 393      return false;
 394  }
 395  
 396  /**
 397  * Apply onkeypress event for forcing default submit button on ENTER key press
 398  * The jQuery snippet used is based on http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/
 399  * The non-jQuery code is a mimick of the jQuery code ;)
 400  */
 401  function apply_onkeypress_event()
 402  {
 403      // jQuery code in case jQuery is used
 404      if (jquery_present)
 405      {
 406          jQuery('form input[type=text], form input[type=password]').live('keypress', function (e)
 407          {
 408              var default_button = jQuery(this).parents('form').find('input[type=submit].default-submit-action');
 409              
 410              if (!default_button || default_button.length <= 0)
 411                  return true;
 412  
 413              if (phpbb_check_key(e))
 414                  return true;
 415  
 416              if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
 417              {
 418                  default_button.click();
 419                  return false;
 420              }
 421  
 422              return true;
 423          });
 424      
 425          return;
 426      }
 427  
 428      var input_tags = document.getElementsByTagName('input');
 429  
 430      for (var i = 0, element = input_tags[0]; i < input_tags.length ; element = input_tags[++i])
 431      {
 432          if (element.type == 'text' || element.type == 'password')
 433          {
 434              // onkeydown is possible too
 435              element.onkeypress = function (evt) { submit_default_button((evt || window.event), this, 'default-submit-action'); };
 436          }
 437      }
 438  }
 439  
 440  /**
 441  * Detect JQuery existance. We currently do not deliver it, but some styles do, so why not benefit from it. ;)
 442  */
 443  var jquery_present = typeof jQuery == 'function';


Generated: Wed Oct 2 15:03:47 2013 Cross-referenced by PHPXref 0.7.1