用javascript自定义SharePoint文档库/列表项菜单..
时间:2009-02-06 来源:sdwjian
我们在SharePoint中自定义菜单,通常通过带CustomAction 的Feature来实现,比如隐藏一个菜单:
<HideCustomAction>
GroupId = "Text"
HideActionId = "Text"
Id = "Text"
Location = "Text">
</HideCustomAction>
自定义一个菜单:
<CustomAction
Id="Extend"
Location="Microsoft.SharePoint.Administration.ApplicationManagement"
Sequence="10"
Title="Extend or upgrade virtual server"
Description="">
<UrlAction Url="vslist.aspx?NextPage=extendvsoption.aspx&Show=NeedExtend&Show=NeedUpgrade"/>
</CustomAction>
具体知识请参考SDK或者参考网上的相关文章。
但是。。。。这种方法不是都管用的,比如我要改变文档库或者列表的ListItem的菜单中的某项或者增加删除一个菜单等等,通过这种方法是没有效果的……

这个时候,我们通过javascript来实现就非常容易了,如果您看过core.js的代码就会发现,MS已经给我们预留了自定义的接口来实现我们自己的菜单定义了,MS想的就是周到哇,嘿嘿……
core.js在路径C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\下的1033[英文]或者2052[中文]下,我们找到添加文档库/列表菜单的function


看到了吧我们可以自定义实现Custom_AddDocLibMenuItems(文档库) / Custom_AddListMenuItems(列表)来添加我们自己的菜单,具体做法是。。。
1)在我们的页面中加入一个WebPart-内容编辑器部件,然后修改部件属性,最好将部件设置为隐藏的:

然后点击“源编辑器...”,输入我们的自定义javascript脚本来实现我们自己的菜单:
<script language="javascript">
function Custom_AddDocLibMenuItems(m, ctx)


{
strDisplayText = "我的菜单";
var rootMenu = CASubM(m,strDisplayText,"","",500);

strDisplayText = "我的菜单还是我的菜单";
strAction = "STSNavigate('http://www.cnblogs.com')";
strImagePath=ctx.imagesPath+"oisweb.gif";
menuOption = CAMOpt(rootMenu,strDisplayText,strAction,strImagePath);
menuOption.id = "ID_MySubMenu";
return false;
}
</script>
function里怎么个写法可以参照core.js的写法:) 最后的return false;说明继续执行系统的代码,如果return true的话。。。那整个菜单就一个你自己的菜单项啦。写完后保存,然后退出编辑模式来瞧瞧:

如果要去掉某个菜单,比如WorkFlow之类,我比较笨,用了个笨方法,把他内置的AddDocLibMenuItems中的脚本copy过来,把要去掉的菜单项给注释掉,然后最后来个return true;呵呵













</CustomAction>
具体知识请参考SDK或者参考网上的相关文章。
但是。。。。这种方法不是都管用的,比如我要改变文档库或者列表的ListItem的菜单中的某项或者增加删除一个菜单等等,通过这种方法是没有效果的……

这个时候,我们通过javascript来实现就非常容易了,如果您看过core.js的代码就会发现,MS已经给我们预留了自定义的接口来实现我们自己的菜单定义了,MS想的就是周到哇,嘿嘿……
core.js在路径C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\下的1033[英文]或者2052[中文]下,我们找到添加文档库/列表菜单的function


看到了吧我们可以自定义实现Custom_AddDocLibMenuItems(文档库) / Custom_AddListMenuItems(列表)来添加我们自己的菜单,具体做法是。。。
1)在我们的页面中加入一个WebPart-内容编辑器部件,然后修改部件属性,最好将部件设置为隐藏的:

然后点击“源编辑器...”,输入我们的自定义javascript脚本来实现我们自己的菜单:

















如果要去掉某个菜单,比如WorkFlow之类,我比较笨,用了个笨方法,把他内置的AddDocLibMenuItems中的脚本copy过来,把要去掉的菜单项给注释掉,然后最后来个return true;呵呵
相关阅读 更多 +