Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.33 KB | None | 0 0
  1. jQuery(function(e) {
  2. function a() {
  3. function a() {
  4. var a = "metric" == e(".tdee-macro-calc input[name='system']:checked").val() ? 2.2 * p.val() : p.val();
  5. if ("cut" == o.find("option:selected").val()) {
  6. e(".tdee-macro-calc input[value='deficit']").prop("checked", !0), e(".tdee-macro-calc input[name='def-surp-percentage']").val("-20%").removeClass("surplus").addClass("deficit");
  7. var c = {};
  8. c.protein = 40, c.carbs = 40, c.fat = 20
  9. } else if ("maintain" == o.find("option:selected").val() || "bulk" == o.find("option:selected").val()) {
  10. "maintain" == o.find("option:selected").val() ? (e(".tdee-macro-calc input[value='deficit']").prop("checked", !0), e(".tdee-macro-calc input[name='def-surp-percentage']").val("0%").removeClass("surplus deficit")) : (e(".tdee-macro-calc input[value='surplus']").prop("checked", !0), e(".tdee-macro-calc input[name='def-surp-percentage']").val("+10%").removeClass("deficit").addClass("surplus"));
  11. var l = 1 * a * 4,
  12. r = l / i * 100,
  13. s = .3 * a * 9,
  14. d = s / i * 100,
  15. u = i - (s + l),
  16. v = u / i * 100,
  17. c = {};
  18. c.protein = r, c.carbs = v, c.fat = d
  19. }
  20. if (!a || "none" == o.find("option:selected").val()) {
  21. var c = {};
  22. c.protein = 40, c.carbs = 40, c.fat = 20
  23. }
  24. e(h).each(function() {
  25. e(this).slider("value", c[e(this).data("type")]), n && e(this).slider("option", "max", 100)
  26. }), n = !1, t()
  27. }
  28.  
  29. function t() {
  30. var a = .01 * parseInt(Math.abs(e(".tdee-macro-calc input[name='def-surp-percentage']").val().replace("%", "")));
  31. "surplus" == e(".tdee-macro-calc input[name='def-surp']:checked").val() ? (i = Math.round(Number(d.val()) + Number(d.val() * a)), u.html(i)) : (i = Math.round(Number(d.val()) - Number(d.val() * a)), u.html(i))
  32. }
  33.  
  34. function c() {
  35. i && e(h).each(function() {
  36. var a = e(".tdee-macro-calc ." + e(this).attr("data-type") + "-perc input"),
  37. t = e(".tdee-macro-calc ." + e(this).attr("data-type") + "-grams input"),
  38. c = e(".tdee-macro-calc ." + e(this).attr("data-type") + "-calories"),
  39. l = e(this).slider("value"),
  40. r = .01 * l * i,
  41. n = r / e(this).data("cals");
  42. a.val(Math.round(l) + "%"), t.val(Math.round(n) + "g"), c.html(Math.round(r) + " kcal")
  43. })
  44. }
  45.  
  46. function l(a, t) {
  47. if (e(this).data("current-value", t.value), "protein" !== e(this).data("type")) {
  48. var c = v.slider("value");
  49. e(this).data("max-value", 100 - c)
  50. } else e(this).data("max-value", 100)
  51. }
  52.  
  53. function r(a, t) {
  54. if (a.originalEvent) {
  55. if (t.value > e(this).data("max-value")) return void a.preventDefault();
  56. o.find("option[value='none']").prop("selected", !0); {
  57. e(this).slider("value") < t.value ? !0 : !1, Math.abs(e(this).slider("value") - t.value)
  58. }
  59. if (e(this).slider("value", t.value), "protein" == e(this).attr("data-type")) {
  60. var l = v.slider("value"),
  61. r = 100 - l;
  62. f.slider("value", .3 * r), m.slider("value", .7 * r)
  63. }
  64. if ("carbs" == e(this).attr("data-type")) {
  65. var i = t.value,
  66. l = v.slider("value"),
  67. n = 100 - (i + l);
  68. f.slider("value", n)
  69. }
  70. if ("fat" == e(this).attr("data-type")) {
  71. var s = t.value,
  72. l = v.slider("value"),
  73. n = 100 - (s + l);
  74. m.slider("value", n)
  75. }
  76. c()
  77. }
  78. }
  79.  
  80. function s() {
  81. var a = e(".tdee-macro-calc input[name='def-surp-percentage']"),
  82. t = a.val().replace("%", "");
  83. /\-|\+/i.test(t) || (t = "surplus" == e(".tdee-macro-calc input[name='def-surp']:checked").val() ? "+" + t : "-" + t), t > 0 ? e(".tdee-macro-calc input[value='surplus']").prop("checked", !0) : 0 > t && e(".tdee-macro-calc input[value='deficit']").prop("checked", !0), t = t.replace("-", ""), t = t.replace("+", ""), t ? (a.val(""), "0" == t ? a.val(t + "%").removeClass("deficit surplus") : "surplus" == e(".tdee-macro-calc input[name='def-surp']:checked").val() ? a.val("+" + t + "%").removeClass("deficit").addClass("surplus") : a.val("-" + t + "%").removeClass("surplus").addClass("deficit")) : a.removeClass("deficit surplus")
  84. }
  85. var d = e(".tdee-macro-calc #tdee"),
  86. u = e(".tdee-macro-calc #cals-left"),
  87. o = e(".tdee-macro-calc #presets"),
  88. p = e(".tdee-macro-calc #body-weight");
  89. t();
  90. var v = e(".tdee-macro-calc .protein-slider").slider({
  91. max: 0,
  92. value: 0,
  93. step: .001,
  94. range: "min",
  95. min: 0,
  96. change: r,
  97. slide: r,
  98. start: l
  99. }),
  100. m = e(".tdee-macro-calc .carbs-slider").slider({
  101. max: 0,
  102. value: 0,
  103. step: .001,
  104. range: "min",
  105. change: r,
  106. slide: r,
  107. start: l
  108. }),
  109. f = e(".tdee-macro-calc .fat-slider").slider({
  110. max: 0,
  111. value: 0,
  112. step: .001,
  113. range: "min",
  114. min: 0,
  115. change: r,
  116. slide: r,
  117. start: l
  118. }),
  119. h = [v, m, f];
  120. e(".tdee-macro-calc input[name='body-weight'], .tdee-macro-calc select[name='presets'], .tdee-macro-calc input[name='def-surp-percentage']").on("change", function(l) {
  121. d.val() && p.val() && e(".tdee-macro-calc input[name='def-surp-percentage']").val() && ((e(l.target).is(".tdee-macro-calc input[name='def-surp-percentage']") || e(l.target).is(".tdee-macro-calc input[type='radio']")) && o.find("option[value='none']").prop("selected", !0), s(), t(), a(), c())
  122. }).on("input", function(l) {
  123. if (d.val() && p.val() && "" !== e(".tdee-macro-calc input[name='def-surp-percentage']").val()) {
  124. if ((e(l.target).is(".tdee-macro-calc input[name='def-surp-percentage']") || e(l.target).is(".tdee-macro-calc input[type='radio']")) && o.find("option[value='none']").prop("selected", !0), e(l.target).is(".tdee-macro-calc input[name='def-surp-percentage']")) return;
  125. s(), t(), a(), c()
  126. }
  127. }), e(".tdee-macro-calc input[name='tdee']").on("change input", function() {
  128. d.val() && p.val() && e(".tdee-macro-calc input[name='def-surp-percentage']").val() && (s(), t(), a(), c())
  129. }), e(".tdee-macro-calc .perc-input").on("input", function(a) {
  130. if (a.originalEvent) {
  131. a.originalEvent && o.find("option[value='none']").prop("selected", !0);
  132. var t = parseInt(e(this).val().replace("%", ""));
  133. if ("protein" !== e(this).data("type")) {
  134. var l = v.slider("value"),
  135. r = 100 - l;
  136. if (t > r && (t = r, e(this).val(t)), "carbs" == e(this).data("type")) {
  137. m.slider("value", t);
  138. var i = t,
  139. n = v.slider("value"),
  140. s = 100 - (i + n);
  141. f.slider("value", s)
  142. } else {
  143. f.slider("value", t);
  144. var d = t,
  145. n = v.slider("value"),
  146. s = 100 - (d + n);
  147. m.slider("value", s)
  148. }
  149. } else {
  150. v.slider("value", t);
  151. var n = v.slider("value"),
  152. u = 100 - n;
  153. m.slider("value", .7 * u), f.slider("value", .3 * u)
  154. }
  155. c()
  156. }
  157. }).blur(function() {
  158. var a = parseInt(e(this).val());
  159. e(this).val(a + "%")
  160. }), e(".tdee-macro-calc .gram-input").on("keypress change", function(a) {
  161. if (console.log(e(this).val()), a.originalEvent && o.find("option[value='none']").prop("selected", !0), ("keypress" != a.type || 13 === a.which) && a.originalEvent) {
  162. var t = parseInt(e(this).val().replace("g", ""));
  163. if (!(t < e(this).data("cals"))) {
  164. var l = t * e(this).data("cals"),
  165. r = l / i * 100;
  166. if ("protein" !== e(this).data("type")) {
  167. var n = .01 * v.slider("value") * i,
  168. s = i - n,
  169. d = "carbs" == e(this).data("type") ? s / 4 : s / 9;
  170. if (t > d && (t = d, l = t * e(this).data("cals"), r = l / i * 100, e(this).val(t)), "carbs" == e(this).data("type")) {
  171. m.slider("value", r);
  172. var u = v.slider("value"),
  173. p = 100 - (r + u);
  174. f.slider("value", p)
  175. } else {
  176. f.slider("value", r);
  177. var u = v.slider("value"),
  178. p = 100 - (r + u);
  179. m.slider("value", p)
  180. }
  181. } else {
  182. v.slider("value", r);
  183. var h = 100 - r;
  184. f.slider("value", .3 * h), m.slider("value", .7 * h)
  185. }
  186. c()
  187. }
  188. }
  189. }).blur(function() {
  190. var a = parseInt(e(this).val());
  191. e(this).val(a + "g")
  192. }), e(".tdee-macro-calc input[type='text'], .tdee-macro-calc input[type='number']").on("click", function(a) {
  193. a.originalEvent && e(this).select()
  194. }), e(".tdee-macro-calc input[name='def-surp']").on("change", function(l) {
  195. l.originalEvent && o.find("option[value='none']").prop("selected", !0), e(".tdee-macro-calc input[name='def-surp-percentage']").val("surplus" == e(".tdee-macro-calc input[name='def-surp']:checked").val() ? e(".tdee-macro-calc input[name='def-surp-percentage']").val().replace("-", "+") : e(".tdee-macro-calc input[name='def-surp-percentage']").val().replace("+", "-")), s(), t(), a(), c()
  196. })
  197. }
  198.  
  199. function t(e, a, t) {
  200. var c, l = .01 * a;
  201. return c = "metric" == t ? 2.2 * (1 - l) * e : (1 - l) * e
  202. }
  203.  
  204. function c(e) {
  205. var a = e / 2.2,
  206. t = 370 + 21.6 * a;
  207. return t
  208. }
  209.  
  210. function l() {
  211. var a = e(".tdee-macro-calc input[name='body-weight']").val(),
  212. l = e(".tdee-macro-calc input[name='body-fat']").val();
  213. if (a && l) {
  214. var r, i, n, s = e(".tdee-macro-calc select[name='activity-level']").val(),
  215. d = e(".tdee-macro-calc #custom-multiplier").val(),
  216. u = e(".tdee-macro-calc input[name='system']:checked").val();
  217. d && (s = d), n = t(a, l, u), r = c(n), i = r * s;
  218. var o = "metric" == e(".tdee-macro-calc input[name='system']:checked").val() ? n / 2.2 : n;
  219. return {
  220. lbm: ~~o,
  221. tdee: ~~i,
  222. bmr: ~~r
  223. }
  224. }
  225. }
  226.  
  227. function r(a) {
  228. a && e(a.target).is(".tdee-macro-calc #activity-level") && (console.log("VAL"), e(".tdee-macro-calc #custom-multiplier").val(e(".tdee-macro-calc #activity-level").val()));
  229. var t = l();
  230. if (t) {
  231. var c = "metric" == e(".tdee-macro-calc input[name='system']:checked").val() ? "kgs." : "lbs.";
  232. e(".tdee-macro-calc .lbm-result").html(t.lbm + " <em>" + c + "</em>"), e(".tdee-macro-calc .bmr-result").html(t.bmr + ""), e(".tdee-macro-calc .tdee-result").html(t.tdee + " <em>calories per day</em>"), e(".tdee-macro-calc #tdee").val(t.tdee), e(".tdee-macro-calc #tdee").trigger("input")
  233. }
  234. }
  235. var i, n = !0;
  236. a(), e(".tdee-macro-calc input[type='number'], .tdee-macro-calc select[name='activity-level']").on("input change keypress keyup", r), e(".tdee-macro-calc input[name='system']").on("change", function() {
  237. "metric" == e(".tdee-macro-calc input[name='system']:checked").val() ? (e(".tdee-macro-calc span.measurement-system").html("(kgs.)"), e(".tdee-macro-calc input[name='body-weight']").val(Math.round(e(".tdee-macro-calc input[name='body-weight']").val() / 2.2))) : (e(".tdee-macro-calc span.measurement-system").html("(lbs.)"), e(".tdee-macro-calc input[name='body-weight']").val(Math.round(2.2 * e(".tdee-macro-calc input[name='body-weight']").val()))), r()
  238. }), e(".tdee-macro-calc #custom-multiplier").on("input", function(a) {
  239. a.originalEvent && e(".tdee-macro-calc #activity-level option[value='1']").prop("selected", !0)
  240. }), r()
  241. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement