Try to run the experiment again. If the error persists, contact the experiment designer.
';
titleColour = 'red';
}
// we are displaying a message:
else if (typeof message !== 'undefined') {
htmlCode = '
'
+ '
' + message + '
';
titleColour = 'green';
}
// we are displaying a warning:
else if (typeof warning !== 'undefined') {
htmlCode = '
'
+ '
' + warning + '
';
titleColour = 'orange';
}
htmlCode += '
';
// replace root by the html code:
const dialogElement = document.getElementById('root');
dialogElement.innerHTML = htmlCode;
// init and open the dialog box:
this._estimateDialogScalingFactor();
const dialogSize = this._getDialogSize();
const self = this;
$('#msgDialog').dialog({
dialogClass: 'no-close',
width: dialogSize[0],
maxHeight: dialogSize[1],
autoOpen: true,
modal: true,
closeOnEscape: false,
buttons: (!showOK)?[]:[{
id: "buttonOk",
text: "Ok",
click: function() {
$(this).dialog("close");
// execute callback function:
if (typeof onOK !== 'undefined')
onOK();
}
}],
// open the dialog in the middle of the screen:
open: self._dialogOpen('#msgDialog'),
})
// change colour of title bar
.prev(".ui-dialog-titlebar").css("background", titleColour);
// when the browser window is resize, we redimension and reposition the dialog:
self._dialogResize('#msgDialog');
}
/**
* Get the jQuery UI callback for opening the given dialog in the middle of the screen.
*
* @name module:core.GUI#_dialogOpen
* @function
* @param {String} dialogId - the dialog ID
* @returns {Function} jquery ui open function
* @private
*/
_dialogOpen(dialogId) {
const self = this;
return () => {
const windowSize = [$(window).width(), $(window).height()];
// note: $(dialogId) is the dialog-content, $(dialogId).parent() is the actual widget
const parent = $(dialogId).parent();
parent.css({
position: 'absolute',
left: Math.max(0, (windowSize[0] - parent.outerWidth()) / 2.0),
top: Math.max(0, (windowSize[1] - parent.outerHeight()) / 2.0)
});
// record width and height difference between dialog content and dialog:
self._contentDelta = [
parent.css('width').slice(0, -2) - $(dialogId).css('width').slice(0, -2),
parent.css('height').slice(0, -2) - $(dialogId).css('height').slice(0, -2)];
};
}
/**
* Ensure that the browser window's resize events redimension and reposition the dialog UI.
*
* @name module:core.GUI#_dialogResize
* @function
* @param {String} dialogId - the dialog ID
* @private
*/
_dialogResize(dialogId) {
const self = this;
$(window).resize( function() {
const parent = $(dialogId).parent();
const windowSize = [$(window).width(), $(window).height()];
// size (we need to redimension both the dialog and the dialog content):
const dialogSize = self._getDialogSize();
parent.css({
width: dialogSize[0],
maxHeight: dialogSize[1]
});
const isDifferent = self._estimateDialogScalingFactor();
if (!isDifferent) {
$(dialogId).css({
width: dialogSize[0] - self._contentDelta[0],
maxHeight: dialogSize[1] - self._contentDelta[1]
});
}
// position:
parent.css({
position: 'absolute',
left: Math.max(0, (windowSize[0] - parent.outerWidth()) / 2.0),
top: Math.max(0, (windowSize[1] - parent.outerHeight()) / 2.0),
});
} );
}
/**
* Destroy the currently opened dialog box.
*
* @name module:core.GUI#dialog
* @function
* @public
*/
destroyDialog()
{
if ($("#expDialog").length) {
$("#expDialog").dialog("destroy");
}
if ($("#msgDialog").length) {
$("#msgDialog").dialog("destroy");
}
}
/**
* Listener for resource event from the [Server Manager]{@link ServerManager}.
*
* @name module:core.GUI#_onResourceEvents
* @function
* @private
* @param {Object.
} signal the signal
*/
_onResourceEvents(signal) {
this._psychoJS.logger.debug('signal: ' + util.toString(signal));
// all resources have been registered:
if (signal.message === ServerManager.Event.RESOURCES_REGISTERED) {
// for each resource, we have a 'downloading resource' and a 'resource downloaded' message:
this._progressBarMax = signal.count * 2;
$("#progressbar").progressbar("option", "max", this._progressBarMax);
this._progressBarCurrentIncrement = 0;
$("#progressMsg").text('all resources registered.');
}
// all the resources have been downloaded: show the ok button
else if (signal.message === ServerManager.Event.DOWNLOAD_COMPLETED) {
this._allResourcesDownloaded = true;
$("#progressMsg").text('all resources downloaded.');
this._updateOkButtonStatus();
}
// update progress bar:
else if (signal.message === ServerManager.Event.DOWNLOADING_RESOURCE || signal.message === ServerManager.Event.RESOURCE_DOWNLOADED)
{
if (typeof this._progressBarCurrentIncrement === 'undefined')
this._progressBarCurrentIncrement = 0;
++ this._progressBarCurrentIncrement;
if (signal.message === ServerManager.Event.RESOURCE_DOWNLOADED)
$("#progressMsg").text('downloaded ' + this._progressBarCurrentIncrement/2 + ' / ' + this._progressBarMax/2);
// $("#progressMsg").text(signal.resource + ': downloaded.');
// else
// $("#progressMsg").text(signal.resource + ': downloading...');
$("#progressbar").progressbar("option", "value", this._progressBarCurrentIncrement);
}
// unknown message: we just display it
else
$("#progressMsg").text(signal.message);
}
/**
* Update the status of the OK button.
*
* @name module:core.GUI#_updateOkButtonStatus
* @function
* @private
*/
_updateOkButtonStatus() {
if (this._psychoJS.config.environment === PsychoJS.Environment.LOCAL || (this._allResourcesDownloaded && this._nbSetRequiredKeys >= this._requiredKeys.length) ) {
$("#buttonOk").button("option", "disabled", false);
} else
$("#buttonOk").button("option", "disabled", true);
// strangely, changing the disabled option sometimes fails to update the ui,
// so we need to hide it and show it again:
$("#buttonOk").hide(0, () => { $("#buttonOk").show(); });
}
/**
* Estimate the scaling factor for the dialog popup windows.
*
* @name module:core.GUI#_estimateDialogScalingFactor
* @function
* @private
* @returns {boolean} whether or not the scaling factor is different from the previously estimated one
*/
_estimateDialogScalingFactor() {
const windowSize = [$(window).width(), $(window).height()];
// desktop:
let dialogScalingFactor = 1.0;
// mobile or tablet:
if (windowSize[0] < 1080) {
// landscape:
if (windowSize[0] > windowSize[1])
dialogScalingFactor = 1.5;
// portrait:
else
dialogScalingFactor = 2.0;
}
const isDifferent = (dialogScalingFactor !== this._dialogScalingFactor);
this._dialogScalingFactor = dialogScalingFactor;
return isDifferent;
}
/**
* Get the size of the dialog.
*
* @name module:core.GUI#_getDialogSize
* @private
* @returns {number[]} the size of the popup dialog window
*/
_getDialogSize() {
const windowSize = [$(window).width(), $(window).height()];
this._estimateDialogScalingFactor();
return [
Math.min(GUI.dialogMaxSize[0], (windowSize[0]-GUI.dialogMargin[0]) / this._dialogScalingFactor),
Math.min(GUI.dialogMaxSize[1], (windowSize[1]-GUI.dialogMargin[1]) / this._dialogScalingFactor)];
}
/**
* Listener for change event for required keys.
*
* @name module:core.GUI#_onKeyChange
* @function
* @static
* @private
* @param {module:core.GUI} gui - this GUI
* @param {Event} event - event
*/
static _onKeyChange(gui, event) {
const element = event.target;
const value = element.value;
if (typeof value !== 'undefined' && value.length > 0)
gui._nbSetRequiredKeys++;
else
gui._nbSetRequiredKeys--;
gui._updateOkButtonStatus();
}
}
/**
* Maximal dimensions of the dialog window.
*
* @name module:core.GUI#dialogMaxSize
* @enum {Symbol}
* @readonly
* @public
*/
GUI.dialogMaxSize = [500, 600];
/**
* Dialog window margins.
*
* @name module:core.GUI#dialogMargin
* @enum {Symbol}
* @readonly
* @public
*/
GUI.dialogMargin = [50, 50];