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.

117 lines
3.3 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. {
  28. ajax = new XMLHttpRequest(); // nowoczesne przegladarki
  29. ajax.overrideMimeType('text/xml');
  30. }
  31. catch(e) // IE <= 6
  32. {
  33. var XmlHttpVersions = [
  34. 'MSXML2.XMLHTTP.6.0',
  35. 'MSXML2.XMLHTTP.5.0',
  36. 'MSXML2.XMLHTTP.4.0',
  37. 'MSXML2.XMLHTTP.3.0',
  38. 'MSXML2.XMLHTTP',
  39. 'Microsoft.XMLHTTP'
  40. ];
  41. for (var i=0; i < XmlHttpVersions.length && null === ajax; i++)
  42. {
  43. try
  44. {
  45. ajax = new ActiveXObject(XmlHttpVersions[i]);
  46. } catch (e) {}
  47. }
  48. if (null === ajax)
  49. {
  50. throw new Error('AJAX Error');
  51. }
  52. }
  53. return true;
  54. }
  55. function response() {
  56. if (ajax.readyState != 4 || ajax.status != 200)
  57. return;
  58. var xml = ajax.responseXML;
  59. document.getElementById("curr_image").parentNode.href=document.getElementById("curr_image").src='images/upload/'+xml.getElementsByTagName("current")[0].getAttribute("src");
  60. document.title = 'Podgląd zdjęcia nr ' + xml.getElementsByTagName("current")[0].getAttribute("id");
  61. document.getElementById("author").firstChild.nodeValue=xml.getElementsByTagName("author")[0].firstChild.nodeValue;
  62. desc=document.getElementById("description");
  63. while(desc.hasChildNodes()) desc.removeChild(desc.firstChild);
  64. children=document.importNode(xml.getElementsByTagName("desc")[0], true).childNodes;
  65. for(i=0; i<children.length; i++) {
  66. desc.appendChild(children[i]);
  67. }
  68. document.getElementById("current").src=xml.getElementsByTagName("current")[0].getAttribute("src");
  69. if(xml.getElementsByTagName("next").length>0) {
  70. document.getElementById("next_image").src='images/upload/'+xml.getElementsByTagName("next")[0].getAttribute("thumb");
  71. nextid=xml.getElementsByTagName("next")[0].getAttribute("id");
  72. document.getElementById("next_image").alt=nextid;
  73. document.getElementById("next").style.display="block";
  74. }
  75. else {
  76. document.getElementById("next").style.display="none";
  77. nextid=-1;
  78. }
  79. if(xml.getElementsByTagName("prev").length>0) {
  80. document.getElementById("prev_image").src='images/upload/'+xml.getElementsByTagName("prev")[0].getAttribute("thumb");
  81. previd=xml.getElementsByTagName("prev")[0].getAttribute("id");
  82. document.getElementById("prev_image").alt=previd;
  83. document.getElementById("prev").style.display="block";
  84. }
  85. else {
  86. document.getElementById("prev").style.display="none";
  87. previd=-1;
  88. }
  89. }
  90. function previewImage(el) {
  91. if(el==-1) return 0;
  92. ajax.onreadystatechange = response;
  93. ajax.open('GET', path+ '/ask.php?id=' + el, true);
  94. ajax.send(null);
  95. }
  96. function prev() {
  97. previewImage(previd);
  98. }
  99. function next() {
  100. previewImage(nextid);
  101. }