2017-02-07 13:48:42 +01:00
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
* @augments H5P.EventDispatcher
|
|
|
|
* @param {Object} displayOptions
|
|
|
|
* @param {boolean} displayOptions.export Triggers the display of the 'Download' button
|
|
|
|
* @param {boolean} displayOptions.copyright Triggers the display of the 'Copyright' button
|
|
|
|
* @param {boolean} displayOptions.embed Triggers the display of the 'Embed' button
|
|
|
|
* @param {boolean} displayOptions.icon Triggers the display of the 'H5P icon' link
|
|
|
|
*/
|
2016-12-13 10:29:33 +01:00
|
|
|
H5P.ActionBar = (function ($, EventDispatcher) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function ActionBar(displayOptions) {
|
|
|
|
EventDispatcher.call(this);
|
|
|
|
|
2017-02-07 13:48:42 +01:00
|
|
|
/** @alias H5P.ActionBar# */
|
2016-12-13 10:29:33 +01:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var hasActions = false;
|
|
|
|
|
|
|
|
// Create action bar
|
|
|
|
var $actions = H5P.jQuery('<ul class="h5p-actions"></ul>');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for creating action bar buttons.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} type
|
|
|
|
* @param {string} customClass Instead of type class
|
|
|
|
*/
|
|
|
|
var addActionButton = function (type, customClass) {
|
2017-01-30 08:43:47 +01:00
|
|
|
/**
|
|
|
|
* Handles selection of action
|
|
|
|
*/
|
2016-12-13 10:29:33 +01:00
|
|
|
var handler = function () {
|
|
|
|
self.trigger(type);
|
|
|
|
};
|
|
|
|
H5P.jQuery('<li/>', {
|
|
|
|
'class': 'h5p-button h5p-' + (customClass ? customClass : type),
|
|
|
|
role: 'button',
|
|
|
|
tabindex: 0,
|
|
|
|
title: H5P.t(type + 'Description'),
|
|
|
|
html: H5P.t(type),
|
|
|
|
on: {
|
|
|
|
click: handler,
|
|
|
|
keypress: function (e) {
|
|
|
|
if (e.which === 32) {
|
|
|
|
handler();
|
|
|
|
e.preventDefault(); // (since return false will block other inputs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
appendTo: $actions
|
|
|
|
});
|
|
|
|
|
|
|
|
hasActions = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Register action bar buttons
|
2016-12-16 14:22:03 +01:00
|
|
|
if (displayOptions.export) {
|
2016-12-13 10:29:33 +01:00
|
|
|
// Add export button
|
|
|
|
addActionButton('download', 'export');
|
|
|
|
}
|
2016-12-16 14:22:03 +01:00
|
|
|
if (displayOptions.copyright) {
|
2016-12-13 10:29:33 +01:00
|
|
|
addActionButton('copyrights');
|
|
|
|
}
|
2016-12-16 14:22:03 +01:00
|
|
|
if (displayOptions.embed) {
|
2016-12-13 10:29:33 +01:00
|
|
|
addActionButton('embed');
|
|
|
|
}
|
2016-12-16 14:22:03 +01:00
|
|
|
if (displayOptions.icon) {
|
2016-12-13 10:29:33 +01:00
|
|
|
// Add about H5P button icon
|
|
|
|
H5P.jQuery('<li><a class="h5p-link" href="http://h5p.org" target="_blank" title="' + H5P.t('h5pDescription') + '"></a></li>').appendTo($actions);
|
|
|
|
hasActions = true;
|
|
|
|
}
|
|
|
|
|
2016-12-16 11:38:47 +01:00
|
|
|
/**
|
|
|
|
* Returns a reference to the dom element
|
|
|
|
*
|
|
|
|
* @return {H5P.jQuery}
|
|
|
|
*/
|
2016-12-13 10:29:33 +01:00
|
|
|
self.getDOMElement = function () {
|
|
|
|
return $actions;
|
|
|
|
};
|
|
|
|
|
2016-12-16 11:38:47 +01:00
|
|
|
/**
|
|
|
|
* Does the actionbar contain actions?
|
|
|
|
*
|
|
|
|
* @return {Boolean}
|
|
|
|
*/
|
2016-12-13 10:29:33 +01:00
|
|
|
self.hasActions = function () {
|
|
|
|
return hasActions;
|
2017-01-30 08:43:47 +01:00
|
|
|
};
|
|
|
|
}
|
2016-12-13 10:29:33 +01:00
|
|
|
|
|
|
|
ActionBar.prototype = Object.create(EventDispatcher.prototype);
|
|
|
|
ActionBar.prototype.constructor = ActionBar;
|
|
|
|
|
|
|
|
return ActionBar;
|
|
|
|
|
|
|
|
})(H5P.jQuery, H5P.EventDispatcher);
|