From afbf30d09a846a4afaa99964836854a7b46d425e Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Fri, 31 Oct 2014 20:15:17 -0400 Subject: [PATCH] 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. --- Gruntfile.js | 33 +++++++++------------------------ dist/js/select2.amd.full.js | 3 ++- dist/js/select2.amd.js | 3 ++- dist/js/select2.full.js | 6 ++---- dist/js/select2.full.min.js | 8 ++++---- dist/js/select2.js | 6 ++---- dist/js/select2.min.js | 2 +- src/js/banner.json | 4 ++++ 8 files changed, 26 insertions(+), 39 deletions(-) create mode 100644 src/js/banner.json diff --git a/Gruntfile.js b/Gruntfile.js index 4856e9df..b47d6d57 100644 --- a/Gruntfile.js +++ b/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']); }; diff --git a/dist/js/select2.amd.full.js b/dist/js/select2.amd.full.js index 472d777e..a2bf6e4e 100644 --- a/dist/js/select2.amd.full.js +++ b/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 };}()); \ No newline at end of file diff --git a/dist/js/select2.amd.js b/dist/js/select2.amd.js index 472d777e..a2bf6e4e 100644 --- a/dist/js/select2.amd.js +++ b/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 };}()); \ No newline at end of file diff --git a/dist/js/select2.full.js b/dist/js/select2.full.js index 4be5fa91..3bbb2633 100644 --- a/dist/js/select2.full.js +++ b/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 };}()); \ No newline at end of file diff --git a/dist/js/select2.full.min.js b/dist/js/select2.full.min.js index 128512ff..3e425a07 100644 --- a/dist/js/select2.full.min.js +++ b/dist/js/select2.full.min.js @@ -1,4 +1,4 @@ -var requirejs,require,define;!function(a){function b(a,b){return r.call(a,b)}function c(a,b){var c,d,e,f,g,h,i,j,k,l,m,n=b&&b.split("/"),o=p.map,q=o&&o["*"]||{};if(a&&"."===a.charAt(0))if(b){for(n=n.slice(0,n.length-1),a=a.split("/"),g=a.length-1,p.nodeIdCompat&&t.test(a[g])&&(a[g]=a[g].replace(t,"")),a=n.concat(a),k=0;k0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}else 0===a.indexOf("./")&&(a=a.substring(2));if((n||q)&&o){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),n)for(l=n.length;l>0;l-=1)if(e=o[n.slice(0,l).join("/")],e&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&q&&q[d]&&(i=q[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function d(b,c){return function(){return k.apply(a,s.call(arguments,0).concat([b,c]))}}function e(a){return function(b){return c(b,a)}}function f(a){return function(b){n[a]=b}}function g(c){if(b(o,c)){var d=o[c];delete o[c],q[c]=!0,j.apply(a,d)}if(!b(n,c)&&!b(q,c))throw new Error("No "+c);return n[c]}function h(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function i(a){return function(){return p&&p.config&&p.config[a]||{}}}var j,k,l,m,n={},o={},p={},q={},r=Object.prototype.hasOwnProperty,s=[].slice,t=/\.js$/;l=function(a,b){var d,f=h(a),i=f[0];return a=f[1],i&&(i=c(i,b),d=g(i)),i?a=d&&d.normalize?d.normalize(a,e(b)):c(a,b):(a=c(a,b),f=h(a),i=f[0],a=f[1],i&&(d=g(i))),{f:i?i+"!"+a:a,n:a,pr:i,p:d}},m={require:function(a){return d(a)},exports:function(a){var b=n[a];return"undefined"!=typeof b?b:n[a]={}},module:function(a){return{id:a,uri:"",exports:n[a],config:i(a)}}},j=function(c,e,h,i){var j,k,p,r,s,t,u=[],v=typeof h;if(i=i||c,"undefined"===v||"function"===v){for(e=!e.length&&h.length?["require","exports","module"]:e,s=0;s0&&b-1 in a}function d(a,b,c){if(ab.isFunction(b))return ab.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return ab.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(hb.test(b))return ab.filter(b,a,c);b=ab.filter(b,a)}return ab.grep(a,function(a){return U.call(b,a)>=0!==c})}function e(a,b){for(;(a=a[b])&&1!==a.nodeType;);return a}function f(a){var b=ob[a]={};return ab.each(a.match(nb)||[],function(a,c){b[c]=!0}),b}function g(){$.removeEventListener("DOMContentLoaded",g,!1),a.removeEventListener("load",g,!1),ab.ready()}function h(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=ab.expando+Math.random()}function i(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(ub,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:tb.test(c)?ab.parseJSON(c):c}catch(e){}sb.set(a,b,c)}else c=void 0;return c}function j(){return!0}function k(){return!1}function l(){try{return $.activeElement}catch(a){}}function m(a,b){return ab.nodeName(a,"table")&&ab.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function n(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function o(a){var b=Kb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function p(a,b){for(var c=0,d=a.length;d>c;c++)rb.set(a[c],"globalEval",!b||rb.get(b[c],"globalEval"))}function q(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(rb.hasData(a)&&(f=rb.access(a),g=rb.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)ab.event.add(b,e,j[e][c])}sb.hasData(a)&&(h=sb.access(a),i=ab.extend({},h),sb.set(b,i))}}function r(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&ab.nodeName(a,b)?ab.merge([a],c):c}function s(a,b){var c=b.nodeName.toLowerCase();"input"===c&&yb.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}function t(b,c){var d=ab(c.createElement(b)).appendTo(c.body),e=a.getDefaultComputedStyle?a.getDefaultComputedStyle(d[0]).display:ab.css(d[0],"display");return d.detach(),e}function u(a){var b=$,c=Ob[a];return c||(c=t(a,b),"none"!==c&&c||(Nb=(Nb||ab("