Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复ContextMenuActions的Bug #2128

Open
wants to merge 1 commit into
base: 2.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/Grid/Displayers/ContextMenuActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ protected function addScript()
{
$script = <<<JS
(function () {
var id = '#{$this->elementId}';

$("body").on("contextmenu", "#{$this->grid->getTableId()} tr", function(e) {
$(id + ' .dropdown-menu').hide();
var id = '#{$this->elementId}';
// 先解绑事件再绑定,不然切换界面时会导致事件重复绑定
$("body").off('contextmenu').on("contextmenu", "#{$this->grid->getTableId()} tr", function(e) {
// 每次都要移除,免得不同界面出现Bug
$(id + ' .dropdown-menu').remove();

var menu = $(this).find('td .grid-dropdown-actions .dropdown-menu');
// 直接复制操作栏元素和事件
var menu = $(this).find('td .grid-dropdown-actions .dropdown-menu').clone(true);
var index = $(this).index();

if (menu.length) {
menu.attr('index', index).detach().appendTo(id);
} else {
menu = $(id + ' .dropdown-menu[index='+index+']');
}
menu.attr('index', index).appendTo(id);

if (menu.height() > (document.body.clientHeight - e.pageY)) {
menu.css({left: e.pageX+10, top: e.pageY - menu.height()}).show();
} else {
menu.css({left: e.pageX+10, top: e.pageY-10}).show();
}

return false;
});

Expand All @@ -39,11 +39,13 @@ protected function addScript()
}

$(document).on('click',function(){
$(id + ' .dropdown-menu').hide();
// 每次都需要移除插入的元素
$(id + ' .dropdown-menu').remove();
})

$(id).click('a', function () {
$(this).find('.dropdown-menu').hide();
// 每次都需要移除插入的元素
$(this).find('.dropdown-menu').remove();
});
})();
JS;
Expand Down