Created
April 8, 2015 16:49
-
-
Save antonioortegajr/5d858eea1976921edc5f to your computer and use it in GitHub Desktop.
Adds auto suggest for Desk.com email us page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- auto suggest kb articles --> | |
<div class="message_suggest" id="form_suggest_web"> | |
<div class="autosuggest right-side hide"></div> | |
<div id="common" class="right-side"> | |
<h2 class="muted">Common Questions</h2> | |
<ul class="unstyled"> | |
<li><em>Start typing your question in the form, and you'll see knowledge base results here.</em></li> | |
</ul> | |
</div> | |
</div> | |
</div> <!-- end common questions section --> | |
<script> | |
$(function() { | |
// Skip pre-create | |
//$('#new_email').attr('action','/customer/portal/emails'); | |
// Real-time auto-suggest | |
$('#email_subject, #email_body').keyup(function() { | |
count = 0; | |
if ($('#email_subject').val().length > 2 || $('#email_body').val().length > 2) { | |
query = $('#email_subject').val() + " " + $('#email_body').val(); | |
$.ajax({ | |
url: '//' + document.domain.toString() + '/customer/en/portal/articles/autocomplete?term=' + query, | |
dataType: 'json' | |
}).done(apiSuccess).fail(apiFail); | |
} else { | |
$(".autosuggest").addClass('hide'); | |
$("#common").show(); | |
} | |
}); | |
}); | |
apiSuccess = function(data) { | |
auto_suggest_content = ""; | |
auto_suggest_articles = ""; | |
auto_suggest_questions = ""; | |
$('.autosuggest').html('<h2 class="muted">Do these help?</h2><ul class="unstyled"></ul>'); | |
$.each(data, function() { | |
var html = $(this.label); | |
article_title = html.find(".article-autocomplete-subject").html(); | |
if (this.id.indexOf("questions") !== -1) { | |
auto_suggest_questions += '<li><a target="_blank" href="' + this.id + '" class="discussion">' + article_title + '</a></li>'; | |
} else { | |
auto_suggest_articles += '<li><a target="_blank" href="' + this.id + '" class="article">' + article_title + '</a></li>'; | |
} | |
count++; | |
}); | |
if (count > 0) { | |
$('.autosuggest ul').append(auto_suggest_articles + auto_suggest_questions); | |
$("#common").hide(); | |
$(".autosuggest").removeClass('hide'); | |
} else { | |
$(".autosuggest").addClass('hide'); | |
$("#common").show(); | |
} | |
}; | |
apiFail = function(data) { | |
}; | |
</script> | |
<!-- end auto suggest kb articles --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment