src/widgets/Slider.js
author veltr
Mon, 17 Sep 2012 00:17:06 +0900
branchplayers-as-widgets
changeset 957 4da0a5740b6c
parent 909 aa0e42229784
child 960 9a278b9e3b05
permissions -rw-r--r--
Starting 'players-as-widgets' 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,
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
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
    
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    20
    this.$slider = IriSP.jQuery('<div>')
909
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    21
        .addClass("Ldt-Slider");
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    22
    
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    23
    this.$.append(this.$slider);
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) {
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 909
diff changeset
    33
            _this.media.setCurrentTime(ui.value);
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 909
diff changeset
    34
            _this.player.trigger("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
    
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 909
diff changeset
    40
    this.onMediaEvent("timeupdate","onTimeupdate");
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 909
diff changeset
    41
    this.onMdpEvent("PlayerWidget.MouseOver","onMouseover");
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 909
diff changeset
    42
    this.onMdpEvent("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
        
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    48
        this.$
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    49
            .mouseover(this.functionWrapper("onMouseover"))
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    50
            .mouseout(this.functionWrapper("onMouseout"));
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    51
        
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
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 909
diff changeset
    57
IriSP.Widgets.Slider.prototype.onTimeupdate = function(_time) {
880
4c7b33bf2795 Started work on CreateAnnotation and Mediafragment
veltr
parents: 875
diff changeset
    58
    this.$slider.slider("value",_time);
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 909
diff changeset
    59
    this.player.trigger("Arrow.updatePosition",{widget: this.type, time: _time});
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    60
}
289
c0e399fbf3fb due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents: 260
diff changeset
    61
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    62
IriSP.Widgets.Slider.prototype.onMouseover = function() {
909
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    63
    if (this.minimize_timeout) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    64
        if (this.timeoutId) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    65
            window.clearTimeout(this.timeoutId);
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    66
            this.timeoutId = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    67
        }
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    68
        if (!this.maximized) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    69
           this.animateToHeight(this.maximized_height);
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    70
           this.maximized = true;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    71
        }
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    72
    }
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    73
}
347
9c55d584d3a9 slider maximization when rolled over now works.
hamidouk
parents: 332
diff changeset
    74
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    75
IriSP.Widgets.Slider.prototype.onMouseout = function() {
909
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    76
    if (this.minimize_timeout) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    77
        if (this.timeoutId) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    78
            window.clearTimeout(this.timeoutId);
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    79
            this.timeoutId = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    80
        }
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    81
        var _this = this;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    82
        this.timeoutId = window.setTimeout(function() {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    83
            if (_this.maximized) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    84
                _this.animateToHeight(_this.minimized_height);
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    85
                _this.maximized = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    86
            }
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    87
            _this.timeoutId = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    88
        }, this.minimize_timeout);
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    89
    }
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    90
}
347
9c55d584d3a9 slider maximization when rolled over now works.
hamidouk
parents: 332
diff changeset
    91
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    92
IriSP.Widgets.Slider.prototype.animateToHeight = function(_height) {
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    93
    this.$slider.stop().animate(
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    94
        this.calculateSliderCss(_height),
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    95
        500,
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    96
        function() {
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    97
            IriSP.jQuery(this).css("overflow","visible");
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    98
        });
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    99
    this.$handle.stop().animate(
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   100
        this.calculateHandleCss(_height),
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   101
        500,
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   102
        function() {
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   103
            IriSP.jQuery(this).css("overflow","visible");
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   104
        });
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   105
}
289
c0e399fbf3fb due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents: 260
diff changeset
   106
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   107
IriSP.Widgets.Slider.prototype.calculateSliderCss = function(_size) {
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   108
    return {
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   109
        height: _size + "px",
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   110
        "margin-top": (this.minimized_height - _size) + "px"
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   111
    };
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   112
}
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 820
diff changeset
   113
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   114
IriSP.Widgets.Slider.prototype.calculateHandleCss = function(_size) {
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   115
    return {
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   116
        height: (2 + _size) + "px",
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   117
        width: (2 + _size) + "px",
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   118
        "margin-left": -Math.ceil(2 + _size / 2) + "px" 
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   119
    }
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   120
}