Comboios de Portugal
by Couto
CSS
img {border:0; margin: 0; padding:0}
.cpmobi-home-menuitem-separator {height:1px; color:#CCCCCC; background-color:#D0D0D0; border:0px solid #DDDDDD; }
.cpmobi-page-header {color:#FFFFFF; width:100%; font-style:normal; border-bottom:1px solid #FFFFFF; background-color:#9DB131; font-family:Verdana; margin:0; padding:0; }
body {line-height:normal; color:#666666; width:100%; background-color:#F2F2F2; font-family:Verdana; margin:0; font-weight:normal; border:0; }
.uvpvtcl {margin:0px; padding:0px; }
.cpmobi-footer-a {color:#E6EECF; text-decoration:none !important; }
a {color:#666666; font-family:Verdana; text-decoration:underline; }
.cpmobi-page-header-right {vertical-align:middle; color:#E6EECF; }
.cpmobi-home-menuitem {width:100%; padding:4px 5px 4px 5px; }
.cpmobi-home-menuitem-link {font-weight:bolder; }
.cpmobi-table-eco-header {font-weight:bolder; }
img {border:0px; }
.nejslmh {vertical-align:top; width:22px; }
.cpmobi-footer {color:#E6EECF; font-style:normal; background-color:#9DB131; border-top:1px solid #FFFFFF; padding:3px 1px 3px 7px !important; }
.iawilg {vertical-align:middle; width:30px; }
.mwtushk {vertical-align:top; }
hr {height:1px; color:#CCCCCC; background-color:#D0D0D0; margin:0; border:0px solid #DDDDDD; }
JavaScript
var CP = function() {
var that = this;
this.request = function(url, callback) {
var yql = 'http://query.yahooapis.com/v1/public/yql?q=',
query = function(url) {
return 'select * from html where url="' + url + '"';
},
req = $.ajax(yql + query(url), {
type: 'GET',
dataType: 'jsonp'
});
req.success(function(msg) {
callback(msg.results[0]);
});
};
this.replaceImages = function() {
$('img').each(function() {
var $img = $(this),
url = $img.attr('src');
$img.attr('src', 'http://m.cp.pt' + url);
});
};
this.replaceLink = function(e){
e.preventDefault();
var url = 'http://m.cp.pt/' + $(e.currentTarget).attr('href');
that.request(url, function(result) {
$('body').html(result);
that.replaceImages();
});
return false;
}
this.delegations = function(){
$('body').delegate('a', 'click', that.replaceLink);
$('body').delegate('form', 'submit', that.sendForm);
}
this.home = function() {
that.request('http://m.cp.pt', function(result) {
$('body').html(result);
that.replaceImages();
});
};
this.sendForm = function(e){
e.preventDefault();
var $form = $(e.currentTarget),
data = $form.find('input:text').serializeArray(),
url = 'http://m.cp.pt/mobi/' + $form.attr('action') +'?' + data[0]['name'] + '=' + data[0]['value'];
that.request(url, function(result){
$('body').html(result);
that.replaceImages();
});
};
this.init = (function(){
that.home();
that.delegations();
}());
};
var widget = new CP();