eligo-rails 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eligo (0.0.1)
4
+ eligo-rails (0.0.3)
5
5
  jquery-rails (~> 1.0)
6
6
  railties (~> 3.1.0)
7
7
 
@@ -79,6 +79,6 @@ PLATFORMS
79
79
  ruby
80
80
 
81
81
  DEPENDENCIES
82
- eligo!
82
+ eligo-rails!
83
83
  jasmine-headless-webkit (~> 0.8.4)
84
84
  jasmine-spec-extras (~> 0.0.2)
data/README.md ADDED
@@ -0,0 +1 @@
1
+ [![Build Status](https://secure.travis-ci.org/lmarburger/eligo-rails.png)](http://travis-ci.org/lmarburger/eligo-rails)
data/Rakefile CHANGED
@@ -45,15 +45,17 @@ end
45
45
 
46
46
 
47
47
  begin
48
- require 'jasmine'
49
- load 'jasmine/tasks/jasmine.rake'
48
+ require 'jasmine-headless-webkit'
49
+ Jasmine::Headless::Task.new
50
50
  rescue LoadError
51
- task :jasmine do
52
- abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
51
+ task :jasmine-headless do
52
+ abort "jasmine-headless-webkit is not available. In order to run, you must: (sudo) gem install jasmine-headless-webkit"
53
53
  end
54
54
  end
55
55
 
56
- task :default => :jasmine
56
+ task :default => 'jasmine:headless'
57
+
58
+
57
59
 
58
60
  #############################################################################
59
61
  #
data/eligo-rails.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'eligo-rails'
16
- s.version = '0.0.3'
17
- s.date = '2012-01-05'
16
+ s.version = '0.0.4'
17
+ s.date = '2012-01-07'
18
18
 
19
19
  ## Make sure your summary is short. The description may be as long
20
20
  ## as you like.
@@ -54,6 +54,7 @@ Gem::Specification.new do |s|
54
54
  s.files = %w[
55
55
  Gemfile
56
56
  Gemfile.lock
57
+ README.md
57
58
  Rakefile
58
59
  eligo-rails.gemspec
59
60
  lib/eligo-rails.rb
data/lib/eligo-rails.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Eligo
2
2
  module Rails
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
 
5
5
  class Engine < ::Rails::Engine
6
6
  end
@@ -19,7 +19,10 @@ describe 'shiftClickable()', ->
19
19
  third = createCheckbox()
20
20
  list.shiftClickable()
21
21
 
22
- shiftClickEvent = -> jQuery.Event 'click', shiftKey: true
22
+ shiftEvent = (event) ->
23
+ event or= 'click'
24
+ jQuery.Event event, shiftKey: true
25
+
23
26
  createCheckbox = ->
24
27
  $('<input type="checkbox">')
25
28
  .attr('id', checkID++)
@@ -41,7 +44,7 @@ describe 'shiftClickable()', ->
41
44
 
42
45
  it 'checks checkboxes between last and shift-clicked checkboxes', ->
43
46
  first.trigger 'click'
44
- third.trigger shiftClickEvent()
47
+ third.trigger shiftEvent()
45
48
 
46
49
  deferExpect ->
47
50
  expect(first) .toBeChecked()
@@ -56,7 +59,7 @@ describe 'shiftClickable()', ->
56
59
 
57
60
  it 'checks checkboxes when shift-clicking parent list item', ->
58
61
  first.trigger 'click'
59
- third.closest('li').trigger shiftClickEvent()
62
+ third.closest('li').trigger shiftEvent()
60
63
 
61
64
  deferExpect ->
62
65
  expect(first) .toBeChecked()
@@ -66,7 +69,7 @@ describe 'shiftClickable()', ->
66
69
  it 'triggers the change event on checkboxes', ->
67
70
  first.trigger 'click'
68
71
  spyOnEvent second, 'change'
69
- third.trigger shiftClickEvent()
72
+ third.trigger shiftEvent()
70
73
 
71
74
  deferExpect ->
72
75
  expect('change').toHaveBeenTriggeredOn(first)
@@ -75,7 +78,7 @@ describe 'shiftClickable()', ->
75
78
 
76
79
  it 'checks checkboxes below the shift-clicked checkbox', ->
77
80
  third.trigger 'click'
78
- first.trigger shiftClickEvent()
81
+ first.trigger shiftEvent()
79
82
 
80
83
  deferExpect ->
81
84
  expect(first) .toBeChecked()
@@ -83,7 +86,7 @@ describe 'shiftClickable()', ->
83
86
  expect(third) .toBeChecked()
84
87
 
85
88
  it 'sets a default anchor', ->
86
- second.trigger shiftClickEvent()
89
+ second.trigger shiftEvent()
87
90
 
88
91
  deferExpect ->
89
92
  expect(first) .toBeChecked()
@@ -91,7 +94,7 @@ describe 'shiftClickable()', ->
91
94
 
92
95
  it 'does not check checkboxes above the selected group', ->
93
96
  second.trigger 'click'
94
- third .trigger shiftClickEvent()
97
+ third .trigger shiftEvent()
95
98
 
96
99
  deferExpect ->
97
100
  expect(second).toBeChecked()
@@ -100,7 +103,7 @@ describe 'shiftClickable()', ->
100
103
 
101
104
  it 'does not check checkboxes below the selected group', ->
102
105
  first .trigger 'click'
103
- second.trigger shiftClickEvent()
106
+ second.trigger shiftEvent()
104
107
 
105
108
  deferExpect ->
106
109
  expect(first) .toBeChecked()
@@ -110,7 +113,7 @@ describe 'shiftClickable()', ->
110
113
  it 'unchecks checkboxes between last and shift-clicked checkboxes', ->
111
114
  group = [ third, second, first ]
112
115
  checkbox.trigger 'click' for checkbox in group
113
- third.trigger shiftClickEvent()
116
+ third.trigger shiftEvent()
114
117
 
115
118
  deferExpect ->
116
119
  expect(first) .not.toBeChecked()
@@ -120,7 +123,7 @@ describe 'shiftClickable()', ->
120
123
  it 'handles shift-clicks on appended checkboxes', ->
121
124
  late = createCheckbox()
122
125
  second.trigger 'click'
123
- late .trigger shiftClickEvent()
126
+ late .trigger shiftEvent()
124
127
 
125
128
  deferExpect ->
126
129
  expect(second).toBeChecked()
@@ -131,7 +134,7 @@ describe 'shiftClickable()', ->
131
134
  firstLate = createCheckbox()
132
135
  secondLate = createCheckbox()
133
136
  second .trigger 'click'
134
- secondLate.trigger shiftClickEvent()
137
+ secondLate.trigger shiftEvent()
135
138
 
136
139
  deferExpect ->
137
140
  expect(second) .toBeChecked()
@@ -148,10 +151,33 @@ describe 'shiftClickable()', ->
148
151
  firstLate.add(secondLate).closest('li')
149
152
  .insertBefore(second.closest('li'))
150
153
 
151
- first.trigger shiftClickEvent()
154
+ first.trigger shiftEvent()
152
155
 
153
156
  deferExpect ->
154
157
  expect(first) .toBeChecked()
155
158
  expect(firstLate) .toBeChecked()
156
159
  expect(secondLate).toBeChecked()
157
160
  expect(second) .toBeChecked()
161
+
162
+
163
+ describe 'text selection', ->
164
+ emptyMock = removeMock = null
165
+
166
+ beforeEach ->
167
+ selectionStub = sinon.stub()
168
+ emptyMock = selectionStub.empty = sinon.mock()
169
+ removeMock = selectionStub.removeAllRanges = sinon.mock()
170
+ sinon.stub(window, 'getSelection').returns(selectionStub)
171
+
172
+ afterEach ->
173
+ window.getSelection.restore()
174
+ emptyMock .verify()
175
+ removeMock.verify()
176
+
177
+ it 'prevents selecting text when shift-clicking a list item', ->
178
+ first.trigger shiftEvent 'mousedown'
179
+
180
+ it 'does nothing when clicking an item', ->
181
+ emptyMock .never()
182
+ removeMock.never()
183
+ first.trigger 'mousedown'
@@ -19,19 +19,25 @@ $.fn.shiftClickable = ->
19
19
  .prop('checked', checked)
20
20
  .change()
21
21
 
22
- list.click (e) ->
23
- clicked = $ e.target
24
- if clicked.is 'li'
25
- clicked.find(checkboxSelector)
26
- .trigger $.Event('click', shiftKey: e.shiftKey)
27
- else
28
- clicked = clicked.closest 'li'
22
+ list
23
+ .mousedown (e) ->
24
+ return unless e.shiftKey
25
+ window.getSelection?().empty?()
26
+ window.getSelection?().removeAllRanges?()
29
27
 
30
- # It seems WebKit triggers `change` before `click`, but I'm not too
31
- # confident that all browsers must trigger events in exactly the same way.
32
- # Defer setting the value to be sure the checkbox has its new value.
33
- window.setTimeout(
34
- ->
35
- shiftClick clicked if e.shiftKey
36
- anchor = clicked
37
- 1)
28
+ .click (e) ->
29
+ clicked = $ e.target
30
+ if clicked.is 'li'
31
+ clicked.find(checkboxSelector)
32
+ .trigger $.Event('click', shiftKey: e.shiftKey)
33
+ else
34
+ clicked = clicked.closest 'li'
35
+
36
+ # It seems WebKit triggers `change` before `click`, but I'm not too
37
+ # confident that all browsers must trigger events in exactly the same way.
38
+ # Defer setting the value to be sure the checkbox has its new value.
39
+ window.setTimeout(
40
+ ->
41
+ shiftClick clicked if e.shiftKey
42
+ anchor = clicked
43
+ 1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eligo-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-05 00:00:00.000000000 Z
12
+ date: 2012-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70188917783640 !ruby/object:Gem::Requirement
16
+ requirement: &70104276728640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70188917783640
24
+ version_requirements: *70104276728640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jquery-rails
27
- requirement: &70188917782640 !ruby/object:Gem::Requirement
27
+ requirement: &70104276727560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70188917782640
35
+ version_requirements: *70104276727560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jasmine-headless-webkit
38
- requirement: &70188917781460 !ruby/object:Gem::Requirement
38
+ requirement: &70104276726580 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.8.4
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70188917781460
46
+ version_requirements: *70104276726580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jasmine-spec-extras
49
- requirement: &70188917780220 !ruby/object:Gem::Requirement
49
+ requirement: &70104276725280 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 0.0.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70188917780220
57
+ version_requirements: *70104276725280
58
58
  description: Add shift-click selection to a list of checkboxes.
59
59
  email: larry@marburger.cc
60
60
  executables: []
@@ -63,6 +63,7 @@ extra_rdoc_files: []
63
63
  files:
64
64
  - Gemfile
65
65
  - Gemfile.lock
66
+ - README.md
66
67
  - Rakefile
67
68
  - eligo-rails.gemspec
68
69
  - lib/eligo-rails.rb