Skip to content

Commit

Permalink
Add gulpfile.js with angular-chosen.min.js at /dist #165
Browse files Browse the repository at this point in the history
  • Loading branch information
leocaseiro committed Mar 1, 2016
1 parent 8bd7354 commit f1132db
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 142 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bower_components/
node_modules/
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "git",
"url": "git://github.com/leocaseiro/angular-chosen.git"
},
"main": "chosen.js",
"main": "dist/angular-chosen.js",
"dependencies": {
"chosen": "^1.1.0",
"angular": "^1.2.0"
Expand Down
136 changes: 1 addition & 135 deletions chosen.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 137 additions & 0 deletions dist/angular-chosen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* angular-chosen-localytics - Angular Chosen directive is an AngularJS Directive that brings the Chosen jQuery in a Angular way
* @version v1.2.0
* @link http://github.com/leocaseiro/angular-chosen
* @license MIT
*/
var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

angular.module('localytics.directives', []);

angular.module('localytics.directives').directive('chosen', [
'$timeout', function($timeout) {
var CHOSEN_OPTION_WHITELIST, NG_OPTIONS_REGEXP, isEmpty, snakeCase;
NG_OPTIONS_REGEXP = /^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(.*?)(?:\s+track\s+by\s+(.*?))?$/;
CHOSEN_OPTION_WHITELIST = ['noResultsText', 'allowSingleDeselect', 'disableSearchThreshold', 'disableSearch', 'enableSplitWordSearch', 'inheritSelectClasses', 'maxSelectedOptions', 'placeholderTextMultiple', 'placeholderTextSingle', 'searchContains', 'singleBackstrokeDelete', 'displayDisabledOptions', 'displaySelectedOptions', 'width'];
snakeCase = function(input) {
return input.replace(/[A-Z]/g, function($1) {
return "_" + ($1.toLowerCase());
});
};
isEmpty = function(value) {
var key;
if (angular.isArray(value)) {
return value.length === 0;
} else if (angular.isObject(value)) {
for (key in value) {
if (value.hasOwnProperty(key)) {
return false;
}
}
}
return true;
};
return {
restrict: 'A',
require: '?ngModel',
priority: 1,
link: function(scope, element, attr, ngModel) {
var chosen, defaultText, disableWithMessage, empty, initOrUpdate, match, options, origRender, removeEmptyMessage, startLoading, stopLoading, valuesExpr, viewWatch;
scope.disabledValuesHistory = scope.disabledValuesHistory ? scope.disabledValuesHistory : [];
element.addClass('localytics-chosen');
options = scope.$eval(attr.chosen) || {};
angular.forEach(attr, function(value, key) {
if (indexOf.call(CHOSEN_OPTION_WHITELIST, key) >= 0) {
return options[snakeCase(key)] = String(element.attr(attr.$attr[key])).slice(0, 2) === '{{' ? value : scope.$eval(value);
}
});
startLoading = function() {
var disabledValueOfElement, elementAlreadyExists;
disabledValueOfElement = {};
elementAlreadyExists = false;
angular.forEach(scope.disabledValuesHistory, function(data) {
if (data.hasOwnProperty(element.context.id)) {
data[element.context.id] = element.context.disabled;
elementAlreadyExists = true;
}
});
if (!elementAlreadyExists) {
disabledValueOfElement[element.context.id] = element.context.disabled;
scope.disabledValuesHistory.push(disabledValueOfElement);
}
return element.addClass('loading').attr('disabled', true).trigger('chosen:updated');
};
stopLoading = function() {
var disabledValue;
disabledValue = false;
angular.forEach(scope.disabledValuesHistory, function(data) {
disabledValue = data.hasOwnProperty(element.context.id) ? data[element.context.id] : disabledValue;
});
return element.removeClass('loading').attr('disabled', disabledValue).trigger('chosen:updated');
};
chosen = null;
defaultText = null;
empty = false;
initOrUpdate = function() {
if (chosen) {
return element.trigger('chosen:updated');
} else {
chosen = element.chosen(options);
return defaultText = chosen.default_text;
}
};
removeEmptyMessage = function() {
empty = false;
return element.attr('data-placeholder', defaultText).trigger('chosen:updated');
};
disableWithMessage = function() {
empty = true;
return element.attr('data-placeholder', chosen.results_none_found).attr('disabled', true).trigger('chosen:updated');
};
if (ngModel) {
origRender = ngModel.$render;
ngModel.$render = function() {
origRender();
return initOrUpdate();
};
if (attr.multiple) {
viewWatch = function() {
return ngModel.$viewValue;
};
scope.$watch(viewWatch, ngModel.$render, true);
}
} else {
initOrUpdate();
}
attr.$observe('disabled', function() {
return element.trigger('chosen:updated');
});
if (attr.ngOptions && ngModel) {
match = attr.ngOptions.match(NG_OPTIONS_REGEXP);
valuesExpr = match[7];
scope.$watchCollection(valuesExpr, function(newVal, oldVal) {
var timer;
return timer = $timeout(function() {
if (angular.isUndefined(newVal)) {
return startLoading();
} else {
if (empty) {
removeEmptyMessage();
}
stopLoading();
if (isEmpty(newVal) && !attr.allowEmptyResultsList) {
return disableWithMessage();
}
}
});
});
return scope.$on('$destroy', function(event) {
if (typeof timer !== "undefined" && timer !== null) {
return $timeout.cancel(timer);
}
});
}
}
};
}
]);
7 changes: 7 additions & 0 deletions dist/angular-chosen.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<script src="vendor/chosen.jquery.js"></script>

<script src="../chosen.js"></script>
<script src="../dist/angular-chosen.min.js"></script>
<script src="index.js"></script>

<link rel="stylesheet" type="text/css" href="vendor/chosen.css" />
Expand Down
82 changes: 82 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
var config = {
src: './src/',
dist: './dist/',
file: 'angular-chosen'
};

var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');

var args = require('yargs').argv,
gulp = require('gulp'),
del = require('del'),
$ = require('gulp-load-plugins')({ lazy: true }),
pkg = require('./package.json');

// List Tasks by default
gulp.task('default', $.taskListing.withFilters(null, ['build-hint']));

//TODO rewrite Coffee Script of coffeelint()
gulp.task('build-hint', function() {
return gulp.src(config.src + '/*.coffee')
.pipe($.if(args.debug, $.debug()))
.pipe($.plumber())
.pipe($.coffeelint())
.pipe($.coffeelint.reporter());
// .pipe($.jshint())
// .pipe($.jshint.reporter('jshint-stylish', { verbose: true }));
// .pipe($.jscs());
});

// gulp.task('build-coffee-script', ['build-hint'], function() {
/**
* Compile CoffeeScript into ./dist/angular-chose.js
*/
gulp.task('build-coffee-script', function() {
return gulp.src(config.src + '/*.coffee')
.pipe($.if(args.debug, $.debug()))
.pipe($.plumber())
.pipe($.coffee({bare: true}).on('error', $.util.log))
.pipe($.rename(config.file + '.js'))
.pipe($.header(banner, { pkg : pkg }))
.pipe(gulp.dest(config.dist));
});

/**
* Minify ./dist/angular-chose.js into ./dist/angular-chose.min.js
*/
gulp.task('build-minify', ['build-coffee-script'], function() {
return gulp.src(config.dist + '/angular-chosen.js')
.pipe($.if(args.debug, $.debug()))
.pipe($.plumber())
.pipe($.uglify({mangle: true}))
.pipe($.rename(config.file + '.min.js'))
.pipe($.header(banner, {pkg : pkg}))
.pipe(gulp.dest(config.dist));
});

/**
* Run Clean Javascripts, than minify(coffee-script)
*/
gulp.task('build', ['build-clean-javascripts'], function() {
gulp.start('build-minify');
});

/**
* Clean Javascripts from .dist/
*/
gulp.task('build-clean-javascripts', function() {
return del(config.dist);
});

/**
* Watch files and compile Coffee Script in real-time
*/
gulp.task('watcher', ['minify'], function() {
gulp.watch([config.src + '*.coffee', config.dist + '*.js'], ['minify']);
});
Loading

0 comments on commit f1132db

Please sign in to comment.