// Generated by CoffeeScript 1.12.7
/**
* Tooltip
* @namespace tooltipService
*/
'use strict';
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
app.factory('tooltipService', [
'$rootScope', '$timeout', '$document', function($rootScope, $timeout, $document) {
var BaseTooltip, LiveTooltip, Tooltip, all, delay, events, focusElements, focusEvents, list, mouseEvents, namespace;
delay = 500;
all = {};
list = [];
namespace = '.tooltip';
focusElements = {
INPUT: true,
SELECT: true,
TEXTAREA: true
};
focusEvents = {
"in": 'focusin' + namespace,
out: 'focusout' + namespace
};
mouseEvents = {
"in": 'mouseenter' + namespace,
out: 'mouseleave' + namespace
};
events = function(target) {
if (focusElements[target.prop('tagName')]) {
return focusEvents;
} else {
return mouseEvents;
}
};
BaseTooltip = (function() {
function BaseTooltip() {
if (this.id in all) {
throw new Error('duplicate Tooltip ' + this.id);
}
all[this.id] = this;
}
BaseTooltip.prototype.cancelTimeout = function() {
if (!this.timeout) {
return;
}
$timeout.cancel(this.timeout);
return this.timeout = void 0;
};
BaseTooltip.prototype.out = function() {
this.cancelTimeout();
if (this.active) {
this.active = void 0;
return list.remove(this);
}
};
BaseTooltip.prototype.remove = function() {
return delete all[this.id];
};
return BaseTooltip;
})();
Tooltip = (function(superClass) {
extend(Tooltip, superClass);
function Tooltip(message1) {
this.message = message1;
this.target = $();
Tooltip.__super__.constructor.call(this);
}
Tooltip.prototype.live = false;
Object.defineProperty(Tooltip.prototype, 'id', {
get: function() {
return this.message;
}
});
Tooltip.prototype.add = function(target) {
var ev;
ev = events(target);
target.on(ev["in"], (function(_this) {
return function(event) {
_this.cancelTimeout();
return _this.timeout = $timeout(function() {
_this.timeout = void 0;
if (!_this.active) {
list.push(_this);
}
return _this.active = event.target;
}, delay);
};
})(this));
target.on(ev.out, $rootScope.$lift((function(_this) {
return function() {
return _this.out();
};
})(this)));
this.target = this.target.add(target);
};
Tooltip.prototype.remove = function(target) {
var ev;
ev = events(target);
target.off(ev["in"] + ' ' + ev.out);
if (target.is(this.active)) {
this.out();
} else {
this.cancelTimeout();
}
this.target = this.target.not(target);
if (!this.target.length) {
Tooltip.__super__.remove.call(this);
}
};
return Tooltip;
})(BaseTooltip);
LiveTooltip = (function(superClass) {
extend(LiveTooltip, superClass);
function LiveTooltip(target1, message1) {
this.target = target1;
this.message = message1;
$document.on(mouseEvents["in"], this.target, (function(_this) {
return function(event) {
_this.cancelTimeout();
return _this.timeout = $timeout(function() {
_this.timeout = void 0;
if (document.body.contains(event.target) && $(event.target).is(_this.target)) {
if (!_this.active) {
list.push(_this);
}
return _this.active = event.target;
}
}, delay);
};
})(this));
$document.on(mouseEvents.out, this.target, $rootScope.$lift((function(_this) {
return function() {
return _this.out();
};
})(this)));
LiveTooltip.__super__.constructor.call(this);
}
LiveTooltip.prototype.live = true;
Object.defineProperty(LiveTooltip.prototype, 'id', {
get: function() {
return this.target;
}
});
return LiveTooltip;
})(BaseTooltip);
return {
list: list,
add: function(target, message) {
var cur;
if (typeof target === 'string') {
return new LiveTooltip(target, message);
} else {
cur = all[message] || new Tooltip(message);
cur.add(target);
return cur;
}
},
clear: function() {
var i, t;
for (i in all) {
t = all[i];
t.out();
}
}
};
}
]);
//# sourceMappingURL=tooltip.js.map