Skip to content

Commit

Permalink
fix configuration issue, bump version to 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
typerandom committed Jan 19, 2016
1 parent f988816 commit 7a766fa
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 54 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $ bower install activity --save

## Usage

At the end of your code, right before `</body>`, add the following:
At the end of your code, right before `</body>`, call the following:

```javascript
Activity.detect();
Expand All @@ -34,12 +34,12 @@ Activity.detect();
Once this is done, you'll be able to detect user activity by listening to either the `user_active` or `user_inactive` events, as shown below:

```javascript
window.addEventListener('user_active', function () {
console.log("The user is active!");
Activity.on('active', function () {
console.log("The user is active!");
});

window.addEventListener('user_inactive', function () {
console.log("The user is inactive!");
Activity.on('inactive', function () {
console.log("The user is inactive!");
});
```

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "activity",
"version": "0.6.0",
"version": "0.7.0",
"main": [
"dist/activity.min.js"
],
Expand Down
39 changes: 17 additions & 22 deletions dist/activity.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/activity.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/activity.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/activity.min.js.map

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions example/console.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<html>
<head>
<script src="../dist/activity.js"></script>
<script>
Activity.on('active', function () {
console.log("The user is active!");
});

Activity.on('inactive', function () {
console.log("The user is inactive!");
});

Activity.detect();
</script>
</head>
<body>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "activityjs",
"version": "0.6.0",
"version": "0.7.0",
"description": "Know when your users are using your site",
"homepage": "https://github.com/typerandom/activity.js#readme",
"author": "Robin Orheden",
Expand Down
39 changes: 17 additions & 22 deletions src/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,23 @@

Object.freeze(Activity.State);

// Method that helps with setting up the user monitor.
// Forwards all user monitoring events to the window scope.
Activity.detect = function detect(options) {
if (Activity._instance) {
return false;
var instance = null;
function resolveInstance(options) {
return !instance ? instance = new Activity(options) : instance;
}

Activity.configure = function configure(options) {
return resolveInstance(options);
};

Activity.detect = function detect() {
var instance = resolveInstance();

if (instance.initialized) {
return true;
}

var instance = Activity._instance = new Activity(options);
instance.initialized = true;

instance.on('inactive', function () {
window.dispatchEvent(new CustomEvent('user_inactive'));
Expand All @@ -231,26 +240,12 @@
return true;
};

// Listen to a event.
Activity.on = function on(name, listener) {
var instance = Activity._instance;

if (!instance) {
throw new Error('Activity.detect() hasn\'t been called.');
}

return instance.on(event, handler);
return resolveInstance().on(name, listener);
};

// Get activity state.
Activity.state = function state() {
var instance = Activity._instance;

if (!instance) {
throw new Error('Activity.detect() hasn\'t been called.');
}

return instance.state();
return resolveInstance().state();
};

// Replays the current user state to all event listeners.
Expand Down

0 comments on commit 7a766fa

Please sign in to comment.