jquery-modal-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/.gitignore +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +22 -0
  5. data/README.md +81 -0
  6. data/Rakefile +2 -0
  7. data/demoapp/Gemfile +41 -0
  8. data/demoapp/README.rdoc +261 -0
  9. data/demoapp/Rakefile +7 -0
  10. data/demoapp/app/assets/images/rails.png +0 -0
  11. data/demoapp/app/assets/javascripts/application.js +17 -0
  12. data/demoapp/app/assets/javascripts/users.js.coffee +3 -0
  13. data/demoapp/app/assets/stylesheets/application.css +15 -0
  14. data/demoapp/app/assets/stylesheets/scaffolds.css.scss +56 -0
  15. data/demoapp/app/assets/stylesheets/users.css.scss +3 -0
  16. data/demoapp/app/controllers/application_controller.rb +3 -0
  17. data/demoapp/app/controllers/users_controller.rb +89 -0
  18. data/demoapp/app/helpers/application_helper.rb +2 -0
  19. data/demoapp/app/helpers/users_helper.rb +2 -0
  20. data/demoapp/app/models/user.rb +7 -0
  21. data/demoapp/app/views/layouts/application.html.erb +14 -0
  22. data/demoapp/app/views/users/_form.html.erb +25 -0
  23. data/demoapp/app/views/users/edit.html.erb +6 -0
  24. data/demoapp/app/views/users/index.html.erb +31 -0
  25. data/demoapp/app/views/users/new.html.erb +5 -0
  26. data/demoapp/app/views/users/show.html.erb +15 -0
  27. data/demoapp/config.ru +4 -0
  28. data/demoapp/config/application.rb +62 -0
  29. data/demoapp/config/boot.rb +6 -0
  30. data/demoapp/config/database.yml +25 -0
  31. data/demoapp/config/environment.rb +5 -0
  32. data/demoapp/config/environments/development.rb +37 -0
  33. data/demoapp/config/environments/production.rb +67 -0
  34. data/demoapp/config/environments/test.rb +37 -0
  35. data/demoapp/config/initializers/backtrace_silencers.rb +7 -0
  36. data/demoapp/config/initializers/inflections.rb +15 -0
  37. data/demoapp/config/initializers/mime_types.rb +5 -0
  38. data/demoapp/config/initializers/secret_token.rb +7 -0
  39. data/demoapp/config/initializers/session_store.rb +8 -0
  40. data/demoapp/config/initializers/wrap_parameters.rb +14 -0
  41. data/demoapp/config/locales/en.yml +5 -0
  42. data/demoapp/config/routes.rb +4 -0
  43. data/demoapp/db/development.sqlite3 +0 -0
  44. data/demoapp/db/migrate/20120621084323_create_users.rb +10 -0
  45. data/demoapp/db/schema.rb +23 -0
  46. data/demoapp/db/seeds.rb +7 -0
  47. data/demoapp/doc/README_FOR_APP +2 -0
  48. data/demoapp/public/404.html +26 -0
  49. data/demoapp/public/422.html +26 -0
  50. data/demoapp/public/500.html +25 -0
  51. data/demoapp/public/favicon.ico +0 -0
  52. data/demoapp/public/robots.txt +5 -0
  53. data/demoapp/script/rails +6 -0
  54. data/demoapp/test/fixtures/users.yml +9 -0
  55. data/demoapp/test/functional/users_controller_test.rb +49 -0
  56. data/demoapp/test/performance/browsing_test.rb +12 -0
  57. data/demoapp/test/test_helper.rb +13 -0
  58. data/demoapp/test/unit/helpers/users_helper_test.rb +4 -0
  59. data/demoapp/test/unit/user_test.rb +7 -0
  60. data/jquery-modal-rails.gemspec +24 -0
  61. data/lib/jquery-modal-rails.rb +3 -0
  62. data/lib/jquery/modal/filters.rb +9 -0
  63. data/lib/jquery/modal/filters/ajax_request_filters.rb +18 -0
  64. data/lib/jquery/modal/helpers.rb +9 -0
  65. data/lib/jquery/modal/helpers/link_helpers.rb +33 -0
  66. data/lib/jquery/modal/rails.rb +7 -0
  67. data/lib/jquery/modal/rails/engine.rb +8 -0
  68. data/lib/jquery/modal/rails/version.rb +8 -0
  69. data/vendor/assets/images/close.png +0 -0
  70. data/vendor/assets/images/spinner.gif +0 -0
  71. data/vendor/assets/javascripts/jquery.modal.js +265 -0
  72. data/vendor/assets/stylesheets/jquery.modal.css +45 -0
  73. metadata +189 -0
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/jquery/modal/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "jquery-modal-rails"
6
+ s.version = Jquery::Modal::Rails::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Dirk Eisenberg"]
9
+ s.email = ["dirk.eisenberg@gmail.com"]
10
+ s.homepage = "https://github.com/dei79/jquery-modal-rails"
11
+ s.summary = "The simplest possible modal for jQuery for the Rails 3.1+ asset pipeline"
12
+ s.description = "The simplest possible modal for jQuery for the Rails 3.1+ asset pipeline based on https://github.com/kylefox/jquery-modal."
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+
16
+ s.add_dependency "railties", ">= 3.2.0", "< 5.0"
17
+ s.add_dependency "thor", "~> 0.14"
18
+ s.add_dependency "jquery-ui-rails"
19
+ s.add_dependency "uuidtools"
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
23
+ s.require_path = 'lib'
24
+ end
@@ -0,0 +1,3 @@
1
+ require 'jquery/modal/rails'
2
+ require 'jquery/modal/filters'
3
+ require 'jquery/modal/helpers'
@@ -0,0 +1,9 @@
1
+ require 'jquery/modal/filters/ajax_request_filters'
2
+
3
+ module Jquery
4
+ module Filters
5
+ end
6
+ end
7
+
8
+
9
+ ActionController::Base.send :include, Jquery::Filters
@@ -0,0 +1,18 @@
1
+ module Jquery
2
+ module Filters
3
+
4
+ def self.included(base)
5
+
6
+ #
7
+ # This filter disables the layout for all AJAX requests so a formular in the dialog
8
+ # can be presentend in the layout of the master form
9
+ #
10
+ base.send :before_filter do |controller|
11
+ (controller.action_has_layout = false) if controller.request.xhr?
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+
18
+
@@ -0,0 +1,9 @@
1
+ require 'uuidtools'
2
+ require 'jquery/modal/helpers/link_helpers.rb'
3
+
4
+ module Jquery
5
+ module Helpers
6
+ end
7
+ end
8
+
9
+ ActionView::Base.send :include, Jquery::Helpers
@@ -0,0 +1,33 @@
1
+ module Jquery
2
+ module Helpers
3
+
4
+ # Creates a link tag to a given url or path and ensures that the linke will be rendered
5
+ # as jquery modal dialog
6
+ #
7
+ # ==== Signatures
8
+ #
9
+ # link_to(body, url, html_options = {})
10
+ # link_to(body, url)
11
+ #
12
+ def link_to_modal(body, url, html_options = {})
13
+ # extend the html_options
14
+ html_options[:rel] = "modal:open"
15
+ if (html_options.has_key?(:remote))
16
+ if (html_options[:remote] == true)
17
+ html_options[:rel] = "modal:open:ajaxpost"
18
+ end
19
+
20
+ # remove the remote tag
21
+ html_options.delete(:remote)
22
+ end
23
+ # check if we have an id
24
+ html_options[:id] = UUIDTools::UUID.random_create().to_s unless html_options.has_key?(:id)
25
+
26
+ # perform the normal link_to operation
27
+ html_link = link_to(body, url, html_options)
28
+
29
+ # emit both
30
+ html_link.html_safe
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ require 'jquery/modal/rails/engine'
2
+ require 'jquery/modal/rails/version'
3
+
4
+ module Jquery
5
+ module Rails
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module Jquery
2
+ module Modal
3
+ module Rails
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Jquery
2
+ module Modal
3
+ module Rails
4
+ VERSION = "0.0.1"
5
+ JQUERY_MODAL_VERSION = "0.5"
6
+ end
7
+ end
8
+ end
Binary file
Binary file
@@ -0,0 +1,265 @@
1
+ /*
2
+ A simple jQuery modal (http://github.com/kylefox/jquery-modal)
3
+ Version 0.5
4
+ */
5
+ (function($) {
6
+
7
+ var current = null;
8
+
9
+ $.modal = function(el, options) {
10
+ var remove, target;
11
+ this.$body = $('body');
12
+ this.options = $.extend({}, $.modal.defaults, options);
13
+ if (el.is('a')) {
14
+ target = el.attr('href');
15
+ //Select element by id from href
16
+ if (/^#/.test(target)) {
17
+ this.$elm = $(target);
18
+ if (this.$elm.length !== 1) return null;
19
+ this.open();
20
+ //AJAX
21
+ } else {
22
+ this.$elm = $('<div>');
23
+ this.$body.append(this.$elm);
24
+ remove = function(event, modal) { modal.elm.remove(); };
25
+ this.showSpinner();
26
+ el.trigger($.modal.AJAX_SEND);
27
+ $.get(target).done(function(html) {
28
+ if (!current) return;
29
+ el.trigger($.modal.AJAX_SUCCESS);
30
+ current.$elm.empty().append(html).on($.modal.CLOSE, remove);
31
+ current.hideSpinner();
32
+ current.open();
33
+ el.trigger($.modal.AJAX_COMPLETE);
34
+ }).fail(function() {
35
+ el.trigger($.modal.AJAX_FAIL);
36
+ current.hideSpinner();
37
+ el.trigger($.modal.AJAX_COMPLETE);
38
+ });
39
+ }
40
+ } else {
41
+ this.$elm = el;
42
+ this.open();
43
+ }
44
+ };
45
+
46
+ $.modal.prototype = {
47
+ constructor: $.modal,
48
+
49
+ open: function() {
50
+ this.block();
51
+ this.show();
52
+ if (this.options.escapeClose) {
53
+ $(document).on('keydown.modal', function(event) {
54
+ if (event.which == 27) $.modal.close();
55
+ });
56
+ }
57
+ if (this.options.clickClose) this.blocker.click($.modal.close);
58
+ },
59
+
60
+ close: function() {
61
+ this.unblock();
62
+ this.hide();
63
+ $(document).off('keydown.modal');
64
+ },
65
+
66
+ block: function() {
67
+ this.$elm.trigger($.modal.BEFORE_BLOCK, [this._ctx()]);
68
+ this.blocker = $('<div class="jquery-modal blocker"></div>').css({
69
+ top: 0, right: 0, bottom: 0, left: 0,
70
+ width: "100%", height: "100%",
71
+ position: "fixed",
72
+ zIndex: this.options.zIndex,
73
+ background: this.options.overlay,
74
+ opacity: this.options.opacity
75
+ });
76
+ this.$body.append(this.blocker);
77
+ this.$elm.trigger($.modal.BLOCK, [this._ctx()]);
78
+ },
79
+
80
+ unblock: function() {
81
+ this.blocker.remove();
82
+ },
83
+
84
+ show: function() {
85
+ this.$elm.trigger($.modal.BEFORE_OPEN, [this._ctx()]);
86
+ if (this.options.showClose) {
87
+ this.closeButton = $('<a href="#close-modal" rel="modal:close" class="close-modal">' + this.options.closeText + '</a>');
88
+ this.$elm.append(this.closeButton);
89
+ }
90
+ this.$elm.addClass(this.options.modalClass + ' current');
91
+ this.center();
92
+ this.$elm.show().trigger($.modal.OPEN, [this._ctx()]);
93
+ },
94
+
95
+ hide: function() {
96
+ this.$elm.trigger($.modal.BEFORE_CLOSE, [this._ctx()]);
97
+ if (this.closeButton) this.closeButton.remove();
98
+ this.$elm.removeClass('current').hide();
99
+ this.$elm.trigger($.modal.CLOSE, [this._ctx()]);
100
+ },
101
+
102
+ showSpinner: function() {
103
+ if (!this.options.showSpinner) return;
104
+ this.spinner = this.spinner || $('<div class="' + this.options.modalClass + '-spinner"></div>')
105
+ .append(this.options.spinnerHtml);
106
+ this.$body.append(this.spinner);
107
+ this.spinner.show();
108
+ },
109
+
110
+ hideSpinner: function() {
111
+ if (this.spinner) this.spinner.remove();
112
+ },
113
+
114
+ center: function() {
115
+ this.$elm.css({
116
+ position: 'fixed',
117
+ top: "50%",
118
+ left: "50%",
119
+ marginTop: - (this.$elm.outerHeight() / 2),
120
+ marginLeft: - (this.$elm.outerWidth() / 2),
121
+ zIndex: this.options.zIndex + 1
122
+ });
123
+ },
124
+
125
+ //Return context for custom events
126
+ _ctx: function() {
127
+ return { elm: this.$elm, blocker: this.blocker, options: this.options };
128
+ }
129
+ };
130
+
131
+ //resize is alias for center for now
132
+ $.modal.prototype.resize = $.modal.prototype.center;
133
+
134
+ $.modal.close = function(event) {
135
+ if (!current) return;
136
+ if (event) event.preventDefault();
137
+ current.close();
138
+ current = null;
139
+ };
140
+
141
+ $.modal.showSpinner = function(event) {
142
+ if (!current) return;
143
+ if (event) event.preventDefault();
144
+ current.showSpinner();
145
+ }
146
+
147
+ $.modal.hideSpinner = function(event) {
148
+ if (!current) return;
149
+ if (event) event.preventDefault();
150
+ current.hideSpinner();
151
+ }
152
+
153
+ $.modal.getWidget = function() {
154
+ if (!current)
155
+ return null;
156
+ else
157
+ return current.$elm;
158
+ }
159
+
160
+ $.modal.resize = function() {
161
+ if (!current) return;
162
+ current.resize();
163
+ };
164
+
165
+ $.modal.defaults = {
166
+ overlay: "#000",
167
+ opacity: 0.75,
168
+ zIndex: 1,
169
+ escapeClose: true,
170
+ clickClose: true,
171
+ closeText: 'Close',
172
+ modalClass: "modal",
173
+ spinnerHtml: null,
174
+ showSpinner: true,
175
+ showClose: true
176
+ };
177
+
178
+ // Event constants
179
+ $.modal.BEFORE_BLOCK = 'modal:before-block';
180
+ $.modal.BLOCK = 'modal:block';
181
+ $.modal.BEFORE_OPEN = 'modal:before-open';
182
+ $.modal.OPEN = 'modal:open';
183
+ $.modal.BEFORE_CLOSE = 'modal:before-close';
184
+ $.modal.CLOSE = 'modal:close';
185
+ $.modal.AJAX_SEND = 'modal:ajax:send';
186
+ $.modal.AJAX_SUCCESS = 'modal:ajax:success';
187
+ $.modal.AJAX_FAIL = 'modal:ajax:fail';
188
+ $.modal.AJAX_COMPLETE = 'modal:ajax:complete';
189
+
190
+ $.fn.modal = function(options){
191
+ if (this.length === 1) {
192
+ current = new $.modal(this, options);
193
+ }
194
+ return this;
195
+ };
196
+
197
+ // Automatically bind links with rel="modal:close" to, well, close the modal.
198
+ $(document).on('click', 'a[rel="modal:close"]', $.modal.close);
199
+ $(document).on('click', 'a[rel="modal:open"]', function(event) {
200
+ event.preventDefault();
201
+ $(this).modal();
202
+ });
203
+
204
+ // Automatically bind links with rel="modal:open:ajaxpost" to
205
+ $(document).on('click', 'a[rel="modal:open:ajaxpost"]', function(event)
206
+ {
207
+ //ensure that our custom events will be received
208
+ event.preventDefault();
209
+
210
+ // show the dialog
211
+ $(this).modal();
212
+
213
+ // bind the event when the ajax call is completed
214
+ $(this).bind($.modal.AJAX_COMPLETE, function() {
215
+ // configure the submit handler
216
+ $('form').submit(function(){
217
+
218
+ // save the current form
219
+ current_form = $(this);
220
+
221
+ // show the spinner again
222
+ $.modal.showSpinner();
223
+
224
+ // send the ajax call
225
+ $.ajax({
226
+ type: this.method,
227
+ url: this.action + '.json',
228
+ data: $(this).serialize(),
229
+ dataType: 'html',
230
+ success: function(data)
231
+ {
232
+ // hide the sinner
233
+ $.modal.hideSpinner();
234
+
235
+ // close the dialog
236
+ $.modal.close();
237
+ },
238
+ error: function(data)
239
+ {
240
+ // hide the sinner
241
+ $.modal.hideSpinner();
242
+
243
+ // remove the older error message
244
+ current_form.find(".error").remove()
245
+
246
+ // parse the result
247
+ var obj = jQuery.parseJSON(data.responseText);
248
+
249
+ $.each(obj.errors, function(key, value)
250
+ {
251
+
252
+ current_form.find("#"+ current_form.attr("id").split('_').pop()+ "_" + key).after('<span class="error">'+ value[0] + '</span>');
253
+ });
254
+ }
255
+ });
256
+ return false;
257
+ });
258
+ });
259
+
260
+
261
+ // return false to prevent normal anchor action
262
+ return false;
263
+ });
264
+
265
+ })(jQuery);
@@ -0,0 +1,45 @@
1
+ .modal {
2
+ display: none;
3
+ width: 400px;
4
+ background: #fff;
5
+ padding: 15px 30px;
6
+ -webkit-border-radius: 8px;
7
+ -moz-border-radius: 8px;
8
+ -o-border-radius: 8px;
9
+ -ms-border-radius: 8px;
10
+ border-radius: 8px;
11
+ -webkit-box-shadow: 0 0 10px #000;
12
+ -moz-box-shadow: 0 0 10px #000;
13
+ -o-box-shadow: 0 0 10px #000;
14
+ -ms-box-shadow: 0 0 10px #000;
15
+ box-shadow: 0 0 10px #000;
16
+ }
17
+
18
+ .modal a.close-modal {
19
+ position: absolute;
20
+ top: -12.5px;
21
+ right: -12.5px;
22
+ display: block;
23
+ width: 30px;
24
+ height: 30px;
25
+ text-indent: -9999px;
26
+ background: url(close.png) no-repeat 0 0;
27
+ }
28
+
29
+ .modal-spinner {
30
+ display: none;
31
+ width: 64px;
32
+ height: 64px;
33
+ position: fixed;
34
+ top: 50%;
35
+ left: 50%;
36
+ margin-right: -32px;
37
+ margin-top: -32px;
38
+ background: url(spinner.gif) #111 no-repeat center center;
39
+ -webkit-border-radius: 8px;
40
+ -moz-border-radius: 8px;
41
+ -o-border-radius: 8px;
42
+ -ms-border-radius: 8px;
43
+ border-radius: 8px;
44
+ z-index: 9999;
45
+ }