Monday, 30 July 2007

How to change the default 'My Site' link text using INIT.JS

Ok, I think this probably isn't the best way to do it but it's an immediate results hack so here goes...
First find your INIT.JS file on your web server, mine was at:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033
Next find the line:
var browseris=new Browseris();
And paste the following code beneath it:
window.attachEvent("onload", new Function("MySiteLinkTextReplace();")); function MySiteLinkTextReplace(){ 
try{
//this code replaces "My Site" with "My Home"
//By default the mysite link item (just an asp:hyperlink control) does not
//have a consistent naming convention, and so could be called anything with
//hlMySite in its ID attribute so we get all 'a' tagged items and loop through
//them to find the right one

            var allAtags = document.getElementsByTagName("a");
           
//Look for "My Site" in the innerText property - it will normally
            //the first one found
            for(var j=0;j<allAtags.length;j++){
                var allAtags = allAtags(j);
                //added the 'i' element to make sure on My Profile the My Site
                //text is properly replaced in the two main locations

                var i = 0;
                //If match found replace the text
                if(allAtags.innerText=="My Site")
                {
                    
//assign the new name for "My Site"
                    allAtags.innerText="My Home";
                    //break if we've replaced two 'My Site' instances (i == 1)

                    if(i == 1)
                    {
                       break;
                    }
                    else
                    {
                       i++;
                    }
               }
    }
    catch(e){
       
//not much point doing anything here, either it works and the user
        //sees 'My Home' instead of 'My Site', or it fails and they still
        //see 'My Site'

    }
}
Save the INIT.js file and the changes should be immediate, with no IISRESET required.
This isn't quite the whole story though, the one place I've discovered it has no effect is on the person.aspx page (My Profile tab, if visited from your own My Site). There must be a way around this so I'm going to do some experimenting and will update here when I find the answer.
*UPDATE*
Right, so, if I'd been paying attention to my code, I would've noticed that the reason it wasn't working on the My Profile (person.aspx) page was due to the fact that there are two instances of 'My Site', one occurs where, on the standard personal view of My Site you see your name (top left of the page), and the other occurs in the top right as per usual. The latter instance was the one that wasn't being corrected as the code above breaks after it hits the first instance of 'My Site'. I've now added a count var into the loop above such that it checks for two instances by default and corrects them both, it now works on all pages, hurrah!
-moss[op]

Monday, 2 July 2007

Obligitary first post...

Ok, so this is the obligatory first post, yes I've got blogs elsewhere (treborpossom.spaces.live.com to be precise, but don't bother unless you're already in my friends list as the permissions are, for some unknown reason, locked down) so this isn't going to be a "oooh what's a blog and will I use it and will anyone read it?" type post because I already know the answers to those questions:
  1. It's one of what I'm writing in now...
  2. Hmm, my heart says "yes" my head says "occasionally you'll get a pang of guilt Rob, you'll write a massive update post and then feel no need whatsover to post again until the guilt comes knocking once more"
  3. A certain no!
So given my somewhat cynical expectations why have I created a new blog and why am I bothering to write in it?
  1. This blog (sorry, I know, technically I should write 'blog every time as blog is an abbreviated form of weblog, but really, life's too short) is specifically for my work in the IT arena and normally this will mean SharePoint;
  2. I thought as the most recent version is known as 'MOSS 2007' and my surname is MOSSop (I always spell it with that capitalisation, obviously ;) that this would be a witty and hilarious title, which will draw people in by the millions...
Ok so one out of two isn't bad is it? Oh and some git has already swiped mossop.blogger.com so I had to go with themossop, which I'm now fully convinced is a much better option for some random set of justifications that I haven't finalised as yet.
So, in summary, this is my SharePoint related work-ish 'blog in a vague attempt to hand back to the community who've so nobly assisted me in my SharePoint related endeavours.
I'll probably dump a load of old posts from my live spaces blog in here at some point to get everyone up to speed with where I am, they'll make such wonderful reading, I promise.
-moss[op]