瀏覽代碼

Make it compatible with both Select2 v3 and v4 (#3988)

Sullivan SENECHAL 9 年之前
父節點
當前提交
c03fd27059
共有 1 個文件被更改,包括 7 次插入3 次删除
  1. 7 3
      Resources/public/Admin.js

+ 7 - 3
Resources/public/Admin.js

@@ -56,7 +56,7 @@ var Admin = {
         });
     },
     setup_select2: function(subject) {
-        if (window.SONATA_CONFIG && window.SONATA_CONFIG.USE_SELECT2 && window.Select2) {
+        if (window.SONATA_CONFIG && window.SONATA_CONFIG.USE_SELECT2) {
             Admin.log('[core|setup_select2] configure Select2 on', subject);
 
             jQuery('select:not([data-sonata-select2="false"])', subject).each(function() {
@@ -74,7 +74,9 @@ var Admin = {
 
                 select.select2({
                     width: function(){
-                        return Admin.get_select2_width(this.element);
+                        // Select2 v3 and v4 BC. If window.Select2 is defined, then the v3 is installed.
+                        // NEXT_MAJOR: Remove Select2 v3 support.
+                        return Admin.get_select2_width(window.Select2 ? this.element : jQuery(this));
                     },
                     dropdownAutoWidth: true,
                     minimumResultsForSearch: 10,
@@ -446,7 +448,9 @@ var Admin = {
 
         subject.select2({
             width: function(){
-                return Admin.get_select2_width(this.element);
+                // Select2 v3 and v4 BC. If window.Select2 is defined, then the v3 is installed.
+                // NEXT_MAJOR: Remove Select2 v3 support.
+                return Admin.get_select2_width(window.Select2 ? this.element : jQuery(this));
             },
             dropdownAutoWidth: true,
             data: transformedData,