Comparing version 0.1.8 to 0.2.0
@@ -61,9 +61,11 @@ (function (global, factory) { | ||
var plugin = window.$ || window.jQuery || window.Zepto; | ||
if (plugin) { | ||
plugin.fn.extend({ | ||
shave: function shaveFunc(maxHeight, opts) { | ||
return shave(this, maxHeight, opts); | ||
} | ||
}); | ||
if (typeof window !== 'undefined') { | ||
var plugin = window.$ || window.jQuery || window.Zepto; | ||
if (plugin) { | ||
plugin.fn.extend({ | ||
shave: function shaveFunc(maxHeight, opts) { | ||
return shave(this, maxHeight, opts); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -70,0 +72,0 @@ |
/** | ||
* shave - Shave is a javascript plugin that truncates multi-line text within a html element based on set max height | ||
* @version v0.1.7 | ||
* @version v0.2.0 | ||
* @link https://github.com/dollarshaveclub/shave#readme | ||
* @author Jeff Wainwright <jjwainwright2@gmail.com> (jeffr.in) | ||
* @author Jeff Wainwright <jjwainwright2@gmail.com> (jeffry.in) | ||
* @license ISC */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.shave=t()}(this,function(){"use strict";function e(e,t,n){if(!t)throw Error("maxHeight is required");var s="string"==typeof e?document.querySelectorAll(e):e;"length"in s||(s=[s]);for(var r={character:"…",classname:"js-shave",spaces:!0},o=n&&n.character||r.character,a=n&&n.classname||r.classname,i=(!n||n.spaces!==!1)&&r.spaces,c='<span class="js-shave-char">'+o+"</span>",f=0;f<s.length;f++){var l=s[f],d=l.querySelector("."+a);if(d&&(l.removeChild(l.querySelector(".js-shave-char")),l.textContent=l.textContent),!(l.offsetHeight<t)){var h=l.textContent,u=i?h.split(" "):h;if(!(u.length<2)){for(var p=u.length-1,v=0,j=void 0;v<p;)j=v+p+1>>1,l.textContent=i?u.slice(0,j).join(" "):u.slice(0,j),l.insertAdjacentHTML("beforeend",c),l.offsetHeight>t?p=i?j-1:j-2:v=j;l.textContent=i?u.slice(0,p).join(" "):u.slice(0,p),l.insertAdjacentHTML("beforeend",c);var y=i?u.slice(p+1).join(" "):u.slice(p);l.insertAdjacentHTML("beforeend",'<span class="'+a+'" style="display:none;">'+y+"</span>")}}}}var t=window.$||window.jQuery||window.Zepto;return t&&t.fn.extend({shave:function(t,n){return e(this,t,n)}}),e}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.shave=t()}(this,function(){"use strict";function e(e,t,n){if(!t)throw Error("maxHeight is required");var s="string"==typeof e?document.querySelectorAll(e):e;"length"in s||(s=[s]);for(var r={character:"…",classname:"js-shave",spaces:!0},i=n&&n.character||r.character,o=n&&n.classname||r.classname,a=(!n||n.spaces!==!1)&&r.spaces,c='<span class="js-shave-char">'+i+"</span>",f=0;f<s.length;f++){var d=s[f],l=d.querySelector("."+o);if(l&&(d.removeChild(d.querySelector(".js-shave-char")),d.textContent=d.textContent),!(d.offsetHeight<t)){var h=d.textContent,u=a?h.split(" "):h;if(!(u.length<2)){for(var p=u.length-1,v=0,j=void 0;v<p;)j=v+p+1>>1,d.textContent=a?u.slice(0,j).join(" "):u.slice(0,j),d.insertAdjacentHTML("beforeend",c),d.offsetHeight>t?p=a?j-1:j-2:v=j;d.textContent=a?u.slice(0,p).join(" "):u.slice(0,p),d.insertAdjacentHTML("beforeend",c);var y=a?u.slice(p+1).join(" "):u.slice(p);d.insertAdjacentHTML("beforeend",'<span class="'+o+'" style="display:none;">'+y+"</span>")}}}}if("undefined"!=typeof window){var t=window.$||window.jQuery||window.Zepto;t&&t.fn.extend({shave:function(t,n){return e(this,t,n)}})}return e}); |
{ | ||
"name": "shave", | ||
"version": "0.1.8", | ||
"version": "0.2.0", | ||
"description": "Shave is a javascript plugin that truncates multi-line text within a html element based on set max height", | ||
@@ -5,0 +5,0 @@ "main": "dist/shave.js", |
 | ||
[](https://www.npmjs.com/package/shave) | ||
[](https://github.com/dollarshaveclub/shave) | ||
[](https://www.npmjs.com/package/shave) | ||
[](https://github.com/dollarshaveclub/shave) | ||
[](https://travis-ci.org/dollarshaveclub/shave) | ||
@@ -86,2 +86,4 @@ [](https://twitter.com/home?status=Shave%20is%20a%200%20dep%20js%20lib%20that%20truncates%20multiline%20text%20to%20fit%20within%20a%20html%20element%20%E2%9C%81https%3A%2F%2Fgithub.com%2Fdollarshaveclub%2Fshave%20%40DSCEngineering%20%23JavaScript%20%F0%9F%92%AA) | ||
Here are some super basic examples of shave with [window resize](http://codepen.io/yowainwright/pen/yVBxGY) and [click](http://codepen.io/yowainwright/pen/PbYdvL/) events. 🙌 | ||
Shave works in all modern browsers and was tested in some not so modern browsers (like Internet Explorer 8) - it works there too. 🍻 |
10661
66
89