I'm currently trying to hack a kind of edit-in-place functionality into the JIRA bugtracker without changing its page templates. So, on the detail page for an issue, I'm attaching dblclick events to fields that replace the static field with an editable form element (from the edit page, which has been ajax-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 carry these elements across with the rest of the HTML, and have them executed in 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 across looks like this:
<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, // first day of the week
inputField : "duedate", // id of the input field
button : "duedate_trigger_c", // trigger for the calendar (button ID)
align : "Tl", // alignment (defaults to "Bl")
singleClick : true,
ifFormat : "%e/%b/%y" // our date only format
});
</script>
</td>
I want to keep the <script> element and have it execute in the target page (after the copy) so that the Calendar widget inits properly.
I'm using jQuery to AJAX-load the edit page like so:
$.get(editlink, function(data){
jeip_editpage = data;
}, "text");
And replacing the field like so:
this.innerHTML = $("#"+fieldname+"FieldArea .fieldValueArea",jeip_editpage).html();
(where this = the field TD)
After the $.get(), jeip_editpage contains the <script> element in the right place, but when I try and grab the element as above, it's gone. I've done some Googling and found that jQuery moves <script> elements around in the page during the parsing stage, which is a right pain. I suppose I could do a search & grab & replace on the text right after the $.get() to make sure I have all the <script> elements separately, but I figure there has to be an easier way, right?
Note that I'm not changing any of JIRA's page templates, so answers involving the HTML coming back in a more useful layout aren't going to work for me.