diff --git a/jquery.expander.js b/jquery.expander.js index 85fe6bd..11b78a0 100644 --- a/jquery.expander.js +++ b/jquery.expander.js @@ -38,6 +38,8 @@ expandAfterSummary: false, + appendExpandPrefixToSummaryText: false, + // Possible word endings to test against for when preserveWords: true wordEnd: /(&(?:[^;]+;)?|[a-zA-Z\u00C0-\u0100]+|[^\u0000-\u007F]+)$/, @@ -178,6 +180,10 @@ summaryText = backup(summaryText, o.preserveWords && allHtml.slice(summaryText.length).length); + if (o.appendExpandPrefixToSummaryText) { + summaryText = summaryText + '' + o.expandPrefix + ''; + } + // separate open tags from close tags and clean up the lists summOpens = summaryText.match(rOpenTag) || []; summCloses = summaryText.match(rCloseTag) || []; @@ -402,7 +408,12 @@ } function buildMoreLabel(o, detailText) { - var ret = '' + o.expandPrefix; + var ret = ''; + + if (!o.appendExpandPrefixToSummaryText) { + ret = ret + o.expandPrefix; + summaryText = summaryText + '' + o.expandPrefix + ''; + } if (o.showWordCount) { diff --git a/jquery.expander.min.js b/jquery.expander.min.js index b5041c0..af29aef 100644 --- a/jquery.expander.min.js +++ b/jquery.expander.min.js @@ -1,7 +1 @@ -/*! - * jQuery Expander Plugin - v1.4.13 - 2014-10-05 - * http://plugins.learningjquery.com/expander/ - * Copyright (c) 2014 Karl Swedberg - * Licensed MIT (http://www.opensource.org/licenses/mit-license.php) - */ -(function(e){e.expander={version:"1.4.13",defaults:{slicePoint:100,sliceOn:null,preserveWords:!0,showWordCount:!1,wordCountText:" ({{count}} words)",widow:4,expandText:"read more",expandPrefix:"… ",expandAfterSummary:!1,wordEnd:/(&(?:[^;]+;)?|[a-zA-Z\u00C0-\u0100]+|[^\u0000-\u007F]+)$/,summaryClass:"summary",detailClass:"details",moreClass:"read-more",lessClass:"read-less",moreLinkClass:"more-link",lessLinkClass:"less-link",collapseTimer:0,expandEffect:"slideDown",expandSpeed:250,collapseEffect:"slideUp",collapseSpeed:200,userCollapse:!0,userCollapseText:"read less",userCollapsePrefix:" ",onSlice:null,beforeExpand:null,afterExpand:null,onCollapse:null,afterCollapse:null}},e.fn.expander=function(a){function l(e,a){var l="span",s=e.summary,n=h.exec(s),t=n?n[2].toLowerCase():"";return a?(l="div",n&&"a"!==t&&!e.expandAfterSummary?s=s.replace(h,e.moreLabel+"$1"):s+=e.moreLabel,s='
'+s+"
"):s+=e.moreLabel,[s," <",l+' class="'+e.detailClass+'"',">",e.details,""].join("")}function s(e,a){var l=''+e.expandPrefix;return e.wordCountText=e.showWordCount?e.wordCountText.replace(/\{\{count\}\}/,a.replace(u,"").replace(/\&(?:amp|nbsp);/g,"").replace(/(?:^\s+|\s+$)/,"").match(/\w+/g).length):"",l+=''+e.expandText+e.wordCountText+""}function n(a,l){return a.lastIndexOf("<")>a.lastIndexOf(">")&&(a=a.slice(0,a.lastIndexOf("<"))),l&&(a=a.replace(f,"")),e.trim(a)}function t(e,a){a.stop(!0,!0)[e.collapseEffect](e.collapseSpeed,function(){var l=a.prev("span."+e.moreClass).show();l.length||a.parent().children("div."+e.summaryClass).show().find("span."+e.moreClass).show(),e.afterCollapse&&e.afterCollapse.call(a)})}function r(a,l,s){a.collapseTimer&&(d=setTimeout(function(){t(a,l),e.isFunction(a.onCollapse)&&a.onCollapse.call(s,!1)},a.collapseTimer))}function i(a){var l="ExpandMoreHere374216623",s=a.summaryText.replace(a.sliceOn,l);s=e("
"+s+"
").text();var n=s.indexOf(l),t=a.summaryText.indexOf(a.sliceOn);return-1!==n&&a.slicePoint>n&&(a.summaryText=a.allHtml.slice(0,t)),a}var o="init";"string"==typeof a&&(o=a,a={});var d,c=e.extend({},e.expander.defaults,a),p=/^<(?:area|br|col|embed|hr|img|input|link|meta|param).*>$/i,f=c.wordEnd,u=/<\/?(\w+)[^>]*>/g,m=/<(\w+)[^>]*>/g,x=/<\/(\w+)>/g,h=/(<\/([^>]+)>)\s*$/,C=/^(<[^>]+>)+.?/,v=/\s\s+/g,g=function(a){return e.trim(a||"").replace(v," ")},w={init:function(){this.each(function(){var a,o,f,h,v,w,y,T,E,S,b,k,O,P,L,I=[],$=[],j="",A={},D=this,W=e(this),F=e([]),H=e.extend({},c,W.data("expander")||e.meta&&W.data()||{}),z=!!W.find("."+H.detailClass).length,U=!!W.find("*").filter(function(){var a=e(this).css("display");return/^block|table|list/.test(a)}).length,M=U?"div":"span",Q=M+"."+H.detailClass,Z=H.moreClass+"",q=H.lessClass+"",B=H.expandSpeed||0,G=g(W.html()),J=G.slice(0,H.slicePoint);if(H.moreSelector="span."+Z.split(" ").join("."),H.lessSelector="span."+q.split(" ").join("."),!e.data(this,"expanderInit")){for(e.data(this,"expanderInit",!0),e.data(this,"expander",H),e.each(["onSlice","beforeExpand","afterExpand","onCollapse","afterCollapse"],function(a,l){A[l]=e.isFunction(H[l])}),J=n(J),v=J.replace(u,"").length;H.slicePoint>v;)h=G.charAt(J.length),"<"===h&&(h=G.slice(J.length).match(C)[0]),J+=h,v++;for(H.sliceOn&&(L=i({sliceOn:H.sliceOn,slicePoint:H.slicePoint,allHtml:G,summaryText:J}),J=L.summaryText),J=n(J,H.preserveWords&&G.slice(J.length).length),w=J.match(m)||[],y=J.match(x)||[],f=[],e.each(w,function(e,a){p.test(a)||f.push(a)}),w=f,o=y.length,a=0;o>a;a++)y[a]=y[a].replace(x,"$1");if(e.each(w,function(a,l){var s=l.replace(m,"$1"),n=e.inArray(s,y);-1===n?(I.push(l),$.push("")):y.splice(n,1)}),$.reverse(),z)E=W.find(Q).remove().html(),J=W.html(),G=J+E,T="";else{if(E=G.slice(J.length),S=e.trim(E.replace(u,"")),""===S||S.split(/\s+/).length'+H.userCollapsePrefix+''+H.userCollapseText+"
"),W.find(H.lessSelector+" a").unbind("click.expander").bind("click.expander",function(a){a.preventDefault(),clearTimeout(d);var l=e(this).closest(Q);t(H,l),A.onCollapse&&H.onCollapse.call(D,!0)})}})},destroy:function(){this.each(function(){var a,l,s=e(this);s.data("expanderInit")&&(a=e.extend({},s.data("expander")||{},c),l=s.find("."+a.detailClass).contents(),s.removeData("expanderInit"),s.removeData("expander"),s.find(a.moreSelector).remove(),s.find("."+a.summaryClass).remove(),s.find("."+a.detailClass).after(l).remove(),s.find(a.lessSelector).remove())})}};return w[o]&&w[o].call(this),this},e.fn.expander.defaults=e.expander.defaults})(jQuery); +!function(e){e.expander={version:"1.4.13",defaults:{slicePoint:100,sliceOn:null,preserveWords:!0,showWordCount:!1,wordCountText:" ({{count}} words)",widow:4,expandText:"read more",expandPrefix:"… ",expandAfterSummary:!1,appendExpandPrefixToSummaryText:!1,wordEnd:/(&(?:[^;]+;)?|[a-zA-Z\u00C0-\u0100]+|[^\u0000-\u007F]+)$/,summaryClass:"summary",detailClass:"details",moreClass:"read-more",lessClass:"read-less",moreLinkClass:"more-link",lessLinkClass:"less-link",collapseTimer:0,expandEffect:"slideDown",expandSpeed:250,collapseEffect:"slideUp",collapseSpeed:200,userCollapse:!0,userCollapseText:"read less",userCollapsePrefix:" ",onSlice:null,beforeExpand:null,afterExpand:null,onCollapse:null,afterCollapse:null}},e.fn.expander=function(a){function s(e,a){var s="span",l=e.summary,n=h.exec(l),t=n?n[2].toLowerCase():"";return a?(s="div",n&&"a"!==t&&!e.expandAfterSummary?l=l.replace(h,e.moreLabel+"$1"):l+=e.moreLabel,l='
'+l+"
"):l+=e.moreLabel,[l," <",s+' class="'+e.detailClass+'"',">",e.details,""].join("")}function l(e,a){var s='';return e.appendExpandPrefixToSummaryText||(s+=e.expandPrefix,summaryText=summaryText+''+e.expandPrefix+""),e.wordCountText=e.showWordCount?e.wordCountText.replace(/\{\{count\}\}/,a.replace(u,"").replace(/\&(?:amp|nbsp);/g,"").replace(/(?:^\s+|\s+$)/,"").match(/\w+/g).length):"",s+=''+e.expandText+e.wordCountText+""}function n(a,s){return a.lastIndexOf("<")>a.lastIndexOf(">")&&(a=a.slice(0,a.lastIndexOf("<"))),s&&(a=a.replace(f,"")),e.trim(a)}function t(e,a){a.stop(!0,!0)[e.collapseEffect](e.collapseSpeed,function(){var s=a.prev("span."+e.moreClass).show();s.length||a.parent().children("div."+e.summaryClass).show().find("span."+e.moreClass).show(),e.afterCollapse&&e.afterCollapse.call(a)})}function r(a,s,l){a.collapseTimer&&(d=setTimeout(function(){t(a,s),e.isFunction(a.onCollapse)&&a.onCollapse.call(l,!1)},a.collapseTimer))}function i(a){var s="ExpandMoreHere374216623",l=a.summaryText.replace(a.sliceOn,s);l=e("
"+l+"
").text();var n=l.indexOf(s),t=a.summaryText.indexOf(a.sliceOn);return-1!==n&&n$/i,f=p.wordEnd,u=/<\/?(\w+)[^>]*>/g,m=/<(\w+)[^>]*>/g,x=/<\/(\w+)>/g,h=/(<\/([^>]+)>)\s*$/,C=/^(<[^>]+>)+.?/,v=/\s\s+/g,T=function(a){return e.trim(a||"").replace(v," ")},y={init:function(){this.each(function(){var a,o,f,h,v,y,g,w,E,S,b,P,k,O,L,I=[],$=[],j="",A={},D=this,W=e(this),F=e([]),H=e.extend({},p,W.data("expander")||e.meta&&W.data()||{}),z=!!W.find("."+H.detailClass).length,U=!!W.find("*").filter(function(){var a=e(this).css("display");return/^block|table|list/.test(a)}).length,M=U?"div":"span",Q=M+"."+H.detailClass,Z=H.moreClass+"",q=H.lessClass+"",B=H.expandSpeed||0,G=T(W.html()),J=G.slice(0,H.slicePoint);if(H.moreSelector="span."+Z.split(" ").join("."),H.lessSelector="span."+q.split(" ").join("."),!e.data(this,"expanderInit")){for(e.data(this,"expanderInit",!0),e.data(this,"expander",H),e.each(["onSlice","beforeExpand","afterExpand","onCollapse","afterCollapse"],function(a,s){A[s]=e.isFunction(H[s])}),J=n(J),v=J.replace(u,"").length;v'+H.expandPrefix+"
"),y=J.match(m)||[],g=J.match(x)||[],f=[],e.each(y,function(e,a){c.test(a)||f.push(a)}),y=f,o=g.length,a=0;o>a;a++)g[a]=g[a].replace(x,"$1");if(e.each(y,function(a,s){var l=s.replace(m,"$1"),n=e.inArray(l,g);-1===n?(I.push(s),$.push("")):g.splice(n,1)}),$.reverse(),z)E=W.find(Q).remove().html(),J=W.html(),G=J+E,w="";else{if(E=G.slice(J.length),S=e.trim(E.replace(u,"")),""===S||S.split(/\s+/).length'+H.userCollapsePrefix+''+H.userCollapseText+""),W.find(H.lessSelector+" a").unbind("click.expander").bind("click.expander",function(a){a.preventDefault(),clearTimeout(d);var s=e(this).closest(Q);t(H,s),A.onCollapse&&H.onCollapse.call(D,!0)})}})},destroy:function(){this.each(function(){var a,s,l=e(this);l.data("expanderInit")&&(a=e.extend({},l.data("expander")||{},p),s=l.find("."+a.detailClass).contents(),l.removeData("expanderInit"),l.removeData("expander"),l.find(a.moreSelector).remove(),l.find("."+a.summaryClass).remove(),l.find("."+a.detailClass).after(s).remove(),l.find(a.lessSelector).remove())})}};return y[o]&&y[o].call(this),this},e.fn.expander.defaults=e.expander.defaults}(jQuery);