Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
181 views

Ajax Blogger Menu

This document contains the code for a jQuery plugin that adds AJAX functionality to blogger menus. It parses the URL to determine the AJAX URL, makes the AJAX call on hover, parses the response to generate HTML for the submenu items, and handles hover events to show/hide the submenu. On initialization, it transforms the existing menu HTML structure and binds hover event handlers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
181 views

Ajax Blogger Menu

This document contains the code for a jQuery plugin that adds AJAX functionality to blogger menus. It parses the URL to determine the AJAX URL, makes the AJAX call on hover, parses the response to generate HTML for the submenu items, and handles hover events to show/hide the submenu. On initialization, it transforms the existing menu HTML structure and binds hover event handlers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/**

* Mashable Style AJAX Menu for Blogger jQuery Plugin


*
* Version 1.0
* by Harish Dasari <harish@way2blogging.org>
* http://www.way2blogging.org/
* http://github.com/harishdasari
*
* Copyright 2012 Harish Dasari (http://www.way2blogging.org/)
* Dual licensed under the MIT and GPL v2 licenses
*/

(function(e){var t=function(e,t){this.elem=e;this.settings=t;this.addAjaxHtml()
;this.ajaxcall=null;this.lielem=this.elem.find(".verticlemenu li a");this.menuHe
lper(this.elem);this.addEvents()};t.prototype={regex:{islabel:new RegExp("/searc
h/label/","g"),issearch:new RegExp("[?&]q=","g"),labelsearch:new RegExp("(http:/
/[^/]+)/search/label/([^/?&]+).*[?&]q=([^$&]+)(?:[^$]+)?","g"),label:new RegExp(
"(http://[^/]+)/search/label/([^/?&$]+)","g"),search:new RegExp("(http://[^/]+)/
search/?[?&]q=(.*)","g")},addEvents:function(){var t=this;this.lielem.hover(func
tion(){if(e(this).data("menuloaded")!=="true"){t.li=e(this);t.url=t.li.attr("hre
f");t.container=t.li.closest("ul").siblings("ul");t.hoverOver()}},function(){t.h
overOut()})},hoverOver:function(){var t=this;this.getAJAXUrl();if(!this.ajaxUrl)
return;this.ajaxcall=e.ajax({type:"GET",url:t.ajaxUrl,dataType:"jsonp",data:t.aj
axData,beforeSend:function(){t.showLoader()},success:function(e){t.hideLoader();
t.addArrow();t.showPosts(e)},error:function(e){t.showError(e)}})},hoverOut:funct
ion(){this.ajaxcall.abort();this.hideLoader()},getAJAXUrl:function(){if(this.url
){var e=this;this.ajaxData={alt:"json","max-results":this.settings.numPosts};thi
s.url.search(this.regex.islabel)!==-1&&this.url.search(this.regex.issearch)!==-1
?this.ajaxUrl=this.url.replace(this.regex.labelsearch,function(t,n,r,i){e.ajaxDa
ta.q=i;return[n,"/feeds/posts/default/-/",r,"/"].join("")}):this.url.search(this
.regex.islabel)!==-1&&this.url.search(this.regex.issearch)===-1?this.ajaxUrl=thi
s.url.replace(this.regex.label,function(t,n,r){delete e.ajaxData.q;return[n,"/fe
eds/posts/default/-/",r,"/"].join("")}):this.url.search(this.regex.islabel)===-1
&&this.url.search(this.regex.issearch)!==-1?this.ajaxUrl=this.url.replace(this.r
egex.search,function(t,n,r){e.ajaxData.q=r;return[n,"/feeds/posts/default"].join
("")}):this.ajaxUrl=!1}else this.ajaxUrl=!1},showLoader:function(){e("<span></sp
an>",{"class":"loader"}).appendTo(this.li.closest("li"))},hideLoader:function(){
this.li.closest("li").find("span.loader").remove()},showPosts:function(t){var n=
this,r=[],i,s,o;t.feed.openSearch$totalResults.$t>0?e.each(t.feed.entry,function
(t,u){i=u.title.$t;e.each(u.link,function(e,t){t.rel==="alternate"?s=t.href:s="#
"});o=u.media$thumbnail?u.media$thumbnail.url.replace(/\/s72\-c\//,"/s100-c/"):n
.settings.defaultImg;r.push('<li><span class="imgCont"><img alt="',i,'" src="',o
,'"/></span><a rel="nofollow" title="',i,'" href="',s,'">',i,"</a></li>")}):r.pu
sh("<h5>","Sorry!!, No Posts to Show","</h5>");this.container.html(r.join(""));t
his.lielem.removeData("menuloaded");this.li.data("menuloaded","true")},showError
:function(e){if(e.statusText==="error"){this.hideLoader();this.addArrow();this.c
ontainer.html("<h5>Error!! Could not fetch the Blog Posts!</h5>")}},addArrow:fun
ction(){this.lielem.closest("li").find("span").remove();this.lielem.removeClass(
"hoverover");this.li.addClass("hoverover");e("<span></span>",{"class":"menuArrow
"}).appendTo(this.li.closest("li"))},menuHelper:function(t){var n=this;t.find(">
li").hover(function(){var t=e(this);t.find("a:first").addClass("hoverover");var
r=e(this).find("ul.verticlemenu li").height()*e(this).find("ul.verticlemenu li")
.length;t.find("ul.postslist").css({"min-height":r+"px"});n.requestFirstAjax(t)}
,function(){e(this).find("a:first").removeClass("hoverover")})},addAjaxHtml:func
tion(){this.elem.find("ul ul").remove();this.elem.addClass("w2bajaxmenu").find("
>li").find("ul:first").addClass("verticlemenu").wrap(e("<div></div>",{"class":th
is.settings.divClass}));e("ul.verticlemenu").after(e("<ul></ul>",{"class":"posts
list"}))},requestFirstAjax:function(e){e=e.find(".verticlemenu li:first-child a"
);this.url=e.attr("href");this.container=e.closest("ul").siblings("ul");this.li=
e;this.hoverOver()}};e.fn.ajaxBloggerMenu=function(n){var r={numPosts:4,divClass
:"submenu",postsClass:"postslist",defaultImg:"/default.png"},i=e.extend({},r,n);
return this.each(function(){var n=new t(e(this),i)})}})(jQuery);

You might also like