vendor: 6,994 bytes, lines 1-273
1/* 2 # ----------------------------------------------------------------------------- 3 # ~/assets/themes/j1/modules/fam/js/cash.js 4 # MODIFIED old Cash version 1.3.5 from Materialize used by J1 Module FAM 5 # 6 # Product/Info: 7 # https://jekyll.one 8 # https://github.com/fabiospampinato/cash 9 # 10 # Copyright (C) 2022 Juergen Adams 11 # 12 # Cash is licensed under the MIT License. 13 # See: https://github.com/jekyll-one-org/J1 Template/blob/master/LICENSE 14 # J1 Template is licensed under the MIT License. 15 # See: https://github.com/fabiospampinato/cash/blob/master/LICENSE.md 16 # ----------------------------------------------------------------------------- 17 # NOTE: cash-dom 1.3.5, https://github.com/kenwheeler/cash 18 # ----------------------------------------------------------------------------- 19*/ 20(function (factory) { 21 window.cash = factory(); 22})(function () { 23 var doc = document, win = window, ArrayProto = Array.prototype, slice = ArrayProto.slice, filter = ArrayProto.filter, push = ArrayProto.push; 24 25 var noop = function () {}, isFunction = function (item) { 26 // @see https://crbug.com/568448 27 return typeof item === typeof noop && item.call; 28 }, isString = function (item) { 29 return typeof item === typeof ""; 30 }; 31 32 var idMatch = /^#[\w-]*$/, classMatch = /^\.[\w-]*$/, htmlMatch = /<.+>/, singlet = /^\w+$/; 33 34 function find(selector, context) { 35 context = context || doc; 36 var elems = (classMatch.test(selector) ? context.getElementsByClassName(selector.slice(1)) : singlet.test(selector) ? context.getElementsByTagName(selector) : context.querySelectorAll(selector)); 37 return elems; 38 } 39 40 var frag; 41 function parseHTML(str) { 42 if (!frag) { 43 frag = doc.implementation.createHTMLDocument(null); 44 var base = frag.createElement("base"); 45 base.href = doc.location.href; 46 frag.head.appendChild(base); 47 } 48 49 frag.body.innerHTML = str; 50 51 return frag.body.childNodes; 52 } 53 54 function onReady(fn) { 55 if (doc.readyState !== "loading") { 56 fn(); 57 } else { 58 doc.addEventListener("DOMContentLoaded", fn); 59 } 60 } 61 62 function Init(selector, context) { 63 if (!selector) { 64 return this; 65 } 66 67 // If already a cash collection, don't do any further processing 68 if (selector.cash && selector !== win) { 69 return selector; 70 } 71 72 var elems = selector, i = 0, length; 73 74 if (isString(selector)) { 75 elems = (idMatch.test(selector) ? 76 // If an ID use the faster getElementById check 77 doc.getElementById(selector.slice(1)) : htmlMatch.test(selector) ? 78 // If HTML, parse it into real elements 79 parseHTML(selector) : 80 // else use `find` 81 find(selector, context)); 82 83 // If function, use as shortcut for DOM ready 84 } else if (isFunction(selector)) { 85 onReady(selector);return this; 86 } 87 88 if (!elems) { 89 return this; 90 } 91 92 // If a single DOM element is passed in or received via ID, return the single element 93 if (elems.nodeType || elems === win) { 94 this[0] = elems; 95 this.length = 1; 96 } else { 97 // Treat like an array and loop through each item. 98 length = this.length = elems.length; 99 for (; i < length; i++) { 100 this[i] = elems[i]; 101 } 102 } 103 104 return this; 105 } 106 107 function cash(selector, context) { 108 return new Init(selector, context); 109 } 110 111 var fn = cash.fn = cash.prototype = Init.prototype = { // jshint ignore:line 112 cash: true, 113 length: 0, 114 push: push, 115 splice: ArrayProto.splice, 116 map: ArrayProto.map, 117 init: Init 118 }; 119 120 Object.defineProperty(fn, "constructor", { value: cash }); 121 122 cash.parseHTML = parseHTML; 123 cash.noop = noop; 124 cash.isFunction = isFunction; 125 cash.isString = isString; 126 127 cash.extend = fn.extend = function (target) { 128 target = target || {}; 129 130 var args = slice.call(arguments), length = args.length, i = 1; 131 132 if (args.length === 1) { 133 target = this; 134 i = 0; 135 } 136 137 for (; i < length; i++) { 138 if (!args[i]) { 139 continue; 140 } 141 for (var key in args[i]) { 142 if (args[i].hasOwnProperty(key)) { 143 target[key] = args[i][key]; 144 } 145 } 146 } 147 148 return target; 149 }; 150 151 function each(collection, callback) { 152 var l = collection.length, i = 0; 153 154 for (; i < l; i++) { 155 if (callback.call(collection[i], collection[i], i, collection) === false) { 156 break; 157 } 158 } 159 } 160 161 function matches(el, selector) { 162 var m = el && (el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector || el.oMatchesSelector); 163 return !!m && m.call(el, selector); 164 } 165 166 function getCompareFunction(selector) { 167 return ( 168 /* Use browser's `matches` function if string */ 169 isString(selector) ? matches : 170 /* Match a cash element */ 171 selector.cash ? function (el) { 172 return selector.is(el); 173 } : 174 /* Direct comparison */ 175 function (el, selector) { 176 return el === selector; 177 }); 178 } 179 180 function unique(collection) { 181 return cash(slice.call(collection).filter(function (item, index, self) { 182 return self.indexOf(item) === index; 183 })); 184 } 185 186 cash.extend({ 187 merge: function (first, second) { 188 var len = +second.length, i = first.length, j = 0; 189 190 for (; j < len; i++, j++) { 191 first[i] = second[j]; 192 } 193 194 first.length = i; 195 return first; 196 }, 197 198 each: each, 199 matches: matches, 200 unique: unique, 201 isArray: Array.isArray, 202 isNumeric: function (n) { 203 return !isNaN(parseFloat(n)) && isFinite(n); 204 } 205 206 }); 207 208 var uid = cash.uid = "_cash" + Date.now(); 209 210 function getDataCache(node) { 211 return (node[uid] = node[uid] || {}); 212 } 213 214 function setData(node, key, value) { 215 return (getDataCache(node)[key] = value); 216 } 217 218 function getData(node, key) { 219 var c = getDataCache(node); 220 if (c[key] === undefined) { 221 c[key] = node.dataset ? node.dataset[key] : cash(node).attr("data-" + key); 222 } 223 return c[key]; 224 } 225 226 function removeData(node, key) { 227 var c = getDataCache(node); 228 if (c) { 229 delete c[key]; 230 } else if (node.dataset) { 231 delete node.dataset[key]; 232 } else { 233 cash(node).removeAttr("data-" + name); 234 } 235 } 236 237 fn.extend({ 238 data: function (name, value) { 239 if (isString(name)) { 240 return (value === undefined ? getData(this[0], name) : this.each(function (v) { 241 return setData(v, name, value); 242 })); 243 } 244 245 for (var key in name) { 246 this.data(key, name[key]); 247 } 248 249 return this; 250 }, 251 252 removeData: function (key) { 253 return this.each(function (v) { 254 return removeData(v, key); 255 }); 256 } 257 258 }); 259 260 var notWhiteMatch = /\S+/g; 261 262 function getClasses(c) { 263 return isString(c) && c.match(notWhiteMatch); 264 } 265 266 function hasClass(v, c) { 267 return (v.classList ? v.classList.contains(c) : new RegExp("(^| )" + c + "( |$)", "gi").test(v.className)); 268 } 269 270 function addClass(v, c, spacedName) { 271 if (v.classList) { 272 v.classList.add(c); 273 }
273 else if (spacedName.indexOf(" " + c + " ")) { 274 v.className += " " + c; 275 } 276 } 277 278 function removeClass(v, c) { 279 if (v.classList) { 280 v.classList.remove(c); 281 } else { 282 v.className = v.className.replace(c, ""); 283 } 284 } 285 286 fn.extend({ 287 addClass: function (c) { 288 var classes = getClasses(c); 289 290 return (classes ? this.each(function (v) { 291 var spacedName = " " + v.className + " "; 292 each(classes, function (c) { 293 addClass(v, c, spacedName); 294 }); 295 }) : this); 296 }, 297 298 attr: function (name, value) { 299 if (!name) { 300 return undefined; 301 } 302 303 if (isString(name)) { 304 if (value === undefined) { 305 return this[0] ? this[0].getAttribute ? this[0].getAttribute(name) : this[0][name] : undefined; 306 } 307 308 return this.each(function (v) { 309 if (v.setAttribute) { 310 v.setAttribute(name, value); 311 } else { 312 v[name] = value; 313 } 314 }); 315 } 316 317 for (var key in name) { 318 this.attr(key, name[key]); 319 } 320 321 return this; 322 }, 323 324 hasClass: function (c) { 325 var check = false, classes = getClasses(c); 326 if (classes && classes.length) { 327 this.each(function (v) { 328 check = hasClass(v, classes[0]); 329 return !check; 330 }); 331 } 332 return check; 333 }, 334 335 prop: function (name, value) { 336 if (isString(name)) { 337 return (value === undefined ? this[0][name] : this.each(function (v) { 338 v[name] = value; 339 })); 340 } 341 342 for (var key in name) { 343 this.prop(key, name[key]); 344 } 345 346 return this; 347 }, 348 349 removeAttr: function (name) { 350 return this.each(function (v) { 351 if (v.removeAttribute) { 352 v.removeAttribute(name); 353 } else { 354 delete v[name]; 355 } 356 }); 357 }, 358 359 removeClass: function (c) { 360 if (!arguments.length) { 361 return this.attr("class", ""); 362 } 363 var classes = getClasses(c); 364 return (classes ? this.each(function (v) { 365 each(classes, function (c) { 366 removeClass(v, c); 367 }); 368 }) : this); 369 }, 370 371 removeProp: function (name) { 372 return this.each(function (v) { 373 delete v[name]; 374 }); 375 }, 376 377 toggleClass: function (c, state) { 378 if (state !== undefined) { 379 return this[state ? "addClass" : "removeClass"](c); 380 } 381 var classes = getClasses(c); 382 return (classes ? this.each(function (v) { 383 var spacedName = " " + v.className + " "; 384 each(classes, function (c) { 385 if (hasClass(v, c)) { 386 removeClass(v, c); 387 } else { 388 addClass(v, c, spacedName); 389 } 390 }); 391 }) : this); 392 } }); 393 394 fn.extend({ 395 add: function (selector, context) { 396 return unique(cash.merge(this, cash(selector, context))); 397 }, 398 399 each: function (callback) { 400 each(this, callback); 401 return this; 402 }, 403 404 eq: function (index) { 405 return cash(this.get(index)); 406 }, 407 408 filter: function (selector) { 409 if (!selector) { 410 return this; 411 } 412 413 var comparator = (isFunction(selector) ? selector : getCompareFunction(selector)); 414 415 return cash(filter.call(this, function (e) { 416 return comparator(e, selector); 417 })); 418 }, 419 420 first: function () { 421 return this.eq(0); 422 }, 423 424 get: function (index) { 425 if (index === undefined) { 426 return slice.call(this); 427 } 428 return (index < 0 ? this[index + this.length] : this[index]); 429 }, 430 431 index: function (elem) { 432 var child = elem ? cash(elem)[0] : this[0], collection = elem ? this : cash(child).parent().children(); 433 return slice.call(collection).indexOf(child); 434 }, 435 436 last: function () { 437 return this.eq(-1); 438 } 439 440 }); 441 442 var camelCase = (function () { 443 var camelRegex = /(?:^\w|[A-Z]|\b\w)/g, whiteSpace = /[\s-_]+/g; 444 return function (str) { 445 return str.replace(camelRegex, function (letter, index) { 446 return letter[index === 0 ? "toLowerCase" : "toUpperCase"](); 447 }).replace(whiteSpace, ""); 448 }; 449 }()); 450 451 var getPrefixedProp = (function () { 452 var cache = {}, doc = document, div = doc.createElement("div"), style = div.style; 453 454 return function (prop) { 455 prop = camelCase(prop); 456 if (cache[prop]) { 457 return cache[prop]; 458 } 459 460 var ucProp = prop.charAt(0).toUpperCase() + prop.slice(1), prefixes = ["webkit", "moz", "ms", "o"], props = (prop + " " + (prefixes).join(ucPro
460p + " ") + ucProp).split(" "); 461 462 each(props, function (p) { 463 if (p in style) { 464 cache[p] = prop = cache[prop] = p; 465 return false; 466 } 467 }); 468 469 return cache[prop]; 470 }; 471 }()); 472 473 cash.prefixedProp = getPrefixedProp; 474 cash.camelCase = camelCase; 475 476 fn.extend({ 477 css: function (prop, value) { 478 if (isString(prop)) { 479 prop = getPrefixedProp(prop); 480 return (arguments.length > 1 ? this.each(function (v) { 481 return v.style[prop] = value; 482 }) : win.getComputedStyle(this[0])[prop]); 483 } 484 485 for (var key in prop) { 486 this.css(key, prop[key]); 487 } 488 489 return this; 490 } 491 492 }); 493 494 function compute(el, prop) { 495 return parseInt(win.getComputedStyle(el[0], null)[prop], 10) || 0; 496 } 497 498 each(["Width", "Height"], function (v) { 499 var lower = v.toLowerCase(); 500 501 fn[lower] = function () { 502 return this[0].getBoundingClientRect()[lower]; 503 }; 504 505 fn["inner" + v] = function () { 506 return this[0]["client" + v]; 507 }; 508 509 fn["outer" + v] = function (margins) { 510 return this[0]["offset" + v] + (margins ? compute(this, "margin" + (v === "Width" ? "Left" : "Top")) + compute(this, "margin" + (v === "Width" ? "Right" : "Bottom")) : 0); 511 }; 512 }); 513 514 function registerEvent(node, eventName, callback) { 515 var eventCache = getData(node, "_cashEvents") || setData(node, "_cashEvents", {}); 516 eventCache[eventName] = eventCache[eventName] || []; 517 eventCache[eventName].push(callback); 518 node.addEventListener(eventName, callback); 519 } 520 521 function removeEvent(node, eventName, callback) { 522 var events = getData(node, "_cashEvents"), eventCache = (events && events[eventName]), index; 523 524 if (!eventCache) { 525 return; 526 } 527 528 if (callback) { 529 node.removeEventListener(eventName, callback); 530 index = eventCache.indexOf(callback); 531 if (index >= 0) { 532 eventCache.splice(index, 1); 533 } 534 } else { 535 each(eventCache, function (event) { 536 node.removeEventListener(eventName, event); 537 }); 538 eventCache = []; 539 } 540 } 541 542 fn.extend({ 543 off: function (eventName, callback) { 544 return this.each(function (v) { 545 return removeEvent(v, eventName, callback); 546 }); 547 }, 548 549 on: function (eventName, delegate, callback, runOnce) { 550 // jshint ignore:line 551 var originalCallback; 552 if (!isString(eventName)) { 553 for (var key in eventName) { 554 this.on(key, delegate, eventName[key]); 555 } 556 return this; 557 } 558 559 if (isFunction(delegate)) { 560 callback = delegate; 561 delegate = null; 562 } 563 564 if (eventName === "ready") { 565 onReady(callback); 566 return this; 567 } 568 569 if (delegate) { 570 originalCallback = callback; 571 callback = function (e) { 572 var t = e.target; 573 while (!matches(t, delegate)) { 574 if (t === this || t === null) { 575 return (t = false); 576 } 577 578 t = t.parentNode; 579 } 580 581 if (t) { 582 originalCallback.call(t, e); 583 } 584 }; 585 } 586 587 return this.each(function (v) { 588 var finalCallback = callback; 589 if (runOnce) { 590 finalCallback = function () { 591 callback.apply(this, arguments); 592 removeEvent(v, eventName, finalCallback); 593 }; 594 } 595 registerEvent(v, eventName, finalCallback); 596 }); 597 }, 598 599 one: function (eventName, delegate, callback) { 600 return this.on(eventName, delegate, callback, true); 601 }, 602 603 ready: onReady, 604 605 /** 606 * Modified 607 * Triggers browser event 608 * @param String eventName 609 * @param Object data - Add properties to event object 610 */ 611 trigger: function (eventName, data) { 612 if (document.createEvent) { 613 var evt = document.createEvent('HTMLEvents'); 614 evt.initEvent(eventName, true, false); 615 evt = this.extend(evt, data); 616 return this.each(function (v) { 617 return v.dispatchEvent(evt); 618 }); 619 } 620 } 621 622 }); 623 624 function encode(name, value) { 625 return "&" + encodeURIComponent(name) + "=" + encodeURIComponent(value).replace(/%20/g, "+"); 626 } 627 628 function getSelectMultiple_(el) { 629 var values = []; 630 each(el.options, function (o) { 631 if (o.selected) { 632 values.push(o.value); 633 } 634 }); 635 return values.length ? values : null; 636 } 637 638 function getSelectSingle_(el) { 639 var selectedIndex = el.selectedIndex; 640 return selectedIndex >
640= 0 ? el.options[selectedIndex].value : null; 641 } 642 643 function getValue(el) { 644 var type = el.type; 645 if (!type) { 646 return null; 647 } 648 switch (type.toLowerCase()) { 649 case "select-one": 650 return getSelectSingle_(el); 651 case "select-multiple": 652 return getSelectMultiple_(el); 653 case "radio": 654 return (el.checked) ? el.value : null; 655 case "checkbox": 656 return (el.checked) ? el.value : null; 657 default: 658 return el.value ? el.value : null; 659 } 660 } 661 662 fn.extend({ 663 serialize: function () { 664 var query = ""; 665 666 each(this[0].elements || this, function (el) { 667 if (el.disabled || el.tagName === "FIELDSET") { 668 return; 669 } 670 var name = el.name; 671 switch (el.type.toLowerCase()) { 672 case "file": 673 case "reset": 674 case "submit": 675 case "button": 676 break; 677 case "select-multiple": 678 var values = getValue(el); 679 if (values !== null) { 680 each(values, function (value) { 681 query += encode(name, value); 682 }); 683 } 684 break; 685 default: 686 var value = getValue(el); 687 if (value !== null) { 688 query += encode(name, value); 689 } 690 } 691 }); 692 693 return query.substr(1); 694 }, 695 696 val: function (value) { 697 if (value === undefined) { 698 return getValue(this[0]); 699 } 700 701 return this.each(function (v) { 702 return v.value = value; 703 }); 704 } 705 706 }); 707 708 function insertElement(el, child, prepend) { 709 if (prepend) { 710 var first = el.childNodes[0]; 711 el.insertBefore(child, first); 712 } else { 713 el.appendChild(child); 714 } 715 } 716 717 function insertContent(parent, child, prepend) { 718 var str = isString(child); 719 720 if (!str && child.length) { 721 each(child, function (v) { 722 return insertContent(parent, v, prepend); 723 }); 724 return; 725 } 726 727 each(parent, str ? function (v) { 728 return v.insertAdjacentHTML(prepend ? "afterbegin" : "beforeend", child); 729 } : function (v, i) { 730 return insertElement(v, (i === 0 ? child : child.cloneNode(true)), prepend); 731 }); 732 } 733 734 fn.extend({ 735 after: function (selector) { 736 cash(selector).insertAfter(this); 737 return this; 738 }, 739 740 append: function (content) { 741 insertContent(this, content); 742 return this; 743 }, 744 745 appendTo: function (parent) { 746 insertContent(cash(parent), this); 747 return this; 748 }, 749 750 before: function (selector) { 751 cash(selector).insertBefore(this); 752 return this; 753 }, 754 755 clone: function () { 756 return cash(this.map(function (v) { 757 return v.cloneNode(true); 758 })); 759 }, 760 761 empty: function () { 762 this.html(""); 763 return this; 764 }, 765 766 html: function (content) { 767 if (content === undefined) { 768 return this[0].innerHTML; 769 } 770 var source = (content.nodeType ? content[0].outerHTML : content); 771 return this.each(function (v) { 772 return v.innerHTML = source; 773 }); 774 }, 775 776 insertAfter: function (selector) { 777 var _this = this; 778 779 780 cash(selector).each(function (el, i) { 781 var parent = el.parentNode, sibling = el.nextSibling; 782 _this.each(function (v) { 783 parent.insertBefore((i === 0 ? v : v.cloneNode(true)), sibling); 784 }); 785 }); 786 787 return this; 788 }, 789 790 insertBefore: function (selector) { 791 var _this2 = this; 792 cash(selector).each(function (el, i) { 793 var parent = el.parentNode; 794 _this2.each(function (v) { 795 parent.insertBefore((i === 0 ? v : v.cloneNode(true)), el); 796 }); 797 }); 798 return this; 799 }, 800 801 prepend: function (content) { 802 insertContent(this, content, true); 803 return this; 804 }, 805 806 prependTo: function (parent) { 807 insertContent(cash(parent), this, true); 808 return this; 809 }, 810 811 remove: function () { 812 return this.each(function (v) { 813 if (!!v.parentNode) { 814 return v.parentNode.removeChild(v); 815 } 816 }); 817 }, 818 819 text: function (content) { 820 if (content === undefined) { 821 return this[0].textContent; 822 } 823 return this.each(function (v) { 824 return v.textContent = content; 825 }); 826 } 827 828 }); 829 830 var docEl = doc.documentElement; 831 832 fn.extend({ 833 position: function () { 834 var el = this[0]; 835 return { 836 left: el.offsetLeft, 837 top: el.offsetTop 838 }; 839 }, 840 841 offset: function () { 842 var rect = this[0].getBoundingClientRect(); 843 return { 844 top: rect.top + win.pageYOffset - docEl.clientTop, 845 left: rect.left + win.pageXOffset - docEl.clientLeft 846 }; 847 }, 848 849 offsetParent: function () { 850 return cash(this[0].offsetParent); 851 } 852 853 }); 854 855 fn.extend({ 856 children: function (selector) { 857 var elems = []; 858 this.each(function (el) { 859 push.apply(elems, el.children); 860 }); 861 elems = unique(elems); 862 863 return (!selector ? elems : elems.filter(function (v) { 864 return matches(v, selector); 865 })); 866 }, 867 868 closest: function (selector) { 869 if (!selector || this.length < 1) { 870 return cash(); 871 } 872 if (this.is(selector)) { 873 return this.filter(selector); 874 } 875 return this.parent().closest(selector); 876 }, 877 878 is: function (selector) { 879 if (!selector) { 880 return false;
881 } 882 883 var match = false, comparator = getCompareFunction(selector); 884 885 this.each(function (el) { 886 match = comparator(el, selector); 887 return !match; 888 }); 889 890 return match; 891 }, 892 893 find: function (selector) { 894 if (!selector || selector.nodeType) { 895 return cash(selector && this.has(selector).length ? selector : null); 896 } 897 898 var elems = []; 899 this.each(function (el) { 900 push.apply(elems, find(selector, el)); 901 }); 902 903 return unique(elems); 904 }, 905 906 has: function (selector) { 907 var comparator = (isString(selector) ? function (el) { 908 return find(selector, el).length !== 0; 909 } : function (el) { 910 return el.contains(selector); 911 }); 912 913 return this.filter(comparator); 914 }, 915 916 next: function () { 917 return cash(this[0].nextElementSibling); 918 }, 919 920 not: function (selector) { 921 if (!selector) { 922 return this; 923 } 924 925 var comparator = getCompareFunction(selector); 926 927 return this.filter(function (el) { 928 return !comparator(el, selector); 929 }); 930 }, 931 932 parent: function () { 933 var result = []; 934 935 this.each(function (item) { 936 if (item && item.parentNode) { 937 result.push(item.parentNode); 938 } 939 }); 940 941 return unique(result); 942 }, 943 944 parents: function (selector) { 945 var last, result = []; 946 947 this.each(function (item) { 948 last = item; 949 950 while (last && last.parentNode && last !== doc.body.parentNode) { 951 last = last.parentNode; 952 953 if (!selector || (selector && matches(last, selector))) { 954 result.push(last); 955 } 956 } 957 }); 958 959 return unique(result); 960 }, 961 962 prev: function () { 963 return cash(this[0].previousElementSibling); 964 }, 965 966 siblings: function (selector) { 967 var collection = this.parent().children(selector), el = this[0]; 968 969 return collection.filter(function (i) { 970 return i !== el; 971 }); 972 } 973 974 }); 975 976 977 return cash; 978});
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.