Silnik strony + galerii zdjęć Suczawa 2009
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.1 KiB

  1. var ajax, previd, nextid;
  2. function init() {
  3. initAjax();
  4. if (!document.importNode) {
  5. document.importNode = function(node, allChildren) {
  6. switch (node.nodeType) {
  7. case 1:
  8. var newNode = document.createElement(node.nodeName);
  9. if (allChildren && node.childNodes && node.childNodes.length > 0) {
  10. il=node.childNodes.length;
  11. for (var i = 0; i < il; i++)
  12. newNode.appendChild(document.importNode(node.childNodes[i], allChildren));
  13. }
  14. return newNode;
  15. break;
  16. default:
  17. return document.createTextNode(node.nodeValue);
  18. break;
  19. }
  20. };
  21. }
  22. nextid=(document.getElementById("next_image")!=null)?document.getElementById("next_image").alt:-1;
  23. previd=(document.getElementById("prev_image")!=null)?document.getElementById("prev_image").alt:-1;
  24. }
  25. function initAjax() {
  26. try {
  27. if (window.XMLHttpRequest) {
  28. ajax = new XMLHttpRequest();
  29. ajax.overrideMimeType('text/xml');
  30. }
  31. else if (window.ActiveXObject)
  32. ajax = new ActiveXObject('Microsoft.XMLHTTP');
  33. else throw 'AJAX Error';
  34. }
  35. catch (e) {
  36. return false;
  37. }
  38. if (!ajax) {
  39. alert('AJAX Error');
  40. return false;
  41. }
  42. return true;
  43. }
  44. function response() {
  45. if (ajax.readyState != 4 || ajax.status != 200)
  46. return;
  47. var xml = ajax.responseXML;
  48. document.getElementById("curr_image").parentNode.href=document.getElementById("curr_image").src='images/upload/'+xml.getElementsByTagName("current")[0].getAttribute("src");
  49. document.title = 'Podgląd zdjęcia nr ' + xml.getElementsByTagName("current")[0].getAttribute("id");
  50. document.getElementById("author").firstChild.nodeValue=xml.getElementsByTagName("author")[0].firstChild.nodeValue;
  51. desc=document.getElementById("description");
  52. while(desc.hasChildNodes()) desc.removeChild(desc.firstChild);
  53. children=document.importNode(xml.getElementsByTagName("desc")[0], true).childNodes;
  54. for(i=0; i<children.length; i++) {
  55. desc.appendChild(children[i]);
  56. }
  57. document.getElementById("current").src=xml.getElementsByTagName("current")[0].getAttribute("src");
  58. if(xml.getElementsByTagName("next").length>0) {
  59. document.getElementById("next_image").src='images/upload/'+xml.getElementsByTagName("next")[0].getAttribute("thumb");
  60. nextid=xml.getElementsByTagName("next")[0].getAttribute("id");
  61. document.getElementById("next_image").alt=nextid;
  62. document.getElementById("next").style.display="block";
  63. }
  64. else {
  65. document.getElementById("next").style.display="none";
  66. nextid=-1;
  67. }
  68. if(xml.getElementsByTagName("prev").length>0) {
  69. document.getElementById("prev_image").src='images/upload/'+xml.getElementsByTagName("prev")[0].getAttribute("thumb");
  70. previd=xml.getElementsByTagName("prev")[0].getAttribute("id");
  71. document.getElementById("prev_image").alt=previd;
  72. document.getElementById("prev").style.display="block";
  73. }
  74. else {
  75. document.getElementById("prev").style.display="none";
  76. previd=-1;
  77. }
  78. }
  79. function previewImage(el) {
  80. if(el==-1) return 0;
  81. ajax.onreadystatechange = response;
  82. ajax.open('GET', path+ '/ask.php?id=' + el, true);
  83. ajax.send(null);
  84. }
  85. function prev() {
  86. previewImage(previd);
  87. }
  88. function next() {
  89. previewImage(nextid);
  90. }