olay-rails 0.1.8 → 0.1.9

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
- SHA1:
3
- metadata.gz: d865996f1310571f34aaaf0ef4b6fcd43890fbaf
4
- data.tar.gz: 0d23f8982d580c25398fadb25d9c00f5e5f1087a
5
2
  SHA512:
6
- metadata.gz: 37a68accc0d3151a40d73000f5c2eb45ad155b70e725c560a972ed8ccaa3845c7da0299d23777e74b44a096b464244fb7af9f8dd0f41d0717ecbd24095090c64
7
- data.tar.gz: 6cbb597fa03e856ddd592308218dd7e2758101c035882c9a7f95c5323549def287696f3db6bc456c3d9c27f1e8aed2acd1ba67f21d5844c8650a734afce430f6
3
+ data.tar.gz: a7e9f507d8e88291ea0a25c42a36d6df462d03f430f90ec025a9b7a6f41a65e97d1a27512813db75859feaf571ca09661d7f37ba772650fcf6093ee1bf541b5d
4
+ metadata.gz: 66fd18e3cef5ae793b346d378be1b9c278a82c3977c3e0416dc706fc98ee5c4d48fd18cd7394c19c159e4b33a51e5b9cd545bbb8b6ced17d273287d7fee8c660
5
+ SHA1:
6
+ data.tar.gz: a0e3d42af15820af64d51f81ae18a555dcb8875e
7
+ metadata.gz: 96550cafdbc971374c92b50aa54a18eece53fe76
@@ -1,6 +1,6 @@
1
1
  module Olay
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  module Rails
4
- VERSION = '0.1.8'
4
+ VERSION = '0.1.9'
5
5
  end
6
6
  end
@@ -4,13 +4,16 @@
4
4
  // Store a local reference to jQuery.
5
5
  var $ = window.jQuery;
6
6
 
7
- // This private function will be used to stop event propagation in $content.
8
- var stopPropagation = function (ev) { ev.stopPropagation(); };
9
-
10
7
  // Selector for tabbable elements.
11
8
  var tabbable =
12
9
  ':input, [tabindex], [contenteditable], [href], iframe, object, embed';
13
10
 
11
+ // Convenience method for `off`/`on`ing in jQuery.
12
+ var delegate = function ($el, ev, selector, cb) {
13
+ $el.off.call($el, ev, selector, cb);
14
+ $el.on.call($el, ev, selector, cb);
15
+ };
16
+
14
17
  // Listen for keydown events.
15
18
  $(document).keydown(function (ev) {
16
19
  var $olay = $('.js-olay-container').last();
@@ -33,14 +36,19 @@
33
36
  // Extend the instance with its options.
34
37
  for (var name in options) this[name] = options[name];
35
38
 
36
- // Store a bound `hide` to be used for callbacks. This is also used to
39
+ // Store bound listeners to be used for callbacks. This is also used to
37
40
  // ensure event callbacks can be removed consistently.
38
41
  var self = this;
39
42
  this._hide = function () { return self.hide(); };
43
+ var event;
44
+ this._$containerClick = function (ev) {
45
+ if (self.hideOnClick && event !== ev.originalEvent) self.hide();
46
+ };
47
+ this._$contentClick = function (ev) { event = ev.originalEvent; };
40
48
 
41
49
  // Create the necessary DOM nodes.
42
50
  this.$container = $('<div>')
43
- .addClass('js-olay-container')
51
+ .addClass('js-olay-container ')
44
52
  .addClass(this.transition)
45
53
  .append(
46
54
  this.$table = $('<div>')
@@ -51,8 +59,7 @@
51
59
  .append(
52
60
  this.$content = $('<div>')
53
61
  .addClass('js-olay-content')
54
- .attr({role: 'alertdialog', 'aria-label': this.ariaLabel})
55
- .on('click', '.js-olay-hide', this._hide))));
62
+ .attr({role: 'alertdialog', 'aria-label': this.ariaLabel}))));
56
63
 
57
64
  // Finally, set the element.
58
65
  this.setElement(el);
@@ -94,19 +101,20 @@
94
101
  clearTimeout(this._timeout);
95
102
  if (!inDom) this._append();
96
103
 
97
- // Force a redraw before and after adding the transition class. Not doing
98
- // this will apply the end result of the transition instantly, which is
99
- // not desirable in a transition...
104
+ // Force a redraw before adding the transition class. Not doing this will
105
+ // apply the end result of the transition instantly, which is not
106
+ // desirable in a transition...
100
107
  this.$container.data('olay', this).height();
101
- this.$container.addClass('js-olay-show').off('click', this._hide);
102
- this.$content.off('click', stopPropagation);
103
- if (this.hideOnClick) {
104
- this.$container.click(this._hide);
105
- this.$content.click(stopPropagation);
106
- }
108
+ this.$container.addClass('js-olay-show');
109
+
110
+ // Delegate events, ensuring no double-binding.
111
+ delegate(this.$container, 'click', this._$containerClick);
112
+ delegate(this.$content, 'click', this._$contentClick);
113
+ delegate(this.$content, 'click', '.js-olay-hide', this._hide);
114
+
107
115
  this.$el.trigger('show');
108
116
  var duration = this.duration;
109
- if (!duration) return this;
117
+ if (!this.duration) return this;
110
118
  duration += this.transitionDuration;
111
119
  this._timeout = setTimeout(this._hide, duration);
112
120
  return this;
@@ -128,6 +136,7 @@
128
136
  // Use this method to set or update `$el`.
129
137
  setElement: function (el) {
130
138
  this.$content.empty().append(this.$el = el instanceof $ ? el : $(el));
139
+ return this;
131
140
  },
132
141
 
133
142
  // Completely remove the `$container` element and its children and all of
@@ -143,15 +152,13 @@
143
152
  var $body = $('body');
144
153
  var $olays = $('.js-olay-container');
145
154
  var active = document.activeElement;
146
- this._$active =
147
- $olays.length && active === $body[0] ?
148
- $olays.last() :
149
- $(active);
155
+ var useLast = $olays.length && active === $body[0];
156
+ this._$active = useLast ? $olays.last() : $(active);
150
157
  $(tabbable).each(function () {
151
158
  if ('olayTabindex' in this) return;
152
- var $t = $(this);
153
- this.olayTabindex = $t.attr('tabindex') || null;
154
- $t.attr('tabindex', -1);
159
+ var $self = $(this);
160
+ this.olayTabindex = $self.attr('tabindex') || null;
161
+ $self.attr('tabindex', -1);
155
162
  });
156
163
  $body.addClass('js-olay-visible').append(this.$container);
157
164
  this.$content.attr('tabindex', 0).focus().removeAttr('tabindex');
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: olay-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Casey Foster
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-03-08 00:00:00 Z
13
+ date: 2013-03-11 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  prerelease: false
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: "3.1"
23
23
  type: :runtime
24
24
  version_requirements: *id001
25
- description: Places Olay 0.1.8 in the Rails asset pipeline.
25
+ description: Places Olay 0.1.9 in the Rails asset pipeline.
26
26
  email:
27
27
  - c@sey.me
28
28
  executables: []