Skip to content

Instantly share code, notes, and snippets.

View Sarapulov's full-sized avatar

Andrey Sarapulov Sarapulov

  • EMEA
View GitHub Profile
@Sarapulov
Sarapulov / set_unset_checkbox.js
Created November 19, 2017 17:56
set and unset checkbox on Web Widget
// set and unset checkbox on Web Widget
// jQuery is epxected
// fieldHandler.setCheckbox("45510285"); // call to set
// fieldHandler.unsetCheckbox("45510285"); // call to unset
var fieldHandler = (function() {
return {
getCheckbox: function(field_id) {
return $("iframe#webWidget").contents().find('input[name='+field_id+']');
},
setCheckbox: function(field_id) {
@Sarapulov
Sarapulov / observer_example.html
Created September 7, 2017 08:04
observer_example.html
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://assets.zendesk.com/apps/sdk-assets/css/1/zendesk_garden.css" type="text/css">
<style>
#main > div {
display: block;
}
</style>
</head>
@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>
@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 / 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 / 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 / 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 / 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 / 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 / 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);