briansugar / jquery.ogp

Open Graph Protocol parser in jQuery

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Open Graph Protocol parser

This is a simple parser for Open Graph Protocol data, implemented as a jQuery plugin.

The parser converts OGP data into a JSON object, in the same format as the server-side OGP to JSON parser. You can then use the data from jQuery without redeclaring the content in your page.

Usage

First, create a page with some OGP meta elements. Here's the canonical example:

<html xmlns:og="http://opengraphprotocol.org/schema/">
<head>
<title>The Rock (1996)</title>
<meta property="og:title" content="The Rock" />
<meta property="og:type" content="movie" />
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
...
</head>
...
</html>

Then load the jQuery library (tested with jQuery 1.4.2) and the jquery.ogp.js.

jsondata = jQuery('head').ogp();

Testing

There are some test pages in the test folder. You can fire up a simple webserver (Sinatra) by typing

rake server

and then open http://localhost:4567/.

There's also some basic test automation using the wonderful Ruby wrapper for env.js. Type

rake test

to run all the tests in a simulated browser environment.

License

This code is licensed under the BSD license. There's just a stub at the moment, but help yourself if it's useful to you.

About

Open Graph Protocol parser in jQuery