newWindow(mainHTML, headHTML, footHTML) [Javascript]

Trying out a new Visual Code Editor plugin for WordPress. Below is a Javascript function that I wrote (leveraging jQuery) for popping a modal window. So far, it’s made its way into two websites.

[javascript]
function newWindow(mainHTML, headHTML, footHTML){
if (!mainHTML) { var mainHTML = “”; }
if (!headHTML) { var headHTML = “”; }
if (!footHTML) { var footHTML = “”; }

if (!$(“#popupcontent”).length){
$popout = $(“<div id=\”popup\”></div>”).addClass(“popup”);
} else {
$popout = $(“#popup”).empty();
if (!$popout.hasClass(“popup”)) { $popout.addClass(“popup”); }
}

$popup = $(“<div id=\”popupcontent\”></div>”);
$(“body”).append($popout.append($popup));

$close = $(“<a>Close</a>”).addClass(“close”).click(function(){ $(“#popup”).remove();});
$popupHead = $(“<div id=\”popuphead\”></div>”).html(headHTML).prepend($close);
$popupFoot = $(“<div id=\”popupfoot\”></div>”).html(footHTML);
$popup.html(mainHTML);
$popout.prepend($popupHead).append($popupFoot);

$popout.css({
position:”absolute”,
top:($(window).height()-$popout.outerHeight())/2,
left:($(window).width()-$popout.outerWidth())/2
});
}
[/javascript]

3 Replies to “newWindow(mainHTML, headHTML, footHTML) [Javascript]”

  1. Entities for intended? For example, on lines 16, 17, and 18?

    Seems like you would want literals there, based on the little experience I have with jQuery…

    1. Actually, that’s a bug in the WordPress + plugin relationship. In my actual code, you can rest assured that I have no great collection of < and >. *sigh* I guess I’ll have to keep trying plugins before I can easily post source code samples.

Comments are closed.

%d bloggers like this: