File: D:/HostingSpaces/SBogers45/smuldersinterieurprojecten.nl/wwwroot/admin/js/functions.js
var currentId = null;
var editor = [];
// Document ready?
$(document).ready(function() {
// Convert .wysiqyg's to CKeditor's
$('textarea.wysiwyg').each( function() {
$(this).ckeditor( function() { }, {
extraPlugins : "uicolor",
uiColor: "#fff",
forcePasteAsPlainText : true,
pasteFromWordRemoveFontStyles : true,
enterMode : CKEDITOR.ENTER_BR,
shiftEnterMode : CKEDITOR.ENTER_BR,
toolbar :
[
//[ "Bold", "Italic", "-", "NumberedList", "BulletedList", "-", "Link", "Unlink", "-", "PasteText", "-", "FontSize", "TextColor" ]
[ "Bold", "Italic", "-", "BulletedList", "-", "Link", "Unlink", "-", "PasteText", "-",]
]
});
// Get the actual object and add it to the array
editor.push($(this).ckeditorGet());
});
// Input field focussed?
$('input').focus(function() {
currentId = $(this).attr('id');
});
// CKeditor focussed?
$('textarea.wysiwyg').each( function() {
$(this).ckeditorGet().on('focus', function(event) {
currentId = $(this).attr('id');
});
});
});
// Trim functions
function trim(string) {
return rightTrim(leftTrim(string));
}
function leftTrim(string) {
var left = 0;
while (left < string.length && string[left] == ' ') {
left++;
}
return string.substring(left, string.length);
}
function rightTrim(string) {
var right = string.length - 1;
while(right > 0 && string[right] == ' ') {
right-=1;
}
return string.substring(0, right + 1);
}
// Insertion code switcher
function checkInsert(shortcode){
var key = currentId.replace('cke_','');
var len1 = currentId.length;
var len2 = key.length;
if (len1 != len2) {
key = parseInt(key);
key--;
editor[key].insertText('[' + shortcode + ']');
} else {
insertCode(currentId,'[' + shortcode + ']');
}
}
// uberBB script
function insertCode(targetId, openTag, closeTag) {
//var targetId = 'editor';
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 = sel.duplicate();
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);
}
}
//checks al checkforms
function check_all(iam)
{
var node_list = document.getElementsByTagName('input');
for (var i = 0; i < node_list.length; i++)
{
var node = node_list[i];
if (node.getAttribute('type') == 'checkbox')
{
if (iam.checked == 1)
{
node.checked = 1;
}
else
{
node.checked = 0;
}
}
}
}
//load new page with ajax
function getPage(target, page, arguments) {
$("#" + target).load("./pages/" + page + ".php?" + arguments);
}