-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectList.lib.js
More file actions
10 lines (10 loc) · 2.53 KB
/
selectList.lib.js
File metadata and controls
10 lines (10 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
/*
Info:
Plugin: selectList
Version: 1.0
Author: Sujan Byanjankar
E-mail: sujan.byanjankar@gmail.com
Website: https://sujanbyanjankar.com.np
https://github.com/ktmcodelabs/selectList
*/
*!function(e){e.fn.selectList=function(t){var o=e.extend({from:"#fromList",to:"#toList",sort:!0,adder:"#add",remover:"#remove",mover:"#move",cleaner:"#clean",notifier:"select-highlight",notifytimer:800,fromSearch:"#fromListSearch",toSearch:"#toListSearch"},t),n=e(this).find(o.from),r=e(this).find(o.to),f=e(this).find(o.adder),s=e(this).find(o.remover),c=e(this).find(o.mover),a=e(this).find(o.cleaner),l=e(this).find(o.fromSearch),d=e(this).find(o.toSearch);f.click(function(t){var i=n.find("option:selected");0==i.length&&(alert("Select item to move."),t.preventDefault()),r.append(e(i).clone().addClass(o.notifier)),e(i).remove(),t.preventDefault(),p.sortOptionList(o.to),p.removeNotification(o.to),p.setSelected()}),s.click(function(t){var i=r.find("option:selected");0==i.length&&(alert("Select item to move."),t.preventDefault()),n.append(e(i).clone().addClass(o.notifier)),e(i).remove(),t.preventDefault(),p.sortOptionList(o.from),p.removeNotification(o.from),p.setSelected()}),n.on("dblclick","option",function(t){r.append(e(this).clone().addClass(o.notifier)),e(this).remove(),t.preventDefault(),p.sortOptionList(o.to),p.removeNotification(o.to),p.setSelected()}),r.on("dblclick","option",function(t){n.append(e(this).clone().addClass(o.notifier)),e(this).remove(),t.preventDefault(),p.sortOptionList(o.from),p.removeNotification(o.from),p.setSelected()}),c.click(function(t){var o=n.find(" option");0==o.length&&(alert("Select item to move."),t.preventDefault()),r.append(e(o).clone()),e(o).remove(),t.preventDefault(),p.setSelected()}),a.click(function(t){var o=r.find(" option");0==o.length&&(alert("Select item to move."),t.preventDefault()),n.append(e(o).clone()),e(o).remove(),t.preventDefault(),p.setSelected()}),l.keyup(function(){p.searchInList(o.from,this)}),d.keyup(function(){p.searchInList(o.to,this)});var p={sortOptionList:function(t){if(o.sort){var i=e(t);i.html(i.find("option").sort(function(t,o){return e(t).text().toLowerCase()>e(o).text().toLowerCase()?1:-1}))}},removeNotification:function(t){setTimeout(function(){e(t).find("option").removeClass(o.notifier)},o.notifytimer)},searchInList:function(t,o){var n,r,f;for(n=e(t).find("option"),f=o.value.toUpperCase(),i=0;i<n.length;i++)(r=n[i])&&(r.innerHTML.toUpperCase().indexOf(f)>-1?n[i].style.display="":n[i].style.display="none")},setSelected:function(){r.find("option").prop("selected",!0)}}}}(jQuery);