//javascript document for Bubble Dream theme(http://html5beta.com/wordpress-theme-bubbledream/) //globals var colorPool = ['rgba(156,183,52,.85)','rgba(227,163,26,.85)','rgba(217,84,56,.85)','rgba(4,80,150,.85)','rgba(122,24,105,.85)']; var shapes = []; var animateOn = true; var step = 1; var fps = 100; var shapeNum = 34; var canvasSettting = null; var supportCanvas = true; //function start $(document).ready(function() { var c = $('#cbg')[0]; supportCanvas = c.getContext?true:false; initSite(); }) /** * init site function */ function initSite() { //input styling $('.post input:text').addClass('text'); $('.post input:password').addClass('password'); $('.post input:submit').addClass('submit'); //search input focus $('.search-form .s').focus(function() { var res = $(this); var res1 = $(this).parent(); res1.addClass('focus'); res.animate({ width:213 },400); res1.animate({ width:250 },400) }).blur(function() { var res = $(this); var res1 = $(this).parent(); res1.removeClass('focus'); res.animate({ width:113 },400); res1.animate({ width:150 },400) }) //footer widget adjust $('#footer-widgets .widget-container').last().css({ border:'none' }) //nav menu hover $('#nav ul li').hover(function() { var res = $(this).children('ul'); if(res.length) { checkMenuWidth(res); $(this).addClass('hover'); res.show("normal"); } },function() { $(this).removeClass('hover').children('ul').hide("normal"); }); //table odd row $('tr:odd').addClass("odd-row"); //temp //ajax load more content $(".more-link").live('click', function(e){ e.preventDefault(); var link = $(this); $.post(link.attr("href"), { post_expander: 1 }, function(data) { link.parents(".post-content").html($(data)); }); }) //canvas bubble if(supportCanvas) { drawBg(); $('#footer .addBubble').click(function() { canvasSettting.num ++; drawShape(canvasSettting.num,canvasSettting.w,canvasSettting.h,canvasSettting.num,canvasSettting.ctx) }) $('#footer .faster').click(function() { step ++; step = step>50?50:step; }) } //end } //checkMenuWidth function checkMenuWidth(res) { var li = res.children('li'); var len = li.length; var len2 = 0; for(var i = 0;i < len;i ++) { var len3 = li.eq(i).children('a').text().length * 12; len2 = len2>len3?len2:len3; if(i == (len -1)) { res.css('width',len2) } } } //draw canvas bg function drawBg() { var c = $('#cbg')[0]; var ctx = c.getContext('2d'); var w = $('#cbg').width(); var h = $('#cbg').height(); canvasSettting = { w:w, h:h, ctx:ctx, num:shapeNum }; $('#cbg').attr({ width:w, height:h }) var num = shapeNum; for(var i = 0;i < num;i ++) { drawShape(i,w,h,num,ctx); } animateShapes(); } //draw canvas shape function drawShape(i,w,h,num,ctx) { var r = Math.floor(Math.random() * 100) +50; var r2 = r*2; var w2 = w>r2?w:r2+1; var h2 = h>r2?h:r2+1; var bx = r + Math.floor(Math.random() * (w2 - r2)); var by = r + Math.floor(Math.random() * (h2 - r2)); var co = Math.floor(Math.random() * 5); var st =colorPool[co]; var plx = Math.random()>0.5?true:false; var ply = Math.random()>0.5?true:false; var s = { x:bx, y:by, r:r, fillStyle:st, d:230, plusX:plx, plusY:ply }; shapes.push(s); drawCircle(ctx,bx,by,r,st); } //drawCircle(bx,by,r,st); function drawCircle(ctx,bx,by,r,st) { ctx.beginPath(); ctx.fillStyle = st; ctx.arc(bx,by,r,0,Math.PI *2,true); ctx.fill(); ctx.closePath(); } //animateShapes function animateShapes() { if(animateOn) { canvasSettting.ctx.clearRect(0,0,canvasSettting.w,canvasSettting.h); var num0 = canvasSettting.num; for(var i = 0;i < num0;i ++) { var s = shapes[i]; var r1 =s.r; var d1 = s.d+1; var plusX1 = s.plusX; var plusY1 = s.plusY; if(d1>=230) { var plusX1 = Math.random()>0.5?true:false; var plusY1 = Math.random()>0.5?true:false; d1 = 0; } var x1 = plusX1?(s.x + step):(s.x-step); if(x1>(canvasSettting.w-r1)) { x1 = x1 - 2*step; plusX1 = !s.plusX; } if(x1(canvasSettting.h-r1)) { y1 = y1 - 2*step; plusY1 = !s.plusY; } if(y1