UNPKG

unibox

Version:

A powerful search suggestion input box.

1,332 lines (1,218 loc) 158 kB
/******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = "/"; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 33); /******/ }) /************************************************************************/ /******/ ({ /***/ 0: /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var _SxQueryObject = __webpack_require__(2); var _SxQueryObject2 = _interopRequireDefault(_SxQueryObject); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var sxQuery = function sxQuery(data) { var isWindow = false; try { isWindow = data instanceof Window || data === window; } catch (e) { isWindow = window.constructor ? data instanceof window.constructor : data === window; } if (typeof data === "string") { var parsedHTML = sxQuery.parseHTML(data); if (parsedHTML.length === 0) { return new _SxQueryObject2.default(sxQuery.querySelectorAll(data)); } else { return new _SxQueryObject2.default(parsedHTML); } } else if (data instanceof Node || data === document || data !== undefined && data.appendChild && data.cloneNode) { return new _SxQueryObject2.default([data]); } else if (data instanceof Array || data instanceof HTMLCollection || data instanceof NodeList) { if (data instanceof Array && data.reduce(function (acc, node) { return acc && typeof node === "string"; }, true)) { // array of html strings return new _SxQueryObject2.default(data.map(function (item) { return sxQuery.parseHTML(item); })); } else { return new _SxQueryObject2.default(data); } } else if (isWindow) { return new _SxQueryObject2.default([data]); } else if (data instanceof _SxQueryObject2.default) { return new _SxQueryObject2.default(data.get()); } else { return new _SxQueryObject2.default([]); // } }; // private methods and properties sxQuery._animations = {}; sxQuery._callbacksByName = {}; sxQuery._animationNodeFlag = 0; sxQuery._notifyAnimation = function (node, type, id) { if (!node.sxQueryAnimationFlag) { node.sxQueryAnimationFlag = sxQuery._animationNodeFlag; sxQuery._animationNodeFlag++; sxQuery._animations[node.sxQueryAnimationFlag] = {}; } sxQuery._animations[node.sxQueryAnimationFlag][type] = id; }; sxQuery._clearAnimation = function (node, type) { var flg = node.sxQueryAnimationFlag; if (flg !== undefined && sxQuery._animations[flg] !== undefined && type in sxQuery._animations[flg]) { sxQuery._stopAnimation(sxQuery._animations[flg][type]); } }; sxQuery._requestAnimation = function (tick) { return window.requestAnimationFrame && requestAnimationFrame(tick) || setTimeout(tick, 16); }; sxQuery._stopAnimation = function (id) { if (!window.cancelAnimationFrame || !window.cancelAnimationFrame(id)) { clearTimeout(id); } }; //dom independent public methods sxQuery.inArray = function (item, array) { return array.indexOf(item); }; /** * Loops through array or object keys and calls the callback - with index and value in case of array, with key and value in case of object. * * @param data - object or array * @param callback - callback to call * @returns {*} - data */ sxQuery.each = function (data, callback) { if (data instanceof Array) { //array data.forEach(function (item, i) { if (callback && typeof callback == "function") { callback(i, item); } }); } else { //object var idx = 0; for (var i in data) { if (data.hasOwnProperty && data.hasOwnProperty(i)) { if (callback && typeof callback == "function") { callback(i, data[i], idx); } idx++; } } } return data; }; sxQuery.indexInNodeList = function (el, arr) { for (var i = 0; i < arr.length; i++) { if (arr[i] == el) { return i; } } return -1; }; // creating and reading cookies sxQuery.createCookie = function (name, value, days) { var expires; if (days) { var date = new Date(); date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); expires = "; expires=" + date.toGMTString(); } else { expires = ""; } document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/"; }; sxQuery.readCookie = function (name) { var nameEQ = encodeURIComponent(name) + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) === ' ') { c = c.substring(1, c.length); } if (c.indexOf(nameEQ) === 0) { return decodeURIComponent(c.substring(nameEQ.length, c.length)); } } return null; }; sxQuery.linkOpensInNewTab = function (event) { return event.ctrlKey || //CTRL event.which == 2 || event.button == 4 || //middle mouse click event.target && event.target.target && event.target.target == "_blank"; // target="_blank" }; /** * @param type - one of ['max','min'] */ sxQuery.matchesMediaQuery = function (type, breakpoint) { if (window.matchMedia) { var mQuery = type == "max" ? "(max-width: " + breakpoint + "px)" : "(min-width: " + breakpoint + "px)"; return window.matchMedia(mQuery).matches; } if (type == "max") { return window.innerWidth <= parseInt(breakpoint); } return window.innerWidth >= parseInt(breakpoint); }; sxQuery.parseHTML = function (str) { var tmp = document.implementation.createHTMLDocument(""); tmp.body.innerHTML = str; var res = []; for (var i = 0; i < tmp.body.children.length; i++) { res.push(document.importNode(tmp.body.children[i], true)); } return res; }; /** * Deep extend * @param out the output object * @param [,object1][,objectN] */ sxQuery.extend = function (out) { var output = out || {}; for (var i = 1; i < arguments.length; i++) { if (arguments[i]) { for (var key in arguments[i]) { if (arguments[i].hasOwnProperty(key) && arguments[i][key] !== undefined) { if (sxQuery.isObject(output[key]) && sxQuery.isObject(arguments[i][key])) { output[key] = sxQuery.extend(output[key], arguments[i][key]); } else { output[key] = arguments[i][key]; } } } } } return output; }; sxQuery.isObject = function (el) { return el !== undefined && (typeof el === "undefined" ? "undefined" : _typeof(el)) == "object" && !(el instanceof Array); }; sxQuery.ajax = function (dataObject) { dataObject = dataObject || {}; var method = dataObject.method || 'GET'; var dataType = dataObject.dataType; var url = dataObject.url; var success = dataObject.success || function () {}; var error = dataObject.error || function () {}; var forceXDR = 'XDomainRequest' in window; var request = forceXDR ? new XDomainRequest() : new XMLHttpRequest(); request.open(method, forceXDR ? url.replace("https://", "//") : url, true); request.onload = function () { if (forceXDR || request.status >= 200 && request.status < 400) { var response = request.responseText; if (!dataType || dataType === "json") { try { success(JSON.parse(response)); } catch (e) { console.warn(e); success(response); } } } else { //mmmmm... } }; request.onerror = function () { error(request.status, request.statusText); }; var send = function (request) { try { if (method !== "POST") { request.send(); } else { var data = ""; sxQuery.each(dataObject.data, function (key, value) { data += key + "=" + value + "&"; }); if (data.length > 0) { data = data.substring(0, data.length - 1); } request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); request.send(data); } } catch (e) { error(request.status, request.statusText, e); } }.bind(this, request); if (forceXDR) { setTimeout(send, 0); } else { send(); } }; sxQuery.get = function (url, success, error, dataType) { sxQuery.ajax({ url: url, success: success, error: error, dataType: dataType }); }; sxQuery.post = function (url, data, success, dataType) { sxQuery.ajax({ url: url, success: success, dataType: dataType, method: 'POST', data: data }); }; //no invert support sxQuery.grep = function (array, filter) { var result = []; for (var i = 0; i < array.length; i++) { if (filter(array[i])) { result.push(array[i]); } } return result; }; sxQuery.querySelectorAll = function (data, node) { node = node || document; var matches = []; //get just first element for id-only query - same behavior as jQuery if (data.indexOf("#") === 0 && data.indexOf(" ") == -1 && data.indexOf(".") == -1 && data.indexOf(":") == -1 && data.indexOf(">") !== -1) { var found = node.getElementById ? node.getElementById(data.replace("#", "")) : node.querySelector(data); if (found) { matches.push(found); } return matches; } if (data.indexOf(":first") !== -1 || data.indexOf(":visible") !== -1) { //handle jQuery-like :first and :visible var partialQueries = data.split(" "); for (var i = 0; i < partialQueries.length; i++) { var query = partialQueries[i]; var justFirst = false; var justVisible = false; if (query.indexOf(":first") !== -1) { justFirst = true; query = query.replace(":first", ""); } else if (query.indexOf(":visible") !== -1) { justVisible = true; query = query.replace(":visible", ""); } matches = matches.length === 0 ? sxQuery(node).find(query) : matches.find(query); if (justFirst && matches.length > 0) { matches = sxQuery(matches[0]); } else if (justVisible && matches.length > 0) { matches = matches.filter(function (m) { return sxQuery(m).isVisible(); }); } } matches = matches.get(); } else if (data) { matches = node.querySelectorAll(data); } return matches; }; sxQuery.prefersReducedMotion = function () { return window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches; }; sxQuery.srOnlyCss = "position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0"; var handler = { set: function set(obj, prop, value) { _SxQueryObject2.default.prototype[prop] = value; return true; } }; try { sxQuery.fn = new Proxy({}, handler); } catch (e) { //proxy not supported --> IE sxQuery.fn = _SxQueryObject2.default.prototype; } exports.default = sxQuery; /***/ }), /***/ 2: /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _sxQuery = __webpack_require__(0); var _sxQuery2 = _interopRequireDefault(_sxQuery); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var SxQueryObject = function SxQueryObject(elems) { var _self = this; var makePureArray = function makePureArray() { var pureArray = []; for (var g = 0; g < elems.length; g++) { pureArray.push(elems[g]); } return pureArray; }; var _elems = makePureArray(); var CSS_TO_PIXEL = { width: true, height: true, minWidth: true, minHeight: true, maxWidth: true, padding: true, paddingLeft: true, paddingRight: true, paddingTop: true, paddingBottom: true, left: true, right: true, top: true, bottom: true, borderWidth: true }; this._it = function (callback) { for (var i = 0; i < _elems.length; i++) { var elem = _elems[i]; if (elem && callback) { callback(elem, i == _elems.length - 1); } } }; this._canMatch = function (elem) { return elem.matches || elem.matchesSelector || elem.msMatchesSelector; }; this._match = function (elem, querySelector) { return elem.matches ? elem.matches(querySelector) : elem.matchesSelector ? elem.matchesSelector(querySelector) : elem.msMatchesSelector(querySelector); }; /* Append or prepend an element*/ this._addNode = function (content, append) { var result = []; if (typeof content === "string") { //parseHtml and append result = result.concat(this._addNode(_sxQuery2.default.parseHTML(content), append)); return result; } else if (content instanceof Array || content instanceof HTMLCollection || content instanceof NodeList) { //append each element for (var i = append ? 0 : content.length - 1; append ? i < content.length : i >= 0; append ? i++ : i--) { result = result.concat(this._addNode(content[i], append)); } return result; } else if (content instanceof SxQueryObject) { //get elements and append those result = result.concat(this._addNode(content.get(), append)); content.clear(); content.push(result); return result; } else if (content instanceof Node || content !== undefined && content.appendChild && content.cloneNode) { //finally really append this._it(function (elem, isLast) { var node = !isLast ? content.cloneNode(true) : content; result.push(node); try { if (append || !elem.firstChild) { elem.appendChild(node); } else { elem.insertBefore(node, elem.firstChild); } } catch (ex) { console.log(ex); } }); return result; } }; this._init = function () { for (var i = 0; i < _elems.length; i++) { this[i] = _elems[i]; } }; this._init(); //api this.length = _elems.length; this.push = function (arr) { _elems = _elems || []; _elems = _elems.concat(arr); this.length = _elems.length; }; this.clear = function () { _elems = []; this.length = 0; }; this.get = function (idx) { if (idx !== undefined) { return _elems[idx]; } return _elems; }; this.remove = function () { this._it(function (elem) { if (elem.parentNode) { elem.parentNode.removeChild(elem); } }); }; this.each = function (callback) { var idx = 0; this._it(function (elem) { callback.call(elem, elem, idx); idx++; }); }; this._trigger = function (eventName) { //FIXME: not sure that this would work... - currently used only as fallback, that's why private var e = undefined; if (window.CustomEvent) { try { e = new CustomEvent(eventName); } catch (ex) {} } if (e === undefined) { e = document.createEvent('CustomEvent'); e.initCustomEvent(eventName, true, true, {}); } this._it(function (elem) { elem.dispatchEvent(e); }); }; this.on = function (event, selector, callback) { if (callback === undefined) { this.on(event, undefined, selector); //selector is actually callback } else { if (!selector) { this._it(function (elem) { var events = event.split(","); for (var i = 0; i < events.length; i++) { var eventName = events[i]; if (eventName.indexOf(".") !== -1) { var nameToKey = eventName.split("."); if (nameToKey.length == 2) { eventName = eventName.trim(); //save callback if (!_sxQuery2.default._callbacksByName[eventName]) { _sxQuery2.default._callbacksByName[eventName] = []; } _sxQuery2.default._callbacksByName[eventName].push(callback); eventName = nameToKey[0]; } } elem.addEventListener(eventName.trim(), callback); } }); } else { var matches = this._match; var canMatch = this._canMatch; var handler = function (canMatch, matches, selector, callback, e) { if (!e || !e.target) { return; } if (canMatch(e.target) && matches(e.target, selector)) { //elem triggered the event callback.bind(e.target, e).call(); } else { //check whether elem child triggered the event var node = e.target; while (node.parentNode && canMatch(node.parentNode)) { node = node.parentNode; if (canMatch(node) && matches(node, selector)) { callback.bind(e.target, e).call(); break; } } } }.bind(this, canMatch, matches); this._it(function (elem) { var events = event.split(","); for (var i = 0; i < events.length; i++) { elem.addEventListener(events[i].trim(), handler.bind(this, selector, callback)); } }); } } return _self; }; this.off = function (event, listener) { var events = event.split(","); if (!events || events.length == 0) { return _self; } this._it(function (elem) { events.map(function (e) { if (e.indexOf(".") === -1) { elem.removeEventListener(e.trim(), listener); } else if (_sxQuery2.default._callbacksByName[e.trim()]) { var eventName = e.split(".")[0].trim(); _sxQuery2.default._callbacksByName[e.trim()].map(function (callback) { elem.removeEventListener(eventName, callback); }); } }); }); return _self; }; this.mouseenter = function (callback) { return this.on("mouseenter", callback); }; this.mousedown = function (callback) { return this.on("mousedown", callback); }; this.mouseup = function (callback) { return this.on("mouseup", callback); }; this.click = function (callback) { return this.on("click", callback); }; this.scroll = function (callback) { return this.on("scroll", callback); }; this.focus = function (callback) { if (callback === undefined) { this._it(function (elem) { if (elem.focus) { elem.focus(); } else { (0, _sxQuery2.default)(elem)._trigger("focus"); } }); } else { this.on("focus", callback); } return _self; }; this.blur = function (callback) { if (callback === undefined) { this._it(function (elem) { if (elem.blur) { elem.blur(); } else { (0, _sxQuery2.default)(elem)._trigger("blur"); } }); } else { this.on("blur", callback); } return _self; }; this.keydown = function (callback) { return this.on("keydown", callback); }; this.keyup = function (callback) { return this.on("keyup", callback); }; this.focusout = function (callback) { return this.on("focusout", callback); }; this.find = function (querySelector) { var result = []; this._it(function (elem) { var found = _sxQuery2.default.querySelectorAll(querySelector, elem); for (var i = 0; i < found.length; i++) { result.push(found[i]); } }); return (0, _sxQuery2.default)(result); }; this.children = function () { var result = []; this._it(function (elem) { for (var i = 0; i < elem.childElementCount; i++) { result.push(elem.children[i]); } }); return (0, _sxQuery2.default)(result); }; this.is = function (node) { for (var i = 0; i < _elems.length; i++) { var el = _elems[i]; if (el === node) { return true; } } return false; }; this.text = function (text) { if (text == undefined) { var result = ""; this._it(function (elem) { result += elem.textContent || ""; }); return result; } else { this._it(function (elem) { elem.innerText = text; }); return _self; } }; this.position = function () { if (_elems.length > 0) { var elem = _elems[0]; var $elem = (0, _sxQuery2.default)(elem); var offset; if ($elem.css("position") == "fixed") { offset = elem.getBoundingClientRect(); } else { var offsetParent = elem.offsetParent; var $offsetParent = (0, _sxQuery2.default)(offsetParent); var parentOffset = { top: 0, left: 0 }; offset = $elem.offset(); if (offsetParent.nodeName != "html") { parentOffset = $offsetParent.offset(); } parentOffset.top += parseFloat($offsetParent.css("borderTopWidth")); parentOffset.left += parseFloat($offsetParent.css("borderLeftWidth")); offset.top = offset.top - parentOffset.top - parseFloat($elem.css("marginTop")); offset.left = offset.left - parentOffset.left - parseFloat($elem.css("marginLeft")); } return offset; } }; this.attr = function (key, value) { if (value === undefined) { if (_elems.length > 0) { return _elems[0].getAttribute(key); } } else { this._it(function (elem) { if (value !== null) { elem.setAttribute(key, value); } else { elem.removeAttribute(key); } }); } }; this.removeAttribute = function (key) { if (key) { this._it(function (el) { if (el.removeAttribute) { el.removeAttribute(key); } }); } }; this.hide = function () { this._it(function (elem) { elem.style.display = "none"; }); }; this.show = function () { this._it(function (elem) { elem.style.display = ''; }); }; this.data = function (key, value) { if (value === undefined) { if (_elems.length > 0) { return _elems[0].dataset[key]; } return undefined; } else { this._it(function (el) { if (value === null) { delete el.dataset[key]; } else { el.dataset[key] = value; } }); return this; } }; this.addClass = function (className) { var classElems = className.split(" "); this._it(function (elem) { for (var i = 0; i < classElems.length; i++) { if (elem.classList) { elem.classList.add(classElems[i]); } else { elem.className += " " + classElems[i]; } } }); return this; }; this.removeClass = function (className) { var classElems = className.split(" "); this._it(function (elem) { for (var i = 0; i < classElems.length; i++) { if (elem.classList) { elem.classList.remove(classElems[i]); } else { elem.className = elem.className.replace(new RegExp('(^|\\b)' + classElems[i].split(' ').join('|') + '(\\b|$)', 'gi'), ' '); } } }); return this; }; this.toggleClass = function (className) { if (this.hasClass(className)) { this.removeClass(className); } else { this.addClass(className); } }; this.hasClass = function (className) { for (var i = 0; i < _elems.length; i++) { //not using _it to be able to break the loop var elem = elems[i]; if (!elem) { continue; } if (elem.classList) { if (elem.classList.contains(className)) { return true; } } else { if (new RegExp('(^| )' + className + '( |$)', 'gi').test(elem.className)) { return true; } } } return false; }; /* Returns new SxQueryObject containing filtered elements */ this.filter = function (validator) { return (0, _sxQuery2.default)(this.get().filter(validator)); }; this.val = function (value) { if (value !== undefined) { this._it(function (elem) { elem.value = value; }); return this; } else if (_elems.length > 0) { return _elems[0].value; } }; this.css = function (key, value) { key = key.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); }); if (value !== undefined) { if (value !== null) { var valueString = value.toString(); if (CSS_TO_PIXEL[key] && valueString !== "auto" && valueString.indexOf("px") === -1 && valueString.indexOf("%") === -1 && valueString.indexOf("calc") === -1 && value !== 0 && value !== '') { value = value.toString(); value += "px"; } } this._it(function (elem) { elem.style[key] = value; }); } else if (_elems.length > 0) { for (var i = 0; i < _elems.length; i++) { try { return window.getComputedStyle(_elems[i])[key]; } catch (e) {} } return null; } }; this.append = function (content) { this._addNode(content, true); return this; }; this.prepend = function (content) { this._addNode(content, false); return this; }; this.parent = function () { var result = []; this._it(function (elem) { result.push(elem.parentNode); }); return (0, _sxQuery2.default)(result); }; this.parents = function (querySelector) { var result = []; var scope = this; this._it(function (elem) { var parent = elem.parentNode; while (parent && scope._canMatch(parent)) { if (querySelector === undefined || scope._match(parent, querySelector)) { result.push(parent); } parent = parent.parentNode; } }); return result; }; this.prev = function () { var result = []; this._it(function (elem) { result.push(elem.previousElementSibling); }); return (0, _sxQuery2.default)(result); }; this.next = function () { var result = []; this._it(function (elem) { result.push(elem.nextElementSibling); }); return (0, _sxQuery2.default)(result); }; this.closest = function (querySelector) { var result = []; var scope = this; this._it(function (elem) { var tested = elem; while (tested && scope._canMatch(tested) && !scope._match(tested, querySelector)) { tested = tested.parentNode; } if (!scope._canMatch(tested)) { tested = undefined; } result.push(tested); }); return (0, _sxQuery2.default)(result); }; this.index = function (htmlNode) { for (var i = 0; i < _elems.length; i++) { if (_elems[i] === htmlNode) { return i; } } return -1; }; this.offset = function () { if (_elems.length > 0) { var elem = _elems[0]; if (!elem.getClientRects().length) { return { top: 0, left: 0 }; } var rect = elem.getBoundingClientRect(); var win = elem.ownerDocument.defaultView; return { top: rect.top + win.pageYOffset, left: rect.left + win.pageXOffset }; } }; this.outerWidth = function () { if (_elems.length > 0) { return _elems[0].offsetWidth; } }; this.height = function (val) { if (val !== null && val !== undefined) { if (val.toString().indexOf("px") == -1 && val.toString().indexOf("%") == -1 && val !== "auto") { val = val.toString() + "px"; } this.css("height", val); } else { return parseFloat(this.css("height")); } }; this.outerHeight = function () { if (_elems.length > 0) { return _elems[0].offsetHeight; } }; this.html = function (data) { if (data !== undefined) { this.empty(); this.append(data); } else if (_elems.length > 0) { return _elems[0].innerHTML; } }; this.empty = function () { this._it(function (elem) { while (elem.firstChild) { elem.removeChild(elem.firstChild); } }); }; this.scrollTop = function (val) { if (val !== undefined) { this._it(function (elem) { if (elem.scrollTop !== undefined) { elem.scrollTop = val; } else if (elem.scrollY !== undefined && elem.scrollTo !== undefined) { elem.scrollTo(elem.scrollX, val); } }); } else if (_elems.length > 0) { return _elems[0].scrollTop !== undefined ? _elems[0].scrollTop : _elems[0].scrollY; } }; this.ready = function (fn) { this._it(function (elem) { if (elem.attachEvent ? elem.readyState === "complete" : elem.readyState !== "loading") { fn(); } else { elem.addEventListener('DOMContentLoaded', fn); } }); }; /** * ~ jQuery(elem).is(":visible"); */ this.isVisible = function () { if (_elems.length > 0) { return (0, _sxQuery2.default)(_elems[0]).css("display") !== "none"; } }; this.map = function (callback) { var result = []; var i = 0; this._it(function (elem) { result.push(callback(i, elem)); i++; }); return result; }; this._animate = function (el, animationType, duration, cosParameter, setter, callback) { var count = 0; var last = +new Date(); var tick = function tick() { var current = new Date(); count += Math.PI / (duration / (current - last)); var val = cosParameter + cosParameter * Math.cos(count); setter(el, val); last = +new Date(); if (count >= Math.PI) { if (callback !== undefined && typeof callback == "function") { callback(el); } } else { _sxQuery2.default._notifyAnimation(el, animationType, _sxQuery2.default._requestAnimation(tick)); } }; _sxQuery2.default._notifyAnimation(el, animationType, _sxQuery2.default._requestAnimation(tick)); }; //animations this._fade = function (out, duration, callback) { var factor = out ? -1 : 1; var setter = function setter(el, val) { if (el == undefined || val == undefined) { return; } el.style.opacity = factor > 0 ? 1 - val : val; }; var completeCallback = function completeCallback(el) { var $el = (0, _sxQuery2.default)(el); $el.css("opacity", ""); if (out) { $el.hide(); } if (callback && typeof callback == "function") { callback.bind($el).call(); } }; var scope = this; this._it(function (el) { _sxQuery2.default._clearAnimation(el, "fade"); if (duration != 0 && !_sxQuery2.default.prefersReducedMotion()) { scope._animate(el, "fade", duration || 400, 0.5, setter, completeCallback); } else { completeCallback(el); } }); }; this.fadeIn = function (duration, callback, displayType) { if (displayType === undefined || displayType != "flex") { this.css("display", "block"); } else { this._it(function (el) { var $el = (0, _sxQuery2.default)(el); var style = $el.attr("style"); if (style.length > 0 && style[style.length - 1] != ";") { style += ";"; } style += "display: -ms-flexbox;display: -webkit-flex;display: flex;"; $el.attr("style", style); }); } this._it(function (el) { el.style.opacity = 0; }); this._fade(false, duration, callback); }; this.fadeOut = function (duration, callback) { this._it(function (el) { el.style.opacity = 1; }); this._fade(true, duration, callback); }; this._slide = function (up, duration, callback) { var scope = this; var completeCallback = function completeCallback(el) { var $el = (0, _sxQuery2.default)(el); $el.css("height", ""); if (up) { $el.hide(); } if (callback && typeof callback == "function") { callback.bind($el).call(); } }; //.bind(this, up, callback); var setter = function setter(up, height, el, val) { if (el == undefined || val == undefined) { return; } var nHeight = up ? val : height - val; el.style.height = nHeight + "px"; }; this._it(function (el) { _sxQuery2.default._clearAnimation(el, 'slide'); if (duration != 0 && !_sxQuery2.default.prefersReducedMotion()) { var $el = (0, _sxQuery2.default)(el); var height = $el.outerHeight(); $el.css("height", 0); var cosParam = height / 2; scope._animate(el, 'slide', duration || 400, cosParam, function (el, val) { setter(up, height, el, val); }, completeCallback); } else { completeCallback(el); } }); }; this.slideDown = function (duration, callback) { this.css("display", "block"); this._slide(false, duration, callback); }; this.slideUp = function (duration, callback) { this._it(function (el) { var $el = (0, _sxQuery2.default)(el); $el.css("height", $el.outerHeight()); }); this._slide(true, duration, callback); }; this.animateScrollTop = function (target, duration) { var scope = this; duration = duration || 400; var setter = function setter(startVal, target, el, newVal) { if (target >= startVal) { el.scrollTop = startVal + (Math.abs(startVal - target) - newVal); } else { el.scrollTop = target + newVal; } }; this._it(function (el) { var startVal = el.scrollTop; var range = Math.abs(startVal - target); _sxQuery2.default._clearAnimation(el, 'scrollTop'); if (range < 1 || duration == 0 || _sxQuery2.default.prefersReducedMotion()) { el.scrollTop = target; return; } var cosParameter = range / 2; scope._animate(el, 'scrollTop', duration || 400, cosParameter, setter.bind(this, startVal, target)); }); }; this.animateTop = function (target, duration) { var scope = this; var completeCallback = function (target, el) { (0, _sxQuery2.default)(el).css("top", target); }.bind(this, target); var setter = function setter(startVal, trgt, el, nVal) { var val; if (trgt >= startVal) { //FIXME: will work only for our use-case - 0 to negative and negative to 0 val = nVal; if (startVal < 0) { val *= -1; } } else { if (trgt < 0) { val = trgt + nVal; } else { val = nVal + startVal; } } (0, _sxQuery2.default)(el).css("top", val + "px"); }; this._it(function (el) { _sxQuery2.default._clearAnimation(el, 'positionTop'); if (duration == 0 || _sxQuery2.default.prefersReducedMotion()) { completeCallback(el); return; } var $el = (0, _sxQuery2.default)(el); var crnt = parseFloat($el.css("top"))