Conditions | 1 |
Paths | 1 |
Total Lines | 117 |
Code Lines | 81 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
7 | jQuery(document).ready(function () { |
||
8 | |||
9 | // Выбор select без ctrl |
||
10 | $('select').mousedown(function (event) { |
||
11 | event.preventDefault() |
||
12 | |||
13 | var select = this |
||
14 | var scroll = select.scrollTop |
||
15 | event.target.selected = !event.target.selected |
||
16 | setTimeout(function () {select.scrollTop = scroll}, 0) |
||
17 | $('select').focus() |
||
18 | }).mousemove(function (e) {e.preventDefault()}) |
||
19 | |||
20 | // false для checkbox |
||
21 | $('.module_on:checkbox').on('change', function () { |
||
22 | if (this.checked) { |
||
23 | $(this).val('1') |
||
24 | } else { |
||
25 | $(this).val('0') |
||
26 | } |
||
27 | }) |
||
28 | |||
29 | $('.proxy_on:checkbox').on('change', function () { |
||
30 | if (this.checked) { |
||
31 | $(this).val('1') |
||
32 | } else { |
||
33 | $(this).val('0') |
||
34 | } |
||
35 | }) |
||
36 | |||
37 | // Сохранение настроек |
||
38 | $('#save').click(function (event) { |
||
39 | event.preventDefault() |
||
40 | var btn = this |
||
41 | |||
42 | $(btn).fadeTo(0, 0.5) |
||
43 | $.ajax({ |
||
44 | url: '/bitrix/admin/telegram_main.php', |
||
45 | type: 'POST', |
||
46 | dataType: 'json', |
||
47 | data: { |
||
48 | funcName: 'saveConfig', |
||
49 | fields: { |
||
50 | module_on: $('.module_on').val(), |
||
51 | name_bot: $('.name_bot').val(), |
||
52 | token: $('.token').val(), |
||
53 | mail: $('.mail').val(), |
||
54 | proxy_on: $('.proxy_on').val(), |
||
55 | proxy: { |
||
56 | url: $('.proxy_url').val(), |
||
57 | port: $('.proxy_port').val(), |
||
58 | user: $('.proxy_user').val(), |
||
59 | pass: $('.proxy_pass').val() |
||
60 | } |
||
61 | } |
||
62 | } |
||
63 | }).done(function (data) { |
||
64 | if (Object.keys(data['message']).length > 0) { |
||
65 | $('.telegram-response').html(data['message']).fadeIn(500) |
||
66 | } |
||
67 | }).fail(function (data) { |
||
68 | console.log(data) |
||
|
|||
69 | alert('Error. Please, refresh page!') |
||
70 | }).always(function () { |
||
71 | $(btn).fadeTo(0, 1) |
||
72 | }) |
||
73 | }) |
||
74 | |||
75 | // Получение входящих запросов |
||
76 | $('#updates_user').click(function (event) { |
||
77 | event.preventDefault() |
||
78 | var btn = this |
||
79 | |||
80 | $(btn).fadeTo(0, 0.5) |
||
81 | $.ajax({ |
||
82 | type: 'POST', |
||
83 | dataType: 'json', |
||
84 | url: '/bitrix/admin/telegram_main.php', |
||
85 | data: { |
||
86 | funcName: 'getUpdates' |
||
87 | } |
||
88 | }).done(function (data) { |
||
89 | user = data['updates'] |
||
90 | |||
91 | if (Object.keys(user).length > 0) { |
||
92 | $('.new_user').html('<td colspan="6">Новый пользователь</td>') |
||
93 | |||
94 | $('.telegram_user').html( |
||
95 | '<td id="idUser">' + user['id'] + '</td>' + |
||
96 | '<td id="nicknameUser">' + user['username'] + '</td>' + |
||
97 | '<td id="usernameUser">' + user['first_name'] + ' ' + user['last_name'] + '</td>' + |
||
98 | '<td><input id="save_user" name="save_user" value="Сохранить" type="button" onclick="saveUser();"></td>' |
||
99 | ) |
||
100 | } else { |
||
101 | $('.telegram-response').html(data['message']).fadeIn(500) |
||
102 | } |
||
103 | |||
104 | }).fail(function (data) { |
||
105 | console.log(data) |
||
106 | alert('Error. Please, refresh page!') |
||
107 | }).always(function () { |
||
108 | $(btn).fadeTo(0, 1) |
||
109 | }) |
||
110 | }) |
||
111 | |||
112 | // Переключение табов |
||
113 | $('.adm-detail-tabs-block span').click(function() { |
||
114 | var click_id=$(this).attr('id'); |
||
115 | if (click_id !== $('.adm-detail-tabs-block span.adm-detail-tab-active').attr('id') ) { |
||
116 | $('.adm-detail-tabs-block span').removeClass('adm-detail-tab-active'); |
||
117 | $(this).addClass('adm-detail-tab-active'); |
||
118 | $('.adm-detail-content').fadeOut(0); |
||
119 | $('#wrap-' + click_id).fadeIn(500); |
||
120 | } |
||
121 | }) |
||
122 | |||
123 | }) |
||
124 | |||
175 |