• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript wed.util类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中wed.util的典型用法代码示例。如果您正苦于以下问题:TypeScript util类的具体用法?TypeScript util怎么用?TypeScript util使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了util类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: addHandlers

  addHandlers(): void {
    this.domlistener.addHandler(
      "included-element",
      util.classFromOriginalName("*", {}),
      (root: Node, _tree: Node, _parent: Node, _prev: Node | null,
       _next: Node | null, el: Element) => {
         // Skip elements which would already have been removed from the
         // tree. Unlikely but...
         if (!root.contains(el)) {
           return;
         }

         this.elementDecorator(root as Element, el);

         const klass = this.getAdditionalClasses(el);
         if (klass.length > 0) {
           el.className += ` ${klass}`;
         }
       });

    this.domlistener.addHandler(
      "children-changed",
      util.classFromOriginalName("*", {}),
      (root: Node, added: Node[], removed: Node[],
       _previousSibling: Node | null, _nextSibling: Node | null,
       el: Element) => {
         for (const child of added.concat(removed)) {
           if (isText(child) || (isElement(child) &&
                                 (child.classList.contains("_real") ||
                                  child.classList.contains("_phantom_wrap")))) {
             this.elementDecorator(root as Element, el);
             break;
           }
         }
       });

    this.domlistener.addHandler("text-changed",
                                util.classFromOriginalName("*", {}),
                                (root: Node, node: Text) => {
                                  this.elementDecorator(
                                    root as Element,
                                    node.parentNode! as Element);
                                });

    this.domlistener.addHandler("attribute-changed",
                                util.classFromOriginalName("*", {}),
                                (root: Node, el: Element) => {
                                  this.elementDecorator(root as Element, el);
                                });
  }
开发者ID:lddubeau,项目名称:wed,代码行数:50,代码来源:generic-decorator.ts


示例2:

    mode.getBibliographicalInfo().then((info: BibliographicalInfo) => {
      const allValues: BibliographicalItem[] = [];
      for (const key of Object.keys(info)) {
        allValues.push(info[key]);
      }

      const citedValues: BibliographicalItem[] = [];
      const refs = editor.guiRoot.querySelectorAll("._real.ref");
      // tslint:disable-next-line:prefer-for-of
      for (let refIx = 0; refIx < refs.length; ++refIx) {
        const ref = refs[refIx];
        const origTarget = ref.getAttribute(util.encodeAttrName("target"))!;
        if (origTarget.lastIndexOf("/bibliography/", 0) !== 0) {
          continue;
        }

        citedValues.push(info[origTarget]);
      }

      zoteroEngine.add(allValues);
      citedEngine.add(citedValues);
      if (range !== undefined) {
        ta.setValue(range.toString());
      }
      ta.hideSpinner();
    });
开发者ID:mangalam-research,项目名称:btw,代码行数:26,代码来源:btw-actions.ts


示例3: insertPtr

export function insertPtr(editor: EditorAPI,
                          data: TargetedTransformationData): void {
  const caret = editor.caretManager.getDataCaret()!;
  let parent = caret.node;
  const index = caret.offset;

  // The data.target value is the wed ID target of the ptr. We must find this
  // element and add a data ID.
  const target = editor.guiRoot.ownerDocument.getElementById(data.target)!;
  const dataId = data.target.slice(4);
  target.setAttribute(util.encodeAttrName("xml:id"), dataId);
  $.data(target, "wed_mirror_node").setAttributeNS(
    // tslint:disable-next-line:no-http-string
    "http://www.w3.org/XML/1998/namespace", "xml:id", dataId);

  const mode = editor.modeTree.getMode(parent);
  const ename = mode.getAbsoluteResolver().resolveName("ptr")!;

  const ptr = makeElement(parent.ownerDocument,
                          ename.ns, "ptr", { target: `#${dataId}` });
  editor.dataUpdater.insertAt(parent, index, ptr);

  // The original parent and index information are no necessarily representative
  // because insertAt can do quite a lot of things to insert the node.
  parent = ptr.parentNode!;
  editor.caretManager.setCaret(parent, _indexOf.call(parent.childNodes, ptr));
}
开发者ID:mangalam-research,项目名称:btw,代码行数:27,代码来源:btw-tr.ts


示例4: citDecorator

  citDecorator(root: Element, el: Element): void {
    this.elementDecorator(root, el);

    let ref;
    let child = el.firstElementChild;
    while (child !== null) {
      const next = child.nextElementSibling;
      if (child.classList.contains("_ref_space") ||
          child.classList.contains("_cit_bullet")) {
        this.guiUpdater.removeNode(child);
      }
      else if (child.classList.contains("ref")) {
        ref = child;
      }
      child = next;
    }

    if (ref) {
      const space = el.ownerDocument.createElement("div");
      space.className = "_text _phantom _ref_space";
      space.textContent = " ";
      el.insertBefore(space, ref.nextSibling);
    }

    if (el.querySelector(`*[${util.encodeAttrName("xml:lang")}='pi-Latn']`) !==
       null) {
      const div = el.ownerDocument.createElement("div");
      div.className = "_phantom _text _cit_bullet";
      div.style.position = "absolute";
      div.style.left = "-1em";
      div.textContent = WHEEL;
      this.guiUpdater.insertNodeAt(el, 0, div);
      (el as HTMLElement).style.position = "relative";
    }
  }
开发者ID:mangalam-research,项目名称:btw,代码行数:35,代码来源:btw-dispatch.ts


示例5: idDecorator

  idDecorator(_root: Element, el: Element): void {
    const refman = this.refmans.getRefmanForElement(el);
    if (refman !== null) {
      let wedId = el.id;
      if (wedId === "") {
        const id = el.getAttribute(util.encodeAttrName("xml:id"));
        const idMan = this._getIDManagerForRefman(refman);
        wedId = `BTW-${id !== null ? id : idMan.generate()}`;
        el.id = wedId;
      }

      // We have some reference managers that don't derive from ReferenceManager
      // and thus do not have this method.
      if (refman instanceof LabelManager) {
        refman.allocateLabel(wedId);
      }
    }
  }
开发者ID:mangalam-research,项目名称:btw,代码行数:18,代码来源:btw-dispatch.ts


示例6: 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 });
      }
    });
  }
开发者ID:mangalam-research,项目名称:btw,代码行数:100,代码来源:btw-actions.ts


示例7: classFromOriginalName

 classFromOriginalName(name: string): string {
   return util.classFromOriginalName(name, this.mapping);
 }
开发者ID:mangalam-research,项目名称:btw,代码行数:3,代码来源:mapped-util.ts


示例8: dispatch

  protected dispatch(root: Element, el: Element): void {
    const klass = this.getAdditionalClasses(el);
    if (klass.length !== 0) {
      el.className += ` ${klass}`;
    }

    const name = util.getOriginalName(el);
    let skipDefault = false;
    switch (name) {
    case "btw:overview":
    case "btw:sense-discrimination":
    case "btw:historico-semantical-data":
    case "btw:credits":
      this.headingDecorator.unitHeadingDecorator(el);
      break;
    case "btw:definition":
    case "btw:english-renditions":
    case "btw:english-rendition":
    case "btw:etymology":
    case "btw:contrastive-section":
    case "btw:antonyms":
    case "btw:cognates":
    case "btw:conceptual-proximates":
    case "btw:other-citations":
    case "btw:citations":
      this.headingDecorator.sectionHeadingDecorator(el);
      break;
    case "btw:semantic-fields":
      this.headingDecorator.sectionHeadingDecorator(el);
      break;
    case "btw:sf":
      this.sfDecorator(root, el);
      skipDefault = true;
      break;
    case "ptr":
      this.ptrDecorator(root, el);
      break;
    case "foreign":
      this.languageDecorator(el);
      break;
    case "ref":
      this.refDecorator(root, el);
      break;
    case "btw:example":
      this.idDecorator(root, el);
      break;
    case "btw:cit":
      this.citDecorator(root, el);
      skipDefault = true; // citDecorator calls elementDecorator
      break;
    case "btw:explanation":
      this.explanationDecorator(root, el);
      skipDefault = true; // explanationDecorator calls elementDecorator
      break;
    case "btw:none":
      this.noneDecorator(el);
      // THIS ELEMENT DOES NOT GET THE REGULAR DECORATION.
      skipDefault = true;
      break;
    default:
      break;
    }

    if (!skipDefault) {
      this.elementDecorator(root, el);
    }
  }
开发者ID:mangalam-research,项目名称:btw,代码行数:67,代码来源:btw-dispatch.ts


示例9: linkingDecorator

  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
  linkingDecorator(root: Element, el: Element, isPtr: boolean): void {
    let origTarget = el.getAttribute(util.encodeAttrName("target"));
    // XXX This should become an error one day. The only reason we need this now
    // is that some of the early test files had <ref> elements without targets.
    if (origTarget === null) {
      origTarget = "";
    }

    origTarget = origTarget.trim();

    const doc = root.ownerDocument;
    if (origTarget.lastIndexOf("#", 0) === 0) {
      // Internal target
      // Add BTW in front because we want the target used by wed.
      const targetId = origTarget.replace(/#(.*)$/, "#BTW-$1");

      const text = doc.createElement("div");
      text.className = "_text _phantom _linking_deco";
      const a = doc.createElement("a");
      a.className = "_phantom";
      a.setAttribute("href", targetId);
      text.appendChild(a);
      if (isPtr) {
        // _linking_deco is used locally to make this function idempotent
        {
          let child = el.firstElementChild;
          while (child !== null) {
            const next = child.nextElementSibling;
            if (child.classList.contains("_linking_deco")) {
              this.guiUpdater.removeNode(child);
              break; // There is only one.
            }
            child = next;
          }
        }

        const refman = this.refmans.getRefmanForElement(el);

        // Find the referred element. Slice to drop the #.
        let target = doc.getElementById(targetId.slice(1));

        // An undefined or null refman can happen when first decorating the
        // document.
        let label;
        if (refman !== null) {
          if (refman instanceof LabelManager) {
            if (refman.name === "sense" || refman.name === "subsense") {
              label = refman.idToLabel(targetId.slice(1));
              label = label !== undefined ? `[${label}]` : undefined;
            }
          }
          else {
            // An empty target can happen when first decorating the document.
            if (target !== null) {
              label = refman.getPositionalLabel(
                this.editor.toDataNode(el) as Element,
                this.editor.toDataNode(target) as Element);
            }
          }
        }

        if (label === undefined) {
          label = targetId;
        }

        a.textContent = label;

        // A ptr contains only attributes, no text, so we can just append.
        const pair = this.mode.nodesAroundEditableContents(el);
        this.guiUpdater.insertBefore(el, text, pair[1]);

        if (target !== null) {
          const targetName = util.getOriginalName(target);

          // Reduce the target to something sensible for tooltip text.
          if (targetName === "btw:sense") {
            const terms = target.querySelectorAll(this.mapped.toGUISelector(
              this.senseTooltipSelector));
            let html = "";
            for (let i = 0; i < terms.length; ++i) {
              const term = terms[i];
              html += term.innerHTML;
              if (i < terms.length - 1) {
                html += ", ";
              }
            }
            target = target.ownerDocument.createElement("div");
            // tslint:disable-next-line:no-inner-html
            target.innerHTML = html;
          }
          else if (targetName === "btw:subsense") {
            let child = target.firstElementChild;
            while (child !== null) {
              if (child.classList.contains("btw:explanation")) {
                target = child.cloneNode(true) as HTMLElement;
                break;
              }
              child = child.nextElementSibling;
            }
//.........这里部分代码省略.........
开发者ID:mangalam-research,项目名称:btw,代码行数:101,代码来源:btw-dispatch.ts



注:本文中的wed.util类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript caret-manager.CaretManager类代码示例发布时间:2022-05-25
下一篇:
TypeScript wed.domutil类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap