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.

118 lines
3.3 KiB

  1. var ajax;
  2. var disp;
  3. var disp_img;
  4. var disp_info;
  5. var disp_name;
  6. var disp_author, disp_a;
  7. var curr, last, first;
  8. function init() {
  9. initAjax();
  10. disp=document.getElementById("disp");
  11. disp_a=document.getElementById("disp_a");
  12. disp_name=document.getElementById("disp_name");
  13. disp_author=document.getElementById("disp_author");
  14. disp_img=document.getElementById("disp_img");
  15. disp_info=document.getElementById("disp_info");
  16. if (!document.importNode) {
  17. document.importNode = function(node, allChildren) {
  18. switch (node.nodeType) {
  19. case 1:
  20. var newNode = document.createElement(node.nodeName);
  21. /*if (node.attributes && node.attributes.length > 0)
  22. for (var i = 0; il = node.attributes.length; i < il)
  23. newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i++].nodeName));*/
  24. //alert("Attr done");
  25. if (allChildren && node.childNodes && node.childNodes.length > 0) {
  26. il=node.childNodes.length;
  27. for (var i = 0; i < il; i++)
  28. newNode.appendChild(document.importNode(node.childNodes[i], allChildren));
  29. }
  30. return newNode;
  31. break;
  32. default:
  33. return document.createTextNode(node.nodeValue);
  34. break;
  35. }
  36. };
  37. }
  38. if(!disp_name.firstChild)
  39. disp_name.appendChild(document.createTextNode(' '));
  40. if(!disp_author.firstChild)
  41. disp_author.appendChild(document.createTextNode(' '));
  42. }
  43. function initAjax() {
  44. try {
  45. if (window.XMLHttpRequest) {
  46. ajax = new XMLHttpRequest();
  47. ajax.overrideMimeType('text/xml');
  48. }
  49. else if (window.ActiveXObject)
  50. ajax = new ActiveXObject('Microsoft.XMLHTTP');
  51. else throw 'AJAX Error';
  52. }
  53. catch (e) {
  54. return false;
  55. }
  56. if (!ajax) {
  57. alert('AJAX Error');
  58. return false;
  59. }
  60. return true;
  61. }
  62. function response() {
  63. if (ajax.readyState != 4 || ajax.status != 200)
  64. return;
  65. var xml = ajax.responseXML;
  66. while(disp_info.hasChildNodes()) disp_info.removeChild(disp_info.firstChild);
  67. elemXML=xml.getElementsByTagName("desc")[0];
  68. if(document.importNode) children=document.importNode(elemXML, true).childNodes;
  69. else children=elemXML.childNodes;
  70. for(i=0; i<children.length; i++) {
  71. disp_info.appendChild(children[i]);
  72. }
  73. disp_img.src= 'images/upload/' + xml.getElementsByTagName("src")[0].firstChild.nodeValue;
  74. disp_a.href= 'images/upload/' + xml.getElementsByTagName("src")[0].firstChild.nodeValue;
  75. disp_name.firstChild.nodeValue=xml.getElementsByTagName("name")[0].firstChild.nodeValue;
  76. disp_author.firstChild.nodeValue=xml.getElementsByTagName("author")[0].firstChild.nodeValue;
  77. if(xml.getElementsByTagName("last").length) {
  78. document.getElementById("disp_next").src="images/next_i.png";
  79. last=true;
  80. }
  81. if(xml.getElementsByTagName("first").length) {
  82. document.getElementById("disp_prev").src="images/prev_i.png";
  83. first=true;
  84. }
  85. disp.style.display="block";
  86. }
  87. function previewImage(el) {
  88. curr=el;
  89. last=false;
  90. first=false
  91. document.getElementById("disp_next").src="images/next.png";
  92. document.getElementById("disp_prev").src="images/prev.png";
  93. ajax.onreadystatechange = response;
  94. ajax.open('GET', sciezka + 'ask.php?name=' + el, true);
  95. ajax.send(null);
  96. }
  97. function prev() {
  98. if(!first) previewImage(curr-1);
  99. }
  100. function next() {
  101. if(!last) previewImage(curr+1);
  102. }
  103. function closeDisp() {
  104. disp.style.display="none";
  105. }