|
18 | 18 | afterOpen: null, |
19 | 19 | afterClose: null, |
20 | 20 | loopAtEnd: false, |
21 | | - autoplayVideos: false |
| 21 | + autoplayVideos: false, |
| 22 | + queryStringData: {} |
22 | 23 | }, |
23 | 24 |
|
24 | 25 | plugin = this, |
|
727 | 728 |
|
728 | 729 | }, |
729 | 730 |
|
| 731 | + /** |
| 732 | + * Parse URI querystring and: |
| 733 | + * - overrides value provided via dictionary |
| 734 | + * - rebuild it again returning a string |
| 735 | + */ |
| 736 | + parseUri : function (uri, customData) { |
| 737 | + var a = document.createElement('a'), |
| 738 | + qs = {}; |
| 739 | + |
| 740 | + // Decode the URI |
| 741 | + a.href = decodeURIComponent( uri ); |
| 742 | + |
| 743 | + // QueryString to Object |
| 744 | + qs = JSON.parse( a.search.toLowerCase().replace('?','').replace(/&/g,'","').replace(/=/g,'":"') ); |
| 745 | + |
| 746 | + // Extend with custom data |
| 747 | + if ( $.isPlainObject( customData ) ) { |
| 748 | + qs = $.extend( qs, customData, plugin.settings.queryStringData ); // The dev has always the final word |
| 749 | + } |
| 750 | + |
| 751 | + // Return querystring as a string |
| 752 | + return $ |
| 753 | + .map( qs, function (val, key) { |
| 754 | + if ( val && val > '' ) { |
| 755 | + return encodeURIComponent( key ) + '=' + encodeURIComponent( val ); |
| 756 | + } |
| 757 | + }) |
| 758 | + .join('&'); |
| 759 | + }, |
| 760 | + |
730 | 761 | /** |
731 | 762 | * Get video iframe code from URL |
732 | 763 | */ |
733 | 764 | getVideo : function( url ) { |
734 | 765 | var iframe = '', |
735 | 766 | youtubeUrl = url.match( /watch\?v=([a-zA-Z0-9\-_]+)/ ), |
736 | 767 | youtubeShortUrl = url.match(/youtu\.be\/([a-zA-Z0-9\-_]+)/), |
737 | | - vimeoUrl = url.match( /vimeo\.com\/([0-9]*)/ ); |
| 768 | + vimeoUrl = url.match( /vimeo\.com\/([0-9]*)/ ), |
| 769 | + qs = ''; |
738 | 770 | if ( youtubeUrl || youtubeShortUrl) { |
739 | 771 | if ( youtubeShortUrl ) { |
740 | 772 | youtubeUrl = youtubeShortUrl; |
741 | 773 | } |
742 | | - iframe = '<iframe width="560" height="315" src="//www.youtube.com/embed/' + youtubeUrl[1] + '?autoplay='+ plugin.settings.autoplayVideos + '" frameborder="0" allowfullscreen></iframe>'; |
| 774 | + qs = ui.parseUri( url, { |
| 775 | + 'autoplay' : ( plugin.settings.autoplayVideos ? '1' : '0' ), |
| 776 | + 'v' : '' |
| 777 | + }); |
| 778 | + iframe = '<iframe width="560" height="315" src="//www.youtube.com/embed/' + youtubeUrl[1] + '?' + qs + '" frameborder="0" allowfullscreen></iframe>'; |
743 | 779 |
|
744 | 780 | } else if ( vimeoUrl ) { |
745 | | - |
746 | | - iframe = '<iframe width="560" height="315" src="//player.vimeo.com/video/' + vimeoUrl[1] + '?byline=0&portrait=0&color=' + plugin.settings.vimeoColor + '&autoplay=' + plugin.settings.autoplayVideos + '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; |
747 | | - |
748 | | - } |
749 | | - |
750 | | - if ( youtubeUrl || youtubeShortUrl || vimeoUrl ) { |
| 781 | + qs = ui.parseUri( url, { |
| 782 | + 'autoplay' : ( plugin.settings.autoplayVideos ? '1' : '0' ), |
| 783 | + 'byline' : '0', |
| 784 | + 'portrait' : '0', |
| 785 | + 'color': plugin.settings.vimeoColor |
| 786 | + }); |
| 787 | + iframe = '<iframe width="560" height="315" src="//player.vimeo.com/video/' + vimeoUrl[1] + '?' + qs + '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; |
751 | 788 |
|
752 | 789 | } else { |
753 | 790 | iframe = '<iframe width="560" height="315" src="' + url + '" frameborder="0" allowfullscreen></iframe>'; |
|
0 commit comments