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