1,804 articles and 14,876 comments as of Saturday, May 14th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Friday, December 19, 2008

JQuery for Everyone: Cleaning Windows Pt1

User:  I never use that, can’t you just hide it?
You:  Others may need it.  I’ll give you check boxes to turn it on and off.

If a user hasn’t asked for it yet, they probably will.  Maybe they want more dashboard width, better content real estate in a mobile browser, or a printable page.  This may not be a “solution-in-a-box,” but it should give you an idea or two how you can approach the problem.

I created a simple lab that you can drop into a Content Editor Web Part (CEWP) on any default-ish page in your site to hide the three top-offenders.  Each uses a different selector strategy (just for demonstration purposes) and the overall result rocks.  Without QuickLaunch and the top section, this busy page only needs 640px!

Click “Read more” to see the code. Then come back next week when I show you how to persist the user’s choices with cookies.

<div>
  <input type=checkbox class="toggleClass" value=".ms-searchform" />
  <span style="vertical-align:top">Search Form</span>
</div>
<div>
  <input type=checkbox class="toggleClass" value="#LeftNavigationAreaCell" />
  <span style="vertical-align:top">Left Nav Pane</span>
</div>
<div>
  <input type=checkbox class="toggleClass" value="tr:lt(9)" />
  <span style="vertical-align:top">Top Panel</span>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
	$("input.toggleClass:checkbox").click(function(e) {
		$($(e.target).val()).toggle();
	});
});
</script>

Paul Grenier

View all entries in this series: PaulGrenier-JQuery for Everyone»
Entries in this series:
  1. JQuery for Everyone: Accordion Left Nav
  2. JQuery for Everyone: Print (Any) Web Part
  3. JQuery for Everyone: HTML Calculated Column
  4. JQuery for Everyone: Dressing-up Links Pt1
  5. JQuery for Everyone: Dressing-up Links Pt2
  6. JQuery for Everyone: Dressing-up Links Pt3
  7. JQuery for Everyone: Cleaning Windows Pt1
  8. JQuery for Everyone: Cleaning Windows Pt2
  9. JQuery for Everyone: Fixing the Gantt View
  10. JQuery for Everyone: Dynamically Sizing Excel Web Parts
  11. JQuery for Everyone: Manually Resizing Web Parts
  12. JQuery for Everyone: Total Calculated Columns
  13. JQuery for Everyone: Total of Time Differences
  14. JQuery for Everyone: Fixing Configured Web Part Height
  15. JQuery for Everyone: Expand/Collapse All Groups
  16. JQuery for Everyone: Preview Pane for Multiple Lists
  17. JQuery for Everyone: Preview Pane for Calendar View
  18. JQuery for Everyone: Degrading Dynamic Script Loader
  19. JQuery for Everyone: Force Checkout
  20. JQuery for Everyone: Replacing [Today]
  21. JQuery for Everyone: Whether They Want It Or Not
  22. JQuery for Everyone: Linking the Attachment Icon
  23. JQuery for Everyone: Aspect-Oriented Programming with jQuery
  24. JQuery for Everyone: AOP in Action - loadTip Gone Wild
  25. JQuery for Everyone: Wiki Outbound Links
  26. JQuery for Everyone: Collapse Text in List View
  27. JQuery for Everyone: AOP in Action - Clone List Header
  28. JQuery for Everyone: $.grep and calcHTML Revisited
  29. JQuery for Everyone: Evolution of the Preview
  30. JQuery for Everyone: Create a Client-Side Object Model
  31. JQuery for Everyone: Print (Any) Web Part(s) Plugin
  32. JQuery for Everyone: Minimal AOP and Elegant Modularity
  33. JQuery for Everyone: Cookies and Plugins
  34. JQuery for Everyone: Live Events vs. AOP
  35. JQuery for Everyone: Live Preview Pane
  36. JQuery for Everyone: Pre-populate Form Fields
  37. JQuery for Everyone: Get XML List Data with OWSSVR.DLL (RPC)
  38. Use Firebug in IE
  39. JQuery for Everyone: Extending OWS API for Calculated Columns
  40. JQuery for Everyone: Accordion Left-nav with Cookies Speed Test
  41. JQuery for Everyone: Email a List of People with OWS
  42. JQuery for Everyone: Faster than Document.Ready
  43. jQuery for Everyone: Collapse or Prepopulate Form Fields
  44. jQuery for Everyone: Hourly Summary Web Part
  45. jQuery for Everyone: "Read More..." On a Blog Site
  46. jQuery for Everyone: Slick Speed Test
  47. jQuery for Everyone: The SharePoint Game Changer
  48. JQuery For Everyone: Live LoadTip
 

Please Join the Discussion

15 Responses to “JQuery for Everyone: Cleaning Windows Pt1”
  1. Jeff says:

    How can I safely include JQuery in ALL SharePoint pages? Editing the ONET.XML or CORE.JS somehow?

    I really enjoy these JQuery interface tweaks and am looking for a best practice to deploy the JS files.

    Thank you! Keep up the great work.

  2. AutoSponge says:

    @Jeff,

    Thanks for the compliment. Check out parts 3-6 of the other series for some ideas about library deployment. It’s going to be different for everyone.
    pt6: http://www.endusersharepoint.com/?p=980

  3. It would be cool to do the same for Web Parts to declutter the interface.

  4. AutoSponge says:

    One problem with hiding web parts: it still loads the data. I’d rather allow personalization or make custom pages for better performance.

    But the idea has merit for some applications–borrowing some code from the Print Any Web Part would be a head start.

  5. @AutoSponge: That’s why I mentioned it as a UI fix only instead of a performance solution ;)

  6. @Jeff, You can add JQuery into every page, without messing about with onet.xml, core.js or master pages using our free SharePoint Infuser.

    See http://www.muhimbi.com/blog/2009/07/massage-sharepoint-into-submission.html

    @Paul, this article refers to ‘click read more’. Am I blind or is this link missing?

  7. AutoSponge says:

    @Jeroen,

    That only makes sense if you see the article from the main page (when it’s a new article). Viewing the entire post… well, there’s no more :)

  8. Tony says:

    Well, I see what you mean by working on “default-ish” type pages. Works fine for those. It took me some time to figure out what “tr:lt(9)” means, and it’s only a guess. There appear to be nice tags that need to be toggled to effectively hide the top panel. Is that correct?

    Nice that you show 3 different selector strategies, but one or two sentences on exactly what they mean would be nice, since I “futzed” around trying to figure them out for for about 3 hours!

    Anyway, if I build any other page, the left navigation hiding does not work. I can sort of see why, but no idea how to change the selector for it to make it work. I’ve tried looking for another element on those non-default-ish pages to toggle and nothing works. Any ideas? Hiding the left nav pane would be more useful on non-default pages!

  9. Tony says:

    Oops, correction in that last post:

    “tr:lt(9)” … There appear to be nine (not nice) tags that need to be toggled to effectively hide the top panel. Is that correct?

  10. AutoSponge says:

    @Tony,

    This script example works better as a learning lab than a real solution, but if you like it, that’s awesome!

    tr:lt(9) is jQuery language for table row tags 0-8 (or the first 9 tags). When the jQuery factory function collects objects, $(”tr”) for example, it puts them in an array starting with position 0 from top-to-bottom on the page.

    For more information and some learning examples, see jquery.com’s documentation and jsbin.com’s lab.

    I use Firebug (add on for Firefox) when researching elements I need to work with. I suggest loading one of your pages and using Firebug to find the right thing(s) to hide.

  11. Tony says:

    Thanks, Paul! I’ll try that and let you know what element to look for on pages that are just list views. We use those alot here and have had multiple requests to be able to hide the left nav panel for wide list views.

  12. Tony says:

    OK, that did not take long! Since I had the IE Developer Toolbar installed, I used that and was easily able to identify the one additional element that needs to be hidden. It’s the element with id=”TitleAreaImageCell”. Hiding that element plus the aforementioned element with id=”LeftNavigationAreaCell” when the user selects to hide the left nav works great!

    Thanks, Paul! Now I can hide left nav on default pages and list views.

Trackbacks

Check out what others are saying about this post...
  1. [...] JQuery for Everyone: Cleaning Windows Pt1 [...]

  2. SharePoint Kaffeetasse #98…

    Tools und Addons Custom Content Editor Web Part for SharePoint jQuery http://jquery.com/ jQuery is a…

  3. [...] JQuery for Everyone: Cleaning Windows Pt1 [...]




Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!