unpoly-rails 0.50.1 → 0.50.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of unpoly-rails might be problematic. Click here for more details.

@@ -261,10 +261,11 @@ up.link = (($) ->
261
261
  unless isFollowable($link)
262
262
  $link.attr('up-follow', '')
263
263
 
264
- childClicked = (event, $link) ->
264
+ shouldProcessEvent = (event, $link) ->
265
265
  $target = $(event.target)
266
- $targetLink = $target.closest('a, [up-href]')
267
- $targetLink.length && $link.find($targetLink).length
266
+ $targetedChildLink = $target.closest('a, [up-href]').not($link)
267
+ $targetedInput = up.form.fieldSelector().seekUp($target)
268
+ $targetedChildLink.length == 0 && $targetedInput.length == 0 && u.isUnmodifiedMouseEvent(event)
268
269
 
269
270
  ###*
270
271
  Returns whether the given link has a [safe](https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.1)
@@ -553,7 +554,7 @@ up.link = (($) ->
553
554
  makeFollowable: makeFollowable
554
555
  isSafe: isSafe
555
556
  isFollowable: isFollowable
556
- childClicked: childClicked
557
+ shouldProcessEvent: shouldProcessEvent
557
558
  followMethod: followMethod
558
559
  addFollowVariant: addFollowVariant
559
560
  followVariantForLink: followVariantForLink
@@ -159,7 +159,7 @@ up.proxy = (($) ->
159
159
 
160
160
  up.request('/search', data: { query: 'sunshine' }).then(function(response) {
161
161
  console.log('The response text is %o', response.text);
162
- }).fail(function() {
162
+ }).catch(function() {
163
163
  console.error('The request failed');
164
164
  });
165
165
 
@@ -266,7 +266,7 @@ up.proxy = (($) ->
266
266
 
267
267
  up.request('/search', data: { query: 'sunshine' }).then(function(text) {
268
268
  console.log('The response text is %o', text);
269
- }).fail(function() {
269
+ }).catch(function() {
270
270
  console.error('The request failed');
271
271
  });
272
272
 
@@ -631,11 +631,11 @@ up.proxy = (($) ->
631
631
  but will also make the interaction feel less instant.
632
632
  @stable
633
633
  ###
634
- up.on 'mouseover mousedown touchstart', 'a[up-preload], [up-href][up-preload]', (event, $element) ->
634
+ up.on 'mouseover mousedown touchstart', 'a[up-preload], [up-href][up-preload]', (event, $link) ->
635
635
  # Don't do anything if we are hovering over the child of a link.
636
636
  # The actual link will receive the event and bubble in a second.
637
- if !up.link.childClicked(event, $element) && up.link.isSafe($element)
638
- checkPreload($element)
637
+ if up.link.shouldProcessEvent(event, $link) && up.link.isSafe($link)
638
+ checkPreload($link)
639
639
 
640
640
  up.on 'up:framework:reset', reset
641
641
 
@@ -345,10 +345,14 @@ up.syntax = (($) ->
345
345
  $matches = u.selectInSubtree($fragment, compiler.selector)
346
346
 
347
347
  # Exclude all elements that are descendants of the subtrees we want to keep.
348
- $matches = $matches.filter ->
349
- $match = $(this)
350
- u.all $skipSubtrees, (skipSubtree) ->
351
- $match.closest(skipSubtree).length == 0
348
+ # We only do this if `options.skip` was given, since the exclusion
349
+ # process below is very expensive (we had a case where compiling 100 slements
350
+ # took 1.5s because of this).
351
+ if $skipSubtrees.length
352
+ $matches = $matches.filter ->
353
+ $match = $(this)
354
+ u.all $skipSubtrees, (skipSubtree) ->
355
+ $match.closest(skipSubtree).length == 0
352
356
 
353
357
  if $matches.length
354
358
  up.log.group ("Compiling '%s' on %d element(s)" unless compiler.isSystem), compiler.selector, $matches.length, ->
@@ -4,6 +4,6 @@ module Unpoly
4
4
  # The current version of the unpoly-rails gem.
5
5
  # This version number is also used for releases of the Unpoly
6
6
  # frontend code.
7
- VERSION = '0.50.1'
7
+ VERSION = '0.50.2'
8
8
  end
9
9
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unpoly",
3
- "version": "0.50.1",
3
+ "version": "0.50.2",
4
4
  "description": "Unobtrusive JavaScript framework",
5
5
  "main": "dist/unpoly.js",
6
6
  "files": [
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- unpoly-rails (0.50.0)
4
+ unpoly-rails (0.50.1)
5
5
  rails (>= 3)
6
6
 
7
7
  GEM
@@ -81,6 +81,6 @@
81
81
  mouseup: mouseup
82
82
  click: click
83
83
  clickSequence: clickSequence
84
-
84
+ createMouseEvent: createMouseEvent
85
85
 
86
86
  )()
@@ -207,6 +207,12 @@ describe 'up.layout', ->
207
207
  # [F] 0 ............ 99
208
208
  expect($(document).scrollTop()).toBe(@clientHeight + 50)
209
209
 
210
+ it 'does not crash when called with a CSS selector (bugfix)', (done) ->
211
+ promise = up.reveal('.container')
212
+ promiseState(promise).then (result) ->
213
+ expect(result.state).toEqual('fulfilled')
214
+ done()
215
+
210
216
  describe 'with { top: true } option', ->
211
217
 
212
218
  it 'scrolls the viewport to the first row of the element, even if that element is already fully revealed', asyncSpec (next) ->
@@ -368,7 +368,7 @@ describe 'up.link', ->
368
368
 
369
369
  describeFallback 'canPushState', ->
370
370
 
371
- it 'follows the given link', asyncSpec (next) ->
371
+ it 'navigates to the given link without JavaScript', asyncSpec (next) ->
372
372
  $link = affix('a[href="/path"]')
373
373
  spyOn(up.browser, 'navigate')
374
374
  up.follow($link)
@@ -384,6 +384,57 @@ describe 'up.link', ->
384
384
  next =>
385
385
  expect(up.browser.navigate).toHaveBeenCalledWith('/path', { method: 'PUT' })
386
386
 
387
+ describe 'up.link.shouldProcessEvent', ->
388
+
389
+ buildEvent = ($element, attrs) ->
390
+ event = Trigger.createMouseEvent('mousedown', attrs)
391
+ event = $.event.fix(event) # convert native event to jQuery event
392
+ event.target = u.unJQuery($element)
393
+ event
394
+
395
+ it "returns true when the given event's target is the given link itself", ->
396
+ $link = affix('a[href="/foo"]')
397
+ event = buildEvent($link)
398
+ expect(up.link.shouldProcessEvent(event, $link)).toBe(true)
399
+
400
+ it "returns true when the given event's target is a non-link child of the given link", ->
401
+ $link = affix('a[href="/foo"]')
402
+ $span = $link.affix('span')
403
+ event = buildEvent($span)
404
+ expect(up.link.shouldProcessEvent(event, $link)).toBe(true)
405
+
406
+ it "returns false when the given event's target is a child link of the given link (think [up-expand])", ->
407
+ $link = affix('div[up-href="/foo"]')
408
+ $childLink = $link.affix('a[href="/bar"]')
409
+ event = buildEvent($childLink)
410
+ expect(up.link.shouldProcessEvent(event, $link)).toBe(false)
411
+
412
+ it "returns false when the given event's target is a child input of the given link (think [up-expand])", ->
413
+ $link = affix('div[up-href="/foo"]')
414
+ $childInput = $link.affix('input[type="text"]')
415
+ event = buildEvent($childInput)
416
+ expect(up.link.shouldProcessEvent(event, $link)).toBe(false)
417
+
418
+ it 'returns false if the right mouse button is used', ->
419
+ $link = affix('a[href="/foo"]')
420
+ event = buildEvent($link, button: 2)
421
+ expect(up.link.shouldProcessEvent(event, $link)).toBe(false)
422
+
423
+ it 'returns false if shift is pressed during the click', ->
424
+ $link = affix('a[href="/foo"]')
425
+ event = buildEvent($link, shiftKey: 2)
426
+ expect(up.link.shouldProcessEvent(event, $link)).toBe(false)
427
+
428
+ it 'returns false if ctrl is pressed during the click', ->
429
+ $link = affix('a[href="/foo"]')
430
+ event = buildEvent($link, ctrlKey: 2)
431
+ expect(up.link.shouldProcessEvent(event, $link)).toBe(false)
432
+
433
+ it 'returns false if meta is pressed during the click', ->
434
+ $link = affix('a[href="/foo"]')
435
+ event = buildEvent($link, metaKey: 2)
436
+ expect(up.link.shouldProcessEvent(event, $link)).toBe(false)
437
+
387
438
  describe 'up.link.makeFollowable', ->
388
439
 
389
440
  it "adds [up-follow] to a link that wouldn't otherwise be handled by Unpoly", ->
@@ -824,6 +875,27 @@ describe 'up.link', ->
824
875
  next =>
825
876
  expect(up.replace).toHaveBeenCalled()
826
877
 
878
+ it 'does nothing when the user clicks another link in the expanded area', asyncSpec (next) ->
879
+ $area = affix('div[up-expand]')
880
+ $expandedLink = $area.affix('a[href="/expanded-path"][up-follow]')
881
+ $otherLink = $area.affix('a[href="/other-path"][up-follow]')
882
+ up.hello($area)
883
+ followSpy = up.link.knife.mock('defaultFollow').and.returnValue(Promise.resolve())
884
+ Trigger.clickSequence($otherLink)
885
+ next =>
886
+ expect(followSpy.calls.count()).toEqual(1)
887
+ expect(followSpy.calls.mostRecent().args[0]).toEqual($otherLink)
888
+
889
+ it 'does nothing when the user clicks on an input in the expanded area', asyncSpec (next) ->
890
+ $area = affix('div[up-expand]')
891
+ $expandedLink = $area.affix('a[href="/expanded-path"][up-follow]')
892
+ $input = $area.affix('input[type=text]')
893
+ up.hello($area)
894
+ followSpy = up.link.knife.mock('defaultFollow').and.returnValue(Promise.resolve())
895
+ Trigger.clickSequence($input)
896
+ next =>
897
+ expect(followSpy).not.toHaveBeenCalled()
898
+
827
899
  it 'does not trigger multiple replaces when the user clicks on the expanded area of an [up-instant] link (bugfix)', asyncSpec (next) ->
828
900
  $area = affix('div[up-expand] a[href="/path"][up-follow][up-instant]')
829
901
  up.hello($area)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unpoly-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.50.1
4
+ version: 0.50.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-18 00:00:00.000000000 Z
11
+ date: 2017-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails