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


TypeScript component-closest.default函数代码示例

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


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

示例1: execute

  execute(range?: Range, value?: any): void {
    var r = range || currentRange(this.document);
    var li = closest(r.commonAncestorContainer, 'li', true);

    if (li) {
      // we're inside a LI element
      var h = li.querySelector(this.nodeName);
      if (h) {
        // unwrap the H node
        unwrap(h);
      } else {
        // create an H node, wrap the LI contents with it
        h = this.document.createElement(this.nodeName);
        while (li.firstChild) {
          h.appendChild(li.firstChild);
        }
        li.appendChild(h);
      }
    } else {
      if (this.queryState(r)) {
        super.execute(range, '<p>');
      } else {
        super.execute(range, this.tag);
      }
    }
  }
开发者ID:webmodules,项目名称:header-command,代码行数:26,代码来源:index.ts

示例2: queryState

  queryState(range?: Range): boolean {
    if (!range) range = currentRange(this.document);
    if (!range) return false;

    var next: Node = range.startContainer;
    var end: Node = range.endContainer;
    var iterator = domIterator(next).revisit(false);

    while (next) {
      var node: Node = closest(next, 'a', true);
      if (!node) return false;
      if (contains(end, next)) break;
      next = iterator.next(3 /* Node.TEXT_NODE */);
    }

    return true;
  }
开发者ID:webmodules,项目名称:link-command,代码行数:17,代码来源:index.ts

示例3: execute

  execute(range?: Range, value?: any): void {
    var isSel: boolean = false;
    var backward: boolean;
    var selection: Selection;

    var sel: Selection = currentSelection(this.document);
    if (null != range && !(range instanceof Range)) {
      value = range;
      range = null;
    }
    if (!range) {
      backward = isBackward(sel);
      range = currentRange(this.document);
      isSel = true;
    }
    if (!range) return;
    var command: Command;

    if (this.queryState(range)) {
      command = this.unlink;
      value = null;

      if (range.collapsed) {
        // no selection, so manually traverse up the DOM and find the A node
        var a: Node = closest(range.commonAncestorContainer, 'a', true);
        if (a) {
          debug('selecting A node contents %o', a);
          range.selectNodeContents(a);
        }
      }

    } else {
      command = this.createLink;
      if (!value) value = this.href;

      if (range.collapsed) {
        debug('finding surrounding word at caret for collapsed Range');
        // upon a collapsed Range, we want to find the surrounding "word" that
        // the cursor is touching, and then augment the Range to surround the word
        var wordRange: Range = wordAtCaret(range.endContainer, range.endOffset);
        if (wordRange) {
          debug('found surrounding word: %o', wordRange.toString());
          copyRange(range, wordRange);
        } else {
          debug('no surrounding word, inserting text "Link"');
          var text = this.document.createTextNode('Link');
          insertNode(range, text);
          range.setStart(text, 0);
          range.setEnd(text, 4);
        }
      }

    }

    if (isSel) {
      // if no Range was explicitly passed in, then augment the current Selection
      // in the case that we modified the range (collapsd), so that native
      // browser selection works out properly after the command is executed.
      setRange(sel, range, backward);
      range = null;
    }

    command.execute(range, value);
  }
开发者ID:webmodules,项目名称:link-command,代码行数:64,代码来源:index.ts

示例4: queryState

 queryState(range?: Range): boolean {
   if (!range) range = currentRange(this.document);
   if (!range) return false;
   var node = closest(range.commonAncestorContainer, this.nodeName, true);
   return !! node;
 }
开发者ID:webmodules,项目名称:header-command,代码行数:6,代码来源:index.ts


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