|
654 | 654 | addVerticalNavigation();
|
655 | 655 | }
|
656 | 656 |
|
| 657 | + enableYoutubeAPI(); |
| 658 | + enableVidemoAPI(); |
| 659 | + |
657 | 660 | if(options.scrollOverflow){
|
658 | 661 | if(document.readyState === 'complete'){
|
659 | 662 | createSlimScrollingHandler();
|
|
838 | 841 | afterRenderActions();
|
839 | 842 | }
|
840 | 843 |
|
| 844 | + /* |
| 845 | + * Enables the Youtube videos API so we can control their flow if necessary. |
| 846 | + */ |
| 847 | + function enableYoutubeAPI(){ |
| 848 | + container.find('iframe[src*="youtube.com/embed/"]').each(function(){ |
| 849 | + var sign = getUrlParamSign($(this).attr('src')); |
| 850 | + $(this).attr('src', $(this).attr('src') + sign + 'enablejsapi=1'); |
| 851 | + }); |
| 852 | + } |
| 853 | + |
| 854 | + /* |
| 855 | + * Enables the Vimeo videos API so we can control their flow if necessary. |
| 856 | + */ |
| 857 | + function enableVidemoAPI(){ |
| 858 | + container.find('iframe[src*="player.vimeo.com/"]').each(function(){ |
| 859 | + var sign = getUrlParamSign($(this).attr('src')); |
| 860 | + $(this).attr('src', $(this).attr('src') + sign + 'api=1'); |
| 861 | + }); |
| 862 | + } |
| 863 | + |
| 864 | + /* |
| 865 | + * Returns the prefix sign to use for a new parameter in an existen URL. |
| 866 | + * |
| 867 | + * @return {String} ? | & |
| 868 | + */ |
| 869 | + function getUrlParamSign(url){ |
| 870 | + return ( !/\?/.test( url ) ) ? '?' : '&'; |
| 871 | + } |
| 872 | + |
841 | 873 | /**
|
842 | 874 | * Actions and callbacks to fire afterRender
|
843 | 875 | */
|
|
1534 | 1566 | destiny.find('video, audio').each(function(){
|
1535 | 1567 | var element = $(this).get(0);
|
1536 | 1568 |
|
1537 |
| - if( element.hasAttribute('autoplay') && typeof element.play === 'function' ) { |
| 1569 | + if( element.hasAttribute('data-autoplay') && typeof element.play === 'function' ) { |
1538 | 1570 | element.play();
|
1539 | 1571 | }
|
1540 | 1572 | });
|
| 1573 | + |
| 1574 | + //youtube videos |
| 1575 | + destiny.find('iframe[src*="youtube.com/embed/"]').each(function(){ |
| 1576 | + var element = $(this).get(0); |
| 1577 | + |
| 1578 | + if( /youtube\.com\/embed\//.test($(this).attr('src')) && element.hasAttribute('data-autoplay')){ |
| 1579 | + element.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*'); |
| 1580 | + } |
| 1581 | + }); |
1541 | 1582 | }
|
1542 | 1583 |
|
1543 | 1584 | /**
|
|
1550 | 1591 | destiny.find('video, audio').each(function(){
|
1551 | 1592 | var element = $(this).get(0);
|
1552 | 1593 |
|
1553 |
| - if( !element.hasAttribute('data-ignore') && typeof element.pause === 'function' ) { |
| 1594 | + if( !element.hasAttribute('data-keepplaying') && typeof element.pause === 'function' ) { |
1554 | 1595 | element.pause();
|
1555 | 1596 | }
|
1556 | 1597 | });
|
| 1598 | + |
| 1599 | + //youtube videos |
| 1600 | + destiny.find('iframe[src*="youtube.com/embed/"]').each(function(){ |
| 1601 | + var element = $(this).get(0); |
| 1602 | + |
| 1603 | + if( /youtube\.com\/embed\//.test($(this).attr('src')) && !element.hasAttribute('data-keepplaying')){ |
| 1604 | + $(this).get(0).contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}','*'); |
| 1605 | + } |
| 1606 | + }); |
1557 | 1607 | }
|
1558 | 1608 |
|
1559 | 1609 | /**
|
|
0 commit comments