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.

164 lines
4.5 KiB

  1. /*! UIkit 2.3.1 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
  2. (function($, UI){
  3. var containers = {},
  4. messages = {},
  5. notify = function(options){
  6. if ($.type(options) == 'string') {
  7. options = { message: options };
  8. }
  9. if (arguments[1]) {
  10. options = $.extend(options, $.type(arguments[1]) == 'string' ? {status:arguments[1]} : arguments[1]);
  11. }
  12. return (new Message(options)).show();
  13. },
  14. closeAll = function(group, instantly){
  15. if(group) {
  16. for(var id in messages) { if(group===messages[id].group) messages[id].close(instantly); }
  17. } else {
  18. for(var id in messages) { messages[id].close(instantly); }
  19. }
  20. };
  21. var Message = function(options){
  22. var $this = this;
  23. this.options = $.extend({}, Message.defaults, options);
  24. this.uuid = "ID"+(new Date().getTime())+"RAND"+(Math.ceil(Math.random() * 100000));
  25. this.element = $([
  26. '<div class="uk-notify-message">',
  27. '<a class="uk-close"></a>',
  28. '<div>'+this.options.message+'</div>',
  29. '</div>'
  30. ].join('')).data("notifyMessage", this);
  31. // status
  32. if (this.options.status) {
  33. this.element.addClass('uk-notify-message-'+this.options.status);
  34. this.currentstatus = this.options.status;
  35. }
  36. this.group = this.options.group;
  37. messages[this.uuid] = this;
  38. if(!containers[this.options.pos]) {
  39. containers[this.options.pos] = $('<div class="uk-notify uk-notify-'+this.options.pos+'"></div>').appendTo('body').on("click", ".uk-notify-message", function(){
  40. $(this).data("notifyMessage").close();
  41. });
  42. }
  43. };
  44. $.extend(Message.prototype, {
  45. uuid: false,
  46. element: false,
  47. timout: false,
  48. currentstatus: "",
  49. group: false,
  50. show: function() {
  51. if (this.element.is(":visible")) return;
  52. var $this = this;
  53. containers[this.options.pos].show().prepend(this.element);
  54. var marginbottom = parseInt(this.element.css("margin-bottom"), 10);
  55. this.element.css({"opacity":0, "margin-top": -1*this.element.outerHeight(), "margin-bottom":0}).animate({"opacity":1, "margin-top": 0, "margin-bottom":marginbottom}, function(){
  56. if ($this.options.timeout) {
  57. var closefn = function(){ $this.close(); };
  58. $this.timeout = setTimeout(closefn, $this.options.timeout);
  59. $this.element.hover(
  60. function() { clearTimeout($this.timeout); },
  61. function() { $this.timeout = setTimeout(closefn, $this.options.timeout); }
  62. );
  63. }
  64. });
  65. return this;
  66. },
  67. close: function(instantly) {
  68. var $this = this,
  69. finalize = function(){
  70. $this.element.remove();
  71. if(!containers[$this.options.pos].children().length) {
  72. containers[$this.options.pos].hide();
  73. }
  74. delete messages[$this.uuid];
  75. };
  76. if(this.timeout) clearTimeout(this.timeout);
  77. if(instantly) {
  78. finalize();
  79. } else {
  80. this.element.animate({"opacity":0, "margin-top": -1* this.element.outerHeight(), "margin-bottom":0}, function(){
  81. finalize();
  82. });
  83. }
  84. },
  85. content: function(html){
  86. var container = this.element.find(">div");
  87. if(!html) {
  88. return container.html();
  89. }
  90. container.html(html);
  91. return this;
  92. },
  93. status: function(status) {
  94. if(!status) {
  95. return this.currentstatus;
  96. }
  97. this.element.removeClass('uk-notify-message-'+this.currentstatus).addClass('uk-notify-message-'+status);
  98. this.currentstatus = status;
  99. return this;
  100. }
  101. });
  102. Message.defaults = {
  103. message: "",
  104. status: "",
  105. timeout: 5000,
  106. group: null,
  107. pos: 'top-center'
  108. };
  109. UI["notify"] = notify;
  110. UI["notify"].message = Message;
  111. UI["notify"].closeAll = closeAll;
  112. })(jQuery, jQuery.UIkit);