diff options
Diffstat (limited to 'src/services.js')
| -rw-r--r-- | src/services.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/services.js b/src/services.js index 2532d3d3..173cee98 100644 --- a/src/services.js +++ b/src/services.js @@ -44,3 +44,46 @@ angularService("$location", function(browser){ return location; }, {inject: ['$browser']}); +angularService("$hover", function(browser) { + var tooltip, self = this, error, width = 300, arrowWidth = 10; + browser.hover(function(element, show){ + if (show && (error = element.attr('ng-error'))) { + if (!tooltip) { + tooltip = { + callout: jqLite('<div id="ng-callout"></div>'), + arrow: jqLite('<div></div>'), + title: jqLite('<div class="ng-title"></div>'), + content: jqLite('<div class="ng-content"></div>') + }; + tooltip.callout.append(tooltip.arrow); + tooltip.callout.append(tooltip.title); + tooltip.callout.append(tooltip.content); + self.$browser.body.append(tooltip.callout); + } + var docRect = self.$browser.body[0].getBoundingClientRect(), + elementRect = element[0].getBoundingClientRect(), + leftSpace = docRect.right - elementRect.right - arrowWidth; + tooltip.title.text(element.hasClass("ng-exception") ? "EXCEPTION:" : "Validation error..."); + tooltip.content.text(error); + if (leftSpace < width) { + tooltip.arrow.addClass('ng-arrow-right'); + tooltip.arrow.css({left: (width + 1)+'px'}); + tooltip.callout.css({ + left: (elementRect.left - arrowWidth - width - 4) + "px", + top: (elementRect.top - 3) + "px", + width: width + "px" + }); + } else { + tooltip.arrow.addClass('ng-arrow-left'); + tooltip.callout.css({ + left: (elementRect.right + arrowWidth) + "px", + top: (elementRect.top - 3) + "px", + width: width + "px" + }); + } + } else if (tooltip) { + tooltip.callout.remove(); + tooltip = null; + } + }); +}, {inject:['$browser']}); |
