File: spec_helper.coffee

package info (click to toggle)
jquery-at.js 1.5.4%2Bdfsg.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 312 kB
  • sloc: makefile: 72
file content (41 lines) | stat: -rw-r--r-- 1,035 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$ = jQuery

@KEY_CODE =
  DOWN: 40
  UP: 38
  ESC: 27
  TAB: 9
  ENTER: 13
  CTRL: 17
  P: 80
  N: 78

@fixtures or= loadJSONFixtures("data.json")["data.json"]

@triggerAtwhoAt = ($inputor) ->
  simulateTypingIn $inputor
  simulateChoose $inputor

@simulateTypingIn = ($inputor, flag, pos=31) ->
  $inputor.data("atwho").setContextFor flag || "@"
  oDocument = $inputor[0].ownerDocument
  oWindow = oDocument.defaultView || oDocument.parentWindow
  if $inputor.attr('contentEditable') == 'true' && oWindow.getSelection
    $inputor.focus()
    sel = oWindow.getSelection()
    range = oDocument.createRange()
    range.setStart $inputor.contents().get(0), pos
    range.setEnd $inputor.contents().get(0), pos
    range.collapse false
    sel.removeAllRanges()
    sel.addRange(range)
  else
    $inputor.caret('pos', pos)
  $inputor.trigger("keyup")

@simulateChoose = ($inputor) ->
  e = $.Event("keydown", keyCode: KEY_CODE.ENTER)
  $inputor.trigger(e)

@getAppOf = ($inputor, at = "@") ->
  $inputor.data('atwho').setContextFor(at)