123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- goog.provide('goog.ui.HoverCard');
- goog.provide('goog.ui.HoverCard.EventType');
- goog.provide('goog.ui.HoverCard.TriggerEvent');
- goog.require('goog.array');
- goog.require('goog.dom');
- goog.require('goog.events');
- goog.require('goog.events.Event');
- goog.require('goog.events.EventType');
- goog.require('goog.ui.AdvancedTooltip');
- goog.require('goog.ui.PopupBase');
- goog.require('goog.ui.Tooltip');
- goog.ui.HoverCard = function(
- isAnchor, opt_checkDescendants, opt_domHelper, opt_triggeringDocument) {
- goog.ui.AdvancedTooltip.call(this, null, null, opt_domHelper);
- if (goog.isFunction(isAnchor)) {
-
- this.isAnchor_ = isAnchor;
- } else {
-
- this.anchors_ = isAnchor;
- }
-
- this.checkDescendants_ = opt_checkDescendants != false;
-
- this.tempAttachedAnchors_ = [];
-
- this.document_ = opt_triggeringDocument ||
- (opt_domHelper ? opt_domHelper.getDocument() : goog.dom.getDocument());
- goog.events.listen(
- this.document_, goog.events.EventType.MOUSEOVER,
- this.handleTriggerMouseOver_, false, this);
- };
- goog.inherits(goog.ui.HoverCard, goog.ui.AdvancedTooltip);
- goog.tagUnsealableClass(goog.ui.HoverCard);
- goog.ui.HoverCard.EventType = {
- TRIGGER: 'trigger',
- CANCEL_TRIGGER: 'canceltrigger',
- BEFORE_SHOW: goog.ui.PopupBase.EventType.BEFORE_SHOW,
- SHOW: goog.ui.PopupBase.EventType.SHOW,
- BEFORE_HIDE: goog.ui.PopupBase.EventType.BEFORE_HIDE,
- HIDE: goog.ui.PopupBase.EventType.HIDE
- };
- goog.ui.HoverCard.prototype.disposeInternal = function() {
- goog.ui.HoverCard.superClass_.disposeInternal.call(this);
- goog.events.unlisten(
- this.document_, goog.events.EventType.MOUSEOVER,
- this.handleTriggerMouseOver_, false, this);
- };
- goog.ui.HoverCard.prototype.currentAnchor_;
- goog.ui.HoverCard.prototype.maxSearchSteps_;
- goog.ui.HoverCard.prototype.isAnchor_ = function(node) {
- return node.tagName in this.anchors_ &&
- !!node.getAttribute(this.anchors_[node.tagName]);
- };
- goog.ui.HoverCard.prototype.handleTriggerMouseOver_ = function(e) {
- var target = (e.target);
-
- if (!target) {
- return;
- }
- if (this.isAnchor_(target)) {
- this.setPosition(null);
- this.triggerForElement(target);
- } else if (this.checkDescendants_) {
- var trigger = goog.dom.getAncestor(
- target, goog.bind(this.isAnchor_, this), false, this.maxSearchSteps_);
- if (trigger) {
- this.setPosition(null);
- this.triggerForElement( (trigger));
- }
- }
- };
- goog.ui.HoverCard.prototype.triggerForElement = function(
- anchorElement, opt_pos, opt_data) {
- if (anchorElement == this.currentAnchor_) {
-
- this.clearHideTimer();
- return;
- }
- if (anchorElement == this.anchor) {
-
- return;
- }
-
- this.maybeCancelTrigger_();
-
- var triggerEvent = new goog.ui.HoverCard.TriggerEvent(
- goog.ui.HoverCard.EventType.TRIGGER, this, anchorElement, opt_data);
- if (!this.getElements().contains(anchorElement)) {
- this.attach(anchorElement);
- this.tempAttachedAnchors_.push(anchorElement);
- }
- this.anchor = anchorElement;
- if (!this.onTrigger(triggerEvent)) {
- this.onCancelTrigger();
- return;
- }
- var pos = opt_pos || this.getPosition();
- this.startShowTimer(
- anchorElement,
- (pos));
- };
- goog.ui.HoverCard.prototype.setCurrentAnchor_ = function(anchor) {
- if (anchor != this.currentAnchor_) {
- this.detachTempAnchor_(this.currentAnchor_);
- }
- this.currentAnchor_ = anchor;
- };
- goog.ui.HoverCard.prototype.detachTempAnchor_ = function(anchor) {
- if (anchor) {
- var pos = goog.array.indexOf(this.tempAttachedAnchors_, anchor);
- if (pos != -1) {
- this.detach(anchor);
- this.tempAttachedAnchors_.splice(pos, 1);
- }
- }
- };
- goog.ui.HoverCard.prototype.onTrigger = function(triggerEvent) {
- return this.dispatchEvent(triggerEvent);
- };
- goog.ui.HoverCard.prototype.cancelTrigger = function() {
- this.clearShowTimer();
- this.onCancelTrigger();
- };
- goog.ui.HoverCard.prototype.maybeCancelTrigger_ = function() {
- if (this.getState() == goog.ui.Tooltip.State.WAITING_TO_SHOW ||
- this.getState() == goog.ui.Tooltip.State.UPDATING) {
- this.cancelTrigger();
- }
- };
- goog.ui.HoverCard.prototype.onCancelTrigger = function() {
- var event = new goog.ui.HoverCard.TriggerEvent(
- goog.ui.HoverCard.EventType.CANCEL_TRIGGER, this, this.anchor || null);
- this.dispatchEvent(event);
- this.detachTempAnchor_(this.anchor);
- delete this.anchor;
- };
- goog.ui.HoverCard.prototype.getAnchorElement = function() {
-
-
- return (this.currentAnchor_ || this.anchor);
- };
- goog.ui.HoverCard.prototype.onHide = function() {
- goog.ui.HoverCard.superClass_.onHide.call(this);
- this.setCurrentAnchor_(null);
- };
- goog.ui.HoverCard.prototype.handleMouseOver = function(event) {
-
- var trigger = this.getAnchorFromElement(
- (event.target));
-
-
- if (trigger && trigger != this.anchor) {
- this.triggerForElement(trigger);
- return;
- }
- goog.ui.HoverCard.superClass_.handleMouseOver.call(this, event);
- };
- goog.ui.HoverCard.prototype.handleMouseOutAndBlur = function(event) {
-
- var anchor = this.anchor;
- var state = this.getState();
- goog.ui.HoverCard.superClass_.handleMouseOutAndBlur.call(this, event);
- if (state != this.getState() &&
- (state == goog.ui.Tooltip.State.WAITING_TO_SHOW ||
- state == goog.ui.Tooltip.State.UPDATING)) {
-
-
-
- this.anchor = anchor;
- this.onCancelTrigger();
- }
- };
- goog.ui.HoverCard.prototype.maybeShow = function(el, opt_pos) {
- goog.ui.HoverCard.superClass_.maybeShow.call(this, el, opt_pos);
- if (!this.isVisible()) {
- this.cancelTrigger();
- } else {
- this.setCurrentAnchor_(el);
- }
- };
- goog.ui.HoverCard.prototype.setMaxSearchSteps = function(maxSearchSteps) {
- if (!maxSearchSteps) {
- this.checkDescendants_ = false;
- } else if (this.checkDescendants_) {
- this.maxSearchSteps_ = maxSearchSteps;
- }
- };
- goog.ui.HoverCard.TriggerEvent = function(type, target, anchor, opt_data) {
- goog.events.Event.call(this, type, target);
-
- this.anchor = anchor;
-
- this.data = opt_data;
- };
- goog.inherits(goog.ui.HoverCard.TriggerEvent, goog.events.Event);
|