Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. import {
  2. store,
  3. animateBoughtTickets,
  4. // animateDivs,
  5. // pushNewTicketsAnimation,
  6. ticketThingsBoughtTickets,
  7. ticketThings,
  8. } from './keno.js';
  9. import {
  10. initialize
  11. } from './initialize.js';
  12. import * as b_tickets from './bought_tickets.js';
  13. // import * as extra from './extra.js';
  14.  
  15.  
  16. let oldRandomTicketsCache;
  17.  
  18. // Invokes animateBoughtTickets function with the right position calculations and divs passed as argument by Screen (Premade/Manual)
  19. function generateRandomTicketsAnimation(plusBtn) {
  20. const ns = store.getState();
  21.  
  22. const animationWrapper = $(plusBtn); // from which container
  23.  
  24. // const ticketsContainerPremade = $('#tickets_container_premade'); // to which container
  25. const premadeTicketsContainer = $('#rollingTicketsAnimation');
  26. // $('#keno_bh_layout1').addClass('overflow_hidden'); // on "generate random tickets" add class to hide overflow of tickets
  27.  
  28. /* Helps with finding from where to where animation must be played */
  29.  
  30. const usrAgent = navigator.userAgent;
  31. const leftEnd = LeftByDevice(animationWrapper, usrAgent);
  32. const topEnd = topEndByDevice(animationWrapper, usrAgent);
  33. const heightEnd = topEnd + premadeTicketsContainer.height();
  34.  
  35. // const ticketsVisible = ticketsContainerPremade.find('.ktbought:visible'); //tickets to copy
  36. const tickets = premadeTicketsContainer.find('.ktbought');
  37. // tickets.prepend(ticketsVisible.eq(0).clone().addClass('basierPremadeTickets').removeClass('clicked'));; //tickets to copy
  38.  
  39. /* PremadeTicketsScreen animation */
  40. if (ns.localstate.show_15_tickets !== 1) return;
  41. const ticketPosition = animationWrapper.position();
  42.  
  43. let range = 15;
  44. if (plusBtn === '.btn-plus10') range = 10;
  45. // copy 15 visible random tickets
  46. for (let index = 0; index < range; index++) {
  47. /* Calculating positions and taking the right divs before pass them as arguments to animateFunction */
  48. // const animatedTicketDiv = tickets.eq(index).clone().addClass('basierPremadeTickets').removeClass('clicked');
  49. const animatedTicketDiv = tickets.eq(index).clone().addClass('basierPremadeTickets').removeClass('clicked');
  50. animatedTicketDiv.addClass('ticketsStyle');
  51. animateBoughtTickets(ticketPosition.top / 10, ticketPosition.left, index, animatedTicketDiv, leftEnd, topEnd, plusBtn);
  52. }
  53.  
  54. const interval = 500;
  55. /* Updates ticketDiv after animation */
  56.  
  57. setTimeout(() => ticketThings(), 1);
  58. setTimeout(() => ticketThings(), Number(interval / 2)); //use for bought tickets ()
  59. setTimeout(() => ticketThings(), Number(interval * 2 / 3));
  60. return;
  61. }
  62.  
  63. // Top position animation according to the device
  64. function topEndByDevice(animationWrapper, userAgent) {
  65. return {
  66. 'iPhone': $('#game').height() / 4.43, // jQuery .position() doesn't work on IOS devices. This is a hardcore solution which works for now.
  67. 'ipad': $('#game').height() / 4.43, // jQuery .position() doesn't work on IOS devices. This is a hardcore solution which works for now.
  68. 'Android': animationWrapper.position().top + 30,
  69. null: animationWrapper.position().top + 30,
  70. }[navigator.userAgent.match(userAgent)];
  71. }
  72.  
  73. // Left position animation according to the device
  74. function LeftByDevice(animationWrapper, userAgent) {
  75. return {
  76. 'iPhone': $('#game').width() / 12.35, // jQuery .position() doesn't work on IOS devices. This is a hardcore solution which works for now.
  77. 'Mac OS X': $('#game').width() / 12.35, // jQuery .position() doesn't work on Mac OS devices. This is a hardcore solution which works for now.
  78. null: animationWrapper.position().left + animationWrapper.width()
  79. }[navigator.userAgent.match(userAgent)];
  80. }
  81.  
  82. function rollingTicketsAnimation() {
  83. // console.warn(ns.localstate.rollingTickets.length);
  84. $('#rollingTicketsAnimation').remove(); // remove div before append
  85. $('#tickets_container_premade').append($('<div id="rollingTicketsAnimation"></div>'))
  86. $('#keno_bh_layout1').addClass('overflow_hidden'); // on "generate random tickets" add class to hide overflow of tickets
  87.  
  88. /* GENERATING 45 tickets for rolling animation usage */
  89. const rollingTickets = store.getState().localstate.rollingTickets;
  90. ticketThings();
  91. // $('rollingTicketsAnimation .ktbought_ticketid_text').hide();
  92.  
  93. rollingTickets.forEach((ticket, index) => {
  94. $('#rollingTicketsAnimation').append(b_tickets.createTicket(ticket)); // create divs
  95. b_tickets.fillTicketData(ticket, index + 15, b_tickets.target.RANDOM_TICKETS_ANIMTION); // fill divs
  96. });
  97. }
  98.  
  99. export {
  100. generateRandomTicketsAnimation,
  101. rollingTicketsAnimation
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement