Merge branch 'master' of github.com:diaspora/diaspora

This commit is contained in:
Sarah Mei 2011-09-03 13:23:27 -07:00
commit c8046842c0
3 changed files with 143 additions and 110 deletions

View file

@ -1,39 +1,55 @@
/* /*!
* jQuery Expander plugin * jQuery Expander Plugin v0.7
* Version 0.4 (12/09/2008)
* @requires jQuery v1.1.1+
* *
* Dual licensed under the MIT and GPL licenses: * Date: Wed Aug 31 20:53:59 2011 EDT
* Requires: jQuery v1.3+
*
* Copyright 2011, Karl Swedberg
* Dual licensed under the MIT and GPL licenses (just like jQuery):
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* * source: https://github.com/kswedberg/jquery-expander/
*/ */
(function($) { (function($) {
$.fn.expander = function(options) { $.fn.expander = function(options) {
var opts = $.extend({}, $.fn.expander.defaults, options); var opts = $.extend({}, $.fn.expander.defaults, options),
var delayedCollapse; rSlash = /\//,
return this.each(function() { delayedCollapse;
var $this = $(this);
var o = $.meta ? $.extend({}, opts, $this.data()) : opts; this.each(function() {
var cleanedTag, startTags, endTags; var cleanedTag, startTags, endTags,
var allText = $this.html(); thisEl = this,
var startText = allText.slice(0, o.slicePoint).replace(/\w+$/,''); $this = $(this),
o = $.meta ? $.extend({}, opts, $this.data()) : opts,
expandSpeed = o.expandSpeed || 0,
allText = $this.html(),
startText = allText.slice(0, o.slicePoint).replace(/(&([^;]+;)?|\w+)$/,'');
startTags = startText.match(/<\w[^>]*>/g); startTags = startText.match(/<\w[^>]*>/g);
if (startTags) {startText = allText.slice(0,o.slicePoint + startTags.join('').length).replace(/\w+$/,'');}
if (startTags) {
startText = allText.slice(0,o.slicePoint + startTags.join('').length).replace(/(&([^;]+;)?|\w+)$/,'');
}
if (startText.lastIndexOf('<') > startText.lastIndexOf('>') ) { if (startText.lastIndexOf('<') > startText.lastIndexOf('>') ) {
startText = startText.slice(0,startText.lastIndexOf('<')); startText = startText.slice(0,startText.lastIndexOf('<'));
} }
var defined = {};
$.each(['onSlice','beforeExpand', 'afterExpand', 'onCollapse'], function(index, val) {
defined[val] = $.isFunction(o[val]);
});
var endText = allText.slice(startText.length); var endText = allText.slice(startText.length);
// create necessary expand/collapse elements if they don't already exist // create necessary expand/collapse elements if they don't already exist
if (!$('span.details', this).length) { if (!$(this).find('span.details').length) {
// end script if text length isn't long enough. // end script if text length isn't long enough.
if ( endText.replace(/\s+$/,'').split(' ').length < o.widow ) { return; } if ( endText.replace(/\s+$/,'').split(' ').length < o.widow || allText.length < o.slicePoint ) { return; }
// otherwise, continue... // otherwise, continue...
if (defined.onSlice) { o.onSlice.call(thisEl); }
if (endText.indexOf('</') > -1) { if (endText.indexOf('</') > -1) {
endTags = endText.match(/<(\/)?[^>]*>/g); endTags = endText.match(/<(\/)?[^>]*>/g);
for (var i=0; i < endTags.length; i++) { for (var i=0; i < endTags.length; i++) {
@ -41,8 +57,8 @@
if (endTags[i].indexOf('</') > -1) { if (endTags[i].indexOf('</') > -1) {
var startTag, startTagExists = false; var startTag, startTagExists = false;
for (var j=0; j < i; j++) { for (var j=0; j < i; j++) {
startTag = endTags[j].slice(0, endTags[j].indexOf(' ')).replace(/(\w)$/,'$1>'); startTag = endTags[j].slice(0, endTags[j].indexOf(' ')).replace(/\w$/,'$1>');
if (startTag == rSlash(endTags[i])) { if (startTag == endTags[i].replace(rSlash,'')) {
startTagExists = true; startTagExists = true;
} }
} }
@ -50,12 +66,12 @@
startText = startText + endTags[i]; startText = startText + endTags[i];
var matched = false; var matched = false;
for (var s=startTags.length - 1; s >= 0; s--) { for (var s=startTags.length - 1; s >= 0; s--) {
if (startTags[s].slice(0, startTags[s].indexOf(' ')).replace(/(\w)$/,'$1>') == rSlash(endTags[i]) if (startTags[s].slice(0, startTags[s].indexOf(' ')).replace(/(\w)$/,'$1>') == endTags[i].replace(rSlash,'') &&
&& matched == false) { !matched ) {
cleanedTag = cleanedTag ? startTags[s] + cleanedTag : startTags[s]; cleanedTag = cleanedTag ? startTags[s] + cleanedTag : startTags[s];
matched = true; matched = true;
} }
}; }
} }
} }
} }
@ -76,77 +92,94 @@
].join('') ].join('')
); );
} }
var $thisDetails = $('span.details', this),
$readMore = $('span.read-more', this); var $thisDetails = $(this).find('span.details'),
$readMore = $(this).find('span.read-more');
$thisDetails.hide(); $thisDetails.hide();
$readMore.find('a').click(function() { $readMore.find('a').bind('click.expander', function(event) {
event.preventDefault();
$readMore.hide(); $readMore.hide();
if (defined.beforeExpand) {
if (o.expandEffect === 'show' && !o.expandSpeed) { o.beforeExpand.call(thisEl);
o.beforeExpand($this);
$thisDetails.show();
o.afterExpand($this);
delayCollapse(o, $thisDetails);
} else {
o.beforeExpand($this);
$thisDetails[o.expandEffect](o.expandSpeed, function() {
$thisDetails.css({zoom: ''});
o.afterExpand($this);
delayCollapse(o, $thisDetails);
});
} }
return false;
});
if (o.userCollapse) {
$this
.find('span.details').append('<span class="re-collapse">' + o.userCollapsePrefix + '<a href="#">' + o.userCollapseText + '</a></span>');
$this.find('span.re-collapse a').click(function() {
$thisDetails[o.expandEffect](expandSpeed, function() {
$thisDetails.css({zoom: ''});
if (defined.afterExpand) {o.afterExpand.call(thisEl);}
delayCollapse(o, $thisDetails, thisEl);
});
});
if ( o.userCollapse && !$this.find('span.re-collapse').length ) {
$this
.find('span.details')
.append('<span class="re-collapse">' + o.userCollapsePrefix + '<a href="#">' + o.userCollapseText + '</a></span>');
$this.find('span.re-collapse a').bind('click.expander', function(event) {
event.preventDefault();
clearTimeout(delayedCollapse); clearTimeout(delayedCollapse);
var $detailsCollapsed = $(this).parents('span.details'); var $detailsCollapsed = $(this).parents('span.details');
reCollapse($detailsCollapsed); reCollapse($detailsCollapsed);
o.onCollapse($this, true); if (defined.onCollapse) {
return false; o.onCollapse.call(thisEl, true);
}
}); });
} }
}); });
function reCollapse(el) { function reCollapse(el) {
el.hide() el.hide()
.prev('span.read-more').show(); .prev('span.read-more').show();
} }
function delayCollapse(option, $collapseEl) { function delayCollapse(option, $collapseEl, thisEl) {
if (option.collapseTimer) { if (option.collapseTimer) {
delayedCollapse = setTimeout(function() { delayedCollapse = setTimeout(function() {
reCollapse($collapseEl); reCollapse($collapseEl);
option.onCollapse($collapseEl.parent(), false); if ( $.isFunction(option.onCollapse) ) {
}, option.onCollapse.call(thisEl, false);
option.collapseTimer }
); }, option.collapseTimer);
} }
} }
function rSlash(rString) {
return rString.replace(/\//,''); return this;
}
}; };
// plugin defaults // plugin defaults
$.fn.expander.defaults = { $.fn.expander.defaults = {
slicePoint: 100, // the number of characters at which the contents will be sliced into two parts. // slicePoint: the number of characters at which the contents will be sliced into two parts.
// Note: any tag names in the HTML that appear inside the sliced element before // Note: any tag names in the HTML that appear inside the sliced element before
// the slicePoint will be counted along with the text characters. // the slicePoint will be counted along with the text characters.
widow: 4, // a threshold of sorts for whether to initially hide/collapse part of the element's contents. slicePoint: 100,
// widow: a threshold of sorts for whether to initially hide/collapse part of the element's contents.
// If after slicing the contents in two there are fewer words in the second part than // If after slicing the contents in two there are fewer words in the second part than
// the value set by widow, we won't bother hiding/collapsing anything. // the value set by widow, we won't bother hiding/collapsing anything.
expandText: 'read more', // text displayed in a link instead of the hidden part of the element. widow: 4,
// text displayed in a link instead of the hidden part of the element.
// clicking this will expand/show the hidden/collapsed text // clicking this will expand/show the hidden/collapsed text
expandText: 'read more',
expandPrefix: '&hellip; ', expandPrefix: '&hellip; ',
collapseTimer: 0, // number of milliseconds after text has been expanded at which to collapse the text again
// number of milliseconds after text has been expanded at which to collapse the text again
collapseTimer: 0,
expandEffect: 'fadeIn', expandEffect: 'fadeIn',
expandSpeed: '', // speed in milliseconds of the animation effect for expanding the text expandSpeed: 250,
userCollapse: true, // allow the user to re-collapse the expanded text.
userCollapseText: '[collapse expanded text]', // text to use for the link to re-collapse the text // allow the user to re-collapse the expanded text.
userCollapse: true,
// text to use for the link to re-collapse the text
userCollapseText: '[collapse expanded text]',
userCollapsePrefix: ' ', userCollapsePrefix: ' ',
beforeExpand: function($thisEl) {},
afterExpand: function($thisEl) {},
onCollapse: function($thisEl, byUser) {} // all callback functions have the this keyword mapped to the element in the jQuery set when .expander() is called
onSlice: null, // function() {}
beforeExpand: null, // function() {},
afterExpand: null, // function() {},
onCollapse: null // function(byUser) {}
}; };
})(jQuery); })(jQuery);

View file

@ -14,12 +14,12 @@
self.deleteCommentLink.click(self.removeComment); self.deleteCommentLink.click(self.removeComment);
self.deleteCommentLink.tipsy({ trigger: "hover" }); self.deleteCommentLink.tipsy({ trigger: "hover" });
self.content.expander({ // self.content.expander({
slicePoint: 200, // slicePoint: 200,
widow: 18, // widow: 18,
expandText: Diaspora.I18n.t("show_more"), // expandText: Diaspora.I18n.t("show_more"),
userCollapse: false // userCollapse: false
}); // });
self.globalSubscribe("likes/" + self.comment.attr('id') + "/updated", function(){ self.globalSubscribe("likes/" + self.comment.attr('id') + "/updated", function(){
self.likes = self.instantiate("Likes", self.comment.find(".likes_container")); self.likes = self.instantiate("Likes", self.comment.find(".likes_container"));

View file

@ -27,12 +27,12 @@
self.postScope.tipsy({ trigger: "hover" }); self.postScope.tipsy({ trigger: "hover" });
// collapse long posts // collapse long posts
self.content.expander({ // self.content.expander({
slicePoint: 400, // slicePoint: 400,
widow: 12, // widow: 12,
expandText: Diaspora.I18n.t("show_more"), // expandText: Diaspora.I18n.t("show_more"),
userCollapse: false // userCollapse: false
}); // });
self.globalSubscribe("likes/" + self.postGuid + "/updated", function() { self.globalSubscribe("likes/" + self.postGuid + "/updated", function() {
self.likes = self.instantiate("Likes", self.post.find(".likes_container:first")); self.likes = self.instantiate("Likes", self.post.find(".likes_container:first"));