./lib/helios/frontend/javascripts/vendor/foundation/foundation.tooltips.js in helios-0.3.0 vs ./lib/helios/frontend/javascripts/vendor/foundation/foundation.tooltips.js in helios-0.4.0
- old
+ new
@@ -4,41 +4,48 @@
'use strict';
Foundation.libs.tooltips = {
name: 'tooltips',
- version : '4.0.2',
+ version : '4.2.2',
settings : {
selector : '.has-tip',
additionalInheritableClasses : [],
tooltipClass : '.tooltip',
+ appendTo: 'body',
+ 'disable-for-touch': false,
tipTemplate : function (selector, content) {
return '<span data-selector="' + selector + '" class="'
+ Foundation.libs.tooltips.settings.tooltipClass.substring(1)
+ '">' + content + '<span class="nub"></span></span>';
}
},
cache : {},
init : function (scope, method, options) {
+ Foundation.inherit(this, 'data_options');
var self = this;
- this.scope = scope || this.scope;
if (typeof method === 'object') {
$.extend(true, this.settings, method);
+ } else if (typeof options !== 'undefined') {
+ $.extend(true, this.settings, options);
}
- if (typeof method != 'string') {
+ if (typeof method !== 'string') {
if (Modernizr.touch) {
$(this.scope)
.on('click.fndtn.tooltip touchstart.fndtn.tooltip touchend.fndtn.tooltip',
'[data-tooltip]', function (e) {
- e.preventDefault();
- $(self.settings.tooltipClass).hide();
- self.showOrCreateTip($(this));
+ var settings = $.extend({}, self.settings, self.data_options($(this)));
+ if (!settings['disable-for-touch']) {
+ e.preventDefault();
+ $(settings.tooltipClass).hide();
+ self.showOrCreateTip($(this));
+ }
})
.on('click.fndtn.tooltip touchstart.fndtn.tooltip touchend.fndtn.tooltip',
this.settings.tooltipClass, function (e) {
e.preventDefault();
$(this).fadeOut(150);
@@ -47,11 +54,11 @@
$(this.scope)
.on('mouseenter.fndtn.tooltip mouseleave.fndtn.tooltip',
'[data-tooltip]', function (e) {
var $this = $(this);
- if (e.type === 'mouseover' || e.type === 'mouseenter') {
+ if (/enter|over/i.test(e.type)) {
self.showOrCreateTip($this);
} else if (e.type === 'mouseout' || e.type === 'mouseleave') {
self.hide($this);
}
});
@@ -77,11 +84,11 @@
getTip : function ($target) {
var selector = this.selector($target),
tip = null;
if (selector) {
- tip = $('span[data-selector=' + selector + ']' + this.settings.tooltipClass);
+ tip = $('span[data-selector="' + selector + '"]' + this.settings.tooltipClass);
}
return (typeof tip === 'object') ? tip : false;
},
@@ -96,14 +103,14 @@
return (id && id.length > 0) ? id : dataSelector;
},
create : function ($target) {
- var $tip = $(this.settings.tipTemplate(this.selector($target), $('<div>').html($target.attr('title')).html())),
+ var $tip = $(this.settings.tipTemplate(this.selector($target), $('<div></div>').html($target.attr('title')).html())),
classes = this.inheritable_classes($target);
- $tip.addClass(classes).appendTo('body');
+ $tip.addClass(classes).appendTo(this.settings.appendTo);
if (Modernizr.touch) {
$tip.append('<span class="tap-to-close">tap to close </span>');
}
$target.removeAttr('title').attr('title','');
this.show($target);
@@ -134,14 +141,18 @@
if ($(window).width() < 767) {
objPos(tip, (target.offset().top + this.outerHeight(target) + 10), 'auto', 'auto', 12.5, $(this.scope).width());
tip.addClass('tip-override');
objPos(nub, -nubHeight, 'auto', 'auto', target.offset().left);
} else {
- objPos(tip, (target.offset().top + this.outerHeight(target) + 10), 'auto', 'auto', target.offset().left, width);
+ var left = target.offset().left;
+ if (Foundation.rtl) {
+ left = target.offset().left + target.offset().width - this.outerWidth(tip);
+ }
+ objPos(tip, (target.offset().top + this.outerHeight(target) + 10), 'auto', 'auto', left, width);
tip.removeClass('tip-override');
if (classes && classes.indexOf('tip-top') > -1) {
- objPos(tip, (target.offset().top - this.outerHeight(tip)), 'auto', 'auto', target.offset().left, width)
+ objPos(tip, (target.offset().top - this.outerHeight(tip)), 'auto', 'auto', left, width)
.removeClass('tip-override');
} else if (classes && classes.indexOf('tip-left') > -1) {
objPos(tip, (target.offset().top + (this.outerHeight(target) / 2) - nubHeight*2.5), 'auto', 'auto', (target.offset().left - this.outerWidth(tip) - nubHeight), width)
.removeClass('tip-override');
} else if (classes && classes.indexOf('tip-right') > -1) {
@@ -188,8 +199,10 @@
off : function () {
$(this.scope).off('.fndtn.tooltip');
$(this.settings.tooltipClass).each(function (i) {
$('[data-tooltip]').get(i).attr('title', $(this).text());
}).remove();
- }
+ },
+
+ reflow : function () {}
};
}(Foundation.zj, this, this.document));