I'm currently trying to hack some kind of in-place editing functionality in the JIRA bugtracker without changing its page templates. So, on the details page for the problem, I bind the dblclick events to the fields that replace the static field with the editable form element (from the edit page that was loaded and cached at the beginning of the script). Some of these elements are JS widgets, such as a calendar widget, and they have <script> elements within the <td> for the field. I want to wrap these elements along with the rest of the HTML and execute them on the page.
So, the original static field looks like this:
<td bgcolor="#ffffff" width="80%"> 2008/Sep/22 </td>
The one I'm trying to copy is as follows:
<td class="fieldValueArea"> <input type="text" name="duedate" id="duedate" value="" size="10"> <img id="duedate_trigger_c" src="/jira/images/icons/cal.gif" width="16" height="16" border="0" alt="Select a date" title="Select a date"> <script type="text/javascript"> Calendar.setup({ firstDay : 0, </script> </td>
I want to save the <script> and execute it on the landing page (after the copy) so that the Calendar widget correctly enters.
I use jQuery for AJAX-load the edit page like this:
$.get(editlink, function(data){ jeip_editpage = data; }, "text");
And replacing the field like this:
this.innerHTML = $("#"+fieldname+"FieldArea .fieldValueArea",jeip_editpage).html();
(where this = TD field)
After $ .get (), jeip_editpage contains the <script> element in the right place, but when I try to grab the element as above, it disappears. I did some Googling and found that jQuery moves <script> elements around the page during the parsing stage, which is the right pain. I suppose that I could search, grab and replace the text immediately after $ .get (), to make sure that I have all the <script> elements separately, but I believe that there should be an easier way, right?
Note that I do not change any JIRA page template, so the answers related to returning HTML to a more useful layout will not work for me.