PageSourceSearch

https://arlingtonmnnews.com/wp-content/plugins/nextgen-gallery-pro…/ImageProtection/pressure.js?ver=3.31.6

js arlingtonmnnews.com collected 2026-10-02 18:40:27 UTC 20,453 bytes, 574 lines download raw bytes

vendor: 4,477 bytes, lines 1-66
1// Pressure v2.2.0 | Created By Stuart Yamartino | MIT License | 2015 - 2020
2;(function(root, factory) {
3  if (typeof define === 'function' && define.amd) {
4    define([], factory);
5  } else if (typeof exports === 'object') {
6    module.exports = factory();
7  } else {
8    root.Pressure = factory();
9  }
10}(this, function() {
11"use strict";
12
13function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
14
15function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
16
17function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
18
19function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
20
21function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
22
23function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
24
25function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
26
27function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
28
29function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
30
31function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
32
33function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
34
35//--------------------- Public API Section ---------------------//
36// this is the Pressure Object, this is the only object that is accessible to the end user
37// only the methods in this object can be called, making it the "public api"
38var Pressure = {
39  // targets any device with Force or 3D Touch
40  set: function set(selector, closure, options) {
41    loopPressureElements(selector, closure, options);
42  },
43  // set configuration options for global config
44  config: function config(options) {
45    Config.set(options);
46  },
47  // the map method allows for interpolating a value from one range of values to another
48  // example from the Arduino documentation: https://www.arduino.cc/en/Reference/Map
49  map: function map(x, in_min, in_max, out_min, out_max) {
50    return _map.apply(null, arguments);
51  }
52};
53
54var Element = /*#__PURE__*/function () {
55  function Element(el, block, options) {
56    _classCallCheck(this, Element);
57
58    this.routeEvents(el, block, options);
59    this.preventSelect(el, options);
60  }
61
62  _createClass(Element, [{
63    key: "routeEvents",
64    value: function routeEvents(el, block, options) {
65      var type = Config.get('only', options); // for devices that support Force Touch
66
67      if (supportsMouse && (type === 'mouse' || type === null)) {
68        this.adapter = new AdapterForceTouch(el, block, options).bindEvents();
69      } // for devices that support pointer events
70      else if (supportsPointer && (type === 'pointer' || type === null)) {
71          this.adapter = new AdapterPointer(el, block, options).bindEvents();
72        } // for devices that support 3D Touch
73        else if (supportsTouch && (type === 'touch' || type === null)) {
74            this.adapter = new Adapter3DTouch(el, block, options).bindEvents();
75          } // unsupported if it is requesting a type and your browser is of other type
76          else {
77              this.adapter = new Adapter(el, block).bindUnsupportedEvent();
78            }
79    } // prevent the default action of text selection, "peak & pop", and force touch special feature
80
81  }, {
82    key: "preventSelect",
83    value: function preventSelect(el, options) {
84      if (Config.get('preventSelect', options)) {
85        el.style.webkitTouchCallout = "none";
86        el.style.webkitUserSelect = "none";
87        el.style.khtmlUserSelect = "none";
88        el.style.MozUserSelect = "none";
89        el.style.msUserSelect = "none";
90        el.style.userSelect = "none";
91      }
92    }
93  }]);
94
95  return Element;
96}();
97/*
98This is the base adapter from which all the other adapters extend.
99*/
100
101
102var Adapter = /*#__PURE__*/function () {
103  function Adapter(el, block, options) {
104    _classCallCheck(this, Adapter);
105
106    this.el = el;
107    this.block = block;
108    this.options = options;
109    this.pressed = false;
110    this.deepPressed = false;
111    this.nativeSupport = false;
112    this.runningPolyfill = false;
113    this.runKey = Math.random();
114  }
115
116  _createClass(Adapter, [{
117    key: "setPressed",
118    value: function setPressed(_boolean) {
119      this.pressed = _boolean;
120    }
121  }, {
122    key: "setDeepPressed",
123    value: function setDeepPressed(_boolean2) {
124      this.deepPressed = _boolean2;
125    }
126  }, {
127    key: "isPressed",
128    value: function isPressed() {
129      return this.pressed;
130    }
131  }, {
132    key: "isDeepPressed",
133    value: function isDeepPressed() {
134      return this.deepPressed;
135    }
136  }, {
137    key: "add",
138    value: function add(event, set) {
139      this.el.addEventListener(event, set, false);
140    }
141  }, {
142    key: "runClosure",
143    value: function runClosure(method) {
144      if (method in this.block) {
145        // call the closure method and apply nth arguments if they exist
146        this.block[method].apply(this.el, Array.prototype.slice.call(arguments, 1));
147      }
148    }
149  }, {
150    key: "fail",
151    value: function fail(event, runKey) {
152      if (Config.get('polyfill', this.options)) {
153        if (this.runKey === runKey) {
154          this.runPolyfill(event);
155        }
156      } else {
157        this.runClosure('unsupported', event);
158      }
159    }
160  }, {
161    key: "bindUnsupportedEvent",
162    value: function bindUnsupportedEvent() {
163      var _this = this;
164
165      this.add(supportsTouch ? 'touchstart' : 'mousedown', function (event) {
166        return _this.runClosure('unsupported', event);
167      });
168    }
169  }, {
170    key: "_startPress",
171    value: function _startPress(event) {
172      if (this.isPressed() === false) {
173        this.runningPolyfill = false;
174        this.setPressed(true);
175        this.runClosure('start', event);
176      }
177    }
178  }, {
179    key: "_startDeepPress",
180    value: function _startDeepPress(event) {
181      if (this.isPressed() && this.isDeepPressed() === false) {
182        this.setDeepPressed(true);
183        this.runClosure('startDeepPress', event);
184      }
185    }
186  }, {
187    key: "_changePress",
188    value: function _changePress(force, event) {
189      this.nativeSupport = true;
190      this.runClosure('change', force, event);
191    }
192  }, {
193    key: "_endDeepPress",
194    value: function _endDeepPress() {
195      if (this.isPressed() && this.isDeepPressed()) {
196        this.setDeepPressed(false);
197        this.runClosure('endDeepPress');
198      }
199    }
200  }, {
201    key: "_endPress",
202    value: function _endPress() {
203      if (this.runningPolyfill === false) {
204        if (this.isPressed()) {
205          this._endDeepPress();
206
207          this.setPressed(false);
208          this.runClosure('end');
209        }
210
211        this.runKey = Math.random();
212        this.nativeSupport = false;
213      } else {
214        this.setPressed(false);
215      }
216    }
217  }, {
218    key: "deepPress",
219    value: function deepPress(force, event) {
220      force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
221    }
222  }, {
223    key: "runPolyfill",
224    value: function runPolyfill(event) {
225      this.increment = Config.get('polyfillSpeedUp', this.options) === 0 ? 1 : 10 / Config.get('polyfillSpeedUp', this.options);
226      this.decrement = Config.get('polyfillSpeedDown', this.options) === 0 ? 1 : 10 / Config.get('polyfillSpeedDown', this.options);
227      this.setPressed(true);
228      this.runClosure('start', event);
229
230      if (this.runningPolyfill === false) {
231        this.loopPolyfillForce(0, event);
232      }
233    }
234  }, {
235    key: "loopPolyfillForce",
236    value: function loopPolyfillForce(force, event) {
237      if (this.nativeSupport === false) {
238        if (this.isPressed()) {
239          this.runningPolyfill = true;
240          force = force + this.increment > 1 ? 1 : force + this.increment;
241          this.runClosure('change', force, event);
242          this.deepPress(force, event);
243          setTimeout(this.loopPolyfillForce.bind(this, force, event), 10);
244        } else {
245          force = force - this.decrement < 0 ? 0 : force - this.decrement;
246
247          if (force < 0.5 && this.isDeepPressed()) {
248            this.setDeepPressed(false);
249            this.runClosure('endDeepPress');
250          }
251
252          if (force === 0) {
253            this.runningPolyfill = false;
254            this.setPressed(true);
255
256            this._endPress();
257          } else {
258            this.runClosure('change', force, event);
259            this.deepPress(force, event);
260            setTimeout(this.loopPolyfillForce.bind(this, force, event), 10);
261          }
262        }
263      }
264    }
265  }]);
266
267  return Adapter;
268}();
269/*
270This adapter is for Macs with Force Touch trackpads.
271*/
272
273
274var AdapterForceTouch = /*#__PURE__*/function (_Adapter) {
275  _inherits(AdapterForceTouch, _Adapter);
276
277  var _super = _createSuper(AdapterForceTouch);
278
279  function AdapterForceTouch(el, block, options) {
280    _classCallCheck(this, AdapterForceTouch);
281
282    return _super.call(this, el, block, options);
283  }
284
285  _createClass(AdapterForceTouch, [{
286    key: "bindEvents",
287    value: function bindEvents() {
288      this.add('webkitmouseforcewillbegin', this._startPress.bind(this));
289      this.add('mousedown', this.support.bind(this));
290      this.add('webkitmouseforcechanged', this.change.bind(this));
291      this.add('webkitmouseforcedown', this._startDeepPress.bind(this));
292      this.add('webkitmouseforceup', this._endDeepPress.bind(this));
293      this.add('mouseleave', this._endPress.bind(this));
294      this.add('mouseup', this._endPress.bind(this));
295    }
296  }, {
297    key: "support",
298    value: function support(event) {
299      if (this.isPressed() === false) {
300        this.fail(event, this.runKey);
301      }
302    }
303  }, {
304    key: "change",
305    value: function change(event) {
306      if (this.isPressed() && event.webkitForce > 0) {
307        this._changePress(this.normalizeForce(event.webkitForce), event);
308      }
309    } // make the force the standard 0 to 1 scale and not the 1 to 3 scale
310
311  }, {
312    key: "normalizeForce",
313    value: function normalizeForce(force) {
314      return this.reachOne(_map(force, 1, 3, 0, 1));
315    } // if the force value is above 0.995 set the force to 1
316
317  }, {
318    key: "reachOne",
319    value: function reachOne(force) {
320      return force > 0.995 ? 1 : force;
321    }
322  }]);
323
324  return AdapterForceTouch;
325}(Adapter);
326/*
327This adapter is more mobile devices that support 3D Touch.
328*/
329
330
331var Adapter3DTouch = /*#__PURE__*/function (_Adapter2) {
332  _inherits(Adapter3DTouch, _Adapter2);
333
334  var _super2 = _createSuper(Adapter3DTouch);
335
336  function Adapter3DTouch(el, block, options) {
337    _classCallCheck(this, Adapter3DTouch);
338
339    return _super2.call(this, el, block, options);
340  }
341
342  _createClass(Adapter3DTouch, [{
343    key: "bindEvents",
344    value: function bindEvents() {
345      if (supportsTouchForceChange) {
346        this.add('touchforcechange', this.start.bind(this));
347        this.add('touchstart', this.support.bind(this, 0));
348        this.add('touchend', this._endPress.bind(this));
349      } else {
350        this.add('touchstart', this.startLegacy.bind(this));
351        this.add('touchend', this._endPress.bind(this));
352      }
353    }
354  }, {
355    key: "start",
356    value: function start(event) {
357      if (event.touches.length > 0) {
358        this._startPress(event);
359
360        this.touch = this.selectTouch(event);
361
362        if (this.touch) {
363          this._changePress(this.touch.force, event);
364        }
365      }
366    }
367  }, {
368    key: "support",
369    value: function support(iter, event) {
370      var runKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.runKey;
371
372      if (this.isPressed() === false) {
373        if (iter <= 6) {
374          iter++;
375          setTimeout(this.support.bind(this, iter, event, runKey), 10);
376        } else {
377          this.fail(event, runKey);
378        }
379      }
380    }
381  }, {
382    key: "startLegacy",
383    value: function startLegacy(event) {
384      this.initialForce = event.touches[0].force;
385      this.supportLegacy(0, event, this.runKey, this.initialForce);
386    } // this checks up to 6 times on a touch to see if the touch can read a force value
387    // if the force value has changed it means the device supports pressure
388    // more info from this issue https://github.com/yamartino/pressure/issues/15
389
390  }, {
391    key: "supportLegacy",
392    value: function supportLegacy(iter, event, runKey, force) {
393      if (force !== this.initialForce) {
394        this._startPress(event);
395
396        this.loopForce(event);
397      } else if (iter <= 6) {
398        iter++;
399        setTimeout(this.supportLegacy.bind(this, iter, event, runKey, force), 10);
400      } else {
401        this.fail(event, runKey);
402      }
403    }
404  }, {
405    key: "loopForce",
406    value: function loopForce(event) {
407      if (this.isPressed()) {
408        this.touch = this.selectTouch(event);
409        setTimeout(this.loopForce.bind(this, event), 10);
410
411        this._changePress(this.touch.force, event);
412      }
413    } // link up the touch point to the correct element, this is to support multitouch
414
415  }, {
416    key: "selectTouch",
417    value: function selectTouch(event) {
418      if (event.touches.length === 1) {
419        return this.returnTouch(event.touches[0], event);
420      } else {
421        for (var i = 0; i < event.touches.length; i++) {
422          // if the target press is on this element
423          if (event.touches[i].target === this.el || this.el.contains(event.touches[i].target)) {
424            return this.returnTouch(event.touches[i], event);
425          }
426        }
427      }
428    } // return the touch and run a start or end for deep press
429
430  }, {
431    key: "returnTouch",
432    value: function returnTouch(touch, event) {
433      this.deepPress(touch.force, event);
434      return touch;
435    }
436  }]);
437
438  return Adapter3DTouch;
439}(Adapter);
440/*
441This adapter is for devices that support pointer events.
442*/
443
444
445var AdapterPointer = /*#__PURE__*/function (_Adapter3) {
446  _inherits(AdapterPointer, _Adapter3);
447
448  var _super3 = _createSuper(AdapterPointer);
449
450  function AdapterPointer(el, block, options) {
451    _classCallCheck(this, AdapterPointer);
452
453    return _super3.call(this, el, block, options);
454  }
455
456  _createClass(AdapterPointer, [{
457    key: "bindEvents",
458    value: function bindEvents() {
459      this.add('pointerdown', this.support.bind(this));
460      this.add('pointermove', this.change.bind(this));
461      this.add('pointerup', this._endPress.bind(this));
462      this.add('pointerleave', this._endPress.bind(this));
463    }
464  }, {
465    key: "support",
466    value: function support(event) {
467      if (this.isPressed() === false) {
468        if (event.pressure === 0 || event.pressure === 0.5 || event.pressure > 1) {
469          this.fail(event, this.runKey);
470        } else {
471          this._startPress(event);
472
473          this._changePress(event.pressure, event);
474        }
475      }
476    }
477  }, {
478    key: "change",
479    value: function change(event) {
480      if (this.isPressed() && event.pressure > 0 && event.pressure !== 0.5) {
481        this._changePress(event.pressure, event);
482
483        this.deepPress(event.pressure, event);
484      }
485    }
486  }]);
487
488  return AdapterPointer;
489}(Adapter); // This class holds the states of the the Pressure config
490
491
492var Config = {
493  // 'false' will make polyfill not run when pressure is not supported and the 'unsupported' method will be called
494  polyfill: true,
495  // milliseconds it takes to go from 0 to 1 for the polyfill
496  polyfillSpeedUp: 1000,
497  // milliseconds it takes to go from 1 to 0 for the polyfill
498  polyfillSpeedDown: 0,
499  // 'true' prevents the selecting of text and images via css properties
500  preventSelect: true,
501  // 'touch', 'mouse', or 'pointer' will make it run only on that type of device
502  only: null,
503  // this will get the correct config / option settings for the current pressure check
504  get: function get(option, options) {
505    return options.hasOwnProperty(option) ? options[option] : this[option];
506  },
507  // this will set the global configs
508  set: function set(options) {
509    for (var k in options) {
510      if (options.hasOwnProperty(k) && this.hasOwnProperty(k) && k != 'get' && k != 'set') {
511        this[k] = options[k];
512      }
513    }
514  }
515}; //------------------- Helpers -------------------//
516// accepts jQuery object, node list, string selector, then called a setup for each element
517
518var loopPressureElements = function loopPressureElements(selector, closure) {
519  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
520
521  // if a string is passed in as an element
522  if (typeof selector === 'string' || selector instanceof String) {
523    var elements = document.querySelectorAll(selector);
524
525    for (var i = 0; i < elements.length; i++) {
526      new Element(elements[i], closure, options);
527    } // if a single element object is passed in
528
529  } else if (isElement(selector)) {
530    new Element(selector, closure, options); // if a node list is passed in ex. jQuery $() object
531  } else {
532    for (var i = 0; i < selector.length; i++) {
533      new Element(selector[i], closure, options);
534    }
535  }
536}; //Returns true if it is a DOM element
537
538
539var isElement = function isElement(o) {
540  return (typeof HTMLElement === "undefined" ? "undefined" : _typeof(HTMLElement)) === "object" ? o instanceof HTMLElement : //DOM2
541  o && _typeof(o) === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName === "string";
542}; // the map method allows for interpolating a value from one range of values to another
543// example from the Arduino documentation: https://www.arduino.cc/en/Reference/Map
544
545
546var _map = function _map(x, in_min, in_max, out_min, out_max) {
547  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
548};
549
550var supportsMouse = false;
551var supportsTouch = false;
552var supportsPointer = false;
553var supportsTouchForce = false;
554var supportsTouchForceChange = false;
555
556if (typeof window !== 'undefined') {
557  // only attempt to assign these in a browser environment.
558  // on the server, this is a no-op, like the rest of the library
559  if (typeof Touch !== 'undefined') {
560    // In Android, new Touch requires arguments.
561    try {
562      if (Touch.prototype.hasOwnProperty('force') || 'force' in new Touch()) {
563        supportsTouchForce = true;
564      }
565    } catch (e) {}
566  }
567
568  supportsTouch = 'ontouchstart' in window.document && supportsTouchForce;
569  supportsMouse = 'onmousemove' in window.document && 'onwebkitmouseforcechanged' in window.document && !supportsTouch;
570  supportsPointer = 'onpointermove' in window.document;
571  supportsTouchForceChange = 'ontouchforcechange' in window.document;
572}
573return Pressure;
574}));

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.