src/widgets/AnnotationsController.js
author ymh <ymh.work@gmail.com>
Fri, 18 Oct 2024 10:24:57 +0200
changeset 1074 231ea5ea7de4
parent 1072 ac1eacb3aa33
permissions -rw-r--r--
change http to https for default thumb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
     1
/*
1039
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
     2
 * Widget that ties AnnotationList and CreateAnnotation together
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
     3
 * using buttons to hide/show AnnotationList and CreateAnnotation widgets.
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
     4
 *
1039
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
     5
 */
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
     6
import annotationsControllerStyles from "./AnnotationsController.module.css";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
     7
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
     8
const AnnotationsController = function (ns) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
     9
  return class extends ns.Widgets.Widget {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    10
    constructor(player, config) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    11
      super(player, config);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    12
    }
1039
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
    13
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    14
    static defaults = {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    15
      // If true, displaying AnnotationList will hide CreateAnnotation and vice versa.
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    16
      display_or_write: false,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    17
      toggle_widgets: false,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    18
      starts_hidden: false,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    19
      hide_without_segment: false,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    20
      hide_when_writing: true,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    21
      starting_widget: false,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    22
      always_show_widget: false,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    23
      segments_annotation_type: "chap",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    24
      custom_write_text: false,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    25
      custom_display_text: false,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    26
    };
1039
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
    27
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    28
    static template =
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    29
      "<div class='Ldt-AnnotationsController'>" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    30
      "<div class='Ldt-AnnotationsController-ButtonsContainer'>" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    31
      "    <div class='Ldt-AnnotationsController-Button Ldt-AnnotationsController-ShowCreateAnnotationButton'>{{#custom_write_text}}{{/custom_write_text}}{{custom_write_text}}{{^custom_write_text}}{{l10n.write}}{{/custom_write_text}}</div>" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    32
      "    <div class='Ldt-AnnotationsController-Button Ldt-AnnotationsController-ShowAnnotationsListButton'>{{#custom_display_text}}{{/custom_display_text}}{{custom_display_text}}{{^custom_display_text}}{{l10n.display}}{{/custom_display_text}}</div>" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    33
      "</div>" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    34
      "</div>";
1039
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
    35
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    36
    static messages =  {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    37
      en: {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    38
        write: "Write",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    39
        display: "Display",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    40
      },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    41
      fr: {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    42
        write: "Ecrire",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    43
        display: "Voir",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    44
      },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    45
    };
1039
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
    46
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    47
    draw() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    48
      this.renderTemplate();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    49
      var _this = this;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    50
      this.element_$ = this.$.find(".Ldt-AnnotationsController");
1039
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
    51
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    52
      this.displayButton_$ = this.$.find(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    53
        ".Ldt-AnnotationsController-ShowAnnotationsListButton"
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    54
      );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    55
      this.writeButton_$ = this.$.find(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    56
        ".Ldt-AnnotationsController-ShowCreateAnnotationButton"
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    57
      );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    58
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    59
      this.writeButton_$.click(function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    60
        if (!_this.writeButton_$.hasClass("selected")) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    61
          _this.player.trigger("CreateAnnotation.show");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    62
          if (_this.display_or_write) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    63
            _this.player.trigger("AnnotationsList.hide");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    64
          }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    65
        } else {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    66
          _this.player.trigger("CreateAnnotation.hide");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    67
          if (_this.toggle_widgets) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    68
            _this.player.trigger("AnnotationsList.show");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    69
          } else if (_this.display_or_write) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    70
            _this.player.trigger("AnnotationsList.hide");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    71
          }
1039
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
    72
        }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    73
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    74
      this.displayButton_$.click(function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    75
        if (!_this.displayButton_$.hasClass("selected")) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    76
          _this.player.trigger("AnnotationsList.show");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    77
          if (_this.display_or_write) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    78
            _this.player.trigger("CreateAnnotation.hide");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    79
          }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    80
        } else {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    81
          _this.player.trigger("AnnotationsList.hide");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    82
          if (_this.toggle_widgets) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    83
            _this.player.trigger("CreateAnnotation.show");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    84
          } else if (_this.display_or_write) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    85
            _this.player.trigger("CreateAnnotation.hide");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    86
          }
1048
13211bca0256 Updated Annotation controller to assign "selected" class to buttons when they get clicked on, for use in custom css.
durandn
parents: 1046
diff changeset
    87
        }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    88
      });
1069
2409cb4cebaf getting various changes from github
ymh <ymh.work@gmail.com>
parents: 1048
diff changeset
    89
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    90
      if (this.hide_without_segment) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    91
        this.onMediaEvent("timeupdate", function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    92
          _this.refresh();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    93
        });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    94
        this.onMediaEvent("settimerange", function (_timeRange) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    95
          _this.refresh(_timeRange);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    96
        });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    97
        this.segments = this.source.getAnnotationsByTypeTitle(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    98
          this.segments_annotation_type
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
    99
        );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   100
        this.currentSegment = false;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   101
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   102
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   103
      this.createAnnotationEnabled = false;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   104
      this.onMdpEvent("CreateAnnotation.hide", function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   105
        if (_this.hide_when_writing) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   106
          _this.show();
1069
2409cb4cebaf getting various changes from github
ymh <ymh.work@gmail.com>
parents: 1048
diff changeset
   107
        }
2409cb4cebaf getting various changes from github
ymh <ymh.work@gmail.com>
parents: 1048
diff changeset
   108
        _this.createAnnotationEnabled = false;
1048
13211bca0256 Updated Annotation controller to assign "selected" class to buttons when they get clicked on, for use in custom css.
durandn
parents: 1046
diff changeset
   109
        _this.writeButton_$.toggleClass("selected", false);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   110
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   111
      this.onMdpEvent("CreateAnnotation.show", function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   112
        if (_this.hide_when_writing) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   113
          _this.hide();
1069
2409cb4cebaf getting various changes from github
ymh <ymh.work@gmail.com>
parents: 1048
diff changeset
   114
        }
2409cb4cebaf getting various changes from github
ymh <ymh.work@gmail.com>
parents: 1048
diff changeset
   115
        _this.createAnnotationEnabled = true;
1048
13211bca0256 Updated Annotation controller to assign "selected" class to buttons when they get clicked on, for use in custom css.
durandn
parents: 1046
diff changeset
   116
        _this.writeButton_$.toggleClass("selected", true);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   117
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   118
      this.onMdpEvent("AnnotationsList.hide", function () {
1048
13211bca0256 Updated Annotation controller to assign "selected" class to buttons when they get clicked on, for use in custom css.
durandn
parents: 1046
diff changeset
   119
        _this.displayButton_$.toggleClass("selected", false);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   120
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   121
      this.onMdpEvent("AnnotationsList.show", function () {
1048
13211bca0256 Updated Annotation controller to assign "selected" class to buttons when they get clicked on, for use in custom css.
durandn
parents: 1046
diff changeset
   122
        _this.displayButton_$.toggleClass("selected", true);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   123
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   124
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   125
      if (this.starts_hidden) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   126
        this.visible = true;
1039
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
   127
        this.hide();
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   128
      } else {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   129
        this.visible = false;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   130
        this.show();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   131
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   132
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   133
      if (this.starting_widget && this.visible) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   134
        if (this.starting_widget == "AnnotationsList") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   135
          this.player.trigger("AnnotationsList.show");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   136
        } else if (this.starting_widget == "CreateAnnotation") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   137
          this.player.trigger("CreateAnnotation.show");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   138
        }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   139
      }
1039
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
   140
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   141
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   142
    refresh(_timeRange) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   143
      _timeRange = typeof _timeRange !== "undefined" ? _timeRange : false;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   144
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   145
      if (!_timeRange) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   146
        if (this.media.getTimeRange()) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   147
          _timeRange = this.media.getTimeRange();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   148
        }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   149
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   150
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   151
      if (this.hide_without_segment) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   152
        if (!_timeRange && !this.media.getTimeRange()) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   153
          _currentTime = this.media.getCurrentTime();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   154
          _currentSegments = this.segments.filter(function (_segment) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   155
            return (
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   156
              _currentTime >= _segment.begin && _currentTime <= _segment.end
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   157
            );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   158
          });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   159
          if (_currentSegments.length > 0) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   160
            currentSegment = true;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   161
          } else {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   162
            currentSegment = false;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   163
          }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   164
        } else {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   165
          var _timeRangeBegin = _timeRange[0],
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   166
            _timeRangeEnd = _timeRange[1];
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   167
          _currentSegments = this.segments.filter(function (_segment) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   168
            return (
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   169
              _timeRangeBegin == _segment.begin && _timeRangeEnd == _segment.end
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   170
            );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   171
          });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   172
          if (_currentSegments.length > 0) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   173
            currentSegment = true;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   174
          } else {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   175
            currentSegment = false;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   176
          }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   177
        }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   178
        if (!currentSegment && _currentSegments.length == 0) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   179
          if (this.visible || this.hide_when_writing) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   180
            this.writeButton_$.toggleClass("selected", false);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   181
            this.displayButton_$.toggleClass("selected", false);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   182
            this.player.trigger("CreateAnnotation.hide");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   183
            this.player.trigger("AnnotationsList.hide");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   184
            this.hide();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   185
          }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   186
        } else {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   187
          if (!this.visible) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   188
            if (!this.createAnnotationEnabled) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   189
              this.show();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   190
            }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   191
            this.writeButton_$.toggleClass("selected", false);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   192
            this.displayButton_$.toggleClass("selected", false);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   193
            if (this.starting_widget == "AnnotationsList") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   194
              this.player.trigger("AnnotationsList.show");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   195
            }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   196
            if (this.starting_widget == "CreateAnnotation") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   197
              this.player.trigger("CreateAnnotation.show");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   198
            }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   199
          }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   200
        }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   201
      }
1039
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
   202
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   203
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   204
    hide() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   205
      if (this.visible) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   206
        this.visible = false;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   207
        this.element_$.hide();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   208
      }
1069
2409cb4cebaf getting various changes from github
ymh <ymh.work@gmail.com>
parents: 1048
diff changeset
   209
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   210
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   211
    show() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   212
      if (!this.visible) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   213
        this.visible = true;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   214
        this.element_$.show();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   215
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   216
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   217
  };
1039
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
   218
};
4fddc765a716 New widget AnnotationsController that displays buttons to hide/show AnnotationsList and CreateAnnotations
durandn
parents:
diff changeset
   219
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1069
diff changeset
   220
export { AnnotationsController, annotationsControllerStyles };