PageSourceSearch

https://riaz.ch/wp-content/plugins/bsk-pdf-manager-pro/js/bsk_pdf_manager_pro.js?ver=1782116256

js riaz.ch collected 2026-10-01 13:00:56 UTC 95,041 bytes, 1,960 lines download raw bytes

1
2/*
3 * Version: 3.7
4 */
5jQuery(document).ready( function($) {
6    
7    /*
8      * PDFs Dropdown
9      */
10    $(".bsk-pdfm-output-container").on("change", ".bsk-pdfm-pdfs-dropdown", function( e ){
11        
12        var output_container = $(this).parents(".bsk-pdfm-output-container");
13        
14        var url = $(this).val();
15        
16        if( url && output_container.find(".bsk-pdfm-statistics-ajax-nonce").length &&
17            output_container.find( ".bsk_pdfm_settings_enalbe_permalink_cls" ).val() < 1 ){
18            
19            //do not do statics by ajax if permalink enabled
20            
21            var ajax_nonce = output_container.find(".bsk-pdfm-statistics-ajax-nonce").val();
22            var pdf_id = $(this).find(":selected").attr("id");
23            if( pdf_id == "" ){
24                //console.log( 'Invalid PDF id' );
25                return;
26            }
27            var pdf_id_array = pdf_id.split('-');
28            var pdf_id_int = parseInt( pdf_id_array[pdf_id_array.length - 1] );
29            if( pdf_id_int < 1 ){
30                //console.log( 'Invalid PDF id' );
31                return;
32            }
33            var action_val = 'pdfs_statistics_update_download_count';
34            var data = { action: action_val, id: pdf_id_int, nonce: ajax_nonce };
35
36            $.post( bsk_pdf_pro.ajaxurl, data, function(response) {
37                //do nothing
38            });
39
40        }
41
42		if ( url ) {
43			//window.open( url, target);
44            var form_ID_random = $( this ).data( "from-id" );
45
46            //if pdfjs enabled
47            var pdfjs_enabled = output_container.find( ".bsk-pdfm-pdfs-dropdown-pdfs-enable" ).val();
48            var permalink_enabled = output_container.find( ".bsk_pdfm_settings_enalbe_permalink_cls" ).val() > 0 ? true : false ;
49            var file_extension = bsk_pdfm_get_fiel_extension( url );
50            if ( pdfjs_enabled == 'YES' && permalink_enabled == false && file_extension == 'PDF' ) {
51                //change file's value
52                $( "#bsk_pdfm_pdfs_dropdown_to_open_ID_" + form_ID_random ).val( url );
53            } else {
54                //change form's action
55                $( "#bsk_pdfm_pdfs_dropdown_open_form_ID_" + form_ID_random ).prop( "action", url );
56                //remove all form's fields
57                $( "#bsk_pdfm_pdfs_dropdown_open_form_ID_" + form_ID_random ).find( ".bsk-pdfm-pdfs-dropdown-form-fields" ).remove();
58            }
59            $( "#bsk_pdfm_pdfs_dropdown_open_form_ID_" + form_ID_random ).submit();
60		}
61
62    });
63
64    function bsk_pdfm_get_fiel_extension(url) {
65        try {
66          const urlObj = new URL(url);
67          const pathname = urlObj.pathname;
68          
69          if (!pathname.includes('.')) {
70            return null;
71          }
72          
73          const filename = pathname.split('/').pop();
74          const extension = filename.split('.').pop();
75          
76          if (extension === filename) {
77            return null;
78          }
79          
80          return extension.toUpperCase();
81        } catch (error) {
82          console.error('Invalid URL:', error);
83          return null;
84        }
85      }
86    
87     /*
88      * Search bar
89      */
90    $(".bsk-pdfm-output-container, .bsk-pdfm-widget-output-container").on("keypress", ".bsk-pdfm-search-keywords", function( e ){
91        if( e.which == 13 ) {
92            $(this).parent().find(".bsk-pdfm-search-anchor").click();
93        }
94    });
95    
96     /*
97      * Category password
98      */
99    //can only be numbers & letters
100    $(".bsk-pdfm-output-container").on("keyup", ".bsk-pdfm-category-password", function( e ){
101        //only number & letters
102        this.value = this.value.replace(/[^0-9a-zA-Z]/g, '');
103    });
104    
105    $(".bsk-pdfm-output-container").on("keypress", ".bsk-pdfm-category-password", function( e ){
106        if( e.which == 13 ) {
107            $(this).parent().find(".bsk-pdfm-category-password-verify-anchor").click();
108        }
109    });
110    
111    /*
112     * PDFs ajax query
113     * Pagination, Search
114     * Category Password
115     */
116    $(".bsk-pdfm-output-container").on("click", ".bsk-pdfm-pagination a, .bsk-p
116dfm-search-input button, .bsk-pdfm-search-results a, .bsk-pdfm-category-password-verify-anchor, .bsk-pdfm-title-filter-anchor, .bsk-pdfm-extension-filter-anchor, .bsk-pdfm-tags-filter-anchor", { infinite_scrolling: false }, ajax_query_pdfs_function );
117    
118    $(".bsk-pdfm-output-container").on("change", ".bsk-pdfm-date-weekday-query-year, .bsk-pdfm-date-weekday-query-month, .bsk-pdfm-date-weekday-query-day, .bsk-pdfm-date-weekday-query-weekday", { infinite_scrolling: false }, ajax_query_pdfs_function );
119    
120    function ajax_query_pdfs_function( event ){
121
122        /* console.log( event );
123        console.log( event.infinite_scrolling ); */
124
125        var called_by_infinite_scrolling = false;
126        var output_container = '';
127        if ( event.infinite_scrolling != undefined && event.infinite_scrolling ) {
128            output_container = event.scrolling_container;
129            called_by_infinite_scrolling = true;
130        } else if ( event.data.infinite_scrolling == false ) {
131            output_container = $(this).parents(".bsk-pdfm-output-container");
132            called_by_infinite_scrolling = false;
133        } else {
134            console.log( 'Confused in ajax_query_pdfs_function');
135            return;
136        }
137
138        var shortcode_type = '';
139        var output = '';
140        if( output_container.hasClass("shortcode-pdfs") ){
141            shortcode_type = 'pdfs';
142        }else if( output_container.hasClass("shortcode-category") ){
143            shortcode_type = 'category';
144        }else if( output_container.hasClass("shortcode-selector") ){
145            shortcode_type = 'selector';
146        }else{
147            return;
148        }
149
150        if( output_container.hasClass( 'layout-ul' ) ){
151            output =  'ul';
152        }else if( output_container.hasClass( 'layout-ol' ) ){
153            output = 'ol';
154        }else if( output_container.hasClass( 'layout-columns' ) ){
155            output = 'columns';
156        }else if( output_container.hasClass( 'layout-dropdown' ) ){
157            output = 'dropdown';
158        }else{
159            return;
160        }
161
162        //clear error message
163        output_container.find(".bsk-pdfm-error-message").remove();
164        
165        var keywords_val = '';
166        var keywords_match_type_choice = 'PARTIALLY';
167        var search_cat_id_val = '';
168        var search_year_of_val = '';
169        var extension_filter_val = '';
170        var start_with = '';
171        var date_weekday_query_year = '';
172        var date_weekday_query_month = '';
173        var date_weekday_query_day = '';
174        var date_weekday_query_weekday = '';
175        var tags_filter_val = '';
176        
177        /*
178         * for extension filter
179         */
180        if ( called_by_infinite_scrolling == false && $(this).hasClass( "bsk-pdfm-extension-filter-anchor" ) ) {
181            if( $(this).hasClass("active") ){
182                return;
183            }
184            extension_filter_val = $(this).data("extension");
185            $(this).addClass( "bsk-pdfm-just-clicked" );
186            output_container.find(".bsk-pdfm-extension-filter-ajax-loader").css("display", "block");
187            
188            //refresh pagination
189            output_container.find(".bsk-pdfm-pagination").find("li").removeClass("active");
190        } else if ( output_container.find( ".bsk-pdfm-extension-filter-anchor.active" ).length > 0 ) {
191            extension_filter_val = output_container.find( ".bsk-pdfm-extension-filter-anchor.active" ).data("extension");
192        }
193        
194        /*
195         * for title filter
196         */
197        if ( called_by_infinite_scrolling == false &&  $(this).hasClass( "bsk-pdfm-title-filter-anchor" ) ) {
198            if( $(this).hasClass("active") ){
199                return;
200            }
201            start_with = $(this).data("start-with");
202            $(this).addClass( "bsk-pdfm-just-clicked" );
203            output_container.find(".bsk-pdfm-title-filter-ajax-loader").css("display", "block");
204            
205            //refresh pagination
206            output_container.find(".bsk-pdfm-pagination").find("li").removeClass("active");
207        } else if ( output_container.find( ".bsk-pdfm-title-filter-anchor.active" ).length > 0 ) {
208            start_with = output_container.find( ".bsk-pdfm-title-filter-anchor.active" ).data("start-with");
209        }
210        
211        /*
212         * for date weekday query filter
213         */
214        if ( output_container.find( ".bsk-pdfm-date-weekday-query-filter" ).length > 0 ) {
215            
216            if( output_container.find( ".bsk-pdfm-date-weekday-query-year" ).length > 0 ){
217                date_weekday_query_year = output_container.find( ".bsk-pdfm-date-weekday-query-year" ).val();
218            }
219            
220            if( output_container.find( ".bsk-pdfm-date-weekday-query-month" ).length > 0 ){
221                date_weekday_query_month = output_container.find( ".bsk-pdfm-date-weekday-query-month" ).val();
222            }
223            
224            if( output_container.find( ".bsk-pdfm-date-weekday-query-day" ).length > 0 ){
225                date_weekday_query_day = output_container.find( ".bsk-pdfm-date-weekday-query-day" ).val();
226            }
227            
228            if( output_container.find( ".bsk-pdfm-date-weekday-query-weekday" ).length > 0 ){
229                date_weekday_query_weekday = output_container.find( ".bsk-pdfm-date-weekday-query-weekday" ).val();
230            }
231            
232            if ( called_by_infinite_scrolling == false ) {
233                if( $(this).hasClass("bsk-pdfm-date-weekday-query-year") || 
234                    $(this).hasClass("bsk-pdfm-date-weekday-query-month") || 
235                    $(this).hasClass("bsk-pdfm-date-weekday-query-day") || 
236                    $(this).hasClass("bsk-pdfm-date-weekday-query-weekday") ){
237                    
238                    var date_weekday_query_filter_container = output_container.find(".bsk-p
238dfm-date-weekday-query-filter");
239                    date_weekday_query_filter_container.find(".bsk-pdfm-date-weekday-query-filter-ajax-loader").css( "display", "inline-block" );
240                }
241            }
242        }
243        
244        /*
245         * for tags filter
246         */
247        if ( called_by_infinite_scrolling == false && $(this).hasClass( "bsk-pdfm-tags-filter-anchor" ) ) {
248            if( $(this).hasClass("active") ){
249                return;
250            }
251            tags_filter_val = $(this).data("tagid");
252            $(this).addClass( "bsk-pdfm-just-clicked" );
253            output_container.find(".bsk-pdfm-tags-filter-ajax-loader").css("display", "block");
254            
255            //refresh pagination
256            output_container.find(".bsk-pdfm-pagination").find("li").removeClass("active");
257        } else if ( output_container.find( ".bsk-pdfm-tags-filter-anchor.active" ).length > 0 ) {
258            tags_filter_val = output_container.find( ".bsk-pdfm-tags-filter-anchor.active" ).data("tagid");
259        }
260
261        /*
262          for search bar 
263          */
264        if ( called_by_infinite_scrolling == false && ( $(this).hasClass("bsk-pdfm-search-anchor") || $(this).hasClass("bsk-pdfm-search-clear-anchor") ) ) {
265            var search_input_obj = $(this).parents(".bsk-pdfm-search-bar").find(".bsk-pdfm-search-input");
266            
267            if( $(this).hasClass("bsk-pdfm-search-clear-anchor") ){
268                search_input_obj.find(".bsk-pdfm-search-keywords").val( "" );
269                search_input_obj.find(".bsk-pdfm-year-dropdown").val( "" );
270                search_input_obj.find(".bsk-pdfm-category-dropdown").val( "" );
271            }
272            
273            var search_reulsts_label_obj = $(this).parents(".bsk-pdfm-search-bar").find(".bsk-pdfm-search-results");
274            search_reulsts_label_obj.css("display", "block");
275            search_reulsts_label_obj.find(".bsk-pdfm-searchbar-ajax-loader").css( "display", "inline-block" );
276            search_reulsts_label_obj.find(".bsk-pdfm-search-results-desc").css( "display", "none" );
277            
278            //refresh pagination
279            output_container.find(".bsk-pdfm-pagination").find("li").removeClass("active");
280        }
281        if( output_container.find( ".bsk-pdfm-search-bar" ).length > 0 ){
282            var search_input_obj = output_container.find(".bsk-pdfm-search-input");
283            keywords_val = search_input_obj.find(".bsk-pdfm-search-keywords").val();
284            keywords_val = $.trim( keywords_val );
285            keywords_input_placeholder = search_input_obj.find(".bsk-pdfm-search-keywords").attr("placeholder");
286            if( keywords_val == keywords_input_placeholder ){
287                keywords_val = '';
288            }
289            keywords_match_type_choice = $( "input[name='bsk_pdfm_search_keywords_match_choice']:checked" ).val();
290            if( search_input_obj.find(".bsk-pdfm-year-dropdown").length ){
291                search_year_of_val = search_input_obj.find(".bsk-pdfm-year-dropdown").val();
292            }
293            if( search_input_obj.find(".bsk-pdfm-category-dropdown").length ){
294                search_cat_id_val = search_input_obj.find(".bsk-pdfm-category-dropdown").val();
295            }
296        }
297        
298        /* 
299          * for pagination
300          */
301        var page_to_show = 1;
302        if ( called_by_infinite_scrolling == false && $(this).hasClass( "bsk-pdfm-pagination-anchor" ) ) { //pagination anchor
303            if( $(this).parent().hasClass("active") ){
304                //click on active pagination anchor
305                return;
306            }
307            page_to_show = $(this).data("page");
308            output_container.find(".bsk-pdfm-pagination-ajax-loader").css( "display", "inline-block" );
309        } else if ( output_container.find(".bsk-pdfm-pagination").length ) {
310            if( output_container.find(".bsk-pdfm-pagination").find("li.active").length ){
311                page_to_show = output_container.find(".bsk-pdfm-pagination").find("li.active").find("a").data("page");
312            }
313        } else if ( called_by_infinite_scrolling ) {
314            //{ infinite_scrolling: true, scrolling_container: scrolling_container_obj, header : header_obj,  current: current_page, max: max_page }
315            page_to_show = event.current;
316        }
317        
318        
319         /* 
320          * for verify password
321          */
322        var category_password_str = '';
323        if ( called_by_infinite_scrolling == false && $(this).hasClass( "bsk-pdfm-category-password-ver
323ify-anchor" ) ) { //verify password anchor
324            var password = $(this).parent().find(".bsk-pdfm-category-password").val();
325            password = $.trim( password );
326            if( password == "" ){
327                $(this).parent().find(".bsk-pdfm-category-password").val( "" );
328                $(this).parent().find(".bsk-pdfm-category-password").focus();
329                return;
330            }
331            var category_id = $(this).parents(".bsk-pdfm-category-password-form").data( "cat-id" );
332            var exist_password = output_container.find(".category-password-hidden-feild").val();
333            var exist_password_array = new Array();
334            var password_updated = false;
335            if( exist_password ){
336                exist_password_array = exist_password.split(',');
337                for( var i_password = 0; i_password < exist_password_array.length; i_password++){
338                    var category_n_password = exist_password_array[i_password];
339                    if( category_n_password.indexOf(category_id+':') != -1 ){
340                        exist_password_array[i_password] = category_id + ':' + password;
341                        password_updated = true;
342                    }
343                }
344            }
345            if( password_updated == false ){
346                exist_password_array.push( category_id + ':' + password );
347            }
348
349            category_password_str = exist_password_array.join(',');
350            output_container.find(".category-password-hidden-feild").val( category_password_str );
351            $(this).parent().find(".bsk-pdfm-category-password-verify-ajax-loader").css("display", "inline-block")
352        } else if ( output_container.find(".category-password-hidden-feild").length ) {
353            
354            category_password_str = output_container.find(".category-password-hidden-feild").val();
355        }
356
357        var ajax_nonce = output_container.find(".bsk-pdfm-" + shortcode_type + "-ajax-nonce").val();
358        var action_val = "pdfs_get_" + shortcode_type + "_" + output;
359        var data = { action: action_val, layout: output, nonce: ajax_nonce };
360        
361        //organise ajax parameters
362        output_container.find(".bsk-pdfm-shortcode-attr").each(function(index, value ){
363            var attr_name = $(this).data("attr_name");
364            data[attr_name] = $(this).val();
365        });
366        
367        //date weekday query filter
368        //will overwrite shortcode attributes 
369        if( date_weekday_query_year ){
370           data['year_of'] = date_weekday_query_year;
371        }
372        
373        if( date_weekday_query_month ){
374           data['month_of'] = date_weekday_query_month;
375        }
376        
377        if( date_weekday_query_day ){
378           data['day_of'] = date_weekday_query_day;
379        }
380        
381        if( date_weekday_query_weekday ){
382           data['weekday_of'] = date_weekday_query_weekday;
383        }
384        
385        //sear bar 
386        if( search_cat_id_val ){
387            data['search_cat_id'] = search_cat_id_val;
388            //means under search mode
389            //in this mode only search PDFs from the selected category so close hierarchical temporarily
390            data['hierarchical'] = 'no';
391        }
392        
393        if( search_year_of_val ){
394            data['year_of'] = search_year_of_val;
395        }
396        if( extension_filter_val ){
397            data['extension'] = extension_filter_val; 
398        }
399        if( tags_filter_val ){
400            data['tags_default'] = tags_filter_val;
401        }
402        data['title_start_with'] = start_with;
403        data['paged'] = page_to_show;
404        data['keywords'] = keywords_val;
405        data['keywords_match_type_choice'] = keywords_match_type_choice;
406        data['password'] = category_password_str;
407        data['infinite_scrolling_callback'] = called_by_infinite_scrolling ? 'infinite_scrolling' : 'ajax';
408        
409        /*
410          * for category selector
411          */
412        if( shortcode_type == 'selector' ){
413            data['action'] = "pdfs_get_category_" + output;
414            data['nonce'] = output_container.find(".bsk-pdfm-category-ajax-nonce").val();
415            data['id'] = output_container.find(".bsk-pdfm-category-selector-container").find(".bsk-pdfm-category-dropdown").val();
416            //unser selector mode for showing PDF results, hierarchical is always closed
417            data['hierarchical'] = 'no';
418            
419            if( output == 'dropdown' ){
420                data['option_group_label'] = 'HIDE';
421            }
422            
423        }
424        
425        /* infinite_scrolling ajax loader */
426        if ( called_by_infinite_scrolling == true ) {
427            var ajax_loader = event.header.find( ".bsk_pdfm_infinite_scrolling_header_ajax_loader" ).html();
428            var ajax_loader_p = '<p class="bsk_pdfm_infinitive_scrolling_ajax_loader">' + ajax_loader + 'LOADING</p>';
429
430            var pdfs_list_container = output_container.find( ".bsk-pdfm-pdfs-" + output + "-list" );
431            pdfs_list_container.append( ajax_loader_p );
432        }
433        
434        //console.log( data );
435
436        $.post( bsk_pdf_pro.ajaxurl, data, function(response) {
437
438            /* console.log( response );
439            return; */
440            
441            /* infinite_scrolling ajax loader */
442            if ( called_by_infinite_scrolling == true ) {
443                output_container.find( ".bsk_pdfm_infinitive_scrolling_ajax_loader" ).remove();
444            }
445            
446            var return_data = $.parseJSON( response );
447            
448            /*
449             * process extension filter
450             */
451            if( output_container.find(".bsk-pdfm-extension-filter-container").length ){
452                
453                var extension_filter_container = output_container.find(".bsk-pdfm-extension-filter-container");
454                extension_filter_container.find(".bsk-pdfm-extension-filter-ajax-loader").css("display", "none");
455                
456                if( extension_filter_container.find(".bsk-pdfm-just-clicked").length ){
457                    
458                    extension_filter_container.find( ".bsk-pdfm-extension-filter-anchor" ).removeClass( 'active' );
459                    extension_filter_container.find( ".bsk-pdfm-just-clicked" ).addClass( 'active' );
460                    extension_filter_container.find( ".bsk-pdfm-extension-filter-anchor" ).removeClass( 'bsk-pdfm-just-clicked' );
461                }
462            }
463            
464            /*
465             * process title filter
466             */
467            if( output_container.find(".bsk-pdfm-title-filter-container").length ){
468                
469                var title_filter_container = output_container.find(".bsk-pdfm-title-filter-container");
470                title_filter_container.find(".bsk-pdfm-title-filter-ajax-loader").css("display", "none");
471                
472                if( title_filter_container.find(".bsk-pdfm-just-clicked").length ){
473                    
474                    title_filter_container.find( ".bsk-pdfm-title-filter-anchor" ).removeClass( 'active' );
475                    title_filter_container.find( ".bsk-pdfm-just-clicked" ).addClass( 'active' );
476                    title_filter_container.find( ".bsk-pdfm-title-filter-anchor" ).removeClass( 'bsk-pdfm-just-clicked' );
477                }
478            }
479            
480            /*
481             * process date weekday query filter
482             */
483            if( output_container.find(".bsk-pdfm-date-weekday-query-filter").length ){
484                var date_weekday_query_filter_container = output_container.find(".bsk-pdfm-date-weekday-query-filter");
485                date_weekday_query_filter_container.find(".bsk-pdfm-date-weekday-query-filter-ajax-loader").css( "display", "none" );
486            }
487            
488            /*
489             * process tags filter
490             */
491            if( output_container.find(".bsk-pdfm-tags-filter-container").length ){
492                
493                var tags_filter_container = output_container.find(".bsk-pdfm-tags-filter-container");
494                tags_filter_container.find(".bsk-pdfm-tags-filter-ajax-loader").css("display", "none");
495                
496                if( tags_filter_container.find(".bsk-pdfm-just-clicked").length ){
497                    
498                    tags_filter_container.find( ".bsk-pdfm-tags-filter-anchor" ).removeClass( 'active' );
499                    tags_filter_container.find( ".bsk-pdfm-just-clicked" ).addClass( 'active' );
500                    tags_filter_container.find( ".bsk-pdfm-tags-filter-anchor" ).removeClass( 'bsk-pdfm-just-clicked' );
501                }
502            }
503            
504            /*
505              * process search bar
506            */
507            if( output_container.find(".bsk-pdfm-search-results").length ){
508                
509                var search_reulsts_container = output_container.find(".bsk-pdfm-search-results");
510                
511                search_reulsts_container.find(".bsk-pdfm-searchbar-ajax-loader").css("display", "none");
512                if( keywords_val == "" && search_year_of_val == "" && search_cat_id_val == "" ){
513                    search_reulsts_container.css("display", "none");
514                }else{
515                    search_reulsts_container.css("display", "block");
516                    search_reulsts_container.find(".bsk-pdfm-search-clear-anchor").css("display", "inline-block");
517                }
518                
519            }
520            
521
522            /*
523             * output for pdfs
524             */
525            if( shortcode_type == 'pdfs' ){
526                output_container.find(".bsk-pdfm-date-filter").remove();
527                output_container.find(".bsk-pdfm-pagination").remove();
528                
529                if( output == 'dropdown' ){
530                    var dropdown_obj = output_container.find( ".bsk-pdfm-pdfs-dropdown" );
531                    dropdown_obj.html( return_data.pdfs );
532                    dropdown_obj.css( "display", "block" );
533                    output_container.find(".bsk-pdfm-date-filter").remove();
534                    
535                    if( return_data.error_message ){
536                        $( return_data.error_message ).insertBefore( dropdown_obj );
537                    }else{
538                        $( return_data.date_filter ).insertBefore( dropdown_obj );
539                        //desc
540                        if( output_container.find(".bsk-pdfm-count-desc-container").length ){
541                            output_container.find(".bsk-pdfm-count-desc-container").find( "h3" ).html( return_data.results_desc );
542                        }
543                    }
544                    output_container.find(".bsk-pdfm-pdfs-dropdown").focus();
545                }else if( output == 'ul' || output == 'ol' ){
546                    var pdfs_list_container = output_container.find(".bsk-pdfm-pdfs-" + output + "-list");
547                    if ( called_by_infinite_scrolling == false ) {
548                        pdfs_list_container.html( "" );
549                    }
550                    if( return_data.error_message ){
551                        $( return_data.error_message ).insertBefore( pdfs_list_container );
552                    }else{
553                        if ( called_by_infinite_scrolling == false ) {
554                            pdfs_list_container.html( return_data.pdfs );
555                            //Need to refresh infinite scrolling header...
556                            //console.log( 'Need to refresh infinite scrolling header...' );
557                            output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_current_page" ).val( 1 );
558                            output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_page_max" ).val( return_data.page_max );
559                            output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_total" ).val( return_data.pdfs_count );
560                        } else {
561                            pdfs_list_container.append( return_data.pdfs );
562                            //change status control for infinite_scrolling
563                            //{ infinite_scrolling: true, scrolling_container: scrolling_container_obj, header : header_obj,  current: current_page, max: max_page }
564                            event.header.find( ".bsk_pdfm_infinite_scrolling_header_current_page" ).val( page_to_show );
565                            event.header.find( ".bsk_pdfm_infinite_scrolling_header_loading" ).val( 0 );
566                        }
567                        $( return_data.date_filter ).insertBefore( pdfs_list_container );
568                        $( return_data.pagination ).insertAfter( pdfs_list_container );
569                        
570                        //desc
571                        if( output_container.find(".bsk-pdfm-count-desc-container").length ){
572                            output_container.find(".bsk-pdfm-count-desc-container").find( "h3" ).html( return_data.results_desc );
573                        }
574                    }                    
575                }else if( output == 'columns' ){
576                    var pdfs_columns_container = output_container.find(".bsk-pdfm-pdfs-columns-list");
577                    if ( called_by_infinite_scrolling == false ) {
578                        pdfs_columns_container.html( "" );
579                    }
580                    
581                    if( return_data.error_message ){
582                        $( return_data.error_message ).insertBefore( pdfs_columns_container );
583                    }else{
584                        if ( called_by_infinite_scrolling == false ) {
585                            pdfs_columns_container.html( return_data.pdfs );
586                            //Need to refresh infinite scrolling header...
587                            //console.log( 'Need to refresh infinite scrolling header...' );
588                            output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_current_page" ).val( 1 );
589                            output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_page_max" ).val( return_data.page_max );
590                            output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_total" ).val( return_data.pdfs_count );
591                        } else {
592                            pdfs_columns_container.append( return_data.pdfs );
593                            //change status control for infinite_scrolling
594                            //{ infinite_scrolling: true, scrolling_container: scrolling_container_obj, header : header_obj,  current: current_page, max: max_page }
595                            event.header.find( ".bsk_pdfm_infinite_scrolling_header_current_page" ).val( page_to_show );
596                            event.header.find( ".bsk_pdfm_infinite_scrolling_header_loading" ).val( 0 );
597                        }
598                        $( return_data.date_filter ).insertBefore( pdfs_columns_container );
599                        $( return_data.pagination ).insertAfter( pdfs_columns_container );
600                        
601                        //desc
602                        if( output_container.find(".bsk-pdfm-count-desc-container").length ){
603                            output_container.find(".bsk-pdfm-count-desc-container").find( "h3" ).html( return_data.results_desc );
604                        }
605                    }
606                    
607                    //call function to re-set column height
608                    //if have fetured image then need call function when all images loaded
609                    if( output_container.find(".bsk-pdfm-pdfs-columns-list").find(".bsk-pdfm-pdf-link-for-featured-image img").length > 0 ){
610                        output_container.find(".bsk-pdfm-pdfs-columns-list").find(".bsk-pdfm-pdf-link-for-featured-image img").each(function(){
611                            $(this).on('load', function() { reset_columns_height_in_eacho_row(); /*console.log("image loaded correctly");*/ });
612                        });
613                    }else{
614                        reset_columns_height_in_eacho_row();
615                    }
616                }
617                
618                return;
619            }
620            
621            
622            
623            /*
624             * output for category
625             */
626            if( shortcode_type == 'category' ){
627
628                /* for infinite_scrolling, only support one category id */
629                if ( called_by_infinite_scrolling == false ) {
630                    output_container.find(".bsk-pdfm-date-filter").remove();
631                    output_container.find(".bsk-pdfm-pagination").remove();
632                    output_container.find(".bsk-pdfm-category-output").remove();
633                }
634                
635                var obj_insert_before = output_container.find(".bsk-p
635dfm-category-shortcode-attr");
636                if( output_container.find(".bsk-pdfm-credit-link-container").length > 0 ){
637                    obj_insert_before = output_container.find(".bsk-pdfm-credit-link-container");
638                }
639                
640                output_container.find(".bsk-pdfm-category-password-form").remove();
641                
642                if( output == 'dropdown' ){
643                    if( return_data.error_message ){
644                        $( return_data.error_message ).insertBefore( obj_insert_before );
645
646                        return;
647                    }
648                    $( return_data.category_out ).insertBefore( obj_insert_before );
649
650                    //desc
651                    if( output_container.find(".bsk-pdfm-count-desc-container").length ){
652                        output_container.find(".bsk-pdfm-count-desc-container").find( "h3" ).html( return_data.results_desc );
653                    }
654                    output_container.find(".bsk-pdfm-pdfs-dropdown").focus();
655                }else if( output == 'ul' || output == 'ol' ){
656                    if( return_data.error_message ){
657                        $( return_data.error_message ).insertBefore( obj_insert_before );
658
659                        return;
660                    }
661                    
662                    /* for infinite_scrolling, out put as only_output_pdfs = yes */
663                    if ( called_by_infinite_scrolling == false ) {
664                        $( return_data.category_out ).insertBefore( obj_insert_before );
665                        $( return_data.pagination ).insertBefore( obj_insert_before );
666
667                        //Need to refresh infinite scrolling header...
668                        //console.log( 'Need to refresh infinite scrolling header...' );
669                        output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_current_page" ).val( 1 );
670                        output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_page_max" ).val( return_data.page_max );
671                        output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_total" ).val( return_data.pdfs_count );
672                    } else {
673                        //append
674                        var pdfs_list_container = output_container.find(".bsk-pdfm-pdfs-" + output + "-list");
675                        pdfs_list_container.append( return_data.category_out );
676
677                        //reset list-item-odd, list-item-even class
678                        var list_item_no = 1;
679                        pdfs_list_container.find( ".bsk-pdfm-list-item" ).each( function() {
680                            $( this ).removeClass( "list-item-odd" );
681                            $( this ).removeClass( "list-item-even" );
682
683                            if ( list_item_no % 2 == 0 ) {
684                                $( this ).addClass( "list-item-even" );
685                            } else {
686                                $( this ).addClass( "list-item-odd" );
687                            }
688                            list_item_no++;
689                        });
690
691                        //change status control for infinite_scrolling
692                        //{ infinite_scrolling: true, scrolling_container: scrolling_container_obj, header : header_obj,  current: current_page, max: max_page }
693                        event.header.find( ".bsk_pdfm_infinite_scrolling_header_current_page" ).val( page_to_show );
694                        event.header.find( ".bsk_pdfm_infinite_scrolling_header_loading" ).val( 0 );
695                    }
696
697                    //desc
698                    if( output_container.find(".bsk-pdfm-count-desc-container").length ){
699                        output_container.find(".bsk-pdfm-count-desc-container").find( "h3" ).html( return_data.results_desc );
700                    }
701                }else if( output == 'columns' ){
702                    if( return_data.error_message ){
703                        $( return_data.error_message ).insertBefore( obj_insert_before );
704
705                        return;
706                    }
707
708                    /* for infinite_scrolling, out put as only_output_pdfs = yes */
709                    if ( called_by_infinite_scrolling == false ) {
710                        $( return_data.category_out ).insertBefore( obj_insert_before );
711                        $( return_data.pagination ).insertBefore( obj_insert_before );
712
713                        //Need to refresh infinite scrolling header...
714                        //console.log( 'Need to refresh infinite scrolling header...' );
715                        output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_current_page" ).val( 1 );
716                        output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_page_max" ).val( return_data.page_max );
717                        output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_total" ).val( return_data.pdfs_count );
718                    } else {
719                        //append
720                        var pdfs_columns_list_container = output_container.find(".bsk-p
720dfm-pdfs-columns-list");
721                        pdfs_columns_list_container.append( return_data.category_out );
722                        
723                        //change status control for infinite_scrolling
724                        //{ infinite_scrolling: true, scrolling_container: scrolling_container_obj, header : header_obj,  current: current_page, max: max_page }
725                        event.header.find( ".bsk_pdfm_infinite_scrolling_header_current_page" ).val( page_to_show );
726                        event.header.find( ".bsk_pdfm_infinite_scrolling_header_loading" ).val( 0 );
727                    }
728
729                    //desc
730                    if( output_container.find(".bsk-pdfm-count-desc-container").length ){
731                        output_container.find(".bsk-pdfm-count-desc-container").find( "h3" ).html( return_data.results_desc );
732                    }
733                    
734                    //call function to re-set column height
735                    //if have fetured image then need call function when all images loaded
736                    if( output_container.find(".bsk-pdfm-pdfs-columns-list .bsk-pdfm-pdf-link-for-featured-image img").length > 0 ){
737                        output_container.find(".bsk-pdfm-pdfs-columns-list .bsk-pdfm-pdf-link-for-featured-image img").each(function(){
738                            $(this).on('load', function() { reset_columns_height_in_eacho_row(); /*console.log("image loaded correctly");*/ });
739                        });
740                    }else{
741                        reset_columns_height_in_eacho_row();
742                    }
743                }
744                
745                return;
746            } //end for output for category
747            
748            /*
749             * output for selector
750             */
751            if( shortcode_type == 'selector' ){
752                
753                /* for infinite_scrolling, only support one category id */
754                if ( called_by_infinite_scrolling == false ) {
755                    output_container.find(".bsk-pdfm-date-filter").remove();
756                    output_container.find(".bsk-pdfm-pagination").remove();
757                    output_container.find(".bsk-pdfm-count-desc-container").find("h3").html( "" );
758                    output_container.find(".bsk-pdfm-category-output").remove();
759                    output_container.find(".bsk-pdfm-category-description").remove();
760                }
761
762                if( output == 'dropdown' ){
763                    var obj_insert_before = output_container.find(".bsk-pdfm-pdfs-shortcode-attr");
764                    if( output_container.find(".bsk-pdfm-credit-link-container").length > 0 ){
765                        obj_insert_before = output_container.find(".bsk-pdfm-credit-link-container");
766                    }
767
768                    if( return_data.error_message ){
769                        $( return_data.error_message ).insertBefore( obj_insert_before );
770
771                        return;
772                    }
773                    
774                    $( return_data.category_out ).insertBefore( obj_insert_before );
775                    //desc
776                    if( output_container.find(".bsk-pdfm-count-desc-container").length ){
777                        output_container.find(".bsk-pdfm-count-desc-container").find( "h3" ).html( return_data.results_desc );
778                    }
779                    output_container.find(".bsk-pdfm-pdfs-dropdown").focus();
780                }else if( output == 'ul' || output == 'ol' ){
781                    var obj_insert_before = output_container.find(".bsk-pdfm-pdfs-shortcode-attr");
782                    if( output_container.find(".bsk-pdfm-credit-link-container").length > 0 ){
783                        obj_insert_before = output_container.find(".bsk-pdfm-credit-link-container");
784                    }
785
786                    if( return_data.error_message ){
787                        $( return_data.error_message ).insertBefore( obj_insert_before );
788
789                        return;
790                    }
791
792                    /* for infinite_scrolling, out put as only_output_pdfs = yes */
793                    if ( called_by_infinite_scrolling == false ) {
794                        $( return_data.category_out ).insertBefore( obj_insert_before );
795                        $( return_data.pagination ).insertBefore( obj_insert_before );
796
797                        //Need to refresh infinite scrolling header...
798                        //console.log( 'Need to refresh infinite scrolling header...' );
799                        output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_current_page" ).val( 1 );
800                        output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_page_max" ).val( return_data.page_max );
801                        output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_total" ).val( return_data.pdfs_count );
802                    } else {
803                        //append
804                        var pdfs_list_container = output_container.find(".bsk-p
804dfm-pdfs-" + output + "-list");
805                        pdfs_list_container.append( return_data.category_out );
806
807                        //reset list-item-odd, list-item-even class
808                        var list_item_no = 1;
809                        pdfs_list_container.find( ".bsk-pdfm-list-item" ).each( function() {
810                            $( this ).removeClass( "list-item-odd" );
811                            $( this ).removeClass( "list-item-even" );
812
813                            if ( list_item_no % 2 == 0 ) {
814                                $( this ).addClass( "list-item-even" );
815                            } else {
816                                $( this ).addClass( "list-item-odd" );
817                            }
818                            list_item_no++;
819                        });
820
821                        //change status control for infinite_scrolling
822                        //{ infinite_scrolling: true, scrolling_container: scrolling_container_obj, header : header_obj,  current: current_page, max: max_page }
823                        event.header.find( ".bsk_pdfm_infinite_scrolling_header_current_page" ).val( page_to_show );
824                        event.header.find( ".bsk_pdfm_infinite_scrolling_header_loading" ).val( 0 );
825                    }
826                    
827                    //desc
828                    if( output_container.find(".bsk-pdfm-count-desc-container").length ){
829                        output_container.find(".bsk-pdfm-count-desc-container").find( "h3" ).html( return_data.results_desc );
830                    }
831                }else if( output == 'columns' ){
832                    var obj_insert_before = output_container.find(".bsk-pdfm-pdfs-shortcode-attr");
833                    if( output_container.find(".bsk-pdfm-credit-link-container").length > 0 ){
834                        obj_insert_before = output_container.find(".bsk-pdfm-credit-link-container");
835                    }
836
837                    if( return_data.error_message ){
838                        $( return_data.error_message ).insertBefore( obj_insert_before );
839
840                        return;
841                    }
842
843                    /* for infinite_scrolling, out put as only_output_pdfs = yes */
844                    if ( called_by_infinite_scrolling == false ) {
845                        $( return_data.category_out ).insertBefore( obj_insert_before );
846                        $( return_data.pagination ).insertBefore( obj_insert_before );
847
848                        //Need to refresh infinite scrolling header...
849                        //console.log( 'Need to refresh infinite scrolling header...' );
850                        output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_current_page" ).val( 1 );
851                        output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_page_max" ).val( return_data.page_max );
852                        output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_total" ).val( return_data.pdfs_count );
853                    } else {
854                        //append
855                        var pdfs_list_container = output_container.find(".bsk-pdfm-pdfs-" + output + "-list");
856                        pdfs_list_container.append( return_data.category_out );
857
858                        //change status control for infinite_scrolling
859                        //{ infinite_scrolling: true, scrolling_container: scrolling_container_obj, header : header_obj,  current: current_page, max: max_page }
860                        event.header.find( ".bsk_pdfm_infinite_scrolling_header_current_page" ).val( page_to_show );
861                        event.header.find( ".bsk_pdfm_infinite_scrolling_header_loading" ).val( 0 );
862                    }
863
864                    //desc
865                    if( output_container.find(".bsk-pdfm-count-desc-container").length ){
866                        output_container.find(".bsk-pdfm-count-desc-container").find( "h3" ).html( return_data.results_desc );
867                    }
868                    //call function to re-set column height
869                    //if have fetured image then need call function when all images loaded
870                    if( output_container.find(".bsk-pdfm-pdfs-columns-list").find(".bsk-pdfm-pdf-link-for-featured-image img").length > 0 ){
871                        output_container.find(".bsk-pdfm-pdfs-columns-list").find(".bsk-pdfm-pdf-link-for-featured-image img").each(function(){
872                            $(this).on('load', function() { reset_columns_height_in_eacho_row(); /*console.log("image loaded correctly");*/ });
873                        });
874                    }else{
875                        reset_columns_height_in_eacho_row();
876                    }
877                }
878                
879                return;
880            } //end for output for category
881            
882       }); /* //$.post */
883        
884    }
885    
886    /*
887     * date filter
888     */
889    function set_validate_date_filter( date_filter_container, current_filter_select ){
890        /*
891          * refresh selects
892          * Year -> Month -> Day / Weekday
893          * Month -> Day / Weekday
894          * Day -> Weekday
895          */
896        var availabe_filter_select = new Array( 'year', 'month', 'day', 'weekday' );
897        var exist_filter_select = new Array();
898        var current_filter_select_str = '';
899        var current_filter_select_val = '';
900        
901        for( var i_filter = 0; i_filter < availabe_filter_select.length; i_filter++ ){
902            if( date_filter_container.find(".bsk-pdfm-date-" + availabe_filter_select[i_filter]).length ){
903                exist_filter_select.push( availabe_filter_select[i_filter] );
904            }
905        }
906        
907        /*
908         * create hidden selects
909         */
910        var first_select_obj = date_filter_container.find(".bsk-pdfm-date-" + availabe_filter_select[0]);
911        for( var i_filter = 0; i_filter < availabe_filter_select.length; i_filter++ ){
912            var fitler_str = availabe_filter_select[i_filter];
913            if( date_filter_container.find(".bsk-pdfm-date-" + fitler_str + '-hidden').length ){
914                continue;
915            }else{
916                var hidden_obj = date_filter_container.find(".bsk-pdfm-date-" + fitler_str).clone();
917                hidden_obj.removeClass( "bsk-pdfm-date-" + fitler_str );
918                hidden_obj.addClass( "bsk-pdfm-date-" + fitler_str + '-hidden' );
919                hidden_obj.hide();
920                hidden_obj.insertBefore( first_select_obj );
921            }
922        }
923        
924
925        if( exist_filter_select.length < 2 ){
926            //do nothing if only one filter
927            return;
928        }
929        
930        if( current_filter_select.hasClass("bsk-pdfm-date-year") ){
931            current_filter_select_str = 'year';   
932        }else if( current_filter_select.hasClass("bsk-pdfm-date-month") ){
933            current_filter_select_str = 'month';   
934        }else if( current_filter_select.hasClass("bsk-pdfm-date-day") ){
935            current_filter_select_str = 'day';   
936        }else if( current_filter_select.hasClass("bsk-pdfm-date-weekday") ){
937            current_filter_select_str = 'weekday';   
938        }
939        current_filter_select_val = current_filter_select.val();
940        
941        //get all valid dates according to what selected
942        var valid_dates = new Array();
943        var valid_month_options = new Array();
944        var valid_day_options = new Array();
945        var valid_weekday_options = new Array();
946        $(".bsk-pdfm-valid-date").each(function(){
947            switch( current_filter_select_str ){
948                case 'year':
949                    if( current_filter_select_val && current_filter_select_val != $(this).val().substr(0, 4) ){
950                        return;
951                    }
952                break;
953                case 'month':
954                    if( current_filter_select_val && current_filter_select_val != $(this).val().substr(5, 2) ){
955                        return;
956                    }
957                    //consider year
958                    if( date_filter_container.find(".bsk-pdfm-date-year").length ){
959                        var year_val = date_filter_container.find(".bsk-pdfm-date-year").val();
960                        if( year_val && year_val != $(this).val().substr(0, 4) ){
961                            return;
962                        }
963                    }
964                break;
965                case 'day':
966                    if( current_filter_select_val && current_filter_select_val != $(this).val().substr(8, 2) ){
967                        return;
968                    }
969                    //consider year, month
970                    if( date_filter_container.find(".bsk-pdfm-date-year").length ){
971                        var year_val = date_filter_container.find(".bsk-pdfm-date-year").val();
972                        if( year_val && year_val != $(this).val().substr(0, 4) ){
973                            return;
974                        }
975                    }
976                    if( date_filter_container.find(".bsk-pdfm-date-month").length ){
977                        var month_val = date_filter_container.find(".bsk-pdfm-date-month").val();
978                        if( month_val && month_val != $(this).val().substr(5, 2) ){
979                            return;
980                        }
981                    }
982                break;
983                case 'weekday':
984                    if( current_filter_select_val && current_filter_select_val != $(this).val().substr(11, 3) ){
985                        return;
986                    }
987                    //consider year, month, day
988                    if( date_filter_container.find(".bsk-pdfm-date-year").length ){
989                        var year_val = date_filter_container.find(".bsk-pdfm-date-year").val();
990                        if( year_val && year_val != $(this).val().substr(0, 4) ){
991                            return;
992                        }
993                    }
994                    if( date_filter_container.find(".bsk-pdfm-date-month").length ){
995                        var month_val = date_filter_container.find(".bsk-pdfm-date-month").val();
996                        if( month_val && month_val != $(this).val().substr(5, 2) ){
997                            return;
998                        }
999                    }
1000                    if( date_filter_container.find(".bsk-pdfm-date-day").length ){
1001                        var day_val = date_filter_container.find(".bsk-pdfm-date-day").val();
1002                        if( day_val && day_val != $(this).val().substr(8, 2) ){
1003                            return;
1004                        }
1005                    }
1006                break;
1007            }
1008            valid_dates.push( $(this).val() );
1009            valid_month_options.push( $(this).val().substr(5, 2) );
1010            valid_day_options.push( $(this).val().substr(8, 2) );
1011            valid_weekday_options.push( $(this).val().substr(11, 3) );
1012        });
1013        
1014        /*
1015          * Year control Month
1016          * Month control Day and Weekday
1017          */
1018        if( current_filter_select_str == 'year' || current_filter_select_str == 'month' || current_filter_select_str == 'day' ){
1019            var filter_str_to_ctrl = new Array();
1020            if( current_filter_select_str == 'year' ){
1021                filter_str_to_ctrl.push( 'month' );
1022                filter_str_to_ctrl.push( 'day' );
1023                filter_str_to_ctrl.push( 'weekday' );
1024            }else if( current_filter_select_str == 'month' ){
1025                filter_str_to_ctrl.push( 'day' );
1026                filter_str_to_ctrl.push( 'weekday' );
1027            }else if( current_filter_select_str == 'day' ){
1028                filter_str_to_ctrl.push( 'weekday' );
1029            }
1030            for( var i_ctrl = 0; i_ctrl < filter_str_to_ctrl.length; i_ctrl++ ){
1031                if( date_filter_container.find(".bsk-pdfm-date-" + filter_str_to_ctrl[i_ctrl]).length < 1 ){
1032                    continue;
1033                }
1034                
1035                //copy all options first
1036                var hidden_options = date_filter_container.find(".bsk-pdfm-date-" + filter_str_to_ctrl[i_ctrl] + '-hidden').html();
1037                date_filter_container.find(".bsk-pdfm-date-" + filter_str_to_ctrl[i_ctrl]).html( hidden_options );
1038                date_filter_container.find(".bsk-pdfm-date-" + filter_str_to_ctrl[i_ctrl]).val("");
1039
1040                /* show first and then hide */
1041                date_filter_container.find(".bsk-pdfm-date-" + filter_str_to_ctrl[i_ctrl] + " > option").show();
1042                switch( filter_str_to_ctrl[i_ctrl] ){
1043                    case 'month':
1044                        date_filter_container.find(".bsk-pdfm-date-" + filter_str_to_ctrl[i_ctrl] + " > option").each(function(){
1045                            if( $(this).val() == "" ){
1046                                return;
1047                            }
1048                            if( valid_month_options.indexOf( $(this).val() ) == -1 ){
1049                                $(this).remove();
1050                            }
1051                        });
1052                    break;
1053                    case 'day':
1054                        date_filter_container.find(".bsk-pdfm-date-" + filter_str_to_ctrl[i_ctrl] + " > option").each(function(){
1055                            if( $(this).val() == "" ){
1056                                return;
1057                            }
1058                            if( valid_day_options.indexOf( $(this).val() ) == -1 ){
1059                                $(this).remove();
1060                            }
1061                        });
1062                    break;
1063                    case 'weekday':
1064                        date_filter_container.find(".bsk-pdfm-date-" + filter_str_to_ctrl[i_ctrl] + " > option").each(function(){
1065                            if( $(this).val() == "" ){
1066                                return;
1067                            }
1068                            if( valid_weekday_options.indexOf( $(this).val() ) == -1 ){
1069                                $(this).remove();
1070                            }
1071                        });
1072                    break;
1073                }
1074            } //end for select to ctrl
1075        }
1076        //
1077    }
1078    
1079    
1080    /*
1081    *
1082    *  Date filter
1083    *
1084    */    
1085    $(".bsk-pdfm-output-container").on("change", ".bsk-pdfm-date-filter select", function(){
1086        var output_container = $(this).parents(".bsk-pdfm-output-container");
1087        var date_weekday_filter_container = $(this).parent(".bsk-pdfm-date-filter");
1088        var current_changed_select = $(this);
1089
1090        var shortcode_type = '';
1091        var output = '';
1092        if( output_container.hasClass("shortcode-pdfs") ){
1093            shortcode_type = 'pdfs';
1094        }else if( output_container.hasClass("shortcode-category") ){
1095            shortcode_type = 'category';
1096        }else if( output_container.hasClass("shortcode-selector") ){
1097            shortcode_type = 'selector';
1098        }else{
1099            return;
1100        }
1101
1102        if( output_container.hasClass( 'layout-ul' ) ){
1103            output =  'ul';
1104        }else if( output_container.hasClass( 'layout-ol' ) ){
1105            output = 'ol';
1106        }else if( output_container.hasClass( 'layout-columns' ) ){
1107            output = 'columns';
1108        }else if( output_container.hasClass( 'layout-dropdown' ) ){
1109            output = 'dropdown';
1110        }else{
1111            return;
1112        }
1113        
1114        /*
1115          * refresh selects
1116          * Year -> Month -> Day / Weekday
1117          * Month -> Day / Weekday
1118          * Day -> Weekday
1119          */
1120        set_validate_date_filter( date_weekday_filter_container, current_changed_select );
1121        
1122        //refresh year month day weekday
1123        var filter_year = $(this).parent().find(".bsk-pdfm-date-year").val();
1124        var filter_month = $(this).parent().find(".bsk-pdfm-date-month").val();
1125        var filter_day = $(this).parent().find(".bsk-pdfm-date-day").val();
1126        var filter_weekday = $(this).parent().find(".bsk-pdfm-date-weekday").val();
1127
1128        /*
1129          * process for pdfs
1130          */
1131        if( shortcode_type == 'pdfs' ){
1132            if( output == 'ul' || output == 'ol' ){
1133                 var ul_or_ol_parent = output_container.find( ".bsk-pdfm-" + shortcode_type + "-output" );
1134                 process_date_weekday_filter_for_li( ul_or_ol_parent, output, filter_year, filter_month, filter_day, filter_weekday );
1135            }else if( output == 'dropdown' ){
1136                 var dropdown_parent = output_container.find( ".bsk-pdfm-" + shortcode_type + "-output" );
1137                 process_date_weekday_filter_for_dropdown( dropdown_parent, filter_year, filter_month, filter_day, filter_weekday );
1138             }else if( output == 'columns' ){
1139                 var column = $(this).parents(".bsk-pdfm-" + shortcode_type + "-output").data("columns");
1140                 var column_parent = output_container.find( ".bsk-pdfm-" + shortcode_type + "-output" );
1141                 process_date_weekday_filter_for_column( column_parent, column, filter_year, filter_month, filter_day, filter_weekday );
1142             }
1143        }//end for pdfs
1144                                       
1145        /*
1146          * process for category
1147          */
1148        if( shortcode_type == 'category' ){
1149            if( output == 'ul' || output == 'ol' ){
1150                output_container.find( ".bsk-pdfm-category-output" ).each(function(){
1151                    var ul_or_ol_parent = $(this);
1152                    process_date_weekday_filter_for_li( ul_or_ol_parent, output, filter_year, filter_month, filter_day, filter_weekday );
1153                });
1154            }else if( output == 'dropdown' ){
1155                    var dropdown_parent = $(this).closest( ".bsk-pdfm-category-output" );
1156                    process_date_weekday_filter_for_dropdown( dropdown_parent, filter_year, filter_month, filter_day, filter_weekday );
1157             }else if( output == 'columns' ){
1158                output_container.find( ".bsk-pdfm-category-output" ).each(function(){
1159                    var column_parent = $(this);
1160                    var column = $(this).data("columns");
1161                    process_date_weekday_filter_for_column( column_parent, column, filter_year, filter_month, filter_day, filter_weekday );
1162                });
1163             }
1164        }//end for category
1165        
1166        /*
1167          * process for selector
1168          */
1169        if( shortcode_type == 'selector' ){
1170            if( output == 'ul' || output == 'ol' ){
1171                output_container.find( ".bsk-pdfm-category-output" ).each(function(){
1172                    var ul_or_ol_parent = $(this);
1173                    process_date_weekday_filter_for_li( ul_or_ol_parent, output, filter_year, filter_month, filter_day, filter_weekday );
1174                });
1175            }else if( output == 'dropdown' ){
1176                output_container.find( ".bsk-pdfm-category-output" ).each(function(){
1177                    var dropdown_parent = $(this);
1178                    process_date_weekday_filter_for_dropdown( dropdown_parent, filter_year, filter_month, filter_day, filter_weekday );
1179                });
1180             }else if( output == 'columns' ){
1181                output_container.find( ".bsk-pdfm-category-output" ).each(function(){
1182                    var column_parent = $(this);
1183                    var column = $(this).data("columns");
1184                    process_date_weekday_filter_for_column( column_parent, column, filter_year, filter_month, filter_day, filter_weekday );
1185                });
1186             }
1187        }//end for selector
1188        
1189    }); //end of filter listener function
1190    
1191    function process_date_weekday_filter_for_li( parent_div, ul_ol, filter_year, filter_month, filter_day, filter_weekday ){
1192        parent_div.find(".bsk-pdfm-pdfs-" + ul_ol + "-list > li").each( function( index, value ){
1193            var date = $(this).data("date" );
1194            if( date == "" ){
1195                return;
1196            }
1197            var pdf_year = date.substr( 0, 4 );
1198            var pdf_month = date.substr( 5, 2 );
1199            var pdf_day = date.substr( 8, 2 );
1200            var pdf_weekday = date.substr( 11, 3 );
1201
1202            if( filter_year && pdf_year != filter_year ){
1203                $(this).css("display", "none");
1204                return;
1205            }
1206            if( filter_month && pdf_month != filter_month ){
1207                $(this).css("display", "none");
1208                return;
1209            }
1210            if( filter_day && pdf_day != filter_day ){
1211                $(this).css("display", "none");
1212                return;
1213            }
1214            if( filter_weekday && pdf_weekday != filter_weekday ){
1215                $(this).css("display", "none");
1216                return;
1217            }
1218            $(this).css("display", "list-item");
1219        }); //end of process pdfs
1220
1221        //reset list-item class
1222        var i_list_item = 1;
1223        parent_div.find(".bsk-pdfm-pdfs-" + ul_ol + "-list > li").each( function( index, value ){
1224            $(this).removeClass("list-item-odd");
1225            $(this).removeClass("list-item-even");
1226            if( $(this).css("display") == "none" ){
1227                return;
1228            }
1229            if( i_list_item % 2 == 0 ){
1230                $(this).addClass( "list-item-even" );
1231            }else{
1232                $(this).addClass( "list-item-odd" );
1233            }
1234            i_list_item++;
1235        });
1236    }
1237    
1238    function process_date_weekday_filter_for_dropdown( parent_div, filter_year, filter_month, filter_day, filter_weekday ){
1239        
1240        if( parent_div.find(".bsk-pdfm-pdfs-dropdown").length < 1 ){
1241            return;
1242        }
1243        //check if hidden dropdown exist
1244        if( parent_div.find(".bsk-pdfm-pdfs-hidden-dropdown").length < 1 ){
1245            var hidden_dropdown_obj = parent_div.find(".bsk-pdfm-pdfs-dropdown").clone();
1246            hidden_dropdown_obj.removeClass("bsk-pdfm-pdfs-dropdown");
1247            hidden_dropdown_obj.addClass("bsk-pdfm-pdfs-hidden-dropdown");
1248            hidden_dropdown_obj.hide();
1249            hidden_dropdown_obj.insertAfter( parent_div.find(".bsk-pdfm-pdfs-dropdown") );
1250        }else{
1251            //copy options from hidden
1252            parent_div.find(".bsk-pdfm-pdfs-dropdown").html( parent_div.find(".bsk-pdfm-pdfs-hidden-dropdown").html() );
1253        }
1254        
1255        var options = null;
1256        if( parent_div.find(".bsk-pdfm-pdfs-dropdown optgroup").length ){
1257            options = parent_div.find(".bsk-pdfm-pdfs-dropdown optgroup > option");
1258        }else{
1259            options = parent_div.find(".bsk-pdfm-pdfs-dropdown > option");
1260        }
1261        $.each( options, function( index, value ) {
1262            var date = $(this).prop("id");
1263            if( date == "" ){
1264                return;
1265            }
1266
1267            var pdf_year = date.substr( 0, 4 );
1268            var pdf_month = date.substr( 5, 2 );
1269            var pdf_day = date.substr( 8, 2 );
1270            var pdf_weekday = date.substr( 11, 3 );
1271
1272            if( filter_year && pdf_year != filter_year ){
1273                $(this).remove();
1274                return;
1275            }
1276            if( filter_month && pdf_month != filter_month ){
1277                $(this).remove();
1278                return;
1279            }
1280            if( filter_day && pdf_day != filter_day ){
1281                $(this).remove();
1282                return;
1283            }
1284            if( filter_weekday && pdf_weekday != filter_weekday ){
1285                $(this).remove();
1286                return;
1287            }
1288        });
1289    }
1290
1291    function process_date_weekday_filter_for_column( parent_div, column, filter_year, filter_month, filter_day, filter_weekday ){
1292        parent_div.find(".bsk-pdfm-pdfs-columns-list > div").each(function(){
1293            var date = $(this).data("date");
1294            if( date == "" ){
1295                return;
1296            }
1297
1298            $(this).removeClass( "bsk-pdfm-first" );
1299
1300            var pdf_year = date.substr( 0, 4 );
1301            var pdf_month = date.substr( 5, 2 );
1302            var pdf_day = date.substr( 8, 2 );
1303            var pdf_weekday = date.substr( 11, 3 );
1304            if( filter_year && pdf_year != filter_year ){
1305                $(this).css("display", "none");
1306                return;
1307            }
1308            if( filter_month && pdf_month != filter_month ){
1309                $(this).css("display", "none");
1310                return;
1311            }
1312            if( filter_day && pdf_day != filter_day ){
1313                $(this).css("display", "none");
1314                return;
1315            }
1316            if( filter_weekday && pdf_weekday != filter_weekday ){
1317                $(this).css("display", "none");
1318                return;
1319            }
1320            $(this).css("display", "block");
1321        });
1322
1323        //refresh column display or not
1324        function reset_columns_class( column_parent_div ){
1325            var current_index = 0;
1326            column_parent_div.find(".bsk-pdfm-pdfs-columns-list > div").each(function(){
1327                if( $(this).css("display") != "block" ){
1328                    return;
1329                }
1330                if( current_index % column == 0 ){
1331                    $(this).addClass( "bsk-pdfm-first" );
1332                }
1333                current_index++;
1334            });
1335        }
1336        $.when( reset_columns_class( parent_div ) ).done(function( x ) {
1337            //need reset column height, as column height is by row
1338            reset_columns_height_in_eacho_row();
1339        });   
1340    }
1341    
1342    
1343    
1344    /*
1345      * Columns - make each row have same height
1346      */
1347    if( $(".pdfs-in-columns").length > 0 ){
1348        output_container = $(".bsk-pdfm-output-container");
1349        if( output_container.find(".bsk-pdfm-pdfs-columns-list .bsk-pdfm-pdf-link-for-featured-image img").length > 0 ){
1350
1351            output_container.find(".bsk-pdfm-pdfs-columns-list .bsk-pdfm-pdf-link-for-featured-image img").each(function(){
1352                $(this).on( 
1353                            'load', 
1354                            function() { 
1355                                reset_columns_height_in_eacho_row(); 
1356                                /*console.log("image loaded correctly");*/
1357                            }
1358                          );
1359            });
1360        }else{
1361            reset_columns_height_in_eacho_row();
1362        }
1363
1364        $( window ).resize(function() {
1365            output_container = $(".bsk-pdfm-output-container");
1366            if( output_container.find(".bsk-pdfm-pdfs-columns-list .bsk-pdfm-pdf-link-for-featured-image img").length > 0 ){
1367                
1368                output_container.find(".bsk-pdfm-pdfs-columns-list .bsk-pdfm-pdf-link-for-featured-image img").each(function(){
1369                    $(this).on('load', function() { reset_columns_height_in_eacho_row(); /*console.log("image loaded correctly");*/ });
1370                });
1371            }else{
1372                reset_columns_height_in_eacho_row();
1373            }
1374        });
1375        
1376        var reset_when_scroll = false;
1377        $( window ).scroll(function() {
1378            if( reset_when_scroll == false ){
1379                output_container = $(".bsk-pdfm-output-container");
1380                if( output_container.find(".bsk-pdfm-pdfs-columns-list .bsk-pdfm-pdf-link-for-featured-image img").length > 0 ){
1381                    output_container.find(".bsk-pdfm-pdfs-columns-list .bsk-pdfm-pdf-link-for-featured-image img").each(function(){
1382                        $(this).on('load', function() { reset_columns_height_in_eacho_row(); /*console.log("image loaded correctly");*/ });
1383                    });
1384                }else{
1385                    reset_columns_height_in_eacho_row();
1386                }
1387                reset_when_scroll = true;
1388            }
1389        });
1390    }
1391    
1392    function reset_columns_height_in_eacho_row(){
1393        $(".pdfs-in-columns").each(function(){
1394            var columns = $(this).data( "columns" );
1395            if( columns < 2 ){
1396                return;
1397            }
1398            //get first
1399            $(this).find(".bsk-pdfm-first").each(function(){
1400                // reset the height
1401                $(this).css({'height':'auto'});
1402                var first_column_height = $(this).height();
1403                var max_height = first_column_height;
1404                //get others in the row
1405                var temp_obj = $(this);
1406                while( temp_obj.next(".bsk-pdfm-columns-single").length && !temp_obj.next(".bsk-pdfm-columns-single").hasClass("bsk-pdfm-first") ){
1407                    temp_obj = temp_obj.next(".bsk-pdfm-columns-single");
1408                    if( temp_obj.css("display") != "block" ){
1409                        continue;
1410                    }
1411                    temp_obj.css({'height':'auto'});
1412                    //console.log( temp_obj.height() );
1413                    if( temp_obj.height() > max_height ){
1414                        max_height = temp_obj.height();
1415                    }
1416                }
1417
1418                //set height to the row
1419                $(this).height( max_height );
1420                var temp_obj = $(this);
1421                while( temp_obj.next(".bsk-pdfm-columns-single").length && !temp_obj.next(".bsk-pdfm-columns-single").hasClass("bsk-pdfm-first") ){
1422                    temp_obj = temp_obj.next(".bsk-pdfm-columns-single");
1423                    if( temp_obj.css("display") != "block" ){
1424                        continue;
1425                    }
1426                    temp_obj.height( max_height );
1427                }
1428            });
1429        });
1430    }
1431    
1432    /*
1433      * Download / Open statistics
1434      */
1435    $(".bsk-pdfm-output-container").on("click", ".bsk-pdfm-pdf-link-for-title, .bsk-pdfm-pdf-link-for-featured-image", function( e ){
1436
1437        var output_container = $(this).parents(".bsk-pdfm-output-container");
1438        
1439        //check if permalink enable
1440        if( output_container.find( ".bsk_pdfm_settings_enalbe_permalink_cls" ).val() > 0 ){
1441            return;
1442        }
1443        
1444        if( output_container.find(".bsk-pdfm-statistics-ajax-nonce").length < 1 ){
1445            //console.log( 'No statistics enabled' );
1446            return;
1447        }
1448        
1449        var anchor_id = $(this).attr( "id" );
1450        
1451        if( !$(this).hasClass( 'bsk-pdfm-statistics-done' ) ){
1452            e.preventDefault();
1453            
1454            var ajax_nonce = output_container.find(".bsk-pdfm-statistics-ajax-nonce").val();
1455            var pdf_id = 0;
1456            if( $(this).parents( ".bsk-pdfm-list-item" ).length ){
1457                pdf_id = $(this).parents( ".bsk-pdfm-list-item" ).data( "id" );
1458            }else if( $(this).parents( ".bsk-pdfm-columns-single" ).length ){
1459                pdf_id = $(this).parents( ".bsk-pdfm-columns-single" ).data( "id" );
1460             }
1461
1462            if( pdf_id < 1 ){
1463                //console.log( 'Invalid PDF id' );
1464                return;
1465            }
1466            var action_val = 'pdfs_statistics_update_download_count';
1467            var data = { action: action_val, id: pdf_id, nonce: ajax_nonce };
1468
1469            $.post( bsk_pdf_pro.ajaxurl, data, function(response) {
1470                //do nothing
1471                $('#' + anchor_id ).addClass( 'bsk-pdfm-statistics-done' );
1472                $('#' + anchor_id )[0].click();
1473            });
1474        }else{
1475             $(this).removeClass( 'bsk-pdfm-statistics-done' );
1476        }
1477    });
1478
1479    $( ".bsk-pdfm-pdf-link-statics" ).click( function() {
1480
1481        if( !$(this).hasClass( 'bsk-pdfm-statistics-done' ) ){
1482            
1483            var pdf_id = $(this).data( "pdf-id" );
1484            if( pdf_id < 1 ){
1485                //console.log( 'Invalid PDF id' );
1486                return;
1487            }
1488            var action_val = 'pdfs_statistics_update_download_count';
1489            var data = { action: action_val, id: pdf_id, nonce: 'LINK_ONLY_NO_NONCE' };
1490            //console.log( pdf_id );
1491            $.post( bsk_pdf_pro.ajaxurl, data, function(response) {
1492                //do nothing
1493                $(this).addClass( 'bsk-pdfm-statistics-done' );
1494                $(this).click();
1495            });
1496        }else{
1497             $(this).removeClass( 'bsk-pdfm-statistics-done' );
1498        }
1499    });
1500    
1501    /*
1502     *
1503     * Selector
1504     * dropdown change
1505     *
1506    */
1507    $(".bsk-pdfm-category-selector-container .bsk-pdfm-category-dropdown").change(function(){
1508        var output_container = null;
1509        var selector_container = $(this).parent();
1510        var output;
1511        
1512        if( $(this).parents(".bsk-pdfm-output-container").length ){
1513            output_container = $(this).parents(".bsk-pdfm-output-container");
1514        }else if( $(this).parents(".bsk-pdfm-widget-output-container").length ){
1515            output_container = $(this).parents(".bsk-pdfm-widget-output-container");
1516        }else{
1517            return;
1518        }
1519        
1520        if( output_container.hasClass( 'layout-ul' ) ){
1521            output =  'ul';
1522        }else if( output_container.hasClass( 'layout-ol' ) ){
1523            output = 'ol';
1524        }else if( output_container.hasClass( 'layout-columns' ) ){
1525            output = 'columns';
1526        }else if( output_container.hasClass( 'layout-dropdown' ) ){
1527            output = 'dropdown';
1528        }else{
1529            return;
1530        }
1531        
1532        //
1533        // remove category out, pagintaion, 
1534        // reset title filter, extension filter, date-weekday query filter, tags filter, search bar
1535        //
1536        output_container.find(".bsk-pdfm-error-message").remove();
1537        output_container.find(".bsk-pdfm-category-description").remove();
1538        output_container.find(".bsk-pdfm-category-output").remove();
1539        output_container.find(".bsk-pdfm-date-filter").remove();
1540        output_container.find(".bsk-pdfm-pagination").remove();
1541        output_container.find(".bsk-pdfm-count-desc-container").remove();
1542        output_container.find(".bsk-pdfm-extension-filter-container").remove();
1543        output_container.find(".bsk-pdfm-title-filter-container").remove();
1544        output_container.find(".bsk-pdfm-date-weekday-query-filter").remove();
1545        output_container.find(".bsk-pdfm-tags-filter-container").remove();
1546        output_container.find(".bsk-pdfm-search-bar").remove();
1547        
1548        
1549        //load category out by ajax
1550        var category_id = $(this).val();
1551        if( category_id < 1 ){
1552            return;
1553        }
1554        
1555        var ajax_nonce = output_container.find(".bsk-pdfm-selector-ajax-nonce").val();
1556        var action_val = 'pdfs_get_selector_' + output;
1557        var data = { action: action_val, layout: output, nonce: ajax_nonce };
1558        output_container.find(".bsk-pdfm-shortcode-attr").each(function(index, value ){
1559            var attr_name = $(this).data("attr_name");
1560            data[attr_name] = $(this).val();
1561        });
1562        data['default_cat_id'] = category_id;
1563        selector_container.find(".bsk-pdfm-category-selector-ajax-loader").css( "display", "inline-block" );
1564        
1565        $.post( bsk_pdf_pro.ajaxurl, data, function(response) {
1566            /*console.log( response );
1567            return;*/
1568            selector_container.find(".bsk-pdfm-category-selector-ajax-loader").css( "display", "none" );
1569            
1570            var obj_insert_before = output_container.find(".bsk-p
1570dfm-pdfs-shortcode-attr");
1571            if( output_container.find(".bsk-pdfm-credit-link-container").length > 0 ){
1572                obj_insert_before = output_container.find(".bsk-pdfm-credit-link-container");
1573            }
1574            var category_selector_obj = output_container.find(".bsk-pdfm-category-selector-container");
1575            
1576            var return_data = $.parseJSON( response );
1577            if( return_data.error_message ){
1578                $( return_data.error_message ).insertBefore( obj_insert_before );
1579                
1580                return;
1581            }
1582            
1583            if( output == 'dropdown' ){
1584                $( return_data.selected_category_out ).insertAfter( category_selector_obj );
1585                output_container.find(".bsk-pdfm-pdfs-dropdown").focus();
1586            }else if( output == 'ul' || output == 'ol' ){
1587                $( return_data.selected_category_out ).insertAfter( category_selector_obj );
1588
1589                //refresh bsk_pdfm_infinite_scrolling_header
1590                output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_current_page" ).val( 1 );
1591                output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_page_max" ).val( return_data.page_max );
1592                output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_total" ).val( return_data.pdfs_count );
1593            }else if( output == 'columns' ){
1594                $( return_data.selected_category_out ).insertAfter( category_selector_obj );
1595
1596                //refresh bsk_pdfm_infinite_scrolling_header
1597                output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_current_page" ).val( 1 );
1598                output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_page_max" ).val( return_data.page_max );
1599                output_container.find( ".bsk_pdfm_infinite_scrolling_header .bsk_pdfm_infinite_scrolling_header_total" ).val( return_data.pdfs_count );
1600
1601                //call function to re-set column height
1602                //if have fetured image then need call function when all images loaded
1603                if( output_container.find(".bsk-pdfm-pdfs-columns-list").find(".bsk-pdfm-pdf-link-for-featured-image img").length > 0 ){
1604                    output_container.find(".bsk-pdfm-pdfs-columns-list").find(".bsk-pdfm-pdf-link-for-featured-image img").each(function(){
1605                        $(this).on('load', function() { reset_columns_height_in_eacho_row(); /*console.log("image loaded correctly");*/ });
1606                    });
1607                }else{
1608                    reset_columns_height_in_eacho_row();
1609                }
1610            }
1611            
1612       }); /* //$.post */
1613    });
1614    
1615    /*
1616     * Wdiget
1617     * Pagination, Search
1618     */
1619    $(".bsk-pdfm-widget-output-container").on("click", ".bsk-pdfm-pagination a, .bsk-pdfm-search-input button, .bsk-pdfm-search-results a", function(){
1620        
1621        var output_container = $(this).closest(".bsk-pdfm-widget-output-container");
1622        var shortcode_type = '';
1623        var output = '';
1624        if( output_container.hasClass("widget-pdfs") ){
1625            shortcode_type = 'pdfs';
1626        }else if( output_container.hasClass("widget-category") ){
1627            shortcode_type = 'category';
1628        }else if( output_container.hasClass("widget-selector") ){
1629            shortcode_type = 'selector';
1630        }else{
1631            return;
1632        }
1633
1634        if( output_container.hasClass( 'layout-ul' ) ){
1635            output =  'ul';
1636        }else if( output_container.hasClass( 'layout-ol' ) ){
1637            output = 'ol';
1638        }else{
1639            return;
1640        }
1641
1642        //clear error message
1643        output_container.find(".bsk-pdfm-error-message").remove();
1644        
1645        var keywords_val = '';
1646        var search_cat_id_val = '';
1647        var search_year_of_val = '';
1648        var start_with = '';
1649        
1650
1651        /*
1652          for search bar 
1653          */
1654        if( $(this).hasClass("bsk-pdfm-search-anchor") || $(this).hasClass("bsk-pdfm-search-clear-anchor") ){
1655            var search_input_obj = $(this).parents(".bsk-pdfm-search-bar").find(".bsk-pdfm-search-input");
1656            
1657            if( $(this).hasClass("bsk-pdfm-search-clear-anchor") ){
1658                search_input_obj.find(".bsk-pdfm-search-keywords").val( "" );
1659                search_input_obj.find(".bsk-pdfm-year-dropdown").val( "" );
1660                search_input_obj.find(".bsk-pdfm-category-dropdown").val( "" );
1661            }
1662            
1663            var search_reulsts_label_obj = $(this).parents(".bsk-pdfm-search-bar").find(".bsk-pdfm-search-results");
1664            search_reulsts_label_obj.css("display", "block");
1665            search_reulsts_label_obj.find(".bsk-pdfm-searchbar-ajax-loader").css( "display", "inline-block" );
1666            search_reulsts_label_obj.find(".bsk-pdfm-search-results-desc").css( "display", "none" );
1667            
1668            //refresh pagination
1669            output_container.find(".bsk-pdfm-pagination").find("li").removeClass("active");
1670        }
1671        if( output_container.find( ".bsk-pdfm-search-bar" ).length > 0 ){
1672            var search_input_obj = output_container.find(".bsk-pdfm-search-input");
1673            keywords_val = search_input_obj.find(".bsk-pdfm-search-keywords").val();
1674            keywords_val = $.trim( keywords_val );
1675            keywords_input_placeholder = search_input_obj.find(".bsk-pdfm-search-keywords").attr("placeholder");
1676            if( keywords_val == keywords_input_placeholder ){
1677                keywords_val = '';
1678            }
1679            if( search_input_obj.find(".bsk-pdfm-year-dropdown").length ){
1680                search_year_of_val = search_input_obj.find(".bsk-pdfm-year-dropdown").val();
1681            }
1682            if( search_input_obj.find(".bsk-pdfm-category-dropdown").length ){
1683                search_cat_id_val = search_input_obj.find(".bsk-pdfm-category-dropdown").val();
1684            }
1685        }
1686        
1687        /* 
1688          * for pagination
1689          */
1690        var page_to_show = 1;
1691        if( $(this).hasClass( "bsk-pdfm-pagination-anchor" ) ){ //pagination anchor
1692            if( $(this).parent().hasClass("active") ){
1693                //click on active pagination anchor
1694                return;
1695            }
1696            page_to_show = $(this).data("page");
1697            output_container.find(".bsk-pdfm-pagination-ajax-loader").css( "display", "inline-block" );
1698        }else if( output_container.find(".bsk-pdfm-pagination").length ){
1699            page_to_show = output_container.find(".bsk-pdfm-pagination").find("li.active").find("a").data("page");
1700        }
1701        
1702        var ajax_nonce = output_container.find(".bsk-pdfm-" + shortcode_type + "-ajax-nonce").val();
1703        var action_val = "pdfs_get_" + shortcode_type + "_" + output;
1704        var data = { action: action_val, layout: output, nonce: ajax_nonce };
1705        
1706        //organise ajax parameters
1707        output_container.find(".bsk-pdfm-shortcode-attr").each(function(index, value ){
1708            var attr_name = $(this).data("attr_name");
1709            data[attr_name] = $(this).val();
1710        });
1711        
1712        if( search_cat_id_val ){
1713            data['search_cat_id'] = search_cat_id_val;
1714            //means under search mode
1715            //in this mode only search PDFs from the selected category so close hierarchical temporarily
1716            data['hierarchical'] = 'no';
1717        }
1718        
1719        if( search_year_of_val ){
1720            data['year_of'] = search_year_of_val;
1721        }
1722
1723        data['paged'] = page_to_show;
1724        data['keywords'] = keywords_val;
1725
1726        /*
1727          * for category selector
1728          */
1729        if( shortcode_type == 'selector' ){
1730            data['action'] = "pdfs_get_category_" + output;
1731            data['nonce'] = output_container.find(".bsk-pdfm-category-ajax-nonce").val();
1732            data['id'] = output_container.find(".bsk-pdfm-category-selector-container").find(".bsk-pdfm-category-dropdown").val();
1733            //unser selector mode for showing PDF results, hierarchical is always closed
1734            data['hierarchical'] = 'no';
1735        }
1736        
1737        
1738        /*console.log( data );
1739        return;*/
1740        $.post( bsk_pdf_pro.ajaxurl, data, function(response) {
1741            /*console.log( response );
1742            return;*/
1743            var return_data = $.parseJSON( response );
1744            
1745            /*
1746              * process search bar
1747            */
1748            if( output_container.find(".bsk-pdfm-search-results").length ){
1749                
1750                var search_reulsts_container = output_container.find(".bsk-pdfm-search-results");
1751                
1752                search_reulsts_container.find(".bsk-pdfm-searchbar-ajax-loader").css("display", "none");
1753                if( keywords_val == "" && search_year_of_val == "" && search_cat_id_val == "" ){
1754                    search_reulsts_container.css("display", "none");
1755                }else{
1756                    search_reulsts_container.css("display", "block");
1757                    search_reulsts_container.find(".bsk-pdfm-search-clear-anchor").css("display", "inline-block");
1758                }
1759                
1760            }
1761            
1762
1763            /*
1764             * output for pdfs
1765             */
1766            if( shortcode_type == 'pdfs' ){
1767
1768                output_container.find(".bsk-pdfm-pagination").remove();
1769                
1770                if( output == 'dropdown' ){
1771                    output_container.find(".bsk-pdfm-pdfs-dropdown").focus();
1772                }else if( output == 'ul' || output == 'ol' ){
1773                    var pdfs_list_container = output_container.find(".bsk-pdfm-pdfs-" + output + "-list");
1774                    pdfs_list_container.html( "" );
1775                    if( return_data.error_message ){
1776                        $( return_data.error_message ).insertBefore( pdfs_list_container );
1777                    }else{
1778                        pdfs_list_container.html( return_data.pdfs );
1779                        $( return_data.date_filter ).insertBefore( pdfs_list_container );
1780                        $( return_data.pagination ).insertAfter( pdfs_list_container );
1781                    }                    
1782                }else if( output == 'columns' ){
1783                
1784                }
1785                
1786                return;
1787            }
1788            
1789            
1790            
1791            /*
1792             * output for category
1793             */
1794            if( shortcode_type == 'category' ){
1795                output_container.find(".bsk-pdfm-pagination").remove();
1796                output_container.find(".bsk-pdfm-category-output").remove();
1797                
1798                var obj_insert_before = output_container.find(".bsk-pdfm-pdfs-shortcode-attr");
1799                if( output_container.find(".bsk-pdfm-credit-link-container").length > 0 ){
1800                    obj_insert_before = output_container.find(".bsk-pdfm-credit-link-container");
1801                }
1802                
1803                
1804                if( output == 'dropdown' ){
1805                    output_container.find(".bsk-pdfm-pdfs-dropdown").focus();
1806                }else if( output == 'ul' || output == 'ol' ){
1807                    if( return_data.error_message ){
1808                        $( return_data.error_message ).insertBefore( obj_insert_before );
1809
1810                        return;
1811                    }
1812                    
1813                    $( return_data.category_out ).insertBefore( obj_insert_before );
1814                    $( return_data.pagination ).insertBefore( obj_insert_before );
1815                }else if( output == 'columns' ){
1816                    
1817                }
1818                
1819                return;
1820            } //end for output for category
1821            
1822            /*
1823             * output for selector
1824             */
1825            if( shortcode_type == 'selector' ){
1826                
1827                output_container.find(".bsk-pdfm-category-output").remove();
1828                output_container.find(".bsk-pdfm-pagination").remove();
1829
1830                if( output == 'dropdown' ){
1831                    output_container.find(".bsk-pdfm-pdfs-dropdown").focus();
1832                }else if( output == 'ul' || output == 'ol' ){
1833                    var obj_insert_before = output_container.find(".bsk-pdfm-pdfs-shortcode-attr");
1834                    if( output_container.find(".bsk-pdfm-credit-link-container").length > 0 ){
1835                        obj_insert_before = output_container.find(".bsk-pdfm-credit-link-container");
1836                    }
1837
1838                    if( return_data.error_message ){
1839                        $( return_data.error_message ).insertBefore( obj_insert_before );
1840
1841                        return;
1842                    }
1843
1844                    $( return_data.category_out ).insertBefore( obj_insert_before );
1845                    $( return_data.pagination ).insertBefore( obj_insert_before );
1846                }else if( output == 'columns' ){
1847                    
1848                }
1849            } //end for output for category
1850            
1851       }); /* //$.post */
1852       
1853       output_container.resize();
1854    });
1855
1856    /**************************************************
1857     *
1858     * Infinite Scrolling
1859     *
1860     **************************************************/
1861    $( window ).scroll( function () { 
1862
1863        if ( $( ".bsk_pdfm_infinite_scrolling_container" ).length < 1 ||
1864             $( ".bsk_pdfm_infinite_scrolling_container" ).length > 1 ||
1865             $( ".bsk_pdfm_infinite_scrolling_header" ).length < 1 || 
1866             $( ".bsk_pdfm_infinite_scrolling_header" ).length > 1 ) {
1867
1868            return;
1869        }
1870
1871        var scrolling_container_obj = $( ".bsk_pdfm_infinite_scrolling_container" );
1872        var header_obj = scrolling_container_obj.find( ".bsk_pdfm_infinite_scrolling_header" );
1873
1874        var current_page = header_obj.find( ".bsk_pdfm_infinite_scrolling_header_current_page" ).val();
1875        var max_page = header_obj.find( ".bsk_pdfm_infinite_scrolling_header_page_max" ).val();
1876
1877        current_page = parseInt( current_page );
1878        max_page = parseInt( max_page );
1879
1880        if ( max_page < 2 || current_page >= max_page ) {
1881            //console.log( current_page, max_page );
1882            return;
1883        }
1884
1885        var loading_status = header_obj.find( ".bsk_pdfm_infinite_scrolling_header_loading" ).val();
1886        if ( loading_status > 0 ) {
1887            //console.log( 'Lock loading....' );
1888            return;
1889        }
1890
1891        if ( $(window).scrollTop() >= $(document).height() - $(window).height() - 10 ) {
1892            header_obj.find( ".bsk_pdfm_infinite_scrolling_header_loading" ).val( 1 )
1893
1894            current_page++;
1895            //call function to refresh pdfs, 
1896            //needs to append ajax loader and set status fields' value in ajax callback function
1897            ajax_query_pdfs_function( { infinite_scrolling: true, scrolling_container: scrolling_container_obj, header : header_obj,  current: current_page, max: max_page } );
1898            
1899            //var ajax_loader = $( "#bsk_pdfm_infinite_scrolling_ajax_loader_ID" ).html();
1900            //var ajax_loader_p = '<p id="bsk_pdfm_infinite_scrolling_ajax_loader_ID">' + ajax_loader + '</p>';
1901            //$( "#bsk_pdfm_infinite_scrolling_container_ID" ).append( ajax_loader_p );
1902            /*$.post( ajaxurl, data, function(response) {
1903                $( "#bsk_pdfm_infinite_scrolling_ajax_loader_ID" ).remove();
1904    
1905                var return_data = $.parseJSON( response );
1906                
1907                $( "#bsk_pdfm_infinite_scrolling_header_current_page_ID" ).val( current_page );
1908                $( "#bsk_pdfm_infinite_scrolling_ajax_ID" ).append( return_data.data );
1909                
1910                $( "#bsk_pdfm_infinite_scrolling_header_loading_ID" ).val( 0 );
1911                //console.log( 'Unlock loading....' );
1912            });*/
1913        }
1914        
1915    });
1916
1917    /**************************************************
1918     *
1919     * Embedded PDF Viewer
1920     *
1921     **************************************************/
1922    function is_mobile_device() {
1923		if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent ) ) {
1924			return true;
1925		}
1926
1927		return false;
1928	}
1929
1930    $( ".bsk-pdfm-output-container.embeded-pdf-container" ).each ( function() {
1931        var pdf_id = $( this ).data( "id" );
1932        var disable_viewer_mobile = $( this ).data( "disable_viewer_on_mobile" ).toUpperCase();
1933        var show_download_on_mobile = $( this ).data( "show_download_on_mobile" ).toUpperCase();
1934        var show_download_on_desktop = $( this ).data( "show_download_on_desktop" ).toUpperCase();
1935
1936        if ( is_mobile_device() ) {
1937            if ( disable_viewer_mobile == 'YES' ) {
1938                $( "#bsk_pdfm_embeded_pdf_iframe_ID_" + pdf_id ).css( "display", "none" );
1939            } else {
1940                $( "#bsk_pdfm_embeded_pdf_iframe_ID_" + pdf_id ).attr( 'src', $( "#bsk_pdfm_embeded_pdf_viewer_url_ID_" + pdf_id ).val() );
1941            }
1942
1943            if ( show_download_on_mobile == 'YES' ) {
1944                $( "#bsk_pdfm_embeded_pdf_download_link_p_ID_" + pdf_id ).css( "display", "block" );
1945            } else {
1946                $( "#bsk_pdfm_embeded_pdf_download_link_p_ID_" + pdf_id ).css( "display", "none" );
1947            }
1948        } else {
1949            
1950            $( "#bsk_pdfm_embeded_pdf_iframe_ID_" + pdf_id ).attr( 'src', $( "#bsk_pdfm_embeded_pdf_viewer_url_ID_" + pdf_id ).val() );
1951
1952            if ( show_download_on_desktop == 'YES' ) {
1953                $( "#bsk_pdfm_embeded_pdf_download_link_p_ID_" + pdf_id ).css( "display", "block" );
1954            } else {
1955                $( "#bsk_pdfm_embeded_pdf_download_link_p_ID_" + pdf_id ).css( "display", "none" );
1956            }
1957        }
1958    });
1959
1960});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.