PageSourceSearch

https://www.stuttgart-tourist.de/vendor/infomax/imxlibrary.imxautocomplete/src/js/Autocomplete.util.js

js stuttgart-tourist.de collected 2026-10-02 04:26:41 UTC 4,437 bytes, 166 lines download raw bytes

1/**
2 *
3 * @type {{triggerEvent, insertAfter, isVisible, extend, serialize, createElementByTemplate}}
4 */
5window.Autocomplete_util = (function(window, document, Array, Object, encodeURIComponent) {
6
7  /**
8   *
9   * @param {HtmlElement} element
10   * @param {string} eventname
11   * @param {object} data
12   */
13  var triggerEvent = function(element, eventname, data) {
14    var event = null;
15    if(typeof window.CustomEvent === "function") {
16      event = new CustomEvent(eventname, {
17        detail: data
18      });
19    }else {
20      event = document.createEvent('CustomEvent');
21      event.initCustomEvent(eventname, false, false, {
22        detail: data
23      });
24    }
25    element.dispatchEvent(event);
26  };
27
28  /**
29   * @param element
30   * @param parent
31   **/
32  var append = function(element, parent) {
33    parent.appendChild(element);
34  };
35
36  /**
37   *
38   * @param {HtmlElement} element
39   * @return {boolean}
40   *
41   * @see https://github.com/madrobby/zepto/blob/a08af67f24d2e0c93f6cfc5bb813b5a85cedbd53/src/selector.js#L8
42   */
43  var isVisible = function(element) {
44    return (element.offsetWidth > 0 || element.offsetHeigth > 0) && element.style.display !== 'none';
45  };
46
47  /**
48   * Converts a simple object into a query string
49   *
50   * @param {Object} object
51   * @returns {string}
52   *
53   * @see https://stackoverflow.com/a/1714899
54   */
55  var serialize = function(object) {
56    var str = [];
57    for(var p in object) {
58      if(object.hasOwnProperty(p)) {
59        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(object[p]));
60      }
61    }
62    return str.join("&");
63  };
64
65  /**
66   * Checḱs if the given object is a array
67   *
68   * @param object
69   * @returns {boolean}
70   * @private
71   *
72   * @see https://github.com/madrobby/zepto/blob/a08af67f24d2e0c93f6cfc5bb813b5a85cedbd53/src/zepto.js#L49
73   */
74  var _isArray = function(object) {
75    return object instanceof Array;
76  };
77
78  /**
79   *
80   * @param object
81   * @returns {boolean}
82   * @private
83   *
84   * @see https://github.com/madrobby/zepto/blob/a08af67f24d2e0c93f6cfc5bb813b5a85cedbd53/src/zepto.js#L74
85   */
86  var _isPlainObject = function(object) {
87    return object !== null &&
88        typeof object === 'object' &&
89        object !== object.window &&
90        Object.getPrototypeOf(object) === Object.prototype;
91  };
92
93  /**
94   *
95   * @param target
96   * @param source
97   * @param deep
98   * @private
99   *
100   * @see https://github.com/madrobby/zepto/blob/a08af67f24d2e0c93f6cfc5bb813b5a85cedbd53/src/zepto.js#L235
101   */
102  var _extendObject = function(target, source, deep) {
103    for(var key in source)
104      if(deep && (_isPlainObject(source[key]) || _isArray(source[key]))) {
105        if(_isPlainObject(source[key]) && !_isPlainObject(target[key])) {
106          target[key] = {};
107        }
108        if(_isArray(source[key]) && !_isArray(target[key])) {
109          target[key] = [];
110        }
111        _extendObject(target[key], source[key], deep);
112      }
113      else if(source[key] !== undefined) {
114        target[key] = source[key];
115      }
116  };
117
118  /**
119   * extend an array or an object with following objects and arrays
120   *
121   * @param target if target is a boolean, it is used as setting for a deep extend. Then the second parameter is the
122   * target. All following arguments will be merged into the target.
123   * @returns {Object}
124   *
125   * @see https://github.com/madrobby/zepto/blob/a08af67f24d2e0c93f6cfc5bb813b5a85cedbd53/src/zepto.js#L249
126   */
127  var extend = function(target) {
128    var deep, args = Array.prototype.slice.call(arguments, 1);
129    if(typeof target === 'boolean') {
130      deep = target;
131      target = args.shift();
132    }
133    args.forEach(function(arg) {
134      _extendObject(target, arg, deep);
135    });
136    return target;
137  };
138
139  /**
140   * Creates a html node by a given string template
141   *
142   * @param {String} html
143   * @returns {Node}
144   *
145   * @see https://stackoverflow.com/a/35385518 (but made compatible with IE 11)
146   */
147  var createElementByTemplate = function(html) {
148    var htmlWrapper = document.createElement('template');
149    htmlWrapper.innerHTML = html;
150
151    if(htmlWrapper.content) {
152      return htmlWrapper.content.firstChild;
153    }
154    return htmlWrapper.firstChild;
155  };
156
157  return {
158    triggerEvent: triggerEvent,
159    append: append,
160    isVisible: isVisible,
161    extend: extend,
162    serialize: serialize,
163    createElementByTemplate: createElementByTemplate
164  };
165
166})(window, document, Array, Object, encodeURIComponent);

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.