Skip to content

Commit b1fd1b9

Browse files
committed
Trim JS
1 parent 8ac8ce8 commit b1fd1b9

File tree

1 file changed

+40
-44
lines changed

1 file changed

+40
-44
lines changed

src/StackApis/default.cshtml

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,53 @@
55
}
66
<script>
77
var app = angular.module('soApp', []);
8-
app.controller('soCtrl', ['$scope', '$http', '$timeout',
9-
function ($scope, $http, $timeout) {
10-
$scope.makeRequest = function (path) {
11-
$http.get(path).success(function (response) {
12-
$scope.questionsResult = response.Results;
13-
});
14-
};
15-
16-
$('input,select').change(function () {
17-
$scope.makeRequest(constructUrl());
8+
app.controller('soCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
9+
$scope.makeRequest = function (path) {
10+
$http.get(path).success(function (response) {
11+
$scope.questionsResult = response.Results;
1812
});
13+
};
1914
20-
function processInputChange() {
21-
if ($scope.titleSearchTimeout != null) {
22-
$timeout.cancel($scope.titleSearchTimeout);
23-
$scope.titleSearchTimeout = null;
24-
}
25-
$scope.titleSearchTimeout = $timeout(function () {
26-
$scope.makeRequest(constructUrl());
27-
}, 200);
28-
}
29-
30-
$scope.titleSearchTimeout = null;
31-
var watch = ['titleSearch', 'scoreSelect', 'scoreVal', 'viewsSelect', 'viewsVal', 'answersSelect', 'answersVal', 'orderBySelect'];
32-
angular.forEach(watch, function (input) {
33-
$scope.$watch(input, processInputChange);
34-
});
15+
$('input,select').change(function () {
16+
$scope.makeRequest(constructUrl());
17+
});
3518
36-
function constructUrl(model) {
37-
var path = '@(new StackOverflowQuery().ToGetUrl())' +
38-
'?Score' + ($scope.scoreSelect || 'GreaterThan') + '=' + ($scope.scoreVal || 0) +
39-
'&ViewCount' + ($scope.viewsSelect || 'GreaterThan') + '=' + ($scope.viewsVal || 0) +
40-
'&AnswerCount' + ($scope.answersSelect || 'GreaterThan') + '=' + ($scope.answersVal || 0) +
41-
'&OrderByDesc=' + ($scope.orderBySelect || 'Score');
42-
if ($scope.titleSearch) {
43-
path += '&TitleContains=' + $scope.titleSearch;
44-
}
45-
return path;
19+
function processInputChange() {
20+
if ($scope.titleSearchTimeout != null) {
21+
$timeout.cancel($scope.titleSearchTimeout);
22+
$scope.titleSearchTimeout = null;
4623
}
47-
48-
$scope.filterResult = function () {
24+
$scope.titleSearchTimeout = $timeout(function () {
4925
$scope.makeRequest(constructUrl());
50-
};
26+
}, 200);
27+
}
28+
29+
$scope.titleSearchTimeout = null;
30+
var watch = ['titleSearch', 'scoreSelect', 'scoreVal', 'viewsSelect', 'viewsVal', 'answersSelect', 'answersVal', 'orderBySelect'];
31+
angular.forEach(watch, function (input) {
32+
$scope.$watch(input, processInputChange);
33+
});
5134
52-
$scope.scoreSelect = 'GreaterThan';
53-
$scope.viewsSelect = 'GreaterThan';
54-
$scope.answersSelect = 'GreaterThan';
55-
$scope.orderBySelect = 'Score';
56-
$scope.makeRequest('/questions');
35+
function constructUrl(model) {
36+
var path = '@(new StackOverflowQuery().ToGetUrl())' +
37+
'?Score' + ($scope.scoreSelect || 'GreaterThan') + '=' + ($scope.scoreVal || 0) +
38+
'&ViewCount' + ($scope.viewsSelect || 'GreaterThan') + '=' + ($scope.viewsVal || 0) +
39+
'&AnswerCount' + ($scope.answersSelect || 'GreaterThan') + '=' + ($scope.answersVal || 0) +
40+
'&OrderByDesc=' + ($scope.orderBySelect || 'Score') +
41+
($scope.titleSearch ? '&TitleContains=' + $scope.titleSearch : '');
42+
return path;
5743
}
58-
]);
44+
45+
$scope.filterResult = function () {
46+
$scope.makeRequest(constructUrl());
47+
};
48+
49+
$scope.scoreSelect = 'GreaterThan';
50+
$scope.viewsSelect = 'GreaterThan';
51+
$scope.answersSelect = 'GreaterThan';
52+
$scope.orderBySelect = 'Score';
53+
$scope.makeRequest('/questions');
54+
}]);
5955
</script>
6056
<div ng-app="soApp">
6157
<div ng-controller="soCtrl">

0 commit comments

Comments
 (0)