diff --git a/script/ugc.js b/script/ugc.js index 5a3045e..144cc17 100644 --- a/script/ugc.js +++ b/script/ugc.js @@ -8,7 +8,7 @@ function Film(oSettings) this._ban = {status:false, reason:''}; this._timetable = {}; this.$Main = $('main'); - + this.ban = function(bStatus, sReason) { sReason = sReason || ''; @@ -22,18 +22,18 @@ function Film(oSettings) } else this.error('Setting ban status with no reason'); } - + this.id = function(iFilmId) { return this.attr('id', iFilmId); } - + this.name = function(sName) { sName = sName?(sName + '').toLowerCase().replace(/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g, function($1) {return $1.toUpperCase();}):''; return this.attr('name', sName); }; - + this.safe = function(sName) { var sSafeName = sName?removeDiacritics(sName):''; @@ -52,7 +52,7 @@ function Film(oSettings) if(sPoster) sPoster = this.getPosterUrl(sPoster, 'large', bForce); return this.attr('poster_bg', sPoster); }; - + this.getPosterUrl = function(sUrl, sSize, bForce) { bForce = bForce || false; @@ -65,18 +65,18 @@ function Film(oSettings) { return this.attr('edito', sEdito); }; - + this.trailer = function(sTrailer) { - sTrailer = sTrailer?self.consts.ugc_url+sTrailer:''; + sTrailer = sTrailer?self.consts.ugc_url+sTrailer:''; return this.attr('trailer', sTrailer); }; - + this.director = function(sDirector) { return this.attr('director', sDirector); }; - + this.attr = function(sName, sValue) { if(!sValue) return this._attr[sName]; @@ -106,12 +106,12 @@ function Film(oSettings) else if(sEdito=='Nouveau') iRank += 10000000; //New releases else if(sEdito.slice(-7)=='semaine')iRank += 100000 * parseInt(sEdito.substr(0, sEdito.indexOf('è'))); //Popular movies else if(sEdito=='Dernières Séances')iRank += 100000; - + //Adding movie ID (newer movies have greater IDs) iRank += parseInt(this.id(), 10); return iRank; }; - + this.anchor = function() { if(Object.keys(this._anchor).length > 0) return this._anchor; @@ -151,7 +151,7 @@ function Film(oSettings) .appendTo(this.$Main); } }; - + this.toggleFilmDetails = function() { var $This = $(this); var show = function(hDom){ @@ -160,7 +160,7 @@ function Film(oSettings) $Dom.find('.movie-infos li').add($Dom.find('.movie-infos').next('ul').find('li')).each(function(iKey, oElem){ self.anchor().find('.film-details').append($('

').text($(oElem).text())); }); - + self.anchor().find('.film-details, .timetable').toggle(); self.anchor().find('.more-info').removeClass('fa-spinner fa-spin').addClass('fa-close'); }; @@ -168,17 +168,17 @@ function Film(oSettings) self.anchor().find('.film-details, .timetable').toggle(); self.anchor().find('.more-info').removeClass('fa-close').addClass('fa-more'); } - + if(self.anchor().find('.more-info').hasClass('fa-close')) hide(); else if(!$This.data('loaded')) self.getFilmDetails(show); else show(); }; - + this.getFilmDetails = function(fCallBack) { self.anchor().find('.more-info').removeClass('fa-more').addClass('fa-spinner fa-spin'); getUgcPage('film.html', {id: self.id()}, fCallBack, function(){}, 'html'); }; - + this.timetable = function(iCinemaId, sLang, oTimetable) { if(!iCinemaId) return this._timetable || {}; @@ -191,7 +191,7 @@ function Film(oSettings) this._timetable[iCinemaId][sLang].push(oTimetable); } }; - + this.renderTimetable = function(iCinemaId) { var sCinema = self.settings.cinemas(iCinemaId); @@ -208,7 +208,7 @@ function Film(oSettings) .append($('', {'class':'cinema_name'}).text(sCinema))) .append($('', {'class':'lang'}).text(sLang)) .appendTo($CinemaBox); - + var $Timetable = $('

', {'class':'screening'}); $.each(asTimetable.sort(self.timeCompare), function(iKey, oTime){ $Timetable @@ -219,12 +219,12 @@ function Film(oSettings) } }); }; - + this.timeCompare = function(sTime1, sTime2) { return (Date.parse('01/01/1970 '+sTime1.time+':00') > Date.parse('01/01/1970 '+sTime2.time+':00')); }; - + this.feedback = function(sMsg) { $('#feed_content').append($('

').text(sMsg)); @@ -249,15 +249,15 @@ function Ugc() this.$Main = $('main'); this.$Footer = $('footer'); this.$Feedback = $('#feedback'); - + this.loadCinemas = function() { //Display buffer while loading buffer(true); - + //Load Settings this.settings.init(); - + //Set Header $('#date') .attr('datetime', this.settings.date('html')) @@ -270,10 +270,10 @@ function Ugc() {cinemaId:iCinemaId, date:self.settings.date('french'), page:'10007', sort:'ugc', searchFilmKey:''}, function(hDom){self.addCinema(iCinemaId, hDom)}, function(){}, - 'html'); + 'html'); }); }; - + this.wip = function(iProgress) { if(!iProgress) return this._wip; @@ -283,11 +283,11 @@ function Ugc() if(this._wip==0) this.onPostLoad(); } }; - + this.onPostLoad = function() { var $Films = $('.film'); - + //Remove movies with no screening $Films.not('.banned').each(function(iKey, hFilm){ var $Film = $(hFilm); @@ -297,22 +297,22 @@ function Ugc() oFilm.ban(true, 'No screening today'); } }); - + //Sort films $Films.sort(function(oFilm1, oFilm2){ return (self.film($(oFilm1).data('id')).getRank() < self.film($(oFilm2).data('id')).getRank())?1:-1; }).detach(); - + //Add films (except bans) $Films.appendTo(this.$Main); - + //remove buffer buffer(false); - + //Build Search this.initSearch(); }; - + this.addCineNav = function(iCinemaId) { var sCinema = self.settings.cinemas(iCinemaId); @@ -326,7 +326,7 @@ function Ugc() }) .text(sFirstLetter)); }; - + this.initSearch = function() { var $SearchInput = $("#search"); @@ -345,10 +345,10 @@ function Ugc() { var sTerm = removeDiacritics(oRequest.term); var rMatcher = new RegExp($.ui.autocomplete.escapeRegex(sTerm), 'i'); - + //Remove all films $('.film').not('.banned').hide(); - + $.each(oUgc.film(), function(iFilmId, oFilm) { if(!oFilm.ban().status) @@ -362,7 +362,7 @@ function Ugc() }); } }); - + var asHash = self.hash(); var sDefaultSearch = asHash.items[0] || ''; if(asHash.page=='search' && sDefaultSearch!='') @@ -370,7 +370,7 @@ function Ugc() $SearchInput.focus().val(sDefaultSearch).putCursorAtEnd().autocomplete("search", sDefaultSearch); } }; - + this.hash = function(sPage, asItems) { sPage = sPage || ''; @@ -390,7 +390,7 @@ function Ugc() window.location.hash = '#'+encodeURIComponent(sPage+sItems); } }; - + this.addCinema = function(iCinemaId, hDom) { var $Films = $('

'+hDom+'
').find('.cinema-time-item'); @@ -401,54 +401,54 @@ function Ugc() var $Film = $(this); var iFilmId = $Film.find('.movie-link').attr('href').split('id=').pop(); var oFilm = self.film(iFilmId); - + if(!oFilm) { oFilm = new Film(self.settings); - + //ID oFilm.id(iFilmId); - + //Edito - var sProg = $.trim($Film.find('.programming').text()); + var sProg = $.trim($Film.find('.programming').text()); var sLabel = $.trim($Film.find('.label-ugc').text()); var sEdito = sProg?sProg:sLabel; oFilm.edito(sEdito); //Name oFilm.safe(oFilm.name($Film.find('.title > a').text())); - + //Poster var sPosterUrl = $Film.find('.movie-img').attr('source').replace('palegrey.jpg', 'white.jpg'); oFilm.poster(sPosterUrl); oFilm.backgroundPoster(sPosterUrl.replace('/small/', '/large/')); - + //Trailer oFilm.trailer(''); - + //Director - oFilm.director($.trim($Film.find('.movie-realisator').text().substring(4))); //omg - + oFilm.director($.trim($Film.find('.movie-realisator').text().trim().substring(3))); //omg + //Minimum info acquired: book place on DOM oFilm.anchor(); - + //Ban if wrong edito if((sEdito=='Avant-Première' && !self.settings.premiere()) || sEdito=='UGC Culte' || sEdito=='Soirée Club') oFilm.ban(true, sEdito); - + //Append film to Ugc self.film(iFilmId, oFilm); } - - //Timetable + + //Timetable if(!oFilm.ban().status) { var sLang = ''; var $Timetables = $Film.find('ul.timetable'); var oTimes = []; - + //Loop on languages $Timetables.each(function(iKey, oTimeTable){ - + //Loop on sessions $(oTimeTable).find('li').each(function(iKey, oLi){ $Li = $(oLi); @@ -470,19 +470,19 @@ function Ugc() else self.wip(-1); }); }; - + this.film = function(iFilmId, oFilm) { if(!iFilmId) return this._films; else if(!oFilm) return (iFilmId in this._films)?this._films[iFilmId]:false; else this._films[iFilmId] = oFilm; }; - + this.feedback = function(sMsg) { $('#feed_content').append($('

').text(sMsg)); }; - + this.error = function(sMsg) { console.log('Ugc Error: '+sMsg); @@ -496,14 +496,14 @@ function Settings() this._cinemas = {}; //this._ugcDates = []; this._date = null; - + this.$Settings = $('#settings'); this.$Header = $('header'); this.$Main = $('main'); - + this.consts = { days:["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], months:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]}; - + this.init = function() { //Default date @@ -516,16 +516,16 @@ function Settings() } else oDate = new Date(iCookieTimestamp); this.date(oDate); - + //UGC dates this.addUgcDatesToDom(); - + //Default cinemas var asCookieCinemas = Cookies.getJSON('cinemas'); this.cinemas(asCookieCinemas?asCookieCinemas:{'10':'Les Halles', '12':'Bercy', '20':'La Défense'}); - + //UGC cinemas - getUgcPage( 'resaExpressAction!getCinemaList.action', + getUgcPage( 'resaExpressAction!getCinemaList.action', {region:'', cinema:'', film:'', date:'', seance:'', '_':this.date('timestamp')}, function(jData){ self.ugcCinemas(jData.cinemas); @@ -533,20 +533,20 @@ function Settings() }, function(){self.error('Error: Could not load cinema list');}, 'json'); - + //Avant-Première switch var bCookiePremiere = Cookies.getJSON('premiere'); this.premiere(bCookiePremiere==null?false:bCookiePremiere); $('.switches').click(function(){self.premiere(!self.premiere());}); }; - + this.premiere = function(bActive) { var $Premiere = $('#premiere'); if(bActive==null) return $Premiere.hasClass('fa-on'); else $Premiere.removeClass('fa-on fa-off').addClass(bActive?'fa-on':'fa-off'); }; - + this.ugcCinemas = function(asCinemas) { if(!asCinemas) return this._ugcCinemas; @@ -558,14 +558,14 @@ function Settings() }); } }; - + this.cinemas = function(asCinemas) { if(!asCinemas) return this._cinemas; else if($.isNumeric(asCinemas)) return this._cinemas[asCinemas]; //Get Cinema name else this._cinemas = asCinemas; }; - + this.date = function(oDate) { if(!oDate) return this._date; @@ -601,14 +601,14 @@ function Settings() } else this._date = oDate; }; - + this.addUgcDatesToDom = function() { //Build today at midnight var oNextDay = new Date(); var bTuesdayNight = (oNextDay.getDay()==2 && oNextDay.getHours()==23); oNextDay = new Date(oNextDay.getFullYear(), oNextDay.getMonth(), oNextDay.getDate()); - + //Build available dates var $Select = $('#ugc_dates').find('select'); var $List = $('#ugc_days'); @@ -625,19 +625,19 @@ function Settings() } $Select.append($('