From d744773bdc2620a4f86fa4ae69749effbd165986 Mon Sep 17 00:00:00 2001 From: Gildonei Mendes Anacleto Junior Date: Thu, 27 Oct 2016 17:04:08 -0200 Subject: [PATCH 1/2] Added parameter sort Added parameter sort to let user decide if options order should or not be sorted --- dist/dual-list-box.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/dist/dual-list-box.js b/dist/dual-list-box.js index 5fdf03f..712a62b 100644 --- a/dist/dual-list-box.js +++ b/dist/dual-list-box.js @@ -34,7 +34,8 @@ moveAllBtn: true, // Whether the append all button is available. maxAllBtn: 500, // Maximum size of list in which the all button works without warning. See below. selectClass:'form-control', - warning: 'Are you sure you want to move this many items? Doing so can cause your browser to become unresponsive.' + warning: 'Are you sure you want to move this many items? Doing so can cause your browser to become unresponsive.', + sort: true }; var htmlOptions = { @@ -49,7 +50,8 @@ textLength: $(this).data('textLength'), moveAllBtn: $(this).data('moveAllBtn'), maxAllBtn: $(this).data('maxAllBtn'), - selectClass:$(this).data('selectClass') + selectClass:$(this).data('selectClass'), + sort: $(this).data('sort') }; var options = $.extend({}, defaults, htmlOptions, paramOptions); @@ -142,8 +144,10 @@ default: break; } - unselected.filterByText($(options.parentElement + ' .filter-unselected'), options.timeout, options.parentElement).scrollTop(0).sortOptions(); - selected.filterByText($(options.parentElement + ' .filter-selected'), options.timeout, options.parentElement).scrollTop(0).sortOptions(); + if (options.sort) { + unselected.filterByText($(options.parentElement + ' .filter-unselected'), options.timeout, options.parentElement).scrollTop(0).sortOptions(); + selected.filterByText($(options.parentElement + ' .filter-selected'), options.timeout, options.parentElement).scrollTop(0).sortOptions(); + } handleMovement(options); }); @@ -158,8 +162,10 @@ } }); - selected.filterByText($(options.parentElement + ' .filter-selected'), options.timeout, options.parentElement).scrollTop(0).sortOptions(); - unselected.filterByText($(options.parentElement + ' .filter-unselected'), options.timeout, options.parentElement).scrollTop(0).sortOptions(); + if (options.sort) { + selected.filterByText($(options.parentElement + ' .filter-selected'), options.timeout, options.parentElement).scrollTop(0).sortOptions(); + unselected.filterByText($(options.parentElement + ' .filter-unselected'), options.timeout, options.parentElement).scrollTop(0).sortOptions(); + } } /** Constructs the jQuery plugin after the elements have been retrieved. */ @@ -349,4 +355,4 @@ timer = setTimeout(callback, ms); }; })(); -})(jQuery); \ No newline at end of file +})(jQuery); From 9615afa1e57038c695fc5af48238c730fcfa3ef2 Mon Sep 17 00:00:00 2001 From: Gildonei Mendes Anacleto Junior Date: Thu, 27 Oct 2016 17:05:27 -0200 Subject: [PATCH 2/2] Added parameter sort Added parameter sort to let user decide if options order should or not be sorted --- dist/dual-list-box.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/dual-list-box.min.js b/dist/dual-list-box.min.js index 6de2806..29d0c32 100644 --- a/dist/dual-list-box.min.js +++ b/dist/dual-list-box.min.js @@ -1 +1 @@ -(function($){$.fn.DualListBox=function(paramOptions,selected){return this.each(function(){var defaults={element:$(this).context,uri:"local.json",value:"id",text:"name",title:"Example",json:true,timeout:500,horizontal:false,textLength:45,moveAllBtn:true,maxAllBtn:500,selectClass:"form-control",warning:"Are you sure you want to move this many items? Doing so can cause your browser to become unresponsive."};var htmlOptions={element:$(this).context,uri:$(this).data("source"),value:$(this).data("value"),text:$(this).data("text"),title:$(this).data("title"),json:$(this).data("json"),timeout:$(this).data("timeout"),horizontal:$(this).data("horizontal"),textLength:$(this).data("textLength"),moveAllBtn:$(this).data("moveAllBtn"),maxAllBtn:$(this).data("maxAllBtn"),selectClass:$(this).data("selectClass")};var options=$.extend({},defaults,htmlOptions,paramOptions);$.each(options,function(i,item){if(item===undefined||item===null){throw"DualListBox: "+i+" is undefined."}});options["parent"]="dual-list-box-"+options.title;options["parentElement"]="#"+options.parent;selected=$.extend([{}],selected);if(options.json){addElementsViaJSON(options,selected)}else{construct(options)}})};function addElementsViaJSON(options,selected){var multipleTextFields=false;if(options.text.indexOf(":")>-1){var textToUse=options.text.split(":");if(textToUse.length>1){multipleTextFields=true}}$.getJSON(options.uri,function(json){$.each(json,function(key,item){var text="";if(multipleTextFields){textToUse.forEach(function(entry){text+=item[entry]+" "})}else{text=item[options.text]}$("