Skip to content
Extraits de code Groupes Projets
Valider 8039ab31 rédigé par Dan Hansen's avatar Dan Hansen
Parcourir les fichiers

publisher is now a hot widget

parent d533f46c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -48,7 +48,7 @@ javascripts: ...@@ -48,7 +48,7 @@ javascripts:
- public/javascripts/aspect-edit.js - public/javascripts/aspect-edit.js
- public/javascripts/contact-list.js - public/javascripts/contact-list.js
home: home:
- public/javascripts/publisher.js - public/javascripts/widgets/publisher.js
- public/javascripts/aspect-filters.js - public/javascripts/aspect-filters.js
- public/javascripts/contact-list.js - public/javascripts/contact-list.js
people: people:
......
/* Copyright (c) 2010, Diaspora Inc. This file is
* licensed under the Affero General Public License version 3 or later. See
* the COPYRIGHT file.
*/
(function() {
var Publisher = function() {
var self = this;
this.start = function() {
this.$publisher = $("#publisher");
this.$realMessage = this.$publisher.find("#status_message_message");
this.$fakeMessage = this.$publisher.find("#status_message_fake_message");
if(this.$fakeMessage.val() === "") {
this.toggle();
}
$("div.public_toggle input").live("click", function(evt) {
$("#publisher_service_icons").toggleClass("dim");
if (this.checked) {
$(".question_mark").click();
}
});
self
.$publisher
.find("textarea")
.focus(self.toggle)
.blur(self.toggle);
self
.$fakeMessage
.change(self.updateHiddenField);
self.updateHiddenField();
};
this.toggle = function() {
self
.$publisher
.toggleClass("closed")
.find(".options_and_submit")
.toggle(
!self.$publisher.hasClass("closed")
);
self
.$fakeMessage
.css("min-height", (self.$publisher.hasClass("closed"))
? ""
: "42px");
};
this.updateHiddenField = function() {
self
.$realMessage
.val(
self.$fakeMessage.val()
);
};
};
Diaspora.widgets.add("publisher", Publisher);
})();
/* Copyright (c) 2010, Diaspora Inc. This file is /* Copyright (c) 2010, Diaspora Inc. This file is
* licensed under the Affero General Public License version 3 or later. See * licensed under the Affero General Public License version 3 or later. See
* the COPYRIGHT file. * the COPYRIGHT file.
*/ */
describe("Publisher", function() { describe("Diaspora", function() {
describe("widgets", function() {
describe("initialize", function(){ describe("publisher", function() {
it("calls updateHiddenField", function(){ describe("start", function() {
spec.loadFixture('aspects_index_prefill'); it("calls updateHiddenField", function() {
spyOn(Publisher, 'updateHiddenField'); spec.loadFixture('aspects_index_prefill');
Publisher.initialize(); spyOn(Diaspora.widgets.publisher, 'updateHiddenField');
expect(Publisher.updateHiddenField).toHaveBeenCalled(); Diaspora.widgets.publisher.start();
}); expect(Diaspora.widgets.publisher.updateHiddenField).toHaveBeenCalled();
});
it("attaches updateHiddenField to the change handler on fake_message", function(){ it("attaches updateHiddenField to the change handler on fake_message", function() {
spec.loadFixture('aspects_index_prefill'); spec.loadFixture('aspects_index_prefill');
spyOn(Publisher, 'updateHiddenField'); spyOn(Diaspora.widgets.publisher, 'updateHiddenField');
Publisher.initialize(); Diaspora.widgets.publisher.start();
Publisher.form().find('#status_message_fake_message').change(); Diaspora.widgets.publisher.$fakeMessage.change();
expect(Publisher.updateHiddenField.mostRecentCall.args[0].type).toBe('change'); expect(Diaspora.widgets.publisher.updateHiddenField.mostRecentCall.args[0].type).toBe('change');
}); });
it("calls close when it does not have text", function(){ it("calls toggle when it does not have text", function() {
spec.loadFixture('aspects_index'); spec.loadFixture('aspects_index');
spyOn(Publisher, 'close'); spyOn(Diaspora.widgets.publisher, 'toggle');
Publisher.initialize(); Diaspora.widgets.publisher.start();
expect(Publisher.close).toHaveBeenCalled(); expect(Diaspora.widgets.publisher.toggle).toHaveBeenCalled();
}); });
it("does not call close when there is prefilled text", function(){ it("does not call toggle when there is prefilled text", function() {
spec.loadFixture('aspects_index_prefill'); spec.loadFixture('aspects_index_prefill');
spyOn(Publisher, 'close'); spyOn(Diaspora.widgets.publisher, 'toggle');
Publisher.initialize(); Diaspora.widgets.publisher.start();
expect(Publisher.close).wasNotCalled(); expect(Diaspora.widgets.publisher.toggle).not.toHaveBeenCalled();
}); });
});
describe("open", function() {
beforeEach(function() {
spec.loadFixture('aspects_index');
Publisher.initialize();
}); });
it("removes the closed class", function() { describe("toggle", function() {
expect(Publisher.form().hasClass('closed')).toBeTruthy(); beforeEach(function() {
Publisher.open(); spec.loadFixture('aspects_index');
expect(Publisher.form().hasClass('closed')).toBeFalsy(); Diaspora.widgets.publisher.start();
}); });
it("shows the options_and_submit div", function() { it("toggles the closed class", function() {
expect(Publisher.form().find(".options_and_submit:visible").length).toBe(0); expect(Diaspora.widgets.publisher.$publisher.hasClass('closed')).toBeTruthy();
Publisher.open(); Diaspora.widgets.publisher.toggle();
expect(Publisher.form().find(".options_and_submit:visible").length).toBe(1); expect(Diaspora.widgets.publisher.$publisher.hasClass('closed')).toBeFalsy();
});
}); expect(Diaspora.widgets.publisher.$publisher.hasClass('closed')).toBeFalsy();
describe("close", function() { Diaspora.widgets.publisher.toggle();
beforeEach(function() { expect(Diaspora.widgets.publisher.$publisher.hasClass('closed')).toBeTruthy;
spec.loadFixture('aspects_index_prefill');
Publisher.initialize();
});
it("adds the closed class", function() {
expect(Publisher.form().hasClass('closed')).toBeFalsy();
Publisher.close();
expect(Publisher.form().hasClass('closed')).toBeTruthy();
}); });
it("hides the options_and_submit div", function() {
expect(Publisher.form().find(".options_and_submit:visible").length).toBe(1); it("toggles the options_and_submit div", function() {
Publisher.close(); expect(Diaspora.widgets.publisher.$publisher.find(".options_and_submit").is(":visible")).toBeFalsy();
expect(Publisher.form().find(".options_and_submit:visible").length).toBe(0); Diaspora.widgets.publisher.toggle();
expect(Diaspora.widgets.publisher.$publisher.find(".options_and_submit").is(":visible")).toBeTruthy();
expect(Diaspora.widgets.publisher.$publisher.find(".options_and_submit").is(":visible")).toBeTruthy();
Diaspora.widgets.publisher.toggle();
expect(Diaspora.widgets.publisher.$publisher.find(".options_and_submit").is(":visible")).toBeFalsy();
}); });
});
describe("updateHiddenField", function(){
beforeEach(function(){
spec.loadFixture('aspects_index_prefill');
}); });
it("copies the value of fake_message to message",function(){ describe("updateHiddenField", function() {
Publisher.updateHiddenField(); beforeEach(function() {
expect(Publisher.form().find('#status_message_message').val()).toBe( spec.loadFixture('aspects_index_prefill');
Publisher.form().find('#status_message_fake_message').val()); });
it("copies the value of fake_message to message", function() {
Diaspora.widgets.publisher.updateHiddenField();
expect(Diaspora.widgets.publisher.$realMessage.val()).toBe(
Diaspora.widgets.publisher.$fakeMessage.val());
});
}); });
}); });
}); });
});
\ No newline at end of file
...@@ -24,12 +24,12 @@ src_files: ...@@ -24,12 +24,12 @@ src_files:
- public/javascripts/widgets/embedder.js - public/javascripts/widgets/embedder.js
- public/javascripts/widgets/i18n.js - public/javascripts/widgets/i18n.js
- public/javascripts/widgets/timeago.js - public/javascripts/widgets/timeago.js
- public/javascripts/widgets/publisher.js
- public/javascripts/mobile.js - public/javascripts/mobile.js
- public/javascripts/aspect-edit.js - public/javascripts/aspect-edit.js
- public/javascripts/aspect-contacts.js - public/javascripts/aspect-contacts.js
- public/javascripts/web-socket-receiver.js - public/javascripts/web-socket-receiver.js
- public/javascripts/view.js - public/javascripts/view.js
- public/javascripts/publisher.js
- public/javascripts/stream.js - public/javascripts/stream.js
- public/javascripts/validation.js - public/javascripts/validation.js
- public/javascripts/rails.js - public/javascripts/rails.js
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter