Showing posts with label image. Show all posts
Showing posts with label image. Show all posts

Thursday, February 23, 2012

Using msDropDown with tooltips plugin

In this post we are going to discuss using msDropDown plugin with tooltips plugin. First lets study the post for how to use msDropDown here. We are going to use the source code specified in that code.

To continue with tooltips implementation with msDropDown, we can first explore the generated HTML for the dropdown in the previous post.
First part(part 1) of the image is the UI of the rendered dropdown. Second part(part 2) is the actual dropdwn we have . And the third part(part 3) of the image is the generated HTML by the msDropDown plugin. Lets study the HTML a little.

If we notice the HTML generated in part 2, the select is inserted in a div and the div height is made to zero. So, the actual dropdown is made hidden. And if we notice the part 3 HTML, we can see the select got converted to a div which contains two child divs. The red box contains the HTML for the selected option. And the green box contains the all options. Each option has converted to anchor(<a> tag) with id like selectID_msa_index. If we notice we can see that each index corresponds to the index of corresponding select option.

Now adding tooltips to the select > option is nothing but adding tooltips to the anchor tag. Let us implement tooltips now. First let us add some dummy attribute to the option tag that represent the tooltip. In this case we are using attribute named tooltipdata like below-
<select name="webmenu" id="webmenu">
        <option value="calendar" tooltipdata="Calendar tip" title="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/icons/icon_calendar.gif">
            Calendar</option>
        <option value="shopping_cart" tooltipdata="Shopping Cart tip" title="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/icons/icon_cart.gif">
            Shopping Cart</option>
        <option value="cd" tooltipdata="CD tip" title="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/icons/icon_cd.gif">
            CD</option>
        <option value="email" selected="selected" tooltipdata="Email tip" title="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/icons/icon_email.gif">
            Email</option>
        <option value="faq" tooltipdata="FAQ tip" title="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/icons/icon_faq.gif">
            FAQ</option>
        <option value="games" tooltipdata="Games tip" title="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/icons/icon_games.gif">
            Games</option>
    </select>
Before implementing tooltip, we need to add the following file references-
<script src="http://jquery.bassistance.de/tooltip/jquery.tooltip.js" type="text/javascript"></script>
    <link href="http://jquery.bassistance.de/tooltip/jquery.tooltip.css" rel="stylesheet"
        type="text/css" />
Now lets modify the msDropDown plugin initialization code. If we go to the plugin documentation we can see that the plugin can accept a function as a parameter that gets called after the plugin initialization happens. So we can add a function like-
<script language="javascript">
        $(document).ready(function (e) {
            try {
                $("#webmenu").msDropDown({ onInit: callAfterInitialization });
            } catch (e) {
                alert(e.message);
            }
        });
        function callAfterInitialization() {
        }
    </script>
In our case we are we are adding a function named callAfterInitialization to onInit parameter of the msDropDown plugin.

Next we can use this function to implement tooltips plugin. As we have already seen the id of the generated anchor selectID_msa_index, we can get the index from the id and find corresponding option from the select. If we can get the option from the select then we can read the value attribute toolltipdata from the option, which is nothing but the tooltip text we need to show in the tooltip of the anchor. We can to this by the following selector. Here this is nothing but the anchor.
$("select[id*=webmenu] option:eq(" + 
this.id.substring(this.id.lastIndexOf("_") + 1) + ")").attr("tooltipdata");
So the full function definition goes like below-
        function callAfterInitialization() {
            $("a[id*=webmenu]").tooltip({
                track: true,
                delay: 0,
                showURL: false,
                fade: 250,
                bodyHandler: function () {
                    return $("select[id*=webmenu] option:eq(" + this.id.substring(this.id.lastIndexOf("_") + 1) + ")").attr("tooltipdata");
                },
                showURL: false
            });
        }
And finally to make sure the tooltip is always on the top, we can change the z-index property of the tooltip to a very higher value.
<style>
        div#tooltip
        {
            z-index: 20000;
        }
    </style>
In this case the tooltip is nothing but a div with id tooltip. You have to check the generated id for your tooltip.

Now if we want to add tooltip to selected item, we can achieve it with little more effort. If we notice part 3, red square section is the HTML for the selected item. The container has a css class named ddTitle. To add tooltip to the selected item is nothing but adding tooltip to the div with class ddTitle. We can do this by enabling tooltip for ddTitle inside document.ready. Code goes here-
$("div[id*=_msdd] div.ddTitle").tooltip({
                track: true,
                delay: 0,
                showURL: false,
                fade: 250,
                bodyHandler: function () {
                    return $("select[id*=" + this.id.substring(0, this.id.indexOf("_") - 1) + "] option:selected").attr("tooltipdata");
                },
                showURL: false
            });
What we are doing in bodyHandler is finding the selected option in the original drop down and adding it as the body of the tooltip. While selected index changes, the msDropDown plugin is also internally changing the selected index of the hidden drop down.

Using msDropDown - a dropdown with icon in the option

msDropDown is a nice plugin. Its a dropdown plugin where we can use icon with the option of the select element. The detail of the plugin can be found here. Implementation goes like below-

We need to add the jQuery and msDropDown script and css file reference. We can download the files form the plugin site given above.
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.js" type="text/javascript"></script>
    <script src="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/msdropdown/js/jquery.dd.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/msdropdown/dd.css" />
Working principle of the plugin is very simple. We need to add the icon path to the title of the option in select tag. Like below-
<option value="value" title="path of the icon">text</option>
Lets have a sample dropdown for this-
    <select name="webmenu" id="webmenu" onchange="showValue(this.value)">
        <option value="calendar" title="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/icons/icon_calendar.gif">
            Calendar</option>
        <option value="shopping_cart" title="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/icons/icon_cart.gif">
            Shopping Cart</option>
        <option value="cd" title="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/icons/icon_cd.gif">
            CD</option>
        <option value="email" selected="selected" title="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/icons/icon_email.gif">
            Email</option>
        <option value="faq" title="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/icons/icon_faq.gif">
            FAQ</option>
        <option value="games" title="http://www.marghoobsuleman.com/mywork/jcomponents/image-dropdown/samples/icons/icon_games.gif">
            Games</option>
    </select>
Now we can activate the msDropDown by the following JavaScript code-
    <script language="javascript">
        $(document).ready(function (e) {
            try {
                $("#webmenu").msDropDown();
            } catch (e) {
                alert(e.message);
            }
        });
    </script>
Thats all. For various other options we can check the plugin site.

Wednesday, January 18, 2012

ppGallery - Lightbox Gallery with asp.net repeater

In this post, we will go through implementation of ppgallery image slider plug-in with asp.net repeater control. The plug-in information can be found here for download.

To start with this lets first see how ppgallery works. The basic implementation of goes as follows-
To use the plugin we need to take following file references-
<link href="http://www.ppplugins.com/demo/ppgallery/ppgallery/css/ppgallery.css" rel="stylesheet" type="text/css" />
<link href="http://www.ppplugins.com/demo/ppgallery/ppgallery/css/dark-hive/jquery-ui-1.8.6.custom.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script> 
<script type="text/javascript" src="http://www.ppplugins.com/demo/ppgallery/ppgallery/js/ppgallery.js"></script> 
We can download the CSS and JS file to your local system and take the reference from locally.
The HTML structure of the plug-in should be like this-
<ul id="gallery">
  <li><a href="big image URL" title="Title"><img src="Thumbnail URL"></a></li>
  <li><a href="big image URL" title="Title"><img src="Thumbnail URL"></a></li>
.
.
.
.
</ul>
For example-
<ul id="gallery">
  <li><a href="http://ppplugins.com/demo/ppgallery/images/l_01.jpg" title="Example of a title goes here."><img src="http://ppplugins.com/demo/ppgallery/images/s_01.jpg"></a></li>
  <li><a href="http://ppplugins.com/demo/ppgallery/images/l_02.jpg" title="Example of a title goes here."><img src="http://ppplugins.com/demo/ppgallery/images/s_02.jpg"></a></li>
  <li><a href="http://ppplugins.com/demo/ppgallery/images/l_03.jpg" title="Example of a title goes here."><img src="http://ppplugins.com/demo/ppgallery/images/s_03.jpg"></a></li>
  <li><a href="http://ppplugins.com/demo/ppgallery/images/l_28.jpg" title="Thanks for visiting PP Plugins"><img src="http://ppplugins.com/demo/ppgallery/images/s_28.jpg"></a></li>
</ul>
And we can implement the plug-in by calling the following script-
<script type="text/javascript">
$(document).ready(function() {
 $('#gallery').ppGallery();
});
</script>
Now we can integrate the image HTML in a repeater. And the code goes below-
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="http://www.ppplugins.com/demo/ppgallery/ppgallery/css/ppgallery.css" rel="stylesheet" type="text/css" />
<link href="http://www.ppplugins.com/demo/ppgallery/ppgallery/css/dark-hive/jquery-ui-1.8.6.custom.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script> 
<script type="text/javascript" src="http://www.ppplugins.com/demo/ppgallery/ppgallery/js/ppgallery.js"></script> 
<script type="text/javascript">
$(document).ready(function() {
        $('#gallery').ppGallery();
});
</script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Repeater ID="Repeater1" runat="server">
        <HeaderTemplate>
            <ul id="gallery">
        </HeaderTemplate>
        <ItemTemplate>
            <li><a href='<%#Eval("URL") %>' title='<%#Eval("Title") %>'>
                <img src='<%#Eval("Thumb") %>'></a></li>
        </ItemTemplate>
        <FooterTemplate>
            </ul>
        </FooterTemplate>
    </asp:Repeater>
    </form>
</body>
</html>
    protected void Page_Load(object sender, EventArgs e)
    {
        var imageDataSource = (new[] { new { URL = "http://ppplugins.com/demo/ppgallery/images/l_01.jpg", 
                                    Thumb = "http://ppplugins.com/demo/ppgallery/images/s_01.jpg" Title= "Title 1"} }).ToList();
        imageDataSource.Add(new {URL = "http://ppplugins.com/demo/ppgallery/images/l_02.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_02.jpg" Title= "Title 2"});
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_03.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_03.jpg" Title= "Title 3" });
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_04.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_04.jpg" Title= "Title 4" });
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_05.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_05.jpg" Title= "Title 5" });
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_06.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_06.jpg" Title= "Title 6" });
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_19.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_19.jpg" Title= "Title 7" });
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_20.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_20.jpg" Title= "Title 8" });
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_21.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_21.jpg" Title= "Title 9" });
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_22.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_22.jpg" Title= "Title 10" });
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_23.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_23.jpg" Title= "Title 11" });
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_24.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_24.jpg" Title= "Title 12" });
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_25.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_25.jpg" Title= "Title 13" });
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_26.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_26.jpg" Title= "Title 14" });
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_27.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_27.jpg" Title= "Title 15" });
        imageDataSource.Add(new { URL = "http://ppplugins.com/demo/ppgallery/images/l_28.jpg", Thumb = "http://ppplugins.com/demo/ppgallery/images/s_28.jpg" Title= "Title 16" });
        Repeater1.DataSource = imageDataSource;
        Repeater1.DataBind(); 
    }
This is an in memory data source. We can replace the data source as we want.