How to use the ssr-window.window.getSelection function in ssr-window

To help you get started, we’ve selected a few ssr-window examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github capricorncd / zx-editor / src / js / range.js View on Github external
getRange () {
    // 获取选定对象
    this.selection = window.getSelection()
    // 设置最后光标对象
    this.$el = this.selection.getRangeAt(0)
    // console.log('selection.getRangeAt(0)', selection.getRangeAt(0))
    this.offset = this.$el.startOffset
    // 当前Node
    let currentNode = this.$el.endContainer
    // 获取光标所在元素的父级为this.$content.children
    return dom.closest(currentNode, this.$content)
  }
}
github framework7io / framework7 / src / core / components / text-editor / text-editor-class.js View on Github external
onButtonClick(e) {
    const self = this;
    const selection = window.getSelection();
    const selectionIsInContent = $(selection.anchorNode).parents(self.contentEl).length || selection.anchorNode === self.contentEl;
    if (!selectionIsInContent) return;
    const $buttonEl = $(e.target).closest('button');
    if ($buttonEl.parents('form').length) {
      e.preventDefault();
    }
    const button = $buttonEl.attr('data-button');
    const buttonData = self.params.customButtons && self.params.customButtons[button];
    if (!button || !(textEditorButtonsMap[button] || buttonData)) return;
    $buttonEl.trigger('texteditor:buttonclick', button);
    self.emit('local::buttonClick textEditorButtonClick', self, button);
    if (buttonData) {
      if (buttonData.onClick) buttonData.onClick();
      return;
    }
    const command = textEditorButtonsMap[button][2];
github framework7io / framework7 / src / core / components / text-editor / text-editor-class.js View on Github external
onBlur() {
    const self = this;
    if (self.params.placeholder && self.$contentEl.html() === '') {
      self.insertPlaceholder();
    }
    if (self.params.mode === 'popover') {
      const selection = window.getSelection();
      const selectionIsInContent = $(selection.anchorNode).parents(self.contentEl).length || selection.anchorNode === self.contentEl;
      const inPopover = document.activeElement && self.popover && $(document.activeElement).closest(self.popover.$el).length;
      if (!inPopover && !selectionIsInContent) {
        self.closePopover();
      }
    }
    if (self.params.mode === 'keyboard-toolbar') {
      const selection = window.getSelection();
      const selectionIsInContent = $(selection.anchorNode).parents(self.contentEl).length || selection.anchorNode === self.contentEl;
      if (!selectionIsInContent) {
        self.closeKeyboardToolbar();
      }
    }
    self.$el.trigger('texteditor:blur');
    self.emit('local::blur textEditorBlur', self);
  }
github framework7io / framework7 / src / core / components / text-editor / text-editor-class.js View on Github external
createLink() {
    const self = this;
    const currentSelection = window.getSelection();
    const selectedNodes = [];
    let $selectedLinks;
    if (currentSelection && currentSelection.anchorNode && $(currentSelection.anchorNode).parents(self.$el).length) {
      let anchorNode = currentSelection.anchorNode;
      while (anchorNode) {
        selectedNodes.push(anchorNode);
        if (!anchorNode.nextSibling || anchorNode === currentSelection.focusNode) {
          anchorNode = null;
        }
        if (anchorNode) {
          anchorNode = anchorNode.nextSibling;
        }
      }
      $selectedLinks = $(selectedNodes).closest('a').add($(selectedNodes).children('a'));
    }
    if ($selectedLinks && $selectedLinks.length) {
github capricorncd / zx-editor / src / js / range.js View on Github external
init (offset) {
    this.selection = window.getSelection()
    try {
      this.$el = this.selection.getRangeAt(0)
    } catch (e) {
      this.$el = new Range()
    }
    this.offset = util.int(offset)
  }
github capricorncd / zx-editor / src / js / cursor.js View on Github external
init () {
    this.selection = window.getSelection()
    try {
      this.range = this.selection.getRangeAt(0)
    } catch (e) {
      this.range = new Range()
    }
    this.offset = 0
  }
github framework7io / framework7 / src / core / components / text-editor / text-editor-class.js View on Github external
onSelectionChange() {
    const self = this;
    if (self.params.mode === 'toolbar') return;
    const selection = window.getSelection();
    const selectionIsInContent = $(selection.anchorNode).parents(self.contentEl).length || selection.anchorNode === self.contentEl;
    if (self.params.mode === 'keyboard-toolbar') {
      if (!selectionIsInContent) {
        self.closeKeyboardToolbar();
      } else {
        self.openKeyboardToolbar();
      }
      return;
    }
    if (self.params.mode === 'popover') {
      const selectionIsInPopover = $(selection.anchorNode).parents(self.popover.el).length || selection.anchorNode === self.popover.el;
      if (!selectionIsInContent && !selectionIsInPopover) {
        self.closePopover();
        return;
      }
      if (!selection.isCollapsed && selection.rangeCount) {
github framework7io / framework7 / packages / core / modules / touch / touch.js View on Github external
tapHoldTimeout = setTimeout(() => {
        if (e && e.touches && e.touches.length > 1) return;
        tapHoldFired = true;
        e.preventDefault();
        $(e.target).trigger('taphold');
      }, params.tapHoldDelay);
    }
    if (needsFastClickTimeOut) clearTimeout(needsFastClickTimeOut);
    needsFastClick = targetNeedsFastClick(e.target);

    if (!needsFastClick) {
      trackClick = false;
      return true;
    }
    if (Device.ios || (Device.android && 'getSelection' in window)) {
      const selection = window.getSelection();
      if (
        selection.rangeCount
        && selection.focusNode !== document.body
        && (!selection.isCollapsed || document.activeElement === selection.focusNode)
      ) {
        activeSelection = true;
        return true;
      }

      activeSelection = false;
    }
    if (Device.android) {
      if (androidNeedsBlur(e.target)) {
        document.activeElement.blur();
      }
    }