Skip to content

Commit

Permalink
fields now passed in as objects
Browse files Browse the repository at this point in the history
  • Loading branch information
robflaherty committed Mar 10, 2014
1 parent 441e8fa commit 051839a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
21 changes: 11 additions & 10 deletions screentime.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
var started = false;
var universalGA, classicGA;

if (!options.fields.length) {
return;
}

if (options.googleAnalytics) {

if (typeof ga === "function") {
Expand Down Expand Up @@ -100,9 +104,10 @@
* Constructors
*/

function Field(selector) {
this.selector = selector;
$elem = this.$elem = $(selector);
function Field(elem) {
this.selector = elem.selector;
$elem = this.$elem = $(elem.selector);
this.name = elem.name;

this.top = $elem.offset().top;
this.height = $elem.height();
Expand Down Expand Up @@ -161,7 +166,6 @@
log[key] += 1;
counter[key] += 1;
}

});

}
Expand All @@ -170,9 +174,6 @@

var data = {};

console.log(log);
console.log(counter);

$.each(counter, function(key, val) {
if (val > 0) {
data[key] = val;
Expand Down Expand Up @@ -220,9 +221,9 @@
$.each(options.fields, function(index, elem) {
if ($(elem).length) {
var field = new Field(elem);
cache[field.selector] = field;
counter[field.selector] = 0;
log[field.selector] = 0;
cache[field.name] = field;
counter[field.name] = 0;
log[field.name] = 0;
}
});

Expand Down
12 changes: 11 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ <h1>Screentime Test Page</h1>
<script src="../screentime.js"></script>
<script>
$.screentime({
fields: ['#top', '#middle', '#bottom'],
fields: [
{ selector: '#top',
name: 'Top'
},
{ selector: '#middle',
name: 'Middle'
},
{ selector: '#bottom',
name: 'Bottom'
}
],
googleAnalytics: false,
callback: function(data) {
console.log(data);
Expand Down

0 comments on commit 051839a

Please sign in to comment.