diff --git a/apps/common/main/lib/component/MenuItem.js b/apps/common/main/lib/component/MenuItem.js index 6b81c41f4..7b49b77e2 100644 --- a/apps/common/main/lib/component/MenuItem.js +++ b/apps/common/main/lib/component/MenuItem.js @@ -194,7 +194,22 @@ define([ el.attr('data-toggle', 'tooltip'); el.tooltip({ title : me.options.hint, - placement : me.options.hintAnchor||'cursor' + placement : me.options.hintAnchor||function(tip, element) { + var pos = this.getPosition(), + actualWidth = tip.offsetWidth, + actualHeight = tip.offsetHeight, + innerWidth = Common.Utils.innerWidth(), + innerHeight = Common.Utils.innerHeight(); + var top = pos.top, + left = pos.left + pos.width + 2; + if (top + actualHeight > innerHeight) { + top = innerHeight - actualHeight - 2; + } + if (left + actualWidth > innerWidth) { + left = pos.left - actualWidth - 2; + } + $(tip).offset({top: top,left: left}).addClass('in'); + } }); } diff --git a/apps/common/main/lib/util/Tip.js b/apps/common/main/lib/util/Tip.js index 1ef303d66..b0521586d 100644 --- a/apps/common/main/lib/util/Tip.js +++ b/apps/common/main/lib/util/Tip.js @@ -127,15 +127,12 @@ if (this.hasContent() && this.enabled && !this.dontShow) { if (!this.$element.is(":visible") && this.$element.closest('[role=menu]').length>0) return; var $tip = this.tip(); - var placement = typeof this.options.placement === 'function' ? - this.options.placement.call(this, $tip[0], this.$element[0]) : this.options.placement; if (this.options.arrow === false) $tip.addClass('arrow-free'); if (this.options.cls) $tip.addClass(this.options.cls); - - var placementEx = /^([a-zA-Z]+)-?([a-zA-Z]*)$/.exec(placement); - if (!at && !placementEx[2].length) { + var placementEx = (typeof this.options.placement !== 'function') ? /^([a-zA-Z]+)-?([a-zA-Z]*)$/.exec(this.options.placement) : null; + if (!at && placementEx && !placementEx[2].length) { _superclass.prototype.show.apply(this, arguments); } else { var e = $.Event('show.bs.tooltip'); @@ -152,7 +149,9 @@ this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element); - if (typeof at == 'object') { + if (typeof this.options.placement === 'function') { + this.options.placement.call(this, $tip[0], this.$element[0]); + } else if (typeof at == 'object') { var tp = {top: at[1] + 15, left: at[0] + 18}, innerWidth = Common.Utils.innerWidth(), innerHeight = Common.Utils.innerHeight();