Categories
Javascript JQuery

Short Note: Colorbox moving Close button on Top right

By default Colorbox Close button is on Bottom Right. However moving it back to top is as simple as changing Position of div from bottom to top. All I have done is change bottom: x to top: x for all child of cboxContent class. which include cboxLoadedContent, cboxTitle, cboxCurrent, cboxSlideshow, ,cboxPrevious ,cboxNext,cboxClose

Note for myself, and those who find it useful.

Categories
Concept/algorithm HTML/CSS Javascript JQuery

Selecting menu item using Javascript

Okay, I create a pure CSS menu that use UL/LI structure to maintain the child relationship. All was great with this menu except that when you are on any of menu item page it doesn’t highlight that menu item explicitly. If you consider this it is not a big deal. What you can do is simply, iterate through the Menu Items which are probably in LI A tags. Once you iterate, find the URL in A tag and match the Page URL with the Menu ITEM link. If they match change the Class of respective LI or A as your liking.

try {
    var path = window.location.pathname.replace("/User/", "");
    if (path == "" )
        path="Userhome.aspx";
    $("#mainemnu a").each(function () {

        if ($(this).attr("href").toLowerCase() == path.toLowerCase() ) {
            if ($(this).parent().hasClass("submenuitem")) { //it is sub menu
                $(this).parent().parent().parent().addClass("selectedmenu");
            } else {
                $(this).parent().addClass("selectedmenu");
            }
        }
    });
} catch (err) { }

That was a simple Jquery Driven Javascript function that I call in Document ready function of Jquery.

Categories
.NET ASP.NET C#.NET JQuery JSON VB.NET/VB

ASP.NET JavascriptSerializer for Array

I need to throw some database entry which are as simple as TIME, for this I got a string array in my ASP.NET code behind. I was throwing this String Array in JSON format after using JavascriptSerialize.Serialize method and it is making not so perfect Json script. I said it is not making perfect json because the expect result for me was something like this:

[“10:20″,”10:30″,”10:40”]

but it was returing something like

{“d”:”[\”10:20\”,\”10:30\”,\”10:40\”]”}

the difference is that it is converting the array in to string, however the ideal result can be

{“d”:[“10:20″,”10:30″,”10:40”]}

But we cannot change that functionality now, so what I realise we should use the eval function of javascript to make our Jquery or whatever JSON parse you are using. So my Jquery code looks like

….

success: function(data) {
var items = [];
$.each(data, function(ind, val) {
var myobject = eval(val);
$.each(myobject, function(i, v) {                   
items.push(‘<option value=”‘ + v + ‘”>’ + v+ ‘</option>’);
});
});
}

this convert the String to Javascript object using Eval function. Easy enough !!!