/widget-server

An example Rails and JavaScript app to demonstrate how to build a 3rd party JavaScript widget

Primary LanguageRuby

3rd Party JavaScript Widgets

Jonathan Julian (@jonathanjulian) April 23, 2012, BohConf in Austin, TX (the RailsConf un-conf)

What is a widget?

  • Some part of a page generated from another site
  • Not an iframe
  • Built using JavaScript
  • easy for the site owner to implement

Examples

Issues

  • communication
  • namespace collisions
  • need prereq JS libs
  • styling the widget

Solutions

  • use JSONP to get data, use JSONP to transmit data
  • run your code in a scoped function
  • load scripts dynamically
  • use a reset stylesheet on your elements

Server-side: Rails 3

  • expose data as JSON with a callback
  • accept JSONP "submissions"

Client-side: JavaScript

  • create a namespace
  • load scripts
  • load data
  • load CSS
  • build the DOM elements
  • respond to events

Alternative technologies

Thanks for the inspiration

Running this code

  • Run the server rails server
  • Run the host web site nginx -p `pwd`/host/ -c `pwd`/host/nginx.conf
  • Go to http://localhost:8080