PluginProbe
WP Docs / 2.3.2
WP Docs v2.3.2
2.3.3 2.3.2 trunk 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1
wp-docs / js / front-scripts.js

front-scripts.js in WP Docs 2.3.2, at js/front-scripts.js

362 lines 8.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // JavaScript Document
2
3
4
5
6 jQuery(document).ready(function($){
7
8
9 var is_pro = (wpdocs.wpdocs_pro=='1');
10 var history_state = wpdocs.is_ajax_url;
11
12 /*if(wpdocs.restriction_load){
13 $.blockUI({
14 message: wpdocs.block_ui,
15 css: {
16
17 }
18 });
19 setTimeout(function(){
20 $.unblockUI();
21 }, 1500);
22 }*/
23
24 setTimeout(function(){
25 if($('.empty-dir-files').length>0 && wpdocs.current_user_id>0 && wpdocs.del_from_front){
26 $.each($('.empty-dir-files'), function(){
27 $(this).parents().eq(2).find('.wp_docs_del_file').addClass('empty-dir').css('opacity', '1').show();
28 });
29 }
30
31 var dir_obj = $('div.wpdoc_container[data-dir="'+wpdocs.dir_id+'"]');
32 if(wpdocs.dir_id>0 && dir_obj.length>0){
33 $('html, body').animate({
34 scrollTop: dir_obj.offset().top-240
35 }, 100);
36 }
37 }, 500);
38
39
40
41 function wpd_load_dir_simple(dir_id){
42
43 //console.log(dir_id);
44
45 var separator = '?';
46 if(wpdocs.this_url.includes('?')){
47 separator = '&';
48 }
49 if(dir_id === 0){
50
51 window.location.href = wpdocs.this_url;
52
53 }else{
54
55 window.location.href = wpdocs.this_url+separator+'dir='+dir_id;
56
57 }
58 }
59
60 $('body').on('click', '.file_wrapper.is_dir, .wpd_bread_item', function(e){
61
62 e.preventDefault();
63 var linked_id = $(this).data('linked');
64 var dir_id = (linked_id?linked_id:$(this).data('id'));
65 var linked_url = $(this).data('guid');
66 var parent_container = $(this).parents('div.wpdoc_container:first');
67 var home_id = parent_container.data('home');
68
69 if(linked_url && !linked_id){
70 window.open(linked_url, '_blank').focus();
71 return;
72 }
73
74 if(is_pro && wpdocs.is_ajax=='1'){
75
76 wpd_load_dir_ajax(dir_id, parent_container);
77
78 }else{
79
80
81 wpd_load_dir_simple(dir_id);
82
83 }
84
85 });
86
87
88
89
90
91
92 $('body').on('mouseover','figure.file_view:not(.selected)', function(){
93
94 $(this).addClass('bg-dark text-white rounded');
95 $(this).find('.figure-caption').addClass('text-white');
96 });
97
98 $('body').on('mouseout','figure.file_view:not(.selected)', function(){
99 $(this).removeClass('bg-dark text-white rounded');
100 $(this).find('.figure-caption').removeClass('text-white');
101 });
102
103
104
105 $('body').on('dblclick','div.list_view figure.file_view', function(e){
106
107 //if(wpdocs.del_from_front){
108 e.preventDefault();
109
110 if($(this).find('a').length>0){
111 window.open($(this).find('a').attr('href'), '_blank');
112 }
113
114 //}
115 });
116
117 $('body').on('dblclick','tr.file_view', function(e){
118 //if(wpdocs.del_from_front){
119 e.preventDefault();
120 if(typeof $(this).data('url')!='undefined' && $(this).data('url')!=''){
121 //window.open($(this).data('url'), '_blank');
122 }
123 //}
124 });
125
126 $('body').on('click','tr.file_view', function(e){
127
128 var this_parent = $(this).parents('.wpdoc_container:first');
129
130 if(this_parent.data('del_from_front')){
131
132
133 }else{
134 e.preventDefault();
135 if(typeof $(this).data('url')!='undefined' && $(this).data('url')!=''){
136 window.open($(this).data('url'), '_blank');
137 }
138 }
139
140 });
141
142 $('body').on('click','figure.file_view', function(e){
143
144 var this_parent = $(this).parents('.wpdoc_container:first');
145 var is_dir = $(this).parent().hasClass('is_dir');
146
147 //console.log(this_parent);
148 //console.log(this_parent.data('del_from_front'));
149 //console.log(!is_dir && this_parent.data('del_from_front'));
150 if(!is_dir && this_parent.data('del_from_front')!=''){
151
152
153 e.preventDefault();
154
155 this_parent.find('figure.file_view').removeClass('bg-dark text-white rounded selected');
156 this_parent.find('figure.file_view').find('.figure-caption').removeClass('text-white');
157
158
159
160 $(this).addClass('bg-dark text-white rounded selected');
161 $(this).find('.figure-caption').addClass('text-white');
162
163 if($('figure.file_view.selected').length > 0 && wpdocs.current_user_id>0){
164 this_parent.find('.wp_docs_del_file').show();
165 this_parent.find('.wp_docs_del_file').css('opacity', '1');
166 }else{
167 this_parent.find('.wp_docs_del_file').css('opacity', '0.5');
168 this_parent.find('.wp_docs_del_file').hide();
169
170 }
171
172 this_parent.find('.wpd_del_file_id').val($(this).parents('.is_file:first').data('id'));
173
174
175
176 }else{
177 $(this).trigger('dblclick');
178 }
179 });
180
181 $('body').on('click','figure.file_view figcaption', function(e){
182 var this_parent = $(this).parents('.wpdoc_container:first');
183
184 if(this_parent.data('del_from_front')){
185 }else{
186 if($(this).parent().find('a').length>0){
187 window.open($(this).parent().find('a').attr('href'), '_blank');
188 }
189 }
190 });
191
192
193
194
195
196
197
198
199 $('body').on('click','.folder_view_btn', function(){
200
201 var this_view_link = $(this);
202
203 //console.log(this_view_link);
204
205 var parent_container = this_view_link.parents('div.wpdoc_container:first');
206
207 //console.log(parent_container);
208
209 parent_container.find('.folder_view').addClass('d-none');
210 var data_class = $(this).data('source');
211 parent_container.find('.'+data_class).removeClass('d-none');
212
213
214 });
215
216
217
218
219 if ( typeof wp !== 'undefined' && wp.media && wp.media.editor) {
220 $('body').on('click','.wpdocs-front-add-media:visible', function(e) {
221 var parent_container = $(this).parents('div.wpdoc_container:first');
222
223 var id = parent_container.data('dir');
224 var this_id = parent_container.find('.wpdocs-front-add-media').prop('id');
225
226 e.preventDefault();
227
228 //alert(id);alert(attachment.id);return;
229
230 if(id != 0){
231
232
233 if(is_pro && wpdocs_apply_restriction(parent_container, 0)){
234 return;
235 };
236
237 var attachment_ids = [];
238 var add_file_status = true;
239
240 wp.media.editor.send.attachment = function(props, attachment) {
241
242 attachment_ids.push(attachment.id);
243
244 if(add_file_status){
245
246 add_file_status = false;
247
248 setTimeout(function(){
249
250 var data = {
251 'action': 'wpdocs_add_files',
252 'dir_id': id,
253 'files': attachment_ids,
254 'nonce': wpdocs.nonce,
255 };
256 $.post(wpdocs.ajax_url, data, function(response) {
257
258 if(is_pro){
259
260 wpd_load_dir_ajax(id, parent_container);
261
262 }else{
263
264
265 wpd_load_dir_simple(id);
266
267 }
268
269 });
270
271 })
272
273 }
274
275
276
277 };
278 //wp.media.editor.open($(this));
279 wp.media.editor.open(this_id);
280
281 }
282 //return false;
283 });
284
285 }
286
287 $('body').on('click', '.wpdocs-views a', function(){
288 //console.log($(this).data('source'));
289
290 var this_view_link = $(this);
291 var parent_container = this_view_link.parents('div.wpdoc_container');
292 var parent_dir = parent_container.data('home');
293
294 var data = {
295 'action': 'wpdocs_update_view',
296 'parent_dir': parent_dir,
297 'update_view': $(this).data('source'),
298 'nonce': wpdocs.nonce,
299 };
300 $.post(wpdocs.ajax_url, data, function(response) {
301
302 });
303 });
304
305 $('body').on("keyup", '.wpdocs-searchbox input', function() {
306
307
308 var value = $(this).val().toLowerCase();
309
310 var this_search_box = $(this);
311 var this_parent = this_search_box.parents('div.wpdoc_container:first');
312
313
314
315 if(this_parent.find(".row.folder_view:visible > div.table-responsive").length>0){
316 if(wpdocs.ajax_based_deep_search){
317 this_parent.find(".row.folder_view:visible > div table tbody tr.is_deep").addClass('is_deep_item').removeClass('is_deep');
318 }
319 this_parent.find(".row.folder_view:visible > div table tbody tr").filter(function() {
320 $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
321 });
322 if(value==''){
323 this_parent.find(".row.folder_view:visible > div table tbody tr.is_deep_item").addClass('is_deep').removeClass('is_deep_item');
324 }
325 }else{
326 this_parent.find(".row.folder_view:visible > div.is_deep").addClass('is_deep_item').removeClass('is_deep');
327 this_parent.find(".row.folder_view:visible > div").filter(function() {
328 $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
329 });
330 if(value==''){
331 this_parent.find(".row.folder_view:visible > div.is_deep_item").addClass('is_deep').removeClass('is_deep_item');
332 }
333 }
334
335
336 });
337
338 if(is_pro && wpdocs.restriction_load){
339
340 var rest_dir_id = wpdocs.restriction_id;
341 var parent_index = wpdocs.restriction_container;
342
343 var parent_container = $('div.wpdoc_container').eq(parent_index);
344 var parent_container_dir = parent_container.data('dir');
345
346 if(parent_container_dir != rest_dir_id){
347
348 wpd_load_dir_ajax(rest_dir_id, parent_container);
349
350 }
351
352
353 wpdocs_disable_container(rest_dir_id);
354
355 history.pushState({}, '', wpdocs.this_url);
356
357
358 }
359
360
361
362 });