| 1 | // Move the add hours box next to the comment box |
|---|
| 2 | var TandE_MoveAddHours = function(){ |
|---|
| 3 | // Couldnt find the comment box, lets just abort |
|---|
| 4 | if ($('#comment').length == 0) return; |
|---|
| 5 | var tbl, hours, colClass, tr, replacement; |
|---|
| 6 | tbl = $('<table style="border:1px solid #D7D7D7;" border="0" cellpadding="3" cellspacing="0"><tbody><tr></tr></tbody></table>'); |
|---|
| 7 | $('#comment').parent().parent().after(tbl); |
|---|
| 8 | hours = $('#field-hours'); |
|---|
| 9 | colClass = hours.parent().attr("class"); |
|---|
| 10 | tr = hours.parent().parent(); |
|---|
| 11 | $(tbl[0].rows[0]).append($('.'+colClass, tr)); |
|---|
| 12 | replacement = $('<td class="'+colClass+'"></td>'); |
|---|
| 13 | tr.prepend(replacement.clone()).prepend(replacement.clone()); |
|---|
| 14 | }; |
|---|
| 15 | |
|---|
| 16 | /* |
|---|
| 17 | * Rewritten by Russ Tyndall when this started failing on Trac 1 |
|---|
| 18 | * |
|---|
| 19 | * Code by Josh Godsiff, for www.oxideinteractive.com.au |
|---|
| 20 | * Email: josh@oxideinteractive.com.au |
|---|
| 21 | */ |
|---|
| 22 | $.prototype.cleanupTable = function() { |
|---|
| 23 | // make sure that body |
|---|
| 24 | if($(this).is('table')) { |
|---|
| 25 | var bodies = $(this).children('thead, tbody, tfoot'); |
|---|
| 26 | } else if($(this).is('thead, tbody, tfoot')) { |
|---|
| 27 | var bodies = $(this); |
|---|
| 28 | } else { |
|---|
| 29 | return; |
|---|
| 30 | } |
|---|
| 31 | // helper to determine if a table cell has visible content |
|---|
| 32 | var has_contents =function(it){ |
|---|
| 33 | var t=$(it).text(); |
|---|
| 34 | if(t && $.trim(t).length>0 ) return true; |
|---|
| 35 | return false; |
|---|
| 36 | }; |
|---|
| 37 | |
|---|
| 38 | $(bodies).each(function(bodyIdx, body){ |
|---|
| 39 | body = $(body); |
|---|
| 40 | var trs = $(body).children('tr'); |
|---|
| 41 | var leftTds = [], rightTds = [], extraTDs=[]; |
|---|
| 42 | $(trs).each(function(ind, val){ |
|---|
| 43 | var kids = $(this).children(); |
|---|
| 44 | |
|---|
| 45 | // special case for things that get removed badly (eg: CondFieldsGenshiPlugin) |
|---|
| 46 | // this is a two cell row in a table full of 4 cell rows |
|---|
| 47 | if(kids.length == 2 && !$(kids[1]).is('.fullrow')){ |
|---|
| 48 | $(this).detach(); |
|---|
| 49 | extraTDs.push([kids[0], kids[1]]); |
|---|
| 50 | } |
|---|
| 51 | else if(kids.length == 4){ |
|---|
| 52 | $(this).detach(); |
|---|
| 53 | if(has_contents(kids[0]) || has_contents(kids[1])) |
|---|
| 54 | leftTds.push([kids[0], kids[1]]); |
|---|
| 55 | //else console.log('skipping empty', kids); |
|---|
| 56 | if(has_contents(kids[2]) || has_contents(kids[3])) |
|---|
| 57 | rightTds.push([kids[2], kids[3]]); |
|---|
| 58 | //else console.log('skipping empty', kids); |
|---|
| 59 | }; |
|---|
| 60 | }); |
|---|
| 61 | //console.log(leftTds,rightTds, extraTDs); |
|---|
| 62 | while(leftTds.length>0 || rightTds.length>0 || extraTDs.length>0){ |
|---|
| 63 | var tr = $('<tr>'); |
|---|
| 64 | var leftContent = leftTds.shift() || extraTDs.shift() || [$("<td>"),$("<td>")]; |
|---|
| 65 | var rightContent = rightTds.shift() || extraTDs.shift() || [$("<td>"),$("<td>")]; |
|---|
| 66 | tr.append(leftContent[0]).append(leftContent[1]) |
|---|
| 67 | .append(rightContent[0]).append(rightContent[1]); |
|---|
| 68 | $(body).append(tr); |
|---|
| 69 | } |
|---|
| 70 | }); |
|---|
| 71 | }; |
|---|
| 72 | |
|---|
| 73 | $(document).ready(function() { |
|---|
| 74 | // Give other layout changing functions time to run |
|---|
| 75 | |
|---|
| 76 | // move add hours input to next to the comment box |
|---|
| 77 | TandE_MoveAddHours(); |
|---|
| 78 | // remove add_hours from header |
|---|
| 79 | $('#h_hours,#h_hours + td').empty(); |
|---|
| 80 | |
|---|
| 81 | //remove whitespace caused by the above |
|---|
| 82 | $('#properties table').cleanupTable(); |
|---|
| 83 | $('table.properties').cleanupTable(); |
|---|
| 84 | |
|---|
| 85 | }); |
|---|