bhf 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,160 @@
1
+ /*
2
+ ---
3
+ description: A MooTools driver for the Ruby on Rails 3 unobtrusive JavaScript API.
4
+
5
+ license: MIT-style
6
+
7
+ authors:
8
+ - Kevin Valdek
9
+ - Oskar Krawczyk
10
+
11
+ requires:
12
+ core/1.4: '*'
13
+
14
+ provides:
15
+ - Rails 3 MooTools driver
16
+
17
+ ...
18
+ */
19
+
20
+ window.addEvent('domready', function(){
21
+
22
+ rails.csrf = {
23
+ token: rails.getCsrf('token'),
24
+ param: rails.getCsrf('param')
25
+ };
26
+
27
+ rails.applyEvents();
28
+ });
29
+
30
+ (function($){
31
+
32
+ window.rails = {
33
+ /**
34
+ * If el is passed as argument, events will only be applied to
35
+ * elements within el. Otherwise applied to document body.
36
+ */
37
+ applyEvents: function(el){
38
+ el = $(el || document.body);
39
+ var apply = function(selector, action, callback){
40
+ el.addEvent(action + ':relay(' + selector + ')', callback);
41
+ };
42
+
43
+ apply('form[data-remote="true"]', 'submit', rails.handleRemote);
44
+ apply('a[data-remote="true"], input[data-remote="true"]', 'click', rails.handleRemote);
45
+ apply('a[data-method][data-remote!=true]', 'click', function(event){
46
+ event.preventDefault();
47
+ if (rails.confirmed(this)){
48
+ var form = Element('form', {
49
+ method: 'post',
50
+ action: this.get('href'),
51
+ styles: {
52
+ display: 'none'
53
+ }
54
+ }).inject(this, 'after');
55
+
56
+ var methodInput = Element('input', {
57
+ type: 'hidden',
58
+ name: '_method',
59
+ value: this.get('data-method')
60
+ });
61
+
62
+ var csrfInput = Element('input', {
63
+ type: 'hidden',
64
+ name: rails.csrf.param,
65
+ value: rails.csrf.token
66
+ });
67
+
68
+ form.adopt(methodInput, csrfInput).submit();
69
+ }
70
+ });
71
+ var noMethodNorRemoteConfirm = ':not([data-method]):not([data-remote=true])[data-confirm]';
72
+ apply('a' + noMethodNorRemoteConfirm + ',' + 'input' + noMethodNorRemoteConfirm, 'click', function(){
73
+ return rails.confirmed(this);
74
+ });
75
+ },
76
+
77
+ getCsrf: function(name){
78
+ var meta = document.getElement('meta[name=csrf-' + name + ']');
79
+ return (meta ? meta.get('content') : null);
80
+ },
81
+
82
+ confirmed: function(el){
83
+ var confirmMessage = el.get('data-confirm');
84
+ if(confirmMessage && !confirm(confirmMessage)){
85
+ return false;
86
+ }
87
+ return true;
88
+ },
89
+
90
+ disable: function(el){
91
+ var button = el.get('data-disable-with') ? el : el.getElement('[data-disable-with]');
92
+ if (button){
93
+ var enableWith = button.get('value');
94
+ el.addEvent('ajax:complete', function(){
95
+ button.set({
96
+ value: enableWith,
97
+ disabled: false
98
+ });
99
+ });
100
+ button.set({
101
+ value: button.get('data-disable-with'),
102
+ disabled: true
103
+ });
104
+ }
105
+ },
106
+
107
+ handleRemote: function(event){
108
+ event.preventDefault();
109
+ if(rails.confirmed(this)){
110
+ this.request = new Request.Rails(this);
111
+ rails.disable(this);
112
+ this.request.send();
113
+ }
114
+ }
115
+ };
116
+
117
+ Request.Rails = new Class({
118
+
119
+ Extends: Request,
120
+
121
+ initialize: function(element, options){
122
+ this.el = element;
123
+ this.parent(Object.merge({
124
+ method: this.el.get('method') || this.el.get('data-method') || 'get',
125
+ url: this.el.get('action') || this.el.get('href')
126
+ }, options));
127
+ this.addRailsEvents();
128
+ },
129
+
130
+ send: function(options) {
131
+ this.el.fireEvent('ajax:before');
132
+ if (this.el.get('tag') === 'form'){
133
+ this.options.data = this.el;
134
+ }
135
+ this.parent(options);
136
+ this.el.fireEvent('ajax:after', this.xhr);
137
+ },
138
+
139
+ addRailsEvents: function(){
140
+ this.addEvent('request', function(){
141
+ this.el.fireEvent('ajax:loading', this.xhr);
142
+ });
143
+
144
+ this.addEvent('success', function(){
145
+ this.el.fireEvent('ajax:success', this.xhr);
146
+ });
147
+
148
+ this.addEvent('complete', function(){
149
+ this.el.fireEvent('ajax:complete', this.xhr);
150
+ this.el.fireEvent('ajax:loaded', this.xhr);
151
+ });
152
+
153
+ this.addEvent('failure', function(){
154
+ this.el.fireEvent('ajax:failure', this.xhr);
155
+ });
156
+ }
157
+
158
+ });
159
+
160
+ })(document.id);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bhf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-01 00:00:00.000000000 Z
12
+ date: 2013-08-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -191,7 +191,9 @@ files:
191
191
  - vendor/assets/javascripts/bhf/classes/Setlatlng.js
192
192
  - vendor/assets/javascripts/bhf/classes/showdown.js
193
193
  - vendor/assets/javascripts/bhf/classes/wmd.js
194
+ - vendor/assets/javascripts/bhf/mootools-compat.js
194
195
  - vendor/assets/javascripts/bhf/mootools-more-1.4.0.1.js
196
+ - vendor/assets/javascripts/bhf/mootools_ujs_ap.js
195
197
  - vendor/assets/stylesheets/bhf/MooEditable.css.scss
196
198
  - vendor/assets/stylesheets/bhf/application.css.sass
197
199
  - vendor/assets/stylesheets/bhf/functions.css.sass