Skip to content

Commit

Permalink
update to v2.0.6
Browse files Browse the repository at this point in the history
add document for nyaBsOptionProvider
  • Loading branch information
lordfriend committed Jan 17, 2015
1 parent 12c5968 commit 27b0fac
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 42 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.0.5",
"version": "2.0.6",
"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.0.5
* nya-bootstrap-select v2.0.6
* 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.

77 changes: 50 additions & 27 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.0.5
* nya-bootstrap-select v2.0.6
* Copyright 2014 Nyasoft
* Licensed under MIT license
*/
Expand Down Expand Up @@ -315,6 +315,8 @@ var deepEquals = angular.equals;

var deepCopy = angular.copy;

var extend = angular.extend;

var nyaBsSelect = angular.module('nya.bootstrap.select', []);


Expand All @@ -338,7 +340,7 @@ nyaBsSelect.controller('nyaBsSelectCtrl', function(){
};

});
nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', function ($parse, $document, $timeout) {
nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', 'nyaBsConfig', function ($parse, $document, $timeout, nyaBsConfig) {

var DEFAULT_NONE_SELECTION = 'Nothing selected';

Expand All @@ -364,8 +366,32 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', functio
controller: 'nyaBsSelectCtrl',
compile: function nyaBsSelectCompile (tElement, tAttrs){


tElement.addClass('btn-group');

var getDefaultNoneSelectionContent = function() {
// text node or jqLite element.
var content;

if(tAttrs.titleTpl) {
// use title-tpl attribute value.
content = jqLite(tAttrs.titleTpl);
} else if(tAttrs.title) {
// use title attribute value.
content = document.createTextNode(tAttrs.title);
} else if(localizedText.defaultNoneSelectionTpl){
// use localized text template.
content = jqLite(localizedText.defaultNoneSelectionTpl);
} else if(localizedText.defaultNoneSelection) {
// use localized text.
content = document.createTextNode(localizedText.defaultNoneSelection);
} else {
// use default.
content = document.createTextNode(DEFAULT_NONE_SELECTION);
}
return content;
};

var options = tElement.children(),
dropdownToggle = jqLite(DROPDOWN_TOGGLE),
dropdownContainer = jqLite(DROPDOWN_CONTAINER),
Expand All @@ -375,7 +401,8 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', functio
classList,
length,
index,
liElement;
liElement,
localizedText = nyaBsConfig;

classList = getClassList(tElement[0]);
classList.forEach(function(className) {
Expand Down Expand Up @@ -409,17 +436,21 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', functio

if(tAttrs.liveSearch === 'true') {
searchBox = jqLite(SEARCH_BOX);

// set localized text
if(localizedText.noSearchResultTpl) {
NO_SEARCH_RESULT = NO_SEARCH_RESULT.replace('NO SEARCH RESULT', localizedText.noSearchResultTpl);
} else if(localizedText.noSearchResult) {
NO_SEARCH_RESULT = NO_SEARCH_RESULT.replace('NO SEARCH RESULT', localizedText.noSearchResult);
}

noSearchResult = jqLite(NO_SEARCH_RESULT);
dropdownContainer.append(searchBox);
dropdownMenu.append(noSearchResult);
}

// set default none selection text
if(tAttrs.title) {
dropdownToggle.children().eq(0).text(tAttrs.title);
} else {
dropdownToggle.children().eq(0).text(DEFAULT_NONE_SELECTION);
}
dropdownToggle.children().eq(0).append(getDefaultNoneSelectionContent());

dropdownContainer.append(dropdownMenu);

Expand Down Expand Up @@ -1013,15 +1044,8 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', functio
return;
}
if(isMultiple && modelValue.length === 0) {
if($attrs.title) {
// use title attribute value.
filterOption.empty();
filterOption.append(document.createTextNode($attrs.title));
} else {
// use default text.
filterOption.empty();
filterOption.append(document.createTextNode(DEFAULT_NONE_SELECTION));
}
filterOption.empty();
filterOption.append(getDefaultNoneSelectionContent());
} else {
$timeout(function() {

Expand All @@ -1044,7 +1068,13 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', functio
// data-selected-text-format="count" or data-selected-text-format="count>x"
if((typeof count !== 'undefined') && modelValue.length > count) {
filterOption.empty();
filterOption.append(document.createTextNode(modelValue.length + ' items selected'));
if(localizedText.numberItemSelectedTpl) {
filterOption.append(jqLite(localizedText.numberItemSelectedTpl.replace('%d', modelValue.length)));
} else if(localizedText.numberItemSelected) {
filterOption.append(document.createTextNode(localizedText.numberItemSelected.replace('%d', modelValue.length)));
} else {
filterOption.append(document.createTextNode(modelValue.length + ' items selected'));
}
return;
}

Expand Down Expand Up @@ -1082,15 +1112,8 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', functio
}

if(selection.length === 0) {
if($attrs.title) {
// use title attribute value.
filterOption.empty();
filterOption.append(document.createTextNode($attrs.title));
} else {
// use default text.
filterOption.empty();
filterOption.append(document.createTextNode(DEFAULT_NONE_SELECTION));
}
filterOption.empty();
filterOption.append(getDefaultNoneSelectionContent());
} else if(selection.length === 1) {
// either single or multiple selection will show the only selected content.
filterOption.empty();
Expand Down
4 changes: 2 additions & 2 deletions dist/js/nya-bs-select.min.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions docs/dist/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ angular.module('controllers', [])
.controller('ApiCtrl', function($scope, pages){
$scope.articles = [];
angular.forEach(pages, function(stateName){
var words = stateName.split('-');
var title = words.map(function(word, index) {
return index === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1);
}).join('');
$scope.articles.push({
state: stateName,
title: stateName
title: title
});
});
});
Expand Down Expand Up @@ -144,7 +148,8 @@ angular.module('docApp', ['ui.router', 'nya.bootstrap.select', 'directives', 'fi
],
api: [
'nya-bs-select',
'nya-bs-option'
'nya-bs-option',
'nya-bs-config-provider'
]
};

Expand Down
64 changes: 64 additions & 0 deletions docs/src/content/api/nya-bs-config-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#nyaBsConfigProvider

This provider help the developer configure the default text appearance of nya-bs-select base on user-agent localization. Default implementation of the locale text is `en-us`.

There are three default text can be configured. Each one has two form, pure text and custom html template. The priority of template configuration is higher than pure text.

<table class="table table-striped">
<thead>
<tr>
<th>Text</th>
<th>Template</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr>
<td>defaultNoneSelection</td>
<td>defaultNoneSelectionTpl</td>
<td>defaultNoneSelection is appeared on dropdown toggle when nothing is selected.</td>
</tr>
<tr>
<td>noSearchResult</td>
<td>noSearchResultTpl</td>
<td>noSearchResult is appeared on dropdown menu when using live search and nothing match the filter text</td>
</tr>
<tr>
<td>numberItemSelected</td>
<td>numberItemSelectedTpl</td>
<td>
<p>numberItemSelected is appeared when <code>select-text-format</code> attribute is set to count or count>x and when user selected multiple items. dropdown button text will be replaced by this text.</p>

<p>**To show a count of selected items. this text string or template should contains a `%d` which will be replaced with number**</p>
</td>
</tr>
</tbody>
</table>

>NOTE: You shouldn't use any angular directive or expression in template, it will not be parsed.
###Methods

####`setLocalizedText(localeId, configObj);`

Register a new locale configuration or override an existing locale configuration.

- `localeId` a string formatted as languageId-countryId, e.g. en-us
- `configObj` a localized configuration object. should contain one of the three properties.

```javascript
{
defaultNoneSelection: 'Nothing selected',
noSearchResult: 'NO SEARCH RESULT',
numberItemSelected: '%d item selected'
}
```

####`useLocale(localeId);`

Force to use a special locale configuration with given localeId.

- `localeId` a string formatted as languageId-countryId, e.g. en-us



10 changes: 5 additions & 5 deletions docs/src/content/api/nya-bs-option.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#nya-bs-option
#nyaBsOption

The main function of this directive is manipulating an option list base on given collection.
its expression is very similar as `ng-repeat` but add a little magic to support the special scenario of select component.

The `nya-bs-option` instantiates a template once per item from a collection. Each template instance gets its own scope,
The `nyaBsOption` instantiates a template once per item from a collection. Each template instance gets its own scope,
where the given loop variable is set to the current collection item,
and `$index` is set to the item index or key. If `group by` expression is provided.
the generated options list will resorted by the result of the expression, and `$group` is set to each template scope.
Expand Down Expand Up @@ -61,7 +61,7 @@ the generated options list will resorted by the result of the expression, and `$

###Special class generated on each element.

When using `group by` expression, the `nya-bs-option` will generate a class `group-item` on each repeated element.
When using `group by` expression, the `nyaBsOption` will generate a class `group-item` on each repeated element.
To identify the first element of each group. It will also add a class `first-in-group` on the first element of a group.
Theses class has some special styles to build the group header.

Expand Down Expand Up @@ -163,9 +163,9 @@ as attribute:
<td>deep-watch</td>
<td><span class="label label-primary">string</span></td>
<td>
When set to true, enable a deep watch to collection_expression. `nya-bs-option` will use $watch(exp, listener, true) to make a deep watch. Turn on this feature will impact the performance. even cause expection.
When set to true, enable a deep watch to collection_expression. `nyaBsOption` will use $watch(exp, listener, true) to make a deep watch. Turn on this feature will impact the performance. even cause expection.
It is not recommended.
By default. `nya-bs-option` will use $watchCollection to watch the collection_expression.
By default. `nyaBsOption` will use $watchCollection to watch the collection_expression.
</td>
</tr>
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/api/nya-bs-select.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#nya-bs-select
#nyaBsSelect

nya-bs-select is the main directive of this module. You can consider it as a select directive. It manipulates the the dropdown-toggle content and all user interaction.
nyaBsSelect is the main directive of this module. You can consider it as a select directive. It manipulates the the dropdown-toggle content and all user interaction.

###Usage

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.0.5",
"version": "2.0.6",
"description": "An angular directive wraps bootstrap-select",
"repository": {
"type": "git",
Expand Down

0 comments on commit 27b0fac

Please sign in to comment.