25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bootstrap-popover.js 2.6 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* ===========================================================
  2. * bootstrap-popover.js v1.4.0
  3. * http://twitter.github.com/bootstrap/javascript.html#popover
  4. * ===========================================================
  5. * Copyright 2011 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"
  21. var Popover = function ( element, options ) {
  22. this.$element = $(element)
  23. this.options = options
  24. this.enabled = true
  25. this.fixTitle()
  26. }
  27. /* NOTE: POPOVER EXTENDS BOOTSTRAP-TWIPSY.js
  28. ========================================= */
  29. Popover.prototype = $.extend({}, $.fn.twipsy.Twipsy.prototype, {
  30. setContent: function () {
  31. var $tip = this.tip()
  32. $tip.find('.title')[this.options.html ? 'html' : 'text'](this.getTitle())
  33. $tip.find('.content p')[this.options.html ? 'html' : 'text'](this.getContent())
  34. $tip[0].className = 'popover'
  35. }
  36. , hasContent: function () {
  37. return this.getTitle() || this.getContent()
  38. }
  39. , getContent: function () {
  40. var content
  41. , $e = this.$element
  42. , o = this.options
  43. if (typeof this.options.content == 'string') {
  44. content = this.options.content
  45. } else if (typeof this.options.content == 'function') {
  46. content = this.options.content.call(this.$element[0])
  47. }
  48. return content
  49. }
  50. , tip: function() {
  51. if (!this.$tip) {
  52. this.$tip = $('<div class="popover" />')
  53. .html(this.options.template)
  54. }
  55. return this.$tip
  56. }
  57. })
  58. /* POPOVER PLUGIN DEFINITION
  59. * ======================= */
  60. $.fn.popover = function (options) {
  61. if (typeof options == 'object') options = $.extend({}, $.fn.popover.defaults, options)
  62. $.fn.twipsy.initWith.call(this, options, Popover, 'popover')
  63. return this
  64. }
  65. $.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, {
  66. placement: 'right'
  67. , template: '<div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div>'
  68. })
  69. }( window.jQuery || window.ender );