1 |
efrain |
1 |
/* global H5PEditor */
|
|
|
2 |
H5PEditor.FullscreenBar = (function ($) {
|
|
|
3 |
function FullscreenBar ($mainForm, library) {
|
|
|
4 |
|
|
|
5 |
const title = H5PEditor.libraryCache[library] ? H5PEditor.libraryCache[library].title : library;
|
|
|
6 |
const iconId = library.split(' ')[0].split('.')[1].toLowerCase();
|
|
|
7 |
|
|
|
8 |
let isInFullscreen = false;
|
|
|
9 |
let exitSemiFullscreen;
|
|
|
10 |
|
|
|
11 |
$mainForm.addClass('h5peditor-form-manager');
|
|
|
12 |
|
|
|
13 |
// Add fullscreen bar
|
|
|
14 |
const $bar = ns.$('<div/>', {
|
|
|
15 |
'class': 'h5peditor-form-manager-head'
|
|
|
16 |
})
|
|
|
17 |
|
|
|
18 |
const $breadcrumb = ns.$('<div/>', {
|
|
|
19 |
'class': 'h5peditor-form-manager-breadcrumb',
|
|
|
20 |
appendTo: $bar
|
|
|
21 |
});
|
|
|
22 |
|
|
|
23 |
const $title = ns.$('<div/>', {
|
|
|
24 |
'class': 'h5peditor-form-manager-title ' + iconId,
|
|
|
25 |
text: title,
|
|
|
26 |
appendTo: $breadcrumb
|
|
|
27 |
});
|
|
|
28 |
|
|
|
29 |
const fullscreenButton = createButton('fullscreen', '', function () {
|
|
|
30 |
if (isInFullscreen) {
|
|
|
31 |
// Trigger semi-fullscreen exit
|
|
|
32 |
exitSemiFullscreen();
|
|
|
33 |
}
|
|
|
34 |
else {
|
|
|
35 |
// Trigger semi-fullscreen enter
|
|
|
36 |
exitSemiFullscreen = H5PEditor.semiFullscreen($mainForm, function () {
|
|
|
37 |
fullscreenButton.setAttribute('aria-label', H5PEditor.t('core', 'exitFullscreenButtonLabel'));
|
|
|
38 |
isInFullscreen = true;
|
|
|
39 |
}, function () {
|
|
|
40 |
fullscreenButton.setAttribute('aria-label', H5PEditor.t('core', 'enterFullscreenButtonLabel'))
|
|
|
41 |
isInFullscreen = false;
|
|
|
42 |
});
|
|
|
43 |
}
|
|
|
44 |
}, H5PEditor.t('core', 'enterFullscreenButtonLabel'));
|
|
|
45 |
|
|
|
46 |
// Create 'Proceed to save' button
|
|
|
47 |
const proceedButton = createButton('proceed', H5PEditor.t('core', 'proceedButtonLabel'), function () {
|
|
|
48 |
exitSemiFullscreen();
|
|
|
49 |
});
|
|
|
50 |
|
|
|
51 |
$bar.append(proceedButton);
|
|
|
52 |
$bar.append(fullscreenButton);
|
|
|
53 |
$mainForm.prepend($bar);
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Helper for creating buttons.
|
|
|
58 |
*
|
|
|
59 |
* @private
|
|
|
60 |
* @param {string} id
|
|
|
61 |
* @param {string} text
|
|
|
62 |
* @param {function} clickHandler
|
|
|
63 |
* @param {string} ariaLabel
|
|
|
64 |
* @return {Element}
|
|
|
65 |
*/
|
|
|
66 |
const createButton = function (id, text, clickHandler, ariaLabel) {
|
|
|
67 |
if (ariaLabel === undefined) {
|
|
|
68 |
ariaLabel = text;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
const button = document.createElement('button');
|
|
|
72 |
button.setAttribute('type', 'button');
|
|
|
73 |
button.classList.add('h5peditor-form-manager-button');
|
|
|
74 |
button.classList.add('h5peditor-form-manager-' + id);
|
|
|
75 |
button.setAttribute('aria-label', ariaLabel);
|
|
|
76 |
button.addEventListener('click', clickHandler);
|
|
|
77 |
|
|
|
78 |
// Create special inner filler to avoid focus from pointer devices.
|
|
|
79 |
const content = document.createElement('span');
|
|
|
80 |
content.classList.add('h5peditor-form-manager-button-inner');
|
|
|
81 |
content.innerText = text
|
|
|
82 |
content.tabIndex = -1;
|
|
|
83 |
button.appendChild(content);
|
|
|
84 |
|
|
|
85 |
return button;
|
|
|
86 |
};
|
|
|
87 |
|
|
|
88 |
return FullscreenBar;
|
|
|
89 |
}(ns.jQuery));
|