mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-08 15:25:01 -04:00
add option to c-op-list to create a sortable list
This commit is contained in:
parent
b3ad5bb303
commit
d9ea487c1a
1 changed files with 30 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
import {COperationLi} from "./c-operation-li.mjs";
|
import {COperationLi} from "./c-operation-li.mjs";
|
||||||
|
import Sortable from "sortablejs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* c(ustom element)-operation-list
|
* c(ustom element)-operation-list
|
||||||
|
@ -9,13 +10,20 @@ import {COperationLi} from "./c-operation-li.mjs";
|
||||||
* @param {Object} icon ( { class: string, innerText: string } ). check-icon by default
|
* @param {Object} icon ( { class: string, innerText: string } ). check-icon by default
|
||||||
*/
|
*/
|
||||||
export class COperationList extends HTMLElement {
|
export class COperationList extends HTMLElement {
|
||||||
constructor(app, opNames, includeStarIcon, icon) {
|
constructor(
|
||||||
|
app,
|
||||||
|
opNames,
|
||||||
|
includeStarIcon,
|
||||||
|
icon,
|
||||||
|
isSortable = false
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.opNames = opNames;
|
this.opNames = opNames;
|
||||||
this.includeStarIcon = includeStarIcon;
|
this.includeStarIcon = includeStarIcon;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
|
this.isSortable = isSortable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,6 +47,27 @@ export class COperationList extends HTMLElement {
|
||||||
ul.appendChild(li);
|
ul.appendChild(li);
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
if (this.isSortable) {
|
||||||
|
const sortableList = Sortable.create(ul, {
|
||||||
|
group: "sorting",
|
||||||
|
sort: true,
|
||||||
|
draggable: "c-operation-li",
|
||||||
|
onFilter: function (e) {
|
||||||
|
const el = sortableList.closest(e.item);
|
||||||
|
if (el && el.parentNode) {
|
||||||
|
$(el).popover("dispose");
|
||||||
|
el.parentNode.removeChild(el);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onEnd: function(e) {
|
||||||
|
if (this.removeIntent) {
|
||||||
|
$(e.item).popover("dispose");
|
||||||
|
e.item.remove();
|
||||||
|
}
|
||||||
|
}.bind(this),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ul.dispatchEvent(this.app.manager.oplistcreate);
|
ul.dispatchEvent(this.app.manager.oplistcreate);
|
||||||
|
|
||||||
this.append(ul);
|
this.append(ul);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue