MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus Planet 3DNow! Distributed Computing Wiki
Zur Navigation springen Zur Suche springen
(meine Änderungen rückgängig gemacht)
Zeile 1: Zeile 1:
 
/* Jedes JavaScript hier wird für alle Benutzer für jede Seite geladen. */
 
/* Jedes JavaScript hier wird für alle Benutzer für jede Seite geladen. */
 +
 +
var AJAX_Compatible  = false;
 +
var userAgent = navigator.userAgent.toLowerCase();
 +
var is_opera  = ((userAgent.indexOf('opera') != -1) || (typeof(window.opera) != 'undefined'));
 +
var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
 +
var is_webtv  = (userAgent.indexOf('webtv') != -1);
 +
var is_ie    = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
 +
var is_ie4    = ((is_ie) && (userAgent.indexOf('msie 4.') != -1));
 +
var is_ie7    = ((is_ie) && (userAgent.indexOf('msie 7.') != -1));
  
 
  // ============================================================
 
  // ============================================================
Zeile 135: Zeile 144:
 
     }
 
     }
 
   
 
   
    // TODO: implement a replacement for vB_AJAX_Handler
+
     this.xml_sender = new DCW_AJAX_Handler(true);
     this.xml_sender = new vB_AJAX_Handler(true);
 
 
     this.xml_sender.onreadystatechange(this.OnLoadReadyStateChange);
 
     this.xml_sender.onreadystatechange(this.OnLoadReadyStateChange);
 
     // TODO: change ajax.php
 
     // TODO: change ajax.php
Zeile 157: Zeile 165:
 
   
 
   
 
  // END AJAX Teamstatistiken
 
  // END AJAX Teamstatistiken
 +
// ============================================================
 +
 +
 +
// ============================================================
 +
// BEGIN AJAX DCW_AJAX_Handler
 +
 +
function DCW_AJAX_Handler(async)
 +
{
 +
  this.async = async ? true : false;
 +
}
 +
 +
DCW_AJAX_Handler.prototype.init = function()
 +
{
 +
  if(typeof XMLHttpRequest != "undefined") {
 +
    this.handler = new XMLHttpRequest();
 +
    return (this.handler.setRequestHeader ? true : false);
 +
  } else if(is_ie && !is_ie7) {
 +
    this.handler = eval("new A" + "ctiv" + "eX" + "Ob" + "ject('Micr" + "osoft.XM" + "LHTTP');");
 +
    return true;
 +
  } else {
 +
    return false;
 +
  }
 +
}
 +
 +
DCW_AJAX_Handler.prototype.is_compatible = function()
 +
{
 +
  if(is_ie && !is_ie4) {
 +
    return true;
 +
  } else if(typeof XMLHttpRequest != 'undefined') {
 +
    try {
 +
      return XMLHttpRequest.prototype.setRequestHeader ? true : false;
 +
    } catch(e) {
 +
      try {
 +
        var tester = new XMLHttpRequest();
 +
        return tester.setRequestHeader ? true : false;
 +
      } catch(e) {
 +
        return false;
 +
      }
 +
    }
 +
  } else {
 +
    return false;
 +
  }
 +
}
 +
 +
DCW_AJAX_Handler.prototype.not_ready = function()
 +
{
 +
  return (this.handler.readyState && (this.handler.readyState < 4));
 +
}
 +
 +
DCW_AJAX_Handler.prototype.onreadystatechange = function(event)
 +
{
 +
  if(!this.handler) {
 +
    if(!this.init()) {
 +
      return false;
 +
    }
 +
  }
 +
  if(typeof event == 'function') {
 +
    this.handler.onreadystatechange = event;
 +
  } else {
 +
    alert('XML Sender OnReadyState event is not a function');
 +
  }
 +
  return false;
 +
}
 +
 +
DCW_AJAX_Handler.prototype.send = function(desturl, datastream)
 +
{
 +
  if(!this.handler) {
 +
    if(!this.init()) {
 +
      return false;
 +
    }
 +
  }
 +
  if(!this.not_ready()) {
 +
    this.handler.open('POST', desturl, this.async);
 +
    this.handler.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 +
    this.handler.send(datastream + '&s=' + fetch_sessionhash());
 +
 +
    if(!this.async && this.handler.readyState == 4 && this.handler.status == 200) {
 +
      return true;
 +
    }
 +
  }
 +
  return false;
 +
}
 +
 +
DCW_AJAX_Handler.prototype.fetch_data = function(xml_node)
 +
{
 +
  if(xml_node && xml_node.firstChild && xml_node.firstChild.nodeValue) {
 +
    return PHP.unescape_cdata(xml_node.firstChild.nodeValue);
 +
  } else {
 +
    return '';
 +
  }
 +
}
 +
 +
AJAX_Compatible = DCW_AJAX_Handler.prototype.is_compatible();
 +
console.info("Browser is%s AJAX compatible", AJAX_Compatible ? "" : " NOT");
 +
 +
// END AJAX DCW_AJAX_Handler
 
  // ============================================================
 
  // ============================================================

Version vom 5. Februar 2008, 01:37 Uhr

/* Jedes JavaScript hier wird für alle Benutzer für jede Seite geladen. */

 var AJAX_Compatible  = false;
 var userAgent = navigator.userAgent.toLowerCase();
 var is_opera  = ((userAgent.indexOf('opera') != -1) || (typeof(window.opera) != 'undefined'));
 var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
 var is_webtv  = (userAgent.indexOf('webtv') != -1);
 var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
 var is_ie4    = ((is_ie) && (userAgent.indexOf('msie 4.') != -1));
 var is_ie7    = ((is_ie) && (userAgent.indexOf('msie 7.') != -1));

 // ============================================================
 // BEGIN Event Hooking
 function HookEvent(hookName, hookFunction)
 {
   if(window.addEventListener) {
     window.addEventListener(hookName, hookFunction, false);
   } else if(window.attachEvent) {
     window.attachEvent("on" + hookName, hookFunction);
   }
 }
 // END Event Hooking
 // ============================================================


 // ============================================================
 // BEGIN Dynamic Navigation Bars
 
 var strNavigationBarHide = "Einklappen";
 var strNavigationBarShow = "Ausklappen";
 
 var navigationBarShowDefault = 0;
 
 // shows and hides content and picture (if available) of navigation bars
 // Parameters:
 //     indexNavigationBar: the index of navigation bar to be toggled
 function ToggleNavigationBar(indexNavigationBar)
 {
    var naviToggle = document.getElementById("dcw_navitoggle" + indexNavigationBar);
    var naviFrame = document.getElementById("dcw_naviframe" + indexNavigationBar);
 
    if(!naviFrame || !naviToggle) {
        return false;
    }
 
    // if shown now
    if(naviToggle.firstChild.data == strNavigationBarHide) {
        for(var naviChild = naviFrame.firstChild; naviChild != null; naviChild = naviChild.nextSibling) {
            if(naviChild.className == "dcw_navipicture") {
                naviChild.style.display = "none";
            }
            if(naviChild.className == "dcw_navicontent") {
                naviChild.style.display = "none";
            }
            if(naviChild.className == "dcw_navitoggle") {
                naviChild.firstChild.data = strNavigationBarShow;
            }
        }
 
    // if hidden now
    } else if(naviToggle.firstChild.data == strNavigationBarShow) {
        for(var naviChild = naviFrame.firstChild; naviChild != null; naviChild = naviChild.nextSibling) {
            if(naviChild.className == "dcw_navipicture") {
                naviChild.style.display = "block";
            }
            if(naviChild.className == "dcw_navicontent") {
                naviChild.style.display = "block";
            }
            if(naviChild.className == "dcw_navitoggle") {
                naviChild.firstChild.data = strNavigationBarHide;
            }
        }
    }
 }
 
 // adds show/hide-button to navigation bars
 function CreateNavigationBarToggleButton()
 {
    var indexNavigationBar = 0;
    // iterate over all < div >-elements
    for(var i = 0; naviFrame = document.getElementsByTagName("div")[i]; ++i) {
        // if found a navigation bar
        if(naviFrame.className == "dcw_naviframe") {
            ++indexNavigationBar;
            var naviToggle = document.createElement("a");
            naviToggle.className = "dcw_navitoggle";
            naviToggle.setAttribute("id", "dcw_navitoggle" + indexNavigationBar);
            naviToggle.setAttribute("href", "javascript:ToggleNavigationBar(" + indexNavigationBar + ");");
 
            var naviToggleText = document.createTextNode(strNavigationBarHide);
            naviToggle.appendChild(naviToggleText);
 
            // add naviToggle-Button as first div-element 
            // in < div class="dcw_naviframe" >
            naviFrame.insertBefore(naviToggle, naviFrame.firstChild);
            naviFrame.setAttribute("id", "dcw_naviframe" + indexNavigationBar);
        }
    }
    // if more navigation bars found than default: hide all
    if(navigationBarShowDefault < indexNavigationBar) {
        for(var i = 1; i <= indexNavigationBar; ++i) {
            ToggleNavigationBar(i);
        }
    }
 }
 
 HookEvent("load", CreateNavigationBarToggleButton);
 
 // END Dynamic Navigation Bars
 // ============================================================


 // ============================================================
 // BEGIN AJAX Teamstatistiken
 
 var dcw_TeamStatsLoader = null;
 
 function TeamStatsLoader(statsSpan, project)
 {
    this.statsSpan = statsSpan;
    this.project = project;
 
    this.xml_sender = null;
    this.teamPosition = '';
 
    var me = this;
 
    this.OnLoadReadyStateChange = function()
    {
        //alert("in OnLoadReadyStateChange()");
        if(me.xml_sender.handler.readyState == 4 && me.xml_sender.handler.status == 200) {
            alert(me.xml_sender.handler.responseXML);
            if(me.xml_sender.handler.responseXML) {
                me.teamPosition = me.xml_sender.fetch_data(fetch_tags(me.xml_sender.handler.responseXML, 'teamposition'));
            }
 
            if(is_ie) {
                me.xml_sender.handler.abort();
            }
 
            var textNode = document.createTextNode(me.teamPosition);
            me.statsSpan.appendChild(textNode);
        }
    }
 
    this.xml_sender = new DCW_AJAX_Handler(true);
    this.xml_sender.onreadystatechange(this.OnLoadReadyStateChange);
    // TODO: change ajax.php
    this.xml_sender.send('ajax.php?do=getteamposition&project=' + me.project, 'do=getteamposition&project=' + me.project);
 }
 
 function LoadTeamStats()
 {
    // iterate over all < span >-elements
    for(var i = 0; statsSpan = document.getElementsByTagName("span")[i]; ++i) {
        if(statsSpan.className == "dcw_span_teamstats") {
           var friendlyProjectName = statsSpan.id.replace(/.40/g, "@");
 
           dcw_TeamStatsLoader = new TeamStatsLoader(statsSpan, friendlyProjectName);
        }
    }
 }
 
 HookEvent("load", LoadTeamStats);
 
 // END AJAX Teamstatistiken
 // ============================================================


 // ============================================================
 // BEGIN AJAX DCW_AJAX_Handler
 
 function DCW_AJAX_Handler(async)
 {
   this.async = async ? true : false;
 }
 
 DCW_AJAX_Handler.prototype.init = function()
 {
   if(typeof XMLHttpRequest != "undefined") {
     this.handler = new XMLHttpRequest();
     return (this.handler.setRequestHeader ? true : false);
   } else if(is_ie && !is_ie7) {
     this.handler = eval("new A" + "ctiv" + "eX" + "Ob" + "ject('Micr" + "osoft.XM" + "LHTTP');");
     return true;
   } else {
     return false;
   }
 }
 
 DCW_AJAX_Handler.prototype.is_compatible = function()
 {
   if(is_ie && !is_ie4) {
     return true;
   } else if(typeof XMLHttpRequest != 'undefined') {
     try {
       return XMLHttpRequest.prototype.setRequestHeader ? true : false;
     } catch(e) {
       try {
         var tester = new XMLHttpRequest();
         return tester.setRequestHeader ? true : false;
       } catch(e) {
         return false;
       }
     }
   } else {
     return false;
   }
 }
 
 DCW_AJAX_Handler.prototype.not_ready = function()
 {
   return (this.handler.readyState && (this.handler.readyState < 4));
 }
 
 DCW_AJAX_Handler.prototype.onreadystatechange = function(event)
 {
   if(!this.handler) {
     if(!this.init()) {
       return false;
     }
   }
   if(typeof event == 'function') {
     this.handler.onreadystatechange = event;
   } else {
     alert('XML Sender OnReadyState event is not a function');
   }
   return false;
 }
 
 DCW_AJAX_Handler.prototype.send = function(desturl, datastream)
 {
   if(!this.handler) {
     if(!this.init()) {
       return false;
     }
   }
   if(!this.not_ready()) {
     this.handler.open('POST', desturl, this.async);
     this.handler.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
     this.handler.send(datastream + '&s=' + fetch_sessionhash());

     if(!this.async && this.handler.readyState == 4 && this.handler.status == 200) {
       return true;
     }
   }
   return false;
 }
 
 DCW_AJAX_Handler.prototype.fetch_data = function(xml_node)
 {
   if(xml_node && xml_node.firstChild && xml_node.firstChild.nodeValue) {
     return PHP.unescape_cdata(xml_node.firstChild.nodeValue);
   } else {
     return '';
   }
 }
 
 AJAX_Compatible = DCW_AJAX_Handler.prototype.is_compatible();
 console.info("Browser is%s AJAX compatible", AJAX_Compatible ? "" : " NOT");
 
 // END AJAX DCW_AJAX_Handler
 // ============================================================