zoukankan      html  css  js  c++  java
  • Bootstrap popover源码分析

    /* ========================================================================
     * Bootstrap: popover.js v3.3.7
     * http://getbootstrap.com/javascript/#popovers
     * ========================================================================
     * Copyright 2011-2016 Twitter, Inc.
     * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
     * ======================================================================== */
    
    
    +function ($) {
      'use strict';
    
      // POPOVER PUBLIC CLASS DEFINITION
      // ===============================
    
      var Popover = function (element, options) {
        this.init('popover', element, options)
      }
    
      if (!$.fn.tooltip) throw new Error('Popover requires tooltip.js')
    
      Popover.VERSION  = '3.3.7'
    
      Popover.DEFAULTS = $.extend({}, $.fn.tooltip.Constructor.DEFAULTS, {//把默认trigger条件改为click,默认模板也改成现在需要的。
        placement: 'right',
        trigger: 'click',
        content: '',
        template: '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
      })
    
    
      // NOTE: POPOVER EXTENDS tooltip.js
      // ================================
    
      Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype)//把原型里的方法都继承过来,
    
      Popover.prototype.constructor = Popover
    
      Popover.prototype.getDefaults = function () {//因为继承的tootle里面还是原来的,现在改成Popover.DEFAULTS
        return Popover.DEFAULTS
      }
    
      Popover.prototype.setContent = function () {//这个是把模板填充数据的方法,当然需要修改成Popover独有的
        var $tip    = this.tip()
        var title   = this.getTitle()
        var content = this.getContent()
    
        $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
        $tip.find('.popover-content').children().detach().end()[ // we use append for html objects to maintain js events
          this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text'
        ](content)
    
        $tip.removeClass('fade top bottom left right in')
    
        // IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do
        // this manually by checking the contents.
        if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide()
      }
    
      Popover.prototype.hasContent = function () {//一句话,把你的换成我的
        return this.getTitle() || this.getContent()
      }
    
      Popover.prototype.getContent = function () {
        var $e = this.$element
        var o  = this.options
    
        return $e.attr('data-content')
          || (typeof o.content == 'function' ?
                o.content.call($e[0]) :
                o.content)
      }
    
      Popover.prototype.arrow = function () {
        return (this.$arrow = this.$arrow || this.tip().find('.arrow'))
      }
    
    
      // POPOVER PLUGIN DEFINITION
      // =========================
    
      function Plugin(option) {
        return this.each(function () {
          var $this   = $(this)
          var data    = $this.data('bs.popover')
          var options = typeof option == 'object' && option
    
          if (!data && /destroy|hide/.test(option)) return
          if (!data) $this.data('bs.popover', (data = new Popover(this, options)))
          if (typeof option == 'string') data[option]()
        })
      }
    
      var old = $.fn.popover
    
      $.fn.popover             = Plugin
      $.fn.popover.Constructor = Popover
    
    
      // POPOVER NO CONFLICT
      // ===================
    
      $.fn.popover.noConflict = function () {
        $.fn.popover = old
        return this
      }
    
    }(jQuery);
  • 相关阅读:
    对 String 的几个错误认识 X
    用C# 自定义Window7的JumpList(跳转列表) X
    IPv6无状态自动配置功能配合DHCPv6无状态配置功能 实现IPv6自动分配
    H3C S7500E IPV6白皮书
    静默方式执行chkdsk命令
    IPv6基本知识(转载)
    解决win7官方主题themepack无法安装的问题
    英保通等PXE网刻软件的使用
    通过命令提示符修改windows默认打印机
    OFFICE2010出现两个激活信息的处理办法。
  • 原文地址:https://www.cnblogs.com/xiaobie123/p/5997617.html
Copyright © 2011-2022 走看看