Blog of an overweight SharePoint addict

Wed 22 Apr 09

Overriding Core.JS functions

Filed under: Javascript, Programming, SharePoint, Troubleshooting — Reginald @ 2:30 pm

A client of mine recently required adding an additional E-Mail link adding to the Item Drop Down menu that drops off of the ECB menu within Document Libraries and Lists.

Now this functionality is provided by the function AddSendSubMenu(m,ctx) within Core.JS. Editing this file is NOT SUPPORTED (You all know this by now I’m sure!). So what to do? Well the answer is make use of Javascript’s natural override.. I.e. If you declare a function twice, the last declaration is the one that gets used.

So, Seems simple huh? We copy the function we want out of Core.JS and stick it into our own NewSendToMenu.js file in /TEMPLATE/LAYOUTS/1033

We then place a standard little script tag into the Head of the Master Page and bobs your uncle, the code gets loaded quite happily on each page.

Or does it? Well yes it does always get loaded.. I proved this by putting a document.write(”Hello World”) in front of the function and this got displayed every time without fail, And yet my customisations weren’t there.

I remembered reading somewhere that Core.JS has a habit of hanging around and getting executed last, My original method using the SharePoint:ScriptLink tag seemed to support this, so I dropped back to using the standard Script tags.. same problem though..

I then stumbled across a small article on the MSDN forums that pointed out the use of the Defer tag in the Core.JS script block. (You can see this if you view the page source in IE..) This means that the execution of Core.JS is deferred until the rest of the page is loaded, thus overriding my own override..

So the solution appears, Declare my script lower down the page than the Core.JS, and tag my Script block with the Defer option also.. This appears to execute my code AFTER core.js has completed.

Now, I’m not 100% how often this will be the case.. looks like this may need some load testing, but I think it’s fair to say that if one script is deferred higher up the page, than another lower down, they should be deferred into the same execution order that they met during page load?

Or am I being too simplistic? Never mind.. for now this works and resolves the client issue!

Paul

Fri 17 Apr 09

Well it was a Thursday afterall!!

Filed under: Installation, Laughter, SharePoint, Win2K8 — Reginald @ 10:49 am

Ok, yesterday was not my best day.. There’s a reason that I switched from ITPro to Dev.. Dev’s shouldn’t do installations as they forget the important bits..like logging in as the Site Collection Admin into Central Administration, and not the Farm Admin..

Logged in properly this morning and hey presto, there’s my create or extend option….

DOH!

Thu 16 Apr 09

WSS3 on Wind2K8 with SQL2K8 – Part 1

Filed under: Installation, SQL2K8, SharePoint, Win2K8 — Reginald @ 4:02 pm

Ok, so today saw me startto build my development environment for those clients that have switched to Windows 2008 and SQL 2008.

All told, I have to say the install for both products is pretty slick, I think for Win2K8 I probably clicked about 6-7 times before I had a fully working server installed and running in the VM.

Installing SQL onto that was just as simple, I opted for Standard edition and installed only the Database engine.

So onto installing WSS itself. Microsoft have published some installation papers to fllow when installing onto Windows 2008, and I have to be honest I didn’t follow them for gospel..Afterall I’m a developer.. when do we RTFM? That’s right..when things go wrong..

Guess what.. It’s starting to go wrong..

SharePoint installed absolutley fine, no errors.. A few minutes later, the infrastructure update went on top… All fine, the configuration database updated happily..

Well this is all dandy.. Up pops Central admin, so I figure I’ll create a quick Web Application and check that I can browse from my desktop to the VM to see that IIS/Win2K8 security is all happy.

Hmm.. Hang on.. where on earth is the option to “Create or Extend a web application”..? It’s just not there.. Todd Klindt suggested to me on Twitter to make sure that I’ve used the Admin Tools option, rather than just browsing, which I tried as well.. The Bamboo community forums suggest running Internet Explorer as administrator.. I did that too..

But at the moment, nothing seems to work.. I’m going to try that old faithful now.. A reboot!

Paul.

Tue 14 Apr 09

Using JQuery to remove Linked List Items hyperlinks.

Filed under: General, JQuery, Programming, SharePoint — Reginald @ 2:30 pm

A client of mine recently raised a concern about the linked list items that are used within SharePoint. In the display list view, they show up as hyperlinks to the linked item. All well and good, you can click on these links to see the full item, however there is no easy way to return as when you click on close you are sent to the default view for the list the linked item belongs to.. (Still with me?)

We discussed several ways around this, but the feeling from the client was that they didn’t want to see these links anyway, so removing them would be the best solution. (I did suggest creating a whole new field type with the option to turn off the Hyperlink in the display render, but they felt that was overkill)

Having played with JQuery, I was pretty certain that we could override the default behaviour using a simpler jQuery selector.. But what do we select?

Well the Linked List items very handily all have the term RootFolder=* in their URL. No other link in SharePoint appears to have this and certainly my testing hasn’t thrown up any errors yet!

So, how do we remove this link in jQuery? Well the trick is to return a collection of A tags that have an Href containing the pattern “RootFolder=*”. Once we have this, we simply add a sibling node using the .After() function to create a new span tag, and then copy the previous tags text content into the new tag, before hiding the A tag using .Remove()

It sounds very simple and it is, but as I found during this exercise, the secret is getting your selectors spot on and making sure the code is firing properly!

Paul.

Note: You will need to have downloaded the JQuery library and registered it in the masterpage, along with the code below (Which can either go in a Content Editor Web Part, or be placed in the Masterpage itself if you want to affect every page.)

<script type="text/javascript" src="/jquery-1.3.1.js"></script>
 
<script type="text/javascript">
$(document).ready(function() {
$('a[href*="RootFolder=*"]').each(function(index) {
var link = $(this);
$(this).after("<span>" + link.text() + "</span>");
$(this).remove();
});
});
</script>

European SharePoint Best Practices Conference

Filed under: Uncategorized — Reginald @ 7:56 am

Well last week saw the first European SharePoint Best practices conference organised by Combined Knowledge here in London.

The event, located at the QEII Conference centre in Westminster was exceptionally well run by Combined Knowledge, Steve and the gang certainly know how to run a user event and all of the staff from CK and the red coats were exceptional. Zoe as always had all the information needed to hand and is my personal favorite for saving me from the Headache from hell!

As to the sessions themselves, I followed the dev track religiously as there are several areas that I’ve been keen to improve on.

The first session featuring the somewhat ‘manic’ Todd Bleeker was exceptionally entertaining and enlightening and set the scene for the conference to come. Todd manages to bring his love of SharePoint and desire to spread the word of development joy to the world with the enthusiasm of a Baptist Revival Minister. A throughly engaging man, I had the pleasure to spend an hour during one of the sessions with Todd showing me how to use his none ajax method of preventing full page post backs using the ICallBackEventHandler, something that I will be making use of in some of my webparts this very week to fully understand it.

Further sessions from such well known US based speakers as Andrew Connell (on Field controls and webparts in publishing sites, Star Wars references were a hoot!!), Eric Schupps (on Custom Site definitions and High Performance applications.. I used a method from this at a client last week and decreased page load times by 20%!)

And our very own home grown talent in the form of Chris O’Brien (Deployment methodologies), Andrew Woodward (TDD and SharePoint in education) and Ben Robb (Customising the Search UI)

And the final sessions of day 2 and 3 were the open mike Ask the Experts panel. Judging by the comments received from people in the other sessions, ours was the best attended and certainly the most fun. Each of the speakers were happy to be challenged by the audience and I gained an great insight into some of the subjects discussed.

Overall, for my first ever Conference, I found this event to be possibly the most value for money training event I’ve attended, with a great return on investment!!

Regards

Paul.

Powered by WordPress