src/widgets/Slider.js
author cavaliet
Thu, 02 Jan 2014 16:49:20 +0100
branchnew-model
changeset 1020 198c2b79f5e1
parent 1019 3ab36f402b0c
permissions -rw-r--r--
oups (last commit in bad branch)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
     1
/*
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
     2
 The Slider Widget fits right under the video
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
     3
 */
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
     4
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
     5
IriSP.Widgets.Slider = function(player, config) {
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
     6
    IriSP.Widgets.Widget.call(this, player, config);
289
c0e399fbf3fb due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents: 260
diff changeset
     7
};
c0e399fbf3fb due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents: 260
diff changeset
     8
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
     9
IriSP.Widgets.Slider.prototype = new IriSP.Widgets.Widget();
289
c0e399fbf3fb due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents: 260
diff changeset
    10
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    11
IriSP.Widgets.Slider.prototype.defaults = {
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    12
    minimized_height : 4,
1020
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    13
    maximized_height : 10,
909
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    14
    minimize_timeout : 1500 /*  time before minimizing slider after mouseout,
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    15
                                set to zero for fixed slider */
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    16
};
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    17
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    18
IriSP.Widgets.Slider.prototype.draw = function() {
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    19
    
1020
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    20
    this.$slider = IriSP.jQuery('<div>')
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    21
        .addClass("Ldt-Slider");
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    22
    
1020
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    23
    this.$.append(this.$slider);
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    24
    
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    25
    var _this = this;
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    26
    
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    27
    this.$slider.slider({
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    28
        range: "min",
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    29
        value: 0,
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    30
        min: 0,
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
    31
        max: this.source.getDuration().milliseconds,
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    32
        slide: function(event, ui) {
1020
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    33
            _this.player.popcorn.currentTime(ui.value / 1000);
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    34
            _this.player.popcorn.trigger("IriSP.Mediafragment.setHashToTime");
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    35
        }
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    36
    });
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    37
    
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    38
    this.$handle = this.$slider.find('.ui-slider-handle');
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    39
    
1020
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    40
    this.bindPopcorn("timeupdate","onTimeupdate");
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    41
    this.bindPopcorn("IriSP.PlayerWidget.MouseOver","onMouseover");
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    42
    this.bindPopcorn("IriSP.PlayerWidget.MouseOut","onMouseout");
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    43
    
909
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    44
    if (this.minimize_timeout) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    45
        this.$slider.css(this.calculateSliderCss(this.minimized_height));
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    46
        this.$handle.css(this.calculateHandleCss(this.minimized_height));
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    47
        
1020
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    48
        this.$
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    49
            .mouseover(this.functionWrapper("onMouseover"))
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    50
            .mouseout(this.functionWrapper("onMouseout"));
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    51
        
909
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    52
        this.maximized = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    53
        this.timeoutId = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    54
    }
289
c0e399fbf3fb due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents: 260
diff changeset
    55
};
c0e399fbf3fb due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents: 260
diff changeset
    56
1020
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    57
IriSP.Widgets.Slider.prototype.onTimeupdate = function() {
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    58
    var _time = 1000 * this.player.popcorn.currentTime();
880
4c7b33bf2795 Started work on CreateAnnotation and Mediafragment
veltr
parents: 875
diff changeset
    59
    this.$slider.slider("value",_time);
1020
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    60
    this.player.popcorn.trigger("IriSP.Arrow.updatePosition",{widget: this.type, time: _time});
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    61
}
289
c0e399fbf3fb due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents: 260
diff changeset
    62
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    63
IriSP.Widgets.Slider.prototype.onMouseover = function() {
909
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    64
    if (this.minimize_timeout) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    65
        if (this.timeoutId) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    66
            window.clearTimeout(this.timeoutId);
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    67
            this.timeoutId = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    68
        }
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    69
        if (!this.maximized) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    70
           this.animateToHeight(this.maximized_height);
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    71
           this.maximized = true;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    72
        }
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    73
    }
1020
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    74
}
347
9c55d584d3a9 slider maximization when rolled over now works.
hamidouk
parents: 332
diff changeset
    75
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    76
IriSP.Widgets.Slider.prototype.onMouseout = function() {
909
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    77
    if (this.minimize_timeout) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    78
        if (this.timeoutId) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    79
            window.clearTimeout(this.timeoutId);
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    80
            this.timeoutId = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    81
        }
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    82
        var _this = this;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    83
        this.timeoutId = window.setTimeout(function() {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    84
            if (_this.maximized) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    85
                _this.animateToHeight(_this.minimized_height);
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    86
                _this.maximized = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    87
            }
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    88
            _this.timeoutId = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    89
        }, this.minimize_timeout);
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    90
    }
1020
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
    91
}
347
9c55d584d3a9 slider maximization when rolled over now works.
hamidouk
parents: 332
diff changeset
    92
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    93
IriSP.Widgets.Slider.prototype.animateToHeight = function(_height) {
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    94
    this.$slider.stop().animate(
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    95
        this.calculateSliderCss(_height),
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    96
        500,
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    97
        function() {
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    98
            IriSP.jQuery(this).css("overflow","visible");
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    99
        });
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   100
    this.$handle.stop().animate(
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   101
        this.calculateHandleCss(_height),
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   102
        500,
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   103
        function() {
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   104
            IriSP.jQuery(this).css("overflow","visible");
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   105
        });
1020
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
   106
}
289
c0e399fbf3fb due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents: 260
diff changeset
   107
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   108
IriSP.Widgets.Slider.prototype.calculateSliderCss = function(_size) {
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   109
    return {
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   110
        height: _size + "px",
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   111
        "margin-top": (this.minimized_height - _size) + "px"
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   112
    };
1020
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
   113
}
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 820
diff changeset
   114
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   115
IriSP.Widgets.Slider.prototype.calculateHandleCss = function(_size) {
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   116
    return {
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   117
        height: (2 + _size) + "px",
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   118
        width: (2 + _size) + "px",
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   119
        "margin-left": -Math.ceil(2 + _size / 2) + "px" 
1020
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
   120
    }
198c2b79f5e1 oups (last commit in bad branch)
cavaliet
parents: 1019
diff changeset
   121
}