publisher is now a hot widget
This commit is contained in:
parent
d533f46cd7
commit
8039ab312a
4 changed files with 140 additions and 74 deletions
|
|
@ -48,7 +48,7 @@ javascripts:
|
|||
- public/javascripts/aspect-edit.js
|
||||
- public/javascripts/contact-list.js
|
||||
home:
|
||||
- public/javascripts/publisher.js
|
||||
- public/javascripts/widgets/publisher.js
|
||||
- public/javascripts/aspect-filters.js
|
||||
- public/javascripts/contact-list.js
|
||||
people:
|
||||
|
|
|
|||
68
public/javascripts/widgets/publisher.js
Normal file
68
public/javascripts/widgets/publisher.js
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/* 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);
|
||||
|
||||
})();
|
||||
|
|
@ -1,81 +1,79 @@
|
|||
/* Copyright (c) 2010, Diaspora Inc. This file is
|
||||
* licensed under the Affero General Public License version 3 or later. See
|
||||
* the COPYRIGHT file.
|
||||
*/
|
||||
* licensed under the Affero General Public License version 3 or later. See
|
||||
* the COPYRIGHT file.
|
||||
*/
|
||||
|
||||
describe("Publisher", function() {
|
||||
describe("Diaspora", function() {
|
||||
describe("widgets", function() {
|
||||
describe("publisher", function() {
|
||||
describe("start", function() {
|
||||
it("calls updateHiddenField", function() {
|
||||
spec.loadFixture('aspects_index_prefill');
|
||||
spyOn(Diaspora.widgets.publisher, 'updateHiddenField');
|
||||
Diaspora.widgets.publisher.start();
|
||||
expect(Diaspora.widgets.publisher.updateHiddenField).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("initialize", function(){
|
||||
it("calls updateHiddenField", function(){
|
||||
spec.loadFixture('aspects_index_prefill');
|
||||
spyOn(Publisher, 'updateHiddenField');
|
||||
Publisher.initialize();
|
||||
expect(Publisher.updateHiddenField).toHaveBeenCalled();
|
||||
it("attaches updateHiddenField to the change handler on fake_message", function() {
|
||||
spec.loadFixture('aspects_index_prefill');
|
||||
spyOn(Diaspora.widgets.publisher, 'updateHiddenField');
|
||||
Diaspora.widgets.publisher.start();
|
||||
Diaspora.widgets.publisher.$fakeMessage.change();
|
||||
expect(Diaspora.widgets.publisher.updateHiddenField.mostRecentCall.args[0].type).toBe('change');
|
||||
});
|
||||
|
||||
it("calls toggle when it does not have text", function() {
|
||||
spec.loadFixture('aspects_index');
|
||||
spyOn(Diaspora.widgets.publisher, 'toggle');
|
||||
Diaspora.widgets.publisher.start();
|
||||
expect(Diaspora.widgets.publisher.toggle).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not call toggle when there is prefilled text", function() {
|
||||
spec.loadFixture('aspects_index_prefill');
|
||||
spyOn(Diaspora.widgets.publisher, 'toggle');
|
||||
Diaspora.widgets.publisher.start();
|
||||
expect(Diaspora.widgets.publisher.toggle).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
describe("toggle", function() {
|
||||
beforeEach(function() {
|
||||
spec.loadFixture('aspects_index');
|
||||
Diaspora.widgets.publisher.start();
|
||||
});
|
||||
it("toggles the closed class", function() {
|
||||
expect(Diaspora.widgets.publisher.$publisher.hasClass('closed')).toBeTruthy();
|
||||
Diaspora.widgets.publisher.toggle();
|
||||
expect(Diaspora.widgets.publisher.$publisher.hasClass('closed')).toBeFalsy();
|
||||
|
||||
expect(Diaspora.widgets.publisher.$publisher.hasClass('closed')).toBeFalsy();
|
||||
Diaspora.widgets.publisher.toggle();
|
||||
expect(Diaspora.widgets.publisher.$publisher.hasClass('closed')).toBeTruthy;
|
||||
});
|
||||
|
||||
it("toggles the options_and_submit div", function() {
|
||||
expect(Diaspora.widgets.publisher.$publisher.find(".options_and_submit").is(":visible")).toBeFalsy();
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
it("attaches updateHiddenField to the change handler on fake_message", function(){
|
||||
spec.loadFixture('aspects_index_prefill');
|
||||
spyOn(Publisher, 'updateHiddenField');
|
||||
Publisher.initialize();
|
||||
Publisher.form().find('#status_message_fake_message').change();
|
||||
expect(Publisher.updateHiddenField.mostRecentCall.args[0].type).toBe('change');
|
||||
});
|
||||
describe("updateHiddenField", function() {
|
||||
beforeEach(function() {
|
||||
spec.loadFixture('aspects_index_prefill');
|
||||
});
|
||||
|
||||
it("calls close when it does not have text", function(){
|
||||
spec.loadFixture('aspects_index');
|
||||
spyOn(Publisher, 'close');
|
||||
Publisher.initialize();
|
||||
expect(Publisher.close).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not call close when there is prefilled text", function(){
|
||||
spec.loadFixture('aspects_index_prefill');
|
||||
spyOn(Publisher, 'close');
|
||||
Publisher.initialize();
|
||||
expect(Publisher.close).wasNotCalled();
|
||||
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());
|
||||
});
|
||||
});
|
||||
describe("open", function() {
|
||||
beforeEach(function() {
|
||||
spec.loadFixture('aspects_index');
|
||||
Publisher.initialize();
|
||||
});
|
||||
it("removes the closed class", function() {
|
||||
expect(Publisher.form().hasClass('closed')).toBeTruthy();
|
||||
Publisher.open();
|
||||
expect(Publisher.form().hasClass('closed')).toBeFalsy();
|
||||
});
|
||||
it("shows the options_and_submit div", function() {
|
||||
expect(Publisher.form().find(".options_and_submit:visible").length).toBe(0);
|
||||
Publisher.open();
|
||||
expect(Publisher.form().find(".options_and_submit:visible").length).toBe(1);
|
||||
});
|
||||
});
|
||||
describe("close", function() {
|
||||
beforeEach(function() {
|
||||
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);
|
||||
Publisher.close();
|
||||
expect(Publisher.form().find(".options_and_submit:visible").length).toBe(0);
|
||||
});
|
||||
});
|
||||
describe("updateHiddenField", function(){
|
||||
beforeEach(function(){
|
||||
spec.loadFixture('aspects_index_prefill');
|
||||
});
|
||||
|
||||
it("copies the value of fake_message to message",function(){
|
||||
Publisher.updateHiddenField();
|
||||
expect(Publisher.form().find('#status_message_message').val()).toBe(
|
||||
Publisher.form().find('#status_message_fake_message').val());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -24,12 +24,12 @@ src_files:
|
|||
- public/javascripts/widgets/embedder.js
|
||||
- public/javascripts/widgets/i18n.js
|
||||
- public/javascripts/widgets/timeago.js
|
||||
- public/javascripts/widgets/publisher.js
|
||||
- public/javascripts/mobile.js
|
||||
- public/javascripts/aspect-edit.js
|
||||
- public/javascripts/aspect-contacts.js
|
||||
- public/javascripts/web-socket-receiver.js
|
||||
- public/javascripts/view.js
|
||||
- public/javascripts/publisher.js
|
||||
- public/javascripts/stream.js
|
||||
- public/javascripts/validation.js
|
||||
- public/javascripts/rails.js
|
||||
|
|
|
|||
Loading…
Reference in a new issue