").append(this.eq(0).clone()).html(); } function JQueryChangeVisibility(visible) { if (visible == true) this.show(); else this.hide(); } function JQueryInsertAtIndex(element, index) { var lastIndex = this.children().size(); if (index < 0) { index = Math.max(0, lastIndex + 1 + index); } this.append(element); if (index < lastIndex) { this.children().eq(index).before(this.children().last()); } return this; } function JQueryRemoveAttributes(except_array) { return this.each(function() { var attributes = $.map(this.attributes, function(item) { return item.name; }); var element = $(this); $.each(attributes, function(i, item) { var should_delete = true; if (except_array) { console.log(except_array); should_delete = should_delete && (except_array.indexOf(item) < 0); console.log(item + ": " + except_array.indexOf(item)); } if (should_delete) element.removeAttr(item); }); }); } function UpdateJQueryAdditionalFunctions() { jQuery.fn.outerHTML = JQueryGetOuterHTML; jQuery.fn.changeVisibility = JQueryChangeVisibility; jQuery.fn.insertAt = JQueryInsertAtIndex; jQuery.fn.removeAttributes = JQueryRemoveAttributes; } function Assigned(variable) { let result = (variable != null); result = result && (typeof variable !== 'undefined'); if (result) { if ((typeof variable === 'string') || (variable instanceof String)) { result = result && (variable != ""); } } return result; } function SetCookie(cookie_name, cookie_value, expire_days) { if (Assigned(cookie_name)) { var expires = ""; if (expire_days > 0) { var date_expire = new Date(); date_expire.setTime(date_expire.getTime() + (expire_days * 24 * 60 * 60 * 1000)); var expires = "; expires=" + date_expire.toGMTString(); } document.cookie = cookie_name + "=" + cookie_value + expires + "; path=/"; } } function ClearCookie(cookie_name) { SetCookie(cookie_name, ""); } function GetCookie(cookie_name) { var match = document.cookie.match(new RegExp('(^| )' + cookie_name + '=([^;]+)')); if (match) return match[2]; return ""; } function ExecuteHTTPRequest(url, data, on_request_successed, on_request_finish, isNotAsync) { isNotAsync = isNotAsync || false; return $.ajax( { url: url, type: 'POST', data: data, async: (!isNotAsync), success: function(response) { if (on_request_successed) on_request_successed(response); }, complete: function(response) { if (on_request_finish) on_request_finish(response); } }); } function ProcessJsonRequest(server_answer, on_request_successed, on_request_error) { if (server_answer.status == "ok") { if (on_request_successed) on_request_successed(server_answer); return true; } else if (server_answer.status == "error") { if (on_request_error) on_request_error(server_answer); else alert(server_answer.error_desc); return true; } return false; } function ExecuteAjaxRequest(url, data, on_request_successed, on_request_error, on_request_finish, isNotAsync) { return ExecuteHTTPRequest(url, data, function(response) { var server_answer = JSON.parse(response); ProcessJsonRequest(server_answer, on_request_successed, on_request_error); }, on_request_finish, isNotAsync); } function ExecuteMixedRequest(url, data, on_request_successed, on_request_error, on_request_finish, isNotAsync) { return ExecuteHTTPRequest(url, data, function(response) { if (IsJson(response)) { var server_answer = JSON.parse(response); if (server_answer) { if ((!ProcessJsonRequest(server_answer, on_request_successed, on_request_error)) && (on_request_successed)) { on_request_successed(server_answer, true); } } } else if (on_request_successed) on_request_successed(response, false); }, on_request_finish, isNotAsync); } function CreateURLFromFile(file) { if (file) return URL.createObjectURL(file); return ""; } function GetFirstDayOfYear(year, day_number) { var result = new Date(year + "-01-01"); while (result.getDay() != 1) result = IncrementDays(result, 1); return result; } function IncrementDays(date, days) { var result = new Date(date.valueOf()); result.setDate(result.getDate() + days); return result; } async function getImageSize(url) { return new Promise(resolve => { var image = new Image(); image.onload = function() { resolve({ width: image.width, height: image.height }); }; image.onerror = function() { resolve({width: 0, height: 0}); }; image.src = url; }); } /** Returns the dimensions of a video asynchrounsly. @param {String} url Url of the video to get dimensions from. @return {Promise} Promise which returns the dimensions of the video in 'width' and 'height' properties. */ async function getVideoMetadataOf(url) { var image_size = await getImageSize(url); return new Promise(resolve => { if ((image_size.height > 0) && (image_size.width > 0)) { resolve({ width: image_size.width, height: image_size.height, duration: 0 }); } // create the video element const video = document.createElement('video'); // place a listener on it video.addEventListener( "loadedmetadata", function () { // retrieve dimensions var height = this.videoHeight; var width = this.videoWidth; if ((height == 0) || (width ==0)) { var image_size = getImageSize(url); width = image_size.width; height = image_size.height; } const duration = this.duration; // send back result resolve({ width: width, height: height, duration: duration }); }, false ); // start download meta-datas video.src = url; }); } function GetFileSizeInStringFormat(file_size) { let BYTES_COUNT = 1024; if (file_size > BYTES_COUNT) { // Receive Free bytes in KB let calc_size = (file_size / BYTES_COUNT); let prefix = "КБ"; // If free space in KB > 1024 - receive free spaces in MB if (calc_size > BYTES_COUNT) { calc_size = (calc_size / BYTES_COUNT); prefix = 'МБ'; } // If free space in MB > 1024 - receive free spaces in GB if (calc_size > BYTES_COUNT) { calc_size = (calc_size / BYTES_COUNT); prefix = 'ГБ'; } // If free space in GB > 1024 - receive free spaces in TB if (calc_size > BYTES_COUNT) { calc_size = (calc_size / BYTES_COUNT); prefix = 'ТБ'; } return calc_size.toFixed(2) + ' ' + prefix; } return file_size + ' байт'; } function base64ToDataUri(base64) { return 'data:image/png;base64,' + base64; } function base64ToDataUri(base64) { return 'data:image/png;base64,' + base64; } async function resizeImage(img, width, height) { return new Promise(resolve => { // create an off-screen canvas var canvas = document.createElement('canvas'); var ctx = canvas.getContext('2d'); // set its dimension to target size canvas.width = width; canvas.height = height; // draw source image into the off-screen canvas: ctx.drawImage(img, 0, 0, width, height); // encode image to data-uri with base64 version of compressed image resolve(canvas.toDataURL()); }); } async function resizeImageSrc(image_src, width, height) { return new Promise(resolve => { var image = new Image(); image.onload = function() { resolve(resizeImage(this, width, height)); }; image.onerror = function() { resolve(null); }; image.src = image_src; }); } function getScaledImageSize(original_width, original_height, wanted_width, wanted_height) { if ((original_width > 0) && (original_height > 0) && ((wanted_width > 0) || (wanted_height > 0))) { var side_ratio = (original_width / original_height); var new_width = wanted_width; var new_height = wanted_height; // Receive New size of the picture if ((side_ratio <= 1) && (wanted_height > 0)) { new_width = Math.trunc(wanted_height * side_ratio); if ((wanted_width > 0) && (new_width > wanted_width)) { new_height = new_height - Math.trunc((new_width - wanted_width) / side_ratio); new_width = wanted_width; } } else { new_height = Math.trunc(wanted_width / side_ratio); if ((wanted_height > 0) && (new_height > wanted_height)) { new_width = new_width - Math.trunc((new_height - wanted_height) * side_ratio); new_height = wanted_height; } } return {'width': new_width, 'height': new_height}; } return {'width': original_width, 'height': original_height}; } function FormatInteger(integer, digits) { return (integer).toLocaleString('en-US', {minimumIntegerDigits: digits, useGrouping:false}) } function DecodeEntities(text) { return $('