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 encoding 3123 #3161

Merged
merged 13 commits into from
Aug 7, 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
38 changes: 38 additions & 0 deletions app/assets/javascripts/atwho_autocomplete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(function() {

var at_config = {
at: "@",
callbacks: {
remoteFilter: function(query, callback) {
$.getJSON("/api/srch/profiles?srchString=" + query, {}, function(data) {
if (data.hasOwnProperty('items') && data.items.length > 0) {
callback(data.items.map(function(i) { return i.docTitle }));
}
});
}
},
limit: 20
},
hashtags_config = {
at: "#",
callbacks: {
remoteFilter: function(query, callback) {
if (query != ''){
$.post('/tag/suggested/' + query, {}, function(response) {
callback(response.map(function(tagnames){ return tagnames }));
});
}
}
},
limit: 20
},
emojis_config = {
at: ':',
data: Object.keys(emoji).map(function(name){ return {'name': name, 'value': emoji[name]}}),
displayTpl: "<li>${value} ${name}</li>",
insertTpl: ":${name}:",
limit: 100
}

$('textarea#text-input').atwho(at_config).atwho(hashtags_config).atwho(emojis_config);
})();
46 changes: 5 additions & 41 deletions app/views/comments/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,50 +65,15 @@

<%= javascript_include_tag "dragdrop" %>
<script src="/lib/emoji.js" type="text/javascript"></script>
<script src="/assets/atwho_autocomplete.js" type="text/javascript"></script>
<script>

(function() {
$('#comment-form').bind('ajax:beforeSend', function(event){
$("#text-input").prop('disabled',true)
$("#comment-form .btn-primary").button('loading',true);
});

(function() {

var at_config = {
at: "@",
callbacks: {
remoteFilter: function(query, callback) {
$.getJSON("/api/srch/profiles?srchString=" + query, {}, function(data) {
if (data.hasOwnProperty('items') && data.items.length > 0) {
callback(data.items.map(function(i) { return i.docTitle }));
}
});
}
},
limit: 20
},
hashtags_config = {
at: "#",
callbacks: {
remoteFilter: function(query, callback) {
if (query != ''){
$.post('/tag/suggested/' + query, {}, function(response) {
callback(response.map(function(tagnames){ return tagnames }));
});
}
}
},
limit: 20
},
emojis_config = {
at: ':',
data: Object.keys(emoji).map(function(name){ return {'name': name, 'value': emoji[name]} }),
displayTpl: "<li>${value} ${name}</li>",
insertTpl: ":${name}:",
limit: 100
}

$('textarea#text-input').atwho(at_config).atwho(hashtags_config).atwho(emojis_config);

$('#comment-form').bind('ajax:success', function(e, data, status, xhr){
Copy link
Member

Choose a reason for hiding this comment

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

Can you confirm that the error message here still works without the (function() { around it? Maybe best to add that back in, as it helps the whole thing run /after/ page load is complete?

Copy link
Member

Choose a reason for hiding this comment

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

I think adding it back in may be easier than testing it... i know you can get it to error either by turning off your locally running app OR by submitting a real unicode emoji (not just a :smiley:) -- since we're trying to fix that! But... could be a bit tricky to test.

Copy link
Collaborator Author

@cheneyshreve01 cheneyshreve01 Aug 4, 2018

Choose a reason for hiding this comment

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

Hi @jywarren, I moved the code for error message back into the function athwho_autocomplete script! Quick question --- so the public folder is in .gitignore-- how do we then make sure we're including /lib/emoji.js? I just realized it wasn't getting included when I made that code change above then freaked out momentarily because "emoji " wasn't defined then realized it was because the file is in .gitignore so I had to go add it in again. Thanks again for all of your help!

I'll go ahead and push up changes--we just need to make sure that /lib/emoji.js gets included and it's currently in .gitignore.

$('#text-input').prop('disabled',false);
$('#text-input').val('');
Expand All @@ -126,9 +91,8 @@
$('#comment-form .control-group .help-block ').remove()
$('#comment-form .control-group').append('<span class="help-block ">Error: there was a problem.</span>')
});

})();

})();

function insertTitleSuggestionTemplate() {
var element = $('#text-input');
var currentText = $('#text-input').val().trim();
Expand Down
8 changes: 2 additions & 6 deletions app/views/editor/rich.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@
<% if controller.action_name != "edit" && !current_user.first_time_poster %>
<span id="newOpts" style="display: inline-block;">
<span id="text" style="display: none; color:red;">
Others won't see your post yet
Others won't see your post yet
(<a href="https://publiclab.org/draft-feature" targrt="_blank">?</a>) &nbsp; &nbsp;</span>
<span class="checkbox">
<label>
<input type="checkbox" id="myCheck" onclick="draftCheck()" />
Save as draft
</label> |
</label> |
</span>
<span class="ple-steps-left">2</span>
<span class="hidden-xs"> steps left</span>
Expand All @@ -185,8 +185,6 @@
</div>

</div>


<script>

var editor;
Expand Down Expand Up @@ -294,7 +292,6 @@
}
}
});

})();

$('.legacy-button').click(function onLegacyClick(event) {
Expand All @@ -317,5 +314,4 @@
}
console.log("Draft:", editor.data.draft);
}

</script>
9 changes: 4 additions & 5 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Rails.application.config.assets.precompile += [
Rails.application.config.assets.precompile += [
'leaflet-blurred-location/dist/Leaflet.BlurredLocation.js',

'advanced_search.js',
'application.js',
'comment_expand.js',
Expand Down Expand Up @@ -30,7 +30,7 @@
'textbox_expand.js',
'users.js',
'wikis.js',

'blog.css',
'comments.css',
'dashboard.css',
Expand All @@ -48,6 +48,5 @@
'user_tags.css.scss',
'wiki.css',
'horsey.js',
'comment-autocomplete'
'atwho_autocomplete.js'
]