Edit File by line
/home/barbar84/public_h.../wp-inclu.../js/jquery
File: suggest.js
/*
[0] Fix | Delete
* jquery.suggest 1.1b - 2007-08-06
[1] Fix | Delete
* Patched by Mark Jaquith with Alexander Dick's "multiple items" patch to allow for auto-suggesting of more than one tag before submitting
[2] Fix | Delete
* See: http://www.vulgarisoip.com/2007/06/29/jquerysuggest-an-alternative-jquery-based-autocomplete-library/#comment-7228
[3] Fix | Delete
*
[4] Fix | Delete
* Uses code and techniques from following libraries:
[5] Fix | Delete
* 1. http://www.dyve.net/jquery/?autocomplete
[6] Fix | Delete
* 2. http://dev.jquery.com/browser/trunk/plugins/interface/iautocompleter.js
[7] Fix | Delete
*
[8] Fix | Delete
* All the new stuff written by Peter Vulgaris (www.vulgarisoip.com)
[9] Fix | Delete
* Feel free to do whatever you want with this file
[10] Fix | Delete
*
[11] Fix | Delete
*/
[12] Fix | Delete
[13] Fix | Delete
(function($) {
[14] Fix | Delete
[15] Fix | Delete
$.suggest = function(input, options) {
[16] Fix | Delete
var $input, $results, timeout, prevLength, cache, cacheSize;
[17] Fix | Delete
[18] Fix | Delete
$input = $(input).attr("autocomplete", "off");
[19] Fix | Delete
$results = $("<ul/>");
[20] Fix | Delete
[21] Fix | Delete
timeout = false; // hold timeout ID for suggestion results to appear
[22] Fix | Delete
prevLength = 0; // last recorded length of $input.val()
[23] Fix | Delete
cache = []; // cache MRU list
[24] Fix | Delete
cacheSize = 0; // size of cache in chars (bytes?)
[25] Fix | Delete
[26] Fix | Delete
$results.addClass(options.resultsClass).appendTo('body');
[27] Fix | Delete
[28] Fix | Delete
[29] Fix | Delete
resetPosition();
[30] Fix | Delete
$(window)
[31] Fix | Delete
.on( 'load', resetPosition ) // just in case user is changing size of page while loading
[32] Fix | Delete
.on( 'resize', resetPosition );
[33] Fix | Delete
[34] Fix | Delete
$input.blur(function() {
[35] Fix | Delete
setTimeout(function() { $results.hide() }, 200);
[36] Fix | Delete
});
[37] Fix | Delete
[38] Fix | Delete
$input.keydown(processKey);
[39] Fix | Delete
[40] Fix | Delete
function resetPosition() {
[41] Fix | Delete
// requires jquery.dimension plugin
[42] Fix | Delete
var offset = $input.offset();
[43] Fix | Delete
$results.css({
[44] Fix | Delete
top: (offset.top + input.offsetHeight) + 'px',
[45] Fix | Delete
left: offset.left + 'px'
[46] Fix | Delete
});
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
[50] Fix | Delete
function processKey(e) {
[51] Fix | Delete
[52] Fix | Delete
// handling up/down/escape requires results to be visible
[53] Fix | Delete
// handling enter/tab requires that AND a result to be selected
[54] Fix | Delete
if ((/27$|38$|40$/.test(e.keyCode) && $results.is(':visible')) ||
[55] Fix | Delete
(/^13$|^9$/.test(e.keyCode) && getCurrentResult())) {
[56] Fix | Delete
[57] Fix | Delete
if (e.preventDefault)
[58] Fix | Delete
e.preventDefault();
[59] Fix | Delete
if (e.stopPropagation)
[60] Fix | Delete
e.stopPropagation();
[61] Fix | Delete
[62] Fix | Delete
e.cancelBubble = true;
[63] Fix | Delete
e.returnValue = false;
[64] Fix | Delete
[65] Fix | Delete
switch(e.keyCode) {
[66] Fix | Delete
[67] Fix | Delete
case 38: // up
[68] Fix | Delete
prevResult();
[69] Fix | Delete
break;
[70] Fix | Delete
[71] Fix | Delete
case 40: // down
[72] Fix | Delete
nextResult();
[73] Fix | Delete
break;
[74] Fix | Delete
[75] Fix | Delete
case 9: // tab
[76] Fix | Delete
case 13: // return
[77] Fix | Delete
selectCurrentResult();
[78] Fix | Delete
break;
[79] Fix | Delete
[80] Fix | Delete
case 27: // escape
[81] Fix | Delete
$results.hide();
[82] Fix | Delete
break;
[83] Fix | Delete
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
} else if ($input.val().length != prevLength) {
[87] Fix | Delete
[88] Fix | Delete
if (timeout)
[89] Fix | Delete
clearTimeout(timeout);
[90] Fix | Delete
timeout = setTimeout(suggest, options.delay);
[91] Fix | Delete
prevLength = $input.val().length;
[92] Fix | Delete
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
[99] Fix | Delete
function suggest() {
[100] Fix | Delete
[101] Fix | Delete
var q = $.trim($input.val()), multipleSepPos, items;
[102] Fix | Delete
[103] Fix | Delete
if ( options.multiple ) {
[104] Fix | Delete
multipleSepPos = q.lastIndexOf(options.multipleSep);
[105] Fix | Delete
if ( multipleSepPos != -1 ) {
[106] Fix | Delete
q = $.trim(q.substr(multipleSepPos + options.multipleSep.length));
[107] Fix | Delete
}
[108] Fix | Delete
}
[109] Fix | Delete
if (q.length >= options.minchars) {
[110] Fix | Delete
[111] Fix | Delete
cached = checkCache(q);
[112] Fix | Delete
[113] Fix | Delete
if (cached) {
[114] Fix | Delete
[115] Fix | Delete
displayItems(cached['items']);
[116] Fix | Delete
[117] Fix | Delete
} else {
[118] Fix | Delete
[119] Fix | Delete
$.get(options.source, {q: q}, function(txt) {
[120] Fix | Delete
[121] Fix | Delete
$results.hide();
[122] Fix | Delete
[123] Fix | Delete
items = parseTxt(txt, q);
[124] Fix | Delete
[125] Fix | Delete
displayItems(items);
[126] Fix | Delete
addToCache(q, items, txt.length);
[127] Fix | Delete
[128] Fix | Delete
});
[129] Fix | Delete
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
} else {
[133] Fix | Delete
[134] Fix | Delete
$results.hide();
[135] Fix | Delete
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
[141] Fix | Delete
function checkCache(q) {
[142] Fix | Delete
var i;
[143] Fix | Delete
for (i = 0; i < cache.length; i++)
[144] Fix | Delete
if (cache[i]['q'] == q) {
[145] Fix | Delete
cache.unshift(cache.splice(i, 1)[0]);
[146] Fix | Delete
return cache[0];
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
return false;
[150] Fix | Delete
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
function addToCache(q, items, size) {
[154] Fix | Delete
var cached;
[155] Fix | Delete
while (cache.length && (cacheSize + size > options.maxCacheSize)) {
[156] Fix | Delete
cached = cache.pop();
[157] Fix | Delete
cacheSize -= cached['size'];
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
cache.push({
[161] Fix | Delete
q: q,
[162] Fix | Delete
size: size,
[163] Fix | Delete
items: items
[164] Fix | Delete
});
[165] Fix | Delete
[166] Fix | Delete
cacheSize += size;
[167] Fix | Delete
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
function displayItems(items) {
[171] Fix | Delete
var html = '', i;
[172] Fix | Delete
if (!items)
[173] Fix | Delete
return;
[174] Fix | Delete
[175] Fix | Delete
if (!items.length) {
[176] Fix | Delete
$results.hide();
[177] Fix | Delete
return;
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
resetPosition(); // when the form moves after the page has loaded
[181] Fix | Delete
[182] Fix | Delete
for (i = 0; i < items.length; i++)
[183] Fix | Delete
html += '<li>' + items[i] + '</li>';
[184] Fix | Delete
[185] Fix | Delete
$results.html(html).show();
[186] Fix | Delete
[187] Fix | Delete
$results
[188] Fix | Delete
.children('li')
[189] Fix | Delete
.mouseover(function() {
[190] Fix | Delete
$results.children('li').removeClass(options.selectClass);
[191] Fix | Delete
$(this).addClass(options.selectClass);
[192] Fix | Delete
})
[193] Fix | Delete
.click(function(e) {
[194] Fix | Delete
e.preventDefault();
[195] Fix | Delete
e.stopPropagation();
[196] Fix | Delete
selectCurrentResult();
[197] Fix | Delete
});
[198] Fix | Delete
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
function parseTxt(txt, q) {
[202] Fix | Delete
[203] Fix | Delete
var items = [], tokens = txt.split(options.delimiter), i, token;
[204] Fix | Delete
[205] Fix | Delete
// parse returned data for non-empty items
[206] Fix | Delete
for (i = 0; i < tokens.length; i++) {
[207] Fix | Delete
token = $.trim(tokens[i]);
[208] Fix | Delete
if (token) {
[209] Fix | Delete
token = token.replace(
[210] Fix | Delete
new RegExp(q, 'ig'),
[211] Fix | Delete
function(q) { return '<span class="' + options.matchClass + '">' + q + '</span>' }
[212] Fix | Delete
);
[213] Fix | Delete
items[items.length] = token;
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
return items;
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
function getCurrentResult() {
[221] Fix | Delete
var $currentResult;
[222] Fix | Delete
if (!$results.is(':visible'))
[223] Fix | Delete
return false;
[224] Fix | Delete
[225] Fix | Delete
$currentResult = $results.children('li.' + options.selectClass);
[226] Fix | Delete
[227] Fix | Delete
if (!$currentResult.length)
[228] Fix | Delete
$currentResult = false;
[229] Fix | Delete
[230] Fix | Delete
return $currentResult;
[231] Fix | Delete
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
function selectCurrentResult() {
[235] Fix | Delete
[236] Fix | Delete
$currentResult = getCurrentResult();
[237] Fix | Delete
[238] Fix | Delete
if ($currentResult) {
[239] Fix | Delete
if ( options.multiple ) {
[240] Fix | Delete
if ( $input.val().indexOf(options.multipleSep) != -1 ) {
[241] Fix | Delete
$currentVal = $input.val().substr( 0, ( $input.val().lastIndexOf(options.multipleSep) + options.multipleSep.length ) ) + ' ';
[242] Fix | Delete
} else {
[243] Fix | Delete
$currentVal = "";
[244] Fix | Delete
}
[245] Fix | Delete
$input.val( $currentVal + $currentResult.text() + options.multipleSep + ' ' );
[246] Fix | Delete
$input.focus();
[247] Fix | Delete
} else {
[248] Fix | Delete
$input.val($currentResult.text());
[249] Fix | Delete
}
[250] Fix | Delete
$results.hide();
[251] Fix | Delete
$input.trigger('change');
[252] Fix | Delete
[253] Fix | Delete
if (options.onSelect)
[254] Fix | Delete
options.onSelect.apply($input[0]);
[255] Fix | Delete
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
function nextResult() {
[261] Fix | Delete
[262] Fix | Delete
$currentResult = getCurrentResult();
[263] Fix | Delete
[264] Fix | Delete
if ($currentResult)
[265] Fix | Delete
$currentResult
[266] Fix | Delete
.removeClass(options.selectClass)
[267] Fix | Delete
.next()
[268] Fix | Delete
.addClass(options.selectClass);
[269] Fix | Delete
else
[270] Fix | Delete
$results.children('li:first-child').addClass(options.selectClass);
[271] Fix | Delete
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
function prevResult() {
[275] Fix | Delete
var $currentResult = getCurrentResult();
[276] Fix | Delete
[277] Fix | Delete
if ($currentResult)
[278] Fix | Delete
$currentResult
[279] Fix | Delete
.removeClass(options.selectClass)
[280] Fix | Delete
.prev()
[281] Fix | Delete
.addClass(options.selectClass);
[282] Fix | Delete
else
[283] Fix | Delete
$results.children('li:last-child').addClass(options.selectClass);
[284] Fix | Delete
[285] Fix | Delete
}
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
$.fn.suggest = function(source, options) {
[289] Fix | Delete
[290] Fix | Delete
if (!source)
[291] Fix | Delete
return;
[292] Fix | Delete
[293] Fix | Delete
options = options || {};
[294] Fix | Delete
options.multiple = options.multiple || false;
[295] Fix | Delete
options.multipleSep = options.multipleSep || ",";
[296] Fix | Delete
options.source = source;
[297] Fix | Delete
options.delay = options.delay || 100;
[298] Fix | Delete
options.resultsClass = options.resultsClass || 'ac_results';
[299] Fix | Delete
options.selectClass = options.selectClass || 'ac_over';
[300] Fix | Delete
options.matchClass = options.matchClass || 'ac_match';
[301] Fix | Delete
options.minchars = options.minchars || 2;
[302] Fix | Delete
options.delimiter = options.delimiter || '\n';
[303] Fix | Delete
options.onSelect = options.onSelect || false;
[304] Fix | Delete
options.maxCacheSize = options.maxCacheSize || 65536;
[305] Fix | Delete
[306] Fix | Delete
this.each(function() {
[307] Fix | Delete
new $.suggest(this, options);
[308] Fix | Delete
});
[309] Fix | Delete
[310] Fix | Delete
return this;
[311] Fix | Delete
[312] Fix | Delete
};
[313] Fix | Delete
[314] Fix | Delete
})(jQuery);
[315] Fix | Delete
[316] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function