//# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // //# TOOLS (function($) { //# --------------------------------------------------------------------------------- // //# sortAsc Array.prototype.sortAsc = function() { this.sort(function(_a, _b) { return _a - _b; }); } //# sortDesc Array.prototype.sortDesc = function() { this.sort(function(_a, _b) { return _b - _a; }); } //# sortOnKey Array.prototype.sortOnKey = function(_type, _key) { this.sort(function(_a, _b) { if ( _type == 'ASC' ) { return ~~( _key ? _a[_key] > _b[_key] : _a > _b ); } if ( _type == 'DESC' ) { return ~~( _key ? _a[_key] < _b[_key] : _a < _b ); } }); } //# --------------------------------------------------------------------------------- // //# inArray inArray = function(_value, _array) { var i; for ( i=0; i < _array.length; i++ ) { if (_array[i] == _value) { return true; } } return false; } //# --------------------------------------------------------------------------------- // //# trimText trimText = function(_str, _maxwidth) { var newStr; if ( _str.length > _maxwidth ) { newStr = _str.substring(0, _maxwidth) + '...'; } else { newStr = _str; } return newStr; } //# --------------------------------------------------------------------------------- // //# createHashUrl createHashUrl = function(_str, _more) { var oldUrl = _str.replace('?', '').split('&'); var newUrl = ''; var tmpMore = _more ? '/' + _more : ''; var get; for ( var s=0; s= 0 && percentage <= 100 ) ? percentage : ( percentage < 0 ) ? 0 : 100; } return percentage; } //# --------------------------------------------------------------------------------- // //# submitForm submitForm = function(_str) { $('form[name=' + _str + ']').submit(); } //# submitThis submitThis = function(_obj) { _obj.submit(); } //# --------------------------------------------------------------------------------- // //# scrollHtml scrollHtml = function(_val, _speed) { return $('html, body').animate( {scrollTop: _val+'px'}, {queue: false, duration: _speed} ); } //# --------------------------------------------------------------------------------- // //# setFullscreen setFullscreen = function(_obj) { var el = _obj; if ( el.requestFullScreen ) { el.requestFullScreen(); } else if ( el.mozRequestFullScreen ) { el.mozRequestFullScreen(); } else if ( el.webkitRequestFullScreen ) { el.webkitRequestFullScreen(); } } //# endFullscreen endFullscreen = function() { if ( document.cancelFullScreen ) { document.cancelFullScreen(); } else if ( document.mozCancelFullScreen ) { document.mozCancelFullScreen(); } else if ( document.webkitCancelFullScreen ) { document.webkitCancelFullScreen(); } } //# --------------------------------------------------------------------------------- // //# resizeObject resizeObject = function(_obj, _cont) { var thisObj = _obj; //: np. $('img') var thisContainer = _cont; //: np. $(window) var tmpWidth = thisObj.width(); var tmpHeight = thisObj.height(); var winWidth = thisContainer.width(); var winHeight = thisContainer.height(); var widthRatio = (winWidth / tmpWidth); var heightRatio = (winHeight / tmpHeight); var widthDiff = (heightRatio * tmpWidth); var heightDiff = (widthRatio * tmpHeight); if ( heightDiff > winHeight ) { thisObj.css({ width: winWidth + 'px', height: heightDiff + 'px' }); } else { thisObj.css({ width: widthDiff + 'px', height: winHeight + 'px' }); } } //# --------------------------------------------------------------------------------- // //# loadImage loadImage = function(_obj, _file, _speed) { var thisImage = new Image(); var thisObj = _obj; var thisFile = _file; var thisSpeed = parseInt(_speed); $(thisImage) .load( function(e) { $(this).hide(); thisObj.html(this).addClass('Loading'); $(this).stop(true, true).animate({opacity: 'show'}, thisSpeed, function() { $(this).parent(thisObj).removeClass('Loading'); }); }) .error( function(e) { thisObj.html('Brak zdjęcia: ' + thisFile + '').removeClass('Loading'); }) .attr('src', thisFile); } //# --------------------------------------------------------------------------------- // //# pageScrollPosition pageScrollPosition = function() { var xScroll, yScroll; if ( self.pageYOffset ) { yScroll = self.pageYOffset; xScroll = self.pageXOffset; } else if ( document.documentElement && document.documentElement.scrollTop ) { // Explorer 6 Strict yScroll = document.documentElement.scrollTop; xScroll = document.documentElement.scrollLeft; } else if ( document.body ) { // all other Explorers yScroll = document.body.scrollTop; xScroll = document.body.scrollLeft; } return new Array(xScroll, yScroll); } //# --------------------------------------------------------------------------------- // //# mousePosition mousePosition = function(_e, _str) { var value; if ( _e.originalEvent.touches ) { if ( _str == 'pageX' ) { value = _e.originalEvent.touches[0].pageX; } if ( _str == 'pageY' ) { value = _e.originalEvent.touches[0].pageY; } } else if ( _e.originalEvent ) { if ( _str == 'pageX' ) { value = _e.originalEvent.pageX ? _e.originalEvent.pageX : _e.originalEvent.clientX; } if ( _str == 'pageY' ) { value = _e.originalEvent.pageY ? _e.originalEvent.pageY : _e.originalEvent.clientY; } } else { if ( _str == 'pageX' ) { value = _e.pageX; } if ( _str == 'pageY' ) { value = _e.pageY; } } return value; } //# --------------------------------------------------------------------------------- // //# addEvent addEvent = function(_element, _eventName, _callback) { if ( _element.addEventListener ) { _element.addEventListener(_eventName, _callback, false) } else { _element.attachEvent(_eventName, _callback, false); } } //# stopEvent stopEvent = function(_e) { if ( !_e ) { _e = window.event; } _e.cancelBubble = true; _e.returnValue = false; if ( _e.stopPropagation ) { _e.stopPropagation(); } if ( _e.preventDefault ) { _e.preventDefault(); } return false; } //# --------------------------------------------------------------------------------- // //# isTouchDevice isTouchDevice = function() { var isTouch = false; if ( navigator.userAgent.indexOf('Phone') > -1 || navigator.userAgent.indexOf('Touch') > -1 || navigator.userAgent.indexOf('Android') > -1 ) { isTouch = true; } else if ( navigator.userAgent.indexOf('MSIE') > -1 || navigator.userAgent.indexOf('Trident') > -1 ) { if ( !!('ontouchstart' in window) ) { isTouch = true; } } else if ( !!('ontouchstart' in window) || !!('onmsgesturechange' in window) ) { if ( navigator.userAgent.match(/mobile/i) ) { isTouch = true; } } return isTouch; } //# --------------------------------------------------------------------------------- // //# detectScrollDirection | _node -> '.class', '#id', '' or this detectScrollDirection = function(_node, _e) { if ( _e.type == 'scroll' ) { if ( typeof lastTop == 'undefined' ) { lastTop = 0; } currTop = $(_node).scrollTop(); direction = ( currTop >= lastTop ) ? 'down' : 'up'; lastTop = currTop; } return ( typeof direction != 'undefined' ) ? direction : ''; } //# --------------------------------------------------------------------------------- // //# disableMouseWheel | _node -> '', '.class', '#id', '' disableMouseWheel = function(_node) { $(document) .on('DOMMouseScroll mousewheel touchmove', _node, function(e) { stopEvent(e); }); } //# preventMouseWheel | _node -> '', '.class', '#id', '' preventMouseWheel = function(_node) { var startPos; var scrollTo; var divideNum = 4; $(document) .on('touchstart', _node, function(e) { startPos = $(this).scrollTop() + e.originalEvent.touches[0].pageY; }) .on('DOMMouseScroll mousewheel touchmove', _node, function(e) { switch(e.type) { case 'DOMMouseScroll': scrollTo = $(this).scrollTop() + ((e.originalEvent.detail * 40) / divideNum); break; case 'mousewheel': scrollTo = $(this).scrollTop() + ((e.originalEvent.wheelDelta * -1) / divideNum); break; case 'touchmove': scrollTo = startPos - e.originalEvent.touches[0].pageY; break; } if ( scrollTo ) { stopEvent(e); $(this).scrollTop(scrollTo); } }); } //# isolatedMouseWheel | _node -> '', '.class', '#id', '' isolatedMouseWheel = function(_node) { var startPos; var limitTop; var limitBottom; var delta; $(document) .on('touchstart', _node, function(e) { startPos = e.originalEvent.touches[0].pageY; }) .on('DOMMouseScroll mousewheel touchmove', _node, function(e) { limitTop = 0; limitBottom = ( $(this)[0].scrollHeight ) ? $(this)[0].scrollHeight - $(this).height() : $(this).height() - $(window).height(); switch(e.type) { case 'DOMMouseScroll': delta = e.originalEvent.detail * -1; break; case 'mousewheel': delta = e.originalEvent.wheelDelta; break; case 'touchmove': delta = ( startPos > e.originalEvent.touches[0].pageY ) ? -1 : 1; break; } if ( delta > 0 && $(this).scrollTop() <= limitTop ) { stopEvent(e); } if ( delta < 0 && $(this).scrollTop() >= limitBottom ) { stopEvent(e); } }); } //# --------------------------------------------------------------------------------- // //# getScrollDetails | _node -> '.class', '#id', '' or this getScrollDetails = function(_node, _e) { if ( _e.type == 'scroll' || _e.type == 'resize' ) { if ( typeof lastTop == 'undefined' ) { lastTop = 0; } currTop = $(_node).scrollTop(); limitTop = 0; limitBottom = ( $(_node)[0].scrollHeight ) ? $(_node)[0].scrollHeight - $(_node).height() : ( $.isWindow(_node) ) ? $(document).height() - $(_node).height() : $(_node).height() - $(window).height(); jsonData = { 'action' : ( currTop >= limitBottom ) ? 'end' : ( currTop <= limitTop ) ? 'start' : 'move', 'direction' : ( currTop >= lastTop ) ? 'down' : 'up', 'progress' : calculatePercentages(currTop, limitBottom, true) + '%', 'position' : currTop, 'limit' : limitBottom } lastTop = currTop; } return ( typeof jsonData != 'undefined' ) ? jsonData : ''; } //# --------------------------------------------------------------------------------- // //# getResponseData getResponseData = function(_data) { var result = ''; if ( _data ) { try { result = $.parseJSON(_data); } catch(e) { result = _data; } } return result; } //# --------------------------------------------------------------------------------- // //# getMediaFromUrl getMediaFromUrl = function(_url) { var match = null; var media = {}; var regY = /^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/; var regV = /^.*(?:(?:vimeo\.com\/|channels\/|staffpicks\/|originals\/\inthemoment\/|groups\/\/|videos\/))([^#\&\?]*).*/; if ( _url.match(regY) ) { match = _url.match(regY); media.type = 'youtube'; media.id = match[1]; } else if ( _url.match(regV) ) { match = _url.match(regV); media.type = 'vimeo'; media.id = match[1]; } return media; } //# --------------------------------------------------------------------------------- // //# getFormDataArray getFormDataArray = function(_obj) { var result = {}; _obj.find('input, textarea, select').map(function(index, el) { var tagname = el.tagName.toLowerCase(); var tagtype = el.type.toLowerCase(); var postname = el.name; if ( tagtype == 'radio' ) { result[postname] = _obj.find('[type="' + tagtype + '"][name="' + postname + '"]:checked').val() || ''; } else if ( tagtype == 'checkbox' ) { if ( _obj.find('[type="' + tagtype + '"][name="' + postname + '"]').length == 1 ) { result[postname] = _obj.find('[type="' + tagtype + '"][name="' + postname + '"]:checked').val() || ''; } else { result[postname] = getObjectItems(_obj.find('[type="' + tagtype + '"][name="' + postname + '"]:checked')); } } else if ( tagtype == 'select-one' ) { result[postname] = $(el).children('option:selected').val(); } else if ( tagtype == 'select-multiple' ) { result[postname] = getObjectItems($(el).children('option:selected')); } else { result[postname] = $(el).val(); } }); function getObjectItems(_object) { items = []; _object.map(function(index, el) { items[index] = $(el).val(); }); items = $.grep(items, function(n) { return(n); }); return ( items.length > 0 ) ? items : ''; } return result; } //# --------------------------------------------------------------------------------- // //# getSwfMovie getSwfMovie = function(_movieName) { var isIE = navigator.appName.indexOf('Microsoft') != -1; return ( isIE ) ? window[_movieName] : document[_movieName]; } //# --------------------------------------------------------------------------------- // // setCookie setCookie = function(_cookieName, _cookieValue, _cookieExpires, _cookieLength) { const curDate = new Date(); let exdate; if ( _cookieLength === 'days' ) { exdate = new Date(curDate.getTime() + (_cookieExpires * 86400 * 1000)); }else if ( _cookieLength === 'minutes' ) { exdate = new Date(curDate.getTime() + (_cookieExpires * 60 * 1000)); } const c_value = escape(_cookieValue) + ((exdate== null) ? '' : '; expires=' + exdate.toUTCString()); console.log( _cookieExpires, _cookieLength, curDate, exdate, exdate.toUTCString() ); document.cookie = _cookieName + '=' + c_value; }; //# getCookie getCookie = function(_cookieName) { var i, x, y, ARRcookies = document.cookie.split(';'); for ( i=0; i 'function, object, boolean, number, string' logObjectDetails = function(_object, _clear, _exclude) { _object = $(_object).get(0) || _object; _exclude = _exclude.replace(/\s+/g, '').split(','); if ( typeof window.console != 'undefined' ) { if ( _clear ) { console.clear(); } console.log( _object, '\r-------------------------------------------------------------------' ); for ( var key in _object ) { if ( _object[key] != null && !inArray(typeof _object[key], _exclude) ) { console.log( '[', typeof _object[key], '] ', key, ': ', _object[key] ); } } console.log( '-------------------------------------------------------------------' ); } } })(jQuery);