/* ============================================================= * Foundation * Copyright(c) 2024 Vook * * All rights reserved - Do Not Redistribute * ============================================================ */ if (typeof module !== 'undefined') module.exports = window !function($) { $.vook = $.vook || { params: { company: undefined, id: undefined }, version: '0.0.1' } }(window.jQuery) /* ============================================================= * Calendar * Copyright(c) 2024 Vook * * All rights reserved - Do Not Redistribute * ============================================================ */ !function($) { }(window.jQuery) /* ============================================================= * Color picker * Copyright(c) 2024 Vook * * All rights reserved - Do Not Redistribute * ============================================================ */ !function($) { }(window.jQuery) /* ============================================================= * Cookie * Copyright(c) 2024 Vook * * All rights reserved - Do Not Redistribute * ============================================================ */ !function($) { $.cookie = function(key, value, options) { // key and at least value given, set cookie... if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) { options = $.extend({}, options) if (value === null || value === undefined) { options.expires = -1 } if (typeof options.expires === 'number') { var days = options.expires, t = options.expires = new Date() t.setDate(t.getDate() + days) } value = String(value) return (document.cookie = [ encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : '' ].join('')) } // key and possibly options given, get cookie... options = value || {} var decode = options.raw ? function(s) { return s; } : decodeURIComponent var pairs = document.cookie.split('; ') for (var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) { if (decode(pair[0]) === key) return decode(pair[1] || '') // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, thus pair[1] may be undefined } return null } }(window.jQuery) /* ============================================================= * Data tables * Copyright(c) 2024 Vook * * All rights reserved - Do Not Redistribute * ============================================================ */ !function($) { var DataTable = function(element, options) { this.$element = $(element) this.options = $.extend({}, $.fn.dataTable.defaults, options) this.init() } DataTable.prototype = { constructor: DataTable, init: function() { _.bindAll(this) if (this.options.sortable) this.sortable() return this }, sortable: function() { var sortables = this.$table.find('.sortable') _.each(sortables, function(colHead) { $(colHead).click(this.columnSort) }, this) }, columnSort: function(event) { var column = $(event.target), ascending = false, tableCells = this.$table.find('td'), columnCells = _.filter(tableCells, function(cell) { return $(cell).index() === column.index() }) ascending = column.hasClass('sorted-asc') ? true: false this.sortElements(columnCells, function(a, b) { return $.text([a]) > $.text([b]) ? (ascending ? false: true): (ascending ? true: false) }) this.$table.find('th').removeClass('sorted-asc sorted-desc') ascending ? column.addClass('sorted-desc'): column.addClass('sorted-asc') tableCells.css('background', 'transparent') $(columnCells).css('background', '#efefef') }, sortElements: function(elements, comparator) { var placements = _.map(elements, function(element) { var sortElement = element.parentNode, container = sortElement.parentNode, nextElement = container.insertBefore(document.createTextNode(''), sortElement.nextSibling) return function() { container.insertBefore(this, nextElement) container.removeChild(nextElement) } }) return _.each([].sort.call(elements, comparator), function(el, i) { placements[i].call(el.parentNode) }) } } $.fn.dataTable = function(option) { return this.each(function() { var $this = $(this), data = $this.data('table'), options = typeof option == 'object' && option if (!data) $this.data('table', (data = new DataTable(this, options))) if (typeof option == 'string') data[option]() }) } $.fn.dataTable.Constructor = DataTable $.fn.dataTable.defaults = $.fn.dataTable.defaults || { sortable: false } }(window.jQuery) /* ============================================================= * Track event * Copyright(c) 2024 Vook * * All rights reserved - Do Not Redistribute * ============================================================ */ !function($) { $.fn.trackEvent = function(option) { return this.each(function() { var $this = $(this), options = typeof option == 'object' && option if (typeof _gaq !== 'undefined') $this.on(options.event, function() { _gaq.push(options.model) }) }) } $.fn.trackEvent.defaults = $.fn.trackEvent.defaults || { /* selector: { event: 'click', model: [] } */ events: { '.get-file': { event: 'click', model: ['_trackEvent', 'Preview', 'Get', 'Preview - Get file'] }, '.send-email': { event: 'click', model: ['_trackEvent', 'Preview', 'Send', 'Preview - Send email'] } } } _.each($.fn.trackEvent.defaults.events, function(event, selector) { $(selector).trackEvent(event) }) }(window.jQuery) /* ============================================================= * Loading mask * Copyright(c) 2024 Vook * * All rights reserved - Do Not Redistribute * ============================================================ */ !function($) { $.loadMask = function(delay, duration) { var delay = delay || $.loadMask.defaults.delay, duration = duration || $.loadMask.duration $('#loading-mask').delay(delay).fadeOut(duration, function() { $(this).remove() }) } $.loadMask.defaults = $.loadMask.defaults || { delay: 1500, duration: 500 } $(function() { $.loadMask() }) }(window.jQuery) /* ============================================================= * Log * Copyright(c) 2024 Vook * * All rights reserved - Do Not Redistribute * ============================================================ */ !function($) { var levels = { critical: 0, error: 1, warning: 2, info: 3, debug: 4 } $.log = function(msg, lvl, params) { var options = $.extend({}, $.log.defaults, options) var level = options.level, lvl = lvl || 'debug', url = options.url if (levels[lvl] <= levels[level]) { if (url) { var data = { message: msg, level: lvl } if (params) _.extend(data, params) $.post(url, data) } else if (window.console) { if (params) { msg += '\n' _.each(params, function(value, key) { msg += key + ': ' + value + '\n' }) } window.console.log(lvl + ': ' + msg) } } } $.log.critical = function(msg, fields) { $.log(msg, 'critical', fields) } $.log.error = function(msg, fields) { $.log(msg, 'error', fields) } $.log.warning = function(msg, fields) { $.log(msg, 'warning', fields) } $.log.info = function(msg, fields) { $.log(msg, 'info', fields) } $.log.debug = function(msg, fields) { $.log(msg, 'debug', fields) } $.log.defaults = $.log.defaults || { level: 'info', url: undefined //'/logs/' } $.log.defaults.company = ($.vook.params && $.vook.params.company) ? $.vook.params.company: 'undefined' $.log.defaults.id = ($.vook.params && $.vook.params.id) ? $.vook.params.id: 'undefined' $.vook.onError = $.vook.onError || { conf: { mods: [] } } $.onError = function(msg, url, ln) { var fields = { lang: 'javascript', url: window.location.origin + window.location.pathname, file: url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('?')) + ':' + ln, company: $.log.defaults.company, title: $.log.defaults.id }, match = _.find($.onError.defaults.mods, function(str) { return _.str.include(msg, str) }) if (match) $.log.debug(msg, fields) else $.log.error(msg, fields) } $.onError.defaults = $.onError.defaults || { mods: [] } // TODO: Assign only on non-dev environment window.onerror = $.onError }(window.jQuery) /* ============================================================= * Scroll To * Copyright(c) 2024 Vook * * All rights reserved - Do Not Redistribute * ============================================================ */ !function($) { var $scrollTo = $.scrollTo = function(target, duration, settings) { $(window).scrollTo(target, duration, settings) } $scrollTo.defaults = { axis: 'xy', duration: parseFloat($.fn.jquery) >= 1.3 ? 0: 1 } // Returns the element that needs to be animated to scroll the window. // Kept for backwards compatibility (specially for localScroll & serialScroll) $scrollTo.window = function(scope) { return $(window)._scrollable() } // Hack, hack, hack :) // Returns the real elements to scroll (supports window/iframes, documents and regular nodes) $.fn._scrollable = function() { return this.map(function() { var elem = this, isWin = !elem.nodeName || $.inArray(elem.nodeName.toLowerCase(), ['iframe', '#document', 'html', 'body']) != -1 if (!isWin) return elem var doc = (elem.contentWindow || elem).document || elem.ownerDocument || elem return $.browser.safari || doc.compatMode == 'BackCompat' ? doc.body: doc.documentElement }) } $.fn.scrollTo = function(target, duration, settings) { if (typeof duration == 'object') { settings = duration duration = 0 } if (typeof settings == 'function') settings = { onAfter: settings } if (target == 'max') target = 9e9 settings = $.extend({}, $scrollTo.defaults, settings) // Speed is still recognized for backwards compatibility duration = duration || settings.speed || settings.duration // Make sure the settings are given right settings.queue = settings.queue && settings.axis.length > 1 if (settings.queue) // Let's keep the overall duration duration /= 2 settings.offset = both(settings.offset) settings.over = both(settings.over) return this._scrollable().each(function() { var elem = this, $elem = $(elem), targ = target, toff, attr = {}, win = $elem.is('html,body') switch (typeof targ) { // A number will pass the regex case 'number': case 'string': if (/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(targ)) { targ = both(targ) // We are done break } // Relative selector, no break! targ = $(targ, this) case 'object': // DOMElement / jQuery if (targ.is || targ.style) // Get the real position of the target toff = (targ = $(targ)).offset() } $.each(settings.axis.split(''), function(i, axis) { var Pos = axis == 'x' ? 'Left': 'Top', pos = Pos.toLowerCase(), key = 'scroll' + Pos, old = elem[key], max = $scrollTo.max(elem, axis) if (toff) { // jQuery / DOMElement attr[key] = toff[pos] + (win ? 0: old - $elem.offset()[pos]) // If it's a dom element, reduce the margin if (settings.margin) { attr[key] -= parseInt(targ.css('margin' + Pos)) || 0 attr[key] -= parseInt(targ.css('border' + Pos + 'Width')) || 0 } attr[key] += settings.offset[pos] || 0 if (settings.over[pos]) // Scroll to a fraction of its width/height attr[key] += targ[axis == 'x' ? 'width': 'height']() * settings.over[pos] } else { var val = targ[pos] // Handle percentage values if (attr && attr[key]) attr[key] = val.slice && val.slice( - 1) == '%' ? parseFloat(val) / 100 * max: val } // Number or 'number' if (/^\d+$/.test(attr[key])) // Check the limits attr[key] = attr[key] <= 0 ? 0: Math.min(attr[key], max) // Queueing axes if (!i && settings.queue) { // Don't waste time animating, if there's no need. if (old != attr[key]) // Intermediate animation animate(settings.onAfterFirst) // Don't animate this axis again in the next iteration. delete attr[key] } }) animate(settings.onAfter) function animate(callback) { $elem.animate(attr, duration, settings.easing, callback && function() { callback.call(this, target, settings) }) } }).end() } // Max scrolling position, works on quirks mode // It only fails (not too badly) on IE, quirks mode. $scrollTo.max = function(elem, axis) { var Dim = axis == 'x' ? 'Width': 'Height', scroll = 'scroll' + Dim if (!$(elem).is('html,body')) return elem[scroll] - $(elem)[Dim.toLowerCase()]() var size = 'client' + Dim, html = elem.ownerDocument.documentElement, body = elem.ownerDocument.body return Math.max(html[scroll], body[scroll]) - Math.min(html[size], body[size]) } function both(val) { return typeof val == 'object' ? val: { top: val, left: val } } }(window.jQuery) /* ============================================================= * Progress bar * Copyright(c) 2024 Vook * * All rights reserved - Do Not Redistribute * ============================================================ */ !function($) { }(window.jQuery) /* ============================================================= * Slider * Copyright(c) 2024 Vook * * All rights reserved - Do Not Redistribute * ============================================================ */ !function($) { }(window.jQuery)