Advertisement
Guest User

Untitled

a guest
Mar 16th, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ! function() {
  2.     "use strict";
  3.     function o(o) {
  4.         return 10 > o ? "0" + o : o
  5.     }
  6.     function e() {
  7.         return Math.round((new Date).getTime() / 10)
  8.     }
  9.     function n(o) {
  10.         o = o.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  11.         var e = new RegExp("[\\?&]" + o + "=([^&#]*)"),
  12.             n = e.exec(location.search);
  13.         return null === n ? "" : decodeURIComponent(n[1].replace(/\+/g, " "))
  14.     }
  15.     var t = function() {},
  16.         i = ["assert", "clear", "count", "debug", "dir", "dirxml", "error", "exception", "group", "groupCollapsed", "groupEnd", "info", "log", "markTimeline", "profile", "profileEnd", "table", "time", "timeEnd", "timeStamp", "trace", "warn"];
  17.     _.each(i, function(o) {
  18.         console[o] || (console[o] = t)
  19.     }), window.App = {}, App.viewport = function() {
  20.         var o = window,
  21.             e = "inner";
  22.         return "innerWidth" in window || (e = "client", o = document.documentElement || document.body), {
  23.             width: o[e + "Width"],
  24.             height: o[e + "Height"]
  25.         }
  26.     }, App.isMobileBreakpoint = function() {
  27.         return App.viewport().width < 496
  28.     }, App.formatMiliseconds = function(e) {
  29.         var n = Math.floor(e / 100),
  30.             t = e - 100 * n;
  31.         return o(n) + ":" + o(t)
  32.     }, App.trackEvent = function(o, e) {
  33.         console.log("TRACKING:", o, "-", e), ga("send", "event", o, "click", e)
  34.     }, App.msTimer = function(o, n) {
  35.         var t = e(),
  36.             i = setInterval(function() {
  37.                 var r = e(),
  38.                     c = o - (r - t);
  39.                 0 >= c && clearInterval(i), n(c)
  40.             }, 10)
  41.     };
  42.     var r = n("ref");
  43.     "" !== r && ga("send", "event", "pageview", "open", "ref", r), window.fbAsyncInit = function() {
  44.             FB.init(), FB.Canvas.setSize()
  45.         },
  46.         function() {
  47.             var o = document.createElement("script");
  48.             o.async = !0, o.src = document.location.protocol + "//connect.facebook.net/en_US/all.js", document.getElementById("fb-root").appendChild(o)
  49.         }()
  50. }(),
  51. function() {
  52.     "use strict";
  53.     $("#content-close_overlay").on("click", function() {
  54.         history.back()
  55.     })
  56. }(),
  57. function() {
  58.     "use strict";
  59.     function o() {
  60.         var o = $.Deferred(),
  61.             t = Phaser.AUTO;
  62.         return monster.get("force_canvas") && (t = Phaser.CANVAS), I = new Phaser.Game(C, S, t, T, {
  63.             preload: e,
  64.             create: function() {
  65.                 n(o)
  66.             },
  67.             update: c
  68.         }), d.game = I, o.done(function() {
  69.             if (I.renderer && I.renderer.gl) {
  70.                 var o = I.renderer.gl,
  71.                     e = I.renderer.gl.getError();
  72.                 e !== o.NO_ERROR && e !== o.CONTEXT_LOST_WEBGL && (console.log("Detected webGL error. Set cookie and reload."), monster.set("force_canvas", "1"), location.reload())
  73.             }
  74.         }), o.promise()
  75.     }
  76.     function e() {
  77.         I.load.image("background", ASSETS_PATH + "bundles/lenovoyogamodes/img/game-background.png"), I.load.image("block0", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block0.png"), I.load.image("block0-combo", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block0-combo.png"), I.load.image("block1", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block1.png"), I.load.image("block1-combo", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block1-combo.png"), I.load.image("block2", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block2.png"), I.load.image("block2-combo", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block2-combo.png"), I.load.image("block3", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block3.png"), I.load.image("block3-combo", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block3-combo.png"), I.load.image("block4", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block4.png"), I.load.image("block4-combo", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block4-combo.png")
  78.     }
  79.     function n(o) {
  80.         var e = I.add.sprite(0, 0, "background");
  81.         e.width = C, e.height = S, I.physics.startSystem(Phaser.Physics.ARCADE), I.stage.disableVisibilityChange = !0, x = I.add.group();
  82.         var n = "ontouchstart" in window || navigator.msMaxTouchPoints || "onmsgesturechange" in window;
  83.         n && $("#game-mobile-controls").addClass("active");
  84.         var t = I.input.keyboard.createCursorKeys();
  85.         ["left", "right", "down"].forEach(function(o) {
  86.             t[o].onDown.add(function() {
  87.                 i(o)
  88.             });
  89.             var e = "";
  90.             window.navigator.msPointerEnabled && (e = "MSPointerDown "), e += "touchstart", window.navigator.userAgent.match(/android/i) || (e += " click"), $(document).on(e, "#cursor-" + o, function(e) {
  91.                 return e.stopPropagation(), e.preventDefault(), event.handled === !0 ? !1 : (i(o), event.handled = !0, void 0)
  92.             })
  93.         });
  94.         var r = Math.max(0, $(document).height() - App.viewport().height - $(".app-footer").outerHeight());
  95.         $(window).scrollTop(r), o.resolve()
  96.     }
  97.     function t() {
  98.         var o = G.shift(),
  99.             e = -O.BLOCK_HEIGHT,
  100.             n = Math.ceil(A / 2) * O.BLOCK_WIDTH,
  101.             t = x.create(n, e, "block" + o);
  102.         t.width = O.BLOCK_WIDTH - 1, t.height = O.BLOCK_WIDTH, t.type = o, t.id = ++P, t.name = "Block #" + t.id + " (type " + t.type + ")", I.physics.enable([t], Phaser.Physics.ARCADE), t.body.velocity.y = O.VELOCITY, H = t, console.info("spawned", t.name), G.length < 15 && v()
  103.     }
  104.     function i(o) {
  105.         if (H) {
  106.             var e, n;
  107.             switch (o) {
  108.                 case "left":
  109.                     e = H.position.x - O.BLOCK_WIDTH, e = Math.max(e, 0), n = H.position.y;
  110.                     break;
  111.                 case "right":
  112.                     e = H.position.x + O.BLOCK_WIDTH, e = Math.min(e, C - O.BLOCK_WIDTH), n = H.position.y;
  113.                     break;
  114.                 case "down":
  115.                     e = H.position.x, n = H.position.y + O.BLOCK_HEIGHT, n = Math.min(n, S - O.BLOCK_HEIGHT);
  116.                     break;
  117.                 default:
  118.                     return
  119.             }
  120.             r(e, n) ? "down" === o && (n = p(n), r(e, n) || (H.position.y = n)) : (H.position.x = e, H.position.y = n)
  121.         }
  122.     }
  123.     function r(o, e) {
  124.         var n = !1;
  125.         return $.each(M, function(t, i) {
  126.             if (null !== i && M.hasOwnProperty(t)) {
  127.                 var r = o === i.position.x,
  128.                     c = e >= i.position.y - O.BLOCK_HEIGHT && e < i.position.y + O.BLOCK_HEIGHT;
  129.                 r && c && (n = !0)
  130.             }
  131.         }), n
  132.     }
  133.     function c() {
  134.         I.physics.arcade.collide(x, x, function(o, e) {
  135.             H === e && (o.position.x !== e.position.x && (e.position.x = o.position.x), a())
  136.         }), H && H.position.y + H.height >= I.world.height - 1 && a()
  137.     }
  138.     function a() {
  139.         if (H.body.immovable = !0, H.body.velocity.y = 0, H.position.y <= 0) return h(), void 0;
  140.         var o = H.position.x,
  141.             e = p(H.position.y);
  142.         H.gridRow = e / O.BLOCK_HEIGHT, H.gridCol = o / O.BLOCK_WIDTH, D[H.gridRow][H.gridCol] = H, M[H.id] = H;
  143.         var n = l();
  144.         console.info("placed ", H.name, "at", H.gridCol + ":" + H.gridRow), k(H, n), H = null, n.length ? setTimeout(t, O.REMOVE_COMBO_DELAY) : t()
  145.     }
  146.     function l() {
  147.         var o = [];
  148.         _.each(D, function(e) {
  149.             o = o.concat(s(e))
  150.         });
  151.         for (var e = 0; A > e; e++) {
  152.             for (var n = [], t = 0; B > t; t++) n.push(D[t][e]);
  153.             o = o.concat(s(n))
  154.         }
  155.         if (_.each(u(), function(e) {
  156.                 var n = [];
  157.                 _.each(e, function(o) {
  158.                     null !== D[o.y][o.x] ? n.push(D[o.y][o.x]) : n.push(null)
  159.                 }), o = o.concat(s(n))
  160.             }), o.length) {
  161.             o = _.uniq(o), E(), o.length && console.info(" => combos:", o), o.forEach(function(o) {
  162.                 g(o.length)
  163.             }), o.forEach(f);
  164.             var i = l();
  165.             i.length && k(null, i)
  166.         }
  167.         return o
  168.     }
  169.     function s(o) {
  170.         for (var e = [], n = !1, t = !1, i = !1, r = _.size(o), c = 0; r > c; c++) {
  171.             var a = o[c],
  172.                 l = null === a,
  173.                 s = l ? null : a.type,
  174.                 u = s === t,
  175.                 d = 0 === s,
  176.                 p = 0 === t,
  177.                 f = parseInt(c, 10) === r - 1;
  178.             if (n !== !1 || l)
  179.                 if (!l && (u || d || p)) n.push(a), p && (t = s), f && n.length >= O.BLOCKS_PER_COMBO && e.push(n);
  180.                 else {
  181.                     if (n.length >= O.BLOCKS_PER_COMBO) e.push(n);
  182.                     else if (0 === i && !l) {
  183.                         n = !1, t = !1, i = !1, c -= 2;
  184.                         continue
  185.                     }
  186.                     l ? (n = !1, t = !1) : (n = [a], t = s)
  187.                 } else n = [a], t = s;
  188.             i = s
  189.         }
  190.         return e
  191.     }
  192.     function u() {
  193.         for (var o = function(o, e, n) {
  194.                 return n.x < o && n.x >= 0 && n.y < e && n.y >= 0
  195.             }, e = function(o) {
  196.                 return {
  197.                     x: o.x - 1,
  198.                     y: o.y + 1
  199.                 }
  200.             }, n = function(o) {
  201.                 return {
  202.                     x: o.x + 1,
  203.                     y: o.y + 1
  204.                 }
  205.             }, t = -1 * B + O.BLOCKS_PER_COMBO, i = A + B - O.BLOCKS_PER_COMBO, r = [], c = [], a = t; i > a; a++) {
  206.             var l = {
  207.                     x: a,
  208.                     y: 0
  209.                 },
  210.                 s = e(l);
  211.             for (o(A, B, l) && c.push(l); s.x >= 0 && s.y < B;) o(A, B, s) && c.unshift(s), s = e(s);
  212.             r.push(c), c = [];
  213.             var u = n(l);
  214.             for (o(A, B, l) && c.push(l); u.y >= 0 && u.x < A;) o(A, B, u) && c.push(u), u = n(u);
  215.             r.push(c), c = []
  216.         }
  217.         return r
  218.     }
  219.     function p(o) {
  220.         return Math.floor((o + 1) / O.BLOCK_HEIGHT) * O.BLOCK_HEIGHT
  221.     }
  222.     function f(o) {
  223.         o.forEach(function(o) {
  224.             o.loadTexture("block" + o.type + "-combo"), setTimeout(function() {
  225.                 o.kill()
  226.             }, O.REMOVE_COMBO_DELAY), D[o.gridRow][o.gridCol] = null, M[o.id] = null;
  227.             for (var e = o.gridRow - 1; e >= 0; e--)
  228.                 if (null !== D[e][o.gridCol]) {
  229.                     var n = D[e][o.gridCol];
  230.                     n.position.y += O.BLOCK_HEIGHT, n.gridRow += 1, D[e][o.gridCol] = null, D[n.gridRow][o.gridCol] = n
  231.                 }
  232.         })
  233.     }
  234.     function g(o) {
  235.         var e;
  236.         switch (o) {
  237.             case 4:
  238.                 e = 2.5;
  239.                 break;
  240.             case 5:
  241.                 e = 5;
  242.                 break;
  243.             default:
  244.                 e = 1
  245.         }
  246.         K += O.SCORE_MULTIPLIER_BASE * e, R += O.SCORE_MULTIPLIER_BASE * e, $("#game_play_score").val(K), $("#score-counter").text(R)
  247.     }
  248.     function h() {
  249.         $("#game canvas").hide(), $("#game-loading").show(), I.destroy(), console.info("GAME OVER (" + K + ")"), window._fbq.push(["track", "6020907107647", {
  250.             value: "0.00",
  251.             currency: "GBP"
  252.         }]), $.when.apply(this, q).always(function() {
  253.             $("#game-form").submit()
  254.         })
  255.     }
  256.     function m() {
  257.         var o = 100 * O.TIME_LIMIT;
  258.         App.msTimer(o, function(o) {
  259.             $("#time-left").text(App.formatMiliseconds(o)), 0 >= o && h()
  260.         })
  261.     }
  262.     function v() {
  263.         return $.ajax({
  264.             url: "play/get-elements",
  265.             dataType: "json",
  266.             cache: !1
  267.         }).then(function(o) {
  268.             L = o.key, $("#game_play_key").val(L), G = G.concat(o.elements)
  269.         }).fail(function(o) {
  270.             alert("[getElems] server error (" + o.statusText + "): " + o.responseText), location.reload()
  271.         })
  272.     }
  273.     function b() {
  274.         return $.post("play/start", {
  275.             key: L
  276.         }).fail(function(o) {
  277.             alert("[start] server error (" + o.statusText + "): " + o.responseText), location.reload()
  278.         })
  279.     }
  280.     function k(o, e) {
  281.         var n = {
  282.             key: L
  283.         };
  284.         null !== o && (n.element = {
  285.             type: o.type,
  286.             pos: {
  287.                 col: o.gridCol,
  288.                 row: o.gridRow
  289.             }
  290.         }), n.groups = e.map(function(o) {
  291.             return o.map(function(o) {
  292.                 return {
  293.                     type: o.type,
  294.                     pos: {
  295.                         col: o.gridCol,
  296.                         row: o.gridRow
  297.                     }
  298.                 }
  299.             })
  300.         });
  301.         var t = $.post("play/update", n);
  302.         q.push(t), t.fail(function(o) {
  303.             alert("[update] server error (" + o.statusText + "): " + o.responseText), location.reload()
  304.         })
  305.     }
  306.     function w() {
  307.         $("#game-loading").hide(), $("#game .canvas-wrapper").css({
  308.             visibility: "visible"
  309.         }), $("#countdown").show();
  310.         var o = $.Deferred(),
  311.             e = 5,
  312.             n = setInterval(function() {
  313.                 e -= 1, $("#countdown .counter").text(e), 0 === e && ($("#countdown").hide(), o.resolve(), clearInterval(n))
  314.             }, 1e3);
  315.         return o.promise()
  316.     }
  317.     function y(o) {
  318.         App.viewport().width > 495 && $("body").css({
  319.             backgroundImage: "url(" + ASSETS_PATH + "bundles/lenovoyogamodes/img/game-bodybackground.png)",
  320.             backgroundSize: "auto " + (o - 50) + "px"
  321.         })
  322.     }
  323.     function E() {
  324.         _.each(D, function(o, e) {
  325.             var n = "row " + e + ": ";
  326.             _.each(o, function(o) {
  327.                 n += "|" + (o ? o.type : "-")
  328.             }), console.log(n + "|")
  329.         })
  330.     }
  331.     if (0 !== $("#game").length) {
  332.         var T = $("#game .canvas-wrapper")[0],
  333.             A = 6,
  334.             B = 8,
  335.             C = Math.floor(T.offsetWidth / A) * A,
  336.             S = B / A * C;
  337.         T.style.height = S, y(S);
  338.         var O = {
  339.             BLOCK_WIDTH: Math.floor(C / 6),
  340.             BLOCK_HEIGHT: Math.floor(S / 8),
  341.             VELOCITY: parseInt(GAMECONFIG.velocity || "50", 10),
  342.             BLOCKS_PER_COMBO: 3,
  343.             SCORE_MULTIPLIER_BASE: 10,
  344.             REMOVE_COMBO_DELAY: 500,
  345.             TIME_LIMIT: parseInt($("#time-left").attr("data-time"), 10)
  346.         };
  347.         console.info("init - world", C, S, "blocks:", O.BLOCK_WIDTH, O.BLOCK_HEIGHT);
  348.         for (var I, x, H, L, P = 0, M = {}, R = parseInt($("#score-counter").text(), 10) || 0, K = 0, G = [], q = [], D = {}, W = 0; B > W; W++) {
  349.             D[W] = {};
  350.             for (var V = 0; A > V; V++) D[W][V] = null
  351.         }
  352.         v().then(o).then(w).then(m).then(b).then(t), window.d = {
  353.             blocksGroup: x,
  354.             activeBlock: H,
  355.             placedBlocks: M,
  356.             grid: D
  357.         }, window.d.logGrid = E
  358.     }
  359. }(),
  360. function() {
  361.     "use strict";
  362.     $("#howto-slider").length && ($("#howto-slider").bxSlider({
  363.         adaptiveHeight: !0,
  364.         infiniteLoop: !1,
  365.         hideControlOnEnd: !0,
  366.         touchEnabled: !0
  367.     }), $("#howto-slider li:first img:first").trigger("load"))
  368. }(),
  369. function() {
  370.     "use strict";
  371.     if ($("#view-index").length) {
  372.         if (self !== top) {
  373.             var o = $("#auth-button").attr("href");
  374.             $("#auth-button").attr("href", o + "?redirect_url=lym_canvas")
  375.         }
  376.         $("#auth-button").on("click", function() {
  377.             App.trackEvent("Start Screen", "Button1 (let´s go) click")
  378.         })
  379.     }
  380. }(),
  381. function() {
  382.     "use strict";
  383.     $("#view-intro").length && ($("#intro-newbie-play-button").on("click", function() {
  384.         App.trackEvent("Intro screen new user", "Button2 (let´s go) click"), window._fbq.push(["track", "6020907068647", {
  385.             value: "0.00",
  386.             currency: "GBP"
  387.         }]), window._fbq.push(["track", "6020907052047", {
  388.             value: "0.00",
  389.             currency: "GBP"
  390.         }])
  391.     }), $("#intro-returnee-play-button").on("click", function() {
  392.         App.trackEvent("Intro screen returning user", "Button3 (let´s go) click"), window._fbq.push(["track", "6020907068647", {
  393.             value: "0.00",
  394.             currency: "GBP"
  395.         }]), window._fbq.push(["track", "6020907052047", {
  396.             value: "0.00",
  397.             currency: "GBP"
  398.         }])
  399.     }))
  400. }(),
  401. function() {
  402.     "use strict";
  403.     if ($("#view-question").length) {
  404.         var o = 100 * parseInt($("#time-left").attr("data-time"), 10);
  405.         App.msTimer(o, function(o) {
  406.             $("#time-left").text(App.formatMiliseconds(o)), 0 >= o && $("#question-form").submit()
  407.         }), $(".question-lvl-1 #game_question_save").on("click", function() {
  408.             App.trackEvent("Bonus question level 1 play screen", "Button5 (submit) click")
  409.         }), $(".question-lvl-2 #game_question_save").on("click", function() {
  410.             App.trackEvent("Bonus question level 2 play screen", "Button7 (submit) click")
  411.         })
  412.     }
  413. }(),
  414. function() {
  415.     "use strict";
  416.     $("#questionIntro-lvl-1, #questionIntro-lvl-2").length && (App.isMobileBreakpoint() && $("#questionIntro-visual-mobile").slickWrap(), $("#questionIntro-lvl-1 .question-link").on("click", function() {
  417.         App.trackEvent("Bonus question level 1 intro screen", "Button4 (let´s go) click")
  418.     }), $("#questionIntro-lvl-2 .question-link").on("click", function() {
  419.         App.trackEvent("Bonus question level 2 intro screen", "Button6 (let´s go) click")
  420.     }))
  421. }(),
  422. function() {
  423.     "use strict";
  424.     $("#registration-form").on("submit", function(o) {
  425.         $("#registration-terms").prop("checked") || ($("#terms-row").addClass("has-error"), o.preventDefault())
  426.     })
  427. }(),
  428. function() {
  429.     "use strict";
  430.     if ($("#view-success").length) {
  431.         $("#success-facebook-link, #success-twitter-link").on("click", function(o) {
  432.             o.preventDefault();
  433.             var e = window.open($(this).attr("href"), "", "scrollbars=1,width=684,height=450");
  434.             window.focus && e.focus()
  435.         });
  436.         var o = navigator.userAgent.match(/Android|iPhone/i) && !navigator.userAgent.match(/iPod|iPad/i) ? !0 : !1;
  437.         o || $("#success-whatsapp").hide(), $("#success-replay_button").on("click", function() {
  438.             App.trackEvent("Threshold score achieved", "Button9 (submit) click")
  439.         })
  440.     }
  441. }(),
  442. function() {
  443.     "use strict";
  444.     $("#successTreshold-replay_button").on("click", function() {
  445.         App.trackEvent("Threshold score failed", "Button8 (play again) click")
  446.     })
  447. }(),
  448. function() {
  449.     "use strict";
  450.     $("#view-win").length && $('#win-text a[href*="lenovo.com"]').on("click", function() {
  451.         App.trackEvent("Win Screen", "Textlink (lenovo) click")
  452.     })
  453. }();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement