A Simple, Google-ish Wikipedia Search Project

A Simple, Google-ish Wikipedia Search Project
0

#1

Hi All,

I would love to hear critique of my wikipedia viewer, be it about design, clarity/function of code, or anything else that comes to mind.

Thank You x 1 million,
Sam


#2

Hi :slight_smile:

This code:

$.ajax({
      type: 'GET',
      url: 'https://en.wikipedia.org/w/api.php?'+
      'action=query' +
      '&list=search' +
      '&srsearch=' + 
      searchTerm +
      '&format=json',
      dataType: 'jsonp',
...

It can be written using the data parameter:

http://api.jquery.com/jquery.ajax/

data
Type: PlainObject or String or Array
Data to be sent to the server. It is converted to a query string, if not already a string. It’s appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key based on the value of the traditional setting (described below).


#3

I like it, simple and nice.

You may add some handling for entry not found situations. For example, if I search for “;lckmds” it just isn’t showing anything, but would be nice if it would write something like “couldn’t find this entry, try to search for something else”. I haven’t implemented this myself yet, but I think it can be easily done with checking json properties like “if (data.query.search == null)”.


#4

Thanks Erretres! I’ve updated the query to use the data parameter. I like separating the base url from the query; that’s much cleaner.


#5

Thanks svmi! I added a little error handling message for entry not found. It turns out data.query.search will still have an array assigned to it, though the array will be have a length of 0. This is helpful to consider for all API-related projects. When I go back to review my projects I will definitely try to sort out the specific error scenarios and make helpful responses on the page.


#6

[quote=“swfisher, post:5, topic:28696”]
It turns out data.query.search will still have an array assigned to it, though the array will be have a length of 0
[/quote]Good to know, will use it. I am trying to handle possible errors, if I figure out they can happen)


#7

Oh, by the way, since you are doing this:

function banishBtns(){ $('.searchBtns').animate({opacity: '0'},0); }

it gives a funny effect. When I searched and received my result, I cannot see the buttons, but if I accidentally click on their place, they will work and, for example, suddenly send me to random wiki article. This is because they are invisible, but still exist where they are.


#8

Thank you! Excellent bug catch… I would not have seen that without your help. Perhaps I can either dynamically generate the buttons or figure out a way to disable their function. I’ll let you know what I end up with.


#9

I went with removing the opacity animation altogether & I replaced it with dynamically generated buttons. In order to bind the events needed for the buttons to function, I created a delegated event using jQuery’s $(‘parent’).on(‘event’, ‘child’, function(){…}) syntax.