-
Notifications
You must be signed in to change notification settings - Fork 0
/
7-exemplo-bonito-abas-link.php
93 lines (81 loc) · 1.86 KB
/
7-exemplo-bonito-abas-link.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
<head>
<title>Exemplos Javascript não obstrutivo</title>
<!-- ADICIONA CLASSE NO HTML QUANDO HA SUPORTE -->
<script>document.getElementsByTagName('html')[0].className += ' js'</script>
<style>
ul {
overflow:hidden;
list-style:none;
}
ul li {
float:left;
padding-right:30px;
}
.aba {
display:block;
border-top:solid 1px #CCC;
padding:30px;
}
</style>
</head>
<body>
<h1>Exemplo MAIS BONITO de javascript não obstrutivo em abas / páginas com ajax</h1>
<div>Contador: <strong id="counter"></strong></div>
<ul>
<li><a href="?p=aba1">Aba 1</a></li>
<li><a href="?p=aba2">Aba 2</a></li>
<li><a href="?p=aba3">Aba 3</a></li>
<li><a href="?p=aba4">Aba 4</a></li>
</ul>
<div class="aba">
<?php
$p = $_REQUEST["p"];
if (!($p)) $p = "aba1";
include($p.".html");
?>
</div>
<!-- TENTA CARREGAR JQUERY EXTERNO, EM CASO DE TIMEOUT CARREGA LOCAL -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="scripts/jquery-1.7.1.min.js"><\/script>')</script>
<script>
var conteudoAbas = $(".aba")
, abas = $("ul a")
, pagina
, link
, state
abas.click(function(e) {
e.preventDefault();
link = $(this).attr('href')
pagina = link.replace(/.*p=/,"")+".html"
state = {
'pagina': pagina
}
$.ajax({
url: pagina,
success: function(data) {
conteudoAbas.html(data)
history.pushState(state, link, "abacate") /* State, title, url */
}
});
});
// Popstate
window.onpopstate = function(event) {
if (event.state == null)
return;
$.ajax({
url: event.state.pagina,
success: function(data) {
conteudoAbas.html(data)
}
});
}
// Contador
var cont = 0;
setInterval(function() {
$("#counter").html(cont++)
},1000)
</script>
</body>
</html>