From 5cd46e5a0da3841719d0676a06c963c70c5a524c Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Mon, 9 Nov 2015 01:15:12 +0100 Subject: Created theme for apigen4, wsat doc fixes --- .../apigen/pradosoft/js/jquery.autocomplete.js | 178 +++++++++++++-------- 1 file changed, 110 insertions(+), 68 deletions(-) (limited to 'buildscripts/apigen/pradosoft/js/jquery.autocomplete.js') diff --git a/buildscripts/apigen/pradosoft/js/jquery.autocomplete.js b/buildscripts/apigen/pradosoft/js/jquery.autocomplete.js index b8bec34d..ecc032da 100644 --- a/buildscripts/apigen/pradosoft/js/jquery.autocomplete.js +++ b/buildscripts/apigen/pradosoft/js/jquery.autocomplete.js @@ -1,5 +1,5 @@ -/*! - * jQuery Autocomplete plugin 1.1 +/* + * jQuery Autocomplete plugin 1.2.3 * * Copyright (c) 2009 Jörn Zaefferer * @@ -7,7 +7,9 @@ * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * - * Revision: $Id: jquery.autocomplete.js 15 2009-08-22 10:30:27Z joern.zaefferer $ + * With small modifications by Alfonso Gómez-Arzola. + * See changelog for details. + * */ ;(function($) { @@ -19,7 +21,8 @@ $.fn.extend({ url: isUrl ? urlOrData : null, data: isUrl ? null : urlOrData, delay: isUrl ? $.Autocompleter.defaults.delay : 10, - max: options && !options.scroll ? 10 : 150 + max: options && !options.scroll ? 10 : 150, + noRecord: "No Records." }, options); // if highlight is set to false, replace it with a do-nothing function @@ -28,8 +31,6 @@ $.fn.extend({ // if the formatMatch option is not specified, then use formatItem for backwards compatibility options.formatMatch = options.formatMatch || options.formatItem; - options.show = options.show || function(list) {}; - return this.each(function() { new $.Autocompleter(this, options); }); @@ -66,6 +67,11 @@ $.Autocompleter = function(input, options) { BACKSPACE: 8 }; + var globalFailure = null; + if(options.failure != null && typeof options.failure == "function") { + globalFailure = options.failure; + } + // Create $ object for input element var $input = $(input).attr("autocomplete", "off").addClass(options.inputClass); @@ -79,8 +85,18 @@ $.Autocompleter = function(input, options) { }; var select = $.Autocompleter.Select(options, input, selectCurrent, config); - // only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all - $input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) { + var blockSubmit; + + // prevent form submit in opera when selecting with return key + navigator.userAgent.indexOf("Opera") != -1 && $(input.form).bind("submit.autocomplete", function() { + if (blockSubmit) { + blockSubmit = false; + return false; + } + }); + + // older versions of opera don't trigger keydown multiple times while pressed, others don't work with keypress at all + $input.bind((navigator.userAgent.indexOf("Opera") != -1 && !'KeyboardEvent' in window ? "keypress" : "keydown") + ".autocomplete", function(event) { // a keypress means the input has focus // avoids issue where input had focus before the autocomplete was applied hasFocus = 1; @@ -89,8 +105,8 @@ $.Autocompleter = function(input, options) { switch(event.keyCode) { case KEY.UP: - event.preventDefault(); if ( select.visible() ) { + event.preventDefault(); select.prev(); } else { onChange(0, true); @@ -98,8 +114,8 @@ $.Autocompleter = function(input, options) { break; case KEY.DOWN: - event.preventDefault(); if ( select.visible() ) { + event.preventDefault(); select.next(); } else { onChange(0, true); @@ -107,8 +123,8 @@ $.Autocompleter = function(input, options) { break; case KEY.PAGEUP: - event.preventDefault(); if ( select.visible() ) { + event.preventDefault(); select.pageUp(); } else { onChange(0, true); @@ -116,8 +132,8 @@ $.Autocompleter = function(input, options) { break; case KEY.PAGEDOWN: - event.preventDefault(); if ( select.visible() ) { + event.preventDefault(); select.pageDown(); } else { onChange(0, true); @@ -129,8 +145,10 @@ $.Autocompleter = function(input, options) { case KEY.TAB: case KEY.RETURN: if( selectCurrent() ) { - //event.preventDefault(); - //return false; + // stop default to prevent a form submit, Opera needs special handling + event.preventDefault(); + blockSubmit = true; + return false; } break; @@ -148,17 +166,24 @@ $.Autocompleter = function(input, options) { // results if the field no longer has focus hasFocus++; }).blur(function() { - hasFocus = 0; + hasFocus = 0; if (!config.mouseDownOnSelect) { hideResults(); } }).click(function() { // show select when clicking in a focused field - if ( hasFocus++ > 1 && !select.visible() ) { - onChange(0, true); + // but if clickFire is true, don't require field + // to be focused to begin with; just show select + if( options.clickFire ) { + if ( !select.visible() ) { + onChange(0, true); + } + } else { + if ( hasFocus++ > 1 && !select.visible() ) { + onChange(0, true); + } } }).bind("search", function() { - // TODO why not just specifying both arguments? var fn = (arguments.length > 1) ? arguments[1] : null; function findValueCallback(q, data) { var result; @@ -179,7 +204,7 @@ $.Autocompleter = function(input, options) { }).bind("flushCache", function() { cache.flush(); }).bind("setOptions", function() { - $.extend(options, arguments[1]); + $.extend(true, options, arguments[1]); // if we've updated the data, repopulate if ( "data" in arguments[1] ) cache.populate(); @@ -213,7 +238,6 @@ $.Autocompleter = function(input, options) { progress += seperator; }); words[wordAt] = v; - // TODO this should set the cursor to the right position, but it gets overriden somewhere //$.Autocompleter.Selection(input, progress + seperator, progress + seperator); v = words.join( options.multipleSeparator ); } @@ -336,8 +360,14 @@ $.Autocompleter = function(input, options) { term = term.toLowerCase(); var data = cache.load(term); // recieve the cached data - if (data && data.length) { - success(term, data); + if (data) { + if(data.length) { + success(term, data); + } + else{ + var parsed = options.parse && options.parse(options.noRecord) || parse(options.noRecord); + success(term,parsed); + } // if an AJAX url has been supplied, try loading the data now } else if( (typeof options.url == "string") && (options.url.length > 0) ){ @@ -368,7 +398,12 @@ $.Autocompleter = function(input, options) { } else { // if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match select.emptyList(); - failure(term); + if(globalFailure != null) { + globalFailure(); + } + else { + failure(term); + } } }; @@ -404,8 +439,8 @@ $.Autocompleter.defaults = { matchCase: false, matchSubset: true, matchContains: false, - cacheLength: 10, - max: 100, + cacheLength: 100, + max: 1000, mustMatch: false, extraParams: {}, selectFirst: true, @@ -414,12 +449,15 @@ $.Autocompleter.defaults = { autoFill: false, width: 0, multiple: false, - multipleSeparator: ", ", + multipleSeparator: " ", + inputFocus: true, + clickFire: false, highlight: function(value, term) { return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "$1"); }, - scroll: true, - scrollHeight: 180 + scroll: true, + scrollHeight: 180, + scrollJumpPosition: true }; $.Autocompleter.Cache = function(options) { @@ -428,14 +466,9 @@ $.Autocompleter.Cache = function(options) { var length = 0; function matchSubset(s, sub) { - if (!options.matchCase) - s = s.toLowerCase(); - var i = s.indexOf(sub); - if (options.matchContains == "word"){ - i = s.toLowerCase().search("\\b" + sub.toLowerCase()); - } - if (i == -1) return false; - return i == 0 || options.matchContains; + return (new RegExp(sub.toUpperCase().replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1").replace(/[A-Z0-9]/g, function(m, offset) { + return offset === 0 ? '(?:' + m + '|^' + m.toLowerCase() + ')' : '(?:.*' + m + '|' + m.toLowerCase() + ')'; + }))).test(s); // find by initials }; function add(q, value) { @@ -467,7 +500,7 @@ $.Autocompleter.Cache = function(options) { rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue; var value = options.formatMatch(rawValue, i+1, options.data.length); - if ( value === false ) + if ( typeof(value) === 'undefined' || value === false ) continue; var firstChar = value.charAt(0).toLowerCase(); @@ -582,18 +615,25 @@ $.Autocompleter.Select = function (options, input, select, config) { .hide() .addClass(options.resultsClass) .css("position", "absolute") - .appendTo(document.body); + .appendTo(document.body) + .hover(function(event) { + // Browsers except FF do not fire mouseup event on scrollbars, resulting in mouseDownOnSelect remaining true, and results list not always hiding. + if($(this).is(":visible")) { + input.focus(); + } + config.mouseDownOnSelect = false; + }); list = $("