July 31, 2009

Script for Add Buttons for Site Action Menu.

Hi,Many folks face problem once the SharePoint portal is authorized; many eliminate the option of removing the site action menu from master page. Many occasions accrue when one is suppose the edit the web parts or the page contents, everything using designer is also not fissile. Here is a simple script which can be added in the required page as a Content Editor WebPart which can help you in further alterations in future.





< !--Code-- >

<style>

#ContentTypeToolbar table
{
background-color: #BFDBFF !important;width: 100%;
}


td button
{
padding: 3px 7px 4px 7px !important; border: 1px solid
#A0BECE; font-family: Verdana; background-color: transparent; height:auto; width:auto;
xoverflow:visible; margin: 0px 1px 0px 1px !important;
}

</style>



<div id="ContentTypeToolbar" style="background-color:#93BCF;"></div>

<script>

window.attachEvent("onload", new Function("NewButtons_OnLoad();"));

function NewButtons_OnLoad()

{

try

{
var aTags = document.getElementsByTagName("IE:MENUITEM");
var sToolbar='<table
class="ms-menutoolbar" cellSpacing="0" cellPadding="2" width="100%" border="0" >

<tr><td>';


// For Each Menu Item
for(var j=0;j< aTags.length;j++)
{
var aTag = aTags[j];
// Only Process the items from the _New And _settings Menu (ignore Actions)
if(aTag.getAttribute("id").toLowerCase().indexOf("_siteaction")>=0)
{
var BtnText=aTag.getAttributeNode("text").value;
var OnMenuClick=aTag.getAttributeNode("onMenuClick").value;
var IconSrc=aTag.getAttributeNode("iconSrc").value;
var Description=aTag.getAttributeNode("description").value; // Add the Button with
an Image.
sToolbar=sToolbar+'<button class="ms-menubuttoninactivehover"
onmouseover="MMU_EcbTableMouseOverOut(this, true)"
onClick="'+OnMenuClick+'" title="'+Description+'" hoverInactive="ms-menubuttoninactivehover"
hoverActive="ms-menubuttonactivehover">
<img style="height:22px;width:22px;" align="absmiddle" src="'+IconSrc+'">'+BtnText+'</button>';
}//end of if

if(aTag.getAttribute("id").toLowerCase().indexOf("_settings")>=0)

{
var BtnText=aTag.getAttributeNode("text").value;
var OnMenuClick=aTag.getAttributeNode("onMenuClick").value;
var IconSrc=aTag.getAttributeNode("iconSrc").value;
var Description=aTag.getAttributeNode("description").value; // Add the Button
with an Image.
sToolbar=sToolbar+'<button class="ms-menubuttoninactivehover"
onmouseover="MMU_EcbTableMouseOverOut(this, true)"
onClick="'+OnMenuClick+'" title="'+Description+'" hoverInactive="ms-menubuttoninactivehover"
hoverActive="ms-menubuttonactivehover">
<img style="height:22px;width:22px;" align="absmiddle" src="'+IconSrc+'">'+BtnText+'</button>';
}//end of if
} // End For
sToolbar=sToolbar+'<td class="ms-toolbar" noWrap width="1%" >
<img class="icon"
height="18" alt="" src="../../_layouts/images/blank.gif" width="1">
</td>
<td class="ms-toolbar" noWrap align="right">
<
button onclick="CTWPAbout()" style="background-color:transparent;border:0;cursor:hand;">
<img src="/_layouts/images/helpicon.gif"></button>
</td>
</tr>
</table>';

if (document.location.href.indexOf('codeexport') >0)
{
sToolbar='<textarea rows="5">'+sToolbar+'</textarea>';
}
document.getElementById("ContentTypeToolbar").innerHTML=sToolbar;
} // try
catch (e)
{ window.status=e.description;
} // catch
}
function CTWPAbout()
{
var sAbout='by Vinay Patil\n\nCopyright 2009\n ';
alert(sAbout);
}

No comments: