Socket
Socket
Sign inDemoInstall

jquery-ellipsis

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jquery-ellipsis - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

2

bower.json
{
"name": "ellipsis",
"description": "ellipsis text depending on number of lines or number of chars",
"version": "0.1.3",
"version": "0.1.4",
"main": "./dist/jquery.ellipsis.min.js",

@@ -6,0 +6,0 @@ "authors": [

@@ -21,3 +21,3 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var PLUGIN_NAME = 'ellipsis';
var VERSION = '0.1.3';
var VERSION = '0.1.4';

@@ -87,3 +87,3 @@ /**

charsNo = this._getTotalCharsInLines(this.options.count);
result = this._excerptTillChar(charsNo);
if (charsNo) result = this._excerptTillChar(charsNo);
}

@@ -134,2 +134,4 @@

if (number >= this.text.length) return null;
return this.element.html(this.text.slice(0, number) + '...');

@@ -168,6 +170,11 @@ }

if (count >= this.text.length) {
$charSpan.remove();
return null;
}
$charSpan.text(this.text.slice(0, count));
$charSpan.css('max-width', this.element.width());
while ($charSpan.height() <= height) {
while ($charSpan.height() <= height && this.text.length >= $charSpan.text().length + 1) {
$charSpan.text(this.text.slice(0, $charSpan.text().length + 1));

@@ -177,4 +184,9 @@ }

count = $charSpan.text().length;
$charSpan.remove();
if (count >= this.text.length) {
return null;
}
if (count && typeof count === 'number') count--;

@@ -181,0 +193,0 @@ return count;

@@ -1,1 +0,1 @@

function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_createClass=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}();!function(t,e,i,n){"use strict";var s="ellipsis",o={type:"lines",count:3},r={visibility:"hidden",opacity:1,display:"block",position:"absolute"},a=function(){function i(e){var s=arguments.length>1&&arguments[1]!==n?arguments[1]:{};_classCallCheck(this,i),this.element=t(e),this.options=Object.assign({},i.DEFAULTS,s),this.text=this.element.text(),this._resizeTimeout=null,this._resizeHandler=this._updateOnResize.bind(this),this.init()}return _createClass(i,[{key:"init",value:function(){var i=void 0,n=void 0;if("chars"===this.options.type?i=this._excerptTillChar(this.options.count):"lines"===this.options.type&&(n=this._getTotalCharsInLines(this.options.count),i=this._excerptTillChar(n)),i instanceof Error)throw i;"lines"===this.options.type&&t(e).on("resize",this._resizeHandler)}},{key:"update",value:function(){var t=void 0;t="lines"===this.options.type?this._getTotalCharsInLines(this.options.count):this.options.count,this._excerptTillChar(t)}},{key:"_excerptTillChar",value:function(t){return t<=0?new Error("Number of chars to be shown is equal to or less than zero !!"):("lines"===this.options.type&&t>=3&&(t-=3),this.element.html(this.text.slice(0,t)+"..."))}},{key:"_getTotalCharsInLines",value:function(e){var i=0,n=void 0,s=void 0,o=void 0,a=void 0;if(e<=0)return 0;for(s="ellipsis_char_"+this._getIdNo(),this.element.append('<span id="'+s+'" class="jquery_ellipsis">W</span>'),n=t("#"+s),n.css(r),a=n.width(),i=e*this.element.width()/a,o=e*n.height(),n.text(this.text.slice(0,i)),n.css("max-width",this.element.width());n.height()<=o;)n.text(this.text.slice(0,n.text().length+1));return i=n.text().length,n.remove(),i&&"number"==typeof i&&i--,i}},{key:"_updateOnResize",value:function(){var t=this;clearTimeout(this._resizeTimeout),this._resizeTimeout=setTimeout(function(){t.update()},300)}},{key:"_getIdNo",value:function(){return t("jquery_ellipsis").length}}],[{key:"DEFAULTS",get:function(){return Object.freeze(o)}}]),i}();t.fn[s]=function(e){var i=arguments;if(e===n||"object"===("undefined"==typeof e?"undefined":_typeof(e)))return this.each(function(){t.data(this,"plugin_"+s)||t.data(this,"plugin_"+s,new a(this,e))});if("string"==typeof e&&"_"!==e[0]&&"init"!==e){var o;return this.each(function(){var n=t.data(this,"plugin_"+s);n instanceof a&&"function"==typeof n[e]&&(o=n[e].apply(n,Array.prototype.slice.call(i,1))),"destroy"===e&&t.data(this,"plugin_"+s,null)}),o!==n?o:this}},t(i).ready(function(){var e=t('[data-toggle="ellipsis"]');e.each(function(e,i){var s=t(i),o={};s.data("type")!==n&&(o.type=s.data("type")),s.data("count")!==n&&(o.count=s.data("count")),s.ellipsis(o)})})}(jQuery,window,document);
function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_createClass=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}();!function(t,e,i,n){"use strict";var s="ellipsis",o={type:"lines",count:3},r={visibility:"hidden",opacity:1,display:"block",position:"absolute"},l=function(){function i(e){var s=arguments.length>1&&arguments[1]!==n?arguments[1]:{};_classCallCheck(this,i),this.element=t(e),this.options=Object.assign({},i.DEFAULTS,s),this.text=this.element.text(),this._resizeTimeout=null,this._resizeHandler=this._updateOnResize.bind(this),this.init()}return _createClass(i,[{key:"init",value:function(){var i=void 0,n=void 0;if("chars"===this.options.type?i=this._excerptTillChar(this.options.count):"lines"===this.options.type&&(n=this._getTotalCharsInLines(this.options.count),n&&(i=this._excerptTillChar(n))),i instanceof Error)throw i;"lines"===this.options.type&&t(e).on("resize",this._resizeHandler)}},{key:"update",value:function(){var t=void 0;t="lines"===this.options.type?this._getTotalCharsInLines(this.options.count):this.options.count,this._excerptTillChar(t)}},{key:"_excerptTillChar",value:function(t){return t<=0?new Error("Number of chars to be shown is equal to or less than zero !!"):("lines"===this.options.type&&t>=3&&(t-=3),t>=this.text.length?null:this.element.html(this.text.slice(0,t)+"..."))}},{key:"_getTotalCharsInLines",value:function(e){var i=0,n=void 0,s=void 0,o=void 0,l=void 0;if(e<=0)return 0;if(s="ellipsis_char_"+this._getIdNo(),this.element.append('<span id="'+s+'" class="jquery_ellipsis">W</span>'),n=t("#"+s),n.css(r),l=n.width(),i=e*this.element.width()/l,o=e*n.height(),i>=this.text.length)return n.remove(),null;for(n.text(this.text.slice(0,i)),n.css("max-width",this.element.width());n.height()<=o&&this.text.length>=n.text().length+1;)n.text(this.text.slice(0,n.text().length+1));return i=n.text().length,n.remove(),i>=this.text.length?null:(i&&"number"==typeof i&&i--,i)}},{key:"_updateOnResize",value:function(){var t=this;clearTimeout(this._resizeTimeout),this._resizeTimeout=setTimeout(function(){t.update()},300)}},{key:"_getIdNo",value:function(){return t("jquery_ellipsis").length}}],[{key:"DEFAULTS",get:function(){return Object.freeze(o)}}]),i}();t.fn[s]=function(e){var i=arguments;if(e===n||"object"===("undefined"==typeof e?"undefined":_typeof(e)))return this.each(function(){t.data(this,"plugin_"+s)||t.data(this,"plugin_"+s,new l(this,e))});if("string"==typeof e&&"_"!==e[0]&&"init"!==e){var o;return this.each(function(){var n=t.data(this,"plugin_"+s);n instanceof l&&"function"==typeof n[e]&&(o=n[e].apply(n,Array.prototype.slice.call(i,1))),"destroy"===e&&t.data(this,"plugin_"+s,null)}),o!==n?o:this}},t(i).ready(function(){var e=t('[data-toggle="ellipsis"]');e.each(function(e,i){var s=t(i),o={};s.data("type")!==n&&(o.type=s.data("type")),s.data("count")!==n&&(o.count=s.data("count")),s.ellipsis(o)})})}(jQuery,window,document);
{
"name": "jquery-ellipsis",
"version": "0.1.3",
"version": "0.1.4",
"description": "ellipsis text depending on number of lines or number of chars",

@@ -5,0 +5,0 @@ "private": false,

@@ -14,3 +14,3 @@ /**

const PLUGIN_NAME = 'ellipsis';
const VERSION = '0.1.3';
const VERSION = '0.1.4';

@@ -78,3 +78,4 @@

charsNo = this._getTotalCharsInLines(this.options.count);
result = this._excerptTillChar(charsNo);
if(charsNo)
result = this._excerptTillChar(charsNo);
}

@@ -127,3 +128,6 @@

return this.element.html(this.text.slice(0, number) + '...')
if(number >= this.text.length)
return null;
return this.element.html(this.text.slice(0, number) + '...');
}

@@ -161,12 +165,23 @@

if(count >= this.text.length){
$charSpan.remove();
return null;
}
$charSpan.text(this.text.slice(0, count));
$charSpan.css('max-width', this.element.width());
while($charSpan.height() <= height) {
$charSpan.text(this.text.slice(0, $charSpan.text().length + 1));
while($charSpan.height() <= height &&
this.text.length >= $charSpan.text().length + 1) {
$charSpan.text(this.text.slice(0, $charSpan.text().length + 1));
}
count = $charSpan.text().length;
$charSpan.remove();
if(count >= this.text.length){
return null;
}
if(count && typeof count === 'number') count --;

@@ -173,0 +188,0 @@ return count;

@@ -56,2 +56,35 @@ /**

});
it('should not excerpt the text if it\'s less than 2 lines', () => {
let $p = $('#paragraph');
let expectedText = '';
let expectedHeight = 0;
$p.append('<span class="height-span">x</span>');
expectedHeight = $('.height-span').height();
$('.height-span').remove();
$('#paragraph').text(text.slice(0, 16));
expectedText = text.slice(0, 16)
$('#paragraph').ellipsis({type: 'lines', count: 2});
expect($('#paragraph').height()).toEqual(expectedHeight);
expect($('#paragraph').text()).toEqual(expectedText);
});
it('should not excerpt the text if text length less than dedicated lines count chars', () => {
let $p = $('#paragraph');
let expectedText = '';
let expectedHeight = 0;
$p.append('<span class="height-span">x</span>');
expectedHeight = $('.height-span').height() * 2;
$('.height-span').remove();
$('#paragraph').text(text.slice(0, 34));
expectedText = text.slice(0, 34)
$('#paragraph').ellipsis({type: 'lines', count: 2});
expect($('#paragraph').height()).toEqual(expectedHeight);
expect($('#paragraph').text()).toEqual(expectedText);
});
});

@@ -58,0 +91,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc