Skip to content

Instantly share code, notes, and snippets.

View Sarapulov's full-sized avatar

Andrey Sarapulov Sarapulov

  • EMEA
View GitHub Profile
@Sarapulov
Sarapulov / gist:8f9192135b793f4f95d0982fc2eeb7cf
Created May 9, 2016 15:03
Move subject and description to the bottom
if ( document.location.href.indexOf('/requests/new') > -1 ) {
$('.request_subject').insertBefore('.form footer');
$('.request_description').insertBefore('.form footer');
}
@Sarapulov
Sarapulov / HTTP_target_setting.js
Created May 10, 2016 08:54
Update Date Field using HTTP target
// TARGET SETTINGS
https://DOMAIN.zendesk.com/api/v2/tickets/update_many.json
PUT
JSON
Basic Authentication - Enabled (email/token + API token)
// PAYLOAD (IN TRIGGER)
{
"tickets": [
{ "id": {{ticket.id}},
@Sarapulov
Sarapulov / locale_redirect.js
Created September 20, 2016 13:13
Change HC locale in the URL for everyone who is not on Request Page
/************************************************
Change HC locale in the URL for everyone who is not on Request Page
************************************************/
if (/*HelpCenter.user.role != 'anonymous' &&*/ !window.location.pathname.match('/requests/')) {
(function() {
var url = window.location.pathname;
expected_locale = 'en-us',
current_locale = url.split('/hc/')[1].split('/')[0],
is_expected_locale = current_locale === expected_locale;
if (!is_expected_locale) window.location.pathname = url.replace(current_locale,expected_locale);
@Sarapulov
Sarapulov / url_params_to_fields.js
Created October 11, 2016 09:46
Quick and dirty way to read URL parameters and set given ticket fields Expected URL example https://sarapulov.zendesk.com/hc/en-us/requests/new?ticket_form_id=72316&country=bhutan&age=21 CODE CONTAIN BUGS!
/*
Quick and dirty way to read URL parameters and set given ticket fields
Expected URL example https://sarapulov.zendesk.com/hc/en-us/requests/new?ticket_form_id=72316&country=bhutan&age=21
CODE CONTAIN BUGS!
*/
if ( window.location.search.match("ticket_form_id") ) {
function getUrlParameter(param) {
if (!param) return '';
var href = window.location.href;
if (param === 'locale') return href.split('/hc/')[1].split('/')[0];
@Sarapulov
Sarapulov / form_fields.js
Created October 11, 2016 12:41
Move Subject & Description fields and copy custom field value into subject
if ( document.location.href.indexOf('/requests/new') > -1 ) {
// move fields
var $att = $('div.form-field').last();
$('.request_subject').insertBefore($att);
$('.request_description').insertBefore($att);
// set subject
var field_val = $('#request_custom_fields_31616405').val();
$('#request_subject').val(field_val).change();
}
@Sarapulov
Sarapulov / benefex_help_center_forms.js
Last active October 12, 2016 12:59
Help Center cutomizations Preset Subject field based on custom field value, Hide Subject, Move Subject and Description fields.
/************************************************************
Help Center cutomization (ver 1.0.1)
Preset & hide Subject field based on custom field value,
Move Subject and Description fields.
************************************************************/
if (document.location.search.indexOf('ticket_form_id') > -1) {
(function () {
var settings = { // change settings here
"hide_subject": true,
"133425":"request_custom_fields_31616405",
@Sarapulov
Sarapulov / preset_nested_dropdown.js
Created January 2, 2017 15:37
Preset given nested dropdown on Zendesk Help Center with a given value
/**
* Preset given nested dropdown on Zendesk Help Center with a given value
*
* @param {String} field_id (example: 'request_custom_fields_31265065')
* @param {String} field_value (example: 'complaint_type_b')
*/
function presetNestedDrodown(field_id,field_value){
if (!field_id || field_value === undefined) return;
var $field = $('.'+field_id);
if ($field && $field.length > 0 && $field.hasClass('string')) {
@Sarapulov
Sarapulov / zopim_logic.js
Last active January 12, 2017 10:14
Zopim logic for handling departments
<!-- the web widget -->
<script>
window.zEmbed||(function(){
var queue = [];
window.zEmbed = function() { queue.push(arguments); }
window.zE = window.zE || window.zEmbed;
document.zendeskHost = 'mycompany.zendesk.com';
document.zEQueue = queue;
}());
</script>
@Sarapulov
Sarapulov / hc_redirect.html
Created June 7, 2017 09:36
Advanced HC redirect script to the specific form
<script type="text/javascript">
(function(f, l, lh, isR){ // redirect to ticket form page if not already form page, requests page or article page
f = 151485, l = window.location, lh = l.href, isR = !(l.search.match("ticket_form_id") || lh.indexOf('/requests') > -1 || lh.indexOf('/articles') > -1);
if (isR {{#if signed_in}}&& false{{/if}}) l.replace("/hc/"+document.getElementsByTagName("html")[0].lang.toLowerCase()+"/requests/new?ticket_form_id="+f);
})();
</script>
@Sarapulov
Sarapulov / hc_redirect_after_page_loaded.html
Created June 8, 2017 08:27
Zendesk Help Center redirect after page is loaded
<script type="text/javascript">
$(document).ready(function() {
(function(f, l, lh, isR){ // redirect to ticket form page if not already form page, requests page or article page
f = 151485, l = window.location, lh = l.href, isR = !(l.search.match("ticket_form_id") || lh.indexOf('/requests') > -1 || lh.indexOf('/articles') > -1),
hc = HelpCenter, isU = hc && (hc.user.role !== 'manager' && hc.user.role !== 'agent');
if (isR && isU) l.replace("/hc/"+document.getElementsByTagName("html")[0].lang.toLowerCase()+"/requests/new?ticket_form_id="+f);
})();
});
</script>