pagehook-rails 0.0.1 → 0.0.2

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: f1fb9f17ca1a217f7f7d7d2a0aca524fb4a05773
4
- data.tar.gz: 032173384668bb9ed8e87411f4db844009066663
3
+ metadata.gz: cb52eecc763ca2f4c570e6e5c1c728dc71730bd4
4
+ data.tar.gz: 35708ed0d651329f25487a9d3e727fccc98b6ea6
5
5
  SHA512:
6
- metadata.gz: e996a512a9d6e966416ef19ef3f088afac00a3d75aa48958080eb36c9b5bb2235790515373741165360ec6d40c8e70aa2c8fcbfb61ed68d84cdbed2575be045a
7
- data.tar.gz: 66bae609658cc2f0d74684c635de547750c66719fabf3d02026b84e8c3f06bfbccb39d21c4077fb22498c310a5862fe44e4be4323e726ac7c3ccfcb5b82aaeb8
6
+ metadata.gz: 3234581d1807f6f1d06127c0337b5fea2836243e524230384bbd2a19d9b2199b265b5a956c90593127ef4ccfbcedda731b664bc0ff175cea0df27689c550fb14
7
+ data.tar.gz: d0893e20e2b052e632aa9c5fa5ee3207b0d0fbd0d943f058960a334e89138e07a2025a12286a55880f035eca7434de46737767d7cde296ade726c7be7a32f6e7
@@ -20,7 +20,7 @@
20
20
  };
21
21
 
22
22
  function Pagehook() {
23
- this.definitions = [];
23
+ this.definitions = {};
24
24
  this.handler = (function(_this) {
25
25
  return function() {
26
26
  return _this.handlerUnbound();
@@ -29,44 +29,42 @@
29
29
  }
30
30
 
31
31
  Pagehook.prototype.register = function(name_or_map, func) {
32
- var name, _results;
32
+ var name, _base, _results;
33
33
  if (typeof name_or_map === "string") {
34
- return this.definitions.push([name_or_map, func]);
34
+ return ((_base = this.definitions)[name_or_map] || (_base[name_or_map] = [])).push(func);
35
35
  } else {
36
36
  _results = [];
37
37
  for (name in name_or_map) {
38
38
  func = name_or_map[name];
39
- _results.push(this.definitions.push([name, func]));
39
+ _results.push(this.register(name, func));
40
40
  }
41
41
  return _results;
42
42
  }
43
43
  };
44
44
 
45
- Pagehook.prototype.dispatch = function(name, params) {
46
- var func, registered, _i, _len, _ref, _ref1, _results;
47
- _ref = this.definitions;
48
- _results = [];
49
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
50
- _ref1 = _ref[_i], registered = _ref1[0], func = _ref1[1];
51
- if (registered === name) {
52
- _results.push(func(params));
53
- } else {
54
- _results.push(void 0);
45
+ Pagehook.prototype.dispatch = function(name, arg) {
46
+ var func, _i, _len, _ref, _results;
47
+ if (this.definitions[name]) {
48
+ _ref = this.definitions[name];
49
+ _results = [];
50
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
51
+ func = _ref[_i];
52
+ _results.push(func(arg));
55
53
  }
54
+ return _results;
56
55
  }
57
- return _results;
58
56
  };
59
57
 
60
58
  Pagehook.prototype.handlerUnbound = function() {
61
- var args, e, name, _i, _len, _ref, _results;
59
+ var arg, e, name, _i, _len, _ref, _results;
62
60
  this.dispatch(Pagehook.GLOBAL_HOOK_NAME);
63
61
  _ref = document.querySelectorAll("[" + Pagehook.ATTRIBUTE_NAME + "]");
64
62
  _results = [];
65
63
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
66
64
  e = _ref[_i];
67
65
  name = e.getAttribute(Pagehook.ATTRIBUTE_NAME);
68
- args = this.isBlank(e.textContent) ? void 0 : JSON.parse(e.textContent);
69
- _results.push(this.dispatch(name, args));
66
+ arg = this.isBlank(e.textContent) ? void 0 : JSON.parse(e.textContent);
67
+ _results.push(this.dispatch(name, arg));
70
68
  }
71
69
  return _results;
72
70
  };
@@ -1,3 +1,3 @@
1
1
  module PagehookRails
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagehook-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - labocho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-29 00:00:00.000000000 Z
11
+ date: 2014-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails