src/widgets/Slice.js
author veltr
Fri, 29 Jun 2012 16:22:52 +0200
branchnew-model
changeset 923 b3ee7d1b472a
parent 904 510ebab76fa3
child 924 64c2eaafe5e2
permissions -rw-r--r--
UI improvements

/*
 The Slider Widget shows time position and allows seek
 */

IriSP.Widgets.Slice = function(player, config) {
    IriSP.Widgets.Widget.call(this, player, config);
};

IriSP.Widgets.Slice.prototype = new IriSP.Widgets.Widget();

IriSP.Widgets.Slice.prototype.defaults = {
    start_visible : false,
    pause_on_change : true,
    live_update : true
        /* Shall the bounds change each time
        the Annotation Widget sends an update (true)
        or only when "show" is triggered (false) ?
        - true is to be recommended when the widget is permanently displayed.
        */
};

IriSP.Widgets.Slice.prototype.draw = function() {
    
    this.$slider = IriSP.jQuery('<div>')
        .addClass("Ldt-Slice")
    
    this.$.append(this.$slider);
    
    this.min = 0;
    this.max = this.source.getDuration().valueOf();
    
    var _this = this;
    
    this.$slider.slider({
        range: true,
        values: [0, 0],
        min: 0,
        max: this.max,
        change: function(event, ui) {
            _this.player.popcorn.trigger("IriSP.Arrow.updatePosition",{
                widget:_this.type,
                time:Math.floor((ui.values[0]+ui.values[1])/2)
            });
            _this.player.popcorn.trigger("IriSP.Slice.boundsChanged",[ui.values[0], ui.values[1]]);
        },
        start: function() {
            if (_this.pause_on_change && !_this.player.popcorn.media.paused) {
                _this.player.popcorn.pause();
            }
        }
    });
    this.$slider.find(".ui-slider-handle:first").addClass("Ldt-Slice-left-handle");
    this.$slider.find(".ui-slider-handle:last").addClass("Ldt-Slice-right-handle");
    if (this.start_visible) {
        this.show();
    } else {
        this.hide();
    }
    this.bindPopcorn("IriSP.Slice.show","show");
    this.bindPopcorn("IriSP.Slice.hide","hide");
    this.bindPopcorn("IriSP.Annotation.boundsChanged","storeBounds");
    this.trigger("IriSP.Annotation.getBounds");
};

IriSP.Widgets.Slice.prototype.show = function() {
    this.$slider.show();
    this.player.popcorn.trigger("IriSP.Arrow.takeover",this.type);
    this.$slider.slider("values", [this.min, this.max]);
}

IriSP.Widgets.Slice.prototype.hide = function() {
    this.$slider.hide();
    this.player.popcorn.trigger("IriSP.Arrow.release");
}

IriSP.Widgets.Slice.prototype.storeBounds = function(_values) {
    this.min = _values[0];
    this.max = _values[1];
    if (this.live_update) {
        this.$slider.slider("values", [this.min, this.max]);
    }
}