Home

Awesome

NOTICE: This project is deprecated and no longer maintained. If you'd like to continue supporting a forked version, please reach out on Twitter (@kidjustino) to have it listed here.

Marco Polo

Selenium Test Status Build Status

A jQuery autocomplete plugin for the discerning developer.

After spending years struggling with various autocomplete plugins, I became fed up with their bugginess, poor documentation, lack of updates, inflexibility, and antiquated coding patterns. Surely something as fundamental as autocomplete could — really, should — be done better. And now it has. Meet Marco Polo. For the discerning developer.

Developed by Justin Stayton while at Monk Development for the Ekklesia 360 CMS.

Features

Requirements

Installation

Download

Bower

Bower is a package manager for the web. Once installed, Bower can install Marco Polo with a single command:

bower install jquery-marcopolo

Manually

Include

Include both jQuery and Marco Polo in your HTML:

<script src="jquery.min.js"></script>
<script src="jquery.marcopolo.min.js"></script>

In most cases, jquery.marcopolo.min.js is the best file to include, as it contains the required libraries and source code in a single minified package.

The build directory contains a number of other files as well:

Getting Started

Let's say you want to create a user search field that redirects to the user's profile when a result is selected. To start, add a text input, if you haven't already:

<input type="text" name="userSearch" id="userSearch">

Then attach Marco Polo to the text input in your JavaScript:

$('#userSearch').marcoPolo({
  url: '/users/search',
  formatItem: function (data, $item) {
    return data.first_name + ' ' + data.last_name;
  },
  onSelect: function (data, $item) {
    window.location = data.profile_url;
  }
});

When a search happens, a GET request is made to the url with q (the search value) added to the query string. (Additional data can be included using the data option.) Let's say a search is made for Butler. A GET request is made to /users/search?q=Butler. Your backend code must then use the q parameter to find and return the matching users in JSON format:

[
  {
    "first_name": "James",
    "last_name": "Butler",
    "profile_url": "/users/78749",
    …
  },
  {
    "first_name": "Win",
    "last_name": "Butler",
    "profile_url": "/users/41480",
    …
  },
  …
]

Each JSON user object is passed to the formatItem callback option for display in the results list. And when a user is selected from the results list, their JSON object is then passed to the onSelect callback option to complete the browser redirect.

You should now have enough understanding of Marco Polo to start configuring it for your specific needs. While this example demonstrates a number of fundamental concepts, the possibilities extend far beyond the straightforward search, click, redirect setup shown here. And when you're ready, consider reading through some of the more advanced guides:

Options

All options are optional, although url is usually specified unless the input field is in a form by itself (in which case the form's action attribute can be used).

Callbacks

Formatting

Events

Methods

Feedback

Please open an issue to request a feature or submit a bug report. Or even if you just want to provide some feedback, I'd love to hear. I'm also available on Twitter as @kidjustino.

Contributing

  1. Fork it.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Added some feature').
  4. Push to the branch (git push origin my-new-feature).
  5. Create a new Pull Request.