metadata.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Exif metadata display for MediaWiki file uploads
  2. //
  3. // Add an expand/collapse link and collapse by default if set to
  4. // (with JS disabled, user will see all items)
  5. //
  6. // attachMetadataToggle("mw_metadata", "More...", "Fewer...");
  7. function attachMetadataToggle(tableId, showText, hideText) {
  8. if (document.createTextNode) {
  9. var box = document.getElementById(tableId);
  10. if (!box)
  11. return false;
  12. var tbody = box.getElementsByTagName('tbody')[0];
  13. var row = document.createElement('tr');
  14. var col = document.createElement('td');
  15. col.colSpan = 2;
  16. var link = document.createElement('a');
  17. link.href = '#';
  18. link.onclick = function() {
  19. if (box.className == 'mw_metadata collapsed') {
  20. changeText(link, hideText);
  21. box.className = 'mw_metadata expanded';
  22. } else {
  23. changeText(link, showText);
  24. box.className = 'mw_metadata collapsed';
  25. }
  26. return false;
  27. }
  28. var text = document.createTextNode(hideText);
  29. link.appendChild(text);
  30. col.appendChild(link);
  31. row.appendChild(col);
  32. tbody.appendChild(row);
  33. // And collapse!
  34. link.onclick();
  35. return true;
  36. }
  37. return false;
  38. }