Revert "Reformated JS (#753)"

This reverts commit 243ddf337c.
This commit is contained in:
Roman Kelesidis 2023-06-08 13:50:37 +07:00
commit fb07248a4a

View file

@ -8,15 +8,15 @@
// prototype $ // prototype $
function $p() { function $p() {
let elements = []; var elements = [];
for (var i = 0; i < arguments.length; i++) {
for (let i = 0; i < arguments.length; i++) { var element = arguments[i];
let element = arguments[i]; if (typeof element === 'string')
if (typeof element === 'string') element = document.getElementById(element); element = document.getElementById(element);
if (arguments.length === 1) return element; if (arguments.length === 1)
return element;
elements.push(element); elements.push(element);
} }
return elements; return elements;
} }
@ -24,14 +24,16 @@ function addEvent(obj, type, fn) {
if (obj.addEventListener) { if (obj.addEventListener) {
obj.addEventListener(type, fn, false); obj.addEventListener(type, fn, false);
EventCache.add(obj, type, fn); EventCache.add(obj, type, fn);
} else if (obj.attachEvent) { }
else if (obj.attachEvent) {
obj["e" + type + fn] = fn; obj["e" + type + fn] = fn;
obj[type + fn] = function () { obj[type + fn] = function () {
obj["e" + type + fn](window.event); obj["e" + type + fn](window.event);
}; };
obj.attachEvent("on" + type, obj[type + fn]); obj.attachEvent("on" + type, obj[type + fn]);
EventCache.add(obj, type, fn); EventCache.add(obj, type, fn);
} else { }
else {
obj["on" + type] = obj["e" + type + fn]; obj["on" + type] = obj["e" + type + fn];
} }
} }
@ -39,9 +41,11 @@ function addEvent(obj, type, fn) {
var EventCache = function () { var EventCache = function () {
var listEvents = []; var listEvents = [];
return { return {
listEvents: listEvents, add: function (node, sEventName, fHandler) { listEvents: listEvents,
add: function (node, sEventName, fHandler) {
listEvents.push(arguments); listEvents.push(arguments);
}, flush: function () { },
flush: function () {
var i, item; var i, item;
for (i = listEvents.length - 1; i >= 0; i = i - 1) { for (i = listEvents.length - 1; i >= 0; i = i - 1) {
item = listEvents[i]; item = listEvents[i];
@ -65,7 +69,7 @@ if (document.all) {
function imgFit(img, maxW) { function imgFit(img, maxW) {
img.title = 'Размеры изображения: ' + img.width + ' x ' + img.height; img.title = 'Размеры изображения: ' + img.width + ' x ' + img.height;
if (typeof (img.naturalHeight) === 'undefined') { if (typeof(img.naturalHeight) === 'undefined') {
img.naturalHeight = img.height; img.naturalHeight = img.height;
img.naturalWidth = img.width; img.naturalWidth = img.width;
} }
@ -75,18 +79,20 @@ function imgFit(img, maxW) {
img.title = 'Нажмите на изображение, чтобы посмотреть его в полный размер'; img.title = 'Нажмите на изображение, чтобы посмотреть его в полный размер';
img.style.cursor = 'move'; img.style.cursor = 'move';
return false; return false;
} else if (img.width === maxW && img.width < img.naturalWidth) { }
else if (img.width === maxW && img.width < img.naturalWidth) {
img.height = img.naturalHeight; img.height = img.naturalHeight;
img.width = img.naturalWidth; img.width = img.naturalWidth;
img.title = 'Размеры изображения: ' + img.naturalWidth + ' x ' + img.naturalHeight; img.title = 'Размеры изображения: ' + img.naturalWidth + ' x ' + img.naturalHeight;
return false; return false;
} else { }
else {
return true; return true;
} }
} }
function toggle_block(id) { function toggle_block(id) {
let el = document.getElementById(id); var el = document.getElementById(id);
el.style.display = (el.style.display === 'none') ? '' : 'none'; el.style.display = (el.style.display === 'none') ? '' : 'none';
} }
@ -100,8 +106,8 @@ function rand(min, max) {
// Cookie functions // Cookie functions
/** /**
* [name] Name of the cookie * name Name of the cookie
* [value] Value of the cookie * value Value of the cookie
* [days] Number of days to remain active (default: end of current session) * [days] Number of days to remain active (default: end of current session)
* [path] Path where the cookie is valid (default: path of calling document) * [path] Path where the cookie is valid (default: path of calling document)
* [domain] Domain where the cookie is valid * [domain] Domain where the cookie is valid
@ -119,7 +125,12 @@ function setCookie(name, value, days, path, domain, secure) {
var expires = ''; var expires = '';
} }
document.cookie = name + '=' + encodeURI(value) + ((expires) ? '; expires=' + expires : '') + ((path) ? '; path=' + path : ((cookiePath) ? '; path=' + cookiePath : '')) + ((domain) ? '; domain=' + domain : ((cookieDomain) ? '; domain=' + cookieDomain : '')) + ((secure) ? '; secure' : ((cookieSecure) ? '; secure' : '')); document.cookie =
name + '=' + encodeURI(value)
+ ((expires) ? '; expires=' + expires : '')
+ ((path) ? '; path=' + path : ((cookiePath) ? '; path=' + cookiePath : ''))
+ ((domain) ? '; domain=' + domain : ((cookieDomain) ? '; domain=' + cookieDomain : ''))
+ ((secure) ? '; secure' : ((cookieSecure) ? '; secure' : ''));
} }
/** /**
@ -132,7 +143,7 @@ function getCookie(name) {
} }
/** /**
* [name] name of the cookie * name name of the cookie
* [path] path of the cookie (must be same as path used to create cookie) * [path] path of the cookie (must be same as path used to create cookie)
* [domain] domain of the cookie (must be same as domain used to create cookie) * [domain] domain of the cookie (must be same as domain used to create cookie)
*/ */
@ -142,7 +153,9 @@ function deleteCookie(name, path, domain) {
// Menus // Menus
var Menu = { var Menu = {
hideSpeed: 'fast', offsetCorrection_X: -4, offsetCorrection_Y: 2, hideSpeed: 'fast',
offsetCorrection_X: -4,
offsetCorrection_Y: 2,
activeMenuId: null, // currently opened menu (from previous click) activeMenuId: null, // currently opened menu (from previous click)
clickedMenuId: null, // menu to show up clickedMenuId: null, // menu to show up
@ -252,18 +265,23 @@ $(document).ready(function () {
// Menus // Menus
$('body').append($('div.menu-sub')); $('body').append($('div.menu-sub'));
$('a.menu-root') $('a.menu-root')
.click(function (e) { .click(
e.preventDefault(); function (e) {
Menu.clicked($(this)); e.preventDefault();
return false; Menu.clicked($(this));
}) return false;
.hover(function () { })
Menu.hovered($(this)); .hover(
return false; function () {
}, function () { Menu.hovered($(this));
Menu.unhovered($(this)); return false;
return false; },
}); function () {
Menu.unhovered($(this));
return false;
}
)
;
$('div.menu-sub') $('div.menu-sub')
.mousedown(function (e) { .mousedown(function (e) {
e.stopPropagation(); e.stopPropagation();
@ -271,7 +289,8 @@ $(document).ready(function () {
.find('a') .find('a')
.click(function (e) { .click(function (e) {
Menu.hide(e); Menu.hide(e);
}); })
;
// Input hints // Input hints
$('input') $('input')
.filter('.hint').one('focus', function () { .filter('.hint').one('focus', function () {
@ -280,7 +299,8 @@ $(document).ready(function () {
.end() .end()
.filter('.error').one('focus', function () { .filter('.error').one('focus', function () {
$(this).removeClass('error'); $(this).removeClass('error');
}); })
;
}); });
// //
@ -299,14 +319,20 @@ Ajax.prototype = {
state: {}, // current action state state: {}, // current action state
request: {}, // request data request: {}, // request data
params: {}, // action params, format: ajax.params[ElementID] = { param: "val" ... } params: {}, // action params, format: ajax.params[ElementID] = { param: "val" ... }
form_token: '', hide_loading: null, form_token: '',
hide_loading: null,
exec: function (request, hide_loading = false) { exec: function (request, hide_loading = false) {
this.request[request.action] = request; this.request[request.action] = request;
request['form_token'] = this.form_token; request['form_token'] = this.form_token;
this.hide_loading = hide_loading; this.hide_loading = hide_loading;
$.ajax({ $.ajax({
url: this.url, type: this.type, dataType: this.dataType, data: request, success: ajax.success, error: ajax.error url: this.url,
type: this.type,
dataType: this.dataType,
data: request,
success: ajax.success,
error: ajax.error
}); });
}, },
@ -331,22 +357,27 @@ Ajax.prototype = {
var req = ajax.request[action]; var req = ajax.request[action];
req.user_password = user_password; req.user_password = user_password;
ajax.exec(req); ajax.exec(req);
} else { }
else {
ajax.clearActionState(action); ajax.clearActionState(action);
ajax.showErrorMsg('Введен неверный пароль'); ajax.showErrorMsg('Введен неверный пароль');
} }
} else if (response.prompt_confirm) { }
else if (response.prompt_confirm) {
if (window.confirm(response.confirm_msg)) { if (window.confirm(response.confirm_msg)) {
var req = ajax.request[action]; var req = ajax.request[action];
req.confirmed = 1; req.confirmed = 1;
ajax.exec(req); ajax.exec(req);
} else { }
else {
ajax.clearActionState(action); ajax.clearActionState(action);
} }
} else if (response.error_code) { }
else if (response.error_code) {
ajax.showErrorMsg(response.error_msg); ajax.showErrorMsg(response.error_msg);
$('.loading-1').removeClass('loading-1').html('error'); $('.loading-1').removeClass('loading-1').html('error');
} else { }
else {
ajax.callback[action](response); ajax.callback[action](response);
ajax.clearActionState(action); ajax.clearActionState(action);
} }
@ -442,7 +473,9 @@ $(document).ready(function () {
status = ''; status = '';
text = 'неверный формат данных'; text = 'неверный формат данных';
} }
$(this).html("Ошибка в: <i>" + ajax.url + "</i><br /><b>" + status + " " + text + "</b>").show(); $(this).html(
"Ошибка в: <i>" + ajax.url + "</i><br /><b>" + status + " " + text + "</b>"
).show();
ajax.setStatusBoxPosition($(this)); ajax.setStatusBoxPosition($(this));
}); });
@ -479,7 +512,8 @@ var autocomplete = function (noCenter) {
if (!noCenter) { if (!noCenter) {
$("div#autocomplete_popup").css({ $("div#autocomplete_popup").css({
left: _popup_left + "px", top: _popup_top + "px" left: _popup_left + "px",
top: _popup_top + "px"
}).show(1000); }).show(1000);
} else { } else {
$("div#autocomplete_popup").show(1000); $("div#autocomplete_popup").show(1000);