-
Notifications
You must be signed in to change notification settings - Fork 2
/
pair-select.min.js
1 lines (1 loc) · 1.28 KB
/
pair-select.min.js
1
(function(e){function t(t,n){this.defaults={attribute:"value"};this.opts=e.extend({},this.defaults,n);this.$el=e(t);this.items=new Array}t.prototype={init:function(){var t=this;e("option",this.$el).each(function(n,r){var i=e(r);i.data("status","enabled");t.items.push({attribute:i.attr(t.opts.attribute),$el:i})})},transferElement:function(t){var n=e(t).attr(e(this)[0].opts.attribute);e.each(this.items,function(e,t){if(t.attribute==n){t.$el.remove();t.$el.data("status","disabled")}})},bringBackElement:function(t){var n=this;var r=e(t).attr(e(this)[0].opts.attribute);e.each(this.items,function(e,t){if(t.attribute==r){var i=e+1;while(true){if(i<n.items.length){if(n.items[i].$el.data("status")=="enabled"){n.items[i].$el.before(t.$el);t.$el.data("status","enabled");break}else{i++}}else{n.$el.append(t.$el);t.$el.data("status","enabled");break}}}})}};e.fn.pairMaster=function(n){if(this.length){this.each(function(){var r=new t(this,n);r.init();e(this).data("pairselect",r)})}};e.fn.addSelected=function(t){var n=e(this).find(":selected");var r=this;e.each(n,function(n,i){e(r).data("pairselect").transferElement(i);if(t){e(t).append(i)}})};e.fn.removeSelected=function(t){var n=e(this).find(":selected");e.each(n,function(n,r){e(r).remove();if(t){e(t).data("pairselect").bringBackElement(r)}})}})(jQuery)