Reformated JS (#794)

This commit is contained in:
Roman Kelesidis 2023-06-08 13:53:26 +07:00 committed by GitHub
commit 9015980e17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,10 +11,8 @@ function $p() {
var elements = []; var elements = [];
for (var i = 0; i < arguments.length; i++) { for (var i = 0; i < arguments.length; i++) {
var element = arguments[i]; var 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,16 +22,14 @@ 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];
} }
} }
@ -41,11 +37,9 @@ function addEvent(obj, type, fn) {
var EventCache = function () { var EventCache = function () {
var listEvents = []; var listEvents = [];
return { return {
listEvents: listEvents, listEvents: listEvents, add: function (node, sEventName, fHandler) {
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];
@ -69,7 +63,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;
} }
@ -79,14 +73,12 @@ 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;
} }
} }
@ -125,12 +117,7 @@ function setCookie(name, value, days, path, domain, secure) {
var expires = ''; var expires = '';
} }
document.cookie = document.cookie = name + '=' + encodeURI(value) + ((expires) ? '; expires=' + expires : '') + ((path) ? '; path=' + path : ((cookiePath) ? '; path=' + cookiePath : '')) + ((domain) ? '; domain=' + domain : ((cookieDomain) ? '; domain=' + cookieDomain : '')) + ((secure) ? '; secure' : ((cookieSecure) ? '; secure' : ''));
name + '=' + encodeURI(value)
+ ((expires) ? '; expires=' + expires : '')
+ ((path) ? '; path=' + path : ((cookiePath) ? '; path=' + cookiePath : ''))
+ ((domain) ? '; domain=' + domain : ((cookieDomain) ? '; domain=' + cookieDomain : ''))
+ ((secure) ? '; secure' : ((cookieSecure) ? '; secure' : ''));
} }
/** /**
@ -153,9 +140,7 @@ function deleteCookie(name, path, domain) {
// Menus // Menus
var Menu = { var Menu = {
hideSpeed: 'fast', hideSpeed: 'fast', offsetCorrection_X: -4, offsetCorrection_Y: 2,
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
@ -265,23 +250,18 @@ $(document).ready(function () {
// Menus // Menus
$('body').append($('div.menu-sub')); $('body').append($('div.menu-sub'));
$('a.menu-root') $('a.menu-root')
.click( .click(function (e) {
function (e) { e.preventDefault();
e.preventDefault(); Menu.clicked($(this));
Menu.clicked($(this)); return false;
return false; })
}) .hover(function () {
.hover( Menu.hovered($(this));
function () { return false;
Menu.hovered($(this)); }, function () {
return false; Menu.unhovered($(this));
}, return false;
function () { });
Menu.unhovered($(this));
return false;
}
)
;
$('div.menu-sub') $('div.menu-sub')
.mousedown(function (e) { .mousedown(function (e) {
e.stopPropagation(); e.stopPropagation();
@ -289,8 +269,7 @@ $(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 () {
@ -299,8 +278,7 @@ $(document).ready(function () {
.end() .end()
.filter('.error').one('focus', function () { .filter('.error').one('focus', function () {
$(this).removeClass('error'); $(this).removeClass('error');
}) });
;
}); });
// //
@ -319,20 +297,14 @@ 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: '', form_token: '', hide_loading: null,
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, url: this.url, type: this.type, dataType: this.dataType, data: request, success: ajax.success, error: ajax.error
type: this.type,
dataType: this.dataType,
data: request,
success: ajax.success,
error: ajax.error
}); });
}, },
@ -357,27 +329,22 @@ 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);
} }
@ -473,9 +440,7 @@ $(document).ready(function () {
status = ''; status = '';
text = 'неверный формат данных'; text = 'неверный формат данных';
} }
$(this).html( $(this).html("Ошибка в: <i>" + ajax.url + "</i><br /><b>" + status + " " + text + "</b>").show();
"Ошибка в: <i>" + ajax.url + "</i><br /><b>" + status + " " + text + "</b>"
).show();
ajax.setStatusBoxPosition($(this)); ajax.setStatusBoxPosition($(this));
}); });
@ -512,8 +477,7 @@ var autocomplete = function (noCenter) {
if (!noCenter) { if (!noCenter) {
$("div#autocomplete_popup").css({ $("div#autocomplete_popup").css({
left: _popup_left + "px", left: _popup_left + "px", top: _popup_top + "px"
top: _popup_top + "px"
}).show(1000); }).show(1000);
} else { } else {
$("div#autocomplete_popup").show(1000); $("div#autocomplete_popup").show(1000);