﻿(function (a) { jQuery.fn.extend({ slimScroll: function (b) { var c = b; this.each(function () { var b, d, e, f, g, h = "<div></div>", i = 30, j = 30, k = c || {}, l = k.width || "auto", m = k.height || "250px", n = k.size || "7px", o = k.color || "#000", p = k.position || "right", q = k.opacity || .4, r = k.alwaysVisible === true; var s = a(this); var t = a(h).css({ position: "relative", overflow: "hidden", width: l, height: m }).attr({ "class": "slimScrollDiv" }); s.css({ overflow: "hidden", width: l, height: m }); var u = a(h).css({ width: "15px", height: "100%", position: "absolute", top: 0 }); var v = a(h).attr({ "class": "slimScrollBar ", style: "border-radius: " + n }).css({ background: o, width: n, position: "absolute", top: 0, opacity: q, display: r ? "block" : "none", BorderRadius: n, MozBorderRadius: n, WebkitBorderRadius: n, zIndex: 99 }); var w = p == "right" ? { right: "1px"} : { left: "1px" }; u.css(w); v.css(w); s.wrap(t); s.parent().append(v); s.parent().append(u); v.draggable({ axis: "y", containment: "parent", start: function () { e = true }, stop: function () { e = false; C() }, drag: function (b) { y(0, a(this).position().top, false) } }); u.hover(function () { B() }, function () { C() }); v.hover(function () { d = true }, function () { d = false }); s.hover(function () { b = true; B(); C() }, function () { b = false; C() }); var x = function (a) { if (!b) { return } var a = a || window.event; var c = 0; if (a.wheelDelta) { c = -a.wheelDelta / 120 } if (a.detail) { c = a.detail / 3 } y(0, c, true); if (a.preventDefault) { a.preventDefault() } a.returnValue = false }; var y = function (a, b, c) { var d = b; if (c) { d = v.position().top + b * j; d = Math.max(d, 0); var e = s.outerHeight() - v.outerHeight(); d = Math.min(d, e); v.css({ top: d + "px" }) } percentScroll = parseInt(v.position().top) / (s.outerHeight() - v.outerHeight()); d = percentScroll * (s[0].scrollHeight - s.outerHeight()); s.scrollTop(d); B() }; var z = function () { if (window.addEventListener) { this.addEventListener("DOMMouseScroll", x, false); this.addEventListener("mousewheel", x, false) } else { document.attachEvent("onmousewheel", x) } }; z(); var A = function () { g = Math.max(s.outerHeight() / s[0].scrollHeight * s.outerHeight(), i); v.css({ height: g + "px" }) }; A(); var B = function () { A(); clearTimeout(f); if (g >= s.outerHeight()) { return } v.fadeIn("fast") }; var C = function () { if (!r) { f = setTimeout(function () { if (!d && !e) { v.fadeOut("slow") } }, 1e3) } } }); return this } }); jQuery.fn.extend({ slimscroll: jQuery.fn.slimScroll }) })(jQuery)
