Clean up stream.js, make the comments step selector more sane
This commit is contained in:
parent
c937f76433
commit
0edc160007
2 changed files with 79 additions and 74 deletions
|
|
@ -3,11 +3,11 @@ When /^I focus the comment field$/ do
|
||||||
end
|
end
|
||||||
|
|
||||||
Then /^the first comment field should be open/ do
|
Then /^the first comment field should be open/ do
|
||||||
css_query = "$('#main_stream .stream_element:first .submit_button .comment_submit.button:visible')"
|
css_query = "$('#main_stream .stream_element:first ul.comments:visible')"
|
||||||
page.evaluate_script("#{css_query}.length").should == 1
|
page.evaluate_script("#{css_query}.length").should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
Then /^the first comment field should be closed$/ do
|
Then /^the first comment field should be closed$/ do
|
||||||
css_query = "$('#main_stream .stream_element:first .submit_button .comment_submit.button:hidden')"
|
css_query = "$('#main_stream .stream_element:first ul.comments:hidden')"
|
||||||
page.evaluate_script("#{css_query}.length").should == 1
|
page.evaluate_script("#{css_query}.length").should == 1
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,123 +4,126 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Stream = {
|
var Stream = {
|
||||||
|
selector: "#main_stream",
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
var stream_string = '#main_stream';
|
console.log(this);
|
||||||
var $stream = $(stream_string);
|
|
||||||
|
|
||||||
$(".status_message_delete").tipsy({trigger: 'hover', gravity: 'n'});
|
|
||||||
|
|
||||||
Diaspora.widgets.subscribe("stream/reloaded", Stream.initialized);
|
|
||||||
Diaspora.widgets.timeago.updateTimeAgo();
|
Diaspora.widgets.timeago.updateTimeAgo();
|
||||||
Diaspora.widgets.directionDetector.updateBinds();
|
Diaspora.widgets.directionDetector.updateBinds();
|
||||||
|
|
||||||
|
$(".status_message_delete").tipsy({
|
||||||
|
trigger: "hover",
|
||||||
|
gravity: "n"
|
||||||
|
});
|
||||||
|
|
||||||
$(stream_string + " a.show_post_comments:not(.show)").live("click", Stream.toggleComments);
|
$("a.show_post_comments:not(.show)", this.selector).click(Stream.toggleComments);
|
||||||
//audio linx
|
|
||||||
|
//audio links
|
||||||
Stream.setUpAudioLinks();
|
Stream.setUpAudioLinks();
|
||||||
//Stream.setUpImageLinks();
|
//Stream.setUpImageLinks();
|
||||||
|
|
||||||
|
|
||||||
|
console.log(this, $(".focus_comment_textarea").length, $(".focus_comment_textarea", this.selector), this.selector);
|
||||||
// comment link form focus
|
// comment link form focus
|
||||||
$(stream_string + " .focus_comment_textarea").live("click", function(e){
|
$(".focus_comment_textarea", this.selector).click(function(evt) {
|
||||||
Stream.focusNewComment($(this), e);
|
Stream.focusNewComment($(this), evt);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(stream_string + " textarea.comment_box").live("focus", function(evt) {
|
$("textarea.comment_box", this.selector).bind("focus blur", function(evt) {
|
||||||
var commentBox = $(this);
|
var commentBox = $(this);
|
||||||
commentBox
|
commentBox
|
||||||
.attr('rows',2)
|
.attr("rows", (evt.type === "focus") ? 2 : 1)
|
||||||
.parent().parent()
|
.parent().parent()
|
||||||
.addClass('open');
|
.toggleClass("open");
|
||||||
});
|
});
|
||||||
|
|
||||||
$(stream_string + " textarea.comment_box").live("blur", function(evt) {
|
$("a.expand_likes", this.selector).click(function(evt) {
|
||||||
var commentBox = $(this);
|
|
||||||
if (!commentBox.val()) {
|
|
||||||
commentBox
|
|
||||||
.attr('rows',1)
|
|
||||||
.css('height','1.4em')
|
|
||||||
.parent().parent()
|
|
||||||
.removeClass('open');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// like/dislike
|
|
||||||
$(stream_string + " a.expand_likes").live("click", function(evt) {
|
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
$(this).siblings('.likes_list').fadeToggle('fast');
|
$(this).siblings(".likes_list").fadeToggle("fast");
|
||||||
});
|
});
|
||||||
|
|
||||||
$(stream_string + " a.expand_dislikes").live("click", function(evt) {
|
$("a.expand_dislikes", this.selector).click(function(evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
$(this).siblings('.dislikes_list').fadeToggle('fast');
|
$(this).siblings(".dislikes_list").fadeToggle("fast");
|
||||||
});
|
});
|
||||||
|
|
||||||
// reshare button action
|
// reshare button action
|
||||||
$(stream_string + ' .reshare_button').live("click", function(evt) {
|
$(".reshare_button", this.selector).click(function(evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
var button = $(this);
|
var button = $(this),
|
||||||
var box = button.siblings(".reshare_box");
|
box = button.siblings(".reshare_box");
|
||||||
|
|
||||||
if (box.length > 0) {
|
if (box.length > 0) {
|
||||||
button.toggleClass("active");
|
button.toggleClass("active");
|
||||||
box.toggle();
|
box.toggle();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(stream_string + ".new_comment").live('ajax:failure', function(data, html, xhr) {
|
$(".new_comment", this.selector).bind("ajax:failure", function() {
|
||||||
Diaspora.widgets.alert.alert(Diaspora.widgets.i18n.t('failed_to_post_message'));
|
Diaspora.widgets.alert.alert(Diaspora.widgets.i18n.t("failed_to_post_message"));
|
||||||
});
|
});
|
||||||
|
|
||||||
$stream.find(".comment_delete", ".comment").live('ajax:success', function(data, html, xhr) {
|
$(".comment .comment_delete", this.selector).bind("ajax:success", function() {
|
||||||
var element = $(this),
|
var element = $(this),
|
||||||
target = element.parents(".comment"),
|
target = element.parents(".comment"),
|
||||||
post = element.closest('.stream_element'),
|
post = element.closest(".stream_element"),
|
||||||
toggler = post.find('.show_post_comments');
|
toggler = post.find(".show_post_comments");
|
||||||
|
|
||||||
target.hide('blind', { direction: 'vertical' }, 300, function(){
|
target.hide("blind", { direction: "vertical" }, 300, function() {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
toggler.html(
|
toggler.html(
|
||||||
toggler.html().replace(/\d+/,$('.comments', post).find('li').length -1)
|
toggler.html().replace(/\d+/, $(".comments li", post).length - 1)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// collapse long comments
|
// collapse long comments
|
||||||
$(stream_string + " .content").find("p").expander({
|
$(".content p", this.selector).expander({
|
||||||
slicePoint: 400,
|
slicePoint: 400,
|
||||||
widow: 12,
|
widow: 12,
|
||||||
expandText: Diaspora.widgets.i18n.t('show_more'),
|
expandText: Diaspora.widgets.i18n.t("show_more"),
|
||||||
userCollapse: false
|
userCollapse: false
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setUpLikes: function(){
|
|
||||||
var likes = $("#main_stream .like_it, #main_stream .dislike_it");
|
|
||||||
|
|
||||||
likes.live('ajax:loading', function(data, json, xhr) {
|
setUpLikes: function() {
|
||||||
$(this).parent().fadeOut('fast');
|
var likes = $(".like_it, .dislike_it", this.selector);
|
||||||
|
|
||||||
|
likes.bind("ajax:loading", function() {
|
||||||
|
$(this).parent().fadeOut("fast");
|
||||||
});
|
});
|
||||||
|
|
||||||
likes.live('ajax:failure', function(data, html, xhr) {
|
likes.bind("ajax:failure", function() {
|
||||||
Diaspora.widgets.alert.alert(Diaspora.widgets.i18n.t('failed_to_like'));
|
Diaspora.widgets.alert.alert(Diaspora.widgets.i18n.t("failed_to_like"));
|
||||||
$(this).parent().fadeIn('fast');
|
$(this).parent().fadeIn("fast");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
setUpAudioLinks: function(){
|
setUpAudioLinks: function() {
|
||||||
$(".stream a[target='_blank']").each(function(){
|
$(".stream a[target='_blank']").each(function() {
|
||||||
var link = $(this);
|
var link = $(this);
|
||||||
if(link.attr('href').match(/\.mp3$|\.ogg$/)) {
|
if(this.href.match(/\.mp3$|\.ogg$/)) {
|
||||||
link.parent().append("<audio preload='none' src='" + this.href + "' controls='controls'>mom</audio>");
|
$("<audio/>", {
|
||||||
|
preload: "none",
|
||||||
|
src: this.href,
|
||||||
|
controls: "controls"
|
||||||
|
}).appendTo(link.parent());
|
||||||
|
|
||||||
link.remove();
|
link.remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
setUpImageLinks: function(){
|
setUpImageLinks: function() {
|
||||||
$(".stream a[target='_blank']").each(function(){
|
$(".stream a[target='_blank']").each(function() {
|
||||||
var link = $(this);
|
var link = $(this);
|
||||||
if(link.attr('href').match(/\.gif$|\.jpg$|\.png$|\.jpeg$/)) {
|
if(this.href.match(/\.gif$|\.jpg$|\.png$|\.jpeg$/)) {
|
||||||
link.parent().append("<img src='" + this.href + "'</img>");
|
$("<img/>", {
|
||||||
|
src: this.href
|
||||||
|
}).appendTo(link.parent());
|
||||||
|
|
||||||
link.remove();
|
link.remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -129,8 +132,7 @@ var Stream = {
|
||||||
toggleComments: function(evt) {
|
toggleComments: function(evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
text = $this.html(),
|
showUl = $(this).closest("li"),
|
||||||
showUl = $(this).closest('li'),
|
|
||||||
commentBlock = $this.closest(".stream_element").find("ul.comments", ".content"),
|
commentBlock = $this.closest(".stream_element").find("ul.comments", ".content"),
|
||||||
commentBlockMore = $this.closest(".stream_element").find(".older_comments", ".content")
|
commentBlockMore = $this.closest(".stream_element").find(".older_comments", ".content")
|
||||||
|
|
||||||
|
|
@ -139,16 +141,16 @@ var Stream = {
|
||||||
commentBlockMore.removeClass("inactive");
|
commentBlockMore.removeClass("inactive");
|
||||||
commentBlockMore.removeClass("hidden");
|
commentBlockMore.removeClass("hidden");
|
||||||
});
|
});
|
||||||
$this.html(Diaspora.widgets.i18n.t('comments.hide'));
|
$this.html(Diaspora.widgets.i18n.t("comments.hide"));
|
||||||
} else {
|
} else {
|
||||||
if(commentBlock.hasClass("hidden")) {
|
if(commentBlock.hasClass("hidden")) {
|
||||||
commentBlock.removeClass('hidden');
|
commentBlock.removeClass("hidden");
|
||||||
showUl.css('margin-bottom','-1em');
|
showUl.css("margin-bottom","-1em");
|
||||||
$this.html(Diaspora.widgets.i18n.t('comments.hide'));
|
$this.html(Diaspora.widgets.i18n.t("comments.hide"));
|
||||||
}else{
|
}else{
|
||||||
commentBlock.addClass('hidden');
|
commentBlock.addClass("hidden");
|
||||||
showUl.css('margin-bottom','1em');
|
showUl.css("margin-bottom","1em");
|
||||||
$this.html(Diaspora.widgets.i18n.t('comments.show'));
|
$this.html(Diaspora.widgets.i18n.t("comments.show"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -157,17 +159,20 @@ var Stream = {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
var commentBlock = toggle.closest(".stream_element").find("ul.comments", ".content");
|
var commentBlock = toggle.closest(".stream_element").find("ul.comments", ".content");
|
||||||
|
|
||||||
if(commentBlock.hasClass('hidden')) {
|
if(commentBlock.hasClass("hidden")) {
|
||||||
commentBlock.removeClass('hidden');
|
commentBlock.removeClass("hidden");
|
||||||
commentBlock.find('textarea').focus();
|
commentBlock.find("textarea").focus();
|
||||||
} else {
|
} else {
|
||||||
if(commentBlock.children().length <= 1){
|
if(commentBlock.children().length <= 1) {
|
||||||
commentBlock.addClass('hidden');
|
commentBlock.addClass("hidden");
|
||||||
} else {
|
} else {
|
||||||
commentBlock.find('textarea').focus();
|
commentBlock.find("textarea").focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).ready(Stream.initialize);
|
$(document).ready(function() {
|
||||||
|
Diaspora.widgets.subscribe("stream/reloaded", Stream.initialize, Stream);
|
||||||
|
Diaspora.widgets.publish("stream/reloaded");
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue