9
9
}
10
10
11
11
var getHooks = function getHooks() {
12
- var type = getTb().find('.newtype:checked').attr('id');
12
+ console.log('getHooks');
13
+ var tb = getTb();
14
+ var type = tb.find('.newtype:checked').attr('id');
13
15
if (type == 'action') {
14
- getTb() .find('#action_or_filter').text('<?php _e ("Action: " ,'hookpress ' );?> ');
15
- getTb() .find('#filtermessage').hide();
16
+ tb .find('#action_or_filter').text('<?php _e ("Action: " ,'hookpress ' );?> ');
17
+ tb .find('#filtermessage').hide();
16
18
}
17
19
if (type == 'filter') {
18
- getTb() .find('#action_or_filter').text('<?php _e ("Filter: " ,'hookpress ' );?> ');
19
- getTb() .find('#filtermessage').show();
20
+ tb .find('#action_or_filter').text('<?php _e ("Filter: " ,'hookpress ' );?> ');
21
+ tb .find('#filtermessage').show();
20
22
}
21
23
$.ajax({type:'POST',
22
24
url:'admin-ajax.php',
23
25
data:'action=hookpress_get_hooks&type='+type,
24
26
beforeSend:function(){
25
- getTb() .find('#newhook').html('<div class="webhooks-spinner"> </div>');
27
+ tb .find('#newhook').html('<div class="webhooks-spinner"> </div>');
26
28
},
27
29
success:function(html){
28
- getTb() .find('#newhook').html(html);
30
+ tb .find('#newhook').html(html);
29
31
getFields();
30
32
},
31
33
dataType:'html'}
32
34
)
33
35
}
34
36
35
37
var getFields = function getFields() {
36
- var hook = getTb().find('#newhook').val();
37
- var type = getTb().find('.newtype:checked').attr('id');
38
+ console.log('getFields');
39
+ var tb = getTb();
40
+ var hook = tb.find('#newhook').val();
41
+ var type = tb.find('.newtype:checked').attr('id');
38
42
$.ajax({type:'POST',
39
43
url:'admin-ajax.php',
40
44
data:'action=hookpress_get_fields&hook='+hook+'&type='+type,
41
45
beforeSend:function(){
42
- getTb() .find('#newfields').html('<div class="webhooks-spinner"> </div>');
46
+ tb .find('#newfields').html('<div class="webhooks-spinner"> </div>');
43
47
},
44
48
success:function(html){
45
- getTb() .find('#newfields').html(html)
49
+ tb .find('#newfields').html(html)
46
50
},
47
51
dataType:'html'}
48
52
)
49
53
};
50
54
51
55
var getEditHooks = function getEditHooks() {
52
- var type = getTb().find('.newtype:checked').attr('id');
56
+ console.log('getEditHooks');
57
+ var tb = getTb();
58
+ var type = tb.find('.newtype:checked').attr('id');
53
59
if (type == 'action') {
54
- getTb() .find('#action_or_filter').text('<?php _e ("Action: " ,'hookpress ' );?> ');
55
- getTb() .find('#filtermessage').hide();
60
+ tb .find('#action_or_filter').text('<?php _e ("Action: " ,'hookpress ' );?> ');
61
+ tb .find('#filtermessage').hide();
56
62
}
57
63
if (type == 'filter') {
58
- getTb() .find('#action_or_filter').text('<?php _e ("Filter: " ,'hookpress ' );?> ');
59
- getTb() .find('#filtermessage').show();
64
+ tb .find('#action_or_filter').text('<?php _e ("Filter: " ,'hookpress ' );?> ');
65
+ tb .find('#filtermessage').show();
60
66
}
61
67
$.ajax({type:'POST',
62
68
url:'admin-ajax.php',
63
69
data:'action=hookpress_get_hooks&type='+type,
64
70
beforeSend:function(){
65
- getTb() .find('#edithook').html('<div class="webhooks-spinner"> </div>');
71
+ tb .find('#edithook').html('<div class="webhooks-spinner"> </div>');
66
72
},
67
73
success:function(html){
68
- getTb() .find('#edithook').html(html);
74
+ tb .find('#edithook').html(html);
69
75
getEditFields();
70
76
},
71
77
dataType:'html'}
72
78
)
73
79
}
74
80
75
81
var getEditFields = function getEditFields() {
76
- var hook = getTb().find('#edithook').val();
77
- var type = getTb().find('.newtype:checked').attr('id');
82
+ console.log('getEditFields');
83
+ var tb = getTb();
84
+ var hook = tb.find('#edithook').val();
85
+ var type = tb.find('.newtype:checked').attr('id');
78
86
$.ajax({type:'POST',
79
87
url:'admin-ajax.php',
80
88
data:'action=hookpress_get_fields&hook='+hook+'&type='+type,
81
89
beforeSend:function(){
82
- getTb() .find('#editfields').html('<div class="webhooks-spinner"> </div>');
90
+ tb .find('#editfields').html('<div class="webhooks-spinner"> </div>');
83
91
},
84
92
success:function(html){
85
- getTb() .find('#editfields').html(html);
93
+ tb .find('#editfields').html(html);
86
94
},
87
95
dataType:'html'}
88
96
)
89
97
};
90
98
91
99
var editSubmit = function editSubmit() {
92
- if (!getTb().find('#editfields').val()) {
93
- getTb().find('#editindicator').html('<small><?php _e ("You must select at least one field to send. " ,"hookpress " );?> </small>');
100
+ console.log('editSubmit');
101
+ var tb = getTb();
102
+ if (!tb.find('#editfields').val()) {
103
+ tb.find('#editindicator').html('<small><?php _e ("You must select at least one field to send. " ,"hookpress " );?> </small>');
94
104
return;
95
105
}
96
- if (!/^https?:\/\/\w+/.test(getTb() .find('#editurl').val())) {
97
- getTb() .find('#editindicator').html('<small><?php _e ("Please enter a valid URL. " ,"hookpress " );?> </small>');
106
+ if (!/^https?:\/\/\w+/.test(tb .find('#editurl').val())) {
107
+ tb .find('#editindicator').html('<small><?php _e ("Please enter a valid URL. " ,"hookpress " );?> </small>');
98
108
return;
99
109
}
100
110
101
- getTb() .find('#editindicator').html('<div class="webhooks-spinner"> </div>');
111
+ tb .find('#editindicator').html('<div class="webhooks-spinner"> </div>');
102
112
103
- id = getTb() .find('#edit-hook-id').val();
113
+ id = tb .find('#edit-hook-id').val();
104
114
105
115
$.ajax({type: 'POST',
106
116
url:'admin-ajax.php',
107
117
data:'action=hookpress_add_fields'
108
- +'&fields='+getTb() .find('#editfields').val().join()
109
- +'&url='+getTb() .find('#editurl').val()
110
- +'&type='+getTb() .find('.newtype:checked').attr('id')
111
- +'&hook='+getTb() .find('#edithook').val()
112
- +'&enabled='+getTb() .find('#enabled').val()
118
+ +'&fields='+tb .find('#editfields').val().join()
119
+ +'&url='+tb .find('#editurl').val()
120
+ +'&type='+tb .find('.newtype:checked').attr('id')
121
+ +'&hook='+tb .find('#edithook').val()
122
+ +'&enabled='+tb .find('#enabled').val()
113
123
+'&id='+id
114
- +'&_nonce='+getTb() .find('#submit-nonce').val(),
124
+ +'&_nonce='+tb .find('#submit-nonce').val(),
115
125
beforeSend:function(){
116
- getTb() .find('#editsubmit').hide();
117
- getTb() .find('#editcancel').hide()
126
+ tb .find('#editsubmit').hide();
127
+ tb .find('#editcancel').hide()
118
128
},
119
129
success:function(html){
120
- getTb() .find('#editsubmit').show();
121
- getTb() .find('#editcancel').show()
122
- getTb() .find('#editindicator').html('');
130
+ tb .find('#editsubmit').show();
131
+ tb .find('#editcancel').show()
132
+ tb .find('#editindicator').html('');
123
133
if (/^ERROR/.test(html))
124
- getTb() .find('#editindicator').html(html);
134
+ tb .find('#editindicator').html(html);
125
135
else if (!html)
126
- getTb() .find('#editindicator').html('<?php _e ("There was an unknown error. " ,"hookpress " );?> ');
136
+ tb .find('#editindicator').html('<?php _e ("There was an unknown error. " ,"hookpress " );?> ');
127
137
else {
128
138
$('#'+id).replaceWith(html);
129
139
tb_init('a.thickbox, area.thickbox, input.thickbox');
135
145
};
136
146
137
147
var enforceFirst = function enforceFirst() {
138
- var type = getTb().find('.newtype:checked').attr('id');
148
+ console.log('enforceFirst');
149
+ var tb = getTb();
150
+ var type = tb.find('.newtype:checked').attr('id');
139
151
if (type == 'action')
140
152
return;
141
- getTb() .find('option.first').attr('selected',true);
153
+ tb .find('option.first').attr('selected',true);
142
154
}
143
155
144
156
var newSubmit = function newSubmit() {
145
- if (!getTb().find('#newfields').val()) {
146
- getTb().find('#newindicator').html('<small><?php _e ("You must select at least one field to send. " ,"hookpress " );?> </small>');
157
+ console.log('newSubmit');
158
+ var tb = getTb();
159
+ if (!tb.find('#newfields').val()) {
160
+ tb.find('#newindicator').html('<small><?php _e ("You must select at least one field to send. " ,"hookpress " );?> </small>');
147
161
return;
148
162
}
149
- if (!/^https?:\/\/\w+/.test(getTb() .find('#newurl').val())) {
150
- getTb() .find('#newindicator').html('<small><?php _e ("Please enter a valid URL. " ,"hookpress " );?> </small>');
163
+ if (!/^https?:\/\/\w+/.test(tb .find('#newurl').val())) {
164
+ tb .find('#newindicator').html('<small><?php _e ("Please enter a valid URL. " ,"hookpress " );?> </small>');
151
165
return;
152
166
}
153
167
154
- getTb() .find('#newindicator').html('<div class="webhooks-spinner"> </div>');
168
+ tb .find('#newindicator').html('<div class="webhooks-spinner"> </div>');
155
169
156
170
$.ajax({type: 'POST',
157
171
url:'admin-ajax.php',
158
172
data:'action=hookpress_add_fields'
159
- +'&fields='+getTb() .find('#newfields').val().join()
160
- +'&url='+getTb() .find('#newurl').val()
161
- +'&type='+getTb() .find('.newtype:checked').attr('id')
162
- +'&hook='+getTb() .find('#newhook').val()
163
- +'&_nonce='+getTb() .find('#submit-nonce').val(),
173
+ +'&fields='+tb .find('#newfields').val().join()
174
+ +'&url='+tb .find('#newurl').val()
175
+ +'&type='+tb .find('.newtype:checked').attr('id')
176
+ +'&hook='+tb .find('#newhook').val()
177
+ +'&_nonce='+tb .find('#submit-nonce').val(),
164
178
beforeSend:function(){
165
- getTb() .find('#newsubmit').hide();
166
- getTb() .find('#newcancel').hide()
179
+ tb .find('#newsubmit').hide();
180
+ tb .find('#newcancel').hide()
167
181
},
168
182
success:function(html){
169
- getTb() .find('#newsubmit').show();
170
- getTb() .find('#newcancel').show()
171
- getTb() .find('#newindicator').html('');
183
+ tb .find('#newsubmit').show();
184
+ tb .find('#newcancel').show()
185
+ tb .find('#newindicator').html('');
172
186
if (/^ERROR/.test(html))
173
- getTb() .find('#newindicator').html(html);
187
+ tb .find('#newindicator').html(html);
174
188
else if (!html)
175
- getTb() .find('#newindicator').html('<?php _e ("There was an unknown error. " ,"hookpress " );?> ');
189
+ tb .find('#newindicator').html('<?php _e ("There was an unknown error. " ,"hookpress " );?> ');
176
190
else {
177
191
var newhook = $(html);
178
192
newhook.css('background-color','rgb(255, 251, 204)');
@@ -189,6 +203,7 @@ function(){newhook.css('background-color','transparent')});
189
203
};
190
204
191
205
var deleteHook = function deleteHook(id) {
206
+ console.log('deleteHook');
192
207
var nonce = $('#delete-nonce-' + id).val();
193
208
$.ajax({type: 'POST',
194
209
url:'admin-ajax.php',
@@ -206,6 +221,7 @@ function(){newhook.css('background-color','transparent')});
206
221
}
207
222
208
223
var setHookEnabled = function setHookEnabled(id, nonce, boolean) {
224
+ console.log('setHookEnabled');
209
225
$.ajax({type: 'POST',
210
226
url:'admin-ajax.php',
211
227
beforeSend:function(){$('#' + id + ' span.edit').html('<div class="webhooks-spinner"> </div>')},
@@ -226,15 +242,29 @@ function(){newhook.css('background-color','transparent')});
226
242
}
227
243
228
244
var setupEditHook = function setupEditHook(id) {
245
+ console.log('setupEditHook');
246
+ var tb = getTb();
229
247
$.ajax({type: 'POST',
230
248
url:'admin-ajax.php',
231
249
data:'action=hookpress_edit_hook&id='+id,
232
- success:function(html){
233
- $('#TB_ajaxContent').html(html);
234
- getTb().find('#edithook').change(getEditFields);
235
- getTb().find('#editfields').change(enforceFirst);
236
- getTb().find('#editsubmit').click(editSubmit);
237
- getTb().find('#editcancel').click(tb_remove);
250
+ success: function(html){
251
+ $('#TB_ajaxContent').html(html)
252
+ .find('.newtype').change(getEditHooks).end()
253
+ .find('#edithook').change(getEditFields).end()
254
+ .find('#editfields').change(enforceFirst).end()
255
+ .find('#editsubmit').click(editSubmit).end()
256
+ .find('#editcancel').click(tb_remove);
257
+
258
+ var type = $('#TB_ajaxContent').find('.newtype:checked').attr('id');
259
+ if (type == 'action') {
260
+ $('#TB_ajaxContent').find('#action_or_filter').text('<?php _e ("Action: " ,'hookpress ' );?> ');
261
+ $('#TB_ajaxContent').find('#filtermessage').hide();
262
+ }
263
+ if (type == 'filter') {
264
+ $('#TB_ajaxContent').find('#action_or_filter').text('<?php _e ("Filter: " ,'hookpress ' );?> ');
265
+ $('#TB_ajaxContent').find('#filtermessage').show();
266
+ }
267
+
238
268
},
239
269
dataType:'html'}
240
270
);
@@ -253,31 +283,32 @@ function(){newhook.css('background-color','transparent')});
253
283
});
254
284
255
285
var setEvents = function setEvents() {
256
- $(document).on('change','#TB_window .newtype',getHooks);
257
- $(document).on('change','#TB_window #newhook',getFields);
258
- $(document).on('change','#TB_window #newfields',enforceFirst);
259
- $(document).on('click','#TB_window #newsubmit',newSubmit);
260
- $(document).on('click','#TB_window #newcancel',tb_remove);
261
-
262
- $(document).on('click', '#webhooks .delete', function(e){
263
- var id = e.currentTarget.id.replace('delete','');
264
- deleteHook(id);
265
- });
266
- $(document).on('click', '#webhooks .edit', function(e){
267
- var id = e.currentTarget.id.replace('edit','');
268
- if(id){setupEditHook(id);}
269
- });
270
-
271
- $(document).on('click', '#webhooks .on', function(e){
272
- var id = e.currentTarget.id.replace('on','');
273
- var nonce = $('#action-nonce-' + id).val();
274
- if(id && nonce){setHookEnabled(id, nonce, 'false');}
275
- });
276
- $(document).on('click', '#webhooks .off', function(e){
277
- var id = e.currentTarget.id.replace('off','');
278
- var nonce = $('#action-nonce-' + id).val();
279
- if(id&&nonce){setHookEnabled(id, nonce, 'true');}
280
- });
286
+ $(document.body)
287
+ .on('change','#TB_window .newtype',getHooks)
288
+ .on('change','#TB_window #newhook',getFields)
289
+ .on('change','#TB_window #newfields',enforceFirst)
290
+ .on('click','#TB_window #newsubmit',newSubmit)
291
+ .on('click','#TB_window #newcancel',tb_remove);
292
+
293
+ $('#webhooks')
294
+ .on('click', '.delete', function(e){
295
+ var id = e.currentTarget.id.replace('delete','');
296
+ deleteHook(id);
297
+ })
298
+ .on('click', '.edit', function(e){
299
+ var id = e.currentTarget.id.replace('edit','');
300
+ if(id){setupEditHook(id);}
301
+ })
302
+ .on('click', '.on', function(e){
303
+ var id = e.currentTarget.id.replace('on','');
304
+ var nonce = $('#action-nonce-' + id).val();
305
+ if(id && nonce){setHookEnabled(id, nonce, 'false');}
306
+ })
307
+ .on('click', '.off', function(e){
308
+ var id = e.currentTarget.id.replace('off','');
309
+ var nonce = $('#action-nonce-' + id).val();
310
+ if(id&&nonce){setHookEnabled(id, nonce, 'true');}
311
+ });
281
312
}
282
313
283
314
})(jQuery);
0 commit comments