cy-element-ui 1.0.3 → 1.0.5

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.
Files changed (416) hide show
  1. package/README.md +163 -59
  2. package/lib/alert.js +211 -203
  3. package/lib/aside.js +29 -29
  4. package/lib/autocomplete.js +4615 -483
  5. package/lib/avatar.js +152 -126
  6. package/lib/backtop.js +117 -125
  7. package/lib/badge.js +128 -134
  8. package/lib/breadcrumb-item.js +146 -122
  9. package/lib/breadcrumb.js +97 -96
  10. package/lib/button-group.js +68 -65
  11. package/lib/button.js +67 -87
  12. package/lib/calendar.js +2475 -603
  13. package/lib/card.js +101 -100
  14. package/lib/carousel-item.js +854 -210
  15. package/lib/carousel.js +575 -408
  16. package/lib/cascader-panel.js +3546 -1153
  17. package/lib/cascader.js +7376 -970
  18. package/lib/checkbox-button.js +337 -290
  19. package/lib/checkbox-group.js +176 -105
  20. package/lib/checkbox.js +240 -220
  21. package/lib/col.js +113 -68
  22. package/lib/collapse-item.js +1228 -225
  23. package/lib/collapse.js +163 -123
  24. package/lib/color-picker.js +5223 -1251
  25. package/lib/container.js +98 -88
  26. package/lib/date-picker.js +8396 -3945
  27. package/lib/descriptions-item.js +53 -32
  28. package/lib/descriptions.js +697 -334
  29. package/lib/dialog.js +1725 -247
  30. package/lib/directives/mousewheel.js +14 -20
  31. package/lib/directives/repeat-click.js +27 -30
  32. package/lib/divider.js +38 -45
  33. package/lib/drawer.js +1032 -238
  34. package/lib/dropdown-item.js +159 -111
  35. package/lib/dropdown-menu.js +2445 -117
  36. package/lib/dropdown.js +1675 -366
  37. package/lib/element-ui.common.js +49110 -39985
  38. package/lib/empty.js +1084 -203
  39. package/lib/fileUpload.js +3900 -0
  40. package/lib/footer.js +29 -29
  41. package/lib/form-item.js +1236 -467
  42. package/lib/form.js +326 -258
  43. package/lib/header.js +80 -80
  44. package/lib/icon.js +71 -68
  45. package/lib/image.js +2389 -743
  46. package/lib/index.js +1 -1
  47. package/lib/infinite-scroll.js +814 -150
  48. package/lib/input-number.js +2181 -444
  49. package/lib/input.js +1197 -517
  50. package/lib/link.js +117 -135
  51. package/lib/loading.js +1130 -363
  52. package/lib/locale/format.js +38 -49
  53. package/lib/locale/index.js +38 -52
  54. package/lib/locale/lang/af-ZA.js +130 -123
  55. package/lib/locale/lang/ar.js +123 -122
  56. package/lib/locale/lang/az.js +122 -121
  57. package/lib/locale/lang/bg.js +133 -123
  58. package/lib/locale/lang/bn.js +121 -121
  59. package/lib/locale/lang/ca.js +123 -122
  60. package/lib/locale/lang/cs-CZ.js +127 -125
  61. package/lib/locale/lang/da.js +124 -122
  62. package/lib/locale/lang/de.js +126 -124
  63. package/lib/locale/lang/ee.js +125 -123
  64. package/lib/locale/lang/el.js +125 -123
  65. package/lib/locale/lang/en.js +127 -123
  66. package/lib/locale/lang/eo.js +125 -123
  67. package/lib/locale/lang/es.js +123 -122
  68. package/lib/locale/lang/eu.js +128 -123
  69. package/lib/locale/lang/fa.js +125 -123
  70. package/lib/locale/lang/fi.js +125 -123
  71. package/lib/locale/lang/fr.js +125 -122
  72. package/lib/locale/lang/he.js +130 -123
  73. package/lib/locale/lang/hr.js +128 -123
  74. package/lib/locale/lang/hu.js +124 -122
  75. package/lib/locale/lang/hy-AM.js +125 -123
  76. package/lib/locale/lang/id.js +124 -123
  77. package/lib/locale/lang/is.js +124 -123
  78. package/lib/locale/lang/it.js +123 -122
  79. package/lib/locale/lang/ja.js +125 -123
  80. package/lib/locale/lang/kg.js +125 -123
  81. package/lib/locale/lang/km.js +124 -123
  82. package/lib/locale/lang/ko.js +125 -123
  83. package/lib/locale/lang/ku.js +125 -123
  84. package/lib/locale/lang/kz.js +125 -123
  85. package/lib/locale/lang/lo-LA.js +121 -121
  86. package/lib/locale/lang/lt.js +125 -123
  87. package/lib/locale/lang/lv.js +125 -123
  88. package/lib/locale/lang/mn.js +125 -123
  89. package/lib/locale/lang/ms.js +123 -122
  90. package/lib/locale/lang/nb-NO.js +123 -122
  91. package/lib/locale/lang/nl.js +125 -123
  92. package/lib/locale/lang/pl.js +125 -123
  93. package/lib/locale/lang/pt-br.js +124 -123
  94. package/lib/locale/lang/pt.js +133 -123
  95. package/lib/locale/lang/ro.js +125 -123
  96. package/lib/locale/lang/ru-RU.js +124 -123
  97. package/lib/locale/lang/si.js +127 -123
  98. package/lib/locale/lang/sk.js +126 -125
  99. package/lib/locale/lang/sl.js +125 -123
  100. package/lib/locale/lang/sr-Latn.js +124 -123
  101. package/lib/locale/lang/sr.js +128 -123
  102. package/lib/locale/lang/sv-SE.js +128 -123
  103. package/lib/locale/lang/sw.js +127 -123
  104. package/lib/locale/lang/ta.js +130 -122
  105. package/lib/locale/lang/th.js +127 -123
  106. package/lib/locale/lang/tk.js +129 -123
  107. package/lib/locale/lang/tr-TR.js +125 -123
  108. package/lib/locale/lang/ua.js +124 -123
  109. package/lib/locale/lang/ug-CN.js +124 -123
  110. package/lib/locale/lang/uz-UZ.js +124 -123
  111. package/lib/locale/lang/vi.js +124 -123
  112. package/lib/locale/lang/zh-CN.js +124 -123
  113. package/lib/locale/lang/zh-TW.js +128 -123
  114. package/lib/main.js +23 -21
  115. package/lib/menu-item-group.js +105 -111
  116. package/lib/menu-item.js +3558 -253
  117. package/lib/menu.js +1680 -528
  118. package/lib/message-box.js +3427 -684
  119. package/lib/message.js +1677 -229
  120. package/lib/mixins/emitter.js +28 -30
  121. package/lib/mixins/focus.js +10 -11
  122. package/lib/mixins/locale.js +12 -14
  123. package/lib/mixins/migrating.js +38 -45
  124. package/lib/notification.js +1707 -269
  125. package/lib/option-group.js +190 -139
  126. package/lib/option.js +949 -196
  127. package/lib/page-header.js +964 -42
  128. package/lib/pagination.js +6947 -641
  129. package/lib/popconfirm.js +3951 -223
  130. package/lib/popover.js +3247 -369
  131. package/lib/progress.js +254 -244
  132. package/lib/radio-button.js +259 -226
  133. package/lib/radio-group.js +249 -186
  134. package/lib/radio.js +263 -253
  135. package/lib/rate.js +1399 -420
  136. package/lib/result.js +183 -227
  137. package/lib/row.js +58 -41
  138. package/lib/scrollbar.js +1331 -278
  139. package/lib/select.js +5816 -1428
  140. package/lib/skeleton-item.js +133 -145
  141. package/lib/skeleton.js +82 -91
  142. package/lib/slider.js +5157 -702
  143. package/lib/spinner.js +113 -101
  144. package/lib/statistic.js +10205 -254
  145. package/lib/step.js +274 -311
  146. package/lib/steps.js +854 -117
  147. package/lib/subTitle.js +292 -0
  148. package/lib/submenu.js +2867 -429
  149. package/lib/switch.js +1051 -291
  150. package/lib/tab-pane.js +125 -135
  151. package/lib/tabDialog.js +2658 -0
  152. package/lib/table-column.js +1975 -751
  153. package/lib/table.js +8019 -3979
  154. package/lib/tabs.js +1455 -605
  155. package/lib/tag.js +73 -68
  156. package/lib/theme-chalk/src/index.scss +3 -0
  157. package/lib/time-picker.js +6821 -1944
  158. package/lib/time-select.js +6297 -1186
  159. package/lib/timeline-item.js +43 -84
  160. package/lib/timeline.js +43 -39
  161. package/lib/tooltip.js +3185 -287
  162. package/lib/transfer.js +2943 -625
  163. package/lib/transitions/collapse-transition.js +69 -87
  164. package/lib/tree.js +3312 -1791
  165. package/lib/treeSelect.js +4436 -0
  166. package/lib/umd/locale/af-ZA.js +145 -138
  167. package/lib/umd/locale/ar.js +138 -137
  168. package/lib/umd/locale/az.js +139 -137
  169. package/lib/umd/locale/bg.js +148 -138
  170. package/lib/umd/locale/bn.js +138 -137
  171. package/lib/umd/locale/ca.js +138 -137
  172. package/lib/umd/locale/cs-CZ.js +142 -140
  173. package/lib/umd/locale/da.js +139 -137
  174. package/lib/umd/locale/de.js +141 -139
  175. package/lib/umd/locale/ee.js +140 -138
  176. package/lib/umd/locale/el.js +140 -138
  177. package/lib/umd/locale/en.js +142 -138
  178. package/lib/umd/locale/eo.js +140 -138
  179. package/lib/umd/locale/es.js +138 -137
  180. package/lib/umd/locale/eu.js +143 -138
  181. package/lib/umd/locale/fa.js +140 -138
  182. package/lib/umd/locale/fi.js +140 -138
  183. package/lib/umd/locale/fr.js +140 -137
  184. package/lib/umd/locale/he.js +145 -138
  185. package/lib/umd/locale/hr.js +143 -138
  186. package/lib/umd/locale/hu.js +139 -137
  187. package/lib/umd/locale/hy-AM.js +140 -138
  188. package/lib/umd/locale/id.js +139 -138
  189. package/lib/umd/locale/is.js +139 -138
  190. package/lib/umd/locale/it.js +138 -137
  191. package/lib/umd/locale/ja.js +140 -138
  192. package/lib/umd/locale/kg.js +140 -138
  193. package/lib/umd/locale/km.js +139 -138
  194. package/lib/umd/locale/ko.js +140 -138
  195. package/lib/umd/locale/ku.js +140 -138
  196. package/lib/umd/locale/kz.js +140 -138
  197. package/lib/umd/locale/lo-LA.js +138 -137
  198. package/lib/umd/locale/lt.js +140 -138
  199. package/lib/umd/locale/lv.js +140 -138
  200. package/lib/umd/locale/mn.js +140 -138
  201. package/lib/umd/locale/ms.js +138 -137
  202. package/lib/umd/locale/nb-NO.js +138 -137
  203. package/lib/umd/locale/nl.js +140 -138
  204. package/lib/umd/locale/pl.js +140 -138
  205. package/lib/umd/locale/pt-br.js +139 -138
  206. package/lib/umd/locale/pt.js +148 -138
  207. package/lib/umd/locale/ro.js +140 -138
  208. package/lib/umd/locale/ru-RU.js +139 -138
  209. package/lib/umd/locale/si.js +142 -138
  210. package/lib/umd/locale/sk.js +141 -140
  211. package/lib/umd/locale/sl.js +140 -138
  212. package/lib/umd/locale/sr-Latn.js +139 -138
  213. package/lib/umd/locale/sr.js +143 -138
  214. package/lib/umd/locale/sv-SE.js +143 -138
  215. package/lib/umd/locale/sw.js +142 -138
  216. package/lib/umd/locale/ta.js +145 -137
  217. package/lib/umd/locale/th.js +142 -138
  218. package/lib/umd/locale/tk.js +144 -138
  219. package/lib/umd/locale/tr-TR.js +140 -138
  220. package/lib/umd/locale/ua.js +139 -138
  221. package/lib/umd/locale/ug-CN.js +139 -138
  222. package/lib/umd/locale/uz-UZ.js +139 -138
  223. package/lib/umd/locale/vi.js +139 -138
  224. package/lib/umd/locale/zh-CN.js +139 -138
  225. package/lib/umd/locale/zh-TW.js +143 -138
  226. package/lib/upload.js +2377 -987
  227. package/lib/utils/after-leave.js +36 -33
  228. package/lib/utils/aria-dialog.js +55 -73
  229. package/lib/utils/aria-utils.js +67 -76
  230. package/lib/utils/clickoutside.js +52 -60
  231. package/lib/utils/date-util.js +198 -241
  232. package/lib/utils/date.js +6 -368
  233. package/lib/utils/date_source.js +349 -0
  234. package/lib/utils/dom.js +167 -183
  235. package/lib/utils/lodash.js +13 -9421
  236. package/lib/utils/lodash_source.js +9421 -0
  237. package/lib/utils/menu/aria-menubar.js +13 -18
  238. package/lib/utils/menu/aria-menuitem.js +43 -54
  239. package/lib/utils/menu/aria-submenu.js +50 -59
  240. package/lib/utils/merge.js +15 -17
  241. package/lib/utils/popper.js +1141 -1170
  242. package/lib/utils/popup/index.js +186 -230
  243. package/lib/utils/popup/popup-manager.js +159 -191
  244. package/lib/utils/resize-event.js +29 -44
  245. package/lib/utils/scroll-into-view.js +25 -33
  246. package/lib/utils/scrollbar-width.js +25 -36
  247. package/lib/utils/shared.js +3 -3
  248. package/lib/utils/types.js +19 -32
  249. package/lib/utils/util.js +187 -221
  250. package/lib/utils/vdom.js +5 -9
  251. package/lib/utils/vue-popper.js +166 -188
  252. package/package.json +20 -19
  253. package/packages/alert/src/main.vue +63 -63
  254. package/packages/aside/src/main.vue +9 -9
  255. package/packages/autocomplete/src/autocomplete-suggestions.vue +46 -46
  256. package/packages/autocomplete/src/autocomplete.vue +198 -198
  257. package/packages/avatar/src/main.vue +5 -5
  258. package/packages/backtop/src/main.vue +3 -3
  259. package/packages/badge/src/main.vue +1 -1
  260. package/packages/breadcrumb/src/breadcrumb-item.vue +26 -26
  261. package/packages/breadcrumb/src/breadcrumb.vue +22 -22
  262. package/packages/button/src/button-group.vue +3 -3
  263. package/packages/button/src/button.vue +44 -44
  264. package/packages/calendar/src/date-table.vue +3 -3
  265. package/packages/calendar/src/main.vue +7 -7
  266. package/packages/card/src/main.vue +9 -9
  267. package/packages/carousel/src/item.vue +98 -98
  268. package/packages/carousel/src/main.vue +2 -2
  269. package/packages/cascader/src/cascader.vue +4 -4
  270. package/packages/cascader-panel/src/cascader-menu.vue +4 -4
  271. package/packages/cascader-panel/src/cascader-node.vue +232 -232
  272. package/packages/cascader-panel/src/cascader-panel.vue +3 -3
  273. package/packages/cascader-panel/src/node.js +2 -3
  274. package/packages/cascader-panel/src/store.js +0 -1
  275. package/packages/checkbox/src/checkbox-button.vue +139 -139
  276. package/packages/checkbox/src/checkbox-group.vue +33 -33
  277. package/packages/checkbox/src/checkbox.vue +140 -140
  278. package/packages/col/src/col.js +5 -5
  279. package/packages/collapse/src/collapse-item.vue +55 -55
  280. package/packages/collapse/src/collapse.vue +54 -54
  281. package/packages/color-picker/src/color.js +4 -4
  282. package/packages/color-picker/src/components/alpha-slider.vue +100 -100
  283. package/packages/color-picker/src/components/hue-slider.vue +91 -91
  284. package/packages/color-picker/src/components/picker-dropdown.vue +64 -64
  285. package/packages/color-picker/src/components/predefine.vue +43 -43
  286. package/packages/color-picker/src/components/sv-panel.vue +70 -70
  287. package/packages/color-picker/src/main.vue +141 -141
  288. package/packages/container/src/main.vue +20 -20
  289. package/packages/date-picker/src/basic/date-table.vue +360 -360
  290. package/packages/date-picker/src/basic/month-table.vue +222 -223
  291. package/packages/date-picker/src/basic/time-spinner.vue +174 -174
  292. package/packages/date-picker/src/basic/year-table.vue +91 -91
  293. package/packages/date-picker/src/panel/date-range.vue +415 -415
  294. package/packages/date-picker/src/panel/date.vue +423 -423
  295. package/packages/date-picker/src/panel/month-range.vue +177 -177
  296. package/packages/date-picker/src/panel/time-range.vue +173 -173
  297. package/packages/date-picker/src/panel/time-select.vue +131 -131
  298. package/packages/date-picker/src/panel/time.vue +131 -131
  299. package/packages/date-picker/src/picker.vue +7 -7
  300. package/packages/descriptions/src/descriptions-row.js +3 -3
  301. package/packages/descriptions/src/index.js +1 -1
  302. package/packages/dialog/src/component.vue +155 -155
  303. package/packages/divider/src/main.vue +1 -1
  304. package/packages/drawer/src/main.vue +2 -2
  305. package/packages/dropdown/src/dropdown-item.vue +15 -15
  306. package/packages/dropdown/src/dropdown-menu.vue +47 -47
  307. package/packages/dropdown/src/dropdown.vue +260 -260
  308. package/packages/empty/src/index.vue +1 -1
  309. package/packages/fileUpload/index.js +8 -0
  310. package/packages/fileUpload/src/main.vue +430 -0
  311. package/packages/footer/src/main.vue +9 -9
  312. package/packages/form/src/form-item.vue +245 -245
  313. package/packages/form/src/form.vue +154 -154
  314. package/packages/header/src/main.vue +9 -9
  315. package/packages/icon/src/icon.vue +6 -6
  316. package/packages/image/src/image-viewer.vue +9 -9
  317. package/packages/image/src/main.vue +206 -206
  318. package/packages/infinite-scroll/src/main.js +1 -2
  319. package/packages/input/src/calcTextareaHeight.js +2 -2
  320. package/packages/input/src/input.vue +311 -311
  321. package/packages/input-number/src/input-number.vue +205 -205
  322. package/packages/loading/src/loading.vue +19 -19
  323. package/packages/main/src/main.vue +4 -4
  324. package/packages/menu/src/menu-item-group.vue +27 -27
  325. package/packages/menu/src/menu-item.vue +69 -69
  326. package/packages/menu/src/menu.vue +284 -284
  327. package/packages/menu/src/submenu.vue +308 -309
  328. package/packages/message/src/main.js +1 -1
  329. package/packages/message/src/main.vue +72 -72
  330. package/packages/message-box/src/main.vue +216 -216
  331. package/packages/notification/src/main.js +1 -1
  332. package/packages/notification/src/main.vue +93 -93
  333. package/packages/pagination/src/pager.vue +99 -99
  334. package/packages/popconfirm/src/main.vue +28 -28
  335. package/packages/popover/src/main.vue +6 -6
  336. package/packages/progress/src/progress.vue +174 -174
  337. package/packages/radio/src/radio-button.vue +64 -64
  338. package/packages/radio/src/radio-group.vue +88 -88
  339. package/packages/radio/src/radio.vue +74 -74
  340. package/packages/rate/src/main.vue +270 -270
  341. package/packages/row/src/row.js +3 -3
  342. package/packages/scrollbar/src/main.js +2 -2
  343. package/packages/scrollbar/src/util.js +1 -1
  344. package/packages/select/src/option-group.vue +46 -46
  345. package/packages/select/src/option.vue +122 -122
  346. package/packages/select/src/select-dropdown.vue +49 -49
  347. package/packages/select/src/select.vue +676 -676
  348. package/packages/skeleton/src/item.vue +12 -12
  349. package/packages/slider/src/button.vue +191 -191
  350. package/packages/slider/src/main.vue +314 -314
  351. package/packages/spinner/src/spinner.vue +16 -16
  352. package/packages/statistic/src/main.vue +5 -6
  353. package/packages/steps/src/step.vue +2 -2
  354. package/packages/steps/src/steps.vue +4 -4
  355. package/packages/subTitle/index.js +8 -0
  356. package/packages/subTitle/src/main.vue +33 -0
  357. package/packages/switch/src/component.vue +123 -123
  358. package/packages/tabDialog/index.js +23 -0
  359. package/packages/tabDialog/src/dialog/drag.js +63 -0
  360. package/packages/tabDialog/src/dialog/dragHeight.js +34 -0
  361. package/packages/tabDialog/src/dialog/dragWidth.js +30 -0
  362. package/packages/tabDialog/src/main.vue +277 -0
  363. package/packages/table/src/filter-panel.vue +128 -128
  364. package/packages/table/src/store/index.js +1 -1
  365. package/packages/table/src/table-body.js +2 -2
  366. package/packages/table/src/table-column.js +1 -1
  367. package/packages/table/src/table-header.js +1 -1
  368. package/packages/table/src/table-layout.js +1 -1
  369. package/packages/table/src/table.vue +416 -416
  370. package/packages/tabs/src/tab-bar.vue +43 -43
  371. package/packages/tabs/src/tab-nav.vue +250 -250
  372. package/packages/tabs/src/tab-pane.vue +34 -34
  373. package/packages/tabs/src/tabs.vue +165 -165
  374. package/packages/tag/src/tag.vue +52 -52
  375. package/packages/theme-chalk/src/index.scss +3 -0
  376. package/packages/theme-cy/lib/element.css +1 -0
  377. package/packages/theme-cy/lib/fileUpload.css +1 -0
  378. package/packages/theme-cy/lib/index.css +1 -1
  379. package/packages/theme-cy/lib/subTitle.css +1 -0
  380. package/packages/theme-cy/lib/tabDialog.css +1 -0
  381. package/packages/theme-cy/lib/treeselect.css +1 -1
  382. package/packages/theme-cy/src/element.scss +45 -0
  383. package/packages/theme-cy/src/fileUpload.scss +30 -0
  384. package/packages/theme-cy/src/index.scss +4 -0
  385. package/packages/theme-cy/src/subTitle.scss +26 -0
  386. package/packages/theme-cy/src/tabDialog.scss +43 -0
  387. package/packages/theme-cy/src/treeselect.scss +20 -14
  388. package/packages/timeline/src/item.vue +24 -24
  389. package/packages/timeline/src/main.vue +27 -27
  390. package/packages/tooltip/src/main.js +1 -1
  391. package/packages/transfer/src/main.vue +169 -169
  392. package/packages/transfer/src/transfer-panel.vue +164 -164
  393. package/packages/tree/src/tree-node.vue +169 -169
  394. package/packages/tree/src/tree.vue +408 -408
  395. package/packages/treeSelect/index.js +8 -0
  396. package/packages/{treeselect → treeSelect}/src/main.vue +19 -19
  397. package/packages/upload/src/ajax.js +3 -3
  398. package/packages/upload/src/upload-dragger.vue +50 -50
  399. package/packages/upload/src/upload-list.vue +33 -33
  400. package/packages/upload/src/upload.vue +1 -1
  401. package/src/index.js +13 -5
  402. package/src/locale/format.js +0 -1
  403. package/src/mixins/migrating.js +2 -2
  404. package/src/utils/date.js +2 -368
  405. package/src/utils/date_source.js +368 -0
  406. package/src/utils/lodash.js +9 -18075
  407. package/src/utils/lodash_source.js +18075 -0
  408. package/src/utils/types.js +1 -1
  409. package/types/element-ui.d.ts +16 -3
  410. package/types/fileUpload.d.ts +5 -0
  411. package/types/subTitle.d.ts +5 -0
  412. package/types/tabDialog.d.ts +5 -0
  413. package/types/treeSelect.d.ts +5 -0
  414. package/lib/treeselect.js +0 -682
  415. package/packages/treeselect/index.js +0 -8
  416. package/types/treeselect.d.ts +0 -5
@@ -1,6 +1,4 @@
1
- 'use strict';
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
- ;(function (root, factory) {
35
- if (typeof define === 'function' && define.amd) {
36
- // AMD. Register as an anonymous module.
37
- define(factory);
38
- } else if ((typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object' && module.exports) {
39
- // Node. Does not work with strict CommonJS, but
40
- // only CommonJS-like environments that support module.exports,
41
- // like Node.
42
- module.exports = factory();
43
- } else {
44
- // Browser globals (root is window)
45
- root.Popper = factory();
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
- })(undefined, function () {
48
-
49
- 'use strict';
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
- // Methods
201
- //
202
- /**
203
- * Destroy the popper
204
- * @method
205
- * @memberof Popper
206
- */
207
- Popper.prototype.destroy = function () {
208
- this._popper.removeAttribute('x-placement');
209
- this._popper.style.left = '';
210
- this._popper.style.position = '';
211
- this._popper.style.top = '';
212
- this._popper.style[getSupportedPropertyName('transform')] = '';
213
- this._removeEventListeners();
214
-
215
- // remove the popper if user explicity asked for the deletion on destroy
216
- if (this._options.removeOnDestroy) {
217
- this._popper.remove();
218
- }
219
- return this;
220
- };
221
-
222
- /**
223
- * Updates the position of the popper, computing the new offsets and applying the new style
224
- * @method
225
- * @memberof Popper
226
- */
227
- Popper.prototype.update = function () {
228
- var data = { instance: this, styles: {} };
229
-
230
- // store placement inside the data object, modifiers will be able to edit `placement` if needed
231
- // and refer to _originalPlacement to know the original value
232
- data.placement = this._options.placement;
233
- data._originalPlacement = this._options.placement;
234
-
235
- // compute the popper and reference offsets and put them inside data.offsets
236
- data.offsets = this._getOffsets(this._popper, this._reference, data.placement);
237
-
238
- // get boundaries
239
- data.boundaries = this._getBoundaries(data, this._options.boundariesPadding, this._options.boundariesElement);
240
-
241
- data = this.runModifiers(data, this._options.modifiers);
242
-
243
- if (typeof this.state.updateCallback === 'function') {
244
- this.state.updateCallback(data);
245
- }
246
- };
247
-
248
- /**
249
- * If a function is passed, it will be executed after the initialization of popper with as first argument the Popper instance.
250
- * @method
251
- * @memberof Popper
252
- * @param {Function} callback
253
- */
254
- Popper.prototype.onCreate = function (callback) {
255
- // the createCallbacks return as first argument the popper instance
256
- callback(this);
257
- return this;
258
- };
259
-
260
- /**
261
- * If a function is passed, it will be executed after each update of popper with as first argument the set of coordinates and informations
262
- * used to style popper and its arrow.
263
- * NOTE: it doesn't get fired on the first call of the `Popper.update()` method inside the `Popper` constructor!
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
- * Get offsets to the popper
393
- * @method
394
- * @memberof Popper
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
- return {
443
- popper: popperOffsets,
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
- * Setup needed event listeners used to update the popper position
450
- * @method
451
- * @memberof Popper
452
- * @access private
453
- */
454
- Popper.prototype._setupEventListeners = function () {
455
- // NOTE: 1 DOM access here
456
- this.state.updateBound = this.update.bind(this);
457
- root.addEventListener('resize', this.state.updateBound);
458
- // if the boundariesElement is window we don't need to listen for the scroll event
459
- if (this._options.boundariesElement !== 'window') {
460
- var target = getScrollParent(this._reference);
461
- // here it could be both `body` or `documentElement` thanks to Firefox, we then check both
462
- if (target === root.document.body || target === root.document.documentElement) {
463
- target = root;
464
- }
465
- target.addEventListener('scroll', this.state.updateBound);
466
- this.state.scrollTarget = target;
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
- * Remove event listeners used to update the popper position
472
- * @method
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
- * Computed the boundaries limits and return them
488
- * @method
489
- * @memberof Popper
490
- * @access private
491
- * @param {Object} data - Object containing the property "offsets" generated by `_getOffsets`
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
- Popper.prototype._getBoundaries = function (data, padding, boundariesElement) {
497
- // NOTE: 1 DOM access here
498
- var boundaries = {};
499
- var width, height;
500
- if (boundariesElement === 'window') {
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
- * Loop trough the list of modifiers and run them in order, each of them will then edit the data object
557
- * @method
558
- * @memberof Popper
559
- * @access public
560
- * @param {Object} data
561
- * @param {Array} modifiers
562
- * @param {Function} ends
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
- Popper.prototype.runModifiers = function (data, modifiers, ends) {
565
- var modifiersToRun = modifiers.slice();
566
- if (ends !== undefined) {
567
- modifiersToRun = this._options.modifiers.slice(0, getArrayKeyIndex(this._options.modifiers, ends));
568
- }
569
-
570
- modifiersToRun.forEach(function (modifier) {
571
- if (isFunction(modifier)) {
572
- data = modifier.call(this, data);
573
- }
574
- }.bind(this));
575
-
576
- return data;
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
- * Helper used to know if the given modifier depends from another one.
581
- * @method
582
- * @memberof Popper
583
- * @param {String} requesting - name of requesting modifier
584
- * @param {String} requested - name of requested modifier
585
- * @returns {Boolean}
586
- */
587
- Popper.prototype.isModifierRequired = function (requesting, requested) {
588
- var index = getArrayKeyIndex(this._options.modifiers, requesting);
589
- return !!this._options.modifiers.slice(0, index).filter(function (modifier) {
590
- return modifier === requested;
591
- }).length;
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
- // Modifiers
392
+ // Get reference element position
596
393
  //
394
+ var referenceOffsets = getOffsetRectRelativeToCustomParent(reference, getOffsetParent(popper), isParentFixed);
597
395
 
598
- /**
599
- * Modifiers list
600
- * @namespace Popper.modifiers
601
- * @memberof Popper
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
- return data;
656
- };
401
+ //
402
+ // Compute offsets of popper
403
+ //
657
404
 
658
- /**
659
- * Modifier used to shift the popper on the start or end of its reference element side
660
- * @method
661
- * @memberof Popper.modifiers
662
- * @argument {Object} data - The data object generated by `update` method
663
- * @returns {Object} The data object, properly modified
664
- */
665
- Popper.prototype.modifiers.shift = function (data) {
666
- var placement = data.placement;
667
- var basePlacement = placement.split('-')[0];
668
- var shiftVariation = placement.split('-')[1];
669
-
670
- // if shift shiftVariation is specified, run the modifier
671
- if (shiftVariation) {
672
- var reference = data.offsets.reference;
673
- var popper = getPopperClientRect(data.offsets.popper);
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
- return data;
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
- * Modifier used to make sure the popper does not overflows from it's boundaries
696
- * @method
697
- * @memberof Popper.modifiers
698
- * @argument {Object} data - The data object generated by `update` method
699
- * @returns {Object} The data object, properly modified
700
- */
701
- Popper.prototype.modifiers.preventOverflow = function (data) {
702
- var order = this._options.preventOverflowOrder;
703
- var popper = getPopperClientRect(data.offsets.popper);
704
-
705
- var check = {
706
- left: function left() {
707
- var left = popper.left;
708
- if (popper.left < data.boundaries.left) {
709
- left = Math.max(popper.left, data.boundaries.left);
710
- }
711
- return { left: left };
712
- },
713
- right: function right() {
714
- var left = popper.left;
715
- if (popper.right > data.boundaries.right) {
716
- left = Math.min(popper.left, data.boundaries.right - popper.width);
717
- }
718
- return { left: left };
719
- },
720
- top: function top() {
721
- var top = popper.top;
722
- if (popper.top < data.boundaries.top) {
723
- top = Math.max(popper.top, data.boundaries.top);
724
- }
725
- return { top: top };
726
- },
727
- bottom: function bottom() {
728
- var top = popper.top;
729
- if (popper.bottom > data.boundaries.bottom) {
730
- top = Math.min(popper.top, data.boundaries.bottom - popper.height);
731
- }
732
- return { top: top };
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
- order.forEach(function (direction) {
737
- data.offsets.popper = Object.assign(popper, check[direction]());
738
- });
739
-
740
- return data;
741
- };
742
-
743
- /**
744
- * Modifier used to make sure the popper is always near its reference
745
- * @method
746
- * @memberof Popper.modifiers
747
- * @argument {Object} data - The data object generated by _update method
748
- * @returns {Object} The data object, properly modified
749
- */
750
- Popper.prototype.modifiers.keepTogether = function (data) {
751
- var popper = getPopperClientRect(data.offsets.popper);
752
- var reference = data.offsets.reference;
753
- var f = Math.floor;
754
-
755
- if (popper.right < f(reference.left)) {
756
- data.offsets.popper.left = f(reference.left) - popper.width;
757
- }
758
- if (popper.left > f(reference.right)) {
759
- data.offsets.popper.left = f(reference.right);
760
- }
761
- if (popper.bottom < f(reference.top)) {
762
- data.offsets.popper.top = f(reference.top) - popper.height;
763
- }
764
- if (popper.top > f(reference.bottom)) {
765
- data.offsets.popper.top = f(reference.bottom);
766
- }
767
-
768
- return data;
769
- };
770
-
771
- /**
772
- * Modifier used to flip the placement of the popper when the latter is starting overlapping its reference element.
773
- * Requires the `preventOverflow` modifier before it in order to work.
774
- * **NOTE:** This modifier will run all its previous modifiers everytime it tries to flip the popper!
775
- * @method
776
- * @memberof Popper.modifiers
777
- * @argument {Object} data - The data object generated by _update method
778
- * @returns {Object} The data object, properly modified
779
- */
780
- Popper.prototype.modifiers.flip = function (data) {
781
- // check if preventOverflow is in the list of modifiers before the flip modifier.
782
- // otherwise flip would not work as expected.
783
- if (!this.isModifierRequired(this.modifiers.flip, this.modifiers.preventOverflow)) {
784
- console.warn('WARNING: preventOverflow modifier is required by flip modifier in order to work, be sure to include it before flip!');
785
- return data;
786
- }
787
-
788
- if (data.flipped && data.placement === data._originalPlacement) {
789
- // seems like flip is trying to loop, probably there's not enough space on any of the flippable sides
790
- return data;
791
- }
792
-
793
- var placement = data.placement.split('-')[0];
794
- var placementOpposite = getOppositePlacement(placement);
795
- var variation = data.placement.split('-')[1] || '';
796
-
797
- var flipOrder = [];
798
- if (this._options.flipBehavior === 'flip') {
799
- flipOrder = [placement, placementOpposite];
800
- } else {
801
- flipOrder = this._options.flipBehavior;
802
- }
803
-
804
- flipOrder.forEach(function (step, index) {
805
- if (placement !== step || flipOrder.length === index + 1) {
806
- return;
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
- * Modifier used to add an offset to the popper, useful if you more granularity positioning your popper.
836
- * The offsets will shift the popper on the side of its reference element.
837
- * @method
838
- * @memberof Popper.modifiers
839
- * @argument {Object} data - The data object generated by _update method
840
- * @returns {Object} The data object, properly modified
841
- */
842
- Popper.prototype.modifiers.offset = function (data) {
843
- var offset = this._options.offset;
844
- var popper = data.offsets.popper;
845
-
846
- if (data.placement.indexOf('left') !== -1) {
847
- popper.top -= offset;
848
- } else if (data.placement.indexOf('right') !== -1) {
849
- popper.top += offset;
850
- } else if (data.placement.indexOf('top') !== -1) {
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
- * 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
860
- * It will use the CSS outer size of the arrow element to know how many pixels of conjuction are needed
861
- * @method
862
- * @memberof Popper.modifiers
863
- * @argument {Object} data - The data object generated by _update method
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
- // if the arrowElement is a string, suppose it's a CSS selector
871
- if (typeof arrow === 'string') {
872
- arrow = this._popper.querySelector(arrow);
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
- // if arrow element is not found, don't run the modifier
876
- if (!arrow) {
877
- return data;
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
- // the arrow element must be child of its popper
881
- if (!this._popper.contains(arrow)) {
882
- console.warn('WARNING: `arrowElement` must be child of its popper element!');
883
- return data;
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
- // arrow depends on keepTogether in order to work
887
- if (!this.isModifierRequired(this.modifiers.arrow, this.modifiers.keepTogether)) {
888
- console.warn('WARNING: keepTogether modifier is required by arrow modifier in order to work, be sure to include it before arrow!');
889
- return data;
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
- var arrowStyle = {};
893
- var placement = data.placement.split('-')[0];
894
- var popper = getPopperClientRect(data.offsets.popper);
895
- var reference = data.offsets.reference;
896
- var isVertical = ['left', 'right'].indexOf(placement) !== -1;
897
-
898
- var len = isVertical ? 'height' : 'width';
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
- // bottom/right side
914
- if (reference[side] + arrowSize > popper[opSide]) {
915
- data.offsets.popper[side] += reference[side] + arrowSize - popper[opSide];
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
- // compute center of the popper
919
- var center = reference[side] + (arrowOffset || reference[len] / 2 - arrowSize / 2);
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
- // Helpers
936
- //
937
-
938
- /**
939
- * Get the outer sizes of the given element (offset size + margins)
940
- * @function
941
- * @ignore
942
- * @argument {Element} element
943
- * @returns {Object} object containing width and height properties
944
- */
945
- function getOuterSizes(element) {
946
- // NOTE: 1 DOM access here
947
- var _display = element.style.display,
948
- _visibility = element.style.visibility;
949
- element.style.display = 'block';element.style.visibility = 'hidden';
950
- var calcWidthToForceRepaint = element.offsetWidth;
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
- * Get CSS computed property of the given element
1013
- * @function
1014
- * @ignore
1015
- * @argument {Eement} element
1016
- * @argument {String} property
1017
- */
1018
- function getStyleComputedProperty(element, property) {
1019
- // NOTE: 1 DOM access here
1020
- var css = root.getComputedStyle(element, null);
1021
- return css[property];
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
- * Returns the offset parent of the given element
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
- * Returns the scrolling parent of the given element
1039
- * @function
1040
- * @ignore
1041
- * @argument {Element} element
1042
- * @returns {Element} offset parent
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
- * Check if the given element is fixed or is inside a fixed parent
1073
- * @function
1074
- * @ignore
1075
- * @argument {Element} element
1076
- * @argument {Element} customContainer
1077
- * @returns {Boolean} answer to "isFixed?"
1078
- */
1079
- function isFixed(element) {
1080
- if (element === root.document.body) {
1081
- return false;
1082
- }
1083
- if (getStyleComputedProperty(element, 'position') === 'fixed') {
1084
- return true;
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
- return element.parentNode ? isFixed(element.parentNode) : element;
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
- * Set the style to the given popper
1091
- * @function
1092
- * @ignore
1093
- * @argument {Element} element - Element to apply the style to
1094
- * @argument {Object} styles - Object with a list of properties and values which will be applied to the element
1095
- */
1096
- function setStyle(element, styles) {
1097
- function is_numeric(n) {
1098
- return n !== '' && !isNaN(parseFloat(n)) && isFinite(n);
1099
- }
1100
- Object.keys(styles).forEach(function (prop) {
1101
- var unit = '';
1102
- // add unit if the value is numeric and is one of the following
1103
- if (['width', 'height', 'top', 'right', 'bottom', 'left'].indexOf(prop) !== -1 && is_numeric(styles[prop])) {
1104
- unit = 'px';
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
- * Check if the given variable is a function
1112
- * @function
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
- * Get the position of the given element, relative to its offset parent
1124
- * @function
1125
- * @ignore
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
- * Get bounding client rect of given element
1146
- * @function
1147
- * @ignore
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
- * Given an element and one of its parents, return the offset
1172
- * @function
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
- var rect = {
1191
- top: elementRect.top - parentRect.top,
1192
- left: elementRect.left - parentRect.left,
1193
- bottom: elementRect.top - parentRect.top + elementRect.height,
1194
- right: elementRect.left - parentRect.left + elementRect.width,
1195
- width: elementRect.width,
1196
- height: elementRect.height
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
- * Get the prefixed supported property name
1203
- * @function
1204
- * @ignore
1205
- * @argument {String} property (camelCase)
1206
- * @returns {String} prefixed property (camelCase)
1207
- */
1208
- function getSupportedPropertyName(property) {
1209
- var prefixes = ['', 'ms', 'webkit', 'moz', 'o'];
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
- for (var i = 0; i < prefixes.length; i++) {
1212
- var toCheck = prefixes[i] ? prefixes[i] + property.charAt(0).toUpperCase() + property.slice(1) : property;
1213
- if (typeof root.document.body.style[toCheck] !== 'undefined') {
1214
- return toCheck;
1215
- }
1216
- }
1217
- return null;
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
- * The Object.assign() method is used to copy the values of all enumerable own properties from one or more source
1222
- * objects to a target object. It will return the target object.
1223
- * This polyfill doesn't support symbol properties, since ES5 doesn't have symbols anyway
1224
- * Source: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
1225
- * @function
1226
- * @ignore
1227
- */
1228
- if (!Object.assign) {
1229
- Object.defineProperty(Object, 'assign', {
1230
- enumerable: false,
1231
- configurable: true,
1232
- writable: true,
1233
- value: function value(target) {
1234
- if (target === undefined || target === null) {
1235
- throw new TypeError('Cannot convert first argument to object');
1236
- }
1237
-
1238
- var to = Object(target);
1239
- for (var i = 1; i < arguments.length; i++) {
1240
- var nextSource = arguments[i];
1241
- if (nextSource === undefined || nextSource === null) {
1242
- continue;
1243
- }
1244
- nextSource = Object(nextSource);
1245
-
1246
- var keysArray = Object.keys(nextSource);
1247
- for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
1248
- var nextKey = keysArray[nextIndex];
1249
- var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
1250
- if (desc !== undefined && desc.enumerable) {
1251
- to[nextKey] = nextSource[nextKey];
1252
- }
1253
- }
1254
- }
1255
- return to;
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
- return Popper;
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
  });