Skip to content

Commit b58fe48

Browse files
committed
Merge branch 'fff'
Conflicts: app/scripts/controllers/about.js app/scripts/directives/dropdown-items.html app/scripts/directives/dropdown-items.js app/scripts/directives/dropdown-list.html app/scripts/directives/dropdown-list.js app/scripts/directives/dropdown-selected.js app/scripts/directives/dropdownListCtrl.js app/views/about.html
2 parents 78844cb + ad1fede commit b58fe48

11 files changed

+497
-209
lines changed

app/index.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@
6666
<!-- endbower -->
6767
<!-- endbuild -->
6868

69-
<!-- build:js({.tmp,app}) scripts/scripts.js -->
70-
<script src="scripts/app.js"></script>
71-
<script src="scripts/controllers/main.js"></script>
72-
<script src="scripts/controllers/about.js"></script>
73-
<script src="scripts/directives/dropdown-items.js"></script>
74-
<script src="scripts/directives/dropdown-list.js"></script>
75-
<script src="scripts/directives/dropdown-selected.js"></script>
69+
<!-- build:js({.tmp,app}) scripts/scripts.js -->
70+
<script src="scripts/app.js"></script>
71+
<script src="scripts/controllers/main.js"></script>
72+
<script src="scripts/controllers/about.js"></script>
73+
<script src="scripts/directives/dropdown-items.js"></script>
74+
<script src="scripts/directives/dropdown-list.js"></script>
75+
<script src="scripts/directives/dropdown-selected.js"></script>
7676

77-
<script src="scripts/directives/dropdownListCtrl.js"></script>
78-
<script src="scripts/directives/repeaterParser.js"></script>
79-
<script src="scripts/directives/transcludeAppend.js"></script>
80-
<!-- endbuild -->
77+
<script src="scripts/directives/dropdownListCtrl.js"></script>
78+
<script src="scripts/directives/repeaterParser.js"></script>
79+
<script src="scripts/directives/transcludeAppend.js"></script>
80+
<!-- endbuild -->
8181
</body>
8282
</html>

app/scripts/controllers/about.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,31 @@
33
angular.module('angularTestApp').controller('aboutCtrl', ['$interval','$scope',function($interval, $scope){
44

55
$scope.users = [
6-
{budgetshare: 1233.86,publisher: 'Cosmik Debris', rollover: 12345, adjustment: 434, ebudget: 34234},
7-
{budgetshare: 633.86,publisher: 'Electric Aunt Jemima', rollover: 345, adjustment: 341, ebudget: 1234},
8-
{budgetshare: 33.86,publisher: 'Bongo Fury', rollover: 9457, adjustment: 50, ebudget: 8744},
9-
{budgetshare: 823.86,publisher: 'Acquisio', rollover: 5645, adjustment: 984, ebudget: 9334}
6+
{country: 'Sweden',publisher: 'Cosmik Debris', rollover: 12345, adjustment: 434, ebudget: 34234},
7+
{country: 'Sweden',publisher: 'Electric Aunt Jemima', rollover: 345, adjustment: 341, ebudget: 1234},
8+
{country: 'China',publisher: 'Bongo Fury', rollover: 9457, adjustment: 50, ebudget: 8744},
9+
{country: 'China',publisher: 'Jessica', rollover: 845, adjustment: 984, ebudget: 9334},
10+
{country: 'China',publisher: 'Acquisio', rollover: 7645, adjustment: 984, ebudget: 9334},
11+
{country: 'Japan',publisher: 'Judy', rollover: 535, adjustment: 984, ebudget: 9334},
12+
{country: 'China',publisher: 'Acquisio', rollover: 5645, adjustment: 984, ebudget: 9334},
13+
{country: 'China',publisher: 'Honda', rollover: 561, adjustment: 984, ebudget: 9334},
14+
{country: 'Japan',publisher: 'Bar', rollover: 5645, adjustment: 984, ebudget: 9334},
15+
{country: 'Japan',publisher: 'Foo', rollover: 6235, adjustment: 984, ebudget: 9334},
16+
{country: 'Canada',publisher: 'Eva', rollover: 57, adjustment: 984, ebudget: 9334},
17+
{country: 'Canada',publisher: 'Acquisio', rollover: 7695, adjustment: 984, ebudget: 9334}
1018
];
1119

1220
$scope.selection = {
1321
selected: null
22+
// selected: $scope.users[2]
1423
};
1524

16-
$scope.test = 'yeehaw';
17-
1825
$scope.$watch('selection.selected', function(newVal){
19-
console.log('value changed');
20-
console.log(newVal);
2126
});
2227

23-
// $scope.$watch('test', function(newVal){
24-
// console.log('value changed');
25-
// console.log(newVal);
26-
// });
27-
28+
$scope.remove = function(){
29+
$('#dropdown').remove();
30+
}
2831
// $scope.$watch('users', function(newVal){
2932
// console.log('value changed');
3033
// console.log(newVal);
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
<ul class="ui-select-choices ui-select-choices-content dropdown-menu"
2-
role="menu">
3-
<li class="ui-select-choices-group">
4-
<div class="ui-select-choices-row" ng-click = "$select.select(user, $event)" ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}" ng-repeat = "user in users">
5-
<a href="javascript:void(0)" class="ui-select-choices-row-inner" uis-transclude-append></a>
6-
<!-- <a href="javascript:void(0)" class="ui-select-choices-row-inner" ng-transclude></a> -->
7-
1+
<ul class="acq-dropdown-item dropdown-menu" ng-show="$select.items.length > 0">
2+
<li class = "ui-select-choices-group">
3+
<div class="divider" ng-show="$select.isGrouped && $index > 0"></div>
4+
<div ng-show="$select.isGrouped" class="ui-select-choices-group-label dropdown-header" ng-bind="$group.name"></div>
5+
<div class="acq-dropdown-item-row" ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}">
6+
<a href="javascript:void(0)" class="acq-dropdown-item-row-inner"></a> <!-- class only used as selector -->
87
</div>
98
</li>
109
</ul>

app/scripts/directives/dropdown-items.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,54 @@
1919
transclude: true,
2020
templateUrl: './scripts/directives/dropdown-items.html',
2121
compile: function(tElement, tAttrs) {
22-
// if (!tAttrs.repeat){
23-
// throw "Expected 'repeat' expression.";
24-
// }
22+
// debugger;
23+
if (!tAttrs.repeat){
24+
throw"Expected 'repeat' expression.";
25+
}
2526

2627
return function link(scope, element, attrs, $select, transcludeFn) {
27-
scope.$watch('$select.search', function(newValue) {
28-
if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
28+
// debugger;
29+
// var repeat = RepeatParser.parse(attrs.repeat);
30+
var groupByExp = attrs.groupBy;
31+
if(groupByExp) {
32+
var groups = element.querySelectorAll('.ui-select-choices-group');
33+
groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression());
34+
}
35+
36+
$select.parseRepeatAttr(attrs.repeat, groupByExp); //Result ready at $select.parserResult
37+
38+
var choices = element.querySelectorAll('.acq-dropdown-item-row');
39+
40+
choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp))
41+
.attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed
42+
.attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')')
43+
.attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)');
44+
45+
var rowsInner = element.querySelectorAll('.acq-dropdown-item-row-inner');
46+
transcludeFn(scope, function(clone){
47+
rowsInner.append(clone);
48+
});
49+
50+
$compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend
51+
52+
scope.$on('$destroy', function(){
53+
console.log('dropdown-item directive scope destroy');
2954
});
55+
56+
element.on('$destroy', function(){
57+
console.log('dropdow-item directive element destroy');
58+
});
59+
// scope.$watch('$select.search', function(newValue) {
60+
// if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
61+
// // $select.activeIndex = $select.tagging.isActivated ? -1 : 0;
62+
// // $select.refresh(attrs.refresh);
63+
// });
64+
65+
// attrs.$observe('refreshDelay', function() {
66+
// // $eval() is needed otherwise we get a string instead of a number
67+
// var refreshDelay = scope.$eval(attrs.refreshDelay);
68+
// $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay;
69+
// });
3070
};
3171
}
3272
};
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
<div class="ui-select-bootstrap dropdown" ng-class="{open: $select.open}">
2-
<input type="text" autocomplete="off" tabindex="-1"
3-
class="form-control ui-select-search"
1+
<div class="acq-dropdown-list dropdown" ng-class="{open: $select.open}">
2+
<div class="acq-dropdown-selected"></div>
3+
<input type="text" autocomplete="off"
4+
class="ui-select-search"
45
placeholder="{{$select.placeholder}}"
5-
ng-model="$select.selected.publisher"
6-
ng-show="$select.searchEnabled && $select.open">
6+
ng-model="$select.search"
7+
ng-show="$select.searchEnabled && $select.open && $select.exceedThreshold">
8+
<div class="acq-dropdown-item"></div>
79
</div>
810

app/scripts/directives/dropdown-list.js

Lines changed: 156 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,53 @@
2020
transclude: true,
2121
controller: 'dropdownListCtrl',
2222
controllerAs: '$select',
23-
link: function link(scope, element, iAttrs, ctrls, transcludeFn) {
23+
compile: function(){
24+
// debugger;
25+
return function link(scope, element, iAttrs, ctrls, transcludeFn) {
26+
// debugger;
2427
// console.log(scope.users);
2528
/*prototypical inheritance*/
2629
// scope.users[0] = {budgetshare: 1233.86,publisher: 'Alan', rollover: 831201, adjustment: 434, ebudget: 34234};
2730
// scope.users = []; // shaded, prototypical inheritance
28-
29-
3031
var $select = ctrls[0];
3132
var ngModel = ctrls[1];
3233

34+
var searchInput = element.querySelectorAll('input.ui-select-search');
35+
36+
//From view --> model
37+
ngModel.$parsers.unshift(function (inputValue) {
38+
var locals = {},
39+
result;
40+
41+
locals = {};
42+
locals[$select.parserResult.itemName] = inputValue;
43+
result = $select.parserResult.modelMapper(scope, locals);
44+
return result;
45+
46+
});
47+
//From model --> view
48+
ngModel.$formatters.unshift(function (inputValue) {
49+
var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
50+
locals = {},
51+
result;
52+
if (data){
53+
54+
var checkFnSingle = function(d){
55+
locals[$select.parserResult.itemName] = d;
56+
result = $select.parserResult.modelMapper(scope, locals);
57+
return result == inputValue;
58+
};
59+
//If possible pass same object stored in $select.selected
60+
if ($select.selected && checkFnSingle($select.selected)) {
61+
return $select.selected;
62+
}
63+
for (var i = data.length - 1; i >= 0; i--) {
64+
if (checkFnSingle(data[i])) return data[i];
65+
}
66+
}
67+
68+
return inputValue;
69+
});
3370
//Set reference to ngModel from dropdownListCtrl
3471
$select.ngModel = ngModel;
3572

@@ -43,11 +80,126 @@
4380
$select.selected = ngModel.$viewValue;
4481
};
4582

83+
84+
element.on('focus', function(){
85+
console.log('focus event on dropdown-list')
86+
});
87+
88+
// handle key press
89+
element.on('keydown', function(e) {
90+
var key = e.which;
91+
console.log('key event on dropdown-list');
92+
scope.$apply(function() {
93+
var processed = false;
94+
if (!processed && $select.items.length > 0) {
95+
processed = $select.handleDropDownSelection(key);
96+
}
97+
if (processed) {
98+
//TODO Check si el tab selecciona aun correctamente
99+
//Crear test
100+
e.preventDefault();
101+
e.stopPropagation();
102+
}
103+
if((key === 38 || key ===40) && $select.items.length > 0){
104+
ensureHighlightVisible();
105+
}
106+
107+
108+
});
109+
});
110+
111+
// reset hightlight if the current selected item is not in the new filtered list
112+
element.on('keyup', function(e) {
113+
var key = e.which;
114+
if (key!==38 && key!== 40){
115+
scope.$apply(function() {
116+
var index = $select.items.indexOf($select.selected);
117+
if (index === -1){
118+
$select.activeIndex = 0;
119+
}else{
120+
$select.activeIndex = index;
121+
}
122+
});
123+
}
124+
});
125+
126+
// when move the UP/DOWN, ensure that the dropdown scrolls to keep the current highlighted item in sight
127+
function ensureHighlightVisible() {
128+
// debugger;
129+
var container = angular.element(element[0].querySelectorAll('.acq-dropdown-item'));
130+
var choices = angular.element(container[0].querySelectorAll('.acq-dropdown-item-row'));
131+
if (choices.length < 1) {
132+
throw uiSelectMinErr('choices', "Expected multiple .ui-select-choices-row but got '{0}'.", choices.length);
133+
}
134+
135+
var highlighted = choices[$select.activeIndex];
136+
var posY = highlighted.offsetTop + highlighted.clientHeight - container[0].scrollTop;
137+
var height = container[0].offsetHeight;
138+
139+
if (posY > height) {
140+
container[0].scrollTop += posY - height;
141+
} else if (posY < highlighted.clientHeight) {
142+
if ($select.isGrouped && $select.activeIndex === 0){
143+
container[0].scrollTop = 0; //To make group header visible when going all the way up
144+
}else{
145+
container[0].scrollTop -= highlighted.clientHeight - posY;
146+
}
147+
}
148+
}
149+
150+
151+
function onDocumentClick(e) {
152+
var contains = false;
153+
154+
contains = element[0].contains(e.target);
155+
156+
if (!contains && !$select.clickTriggeredSelect) {
157+
$select.close();
158+
scope.$digest();
159+
}
160+
$select.clickTriggeredSelect = false;
161+
}
162+
163+
// See Click everywhere but here event http://stackoverflow.com/questions/12931369
164+
$document.on('click', onDocumentClick);
165+
166+
element.on('$destroy', function(){
167+
console.log('dropdow-list directive element destroy');
168+
});
169+
170+
scope.$on('$destroy', function() {
171+
$document.off('click', onDocumentClick);
172+
console.log('dropdow-list directive scope destroy');
173+
});
174+
46175
transcludeFn(scope, function(clone) {
47-
element.append(clone);
176+
// See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html
177+
178+
// One day jqLite will be replaced by jQuery and we will be able to write:
179+
// var transcludedElement = clone.filter('.my-class')
180+
// instead of creating a hackish DOM element:
181+
// debugger;
182+
// element.append(clone);
183+
var transcluded = angular.element('<div>').append(clone);
184+
var transcludedMatch = transcluded.querySelectorAll('.acq-dropdown-selected');
185+
186+
// transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr
187+
//if (transcludedMatch.length !== 1) {
188+
// throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", transcludedMatch.length);
189+
//}
190+
element.querySelectorAll('.acq-dropdown-selected').replaceWith(transcludedMatch);
191+
192+
var transcludedChoices = transcluded.querySelectorAll('.acq-dropdown-item');
193+
// transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr
194+
//if (transcludedChoices.length !== 1) {
195+
// throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length);
196+
//}
197+
element.querySelectorAll('.acq-dropdown-item').replaceWith(transcludedChoices);
48198
});
199+
// debugger;
49200

50201
}
202+
}
51203

52204
};
53205
});

app/scripts/directives/dropdown-selected.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
<button type="button" class="btn btn-default form-control ui-select-match" tabindex="-1"
2-
ng-hide="$select.open"
1+
<button type="button" class="form-control acq-dropdown-selected"
32
ng-disabled="$select.disabled"
4-
ng-class="{'btn-default-focus':$select.focus}";
53
ng-click="$select.activate()">
64
<span ng-show="$select.isEmpty()" class="text-muted">{{$select.placeholder}}</span>
75
<!-- transclusion here -->

app/scripts/directives/dropdown-selected.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
replace: true,
1818
transclude: true,
1919
templateUrl: './scripts/directives/dropdown-selected.html',
20-
link: function(scope, element, attrs, $select) {
21-
22-
// attrs.$observe('placeholder', function(placeholder) {
23-
// $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder;
24-
// });
25-
26-
$select.allowClear = (angular.isDefined(attrs.allowClear)) ? (attrs.allowClear === '') ? true : (attrs.allowClear.toLowerCase() === 'true') : false;
27-
28-
// if($select.multiple){
29-
// $select.sizeSearchInput();
30-
// }
20+
compile: function(){
21+
// debugger;
22+
return function link(scope, element, attrs, $select) {
23+
// debugger;
24+
scope.$on('$destroy', function(){
25+
console.log('dropdown-selected directive scope destroy');
26+
});
27+
element.on('$destroy', function(){
28+
console.log('dropdow-selected directive element destroy');
29+
});
30+
}
3131
}
3232
};
3333
});

0 commit comments

Comments
 (0)