forked from lenincasco/EjPhoneGap-Mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mgram-paso16.html
238 lines (206 loc) · 7.52 KB
/
mgram-paso16.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script type="text/javascript" src="ui/jquery.ui.map.js"></script>
<script type="text/javascript" src="ui/jquery.ui.map.services.js"></script>
<script type="text/javascript" src="ui/jquery.ui.map.extensions.js"></script><script type="text/javascript" src="cordova-2.2.0.js"></script>
<script type="text/javascript">
var _photo_uri;
var imgur_client_id = "1841367133e3c0151755f5632959b990";
var instagram_client_id = "fc8041d4af1544a2939c3f5a9a1ef8cf";
function getPhotos() {
var map_visible = $("#map").is(':visible');
var list_visible = $("#list").is(':visible');
if (map_visible) {
tag = $("#map .tag").val();
} else if (list_visible) {
tag = $("#list .tag").val();
}
if (tag == "") {
tag = "instafood";
}
tag = tag.replace(/(#| )/g,"");
$(".search-button").addClass('ui-disabled');
$(".result-count").html("cargando...");
if (map_visible) {
$('#map_canvas').gmap('clear', 'markers');
} else if (list_visible) {
$("#element_list").empty();
}
var url = "https://api.instagram.com/v1/tags/" + tag + "/media/recent?client_id=" + instagram_client_id + "&callback=?";
$.getJSON(url, function(data){
var data_elements = data["data"];
var showing = 0;
$.each(data_elements, function(index, current_element) {
var thumbnail = current_element["images"]["thumbnail"]["url"];
var caption = "ver imagen";
if (current_element["caption"] != null) {
caption = current_element["caption"]["text"];
}
var link = current_element["link"];
if (map_visible && current_element["location"] != null) {
showing++;
var lat = current_element["location"]["latitude"];
var lng = current_element["location"]["longitude"];
var position = new google.maps.LatLng(lat,lng);
var info_window = $('<span>').append(
$('<img>').attr('src',thumbnail)).append(
$('<br>')).append(
$('<a>').attr('href',link).text(caption)).html();
$('#map_canvas').gmap('addMarker', {'position': position}).click(function(){
$('#map_canvas').gmap('openInfoWindow', {'content': info_window}, this);
$('#map_canvas').gmap('getMap').panTo(position);
});
} else if (list_visible) {
showing++;
$("#element_list").append(
$('<li>').append(
$('<a>').attr('href',link).append(
$('<img>').attr('src',thumbnail)).append(caption))
);
}
});
if (list_visible) {
$("#element_list").listview("refresh");
}
$(".search-button").removeClass('ui-disabled');
$(".result-count").html("Mostrando " + showing + " resultados para #" + tag);
});
}
function takePhoto() {
var opts = {
targetWidth: 300,
targetHeight: 300,
destinationType : Camera.DestinationType.FILE_URI
}
navigator.camera.getPicture(function(imageURI) {
_photo_uri = imageURI;
$("#pic").attr("src",_photo_uri);
},
function(error){
$("#picinfo").html("error " + error.code);
}, opts)
}
function uploadPhoto() {
var opts = new FileUploadOptions();
opts.fileKey = "image";
opts.fileName = _photo_uri.substr(_photo_uri.lastIndexOf('/')+1);
opts.mimeType = "image/jpeg";
opts.params = {"type":"file","key":imgur_client_id};
var ft = new FileTransfer();
ft.upload(_photo_uri, "http://api.imgur.com/3/upload.json",
function(resp) {
var link = jQuery.parseJSON(resp.response).data.link;
$("#picinfo").html($("<a>").attr("href",link).text("imagen publicada en " + link));
},
function(error) {
$("#picinfo").html("no fue posible publicar " + error.code);
}, opts);
}
function locationSuccess(position){
var lat = position.coords.latitude;
var lng = position.coords.longitude;
$('#map_canvas').gmap({ 'center': new google.maps.LatLng(lat, lng), 'zoom': 5});
getPhotos();
}
function locationError(error) {
$('#map_canvas').gmap({'zoom': 2});
getPhotos();
}
$("#map").live("pagecreate", function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
locationSuccess,locationError,
{enableHighAccuracy: true });
}
});
$("#list").live("pageshow", function() {
getPhotos();
});
$(document).on('click', '[data-role="navbar"] a', function () {
$.mobile.changePage($(this).attr("data-href"), {
transition: "none",
changeHash: false
});
return false;
});
</script>
</head>
<body>
<div id="map" data-role="page">
<div data-role="header">
<h1>Mejorando.la-gram</h1>
</div>
<div data-role="navbar">
<ul>
<li><a href="#" data-href="#map" class="ui-btn-active">Mapa</a></li>
<li><a href="#" data-href="#list">Listado</a></li>
<li><a href="#" data-href="#upload">Mis fotos</a></li>
</ul>
</div>
<div data-role="content">
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<input type="text" class="tag" name="tag"/>
</div>
<div class="ui-block-b">
<a href="javascript:getPhotos();" data-role="button"
data-icon="check" data-inline="true" class="search-button">Buscar</a>
</div>
</fieldset>
<div class="result-count"></div>
<br/>
<div class="ui-bar-c ui-corner-all ui-shadow" style="padding:1em;">
<div id="map_canvas" style="height:350px"></div>
</div>
</div>
</div>
<div id="list" data-role="page">
<div data-role="header">
<h1>Mejorando.la-gram</h1>
</div>
<div data-role="navbar">
<ul>
<li><a href="#" data-href="#map">Mapa</a></li>
<li><a href="#" data-href="#list" class="ui-btn-active">Listado</a></li>
<li><a href="#" data-href="#upload">Mis fotos</a></li>
</ul>
</div>
<div data-role="content">
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<input type="text" class="tag" name="tag"/>
</div>
<div class="ui-block-b">
<a href="javascript:getPhotos();" data-role="button"
data-icon="check" data-inline="true" class="search-button">Buscar</a>
</div>
</fieldset>
<div class="result-count"></div>
<br/>
<ul data-role="listview" id="element_list"></ul>
</div>
</div>
<div id="upload" data-role="page">
<div data-role="header">
<h1>Mejorando.la-gram</h1>
</div>
<div data-role="navbar">
<ul>
<li><a href="#" data-href="#map">Mapa</a></li>
<li><a href="#" data-href="#list">Listado</a></li>
<li><a href="#" data-href="#upload" class="ui-btn-active">Mis fotos</a></li>
</ul>
</div>
<a href="#" data-role="button" onclick="takePhoto();">Tomar una foto</a>
<a href="#" data-role="button" onclick="uploadPhoto();">Publicarla</a>
<div id="picinfo"></div>
<img id="pic" />
</div>
</body>
</html>