-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
48 lines (42 loc) · 1.46 KB
/
script.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
var app = angular.module('WikiApp', ['ngAnimate']);
app.controller('MainCtrl', function($scope, $http, $timeout) {
var form = $('form');
var close = $('.eks');
var input = $('input');
var search = $("#search");
var help = $("#help");
$scope.results = [];
close.on('click', function() {
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', function() {
if (form.hasClass('open')) {
input.focus();
} else {
return;
}
})
$scope.search = function() {
$scope.results = [];
help.addClass('hide');
search.removeClass('fullHeight');
var title = input.val();
var 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=';
var cb = '&callback=JSON_CALLBACK';
var page = 'https://en.wikipedia.org/?curid=';
$http.jsonp(api + title + cb)
.success(function(data) {
var results = data.query.pages;
angular.forEach(results, function(v,k) {
$scope.results.push({title: v.title, body: v.extract, page: page + v.pageid})
})
});
}
});