PageRenderTime 48ms CodeModel.GetById 16ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

/com_joomleague/components/com_joomleague/modules/mod_joomleague_matches/assets/js/mod_joomleague_matches.js

https://gitlab.com/volleyuisp/joomleague
JavaScript | 157 lines | 133 code | 21 blank | 3 comment | 8 complexity | 8d6b2f5332d950b106ad5e2ca135ba31 MD5 | raw file
  1
  2function jlmlnewAjax()
  3{
  4  /* THIS CREATES THE AJAX OBJECT */
  5  var xmlhttp=false;
  6  try
  7  {
  8    // ajax object for non IE navigators
  9    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
 10  }
 11  catch(e)
 12  {
 13    try
 14    {
 15      // ajax object for IE
 16      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 17    }
 18    catch(E) { xmlhttp=false; }
 19  }
 20  if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); }
 21
 22  return xmlhttp;
 23}
 24function jlml_loadMatch(usedteam, matchid, moduleid, nr, origin) {
 25  var classadd = 'modJLML'+moduleid+'_row'+nr;
 26  var myFx = new Fx.Morph(classadd);
 27  myFx.start({'opacity':0});
 28  $(classadd).addClass('ajaxloading');
 29  var myFx = new Fx.Morph(classadd);
 30  myFx.start({'opacity':1});
 31  var ajax=jlmlnewAjax();
 32    ajax.open("POST", location.href, true);
 33    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 34    ajax.send('ajaxMListMod=1&ajaxmodid='+moduleid+'&match_id='+matchid+'&nr='+nr+'&usedteam='+usedteam+'&origin='+origin);
 35    ajax.onreadystatechange=function()
 36    {
 37      if (ajax.readyState==4)
 38      {
 39
 40        var response = ajax.responseText;
 41        var start = response.indexOf('<!--jlml-mod'+moduleid+'nr'+nr+' start-->');
 42        var finish = response.indexOf('<!--jlml-mod'+moduleid+'nr'+nr+' end-->');
 43
 44        justMatch= response.substring(start,finish);
 45
 46        var myFx = new Fx.Morph(classadd);
 47        myFx.start({'opacity':1});
 48        $(classadd).innerHTML=justMatch;
 49
 50      }
 51      addJLMLtips('.jlmlTeamname', 'over');
 52    };
 53  return false;
 54}
 55var JLMLToolTip = new Class({
 56  initialize: function(options) {
 57    this.options = Object.extend({
 58      tipper: options.tipper,   // element displaying the tooltip
 59      message: options.message,   // some predefined message
 60      ajax:null,      // show message from ajax / if message is not null, this will override it
 61      ToolTipClass:'tool',  // tooltip display class
 62      followMouse:false,  // follow mouse on move
 63      sticky: options.sticky,    // remove tooltip if closed
 64      fromTop: -15,   // distance from mouse or object
 65      duration: 300,    // fade effect transition duration
 66      fadeDistance: 20,    // the distance the tooltip sarts fading in/out
 67      closeOn: 'click'  // all options to close: click, mouseover, mouseleave
 68    }, options || {});
 69    this.el = this.options.tipper;
 70    this.start();
 71    this.visible = 0;
 72  },
 73
 74  start: function(){
 75    this.createContainer();
 76
 77    this.header.set('html',this.el.title);
 78    this.el.set({'title':''});
 79
 80    if(!this.options.ajax){
 81      this.message.set('html',this.options.message);
 82    }else{
 83      this.message.set('html', this.options.message);
 84      this.message.addClass('message_loading');
 85      new Ajax(this.options.ajax, {
 86        method: 'get',
 87        onComplete: function() {
 88          this.message.removeClass('message_loading');
 89          this.message.addClass('message');
 90        }.bind(this),
 91        update: this.message
 92      }).request();
 93    }
 94
 95    this.fx = new Fx.Morph(this.container, {duration:this.options.duration, wait:false, transition:Fx.Transitions.Sine.easeOut});
 96    
 97    this.el.addEvent( this.options.followMouse ? 'mousemove' : 'mouseenter', this.showToolTip.bind(this) );
 98    if(!this.options.sticky){
 99      this.el.addEvent('mouseleave', this.hideToolTip.bind(this));
100
101    }
102    else{
103
104      this.closeTip = new Element('a').set({'class':'sticky_close','href':'javascript:void(0);'}).setStyles({'position':'absolute','top':3,'right':3});
105      this.closeTip.injectInside(this.header);
106      this.closeTip.addEvent(this.options.closeOn, this.hideToolTip.bind(this));
107      this.container.addEvent('mouseleave', this.hideToolTip.bind(this));
108    }
109  },
110
111  showToolTip: function(ev){
112    var event = new Event(ev);
113    $$('.tmp_sticky_tip').each(function(handle){handle.setStyles({'display': 'none'});});
114    this.container.addClass('tmp_sticky_tip');
115    this.elemHeight = this.el.getCoordinates().height;
116
117
118    this.top = this.options.followMouse ? event.client.y : this.el.getPosition().y;
119    var left = this.options.followMouse ? event.client.x : this.el.getPosition().x;
120
121    var top_dist = this.visible == 1 ?
122             this.top + this.options.fromTop + this.elemHeight :
123             this.top + this.options.fromTop + this.elemHeight + this.options.fadeDistance;
124
125    this.container.setStyles({'top': top_dist,'left':left,'display':'block', 'z-index':'110000'});
126    this.fx.start({'opacity':1, 'top':this.top + this.options.fromTop + this.elemHeight});
127    this.visible = 1;
128  },
129
130  hideToolTip: function(){
131    this.container.setStyles({'z-index':'100000'});
132    this.fx.start({'opacity':0,'top': this.top + this.options.fromTop + this.elemHeight + this.options.fadeDistance});
133    this.visible = 0;
134  },
135
136  createContainer: function(){
137    this.container = new Element('div');
138    this.container.addClass(this.options.ToolTipClass+'-tip');
139    this.container.setStyles({'position':'absolute','opacity':0,'display':'none','z-index':'100000'});
140    this.container.injectInside(document.body);
141    this.wrapper=new Element('div').inject(this.container);
142    this.header = new Element('span').inject(new Element('div',{'class':this.options.ToolTipClass+'-title'}).inject(this.wrapper));
143    this.message = new Element('span').inject(new Element('div',{'class':this.options.ToolTipClass+'-text'}).inject(this.wrapper));
144  }
145});
146
147function addJLMLtips (els, suffix) {
148    $$(els).each(function(el) {
149      var tipsource = el.id+'_'+suffix;
150      if($(tipsource)) {
151        new JLMLToolTip({tipper: $(tipsource), 
152        				sticky: true,
153        				message: $(tipsource).innerHTML}
154        );
155      }
156    });
157}