Last active
February 9, 2016 00:45
-
-
Save stoplion/12d3495ecb52f70712c0 to your computer and use it in GitHub Desktop.
topTest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| window.DSCR = window.DSCR || {}; | |
| DSCR.hostname = DSCR.hostname || "www.opentable.com"; | |
| DSCR.cookies = DSCR.cookies || {}; | |
| DSCR.templates = DSCR.templates || {}; | |
| DSCR.xhr = DSCR.xhr || {}; | |
| DSCR.util = DSCR.util || {}; | |
| DSCR.init = DSCR.init || {}; | |
| window.DSCR.cookies = { | |
| setCookie: function(name, value, days) { | |
| var expires; | |
| if (days) { | |
| var date = new Date(); | |
| date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); | |
| expires = "; expires=" + date.toGMTString(); | |
| } else { | |
| expires = ""; | |
| } | |
| document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/"; | |
| }, | |
| getCookie: function(name) { | |
| var nameEQ = encodeURIComponent(name) + "="; | |
| var ca = document.cookie.split(';'); | |
| for (var i = 0; i < ca.length; i++) { | |
| var c = ca[i]; | |
| while (c.charAt(0) === ' ') c = c.substring(1, c.length); | |
| if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length)); | |
| } | |
| return null; | |
| }, | |
| unsetCookie: function(name) { | |
| this.setCookie(name, "", -1); | |
| }, | |
| allLastseen: function() { | |
| var lastseen = _.isNull(this.getCookie("lastseen")) ? [] : _.uniq(_.compact(JSON.parse(this.getCookie("lastseen")))).slice(0,15); | |
| return lastseen; | |
| }, | |
| lastLastseen: function() { | |
| var lastseen = this.allLastseen(); | |
| return lastseen[0]; | |
| }, | |
| addLastseen: function(rid) { | |
| var lastseen = this.allLastseen(); | |
| lastseen.unshift(rid); | |
| this.setCookie("lastseen", JSON.stringify(lastseen), 180); | |
| }, | |
| // private for testing purposes | |
| _clearLastseen: function() { | |
| this.unsetCookie("lastseen"); | |
| }, | |
| getLastName: function() { | |
| var lastname = _.isNull(this.getCookie("lastname")) ? "unknown" : JSON.parse(this.getCookie("lastname")); | |
| return lastname; | |
| }, | |
| setLastName: function(name) { | |
| this.setCookie("lastname", JSON.stringify(name), 180); | |
| } | |
| }; | |
| window.DSCR.util['trigger_scroller'] = function() { | |
| setTimeout(function(){function r(r){function t(){e.scrollLeft()>0?s.addClass("active"):s.removeClass("active");var r=o.width()-e.width();e.scrollLeft()<r?l.addClass("active"):l.removeClass("active")}function i(r){function i(r){return Math.round(r.position().left)}function n(r){return i(r)+r.width()}var o,l=e.scrollLeft(),s=l+e.width();if("right"==r)o=_.find(c,function(r){return s<n($(r))});else if("left"==r){var a=_.find(c.get().reverse(),function(r){return i($(r))<l});if(a){var h=n($(a)),d=h-e.width();o=_.find(c,function(r){return d<=i($(r))})}}o&&e.animate({scrollLeft:i($(o))},200,function(){t()})}var n=$(".grid-scroller-container",r),e=$(".grid-scroller-wrapper",n),o=$(".grid-scroller-row",e),c=$(".grid-scroller-column",o),l=$(".grid-scroller-arrow-right",r),s=$(".grid-scroller-arrow-left",r),a=(c.length,0),h=0,d=0;e.addClass("with-scrolling"),c.each(function(){var r=$(this),t=r.outerHeight(),i=r.outerWidth();h+=i,t>a&&(a=t),i>d&&(d=i)}),n.hasClass("photo-container")||(n.height(a),o.width(h)),o.width()>e.width()&&l.addClass("active"),e.scroll(function(){t()}),l.click(function(){return i("right"),!1}),s.click(function(){return i("left"),!1}),n.hasClass("photo-container")&&$(document).on("keyup",function(r){37==r.which?i("left"):39==r.which&&i("right")}),this.doArrows=t}var t="ot-grid-scroller";$(".grid-scroller").each(function(){$(this).data(t,new r($(this)))})},500); | |
| }; | |
| window.DSCR.util['lunch_or_dinner'] = function() { | |
| return new Date().getHours() < 14 ? "lunch" : "dinner" | |
| }; | |
| window.DSCR.templates['restaurant_i18n'] = function( lang ) { | |
| var reserve_now = 'Reserve Now'; | |
| if (lang == 'ja') { reserve_now = '予約を入れる'; } | |
| if (lang == 'de') { reserve_now = 'Reserviere jetzt'; } | |
| if (lang == 'fr') { reserve_now = 'Réservez maintenant'; } | |
| return _.template('<div class="result content-section-list-row cf with-times grid-scroller-column">' | |
| +'<div class="rest-row with-image">' | |
| +' <div class="rest-row-image">' | |
| +' <a href="/<%= natural_language_name %>?p=2">' | |
| +' <img src="<%= image %>" class="lazy rest-image loaded">' | |
| +' </a>' | |
| +' </div>' | |
| +' <div class="rest-row-info">' | |
| +' <a href="/<%= natural_language_name %>?p=2" class="rest-row-name rest-name"><%= name %></a>' | |
| +' <div class="rest-row-review">' | |
| +' <div class="star-rating">' | |
| +' <% if (review_overall > 0) { %>' | |
| +' <div class="star-wrapper small">' | |
| +' <div class="all-stars"></div>' | |
| +' <div style="width: <%= (review_overall*20) %>%;" title="4.4" class="all-stars filled"></div>' | |
| +' </div>' | |
| +' <% } %>' | |
| +' <% if (review_count > 0) { %>' | |
| +' <span class="star-rating-text color-light">(<%= review_count %>)</span>' | |
| +' <% } %>' | |
| +' </div>' | |
| +' </div>' | |
| +' <div class="rest-row-pricing">' | |
| +' <div class="price-rating">' | |
| +' <span class="price-rating-tier <%= (price_band >=1) ? "on" : "off" %>"></span>' | |
| +' <span class="price-rating-tier <%= (price_band >=2) ? "on" : "off" %>"></span>' | |
| +' <span class="price-rating-tier <%= (price_band >=3) ? "on" : "off" %>"></span>' | |
| +' <span class="price-rating-tier <%= (price_band >=4) ? "on" : "off" %>"></span>' | |
| +' </div>' | |
| +' </div>' | |
| +' <div class="rest-row-meta rest-row-meta-grid"><%= cuisine %> <i>|</i> <%= neighborhood %></div>' | |
| +' </div>' | |
| +'</div>' | |
| +'<div class="rest-row-times-cont">' | |
| +' <div class="rest-row-times">' | |
| +' <a class="reserve-now" href="/<%= natural_language_name %>?p=2">'+ reserve_now +'</a>' | |
| +' </div>' | |
| +'</div>' | |
| +'</div>'); | |
| }; | |
| // ------------------------------------ Recently Viewed ------------------------------------ // | |
| window.DSCR.xhr['rowUsingRids'] = function(rids, lang) { | |
| var allrids = rids.join(','); | |
| var protocol = 'https:' == document.location.protocol ? 'https://' : 'http://'; | |
| var injector_uri = protocol + DSCR.hostname + "/injector/restaurants/" + allrids+ "?lang="+ lang; | |
| return $.ajax({ | |
| url: injector_uri, | |
| method: 'GET', | |
| dataType: "json", | |
| crossDomain: true | |
| }); | |
| }; | |
| window.DSCR.init['recently_viewed'] = function() { | |
| var injector = $('#injector-popular-recommendations .grid-scroller-row'); | |
| var rids = DSCR.cookies.allLastseen() || [0]; | |
| var lang = "en"; | |
| if (!_.isUndefined(window.OT) && !_.isUndefined(window.OT.SRS) && !_.isUndefined(window.OT.SRS.lang)) { lang = window.OT.SRS.lang; } | |
| return DSCR.xhr | |
| .rowUsingRids(rids, lang) | |
| .done(function(response) { | |
| if (response.code == 'ok' && response.restaurants) { | |
| if (_.isEmpty(response.restaurants)) { | |
| $('#popular-recommendations').hide(); | |
| } else { | |
| $('#popular-recommendations').show(); | |
| //also skip the null | |
| var pickRid; | |
| _.compact(response.restaurants).slice(0, 2).forEach(function(restaurant_data){ | |
| pickRid = restaurant_data.rid; | |
| var templateToAppend = $(DSCR.templates.restaurant_i18n(lang)(restaurant_data)).addClass('recently-viewed-item').get(0); | |
| injector.append(templateToAppend); | |
| }); | |
| $('.recently-viewed-item').first().prepend('<h3 class="recently-viewed-header">Recently Viewed</h3>'); | |
| DSCR.init.similar_cf(pickRid); | |
| injector.show(); | |
| DSCR.util.trigger_scroller(); | |
| } | |
| } | |
| }); | |
| }; | |
| // ------------------------------------ / Recently Viewed ------------------------------------ // | |
| // ------------------------------------ Similar ------------------------------------ // | |
| window.DSCR.xhr['rowWithSimilarCF'] = function(rid, lang) { | |
| var protocol = 'https:' == document.location.protocol ? 'https://' : 'http://'; | |
| var injector_uri = protocol + DSCR.hostname + "/injector/restaurants/similar_cf/" + rid + "?lang="+ lang; | |
| return $.ajax({ | |
| url: injector_uri, | |
| method: 'GET', | |
| dataType: "json", | |
| crossDomain: true | |
| }); | |
| }; | |
| window.DSCR.init['similar_cf'] = function(rid) { | |
| var injector = $('#injector-popular-recommendations .grid-scroller-row'); | |
| var lang = "en"; | |
| if (!_.isUndefined(window.OT) && !_.isUndefined(window.OT.SRS) && !_.isUndefined(window.OT.SRS.lang)) { lang = window.OT.SRS.lang; } | |
| return DSCR.xhr | |
| .rowWithSimilarCF(rid, lang) | |
| .done(function(response) { | |
| if (response.code == 'ok' && response.restaurants) { | |
| if (_.isEmpty(response.restaurants)) { | |
| return; | |
| } else { | |
| _.compact(response.restaurants).slice(0,15).forEach(function(restaurant_data){ | |
| var templateToAppend = $(DSCR.templates.restaurant_i18n(lang)(restaurant_data)).addClass('similar-rest-item').get(0); | |
| injector.append(templateToAppend); | |
| }); | |
| $('.similar-rest-item').first().prepend('<h3 class="recently-viewed-header">Restaurants You Might Like</h3>'); | |
| } | |
| } | |
| }); | |
| }; | |
| // ------------------------------------ / Similar ------------------------------------ // | |
| DSCR.init.recently_viewed(); | |
| console.log('recently viewwed with sim'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment