pagehook-rails 0.0.3 → 0.0.4

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: 9d75e3e175c46f74f0ee38bc881535d9854f981c
4
- data.tar.gz: ef62bd763d803d5efecc494b3e19dd2529f0d659
3
+ metadata.gz: 9e7f5e0498a166424911b6cc6521a1ddc8e74b65
4
+ data.tar.gz: dc2c04751acdbdf7e8a875cd44d09bad38580776
5
5
  SHA512:
6
- metadata.gz: cb62ed1eee09fd03f669d2c74cc101be7e7efadb92015a2691748e1a4e93b7a01fea35440d10cac0b6f7de06c34cd2c7607a7bce57d89255519ae26f5ed081bd
7
- data.tar.gz: 655f5c0452530a5774eb286d7939c02e6bc733274a7a812c8f07c8fb0cb755f7990bd1f2818fcda8115b173928a2f3ee195bceb40c18719c871c3c24f9e41f8f
6
+ metadata.gz: 3919d557ac9c8c2472e286f53c91424ca4492da202e6c1546b7535e7fe9fa9947aff35ce72e1d6de2c7804c91d0f903fc7b64af0b535546168d7d32733ac6af4
7
+ data.tar.gz: 208d4bedfacb0c58e940f3e5bb87040c95d55e51a9742fd4ec63e5e82fb491adf53edc3ceb1d096b5f11d017e05bc0f93a5650625c04f905c4827fc6bc627843
@@ -1,84 +1,82 @@
1
- (function() {
2
- var Pagehook,
3
- __slice = [].slice;
1
+ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.Pagehook=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
+ "use strict";
4
3
 
5
- this.Pagehook = Pagehook = (function() {
6
- Pagehook.GLOBAL_HOOK_NAME = "@global";
4
+ // constructor
5
+ var Pagehook = function() {
6
+ this.definitions = {};
7
+ this.handler = this.handlerUnbound.bind(this);
8
+ };
7
9
 
8
- Pagehook.ATTRIBUTE_NAME = "data-pagehook";
10
+ // constant
11
+ Pagehook.GLOBAL_HOOK_NAME = "@global";
12
+ Pagehook.ATTRIBUTE_NAME = "data-pagehook";
9
13
 
10
- Pagehook.register = function() {
11
- var args, _ref;
12
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
13
- return (_ref = this.instance).register.apply(_ref, args);
14
- };
14
+ // static methods
15
+ Pagehook.register = function(name_or_map, func) {
16
+ this.instance.register(name_or_map, func);
17
+ };
15
18
 
16
- Pagehook.dispatch = function() {
17
- var args, _ref;
18
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
19
- return (_ref = this.instance).dispatch.apply(_ref, args);
20
- };
19
+ Pagehook.dispatch = function(name, arg) {
20
+ this.instance.dispatch(name, arg);
21
+ };
21
22
 
22
- function Pagehook() {
23
- this.definitions = {};
24
- this.handler = (function(_this) {
25
- return function() {
26
- return _this.handlerUnbound();
27
- };
28
- })(this);
29
- }
23
+ // Pagehook.register "name", (arg)-> ...
24
+ // // or
25
+ // Pagehoook.register
26
+ // name: (arg)->
27
+ Pagehook.prototype.register = function(name_or_map, func) {
28
+ var name;
30
29
 
31
- Pagehook.prototype.register = function(name_or_map, func) {
32
- var name, _base, _results;
33
- if (typeof name_or_map === "string") {
34
- return ((_base = this.definitions)[name_or_map] || (_base[name_or_map] = [])).push(func);
35
- } else {
36
- _results = [];
37
- for (name in name_or_map) {
38
- func = name_or_map[name];
39
- _results.push(this.register(name, func));
40
- }
41
- return _results;
42
- }
43
- };
30
+ if (typeof(name_or_map) === "string") {
31
+ if (!this.definitions[name_or_map]) {
32
+ this.definitions[name_or_map] = [];
33
+ }
34
+ this.definitions[name_or_map].push(func);
35
+ } else {
36
+ for (name in name_or_map) {
37
+ this.register(name, name_or_map[name]);
38
+ }
39
+ }
40
+ };
44
41
 
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));
53
- }
54
- return _results;
55
- }
56
- };
42
+ // Pagehook.dispatch("name", {foo: 1, bar: 2})
43
+ Pagehook.prototype.dispatch = function(name, arg) {
44
+ if (this.definitions[name]) {
45
+ this.definitions[name].forEach(function(func) {
46
+ func(arg);
47
+ });
48
+ } else {
49
+ if (name !== Pagehook.GLOBAL_HOOK_NAME) {
50
+ console.log("Pagehook for " + name + " is undefined");
51
+ }
52
+ }
53
+ };
57
54
 
58
- Pagehook.prototype.handlerUnbound = function() {
59
- var arg, e, name, _i, _len, _ref, _results;
60
- this.dispatch(Pagehook.GLOBAL_HOOK_NAME);
61
- _ref = document.querySelectorAll("[" + Pagehook.ATTRIBUTE_NAME + "]");
62
- _results = [];
63
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
64
- e = _ref[_i];
65
- name = e.getAttribute(Pagehook.ATTRIBUTE_NAME);
66
- arg = this.isBlank(e.textContent) ? void 0 : JSON.parse(e.textContent);
67
- _results.push(this.dispatch(name, arg));
68
- }
69
- return _results;
70
- };
55
+ // Event handler for DOMContentLoaded or page:change (turbolinks)
56
+ // Use `handler` property instead of this
57
+ Pagehook.prototype.handlerUnbound = function() {
58
+ var elements, i, e, name, arg;
71
59
 
72
- Pagehook.prototype.isBlank = function(string) {
73
- return !!(string.match(/^\s*$/));
74
- };
60
+ this.dispatch(Pagehook.GLOBAL_HOOK_NAME);
75
61
 
76
- return Pagehook;
62
+ elements = document.querySelectorAll("[" + Pagehook.ATTRIBUTE_NAME + "]");
63
+ for (i = 0; i < elements.length; i++) {
64
+ e = elements[i];
65
+ name = e.getAttribute(Pagehook.ATTRIBUTE_NAME);
66
+ arg = this.isBlank(e.textContent) ? undefined : JSON.parse(e.textContent);
67
+ this.dispatch(name, arg);
68
+ }
69
+ };
77
70
 
78
- })();
71
+ Pagehook.prototype.isBlank = function(string) {
72
+ return !!(string.match(/^\s*$/));
73
+ };
79
74
 
80
- this.Pagehook.instance = new Pagehook();
75
+ // instanciate singleton object
76
+ Pagehook.instance = new Pagehook();
77
+ Pagehook.handler = Pagehook.instance.handler;
81
78
 
82
- this.Pagehook.handler = this.Pagehook.instance.handler;
79
+ module.exports = Pagehook;
83
80
 
84
- }).call(this);
81
+ },{}]},{},[1])(1)
82
+ });
@@ -1,3 +1,3 @@
1
1
  module PagehookRails
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - labocho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-04 00:00:00.000000000 Z
11
+ date: 2014-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  requirements: []
108
108
  rubyforge_project:
109
- rubygems_version: 2.2.0
109
+ rubygems_version: 2.2.2
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Rails plugin integrates Pagehook (https://github.com/labocho/pagehook)