Widgets

What is a widget?

A widget is a tool that pulls content from one location and displays it in a compact form at another location. Widgets are not advertisements, they are a way to cross pollinate sites. They should be helpful and functional.

Search widget

The marketplace search widget is intended to be a tool to promote marketplace search on other sites. It consists of a header graphic, search box, and an optional featured business listing.

Quick example:

<script type="text/javascript">
  mp_search_widget = {
    'header_url': 'http://media.ljworld.com/static/marketplace_default/images/widgets/search_header.jpg',
    'marketplace_url': 'http://ljworld.com/marketplace/'
  }
</script>
<script type="text/javascript" src="http://media.ljworld.com/static/marketplace_default/javascript/search_widget.js"></script>
<script type="text/javascript" src="http://ljworld.com/marketplace/api/v0/random_business_json/?callback=randomBusiness"></script>

Output:

_images/search_widget.gif

Required parameters

In order for the widget to work you’ll need to provide it with some information about your marketplace site.

header_url
This needs to be a graphic (JPG or GIF) sized properly to fit the width of the widget. The default widget content area width is 280 pixels.
marketplace_url
This needs to be a url to your marketplace site with the http:// prefix and ending forward slash.

Optional parameters

You can pass the search widget a few options to customize the look and size so it works with your site layout.

container_width
This sets the container width of the widget.
container_border
Sets the border around the widget container. Possible value would be 1px solid #dddddd which stands for the size, type and color.
id
Sets the ID of the widget tag so it can be exclusively targeted with CSS.

Data URL

If your Marketplace site is at http://example.com, the default data url is http://example.com/marketplace/api/v0/random_business_json/. This will query businesses in your default market. If you would like to create a widget that pulls from markets other than your default, append that market to data_url. For example: http://example.com/marketplace/api/v0/random_business_json/market/?callback=randomBusiness. The data url must have the callback parameter set to randomBusiness.

It is possible to further customize the widget by specifying options in your data_url. The following paramters can be passed to data_url as QueryString parameters:

number-requested
The number of businesses to return (default: a list of one business).
category-requested
Limit businesses returned by category path (default: None).
photo-width
Crop business photo to this width (default: 80).
photo-height
Crop business photo to this height (default: 70).
business-type
Limit what type of businesses to return (allowed values: basic, expanded, homepage-sponsor, category-sponsor, None. Default: None [any business]).
callback
Must be set to randomBusiness.

Here is an example of a data_url that businesses with custom photo sizes and a custom callback:

http://example.com/marketplace/api/v0/random_business_json/?photo-width=100&photo-height=80&callback=mycallback

A call to data_url will return information used by the widget. If you would like to make use of the data_url within your own applications, here is an example of the data returned by the example above:

mycallback([
   {
      "pk":9174,
      "model":"business.business",
      "fields":{
         "point":null,
         "fax":"",
         "validated":true,
         "meta_description":null,
         "city":"Lawrence",
         "mailing_zip_code":null,
         "mailing_address2":null,
         "state":"KS",
         "mailing_address1":null,
         "latitude":null,
         "thumbnail":"http://media.lawrence.com/img/marketplace/businesses/images/2008/03/14/FrontDesk_r100x80.jpg?144a9619b7b2d55e12d8b619b3e5adb91a2095fa",
         "zip_code":"66046",
         "website":"http://www.sunkissed.com/",
         "suggested_type":"",
         "description":"",
         "phone2":"",
         "address1":"2540 Iowa St Ste M",
         "address2":"",
         "phone1":"785-842-5096",
         "default_hours":null,
         "nickname":"",
         "slug":"sunkissed_tanning",
         "categories":[
            1673,
            1685
         ],
         "additional_hours_info":"",
         "business_type":1,
         "name":"Sunkissed Tanning",
         "hours_text":"Open today until 8:30 p.m.",
         "safe_description":"",
         "notes":"Kathy & Mike Byrnes (Owners)\r\nkathy@sunkissedlawrence.com\r\n816-665-4849 (Evening)",
         "pre_name":"",
         "longitude":null,
         "email":"",
         "mailing_state":null,
         "mailing_city":null
      }
   }
])

The data_url returns a representation of each field stored for the business as well as a few extra fields:

thumbnail
A thumbnail of either the main photo for the business or the still for the main video.
safe_description
The description of the business with any HTML tags removed.
hours_text
A text description of if the business is open or if closed when it will be open next.

Home

Browse

Glossary

You are here:

This Page