honkster-jelly 0.6.7 → 0.7.0
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.
- data/VERSION.yml +2 -2
- data/generators/jelly/templates/javascripts/jelly.js +55 -35
- data/lib/jelly/jelly_helper.rb +2 -2
- metadata +1 -1
data/VERSION.yml
CHANGED
|
@@ -14,41 +14,56 @@
|
|
|
14
14
|
if (!window.Jelly) Jelly = new Object();
|
|
15
15
|
Jelly.init = function() {
|
|
16
16
|
this.components = [];
|
|
17
|
-
|
|
17
|
+
this.observers = [];
|
|
18
|
+
this.Components.initCalled = false;
|
|
19
|
+
this.Pages.init();
|
|
20
|
+
var self = this;
|
|
18
21
|
$(document).ready(function() {
|
|
19
|
-
|
|
22
|
+
self.Components.init();
|
|
20
23
|
});
|
|
21
24
|
};
|
|
22
25
|
|
|
23
26
|
Jelly.attach = function() {
|
|
24
|
-
for(var i = 0; i < arguments.length; i++) {
|
|
27
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
25
28
|
var definition = arguments[i];
|
|
26
29
|
var component = (typeof definition.component == "string") ?
|
|
27
30
|
eval(definition.component) :
|
|
28
31
|
definition.component;
|
|
29
|
-
|
|
32
|
+
var evaluatedDefinition = {
|
|
30
33
|
component: component,
|
|
31
34
|
arguments: definition.arguments
|
|
32
|
-
}
|
|
35
|
+
};
|
|
36
|
+
this.components.push(evaluatedDefinition);
|
|
37
|
+
if (Jelly.Components.initCalled) {
|
|
38
|
+
Jelly.Components.initComponentFromDefinition(evaluatedDefinition);
|
|
39
|
+
}
|
|
33
40
|
}
|
|
34
41
|
};
|
|
35
42
|
|
|
36
43
|
Jelly.notifyObservers = function(params, observers) {
|
|
37
|
-
var context;
|
|
38
44
|
if (!observers) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
observers = [];
|
|
46
|
+
for (var i = 0; i < Jelly.observers.length; i++) {
|
|
47
|
+
observers.push(Jelly.observers[i]);
|
|
48
|
+
}
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
// Deprecate 'on' in favor of making each page action a Component.
|
|
51
|
+
if (params.on) {
|
|
52
|
+
var additionalObserver = eval(params.on);
|
|
53
|
+
var additionalObserverAlreadyAnObserver = false;
|
|
54
|
+
for (var i = 0; i < observers.length; i++) {
|
|
55
|
+
if (observers[i] == additionalObserver) {
|
|
56
|
+
additionalObserverAlreadyAnObserver = true;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!additionalObserverAlreadyAnObserver) {
|
|
61
|
+
observers.push(additionalObserver);
|
|
47
62
|
}
|
|
48
63
|
}
|
|
49
64
|
}
|
|
50
65
|
|
|
51
|
-
for(var i = 0; i < observers.length; i++) {
|
|
66
|
+
for (var i = 0; i < observers.length; i++) {
|
|
52
67
|
var observer = observers[i];
|
|
53
68
|
if (observer[params.method]) {
|
|
54
69
|
observer[params.method].apply(observer, params.arguments);
|
|
@@ -58,12 +73,17 @@ Jelly.notifyObservers = function(params, observers) {
|
|
|
58
73
|
|
|
59
74
|
Jelly.Components = {
|
|
60
75
|
init: function() {
|
|
61
|
-
for(var i = 0; i < Jelly.components.length; i++) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
for (var i = 0; i < Jelly.components.length; i++) {
|
|
77
|
+
this.initComponentFromDefinition(Jelly.components[i]);
|
|
78
|
+
}
|
|
79
|
+
this.initCalled = true;
|
|
80
|
+
},
|
|
81
|
+
initComponentFromDefinition: function(definition) {
|
|
82
|
+
var observer;
|
|
83
|
+
if (definition.component.init) {
|
|
84
|
+
observer = definition.component.init.apply(definition.component, definition.arguments);
|
|
66
85
|
}
|
|
86
|
+
Jelly.observers.push(observer ? observer : definition.component);
|
|
67
87
|
}
|
|
68
88
|
};
|
|
69
89
|
|
|
@@ -74,7 +94,7 @@ Jelly.Pages = {
|
|
|
74
94
|
},
|
|
75
95
|
|
|
76
96
|
add: function(name) {
|
|
77
|
-
var page = new Jelly.Page(name);
|
|
97
|
+
var page = new Jelly.Page.Constructor(name);
|
|
78
98
|
for (var i = 1; i < arguments.length; i++) {
|
|
79
99
|
$.extend(page, arguments[i]);
|
|
80
100
|
}
|
|
@@ -83,22 +103,22 @@ Jelly.Pages = {
|
|
|
83
103
|
};
|
|
84
104
|
Jelly.add = Jelly.Pages.add; // Deprecated
|
|
85
105
|
|
|
86
|
-
Jelly.Page =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
106
|
+
Jelly.Page = {
|
|
107
|
+
init: function(controllerName, actionName) {
|
|
108
|
+
var page = Jelly.Pages.all[controllerName] || new Jelly.Page.Constructor(controllerName);
|
|
109
|
+
window.page = page;
|
|
110
|
+
if (page.all) page.all();
|
|
111
|
+
if (page[actionName]) page[actionName].call(page);
|
|
112
|
+
page.loaded = true;
|
|
113
|
+
return page;
|
|
114
|
+
},
|
|
115
|
+
Constructor: function(name) {
|
|
116
|
+
this.loaded = false;
|
|
117
|
+
this.documentHref = Jelly.Location.documentHref;
|
|
95
118
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (page.all) page.all();
|
|
100
|
-
if (page[actionName]) page[actionName].call(page);
|
|
101
|
-
page.loaded = true;
|
|
119
|
+
this.name = name;
|
|
120
|
+
Jelly.Pages.all[name] = this;
|
|
121
|
+
}
|
|
102
122
|
};
|
|
103
123
|
|
|
104
124
|
Jelly.Location = {
|
data/lib/jelly/jelly_helper.rb
CHANGED
|
@@ -16,9 +16,9 @@ module JellyHelper
|
|
|
16
16
|
attach_javascript_component("Jelly.Page", controller.controller_path.camelcase, controller.action_name)
|
|
17
17
|
javascript_tag <<-JS
|
|
18
18
|
#{javascript_set_window_token}
|
|
19
|
-
Jelly.attach.
|
|
19
|
+
Jelly.attach.apply(Jelly, #{jelly_attached_components.to_json});
|
|
20
20
|
$(document).ready(function() {
|
|
21
|
-
Jelly.attach.
|
|
21
|
+
Jelly.attach.apply(Jelly, #{jelly_attached_components_on_ready.to_json});
|
|
22
22
|
});
|
|
23
23
|
JS
|
|
24
24
|
end
|