]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Object spread : less jQuery more ES6 (#24665)
authorJohann-S <johann.servoire@gmail.com>
Mon, 13 Nov 2017 10:25:36 +0000 (11:25 +0100)
committerGitHub <noreply@github.com>
Mon, 13 Nov 2017 10:25:36 +0000 (11:25 +0100)
.babelrc.js
build/rollup.config.js
js/src/carousel.js
js/src/collapse.js
js/src/dropdown.js
js/src/modal.js
js/src/popover.js
js/src/scrollspy.js
js/src/tooltip.js

index 693f6f8a3a4f4f5e69214f10b6ff5d8c537f4f55..277f96ae746a0fd821d35592b304797f208e1301 100644 (file)
@@ -10,6 +10,7 @@ module.exports = {
     ]
   ],
   plugins: [
-    process.env.PLUGINS && 'transform-es2015-modules-strip'
+    process.env.PLUGINS && 'transform-es2015-modules-strip',
+    '@babel/proposal-object-rest-spread'
   ].filter(Boolean)
 };
index 44ffac71002d2b7460d8d58bdfc412784931bc47..99bf637c0d891fd6702bac2709f7f6833daf91a1 100644 (file)
@@ -15,7 +15,8 @@ const plugins = [
     externalHelpersWhitelist: [ // include only required helpers
       'defineProperties',
       'createClass',
-      'inheritsLoose'
+      'inheritsLoose',
+      'extends'
     ]
   })
 ]
index 10ed2203edeb8ff3a39d06f5a2e637fc2154fb51..ea443f189f060f77d3c27f07bba7d3f61d7b8b83 100644 (file)
@@ -223,7 +223,10 @@ const Carousel = (($) => {
     // private
 
     _getConfig(config) {
-      config = $.extend({}, Default, config)
+      config = {
+        ...Default,
+        ...config
+      }
       Util.typeCheckConfig(NAME, config, DefaultType)
       return config
     }
@@ -428,10 +431,16 @@ const Carousel = (($) => {
     static _jQueryInterface(config) {
       return this.each(function () {
         let data      = $(this).data(DATA_KEY)
-        const _config = $.extend({}, Default, $(this).data())
+        let _config = {
+          ...Default,
+          ...$(this).data()
+        }
 
         if (typeof config === 'object') {
-          $.extend(_config, config)
+          _config = {
+            ..._config,
+            ...config
+          }
         }
 
         const action = typeof config === 'string' ? config : _config.slide
@@ -468,7 +477,10 @@ const Carousel = (($) => {
         return
       }
 
-      const config     = $.extend({}, $(target).data(), $(this).data())
+      const config = {
+        ...$(target).data(),
+        ...$(this).data()
+      }
       const slideIndex = this.getAttribute('data-slide-to')
 
       if (slideIndex) {
index f907aec54d82017e4a4d8f1c62821d57427d9193..1456294f43e1bf833f1012fba29440a1b0ae67b9 100644 (file)
@@ -277,7 +277,10 @@ const Collapse = (($) => {
     // private
 
     _getConfig(config) {
-      config = $.extend({}, Default, config)
+      config = {
+        ...Default,
+        ...config
+      }
       config.toggle = Boolean(config.toggle) // coerce string values
       Util.typeCheckConfig(NAME, config, DefaultType)
       return config
@@ -338,12 +341,11 @@ const Collapse = (($) => {
       return this.each(function () {
         const $this   = $(this)
         let data      = $this.data(DATA_KEY)
-        const _config = $.extend(
-          {},
-          Default,
-          $this.data(),
-          typeof config === 'object' && config
-        )
+        const _config = {
+          ...Default,
+          ...$this.data(),
+          ...typeof config === 'object' && config
+        }
 
         if (!data && _config.toggle && /show|hide/.test(config)) {
           _config.toggle = false
index 57ee10ebdddf8a9192d287c03bc221e401a40f54..8affedc6ce9e614a42038229a8b8fec806dec4e5 100644 (file)
@@ -210,12 +210,11 @@ const Dropdown = (($) => {
     }
 
     _getConfig(config) {
-      config = $.extend(
-        {},
-        this.constructor.Default,
-        $(this._element).data(),
-        config
-      )
+      config = {
+        ...this.constructor.Default,
+        ...$(this._element).data(),
+        ...config
+      }
 
       Util.typeCheckConfig(
         NAME,
@@ -262,7 +261,10 @@ const Dropdown = (($) => {
       const offsetConf = {}
       if (typeof this._config.offset === 'function') {
         offsetConf.fn = (data) => {
-          data.offsets = $.extend({}, data.offsets, this._config.offset(data.offsets) || {})
+          data.offsets = {
+            ...data.offsets,
+            ...this._config.offset(data.offsets) || {}
+          }
           return data
         }
       } else {
index 95565aabccebf0d545789ee84caa1ccd44902b93..be3105fa150c9d69b924fc567cc2d6b42ffc6a27 100644 (file)
@@ -227,7 +227,10 @@ const Modal = (($) => {
     // private
 
     _getConfig(config) {
-      config = $.extend({}, Default, config)
+      config = {
+        ...Default,
+        ...config
+      }
       Util.typeCheckConfig(NAME, config, DefaultType)
       return config
     }
@@ -506,12 +509,11 @@ const Modal = (($) => {
     static _jQueryInterface(config, relatedTarget) {
       return this.each(function () {
         let data      = $(this).data(DATA_KEY)
-        const _config = $.extend(
-          {},
-          Modal.Default,
-          $(this).data(),
-          typeof config === 'object' && config
-        )
+        const _config = {
+          ...Modal.Default,
+          ...$(this).data(),
+          ...typeof config === 'object' && config
+        }
 
         if (!data) {
           data = new Modal(this, _config)
@@ -547,7 +549,10 @@ const Modal = (($) => {
     }
 
     const config = $(target).data(DATA_KEY) ?
-      'toggle' : $.extend({}, $(target).data(), $(this).data())
+      'toggle' : {
+        ...$(target).data(),
+        ...$(this).data()
+      }
 
     if (this.tagName === 'A' || this.tagName === 'AREA') {
       event.preventDefault()
index 5534f44412466e3b7f064e1236284eac061f88d3..8beec963a2b061eedaedd722570a4f0afb6c02f7 100644 (file)
@@ -26,19 +26,25 @@ const Popover = (($) => {
   const CLASS_PREFIX        = 'bs-popover'
   const BSCLS_PREFIX_REGEX  = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
 
-  const Default = $.extend({}, Tooltip.Default, {
-    placement : 'right',
-    trigger   : 'click',
-    content   : '',
-    template  : '<div class="popover" role="tooltip">'
-              + '<div class="arrow"></div>'
-              + '<h3 class="popover-header"></h3>'
-              + '<div class="popover-body"></div></div>'
-  })
-
-  const DefaultType = $.extend({}, Tooltip.DefaultType, {
-    content : '(string|element|function)'
-  })
+  const Default = {
+    ...Tooltip.Default,
+    ...{
+      placement : 'right',
+      trigger   : 'click',
+      content   : '',
+      template  : '<div class="popover" role="tooltip">'
+                + '<div class="arrow"></div>'
+                + '<h3 class="popover-header"></h3>'
+                + '<div class="popover-body"></div></div>'
+    }
+  }
+
+  const DefaultType = {
+    ...Tooltip.DefaultType,
+    ...{
+      content : '(string|element|function)'
+    }
+  }
 
   const ClassName = {
     FADE : 'fade',
index 3a13d954ac572887b726a1bc5cdcb4138ab7a1ba..fd5197e383fd89e43a3ce094a58952d3da038427 100644 (file)
@@ -171,7 +171,10 @@ const ScrollSpy = (($) => {
     // private
 
     _getConfig(config) {
-      config = $.extend({}, Default, config)
+      config = {
+        ...Default,
+        ...config
+      }
 
       if (typeof config.target !== 'string') {
         let id = $(config.target).attr('id')
index 7cefd0be6aa170fbf7938001d2ee5af9e11b9a27..002dea429835fc9a30f858296e24f8388da76889 100644 (file)
@@ -501,10 +501,13 @@ const Tooltip = (($) => {
       })
 
       if (this.config.selector) {
-        this.config = $.extend({}, this.config, {
-          trigger  : 'manual',
-          selector : ''
-        })
+        this.config = {
+          ...this.config,
+          ...{
+            trigger  : 'manual',
+            selector : ''
+          }
+        }
       } else {
         this._fixTitle()
       }
@@ -613,12 +616,11 @@ const Tooltip = (($) => {
     }
 
     _getConfig(config) {
-      config = $.extend(
-        {},
-        this.constructor.Default,
-        $(this.element).data(),
-        config
-      )
+      config = {
+        ...this.constructor.Default,
+        ...$(this.element).data(),
+        ...config
+      }
 
       if (typeof config.delay === 'number') {
         config.delay = {