(function ($) {
$.fn.popBox = function (options) {
var defaults = {
height: 100,
width: 320,
newlineString: "
"
};
var options = $.extend(defaults, options);
return this.each(function () {
obj = $(this);
var inputName = 'popBoxInput' + obj.attr("Id");
var labelValue = $("label[for=" + obj.attr('id') + "]").text();
obj.after('');
obj.focus(function () {
$(this).next(".popBox-holder").show();
var popBoxContainer = $(this).next().next(".popBox-container");
var change = true;
popBoxContainer.children('.popBox-input').css({ height: options.height, width: options.width });
popBoxContainer.show();
var winH = $(window).height();
var winW = $(window).width();
var objH = popBoxContainer.height();
var objW = popBoxContainer.width();
var left = (winW / 2) - (objW / 2);
var top = (winH / 2) - (objH / 2);
popBoxContainer.css({ position: 'fixed', margin: 0, top: (top > 0 ? top : 0) + 'px', left: (left > 0 ? left : 0) + 'px' });
popBoxContainer.children('.popBox-input').val($(this).val().replace(RegExp(options.newlineString, "g"), "\n"));
popBoxContainer.children('.popBox-input').focus();
popBoxContainer.children().keydown(function (e) {
if (e == null) { // ie
keycode = event.keyCode;
} else { // mozilla
keycode = e.which;
}
if (keycode == 27) { // close
$(this).parent().hide();
$(this).parent().prev().hide();
change = false;
}
});
popBoxContainer.children().blur(function () {
if (change) {
$(this).parent().hide();
$(this).parent().prev().hide();
$(this).parent().prev().prev().val($(this).val().replace(/\n/g, options.newlineString));
}
});
});
});
};
})(jQuery);
if (jQuery("#pop_area")[0]) {
jQuery('#pop_area').popBox();
}