Advertisement
Guest User

Untitled

a guest
Dec 29th, 2010
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(a) {
  2. a.fn.extend({
  3. troppinautocomplete: function(b, c) {
  4. var d = typeof b == "string";
  5. c = a.extend({}, a.TroppinAutocompleter.defaults, { url: d ? b : null, data: d ? null : b, delay: d ? a.TroppinAutocompleter.defaults.delay : 10, max: c && !c.scroll ? 10 : 150 }, c);
  6. c.highlight = c.highlight || function(e) { return e };
  7. c.formatMatch = c.formatMatch || c.formatItem;
  8. return this.each(function() {
  9. new a.TroppinAutocompleter(this, c)
  10. })
  11. }, result: function(b) { return this.bind("result", b) }, search: function(b) {
  12. return this.trigger("search", [b])
  13. }, flushCache: function() {
  14. return this.trigger("flushCache")
  15. }, setOptions: function(b) {
  16.     return this.trigger("setOptions", [b])
  17. }, untroppinautocomplete: function() {
  18.     return this.trigger("untroppinautocomplete")
  19. }
  20. });
  21.  
  22. a.TroppinAutocompleter = function(l, g) {
  23. var c = { UP: 38, DOWN: 40, DEL: 46, TAB: 9, RETURN: 13, ESC: 27, COMMA: 188, PAGEUP: 33, PAGEDOWN: 34, BACKSPACE: 8 };
  24.  
  25. var b = a(l).attr("troppinautocomplete", "off").addClass(g.inputClass);
  26. var j;
  27. var p = "";
  28. var m = a.TroppinAutocompleter.Cache(g);
  29. var e = 0;
  30. var u;
  31. var x = { mouseDownOnSelect: false };
  32. var r = a.TroppinAutocompleter.Select(g, l, d, x);
  33. var w;
  34.  
  35. a.browser.opera && a(l.form).bind("submit.troppinautocomplete", function() {
  36. if (w) {
  37.     w = false; return false
  38. }
  39. });
  40.  
  41. b.bind((a.browser.opera ? "keypress" : "keydown") + ".troppinautocomplete", function(y) {
  42. u = y.keyCode;
  43. switch (y.keyCode) {
  44.     case c.UP: y.preventDefault();
  45.         if (r.visible()) {
  46.             r.prev()
  47.         } else {
  48.         t(0, true)
  49.     }
  50.     break;
  51. case c.DOWN: y.preventDefault();
  52.     if (r.visible()) {
  53.         r.next()
  54.     } else {
  55.         t(0, true)
  56.     } break;
  57. case c.PAGEUP: y.preventDefault();
  58.     if (r.visible()) {
  59.         r.pageUp()
  60.     } else {
  61.         t(0, true)
  62.     } break;
  63. case c.PAGEDOWN: y.preventDefault();
  64.     if (r.visible()) {
  65.         r.pageDown()
  66.     } else {
  67.     t(0, true)
  68. } break;
  69. case g.multiple && a.trim(g.multipleSeparator) == "," && c.COMMA: case c.TAB: case c.RETURN: if (d()) {
  70.         y.preventDefault();
  71.         w = true;
  72.         return false
  73.     } break;
  74. case c.ESC: r.hide();
  75.     break;
  76. default: clearTimeout(j);
  77.     j = setTimeout(t, g.delay);
  78.     break
  79. }
  80. }).focus(function() { e++ }).blur(function() {
  81. e = 0;
  82. if (!x.mouseDownOnSelect) {
  83.     s()
  84. }
  85. }).click(function() {
  86. if (e++ > 1 && !r.visible()) {
  87.     t(0, true)
  88. }
  89. }).bind("search", function() {
  90. var y = (arguments.length > 1) ? arguments[1] : null;
  91.  
  92. function z(D, C) {
  93.     var A;
  94.     if (C && C.length) {
  95.         for (var B = 0; B < C.length; B++) {
  96.             if (C[B].result.toLowerCase() == D.toLowerCase()) {
  97.                 A = C[B];
  98.                 break
  99.             }
  100.         }
  101.     }
  102.     if (typeof y == "function") {
  103.         y(A)
  104.     } else {
  105.     b.trigger("result", A && [A.data, A.value])
  106. }
  107. }
  108. a.each(h(b.val()), function(A, B) {
  109. f(B, z, z)
  110. })
  111. }).bind("flushCache", function() { m.flush() }).bind("setOptions", function() {
  112.     a.extend(g, arguments[1]);
  113.     if ("data" in arguments[1]) { m.populate() }
  114. }).bind("untroppinautocomplete", function() {
  115.     r.unbind();
  116.     b.unbind();
  117.     a(l.form).unbind(".troppinautocomplete")
  118. });
  119.  
  120. function d() {
  121.     var z = r.selected();
  122.     if (!z) { return false }
  123.     var y = z.result;
  124.     y = y.replace(/\s+\(\d+\)$/, "");
  125.     p = y;
  126.     if (g.multiple) {
  127.         var A = h(b.val());
  128.         if (A.length > 1) {
  129.             y = A.slice(0, A.length - 1).join(g.multipleSeparator) + g.multipleSeparator + y
  130.         } y += g.multipleSeparator
  131.     }
  132.    
  133.     b.val(y);
  134.     v();
  135.     b.trigger("result", [z.data, z.value]); return true
  136. }
  137.  
  138. function t(A, z) {
  139.     if (u == c.DEL) {
  140.         r.hide();
  141.         return
  142.     }
  143.    
  144.     var y = b.val();
  145.     if (!z && y == p) { return }
  146.     p = y;
  147.     y = i(y);
  148.     if (y.length >= g.minChars) {
  149.         b.addClass(g.loadingClass);
  150.         if (!g.matchCase) {
  151.             y = y.toLowerCase()
  152.         }
  153.        
  154.         f(y, k, v)
  155.     } else {
  156.     n();
  157.     r.hide()
  158. }
  159. }
  160.  
  161. function h(z) {
  162.     if (!z) {
  163.         return [""]
  164.     }
  165.     var A = z.split(g.multipleSeparator);
  166.     var y = [];
  167.     a.each(A, function(B, C) {
  168.     if (a.trim(C)) {
  169.         y[B] = a.trim(C)
  170.     }
  171. });
  172. return y
  173. }
  174.  
  175. function i(y) {
  176.     if (!g.multiple) {
  177.         return y
  178.     }
  179.     var z = h(y);
  180.     return z[z.length - 1]
  181. }
  182.  
  183. function q(y, z) {
  184.     if (g.autoFill && (i(b.val()).toLowerCase() == y.toLowerCase()) && u != c.BACKSPACE) {
  185.         b.val(b.val() + z.substring(i(p).length));
  186.         a.TroppinAutocompleter.Selection(l, p.length, p.length + z.length)
  187.     }
  188. }
  189.  
  190. function s() {
  191.     clearTimeout(j);
  192.     j = setTimeout(v, 200)
  193. }
  194.  
  195. function v() {
  196.     var y = r.visible();
  197.     r.hide();
  198.     clearTimeout(j);
  199.     n();
  200.     if (g.mustMatch) {
  201.         b.search(function(z) {
  202.         if (!z) {
  203.             if (g.multiple) {
  204.                 var A = h(b.val()).slice(0, -1);
  205.                 b.val(A.join(g.multipleSeparator) + (A.length ? g.multipleSeparator : ""))
  206.             } else {
  207.                 b.val("")
  208.             }
  209.         }
  210.     })
  211. }
  212.  
  213. if (y) {
  214.     a.TroppinAutocompleter.Selection(l, l.value.length, l.value.length)
  215. }
  216. }
  217.  
  218. function k(z, y) {
  219.     if (y && y.length && e) {
  220.         n();
  221.         r.display(y, z);
  222.         q(z, y[0].value);
  223.         r.show()
  224.     } else {
  225.     v()
  226. }
  227. }
  228.  
  229. function f(z, B, y) {
  230.     if (!g.matchCase) {
  231.         z = z.toLowerCase()
  232.     }
  233.     var A = m.load(z);
  234.     if (A && A.length) {
  235.         B(z, A)
  236.     } else {
  237.     if ((typeof g.url == "string") && (g.url.length > 0)) {
  238.         var C = { timestamp: +new Date() };
  239.         a.each(g.extraParams, function(D, E) { C[D] = typeof E == "function" ? E() : E });
  240.         a.ajax({ mode: "abort", port: "troppinautocomplete" + l.name, dataType: g.dataType, url: g.url + "/" + g.max + "/" + i(z), cache: false, success: function(E) {
  241.         var D = g.parse && g.parse(E) || o(E);
  242.         m.add(z, D);
  243.         B(z, D)
  244.     }
  245. })
  246. } else {
  247. r.emptyList();
  248. y(z)
  249. }
  250. }
  251. }
  252.  
  253. function o(B) {
  254.     var y = [];
  255.     var A = B.split("\n");
  256.     for (var z = 0; z < A.length; z++) {
  257.         var C = a.trim(A[z]);
  258.         if (C) {
  259.             C = C.split("|");
  260.             y[y.length] = { data: C, value: C[0], result: g.formatResult && g.formatResult(C, C[0]) || C[0]
  261.         }
  262.     }
  263. }
  264.  
  265. return y
  266. }
  267.  
  268. function n() {
  269.     b.removeClass(g.loadingClass)
  270. }
  271. };
  272.  
  273. a.TroppinAutocompleter.defaults = {
  274.     inputClass: "ac_input",
  275.     resultsClass: "ac_results",
  276.     loadingClass: "ac_loading",
  277.     minChars: 1,
  278.     delay: 400,
  279.     matchCase: false,
  280.     matchSubset: true,
  281.     matchContains: false,
  282.     cacheLength: 10,
  283.     max: 100,
  284.     mustMatch: false,
  285.     extraParams: {},
  286.     selectFirst: true,
  287.     formatItem: function(b) { return b[0] },
  288.     formatMatch: null,
  289.     formatResult: function(b) { return b[0] },
  290.     autoFill: false,
  291.     width: 0,
  292.     multiple: false,
  293.     multipleSeparator: ", ",
  294.     highlight: function(c, b) { return c.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + b.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>") },
  295.     scroll: true,
  296.     scrollHeight: 180
  297. };
  298.  
  299. a.TroppinAutocompleter.Cache = function(c) {
  300. var f = {};
  301. var d = 0;
  302. function h(l, k) {
  303.     if (!c.matchCase) {
  304.         l = l.toLowerCase()
  305.     }
  306.  
  307.     var j = l.indexOf(k);
  308.     if (j == -1) {
  309.         return false
  310.     }
  311.     return j == 0 || c.matchContains
  312. }
  313.  
  314. function g(j, i) {
  315.     if (d > c.cacheLength) {
  316.         b()
  317.     }
  318.     if (!f[j]) {
  319.         d++
  320.     }
  321.     f[j] = i
  322. }
  323.  
  324. function e() {
  325.     if (!c.data) {
  326.         return false
  327.     }
  328.     var k = {}, j = 0;
  329.     if (!c.url) {
  330.         c.cacheLength = 1
  331.     }
  332.     k[""] = [];
  333.     for (var m = 0, l = c.data.length; m < l; m++) {
  334.         var p = c.data[m];
  335.         p = (typeof p == "string") ? [p] : p;
  336.         var o = c.formatMatch(p, m + 1, c.data.length);
  337.         if (o === false) {
  338.             continue
  339.         }
  340.         var n = o.charAt(0).toLowerCase();
  341.         if (!k[n]) {
  342.             k[n] = []
  343.         }
  344.         var q = { value: o, data: p, result: c.formatResult && c.formatResult(p) || o };
  345.         k[n].push(q);
  346.         if (j++ < c.max) {
  347.             k[""].push(q)
  348.         }
  349.     }
  350.     a.each(k, function(r, s) {
  351.     c.cacheLength++;
  352.     g(r, s)
  353. })
  354. }
  355. setTimeout(e, 25);
  356.  
  357. function b() {
  358.     f = {};
  359.     d = 0
  360. }
  361. return {
  362. flush: b,
  363. add: g,
  364. populate: e,
  365. load: function(n) {
  366. if (!c.cacheLength || !d) {
  367.     return null
  368. }
  369. if (!c.url && c.matchContains) {
  370.     var m = [];
  371.     for (var j in f) {
  372.         if (j.length > 0) {
  373.             var o = f[j]; a.each(o, function(p, k) {
  374.             if (h(k.value, n)) {
  375.                 m.push(k)
  376.             }
  377.         })
  378.     }
  379. }
  380. return m
  381. } else {
  382. if (f[n]) {
  383.     return f[n]
  384. } else {
  385. if (c.matchSubset) {
  386.     for (var l = n.length - 1; l >= c.minChars; l--) {
  387.         var o = f[n.substr(0, l)];
  388.         if (o) {
  389.             var m = [];
  390.             a.each(o, function(p, k) {
  391.             if (h(k.value, n)) {
  392.                 m[m.length] = k
  393.             }
  394.         });
  395.         return m
  396.     }
  397. }
  398. }
  399. }
  400. }
  401. return null
  402. }
  403. }
  404. };
  405.  
  406. a.TroppinAutocompleter.Select = function(e, j, l, p) {
  407. var i = { ACTIVE: "ac_over" };
  408. var k, f = -1, r, m = "", s = true, c, o;
  409. function n() {
  410.     if (!s) {
  411.         return
  412.     }
  413.     c = a("<div/>").hide().addClass(e.resultsClass).css("position", "absolute").appendTo(document.body); o = a("<ul/>").appendTo(c).mouseover(function(t) {
  414.         if (q(t).nodeName && q(t).nodeName.toUpperCase() == "LI") {
  415.             f = a("li", o).removeClass(i.ACTIVE).index(q(t));
  416.             a(q(t)).addClass(i.ACTIVE)
  417.         }
  418.     }).click(function(t) {
  419.     a(q(t)).addClass(i.ACTIVE);
  420.     l();
  421.     j.focus();
  422.     return false
  423. }).mousedown(function() { p.mouseDownOnSelect = true }).mouseup(function() { p.mouseDownOnSelect = false });
  424.  
  425. if (e.width > 0) {
  426.     c.css("width", e.width)
  427. }
  428. s = false
  429. }
  430.  
  431. function q(u) {
  432.     var t = u.target;
  433.     while (t && t.tagName != "LI") {
  434.         t = t.parentNode
  435.     }
  436.  
  437.     if (!t) {
  438.         return []
  439.     }
  440.     return t
  441. }
  442.  
  443. function h(t) {
  444.     k.slice(f, f + 1).removeClass(i.ACTIVE);
  445.     g(t);
  446.     var v = k.slice(f, f + 1).addClass(i.ACTIVE);
  447.     if (e.scroll) {
  448.         var u = 0;
  449.         k.slice(0, f).each(function() {
  450.         u += this.offsetHeight
  451.     });
  452.  
  453.     if ((u + v[0].offsetHeight - o.scrollTop()) > o[0].clientHeight) {
  454.         o.scrollTop(u + v[0].offsetHeight - o.innerHeight())
  455.     } else {
  456.     if (u < o.scrollTop()) {
  457.         o.scrollTop(u)
  458.     }
  459. }
  460. }
  461. }
  462.  
  463. function g(t) {
  464.     f += t;
  465.     if (f < 0) {
  466.         f = k.size() - 1
  467.     } else {
  468.     if (f >= k.size()) {
  469.         f = 0
  470.     }
  471. }
  472. }
  473.  
  474. function b(t) {
  475.     return e.max && e.max < t ? e.max : t
  476. }
  477.  
  478. function d() {
  479.     o.empty();
  480.     var u = b(r.length);
  481.     for (var v = 0; v < u; v++) {
  482.         if (!r[v]) {
  483.             continue
  484.         }
  485.         var w = e.formatItem(r[v].data, v + 1, u, r[v].value, m);
  486.         if (w === false) {
  487.             continue
  488.         }
  489.  
  490.         var t = a("<li/>").html(e.highlight(w, m)).addClass(v % 2 == 0 ? "ac_even" : "ac_odd").appendTo(o)[0];
  491.         a.data(t, "ac_data", r[v])
  492.     }
  493.     k = o.find("li");
  494.     if (e.selectFirst) {
  495.         k.slice(0, 1).addClass(i.ACTIVE);
  496.         f = 0
  497.     } if (a.fn.bgiframe) {
  498.         o.bgiframe()
  499.     }
  500. }
  501.  
  502. return { display: function(u, t) {
  503. n();
  504. r = u;
  505. m = t;
  506. d()
  507. },
  508. next: function() { h(1) },
  509. prev: function() { h(-1) },
  510. pageUp: function() {
  511. if (f != 0 && f - 8 < 0) {
  512.     h(-f)
  513. } else {
  514. h(-8)
  515. }
  516. },
  517. pageDown: function() {
  518. if (f != k.size() - 1 && f + 8 > k.size()) {
  519.     h(k.size() - 1 - f)
  520. } else {
  521.     h(8)
  522. }
  523. },
  524. hide: function() {
  525. c && c.hide();
  526. k && k.removeClass(i.ACTIVE);
  527. f = -1
  528. },
  529. visible: function() { return c && c.is(":visible") }, current: function() { return this.visible() && (k.filter("." + i.ACTIVE)[0] || e.selectFirst && k[0]) },
  530. show: function() {
  531. var v = a(j).offset();
  532. c.css({ width: typeof e.width == "string" || e.width > 0 ? e.width : a(j).width(), top: v.top + j.offsetHeight, left: v.left }).show();
  533.  
  534. if (e.scroll) {
  535.     o.scrollTop(0); o.css({ maxHeight: e.scrollHeight, overflow: "auto" });
  536.     if (a.browser.msie && typeof document.body.style.maxHeight === "undefined") {
  537.         var t = 0;
  538.         k.each(function() {
  539.         t += this.offsetHeight
  540.     });
  541.     var u = t > e.scrollHeight;
  542.     o.css("height", u ? e.scrollHeight : t);
  543.     if (!u) {
  544.         k.width(o.width() - parseInt(k.css("padding-left")) - parseInt(k.css("padding-right")))
  545.     }
  546. }
  547. }
  548. },
  549. selected: function() {
  550. var t = k && k.filter("." + i.ACTIVE).removeClass(i.ACTIVE);
  551. return t && t.length && a.data(t[0], "ac_data")
  552. }, emptyList: function() {
  553. o && o.empty()
  554. }, unbind: function() {
  555. c && c.remove()
  556. }
  557. }
  558. };
  559.  
  560. a.TroppinAutocompleter.Selection = function(d, e, c) {
  561. if (d.createTextRange) {
  562.     var b = d.createTextRange();
  563.     b.collapse(true);
  564.     b.moveStart("character", e);
  565.     b.moveEnd("character", c);
  566.     b.select()
  567. } else {
  568. if (d.setSelectionRange) {
  569.     d.setSelectionRange(e, c)
  570. } else {
  571. if (d.selectionStart) {
  572.     d.selectionStart = e;
  573.     d.selectionEnd = c
  574. }
  575. }
  576. }
  577.  
  578. d.focus()
  579. }
  580. })(jQuery);
  581.  
  582. (function(a) {
  583. a.fn.bgIframe = a.fn.bgiframe = function(c) {
  584. if (a.browser.msie && /6.0/.test(navigator.userAgent)) {
  585.     c = a.extend({ top: "auto", left: "auto", width: "auto", height: "auto", opacity: true, src: "javascript:false;" }, c || {});
  586.     var d = function(e) {
  587.     return e && e.constructor == Number ? e + "px" : e
  588. },
  589. b = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="' + c.src + '"style="display:block;position:absolute;z-index:-1;' + (c.opacity !== false ? "filter:Alpha(Opacity='0');" : "") + "top:" + (c.top == "auto" ? "expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+'px')" : d(c.top)) + ";left:" + (c.left == "auto" ? "expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+'px')" : d(c.left)) + ";width:" + (c.width == "auto" ? "expression(this.parentNode.offsetWidth+'px')" : d(c.width)) + ";height:" + (c.height == "auto" ? "expression(this.parentNode.offsetHeight+'px')" : d(c.height)) + ';"/>';
  590. return this.each(function() {
  591. if (a("> iframe.bgiframe", this).length == 0) {
  592.     this.insertBefore(document.createElement(b), this.firstChild)
  593. }
  594. })
  595. }
  596. return this
  597. }
  598. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement