PageSourceSearch

https://www.marqueze.net/wp-content/themes/bimber/js/front.js?ver=6.1

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