当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript domutil.dataFindAll方法代码示例

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


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

示例1: execute

  execute(data: {}): void {
    const editor = this.editor;
    const dataCaret = editor.caretManager.getDataCaret(true)!;
    const guiCaret = editor.caretManager.fromDataLocation(dataCaret)!;
    const guiSfsContainer =
      domutil.closestByClass(guiCaret.node, "btw:semantic-fields",
                             editor.guiRoot);
    if (guiSfsContainer === null) {
      throw new Error("unable to acquire btw:semantic-fields");
    }

    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 fetcher = decorator.sfFetcher;

    const sfsContainer = editor.toDataNode(guiSfsContainer) as Element;
    const sfs = domutil.dataFindAll(sfsContainer, "btw:sf",
                                    mode.getAbsoluteNamespaceMappings());

    const paths = sfs.map((sf) => sf.textContent!);

    const modal = getEditSemanticFieldModal(editor);

    const fieldToPath = (f) => f.get("path");

    let sfEditor;
    const primary = modal.getPrimary()[0];
    primary.classList.add("disabled");
    modal.setBody("<i class='fa fa-spinner fa-2x fa-spin'></i>");

    const $modalTop = modal.getTopLevel();
    const body =
      $modalTop[0].getElementsByClassName("modal-body")[0] as HTMLElement;
    const content =
      $modalTop[0].getElementsByClassName("modal-content")[0] as HTMLElement;
    const header = $modalTop[0].getElementsByClassName("modal-header")[0];
    const footer = $modalTop[0].getElementsByClassName("modal-footer")[0];

    $modalTop.on("shown.bs.modal.modal", () => {
      // Once we have shown the modal we set its height to the max-height so
      // that the children of the body can use height percentages.
      content.style.height = content.style.maxHeight;
      const contentHeight = content.getBoundingClientRect().height;
      body.style.height =
        `${contentHeight - header.getBoundingClientRect().height -
footer.getBoundingClientRect().height}px`;
    });

    modal.modal(() => {
      const clicked = modal.getClickedAsText();
      if (clicked === "Commit") {
        if (!sfEditor) {
          throw new Error("modal dismissed with primary button " +
                          "while sfEditor is non-existent");
        }

        mode.replaceSemanticFields.execute(
          { newPaths: sfEditor.getChosenFields().map(fieldToPath) });
      }
    });

    fetcher.fetch(paths).then((resolved) => {
      const fields = _.values(resolved);

      // We grab the list of paths from the resolved fields because initially we
      // may have unknown fields, and the list of resolve fields may be shorter
      // than ``paths``.
      // Reminder: fields are plain old JS objects.
      const initialPaths = fields.map((x) => x.path);

      // Clear it before the editor is started.
      modal.setBody("");
      sfEditor = new SFEditor({
        container: body,
        fields: fields,
        fetcher: fetcher,
        searchUrl: mode.semanticFieldFetchUrl,
      });
      sfEditor.start();

      sfEditor.on("sf:chosen:change", () => {
        const newPaths = sfEditor.getChosenFields().map(fieldToPath);
        const method = _.isEqual(initialPaths, newPaths) ? "add" : "remove";
        primary.classList[method]("disabled");
      });
    });
  }
开发者ID:mangalam-research,项目名称:btw,代码行数:95,代码来源:btw-actions.ts

示例2: dataFindAll

 dataFindAll(el: Element, selector: string): Element[] {
   return domutil.dataFindAll(el, selector, this.mapping);
 }
开发者ID:mangalam-research,项目名称:btw,代码行数:3,代码来源:mapped-util.ts


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