1/****************** 2 * 3 * Init GIF Player 4 * 5 *****************/ 6 7(function ($) { 8 9 'use strict'; 10 var isEnabled = g1.config.use_gif_player; 11 12 g1.gifPlayer = function ($scope) { 13 if ( ! isEnabled ) { 14 return; 15 } 16 if (! $scope ) { 17 $scope = $('body'); 18 } 19 20 // SuperGif library depends on the overrideMimeType method of the XMLHttpRequest object 21 // if browser doesn't support this method, we can't use that library 22 if ( typeof XMLHttpRequest.prototype.overrideMimeType === 'undefined' ) { 23 return; 24 } 25 26 g1.gifPlayerIncludeSelectors =[ 27 '.entry-content img.aligncenter[src$=".gif"]', 28 '.entry-content .aligncenter img[src$=".gif"]', 29 'img.g1-enable-gif-player', 30 '.entry-featured-media-main img[src$=".gif"]', 31 '.entry-tpl-stream .entry-featured-media img[src$=".gif"]', 32 '.entry-tpl-grid-l .entry-featured-media img[src$=".gif"]' 33 ]; 34 35 g1.gifPlayerExcludeSelectors = [ 36 '.ajax-loader', // for Contact Form 7 37 '.g1-disable-gif-player', 38 '.wp-block-image.g1-disable-gif-player img[src$=".gif"]' 39 ]; 40 41 $( g1.gifPlayerIncludeSelectors.join(','), $scope ).not( g1.gifPlayerExcludeSelectors.join(',') ).each(function () { 42 var $img = $(this); 43 var imgClasses = $img.attr('class'); 44 var imgSrc = $img.attr('src'); 45 46 // Check only absolute paths. Relative paths, by nature, are from the same domain. 47 // Seems like the GIFs from outside of the site's domain work too. 48 // if (-1 !== imgSrc.indexOf('http')) { 49 // // Only locally stored gifs, unless user decided otherwise. 50 // if (imgSrc.indexOf(location.hostname) === -1 && !$img.is('.g1-enable-gif-player')) { 51 // return; 52 // } 53 // } 54 55 56 var gifObj = new SuperGif({ 57 gif: this, 58 auto_play: 0 59 }); 60 61 var $gitIndicator = $('<span class="g1-indicator-gif g1-loading">'); 62 63 gifObj.load(function() { 64 var frames = gifObj.get_length(); 65 66 var $canvasWrapper = $(gifObj.get_canvas()).parent(); 67 68 // Only for animated gifs. 69 if (frames > 1) { 70 gifObj.isPlaying = false; 71 72 // Store references to original methods. 73 var playRef = gifObj.play; 74 var pauseRef = gifObj.pause; 75 76 var playGif = function() { 77 playRef(); 78 gifObj.isPlaying = true; 79 $gitIndicator.addClass('g1-indicator-gif-playing'); 80 }; 81 82 var pauseGif = function() { 83 pauseRef(); 84 gifObj.isPlaying = false; 85 $gitIndicator.removeClass('g1-indicator-gif-playing'); 86 }; 87 88 // Override and extend the API. 89 gifObj.play = playGif; 90 gifObj.pause = pauseGif; 91 92 // Play/stop the GIF. 93 $canvasWrapper.on('click', function(e) { 94 // Prevent redirecting to single post. 95 e.preventDefault(); 96 97 if (gifObj.isPlaying) { 98 pauseGif(); 99 } else { 100 playGif(); 101 } 102 }); 103 104 $gitIndicator.toggleClass('g1-loading g1-loaded'); 105
106 $(document).trigger('bimberGifPlayerLoaded', [$canvasWrapper]); 107 } else { 108 // It's just a gif type image, not animation to play. 109 $gitIndicator.remove(); 110 } 111 }); 112 113 // canvas parent can be fetched after gifObj.load() call 114 var $canvasWrapper = $(gifObj.get_canvas()).parent(); 115 116 $canvasWrapper. 117 addClass(imgClasses + ' g1-enable-share-links'). 118 attr('data-img-src', imgSrc). 119 append($gitIndicator). 120 data('gifPlayer', gifObj); 121 }); 122 }; 123 124 // Listeners. 125 $('body').on('g1NewContentLoaded', function(e, $newContent) { 126 g1.gifPlayer($newContent); 127 }); 128 129})(jQuery); 130 131/************************ 132 * 133 * Media Players Factory 134 * 135 ***********************/ 136 137(function ($) { 138 139 'use strict'; 140 141 var selectors = { 142 'iframe': 'iframe', 143 'mp4': '.mejs-video', 144 'gif': '.jsgif', 145 'html5Video': '.snax-native-video', 146 'embedly': '.embedly-card iframe', 147 'maceYT': '.mace-youtube' 148 }; 149 150 g1.mediaPlayers = {}; 151 152 g1.getMediaPlayer = function(element) { 153 var player = $(element).data('g1MediaPlayer'); 154 155 if (player) { 156 g1.log('Returning a player (' + player.getType() + ') assigned to the element.'); 157 return player; 158 } 159 160 // IFRAME. 161 var $iframe = $(selectors.iframe, element); 162 163 if ($iframe.length > 0) { 164 var iframesrc = false; 165 166 if ($iframe.attr('data-src')) { 167 iframesrc = $iframe.attr('data-src'); 168 } else { 169 iframesrc= $iframe.attr('src'); 170 } 171 172 if (iframesrc) { 173 // YouTube? 174 if (iframesrc.indexOf('youtu') > 0) { 175 player = g1.mediaPlayers.youtube($iframe); 176 $(element).data('g1MediaPlayer', player); 177 178 return player; 179 } 180 181 // Vimeo? 182 if (iframesrc.indexOf('vimeo') > 0) { 183 player = g1.mediaPlayers.vimeo($iframe); 184 $(element).data('g1MediaPlayer', player); 185 186 return player; 187 } 188 189 // Dailymotion? 190 if (iframesrc.indexOf('dailymotion') > 0) { 191 player = g1.mediaPlayers.dailymotion($iframe); 192 $(element).data('g1MediaPlayer', player); 193 194 return player; 195 } 196 197 // Gfycat? 198 if (iframesrc.indexOf('gfycat') > 0) { 199 player = g1.mediaPlayers.gfycat($iframe); 200 $(element).data('g1MediaPlayer', player); 201 202 return player; 203 } 204 205 206 } 207 208 209 return false; 210 } 211 212 // MP4. 213 var $mp4 = $(selectors.mp4, element); 214 215 if ($mp4.length > 0) { 216 var playerId = $mp4.attr('id'); 217 218 if (playerId && mejs && typeof mejs.players !== 'undefined') { 219 if (typeof mejs.players[playerId] !== 'undefined') { 220 var mejsPlayer = mejs.players[playerId]; 221 player = g1.mediaPlayers.mp4(mejsPlayer); 222 223 $(element).data('g1MediaPlayer', player); 224 225 return player; 226 } 227 } 228 229 return false; 230 } 231 232 // GIF. 233 var $gif = $(selectors.gif, element); 234 235 if ($gif.length > 0) { 236 var gifPlayer = $gif.data('gifPlayer'); 237 238 if (gifPlayer) { 239 player = g1.mediaPlayers.gif(gifPlayer); 240 241 $(element).data('g1MediaPlayer', player); 242 243 return player; 244 } 245 246 return false; 247 } 248 249 // MediaAce Lazy Loaded video. 250 var $maceYT = $(selectors.maceYT, element); 251 252 // HTML5 native videos. 253 var $html5 = $(selectors.html5Video, element); 254 255 if ( $html5.length > 0 ) { 256 player = g1.mediaPlayers.html5video($html5[0]); 257 258 $(element).data('g1MediaPlayer', player); 259 260 return player; 261 } 262 263 // Embedly. 264 if (typeof embedly !== 'undefined') { 265 var $embedly = $(selectors.embedly, element); 266 267 if ($embedly.length > 0 ) { 268 // The following iterates over all the instances of the player. 269 embedly('player', function(embedlyPlayer){ 270 if ($embedly[0] === $(embedlyPlayer.frame.elem)[0]) { 271 player = g1.mediaPlayers.embedly(embedlyPlayer); 272 273 $(element).data('g1MediaPlayer', player); 274 275 return player; 276 } else { 277 player.pause(); 278 } 279 }); 280 281 return false;
282 } else { 283 embedly('player', function(player){ 284 player.pause(); 285 }); 286 } 287 } 288 289 // MediaAce YouTube lazy loader. 290 if ($maceYT.length > 0) { 291 // Start to load YouTube player. 292 $maceYT.find('.mace-play-button').trigger('click'); 293 294 // YouTube player (iframe) loaded. 295 $maceYT.on('maceIframeLoaded', function(e, $iframe) { 296 // Get YT player to initialize YT properly. 297 player = g1.getMediaPlayer($maceYT); 298 299 // Assign the player to the element. 300 $(element).data('g1MediaPlayer', player); 301 }); 302 303 // We don't want to return an instance of the MaceYT player here, as the MaceYT is just a wrapper for YT player. 304 // So we return false here and wait for YT iframe. When it's loaded, we assigned the YT player to the element. 305 return false; 306 } 307 }; 308 309})(jQuery); 310 311/******************* 312 * 313 * YouTube Player 314 * 315 ******************/ 316 317(function ($) { 318 319 'use strict'; 320 321 g1.mediaPlayers.youtube = function ($iframe) { 322 let obj = {}; 323 let isPlaying = false; 324 325 function init() { 326 g1.log('YouTube player object initialized'); 327 328 $iframe.on('load', function() { 329 // Mute on load. 330 $iframe[0].contentWindow.postMessage(JSON.stringify({ 331 'event': 'command', 332 'func': 'mute', 333 'args': ''}), 334 '*'); 335 }); 336 337 let iframesrc = ''; 338 let separator = '?'; 339 340 if ($iframe.attr('data-src')) { 341 iframesrc = $iframe.attr('data-src'); 342 } else { 343 iframesrc = $iframe.attr('src'); 344 } 345 346 if (iframesrc.indexOf('?') > 0){ 347 separator = '&'; 348 } 349 350 // Trigger the "load" event, with new params. 351 $iframe.attr('src', iframesrc + separator + 'autoplay=1&enablejsapi=1&loop=1'); 352 353 return obj; 354 } 355 356 obj.getType = function() { 357 return 'YouTube'; 358 }; 359 360 obj.play = function () { 361 $iframe[0].contentWindow.postMessage(JSON.stringify({ 362 'event': 'command', 363 'func': 'playVideo', 364 'args': ''}), 365 '*'); 366 367 isPlaying = true; 368 }; 369 370 obj.pause = function () { 371 $iframe[0].contentWindow.postMessage(JSON.stringify({ 372 'event': 'command', 373 'func': 'pauseVideo', 374 'args': ''}), 375 '*'); 376 377 isPlaying = false; 378 }; 379 380 obj.isPlaying = function() { 381 return isPlaying; 382 }; 383 384 return init(); 385 }; 386 387})(jQuery); 388 389/******************* 390 * 391 * Vimoe Player 392 * 393 ******************/ 394 395(function ($) { 396 397 'use strict'; 398 399 g1.mediaPlayers.vimeo = function ($iframe) { 400 let obj = {}; 401 let isPlaying = false; 402 403 function init() { 404 g1.log('Vimeo player object initialized'); 405 406 $iframe.on('load', function() { 407 $iframe[0].contentWindow.postMessage(JSON.stringify({ 408 method: 'setVolume', 409 value: 0 410 }), '*'); 411 }); 412 413 let iframesrc = ''; 414 let separator = '?'; 415 416 if ($iframe.attr('data-src')) { 417 iframesrc = $iframe.attr('data-src'); 418 } else { 419 iframesrc = $iframe.attr('src'); 420 } 421 422 if (iframesrc.indexOf('?') > 0){ 423 separator = '&'; 424 } 425 426 $iframe.attr('src', iframesrc + separator + 'autoplay=1&autopause=0'); 427 428 return obj; 429 } 430 431 obj.getType = function() { 432 return 'Vimeo'; 433 }; 434 435 obj.play = function () { 436 $iframe[0].contentWindow.postMessage(JSON.stringify({ 437 method: 'play' 438 }), '*'); 439 440 isPlaying = true; 441 }; 442 443 obj.pause = function () { 444 $iframe[0].contentWindow.postMessage(JSON.stringify({ 445 method: 'pause' 446 }), '*'); 447 448 isPlaying = false;
449 }; 450 451 obj.isPlaying = function() { 452 return isPlaying; 453 }; 454 455 return init(); 456 }; 457 458})(jQuery); 459 460/******************* 461 * 462 * DailyMotion Player 463 * 464 ******************/ 465 466(function ($) { 467 468 'use strict'; 469 470 g1.mediaPlayers.dailymotion = function ($iframe) { 471 let obj = {}; 472 let isPlaying = false; 473 474 function init() { 475 g1.log('DailyMotion player object initialized'); 476 477 // Mute on load. 478 let iframesrc = ''; 479 let separator = '?'; 480 481 if ($iframe.attr('data-src')) { 482 iframesrc = $iframe.attr('data-src'); 483 } else { 484 iframesrc = $iframe.attr('src'); 485 } 486 487 if (iframesrc.indexOf('?') > 0){ 488 separator = '&'; 489 } 490 491 $iframe.attr('src', iframesrc + separator + 'autoplay=1&api=postMessage&mute=1'); 492 493 return obj; 494 } 495 496 obj.getType = function() { 497 return 'DailyMotion'; 498 }; 499 500 obj.play = function () { 501 $iframe[0].contentWindow.postMessage('play', '*'); 502 503 isPlaying = true; 504 }; 505 506 obj.pause = function () { 507 $iframe[0].contentWindow.postMessage('pause', '*'); 508 509 isPlaying = false; 510 }; 511 512 obj.isPlaying = function() { 513 return isPlaying; 514 }; 515 516 return init(); 517 }; 518 519})(jQuery); 520 521/******************* 522 * 523 * Gfycat Player 524 * 525 ******************/ 526 527(function ($) { 528 529 'use strict'; 530 531 g1.mediaPlayers.gfycat = function ($iframe) { 532 let obj = {}; 533 let isPlaying = false; 534 535 function init() { 536 g1.log('Gfycat player object initialized'); 537 return obj; 538 } 539 540 obj.getType = function() { 541 return 'Gfycat'; 542 }; 543 544 obj.play = function () { 545 $iframe[0].contentWindow.postMessage('play', '*'); 546 547 isPlaying = true; 548 }; 549 550 obj.pause = function () { 551 $iframe[0].contentWindow.postMessage('pause', '*'); 552 553 isPlaying = false; 554 }; 555 556 obj.isPlaying = function() { 557 return isPlaying; 558 }; 559 560 return init(); 561 }; 562 563})(jQuery); 564 565/******************* 566 * 567 * MP4 Player 568 * 569 ******************/ 570 571(function ($) { 572 573 'use strict'; 574 575 g1.mediaPlayers.mp4 = function (mejsPlayer) { 576 let obj = {}; 577 let isPlaying = false; 578 579 function init() { 580 g1.log('MP4 player initialized'); 581 582 // Start muted. 583 mejsPlayer.setMuted(true); 584 585 // Play in loop. 586 mejsPlayer.media.addEventListener('ended', function() { 587 mejsPlayer.play(); 588 }, false); 589 590 return obj; 591 } 592 593 obj.getType = function() { 594 return 'MP4'; 595 }; 596 597 obj.play = function() { 598 mejsPlayer.play(); 599 600 isPlaying = true; 601 }; 602 603 obj.pause = function() { 604 mejsPlayer.pause(); 605 606 isPlaying = false; 607 }; 608 609 obj.isPlaying = function() { 610 return isPlaying; 611 }; 612 613 return init(); 614 }; 615 616})(jQuery); 617 618/******************* 619 * 620 * GIF Player 621 * 622 ******************/ 623 624(function ($) { 625 626 'use strict'; 627 628 g1.mediaPlayers.gif = function (gifPlayer) { 629 let obj = {}; 630 631 function init() { 632 g1.log('GIF player initialized'); 633 634 return obj; 635 } 636 637 obj.getType = function() { 638 return 'GIF'; 639 }; 640 641 obj.play = function() { 642 gifPlayer.play(); 643 }; 644 645 obj.pause = function() { 646 gifPlayer.pause(); 647 }; 648 649 obj.isPlaying = function() { 650 return gifPlayer.isPlaying; 651 }; 652 653 return init(); 654 }; 655 656})(jQuery); 657 658/******************* 659 * 660 * HTML Video Player 661 * 662 ******************/ 663 664(function ($) { 665 666 'use strict'; 667 668 g1.mediaPlayers.html5video = function (video) { 669 let obj = {}; 670 let isPlaying = false; 671 672 function init() { 673 g1.log('HTML5 Video player initialized'); 674 675 return obj; 676 } 677 678 obj.getType = function() { 679 return 'HTML5 Video'; 680 }; 681 682 obj.play = function() { 683 video.play(); 684 685 isPlaying = true; 686 }; 687 688 obj.pause = function() { 689 video.pause(); 690 691 isPlaying = false;
692 }; 693 694 obj.isPlaying = function() { 695 return isPlaying; 696 }; 697 698 return init(); 699 }; 700 701})(jQuery); 702 703/******************* 704 * 705 * Embedly Player 706 * 707 ******************/ 708 709(function ($) { 710 711 'use strict'; 712 713 g1.mediaPlayers.embedly = function (embedlyPlayer) { 714 let obj = {}; 715 let isPlaying = false; 716 717 function init() { 718 g1.log('Embedly player initialized'); 719 720 embedlyPlayer.mute(); 721 722 return obj; 723 } 724 725 obj.getType = function() { 726 return 'Embedly'; 727 }; 728 729 obj.play = function() { 730 embedlyPlayer.play(); 731 732 isPlaying = true; 733 }; 734 735 obj.pause = function() { 736 embedlyPlayer.pause(); 737 738 isPlaying = false; 739 }; 740 741 obj.isPlaying = function() { 742 return isPlaying; 743 }; 744 745 return init(); 746 }; 747 748})(jQuery); 749 750 751/********************** 752/********************** 753 * 754 * Auto Play Controller 755 * 756 ********************** 757 **********************/ 758 759(function ($) { 760 761 'use strict'; 762 763 var selectors = { 764 'postMedia': '.archive-body-stream .entry-tpl-stream .entry-featured-media:not(.entry-media-nsfw-embed)' 765 }; 766 767 // Due to varied autoplay browsers' policies, it's almost impossible to guarantee autoplying on mobiles, so we turn it off. 768 g1.isAutoPlayEnabled = g1.config.auto_play_videos && ! g1.isTouchDevice(); 769 770 var players = {}; // Initialized players. 771 772 g1.autoPlayVideo = function () { 773 if ( ! g1.isAutoPlayEnabled ) { 774 return; 775 } 776 777 var pauseAllVideos = function() { 778 g1.log('Pausing all videos'); 779 780 for(var i in players) { 781 players[i].pause(); 782 } 783 }; 784 785 var play = function(element) { 786 var postId = $(element).parents('article').attr('id'); 787 788 g1.log('Trying to play media...'); 789 790 var player = g1.getMediaPlayer(element); 791 792 if (!player) { 793 g1.log('Media player not defined for the element'); 794 return; 795 } 796 797 // Before playing this video we want to make sure that others video are paused too. 798 pauseAllVideos(); 799 800 player.play(); 801 802 g1.log(player.getType() + ' played'); 803 804 // Store reference. 805 if (!players[postId]) { 806 players[postId] = player; 807 } 808 }; 809 810 var pause = function (element) { 811 g1.log('Trying to pause media...'); 812 813 var player = g1.getMediaPlayer(element); 814 815 if (!player) { 816 g1.log('Media player not defined for the element'); 817 return; 818 } 819 820 player.pause(); 821 822 g1.log(player.getType() + ' paused'); 823 }; 824 825 var bindEvents = function() { 826 827 // Delay waypoint. User scroll activate events. 828 var scrollEvents = 0; 829 var allowPlaying = false; 830 831 // Wait for user scroll. Not scroll event while page loading. 832 $(document).scroll(function() { 833 scrollEvents++; 834 835 if (scrollEvents > 5) { 836 allowPlaying = true; 837 } 838 }); 839 840 // ENTER, while up to down scrolling. 841 $(selectors.postMedia).waypoint(function(direction) { 842 if ('down' === direction) { 843 if (allowPlaying) { 844 g1.log([ '>>> ENTER post (direction: DOWN)', this.element ] ); 845 846 play(this.element); 847 } 848 849 } 850 }, { 851 // When the bottom of the element hits the bottom of the viewport. 852 offset: 'bottom-in-view' 853 }); 854 855 // ENTER, while down to up scrolling. 856 $(selectors.postMedia).waypoint(function(direction) { 857 if ('up' === direction) { 858 if (allowPlaying) { 859 g1.log([ '>>> ENTER post (direction: UP)', this.element ] ); 860 861 play(this.element); 862 } 863 } 864 }, { 865 // When the top of the element hits the top of the viewport. 866 offset: '0' 867 }); 868 869 // EXIT, while up to down scrolling. 870 $(selectors.postMedia).waypoint(function(direction) { 871 if ('down' === direction) { 872 g1.log([ '>>> EXIT post (direction: DOWN)', this.element ] ); 873 874 pause(this.element); 875 } 876 }, { 877 offset: function() { 878 // Fires when top of the element is (HALF OF ELEMENT HEIGHT)px from the top of the window. 879 return -Math.round(this.element.clientHeight / 2); 880 } 881 }); 882 883 // EXIT, while down to up scrolling. 884 $(selectors.postMedia).waypoint(function(direction) { 885 if ('up' === direction) { 886 g1.log([ '>>> EXIT post (direction: UP)', this.element ] ); 887 888 pause(this.element); 889 } 890 }, { 891 offset: function() {
892 var viewportHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0); 893 894 // Fires when top of the element is (HALF OF ELEMENT HEIGHT)px from the bottom of the window. 895 return viewportHeight - Math.round(this.element.clientHeight / 2); 896 } 897 }); 898 899 // Play on demand. 900 $(selectors.postMedia).on('bimber:play', function() { 901 g1.log([ '>>> PLAY ', $(this).get(0) ] ); 902 903 play($(this).get(0)); 904 }); 905 906 // Pause on demand. 907 $(selectors.postMedia).on('bimber:pause', function() { 908 g1.log([ '>>> PAUSE ', $(this).get(0) ] ); 909 910 pause($(this).get(0)); 911 }); 912 }; 913 914 bindEvents(); 915 }; 916 917})(jQuery); 918 919/************************** 920 * 921 * document ready functions (keep this at the end for better compatibillity with optimizing plugins) 922 * 923 *************************/ 924 925(function ($) { 926 927 'use strict'; 928 929 $(document).ready(function () { 930 // Init GIF player. 931 g1.gifPlayer(); 932 933 // Init videos auto load on scroll. 934 g1.autoPlayVideo(); 935 }); 936 937})(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.