first
This commit is contained in:
151
plugins/jquery.shorten/1.0/jquery.shorten.js
Normal file
151
plugins/jquery.shorten/1.0/jquery.shorten.js
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* jQuery Shorten plugin 1.1.0
|
||||
*
|
||||
* Copyright (c) 2014 Viral Patel
|
||||
* http://viralpatel.net
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
/*
|
||||
** updated by Jeff Richardson
|
||||
** Updated to use strict,
|
||||
** IE 7 has a "bug" It is returning undefined when trying to reference string characters in this format
|
||||
** content[i]. IE 7 allows content.charAt(i) This works fine in all modern browsers.
|
||||
** I've also added brackets where they weren't added just for readability (mostly for me).
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
$.fn.shorten = function(settings) {
|
||||
"use strict";
|
||||
|
||||
var config = {
|
||||
showChars: 100,
|
||||
minHideChars: 10,
|
||||
ellipsesText: "...",
|
||||
moreText: "more",
|
||||
lessText: "less",
|
||||
onLess: function() {},
|
||||
onMore: function() {},
|
||||
errMsg: null,
|
||||
force: false
|
||||
};
|
||||
|
||||
if (settings) {
|
||||
$.extend(config, settings);
|
||||
}
|
||||
|
||||
if ($(this).data('jquery.shorten') && !config.force) {
|
||||
return false;
|
||||
}
|
||||
$(this).data('jquery.shorten', true);
|
||||
|
||||
$(document).off("click", '.morelink');
|
||||
|
||||
$(document).on({
|
||||
click: function() {
|
||||
|
||||
var $this = $(this);
|
||||
if ($this.hasClass('less')) {
|
||||
$this.removeClass('less');
|
||||
$this.html(config.moreText);
|
||||
$this.parent().prev().animate({'height':'0'+'%'}, function () { $this.parent().prev().prev().show(); }).hide('fast', function() {
|
||||
config.onLess();
|
||||
});
|
||||
|
||||
} else {
|
||||
$this.addClass('less');
|
||||
$this.html(config.lessText);
|
||||
$this.parent().prev().animate({'height':'100'+'%'}, function () { $this.parent().prev().prev().hide(); }).show('fast', function() {
|
||||
config.onMore();
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}, '.morelink');
|
||||
|
||||
return this.each(function() {
|
||||
var $this = $(this);
|
||||
|
||||
var content = $this.html();
|
||||
var contentlen = $this.text().length;
|
||||
if (contentlen > config.showChars + config.minHideChars) {
|
||||
var c = content.substr(0, config.showChars);
|
||||
if (c.indexOf('<') >= 0) // If there's HTML don't want to cut it
|
||||
{
|
||||
var inTag = false; // I'm in a tag?
|
||||
var bag = ''; // Put the characters to be shown here
|
||||
var countChars = 0; // Current bag size
|
||||
var openTags = []; // Stack for opened tags, so I can close them later
|
||||
var tagName = null;
|
||||
|
||||
for (var i = 0, r = 0; r <= config.showChars; i++) {
|
||||
if (content[i] == '<' && !inTag) {
|
||||
inTag = true;
|
||||
|
||||
// This could be "tag" or "/tag"
|
||||
tagName = content.substring(i + 1, content.indexOf('>', i));
|
||||
|
||||
// If its a closing tag
|
||||
if (tagName[0] == '/') {
|
||||
|
||||
|
||||
if (tagName != '/' + openTags[0]) {
|
||||
config.errMsg = 'ERROR en HTML: the top of the stack should be the tag that closes';
|
||||
} else {
|
||||
openTags.shift(); // Pops the last tag from the open tag stack (the tag is closed in the retult HTML!)
|
||||
}
|
||||
|
||||
} else {
|
||||
// There are some nasty tags that don't have a close tag like <br/>
|
||||
if (tagName.toLowerCase() != 'br') {
|
||||
openTags.unshift(tagName); // Add to start the name of the tag that opens
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inTag && content[i] == '>') {
|
||||
inTag = false;
|
||||
}
|
||||
|
||||
if (inTag) { bag += content.charAt(i); } // Add tag name chars to the result
|
||||
else {
|
||||
r++;
|
||||
if (countChars <= config.showChars) {
|
||||
bag += content.charAt(i); // Fix to ie 7 not allowing you to reference string characters using the []
|
||||
countChars++;
|
||||
} else // Now I have the characters needed
|
||||
{
|
||||
if (openTags.length > 0) // I have unclosed tags
|
||||
{
|
||||
//console.log('They were open tags');
|
||||
//console.log(openTags);
|
||||
for (j = 0; j < openTags.length; j++) {
|
||||
//console.log('Cierro tag ' + openTags[j]);
|
||||
bag += '</' + openTags[j] + '>'; // Close all tags that were opened
|
||||
|
||||
// You could shift the tag from the stack to check if you end with an empty stack, that means you have closed all open tags
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
c = $('<div/>').html(bag + '<span class="ellip">' + config.ellipsesText + '</span>').html();
|
||||
}else{
|
||||
c+=config.ellipsesText;
|
||||
}
|
||||
|
||||
var html = '<div class="shortcontent">' + c +
|
||||
'</div><div class="allcontent">' + content +
|
||||
'</div><span><a href="javascript://nop/" class="morelink">' + config.moreText + '</a></span>';
|
||||
|
||||
$this.html(html);
|
||||
$this.find(".allcontent").hide(); // Hide all text
|
||||
$('.shortcontent p:last', $this).css('margin-bottom', 0); //Remove bottom margin on last paragraph as it's likely shortened
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
1
plugins/jquery.shorten/1.0/jquery.shorten.min.js
vendored
Normal file
1
plugins/jquery.shorten/1.0/jquery.shorten.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e){e.fn.shorten=function(s){"use strict";var t={showChars:100,minHideChars:10,ellipsesText:"...",moreText:"more",lessText:"less",onLess:function(){},onMore:function(){},errMsg:null,force:!1};return s&&e.extend(t,s),e(this).data("jquery.shorten")&&!t.force?!1:(e(this).data("jquery.shorten",!0),e(document).off("click",".morelink"),e(document).on({click:function(){var s=e(this);return s.hasClass("less")?(s.removeClass("less"),s.html(t.moreText),s.parent().prev().animate({height:"0%"},function(){s.parent().prev().prev().show()}).hide("fast",function(){t.onLess()})):(s.addClass("less"),s.html(t.lessText),s.parent().prev().animate({height:"100%"},function(){s.parent().prev().prev().hide()}).show("fast",function(){t.onMore()})),!1}},".morelink"),this.each(function(){var s=e(this),n=s.html(),r=s.text().length;if(r>t.showChars+t.minHideChars){var o=n.substr(0,t.showChars);if(o.indexOf("<")>=0){for(var a=!1,i="",h=0,l=[],c=null,f=0,u=0;u<=t.showChars;f++)if("<"!=n[f]||a||(a=!0,c=n.substring(f+1,n.indexOf(">",f)),"/"==c[0]?c!="/"+l[0]?t.errMsg="ERROR en HTML: the top of the stack should be the tag that closes":l.shift():"br"!=c.toLowerCase()&&l.unshift(c)),a&&">"==n[f]&&(a=!1),a)i+=n.charAt(f);else if(u++,h<=t.showChars)i+=n.charAt(f),h++;else if(l.length>0){for(j=0;j<l.length;j++)i+="</"+l[j]+">";break}o=e("<div/>").html(i+'<span class="ellip">'+t.ellipsesText+"</span>").html()}else o+=t.ellipsesText;var m='<div class="shortcontent">'+o+'</div><div class="allcontent">'+n+'</div><span><a href="javascript://nop/" class="morelink">'+t.moreText+"</a></span>";s.html(m),s.find(".allcontent").hide(),e(".shortcontent p:last",s).css("margin-bottom",0)}}))}}(jQuery);
|
||||
21
plugins/jquery.shorten/MIT-LICENSE.txt
Normal file
21
plugins/jquery.shorten/MIT-LICENSE.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
Copyright 2013 Viral Patel and other contributors
|
||||
http://viralpatel.net
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
72
plugins/jquery.shorten/README.md
Normal file
72
plugins/jquery.shorten/README.md
Normal file
@@ -0,0 +1,72 @@
|
||||
Shorten
|
||||
=======
|
||||
|
||||

|
||||
|
||||
A simple jquery plugin that automatically shortens text within an element and add "more" link.
|
||||
|
||||
*Read tutorial: [jQuery Shorten](http://viralpatel.net/blogs/dynamically-shortened-text-show-more-link-jquery/).*
|
||||
|
||||
Usage
|
||||
-----
|
||||
Shortens the text within 'element' and add a 'more' link.
|
||||
|
||||
$(element).shorten();
|
||||
|
||||
Add a link with text 'read more' while shortening the content of element.
|
||||
|
||||
$(element).shorten({
|
||||
moreText: 'read more'
|
||||
});
|
||||
|
||||
Change the link text to 'read more' and 'read less' overriding default value 'more' and 'less'.
|
||||
|
||||
$(element).shorten({
|
||||
moreText: 'read more',
|
||||
lessText: 'read less'
|
||||
});
|
||||
|
||||
Override default display 100 characters and hide text above 50 characters.
|
||||
|
||||
$(element).shorten({
|
||||
showChars: 50,
|
||||
});
|
||||
|
||||
Parameters
|
||||
----------
|
||||
You can change the behaviour by changing following js variables.
|
||||
|
||||
| Property | Description |
|
||||
| -------------- | ----------------------------------------------------------------------------------------- |
|
||||
| `showChars` | Total characters to show to user. If the content is more then showChar, it will be split into two halves and first one will be showed to user. |
|
||||
| `ellipsesText` | The text displayed before “more” link. Default is “…” |
|
||||
| `moreText` | The text shown in more link. Default is “more”. You can change to ">>" or "read more" |
|
||||
| `lessText` | The text shown in less link. Default is “less”. You can change to "<<" or "read less" |
|
||||
| `onMore` | Callback function to trigger when "more" is clicked |
|
||||
| `onLess` | Callback function to trigger when "less" is clicked |
|
||||
|
||||
|
||||
Licence
|
||||
-------
|
||||
|
||||
Copyright 2013 Viral Patel and other contributors
|
||||
http://viralpatel.net
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
Reference in New Issue
Block a user