New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
authordurandn
Fri, 03 Jul 2015 16:59:29 +0200
changeset 1039 4fddc765a716
parent 1038 e78b889a75e1
child 1040 be314c4ea4ac
New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
src/widgets/AnnotationsController.css
src/widgets/AnnotationsController.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/widgets/AnnotationsController.css	Fri Jul 03 16:59:29 2015 +0200
@@ -0,0 +1,43 @@
+
+.Ldt-AnnotationsController{
+	background: url(img/pinstripe.png);
+	width: 535px;
+    max-height: 280px;
+	margin: 0px;
+	margin-top: 4px;
+	border-style: solid;
+    border-width: 1px;
+    border-color: #b7b7b7;
+}
+
+.Ldt-AnnotationsController-ButtonsContainer{
+	width: 100%;
+	min-height: 30px;
+	text-align: center;
+}
+
+.Ldt-AnnotationsController-Button{
+	display: inline-block;
+    background-color: #d93c71;
+    color: #ffffff;
+    cursor: pointer;
+    height: 25px;
+    width: 150px;
+    font-size: 14px;
+    border: 1px solid;
+    border-color: #eca3bc #631e34 #36101c #e16e93;
+    cursor: pointer;
+    margin-right: 10px;
+    margin-left: 10px;
+    margin-bottom: 5px;
+    margin-top: 5px;
+    padding: 4px;
+    text-align: center;
+	vertical-align: middle;
+	line-height: 30px;
+}
+
+.Ldt-AnnotationsController-Button:hover{
+	background-color: #e15581;
+	border-color: #222222 #e87d9f #f0adc3 #68273c;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/widgets/AnnotationsController.js	Fri Jul 03 16:59:29 2015 +0200
@@ -0,0 +1,109 @@
+/* 
+ * Widget that ties AnnotationList and CreateAnnotation together
+ * using buttons to hide/show AnnotationList and CreateAnnotation widgets.
+ * 
+ */
+
+IriSP.Widgets.AnnotationsController = function(player, config){
+    IriSP.Widgets.Widget.call(this, player, config);
+};
+
+IriSP.Widgets.AnnotationsController.prototype = new IriSP.Widgets.Widget();
+
+IriSP.Widgets.AnnotationsController.prototype.defaults = {
+    // If true, displaying AnnotationList will hide CreateAnnotation and vice versa.
+    display_or_write: false,
+    starts_hidden: false,
+    hide_without_segment: false,
+    segments_annotation_type: "chap"
+};
+
+IriSP.Widgets.AnnotationsController.prototype.template = 
+    "<div class='Ldt-AnnotationsController'>"
+    + "<div class='Ldt-AnnotationsController-ButtonsContainer'>"
+    + "    <div class='Ldt-AnnotationsController-Button Ldt-AnnotationsController-ShowAnnotationsListButton'>{{l10n.display}}</div>"
+    + "    <div class='Ldt-AnnotationsController-Button Ldt-AnnotationsController-ShowCreateAnnotationButton'>{{l10n.write}}</div>"
+    + "</div>"
+    + "</div>"
+
+IriSP.Widgets.AnnotationsController.prototype.messages = {
+    en : {
+        write : "Write",
+        display : "Display",
+    },
+    fr : {
+        write : "Ecrire",
+        display : "Voir"
+    }
+};
+
+IriSP.Widgets.AnnotationsController.prototype.draw = function() { 
+    this.renderTemplate();
+    var _this = this;
+    this.element_$ = this.$.find(".Ldt-AnnotationsController")
+    
+    this.displayButton_$ = this.$.find(".Ldt-AnnotationsController-ShowAnnotationsListButton");
+    this.writeButton_$ = this.$.find(".Ldt-AnnotationsController-ShowCreateAnnotationButton");
+    
+    this.writeButton_$.click(function(){
+        _this.player.trigger("CreateAnnotation.toggle");
+        if (_this.display_or_write){
+            _this.player.trigger("AnnotationsList.hide");
+        }
+    });
+    this.displayButton_$.click(function(){
+        _this.player.trigger("AnnotationsList.toggle");
+        if (_this.display_or_write){
+            _this.player.trigger("CreateAnnotation.hide");
+        }
+    })
+    this.onMediaEvent("timeupdate", "onTimeUpdate")
+    
+    if (this.starts_hidden) {
+        this.visible = true
+        this.hide();
+    }
+    else{
+        this.visible = false
+        this.show();
+    }
+    
+};
+
+IriSP.Widgets.AnnotationsController.prototype.onTimeUpdate = function(){
+    if (this.hide_without_segment){
+        _currentTime = this.media.getCurrentTime() 
+        _segmentsAnnotations = this.source.getAnnotationsByTypeTitle(this.segments_annotation_type)
+        _currentSegments = _segmentsAnnotations.filter(function(_segment){
+            return (_currentTime >= _segment.begin && _currentTime <= _segment.end)
+        });
+        if (_currentSegments.length == 0){
+            if (this.visible){
+                this.hide();
+                _this.player.trigger("CreateAnnotation.hide");
+                _this.player.trigger("AnnotationsList.hide");
+            }
+        }
+        else {
+            if (!this.visible){
+                this.show();
+                _this.player.trigger("CreateAnnotation.hide");
+                _this.player.trigger("AnnotationsList.hide");
+            }
+        }
+    }
+}
+
+IriSP.Widgets.AnnotationsController.prototype.hide = function() {
+    if (this.visible){
+        this.visible = false;
+        this.element_$.hide()
+    }
+}
+
+IriSP.Widgets.AnnotationsController.prototype.show = function() {
+    if(!this.visible){
+        this.visible = true;
+        this.element_$.show()
+    }
+}