A Twitch.tv viewer reward and games system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
33 KiB

  1. /*! UIkit 2.3.1 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
  2. (function(global, $, UI){
  3. // Datepicker
  4. var active = false,
  5. dropdown = $('<div class="uk-dropdown uk-datepicker"></div>');
  6. dropdown.on("click", ".uk-datepicker-next, .uk-datepicker-previous, [data-date]", function(e){
  7. e.stopPropagation();
  8. e.preventDefault();
  9. var ele = $(this);
  10. if(ele.is('[data-date]')) {
  11. active.element.val(moment(ele.data("date")).format(active.options.format)).trigger("change");
  12. dropdown.hide();
  13. active = false;
  14. } else {
  15. active.add("months", 1 * (ele.hasClass("uk-datepicker-next") ? 1:-1));
  16. }
  17. });
  18. var DatePicker = function(element, options) {
  19. var $this = this, $element = $(element);
  20. if($element.data("datepicker")) return;
  21. this.element = $element;
  22. this.options = $.extend({}, DatePicker.defaults, options);
  23. this.current = this.element.val() ? moment(this.element.val(), this.options.format) : moment();
  24. this.element.on("click", function(){
  25. if(active!==$this) $this.pick(this.value);
  26. }).on("change", function(){
  27. if($this.element.val() && !moment($this.element.val(), $this.options.format).isValid()) {
  28. $this.element.val(moment().format($this.options.format));
  29. }
  30. });
  31. this.element.data("datepicker", this);
  32. };
  33. DatePicker.defaults = {
  34. weekstart: 1,
  35. i18n: {
  36. months : ['January','February','March','April','May','June','July','August','September','October','November','December'],
  37. weekdays : ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
  38. },
  39. format: "DD.MM.YYYY",
  40. offsettop: 5,
  41. template: function(data, opts) {
  42. var content = '';
  43. content += '<div class="uk-datepicker-nav">';
  44. content += '<a href="" class="uk-datepicker-previous"></a>';
  45. content += '<a href="" class="uk-datepicker-next"></a>';
  46. content += '<div class="uk-datepicker-heading">'+ opts.i18n.months[data.month] +' '+ data.year+'</div>';
  47. content += '</div>';
  48. content += '<table class="uk-datepicker-table">';
  49. content += '<thead>';
  50. for(var i = 0; i < data.weekdays.length; i++) {
  51. if (data.weekdays[i]) {
  52. content += '<th>'+data.weekdays[i]+'</th>';
  53. }
  54. }
  55. content += '</thead>';
  56. content += '<tbody>';
  57. for(var i = 0; i < data.days.length; i++) {
  58. if (data.days[i] && data.days[i].length){
  59. content += '<tr>';
  60. for(var d = 0; d < data.days[i].length; d++) {
  61. if (data.days[i][d]) {
  62. var day = data.days[i][d],
  63. cls = [];
  64. if(!day.inmonth) cls.push("uk-datepicker-table-muted");
  65. if(day.selected) cls.push("uk-active");
  66. content += '<td><a href="" class="'+cls.join(" ")+'" data-date="'+day.day.format()+'">'+day.day.format("D")+'</a></td>';
  67. }
  68. }
  69. content += '</tr>';
  70. }
  71. }
  72. content += '</tbody>';
  73. content += '</table>';
  74. return content;
  75. }
  76. };
  77. $.extend(DatePicker.prototype, {
  78. pick: function(initdate) {
  79. var offset = this.element.offset(),
  80. css = {"top": offset.top + this.element.outerHeight() + this.options.offsettop, "left": offset.left, "right":""};
  81. this.current = initdate ? moment(initdate, this.options.format):moment();
  82. this.initdate = this.current.format("YYYY-MM-DD");
  83. this.update();
  84. if ($.UIkit.langdirection == 'right') {
  85. css.right = window.innerWidth - (css.left + this.element.outerWidth());
  86. css.left = "";
  87. }
  88. dropdown.css(css).show();
  89. active = this;
  90. },
  91. add: function(unit, value) {
  92. this.current.add(unit, value);
  93. this.update();
  94. },
  95. setMonth: function(month) {
  96. this.current.month(month);
  97. this.update();
  98. },
  99. setYear: function(year) {
  100. this.current.year(year);
  101. this.update();
  102. },
  103. update: function() {
  104. var data = this.getRows(this.current.year(), this.current.month()),
  105. tpl = this.options.template(data, this.options);
  106. dropdown.html(tpl);
  107. },
  108. getRows: function(year, month) {
  109. var opts = this.options,
  110. now = moment().format('YYYY-MM-DD'),
  111. days = [31, (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month],
  112. before = new Date(year, month, 1).getDay(),
  113. data = {"month":month, "year":year,"weekdays":[],"days":[]},
  114. row = [];
  115. data.weekdays = (function(){
  116. for (var i=0, arr=[]; i < 7; i++) {
  117. var day = i + (opts.weekstart || 0);
  118. while (day >= 7) {
  119. day -= 7;
  120. }
  121. arr.push(opts.i18n.weekdays[day]);
  122. }
  123. return arr;
  124. })();
  125. if (opts.weekstart && opts.weekstart > 0) {
  126. before -= opts.weekstart;
  127. if (before < 0) {
  128. before += 7;
  129. }
  130. }
  131. var cells = days + before, after = cells;
  132. while(after > 7) { after -= 7; }
  133. cells += 7 - after;
  134. var day, isDisabled, isSelected, isToday, isInMonth;
  135. for (var i = 0, r = 0; i < cells; i++) {
  136. day = new Date(year, month, 1 + (i - before));
  137. isDisabled = (opts.mindate && day < opts.mindate) || (opts.maxdate && day > opts.maxdate);
  138. isInMonth = !(i < before || i >= (days + before));
  139. day = moment(day);
  140. isSelected = this.initdate == day.format("YYYY-MM-DD");
  141. isToday = now == day.format("YYYY-MM-DD");
  142. row.push({"selected": isSelected, "today": isToday, "disabled": isDisabled, "day":day, "inmonth":isInMonth});
  143. if (++r === 7) {
  144. data.days.push(row);
  145. row = [];
  146. r = 0;
  147. }
  148. }
  149. return data;
  150. }
  151. });
  152. UI["datepicker"] = DatePicker;
  153. // init code
  154. $(document).on("focus.datepicker.uikit", "[data-uk-datepicker]", function(e) {
  155. var ele = $(this);
  156. if (!ele.data("datepicker")) {
  157. e.preventDefault();
  158. var obj = new DatePicker(ele, UI.Utils.options(ele.attr("data-uk-datepicker")));
  159. ele.trigger("focus");
  160. }
  161. });
  162. $(document).on("click.datepicker.uikit", function(e) {
  163. var target = $(e.target);
  164. if (active && target[0] != dropdown[0] && !target.data("datepicker") && !target.parents(".uk-datepicker:first").length) {
  165. dropdown.hide();
  166. active = false;
  167. }
  168. });
  169. $(function(){
  170. dropdown.appendTo("body");
  171. });
  172. })(this, jQuery, jQuery.UIkit);
  173. if(!window.moment) {
  174. //! moment.js
  175. //! version : 2.5.1
  176. //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
  177. //! license : MIT
  178. //! momentjs.com
  179. (function(a){function b(){return{empty:!1,unusedTokens:[],unusedInput:[],overflow:-2,charsLeftOver:0,nullInput:!1,invalidMonth:null,invalidFormat:!1,userInvalidated:!1,iso:!1}}function c(a,b){return function(c){return k(a.call(this,c),b)}}function d(a,b){return function(c){return this.lang().ordinal(a.call(this,c),b)}}function e(){}function f(a){w(a),h(this,a)}function g(a){var b=q(a),c=b.year||0,d=b.month||0,e=b.week||0,f=b.day||0,g=b.hour||0,h=b.minute||0,i=b.second||0,j=b.millisecond||0;this._milliseconds=+j+1e3*i+6e4*h+36e5*g,this._days=+f+7*e,this._months=+d+12*c,this._data={},this._bubble()}function h(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return b.hasOwnProperty("toString")&&(a.toString=b.toString),b.hasOwnProperty("valueOf")&&(a.valueOf=b.valueOf),a}function i(a){var b,c={};for(b in a)a.hasOwnProperty(b)&&qb.hasOwnProperty(b)&&(c[b]=a[b]);return c}function j(a){return 0>a?Math.ceil(a):Math.floor(a)}function k(a,b,c){for(var d=""+Math.abs(a),e=a>=0;d.length<b;)d="0"+d;return(e?c?"+":"":"-")+d}function l(a,b,c,d){var e,f,g=b._milliseconds,h=b._days,i=b._months;g&&a._d.setTime(+a._d+g*c),(h||i)&&(e=a.minute(),f=a.hour()),h&&a.date(a.date()+h*c),i&&a.month(a.month()+i*c),g&&!d&&db.updateOffset(a),(h||i)&&(a.minute(e),a.hour(f))}function m(a){return"[object Array]"===Object.prototype.toString.call(a)}function n(a){return"[object Date]"===Object.prototype.toString.call(a)||a instanceof Date}function o(a,b,c){var d,e=Math.min(a.length,b.length),f=Math.abs(a.length-b.length),g=0;for(d=0;e>d;d++)(c&&a[d]!==b[d]||!c&&s(a[d])!==s(b[d]))&&g++;return g+f}function p(a){if(a){var b=a.toLowerCase().replace(/(.)s$/,"$1");a=Tb[a]||Ub[b]||b}return a}function q(a){var b,c,d={};for(c in a)a.hasOwnProperty(c)&&(b=p(c),b&&(d[b]=a[c]));return d}function r(b){var c,d;if(0===b.indexOf("week"))c=7,d="day";else{if(0!==b.indexOf("month"))return;c=12,d="month"}db[b]=function(e,f){var g,h,i=db.fn._lang[b],j=[];if("number"==typeof e&&(f=e,e=a),h=function(a){var b=db().utc().set(d,a);return i.call(db.fn._lang,b,e||"")},null!=f)return h(f);for(g=0;c>g;g++)j.push(h(g));return j}}function s(a){var b=+a,c=0;return 0!==b&&isFinite(b)&&(c=b>=0?Math.floor(b):Math.ceil(b)),c}function t(a,b){return new Date(Date.UTC(a,b+1,0)).getUTCDate()}function u(a){return v(a)?366:365}function v(a){return a%4===0&&a%100!==0||a%400===0}function w(a){var b;a._a&&-2===a._pf.overflow&&(b=a._a[jb]<0||a._a[jb]>11?jb:a._a[kb]<1||a._a[kb]>t(a._a[ib],a._a[jb])?kb:a._a[lb]<0||a._a[lb]>23?lb:a._a[mb]<0||a._a[mb]>59?mb:a._a[nb]<0||a._a[nb]>59?nb:a._a[ob]<0||a._a[ob]>999?ob:-1,a._pf._overflowDayOfYear&&(ib>b||b>kb)&&(b=kb),a._pf.overflow=b)}function x(a){return null==a._isValid&&(a._isValid=!isNaN(a._d.getTime())&&a._pf.overflow<0&&!a._pf.empty&&!a._pf.invalidMonth&&!a._pf.nullInput&&!a._pf.invalidFormat&&!a._pf.userInvalidated,a._strict&&(a._isValid=a._isValid&&0===a._pf.charsLeftOver&&0===a._pf.unusedTokens.length)),a._isValid}function y(a){return a?a.toLowerCase().replace("_","-"):a}function z(a,b){return b._isUTC?db(a).zone(b._offset||0):db(a).local()}function A(a,b){return b.abbr=a,pb[a]||(pb[a]=new e),pb[a].set(b),pb[a]}function B(a){delete pb[a]}function C(a){var b,c,d,e,f=0,g=function(a){if(!pb[a]&&rb)try{require("./lang/"+a)}catch(b){}return pb[a]};if(!a)return db.fn._lang;if(!m(a)){if(c=g(a))return c;a=[a]}for(;f<a.length;){for(e=y(a[f]).split("-"),b=e.length,d=y(a[f+1]),d=d?d.split("-"):null;b>0;){if(c=g(e.slice(0,b).join("-")))return c;if(d&&d.length>=b&&o(e,d,!0)>=b-1)break;b--}f++}return db.fn._lang}function D(a){return a.match(/\[[\s\S]/)?a.replace(/^\[|\]$/g,""):a.replace(/\\/g,"")}function E(a){var b,c,d=a.match(vb);for(b=0,c=d.length;c>b;b++)d[b]=Yb[d[b]]?Yb[d[b]]:D(d[b]);return function(e){var f="";for(b=0;c>b;b++)f+=d[b]instanceof Function?d[b].call(e,a):d[b];return f}}function F(a,b){return a.isValid()?(b=G(b,a.lang()),Vb[b]||(Vb[b]=E(b)),Vb[b](a)):a.lang().invalidDate()}function G(a,b){function c(a){return b.longDateFormat(a)||a}var d=5;for(wb.lastIndex=0;d>=0&&wb.test(a);)a=a.replace(wb,c),wb.lastIndex=0,d-=1;return a}function H(a,b){var c,d=
  180. }