Skip to content

Commit

Permalink
refactor and jsdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
Klap-in committed Dec 23, 2023
1 parent fe77ef1 commit 8094756
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
44 changes: 32 additions & 12 deletions scripts/contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ var IndexmenuContextmenu = {
/**
* Common functions
* Insert your custom functions (available for all users) here.
*/

/**
* Navigate to the search page
*
* @param {string} urlbase index.config.urlbase
* @param {string} sepchar index.config.sepchar
Expand Down Expand Up @@ -186,24 +190,40 @@ var IndexmenuContextmenu = {
return url;
},

reqpage: function (b, s, id, n) {
var r;
if (n) {
r = id + s + n;
/**
* Navigate to the editor window
*
* @param {string} urlbase
* @param {string} sepchar
* @param {string} id
* @param {string} pagename
*/
reqpage: function (urlbase, sepchar, id, pagename) {
let newpageid;
if (pagename) {
newpageid = id + sepchar + pagename;
} else {
r = prompt(LANG.plugins.indexmenu.insertpagename, "");
if (!r) {
newpageid = prompt(LANG.plugins.indexmenu.insertpagename, "");
if (!newpageid) {
return;
}
r = id + s + r;
newpageid = id + sepchar + newpageid;
}
if (newpageid) {
window.location.href = IndexmenuContextmenu.getid(urlbase, newpageid) + "do=edit";
}
if (r) window.location.href = IndexmenuContextmenu.getid(b, r) + "do=edit";
},

insertTags: function (lnk, sep) {
var r, l = lnk;
if (sep) {
r = new RegExp(sep, "g");
/**
* Insert link syntax with given id in current editor window
*
* @param {string} lnk page id
* @param {string} sepchar
*/
insertTags: function (lnk, sepchar) {
let r, l = lnk;
if (sepchar) {
r = new RegExp(sepchar, "g");
l = lnk.replace(r, ':');
}
insertTags('wiki__text', '[[', ']]', l);
Expand Down
10 changes: 5 additions & 5 deletions scripts/contextmenu.local.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ if (JSINFO && JSINFO.isadmin) {
* Common available functions:
*
* Some common functions are added by [indexmenu plugin folder]/scripts/contextmenu.js
* - IndexmenuContextmenu.srchpage(u, s, isdir, nid)
* - IndexmenuContextmenu.getid(u, id)
* - IndexmenuContextmenu.reqpage(b, s, id, n)
* - IndexmenuContextmenu.insertTags(lnk, sep)
* - IndexmenuContextmenu.srchpage(urlbase, sepchar, isdir, dokuid)
* - IndexmenuContextmenu.getid(urlbase, dokuid)
* - IndexmenuContextmenu.reqpage(urlbase, sepchar, dokuid, pagename)
* - IndexmenuContextmenu.insertTags(dokuid, sepchar)
*
* Insert your custom functions (available for all users) at the bottom of this file.
*/
Expand All @@ -67,4 +67,4 @@ function indexmenu_custom_dosomething(a, isdir) {
//do something
return false;
}
*/
*/

0 comments on commit 8094756

Please sign in to comment.