[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/jscripts/ -> general.js (source)

   1  var MyBB = {
   2      init: function()
   3      {
   4          this.detectBrowser();
   5          Event.observe(document, "dom:loaded", MyBB.pageLoaded);
   6          return true;
   7      },
   8  
   9      pageLoaded: function()
  10      {
  11          MyBB.page_loaded = 1;
  12  
  13          expandables.init();
  14  
  15          // Initialise check all boxes
  16          checkall = $$('input.checkall');
  17          checkall.each(function(element) {
  18              Event.observe(element, "click", MyBB.checkAll.bindAsEventListener(this));
  19          });
  20  
  21          // Initialise "initial focus" field if we have one
  22          initialfocus = $$('input.initial_focus');
  23          if(initialfocus[0])
  24          {
  25              initialfocus[0].focus();
  26          }
  27  
  28          if(typeof(use_xmlhttprequest) != "undefined" && use_xmlhttprequest == 1)
  29          {
  30              mark_read_imgs = $$('img.ajax_mark_read');
  31              mark_read_imgs.each(function(element) {
  32                  if(element.src.match("off.gif") || element.src.match("offlock.gif") || (element.title && element.title == lang.no_new_posts)) return;
  33                  Event.observe(element, "click", MyBB.markForumRead.bindAsEventListener(this));
  34                  element.style.cursor = 'pointer';
  35                  if(element.title)
  36                  {
  37                      element.title += " - ";
  38                  }
  39                  element.title += lang.click_mark_read;
  40              });
  41          }
  42      },
  43  
  44      detectBrowser: function()
  45      {
  46          this.useragent = navigator.userAgent.toLowerCase();
  47          this.useragent_version = parseInt(navigator.appVersion);
  48  
  49          if(navigator.product == "Gecko" && navigator.vendor.indexOf("Apple Computer") != -1)
  50          {
  51              this.browser = "safari";
  52          }
  53          else if(this.useragent.indexOf("chrome") != -1)
  54          {
  55              this.browser = "chrome";
  56          }
  57          else if(navigator.product == "Gecko")
  58          {
  59              this.browser = "mozilla";
  60          }
  61          else if(this.useragent.indexOf("opera") != -1)
  62          {
  63              this.browser = "opera";
  64          }
  65          else if(this.useragent.indexOf("konqueror") != -1)
  66          {
  67              this.browser = "konqueror";
  68          }
  69          else if(this.useragent.indexOf("msie") != -1)
  70          {
  71              this.browser = "ie";
  72          }
  73          else if(this.useragent.indexOf("compatible") == -1 && this.useragent.indexOf("mozilla") != -1)
  74          {
  75              this.browser = "netscape";
  76          }
  77  
  78          if(this.useragent.indexOf("win") != -1)
  79          {
  80              this.os = "win";
  81          }
  82          else if(this.useragent.indexOf("mac") != -1)
  83          {
  84              this.os = "mac";
  85          }
  86      },
  87  
  88      popupWindow: function(url, name, width, height)
  89      {
  90          settings = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
  91  
  92          if(width)
  93          {
  94              settings = settings+",width="+width;
  95          }
  96  
  97          if(height)
  98          {
  99              settings = settings+",height="+height;
 100          }
 101          window.open(url, name, settings);
 102      },
 103  
 104      deleteEvent: function(eid)
 105      {
 106          confirmReturn = confirm(deleteevent_confirm);
 107  
 108          if(confirmReturn == true)
 109          {
 110              var form = new Element("form", { method: "post", action: "calendar.php", style: "display: none;" });
 111  
 112              form.insert({ bottom: new Element("input",
 113                  {
 114                      name: "action",
 115                      type: "hidden",
 116                      value: "do_editevent"
 117                  })
 118              });
 119  
 120              if(my_post_key)
 121              {
 122                  form.insert({ bottom: new Element("input",
 123                      {
 124                          name: "my_post_key",
 125                          type: "hidden",
 126                          value: my_post_key
 127                      })
 128                  });
 129              }
 130  
 131              form.insert({ bottom: new Element("input",
 132                  {
 133                      name: "eid",
 134                      type: "hidden",
 135                      value: eid
 136                  })
 137              });
 138  
 139              form.insert({ bottom: new Element("input",
 140                  {
 141                      name: "delete",
 142                      type: "hidden",
 143                      value: 1
 144                  })
 145              });
 146  
 147              $$("body")[0].insert({ bottom: form });
 148              form.submit();
 149          }
 150      },
 151  
 152      checkAll: function(e)
 153      {
 154          var allbox = Event.element(e);
 155          var form = Event.findElement(e, 'FORM');
 156          if(!form)
 157          {
 158              return false;
 159          }
 160          form.getElements().each(function(element) {        
 161              if(!element.hasClassName("checkall") && element.type == "checkbox")
 162              {
 163                  element.checked = allbox.checked;
 164              }
 165          });
 166      },
 167  
 168      reputation: function(uid, pid)
 169      {
 170          if(!pid)
 171          {
 172              var pid = 0;
 173          }
 174  
 175          MyBB.popupWindow("reputation.php?action=add&uid="+uid+"&pid="+pid, "reputation", 400, 350)
 176      },
 177  
 178      deleteReputation: function(uid, rid)
 179      {
 180          confirmReturn = confirm(delete_reputation_confirm);
 181  
 182          if(confirmReturn == true)
 183          {
 184              var form = new Element("form", { method: "post", action: "reputation.php?action=delete", style: "display: none;" });
 185  
 186              form.insert({ bottom: new Element("input",
 187                  {
 188                      name: "rid",
 189                      type: "hidden",
 190                      value: rid
 191                  })
 192              });
 193  
 194              if(my_post_key)
 195              {
 196                  form.insert({ bottom: new Element("input",
 197                      {
 198                          name: "my_post_key",
 199                          type: "hidden",
 200                          value: my_post_key
 201                      })
 202                  });
 203              }
 204  
 205              form.insert({ bottom: new Element("input",
 206                  {
 207                      name: "uid",
 208                      type: "hidden",
 209                      value: uid
 210                  })
 211              });
 212  
 213              $$("body")[0].insert({ bottom: form });
 214              form.submit();
 215          }
 216      },
 217  
 218      whoPosted: function(tid)
 219      {
 220          MyBB.popupWindow("misc.php?action=whoposted&tid=" + tid, "whoPosted", 230, 300)
 221      },
 222  
 223      hopPage: function(tid, page, pages)
 224      {
 225          if(pages > 1)
 226          {
 227              defpage = page + 1;
 228          }
 229          else
 230          {
 231              defpage = 1;
 232          }
 233  
 234          promptres = prompt("Quick Page Jump\nPlease enter a page number between 1 and "+pages+" to jump to.", defpage);
 235  
 236          if((promptres != null) && (promptres != "") && (promptres > 1) && (promptres <= pages))
 237          {
 238              window.location = "showthread.php?tid="+tid+"&page"+promotres;
 239          }
 240      },
 241  
 242      markForumRead: function(event)
 243      {
 244          element = Event.element(event);
 245          if(!element)
 246          {
 247              return false;
 248          }
 249          var fid = element.id.replace("mark_read_", "");
 250          if(!fid)
 251          {
 252              return false;
 253          }
 254          new Ajax.Request('misc.php?action=markread&fid='+fid+'&ajax=1&my_post_key='+my_post_key, {method: 'get', onComplete: function(request) {MyBB.forumMarkedRead(fid, request); }});
 255      },
 256  
 257      forumMarkedRead: function(fid, request)
 258      {
 259          if(request.responseText == 1)
 260          {
 261              $('mark_read_'+fid).src = $('mark_read_'+fid).src.replace("on.gif", "off.gif");
 262              Event.stopObserving($('mark_read_'+fid), "click", MyBB.markForumRead.bindAsEventListener(this));
 263              $('mark_read_'+fid).style.cursor = 'default';
 264              $('mark_read_'+fid).title = lang.no_new_posts;
 265          }
 266      },
 267  
 268      detectDSTChange: function(timezone_with_dst)
 269      {
 270          var date = new Date();
 271          var local_offset = date.getTimezoneOffset() / 60;
 272          if(Math.abs(parseInt(timezone_with_dst) + local_offset) == 1)
 273          {
 274              if(use_xmlhttprequest != 1 || !new Ajax.Request('misc.php?action=dstswitch&ajax=1', {method: 'post'})) // Ajax update failed? (No ajax support) Fake it
 275              {
 276                  var form = new Element("form", { method: "post", action: "misc.php", style: "display: none;" });
 277  
 278                  form.insert({ bottom: new Element("input",
 279                      {
 280                          name: "action",
 281                          type: "hidden",
 282                          value: "dstswitch"
 283                      })
 284                  });
 285  
 286                  $$("body")[0].insert({ bottom: form });
 287                  form.submit();
 288              }
 289          }
 290      },
 291  
 292      dismissPMNotice: function()
 293      {
 294          if(!$('pm_notice'))
 295          {
 296              return false;
 297          }
 298  
 299          if(use_xmlhttprequest != 1)
 300          {
 301              return true;
 302          }
 303  
 304          new Ajax.Request('private.php?action=dismiss_notice', {method: 'post', postBody: 'ajax=1&my_post_key='+my_post_key});
 305          Element.remove('pm_notice');
 306          return false;
 307      },
 308  
 309      unHTMLchars: function(text)
 310      {
 311          text = text.replace(/&lt;/g, "<");
 312          text = text.replace(/&gt;/g, ">");
 313          text = text.replace(/&nbsp;/g, " ");
 314          text = text.replace(/&quot;/g, "\"");
 315          text = text.replace(/&amp;/g, "&");
 316          return text;
 317      },
 318  
 319      HTMLchars: function(text)
 320      {
 321          text = text.replace(new RegExp("&(?!#[0-9]+;)", "g"), "&amp;");        
 322          text = text.replace(/</g, "&lt;");
 323          text = text.replace(/>/g, "&gt;");
 324          text = text.replace(/"/g, "&quot;");
 325          return text;
 326      },
 327  
 328      changeLanguage: function()
 329      {
 330          form = $('lang_select');
 331          if(!form)
 332          {
 333              return false;
 334          }
 335          form.submit();
 336      },
 337      
 338      quickLogin: function()
 339      {        
 340          if($("quick_login"))
 341          {
 342              var form = new Element("form", { method: "post", action: "member.php" });
 343              form.insert({ bottom: new Element("input",
 344                  {
 345                      name: "action",
 346                      type: "hidden",
 347                      value: "do_login"
 348                  })
 349              });
 350  
 351              if(document.location.href)
 352              {
 353                  form.insert({ bottom: new Element("input",
 354                      {
 355                          name: "url",
 356                          type: "hidden",
 357                          value: this.HTMLchars(document.location.href)
 358                      })
 359                  });
 360              }
 361  
 362              form.insert({ bottom: new Element("input",
 363                  {
 364                      name: "quick_login",
 365                      type: "hidden",
 366                      value: "1"
 367                  })
 368              });
 369  
 370              form.insert({ bottom: new Element("input",
 371                  {
 372                      name: "quick_username",
 373                      id: "quick_login_username",
 374                      type: "text",
 375                      value: lang.username,
 376                      "class": "textbox",
 377                      onfocus: "if(this.value == '"+lang.username+"') { this.value=''; }",
 378                      onblur: "if(this.value == '') { this.value='"+lang.username+"'; }"
 379                  })
 380              }).insert({ bottom: "&nbsp;" });
 381  
 382              form.insert({ bottom: new Element("input",
 383                  {
 384                      name: "quick_password",
 385                      id: "quick_login_password",
 386                      type: "password",
 387                      value: lang.password,
 388                      "class": "textbox",
 389                      onfocus: "if(this.value == '"+lang.password+"') { this.value=''; }",
 390                      onblur: "if(this.value == '') { this.value='"+lang.password+"'; }"
 391                  })
 392              }).insert({ bottom: "&nbsp;" });
 393  
 394              form.insert({ bottom: new Element("input",
 395                  {
 396                      name: "submit",
 397                      type: "submit",
 398                      value: lang.login,
 399                      "class": "button"
 400                  })
 401              });
 402  
 403              var span = new Element("span", { "class": "remember_me" }).insert({ bottom: new Element("input",
 404                  {
 405                      name: "quick_remember",
 406                      id: "quick_login_remember",
 407                      type: "checkbox",
 408                      value: "yes",
 409                      "class": "checkbox"
 410                  })
 411              });
 412  
 413              span.innerHTML += "<label for=\"quick_login_remember\"> "+lang.remember_me+"</label>";
 414              form.insert({ bottom: span });
 415  
 416              form.innerHTML += lang.lost_password+lang.register_url;
 417      
 418              $("quick_login").innerHTML = "";
 419              $("quick_login").insert({ before: form });
 420  
 421              $("quick_login_remember").setAttribute("checked", "checked");
 422              $('quick_login_username').focus();
 423          }
 424  
 425          return false;
 426      }
 427  };
 428  
 429  var Cookie = {
 430      get: function(name)
 431      {
 432          cookies = document.cookie;
 433          name = cookiePrefix+name+"=";
 434          cookiePos = cookies.indexOf(name);
 435          
 436          if(cookiePos != -1) 
 437          {
 438              cookieStart = cookiePos+name.length;
 439              cookieEnd = cookies.indexOf(";", cookieStart);
 440              
 441              if(cookieEnd == -1) 
 442              {
 443                  cookieEnd = cookies.length;
 444              }
 445              
 446              return unescape(cookies.substring(cookieStart, cookieEnd));
 447          }
 448      },
 449  
 450      set: function(name, value, expires)
 451      {
 452          if(!expires) 
 453          {
 454              expires = "; expires=Wed, 1 Jan 2020 00:00:00 GMT;"
 455          } 
 456          else 
 457          {
 458              expire = new Date();
 459              expire.setTime(expire.getTime()+(expires*1000));
 460              expires = "; expires="+expire.toGMTString();
 461          }
 462  
 463          if(cookieDomain) 
 464          {
 465              domain = "; domain="+cookieDomain;
 466          }
 467          else
 468          {
 469              domain = "";
 470          }
 471  
 472          if(cookiePath != "") 
 473          {
 474              path = cookiePath;
 475          }
 476          else
 477          {
 478              path = "";
 479          }
 480  
 481          document.cookie = cookiePrefix+name+"="+escape(value)+"; path="+path+domain+expires;
 482      },
 483  
 484      unset: function(name)
 485      {
 486          Cookie.set(name, 0, -1);
 487      }
 488  };
 489  
 490  var DomLib = {
 491      // This function is from quirksmode.org
 492      // Modified for use in MyBB
 493      getPageScroll: function()
 494      {
 495          var yScroll;
 496  
 497          if(self.pageYOffset)
 498          {
 499              yScroll = self.pageYOffset;
 500          }
 501          else if(document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
 502          {
 503              yScroll = document.documentElement.scrollTop;
 504          }
 505          else if(document.body) // all other Explorers
 506          {
 507              yScroll = document.body.scrollTop;
 508          }
 509  
 510          arrayPageScroll = new Array('',yScroll);
 511  
 512          return arrayPageScroll;
 513      },
 514  
 515      // This function is from quirksmode.org
 516      // Modified for use in MyBB
 517      getPageSize: function()
 518      {
 519          var xScroll, yScroll;
 520  
 521          if(window.innerHeight && window.scrollMaxY)
 522          {
 523              xScroll = document.body.scrollWidth;
 524              yScroll = window.innerHeight + window.scrollMaxY;
 525          }
 526          else if(document.body.scrollHeight > document.body.offsetHeight) // All but Explorer Mac
 527          {
 528              xScroll = document.body.scrollWidth;
 529              yScroll = document.body.scrollHeight;
 530          }
 531          else  // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
 532          {
 533              xScroll = document.body.offsetWidth;
 534              yScroll = document.body.offsetHeight;
 535          }
 536  
 537          var windowWidth, windowHeight;
 538          if(self.innerHeight) // all except Explorer
 539          {
 540              windowWidth = self.innerWidth;
 541              windowHeight = self.innerHeight;
 542          }
 543          else if(document.documentElement && document.documentElement.clientHeight)  // Explorer 6 Strict Mode
 544          {
 545              windowWidth = document.documentElement.clientWidth;
 546              windowHeight = document.documentElement.clientHeight;
 547          }
 548          else if (document.body) // other Explorers
 549          {
 550              windowWidth = document.body.clientWidth;
 551              windowHeight = document.body.clientHeight;
 552          }
 553  
 554          var pageHeight, pageWidth;
 555  
 556          // For small pages with total height less then height of the viewport
 557          if(yScroll < windowHeight)
 558          {
 559              pageHeight = windowHeight;
 560          }
 561          else
 562          {
 563              pageHeight = yScroll;
 564          }
 565  
 566          // For small pages with total width less then width of the viewport
 567          if(xScroll < windowWidth)
 568          {
 569              pageWidth = windowWidth;
 570          }
 571          else
 572          {
 573              pageWidth = xScroll;
 574          }
 575          
 576          var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
 577  
 578          return arrayPageSize;
 579      }
 580  };
 581  
 582  var expandables = {
 583      init: function()
 584      {
 585          expanders = $$('img.expander');
 586          if(expanders.length > 0)
 587          {
 588              expanders.each(function(expander) {
 589                  if(!expander.id)
 590                  {
 591                      return;
 592                  }
 593  
 594                  Event.observe(expander, "click", this.expandCollapse.bindAsEventListener(this));
 595  
 596                  if(MyBB.browser == "ie")
 597                  {
 598                      expander.style.cursor = "hand";
 599                  }
 600                  else
 601                  {
 602                      expander.style.cursor = "pointer";
 603                  }
 604  
 605                  expander.controls = expander.id.replace("_img", "");
 606                  var row = $(expander.controls);
 607  
 608                  if(row)
 609                  {
 610                      Event.observe(row, "dblclick", this.expandCollapse.bindAsEventListener(this));
 611                      row.controls = expander.id.replace("_img", "");
 612                  }
 613              }.bind(this));
 614          }
 615      },
 616  
 617      expandCollapse: function(e)
 618      {
 619          element = Event.element(e)
 620          if(!element || !element.controls)
 621          {
 622              return false;
 623          }
 624          var expandedItem = $(element.controls+"_e");
 625          var collapsedItem = $(element.controls+"_c");
 626  
 627          if(expandedItem && collapsedItem)
 628          {
 629              if(expandedItem.style.display == "none")
 630              {
 631                  expandedItem.show();
 632                  collapsedItem.hide();
 633                  this.saveCollapsed(element.controls);
 634              }
 635              else
 636              {
 637                  expandedItem.hide();
 638                  collapsedItem.show();
 639                  this.saveCollapsed(element.controls, 1);
 640              }
 641          }
 642          else if(expandedItem && !collapsedItem)
 643          {
 644              if(expandedItem.style.display == "none")
 645              {
 646                  expandedItem.show();
 647                  element.src = element.src.replace("collapse_collapsed.gif", "collapse.gif");
 648                  element.alt = "[-]";
 649                  element.title = "[-]";
 650                  this.saveCollapsed(element.controls);
 651              }
 652              else
 653              {
 654                  expandedItem.hide();
 655                  element.src = element.src.replace("collapse.gif", "collapse_collapsed.gif");
 656                  element.alt = "[+]";
 657                  element.title = "[+]";
 658                  this.saveCollapsed(element.controls, 1);
 659              }
 660          }
 661          return true;
 662      },
 663  
 664      saveCollapsed: function(id, add)
 665      {
 666          var saved = new Array();
 667          var newCollapsed = new Array();
 668          var collapsed = Cookie.get("collapsed");
 669  
 670          if(collapsed)
 671          {
 672              saved = collapsed.split("|");
 673              saved.each(function(item) {
 674                  if(item != id && item != "")
 675                  {
 676                      newCollapsed[newCollapsed.length] = item;
 677                  }
 678              });
 679          }
 680  
 681          if(add == 1)
 682          {
 683              newCollapsed[newCollapsed.length] = id;
 684          }
 685          Cookie.set("collapsed", newCollapsed.join("|"));
 686      }
 687  };
 688  
 689  var ActivityIndicator = Class.create();
 690  
 691  ActivityIndicator.prototype = {
 692      initialize: function(owner, options)
 693      {
 694          var image;
 695  
 696          if(options && options.image)
 697          {
 698              image = "<img src=\""+options.image+"\" alt=\"\" />";
 699          }
 700          else
 701          {
 702              image = "";
 703          }
 704  
 705          this.height = options.height || 150;
 706          this.width = options.width || 150;
 707  
 708          if(owner == "body")
 709          {
 710              arrayPageSize = DomLib.getPageSize();
 711              arrayPageScroll = DomLib.getPageScroll();
 712              var top = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - this.height) / 2);
 713              var left = ((arrayPageSize[0] - 20 - this.width) / 2);
 714              owner = document.getElementsByTagName("body").item(0);
 715          }
 716          else
 717          {
 718              if($(owner))
 719              {
 720                  owner = $(owner);
 721              }
 722  
 723              var offset = Position.positionedOffset(owner);
 724              left = offset[0];
 725              top = offset[1];
 726          }
 727  
 728          this.spinner = document.createElement("div");
 729          this.spinner.style.border = "1px solid #000000";
 730          this.spinner.style.background = "#FFFFFF";
 731          this.spinner.style.color = "#000000";
 732          this.spinner.style.position = "absolute";
 733          this.spinner.style.zIndex = 1000;
 734          this.spinner.style.textAlign = "center";
 735          this.spinner.style.verticalAlign = "middle";
 736          this.spinner.style.fontSize = "13px";
 737  
 738          this.spinner.innerHTML = "<br />"+image+"<br /><br /><strong>"+loading_text+"</strong>";
 739          this.spinner.style.width = this.width + "px";
 740          this.spinner.style.height = this.height + "px";
 741          this.spinner.style.top = top + "px";
 742          this.spinner.style.left = left + "px";
 743          this.spinner.id = "spinner";
 744          owner.insertBefore(this.spinner, owner.firstChild);
 745      },
 746  
 747      destroy: function()
 748      {
 749          Element.remove(this.spinner);
 750      }
 751  };
 752  
 753  /* Lang this! */
 754  var lang = {
 755  
 756  };
 757  
 758  /* additions for IE5 compatibility */ 
 759  if(!Array.prototype.shift) {
 760      Array.prototype.shift = function()
 761      {
 762          firstElement = this[0];
 763          this.reverse();
 764          this.length = Math.max(this.length-1,0);
 765          this.reverse();
 766          return firstElement;
 767      }
 768  }
 769  
 770  if(!Array.prototype.unshift) { 
 771      Array.prototype.unshift = function()
 772      {
 773          this.reverse();
 774          for(var i=arguments.length-1;i>=0;i--) {
 775              this[this.length]=arguments[i]
 776          }
 777          this.reverse();
 778          return this.length
 779      }
 780  }
 781  
 782  if(!Array.prototype.push) {
 783      Array.prototype.push = function()
 784      {
 785          for(var i=0;i<arguments.length;i++){
 786              this[this.length]=arguments[i]
 787          };
 788          return this.length;
 789      }
 790  }
 791  
 792  if(!Array.prototype.pop) {
 793      Array.prototype.pop = function() {
 794          lastElement = this[this.length-1];
 795          this.length = Math.max(this.length-1,0);
 796          return lastElement;
 797      }
 798  }
 799  
 800  if (!Function.prototype.apply) {
 801      Function.prototype.apply = function(oScope, args) {
 802          var sarg = [];
 803          var rtrn, call;
 804  
 805          if (!oScope) oScope = window;
 806          if (!args) args = [];
 807  
 808          for (var i = 0; i < args.length; i++) {
 809              sarg[i] = "args["+i+"]";
 810          }
 811  
 812          call = "oScope.__applyTemp__(" + sarg.join(",") + ");";
 813  
 814          oScope.__applyTemp__ = this;
 815          rtrn = eval(call);
 816          //delete oScope.__applyTemp__;
 817          return rtrn;
 818      }
 819  }
 820  
 821  if(!Function.prototype.call) {
 822      Function.prototype.call = function(obj, param) {
 823          obj.base = this;
 824          obj.base(param);
 825      }
 826  }
 827  
 828  MyBB.init();


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1