We can now execute a function when enter key used
Will be used to open links easily Key isn't activated is no function is passed to showNotification
This commit is contained in:
@@ -388,7 +388,7 @@ export async function addAssetsOnScene(scene){
|
|||||||
linkPlate.scene.position.y = 2;
|
linkPlate.scene.position.y = 2;
|
||||||
linkPlate.scene.position.z = 1;
|
linkPlate.scene.position.z = 1;
|
||||||
scene.add( linkPlate.scene );
|
scene.add( linkPlate.scene );
|
||||||
linkPlate.onEnterHitbox = ()=>{Notifications.showNotification("Hello World !")};
|
linkPlate.onEnterHitbox = ()=>{Notifications.showNotification("Hello World !", ()=>{console.log('ok')})};
|
||||||
linkPlate.onLeaveHitbox = ()=>{Notifications.hideNotification()};
|
linkPlate.onLeaveHitbox = ()=>{Notifications.hideNotification()};
|
||||||
linkPlates.push(linkPlate);
|
linkPlates.push(linkPlate);
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,34 @@
|
|||||||
import $ from 'jquery';
|
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 p").html(HTMLText);
|
||||||
$("#notification_bar").css( 'opacity', 0.9 ).animate({
|
$("#notification_bar").css('opacity', 0.9).animate({
|
||||||
width:320
|
width: 320
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hideNotification(){
|
//Hiding function
|
||||||
|
export function hideNotification() {
|
||||||
$("#notification_bar").animate({
|
$("#notification_bar").animate({
|
||||||
width:0
|
width: 0
|
||||||
}, 500, function(){ $(this).css( 'opacity', 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();
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user