jquery-modal-rails-assets 0.6.1 → 0.7.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0a7d1c2ce9b7ada484825b08678b4fc017c3bfb
4
- data.tar.gz: cfd11161fd506d4e5009f19af195b7172c99d84c
3
+ metadata.gz: aee86331f582edecdab486c2c248c99f7a8392d5
4
+ data.tar.gz: 3a2d4b93aa9c4986a12a09df40eaad7dc1418c32
5
5
  SHA512:
6
- metadata.gz: fa3ca7c03cfab0cf944e617f8749a62e0ac40133c1079608efb7665b3d517bed0c6f3ad896f8cab3d508abbc01027727e94619c3c60ffd3855e5df83d8cc0857
7
- data.tar.gz: 835f8338771ae39b9678787b5d2ed3dc7b287b86d415d06f91c923eb44cc7697f34931011e36ffbd204de51047f75df0ef4c8935077456b4f393ca958e8181df
6
+ metadata.gz: 46cdc0b4d24fd162bc2bae448dfdb1f2888e0d4ab38db47848c0c833feb0f1bb12db2f1bdb5cd35a227574f7ca9b8d4262801466e7a7bbcb72d0216b8ffe8a70
7
+ data.tar.gz: fdbb251e4ac70cba55a92fb9adfb05c0b3cb38605a1b6b6ff602ea8da70eed1003ab018ab0d504de1ecfd006f2fe04d71ee2c1cd2d452aa0aa09acb3eac92a0e
@@ -1,17 +1,34 @@
1
1
  /*
2
2
  A simple jQuery modal (http://github.com/kylefox/jquery-modal)
3
- Version 0.6.1
3
+ Version 0.7.0
4
4
  */
5
5
  (function($) {
6
6
 
7
- var current = null;
7
+ var modals = [],
8
+ getCurrent = function() {
9
+ return modals.length ? modals[modals.length - 1] : null;
10
+ },
11
+ selectCurrent = function() {
12
+ var i,
13
+ selected = false;
14
+ for (i=modals.length-1; i>=0; i--) {
15
+ if (modals[i].$blocker) {
16
+ modals[i].$blocker.toggleClass('current',!selected).toggleClass('behind',selected);
17
+ selected = true;
18
+ }
19
+ }
20
+ };
8
21
 
9
22
  $.modal = function(el, options) {
10
- $.modal.close(); // Close any open modals.
11
23
  var remove, target;
12
24
  this.$body = $('body');
13
25
  this.options = $.extend({}, $.modal.defaults, options);
14
26
  this.options.doFade = !isNaN(parseInt(this.options.fadeDuration, 10));
27
+ this.$blocker = null;
28
+ if (this.options.closeExisting)
29
+ while ($.modal.isActive())
30
+ $.modal.close(); // Close any open modals.
31
+ modals.push(this);
15
32
  if (el.is('a')) {
16
33
  target = el.attr('href');
17
34
  //Select element by id from href
@@ -28,15 +45,18 @@
28
45
  this.showSpinner();
29
46
  el.trigger($.modal.AJAX_SEND);
30
47
  $.get(target).done(function(html) {
31
- if (!current) return;
48
+ if (!$.modal.isActive()) return;
32
49
  el.trigger($.modal.AJAX_SUCCESS);
50
+ var current = getCurrent();
33
51
  current.$elm.empty().append(html).on($.modal.CLOSE, remove);
34
52
  current.hideSpinner();
35
53
  current.open();
36
54
  el.trigger($.modal.AJAX_COMPLETE);
37
55
  }).fail(function() {
38
56
  el.trigger($.modal.AJAX_FAIL);
57
+ var current = getCurrent();
39
58
  current.hideSpinner();
59
+ modals.pop(); // remove expected modal from the list
40
60
  el.trigger($.modal.AJAX_COMPLETE);
41
61
  });
42
62
  }
@@ -52,55 +72,54 @@
52
72
 
53
73
  open: function() {
54
74
  var m = this;
75
+ this.block();
55
76
  if(this.options.doFade) {
56
- this.block();
57
77
  setTimeout(function() {
58
78
  m.show();
59
79
  }, this.options.fadeDuration * this.options.fadeDelay);
60
80
  } else {
61
- this.block();
62
81
  this.show();
63
82
  }
64
- if (this.options.escapeClose) {
65
- $(document).on('keydown.modal', function(event) {
66
- if (event.which == 27) $.modal.close();
67
- });
68
- }
69
- if (this.options.clickClose) this.blocker.click(function(e){
70
- if (e.target==this)
71
- $.modal.close();
83
+ $(document).off('keydown.modal').on('keydown.modal', function(event) {
84
+ var current = getCurrent();
85
+ if (event.which == 27 && current.options.escapeClose) current.close();
72
86
  });
87
+ if (this.options.clickClose)
88
+ this.$blocker.click(function(e) {
89
+ if (e.target==this)
90
+ $.modal.close();
91
+ });
73
92
  },
74
93
 
75
94
  close: function() {
95
+ modals.pop();
76
96
  this.unblock();
77
97
  this.hide();
78
- $(document).off('keydown.modal');
98
+ if (!$.modal.isActive())
99
+ $(document).off('keydown.modal');
79
100
  },
80
101
 
81
102
  block: function() {
82
103
  this.$elm.trigger($.modal.BEFORE_BLOCK, [this._ctx()]);
83
- this.blocker = $('<div class="jquery-modal blocker"></div>');
84
104
  this.$body.css('overflow','hidden');
85
- this.$body.append(this.blocker);
105
+ this.$blocker = $('<div class="jquery-modal blocker current"></div>').appendTo(this.$body);
106
+ selectCurrent();
86
107
  if(this.options.doFade) {
87
- this.blocker.css('opacity',0).animate({opacity: 1}, this.options.fadeDuration);
108
+ this.$blocker.css('opacity',0).animate({opacity: 1}, this.options.fadeDuration);
88
109
  }
89
110
  this.$elm.trigger($.modal.BLOCK, [this._ctx()]);
90
111
  },
91
112
 
92
- unblock: function() {
93
- if(this.options.doFade) {
94
- var self=this;
95
- this.blocker.fadeOut(this.options.fadeDuration, function() {
96
- self.blocker.children().appendTo(self.$body);
97
- self.blocker.remove();
98
- self.$body.css('overflow','');
99
- });
100
- } else {
101
- this.blocker.children().appendTo(this.$body);
102
- this.blocker.remove();
103
- this.$body.css('overflow','');
113
+ unblock: function(now) {
114
+ if (!now && this.options.doFade)
115
+ this.$blocker.fadeOut(this.options.fadeDuration, this.unblock.bind(this,true));
116
+ else {
117
+ this.$blocker.children().appendTo(this.$body);
118
+ this.$blocker.remove();
119
+ this.$blocker = null;
120
+ selectCurrent();
121
+ if (!$.modal.isActive())
122
+ this.$body.css('overflow','');
104
123
  }
105
124
  },
106
125
 
@@ -110,8 +129,7 @@
110
129
  this.closeButton = $('<a href="#close-modal" rel="modal:close" class="close-modal ' + this.options.closeClass + '">' + this.options.closeText + '</a>');
111
130
  this.$elm.append(this.closeButton);
112
131
  }
113
- this.$elm.addClass(this.options.modalClass + ' current');
114
- this.$elm.appendTo(this.blocker);
132
+ this.$elm.addClass(this.options.modalClass).appendTo(this.$blocker);
115
133
  if(this.options.doFade) {
116
134
  this.$elm.css('opacity',0).show().animate({opacity: 1}, this.options.fadeDuration);
117
135
  } else {
@@ -123,8 +141,6 @@
123
141
  hide: function() {
124
142
  this.$elm.trigger($.modal.BEFORE_CLOSE, [this._ctx()]);
125
143
  if (this.closeButton) this.closeButton.remove();
126
- this.$elm.removeClass('current');
127
-
128
144
  var _this = this;
129
145
  if(this.options.doFade) {
130
146
  this.$elm.fadeOut(this.options.fadeDuration, function () {
@@ -152,25 +168,25 @@
152
168
 
153
169
  //Return context for custom events
154
170
  _ctx: function() {
155
- return { elm: this.$elm, blocker: this.blocker, options: this.options };
171
+ return { elm: this.$elm, $blocker: this.$blocker, options: this.options };
156
172
  }
157
173
  };
158
174
 
159
175
  $.modal.close = function(event) {
160
- if (!current) return;
176
+ if (!$.modal.isActive()) return;
161
177
  if (event) event.preventDefault();
178
+ var current = getCurrent();
162
179
  current.close();
163
- var that = current.$elm;
164
- current = null;
165
- return that;
180
+ return current.$elm;
166
181
  };
167
182
 
168
183
  // Returns if there currently is an active modal
169
184
  $.modal.isActive = function () {
170
- return current ? true : false;
185
+ return modals.length > 0;
171
186
  }
172
187
 
173
188
  $.modal.defaults = {
189
+ closeExisting: true,
174
190
  escapeClose: true,
175
191
  clickClose: true,
176
192
  closeText: 'Close',
@@ -198,7 +214,7 @@
198
214
 
199
215
  $.fn.modal = function(options){
200
216
  if (this.length === 1) {
201
- current = new $.modal(this, options);
217
+ new $.modal(this, options);
202
218
  }
203
219
  return this;
204
220
  };
@@ -17,6 +17,9 @@
17
17
  vertical-align: middle;
18
18
  margin-right: -0.05em;
19
19
  }
20
+ .blocker.behind {
21
+ background-color: transparent;
22
+ }
20
23
  .modal {
21
24
  display: inline-block;
22
25
  vertical-align: middle;
@@ -1,3 +1,3 @@
1
1
  module JqueryModalRailsAssets
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-modal-rails-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RogerE
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler