Hello. I'm studying, there is a piece of code i cannot get to work, so i was asking myself if you can help, given that all the pastebin doesn't accept the prototype link. I'm not exaclty sure of what it does, i assume it goes through the document dom to place every div page in the right order to be viewed. Its a php file, and i can't really understand why php is needed to solve this task, however is a pice of code found in a book, it could be wrong.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <script type="text/javascript" src="prototype.js"></script> <script type="text/javascript"> function importNode(p_element, p_allChildren) { switch (p_element.nodeType) { case 1: var newNode = document.createElement(p_element.nodeName); if (p_element.attributes && p_element.attributes.length >0) for (var i = 0, il=p_element.attributes.length; i < il;) newNode.setAttribute(p_element.attributes[i].nodeName, p_element.getAttribute( p_element.attributes[i++].nodeName)); if(p_allChildren && p_element.childNotes && p_element.childNodes.length > 0) for (var i = 0, il = p_element.childNodes.length; i < il;) newNode.appendChild(importNode(p_element.childNodes[i++], p_allChildren)); return NewNode; break; case 2: case 3: return document.createTextNode(p_element.nodeValue); break; } }; function turnPage(p_number) { var pages = $('article').getElemenetsByTagName('div'); for (var i = 0, il = pages.length; i< il; i++) { $(pages[i]).setStyle({display: 'none'}); $('l' + (i+1)).innerHTML = '<a href="article.php?page=' + (i+1)+ '"onClick="return turnPage('+ (i+1)+')">' +(i+1)+'</a>'; } if ($('page' + p_number).innerHTML == '') { new Ajax.Request('article.php', { method: 'post', parameters: {page:p_number }, onSuccess: function(xhrResponse) { var response = xhrResponse.responseXML; var newNode; if (!window.ActiveXObject) { newNode = document.importNode(response.getElementsByTagName('page')[0].childNodes[1], true); $('page' + p_number).appendChild(newNode); } else { newNode = importNode(response.getElementsByTagName('page')[0].childNodes[0], true); $('page' + p_number).appendChild(newNode); } $('l' + p_number).innerHTML = p_number; $('page' + p_number).setStyle({display: 'block' }); }, onFailure: function(xhrResponse) { $('page').innerHTML = xhrResponse.statusText; } }); } else { $('l' + p_number).innerHTML = p_number; $('page'+ p_number).setStyle({display: 'block' }); } return (false); }</script> <title>Paged navigation</title> </head><body> <h1> Paged Navigation </h1> <div id="article"> <div id="page1"> <p>This is page one.</p> </div> <div id="page2"> <p>This is page two.</p> </div> <div id="page3"> <p>This is page three.</p> </div> <div id="page4"> <p>This is page four.</p> </div> <div id="page5"> <p>This is page five.</p> </div> </div> <div id="pageNavContainer"> <ul id="pageNavList"> <li id="l1">1</li> <li id="l2"> <a href="article.php?page=2" onClick="return turnPage(2);">2</a> </li> <li id="l3"> <a href="article.php?page=3" onClick="return turnPage(3);">3</a> </li> <li id="l4"> <a href="article.php?page=4" onClick="return turnPage(4);">4</a> </li> <li id="l5"> <a href="article.php?page=5" onClick="return turnPage(5);">5</a> </li> </ul> </div> </body> </html> -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To view this discussion on the web visit https://groups.google.com/d/msg/prototype-scriptaculous/-/Ibtlp8ZSnzAJ. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.