﻿(function (a) { a.watermarker = function () { }; a.extend(a.watermarker, { defaults: { color: "#999", left: 4 }, setDefaults: function (b) { a.extend(a.watermarker.defaults, b) }, checkVal: function (c, b) { if (c == "") { a(b).show() } else { a(b).hide() } } }); a.fn.watermark = function (e, d) { var c, b; c = a.extend(a.watermarker.defaults, d); b = this.filter("input[type=text], input[type=password], textarea"); b.each(function () { var f, p, h, m, i; var j, g, l, k, o, n; f = a(this); p = f.attr("placeholder") != undefined && f.attr("placeholder") != "" ? "placeholder" : "title"; h = e === undefined || e === "" ? a(this).attr(p) : e; m = a('<span class="watermark_container"></span>'); i = a('<span class="watermark">' + h + "</span>"); if (p == "placeholder") { f.removeAttr("placeholder") } m.css({ "float": f.css("float"), position: "relative" }); f.wrap(m); if (this.nodeName.toLowerCase() != "textarea") { o = f.outerHeight(); k = "50%"; n = o + "px" } else { l = f.position(); g = f.css("margin-top") !== "auto" ? parseInt(f.css("margin-top")) : 0; k = l.top + parseInt(f.css("padding-top")) + g + parseInt(f.css("border-top-width")); n = f.css("line-height"); o = n === "normal" ? parseInt(f.css("font-size")) : n } j = f.css("margin-left") !== "auto" ? parseInt(f.css("margin-left")) : "0"; a.watermarker.checkVal(f.val(), i); i.css({ position: "absolute", fontFamily: f.css("font-family"), fontSize: f.css("font-size"), color: c.color, left: c.left, right: 0, bottom: 0, top: k, height: o + "px", lineHeight: n, marginTop: "-" + (o / 2) + "px", marginLeft: j + parseInt(f.css("padding-left")) }).data("jq_watermark_element", f); i.click(function () { a(a(this).data("jq_watermark_element")).focus() }); f.before(i).focus(function () { a.watermarker.checkVal(a(this).val(), i); i.animate({ opacity: 0.7 }, 250) }).blur(function () { a.watermarker.checkVal(a(this).val(), i); i.animate({ opacity: 1 }, 250) }).keydown(function (q) { a(i).hide() }) }); return this }; a(document).ready(function () { a(".jq_watermark").watermark() }) })(jQuery);
