-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from machineboy2045/v3.0.0
V3.0.0
- Loading branch information
Showing
5 changed files
with
132 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## 3.0.1 (2015-09-07) | ||
|
||
Documentation: | ||
|
||
- Added CHANGELOG | ||
- Updated README concerning config.options | ||
|
||
## 3.0.0 (2015-08-07) | ||
|
||
Changes: | ||
|
||
- Dropped support for simple arrays `['Option 1', 'Option 2']` in order to simplify the directive and ensure consistent behavior. | ||
- Renamed `'selectize.js'` to `'angular-selectize.js'` to avoid confusion. | ||
- update to selectize 0.12.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"name": "angular-selectize2", | ||
"version": "1.2.3", | ||
"version": "3.0.1", | ||
"main" : [ | ||
"./dist/selectize.js" | ||
"./dist/angular-selectize.js" | ||
], | ||
"dependencies": { | ||
"selectize": ">=0.9.0" | ||
"selectize": ">=0.12.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* Angular Selectize2 | ||
* https://github.com/machineboy2045/angular-selectize | ||
**/ | ||
|
||
angular.module('selectize', []).value('selectizeConfig', {}).directive("selectize", ['selectizeConfig', function(selectizeConfig) { | ||
return { | ||
restrict: 'EA', | ||
require: '^ngModel', | ||
scope: { ngModel: '=', config: '=?', options: '=?', ngDisabled: '=', ngRequired: '&' }, | ||
link: function(scope, element, attrs, modelCtrl) { | ||
|
||
var selectize, | ||
settings = angular.extend({}, Selectize.defaults, selectizeConfig, scope.config); | ||
|
||
scope.options = scope.options || []; | ||
scope.config = scope.config || {}; | ||
|
||
var isEmpty = function(val) { | ||
return val === undefined || val === null || !val.length; //support checking empty arrays | ||
}; | ||
|
||
var toggle = function(disabled) { | ||
disabled ? selectize.disable() : selectize.enable(); | ||
} | ||
|
||
var validate = function() { | ||
var isInvalid = (scope.ngRequired() || attrs.required || settings.required) && isEmpty(scope.ngModel); | ||
modelCtrl.$setValidity('required', !isInvalid); | ||
}; | ||
|
||
var setSelectizeOptions = function(curr, prev) { | ||
angular.forEach(prev, function(opt){ | ||
if(curr.indexOf(opt) === -1){ | ||
var value = opt[settings.valueField]; | ||
selectize.removeOption(value, true); | ||
} | ||
}); | ||
|
||
selectize.addOption(curr, true); | ||
|
||
setSelectizeValue(); | ||
} | ||
|
||
var setSelectizeValue = function() { | ||
validate(); | ||
|
||
selectize.$control.toggleClass('ng-valid', modelCtrl.$valid); | ||
selectize.$control.toggleClass('ng-invalid', modelCtrl.$invalid); | ||
selectize.$control.toggleClass('ng-dirty', modelCtrl.$dirty); | ||
selectize.$control.toggleClass('ng-pristine', modelCtrl.$pristine); | ||
|
||
if (!angular.equals(selectize.items, scope.ngModel)) { | ||
selectize.setValue(scope.ngModel, true); | ||
} | ||
} | ||
|
||
settings.onChange = function(value) { | ||
var value = angular.copy(selectize.items); | ||
if (settings.maxItems == 1) { | ||
value = value[0] | ||
} | ||
modelCtrl.$setViewValue( value ); | ||
|
||
if (scope.config.onChange) { | ||
scope.config.onChange.apply(this, arguments); | ||
} | ||
}; | ||
|
||
settings.onOptionAdd = function(value, data) { | ||
if( scope.options.indexOf(data) === -1 ) { | ||
scope.options.push(data); | ||
|
||
if (scope.config.onOptionAdd) { | ||
scope.config.onOptionAdd.apply(this, arguments); | ||
} | ||
} | ||
}; | ||
|
||
settings.onInitialize = function() { | ||
selectize = element[0].selectize; | ||
|
||
setSelectizeOptions(scope.options); | ||
|
||
//provides a way to access the selectize element from an | ||
//angular controller | ||
if (scope.config.onInitialize) { | ||
scope.config.onInitialize(selectize); | ||
} | ||
|
||
scope.$watchCollection('options', setSelectizeOptions); | ||
scope.$watch('ngModel', setSelectizeValue); | ||
scope.$watch('ngDisabled', toggle); | ||
}; | ||
|
||
element.selectize(settings); | ||
|
||
element.on('$destroy', function() { | ||
if (selectize) { | ||
selectize.destroy(); | ||
element = null; | ||
} | ||
}); | ||
} | ||
}; | ||
}]); |
This file was deleted.
Oops, something went wrong.