var boozurkScripts; (function($) { boozurkScripts = { init : function( in_modules ) { var modules = in_modules.split(','); for (i in modules) { switch(modules[i]) { case 'postexpander': boozurkScripts.post_expander(); break; case 'thickbox': boozurkScripts.init_thickbox(); break; case 'tooltips': boozurkScripts.tooltips(); boozurkScripts.cooltips('.pmb_comm,.minibutton,.share-item img,.tb_categories a,#bz-quotethis,.tb_latest_commentators li,.tb_social a,.post-format-item.compact img,a.bz-tipped-anchor'); break; case 'plusone': gapi.plusone.go("posts_content"); break; case 'quotethis': boozurkScripts.init_quote_this(); break; case 'infinitescroll': boozurkScripts.infinite_scroll(boozurk_l10n.infinite_scroll_type); break; case 'animatemenu': boozurkScripts.animate_menu(); break; case 'scrolltopbottom': boozurkScripts.scroll_top_bottom(); break; case 'commentvariants': boozurkScripts.comment_variants(); break; case 'resizevideo': boozurkScripts.resize_video(); break; case 'tinynav': boozurkScripts.tinynav(); break; default : //no default action break; } } }, post_expander : function() { return $('#posts_content').find('a.more-link').each(function() { $(this).click(function() { var link = $(this); $.ajax({ type: 'POST', url: link.attr("href"), beforeSend: function(XMLHttpRequest) { link.html(boozurk_l10n.post_expander).addClass('ajaxed'); }, data: 'boozurk_post_expander=1', success: function(data) { link.parents(".storycontent").hide().html($(data)).fadeIn(600); } }); return false; }); }); }, infinite_scroll : function( behaviour ) { $('#bz-page-nav').addClass('ajaxed'); $('#bz-next-posts-button').fadeOut(); $('.nb-nextprev').hide(); return $(window).scroll(function () { if ( $('#bz-page-nav').position().top-$(window).scrollTop()-$(window).height() < -150) { var link = $('#bz-next-posts-link a'); if ( link.length > 0 ) { if ( behaviour == 'auto' ) { boozurkScripts.AJAX_paged(); } else if ( behaviour == 'manual' ) { $('#bz-next-posts-button').fadeIn(); } } else { $('#bz-next-posts-button').html(boozurk_l10n.infinite_scroll_end).fadeIn(); return false; } } }); }, animate_menu : function() { return $('#mainmenu').children('.menu-item-parent').each(function() { $this = $(this); var d = $this.children('ul'); //for each main item, get the sub list d.css( {'opacity' : 0 } ); $this.hoverIntent( function(){ //when mouse enters, slide down the sub list d.css( {'display' : 'block' } ).animate( { 'opacity' : 0.95 } ); }, function(){ //when mouse leaves, hide the sub list d.stop().animate( { 'opacity' : 0 }, 200, 'swing', function(){ d.css( {'display' : '' } ); } ); } ); }); }, tooltips : function() { return $('#posts_content').find('.bz-tooltip').each(function() { var p = $(this).parent(); var self = $(this); var timeoutID; self.hide(); p.hoverIntent( function(){ window.clearTimeout(timeoutID); self.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: 0.9}); }, function(){ timeoutID = window.setTimeout( function(){self.fadeOut()}, 200); } ); }); }, cooltips : function(selector) { var baloon = $('
'); baloon.appendTo(document.body); var timeoutID; return $(selector).each(function() { var $this = $(this); $this.hoverIntent( function(){ var offset,h_pos,pin_pos; if ($this.attr('title') || typeof($this.attr('original-title')) != 'string') { $this.attr('original-title', $this.attr('title') || '').removeAttr('title'); } baloon.html($this.attr('original-title')); offset = $this.offset(); baloon.css({top: 0, left: 0, display: 'block'}).removeClass('to_left to_right'); if ( offset.left > ( $(window).width() - 250 ) ) { h_pos = offset.left - baloon.outerWidth() + ( $this.outerWidth() / 2 ); pin_pos = 'to_left'; } else { h_pos = offset.left + ( $this.outerWidth() / 2 ); pin_pos = 'to_right'; } baloon.css({top: offset.top - baloon.outerHeight() - 10, left: h_pos}).addClass(pin_pos); window.clearTimeout(timeoutID); baloon.stop().css({opacity: 0}).animate({opacity: 0.9}); }, function(){ timeoutID = window.setTimeout( function(){baloon.fadeOut()}, 200); } ); }); }, AJAX_paged : function() { var next_href = $('#bz-next-posts-link a').attr( "href" ); var nav = $('#bz-page-nav'); $.ajax({ type: 'POST', url: next_href, beforeSend: function(XMLHttpRequest) { $('#bz-page-nav-msg').addClass('loading').html(boozurk_l10n.infinite_scroll).animate( { 'opacity' : 1 } ); }, data: 'boozurk_infinite_scroll=1', success: function(data) { nav.replaceWith( $(data) ); boozurkScripts.init(boozurk_l10n.script_modules_afterajax); $('#bz-next-posts-button input').click(function() { boozurkScripts.AJAX_paged(); }); } }); return false; }, init_thickbox : function() { $('#posts_content').find('.storycontent a img').parent('a[href$=".jpg"],a[href$=".png"],a[href$=".gif"]').addClass('thickbox'); $('#posts_content').find('.storycontent .gallery').each(function() { $('a[href$=".jpg"],a[href$=".png"],a[href$=".gif"]',$(this)).attr('rel', $(this).attr('id')); }); }, scroll_top_bottom : function() { top_but = $('#navbuttons').find('.minib_top'); bot_but = $('#navbuttons').find('.minib_bottom'); // smooth scroll top/bottom top_but.click(function() { $("html, body").animate({ scrollTop: 0 }, { duration: 400 }); return false; }); bot_but.click(function() { $("html, body").animate({ scrollTop: $('#footer').offset().top - 80 }, { duration: 400 }); return false; }); }, comment_variants : function() { $('#commentform').find('.comment-variants label').click(function() { $('#comment').removeClass( 'style-default style-blue style-pink style-orange style-yellow style-green style-gray style-white' ); $('#comment').addClass( $('input', this).val() ); $('input', this).attr('checked',true); }); }, init_quote_this : function() { if ( document.getElementById('reply-title') && document.getElementById("comment") ) { bz_qdiv = document.createElement('small'); bz_qdiv.innerHTML = ' - ' + boozurk_l10n.quote + ''; bz_replink = document.getElementById('reply-title'); bz_replink.appendChild(bz_qdiv); } }, quote_this : function() { var posttext = ''; if (window.getSelection){ posttext = window.getSelection(); } else if (document.getSelection){ posttext = document.getSelection(); } else if (document.selection){ posttext = document.selection.createRange().text; } else { return true; } posttext = posttext.toString().replace(/&/g,"&").replace(/"/g,""").replace(//g,">"); if ( posttext.length !== 0 ) { document.getElementById("comment").value = document.getElementById("comment").value + '' + posttext + ''; } else { alert( boozurk_l10n.quote_alert ); } }, resize_video : function() { // https://github.com/chriscoyier/Fluid-Width-Video var $fluidEl = $("#posts_content").find(".storycontent"); var $allVideos = $("iframe[src^='http://player.vimeo.com'], iframe[src^='http://www.youtube.com'], object, embed",$fluidEl); $allVideos.each(function() { $(this) // jQuery .data does not work on object/embed elements .attr('data-aspectRatio', this.height / this.width) .removeAttr('height') .removeAttr('width'); }); $(window).resize(function() { var newWidth = $fluidEl.width(); $allVideos.each(function() { var $el = $(this); $el .width(newWidth) .height(newWidth * $el.attr('data-aspectRatio')); }); }).resize(); }, tinynav : function() { $(".nav-menu").tinyNav({ label: '', // String: Sets the