cy-element-ui 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -13
- package/lib/alert.js +211 -203
- package/lib/aside.js +29 -29
- package/lib/autocomplete.js +4615 -483
- package/lib/avatar.js +152 -126
- package/lib/backtop.js +117 -125
- package/lib/badge.js +128 -134
- package/lib/breadcrumb-item.js +146 -122
- package/lib/breadcrumb.js +97 -96
- package/lib/button-group.js +68 -65
- package/lib/button.js +67 -87
- package/lib/calendar.js +2475 -603
- package/lib/card.js +101 -100
- package/lib/carousel-item.js +854 -210
- package/lib/carousel.js +575 -408
- package/lib/cascader-panel.js +3546 -1153
- package/lib/cascader.js +7376 -970
- package/lib/checkbox-button.js +337 -290
- package/lib/checkbox-group.js +176 -105
- package/lib/checkbox.js +240 -220
- package/lib/col.js +113 -68
- package/lib/collapse-item.js +1228 -225
- package/lib/collapse.js +163 -123
- package/lib/color-picker.js +5223 -1251
- package/lib/container.js +98 -88
- package/lib/date-picker.js +8396 -3945
- package/lib/descriptions-item.js +53 -32
- package/lib/descriptions.js +697 -334
- package/lib/dialog.js +1725 -247
- package/lib/directives/mousewheel.js +14 -20
- package/lib/directives/repeat-click.js +27 -30
- package/lib/divider.js +38 -45
- package/lib/drawer.js +1032 -238
- package/lib/dropdown-item.js +159 -111
- package/lib/dropdown-menu.js +2445 -117
- package/lib/dropdown.js +1675 -366
- package/lib/element-ui.common.js +49110 -39985
- package/lib/empty.js +1084 -203
- package/lib/fileUpload.js +3900 -0
- package/lib/footer.js +29 -29
- package/lib/form-item.js +1236 -467
- package/lib/form.js +326 -258
- package/lib/header.js +80 -80
- package/lib/icon.js +71 -68
- package/lib/image.js +2389 -743
- package/lib/index.js +1 -1
- package/lib/infinite-scroll.js +814 -150
- package/lib/input-number.js +2181 -444
- package/lib/input.js +1197 -517
- package/lib/link.js +117 -135
- package/lib/loading.js +1130 -363
- package/lib/locale/format.js +38 -49
- package/lib/locale/index.js +38 -52
- package/lib/locale/lang/af-ZA.js +130 -123
- package/lib/locale/lang/ar.js +123 -122
- package/lib/locale/lang/az.js +122 -121
- package/lib/locale/lang/bg.js +133 -123
- package/lib/locale/lang/bn.js +121 -121
- package/lib/locale/lang/ca.js +123 -122
- package/lib/locale/lang/cs-CZ.js +127 -125
- package/lib/locale/lang/da.js +124 -122
- package/lib/locale/lang/de.js +126 -124
- package/lib/locale/lang/ee.js +125 -123
- package/lib/locale/lang/el.js +125 -123
- package/lib/locale/lang/en.js +127 -123
- package/lib/locale/lang/eo.js +125 -123
- package/lib/locale/lang/es.js +123 -122
- package/lib/locale/lang/eu.js +128 -123
- package/lib/locale/lang/fa.js +125 -123
- package/lib/locale/lang/fi.js +125 -123
- package/lib/locale/lang/fr.js +125 -122
- package/lib/locale/lang/he.js +130 -123
- package/lib/locale/lang/hr.js +128 -123
- package/lib/locale/lang/hu.js +124 -122
- package/lib/locale/lang/hy-AM.js +125 -123
- package/lib/locale/lang/id.js +124 -123
- package/lib/locale/lang/is.js +124 -123
- package/lib/locale/lang/it.js +123 -122
- package/lib/locale/lang/ja.js +125 -123
- package/lib/locale/lang/kg.js +125 -123
- package/lib/locale/lang/km.js +124 -123
- package/lib/locale/lang/ko.js +125 -123
- package/lib/locale/lang/ku.js +125 -123
- package/lib/locale/lang/kz.js +125 -123
- package/lib/locale/lang/lo-LA.js +121 -121
- package/lib/locale/lang/lt.js +125 -123
- package/lib/locale/lang/lv.js +125 -123
- package/lib/locale/lang/mn.js +125 -123
- package/lib/locale/lang/ms.js +123 -122
- package/lib/locale/lang/nb-NO.js +123 -122
- package/lib/locale/lang/nl.js +125 -123
- package/lib/locale/lang/pl.js +125 -123
- package/lib/locale/lang/pt-br.js +124 -123
- package/lib/locale/lang/pt.js +133 -123
- package/lib/locale/lang/ro.js +125 -123
- package/lib/locale/lang/ru-RU.js +124 -123
- package/lib/locale/lang/si.js +127 -123
- package/lib/locale/lang/sk.js +126 -125
- package/lib/locale/lang/sl.js +125 -123
- package/lib/locale/lang/sr-Latn.js +124 -123
- package/lib/locale/lang/sr.js +128 -123
- package/lib/locale/lang/sv-SE.js +128 -123
- package/lib/locale/lang/sw.js +127 -123
- package/lib/locale/lang/ta.js +130 -122
- package/lib/locale/lang/th.js +127 -123
- package/lib/locale/lang/tk.js +129 -123
- package/lib/locale/lang/tr-TR.js +125 -123
- package/lib/locale/lang/ua.js +124 -123
- package/lib/locale/lang/ug-CN.js +124 -123
- package/lib/locale/lang/uz-UZ.js +124 -123
- package/lib/locale/lang/vi.js +124 -123
- package/lib/locale/lang/zh-CN.js +124 -123
- package/lib/locale/lang/zh-TW.js +128 -123
- package/lib/main.js +23 -21
- package/lib/menu-item-group.js +105 -111
- package/lib/menu-item.js +3558 -253
- package/lib/menu.js +1680 -528
- package/lib/message-box.js +3427 -684
- package/lib/message.js +1677 -229
- package/lib/mixins/emitter.js +28 -30
- package/lib/mixins/focus.js +10 -11
- package/lib/mixins/locale.js +12 -14
- package/lib/mixins/migrating.js +38 -45
- package/lib/notification.js +1707 -269
- package/lib/option-group.js +190 -139
- package/lib/option.js +949 -196
- package/lib/page-header.js +964 -42
- package/lib/pagination.js +6947 -641
- package/lib/popconfirm.js +3951 -223
- package/lib/popover.js +3247 -369
- package/lib/progress.js +254 -244
- package/lib/radio-button.js +259 -226
- package/lib/radio-group.js +249 -186
- package/lib/radio.js +263 -253
- package/lib/rate.js +1399 -420
- package/lib/result.js +183 -227
- package/lib/row.js +58 -41
- package/lib/scrollbar.js +1331 -278
- package/lib/select.js +5816 -1428
- package/lib/skeleton-item.js +133 -145
- package/lib/skeleton.js +82 -91
- package/lib/slider.js +5157 -702
- package/lib/spinner.js +113 -101
- package/lib/statistic.js +10205 -254
- package/lib/step.js +274 -311
- package/lib/steps.js +854 -117
- package/lib/subTitle.js +292 -0
- package/lib/submenu.js +2867 -429
- package/lib/switch.js +1051 -291
- package/lib/tab-pane.js +125 -135
- package/lib/tabDialog.js +2658 -0
- package/lib/table-column.js +1975 -751
- package/lib/table.js +8019 -3979
- package/lib/tabs.js +1455 -605
- package/lib/tag.js +73 -68
- package/lib/theme-chalk/src/index.scss +3 -0
- package/lib/time-picker.js +6821 -1944
- package/lib/time-select.js +6297 -1186
- package/lib/timeline-item.js +43 -84
- package/lib/timeline.js +43 -39
- package/lib/tooltip.js +3185 -287
- package/lib/transfer.js +2943 -625
- package/lib/transitions/collapse-transition.js +69 -87
- package/lib/tree.js +3312 -1791
- package/lib/treeSelect.js +4436 -0
- package/lib/umd/locale/af-ZA.js +145 -138
- package/lib/umd/locale/ar.js +138 -137
- package/lib/umd/locale/az.js +139 -137
- package/lib/umd/locale/bg.js +148 -138
- package/lib/umd/locale/bn.js +138 -137
- package/lib/umd/locale/ca.js +138 -137
- package/lib/umd/locale/cs-CZ.js +142 -140
- package/lib/umd/locale/da.js +139 -137
- package/lib/umd/locale/de.js +141 -139
- package/lib/umd/locale/ee.js +140 -138
- package/lib/umd/locale/el.js +140 -138
- package/lib/umd/locale/en.js +142 -138
- package/lib/umd/locale/eo.js +140 -138
- package/lib/umd/locale/es.js +138 -137
- package/lib/umd/locale/eu.js +143 -138
- package/lib/umd/locale/fa.js +140 -138
- package/lib/umd/locale/fi.js +140 -138
- package/lib/umd/locale/fr.js +140 -137
- package/lib/umd/locale/he.js +145 -138
- package/lib/umd/locale/hr.js +143 -138
- package/lib/umd/locale/hu.js +139 -137
- package/lib/umd/locale/hy-AM.js +140 -138
- package/lib/umd/locale/id.js +139 -138
- package/lib/umd/locale/is.js +139 -138
- package/lib/umd/locale/it.js +138 -137
- package/lib/umd/locale/ja.js +140 -138
- package/lib/umd/locale/kg.js +140 -138
- package/lib/umd/locale/km.js +139 -138
- package/lib/umd/locale/ko.js +140 -138
- package/lib/umd/locale/ku.js +140 -138
- package/lib/umd/locale/kz.js +140 -138
- package/lib/umd/locale/lo-LA.js +138 -137
- package/lib/umd/locale/lt.js +140 -138
- package/lib/umd/locale/lv.js +140 -138
- package/lib/umd/locale/mn.js +140 -138
- package/lib/umd/locale/ms.js +138 -137
- package/lib/umd/locale/nb-NO.js +138 -137
- package/lib/umd/locale/nl.js +140 -138
- package/lib/umd/locale/pl.js +140 -138
- package/lib/umd/locale/pt-br.js +139 -138
- package/lib/umd/locale/pt.js +148 -138
- package/lib/umd/locale/ro.js +140 -138
- package/lib/umd/locale/ru-RU.js +139 -138
- package/lib/umd/locale/si.js +142 -138
- package/lib/umd/locale/sk.js +141 -140
- package/lib/umd/locale/sl.js +140 -138
- package/lib/umd/locale/sr-Latn.js +139 -138
- package/lib/umd/locale/sr.js +143 -138
- package/lib/umd/locale/sv-SE.js +143 -138
- package/lib/umd/locale/sw.js +142 -138
- package/lib/umd/locale/ta.js +145 -137
- package/lib/umd/locale/th.js +142 -138
- package/lib/umd/locale/tk.js +144 -138
- package/lib/umd/locale/tr-TR.js +140 -138
- package/lib/umd/locale/ua.js +139 -138
- package/lib/umd/locale/ug-CN.js +139 -138
- package/lib/umd/locale/uz-UZ.js +139 -138
- package/lib/umd/locale/vi.js +139 -138
- package/lib/umd/locale/zh-CN.js +139 -138
- package/lib/umd/locale/zh-TW.js +143 -138
- package/lib/upload.js +2377 -987
- package/lib/utils/after-leave.js +36 -33
- package/lib/utils/aria-dialog.js +55 -73
- package/lib/utils/aria-utils.js +67 -76
- package/lib/utils/clickoutside.js +52 -60
- package/lib/utils/date-util.js +198 -241
- package/lib/utils/date.js +6 -368
- package/lib/utils/date_source.js +349 -0
- package/lib/utils/dom.js +167 -183
- package/lib/utils/lodash.js +13 -9421
- package/lib/utils/lodash_source.js +9421 -0
- package/lib/utils/menu/aria-menubar.js +13 -18
- package/lib/utils/menu/aria-menuitem.js +43 -54
- package/lib/utils/menu/aria-submenu.js +50 -59
- package/lib/utils/merge.js +15 -17
- package/lib/utils/popper.js +1141 -1170
- package/lib/utils/popup/index.js +186 -230
- package/lib/utils/popup/popup-manager.js +159 -191
- package/lib/utils/resize-event.js +29 -44
- package/lib/utils/scroll-into-view.js +25 -33
- package/lib/utils/scrollbar-width.js +25 -36
- package/lib/utils/shared.js +3 -3
- package/lib/utils/types.js +19 -32
- package/lib/utils/util.js +187 -221
- package/lib/utils/vdom.js +5 -9
- package/lib/utils/vue-popper.js +166 -188
- package/package.json +22 -19
- package/packages/alert/src/main.vue +63 -63
- package/packages/aside/src/main.vue +9 -9
- package/packages/autocomplete/src/autocomplete-suggestions.vue +46 -46
- package/packages/autocomplete/src/autocomplete.vue +198 -198
- package/packages/avatar/src/main.vue +5 -5
- package/packages/backtop/src/main.vue +3 -3
- package/packages/badge/src/main.vue +1 -1
- package/packages/breadcrumb/src/breadcrumb-item.vue +26 -26
- package/packages/breadcrumb/src/breadcrumb.vue +22 -22
- package/packages/button/src/button-group.vue +3 -3
- package/packages/button/src/button.vue +44 -44
- package/packages/calendar/src/date-table.vue +3 -3
- package/packages/calendar/src/main.vue +7 -7
- package/packages/card/src/main.vue +9 -9
- package/packages/carousel/src/item.vue +98 -98
- package/packages/carousel/src/main.vue +2 -2
- package/packages/cascader/src/cascader.vue +4 -4
- package/packages/cascader-panel/src/cascader-menu.vue +4 -4
- package/packages/cascader-panel/src/cascader-node.vue +232 -232
- package/packages/cascader-panel/src/cascader-panel.vue +3 -3
- package/packages/cascader-panel/src/node.js +2 -3
- package/packages/cascader-panel/src/store.js +0 -1
- package/packages/checkbox/src/checkbox-button.vue +139 -139
- package/packages/checkbox/src/checkbox-group.vue +33 -33
- package/packages/checkbox/src/checkbox.vue +140 -140
- package/packages/col/src/col.js +5 -5
- package/packages/collapse/src/collapse-item.vue +55 -55
- package/packages/collapse/src/collapse.vue +54 -54
- package/packages/color-picker/src/color.js +4 -4
- package/packages/color-picker/src/components/alpha-slider.vue +100 -100
- package/packages/color-picker/src/components/hue-slider.vue +91 -91
- package/packages/color-picker/src/components/picker-dropdown.vue +64 -64
- package/packages/color-picker/src/components/predefine.vue +43 -43
- package/packages/color-picker/src/components/sv-panel.vue +70 -70
- package/packages/color-picker/src/main.vue +141 -141
- package/packages/container/src/main.vue +20 -20
- package/packages/date-picker/src/basic/date-table.vue +360 -360
- package/packages/date-picker/src/basic/month-table.vue +222 -223
- package/packages/date-picker/src/basic/time-spinner.vue +174 -174
- package/packages/date-picker/src/basic/year-table.vue +91 -91
- package/packages/date-picker/src/panel/date-range.vue +415 -415
- package/packages/date-picker/src/panel/date.vue +423 -423
- package/packages/date-picker/src/panel/month-range.vue +177 -177
- package/packages/date-picker/src/panel/time-range.vue +173 -173
- package/packages/date-picker/src/panel/time-select.vue +131 -131
- package/packages/date-picker/src/panel/time.vue +131 -131
- package/packages/date-picker/src/picker.vue +7 -7
- package/packages/descriptions/src/descriptions-row.js +3 -3
- package/packages/descriptions/src/index.js +1 -1
- package/packages/dialog/src/component.vue +155 -155
- package/packages/divider/src/main.vue +1 -1
- package/packages/drawer/src/main.vue +2 -2
- package/packages/dropdown/src/dropdown-item.vue +15 -15
- package/packages/dropdown/src/dropdown-menu.vue +47 -47
- package/packages/dropdown/src/dropdown.vue +260 -260
- package/packages/empty/src/index.vue +1 -1
- package/packages/fileUpload/index.js +8 -0
- package/packages/fileUpload/src/main.vue +430 -0
- package/packages/footer/src/main.vue +9 -9
- package/packages/form/src/form-item.vue +245 -245
- package/packages/form/src/form.vue +154 -154
- package/packages/header/src/main.vue +9 -9
- package/packages/icon/src/icon.vue +6 -6
- package/packages/image/src/image-viewer.vue +9 -9
- package/packages/image/src/main.vue +206 -206
- package/packages/infinite-scroll/src/main.js +1 -2
- package/packages/input/src/calcTextareaHeight.js +2 -2
- package/packages/input/src/input.vue +311 -311
- package/packages/input-number/src/input-number.vue +205 -205
- package/packages/loading/src/loading.vue +19 -19
- package/packages/main/src/main.vue +4 -4
- package/packages/menu/src/menu-item-group.vue +27 -27
- package/packages/menu/src/menu-item.vue +69 -69
- package/packages/menu/src/menu.vue +284 -284
- package/packages/menu/src/submenu.vue +308 -309
- package/packages/message/src/main.js +1 -1
- package/packages/message/src/main.vue +72 -72
- package/packages/message-box/src/main.vue +216 -216
- package/packages/notification/src/main.js +1 -1
- package/packages/notification/src/main.vue +93 -93
- package/packages/pagination/src/pager.vue +99 -99
- package/packages/popconfirm/src/main.vue +28 -28
- package/packages/popover/src/main.vue +6 -6
- package/packages/progress/src/progress.vue +174 -174
- package/packages/radio/src/radio-button.vue +64 -64
- package/packages/radio/src/radio-group.vue +88 -88
- package/packages/radio/src/radio.vue +74 -74
- package/packages/rate/src/main.vue +270 -270
- package/packages/row/src/row.js +3 -3
- package/packages/scrollbar/src/main.js +2 -2
- package/packages/scrollbar/src/util.js +1 -1
- package/packages/select/src/option-group.vue +46 -46
- package/packages/select/src/option.vue +122 -122
- package/packages/select/src/select-dropdown.vue +49 -49
- package/packages/select/src/select.vue +676 -676
- package/packages/skeleton/src/item.vue +12 -12
- package/packages/slider/src/button.vue +191 -191
- package/packages/slider/src/main.vue +314 -314
- package/packages/spinner/src/spinner.vue +16 -16
- package/packages/statistic/src/main.vue +5 -6
- package/packages/steps/src/step.vue +2 -2
- package/packages/steps/src/steps.vue +4 -4
- package/packages/subTitle/index.js +8 -0
- package/packages/subTitle/src/main.vue +33 -0
- package/packages/switch/src/component.vue +123 -123
- package/packages/tabDialog/index.js +23 -0
- package/packages/tabDialog/src/dialog/drag.js +63 -0
- package/packages/tabDialog/src/dialog/dragHeight.js +34 -0
- package/packages/tabDialog/src/dialog/dragWidth.js +30 -0
- package/packages/tabDialog/src/main.vue +277 -0
- package/packages/table/src/filter-panel.vue +128 -128
- package/packages/table/src/store/index.js +1 -1
- package/packages/table/src/table-body.js +2 -2
- package/packages/table/src/table-column.js +1 -1
- package/packages/table/src/table-header.js +1 -1
- package/packages/table/src/table-layout.js +1 -1
- package/packages/table/src/table.vue +416 -416
- package/packages/tabs/src/tab-bar.vue +43 -43
- package/packages/tabs/src/tab-nav.vue +250 -250
- package/packages/tabs/src/tab-pane.vue +34 -34
- package/packages/tabs/src/tabs.vue +165 -165
- package/packages/tag/src/tag.vue +52 -52
- package/packages/theme-cy/lib/element.css +1 -0
- package/packages/theme-cy/lib/fileUpload.css +1 -0
- package/packages/theme-cy/lib/index.css +1 -1
- package/packages/theme-cy/lib/subTitle.css +1 -0
- package/packages/theme-cy/lib/tabDialog.css +1 -0
- package/packages/theme-cy/lib/treeselect.css +1 -1
- package/packages/theme-cy/src/element.scss +45 -0
- package/packages/theme-cy/src/fileUpload.scss +30 -0
- package/packages/theme-cy/src/index.scss +4 -0
- package/packages/theme-cy/src/subTitle.scss +26 -0
- package/packages/theme-cy/src/tabDialog.scss +43 -0
- package/packages/theme-cy/src/treeselect.scss +20 -14
- package/packages/timeline/src/item.vue +24 -24
- package/packages/timeline/src/main.vue +27 -27
- package/packages/tooltip/src/main.js +1 -1
- package/packages/transfer/src/main.vue +169 -169
- package/packages/transfer/src/transfer-panel.vue +164 -164
- package/packages/tree/src/tree-node.vue +169 -169
- package/packages/tree/src/tree.vue +408 -408
- package/packages/treeSelect/index.js +8 -0
- package/packages/{treeselect → treeSelect}/src/main.vue +19 -19
- package/packages/upload/src/ajax.js +3 -3
- package/packages/upload/src/upload-dragger.vue +50 -50
- package/packages/upload/src/upload-list.vue +33 -33
- package/packages/upload/src/upload.vue +1 -1
- package/src/index.js +13 -5
- package/src/locale/format.js +0 -1
- package/src/mixins/migrating.js +2 -2
- package/src/utils/date.js +2 -368
- package/src/utils/date_source.js +368 -0
- package/src/utils/lodash.js +9 -18075
- package/src/utils/lodash_source.js +18075 -0
- package/src/utils/types.js +1 -1
- package/types/element-ui.d.ts +16 -3
- package/types/fileUpload.d.ts +5 -0
- package/types/subTitle.d.ts +5 -0
- package/types/tabDialog.d.ts +5 -0
- package/types/treeSelect.d.ts +5 -0
- package/lib/treeselect.js +0 -682
- package/packages/treeselect/index.js +0 -8
- package/types/treeselect.d.ts +0 -5
package/lib/utils/popper.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
|
1
|
+
"use strict";
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* @fileOverview Kickass library to create and place poppers near their reference elements.
|
|
@@ -31,1231 +29,1204 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
|
|
|
31
29
|
// Cross module loader
|
|
32
30
|
// Supported: Node, AMD, Browser globals
|
|
33
31
|
//
|
|
34
|
-
;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
;
|
|
33
|
+
(function (root, factory) {
|
|
34
|
+
if (typeof define === 'function' && define.amd) {
|
|
35
|
+
// AMD. Register as an anonymous module.
|
|
36
|
+
define(factory);
|
|
37
|
+
} else if (typeof module === 'object' && module.exports) {
|
|
38
|
+
// Node. Does not work with strict CommonJS, but
|
|
39
|
+
// only CommonJS-like environments that support module.exports,
|
|
40
|
+
// like Node.
|
|
41
|
+
module.exports = factory();
|
|
42
|
+
} else {
|
|
43
|
+
// Browser globals (root is window)
|
|
44
|
+
root.Popper = factory();
|
|
45
|
+
}
|
|
46
|
+
})(void 0, function () {
|
|
47
|
+
'use strict';
|
|
48
|
+
|
|
49
|
+
var root = window;
|
|
50
|
+
|
|
51
|
+
// default options
|
|
52
|
+
var DEFAULTS = {
|
|
53
|
+
// placement of the popper
|
|
54
|
+
placement: 'bottom',
|
|
55
|
+
gpuAcceleration: true,
|
|
56
|
+
// shift popper from its origin by the given amount of pixels (can be negative)
|
|
57
|
+
offset: 0,
|
|
58
|
+
// the element which will act as boundary of the popper
|
|
59
|
+
boundariesElement: 'viewport',
|
|
60
|
+
// amount of pixel used to define a minimum distance between the boundaries and the popper
|
|
61
|
+
boundariesPadding: 5,
|
|
62
|
+
// popper will try to prevent overflow following this order,
|
|
63
|
+
// by default, then, it could overflow on the left and on top of the boundariesElement
|
|
64
|
+
preventOverflowOrder: ['left', 'right', 'top', 'bottom'],
|
|
65
|
+
// the behavior used by flip to change the placement of the popper
|
|
66
|
+
flipBehavior: 'flip',
|
|
67
|
+
arrowElement: '[x-arrow]',
|
|
68
|
+
arrowOffset: 0,
|
|
69
|
+
// list of functions used to modify the offsets before they are applied to the popper
|
|
70
|
+
modifiers: ['shift', 'offset', 'preventOverflow', 'keepTogether', 'arrow', 'flip', 'applyStyle'],
|
|
71
|
+
modifiersIgnored: [],
|
|
72
|
+
forceAbsolute: false
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Create a new Popper.js instance
|
|
77
|
+
* @constructor Popper
|
|
78
|
+
* @param {HTMLElement} reference - The reference element used to position the popper
|
|
79
|
+
* @param {HTMLElement|Object} popper
|
|
80
|
+
* The HTML element used as popper, or a configuration used to generate the popper.
|
|
81
|
+
* @param {String} [popper.tagName='div'] The tag name of the generated popper.
|
|
82
|
+
* @param {Array} [popper.classNames=['popper']] Array of classes to apply to the generated popper.
|
|
83
|
+
* @param {Array} [popper.attributes] Array of attributes to apply, specify `attr:value` to assign a value to it.
|
|
84
|
+
* @param {HTMLElement|String} [popper.parent=window.document.body] The parent element, given as HTMLElement or as query string.
|
|
85
|
+
* @param {String} [popper.content=''] The content of the popper, it can be text, html, or node; if it is not text, set `contentType` to `html` or `node`.
|
|
86
|
+
* @param {String} [popper.contentType='text'] If `html`, the `content` will be parsed as HTML. If `node`, it will be appended as-is.
|
|
87
|
+
* @param {String} [popper.arrowTagName='div'] Same as `popper.tagName` but for the arrow element.
|
|
88
|
+
* @param {Array} [popper.arrowClassNames='popper__arrow'] Same as `popper.classNames` but for the arrow element.
|
|
89
|
+
* @param {String} [popper.arrowAttributes=['x-arrow']] Same as `popper.attributes` but for the arrow element.
|
|
90
|
+
* @param {Object} options
|
|
91
|
+
* @param {String} [options.placement=bottom]
|
|
92
|
+
* Placement of the popper accepted values: `top(-start, -end), right(-start, -end), bottom(-start, -right),
|
|
93
|
+
* left(-start, -end)`
|
|
94
|
+
*
|
|
95
|
+
* @param {HTMLElement|String} [options.arrowElement='[x-arrow]']
|
|
96
|
+
* The DOM Node used as arrow for the popper, or a CSS selector used to get the DOM node. It must be child of
|
|
97
|
+
* its parent Popper. Popper.js will apply to the given element the style required to align the arrow with its
|
|
98
|
+
* reference element.
|
|
99
|
+
* By default, it will look for a child node of the popper with the `x-arrow` attribute.
|
|
100
|
+
*
|
|
101
|
+
* @param {Boolean} [options.gpuAcceleration=true]
|
|
102
|
+
* When this property is set to true, the popper position will be applied using CSS3 translate3d, allowing the
|
|
103
|
+
* browser to use the GPU to accelerate the rendering.
|
|
104
|
+
* If set to false, the popper will be placed using `top` and `left` properties, not using the GPU.
|
|
105
|
+
*
|
|
106
|
+
* @param {Number} [options.offset=0]
|
|
107
|
+
* Amount of pixels the popper will be shifted (can be negative).
|
|
108
|
+
*
|
|
109
|
+
* @param {String|Element} [options.boundariesElement='viewport']
|
|
110
|
+
* The element which will define the boundaries of the popper position, the popper will never be placed outside
|
|
111
|
+
* of the defined boundaries (except if `keepTogether` is enabled)
|
|
112
|
+
*
|
|
113
|
+
* @param {Number} [options.boundariesPadding=5]
|
|
114
|
+
* Additional padding for the boundaries
|
|
115
|
+
*
|
|
116
|
+
* @param {Array} [options.preventOverflowOrder=['left', 'right', 'top', 'bottom']]
|
|
117
|
+
* Order used when Popper.js tries to avoid overflows from the boundaries, they will be checked in order,
|
|
118
|
+
* this means that the last ones will never overflow
|
|
119
|
+
*
|
|
120
|
+
* @param {String|Array} [options.flipBehavior='flip']
|
|
121
|
+
* The behavior used by the `flip` modifier to change the placement of the popper when the latter is trying to
|
|
122
|
+
* overlap its reference element. Defining `flip` as value, the placement will be flipped on
|
|
123
|
+
* its axis (`right - left`, `top - bottom`).
|
|
124
|
+
* You can even pass an array of placements (eg: `['right', 'left', 'top']` ) to manually specify
|
|
125
|
+
* how alter the placement when a flip is needed. (eg. in the above example, it would first flip from right to left,
|
|
126
|
+
* then, if even in its new placement, the popper is overlapping its reference element, it will be moved to top)
|
|
127
|
+
*
|
|
128
|
+
* @param {Array} [options.modifiers=[ 'shift', 'offset', 'preventOverflow', 'keepTogether', 'arrow', 'flip', 'applyStyle']]
|
|
129
|
+
* List of functions used to modify the data before they are applied to the popper, add your custom functions
|
|
130
|
+
* to this array to edit the offsets and placement.
|
|
131
|
+
* The function should reflect the @params and @returns of preventOverflow
|
|
132
|
+
*
|
|
133
|
+
* @param {Array} [options.modifiersIgnored=[]]
|
|
134
|
+
* Put here any built-in modifier name you want to exclude from the modifiers list
|
|
135
|
+
* The function should reflect the @params and @returns of preventOverflow
|
|
136
|
+
*
|
|
137
|
+
* @param {Boolean} [options.removeOnDestroy=false]
|
|
138
|
+
* Set to true if you want to automatically remove the popper when you call the `destroy` method.
|
|
139
|
+
*/
|
|
140
|
+
function Popper(reference, popper, options) {
|
|
141
|
+
this._reference = reference.jquery ? reference[0] : reference;
|
|
142
|
+
this.state = {};
|
|
143
|
+
|
|
144
|
+
// if the popper variable is a configuration object, parse it to generate an HTMLElement
|
|
145
|
+
// generate a default popper if is not defined
|
|
146
|
+
var isNotDefined = typeof popper === 'undefined' || popper === null;
|
|
147
|
+
var isConfig = popper && Object.prototype.toString.call(popper) === '[object Object]';
|
|
148
|
+
if (isNotDefined || isConfig) {
|
|
149
|
+
this._popper = this.parse(isConfig ? popper : {});
|
|
46
150
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var root = window;
|
|
52
|
-
|
|
53
|
-
// default options
|
|
54
|
-
var DEFAULTS = {
|
|
55
|
-
// placement of the popper
|
|
56
|
-
placement: 'bottom',
|
|
57
|
-
|
|
58
|
-
gpuAcceleration: true,
|
|
59
|
-
|
|
60
|
-
// shift popper from its origin by the given amount of pixels (can be negative)
|
|
61
|
-
offset: 0,
|
|
62
|
-
|
|
63
|
-
// the element which will act as boundary of the popper
|
|
64
|
-
boundariesElement: 'viewport',
|
|
65
|
-
|
|
66
|
-
// amount of pixel used to define a minimum distance between the boundaries and the popper
|
|
67
|
-
boundariesPadding: 5,
|
|
68
|
-
|
|
69
|
-
// popper will try to prevent overflow following this order,
|
|
70
|
-
// by default, then, it could overflow on the left and on top of the boundariesElement
|
|
71
|
-
preventOverflowOrder: ['left', 'right', 'top', 'bottom'],
|
|
72
|
-
|
|
73
|
-
// the behavior used by flip to change the placement of the popper
|
|
74
|
-
flipBehavior: 'flip',
|
|
75
|
-
|
|
76
|
-
arrowElement: '[x-arrow]',
|
|
77
|
-
|
|
78
|
-
arrowOffset: 0,
|
|
79
|
-
|
|
80
|
-
// list of functions used to modify the offsets before they are applied to the popper
|
|
81
|
-
modifiers: ['shift', 'offset', 'preventOverflow', 'keepTogether', 'arrow', 'flip', 'applyStyle'],
|
|
82
|
-
|
|
83
|
-
modifiersIgnored: [],
|
|
84
|
-
|
|
85
|
-
forceAbsolute: false
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Create a new Popper.js instance
|
|
90
|
-
* @constructor Popper
|
|
91
|
-
* @param {HTMLElement} reference - The reference element used to position the popper
|
|
92
|
-
* @param {HTMLElement|Object} popper
|
|
93
|
-
* The HTML element used as popper, or a configuration used to generate the popper.
|
|
94
|
-
* @param {String} [popper.tagName='div'] The tag name of the generated popper.
|
|
95
|
-
* @param {Array} [popper.classNames=['popper']] Array of classes to apply to the generated popper.
|
|
96
|
-
* @param {Array} [popper.attributes] Array of attributes to apply, specify `attr:value` to assign a value to it.
|
|
97
|
-
* @param {HTMLElement|String} [popper.parent=window.document.body] The parent element, given as HTMLElement or as query string.
|
|
98
|
-
* @param {String} [popper.content=''] The content of the popper, it can be text, html, or node; if it is not text, set `contentType` to `html` or `node`.
|
|
99
|
-
* @param {String} [popper.contentType='text'] If `html`, the `content` will be parsed as HTML. If `node`, it will be appended as-is.
|
|
100
|
-
* @param {String} [popper.arrowTagName='div'] Same as `popper.tagName` but for the arrow element.
|
|
101
|
-
* @param {Array} [popper.arrowClassNames='popper__arrow'] Same as `popper.classNames` but for the arrow element.
|
|
102
|
-
* @param {String} [popper.arrowAttributes=['x-arrow']] Same as `popper.attributes` but for the arrow element.
|
|
103
|
-
* @param {Object} options
|
|
104
|
-
* @param {String} [options.placement=bottom]
|
|
105
|
-
* Placement of the popper accepted values: `top(-start, -end), right(-start, -end), bottom(-start, -right),
|
|
106
|
-
* left(-start, -end)`
|
|
107
|
-
*
|
|
108
|
-
* @param {HTMLElement|String} [options.arrowElement='[x-arrow]']
|
|
109
|
-
* The DOM Node used as arrow for the popper, or a CSS selector used to get the DOM node. It must be child of
|
|
110
|
-
* its parent Popper. Popper.js will apply to the given element the style required to align the arrow with its
|
|
111
|
-
* reference element.
|
|
112
|
-
* By default, it will look for a child node of the popper with the `x-arrow` attribute.
|
|
113
|
-
*
|
|
114
|
-
* @param {Boolean} [options.gpuAcceleration=true]
|
|
115
|
-
* When this property is set to true, the popper position will be applied using CSS3 translate3d, allowing the
|
|
116
|
-
* browser to use the GPU to accelerate the rendering.
|
|
117
|
-
* If set to false, the popper will be placed using `top` and `left` properties, not using the GPU.
|
|
118
|
-
*
|
|
119
|
-
* @param {Number} [options.offset=0]
|
|
120
|
-
* Amount of pixels the popper will be shifted (can be negative).
|
|
121
|
-
*
|
|
122
|
-
* @param {String|Element} [options.boundariesElement='viewport']
|
|
123
|
-
* The element which will define the boundaries of the popper position, the popper will never be placed outside
|
|
124
|
-
* of the defined boundaries (except if `keepTogether` is enabled)
|
|
125
|
-
*
|
|
126
|
-
* @param {Number} [options.boundariesPadding=5]
|
|
127
|
-
* Additional padding for the boundaries
|
|
128
|
-
*
|
|
129
|
-
* @param {Array} [options.preventOverflowOrder=['left', 'right', 'top', 'bottom']]
|
|
130
|
-
* Order used when Popper.js tries to avoid overflows from the boundaries, they will be checked in order,
|
|
131
|
-
* this means that the last ones will never overflow
|
|
132
|
-
*
|
|
133
|
-
* @param {String|Array} [options.flipBehavior='flip']
|
|
134
|
-
* The behavior used by the `flip` modifier to change the placement of the popper when the latter is trying to
|
|
135
|
-
* overlap its reference element. Defining `flip` as value, the placement will be flipped on
|
|
136
|
-
* its axis (`right - left`, `top - bottom`).
|
|
137
|
-
* You can even pass an array of placements (eg: `['right', 'left', 'top']` ) to manually specify
|
|
138
|
-
* how alter the placement when a flip is needed. (eg. in the above example, it would first flip from right to left,
|
|
139
|
-
* then, if even in its new placement, the popper is overlapping its reference element, it will be moved to top)
|
|
140
|
-
*
|
|
141
|
-
* @param {Array} [options.modifiers=[ 'shift', 'offset', 'preventOverflow', 'keepTogether', 'arrow', 'flip', 'applyStyle']]
|
|
142
|
-
* List of functions used to modify the data before they are applied to the popper, add your custom functions
|
|
143
|
-
* to this array to edit the offsets and placement.
|
|
144
|
-
* The function should reflect the @params and @returns of preventOverflow
|
|
145
|
-
*
|
|
146
|
-
* @param {Array} [options.modifiersIgnored=[]]
|
|
147
|
-
* Put here any built-in modifier name you want to exclude from the modifiers list
|
|
148
|
-
* The function should reflect the @params and @returns of preventOverflow
|
|
149
|
-
*
|
|
150
|
-
* @param {Boolean} [options.removeOnDestroy=false]
|
|
151
|
-
* Set to true if you want to automatically remove the popper when you call the `destroy` method.
|
|
152
|
-
*/
|
|
153
|
-
function Popper(reference, popper, options) {
|
|
154
|
-
this._reference = reference.jquery ? reference[0] : reference;
|
|
155
|
-
this.state = {};
|
|
156
|
-
|
|
157
|
-
// if the popper variable is a configuration object, parse it to generate an HTMLElement
|
|
158
|
-
// generate a default popper if is not defined
|
|
159
|
-
var isNotDefined = typeof popper === 'undefined' || popper === null;
|
|
160
|
-
var isConfig = popper && Object.prototype.toString.call(popper) === '[object Object]';
|
|
161
|
-
if (isNotDefined || isConfig) {
|
|
162
|
-
this._popper = this.parse(isConfig ? popper : {});
|
|
163
|
-
}
|
|
164
|
-
// otherwise, use the given HTMLElement as popper
|
|
165
|
-
else {
|
|
166
|
-
this._popper = popper.jquery ? popper[0] : popper;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// with {} we create a new object with the options inside it
|
|
170
|
-
this._options = Object.assign({}, DEFAULTS, options);
|
|
171
|
-
|
|
172
|
-
// refactoring modifiers' list
|
|
173
|
-
this._options.modifiers = this._options.modifiers.map(function (modifier) {
|
|
174
|
-
// remove ignored modifiers
|
|
175
|
-
if (this._options.modifiersIgnored.indexOf(modifier) !== -1) return;
|
|
176
|
-
|
|
177
|
-
// set the x-placement attribute before everything else because it could be used to add margins to the popper
|
|
178
|
-
// margins needs to be calculated to get the correct popper offsets
|
|
179
|
-
if (modifier === 'applyStyle') {
|
|
180
|
-
this._popper.setAttribute('x-placement', this._options.placement);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// return predefined modifier identified by string or keep the custom one
|
|
184
|
-
return this.modifiers[modifier] || modifier;
|
|
185
|
-
}.bind(this));
|
|
186
|
-
|
|
187
|
-
// make sure to apply the popper position before any computation
|
|
188
|
-
this.state.position = this._getPosition(this._popper, this._reference);
|
|
189
|
-
setStyle(this._popper, { position: this.state.position, top: 0 });
|
|
190
|
-
|
|
191
|
-
// fire the first update to position the popper in the right place
|
|
192
|
-
this.update();
|
|
193
|
-
|
|
194
|
-
// setup event listeners, they will take care of update the position in specific situations
|
|
195
|
-
this._setupEventListeners();
|
|
196
|
-
return this;
|
|
151
|
+
// otherwise, use the given HTMLElement as popper
|
|
152
|
+
else {
|
|
153
|
+
this._popper = popper.jquery ? popper[0] : popper;
|
|
197
154
|
}
|
|
198
155
|
|
|
199
|
-
//
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
this._popper.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
* @method
|
|
265
|
-
* @memberof Popper
|
|
266
|
-
* @param {Function} callback
|
|
267
|
-
*/
|
|
268
|
-
Popper.prototype.onUpdate = function (callback) {
|
|
269
|
-
this.state.updateCallback = callback;
|
|
270
|
-
return this;
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Helper used to generate poppers from a configuration file
|
|
275
|
-
* @method
|
|
276
|
-
* @memberof Popper
|
|
277
|
-
* @param config {Object} configuration
|
|
278
|
-
* @returns {HTMLElement} popper
|
|
279
|
-
*/
|
|
280
|
-
Popper.prototype.parse = function (config) {
|
|
281
|
-
var defaultConfig = {
|
|
282
|
-
tagName: 'div',
|
|
283
|
-
classNames: ['popper'],
|
|
284
|
-
attributes: [],
|
|
285
|
-
parent: root.document.body,
|
|
286
|
-
content: '',
|
|
287
|
-
contentType: 'text',
|
|
288
|
-
arrowTagName: 'div',
|
|
289
|
-
arrowClassNames: ['popper__arrow'],
|
|
290
|
-
arrowAttributes: ['x-arrow']
|
|
291
|
-
};
|
|
292
|
-
config = Object.assign({}, defaultConfig, config);
|
|
293
|
-
|
|
294
|
-
var d = root.document;
|
|
295
|
-
|
|
296
|
-
var popper = d.createElement(config.tagName);
|
|
297
|
-
addClassNames(popper, config.classNames);
|
|
298
|
-
addAttributes(popper, config.attributes);
|
|
299
|
-
if (config.contentType === 'node') {
|
|
300
|
-
popper.appendChild(config.content.jquery ? config.content[0] : config.content);
|
|
301
|
-
} else if (config.contentType === 'html') {
|
|
302
|
-
popper.innerHTML = config.content;
|
|
303
|
-
} else {
|
|
304
|
-
popper.textContent = config.content;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
if (config.arrowTagName) {
|
|
308
|
-
var arrow = d.createElement(config.arrowTagName);
|
|
309
|
-
addClassNames(arrow, config.arrowClassNames);
|
|
310
|
-
addAttributes(arrow, config.arrowAttributes);
|
|
311
|
-
popper.appendChild(arrow);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
var parent = config.parent.jquery ? config.parent[0] : config.parent;
|
|
315
|
-
|
|
316
|
-
// if the given parent is a string, use it to match an element
|
|
317
|
-
// if more than one element is matched, the first one will be used as parent
|
|
318
|
-
// if no elements are matched, the script will throw an error
|
|
319
|
-
if (typeof parent === 'string') {
|
|
320
|
-
parent = d.querySelectorAll(config.parent);
|
|
321
|
-
if (parent.length > 1) {
|
|
322
|
-
console.warn('WARNING: the given `parent` query(' + config.parent + ') matched more than one element, the first one will be used');
|
|
323
|
-
}
|
|
324
|
-
if (parent.length === 0) {
|
|
325
|
-
throw 'ERROR: the given `parent` doesn\'t exists!';
|
|
326
|
-
}
|
|
327
|
-
parent = parent[0];
|
|
328
|
-
}
|
|
329
|
-
// if the given parent is a DOM nodes list or an array of nodes with more than one element,
|
|
330
|
-
// the first one will be used as parent
|
|
331
|
-
if (parent.length > 1 && parent instanceof Element === false) {
|
|
332
|
-
console.warn('WARNING: you have passed as parent a list of elements, the first one will be used');
|
|
333
|
-
parent = parent[0];
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// append the generated popper to its parent
|
|
337
|
-
parent.appendChild(popper);
|
|
338
|
-
|
|
339
|
-
return popper;
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Adds class names to the given element
|
|
343
|
-
* @function
|
|
344
|
-
* @ignore
|
|
345
|
-
* @param {HTMLElement} target
|
|
346
|
-
* @param {Array} classes
|
|
347
|
-
*/
|
|
348
|
-
function addClassNames(element, classNames) {
|
|
349
|
-
classNames.forEach(function (className) {
|
|
350
|
-
element.classList.add(className);
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Adds attributes to the given element
|
|
356
|
-
* @function
|
|
357
|
-
* @ignore
|
|
358
|
-
* @param {HTMLElement} target
|
|
359
|
-
* @param {Array} attributes
|
|
360
|
-
* @example
|
|
361
|
-
* addAttributes(element, [ 'data-info:foobar' ]);
|
|
362
|
-
*/
|
|
363
|
-
function addAttributes(element, attributes) {
|
|
364
|
-
attributes.forEach(function (attribute) {
|
|
365
|
-
element.setAttribute(attribute.split(':')[0], attribute.split(':')[1] || '');
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Helper used to get the position which will be applied to the popper
|
|
372
|
-
* @method
|
|
373
|
-
* @memberof Popper
|
|
374
|
-
* @param config {HTMLElement} popper element
|
|
375
|
-
* @param reference {HTMLElement} reference element
|
|
376
|
-
* @returns {String} position
|
|
377
|
-
*/
|
|
378
|
-
Popper.prototype._getPosition = function (popper, reference) {
|
|
379
|
-
var container = getOffsetParent(reference);
|
|
380
|
-
|
|
381
|
-
if (this._options.forceAbsolute) {
|
|
382
|
-
return 'absolute';
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// Decide if the popper will be fixed
|
|
386
|
-
// If the reference element is inside a fixed context, the popper will be fixed as well to allow them to scroll together
|
|
387
|
-
var isParentFixed = isFixed(reference, container);
|
|
388
|
-
return isParentFixed ? 'fixed' : 'absolute';
|
|
156
|
+
// with {} we create a new object with the options inside it
|
|
157
|
+
this._options = Object.assign({}, DEFAULTS, options);
|
|
158
|
+
|
|
159
|
+
// refactoring modifiers' list
|
|
160
|
+
this._options.modifiers = this._options.modifiers.map(function (modifier) {
|
|
161
|
+
// remove ignored modifiers
|
|
162
|
+
if (this._options.modifiersIgnored.indexOf(modifier) !== -1) return;
|
|
163
|
+
|
|
164
|
+
// set the x-placement attribute before everything else because it could be used to add margins to the popper
|
|
165
|
+
// margins needs to be calculated to get the correct popper offsets
|
|
166
|
+
if (modifier === 'applyStyle') {
|
|
167
|
+
this._popper.setAttribute('x-placement', this._options.placement);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// return predefined modifier identified by string or keep the custom one
|
|
171
|
+
return this.modifiers[modifier] || modifier;
|
|
172
|
+
}.bind(this));
|
|
173
|
+
|
|
174
|
+
// make sure to apply the popper position before any computation
|
|
175
|
+
this.state.position = this._getPosition(this._popper, this._reference);
|
|
176
|
+
setStyle(this._popper, {
|
|
177
|
+
position: this.state.position,
|
|
178
|
+
top: 0
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// fire the first update to position the popper in the right place
|
|
182
|
+
this.update();
|
|
183
|
+
|
|
184
|
+
// setup event listeners, they will take care of update the position in specific situations
|
|
185
|
+
this._setupEventListeners();
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
//
|
|
190
|
+
// Methods
|
|
191
|
+
//
|
|
192
|
+
/**
|
|
193
|
+
* Destroy the popper
|
|
194
|
+
* @method
|
|
195
|
+
* @memberof Popper
|
|
196
|
+
*/
|
|
197
|
+
Popper.prototype.destroy = function () {
|
|
198
|
+
this._popper.removeAttribute('x-placement');
|
|
199
|
+
this._popper.style.left = '';
|
|
200
|
+
this._popper.style.position = '';
|
|
201
|
+
this._popper.style.top = '';
|
|
202
|
+
this._popper.style[getSupportedPropertyName('transform')] = '';
|
|
203
|
+
this._removeEventListeners();
|
|
204
|
+
|
|
205
|
+
// remove the popper if user explicity asked for the deletion on destroy
|
|
206
|
+
if (this._options.removeOnDestroy) {
|
|
207
|
+
this._popper.remove();
|
|
208
|
+
}
|
|
209
|
+
return this;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Updates the position of the popper, computing the new offsets and applying the new style
|
|
214
|
+
* @method
|
|
215
|
+
* @memberof Popper
|
|
216
|
+
*/
|
|
217
|
+
Popper.prototype.update = function () {
|
|
218
|
+
var data = {
|
|
219
|
+
instance: this,
|
|
220
|
+
styles: {}
|
|
389
221
|
};
|
|
390
222
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
* @access private
|
|
396
|
-
* @param {Element} popper - the popper element
|
|
397
|
-
* @param {Element} reference - the reference element (the popper will be relative to this)
|
|
398
|
-
* @returns {Object} An object containing the offsets which will be applied to the popper
|
|
399
|
-
*/
|
|
400
|
-
Popper.prototype._getOffsets = function (popper, reference, placement) {
|
|
401
|
-
placement = placement.split('-')[0];
|
|
402
|
-
var popperOffsets = {};
|
|
403
|
-
|
|
404
|
-
popperOffsets.position = this.state.position;
|
|
405
|
-
var isParentFixed = popperOffsets.position === 'fixed';
|
|
406
|
-
|
|
407
|
-
//
|
|
408
|
-
// Get reference element position
|
|
409
|
-
//
|
|
410
|
-
var referenceOffsets = getOffsetRectRelativeToCustomParent(reference, getOffsetParent(popper), isParentFixed);
|
|
411
|
-
|
|
412
|
-
//
|
|
413
|
-
// Get popper sizes
|
|
414
|
-
//
|
|
415
|
-
var popperRect = getOuterSizes(popper);
|
|
416
|
-
|
|
417
|
-
//
|
|
418
|
-
// Compute offsets of popper
|
|
419
|
-
//
|
|
420
|
-
|
|
421
|
-
// depending by the popper placement we have to compute its offsets slightly differently
|
|
422
|
-
if (['right', 'left'].indexOf(placement) !== -1) {
|
|
423
|
-
popperOffsets.top = referenceOffsets.top + referenceOffsets.height / 2 - popperRect.height / 2;
|
|
424
|
-
if (placement === 'left') {
|
|
425
|
-
popperOffsets.left = referenceOffsets.left - popperRect.width;
|
|
426
|
-
} else {
|
|
427
|
-
popperOffsets.left = referenceOffsets.right;
|
|
428
|
-
}
|
|
429
|
-
} else {
|
|
430
|
-
popperOffsets.left = referenceOffsets.left + referenceOffsets.width / 2 - popperRect.width / 2;
|
|
431
|
-
if (placement === 'top') {
|
|
432
|
-
popperOffsets.top = referenceOffsets.top - popperRect.height;
|
|
433
|
-
} else {
|
|
434
|
-
popperOffsets.top = referenceOffsets.bottom;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
// Add width and height to our offsets object
|
|
439
|
-
popperOffsets.width = popperRect.width;
|
|
440
|
-
popperOffsets.height = popperRect.height;
|
|
223
|
+
// store placement inside the data object, modifiers will be able to edit `placement` if needed
|
|
224
|
+
// and refer to _originalPlacement to know the original value
|
|
225
|
+
data.placement = this._options.placement;
|
|
226
|
+
data._originalPlacement = this._options.placement;
|
|
441
227
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
reference: referenceOffsets
|
|
445
|
-
};
|
|
446
|
-
};
|
|
228
|
+
// compute the popper and reference offsets and put them inside data.offsets
|
|
229
|
+
data.offsets = this._getOffsets(this._popper, this._reference, data.placement);
|
|
447
230
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
231
|
+
// get boundaries
|
|
232
|
+
data.boundaries = this._getBoundaries(data, this._options.boundariesPadding, this._options.boundariesElement);
|
|
233
|
+
data = this.runModifiers(data, this._options.modifiers);
|
|
234
|
+
if (typeof this.state.updateCallback === 'function') {
|
|
235
|
+
this.state.updateCallback(data);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* If a function is passed, it will be executed after the initialization of popper with as first argument the Popper instance.
|
|
241
|
+
* @method
|
|
242
|
+
* @memberof Popper
|
|
243
|
+
* @param {Function} callback
|
|
244
|
+
*/
|
|
245
|
+
Popper.prototype.onCreate = function (callback) {
|
|
246
|
+
// the createCallbacks return as first argument the popper instance
|
|
247
|
+
callback(this);
|
|
248
|
+
return this;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* If a function is passed, it will be executed after each update of popper with as first argument the set of coordinates and informations
|
|
253
|
+
* used to style popper and its arrow.
|
|
254
|
+
* NOTE: it doesn't get fired on the first call of the `Popper.update()` method inside the `Popper` constructor!
|
|
255
|
+
* @method
|
|
256
|
+
* @memberof Popper
|
|
257
|
+
* @param {Function} callback
|
|
258
|
+
*/
|
|
259
|
+
Popper.prototype.onUpdate = function (callback) {
|
|
260
|
+
this.state.updateCallback = callback;
|
|
261
|
+
return this;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Helper used to generate poppers from a configuration file
|
|
266
|
+
* @method
|
|
267
|
+
* @memberof Popper
|
|
268
|
+
* @param config {Object} configuration
|
|
269
|
+
* @returns {HTMLElement} popper
|
|
270
|
+
*/
|
|
271
|
+
Popper.prototype.parse = function (config) {
|
|
272
|
+
var defaultConfig = {
|
|
273
|
+
tagName: 'div',
|
|
274
|
+
classNames: ['popper'],
|
|
275
|
+
attributes: [],
|
|
276
|
+
parent: root.document.body,
|
|
277
|
+
content: '',
|
|
278
|
+
contentType: 'text',
|
|
279
|
+
arrowTagName: 'div',
|
|
280
|
+
arrowClassNames: ['popper__arrow'],
|
|
281
|
+
arrowAttributes: ['x-arrow']
|
|
468
282
|
};
|
|
283
|
+
config = Object.assign({}, defaultConfig, config);
|
|
284
|
+
var d = root.document;
|
|
285
|
+
var popper = d.createElement(config.tagName);
|
|
286
|
+
addClassNames(popper, config.classNames);
|
|
287
|
+
addAttributes(popper, config.attributes);
|
|
288
|
+
if (config.contentType === 'node') {
|
|
289
|
+
popper.appendChild(config.content.jquery ? config.content[0] : config.content);
|
|
290
|
+
} else if (config.contentType === 'html') {
|
|
291
|
+
popper.innerHTML = config.content;
|
|
292
|
+
} else {
|
|
293
|
+
popper.textContent = config.content;
|
|
294
|
+
}
|
|
295
|
+
if (config.arrowTagName) {
|
|
296
|
+
var arrow = d.createElement(config.arrowTagName);
|
|
297
|
+
addClassNames(arrow, config.arrowClassNames);
|
|
298
|
+
addAttributes(arrow, config.arrowAttributes);
|
|
299
|
+
popper.appendChild(arrow);
|
|
300
|
+
}
|
|
301
|
+
var parent = config.parent.jquery ? config.parent[0] : config.parent;
|
|
302
|
+
|
|
303
|
+
// if the given parent is a string, use it to match an element
|
|
304
|
+
// if more than one element is matched, the first one will be used as parent
|
|
305
|
+
// if no elements are matched, the script will throw an error
|
|
306
|
+
if (typeof parent === 'string') {
|
|
307
|
+
parent = d.querySelectorAll(config.parent);
|
|
308
|
+
if (parent.length > 1) {
|
|
309
|
+
console.warn('WARNING: the given `parent` query(' + config.parent + ') matched more than one element, the first one will be used');
|
|
310
|
+
}
|
|
311
|
+
if (parent.length === 0) {
|
|
312
|
+
throw 'ERROR: the given `parent` doesn\'t exists!';
|
|
313
|
+
}
|
|
314
|
+
parent = parent[0];
|
|
315
|
+
}
|
|
316
|
+
// if the given parent is a DOM nodes list or an array of nodes with more than one element,
|
|
317
|
+
// the first one will be used as parent
|
|
318
|
+
if (parent.length > 1 && parent instanceof Element === false) {
|
|
319
|
+
console.warn('WARNING: you have passed as parent a list of elements, the first one will be used');
|
|
320
|
+
parent = parent[0];
|
|
321
|
+
}
|
|
469
322
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
* @memberof Popper
|
|
474
|
-
* @access private
|
|
475
|
-
*/
|
|
476
|
-
Popper.prototype._removeEventListeners = function () {
|
|
477
|
-
// NOTE: 1 DOM access here
|
|
478
|
-
root.removeEventListener('resize', this.state.updateBound);
|
|
479
|
-
if (this._options.boundariesElement !== 'window' && this.state.scrollTarget) {
|
|
480
|
-
this.state.scrollTarget.removeEventListener('scroll', this.state.updateBound);
|
|
481
|
-
this.state.scrollTarget = null;
|
|
482
|
-
}
|
|
483
|
-
this.state.updateBound = null;
|
|
484
|
-
};
|
|
323
|
+
// append the generated popper to its parent
|
|
324
|
+
parent.appendChild(popper);
|
|
325
|
+
return popper;
|
|
485
326
|
|
|
486
327
|
/**
|
|
487
|
-
*
|
|
488
|
-
* @
|
|
489
|
-
* @
|
|
490
|
-
* @
|
|
491
|
-
* @param {
|
|
492
|
-
* @param {Number} padding - Boundaries padding
|
|
493
|
-
* @param {Element} boundariesElement - Element used to define the boundaries
|
|
494
|
-
* @returns {Object} Coordinates of the boundaries
|
|
328
|
+
* Adds class names to the given element
|
|
329
|
+
* @function
|
|
330
|
+
* @ignore
|
|
331
|
+
* @param {HTMLElement} target
|
|
332
|
+
* @param {Array} classes
|
|
495
333
|
*/
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
var body = root.document.body,
|
|
502
|
-
html = root.document.documentElement;
|
|
503
|
-
|
|
504
|
-
height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
|
|
505
|
-
width = Math.max(body.scrollWidth, body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth);
|
|
506
|
-
|
|
507
|
-
boundaries = {
|
|
508
|
-
top: 0,
|
|
509
|
-
right: width,
|
|
510
|
-
bottom: height,
|
|
511
|
-
left: 0
|
|
512
|
-
};
|
|
513
|
-
} else if (boundariesElement === 'viewport') {
|
|
514
|
-
var offsetParent = getOffsetParent(this._popper);
|
|
515
|
-
var scrollParent = getScrollParent(this._popper);
|
|
516
|
-
var offsetParentRect = getOffsetRect(offsetParent);
|
|
517
|
-
|
|
518
|
-
// Thanks the fucking native API, `document.body.scrollTop` & `document.documentElement.scrollTop`
|
|
519
|
-
var getScrollTopValue = function getScrollTopValue(element) {
|
|
520
|
-
return element == document.body ? Math.max(document.documentElement.scrollTop, document.body.scrollTop) : element.scrollTop;
|
|
521
|
-
};
|
|
522
|
-
var getScrollLeftValue = function getScrollLeftValue(element) {
|
|
523
|
-
return element == document.body ? Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) : element.scrollLeft;
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
// if the popper is fixed we don't have to substract scrolling from the boundaries
|
|
527
|
-
var scrollTop = data.offsets.popper.position === 'fixed' ? 0 : getScrollTopValue(scrollParent);
|
|
528
|
-
var scrollLeft = data.offsets.popper.position === 'fixed' ? 0 : getScrollLeftValue(scrollParent);
|
|
529
|
-
|
|
530
|
-
boundaries = {
|
|
531
|
-
top: 0 - (offsetParentRect.top - scrollTop),
|
|
532
|
-
right: root.document.documentElement.clientWidth - (offsetParentRect.left - scrollLeft),
|
|
533
|
-
bottom: root.document.documentElement.clientHeight - (offsetParentRect.top - scrollTop),
|
|
534
|
-
left: 0 - (offsetParentRect.left - scrollLeft)
|
|
535
|
-
};
|
|
536
|
-
} else {
|
|
537
|
-
if (getOffsetParent(this._popper) === boundariesElement) {
|
|
538
|
-
boundaries = {
|
|
539
|
-
top: 0,
|
|
540
|
-
left: 0,
|
|
541
|
-
right: boundariesElement.clientWidth,
|
|
542
|
-
bottom: boundariesElement.clientHeight
|
|
543
|
-
};
|
|
544
|
-
} else {
|
|
545
|
-
boundaries = getOffsetRect(boundariesElement);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
boundaries.left += padding;
|
|
549
|
-
boundaries.right -= padding;
|
|
550
|
-
boundaries.top = boundaries.top + padding;
|
|
551
|
-
boundaries.bottom = boundaries.bottom - padding;
|
|
552
|
-
return boundaries;
|
|
553
|
-
};
|
|
334
|
+
function addClassNames(element, classNames) {
|
|
335
|
+
classNames.forEach(function (className) {
|
|
336
|
+
element.classList.add(className);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
554
339
|
|
|
555
340
|
/**
|
|
556
|
-
*
|
|
557
|
-
* @
|
|
558
|
-
* @
|
|
559
|
-
* @
|
|
560
|
-
* @param {
|
|
561
|
-
* @
|
|
562
|
-
*
|
|
341
|
+
* Adds attributes to the given element
|
|
342
|
+
* @function
|
|
343
|
+
* @ignore
|
|
344
|
+
* @param {HTMLElement} target
|
|
345
|
+
* @param {Array} attributes
|
|
346
|
+
* @example
|
|
347
|
+
* addAttributes(element, [ 'data-info:foobar' ]);
|
|
563
348
|
*/
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
349
|
+
function addAttributes(element, attributes) {
|
|
350
|
+
attributes.forEach(function (attribute) {
|
|
351
|
+
element.setAttribute(attribute.split(':')[0], attribute.split(':')[1] || '');
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Helper used to get the position which will be applied to the popper
|
|
358
|
+
* @method
|
|
359
|
+
* @memberof Popper
|
|
360
|
+
* @param config {HTMLElement} popper element
|
|
361
|
+
* @param reference {HTMLElement} reference element
|
|
362
|
+
* @returns {String} position
|
|
363
|
+
*/
|
|
364
|
+
Popper.prototype._getPosition = function (popper, reference) {
|
|
365
|
+
var container = getOffsetParent(reference);
|
|
366
|
+
if (this._options.forceAbsolute) {
|
|
367
|
+
return 'absolute';
|
|
368
|
+
}
|
|
578
369
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
370
|
+
// Decide if the popper will be fixed
|
|
371
|
+
// If the reference element is inside a fixed context, the popper will be fixed as well to allow them to scroll together
|
|
372
|
+
var isParentFixed = isFixed(reference, container);
|
|
373
|
+
return isParentFixed ? 'fixed' : 'absolute';
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Get offsets to the popper
|
|
378
|
+
* @method
|
|
379
|
+
* @memberof Popper
|
|
380
|
+
* @access private
|
|
381
|
+
* @param {Element} popper - the popper element
|
|
382
|
+
* @param {Element} reference - the reference element (the popper will be relative to this)
|
|
383
|
+
* @returns {Object} An object containing the offsets which will be applied to the popper
|
|
384
|
+
*/
|
|
385
|
+
Popper.prototype._getOffsets = function (popper, reference, placement) {
|
|
386
|
+
placement = placement.split('-')[0];
|
|
387
|
+
var popperOffsets = {};
|
|
388
|
+
popperOffsets.position = this.state.position;
|
|
389
|
+
var isParentFixed = popperOffsets.position === 'fixed';
|
|
593
390
|
|
|
594
391
|
//
|
|
595
|
-
//
|
|
392
|
+
// Get reference element position
|
|
596
393
|
//
|
|
394
|
+
var referenceOffsets = getOffsetRectRelativeToCustomParent(reference, getOffsetParent(popper), isParentFixed);
|
|
597
395
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
* @type {Object}
|
|
603
|
-
*/
|
|
604
|
-
Popper.prototype.modifiers = {};
|
|
605
|
-
|
|
606
|
-
/**
|
|
607
|
-
* Apply the computed styles to the popper element
|
|
608
|
-
* @method
|
|
609
|
-
* @memberof Popper.modifiers
|
|
610
|
-
* @argument {Object} data - The data object generated by `update` method
|
|
611
|
-
* @returns {Object} The same data object
|
|
612
|
-
*/
|
|
613
|
-
Popper.prototype.modifiers.applyStyle = function (data) {
|
|
614
|
-
// apply the final offsets to the popper
|
|
615
|
-
// NOTE: 1 DOM access here
|
|
616
|
-
var styles = {
|
|
617
|
-
position: data.offsets.popper.position
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
// round top and left to avoid blurry text
|
|
621
|
-
var left = Math.round(data.offsets.popper.left);
|
|
622
|
-
var top = Math.round(data.offsets.popper.top);
|
|
623
|
-
|
|
624
|
-
// if gpuAcceleration is set to true and transform is supported, we use `translate3d` to apply the position to the popper
|
|
625
|
-
// we automatically use the supported prefixed version if needed
|
|
626
|
-
var prefixedProperty;
|
|
627
|
-
if (this._options.gpuAcceleration && (prefixedProperty = getSupportedPropertyName('transform'))) {
|
|
628
|
-
styles[prefixedProperty] = 'translate3d(' + left + 'px, ' + top + 'px, 0)';
|
|
629
|
-
styles.top = 0;
|
|
630
|
-
styles.left = 0;
|
|
631
|
-
}
|
|
632
|
-
// othwerise, we use the standard `left` and `top` properties
|
|
633
|
-
else {
|
|
634
|
-
styles.left = left;
|
|
635
|
-
styles.top = top;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
// any property present in `data.styles` will be applied to the popper,
|
|
639
|
-
// in this way we can make the 3rd party modifiers add custom styles to it
|
|
640
|
-
// Be aware, modifiers could override the properties defined in the previous
|
|
641
|
-
// lines of this modifier!
|
|
642
|
-
Object.assign(styles, data.styles);
|
|
643
|
-
|
|
644
|
-
setStyle(this._popper, styles);
|
|
645
|
-
|
|
646
|
-
// set an attribute which will be useful to style the tooltip (use it to properly position its arrow)
|
|
647
|
-
// NOTE: 1 DOM access here
|
|
648
|
-
this._popper.setAttribute('x-placement', data.placement);
|
|
649
|
-
|
|
650
|
-
// if the arrow modifier is required and the arrow style has been computed, apply the arrow style
|
|
651
|
-
if (this.isModifierRequired(this.modifiers.applyStyle, this.modifiers.arrow) && data.offsets.arrow) {
|
|
652
|
-
setStyle(data.arrowElement, data.offsets.arrow);
|
|
653
|
-
}
|
|
396
|
+
//
|
|
397
|
+
// Get popper sizes
|
|
398
|
+
//
|
|
399
|
+
var popperRect = getOuterSizes(popper);
|
|
654
400
|
|
|
655
|
-
|
|
656
|
-
|
|
401
|
+
//
|
|
402
|
+
// Compute offsets of popper
|
|
403
|
+
//
|
|
657
404
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
var shiftOffsets = {
|
|
676
|
-
y: {
|
|
677
|
-
start: { top: reference.top },
|
|
678
|
-
end: { top: reference.top + reference.height - popper.height }
|
|
679
|
-
},
|
|
680
|
-
x: {
|
|
681
|
-
start: { left: reference.left },
|
|
682
|
-
end: { left: reference.left + reference.width - popper.width }
|
|
683
|
-
}
|
|
684
|
-
};
|
|
685
|
-
|
|
686
|
-
var axis = ['bottom', 'top'].indexOf(basePlacement) !== -1 ? 'x' : 'y';
|
|
687
|
-
|
|
688
|
-
data.offsets.popper = Object.assign(popper, shiftOffsets[axis][shiftVariation]);
|
|
689
|
-
}
|
|
405
|
+
// depending by the popper placement we have to compute its offsets slightly differently
|
|
406
|
+
if (['right', 'left'].indexOf(placement) !== -1) {
|
|
407
|
+
popperOffsets.top = referenceOffsets.top + referenceOffsets.height / 2 - popperRect.height / 2;
|
|
408
|
+
if (placement === 'left') {
|
|
409
|
+
popperOffsets.left = referenceOffsets.left - popperRect.width;
|
|
410
|
+
} else {
|
|
411
|
+
popperOffsets.left = referenceOffsets.right;
|
|
412
|
+
}
|
|
413
|
+
} else {
|
|
414
|
+
popperOffsets.left = referenceOffsets.left + referenceOffsets.width / 2 - popperRect.width / 2;
|
|
415
|
+
if (placement === 'top') {
|
|
416
|
+
popperOffsets.top = referenceOffsets.top - popperRect.height;
|
|
417
|
+
} else {
|
|
418
|
+
popperOffsets.top = referenceOffsets.bottom;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
690
421
|
|
|
691
|
-
|
|
422
|
+
// Add width and height to our offsets object
|
|
423
|
+
popperOffsets.width = popperRect.width;
|
|
424
|
+
popperOffsets.height = popperRect.height;
|
|
425
|
+
return {
|
|
426
|
+
popper: popperOffsets,
|
|
427
|
+
reference: referenceOffsets
|
|
692
428
|
};
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Setup needed event listeners used to update the popper position
|
|
433
|
+
* @method
|
|
434
|
+
* @memberof Popper
|
|
435
|
+
* @access private
|
|
436
|
+
*/
|
|
437
|
+
Popper.prototype._setupEventListeners = function () {
|
|
438
|
+
// NOTE: 1 DOM access here
|
|
439
|
+
this.state.updateBound = this.update.bind(this);
|
|
440
|
+
root.addEventListener('resize', this.state.updateBound);
|
|
441
|
+
// if the boundariesElement is window we don't need to listen for the scroll event
|
|
442
|
+
if (this._options.boundariesElement !== 'window') {
|
|
443
|
+
var target = getScrollParent(this._reference);
|
|
444
|
+
// here it could be both `body` or `documentElement` thanks to Firefox, we then check both
|
|
445
|
+
if (target === root.document.body || target === root.document.documentElement) {
|
|
446
|
+
target = root;
|
|
447
|
+
}
|
|
448
|
+
target.addEventListener('scroll', this.state.updateBound);
|
|
449
|
+
this.state.scrollTarget = target;
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Remove event listeners used to update the popper position
|
|
455
|
+
* @method
|
|
456
|
+
* @memberof Popper
|
|
457
|
+
* @access private
|
|
458
|
+
*/
|
|
459
|
+
Popper.prototype._removeEventListeners = function () {
|
|
460
|
+
// NOTE: 1 DOM access here
|
|
461
|
+
root.removeEventListener('resize', this.state.updateBound);
|
|
462
|
+
if (this._options.boundariesElement !== 'window' && this.state.scrollTarget) {
|
|
463
|
+
this.state.scrollTarget.removeEventListener('scroll', this.state.updateBound);
|
|
464
|
+
this.state.scrollTarget = null;
|
|
465
|
+
}
|
|
466
|
+
this.state.updateBound = null;
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Computed the boundaries limits and return them
|
|
471
|
+
* @method
|
|
472
|
+
* @memberof Popper
|
|
473
|
+
* @access private
|
|
474
|
+
* @param {Object} data - Object containing the property "offsets" generated by `_getOffsets`
|
|
475
|
+
* @param {Number} padding - Boundaries padding
|
|
476
|
+
* @param {Element} boundariesElement - Element used to define the boundaries
|
|
477
|
+
* @returns {Object} Coordinates of the boundaries
|
|
478
|
+
*/
|
|
479
|
+
Popper.prototype._getBoundaries = function (data, padding, boundariesElement) {
|
|
480
|
+
// NOTE: 1 DOM access here
|
|
481
|
+
var boundaries = {};
|
|
482
|
+
var width, height;
|
|
483
|
+
if (boundariesElement === 'window') {
|
|
484
|
+
var body = root.document.body,
|
|
485
|
+
html = root.document.documentElement;
|
|
486
|
+
height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
|
|
487
|
+
width = Math.max(body.scrollWidth, body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth);
|
|
488
|
+
boundaries = {
|
|
489
|
+
top: 0,
|
|
490
|
+
right: width,
|
|
491
|
+
bottom: height,
|
|
492
|
+
left: 0
|
|
493
|
+
};
|
|
494
|
+
} else if (boundariesElement === 'viewport') {
|
|
495
|
+
var offsetParent = getOffsetParent(this._popper);
|
|
496
|
+
var scrollParent = getScrollParent(this._popper);
|
|
497
|
+
var offsetParentRect = getOffsetRect(offsetParent);
|
|
498
|
+
|
|
499
|
+
// Thanks the fucking native API, `document.body.scrollTop` & `document.documentElement.scrollTop`
|
|
500
|
+
var getScrollTopValue = function getScrollTopValue(element) {
|
|
501
|
+
return element == document.body ? Math.max(document.documentElement.scrollTop, document.body.scrollTop) : element.scrollTop;
|
|
502
|
+
};
|
|
503
|
+
var getScrollLeftValue = function getScrollLeftValue(element) {
|
|
504
|
+
return element == document.body ? Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) : element.scrollLeft;
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
// if the popper is fixed we don't have to substract scrolling from the boundaries
|
|
508
|
+
var scrollTop = data.offsets.popper.position === 'fixed' ? 0 : getScrollTopValue(scrollParent);
|
|
509
|
+
var scrollLeft = data.offsets.popper.position === 'fixed' ? 0 : getScrollLeftValue(scrollParent);
|
|
510
|
+
boundaries = {
|
|
511
|
+
top: 0 - (offsetParentRect.top - scrollTop),
|
|
512
|
+
right: root.document.documentElement.clientWidth - (offsetParentRect.left - scrollLeft),
|
|
513
|
+
bottom: root.document.documentElement.clientHeight - (offsetParentRect.top - scrollTop),
|
|
514
|
+
left: 0 - (offsetParentRect.left - scrollLeft)
|
|
515
|
+
};
|
|
516
|
+
} else {
|
|
517
|
+
if (getOffsetParent(this._popper) === boundariesElement) {
|
|
518
|
+
boundaries = {
|
|
519
|
+
top: 0,
|
|
520
|
+
left: 0,
|
|
521
|
+
right: boundariesElement.clientWidth,
|
|
522
|
+
bottom: boundariesElement.clientHeight
|
|
734
523
|
};
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
placement = data.placement.split('-')[0];
|
|
810
|
-
placementOpposite = getOppositePlacement(placement);
|
|
811
|
-
|
|
812
|
-
var popperOffsets = getPopperClientRect(data.offsets.popper);
|
|
813
|
-
|
|
814
|
-
// this boolean is used to distinguish right and bottom from top and left
|
|
815
|
-
// they need different computations to get flipped
|
|
816
|
-
var a = ['right', 'bottom'].indexOf(placement) !== -1;
|
|
817
|
-
|
|
818
|
-
// using Math.floor because the reference offsets may contain decimals we are not going to consider here
|
|
819
|
-
if (a && Math.floor(data.offsets.reference[placement]) > Math.floor(popperOffsets[placementOpposite]) || !a && Math.floor(data.offsets.reference[placement]) < Math.floor(popperOffsets[placementOpposite])) {
|
|
820
|
-
// we'll use this boolean to detect any flip loop
|
|
821
|
-
data.flipped = true;
|
|
822
|
-
data.placement = flipOrder[index + 1];
|
|
823
|
-
if (variation) {
|
|
824
|
-
data.placement += '-' + variation;
|
|
825
|
-
}
|
|
826
|
-
data.offsets.popper = this._getOffsets(this._popper, this._reference, data.placement).popper;
|
|
827
|
-
|
|
828
|
-
data = this.runModifiers(data, this._options.modifiers, this._flip);
|
|
829
|
-
}
|
|
830
|
-
}.bind(this));
|
|
831
|
-
return data;
|
|
524
|
+
} else {
|
|
525
|
+
boundaries = getOffsetRect(boundariesElement);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
boundaries.left += padding;
|
|
529
|
+
boundaries.right -= padding;
|
|
530
|
+
boundaries.top = boundaries.top + padding;
|
|
531
|
+
boundaries.bottom = boundaries.bottom - padding;
|
|
532
|
+
return boundaries;
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Loop trough the list of modifiers and run them in order, each of them will then edit the data object
|
|
537
|
+
* @method
|
|
538
|
+
* @memberof Popper
|
|
539
|
+
* @access public
|
|
540
|
+
* @param {Object} data
|
|
541
|
+
* @param {Array} modifiers
|
|
542
|
+
* @param {Function} ends
|
|
543
|
+
*/
|
|
544
|
+
Popper.prototype.runModifiers = function (data, modifiers, ends) {
|
|
545
|
+
var modifiersToRun = modifiers.slice();
|
|
546
|
+
if (ends !== undefined) {
|
|
547
|
+
modifiersToRun = this._options.modifiers.slice(0, getArrayKeyIndex(this._options.modifiers, ends));
|
|
548
|
+
}
|
|
549
|
+
modifiersToRun.forEach(function (modifier) {
|
|
550
|
+
if (isFunction(modifier)) {
|
|
551
|
+
data = modifier.call(this, data);
|
|
552
|
+
}
|
|
553
|
+
}.bind(this));
|
|
554
|
+
return data;
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Helper used to know if the given modifier depends from another one.
|
|
559
|
+
* @method
|
|
560
|
+
* @memberof Popper
|
|
561
|
+
* @param {String} requesting - name of requesting modifier
|
|
562
|
+
* @param {String} requested - name of requested modifier
|
|
563
|
+
* @returns {Boolean}
|
|
564
|
+
*/
|
|
565
|
+
Popper.prototype.isModifierRequired = function (requesting, requested) {
|
|
566
|
+
var index = getArrayKeyIndex(this._options.modifiers, requesting);
|
|
567
|
+
return !!this._options.modifiers.slice(0, index).filter(function (modifier) {
|
|
568
|
+
return modifier === requested;
|
|
569
|
+
}).length;
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
//
|
|
573
|
+
// Modifiers
|
|
574
|
+
//
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Modifiers list
|
|
578
|
+
* @namespace Popper.modifiers
|
|
579
|
+
* @memberof Popper
|
|
580
|
+
* @type {Object}
|
|
581
|
+
*/
|
|
582
|
+
Popper.prototype.modifiers = {};
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Apply the computed styles to the popper element
|
|
586
|
+
* @method
|
|
587
|
+
* @memberof Popper.modifiers
|
|
588
|
+
* @argument {Object} data - The data object generated by `update` method
|
|
589
|
+
* @returns {Object} The same data object
|
|
590
|
+
*/
|
|
591
|
+
Popper.prototype.modifiers.applyStyle = function (data) {
|
|
592
|
+
// apply the final offsets to the popper
|
|
593
|
+
// NOTE: 1 DOM access here
|
|
594
|
+
var styles = {
|
|
595
|
+
position: data.offsets.popper.position
|
|
832
596
|
};
|
|
833
597
|
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
popper.left -= offset;
|
|
852
|
-
} else if (data.placement.indexOf('bottom') !== -1) {
|
|
853
|
-
popper.left += offset;
|
|
854
|
-
}
|
|
855
|
-
return data;
|
|
856
|
-
};
|
|
598
|
+
// round top and left to avoid blurry text
|
|
599
|
+
var left = Math.round(data.offsets.popper.left);
|
|
600
|
+
var top = Math.round(data.offsets.popper.top);
|
|
601
|
+
|
|
602
|
+
// if gpuAcceleration is set to true and transform is supported, we use `translate3d` to apply the position to the popper
|
|
603
|
+
// we automatically use the supported prefixed version if needed
|
|
604
|
+
var prefixedProperty;
|
|
605
|
+
if (this._options.gpuAcceleration && (prefixedProperty = getSupportedPropertyName('transform'))) {
|
|
606
|
+
styles[prefixedProperty] = 'translate3d(' + left + 'px, ' + top + 'px, 0)';
|
|
607
|
+
styles.top = 0;
|
|
608
|
+
styles.left = 0;
|
|
609
|
+
}
|
|
610
|
+
// othwerise, we use the standard `left` and `top` properties
|
|
611
|
+
else {
|
|
612
|
+
styles.left = left;
|
|
613
|
+
styles.top = top;
|
|
614
|
+
}
|
|
857
615
|
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
* @returns {Object} The data object, properly modified
|
|
865
|
-
*/
|
|
866
|
-
Popper.prototype.modifiers.arrow = function (data) {
|
|
867
|
-
var arrow = this._options.arrowElement;
|
|
868
|
-
var arrowOffset = this._options.arrowOffset;
|
|
616
|
+
// any property present in `data.styles` will be applied to the popper,
|
|
617
|
+
// in this way we can make the 3rd party modifiers add custom styles to it
|
|
618
|
+
// Be aware, modifiers could override the properties defined in the previous
|
|
619
|
+
// lines of this modifier!
|
|
620
|
+
Object.assign(styles, data.styles);
|
|
621
|
+
setStyle(this._popper, styles);
|
|
869
622
|
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
}
|
|
623
|
+
// set an attribute which will be useful to style the tooltip (use it to properly position its arrow)
|
|
624
|
+
// NOTE: 1 DOM access here
|
|
625
|
+
this._popper.setAttribute('x-placement', data.placement);
|
|
874
626
|
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
627
|
+
// if the arrow modifier is required and the arrow style has been computed, apply the arrow style
|
|
628
|
+
if (this.isModifierRequired(this.modifiers.applyStyle, this.modifiers.arrow) && data.offsets.arrow) {
|
|
629
|
+
setStyle(data.arrowElement, data.offsets.arrow);
|
|
630
|
+
}
|
|
631
|
+
return data;
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Modifier used to shift the popper on the start or end of its reference element side
|
|
636
|
+
* @method
|
|
637
|
+
* @memberof Popper.modifiers
|
|
638
|
+
* @argument {Object} data - The data object generated by `update` method
|
|
639
|
+
* @returns {Object} The data object, properly modified
|
|
640
|
+
*/
|
|
641
|
+
Popper.prototype.modifiers.shift = function (data) {
|
|
642
|
+
var placement = data.placement;
|
|
643
|
+
var basePlacement = placement.split('-')[0];
|
|
644
|
+
var shiftVariation = placement.split('-')[1];
|
|
645
|
+
|
|
646
|
+
// if shift shiftVariation is specified, run the modifier
|
|
647
|
+
if (shiftVariation) {
|
|
648
|
+
var reference = data.offsets.reference;
|
|
649
|
+
var popper = getPopperClientRect(data.offsets.popper);
|
|
650
|
+
var shiftOffsets = {
|
|
651
|
+
y: {
|
|
652
|
+
start: {
|
|
653
|
+
top: reference.top
|
|
654
|
+
},
|
|
655
|
+
end: {
|
|
656
|
+
top: reference.top + reference.height - popper.height
|
|
657
|
+
}
|
|
658
|
+
},
|
|
659
|
+
x: {
|
|
660
|
+
start: {
|
|
661
|
+
left: reference.left
|
|
662
|
+
},
|
|
663
|
+
end: {
|
|
664
|
+
left: reference.left + reference.width - popper.width
|
|
665
|
+
}
|
|
878
666
|
}
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
667
|
+
};
|
|
668
|
+
var axis = ['bottom', 'top'].indexOf(basePlacement) !== -1 ? 'x' : 'y';
|
|
669
|
+
data.offsets.popper = Object.assign(popper, shiftOffsets[axis][shiftVariation]);
|
|
670
|
+
}
|
|
671
|
+
return data;
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Modifier used to make sure the popper does not overflows from it's boundaries
|
|
676
|
+
* @method
|
|
677
|
+
* @memberof Popper.modifiers
|
|
678
|
+
* @argument {Object} data - The data object generated by `update` method
|
|
679
|
+
* @returns {Object} The data object, properly modified
|
|
680
|
+
*/
|
|
681
|
+
Popper.prototype.modifiers.preventOverflow = function (data) {
|
|
682
|
+
var order = this._options.preventOverflowOrder;
|
|
683
|
+
var popper = getPopperClientRect(data.offsets.popper);
|
|
684
|
+
var check = {
|
|
685
|
+
left: function left() {
|
|
686
|
+
var left = popper.left;
|
|
687
|
+
if (popper.left < data.boundaries.left) {
|
|
688
|
+
left = Math.max(popper.left, data.boundaries.left);
|
|
884
689
|
}
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
690
|
+
return {
|
|
691
|
+
left: left
|
|
692
|
+
};
|
|
693
|
+
},
|
|
694
|
+
right: function right() {
|
|
695
|
+
var left = popper.left;
|
|
696
|
+
if (popper.right > data.boundaries.right) {
|
|
697
|
+
left = Math.min(popper.left, data.boundaries.right - popper.width);
|
|
890
698
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
var
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
var side = isVertical ? 'top' : 'left';
|
|
900
|
-
var translate = isVertical ? 'translateY' : 'translateX';
|
|
901
|
-
var altSide = isVertical ? 'left' : 'top';
|
|
902
|
-
var opSide = isVertical ? 'bottom' : 'right';
|
|
903
|
-
var arrowSize = getOuterSizes(arrow)[len];
|
|
904
|
-
|
|
905
|
-
//
|
|
906
|
-
// extends keepTogether behavior making sure the popper and its reference have enough pixels in conjuction
|
|
907
|
-
//
|
|
908
|
-
|
|
909
|
-
// top/left side
|
|
910
|
-
if (reference[opSide] - arrowSize < popper[side]) {
|
|
911
|
-
data.offsets.popper[side] -= popper[side] - (reference[opSide] - arrowSize);
|
|
699
|
+
return {
|
|
700
|
+
left: left
|
|
701
|
+
};
|
|
702
|
+
},
|
|
703
|
+
top: function top() {
|
|
704
|
+
var top = popper.top;
|
|
705
|
+
if (popper.top < data.boundaries.top) {
|
|
706
|
+
top = Math.max(popper.top, data.boundaries.top);
|
|
912
707
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
708
|
+
return {
|
|
709
|
+
top: top
|
|
710
|
+
};
|
|
711
|
+
},
|
|
712
|
+
bottom: function bottom() {
|
|
713
|
+
var top = popper.top;
|
|
714
|
+
if (popper.bottom > data.boundaries.bottom) {
|
|
715
|
+
top = Math.min(popper.top, data.boundaries.bottom - popper.height);
|
|
916
716
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
var sideValue = center - popper[side];
|
|
922
|
-
|
|
923
|
-
// prevent arrow from being placed not contiguously to its popper
|
|
924
|
-
sideValue = Math.max(Math.min(popper[len] - arrowSize - 8, sideValue), 8);
|
|
925
|
-
arrowStyle[side] = sideValue;
|
|
926
|
-
arrowStyle[altSide] = ''; // make sure to remove any old style from the arrow
|
|
927
|
-
|
|
928
|
-
data.offsets.arrow = arrowStyle;
|
|
929
|
-
data.arrowElement = arrow;
|
|
930
|
-
|
|
931
|
-
return data;
|
|
717
|
+
return {
|
|
718
|
+
top: top
|
|
719
|
+
};
|
|
720
|
+
}
|
|
932
721
|
};
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
// original method
|
|
953
|
-
var styles = root.getComputedStyle(element);
|
|
954
|
-
var x = parseFloat(styles.marginTop) + parseFloat(styles.marginBottom);
|
|
955
|
-
var y = parseFloat(styles.marginLeft) + parseFloat(styles.marginRight);
|
|
956
|
-
var result = { width: element.offsetWidth + y, height: element.offsetHeight + x };
|
|
957
|
-
|
|
958
|
-
// reset element styles
|
|
959
|
-
element.style.display = _display;element.style.visibility = _visibility;
|
|
960
|
-
return result;
|
|
722
|
+
order.forEach(function (direction) {
|
|
723
|
+
data.offsets.popper = Object.assign(popper, check[direction]());
|
|
724
|
+
});
|
|
725
|
+
return data;
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* Modifier used to make sure the popper is always near its reference
|
|
730
|
+
* @method
|
|
731
|
+
* @memberof Popper.modifiers
|
|
732
|
+
* @argument {Object} data - The data object generated by _update method
|
|
733
|
+
* @returns {Object} The data object, properly modified
|
|
734
|
+
*/
|
|
735
|
+
Popper.prototype.modifiers.keepTogether = function (data) {
|
|
736
|
+
var popper = getPopperClientRect(data.offsets.popper);
|
|
737
|
+
var reference = data.offsets.reference;
|
|
738
|
+
var f = Math.floor;
|
|
739
|
+
if (popper.right < f(reference.left)) {
|
|
740
|
+
data.offsets.popper.left = f(reference.left) - popper.width;
|
|
961
741
|
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
* Get the opposite placement of the given one/
|
|
965
|
-
* @function
|
|
966
|
-
* @ignore
|
|
967
|
-
* @argument {String} placement
|
|
968
|
-
* @returns {String} flipped placement
|
|
969
|
-
*/
|
|
970
|
-
function getOppositePlacement(placement) {
|
|
971
|
-
var hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' };
|
|
972
|
-
return placement.replace(/left|right|bottom|top/g, function (matched) {
|
|
973
|
-
return hash[matched];
|
|
974
|
-
});
|
|
742
|
+
if (popper.left > f(reference.right)) {
|
|
743
|
+
data.offsets.popper.left = f(reference.right);
|
|
975
744
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
* Given the popper offsets, generate an output similar to getBoundingClientRect
|
|
979
|
-
* @function
|
|
980
|
-
* @ignore
|
|
981
|
-
* @argument {Object} popperOffsets
|
|
982
|
-
* @returns {Object} ClientRect like output
|
|
983
|
-
*/
|
|
984
|
-
function getPopperClientRect(popperOffsets) {
|
|
985
|
-
var offsets = Object.assign({}, popperOffsets);
|
|
986
|
-
offsets.right = offsets.left + offsets.width;
|
|
987
|
-
offsets.bottom = offsets.top + offsets.height;
|
|
988
|
-
return offsets;
|
|
745
|
+
if (popper.bottom < f(reference.top)) {
|
|
746
|
+
data.offsets.popper.top = f(reference.top) - popper.height;
|
|
989
747
|
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
* Given an array and the key to find, returns its index
|
|
993
|
-
* @function
|
|
994
|
-
* @ignore
|
|
995
|
-
* @argument {Array} arr
|
|
996
|
-
* @argument keyToFind
|
|
997
|
-
* @returns index or null
|
|
998
|
-
*/
|
|
999
|
-
function getArrayKeyIndex(arr, keyToFind) {
|
|
1000
|
-
var i = 0,
|
|
1001
|
-
key;
|
|
1002
|
-
for (key in arr) {
|
|
1003
|
-
if (arr[key] === keyToFind) {
|
|
1004
|
-
return i;
|
|
1005
|
-
}
|
|
1006
|
-
i++;
|
|
1007
|
-
}
|
|
1008
|
-
return null;
|
|
748
|
+
if (popper.top > f(reference.bottom)) {
|
|
749
|
+
data.offsets.popper.top = f(reference.bottom);
|
|
1009
750
|
}
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
751
|
+
return data;
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Modifier used to flip the placement of the popper when the latter is starting overlapping its reference element.
|
|
756
|
+
* Requires the `preventOverflow` modifier before it in order to work.
|
|
757
|
+
* **NOTE:** This modifier will run all its previous modifiers everytime it tries to flip the popper!
|
|
758
|
+
* @method
|
|
759
|
+
* @memberof Popper.modifiers
|
|
760
|
+
* @argument {Object} data - The data object generated by _update method
|
|
761
|
+
* @returns {Object} The data object, properly modified
|
|
762
|
+
*/
|
|
763
|
+
Popper.prototype.modifiers.flip = function (data) {
|
|
764
|
+
// check if preventOverflow is in the list of modifiers before the flip modifier.
|
|
765
|
+
// otherwise flip would not work as expected.
|
|
766
|
+
if (!this.isModifierRequired(this.modifiers.flip, this.modifiers.preventOverflow)) {
|
|
767
|
+
console.warn('WARNING: preventOverflow modifier is required by flip modifier in order to work, be sure to include it before flip!');
|
|
768
|
+
return data;
|
|
1022
769
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
* @function
|
|
1027
|
-
* @ignore
|
|
1028
|
-
* @argument {Element} element
|
|
1029
|
-
* @returns {Element} offset parent
|
|
1030
|
-
*/
|
|
1031
|
-
function getOffsetParent(element) {
|
|
1032
|
-
// NOTE: 1 DOM access here
|
|
1033
|
-
var offsetParent = element.offsetParent;
|
|
1034
|
-
return offsetParent === root.document.body || !offsetParent ? root.document.documentElement : offsetParent;
|
|
770
|
+
if (data.flipped && data.placement === data._originalPlacement) {
|
|
771
|
+
// seems like flip is trying to loop, probably there's not enough space on any of the flippable sides
|
|
772
|
+
return data;
|
|
1035
773
|
}
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
function getScrollParent(element) {
|
|
1045
|
-
var parent = element.parentNode;
|
|
1046
|
-
|
|
1047
|
-
if (!parent) {
|
|
1048
|
-
return element;
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
if (parent === root.document) {
|
|
1052
|
-
// Firefox puts the scrollTOp value on `documentElement` instead of `body`, we then check which of them is
|
|
1053
|
-
// greater than 0 and return the proper element
|
|
1054
|
-
if (root.document.body.scrollTop || root.document.body.scrollLeft) {
|
|
1055
|
-
return root.document.body;
|
|
1056
|
-
} else {
|
|
1057
|
-
return root.document.documentElement;
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
// Firefox want us to check `-x` and `-y` variations as well
|
|
1062
|
-
if (['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow')) !== -1 || ['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow-x')) !== -1 || ['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow-y')) !== -1) {
|
|
1063
|
-
// If the detected scrollParent is body, we perform an additional check on its parentNode
|
|
1064
|
-
// in this way we'll get body if the browser is Chrome-ish, or documentElement otherwise
|
|
1065
|
-
// fixes issue #65
|
|
1066
|
-
return parent;
|
|
1067
|
-
}
|
|
1068
|
-
return getScrollParent(element.parentNode);
|
|
774
|
+
var placement = data.placement.split('-')[0];
|
|
775
|
+
var placementOpposite = getOppositePlacement(placement);
|
|
776
|
+
var variation = data.placement.split('-')[1] || '';
|
|
777
|
+
var flipOrder = [];
|
|
778
|
+
if (this._options.flipBehavior === 'flip') {
|
|
779
|
+
flipOrder = [placement, placementOpposite];
|
|
780
|
+
} else {
|
|
781
|
+
flipOrder = this._options.flipBehavior;
|
|
1069
782
|
}
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
783
|
+
flipOrder.forEach(function (step, index) {
|
|
784
|
+
if (placement !== step || flipOrder.length === index + 1) {
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
placement = data.placement.split('-')[0];
|
|
788
|
+
placementOpposite = getOppositePlacement(placement);
|
|
789
|
+
var popperOffsets = getPopperClientRect(data.offsets.popper);
|
|
790
|
+
|
|
791
|
+
// this boolean is used to distinguish right and bottom from top and left
|
|
792
|
+
// they need different computations to get flipped
|
|
793
|
+
var a = ['right', 'bottom'].indexOf(placement) !== -1;
|
|
794
|
+
|
|
795
|
+
// using Math.floor because the reference offsets may contain decimals we are not going to consider here
|
|
796
|
+
if (a && Math.floor(data.offsets.reference[placement]) > Math.floor(popperOffsets[placementOpposite]) || !a && Math.floor(data.offsets.reference[placement]) < Math.floor(popperOffsets[placementOpposite])) {
|
|
797
|
+
// we'll use this boolean to detect any flip loop
|
|
798
|
+
data.flipped = true;
|
|
799
|
+
data.placement = flipOrder[index + 1];
|
|
800
|
+
if (variation) {
|
|
801
|
+
data.placement += '-' + variation;
|
|
1085
802
|
}
|
|
1086
|
-
|
|
803
|
+
data.offsets.popper = this._getOffsets(this._popper, this._reference, data.placement).popper;
|
|
804
|
+
data = this.runModifiers(data, this._options.modifiers, this._flip);
|
|
805
|
+
}
|
|
806
|
+
}.bind(this));
|
|
807
|
+
return data;
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Modifier used to add an offset to the popper, useful if you more granularity positioning your popper.
|
|
812
|
+
* The offsets will shift the popper on the side of its reference element.
|
|
813
|
+
* @method
|
|
814
|
+
* @memberof Popper.modifiers
|
|
815
|
+
* @argument {Object} data - The data object generated by _update method
|
|
816
|
+
* @returns {Object} The data object, properly modified
|
|
817
|
+
*/
|
|
818
|
+
Popper.prototype.modifiers.offset = function (data) {
|
|
819
|
+
var offset = this._options.offset;
|
|
820
|
+
var popper = data.offsets.popper;
|
|
821
|
+
if (data.placement.indexOf('left') !== -1) {
|
|
822
|
+
popper.top -= offset;
|
|
823
|
+
} else if (data.placement.indexOf('right') !== -1) {
|
|
824
|
+
popper.top += offset;
|
|
825
|
+
} else if (data.placement.indexOf('top') !== -1) {
|
|
826
|
+
popper.left -= offset;
|
|
827
|
+
} else if (data.placement.indexOf('bottom') !== -1) {
|
|
828
|
+
popper.left += offset;
|
|
1087
829
|
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
element.style[prop] = styles[prop] + unit;
|
|
1107
|
-
});
|
|
830
|
+
return data;
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* Modifier used to move the arrows on the edge of the popper to make sure them are always between the popper and the reference element
|
|
835
|
+
* It will use the CSS outer size of the arrow element to know how many pixels of conjuction are needed
|
|
836
|
+
* @method
|
|
837
|
+
* @memberof Popper.modifiers
|
|
838
|
+
* @argument {Object} data - The data object generated by _update method
|
|
839
|
+
* @returns {Object} The data object, properly modified
|
|
840
|
+
*/
|
|
841
|
+
Popper.prototype.modifiers.arrow = function (data) {
|
|
842
|
+
var arrow = this._options.arrowElement;
|
|
843
|
+
var arrowOffset = this._options.arrowOffset;
|
|
844
|
+
|
|
845
|
+
// if the arrowElement is a string, suppose it's a CSS selector
|
|
846
|
+
if (typeof arrow === 'string') {
|
|
847
|
+
arrow = this._popper.querySelector(arrow);
|
|
1108
848
|
}
|
|
1109
849
|
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
* @ignore
|
|
1114
|
-
* @argument {*} functionToCheck - variable to check
|
|
1115
|
-
* @returns {Boolean} answer to: is a function?
|
|
1116
|
-
*/
|
|
1117
|
-
function isFunction(functionToCheck) {
|
|
1118
|
-
var getType = {};
|
|
1119
|
-
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
|
|
850
|
+
// if arrow element is not found, don't run the modifier
|
|
851
|
+
if (!arrow) {
|
|
852
|
+
return data;
|
|
1120
853
|
}
|
|
1121
854
|
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
* @param {Element} element
|
|
1127
|
-
* @return {Object} position - Coordinates of the element and its `scrollTop`
|
|
1128
|
-
*/
|
|
1129
|
-
function getOffsetRect(element) {
|
|
1130
|
-
var elementRect = {
|
|
1131
|
-
width: element.offsetWidth,
|
|
1132
|
-
height: element.offsetHeight,
|
|
1133
|
-
left: element.offsetLeft,
|
|
1134
|
-
top: element.offsetTop
|
|
1135
|
-
};
|
|
1136
|
-
|
|
1137
|
-
elementRect.right = elementRect.left + elementRect.width;
|
|
1138
|
-
elementRect.bottom = elementRect.top + elementRect.height;
|
|
1139
|
-
|
|
1140
|
-
// position
|
|
1141
|
-
return elementRect;
|
|
855
|
+
// the arrow element must be child of its popper
|
|
856
|
+
if (!this._popper.contains(arrow)) {
|
|
857
|
+
console.warn('WARNING: `arrowElement` must be child of its popper element!');
|
|
858
|
+
return data;
|
|
1142
859
|
}
|
|
1143
860
|
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
* @param {HTMLElement} element
|
|
1149
|
-
* @return {Object} client rect
|
|
1150
|
-
*/
|
|
1151
|
-
function getBoundingClientRect(element) {
|
|
1152
|
-
var rect = element.getBoundingClientRect();
|
|
1153
|
-
|
|
1154
|
-
// whether the IE version is lower than 11
|
|
1155
|
-
var isIE = navigator.userAgent.indexOf("MSIE") != -1;
|
|
1156
|
-
|
|
1157
|
-
// fix ie document bounding top always 0 bug
|
|
1158
|
-
var rectTop = isIE && element.tagName === 'HTML' ? -element.scrollTop : rect.top;
|
|
1159
|
-
|
|
1160
|
-
return {
|
|
1161
|
-
left: rect.left,
|
|
1162
|
-
top: rectTop,
|
|
1163
|
-
right: rect.right,
|
|
1164
|
-
bottom: rect.bottom,
|
|
1165
|
-
width: rect.right - rect.left,
|
|
1166
|
-
height: rect.bottom - rectTop
|
|
1167
|
-
};
|
|
861
|
+
// arrow depends on keepTogether in order to work
|
|
862
|
+
if (!this.isModifierRequired(this.modifiers.arrow, this.modifiers.keepTogether)) {
|
|
863
|
+
console.warn('WARNING: keepTogether modifier is required by arrow modifier in order to work, be sure to include it before arrow!');
|
|
864
|
+
return data;
|
|
1168
865
|
}
|
|
866
|
+
var arrowStyle = {};
|
|
867
|
+
var placement = data.placement.split('-')[0];
|
|
868
|
+
var popper = getPopperClientRect(data.offsets.popper);
|
|
869
|
+
var reference = data.offsets.reference;
|
|
870
|
+
var isVertical = ['left', 'right'].indexOf(placement) !== -1;
|
|
871
|
+
var len = isVertical ? 'height' : 'width';
|
|
872
|
+
var side = isVertical ? 'top' : 'left';
|
|
873
|
+
var translate = isVertical ? 'translateY' : 'translateX';
|
|
874
|
+
var altSide = isVertical ? 'left' : 'top';
|
|
875
|
+
var opSide = isVertical ? 'bottom' : 'right';
|
|
876
|
+
var arrowSize = getOuterSizes(arrow)[len];
|
|
1169
877
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
* @ignore
|
|
1174
|
-
* @param {HTMLElement} element
|
|
1175
|
-
* @param {HTMLElement} parent
|
|
1176
|
-
* @return {Object} rect
|
|
1177
|
-
*/
|
|
1178
|
-
function getOffsetRectRelativeToCustomParent(element, parent, fixed) {
|
|
1179
|
-
var elementRect = getBoundingClientRect(element);
|
|
1180
|
-
var parentRect = getBoundingClientRect(parent);
|
|
1181
|
-
|
|
1182
|
-
if (fixed) {
|
|
1183
|
-
var scrollParent = getScrollParent(parent);
|
|
1184
|
-
parentRect.top += scrollParent.scrollTop;
|
|
1185
|
-
parentRect.bottom += scrollParent.scrollTop;
|
|
1186
|
-
parentRect.left += scrollParent.scrollLeft;
|
|
1187
|
-
parentRect.right += scrollParent.scrollLeft;
|
|
1188
|
-
}
|
|
878
|
+
//
|
|
879
|
+
// extends keepTogether behavior making sure the popper and its reference have enough pixels in conjuction
|
|
880
|
+
//
|
|
1189
881
|
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
};
|
|
1198
|
-
return rect;
|
|
882
|
+
// top/left side
|
|
883
|
+
if (reference[opSide] - arrowSize < popper[side]) {
|
|
884
|
+
data.offsets.popper[side] -= popper[side] - (reference[opSide] - arrowSize);
|
|
885
|
+
}
|
|
886
|
+
// bottom/right side
|
|
887
|
+
if (reference[side] + arrowSize > popper[opSide]) {
|
|
888
|
+
data.offsets.popper[side] += reference[side] + arrowSize - popper[opSide];
|
|
1199
889
|
}
|
|
1200
890
|
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
891
|
+
// compute center of the popper
|
|
892
|
+
var center = reference[side] + (arrowOffset || reference[len] / 2 - arrowSize / 2);
|
|
893
|
+
var sideValue = center - popper[side];
|
|
894
|
+
|
|
895
|
+
// prevent arrow from being placed not contiguously to its popper
|
|
896
|
+
sideValue = Math.max(Math.min(popper[len] - arrowSize - 8, sideValue), 8);
|
|
897
|
+
arrowStyle[side] = sideValue;
|
|
898
|
+
arrowStyle[altSide] = ''; // make sure to remove any old style from the arrow
|
|
899
|
+
|
|
900
|
+
data.offsets.arrow = arrowStyle;
|
|
901
|
+
data.arrowElement = arrow;
|
|
902
|
+
return data;
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
//
|
|
906
|
+
// Helpers
|
|
907
|
+
//
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* Get the outer sizes of the given element (offset size + margins)
|
|
911
|
+
* @function
|
|
912
|
+
* @ignore
|
|
913
|
+
* @argument {Element} element
|
|
914
|
+
* @returns {Object} object containing width and height properties
|
|
915
|
+
*/
|
|
916
|
+
function getOuterSizes(element) {
|
|
917
|
+
// NOTE: 1 DOM access here
|
|
918
|
+
var _display = element.style.display,
|
|
919
|
+
_visibility = element.style.visibility;
|
|
920
|
+
element.style.display = 'block';
|
|
921
|
+
element.style.visibility = 'hidden';
|
|
922
|
+
var calcWidthToForceRepaint = element.offsetWidth;
|
|
923
|
+
|
|
924
|
+
// original method
|
|
925
|
+
var styles = root.getComputedStyle(element);
|
|
926
|
+
var x = parseFloat(styles.marginTop) + parseFloat(styles.marginBottom);
|
|
927
|
+
var y = parseFloat(styles.marginLeft) + parseFloat(styles.marginRight);
|
|
928
|
+
var result = {
|
|
929
|
+
width: element.offsetWidth + y,
|
|
930
|
+
height: element.offsetHeight + x
|
|
931
|
+
};
|
|
1210
932
|
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
933
|
+
// reset element styles
|
|
934
|
+
element.style.display = _display;
|
|
935
|
+
element.style.visibility = _visibility;
|
|
936
|
+
return result;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Get the opposite placement of the given one/
|
|
941
|
+
* @function
|
|
942
|
+
* @ignore
|
|
943
|
+
* @argument {String} placement
|
|
944
|
+
* @returns {String} flipped placement
|
|
945
|
+
*/
|
|
946
|
+
function getOppositePlacement(placement) {
|
|
947
|
+
var hash = {
|
|
948
|
+
left: 'right',
|
|
949
|
+
right: 'left',
|
|
950
|
+
bottom: 'top',
|
|
951
|
+
top: 'bottom'
|
|
952
|
+
};
|
|
953
|
+
return placement.replace(/left|right|bottom|top/g, function (matched) {
|
|
954
|
+
return hash[matched];
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
/**
|
|
959
|
+
* Given the popper offsets, generate an output similar to getBoundingClientRect
|
|
960
|
+
* @function
|
|
961
|
+
* @ignore
|
|
962
|
+
* @argument {Object} popperOffsets
|
|
963
|
+
* @returns {Object} ClientRect like output
|
|
964
|
+
*/
|
|
965
|
+
function getPopperClientRect(popperOffsets) {
|
|
966
|
+
var offsets = Object.assign({}, popperOffsets);
|
|
967
|
+
offsets.right = offsets.left + offsets.width;
|
|
968
|
+
offsets.bottom = offsets.top + offsets.height;
|
|
969
|
+
return offsets;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
/**
|
|
973
|
+
* Given an array and the key to find, returns its index
|
|
974
|
+
* @function
|
|
975
|
+
* @ignore
|
|
976
|
+
* @argument {Array} arr
|
|
977
|
+
* @argument keyToFind
|
|
978
|
+
* @returns index or null
|
|
979
|
+
*/
|
|
980
|
+
function getArrayKeyIndex(arr, keyToFind) {
|
|
981
|
+
var i = 0,
|
|
982
|
+
key;
|
|
983
|
+
for (key in arr) {
|
|
984
|
+
if (arr[key] === keyToFind) {
|
|
985
|
+
return i;
|
|
986
|
+
}
|
|
987
|
+
i++;
|
|
1218
988
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
989
|
+
return null;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Get CSS computed property of the given element
|
|
994
|
+
* @function
|
|
995
|
+
* @ignore
|
|
996
|
+
* @argument {Eement} element
|
|
997
|
+
* @argument {String} property
|
|
998
|
+
*/
|
|
999
|
+
function getStyleComputedProperty(element, property) {
|
|
1000
|
+
// NOTE: 1 DOM access here
|
|
1001
|
+
var css = root.getComputedStyle(element, null);
|
|
1002
|
+
return css[property];
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* Returns the offset parent of the given element
|
|
1007
|
+
* @function
|
|
1008
|
+
* @ignore
|
|
1009
|
+
* @argument {Element} element
|
|
1010
|
+
* @returns {Element} offset parent
|
|
1011
|
+
*/
|
|
1012
|
+
function getOffsetParent(element) {
|
|
1013
|
+
// NOTE: 1 DOM access here
|
|
1014
|
+
var offsetParent = element.offsetParent;
|
|
1015
|
+
return offsetParent === root.document.body || !offsetParent ? root.document.documentElement : offsetParent;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* Returns the scrolling parent of the given element
|
|
1020
|
+
* @function
|
|
1021
|
+
* @ignore
|
|
1022
|
+
* @argument {Element} element
|
|
1023
|
+
* @returns {Element} offset parent
|
|
1024
|
+
*/
|
|
1025
|
+
function getScrollParent(element) {
|
|
1026
|
+
var parent = element.parentNode;
|
|
1027
|
+
if (!parent) {
|
|
1028
|
+
return element;
|
|
1029
|
+
}
|
|
1030
|
+
if (parent === root.document) {
|
|
1031
|
+
// Firefox puts the scrollTOp value on `documentElement` instead of `body`, we then check which of them is
|
|
1032
|
+
// greater than 0 and return the proper element
|
|
1033
|
+
if (root.document.body.scrollTop || root.document.body.scrollLeft) {
|
|
1034
|
+
return root.document.body;
|
|
1035
|
+
} else {
|
|
1036
|
+
return root.document.documentElement;
|
|
1037
|
+
}
|
|
1258
1038
|
}
|
|
1259
1039
|
|
|
1260
|
-
|
|
1040
|
+
// Firefox want us to check `-x` and `-y` variations as well
|
|
1041
|
+
if (['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow')) !== -1 || ['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow-x')) !== -1 || ['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow-y')) !== -1) {
|
|
1042
|
+
// If the detected scrollParent is body, we perform an additional check on its parentNode
|
|
1043
|
+
// in this way we'll get body if the browser is Chrome-ish, or documentElement otherwise
|
|
1044
|
+
// fixes issue #65
|
|
1045
|
+
return parent;
|
|
1046
|
+
}
|
|
1047
|
+
return getScrollParent(element.parentNode);
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
/**
|
|
1051
|
+
* Check if the given element is fixed or is inside a fixed parent
|
|
1052
|
+
* @function
|
|
1053
|
+
* @ignore
|
|
1054
|
+
* @argument {Element} element
|
|
1055
|
+
* @argument {Element} customContainer
|
|
1056
|
+
* @returns {Boolean} answer to "isFixed?"
|
|
1057
|
+
*/
|
|
1058
|
+
function isFixed(element) {
|
|
1059
|
+
if (element === root.document.body) {
|
|
1060
|
+
return false;
|
|
1061
|
+
}
|
|
1062
|
+
if (getStyleComputedProperty(element, 'position') === 'fixed') {
|
|
1063
|
+
return true;
|
|
1064
|
+
}
|
|
1065
|
+
return element.parentNode ? isFixed(element.parentNode) : element;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
/**
|
|
1069
|
+
* Set the style to the given popper
|
|
1070
|
+
* @function
|
|
1071
|
+
* @ignore
|
|
1072
|
+
* @argument {Element} element - Element to apply the style to
|
|
1073
|
+
* @argument {Object} styles - Object with a list of properties and values which will be applied to the element
|
|
1074
|
+
*/
|
|
1075
|
+
function setStyle(element, styles) {
|
|
1076
|
+
function is_numeric(n) {
|
|
1077
|
+
return n !== '' && !isNaN(parseFloat(n)) && isFinite(n);
|
|
1078
|
+
}
|
|
1079
|
+
Object.keys(styles).forEach(function (prop) {
|
|
1080
|
+
var unit = '';
|
|
1081
|
+
// add unit if the value is numeric and is one of the following
|
|
1082
|
+
if (['width', 'height', 'top', 'right', 'bottom', 'left'].indexOf(prop) !== -1 && is_numeric(styles[prop])) {
|
|
1083
|
+
unit = 'px';
|
|
1084
|
+
}
|
|
1085
|
+
element.style[prop] = styles[prop] + unit;
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
/**
|
|
1090
|
+
* Check if the given variable is a function
|
|
1091
|
+
* @function
|
|
1092
|
+
* @ignore
|
|
1093
|
+
* @argument {*} functionToCheck - variable to check
|
|
1094
|
+
* @returns {Boolean} answer to: is a function?
|
|
1095
|
+
*/
|
|
1096
|
+
function isFunction(functionToCheck) {
|
|
1097
|
+
var getType = {};
|
|
1098
|
+
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* Get the position of the given element, relative to its offset parent
|
|
1103
|
+
* @function
|
|
1104
|
+
* @ignore
|
|
1105
|
+
* @param {Element} element
|
|
1106
|
+
* @return {Object} position - Coordinates of the element and its `scrollTop`
|
|
1107
|
+
*/
|
|
1108
|
+
function getOffsetRect(element) {
|
|
1109
|
+
var elementRect = {
|
|
1110
|
+
width: element.offsetWidth,
|
|
1111
|
+
height: element.offsetHeight,
|
|
1112
|
+
left: element.offsetLeft,
|
|
1113
|
+
top: element.offsetTop
|
|
1114
|
+
};
|
|
1115
|
+
elementRect.right = elementRect.left + elementRect.width;
|
|
1116
|
+
elementRect.bottom = elementRect.top + elementRect.height;
|
|
1117
|
+
|
|
1118
|
+
// position
|
|
1119
|
+
return elementRect;
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* Get bounding client rect of given element
|
|
1124
|
+
* @function
|
|
1125
|
+
* @ignore
|
|
1126
|
+
* @param {HTMLElement} element
|
|
1127
|
+
* @return {Object} client rect
|
|
1128
|
+
*/
|
|
1129
|
+
function getBoundingClientRect(element) {
|
|
1130
|
+
var rect = element.getBoundingClientRect();
|
|
1131
|
+
|
|
1132
|
+
// whether the IE version is lower than 11
|
|
1133
|
+
var isIE = navigator.userAgent.indexOf("MSIE") != -1;
|
|
1134
|
+
|
|
1135
|
+
// fix ie document bounding top always 0 bug
|
|
1136
|
+
var rectTop = isIE && element.tagName === 'HTML' ? -element.scrollTop : rect.top;
|
|
1137
|
+
return {
|
|
1138
|
+
left: rect.left,
|
|
1139
|
+
top: rectTop,
|
|
1140
|
+
right: rect.right,
|
|
1141
|
+
bottom: rect.bottom,
|
|
1142
|
+
width: rect.right - rect.left,
|
|
1143
|
+
height: rect.bottom - rectTop
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* Given an element and one of its parents, return the offset
|
|
1149
|
+
* @function
|
|
1150
|
+
* @ignore
|
|
1151
|
+
* @param {HTMLElement} element
|
|
1152
|
+
* @param {HTMLElement} parent
|
|
1153
|
+
* @return {Object} rect
|
|
1154
|
+
*/
|
|
1155
|
+
function getOffsetRectRelativeToCustomParent(element, parent, fixed) {
|
|
1156
|
+
var elementRect = getBoundingClientRect(element);
|
|
1157
|
+
var parentRect = getBoundingClientRect(parent);
|
|
1158
|
+
if (fixed) {
|
|
1159
|
+
var scrollParent = getScrollParent(parent);
|
|
1160
|
+
parentRect.top += scrollParent.scrollTop;
|
|
1161
|
+
parentRect.bottom += scrollParent.scrollTop;
|
|
1162
|
+
parentRect.left += scrollParent.scrollLeft;
|
|
1163
|
+
parentRect.right += scrollParent.scrollLeft;
|
|
1164
|
+
}
|
|
1165
|
+
var rect = {
|
|
1166
|
+
top: elementRect.top - parentRect.top,
|
|
1167
|
+
left: elementRect.left - parentRect.left,
|
|
1168
|
+
bottom: elementRect.top - parentRect.top + elementRect.height,
|
|
1169
|
+
right: elementRect.left - parentRect.left + elementRect.width,
|
|
1170
|
+
width: elementRect.width,
|
|
1171
|
+
height: elementRect.height
|
|
1172
|
+
};
|
|
1173
|
+
return rect;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
/**
|
|
1177
|
+
* Get the prefixed supported property name
|
|
1178
|
+
* @function
|
|
1179
|
+
* @ignore
|
|
1180
|
+
* @argument {String} property (camelCase)
|
|
1181
|
+
* @returns {String} prefixed property (camelCase)
|
|
1182
|
+
*/
|
|
1183
|
+
function getSupportedPropertyName(property) {
|
|
1184
|
+
var prefixes = ['', 'ms', 'webkit', 'moz', 'o'];
|
|
1185
|
+
for (var i = 0; i < prefixes.length; i++) {
|
|
1186
|
+
var toCheck = prefixes[i] ? prefixes[i] + property.charAt(0).toUpperCase() + property.slice(1) : property;
|
|
1187
|
+
if (typeof root.document.body.style[toCheck] !== 'undefined') {
|
|
1188
|
+
return toCheck;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
return null;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
/**
|
|
1195
|
+
* The Object.assign() method is used to copy the values of all enumerable own properties from one or more source
|
|
1196
|
+
* objects to a target object. It will return the target object.
|
|
1197
|
+
* This polyfill doesn't support symbol properties, since ES5 doesn't have symbols anyway
|
|
1198
|
+
* Source: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
|
|
1199
|
+
* @function
|
|
1200
|
+
* @ignore
|
|
1201
|
+
*/
|
|
1202
|
+
if (!Object.assign) {
|
|
1203
|
+
Object.defineProperty(Object, 'assign', {
|
|
1204
|
+
enumerable: false,
|
|
1205
|
+
configurable: true,
|
|
1206
|
+
writable: true,
|
|
1207
|
+
value: function value(target) {
|
|
1208
|
+
if (target === undefined || target === null) {
|
|
1209
|
+
throw new TypeError('Cannot convert first argument to object');
|
|
1210
|
+
}
|
|
1211
|
+
var to = Object(target);
|
|
1212
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
1213
|
+
var nextSource = arguments[i];
|
|
1214
|
+
if (nextSource === undefined || nextSource === null) {
|
|
1215
|
+
continue;
|
|
1216
|
+
}
|
|
1217
|
+
nextSource = Object(nextSource);
|
|
1218
|
+
var keysArray = Object.keys(nextSource);
|
|
1219
|
+
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
|
|
1220
|
+
var nextKey = keysArray[nextIndex];
|
|
1221
|
+
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
|
|
1222
|
+
if (desc !== undefined && desc.enumerable) {
|
|
1223
|
+
to[nextKey] = nextSource[nextKey];
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
return to;
|
|
1228
|
+
}
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
return Popper;
|
|
1261
1232
|
});
|