-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
181 lines (139 loc) · 6.99 KB
/
example.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Example of usage for the module ac-fancy-input
var myApp = angular.module('exampleApp',['ac-fancy-input','ui.bootstrap']);
myApp.factory('sampleData',[ function(){
// Example of data source, you can replace is by your own
// WARNING: Each json node should contain at least 'string' as an attribute
// it is what defines the main content of the selection by default
return {
fruits:
[ { string: 'Strawberry', color: 'Red' }, { string: 'Banana', color: 'Yellow' }, { string: 'Apple', color: 'Green' } ],
vegetables:
[ { string: 'Zucchini Squash', color: 'Green' }, { string: 'Sweet Corn', color: 'Yellow' }, { string: 'Tomatoes', color: 'Red' } ]
};
}]);
myApp.factory('sampleDataTwo',[ function(){
// Example of data source, you can replace is by your own
// WARNING: Each json node should contain at least 'string' as an attribute
// it is what defines the main content of the selection by default
return {
fruits:
[ { string: 'Strawberry', color: 'Red' }, { string: 'Banana', color: 'Yellow' }, { string: 'Apple', color: 'Green' } ],
vegetables:
[ { string: 'Zucchini Squash', color: 'Green' }, { string: 'Sweet Corn', color: 'Yellow' }, { string: 'Tomatoes', color: 'Red' } ]
};
}]);
myApp.factory('sampleMessage', [ function(){
// example of message strings for the searchbox animation
// the + and - characters are used to control the presence or absence of color
var init_string = "+This is an example of what you can do with the fancy input module";
return {
init_string: init_string,
pause_string: "",
continue_array: [
init_string,
"You can customize this text animation",
"and even mess with the -c+o-l+o-r+s",
"Click and press any key to try out the -typeahead feature"
]
};
}]);
// This filter simulates a real database search
myApp.filter("suggestions", function(){
return function(suggestions, search){
var filtered_s = [];
for(var k = 0; k < suggestions.length;k++){
if(suggestions[k].color.toLowerCase().indexOf(search.toLowerCase()) !== -1 || suggestions[k].string.toLowerCase().indexOf(search.toLowerCase()) !== -1 ){
filtered_s.push(suggestions[k]);
}
}
return filtered_s;
};
});
myApp.controller('AcExampleController', [ '$scope', 'acfiDataInstance', 'acfiIntervalInstance', '$filter', 'sampleData', 'sampleMessage' ,
function($scope , AcfiDataInstance, AcfiIntervalInstance , $filter , sampleData , sampleMessage){
$scope.AcfiData = AcfiDataInstance.get(1);
$scope.AcfiInterval = AcfiIntervalInstance.get(1);
$scope.sampleData = sampleData;
// The text font is rescaled to fit the input box by default when typing
// but there is added control for the animation
$scope.AcfiData.resizeAnimation = true; // default: false
// initializing the suggestions types
// klass is the css class used in the html, contents is an array of hash
$scope.AcfiData.suggestion_types = [
{ "klass": "fruits", "contents": [], "name": 'Fruits' },
{ "klass": "vegetables", "contents": [], "name": 'Vegetables' }
];
// Define the text that will be used in the animation
$scope.AcfiData.initText(sampleMessage.init_string, sampleMessage.pause_string, sampleMessage.continue_array);
// For now, the animation start is done in 2 steps for more control.
$scope.allowAnimation = true;
$scope.AcfiInterval.startAnimationInterval();
// method called when typing
// it should typically use the 'query' parameter to do a search and then fill the suggestion box
$scope.$on("onQuerySuggestions", function (event, query, id) {
if(id===1){
$scope.AcfiData.suggestion_types[0].contents = $filter('suggestions')($scope.sampleData.fruits, query);
$scope.AcfiData.suggestion_types[1].contents = $filter('suggestions')($scope.sampleData.vegetables, query);
$scope.AcfiData.display = true;
$scope.AcfiData.noResultDisplay = ($scope.AcfiData.displayedLength() === 0);
$scope.allowAnimation = false;
}
});
// method called when pressing enter or selecting a suggestion
// there are no parameters but the current input value is accessed via AcfiData.string
$scope.$on('onSubmitQuery', function(event, id){
if(id===1){
alert($scope.AcfiData.string + " selected");
$scope.AcfiData.updateInput($scope.AcfiData.selected.color + " " + $scope.AcfiData.selected.string);
$scope.AcfiData.display = false;
}
});
$scope.myViewMoreAction = function(){
alert('In this action, you could open a modal window for instance to see all the suggestions');
$scope.AcfiData.display = false;
};
}]);
myApp.controller('AcExampleControllerTwo', [ '$scope', 'acfiDataInstance', 'acfiIntervalInstance', '$filter', 'sampleDataTwo', 'sampleMessage' ,
function($scope , AcfiDataInstance, AcfiIntervalInstance , $filter , sampleDataTwo , sampleMessage){
$scope.AcfiData = AcfiDataInstance.get(2);
$scope.AcfiInterval = AcfiIntervalInstance.get(2);
$scope.sampleData = sampleDataTwo;
// The text font is rescaled to fit the input box by default when typing
// but there is added control for the animation
$scope.AcfiData.resizeAnimation = true; // default: false
// initializing the suggestions types
// klass is the css class used in the html, contents is an array of hash
$scope.AcfiData.suggestion_types = [
{ "klass": "fruits", "contents": [], "name": 'Fruits' },
{ "klass": "vegetables", "contents": [], "name": 'Vegetables' }
];
// Define the text that will be used in the animation
$scope.AcfiData.initText(sampleMessage.init_string, sampleMessage.pause_string, sampleMessage.continue_array);
// For now, the animation start is done in 2 steps for more control.
$scope.allowAnimation = true;
$scope.AcfiInterval.startAnimationInterval();
// method called when typing
// it should typically use the 'query' parameter to do a search and then fill the suggestion box
$scope.$on("onQuerySuggestions", function (event, query, id) {
if(id===2){
$scope.AcfiData.suggestion_types[0].contents = $filter('suggestions')($scope.sampleData.fruits, query);
$scope.AcfiData.suggestion_types[1].contents = $filter('suggestions')($scope.sampleData.vegetables, query);
$scope.AcfiData.display = true;
$scope.AcfiData.noResultDisplay = ($scope.AcfiData.displayedLength() === 0);
}
});
// method called when pressing enter or selecting a suggestion
// there are no parameters but the current input value is accessed via AcfiData.string
$scope.$on('onSubmitQuery', function(event, id){
if(id===2){
alert($scope.AcfiData.string + " selected");
$scope.AcfiData.updateInput($scope.AcfiData.selected.color + " " + $scope.AcfiData.selected.string);
$scope.AcfiData.display = false;
$scope.allowAnimation = false;
}
});
$scope.myViewMoreAction = function(){
alert('In this action, you could open a modal window for instance to see all the suggestions');
$scope.AcfiData.display = false;
};
}]);