views:

21

answers:

1

I'm trying to use JavaScript to find the context menu items being shown and selected from the lists (such as a document library) in SharePoint. I've tracked down a few different function names within core.js, (such as DispEx() and CMOpt()) but I really am having a hard time following the unhelpful variable name mess.

My understanding is that the context menu has to exist within the DOM somewhere - I just can't find out how to retrieve/reference it.

Thanks in advance - this is driving me nuts!

EDIT: I've tried traversing all children from onclick="return DispEx(...)" and I'm not getting anything! This is what I've used to capture that info:
' '

function findStuff(){
var something;
$('[onclick*=DispEx]').children().each(function(){
    something = something + this.tagName + '\n';
});
alert(something);

}

A: 

It looks like those dom elements might be generated by javascript. Take a look at this article.

Also, you might be able to find the element id's by just searching the dom for text using the contains selector:

$(":contains('context menu item text')").attr('id')
Zachary Yates
The article does help confirm that the menu is created in JavaScript, but it refers to a file (ows.js) that doesn't exist in my SharePoint environment :( - Also, I did do a search for the properties to return id, name, and class, none of which are set in the matching condition using: $(':contains("View Properties")').each(function(){ something = something + 'ID: ' + $(this).attr('id') + '\nName: ' + $(this).attr('name') + '\nClass: ' + $(this).attr('class');
patrickgamer
@patrick Well, I don't have an SP environment set up, but can you see the implementation of CAMOpt()? If so, I would add some code in there to set a 'tag' for you to reference later (like the class attribute of the element or something similar). Then, simply bind an event handler using jquery to anything matching the 'tag' you set.
Zachary Yates
@Zachary I can't tailor the solution to my test environment. I have no option to alter other files - that's why I'm trying to find the object when it's rendered.
patrickgamer