diff --git a/public/javascripts/diaspora.js b/public/javascripts/diaspora.js index c1e9348ec..822fe386c 100644 --- a/public/javascripts/diaspora.js +++ b/public/javascripts/diaspora.js @@ -10,57 +10,61 @@ var Diaspora = { }; - Diaspora.WidgetCollection = function() { - this.initialized = false; - this.collection = { }; - this.eventsContainer = $({}); - }; + Diaspora.EventBroker = { + extend: function(obj) { + obj.eventsContainer = $({}); - Diaspora.WidgetCollection.prototype.add = function(widgetId, Widget) { - $.extend(Widget.prototype, Diaspora.BaseWidget); + obj.subscribe = Diaspora.EventBroker.subscribe; + obj.publish = Diaspora.EventBroker.publish; - this[widgetId] = this.collection[widgetId] = new Widget(); - if(this.initialized) { - this.collection[widgetId].start(); + obj.publish = $.proxy(function(eventId, args) { + this.eventsContainer.trigger(eventId, args); + }, obj); + + obj.subscribe = $.proxy(function(eventIds, callback, context) { + var eventIds = eventIds.split(" "); + + for(var eventId in eventIds) { + this.eventsContainer.bind(eventIds[eventId], $.proxy(callback, context)); + } + }, obj); + + return obj; } }; - Diaspora.WidgetCollection.prototype.remove = function(widgetId) { - delete this.collection[widgetId]; - }; + Diaspora.widgets = { + initialize: false, + collection: {}, + constructors: {}, - Diaspora.WidgetCollection.prototype.init = function() { - this.initialized = true; + initialize: function() { + this.initialized = true; + Diaspora.EventBroker.extend(this); - for(var widgetId in this.collection) { - if(typeof this.collection[widgetId].start !== "undefined") { - this.collection[widgetId].start(); + for(var widgetId in this.collection) { + this.collection[widgetId].publish("widget/ready"); } - }; - - }; + }, - Diaspora.WidgetCollection.prototype.subscribe = function(id, callback, context) { - var ids = id.split(" "); - for(var id in ids) { - this.eventsContainer.bind(ids[id], $.proxy(callback, context)); + add: function(widgetId, Widget) { + $.extend(Widget.prototype, Diaspora.EventBroker.extend({})); + + this[widgetId] = this.collection[widgetId] = new Widget(); + if(this.initialized) { + this.collection[widgetId].publish("widget/ready"); + } + }, + + remove: function(widgetId) { + delete this.collection[widgetId]; } }; - Diaspora.WidgetCollection.prototype.publish = function(id, args) { - this.eventsContainer.trigger(id, args); - }; - - Diaspora.BaseWidget = { - require: function(widgetName) { - this[widgetName] = Diaspora.widgets[widgetName]; - } - }; - - Diaspora.widgets = new Diaspora.WidgetCollection(); - window.Diaspora = Diaspora; })(); -$(document).ready(function() { Diaspora.widgets.init(); }); +$(function() { + Diaspora.widgets.initialize(); +}); diff --git a/public/javascripts/widgets/alert.js b/public/javascripts/widgets/alert.js index 9dcf8ed4c..30a7e1715 100644 --- a/public/javascripts/widgets/alert.js +++ b/public/javascripts/widgets/alert.js @@ -1,34 +1,37 @@ -Diaspora.widgets.add("alert", function() { - this.start = function() { - $(document).bind("close.facebox", function() { - if ($("#diaspora_alert").length) { - $("#diaspora_alert").detach(); - } - }); +(function() { + var Alert = function() { + var self = this; + + this.faceboxTemplate = '
' + Diaspora.widgets.i18n.t("videos.unknown") + ' - {{host}}
'); - }; - - Embedder.prototype.onVideoLinkClicked = function(evt) { - if(Diaspora.widgets.embedder.canEmbed) { - evt.preventDefault(); - Diaspora.widgets.embedder.embed($(this)); - } + self.register("undefined", '' + Diaspora.widgets.i18n.t("videos.unknown") + ' - {{host}}
'); + }; }; Diaspora.widgets.add("embedder", Embedder); diff --git a/public/javascripts/widgets/flashes.js b/public/javascripts/widgets/flashes.js index 00232cd6a..ad052f6b8 100644 --- a/public/javascripts/widgets/flashes.js +++ b/public/javascripts/widgets/flashes.js @@ -1,27 +1,30 @@ (function() { var Flashes = function() { - this.start = function() { - this.animateMessages(); - }; + var self = this; + + this.subscribe("widget/ready", function() { + self.animateMessages(); + }); this.animateMessages = function() { - var $this = $("#flash_notice, #flash_error, #flash_alert"); - $this.animate({ + var flashMessages = $("#flash_notice, #flash_error, #flash_alert"); + flashMessages.animate({ top: 0 }).delay(2000).animate({ top: -100 - }, $this.remove); + }, flashMessages.remove); }; this.render = function(result) { - $("") - .attr("id", (result.success) ? "flash_notice" : "flash_error") - .prependTo(document.body) - .html(result.notice); + $("", { + id: (result.success) ? "flash_notice" : "flash_error" + }) + .prependTo(document.body) + .html(result.notice); - this.animateMessages(); + self.animateMessages(); }; }; Diaspora.widgets.add("flashes", Flashes); -})(); \ No newline at end of file +})(); diff --git a/public/javascripts/widgets/hovercard.js b/public/javascripts/widgets/hovercard.js index f75b0f753..21664aa99 100644 --- a/public/javascripts/widgets/hovercard.js +++ b/public/javascripts/widgets/hovercard.js @@ -4,9 +4,9 @@ self.jXHRs = []; - this.start = function() { - self.personCache = new this.Cache(); - self.dropdownCache = new this.Cache(); + self.subscribe("widget/ready", function() { + self.personCache = new self.Cache(); + self.dropdownCache = new self.Cache(); var card = $("#hovercard"); self.hoverCard = { @@ -28,7 +28,7 @@ Diaspora.widgets.subscribe("aspectDropdown/updated aspectDropdown/blurred", function(evt, personId, dropdownHtml) { self.dropdownCache.cache["/people/" + personId + "/aspect_membership_button"] = $(dropdownHtml).removeClass("active").get(0).outerHTML; }); - }; + }); this.handleHoverEvent = function(evt) { self.target = $(evt.target); diff --git a/public/javascripts/widgets/i18n.js b/public/javascripts/widgets/i18n.js index b3a259db5..6335d0007 100644 --- a/public/javascripts/widgets/i18n.js +++ b/public/javascripts/widgets/i18n.js @@ -2,31 +2,34 @@ * licensed under the Affero General Public License version 3 or later. See * the COPYRIGHT file. */ - -Diaspora.widgets.add("i18n", function() { - this.language = "en"; - this.locale = { }; - - this.loadLocale = function(locale, language) { - this.language = language; - this.locale = locale; - }; - - this.t = function(item, views) { - var ret, - _item = item.split("."); +(function() { + var I18n = function() { + var self = this; + this.locale = { }; + this.language = "en"; - while(part = _item.shift()) { - ret = (ret) ? ret[part] : this.locale[part]; - if(typeof ret === "undefined") { - return ""; + this.loadLocale = function(locale, language) { + this.locale = locale; + this.language = language; + }; + + this.t = function(item, views) { + var translatedMessage, + items = item.split("."); + + while(nextNamespace = items.shift()) { + translatedMessage = (translatedMessage) + ? translatedMessage[nextNamespace] + : self.locale[nextNamespace]; + + if(typeof translatedMessage === "undefined") { + return ""; + } } - } - - if(typeof views === "object") { - return $.mustache(ret, views || {}); - } - - return ret; + + return $.mustache(translatedMessage, views || { }); + }; }; -}); + + Diaspora.widgets.add("i18n", I18n); +})(); diff --git a/public/javascripts/widgets/infinite-scroll.js b/public/javascripts/widgets/infinite-scroll.js index d7c461048..82bedbfff 100644 --- a/public/javascripts/widgets/infinite-scroll.js +++ b/public/javascripts/widgets/infinite-scroll.js @@ -4,9 +4,9 @@ */ (function() { - var InfiniteScroll = function() { }; - InfiniteScroll.prototype.options = - { + var InfiniteScroll = function() { + var self = this; + this.options = { navSelector : "#pagination", nextSelector : ".paginate", itemSelector : ".stream_element", @@ -22,38 +22,34 @@ loadingImg: '/images/ajax-loader.gif' }; - InfiniteScroll.prototype.reInitialize = function(){ - this.clear(); - this.initialize(); - }; + this.subscribe("widget/ready", function() { + Diaspora.widgets.subscribe("stream/reloaded", self.reInitialize, this); + self.initialize(); + }); - InfiniteScroll.prototype.initialize = function(){ - if($('#main_stream').length !== 0){ - $('#main_stream').infinitescroll(this.options, function() { - Diaspora.widgets.publish("stream/scrolled"); - }); + this.reInitialize = function() { + self.clear(); + self.initialize(); + }; - } else if($('#people_stream.contacts').length !== 0){ - $("#people_stream.contacts").infinitescroll({ - navSelector : ".pagination", - nextSelector : ".next_page", - itemSelector : ".stream_element", - loadingText: "", - loadingImg: '/images/ajax-loader.gif', - bufferPx: 400 - }, function(){ - Diaspora.widgets.publish("stream/scrolled"); - }); - } - }; + this.initialize = function() { + if($('#main_stream').length !== 0){ + $('#main_stream').infinitescroll(this.options, function() { + Diaspora.widgets.publish("stream/scrolled"); + }); + } else if($('#people_stream.contacts').length !== 0){ + $("#people_stream.contacts").infinitescroll($.extend(self.options, { + navSelector : ".pagination", + nextSelector : ".next_page", + }), function() { + Diaspora.widgets.publish("stream/scrolled"); + }); + } + }; - InfiniteScroll.prototype.start = function() { - Diaspora.widgets.subscribe("stream/reloaded", this.reInitialize, this); - this.initialize(); - }; - - InfiniteScroll.prototype.clear = function() { - $('#main_stream').infinitescroll('destroy'); + this.clear = function() { + $("#main_stream").infinitescroll("destroy"); + }; }; Diaspora.widgets.add("infinitescroll", InfiniteScroll); diff --git a/public/javascripts/widgets/lightbox.js b/public/javascripts/widgets/lightbox.js index aa41b4c6f..8b1e7fd6a 100644 --- a/public/javascripts/widgets/lightbox.js +++ b/public/javascripts/widgets/lightbox.js @@ -20,7 +20,7 @@ jQuery.fn.center = (function() { var Lightbox = function() { var self = this; - this.start = function() { + this.subscribe("widget/ready", function() { $.extend(self, { lightbox: $("#lightbox"), imageset: $("#lightbox-imageset"), @@ -62,7 +62,7 @@ jQuery.fn.center = (function() { break; } }); - }; + }); this.nextImage = function(thumb){ var next = thumb.next(); diff --git a/public/javascripts/widgets/notifications-badge.js b/public/javascripts/widgets/notifications-badge.js index e8dfd95d0..54a69a31a 100644 --- a/public/javascripts/widgets/notifications-badge.js +++ b/public/javascripts/widgets/notifications-badge.js @@ -2,16 +2,16 @@ var NotificationDropdown = function() { var self = this; - this.start = function() { - this.badge = $("#notification_badge"); - this.badgeLink = this.badge.find("a"); - this.documentBody = $(document.body); - this.dropdown = $("#notification_dropdown"); - this.dropdownNotifications = this.dropdown.find(".notifications"); - this.ajaxLoader = this.dropdown.find(".ajax_loader"); + this.subscribe("widget/ready",function() { + self.badge = $("#notification_badge"); + self.badgeLink = self.badge.find("a"); + self.documentBody = $(document.body); + self.dropdown = $("#notification_dropdown"); + self.dropdownNotifications = self.dropdown.find(".notifications"); + self.ajaxLoader = self.dropdown.find(".ajax_loader"); - this.badgeLink.toggle(function(evt) { - evt.preventDefault(); + self.badgeLink.toggle(function(evt) { + evt.preventDefault(); evt.stopPropagation(); self.ajaxLoader.show(); @@ -29,16 +29,16 @@ self.dropdown.css("display", "none"); }); - this.dropdown.click(function(evt) { + self.dropdown.click(function(evt) { evt.stopPropagation(); }); - this.documentBody.click(function(evt) { + self.documentBody.click(function(evt) { if(self.dropdownShowing()) { self.badgeLink.click(); } }); - }; + }); this.dropdownShowing = function() { diff --git a/public/javascripts/widgets/notifications.js b/public/javascripts/widgets/notifications.js index 98fef3bb9..3b63dde72 100644 --- a/public/javascripts/widgets/notifications.js +++ b/public/javascripts/widgets/notifications.js @@ -5,13 +5,14 @@ (function() { var Notifications = function() { - this.start = function() { - var self = this; - this.badge = $("#notification_badge .badge_count") - this.index_badge = $(".notification_count"); - this.on_index_page = this.index_badge.length > 0 - this.notificationArea = $("#notifications"); - this.count = parseInt(this.badge.html()) || 0; + var self = this; + + this.subscribe("widget/ready", function() { + self.badge = $("#notification_badge .badge_count") + self.indexBadge = $(".notification_count"); + self.onIndexPage = self.indexBadge.length > 0; + self.notificationArea = $("#notifications"); + self.count = parseInt(self.badge.html()) || 0; $(".stream_element.unread").live("mousedown", function() { self.decrementCount(); @@ -31,47 +32,47 @@ .next(".hidden") .removeClass("hidden"); }); + }); + + this.showNotification = function(notification) { + $(notification.html).prependTo(this.notificationArea) + .fadeIn(200) + .delay(8000) + .fadeOut(200, function() { + $(this).detach(); + }); + + if(typeof notification.incrementCount === "undefined" || notification.incrementCount) { + this.incrementCount(); + } }; - }; - Notifications.prototype.showNotification = function(notification) { - $(notification.html).prependTo(this.notificationArea) - .fadeIn(200) - .delay(8000) - .fadeOut(200, function() { - $(this).detach(); - }); + this.changeNotificationCount = function(change) { + this.count += change; - if(typeof notification.incrementCount === "undefined" || notification.incrementCount) { - this.incrementCount(); - } - }; + if(this.badge.text() !== "") { + this.badge.text(this.count); + if(this.on_index_page) + this.index_badge.text(this.count + " "); - Notifications.prototype.changeNotificationCount = function(change) { - this.count += change; - - if(this.badge.text() !== "") { - this.badge.text(this.count); - if(this.on_index_page) - this.index_badge.text(this.count + " "); - - if(this.count === 0) { - this.badge.addClass("hidden"); - if(this.on_index_page) - this.index_badge.removeClass('unread'); + if(this.count === 0) { + this.badge.addClass("hidden"); + if(this.on_index_page) + this.index_badge.removeClass('unread'); + } + else if(this.count === 1) { + this.badge.removeClass("hidden"); + } } - else if(this.count === 1) { - this.badge.removeClass("hidden"); - } - } - }; + }; - Notifications.prototype.decrementCount = function() { - this.changeNotificationCount(-1); - }; + this.decrementCount = function() { + self.changeNotificationCount(-1); + }; - Notifications.prototype.incrementCount = function() { - this.changeNotificationCount(1); + this.incrementCount = function() { + self.changeNotificationCount(1); + }; }; Diaspora.widgets.add("notifications", Notifications); diff --git a/public/javascripts/widgets/post.js b/public/javascripts/widgets/post.js index 5239aee09..d8ca300b8 100644 --- a/public/javascripts/widgets/post.js +++ b/public/javascripts/widgets/post.js @@ -8,7 +8,7 @@ var self = this; //timeago //set up ikes //comments //audio video links //embedder // - this.start = function() { + this.subscribe("widget/ready", function() { $.extend(self, { likes: { actions: $(".like_it, .dislike_it"), @@ -16,7 +16,7 @@ } }); self.setUpLikes(); - }, + }); this.setUpLikes = function() { self.likes.expanders.live("click", self.expandLikes); diff --git a/public/javascripts/widgets/timeago.js b/public/javascripts/widgets/timeago.js index c46f872ab..b16079b0d 100644 --- a/public/javascripts/widgets/timeago.js +++ b/public/javascripts/widgets/timeago.js @@ -2,29 +2,29 @@ * licensed under the Affero General Public License version 3 or later. See * the COPYRIGHT file. */ +(function() { + var TimeAgo = function() { + var self = this; + this.selector = "abbr.timeago"; + this.subscribe("widget/ready", function() { + Diaspora.widgets.subscribe("stream/scrolled stream/reloaded", self.updateTimeAgo, this); -Diaspora.widgets.add("timeago", function() { - this.selector = "abbr.timeago"; - this.start = function() { - Diaspora.widgets.subscribe("stream/scrolled", this.updateTimeAgo, this); - Diaspora.widgets.subscribe("stream/reloaded", this.updateTimeAgo, this); + self.updateTimeAgo(); - if(this.timeAgoElement().length) { - this.updateTimeAgo(); - } + if(Diaspora.widgets.i18n.language !== "en") { + $.each($.timeago.settings.strings, function(index) { + $.timeago.settings.strings[index] = Diaspora.widgets.i18n.t("timeago." + index); + }); + } + }); - if(Diaspora.widgets.i18n.language !== "en") { - $.each($.timeago.settings.strings, function(index) { - $.timeago.settings.strings[index] = Diaspora.widgets.i18n.t("timeago." + index); - }); - } + this.timeAgoElement = function(selector) { + return $((typeof selector === "string") ? selector : this.selector); + }; + + this.updateTimeAgo = function() { + self.timeAgoElement().timeago(); + }; }; - - this.timeAgoElement = function(selector) { - return $((typeof selector === "string") ? selector : this.selector); - }; - - this.updateTimeAgo = function() { - this.timeAgoElement().timeago(); - }; -}); + Diaspora.widgets.add("timeago", TimeAgo); +})(); diff --git a/spec/javascripts/diaspora-spec.js b/spec/javascripts/diaspora-spec.js index ffbf289eb..c28aa882b 100644 --- a/spec/javascripts/diaspora-spec.js +++ b/spec/javascripts/diaspora-spec.js @@ -4,85 +4,101 @@ */ describe("Diaspora", function() { - describe("WidgetCollection", function() { - describe("prototype", function() { - var widgets; + describe("widgets", function() { + describe("add", function() { + it("adds a widget to the collection", function() { + expect(Diaspora.widgets.collection["nameOfWidget"]).not.toBeDefined(); + Diaspora.widgets.add("nameOfWidget", function() { }); + expect(Diaspora.widgets.collection["nameOfWidget"]).toBeDefined(); + }); + + it("sets a shortcut by referencing the object on Diaspora.widgetCollection", function() { + expect(Diaspora.widgets.sup).toBeFalsy(); + Diaspora.widgets.add("sup", function() { }); + expect(Diaspora.widgets.sup).toEqual(Diaspora.widgets.collection.sup); + }); + }); + + describe("remove", function() { + it("removes a widget from the collection", function() { + Diaspora.widgets.add("nameOfWidget", function() { }); + expect(Diaspora.widgets.collection["nameOfWidget"]).toBeDefined(); + Diaspora.widgets.remove("nameOfWidget"); + expect(Diaspora.widgets.collection["nameOfWidget"]).not.toBeDefined(); + }); + }); + + describe("init", function() { + it("publishes the widget/ready event on all of the present widgets", function() { + Diaspora.widgets.add("nameOfWidget", function() { + var self = this; + this.subscribe("widget/ready", function() { + self.called = true; + }); + }); + + Diaspora.widgets.initialize(); + expect(Diaspora.widgets.collection.nameOfWidget.called).toBeTruthy(); + }); + + it("changes the initialized property to true", function() { + Diaspora.widgets.initialized = false; + Diaspora.widgets.initialize(); + expect(Diaspora.widgets.initialized).toBeTruthy(); + }); + }); + }); + describe("EventBroker", function() { + describe("extend", function() { + var obj; beforeEach(function() { - widgets = new Diaspora.WidgetCollection(); + obj = {}; }); - describe("add", function() { - it("adds a widget to the collection", function() { - expect(widgets.collection["nameOfWidget"]).not.toBeDefined(); - widgets.add("nameOfWidget", function() { }); - expect(widgets.collection["nameOfWidget"]).toBeDefined(); - }); - - it("sets a shortcut by referencing the object on Diaspora.widgetCollection", function() { - expect(widgets.sup).toBeFalsy(); - widgets.add("sup", function() { }); - expect(widgets.sup).toEqual(widgets.collection.sup); - }); + it("adds an events container to an object", function() { + expect(typeof Diaspora.EventBroker.extend(obj).eventsContainer).toEqual("object"); }); - describe("remove", function() { - it("removes a widget from the collection", function() { - widgets.add("nameOfWidget", function() { }); - expect(widgets.collection["nameOfWidget"]).toBeDefined(); - widgets.remove("nameOfWidget"); - expect(widgets.collection["nameOfWidget"]).not.toBeDefined(); - }); + it("adds a publish method to an object", function() { + expect(typeof Diaspora.EventBroker.extend(obj).publish).toEqual("function"); }); - describe("init", function() { - it("calls the start method on all of the widgets present", function() { - widgets.add("nameOfWidget", function() { - this.start = function() { } - }); + it("adds a subscribe method to an object", function() { + expect(typeof Diaspora.EventBroker.extend(obj).subscribe).toEqual("function"); + }); + }); - spyOn(widgets.collection["nameOfWidget"], "start"); - widgets.init(); - expect(widgets.collection["nameOfWidget"].start).toHaveBeenCalled(); - }); - - it("changes the initialized property to true", function() { - expect(widgets.initialized).toBeFalsy(); - widgets.init(); - expect(widgets.initialized).toBeTruthy(); - }); + describe("subscribe", function() { + it("subscribes to an event specified by an id", function() { + expect(Diaspora.widgets.eventsContainer.data("events")).not.toBeDefined(); + Diaspora.widgets.subscribe("testing/event", function() { }); + expect(Diaspora.widgets.eventsContainer.data("events")["testing/event"]).toBeDefined(); }); - describe("subscribe", function() { - it("subscribes to an event specified by an id", function() { - expect(widgets.eventsContainer.data("events")).not.toBeDefined(); - widgets.subscribe("testing/event", function() { }); - expect(widgets.eventsContainer.data("events")["testing/event"]).toBeDefined(); - }); + it("accepts a context in which the function will always be called", function() { + var foo = "bar"; - it("accepts a context in which the function will always be called", function() { - var foo = "bar"; - widgets.subscribe("testing/context", function() { foo = this.foo; }); - widgets.publish("testing/context"); - expect(foo).toEqual(undefined); + Diaspora.widgets.subscribe("testing/context", function() { foo = this.foo; }); + Diaspora.widgets.publish("testing/context"); + expect(foo).toEqual(undefined); - widgets.subscribe("testing/context_", function() { foo = this.foo; }, { foo: "hello" }); - widgets.publish("testing/context_"); - expect(foo).toEqual("hello"); - }); + Diaspora.widgets.subscribe("testing/context_", function() { foo = this.foo; }, { foo: "hello" }); + Diaspora.widgets.publish("testing/context_"); + expect(foo).toEqual("hello"); }); + }); - describe("publish", function() { - it("triggers events that are related to the specified id", function() { - var called = false; + describe("publish", function() { + it("triggers events that are related to the specified id", function() { + var called = false; - widgets.subscribe("testing/event", function() { - called = true; - }); - - widgets.publish("testing/event"); - - expect(called).toBeTruthy(); + Diaspora.widgets.subscribe("testing/event", function() { + called = true; }); + + Diaspora.widgets.publish("testing/event"); + + expect(called).toBeTruthy(); }); }); }); diff --git a/spec/javascripts/widgets/alert-spec.js b/spec/javascripts/widgets/alert-spec.js new file mode 100644 index 000000000..fdc99698d --- /dev/null +++ b/spec/javascripts/widgets/alert-spec.js @@ -0,0 +1,26 @@ +describe("Diaspora", function() { + describe("widgets", function() { + describe("alert", function() { + beforeEach(function() { + $(document).trigger("close.facebox"); + }); + + describe("on widget ready", function() { + it("should attach an event which will close detach the element from the DOM to close.facebox", function() { + Diaspora.widgets.alert.alert("YEAH", "YEAHH"); + expect($("#diaspora_alert").length).toEqual(1); + $(document).trigger("close.facebox"); + expect($("#diaspora_alert").length).toEqual(0); + }); + + }); + describe("alert", function() { + it("should render a mustache template and append it the body", function() { + Diaspora.widgets.alert.alert("YO", "YEAH"); + expect($("#diaspora_alert").length).toEqual(1); + $(document).trigger("close.facebox"); + }); + }); + }); + }); +}); diff --git a/spec/javascripts/widgets/aspect-nav.js b/spec/javascripts/widgets/aspect-nav.js new file mode 100644 index 000000000..6ea91bc72 --- /dev/null +++ b/spec/javascripts/widgets/aspect-nav.js @@ -0,0 +1,9 @@ +describe("Diaspora", function() { + describe("widgets", function() { + describe("aspectNav", function() { + describe("start", function() { + + }); + }); + }); +}); diff --git a/spec/javascripts/widgets/embedder-spec.js b/spec/javascripts/widgets/embedder-spec.js new file mode 100644 index 000000000..762e7a9c4 --- /dev/null +++ b/spec/javascripts/widgets/embedder-spec.js @@ -0,0 +1,65 @@ +/* Copyright (c) 2010, Diaspora Inc. This file is + * licensed under the Affero General Public License version 3 or later. See + * the COPYRIGHT file. + */ + +describe("Diaspora", function() { + describe("widgets", function() { + describe("embedder", function() { + describe("services", function() { + it("is an object containing all the supported services", function() { + expect(typeof Diaspora.widgets.embedder.services === "object").toBeTruthy(); + }); + }); + describe("register", function() { + it("adds a service and it's template to Diaspora.widgets.embedder.services", function() { + expect(typeof Diaspora.widgets.embedder.services["ohaibbq"] === "undefined").toBeTruthy(); + Diaspora.widgets.embedder.register("ohaibbq", "sup guys"); + expect(typeof Diaspora.widgets.embedder.services["ohaibbq"] === "undefined").toBeFalsy(); + }); + }); + describe("render", function() { + beforeEach(function(){ + Diaspora.widgets.embedder.registerServices(); + }); + it("renders the specified mustache template", function() { + var template = Diaspora.widgets.embedder.render("youtube.com", {"video-id": "asdf"}); + expect(template.length > 0).toBeTruthy(); + expect(typeof template === "string").toBeTruthy(); + }); + it("renders the 'undefined' template if the service is not found", function() { + var template = Diaspora.widgets.embedder.render("yoimmafakeservice", {host: "yo"}); + expect(template).toEqual(Diaspora.widgets.embedder.render("undefined", {host: "yo"})); + }); + }); + describe("embed", function() { + beforeEach(function() { + $("#jasmine_content").html( + '