(function(window, $, undefined) {$.fn.sidebar=function(options) {varDefaults ={menuoverevent:' MouseOver ', Menuleaveevent:' MouseLeave ', Foldevent:' Click ', Menuthumbnailselector:". Menu-thumbnail", Menumeta: [' Flow ', ' account ', ' common ', ' recent ',//data order must be consistent with Menudata order in Menudatamenudata: [{menu:' Flow ', Title:' Business Process Management ', content: [' Pre-shipment management ', ' In-stock management ', ' Post-shipment management ', Other]}, {menu:' Account ', Title:Accounting, content: [' Repayment calculation Schedule ', ' Overdue slack interest calculation ', ' Financial accounting ']}, {menu:' Common ', Title:Common, content: [Contract, ' Partners ', ' Risk classification ', ' Trade Flow ', ' Accounts flow ', ' Boycott loan ']}, {menu:' Recent ', Title:' Recent visits ', content: [Contract, ' Partners ', ' Financial accounting ' ] }] }; Settings=$.extend ({}, defaults, options); return This. each (function() { return NewSidebar ( This, settings); }); }; functionSidebar (el, settings) { This. $el =$ (EL); This. Settings =settings; This. $menulist = This. $el. Find ('. Menu ')); This. $thumbnailBox = This. $el. Find (Settings.menuthumbnailselector); This. Init (); } Sidebar.prototype={init:function() { This. CreateView (); This. attachevents (); }, CreateView:function () { varindex= This. Settings.menumeta.indexOf (' Common '); varData= This. Settings.menudata[index]; var$commonBox = This. $el. Find ('. Common ')); var$title =$ (' ); var$lists =$ (' <ul> '); $.each (Data.content,function(index,val) {$lists. Append ($ (' <li><a href= ' ><i></i> ' + val + ' </a></li> ')); }); $commonBox. Append ($title). Append ($lists); }, Attachevents:function() { var_self = This; _self. $menulist. On (' Show ', $.proxy (_self.showmenu,_self)); _self. $menulist. On (' Hide ', $.proxy (_self.hidemenu,_self)); _self. $menulist. On (_self.settings.menuoverevent,function() {_self. $menulist. Trigger (' Show ', This); }); _self. $menulist. On (_self.settings.menuleaveevent,function(e) {if(Checkpointerindiv (E, _self. $thumbnailBox [0])) { $( This). addclass (' on '); return; } _self. $menulist. Trigger (' Hide ', This); }); _self. $thumbnailBox. On (_self.settings.menuleaveevent,function(e) {_self. $menulist. Trigger (' Hide ', This); }); }, CreateMenu:function(Eventelem) {varMenuIndex = This. Settings.menumeta.indexOf ($ (Eventelem). Data (' Menu ')); varMenudata = This. Settings.menudata[menuindex]; var$box = $ (' <div class= ' + menudata.menu + ' ></div '); var$title = $ (' ); var$lists = $ (' <ul> '); $.each (Menudata.content,function(Index, Val) {$lists. Append ($ (' <li><i></i> ' + val + ' </li> ')); }); if($ (Eventelem). Hasclass (' Menu-thumb ')) {$box. Append ($title); } $box. Append ($lists); This. $thumbnailBox. HTML ('); This. $thumbnailBox. Append ($box). css ({left: This. $el. Width (), Top: $ (Eventelem). Offset (). Top}); }, ShowMenu:function(E, Eventelem) { This. CreateMenu (Eventelem); This. $thumbnailBox. Show (); }, Hidemenu:function(E, Eventelem) { This. $menulist. Removeclass (' on '); This. $thumbnailBox. Hide (); } }; functionCheckpointerindiv (event, Elem) {var_POSX =Event.clientx, _posy=event.clinety; varElemX1 =Elem.offsetleft, ElemY1=Elem.offsettop; varelemX2 = elemX1 +Elem.offsetwidth, ElemY2= ElemY1 +Elem.offsetheight; if(_posx < elemX1 | | _posx > ELEMX2 | | _posy < ELEMY1 | | _posy >elemY2) { return false; } return true; }} (window, jQuery));
jquery Plugin Development Example (ii)