This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(autoComplete): Add custom template support
Add custom template support for the autoComplete directive so each suggestion can be freely customized. Introduce a new option called template that holds either a URL to an HTML file or an id of an inline script tag. The template, once rendered, is provided with both a special property containing the matching data and a helper object containing useful functions (e.g. text highlighting). Closes #99
- Loading branch information
Showing
9 changed files
with
253 additions
and
80 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
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,36 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc directive | ||
* @name tiAutocompleteMatch | ||
* @module ngTagsInput | ||
* | ||
* @description | ||
* Represents an autocomplete match. Used internally by the tagsInput directive. | ||
*/ | ||
tagsInput.directive('tiAutocompleteMatch', function($sce, tiUtil) { | ||
return { | ||
restrict: 'E', | ||
require: '^autoComplete', | ||
template: '<ng-include src="template"></ng-include>', | ||
scope: { data: '=' }, | ||
link: function(scope, element, attrs, autoCompleteCtrl) { | ||
var autoComplete = autoCompleteCtrl.registerAutocompleteMatch(), | ||
options = autoComplete.getOptions(); | ||
|
||
scope.template = options.template; | ||
|
||
scope.util = { | ||
highlight: function(text) { | ||
if (options.highlightMatchedText) { | ||
text = tiUtil.safeHighlight(text, autoComplete.getQuery()); | ||
} | ||
return $sce.trustAsHtml(text); | ||
}, | ||
getDisplayText: function() { | ||
return tiUtil.safeToString(scope.data[options.displayProperty || options.tagsInput.displayProperty]); | ||
} | ||
}; | ||
} | ||
}; | ||
}); |
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
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 @@ | ||
<span ng-bind-html="util.highlight(util.getDisplayText())"></span> |
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,11 @@ | ||
<div class="autocomplete" ng-show="suggestionList.visible"> | ||
<div class="autocomplete" ng-if="suggestionList.visible"> | ||
<ul class="suggestion-list"> | ||
<li class="suggestion-item" | ||
ng-repeat="item in suggestionList.items track by track(item)" | ||
ng-class="{selected: item == suggestionList.selected}" | ||
ng-click="addSuggestionByIndex($index)" | ||
ng-mouseenter="suggestionList.select($index)" | ||
ng-bind-html="highlight(item)"></li> | ||
ng-mouseenter="suggestionList.select($index)"> | ||
<ti-autocomplete-match data="item"></ti-autocomplete-match> | ||
</li> | ||
</ul> | ||
</div> |
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
Oops, something went wrong.