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


TypeScript current-range.default函数代码示例

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


在下文中一共展示了default函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 hasRange: boolean = !!(range && range instanceof Range);
    var backward: boolean;
    var selection: Selection;

    if (!hasRange) {
      selection = currentSelection(this.document);
      backward = isBackward(selection);
      range = currentRange(selection);
    }

    if (this.queryState(range)) {
      unwrapRange(range, this.nodeName, this.document);
    } else {
      wrapRange(range, this.nodeName, this.document);
    }

    if (!hasRange) {
      // when no Range was passed in then we must reset the document's Selection
      setRange(selection, range, backward);
    }
  }
开发者ID:retrofox,项目名称:wrap-command,代码行数:22,代码来源:index.ts

示例4: queryEnabled

  queryEnabled(range?: Range): boolean {
    var current = range || currentRange(this.document);
    if (!current) return false;

    // WebKit seems to return `false` when a collapsed Range is used for "unlink".
    // This makes sense because unlink on an empty selection doesn't actually
    // work, however, we're using `wordAtCaret` above to ensure that there is
    // at least some selection. So always return `true` in this case.
    //
    // Opera seems to do the same thing, but for "createLink" instead.
    // This also makes sense, however we attempt to find the nearest A node when
    // collapsed and remove the entire thing. So also return `true` there as well.
    if (current.collapsed) {
      return true;
    } else {
      // When there's an actual selection, we can rely on the native "unlink"
      // and "createLink" command's `queryEnabled()` implementations.
      // Note that we're passing in the `range` argument that was passed in,
      // rather than the `current` Range, so that falsey values still fall through
      var command: Command = this.queryState(range) ? this.unlink : this.createLink;
      return command.queryEnabled(range);
    }
  }
开发者ID:webmodules,项目名称:link-command,代码行数:23,代码来源:index.ts

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

示例6: queryEnabled

 queryEnabled(range?: Range): boolean {
   if (!range) range = currentRange(this.document);
   return !! range;
 }
开发者ID:retrofox,项目名称:wrap-command,代码行数:4,代码来源:index.ts

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


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