Home

Awesome

trustfeed.js

A library-agnostic micro API wrapper for Trustpilot.

Trustfeed.js is licensed under the terms of the MIT License.

Usage

Include the css file into the head of your document:

<link rel="stylesheet" type="text/css" href="trustfeed.css">

Include the javascript file right before the </body> tag:

<script src="trustfeed.js"></script>

Create one or more elements with class name trustfeed:

<div class="trustfeed"></div>

Finally, define your clientId and load the feed:

Trustfeed.load({
  clientId: 1234567
})

This will fill every html element with class name trustfeed with the latest items.

Customizing

There is a variaty of configuration options.

class

The class name of the elements filled with the trustpilot stream:

Trustfeed.load({
  clientId: 1234567
, class: 'my-class'
})

limit

The maximum amount of reviews to be showed:

Trustfeed.load({
  clientId: 1234567
, limit: 5
})

maxCharacters

The maximum amount of charaters for the content of the review:

Trustfeed.load({
  clientId: 1234567
, maxCharacters: 50
})

offset

The position to start showing reviews:

Trustfeed.load({
  clientId: 1234567
, offset: 3
})

The above example will show from the third to the tenth review.

readMore

Template for the read more link:

Trustfeed.load({
  clientId: 1234567
, readMore: '<a href="{{url}}">Give me more!</a>'
})

defaults to:

<a href="{{url}}" target="_blank">Read more</a>

reverse

Reverses the order of reviews:

Trustfeed.load({
  clientId: 1234567
, reverse: false
})

starSize

The size of the stars:

Trustfeed.load({
  clientId: 1234567
, starSize: 'large'
})

template

The template for every review:

Trustfeed.load({
  clientId: 1234567
, template: '<article class="trustfeed-entry"><h3>{{title}}</h3><div class="stars tf-stars-{{stars}} tf-stars-{{starSize}}"></div><p class="content">{{content}}{{more}}</p><p class="author">{{name}}</p></article><p class="date">{{date}}</p>'
})

Within the template the following variables are available:

defaults to:

<article class="trustfeed-entry">
  <h3>{{title}}</h3>
  <div class="stars tf-stars-{{stars}} tf-stars-{{starSize}}"></div>
  <p class="content">{{content}}{{more}}</p>
  <p class="author">{{name}}</p>
</article>

Important: the template can not contain newlines!