Skip to content

Commit 2fd82e1

Browse files
committed
Initial commit
1 parent 13788bd commit 2fd82e1

13 files changed

+348
-1
lines changed

.coveralls.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
service_name: travis-ci
2+

.jscs.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"preset": "google",
3+
"maximumLineLength": 100
4+
}

.jshintrc

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"undef": true,
3+
"unused": true,
4+
"browser": true,
5+
"globals": {
6+
"console":false,
7+
"jQuery": false,
8+
"$":false,
9+
"assertEquals": false,
10+
"jstestdriver": false,
11+
"assertTrue": false,
12+
"assertFalse": false,
13+
"describe": false,
14+
"it":false,
15+
"expect": false,
16+
"sinon":false,
17+
"beforeEach": false,
18+
"afterEach": false,
19+
"angular": false,
20+
"module": false,
21+
"inject": false,
22+
"chai": false,
23+
"should": false,
24+
"Jed": false,
25+
"tws": false
26+
}
27+
}

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: node_js
2+
node_js:
3+
- 0.10
4+
5+
before_script:
6+
- npm install -g bower
7+
- bower install

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Example
4444
<script type="text/javascript" src="/bower_components/spectrum/spectrum.js"></script>
4545
<script type="text/javascript" src="/bower_components/spectrum/i18n/jquery.spectrum-sv.js"></script>
4646
<script type="text/javascript" src="/bower_components/angular-spectrum-colorpicker/dist/angular-spectrum-colorpicker.min.js"></script>
47-
<script type="text/javascript" src="/bower_components/angular-schema-form-colorpicker/angular-schema-form-colorpicker.min.js"></script>
47+
<script type="text/javascript" src="/bower_components/angular-schema-form-colorpicker/bootstrap-colorpicker.min.js"></script>
4848

4949
<link rel="stylesheet" href="/bower_components/spectrum/spectrum.css">
5050
```

bower.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "angular-schema-form-colorpicker",
3+
"main": [
4+
"bootstrap-colorpicker.min.js"
5+
],
6+
"version": "0.1.0",
7+
"authors": [
8+
"Textalk",
9+
"Denis Dervisevic <[email protected]>",
10+
"David Jensen <[email protected]>"
11+
],
12+
"moduleType": [
13+
"globals"
14+
],
15+
"keywords": [
16+
"angular-schema-form",
17+
"schema-form",
18+
"form",
19+
"json",
20+
"json-schema",
21+
"schema"
22+
],
23+
"license": "MIT",
24+
"ignore": [
25+
"**/.*",
26+
"node_modules",
27+
"bower_components",
28+
"test",
29+
"coverage"
30+
],
31+
"dependencies": {
32+
"angular-spectrum-colorpicker": ">= 1.2.0"
33+
},
34+
"devDependencies": {
35+
"angular-schema-form": ">= 0.7",
36+
"angular-mocks": ">= 1.2"
37+
}
38+
}

gulpfile.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* global require */
2+
3+
var gulp = require('gulp');
4+
5+
var templateCache = require('gulp-angular-templatecache');
6+
var minifyHtml = require('gulp-minify-html');
7+
var concat = require('gulp-concat');
8+
var uglify = require('gulp-uglify');
9+
var streamqueue = require('streamqueue');
10+
var jscs = require('gulp-jscs');
11+
12+
gulp.task('minify', function() {
13+
var stream = streamqueue({objectMode: true});
14+
stream.queue(
15+
gulp.src('./src/*.html')
16+
.pipe(minifyHtml({
17+
empty: true,
18+
spare: true,
19+
quotes: true
20+
}))
21+
.pipe(templateCache({
22+
module: 'schemaForm',
23+
root: 'directives/decorators/bootstrap/colorpicker/'
24+
}))
25+
);
26+
stream.queue(gulp.src('./src/*.js'));
27+
28+
stream.done()
29+
.pipe(concat('bootstrap-colorpicker.min.js'))
30+
.pipe(uglify())
31+
.pipe(gulp.dest('.'));
32+
33+
});
34+
35+
gulp.task('non-minified-dist', function() {
36+
var stream = streamqueue({objectMode: true});
37+
stream.queue(
38+
gulp.src('./src/*.html')
39+
.pipe(templateCache({
40+
module: 'schemaForm',
41+
root: 'directives/decorators/bootstrap/colorpicker/'
42+
}))
43+
);
44+
stream.queue(gulp.src('./src/*.js'));
45+
46+
stream.done()
47+
.pipe(concat('bootstrap-colorpicker.js'))
48+
.pipe(gulp.dest('.'));
49+
50+
});
51+
52+
gulp.task('jscs', function() {
53+
gulp.src('./src/**/*.js')
54+
.pipe(jscs());
55+
});
56+
57+
gulp.task('default', [
58+
'minify',
59+
'non-minified-dist',
60+
'jscs'
61+
]);
62+
63+
gulp.task('watch', function() {
64+
gulp.watch('./src/**/*', ['default']);
65+
});

karma.conf.js

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
2+
module.exports = function(config) {
3+
config.set({
4+
5+
// base path, that will be used to resolve files and exclude
6+
basePath: '.',
7+
8+
// frameworks to use
9+
frameworks: ['mocha', 'chai-sinon'],
10+
11+
// list of files / patterns to load in the browser
12+
files: [
13+
'bower_components/jquery/dist/jquery.min.js',
14+
'bower_components/angular/angular.js',
15+
'bower_components/angular-mocks/angular-mocks.js',
16+
'bower_components/angular-schema-form/dist/schema-form.js',
17+
'bower_components/angular-schema-form/dist/bootstrap-decorator.min.js',
18+
'bower_components/objectpath/lib/ObjectPath.js',
19+
'src/*.js',
20+
'src/**/*.html',
21+
'test/tests.js'
22+
],
23+
24+
// list of files to exclude
25+
exclude: [
26+
27+
],
28+
29+
// test results reporter to use
30+
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
31+
reporters: ['progress', 'coverage', 'growler'],
32+
33+
preprocessors: {
34+
'src/**/*.js': ['coverage'],
35+
'src/**/*.html': ['ng-html2js']
36+
},
37+
38+
// optionally, configure the reporter
39+
coverageReporter: {
40+
type : 'lcov',
41+
dir : 'coverage/'
42+
},
43+
44+
ngHtml2JsPreprocessor: {
45+
cacheIdFromPath: function(filepath) {
46+
return 'directives/decorators/bootstrap/colorpicker/' + filepath.substr(4);
47+
},
48+
moduleName: 'templates'
49+
},
50+
51+
// web server port
52+
port: 9876,
53+
54+
// enable / disable colors in the output (reporters and logs)
55+
colors: true,
56+
57+
// level of logging
58+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
59+
logLevel: config.LOG_INFO,
60+
61+
62+
// enable / disable watching file and executing tests whenever any file changes
63+
autoWatch: true,
64+
65+
66+
// Start these browsers, currently available:
67+
// - Chrome
68+
// - ChromeCanary
69+
// - Firefox
70+
// - Opera (has to be installed with `npm install karma-opera-launcher`)
71+
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
72+
// - PhantomJS
73+
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
74+
browsers: ['PhantomJS'],
75+
76+
77+
// If browser does not capture in given timeout [ms], kill it
78+
captureTimeout: 60000,
79+
80+
81+
// Continuous Integration mode
82+
// if true, it capture browsers, run tests and exit
83+
singleRun: false
84+
});
85+
};

package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "angular-schema-form-colorpicker",
3+
"version": "0.1.0",
4+
"description": "Colorpicker add-on for schema form",
5+
"scripts": {
6+
"test": "rm -fr coverage && ./node_modules/karma/bin/karma start --single-run --browsers PhantomJS karma.conf.js"
7+
},
8+
"author": "Textalk",
9+
"license": "MIT",
10+
"devDependencies": {
11+
"chai": "^1.9.0",
12+
"coveralls": "^2.11.0",
13+
"gulp": "^3.5.6",
14+
"gulp-angular-templatecache": "^1.2.1",
15+
"gulp-concat": "^2.2.0",
16+
"gulp-jscs": "^1.1.0",
17+
"gulp-minify-html": "^0.1.1",
18+
"gulp-uglify": "^0.2.1",
19+
"karma": "^0.12.0",
20+
"karma-chai-sinon": "^0.1.3",
21+
"karma-coverage": "^0.2.1",
22+
"karma-growler-reporter": "0.0.1",
23+
"karma-mocha": "^0.1.3",
24+
"karma-ng-html2js-preprocessor": "^0.1.0",
25+
"karma-phantomjs-launcher": "^0.1.4",
26+
"mocha": "^1.18.0",
27+
"mocha-lcov-reporter": "0.0.1",
28+
"sinon": "^1.9.0",
29+
"sinon-chai": "^2.5.0",
30+
"streamqueue": "0.0.5"
31+
}
32+
}

src/.DS_Store

6 KB
Binary file not shown.

src/bootstrap-colorpicker.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
angular.module('schemaForm').config(
2+
['schemaFormProvider', 'schemaFormDecoratorsProvider', 'sfPathProvider',
3+
function(schemaFormProvider, schemaFormDecoratorsProvider, sfPathProvider) {
4+
5+
var colorpicker = function(name, schema, options) {
6+
if (schema.type === 'string' && schema.format == 'color') {
7+
var f = schemaFormProvider.stdFormObj(name, schema, options);
8+
f.key = options.path;
9+
f.type = 'colorpicker';
10+
options.lookup[sfPathProvider.stringify(options.path)] = f;
11+
return f;
12+
}
13+
};
14+
15+
schemaFormProvider.defaults.string.unshift(colorpicker);
16+
17+
//Add to the bootstrap directive
18+
schemaFormDecoratorsProvider.addMapping('bootstrapDecorator', 'colorpicker',
19+
'directives/decorators/bootstrap/colorpicker/colorpicker.html');
20+
schemaFormDecoratorsProvider.createDirective('colorpicker',
21+
'directives/decorators/bootstrap/colorpicker/colorpicker.html');
22+
}]);

src/colorpicker.html

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<div class="form-group" ng-class="{'has-error': hasError()}">
2+
<label class="control-label" ng-show="showTitle()">{{form.title}}</label>
3+
<div>
4+
<spectrum-colorpicker
5+
ng-model="$$value$$"
6+
format="form.colorFormat || 'rgb'"
7+
style="background-color: white"
8+
type="color"
9+
schema-validate="form"
10+
options="form.spectrumOptions || {
11+
showInput: true,
12+
showAlpha: true,
13+
allowEmpty: true,
14+
showPalette: true,
15+
preferredFormat: form.colorFormat || 'rgb',
16+
palette: [['#fce94f', '#fcaf3e', '#e9b96e'],
17+
['#8ae234', '#729fcf', '#ad7fa8'],
18+
['#ef2929', '#888a85', '#deface']]
19+
}"></spectrum-colorpicker>
20+
</div>
21+
<span class="help-block">{{ (hasError() && errorMessage(schemaError())) || form.description}}</span>
22+
</div>

test/tests.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* jshint expr: true */
2+
chai.should();
3+
4+
describe('Schema form', function() {
5+
6+
describe('directive', function() {
7+
beforeEach(module('templates'));
8+
beforeEach(module('schemaForm'));
9+
beforeEach(
10+
//We don't need no sanitation. We don't need no though control.
11+
module(function($sceProvider) {
12+
$sceProvider.enabled(false);
13+
})
14+
);
15+
16+
it('should return correct form type for format "color"',function(){
17+
inject(function($compile,$rootScope, schemaForm){
18+
var string_schema = {
19+
type: "object",
20+
properties: {
21+
color: {
22+
type: "string",
23+
}
24+
}
25+
};
26+
27+
var color_schema = {
28+
type: "object",
29+
properties: {
30+
color: {
31+
type: "string",
32+
format: "color"
33+
}
34+
}
35+
};
36+
37+
schemaForm.defaults(string_schema).form[0].type.should.be.eq("text");
38+
schemaForm.defaults(color_schema).form[0].type.should.be.eq("colorpicker");
39+
});
40+
});
41+
42+
});
43+
});

0 commit comments

Comments
 (0)