var DText = new Array(); var vvUPText = new Array(); var allText = new Array(); var MText = new Array(); var $ac = new Array(); var ajaxBoxMove = false; var noScrollHistory = false; var currentPage = new Array(); var autoSaveQue = new Array(); var popUpWindow = null; Array.prototype.indexOf = function(obj, start) { for (var i = (start || 0), j = this.length; i < j; i++) { if (this[i] === obj) { return i; } } return -1; } function parmsReplace(msg,parms){ if(parms == null || parms == undefined || msg == ""){ return msg; } if( typeof parms === 'object' && parms !== null){ for(i in parms){ if(typeof parms[i] === 'object'){ var _parms = {}; for(x in parms[i]){ _parms[i+'_'+x] = parms[i][x]; _parms[i+'.'+x] = parms[i][x]; } msg = parmsReplace(msg,_parms); }else{ var reg = new RegExp('\\[\\['+i+'\\]\\]', "ig"); msg = msg.replace(reg,parms[i]); var reg = new RegExp('\{\{'+i+'\}\}', "g"); msg = msg.replace(reg,parms[i]); var reg = new RegExp('\{'+i+'\}', "g"); msg = msg.replace(reg,parms[i]); } } } return msg; } function vvlink(_this){ console.log('Click on link'); console.log($(_this).parent().find('a.right')); $(_this).parent().find('a.right').trigger('click'); } function urldecode(str) { return decodeURIComponent((str+'').replace(/\+/g, '%20')); } function vvSizer(){ var h = $(window).height(); var dh = $(document).height(); var w = $(window).width(); var s = $(window).scrollTop(); $(document).trigger('vvSizer'); $(document).trigger('vvSizerExtra'); $("._col-long").vvShorten(); } var vvTimerVar = false; var vvTimerInter = null; function vvTimer(time,update,complete) { var start = new Date().getTime(); if(vvTimerInter != null){ clearInterval(vvTimerInter); vvTimerInter = null; vvTimerVar = false; $('.timeout').removeClass('active'); } vvTimerInter = setInterval(function() { var now = time-(new Date().getTime()-start); if( now <= 0) { clearInterval(vvTimerInter); complete(); }else{ update(Math.floor(now/1000)); } },1000); // the smaller this number, the more accurate the timer will be } function getSearchParameters() { var prmstr = window.location.search.substr(1); return prmstr != null && prmstr != "" ? transformToAssocArray(prmstr) : {}; } function transformToAssocArray( prmstr ) { var params = {}; var prmarr = prmstr.split("&"); for ( var i = 0; i < prmarr.length; i++) { var tmparr = prmarr[i].split("="); params[tmparr[0]] = tmparr[1]; } return params; } function vvHeroImage(img){ if($("#hero-image").get(0) == undefined){ $(body).append('
'); } $('#hero-image ._hold').anystretch(img); } /* * Edit in progress * vvEditInProgress = true */ var vvEditInProgress = false; function vvCheckClose(){ if(vvEditInProgress){ vvDebugg('Close before edit'); return lang.admin['edit-in-progress']; } } window.onbeforeunload = vvCheckClose; var vvCurrentInput = null; var vvShareTimer = null; var vvShareId = null; function vvUrlInit(){ // vvAjax Navigation init if ("pushState" in history) { //vvDebugg('pushState -> '+settings['URL_PUSH']); if(settings['URL_PUSH']){ $('a:not(.link-init)').each(function(index, obj) { $(this).addClass('link-init'); if($(this).attr('href') == undefined){return;} if($(obj).attr('idx') != undefined){ if(currentPage['id'] == $(obj).attr('idx')){ $(".menu-link-"+$(obj).attr('child-of')).addClass('_active'); $(".menu-link-"+$(obj).attr('idx')).addClass('_active'); $(obj).addClass('_active'); vvDebugg('-- Add class _active 1. Current page '+currentPage['id']); document.title = HtmlDecode(settings['TITLE']+" - "+currentPage['title']); } } if( $(obj).hasClass('popup') ){ $(obj).unbind('click').click(function(e) { e.preventDefault(); window.open(HtmlDecode($(this).attr('url')),"popUpWindow","width=700,height=500,toolbar=0,scrollbars=0,status=0,resizable=0,location=0,menuBar=0"); }); } if($(obj).hasClass('ajax')){ $(obj).bind('click',function(e) { if($(obj).hasClass('loadPage')){ loadPage = false; }else{ loadPage = true; } if($(this).attr('title') != undefined){ var title = $(this).attr('title'); }else{ var title = $(this).text(); } $(document).trigger('vvPageChange'); var url = this.href; lastTitle = document.title; currentPage['title'] = title; currentPage['id'] = $(this).attr('idx'); currentPage['text'] = $(this).text(); pushScrollHistory[urlKey()] = $(window).scrollTop(); pushState({idx:$(obj).attr('idx'),ID:$(obj).attr('id'),Title:title,LoadPage:loadPage,AjaxBox:false}, title, url); }); }else if( !$(obj).hasClass('paginate_button') && !$(obj).hasClass('noAjax') && !$(obj).hasClass('ignore') && $(obj).attr('href') != '#menu'){ $(obj).unbind('click').bind('click',function(e) { e.preventDefault(); console.log('Link click'); abortAllRequests(); if(vvEditInProgress){ if(!confirm(lang.admin['edit-in-progress'])){ return; } } $(document).trigger('vvClick'); if(this.href.match(/\#/)){ vvDebugg('+++ Hash'); hash = this.href.split("#"); if(hash[1] == undefined || hash[1] == '#'){ return; } $(document).trigger('vvHash'); if($("#"+hash[1]).get(0) != undefined){ vvDebugg('Scroll page to '+"#"+hash[1]); $("html, body").stop().animate({ scrollTop: $("#"+hash[1]).offset().top-120}); $(document).trigger('vvPageChange'); if($("#"+hash[1]).hasClass('form-group')){ $("#"+hash[1]).find('input,select,textarea').focus(); } return false; }else{ vvDebugg('Not found '+"#"+hash[1]); } } if($(this).attr('href').match(/\tel:/)){ vvTrackEvent('Users call','click','leave',$(this).attr('href')); vvDebugg('Http'); $(document).trigger('vvOut'); return; } if($(this).attr('href').match(/\http/)){ console.log('Out link clicked'); vvTrackEvent('User Integration','click','leave',$(this).attr('href')); vvDebugg('Http'); $(document).trigger('vvOut'); window.open($(this).attr('href'), '_blank').focus(); return; } if($(this).attr('href').match(/\mailto/)){ vvTrackEvent('User Integration','click','mailto',$(this).attr('href')); vvDebugg('vvMailto'); $(document).trigger('vvMailto'); return; } if($(this).attr('target') == '_blank'){ vvDebugg('target = blank'); window.open($(this).attr('href')); return; } vvDebugg('--- Remove class _active from ._active'); $('._active').removeClass('_active'); vvDebugg('--- Remove class open from .nav-main-heade .open'); $('.nav-main-header .open').removeClass('open'); vvDebugg('--- Add _active class to child of: '+".menu-link-"+$(obj).attr('child-of')); vvDebugg('--- Add _active class to: '+".menu-link-"+$(obj).attr('idx')); $(".menu-link-"+$(obj).attr('child-of')).addClass('_active'); $(".menu-link-"+$(obj).attr('idx')).addClass('_active'); $(document).trigger('vvPageChange'); if($(this).attr('title') != undefined){ var title = $(this).attr('title'); }else{ var title = $(this).text(); } if($(obj).hasClass('loadPage')){ loadPage = false; }else{ loadPage = true; } var url = this.href; lastTitle = document.title; if( $(window).width() < 767){ vvDebugg('hide ---'); if($("#navbar-meny").hasClass('collapse in')){ $("#navbar-meny").collapse('hide'); } } currentPage['title'] = title; currentPage['id'] = $(this).attr('idx'); pushScrollHistory[urlKey()] = $(window).scrollTop(); pushState({idx:$(obj).attr('idx'),ID:$(obj).attr('id'),Title:title,LoadPage:loadPage,AjaxBox:false}, title, url); }); }else{ } }); } } } function vvInit(){ if(typeof _mention == "function"){ _mention(); } vvDebugg('++--> init'); $('img.async').each(async function() { $(this).parent().addClass('async-loading'); const imageUrl = $(this).data('src'); const controller = new AbortController(); const signal = controller.signal; try { const imagePromise = loadImageAsync(imageUrl, signal); $(this).data('abortController', controller); const image = await imagePromise; $(this).attr('src', imageUrl); $(this).parent().removeClass('async-loading'); } catch (error) { console.error('Error loading image:', error); // Handle error } }); if(location.href.match(/\#/)){ hash = location.href.split("#"); if(hash[1] == "" || hash[1] == undefined || hash[1] == "#"){ vvDebugg("HASH MISSING"); }else{ $(document).trigger('vvHash'); if($("#"+hash[1]).get(0) != undefined){ if($("#"+hash[1]).hasClass('tab-pane')){ vvDebugg("HASH -> Tab pane -> a[href='#"+hash[1]+"']"); //setTimeout(function(){ $("a[href='#"+hash[1]+"']").trigger('click');},500); $("a:not(.active)[href='#"+hash[1]+"']").trigger('click'); }else{ $("#"+hash[1]).show(); } $("."+hash[1]).hide(); $(body).stop().animate({ scrollTop: $("#"+hash[1]).position().top-20}); } } } //$("[rel=tooltip]").tooltip({ placement: 'right',trigger:'click'}); $('.show-pass').click(function(){ $(this).hide().parent().find('.hide-pass').show(); }); $(".modal-dialog.draggable .modal-content").draggable({ handle:'.dragBox' }); vvUrlInit(); $("input, textarea").on('blur',function(e) { console.log('auto save blur'); if($(this).parents('.form').hasClass('autosave')){ id = $(this).parents('.form').attr('id'); console.log('auto save check'); clearInterval(autoSaveQue["#"+id]); autoSaveQue["#"+id] = setTimeout(function(){ vvDebugg('Auto save ok'+id); $("#"+id).trigger('submit'); clearInterval(autoSaveQue["#"+id]); },800); } }); $(document).on('change', "input[type='checkbox']", function(e) { if($(this).parents('.form').hasClass('autosave')){ id = $(this).parents('.form').attr('id'); clearInterval(autoSaveQue["#"+id]); autoSaveQue["#"+id] = setTimeout(function(){ vvDebugg('Auto save ok ->'+id); $("#"+id).trigger('submit'); clearInterval(autoSaveQue["#"+id]); },800); } $(this).trigger('vvChange'); }); $(document).on('change', "input[type='radio']", function(e) { if($(this).parents('.form').hasClass('autosave')){ id = $(this).parents('.form').attr('id'); clearInterval(autoSaveQue["#"+id]); autoSaveQue["#"+id] = setTimeout(function(){ vvDebugg('Auto save ok ->'+id); $("#"+id).trigger('submit'); clearInterval(autoSaveQue["#"+id]); },800); } $(this).trigger('vvChange'); }); $("select").on('change',function(e) { if($(this).parents('.form').hasClass('autosave')){ id = $(this).parents('.form').attr('id'); clearInterval(autoSaveQue["#"+id]); autoSaveQue["#"+id] = setTimeout(function(){ vvDebugg('Auto save ok ->'+id); $("#"+id).trigger('submit'); clearInterval(autoSaveQue["#"+id]); },800); } $(this).trigger('vvChange'); }); $(".master-form input, .master-form textarea, .master-form select").unbind('keydown').bind('keydown',function(e) { if(!$(this).hasClass('vvMediaSelect') && vvEditInProgress == false){ vvEditInProgress = true; vvDebugg('vvEdit in progress, make edit alert.'); } }); $(".show-hidden").unbind('click').bind('click',function(e){ e.preventDefault(); $(this).hide(); $(this).parent().find('.hidden').show(); }); $(".like").unbind('click').bind('click',function(){ id = parseInt($(this).parent().attr('idx')); t = $(this).parent().attr('type'); $(this).addClass('active'); vvDebugg('- Add class active 4'); vvGetData(path+'?init=vvLike',{idx:id,type:t},function(data){ if(data.success == 1){ } }); }); $(".share .facebook").unbind('click').bind('click',function(e){ e.preventDefault(); var eurl = $(this).parents('.share').attr('ourl'); vvDebugg(eurl); if(eurl == "" || eurl == undefined){ vvDebugg('ourl not set. Backup url.'); eurl = window.location.href; } if (typeof(FB) != 'undefined' && FB != null ) { vvDebugg('FB native'); FB.ui({ method: 'share', href: eurl, }, function(response){}); }else{ //var url = 'https://www.facebook.com/sharer/sharer.php?s=100&u='+encodeURIComponent(eurl); //window.open(url, 'facebook', 'menubar=no,toolbar=no'); } }); $(".share .pinterest-share").unbind('click').bind('click',function(e){ e.preventDefault(); var eurl = $(this).parent().attr('ourl'); url = $(this).parent().attr('urlimage'); if(url == ""){ url = window.location.href; } url = url+'pin/'; var url = 'http://pinterest.com/pin/create/button/?description='+eurl+'&media='+encodeURIComponent(url); window.open(url, 'pinterest', 'menubar=no,toolbar=no'); }); $(".share .twitter").unbind('click').bind('click',function(e){ e.preventDefault(); var eurl = $(this).parents('.share').attr('ourl'); vvDebugg(eurl); if(eurl == "" || eurl == undefined){ vvDebugg('ourl not set. Backup url.'); eurl = window.location.href; } var url = 'https://twitter.com/home?status='+eurl; window.open(url, 'twitter', 'menubar=no,toolbar=no'); }); $(".share .email").unbind('click').bind('click',function(e){ e.preventDefault(); var subject = $(this).parents('.share').attr('subject'); var eurl = $(this).parents('.share').attr('ourl'); if(eurl == "" || eurl == undefined){ url = window.location.href; } document.location.href = "mailto:?subject="+encodeURIComponent(subject)+"&body="+encodeURIComponent(eurl); }); //Overbuttons $("#vvOverlay,#closebtn,.closebtn").unbind('click').bind('click',function(){ vvDebugg('Overbuttons close box'); vvCloseBox(); }); //btn-save $("div.btn-save").unbind('click').bind('click',function(e){ e.preventDefault(); if($(this).hasClass('disabled')){ return false; } vvDebugg('-------->> .div.btn-save :: .form -> trigger submit'); $(this).parents('.form').trigger('submit'); }); // VVSUBMIT $(".form").unbind('submit').bind('submit',function(e) { e.preventDefault(); vvDebugg('-------->> .form :: trigger submit'); vvSubmit(this).then(function(v){ vvDebugg('+++ .form :: submit end.'); }).catch(function(error){ vvDebugg(error); vvDebugg('*** ---> .form :: submit error.'); vvDosubmit = false; }); }); // VVSUBMIT $(".submit").unbind('click').bind('click',function(e) { e.preventDefault(); vvDebugg('-------->> .submit trigger submit'); vvSubmit(this,e).then(function(v){ vvDebugg('++ .submit :: submit end.'); }).catch(function(error){ vvDebugg(error); vvDebugg('*** ---> .submit :: submit error.'); vvDosubmit = false; }); }); $(".submit").unbind('submit').bind('submit',function(e) { e.preventDefault(); vvDebugg('-------->> .submit trigger submit'); vvSubmit(this,e).then(function(v){ vvDebugg('++ .submit :: submit end.'); }).catch(function(error){ vvDebugg(error); vvDebugg('*** ---> .submit :: submit error.'); vvDosubmit = false; }); }); //$("select").vvSelector(); $('._sortable').sortable({ stop: function( ) { $(document).trigger('vvSortableStop'); } }); $(".login").unbind('click').bind('click',function(e) { e.preventDefault(); $(".boxHolder").show(); }); $(".boxHolder").mouseleave(function(e) { $(this).hide(); }); $(".dropdown-menu").unbind('click').bind('click',function(e) { $(this).parent().find('._list').toggle(); }); $(".dropdown-menu ._list").mouseleave(function(e) { $(this).parent().find('._list').hide(); }); $('._showobj').unbind('click').bind('click',function(){ $("#"+$(this).attr('idx')).show(); $("#"+$(this).attr('idx')).mouseleave(function(e) { $(this).hide(); }); }); $(".vvGetData").unbind('click').bind('click',function(e){ e.preventDefault(); if($(this).attr('parms') != undefined){ var obj = eval("("+$(this).attr('parms')+")"); }else{ vvDebugg('No data'); return; } $("#"+obj.idx).vvGetData({url:'/?init='+obj.action,parms:obj,type:"POST"}); }); $(".vvAjaxBox").unbind('click').bind('click',function(e){ e.preventDefault(); if ($(e.target).hasClass("submit")) { return; } if($(this).attr('parms') != undefined){ var obj = eval("("+$(this).attr('parms')+")"); }else{ var obj = {}; } vvDebugg('vvAjaxBox click:'); obj.cc = 'full-width '; $.each($(this).get(0).attributes, function(i, attrib){ var name = attrib.name; var value = attrib.value; if(name.match(/\$/)){ obj[name.substring(1)] = value; } }); if($(this).attr('href') != undefined && $(this).attr('href') != ""){ vvDebugg('loadPage in ajaxbox'); var a = $(this).attr('href'); obj.url = a; obj.vvAjaxRequest = true; obj.boxed = false; obj.AjaxBox = true; obj.LoadPage = false; title = $(this).attr('title'); obj.title = title; //settings.openUrl = location.href; //pushState(obj, title, obj.url); vvAjaxBox(a,obj); }else if($(this).attr('action') != undefined){ vvDebugg('vvAjaxBox action open:'+$(this).attr('action')); var a = $(this).attr('action'); vvAjaxBox(a,obj); } else { vvDebugg('vvAjaxBox no href or action:'); } }); $('.modal-a-boxed .modal-content a').each(function(index, obj) { if(!$(this).hasClass('submit') && !$(this).hasClass('closeBox') ){ $(this).addClass('vvAjaxBoxed'); } }); $(".vvAjaxBoxed").unbind('click').bind('click',function(e){ e.preventDefault(); var obj = {}; var a = $(this).attr('href'); obj.cc = 'full-width modal-a-boxed'; obj.url = a; obj.vvAjaxRequest = true; obj.boxed = true; vvAjaxBox(a,obj); }); $(".timeago").each(function(){ $(this).timeago(); }); $(".pipes").each(function(index, element) { $ch = $(this); if(!$ch.hasClass('pipe-loaded')){ $ch.addClass('pipe-loaded'); ttime = $ch.attr('timeout'); if(ttime == undefined){ ttime = 5000; } vvDebugg('-- Pipes -> Add obj to pipe que, timeout:'+ttime); clearPipsQue($ch.attr('id')); if(ttime != false){ vvPipesQue.push({ id:$ch.attr('id'), time:setInterval("vvPipe('"+$ch.attr('id')+"')",ttime) }); }else{ vvPipesQue.push({ id:$ch.attr('id'), time:false }); } if($ch.hasClass('piprun')){ if($ch.attr('pipeque')){ if(!pipeIsRuning){ pipeIsRuning = true; vvPipe($ch.attr('id')); }else{ $ch.addClass('loading'); vvPipesRunQue.push({ id:$ch.attr('id') }); } }else{ vvPipe($ch.attr('id')); } } } }); if($("._datepicker").get(0) != undefined){ if(!$("._datepicker").hasClass('timepicker')){ $("._datepicker").addClass('timepicker'); $("._datepicker").datepicker({ changeMonth: true, changeYear: true, showButtonPanel: true, dateFormat: 'yy-mm-dd', onClose: function(dateText, inst) { //$(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1)); } }); } } $(document).trigger('vvInitEnded'); $(document).trigger('vvInitExtra'); }// VVINIT SLUT var pipeIsRuning = false; var initCountDown = 10,countDownTimerInit=null; function vvCountDownVVInit(){ initCountDown = 10; clearInterval(countDownTimerInit); countDownTimerInit = setInterval("vvActVVInit()",100); } function vvActVVInit(){ if(initCountDown<=0){ vvInit(); clearInterval(countDownTimerInit); }else{ initCountDown--; } } function clearPipsQue(id){ for(e in vvPipesQue){ if(vvPipesQue[e].id == id){ vvDebugg('*** Pipes: Clear timer for id: #'+vvPipesQue[e].id); clearInterval(vvPipesQue[e].time); vvPipesQue.splice(e,1); } } } /** * ================ $('.sticky-content').StickyDL({ paddingTop : 220, // default is 200 heightRefElement: '.main-content-end-padding', // default is '.main-content-end-padding' optionalBottomFix: 95, // default is 0 optionalTopFix: 0 }) */ (function ( $ ) { $.fn.StickyDL = function(options) { var params = $.extend({ // Default value paddingTop: 100, heightRefElement: '.main-content-end-padding', optionalBottomFix: 0, optionalTopFix: 0 }, options ); if($(this).length>0) { var $window = $(window); var $el = $(this); var elHeight = $el.height(); var elOffsetTop = 0; var currentScrollTop = 0; var stickyWidth = $el.parent().width() + 'px'; // Initialize values initValues(); $window.scroll(function() { processPositions(); }); } function processPositions() { elHeight = $el.height(); stickyWidth = $el.parent().width() + 'px'; if(screen.height > elHeight || screen.width>=992){ var actualScrolltop = $window.scrollTop() + elHeight - params.paddingTop; if(actualScrolltop >= $el.parent().height() + params.paddingTop){ $el.css({"position": "relative"}); $el.offset({"top": currentScrollTop}); }else{ if ($window.scrollTop()>=elOffsetTop){ $el.css({"position": "fixed", "width": stickyWidth}); $el.offset({"top": $window.scrollTop() + params.paddingTop}); currentScrollTop = $window.scrollTop() + params.paddingTop; }else{ $el.css({"position": "static", "width": '100%'}); } } } else { $el.css({"position": "relative", "width": '100%'}); $el.offset({"top": $el.offset().top}) } } function initValues() { elOffsetTop = $el.offset().top - params.paddingTop; } return this; }; }( jQuery )); function slugify(string) { const a = 'àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;'; const b = 'aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnoooooooooprrsssssttuuuuuuuuuwxyyzzz------'; const p = new RegExp(a.split('').join('|'), 'g'); if(typeof string != 'string'){ console.error('slugify function faild. String is not string:',string); return ''; } return string.toString().toLowerCase() .replace(/\s+/g, '-') // Replace spaces with - .replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters .replace(/&/g, '-and-') // Replace & with 'and' .replace(/[^\w\-]+/g, '') // Remove all non-word characters .replace(/\-\-+/g, '-') // Replace multiple - with single - .replace(/^-+/, '') // Trim - from start of text .replace(/-+$/, '') // Trim - from end of text } var vvPipesRunQue = new Array(); var vvPipesQue = new Array(); function vvPipe(id){ vvDebugg('++- Run pipe --> '+id); $ch = $("#"+id); if(!$ch.hasClass('pipe-running')){ $ch.addClass('pipe-running'); }else{ return; } var parms = { idx:id, type:"POST", triggerAfter:"vvPipeTrigger" }; if($ch[0] != undefined){ $.each($ch.get(0).attributes, function(i, attrib){ var name = attrib.name; var value = attrib.value; if(name.match(/\$/)){ parms[name.substring(1)] = value; } }); vvDebugg('--- Pipe: #'+id); vvDebugg(parms); force = 0; if($ch.attr('force') != undefined){ force = 1; } if(parms.path != undefined){ $ch.vvGetData({ url:settings['PIPE_URL']+'?path='+parms.path+'&utoken='+settings['utoken']+'&init='+$ch.attr('action')+'&force='+force, parms:parms, type:parms.type, after:parms.after, triggerAfter:parms.triggerAfter }); }else if(parms.page != undefined){ $ch.vvGetData({ url:settings['PIPE_URL']+parms.page+'?utoken='+settings['utoken']+'&force='+force, parms:parms, type:parms.type, after:parms.after, triggerAfter:parms.triggerAfter }); }else{ $ch.vvGetData({ url:settings['PIPE_URL']+'?utoken='+settings['utoken']+'&init='+$ch.attr('action')+'&force='+force, parms:parms, type:parms.type, after:parms.after, triggerAfter:parms.triggerAfter }); } }else{ clearPipsQue(id); } } var pipes = new Array(); function vvPipes(){ for(var e in pipes){ if(pipes[e].action != undefined){ $(pipes[e].obj).vvGetData({url:'/?init='+pipes[e].action}); } } } var timeBetweenCalls = 50000; // Milliseconds var numberOfCalls = 10; var timesRun = 0; var startTime = new Date().getTime(); $(document).ready(function(e) { setTimeout(function(){ // Lägg till scrolltop on reload vvDebugg('--- Set init scroll --> '+$(window).scrollTop()); pushScrollHistory[urlKey()] = $(window).scrollTop(); },500); $(document).unbind('vvPipeTrigger').bind('vvPipeTrigger',function(e,data,result){ $ch = $("#"+data.parms.idx); $ch.removeClass('pipe-running'); $ch.addClass('pipe-completed'); for(let x = 0; x < vvPipesRunQue.length; x++){ let p = vvPipesRunQue[x]; if(data.parms.idx == p.id){ // Remove vvPipesRunQue[x] from vvPipesRunQue vvPipesRunQue.splice(x, 1); // Stop the for loop after modifying the array break; } } // If the ID was not found, and the queue is not empty, run the next item if (vvPipesRunQue.length > 0) { vvPipe(vvPipesRunQue[0].id); } }); (function vvPipesRun () { var now = new Date().getTime();  if (timesRun <= numberOfCalls) { timesRun++; if(pipes.length>0){ vvPipes(); timeBetweenCalls = timeBetweenCalls+10000; }else{ timeBetweenCalls = 50000; } setTimeout(vvPipesRun, timeBetweenCalls - ((new Date().getTime() - startTime) % timeBetweenCalls)); }else{ timesRun = 0; timeBetweenCalls = 50000; } })(); }); function vvResetAjax(){ var _Data = new Array(); var exclude_arr = new Array(); var vvSort = null; var vvGettingData = false; var listDiv = ""; var teMplateDiv = ""; var teMplateName = ""; var initFunc = ''; var call = ""; $(".listToggler li").unbind('click'); $("#wrapper").removeAttr('class'); } var mousewheelevt=(/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel" //FF doesn't recognize mousewheel as of FF3.x if (document.attachEvent){ //if IE (and Opera depending on user setting) document.attachEvent("on"+mousewheelevt, function(e){ $(document).trigger('vvScroll',e); }); } else if (document.addEventListener){ document.addEventListener(mousewheelevt, function(e){ $(document).trigger('vvScroll',e); }, false); } $(window).scroll(function(){ $(document).trigger('vvScroll'); }); $(document).bind('vvScroll',function(){ pushScrollHistory[urlKey()] = $(window).scrollTop(); }); function getData(parms){ vvDebugg(parms); vvDosubmit = true; storeRequest( $.ajax({ url:parms.url, data:parms, type:'POST', dataType:"JSON", beforeSend: function(){ vvLoadShow(); }, complete: function(data){ vvDosubmit = false; vvLoadHide(); }, success: function(data){ if(parms.callback != undefined){ parms.callback(data); } $(document).trigger('vvGetDataCollected'); } }) ); } function vvGetData(aUrl,parms,callback,error){ vvDosubmit = true; storeRequest( $.ajax({ url:aUrl, data:parms, type:'POST', dataType:"JSON", beforeSend: function(){ vvLoadShow(); }, complete: function(data){ vvDosubmit = false; vvLoadHide(); if(typeof data.responseJSON == 'object'){ if(data.responseJSON != undefined){ data = data.responseJSON; } } callback(data); $(document).trigger('vvGetDataCollected'); }, success: function(data){ }, error: function(xhr, status, error){ if(typeof error == 'function'){ error(xhr, status, error); } } }) ); } // ---------------- PUSH STATE NAVIGATION ------------------ // $(window).on('load',function(e) { if ("pushState" in history) { if(settings['URL_PUSH']){ settings['URL_PATH'] = location.href; window.onpopstate = function(e) { vvDebugg('------------ POP STATE -------------'); vvDebugg(e.state); if(vvEditInProgress){ if(!confirm(lang.admin['edit-in-progress'])){ return; } } if(e.state == null){ e = {state:{AjaxBox:false,LoadPage:true}}; } if(e.state.tab){ e.preventDefault(); vvDebugg('+++ TAB -> *[href="'+e.state.href+'"]'); if($('*[href="'+e.state.href+'"]').length == 0){ vvLoadPage(location.href, e.state, true); }else{ $('*[href="'+e.state.href+'"]').tab('show'); } return false; } if(e.state.AjaxBox){ vvDebugg('+++ OPEN IN AJAXBOX'); settings.AjaxBox = true; settings.AjaxBoxCount = 1; vvAjaxBox(e.state.url,e.state); }else if(settings.AjaxBox){ vvDebugg('*** AJAX BOX IS OPEN CLOSE IT -'); settings.AjaxBox = false; settings.AjaxBoxCount = 0; $('.modal').modal('hide'); }else{ vvDebugg('++ LOAD PAGE'); vvDebugg(location.href); vvLoadPage(location.href, e.state, true); } }; }else{ window.onpopstate = function(e) { top.location =location.href; }; } } }); var pushScrollHistory = new Array() function pushState(data, title, url) { if ("pushState" in history) { vvDebugg('--- Push state'); history.pushState(data, title, url); if(data.AjaxBox){ settings.AjaxBox = true; settings.AjaxBoxCount = 0; vvDebugg('------------ OPEN IN AJAX BOX -------------'); } if(settings.AjaxBox && data.AjaxBox !== true){ vvDebugg('------------ Try to open regual page -------------'); }else if(settings.AjaxBox && data.AjaxBox){ vvDebugg('------------ Open new ajax box -------------'); settings.AjaxBoxCount++; }else{ vvLoadPage(location.href, data, false); } if(data.ForceClose){ settings.AjaxBox = false; settings.AjaxBoxCount = 0; } }else{ top.location = url; } } var lastPageReload = null; var lastPageTime = 2; function vvLoadPage(url, state, history, scroll = true){ vvDebugg('--- vvLoadPage >> '+url); $(document).trigger('vvPageChange',state); var _opened = $(".navbar-collapse").hasClass("in"); if (_opened === true) { $("button.navbar-toggle").click(); } if(!settings['URL_PUSH']){ vvDebugg('*** URL_PUSTH false'); return; } settings['URL_PATH'] = url; vvDebugg('---------------------------------------------------------------------------------------------------'); if(state != null){ vvDebugg('--- vvLoadPage >> Title >> '+settings['TITLE']+" - "+state.Title); if(state.Title != undefined){ if(state.Title == ""){ document.title = HtmlDecode(settings['TITLE']); }else{ document.title = HtmlDecode(settings['TITLE']+" - "+state.Title); } }else{ document.title = HtmlDecode(settings['TITLE']); } if(history){ if(state.ID != undefined){ vvDebugg('-- Remove _active by state.'); $('._active').removeClass('_active'); $('.nav-main-header .open').removeClass('open'); vvDebugg('-- Add to $(".menu-link-'+state.idx+'").addClass("_active")'); $(".menu-link-"+state.idx).addClass('_active'); currentPage['id'] = state.idx; } } }else{ } // Aktuell sida title currentPage['title'] = document.title; // Track url vvTrackUrl(url); // Om sidan inte ska ändra innehåll if(state != null){ if(state.LoadPage == false){ if(history){ if($("#"+state.ID).get(0) != undefined){ $("#"+state.ID).trigger('click'); } } vvEditInProgress = false; return; } } storeRequest( $.ajax({ url:url, data:{vvAjaxRequest:true}, type:'GET', dataType:"HTML", async:true, beforeSend: function(){ vvLoadShow(); }, complete: function(data){ vvLoadHide(); }, success: function(response, status, xhr ){ if ( status == "error" ) { window.history.back(); setTimeout(function(){ var msg = "Sorry but there was an error: "; $("#content,#main-container ").prepend(''); },500); }else{ if(IsJsonString(response)){ response = JSON.parse(response); if(!response.success){ top.location.reload(); return; } } vvEditInProgress = false; vvResetAjax(); $('nav#menu').trigger('close'); $("#content,#main-container").stop().fadeOut(100,function(){ $("#content,#main-container").html(response); $("#content,#main-container").stop().fadeIn(300,'easeInCubic'); }); //$("#content,#main-container").html(response); hash = url.split('#'); if((hash[1] != "" || hash[1] != undefined || hash[1] != "#") && $("#"+hash[1]).get(0) != undefined ){ vvDebugg('--- Scroll to HASH'); $('body,html').stop().animate({ scrollTop: $("#"+hash[1]).position().top}); }else{ if(pushScrollHistory[urlKey()] == undefined || noScrollHistory == true){ pushScrollHistory[urlKey()] = 0; } vvDebugg('--- Scroll to '+urlKey()+' >> '+pushScrollHistory[urlKey()]); $('body,html').stop().animate({ scrollTop: pushScrollHistory[urlKey()]+"px" },500); } vvDebugg('--- vvPageLoad trigger'); $(document).trigger('vvPageLoad'); $(document).trigger('vvInit'); } } }) ); } function urlKey(){ var key = slugify(window.location.pathname+'-'+window.location.search); if(key == ""){ key = "root"; } return key; } function stripTrailingSlash(str) { if(str.substr(-1) == '/') { return str.substr(0, str.length - 1); } return str; } function vvTrackEvent(e,en,ene,value){ if(typeof _gaq !== 'undefined'){ _gaq.push(['_trackEvent', e, en, ene, value]); vvDebugg('--- _trackEvent'); }else{ } } function vvTrackUrl(url){ if(typeof _gaq !== 'undefined'){ url = url.replace(settings['HOST'],''); vvDebugg('Track url:'+url); _gaq.push(['_trackPageview', url]); } } // ---------------- VVBOX functions ------------------ // function vvCloseBox(){ vvDebugg('vvCloseBox close box'); settings['_vvBoxStatus'] = 'closed'; if(settings['URL_PATH'] != null){ temp = settings['URL_PATH'].split('#'); settings['URL_PATH'] =temp[0]+'#s'; openImage = null; //top.location = settings['URL_PATH']; } $("#vvOverlay").hide(); $("#vvBox").hide(); $("#vvBox #ajaxhtml").html(''); $("#_body").removeClass('_filter-blur'); $(document).trigger('vvBoxClosed'); } // Remove the ugly Facebook appended hash // if (window.location.hash && window.location.hash === "#_=_") { // If you are not using Modernizr, then the alternative is: // `if (window.history && history.pushState) {` if (Modernizr.history) { window.history.pushState("", document.title, window.location.pathname); } else { // Prevent scrolling by storing the page's current scroll offset var scroll = { top: document.body.scrollTop, left: document.body.scrollLeft }; window.location.hash = ""; // Restore the scroll offset, should be flicker free document.body.scrollTop = scroll.top; document.body.scrollLeft = scroll.left; } } var ajaxBoxSettings = new Array; function vvAjaxBox(f,parms){ vvDebugg('++ vvAjaxBox -> open ajax box'); vvDebugg(parms); vvLoadShow(); vvTrackUrl(location.href); var url = path+'?init='+f; var modal = "#vvModal"; if($("#vvModal")[0] == undefined){ vvDebugg('#vvModal is undefined'); return; } //Reset modal dialog class $("#vvModal .modal-dialog").attr('class','modal-dialog'); if(parms != undefined){ if(parms.ccid != null){ $("#vvModal .modal-dialog").attr('id',parms.ccid); } if(parms.cc != null){ $("#vvModal .modal-dialog").addClass(parms.cc); } }else{ parms = {}; } if(parms.modal != null){ modal = parms.modal; } if(parms.url != undefined){ url = parms.url; } parms.vvAjaxRequest=true; vvDebugg(url); vvDebugg(parms); $(modal+'.modal .modal-content').removeClass('ui-draggable').attr('style',' '); $(document).unbind('vvCloseBox').bind('vvCloseBox', function () { $(modal+'.modal').modal('hide'); }); $(modal+'.modal').on('hidden.bs.modal', function () { vvDebugg('--- modal box hidden'); $(document).trigger('vvBoxClosed'); }); $(modal+'.modal').unbind('hide.bs.modal').bind('hide.bs.modal', function (e) { if(vvEditInProgress){ if(!confirm(lang.admin['edit-in-progress'])){ e.preventDefault(); return; }else{ vvEditInProgress = false; } } $(modal+'.modal .modal-content').html(""); vvDebugg('*** vvAjaxBox -> modal box hide'); $(document).trigger('vvBoxHide'); if(settings.AjaxBox){ if(settings.openUrl == undefined){ settings.openUrl = "/"; } pushState({LoadPage:true,AjaxBox:false,ForceClose:true},"",settings.openUrl); } }); parms.vvModal = true; ajaxBoxSettings['modal'] = modal; ajaxBoxSettings['url'] = url; ajaxBoxSettings['parms'] = parms; $.post(url,parms,function(data,status,xhr){ var ct = xhr.getResponseHeader("content-type") || ""; if (ct.indexOf('json') > -1) { vvDebugg('-- vvAjaxBox -> JSON RESPONSE'); vvDebugg(data); if(!data.success){ $(document).trigger('vvAjaxFailed',data); vvDebugg('*** vvAjaxBox- > Data success = false'); vvLoadHide(); return; } } $(modal+'.modal').modal('show'); vvDebugg('-- vvAjaxBox -> show vvModal add content'); vvLoadHide(); $(modal+'.modal .modal-content').html(data); $(document).unbind('vvReloadAjax').bind('vvReloadAjax',function(){ reloadAjaxBox(); }); $(document).trigger('vvAjaxBoxOpen'); $(document).trigger('vvInit'); setTimeout(function(){ $(document).trigger('vvModalLoaded'); },500); $('.closeBox, .btn-close').unbind('click').bind('click', function () { $(document).trigger('vvCloseBox'); }); }); } function reloadAjaxBox(){ vvDebugg('++++ vvReloadAjax'); $.post(ajaxBoxSettings['url'],ajaxBoxSettings['parms'],function(data,status,xhr){ var ct = xhr.getResponseHeader("content-type") || ""; if (ct.indexOf('json') > -1) { vvDebugg('-- vvAjaxBox -> JSON RESPONSE'); vvDebugg(data); if(!data.success){ $(document).trigger('vvAjaxFailed',data); vvDebugg('*** vvAjaxBox- > Data success = false'); return; } } $(ajaxBoxSettings['modal']+'.modal').modal('show'); vvDebugg('-- vvAjaxBox -> show vvModal add content'); $(ajaxBoxSettings['modal']+'.modal .modal-content').html(data); $(document).trigger('vvInit'); setTimeout(function(){ $(document).trigger('vvModalLoaded'); },500); $('.closeBox, .btn-close').unbind('click').bind('click', function () { $(document).trigger('vvCloseBox'); }); }); } function vvHtmlBox(html){ vvRemoveArrow(); vvCheckBox(); $("#ajaxloading").hide(); $("#vvBox #ajaxhtml").html(''); $("#vvBox").fadeIn('fast'); $("#vvOverlay").fadeIn('slow'); $("#vvBox #ajaxhtml").html(html); settings['_vvBoxStatus'] = 'open-html'; } // ---------------- other functions ------------------ // function validEmail(e) { var filter = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/; return String(e).search (filter) != -1; } function vvslug(str) { var d = {"å": "a","ä": "a","ö": "o","Å": "a","Ä": "a","Ö": "o"}; str = str.replace(/[åäöÅÄÖ]/ig, function(s) { return d[s]; }); return str.replace(/[^a-z0-9]+/gi, '-').replace(/^-*|-*$/g, '').toLowerCase(); } var vvSubmitIndex = 10; var vvSubmitObj = null; var CountDownTimer = null; function vvSubmitQue(obj){ vvSubmitIndex = 10; vvSubmitObj = obj; clearInterval(CountDownTimer); CountDownTimer = null; if(CountDownTimer == null){ CountDownTimer = setInterval("setCountDownTimer()",200); } } function setCountDownTimer(){ if(vvSubmitIndex>0){ vvDebugg(vvSubmitIndex); vvSubmitIndex--; }else{ clearInterval(CountDownTimer); ountDownTimer = null; vvSubmit(vvSubmitObj); } } var vvSendingImage = false; var vvSend = false; var vvCurrentForm; var curHtml = ""; async function vvSubmit(This,e){ vvDebugg('++- vvSubmit'); $(This).trigger('vvClick'); if(!vvDosubmit){ vvDosubmit = true; _form = $(This); idx = $(This).attr('idx'); $(document).trigger("beforeSubmit",This); if(_form.hasClass('only-changes')){ if(_change[idx] == null || _change[idx].length == 0){ vvDosubmit = false; console.warn('form not submited'); return; } } vvDebugg('++- vvSubmit LOCK'); obj = $(This); if(!_form.hasClass('autosave')){ obj.parent().addClass('_progress'); }else{ obj.parent().addClass('_autosave-progress'); } vvDebugg('++- idx: '+idx); if(_form.hasClass('disable-on-save')){ _form.addClass('sending'); _form.find('input,textarea,select,button').addClass('disabled-by-form'); } if(_form.hasClass('only-changes')){ var parms = {}; for(i in _change[idx]){ parms[i] = $("."+idx+"[name='"+i+"']").vvSerialize()[i]; } var _defaults = $(".default."+idx).vvSerialize(); for(i in _defaults){ parms[i] = _defaults[i]; } }else{ if($("."+idx).length == 0){ parms = {idx:idx}; }else{ parms = $("."+idx).vvSerialize(); } } if(typeof grecaptcha != 'undefined'){ parms.gtoken = await grecaptcha.execute(settings.google_site_key, {action: 'submit'}).then(function(token) { return token; }); } $.each(This.attributes, function(i, attrib){ var name = attrib.name; var value = attrib.value; if(name.match(/\$/)){ parms[name.substring(1)] = value; } if(name.match(/data-/)){ parms[name.substring(5)] = value; } }); if($(This).hasClass('no-clear')){ parms.noClear = true; } if(!$(This).hasClass('noreq')){ for (var key in parms) { if(typeof parms[key] == 'string'){ if(parms[key].indexOf('_alert') == 0){ alert(decodeURIComponent(parms[key].replace('_alert',''))); return; } } if(parms[key] == '_empty'){ vvDosubmit = false; $(document).trigger('vvInit'); return; } } } if($(this).attr('parms') != undefined){ var data_parms = eval("("+$(This).attr('parms')+")"); for(e in data_parms){ parms[e] = data_parms[e]; } } if($(This).attr('path') != undefined && $(This).attr('path') != ""){ aUrl = $(This).attr('path'); action = $(This).attr('path'); }else{ action = $(This).attr('action'); aUrl = path+'?init='+action; } if(action == 'special'){ window.open(aUrl+'&'+parms); return; } if(!_form.hasClass('autosave')){ if(!$(This).is('form')){ $(This).parents('block').addClass('block-mode-loading'); }else{ $(This).addClass('loading-form'); } }else{ parms.autosave = true } if($(This).attr('http_path') !== undefined){ parms.http_path = location.pathname; } // Debugg vvDebugg(parms); vvDebugg(aUrl); if($(This).attr('confirm') != undefined){ confirm = $(This).attr('confirm'); }else{ confirm = 'Are you sure you want to continue?'; } if($(This).hasClass('confirm')){ //Confirm == #confirm if( (confirm.charAt(0) == '.' || confirm.charAt(0) == "#") && $(confirm).get(0) != undefined){ confirm_text = $($(This).attr('confirm')).html(); confirm_text = parmsReplace(confirm_text,parms); confirm_text = urldecode(confirm_text); confirm = $("
").html(confirm_text).get(0); if(!(await swal({ content: confirm, icon: "info", buttons: true, html:true }).then((value) => { if(value){ return true; }else{ vvDebugg('***- vvSubmit CANCEL'); $("._autosave-progress").removeClass('_autosave-progress'); $('._progress').removeClass('_progress'); $('.loading-form').removeClass('loading-form'); $('.block-mode-loading').removeClass('block-mode-loading'); vvDosubmit = false; _confirm = false; return false; } }) )){ return; } }else { if(!(await swal({ title: confirm, icon: "info", buttons: true }).then((value) => { if(value){ return true; }else{ vvDebugg('***- vvSubmit CANCEL'); $("._autosave-progress").removeClass('_autosave-progress'); $('._progress').removeClass('_progress'); $('.loading-form').removeClass('loading-form'); $('.block-mode-loading').removeClass('block-mode-loading'); vvDosubmit = false; _confirm = false; return false; } }) )){ return; } } } storeRequest( $.ajax({ url:aUrl+'&vvAjaxSubmit=true', data:parms, type:'POST', dataType:"JSON", timeout: 50000, beforeSend: function(){ $(document).trigger('vvSendEventBefore'); if(!_form.hasClass('autosave')){ vvLoadShow(); } }, complete: function(data){ $(document).trigger('vvSendEventComplete',data); vvDosubmit = false; vvDebugg('++- submit complete'); }, error: function(x, t, m) { if(_form.hasClass('disable-on-save')){ _form.removeClass('sending'); _form.find('input,textarea,select,button').removeClass('disabled-by-form'); } if(t==="timeout") { setTimeout(function(){ vvEditInProgress = false; $(document).trigger('vvCloseBox'); vvLoadPage(location.href,{},true); $(document).trigger('vvReloadPage'); },1000); } $("._autosave-progress").removeClass('_autosave-progress'); $('._progress').removeClass('_progress'); if(!$(This).is('form')){ $(This).parent().parent().removeClass('loading-form'); }else{ $(This).removeClass('loading-form'); } vvDebugg('***- submit error'); vvDebugg(x); vvDosubmit = false; vvEditInProgress = false; }, success: function(data){ vvDebugg('++ submit success'); vvDebugg(data); if(typeof data == 'object'){ if(data.success != undefined){ if(data.success == false || data.success <= 0){ vvLoadHide(); if(_form.hasClass('disable-on-save')){ _form.removeClass('sending'); _form.find('input,textarea,select,button').removeClass('disabled-by-form'); } $(document).trigger('vvAjaxFailed'); }else{ console.log(_change[_form.attr('idx')]); _form.removeClass('_hasChange'); for(x in _change[_form.attr('idx')] ){ obj = $("#"+x); try { obj.attr('defvalue',obj.val()); } catch (error) { console.log(typeof obj.val(),obj.attr('name'),error); } try { obj.attr('deflength',obj.val().length); } catch (error) { console.log(typeof $(this).val(),$(this).attr('name'),error); } obj.removeClass('_vvChange'); delete _change[_form.attr('idx')][x]; } $(document).trigger('vvAjaxSuccess'); } }else{ console.warn('vvSubmit response success missing'); } } vvEditInProgress = false; if(data == undefined){ alert('*** vvSubmit -> No data returned'); return; } $(document).trigger('submit-complete',{success:data.success}); $("._autosave-progress").removeClass('_autosave-progress'); $('._progress').removeClass('_progress'); if(!$(This).is('form')){ $(This).parent().parent().removeClass('loading-form'); }else{ $(This).removeClass('loading-form'); } if(data.captcha != undefined){ if(data.captcha == "1"){ $(".captcha_input").hide(); $("#file-uploader").show(); } } if(data.action != undefined){ vvReturnDataAction(data); } } }) ); } } function vvReturnDataAction(data){ if(data.action == undefined){ vvDebugg('-- vvReturnDataAction failed -> data.action undefined'); return; } var pattern = /(timeouturl|timeoutreload|url|wait|block-loading)/i; if(!pattern.test(data.action)){ vvLoadHide(); } pattern = /(block-loading)/i; if(pattern.test(data.action)){ settings['block-loading'] = true; } dataAction = data.action.split('|'); for(var a in dataAction){ action = dataAction[a]; vvDebugg('-- '+action); if(action == 'download'){ window.location = HtmlDecode(data.file); vvMsgBox('Download success','msgbox',2000,'success'); } if(action == 'clearLocalstorage'){ if(localStorage != undefined){ localStorage.clear(); } } if(action == 'empty_reload'){ if(($("#vvModal.modal").data('bs.modal') || {}).isShown){ $("#vvModal.modal").modal('show'); $("#vvExtraModal.modal").hide(); $('#vvModal.modal').on('hide.bs.modal', function () { $("#vvExtraModal.modal").modal('hide'); }); }else{ $("#vvExtraModal.modal").modal('hide'); } } if(action == 'reload'){ window.location.reload(); } if(action == 'timeoutreload'){ setTimeout(function(){ window.location.reload(); },2000); } if(action == 'timeoutclose'){ setTimeout(function(){ vvEditInProgress = false; $(document).trigger('vvCloseBox'); vvLoadPage(location.href,{},true); $(document).trigger('vvReloadPage'); },1000); } if(action == 'root'){ top.location = "/"; } if(action == 'hideshow' || action == 'showhide'){ $(data.hide).hide(); $(data.show).show(); } if(action == 'hideFile'){ $("#file-"+idx).fadeOut(300, function() { $(this).remove(); }); } if(action == 'popupurl'){ if(data.url != "" && data.url != 'reload'){ popUpWindow = window.open(HtmlDecode(data.url),"popUpWindow","width=700,height=500,toolbar=0,scrollbars=0,status=0,resizable=0,location=0,menuBar=0"); } } if(action == 'move_to'){ clone = obj.parent().parent().clone(); clone.attr('db',data.mote_to_id_t); clone.attr('cat',data.mote_to_id_t); obj.parent().parent().remove(); $(data.mote_to_id).append(clone); $(document).trigger('vvInit'); } if(action == 'timeouturl'){ if(data.url == undefined){ } if(data.url != "" && data.url != 'reload' && data.url != undefined){ setTimeout(function(){ top.location = HtmlDecode(data.url); },2000); }else{ if(data.url == 'reload'){ $(document).trigger('vvReload'); } } } if(action == 'timeoutreload'){ setTimeout(function(){ top.location.reload(); },2000); } if(action == 'vvbox' || action == 'vvAjaxBox'){ if(data.url != ""){ if(data.parms != undefined){ vvAjaxBox(HtmlDecode(data.url),data.parms); }else{ vvAjaxBox(HtmlDecode(data.url),{}); } }else{ alert('*** Url is empty'); } } if(action == 'url'){ if(data.url != ""){ top.location = HtmlDecode(data.url); } } if(action == 'push'){ if(data.url != undefined){ pushState({idx:data.idx,ID:data.id,Title:data.title,LoadPage:true,AjaxBox:false}, data.title, data.url); } } if(action == 'reloadCaptcha'){ grecaptcha.reset(); } if(action == 'msgbox_arr'){ for(var e in data.msg){ if(data.msg[e] != null){ if(data.msg[e].body != null){ vvMsgBox(HtmlDecode(data.msg[e].body),'msgbox',data.msg[e].time,data.msg[e].type,HtmlDecode(data.msg[e].subject)); }else if(data.msg[e].msg != undefined){ vvMsgBox(HtmlDecode(data.msg[e].msg),'msgbox',undefined,data.sys_response,HtmlDecode(data.subject)); }else{ vvMsgBox(HtmlDecode(data.msg[e]),'msgbox',2000,'warning',HtmlDecode(data.msg[e].subject)); } } } } if(action == 'swal'){ swal({ text: data.msg, icon: data.icon, buttons: { cancel: "OK", }, }).then((value) => { }) } if(action == 'modal'){ if(data.id != null){ modal = $("#"+data.id); $("#"+data.id).remove(); $("#body").append(modal); modal.modal('show'); } } if(action == 'modal-hide'){ if(data.id != null){ $("#"+data.id).modal('hide'); } } if(action == 'msg'){ if(data.msg != null && data.msg.body != undefined){ vvDebugg(HtmlDecode(data.msg.body)); alert(HtmlDecode(data.msg.body)); } } if(action == 'msgbox'){ if(data.msg != null){ if(data.msg.body != null){ vvMsgBox(HtmlDecode(data.msg.body),'msgbox',data.msg.time,data.msg.type,HtmlDecode(data.msg.subject)); }else{ vvMsgBox(HtmlDecode(data.msg),'msgbox',undefined,data.sys_response,HtmlDecode(data.subject)); } }else{ } } if(action == 'hide'){ $("."+idx).parent().fadeOut('fast'); } if(action == 'curhide'){ $("."+idx).fadeOut('fast'); } if(action == 'html'){ _form.html(''+data.msg.body+''); } if(action == 'fade'){ $("."+idx).parent().parent().fadeTo(100,0.5); $("."+idx).parent().parent().find('textarea,input,select').prop('readOnly', true); $("."+idx).parent().parent().find('.btn').remove(); } if(action == 'fadethis'){ $("."+idx).fadeTo(100,0.5); } if(action == 'remove'){ $("."+idx).parent().remove(); $("._item-"+idx).parent().remove(); $(document).trigger('vvInit'); } if(action == 'reloadajax'){ $(document).trigger('vvReloadAjax'); } if(action == 'reloadpage'){ vvLoadPage(location.href,{},true); $(document).trigger('vvReloadPage'); } if(action == 'timeout-reloadpage'){ setTimeout(function(){ vvLoadPage(location.href,{},true); $(document).trigger('vvReloadPage'); },2000); } if(action == 'toggle'){ $("."+idx).animate({height:0},500,function(){ $(this).remove(); }); $(document).trigger('vvInit'); } if(action == 'trigger'){ if(data.trigger == undefined){ alert('No trigger data'); } trigger = data.trigger.split('|'); for(t in trigger){ $(document).trigger(trigger[t],data); } $(document).trigger(data.trigger,data); } if(action == 'triggertimeout'){ if(data.trigger == undefined){ alert('No trigger data'); } setTimeout(function(){ $(document).trigger(data.trigger); },2000); } if(action == 'removethis'){ $("."+data.idx).remove(); $(document).trigger('vvInit'); } if(action == 'clearfiled'){ $(data.clear).val(''); } if(action == 'clear'){ $("."+data.c).val(''); $("._form").find('._preview').html(''); $(".reset").trigger('click'); $(document).trigger('vvPost'); } } if(data.trigger != undefined){ for(var a in data.trigger){ trigg = data.trigger[a]; $(document).trigger(trigg); } } if(data.empty){ $("."+idx).each(function(index, element) { if($(this).attr('type') == 'text' || $(this).attr('password')){ $(this).val(''); } }); } if(data.clear){ $("."+idx).val(''); $("._form").find('._preview').html(''); $(".reset").trigger('click'); $(document).trigger('vvPost'); } } function arrayCompare(a1, a2) { if (a1.length != a2.length) return false; var length = a2.length; for (var i = 0; i < length; i++) { if (a1[i] !== a2[i]) return false; } return true; } function inArray(needle, haystack) { var length = haystack.length; for(var i = 0; i < length; i++) { if(typeof haystack[i] == 'object') { if(arrayCompare(haystack[i], needle)) return true; } else { if(haystack[i] == needle) return true; } } return false; } function getOffsetSum(elem) { var top=0, left=0; while(elem) { top = top + parseInt(elem.offsetTop); left = left + parseInt(elem.offsetLeft); elem = elem.offsetParent; } return {top: top, left: left}; } /* ---------------------------------- VV SUBMIT FORM --------------- */ function vvMsgClose(id){ $("."+id).addClass('fadeOut').animate({height:0,paddingTop:0,paddingBottom:0,marginBottom:0,marginTop:0},500,function(){ $("."+id).remove(); }); } var msgBoxTimeout = null; function vvMsgBox(msg,bind,time,type,subject,params){ if(type == undefined){ type = "info"; } vvDebugg('++ msgbox->'+type+'->'+time+'->'+subject); if(time == undefined){ time = 1000; } if(subject == undefined ||subject == ""){ subject = lang['admin']['default-ajax-subject']; } var di = Math.floor(Math.random()*10000); var i = 0; if(bind != undefined){ if(bind != null){ $(document).unbind(bind); } } var notify_params = { type: type, placement: { from: "top", align: "right" }, delay:time, offset:40, showProgressbar:true, template: '' }; for(i in params){ notify_params[i] = params[i]; } if(Array.isArray(msg) || (typeof msg === 'object' && msg !== null)){ for(i in msg){ if(Array.isArray(msg[i]) || (typeof msg[i] === 'object' && msg[i] !== null)){ _msg = ""; for(j in msg[i]){ _msg = _msg+parmsReplace(msg[i][j].toString(),notify_params); } }else{ _msg = parmsReplace(msg[i].toString(),notify_params); } if(typeof jQuery.notify == "function"){ vvDebugg('notify'); jQuery.notify({ title: subject, message: _msg },notify_params); } } if(typeof jQuery.notify == "function"){ return; } }else{ msg = parmsReplace(msg,notify_params); if(typeof jQuery.notify == "function"){ vvDebugg('notify'); jQuery.notify({ title: subject, message: msg },notify_params); return; } } $(".msgbox").each(function(index, element) { i++; var did = di+'_'+i; var $msg = $(''); //var $msg = $(''); $(this).fadeIn().append($msg); $msg.data('created',Math.round(new Date().getTime()/1000)); $msg.find('.gritter-close').unbind('click').bind('click',function(e){ e.preventDefault(); vvMsgClose( $(this).parents('.gritter-item-wrapper').attr('idx') ); }); setTimeout("vvMsgClose('"+did+"')",time); if(bind != undefined){ if(bind != null){ $(document).bind(bind,{ id: did },function(event){ var data = event.data; var now = Math.round(new Date().getTime()/1000); var elp = now-$("."+data.id).data('created'); if(elp>-1){ vvDebugg(elp); setTimeout("vvMsgClose('"+data.id+"')",1000); }else{ $("."+data.id).slideToggle('slow',function(){ $(this).remove(); }); } }); } } }); } function doModal(heading, contentId) { vvDebugg('doModal'); var formContent = $("#"+contentId).html(); vvDebugg(formContent); formContent = '
'+HtmlDecode(formContent)+'
'; $("#vvExtraModal.modal").show(); $("#vvExtraModal.modal .modal-content").html( formContent ); $("#vvExtraModal.modal").modal(); $(document).trigger('vvInit'); setTimeout(function(){ $(document).trigger('vvModalLoaded'); },500); $('.closeBox').unbind('click').bind('click', function () { $(document).trigger('vvCloseBox'); }); } function isNumeric(n) { return !isNaN(parseFloat(n)) && isFinite(n); } function removeSpaces(string) { return string.split(' ').join(''); } function sortItemsByVal(listItem,listDiv,searchClass){ if($(listDiv).attr('invert') == 1){ invertIs = 0; $(listDiv).attr('invert',0); }else{ invertIs = 1; $(listDiv).attr('invert',1); } $items = $(listDiv).find(listItem); $items_sort = new Array; var i = 0; $items.each(function(){ $items_sort[i] = new Array(); $items_sort[i]['val'] = removeSpaces($(this).find("."+searchClass).text()); $items_sort[i]['html'] = $(this).clone(); i++; }); $items_sort.sort(function(a,b){ if(!isNaN(a['val']) && !isNaN(b['val'])){ var aT = parseFloat(a['val']); var bT = parseFloat(b['val']); if(invertIs == 1){ return aT - bT; }else{ return bT - aT; } }else{ var aT = a['val'].toLowerCase(); var bT = b['val'].toLowerCase(); if(invertIs == 1){ return ((aT < bT) ? -1 : ((aT > bT) ? 1 : 0)); }else{ return ((bT < aT) ? -1 : ((bT > aT) ? 1 : 0)); } } }); $(listDiv).html(''); for(var e = 0;e<$items_sort.length;e++){ $(listDiv).append($items_sort[e]['html']); }; } /* * Date Format 1.2.3 * (c) 2007-2009 Steven Levithan * MIT license * * Includes enhancements by Scott Trenda * and Kris Kowal * * Accepts a date, a mask, or a date and a mask. * Returns a formatted version of the given date. * The date defaults to the current date/time. * The mask defaults to dateFormat.masks.default. */ var dateFormat = function () { var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g, timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g, timezoneClip = /[^-+\dA-Z]/g, pad = function (val, len) { val = String(val); len = len || 2; while (val.length < len) val = "0" + val; return val; }; // Regexes and supporting functions are cached through closure return function (date, mask, utc) { var dF = dateFormat; // You can't provide utc if you skip other args (use the "UTC:" mask prefix) if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) { mask = date; date = undefined; } // Passing date through Date applies Date.parse, if necessary date = date ? new Date(date) : new Date; if (isNaN(date)) throw SyntaxError("invalid date"); mask = String(dF.masks[mask] || mask || dF.masks["default"]); // Allow setting the utc argument via the mask if (mask.slice(0, 4) == "UTC:") { mask = mask.slice(4); utc = true; } var _ = utc ? "getUTC" : "get", d = date[_ + "Date"](), D = date[_ + "Day"](), m = date[_ + "Month"](), y = date[_ + "FullYear"](), H = date[_ + "Hours"](), M = date[_ + "Minutes"](), s = date[_ + "Seconds"](), L = date[_ + "Milliseconds"](), o = utc ? 0 : date.getTimezoneOffset(), flags = { d: d, dd: pad(d), ddd: dF.i18n.dayNames[D], dddd: dF.i18n.dayNames[D + 7], m: m + 1, mm: pad(m + 1), mmm: dF.i18n.monthNames[m], mmmm: dF.i18n.monthNames[m + 12], yy: String(y).slice(2), yyyy: y, h: H % 12 || 12, hh: pad(H % 12 || 12), H: H, HH: pad(H), M: M, MM: pad(M), s: s, ss: pad(s), l: pad(L, 3), L: pad(L > 99 ? Math.round(L / 10) : L), t: H < 12 ? "a" : "p", tt: H < 12 ? "am" : "pm", T: H < 12 ? "A" : "P", TT: H < 12 ? "AM" : "PM", Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""), o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4), S: ["", "", "", ""][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10] }; return mask.replace(token, function ($0) { return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1); }); }; }(); // Some common format strings dateFormat.masks = { "default": "ddd mmm dd yyyy HH:MM:ss", shortDate: "m/d/yy", mediumDate: "mmm d, yyyy", longDate: "mmmm d, yyyy", fullDate: "dddd, mmmm d, yyyy", shortTime: "h:MM TT", mediumTime: "h:MM:ss TT", longTime: "h:MM:ss TT Z", isoDate: "yyyy-mm-dd", isoTime: "HH:MM:ss", isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" }; // Internationalization strings dateFormat.i18n = { dayNames: [ "Sön", "Mån", "Tis", "Ons", "Tor", "Fre", "Lör", "Söndag", "Måndag", "Tisdag", "Onsdag", "Torsdag", "Fredag", "Lördag" ], monthNames: [ "Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec", "Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December" ] }; // For convenience... Date.prototype.format = function (mask, utc) { return dateFormat(this, mask, utc); }; function scrollFX() { var $window = $(window), scrollTop = $window.scrollTop(), windowHeight = $window.height(), windowWidth = $window.width(), $boxes = $('[data-scroll-speed]'); $bgboxes = $('[data-bg-scroll-speed]'); $boxes.each(function() { var $this = $(this), oTop = scrollTop - $this.offset().top, scrollspeed = parseInt($this.data('scroll-speed')), val = -oTop / scrollspeed; if(val>-300){ $this.css('transform', 'translateY(' + val + 'px)'); } }); $bgboxes.each(function() { var $this = $(this), oTop = scrollTop - $this.offset().top, scrollspeed = parseInt($this.data('bg-scroll-speed')), val = -oTop / scrollspeed; if(val>-300 && $this.css('opacity') != 0){ $this.css('background-position', '50% ' + val + 'px'); } }); } function HtmlDecode(input) { if (input === "" || input === undefined) { return ""; } const textArea = document.createElement('textarea'); textArea.innerHTML = input; return textArea.value; } function abortAllImageLoading() { $('img.async').each(function() { const abortController = $(this).data('abortController'); if (abortController) { abortController.abort(); }else{ alert('No abort controller'); } }); } async function loadImageAsync(url, signal) { try { const response = await fetch(url, { signal }); if (!response.ok) { throw new Error('Network response was not ok'); } const blob = await response.blob(); const imageURL = URL.createObjectURL(blob); const image = new Image(); image.src = imageURL; return new Promise((resolve) => { image.onload = () => resolve(image); }); } catch (error) { console.error('Error loading image:', error); throw error; } }