bludit/bl-kernel/js/functions.php

111 lines
2.7 KiB
PHP
Raw Normal View History

2015-05-05 03:00:01 +02:00
<script>
var ajaxRequest;
2018-05-08 00:15:40 +02:00
function autosave(title, content) {
var ajaxRequest;
if(ajaxRequest) {
ajaxRequest.abort();
}
ajaxRequest = $.ajax({
type: "POST",
data: {
tokenCSRF: tokenCSRF, // token from env variables
title: title,
content: content
},
url: "<?php echo HTML_PATH_ADMIN_ROOT.'ajax/save-as-draft' ?>"
});
// Callback handler that will be called on success
ajaxRequest.done(function (response, textStatus, jqXHR){
console.log("Autosave done.");
});
// Callback handler that will be called on failure
ajaxRequest.fail(function (jqXHR, textStatus, errorThrown){
console.log("Autosave error on ajax call.");
});
// Callback handler that will be called regardless
// if the request failed or succeeded
ajaxRequest.always(function () {
console.log("Autosave always.");
});
}
2017-07-13 22:39:04 +02:00
function generateSlug(text, parentKey, currentKey, writeResponse) {
2015-05-05 03:00:01 +02:00
if(ajaxRequest) {
ajaxRequest.abort();
}
2017-07-13 22:39:04 +02:00
ajaxRequest = $.ajax({
type: "POST",
data: {
tokenCSRF: tokenCSRF,
text: text,
parentKey: parentKey,
currentKey: currentKey
},
url: "<?php echo HTML_PATH_ADMIN_ROOT.'ajax/slug' ?>"
});
2015-05-05 03:00:01 +02:00
// Callback handler that will be called on success
ajaxRequest.done(function (response, textStatus, jqXHR){
writeResponse.val(response["slug"]);
console.log("DEBUG: AJAX Done function");
});
// Callback handler that will be called on failure
ajaxRequest.fail(function (jqXHR, textStatus, errorThrown){
console.log("DEBUG: AJAX error function");
});
// Callback handler that will be called regardless
// if the request failed or succeeded
ajaxRequest.always(function () {
console.log("DEBUG: AJAX always function");
});
}
2017-11-01 19:38:56 +01:00
function sanitizeHTML(text) {
var map = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#039;'
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
}
2018-03-28 23:34:36 +02:00
function setCookie(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0; i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return false;
}
function deleteCookie(name) {
document.cookie = name+'=; Max-Age=-999;';
}
2018-05-08 00:15:40 +02:00
</script>