Created
August 2, 2013 12:04
-
-
Save Ahrengot/6139391 to your computer and use it in GitHub Desktop.
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
// Generated by CoffeeScript 1.3.1 | |
(function() { | |
var SliderControl, | |
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | |
SliderControl = (function() { | |
SliderControl.name = 'SliderControl'; | |
function SliderControl(el) { | |
this.el = el; | |
this.updateProgress = __bind(this.updateProgress, this); | |
this.handleResize = __bind(this.handleResize, this); | |
this.drag = __bind(this.drag, this); | |
this.stopDrag = __bind(this.stopDrag, this); | |
this.startDrag = __bind(this.startDrag, this); | |
this.progbar = this.el.find('.progress'); | |
this.handle = this.el.find('.handle'); | |
this.progX = this.el.offset().left; | |
this.progW = this.el.width(); | |
this.percent = 0; | |
this.progress = 0; | |
this.isDragging = false; | |
this.mouseDown = false; | |
this.handle.on('mousedown', this.startDrag); | |
this.el.on('scrubbing:tick', this.updateProgress); | |
this.el.on('click', this.drag); | |
$(window).on('resize', { | |
self: this | |
}, this.handleResize); | |
} | |
SliderControl.prototype.startDrag = function(e) { | |
this.isDragging = true; | |
this.mouseDown = true; | |
this.el.off('click'); | |
$(window).on('mousemove', this.drag); | |
return $(window).on('mouseup', this.stopDrag); | |
}; | |
SliderControl.prototype.stopDrag = function(e) { | |
var _this = this; | |
this.mouseDown = false; | |
$(window).off('mousemove', this.drag); | |
$(window).off('mouseup', this.stopDrag); | |
return setTimeout(function() { | |
return _this.el.on('click', _this.drag); | |
}, 500); | |
}; | |
SliderControl.prototype.drag = function(e) { | |
var newPerc, | |
_this = this; | |
newPerc = (e.pageX - this.progX) / this.progW; | |
newPerc = Math.round(newPerc * 1000) / 10; | |
if (newPerc < 0) { | |
newPerc = 0; | |
} else if (newPerc > 100) { | |
newPerc = 100; | |
} | |
if (e.type === 'mousemove') { | |
this.percent = newPerc; | |
return TweenMax.to(this, 0.5, { | |
progress: newPerc, | |
overwrite: 'all', | |
onComplete: function() { | |
if (_this.mouseDown) { | |
return; | |
} | |
_this.$isDragging = false; | |
return _this.el.trigger('scrubbing:complete'); | |
}, | |
onUpdate: function() { | |
return _this.el.trigger('scrubbing:tick', _this.progress); | |
}, | |
ease: Power2.easeOut | |
}); | |
} else { | |
this.percent = newPerc; | |
return TweenMax.to(this, 0.6, { | |
progress: newPerc, | |
overwrite: 'all', | |
onComplete: function() { | |
_this.el.isDragging = false; | |
return _this.el.trigger('scrubbing:complete'); | |
}, | |
onUpdate: function() { | |
return _this.el.trigger('scrubbing:tick', _this.progress); | |
}, | |
ease: Back.easeOut | |
}); | |
} | |
}; | |
SliderControl.prototype.handleResize = function(e) { | |
this.progX = this.el.offset().left; | |
return this.progW = this.el.width(); | |
}; | |
SliderControl.prototype.updateProgress = function() { | |
if (this.progress > 100) { | |
this.progress = 100; | |
} else if (this.progress < 0) { | |
this.progress = 0; | |
} | |
this.progbar.css('width', this.progress + '%'); | |
return this.handle.css('left', this.progress + '%'); | |
}; | |
SliderControl.prototype.setProgress = function(prog) { | |
this.progress = prog; | |
return this.updateProgress(); | |
}; | |
SliderControl.prototype.destroy = function() { | |
clearInterval(this.addedToStageListener); | |
$(window).off('resize', this.handleResize); | |
this.el.off(); | |
return this.progbar = null; | |
}; | |
return SliderControl; | |
})(); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment