Greetings all,
I've embedded a custom Jira Issue Collector on our Drupal 7 site. The issue collector works fine when I insert the code into a Drupal theme template file. Unfortunately, that is bad practice.
When I instead add the issue collector code into our template.php file using drupal_add_js(), the code is visible when I View Source in the browser. But no action happens when I click on the custom link that should open the issue collector. The script is the same as the one added to template.php, but it doesn't work. There are no JS console errors or network tab script loading errors. The order of loading is 1) Jira remote issue collector script that has our issue collector defined in Jira, 2) script local to the page which instantiates the custom Jira issue collector (see code below). View Source and the the Network tab shows the scripts are loaded in the correct order. jQuery is also loaded before either of these scripts.
The script is below. I suspect somehow the there is an order-of-execution problem where window.ATL_JQ_PAGE_PROPS does not get associated properly with the trigger function at the right time during the page load cycle. But when I view the value of window.ATL_JQ_PAGE_PROPS in the console it is there and contains the correct triggerFunction property. I tried (document).ready() as well as well as (window).load(). I would greatly appreciate any thoughts:
drupal_add_js('path-to-jira-issue-collector-script-at-jira.com', array('type' => 'external','scope' => 'footer','weight' => 5));
drupal_add_js(
'jQuery(document).ready(function() {
window.ATL_JQ_PAGE_PROPS = {
"triggerFunction": function(showCollectorDialog) {
//Requires that jQuery is available!
jQuery(".our-custom-button-class").click(function(e) {
e.preventDefault();
showCollectorDialog();
});
}
};
});', array('type' => 'inline','scope' => 'footer','weight' => 10));