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("minHeight"));
}
if (dialogDiv.attr("width") != "")
{
width = parseInt(dialogDiv.attr("minWidth"));
}
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");
}
You can shorten it down a bit, like this:
This takes advantage of the fact javascript is weakly typed, actually it kind of abuses the hell out of it, but it works.
I still find this pretty readable, but I’m used to the syntax, if you’re not…decide what’s readable vs what’s terse and which is more important to you, there’s certainly a tradeoff in many cases.