1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
4 <title>MuvMuv - Muvie Review
</title>
6 <link rel=
"stylesheet" type=
"text/css" href=
"static/style.css" />
8 <script src=
"static/common.js" type=
"text/javascript"></script>
9 <script src=
"http://code.google.com/js/jquery.js" type=
"text/javascript">
11 <script src=
"static/json2.js" type=
"text/javascript"></script>
16 var muvmuv
= muvmuv
|| {};
18 muvmuv
.URL_ARGS
= muvmuv
.getUrlArgs();
19 muvmuv
.USER
= '{{user}}' || 'None';
21 var WRITE_REVIEW_LABEL
= 'Write Review';
22 var SUBMIT_REVIEW_LABEL
= 'Submit';
24 $(document
).ready(function() {
26 muvmuv
.initReviewBox();
28 muvmuv
.fetchMovieData();
31 muvmuv
.initReviewBox = function() {
32 $('#reviewbox').hide();
34 $('#cancel').click(function() {
35 $('#reviewbox').hide();
36 $('#writereview').show();
39 $('#submitreview').click(function() {
40 muvmuv
.submitReview();
43 $('#writereview').click(function() {
44 if (muvmuv
.USER
== 'None') {
45 top
.location
.href
= $('#login').attr('href');
47 $('#writereview').hide();
48 $('#reviewbox').show();
50 document
.body
.scrollTop
= document
.body
.scrollHeight
;
51 $('#reviewcomment').get(0).focus();
56 muvmuv
.setReviews = function(reviews
) {
60 for (var i
= 0; i
<reviews
.length
; i
++) {
61 var review
= reviews
[i
];
63 var author
= review
.author
;
64 var comment
= review
.comment
;
66 var date
= new Date(Date
.parse(review
.date
));
68 html
.push('<b>Name: </b>');
71 html
.push('<b>Date: </b>');
74 html
.push('<b>Review: </b>');
81 $('#comments').html(html
.join(''));
82 $('#writereview').show();
85 muvmuv
.fetchMovieData = function() {
87 var title
= muvmuv
.getTitle();
89 var callback = function(data
) {
90 var json
= JSON
.parse(data
);
91 var movie
= json
.movie
;
92 var rating_average
= movie
.rating_average
;
93 var rating_count
= movie
.rating_count
;
95 var summary
= movie
.summary
;
96 var release_date
= new Date(Date
.parse(movie
.release_date
));
98 if (!$('#title').html()) {
99 $('#title').html(movie
.title
);
100 $('#releasedate').html(
101 ['<b>Released date: </b>', release_date
.toString()].join(''));
102 $('#pic').attr({src
: pic
});
103 $('#summary').html(['<b>Sypnosis: </b>', summary
].join(''));
105 muvmuv
.findVideo(decodeURI(title
), summary
);
107 muvmuv
.setReviews(json
.reviews
);
110 $.ajax({type
: 'get', url
: 'reviews', data
: 'title=' + title
,
114 muvmuv
.MovieReview = function() {
117 this.reviewComment
= null;
120 muvmuv
.MovieReview
.prototype.toJson = function() {
121 return JSON
.stringify(this);
124 muvmuv
.submitReview = function() {
126 var review
= new muvmuv
.MovieReview();
127 review
.title
= decodeURI(muvmuv
.getTitle());
128 review
.reviewComment
= $('#reviewcomment').val();
130 if (!$.trim(review
.reviewComment
)) {
131 alert('Review cannot be empty');
135 var jsonString
= review
.toJson();
137 var onSuccess = function() {
138 $('#reviewbox').hide();
139 $('#reviewcomment').val('');
140 muvmuv
.fetchMovieData();
143 $.ajax({type
: 'post', url
: 'submitreview',
144 data
: 'json=' + jsonString
, success
: onSuccess
});
147 muvmuv
.findVideo = function(title
, summary
) {
151 var re
= /\([a-zA-Z0-9'\- ]+(, [a-zA-Z0-9'\- ]+)*\)/g
153 var matches
= summary
.match(re
);
159 for (var i
= 0; i
< matches
.length
; i
++) {
160 var match
= matches
[i
];
162 var hasComma
= match
.indexOf(',') >= 0 | false;
165 var matches_
= match
.split(',');
167 for (var j
= 0; j
< matches_
.length
; j
++) {
168 var match_
= matches_
[j
];
170 match_
= match_
.replace(/[()]/g, '');
172 keywords
.push(match_
);
175 match
= match
.replace(/[()]/g, '');
177 keywords
.push(match
);
181 matches
= title
.split(' ');
183 for (var i
= 0; i
< matches
.length
; i
++) {
184 var match
= matches
[i
];
186 match
= match
.replace(/[^a-zA-Z]/g, '');
188 keywords
.push(match
);
192 keywords
= keywords
.map(function(element
) {
193 element
= element
.replace(/ /g
, '+');
194 return element
.toLowerCase();
197 for (var i
= 0; i
< keywords
.length
; i
++) {
198 keywords
[i
] = keywords
[i
].replace(/ /g
, '+');
202 var callbackName
= 'muvmuv.processYouTubeFeed';
205 ['http://gdata.youtube.com/feeds/api/videos?callback=',
206 callbackName
, '&alt=json-in-script&vq=',
207 keywords
.join('+')].join('');
209 var script
= document
.createElement('script');
210 script
.src
= youtubeFeed
;
212 document
.body
.appendChild(script
);
215 muvmuv
.processYouTubeFeed = function(feed
) {
217 var data
= eval(feed
);
219 if (data
.feed
.openSearch
$totalResults
.$t
> 0) {
221 var url
= data
.feed
.entry
[0].link
[0].href
;
222 var id
= url
.replace('http://www.youtube.com/watch?v=', '');
223 var videoUrl
= 'http://www.youtube.com/v/' + id
;
227 html
.push('<object width="250" height="200">');
228 html
.push('<param name="movie" value="');
230 html
.push('"></param>');
231 html
.push('<param name="wmode" value="transparent"></param>');
232 html
.push('<embed src="');
234 html
.push('" type="application/x-shockwave-flash"');
235 html
.push(' wmode="transparent" width="250" height="200">');
236 html
.push('</embed></object>');
238 $('#video').html(html
.join(''));
245 <div align=
"center" id=
"main">
246 {% include
"header.html" %}
248 <div id=
"reviewsection">
251 <p align=
"center" id=
"releasedate"></p>
254 <td align=
"center" style=
"width: 250px; height: 200px; background: black;">
255 <img id=
"pic" src=
"">
264 <p id=
"summary" align=
"left">
267 <p id=
"comments" align=
"left">
271 <input id=
"writereview" type=
"button" value=
"Write Review">
273 <textarea style=
"height: 150px; width: 500px;"
274 id=
"reviewcomment"></textarea>
276 <input id=
"submitreview" type=
"button" value=
"Submit"/>
277 <input id=
"cancel" type=
"button" value=
"Cancel"/>