Skip to content

Commit

Permalink
Revert "Add support for mousedown event"
Browse files Browse the repository at this point in the history
This reverts commit dae14b7.
  • Loading branch information
ashwinjk committed Sep 11, 2012
1 parent dae14b7 commit cd17466
Showing 1 changed file with 174 additions and 176 deletions.
350 changes: 174 additions & 176 deletions src/gallery-idletimer/js/idletimer.js
@@ -1,176 +1,174 @@
/* /*
* Copyright (c) 2009 Nicholas C. Zakas. All rights reserved. * Copyright (c) 2009 Nicholas C. Zakas. All rights reserved.
* http://www.nczonline.net/ * http://www.nczonline.net/
*/ */


/** /**
* Idle timer * Idle timer
* @module gallery-idletimer * @module gallery-idletimer
*/ */


//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Private variables // Private variables
//------------------------------------------------------------------------- //-------------------------------------------------------------------------


var idle = false, //indicates if the user is idle var idle = false, //indicates if the user is idle
tId = -1, //timeout ID tId = -1, //timeout ID
enabled = false, //indicates if the idle timer is enabled enabled = false, //indicates if the idle timer is enabled
doc = Y.config.doc, //shortcut for document object doc = Y.config.doc, //shortcut for document object
timeout = 30000; //the amount of time (ms) before the user is considered idle timeout = 30000; //the amount of time (ms) before the user is considered idle


//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Private functions // Private functions
//------------------------------------------------------------------------- //-------------------------------------------------------------------------


/* (intentionally not documented) /* (intentionally not documented)
* Handles a user event indicating that the user isn't idle. * Handles a user event indicating that the user isn't idle.
* @param {Event} event A DOM2-normalized event object. * @param {Event} event A DOM2-normalized event object.
* @return {void} * @return {void}
*/ */
function handleUserEvent(event){ function handleUserEvent(event){


//clear any existing timeout //clear any existing timeout
clearTimeout(tId); clearTimeout(tId);


//if the idle timer is enabled //if the idle timer is enabled
if (enabled){ if (enabled){


if (/visibilitychange/.test(event.type)){ if (/visibilitychange/.test(event.type)){
toggleIdleState(doc.hidden || doc.msHidden || doc.webkitHidden || doc.mozHidden); toggleIdleState(doc.hidden || doc.msHidden || doc.webkitHidden || doc.mozHidden);
} else { } else {
//if it's idle, that means the user is no longer idle //if it's idle, that means the user is no longer idle
if (idle){ if (idle){
toggleIdleState(); toggleIdleState();
} }
} }


//set a new timeout //set a new timeout
tId = setTimeout(toggleIdleState, timeout); tId = setTimeout(toggleIdleState, timeout);
} }
} }


/* (intentionally not documented) /* (intentionally not documented)
* Toggles the idle state and fires an appropriate event. * Toggles the idle state and fires an appropriate event.
* @param {Boolean} force (Optional) the value to set idle to. * @param {Boolean} force (Optional) the value to set idle to.
* @return {void} * @return {void}
*/ */
function toggleIdleState(force){ function toggleIdleState(force){


var changed = false; var changed = false;
if (typeof force != "undefined"){ if (typeof force != "undefined"){
if (force != idle){ if (force != idle){
idle = force; idle = force;
changed = true; changed = true;
} }
} else { } else {
idle = !idle; idle = !idle;
changed = true; changed = true;
} }


if (changed){ if (changed){
//fire appropriate event //fire appropriate event
Y.IdleTimer.fire(idle ? "idle" : "active"); Y.IdleTimer.fire(idle ? "idle" : "active");
} }
} }


//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Public interface // Public interface
//------------------------------------------------------------------------- //-------------------------------------------------------------------------


/** /**
* Centralized control for determining when a user has become idle * Centralized control for determining when a user has become idle
* on the current page. * on the current page.
* @class IdleTimer * @class IdleTimer
* @static * @static
*/ */
Y.IdleTimer = { Y.IdleTimer = {


/** /**
* Indicates if the idle timer is running or not. * Indicates if the idle timer is running or not.
* @return {Boolean} True if the idle timer is running, false if not. * @return {Boolean} True if the idle timer is running, false if not.
* @method isRunning * @method isRunning
* @static * @static
*/ */
isRunning: function(){ isRunning: function(){
return enabled; return enabled;
}, },


/** /**
* Indicates if the user is idle or not. * Indicates if the user is idle or not.
* @return {Boolean} True if the user is idle, false if not. * @return {Boolean} True if the user is idle, false if not.
* @method isIdle * @method isIdle
* @static * @static
*/ */
isIdle: function(){ isIdle: function(){
return idle; return idle;
}, },


/** /**
* Starts the idle timer. This adds appropriate event handlers * Starts the idle timer. This adds appropriate event handlers
* and starts the first timeout. * and starts the first timeout.
* @param {int} newTimeout (Optional) A new value for the timeout period in ms. * @param {int} newTimeout (Optional) A new value for the timeout period in ms.
* @return {void} * @return {void}
* @method start * @method start
* @static * @static
*/ */
start: function(newTimeout){ start: function(newTimeout){


//set to enabled //set to enabled
enabled = true; enabled = true;


//set idle to false to begin with //set idle to false to begin with
idle = false; idle = false;


//assign a new timeout if necessary //assign a new timeout if necessary
if (typeof newTimeout == "number"){ if (typeof newTimeout == "number"){
timeout = newTimeout; timeout = newTimeout;
} }


//assign appropriate event handlers //assign appropriate event handlers
Y.on("mousemove", handleUserEvent, doc); Y.on("mousemove", handleUserEvent, doc);
Y.on("keydown", handleUserEvent, doc); Y.on("keydown", handleUserEvent, doc);
Y.on("mousedown", handleUserEvent, doc);

//need to add the old-fashioned way
//need to add the old-fashioned way if (doc.addEventListener) {
if (doc.addEventListener) { doc.addEventListener("msvisibilitychange", handleUserEvent, false);
doc.addEventListener("msvisibilitychange", handleUserEvent, false); doc.addEventListener("webkitvisibilitychange", handleUserEvent, false);
doc.addEventListener("webkitvisibilitychange", handleUserEvent, false); doc.addEventListener("mozvisibilitychange", handleUserEvent, false);
doc.addEventListener("mozvisibilitychange", handleUserEvent, false); }
}

//set a timeout to toggle state
//set a timeout to toggle state tId = setTimeout(toggleIdleState, timeout);
tId = setTimeout(toggleIdleState, timeout); },
},

/**
/** * Stops the idle timer. This removes appropriate event handlers
* Stops the idle timer. This removes appropriate event handlers * and cancels any pending timeouts.
* and cancels any pending timeouts. * @return {void}
* @return {void} * @method stop
* @method stop * @static
* @static */
*/ stop: function(){
stop: function(){

//set to disabled
//set to disabled enabled = false;
enabled = false;

//clear any pending timeouts
//clear any pending timeouts clearTimeout(tId);
clearTimeout(tId);

//detach the event handlers
//detach the event handlers Y.detach("mousemove", handleUserEvent, doc);
Y.detach("mousemove", handleUserEvent, doc); Y.detach("keydown", handleUserEvent, doc);
Y.detach("keydown", handleUserEvent, doc);
Y.detach("mousedown", handleUserEvent, doc); if (doc.removeEventListener) {

doc.removeEventListener("msvisibilitychange", handleUserEvent, false);
if (doc.removeEventListener) { doc.removeEventListener("webkitvisibilitychange", handleUserEvent, false);
doc.removeEventListener("msvisibilitychange", handleUserEvent, false); doc.removeEventListener("mozvisibilitychange", handleUserEvent, false);
doc.removeEventListener("webkitvisibilitychange", handleUserEvent, false); }
doc.removeEventListener("mozvisibilitychange", handleUserEvent, false);
} }


} };


}; //inherit event functionality

Y.augment(Y.IdleTimer, Y.Event.Target);
//inherit event functionality
Y.augment(Y.IdleTimer, Y.Event.Target);

0 comments on commit cd17466

Please sign in to comment.