deleted js files that have been converted to typescript

This commit is contained in:
huangjx
2022-02-26 11:56:30 +08:00
parent 677c88e88c
commit f25d41b5f5
9 changed files with 10 additions and 622 deletions

View File

@@ -51,7 +51,7 @@ class contentTable {
div.appendChild(document.createTextNode(helper.t('No items')));
this.table.appendChild(div);
}
createHeading(prefix = "table-heading") {
createHeading(prefix = "table-heading"):HTMLElement {
let thead = document.createElement("section");
thead.classList.add(this.headingClass);
let headRow = document.createElement("header");
@@ -134,7 +134,7 @@ class contentTable {
}
createActionButton(name: string, path: string, data: string) {
createActionButton(name: string, path: string, data: string):HTMLElement {
let button = document.createElement("button");
button.classList.add("icon-" + name);
button.setAttribute("path", path);

View File

@@ -1,42 +0,0 @@
const eventHandler = {
add: function (eventType, target, selector, callback) {
if (typeof selector === 'function' && !callback) {
callback = selector;
selector = target;
}
if (typeof target === 'object') {
if (target.attachEvent) {
target.attachEvent('on' + eventType, function (e) {
callback.call(target, e);
});
}
else {
target.addEventListener(eventType, function (e) {
callback.call(target, e);
});
}
return;
}
let el = document.querySelector(target);
if (!el) {
return;
}
el.addEventListener(eventType, function (e) {
let element = e.target;
if (element === this && selector === target) {
callback.call(element, e);
return;
}
for (; element && element != this; element = element.parentNode) {
if (element.matches(selector)) {
callback.call(element, e);
break;
}
}
});
},
off: function (element, eventType, callback) {
element.removeEventListener(eventType, callback);
}
}
export default eventHandler;

View File

@@ -1,67 +0,0 @@
const Http = class {
data;
constructor(url) {
this.url = url;
this.method = 'POST';
this.data = null;
this.dataType = 'application/json';
this.xhr = new XMLHttpRequest();
}
static getInstance(url) {
return new Http(url);
}
setData(data) {
this.data = data
return this
}
setDataType($value) {
this.dataType = $value;
}
send() {
let token = this.getToken();
this.xhr.open(this.method, this.url);
this.xhr.setRequestHeader('requesttoken', token)
this.xhr.setRequestHeader('OCS-APIREQUEST', 'true')
if (this.dataType)
this.xhr.setRequestHeader('Content-Type', this.dataType);
let callback = this.handler;
this.xhr.onload = () => {
if (typeof callback === 'function')
callback(JSON.parse(this.xhr.response));
}
this.xhr.onerror = this.errorHandler;
this.xhr.send(JSON.stringify(this.data));
}
getToken() {
return document.getElementsByTagName('head')[0].getAttribute('data-requesttoken')
}
setUrl(url) {
this.url = url
return this
}
setMethod(method) {
this.method = method
return this
}
setHandler(handler) {
this.handler = handler || function (data) { };
return this;
}
setErrorHandler(handler) {
this.errorHandler = handler
return this;
}
upload(file) {
const fd = new FormData();
this.xhr.open(this.method, this.url, true);
let callback = this.handler;
this.xhr.onload = () => {
if (typeof callback === 'function')
callback(JSON.parse(this.xhr.response));
}
fd.append('torrentfile', file);
return this.xhr.send(fd);
}
}
export default Http

View File

@@ -1,120 +0,0 @@
/**
* A little class to manage a status field for a "saving" process.
* It can be used to display a starting message (e.g. "Saving...") and then
* replace it with a green success message or a red error message.
*
*
*/
export default {
/**
* Displayes a "Saving..." message in the given message placeholder
*
* @param {Object} selector Placeholder to display the message in
*/
startSaving(selector) {
this.startAction(selector, t('core', 'Saving …'))
},
/**
* Displayes a custom message in the given message placeholder
*
* @param {Object} selector Placeholder to display the message in
* @param {string} message Plain text message to display (no HTML allowed)
*/
startAction(selector, message) {
let el = document.querySelector(selector);
el.style.removeProperty("display")
el.textContent = message;
},
/**
* Displayes an success/error message in the given selector
*
* @param {Object} selector Placeholder to display the message in
* @param {Object} response Response of the server
* @param {Object} response.data Data of the servers response
* @param {string} response.data.message Plain text message to display (no HTML allowed)
* @param {string} response.status is being used to decide whether the message
* is displayed as an error/success
*/
finishedSaving(selector, response) {
this.finishedAction(selector, response)
},
/**
* Displayes an success/error message in the given selector
*
* @param {Object} selector Placeholder to display the message in
* @param {Object} response Response of the server
* @param {Object} response.data Data of the servers response
* @param {string} response.data.message Plain text message to display (no HTML allowed)
* @param {string} response.status is being used to decide whether the message
* is displayed as an error/success
*/
finishedAction(selector, response) {
if (response.status === 'success') {
this.finishedSuccess(selector, response.data.message)
} else {
this.finishedError(selector, response.data.message)
}
},
/**
* Displayes an success message in the given selector
*
* @param {Object} selector Placeholder to display the message in
* @param {string} message Plain text success message to display (no HTML allowed)
*/
finishedSuccess(selector, message) {
let el = document.querySelector(selector);
el.textContent = message;
if (el.classList.contains("error")) el.classList.remove("error");
el.classList.add("success");
this.fadeOut(el);
},
/**
* Displayes an error message in the given selector
*
* @param {Object} selector Placeholder to display the message in
* @param {string} message Plain text error message to display (no HTML allowed)
*/
finishedError(selector, message) {
let el = document.querySelector(selector);
el.textContent = message;
if (el.classList.contains("success")) el.classList.remove("success");
el.classList.add("error");
},
fadeIn(element, duration = 1000) {
(function increment() {
element.style.opacity = String(0);
element.style.removeProperty("display")
let opacity = parseFloat(element.style.opacity);
if (opacity !== 1) {
setTimeout(() => {
increment(opacity + 0.1);
}, duration / 10);
}
})();
},
fadeOut(element, duration = 1000) {
let opacity = parseFloat(element.style.opacity) || 1;
(function decrement() {
if ((opacity -= 0.1) < 0) {
element.style.display = 'none'
element.style.removeProperty('opacity');
} else {
setTimeout(() => {
decrement();
}, duration / 10);
}
})();
},
show(el) {
el.style.display = '';
},
hide(el) {
el.style.display = 'none';
}
}

View File

@@ -1,155 +0,0 @@
import helper from '../utils/helper'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
class ncTable {
actionLink = true;
bodyClass = "ncdownloader-table-data";
rowClass = "table-row";
headingClass = "table-heading";
cellClass = "table-cell";
//this is the parent element the table is going to append to
tableContainer = 'ncdownloader-table-wrapper';
numRow;
table;
constructor(heading, rows) {
this.table = document.getElementById(this.tableContainer);
if (heading && rows) {
this.table.innerHTML = '';
this.rows = rows;
this.heading = heading;
this.actionButtons = [];
}
}
static getInstance(heading, row) {
return new ncTable(heading, row);
}
create() {
let thead = this.createHeading()
let tbody = this.createRow();
this.table.appendChild(thead);
this.table.appendChild(tbody);
return this;
}
clear() {
this.table.innerHTML = '';
}
loading() {
let htmlStr = '<div class="text-center"><div class="spinner-border" role="status"> <span class="visually-hidden">Loading...</span></div></div>'
this.table.innerHTML = htmlStr;
return this;
}
noData() {
this.clear();
let div = document.createElement('div');
div.classList.add("no-items");
div.appendChild(document.createTextNode(t("ncdownloader", 'No items')));
this.table.appendChild(div);
}
createHeading(prefix = "table-heading") {
let thead = document.createElement("section");
thead.classList.add(this.headingClass);
let headRow = document.createElement("header");
headRow.classList.add(this.rowClass);
thead.classList.add(this.headingClass);
this.heading.forEach(name => {
let rowItem = document.createElement("div");
rowItem.classList.add(prefix + "-" + name.toLowerCase());
rowItem.classList.add(this.cellClass);
let text = document.createTextNode(t("ncdownloader", helper.ucfirst(name)));
rowItem.appendChild(text);
headRow.appendChild(rowItem);
})
thead.appendChild(headRow);
return thead;
}
createRow() {
let tbody = document.createElement("section");
tbody.classList.add(this.bodyClass);
tbody.classList.add("table-body");
let row;
for (const element of this.rows) {
if (element === null) {
continue;
}
row = document.createElement("div");
row.classList.add(this.rowClass);
let text;
for (let key in element) {
if (key.substring(0, 4) == 'data') {
let name = key.replace("_", "-");
row.setAttribute(name, element[key]);
row.setAttribute("id", element[key]);
continue;
}
let rowItem = document.createElement("div");
rowItem.classList.add(this.cellClass);
if (key === 'actions') {
rowItem.classList.add([this.cellClass, "action-item"].join("-"));
let container = document.createElement("div");
container.classList.add("button-container");
element[key].forEach(value => {
if (!value.name) {
return;
}
let data = value.data || '';
container.appendChild(this.createActionButton(value.name, value.path, data));
})
rowItem.appendChild(container);
row.appendChild(rowItem);
continue;
}
if (typeof element[key] === 'object') {
let child = element[key];
let div;
child.forEach(ele => {
div = document.createElement('div');
if (helper.isHtml(ele)) {
div.innerHTML = ele;
} else {
text = document.createTextNode(ele);
div.appendChild(text);
}
rowItem.appendChild(div);
})
rowItem.setAttribute("id", [this.cellClass, key].join("-"));
row.appendChild(rowItem);
continue;
}
text = document.createTextNode(element[key]);
rowItem.appendChild(text);
rowItem.setAttribute("id", [this.cellClass, key].join("-"));
row.appendChild(rowItem);
}
tbody.appendChild(row);
}
return tbody;
}
createActionButton(name, path, data) {
let button = document.createElement("button");
button.classList.add("icon-" + name);
button.setAttribute("path", path);
button.setAttribute("data", data);
if (name == 'refresh') {
name = 'Redownload';
}
button.setAttribute("data-tippy-content", helper.ucfirst(name));
button.setAttribute("title", helper.ucfirst(name));
return button;
}
createActionCell(cell) {
let div = document.createElement("div");
let button = document.createElement("button");
button.classList.add("icon-more", "action-button");
button.setAttribute("id", "action-links-button");
div.classList.add("action-item");
div.appendChild(button);
//div.appendChild(actionLinks);
cell.appendChild(div);
}
}
export default ncTable;

View File

@@ -1,111 +0,0 @@
class settingsForm {
parent = "custom-aria2-settings-container";
constructor() {
}
static getInstance() {
return new this();
}
setParent(selector) {
this.parent = selector;
return this;
}
create(parent, element) {
let label = this._createLabel(element.name, element.id)
let input = this._createInput(element);
//let saveBtn = this._createSaveBtn(element.id);
let cancelBtn = this._createCancelBtn("has-content");
let container = this._createContainer(element.id);
[label, input, cancelBtn].forEach(ele => {
container.appendChild(ele);
})
return parent.prepend(container);
}
createCustomInput(keyId, valueId) {
let div = this._createContainer(keyId + "-container")
div.appendChild(this._createInput({ id: keyId }));
div.appendChild(this._createInput({ id: valueId }));
div.appendChild(this._createCancelBtn());
return div;
}
createInput(element) {
let div = document.createElement("div");
div.classList.add(this.parent);
/* element.forEach(element => {
let label = document.createElement('label');
label.setAttribute("for", element.id);
let text = document.createTextNode(element.name);
label.appendChild(text);
div.appendChild(label);
// div.appendChild(this._createInput(element));
});*/
div.appendChild(this._createInput(element));
let button = document.createElement("button");
//button.setAttribute("type",'button')
button.classList.add("icon-close");
div.appendChild(button);
button = document.createElement("input");
button.setAttribute('type', 'button');
button.setAttribute('value', 'save');
button.setAttribute("data-rel", this.parent);
div.appendChild(button);
return div;
}
_createContainer(id) {
let div = document.createElement("div");
div.classList.add(id);
return div;
}
_createCancelBtn(className = '') {
let button = document.createElement("button");
if (className)
button.classList.add(className);
//button.setAttribute("type",'button')
button.classList.add("icon-close");
return button;
}
_createSaveBtn(id) {
let button = document.createElement("input");
button.setAttribute('type', 'button');
button.setAttribute('value', 'save');
button.setAttribute("data-rel", id + "-container");
return button;
}
_createLabel(name, id) {
name = name.replace('_', '-');
let label = document.createElement("lable");
label.setAttribute("for", id);
let text = document.createTextNode(name);
label.appendChild(text);
return label;
}
_createInput(data) {
let input = document.createElement('input');
let type = data.type || "text";
let placeholder = data.placeholder || 'Leave empty if no value needed';
let value = data.value || '';
input.setAttribute('type', type);
input.setAttribute('id', data.id);
input.setAttribute("name", data.name || data.id);
if (type === 'text') {
input.setAttribute('value', value);
input.setAttribute('placeholder', placeholder);
}
input.classList.add('form-input-' + type);
return input;
}
render(data) {
let parent = document.getElementById(this.parent)
for (const element of data) {
this.create(parent, element)
}
}
}
export default settingsForm

View File

@@ -15,11 +15,11 @@ class settingsForm {
static getInstance() {
return new this();
}
setParent(selector: string) {
setParent(selector: string):settingsForm {
this.parent = selector;
return this;
}
create(parent: HTMLElement, element: dataItems) {
create(parent: HTMLElement, element: dataItems):void {
let label = this._createLabel(element.name, element.id)
let input = this._createInput(element);
//let saveBtn = this._createSaveBtn(element.id);
@@ -32,7 +32,7 @@ class settingsForm {
return parent.prepend(container);
}
createCustomInput(keyId:string, valueId:string) {
createCustomInput(keyId:string, valueId:string):HTMLElement {
let div = this._createContainer(keyId + "-container")
let items:dataItems = {
id:keyId,
@@ -46,12 +46,12 @@ class settingsForm {
return div;
}
_createContainer(id: string) {
_createContainer(id: string):HTMLElement {
let div = document.createElement("div");
div.classList.add(id);
return div;
}
_createCancelBtn(className = '') {
_createCancelBtn(className = ''):HTMLElement {
let button = document.createElement("button");
if (className)
button.classList.add(className);
@@ -59,14 +59,14 @@ class settingsForm {
button.classList.add("icon-close");
return button;
}
_createSaveBtn(id: string) {
_createSaveBtn(id: string):HTMLElement {
let button = document.createElement("input");
button.setAttribute('type', 'button');
button.setAttribute('value', 'save');
button.setAttribute("data-rel", id + "-container");
return button;
}
_createLabel(name: string, id: string) {
_createLabel(name: string, id: string):HTMLElement {
name = name.replace('_', '-');
let label = document.createElement("lable");
label.setAttribute("for", id);
@@ -74,7 +74,7 @@ class settingsForm {
label.appendChild(text);
return label;
}
_createInput(data: dataItems) {
_createInput(data: dataItems):HTMLElement {
let input = document.createElement('input');
let type = data.type || "text";
let placeholder = data.placeholder || 'Leave empty if no value needed';
@@ -89,7 +89,6 @@ class settingsForm {
input.classList.add('form-input-' + type);
return input;
}
render(data: data) {
let parent = document.getElementById(this.parent)
for (const element of data) {

View File

@@ -1,50 +0,0 @@
import $ from 'jquery'
class Tooltip {
id = "ncdownloader-tooltip";
messageNode;
style = {};
text;
constructor(element, text) {
if (typeof element !== 'string' && !(element instanceof HTMLElement))
throw ("invalid element!");
this.element = typeof element == 'object' ? element : document.querySelector(element);
this.style = {
position: 'fixed',
display: 'block',
}
this.text = text || element.getAttribute("data-text");
}
create(id) {
this.messageNode = document.createElement("div");
this.messageNode.classList.add(this.id);
this.messageNode.setAttribute("id", this.id);
this.messageNode.style.display = this.style.display;
this.messageNode.style.position = this.style.position;
this.messageNode.style.zIndex = 10000;
let div = document.createElement('div');
div.setAttribute("id", id);
let text = document.createTextNode(this.text);
div.appendChild(text);
this.messageNode.appendChild(div);
this.setPosition();
return this;
}
render() {
document.body.appendChild(this.messageNode);
}
html() {
return this.messageNode;
}
setPosition(bottomMargin, leftMargin) {
bottomMargin = bottomMargin || 20;
leftMargin = leftMargin || 0;
let rect = this.element.getBoundingClientRect();
let top = (rect['top'] + bottomMargin) + "px";
let left = (rect['left'] - leftMargin) + "px";
this.messageNode.style.top = top;
this.messageNode.style.left = left
}
}
export default Tooltip;

View File

@@ -1,66 +0,0 @@
import Tooltip from "../lib/tooltip";
class Clipboard {
element;
text;
constructor(element, text) {
if (typeof element !== 'string' && !(element instanceof HTMLElement))
throw ("invalid element!");
this.element = typeof element == 'object' ? element : document.querySelector(element);
this.text = text || element.getAttribute("data-text");
}
_copy(text) {
let textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.top = "0";
textArea.style.left = "0";
textArea.style.position = "fixed";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
let result;
try {
result = document.execCommand('copy');
//console.log('copied using exceCommand');
} catch (err) {
console.error('failed to copy', err);
result = false;
} finally {
document.body.removeChild(textArea);
}
if (result) {
this.ShowMsg("Copied!");
}
}
ShowMsg(msg) {
let tip = new Tooltip(this.element, msg);
let html = tip.create('copy-alert').html();
document.body.appendChild(html);
const callback = (element) => {
element.remove()
}
setTimeout(() => {
callback(html)
}, 1000);
}
Copy() {
if (!navigator.clipboard) {
return this._copy(this.text);
}
return navigator.clipboard.writeText(this.text).then(() => {
this.ShowMsg("Copied!");
}, function (err) {
console.error('failed to copy text: ', err);
});
}
}
export default Clipboard;