bootstrap-popover.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* ===========================================================
  2. * bootstrap-popover.js v2.3.2
  3. * http://getbootstrap.com/2.3.2/javascript.html#popovers
  4. * ===========================================================
  5. * Copyright 2013 Twitter, Inc.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * =========================================================== */
  19. !function ($) {
  20. "use strict"; // jshint ;_;
  21. /* POPOVER PUBLIC CLASS DEFINITION
  22. * =============================== */
  23. var Popover = function (element, options) {
  24. this.init('popover', element, options)
  25. }
  26. /* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js
  27. ========================================== */
  28. Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {
  29. constructor: Popover
  30. , setContent: function () {
  31. var $tip = this.tip()
  32. , title = this.getTitle()
  33. , content = this.getContent()
  34. $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
  35. $tip.find('.popover-content')[this.options.html ? 'html' : 'text'](content)
  36. $tip.removeClass('fade top bottom left right in')
  37. }
  38. , hasContent: function () {
  39. return this.getTitle() || this.getContent()
  40. }
  41. , getContent: function () {
  42. var content
  43. , $e = this.$element
  44. , o = this.options
  45. content = (typeof o.content == 'function' ? o.content.call($e[0]) : o.content)
  46. || $e.attr('data-content')
  47. return content
  48. }
  49. , tip: function () {
  50. if (!this.$tip) {
  51. this.$tip = $(this.options.template)
  52. }
  53. return this.$tip
  54. }
  55. , destroy: function () {
  56. this.hide().$element.off('.' + this.type).removeData(this.type)
  57. }
  58. })
  59. /* POPOVER PLUGIN DEFINITION
  60. * ======================= */
  61. var old = $.fn.popover
  62. $.fn.popover = function (option) {
  63. return this.each(function () {
  64. var $this = $(this)
  65. , data = $this.data('popover')
  66. , options = typeof option == 'object' && option
  67. if (!data) $this.data('popover', (data = new Popover(this, options)))
  68. if (typeof option == 'string') data[option]()
  69. })
  70. }
  71. $.fn.popover.Constructor = Popover
  72. $.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
  73. placement: 'right'
  74. , trigger: 'click'
  75. , content: ''
  76. , template: '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
  77. })
  78. /* POPOVER NO CONFLICT
  79. * =================== */
  80. $.fn.popover.noConflict = function () {
  81. $.fn.popover = old
  82. return this
  83. }
  84. }(window.jQuery);