/* global NexT: true */ NexT.utils = NexT.$u = { /** * Wrap images with fancybox support. */ wrapImageWithFancyBox: function () { $('.content img').not('.group-picture img').each(function () { var $image = $(this); var imageTitle = $image.attr('title'); var $imageWrapLink = $image.parent('a'); if ($imageWrapLink.size() < 1) { $imageWrapLink = $image.wrap('').parent('a'); } $imageWrapLink.addClass('fancybox'); $imageWrapLink.attr('rel', 'group'); if (imageTitle) { $imageWrapLink.append('
' + imageTitle + '
'); $imageWrapLink.attr('title', imageTitle); //make sure img title tag will show correctly in fancybox } }); $('.fancybox').fancybox({ helpers: { overlay: { locked: false } } }); }, lazyLoadPostsImages: function () { $('#posts').find('img').lazyload({ placeholder: '/images/loading.gif', effect: 'fadeIn' }); }, registerBackToTop: function () { var THRESHOLD = 50; var $top = $('.back-to-top'); $(window).on('scroll', function () { $top.toggleClass('back-to-top-on', window.pageYOffset > THRESHOLD); }); $top.on('click', function () { $('body').velocity('scroll'); }); }, /** * Transform embedded video to support responsive layout. * @see http://toddmotto.com/fluid-and-responsive-youtube-and-vimeo-videos-with-fluidvids-js/ */ embeddedVideoTransformer: function () { var $iframes = $('iframe'); /* * Supported Players. Extend this if you need more players. */ var SUPPORTED_PLAYERS = [ 'www.youtube.com', 'player.vimeo.com', 'player.youku.com', 'music.163.com', 'www.tudou.com' ]; var pattern = new RegExp(SUPPORTED_PLAYERS.join('|')); $iframes.each(function () { var iframe = this; var $iframe = $(this); if (this.src.search(pattern) > 0) { /* * Calculate the video ratio based on the iframe's w/h dimensions */ var videoRatio = ( $iframe.height() / $iframe.width() ) * 100; // Add height for 163 music. if (this.src.search('music.163.com') > 0) { videoRatio += 10; } /* * Replace the iframe's dimensions and position * the iframe absolute, this is the trick to emulate * the video ratio */ $iframe .width('100%') .height('100%') .css({ position: 'absolute', top: '0', left: '0' }); /* * Wrap the iframe in a new