mirror of https://github.com/friendica/friendica
bug fix #1135, show more is usable again
parent
4ec5974074
commit
2743514791
@ -1 +0,0 @@
|
||||
(function($){var divgrowid=0;$.fn.divgrow=function(options){var options=$.extend({},{initialHeight:100,moreText:"+ Show More",lessText:"- Show Less",speed:1e3,showBrackets:true},options);return this.each(function(){divgrowid++;obj=$(this);obj.css("height",options.initialHeight).css("overflow","hidden");if(options.showBrackets){obj.after('<p class="divgrow-brackets">[…]</p><a href="#" class="divgrow-showmore'+" divgrow-obj-"+divgrowid+'"'+"></a>")}else{obj.after('<a href="#" class="divgrow-showmore'+" divgrow-obj-"+divgrowid+'"'+"></a>")}$("a.divgrow-showmore").html(options.moreText);$("."+"divgrow-obj-"+divgrowid).toggle(function(){var fullHeight=$(this).prevAll("div:first")[0].scrollHeight+10;$(this).prevAll("div:first").animate({height:fullHeight+"px"},options.speed,function(){if(options.showBrackets){$(this).nextAll("p.divgrow-brackets:first").fadeOut()}$(this).nextAll("a.divgrow-showmore:first").html(options.lessText)})},function(){$(this).prevAll("div:first").stop(true,false).animate({height:options.initialHeight},options.speed,function(){if(options.showBrackets){$(this).nextAll("p.divgrow-brackets:first").stop(true,false).fadeIn()}$(this).nextAll("a.divgrow-showmore:first").stop(true,false).html(options.moreText)})})})}})(jQuery);
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,192 @@
|
||||
/*!
|
||||
* Readmore.js jQuery plugin
|
||||
* Author: @jed_foster
|
||||
* Project home: jedfoster.github.io/Readmore.js
|
||||
* Licensed under the MIT license
|
||||
*/
|
||||
|
||||
;(function($) {
|
||||
|
||||
var readmore = 'readmore',
|
||||
defaults = {
|
||||
speed: 100,
|
||||
maxHeight: 200,
|
||||
heightMargin: 16,
|
||||
moreLink: '<a href="#">Read More</a>',
|
||||
lessLink: '<a href="#">Close</a>',
|
||||
embedCSS: true,
|
||||
sectionCSS: 'display: block; width: 100%;',
|
||||
startOpen: false,
|
||||
expandedClass: 'readmore-js-expanded',
|
||||
collapsedClass: 'readmore-js-collapsed',
|
||||
|
||||
// callbacks
|
||||
beforeToggle: function(){},
|
||||
afterToggle: function(){}
|
||||
},
|
||||
cssEmbedded = false;
|
||||
|
||||
function Readmore( element, options ) {
|
||||
this.element = element;
|
||||
|
||||
this.options = $.extend( {}, defaults, options);
|
||||
|
||||
$(this.element).data('max-height', this.options.maxHeight);
|
||||
$(this.element).data('height-margin', this.options.heightMargin);
|
||||
|
||||
delete(this.options.maxHeight);
|
||||
|
||||
if(this.options.embedCSS && ! cssEmbedded) {
|
||||
var styles = '.readmore-js-toggle, .readmore-js-section { ' + this.options.sectionCSS + ' } .readmore-js-section { overflow: hidden; }';
|
||||
|
||||
(function(d,u) {
|
||||
var css=d.createElement('style');
|
||||
css.type = 'text/css';
|
||||
if(css.styleSheet) {
|
||||
css.styleSheet.cssText = u;
|
||||
}
|
||||
else {
|
||||
css.appendChild(d.createTextNode(u));
|
||||
}
|
||||
d.getElementsByTagName('head')[0].appendChild(css);
|
||||
}(document, styles));
|
||||
|
||||
cssEmbedded = true;
|
||||
}
|
||||
|
||||
this._defaults = defaults;
|
||||
this._name = readmore;
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
Readmore.prototype = {
|
||||
|
||||
init: function() {
|
||||
var $this = this;
|
||||
|
||||
$(this.element).each(function() {
|
||||
var current = $(this),
|
||||
maxHeight = (current.css('max-height').replace(/[^-\d\.]/g, '') > current.data('max-height')) ? current.css('max-height').replace(/[^-\d\.]/g, '') : current.data('max-height'),
|
||||
heightMargin = current.data('height-margin');
|
||||
|
||||
if(current.css('max-height') != 'none') {
|
||||
current.css('max-height', 'none');
|
||||
}
|
||||
|
||||
$this.setBoxHeight(current);
|
||||
|
||||
if(current.outerHeight(true) <= maxHeight + heightMargin) {
|
||||
// The block is shorter than the limit, so there's no need to truncate it.
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
current.addClass('readmore-js-section ' + $this.options.collapsedClass).data('collapsedHeight', maxHeight);
|
||||
|
||||
var useLink = $this.options.startOpen ? $this.options.lessLink : $this.options.moreLink;
|
||||
current.after($(useLink).on('click', function(event) { $this.toggleSlider(this, current, event) }).addClass('readmore-js-toggle'));
|
||||
|
||||
if(!$this.options.startOpen) {
|
||||
current.css({height: maxHeight});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$(window).on('resize', function(event) {
|
||||
$this.resizeBoxes();
|
||||
});
|
||||
},
|
||||
|
||||
toggleSlider: function(trigger, element, event)
|
||||
{
|
||||
event.preventDefault();
|
||||
|
||||
var $this = this,
|
||||
newHeight = newLink = sectionClass = '',
|
||||
expanded = false,
|
||||
collapsedHeight = $(element).data('collapsedHeight');
|
||||
|
||||
if ($(element).height() <= collapsedHeight) {
|
||||
newHeight = $(element).data('expandedHeight') + 'px';
|
||||
newLink = 'lessLink';
|
||||
expanded = true;
|
||||
sectionClass = $this.options.expandedClass;
|
||||
}
|
||||
|
||||
else {
|
||||
newHeight = collapsedHeight;
|
||||
newLink = 'moreLink';
|
||||
sectionClass = $this.options.collapsedClass;
|
||||
}
|
||||
|
||||
// Fire beforeToggle callback
|
||||
$this.options.beforeToggle(trigger, element, expanded);
|
||||
|
||||
$(element).animate({'height': newHeight}, {duration: $this.options.speed, complete: function() {
|
||||
// Fire afterToggle callback
|
||||
$this.options.afterToggle(trigger, element, expanded);
|
||||
|
||||
$(trigger).replaceWith($($this.options[newLink]).on('click', function(event) { $this.toggleSlider(this, element, event) }).addClass('readmore-js-toggle'));
|
||||
|
||||
$(this).removeClass($this.options.collapsedClass + ' ' + $this.options.expandedClass).addClass(sectionClass);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setBoxHeight: function(element) {
|
||||
var el = element.clone().css({'height': 'auto', 'width': element.width(), 'overflow': 'hidden'}).insertAfter(element),
|
||||
height = el.outerHeight(true);
|
||||
|
||||
el.remove();
|
||||
|
||||
element.data('expandedHeight', height);
|
||||
},
|
||||
|
||||
resizeBoxes: function() {
|
||||
var $this = this;
|
||||
|
||||
$('.readmore-js-section').each(function() {
|
||||
var current = $(this);
|
||||
|
||||
$this.setBoxHeight(current);
|
||||
|
||||
if(current.height() > current.data('expandedHeight') || (current.hasClass($this.options.expandedClass) && current.height() < current.data('expandedHeight')) ) {
|
||||
current.css('height', current.data('expandedHeight'));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
var $this = this;
|
||||
|
||||
$(this.element).each(function() {
|
||||
var current = $(this);
|
||||
|
||||
current.removeClass('readmore-js-section ' + $this.options.collapsedClass + ' ' + $this.options.expandedClass).css({'max-height': '', 'height': 'auto'}).next('.readmore-js-toggle').remove();
|
||||
|
||||
current.removeData();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$.fn[readmore] = function( options ) {
|
||||
var args = arguments;
|
||||
if (options === undefined || typeof options === 'object') {
|
||||
return this.each(function () {
|
||||
if ($.data(this, 'plugin_' + readmore)) {
|
||||
var instance = $.data(this, 'plugin_' + readmore);
|
||||
instance['destroy'].apply(instance);
|
||||
}
|
||||
|
||||
$.data(this, 'plugin_' + readmore, new Readmore( this, options ));
|
||||
});
|
||||
} else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
|
||||
return this.each(function () {
|
||||
var instance = $.data(this, 'plugin_' + readmore);
|
||||
if (instance instanceof Readmore && typeof instance[options] === 'function') {
|
||||
instance[options].apply( instance, Array.prototype.slice.call( args, 1 ) );
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})(jQuery);
|
@ -0,0 +1,7 @@
|
||||
(function(c){function g(b,a){this.element=b;this.options=c.extend({},h,a);c(this.element).data("max-height",this.options.maxHeight);c(this.element).data("height-margin",this.options.heightMargin);delete this.options.maxHeight;if(this.options.embedCSS&&!k){var d=".readmore-js-toggle, .readmore-js-section { "+this.options.sectionCSS+" } .readmore-js-section { overflow: hidden; }",e=document.createElement("style");e.type="text/css";e.styleSheet?e.styleSheet.cssText=d:e.appendChild(document.createTextNode(d));
|
||||
document.getElementsByTagName("head")[0].appendChild(e);k=!0}this._defaults=h;this._name=f;this.init()}var f="readmore",h={speed:100,maxHeight:200,heightMargin:16,moreLink:'<a href="#">Read More</a>',lessLink:'<a href="#">Close</a>',embedCSS:!0,sectionCSS:"display: block; width: 100%;",startOpen:!1,expandedClass:"readmore-js-expanded",collapsedClass:"readmore-js-collapsed",beforeToggle:function(){},afterToggle:function(){}},k=!1;g.prototype={init:function(){var b=this;c(this.element).each(function(){var a=
|
||||
c(this),d=a.css("max-height").replace(/[^-\d\.]/g,"")>a.data("max-height")?a.css("max-height").replace(/[^-\d\.]/g,""):a.data("max-height"),e=a.data("height-margin");"none"!=a.css("max-height")&&a.css("max-height","none");b.setBoxHeight(a);if(a.outerHeight(!0)<=d+e)return!0;a.addClass("readmore-js-section "+b.options.collapsedClass).data("collapsedHeight",d);a.after(c(b.options.startOpen?b.options.lessLink:b.options.moreLink).on("click",function(c){b.toggleSlider(this,a,c)}).addClass("readmore-js-toggle"));
|
||||
b.options.startOpen||a.css({height:d})});c(window).on("resize",function(a){b.resizeBoxes()})},toggleSlider:function(b,a,d){d.preventDefault();var e=this;d=newLink=sectionClass="";var f=!1;d=c(a).data("collapsedHeight");c(a).height()<=d?(d=c(a).data("expandedHeight")+"px",newLink="lessLink",f=!0,sectionClass=e.options.expandedClass):(newLink="moreLink",sectionClass=e.options.collapsedClass);e.options.beforeToggle(b,a,f);c(a).animate({height:d},{duration:e.options.speed,complete:function(){e.options.afterToggle(b,
|
||||
a,f);c(b).replaceWith(c(e.options[newLink]).on("click",function(b){e.toggleSlider(this,a,b)}).addClass("readmore-js-toggle"));c(this).removeClass(e.options.collapsedClass+" "+e.options.expandedClass).addClass(sectionClass)}})},setBoxHeight:function(b){var a=b.clone().css({height:"auto",width:b.width(),overflow:"hidden"}).insertAfter(b),c=a.outerHeight(!0);a.remove();b.data("expandedHeight",c)},resizeBoxes:function(){var b=this;c(".readmore-js-section").each(function(){var a=c(this);b.setBoxHeight(a);
|
||||
(a.height()>a.data("expandedHeight")||a.hasClass(b.options.expandedClass)&&a.height()<a.data("expandedHeight"))&&a.css("height",a.data("expandedHeight"))})},destroy:function(){var b=this;c(this.element).each(function(){var a=c(this);a.removeClass("readmore-js-section "+b.options.collapsedClass+" "+b.options.expandedClass).css({"max-height":"",height:"auto"}).next(".readmore-js-toggle").remove();a.removeData()})}};c.fn[f]=function(b){var a=arguments;if(void 0===b||"object"===typeof b)return this.each(function(){if(c.data(this,
|
||||
"plugin_"+f)){var a=c.data(this,"plugin_"+f);a.destroy.apply(a)}c.data(this,"plugin_"+f,new g(this,b))});if("string"===typeof b&&"_"!==b[0]&&"init"!==b)return this.each(function(){var d=c.data(this,"plugin_"+f);d instanceof g&&"function"===typeof d[b]&&d[b].apply(d,Array.prototype.slice.call(a,1))})}})(jQuery);
|
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue