-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
188 lines (164 loc) · 5.82 KB
/
index.html
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rushikesh: XKCD viewer App</title>
<link rel="stylesheet" href="themes/xkcd.min.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="themes/jquery.mobile.structure-1.4.2.min.css" />
<script src="themes/jquery-1.10.2.min.js"></script>
<script src="themes/jquery.mobile-1.4.2.min.js"></script>
<script src="themes/img-touch-canvas.js"></script>
<style type="text/css">
#content{
margin: 0 auto;
text-align: center;
}
#descComic{
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
img, object{
/* max-height:90%;
max-width:90%; */
}
.cstmPopup{
overflow-y:scroll;
}
</style>
<script type="text/javascript">
var gesturableImg,html,title,prev,next,comicTitle,deviceWidth=0,deviceHeight=0,imgWidth=0,imgHeight=0;
$(document).ready(function() {
//putFooterToBottom();
calDeviceSize();
loadXkcdData("");
$('#descComic').on('click',function(){
var tmp = "<center><b>"+comicTitle +":</b></center><br/>" + title ;
$('#comicSpan').html(tmp);
});
$('#prevComic').on('click',function(){
loadXkcdData (prev);
});
$('#nextComic').on('click',function(){
loadXkcdData (next);
});
$(document).ajaxStart(function() {
$.mobile.loading('show');
});
$(document).ajaxStop(function() {
$.mobile.loading('hide');
});
});
function loadXkcdData (comicId) {
var w,h;
var url = "https://www.xkcd.com"+comicId;
var jqxhr = $.get( url, function( data ) {
html = $(data);
var tmp = html.find('#comic').html();
var imgSrc = $(tmp).attr('src');
$("<img/>").attr("src", imgSrc).load(function(){
imgWidth=this.width;
imgHeight=this.height;
/*
if(imgWidth>deviceWidth || imgHeight>deviceHeight ){
$('mycanvas').css('width',deviceWidth).css('height',deviceHeight);
console.log("deviceWidth:"+deviceWidth+" deviceHeight:"+deviceHeight);
}else{
$('mycanvas').css('width',imgWidth).css('height',imgHeight);
console.log("imgWidth:"+imgWidth+" imgHeight:"+imgHeight);
}*/
if(imgWidth>deviceWidth){
sx = imgWidth/deviceWidth
sy = imgHeight/deviceHeight
if (sx*imgWidth > deviceHeight){
s = sy;
}
else{
s = sx;
}
new_width = imgWidth*s;
new_height = imgHeight*s;
w = new_width;
h = new_height;
//$('#mycanvas').css('width',new_width+"px").css('height',new_height+"px");
}else{
//$('#mycanvas').css('width',imgWidth+"px").css('height',imgHeight+"px");
w = imgWidth;
h = imgHeight;
}
$('#mycanvas').width= deviceWidth;
$('#mycanvas').height = deviceHeight;
gesturableImg = new ImgTouchCanvas({
canvas: document.getElementById('mycanvas'),
path: ""+imgSrc,
imgWidth: w,
imgHeight: h,
canvasWidth: deviceWidth,
canvasHeight: deviceHeight
});
title = $(tmp).attr('title');
prev = html.find('a[rel=prev]').attr('href');
next = html.find('a[rel=next]').attr('href');
comicTitle = $(tmp).attr('alt');
$('#titleComic').html("XKCD:"+comicTitle);
});
}).fail(function() {
alert( "Cannot Connect: Check Your Network/Wi-fi Connection" );
});
}
function calImgMeta(url){
$("<img/>").attr("src", url).load(function(){
imgWidth=this.width;
imgHeight=this.height;
console.log(url);
console.log(imgWidth+":"+imgHeight);
});
}
function calDeviceSize() {
deviceWidth = $('body').width();
deviceHeight = $('body').height();
}
function putFooterToBottom () {
var docHeight = $(window).height();
var footerHeight = $('#footer').height();
var footerTop = $('#footer').position().top + footerHeight;
if (footerTop < docHeight) {
$('#footer').css('margin-top', (docHeight - footerTop) + 'px');
}
}
</script>
</head>
<body>
<div data-role="page" data-theme="a">
<div data-role="header" data-position="fixed" data-fullscreen="false">
<h1 id="titleComic">XKCD</h1>
<a href="#popupBasic" data-position-to="window" data-transition="fade" data-rel="popup" id="infoicon" data-icon="info" class="ui-btn-right" data-iconpos="notext">Info</a>
</div>
<div id="content" data-role="content" data-theme="a">
<canvas id="mycanvas"></canvas>
</div>
<div id="footer" data-role="footer" data-position="fixed" data-fullscreen="true" data-theme="b">
<div data-role="navbar" style="width:98%;float:left">
<ul>
<li><a href="#" id="prevComic">Prev</a></li>
<li><a href="#popupComicInfo" data-position-to="window" data-transition="fade" data-rel="popup" id="descComic">Comic Info</a></li>
<li><a href="#" id="nextComic">Next</a></li>
</ul>
</div>
<!-- <a href="#" id="descComic" data-icon="info" class="ui-btn-center" data-iconpos="notext">Info</a>
<a href="#" id="prevComic" data-icon="arrow-l" class="ui-btn-left" data-iconpos="notext">Prev</a>
<a href="#" id="nextComic" data-icon="arrow-r" class="ui-btn-right" data-iconpos="notext">Next</a> -->
</div>
<div data-role="popup" id="popupBasic" data-overlay-theme="a" class="ui-content cstmPopup" >
<a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
<p>XKCD Comic Viewer.<p>
<p>Created By: <a href="http://www.rushis.com">Rushi</a><p>
</div>
<div data-role="popup" id="popupComicInfo" data-overlay-theme="a" class="ui-content cstmPopup" >
<a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
<span id="comicSpan"></span>
</div>
</div>
</body>
</html>