Created
November 29, 2012 20:43
-
-
Save HellPat/4171774 to your computer and use it in GitHub Desktop.
An error with class context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ISliderDriver = new Interface({ | |
// The currently active slide | |
activeSlideNumber: Number, | |
// Initialize the slider | |
initialize: Function, | |
// go to the next slide | |
next: Function, | |
// go to the previous slide | |
previous: Function, | |
// arrange the items | |
arrange: Function, | |
// rearrange the items | |
rearrange: Function, | |
// jump to a given slide | |
jumpTo: function(slideNumber){}, | |
}); | |
var UniversalSlider = new Class({ | |
Implements: [Options], | |
started: false, | |
driverObject: null, | |
options: { | |
slides: [], // array of slides | |
startIndex: 0, // where to start | |
driver: 'Fade', | |
driverPath: 'slider/driver/', | |
autoStart: true, | |
autoSlide: true, | |
autoSlideInterval: 2000 | |
}, | |
initialize: function(slider, options){ | |
// convert the options to attributes | |
this.setOptions(options); | |
// set the slider object | |
this.options.sliderObject = slider; | |
// load the driver | |
this.loadDriver(this.options.driver, this.options.driverPath); | |
// arrange the items | |
this.arrange(); | |
if(this.autoStart) | |
{ | |
// set the slider started | |
this.start(); | |
} | |
// slide | |
this.slide(); | |
}, | |
loadDriver: function(driver, driverPath){ | |
var path = driverPath+driver+'.js'; | |
var self = this; | |
var driverFile = Asset.javascript(path , { | |
onLoad: function(){ | |
try { | |
var driverObject = new window[driver](this.options) | |
self.driverObject = driverObject; | |
console.log(self.driverObject); // works here | |
} catch (e){ | |
if (this.console) this.console.error(e); | |
// load default driver here | |
} | |
} | |
}); | |
console.log(self.driverObject); // doesn't work here | |
}, | |
arrange: function(){ | |
}, | |
slide: function(){ | |
if(this.started){ | |
// the slider is started | |
} else { | |
// the slider is stopped | |
} | |
}, | |
start: function(){ | |
this.started = true; | |
}, | |
stop: function(){ | |
this.started = false; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment