PageSourceSearch

https://www.successfulmat.com/frontend/js/help.js

js successfulmat.com collected 2026-10-04 04:50:45 UTC 8,446 bytes, 249 lines download raw bytes

1/**
2 * Listen to clicks on an element that matches the selector using only one event defined at root of the document.
3 * Similar to jQuery .delegate() but faster.
4 */
5(function() {
6  let delegationSelectorsMap = {};
7
8  window.init_delegate = function(){
9
10    window.delegate = function (event, selector, callback, options) {
11      if (event == void 0){
12        return delegationSelectorsMap;
13      }
14      if (typeof selector === 'undefined' || selector === '') throw new Error('The provided selector is empty.');
15      if (typeof callback === 'undefined' || typeof callback !== 'function') throw new Error('Specify an callback.');
16      if (!delegationSelectorsMap[event]) {
17        delegationSelectorsMap[event] = [];
18        document.addEventListener(event, function (evt) {
19          let element = evt.target;
20          let forceBreak = false;
21          while (element && element !== document.documentElement) {
22            for (const selector in delegationSelectorsMap[event]) {
23                element = element == document ? document.body : element;
24                if (element.matches(selector)) {
25                  evt.stopPropagation = function () {
26                    forceBreak = true;
27                  };
28                  const callbackList = delegationSelectorsMap[event][selector];
29                  callbackList.forEach(function (callback) { callback(element, evt); });
30                }
31            }
32
33            if (forceBreak) break;
34
35            element = element.parentElement;
36          }
37        }, options)
38      }
39      if (!delegationSelectorsMap[event][selector]) {
40        // Add new selector to the list
41        delegationSelectorsMap[event][selector] = [callback];
42      } else {
43        delegationSelectorsMap[event][selector].push(callback);
44      }
45
46      function unsubscribeFN () {
47        if (!delegationSelectorsMap[event][selector]) return;
48
49        if (delegationSelectorsMap[selector].length >= 2) {
50          delegationSelectorsMap[event][selector] = delegationSelectorsMap[event][selector].filter(cb => cb !== callback);
51        } else {
52          delete delegationSelectorsMap[event][selector];
53        }
54      }
55
56      return unsubscribeFN;
57    }
58  }
59
60  if (typeof $ !== 'function') {
61      window.init_delegate();
62  } else {
63    if (typeof $.fn !== 'function'){
64      window.init_delegate();
65    } else {
66      if (typeof $.fn.delegate !== 'function'){
67        window.init_delegate();
68      }
69    }
70  }
71  if (window.needDelegate){
72    window.init_delegate();
73  }
74
75  window.attr_merge = function (attributes, options, refer){
76    if (isJquery(attributes)) {
77      attributes = attributes.get(0).attributes;
78    }
79    if (isHTML(attributes)) {
80      attributes = attributes.attributes
81    }
82    if (typeof refer == 'undefined') {
83      refer = options;
84    }
85    let = stringtype = ['function', 'string', 'undefined'];
86    let = evaltype = ['boolean', 'number', 'object', 'array'];
87    Object.keys(refer).forEach(function(elmt) {
88      if (attributes['data-' + elmt] != undefined) {
89        try {
90          var attributetype = eval('typeof ' + attributes['data-' + elmt].value);
91        } catch (e) {
92          var attributetype = 'string';
93        }
94
95        if (evaltype.includes(attributetype)) {
96          eval('options[elmt] = ' + attributes['data-' + elmt].value);
97        } else {
98          if (stringtype.includes(attributetype)) {
99            options[elmt] = attributes['data-' + elmt].value;
100          }
101        }
102        // options[elmt] = eval('typeof ' + attributes['data-' + elmt].value) == "function" ? attributes['data-' + elmt].value : eval(attributes['data-' + elmt].value);
103      }
104    });
105    return options;
106  }
107
108  window.getObjName = function (obj){ return obj.constructor.name; }
109  window.isJquery = function(obj){ return window.getObjName(obj) == window.getObjName($('body')) }
110  window.isHTML = function(obj){ return  window.getObjName(obj).toLowerCase().includes('html') }
111
112  window.attr_prefix = function (attributes, prefix){
113    temp = {};
114    Object.keys(attributes).forEach(function(elmt){
115      if (elmt.indexOf(prefix + '-') == '0'){
116        pure_name = elmt.replace(prefix + '-', '');
117        temp[pure_name] = attributes[elmt];
118      }
119    });
120    return temp;
121  }
122
123  window.waitForFinalEvent = (function () {
124    let timers = {};
125    return function (callback, uniqueId, ms) {
126      ms = ms || 500;
127      uniqueId = uniqueId || Date.now();
128      if (timers[uniqueId]) { clearTimeout (timers[uniqueId]); }
129      timers[uniqueId] = setTimeout(callback, ms);
130      timers = window.jsonSort(timers);
131      return timers;
132    };
133  })();
134
135  window.jsonSort = function(json) {
136    return Object.keys(json).sort().reduce(
137      (obj, key) => {
138        obj[key] = json[key];
139        return obj;
140      },
141      {}
142    );
143  };
144
145  window.getAttibuteByPrefix = function(element, prefix, data = true) {
146    if (data){
147      prefix = `data-${ prefix }-`;
148    }
149    let attributes = null;
150    if (isJquery(element)) {
151      attributes = element.get(0).attributes;
152    }
153    if (isHTML(element)) {
154      attributes = element.attributes;
155    }
156    obj = {};
157    Object.values(attributes).map(function(val, i) {
158      key = val.name;
159      if (key.indexOf(prefix) == 0){
160        let objKey = key.replace(prefix, '');
161        obj[objKey] = val.value;
162      }
163    });
164    return obj;
165  };
166
167  window.groupJsonByPrefix = function(json, prefix, spliter = '-') {
168    Object.keys(json).map(function(key, i) {
169      if (key.indexOf(`${ prefix }-`) == 0){
170        json[prefix] = json[prefix] || {};
171        json[prefix][key.replace(`${ prefix }-`, '')] = json[key];
172        delete json[key];
173      }
174    });
175    json[prefix] = json[prefix] || {};
176  };
177
178  window.groupJsonByDefault = function(json, include = [], prefix = 'default') {
179    Object.keys(json).map(function(key, i) {
180      if(! (include.includes(key) || include.includes(key.split('-')[0]))){
181        json[prefix] = json[prefix] || {};
182        json[prefix][key] = json[key];
183        delete json[key];
184      }
185    });
186    json[prefix] = json[prefix] || {};
187  };
188
189  window.getPosition = function (element) {
190    let x = 0;
191    let y = 0;
192    while ( element ) {
193        x += element.offsetLeft - element.scrollLeft + element.clientLeft;
194        y += element.offsetTop - element.scrollLeft + element.clientTop;
195        element = element.offsetParent;
196    }
197    return { x: x, y: y };
198  }
199  window.getCookie = function( name ) {
200    const value = `; ${document.cookie}`;
201    const parts = value.split(`; ${name}=`);
202    if (parts.length === 2) return parts.pop().split(';').shift();
203  }
204  window.baseName = function(str) {
205      if (str === undefined) {
206          return ""
207      } else {
208          let base = new String(str).substring(str.lastIndexOf('/') + 1);
209          if(base.lastIndexOf(".") != -1)
210              base = base.substring(0, base.lastIndexOf("."));
211          return base;
212      }
213
214  }
215
216  /**
217   * String.prototype.replaceAll() polyfill
218   * https://gomakethings.com/how-to-replace-a-section-of-a-string-with-another-one-with-vanilla-js/
219   * @author Chris Ferdinandi
220   * @license MIT
221   */
222  if (!String.prototype.replaceAll) {
223    String.prototype.replaceAll = function(str, newStr){
224
225      // If a regex pattern
226      if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') {
227        return this.replace(str, newStr);
228      }
229
230      // If a string
231      return this.replace(new RegExp(str, 'g'), newStr);
232
233    };
234  }
235  // get passiveSupported about brower >
236  var passiveSupported = false;
237  try {
238    var options = Object.defineProperty({}, "passive", {
239      get: function() {
240        passiveSupported = true;
241      }
242    });
243    window.addEventListener("test", null, options);
244  } catch(err) {}
245  window.passiveVariable = passiveSupported ? { passive: true } : {passive: false};
246  window.passiveEvent = ['touchmove', 'touchstart'];
247  // get passiveSupported about brower <
248  window.loadingIcon =  $('<svg focusable="false" stroke="currentColor" width="1em" height="1em" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg" class="q-spinner"><g transform="translate(1 1)" stroke-width="2" fill="none" fill-rule="evenodd"><circle stroke-opacity=".5" cx="18" cy="18" r="18"></circle><path d="M36 18c0-9.94-8.06-18-18-18"><animateTransform attributeName="transform" type="rotate" from="0 18 18" to="360 18 18" dur="1s" repeatCount="indefinite"></animateTransform></path></g></svg>');
249})()

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.