Skip to content
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

Emoji Autocomplete #3433

Merged
merged 7 commits into from
Feb 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/css/index.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ function initRepository() {
$editContentZone.html($('#edit-content-form').html());
$textarea = $segment.find('textarea');
issuesTribute.attach($textarea.get());
emojiTribute.attach($textarea.get());

// Give new write/preview data-tab name to distinguish from others
var $editContentForm = $editContentZone.find('.ui.comment.form');
Expand Down
26 changes: 26 additions & 0 deletions public/less/_tribute.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.tribute-container {
box-shadow: 0px 1px 3px 1px #c7c7c7;
ul {
background: #ffffff;
}
li {
padding: 8px 12px;
border-bottom: 1px solid #dcdcdc;
img {
display: inline-block;
vertical-align: middle;
width: 28px;
height: 28px;
margin-right: 5px;
}
span.fullname {
font-weight: normal;
font-size: 0.8rem;
margin-left: 3px;
}
}
li.highlight, li:hover {
background: #2185D0;
color: #ffffff;
}
}
1 change: 1 addition & 0 deletions public/less/index.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "_tribute";
@import "_emojify";
@import "_base";
@import "_markdown";
Expand Down
19 changes: 3 additions & 16 deletions public/vendor/plugins/tribute/tribute.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,20 @@
max-width: 500px;
overflow: auto;
display: block;
box-shadow: 0px 1px 3px 1px #c7c7c7;
z-index: 999999; }
.tribute-container ul {
margin: 0;
margin-top: 2px;
padding: 0;
list-style: none;
background: #ffffff; }
background: #efefef; }
.tribute-container li {
padding: 8px 12px;
border-bottom: 1px solid #dcdcdc;
padding: 5px 5px;
cursor: pointer; }
.tribute-container li.highlight, .tribute-container li:hover {
background: #2185D0;
color: #ffffff;}
.tribute-container li img {
display: inline-block;
vertical-align: middle;
width: 28px;
margin-right: 5px;
}
background: #ddd; }
.tribute-container li span {
font-weight: bold; }
.tribute-container li span.fullname {
font-weight: normal;
font-size: 0.8rem;
margin-left: 3px;}
.tribute-container li.no-match {
cursor: default; }
.tribute-container .menu-highlighted {
Expand Down
32 changes: 32 additions & 0 deletions templates/base/footer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,38 @@
issuesTribute.attach(document.getElementById('content'))
</script>
{{end}}
<script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to not put this in /public/js/index.js?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kolaente it can't be put (at least currently) in index.js as it has server-side condition check if this should be included so such refactoring would probably be better done in different PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried putting it to /public/js/index.js, and limited the initialization of tribute to a condition, wether an element with id content is available.

But I think it is much cleaner, if the emojiTribute is only initialized when the page requiring it is loaded.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh ok I see...

var emojiTribute = new Tribute({
collection: [{
trigger: ':',
requireLeadingSpace: true,
values: function (text, cb) {
var array = emojify.emojiNames;
var data = [];
for(var j=0; j<array.length; j++) {
if(array[j].indexOf(text) !== -1) {
data.push(array[j]);
if(data.length > 5) {
break;
}
}
}
cb(data);
},
lookup: function (item) {
return item;
},
selectTemplate: function (item) {
if (typeof item === 'undefinied') return null;
return ':' + item.original + ':';
},
menuItemTemplate: function (item) {
return '<img class="emoji" src="{{AppSubUrl}}/vendor/plugins/emojify/images/' + item.original + '.png"/>' + item.original;
}
}]
});
emojiTribute.attach(document.getElementById('content'))
</script>
{{end}}
<script src="{{AppSubUrl}}/vendor/plugins/autolink/autolink.js"></script>
<script src="{{AppSubUrl}}/vendor/plugins/emojify/emojify.min.js"></script>
Expand Down