-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (42 loc) · 1.44 KB
/
Copy pathscript.js
File metadata and controls
48 lines (42 loc) · 1.44 KB
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
const app = angular.module('WikiApp', ['ngAnimate']);
app.controller('MainCtrl', ($scope, $http, $timeout) => {
const form = $('form');
const close = $('.eks');
const input = $('input');
const search = $("#search");
const help = $("#help");
$scope.results = [];
close.on('click', () => {
form.toggleClass('open');
if (!form.hasClass('open') && $scope.searchTxt !== '' && typeof $scope.searchTxt !== 'undefined') {
search.toggleClass('fullHeight');
help.toggleClass('hide');
$scope.searchTxt = '';
}
$scope.results = [];
$scope.$apply();
});
input.on('transitionend webkitTransitionEnd oTransitionEnd', () => {
if (form.hasClass('open')) {
input.focus();
} else {
return;
}
});
$scope.search = () => {
$scope.results = [];
help.addClass('hide');
search.removeClass('fullHeight');
const title = input.val();
const api = 'https://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrnamespace=0&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=';
const cb = '&callback=JSON_CALLBACK';
const page = 'https://en.wikipedia.org/?curid=';
$http.jsonp(api + title + cb)
.success(data => {
const results = data.query.pages;
angular.forEach(results, (v, k) => {
$scope.results.push({ title: v.title, body: v.extract, page: page + v.pageid });
});
});
};
});