Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. r.thebutton = {
  2.     _setTimer: function (e) {
  3.         var t = "00000", n = (e > 0 ? e : 0).toString(), i = t.substring(0, t.length - n.length) + n;
  4.         for (var s = 0; s < 4; s++)r.thebutton._timerTextNodes[s].nodeValue = i[s];
  5.         e % 100 === 0 && r.thebutton._drawPie(e, 6e4)
  6.     }, _countdown: function () {
  7.         r.thebutton._setTimer(r.thebutton._msLeft), r.thebutton._msLeft = Math.max(0, r.thebutton._msLeft - 10)
  8.     }, init: function () {
  9.         if ($("#thebutton").length === 0)return;
  10.         this._chart = new google.visualization.PieChart($(".thebutton-pie").get(0)), this._msLeft = 0, this._msgSecondsLeft = 0, this._tickTime = "", this._tickMac = "", this._lastMsLeft = Infinity, this._timerTextNodes = [$("#thebutton-s-10s").get(0).childNodes[0], $("#thebutton-s-1s").get(0).childNodes[0], $("#thebutton-s-100ms").get(0).childNodes[0], $("#thebutton-s-10ms").get(0).childNodes[0]], r.debug("in r.thebutton.init()"), this._started = !1, r.config.thebutton_websocket ? (r.debug("got thebutton_websocket"), this._websocket = new r.WebSocket(r.config.thebutton_websocket), this._websocket.on({
  11.             "message:expired": this._onExpired,
  12.             "message:not_started": this._onNotStarted,
  13.             "message:just_expired": this._onJustExpired,
  14.             "message:ticking": this._onTicking
  15.         }, this), this._websocket.start()) : r.debug("didn't get thebutton_websocket");
  16.         var e = $("#thebutton").parent();
  17.         e.on("click", function (e) {
  18.             var t = $(this);
  19.             t.is(".active.locked") && (t.addClass("unlocking").removeClass("locked"), setTimeout(function () {
  20.                 t.removeClass("unlocking").addClass("unlocked")
  21.             }, 300))
  22.         }), $("#thebutton").on("click", function (t) {
  23.             t.preventDefault(), t.stopPropagation();
  24.             if (e.hasClass("pressed"))return;
  25.             r.thebutton._countdownInterval = window.clearInterval(r.thebutton._countdownInterval), r.thebutton._setTimer(6e4);
  26.             var n = {
  27.                 seconds: $("#thebutton-timer").val(),
  28.                 prev_seconds: r.thebutton._msgSecondsLeft,
  29.                 tick_time: r.thebutton._tickTime,
  30.                 tick_mac: r.thebutton._tickMac
  31.             };
  32.             $.request("press_button", n, function (e) {
  33.                 console.log(e)
  34.             }), e.addClass("pressed").removeClass("unlocked"), r.thebutton.pulse()
  35.         })
  36.     }, _drawPie: function (e, t) {
  37.         var n = t - e, r = google.visualization.arrayToDataTable([["", ""], ["gone", n], ["remaining", e]]), i = {
  38.             chartArea: {
  39.                 top: 0,
  40.                 left: 0,
  41.                 width: 70,
  42.                 height: 70
  43.             },
  44.             pieSliceBorderColor: "transparent",
  45.             legend: "none",
  46.             pieSliceText: "none",
  47.             slices: {0: {color: "#C8C8C8"}, 1: {color: "#4A4A4A"}},
  48.             enableInteractivity: !1
  49.         };
  50.         this._chart.draw(r, i)
  51.     }, _onExpired: function (e) {
  52.         var t = e.seconds_elapsed;
  53.         r.debug("timer expired " + t + " ago"), $(".thebutton-wrap").removeClass("active").addClass("complete"), r.thebutton._countdownInterval = window.clearInterval(r.thebutton._countdownInterval), r.thebutton._setTimer(0)
  54.     }, _onNotStarted: function (e) {
  55.         r.debug("timer hasn't started")
  56.     }, _onJustExpired: function (e) {
  57.         r.debug("timer just expired"), $(".thebutton-wrap").removeClass("active").addClass("complete"), $el = $("#thebutton").parent(), $el.removeClass("unlocked locked logged-out pressed too-new not-active").addClass("denied has-expired")
  58.     }, _onTicking: function (e) {
  59.         if (!r.thebutton._started) {
  60.             var t = $("#thebutton").parent();
  61.             t.is(".not-active, .locked") && t.removeClass("denied not-active").addClass("active locked"), r.thebutton._started = !0, r.thebutton._countdownInterval = window.setInterval(r.thebutton._countdown, 10)
  62.         }
  63.         var n = e.seconds_left;
  64.         this._tickTime = e.now_str, this._msgSecondsLeft = n, this._tickMac = e.tick_mac;
  65.         var i = e.participants_text, s = n * 1e3;
  66.         s > r.thebutton._lastMsLeft && this.pulse2(), r.thebutton._lastMsLeft = s, r.thebutton._msLeft = n * 1e3, r.thebutton._countdownInterval || (this._countdownInterval = window.setInterval(r.thebutton._countdown, 10)), r.debug(n + " seconds remaining"), r.debug(i + " users have pushed the button"), $("#thebutton-timer").val(parseInt(e.seconds_left, 10)), $(".thebutton-participants").text(e.participants_text)
  67.     }, pulse: function () {
  68.         $els = $(".thebutton-container, .thebutton-pie-container"), $els.removeClass("pulse pulse2"), setTimeout(function () {
  69.             $els.addClass("pulse")
  70.         }, 1)
  71.     }, pulse2: function () {
  72.         var e = $(".thebutton-pie-container"), t = this;
  73.         e.removeClass("pulse pulse2"), setTimeout(function () {
  74.             e.addClass("pulse2")
  75.         }, 1)
  76.     }, _testState: function (e, t) {
  77.         t = t || 6e4, $el = $("#thebutton").parent();
  78.         var n = "denied logged-out too-new has-expired pressed locked unlocked";
  79.         $el.removeClass(n), r.thebutton._msLeft = t, r.thebutton.pulse();
  80.         switch (e) {
  81.             case"logged-out":
  82.                 $el.addClass("denied logged-out");
  83.                 break;
  84.             case"too-new":
  85.                 $el.addClass("denied too-new");
  86.                 break;
  87.             case"has-expired":
  88.                 $el.addClass("denied has-expired");
  89.                 break;
  90.             case"pressed":
  91.                 $el.addClass("pressed");
  92.                 break;
  93.             case"unlocked":
  94.                 $el.addClass("unlocked");
  95.                 break;
  96.             case"locked":
  97.             default:
  98.                 $el.addClass("locked")
  99.         }
  100.     }
  101. }, $(function () {
  102.     r.thebutton.init()
  103. })
  104. }catch
  105. (err)
  106. {
  107.     r.sendError("Error running module", "reddit.js", ":", err)
  108. }
  109. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement