Skip to content

Commit a527032

Browse files
committed
Extracted core and the jQuery-Plugin from ng-virtual-select repository
0 parents  commit a527032

30 files changed

+1553
-0
lines changed

.eslintignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
gulpfile.js
2+
karma.conf.js
3+
package.json
4+
config.js
5+
demo/*
6+
dist/*

.eslintrc

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"globals": {
3+
"angular": true,
4+
"_": true,
5+
"$": true
6+
},
7+
"ecmaFeatures": { "modules": true },
8+
"rules": {
9+
"linebreak-style": [2, "unix"],
10+
"semi": [2, "always"],
11+
"no-console": 0,
12+
"array-bracket-spacing": [2, "never"],
13+
"no-use-before-define": [2, "nofunc"],
14+
"no-unused-vars": 2,
15+
"max-len": [2, 120, 4]
16+
},
17+
"env": {
18+
"browser": true,
19+
"es6": true,
20+
"jquery": true
21+
},
22+
"extends": "airbnb/base"
23+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.tmp
2+
node_modules
3+
jspm_packages

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: node_js
2+
node_js:
3+
- "4.2"
4+
before_install:
5+
- npm install -g npm@'>=3.0.0'
6+
- npm --version

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Daniel Bechler
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# virtual-select
2+
This component aims to work well in rare scenarios in which `select2` or `selectize` don't cut it. Not because they are bad (which they are definitely not!), but because of horrible, horrible constraints of the project environment. Like being forced to pre-load and display all entries in the dropdown at once, because the backend request is incredibly slow. When we're talking about a couple thousand entries, this can become very slow and inefficient.
3+
4+
virtual-select is designed to minimize DOM manipulations and memory consumption, in order to deal with large amounts of data.

config.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
System.config({
2+
defaultJSExtensions: true,
3+
transpiler: "babel",
4+
babelOptions: {
5+
"optional": [
6+
"runtime",
7+
"optimisation.modules.system",
8+
],
9+
},
10+
paths: {
11+
"github:*": "jspm_packages/github/*",
12+
"npm:*": "jspm_packages/npm/*",
13+
},
14+
15+
map: {
16+
"array.prototype.findindex": "npm:[email protected]",
17+
"babel": "npm:[email protected]",
18+
"babel-runtime": "npm:[email protected]",
19+
"core-js": "npm:[email protected]",
20+
"jquery": "src/adapter/jquery-adapter.js",
21+
"lodash": "npm:[email protected]",
22+
"github:jspm/[email protected]": {
23+
"assert": "npm:[email protected]",
24+
},
25+
"github:jspm/[email protected]": {
26+
"path-browserify": "npm:[email protected]",
27+
},
28+
"github:jspm/[email protected]": {
29+
"process": "npm:[email protected]",
30+
},
31+
"github:jspm/[email protected]": {
32+
"util": "npm:[email protected]",
33+
},
34+
35+
"util": "npm:[email protected]",
36+
},
37+
38+
"process": "github:jspm/[email protected]",
39+
},
40+
41+
"fs": "github:jspm/[email protected]",
42+
"path": "github:jspm/[email protected]",
43+
"process": "github:jspm/[email protected]",
44+
"systemjs-json": "github:systemjs/[email protected]",
45+
},
46+
47+
"util": "github:jspm/[email protected]",
48+
},
49+
50+
"process": "github:jspm/[email protected]",
51+
},
52+
53+
"process": "github:jspm/[email protected]",
54+
},
55+
56+
"assert": "github:jspm/[email protected]",
57+
},
58+
59+
"inherits": "npm:[email protected]",
60+
"process": "github:jspm/[email protected]",
61+
},
62+
},
63+
});

demo/app.js

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
'use strict';
2+
3+
var DataProvider = function() {
4+
this.availableItems = null;
5+
this.items = null;
6+
};
7+
DataProvider.prototype.load = function() {
8+
var deferred = Q.defer();
9+
var self = this;
10+
if (this.availableItems) {
11+
deferred.resolve();
12+
} else {
13+
// this timeout only exists to give the loading indicator a chance to appear for demo purposes.
14+
setTimeout(function() {
15+
self.availableItems = [];
16+
for (var i = 1; i < 1000; i++) {
17+
self.availableItems.push({
18+
id: '' + i,
19+
name: '' + i,
20+
});
21+
}
22+
self.items = self.availableItems;
23+
deferred.resolve();
24+
}, 1000);
25+
}
26+
return deferred.promise;
27+
};
28+
DataProvider.prototype.filter = function(search) {
29+
if (search.length > 0) {
30+
this.items = _.filter(this.availableItems, function(item) {
31+
return item.name.indexOf(search) === 0;
32+
});
33+
} else {
34+
this.items = this.availableItems;
35+
}
36+
};
37+
DataProvider.prototype.get = function(firstItem, lastItem) {
38+
return this.items.slice(firstItem, lastItem);
39+
};
40+
DataProvider.prototype.size = function() {
41+
return this.items.length;
42+
};
43+
DataProvider.prototype.identity = function(item) {
44+
return item.id;
45+
};
46+
DataProvider.prototype.displayText = function(item, extended) {
47+
if (item) {
48+
return extended ? item.name + ' (' + item.id + ')' : item.name;
49+
} else {
50+
return '';
51+
}
52+
};
53+
DataProvider.prototype.noSelectionText = function() {
54+
return 'Please choose';
55+
};
56+
var dataProvider = new DataProvider();
57+
58+
$(document).ready(function() {
59+
60+
$('.demo-virtual-select').virtualselect({
61+
dataProvider: dataProvider,
62+
onSelect: function(item) {
63+
$('.demo-virtual-select--selection').text(JSON.stringify(item));
64+
},
65+
});
66+
67+
$('#select').click(function() {
68+
$('.demo-virtual-select').virtualselect('select', {
69+
"id": "5",
70+
"name": "5",
71+
});
72+
});
73+
74+
$('#focus').click(function() {
75+
$('.demo-virtual-select').virtualselect('focus');
76+
});
77+
78+
$('#fetch').click(function() {
79+
$('.demo-virtual-select').virtualselect('load');
80+
});
81+
82+
});

demo/index.html

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>virtual-select-jquery</title>
6+
<link rel="stylesheet" href="main.css">
7+
<link rel="stylesheet" href="../dist/virtual-select.css">
8+
</head>
9+
10+
<body>
11+
12+
<script src="../node_modules/lodash/index.js"></script>
13+
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
14+
<script src="../node_modules/q/q.js"></script>
15+
<script src="../dist/virtual-select-jquery.min.js"></script>
16+
<script src="app.js"></script>
17+
18+
<section>
19+
<p>
20+
<input type="button" id="fetch" value="Pre-load!">
21+
<input type="button" id="select" value="Select something!">
22+
<input type="button" id="focus" value="Focus!">
23+
</p>
24+
25+
<div class="demo-virtual-select"></div>
26+
27+
<p class="demo-virtual-select--selection"></p>
28+
</section>
29+
30+
</body>
31+
32+
</html>

demo/main.css

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*,
2+
*:before,
3+
*:after {
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
padding: 20px;
9+
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
10+
}

dist/virtual-select-jquery.min.js

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

dist/virtual-select-jquery.min.js.map

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

dist/virtual-select.css

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

dist/virtual-select.css.map

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

gulpfile.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const gulp = require('gulp'),
2+
sourcemaps = require('gulp-sourcemaps'),
3+
autoprefixer = require('gulp-autoprefixer'),
4+
concat = require('gulp-concat'),
5+
templateCache = require('gulp-angular-templatecache'),
6+
babel = require('gulp-babel'),
7+
del = require('del'),
8+
path = require('path'),
9+
jspm = require('gulp-jspm'),
10+
rename = require('gulp-rename'),
11+
KarmaServer = require('karma').Server;
12+
13+
const options = {
14+
buildDir: 'dist/',
15+
};
16+
17+
gulp.task('css', () => {
18+
return gulp.src('src/*.css')
19+
.pipe(sourcemaps.init())
20+
.pipe(autoprefixer({
21+
browsers: ['last 2 versions'],
22+
cascade: false,
23+
}))
24+
.pipe(sourcemaps.write('.'))
25+
.pipe(gulp.dest(options.buildDir));
26+
});
27+
28+
gulp.task('javascript', () => {
29+
return gulp.src('src/virtual-select-jquery.js')
30+
.pipe(sourcemaps.init())
31+
.pipe(jspm({
32+
selfExecutingBundle: true,
33+
minify: true,
34+
}))
35+
.pipe(rename('virtual-select-jquery.min.js'))
36+
.pipe(sourcemaps.write('.'))
37+
.pipe(gulp.dest(options.buildDir));
38+
});
39+
40+
gulp.task('test', (done) => {
41+
new KarmaServer({
42+
configFile: __dirname + '/karma.conf.js',
43+
singleRun: true,
44+
browsers: ['PhantomJS'],
45+
}, done).start();
46+
});
47+
48+
gulp.task('clean', () => {
49+
return del([options.buildDir]);
50+
});
51+
52+
gulp.task('build', ['css', 'javascript']);
53+
54+
gulp.task('develop', ['build'], () => {
55+
gulp.watch('src/**/*.css', ['css']);
56+
gulp.watch('src/**/*.js', ['javascript']);
57+
});
58+
59+
gulp.task('release', ['build']);
60+
gulp.task('default', ['develop']);

0 commit comments

Comments
 (0)