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.2 to 0.1.3

README.md

2

bower.json
{
"name": "ellipsis",
"description": "ellipsis text depending on number of lines or number of chars",
"version": "0.1.2",
"version": "0.1.3",
"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.2';
var VERSION = '0.1.3';

@@ -42,3 +42,4 @@ /**

opacity: 1,
display: 'block'
display: 'block',
position: 'absolute'
};

@@ -149,3 +150,5 @@

var $charSpan = void 0;
var spanId = void 0;
var height = void 0;
var charWidth = void 0;

@@ -156,15 +159,19 @@ if (linesNo <= 0) {

this.element.append('<span id="ellipsis_char">x</span>');
spanId = 'ellipsis_char_' + this._getIdNo();
this.element.append('<span id="' + spanId + '" class="jquery_ellipsis">W</span>');
$charSpan = $('#ellipsis_char');
$charSpan = $('#' + spanId);
$charSpan.css(SPAN_CHAR_STYLE);
charWidth = $charSpan.width();
count = linesNo * this.element.width() / charWidth;
height = linesNo * $charSpan.height();
$charSpan.text('');
$charSpan.text(this.text.slice(0, count));
$charSpan.css('max-width', this.element.width());
while ($charSpan.height() <= height) {
$charSpan.text($charSpan.text() + this.text[count]);
count++;
$charSpan.text(this.text.slice(0, $charSpan.text().length + 1));
}
count = $charSpan.text().length;
$charSpan.remove();

@@ -193,2 +200,13 @@

/**
* get unique id for each spn
* that used for calculation
*/
}, {
key: '_getIdNo',
value: function _getIdNo() {
return $('jquery_ellipsis').length;
}
/**========================================================================

@@ -195,0 +213,0 @@ * GETTERS

@@ -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 o="ellipsis",s={type:"lines",count:3},r={visibility:"hidden",opacity:1,display:"block"},a=function(){function i(e){var o=arguments.length>1&&arguments[1]!==n?arguments[1]:{};_classCallCheck(this,i),this.element=t(e),this.options=Object.assign({},i.DEFAULTS,o),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,o=void 0;if(e<=0)return 0;for(this.element.append('<span id="ellipsis_char">x</span>'),n=t("#ellipsis_char"),n.css(r),o=e*n.height(),n.text("");n.height()<=o;)n.text(n.text()+this.text[i]),i++;return 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:"DEFAULTS",get:function(){return Object.freeze(s)}}]),i}();t.fn[o]=function(e){var i=arguments;if(e===n||"object"===("undefined"==typeof e?"undefined":_typeof(e)))return this.each(function(){t.data(this,"plugin_"+o)||t.data(this,"plugin_"+o,new a(this,e))});if("string"==typeof e&&"_"!==e[0]&&"init"!==e){var s;return this.each(function(){var n=t.data(this,"plugin_"+o);n instanceof a&&"function"==typeof n[e]&&(s=n[e].apply(n,Array.prototype.slice.call(i,1))),"destroy"===e&&t.data(this,"plugin_"+o,null)}),s!==n?s:this}},t(i).ready(function(){var e=t('[data-toggle="ellipsis"]');e.each(function(e,i){var o=t(i),s={};o.data("type")!==n&&(s.type=o.data("type")),o.data("count")!==n&&(s.count=o.data("count")),o.ellipsis(s)})})}(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"},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);

@@ -39,3 +39,3 @@ // Karma configuration

// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['spec', 'coverage'],
reporters: ['spec', 'coverage', 'coveralls'],
// coverage options

@@ -42,0 +42,0 @@ coverageReporter: {

{
"name": "jquery-ellipsis",
"version": "0.1.2",
"version": "0.1.3",
"description": "ellipsis text depending on number of lines or number of chars",

@@ -48,2 +48,3 @@ "private": false,

"gulp-useref": "^3.1.0",
"jquery": "^3.2.1",
"karma": "^1.1.2",

@@ -72,5 +73,3 @@ "karma-coverage": "^1.1.1",

},
"dependencies": {
"jquery": "2.1.1"
}
"dependencies": {}
}

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

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

@@ -38,3 +38,4 @@

opacity: 1,
display: 'block'
display: 'block',
position: 'absolute',
}

@@ -141,3 +142,5 @@

let $charSpan;
let spanId;
let height;
let charWidth;

@@ -148,15 +151,20 @@ if(linesNo <= 0) {

this.element.append('<span id="ellipsis_char">x</span>');
spanId = 'ellipsis_char_' + this._getIdNo()
this.element.append(`<span id="${spanId}" class="jquery_ellipsis">W</span>`);
$charSpan = $('#ellipsis_char');
$charSpan = $('#' + spanId);
$charSpan.css(SPAN_CHAR_STYLE);
charWidth = $charSpan.width();
count = linesNo * this.element.width() / charWidth;
height = linesNo * $charSpan.height();
$charSpan.text('');
$charSpan.text(this.text.slice(0, count));
$charSpan.css('max-width', this.element.width());
while($charSpan.height() <= height) {
$charSpan.text($charSpan.text() + this.text[count]);
count ++;
$charSpan.text(this.text.slice(0, $charSpan.text().length + 1));
}
count = $charSpan.text().length;
$charSpan.remove();

@@ -184,3 +192,11 @@

/**
* get unique id for each spn
* that used for calculation
*/
_getIdNo() {
return $('jquery_ellipsis').length;
}
/**========================================================================

@@ -187,0 +203,0 @@ * GETTERS

Sorry, the diff of this file is not supported yet

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