Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
popover.js173 linesDownload Raw Back to src
1/**2 * --------------------------------------------------------------------------3 * Bootstrap (v4.6.2): popover.js4 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)5 * --------------------------------------------------------------------------6 */7 8import $ from 'jquery'9import Tooltip from './tooltip'10 11/**12 * Constants13 */14 15const NAME = 'popover'16const VERSION = '4.6.2'17const DATA_KEY = 'bs.popover'18const EVENT_KEY = `.${DATA_KEY}`19const JQUERY_NO_CONFLICT = $.fn[NAME]20const CLASS_PREFIX = 'bs-popover'21const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')22 23const CLASS_NAME_FADE = 'fade'24const CLASS_NAME_SHOW = 'show'25 26const SELECTOR_TITLE = '.popover-header'27const SELECTOR_CONTENT = '.popover-body'28 29const Default = {30  ...Tooltip.Default,31  placement: 'right',32  trigger: 'click',33  content: '',34  template: '<div class="popover" role="tooltip">' +35              '<div class="arrow"></div>' +36              '<h3 class="popover-header"></h3>' +37              '<div class="popover-body"></div></div>'38}39 40const DefaultType = {41  ...Tooltip.DefaultType,42  content: '(string|element|function)'43}44 45const Event = {46  HIDE: `hide${EVENT_KEY}`,47  HIDDEN: `hidden${EVENT_KEY}`,48  SHOW: `show${EVENT_KEY}`,49  SHOWN: `shown${EVENT_KEY}`,50  INSERTED: `inserted${EVENT_KEY}`,51  CLICK: `click${EVENT_KEY}`,52  FOCUSIN: `focusin${EVENT_KEY}`,53  FOCUSOUT: `focusout${EVENT_KEY}`,54  MOUSEENTER: `mouseenter${EVENT_KEY}`,55  MOUSELEAVE: `mouseleave${EVENT_KEY}`56}57 58/**59 * Class definition60 */61 62class Popover extends Tooltip {63  // Getters64  static get VERSION() {65    return VERSION66  }67 68  static get Default() {69    return Default70  }71 72  static get NAME() {73    return NAME74  }75 76  static get DATA_KEY() {77    return DATA_KEY78  }79 80  static get Event() {81    return Event82  }83 84  static get EVENT_KEY() {85    return EVENT_KEY86  }87 88  static get DefaultType() {89    return DefaultType90  }91 92  // Overrides93  isWithContent() {94    return this.getTitle() || this._getContent()95  }96 97  addAttachmentClass(attachment) {98    $(this.getTipElement()).addClass(`${CLASS_PREFIX}-${attachment}`)99  }100 101  getTipElement() {102    this.tip = this.tip || $(this.config.template)[0]103    return this.tip104  }105 106  setContent() {107    const $tip = $(this.getTipElement())108 109    // We use append for html objects to maintain js events110    this.setElementContent($tip.find(SELECTOR_TITLE), this.getTitle())111    let content = this._getContent()112    if (typeof content === 'function') {113      content = content.call(this.element)114    }115 116    this.setElementContent($tip.find(SELECTOR_CONTENT), content)117 118    $tip.removeClass(`${CLASS_NAME_FADE} ${CLASS_NAME_SHOW}`)119  }120 121  // Private122  _getContent() {123    return this.element.getAttribute('data-content') ||124      this.config.content125  }126 127  _cleanTipClass() {128    const $tip = $(this.getTipElement())129    const tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX)130    if (tabClass !== null && tabClass.length > 0) {131      $tip.removeClass(tabClass.join(''))132    }133  }134 135  // Static136  static _jQueryInterface(config) {137    return this.each(function () {138      let data = $(this).data(DATA_KEY)139      const _config = typeof config === 'object' ? config : null140 141      if (!data && /dispose|hide/.test(config)) {142        return143      }144 145      if (!data) {146        data = new Popover(this, _config)147        $(this).data(DATA_KEY, data)148      }149 150      if (typeof config === 'string') {151        if (typeof data[config] === 'undefined') {152          throw new TypeError(`No method named "${config}"`)153        }154 155        data[config]()156      }157    })158  }159}160 161/**162 * jQuery163 */164 165$.fn[NAME] = Popover._jQueryInterface166$.fn[NAME].Constructor = Popover167$.fn[NAME].noConflict = () => {168  $.fn[NAME] = JQUERY_NO_CONFLICT169  return Popover._jQueryInterface170}171 172export default Popover173 
codekingpro/portable-devtools · Team Ai