Created
December 11, 2012 16:17
-
-
Save zhannes/4259920 to your computer and use it in GitHub Desktop.
js inheritance example
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
/* for commented version, see https://gist.github.com/4259920/95d6d741d227c274be1ecf5238998c01f3658131 */ | |
function object(o){ | |
function ctor(){} | |
ctor.prototype = o; | |
return new ctor; | |
} | |
function inheritProto(subType,superType){ | |
var prototype = object(superType.prototype); | |
prototype.constructor = subType; | |
subType.prototype = prototype; | |
} | |
function Carousel(){} | |
Carousel.prototype = { | |
config: function(){}, | |
transition: function(el,pos){}, | |
_config: function(){ /* definition left out */ }, | |
goTo: function(pos){ | |
if(pos >= this.numSlides || pos < 0 ) return; | |
this.activeSlide = pos; | |
this.transition(this.transitionEl,pos); | |
}, | |
init: function(el,options){ | |
if(!el) return; | |
this.el = el; | |
this.options = options || {}; | |
this.$el = $(el); | |
this.transitionEl = this.options.transitionEl || this.$el; | |
this.transitionAlg = this.options.transitionAlg || function(pos){ | |
return pos*-100; | |
}; | |
this._config(); | |
this.config(); | |
} | |
}; | |
function VCarousel(){ | |
Carousel.apply(this,arguments); | |
} | |
inheritProto(VCarousel, Carousel); | |
$.extend(VCarousel.prototype, { | |
config: function(){ /*define*/ }, | |
transition: function(){ /*define*/ } | |
}); | |
var vc = new VCarousel; | |
vc.init($('.slides'), { | |
controls: $('#controls').find('.prev,.next'), | |
easing: 'cubic-bezier(1.000, 0.000, 0.000, 1.000)', | |
transitionProperty: 'top', | |
transitionDuration: '1s' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment