Permalink
Browse files

adding idle timeout

  • Loading branch information...
1 parent 2025e03 commit 613cfd600d8965b4652f04e6be05cbff70769c5e @andyjamesdavies committed May 24, 2012
Showing with 40 additions and 6 deletions.
  1. +34 −1 src/js/application.js
  2. +6 −5 src/js/views/data-view.js
View
@@ -11,7 +11,7 @@ define([
return {
initialize : function() {
- _.bindAll(this, 'renderArticle', 'renderHeadline', 'setHeight');
+ _.bindAll(this, 'renderArticle', 'renderHeadline', 'setHeight', 'idleTimeout', 'thisTimeout');
this.setHeight();
@@ -26,6 +26,7 @@ define([
window.APP_EVENTS.on('pagesLoaded', this.renderArticle);
window.APP_EVENTS.on('pagesLoaded', this.renderHeadline);
+ window.APP_EVENTS.on('tilesBuilt', this.idleTimeout);
$(window).bind('resize', this.setHeight);
},
renderArticle: function () {
@@ -69,6 +70,38 @@ define([
$('body').height($(window).innerHeight());
$('#headline, #article').css({ top: (($('body').height()/100)) + 'px'});
+ },
+ idleTimeout: function () {
+ this.timeout = null;
+ var idleTimeout = null;
+
+ this.thisTimeout();
+ var that = this;
+ $(window).bind('mousemove', function() {
+ clearInterval(that.interval);
+ clearTimeout(that.timeout);
+
+ clearTimeout(idleTimeout);
+ idleTimeout = window.setTimeout(function () {
+ that.thisTimeout();
+ }, 1000);
+ });
+ },
+ thisTimeout: function () {
+ var $tableCells = $('#tiles td');
+ var that = this;
+ this.interval = window.setInterval(function() {
+ var rand = Math.floor(Math.random()*$tableCells.length);
+
+ $($tableCells.get(rand)).trigger('click');
+
+ that.timeout = null;
+ that.timeout = window.setTimeout(function() {
+ console.log('TEST');
+ $('#headline .close').trigger('click');
+ }, 7000);
+
+ }, 10000);
}
};
}
@@ -11,7 +11,7 @@ define([
function($, _, Backbone, PagesCollection, PagesStr, pageArticlesStr, ArticleStr, SquareView) {
"use strict";
- var USE_STUB = false;
+ var USE_STUB = true;
return Backbone.View.extend({
@@ -116,12 +116,12 @@ define([
});
// how many article do we have?
- console.log(this.allArticles.length);
+// console.log(this.allArticles.length);
// what subject is each article?
- _.each(this.allArticles, function(article){
- console.log(article.get('metadata').primarySection.term.name);
- });
+// _.each(this.allArticles, function(article){
+// console.log(article.get('metadata').primarySection.term.name);
+// });
this.renderGrid();
},
renderGrid : function(){
@@ -145,6 +145,7 @@ define([
html.append(tr);
};
this.$el.append(html);
+ window.APP_EVENTS.trigger('tilesBuilt');
},
colourTiles : function() {

0 comments on commit 613cfd6

Please sign in to comment.