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 +4 -4
- data/app/assets/javascripts/pagehook_rails/pagehook.js +68 -70
- data/lib/pagehook-rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9e7f5e0498a166424911b6cc6521a1ddc8e74b65
|
|
4
|
+
data.tar.gz: dc2c04751acdbdf7e8a875cd44d09bad38580776
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3919d557ac9c8c2472e286f53c91424ca4492da202e6c1546b7535e7fe9fa9947aff35ce72e1d6de2c7804c91d0f903fc7b64af0b535546168d7d32733ac6af4
|
|
7
|
+
data.tar.gz: 208d4bedfacb0c58e940f3e5bb87040c95d55e51a9742fd4ec63e5e82fb491adf53edc3ceb1d096b5f11d017e05bc0f93a5650625c04f905c4827fc6bc627843
|
|
@@ -1,84 +1,82 @@
|
|
|
1
|
-
(function() {
|
|
2
|
-
|
|
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
|
-
|
|
6
|
-
|
|
4
|
+
// constructor
|
|
5
|
+
var Pagehook = function() {
|
|
6
|
+
this.definitions = {};
|
|
7
|
+
this.handler = this.handlerUnbound.bind(this);
|
|
8
|
+
};
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
// constant
|
|
11
|
+
Pagehook.GLOBAL_HOOK_NAME = "@global";
|
|
12
|
+
Pagehook.ATTRIBUTE_NAME = "data-pagehook";
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
14
|
+
// static methods
|
|
15
|
+
Pagehook.register = function(name_or_map, func) {
|
|
16
|
+
this.instance.register(name_or_map, func);
|
|
17
|
+
};
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
73
|
-
return !!(string.match(/^\s*$/));
|
|
74
|
-
};
|
|
60
|
+
this.dispatch(Pagehook.GLOBAL_HOOK_NAME);
|
|
75
61
|
|
|
76
|
-
|
|
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
|
-
|
|
75
|
+
// instanciate singleton object
|
|
76
|
+
Pagehook.instance = new Pagehook();
|
|
77
|
+
Pagehook.handler = Pagehook.instance.handler;
|
|
81
78
|
|
|
82
|
-
|
|
79
|
+
module.exports = Pagehook;
|
|
83
80
|
|
|
84
|
-
})
|
|
81
|
+
},{}]},{},[1])(1)
|
|
82
|
+
});
|
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.
|
|
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-
|
|
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.
|
|
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)
|