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'
})
- defaults to:
'trustfeed'
limit
The maximum amount of reviews to be showed:
Trustfeed.load({
clientId: 1234567
, limit: 5
})
- defaults to:
10
- absolute maximum:
10
maxCharacters
The maximum amount of charaters for the content of the review:
Trustfeed.load({
clientId: 1234567
, maxCharacters: 50
})
- defaults to:
145
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.
- defaults to:
0
- absolute maximum:
9
(will show 1 comment)
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
})
- defaults to:
true
starSize
The size of the stars:
Trustfeed.load({
clientId: 1234567
, starSize: 'large'
})
- defaults to:
'medium'
- available options:
'small'
,'medium'
,'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:
- title (review title)
- content (review content)
- url (link to the review)
- more (the
readMore
template) - score (review score)
- stars (number of stars)
- image (review stars image)
- name (name of the user)
- date (date of the review)
- datetime (date and time of the review)
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!