1// jCombo v2.0 2// Carlos De Oliveira [email protected] (c) Feb 2013 3;(function ($, window, document, undefined) { 4 $.fn.jCombo = function(url, opt) { 5 var defaults = { 6 parentField: null, 7 first_optval : "__jcombo__", 8 selected_value : "0", 9 initial_text: "-- Please Select --", 10 method: "GET", 11 dataType: "jsonp" 12 }; 13 var opt = $.extend( defaults, opt) ; 14 var obj = $(this); 15 if(opt.parentField!=null) { 16 var $parentField = $(opt.parentField); 17 $parentField.removeAttr("disabled","disabled"); 18 $parentField.bind('change', function(e) { 19 obj.attr("disabled","disabled"); 20 if($(this).val() != opt.first_optval || globalParent != null) obj.removeAttr("disabled"); 21 __render( obj, { 22 url: url, 23 id: $(this).val(), 24 first_optval: opt.first_optval, 25 initext: opt.initial_text, 26 inival: opt.selected_value, 27 method: opt.method, 28 dataType: opt.dataType 29 }); 30 }); 31 } else __render(obj,{ 32 url: url, 33 id: "", 34 first_optval: opt.first_optval, 35 initext: opt.initial_text, 36 inival: opt.selected_value, 37 method: opt.method, 38 dataType: opt.dataType 39 }); 40 function __render($obj,$options) { 41 var parentColumn = (globalParent != null) ? globalParent.split('-') : (opt.parentField) ? opt.parentField.split('-') : ''; 42 if($options.id==null) return false; 43 if(parentColumn){ 44 parentColumn = parentColumn[2]; 45 } 46 var locId = (globalParent != null) ? $(globalParent).val() : $options.id; 47 $.ajax({ 48 type: $options.method, 49 dataType: $options.dataType, 50 url: $options.url, 51 data: { 52 parent: parentColumn, 53 id: locId 54 }, 55 error:function(){ 56 globalParent = (globalParent != null) ? globalParent : opt.parentField; 57 var response = '<option value="" selected="selected">N/A</option>'; 58 $obj.html(response); 59 $obj.trigger("change"); 60 }, 61 success: function(data){ 62 globalParent = null; 63 var response = '<option value="' + $options.first_optval + '">' + $options.initext + '</option>'; 64 var selected; 65 for(var index in data) { 66 selected = (index==$options.inival)?' selected="selected"':''; 67 response += '<option value="' + index + '"' + selected + '>' + data[index] + '</option>'; 68 } 69 $obj.html(response); 70 $obj.trigger("change"); 71 } 72 }); 73 } 74 } 75})( jQuery, window, document );
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.