Reduce lines of code

Posted by coffeeaddict on Stack Overflow See other posts from Stack Overflow or by coffeeaddict
Published on 2010-04-14T00:44:47Z Indexed on 2010/04/14 0:53 UTC
Read the original article Hit count: 462

Filed under:
|

I'm not a JavaScript guru (yet). I am trying to figure out a way to cut down the number of lines below...are there any shortcuts for lets say the if statements?

function showDialog(divID) 
{
    var dialogDiv = $("#" + divID);

    var height = 500;
    var width = 400;
    var resizable = false;

    if (dialogDiv.attr("height") != "") 
    {
        height = parseInt(dialogDiv.attr("height"));
    }

    if (dialogDiv.attr("width") != "") 
    {
        width = parseInt(dialogDiv.attr("width"));
    }

    if (dialogDiv.attr("resizable") != "") 
    {
        resizable = dialogDiv.attr("resizable");
    }

    dialogDiv.dialog
    (
        {
            resizable: resizable,
            width: width,
            height: height,
            bgiframe: true,
            modal: true,
            autoOpen: false,
            show: 'blind'
        }
    )

    dialogDiv.dialog("open");
}

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript