CyberChef/src/web/HTMLCategory.js

53 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-11-28 11:42:58 +01:00
/**
* Object to handle the creation of operation categories.
*
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2016
* @license Apache-2.0
*
* @constructor
* @param {string} name - The name of the category.
* @param {boolean} selected - Whether this category is pre-selected or not.
*/
2017-04-13 19:08:50 +02:00
const HTMLCategory = function(name, selected) {
2016-11-28 11:42:58 +01:00
this.name = name;
this.selected = selected;
this.opList = [];
2016-11-28 11:42:58 +01:00
};
/**
* Adds an operation to this category.
*
* @param {HTMLOperation} operation - The operation to add.
*/
HTMLCategory.prototype.addOperation = function(operation) {
this.opList.push(operation);
2016-11-28 11:42:58 +01:00
};
/**
* Renders the category and all operations within it in HTML.
*
* @returns {string}
*/
HTMLCategory.prototype.toHtml = function() {
2017-04-13 19:08:50 +02:00
const catName = "cat" + this.name.replace(/[\s/-:_]/g, "");
let html = "<div class='panel category'>\
2016-11-28 11:42:58 +01:00
<a class='category-title' data-toggle='collapse'\
data-parent='#categories' href='#" + catName + "'>\
2016-11-28 11:42:58 +01:00
" + this.name + "\
</a>\
<div id='" + catName + "' class='panel-collapse collapse\
" + (this.selected ? " in" : "") + "'><ul class='op-list'>";
2017-02-09 16:09:33 +01:00
2017-04-13 19:08:50 +02:00
for (let i = 0; i < this.opList.length; i++) {
html += this.opList[i].toStubHtml();
2016-11-28 11:42:58 +01:00
}
2017-02-09 16:09:33 +01:00
2016-11-28 11:42:58 +01:00
html += "</ul></div></div>";
return html;
};
export default HTMLCategory;