src/widgets/Slider.js
author ymh <ymh.work@gmail.com>
Wed, 07 May 2014 15:36:43 +0200
changeset 1030 afd77187fd9a
parent 1021 7253d4d06f0d
child 1068 7623f9af9272
permissions -rw-r--r--
rename REAME + simplify hgignore
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,
1021
7253d4d06f0d update widgets after enhance in annotation platform.
cavaliet
parents: 1013
diff changeset
    13
    maximized_height : 4,
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
965
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    18
IriSP.Widgets.Slider.prototype.template =
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 965
diff changeset
    19
    '<div class="Ldt-Slider"></div><div class="Ldt-Slider-Time">00:00</div>';
965
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    20
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    21
IriSP.Widgets.Slider.prototype.draw = function() {
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    22
    
965
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    23
    this.renderTemplate();
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    24
    
965
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    25
    this.$time = this.$.find(".Ldt-Slider-Time");
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    26
    
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    27
    this.$slider = this.$.find(".Ldt-Slider");
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    28
    
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    29
    var _this = this;
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    30
    
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    31
    this.$slider.slider({
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    32
        range: "min",
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    33
        value: 0,
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    34
        min: 0,
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
    35
        max: this.source.getDuration().milliseconds,
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    36
        slide: function(event, ui) {
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 909
diff changeset
    37
            _this.media.setCurrentTime(ui.value);
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 909
diff changeset
    38
            _this.player.trigger("Mediafragment.setHashToTime");
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    39
        }
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    40
    });
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    41
    
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    42
    this.$handle = this.$slider.find('.ui-slider-handle');
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    43
    
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 909
diff changeset
    44
    this.onMediaEvent("timeupdate","onTimeupdate");
960
9a278b9e3b05 Updated docs and test suite
veltr
parents: 957
diff changeset
    45
    this.onMdpEvent("Player.MouseOver","onMouseover");
9a278b9e3b05 Updated docs and test suite
veltr
parents: 957
diff changeset
    46
    this.onMdpEvent("Player.MouseOut","onMouseout");
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    47
    
909
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    48
    if (this.minimize_timeout) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    49
        this.$slider.css(this.calculateSliderCss(this.minimized_height));
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    50
        this.$handle.css(this.calculateHandleCss(this.minimized_height));
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
    }
965
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    55
    
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    56
    this.$
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    57
        .mouseover(function() {
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    58
            _this.$time.show();
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    59
            _this.onMouseover();
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    60
        })
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    61
        .mouseout(this.functionWrapper("onMouseout"))
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    62
        .mousemove(function(_e) {
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    63
            var _x = _e.pageX - _this.$.offset().left,
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    64
                _t = new IriSP.Model.Time(_this.media.duration * _x / _this.width);
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    65
            _this.$time.text(_t.toString()).css("left",_x);
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    66
        });
289
c0e399fbf3fb due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents: 260
diff changeset
    67
};
c0e399fbf3fb due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents: 260
diff changeset
    68
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 909
diff changeset
    69
IriSP.Widgets.Slider.prototype.onTimeupdate = function(_time) {
880
4c7b33bf2795 Started work on CreateAnnotation and Mediafragment
veltr
parents: 875
diff changeset
    70
    this.$slider.slider("value",_time);
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 909
diff changeset
    71
    this.player.trigger("Arrow.updatePosition",{widget: this.type, time: _time});
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 965
diff changeset
    72
};
289
c0e399fbf3fb due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents: 260
diff changeset
    73
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    74
IriSP.Widgets.Slider.prototype.onMouseover = function() {
909
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    75
    if (this.minimize_timeout) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    76
        if (this.timeoutId) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    77
            window.clearTimeout(this.timeoutId);
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    78
            this.timeoutId = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    79
        }
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    80
        if (!this.maximized) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    81
           this.animateToHeight(this.maximized_height);
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    82
           this.maximized = true;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    83
        }
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
    84
    }
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 965
diff changeset
    85
};
347
9c55d584d3a9 slider maximization when rolled over now works.
hamidouk
parents: 332
diff changeset
    86
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    87
IriSP.Widgets.Slider.prototype.onMouseout = function() {
965
eadb7290c325 Improvements in widget communication
veltr
parents: 960
diff changeset
    88
    this.$time.hide();
909
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    89
    if (this.minimize_timeout) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    90
        if (this.timeoutId) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    91
            window.clearTimeout(this.timeoutId);
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    92
            this.timeoutId = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    93
        }
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    94
        var _this = this;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    95
        this.timeoutId = window.setTimeout(function() {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    96
            if (_this.maximized) {
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    97
                _this.animateToHeight(_this.minimized_height);
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    98
                _this.maximized = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
    99
            }
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
   100
            _this.timeoutId = false;
aa0e42229784 Started reworking on documentation
veltr
parents: 887
diff changeset
   101
        }, this.minimize_timeout);
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   102
    }
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 965
diff changeset
   103
};
347
9c55d584d3a9 slider maximization when rolled over now works.
hamidouk
parents: 332
diff changeset
   104
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   105
IriSP.Widgets.Slider.prototype.animateToHeight = function(_height) {
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   106
    this.$slider.stop().animate(
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   107
        this.calculateSliderCss(_height),
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   108
        500,
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   109
        function() {
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   110
            IriSP.jQuery(this).css("overflow","visible");
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
    this.$handle.stop().animate(
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   113
        this.calculateHandleCss(_height),
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   114
        500,
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   115
        function() {
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   116
            IriSP.jQuery(this).css("overflow","visible");
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   117
        });
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 965
diff changeset
   118
};
289
c0e399fbf3fb due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents: 260
diff changeset
   119
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   120
IriSP.Widgets.Slider.prototype.calculateSliderCss = function(_size) {
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   121
    return {
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   122
        height: _size + "px",
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   123
        "margin-top": (this.minimized_height - _size) + "px"
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   124
    };
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 965
diff changeset
   125
};
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 820
diff changeset
   126
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   127
IriSP.Widgets.Slider.prototype.calculateHandleCss = function(_size) {
874
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   128
    return {
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   129
        height: (2 + _size) + "px",
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   130
        width: (2 + _size) + "px",
38b65761a7d5 TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents: 842
diff changeset
   131
        "margin-left": -Math.ceil(2 + _size / 2) + "px" 
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 965
diff changeset
   132
    };
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 965
diff changeset
   133
};