/*
* Copyright 2012 Yahoo! Inc. All rights reserved.
* Licensed under the BSD License.
*
* Portions Copyright 2012 Jens Elkner.
*/
// The tooltip in the YUI gallery makes nice effects but is not flexible enough.
// So we use a slightly modified version of the YUI examples.
/* Tooltip constructor */
};
/*
* Required NAME static field, used to identify the Widget class and used
* as an event prefix, to generate class names etc. (set to the class name
* in camel case).
*/
/* Static constants */
/* Default Tooltip Attributes */
/*
* The tooltip content. This can either be a String, Node, or a simple
* map of id-to-values, designed to be used when a single tooltip is
* mapped to multiple trigger elements.
*/
content : {
value : null
},
/*
* The set of nodes to bind to the tooltip instance. Can be a string,
* or a node instance.
*/
triggerNodes : {
value : null,
}
return val;
}
},
/*
* The delegate node to which event listeners should be attached. This
* node should be an ancestor of all trigger nodes bound to the
* instance. By default the document is used.
*/
delegate : {
value : null,
}
},
/*
* The time to wait, after the mouse enters the trigger node, to display
* the tooltip
*/
showDelay : {
value : 250
},
/*
* The time to wait, after the mouse leaves the trigger node, to hide
* the tooltip
*/
hideDelay : {
value : 10
},
/*
* The time to wait, after the tooltip is first displayed for a trigger
* node, to hide it, if the mouse has not left the trigger node
*/
autoHideDelay : {
value : 2000
},
/*
* Override the default visibility set by the widget base class
*/
visible : {
value : false
},
/*
* Override the default XY value set by the widget base class, to
* position the tooltip offscreen
*/
xy : {
}
};
/* Extend the base Widget class */
/*
* Initialization Code: Sets up privately used state properties, and
* publishes the events Tooltip introduces
*/
initializer : function(config) {
// Currently bound trigger node information
this._currTrigger = {
node : null,
title : null,
};
// Event handles - mouse over is set on the delegate element,
// mousemove and mouseout are set on the trigger node
this._eventHandles = {
delegate : null,
trigger : {
mouseMove : null,
mouseOut : null
}
};
this._timers = {
show : null,
hide : null
};
// Publish events introduced by Tooltip. Note the triggerEnter event
// is preventable, with the default behavior defined in the
// _defTriggerEnterFn method
this.publish('triggerEnter', {
defaultFn : this._defTriggerEnterFn,
preventable : true
});
this.publish('triggerLeave', {
preventable : false
});
// we assume, horizontal scrollbar has ~ same height as vert. and
// doesn't change
},
/*
* Destruction Code: Clears event handles, timers, and current trigger
* information
*/
destructor : function() {
this._clearCurrentTrigger();
this._clearTimers();
this._clearHandles();
},
/*
* bindUI is used to bind attribute change and dom event listeners
*/
bindUI : function() {
this._bindDelegate();
},
/*
* syncUI is used to update the rendered DOM, based on the current
* Tooltip state
*/
syncUI : function() {
},
/*
* Helper method to extract the content for the tooltip of the given
* node, based on (in order of precedence):
*
* a). The given node's 'content' attribute value, if set:
* 0) If its value denotes a function, the result of executing as
* function(node, this), whereby this is the Tooltip instance
* itself.
* 1) If the value is a map, the maps value for the key equal to
* the node's Id.
* 2) If the value is a String or Node, the value itself.
* 3) otherwise, fallback to b)
* b) The value of the node's 'title' attribute.
*
* @return either an innerHTML acceptable String or a Node
*/
getTooltipContent : function(node) {
if (content) {
content = null;
}
}
if (!content) {
}
return content;
},
/*
* Public method, which can be used by triggerEvent event listeners to
* set the content of the tooltip for the current trigger node. This
* implementation uses {#getTooltipContent} to extract the content to
* show.
*/
setTriggerContent : function(node) {
if (content) {
}
}
},
/*
* Gets the closest ancestor of the given node, which is a tooltip
* trigger node
*/
getParentTrigger : function(node) {
var cn = this._triggerClassName;
? node
},
/*
* Default attribute change listener for the triggerNodes attribute
*/
_afterSetNodes : function(e) {
this._uiSetNodes(e.newVal);
},
/*
* Default attribute change listener for the delegate attribute
*/
_afterSetDelegate : function(e) {
this._bindDelegate(e.newVal);
},
/*
* Updates the rendered DOM to reflect the set of trigger nodes passed in
*/
_uiSetNodes : function(nodes) {
if (this._triggerNodes) {
}
if (nodes) {
this._triggerNodes = nodes;
}
},
/*
* Attaches the default mouseover DOM listener to the current delegate node
*/
_bindDelegate : function() {
var eventHandles = this._eventHandles;
if (eventHandles.delegate) {
eventHandles.delegate = null;
}
},
/*
* Default mouse over DOM event listener.
*
* Delegates to the _enterTrigger method, if the mouseover enters a
* trigger node.
*/
_onDelegateMouseOver : function(e) {
{
}
},
/*
* Default mouse out DOM event listener
*
* Delegates to _leaveTrigger if the mouseout leaves the current trigger
* node
*/
_onNodeMouseOut : function(e) {
var to = e.relatedTarget;
var trigger = e.currentTarget;
this._leaveTrigger(trigger);
}
},
/*
* Default mouse move DOM event listener
*/
_onNodeMouseMove : function(e) {
},
/*
* Default handler invoked when the mouse enters a trigger node. Set the
* content of the tooltip box and fires the triggerEnter event, which
* inturn notifies all listeners. Listeners may prevent the tooltip
* from being displayed.
*/
_enterTrigger : function(node, x, y) {
this._setCurrentTrigger(node, x, y);
this.fire('triggerEnter', {
pageX : x,
pageY : y
});
},
/*
* Default handler for the triggerEvent event, which will setup the
* timer to display the tooltip, if the default handler has not been
* prevented.
*/
_defTriggerEnterFn : function(e) {
if (!this.get('disabled')) {
this._clearTimers();
}
},
/*
* Default handler invoked when the mouse leaves the current trigger
* node. Fires the triggerLeave event and sets up the hide timer
*/
_leaveTrigger : function(node) {
this.fire('triggerLeave');
this._clearCurrentTrigger();
this._clearTimers();
},
/*
* Default handler invoked for mousemove events on the trigger node.
* Stores the current mouse x, y positions
*/
_overTrigger : function(x, y) {
this._currTrigger.mouseX = x;
this._currTrigger.mouseY = y;
},
/*
* Shows the tooltip, after moving it to the current mouse position.
*/
_showTooltip : function(node) {
if (y > max) {
y = max;
}
if (x > max) {
x = max;
}
this.move(x, y);
this.show();
this._clearTimers();
},
/*
* Hides the tooltip, after clearing existing timers.
*/
_hideTooltip : function() {
this._clearTimers();
this.hide();
},
/*
* Set the currently bound trigger node information, clearing out the
*/
_setCurrentTrigger : function(node, x, y) {
= this._eventHandles.trigger;
this.setTriggerContent(node);
if (title) {
}
currTrigger.mouseX = x;
currTrigger.mouseY = y;
},
/*
* Clear out the current trigger state, restoring the title attribute
* on the trigger node, if it was originally set.
*/
_clearCurrentTrigger : function() {
this._eventHandles.trigger;
if (currTrigger.node) {
currTrigger.node = null;
triggerHandles.mouseMove = null;
triggerHandles.mouseOut = null;
if (title) {
}
}
},
/*
*/
_clearTimers : function() {
}
}
},
/*
* Detach any stored event handles
*/
_clearHandles : function() {
var eventHandles = this._eventHandles;
if (eventHandles.delegate) {
}
}
}
}
});
// dynamic:false = Modify the existing Tooltip class
[ Y.WidgetPosition, Y.WidgetStack ],
{ dynamic : false } );
// vim: set filetype=javascript ts=4