Created
December 3, 2018 14:24
-
-
Save Sarapulov/19e10c670334677def1742a4146bc891 to your computer and use it in GitHub Desktop.
Guide - add some text/html/image around Attachments area on certain ticket form [LIGHT VERSION]
This file contains hidden or 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
// Guide form handler script | |
// Applies light customisation around Attachment area on a specific ticket form | |
var zdFormHandler = function(){ | |
'use strict'; | |
// Parse URL for form ID | |
function _getUrlParameter(name, url) { | |
url = url || window.location.href; | |
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); | |
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)','g'), result = regex.exec(url); | |
return result && result.length ? result[1] : null; | |
} | |
// Check form config presense and run the script | |
function _init(form_config) { | |
if (!form_config) { | |
console.log('Unable to apply form customisation as configuration file is missing, broken or can not be loaded.'); | |
return false; | |
} | |
try { | |
_checkForm(form_config); | |
} catch(err) { | |
console.log('Unable to run the script. See error message for more details.', err); | |
return false; | |
} | |
} | |
// check if current form valid one | |
function _checkForm(config) { | |
var current_form_id = _getUrlParameter('ticket_form_id') || $('#request_issue_type_select').val() || $('#request_ticket_form_id').val(); | |
if (current_form_id == config.expected_form_id) _applyCustomisation(config); | |
} | |
// apply customisations | |
function _applyCustomisation(config) { | |
config.customisations.privacy_policy_html && $('form#new_request div.request_custom_fields_360010937194 p').html( config.customisations.privacy_policy_html ); | |
config.customisations.attachments_label_text && $('form#new_request #upload-dropzone').parent().find('label').text( config.customisations.attachments_label_text ); | |
if (config.customisations.post_attachments_html) { | |
if (config.customisations.post_attachments_html.indexOf('{IMAGE_URL}') > -1) config.customisations.post_attachments_html = config.customisations.post_attachments_html.replace('{IMAGE_URL}', config.customisations.image_url_for_post_attachments_html); | |
$('form#new_request #upload-dropzone').parent().append( config.customisations.post_attachments_html ); | |
} | |
} | |
return { | |
init: _init | |
} | |
}; | |
// <script> | |
zdFormHandler().init({ | |
"expected_form_id":"360000364153", | |
"customisations":{ | |
"privacy_policy_html":"{{ dc 'guide-privacy_policy_html' }}", | |
"attachments_label_text":"{{ dc 'guide-attachments_label_text' }}", | |
"post_attachments_html":"{{ dc 'guide-post_attachments_html' }}", | |
"image_url_for_post_attachments_html":"{{ asset 'Reklamation_image.png' }}" | |
} | |
}); | |
// </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment