Stump the Panel » jQuery for Everyone

jQuery - Open link in new window for view using Groupings

(3 posts)
  • Started 2 weeks ago by kayjay
  • Latest reply from Christophe
  1. kayjay
    Member

    Hi,

    The SharePoint "Link to a Document" content type allows you to easily add links into document libraries. The HTML code for a "Link to a Document" looks like this:

    <a href="/sites/Nest/V3Training/Onboarding.aspx">Onboarding<img width="1" height="1" border="0" alt="Use SHIFT+ENTER to open the menu (new window)." class="ms-hidden" src="/_layouts/images/blank.gif"/></a>

    I have been using the jQuery code below to open these links into a new window.
    The code works fine on library views that DO NOT use the grouping feature. It also works fine for views with grouping that initially display ALL Groups EXPANDED.

    However, it refuses to work when the library view uses grouping and ALL Groups are COLLAPSED.
    The grouping feature in SharePoint uses Javascript functions and I guess it conflicts with the jQuery code somehow. I just can't figure out how!

    Any ideas? Thanks!

    <script src="http://mysp/sites/Nest/JQuery/jquery.js" type="text/javascript"></script>
    
    <script type="text/javascript">
    $(document).ready(function() {
    		$('a[onclick*=SharePoint.Link]').attr('target','_blank');
    		var test = $('a[onclick*=SharePoint.Link]');
    		alert(test);
    });
    </script>
    Posted 2 weeks ago #
  2. I have written some articles that will help with this. One should come out in a day or two that uses AOP. However, the brute force method is to rewrite the SharePoint function that renders the new HTML from an expanded group like this:

    'function ExpGroupRenderData(htmlToRender, groupName, isLoaded) {
    $("#tbod"+groupName+"_").attr("isloaded",isLoaded)
    .html(htmlToRender)
    .show("fast",___callback___);'

    where callback is a call to your custom function.

    If you look at some of my code examples, I use that to call something like initPreview(group) so I can pass the groupName from ExpGroupRenderData into my function.

    'function initPreview(group){
    if (!group){group = "#MSO_ContentTable";}
    $(group+" a[href*='DispForm.aspx']").bindPreview();
    ...
    '

    When I run the init function, I don't put a group, and it defaults to the main content area. When the new version of the SP function runs it:

    '.show("fast",initPreview("#tbod"+groupName+"_"));'

    I pass the group so I can select the group by ID.

    I hope that helps. Like I said, if you're still stuck, my new AOP article should make it as simple as this can get.

    Posted 2 days ago #
  3. @kayjay: it's not a conflict issue. It's just that in a collapsed view, SharePoint only calls items on demand (let's call this a "best practice"). When you run your script, the items are not in the page yet, so the formatting doesn't apply to them.
    As Paul suggests, you need to re-run your function everytime you expand the group.

    Posted 2 days ago #

RSS feed for this topic

Reply

You must log in to post.