PageSourceSearch

https://www.vivere.napoli.it/wp-content/themes/Newspaper/js/site.js

js vivere.napoli.it collected 2026-10-05 02:41:56 UTC 46,172 bytes, 1,615 lines download raw bytes

1/*
2    tagDiv - 2013
3    Our portfolio:  http://themeforest.net/user/tagDiv/portfolio
4
5    Thanks for using our theme! :)
6*/
7
8
9
10
11var td_is_js_phone = false; //true if current view port width < 768
12
13
14var td_is_slide_moving = false; //disable touch when the touch sliders are moving
15
16
17var td_is_touch_device = !!('ontouchstart' in window);
18var td_is_iPad = navigator.userAgent.match(/iPad/i) != null;
19var td_is_iOS = ( navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false );
20var td_is_ie10 = false;
21var td_is_ie = false;
22
23var td_is_phone_screen = false;
24//update is phone screen
25if ((jQuery(window).width() < 768 || jQuery(window).height() < 768) && td_is_iPad === false) {
26    td_is_phone_screen = true
27}
28
29
30
31//ie 10 check
32if (Function('/*@cc_on return document.documentMode===10@*/')()){
33    jQuery("html").addClass("ie10");
34    td_is_ie10 = true;
35}
36
37
38if (jQuery('html').is('.ie8, .ie9') || td_is_ie10 === true) {
39    td_is_ie = true;
40}
41
42
43
44
45/*  ----------------------------------------------------------------------------
46    tagDiv magic cache
47 */
48var td_local_cache = {
49    data: {},
50    remove: function (resurce_id) {
51        delete td_local_cache.data[resurce_id];
52    },
53    exist: function (resurce_id) {
54        return td_local_cache.data.hasOwnProperty(resurce_id) && td_local_cache.data[resurce_id] !== null;
55    },
56    get: function (resurce_id) {
57        //console.log('Getting in cache for resurce_id' + resurce_id);
58        return td_local_cache.data[resurce_id];
59    },
60    set: function (resurce_id, cachedData) {
61        td_local_cache.remove(resurce_id);
62        td_local_cache.data[resurce_id] = cachedData;
63    }
64};
65
66
67
68
69/*  ----------------------------------------------------------------------------
70 Menu script
71 */
72
73jQuery('#td-top-menu .sf-menu').supersubs({
74    minWidth:    10, // minimum width of sub-menus in em units
75    maxWidth:    40, // maximum width of sub-menus in em units
76    extraWidth:  1 // extra width can ensure lines don't sometimes turn over
77});
78
79if (td_is_touch_device) {
80    //touch
81    jQuery('#td-top-menu .sf-menu').superfish({
82        delay:300,
83        speed:'fast',
84        useClick:true
85    });
86} else {
87    //not touch
88    jQuery('#td-top-menu .sf-menu').superfish({
89        delay:500,
90        speed:200,
91        useClick:false
92    });
93}
94
95/*  ----------------------------------------------------------------------------
96    On load
97 */
98jQuery().ready(function() {
99
100
101
102    //resize all the videos if we have them
103    td_resize_videos();
104
105
106
107
108
109
110    /*  ----------------------------------------------------------------------------
111        Affix menu
112     */
113
114    var td_menu_offset = 150;
115
116
117    switch(tds_snap_menu) {
118        case 'never':
119            // do nothing? :)
120            jQuery('.td-menu-wrap').css('position', 'relative'); //css fix
121            break;
122        default:
123            jQuery('.td-menu-background').affix({
124                offset: {
125                    top: td_menu_offset
126                }
127            });
128    }
129
130
131    //put focus on search box in blog header
132    jQuery('#search-button').click(function(){
133        jQuery(this).delay(200).queue(function(){
134            document.getElementById("td-header-search").focus();
135            jQuery(this).dequeue();
136        });
137    });
138
139
140    //retina images
141    td_retina();
142
143    //colorbox
144    jQuery('.td-featured-img').colorbox({
145        maxWidth:"95%",
146        maxHeight:"95%",
147        fixed:true
148    });
149
150
151
152    //load the ajax functions
153    td_ajax_load();
154
155    td_ajax_search();
156
157
158    //show the mobile menu only on phone screen
159    if (td_is_phone_screen) {
160        //alert('mobile menu');
161        td_mobile_menu2();
162    } else {
163        if (td_is_touch_device === false) {
164            //run the mobile menu script on desktop!
165            td_mobile_menu2();
166        }
167    }
168
169
170    if (td_is_iPad === false && td_is_touch_device === true && tds_mobile_swipe == 'swipe') {
171        //load fast click only on touch devices, except ipad
172        window.addEventListener('load', function () {
173            FastClick.attach(document.body);
174        }, false);
175
176    }
177
178
179    /*  ----------------------------------------------------------------------------
180        Scroll to top
181     */
182
183    var td_is_scrolling_animation = false;
184
185
186    jQuery(document).bind('mousewheel DOMMouseScroll MozMousePixelScroll', function(e){
187        if (td_is_scrolling_animation === false) {
188            return;
189        } else {
190            td_is_scrolling_animation = false;
191            jQuery("html, body").stop();
192        }
193    });
194
195
196    if (document.addEventListener){
197        document.addEventListener('touchmove', function(e) {
198            if (td_is_scrolling_animation === false) {
199                return;
200            } else {
201                td_is_scrolling_animation = false;
202                jQuery("html, body").stop();
203            }
204        }, false);
205    }
206
207
208    jQuery(window).scroll(function(){
209        if(td_is_scrolling_animation) {
210            return;
211        }
212        if (jQuery(this).scrollTop() > 400) {
213            jQuery('.td-scroll-up').addClass('td-scroll-up-visible');
214        } else {
215            jQuery('.td-scroll-up').removeClass('td-scroll-up-visible');
216        }
217    });
218
219    jQuery('.td-scroll-up').click(function(){
220        if(td_is_scrolling_animation) {
221            return;
222        }
223        td_is_scrolling_animation = true;
224
225        jQuery('.td-scroll-up').removeClass('td-scroll-up-visible');
226
227        jQuery("html, body").animate({ scrollTop: 0 }, {
228                    duration: 1200,
229                    easing:'easeInOutQuart',
230                    complete: function(){
231                            td_is_scrolling_animation = false;
232                        }
233                    }
234            );
235        return false;
236    });
237
238
239
240    td_fake_clicks();
241
242
243    /**
244     * Modal window js code
245     */
246    jQuery('.popup-with-form').magnificPopup({
247        type: 'inline',
248        preloader: false,
249        focus: '#name',
250
251        // When elemened is focused, some mobile browsers in some cases zoom in
252        // It looks not nice, so we disable it:
253        callbacks: {
254            beforeOpen: function() {
255                //empty all fields
256                td_modala_empty_all_fields();
257
258                //empty error display div
259                td_modala_empty_err_div();
260
261                if(jQuery(window).width() < 700) {
262                    this.st.focus = false;
263                } else {
264                    if (td_is_ie === false) {
265                        //do not focus on ie 10
266                        this.st.focus = '#login_email';
267                    }
268
269                }
270            }
271        }
272    });
273
274
275    //login
276    jQuery('#login-link').on( "click", function() {
277        //hides or shows the divs with inputs
278        show_hide_content_modala([['#td-login-div', 1], ['#td-register-div', 0], ['#td-forgot-pass-div', 0]]);
279
280        //moves focus on the tab
281        modala_swich_tabs([['#login-link', 1], ['#register-link', 0]]);
282
283         if(jQuery(window).width() > 700 && td_is_ie === false) {
284             jQuery('#login_email').focus();
285         }
286
287        //empty all fields
288        //td_modala_empty_all_fields();
289
290        //empty error display div
291        td_modala_empty_err_div();
292    });
293    //login button
294    jQuery('#login_button').on( "click", function() {
295        handle_login_for_modal_window();
296    });
297    //enter key on #login_pass
298    jQuery('#login_pass').keydown(function(event) {
299        if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
300            handle_login_for_modal_window();
301        }
302    });
303
304    //register
305    jQuery('#register-link').on( "click", function() {
306        //hides or shows the divs with inputs
307        show_hide_content_modala([['#td-login-div', 0], ['#td-register-div', 1], ['#td-forgot-pass-div', 0]]);
308
309        //moves focus on the tab
310        modala_swich_tabs([['#login-link', 0], ['#register-link', 1]]);
311
312         if(jQuery(window).width() > 700  && td_is_ie === false) {
313            jQuery('#register_email').focus();
314         }
315
316        //empty all fields
317        //td_modala_empty_all_fields();
318
319        //empty error display div
320        td_modala_empty_err_div();
321    });
322    //register button
323    jQuery('#register_button').on( "click", function() {
324        handle_register_for_modal_window();
325    });
326    //enter key on #register_user
327    jQuery('#register_user').keydown(function(event) {
328        if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
329            handle_register_for_modal_window();
330        }
331    });
332
333    //forgot pass
334    jQuery('#forgot-pass-link').on( "click", function() {
335        //hides or shows the divs with inputs
336        show_hide_content_modala([['#td-login-div', 0], ['#td-register-div', 0], ['#td-forgot-pass-div', 1]]);
337
338        //moves focus on the tab
339        modala_swich_tabs([['#login-link', 0], ['#register-link', 0]]);
340
341        if(jQuery(window).width() > 700 && td_is_ie === false) {
342            jQuery('#forgot_email').focus();
343        }
344
345        //empty all fields
346        //td_modala_empty_all_fields();
347
348        //empty error display div
349        td_modala_empty_err_div();
350    });
351    //forgot button
352    jQuery('#forgot_button').on( "click", function() {
353        handle_forgot_password_for_modal_window();
354    });
355    //enter key on #forgot_email
356    jQuery('#forgot_email').keydown(function(event) {
357        if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
358            handle_forgot_password_for_modal_window();
359        }
360    });
361
362
363
364
365    //fake placeholder for ie
366    jQuery('input, textarea').placeholder();
367
368
369
370
371
372    /**
373     * More stories box
374     */
375    if(tds_more_articles_on_post_enable == "show") {
376        //adding event to scroll
377        jQuery(window).scroll(function(){
378
379            var cookie_more_box = td_read_site_cookie('td-cookie-more-articles');
380            //alert(cookie_more_box);
381
382            //setting distance from the top
383            if(!isNaN(parseInt(tds_more_articles_on_post_pages_distance_from_top)) && isFinite(tds_more_articles_on_post_pages_distance_from_top) && parseInt(tds_more_articles_on_post_pages_distance_from_top) > 0){
384                var set_distance = parseInt(tds_more_articles_on_post_pages_distance_from_top);
385            } else {
386                var set_distance = 400;
387            }
388
389            if (jQuery(this).scrollTop() > set_distance && cookie_more_box != 'hide-more-articles-box') {
390                jQuery('.td-more-articles-box').addClass('td-front-end-display-block');
391            } else {
392                jQuery('.td-more-articles-box').removeClass('td-front-end-display-block');
393            }
394        });
395
396        //adding event to hide the box
397        jQuery('.td-close-more-articles-box').click(function(){
398
399            //hiding the box
400            jQuery('.td-more-articles-box').removeClass('td-front-end-display-block');
401            jQuery('.td-more-articles-box').hide();
402
403            //cookie life
404            if(!isNaN(parseInt(tds_more_articles_on_post_time_to_wait)) && isFinite(tds_more_articles_on_post_time_to_wait)){
405                //setting cookie
406                td_create_cookie('td-cookie-more-articles', 'hide-more-articles-box', parseInt(tds_more_articles_on_post_time_to_wait));
407            }
408
409
410
411        });
412    }
413
414
415}); //end on load
416
417
418//patern to check emails
419var td_mod_pattern_email = /^[a-zA-Z0-9][a-zA-Z0-9_\.-]{0,}[a-zA-Z0-9]@[a-zA-Z0-9][a-zA-Z0-9_\.-]{0,}[a-z0-9][\.][a-z0-9]{2,4}$/;
420
421/**
422 * handle all request made from login tab
423 */
424function handle_login_for_modal_window() {
425    var login_email = jQuery('#login_email').val();
426    var login_pass = jQuery('#login_pass').val();
427
428    if(login_email && login_pass){
429        //empty error display div
430        //td_modala_empty_err_div();
431
432        modala_add_remove_class(['.td_display_err', 1, "td_display_msg_ok"]);
433        jQuery('.td_display_err').show();
434        td_modala_write_err_div(td_please_wait);
435
436        //call ajax for log in
437        td_modala_call_ajax('td_mod_login', login_email, '', login_pass);
438    } else {
439        jQuery('.td_display_err').show();
440        td_modala_write_err_div(td_email_user_pass_incorrect);
441    }
442}
443
444/**
445 * handle all request made from register tab
446 */
447function handle_register_for_modal_window() {
448    var register_email = jQuery('#register_email').val();
449    var register_user = jQuery('#register_user').val();
450
451    if(td_mod_pattern_email.test(register_email) && register_user){
452        //empty error display div
453        //td_modala_empty_err_div();
454
455        modala_add_remove_class(['.td_display_err', 1, "td_display_msg_ok"]);
456        jQuery('.td_display_err').show();
457        td_modala_write_err_div(td_please_wait);
458
459        //call ajax
460        td_modala_call_ajax('td_mod_register', register_email, register_user, '');
461    } else {
462        jQuery('.td_display_err').show();
463        td_modala_write_err_div(td_email_user_incorrect);
464    }
465}
466
467/**
468 * handle all request made from forgot password tab
469 */
470function handle_forgot_password_for_modal_window() {
471    var forgot_email = jQuery('#forgot_email').val();
472
473    if(td_mod_pattern_email.test(forgot_email)){
474        //empty error display div
475        //td_modala_empty_err_div();
476
477        modala_add_remove_class(['.td_display_err', 1, "td_display_msg_ok"]);
478        jQuery('.td_display_err').show();
479        td_modala_write_err_div(td_please_wait);
480
481        //call ajax
482        td_modala_call_ajax('td_mod_remember_pass', forgot_email, '', '');
483    } else {
484        jQuery('.td_display_err').show();
485        td_modala_write_err_div(td_email_incorrect);
486    }
487}
488
489/**
490 * swhich the div's acordingly to the user action (Log In, Register, Remember Password)
491 *
492 * ids_array : array of ids that have to be showed or hidden
493 */
494function show_hide_content_modala(ids_array) {
495    var length = ids_array.length;
496
497    for (var i = 0; i < length; i++) {
498        element_id = ids_array[i][0];
499        element_visibility = ids_array[i][1];
500
501        if (element_visibility == 1) {
502            jQuery(element_id).removeClass('td-dispaly-none').addClass('td-dispaly-block');
503        } else {
504            jQuery(element_id).removeClass('td-dispaly-block').addClass('td-dispaly-none');
505        }
506    }
507}
508
509
510/**
511 * swhich the tab's acordingly to the user action (Log In, Register, Remember Password)
512 *
513 * ids_array : array of ids that have to be focus on or unfocus
514 */
515function modala_swich_tabs(ids_array) {
516    var length = ids_array.length;
517
518    for (var i = 0; i < length; i++) {
519        element_id = ids_array[i][0];
520        element_visibility = ids_array[i][1];
521
522        if (element_visibility == 1) {
523            jQuery(element_id).addClass('td_login_tab_focus');
524        } else {
525            jQuery(element_id).removeClass('td_login_tab_focus');
526        }
527    }
528}
529
530
531/**
532 * adds or remove a class from an html object
533 *
534 * param : array with object identifier (id - # or class - .)
535 * ex: ['.class_indetifier', 1, 'class_to_add'] or ['.class_indetifier', 0, 'class_to_remove']
536 */
537function modala_add_remove_class(param) {
538
539    //add class
540    if (param[1] == 1) {
541        jQuery(param[0]).addClass(param[2]);
542
543    //remove class
544    } else {
545        jQuery(param[0]).removeClass(param[2]);
546    }
547}
548
549
550/**
551 * empty the error div
552 */
553function td_modala_empty_err_div() {
554    jQuery('.td_display_err').html('');
555    jQuery('.td_display_err').hide();
556}
557
558
559/**
560 * write text to error div
561 */
562function td_modala_write_err_div(message) {
563    jQuery('.td_display_err').html(message);
564}
565
566/**
567 * empty all fields in modal window
568 */
569function td_modala_empty_all_fields() {
570    //login fields
571    jQuery('#login_email').val('');
572    jQuery('#login_pass').val('');
573
574    //register fields
575    jQuery('#register_email').val('');
576    jQuery('#register_user').val('');
577
578    //forgot pass
579    jQuery('#forgot_email').val('');
580}
581
582
583/**
584 * call to server from modal window
585 *
586 * @param $action : what action (log in, register, forgot email)
587 * @param $email  : the email beening sent
588 * @param $user   : the user name beening sent
589 */
590function td_modala_call_ajax(sent_action, sent_email, sent_user, sent_pass) {
591    jQuery.ajax({
592        type: 'POST',
593        url: td_ajax_url,
594        data: {
595            action: sent_action,
596            email: sent_email,
597            user: sent_user,
598            pass: sent_pass
599        },
600        success: function(data, textStatus, XMLHttpRequest){
601            var td_data_object = jQuery.parseJSON(data); //get the data object
602
603            //check the response from server
604            switch(td_data_object[0]) {
605                case 'login':
606                    if(td_data_object[1] == 1) {
607                        location.reload(true);
608                    } else {
609                        modala_add_remove_class(['.td_display_err', 0, 'td_display_msg_ok']);
610                        jQuery('.td_display_err').show();
611                        td_modala_write_err_div(td_data_object[2]);
612                    }
613                    break;
614
615                case 'register':
616                    if(td_data_object[1] == 1) {
617                        modala_add_remove_class(['.td_display_err', 1, "td_display_msg_ok"]);
618                        jQuery('.td_display_err').show();
619                    } else {
620                        modala_add_remove_class(['.td_display_err', 0, "td_display_msg_ok"]);
621                        jQuery('.td_display_err').show();
622                    }
623                    td_modala_write_err_div(td_data_object[2]);
624                    break;
625
626                case 'remember_pass':
627                    if(td_data_object[1] == 1) {
628                        modala_add_remove_class(['.td_display_err', 1, "td_display_msg_ok"]);
629                        jQuery('.td_display_err').show();
630                    } else {
631                        modala_add_remove_class(['.td_display_err', 0, "td_display_msg_ok"]);
632                        jQuery('.td_display_err').show();
633                    }
634                    td_modala_write_err_div(td_data_object[2]);
635                    break;
636
637            }
638
639
640        },
641        error: function(MLHttpRequest, textStatus, errorThrown){
642            //console.log(errorThrown);
643        }
644    });
645}
646
647function td_live_responsive(is_on_ready) {
648    var td_window_width = jQuery(window).width();
649
650    if (td_window_width < 768) {
651        if (td_is_js_phone === false) {
652            //console.log('mobile');
653
654        }
655        td_is_js_phone = true;
656    } else {
657        if (td_is_js_phone === true || is_on_ready === true) {
658            //console.log('not mobile');
659            //fix for small -> big top menu
660            jQuery('#td-top-menu .sf-menu').supersubs({
661                minWidth:    15, // minimum width of sub-menus in em units
662                maxWidth:    40, // maximum width of sub-menus in em units
663                extraWidth:  1 // extra width can ensure lines don't sometimes turn over
664            });
665        }
666        td_is_js_phone = false;
667
668    }
669}
670
671
672//click on a div -> go to a url
673function td_fake_clicks() {
674    jQuery('.td-fake-click').click(function(){
675        window.location = jQuery(this).data("fake-click");
676    });
677}
678
679
680
681
682var td_resize_timer_id;
683jQuery(window).resize(function() {
684    clearTimeout(td_resize_timer_id);
685    td_resize_timer_id = setTimeout(td_done_resizing, 500);
686
687});
688
689function td_done_resizing(){
690    td_resize_videos();
691}
692
693
694
695/*  ----------------------------------------------------------------------------
696    Resize the videos
697 */
698function td_resize_videos() {
699    //youtube in content
700    jQuery(document).find('iframe[src*="youtube.com"]').each(function() {
701        var td_video = jQuery(this);
702        td_video.attr('width', '100%');
703        var td_video_width = td_video.width();
704        td_video.css('height', td_video_width * 0.6, 'important');
705    });
706
707
708    //vimeo in content
709    jQuery(document).find('iframe[src*="vimeo.com"]').each(function() {
710        var td_video = jQuery(this);
711        td_video.attr('width', '100%');
712        var td_video_width = td_video.width();
713        td_video.css('height', td_video_width * 0.6, 'important');
714    })
715
716
717    //daily motion in content
718    jQuery(document).find('iframe[src*="dailymotion.com"]').each(function() {
719        var td_video = jQuery(this);
720        td_video.attr('width', '100%');
721        var td_video_width = td_video.width();
722        td_video.css('height', td_video_width * 0.6, 'important');
723    })
724}
725
726
727
728
729/*  ----------------------------------------------------------------------------
730    Ajax search
731 */
732var td_aj_search_cur_sel = 0;
733var td_aj_search_results = 0;
734var td_aj_first_down_up = true;
735function td_ajax_search() {
736
737
738
739
740    jQuery('#td-header-search').keydown(function(event) {
741
742        //console.log(event.keyCode);
743
744
745        if ((event.which && event.which == 39) || (event.keyCode && event.keyCode == 39) || (event.which && event.which == 37) || (event.keyCode && event.keyCode == 37)) {
746            //do nothing on left and right arrows
747            td_aj_search_input_focus();
748            return;
749        }
750
751        if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
752
753            //redirectSearch('q');
754            var td_aj_cur_element = jQuery('.td-aj-cur-element');
755            if (td_aj_cur_element.length > 0) {
756                //alert('ra');
757                var td_go_to_url = td_aj_cur_element.find('.entry-title a').attr('href');
758                window.location = td_go_to_url;
759            } else {
760                jQuery(this).parent().parent().submit();
761            }
762
763            return false; //redirect for search on enter
764        } else {
765
766            if ((event.which && event.which == 40) || (event.keyCode && event.keyCode == 40)) {
767                // down
768                td_aj_search_move_prompt_down();
769                return false; //disable the envent
770
771            } else if((event.which && event.which == 38) || (event.keyCode && event.keyCode == 38)) {
772                //up
773                td_aj_search_move_prompt_up();
774                return false; //disable the envent
775            } else {
776
777                //for backspace we have to check if the search query is empty and if so, clear the list
778                if ((event.which && event.which == 8) || (event.keyCode && event.keyCode == 8)) {
779                    //if we have just one character left, that means it will be deleted now and we also have to clear the search results list
780                    var search_query = jQuery(this).val();
781                    if (search_query.length == 1) {
782                        jQuery('#td-aj-search').empty();
783                    }
784
785                }
786
787                //various keys
788                td_aj_search_input_focus();
789                setTimeout("td_ajax_search_do_request()",100);
790            }
791            return true;
792        }
793
794    });
795
796
797
798}
799
800//moves the select up
801function td_aj_search_move_prompt_up() {
802
803
804    if (td_aj_first_down_up === true) {
805        td_aj_first_down_up = false;
806        if (td_aj_search_cur_sel === 0) {
807            td_aj_search_cur_sel = td_aj_search_results - 1;
808        } else {
809            td_aj_search_cur_sel--;
810        }
811    } else {
812        if (td_aj_search_cur_sel === 0) {
813            td_aj_search_cur_sel = td_aj_search_results;
814        } else {
815            td_aj_search_cur_sel--;
816        }
817    }
818
819
820    jQuery('.td_mod_aj_search').removeClass('td-aj-cur-element');
821
822
823
824    if (td_aj_search_cur_sel  > td_aj_search_results -1) {
825        //the input is selected
826        jQuery('.td-search-form').fadeTo(100, 1);
827    } else {
828        td_aj_search_input_remove_focus();
829        jQuery('.td_mod_aj_search').eq(td_aj_search_cur_sel).addClass('td-aj-cur-element');
830    }
831
832
833
834}
835
836//moves the select prompt down
837function td_aj_search_move_prompt_down() {
838
839    if (td_aj_first_down_up === true) {
840        td_aj_first_down_up = false;
841    } else {
842        if (td_aj_search_cur_sel === td_aj_search_results) {
843            td_aj_search_cur_sel = 0;
844        } else {
845            td_aj_search_cur_sel++;
846        }
847    }
848
849
850    jQuery('.td_mod_aj_search').removeClass('td-aj-cur-element');
851
852    if (td_aj_search_cur_sel > td_aj_search_results - 1 ) {
853        //the input is selected
854        jQuery('.td-search-form').fadeTo(100, 1);
855    } else {
856        td_aj_search_input_remove_focus();
857        jQuery('.td_mod_aj_search').eq(td_aj_search_cur_sel).addClass('td-aj-cur-element');
858    }
859
860
861}
862
863
864// puts the focus on the input box
865function td_aj_search_input_focus() {
866    td_aj_search_cur_sel = 0;
867    td_aj_first_down_up = true;
868    jQuery('.td-search-form').fadeTo(100, 1);
869    jQuery('.td_mod_aj_search').removeClass('td-aj-cur-element');
870}
871
872//removes the focus from the input box
873function td_aj_search_input_remove_focus() {
874    if (td_aj_search_results !== 0) {
875        jQuery('.td-search-form').css('opacity', 0.5);
876    }
877}
878
879//makes an ajax request
880function td_ajax_search_do_request() {
881
882    if (jQuery('#td-header-search').val() == '') {
883        td_aj_search_input_focus();
884        return;
885    }
886
887
888    var search_query = jQuery('#td-header-search').val();
889
890
891    //do we have a cache hit
892    if (td_local_cache.exist(search_query)) {
893        td_ajax_search_process_request(td_local_cache.get(search_query));
894        return; //cache HIT
895    }
896
897
898    //fk no cache hit - do the real request
899
900
901
902    jQuery.ajax({
903        type: 'POST',
904        url: td_ajax_url,
905        data: {
906            action: 'td_ajax_search',
907            td_string: search_query
908        },
909        success: function(data, textStatus, XMLHttpRequest){
910            td_local_cache.set(search_query, data);
911            td_ajax_search_process_request(data);
912        },
913        error: function(MLHttpRequest, textStatus, errorThrown){
914            //console.log(errorThrown);
915        }
916    });
917}
918
919function td_ajax_search_process_request(data) {
920    var current_query = jQuery('#td-header-search').val();
921
922    //the search is empty - drop results
923    if (current_query == '') {
924        jQuery('#td-aj-search').empty();
925        return;
926    }
927
928    var td_data_object = jQuery.parseJSON(data); //get the data object
929    //drop the result - it's from a old query
930    if (td_data_object.td_search_query !== current_query) {
931        return;
932    }
933
934    //reset the current selection and total posts
935    td_aj_search_cur_sel = 0;
936    td_aj_search_results = td_data_object.td_total_in_list;
937    td_aj_first_down_up = true;
938
939
940    //update the query
941    jQuery('#td-aj-search').html(td_data_object.td_data);
942
943    /*
944     td_data_object.td_data
945     td_data_object.td_total_results
946     td_data_object.td_total_in_list
947     */
948}
949
950
951
952
953
954
955function td_mobile_menu2() {
956    //return;
957    //alert('mobile menu');
958    //******************************************************************
959    //MOBILE MENU new
960
961    // helper functions
962
963    var trim = function(str)
964    {
965        return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g,'');
966    };
967
968    var hasClass = function(el, cn)
969    {
970        return (' ' + el.className + ' ').indexOf(' ' + cn + ' ') !== -1;
971    };
972
973    var addClass = function(el, cn)
974    {
975        if (!hasClass(el, cn)) {
976            el.className = (el.className === '') ? cn : el.className + ' ' + cn;
977        }
978    };
979
980    var removeClass = function(el, cn)
981    {
982        el.className = trim((' ' + el.className + ' ').replace(' ' + cn + ' ', ' '));
983    };
984
985    var hasParent = function(el, id)
986    {
987        if (el) {
988            do {
989                if (el.id === id) {
990                    return true;
991                }
992                if (el.nodeType === 9) {
993                    break;
994                }
995            }
996            while((el = el.parentNode));
997        }
998        return false;
999    };
1000
1001    // normalize vendor prefixes
1002
1003    var doc = document.documentElement;
1004
1005    var transform_prop = window.Modernizr.prefixed('transform'),
1006        transition_prop = window.Modernizr.prefixed('transition'),
1007        transition_end = (function() {
1008            var props = {
1009                'WebkitTransition' : 'webkitTransitionEnd',
1010                'MozTransition'    : 'transitionend',
1011                'OTransition'      : 'oTransitionEnd otransitionend',
1012                'msTransition'     : 'MSTransitionEnd',
1013                'transition'       : 'transitionend'
1014            };
1015            return props.hasOwnProperty(transition_prop) ? props[transition_prop] : false;
1016        })();
1017
1018    window.App = (function()
1019    {
1020
1021        var _init = false;
1022        var app = { };
1023
1024        var inner_nav_td = document.getElementById('inner-wrap');
1025        var nav_open = false;
1026        var nav_class = 'js-nav';
1027
1028        //console.log(inner_nav_td);
1029        app.init = function()
1030        {
1031            if (_init) {
1032                return;
1033            }
1034            _init = true;
1035
1036            var closeNavEnd = function(e)
1037            {
1038                if (e && e.target === inner_nav_td) {
1039                    document.removeEventListener(transition_end, closeNavEnd, false);
1040                }
1041                nav_open = false;
1042            };
1043
1044            app.closeNav =function()
1045            {
1046                if (nav_open) {
1047                    // close navigation after transition or immediately
1048                    //console.log(inner_nav_td);
1049
1050                    jQuery('#inner-wrap').css('minHeight', 'auto');
1051                    var duration = (transition_end && transition_prop) ? parseFloat(window.getComputedStyle(inner_nav_td, '')[transition_prop + 'Duration']) : 0;
1052                    if (duration > 0) {
1053                        document.addEventListener(transition_end, closeNavEnd, false);
1054                    } else {
1055                        closeNavEnd(null);
1056                    }
1057                }
1058                removeClass(doc, nav_class);
1059            };
1060
1061            app.openNav = function()
1062            {
1063                if (nav_open) {
1064                    return;
1065                }
1066
1067
1068                //var td_cur_innerwrap_height = jQuery('#inner-wrap').height();
1069
1070//                if (td_cur_innerwrap_height != td_cur_mobile_nav_height) {
1071//
1072//                }
1073//                alert(td_cur_mobile_nav_height);
1074                var td_cur_mobile_nav_height = jQuery('.td-menu-animate').height();
1075                jQuery('#inner-wrap').css('minHeight', td_cur_mobile_nav_height);
1076                addClass(doc, nav_class);
1077
1078
1079                /*
1080                jQuery(this).delay(1000).queue(function(){
1081                    if (td_is_phone_screen) {
1082                        jQuery("html, body").animate({ scrollTop: 0 }, {
1083                                duration: 1000,
1084                                easing:'easeInOutQuart',
1085                                complete: function(){
1086                                    td_is_scrolling_animation = false;
1087                                }
1088                            }
1089                        );
1090                    }
1091
1092                    jQuery(this).dequeue();
1093                });
1094*/
1095
1096
1097                nav_open = true;
1098            };
1099
1100            app.toggleNav = function(e)
1101            {
1102
1103                if (nav_open && hasClass(doc, nav_class)) {
1104                    app.closeNav();
1105                } else {
1106                    app.openNav();
1107                }
1108                if (e) {
1109                    e.preventDefault();
1110                }
1111            };
1112
1113            // open nav with main "nav" button
1114            //document.getElementById('nav-open-btn').addEventListener('click', app.toggleNav, false);
1115
1116            jQuery('#td-top-mobile-toggle a, .td-mobile-close a').click(function(){
1117                app.toggleNav();
1118            });
1119
1120
1121
1122
1123            // close nav with main "close" button
1124            //document.getElementById('nav-close-btn').addEventListener('click', app.toggleNav, false);
1125
1126
1127
1128            addClass(doc, 'js-ready');
1129
1130        };
1131
1132        return app;
1133
1134    })();
1135
1136    if (window.addEventListener) {
1137        window.addEventListener('DOMContentLoaded', window.App.init, false);
1138    }
1139
1140
1141
1142
1143    if (tds_mobile_swipe == 'swipe') {
1144        //jquery touch swipe
1145        jQuery("html").swipe( {
1146            swipeLeft:function(event, distance, duration, fingerCount) {
1147                if (td_is_slide_moving === true) {
1148                    return;
1149                }
1150                window.App.closeNav();
1151            },
1152            swipeRight:function(event, distance, duration, fingerCount) {
1153                if (td_is_slide_moving === true) {
1154                    return;
1155                }
1156                window.App.openNav();
1157            },
1158
1159            //Default is 75px, set to 0 for demo so any distance triggers swipe
1160            threshold:130,
1161            allowPageScroll:'vertical',
1162            triggerOnTouchEnd:false,
1163            fallbackToMouseEvents:false,
1164            excludedElements:'.noSwipe'
1165        });
1166    }
1167
1168
1169}
1170
1171
1172
1173
1174/*  ----------------------------------------------------------------------------
1175    Slider callbacks
1176 */
1177function slideStartedMoving(args) {
1178    td_is_slide_moving = true; //used on touch screens + mobile menu 2
1179}
1180
1181function slideContentComplete(args) {
1182    td_is_slide_moving = false;
1183    if(!args.slideChanged) return false;
1184    jQuery(args.currentSlideObject).parent().find('.slide-info-wrap').removeClass('slide-wrap-active');
1185    jQuery(args.currentSlideObject).children('.slide-info-wrap').addClass('slide-wrap-active');
1186}
1187
1188function slideContentLoaded(args) {
1189    if(!args.slideChanged) return false;
1190   // console.log('loaded');
1191    jQuery(args.currentSlideObject).parent().find('.slide-info-wrap').removeClass('slide-wrap-active');
1192    jQuery(args.currentSlideObject).children('.slide-info-wrap').addClass('slide-wrap-active');
1193}
1194
1195
1196/*  ----------------------------------------------------------------------------
1197    blocks ajax support
1198 */
1199
1200function td_ajax_load() {
1201    /*  ----------------------------------------------------------------------------
1202     AJAX pagination next prev
1203     */
1204
1205    jQuery(".td-ajax-next-page").click(function(event){
1206        event.preventDefault();
1207
1208        if(jQuery(this).hasClass('ajax-page-disabled')) {
1209            return;
1210        }
1211
1212        current_block_obj = td_getBlockObjById(jQuery(this).data('td_block_id'));
1213
1214        current_block_obj.td_current_page++;
1215        td_ajax_block_request(current_block_obj);
1216    });
1217
1218    jQuery(".td_ajax-prev-page").click(function(event){
1219        event.preventDefault();
1220
1221        if(jQuery(this).hasClass('ajax-page-disabled')) {
1222            return;
1223        }
1224
1225        current_block_obj = td_getBlockObjById(jQuery(this).data('td_block_id'));
1226
1227        current_block_obj.td_current_page--;
1228        td_ajax_block_request(current_block_obj);
1229    });
1230
1231
1232    /*  ----------------------------------------------------------------------------
1233     AJAX pagination load more
1234     */
1235
1236    jQuery(".td_ajax_load_more").click(function(event){
1237        event.preventDefault();
1238        if(jQuery(this).hasClass('ajax-page-disabled')) {
1239            return;
1240        }
1241
1242        current_block_obj = td_getBlockObjById(jQuery(this).data('td_block_id'));
1243
1244        current_block_obj.td_current_page++;
1245        td_ajax_block_request(current_block_obj, true, true);
1246    });
1247
1248
1249    /*  ----------------------------------------------------------------------------
1250     AJAX pagination infinite load
1251     */
1252    jQuery('.td_ajax_infinite').waypoint(function(direction) {
1253        if (direction === 'down') {
1254            //console.log('loading');
1255            current_block_obj = td_getBlockObjById(jQuery(this).data('td_block_id'));
1256
1257            current_block_obj.td_current_page++;
1258            td_ajax_block_request(current_block_obj, true, false);
1259        }
1260
1261    }, { offset: '110%' });
1262
1263
1264    /*  ----------------------------------------------------------------------------
1265     AJAX sub cat filter
1266     */
1267    jQuery(".ajax-sub-cat").click(function(event){ //click on an ajax category filter
1268        event.preventDefault();
1269
1270
1271        //get the current block id
1272        var current_block_id = jQuery(this).data('td_block_id');
1273
1274        //destroy any iossliders to avoid bugs
1275        jQuery('#' + current_block_id).find('.iosSlider').iosSlider('destroy');;
1276
1277        //get current block
1278        current_block_obj = td_getBlockObjById(current_block_id);
1279
1280        //change cur cat
1281        current_block_obj.td_cur_cat = jQuery(this).data('cat_id');
1282
1283        current_block_obj.td_current_page = 1;
1284
1285        //do request
1286        td_ajax_block_request(current_block_obj);
1287    });
1288
1289
1290
1291
1292    /*  ----------------------------------------------------------------------------
1293        AJAX MEGA MENU
1294     */
1295
1296
1297
1298    var td_mega_menu_last_link = '';
1299
1300    //it used to hook the mega menu categories
1301    function td_ajax_sub_cat_mega_run(event) {
1302
1303        if (td_mega_menu_last_link != jQuery(this).attr('href')) {
1304            event.preventDefault();
1305            td_mega_menu_last_link = jQuery(this).attr('href');
1306        } else {
1307            td_mega_menu_last_link = '';
1308        }
1309
1310
1311        //get the current block id
1312        var current_block_id = jQuery(this).data('td_block_id');
1313
1314        //get current block
1315        current_block_obj = td_getBlockObjById(current_block_id);
1316
1317
1318        //change cur cat
1319        current_block_obj.td_cur_cat = jQuery(this).data('cat_id');
1320
1321        current_block_obj.td_current_page = 1;
1322
1323        //do request - no append, no animation
1324        td_ajax_block_request(current_block_obj, false, true);
1325    }
1326
1327    //on touch devices use click
1328    if (td_is_touch_device) {
1329        jQuery(".ajax-sub-cat-mega").click(td_ajax_sub_cat_mega_run);
1330    } else {
1331        jQuery(".ajax-sub-cat-mega").hover(td_ajax_sub_cat_mega_run, function (event) {} );
1332    }
1333
1334}
1335
1336function td_getBlockIndex(myID) {
1337    cnt = 0;
1338    tmpReturn = 0;
1339    jQuery.each(td_blocks, function(index, td_block) {
1340        //console.log("pid = " + portfolioItem.id + "  id = " + parseInt(myID));
1341        //alert(myID);
1342        if (td_block.id === myID) {
1343            tmpReturn = cnt;
1344            return false; //brake jquery each
1345        } else {
1346            cnt++;
1347        }
1348    });
1349    return tmpReturn;
1350}
1351
1352
1353function td_getBlockObjById(myID) {
1354    return td_blocks[td_getBlockIndex(myID)];
1355}
1356
1357
1358
1359
1360
1361
1362
1363function td_ajax_block_request(current_block_obj, td_append, td_use_animation) {
1364
1365    //append the content in container instead of replacing it
1366    td_append = (typeof td_append === "undefined") ? false : td_append;
1367
1368    //do we use animation? default = true
1369    td_use_animation = (typeof td_use_animation === "undefined") ? true : td_use_animation;
1370
1371    //search the cache
1372    var current_block_obj_signature = JSON.stringify(current_block_obj);
1373    if (td_local_cache.exist(current_block_obj_signature)) {
1374        //do the animation with no loader
1375        if(td_use_animation === true) {
1376            ajax_pagination_loading_start(current_block_obj, false);
1377        }
1378        td_ajax_block_process_response(td_local_cache.get(current_block_obj_signature));
1379        return 'cache_hit'; //cache HIT
1380    }
1381
1382
1383    //cache miss
1384
1385    if(td_use_animation === true) {
1386        ajax_pagination_loading_start(current_block_obj, true);
1387    }
1388
1389
1390    jQuery.ajax({
1391        type: 'POST',
1392        url: td_ajax_url,
1393        cache:true,
1394
1395        data: {
1396            action: 'td_ajax_block',
1397            td_atts: current_block_obj.atts,
1398            td_cur_cat:current_block_obj.td_cur_cat,
1399            td_block_id:current_block_obj.id,
1400            td_column_number:current_block_obj.td_column_number,
1401            td_current_page:current_block_obj.td_current_page,
1402            block_type:current_block_obj.block_type
1403        },
1404        success: function(data, textStatus, XMLHttpRequest){
1405            td_local_cache.set(current_block_obj_signature, data);
1406            td_ajax_block_process_response(data, td_append);
1407        },
1408        error: function(MLHttpRequest, textStatus, errorThrown){
1409            //console.log(errorThrown);
1410        }
1411    });
1412}
1413
1414
1415function td_ajax_block_process_response(data, td_append) {
1416    //jQuery(this).parent().parent().parent().find('.td_block_inner').html("");
1417    var td_data_object = jQuery.parseJSON(data); //get the data object
1418
1419    /*
1420     td_data_object.td_block_id
1421     td_data_object.td_data
1422     td_data_object.td_cur_cat
1423     */
1424
1425    //subcategories
1426    jQuery('.sub-cat-' + td_data_object.td_block_id).removeClass('cur-sub-cat');
1427    jQuery('#sub-cat-' + td_data_object.td_block_id + '-' + td_data_object.td_cur_cat).addClass('cur-sub-cat');
1428
1429    //load the content (in place or append)
1430    if (td_append === true) {
1431        jQuery('#' + td_data_object.td_block_id).append(td_data_object.td_data); //show content
1432    } else {
1433        jQuery('#' + td_data_object.td_block_id).html(td_data_object.td_data); //show content
1434    }
1435
1436
1437    //hide or show prev
1438    if (td_data_object.td_hide_prev === true) {
1439        jQuery('#prev-page-' + td_data_object.td_block_id).addClass('ajax-page-disabled');
1440    } else {
1441        jQuery('#prev-page-' + td_data_object.td_block_id).removeClass('ajax-page-disabled');
1442    }
1443
1444    //hide or show next
1445    if (td_data_object.td_hide_next === true) {
1446        jQuery('#next-page-' + td_data_object.td_block_id).addClass('ajax-page-disabled');
1447    } else {
1448        jQuery('#next-page-' + td_data_object.td_block_id).removeClass('ajax-page-disabled');
1449    }
1450
1451
1452    var  current_block_obj = td_getBlockObjById(td_data_object.td_block_id);
1453    if (current_block_obj.block_type === 'slide') {
1454        //make the first slide active (to have caption)
1455        jQuery('#' + td_data_object.td_block_id + ' .slide-wrap-active-first').addClass('slide-wrap-active');
1456    }
1457
1458
1459
1460    //loading effects
1461    ajax_pagination_loading_end(current_block_obj);
1462}
1463
1464
1465function ajax_pagination_loading_start(current_block_obj, show_loader) {
1466
1467
1468
1469
1470    var el_cur_td_block_inner = jQuery('#' + current_block_obj.id);
1471    jQuery('.td-loader-gif').remove(); //remove any remaining loaders
1472
1473    el_cur_td_block_inner.addClass('td_block_inner_overflow');
1474
1475    //show the loader only if it's needed
1476    if (show_loader === true) {
1477        el_cur_td_block_inner.parent().append('<img class="td-loader-gif" src="' + td_get_template_directory_uri + '/images/AjaxLoader.gif" alt=""/>');
1478    }
1479
1480
1481    el_cur_td_block_inner.stop();
1482    el_cur_td_block_inner.fadeTo('500',0.1, 'easeInOutCubic');
1483
1484    //auto height => fixed height
1485    var td_tmp_block_height = el_cur_td_block_inner.height();
1486    el_cur_td_block_inner.css('height', td_tmp_block_height);
1487}
1488
1489
1490function ajax_pagination_loading_end(current_block_obj) {
1491
1492    jQuery(this).delay(100).queue(function(){
1493        jQuery('.td-loader-gif').remove();
1494
1495
1496        jQuery('#' + current_block_obj.id).stop();
1497        jQuery('#' + current_block_obj.id).fadeTo(700, 1, function(){
1498            jQuery('#' + current_block_obj.id).css('height', 'auto');
1499            jQuery('.td_block_inner_overflow').removeClass('td_block_inner_overflow');
1500        });
1501
1502        jQuery(this).dequeue();
1503    });
1504
1505    //refresh waypoints for infinit scroll
1506    jQuery.waypoints('refresh');
1507}
1508
1509
1510/*  ----------------------------------------------------------------------------
1511    Add retina support
1512 */
1513
1514function td_retina() {
1515    if (window.devicePixelRatio > 1) {
1516        jQuery('.td-retina').each(function(i) {
1517            var lowres = jQuery(this).attr('src');
1518            var highres = lowres.replace(".png", "@2x.png");
1519            highres = highres.replace(".jpg", "@2x.jpg");
1520            jQuery(this).attr('src', highres);
1521
1522        });
1523
1524
1525        //custom logo support
1526        jQuery('.td-retina-data').each(function(i) {
1527            jQuery(this).attr('src', jQuery(this).data('retina'));
1528            //fix logo aligment on retina devices
1529            jQuery(this).addClass('td-retina-version');
1530        });
1531
1532    }
1533}
1534
1535/*
1536jQuery('body').click(function(e){
1537    if(! jQuery(e.target).hasClass('custom-background')){
1538        alert('clicked on something that has not the class theDIV');
1539    }
1540
1541});*/
1542
1543//click only on BACKGROUND, for devices that don't have touch (ex: phone, tablets)
1544if(!td_is_touch_device && td_ad_background_click_link != '') {
1545
1546    //var ev = ev || window.event;
1547    //var target = ev.target || ev.srcElement;
1548    jQuery('body').click(function(event) {
1549
1550        //getting the target element that the user clicks - for W3C and MSIE
1551        var target = (event.target) ? event.target : event.srcElement;
1552
1553        //only if the background has background image
1554        if(jQuery('body').hasClass('td-boxed-layout')) {
1555            if(target.id == 'inner-wrap' || target.className == 'td-header-menu-wrap' || target.className == 'td-header-bg' || target.className == 'td-menu-background affix-top') {
1556
1557                //open the link ad page
1558                if(td_ad_background_click_target == '_blank') {
1559                    //open in a new window
1560                    window.open(td_ad_background_click_link)
1561                } else {
1562                    //open in the same window
1563                    location.href = td_ad_background_click_link;
1564                }
1565            }
1566        }
1567
1568        //e.stopPropagation();
1569        //stopBubble(event);
1570    });
1571}
1572
1573
1574function stopBubble(e){
1575    if(e && e.stopPropagation) {
1576        e.stopPropagation();
1577    } else {
1578        window.event.cancelBubble=true;
1579    }
1580}
1581
1582
1583
1584/**
1585 * reading cookies
1586 * @param name
1587 * @returns {*}
1588 */
1589function td_read_site_cookie(name) {
1590    var nameEQ = escape(name) + "=";
1591    var ca = document.cookie.split(';');
1592    for (var i = 0; i < ca.length; i++) {
1593        var c = ca[i];
1594        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
1595        if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length, c.length));
1596    }
1597    return null;
1598}
1599
1600
1601/**
1602 *
1603 * @param td_time_cookie_array
1604 *
1605 * @param[0]: name of the cookie
1606 * @param[1]: value of the cookie
1607 * @param[2]: expiration time
1608 */
1609function td_set_cookies_life(td_time_cookie_array) {
1610    var expiry = new Date();
1611    expiry.setTime(expiry.getTime() + td_time_cookie_array[2]);
1612
1613    // Date()'s toGMTSting() method will format the date correctly for a cookie
1614    document.cookie = td_time_cookie_array[0] + "=" + td_time_cookie_array[1] + "; expires=" + expiry.toGMTString() + "; path=/";
1615}

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.