« MediaWiki:Ticker2.js » : différence entre les versions

De Baripedia
(Page créée avec « →‎globals Bawolff getElementsByClassName hookEvent wgServer wgArticlePath addLoadEvent : /* __This is Ticker2-0.9__ This is an attempt to redesign the ticker syst... »)
 
Aucun résumé des modifications
 
Ligne 1 : Ligne 1 :
/*globals Bawolff getElementsByClassName hookEvent wgServer wgArticlePath addLoadEvent*/
/*globals Bawolff getElementsByClassName hookEvent wgServer wgArticlePath addLoadEvent*/
/*
/*
__This is Ticker2-0.9__


__This is Ticker2-0.9__
This is an attempt to redesign the ticker system. I believe that well the current ticker system is a good idea, it can be improved on
 
 
This is an attempt to redesign the ticker system. I believe that well the current ticker system is a good idea, it can be improved on
 
 
Then again, this may just be overthinking things. time will tell.
 
######
 
Design goals
 
*modular - should be able to have more then one transition between items
 
*user configurable - should be able to customize on wiki (aka {{ticker|for=Africa|speed=...}})
 
**The user should never have to do anything in js
 
**Downside: have to be extra-careful about XSS
 
*fast - performance was an issue with the other system
 
 
cavets:


*Doesn't handle multilevel lists well
Then again, this may just be overthinking things. time will tell.
######
Design goals
*modular - should be able to have more then one transition between items
*user configurable - should be able to customize on wiki (aka {{ticker|for=Africa|speed=...}})
**The user should never have to do anything in js
**Downside: have to be extra-careful about XSS
*fast - performance was an issue with the other system


*onblur/onfocus?? (works in opera, firefox, broken in MSIE)
cavets:
*Doesn't handle multilevel lists well
*onblur/onfocus?? (works in opera, firefox, broken in MSIE)


Todo:
 
*change intro string to a control string with escape sequences (think printf)
Todo:
**Play/pause button
 
*better fade transitions (current one kind of sucks)
*change intro string to a control string with escape sequences (think printf)
*Change state system to number instead of T,F,U.  
 
*make fade work in IE
**Play/pause button
*multiple speed variables
 
*better fade transitions (current one kind of sucks)
 
*Change state system to number instead of T,F,U.
 
*make fade work in IE
 
*multiple speed variables
 
 
####
 
 
Note: Setting disable_ticker2 to true will disable the ticker.
 
*/


####


Note: Setting disable_ticker2 to true will disable the ticker.
*/


//to avoid name conflicts (we already have way to many global variables as is imho)
//to avoid name conflicts (we already have way to many global variables as is imho)
//Everything should be a member of Bawolff.Ticker
//Everything should be a member of Bawolff.Ticker
if (typeof Bawolff !== "object") Bawolff = {};
if (typeof Bawolff !== "object") Bawolff = {};
if (typeof Bawolff.Ticker === "Object") throw new Error("Can not initilize ticker. Already initilized, or someone stole its name!");
if (typeof Bawolff.Ticker === "Object") throw new Error("Can not initilize ticker. Already initilized, or someone stole its name!");


Bawolff.Ticker = function() {
Bawolff.Ticker = function() {
/*
This is the constructor function for new Ticker objects. Call as:
var some_ticker_object = new Bawolff.Ticker;


    /*
Its primary purpose is to set defaults and create new Ticker objects. It takes no arguments.
 
Ticker Objects should have the following methods:
    This is the constructor function for new Ticker objects. Call as:
*setUp - set up ticker properties (and does sanity checks)
 
*engines - functions for transitions
    var some_ticker_object = new Bawolff.Ticker;
probably more
 
*/
   
 
    Its primary purpose is to set defaults and create new Ticker objects. It takes no arguments.
 
    Ticker Objects should have the following methods:
 
    *setUp - set up ticker properties (and does sanity checks)
 
    *engines - functions for transitions
 
    probably more
 
    */
 
   


     var t_s = Bawolff.Ticker; //shortcut
     var t_s = Bawolff.Ticker; //shortcut
   


     this.arg = ""; //defaults to none, if uspecified. (should this be an arg to this function?). unphrased definition of options
     this.arg = ""; //defaults to none, if uspecified. (should this be an arg to this function?). unphrased definition of options
 
     this.elm = null; //element to work ticker magic on. setUp method will throw an error if this isn't set by then  
     this.elm = null; //element to work ticker magic on. setUp method will throw an error if this isn't set by then
 
   


     //method setUp will take care of these. These are the actual options (defaults here)
     //method setUp will take care of these. These are the actual options (defaults here)
   


     this.engineNumb = t_s.eng.none; //constant representing engine number
     this.engineNumb = t_s.eng.none; //constant representing engine number
     this.speed = 1; //float - multiplication factor
     this.speed = 1; //float - multiplication factor
     //Probably can't set these to null through wiki
     //Probably can't set these to null through wiki
     this.strLeft = "Dernières nouvelles ("; //Intro string part 1 - null for none
     this.strLeft = "Dernières nouvelles ("; //Intro string part 1 - null for none
     this.strRight = ") :"; //intro part 3 - null for none
     this.strRight = ") :"; //intro part 3 - null for none
     this.strLinkURI = "//fr.wikinews.org/wiki/Utilisateur:TheFearow/Tickersource"; //part 2 url
     this.strLinkURI = "//fr.wikinews.org/wiki/Utilisateur:TheFearow/Tickersource"; //part 2 url
     this.strLinkText = "liste complète"; //part 2 text. null for no link.
     this.strLinkText = "liste complète"; //part 2 text. null for no link.
     this.schowControls = false; //pause/restart
     this.schowControls = false; //pause/restart
     this.tickSpeed = 1;
     this.tickSpeed = 1;
     this.resetSpeed=1;
     this.resetSpeed=1;
   


     //Internal thingies (don't change)
     //Internal thingies (don't change)
     this.listIndex = 0;
     this.listIndex = 0;
     this.charIndex = 0;
     this.charIndex = 0;
     this.curState = "ok"; //for pausing
     this.curState = "ok"; //for pausing
     this.resumeFunc = null; //storage for resume function
     this.resumeFunc = null; //storage for resume function
     this.resumeDelay = 0; //wait time before executing
     this.resumeDelay = 0; //wait time before executing
   


}
}


Bawolff.Ticker.prototype.setUp = function() {
Bawolff.Ticker.prototype.setUp = function() {
/*
This function takes no arguments. call as:
some_ticker_object.setUp();


    /*
It initilizes ticker options based on what the class name of the ticker element is.
 
The options are (mostly) encoded as follows in a class attribute:
    This function takes no arguments. call as:
 
    some_ticker_object.setUp();
 
   
 
    It initilizes ticker options based on what the class name of the ticker element is.
 
    The options are (mostly) encoded as follows in a class attribute:
 
   
 
    Ticker_<option name- no dashes, underscore allowed>-<urlencoded option value(must end in alphanumeric or _ character)>


   
Ticker_<option name- no dashes, underscore allowed>-<urlencoded option value(must end in alphanumeric or _ character)>


    options are separated by a space (each is a different class).
options are separated by a space (each is a different class).
###################################################
##This function must be extra careful not to be  ##
##vulnurable to an xss attack as it directly    ##
##deals with editable on wiki data, that could be##
##malicious! be careful                          ##
###################################################


    ###################################################
*/


    ##This function must be extra careful not to be  ##
    ##vulnurable to an xss attack as it directly    ##
    ##deals with editable on wiki data, that could be##
    ##malicious! be careful                          ##
    ###################################################
   
    */
   
   


     //check to see if we really have an element
     //check to see if we really have an element
     if (!(this.elm && this.elm.nodeType && this.elm.nodeType === 1)) throw new Error("no element, or invalid element for ticker");
     if (!(this.elm && this.elm.nodeType && this.elm.nodeType === 1)) throw new Error("no element, or invalid element for ticker");
   


     var propMatch = /\bTicker_(\w+)-(\S*)\b/g;
     var propMatch = /\bTicker_(\w+)-(\S*)\b/g;
     var res;
     var res;
     var plusSign = /\+/g;
     var plusSign = /\+/g;
      
      
     while(res = propMatch.exec(this.arg)) {
     while(res = propMatch.exec(this.arg)) {
 
      switch(res[1]) { //option name
        switch(res[1]) { //option name
 
             case "speed":
             case "speed":
 
              var speed = parseFloat(decodeURIComponent(res[2]));
                var speed = parseFloat(decodeURIComponent(res[2]));
              if (isNaN(speed)) break;
 
              speed = 1/speed; //turn delay into speed multiplier
                if (isNaN(speed)) break;
              if (speed < 1e-5) break;
 
              if (speed > 1e2)  break;
                speed = 1/speed; //turn delay into speed multiplier
             
 
              this.speed = speed;
                if (speed < 1e-5) break;
              break;
 
                if (speed > 1e2)  break;
 
               
 
                this.speed = speed;
 
                break;
 
               


             case "strRight":
             case "strRight":
 
              res[2] = res[2].replace(plusSign, '%20');//encode + with % encode. does this work w/unicode
                res[2] = res[2].replace(plusSign, '%20');//encode + with % encode. does this work w/unicode
              res[2] = res[2].replace('%00', '');
 
              this.strRight = decodeURIComponent(res[2]);
                res[2] = res[2].replace('%00', '');
              break;
 
                this.strRight = decodeURIComponent(res[2]);
 
                break;
 
               


             case "strLeft":
             case "strLeft":
 
              res[2] = res[2].replace(plusSign, '%20');//encode + with % encode. does this work w/unicode
                res[2] = res[2].replace(plusSign, '%20');//encode + with % encode. does this work w/unicode
              res[2] = res[2].replace('%00', '');
 
              this.strLeft = decodeURIComponent(res[2]);
                res[2] = res[2].replace('%00', '');
              break;
 
                this.strLeft = decodeURIComponent(res[2]);
 
                break;
 
               


             case "strLinkText":
             case "strLinkText":
 
              res[2] = res[2].replace(plusSign, '%20');//encode + with % encode. does this work w/unicode
                res[2] = res[2].replace(plusSign, '%20');//encode + with % encode. does this work w/unicode
              res[2] = res[2].replace('%00', '');
 
              this.strLinkText = decodeURIComponent(res[2]);
                res[2] = res[2].replace('%00', '');
              break;
 
                this.strLinkText = decodeURIComponent(res[2]);
 
                break;
 
               


             case "strLinkURI":
             case "strLinkURI":
 
              //despite name, actually local page name, not a URI
                //despite name, actually local page name, not a URI
              var page = encodeURIComponent(res[2]); //note encode not decode
 
              if (page.match(/^special(%3A|:)userlogout/i)) break; //link is malicious
                var page = encodeURIComponent(res[2]); //note encode not decode
              this.strLinkURI = (page.length > 0) ? wgServer + wgArticlePath.replace("$1", page) : null;
 
              break;
                if (page.match(/^special(%3A|:)userlogout/i)) break; //link is malicious
 
                this.strLinkURI = (page.length > 0) ? wgServer + wgArticlePath.replace("$1", page) : null;
 
                break;
 
               


             case "engine":
             case "engine":
 
              //takes a literal engine name
                //takes a literal engine name
              var engName = decodeURIComponent(res[2]);
 
              if (engName.match(/^\d+$/)||engName.length === 0) break;
                var engName = decodeURIComponent(res[2]);
              this.engineNumb = (typeof Bawolff.Ticker.eng[engName] === "number" ? Bawolff.Ticker.eng[engName] : this.engineNumb);
 
                if (engName.match(/^\d+$/)||engName.length === 0) break;
 
                this.engineNumb = (typeof Bawolff.Ticker.eng[engName] === "number" ? Bawolff.Ticker.eng[engName] : this.engineNumb);
 
                  
                  
 
             default:  
             default:
              //throw new Error("not implemented");
 
                //throw new Error("not implemented");
 
         }
         }
     }
     }
     this.bigList = this.elm.getElementsByTagName("li"); //items to cycle ticker through
     this.bigList = this.elm.getElementsByTagName("li"); //items to cycle ticker through
     this.listLength = this.bigList.length;
     this.listLength = this.bigList.length;
}
}
Bawolff.Ticker.prototype.start = function() {
Bawolff.Ticker.prototype.start = function() {
//Start the ticker sets it up as well) separate from restart


    //Start the ticker sets it up as well) separate from restart
/*
 
Creates a <ul class="actualTicker"> - actualTicker
   
            <span class="tickerIntroduction">(into <a class="tickerLink">stuff</a>):</span> - realTicker  
 
            <li > ...</li> (dummyItem)
    /*
          </ul>
 
*/
    Creates a <ul class="actualTicker"> - actualTicker
 
    <span class="tickerIntroduction">(into <a class="tickerLink">stuff</a>):</span> - realTicker
 
    <li > ...</li> (dummyItem)
 
    </ul>
 
    */
 
   


     this.elm.style.display = "none"; //hide the list
     this.elm.style.display = "none"; //hide the list
   


     var actualTicker = this.tickerElm = document.createElement("ul");
     var actualTicker = this.tickerElm = document.createElement("ul");
 
     actualTicker.className = "actualTicker";  
     actualTicker.className = "actualTicker";
 
   


     var realTicker = document.createElement("Span");
     var realTicker = document.createElement("Span");
     realTicker.className = "tickerIntroduction";
     realTicker.className = "tickerIntroduction";
     realTicker.appendChild(document.createTextNode(this.strLeft));
     realTicker.appendChild(document.createTextNode(this.strLeft));
   


     var realTickerLink = document.createElement("a");
     var realTickerLink = document.createElement("a");
     realTickerLink.href= this.strLinkURI;
     realTickerLink.href= this.strLinkURI;
     realTickerLink.title = this.strLinkText;
     realTickerLink.title = this.strLinkText;
     realTickerLink.className = "tickerLink";
     realTickerLink.className = "tickerLink";
     realTickerLink.appendChild(document.createTextNode(this.strLinkText));
     realTickerLink.appendChild(document.createTextNode(this.strLinkText));
     realTicker.appendChild(realTickerLink);
     realTicker.appendChild(realTickerLink);
   


     realTicker.appendChild(document.createTextNode(this.strRight));
     realTicker.appendChild(document.createTextNode(this.strRight));
     //Start the 2nd (Actual) span
     //Start the 2nd (Actual) span
   


     actualTicker.appendChild(realTicker);
     actualTicker.appendChild(realTicker);
   


     var dummyItem = document.createElement("li");
     var dummyItem = document.createElement("li");
     actualTicker.appendChild(dummyItem);
     actualTicker.appendChild(dummyItem);
   


     this.elm.parentNode.insertBefore(actualTicker, this.elm);
     this.elm.parentNode.insertBefore(actualTicker, this.elm);
   


     this[Bawolff.Ticker.eng[this.engineNumb]](true); //Start the engine (ticker)
     this[Bawolff.Ticker.eng[this.engineNumb]](true); //Start the engine (ticker)


   
   


   


}
}
Bawolff.Ticker.prototype.pause = function () {
Bawolff.Ticker.prototype.pause = function () {
     this.curState = "paused";
     this.curState = "paused";
}
}
Bawolff.Ticker.prototype.restart = function () {
Bawolff.Ticker.prototype.restart = function () {
     if (this.curState !== "paused") return false;
     if (this.curState !== "paused") return false;
     this.curState = "ok";
     this.curState = "ok";
     window.setTimeout(this.resumeFunc, this.resumeDelay);
     window.setTimeout(this.resumeFunc, this.resumeDelay);
}
}






/*
/*
 
####
####
functions that are direct properties of the ticker constructor (not in prototype chain)
 
####
functions that are direct properties of the ticker constructor (not in prototype chain)
*/
 
####
 
*/
 
Bawolff.Ticker.eng = []; //Stores object mapping engine name to engine number
Bawolff.Ticker.eng = []; //Stores object mapping engine name to engine number
Bawolff.Ticker.registerEngine = function (engName, engine) {
Bawolff.Ticker.registerEngine = function (engName, engine) {
/*
This function takes care of hooking up engines (transitions)
into the system.
Arguments: String engName - name of engine (can not be a number)
          function engine - function containing engine code


    /*
Structure of what an engine should look like is noted somewhere (FIXME)
 
    This function takes care of hooking up engines (transitions)
 
    into the system.
 
    Arguments: String engName - name of engine (can not be a number)
 
    function engine - function containing engine code
 
   
 
    Structure of what an engine should look like is noted somewhere (FIXME)
 
   
 
    */


*/
     //to prevent screwing around with length property. considered an array index, even if passed a string with an interger value
     //to prevent screwing around with length property. considered an array index, even if passed a string with an interger value
     if (typeof engName !== "string" || (engName.match(/^\d+$/) !== null)) throw new Error("Invalid engine name. (can't be a number)");
     if (typeof engName !== "string" || (engName.match(/^\d+$/) !== null)) throw new Error("Invalid engine name. (can't be a number)");
   


     var te_s = Bawolff.Ticker.eng;
     var te_s = Bawolff.Ticker.eng;
     var listLen = te_s.length;
     var listLen = te_s.length;
     te_s[listLen] = "eng-" + engName;
     te_s[listLen] = "eng-" + engName;
     te_s[engName] = listLen;
     te_s[engName] = listLen;
   


     Bawolff.Ticker.prototype["eng-" + engName] = engine; //is that really the best way to add the engine functions?
     Bawolff.Ticker.prototype["eng-" + engName] = engine; //is that really the best way to add the engine functions?
}
}


Bawolff.Ticker.registerEngine("none", function(state) {
Bawolff.Ticker.registerEngine("none", function(state) {
/*
/*
This function is a dummy transition (no animation, but changes it)


This function is a dummy transition (no animation, but changes it)
called as:
tick() - advance one letter forward (unused)
tick(flase) - last tick before break
tick(true) - set up/first tick




called as:
*/
    if (!state) return true; //Shouldn't happen as null transition. normally can't do this


tick() - advance one letter forward (unused)
    if (state) {
        var newItem = this.bigList[this.listIndex].cloneNode(true); //true means deep
        this.tickerElm.replaceChild(newItem, this.tickerElm.lastChild);
        this.listIndex++;
        this.listIndex >= this.listLength ? this.listIndex = 0: true;


tick(flase) - last tick before break
        var cur_obj = this; //needed, as otherwise executes in context of window
        var resF = function() {
            cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, true);
        }
        var resD = 7000*cur_obj.speed*cur_obj.resetSpeed;
        if (this.curState === "paused") {
            this.resumeFunc = resF;
            this.resumeDelay = resD;
        } else { //assume "ok" but allow other states
            window.setTimeout(resF, resD);
        }


tick(true) - set up/first tick
    }
 
 
 
*/
 
                              if (!state) return true; //Shouldn't happen as null transition. normally can't do this
 
                             
 
                              if (state) {
 
                              var newItem = this.bigList[this.listIndex].cloneNode(true); //true means deep
 
                              this.tickerElm.replaceChild(newItem, this.tickerElm.lastChild);
 
                              this.listIndex++;
 
                              this.listIndex >= this.listLength ? this.listIndex = 0: true;
 
                             
 
                              var cur_obj = this; //needed, as otherwise executes in context of window
 
                              var resF = function() {
 
                              cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, true);
 
                              }
 
                              var resD = 7000*cur_obj.speed*cur_obj.resetSpeed;
 
                              if (this.curState === "paused") {
 
                              this.resumeFunc = resF;
 
                              this.resumeDelay = resD;
 
                              } else { //assume "ok" but allow other states
 
                              window.setTimeout(resF, resD);
 
                              }
 
                             
 
                              }
 
                             
 
                             
 
                              });




});


Bawolff.Ticker.registerEngine("std", function(state) {
Bawolff.Ticker.registerEngine("std", function(state) {
/*
/*
This function is a standard - 1 char at a time ticker


This function is a standard - 1 char at a time ticker
//this is not the greatest done tick function. In a paticular it expects a list formated
 
// a specific way, and does not handle exceptional conditions as it should
//this should be fixed later


//this is not the greatest done tick function. In a paticular it expects a list formated
called as:
tick() - advance one letter forward (unused)
tick(flase) - last tick before break
tick(true) - set up/first tick


// a specific way, and does not handle exceptional conditions as it should


//this should be fixed later
*/
    if (state === false) {
        this.tickerElm.lastChild.firstChild.firstChild.data = this.fullItem.substring(0,this.charIndex); // kill ...
        var cur_obj = this; //needed, as otherwise executes in context of window
        var resF = function() {
            cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, true);
        }
        var resD = 7000*cur_obj.speed*cur_obj.resetSpeed;
        if (this.curState === "paused") {
            this.resumeFunc = resF;
            this.resumeDelay = resD;
        } else { //assume "ok" but allow other states
            window.setTimeout(resF, resD);
        }
    }


    if (state === void 0) { //undefined as in normal tick
        if (this.charIndex === this.fullItem.length) {
            //if we're done


called as:
            var cur_obj = this; //needed, as otherwise executes in context of window
            var resF = function() {
                cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, false);
            }
            var resD = 60*cur_obj.speed*cur_obj.tickSpeed;
            if (this.curState === "paused") {
                this.resumeFunc = resF;
                this.resumeDelay = resD;
            } else { //assume "ok" but allow other states
                window.setTimeout(resF, resD);
            }
            return true;
        }


tick() - advance one letter forward (unused)
        this.charIndex++;
        this.tickerElm.lastChild.firstChild.firstChild.data = this.fullItem.substring(0,this.charIndex) + '...';


tick(flase) - last tick before break
        var cur_obj = this; //needed, as otherwise executes in context of window
        var resF = function() {
            cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj);
        }
        var resD = 60*cur_obj.speed*cur_obj.tickSpeed;
        if (this.curState === "paused") {
            this.resumeFunc = resF;
            this.resumeDelay = resD;
        } else { //assume "ok" but allow other states
            window.setTimeout(resF, resD);
        }
        return true;


tick(true) - set up/first tick
    }


    if (state) {
        var newItem = this.bigList[this.listIndex].cloneNode(true); //true means deep
//This still doesn't handle exceptional situations as good as possible, but it won't indef loop or freeze
        if (newItem.firstChild.firstChild !== null) { //Link and then text
            this.fullItem = newItem.firstChild.firstChild.data;   
            newItem.firstChild.firstChild.data = "";
        } else if (newItem.firstChild !== null) { //just text
            this.fullItem = newItem.firstChild.data;   
            newItem.replaceChild(document.createElement("span"), newItem.firstChild);
            newItem.firstChild.appendChild(document.createTextNode(""));
        } else { //input confused script. send error message
            newitem.insertBefore(document.createElement("strong"), null);
            newitem.firstChild.className = "error";
            newitem.firstChild.appendChild(document.createTextNode("Error: List item incorrectly formated for this ticker type. Please use unformatted text, or a single unformatted link (or otherwise one element deep)."));
            this.fullItem = newItem.firstChild.firstChild.data;
            newItem.firstChild.firstChild.data = "";
        }   
           
        this.charIndex = 0;


        this.tickerElm.replaceChild(newItem, this.tickerElm.lastChild);
        this.listIndex++;
        this.listIndex >= this.listLength ? this.listIndex = 0: true;


*/
        var cur_obj = this; //needed, as otherwise executes in context of window
 
        cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj);
                              if (state === false) {
 
                              this.tickerElm.lastChild.firstChild.firstChild.data = this.fullItem.substring(0,this.charIndex); // kill ...
 
                              var cur_obj = this; //needed, as otherwise executes in context of window
 
                              var resF = function() {
 
                              cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, true);
 
                              }
 
                              var resD = 7000*cur_obj.speed*cur_obj.resetSpeed;
 
                              if (this.curState === "paused") {
 
                              this.resumeFunc = resF;
 
                              this.resumeDelay = resD;
 
                              } else { //assume "ok" but allow other states
 
                              window.setTimeout(resF, resD);
 
                              }
 
                              }
 
                             
 
                              if (state === void 0) { //undefined as in normal tick
 
                              if (this.charIndex === this.fullItem.length) {
 
                              //if we're done
 
                             
 
                              var cur_obj = this; //needed, as otherwise executes in context of window
 
                              var resF = function() {
 
                              cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, false);
 
                              }
 
                              var resD = 60*cur_obj.speed*cur_obj.tickSpeed;
 
                              if (this.curState === "paused") {
 
                              this.resumeFunc = resF;
 
                              this.resumeDelay = resD;
 
                              } else { //assume "ok" but allow other states
 
                              window.setTimeout(resF, resD);
 
                              }
 
                              return true;
 
                              }
 
                             
 
                              this.charIndex++;
 
                              this.tickerElm.lastChild.firstChild.firstChild.data = this.fullItem.substring(0,this.charIndex) + '...';
 
                             
 
                              var cur_obj = this; //needed, as otherwise executes in context of window
 
                              var resF = function() {
 
                              cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj);
 
                              }
 
                              var resD = 60*cur_obj.speed*cur_obj.tickSpeed;
 
                              if (this.curState === "paused") {
 
                              this.resumeFunc = resF;
 
                              this.resumeDelay = resD;
 
                              } else { //assume "ok" but allow other states
 
                              window.setTimeout(resF, resD);
 
                              }
 
                              return true;
 
                             
 
                              }
 
                             
 
                              if (state) {
 
                              var newItem = this.bigList[this.listIndex].cloneNode(true); //true means deep
 
                              //This still doesn't handle exceptional situations as good as possible, but it won't indef loop or freeze
 
                              if (newItem.firstChild.firstChild !== null) { //Link and then text
 
                              this.fullItem = newItem.firstChild.firstChild.data;
 
                              newItem.firstChild.firstChild.data = "";
 
                              } else if (newItem.firstChild !== null) { //just text
 
                              this.fullItem = newItem.firstChild.data;
 
                              newItem.replaceChild(document.createElement("span"), newItem.firstChild);
 
                              newItem.firstChild.appendChild(document.createTextNode(""));
 
                              } else { //input confused script. send error message
 
                              newitem.insertBefore(document.createElement("strong"), null);
 
                              newitem.firstChild.className = "error";
 
                              newitem.firstChild.appendChild(document.createTextNode("Error: List item incorrectly formated for this ticker type. Please use unformatted text, or a single unformatted link (or otherwise one element deep)."));
 
                              this.fullItem = newItem.firstChild.firstChild.data;
 
                              newItem.firstChild.firstChild.data = "";
 
                              }
 
                             
 
                              this.charIndex = 0;
 
                             
 
                              this.tickerElm.replaceChild(newItem, this.tickerElm.lastChild);
 
                              this.listIndex++;
 
                              this.listIndex >= this.listLength ? this.listIndex = 0: true;
 
                             
 
                              var cur_obj = this; //needed, as otherwise executes in context of window
 
                              cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj);
 
                             
 
                              }
 
                             
 
                             
 
                              });


    }




});




Bawolff.Ticker.registerEngine("fade", function(state) {
Bawolff.Ticker.registerEngine("fade", function(state) {
/*
/*
This function is a fade in effect


This function is a fade in effect
This is relies on Css3+MSIE extentions, and thus isn't all that cross browser compatible
 
 
This is relies on Css3+MSIE extentions, and thus isn't all that cross browser compatible
 


called as:
called as:
tick() - advance one letter forward (unused)
tick(flase) - last tick before break
tick(true) - set up/first tick


tick() - advance one letter forward (unused)


tick(flase) - last tick before break
*/
 
tick(true) - set up/first tick


   
   
    if (state === false) { //sleep
        var cur_obj = this; //needed, as otherwise executes in context of window
        var resF = function() {
            cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, true);
        }
        var resD = 7000*cur_obj.speed*cur_obj.resetSpeed;
        if (this.curState === "paused") {
            this.resumeFunc = resF;
            this.resumeDelay = resD;
        } else { //assume "ok" but allow other states
            window.setTimeout(resF, resD);
        }
    }


    if (state === void 0) { //undefined as in normal tick
        if (this.charIndex === 100) {
            //if we're done


*/
            var cur_obj = this; //needed, as otherwise executes in context of window
            var resF = function() {
                cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, false);
            }
            var resD = 40*cur_obj.speed*cur_obj.tickSpeed;
            if (this.curState === "paused") {
                this.resumeFunc = resF;
                this.resumeDelay = resD;
            } else { //assume "ok" but allow other states
                window.setTimeout(resF, resD);
            }
            return true;
        }


                             
        this.charIndex++;
        Bawolff.setTrans(this.tickerElm.lastChild, this.charIndex/100);


                             
        var cur_obj = this; //needed, as otherwise executes in context of window
        var resF = function() {
            cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj);
        }
        var resD = 40*cur_obj.speed*cur_obj.tickSpeed;
        if (this.curState === "paused") {
            this.resumeFunc = resF;
            this.resumeDelay = resD;
        } else { //assume "ok" but allow other states
            window.setTimeout(resF, resD);
        }
        return true;


                              if (state === false) { //sleep
    }


                              var cur_obj = this; //needed, as otherwise executes in context of window
        if (state) {


                              var resF = function() {
        this.charIndex = 0;


                              cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, true);
        var newItem = this.bigList[this.listIndex].cloneNode(true); //true means deep
 
        Bawolff.setTrans(newItem, 0);
                              }
        (navigator && navigator.appName === "Microsoft Internet Explorer") ? newItem.style.display = 'inline-block' : true;
 
        this.tickerElm.replaceChild(newItem, this.tickerElm.lastChild);
                              var resD = 7000*cur_obj.speed*cur_obj.resetSpeed;
        this.listIndex++;
 
        this.listIndex >= this.listLength ? this.listIndex = 0: true;
                              if (this.curState === "paused") {
 
                              this.resumeFunc = resF;
 
                              this.resumeDelay = resD;
 
                              } else { //assume "ok" but allow other states
 
                              window.setTimeout(resF, resD);
 
                              }
 
                              }
 
                             
 
                              if (state === void 0) { //undefined as in normal tick
 
                              if (this.charIndex === 100) {
 
                              //if we're done
 
                             
 
                              var cur_obj = this; //needed, as otherwise executes in context of window
 
                              var resF = function() {
 
                              cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, false);
 
                              }
 
                              var resD = 40*cur_obj.speed*cur_obj.tickSpeed;
 
                              if (this.curState === "paused") {
 
                              this.resumeFunc = resF;
 
                              this.resumeDelay = resD;
 
                              } else { //assume "ok" but allow other states
 
                              window.setTimeout(resF, resD);
 
                              }
 
                              return true;
 
                              }
 
                             
 
                              this.charIndex++;
 
                              Bawolff.setTrans(this.tickerElm.lastChild, this.charIndex/100);
 
                             
 
                              var cur_obj = this; //needed, as otherwise executes in context of window
 
                              var resF = function() {
 
                              cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj);
 
                              }
 
                              var resD = 40*cur_obj.speed*cur_obj.tickSpeed;
 
                              if (this.curState === "paused") {
 
                              this.resumeFunc = resF;
 
                              this.resumeDelay = resD;
 
                              } else { //assume "ok" but allow other states
 
                              window.setTimeout(resF, resD);
 
                              }
 
                              return true;
 
                             
 
                              }
 
                             
 
                              if (state) {
 
                             
 
                              this.charIndex = 0;
 
                             
 
                              var newItem = this.bigList[this.listIndex].cloneNode(true); //true means deep
 
                              Bawolff.setTrans(newItem, 0);
 
                              (navigator && navigator.appName === "Microsoft Internet Explorer") ? newItem.style.display = 'inline-block' : true;
 
                              this.tickerElm.replaceChild(newItem, this.tickerElm.lastChild);
 
                              this.listIndex++;
 
                              this.listIndex >= this.listLength ? this.listIndex = 0: true;
 
                             
 
                             
 
                              var cur_obj = this; //needed, as otherwise executes in context of window
 
                              cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj);
 
                             
 
                              }
 
                             
 
                              });




        var cur_obj = this; //needed, as otherwise executes in context of window
        cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj);


    }


});






/*Not really used. To make all pause call Bawolff.Ticker.allDo("pause");
/*Not really used. To make all pause call Bawolff.Ticker.allDo("pause");
 
Bawolff.Ticker.allDo =  function (func) {
Bawolff.Ticker.allDo =  function (func) {
    var l = Bawolff.Ticker.allTickers.length;
 
    for (var i=0;i<l;i++) {
var l = Bawolff.Ticker.allTickers.length;
        Bawolff.Ticker.allTickers[i][func]();
 
    }
for (var i=0;i<l;i++) {
}
 
*/
Bawolff.Ticker.allTickers[i][func]();
 
}
 
}
 
*/
 
Bawolff.Ticker.allDoPause =  function () {
Bawolff.Ticker.allDoPause =  function () {
     var l = Bawolff.Ticker.allTickers.length;
     var l = Bawolff.Ticker.allTickers.length;
     for (var i=0;i<l;i++) {
     for (var i=0;i<l;i++) {
         Bawolff.Ticker.allTickers[i].pause();
         Bawolff.Ticker.allTickers[i].pause();
     }
     }
}
}
Bawolff.Ticker.allDoRestart =  function () {
Bawolff.Ticker.allDoRestart =  function () {
     var l = Bawolff.Ticker.allTickers.length;
     var l = Bawolff.Ticker.allTickers.length;
     for (var i=0;i<l;i++) {
     for (var i=0;i<l;i++) {
         Bawolff.Ticker.allTickers[i].restart();
         Bawolff.Ticker.allTickers[i].restart();
     }
     }
}
}


Bawolff.setTrans = function(elm, opacity/*1 being full visible, 0 being invisible*/) {
Bawolff.setTrans = function(elm, opacity/*1 being full visible, 0 being invisible*/) {
     if (!Bawolff.setTrans.opacityMethod) {
     if (!Bawolff.setTrans.opacityMethod) {
         //standard way (CSS3)
         //standard way (CSS3)
         if (elm.style && (typeof elm.style.opacity != "undefined")) {
         if (elm.style && (typeof elm.style.opacity != "undefined")) {
             Bawolff.setTrans.opacityMethod = 1;
             Bawolff.setTrans.opacityMethod = 1;
         }
         }
         else if (elm.style && (typeof elm.style.MozOpacity != "undefined")) { //old moz
         else if (elm.style && (typeof elm.style.MozOpacity != "undefined")) { //old moz
             Bawolff.setTrans.opacityMethod = 2;
             Bawolff.setTrans.opacityMethod = 2;
         }
         }
         else if (elm.style && (typeof elm.style.filter != "undefined")) {
         else if (elm.style && (typeof elm.style.filter != "undefined")) {
             Bawolff.setTrans.opacityMethod = 3;
             Bawolff.setTrans.opacityMethod = 3;
         }
         }
         else {
         else {
              
              
             //throw new Error("opacity is not supported on this platform (or this script needs to be fixed to include support on your platform");
             //throw new Error("opacity is not supported on this platform (or this script needs to be fixed to include support on your platform");
         }
         }
     }
     }
     switch (Bawolff.setTrans.opacityMethod) {
     switch (Bawolff.setTrans.opacityMethod) {
         case 1:
         case 1:
             elm.style.opacity = opacity;
             elm.style.opacity = opacity;
             break;
             break;
         case 2:
         case 2:
             elm.style.MozOpacity = opacity;
             elm.style.MozOpacity = opacity;
             break;
             break;
         case 3:
         case 3:
             elm.style.filter = "alpha(opacity=" + opacity*100 + ")"; //No guarantees this works
             elm.style.filter = "alpha(opacity=" + opacity*100 + ")"; //No guarantees this works
             break;
             break;
         default:
         default:
             //do nothing, so other browsers not inconvianced
             //do nothing, so other browsers not inconvianced
             break;
             break;
     }
     }
}
}


Bawolff.Ticker.init = function () {
Bawolff.Ticker.init = function () {
     //handled elsewhere if (!document.getElementById("enableTickers")) return false; //Bcause getting all elements by class is expensive
     //handled elsewhere if (!document.getElementById("enableTickers")) return false; //Bcause getting all elements by class is expensive
   


     var tickerList = getElementsByClassName(document.body, "div", "isATicker");
     var tickerList = getElementsByClassName(document.body, "div", "isATicker");
     var l = tickerList.length;
     var l = tickerList.length;
     var i = 0; //index of which ticker we are on.
     var i = 0; //index of which ticker we are on.
   


     Bawolff.Ticker.allTickers = [];
     Bawolff.Ticker.allTickers = [];
   


     if (document.getElementById("singleTickerForPage")) { //for simplifications. if only one on page
     if (document.getElementById("singleTickerForPage")) { //for simplifications. if only one on page
         Bawolff.Ticker.allTickers[i] = new Bawolff.Ticker;
         Bawolff.Ticker.allTickers[i] = new Bawolff.Ticker;
         Bawolff.Ticker.allTickers[i].elm = document.getElementById("singleTickerForPage");
         Bawolff.Ticker.allTickers[i].elm = document.getElementById("singleTickerForPage");
         Bawolff.Ticker.allTickers[i].arg = document.getElementById("singleTickerForPage").className;
         Bawolff.Ticker.allTickers[i].arg = document.getElementById("singleTickerForPage").className;
       


         Bawolff.Ticker.allTickers[i].setUp();
         Bawolff.Ticker.allTickers[i].setUp();
         Bawolff.Ticker.allTickers[i].start();
         Bawolff.Ticker.allTickers[i].start();
         i++;
         i++;
     }
     }
   


     for (;i<l;i++) {
     for (;i<l;i++) {
         Bawolff.Ticker.allTickers[i] = new Bawolff.Ticker;
         Bawolff.Ticker.allTickers[i] = new Bawolff.Ticker;
         Bawolff.Ticker.allTickers[i].elm = tickerList[i];
         Bawolff.Ticker.allTickers[i].elm = tickerList[i];
         Bawolff.Ticker.allTickers[i].arg = tickerList[i].className;
         Bawolff.Ticker.allTickers[i].arg = tickerList[i].className;
       


         Bawolff.Ticker.allTickers[i].setUp();
         Bawolff.Ticker.allTickers[i].setUp();
         Bawolff.Ticker.allTickers[i].start();
         Bawolff.Ticker.allTickers[i].start();
     }
     }
   
      
      


   


     if (!(navigator && navigator.appName === "Microsoft Internet Explorer")) {
     if (!(navigator && navigator.appName === "Microsoft Internet Explorer")) {
 
    //blur sometimes fires too much on MSIE and makes things not work
        //blur sometimes fires too much on MSIE and makes things not work
    hookEvent('blur', Bawolff.Ticker.allDoPause);//stop anim on loss of focus, and restart it on gain of focus. hookEvent from wikibits
 
    hookEvent('focus', Bawolff.Ticker.allDoRestart);
        hookEvent('blur', Bawolff.Ticker.allDoPause);//stop anim on loss of focus, and restart it on gain of focus. hookEvent from wikibits
 
        hookEvent('focus', Bawolff.Ticker.allDoRestart);
 
     }
     }
   


}
}
Bawolff.Ticker.init(); //already from a load event
Bawolff.Ticker.init(); //already from a load event

Version actuelle datée du 4 mai 2014 à 23:41

/*globals Bawolff getElementsByClassName hookEvent wgServer wgArticlePath addLoadEvent*/
/*
__This is Ticker2-0.9__

This is an attempt to redesign the ticker system. I believe that well the current ticker system is a good idea, it can be improved on

Then again, this may just be overthinking things. time will tell.
######
Design goals
*modular - should be able to have more then one transition between items
*user configurable - should be able to customize on wiki (aka {{ticker|for=Africa|speed=...}})
**The user should never have to do anything in js
**Downside: have to be extra-careful about XSS
*fast - performance was an issue with the other system

cavets:
*Doesn't handle multilevel lists well
*onblur/onfocus?? (works in opera, firefox, broken in MSIE)

Todo:
*change intro string to a control string with escape sequences (think printf)
**Play/pause button
*better fade transitions (current one kind of sucks)
*Change state system to number instead of T,F,U. 
*make fade work in IE
*multiple speed variables

####

Note: Setting disable_ticker2 to true will disable the ticker.
*/

//to avoid name conflicts (we already have way to many global variables as is imho)
//Everything should be a member of Bawolff.Ticker
if (typeof Bawolff !== "object") Bawolff = {};
if (typeof Bawolff.Ticker === "Object") throw new Error("Can not initilize ticker. Already initilized, or someone stole its name!");

Bawolff.Ticker = function() {
/*
This is the constructor function for new Ticker objects. Call as:
var some_ticker_object = new Bawolff.Ticker;

Its primary purpose is to set defaults and create new Ticker objects. It takes no arguments.
Ticker Objects should have the following methods:
*setUp - set up ticker properties (and does sanity checks)
*engines - functions for transitions
probably more
*/

    var t_s = Bawolff.Ticker; //shortcut

    this.arg = ""; //defaults to none, if uspecified. (should this be an arg to this function?). unphrased definition of options
    this.elm = null; //element to work ticker magic on. setUp method will throw an error if this isn't set by then 

    //method setUp will take care of these. These are the actual options (defaults here)

    this.engineNumb = t_s.eng.none; //constant representing engine number
    this.speed = 1; //float - multiplication factor
    //Probably can't set these to null through wiki
    this.strLeft = "Dernières nouvelles ("; //Intro string part 1 - null for none
    this.strRight = ") :"; //intro part 3 - null for none
    this.strLinkURI = "//fr.wikinews.org/wiki/Utilisateur:TheFearow/Tickersource"; //part 2 url
    this.strLinkText = "liste complète"; //part 2 text. null for no link.
    this.schowControls = false; //pause/restart
    this.tickSpeed = 1;
    this.resetSpeed=1;

    //Internal thingies (don't change)
    this.listIndex = 0;
    this.charIndex = 0;
    this.curState = "ok"; //for pausing
    this.resumeFunc = null; //storage for resume function
    this.resumeDelay = 0; //wait time before executing

}

Bawolff.Ticker.prototype.setUp = function() {
/*
This function takes no arguments. call as:
some_ticker_object.setUp();

It initilizes ticker options based on what the class name of the ticker element is.
The options are (mostly) encoded as follows in a class attribute:

Ticker_<option name- no dashes, underscore allowed>-<urlencoded option value(must end in alphanumeric or _ character)>

options are separated by a space (each is a different class).
###################################################
##This function must be extra careful not to be  ##
##vulnurable to an xss attack as it directly     ##
##deals with editable on wiki data, that could be##
##malicious! be careful                          ##
###################################################

*/


    //check to see if we really have an element
    if (!(this.elm && this.elm.nodeType && this.elm.nodeType === 1)) throw new Error("no element, or invalid element for ticker");

    var propMatch = /\bTicker_(\w+)-(\S*)\b/g;
    var res;
    var plusSign = /\+/g;
    
    while(res = propMatch.exec(this.arg)) {
       switch(res[1]) { //option name
            case "speed":
              var speed = parseFloat(decodeURIComponent(res[2]));
              if (isNaN(speed)) break;
              speed = 1/speed; //turn delay into speed multiplier
              if (speed < 1e-5) break;
              if (speed > 1e2)  break;
              
              this.speed = speed;
              break;

            case "strRight":
              res[2] = res[2].replace(plusSign, '%20');//encode + with % encode. does this work w/unicode
              res[2] = res[2].replace('%00', '');
              this.strRight = decodeURIComponent(res[2]);
              break;

            case "strLeft":
              res[2] = res[2].replace(plusSign, '%20');//encode + with % encode. does this work w/unicode
              res[2] = res[2].replace('%00', '');
              this.strLeft = decodeURIComponent(res[2]);
              break;

            case "strLinkText":
              res[2] = res[2].replace(plusSign, '%20');//encode + with % encode. does this work w/unicode
              res[2] = res[2].replace('%00', '');
              this.strLinkText = decodeURIComponent(res[2]);
              break;

            case "strLinkURI":
              //despite name, actually local page name, not a URI
              var page = encodeURIComponent(res[2]); //note encode not decode
              if (page.match(/^special(%3A|:)userlogout/i)) break; //link is malicious
              this.strLinkURI = (page.length > 0) ? wgServer + wgArticlePath.replace("$1", page) : null;
              break;

            case "engine":
              //takes a literal engine name
              var engName = decodeURIComponent(res[2]);
              if (engName.match(/^\d+$/)||engName.length === 0) break;
              this.engineNumb = (typeof Bawolff.Ticker.eng[engName] === "number" ? Bawolff.Ticker.eng[engName] : this.engineNumb);
                
            default: 
              //throw new Error("not implemented");
        }
    }
    this.bigList = this.elm.getElementsByTagName("li"); //items to cycle ticker through
    this.listLength = this.bigList.length;
}
Bawolff.Ticker.prototype.start = function() {
//Start the ticker sets it up as well) separate from restart

/*
Creates a <ul class="actualTicker"> - actualTicker
            <span class="tickerIntroduction">(into <a class="tickerLink">stuff</a>):</span> - realTicker 
            <li > ...</li> (dummyItem)
          </ul>
*/

    this.elm.style.display = "none"; //hide the list

    var actualTicker = this.tickerElm = document.createElement("ul");
    actualTicker.className = "actualTicker";    

    var realTicker = document.createElement("Span");
    realTicker.className = "tickerIntroduction";
    realTicker.appendChild(document.createTextNode(this.strLeft));

    var realTickerLink = document.createElement("a");
    realTickerLink.href= this.strLinkURI;
    realTickerLink.title = this.strLinkText;
    realTickerLink.className = "tickerLink";
    realTickerLink.appendChild(document.createTextNode(this.strLinkText));
    realTicker.appendChild(realTickerLink);

    realTicker.appendChild(document.createTextNode(this.strRight));
    //Start the 2nd (Actual) span

    actualTicker.appendChild(realTicker);

    var dummyItem = document.createElement("li");
    actualTicker.appendChild(dummyItem);

    this.elm.parentNode.insertBefore(actualTicker, this.elm);

    this[Bawolff.Ticker.eng[this.engineNumb]](true); //Start the engine (ticker)



}
Bawolff.Ticker.prototype.pause = function () {
    this.curState = "paused";
}
Bawolff.Ticker.prototype.restart = function () {
    if (this.curState !== "paused") return false;
    this.curState = "ok";
    window.setTimeout(this.resumeFunc, this.resumeDelay);
}



/*
####
functions that are direct properties of the ticker constructor (not in prototype chain)
####
*/
Bawolff.Ticker.eng = []; //Stores object mapping engine name to engine number
Bawolff.Ticker.registerEngine = function (engName, engine) {
/*
This function takes care of hooking up engines (transitions)
into the system.
Arguments: String engName - name of engine (can not be a number)
           function engine - function containing engine code

Structure of what an engine should look like is noted somewhere (FIXME)

*/
    //to prevent screwing around with length property. considered an array index, even if passed a string with an interger value
    if (typeof engName !== "string" || (engName.match(/^\d+$/) !== null)) throw new Error("Invalid engine name. (can't be a number)");

    var te_s = Bawolff.Ticker.eng;
    var listLen = te_s.length;
    te_s[listLen] = "eng-" + engName;
    te_s[engName] = listLen;

    Bawolff.Ticker.prototype["eng-" + engName] = engine; //is that really the best way to add the engine functions?
}

Bawolff.Ticker.registerEngine("none", function(state) {
/*
This function is a dummy transition (no animation, but changes it)

called as:
tick() - advance one letter forward (unused)
tick(flase) - last tick before break
tick(true) - set up/first tick


*/
    if (!state) return true; //Shouldn't happen as null transition. normally can't do this

    if (state) {
        var newItem = this.bigList[this.listIndex].cloneNode(true); //true means deep
        this.tickerElm.replaceChild(newItem, this.tickerElm.lastChild);
        this.listIndex++;
        this.listIndex >= this.listLength ? this.listIndex = 0: true;

        var cur_obj = this; //needed, as otherwise executes in context of window
        var resF = function() {
            cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, true);
        }
        var resD = 7000*cur_obj.speed*cur_obj.resetSpeed;
        if (this.curState === "paused") {
            this.resumeFunc = resF;
            this.resumeDelay = resD;
        } else { //assume "ok" but allow other states
            window.setTimeout(resF, resD);
        }

    }


});

Bawolff.Ticker.registerEngine("std", function(state) {
/*
This function is a standard - 1 char at a time ticker

//this is not the greatest done tick function. In a paticular it expects a list formated
// a specific way, and does not handle exceptional conditions as it should
//this should be fixed later

called as:
tick() - advance one letter forward (unused)
tick(flase) - last tick before break
tick(true) - set up/first tick


*/
    if (state === false) {
        this.tickerElm.lastChild.firstChild.firstChild.data = this.fullItem.substring(0,this.charIndex); // kill ...
        var cur_obj = this; //needed, as otherwise executes in context of window
        var resF = function() {
            cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, true);
        }
        var resD = 7000*cur_obj.speed*cur_obj.resetSpeed;
        if (this.curState === "paused") {
            this.resumeFunc = resF;
            this.resumeDelay = resD;
        } else { //assume "ok" but allow other states
            window.setTimeout(resF, resD);
        }
    }

    if (state === void 0) { //undefined as in normal tick
        if (this.charIndex === this.fullItem.length) {
            //if we're done

            var cur_obj = this; //needed, as otherwise executes in context of window
            var resF = function() {
                cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, false);
            }
            var resD = 60*cur_obj.speed*cur_obj.tickSpeed;
            if (this.curState === "paused") {
                this.resumeFunc = resF;
                this.resumeDelay = resD;
            } else { //assume "ok" but allow other states
                window.setTimeout(resF, resD);
            }
            return true;
        }

        this.charIndex++;
        this.tickerElm.lastChild.firstChild.firstChild.data = this.fullItem.substring(0,this.charIndex) + '...';

        var cur_obj = this; //needed, as otherwise executes in context of window
        var resF = function() {
            cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj);
        }
        var resD = 60*cur_obj.speed*cur_obj.tickSpeed;
        if (this.curState === "paused") {
            this.resumeFunc = resF;
            this.resumeDelay = resD;
        } else { //assume "ok" but allow other states
            window.setTimeout(resF, resD);
        }
        return true;

    }

    if (state) {
        var newItem = this.bigList[this.listIndex].cloneNode(true); //true means deep
//This still doesn't handle exceptional situations as good as possible, but it won't indef loop or freeze
        if (newItem.firstChild.firstChild !== null) { //Link and then text
            this.fullItem = newItem.firstChild.firstChild.data;    
            newItem.firstChild.firstChild.data = "";
        } else if (newItem.firstChild !== null) { //just text
            this.fullItem = newItem.firstChild.data;    
            newItem.replaceChild(document.createElement("span"), newItem.firstChild);
            newItem.firstChild.appendChild(document.createTextNode(""));
        } else { //input confused script. send error message
            newitem.insertBefore(document.createElement("strong"), null);
            newitem.firstChild.className = "error";
            newitem.firstChild.appendChild(document.createTextNode("Error: List item incorrectly formated for this ticker type. Please use unformatted text, or a single unformatted link (or otherwise one element deep)."));
            this.fullItem = newItem.firstChild.firstChild.data;
            newItem.firstChild.firstChild.data = "";
        }    
            
        this.charIndex = 0;

        this.tickerElm.replaceChild(newItem, this.tickerElm.lastChild);
        this.listIndex++;
        this.listIndex >= this.listLength ? this.listIndex = 0: true;

        var cur_obj = this; //needed, as otherwise executes in context of window
        cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj);

    }


});


Bawolff.Ticker.registerEngine("fade", function(state) {
/*
This function is a fade in effect

This is relies on Css3+MSIE extentions, and thus isn't all that cross browser compatible

called as:
tick() - advance one letter forward (unused)
tick(flase) - last tick before break
tick(true) - set up/first tick


*/

 
    if (state === false) { //sleep
        var cur_obj = this; //needed, as otherwise executes in context of window
        var resF = function() {
            cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, true);
        }
        var resD = 7000*cur_obj.speed*cur_obj.resetSpeed;
        if (this.curState === "paused") {
            this.resumeFunc = resF;
            this.resumeDelay = resD;
        } else { //assume "ok" but allow other states
            window.setTimeout(resF, resD);
        }
    }

    if (state === void 0) { //undefined as in normal tick
        if (this.charIndex === 100) {
            //if we're done

            var cur_obj = this; //needed, as otherwise executes in context of window
            var resF = function() {
                cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj, false);
            }
            var resD = 40*cur_obj.speed*cur_obj.tickSpeed;
            if (this.curState === "paused") {
                this.resumeFunc = resF;
                this.resumeDelay = resD;
            } else { //assume "ok" but allow other states
                window.setTimeout(resF, resD);
            }
            return true;
        }

        this.charIndex++;
        Bawolff.setTrans(this.tickerElm.lastChild, this.charIndex/100);

        var cur_obj = this; //needed, as otherwise executes in context of window
        var resF = function() {
            cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj);
        }
        var resD = 40*cur_obj.speed*cur_obj.tickSpeed;
        if (this.curState === "paused") {
            this.resumeFunc = resF;
            this.resumeDelay = resD;
        } else { //assume "ok" but allow other states
            window.setTimeout(resF, resD);
        }
        return true;

    }

        if (state) {

        this.charIndex = 0;

        var newItem = this.bigList[this.listIndex].cloneNode(true); //true means deep
        Bawolff.setTrans(newItem, 0);
        (navigator && navigator.appName === "Microsoft Internet Explorer") ? newItem.style.display = 'inline-block' : true;
        this.tickerElm.replaceChild(newItem, this.tickerElm.lastChild);
        this.listIndex++;
        this.listIndex >= this.listLength ? this.listIndex = 0: true;


        var cur_obj = this; //needed, as otherwise executes in context of window
        cur_obj[Bawolff.Ticker.eng[cur_obj.engineNumb]].call(cur_obj);

    }

});



/*Not really used. To make all pause call Bawolff.Ticker.allDo("pause");
Bawolff.Ticker.allDo =  function (func) {
    var l = Bawolff.Ticker.allTickers.length;
    for (var i=0;i<l;i++) {
        Bawolff.Ticker.allTickers[i][func]();
    }
}
*/
Bawolff.Ticker.allDoPause =  function () {
    var l = Bawolff.Ticker.allTickers.length;
    for (var i=0;i<l;i++) {
        Bawolff.Ticker.allTickers[i].pause();
    }
}
Bawolff.Ticker.allDoRestart =  function () {
    var l = Bawolff.Ticker.allTickers.length;
    for (var i=0;i<l;i++) {
        Bawolff.Ticker.allTickers[i].restart();
    }
}

Bawolff.setTrans = function(elm, opacity/*1 being full visible, 0 being invisible*/) {
    if (!Bawolff.setTrans.opacityMethod) {
        //standard way (CSS3)
        if (elm.style && (typeof elm.style.opacity != "undefined")) {
            Bawolff.setTrans.opacityMethod = 1;
        }
        else if (elm.style && (typeof elm.style.MozOpacity != "undefined")) { //old moz
            Bawolff.setTrans.opacityMethod = 2;
        }
        else if (elm.style && (typeof elm.style.filter != "undefined")) {
            Bawolff.setTrans.opacityMethod = 3;
        }
        else {
            
            //throw new Error("opacity is not supported on this platform (or this script needs to be fixed to include support on your platform");
        }
    }
    switch (Bawolff.setTrans.opacityMethod) {
        case 1:
            elm.style.opacity = opacity;
            break;
        case 2:
            elm.style.MozOpacity = opacity;
            break;
        case 3:
            elm.style.filter = "alpha(opacity=" + opacity*100 + ")"; //No guarantees this works
            break;
        default:
            //do nothing, so other browsers not inconvianced
            break;
    }
}

Bawolff.Ticker.init = function () {
    //handled elsewhere if (!document.getElementById("enableTickers")) return false; //Bcause getting all elements by class is expensive

    var tickerList = getElementsByClassName(document.body, "div", "isATicker");
    var l = tickerList.length;
    var i = 0; //index of which ticker we are on.

    Bawolff.Ticker.allTickers = [];

    if (document.getElementById("singleTickerForPage")) { //for simplifications. if only one on page
        Bawolff.Ticker.allTickers[i] = new Bawolff.Ticker;
        Bawolff.Ticker.allTickers[i].elm = document.getElementById("singleTickerForPage");
        Bawolff.Ticker.allTickers[i].arg = document.getElementById("singleTickerForPage").className;

        Bawolff.Ticker.allTickers[i].setUp();
        Bawolff.Ticker.allTickers[i].start();
        i++;
    }

    for (;i<l;i++) {
        Bawolff.Ticker.allTickers[i] = new Bawolff.Ticker;
        Bawolff.Ticker.allTickers[i].elm = tickerList[i];
        Bawolff.Ticker.allTickers[i].arg = tickerList[i].className;

        Bawolff.Ticker.allTickers[i].setUp();
        Bawolff.Ticker.allTickers[i].start();
    }
    


    if (!(navigator && navigator.appName === "Microsoft Internet Explorer")) {
    //blur sometimes fires too much on MSIE and makes things not work
    hookEvent('blur', Bawolff.Ticker.allDoPause);//stop anim on loss of focus, and restart it on gain of focus. hookEvent from wikibits
    hookEvent('focus', Bawolff.Ticker.allDoRestart);
    }

}
Bawolff.Ticker.init(); //already from a load event