Skip to content

Commit 06e195b

Browse files
committed
Work on the AMD scaffolding
This will make it far easier to ensure that components are in their own modules as well as make it possible to have custom builds of Select2.
1 parent c0d9316 commit 06e195b

18 files changed

+11157
-26
lines changed

.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
.idea
2-
src/scss/**/*.css
3-
1+
node_modules

Gruntfile.js

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
module.exports = function (grunt) {
2+
// Full list of files that must be included by RequireJS
3+
amd_includes = [
4+
"almond"
5+
]
6+
7+
full_includes = [
8+
"jquery"
9+
]
10+
11+
grunt.initConfig({
12+
uglify: {
13+
"dist": {
14+
src: 'dist/js/select2.js',
15+
dest: 'dist/js/select2.min.js'
16+
},
17+
"dist.full": {
18+
src: 'dist/js/select2.full.js',
19+
dest: 'dist/js/select2.full.min.js'
20+
}
21+
},
22+
23+
qunit: {
24+
all: [
25+
"tests/**/*.html"
26+
]
27+
},
28+
29+
sass: {
30+
dist: {
31+
options: {
32+
outputStyle: "compressed"
33+
},
34+
files: {
35+
"dist/css/select2.min.css": [
36+
"src/scss/core.scss",
37+
"src/scss/theme/default/layout.css"
38+
]
39+
}
40+
},
41+
dev: {
42+
options: {
43+
outputStyle: "nested"
44+
},
45+
files: {
46+
"dist/css/select2.css": [
47+
"src/scss/core.scss",
48+
"src/scss/theme/default/layout.css"
49+
]
50+
}
51+
}
52+
},
53+
54+
requirejs: {
55+
"dist": {
56+
options: {
57+
baseUrl: "src/js",
58+
optimize: "none",
59+
name: "select2/core",
60+
out: "dist/js/select2.js",
61+
include: amd_includes,
62+
paths: {
63+
almond: "../../vendor/almond-0.2.9",
64+
jquery: "jquery.shim"
65+
}
66+
}
67+
},
68+
"dist.full": {
69+
options: {
70+
baseUrl: "src/js",
71+
optimize: "none",
72+
name: "select2/core",
73+
out: "dist/js/select2.full.js",
74+
include: amd_includes.concat(full_includes),
75+
paths: {
76+
almond: "../../vendor/almond-0.2.9",
77+
jquery: "../../vendor/jquery-2.1.0"
78+
}
79+
}
80+
},
81+
"amd": {
82+
options: {
83+
baseUrl: "src/js",
84+
optimize: "none",
85+
name: "select2/core",
86+
out: "dist/js/select2.amd.js",
87+
paths: {
88+
jquery: "empty:"
89+
}
90+
}
91+
},
92+
"amd.full": {
93+
options: {
94+
baseUrl: "src/js",
95+
optimize: "none",
96+
name: "select2/core",
97+
out: "dist/js/select2.amd.full.js",
98+
include: full_includes,
99+
paths: {
100+
jquery: "empty:"
101+
}
102+
}
103+
}
104+
},
105+
106+
concat: {
107+
"dist": {
108+
src: [
109+
"src/coffee/start.js",
110+
"dist/js/select2.js",
111+
"src/coffee/end.js"
112+
],
113+
dest: "dist/js/select2.js"
114+
},
115+
"dist.full": {
116+
src: [
117+
"src/coffee/start.js",
118+
"dist/js/select2.full.js",
119+
"src/coffee/end.js"
120+
],
121+
dest: "dist/js/select2.full.js"
122+
}
123+
},
124+
125+
watch: {
126+
js: {
127+
files: [
128+
"src/js/**/*.js"
129+
],
130+
tasks: [
131+
"compile",
132+
"test"
133+
]
134+
},
135+
css: {
136+
files: [
137+
"src/scss/**/*.scss"
138+
],
139+
tasks: [
140+
"compile"
141+
]
142+
}
143+
}
144+
});
145+
146+
grunt.loadNpmTasks("grunt-contrib-concat")
147+
grunt.loadNpmTasks("grunt-contrib-qunit")
148+
grunt.loadNpmTasks("grunt-contrib-requirejs")
149+
grunt.loadNpmTasks("grunt-contrib-uglify")
150+
grunt.loadNpmTasks("grunt-contrib-watch")
151+
152+
grunt.loadNpmTasks("grunt-sass")
153+
154+
grunt.registerTask("default", ["compile", "test", "minify"])
155+
156+
grunt.registerTask("compile", ["requirejs", "sass:dev", "concat"])
157+
grunt.registerTask("minify", ["uglify", "sass:dist"])
158+
grunt.registerTask("test", ["qunit"])
159+
}

dist/css/select2.css

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
.s2-container {
2+
margin: 0;
3+
position: relative;
4+
zoom: 1;
5+
vertical-align: middle; }
6+
.s2-container.s2-active {
7+
border: 1px solid #5897fb;
8+
border-top: bottom; }
9+
.s2-container .s2-single-select {
10+
display: block;
11+
height: 26px;
12+
padding: 0 0 0 8px;
13+
overflow: hidden;
14+
position: relative;
15+
border: 1px solid #aaa;
16+
white-space: nowrap;
17+
line-height: 26px;
18+
color: #444;
19+
text-decoration: none;
20+
border-radius: 4px;
21+
background-clip: padding-box;
22+
-webkit-touch-callout: none;
23+
-webkit-user-select: none;
24+
-moz-user-select: none;
25+
-ms-user-select: none;
26+
user-select: none;
27+
background-color: #fff;
28+
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #eee), color-stop(0.5, #fff));
29+
background-image: -webkit-linear-gradient(center bottom, #eee 0%, #fff 50%);
30+
background-image: -moz-linear-gradient(center bottom, #eee 0%, #fff 50%);
31+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = '#ffffff', endColorstr = '#eeeeee', GradientType = 0);
32+
background-image: linear-gradient(to top, #eee 0%, #fff 50%); }
33+
.s2-container .s2-single-select .s2-selection {
34+
margin-right: 26px;
35+
display: block;
36+
overflow: hidden;
37+
white-space: nowrap;
38+
text-overflow: ellipsis; }
39+
.s2-container .s2-open .select2-container-active .select2-choice, .s2-container .s2-open .select2-container-active .select2-choices {
40+
border: 1px solid #5897fb;
41+
outline: none;
42+
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
43+
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); }
44+
45+
.s2-search input {
46+
-webkit-box-sizing: border-box;
47+
/* webkit */
48+
-moz-box-sizing: border-box;
49+
/* firefox */
50+
box-sizing: border-box;
51+
/* css3 */ }
52+
53+
.s2-dropdown {
54+
width: 100%;
55+
margin-top: -1px;
56+
position: absolute;
57+
z-index: 9999;
58+
overflow: scroll;
59+
background: #fff;
60+
color: #000;
61+
border: 1px solid #5897fb;
62+
border-top: none;
63+
border-radius: 0 0 4px 4px;
64+
-webkit-box-shadow: 0 4px 5px rgba(0, 0, 0, 0.15);
65+
box-shadow: 0 4px 5px rgba(0, 0, 0, 0.15); }
66+
67+
.s2-hidden {
68+
display: none; }

dist/css/select2.min.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.amd.full.js

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
define('select2/utils',[], function () {
2+
var Utils = {};
3+
4+
Utils.Extend = function (ChildClass, SuperClass) {
5+
var __hasProp = {}.hasOwnProperty
6+
7+
function BaseConstructor () {
8+
this.constructor = ChildClass;
9+
}
10+
11+
for (var key in SuperClass) {
12+
if (__hasProp.call(SuperClass, key)) {
13+
ChildClass[key] = SuperClass[key];
14+
}
15+
}
16+
17+
BaseConstructor.prototype = SuperClass.prototype;
18+
ChildClass.prototype = new BaseConstructor();
19+
ChildClass.__super__ = SuperClass.prototype;
20+
21+
return ChildClass;
22+
};
23+
24+
var Observable = function () {
25+
this.listeners = {};
26+
};
27+
28+
Observable.prototype.on = function (event, callback) {
29+
if (event in this.listeners) {
30+
this.listeners[event].push(callback);
31+
} else {
32+
this.listeners[event] = [callback];
33+
}
34+
};
35+
36+
Observable.prototype.trigger = function (event) {
37+
if (event in this.listeners) {
38+
this.invoke(this.listeners[event], util.shift(arguments));
39+
}
40+
41+
if ("*" in this.listeners) {
42+
this.invoke(this.listeners["*"], arguments);
43+
}
44+
};
45+
46+
Observable.prototype.invoke = function (listeners, params) {
47+
for (var i = 0, len = listeners.length; i < len; i++) {
48+
listeners[i].apply(this, params);
49+
}
50+
};
51+
52+
Utils.Observable = Observable;
53+
54+
return Utils;
55+
});
56+
57+
define('select2/adapters/select',[
58+
"../utils"
59+
], function (Utils) {
60+
function SelectAdapter (element, options) {
61+
this.element = element;
62+
}
63+
64+
Utils.Extend(SelectAdapter, Utils.Observable);
65+
66+
return SelectAdapter;
67+
});
68+
69+
define('select2/options',[
70+
"./adapters/select"
71+
], function (SelectAdapter) {
72+
function Options (options) {
73+
this.options = options;
74+
75+
this.DataAdapter = SelectAdapter;
76+
}
77+
78+
return Options;
79+
})
80+
;
81+
define('select2/core',[
82+
"jquery",
83+
"./options",
84+
"./utils"
85+
], function ($, Options, Utils) {
86+
var Select2 = function (element, options) {
87+
this.element = element;
88+
this.options = new Options(options);
89+
90+
this.adapter = new this.options.DataAdapter(element, options);
91+
};
92+
93+
Utils.Extend(Select2, Utils.Observable);
94+
95+
return Select2;
96+
});
97+

0 commit comments

Comments
 (0)