//创建Cht公共对象
//用来统一管理JS脚本
//2012 by Shw 创建
window.Cht={
//命名空间 cityInfo
cityInfo:{},
//命名空间 社会化媒体
SNS:{}
};
(function(){
window.Cht.cityInfo = {
//获取Top酒店数据
getHotelList : function(DomId){
if(typeof(cityIdNum)!="undefined"){
var hotelApiUrl="//www.chinahighlights.com/api/api.asp?method=cht.hotel.monthpromotion&cityID="+cityIdNum+"&jsoncallback=?";
$.getJSON(hotelApiUrl,function(data){
var thisHtml="";
$.each(data.Hotel,function(i,n){
var starStr=$(n.HotelStar).attr("alt");
if ( i == 0 ){
thisHtml='
'+ (i+1) +' '+n.HotelName+' ('+starStr+') $'+n.HotelLowPrice+'
';
}else{
thisHtml+=''+ (i+1) +' '+n.HotelName+' ('+starStr+') $'+n.HotelLowPrice+'';
}
});
$("#"+DomId).html(thisHtml);
});
}
},
//根据城市ID获取天气预报
getWeather : function(DomId){
var thisDom=$("#"+DomId);
if(thisDom.length>0){
var cityIdStr=thisDom.text();
var getDataUrl="/index.php/travelguide/getweather/";
$.getJSON(getDataUrl, { cityId: cityIdStr},function(data){
var reg = /\b(\w)|\s(\w)/g;
var cityNme=data.weatherinfo["city"];
var cityName=cityNme.replace(reg,function(m){return m.toUpperCase()});
var weatherPic="
";
var weatherTemp=data.weatherinfo["temp1"];
var weatherHtml=""+cityName+""+" "+weatherPic+" "+weatherTemp;
thisDom.html(weatherHtml);
});
}
}
};
})();
(function(){
window.Cht.SNS = {
//获取当前页面标题
PageTitle : $("title").text(),
//获取当前URL
//HREF : document.location.href
//测试用URL
HREF : document.location.href.replace("127.0.0.1/index.php/travelguide/guide","www.chinahighlights.com"),
//facebook的sharer地址
//使用是需要:.replace("$1",this.HREF).replace("$2",this.PageTitle)
faceBookUpdataUrl : "http://www.facebook.com/sharer/sharer.php?u=$1&t=$2",
//twitter的sharer地址
//使用是需要:.replace("$1",thisHREF);
twitterUpdataUrl : "https://twitter.com/intent/tweet?original_referer=$1&related=Chinahighlights&screen_name=Chinahighlights&source=tweetbutton&text=",
test : function(){
alert("test");
},
//获取当前页面的FACEBOOK的sharer数量
getFaceBookSharerNum : function(DomId){
var faceBookApiUrl = "http://api.facebook.com/restserver.php?method=links.getStats&urls=";
//真实的URL
//var thisFBApiUrl = faceBookApiUrl+this.HREF;
//测试用URL
var thisFBApiUrl="/api.xml";
// $.get(thisFBApiUrl,function(data){
// var apiData = $(data);
// var share_count = apiData.find("share_count").text();
// $("#"+DomId).text(share_count);
// });
},
//获取twitter当前页面的推荐数量
getTwitterNum : function(DomId){
var twitterApiUrl="http://cdn.api.twitter.com/1/urls/count.json?url=$1&callback=twttr.receiveCount";
//真实的URL
//var thisTtApiUrl=twitterApiUrl.replace("$1",thisHREF);
//测试用数据
var thisTtApiUrl="/Tt.html";
// $.get(thisTtApiUrl,function(data){
// var jsonStr=data.replace("twttr.receiveCount","");
// var thisJson=eval(jsonStr);
// $("#"+DomId).text(thisJson.count);
// });
},
//sharer到Facebook
sharerToFaceBook : function(){
window.open (this.faceBookUpdataUrl.replace("$1",this.HREF).replace("$2",this.PageTitle),'newfbwindow','height=300,width=560,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
},
//sharer到twitter
sharerToTwitter : function(RwStr){
window.open (this.twitterUpdataUrl.replace("$1",this.HREF)+RwStr,'newttwindow','height=300,width=560,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
}
}
})();