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('