[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/jscripts/ -> usercp.js (source)

   1  var UserCP = {
   2      init: function()
   3      {
   4      },
   5  
   6      openBuddySelect: function(field)
   7      {
   8          if(!$(field))
   9          {
  10              return false;
  11          }
  12          this.buddy_field = field;
  13          if($('buddyselect_container'))
  14          {
  15              UserCP.buddySelectLoaded();
  16              return false;
  17          }
  18          if(use_xmlhttprequest == 1)
  19          {
  20              this.spinner = new ActivityIndicator("body", {image: "images/spinner_big.gif"});
  21              new Ajax.Request('xmlhttp.php?action=get_buddyselect', {method: 'get', onComplete: function(request) { UserCP.buddySelectLoaded(request); }});
  22          }
  23      },
  24  
  25      buddySelectLoaded: function(request)
  26      {
  27          // Using new copy
  28          if(request)
  29          {
  30              if(request.responseText.match(/<error>(.*)<\/error>/))
  31              {
  32                  message = request.responseText.match(/<error>(.*)<\/error>/);
  33                  if(!message[1])
  34                  {
  35                      message[1] = "An unknown error occurred.";
  36                  }
  37                  if(this.spinner)
  38                  {
  39                      this.spinner.destroy();
  40                      this.spinner = '';
  41                  }
  42                  alert('There was an error fetching the buddy list.\n\n'+message[1]);
  43                  return false;
  44              }
  45              else if(request.responseText)
  46              {
  47                  if($('buddyselect_container'))
  48                  {
  49                      Element.remove('buddyselect_container');
  50                  }
  51                  var container = document.createElement('DIV');
  52                  container.id = "buddyselect_container";
  53                  container.style.display = 'none';
  54                  container.innerHTML = request.responseText;
  55                  document.body.appendChild(container);
  56              }
  57          }
  58          else
  59          {
  60              Element.hide('buddyselect_container');
  61              var checkboxes = $('buddyselect_container').getElementsByTagName("input");
  62              $A(checkboxes).each(function(item) {
  63                  item.checked = false;
  64              });
  65              $('buddyselect_buddies').innerHTML = '';
  66              container = $('buddyselect_container');
  67          }
  68  
  69          // Clone off screen
  70          var clone = container.cloneNode(true);
  71          document.body.appendChild(clone);
  72          clone.style.width = '300px';
  73          clone.style.top = "-10000px";
  74          clone.style.display = "block";
  75          offsetHeight = clone.offsetHeight;
  76          offsetWidth = clone.offsetWidth;
  77          Element.remove(clone);
  78  
  79          // Center it on the page
  80          arrayPageSize = DomLib.getPageSize();
  81          arrayPageScroll = DomLib.getPageScroll();
  82          var top = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - offsetHeight) / 2);
  83          var left = ((arrayPageSize[0] - 20 - offsetWidth) / 2);
  84          $('buddyselect_container').style.top = top+"px";
  85          $('buddyselect_container').style.left = left+"px";
  86          $('buddyselect_container').style.position = "absolute";
  87          $('buddyselect_container').style.display = "block";
  88          $('buddyselect_container').style.zIndex = '1000';
  89          $('buddyselect_container').style.textAlign = 'left';
  90          if(this.spinner)
  91          {
  92              this.spinner.destroy();
  93              this.spinner = '';
  94          }
  95      },
  96  
  97      selectBuddy: function(uid, username)
  98      {
  99          var checkbox = $('checkbox_'+uid);
 100          // Buddy already in list - remove
 101          if($('buddyselect_buddies_'+uid))
 102          {
 103              Element.remove('buddyselect_buddies_'+uid);
 104              var buddies = $('buddyselect_buddies').innerHTML.stripTags();
 105              if(buddies.charAt(0) == ",")
 106              {
 107                  first_buddy = $('buddyselect_buddies').childNodes[0];
 108                  first_buddy.innerHTML = first_buddy.innerHTML.substr(1, first_buddy.innerHTML.length);
 109              }
 110          }
 111          // Add buddy to list
 112          else
 113          {
 114              var buddies = $('buddyselect_buddies').innerHTML.stripTags();
 115              if(buddies != "")
 116              {
 117                  username = ", "+username;
 118              }
 119              var buddy = document.createElement('span');
 120              buddy.id = "buddyselect_buddies_"+uid;
 121              buddy.innerHTML = username;
 122              $('buddyselect_buddies').appendChild(buddy);
 123          }
 124      },
 125  
 126      closeBuddySelect: function(canceled)
 127      {
 128          if(canceled != true)
 129          {
 130              var buddies = $('buddyselect_buddies').innerHTML.stripTags();
 131              existing_buddies = $(this.buddy_field).value;
 132              if(existing_buddies != "")
 133              {
 134                  existing_buddies = existing_buddies.replace(/^\s+|\s+$/g, "");
 135                  existing_buddies = existing_buddies.replace(/,\s?/g, ",");
 136                  exp_buddies = buddies.split(",");
 137                  exp_buddies.each(function(buddy, i)
 138                  {
 139                      buddy = buddy.replace(/^\s+|\s+$/g, "");
 140                      if((","+existing_buddies+",").toLowerCase().indexOf(","+buddy.toLowerCase()+",") == -1)
 141                      {
 142                          if(existing_buddies)
 143                          {
 144                              existing_buddies += ",";
 145                          }
 146                          existing_buddies += buddy;
 147                      }
 148                  });
 149                  $(this.buddy_field).value = existing_buddies.replace(/,\s?/g, ", ");
 150              }
 151              else
 152              {
 153                  $(this.buddy_field).value = buddies;
 154              }
 155              $(this.buddy_field).focus();
 156          }
 157          $('buddyselect_container').hide();
 158      },
 159  
 160      addBuddy: function(type)
 161      {
 162          if(!$(type+'_add_username').value)
 163          {
 164              return false;
 165          }
 166          if(use_xmlhttprequest != 1)
 167          {
 168              return true;
 169          }
 170  
 171          var old_value = $(type+'_submit').value;
 172  
 173          if(type == "ignored")
 174          {
 175              $(type+'_submit').value = lang.adding_ignored;
 176              var list = 'ignore';
 177          }
 178          else
 179          {
 180              $(type+'_submit').value = lang.adding_buddy;
 181              var list = 'buddy';
 182          }
 183  
 184          new Ajax.Updater(list+'_list', 'usercp.php?action=do_editlists&my_post_key='+my_post_key+'&manage='+type, {method: 'post', postBody: 'ajax=1&add_username='+encodeURIComponent($(type+'_add_username').value), evalScripts: true, onComplete: function() { $(type+'_submit').value = old_value; $(type+'_submit').disabled = false; $(type+'_add_username').disabled = false; $(type+'_add_username').value = ''; $(type+'_add_username').focus(); }});
 185          $(type+'_add_username').disabled = true;
 186          $(type+'_submit').disabled = true;
 187          return false;
 188      },
 189  
 190      removeBuddy: function(type, uid)
 191      {
 192          if(type == "ignored")
 193          {
 194              var message = lang.remove_ignored;
 195          }
 196          else
 197          {
 198              var message = lang.remove_buddy;
 199          }
 200  
 201          if(confirm(message))
 202          {
 203              if(use_xmlhttprequest != 1)
 204              {
 205                  return true;
 206              }
 207              new Ajax.Request('usercp.php?action=do_editlists&my_post_key='+my_post_key+'&manage='+type+'&delete='+uid, {method: 'post', postBody: 'ajax=1'});
 208          }
 209  
 210          return false;
 211      }
 212  };


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