當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。