Advertisement
plasticfuzz

T117_SV_Promotion_Games

May 1st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <div class="mm-t117-wrap">
  2.     <h6 class="mm-t117-header">Recently played</h6>
  3.     <div class="mm-t117-content category-list soft--bottom"
  4.          data-rosin-component="rosin/TylerGroup"
  5.          data-tyler-category-list>
  6.     </div>
  7. </div>
  8. <script>
  9.     ;
  10.     (function (campaign) {
  11.         campaign.renderVariant = renderVariant;
  12.  
  13.         mmcore.mediator.on('www-sv-dispatch-event-after', function (data) {
  14.             if (data.args[0] !== 'UPDATE_RECENT_GAMES') {
  15.                 return;
  16.             }
  17.  
  18.             newRecentGameHandler(data)
  19.         });
  20.  
  21.         function renderVariant(evt) {
  22.             var isLoggedIn;
  23.  
  24.             var games = getPromoGames(evt);
  25.  
  26.             if (games) {
  27.                 return campaign.allGames.receive(games).then(function () {
  28.                     renderGames(evt, games, 'Featured');
  29.                 });
  30.             }
  31.  
  32.             games = getRecentGames();
  33.  
  34.             try {
  35.                 isLoggedIn = window.SkyBetAccount.lastLoginState.name === 'loggedIn'
  36.             } catch (e) {
  37.             }
  38.  
  39.             if (isLoggedIn && games.length) {
  40.                 return campaign.allGames.receive(games).then(function () {
  41.                     renderGames(evt, games, 'Recently played');
  42.                 });
  43.             }
  44.  
  45.             return campaign.featuredGames.getList().then(function (games) {
  46.                 return campaign.allGames.receive(games);
  47.             }).then(function (games) {
  48.                 renderGames(evt, games, 'Featured games');
  49.             });
  50.         }
  51.  
  52.         function renderGames(evt, games, header) {
  53.             var elemInsetTo;
  54.             var tempWrap = document.createElement('div');
  55.             var injectWrap = document.createElement('div');
  56.             var gamesScrpt = convGamesToTag(games);
  57.  
  58.             injectWrap.innerHTML = mm_inner_HTML;
  59.             injectWrap = injectWrap.querySelector('.mm-t117-wrap');
  60.  
  61.             injectWrap.querySelector('.mm-t117-header').innerHTML = header;
  62.             injectWrap.querySelector('.mm-t117-content').appendChild(gamesScrpt);
  63.  
  64.             /**
  65.              * Different handling of sibgle page routing and hard load of the page
  66.              */
  67.             if (evt && evt.data && evt.data.content) {
  68.                 tempWrap.innerHTML = evt.data.content;
  69.             } else {
  70.                 tempWrap = document;
  71.             }
  72.  
  73.             try {
  74.                 elemInsetTo = tempWrap
  75.                         .querySelector('.main-body')
  76.                         .querySelector('[data-rosin-component="rosin/MyAccountLink"][data-track-id="FAQ"]')
  77.                         .parentNode;
  78.             } catch (e) {
  79.             }
  80.  
  81.             if (!elemInsetTo) {
  82.                 mmcore.EH('T117 error - node to insert content absent');
  83.                 return;
  84.             }
  85.  
  86.             var oldWrap = tempWrap.querySelector('.mm-t117-wrap');
  87.             var oldCont = oldWrap && oldWrap.querySelector('.mm-t117-content');
  88.  
  89.             if (oldCont) {
  90.                 oldCont.innerHTML = injectWrap.querySelector('.mm-t117-content').innerHTML;
  91.             } else {
  92.                 prependEl(injectWrap, elemInsetTo);
  93.             }
  94.  
  95.             if (games.length < 3) {
  96.                 (oldWrap || injectWrap).classList.add('mm-t117-half-height')
  97.             }
  98.  
  99.             if (evt && evt.data && evt.data.content) {
  100.                 evt.data.content = tempWrap.innerHTML;
  101.             } else {
  102.                 window.rosin.update(oldWrap || injectWrap);
  103.             }
  104.  
  105.             oldCont && oldCont.classList.remove('mm-t117-content__hidden');
  106.         }
  107.  
  108.         function getPromoGames(evt) {
  109.             var url;
  110.  
  111.             try {
  112.                 url = evt.data.path;
  113.             } catch (e) {
  114.             }
  115.  
  116.             if (!url) {
  117.                 url = location.pathname;
  118.             }
  119.  
  120.             if (url.indexOf('/promotions/rainbow-riches-freespin-drop') === 0) {
  121.                 return ["/games/rainbow-riches-pick-n-mix-html"];
  122.             } else {
  123.                 return null;
  124.             }
  125.  
  126.         }
  127.  
  128.         function getRecentGames() {
  129.             try {
  130.                 return mmcore.SkyVegasDeskApi.dispCtx.getStore('RecentGamesStore').recentGames.slice(0, 4);
  131.             } catch (e) {
  132.                 return [];
  133.             }
  134.         }
  135.  
  136.         function convGamesToTag(games) {
  137.             var gameCats = [];
  138.  
  139.             for (var i = 0; i < 2; i++) {
  140.                 if (games.length < 3 && i === 1) {
  141.                     break;
  142.                 }
  143.  
  144.                 gameCats[i] = {
  145.                     "title": "Row " + (i + 1),
  146.                     "seeAllLink": null,
  147.                     "description": null,
  148.                     "reflowOnWindowResize": true,
  149.                     "tileGroup": {
  150.                         "layout": "mm-t117-layout",
  151.                         "tiles": []
  152.                     }
  153.                 };
  154.             }
  155.  
  156.             games.forEach(function (val, indx, arr) {
  157.                 var catInd = indx < 2 ? 0 : 1;
  158.  
  159.                 gameCats[catInd].tileGroup.tiles.push({
  160.                     type: 'game',
  161.                     href: val
  162.                 });
  163.             });
  164.  
  165.             var scrpt = document.createElement('scr' + 'ipt');
  166.             scrpt.setAttribute('type', "application/json");
  167.  
  168.             scrpt.innerHTML = JSON.stringify({
  169.                 "categories": gameCats
  170.             });
  171.  
  172.             return scrpt;
  173.         }
  174.  
  175.         function prependEl(elem, parent) {
  176.             parent.insertBefore(elem, parent.firstElementChild);
  177.         }
  178.  
  179.         function newRecentGameHandler(evt) {
  180.             if (!campaign.checkUrl(location.pathname)) {
  181.                 return;
  182.             }
  183.  
  184.             var oldCont = document.querySelector('.mm-t117-content');
  185.  
  186.             var header = document.querySelector('.mm-t117-header');
  187.  
  188.             if ( header && header.innerHTML !== 'Recently played' ) {
  189.                 return;
  190.             }
  191.  
  192.             if (oldCont) {
  193.                 oldCont.classList.add('mm-t117-content__hidden');
  194.                 oldCont.innerHTML = '';
  195.             }
  196.  
  197.             setTimeout(function() {
  198.                 campaign.renderVariant({
  199.                     dispatch: {
  200.                         ctx: evt.ctx,
  201.                         args: evt.args
  202.                     }
  203.                 })
  204.             }, 250);
  205.         }
  206.     })(this);
  207. </script>
  208. <style>
  209.     .mm-t117-wrap {
  210.         margin-bottom: 24px;
  211.         padding-bottom: 20px;
  212.         border-bottom: 1px dashed black;
  213.     }
  214.  
  215.     .mm-t117-content {
  216.         position: relative;
  217.         width: 100%;
  218.         padding-top: 100%;
  219.         padding-bottom: 0px !important;
  220.         transition: opacity .25s;
  221.     }
  222.  
  223.     .mm-t117-half-height .mm-t117-content {
  224.         padding-top: 50%;
  225.     }
  226.  
  227.     .mm-t117-content > div {
  228.         width: 100%;
  229.         position: absolute;
  230.         top: 0;
  231.     }
  232.  
  233.     .mm-t117-content__hidden {
  234.         opacity: 0;
  235.     }
  236.  
  237.     .mm-t117-content .tile {
  238.         width: 47.5% !important;
  239.         height: 100% !important;
  240.         top: auto !important;
  241.         left: auto !important;
  242.         right: 0;
  243.  
  244.         transform: initial !important;
  245.         -webkit-transform: initial !important;
  246.         -ms-transform: initial !important;
  247.     }
  248.  
  249.     .mm-t117-content .tile:first-child {
  250.         left: 0 !important;
  251.     }
  252.  
  253.     .mm-t117-content .homepage-category {
  254.         margin: 0px;
  255.     }
  256.  
  257.     .mm-t117-content .homepage-category.homepage-category--row-1 {
  258.         margin-bottom: 5%;
  259.     }
  260.  
  261.     .mm-t117-content .tyler-group > div {
  262.         width: auto !important;
  263.     }
  264.  
  265.     .mm-t117-content .tyler-group__inner {
  266.         padding-bottom: 47.5% !important;
  267.         width: auto !important;
  268.         height: auto !important;
  269.     }
  270.  
  271.     .mm-t117-content .tile .tile__inner-mouseout,
  272.     .mm-t117-content .tile .tile__inner-mouseover {
  273.         width: 100%;
  274.     }
  275.  
  276.     .mm-t117-content .tile__inner__footer__info:hover {
  277.         color: white;
  278.     }
  279.  
  280.     .mm-t117-content .tyler-group > div:first-child {
  281.         display: none;
  282.     }
  283.  
  284.     .mm-t117-content .mm-t117-wrap {
  285.         margin-bottom: 50px;
  286.     }
  287.  
  288.     @media only screen and (max-width: 749px) and (min-width: 470px) {
  289.         .mm-t117-content .tile {
  290.             /*zoom: 1.5;*/
  291.         }
  292.     }
  293. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement