Skip to content
forked from xoxco/awarejs

Tookit for enabling reader aware design for your site.

Notifications You must be signed in to change notification settings

jackplug/awarejs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Aware.js

Make Your Site Reader Aware

Aware.js is a simple jQuery plugin that allows a site to customize and personalize the display of content based on a reader's behavior without requiring login, authentication, or any server-side processing.

Read about the concept of "reader aware design."

View Demo of Aware.js in action. This demo uses Aware.js and CSS only to drastically alter the layout an otherwise static page in three different ways based on the reader's personalized relationship with the content.

Created by XOXCO

Download

Get it from Github

Aware.js is released under the MIT Open Source license. It's free to use, and you can use it however you want!

Instructions

Aware.js bundles several features into one easy to implement library. To add it to your site, include the script tag, and then initiate the plugin:

$().aware();

Aware.js will then leap into action, and perform a variety of useful functions like:

Tracking the amount of time between a reader's visits

Aware.js will track a reader's visits, and provide information about the reader's habits, making information available to developers via CSS classes AND via a Javascript reader object.

Classes will be added to the body tag to represent various states a reader might be in:

.first-visit - This is the reader's first visit on record.

.repeat-visitor - This reader has been to the site at least once before.

.first-visit-of-day - This is a reader who has visited before, but not today.

In addition, the reader object contains this same information, along with some specific information about previous visits. This is useful for Javascript developers who want to add more dynamic features to their site based on this information (and who don't want to query the DOM for classes)

reader.firstVisit	- true/false
reader.repeatVisitor - true/false
reader.firstVisitOfDay - true/false

reader.lastVisit - Javascript Date object
reader.secondsSinceLastVisit  - seconds since last visit
reader.timeSinceLastVisit - relative timestamp "28 minutes"

This simple information can be used to mildly or drastically alter the layout of a page. For example, first time visitors can be shown a special introduction, while repeat visitors are shown only the newest things. Visitors who haven't come in a while can be presented with a recap of recent, important items.

Flag Content As New or Seen

Aware.js can also flag content on a page as new to the reader, helping them keep up-to-date without remembering what they read last visit.

To enable this, the publication date of each piece of content must be included as an HTML5 data attribute, data-pubDate in the format YYYY-MM-DD HH:MM:SS, as below:

<div class="post" data-pubDate="2012-07-01 02:30:00">
	POST HERE
</div>

Once these attributes are added to the markup, tell Aware.js to process them by passing in a element selector:

$('.post').aware();

Any matching element with a date after the reader's last visit will have the .new class added. Any item with a date before the reader's last visit will have .seen added.

Highlight new elements by using the .new class in your CSS:

.post.new {
	background: #FFFF99;
}

Insert Relative Bookmark

Inspired by the Andre Torrez's image sharing site, Mlkshk, Aware.js also provides a method for inserting relative bookmarks into the stream of content to clearly delineate content added since the reader's last visit. See demo.

Shkmark Demo

To inject a relative bookmark below the last new post, call the deferentially named shkmark() function after calling aware(). The relative bookmark will include the message, "You started reading here timestamp ago."

$('.post').aware();
$('.post').shkmark();

// this would result in a div with class .bookmark being added:
// <li class="shkmark">You started reading here 5 minutes ago</li>

Options

Aware.js has several options that can be used to customize its behavior:

$(optional_selector).aware({
	dateAttribute: 'data-pubDate', 
	// change the name of the attribute that contains the date


	bufferTime: 10*60*1000 
	// time in milliseconds that a freshly published piece 
	// of content should be flagged as new regardless of reader's last visit.
});

By default, shkmarks are created as <li> elements with the class .shkmark, but these can be overridden:

$(.post').shkmark({
	element: 'div',
	className: 'bookmark'
});

// this would result in a div with class .bookmark being added:
// <div class="bookmark">You started reading here 5 minutes ago</div>

About

Tookit for enabling reader aware design for your site.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published