From 83b7eb16d05e7a8a0aac806793b810ac3fb602d6 Mon Sep 17 00:00:00 2001 From: James Homer Date: Wed, 11 Feb 2015 17:49:39 +0000 Subject: [PATCH 1/2] Allow sorting of multiple select --- examples/demo-multi-select.html | 4 +- examples/demo-tagging.html | 4 +- examples/select2-bootstrap3.html | 15 +++ src/bootstrap/match-multiple.tpl.html | 4 +- src/select.css | 31 +++++- src/select.js | 142 ++++++++++++++++++++++++++ src/select2/match-multiple.tpl.html | 3 +- 7 files changed, 194 insertions(+), 9 deletions(-) diff --git a/examples/demo-multi-select.html b/examples/demo-multi-select.html index 4246aa988..81cf4de79 100644 --- a/examples/demo-multi-select.html +++ b/examples/demo-multi-select.html @@ -121,8 +121,8 @@

Array of strings

Selected: {{multipleDemo.colors}}


-

Array of objects

- +

Array of objects (sorting enabled)

+ {{$item.name}} <{{$item.email}}>
diff --git a/examples/demo-tagging.html b/examples/demo-tagging.html index b2cc6cf7a..3ca339f7d 100644 --- a/examples/demo-tagging.html +++ b/examples/demo-tagging.html @@ -65,8 +65,8 @@

Tagging Demos

Simple String Tags

-

(With Custom Tag Label)

- +

(With Custom Tag Label / Sort Enabled)

+ {{$item}} {{color}} diff --git a/examples/select2-bootstrap3.html b/examples/select2-bootstrap3.html index 4febfa396..9db76eef3 100644 --- a/examples/select2-bootstrap3.html +++ b/examples/select2-bootstrap3.html @@ -64,6 +64,21 @@ +
+ +
+ + + {{$select.selected.name}} + +
+ +
+
+ +
+
+
diff --git a/src/bootstrap/match-multiple.tpl.html b/src/bootstrap/match-multiple.tpl.html index f303016e4..3e60ccd0d 100644 --- a/src/bootstrap/match-multiple.tpl.html +++ b/src/bootstrap/match-multiple.tpl.html @@ -1,13 +1,13 @@ + ng-class="{'btn-primary':$select.activeMatchIndex === $index, 'select-locked':$select.isLocked(this, $index)}" + ui-select-sort="$select.selected">  × diff --git a/src/select.css b/src/select.css index c5aecbd2a..c284e6d98 100644 --- a/src/select.css +++ b/src/select.css @@ -121,11 +121,12 @@ height: auto; max-height: 200px; overflow-x: hidden; + margin-top: -1px; } .ui-select-multiple.ui-select-bootstrap { height: auto; - padding: .3em; + padding: 3px 3px 0 3px; } .ui-select-multiple.ui-select-bootstrap input.ui-select-search { @@ -133,6 +134,7 @@ border: none; outline: none; height: 1.666666em; + margin-bottom: 3px; } .ui-select-multiple.ui-select-bootstrap .ui-select-match .close { @@ -140,8 +142,33 @@ line-height: 0.75; } -.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{ +.ui-select-multiple.ui-select-bootstrap .ui-select-match-item { outline: 0; + margin: 0 3px 3px 0; +} + +.ui-select-multiple .ui-select-match-item { + position: relative; +} + +.ui-select-multiple .ui-select-match-item.dropping-before:before { + content: ""; + position: absolute; + top: 0; + right: 100%; + height: 100%; + margin-right: 2px; + border-left: 1px solid #428bca; +} + +.ui-select-multiple .ui-select-match-item.dropping-after:after { + content: ""; + position: absolute; + top: 0; + left: 100%; + height: 100%; + margin-left: 2px; + border-right: 1px solid #428bca; } .ui-select-bootstrap .ui-select-choices-row>a { diff --git a/src/select.js b/src/select.js index f8906c235..071c7a79e 100644 --- a/src/select.js +++ b/src/select.js @@ -90,6 +90,7 @@ .constant('uiSelectConfig', { theme: 'bootstrap', searchEnabled: true, + sortEnabled: false, placeholder: '', // Empty by default, like HTML tag refreshDelay: 1000, // In milliseconds closeOnSelect: true, @@ -184,7 +184,7 @@ ctrl.focusser = undefined; //Reference to input element used to handle focus events ctrl.disabled = undefined; // Initialized inside uiSelect directive link function ctrl.searchEnabled = undefined; // Initialized inside uiSelect directive link function - ctrl.sortEnabled = undefined; // Initialized inside uiSelect directive link function + ctrl.sortable = undefined; // Initialized inside uiSelect directive link function ctrl.resetSearchInput = undefined; // Initialized inside uiSelect directive link function ctrl.refreshDelay = undefined; // Initialized inside uiSelectChoices directive link function ctrl.multiple = false; // Initialized inside uiSelect directive link function @@ -1080,9 +1080,9 @@ $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled; }); - scope.$watch('sortEnabled', function() { - var sortEnabled = scope.$eval(attrs.sortEnabled); - $select.sortEnabled = sortEnabled !== undefined ? sortEnabled : uiSelectConfig.sortEnabled; + scope.$watch('sortable', function() { + var sortable = scope.$eval(attrs.sortable); + $select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable; }); attrs.$observe('disabled', function() { @@ -1325,7 +1325,7 @@ }]) // Make multiple matches sortable - .directive('uiSelectSort', ['$timeout', '$log', 'uiSelectConfig', 'uiSelectMinErr', function($timeout, $log, uiSelectConfig, uiSelectMinErr) { + .directive('uiSelectSort', ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', function($timeout, uiSelectConfig, uiSelectMinErr) { return { require: '^uiSelect', link: function(scope, element, attrs, $select) { @@ -1345,9 +1345,8 @@ droppingAfterClassName = 'dropping-after'; scope.$watch(function(){ - return $select.sortEnabled; + return $select.sortable; }, function(n){ - $log.log(n); if (n) { element.attr('draggable', true); } else { diff --git a/src/select2/select-multiple.tpl.html b/src/select2/select-multiple.tpl.html index 774a02af3..6d8ed0d19 100644 --- a/src/select2/select-multiple.tpl.html +++ b/src/select2/select-multiple.tpl.html @@ -21,7 +21,8 @@ ng-hide="$select.disabled" ng-model="$select.search" ng-click="$select.activate()" - style="width: 34px;"> + style="width: 34px;" + ondrop="return false;">