Skip to content

Commit

Permalink
Emoji autocomplete (publiclab#2832)
Browse files Browse the repository at this point in the history
* basic emoji autocomplete

* minor changes

* minor tweaks

* code climate fixes

* minor change

* changes

* remove unnecessary style
  • Loading branch information
ViditChitkara authored and SidharthBansal committed Jun 19, 2018
1 parent 7d176fd commit b475a7d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
//= require short-code-forms/dist/short-code-prompts.js
//= require wikis.js
//= require chart.js/dist/Chart.js
//= require horsey.js
//= require header_footer.js
// require turbolinks // Temporarily removed while fixing

12 changes: 11 additions & 1 deletion app/assets/stylesheets/comments.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@

#question-comment-form {
width: 90%;
}
}

.sey-item b {
font-weight: 300;
font-size: 20px;
}

.sey-item span {
margin-bottom: 0;
margin-left: 4px;
}
12 changes: 12 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ def emojify(content)
end if content.present?
end

def emoji_names_list
emojis = []
image_map = {}
Emoji.all.each do |e|
next unless e.raw
val = ":#{e.name}:"
emojis<<{ value: val, text: e.name }
image_map[e.name] = e.raw
end
{ emojis: emojis, image_map: image_map }
end

def feature(title)
features = Node.where(type: 'feature', title: title)
if !features.empty?
Expand Down
3 changes: 0 additions & 3 deletions app/views/comments/_edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

</div>
</div>

<script type="application/javascript">
jQuery(document).ready(function() {
$E.initialize();
Expand Down Expand Up @@ -148,5 +147,3 @@
<%= t('comments._edit.email_notifications') %>
</p>
</form>


16 changes: 15 additions & 1 deletion app/views/comments/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

<div class="well col-md-11" id="preview" style="background:white;display: none">
</div>
<link href="/lib/horsey/dist/horsey.min.css" rel="stylesheet">

<script>
jQuery(document).ready(function() {
Expand All @@ -64,11 +65,24 @@
</script>

<%= javascript_include_tag "dragdrop" %>
<script>
<script>
$('#comment-form').bind('ajax:beforeSend', function(event){
$("#text-input").prop('disabled',true)
$("#comment-form .btn-primary").button('loading',true);
});
<% emoji_names = emoji_names_list %>
<% emojis = emoji_names[:emojis] %>
<% image_map = emoji_names[:image_map] %>
var image_map = <%= raw image_map.to_json %>
horsey(document.querySelector('textarea#text-input'), {
suggestions: (<%= raw emojis.to_json %>),
anchor: ':',
render: function (li, suggestion) {
var image = image_map[suggestion.text];
li.innerHTML = "<b>"+image+"</b><span>"+suggestion.text+"</span>";
},
limit: 6
});

$('#comment-form').bind('ajax:success', function(e, data, status, xhr){
$('#text-input').prop('disabled',false);
Expand Down
4 changes: 3 additions & 1 deletion config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
'style.css',
'tags.css',
'user_tags.css.scss',
'wiki.css'
'wiki.css',
'horsey.js',
'comment-autocomplete'
]

0 comments on commit b475a7d

Please sign in to comment.