[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/admin/jscripts/ -> tabs.js (source)

   1  /**
   2   * @author Ryan Johnson <ryan@livepipe.net>
   3   * @copyright 2007 LivePipe LLC
   4   * @package Object.Event
   5   * @license MIT
   6   * @url http://livepipe.net/projects/object_event/
   7   * @version 1.0.0
   8   */
   9  
  10  Object.Event = {
  11      extend: function(object){
  12          object._objectEventSetup = function(event_name){
  13              this._observers = this._observers || {};
  14              this._observers[event_name] = this._observers[event_name] || [];
  15          };
  16          object.observe = function(event_name,observer){
  17              if(typeof(event_name) == 'string' && typeof(observer) != 'undefined'){
  18                  this._objectEventSetup(event_name);
  19                  if(!this._observers[event_name].include(observer))
  20                      this._observers[event_name].push(observer);
  21              }else
  22                  for(var e in event_name)
  23                      this.observe(e,event_name[e]);
  24          };
  25          object.stopObserving = function(event_name,observer){
  26              this._objectEventSetup(event_name);
  27              this._observers[event_name] = this._observers[event_name].without(observer);
  28          };
  29          object.notify = function(event_name){
  30              this._objectEventSetup(event_name);
  31              var collected_return_values = [];
  32              var args = $A(arguments).slice(1);
  33              try{
  34                  for(var i = 0; i < this._observers[event_name].length; ++i)
  35                      collected_return_values.push(this._observers[event_name][i].apply(this._observers[event_name][i],args) || null);
  36              }catch(e){
  37                  if(e == $break)
  38                      return false;
  39                  else
  40                      throw e;
  41              }
  42              return collected_return_values;
  43          };
  44          if(object.prototype){
  45              object.prototype._objectEventSetup = object._objectEventSetup;
  46              object.prototype.observe = object.observe;
  47              object.prototype.stopObserving = object.stopObserving;
  48              object.prototype.notify = function(event_name){
  49                  if(object.notify){
  50                      var args = $A(arguments).slice(1);
  51                      args.unshift(this);
  52                      args.unshift(event_name);
  53                      object.notify.apply(object,args);
  54                  }
  55                  this._objectEventSetup(event_name);
  56                  var args = $A(arguments).slice(1);
  57                  var collected_return_values = [];
  58                  try{
  59                      if(this.options && this.options[event_name] && typeof(this.options[event_name]) == 'function')
  60                          collected_return_values.push(this.options[event_name].apply(this,args) || null);
  61                      for(var i = 0; i < this._observers[event_name].length; ++i)
  62                          collected_return_values.push(this._observers[event_name][i].apply(this._observers[event_name][i],args) || null);
  63                  }catch(e){
  64                      if(e == $break)
  65                          return false;
  66                      else
  67                          throw e;
  68                  }
  69                  return collected_return_values;
  70              };;
  71          }
  72      }
  73  };
  74  
  75  /**
  76   * @author Ryan Johnson <ryan@livepipe.net>
  77   * @copyright 2007 LivePipe LLC
  78   * @package Control.Tabs
  79   * @license MIT
  80   * @url http://livepipe.net/projects/control_tabs/
  81   * @version 2.1.1
  82   */
  83  
  84  if(typeof(Control) == 'undefined')
  85      var Control = {};
  86  Control.Tabs = Class.create();
  87  Object.extend(Control.Tabs,{
  88      instances: [],
  89      findByTabId: function(id){
  90          return Control.Tabs.instances.find(function(tab){
  91              return tab.links.find(function(link){
  92                  return link.key == id;
  93              });
  94          });
  95      }
  96  });
  97  Object.extend(Control.Tabs.prototype,{
  98      initialize: function(tab_list_container,options){
  99          this.activeContainer = false;
 100          this.activeLink = false;
 101          this.containers = $H({});
 102          this.links = [];
 103          Control.Tabs.instances.push(this);
 104          this.options = {
 105              beforeChange: Prototype.emptyFunction,
 106              afterChange: Prototype.emptyFunction,
 107              hover: false,
 108              linkSelector: 'li a',
 109              setClassOnContainer: false,
 110              activeClassName: 'active',
 111              defaultTab: 'first',
 112              autoLinkExternal: true,
 113              targetRegExp: /#(.+)$/,
 114              showFunction: Element.show,
 115              hideFunction: Element.hide
 116          };
 117          Object.extend(this.options,options || {});
 118          (typeof(this.options.linkSelector == 'string')
 119              ? $(tab_list_container).getElementsBySelector(this.options.linkSelector)
 120              : this.options.linkSelector($(tab_list_container))
 121          ).findAll(function(link){
 122              return (/^#/).exec(link.href.replace(window.location.href.split('#')[0],''));
 123          }).each(function(link){
 124              this.addTab(link);
 125          }.bind(this));
 126          this.containers.values().each(this.options.hideFunction);
 127          if(this.options.defaultTab == 'first')
 128              this.setActiveTab(this.links.first());
 129          else if(this.options.defaultTab == 'last')
 130              this.setActiveTab(this.links.last());
 131          else
 132              this.setActiveTab(this.options.defaultTab);
 133          var targets = this.options.targetRegExp.exec(window.location);
 134          if(targets && targets[1]){
 135              targets[1].split(',').each(function(target){
 136                  this.links.each(function(target,link){
 137                      if(link.key == target){
 138                          this.setActiveTab(link);
 139                          throw $break;
 140                      }
 141                  }.bind(this,target));
 142              }.bind(this));
 143          }
 144          if(this.options.autoLinkExternal){
 145              $A(document.getElementsByTagName('a')).each(function(a){
 146                  if(!this.links.include(a)){
 147                      var clean_href = a.href.replace(window.location.href.split('#')[0],'');
 148                      if(clean_href.substring(0,1) == '#'){
 149                          if(this.containers.keys().include(clean_href.substring(1))){
 150                              $(a).observe('click',function(event,clean_href){
 151                                  this.setActiveTab(clean_href.substring(1));
 152                              }.bindAsEventListener(this,clean_href));
 153                          }
 154                      }
 155                  }
 156              }.bind(this));
 157          }
 158      },
 159      addTab: function(link){
 160          this.links.push(link);
 161          link.key = link.getAttribute('href').replace(window.location.href.split('#')[0],'').split('/').last().replace(/#/,'');
 162          this.containers.set(link.key, $(link.key));
 163          link[this.options.hover ? 'onmouseover' : 'onclick'] = function(link){
 164              if(window.event)
 165                  Event.stop(window.event);
 166              this.setActiveTab(link);
 167              return false;
 168          }.bind(this,link);
 169      },
 170      setActiveTab: function(link){
 171          if(!link)
 172              return;
 173          if(typeof(link) == 'string'){
 174              this.links.each(function(_link){
 175                  if(_link.key == link){
 176                      this.setActiveTab(_link);
 177                      throw $break;
 178                  }
 179              }.bind(this));
 180          }else{
 181              this.notify('beforeChange',this.activeContainer);
 182              if(this.activeContainer)
 183                  this.options.hideFunction(this.activeContainer);
 184              this.links.each(function(item){
 185                  (this.options.setClassOnContainer ? $(item.parentNode) : item).removeClassName(this.options.activeClassName);
 186              }.bind(this));
 187              (this.options.setClassOnContainer ? $(link.parentNode) : link).addClassName(this.options.activeClassName);
 188              this.activeContainer = this.containers.get(link.key);
 189              this.activeLink = link;
 190              this.options.showFunction(this.containers.get(link.key));
 191              this.notify('afterChange',this.containers.get(link.key));
 192          }
 193      },
 194      next: function(){
 195          this.links.each(function(link,i){
 196              if(this.activeLink == link && this.links[i + 1]){
 197                  this.setActiveTab(this.links[i + 1]);
 198                  throw $break;
 199              }
 200          }.bind(this));
 201          return false;
 202      },
 203      previous: function(){
 204          this.links.each(function(link,i){
 205              if(this.activeLink == link && this.links[i - 1]){
 206                  this.setActiveTab(this.links[i - 1]);
 207                  throw $break;
 208              }
 209          }.bind(this));
 210          return false;
 211      },
 212      first: function(){
 213          this.setActiveTab(this.links.first());
 214          return false;
 215      },
 216      last: function(){
 217          this.setActiveTab(this.links.last());
 218          return false;
 219      },
 220      notify: function(event_name){
 221          try{
 222              if(this.options[event_name])
 223                  return [this.options[event_name].apply(this.options[event_name],$A(arguments).slice(1))];
 224          }catch(e){
 225              if(e != $break)
 226                  throw e;
 227              else
 228                  return false;
 229          }
 230      }
 231  });
 232  if(typeof(Object.Event) != 'undefined')
 233      Object.Event.extend(Control.Tabs);


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