1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Synacor, Inc. 5 * 6 * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: https://www.zimbra.com/license 9 * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 10 * have been added to cover use of software over a computer network and provide for limited attribution 11 * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. 12 * 13 * Software distributed under the License is distributed on an "AS IS" basis, 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. 15 * See the License for the specific language governing rights and limitations under the License. 16 * The Original Code is Zimbra Open Source Web Client. 17 * The Initial Developer of the Original Code is Zimbra, Inc. All rights to the Original Code were 18 * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015. 19 * 20 * All portions of the code are Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * 26 * @private 27 */ 28 DwtHoverMgr = function() { 29 this._hoverOverAction = new AjxTimedAction(this, this._notifyHoverOver); 30 this._hoverOutAction = new AjxTimedAction(this, this._notifyHoverOut); 31 this._ignoreHoverOverOnClickAction = new AjxTimedAction(this, this._resetIgnoreHoverOverOnClick); 32 }; 33 34 DwtHoverMgr.prototype.isDwtHoverMgr = true; 35 DwtHoverMgr.prototype.toString = function() { return "DwtHoverMgr"; }; 36 37 // Data 38 39 40 DwtHoverMgr.prototype._hoverOverDelay = 750; 41 DwtHoverMgr.prototype._hoverOverActionId = -1; 42 43 DwtHoverMgr.prototype._hoverOutDelay = 50; 44 DwtHoverMgr.prototype._ignoreHoverOverOnClickDelay = 750; 45 DwtHoverMgr.prototype._hoverOutActionId = -1; 46 47 DwtHoverMgr.prototype._isHovering = false; 48 49 // Public methods 50 51 DwtHoverMgr.prototype.setHoverObject = 52 function(object) { 53 this._hoverObject = object; 54 }; 55 56 DwtHoverMgr.prototype.getHoverObject = 57 function() { 58 return this._hoverObject; 59 }; 60 61 DwtHoverMgr.prototype.reset = 62 function() { 63 this._hoverObject = null; 64 this._hoverOverDelay = DwtHoverMgr.prototype._hoverOverDelay; 65 this._hoverOverData = null; 66 if (this._hoverOverActionId != -1) { 67 AjxTimedAction.cancelAction(this._hoverOverActionId); 68 } 69 this._hoverOverActionId = -1; 70 this._hoverOverListener = null; 71 72 this._hoverOutDelay = DwtHoverMgr.prototype._hoverOutDelay; 73 this._hoverOutData = null; 74 if (this._hoverOutActionId != -1) { 75 AjxTimedAction.cancelAction(this._hoverOutActionId); 76 this._notifyHoverOut(); 77 } 78 this._hoverOutActionId = -1; 79 this._hoverOutListener = null; 80 }; 81 82 DwtHoverMgr.prototype.isHovering = 83 function() { 84 return this._isHovering; 85 }; 86 87 DwtHoverMgr.prototype.setHoverOverDelay = 88 function(delay) { 89 this._hoverOverDelay = delay; 90 }; 91 92 DwtHoverMgr.prototype.setHoverOverData = 93 function(data) { 94 this._hoverOverData = data; 95 }; 96 97 DwtHoverMgr.prototype.setHoverOverListener = 98 function(listener) { 99 this._hoverOverListener = listener; 100 }; 101 102 DwtHoverMgr.prototype.setHoverOutDelay = 103 function(delay) { 104 this._hoverOutDelay = delay; 105 }; 106 107 DwtHoverMgr.prototype.setHoverOutData = 108 function(data) { 109 this._hoverOutData = data; 110 }; 111 112 DwtHoverMgr.prototype.setHoverOutListener = 113 function(listener) { 114 this._hoverOutListener = listener; 115 }; 116 117 118 DwtHoverMgr.prototype.ignoreHoverOverOnClick = 119 function() { 120 this._ignoreHoverOverOnClick = true; 121 AjxTimedAction.scheduleAction(this._ignoreHoverOverOnClickAction, this._ignoreHoverOverOnClickDelay); 122 }; 123 124 DwtHoverMgr.prototype._resetIgnoreHoverOverOnClick = 125 function() { 126 this._ignoreHoverOverOnClick = false; 127 }; 128 129 DwtHoverMgr.prototype.hoverOver = 130 function(x, y) { 131 132 if (this._ignoreHoverOverOnClick) { return; } 133 134 this._isHovering = true; 135 if (this._hoverOverActionId != -1) { 136 AjxTimedAction.cancelAction(this._hoverOverActionId); 137 } 138 this._hoverOverAction.args = [x, y]; 139 this._hoverOverActionId = AjxTimedAction.scheduleAction(this._hoverOverAction, this._hoverOverDelay); 140 }; 141 142 DwtHoverMgr.prototype.hoverOut = 143 function() { 144 this._isHovering = false; 145 if (this._hoverOverActionId != -1) { 146 AjxTimedAction.cancelAction(this._hoverOverActionId); 147 } 148 if (this._hoverOutActionId == -1) { 149 if (this._hoverOutDelay > 0) { 150 this._hoverOutActionId = AjxTimedAction.scheduleAction(this._hoverOutAction, this._hoverOutDelay); 151 } 152 else { 153 this._notifyHoverOut(); 154 } 155 } 156 }; 157 158 // Protected methods 159 160 DwtHoverMgr.prototype._notifyHoverOver = 161 function() { 162 this._hoverOverActionId = -1; 163 if (this._hoverOverListener != null) { 164 var x = this._hoverOverAction.args[0]; 165 var y = this._hoverOverAction.args[1]; 166 var event = new DwtHoverEvent(DwtEvent.HOVEROVER, this._hoverOverDelay, this._hoverOverData, x, y); 167 this._hoverOverListener.handleEvent(event); 168 } 169 }; 170 171 DwtHoverMgr.prototype._notifyHoverOut = 172 function() { 173 this._hoverOutActionId = -1; 174 if (this._hoverOutListener != null) { 175 var event = new DwtHoverEvent(DwtEvent.HOVEROUT, this._hoverOutDelay, this._hoverOutData); 176 this._hoverOutListener.handleEvent(event); 177 } 178 }; 179