-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding latinize-tags flag to ignore accents #128
base: master
Are you sure you want to change the base?
Changes from 1 commit
4e91082
ee08193
4194084
8291f3a
14875ef
784b04d
fc21062
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,15 @@ <h2 class="is-size-4" style="margin-bottom: 1rem;">Options</h2> | |
</div> | ||
</div> | ||
|
||
<div class="field"> | ||
<div class="control"> | ||
<label class="checkbox"> | ||
<input type="checkbox" v-model="latinizeTags"> | ||
Tags are latinized (ignore accents) | ||
</label> | ||
</div> | ||
</div> | ||
|
||
<div class="field"> | ||
<div class="control"> | ||
<label class="checkbox"> | ||
|
@@ -203,13 +212,15 @@ <h2 class="is-size-4" style="margin-bottom: 1rem;">Options</h2> | |
:existing-tags="[ | ||
{ key: 'children-of-bodom', value: 'Children of Bodom' }, | ||
{ key: 'epica', value: 'Epica' }, | ||
{ key: 'epica', value: 'Épica' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In real life "Epica" and "Épica" could be two different words with different meanings, right? So the keys should also be different so you would be able to select both words. Please fix your examples here or think of different words. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll add just one little example of an accentuated word. |
||
{ key: 'emperor', value: 'Emperor' }, | ||
{ key: 'shape-of-despair', value: 'Shape of Despair' }, | ||
{ key: 'protest-the-hero', value: 'Protest the Hero' }, | ||
{ key: 'my-dying-bride', value: 'My Dying Bride' }, | ||
{ key: 'ne-obliviscaris', value: 'Ne Obliviscaris' }, | ||
{ key: 'belakor', value: 'Be\'lakor' }, | ||
{ key: 'dark-lunacy', value: 'Dark Lunacy' }, | ||
{ key: 'dark-lunacy', value: 'Dark Lunâcy' }, | ||
{ key: 'dominia', value: 'Dominia' }, | ||
{ key: 'jason-becker', value: 'Jason Becker' }, | ||
{ key: 'jeff-loomis', value: 'Jeff Loomis' }, | ||
|
@@ -226,6 +237,7 @@ <h2 class="is-size-4" style="margin-bottom: 1rem;">Options</h2> | |
:limit="limit" | ||
:only-existing-tags="onlyExistingTags" | ||
:case-sensitive-tags="caseSensitiveTags" | ||
:latinize-tags="latinizeTags" | ||
:delete-on-backspace="deleteOnBackspace" | ||
:allow-duplicates="allowDuplicates" | ||
:add-tags-on-comma="addTagsOnComma" | ||
|
@@ -284,6 +296,7 @@ <h2 class="is-size-5" style="margin-top: 1rem;">Data Events (new at the top)</h2 | |
limit: 0, | ||
onlyExistingTags: false, | ||
caseSensitiveTags: false, | ||
latinizeTags: false, | ||
deleteOnBackspace: true, | ||
allowDuplicates: false, | ||
addTagsOnComma: false, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,8 @@ | |
</template> | ||
|
||
<script> | ||
import latinize from 'latinize'; | ||
|
||
export default { | ||
props: { | ||
elementId: String, | ||
|
@@ -243,6 +245,11 @@ export default { | |
default: false | ||
}, | ||
|
||
latinizeTags: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
|
||
beforeAddingTag: { | ||
type: Function, | ||
default: () => true | ||
|
@@ -400,17 +407,19 @@ export default { | |
value: text, | ||
}; | ||
|
||
const queryTerm = this.latinizeTags ? latinize(newTag[this.textField]) : newTag[this.textField]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to remove diacritics here when checking for whether a tag has been added already. As I mentioned above, there could be two words "Epica" and "Épica" with completely different meanings and because of this code here we won't be able to add them both. |
||
const searchQuery = this.escapeRegExp( | ||
this.caseSensitiveTags | ||
? newTag[this.textField] | ||
: newTag[this.textField].toLowerCase() | ||
? queryTerm | ||
: queryTerm.toLowerCase() | ||
); | ||
|
||
for (let tag of this.typeaheadTags) { | ||
const compareableTerm = this.latinizeTags ? latinize(tag[this.textField]) : tag[this.textField]; | ||
const compareable = this.escapeRegExp( | ||
this.caseSensitiveTags | ||
? tag[this.textField] | ||
: tag[this.textField].toLowerCase() | ||
? compareableTerm | ||
: compareableTerm.toLowerCase() | ||
); | ||
|
||
if (searchQuery === compareable) { | ||
|
@@ -548,8 +557,9 @@ export default { | |
|
||
if ((input.length && input.length >= this.typeaheadActivationThreshold) || this.typeaheadActivationThreshold == 0 || this.typeaheadAlwaysShow) { | ||
// Find all the existing tags which include the search text | ||
const queryTerm = this.latinizeTags ? latinize(input) : input; | ||
const searchQuery = this.escapeRegExp( | ||
this.caseSensitiveTags ? input : input.toLowerCase() | ||
this.caseSensitiveTags ? queryTerm : queryTerm.toLowerCase() | ||
); | ||
|
||
// AJAX search | ||
|
@@ -587,9 +597,10 @@ export default { | |
*/ | ||
doSearch(searchQuery) { | ||
for (let tag of this.typeaheadTags) { | ||
const compareableTerm = this.latinizeTags ? latinize(tag[this.textField]) : tag[this.textField]; | ||
const compareable = this.caseSensitiveTags | ||
? tag[this.textField] | ||
: tag[this.textField].toLowerCase(); | ||
? compareableTerm | ||
: compareableTerm.toLowerCase(); | ||
|
||
if (compareable.search(searchQuery) > -1 && ! this.tagSelected(tag)) { | ||
this.searchResults.push(tag); | ||
|
@@ -728,14 +739,16 @@ export default { | |
return false; | ||
} | ||
|
||
const queryTerm = this.latinizeTags ? latinize(tag[this.textField]) : tag[this.textField]; | ||
const searchQuery = this.escapeRegExp( | ||
this.caseSensitiveTags ? tag[this.textField] : tag[this.textField].toLowerCase() | ||
this.caseSensitiveTags ? queryTerm : queryTerm.toLowerCase() | ||
); | ||
|
||
for (let selectedTag of this.tags) { | ||
const compareableTerm = this.latinizeTags ? latinize(selectedTag[this.textField]) : selectedTag[this.textField]; | ||
const compareable = this.caseSensitiveTags | ||
? selectedTag[this.textField] | ||
: selectedTag[this.textField].toLowerCase(); | ||
? compareableTerm | ||
: compareableTerm.toLowerCase(); | ||
|
||
if (selectedTag[this.idField] === tag[this.idField] && this.escapeRegExp(compareable).length == searchQuery.length && compareable.search(searchQuery) > -1) { | ||
return true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the prop should be called
ignore-diacritics
as this would be a more general term. The word "latinize" doesn't have anything to do with accents according to Google.