Combined power of SharePoint and JQuery part1: Changing the SharePoint Image Picker

By Geert van der Cruijsen at February 23, 2010 11:12
Filed Under: JQuery, SharePoint

Wow… long time since i blogged. Thank god I'm going to the Dutch DevDays to see Scott Hanselman’s session called “How to make your blog suck less” :)

So here is an update of mine about how to use JQuery in SharePoint to do some fancy tricks. I’ll post some more of these tricks later on and I’ll try to be more active as a blogger again. (In which I’ll probably fail)

Have you ever tried to change some of SharePoint's default controls like the image picker?

Well I have. My customer wanted a image picker that worked exactly like the normal one except for 1 change. It shouldn’t show the selected image as an image but it should only show the URL of the selected image. I tried to change this at server side first by inheriting from the default SharePoint image picker control. This was a rather annoying job as i didn’t seem to get the right result this way. you cannot extend the rich image picker from sharepoint but only the default image picker that doesn’t have the image library function behind it.

When i was looking at the html that was rendered by SharePoint i thought it would be easier to change the html with jquery as with serverside code and this is the result. just save this source to a .js file and include it into your masterpage or aspx page and all selected images in the image picker will be changed to only show the url of the image.

///<reference path="jquery-1.3.2.min-vsdoc.js" />
 
$(document).ready(function() {
    HideImages();
});
 
function HideImages() {
    $("span[id $= '_RichImageField_ImageFieldDisplay']").each(function() {
        var url = $(this).find("img").attr("src");
        $(this).find("a").hide();
        $(this).append("<span class='imgurl'>" + url + "</span>");
        $(this).find("a").each(function() {
            $(this).find("img").each(function() {
                $(this).load(function() {
                    $(this).parent().hide();
                    var imgurl = $(this).attr("src");
                    $(this).parent().parent().find(".imgurl").text(imgurl);
                });
            });
        });
    });
}

It’s as easy as that.

More JQuery fun to post in the future.

Geert van der Cruijsen

Comments

7/26/2010 1:52:08 AM #

I posted your article to my myspace profile.

Roxane Baransky

7/26/2010 1:52:09 AM #

Whereas this topic can be very sensitive for most individuals, my opinion is that there has to be a middle or widespread ground that we all can find. I do respect that youve added relevant and intelligent commentary right here though. Thank you!

Nenita Goeltz

7/26/2010 6:54:26 AM #

MMM...Maby considere to put here more SharePoint pic

Judson Handrick

7/26/2010 6:54:39 AM #

Couldnt be written any better about SharePoint . Reading this post strikes a chord in my memory of my old room mate! He always kept talking regarding this. I'll forward this informative article 2 him. Pretty certain he will have a fantastic read. Thanks for sharing!

Issac Baish

7/27/2010 12:22:39 AM #

I do not agree with everything in this post, but you do make some very good points. I'm very excited about this topic and I personally act alot of research as well. Either way it had been a well thoughtout & nice read so I figured I would depart u a comment. Feel free to take a look at my website sometime and let me know what you feel.

Asley Sorrentino

7/27/2010 12:22:40 AM #

Hi webmaster, your internet page's design is superb and i like it. Your posts are wonderful. Please sustain the great work. Sincerely!!!

Ebony Gevorkian

7/27/2010 5:21:47 AM #

I don't trust the whole thing with this post, but you do make some excellent points. I'm very excited about this subject and I myself act alot of explore as well. Either way it was a well thoughtout plus nice read so I figured I would leave u a remark. Feel free to take a look at my website sometime & let me know what you feel.

Erin Mend

7/27/2010 5:21:48 AM #

Maby considere to write a SharePoint company to put here adv

Bryanna Feeback

Add comment



biuquote
Loading