/** * combobox - jQuery EasyUI * * Licensed under the GPL terms * To use it on other terms please contact us * * Copyright(c) 2009-2012 stworthy [ stworthy@gmail.com ] * * Dependencies: * combo * */ (function($){ /** * scroll panel to display the specified item */ function scrollTo(target, value){ var panel = $(target).combo('panel'); var item = panel.find('div.combobox-item[value="' + value + '"]'); if (item.length){ if (item.position().top <= 0){ var h = panel.scrollTop() + item.position().top; panel.scrollTop(h); } else if (item.position().top + item.outerHeight() > panel.height()){ var h = panel.scrollTop() + item.position().top + item.outerHeight() - panel.height(); panel.scrollTop(h); } } } /** * select previous item */ function selectPrev(target){ var panel = $(target).combo('panel'); var values = $(target).combo('getValues'); var item = panel.find('div.combobox-item[value="' + values.pop() + '"]'); if (item.length){ var prev = item.prev(':visible'); if (prev.length){ item = prev; } } else { item = panel.find('div.combobox-item:visible:last'); } var value = item.attr('value'); select(target, value); // setValues(target, [value]); scrollTo(target, value); } /** * select next item */ function selectNext(target){ var panel = $(target).combo('panel'); var values = $(target).combo('getValues'); var item = panel.find('div.combobox-item[value="' + values.pop() + '"]'); if (item.length){ var next = item.next(':visible'); if (next.length){ item = next; } } else { item = panel.find('div.combobox-item:visible:first'); } var value = item.attr('value'); select(target, value); // setValues(target, [value]); scrollTo(target, value); } /** * select the specified value */ function select(target, value){ var opts = $.data(target, 'combobox').options; var data = $.data(target, 'combobox').data; if (opts.multiple){ var values = $(target).combo('getValues'); for(var i=0; ioption', target).each(function(){ var item = {}; item[opts.valueField] = $(this).attr('value')!=undefined ? $(this).attr('value') : $(this).html(); item[opts.textField] = $(this).html(); item['selected'] = $(this).attr('selected'); data.push(item); }); return data; } /** * load data, the old list items will be removed. */ function loadData(target, data, remainText){ var opts = $.data(target, 'combobox').options; var panel = $(target).combo('panel'); $.data(target, 'combobox').data = data; var selected = $(target).combobox('getValues'); panel.empty(); // clear old data for(var i=0; i').appendTo(panel); item.attr('value', v); if (opts.formatter){ item.html(opts.formatter.call(target, data[i])); } else { item.html(s); } if (data[i]['selected']){ (function(){ for(var i=0; i