h5p-memory-game/popup.js

65 lines
1.7 KiB
JavaScript
Raw Normal View History

(function (MemoryGame, $) {
/**
* A dialog for reading the description of a card.
*
* @class H5P.MemoryGame.Popup
* @param {H5P.jQuery} $container
*/
2017-05-08 15:14:18 +02:00
MemoryGame.Popup = function ($container, styles) {
2017-02-13 14:42:34 +01:00
/** @alias H5P.MemoryGame.Popup# */
var self = this;
var closed;
2017-05-08 15:14:18 +02:00
var $popup = $('<div class="h5p-memory-pop"><div class="h5p-memory-top"' + styles + '></div><div class="h5p-memory-desc"></div></div>').appendTo($container);
var $desc = $popup.find('.h5p-memory-desc');
2017-05-08 15:14:18 +02:00
var $top = $popup.find('.h5p-memory-top');
/**
* Show the popup.
*
* @param {string} desc
2017-05-08 15:14:18 +02:00
* @param {H5P.jQuery[]} imgs
* @param {function} done
*/
2017-05-08 15:14:18 +02:00
self.show = function (desc, imgs, styles, done) {
$desc.html(desc);
2017-05-08 15:14:18 +02:00
$top.html('').toggleClass('h5p-memory-two-images', imgs.length > 1);
for (var i = 0; i < imgs.length; i++) {
$('<div class="h5p-memory-image"' + styles + '></div>').append(imgs[i]).appendTo($top);
}
$popup.show();
closed = done;
};
/**
* Close the popup.
*/
self.close = function () {
if (closed !== undefined) {
$popup.hide();
closed();
closed = undefined;
}
};
2017-02-13 12:35:10 +01:00
/**
* Sets popup size relative to the card size
* @param {number} fontSize
*/
self.setSize = function (fontSize) {
// Set image size
2017-05-08 15:14:18 +02:00
$top[0].style.fontSize = fontSize + 'px';
2017-02-13 12:35:10 +01:00
// Determine card size
var cardSize = fontSize * 6.25; // From CSS
// Set popup size
2017-05-08 15:14:18 +02:00
$popup[0].style.minWidth = (cardSize * 2.5) + 'px';
2017-02-13 12:35:10 +01:00
$popup[0].style.minHeight = cardSize + 'px';
};
};
})(H5P.MemoryGame, H5P.jQuery);