mirror of
https://github.com/HeyPuter/puter.git
synced 2025-02-03 07:48:46 +08:00
fixed left/right issue. Feature is ready
This commit is contained in:
parent
23a7f852b4
commit
8ec0e63d7b
@ -145,45 +145,28 @@ function UIContextMenu(options){
|
||||
$(contextMenu).remove();
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// initialize menuAim plugin
|
||||
// initialize menuAim plugin (../libs/jquery.menu-aim.js)
|
||||
$(contextMenu).menuAim({
|
||||
submenuDirection: function(){
|
||||
//if this is not a submenu
|
||||
// if(!options.is_submenu){
|
||||
// if submenu is going to be on the right of the main menu
|
||||
if(x_pos + $(contextMenu).width() + 10 > window.innerWidth){
|
||||
console.log('right')
|
||||
//if not submenu
|
||||
if(!options.is_submenu){
|
||||
// if submenu left postiton is greater than main menu left position
|
||||
if($(contextMenu).offset().left + 2 * $(contextMenu).width() + 15 < window.innerWidth ){
|
||||
return "right";
|
||||
} else {
|
||||
console.log('left')
|
||||
return "left";
|
||||
}
|
||||
// }
|
||||
}
|
||||
},
|
||||
//activates item when mouse enters depending in mouse position and direction
|
||||
activate: function (e) {
|
||||
|
||||
//if submenu opens on right make submenuDirection right
|
||||
// if($(contextMenu).offset().left + $(contextMenu).width() + 10 > window.innerWidth){
|
||||
// $(contextMenu).menuAim({
|
||||
// submenuDirection: 'right'
|
||||
// });
|
||||
// } else {
|
||||
// $(contextMenu).menuAim({
|
||||
// submenuDirection: 'left'
|
||||
// });
|
||||
// }
|
||||
// hover over an item
|
||||
|
||||
|
||||
|
||||
//activate items
|
||||
let item = $(e).closest('.context-menu-item');
|
||||
|
||||
console.log('activate', e)
|
||||
|
||||
// mark other items as inactive
|
||||
$(contextMenu).find('.context-menu-item').removeClass('context-menu-item-active');
|
||||
// mark this item as active
|
||||
@ -195,7 +178,6 @@ function UIContextMenu(options){
|
||||
|
||||
|
||||
// activate submenu
|
||||
|
||||
// open submenu if applicable
|
||||
if($(e).hasClass('context-menu-item-submenu')){
|
||||
let item_rect_box = e.getBoundingClientRect();
|
||||
@ -216,8 +198,8 @@ function UIContextMenu(options){
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
//deactivates row when mouse leavess
|
||||
deactivate: function (e) {
|
||||
console.log('deactivate')
|
||||
//deactivate submenu
|
||||
@ -227,47 +209,7 @@ function UIContextMenu(options){
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// // when mouse is over an item
|
||||
// $(contextMenu).find('.context-menu-item').on('mouseover', function (e) {
|
||||
// // mark other items as inactive
|
||||
// $(contextMenu).find('.context-menu-item').removeClass('context-menu-item-active');
|
||||
// // mark this item as active
|
||||
// $(this).addClass('context-menu-item-active');
|
||||
// // close any submenu that doesn't belong to this item
|
||||
// $(`.context-menu[data-parent-id="${menu_id}"]`).remove();
|
||||
// // mark this context menu as active
|
||||
// $(contextMenu).addClass('context-menu-active');
|
||||
// })
|
||||
|
||||
// open submenu if applicable
|
||||
// $(`#context-menu-${menu_id} > li.context-menu-item-submenu`).on('mouseover', function (e) {
|
||||
|
||||
// // open submenu only if it's not already open
|
||||
// if($(`.context-menu[data-id="${menu_id}-${$(this).attr('data-action')}"]`).length === 0){
|
||||
// let item_rect_box = this.getBoundingClientRect();
|
||||
|
||||
// // close other submenus
|
||||
// $(`.context-menu[parent-element-id="${menu_id}"]`).remove();
|
||||
|
||||
// // open the new submenu
|
||||
// UIContextMenu({
|
||||
// items: options.items[parseInt($(this).attr('data-action'))].items,
|
||||
// parent_id: menu_id,
|
||||
// is_submenu: true,
|
||||
// id: menu_id + '-' + $(this).attr('data-action'),
|
||||
// position:{
|
||||
// top: item_rect_box.top - 5,
|
||||
// left: x_pos + item_rect_box.width + 15,
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// return false;
|
||||
// });
|
||||
|
||||
// useful in cases such as where a menue item is over a window, this prevents from the mousedown event
|
||||
// useful in cases such as where a menu item is over a window, this prevents from the mousedown event
|
||||
// reaching the window underneath
|
||||
$(`#context-menu-${menu_id} > li:not(.context-menu-item-disabled)`).on('mousedown', function (e) {
|
||||
e.preventDefault();
|
||||
|
Loading…
Reference in New Issue
Block a user