PageSourceSearch

https://retromuzsika.hu/wp-content/themes/bimber/js/front.js?ver=7.3.2

js retromuzsika.hu collected 2026-10-02 12:35:57 UTC 116,770 bytes, 3,783 lines download raw bytes

1/* global window */
2/* global document */
3/* global jQuery */
4/* global g1 */
5/* global bimber_front_config */
6/* global bimber_front_microshare */
7/* global SuperGif */
8/* global Waypoint */
9/* global enquire */
10/* global mashsb */
11/* global auto_load_next_post_params */
12/* global FB */
13/* global mejs */
14/* global ga */
15/* global embedly */
16/* global console */
17
18/*************
19 *
20 * Init env
21 *
22 *************/
23
24(function($) {
25    'use strict';
26
27    var config = $.parseJSON(bimber_front_config);
28
29    // namespace
30    var g1 = {
31        'config': config
32    };
33
34    g1.getWindowWidth = function () {
35        if (typeof window.innerWidth !== 'undefined') {
36            return window.innerWidth;
37        }
38
39        return $(window).width();
40    };
41
42    g1.isDesktopDevice = function () {
43        return g1.getWindowWidth() > g1.getDesktopBreakpoint();
44    };
45
46    g1.getDesktopBreakpoint = function () {
47        var desktopBreakPoint = $('#g1-breakpoint-desktop').css('min-width');
48
49        if ( ! desktopBreakPoint ) {
50            return 9999;
51        }
52
53        desktopBreakPoint = parseInt( desktopBreakPoint, 10 );
54
55        // not set explicitly via css
56        if (desktopBreakPoint === 0) {
57            return 9999;
58        }
59
60        return desktopBreakPoint;
61    };
62
63    g1.isTouchDevice = function () {
64        return ('ontouchstart' in window) || navigator.msMaxTouchPoints;
65    };
66
67    g1.isStickySupported = function () {
68        var prefixes = ['', '-webkit-', '-moz-', '-ms-'];
69        var block = document.createElement('div');
70        var supported = false;
71        var i;
72
73        // Test for native support.
74        for (i = prefixes.length - 1; i >= 0; i--) {
75            try {
76                block.style.position = prefixes[i] + 'sticky';
77            }
78            catch(e) {}
79            if (block.style.position !== '') {
80                supported = true;
81            }
82        }
83
84        return supported;
85    };
86
87    g1.isRTL = function () {
88        return $('body').is('.rtl');
89    };
90
91    g1.log = function(data) {
92        if (window.bimberDebugMode && typeof console !== 'undefined') {
93            console.log(data);
94        }
95    };
96
97    g1.createCookie = function (name,value,time) {
98        var expires;
99
100        if (time) {
101            var date = new Date();
102            var ms = time;
103
104            if (typeof time === 'object') {
105                ms = time.value;
106
107                switch (time.type) {
108                    case 'days':
109                        ms = ms * 24 * 60 * 60 * 1000;
110                        break;
111                }
112            }
113
114            date.setTime(date.getTime() + ms);
115            expires = '; expires=' + date.toGMTString();
116        }
117        else {
118            expires = '';
119        }
120
121        document.cookie = name + '=' + value + expires + '; path=/';
122    };
123
124	g1.readCookie = function (name) {
125        var nameEQ = name + '=';
126        var ca = document.cookie.split(';');
127
128        for(var i = 0; i < ca.length; i += 1) {
129            var c = ca[i];
130            while (c.charAt(0) === ' ') {
131                c = c.substring(1,c.length);
132            }
133
134            if (c.indexOf(nameEQ) === 0) {
135                return c.substring(nameEQ.length,c.length);
136            }
137        }
138
139        return null;
140    };
141
142	g1.removeCookie = function (name) {
143        createCookie(name, '', -1);
144    };
145
146    // expose to the world
147    window.g1 = g1;
148})(jQuery);
149
150/*************
151 *
152 * UI Helpers
153 *
154 ************/
155
156(function ($) {
157
158    'use strict';
159
160    g1.uiHelpers = function () {
161        if (g1.isTouchDevice()) {
162            $('body').removeClass( 'g1-hoverable' );
163        }
164
165        // -----------------
166        // Mailchimp widget.
167        // -----------------
168
169        var mc4wpClasses = [
170            'g1-box',
171            'g1-box-tpl-frame',
172            'g1-newsletter'
173        ];
174
175        var mc4wpBackgroundClasses = [
176            'g1-box-background'
177        ];
178
179        if ('original-2018' === g1.config.stack || 'food' === g1.config.stack ) {
180            mc4wpBackgroundClasses.push('g1-current-background');
181        }
182
183        if ( 'miami' === g1.config.stack || 'music' === g1.config.stack ) {
184            mc4wpClasses.push('g1-dark');
185        }
186
187        $('.widget_mc4wp_form_widget').
188            addClass(mc4wpClasses.join(' ')).
189            wrapInner('<div class="g1-box-inner"></div>').
190            prepend('<div class="g1-box-icon"></div>').
191            append('<div class="' + mc4wpBackgroundClasses.join(' ') + '"></div>');
192
193
194        // ----------
195        // Search UI.
196        // ----------
197
198        $('.g1-drop-the-search').on('click', '.g1-drop-toggle', function (e) {
199            e.preventDefault();
200
201           $('.g1-drop-the-search input.search-field').focus();
202        });
203
204        $('.search-submit').on('click', function(e){
205            var $form = $(this).closest('form');
206            var $input = $('input.search-field', $form);
207            if ( ! $input.val()){
208               e.preventDefault();
209            }
210        });
211
212
213        // -----------
214        // BuddyPress.
215        // -----------
216
217        $('.bbp_widget_login').append('<div class="g1-box-background"></div>');
218
219
220        $('#buddypress .load-more').click(function() {
221            var i = 0;
222            var intervalID = setInterval( function() {
223                $('body').trigger( 'g1PageHeightChanged' );
224                i++;
225                if (i === 5){
226                    window.clearInterval(intervalID);
227                }
228            },1000);
229        });
230    };
231
232})(jQuery);
233
234/****************
235 *
236 * Facebook SDK
237 *
238 ****************/
239
240(function ($) {
241
242    'use strict';
243
244    g1.resetFacebookSDK = function () {
245        $('script#facebook-jssdk').remove();
246        $('#fb-root').remove();
247        if (window.FB) {
248            delete window.FB;
249        }
250    };
251
252    $('body').on( 'g1BeforeNewContentReady', function ( e, $newContent ) {
253        if ($newContent.find('.fb-video').length > 0) {
254            g1.resetFacebookSDK();
255        }
256    } );
257
258})(jQuery);
259
260
261/****************
262 *
263 * Back to top
264 *
265 ****************/
266
267(function ($) {
268
269    'use strict';
270
271    g1.backToTop = function () {
272        var $scrollToTop = $('.g1-back-to-top');
273
274        // init
275        toggleVisibility($scrollToTop);
276
277        $scrollToTop.on('click', function (e) {
278            e.preventDefault();
279
280            var multipier = 200;
281            var durationRange = {
282                min: 200,
283                max: 1000
284            };
285
286            var winHeight = $(window).height();
287            var docHeight = $(document).height();
288            var proportion = Math.floor(docHeight / winHeight);
289
290            var duration = proportion * multipier;
291
292            if (duration < durationRange.min) {
293                duration = durationRange.min;
294            }
295
296            if (duration > durationRange.max) {
297                duration = durationRange.max;
298            }
299
300            $('html, body').animate({
301                scrollTop: 0
302            }, duration);
303        });
304
305        $(window).scroll(function() {
306            window.requestAnimationFrame(function () {
307                toggleVisibility($scrollToTop);
308            });
309        });
310    };
311
312    function toggleVisibility ($scrollToTop) {
313        if ($(window).scrollTop() > 240) {
314            $scrollToTop.addClass('g1-back-to-top-on').removeClass('g1-back-to-top-off');
315        } else {
316            $scrollToTop.addClass('g1-back-to-top-off').removeClass('g1-back-to-top-on');
317        }
318    }
319})(jQuery);
320
321
322/********************
323 *
324 * Load More Button
325 *
326 ********************/
327
328(function ($) {
329
330    'use strict';
331
332    // prevent triggering the action more than once at the time
333    var loading = false;
334    var startingUrl = window.location.href;
335    var setTargetBlank = g1.config.setTargetBlank;
336    var useWaypoints = g1.config.useWaypoints;
337
338    g1.loadMoreButton = function () {
339        $('.g1-load-more').on('click', function (e) {
340            if (loading) {
341                return;
342            }
343
344            loading = true;
345
346            e.preventDefault();
347
348            var $button = $(this);
349            var $collectionMore = $button.parents('.g1-collection-more');
350            var url = $button.attr('data-g1-next-page-url');
351            var $endMessage = $('.g1-pagination-end');
352
353            $collectionMore.addClass('g1-collection-more-loading');
354
355            // load page
356            var xhr = $.get(url);
357
358            // on success
359            xhr.done(function (data) {
360                var collectionSelector = '#primary > .g1-collection .g1-collection-items';
361
362                // find elements in response
363                var $resCollectionItems = $(data).find(collectionSelector).find('.g1-collection-item');
364                var $resButton = $(data).find('.g1-load-more');
365
366                // find collection on page
367                var $collection = $(collectionSelector);
368
369                // add extra classes to new loaded items
370                $resCollectionItems.addClass('g1-collection-item-ad
370ded');
371
372                // If there are insta embeds BEFORE the load, we will force to refresh them AFTER the load
373                var $insta = $('script[src="//platform.instagram.com/en_US/embeds.js"]');
374
375                // make sure that mejs is loaded
376                if (typeof window.wp.mediaelement === 'undefined') {
377                    var matches = data.match(/<script(.|\n)*?<\/script>/g);
378                    var mejsCode = '';
379                    matches.forEach(function( match ) {
380                        if ( match.indexOf('mejs') > 0 || match.indexOf('mediaelement') > 0 ){
381                            match = match.replace('<script','<script async');
382                            mejsCode+=match;
383                        }
384                    });
385                    matches = data.match(/<link(.|\n)*?\/>/g);
386                    matches.forEach(function( match ) {
387                        if ( match.indexOf('mejs') > 0 || match.indexOf('mediaelement') > 0 ){
388                            mejsCode+=match;
389                        }
390                    });
391                    $collection.after(mejsCode);
392                }
393                if (setTargetBlank) {
394                    $('a',$resCollectionItems).attr('target','_blank');
395                }
396
397                var $collection_waypoint = '<span class="bimber-collection-waypoint" data-bimber-archive-url="' + url + '"></span>';
398                $collection.append($collection_waypoint);
399                // add new elements to collection
400                $collection.append($resCollectionItems);
401
402                // Google Analytics.
403                if ( typeof ga !== 'undefined' && typeof ga.getAll !== 'undefined') {
404                    ga('create', ga.getAll()[0].get('trackingId'), 'auto');
405                    ga('set', { page: url });
406                    ga('send', 'pageview');
407                }
408
409                if ( $insta.length > 0) {
410                    window.instgrm.Embeds.process();
411                }
412
413                if (typeof window.wp.mediaelement !== 'undefined') {
414                    window.wp.mediaelement.initialize();
415                }
416
417                // load all dependent functions
418                $('body').trigger( 'g1PageHeightChanged' );
419                $('body').trigger( 'g1NewContentLoaded', [ $resCollectionItems ] );
420
421                // update more button
422                if ($resButton.length > 0) {
423                    $button.attr('data-g1-next-page-url', $resButton.attr('data-g1-next-page-url'));
424                } else {
425                    $collectionMore.remove();
426                }
427
428                //bind auto play video events
429                g1.autoPlayVideo();
430                if ( useWaypoints ){
431                    $('.bimber-collection-waypoint').waypoint(function(direction) {
432                        var $waypoint = $(this.element);
433                        if('up' === direction) {
434                            var $waypointUp = $waypoint.prevAll('.bimber-collection-waypoint');
435                            if ($waypointUp.length > 0){
436                                $waypoint = $($waypointUp[0]);
437                            } else {
438                                window.history.replaceState( {} , '', startingUrl );
439                                return;
440                            }
441                        }
442                        var waypointUrl = $waypoint.attr('data-bimber-archive-url');
443                        var currentUrl = window.location.href;
444                        if ( waypointUrl !== currentUrl ){
445                            window.history.replaceState( {} , '', waypointUrl );
446                        }
447                    }, {
448                        offset: '-5%'
449                    });
450                }
451            });
452
453            xhr.fail(function () {
454                $button.addClass('g1-info-error');
455                $button.remove();
456                $endMessage.show();
457            });
458
459            xhr.always(function () {
460                $collectionMore.removeClass('g1-collection-more-loading');
461                loading = false;
462            });
463        });
464    };
465
466})(jQuery);
467
468
469/*******************
470 *
471 * Infinite scroll
472 *
473 ******************/
474
475(function ($) {
476
477    'use strict';
478
479    g1.infiniteScrollConfig = {
480        'offset': '150%'
481    };
482
483    var triggeredByClick = false;
484
485    g1.infiniteScroll = function () {
486        $('.g1-collection-more.infinite-scroll').each(function () {
487            var $this = $(this);
488
489            if ($this.is('.on-demand') && !triggeredByClick) {
490                return false;
491            }
492
493            $this.waypoint(function(direction) {
494                if('down' === direction) {
495                    $this.find('.g1-load-more').trigger('click');
496                }
497            }, {
498                // trigger when the "Load More" container is 10% under the browser window
499                offset: g1.infiniteScrollConfig.offset
500            });
501        });
502    };
503
504    // wait for new content and apply infinite scroll events to it
505    $('body').on( 'g1NewContentLoaded', function () {
506        triggeredByClick = true;
507        g1.infiniteScroll();
508    } );
509
510})(jQuery);
511
512
513/*************
514 *
515 * GIF Player
516 *
517 *************/
518
519(function ($) {
520
521    'use strict';
522    var isEnabled   = g1.config.use_gif_player;
523
524    g1.gifPlayer = function ($scope) {
525        if ( ! isEnabled ) {
526            return;
527        }
528        if (! $scope ) {
529            $scope = $('body');
530        }
531
532        // SuperGif library depends on the overrideMimeType method of the XMLHttpRequest object
533        // if browser doesn't support this method, we can't use that library
534        if ( typeof XMLHttpRequest.prototype.overrideMimeType === 'undefined' ) {
535            return;
536        }
537
538        g1.gifPlayerIncludeSelectors =[
539            '.entry-content img.aligncenter[src$=".gif"]',
540            '.entry-content .aligncenter img[src$=".gif"]',
541            'img.g1-enable-gif-player',
542            '.entry-featured-media-main img[src$=".gif"]',
543            '.entry-tpl-stream .entry-featured-media img[src$=".gif"]',
544            '.entry-tpl-grid-l .entry-featured-media img[src$=".gif"]'
545        ];
546
547        g1.gifPlayerExcludeSelectors = [
548            '.ajax-loader',             // for Contact Form 7
549            '.g1-disable-gif-player'
550        ];
551
552        $( g1.gifPlayerIncludeSelectors.join(','), $scope ).not( g1.gifPlayerExcludeSelectors.join(',') ).each(function () {
553            var $img = $(this);
554            var imgClasses = $img.attr('class');
555            var imgSrc = $img.attr('src');
556
557            // Check only absolute paths. Relative paths, by nature, are from the same domain.
558            if (-1 !== imgSrc.indexOf('http')) {
559                // Only locally stored gifs, unless user decided otherwise.
560                if (imgSrc.indexOf(location.hostname) === -1 && !$img.is('.g1-enable-gif-player')) {
561                    return;
562                }
563            }
564
565            var gifObj = new SuperGif({
566                gif: this,
567                auto_play: 0
568            });
569
570            var $gitIndicator = $('<span class="g1-indicator-gif g1-loading">');
571
572            gifObj.load(function() {
573                var frames = gifObj.get_length();
574
575                var $canvasWrapper = $(gifObj.get_canvas()).parent();
576
577                // Only for animated gifs.
578                if (frames > 1) {
579                    var isPlaying = false;
580
581                    var playGif = function() {
582                        gifObj.play();
583                        isPlaying = true;
584                        $gitIndicator.addClass('g1-indicator-gif-playing');
585                    };
586
587                    var pauseGif = function() {
588                        gifObj.pause();
589                        isPlaying = false;
590                        $gitIndicator.removeClass('g1-indicator-gif-playing');
591                    };
592
593                    if (!g1.isTouchDevice()) {
594                        $canvasWrapper.on('click', function(e) {
595                            // Prevent redirecting to single post.
596                            e.preventDefault();
597
598                            if (isPlaying) {
599                                pauseGif();
600                            } else {
601                                playGif();
602                            }
603                        });
604                    } else {
605                        $canvasWrapper.on('hover', function() {
606                            playGif();
607                        });
608                    }
609
610                    // API.
611                    $canvasWrapper.on('bimberPlayGif', playGif);
612                    $canvasWrapper.on('bimberPauseGif', pauseGif);
613
614                    $gitIndicator.toggleClass('g1-loading g1-loaded');
615
616                    $(document).trigger('bimberGifPlayerLoaded', [$canvasWrapper]);
617                } else {
618                    // It's just a gif type image, not animation to play.
619                    $gitIndicator.remove();
620                }
621            });
622
623            // canvas parent can be fetched after gifObj.load() call
624            var $canvasWrapper = $(gifObj.get_canvas()).parent();
625
626            $canvasWrapper.
627                addClass(imgClasses + ' g1-enable-share-links').
628                attr('data-img-src', imgSrc).
629                append($gitIndicator);
630        });
631    };
632
633})(jQuery);
634
635
636/*************
637 *
638 * MP4 Player
639 *
640 *************/
641
642(function ($) {
643
644    'use strict';
645
646    g1.mp4Player = function () {
647        // We depend on mediaelement.js
648        if ( typeof mejs === 'undefined' ) {
649            return;
650        }
651
652        g1.mp4PlayerIncludeSelectors =[
653            '.entry-content .mace-video',
654            '.entry-featured-media .mace-video',
655            '.g1-enable-mp4-player'
656        ];
657
658        g1.mp4PlayerExcludeSelectors = [
659            '.g1-disable-mp4-player'
660        ];
661
662        $( g1.mp4PlayerIncludeSelectors.join(',') ).not( g1.mp4PlayerExcludeSelectors.join(',') ).each(function () {
663            var $video = $(this);
664            var $mejsContainer = $video.parents('.mejs-container');
665            var playerId;
666            var player;
667
668            // Hide controls.
669            $mejsContainer.find('.mejs-controls').remove();
670
671            // Set up player.
672            $video.attr('loop', 'true');
673
674            $mejsContainer.hover(
675                // In.
676                function() {
677                    // Get player on first access.
678                    if (!player) {
679                        playerId = $mejsContainer.attr('id');
680                        player   = mejs.players[playerId];
681                    }
682
683                    // Player loaded?
684                    if (player) {
685                        player.play();
686                    }
687                },
688                // Out.
689                function() {}
690            );
691        });
692    };
693
694})(jQuery);
695
696/*******************
697 *
698 * Featured Entries
699 *
700 ******************/
701
702(function ($) {
703
704    'use strict';
705
706    var selectors = {
707        'wrapper':  '.g1-featured',
708        'items':    '.g1-featured-items',
709        'item':     '.g1-featured-item',
710        'prevLink': '.g1-featured-arrow-prev',
711        'nextLink': '.g1-featured-arrow-next'
712    };
713
714    var classes = {
715        'startPos': 'g1-featured-viewport-start',
716        'endPos':   'g1-featured-viewport-end',
717        'noArrows':  'g1-featured-viewport-no-overflow'
718    };
719
720    var isRTL;
721    var $wrapper;   // main wrapper
722    var $items;     // items wrapper, is scrollable
723    var $prevLink;  // move collection left
724    var $nextLink;  // move collection right
725
726    // public
727    g1.featuredEntries = function () {
728        isRTL = g1.isRTL();
729
730        $(selectors.wrapper).each(function () {
731            $wrapper = $(this);
732            $items = $wrapper.find(selectors.items);
733            $prevLink = $wrapper.find(selectors.prevLink);
734            $nextLink = $wrapper.find(selectors.nextLink);
735
736            var singleItemWidth = $items.find(selectors.item + ':first').width();
737            var moveOffset = 2 * singleItemWidth;
738            var direction = isRTL ? -1 : 1;
739
740            $prevLink.on('click', function (e) {
741                e.preventDefault();
742
743                scrollHorizontally(-direction * moveOffset);
744            });
745
746            $nextLink.on('click', function (e) {
747                e.preventDefault();
748
749                scrollHorizontally(direction * moveOffset);
750            });
751
752            $items.on('scroll', function () {
753                window.requestAnimationFrame(function () {
754                    updateScrollState();
755                });
756            });
757
758            $wrapper.removeClass('g1-featured-no-js').addClass('g1-featured-js');
759
760            updateScrollState();
761        });
762    };
763
764    // private
765    function updateScrollState () {
766        var width = $items.get(0).scrollWidth;
767        var overflowedWidth = $items.width();
768        var scrollLeft = $items.scrollLeft();
769
770        $wrapper.removeClass(classes.endPos + ' ' + classes.startPos);
771        // we add 20px "error margin", so we don't have scroll when the last element's overflow only a tiny bit.
772        // 20px is equal to the padding of the title, so the text is always in viewport.
773        if ( $items[0].offsetWidth + 20 >= $items[0].scrollWidth ){
774            $wrapper.addClass(classes.noArrows);
775            return;
776        }
777
778        // no scroll LTR, most left RTL
779        if (scrollLeft <= 0) {
780            if (isRTL) {
781                $wrapper.addClass(classes.endPos);
782                $wrapper.removeClass(classes.startPos);
783            } else {
784                $wrapper.addClass(classes.startPos);
785                $wrapper.removeClass(classes.endPos);
786            }
787        // most right LTR, no scroll RTL
788        } else if (width <= scrollLeft + overflowedWidth) {
789            if (isRTL) {
790                $wrapper.addClass(classes.startPos);
791                $wrapper.removeClass(classes.endPos);
792            } else {
793                $wrapper.addClass(classe
793s.endPos);
794                $wrapper.removeClass(classes.startPos);
795            }
796        }
797    }
798
799    function scrollHorizontally(difference) {
800        var leftOffset = $items.scrollLeft();
801
802        $items.animate(
803            // properties to animate
804            {
805                'scrollLeft': leftOffset + difference
806            },
807            375,        // duration
808            'swing'     // easing
809        );
810    }
811
812})(jQuery);
813
814
815/*******************
816 *
817 * Date > Time ago
818 *
819 ******************/
820
821(function ($) {
822
823    'use strict';
824
825    g1.dateToTimeago = function () {
826        if (!$.fn.timeago) {
827            return;
828        }
829
830        $('time.entry-date, .comment-metadata time, time.snax-item-date').timeago();
831
832        $('body').on( 'g1NewContentLoaded', function ( e, $newContent ) {
833            if ($newContent) {
834                $newContent.find('time.entry-date, .comment-metadata time, time.snax-item-date').timeago();
835            }
836        } );
837    };
838
839})(jQuery);
840
841
842/**********
843 *
844 * Canvas
845 *
846 *********/
847
848(function($) {
849    'use strict';
850
851    var selectors = {
852        'toggle':   '.g1-hamburger'
853    };
854
855    g1.globalCanvasSelectors = selectors;
856
857    var canvas;
858
859    g1.canvas = function() {
860        canvas = Canvas();
861
862        // Allow global access.
863        g1.canvasInstance = canvas;
864
865        $(selectors.toggle).on('click', function (e) {
866            e.preventDefault();
867
868            //$('html, body').animate({ // @maybe
869            //    scrollTop: 0 // @maybe
870            //}, 10); // @maybe
871
872            canvas.toggle();
873        });
874    };
875
876    function Canvas () {
877        var that = {};
878        var listeners = {
879            'open': [],
880            'close': []
881        };
882
883        var currentContent = '';
884
885        var currentScroll = 0; // @maybe
886
887        var _clientY;
888
889        var init = function () {
890            var $overlay = $( '.g1-canvas-overlay');
891
892            // toogle canvas events
893            $overlay.on('click', that.toggle);
894
895            $('.g1-canvas').on('toggle-canvas', function () {
896                that.toggle();
897            });
898
899            $('.g1-canvas .g1-canvas-toggle').on('click', that.toggle);
900
901
902            if ( $('html.g1-off-outside').length ) {
903                enquire.register('screen and ( min-width: 700px )', {
904                    match : function() {
905                        that.close();
906                    }
907                });
908            }
909
910            if ( $('html.g1-off-inside').length ) {
911                enquire.register('screen and ( max-width: 1024px )', {
912                    match : function() {
913                        that.close();
914                    }
915                });
916            }
917
918            return that;
919        };
920
921        that.getContent = function() {
922            return $('.g1-canvas-global .g1-canvas-content');
923        };
924
925        that.captureClientY = function (event) {
926            // only respond to a single touch
927            //if (event.targetTouches.length === 1) {
928                _clientY = event.targetTouches[0].clientY;
929            //}
930        };
931
932        that.disableCanvasScroll = function( e ) {
933            // only respond to a single touch
934            //if (e.targetTouches.length !== 1) {
935            //   return;
936            //}
937
938            var _element = $('.g1-canvas');
939
940            var clientY = e.targetTouches[0].clientY - _clientY;
941
942            // The element at the top of its scroll,
943            // and the user scrolls down
944            if (_element.scrollTop === 0 && clientY > 0) {
945
946                alert('top scroll');
947
948                e.preventDefault();
949                e.stopPropagation();
950                return false;
951            }
952
953            // The element at the bottom of its scroll,
954            // and the user scrolls up
955            // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions
956            if ((_element.scrollHeight - _element.scrollTop <= _element.clientHeight) && clientY < 0) {
957                alert('bottom scroll');
958
959                e.preventDefault();
960                e.stopPropagation();
961                return false;
962            }
963        };
964
965        that.disableBodyScroll = function( e ) {
966            //e.preventDefault();
967            //e.stopPropagation();
968            //return false;
969        };
970
971        that.open = function (content) {
972            //$('.g1-canvas').on('touchstart', that.captureClientY);
973            //$('.g1-canvas').on('touchmove', that.disableCanvasScroll);
974
975            window.requestAnimationFrame(function () {
976                var breakpoint = $(document).width();
977                var cssClass = breakpoint >= 1025 ? 'g1-off-global-desktop' : 'g1-off-global';
978                $('html').addClass(cssClass);
979
980                currentContent = content;
981                var $canvas = $('.g1-canvas-global');
982
983                if (content) {
984                    if (typeof content === 'string') {
985                        $canvas.find('.g1-canvas-content').html(content);
986                    } else {
987                        $canvas.find('.g1-canvas-content').empty().append(content);
988                    }
989
990                    // notify about adding new content to DOM so other elements can be reloaded
991                    $canvas.find('.g1-canvas-content').trigger('g1-new-content');
992                }
993
994                that.notify('open');
995            });
996        };
997
998        that.close = function () {
999            //$('.g1-canvas').off('touchmove', that.disableCanvasScroll);
1000            //$('.g1-canvas').off('touchstart', that.captureClientY);
1001
1002            window.requestAnimationFrame(function () {
1003                $('html').removeClass('g1-off-global g1-off-global-desktop');
1004
1005                that.notify('close');
1006            });
1007        };
1008
1009        that.toggle = function (e) {
1010            if (e) {
1011                e.preventDefault();
1012            }
1013
1014            // is opened?
1015            if ( $('html').is('.g1-off-global, .g1-off-global-desktop') ) {
1016                that.close();
1017            } else {
1018                that.open(null);
1019            }
1020        };
1021
1022        that.notify = function (eventType) {
1023            var callbacks = listeners[eventType];
1024
1025            for (var i = 0; i < callbacks.length; i++) {
1026                callbacks[i](that.getContent());
1027            }
1028        };
1029
1030        that.on = function (eventType, listener, priority) {
1031            listeners[eventType][priority] = listener;
1032        };
1033
1034        return init();
1035    }
1036
1037})(jQuery);
1038
1039
1040/********************
1041 *
1042 * Sticky sidebar
1043 *
1044 ********************/
1045
1046(function($) {
1047    'use strict';
1048
1049    var $waypointElem = false;
1050
1051    var selectors = {
1052        'stickyWidgetWrapper': '.g1-sticky-widget-wrapper',
1053        'stickyWidget':        '.g1-sticky-widget',
1054        'widget':              '.widget',
1055        'content':             '#primary .entry-content'
1056    };
1057
1058    var sidebarSelectors = [
1059        '#secondary',
1060        '#tertiary'
1061    ];
1062
1063    g1.stickyTopOffsetSelectors = [
1064        '#wpadminbar',
1065        '.g1-iframe-bar',
1066        '.g1-sharebar-loaded',
1067        '.g1-sticky-top-wrapper'
1068    ];
1069
1070    g1.resetStickyElements = function() {
1071        $(selectors.stickyWidgetWrapper).css('height', '');
1072        $(selectors.stickyWidget).css('position', 'block');
1073    };
1074
1075    g1.stickySidebar = function() {
1076        if (!g1.isDesktopDevice()) {
1077            g1.resetStickyElements();
1078            return;
1079        }
1080
1081        var $widgets = $(selectors.stickyWidget);
1082
1083        if ($widgets.length === 0) {
1084            return;
1085        }
1086
1087        // Calc top offset for sticky elements.
1088        var topOffset = 0;
1089
1090        $(g1.stickyTopOffsetSelectors).each(function() {
1091            var $element = $(this);
1092
1093            if ($element.length > 0 && $element.is(':visible')) {
1094                topOffset += parseInt($element.outerHeight(), 10);
1095            }
1096        });
1097
1098        // Adjust widgets top offset to keep them always fully visible.
1099        $widgets.each(function() {
1100            var $widget = $(this);
1101            var top = parseInt($widget.css('top'), 10);
1102
1103            if (topOffset > 0) {
1104                top += topOffset;
1105
1106                $widget.css('top', top + 'px');
1107            }
1108        });
1109
1110        // Apply "position: sticky" pollyfill (IE9+).
1111        if (typeof Stickyfill !== 'undefined') {
1112            Stickyfill.add($widgets);
1113        }
1114
1115        /**
1116         * Increase the last widget height to cover entire sidebar.
1117         *
1118         * @param {Boolean} isVariableContent  - Determines which element is used for widget height calculation.
1119         */
1120        var adjustLastWidgetHeight = function(isVariableContent) {
1121            $(sidebarSelectors).each(function() {
1122                var $sidebar = $(this);
1123                var $widgets = $sidebar.children(selectors.widget + ',' + selectors.stickyWidgetWrapper);
1124                var $lastWidget = $widgets.last();
1125
1126                if ($lastWidget.is(selectors.stickyWidgetWrapper)) {
1127                    // Reset height (if previously set) to calculate it from scratch.
1128                    $lastWidget.css('height', '');
1129
1130                    var sidebarHeight;
1131
1132                    // Lazy loaded dynamic content elements (like embeds) affects its height.
1133                    // At this point, we don't know what will be the final height.
1134                    // So when we calculate the first time the last widget height, we do this based on current content height,
1135                    // and then when we reach the end of the content, we recalculate (assuming that all elements
1136                    // have already thier final size) the widget height based on current sidebar height (flexbox gives us a certainty
1137                    // that both #primary and #secondary/#tetriary elements have the same height).
1138                    if (isVariableContent) {
1139                        sidebarHeight = parseInt($(selectors.content).outerHeight(), 10);
1140                    } else {
1141                        sidebarHeight = parseInt($sidebar.outerHeight(), 10);
1142                    }
1143
1144                    var widgetsHeight = 0;
1145
1146                    $widgets.each(function() {
1147                        widgetsHeight += parseInt($(this).outerHeight(true), 10);
1148                    });
1149
1150                    // Increase last widget height if exists a space to cover.
1151                    if (widgetsHeight < sidebarHeight) {
1152                        var diffHeight = sidebarHeight - widgetsHeight;
1153
1154                        var lastWidgetHeight = parseInt($lastWidget.css('height'), 10);
1155
1156                        lastWidgetHeight += diffHeight;
1157
1158                        $lastWidget.css('height', lastWidgetHeight + 'px');
1159                    }
1160
1161                    $waypointElem = $lastWidget;
1162                }
1163            });
1164        };
1165
1166        var $body = $('body');
1167
1168        // For a single post, use entry content height to calculate the last widget height at first.
1169        var isVariableContent = $body.is('.single');
1170
1171        adjustLastWidgetHeight(isVariableContent);
1172
1173        // Listen to page height changes.
1174        // ------------------------------
1175
1176        // New content is added (e.g. via auto-load next post) or dynamic element is fully loaded (e.g. Facebook widget).
1177        $body.on( 'g1NewContentLoaded g1PageHeightChanged', function(e) {
1178            adjustLastWidgetHeight();
1179        } );
1180
1181        // Entry content is entirely in the viewport (all inside elements should have final size), adjust widget height.
1182        if (false !== $waypointElem) {
1183            $waypointElem.waypoint(function(direction) {
1184                if ('down' === direction) {
1185                    adjustLastWidgetHeight();
1186                }
1187            }, {
1188                // When the bottom of the element hits the bottom of the viewport.
1189                offset: 'bottom-in-view'
1190            });
1191        }
1192    };
1193
1194})(jQuery);
1195
1196
1197/**************************
1198 *
1199 * Share Content Elements
1200 * (images, video)
1201 *
1202 **************************/
1203
1204(function ($) {
1205
1206        'use strict';
1207
1208        var template = $.parseJSON(bimber_front_microshare)['html'];
1209        var config = $.parseJSON(bimber_front_config);
1210        var fb_api_id_number = 0;
1211
1212        g1.shareContentElements = function ($scope, customTemplate) {
1213            if (config.microshare !== 'on') {
1214                return;
1215            }
1216            if (! $scope) {
1217                $scope = $('#content');
1218            }
1219
1220            g1.microShareIncludeSelectors =[
1221                '.entry-featured-media-main img.wp-post-image',
1222                '.entry-content img.aligncenter',
1223                '.entry-content .aligncenter img',
1224                '.entry-content .alignwide img',
1225                '.entry-content .alignfull img',
1226                '.entry-content .g1-enable-share-links'
1227            ];
1228
1229            g1.microShareExcludeSelectors = [
1230                '.entry-content img.g1-disable-share-links',
1231                '.entry-content .snax-item-box',
1232                '.entry-content .wp-video'
1233            ];
1234
1235            $( g1.microShareIncludeSelectors.join(',') ).not( g1.microShareExcludeSelectors.join(',') ).each(function () {
1236                var $elem = $(this);
1237                var src = '';
1238
1239                if ( $elem.parents('.mashsb-micro-wrapper').length > 0 ) {
1240                    return;
1241                }
1242                var $img = $('img', $elem);
1243                if ($img.length > 0){
1244                    src = $img.attr('data-src');
1245                    if (!src) {
1246                        src = $img.attr('src');
1247                    }
1248                } else {
1249                    src = $elem.attr('data-src');
1250                    if (!src) {
1251                        src = $elem.attr('src');
1252                    }
1253                }
1254                if (typeof src !== 'string') {
1255                    src = '';
1256                }
1257                if (!src.match(new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/))){
1258                    var base = $('base').attr('href');
1259                    if(base){
1260                        src = base.replace(/\/$/, '') + src.replace('./','/');
1261                    }else{
1262                        src = '';
1263                    }
1264                }
1265                var microshare = template;
1266                if (customTemplate){
1267                    microshare = customTemplate;
1268                }
1269
1270                var fb_function_id = 'bimber_microshare_' + fb_api_id_number;
1271                fb_api_id_number+=1;
1272                microshare = microshare.replace(new RegExp(/_bimber_replace_unique_241gw/g),fb_function_id);
1273                microshare = microshare.replace('bimber_replace_encode_241gw',encodeURIComponent(src));
1274                microshare = microshare.replace('bimber_replace_241gw',src);
1275
1276
1277                // @todo-pp: replace the "g1-img-wrap" class with something more general, we don't wrap just images here
1278                $elem.wrap( '<div class="g1-img-wrap"></div>' );
1279                $elem.parent().addClass( 'mashsb-micro-wrapper' );
1280                $elem.parent().append(microshare);
1281                $elem.find('.snax-item-share').empty();
1282            });
1283
1284            //add embedly script if needed
1285            if ( $('.bimber-snax-embedly-script-placeholder').length > 0){
1286                $('.bimber-snax-embedly-script-placeholder').replaceWith('<script async src="//cdn.embedly.com/widgets/platform.js" charset="UTF-8"></script>');
1287            }
1288
1289            $('.bimber-microshare-twitter').on('click', function (e) {
1290                e.preventDefault();
1291                window.open($(this).attr('href'), 'Google', 'width=500,height=300');
1292            });
1293            $('.bimber-microshare-pinterest').on('click', function (e) {
1294                e.preventDefault();
1295                window.open($(this).attr('href'), 'Google', 'width=700,height=670');
1296            });
1297
1298            // On none touchable devices, shares visibility is handled via css :hover.
1299            // On touch devices there is no "hover", so we emulate hover via CSS class toggle on click.
1300            $('.bimber-microshare-item-share-toggle').on('click touchstart', function (e) {
1301                e.preventDefault();
1302                $(this).parents('.bimber-microshare-item-share').addClass('bimber-microshare-item-share-expanded');
1303            });
1304
1305            // Hide shares on focus out.
1306            $('body').on('click touchstart', function (e) {
1307                var $activeMicroShares = $(e.target).parents('.bimber-microshare-item-share-expanded');
1308
1309                // Collapse all expanded micro shares except active one.
1310                $('.bimber-microshare-item-share-expanded').not($activeMicroShares).removeClass( 'bimber-microshare-item-share-expanded' );
1311            });
1312
1313        };
1314
1315    })(jQuery);
1316
1317
1318/*************************
1319 *
1320 * Custom Share Buttons
1321 * (open in a new window)
1322 *
1323 *************************/
1324
1325(function ($) {
1326
1327    'use strict';
1328
1329    g1.customShareButtons = function () {
1330        openCustomSharesInNewWindow();
1331    };
1332
1333    function openCustomSharesInNewWindow () {
1334        $('.mashicon-pinterest, .mashicon-google').click( function(e) {
1335            var winWidth = 750;
1336            var winHeight = 550;
1337            var winTop = (screen.height / 2) - (winHeight / 2);
1338            var winLeft = (screen.width / 2) - (winWidth / 2);
1339            var url = $(this).attr('href');
1340
1341            // Since Mashshare v3.2.8.
1342            if ('#' === url) {
1343                url = $(this).attr('data-mashsb-url');
1344            }
1345
1346            window.open(
1347                url,
1348                'sharer',
1349                'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight
1350            );
1351
1352            e.preventDefault();
1353        });
1354    }
1355
1356    $('body').on('g1NewContentLoaded', function(){
1357        if (typeof lashare_fb == "undefined" && typeof mashsb !== 'undefined') {
1358            $('.mashicon-facebook').click(function (mashfb) {
1359                var winWidth = 520;
1360                var winHeight = 550;
1361                var winTop = (screen.height / 2) - (winHeight / 2);
1362                var winLeft = (screen.width / 2) - (winWidth / 2);
1363                var url = $(this).attr('href');
1364                window.open(url, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
1365                mashfb.preventDefault(mashfb);
1366                return false;
1367            });
1368        }
1369        if (typeof mashsb !== 'undefined') {
1370            $('.mashicon-twitter').click(function (e) {
1371                var winWidth = 520;
1372                var winHeight = 350;
1373                var winTop = (screen.height / 2) - (winHeight / 2);
1374                var winLeft = (screen.width / 2) - (winWidth / 2);
1375                var url = $(this).attr('href');
1376                // deprecated and removed because TW popup opens twice
1377                if (mashsb.twitter_popup === '1') {
1378                    window.open(url, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
1379                }
1380                e.preventDefault();
1381                return false;
1382            });
1383        }
1384    });
1385
1386
1387})(jQuery);
1388
1389
1390/***************************
1391 *
1392 * Customize Share Buttons
1393 * (open in a new window)
1394 *
1395 ***************************/
1396
1397(function ($) {
1398
1399    'use strict';
1400
1401    g1.customizeShareButtons = function () {
1402        overrideOnOffSwitch();
1403        subscribeViaMailbox();
1404    };
1405
1406    function overrideOnOffSwitch () {
1407        // disable current events
1408        var $onoffswitch    = $('.onoffswitch');
1409        var $onoffswitch2   = $('.onoffswitch2');
1410
1411        $onoffswitch.off('click');
1412        $onoffswitch2.off('click');
1413
1414        $onoffswitch.on('click', function() {
1415            var $container = $(this).parents('.mashsb-container');
1416
1417            $('.onoffswitch', $container).hide();
1418            $('.secondary-shares', $container).show();
1419            $('.onoffswitch2', $container).show();
1420        });
1421
1422        $onoffswitch2.on('click', function() {
1423            var $container = $(this).parents('.mashsb-container');
1424
1425            $('.onoffswitch', $container).show();
1426            $('.secondary-shares', $container).hide();
1427        });
1428    }
1429
1430    function subscribeViaMailbox () {
1431        // Skip if subscription is done via content box.
1432        if (typeof mashsb !== 'undefined' && mashsb.subscribe === 'content') {
1433            return;
1434        }
1435
1436        // Skip if subsciption is done via custom url.
1437        if (typeof mashsb !== 'undefined' && mashsb.subscribe_url !== '') {
1438            return;
1439        }
1440
1441        // Open default mail client to subscribe.
1442        $('a.mashicon-subscribe').each(function () {
1443            var $link = $(this);
1444
1445            if ($link.attr('href') === '#') {
1446                // remove all assigned events
1447                $link.off('click');
1448
1449                var postTitle = $('head > title').text();
1450                var postUrl = location.href;
1451
1452                var subject = g1.config.i18n.newsletter.subscribe_mail_subject_tpl.replace('%subject%', postTitle);
1453                var body = postTitle + '%0A%0A' + postUrl;
1454
1455                // template
1456                var mailTo = 'mailto:?subject={subject}&body={body}';
1457
1458                // build final link
1459                mailTo = mailTo.replace('{subject}', subject);
1460                mailTo = mailTo.replace('{body}', body);
1461
1462                $link.attr('href', mailTo);
1463            }
1464        });
1465    }
1466
1467})(jQuery);
1468
1469
1470/*************
1471 *
1472 * Share Bar
1473 *
1474 *************/
1475
1476(function ($) {
1477
1478    'use strict';
1479
1480    g1.shareBarTopOffsetSelectors = [
1481        '#wpadminbar'
1482    ];
1483
1484    g1.shareBar = function () {
1485        var $shareBar = g1.activateShareBar();
1486
1487        $('body').on('g1PageHeightChanged', function () {
1488            if ($shareBar !== false) {
1489                g1.updateShareBarPosition($shareBar);
1490            }
1491        });
1492
1493        enquire.register('screen and ( min-width: 801px )', {
1494            match : function() {
1495                if ($shareBar !== false) {
1496                    g1.updateShareBarPosition($shareBar);
1497                }
1498            },
1499            unmatch: function() {
1500                if ($shareBar !== false) {
1501                    g1.updateShareBarPosition($shareBar);
1502                }
1503            }
1504        });
1505    };
1506
1507    g1.activateShareBar = function () {
1508        var $shareBar = $('.g1-sharebar');
1509        var $shareButtons = $('.mashsb-main:first');
1510
1511        // exit if any of required elements not exists
1512        if ($shareBar.length === 0 || $shareButtons.length === 0) {
1513            return false;
1514        }
1515
1516        var $shareBarInner = $shareBar.find('.g1-sharebar-inner');
1517
1518        if (!$shareBar.is('.g1-sharebar-loaded')) {
1519            var $clonedShareButtons = $shareButtons.clone(true);
1520            //$clonedShareButtons.removeClass('mashsb-main');
1521
1522            // If shares are animated, we need to set total count in sharebar before animation ends
1523            if (typeof mashsb !== 'undefined' && mashsb.animate_shares === '1' && $clonedShareButtons.find('.mashsbcount').length) {
1524                $clonedShareButtons.find('.mashsbcount').text(mashsb.shares);
1525            }
1526
1527            $shareBarInner.append($clonedShareButtons);
1528
1529            $shareBar.addClass('g1-sharebar-loaded');
1530
1531            g1.updateShareBarPosition($shareBar);
1532        }
1533
1534        new Waypoint({
1535            element: $('body'),
1536            handler: function (direction) {
1537                if (direction === 'down') {
1538                    $shareBar.addClass('g1-sharebar-on');
1539                    $shareBar.removeClass('g1-sharebar-off');
1540                } else {
1541                    $shareBar.removeClass('g1-sharebar-on');
1542                    $shareBar.addClass('g1-sharebar-off');
1543                }
1544            },
1545            offset: function() {
1546                // trigger waypoint when body is scrolled down by 100px
1547                return -100;
1548            }
1549        });
1550
1551        return $shareBar;
1552    };
1553
1554    g1.updateShareBarPosition = function ($shareBar) {
1555        var shareBarWidth = parseInt($shareBar.outerWidth(), 10);
1556        var cssMediaQueryBreakpoint = 800;
1557
1558        // Below breakpoint value, sticky is placed on bottom so top has to be reset.
1559        if (shareBarWidth <= cssMediaQueryBreakpoint) {
1560            $shareBar.css('top', '');
1561        } else {
1562            var top = 0;
1563
1564            for (var i = 0; i < g1.shareBarTopOffsetSelectors.length; i++) {
1565                var $element = $(g1.shareBarTopOffsetSelectors[i]);
1566
1567                if ($element.length > 0 && $element.is(':visible')) {
1568                    top += parseInt($element.outerHeight(), 10);
1569                }
1570            }
1571
1572            $shareBar.css('top', top + 'px');
1573        }
1574    };
1575
1576})(jQuery);
1577
1578
1579/*****************
1580 *
1581 * Sticky Elements
1582 *
1583 ****************/
1584
1585(function ($) {
1586
1587    'use strict';
1588
1589    var selectors = [
1590        '#wpadminbar',
1591        '.g1-iframe-bar',
1592        '.g1-sharebar-loaded',
1593        '.g1-sticky-top-wrapper'
1594    ];
1595
1596    // Accessible globally.
1597    g1.stickyElementsTopOffsetSelectors = selectors;
1598
1599    g1.stickyPosition = function ($context) {
1600        $context = $context || $('body');
1601
1602        // Sticky top.
1603        var $stickyTop = $('.g1-sticky-top-wrapper');
1604
1605        // If exists and not loaded already.
1606        if ($stickyTop.length > 0 && !$stickyTop.is('.g1-loaded')) {
1607            var disableStickyHeader = false;
1608            var isDesktop = g1.getWindowWidth() > 800;
1609
1610
1611
1612            // Disable if sharebar enabled.
1613            var sharebarLoaded = $('.g1-sharebar-loaded').length > 0;
1614
1615            if (sharebarLoaded && isDesktop) {
1616                disableStickyHeader = true;
1617            }
1618
1619            if (disableStickyHeader) {
1620                // Prevent native sticky support, like on FF.
1621                $stickyTop.removeClass('g1-sticky-top-wrapper');
1622            } else {
1623                // Apply pollyfill only if not supported.
1624                if (!g1.isStickySupported()) {
1625                    Stickyfill.add($stickyTop);
1626                }
1627
1628                $stickyTop.addClass('g1-loaded');
1629            }
1630        }
1631
1632        // Calculate topOffset after disabling the sticky header!
1633        var topOffset = 0;
1634        for (var i = 0; i < selectors.length; i++) {
1635            var $elem = $(selectors[i]);
1636
1637            if ($elem.length > 0 && $elem.is(':visible')) {
1638                topOffset += $elem.outerHeight();
1639            }
1640        }
1641
1642
1643        // Sticky Item Actions (shares, votes etc).
1644        $context.find('.g1-wrapper-with-stickies > .entry-actions').each(function() {
1645            var $this = $(this);
1646
1647            $this.css('top', topOffset);
1648
1649            Stickyfill.add($this);
1650        });
1651
1652        // Sticky snax form sidebar.
1653        Stickyfill.add($('.snax-form-frontend .snax-form-side'));
1654
1655
1656        // Sticky Item Actions (shares, votes etc).
1657        $context.find('.entry-tpl-index-stickies > .entry-actions, .entry-tpl-feat-stickies .entry-actions').each(function() {
1658            var $this = $(this);
1659
1660            $this.css('top', topOffset + 10);
1661
1662            Stickyfill.add($this);
1663        });
1664    };
1665
1666    $('body').on( 'g1NewContentLoaded', function ( e, $newContent ) {
1667        if ($newContent) {
1668            g1.stickyPosition($newContent);
1669        }
1670    } );
1671
1672})(jQuery);
1673
1674
1675/**********************
1676 *
1677 * Droppable Elements
1678 *
1679 **********************/
1680
1681(function ($) {
1682
1683    'use strict';
1684
1685    var selectors = {
1686        'drop' :        '.g1-drop',
1687        'dropExpanded': '.g1-drop-expanded',
1688        'dropToggle':   '.g1-drop-toggle'
1689    };
1690
1691    var classes = {
1692        'dropExpanded': 'g1-drop-expanded'
1693    };
1694
1695    g1.droppableElements = function () {
1696        // Hide drop on focus out.
1697        $('body').on('click touchstart', function (e) {
1698            var $activeDrop = $(e.target).parents('.g1-drop-expanded');
1699
1700            // Collapse all except active.
1701            $(selectors.dropExpanded).not($activeDrop).removeClass(classes.dropExpanded);
1702        });
1703
1704        // Handle drop state (expanded | collapsed).
1705
1706        // For touch devices we need to toggle CSS class to trigger state change.
1707        if ( g1.isTouchDevice() ) {
1708            $(selectors.drop).on( 'click', function(e) {
1709                var $drop = $(this);
1710
1711                // Drop is expanded, collapse it on toggle click.
1712                if ($drop.is(selectors.dropExpanded)) {
1713                    var $clickedElement = $(e.target);
1714
1715                    var toggleClicked = $clickedElement.parents(selectors.dropToggle).length > 0;
1716
1717                    if (toggleClicked) {
1718                        $drop.removeClass(classes.dropExpanded);
1719                        e.preventDefault();
1720                    }
1721                // Drop is collapsed, expand it.
1722                } else {
1723                    $drop.addClass(classes.dropExpanded);
1724                    e.preventDefault();
1725                }
1726            } );
1727        // Devices without touch events, state is handled via CSS :hover
1728        } else {
1729            // Prevent click on toggle.
1730            $(selectors.dropToggle).on( 'click', function() {
1731            });
1732        }
1733    };
1734
1735})(jQuery);
1736
1737
1738/*************************
1739 *
1740 * BuddyPress Profile Nav
1741 *
1742 *************************/
1743
1744(function ($, i18n) {
1745
1746    'use strict';
1747
1748    var selectors = {
1749        'items':        '> li:not(.g1-drop):not(.g1-delimiter):not(.g1-tab-item-current)'
1750    };
1751
1752    var classes = {
1753        'hidden':       'hidden'
1754    };
1755
1756    var isRTL = g1.isRTL();
1757
1758    g1.bpProfileNav = function () {
1759        // Define reverse function as jQuery plugin.
1760        $.fn.g1Reverse = [].reverse;
1761
1762        $('#menu-bp.g1-tab-items').each(function() {
1763            var $ul             = $(this);
1764            var $liMore         = $('<li class="g1-drop g1-drop-before g1-tab-item">');
1765            var $liMoreToggle   = $('<a class="g1-drop-toggle g1-tab" href="#">' + i18n.more_link + '<span class="g1-drop-toggle-arrow"></span></a>');
1766            var $liMoreContent  = $('<div class="g1-drop-content"></div>' );
1767            var $liMoreSubmenu  = $('<ul class="sub-menu"></ul>');
1768            var $liDelimiter    = $('<li class="g1-delimiter">');
1769
1770            var maxWidth        = $ul.width() - 40;
1771            if ($ul.prop('scrollWidth') <= $ul.width() ) {
1772                return;
1773            }
1774
1775            $liMore.
1776                append($liMoreToggle);
1777            $ul.
1778                append($liMore).
1779                append($liDelimiter);
1780
1781            $ul.find(selectors.items).g1Reverse().each(function(index) {
1782                var $this = $(this);
1783
1784                if ( isRTL) {
1785                    if ( $liMore.position().left < 0) {
1786                        // Adjust HTML markup.
1787                        $this.removeClass('g1-tab-item').addClass('menu-item');
1788                        $this.find('> a').removeClass('g1-tab');
1789
1790                        $liMoreSubmenu.prepend( $this);
1791                    } else if (0 === index) {
1792                        $liMore.toggleClass(classes.hidden);
1793                        $liDelimiter.toggleClass(classes.hidden);
1794
1795                        return false;
1796                    } else {
1797                        if ( $liDelimiter.position().left < 0 ) {
1798                            // Adjust HTML markup.
1799                            $this.removeClass('g1-tab-item').addClass('menu-item');
1800                            $this.find('> a').removeClass('g1-tab');
1801
1802                            $liMoreSubmenu.prepend( $this);
1803                        }
1804                    }
1805                } else {
1806                    if ( $liMore.position().left > maxWidth) {
1807                        // Adjust HTML markup.
1808                        $this.removeClass('g1-tab-item').addClass('menu-item');
1809                        $this.find('> a').removeClass('g1-tab');
1810
1811                        $liMoreSubmenu.prepend( $this);
1812                    } else if (0 === index) {
1813                        $liMore.toggleClass(classes.hidden);
1814                        $liDelimiter.toggleClass(classes.hidden);
1815
1816                        return false;
1817                    } else {
1818                        if ( $liDelimiter.position().left > maxWidth ) {
1819                            // Adjust HTML markup.
1820                            $this.removeClass('g1-tab-item').addClass('menu-item');
1821                            $this.find('> a').removeClass('g1-tab');
1822
1823                            $liMoreSubmenu.prepend( $this);
1824                        }
1825                    }
1826                }
1827            });
1828
1829            $liMoreContent.append($liMoreSubmenu);
1830            $liMore.append($liMoreContent);
1831            $liDelimiter.toggleClass(classes.hidden);
1832        });
1833    };
1834
1835})(jQuery, g1.config.i18n.bp_profile_nav);
1836
1837
1838/********************************
1839 *
1840 * BuddyPress input placeholders
1841 *
1842 ********************************/
1843
1844(function ($) {
1845
1846    'use strict';
1847
1848    $( 'input#bp-login-widget-user-login' ).attr( 'placeholder', $( 'label[for="bp-login-widget-user-login"]' ).text() );
1849    $( 'input#bp-login-widget-user-pass' ).attr( 'placeholder', $( 'label[for="bp-login-widget-user-pass"]' ).text() );
1850
1851})(jQuery);
1852
1853/********************************
1854 *
1855 * BuddyPress Follow Button
1856 *
1857 ********************************/
1858
1859(function ($) {
1860
1861    'use strict';
1862
1863    var follow = function( scope ) {
1864        var $link   = scope;
1865        var uid    = $link.attr('id');
1866        var nonce  = $link.attr('href');
1867        var action = '';
1868
1869        uid    = uid.split('-');
1870        action = uid[0];
1871        uid    = uid[1];
1872
1873        nonce = nonce.split('?_wpnonce=');
1874        nonce = nonce[1].split('&');
1875        nonce = nonce[0];
1876
1877        $.post( ajaxurl, {
1878                action: 'bp_' + action,
1879                'uid': uid,
1880                '_wpnonce': nonce
1881            },
1882            function(response) {
1883                var $newLink = $(response);
1884
1885                var classStr = $link.attr('class');
1886
1887                // Strip follow/unfollow class.
1888                classStr = classStr.replace( action + ' ', '' );
1889
1890                $newLink.addClass(classStr);
1891
1892                $link.replaceWith($newLink);
1893            });
1894    };
1895
1896    g1.bpFollow = function () {
1897        $('body').on('click', '.g1-bp-action.follow,.g1-bp-action.unfollow', function() {
1898            follow( $(this) );
1899
1900            return false;
1901        });
1902    };
1903
1904})(jQuery);
1905
1906
1907
1908/*******************************
1909 *
1910 * Auto Load Next Post plugin
1911 *
1912 *******************************/
1913
1914(function ($) {
1915
1916    'use strict';
1917
1918    $(document).ready(function() {
1919        if ( typeof auto_load_next_post_params === 'object' ) {
1920            g1.autoLoadNextPost();
1921        }
1922    });
1923
1924    g1.autoLoadNextPost = function() {
1925        // Use that code when plugin start supports the "alnpNewPostLoaded" event.
1926        // $('body').on('alnpNewPostLoaded', function () {
1927        //    updateElements();
1928        // });
1929
1930        $('.post-divider').on('scrollSpy:exit', updateElements);
1931        $('.post-divider').on('scrollSpy:enter', updateElements);
1932    };
1933
1934    function updateElements() {
1935        var $lastArticle = $('> article:last', auto_load_next_post_params.alnp_content_container );
1936
1937        // Apply micro shares for new posts.
1938        g1.shareContentElements($lastArticle);
1939
1940        // Load player.
1941        g1.gifPlayer($lastArticle);
1942
1943        // Apply scrollspy again.
1944        $('.post-divider').on('scrollSpy:exit', updateElements);
1945        $('.post-divider').on('scrollSpy:enter', updateElements);
1946    }
1947
1948})(jQuery);
1949
1950
1951/*****************
1952 *
1953 * Ajax search
1954 *
1955 *****************/
1956
1957(function ($) {
1958
1959    'use strict';
1960
1961    var selectors = {
1962        'wrapper':  'div[role=search]',
1963        'form':     'form.g1-searchform-ajax',
1964        'input':    'form.g1-searchform-ajax input.search-field',
1965        'results':  '.g1-searches-ajax',
1966        'seeAll':   '.bimber-see-all-results'
1967    };
1968
1969    g1.ajaxSearch = function () {
1970        if (!$.fn.autocomplete) {
1971            return;
1972        }
1973
1974        $( selectors.input).each(function() {
1975            var $input   = $(this);
1976            var $form    = $input.parents(selectors.form);
1977            var $wrapper = $input.parents(selectors.wrapper);
1978
1979            $input.autocomplete({
1980                'appendTo':   $form,
1981                'delay':      500,
1982                'minLength':  2,
1983                'source': function(request) {
1984                    var xhr = $.ajax({
1985                        'type': 'GET',
1986                        'url': g1.config.ajax_url,
1987                        'dataType': 'json',
1988                        'data': {
1989                            'action':       'bimber_search',
1990                            'bimber_term':  request.term
1991                        }
1992                    });
1993
1994                    xhr.done(function (res) {
1995                        if (res.status === 'success') {
1996                            $wrapper.find(selectors.results).html(res.html);
1997                        }
1998                    });
1999                }
2000            });
2001
2002            // See all results.
2003            $wrapper.on('click', selectors.seeAll, function(e) {
2004                e.preventDefault();
2005
2006                $form.submit();
2007            });
2008        });
2009    };
2010
2011    // Update WooCommerce mini cart.
2012
2013    // Trigger event
2014    $( document.body ).on( 'adding_to_cart', function() {
2015        $('.g1-drop-toggle-badge').removeClass('g1-drop-toggle-badge-animate');
2016    } );
2017
2018    $( document.body ).on( 'added_to_cart removed_from_cart', function() {
2019        // the event is called BEFORE the cart AJAX comes back so we need a small timeout or we'll get the wrong count.
2020        setTimeout(function() {
2021            var $drop = $('.g1-drop-the-cart');
2022
2023            var count = parseInt( $drop.find( '.cart_list').data('g1-cart-count'), 10 );
2024            if ( count > 0 ) {
2025                $drop.find('.g1-drop-toggle-badge').removeClass('g1-drop-toggle-badge-hidden').addClass('g1-drop-toggle-badge-animate').text(count);
2026            } else {
2027                $drop.find('.g1-drop-toggle-badge').addClass('g1-drop-toggle-badge-hidden').text(count);
2028            }
2029        }, 500);
2030    } );
2031
2032    // Add our custom class to the link "View Cart" after product was added to the cart.
2033    // The "View Cart" link is located on product list, under the "Add to Cart" button.
2034    $(document.body).on('wc_cart_button_updated', function (e, $button) {
2035        $button.next('a.added_to_cart').addClass('g1-link g1-link-right');
2036    });
2037    
2038})(jQuery);
2039
2040/*****************
2041 *
2042 * Isotope
2043 *
2044 *****************/
2045
2046(function ($) {
2047
2048    'use strict';
2049
2050    var selectors = {
2051        'grid':     '.g1-collection-masonry .g1-collection-items'
2052    };
2053
2054    var $grid;
2055
2056    g1.isotope = function () {
2057        if (!$.fn.isotope) {
2058            return;
2059        }
2060
2061        $grid = $(selectors.grid);
2062
2063        if (!$grid.length) {
2064            return;
2065        }
2066
2067        $grid.isotope({
2068            itemSelector:   '.g1-collection-item',
2069            layoutMode:     'masonry'
2070        });
2071
2072        $('body').on( 'g1NewContentLoaded', function(e, $addedItems) {
2073            $('.g1-collection-masonry .g1-injected-unit', $addedItems).on( 'DOMSubtreeModified', function() {
2074                g1.resizeIsotope();
2075            });
2076            $grid.isotope('appended', $addedItems);
2077        });
2078        $('.g1-collection-masonry .g1-injected-unit').on( 'DOMSubtreeModified', function() {
2079            g1.resizeIsotope();
2080        });
2081    };
2082
2083    // we cheat isotope into thinking that the browser is resized. we can't do this by event alone so we temporarily change the size of the container.
2084    g1.resizeIsotope = function() {
2085        $('.g1-collection-masonry .g1-collection-items').width($('.g1-collection-masonry .g1-collection-items').width()-1);
2086        window.dispatchEvent(new Event('resize'));
2087        setTimeout(function() {
2088            $('.g1-collection-masonry .g1-collection-items').width($('.g1-collection-masonry .g1-collection-items').width()+1);
2089        }, 1000);
2090    };
2091
2092
2093})(jQuery);
2094
2095/*******************
2096 *
2097 * Snax Integration
2098 *
2099 ******************/
2100
2101(function ($) {
2102
2103    'use strict';
2104
2105    g1.snax = function () {
2106        var $body = $('body');
2107
2108        // Load FB SDK on demand.
2109        $body.on('snaxFbNotLoaded', function() {
2110            $('body').trigger('bimberLoadFbSdk');
2111        });
2112
2113        $body.on('snaxFullFormLoaded', function(e, $post) {
2114            $post.find('.g1-button-m.g1-button-solid').removeClass('g1-button-m  g1-button-solid').addClass('g1-button-s  g1-button-simple');
2115            $post.find('.g1-beta.g1-beta-1st').removeClass('g1-beta g1-beta-1st').addClass('g1-gamma g1-gamma-1st');
2116        });
2117    };
2118
2119})(jQuery);
2120
2121/*******************
2122 *
2123 * Media Ace Integration
2124 *
2125 ******************/
2126
2127(function ($) {
2128
2129    'use strict';
2130
2131    g1.mediaAce = function () {
2132
2133        $('body').on('g1NewContentLoaded', function() {
2134            $('body').trigger('maceLoadYoutube');
2135        });
2136
2137        $(document).on('lazybeforeunveil', function(e) {
2138            var $target = $(e.target);
2139            var targetSrc = $target.attr('data-src');
2140
2141            if (targetSrc && targetSrc.endsWith('.gif')) {
2142                // Wait till image fully loaded.
2143                $target.on('load', function() {
2144                    $target.addClass('g1-enable-gif-player');
2145
2146                    // Wait a while before applying player.
2147                    setTimeout(function() {
2148                        g1.gifPlayer($target.parent());
2149                    }, 100);
2150                });
2151            }
2152        });
2153
2154        $(document).on('bimberGifPlayerLoaded', function(e, $canvasWrapper) {
2155            if ($canvasWrapper.hasClass('lazyloading')) {
2156                $canvasWrapper.removeClass('lazyloading');
2157                $canvasWrapper.addClass('lazyloaded');
2158            }
2159        });
2160    };
2161
2162})(jQuery);
2163
2164/*************
2165 *
2166 * Comments
2167 *
2168 ************/
2169
2170(function ($) {
2171
2172    'use strict';
2173
2174    var selectors = {
2175        'wrapper':      '.g1-comments',
2176        'tabs':         '.g1-tab-items > li',
2177        'tab':          '.g1-tab-item',
2178        'currentTab':   '.g1-tab-item-current',
2179        'commentType':  '.g1-comment-type'
2180    };
2181
2182    var classes = {
2183        'currentTab':   'g1-tab-item-current',
2184        'currentType':  'g1-tab-pane-current',
2185        'type':         'g1-tab-pane',
2186        'loading':      'g1-loading',
2187        'loaded':       'g1-loaded'
2188    };
2189
2190    var $wrapper;
2191
2192    g1.comments = function () {
2193        $wrapper = $(selectors.wrapper);
2194
2195        if ($wrapper.length === 0) {
2196            return;
2197        }
2198
2199        initTabs();
2200
2201        g1.facebookComments();
2202        g1.disqusComments();
2203    };
2204
2205    var initTabs = function() {
2206        var $tabs = $wrapper.find(selectors.tabs);
2207        var currentType = $tabs.filter(selectors.currentTab).attr('data-bimber-type');
2208
2209        // Can't find current tab.
2210        if (!currentType) {
2211            var types = g1.config.comment_types;
2212
2213            if (types && types.length > 0) {
2214                currentType = types[0];
2215            } else {
2216                currentType = 'wp';
2217            }
2218        }
2219
2220        $wrapper.find(selectors.commentType).each(function() {
2221            var $type = $(this);
2222
2223            $type.addClass(classes.type);
2224        });
2225
2226        if ( 'dsq' === currentType ) {
2227            setTimeout(function() {
2228                selectTab(currentType);
2229            }, 1000);
2230        } else {
2231            selectTab(currentType);
2232        }
2233
2234        $tabs.on('click', function() {
2235            var type = $(this).attr('data-bimber-type');
2236
2237            selectTab(type);
2238        });
2239    };
2240
2241    var selectTab = function(type) {
2242        var $tab = $wrapper.find(selectors.tab + '-' + type);
2243        var $type = $wrapper.find(selectors.commentType + '-' + type);
2244
2245        if ($type.hasClass(classes.currentType)) {
2246            return;
2247        }
2248
2249        if ('fb' === type) {
2250            if (!$type.hasClass(classes.loaded)) {
2251                $type.addClass(classes.loading);
2252            }
2253
2254            $('body').trigger('bimberLoadFbSdk');
2255        }
2256
2257        // Select new type.
2258        $wrapper.find(selectors.commentType).removeClass(classes.currentType);
2259        $type.addClass(classes.currentType);
2260
2261        $type.trigger('loadComments');
2262
2263        // Select new tab.
2264        $wrapper.find(selectors.tabs).removeClass(classes.currentTab);
2265        $tab.addClass(classes.currentTab);
2266    };
2267
2268})(jQuery);
2269
2270/*******************
2271 *
2272 * Facebook Comments
2273 * (plugin integration)
2274 *
2275 ******************/
2276
2277(function ($) {
2278
2279    'use strict';
2280
2281    var selectors = {
2282        'wrapper':  '.g1-comment-type-fb',
2283        'counter':  '.g1-comment-count',
2284        'list':     '.g1-comment-list',
2285        'tab':      '.g1-comments .g1-tab-item-fb'
2286    };
2287
2288    var classes = {
2289        'loading':  'g1-loading',
2290        'loaded':   'g1-loaded'
2291    };
2292
2293    var $wrapper;
2294    var loaded = false;
2295
2296    g1.facebookComments = function () {
2297        $wrapper = $(selectors.wrapper);
2298
2299        if (!$wrapper.is('.g1-on-demand')) {
2300            loaded = true;
2301        }
2302
2303        if ($wrapper.length > 0) {
2304            init();
2305
2306            return $wrapper;
2307        } else {
2308            return false;
2309        }
2310    };
2311
2312    var init = function() {
2313        // Init when FB is ready.
2314        var origFbAsyncInit = window.fbAsyncInit;
2315
2316        window.fbAsyncInit = function() {
2317            if (typeof FB === 'undefined') {
2318                return;
2319            }
2320
2321            // Update on post load.
2322            FB.Event.subscribe('xfbml.render', function() {
2323                $wrapper.removeClass(classes.loading);
2324                $wrapper.addClass(classes.loaded);
2325
2326                var $counter = $wrapper.find(selectors.counter);
2327
2328                var url = $counter.find('.fb_comments_count').attr('data-bimber-graph-api-url');
2329                FB.api(
2330                    '/' + url,
2331                    'GET',
2332                    {'fields':'engagement'},
2333                    function(response) {
2334                        if(response.engagement) {
2335                            var count = response.engagement.comment_plugin_count;
2336                            $('.fb_comments_count').html(count);
2337                        }
2338                    }
2339                  );
2340                var realCount = parseInt($counter.find('.fb_comments_count').text(), 10);
2341                var postCount = parseInt($counter.attr('data-bimber-fb-comment-count'), 10);
2342
2343                if (realCount !== postCount) {
2344                    save(realCount);
2345                }
2346            });
2347
2348            // New comment added.
2349            FB.Event.subscribe('comment.create', function() {
2350                changeCommentsNumber(1);
2351            });
2352
2353            // Comment removed.
2354            FB.Event.subscribe('comment.remove', function() {
2355                changeCommentsNumber(-1);
2356            });
2357
2358            if (typeof origFbAsyncInit === 'function') {
2359                origFbAsyncInit();
2360            }
2361        };
2362
2363        // Listen on "Load comments" event.
2364        $wrapper.on('loadComments', function() {
2365            if (loaded) {
2366                return;
2367            }
2368
2369            $wrapper.addClass(classes.loading);
2370
2371            loadComments(function(html) {
2372                g1.resetFacebookSDK();
2373
2374                $wrapper.find(selectors.list).html(html);
2375                $wrapper.removeClass(classes.loading);
2376            });
2377        });
2378    };
2379
2380    var changeCommentsNumber = function(diff) {
2381        var $counter = $wrapper.find(selectors.counter);
2382        var postCount = parseInt($counter.attr('data-bimber-fb-comment-count'), 10);
2383
2384        postCount += diff;
2385
2386        // Update Facebook comment count.
2387        $wrapper.find('.fb_comments_count').text(postCount);
2388        $counter.attr('data-bimber-fb-comment-count', postCount);
2389
2390        // Update total post comment count.
2391        var $postCommentCount = $wrapper.parents('#content').find('.entry-comments-link strong');
2392
2393        var postCommentCount = parseInt($postCommentCount.text(), 10);
2394        $postCommentCount.text(postCommentCount + diff);
2395
2396        // Update tab counter.s
2397        var $fbCount = $(selectors.tab).find('a > span');
2398
2399        if ($fbCount.length > 0) {
2400            var fbCount = parseInt($fbCount.text(), 10);
2401
2402            $fbCount.text(fbCount + diff);
2403        }
2404
2405        save(postCount);
2406    };
2407
2408    var save = function(newCount) {
2409        var postId = $wrapper.find(selectors.counter).attr('data-bimber-post-id');
2410        var nonce  = $wrapper.find(selectors.counter).attr('data-bimber-nonce');
2411
2412        $.ajax({
2413            'type': 'POST',
2414            'url': g1.config.ajax_url,
2415            'dataType': 'json',
2416            'data': {
2417                'action':   'bimber_update_fb_comment_count',
2418                'post_id':  postId,
2419                'security': nonce,
2420                'count':    newCount
2421            }
2422        });
2423    };
2424
2425    var loadComments = function(callback) {
2426        var postId = $wrapper.find(selectors.counter).attr('data-bimber-post-id');
2427
2428        var xhr = $.ajax({
2429            'type': 'GET',
2430            'url': g1.config.ajax_url,
2431            'data': {
2432                'action':   'bimber_load_fbcommentbox',
2433                'post_id':  postId
2434            }
2435        });
2436
2437        xhr.done(function(res) {
2438            callback(res);
2439
2440            loaded = true;
2441        });
2442    };
2443
2444})(jQuery);
2445
2446
2447/**********************
2448 *
2449 * Disqus Comments
2450 * (plugin integration)
2451 *
2452 *********************/
2453
2454(function ($) {
2455
2456    'use strict';
2457
2458    var selectors = {
2459        'wrapper':  '.g1-comment-type-dsq',
2460        'counter':  '.g1-comment-count',
2461        'list':     '.g1-comment-list',
2462        'tab':      '.g1-comments .g1-tab-item-dsq'
2463    };
2464
2465    var classes = {
2466        'loading':  'g1-loading'
2467    };
2468
2469    var $wrapper;
2470    var loaded = false;
2471
2472    g1.disqusComments = function () {
2473        $wrapper = $(selectors.wrapper);
2474
2475        if ($wrapper.length > 0) {
2476            init();
2477
2478            return $wrapper;
2479        } else {
2480            return false;
2481        }
2482    };
2483
2484    var init = function() {
2485        var origDsqConfig = window.disqus_config;
2486
2487        window.disqus_config = function() {
2488            if (typeof origDsqConfig === 'function') {
2489                origDsqConfig();
2490
2491                $wrapper.removeClass(classes.loading);
2492                loaded = true;
2493            }
2494
2495            // DISQUSWIDGETS.getCount({reset: true});
2496
2497            // Init.
2498            var $counter = $wrapper.find(selectors.counter);
2499
2500            var realCount = parseInt($counter.find('.disqus-comment-count').text(), 10);
2501            var postCount = parseInt($counter.attr('data-bimber-dsq-comment-count'), 10);
2502
2503            if (realCount !== postCount) {
2504                save(realCount);
2505            }
2506
2507            this.callbacks.onNewComment = [function() {
2508                changeCommentsNumber(1);
2509            }];
2510        };
2511
2512        // Listen on "Load comments" event.
2513        $wrapper.on('loadComments', function() {
2514            if (loaded) {
2515                return;
2516            }
2517
2518            $wrapper.addClass(classes.loading);
2519
2520            loadComments();
2521        });
2522    };
2523
2524    var changeCommentsNumber = function(diff) {
2525        var $counter = $wrapper.find(selectors.counter);
2526        var postCount = parseInt($counter.attr('data-bimber-dsq-comment-count'), 10);
2527
2528        postCount += diff;
2529
2530        // Update Facebook comment count.
2531        $wrapper.find('.disqus-comment-count').text(postCount);
2532        $counter.attr('data-bimber-dsq-comment-count', postCount);
2533
2534        // Update total post comment count.
2535        var $postCommentCount = $wrapper.parents('#content').find('.entry-comments-link strong');
2536
2537        var postCommentCount = parseInt($postCommentCount.text(), 10);
2538        $postCommentCount.text(postCommentCount + diff);
2539
2540        // Update tab counter.s
2541        var $dsqCount = $(selectors.tab).find('a > span');
2542
2543        if ($dsqCount.length > 0) {
2544            var dsqCount = parseInt($dsqCount.text(), 10);
2545
2546            $dsqCount.text(dsqCount + diff);
2547        }
2548
2549        save(postCount);
2550    };
2551
2552    var save = function(newCount) {
2553        var postId = $wrapper.find(selectors.counter).attr('data-bimber-post-id');
2554        var nonce  = $wrapper.find(selectors.counter).attr('data-bimber-nonce');
2555
2556        $.ajax({
2557            'type': 'POST',
2558            'url': g1.config.ajax_url,
2559            'dataType': 'json',
2560            'data': {
2561                'action':   'bimber_dsq_update_comment_count',
2562                'post_id':  postId,
2563                'security': nonce,
2564                'count':    newCount
2565            }
2566        });
2567    };
2568
2569    var loadComments = function() {
2570        var dsq = document.createElement('script');
2571        dsq.type = 'text/javascript';
2572        dsq.async = true;
2573        dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js';
2574        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
2575    };
2576
2577})(jQuery);
2578
2579/*******
2580 *
2581 * Menu
2582 *
2583 *******/
2584(function (context, $, i18n) {
2585
2586    'use strict';
2587
2588    $(document).ready(function () {
2589        PrimaryMenu();
2590    });
2591
2592    function PrimaryMenu () {
2593        var that = {};
2594
2595        that.init = function () {
2596            that.registerEventsHandlers();
2597
2598            // add toggle to menu
2599            $('.menu-item-has-children > a, .menu-item-g1-mega > a').append( '<span class="g1-link-toggle"></span>' );
2600
2601            return that;
2602        };
2603
2604        that.registerEventsHandlers = function () {
2605            that.handleMenuItemClick();
2606            that.handleMenuItemFocusOut();
2607        };
2608
2609        that.handleMenuItemFocusOut = function () {
2610            $('body').on('click', function (e) {
2611                if ($(e.target).parents('.mtm-drop-expanded').length === 0 ) {
2612                    that.collapseAllOpenedSubmenus();
2613                }
2614            });
2615        };
2616
2617        that.handleMenuItemClick = function () {
2618            $('.g1-primary-nav, .g1-secondary-nav').on('click', '.menu-item > a', function (e) {
2619                var $menu = $(this).parents('.g1-primary-nav');
2620
2621                if ($menu.length === 0) {
2622                    $menu = $(this).parents('.g1-secondary-nav');
2623                }
2624
2625                var isSimpleList = $menu.is('#g1-canvas-primary-nav') || $menu.is('#g1-canvas-secondary-nav');
2626
2627                if (g1.isTouchDevice() || isSimpleList) {
2628                    that.handleMenuTouchEvent($(this), e);
2629                }
2630            });
2631        };
2632
2633        that.handleMenuTouchEvent = function ($link, event) {
2634            var $li = $link.parent('li');
2635
2636            that.collapseAllOpenedSubmenus($li);
2637
2638            if ($li.hasClass('menu-item-has-children')) {
2639                event.preventDefault();
2640
2641                var $helper = $li.find('ul.sub-menu:first > li.g1-menu-item-helper');
2642
2643                if ($helper.length === 0) {
2644                    var href = $link.attr('href');
2645                    var anchor = i18n.go_to + ' <span class="mtm-item-helper-title">'+ $link.html() +'</span>';
2646
2647                    $helper = $('<li class="menu-item g1-menu-item-helper"><a class="mtm-link" href="'+ href +'"><span class="mtm-link-text"><span class="mtm-link-title">' + anchor +'</span></span></a></li>');
2648
2649                    $li.find('ul.sub-menu:first').prepend($helper);
2650                }
2651
2652                if (!$li.is('.mtm-drop-expanded')) {
2653                    $li.find('.mtm-drop-expanded .g1-menu-item-helper').remove();
2654                    $li.addClass('mtm-drop-expanded');
2655                } else {
2656                    $li.find('.mtm-drop-expanded').removeClass('mtm-drop-expanded');
2657                    $li.removeClass('mtm-drop-expanded');
2658                }
2659            }
2660        };
2661
2662        that.collapseAllOpenedSubmenus = function ($currentItem) {
2663            if ($currentItem) {
2664                var $currentMenu = $currentItem.parents('nav');
2665                var $topLevelLi = $currentItem.parents('li.menu-item');
2666
2667                // We are at top level of menu
2668                if($topLevelLi.length === 0) {
2669                    // Collapse all, except current.
2670                    // This will collapse current item subtree items but not item itself. Item will be collapse by the "handleMenuTouchEvent" handler.
2671                    $currentMenu.find('.mtm-drop-expanded').not($currentItem).removeClass('mtm-drop-expanded');
2672                } else {
2673                    // Collapse all opened submenus in current menu, except current subtree.
2674                    $topLevelLi.siblings('li').find('.mtm-drop-expanded').removeClass('mtm-drop-expanded');
2675                }
2676
2677                // Collapse all opened submenus in all other menus.
2678                $('nav').not($currentMenu).find('.mtm-drop-expanded').removeClass('mtm-drop-expanded');
2679            } else {
2680                // collapse all opened, site wide, submenus
2681                $('.mtm-drop-expanded').removeClass('mtm-drop-expanded');
2682            }
2683        };
2684
2685        return that.init();
2686    }
2687
2688})(window, jQuery, g1.config.i18n.menu);
2689
2690// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
2691// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
2692// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
2693// MIT license
2694
2695(function() {
2696    var lastTime = 0;
2697    var vendors = ['ms', 'moz', 'webkit', 'o'];
2698    for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
2699        window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
2700        window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
2701    }
2702
2703    if (!window.requestAnimationFrame) {
2704        window.requestAnimationFrame = function(callback) {
2705            var currTime = new Date().getTime();
2706            var timeToCall = Math.max(0, 16 - (currTime - lastTime));
2707            var id = window.setTimeout(function() { callback(currTime + timeToCall); },
2708                timeToCall);
2709            lastTime = currTime + timeToCall;
2710            return id;
2711        };
2712    }
2713
2714    if (!window.cancelAnimationFrame) {
2715        window.cancelAnimationFrame = function(id) {
2716            clearTimeout(id);
2717        };
2718    }
2719}());
2720
2721/**********************
2722 *
2723 * Bimber Load Next Post
2724 *
2725 **********************/
2726
2727(function ($) {
2728
2729    'use strict';
2730
2731    g1.loadNextPostConfig = {
2732        'offset': '500%'
2733    };
2734
2735    var selectors = {
2736        'button' :       '.bimber-load-next-post',
2737        'urlWaypoint':   '.bimber-url-waypoint',
2738        'elementButton': '.g1-auto-load-button'
2739    };
2740
2741    g1.loadNextPost = function () {
2742
2743        var mainUrl = window.location.href;
2744        var autoLoadLimit = g1.config.auto_load_limit;
2745        var loadedPosts = 0;
2746
2747        var loadNextEvent = function(e){
2748
2749            e.preventDefault();
2750
2751            if (autoLoadLimit > 0 && loadedPosts >= autoLoadLimit){
2752                $(this).remove();
2753                return;
2754            }
2755
2756            var $button = $(this);
2757            var template = 'classic';
2758            if($('#secondary').length === 0){
2759                template = 'row';
2760            }
2761            $button.css('position','relative');
2762            $button.addClass('g1-collection-more-loading');
2763            var postUrl = $('a', this).attr('href');
2764            var gaPostUrl = $('a', this).attr('data-bimber-analytics-href');
2765            var url = postUrl + '?bimber_auto_load_next_post_template=' + template;
2766
2767            $('a', this).remove();
2768
2769            // load page
2770            var xhr = $.get(url);
2771            loadedPosts += 1;
2772
2773            // on success
2774            xhr.done(function (data) {
2775                var $html = $($.parseHTML(data, document, true));
2776                var $content = $html.find('#content');
2777                var title = $($content.find('.entry-title')[0]).text();
2778                var $microshare_template_tag = $content.find('#bimber-front-microshare-autoload');
2779                var microshare_template = $microshare_template_tag.html();
2780                $microshare_template_tag.remove();
2781                $content.find('#secondary').remove();
2782
2783                // If there are insta embeds BEFORE the load, we will force to refresh them AFTER the load
2784                var $insta = $('script[src="//platform.instagram.com/en_US/embeds.js"]');
2785
2786                // make sure that mejs is loaded
2787                if (typeof window.wp.mediaelement === 'undefined') {
2788                    var matches = data.match(/<script(.|\n)*?<\/script>/g);
2789                    var mejsCode = '';
2790                    matches.forEach(function( match ) {
2791                        if ( match.indexOf('mejs') > 0 || match.indexOf('mediaelement') > 0 ){
2792                            match = match.replace('<script','<script async');
2793                            mejsCode+=match;
2794                        }
2795                    });
2796                    matches = data.match(/<link(.|\n)*?\/>/g);
2797                    matches.forEach(function( match ) {
2798                        if ( match.indexOf('mejs') > 0 || match.indexOf('mediaelement') > 0 ){
2799                            mejsCode+=match;
2800                        }
2801                    });
2802                    $button.after(mejsCode);
2803                }
2804                $button.before('<div class="g1-divider"></div>');
2805
2806                $('body').trigger( 'g1BeforeNewContentReady', [ $content ] );
2807
2808                var $scope = $($content.html()).insertAfter($button);
2809
2810                if ( $insta.length > 0) {
2811                    window.instgrm.Embeds.process();
2812                }
2813
2814                $button.remove();
2815
2816                g1.shareContentElements($scope,microshare_template);
2817                $('body').trigger( 'g1NewContentLoaded', [ $scope ] );
2818
2819                if (typeof window.wp.mediaelement !== 'undefined') {
2820                    window.wp.mediaelement.initialize();
2821                }
2822
2823                // Google Analytics.
2824                if ( typeof ga !== 'undefined' && typeof ga.getAll !== 'undefined') {
2825                    ga('create', ga.getAll()[0].get('trackingId'), 'auto');
2826                    ga('set', { page: gaPostUrl, title: title });
2827                    ga('send', 'pageview');
2828                }
2829
2830                // WPP Ajax.
2831                var $nonce = $html.find('#bimber-wpp-nonce');
2832                if ($nonce.length>0){
2833                    var nonce  = $nonce.attr('data-bimber-wpp-nonce');
2834                    var postId = $nonce.attr('data-bimber-wpp-id');
2835                    g1.updatePostViews(nonce,postId);
2836                }
2837                bindEvents();
2838            });
2839
2840            xhr.always(function () {
2841                $button.removeClass('g1-collection-more-loading');
2842            });
2843        };
2844
2845        var bindEvents = function() {
2846            $(selectors.button).click(loadNextEvent);
2847
2848            $(selectors.elementButton).click(function(){
2849                window.history.replaceState( {} , '', mainUrl );
2850            });
2851
2852            $(selectors.button).waypoint(function(direction) {
2853                if('down' === direction) {
2854                    $(selectors.button).trigger('click');
2855                }
2856            }, {
2857                offset: g1.loadNextPostConfig.offset
2858            });
2859
2860            $(selectors.urlWaypoint).waypoint(function(direction) {
2861                var $waypoint = $(this.element);
2862                if('up' === direction) {
2863                    var $waypointUp = $waypoint.parent('article').prev('.bimber-url-waypoint');
2864                    if ($waypointUp.length > 0){
2865                        $waypoint = $waypointUp;
2866                    }
2867                }
2868
2869                var url = $waypoint.attr('data-bimber-post-url');
2870                var title = $waypoint.attr('data-bimber-post-title');
2871                var currentUrl = window.location.href;
2872                if ( url !== currentUrl ){
2873                    var $article = $waypoint.next('article');
2874                    var $mashShare = $('.mashsb-container', $article);
2875                    var $shareBar = $('.g1-sharebar .g1-sharebar-inner');
2876                    if ( $mashShare.length >0 && $.trim($shareBar.html())) {
2877                        $shareBar.html($mashShare[0].outerHTML);
2878                    }
2879                    g1.customizeShareButtons();
2880                    window.history.replaceState( {} , '', url );
2881                    document.title = title;
2882                }
2883            });
2884        };
2885
2886        bindEvents();
2887    };
2888
2889})(jQuery);
2890
2891/**********************
2892 *
2893 * Auto Play Video
2894 *
2895 **********************/
2896
2897(function ($) {
2898
2899    'use strict';
2900
2901    var selectors = {
2902        'videoPost':         '.archive-body-stream .entry-tpl-stream .entry-featured-media:not(.entry-media-nsfw-embed)',
2903        'videoWrapper':      '.g1-fluid-wrapper-inner',
2904        'videoIframe':       '.g1-fluid-wrapper-inner iframe',
2905        'maceButton':        '.g1-fluid-wrapper-inner .mace-play-button',
2906        'embedly':           '.embedly-card iframe',
2907        'mejs':              '.mejs-video',
2908        'mejsButton':        '.mejs-video .mejs-overlay-button',
2909        'mejsPause':         '.mejs-video .mejs-pause',
2910        'mejsPlay':          '.mejs-video .mejs-play',
2911        'mejsMute':          '.mejs-video .mejs-mute button',
2912        'jsgif':             '.jsgif',
2913        'html5Video':         '.snax-native-video'
2914    };
2915
2916    // Due to varied autoplay browsers' policies, it's almost impossible to guarantee autoplying on mobiles, so we turn it off.
2917    g1.isAutoPlayEnabled   = g1.config.auto_play_videos && ! g1.isTouchDevice();
2918
2919    var playingIds          = [];   // Ids of all posts currently playing.
2920    var playingQueue        = [];   // All "videPosts" currently playing.
2921    var playedIds           = [];   // Ids of all posts playing or played (if id is here, we resume it instead of play next time).
2922
2923    g1.autoPlayVideo = function () {
2924        if ( ! g1.isAutoPlayEnabled ) {
2925            return;
2926        }
2927
2928        var addToQueue = function(element) {
2929            var postId = $(element).parents('article').attr('id');
2930
2931            playingQueue.push(element);
2932            playingIds.push(postId);
2933            playedIds.push(postId);
2934        };
2935
2936        var getFromQueue = function() {
2937            var element = playingQueue.pop();
2938
2939            var postId = $(element).parents('article').attr('id');
2940            var index  = playingIds.indexOf(postId);
2941
2942            if (index > -1) {
2943                playingIds.splice(index, 1);
2944            }
2945
2946            return element;
2947        };
2948
2949        var pauseAllVideos = function() {
2950            if (playingQueue.length === 0) {
2951                return;
2952            }
2953
2954            g1.log('Pause all videos');
2955            g1.log(playingQueue);
2956
2957            while (playingQueue.length > 0) {
2958                var element = getFromQueue();
2959
2960                pause(element);
2961            }
2962        };
2963
2964        var play = function(element) {
2965            var postId   = $(element).parents('article').attr('id');
2966            var $iframe  = $(selectors.videoIframe, element);
2967            var $embedly = $(selectors.embedly, element);
2968            var $mace    = $(selectors.maceButton, element);
2969            var $mejs    = $(selectors.mejsButton, element);
2970            var $jsgif   = $(selectors.jsgif, element);
2971            var $html5   = $(selectors.html5Video, element);
2972            var videosInPost = $iframe.length + $embedly.length + $mace.length + $mejs.length + $jsgif.length + $html5.length;
2973
2974            // Element is a video to play?
2975            if (videosInPost > 0) {
2976                // Before playing this video we want to make sure that others video are paused too.
2977                pauseAllVideos();
2978            } else {
2979                return;
2980            }
2981
2982            // IFRAME.
2983            if ($iframe.length > 0 ) {
2984                var iframesrc = false;
2985
2986                if ($iframe.attr('data-src')) {
2987                    iframesrc= $iframe.attr('data-src');
2988                } else {
2989                    iframesrc= $iframe.attr('src');
2990                }
2991
2992                if ( iframesrc ) {
2993                    var separator = '?';
2994
2995                    if (iframesrc.indexOf('?') > 0){
2996                        separator = '&';
2997                    }
2998
2999                    if (iframesrc.indexOf('youtu') > 0){
3000                        // Already played?
3001                        if (-1 !== playedIds.indexOf(postId)) {
3002                            // Resume.
3003                            $iframe[0].contentWindow.postMessage(JSON.stringify({
3004                                    'event': 'command',
3005                                    'func': 'playVideo',
3006                                    'args': ''}),
3007                                '*');
3008                        } else {
3009                            $iframe.on('load', function() {
3010                                // Mute on load.
3011                                $iframe[0].contentWindow.postMessage(JSON.stringify({
3012                                        'event': 'command',
3013                                        'func': 'mute',
3014                                        'args': ''}),
3015                                    '*');
3016                            });
3017
3018                            $iframe.attr('src', iframesrc + separator + 'autoplay=1&enablejsapi=1');
3019                        }
3020                    }
3021
3022                    if (iframesrc.indexOf('dailymotion') > 0){
3023                        // Already played?
3024                        if (-1 !== playedIds.indexOf(postId)) {
3025                            $iframe[0].contentWindow.postMessage('play', '*');
3026                        } else {
3027                            // Mute on load.
3028                            $iframe.attr('src', iframesrc + separator + 'autoplay=1&api=postMessage&mute=1');
3029                        }
3030                    }
3031
3032                    if (iframesrc.indexOf('vimeo') > 0){
3033                        // Already played?
3034                        if (-1 !== playedIds.indexOf(postId)) {
3035                            // Resume playing.
3036                            $iframe[0].contentWindow.postMessage(JSON.stringify({
3037                                method: 'play'
3038                            }), '*');
3039                        } else {
3040                            // Mute on load.
3041                            $iframe.on('load', function() {
3042                                $iframe[0].contentWindow.postMessage(JSON.stringify({
3043                                    method: 'setVolume',
3044                                    value:  0
3045                                }), '*');
3046                            });
3047
3048                            $iframe.attr('src', iframesrc + separator + 'autoplay=1&autopause=0');
3049                        }
3050                    }
3051                }
3052            }
3053
3054            // Embedly player.
3055            if (typeof embedly !== 'undefined'){
3056                if ($embedly.length > 0 ) {
3057                    // the following iterates over all the instances of the player.
3058                    embedly('player', function(player){
3059                        if ($embedly[0] === $(player.frame.elem)[0]) {
3060                            player.play();
3061                            player.mute();
3062                        } else {
3063                            player.pause();
3064                        }
3065                    });
3066                } else {
3067                    embedly('player', function(player){
3068                        player.pause();
3069                    });
3070                }
3071            }
3072
3073            // MediaAce YouTube lazy loader.
3074            if ($mace.length > 0) {
3075                var $maceWrapper = $mace.parent();
3076
3077                // Mute on load.
3078                $maceWrapper.on('maceIframeLoaded', function(e, $iframe) {
3079                    $iframe[0].contentWindow.postMessage(JSON.stringify({
3080                            'event': 'command',
3081                            'func': 'mute',
3082                            'args': ''}),
3083                        '*');
3084                });
3085
3086                $mace.trigger('click');
3087            }
3088
3089            // MEJS player (MP4).
3090            if ($mejs.length > 0) {
3091                $mejs.trigger('click');
3092
3093                // Mute on load.
3094                var playerId = $mejs.parents('.mejs-container').attr('id');
3095
3096                if (playerId && mejs && typeof mejs.players !== 'undefined') {
3097                    var player = mejs.players[playerId];
3098
3099                    player.setVolume(0);
3100                }
3101            }
3102
3103            // GIF player.
3104            if ( $jsgif.length > 0 ) {
3105                setTimeout(function() {
3106                    $jsgif.trigger('bimberPlayGif');
3107                }, 500);
3108            }
3109
3110            // Native HTML5 videos
3111            if ( $html5.length > 0 ) {
3112                $html5[0].play();
3113            }
3114
3115            addToQueue(element);
3116        };
3117
3118        var pause = function (element) {
3119            var $triggerediframe = $(selectors.videoIframe, element);
3120
3121            if ($triggerediframe.length > 0 ) {
3122                var iframesrc=false;
3123                if ($triggerediframe.attr('data-src')) {
3124                    iframesrc= $triggerediframe.attr('data-src');
3125                } else {
3126                    iframesrc= $triggerediframe.attr('src');
3127                }
3128                if ( iframesrc ) {
3129                    if (iframesrc.indexOf('youtu') > 0){
3130                        $triggerediframe[0].contentWindow.postMessage(JSON.stringify({
3131                                'event': 'command',
3132                                'func': 'pauseVideo',
3133                                'args': ''}),
3134                            '*');
3135                    }
3136                    if (iframesrc.indexOf('dailymotion') > 0){
3137                        $triggerediframe[0].contentWindow.postMessage('pause', '*');
3138                    }
3139                    if (iframesrc.indexOf('vimeo') > 0){
3140                        $triggerediframe[0].contentWindow.postMessage(JSON.stringify({
3141                            method: 'pause'
3142                        }), '*');
3143                    }
3144                }
3145            }
3146
3147            if (typeof embedly !== 'undefined'){
3148                var $embedly = $(selectors.embedly,element);
3149                if ($embedly.length > 0 ) {
3150                    embedly('player', function(player){
3151                        if ($embedly[0] === $(player.frame.elem)[0]) {
3152                            player.pause();
3153                        }
3154                    });
3155                }
3156            }
3157
3158            $(selectors.mejsPause, element).trigger('click');
3159
3160            var $jsgif   = $(selectors.jsgif, element);
3161            $jsgif.trigger('bimberPauseGif');
3162
3163            var $html5 = $(selectors.html5Video, element);
3164            if ( $html5.length > 0 ) {
3165                $html5[0].pause();
3166            }
3167        };
3168
3169        // If video post id is still in array, video is still in viewport and can be played.
3170        var canBeAutoPlayed = function(postId) {
3171            return g1.isAutoPlayEnabled && -1 !== playingIds.indexOf(postId);
3172        };
3173
3174        var bindEvents = function() {
3175
3176            // Delay waypoint. User scroll activate events.
3177            var scrollEvents = 0;
3178            var allowPlaying = false;
3179
3180            // Wait for user scroll. Not scroll event while page loading.
3181            $(document).scroll(function() {
3182                scrollEvents++;
3183
3184                if (scrollEvents > 5) {
3185                    allowPlaying = true;
3186                }
3187            });
3188
3189            // ENTER, while up to down scrolling.
3190            $(selectors.videoPost).waypoint(function(direction) {
3191                if ('down' === direction) {
3192                    if (allowPlaying) {
3193                        g1.log('Play video (enter, direction: down)');
3194
3195                        play(this.element);
3196                    }
3197
3198                }
3199            }, {
3200                // When the bottom of the element hits the bottom of the viewport.
3201                offset: 'bottom-in-view'
3202            });
3203
3204            // ENTER, while down to up scrolling.
3205            $(selectors.videoPost).waypoint(function(direction) {
3206                if ('up' === direction) {
3207                    if (allowPlaying) {
3208                        g1.log('Play video (enter, direction: up)');
3209
3210                        play(this.element);
3211                    }
3212                }
3213            }, {
3214                // When the top of the element hits the top of the viewport.
3215                offset: '0'
3216            });
3217
3218            // EXIT, while up to down scrolling.
3219            $(selectors.videoPost).waypoint(function(direction) {
3220                if ('down' === direction) {
3221                    g1.log('Pause (exit, direction: down)');
3222
3223                    pause(this.element);
3224                }
3225            }, {
3226                offset: function() {
3227                    // Fires when top of the element is (HALF OF ELEMENT HEIGHT)px from the top of the window.
3228                    return -Math.round(this.element.clientHeight / 2);
3229                }
3230            });
3231
3232            // EXIT, while down to up scrolling.
3233            $(selectors.videoPost).waypoint(function(direction) {
3234                if ('up' === direction) {
3235                    g1.log('Pause (exit, direction: up)');
3236
3237                    pause(this.element);
3238                }
3239            }, {
3240                offset: function() {
3241                    var viewportHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
3242
3243                    // Fires when top of the element is (HALF OF ELEMENT HEIGHT)px from the bottom of the window.
3244                    return viewportHeight - Math.round(this.element.clientHeight / 2);
3245                }
3246            });
3247
3248            // Play GIF on load.
3249            $(document).on('bimberGifPlayerLoaded', function(e, $canvasWrapper) {
3250                var postId = $canvasWrapper.parents('article').attr('id');
3251
3252                if (canBeAutoPlayed(postId)) {
3253                    $canvasWrapper.trigger('bimberPlayGif');
3254                }
3255            });
3256        };
3257
3258        bindEvents();
3259    };
3260
3261})(jQuery);
3262
3263/**************************
3264 *
3265 * MyCred Notifications
3266 * (images, video)
3267 *
3268 **************************/
3269
3270(function ($) {
3271
3272    'use strict';
3273
3274    g1.myCredNotifications = function () {
3275
3276        var setTimeoutForFirstNotification = function() {
3277            if ( $('.g1-mycred-notice-overlay-standard').attr('data-g1-mycred-notice-timeout') && $('.g1-notification-standard').length > 0) {
3278                var timeout = $('.g1-mycred-notice-overlay-standard').attr('data-g1-mycred-notice-timeout');
3279                var firstNotification = $('.g1-notification-standard')[0];
3280                setTimeout(function() {
3281                    firstNotification.remove();
3282                    setTimeoutForFirstNotification();
3283                }, timeout * 1000);
3284            }
3285        };
3286
3287        var bindStandardNotificationEvents = function() {
3288            if ($('.g1-mycred-notice-overlay').length > 0 || $('.g1-mycred-notice-overlay-standard').length < 1) {
3289                return;
3290            }
3291            $('.g1-notification-standard-close').on('click', function (e) {
3292                $(this).closest('.g1-notification-standard').remove();
3293                setTimeoutForFirstNotification();
3294            });
3295            setTimeoutForFirstNotification();
3296        };
3297
3298        $('.g1-mycred-notice-close').on('click', function (e) {
3299            var $that = $(this);
3300            $that.closest('.g1-mycred-notice-overlay').removeClass('g1-mycred-notice-overlay-visible');
3301            setTimeout(function(){
3302                $that.closest('g1-mycred-notice-overlay').remove();
3303                bindStandardNotificationEvents();
3304            }, 375);
3305        });
3306
3307        $('.g1-mycred-notice-overlay').on('click', function (e) {
3308            var $that = $(this);
3309            $that.closest('.g1-mycred-notice-overlay').removeClass('g1-mycred-notice-overlay-visible');
3310            setTimeout(function(){
3311                $that.remove();
3312                bindStandardNotificationEvents();
3313            }, 375);
3314        }).children().click(function(e) {
3315            if (!$(e.target).hasClass('g1-mycred-notice-close')){
3316                return false;
3317            }
3318        });
3319
3320        bindStandardNotificationEvents();
3321
3322        $('.g1-mycred-notice-share-twitter').on('click', function (e) {
3323            e.preventDefault();
3324            window.open($(this).attr('href'), 'Google', 'width=500,height=300');
3325        });
3326
3327        var noticesTop = $('#wpadminbar').outerHeight() + $('.g1-sticky-top-wrapper').outerHeight();
3328        $('.g1-mycred-notice-overlay-standard').css('top', noticesTop);
3329    };
3330
3331})(jQuery);
3332
3333/**************************
3334 *
3335 * Archive filters
3336 *
3337 **************************/
3338
3339(function ($) {
3340
3341    'use strict';
3342
3343    g1.archiveFilters = function () {
3344        $('#g1-archive-filter-select').on('change', function() {
3345            var $this = $(this);
3346            $('option:selected', $this).each(function() {
3347                window.location.href = $(this).attr('data-g1-archive-filter-url');
3348            });
3349        });
3350    };
3351
3352})(jQuery);
3353
3354/****************
3355 *
3356 * Popup/Slideup
3357 *
3358 ****************/
3359
3360(function ($) {
3361    'use strict';
3362    g1.popup = function () {
3363		var
3364		HTMLBase          = $('html'),
3365		Popup             = $('.g1-popup-newsletter'),
3366		PopupCookie       = g1.readCookie('g1_popup_disabled'),
3367		PopupCloser       = $('.g1-popup-base, .g1-popup-closer');
3368		// If we dont have popup exit.
3369		if( PopupCookie ){ HTMLBase.addClass('exit-intent-disabled'); }
3370		if( Popup.length <= 0 ){ return; }
3371		$(document).on('mouseleave', function(e){
3372			if( e.clientY < 10 && ! HTMLBase.hasClass('exit-intent-disabled') && ! HTMLBase.hasClass('g1-slideup-visible') ){
3373				HTMLBase.addClass('g1-popup-visible').addClass('exit-intent-disabled');
3374			}
3375		});
3376		PopupCloser.on('click', function(e){
3377			e.preventDefault();
3378			HTMLBase.removeClass('g1-popup-visible');
3379	        g1.createCookie('g1_popup_disabled', 1, 24 * 60 * 60 * 1000);
3380		});
3381    }
3382    g1.slideup = function () {
3383		var
3384		HTMLBase           = $('html'),
3385		Slideup            = $('.g1-slideup-newsletter'),
3386		SlideupCloser      = $('.g1-slideup-newsletter-closer'),
3387		SlideupCookie      = g1.readCookie('g1_slideup_disabled'),
3388		ScrollPositon      = $(document).scrollTop(),
3389		ScrollTarget       = $('.single-post article .entry-content'),
3390		ScrollTargetOffset = ScrollTarget.offset(),
3391		ScrollTargetHeight = ScrollTarget.height(),
3392		ShowOn             = 50;
3393		// If we dont have popup exit.
3394		SlideupCloser.on('click', function(e){
3395			e.preventDefault();
3396			HTMLBase.removeClass('g1-slideup-visible').addClass('slideup-intent-disabled');
3397	        g1.createCookie('g1_slideup_disabled', 1, 24 * 60 * 60 * 1000);
3398		});
3399		if( SlideupCookie ){ HTMLBase.addClass('slideup-intent-disabled'); }
3400		if( Slideup.length <= 0 ){ return; }
3401		if( ScrollTarget.length <= 0 ){ return; }
3402		$(window).on('scroll', function(){
3403			ScrollPositon      = $(document).scrollTop();
3404			ScrollTargetOffset = ScrollTarget.offset();
3405			ScrollTargetHeight = ScrollTarget.height();
3406			if( ( (ScrollPositon - ScrollTargetOffset.top) / (ScrollTargetHeight) ).toFixed(6) * 100 >= ShowOn && ! HTMLBase.hasClass('slideup-intent-disabled') && ! HTMLBase.hasClass('g1-popup-visible') ){
3407				HTMLBase.addClass('g1-slideup-visible');
3408			}
3409		});
3410    }
3411})(jQuery);
3412
3413/****************
3414 *
3415 * GDPR
3416 *
3417 ****************/
3418
3419(function ($) {
3420    'use strict';
3421    $(document).ready(function () {
3422        $('.wp-social-login-provider-list').on('click', function() {
3423                if ($(this).hasClass('wp-social-login-provider-list-active')){
3424                    return;
3425                }
3426                $('.snax-wpsl-gdpr-consent').addClass('snax-wpsl-gdpr-consent-blink');
3427                setTimeout(function(){
3428                    $('.snax-wpsl-gdpr-consent').removeClass('snax-wpsl-gdpr-consent-blink');
3429                },
3430                2000);
3431        });
3432        $('.snax-wpsl-gdpr-consent input').on('click', function() {
3433            var enabled = $(this).is(':checked');
3434            if (enabled) {
3435                $('.wp-social-login-provider-list').addClass('wp-social-login-provider-list-active');
3436            } else {
3437                $('.wp-social-login-provider-list').removeClass('wp-social-login-provider-list-active');
3438            }
3439        });
3440    });
3441})(jQuery);
3442
3443/**************************
3444 *
3445 * WordPress Popular Posts
3446 *
3447 **************************/
3448
3449(function ($) {
3450
3451    'use strict';
3452
3453    g1.updatePostViews = function(nonce,postId) {
3454        $.ajax({
3455            'type': 'POST',
3456            'url': g1.config.ajax_url,
3457            'data': {
3458                'action':   'update_views_ajax',
3459                'wpp_id':   postId,
3460                'token':    nonce
3461            }
3462        });
3463    };
3464
3465    // ------------
3466    // Update views
3467    // ------------
3468
3469    $('.bimber-count-view').on('click', function() {
3470        var postId;
3471        var $body = $('body');
3472
3473        if ( $body.is('.single-format-link') ) {
3474            var res = $body.attr('class').match(/postid-(\d+)/);
3475
3476            if (res) {
3477                postId = res[1];
3478            }
3479        } else {
3480            var $article = $(this).parents('article.format-link');
3481
3482            if ( $article.length > 0 ) {
3483                postId = $article.attr('id').replace('post-', '');
3484            }
3485        }
3486
3487        if (postId) {
3488            $.ajax({
3489                'type': 'POST',
3490                'url': g1.config.ajax_url,
3491                'data': {
3492                    'action':   'bimber_update_post_views',
3493                    'post_id':   postId
3494                }
3495            });
3496        }
3497    });
3498
3499})(jQuery);
3500
3501/*******************
3502 *
3503 * Flickity
3504 *
3505 ******************/
3506
3507
3508(function ($) {
3509
3510    'use strict';
3511
3512    g1.flickity = function () {
3513        var
3514            FlickitySpots = $('.adace-shop-the-post-wrap.carousel-wrap .woocommerce .products, .g1-products-widget-carousel .product_list_widget');
3515        FlickitySpots.each(function () {
3516            if ($(this).hasClass('.flickity-enabled')) {
3517                return;
3518            }
3519            var
3520                ThisFlickityItems = $(this).children(),
3521                ThisFlickityItemsWidth = ThisFlickityItems.outerWidth() * ThisFlickityItems.length,
3522                ThisFlickityArgs = {
3523                    cellAlign: 'left',
3524                    wrapAround: true,
3525                    prevNextButtons: true,
3526                    pageDots: false,
3527                    groupCells: true,
3528                    rightToLeft: g1.isRTL(),
3529                    imagesLoaded: true
3530                };
3531            if (ThisFlickityItemsWidth <= $(this).outerWidth()) {
3532                ThisFlickityArgs.cellAlign = 'center';
3533                ThisFlickityArgs.wrapAround = false;
3534            } else {
3535                var ThisRequiredNumber = Math.round($(this).outerWidth() / ThisFlickityItems.outerWidth()) * ThisFlickityItems.length;
3536
3537                while (ThisFlickityItems.length < ThisRequiredNumber) {
3538                    $(this).append(ThisFlickityItems.clone(true));
3539                    ThisFlickityItems = $(this).children();
3540                }
3541            }
3542            $(this).flickity(ThisFlickityArgs);
3543        });
3544    };
3545
3546    $('body').on('g1NewContentLoaded', function () {
3547        g1.flickity();
3548    });
3549})(jQuery);
3550
3551
3552/*******************
3553 *
3554 * Skin Mode
3555 *
3556 ******************/
3557
3558
3559(function ($) {
3560
3561    'use strict';
3562
3563    g1.skinSwitcher = function () {
3564        if ( typeof g1SwitchSkin === 'undefined' ) {
3565            return;
3566        }
3567
3568        $('.g1-drop-the-skin').each( function() {
3569            var $this = $(this);
3570
3571            var $skinItemId = $('meta[name="g1:skin-item-id"]');
3572            var skinItemId = $skinItemId.length > 0 ? $skinItemId.attr('content')  : 'g1_skin';
3573
3574            if ( localStorage.getItem(skinItemId) ) {
3575                if ( $this.is( '.g1-drop-the-skin-light' ) ) {
3576                    $this.removeClass('g1-drop-nojs g1-drop-the-skin-light').addClass( 'g1-drop-the-skin-dark' );
3577                } else {
3578                    // Switch to the light mode.
3579                    $this.removeClass('g1-drop-nojs g1-drop-the-skin-dark').addClass( 'g1-drop-the-skin-light' );
3580                }
3581            } else {
3582                $this.removeClass('g1-drop-nojs');
3583            }
3584        });
3585
3586
3587        $('.g1-drop-the-skin').on( 'click', function() {
3588            var $this = $(this);
3589
3590            $this.addClass('g1-drop-the-skin-anim');
3591
3592            if ( $this.is( '.g1-drop-the-skin-light' ) ) {
3593                // Switch to the dark skin.
3594                $this.removeClass('g1-drop-the-skin-light').addClass( 'g1-drop-the-skin-dark' );
3595                g1SwitchSkin('dark');
3596
3597            } else {
3598                // Switch to the light skin.
3599                $this.removeClass('g1-drop-the-skin-dark').addClass( 'g1-drop-the-skin-light' );
3600                g1SwitchSkin('light');
3601            }
3602        });
3603    };
3604
3605})(jQuery);
3606
3607
3608/*******************
3609 *
3610 * NSFW Mode
3611 *
3612 ******************/
3613
3614
3615(function ($) {
3616
3617    'use strict';
3618
3619    g1.nsfwSwitcher = function () {
3620        if ( typeof g1SwitchNSFW === 'undefined' ) {
3621            return;
3622        }
3623
3624        $('.g1-drop-the-nsfw').each( function() {
3625            var $this = $(this);
3626
3627            var $nsfwItemId = $('meta[name="g1:nsfw-item-id"]');
3628            var nsfwtemId = $nsfwItemId.length > 0 ? $nsfwItemId.attr('content')  : 'g1_nsfw_off';
3629
3630            if ( localStorage.getItem(nsfwtemId) ) {
3631                $this.removeClass('g1-drop-the-nsfw-on').addClass( 'g1-drop-the-nsfw-off' );
3632            }
3633
3634        } );
3635
3636        $('.g1-drop-the-nsfw').on( 'click', function() {
3637            var $this = $(this);
3638
3639            if ( $this.is( '.g1-drop-the-nsfw-on' ) ) {
3640                $this.removeClass('g1-drop-the-nsfw-on').addClass( 'g1-drop-the-nsfw-off' );
3641                g1SwitchNSFW(1);
3642
3643            } else {
3644                $this.removeClass('g1-drop-the-nsfw-off').addClass( 'g1-drop-the-nsfw-on' );
3645                g1SwitchNSFW(0);
3646            }
3647        });
3648    };
3649
3650})(jQuery);
3651
3652
3653/**************************
3654 *
3655 * document ready functions (keep this at the end for better compatibillity with optimizing plugins)
3656 *
3657 *************************/
3658
3659(function ($) {
3660
3661    'use strict';
3662
3663    $(document).ready(function () {
3664        g1.uiHelpers();
3665
3666        if (g1.config.timeago === 'on') {
3667            g1.dateToTimeago();
3668        }
3669
3670        g1.backToTop();
3671        g1.loadMoreButton();
3672        g1.infiniteScroll();
3673        g1.gifPlayer();
3674        g1.featuredEntries();
3675        g1.shareContentElements();
3676        g1.customShareButtons();
3677        g1.customizeShareButtons();
3678        g1.bpProfileNav();
3679
3680        if (g1.config.sharebar === 'on') {
3681            g1.shareBar();
3682        }
3683
3684        g1.stickyPosition();
3685        g1.droppableElements();
3686        g1.canvas();
3687        g1.ajaxSearch();
3688        g1.isotope();
3689        g1.comments();
3690        g1.snax();
3691        g1.bpFollow();
3692        g1.mediaAce();
3693
3694        g1.flickity();
3695        g1.loadNextPost();
3696        g1.autoPlayVideo();
3697        g1.myCredNotifications();
3698        g1.archiveFilters();
3699        g1.popup();
3700        g1.slideup();
3701        g1.stickySidebar();
3702        g1.skinSwitcher();
3703        g1.nsfwSwitcher();
3704    });
3705
3706    $(window).load(function () {
3707        g1.mp4Player();
3708    });
3709
3710})(jQuery);
3711
3712
3713
3714
3715
3716
3717// BuddyPress Profile: get the first item-button before the dropdown
3718(function ($) {
3719    'use strict';
3720
3721    $(document).ready(function () {
3722        $('#item-buttons .g1-drop').each(function() {
3723            var $drop = $(this);
3724
3725            // Get the first element and place it before the dropdown.
3726            var firstItem = $drop.find('.menu-item:first').detach();
3727            if ( firstItem.length ) {
3728                // Adjust the HTML markup.
3729                firstItem.removeClass('menu-item').find('a').addClass('g1-button g1-button-simple g1-button-m');
3730                // Insert before the drop.
3731                firstItem.insertBefore($drop);
3732            }
3733
3734            // Remove empty dropdown.
3735            if ( ! $drop.find('.menu-item').length ) {
3736                $drop.remove();
3737            }
3738
3739        });
3740    } );
3741})(jQuery);
3742
3743
3744
3745// Sticky off-canvas top offset adjustments.
3746(function ($) {
3747    'use strict';
3748
3749    $(document).ready(function () {
3750        var selectors = [
3751            '#wpadminbar',
3752            '.g1-iframe-bar',
3753            '.g1-sticky-top-wrapper'
3754        ];
3755
3756        var applyOffset = function() {
3757            // Calculate the total height of all sticky elements.
3758            var topOffset = 0;
3759            for (var i = 0; i < selectors.length; i++) {
3760                var $elem = $(selectors[i]);
3761
3762                if ($elem.length > 0 && $elem.is(':visible')) {
3763                    topOffset += $elem.outerHeight();
3764                }
3765            }
3766
3767
3768            var cssRule = 'html.g1-off-inside.g1-off-global-desktop .g1-canvas {top:' + topOffset + 'px;'
3769
3770            $('#g1-canvas-js-css').remove();
3771            $('head').append( '<style id="g1-canvas-js-css">' + cssRule + '</style>' );
3772            $('html.g1-off-inside .g1-canvas').removeClass('g1-canvas-no-js').addClass('g1-canvas-js');
3773        };
3774
3775        $('body').on( 'g1PageHeightChanged', function(e) {
3776            applyOffset();
3777        } );
3778
3779        $('html.g1-off-inside .g1-canvas.g1-canvas-no-js').each(function() {
3780            applyOffset();
3781        });
3782    } );
3783})(jQuery);

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.