├── .gitignore ├── README.md ├── plugin └── youtube.rb └── sass └── custom └── _rve.scss /.gitignore: -------------------------------------------------------------------------------- 1 | _site/ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | jekyll-youtube-lazyloading 2 | ========================== 3 | 4 | This Jekill/Octopress plugin improves the responsiveness on page that embed many youtube iframe by delaying the iframe creation until the user clicks on the video 5 | 6 | ## How to use it 7 | 8 | add a ```{% youtube %}``` in your markdown page 9 | 10 | ## Demo 11 | 12 | see [this page for a demo](http://erossignon.github.com/blog/2012/11/22/10-awsome-applications-with-raspberry-pi/) 13 | 14 | 15 | ## How to install it ? 16 | 17 | 1. Add ```gem 'yt'``` to your ```Gemfile``` and run ```Bundle``` 18 | 2. Add [your Youtube API key](https://github.com/Fullscreen/yt#apps-that-do-not-require-user-interactions) to your ```_config.yml``` file: 19 | 20 | ``` 21 | youtube: 22 | api_key: 23 | ``` 24 | 3. Add ```youtube.rb``` to your ```plugin``` folder 25 | 4. Copy ```_rve.sccs``` to ```/sass/custom``` 26 | 5. Add ```@import "custom/rve"``` to ```/sass/screen.scss``` 27 | 28 | ## Credits 29 | 30 | Thanks go to Anders M. Andersen for his [blogpost about responsive embeds](http://amobil.se/2011/11/responsive-embeds/) and to Portway Point for their [Jekyll Youtube Liquid Template Tag Gist](http://www.portwaypoint.co.uk/jekyll-youtube-liquid-template-tag-gist/) 31 | 32 | Thanks to [Fullscreen](http://www.fullscreen.com/) for [yt](https://github.com/Fullscreen/yt), "The reliable YouTube API Ruby client". 33 | 34 | ## Endorsement 35 | 36 | If you like it feel free to endorse me: [![](http://api.coderwall.com/erossignon/endorsecount.png)](http://coderwall.com/erossignon) 37 | -------------------------------------------------------------------------------- /plugin/youtube.rb: -------------------------------------------------------------------------------- 1 | # (c) Etienne Rossignon 2 | # Licence : MIT 3 | # 4 | # https://github.com/erossignon/jekyll-youtube-lazyloading 5 | # 6 | # this liquid plugin insert a embeded youtube video to your octopress or Jekill blog 7 | # using the following syntax: 8 | # {% youtube ABCDEF123 %} 9 | # 10 | # this plugin has been designed to optimize loading time when many youtube videos 11 | # are inserted to a single page by delaying the youtube ") 102 | 103 | # with jQuery 104 | #@onclick = "$('##{@id}').replaceWith('#{@videoFrame}');return false;" 105 | 106 | # without JQuery 107 | @onclick = "var myAnchor = document.getElementById('#{@id}');" + 108 | "var tmpDiv = document.createElement('div');" + 109 | "tmpDiv.innerHTML = '#{@videoFrame}';" + 110 | "myAnchor.parentNode.replaceChild(tmpDiv.firstChild, myAnchor);"+ 111 | "return false;" 112 | 113 | # note: so special care is required to produce html code that will not be massage by the 114 | # markdown processor : 115 | # extract from the markdown doc : 116 | # 'The only restrictions are that block-level HTML elements � e.g.
, ,
, 

, etc. 117 | # must be separated from surrounding content by blank lines, and the start and end tags of the block 118 | # should not be indented with tabs or spaces. ' 119 | result = <<-EOF 120 | 121 |

122 | 123 | 124 | 125 | 126 |
#{@video_data['description']}
127 |
128 | 129 | EOF 130 | 131 | Cache[@id] = result 132 | 133 | return result 134 | 135 | end 136 | 137 | Liquid::Template.register_tag "youtube", self 138 | end 139 | -------------------------------------------------------------------------------- /sass/custom/_rve.scss: -------------------------------------------------------------------------------- 1 | .embed-video-container { 2 | 3 | position: relative; 4 | /* padding-bottom: 56.25%; */ /* 16/9 ratio */ 5 | /* padding-top: 30px; */ /* IE6 workaround*/ 6 | height: 0; 7 | overflow: hidden; 8 | 9 | iframe, object, embed { 10 | position: absolute; 11 | top: 0; 12 | left: 0; 13 | width: 100%; 14 | height: 100%; 15 | } 16 | } 17 | .video-info { 18 | font-size: 0.7em; 19 | font-style: italic; 20 | } 21 | .ratio-16-9{ 22 | padding-bottom:56.25%; /* 9/16*100 */ 23 | } 24 | 25 | .ratio-4-3{ 26 | padding-bottom:75%; /* 3/4*100 */ 27 | } 28 | 29 | .ratio-1-1{ 30 | padding-bottom:100%; /* ... */ 31 | } 32 | 33 | a.youtube-lazy-link { 34 | vertical-align:top; 35 | background:#555; 36 | text-decoration:none; 37 | color:#DDD; 38 | text-align:left; 39 | text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black; 40 | display:inline-block; 41 | } 42 | a.youtube-lazy-link:hover { 43 | text-decoration:none; 44 | color:#FFF; 45 | } 46 | .youtube-lazy-link-div { 47 | width: 100%; 48 | height: 100%; 49 | background: url(http://lh4.googleusercontent.com/-QCeB6REIFlE/TuGUlY3N46I/AAAAAAAAAaI/9-urEUtpKcI/s800/youtube-play-button.png) center center no-repeat; 50 | position:absolute; 51 | top:0; 52 | left:0; 53 | } 54 | .youtube-lazy-link-div:hover { 55 | background: url(http://lh5.googleusercontent.com/-oBFjswrosz4/TuHqainRc3I/AAAAAAAAAbE/t3rMQuSJdLA/s800/youtube-play-button-hover.png) center center no-repeat; 56 | } 57 | .youtube-lazy-link-info { 58 | position:absolute; 59 | top:0.6em; 60 | left:0.6em; 61 | } 62 | --------------------------------------------------------------------------------