Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/**
2
 * @class
3
 * @augments H5P.EventDispatcher
4
 * @param {Object} displayOptions
5
 * @param {boolean} displayOptions.export Triggers the display of the 'Download' button
6
 * @param {boolean} displayOptions.copyright Triggers the display of the 'Copyright' button
7
 * @param {boolean} displayOptions.embed Triggers the display of the 'Embed' button
8
 * @param {boolean} displayOptions.icon Triggers the display of the 'H5P icon' link
9
 */
10
H5P.ActionBar = (function ($, EventDispatcher) {
11
  "use strict";
12
 
13
  function ActionBar(displayOptions) {
14
    EventDispatcher.call(this);
15
 
16
    /** @alias H5P.ActionBar# */
17
    var self = this;
18
 
19
    var hasActions = false;
20
 
21
    // Create action bar
22
    var $actions = H5P.jQuery('<ul class="h5p-actions"></ul>');
23
 
24
    /**
25
     * Helper for creating action bar buttons.
26
     *
27
     * @private
28
     * @param {string} type
29
     * @param {string} customClass Instead of type class
30
     */
31
    var addActionButton = function (type, customClass) {
32
      /**
33
       * Handles selection of action
34
       */
35
      var handler = function () {
36
        self.trigger(type);
37
      };
38
 
39
      const $actionList = H5P.jQuery('<li/>', {
40
        'class': 'h5p-button h5p-noselect h5p-' + (customClass ? customClass : type),
41
        appendTo: $actions
42
      });
43
 
44
      const $actionButton = H5P.jQuery('<button/>', {
45
        tabindex: 0,
46
        'aria-label': H5P.t(type + 'Description'),
47
        html: H5P.t(type),
48
        on: {
49
          click: handler,
50
          keypress: function (e) {
51
            if (e.which === 32) {
52
              handler();
53
              e.preventDefault(); // (since return false will block other inputs)
54
            }
55
          }
56
        },
57
        appendTo: $actionList
58
      });
59
 
60
      H5P.Tooltip($actionButton.get(0));
61
 
62
      hasActions = true;
63
    };
64
 
65
    // Register action bar buttons
66
    if (displayOptions.export || displayOptions.copy) {
67
      // Add export button
68
      addActionButton('reuse', 'export');
69
    }
70
    if (displayOptions.copyright) {
71
      addActionButton('copyrights');
72
    }
73
    if (displayOptions.embed) {
74
      addActionButton('embed');
75
    }
76
    if (displayOptions.icon) {
77
      // Add about H5P button icon
78
      const $h5pLogo = H5P.jQuery('<li><a class="h5p-link" href="http://h5p.org" target="_blank" aria-label="' + H5P.t('h5pDescription') + '"></a></li>').appendTo($actions);
79
      H5P.Tooltip($h5pLogo.find('.h5p-link').get(0));
80
      hasActions = true;
81
    }
82
 
83
    /**
84
     * Returns a reference to the dom element
85
     *
86
     * @return {H5P.jQuery}
87
     */
88
    self.getDOMElement = function () {
89
      return $actions;
90
    };
91
 
92
    /**
93
     * Does the actionbar contain actions?
94
     *
95
     * @return {Boolean}
96
     */
97
    self.hasActions = function () {
98
      return hasActions;
99
    };
100
  }
101
 
102
  ActionBar.prototype = Object.create(EventDispatcher.prototype);
103
  ActionBar.prototype.constructor = ActionBar;
104
 
105
  return ActionBar;
106
 
107
})(H5P.jQuery, H5P.EventDispatcher);