1//autocompletar_cb = function(){ 2// $(".autocompletar_cb").each(function() { 3// $(this).combobox(); 4// }); 5//} 6 7autocompletar = function() { 8 9 $(".autocompletar").each(function() { 10 var self = $(this); 11 var source = self.data('ajax-url'); //.split("_").pop(); 12 var target = self.data('target'); 13 //var children = $(this).attr('children'); 14 $(this).autocomplete({ 15 //search: _buscar(children), 16 messages: { 17 noResults: '', 18 results: function() { 19 } 20 }, 21 source: function(request, response) { 22 _fuente(request, response, source, target, parent) 23 }, 24 select: function(event, ui) { 25 _seleccionar(event, ui, target) 26 }, 27 open: function() { 28 $(this).css('z-index', 100); 29 return false; 30 }, 31 width: 300, 32 delay: 10, 33 cacheLength: 0, 34 scroll: false, 35 highlight: true, 36 minLength: 3 37 }).data('ui-autocomplete')._renderItem = _render; 38 }); 39} 40 41_render = function(ul, item) { 42 var re = new RegExp(this.term, "gi"); 43 var t = item.label.replace(re, '<span class="bold_autocomplete">' + '$&' + '</span>'); 44 var t2 = (item.path != null) ? item.path.replace(re, '<span class="bold_autocomplete">' + '$&' + '</span>') : null; 45 return $('<li></li>').data('ui-autocomplete-item', item).append('<a>' + t + ((t2 != null) ? '<span class="path">' + t2 + '</span>' : '') + '</a>').appendTo(ul); 46} 47 48_buscar = function(children) { 49 if (typeof children != 'undefined') { 50 var pieces = children.split(','); 51 $(pieces).each(function(i) { 52 $('#' + pieces[i] + '_hidden', '#' + pieces[i]).val(''); 53 $('#' + pieces[i]).val(''); 54 }); 55 } 56} 57 58_seleccionar = function(event, ui, target) { 59 if (ui.item.valido == true) { 60 $(this).val(ui.item.label); 61 $('#' + target).val(ui.item.id); 62 } 63 return false; 64} 65 66_fuente = function(request, response, source, target, parent) { 67 $.ajax({ 68 url: source, 69 dataType: "json", 70 data: { 71 val: request.term, 72 //p: $('#' + parent).val() 73 }, 74 type: 'post', 75 error: function() { 76 result = [{ 77 label: 'Sin resultados para: ' + request.term, 78 path: null, 79 value: null, 80 id: null, 81 valido: false 82 }]; 83 }, 84 success: function(data) { 85 var result = []; 86 if (data !== null && data.length > 0) { 87 $.map(data, function(item) { 88 var id = item.id; 89 var path = item.path; 90 var value = (typeof item.nombre != 'undefined') ? item.nombre : item.descripcion; 91 result.push({ 92 label: value, 93 path: path, 94 value: value, 95 id: id, 96 valido: true 97 }); 98 //$('#' + target).val(''); 99 }); 100 } else { 101 result = [{ 102 label: 'Sin resultados para: ' + request.term, 103 path: null, 104 value: null, 105 id: null, 106 valido: false 107 }]; 108 } 109 response(result); 110 } 111 }); 112} 113 114$(document).ready(function() { 115 116 autocompletar(); 117 118});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.