Giter VIP home page Giter VIP logo

dug.js's Introduction

dog illustration

So you want to display your Dribbble shots, recent pins on Pinterest, 500px or Instagram photos, Github commits, or recently listened to music on your blog or site? Then this chunk of javascript is for you. It was designed to be a lightweight, simple, library-independent script to pull in feeds of content available on the web as JSONP (there's lots of em!) to display on your site.

Read the full explanation over at the blog post.

A JSONP to HTML script

Usage

With Dug.js, you really only need two things to pull in data from any JSONP endpoint into any HTML page:

  1. The api endpoint (jsonp callbacks supported)
  2. The HTML template to display the data

Include dug.js

First step is to place dug.js in your /js directory, and include is in your document <head> via <script src="/js/dug.js"></script>.

Add render templates to your HTML

Once you have included dug.js on your page, you can then create render templates directly in your HTML doc by simply calling the dug function, and including the endpoint param, target param, and a template param.

There are five example instances here in the repo, including:

Params

  • target — the id of an existing DOM element to put the html results in.
  • template — the string template OR a CSS selector pointing to a template script.
  • cacheExpire — # of milliseconds to cache data on the client side (using localstorage). 0 for no caching.
  • callbackParam — the name of the query variable a JSONP service will use for a callback function. Most services just use 'callback=functionName', but sometimes a service will use a different query variable name.
  • success — a function to call when JSONP data is successfully retrieved.
  • error — a function to call when JSONP data is not successfully retrieved.
  • beforeRender @param data — a function called before Dug.js renders the template. Helpful for trimming/changing the data before it renders.
  • afterRender @param data — a function called after Dug.js renders the template.

Contributing

If you have a great idea for making dug.js better, just fork, and open a pull requests for discussion & development. When in doubt, open the PR early for discussion (prior to actually fully completing the feature) and once we have a chance to discuss whether it's a good idea, then go build that ✨!

License

Dug.js is 100% free under the WTFPL — no link backs or anything needed.

dug.js's People

Contributors

rogie avatar velppa avatar kennethormandy avatar

Watchers

Joe Watkins avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.