-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathangular-mobile-select.js
83 lines (67 loc) · 2.4 KB
/
angular-mobile-select.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(function()
{
'use strict';
var app = angular
.module('ngmobileselect',['ngAnimate'])
app.run(function($rootScope) {
angular.element(document).on("click", function(e) {
$rootScope.$broadcast("documentClicked", angular.element(e.target));
});
});
app.directive("ngmSelect", function($rootScope) {
return {
restrict: "E",
scope: { placeholder: "@", list: "=", selected: "=", property: "@" },
template: '<div class="ngm-select" ng-class="{\'ngm-select-input-bottom\':isDropped}">'+
'<div class="ngm-select-placeholder">'+
'<span class="ngm-select-floating-label" ng-class ="{\'ngm-select-float-label\': selected[property] || selected , \'ngm-select-active-float-label\': isDropped}">{{placeholder}}</span>'+
'</div>'+
'<div class="ngm-select-selected-item" ng-click="open()">'+
'{{selected[property] || selected || placeholder}}'+
'</div>'+
'<div class="ngm-select-load-container" ng-class={\'ngm-select-backdrop\':isDropped}>'+
'<div class="ngm-select-load-list" ng-if="isDropped">'+
'<div class="ngm-select-load-header">{{placeholder}}</div>'+
'<div class="ngm-select-load-list-container" ng-class={\'ngm-select-full-view\':isFullView}>'+
'<div class="ngm-select-list-item" ng-class={\'ngm-select-disabled-item\':item.disabled} ng-click="item.disabled || select(item)" ng-repeat="item in list">{{item[property] || item}}</div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>',
link : function(scope){
scope.isFullView = false;
$rootScope.$on("documentClicked", function(inner, target) {
if($(target[0]).is(".ngm-select-load-header")){
scope.$apply(function() {
scope.isFullView = true;
});
}
if (!$(target[0]).is(".ngm-select-selected-item") && !$(target[0]).is(".ngm-select-load-header")) {
scope.$apply(function() {
scope.isDropped = false;
scope.isFullView = false;
});
}
});
scope.open = function(){
scope.isDropped = true;
}
scope.select = function(item){
scope.selected = item;
}
}
}
});
app.animation('.ngm-select-load-list', function() {
return {
enter: function(element, done) {
$(element).hide().slideDown();
return function(cancelled) {
};
},
leave: function(element, done) {
$(element).slideUp();
}
};
});
})();