|
1 | | -/** |
2 | | - * @author SORIA Pierre-Henry |
3 | | - * @email pierrehs@hotmail.com |
4 | | - * @link http://github.com/pH-7/Nav-Doc-Script-V2 |
5 | | - * @copyright Copyright pH7 Script All Rights Reserved. |
6 | | - * @license CC-BY - http://creativecommons.org/licenses/by/3.0/ |
| 1 | +/* |
| 2 | + * Title: AjPH |
| 3 | + * Description: Loading pages in Ajax with HTML5 pushState. |
| 4 | + * |
| 5 | + * Author: Pierre-Henry Soria <ph7software@gmail.com> |
| 6 | + * Copyright: (c) 2012-2013, Pierre-Henry Soria. All Rights Reserved. |
| 7 | + * License: GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory. |
| 8 | + * Version: 1.3 |
7 | 9 | */ |
8 | 10 |
|
9 | | -$(document).ready(function() { |
10 | | - if (window.history && history.pushState) { |
11 | | - historyedited = false; |
12 | | - $(window).bind('popstate', function(e) { |
13 | | - if (historyedited) { |
14 | | - loadPage(location.pathname + location.search); |
15 | | - } |
16 | | - }); |
17 | | - doPager(); |
18 | | - } |
| 11 | +$(document).ready(function() |
| 12 | +{ |
| 13 | + if(window.history && history.pushState) |
| 14 | + { |
| 15 | + bHistoryEdited = false; |
| 16 | + $(window).bind('popstate', function() { |
| 17 | + if(bHistoryEdited) { |
| 18 | + loadPage(location.pathname + location.search); |
| 19 | + } |
| 20 | + }); |
| 21 | + doPager(); |
| 22 | + } |
19 | 23 | }); |
20 | 24 |
|
21 | | -function doPager() { |
22 | | - $('a[data-load=ajax]').click(function(e) { |
23 | | - e.preventDefault(); |
24 | | - $('#ajph').html("<div id='loading'>Loading...</div>"); |
25 | | - loadPage($(this).attr('href')); |
26 | | - history.pushState(null, null, $(this).attr('href')); |
27 | | - historyedited = true; |
28 | | - }); |
| 25 | +function doPager() |
| 26 | +{ |
| 27 | + // Loading the ajax pages |
| 28 | + $('a[data-load=ajax]').click(function(oE) |
| 29 | + { |
| 30 | + oE.preventDefault(); |
| 31 | + $('#ajph').html("<div id='loading'>Loading...</div>"); |
| 32 | + loadPage($(this).attr('href')); |
| 33 | + history.pushState(null, null, $(this).attr('href')); |
| 34 | + bHistoryEdited = true; |
| 35 | + }); |
29 | 36 | } |
30 | 37 |
|
31 | | -function loadPage(link) { |
32 | | - $.ajax({ |
33 | | - url: link, |
34 | | - processData: true, |
35 | | - dataType:'html', |
36 | | - success: function(data) { |
37 | | - var content = $(data).find("#sub_ajph"); |
38 | | - var title = $(data).filter('title').text(); |
39 | | - document.title = title; |
40 | 38 |
|
41 | | - $('#ajph').fadeOut('200',function(){ |
42 | | - $(this).html(content.html()).fadeIn('200'); |
43 | | - }); |
44 | | - } |
45 | | - }); |
46 | | - doPager(); |
| 39 | +/** |
| 40 | + * Load page. |
| 41 | + * |
| 42 | + * @param {String} Link |
| 43 | + * @return {Void} |
| 44 | + */ |
| 45 | +function loadPage(sLink) |
| 46 | +{ |
| 47 | + $.ajax({ |
| 48 | + url: sLink, |
| 49 | + processData: true, |
| 50 | + dataType:'html', |
| 51 | + success: function(oData) |
| 52 | + { |
| 53 | + var oContent = $(oData).find("#sub_ajph"); // Get the new Contents |
| 54 | + var oTitle = $(oData).filter('title'); // Get the new Title tag |
| 55 | + var oHeadings = $(oData).find('#headings:first'); // Get the Headings Group |
| 56 | + $('title').text(oTitle.text()); // Set Title |
| 57 | + $('#headings:first').html(oHeadings.html()); // Set the Headings Group |
| 58 | + $('#ajph').fadeOut(200, function() { |
| 59 | + $(this).html(oContent.html()).fadeIn(200); // Set Contents |
| 60 | + }); |
| 61 | + } |
| 62 | + }); |
| 63 | + doPager(); |
47 | 64 | } |
0 commit comments