matrix.popover.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. $(function ()
  2. { $("#example, #example2, #example3, #example4").popover();
  3. });
  4. !function( $ ) {
  5. "use strict"
  6. var Popover = function ( element, options ) {
  7. this.init('popover', element, options)
  8. }
  9. /* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js
  10. ========================================== */
  11. Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {
  12. constructor: Popover
  13. , setContent: function () {
  14. var $tip = this.tip()
  15. , title = this.getTitle()
  16. , content = this.getContent()
  17. $tip.find('.popover-title')[ $.type(title) == 'object' ? 'append' : 'html' ](title)
  18. $tip.find('.popover-content > *')[ $.type(content) == 'object' ? 'append' : 'html' ](content)
  19. $tip.removeClass('fade top bottom left right in')
  20. }
  21. , hasContent: function () {
  22. return this.getTitle() || this.getContent()
  23. }
  24. , getContent: function () {
  25. var content
  26. , $e = this.$element
  27. , o = this.options
  28. content = $e.attr('data-content')
  29. || (typeof o.content == 'function' ? o.content.call($e[0]) : o.content)
  30. content = content.toString().replace(/(^\s*|\s*$)/, "")
  31. return content
  32. }
  33. , tip: function() {
  34. if (!this.$tip) {
  35. this.$tip = $(this.options.template)
  36. }
  37. return this.$tip
  38. }
  39. })
  40. /* POPOVER PLUGIN DEFINITION
  41. * ======================= */
  42. $.fn.popover = function ( option ) {
  43. return this.each(function () {
  44. var $this = $(this)
  45. , data = $this.data('popover')
  46. , options = typeof option == 'object' && option
  47. if (!data) $this.data('popover', (data = new Popover(this, options)))
  48. if (typeof option == 'string') data[option]()
  49. })
  50. }
  51. $.fn.popover.Constructor = Popover
  52. $.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
  53. placement: 'right'
  54. , content: ''
  55. , template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'
  56. })
  57. }( window.jQuery );