Sha256: 8f4458283a8b16c3ef8bf590b612b39bfe7106e10c70ebac80eeb2a3d3bda120

Contents?: true

Size: 1.39 KB

Versions: 5

Compression:

Stored size: 1.39 KB

Contents

# http://stackoverflow.com/questions/4176923/html-of-selected-text
# by Tim Down
window.getSelectionHtml = ->
  html = ''

  if window.getSelection != undefined
    sel = window.getSelection()

    if sel.rangeCount
      container = document.createElement('div')

      for i in [0..sel.rangeCount-1]
        container.appendChild(sel.getRangeAt(i).cloneContents())

      html = container.innerHTML

  else if document.selection != undefined

    if document.selection.type == 'Text'
      html = document.selection.createRange().htmlText

  return html

# http://stackoverflow.com/questions/1197401/how-can-i-get-the-element-the-caret-is-in-with-javascript-when-using-contentedi
# by You
window.getSelectionStart = ->
  node = document.getSelection().anchorNode
  startNode = if node and node.nodeType == 3 then node.parentNode else node
  return startNode

window.isListItemChild = (node) -> $(node).parents('li').length > 0

# http://stackoverflow.com/questions/5605401/insert-link-in-contenteditable-element
# by Tim Down
window.saveSelection = ->
  sel = window.getSelection()

  if sel.getRangeAt and sel.rangeCount
    ranges = []
    for i in [0..sel.rangeCount-1]
      ranges.push(sel.getRangeAt(i))
    return ranges

  return false

window.restoreSelection = (savedSel) ->
  sel = window.getSelection()
  if savedSel
    sel.removeAllRanges()
    for i in [0..savedSel.length-1]
      sel.addRange(savedSel[i])

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
character_editor-0.1.4 app/assets/javascripts/character_editor/_selection.coffee
character_editor-0.1.3 app/assets/javascripts/character_editor/_selection.coffee
character_editor-0.1.2 app/assets/javascripts/character_editor/_selection.coffee
character_editor-0.0.9 app/assets/javascripts/character_editor/_selection.coffee
character_editor-0.0.1 app/assets/javascripts/character_editor/_selection.coffee