Skip to content

Commit

Permalink
fix #140,
Browse files Browse the repository at this point in the history
also fix a bug which is caused by the PR #131 when static value option is used. just as the basic example
  • Loading branch information
lordfriend committed Aug 3, 2016
1 parent cfcb255 commit 23235f2
Show file tree
Hide file tree
Showing 16 changed files with 419 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nya-bootstrap-select",
"version": "2.1.6",
"version": "2.1.7",
"main": [
"dist/js/nya-bs-select.js",
"dist/css/nya-bs-select.css"
Expand Down
2 changes: 1 addition & 1 deletion dist/css/nya-bs-select.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* nya-bootstrap-select v2.1.6
* nya-bootstrap-select v2.1.7
* Copyright 2014 Nyasoft
* Licensed under MIT license
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/css/nya-bs-select.min.css

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

29 changes: 22 additions & 7 deletions dist/js/nya-bs-select.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* nya-bootstrap-select v2.1.6
* nya-bootstrap-select v2.1.7
* Copyright 2014 Nyasoft
* Licensed under MIT license
*/
Expand Down Expand Up @@ -508,9 +508,9 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
dropdownToggle.addClass(className);
}

if(className === 'form-control') {
dropdownToggle.addClass(className);
}
// if(className === 'form-control') {
// dropdownToggle.addClass(className);
// }
});

dropdownMenu.append(options);
Expand Down Expand Up @@ -1290,8 +1290,10 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
length = bsOptionElements.length,
optionTitle,
selection = [],
optionScopes = [],
match,
count;
count,
clone;

if(isMultiple && $attrs.selectedTextFormat === 'count') {
count = 1;
Expand Down Expand Up @@ -1328,6 +1330,7 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
selection.push(document.createTextNode(optionTitle));
} else {
selection.push(getOptionText(nyaBsOption));
optionScopes.push(nyaBsOption.data('isolateScope'))
}

}
Expand All @@ -1338,6 +1341,7 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
selection.push(document.createTextNode(optionTitle));
} else {
selection.push(getOptionText(nyaBsOption));
optionScopes.push(nyaBsOption.data('isolateScope'))
}
}
}
Expand All @@ -1352,12 +1356,23 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
dropdownToggle.removeClass('show-special-title');
// either single or multiple selection will show the only selected content.
filterOption.empty();
filterOption.append(selection[0]);
// the isolateScope attribute may not set when we use the static version nya-bs-option class with data-value attribute.
if(optionScopes[0]) {
clone = $compile (selection[0])(optionScopes[0]);
} else {
clone = selection[0];
}
filterOption.append(clone);
} else {
dropdownToggle.removeClass('show-special-title');
filterOption.empty();
for(index = 0; index < selection.length; index++) {
filterOption.append(selection[index]);
if(optionScopes[index]) {
clone = $compile (selection[index])(optionScopes[index]);
} else {
clone = selection[index];
}
filterOption.append(clone);
if(index < selection.length -1) {
filterOption.append(document.createTextNode(', '));
}
Expand Down
4 changes: 2 additions & 2 deletions dist/js/nya-bs-select.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/dist/css/main.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* nya-bootstrap-select v2.1.6
* nya-bootstrap-select v2.1.7
* Copyright 2014 Nyasoft
* Licensed under MIT license
*/
Expand Down
2 changes: 1 addition & 1 deletion docs/dist/css/nya-bs-select.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* nya-bootstrap-select v2.1.6
* nya-bootstrap-select v2.1.7
* Copyright 2014 Nyasoft
* Licensed under MIT license
*/
Expand Down
Binary file added docs/dist/fonts/glyphicons-halflings-regular.eot
Binary file not shown.
288 changes: 288 additions & 0 deletions docs/dist/fonts/glyphicons-halflings-regular.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/dist/fonts/glyphicons-halflings-regular.ttf
Binary file not shown.
Binary file added docs/dist/fonts/glyphicons-halflings-regular.woff
Binary file not shown.
Binary file not shown.
29 changes: 22 additions & 7 deletions docs/dist/js/nya-bs-select.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* nya-bootstrap-select v2.1.6
* nya-bootstrap-select v2.1.7
* Copyright 2014 Nyasoft
* Licensed under MIT license
*/
Expand Down Expand Up @@ -508,9 +508,9 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
dropdownToggle.addClass(className);
}

if(className === 'form-control') {
dropdownToggle.addClass(className);
}
// if(className === 'form-control') {
// dropdownToggle.addClass(className);
// }
});

dropdownMenu.append(options);
Expand Down Expand Up @@ -1290,8 +1290,10 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
length = bsOptionElements.length,
optionTitle,
selection = [],
optionScopes = [],
match,
count;
count,
clone;

if(isMultiple && $attrs.selectedTextFormat === 'count') {
count = 1;
Expand Down Expand Up @@ -1328,6 +1330,7 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
selection.push(document.createTextNode(optionTitle));
} else {
selection.push(getOptionText(nyaBsOption));
optionScopes.push(nyaBsOption.data('isolateScope'))
}

}
Expand All @@ -1338,6 +1341,7 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
selection.push(document.createTextNode(optionTitle));
} else {
selection.push(getOptionText(nyaBsOption));
optionScopes.push(nyaBsOption.data('isolateScope'))
}
}
}
Expand All @@ -1352,12 +1356,23 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
dropdownToggle.removeClass('show-special-title');
// either single or multiple selection will show the only selected content.
filterOption.empty();
filterOption.append(selection[0]);
// the isolateScope attribute may not set when we use the static version nya-bs-option class with data-value attribute.
if(optionScopes[0]) {
clone = $compile (selection[0])(optionScopes[0]);
} else {
clone = selection[0];
}
filterOption.append(clone);
} else {
dropdownToggle.removeClass('show-special-title');
filterOption.empty();
for(index = 0; index < selection.length; index++) {
filterOption.append(selection[index]);
if(optionScopes[index]) {
clone = $compile (selection[index])(optionScopes[index]);
} else {
clone = selection[index];
}
filterOption.append(clone);
if(index < selection.length -1) {
filterOption.append(document.createTextNode(', '));
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nya-bootstrap-select",
"version": "2.1.6",
"version": "2.1.7",
"description": "An angular directive wraps bootstrap-select",
"repository": {
"type": "git",
Expand Down
19 changes: 14 additions & 5 deletions src/nya-bs-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
dropdownToggle.addClass(className);
}

if(className === 'form-control') {
dropdownToggle.addClass(className);
}
// if(className === 'form-control') {
// dropdownToggle.addClass(className);
// }
});

dropdownMenu.append(options);
Expand Down Expand Up @@ -946,13 +946,22 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
dropdownToggle.removeClass('show-special-title');
// either single or multiple selection will show the only selected content.
filterOption.empty();
clone = $compile (selection[0])(optionScopes[0]);
// the isolateScope attribute may not set when we use the static version nya-bs-option class with data-value attribute.
if(optionScopes[0]) {
clone = $compile (selection[0])(optionScopes[0]);
} else {
clone = selection[0];
}
filterOption.append(clone);
} else {
dropdownToggle.removeClass('show-special-title');
filterOption.empty();
for(index = 0; index < selection.length; index++) {
clone = $compile (selection[index])(optionScopes[index]);
if(optionScopes[index]) {
clone = $compile (selection[index])(optionScopes[index]);
} else {
clone = selection[index];
}
filterOption.append(clone);
if(index < selection.length -1) {
filterOption.append(document.createTextNode(', '));
Expand Down
65 changes: 65 additions & 0 deletions test/spec/static-feature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Features for static option data-value
*/

describe('static feature', function() {
var $scope,
$compile,
$timeout;

beforeEach(module('nya.bootstrap.select'));

beforeEach(inject(function(_$rootScope_, _$compile_, _$timeout_){
$scope = _$rootScope_.$new();
$compile = _$compile_;
$timeout = _$timeout_;
}));

it('should update ngModel value when click some option', function() {
// check list whether an selected element has a selected class
function check() {
var list = selectElement.find('ul').children();
var i, length = list.length,
liElement,
scopeOfOption,
value;
for(i = 0; i < length; i++) {
liElement = list.eq(i);
if(liElement.hasClass('nya-bs-option')) {
value = liElement.attr('data-value');
if(value === $scope.model) {
expect(liElement).toHaveClass('selected');
} else {
expect(liElement).not.toHaveClass('selected');
}
}
}
}
$scope.model = 'a';

$scope.$digest();
var selectElement = angular.element('<ol class="nya-bs-select" ng-model="model">' +
'<li class="nya-bs-option" data-value="a">' +
'<a>Alpha</a>' +
'</li>' +
'<li class="nya-bs-option" data-value="b">' +
'<a>Bravo</a>' +
'</li>' +
'<li class="nya-bs-option" data-value="c">' +
'<a>Charlie</a>' +
'</li>' +
'</ol>');
$compile(selectElement)($scope);

$scope.$digest();

check();

$scope.model = 'b';
$scope.$digest();

check();

});

});

0 comments on commit 23235f2

Please sign in to comment.