Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Saturday, July 6, 2013

Remove the Group Label from the “Group By” List Views

This had to be simple java-script, so a quick search on the internet returned me a 2011 Blog post by “Alexander Bautx” which works “AS-IS”. I had to just replace the single-quotes (‘) by deleting and inserting it back again for all of it’s existence, and that’s it. Probably it was due to the copy-paste formatting issue. I have highlighted the change below, which appears at 4 places in his code.

But this was awesome!! Kudos to Alexander.

Note: You may not need the first line reference for the jquery, if you already have it in your master page.

$(this).find("a:last")[0].nextSibling.nodeValue = '';

Saturday, February 23, 2013

Change position of the “Add new announcement” link

This wasn’t a surprise when it was thrown at me with “Please do not spend much time researching, if you have not already done it in past.”.

The question from the stake-holders was “Does anyone know how to move the ‘add new item’ link at the bottom of lists to the top of the list? (it becomes hard to see and requires scrolling down when many items are added to a list).”

Since I had done that very recently, I came up with a quick solution for her as below:

image

The above highlighted link was moved to top as shown below:

image

This was easily achieved by placing some JQuery code within a hidden content editor on the page this was needed. Although this would move every “Add New…” links on that page, but my stake-holder had no issue with that. She wanted just that. Bingo !!!

Here’s is what you need to use:

<script language="javascript" type="text/javascript">
      $(document).ready(function () {
             $("td.ms-addnew").parent().parent().parent().each(function () {
             $(this).insertBefore($(this).prev());
      });
});

</script>

Saturday, January 19, 2013

Display “Upload Document” button on any web part page

So my client got a little too fancy about having a way to upload documents from anywhere on “a site”, to a particular document library available within that site.

Referring to the SharePoint way of uploading documents as below, I was made to run for a solution that would allow them to add this functionality to any web part page.

image

This wasn’t that bad of a thought. Well, at the end it got out to be quite straight forward, if you are happy and comfortable with java-script.

This is what was done, to allow them quickly add a script in a content editor and display a huge button like this:

image

Now the code:

<div class="ms-uploadbtnlink">
  <button onclick="javascript:OpenNewFormUrl(&#39;Documents/Forms/upload.aspx&#39;);return false;" type="submit">
    <nobr>
     <img alt="Upload Document" src="/_layouts/Images/uploaddoc.png"/>&#160;<span>Upload Document</span>
    </nobr>
  </button>
</div>

Thanks for reading!

Sunday, November 25, 2012

Displaying custom User Name in the Welcome Menu

I have seen so much content about approaching this problem in several ways, which to me are kind of solutions that they either:

-Force you to spend un-necessary long man-hours,

-Write too much of custom codes (writing user controls, etc.),

-Makes you try to understand the Welcome.ascx user control (really?? why? Microsoft has already done that).

So eventually, I ended up writing this post for the benefit of all.

SharePoint is an awesome “PLATFORM”, yes, I call it a platform. Not a Tool, or Application or a CRM or a portal, or a …. and the list goes on. By calling it a platform, I am encapsulating all of them together.

So, with so many stuff already provided out-of-box, we only need to know how to leverage them in a best possible manner to our benefits.

By leveraging, I also mean utilizing the excellent work that is being done by one of the Microsoft’s biggest community, the SharePoint community. You’ll find tons & tons.

The one such work that I am referring to is the SharePoint Services Library on CodePlex. Please find it here.

By using this, I have gotten to get this working in the most minimal way that I could find. Below are the pieces of the code that you would need to get your Welcome menu read aloud “Welcome Tango Charlie”. Pre-requisites being that you have a properly configured User Profile (and of course, if your name is Tango Charlie).

Okay, so we are going to modify our SP 2010 Master Page and place some lines of code in the <head> section.

Step 1: You may download the .js file and insert a script reference to the SPServices library within your <head>…</head> tags:

<script type="text/javascript" src="/_layouts/scripts/jquery-1.4.2.js"></script>
<script type="text/javascript" src="/_layouts/scripts/jquery.SPServices-0.7.2.min.js"></script>

Pre-requisites:

a) You should make sure that you have a JQuery script references before referring to SPServices.

b) Refer the SPServices on CodePlex as the JQuery version requirements are strict for what version of SPServices you are using.

Step 2: Place the below script anywhere within your <head>…</head> tags as long as they follow the tags mentioned in Step 1.

<!-- Format the Welcome Menu -->
<script language="javascript" type="text/javascript">
        $(function() {
            var userFirstName = $().SPServices.SPGetCurrentUser({
                fieldName: "FirstName",
                debug: true
            });

            var userLastName = $().SPServices.SPGetCurrentUser({
                fieldName: "LastName",
                debug: true
            });
           
            var displaySection = $('span.ms-welcomeMenu').children('a.ms-menu-a').children('span');
            var textToShow = 'Welcome ' + userFirstName + ' ' + userLastName;
            // Set the text back to the Welcome Menu
            displaySection.text(textToShow);

          });

</script>

And that’s it. You have your name displayed with the “Welcome” prefix.

Try playing with the combinations/permutations of [fieldName: "FirstName"] and [fieldName: "LastName"] to get different text to display. Good Luck.

Saturday, August 25, 2012

Conditional Javascript in QuickLaunch bar

 

This is a great help !

The ability to display some conditional pop-ups/dialog boxes to the end-users when they click on various links on the Quick Launch bar items, seems a great idea.

I was looking to present a message to the users, whenever they clicked a certain hyper-link on the left navigation.

I wanted them to understand, that they are navigating away from their current site to a page url that might be externally hosted.

This is what really helped me do the same:

javascript: if(confirm(‘You are being re-directed to a site hosted externally. Click OK to proceed, Cancel to stay on the page.’)) document.location=’http://www.bing.com’;

Note: The above line of code being typed in a single line.

Thanks to my colleague Mike Smith for posting this trick with many other options as well.