Ver Mensaje Individual
  #3 (permalink)  
Antiguo 04/06/2013, 11:18
Avatar de estrella2684
estrella2684
 
Fecha de Ingreso: septiembre-2012
Mensajes: 19
Antigüedad: 12 años, 4 meses
Puntos: 3
Respuesta: mapa de google en pagina sin recargar

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Documento sin título</title>
  5.  
  6. <script src="js/libs/jquery-1.7.2.min.js" ></script>
  7.       <style>
  8.  
  9. #map-canvas, #map_canvas {
  10.   height: 30%;
  11.   width:20%;
  12.  
  13. }
  14.  
  15. @media print {
  16.   html, body {
  17.     height: auto;
  18.   }
  19.  
  20.   #map-canvas, #map_canvas {
  21.     height: 650px;
  22.   }
  23. }
  24.  
  25.    
  26. </head>
  27.  
  28.  
  29. <a href="rest.php" class="mnu_load" data-hash="#rest.php"  alt="Globalisimo - Restaurantes, Bares, Tijuana, San Diego">prueba</a>
  30. <a href="rest.php?id=3" class="mnu_load" data-hash="#rest.php?id=3"  alt="Globalisimo - Restaurantes, Bares, Tijuana, San Diego">prueba</a>
  31. <br />
  32.  
  33.  
  34.                        
  35.                     </div>
  36. <div class="contenedor">aqui esta cargando
  37. <div id="map-canvas" ></div>
  38.  
  39.  
  40. <script type="text/javascript">
  41. function initialize() {
  42.   var mapOptions = {
  43.     zoom: 8,
  44.     center: new google.maps.LatLng(-34.397, 150.644),
  45.     mapTypeId: google.maps.MapTypeId.ROADMAP
  46.   };
  47.  
  48.   var map = new google.maps.Map(document.getElementById('map-canvas'),
  49.       mapOptions);
  50.       //document.getElementById('map-canvas').style.position="inherit";
  51. }
  52.  
  53. function loadScript() {
  54.   var script = document.createElement('script');
  55.   script.type = 'text/javascript';
  56.   script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&' +
  57.      'callback=initialize';
  58.   document.body.appendChild(script);
  59. }
  60.  
  61.  
  62.  
  63.             //para cargar secciones
  64.     (function($){
  65.        
  66.         var contenido = $('div.contenedor'), url_anterior = '', extension = '.php', original = window.location;
  67.         $('a.mnu_load').each(function(){ //Cambiamos los href por el contenido del atributo data-hash
  68.            
  69.             $(this).attr('href', $(this).data('hash'));
  70.         });
  71.         $('a.mnu_load').on('click', function(e){   
  72.                         var hash = $(this).attr('href');
  73.                        
  74.        
  75.            
  76.             e.preventDefault();  
  77.             revisarURL(hash).done(function(){
  78.                 window.location.href = hash; // Buen hash, cambiemoslo en la URL           
  79.             }).fail(function(){
  80.                 window.location.href = '#error';
  81.             }).always(function(datos){
  82.                 contenido.html(datos);
  83.             });
  84.            
  85.             //cambiar titulo
  86.             var titulo=$(this).attr('alt');
  87.        
  88.         if(!titulo){
  89.             document.title ='Globalisimo Un Mundo de Opciones - Restaurantes, Clasificados, Noticias, Eventos, Tijuana, San Diego';
  90.             }else{
  91.         document.title = titulo;
  92.         }
  93.            
  94.         });
  95.        
  96.         revisarURL(); // Si hay un hash en la URL (ej, copiamos y pegamos en una conversación) cargará la URL correcta.
  97.         setInterval(function(){
  98.             revisarURL().fail(function(){
  99.                 window.location.href = '#error';
  100.             }).always(function(datos){
  101.                 contenido.html(datos);
  102.             });
  103.         },250); // Revisamos cualquier cambio en el Hash cada 250 milisegundos
  104.        
  105.         function revisarURL (hash){
  106.             var deferred = $.Deferred();
  107.             if (!hash) { // Esto ocurre cuando se pulsa el botón de atrás o adelante en el navegador o al pasar una URL con hash
  108.                 hash = window.location.hash;
  109.             }
  110.             if (!hash) { // Esto puede pasar si es la primera URL - index.html en nuestro caso
  111.                 var url = window.location.pathname; // Obtenemos la URL completa
  112.                 var archivo = url.substring(url.lastIndexOf('/')+1); // Nos quedamos con el nombre del archivo (index.html)
  113.                 hash = archivo.replace(extension,''); // Le quitamos la extensión para convertirlo en "hash"
  114.             }
  115.             if (hash !== url_anterior){
  116.                 url_anterior = hash;
  117.                 cargarPagina(hash).done(
  118.                     function(data){
  119.                         var html = $(data);
  120.                         var filtrado = html.find('.contenedor');
  121.                         deferred.resolve(filtrado.html());
  122.                     }
  123.                 ).fail(function(){ // La URL no existe                 
  124.                     //deferred.reject('<p>La página no existe.</p>'); // Rechazamos nuestro deferred       
  125.                 });
  126.             }
  127.             return deferred.promise(); // Devolvemos una promesa, no un deferred
  128.         }
  129.  
  130.  
  131.         function cargarPagina(hash){
  132.             url = hash.replace('#','');  //Quitamos la almohadilla
  133.            
  134.             loadScript();  
  135.  
  136.            
  137.             var re  = /^([a-zA-Z_])+.php?/;
  138. if (!re.test(url))
  139.                 {
  140.                 url=url + extension;
  141.                 }else{
  142.                     url=url;
  143.                     }
  144.             return $.ajax({
  145.                 type: "GET",
  146.                 url: url,
  147.                 async: true,
  148.                 dataType: "html"});        
  149.                
  150.                
  151.                
  152.         }
  153.     })(jQuery);
  154.   </script>
  155.  
  156.  
  157.      
  158. </body>
  159. </html>