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

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

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

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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