JQuery for Everyone: Force Checkout
With browsers other than IE, users often miss the “force checkout” dialogs when they open documents. Even with IE, if the user has an older version of Office, the document opens in Read Only mode while their computer stores a cached copy in the temp files.

Unwary users then edit the file and save it thinking it will save to SharePoint when it usually just gets lost in their temp files. This script removes document links (you can configure which document extensions) and alerts users to check the document out. Once a document is checked out to the current user, the links work normally (they still need to be careful where they save it).
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> function initForceCheckout(){ var elm = "a[href$='ppt'],"+ //configure file extensions "a[href$='pptx'],"+ "a[href$='doc'],"+ "a[href$='docx'],"+ "a[href$='xls'],"+ "a[href$='xlsx']"; $(elm).each(function(i,e) { var str = "_"+$(e).attr("onclick"); var arr = str.split(","); if (arr[0].indexOf("DispEx")!=-1 && arr[10] != arr[11]) { $(e).attr("href","#") .removeAttr("onClick") .addClass("ForceCheckout") .bind("click", function() { alert("You much check out this document before editing"); }); } }); } $(function (){ //initialize the script initForceCheckout(); }); function ExpGroupRenderData(htmlToRender, groupName, isLoaded) {//re-write of WSS fn for groups var tbody=document.getElementById("tbod"+groupName+"_"); var wrapDiv=document.createElement("DIV"); wrapDiv.innerHTML="<TABLE><TBODY id=\"tbod"+ groupName+"_\" isLoaded=\""+isLoaded+ "\">"+htmlToRender+"</TBODY></TABLE>"; tbody.parentNode.replaceChild(wrapDiv.firstChild.firstChild,tbody); initForceCheckout(); } </script>
- JQuery for Everyone: Accordion Left Nav
- JQuery for Everyone: Print (Any) Web Part
- JQuery for Everyone: HTML Calculated Column
- JQuery for Everyone: Dressing-up Links Pt1
- JQuery for Everyone: Dressing-up Links Pt2
- JQuery for Everyone: Dressing-up Links Pt3
- JQuery for Everyone: Cleaning Windows Pt1
- JQuery for Everyone: Cleaning Windows Pt2
- JQuery for Everyone: Fixing the Gantt View
- JQuery for Everyone: Dynamically Sizing Excel Web Parts
- JQuery for Everyone: Manually Resizing Web Parts
- JQuery for Everyone: Total Calculated Columns
- JQuery for Everyone: Total of Time Differences
- JQuery for Everyone: Fixing Configured Web Part Height
- JQuery for Everyone: Expand/Collapse All Groups
- JQuery for Everyone: Preview Pane for Multiple Lists
- JQuery for Everyone: Preview Pane for Calendar View
- JQuery for Everyone: Degrading Dynamic Script Loader
- JQuery for Everyone: Force Checkout
- JQuery for Everyone: Replacing [Today]
- JQuery for Everyone: Whether They Want It Or Not
- JQuery for Everyone: Linking the Attachment Icon
- JQuery for Everyone: Aspect-Oriented Programming with jQuery
- JQuery for Everyone: AOP in Action - loadTip Gone Wild
- JQuery for Everyone: Wiki Outbound Links
- JQuery for Everyone: Collapse Text in List View
- JQuery for Everyone: AOP in Action - Clone List Header
- JQuery for Everyone: $.grep and calcHTML Revisited
- JQuery for Everyone: Evolution of the Preview
- JQuery for Everyone: Create a Client-Side Object Model
- JQuery for Everyone: Print (Any) Web Part(s) Plugin
- JQuery for Everyone: Minimal AOP and Elegant Modularity
- JQuery for Everyone: Cookies and Plugins
- JQuery for Everyone: Live Events vs. AOP
- JQuery for Everyone: Live Preview Pane
- JQuery for Everyone: Pre-populate Form Fields
- JQuery for Everyone: Get XML List Data with OWSSVR.DLL (RPC)
- Use Firebug in IE
- JQuery for Everyone: Extending OWS API for Calculated Columns
- JQuery for Everyone: Accordion Left-nav with Cookies Speed Test
- JQuery for Everyone: Email a List of People with OWS
- JQuery for Everyone: Faster than Document.Ready
- jQuery for Everyone: Collapse or Prepopulate Form Fields
- jQuery for Everyone: Hourly Summary Web Part
- jQuery for Everyone: "Read More..." On a Blog Site
- jQuery for Everyone: Slick Speed Test
- jQuery for Everyone: The SharePoint Game Changer
- JQuery For Everyone: Live LoadTip
IMHO this is going to help out a lot of people.
Cheers for making it happen Paul. :)
Suggestion/Addition:
Is there a way to modify the buttons produced on the message box instead of OK?
i.e. have a Check Out button and Cancel button. Clicking Check Out automatically performs the Check Out and opens in the appropriate application.
Worth to note that it will fail on grouped views.
@SevenOfNine,
Actually, this was tested with groups.
I rewrote the ExpGroupRenderData function on the page which renders grouped data to fire the initialization again.
Are you seeing something different? Which browser?
You’re right. I missed the part with the rewritten ExpGroupRenderData function completely. Well, well, it was late last night ;-)
Thanks for enlighting me…
This looks perfect!
Please forgive my ignorance but where should I put this code?
CC
@Custard,
For a single library, use Site Actions > Edit to put the page in edit mode. Then ‘Add a web part’ to one of the zones. Add a Content Editor Web Part. In the settings for that CEWP, open the Source Editor and paste the code there.
If you like that, start with my series on JavaScript: http://www.endusersharepoint.com/?p=929
Paul,
Looks like a great trick. I’ve got a WSS 2.0 site that I’d like to use this on, but I can’t get it to work. I suspect it needs to be on MOSS 2007/WSS 3.0 to work. Any way it can be made to work for WSS 2.0?
Thanks,
Adam
@Adam
Thanks for the compliment. I’ve never used WSS2 so I can’t really help you. To create this, I studied the rendered source of the document library looking for a pattern near the document’s link.
The javascript call has a bunch of arguments which included the current user and the user the document is checked out to (null if not checked out).
Therefore, my logic just says arr[10] != arr[11] (if argument 10 does not equal argument 11…)
Do you have a ‘Screencast’ or ‘Screenshots’ for this? I’m still new at SharePoint and we are using WSS 3.0 for our hospital.
Thanks
Two questions:
1. Can this work with PDFs?
2. Not all the documents and PPT slides have the ‘POPUP’. How can I fix this. We are using WSS 3.0
Thanks
I don’t think it’s going to work with PDFs because there’s no expected client integration.
I intended for there to NOT be a popup if the document does not require checkout or you already have it checked out. Is that the case?
@Frank,
BTW, I’m terrible at screencasts. It takes me 2 hours to produce 10 minutes of video. It’s not something I do often but I’m trying to get better. I’ll keep this request in mind.
How and where to use this script?????