<mySearch ⁄>
<mySnippets order="rand" ⁄>
<myContacts ⁄><email ⁄>
<windows live messenger ⁄>
<myCurriculum type="pdf" ⁄>
<myBlog show="last" ⁄>
<myNews show="rand" ⁄>
<myNews type="cat" ⁄>
<myQuote order="random" ⁄>Não faças aos outros homens o que não queres que eles te façam
<myPhoto order="random" ⁄>
<myAdSense ⁄>
<myVisitorsMap ⁄>
/** * Class Events - possui vários métodos/ propriedades estáticos comuns */ Events = function(){ } /** * Adicionar Event * * Adaptada do seguinte URL * http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html * * @param Object * @param Object * @param Object */ Events.AddEvent = function(obj, type, fn){ if(!obj) return; this.RemoveEvent(obj, type, fn); if (obj.addEventListener) { obj.addEventListener(type, fn, false); } else { if (obj.attachEvent) { obj["e" + type + fn] = fn; obj[type + fn] = function(){ obj["e" + type + fn](window.event); } obj.attachEvent("on" + type, obj[type + fn]); } } } /** * Remover Event * * Adaptada do seguinte URL * http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html * * @param Object * @param Object * @param Object */ Events.RemoveEvent = function(obj, type, fn){ if (obj.removeEventListener) { try{obj.removeEventListener(type, fn, false);} catch(e){} } else{ if (obj.detachEvent) { obj.detachEvent("on" + type, fn); obj[type + fn] = null; obj["e" + type + fn] = null; } } }
/** * Class Misc - possui vários métodos/ propriedades estáticos comuns */ Misc = function(){} // ficheiro que vai responder aos pedidos Misc.ServerFile = "ajax.php"; /** * Hack IE para ultrapassar problema cache pedidos get * * @param String */ Misc.AntiCacheRand = function(aurl){ var rnd = encodeURI(Math.random()); aurl += (aurl.indexOf("?") >= 0) ? "&foo=" + rnd : "?foo=" + rnd; return aurl; }; /** * Criar request */ Misc.CreateHttpRequest = function(){ if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/html'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } if (!http_request) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } return http_request; }; /** * Cria um Timer. * Terá como finalidade executar uma determinada função * de X em X segundos * * @param Object Função a executar * @param Int Intervalo temporário (em segundos) */ Misc.Timer = function(func,interval_seconds){ setInterval(func,interval_seconds*1000); }; /** * Obter a referência para um elemento * * @param String */ $ = function(element){return document.getElementById(element);}; //fim class Misc
/** * Class Ajax */ Ajax = function(){}; /** * Actualizar Tempo * * @param Object Onde vai ser impresso o resultado * @param String Formatação da hora */ Ajax.UpdateTime = function(id_span,time_format){ var url = Misc.AntiCacheRand(Misc.ServerFile + "?time_format=" + time_format); var http_request = Misc.CreateHttpRequest(); http_request.onreadystatechange = function(){ var state = http_request.readyState; //pedido completo e respondido com sucesso if (state == 4 && http_request.status == 200) { $(id_span).innerHTML=http_request.responseText; //escrever resultado } } http_request.open("GET", url, true); http_request.send(null); }
<?php include_once("class.MyServerTime.php"); $my_server_time=new MyServerTime($_GET["time_format"]); echo $my_server_time->GetDate(); ?>
<?php class MyServerTime{ private $_format; //formatação DateTime /** * Método construtor * * @param String $format */ public function __construct($format){$this->Format($format);} /** * Getter/ Setter TimeFormat * * @param String $value * @return String */ public function Format($value=""){ if($value){$this->_format=$value;} else{return $this->_format;} } /** * Obter Data formatada * * @return DateTime */ function GetDate(){return gmdate($this->Format());} } ?>
Init = function (){ var id_span = "mySpanTime"; var timer_interval=1; var time_format="H:i:s"; Ajax.UpdateTime(id_span,time_format); Misc.Timer('Ajax.UpdateTime("'+id_span+'","'+time_format+'")',timer_interval); } Events.AddEvent(window, "load", Init);
<html> <head> <title>MyTimeServer</title> <script type="text/javascript" src="Events.js"></script> <script type="text/javascript" src="Misc.js"></script> <script type="text/javascript" src="Ajax.js"></script> <script type="text/javascript" src="Init.js"></script> </head> <body> Hora: <span id="mySpanTime"></span> </body> </html>