From 7317033691b38f05a1334da757a17279dbaedb8f Mon Sep 17 00:00:00 2001 From: xwx <1093967571@qq.com> Date: Mon, 8 Mar 2021 10:15:47 +0800 Subject: [PATCH] feat(src/controllers/constant.js src/controllers/rowcolumnoperation.js src/index.html): custom Add custom rigth click menu #514 --- src/controllers/constant.js | 9 +++++++++ src/controllers/rowColumnOperation.js | 23 +++++++++++++++++++++++ src/index.html | 8 ++++++++ 3 files changed, 40 insertions(+) diff --git a/src/controllers/constant.js b/src/controllers/constant.js index d442808..cdb9c96 100644 --- a/src/controllers/constant.js +++ b/src/controllers/constant.js @@ -288,6 +288,14 @@ function rightclickHTML(){ dataMenuseparator = false; } + const customsButtons = (config.customs || [{title: 'test'}]).map((item, index) => ` +
+
+ ${item.title} +
+
` + ).join(""); + const rightclickContainer = `
${rightclick.copy}
@@ -422,6 +430,7 @@ function rightclickHTML(){
${toolbar.cellFormat}
+ ${customsButtons}
diff --git a/src/controllers/rowColumnOperation.js b/src/controllers/rowColumnOperation.js index 1f9fda5..7703210 100644 --- a/src/controllers/rowColumnOperation.js +++ b/src/controllers/rowColumnOperation.js @@ -1134,6 +1134,29 @@ export function rowColumnOperationInitial(){ }) + + // custom right-click a cell buttton click + $(".luckysheetColsRowsHandleAdd_custom").click(function (clickEvent) { + $("#luckysheet-rightclick-menu").hide(); + const cellRightClickConfig = + luckysheetConfigsetting.cellRightClickConfig; + const rowIndex = Store.luckysheet_select_save[0].row[0]; + const columnIndex = Store.luckysheet_select_save[0].column[0]; + if ( + cellRightClickConfig.customs[ + Number(clickEvent.currentTarget.dataset.index) + ] + ) { + try { + cellRightClickConfig.customs[ + Number(clickEvent.currentTarget.dataset.index) + ].onClick(clickEvent, event, { rowIndex, columnIndex }); + } catch (e) { + console.error("custom click error", e); + } + } + + }); // Add the row up, and click the text area to trigger the confirmation instead of clicking the confirmation button to enhance the experience // $("#luckysheet-addTopRows").click(function (event) { // $("#luckysheetColsRowsHandleAdd_sub .luckysheet-cols-menuitem:first-child").click(function (event) { diff --git a/src/index.html b/src/index.html index 2fa8773..f1dd0cc 100644 --- a/src/index.html +++ b/src/index.html @@ -1878,6 +1878,14 @@ }, imageClass:"loadingAnimation" } + options.cellRightClickConfig = { + customs: [{ + title: 'test', + onClick: function (clickEvent, event, params) { + console.log('function test click', clickEvent, event, params) + } + }] + } luckysheet.create(options); })