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

TypeScript jQuery.data函数代码示例

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

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



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

示例1: constructor

  /**
   * @param el The element to which this object is associated.
   */
  constructor(public readonly node: ValidRoots) {
    if ($.data(node, "wed-dloc-root") != null) {
      throw new Error("node already marked as root");
    }

    $.data(node, "wed-dloc-root", this);
  }
开发者ID:lddubeau,项目名称:wed,代码行数:10,代码来源:dloc.ts


示例2: it

      it("is equivalent to nodeToPath on a data tree", () => {
        const dataRootObj = new DLocRoot(xmlDoc);

        linkTrees(xmlDoc.firstElementChild!, root.firstElementChild!);
        let targetDataNode = xmlDoc.getElementsByTagName("quote")[0];
        const phantomWrapTemplate = "<span class='_phantom_wrap'></span>";
        $($.data(targetDataNode, "wed_mirror_node"))
          .wrap(phantomWrapTemplate)
          .after("<span class='_phantom'>Boo</span>Blip")
          .wrap(phantomWrapTemplate);

        const dataNode = targetDataNode.parentNode as Element;
        // Wrap twice for good measure.
        $($.data(dataNode, "wed_mirror_node"))
          .wrap(phantomWrapTemplate)
          .wrap(phantomWrapTemplate);

        targetDataNode = xmlDoc.getElementsByTagName("quote")[1];
        const targetGuiNode = $.data(targetDataNode, "wed_mirror_node");
        const guiPath = rootObj.nodeToPath(targetGuiNode);
        const dataPath = dataRootObj.nodeToPath(targetDataNode);

        // Both paths should be equal.
        assert.equal(guiPath, dataPath);

        // It should also be reversible.
        assert.equal(rootObj.pathToNode(guiPath), targetGuiNode);
      });
开发者ID:lddubeau,项目名称:wed,代码行数:28,代码来源:guiroot-test.ts


示例3: it

 it("sets wed_mirror_node", () => {
   const root = doc.firstChild as Element;
   const cloned = root.cloneNode(true) as Element;
   domutil.linkTrees(cloned, root);
   const p = root.getElementsByTagName("p")[0];
   const clonedP = cloned.getElementsByTagName("p")[0];
   assert.equal($.data(p, "wed_mirror_node"), clonedP);
   assert.equal($.data(clonedP, "wed_mirror_node"), p);
 });
开发者ID:lddubeau,项目名称:wed,代码行数:9,代码来源:domutil-test.ts


示例4: _beforeDeleteNodeHandler

  /**
   * Handles "BeforeDeleteNode" events.
   *
   * @param ev The event.
   */
  private _beforeDeleteNodeHandler(ev: BeforeDeleteNodeEvent):
  void {
    const dataNode = ev.node;
    let toRemove;
    let element = false;
    switch (dataNode.nodeType) {
    case Node.TEXT_NODE:
      const guiCaret = this.fromDataLocation(dataNode, 0);
      if (guiCaret === null) {
        throw new Error("cannot find gui tree position");
      }
      toRemove = guiCaret.node;
      break;
    case Node.ELEMENT_NODE:
      toRemove = $.data(dataNode as Element, "wed_mirror_node");
      element = true;
      break;
    default:
    }
    this.deleteNode(toRemove);

    // We have to do this **after** we delete the node.
    if (element) {
      unlinkTree(dataNode as Element);
      unlinkTree(toRemove);
    }
  }
开发者ID:lddubeau,项目名称:wed,代码行数:32,代码来源:gui-updater.ts


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


示例6: findRoot

export function findRoot(node: Node | Attr | undefined | null):
DLocRoot | undefined {
  while (node != null) {
    if (isElement(node) || isDocument(node)) {
      const root = $.data(node, "wed-dloc-root");
      if (root != null) {
        return root;
      }
    }
    node = node.parentNode;
  }
  return undefined;
}
开发者ID:lddubeau,项目名称:wed,代码行数:13,代码来源:dloc.ts


示例7: _showHandler

function _showHandler(ev: Event): void {
  const for_ = ev.target as Element;
  const tt = $.data(for_, "bs.tooltip");
  $.data(tt.tip()[0], "wed-tooltip-for", for_);
}
开发者ID:lddubeau,项目名称:wed,代码行数:5,代码来源:tooltip.ts


示例8: validateDocument

  // tslint:disable-next-line:max-func-body-length
  validateDocument(): ErrorData[] {
    //
    // ATTENTION: The logic here must be duplicated server-side to check whether
    // an article is deemed valid. We've thought about having some sort of
    // validation done in Node.js in the server which could perhaps resuse this
    // code but the problem is that there is no lightweight solution yet.
    //
    // Changes here must be mirrored in the btw-storage-[version].sch file.
    //

    const ret: ErrorData[] = [];
    // Verify that all senses have some semantic fields associated with them.
    const senses = this.guiRoot.getElementsByClassName("btw:sense");
    // tslint:disable-next-line:prefer-for-of
    for (let i = 0; i < senses.length; ++i) {
      const sense = senses[i];
      const contrastive =
        sense.getElementsByClassName("btw:contrastive-section")[0];
      const sfs = sense.querySelectorAll(
        this.mapped.toGUISelector("btw:example btw:sf"));
      let found = false;
      // tslint:disable-next-line:prefer-for-of
      for (let sfsIx = 0; sfsIx < sfs.length; ++sfsIx) {
        const sf = sfs[sfsIx];
        // The contrastive section may not exist yet.
        if (contrastive === undefined || !contrastive.contains(sf)) {
          found = true;
          break;
        }
      }

      if (!found) {
        const dataSense = $.data(sense, "wed_mirror_node");
        ret.push({
          error: new ValidationError("sense without semantic fields"),
          node: dataSense.parentNode,
          index: _indexOf.call(dataSense.parentNode.childNodes, dataSense),
        });
      }
    }

    // Verify that all cognates have some semantic fields associated with them.
    const cognates = this.guiRoot.getElementsByClassName("btw:cognate");
    // tslint:disable-next-line:prefer-for-of
    for (let i = 0; i < cognates.length; ++i) {
      const cognate = cognates[i];
      const sfs = cognate.querySelectorAll(
        this.mapped.toGUISelector("btw:example btw:sf"));
      if (sfs.length === 0) {
        const dataCognate = $.data(cognate, "wed_mirror_node");
        ret.push({
          error: new ValidationError("cognate without semantic fields"),
          node: dataCognate.parentNode,
          index: _indexOf.call(dataCognate.parentNode.childNodes, dataCognate),
        });
      }
    }

    // Verify that all semantic fields are of the proper format.
    const allSfs = this.guiRoot.getElementsByClassName("btw:sf");
    // tslint:disable-next-line:prefer-for-of
    for (let i = 0; i < allSfs.length; ++i) {
      const sf = allSfs[i];
      const dataSf = $.data(sf, "wed_mirror_node");
      const text = dataSf.textContent;
      const parts = text.split("@");

      for (const part of parts) {
        // tslint:disable-next-line:max-line-length
        if (!/^\s*\d{2}(?:\.\d{2})*(?:\s*\|\s*\d{2}(?:\.\d{2})*)?(?:aj|av|cj|in|n|p|ph|v|vi|vm|vp|vr|vt)\s*$/.test(part)) {
          ret.push({
            error: new ValidationError(
              "semantic field is not in a recognized format"),
            node: dataSf.parentNode,
            index: _indexOf.call(dataSf.parentNode.childNodes, dataSf),
          });
        }
      }
    }

    // Verify that surnames are not empty
    const surnames = this.guiRoot.getElementsByClassName("surname");
    // tslint:disable-next-line:prefer-for-of
    for (let i = 0; i < surnames.length; ++i) {
      const surname = surnames[i];
      const dataSurname = $.data(surname, "wed_mirror_node");
      if (dataSurname.textContent.length === 0) {
        ret.push({
          error: new ValidationError("surname cannot be empty"),
          node: dataSurname,
          index: 0,
        });
      }
    }

    const btwCredits = this.guiRoot.getElementsByClassName("btw:credits")[0];
    // btw:credits can be missing on files that should be upgraded to the latest
    // version of the schema.
    if (btwCredits !== undefined) {
//.........这里部分代码省略.........
开发者ID:mangalam-research,项目名称:btw,代码行数:101,代码来源:btw-validator.ts


示例9: contextMenuHandler

  /**
   * Context menu handler for the labels of elements decorated by
   * [[Decorator.elementDecorator]].
   *
   * @param atStart Whether or not this event is for the start label.
   *
   * @param wedEv The DOM event that wed generated to trigger this handler.
   *
   * @param ev The DOM event that wed received.
   *
   * @returns To be interpreted the same way as for all DOM event handlers.
   */
  // tslint:disable-next-line:max-func-body-length
  protected contextMenuHandler(atStart: boolean, wedEv: JQueryMouseEventObject,
                               ev: JQueryEventObject): boolean {
    const editor = this.editor;
    const editingMenuManager = editor.editingMenuManager;
    let node = wedEv.target;
    const menuItems: Item[] = [];
    const mode = editor.modeTree.getMode(node);

    function pushItem(data: TransformationData | null,
                      tr: Action<TransformationData>,
                      start?: boolean): void {
      const li = editingMenuManager.makeMenuItemForAction(tr, data, start);
      menuItems.push({ action: tr, item: li, data: data });
    }

    function pushItems(data: TransformationData | null,
                       trs?: Action<{}>[], start?: boolean): void {
      if (trs === undefined) {
        return;
      }

      for (const tr of trs) {
        pushItem(data, tr, start);
      }
    }

    function processAttributeNameEvent(event: salve.Event,
                                       element: Element): void {
      const namePattern = event.params[1] as salve.Name;
      // The next if line causes tslint to inexplicably raise a failure. I am
      // able to reproduce it with something as small as:
      //
      // import { Name } from "salve";
      //
      // export function func(p: Name): void {
      //   if (p.simple()) {
      //     document.body.textContent = "1";
      //   }
      // }
      //
      // tslint:disable-next-line:strict-boolean-expressions
      if (namePattern.simple()) {
        for (const name of namePattern.toArray()) {
          const unresolved =
            mode.getAbsoluteResolver().unresolveName(name.ns, name.name);
          if (unresolved === undefined) {
            throw new Error("cannot unresolve attribute");
          }

          if (editor.isAttrProtected(unresolved, element)) {
            return;
          }

          pushItems({ name: unresolved, node: element },
                    mode.getContextualActions("add-attribute", unresolved,
                                              element));
        }
      }
      else {
        pushItem(null, editor.complexPatternAction);
      }
    }

    const real = closestByClass(node, "_real", editor.guiRoot);
    const readonly = real !== null && real.classList.contains("_readonly");

    const attrVal = closestByClass(node, "_attribute_value", editor.guiRoot);
    if (attrVal !== null) {
      const dataNode = editor.toDataNode(attrVal) as Attr;
      const treeCaret =
        DLoc.mustMakeDLoc(editor.dataRoot, dataNode.ownerElement);
      const toAddTo = treeCaret.node.childNodes[treeCaret.offset];
      editor.validator.possibleAt(treeCaret, true).forEach((event) => {
        if (event.params[0] !== "attributeName") {
          return;
        }
        processAttributeNameEvent(event, toAddTo as Element);
      });

      const name = dataNode.name;
      if (!editor.isAttrProtected(dataNode)) {
        pushItems({ name: name, node: dataNode },
                  mode.getContextualActions("delete-attribute", name,
                                            dataNode));
      }
    }
    else {
//.........这里部分代码省略.........
开发者ID:lddubeau,项目名称:wed,代码行数:101,代码来源:decorator.ts


示例10: elementDecorator

  elementDecorator(_root: Element, el: Element, level: number,
                   preContextHandler: ((wedEv: JQueryMouseEventObject,
                                        ev: Event) => boolean) | undefined,
                   postContextHandler: ((wedEv: JQueryMouseEventObject,
                                         ev: Event) => boolean) | undefined):
  void {
    if (this.editor.modeTree.getMode(el) !== this.mode) {
      // The element is not governed by this mode.
      return;
    }

    if (level > this.editor.maxLabelLevel) {
      throw new Error(
        `level higher than the maximum set by the mode: ${level}`);
    }

    // Save the caret because the decoration may mess up the GUI caret.
    let dataCaret: DLoc | undefined = this.editor.caretManager.getDataCaret();
    if (dataCaret != null &&
        !(isAttr(dataCaret.node) &&
          dataCaret.node.ownerElement === $.data(el, "wed_mirror_node"))) {
      dataCaret = undefined;
    }

    const dataNode = $.data(el, "wed_mirror_node");
    this.setReadOnly(el, Boolean(this.editor.validator.getNodeProperty(
      dataNode, "PossibleDueToWildcard")));

    const origName = util.getOriginalName(el);
    // _[name]_label is used locally to make the function idempotent.
    let cls = `_${origName}_label`;

    // We must grab a list of nodes to remove before we start removing them
    // because an element that has a placeholder in it is going to lose the
    // placeholder while we are modifying it. This could throw off the scan.
    const toRemove = domutil.childrenByClass(el, cls);
    for (const remove of toRemove) {
      el.removeChild(remove);
    }

    let attributesHTML = "";
    let hiddenAttributes = false;
    const attributeHandling = this.editor.modeTree.getAttributeHandling(el);
    if (attributeHandling === "show" || attributeHandling === "edit") {
      // include the attributes
      const attributes = util.getOriginalAttributes(el);
      const names = Object.keys(attributes).sort();

      for (const name of names) {
        const hideAttribute = this.mustHideAttribute(el, name);
        if (hideAttribute) {
          hiddenAttributes = true;
        }

        const extra = hideAttribute ? " _shown_when_caret_in_label" : "";

        attributesHTML += ` \
<span class="_phantom _attribute${extra}">\
<span class="_phantom _attribute_name">${name}</span>=\
"<span class="_phantom _attribute_value">\
${domutil.textToHTML(attributes[name])}</span>"</span>`;
      }
    }

    const doc = el.ownerDocument;
    cls += ` _label_level_${level}`;

    // Save the cls of the end label here so that we don't further modify it.
    const endCls = cls;

    if (hiddenAttributes) {
      cls += " _autohidden_attributes";
    }
    const pre = doc.createElement("span");
    pre.className = `_gui _phantom __start_label _start_wrapper ${cls} _label`;
    const prePh = doc.createElement("span");
    prePh.className = "_phantom";
    // tslint:disable-next-line:no-inner-html
    prePh.innerHTML = `&nbsp;<span class='_phantom _element_name'>${origName}\
</span>${attributesHTML}<span class='_phantom _greater_than'> >&nbsp;</span>`;
    pre.appendChild(prePh);
    this.guiUpdater.insertNodeAt(el, 0, pre);

    const post = doc.createElement("span");
    post.className = `_gui _phantom __end_label _end_wrapper ${endCls} _label`;
    const postPh = doc.createElement("span");
    postPh.className = "_phantom";
    // tslint:disable-next-line:no-inner-html
    postPh.innerHTML = `<span class='_phantom _less_than'>&nbsp;&lt; </span>\
<span class='_phantom _element_name'>${origName}</span>&nbsp;`;
    post.appendChild(postPh);
    this.guiUpdater.insertBefore(el, post, null);

    // Setup a handler so that clicking one label highlights it and the other
    // label.
    $(pre).on("wed-context-menu",
              preContextHandler !== undefined ? preContextHandler : false);

    $(post).on("wed-context-menu",
               postContextHandler !== undefined ? postContextHandler : false);
//.........这里部分代码省略.........
开发者ID:lddubeau,项目名称:wed,代码行数:101,代码来源:decorator.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript jQuery.default函数代码示例发布时间:2022-05-25
下一篇:
TypeScript jQuery.ajax函数代码示例发布时间: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