function Slider(args){
//read & apply arguments
this.args = args;
this.setArgs();
//store dom elements
this.container = document.getElementById(args.containerid);
this.contentWrapper = getElements('content_wrapper','DIV',this.container)[0];
this.contentLists = this.container.getElementsByTagName('UL');
//set up the slider
var slider = this;
setTimeout(function(){slider.initialize()},750);
}/* Argument Setup
-------------- */
Slider.prototype.setArgs = function(){
//required arguments
this.groupSize = this.args.groupsize;
this.direction = this.args.direction;
this.effectType = this.args.effect || false;
//optional arguments
this.hasGroupNav = (this.args.hasgroupnav === null) ? true : this.args.hasgroupnav;
this.hasLoop = this.args.hasloop || false;
this.hasAutoAdvance = this.args.hasautoadvance || false;
this.advanceSeconds = this.args.advanceseconds || 5;
this.hasTabs = this.args.hastabs || false;
this.tabs = this.args.tabs; //required for tabbed modules
this.speed = this.args.speed || 7;
}/* Initialization
-------------- */
Slider.prototype.initialize = function(){
this.setContext(0); //set the context of the content initially displayed in the slider to the first list
this.activeGroup = 1; //set a flag used as a current group indicator
this.assembleScrollControls(); //create a group of slider controls which applies to this content
this.updateControlDisplay(); //update display of the controls to match behavior of this module;
if(this.hasTabs) this.assembleTabs( ); //for sliders used to display more than one context of content, create the tab controls
this.setupLayout(); //set up the layout properties constraining container and content list
if(this.hasAutoAdvance) this.autoAdvance(); //if this slider autoadvances, begin the process
}/* Set the Context of Displayed Content
------------------------------------ */
Slider.prototype.setContext = function(context_index){
this.contentList = this.contentLists[context_index]; //set the active content list
//capture useful properties of the content list
this.contentItems = this.contentList.getElementsByTagName('li');
this.numItems = this.contentItems.length;
this.numGroups = Math.ceil(this.numItems/this.groupSize);
this.itemWidth = this.getItemWidth();
this.itemHeight = this.getItemHeight();
}/* Scroll Control Creation & Event Handling
------------------------------------- */
Slider.prototype.assembleScrollControls = function(){
var moduleObject = this;
if( this.numGroups > 1 ){ //only create controls if they are needed
//create & register handlers for next/previous controls
this.nextTrigger = this.createTrigger('slide_control_next');
this.prevTrigger = this.createTrigger('slide_control_previous');
if(window.addEventListener){
this.nextTrigger.addEventListener("click", function(event){ moduleObject.advance(1); }, false);
this.prevTrigger.addEventListener("click", function(event){ moduleObject.retract(1); }, false);
}
if(window.attachEvent){
this.nextTrigger.attachEvent("onclick", function(event){ moduleObject.advance(1); }, false);
this.prevTrigger.attachEvent("onclick", function(event){ moduleObject.retract(1); }, false);
}
//create & register handlers for group nav
if( this.hasGroupNav ){
this.groupNav = this.createGroupNav();
this.groupTriggers = this.groupNav.getElementsByTagName('A');
for(var i=0; i<this.groupTriggers.length; i++){
if(window.addEventListener)
this.groupTriggers[i].addEventListener("click", function(event){ moduleObject.switchGroup(event); }, false);
if(window.attachEvent)
this.groupTriggers[i].attachEvent("onclick", function(event){ moduleObject.switchGroup(event); },false);
}
}
}
}
//read & apply arguments
this.args = args;
this.setArgs();
//store dom elements
this.container = document.getElementById(args.containerid);
this.contentWrapper = getElements('content_wrapper','DIV',this.container)[0];
this.contentLists = this.container.getElementsByTagName('UL');
//set up the slider
var slider = this;
setTimeout(function(){slider.initialize()},750);
}/* Argument Setup
-------------- */
Slider.prototype.setArgs = function(){
//required arguments
this.groupSize = this.args.groupsize;
this.direction = this.args.direction;
this.effectType = this.args.effect || false;
//optional arguments
this.hasGroupNav = (this.args.hasgroupnav === null) ? true : this.args.hasgroupnav;
this.hasLoop = this.args.hasloop || false;
this.hasAutoAdvance = this.args.hasautoadvance || false;
this.advanceSeconds = this.args.advanceseconds || 5;
this.hasTabs = this.args.hastabs || false;
this.tabs = this.args.tabs; //required for tabbed modules
this.speed = this.args.speed || 7;
}/* Initialization
-------------- */
Slider.prototype.initialize = function(){
this.setContext(0); //set the context of the content initially displayed in the slider to the first list
this.activeGroup = 1; //set a flag used as a current group indicator
this.assembleScrollControls(); //create a group of slider controls which applies to this content
this.updateControlDisplay(); //update display of the controls to match behavior of this module;
if(this.hasTabs) this.assembleTabs( ); //for sliders used to display more than one context of content, create the tab controls
this.setupLayout(); //set up the layout properties constraining container and content list
if(this.hasAutoAdvance) this.autoAdvance(); //if this slider autoadvances, begin the process
}/* Set the Context of Displayed Content
------------------------------------ */
Slider.prototype.setContext = function(context_index){
this.contentList = this.contentLists[context_index]; //set the active content list
//capture useful properties of the content list
this.contentItems = this.contentList.getElementsByTagName('li');
this.numItems = this.contentItems.length;
this.numGroups = Math.ceil(this.numItems/this.groupSize);
this.itemWidth = this.getItemWidth();
this.itemHeight = this.getItemHeight();
}/* Scroll Control Creation & Event Handling
------------------------------------- */
Slider.prototype.assembleScrollControls = function(){
var moduleObject = this;
if( this.numGroups > 1 ){ //only create controls if they are needed
//create & register handlers for next/previous controls
this.nextTrigger = this.createTrigger('slide_control_next');
this.prevTrigger = this.createTrigger('slide_control_previous');
if(window.addEventListener){
this.nextTrigger.addEventListener("click", function(event){ moduleObject.advance(1); }, false);
this.prevTrigger.addEventListener("click", function(event){ moduleObject.retract(1); }, false);
}
if(window.attachEvent){
this.nextTrigger.attachEvent("onclick", function(event){ moduleObject.advance(1); }, false);
this.prevTrigger.attachEvent("onclick", function(event){ moduleObject.retract(1); }, false);
}
//create & register handlers for group nav
if( this.hasGroupNav ){
this.groupNav = this.createGroupNav();
this.groupTriggers = this.groupNav.getElementsByTagName('A');
for(var i=0; i<this.groupTriggers.length; i++){
if(window.addEventListener)
this.groupTriggers[i].addEventListener("click", function(event){ moduleObject.switchGroup(event); }, false);
if(window.attachEvent)
this.groupTriggers[i].attachEvent("onclick", function(event){ moduleObject.switchGroup(event); },false);
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货