PageSourceSearch

https://www.phillumeny.com/wp-content/plugins/nextgen-gallery/prod…/static/shave.js?ver=3.4.7

js phillumeny.com collected 2026-10-02 08:04:34 UTC 3,403 bytes, 83 lines download raw bytes

1/**
2  shave - Shave is a javascript plugin that truncates multi-line text within a html element based on set max height
3  @version v2.5.7
4  @link https://github.com/dollarshaveclub/shave#readme
5  @author Jeff Wainwright <[email protected]> (jeffry.in)
6  @license MIT
7**/
8(function (global, factory) {
9  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
10  typeof define === 'function' && define.amd ? define(factory) :
11  (global = global || self, global.shave = factory());
12}(this, (function () { 'use strict';
13
14  function shave(target, maxHeight) {
15    var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
16    if (typeof maxHeight === 'undefined' || isNaN(maxHeight)) throw Error('maxHeight is required');
17    var els = typeof target === 'string' ? document.querySelectorAll(target) : target;
18    if (!els) return;
19    var character = opts.character || '…';
20    var classname = opts.classname || 'js-shave';
21    var spaces = typeof opts.spaces === 'boolean' ? opts.spaces : true;
22    var charHtml = "<span class=\"js-shave-char\">".concat(character, "</span>");
23    if (!('length' in els)) els = [els];
24
25    for (var i = 0; i < els.length; i += 1) {
26      var el = els[i];
27      var styles = el.style;
28      var span = el.querySelector(".".concat(classname));
29      var textProp = el.textContent === undefined ? 'innerText' : 'textContent'; // If element text has already been shaved
30
31      if (span) {
32        // Remove the ellipsis to recapture the original text
33        el.removeChild(el.querySelector('.js-shave-char'));
34        el[textProp] = el[textProp]; // eslint-disable-line
35        // nuke span, recombine text
36      }
37
38      var fullText = el[textProp];
39      var words = spaces ? fullText.split(' ') : fullText; // If 0 or 1 words, we're done
40
41      if (words.length < 2) continue; // Temporarily remove any CSS height for text height calculation
42
43      var heightStyle = styles.height;
44      styles.height = 'auto';
45      var maxHeightStyle = styles.maxHeight;
46      styles.maxHeight = 'none'; // If already short enough, we're done
47
48      if (el.offsetHeight <= maxHeight) {
49        styles.height = heightStyle;
50        styles.maxHeight = maxHeightStyle;
51        continue;
52      } // Binary search for number of words which can fit in allotted height
53
54
55      var max = words.length - 1;
56      var min = 0;
57      var pivot = void 0;
58
59      while (min < max) {
60        pivot = min + max + 1 >> 1; // eslint-disable-line no-bitwise
61
62        el[textProp] = spaces ? words.slice(0, pivot).join(' ') : words.slice(0, pivot);
63        el.insertAdjacentHTML('beforeend', charHtml);
64        if (el.offsetHeight > maxHeight) max = pivot - 1;else min = pivot;
65      }
66
67      el[textProp] = spaces ? words.slice(0, max).join(' ') : words.slice(0, max);
68      el.insertAdjacentHTML('beforeend', charHtml);
69      var diff = spaces ? " ".concat(words.slice(max).join(' ')) : words.slice(max);
70      var shavedText = document.createTextNode(diff);
71      var elWithShavedText = document.createElement('span');
72      elWithShavedText.classList.add(classname);
73      elWithShavedText.style.display = 'none';
74      elWithShavedText.appendChild(shavedText);
75      el.insertAdjacentElement('beforeend', elWithShavedText);
76      styles.height = heightStyle;
77      styles.maxHeight = maxHeightStyle;
78    }
79  }
80
81  return shave;
82
83})));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.