mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 05:43:55 -07:00
Reformated JS (#753)
This commit is contained in:
parent
f35ca7a88e
commit
243ddf337c
1 changed files with 43 additions and 77 deletions
|
@ -8,15 +8,15 @@
|
||||||
|
|
||||||
// prototype $
|
// prototype $
|
||||||
function $p() {
|
function $p() {
|
||||||
var elements = [];
|
let elements = [];
|
||||||
for (var i = 0; i < arguments.length; i++) {
|
|
||||||
var element = arguments[i];
|
for (let i = 0; i < arguments.length; i++) {
|
||||||
if (typeof element === 'string')
|
let element = arguments[i];
|
||||||
element = document.getElementById(element);
|
if (typeof element === 'string') element = document.getElementById(element);
|
||||||
if (arguments.length === 1)
|
if (arguments.length === 1) return element;
|
||||||
return element;
|
|
||||||
elements.push(element);
|
elements.push(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,16 +24,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 +39,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 +65,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,20 +75,18 @@ 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) {
|
||||||
var el = document.getElementById(id);
|
let el = document.getElementById(id);
|
||||||
el.style.display = (el.style.display === 'none') ? '' : 'none';
|
el.style.display = (el.style.display === 'none') ? '' : 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,8 +100,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
|
||||||
|
@ -125,12 +119,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' : ''));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -143,7 +132,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)
|
||||||
*/
|
*/
|
||||||
|
@ -153,9 +142,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 +252,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 +271,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 +280,7 @@ $(document).ready(function () {
|
||||||
.end()
|
.end()
|
||||||
.filter('.error').one('focus', function () {
|
.filter('.error').one('focus', function () {
|
||||||
$(this).removeClass('error');
|
$(this).removeClass('error');
|
||||||
})
|
});
|
||||||
;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -319,20 +299,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 +331,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 +442,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 +479,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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue