Advertisement
Guest User

Untitled

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