-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.truncate.min.js
executable file
·13 lines (13 loc) · 2.14 KB
/
jquery.truncate.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
/*!
* @fileOverview Truncation plugins that work together.
* @author Peter Galiba (Poetro)
* @requires jQuery 1.4
* @extends jQuery
*
* Contains three plugins:
* - truncate: Get the truncated text of the first selected element.
* - closestChild: Get the closest parent that is a child of selector.
* - truncated: Make the selected elements truncated with a link to expand them.
*
* Sponsored by Examiner.com. Licensed under GNU GPL v3.
*/(function(a,b){function h(a,b,e){var f="",g=1,h,i=e.truncateWhitespace,j=e.sentenceSafe,k=e.wordSafe,l=j||k,m=j?c:d;return function n(a){var c,d=0,e;for(;a[d]&&g;d+=1)c=a[d],c.nodeType===3||c.nodeType===4?(f+=f?c.nodeValue:c.nodeValue.replace(/^\s+/g,""),i&&(f=f.replace(/\s+/g," ")),f.length>=b&&(l?(e=m.exec(f.slice(b)),e&&(f=f.slice(0,b+e.index+(k?0:1)),g=0)):g=0)):c.nodeType!==8&&(h=c,n(c.childNodes))}(a),{text:f,node:h}}var c=/[.!?\u00a1\u203c\u2026\u00bf\u203d]\s|\u3002/,d=/\s/,e,f,g=a.fn;g.truncate=function(b,c){var d=null,f,g;return this[0]&&(f=a.extend({},e,c),d=h(this.eq(0),b,f),g=f.retType,g!=="both"&&g in d&&(d=d[g])),d},e=g.truncate.defaultSettings={retType:"both",wordSafe:!0,sentenceSafe:!0,truncateWhitespace:!0},g.closestChild=function(b,c){var d=a.expr.match.POS.test(b)||typeof b!="string"?a(b,c||this.context):0,e,f=[],g,h,i=this[0];for(g=0,h=this.length;g<h;g+=1){e=i=this[g];while(i){if(d?d.index(i)>-1:a(i).is(b)){f.push(e);break}e=i,i=i.parentNode;if(!i||!i.ownerDocument||i===c||i.nodeType===11)break}}return f=f.length>1?a.unique(f):f,this.pushStack(f,"closestChild",b)},g.truncated=function(b,c){function l(){var b=a(this);return b.next().slideDown(i.toggleSpeed),b.remove(),!1}var d=0,e=this.length,g,h,i=a.extend({},f,c),j,k;if(e){i.retType="node";for(;d<e;d+=1)g=this.eq(d),h=g.truncate(b,i),j=h&&a(h).closestChild(g),j.length&&(k=j.nextAll(),k.length&&(k.wrapAll(a(i.wrapper,{"class":i.wrapperClass})),a(i.toggler,{text:i.togglerText,href:"#","class":i.togglerClass,click:l}).insertAfter(j)))}return this},f=g.truncated.defaultSettings={wrapper:"<div></div>",wrapperClass:"element-hidden",toggler:"<a></a>",togglerText:"Continue reading",togglerClass:"read-more",toggleSpeed:"fast"}})(jQuery,document);