From ac12ada8ec0ccfebc092eb6366b256027005d680 Mon Sep 17 00:00:00 2001 From: Martin Wendt Date: Sun, 10 Mar 2019 08:57:51 +0100 Subject: [PATCH] Sample patch to enable hyphens as title Only four hyphens will be recognized as separator. Update #136 --- demo/index-1-12.html | 10 ++++++++++ jquery.ui-contextmenu.js | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/demo/index-1-12.html b/demo/index-1-12.html index 307d5a0..befa207 100644 --- a/demo/index-1-12.html +++ b/demo/index-1-12.html @@ -80,6 +80,14 @@ loadTheme: "Base" }); */ + /* SAMPLE for issue #136: globally disable hyphen detection. */ + $.ui.menu.prototype._isDivider = function(item) { + console.log("_isDivider", this, arguments); + // Match hyphen, em dash, en dash + // return !/[^\-\u2014\u2013\s]/.test( item.text() ); + // return false; + return item.text() === "----"; + }; /* Menu 1: init by passing an array of entries. */ $(document).contextmenu({ @@ -93,6 +101,8 @@ {title: "Cut Ctrl+X", cmd: "cut", uiIcon: "ui-icon-scissors"}, {title: "Copy Ctrl+C", cmd: "copy", uiIcon: "ui-icon-copy"}, {title: "Paste Ctrl+V", cmd: "paste", uiIcon: "ui-icon-clipboard", disabled: true }, + {title: "-", cmd: "hyphen"}, + {title: " - -", cmd: "hyphen2"}, {title: "----"}, {title: "More", children: [ {title: "Sub 1 (callback)", action: function(event, ui) { alert("action callback sub1");} }, diff --git a/jquery.ui-contextmenu.js b/jquery.ui-contextmenu.js index a8fcf73..15776d0 100644 --- a/jquery.ui-contextmenu.js +++ b/jquery.ui-contextmenu.js @@ -531,7 +531,8 @@ $.extend($.moogle.contextmenu, { $parentLi.attr("data-command", entry.cmd); - if ( !/[^\-\u2014\u2013\s]/.test( entry.title ) ) { + if ( entry.title === "----" ) { + // if ( !/[^\-\u2014\u2013\s]/.test( entry.title ) ) { // hyphen, em dash, en dash: separator as defined by UI Menu 1.10 $parentLi.text(entry.title); } else {