Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 20ac800

Browse files
authored
Merge branch 'master' into header-footer-2
2 parents 96771a2 + b4bbadf commit 20ac800

12 files changed

+362
-34
lines changed

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ env:
77
- GH_REF: github.com/angular-ui/ui-select.git
88
- GH_PAGES_BRANCH: gh-pages
99
- secure: "PkIhXXwrR5fHh7fH+2WizaY0MmK1l1Dr7PCqs112PkEimVPcntRJeA5pjTwGRwHm+RSkFVtfo38EY/GUwzhLSRTO7WZ+id+vIMGQLgiofqrOwi0nq93esG6qI8Jg5K0GUt8mzg5m9B2tgm2I91RAojEhIukKcbsDsq3hNAUy71Y="
10-
1110
addons:
11+
firefox: "31.0"
12+
1213
apt:
1314
sources:
1415
- ubuntu-toolchain-r-test
1516
packages:
1617
- g++-4.8
1718

19+
1820
before_script:
1921
- export DISPLAY=:99.0
2022
- sh -e /etc/init.d/xvfb start

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"karma": "^0.12.16",
4242
"karma-chrome-launcher": "^0.1.3",
4343
"karma-coverage": "~0.2",
44-
"karma-firefox-launcher": "~0.1",
44+
"karma-firefox-launcher": "~1.0",
4545
"karma-jasmine": "~0.2",
4646
"karma-ng-html2js-preprocessor": "^0.1.0",
4747
"karma-phantomjs-launcher": "~0.1.4",

src/bootstrap/select-multiple.tpl.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<div class="ui-select-container ui-select-multiple ui-select-bootstrap dropdown form-control" ng-class="{open: $select.open}">
22
<div>
33
<div class="ui-select-match"></div>
4+
<span ng-show="$select.open && $select.refreshing && $select.spinnerEnabled" class="ui-select-refreshing {{$select.spinnerClass}}"></span>
45
<input type="search"
56
autocomplete="off"
67
autocorrect="off"
78
autocapitalize="off"
89
spellcheck="false"
910
class="ui-select-search input-xs"
10-
placeholder="{{$selectMultiple.getPlaceholder()}}"
11+
placeholder="{{$select.getPlaceholder()}}"
1112
ng-disabled="$select.disabled"
1213
ng-click="$select.activate()"
1314
ng-model="$select.search"
1415
role="combobox"
1516
aria-expanded="{{$select.open}}"
1617
aria-label="{{$select.baseTitle}}"
1718
ng-class="{'spinner': $select.refreshing}"
18-
ondrop="return false;">
19+
data-disallow-drop=data-disallow-drop>
1920
</div>
2021
<div ng-show="$select.open && $select.items.length > 0" class="ui-select-dropdown dropdown-menu">
2122
<div class="ui-select-header"></div>

src/common.css

+30
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ body > .select2-container.open {
155155
width: 0;
156156
}
157157

158+
.ui-select-container[theme="selectize"] .ui-select-header-group-selectable:hover {
159+
background-color: #f5f5f5;
160+
}
161+
162+
.ui-select-container[theme="selectize"] .ui-select-header-group-selectable {
163+
cursor: pointer;
164+
padding-left: 15px;
165+
}
166+
158167
/* Bootstrap theme */
159168

160169
/* Helper class to show styles when focus */
@@ -283,10 +292,31 @@ body > .ui-select-bootstrap.open {
283292
border-right: 1px solid #428bca;
284293
}
285294

295+
286296
.ui-select-bootstrap .ui-select-choices {
287297
padding: 5px 0;
288298
margin: 0;
289299
list-style: none;
300+
301+
.ui-select-bootstrap .ui-select-header-group-selectable:hover {
302+
background-color: #f5f5f5;
303+
}
304+
305+
.ui-select-bootstrap .ui-select-header-group-selectable {
306+
color: black;
307+
cursor: pointer;
308+
padding: 3px 10px;
309+
}
310+
311+
.ui-select-bootstrap .ui-select-choices-row>span {
312+
cursor: pointer;
313+
display: block;
314+
padding: 3px 20px;
315+
clear: both;
316+
font-weight: 400;
317+
line-height: 1.42857143;
318+
color: #333;
319+
white-space: nowrap;
290320
}
291321

292322
.ui-select-bootstrap .ui-select-choices-row > span {

src/select2/select-multiple.tpl.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
aria-label="{{ $select.baseTitle }}"
1717
aria-activedescendant="ui-select-choices-row-{{ $select.generatedId }}-{{ $select.activeIndex }}"
1818
class="select2-input ui-select-search"
19-
placeholder="{{$selectMultiple.getPlaceholder()}}"
19+
placeholder="{{$select.getPlaceholder()}}"
2020
ng-disabled="$select.disabled"
2121
ng-hide="$select.disabled"
2222
ng-model="$select.search"
2323
ng-click="$select.activate()"
2424
style="width: 34px;"
25-
ondrop="return false;">
25+
data-disallow-drop=data-disallow-drop>
2626
</li>
2727
</ul>
2828
<div class="ui-select-dropdown select2-drop select2-with-searchbox select2-drop-active"

src/selectize/select-multiple.tpl.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<input type="search" autocomplete="off" tabindex="-1"
77
class="ui-select-search"
88
ng-class="{'ui-select-search-hidden':!$select.searchEnabled}"
9-
placeholder="{{$selectMultiple.getPlaceholder()}}"
9+
placeholder="{{$select.getPlaceholder()}}"
1010
ng-model="$select.search"
1111
ng-disabled="$select.disabled"
1212
aria-expanded="{{$select.open}}"
1313
aria-label="{{ $select.baseTitle }}"
14-
ondrop="return false;">
14+
data-disallow-drop=data-disallow-drop>
1515
</div>
1616
<div ng-show="$select.open" class="ui-select-dropdown selectize-dropdown"
1717
ng-class="{'single': !$select.multiple, 'multi': $select.multiple}">

src/uiSelectController.js

+21-9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ uis.controller('uiSelectCtrl',
6565
return isNil(ctrl.selected) || ctrl.selected === '' || (ctrl.multiple && ctrl.selected.length === 0);
6666
};
6767

68+
ctrl.getPlaceholder = function(){
69+
if(ctrl.selected && ctrl.selected.length) return;
70+
return ctrl.placeholder;
71+
};
72+
6873
function _findIndex(collection, predicate, thisArg){
6974
if (collection.findIndex){
7075
return collection.findIndex(predicate, thisArg);
@@ -88,10 +93,14 @@ uis.controller('uiSelectCtrl',
8893
if (ctrl.resetSearchInput) {
8994
ctrl.search = EMPTY_SEARCH;
9095
//reset activeIndex
91-
if (ctrl.selected && ctrl.items.length && !ctrl.multiple) {
92-
ctrl.activeIndex = _findIndex(ctrl.items, function(item){
93-
return angular.equals(this, item);
94-
}, ctrl.selected);
96+
if (!ctrl.multiple) {
97+
if (ctrl.selected && ctrl.items.length) {
98+
ctrl.activeIndex = _findIndex(ctrl.items, function(item){
99+
return angular.equals(this, item);
100+
}, ctrl.selected);
101+
} else {
102+
ctrl.activeIndex = 0;
103+
}
95104
}
96105
}
97106
}
@@ -149,7 +158,7 @@ uis.controller('uiSelectCtrl',
149158
} else {
150159
$timeout(function () {
151160
ctrl.focusSearchInput(initSearchValue);
152-
if(!ctrl.tagging.isActivated && ctrl.items.length > 1) {
161+
if(!ctrl.tagging.isActivated && ctrl.items.length > 1 && ctrl.open) {
153162
_ensureHighlightVisible();
154163
}
155164
});
@@ -166,9 +175,12 @@ uis.controller('uiSelectCtrl',
166175
ctrl.searchInput[0].focus();
167176
};
168177

169-
ctrl.findGroupByName = function(name) {
178+
ctrl.findGroupByName = function(name, noStrict) {
170179
return ctrl.groups && ctrl.groups.filter(function(group) {
171-
return group.name === name;
180+
if (noStrict)
181+
return group.name == name;
182+
else
183+
return group.name === name;
172184
})[0];
173185
};
174186

@@ -465,11 +477,11 @@ uis.controller('uiSelectCtrl',
465477
ctrl.toggle = function(e) {
466478
if (ctrl.open) {
467479
ctrl.close();
468-
e.preventDefault();
469-
e.stopPropagation();
470480
} else {
471481
ctrl.activate();
472482
}
483+
e.preventDefault();
484+
e.stopPropagation();
473485
};
474486

475487
// Set default function for locked choices - avoids unnecessary

src/uiSelectDirective.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
uis.directive('uiSelect',
2-
['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout',
3-
function($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) {
2+
['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', '$window',
3+
function($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout, $window) {
44

55
return {
66
restrict: 'EA',
@@ -206,11 +206,15 @@ uis.directive('uiSelect',
206206
$select.clickTriggeredSelect = false;
207207
}
208208

209-
// See Click everywhere but here event http://stackoverflow.com/questions/12931369
210-
$document.on('click', onDocumentClick);
209+
// See Click everywhere but here. Similar approach to http://stackoverflow.com/questions/12931369
210+
// but using the capture phase instead of bubble phase of the event propagation.
211+
//
212+
// Using the capture phase avoids problems that araise when event.stopPropatagion()
213+
// is called before the event reaches the `document`.
214+
$window.document.addEventListener('click', onDocumentClick, true);
211215

212216
scope.$on('$destroy', function() {
213-
$document.off('click', onDocumentClick);
217+
$window.document.removeEventListener('click', onDocumentClick, true);
214218
});
215219

216220
// Move transcluded elements to their correct position in main template
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
uis.directive('uiSelectHeaderGroupSelectable', ['$timeout', function($timeout) {
2+
return {
3+
restrict: 'EA',
4+
require: ['^uiSelect'],
5+
scope: {
6+
isEnabled: "<?uiSelectHeaderGroupSelectable"
7+
},
8+
link: function ($scope, $element, attrs, select) {
9+
// TODO Why that???
10+
var $select = select[0];
11+
if (angular.isUndefined($scope.isEnabled)) {
12+
$scope.isEnabled = true;
13+
}
14+
15+
function isEnabled() {
16+
return angular.isUndefined($scope.isEnabled) || $scope.isEnabled;
17+
}
18+
19+
function getElements() {
20+
if ($select.multiple && $select.groups) {
21+
return $element.querySelectorAll('.ui-select-choices-group-label');
22+
} else {
23+
console.error('Use uiSelectHeaderGroupSelectable with no multiple uiSelect or without groupBy');
24+
return [];
25+
}
26+
}
27+
28+
function enableClick() {
29+
if (isEnabled()) {
30+
angular.forEach(getElements(), function(e) {
31+
var element = angular.element(e);
32+
33+
// Check the onClick event is not already listen
34+
if (!element.hasClass('ui-select-header-group-selectable')) {
35+
element.addClass('ui-select-header-group-selectable');
36+
37+
element.on('click', function () {
38+
if (isEnabled()) {
39+
var group = $select.findGroupByName(element.text(), true);
40+
41+
angular.forEach(group.items, function(item) {
42+
$timeout(function() {
43+
$select.select(item, false, ' ');
44+
});
45+
});
46+
}
47+
});
48+
}
49+
});
50+
}
51+
}
52+
53+
function disableClick() {
54+
if (!isEnabled()) {
55+
angular.forEach(getElements(), function(e) {
56+
var element = angular.element(e);
57+
element.removeClass('ui-select-header-group-selectable');
58+
element.off('click');
59+
});
60+
}
61+
}
62+
63+
// Watch element to trigger select event
64+
$scope.$watch('isEnabled', function() {
65+
if (!isEnabled()) {
66+
disableClick();
67+
} else {
68+
enableClick();
69+
}
70+
});
71+
72+
$scope.$watch('$select.groups', enableClick);
73+
$scope.$watch(function() {
74+
return $select.selected && $select.selected.length ? $select.selected.length : -1;
75+
}, enableClick);
76+
}
77+
};
78+
}]);

src/uiSelectMultipleDirective.js

-6
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
6262
return true;
6363
};
6464

65-
ctrl.getPlaceholder = function(){
66-
//Refactor single?
67-
if($select.selected && $select.selected.length) return;
68-
return $select.placeholder;
69-
};
70-
7165

7266
}],
7367
controllerAs: '$selectMultiple',

src/uiSelectSortDirective.js

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ uis.directive('uiSelectSort', ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', f
3131
}
3232
});
3333

34+
if (element.data('disallowDrop')) {
35+
return;
36+
}
37+
3438
element.on('dragstart', function(event) {
3539
element.addClass(draggingClassName);
3640

0 commit comments

Comments
 (0)