src/js/widgets-container/widget.js
author ymh <ymh.work@gmail.com>
Wed, 04 Sep 2024 17:32:50 +0200
changeset 1072 ac1eacb3aa33
parent 1068 7623f9af9272
child 1073 687133dc13cf
permissions -rw-r--r--
Migrate source and build to vite.js
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
     1
/* widgetsDefinition of an ancestor for the Widget classes */
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
     2
import Mustache from "mustache";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
     3
import jQuery from "jquery";
66
13013b9452af Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff changeset
     4
520
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
     5
/**
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
     6
 * @class IriSP.Widget is an "abstract" class. It's mostly used to define some properties common to every widget.
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
     7
 *
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
     8
 *  Note that widget constructors are never called directly by the user. Instead, the widgets are instantiated by functions
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
     9
 *  defined in init.js
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    10
 *
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    11
 * @constructor
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    12
 * @param player - a reference to the player widget
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    13
 * @param config - configuration options for the widget
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    14
 *
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    15
 */
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    16
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    17
import _ from "lodash";
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    18
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    19
export default function (IriSP) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    20
  const Widgets = {};
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    21
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    22
  Widgets.Widget = class {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    23
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    24
    static defaults = {};
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    25
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    26
    static template = "";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    27
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    28
    static messages = { en: {} };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    29
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    30
    constructor(player, config) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    31
      if (typeof player === "undefined") {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    32
        /* Probably an abstract call of the class when
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    33
         * individual widgets set their prototype */
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    34
        return;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    35
      }
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    36
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    37
      this.__subwidgets = [];
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    38
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    39
      /* Setting all the configuration options */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    40
      var _type = config.type || "(unknown)",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    41
        _config = _.defaults(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    42
          {},
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    43
          config,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    44
          player && player.config ? player.config.default_options : {},
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    45
          this.constructor.defaults
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    46
        ),
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    47
        _this = this;
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    48
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    49
      _(_config).forEach(function (_value, _key) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    50
        _this[_key] = _value;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    51
      });
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    52
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    53
      this.$ = jQuery("#" + this.container);
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    54
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    55
      if (typeof this.width === "undefined") {
988
eefd336335f9 Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents: 986
diff changeset
    56
        this.width = this.$.width();
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    57
      } else {
992
566b590aaf8f height bugfix
veltr
parents: 988
diff changeset
    58
        this.$.css("width", this.width);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    59
      }
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    60
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    61
      if (typeof this.height !== "undefined") {
992
566b590aaf8f height bugfix
veltr
parents: 988
diff changeset
    62
        this.$.css("height", this.height);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    63
      }
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    64
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    65
      /* Setting this.player at the end in case it's been overriden
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    66
       * by a configuration option of the same name :-(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    67
       */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    68
      this.player =
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    69
        player ||
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    70
        new IriSP.FakeClass([
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    71
          "on",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    72
          "trigger",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    73
          "off",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    74
          "loadWidget",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    75
          "loadMetadata",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    76
        ]);
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    77
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    78
      /* Adding classes and html attributes */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    79
      this.$.addClass("Ldt-TraceMe Ldt-Widget").attr("widget-type", _type);
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    80
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    81
      this.l10n =
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    82
        typeof this.constructor.messages[IriSP.language] !== "undefined"
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    83
          ? this.constructor.messages[IriSP.language]
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    84
          : IriSP.language.length > 2 &&
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    85
            typeof this.constructor.messages[IriSP.language.substr(0, 2)] !== "undefined"
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    86
          ? this.constructor.messages[IriSP.language.substr(0, 2)]
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    87
          : this.constructor.messages["en"];
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    88
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    89
      /* Loading Metadata if required */
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    90
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    91
      function onsourceloaded() {
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    92
        if (_this.localannotations) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    93
          _this.localsource = player.loadLocalAnnotations(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    94
            _this.localannotations
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    95
          );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    96
          _this.source.merge(_this.localsource);
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    97
        }
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    98
        if (_this.media_id) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    99
          _this.media = this.getElement(_this.media_id);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   100
        } else {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   101
          var _mediaopts = {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   102
            is_mashup: _this.is_mashup || false,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   103
          };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   104
          _this.media = _this.source.getCurrentMedia(_mediaopts);
1049
4e8b3df6e5be Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents: 1033
diff changeset
   105
        }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   106
        if (_this.pre_draw_callback) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   107
          jQuery.when(_this.pre_draw_callback()).done(_this.draw());
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   108
        } else {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   109
          _this.draw();
1049
4e8b3df6e5be Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents: 1033
diff changeset
   110
        }
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
   111
        _this.player.trigger("widget-loaded");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   112
      }
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   113
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   114
      if (this.metadata) {
986
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
   115
        /* Getting metadata */
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
   116
        this.source = player.loadMetadata(this.metadata);
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
   117
        /* Call draw when loaded */
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
   118
        this.source.onLoad(onsourceloaded);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   119
      } else {
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
   120
        if (this.source) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   121
          onsourceloaded();
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
   122
        }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   123
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   124
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   125
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   126
    toString() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   127
      return "Widget " + this.type;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   128
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   129
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   130
    templateToHtml(_template) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   131
      return Mustache.render(_template, this);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   132
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   133
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   134
    renderTemplate() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   135
      this.$.append(this.templateToHtml(this.constructor.template));
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   136
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   137
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   138
    functionWrapper(_name) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   139
      var _this = this,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   140
        _function = this[_name];
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   141
      if (typeof _function !== "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   142
        return function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   143
          return _function.apply(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   144
            _this,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   145
            Array.prototype.slice.call(arguments, 0)
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   146
          );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   147
        };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   148
      } else {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   149
        console.log(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   150
          "Error, Unknown function IriSP.Widgets." + this.type + "." + _name
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   151
        );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   152
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   153
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   154
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   155
    getFunctionOrName(_functionOrName) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   156
      switch (typeof _functionOrName) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   157
        case "function":
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   158
          return _functionOrName;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   159
        case "string":
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   160
          return this.functionWrapper(_functionOrName);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   161
        default:
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   162
          return undefined;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   163
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   164
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   165
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   166
    onMdpEvent(_eventName, _functionOrName) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   167
      this.player.on(_eventName, this.getFunctionOrName(_functionOrName));
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   168
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   169
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   170
    onMediaEvent(_eventName, _functionOrName) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   171
      this.media.on(_eventName, this.getFunctionOrName(_functionOrName));
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   172
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   173
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   174
    getWidgetAnnotations() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   175
      var result = null;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   176
      if (typeof this.annotation_type === "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   177
        result = this.media.getAnnotations();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   178
      } else if (this.annotation_type.elementType === "annotationType") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   179
        result = this.annotation_type.getAnnotations();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   180
      } else {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   181
        result = this.media.getAnnotationsByTypeTitle(this.annotation_type);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   182
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   183
      if (typeof this.annotation_filter !== "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   184
        return this.annotation_filter(result);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   185
      } else {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   186
        return result;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   187
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   188
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   189
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   190
    getWidgetAnnotationsAtTime() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   191
      var _time = this.media.getCurrentTime();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   192
      return this.getWidgetAnnotations().filter(function (_annotation) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   193
        return _annotation.begin <= _time && _annotation.end > _time;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   194
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   195
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   196
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   197
    isLoaded() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   198
      var isloaded = !_(this.__subwidgets).some(function (w) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   199
        return !(w && w.isLoaded());
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   200
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   201
      return isloaded;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   202
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   203
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   204
    insertSubwidget(_selector, _widgetoptions, _propname) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   205
      var _id = _selector.attr("id"),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   206
        _this = this,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   207
        key = this.__subwidgets.length;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   208
      this.__subwidgets.push(null);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   209
      if (typeof _id == "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   210
        _id = _.uniqueId(this.container + "_sub_widget_" + _widgetoptions.type);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   211
        _selector.attr("id", _id);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   212
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   213
      _widgetoptions.container = _id;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   214
      _this.player.loadWidget(_widgetoptions, function (_widget) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   215
        if (_propname) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   216
          _this[_propname] = _widget;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   217
        }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   218
        _this.__subwidgets[key] = _widget;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   219
      });
986
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
   220
    }
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   221
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   222
    /*
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   223
     * Position the player to the next/previous annotations based on current player position
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   224
     *
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   225
     * Parameter: offset: -1 for previous annotation, +1 for next annotation
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   226
     */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   227
    navigate(offset) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   228
      // offset is normally either -1 (previous slide) or +1 (next slide)
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   229
      var _this = this;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   230
      var currentTime = _this.media.getCurrentTime();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   231
      var annotations = _this
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   232
        .getWidgetAnnotations()
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   233
        .sortBy(function (_annotation) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   234
          return _annotation.begin;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   235
        });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   236
      for (var i = 0; i < annotations.length; i++) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   237
        if (
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   238
          annotations[i].begin <= currentTime &&
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   239
          currentTime < annotations[i].end
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   240
        ) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   241
          // Found a current annotation - clamp i+offset value to [0, length - 1]
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   242
          i = Math.min(annotations.length - 1, Math.max(0, i + offset));
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   243
          _this.media.setCurrentTime(annotations[i].begin);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   244
          break;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   245
        }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   246
      }
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   247
    }
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   248
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   249
    /*
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   250
     * Propose an export of the widget's annotations
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   251
     *
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   252
     * Parameter: a list of annotations. If not specified, the widget's annotations will be exported.
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   253
     */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   254
    exportAnnotations(annotations) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   255
      var widget = this;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   256
      if (annotations === undefined) annotations = this.getWidgetAnnotations();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   257
      var $ = jQuery;
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   258
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   259
      // FIXME: this should belong to a proper serialize/deserialize component?
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   260
      var content =
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   261
        Mustache.render("[video:{{url}}]\n", { url: widget.media.url }) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   262
        annotations
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   263
          .map(function (a) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   264
            return Mustache.render(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   265
              "[{{ a.begin }}]{{ a.title }} {{ a.description }}[{{ a.end }}]",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   266
              { a: a }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   267
            );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   268
          })
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   269
          .join("\n");
984
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   270
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   271
      var el = $("<pre>")
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   272
        .addClass("exportContainer")
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   273
        .text(content)
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   274
        .dialog({
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   275
          title: "Annotation export",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   276
          open: function (event, ui) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   277
            // Select text
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   278
            var range;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   279
            if (document.selection) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   280
              range = document.body.createTextRange();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   281
              range.moveToElementText(this[0]);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   282
              range.select();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   283
            } else if (window.getSelection) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   284
              range = document.createRange();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   285
              range.selectNode(this[0]);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   286
              window.getSelection().addRange(range);
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents: 958
diff changeset
   287
            }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   288
          },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   289
          autoOpen: true,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   290
          width: "80%",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   291
          minHeight: "400",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   292
          height: 400,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   293
          buttons: [
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   294
            {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   295
              text: "Close",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   296
              click: function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   297
                $(this).dialog("close");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   298
              },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   299
            },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   300
            {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   301
              text: "Download",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   302
              click: function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   303
                a = document.createElement("a");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   304
                a.setAttribute(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   305
                  "href",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   306
                  "data:text/plain;base64," + btoa(content)
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   307
                );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   308
                a.setAttribute(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   309
                  "download",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   310
                  "Annotations - " +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   311
                    widget.media.title.replace(/[^ \w]/g, "") +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   312
                    ".txt"
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   313
                );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   314
                a.click();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   315
              },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   316
            },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   317
          ],
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   318
        });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   319
    }
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   320
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   321
    /**
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   322
     * This method responsible of drawing a widget on screen.
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   323
     */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   324
    draw() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   325
      /* implemented by "sub-classes" */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   326
    }
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   327
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   328
    //Generates uid
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   329
    //source : http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   330
    generateUid() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   331
      return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   332
        /[xy]/g,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   333
        function (c) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   334
          var r = (Math.random() * 16) | 0,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   335
            v = c === "x" ? r : (r & 0x3) | 0x8;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   336
          return v.toString(16);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   337
        }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   338
      );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   339
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   340
  };
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   341
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   342
  return Widgets;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   343
}