Ver Fonte

Wrap JS

This will prevent leaking variables, and will remove the possibility
of Select2 not working well with other plugins which support
AMD loaders. The `define` and `require` methods are now aliased
under `$.Select2.amd` for use inside additional files, such as
translations.
Kevin Brown há 10 anos atrás
pai
commit
afbf30d09a

+ 9 - 24
Gruntfile.js

@@ -78,7 +78,8 @@ module.exports = function (grunt) {
           paths: {
             almond: '../../vendor/almond-0.2.9',
             jquery: 'jquery.shim'
-          }
+          },
+          wrap: grunt.file.readJSON('src/js/banner.json')
         }
       },
       'dist.full': {
@@ -91,7 +92,8 @@ module.exports = function (grunt) {
           paths: {
             almond: '../../vendor/almond-0.2.9',
             jquery: '../../vendor/jquery-2.1.0'
-          }
+          },
+          wrap: grunt.file.readJSON('src/js/banner.json')
         }
       },
       'amd': {
@@ -103,7 +105,8 @@ module.exports = function (grunt) {
           include: includes,
           paths: {
             jquery: 'empty:'
-          }
+          },
+          wrap: grunt.file.readJSON('src/js/banner.json')
         }
       },
       'amd.full': {
@@ -115,30 +118,12 @@ module.exports = function (grunt) {
           include: fullIncludes,
           paths: {
             jquery: 'empty:'
-          }
+          },
+          wrap: grunt.file.readJSON('src/js/banner.json')
         }
       }
     },
 
-    concat: {
-      'dist': {
-        src: [
-          'src/js/start.js',
-          'dist/js/select2.js',
-          'src/js/end.js'
-        ],
-        dest: 'dist/js/select2.js'
-      },
-      'dist.full': {
-        src: [
-          'src/js/start.js',
-          'dist/js/select2.full.js',
-          'src/js/end.js'
-        ],
-        dest: 'dist/js/select2.full.js'
-      }
-    },
-
     watch: {
       js: {
         files: [
@@ -174,7 +159,7 @@ module.exports = function (grunt) {
 
   grunt.registerTask('default', ['compile', 'test', 'minify']);
 
-  grunt.registerTask('compile', ['requirejs', 'sass:dev', 'concat']);
+  grunt.registerTask('compile', ['requirejs', 'sass:dev']);
   grunt.registerTask('minify', ['uglify', 'sass:dist']);
   grunt.registerTask('test', ['qunit', 'jshint']);
 };

+ 2 - 1
dist/js/select2.amd.full.js

@@ -1,4 +1,4 @@
-define('select2/utils',[], function () {
+(function() {define('select2/utils',[], function () {
   var Utils = {};
 
   Utils.Extend = function (ChildClass, SuperClass) {
@@ -1674,3 +1674,4 @@ define('jquery.select2',[
   return Select2;
 });
 
+require('jquery.select2'); $.Select2 = $.Select2 || {}; $.Select2.amd = { define: define };}());

+ 2 - 1
dist/js/select2.amd.js

@@ -1,4 +1,4 @@
-define('select2/utils',[], function () {
+(function() {define('select2/utils',[], function () {
   var Utils = {};
 
   Utils.Extend = function (ChildClass, SuperClass) {
@@ -1674,3 +1674,4 @@ define('jquery.select2',[
   return Select2;
 });
 
+require('jquery.select2'); $.Select2 = $.Select2 || {}; $.Select2.amd = { define: define };}());

+ 2 - 4
dist/js/select2.full.js

@@ -1,5 +1,4 @@
-
-/**
+(function() {/**
  * @license almond 0.2.9 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
  * Available via the MIT or new BSD license.
  * see: http://github.com/jrburke/almond for details
@@ -11210,5 +11209,4 @@ define('jquery.select2',[
   return Select2;
 });
 
-
-require('jquery.select2');
+require('jquery.select2'); $.Select2 = $.Select2 || {}; $.Select2.amd = { define: define };}());

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/js/select2.full.min.js


+ 2 - 4
dist/js/select2.js

@@ -1,5 +1,4 @@
-
-/**
+(function() {/**
  * @license almond 0.2.9 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
  * Available via the MIT or new BSD license.
  * see: http://github.com/jrburke/almond for details
@@ -2103,5 +2102,4 @@ define('jquery.select2',[
   return Select2;
 });
 
-
-require('jquery.select2');
+require('jquery.select2'); $.Select2 = $.Select2 || {}; $.Select2.amd = { define: define };}());

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/js/select2.min.js


+ 4 - 0
src/js/banner.json

@@ -0,0 +1,4 @@
+{
+  "start": "(function() {",
+  "end": "require('jquery.select2'); $.Select2 = $.Select2 || {}; $.Select2.amd = { define: define, require: require };}());"
+}

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff