-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchecktrend.js
More file actions
128 lines (109 loc) · 5.12 KB
/
checktrend.js
File metadata and controls
128 lines (109 loc) · 5.12 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Google Analytics設定
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-19734506-5']);
// 初期設定
$(document).bind('mobileinit', function(){
// 日本語化
$.mobile.loadingMessage = '読込み中';
$.mobile.pageLoadErrorMessage = '読込みに失敗しました';
$.mobile.page.prototype.options.backBtnText = '戻る';
$.mobile.dialog.prototype.options.closeBtnText = '閉じる';
$.mobile.selectmenu.prototype.options.closeText= '閉じる';
// Google Analytics設定 ページトラッキング
$(':jqmData(role="page")').live('pageshow', function (event, ui) {
_gaq.push(['_trackPageview', $.mobile.activePage.jqmData('url')]);
});
});
//fastckick.js
$(function() {
FastClick.attach(document.body);
});
// 個別設定
$(document).ready(function(){
// Google Analytics読込み
var ga = document.createElement('script'); ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
// 最初に見せる画面
getData('japan1');
//default
$("#detailBrowser").attr('src', '');
});
function getData(dataCode){
var dataObj = {
testobj: {url: 'http--' , id: '#hogehoge' , msg: 'はーい'} ,
//
japan1: {url: 'http://pipes.yahoo.com/pipes/pipe.run?_id=b4c7153df25b0aa5e1b5034ea03fe54e&_render=json&_callback=?' , id: '#japanTrendContent' , msg: 'Google急上昇ワード'} ,
japan2: {url: 'http://pipes.yahoo.com/pipes/pipe.run?_id=cd404ac46440703b203b1f4f129e761e&_render=json&_callback=?' , id: '#japanTrendContent' , msg: 'Yahoo!急上昇ワード'} ,
japan3: {url: 'http://pipes.yahoo.com/pipes/pipe.run?_id=81ec292d8c0223b7b675452127028e41&_render=json&_callback=?' , id: '#japanTrendContent' , msg: 'MSN週間急上昇ランキング'} ,
japan4: {url: 'http://pipes.yahoo.com/pipes/pipe.run?_id=e95077516313fad645233d42e25efae4&_render=json&_callback=?' , id: '#japanTrendContent' , msg: 'twitterドレンド'} ,
japan5: {url: 'http://pipes.yahoo.com/pipes/pipe.run?_id=f3e422424cafd595628fc32645053652&_render=json&_callback=?' , id: '#japanTrendContent' , msg: 'Amazonヒット書籍'} ,
};
try{
jsonUrl = dataObj[dataCode]['url'];
idName = dataObj[dataCode]['id'];
idTitle = dataObj[dataCode]['msg'];
getJsonFromXML(jsonUrl , idName , idTitle);
}catch(e){
//エラー
}
//データ取得準備
$(idName+'Title').text(idTitle);
$(idName).empty(); //前の表示内容を消去
$(idName).html("<img src='./images/load.gif'>");
//rssをjsonデータに変換して取得
console.log("URL "+ jsonUrl);
$.getJSON(jsonUrl, function (json) { //ロードが終わると開始される
jsonToHtml(idName , idTitle , json);
}).error(function (e) {
$(idName).empty();
$(idName).text("データ読み込み中にエラーが発生しました。しばらく時間を置いてからアクセスをお願いします。");
});
}
//jsonをhtmlに反映する
function jsonToHtml(idName , idTitle , json){
if (typeof json === "undefined") {
console.log("データ取得に失敗した模様");
$(idName).empty();
$(idName).text("データにエラーが発生しました。しばらく時間を置いてからアクセスをお願いします。");
}
//表示するテキストを取得
try{
var strRSS = "";
for(var i in json.value.items){
var linkStr = json.value.items[i].link;
var titleStr = escapeHTML(json.value.items[i].title);
if(json.value.items[i].description){
strRSS = strRSS + "<li><a href='"+ linkStr +"' rel='external'>" + titleStr + "<br><p>"+ escapeHTML(json.value.items[i].description) +"</p></a></li>";
//strRSS = strRSS + "<li><a href='"+ linkStr +"' rel='external'><h3>" + titleStr + "</h3><p>"+ escapeHTML(json.value.items[i].description) +"</p></a></li>";
//strRSS = strRSS + "<li><a href='#browser' onclick=\"$('#detailBrowser').attr('src', '" + linkStr +"');\"><h3>" + titleStr + "</h3><p>"+ escapeHTML(json.value.items[i].description) +"</p></a></li>";
}else{
strRSS = strRSS + "<li><a href='"+ linkStr +"' rel='external'>" + titleStr + "</a></li>";
//strRSS = strRSS + "<li><a href='"+ linkStr +"' rel='external'><h3>" + titleStr + "</h3><p>" + "</a></li>";
//strRSS = strRSS + "<li><a href='#browser' onclick=\"$('#detailBrowser').attr('src', '" + linkStr +"');\"><h3>" + titleStr + "</h3></a></li>";
}
}
}catch(e){
//console.log(e);
$(idName).empty();
$(idName).text("データにエラーが発生しました。しばらく時間を置いてからアクセスをお願いします。");
}
//画面を作る
$(idName).empty();
$( "<ol>", { //メインのデータを表示
"role": "listview",
})
.append(strRSS)
.appendTo($(idName))
.listview();
}
//textを利用してエスケープ(対策として問題無いのか?)
//http://yossie09.blogspot.com/2010/11/jquery-html.html
function escapeHTML(val) {
return $('<div>').text(val).html();
};
function unescapeHTML(val) {
return $('<div>').html(val).text();
};