evil-blocks-rails 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.4.1 (Yoke, 30th April 1948)
2
+ * Allow to listen body and window events from object style.
3
+
1
4
  == 0.4 (X-Ray, 14th April 1948)
2
5
  * Add new object style.
3
6
 
@@ -109,6 +109,27 @@
109
109
  }
110
110
  };
111
111
 
112
+ /**
113
+ * Create callback wrapper for block listener.
114
+ */
115
+ var blockCallback = function (self, func) {
116
+ return function () {
117
+ func.apply(self, arguments);
118
+ }
119
+ };
120
+
121
+ /**
122
+ * Create callback wrapper for element listener.
123
+ */
124
+ var elemCallback = function (self, func) {
125
+ return function () {
126
+ var args = Array.prototype.slice.call(arguments);
127
+ var el = $(this);
128
+ args.unshift(el);
129
+ func.apply(self, args);
130
+ }
131
+ };
132
+
112
133
  /**
113
134
  * Convert block class to callback.
114
135
  */
@@ -116,26 +137,30 @@
116
137
  return function ($, obj, block) {
117
138
  obj.block = block;
118
139
 
119
- for ( var prop in klass ) {
120
- (function (prop) {
121
- if ( prop.indexOf('on ') != -1 ) {
122
- var parts = prop.split(' on ');
123
- if ( parts[1] ) {
124
- block.on(parts[0], parts[1], function () {
125
- var arg = Array.prototype.slice.call(arguments);
126
- var el = $(this);
127
- arg.unshift(el);
128
- klass[prop].apply(obj, arg);
129
- });
130
- } else {
131
- block.on(parts[0], function () {
132
- klass[prop].apply(obj, arguments);
133
- });
134
- }
140
+ for ( var name in klass ) {
141
+ var prop = klass[name];
142
+
143
+ (function (name, prop) {
144
+ if ( name.indexOf('on ') == -1 ) {
145
+ obj[name] = prop;
146
+ return;
147
+ }
148
+
149
+ var parts = name.split(' on ');
150
+
151
+ if ( parts[1] == 'body' ) {
152
+ $('body').on(parts[0], blockCallback(obj, prop));
153
+
154
+ } else if ( parts[1] == 'window' ) {
155
+ $(window).on(parts[0], blockCallback(obj, prop));
156
+
157
+ } else if ( parts[1] ) {
158
+ block.on(parts[0], parts[1], elemCallback(obj, prop));
159
+
135
160
  } else {
136
- obj[prop] = klass[prop];
161
+ block.on(parts[0], blockCallback(obj, prop));
137
162
  }
138
- })(prop);
163
+ })(name, prop);
139
164
  }
140
165
 
141
166
  if ( typeof(obj.init) == 'function' ) {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evil-blocks-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
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-09-09 00:00:00.000000000 Z
12
+ date: 2013-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets