HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/verrassendveel.komma.pro/wwwroot/admin/js/functions.js
// JavaScript Document
var currentId = null;

$(document).ready(function(){
	initTinymce();
	// Input field focussed?
    $('input').focus(function() {
        currentId = $(this).attr('id');
    });	
	
});

function getPage(target, page, arguments) {
	$("#" + target).load("./php/" + page + ".php?" + arguments,function(){
		//callback
	});
}

function updateColorSession(sessionname, key, color, id){
	if(color == 'undefined' || color == null ){
		color = document.getElementById(id).value;
	}
	$('#jsbox').load('./php/js_updateColorSession.php?sessionname='+sessionname+'&color='+color+'&key='+key,function(){
		//callback
	});
}
function updateStockcodeSession(sessionname, key, stockcode, id){
	if(stockcode == 'undefined' || stockcode == null ){
		stockcode = document.getElementById(id).value;
	}
	$('#jsbox').load('./php/js_updateStockcodes.php?sessionname='+sessionname+'&stockcode='+stockcode+'&key='+key,function(){
		//callback
	});
}

function colorBar(id,color){
	$('#'+id).css({backgroundColor:'#'+color});	
}

function initTinymce(){
	$('textarea.tinymce').tinymce({
		// General options
		mode : 	"textareas",
		theme : "motheme",
		skin : 	"mikeontwerpt",
		height : "184",
		plugins : "inlinepopups,tabfocus,paste", 
		init_instance_callback: myCustomInitInstance, 
		
		// Theme options
		theme_motheme_buttons1 : "bold,italic,underline,|,bullist,numlist,|,link,unlink",
		theme_motheme_buttons2 : "",
		theme_motheme_buttons3 : "",
		theme_motheme_buttons4 : "",
		theme_motheme_toolbar_location : "top",
		theme_motheme_toolbar_align : "left",
		theme_motheme_statusbar_location : "bottom",
		theme_motheme_resizing : false,
	
		//content_css : "css/style.css",
	
		// Replace values for the template plugin
		template_replace_values : {
			username : "Mike Ontwerpt",
			staffid : "991234"
		}
	});	
}

function myCustomInitInstance(ed) {
		//set focus on textfield
		var s = ed.settings;
		var realID = ed.id+'_tbl';
		tinymce.dom.Event.add(ed.getWin(), 'focus', function(e) {
			if($(realID)) {
				currentId = ed.id+'_ifr';
			}
		});
	}

// Insertion code switcher
function checkInsert(shortcode){
	var key = currentId.replace('_ifr','');
	var len1 = currentId.length; 
	var len2 = key.length;
	
	if (len1 != len2) {
		$('#'+key).tinymce().execCommand('mceInsertContent', false, '[' + shortcode + ']');
	} else {
		insertCode(currentId,'[' + shortcode + ']');	
	}
}



// uberBB script
function insertCode(targetId, openTag, closeTag) {
	
	var inputForm = document.getElementById(targetId);
	
	var totalLength = 0;		
	var caretPos = 0;
	var isIE = false;
		
	var preTag = "";
	var postTag = "";
	var tweenTag = "";
	
	if (document.all) { isIE = true; }
	
	if (closeTag == undefined) {
		preTag = "";
		tweenTag = openTag;
		postTag = "";
	} else {
		preTag = openTag;
		tweenTag = "";
		postTag = closeTag;
	}
		
	// Getting the caret position; IE then Mozilla
	if (isIE) {
		
		inputForm.focus();
		var selection = document.selection.createRange();
		var selection2 = selection.duplicate();
		
		inputForm = document.getElementById(targetId);
		selection2.moveToElementText(inputForm);
		
		var caretPos = -1;
		
		while (selection2.inRange(selection)) {
			selection2.moveStart('character');
			caretPos++;
		}
		
	} else if (inputForm.selectionStart || inputForm.selectionStart == '0') {
		caretPos = inputForm.selectionStart;
	}
	
	// Modify the selection; IE, Mozilla and a just in case
	if (isIE) {
		
		inputForm.focus();
		selection = document.selection.createRange();
			
		if (tweenTag == "") {
			
			tweenTag = selection;
			
			if (tweenTag.length == 0) {
				totalLength = caretPos + preTag.length;
			} else {
				totalLength = caretPos + tweenTag.length + preTag.length + postTag.length;
			}
			
		} else {			
			totalLength = caretPos + tweenTag.length + preTag.length + postTag.length;		
		}
		
		selection.text = startTag + tweenTag + stopTag;	
			
	} else if (inputForm.selectionStart || inputForm.selectionStart == '0') {
		var startPos = inputForm.selectionStart;
		var endPos = inputForm.selectionEnd;
	
		if (tweenTag == "") {
			
			tweenTag = inputForm.value.substring(startPos, endPos);
		
			if (tweenTag.length == 0) {				
				varLength = inputForm.value.substring(0, startPos) + preTag;
				totalLength = varLength.length;
			} else {
				varLength = inputForm.value.substring(0, startPos) + preTag + tweenTag + postTag;
				totalLength = varLength.length;
			}
		
	} else {
		varLength = inputForm.value.substring(0, startPos) + preTag + tweenTag + postTag;
		totalLength = varLength.length;
	}
	
	inputForm.value = inputForm.value.substring(0, startPos) + preTag + tweenTag + postTag + inputForm.value.substring(endPos, inputForm.value.length);
				  
	} else {
		inputForm.value += preTag + tweenTag + postTag;
		totalLength = inputForm.value.length;
	}	  
 
	// Set the caret back into position; IE then Mozilla
	if (isIE) {
		var range = document.selection.createRange();
			
		range.collapse(false);
		range.move ('character', totalLength - inputForm.value.length + inputForm.value.split('\n').length - 1);
		range.select();
	
	} else if (inputForm.selectionStart || inputForm.selectionStart == '0') {
		inputForm.setSelectionRange(totalLength, totalLength);
	}
}



/* CHANGE ORDER */
//http://davidwalsh.name/mootools-drag-drop
function initSortableList(listid){
	if(listid == 'undefined' || listid == null) listid = '#sortable-list';
	
	/* grab important elements */
	  var sortInput = jQuery('#sort_order');
	  var submit = jQuery('#autoSubmit');
	 // var messageBox = jQuery('#message-box');
	  var list = jQuery(listid);
	  /* create requesting function to avoid duplicate code */
	  var request = function() {
		jQuery.ajax({
		  beforeSend: function() {
			messageBox.text('Updating the sort order in the database.');
		  },
		  complete: function() {
			messageBox.text('Database has been updated.');
		  },
		  data: 'sort_order=' + sortInput[0].value + '&ajax=' + submit.checked + '&do_submit=1&byajax=1', //need [0]?
		  type: 'post',
		  url: '$_SERVER["REQUEST_URI"];'
		});
	  };
	  
	  /* worker function */
	  var fnSubmit = function(save) {
		var sortOrder = [];
		list.children('li').each(function(){
		  sortOrder.push(jQuery(this).data('id'));
		});
		sortOrder.reverse();
		sortInput.val(sortOrder.join(','));
		console.log(sortInput.val());
		if(save) {
		 // request();
			window.location.reload();
		}
	  };
	  
	  /* store values */
	  list.children('li').each(function() {
		var li = jQuery(this);
		li.data('id',li.attr('title')).attr('title','');
	  });
	  
	  /* sortables */
	  list.sortable({
		opacity: 0.7,
		update: function() {
		  fnSubmit(submit.checked);
		}
	  });
	  list.disableSelection();
	  /*
	  /* ajax form submission 
	 jQuery('#dd-form').bind('submit',function(e) {
		if(e) e.preventDefault();
		fnSubmit(true);
	  });*/
}