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 CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 6
3
- :patch: 7
2
+ :minor: 7
3
+ :patch: 0
4
4
  :major: 0
@@ -14,41 +14,56 @@
14
14
  if (!window.Jelly) Jelly = new Object();
15
15
  Jelly.init = function() {
16
16
  this.components = [];
17
- Jelly.Pages.init();
17
+ this.observers = [];
18
+ this.Components.initCalled = false;
19
+ this.Pages.init();
20
+ var self = this;
18
21
  $(document).ready(function() {
19
- Jelly.Components.init();
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
- this.components.push({
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
- // Deprecate 'on' in favor of making each page action a Component.
40
- context = params.on ? eval(params.on) : page;
41
- observers = [context];
45
+ observers = [];
46
+ for (var i = 0; i < Jelly.observers.length; i++) {
47
+ observers.push(Jelly.observers[i]);
48
+ }
42
49
 
43
- for(var i=0; i < Jelly.components.length; i++) {
44
- var component = Jelly.components[i].component;
45
- if (component != context) {
46
- observers.push(component);
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
- var definition = Jelly.components[i];
63
- if (definition.component.init) {
64
- definition.component.init.apply(definition.component, definition.arguments);
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 = function(name) {
87
- this.documentHref = Jelly.Location.documentHref;
88
-
89
- this.name = name;
90
- Jelly.Pages.all[name] = this;
91
- };
92
- Jelly.Page.prototype.loaded = false;
93
- Jelly.Page.prototype.all = function() {
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
- Jelly.Page.init = function(controllerName, actionName) {
97
- var page = Jelly.Pages.all[controllerName] || new Jelly.Page(controllerName);
98
- window.page = page;
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 = {
@@ -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.call(Jelly, #{jelly_attached_components.to_json});
19
+ Jelly.attach.apply(Jelly, #{jelly_attached_components.to_json});
20
20
  $(document).ready(function() {
21
- Jelly.attach.call(Jelly, #{jelly_attached_components_on_ready.to_json});
21
+ Jelly.attach.apply(Jelly, #{jelly_attached_components_on_ready.to_json});
22
22
  });
23
23
  JS
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: honkster-jelly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pivotal Labs, Inc