Top-level Diaspora object for js widget management
This commit is contained in:
parent
78fb5fec73
commit
257d6f414a
3 changed files with 47 additions and 0 deletions
18
public/javascripts/diaspora.js
Normal file
18
public/javascripts/diaspora.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
var Diaspora = Diaspora || {};
|
||||
Diaspora.widgets = Diaspora.widgets || {
|
||||
pageWidgets: {},
|
||||
|
||||
add: function(widgetId, widget) {
|
||||
this.pageWidgets[widgetId] = widget;
|
||||
},
|
||||
|
||||
remove: function(widgetId) {
|
||||
delete this.pageWidgets[widgetId];
|
||||
},
|
||||
|
||||
init: function() {
|
||||
for (var widgetId in this.pageWidgets) {
|
||||
this.pageWidgets[widgetId].start();
|
||||
}
|
||||
}
|
||||
};
|
||||
28
spec/javascripts/diaspora-spec.js
Normal file
28
spec/javascripts/diaspora-spec.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
describe("Diaspora", function() {
|
||||
describe("widgets", function() {
|
||||
beforeEach(function() {
|
||||
Diaspora.widgets.pageWidgets = {};
|
||||
});
|
||||
describe("add", function() {
|
||||
it("adds a widget to the list of pageWidgets", function() {
|
||||
expect(Diaspora.widgets.pageWidgets["nameOfWidget"]).not.toBeDefined();
|
||||
Diaspora.widgets.add("nameOfWidget", {});
|
||||
expect(Diaspora.widgets.pageWidgets["nameOfWidget"]).toBeDefined();
|
||||
});
|
||||
});
|
||||
describe("remove", function() {
|
||||
it("removes a widget from the list of pageWidgets", function() {
|
||||
Diaspora.widgets.add("nameOfWidget", {});
|
||||
expect(Diaspora.widgets.pageWidgets["nameOfWidget"]).toBeDefined();
|
||||
Diaspora.widgets.remove("nameOfWidget");
|
||||
expect(Diaspora.widgets.pageWidgets["nameOfWidget"]).not.toBeDefined();
|
||||
});
|
||||
});
|
||||
describe("init", function() {
|
||||
Diaspora.widgets.add("nameOfWidget", {start:$.noop});
|
||||
spyOn(Diaspora.widgets.pageWidgets["nameOfWidget"], "start");
|
||||
Diaspora.widgets.init();
|
||||
expect(Diaspora.widgets.pageWidgets["nameOfWidget"].start).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -14,6 +14,7 @@ src_files:
|
|||
- public/javascripts/vendor/jquery144.js
|
||||
- public/javascripts/vendor/jquery-ui-1.8.6.custom.min.js
|
||||
- public/javascripts/vendor/jquery.tipsy.js
|
||||
- public/javascripts/diaspora.js
|
||||
- public/javascripts/mobile.js
|
||||
- public/javascripts/aspect-edit.js
|
||||
- public/javascripts/web-socket-receiver.js
|
||||
|
|
|
|||
Loading…
Reference in a new issue