src/widgets/Shortcuts.js
author durandn
Tue, 01 Sep 2015 15:31:46 +0200
changeset 1046 eb77616c245f
parent 1033 c20df1c080e6
child 1068 7623f9af9272
permissions -rw-r--r--
Updated LatestAnnotation, CurrentSegmentInfobox, AnnotationController and AnnotationList widgets to use timerange to find the current segment when the corresponding option is used + CurrentSegmentInfobox now has an option for editing the current segment + LatestAnnotation now has a "Copy and edit" button that allows to use the text from the currently displayed annotation into the CreateAnnotation widget textarea

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

/**
 * Keyboard shortcuts widget
 * This widgets add global shortcuts for common actions.
 * The default shortcuts are: 
 * - Escape or Control-space for play/pause
 * - Control-left for rewind (+shift to go faster)
 * - Control-right for forward (+shift to go faster)
 */
IriSP.Widgets.Shortcuts.prototype = new IriSP.Widgets.Widget();

IriSP.Widgets.Shortcuts.prototype.defaults =  {
    // Time increment, in ms, for backward/forward navigation
    time_increment: 2000
}

IriSP.Widgets.Shortcuts.prototype.draw = function() {
    var  _this = this;
    
    /* Standard shortcuts */
    Mousetrap.bindGlobal(["esc", "ctrl+space"], function (e) {
        e.preventDefault();
        if (! _this.media.getPaused()) {
            _this.media.pause();
        } else {
            _this.media.play();
        }
        return false;
    });
    Mousetrap.bindGlobal("ctrl+left", function (e) {
        // Backward
        e.preventDefault();
        _this.media.setCurrentTime(Math.max(0, _this.media.getCurrentTime() - _this.time_increment));
        return false;
    });
    Mousetrap.bindGlobal("ctrl+shift+left", function (e) {
        // Backward
        e.preventDefault();
        _this.media.setCurrentTime(Math.max(0, _this.media.getCurrentTime() - 5 * _this.time_increment));
        return false;
    });
    Mousetrap.bindGlobal("ctrl+right", function (e) {
        // Forward
        e.preventDefault();
        _this.media.setCurrentTime(Math.min(_this.media.duration, _this.media.getCurrentTime() + _this.time_increment));
        return false;
    });
    Mousetrap.bindGlobal("ctrl+shift+right", function (e) {
        // Forward
        e.preventDefault();
        _this.media.setCurrentTime(Math.min(_this.media.duration, _this.media.getCurrentTime() + 5 * _this.time_increment));
        return false;
    });

};