Permalink
Browse files

Merge branch 'master' of github.com:pusewicz/sonia

  • Loading branch information...
pusewicz committed May 11, 2010
2 parents 37a0bb2 + 0574704 commit 3890870df8e2707c02a2d256d6fbda34afed1a9b
Showing with 4,735 additions and 54 deletions.
  1. +3 −3 Gemfile
  2. +11 −11 lib/sonia/helpers.rb
  3. BIN public/images/icons/button_blue_add.png
  4. +1 −12 public/javascripts/dispatcher.js
  5. +123 −0 public/javascripts/pager.js
  6. +23 −0 public/javascripts/sonia.js
  7. +29 −3 public/javascripts/widget.js
  8. +35 −9 public/stylesheets/sonia.css
  9. 0 public/{javascripts → vendor}/FABridge.js
  10. 0 public/{javascripts → vendor}/builder.js
  11. 0 public/{javascripts → vendor}/contextmenu.js
  12. 0 public/{javascripts → vendor}/controls.js
  13. 0 public/{javascripts → vendor}/cookie.js
  14. 0 public/{javascripts → vendor}/dragdrop.js
  15. 0 public/{javascripts → vendor}/effects.js
  16. 0 public/{javascripts → vendor}/event_behavior.js
  17. 0 public/{javascripts → vendor}/hotkey.js
  18. 0 public/{javascripts → vendor}/json2.js
  19. 0 public/{javascripts → vendor}/livepipe.js
  20. 0 public/{javascripts → vendor}/progressbar.js
  21. 0 public/{javascripts → vendor}/prototype.js
  22. 0 public/{javascripts → vendor}/rating.js
  23. 0 public/{javascripts → vendor}/resizable.js
  24. +4,410 −0 public/vendor/s2.js
  25. 0 public/{javascripts → vendor}/scrollbar.js
  26. 0 public/{javascripts → vendor}/selection.js
  27. 0 public/{javascripts → vendor}/selectmultiple.js
  28. 0 public/{javascripts → vendor}/slider.js
  29. 0 public/{javascripts → vendor}/sound.js
  30. 0 public/{javascripts → vendor}/swfobject.js
  31. 0 public/{javascripts → vendor}/tabs.js
  32. 0 public/{javascripts → vendor}/textarea.js
  33. 0 public/{javascripts → vendor}/unittest.js
  34. 0 public/{javascripts → vendor}/web_socket.js
  35. 0 public/{javascripts → vendor}/window.js
  36. +89 −0 spec/sonia/config_spec.rb
  37. +0 −7 spec/sonia_spec.rb
  38. +1 −0 spec/spec.opts
  39. BIN vendor/cache/gemcutter-0.5.0.gem
  40. BIN vendor/cache/git-1.2.5.gem
  41. BIN vendor/cache/jeweler-1.4.0.gem
  42. BIN vendor/cache/json_pure-1.4.3.gem
  43. BIN vendor/cache/rspec-1.3.0.gem
  44. BIN vendor/cache/rubyforge-2.0.4.gem
  45. BIN vendor/cache/yard-0.5.4.gem
  46. +1 −0 views/index.haml
  47. +1 −1 widgets/campfire/campfire.js
  48. +1 −1 widgets/foursquare/foursquare.js
  49. +1 −1 widgets/github/github.js
  50. +1 −1 widgets/icinga/icinga.js
  51. +1 −1 widgets/rss/rss.js
  52. +1 −1 widgets/tfl/tfl.js
  53. +1 −1 widgets/twitter/twitter.js
  54. +1 −1 widgets/twitter/twitter.rb
  55. +1 −1 widgets/yahoo_weather/yahoo_weather.js
View
@@ -16,10 +16,10 @@ group :runtime do
gem "haml", "2.2.24"
end
-#group :test do
- #gem "rspec"
+group :test do
+ gem "rspec"
#gem "cucumber"
-#end
+end
group :development do
gem "yard"
View
@@ -22,17 +22,17 @@ def widget_stylesheets
def joined_system_javascript
files = %w(
- /javascripts/swfobject.js
- /javascripts/FABridge.js
- /javascripts/web_socket.js
- /javascripts/json2.js
- /javascripts/prototype.js
- /javascripts/effects.js
- /javascripts/dragdrop.js
- /javascripts/livepipe.js
- /javascripts/window.js
- /javascripts/resizable.js
- /javascripts/cookie.js
+ /vendor/swfobject.js
+ /vendor/FABridge.js
+ /vendor/web_socket.js
+ /vendor/json2.js
+ /vendor/prototype.js
+ /vendor/effects.js
+ /vendor/dragdrop.js
+ /vendor/livepipe.js
+ /vendor/window.js
+ /vendor/resizable.js
+ /vendor/cookie.js
/javascripts/storage.js
/javascripts/sonia.js
/javascripts/dispatcher.js
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -16,18 +16,7 @@ var Dispatcher = Class.create({
console.log("Missing data in message message:", json.message);
}
} else if(json.setup) {
- var widgets = json.setup;
- widgets.each(function(payload) {
- var widget = payload.widget;
- var widget_id = payload.widget_id;
- var config = payload.config;
- if(widget && widget_id && config) {
- var widget_object = eval("new " + widget + "(widget_id, config)");
- this.sonia.addWidget(widget_id, widget_object);
- } else {
- console.log("Missing data in setup message:", json.setup);
- }
- }.bind(this));
+ this.sonia.addWidgets(json.setup);
}
}
});
View
@@ -0,0 +1,123 @@
+var Pager = Class.create({
+ initialize: function(sonia) {
+ this.sonia = sonia;
+ this.pages = [];
+ this.currentPage = 0;
+ this.build();
+ setInterval(this.changePage.bind(this), 60 * 100);
+ },
+
+ addWidgetToCurrentPage: function(widgetSha) {
+ if(!this.pages[this.currentPage]) {
+ this.pages[this.currentPage] = [];
+ this.pageCount = this.pages.size();
+ }
+
+ this.getCurrentPage().push(widgetSha);
+ this.update();
+ // TODO: Remove this in final version
+ if(this.getCurrentPage().size() % 3 == 0) this.currentPage++;
+ },
+
+ changePage: function() {
+ var currPage = this.currentPage;
+ if(++this.currentPage >= this.pageCount) {
+ this.currentPage = 0;
+ }
+
+ this.transitionToNewPage(currPage, this.currentPage);
+ this.update();
+ },
+
+ transitionToNewPage: function(fromIdx, toIdx) {
+ var currentPage = this.pages[fromIdx];
+ var nextPage = this.pages[toIdx];
+
+ var viewportWidth = document.viewport.getWidth();
+ // Prepare next page widgets
+
+ var nextWidgets = nextPage.collect(function(el) {
+ return this.sonia.widgets[el];
+ }, this);
+
+ var currentWidgets = currentPage.collect(function(el) {
+ return this.sonia.widgets[el];
+ }, this);
+
+ nextWidgets.each(function(w) {
+ var destX = w.x + viewportWidth;
+ var widget = $(w.widget_id);
+ console.log("Setting", widget, "to", destX);
+ widget.setStyle({left: destX + "px"});
+ console.log("Morphing next", widget, "to", w.x);
+ widget.morph("left:" + w.x + "px", {
+ duration: 0.7,
+ transition: 'easeInOutExpo',
+ propertyTransitions: {
+ top: 'spring', left: 'easeInOutCirc'
+ }
+ });
+ });
+
+ currentWidgets.each(function(w) {
+ var destX = -(w.x + viewportWidth);
+ var widget = $(w.widget_id);
+ console.log("Morphing current", widget, "to", destX);
+ widget.morph("left:" + destX + "px", {
+ duration: 0.7,
+ transition: 'easeInOutExpo',
+ propertyTransitions: {
+ top: 'spring', left: 'easeInOutCirc'
+ }
+ });
+ });
+ },
+
+ build: function() {
+ this.buildPager();
+ },
+
+ update: function() {
+ this.buildPager();
+ this.showOnlyCurrentPageWidgets();
+ },
+
+ buildPager: function() {
+ if(this.pagerContainer) { $(this.pagerContainer).remove(); }
+ this.pagerContainer = new Element("ul", { id: "pager" });
+ this.pages.each(function(page) {
+ this.pagerContainer.insert(new Element("li", { 'class': (this.getCurrentPage() == page) ? 'current' : '' }).update("•"));
+ }, this);
+ $("widgets").insert(this.pagerContainer);
+ },
+
+ showOnlyCurrentPageWidgets: function() {
+ this.currentPageWidgets().each(function(el) {
+ //$(el).show();
+ }, this);
+
+ this.notCurrentPageWidgets().each(function(el) {
+ //$(el).hide();
+ }, this);
+ },
+
+ currentPageWidgets: function() {
+ return(this.getCurrentPage().collect(function(el) {
+ return $(el);
+ }, this));
+ },
+
+ notCurrentPageWidgets: function() {
+ var nonCurrentPages = this.pages.findAll(function(el) {
+ return(el != this.getCurrentPage());
+ }, this);
+
+ return(nonCurrentPages.flatten().collect(function(el) {
+ return $(el);
+ }));
+ },
+
+ getCurrentPage: function() {
+ return(this.pages[this.currentPage]);
+ }
+});
@@ -9,6 +9,8 @@ var Sonia = Class.create({
this.websocket.onmessage = this.onmessage.bind(this);
this.websocket.onclose = this.onclose.bind(this);
this.websocket.onerror = this.onerror.bind(this);
+
+ //this.pager = new Pager(this);
},
onopen: function() {
console.log("Socket opened... ");
@@ -24,9 +26,30 @@ var Sonia = Class.create({
onerror: function(event) {
console.log("Received error:", event);
},
+
+ getWidgets: function() {
+ return(this.widgets);
+ },
+
+ addWidgets: function(setup) {
+ setup.each(function(payload) {
+ var widget = payload.widget;
+ var widget_id = payload.widget_id;
+ var config = payload.config;
+ if(widget && widget_id && config) {
+ var widget_object = eval("new " + widget + "(widget_id, config)");
+ this.addWidget(widget_id, widget_object);
+ } else {
+ console.log("Missing data in setup message:", json.setup);
+ }
+ }.bind(this));
+ },
+
addWidget: function(widget_id, widget) {
this.widgets[widget_id] = widget;
+ //this.pager.addWidgetToCurrentPage(widget_id);
},
+
saveChanges: function() {
$H(this.widgets).each(function(pair) {
pair.value.savePosition();
@@ -4,6 +4,10 @@ var Widget = Class.create({
this.widget_id = widget_id;
this.title = config.title;
this.config = config;
+
+ this.x = 0;
+ this.y = 0;
+
this.buildContainer(config);
this.build();
this.restorePosition();
@@ -32,8 +36,11 @@ var Widget = Class.create({
},
savePosition: function() {
- var position = { left: this.container.measure("left"), top: this.container.measure("top") };
- Storage.set(this.attrKey("position"), position);
+ var left = this.container.measure("left");
+ var top = this.container.measure("top");
+ if(left >= 0 && top >= 0) {
+ Storage.set(this.attrKey("position"), { left: left, top: top });
+ }
},
restorePosition: function() {
@@ -44,11 +51,30 @@ var Widget = Class.create({
this.container.setStyle({ left: (left < 0) ? 0 : left + "px", top: (top < 0) ? 0 : top + "px"});
} catch(err) {
+ this.container.setStyle({ left: "0px", top: "0px"});
console.warn("Cound not set restore position", err);
}
+ var viewportWidth = document.viewport.getWidth();
+ if(this.container.measure("left") >= viewportWidth) {
+ this.container.setStyle({ left: "0px", top: "0px"});
+ }
+ this.setCoordinates();
+ },
+
+ setCoordinates: function() {
+ this.x = parseInt(this.container.measure("left"));
+ this.y = parseInt(this.container.measure("top"));
+ console.log("Stored coordinates", this.x, this.y);
},
attrKey: function(attr) {
return(this.widget_id + "_" + attr);
- }
+ },
+
+ makeDraggable: function() {
+ new Draggable(this.container, { onEnd: function() {
+ this.savePosition();
+ this.setCoordinates();
+ }.bindAsEventListener(this)});
+ },
});
@@ -1,17 +1,25 @@
+html {
+ width: 100%;
+ height: 100%;
+ margin: 0;
+ padding: 0;
+ overflow: hidden;
+}
+
body * {
cursor: default;
}
body {
- background: black; /* fallback for older/unsupporting browsers */
- background-image: -webkit-gradient(linear,
- left bottom,
- left top,
- color-stop(0.12, rgb(77,77,77)),
- color-stop(0.59, rgb(0,0,0)));
- color: white;
- font-size: 14px;
- font-family: "Optima";
+ margin: 0;
+ padding: 0;
+ width: 100%;
+ height: 100%;
+ background-color: black;
+ color: #EAEAEA;
+ font-size: 16px;
+ font-family: HelveticaNeue-Light, 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial, sans-serif;
+ font-weight: 300;
}
h1 {
@@ -88,3 +96,21 @@ div.widget img.icon {
top: -35px;
right: 0;
}
+
+#pager {
+ list-style-type: none;
+ list-style-position: inline;
+ width: 128px;
+ margin: 0px auto;
+ text-align: center;
+}
+
+#pager li {
+ display: inline;
+ color: #363636;
+ padding: 8px 8px;
+}
+
+#pager li.current {
+ color: #EAEAEA;
+}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.

0 comments on commit 3890870

Please sign in to comment.