/** * Author: Marek Zeman * Twitter: MarekZeman91 * Site: http://marekzeman.cz * License: MIT * Version: 0.2 */ var is = { 'function': function (fn) { return typeof fn === 'function' }, 'regExp': function (regExp) { return is.object(regExp) && /RegExp/.test('' + regExp.constructor) }, 'string': function (str) { return typeof str === 'string' }, 'number': function (num) { return typeof num === 'number' }, 'object': function (obj) { return !!obj && typeof obj === 'object' }, 'boolean': function (bool) { return !!('' + bool).match(/true|false/i) }, 'array': function(array) { return !!(array && typeof array === 'object' && array.pop) }, 'iterable': function(array) { return is.array(array) || (is.object(array) && array.length !== undefined) }, 'validElement': function(element) { return element && (element.nodeType === 1 || element.nodeType === 9) }, 'matchingSelector': function(element, selector) { return ( element.matches || element.matchesSelector || element.oMatchesSelector || element.msMatchesSelector || element.mozMatchesSelector || element.webkitMatchesSelector || function(selector, elements, i) { elements = document.querySelectorAll('' + selector); for (i = 0; elements[i]; i++) { if (elements[i] === this) return true; } return false; } ).call(element, '' + selector); } }; /** * Author: Marek Zeman * Twitter: MarekZeman91 * Site: http://marekzeman.cz * License: MIT * Version: 1 */ var classes = (function() { function isntElement(element) { return !(!!element && typeof element === 'object') } var modern = { add: function(element, className) { if (isntElement(element)) return; if (!modern.has(element, className)) { element.classList.add(className); } }, remove: function(element, className) { if (isntElement(element)) return; if (modern.has(element, className)) { element.classList.remove(className); } }, toggle: function(element, className) { if (isntElement(element)) return; element.classList.toggle(className); }, has: function(element, className) { if (isntElement(element)) return false; return element.classList.contains(className); }, hasnt: function(element, className) { return !modern.has(element, className); }, getList: function(element) { if (isntElement(element)) return []; return element.classList; } }; var oldSchool = { add: function(element, className) { if (isntElement(element)) return; if (!oldSchool.has(element, className)) { element.className = oldSchool.getList(element).concat(className).join(' '); } }, remove: function(element, className) { if (isntElement(element)) return; if (oldSchool.has(element, className)) { var list = oldSchool.getList(element), index = list.indexOf(className); list.splice(index, 1); element.className = list.join(' '); } }, toggle: function(element, className) { if (isntElement(element)) return; if (oldSchool.has(element)) { oldSchool.remove(element, className); } else { oldSchool.add(element, className); } }, has: function(element, className) { if (isntElement(element)) return false; return oldSchool.getList(element).indexOf(className) !== -1; }, hasnt: function(element, className) { return !oldSchool.has(element, className); }, getList: function(element) { if (isntElement(element)) return []; return element.className.match(/[^\s\b\t\n\r\f]+/g) || []; } }; return document.documentElement.classList ? modern : oldSchool; })(); /** * Author: Marek Zeman for clickone.cz * Twitter: MarekZeman91 * Site: http://marekzeman.cz * Version: 1.31 * Revision: 4.6.2015 // added [disabled] ability */ (function() { var temp, selectListeners = { clickDocument: function(event, parent, roots, curSelect, select, items, search) { roots = document.querySelectorAll('[fancy="select"]'); if (!roots.length) return; curSelect = getClosest(event.target, '[fancy="select"]'); for (var i = 0; roots[i]; i++) { select = roots[i].querySelector('select'); search = roots[i].querySelector('.select-search'); if (curSelect && roots[i] === curSelect) { if (classes.has(curSelect, 'open')) { event = document.createEvent('Event'); event.initEvent('change', true, true); curSelect.dispatchEvent(event); if (search) search.blur(); } classes.toggle(curSelect, 'open'); continue; } if (search) search.blur(); classes.remove(roots[i], 'open'); } }, clickList: function(event, root, select, current, search, item) { root = getClosest(this, '[fancy="select"]') || this.parentNode; select = root.querySelector('select'); current = root.querySelector('.select-current'); search = root.querySelector('.select-search'); item = getClosest(event.target, '[data-value]'); select.value = (item.dataset || {}).value || item.getAttribute('data-value'); if (search) search.value = event.target.innerHTML; else current.innerHTML = event.target.innerHTML; event = document.createEvent('Event'); event.initEvent('change', true, true); select.dispatchEvent(event); }, changeSelect: function(event, root, current, search, list, items, title) { root = getClosest(this, '[fancy="select"]') || this.parentNode; current = root.querySelector('.select-current'); search = root.querySelector('.select-search'); list = root.querySelector('.select-list'); items = list.children || []; list.style.display = 'none'; for (var i = 0; items[i]; i++) { if ((items[i].dataset || {}).value === this.value) { title = items[i].innerHTML; } items[i].style.display = ''; } list.style.display = ''; if (search) { search.value = title; } else { current.innerHTML = title; } }, changeSearch: function(root, list, items) { root = getClosest(this, '[fancy="select"]') || this.parentNode; list = root.querySelector('.select-list'); items = list.children || []; classes.add(root, 'open'); list.style.display = 'none'; for (var i = 0; items[i]; i++) { items[i].style.display = ( (items[i].innerHTML || '').toLowerCase().indexOf( (this.value || '').toLowerCase() ) === -1 ) ? 'none' : ''; } list.style.display = ''; } }; function matches(element, selector) { return ( element.matches || element.matchesSelector || element.oMatchesSelector || element.msMatchesSelector || element.mozMatchesSelector || element.webkitMatchesSelector || function(selector, elements, i) { elements = document.querySelectorAll('' + selector); for (i = 0; elements[i]; i++) { if (elements[i] === this) return true; } return false; } ).call(element, selector); } function getClosest(element, selector) { do { if (matches(element, selector)) return element } while (element = element.parentNode); return null; } function createSelectElements(select, allowSearch, root, current, search, list) { root = select.parentNode; // FIND AND REMOVE if (current = root.querySelector('.select-current')) current.parentNode.removeChild(current); if (search = root.querySelector('.select-search')) search.parentNode.removeChild(search); if (list = root.querySelector('.select-list')) list.parentNode.removeChild(list); // CREATE current = document.createElement('label'); current.className = 'select-current'; list = document.createElement('span'); list.className = 'select-list'; if (allowSearch) { search = document.createElement('input'); search.className = 'select-search'; } // INIT var option; for (var i = 0; select[i]; i++) { option = list.appendChild(document.createElement('span')); if (option.dataset) { option.dataset.value = select[i].value; } else { option.setAttribute('data-value', select[i].value); } if (select.value === select[i].value) { if (search) { search.value = select[i].innerHTML; } else { current.innerHTML = select[i].innerHTML; } } option.innerHTML = select[i].innerHTML; } root.appendChild(current); root.appendChild(list); if (allowSearch) { current.appendChild(search); search.removeEventListener('keyup', selectListeners.changeSearch); search.addEventListener('keyup', selectListeners.changeSearch); } list.removeEventListener('click', selectListeners.clickList); list.addEventListener('click', selectListeners.clickList); select.removeEventListener('change', selectListeners.changeSelect); select.addEventListener('change', selectListeners.changeSelect); document.removeEventListener('click', selectListeners.clickDocument); document.addEventListener('click', selectListeners.clickDocument); } function changeClass(element) { var hasClass = classes.has(element.parentNode, 'active'); if (element.checked && !hasClass) { classes.add(element.parentNode, 'active'); } if (!element.checked && hasClass) { classes.remove(element.parentNode, 'active'); } return element; } function FancyInstance(elements, allowSearch) { this.allowSearch = allowSearch; this.elements = []; this.inputs = []; for (var i = 0; elements[i]; i++) { if (this.elements.indexOf(elements[i]) == -1) { this.elements.push(elements[i]); if (elements[i].type.match(/radio|checkbox/)) { this.inputs.push(elements[i]); } } } this.changeListener = { inputs: this.inputs, elements: this.elements, handleEvent: this.onChange }; this.init(); } FancyInstance.prototype.inputs = []; FancyInstance.prototype.elements = []; FancyInstance.prototype.allowSearch = false; FancyInstance.prototype.changeListener = {}; FancyInstance.prototype.onChange = function(event, input, i, l, isDisabled) { input = event.target; i = 0; isDisabled = input.disabled || ( input.parentNode.getAttribute('disabled') || '' ).match(/disabled|true/i); if (input && input.parentNode && isDisabled) { event.preventDefault(); return false; } if (event == null) { l = this.inputs.length; } else { l = [this.inputs.length, 1][+(input.type == 'checkbox')]; } while (i < l) { if (l > 1) input = this.inputs[i]; if (!input.parentNode) { i++; continue; } changeClass(input); i++; } }; FancyInstance.prototype.init = function() { for (var i = 0; this.elements[i]; i++) { if (this.elements[i].type === 'select-one') { createSelectElements(this.elements[i], this.allowSearch); continue; } this.elements[i].removeEventListener('change', this.changeListener); this.elements[i].addEventListener('change', this.changeListener); changeClass(this.elements[i]); } }; FancyInstance.prototype.trigger = function() { for (var i = 0, event; this.elements[i]; i++) { event = document.createEvent('Event'); event.initEvent('change', true, true); this.elements[i].dispatchEvent(event); } }; window.FancyInputs = function(selector, allowSearch) { if (!selector) return { reload: function() { instance.init() }, trigger: function() { instance.trigger() } }; if (selector && typeof selector == 'object' && (selector.nodeType === 1 || selector.nodeType === 9)) { temp = [selector]; } else { try { temp = document.querySelectorAll('' + selector) } catch (error) { temp = [] } } var instance = new FancyInstance(temp, !!allowSearch); temp = null; return { reload: function() { instance.init() }, trigger: function() { instance.trigger() } } }; })(); /** * Author: Marek Zeman for clickone.cz * Twitter: MarekZeman91 * Site: http://marekzeman.cz * Version: 1.0 * Revision: 5.6.2015 */ (function() { function Range(root, options) { this.$root = root; this.options = {}; this.public = {}; this.data = {}; this.fn.fixOptions.call(this, options || {}); this.fn.createElements.call(this); this.fn.attachEvents.call(this); this.public.min = this.options.min; this.public.max = this.options.max; this.public.step = this.data.step || 0; this.public.steps = this.options.steps; this.public.value = this.data.current; this.public.values = this.options.values; this.public.percentage = this.data.percentage; this.public.prefix = this.options.prefix; this.public.suffix = this.options.suffix; this.public.single = this.options.single; this.options.afterInit.call(this, this.$root, this.public); } // ELEMENTS Range.prototype.$root = null; Range.prototype.$sliders = null; Range.prototype.$primary = null; Range.prototype.$secondary = null; Range.prototype.$level = null; Range.prototype.$low = null; Range.prototype.$high = null; // EXTRA Range.prototype.isTouchscreen = !!('ontouchstart' in window); // DATA Range.prototype.public = {}; Range.prototype.data = {}; // OPTIONS Range.prototype.options = {}; Range.prototype.defaults = {}; Range.prototype.defaults.classPrefix = 'range'; Range.prototype.defaults.min = 0; Range.prototype.defaults.max = 100; Range.prototype.defaults.steps = 0; Range.prototype.defaults.prefix = ''; Range.prototype.defaults.suffix = ''; Range.prototype.defaults.single = false; Range.prototype.defaults.afterInit = function() {}; Range.prototype.defaults.onDrag = function() {}; Range.prototype.defaults.onChange = function() {}; // LISTENERS Range.prototype.listeners = { instance: null, mousedown: function(event, instance, data, fn) { if (Math.max(+event.which, +event.button) > 1) return; Range.prototype.listeners.instance = this.__Z_Range_instance__; instance = Range.prototype.listeners.instance; if (!instance) return; data = instance.data; fn = instance.fn; fn.doNothing(event); // INIT VALUES data.dragging = true; data.$slider = this; data.stepSize = 0; data.step = 0; data.sliderWidth = data.$slider.offsetWidth; data.slidersWidth = instance.$sliders.offsetWidth; data.startValue = +(data.$slider.style.left || '').replace('%', '') || 0; }, mousemove: function(event, instance, data, fn, options) { if (Math.max(+event.which, +event.button) > 1) return; instance = Range.prototype.listeners.instance; if (!instance) return; if (!instance.data.dragging) return; data = instance.data; fn = instance.fn; options = instance.options; fn.doNothing(event); data.mouse = fn.getMousePosition(event); data.element = fn.getElementPosition(instance.$sliders); data.finalX = data.mouse.x - data.element.x; // SET BORDERS if (data.finalX > data.slidersWidth) { data.finalX = data.slidersWidth; } else if (data.finalX < 0) { data.finalX = 0; } data.percentage = (data.finalX / data.slidersWidth * 100); // STEPS & COLLISIONS if (options.steps > 0) { data.stepSize = 100 / options.steps; data.step = Math.round(data.percentage / data.stepSize); data.percentage = data.step * data.stepSize; if (!options.single) { switch (data.$slider) { case instance.$primary: data.sliderX = +(instance.$secondary.style.left || '').replace('%', '') || 0; if (Math.round(data.percentage * 1000) >= Math.round(data.sliderX * 1000)) { data.percentage = data.sliderX - data.stepSize; } break; case instance.$secondary: data.sliderX = +(instance.$primary.style.left || '').replace('%', '') || 0; if (Math.round(data.percentage * 1000) <= Math.round(data.sliderX * 1000)) { data.percentage = data.sliderX + data.stepSize; } break; } data.step = Math.round(data.percentage / data.stepSize); } } else if (!options.single) { switch (data.$slider) { case instance.$primary: data.sliderX = +(instance.$secondary.style.left || '').replace('%', '') || 0; data.sliderX = data.slidersWidth / 100 * data.sliderX; if (data.finalX >= data.sliderX - data.sliderWidth) { data.finalX = data.sliderX - data.sliderWidth; } break; case instance.$secondary: data.sliderX = +(instance.$primary.style.left || '').replace('%', '') || 0; data.sliderX = data.slidersWidth / 100 * data.sliderX; if (data.finalX <= data.sliderX + data.sliderWidth) { data.finalX = data.sliderX + data.sliderWidth; } break; } data.percentage = (data.finalX / data.slidersWidth * 100); } // POSITION SLIDER & CALC VALUE data.$slider.style.left = data.percentage + '%'; data.current = Math.round( options.min + ((options.max - options.min) / 100 * data.percentage) ); // POSITION BG & SET VALUE if (options.single) { instance.$level.style.right = 100 - data.percentage + '%'; } else { switch (data.$slider) { case instance.$primary: instance.$level.style.left = data.percentage + '%'; data.$value = instance.$low; break; case instance.$secondary: instance.$level.style.right = 100 - data.percentage + '%'; data.$value = instance.$high; break; default: data.$value = {}; break; } data.$value.innerHTML = options.prefix + data.current + options.suffix; } instance.public.min = options.min; instance.public.max = options.max; instance.public.step = data.step || 0; instance.public.steps = options.steps; instance.public.value = data.current; instance.public.percentage = data.percentage; instance.public.prefix = options.prefix; instance.public.suffix = options.suffix; instance.public.single = options.single; options.onDrag.call(instance.$root, data.$slider, instance.public); }, mouseup: function(event, instance, data, fn, options) { if (Math.max(+event.which, +event.button) > 1) return; instance = Range.prototype.listeners.instance; if (!instance) return; if (!instance.data.dragging) return; data = instance.data; fn = instance.fn; options = instance.options; fn.doNothing(event); data.dragging = false; data.endValue = +(data.$slider.style.left || '').replace('%', '') || 0; if (data.startValue !== data.endValue) { instance.public.min = options.min; instance.public.max = options.max; instance.public.step = data.step || 0; instance.public.steps = options.steps; instance.public.value = data.current; instance.public.percentage = data.percentage; instance.public.prefix = options.prefix; instance.public.suffix = options.suffix; instance.public.single = options.single; options.onChange.call(instance.$root, data.$slider, instance.public); } instance.data = {}; } }; // FUNCTIONS Range.prototype.fn = {}; Range.prototype.fn.doNothing = function(event) { event = event || window.event || {}; event.cancelBubble = true; event.returnValue = false; if (event.stopPropagation) event.stopPropagation(); if (event.preventDefault) event.preventDefault(); }; Range.prototype.fn.getElementPosition = function(element) { var position = { x: 0, y: 0 }; if (!element || !element.parentNode) { return position; } while (!!element.offsetParent) { position.x += element.offsetLeft; position.y += element.offsetTop; element = element.offsetParent; } return position; }; Range.prototype.fn.getMousePosition = function(event) { if (event.touches && event.touches[0]) return { x: event.touches[0].pageX, y: event.touches[0].pageY }; if (event.pageX || event.pageY) return { x: event.pageX, y: event.pageY }; return { x: event.clientX + document.body.scrollLeft - document.body.clientLeft, y: event.clientY + document.body.scrollTop - document.body.clientTop }; }; Range.prototype.fn.getNumber = function(value, defNum) { value = value || 'x'; return +value == value ? +value : defNum; }; Range.prototype.fn.getString = function(value, defStr) { return '' + value == value ? '' + value : defStr; }; Range.prototype.fn.getBoolean = function(value, defBol) { switch (('' + value).toLowerCase()) { case 'true': case 'yes': case '1': return true; case 'false': case 'no': case '0': return false; default: return defBol; } }; Range.prototype.fn.fixOptions = function(options) { if (typeof options !== 'object') options = {}; this.options.min = this.fn.getNumber(this.$root.dataset.min, options.min); this.options.max = this.fn.getNumber(this.$root.dataset.max, options.max); this.options.steps = this.fn.getNumber(this.$root.dataset.steps, options.steps); this.options.prefix = this.fn.getString(this.$root.dataset.prefix, options.prefix); this.options.suffix = this.fn.getString(this.$root.dataset.suffix, options.suffix); this.options.single = this.fn.getBoolean(this.$root.dataset.single, options.single); this.options.values = this.fn.getString(this.$root.dataset.values, '' + options.values).split(','); this.options.min = this.fn.getNumber(this.options.min, this.defaults.min); this.options.max = this.fn.getNumber(this.options.max, this.defaults.max); this.options.steps = this.fn.getNumber(this.options.steps, this.defaults.steps); this.options.prefix = this.fn.getString(this.options.prefix, this.defaults.prefix); this.options.suffix = this.fn.getString(this.options.suffix, this.defaults.suffix); this.options.single = this.fn.getBoolean(this.options.single, this.defaults.single); this.options.values = [ this.fn.getNumber(this.options.values[0], this.options.min), this.fn.getNumber(this.options.values[1], this.options.max) ]; this.options.min = Math.round(this.options.min); this.options.max = Math.round(this.options.max); this.options.min = Math.min(this.options.min, this.options.max); this.options.max = Math.max(this.options.min, this.options.max); this.options.steps = Math.round(this.options.steps); if (this.options.values[0] < this.options.min) this.options.values[0] = this.options.min; if (this.options.values[0] > this.options.max) this.options.values[0] = this.options.max; if (this.options.values[1] > this.options.max) this.options.values[1] = this.options.max; if (this.options.values[1] < this.options.min) this.options.values[1] = this.options.min; this.options.afterInit = typeof options.afterInit == 'function' ? options.afterInit : this.defaults.afterInit; this.options.onDrag = typeof options.onDrag == 'function' ? options.onDrag : this.defaults.onDrag; this.options.onChange = typeof options.onChange == 'function' ? options.onChange : this.defaults.onChange; }; Range.prototype.fn.createElements = function() { this.$sliders = this.$root.querySelector('.' + this.defaults.classPrefix + '-sliders'); this.$primary = this.$root.querySelector('.' + this.defaults.classPrefix + '-slider_primary'); this.$secondary = this.$root.querySelector('.' + this.defaults.classPrefix + '-slider_secondary'); this.$level = this.$root.querySelector('.' + this.defaults.classPrefix + '-level'); this.$low = this.$root.querySelector('.' + this.defaults.classPrefix + '-value_low'); this.$high = this.$root.querySelector('.' + this.defaults.classPrefix + '-value_high'); if (!this.$sliders) { this.$sliders = document.createElement('div'); this.$sliders.className = this.defaults.classPrefix + '-sliders'; } if (!this.$primary) { this.$primary = document.createElement('div'); this.$primary.className = this.defaults.classPrefix + '-slider_primary'; } if (!this.$secondary) { this.$secondary = document.createElement('div'); this.$secondary.className = this.defaults.classPrefix + '-slider_secondary'; } if (!this.$level) { this.$level = document.createElement('div'); this.$level.className = this.defaults.classPrefix + '-level'; } if (!this.$low) { this.$low = document.createElement('div'); this.$low.className = this.defaults.classPrefix + '-value_low'; } if (!this.$high) { this.$high = document.createElement('div'); this.$high.className = this.defaults.classPrefix + '-value_high'; } this.$primary.__Z_Range_instance__ = this; this.$secondary.__Z_Range_instance__ = this; this.data.percentage = (this.options.max - this.options.min); this.data.left = ((this.options.values[0] - this.options.min) / this.data.percentage) * 100; this.data.right = ((this.options.values[1] - this.options.min) / this.data.percentage) * 100; this.data.stepSize = 100 / this.options.steps; this.data.step = Math.round(this.data.left / this.data.stepSize); if (this.options.single) { if (this.$secondary.parentNode) { this.$secondary.parentNode.removeChild(this.$secondary); } this.data.percentage = this.data.left; this.$secondary = this.$primary; this.$secondary.style.left = this.data.left + '%'; this.$level.style.left = '0%'; this.$level.style.right = 100 - this.data.left + '%'; this.$low.innerHTML = this.options.prefix + this.options.min + this.options.suffix; this.$high.innerHTML = this.options.prefix + this.options.max + this.options.suffix; } else { this.data.percentage = this.data.right; this.$primary.style.left = this.data.left + '%'; this.$secondary.style.left = this.data.right + '%'; this.$level.style.left = this.data.left + '%'; this.$level.style.right = 100 - this.data.right + '%'; this.$low.innerHTML = this.options.prefix + this.options.values[0] + this.options.suffix; this.$high.innerHTML = this.options.prefix + this.options.values[1] + this.options.suffix; } this.$sliders.appendChild(this.$primary); this.$sliders.appendChild(this.$secondary); this.$sliders.appendChild(this.$level); this.$root.appendChild(this.$sliders); this.$root.appendChild(this.$low); this.$root.appendChild(this.$high); }; Range.prototype.fn.attachEvents = function() { document.body.removeEventListener( this.isTouchscreen ? 'touchmove' : 'mousemove', this.listeners.mousemove ); document.body.addEventListener( this.isTouchscreen ? 'touchmove' : 'mousemove', this.listeners.mousemove ); document.body.removeEventListener( this.isTouchscreen ? 'touchend' : 'mouseup', this.listeners.mouseup ); document.body.addEventListener( this.isTouchscreen ? 'touchend' : 'mouseup', this.listeners.mouseup ); this.$primary.removeEventListener( this.isTouchscreen ? 'touchstart' : 'mousedown', this.listeners.mousedown ); this.$primary.addEventListener( this.isTouchscreen ? 'touchstart' : 'mousedown', this.listeners.mousedown ); this.$secondary.removeEventListener( this.isTouchscreen ? 'touchstart' : 'mousedown', this.listeners.mousedown ); this.$secondary.addEventListener( this.isTouchscreen ? 'touchstart' : 'mousedown', this.listeners.mousedown ); }; window.FancyRanges = function(selector, options) { try { selector = document.querySelectorAll('' + selector) } catch (error) { selector = [] } for (var i = 0, l = selector.length; i < l; i++) { new Range(selector[i], options); } }; })(); /** * Author: Marek Zeman * Twitter: MarekZeman91 * Site: http://marekzeman.cz * URL: http://codepen.io/MarekZeman91/details/xuABv/ * License: MIT * Version: 1.1 * Revision: 15.2.2015 */ $.fn.tabs = function(tabContents, options) { options = $.extend({ linkClass: "active", contentClass: "active", allowClose: false }, options); var $tabLinks = this, $tabContents = $(!!tabContents ? tabContents : ".tab-content"); return $(this).click(function(event, hadClass) { event.preventDefault(); hadClass = $(this).hasClass(options.linkClass); $tabLinks.removeClass(options.linkClass); $tabContents.removeClass(options.contentClass); if (hadClass && options.allowClose) return; $($(this).addClass(options.linkClass)[0].hash).addClass(options.contentClass); }); }; /** * Author: Marek Zeman * Twitter: MarekZeman91 * Site: http://marekzeman.cz * License: MIT * Version: 0.1 */ (function() { function AfterResizeListener(callback, jQuerySafe) { this.callback = typeof callback == 'function' ? callback : function() {}; if (jQuerySafe) return this.handleEvent.bind(this); } AfterResizeListener.prototype = {}; AfterResizeListener.prototype.timer = null; AfterResizeListener.prototype.event = null; AfterResizeListener.prototype.callback = null; AfterResizeListener.prototype.handleEvent = function(event) { clearTimeout(this.timer); this.timer = setTimeout(this.triggerResize.bind(this), 150); this.event = event; }; AfterResizeListener.prototype.triggerResize = function () { clearTimeout(this.timer); this.timer = null; this.callback.call(window, this.event); }; window.AfterResizeListener = AfterResizeListener; })(); /** * Author: Marek Zeman * Twitter: MarekZeman91 * Site: http://marekzeman.cz * License: MIT * Version: 0.2 * Revision: 26.3.2015 */ $.fn.tableColsArranger = function() { function reCalculate(x) { var docSize = document.documentElement.offsetWidth; var minSize = [0,1]; for (var i = 0; x.sizes[i]; i++) { if (minSize[0] < docSize && x.sizes[i][0] >= docSize) minSize = x.sizes[i]; } if (minSize+'' == [0,1]+'') minSize = x.sizes[i-1]; if (x.lastSize+'' == minSize+'') return; x.lastSize = minSize; x.$td.detach(); x.$trHolder.children().remove(); x.$td.each(reArrange.bind(x)); } function reArrange(i, el, cols) { cols = this.lastSize[1]; this.$tr = i % cols == 0 ? $('').appendTo(this.$trHolder) : this.$trHolder.children().last(); this.$tr.append(el); if (i+1 === this.$td.length) { this.$tr.appendTo(this.$trHolder); } } function init(x) { x = {}; x.$table = $(this); x.$td = x.$table.find('> tr, > tbody > tr').children(); x.$tr = null; x.$trHolder = x.$table.children('tbody'); x.$trHolder = !!x.$trHolder.length ? x.$trHolder : x.$table; x.sizes = x.$table.data('responsive') || []; x.lastSize = [0,1]; $(window).resize(new AfterResizeListener(function() { reCalculate(x) }, true)); } return this.each(init); }; /** * Author: Marek Zeman * Twitter: MarekZeman91 * Site: http://marekzeman.cz * License: MIT * Version: 1.1 * Revision: 12.4.2015 // added IE8 support */ (function() { function getOrMake(id, type) { var element = document.getElementById(id) || document.createElement(type || 'div'); return (element.id = id, element); } var element = document.body.appendChild(getOrMake('popup')); classes.add(element, 'invisible'); element = element.appendChild(getOrMake('popup-overlay')); element = element.appendChild(getOrMake('popup-window')); element = element.appendChild(getOrMake('popup-view')); element.appendChild(getOrMake('popup-close')); element.appendChild(getOrMake('popup-content')); var elements = { popup: getOrMake('popup'), content: getOrMake('popup-content'), close: getOrMake('popup-close') }; var Popup = { show: function(hideClose) { elements.close.style.display = hideClose ? 'none' : ''; classes.remove(elements.popup, 'invisible'); return Popup; }, hide: function() { classes.add(elements.popup, 'invisible'); return Popup; }, add: function(html) { if (is.validElement(html)) { elements.content.appendChild(html); return Popup; } if (is.iterable(html)) { for (var i = 0, l = html.length; i < l; i++) { if (!is.validElement(html[i])) continue; elements.content.appendChild(html[i]); } return Popup; } elements.content.innerHTML += html; return Popup; }, fill: function(html) { elements.content.innerHTML = ''; return Popup.add(html); }, elements: elements }; getOrMake('popup-close').onclick = Popup.hide; window.Popup = Popup; })(); /** * Author: Marek Zeman * Twitter: MarekZeman91 * Site: http://marekzeman.cz * License: MIT * Version: 1 */ function deserialize(url) { if (''+url !== url) return; var properties = url.replace(/\+/g, ' ').split('&') , property, name, value, groups = {} , i1, i2, l, inputs; while (property = properties.shift()) { property = decodeURIComponent(property) || ''; property = property.split('='); name = property.shift() || ''; value = property.shift() || ''; groups[name] || (groups[name] = []); groups[name].push(value); } for (name in groups) { inputs = document.getElementsByName(name) || []; i1 = 0; l = inputs.length; while (i1 < l) { switch (inputs[i1].type) { case 'checkbox': case 'radio': inputs[i1].checked = groups[name].indexOf(inputs[i1].value) !== -1; break; case 'select-multiple': i2 = 0; while (inputs[i1].options[i2]) { inputs[i1].options[i2].selected = groups[name].indexOf(inputs[i1].options[i2].value) !== -1; i2++; } break; default: if (inputs[i1].type !== 'file' && !!groups[name][i1]) { inputs[i1].value = groups[name][i1]; } break; } i1++; } } } /** * Title: HistoryManager * Author: Marek Zeman * Twitter: MarekZeman91 * Site: http://marekzeman.cz * License: MIT * Version: 1 * Revision: 11.6.2015 // created */ (function() { var plugin = 'HistoryManager'; var namespace, listeners = {}; var errors = { namespaceNotString: 'HistoryManager.%FN%, "namespace" has to be a string!', listenerNotFunction: 'HistoryManager.%FN%, "listener" has to be a function!', titleNotString: 'HistoryManager.%FN%, "title" has to be a string!', linkNotString: 'HistoryManager.%FN%, "link" has to be a string!' }; function throwError(error, fn) { throw new Error(error.replace('%FN%', fn)) } function isFunction(fn) { return typeof fn === 'function' } function isString(str) { return '' + str === str } function setListener(namespace, listener) { if (!isString(namespace)) throwError(errors.namespaceNotString, 'setListener'); if (!isFunction(listener)) throwError(errors.listenerNotFunction, 'setListener'); listeners[namespace] = listener; return window[plugin]; } function removeListener(namespace) { if (!isString(namespace)) throwError(errors.namespaceNotString, 'removeListener'); delete listeners[namespace]; return window[plugin]; } function changeTo(data, title, link) { if (!isString(title)) throwError(errors.titleNotString, 'changeTo'); if (!isString(link)) throwError(errors.linkNotString, 'changeTo'); if (link === location.href) return window[plugin]; document.title = title; history.pushState({data: data, title: title, link: link, plugin: plugin}, title, link); return window[plugin]; } function initWith(data, title, link) { if (!isString(title)) throwError(errors.titleNotString, 'initWith'); if (!isString(link)) throwError(errors.linkNotString, 'initWith'); document.title = title; history.replaceState({data: data, title: title, link: link, plugin: plugin}, title, link); return window[plugin]; } function onPopState(event) { if (!event.state || event.state.plugin !== plugin) return window[plugin]; document.title = event.state.title; for (namespace in listeners) listeners[namespace]( event.state.data, event.state.title, event.state.link, namespace ); return window[plugin]; } window.addEventListener('popstate', onPopState); window[plugin] = { changeTo: changeTo, initWith: initWith, setListener: setListener, removeListener: removeListener } })();