|
28
|
1 |
$(function(){ |
|
|
2 |
|
|
29
|
3 |
function resizeImg(parentId){ |
|
|
4 |
$(parentId+" img").each(function() { |
|
|
5 |
var img = $(this), |
|
|
6 |
div = $(this).parent(); |
|
|
7 |
img.load(function() { |
|
|
8 |
var iw = img.width(), |
|
|
9 |
ih = img.height(), |
|
|
10 |
dw = div.width(), |
|
|
11 |
dh = div.height(), |
|
|
12 |
scale = Math.max(dw/iw, dh/ih), |
|
|
13 |
niw = iw * scale, |
|
|
14 |
nih = ih * scale; |
|
|
15 |
img.css({ |
|
|
16 |
width: niw, |
|
|
17 |
height: nih, |
|
|
18 |
"margin-left": (dw - niw) / 2, |
|
|
19 |
"margin-top": (dh - nih) / 3 |
|
|
20 |
}); |
|
|
21 |
}); |
|
|
22 |
}); |
|
|
23 |
} |
|
|
24 |
|
|
28
|
25 |
var CONFIG = { |
|
|
26 |
wChart : 100, |
|
|
27 |
now : new Date(), |
|
|
28 |
dayLimit : 1, |
|
|
29 |
timelineMin : 5, |
|
|
30 |
bar : [] |
|
|
31 |
}; |
|
|
32 |
|
|
|
33 |
var bcSettings = { |
|
|
34 |
width : 960, |
|
|
35 |
height : 400, |
|
|
36 |
chart : { |
|
29
|
37 |
spacer : 5 |
|
28
|
38 |
}, |
|
|
39 |
data : { |
|
|
40 |
model :[], |
|
|
41 |
strata:[], |
|
|
42 |
stream : { provider : 'direct' } |
|
|
43 |
}, |
|
|
44 |
sedimentation:{ |
|
|
45 |
aggregation:{height:100} |
|
|
46 |
}, |
|
|
47 |
options:{layout:false} |
|
|
48 |
}; |
|
|
49 |
|
|
|
50 |
|
|
|
51 |
var currentDay = new Date().getDate(); |
|
|
52 |
var _reviewMovies = []; |
|
|
53 |
var nbMovies; |
|
|
54 |
var indiceMovie = 0; |
|
|
55 |
var indiceBar = 0; |
|
|
56 |
var barChart; |
|
|
57 |
|
|
|
58 |
var urlBestMovies = 'http://api.allocine.fr/rest/v3/movielist?partner='+ partnerCode +'&format=json&filter=top:week&count=15'; |
|
|
59 |
$.getJSON(urlBestMovies, function(data) { |
|
|
60 |
|
|
|
61 |
var movies = data.feed.movie; |
|
|
62 |
nbMovies = movies.length; |
|
29
|
63 |
bcSettings.width = nbMovies * CONFIG.wChart + 10 * nbMovies; |
|
28
|
64 |
$('.posters').css('width', bcSettings.width); |
|
|
65 |
//var wItem = bcSettings.width / nbMovies; |
|
|
66 |
|
|
|
67 |
_.each(movies, function(d){ |
|
|
68 |
|
|
|
69 |
var dataMovie = { |
|
|
70 |
title : d.originalTitle, |
|
|
71 |
code : d.code, |
|
|
72 |
posterUrl : d.poster.href, |
|
|
73 |
userRating : d.statistics.userRating, |
|
|
74 |
userReviewCount : d.statistics.userReviewCount |
|
|
75 |
}; |
|
|
76 |
|
|
|
77 |
var poster = |
|
|
78 |
'<li>'+ |
|
|
79 |
'<img src="'+ dataMovie.posterUrl +'" alt="'+ dataMovie.title +'" />'+ |
|
|
80 |
'</li>'; |
|
|
81 |
$('.posters').append(poster); |
|
|
82 |
|
|
|
83 |
//getReviewsByFilm(dataMovie.code); |
|
|
84 |
|
|
|
85 |
CONFIG.bar.push(dataMovie.code); |
|
|
86 |
|
|
|
87 |
bcSettings.data.model.push({}); |
|
|
88 |
|
|
|
89 |
var userReviewCount = dataMovie.userReviewCount; |
|
|
90 |
if(_.isUndefined(userReviewCount))userReviewCount = 0; |
|
|
91 |
var initValue = userReviewCount; |
|
|
92 |
|
|
|
93 |
bcSettings.data.strata.push([{initValue: initValue }]); |
|
|
94 |
/* |
|
|
95 |
var item = $('<li>').attr('data-poster', dataMovie.posterUrl).attr('id', 'movie-'+dataMovie.code ).attr('id', 'movie-'+dataMovie.code ).css('width', wItem); |
|
|
96 |
var nbReview = $('<span>').addClass('nbReview').text(userReviewCount); |
|
|
97 |
item.append(nbReview); |
|
|
98 |
item.appendTo('.info-movies'); |
|
|
99 |
*/ |
|
|
100 |
}); |
|
|
101 |
|
|
29
|
102 |
resizeImg('.posters'); |
|
28
|
103 |
barChart = $("#data-viz").vs(bcSettings).data('visualSedimentation'); |
|
|
104 |
|
|
|
105 |
}); |
|
|
106 |
/* |
|
|
107 |
var now = new Date(); |
|
|
108 |
|
|
|
109 |
function reviewAllowSince(dateReview){ |
|
|
110 |
var diffNowReview = CONFIG.now.getTime() - new Date(dateReview).getTime(); |
|
|
111 |
var limit = (CONFIG.dayLimit * 24) * 60 * 60 * 1000; |
|
|
112 |
if(diffNowReview<=limit){ |
|
|
113 |
var startDate = limit - diffNowReview; |
|
|
114 |
return startDate; |
|
|
115 |
}else{ |
|
|
116 |
return false; |
|
|
117 |
} |
|
|
118 |
} |
|
|
119 |
|
|
|
120 |
function generateTimerByMin(time){ |
|
|
121 |
var timeLimit = (CONFIG.timelineMin*60)*1000; |
|
|
122 |
return (time * timeLimit) / ((CONFIG.dayLimit*24)*60*60*1000) |
|
|
123 |
} |
|
|
124 |
|
|
|
125 |
function showHorloge(){ |
|
|
126 |
var timestampDateLimit = CONFIG.now.getTime() - ((CONFIG.dayLimit*24)*60*60*1000); |
|
|
127 |
var dateLimit = new Date(timestampDateLimit); |
|
|
128 |
var diff = CONFIG.now.getTime() - timestampDateLimit; |
|
|
129 |
|
|
|
130 |
var oneHour = (CONFIG.timelineMin * 60 * 1000) / (CONFIG.dayLimit*24); |
|
|
131 |
var oneMinute = oneHour / 60; |
|
|
132 |
|
|
|
133 |
displayHorloge(timestampDateLimit); |
|
|
134 |
|
|
|
135 |
setInterval(function(){ |
|
|
136 |
if(timestampDateLimit>=CONFIG.now.getTime()) return; |
|
|
137 |
timestampDateLimit = timestampDateLimit + (60 * 1000); |
|
|
138 |
displayHorloge(timestampDateLimit); |
|
|
139 |
},oneMinute); |
|
|
140 |
|
|
|
141 |
} |
|
|
142 |
|
|
|
143 |
function displayHorloge(timestampDateLimit){ |
|
|
144 |
timestampDateLimit = timestampDateLimit+(60*1000); |
|
|
145 |
var dateLimit = new Date(timestampDateLimit); |
|
|
146 |
var horlogeHour = dateLimit.getHours(); |
|
|
147 |
var horlogeMin = dateLimit.getMinutes(); |
|
|
148 |
if(horlogeMin.toString().length==1)horlogeMin = '0'+horlogeMin; |
|
|
149 |
var horlogeDay = dateLimit.getDate(); |
|
|
150 |
var horlogeMonth = dateLimit.getMonth()+1; |
|
|
151 |
$('.horloge').html(horlogeDay+' / '+horlogeMonth+'<br/>'+horlogeHour+'h'+horlogeMin); |
|
|
152 |
} |
|
|
153 |
|
|
|
154 |
function getReviewsByFilm(codeFilm){ |
|
|
155 |
|
|
|
156 |
var _movie = { |
|
|
157 |
movieCode : codeFilm |
|
|
158 |
}; |
|
|
159 |
|
|
|
160 |
var reviewCount = 100; |
|
|
161 |
var urlCommentaireMovie = 'http://api.allocine.fr/rest/v3/reviewlist?partner='+ partnerCode +'&format=json&filter=public&count='+reviewCount+'&subject=movie:'+codeFilm; |
|
|
162 |
$.getJSON(urlCommentaireMovie, function(data) { |
|
|
163 |
|
|
|
164 |
var nbFilmSince = 0; |
|
|
165 |
//console.log(data) |
|
|
166 |
var totalResults = data.feed.totalResults; |
|
|
167 |
if(totalResults > 0) { |
|
|
168 |
var _reviews = new Array(); |
|
|
169 |
var reviews = data.feed.review; |
|
|
170 |
_.each(reviews, function(d){ |
|
|
171 |
if(d.totalResults == 0) return; |
|
|
172 |
|
|
|
173 |
var dataReview = { |
|
|
174 |
commentaire : d.body, |
|
|
175 |
date : d.creationDate,//"2013-03-10T |
|
|
176 |
rating : d.rating, |
|
|
177 |
author : d.writer.name |
|
|
178 |
}; |
|
|
179 |
|
|
|
180 |
var startDate = reviewAllowSince(d.creationDate); |
|
|
181 |
|
|
|
182 |
if(startDate){ |
|
|
183 |
nbFilmSince++ |
|
|
184 |
dataReview.startDate = startDate; |
|
|
185 |
_reviews.push(dataReview); |
|
|
186 |
} |
|
|
187 |
}); |
|
|
188 |
|
|
|
189 |
var totalReviews = $('li#movie-'+codeFilm+' span.nbReview').text(); |
|
|
190 |
$('li#movie-'+codeFilm+' span.nbReview').text(totalReviews-nbFilmSince) |
|
|
191 |
|
|
|
192 |
_movie.reviews = _reviews; |
|
|
193 |
_reviewMovies.push(_movie); |
|
|
194 |
} |
|
|
195 |
|
|
|
196 |
indiceMovie++; |
|
|
197 |
//console.log(indiceMovie) |
|
|
198 |
if(indiceMovie == nbMovies){ |
|
|
199 |
showHorloge(); |
|
|
200 |
displayReviews(); |
|
|
201 |
} |
|
|
202 |
|
|
|
203 |
});//getJson |
|
|
204 |
}//getReviewsByFilm |
|
|
205 |
|
|
|
206 |
function displayReviews(){ |
|
|
207 |
_.each(_reviewMovies, function(a){ |
|
|
208 |
var movieCode = a.movieCode; |
|
|
209 |
var reviews = a.reviews; |
|
|
210 |
|
|
|
211 |
var barCharCat; |
|
|
212 |
$.each(CONFIG.bar, function(k,v){ |
|
|
213 |
if(movieCode == v)barCharCat = k; |
|
|
214 |
}); |
|
|
215 |
|
|
|
216 |
_.each(reviews, function(b){ |
|
|
217 |
|
|
|
218 |
b.movieCode = movieCode; |
|
|
219 |
var startDate = b.startDate; |
|
|
220 |
|
|
|
221 |
var timer = generateTimerByMin(startDate); |
|
|
222 |
setTimeout(function(){ |
|
|
223 |
addToken(barCharCat, b) |
|
|
224 |
},timer); |
|
|
225 |
}); |
|
|
226 |
}); |
|
|
227 |
}//displayReviews |
|
|
228 |
|
|
|
229 |
function addToken(barCharCat, data){ |
|
|
230 |
var commentaire = data.commentaire; |
|
|
231 |
var date = data.date; |
|
|
232 |
var rating = data.rating; |
|
|
233 |
var author = data.author; |
|
|
234 |
var movieCode = data.movieCode; |
|
|
235 |
|
|
|
236 |
var nbReview = $('li#movie-'+movieCode+' span.nbReview').text(); |
|
|
237 |
var newNbReview = parseInt(nbReview)+1; |
|
|
238 |
$('li#movie-'+movieCode+' span.nbReview').text(newNbReview); |
|
|
239 |
//console.log(data.author) |
|
|
240 |
barChart.addToken({ |
|
|
241 |
commentaire : commentaire, |
|
|
242 |
movieCode : movieCode, |
|
|
243 |
date : date, |
|
|
244 |
rating : rating, |
|
|
245 |
author : author, |
|
|
246 |
category:barCharCat, |
|
|
247 |
size:3, |
|
|
248 |
callback:{ |
|
|
249 |
mouseover:function(token){ |
|
|
250 |
var commentaire = token.attr('commentaire'); |
|
|
251 |
var author = token.attr('author'); |
|
|
252 |
var date = token.attr('date'); |
|
|
253 |
var movieCode = token.attr('movieCode'); |
|
|
254 |
$('.review .author').text(author+', '+date); |
|
|
255 |
$('.review .comment').text(commentaire); |
|
|
256 |
var poster = $('li#movie-'+movieCode).attr('data-poster'); |
|
|
257 |
$('.review img').attr('src', poster); |
|
|
258 |
} |
|
|
259 |
} |
|
|
260 |
}); |
|
|
261 |
} |
|
|
262 |
*/ |
|
|
263 |
});//load |