Friday, September 17, 2010

Introducing jQuery API Search

Introducing jQuery API Search

Half-baked tutorials and plugins have been stacking up for months in my virtual kitchen, waiting for me to fire up the oven, finish the cooking, and spread them out on the table. For some reason, though, I've become less and less sure about whether I've put all the right ingredients into the mix. It's irritating, to be sure, but I'm tired of fretting about it. I'm going to consider this the first of what I hope to be many 'taste tests' — experiments in various degrees of completion thrown against the wall to see what, if anything, sticks.

As some of you may know, the online jQuery documentation went through a major overhaul in January of this year, coinciding with the release of jQuery 1.4. Packt Publishing 'open sourced' the jQuery 1.4 Reference Guide that Jonathan Chaffer had been writing, allowing us to put its entire contents (and more) on api.jquery.com. Some of you may also know that the raw XML content of the site is available as a single file, which has allowed other sites such as jqapi.com and idocs.brandonaaron.net to provide alternative views of that content. But what most of you probably do not know is that the jQuery API has been available for quite some time as a searchable API that returns the results in JSON format.

Note: The reason you probably don't know about it is that it's half-baked. So, please go easy on it until some smart people have a chance to look under the hood at what I'm doing. Crazy abuse will surely bring it to its knees.

Motivation

I wanted to let people access the jQuery documentation via JavaScript from any other site and pull out exactly what is needed. I also wanted to play around with JSONP. This fits both of those desires.

URL

To access the searchable API, use the following URL:

http://api.jquery.com/jsonp/

Examples

You can tap into the API with one of jQuery's Ajax methods. If you use $.get() or $.getJSON(), you'll need to append '?callback=?' to the URL. With $.get(), you'll also need to set the dataType argument to 'jsonp'.

Find entries in the API that have 'class' in their name and then do something with them:

JavaScript:
  1. $.get('http://api.jquery.com/jsonp/?callback=?',
  2. {name: 'class'},
  3. function(data) {
  4. // do something with data
  5. },
  6. 'jsonp');

Find all effects-category entries and then do something with them:

JavaScript:
  1. $.getJSON('http://api.jquery.com/jsonp/?callback=?',
  2. {category: 'effects'},
  3. function(json) {
  4. // do something with json
  5. });

You can, of course, also use the low-level $.ajax() method.

Find entries with a title that ends in 'ajax'; append a link for each to the document body:

JavaScript:
  1. url: 'http://api.jquery.com/jsonp/',
  2. dataType: 'jsonp',
  3. data: {title: 'ajax', match: 'end'},
  4. success: function(json) {
  5. for (var i=0, len=json.length; i<len ; i++) {
  6. var entry = json[i];
  7. $('<a />', {
  8. href: entry.url,
  9. html: entry.title
  10. }).appendTo('body');
  11. }
  12. }
  13. });

Search Types

The JSONP API is searchable by name, category, and version. Searching by more than one criterion returns results that match all of the criteria. All searches are case-insensitive.

  • Search by name:
    • Key: title
    • Value: the name of any jQuery method, property, or selector
    • Searches in: post title and post slug
    • Substitutions: Before querying the database, all '$' are converted to 'jQuery' and each instance of one or more spaces is converted to a hyphen ('-') for both the search values and the the post title and slug.
    • Default: all titles
  • Search by category name
    • Key: category
    • Value: category name
    • Substitutions: Before querying the database, each instance of one or more spaces is converted to a hyphen ('-')
    • Searches in: category slug
    • Default: all categories
  • Search by version number
    • Key: version
    • Value: a jQuery version number
    • Searches in: category slug for all categories that are a child of the main 'version' category
    • Default: all versions

String Matching

The 'match' parameter lets you be confine the results to those that match the entire search term, or just the start or end of it.

  • Key: match
  • Value: one of 'start', 'end', or 'exact' (for search by version number, one of 'end' or 'exact')
  • Default: 'anywhere', except for version number, which has a default of 'start'

Returned Data

Data is returned as an array of objects. Each item in the array is an object representing a single method, property, or selector. For example, a result with one item would have the following structure:

JavaScript:
  1. [
  2. {
  3. "url": "...",
  4. "title": "...",
  5. "type": "...", // "method", "property", or "selector"
  6. "signatures": [
  7. {
  8. "added":"...",
  9. "params": [
  10. {
  11. "name": "...",
  12. "type": "...",
  13. "optional": "...", // either "true" or an empty string
  14. "desc": "..." // description of the parameter
  15. }
  16. ]
  17. }
  18. ],
  19. "desc": "...", // short description
  20. "longdesc": "...", // long description
  21. "return": "..." // type of return value
  22. }
  23. ]

Note that currently the examples/demos from each entry are not returned.

A (Fairly) Basic Demo

I put together a quick demo to give an idea of the API's flexibility. Type something into the 'Name' field in the form below—say, 'ajax'—and watch as the results come back. Inside the 'Advanced' area, choose the 'Matching... End' radio button and search again to see how the results differ.

✚ Search Again

jQuery API Search A demonstration

Name
Category
Version
Search

✒ Advanced

Matching
Anywhere
Start
End
Exact
Include in Results
Version Added
Arguments
Short Description
Long Description

Clear Results

A Little Less Basic Demo

I replicated this search form on a test server and added back-button support with Ben Alman's crazy delicious BBQ Plugin. Try out the demo.

But wait! There's more!

I put the whole shebang (well, except for the server-side stuff) in a GitHub repo. Clone it, fork it, have your way with it.

But Wait! There's Less!

As I mentioned above, this little project is incomplete. If you peek at the scripts, you'll quickly spot some major chunks of code in need of refactoring. Also, had I but world enough and time, I'd use a nice templating system such as mustache.js or the jQuery Templates plugin to output the search results. But I'll leave all that for another day (or another developer).

Tuesday, May 18, 2010

Flip Any HTML Element With jQuery Flip!

Flip Any HTML Element With jQuery Flip!:

Flip! is a jQuery plugin that enables you to flip any HTML, text or jQuery element beautifully.

It is possible to set the direction of the effect, right-to-left, up-to-down or vice versa of both, the content to be displayed after the flip and the background of it.

Also, optionally, you can define the speed of the animation and use the callback functions: onBefore, onAnimation and onEnd.

P.S. Tutorialzine shares a very nice tutorial using the plugin.

jQuery Flip Plugin

Special Downloads:

Related posts

A Tweeting jQuery Plugin for Visitors to Your Website

A Tweeting jQuery Plugin for Visitors to Your Website:

“Like it? Tweet it!” is a jQuery-powered JavaScript widget that enables visitors to your website or blog to write a tweet about the site directly in a box displayed in the corner of the website, with a link to the site already embedded in the input field.

It makes it easy for users to share your site with friends while still giving them the opportunity to type out something cool for themselves and thus avoiding auto-tweets. The tweet box is activated when users click on a link you specify, and Like it? Tweet it! has tons of customization options which you can play with to make the widget totally blend in and become one with your site.

tweet-plugin

Requirements: jQuery Framework Demo: http://pongsocket.com/tweet-it/ License: License Free

Pikachoose: jQuery Image Gallery

Pikachoose: jQuery Image Gallery:

Pikachoose is a lightweight jQuery plugin that allows you to easily create photo galleries with customization options for slideshows, navigation buttons, and auto play. It also allows you to add more than one image gallery in a single page. Pikachoose is a cross browser plugin that works in all major web browsers.

Pickachoose is requires simple markup (an unordered list containing images and captions) and is very easy to implement. You can customize the look and feel of your gallery / slideshow by modifying CSS. It also offers configuration options enabling you to customize various features.

Features

  • Multiple Galleries on a Page
  • Auto Thumb Resizing
  • Specify Transition Effects
  • Enable / Disable Captions
  • Enable / Disable Slideshow Option & Controls
  • Enable / Disable Auto Play
  • Enable / Disable Previous & Next Buttons
  • Specify Height/Width of Thumbnails
  • Specify Delay
  • Specify Custom THumbnails

Developed by Jeremy Fry; Pikachoose jQuery Plugin is available for download under GNU General Public License. You can find further information, demos & download on Pikachoose Website.

Similar Posts:

Friday, April 30, 2010

Micro Image Gallery jQuery Plugin

Micro Image Gallery jQuery Plugin:

In many blogs and news sites images are mostly included as an addition to the content. Space is often limited and therefore it would be a good idea to integrate a miniature image gallery that does not occupy a lot of space.

Micro Image Gallery jQuery plugin transforms a set of images into a tiny gallery with several options. It allows to switch between a grid view which shows a preview of the images as thumbnails and a single view showing one image only. The navigation bar can be hidden and sliding out when hovering over the gallery, or visible. A total of nine thumbnails are shown in the grid preview. The plugin will automatically resize the image according to the chosen gallery size.

micro-image-gallery

Requirements: jQuery Framework Demo: http://tympanus.net/Tutorials/MicroGallery/ License: License Free

jCoverflip: Highly Customizable Content Slider

jCoverflip: Highly Customizable Content Slider:

jCoverfilp is a jQuery plugin that allows you to create highly customizable featured content sliders. It provides you with extra control over your slider component with functions to customize the styling and animation for items to the left and right of the current item. jCoverfilp is cross browser plugin that works in all modern web browsers.

jCoverfilp requires both jQuery and jQuery UI library to work, and is easy themeable. The default installation uses a clean style that can be updated with ease. All aspects of jCoverflip are customizable through the API, including: colors, fonts and styles, animation speed and number of items.

Features

  • Drag or click functionality to showcase featured content items on demand by the user
  • All aspects of jCoverflip are customizable through the API
  • Ability to showcase both images and content associated with an item.
  • Module integration with Drupal or Standalone version

Developed by New Signature; jCoverfilp is available for download under GNU General Public License. You can find further information, demo & download on jCoverfilp Website.

Similar Posts:

Thursday, April 1, 2010

Nivo Slider: jQuery Image Slider With Multiple Transitions

Nivo Slider: jQuery Image Slider With Multiple Transitions:

Nivo Slider is a lightweight jQuery plugin that lets you create image slider with 9 unique transition effects: sliceDown, sliceDownLeft, sliceUp, sliceUpLeft, sliceUpDown, sliceUpDownLeft, fold, fade and random. Nivo Slider is a cross browser plugin and has been tested in following browsers: Internet Explorer 7+, Firefox 3+, Google Chrome 4, and Safari 4.

Nivo Slider is really easy to implement and requires simple markup with images wrapped inside a div element. To to add a caption you simply need to add a title attribute to the image. In addition to left and right buttons, it can display navigation controls enabling users to jump from one slide to another. Nivo Slider also provides several configuration options, enabling you to customize its behavior.

Features

  • Nine unique transition effects
  • Simple clean & valid markup
  • Ability to configure animation speed, pause and number of slices
  • Enable /disable directional and control navigation
  • Ability to add beforeChange and afterChange functions

Developed by Gilbert Pellegrom; Nivo Slider is available for download under the GPL License. You can find further information, demo & download on Nivo Slider Website.

Similar Posts:

Monday, March 22, 2010

Visually Connect HTML Elements: jsPlumb

jsPlumb is a jQuery plugin for visually connecting HTML elements on a web page.

It uses a HTML5 canvas element when supported and Google's ExplorerCanvas script to support older browsers.

The styles, shapes of the wires and "the position of the connection" can be customized easily.

jsPlumb jQuery Plugin

jsPlumb also supports drag'n drops (requires jQuery UI for this functionality).

The plugin is currently in beta status, however, works flawless and can be downloaded from the source of the demos provided.

Special Downloads:

Related posts

Embed Google Maps Directions With jQuery GPS

Embed Google Maps Directions With jQuery GPS:

jQuery GPS is a lightweight jQuery plugin that enables you to easily add clean Google maps directions (without unwanted features) in your website. It provides you control over look and feel of input fields and the output. jQuery GPS uses Google Maps API, and you must get your own API key to use this plugin.

Jquery GPS provides easy to configure features enabling you to control: whether you want to show turn by turn directions in text; specify initial zoom level, enable/disable tooltip and optionally place an image at the default location. It is a cross browser plugin that work in all major browsers including IE6.

Developed by Aron Brown; jQuery GPS is available for download under the GNU General Public License. You can find further information, demo & download on jQuery GPS Website.

Similar Posts:

Wednesday, March 10, 2010

Spritely: Create Sprite Animation Using jQuery

Spritely: Create Sprite Animation Using jQuery:

Spritely is a jQuery plugin for creating dynamic character and background animation in pure HTML and JavaScript. It is a light-weight plugin with a few simple methods that allow you to easily create animated sprites and scrolling backgrounds. It is a cross browser plugin that works on all major browsers including iPhone and Internet Explorer 6.

Spritely provides two key methods, sprite() and pan() both of which simply animate the background-image CSS property of an element. The difference between the two is that a ’sprite’ image contains two or more ‘frames’ of animation, whereas a ‘pan’ image contains a continuous image which pans left or right and then repeats.

Developed by Artlogic Media; Spritely is dual licensed under the MIT or GPL Version 2 Licenses. You can find further information, documentation, demo & download on Spritely Website.

Similar Posts: