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


TypeScript util.encodeAttrName方法代码示例

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


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

示例1: 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

示例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: 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

示例4: 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

示例5: 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

示例6: explanationDecorator

  explanationDecorator(root: Element, el: Element): void {
    let child;
    let next;
    let div; // Damn hoisting...
    // Handle explanations that are in btw:example-explained.
    if ((el.parentNode as Element).classList
        .contains("btw:example-explained")) {
      child = el.firstElementChild;
      while (child) {
        next = child.nextElementSibling;
        if (child.classList.contains("_explanation_bullet")) {
          this.guiUpdater.removeNode(child);
          break; // There's only one.
        }
        child = next;
      }

      const cit = domutil.siblingByClass(el, "btw:cit");
      // If the next btw:cit element contains Pāli text.
      if (cit !== null &&
          cit.querySelector(
            `*[${util.encodeAttrName("xml:lang")}='pi-Latn']`) !== null) {
        div = el.ownerDocument.createElement("div");
        div.className = "_phantom _decoration_text _explanation_bullet";
        div.style.position = "absolute";
        div.style.left = "-1em";
        div.textContent = WHEEL;
        this.guiUpdater.insertNodeAt(el, 0, div);
        (el as HTMLElement).style.position = "relative";
      }
      this.elementDecorator(root, el);
      return;
    }

    this.elementDecorator(root, el);
    let label;
    const parent = el.parentNode as Element;
    // Is it in a subsense?
    if (parent.classList.contains("btw:subsense")) {
      const refman = this.refmans.getSubsenseRefman(el)!;
      label = refman.idToSublabel(parent.id);
      child = el.firstElementChild;
      let start;
      while (child) {
        next = child.nextElementSibling;
        if (child.classList.contains("_explanation_number")) {
          this.guiUpdater.removeNode(child);
        }
        else if (child.classList.contains("__start_label")) {
          start = child;
        }
        child = next;
      }

      // We want to insert it after the start label.
      div = el.ownerDocument.createElement("div");
      div.className = "_phantom _decoration_text _explanation_number " +
        "_start_wrapper'";
      div.textContent = `${label}. `;
      this.guiUpdater.insertBefore(el, div,
                                     start ? start.nextSibling : el.firstChild);
    }

    this.headingDecorator.sectionHeadingDecorator(el);
  }
开发者ID:mangalam-research,项目名称:btw,代码行数:65,代码来源:btw-dispatch.ts

示例7: tooltip

  const creators = data.creators;
  let firstCreator = "***ITEM HAS NO CREATORS***";
  if (creators != null && creators !== "") {
    firstCreator = creators.split(",")[0];
  }

  let title = `${firstCreator}, ${data.title}`;
  const date = data.date;
  if (date != null && date !== "") {
    title += `, ${date}`;
  }

  tooltip($el, { title: title, container: "body", trigger: "hover" });
}

const ENCODED_REF_ATTR_NAME = util.encodeAttrName("ref");

export interface DispatchEditor {
  toDataNode(node: Node): Node;
}

export interface DispatchMode {
  nodesAroundEditableContents(element: Element): [Node | null, Node | null];
  getBibliographicalInfo(): Promise<BibliographicalInfo>;
}

/**
 * This mixin is made to be used by the [[Decorator]] created for BTW's mode and
 * by [["btw_viewer".Viewer]]. It combines decoration methods that are common to
 * editing and viewing articles. If suitable, classes may use this class as a
 * base class instead of as a mixin.
开发者ID:mangalam-research,项目名称:btw,代码行数:31,代码来源:btw-dispatch.ts


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