Skip to content

Commit

Permalink
Fix no match template config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Humphreys committed Oct 2, 2017
1 parent 884ae21 commit d294ceb
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 94 deletions.
2 changes: 2 additions & 0 deletions dist/tribute.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
background: #ddd; }
.tribute-container li span {
font-weight: bold; }
.tribute-container li.no-match {
cursor: default; }
.tribute-container .menu-highlighted {
font-weight: bold; }
181 changes: 91 additions & 90 deletions dist/tribute.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tribute.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tribute.min.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ <h5>Tribute on traditional form elements!</h5>
{key: 'Sir Walter Riley', value: 'Sir Walter Riley', email: '[email protected]'}
],
selectTemplate: function (item) {
if (typeof item === 'undefined') return null;
if (this.range.isContentEditable(this.current.element)) {
return '<span contenteditable="false"><a href="http://zurb.com" target="_blank" title="' + item.original.email + '">' + item.original.value + '</a></span>';
}
Expand All @@ -103,6 +104,8 @@ <h5>Tribute on traditional form elements!</h5>
return '@' + item.original.value;
},

noMatchTemplate: function() { return null; },

// the array of objects
values: [
{key: 'Jordan Humphreys', value: 'Jordan Humphreys', email: '[email protected]'},
Expand All @@ -122,6 +125,8 @@ <h5>Tribute on traditional form elements!</h5>
return '#' + item.original.name;
},

noMatchTemplate: function() { return null; },

// function retrieving an array of objects
values: [
{name: 'Bob Bill', email: '[email protected]'},
Expand Down
4 changes: 4 additions & 0 deletions scss/tribute.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
span {
font-weight: bold;
}

&.no-match {
cursor: default;
}
}

.menu-highlighted {
Expand Down
5 changes: 3 additions & 2 deletions src/Tribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Tribute {
return t.bind(this)
}

return function () {return '<li>No match!</li>'}.bind(this)
return function () {return '<li class="no-match">No match!</li>'}.bind(this)
})(noMatchTemplate),

// column to search against in the object
Expand Down Expand Up @@ -100,6 +100,7 @@ class Tribute {
}

static defaultSelectTemplate(item) {
if (typeof item === 'undefined') return null;
if (this.range.isContentEditable(this.current.element)) {
return '<span class="tribute-mention">' + (this.current.collection.trigger + item.original[this.current.collection.fillAttr]) + '</span>';
}
Expand Down Expand Up @@ -339,7 +340,7 @@ class Tribute {
if (typeof index !== 'number') return
let item = this.current.filteredItems[index]
let content = this.current.collection.selectTemplate(item)
this.replaceText(content, originalEvent, item)
if (content !== null) this.replaceText(content, originalEvent, item)
}

replaceText(content, originalEvent, item) {
Expand Down

0 comments on commit d294ceb

Please sign in to comment.