diff --git a/src/utils/addAssetsOnScene.js b/src/utils/addAssetsOnScene.js index acfd0ba..b8353c6 100644 --- a/src/utils/addAssetsOnScene.js +++ b/src/utils/addAssetsOnScene.js @@ -388,7 +388,7 @@ export async function addAssetsOnScene(scene){ linkPlate.scene.position.y = 2; linkPlate.scene.position.z = 1; scene.add( linkPlate.scene ); - linkPlate.onEnterHitbox = ()=>{Notifications.showNotification("Hello World !")}; + linkPlate.onEnterHitbox = ()=>{Notifications.showNotification("Hello World !", ()=>{console.log('ok')})}; linkPlate.onLeaveHitbox = ()=>{Notifications.hideNotification()}; linkPlates.push(linkPlate); diff --git a/src/utils/notification.js b/src/utils/notification.js index fb0512a..949943c 100644 --- a/src/utils/notification.js +++ b/src/utils/notification.js @@ -1,14 +1,34 @@ import $ from 'jquery'; -export function showNotification(HTMLText){ +let optionalFunction; + +//Showing notification +export function showNotification(HTMLText, optionalEnterKeyFunction) { + //If optionalEnterKeyFunction is defined, we enable Enter key + if (optionalEnterKeyFunction && typeof optionalEnterKeyFunction === 'function') { + optionalFunction = optionalEnterKeyFunction; + } + $("#notification_bar p").html(HTMLText); - $("#notification_bar").css( 'opacity', 0.9 ).animate({ - width:320 + $("#notification_bar").css('opacity', 0.9).animate({ + width: 320 }, 500); } -export function hideNotification(){ +//Hiding function +export function hideNotification() { $("#notification_bar").animate({ - width:0 - }, 500, function(){ $(this).css( 'opacity', 0 ) }); -} \ No newline at end of file + width: 0 + }, 500, function () { + $(this).css('opacity', 0); + //This will disable the Enter key + optionalFunction = undefined; + }); +} + +//Event listener on Enter key (13) +$(document).on('keyup', function (e) { + if (e.which === 13 && optionalFunction) { + optionalFunction(); + } +}); \ No newline at end of file