/* Created by Alexander Bautz alexander.bautz@gmail.com Version: 1.4 LastMod: 03.01.2011 LastChange: Support for anonymous access. */ function getSuperfishMenuData(argObj){ var qb, res, list, newFieldsObjArr, updFieldsObjArr, fields, o, r, b, idArr, mo, pid, url, orphansArr, target; qb = []; qb.push(""); qb.push(""+argObj.menuID+""); qb.push(""); qb.push(""); res = spjs_QueryItems({listName:'SuperfishForSharePoint',listBaseUrl:argObj.listBaseUrl,setRequestHeader:false,query:qb.join(''),viewFields:['ID','Title','LinkText','Mouseover','URL','Parent','OpenInNewWindow']}); if(res.count===-1){ if(confirm("The list \"SuperfishForSharePoint\" is missing.\n\nDo you want me to create it?")){ list = spjs_AddList('SuperfishForSharePoint',argObj.listBaseUrl,'Stores the menu items for the superfish menu.'); if(list.success){ newFieldsObjArr = [{'Type':'Lookup','DisplayName':'Parent','List':list.id,'ShowField':'_parent','Description':'The parent menu item. This is a lookup from the current list.','AddToView':true}, {'Type':'Text','DisplayName':'LinkText','AddToView':true}, {'Type':'Text','DisplayName':'URL','Description':'Optional - the URL on the menu item.','AddToView':true}, {'Type':'Boolean','DisplayName':'OpenInNewWindow','AddToView':true,'content':'0'}, {'Type':'Text','DisplayName':'Mouseover','Description':'Optional - the mouseover when hovering over the menu item.','AddToView':true}, {'Type':'Text','DisplayName':'SortOrder','AddToView':true}, {'Type':'Calculated','DisplayName':'_parent','ResultType':'Text','content':"=Title&\": \"&LinkText=Title&LinkTitle"}]; updFieldsObjArr = [{'Type':'Text','Name':'Title','DisplayName':'MenuID','Description':'The Unique ID of this instance of the menu.','Required':'TRUE'}, {'Type':'Text','Name':'LinkText','DisplayName':'Link text','Description':'The visual text on the menu item.','Required':'TRUE'}, {'Type':'Boolean','Name':'OpenInNewWindow','DisplayName':'Open link in new window','Description':'Open the link in a new window.','content':'0'}, {'Type':'Text','Name':'SortOrder','DisplayName':'Sort order','Description':'The sort order in the individual menus or sub menus. To ensure correct sort order with more then 10 items you must use 01, 02 etc.'}]; fields = spjs_UpdateList('SuperfishForSharePoint',argObj.listBaseUrl,newFieldsObjArr, updFieldsObjArr); if(confirm("The list is created!\n\nClick \"OK\" to go to the list and start adding your menu items.")){ location.href=argObj.listBaseUrl+"/Lists/SuperfishForSharePoint"; } } } }else{ o = {}; idArr = []; $.each(res.items,function(i,item){ pid = (item.Parent!==null)?item.Parent.split(';#')[0]:'0'; mo = (item.Mouseover!==null)?item.Mouseover:''; if($.inArray(pid,idArr)===-1){ idArr.push(pid); } if(o[pid]===undefined){ o[pid] = []; } o[pid].push({i:item.ID,t:item.LinkText,u:item.URL,newWindow:item.OpenInNewWindow,m:mo,p:pid}); }); orphansArr = []; $.each(idArr,function(i,aid){ r = []; b = []; $.each(o[aid],function(oid,obj){ target = (obj.newWindow==='1')?" target='_blank'":''; pid = obj.p; url = '#'; if(obj.u!==null){ url = obj.u; } if(aid==='0'){ r.push("
  • "+obj.t+"
  • "); }else{ b.push("
  • "+obj.t+"
  • "); } }); if(aid==='0'){ $("#menuPlaceholder").html(""); }else{ if($("#menuPlaceholder").find("li[id$='_m_"+pid+"']").length>0){ $("#menuPlaceholder").find("li[id$='_m_"+pid+"']").append(""); }else{ orphansArr.push({pid:pid,html:""}); } } }); while(orphansArr.length>0){ $.each(orphansArr,function(i,obj){ if($("#menuPlaceholder").find("li[id$='_m_"+obj.pid+"']").length>0){ $("#menuPlaceholder").find("li[id$='_m_"+obj.pid+"']").append(obj.html); orphansArr.splice(i,1); return false; } }); } $("ul.sf-menu").superfish(); } }