gon 4.0.1 → 4.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.
Potentially problematic release.
This version of gon might be problematic. Click here for more details.
- data/CHANGELOG.md +4 -0
- data/README.md +1 -2
- data/js/watch.js +62 -0
- data/lib/gon/version.rb +1 -1
- data/lib/gon/watch.rb +2 -64
- metadata +3 -2
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
3
|

|
4
4
|
|
5
|
-
|
6
|
-
### Build Status 
|
5
|
+
### Build Status [](http://travis-ci.org/gazay/gon)
|
7
6
|
|
8
7
|
If you need to send some data to your js files and you don't want to do this with long way through views and parsing - use this force!
|
9
8
|
|
data/js/watch.js
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
gon._timers = {};
|
2
|
+
|
3
|
+
gon.watch = function(name, possibleOptions, possibleCallback) {
|
4
|
+
var callback, key, options, performAjax, timer, value, _base, _ref, _ref1;
|
5
|
+
if (typeof $ === 'undefined' || $ === null) {
|
6
|
+
return;
|
7
|
+
}
|
8
|
+
if (typeof possibleOptions === 'object') {
|
9
|
+
options = {};
|
10
|
+
_ref = gon.watchedVariables[name];
|
11
|
+
for (key in _ref) {
|
12
|
+
value = _ref[key];
|
13
|
+
options[key] = value;
|
14
|
+
}
|
15
|
+
for (key in possibleOptions) {
|
16
|
+
value = possibleOptions[key];
|
17
|
+
options[key] = value;
|
18
|
+
}
|
19
|
+
callback = possibleCallback;
|
20
|
+
} else {
|
21
|
+
options = gon.watchedVariables[name];
|
22
|
+
callback = possibleOptions;
|
23
|
+
}
|
24
|
+
performAjax = function() {
|
25
|
+
var xhr;
|
26
|
+
xhr = $.ajax({
|
27
|
+
type: options.type || 'GET',
|
28
|
+
url: options.url,
|
29
|
+
data: {
|
30
|
+
_method: options.method,
|
31
|
+
gon_return_variable: true,
|
32
|
+
gon_watched_variable: name
|
33
|
+
}
|
34
|
+
});
|
35
|
+
return xhr.done(callback);
|
36
|
+
};
|
37
|
+
if (options.interval) {
|
38
|
+
timer = setInterval(performAjax, options.interval);
|
39
|
+
if ((_ref1 = (_base = gon._timers)[name]) == null) {
|
40
|
+
_base[name] = [];
|
41
|
+
}
|
42
|
+
return gon._timers[name].push({
|
43
|
+
timer: timer,
|
44
|
+
fn: callback
|
45
|
+
});
|
46
|
+
} else {
|
47
|
+
return performAjax();
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
gon.unwatch = function(name, fn) {
|
52
|
+
var index, timer, _i, _len, _ref;
|
53
|
+
_ref = gon._timers[name];
|
54
|
+
for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
|
55
|
+
timer = _ref[index];
|
56
|
+
if (timer.fn === fn) {
|
57
|
+
clearInterval(timer.timer);
|
58
|
+
gon._timers[name].splice(index, 1);
|
59
|
+
return;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
};
|
data/lib/gon/version.rb
CHANGED
data/lib/gon/watch.rb
CHANGED
@@ -2,69 +2,7 @@ class Gon
|
|
2
2
|
class Watch < Gon
|
3
3
|
class << self
|
4
4
|
|
5
|
-
JS_FUNCTION =
|
6
|
-
"gon._timers = {};
|
7
|
-
|
8
|
-
gon.watch = function(name, possibleOptions, possibleCallback) {
|
9
|
-
var callback, key, options, performAjax, timer, value, _base, _ref, _ref1;
|
10
|
-
if (typeof $ === 'undefined' || $ === null) {
|
11
|
-
return;
|
12
|
-
}
|
13
|
-
if (typeof possibleOptions === 'object') {
|
14
|
-
options = {};
|
15
|
-
_ref = gon.watchedVariables[name];
|
16
|
-
for (key in _ref) {
|
17
|
-
value = _ref[key];
|
18
|
-
options[key] = value;
|
19
|
-
}
|
20
|
-
for (key in possibleOptions) {
|
21
|
-
value = possibleOptions[key];
|
22
|
-
options[key] = value;
|
23
|
-
}
|
24
|
-
callback = possibleCallback;
|
25
|
-
} else {
|
26
|
-
options = gon.watchedVariables[name];
|
27
|
-
callback = possibleOptions;
|
28
|
-
}
|
29
|
-
performAjax = function() {
|
30
|
-
var xhr;
|
31
|
-
xhr = $.ajax({
|
32
|
-
type: options.type || 'GET',
|
33
|
-
url: options.url,
|
34
|
-
data: {
|
35
|
-
_method: options.method,
|
36
|
-
gon_return_variable: true,
|
37
|
-
gon_watched_variable: name
|
38
|
-
}
|
39
|
-
});
|
40
|
-
return xhr.done(callback);
|
41
|
-
};
|
42
|
-
if (options.interval) {
|
43
|
-
timer = setInterval(performAjax, options.interval);
|
44
|
-
if ((_ref1 = (_base = gon._timers)[name]) == null) {
|
45
|
-
_base[name] = [];
|
46
|
-
}
|
47
|
-
return gon._timers[name].push({
|
48
|
-
timer: timer,
|
49
|
-
fn: callback
|
50
|
-
});
|
51
|
-
} else {
|
52
|
-
return performAjax;
|
53
|
-
}
|
54
|
-
};
|
55
|
-
|
56
|
-
gon.unwatch = function(name, fn) {
|
57
|
-
var index, timer, _i, _len, _ref;
|
58
|
-
_ref = gon._timers[name];
|
59
|
-
for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
|
60
|
-
timer = _ref[index];
|
61
|
-
if (timer.fn === fn) {
|
62
|
-
clearInterval(timer.timer);
|
63
|
-
gon._timers[name].splice(index, 1);
|
64
|
-
return;
|
65
|
-
}
|
66
|
-
}
|
67
|
-
};"
|
5
|
+
JS_FUNCTION = File.read(File.expand_path('../../../js/watch.js', __FILE__))
|
68
6
|
|
69
7
|
def render
|
70
8
|
JS_FUNCTION + "window.gon.watchedVariables=#{all_variables.to_json};"
|
@@ -87,7 +25,7 @@ class Gon
|
|
87
25
|
variable = {}
|
88
26
|
@watch_variables ||= {}
|
89
27
|
env = Gon::Request.env
|
90
|
-
variable['url'] = env['ORIGINAL_FULLPATH']
|
28
|
+
variable['url'] = env['ORIGINAL_FULLPATH'] || env['REQUEST_URI']
|
91
29
|
variable['method'] = env['REQUEST_METHOD']
|
92
30
|
variable['name'] = name
|
93
31
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.2
|
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: 2012-
|
12
|
+
date: 2012-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- doc/logo_small.png
|
127
127
|
- doc/top_sample.png
|
128
128
|
- gon.gemspec
|
129
|
+
- js/watch.js
|
129
130
|
- lib/gon.rb
|
130
131
|
- lib/gon/base.rb
|
131
132
|
- lib/gon/escaper.rb
|