-
+ 58F566E9688BBF7461AE81DFCCA82360F54EFFBB3EA29D7FA039DD36F3DF497214971AABD9730E26E04A7A0294B217B27FF5F12085609708F9A039C42097E09A
mp-wp/wp-includes/js/jquery/suggest.js
(0 . 0)(1 . 332)
102500 /*
102501 * jquery.suggest 1.1b - 2007-08-06
102502 * Patched by Mark Jaquith with Alexander Dick's "multiple items" patch to allow for auto-suggesting of more than one tag before submitting
102503 * See: http://www.vulgarisoip.com/2007/06/29/jquerysuggest-an-alternative-jquery-based-autocomplete-library/#comment-7228
102504 *
102505 * Uses code and techniques from following libraries:
102506 * 1. http://www.dyve.net/jquery/?autocomplete
102507 * 2. http://dev.jquery.com/browser/trunk/plugins/interface/iautocompleter.js
102508 *
102509 * All the new stuff written by Peter Vulgaris (www.vulgarisoip.com)
102510 * Feel free to do whatever you want with this file
102511 *
102512 */
102513
102514 (function($) {
102515
102516 $.suggest = function(input, options) {
102517
102518 var $input = $(input).attr("autocomplete", "off");
102519 var $results = $(document.createElement("ul"));
102520
102521 var timeout = false; // hold timeout ID for suggestion results to appear
102522 var prevLength = 0; // last recorded length of $input.val()
102523 var cache = []; // cache MRU list
102524 var cacheSize = 0; // size of cache in chars (bytes?)
102525
102526 $results.addClass(options.resultsClass).appendTo('body');
102527
102528
102529 resetPosition();
102530 $(window)
102531 .load(resetPosition) // just in case user is changing size of page while loading
102532 .resize(resetPosition);
102533
102534 $input.blur(function() {
102535 setTimeout(function() { $results.hide() }, 200);
102536 });
102537
102538
102539 // help IE users if possible
102540 try {
102541 $results.bgiframe();
102542 } catch(e) { }
102543
102544
102545 // I really hate browser detection, but I don't see any other way
102546 if ($.browser.mozilla)
102547 $input.keypress(processKey); // onkeypress repeats arrow keys in Mozilla/Opera
102548 else
102549 $input.keydown(processKey); // onkeydown repeats arrow keys in IE/Safari
102550
102551
102552
102553
102554 function resetPosition() {
102555 // requires jquery.dimension plugin
102556 var offset = $input.offset();
102557 $results.css({
102558 top: (offset.top + input.offsetHeight) + 'px',
102559 left: offset.left + 'px'
102560 });
102561 }
102562
102563
102564 function processKey(e) {
102565
102566 // handling up/down/escape requires results to be visible
102567 // handling enter/tab requires that AND a result to be selected
102568 if ((/27$|38$|40$/.test(e.keyCode) && $results.is(':visible')) ||
102569 (/^13$|^9$/.test(e.keyCode) && getCurrentResult())) {
102570
102571 if (e.preventDefault)
102572 e.preventDefault();
102573 if (e.stopPropagation)
102574 e.stopPropagation();
102575
102576 e.cancelBubble = true;
102577 e.returnValue = false;
102578
102579 switch(e.keyCode) {
102580
102581 case 38: // up
102582 prevResult();
102583 break;
102584
102585 case 40: // down
102586 nextResult();
102587 break;
102588
102589 case 9: // tab
102590 case 13: // return
102591 selectCurrentResult();
102592 break;
102593
102594 case 27: // escape
102595 $results.hide();
102596 break;
102597
102598 }
102599
102600 } else if ($input.val().length != prevLength) {
102601
102602 if (timeout)
102603 clearTimeout(timeout);
102604 timeout = setTimeout(suggest, options.delay);
102605 prevLength = $input.val().length;
102606
102607 }
102608
102609
102610 }
102611
102612
102613 function suggest() {
102614
102615 var q = $.trim($input.val());
102616
102617 if ( options.multiple ) {
102618 var multipleSepPos = q.lastIndexOf(options.multipleSep);
102619 if ( multipleSepPos != -1 ) {
102620 q = q.substr(multipleSepPos + options.multipleSep.length);
102621 }
102622 }
102623 if (q.length >= options.minchars) {
102624
102625 cached = checkCache(q);
102626
102627 if (cached) {
102628
102629 displayItems(cached['items']);
102630
102631 } else {
102632
102633 $.get(options.source, {q: q}, function(txt) {
102634
102635 $results.hide();
102636
102637 var items = parseTxt(txt, q);
102638
102639 displayItems(items);
102640 addToCache(q, items, txt.length);
102641
102642 });
102643
102644 }
102645
102646 } else {
102647
102648 $results.hide();
102649
102650 }
102651
102652 }
102653
102654
102655 function checkCache(q) {
102656
102657 for (var i = 0; i < cache.length; i++)
102658 if (cache[i]['q'] == q) {
102659 cache.unshift(cache.splice(i, 1)[0]);
102660 return cache[0];
102661 }
102662
102663 return false;
102664
102665 }
102666
102667 function addToCache(q, items, size) {
102668
102669 while (cache.length && (cacheSize + size > options.maxCacheSize)) {
102670 var cached = cache.pop();
102671 cacheSize -= cached['size'];
102672 }
102673
102674 cache.push({
102675 q: q,
102676 size: size,
102677 items: items
102678 });
102679
102680 cacheSize += size;
102681
102682 }
102683
102684 function displayItems(items) {
102685
102686 if (!items)
102687 return;
102688
102689 if (!items.length) {
102690 $results.hide();
102691 return;
102692 }
102693
102694 resetPosition(); // when the form moves after the page has loaded
102695
102696 var html = '';
102697 for (var i = 0; i < items.length; i++)
102698 html += '<li>' + items[i] + '</li>';
102699
102700 $results.html(html).show();
102701
102702 $results
102703 .children('li')
102704 .mouseover(function() {
102705 $results.children('li').removeClass(options.selectClass);
102706 $(this).addClass(options.selectClass);
102707 })
102708 .click(function(e) {
102709 e.preventDefault();
102710 e.stopPropagation();
102711 selectCurrentResult();
102712 });
102713
102714 }
102715
102716 function parseTxt(txt, q) {
102717
102718 var items = [];
102719 var tokens = txt.split(options.delimiter);
102720
102721 // parse returned data for non-empty items
102722 for (var i = 0; i < tokens.length; i++) {
102723 var token = $.trim(tokens[i]);
102724 if (token) {
102725 token = token.replace(
102726 new RegExp(q, 'ig'),
102727 function(q) { return '<span class="' + options.matchClass + '">' + q + '</span>' }
102728 );
102729 items[items.length] = token;
102730 }
102731 }
102732
102733 return items;
102734 }
102735
102736 function getCurrentResult() {
102737
102738 if (!$results.is(':visible'))
102739 return false;
102740
102741 var $currentResult = $results.children('li.' + options.selectClass);
102742
102743 if (!$currentResult.length)
102744 $currentResult = false;
102745
102746 return $currentResult;
102747
102748 }
102749
102750 function selectCurrentResult() {
102751
102752 $currentResult = getCurrentResult();
102753
102754 if ($currentResult) {
102755 if ( options.multiple ) {
102756 if ( $input.val().indexOf(options.multipleSep) != -1 ) {
102757 $currentVal = $input.val().substr( 0, ( $input.val().lastIndexOf(options.multipleSep) + options.multipleSep.length ) );
102758 } else {
102759 $currentVal = "";
102760 }
102761 $input.val( $currentVal + $currentResult.text() + options.multipleSep);
102762 $input.focus();
102763 } else {
102764 $input.val($currentResult.text());
102765 }
102766 $results.hide();
102767
102768 if (options.onSelect)
102769 options.onSelect.apply($input[0]);
102770
102771 }
102772
102773 }
102774
102775 function nextResult() {
102776
102777 $currentResult = getCurrentResult();
102778
102779 if ($currentResult)
102780 $currentResult
102781 .removeClass(options.selectClass)
102782 .next()
102783 .addClass(options.selectClass);
102784 else
102785 $results.children('li:first-child').addClass(options.selectClass);
102786
102787 }
102788
102789 function prevResult() {
102790
102791 $currentResult = getCurrentResult();
102792
102793 if ($currentResult)
102794 $currentResult
102795 .removeClass(options.selectClass)
102796 .prev()
102797 .addClass(options.selectClass);
102798 else
102799 $results.children('li:last-child').addClass(options.selectClass);
102800
102801 }
102802
102803 }
102804
102805 $.fn.suggest = function(source, options) {
102806
102807 if (!source)
102808 return;
102809
102810 options = options || {};
102811 options.multiple = options.multiple || false;
102812 options.multipleSep = options.multipleSep || ", ";
102813 options.source = source;
102814 options.delay = options.delay || 100;
102815 options.resultsClass = options.resultsClass || 'ac_results';
102816 options.selectClass = options.selectClass || 'ac_over';
102817 options.matchClass = options.matchClass || 'ac_match';
102818 options.minchars = options.minchars || 2;
102819 options.delimiter = options.delimiter || '\n';
102820 options.onSelect = options.onSelect || false;
102821 options.maxCacheSize = options.maxCacheSize || 65536;
102822
102823 this.each(function() {
102824 new $.suggest(this, options);
102825 });
102826
102827 return this;
102828
102829 };
102830
102831 })(jQuery);