Changeset 1169
- Timestamp:
- 09/03/10 16:00:42 (17 months ago)
- Files:
-
- 1 modified
-
HelpIM3/htdocs/functions.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
HelpIM3/htdocs/functions.js
r1168 r1169 51 51 }, 52 52 53 expandAll: function(className) { 54 document.getElementsByClassName(className).forEach(HIM.el.show); 55 }, 56 57 colapseAll: function(className) { 58 document.getElementsByClassName(className).forEach(HIM.el.hide); 53 toArray: function(list) { 54 /* some things in javascript look like arrays but aren't 55 * this is to make sure we do have an array after all 56 */ 57 var arr = []; 58 if (!list.length) { 59 // it's an object - iterate its properties 60 for (var i in list) 61 if (list.hasOwnProperty(i)) 62 arr.push(list[i]); 63 } else if (list instanceof Array) { 64 // nothing to do 65 return list; 66 } else { 67 for (var i=0; i<list.length; i++) 68 arr.push(list[i]); 69 } 70 return arr; 59 71 }, 60 72 … … 522 534 function unhideCommentInput(id) 523 535 { 524 show(id);525 536 if (previousHiddenComment && previousHiddenComment != id) 526 537 hide(previousHiddenComment); 538 if (id) 539 show(id); 527 540 previousHiddenComment=id; 541 return false; // stop bubbling 528 542 } 529 543 544 function expandComments(toggleButton) { 545 _toggleComments( 546 toggleButton, 547 function(comment_row) { 548 HIM.el.show(comment_row); 549 toggleButton.innerHTML = '-'; 550 toggleButton.title = 'collapse comments'; 551 }); 552 } 553 554 function collapseComments(toggleButton) { 555 _toggleComments( 556 toggleButton, 557 function(comment_row) { 558 HIM.el.hide(comment_row); 559 toggleButton.innerHTML = '+'; 560 toggleButton.title = 'expand comments'; 561 }); 562 } 563 564 function _toggleComments(toggleButton, fun) { 565 /* navigate to comment row like 566 * <tr><td>..</td><td>{toggleButton}</td></tr> 567 * <tr><td>...</td></tr> 568 * <tr>{comment_row}</tr> 569 */ 570 var comment_row = 571 HIM.el.next( 572 HIM.el.next( 573 HIM.el.parentNode(toggleButton, 'tr'), 574 'tr'), 575 'tr'); 576 fun(comment_row); 577 } 578 579 function toggleComments(toggleButton) { 580 if (toggleButton.innerHTML == '+') 581 expandComments(toggleButton); 582 else 583 collapseComments(toggleButton); 584 } 530 585 531 586 HIM.registerHandler('onload', function() { 532 587 // make comments collapsible 533 588 534 var comment s = document.getElementsByClassName('comment_row');535 536 if (comment s.length>0) {589 var comment_rows = document.getElementsByClassName('comment_row'); 590 591 if (comment_rows.length>0) { 537 592 var header = document.createElement('th') 538 593 var linkp = document.createElement('a'); 539 linkp.setAttribute('href', 'javascript:HIM.expandAll("comment_row")'); 594 linkp.setAttribute('href', '#'); 595 linkp.onclick = function() { 596 document.getElementsByClassName('comments_toggleButton').forEach(expandComments); 597 return false; 598 } 540 599 linkp.appendChild(document.createTextNode('+')); 541 600 var linkm = document.createElement('a'); 542 linkm.setAttribute('href', 'javascript:HIM.colapseAll("comment_row")'); 601 linkm.setAttribute('href', '#'); 602 linkm.onclick = function() { 603 document.getElementsByClassName('comments_toggleButton').forEach(collapseComments); 604 return false; 605 } 543 606 linkm.appendChild(document.createTextNode('-')); 544 607 header.appendChild(linkp); … … 546 609 header.appendChild(linkm); 547 610 HIM.el.firstChild( 548 HIM.el.parentNode(comment s[0], 'tbody'),611 HIM.el.parentNode(comment_rows[0], 'tbody'), 549 612 'tr' 550 613 ).appendChild(header); 551 614 } 552 comments.forEach( 553 function(comment) { 554 var logMessage = HIM.el.prev(HIM.el.prev(comment, 'tr'), 'tr'); 615 616 comment_rows.forEach( 617 function(comment_row) { 618 var logMessage = HIM.el.prev(HIM.el.prev(comment_row, 'tr'), 'tr'); 555 619 if (!logMessage) 556 620 return; 557 621 558 var comment_ input_form =622 var comment_row_input_form = 559 623 HIM.el.firstChild( 560 624 HIM.el.firstChild( 561 'input_'+comment .id,625 'input_'+comment_row.id, 562 626 'td'), 563 627 'form'); 564 628 565 629 logMessage.onmouseover = function() { 566 unhideCommentInput(comment_ input_form.id);630 unhideCommentInput(comment_row_input_form.id); 567 631 } 568 632 569 633 // create new td with text 570 634 var td = logMessage.appendChild(document.createElement('td')); 635 td.className = 'comments_toggleButton'; 571 636 var text = td.appendChild(document.createTextNode('+')); 572 637 573 // hide comment 574 HIM.el.hide(comment );638 // hide comment_row 639 HIM.el.hide(comment_row); 575 640 576 641 // add click handler to new td element 577 td.onclick = function() { 578 HIM.el.toggle(comment, 579 function() { 580 td.innerHTML = '-'; 581 td.title = 'collapse comments'; 582 }, 583 function() { 584 td.innerHTML = '+'; 585 td.title = 'expand comments'; 586 }); 642 td.onclick = function() { 643 toggleComments(td); 587 644 }; 588 645 … … 592 649 593 650 // fix colspan 594 var comment TD = HIM.el.firstChild(comment, 'td');595 if (comment TD) {596 comment TD.setAttribute('colspan','4');651 var comment_rowTD = HIM.el.firstChild(comment_row, 'td'); 652 if (comment_rowTD) { 653 comment_rowTD.setAttribute('colspan','4'); 597 654 } 598 655 }
