本文整理匯總了TypeScript中wed.domutil.childrenByClass方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript domutil.childrenByClass方法的具體用法?TypeScript domutil.childrenByClass怎麽用?TypeScript domutil.childrenByClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wed.domutil
的用法示例。
在下文中一共展示了domutil.childrenByClass方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: execute
execute(data: TransformationData): void {
const editor = this.editor;
const dataCaret = editor.caretManager.getDataCaret(true)!;
const mode = editor.modeTree.getMode(dataCaret.node);
if (!(mode instanceof Mode)) {
throw new Error("expected BTW mode");
}
const decorator = editor.modeTree.getDecorator(dataCaret.node);
if (!(decorator instanceof BTWDecorator)) {
throw new Error("our decorator must be a BTWDecorator");
}
const doc = editor.guiRoot.ownerDocument;
const mappings = mode.getAbsoluteNamespaceMappings();
const senses = editor.guiRoot.querySelectorAll(
util.classFromOriginalName("btw:sense", mappings));
const labels: Element[] = [];
const radios: Element[] = [];
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < senses.length; ++i) {
const sense = senses[i];
let dataNode = $.data(sense, "wed_mirror_node");
const termNodes = btwUtil.termsForSense(sense, mappings);
const terms: string[] = [];
// tslint:disable-next-line:prefer-for-of
for (let tix = 0; tix < termNodes.length; ++tix) {
terms.push($.data(termNodes[tix], "wed_mirror_node").textContent);
}
const senseLabel = decorator.refmans.getSenseLabel(sense);
let span = doc.createElement("span");
span.textContent = ` [${senseLabel}] ${terms.join(", ")}`;
span.setAttribute("data-wed-id", sense.id);
let radio = doc.createElement("input");
radio.type = "radio";
radio.name = "sense";
let div = doc.createElement("div");
div.appendChild(radio);
div.appendChild(span);
labels.push(div);
radios.push(radio);
const subsenses = domutil.childrenByClass(sense, "btw:subsense");
for (const subsense of subsenses) {
dataNode = $.data(subsense, "wed_mirror_node");
const subsenseLabel = decorator.refmans.getSubsenseLabel(subsense);
let child = dataNode.firstElementChild;
let explanation;
while (child) {
if (child.tagName === "btw:explanation") {
explanation = child;
break;
}
child = child.nextElementSibling;
}
span = doc.createElement("span");
span.textContent = ` [${subsenseLabel}] ${explanation.textContent}`;
span.setAttribute("data-wed-id", subsense.id);
radio = doc.createElement("input");
radio.type = "radio";
radio.name = "sense";
div = doc.createElement("div");
div.appendChild(radio);
div.appendChild(span);
labels.push(div);
radios.push(radio);
}
}
const hyperlinkModal = mode.hyperlinkModal;
const primary = hyperlinkModal.getPrimary()[0] as HTMLButtonElement;
const body = doc.createElement("div");
for (const label of labels) {
body.appendChild(label);
}
$(radios).on("click.wed", () => {
primary.disabled = false;
primary.classList.remove("disabled");
});
primary.disabled = true;
primary.classList.add("disabled");
hyperlinkModal.setBody(body);
hyperlinkModal.modal(() => {
const clicked = hyperlinkModal.getClickedAsText();
if (clicked === "Insert") {
const id = body.querySelector("input[type='radio']:checked")!
.nextElementSibling!.getAttribute("data-wed-id")!;
mode.insertPtrTr.execute({ ...data, target: id });
}
});
}