uber_select_rails 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0dad48d52dd5e14c133c8d6c01861f5ae3e9069110df7b8b5faa7840703342f7
4
- data.tar.gz: 72be4762c753d35290e7f9d63d6b9575f0967d44d9a9b382d417accb6324fd6b
3
+ metadata.gz: bf09e09761faba19203a94b5cc53f7d59aaaf114dde0cef6b4624ba5d1b4a916
4
+ data.tar.gz: 6a22b0a860276671c3c10253165e3f06d0735ea383865e077ca3ed2ee81dc286
5
5
  SHA512:
6
- metadata.gz: a39831aaeb705925e5bf27053e4445232096eb8ba8f4e572ce2809a21b1cd4a9f42af62189614089fa7dba4fa9b5f046988fcfea92ce47ee872e76f24692b797
7
- data.tar.gz: 98cdf58391fea57de5ac5ea903a72e2d6fb15b67956ec64d0ffcdf73aa3231349f38b1555a31f2422653b2ed6acb37b63882918cbf16856368cb54af42c1924f
6
+ metadata.gz: 9adcece32e2b8db8049459f8daeac77c25e8f796295b0215297772a34e1b8faf70dd11e7676cdfb3e98d5f25d8ae9ec3ef572325471ec38418e38e7c65c1fa46
7
+ data.tar.gz: 53d97f64a172512b486aeff0094fa4d6493f45b662e4aebef91712535debf63386a1a410f9949daf3a6227a1ad0e8deeac347839da1ac5ee697bc4f9cbbbf9ab
@@ -1,3 +1,3 @@
1
1
  module UberSelectRails
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -1,7 +1,8 @@
1
- function Pane(options){
2
- options = $.extend({
3
- trigger: null
4
- }, options)
1
+ function Pane(){
2
+ var eventsTriggered = {
3
+ shown: 'shown.UberSelect',
4
+ hidden: 'hidden.UberSelect'
5
+ }
5
6
 
6
7
  var context = this
7
8
  var model = {}
@@ -27,13 +28,6 @@ function Pane(options){
27
28
 
28
29
  // BEHAVIOUR
29
30
 
30
- // Hide the pane when clicked out
31
- $(document).on('mousedown', function(event){
32
- if (isEventOutsidePane(event) && isEventOutsideTrigger(event)){
33
- context.hide()
34
- }
35
- })
36
-
37
31
  // Make it possible to have elements in the pane that close it
38
32
  view.on('click', '[data-behaviour~=close-pane]', function(event){
39
33
  context.hide()
@@ -72,13 +66,13 @@ function Pane(options){
72
66
  if (isOpen) { return }
73
67
  isOpen = true
74
68
  view.show()
75
- $(context).trigger('shown')
69
+ triggerEvent(eventsTriggered.shown)
76
70
  }
77
71
  function hide(){
78
72
  if (!isOpen) { return }
79
73
  isOpen = false
80
74
  view.hide()
81
- $(context).trigger('hidden')
75
+ triggerEvent(eventsTriggered.hidden)
82
76
  }
83
77
  function toggle(){
84
78
  if (isOpen) {
@@ -88,13 +82,8 @@ function Pane(options){
88
82
  }
89
83
  }
90
84
 
91
- // returns true if the event originated outside the pane
92
- function isEventOutsidePane(event){
93
- return !$(event.target).closest(view).length
94
- }
95
-
96
- function isEventOutsideTrigger(event){
97
- return !$(event.target).closest(options.trigger).length
85
+ function triggerEvent(eventType, callbackArgs){
86
+ view.trigger(eventType, callbackArgs)
87
+ $(context).trigger(eventType, callbackArgs)
98
88
  }
99
-
100
89
  }
@@ -71,6 +71,13 @@ var UberSearch = function(data, options){
71
71
  pane.show()
72
72
  })
73
73
 
74
+ // Hide the pane when clicked out or another pane is opened
75
+ $(document).on('click shown.UberSelect', function(event){
76
+ if (isEventOutsidePane(event) && isEventOutsideOutputContainer(event)){
77
+ pane.hide()
78
+ }
79
+ })
80
+
74
81
  // Show the pane if the user was tabbed onto the trigger and pressed enter, space, or down arrow
75
82
  $(outputContainer.view).on('keyup', function(event){
76
83
  if (outputContainer.view.hasClass('disabled')) { return }
@@ -359,6 +366,15 @@ var UberSearch = function(data, options){
359
366
  return search.getResults().length
360
367
  }
361
368
 
369
+ // returns true if the event originated outside the pane
370
+ function isEventOutsidePane(event){
371
+ return !$(event.target).closest(pane.view).length
372
+ }
373
+
374
+ function isEventOutsideOutputContainer(event){
375
+ return !$(event.target).closest(outputContainer.view).length
376
+ }
377
+
362
378
  // Allow observer to be attached to the UberSearch itself
363
379
  function triggerEvent(eventType, callbackArgs){
364
380
  view.trigger(eventType, callbackArgs)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uber_select_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Jakobsen