-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebIQ (addon) #14
base: master
Are you sure you want to change the base?
WebIQ (addon) #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
Groucho : WebIQ | ||
============== | ||
|
||
**How good is this user at internetting.** | ||
|
||
This addon uses Groucho to track events which reveal the level of experience users have with web and computer norms. For example: using Ctrl+F on-page or tab in forms a good sign, while having to delete within forms much or doubleclicking on web links is likely a confused, or drunk, user. | ||
|
||
## Install | ||
Include the addon source, then update any config settings. Here are the defaults... | ||
|
||
```html | ||
<!-- Base groucho includes --> | ||
<script src="groucho/addons/webiq/webiq.min.js"></script> | ||
<script> | ||
// Can be skipped for defaults. | ||
groucho.config.addons.webiq = { | ||
'behaviors': { | ||
'formsDelete': { 'increment': -1, 'threshold': 3, 'stash': 0 }, | ||
'formsTab': { 'increment': 2 }, | ||
'findOnPage': { 'increment': 4 }, | ||
'doubleClick': { 'increment': -0.5 }, | ||
'repeatPage': { 'increment': -3, 'threshold': 1 } | ||
} | ||
}; | ||
</script> | ||
</body> | ||
``` | ||
You may have different views on the relative importance of behaviors, as this varies by audience. Free free to change values to suit your needs, or remove listeners altogether when not appropriate. | ||
|
||
## Score | ||
All you actually need to worry about is getting the score. This can be obtained whenever you please, here's any example use... | ||
|
||
```javascript | ||
$('form').submit(function() { | ||
$(this).find('.webIQScore').text(groucho.addons.webIQ.getScore()); | ||
}); | ||
``` | ||
|
||
## More Examples | ||
|
||
You also have access to specific results... | ||
|
||
```javascript | ||
if (groucho.addons.webIQ.getScore('repeatPage') < -7) { | ||
$('.navigation').addClass('.jumbo'); | ||
} | ||
``` | ||
|
||
As well as detailed results... | ||
```javascript | ||
var behaviors = groucho.config.addons.webiq.behaviors, | ||
scores; | ||
|
||
$('form').submit(function() { | ||
scores = groucho.addons.webIQ.getScore(); | ||
for (var b in behaviors) { | ||
$(this).find('.webIQScore.' + behaviors[b]).text(scores[behaviors[b]])); | ||
} | ||
}); | ||
``` | ||
|
||
## New Behaviors | ||
You can add your own scoring behaviors easily. Add the name and settings to the `behaviors` config within Groucho addons. The name will be used to call a coresponding function. You're responsible for: creating the matching function on the `groucho.adds.webIQ` object, listening for events and adding activities. The increment value will tell `getScore` how to tally your activity records. Here's an example... | ||
```html | ||
<!-- Base groucho includes --> | ||
<script src="groucho/addons/webiq/webiq.min.js"></script> | ||
<script> | ||
/** | ||
* Listen: Clicking on non-link table headers. | ||
*/ | ||
groucho.config.addons.webIQ.behaviors.myBehavior = { 'increment': -5 }; | ||
groucho.adds.webIQ.myTableBehavior = function myTableBehavior() { | ||
$('th').click(function() { | ||
if (!$(this).children('a').length) { | ||
groucho.createActivity('webIQ', { 'type': this.name }); | ||
} | ||
}); | ||
} | ||
</script> | ||
</body> | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
/** | ||
* @file | ||
* Determine user's comfort with web norms. Cough. | ||
*/ | ||
|
||
groucho.addons = groucho.addons || {}; | ||
groucho.config.addons = groucho.config.addons || {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'groucho' is not defined. |
||
|
||
(function ($, groucho) { | ||
|
||
var checkThreshold, | ||
listeners; | ||
|
||
// Defaults. | ||
groucho.config.addons.webIQ = { | ||
'behaviors': { | ||
'formsDelete': { 'increment': -1, 'threshold': 3, 'stash': 0 }, | ||
'formsTab': { 'increment': 2 }, | ||
'findOnPage': { 'increment': 4 }, | ||
'doubleClick': { 'increment': -0.5 }, | ||
'repeatPage': { 'increment': -3, 'threshold': 1 } | ||
} | ||
}; | ||
|
||
// Bind listeners. | ||
$(document).ready(function () { | ||
var behaviors = groucho.config.addons.webIQ.behaviors; | ||
|
||
// Call all behavior functions. | ||
for (var i in behaviors) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype. |
||
listeners[behaviors[i]].call(); | ||
} | ||
}); | ||
|
||
|
||
/** | ||
* Externally available. | ||
*/ | ||
groucho.addons.webIQ = { | ||
|
||
/** | ||
* How good is this user at internetting. | ||
* | ||
* @param string behavior | ||
* Optional. Empty for aggregate score, behavior type for specific, "*" for all details. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
* | ||
* @return int|object | ||
* Score value or behaviors. | ||
*/ | ||
getScore: function getScore(behavior) { | ||
var results = groucho.getActivities('webIQ'), | ||
score; | ||
|
||
// Return options. | ||
if (behavior === undefined) { | ||
score = 0; | ||
// Add it up for better or worse. | ||
for (var i in results) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype. |
||
score = score + | ||
groucho.config.addons.webIQ.behaviors[results[i].type].increment; | ||
} | ||
} | ||
else if (behavior === '*') { | ||
score = {}; | ||
// Segment by behavior type. | ||
for (i in results) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype. |
||
score[behavior] = score[behavior] + | ||
groucho.config.addons.webIQ.behaviors[behavior].increment; | ||
} | ||
} | ||
else { | ||
score = 0; | ||
// Just one behavior type. | ||
for (i in results) { | ||
if (results[i].type === behavior) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'i' used out of scope. |
||
score = score + | ||
groucho.config.addons.webIQ.behaviors[behavior].increment; | ||
} | ||
} | ||
} | ||
|
||
return score; | ||
}, | ||
|
||
}; | ||
|
||
|
||
/** | ||
* Utility: Confirm threshold before recording. | ||
* | ||
* @param string behavior | ||
* Behavior being monitored. | ||
* @param int count | ||
* Current threshold count. | ||
* | ||
* @return boolean | ||
* Results of check. | ||
*/ | ||
checkThreshold = function checkThreshold(behavior, count) { | ||
if (count >= groucho.config.addons.webIQ.behaviors[behavior].threshold) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
}; | ||
|
||
/** | ||
* Listeners are called dynamicly. | ||
*/ | ||
listeners = { | ||
|
||
/** | ||
* Listen: Delete keypresses in forms. | ||
*/ | ||
formsDelete: function formsDelete() { | ||
$('input').keypress(function (e) { | ||
if (e.which === 8 || e.which === 46) { | ||
// Allow a threshold, on-page. | ||
if (checkThreshold(this.name, groucho.config.addons.webIQ.behaviors[this.name].stash)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
groucho.createActivity('webIQ', { 'type': this.name }); | ||
} | ||
else { | ||
groucho.config.addons.webIQ.behaviors[this.name].stash++; | ||
} | ||
|
||
console.log("Executed: " + this.name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mixed double and single quotes. |
||
|
||
} | ||
}); | ||
}, | ||
|
||
/** | ||
* Listen: Use of delete in forms. | ||
*/ | ||
formsTab: function formsTab() { | ||
$('input').keypress(function (e) { | ||
if (e.which === 9) { | ||
groucho.createActivity('webIQ', { 'type': this.name }); | ||
|
||
console.log("Executed: " + this.name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mixed double and single quotes. |
||
|
||
} | ||
}); | ||
}, | ||
|
||
/** | ||
* Listen: Typing speed in forms. | ||
*/ | ||
findOnPage: function findOnPage() { | ||
$(document).keypress('f', function (e) { | ||
if (e.ctrlKey) { | ||
groucho.createActivity('webIQ', { 'type': this.name }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected '{' and instead saw 'groucho'. |
||
|
||
console.log("Executed: " + this.name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mixed double and single quotes. |
||
|
||
} | ||
}); | ||
}, | ||
|
||
/** | ||
* Listen: Double clicking, evar. | ||
*/ | ||
doubleClick: function doubleClick() { | ||
$(document).dblclick(function() { | ||
groucho.createActivity('webIQ', { 'type': this.name }); | ||
|
||
console.log("Executed: " + this.name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mixed double and single quotes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mixed double and single quotes. |
||
|
||
}); | ||
}, | ||
|
||
|
||
/** | ||
* Listen: Clicking a link to the same page. | ||
*/ | ||
repeatPage: function repeatPage() { | ||
$('a').click(function() { | ||
if (this.href === location.href) { | ||
// Allow a threshold, persistent. | ||
if (checkThreshold(this.name, groucho.getActivities('webIQ:' + this.name).length)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
groucho.createActivity('webIQ', { 'type': this.name }); | ||
} | ||
else { | ||
groucho.createActivities('webIQ:' + this.name); | ||
} | ||
|
||
console.log("Executed: " + this.name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mixed double and single quotes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mixed double and single quotes. |
||
|
||
} | ||
}); | ||
} | ||
|
||
}; | ||
|
||
})(jQuery, groucho); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'groucho' is not defined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'groucho' is not defined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'groucho' is not defined.