libraryJQueryGrowl

Hosted version of Kevin Sylvestre's growl library

ეს სკრიპტი არ უნდა იყოს პირდაპირ დაინსტალირებული. ეს ბიბლიოთეკაა, სხვა სკრიპტებისთვის უნდა ჩართეთ მეტა-დირექტივაში // @require https://update.greatest.deepsurf.us/scripts/40055/263233/libraryJQueryGrowl.js.

  1. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  2.  
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4.  
  5. // Generated by CoffeeScript 2.1.0
  6. (function () {
  7. /*
  8. jQuery Growl
  9. Copyright 2015 Kevin Sylvestre
  10. 1.3.5
  11. */
  12. "use strict";
  13.  
  14. var $, Animation, Growl;
  15.  
  16. $ = jQuery;
  17.  
  18. Animation = function () {
  19. var Animation = function () {
  20. function Animation() {
  21. _classCallCheck(this, Animation);
  22. }
  23.  
  24. _createClass(Animation, null, [{
  25. key: "transition",
  26. value: function transition($el) {
  27. var el, ref, result, type;
  28. el = $el[0];
  29. ref = this.transitions;
  30. for (type in ref) {
  31. result = ref[type];
  32. if (el.style[type] != null) {
  33. return result;
  34. }
  35. }
  36. }
  37. }]);
  38.  
  39. return Animation;
  40. }();
  41.  
  42. ;
  43.  
  44. Animation.transitions = {
  45. "webkitTransition": "webkitTransitionEnd",
  46. "mozTransition": "mozTransitionEnd",
  47. "oTransition": "oTransitionEnd",
  48. "transition": "transitionend"
  49. };
  50.  
  51. return Animation;
  52. }();
  53.  
  54. Growl = function () {
  55. var Growl = function () {
  56. _createClass(Growl, null, [{
  57. key: "growl",
  58. value: function growl() {
  59. var settings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  60.  
  61. return new Growl(settings);
  62. }
  63. }]);
  64.  
  65. function Growl() {
  66. var settings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  67.  
  68. _classCallCheck(this, Growl);
  69.  
  70. this.render = this.render.bind(this);
  71. this.bind = this.bind.bind(this);
  72. this.unbind = this.unbind.bind(this);
  73. this.mouseEnter = this.mouseEnter.bind(this);
  74. this.mouseLeave = this.mouseLeave.bind(this);
  75. this.click = this.click.bind(this);
  76. this.close = this.close.bind(this);
  77. this.cycle = this.cycle.bind(this);
  78. this.waitAndDismiss = this.waitAndDismiss.bind(this);
  79. this.present = this.present.bind(this);
  80. this.dismiss = this.dismiss.bind(this);
  81. this.remove = this.remove.bind(this);
  82. this.animate = this.animate.bind(this);
  83. this.$growls = this.$growls.bind(this);
  84. this.$growl = this.$growl.bind(this);
  85. this.html = this.html.bind(this);
  86. this.content = this.content.bind(this);
  87. this.container = this.container.bind(this);
  88. this.settings = $.extend({}, Growl.settings, settings);
  89. this.initialize(this.settings.location);
  90. this.render();
  91. }
  92.  
  93. _createClass(Growl, [{
  94. key: "initialize",
  95. value: function initialize(location) {
  96. var id;
  97. id = 'growls-' + location;
  98. return $('body:not(:has(#' + id + '))').append('<div id="' + id + '" />');
  99. }
  100. }, {
  101. key: "render",
  102. value: function render() {
  103. var $growl;
  104. $growl = this.$growl();
  105. this.$growls(this.settings.location).append($growl);
  106. if (this.settings.fixed) {
  107. this.present();
  108. } else {
  109. this.cycle();
  110. }
  111. }
  112. }, {
  113. key: "bind",
  114. value: function bind() {
  115. var $growl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.$growl();
  116.  
  117. $growl.on("click", this.click);
  118. if (this.settings.delayOnHover) {
  119. $growl.on("mouseenter", this.mouseEnter);
  120. $growl.on("mouseleave", this.mouseLeave);
  121. }
  122. return $growl.on("contextmenu", this.close).find("." + this.settings.namespace + "-close").on("click", this.close);
  123. }
  124. }, {
  125. key: "unbind",
  126. value: function unbind() {
  127. var $growl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.$growl();
  128.  
  129. $growl.off("click", this.click);
  130. if (this.settings.delayOnHover) {
  131. $growl.off("mouseenter", this.mouseEnter);
  132. $growl.off("mouseleave", this.mouseLeave);
  133. }
  134. return $growl.off("contextmenu", this.close).find("." + this.settings.namespace + "-close").off("click", this.close);
  135. }
  136. }, {
  137. key: "mouseEnter",
  138. value: function mouseEnter(event) {
  139. var $growl;
  140. $growl = this.$growl();
  141. return $growl.stop(true, true);
  142. }
  143. }, {
  144. key: "mouseLeave",
  145. value: function mouseLeave(event) {
  146. return this.waitAndDismiss();
  147. }
  148. }, {
  149. key: "click",
  150. value: function click(event) {
  151. if (this.settings.url != null) {
  152. event.preventDefault();
  153. event.stopPropagation();
  154. return window.open(this.settings.url);
  155. }
  156. }
  157. }, {
  158. key: "close",
  159. value: function close(event) {
  160. var $growl;
  161. event.preventDefault();
  162. event.stopPropagation();
  163. $growl = this.$growl();
  164. return $growl.stop().queue(this.dismiss).queue(this.remove);
  165. }
  166. }, {
  167. key: "cycle",
  168. value: function cycle() {
  169. var $growl;
  170. $growl = this.$growl();
  171. return $growl.queue(this.present).queue(this.waitAndDismiss());
  172. }
  173. }, {
  174. key: "waitAndDismiss",
  175. value: function waitAndDismiss() {
  176. var $growl;
  177. $growl = this.$growl();
  178. return $growl.delay(this.settings.duration).queue(this.dismiss).queue(this.remove);
  179. }
  180. }, {
  181. key: "present",
  182. value: function present(callback) {
  183. var $growl;
  184. $growl = this.$growl();
  185. this.bind($growl);
  186. return this.animate($growl, this.settings.namespace + "-incoming", 'out', callback);
  187. }
  188. }, {
  189. key: "dismiss",
  190. value: function dismiss(callback) {
  191. var $growl;
  192. $growl = this.$growl();
  193. this.unbind($growl);
  194. return this.animate($growl, this.settings.namespace + "-outgoing", 'in', callback);
  195. }
  196. }, {
  197. key: "remove",
  198. value: function remove(callback) {
  199. this.$growl().remove();
  200. return typeof callback === "function" ? callback() : void 0;
  201. }
  202. }, {
  203. key: "animate",
  204. value: function animate($element, name) {
  205. var direction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'in';
  206. var callback = arguments[3];
  207.  
  208. var transition;
  209. transition = Animation.transition($element);
  210. $element[direction === 'in' ? 'removeClass' : 'addClass'](name);
  211. $element.offset().position;
  212. $element[direction === 'in' ? 'addClass' : 'removeClass'](name);
  213. if (callback == null) {
  214. return;
  215. }
  216. if (transition != null) {
  217. $element.one(transition, callback);
  218. } else {
  219. callback();
  220. }
  221. }
  222. }, {
  223. key: "$growls",
  224. value: function $growls(location) {
  225. var base;
  226. if (this.$_growls == null) {
  227. this.$_growls = [];
  228. }
  229. return (base = this.$_growls)[location] != null ? base[location] : base[location] = $('#growls-' + location);
  230. }
  231. }, {
  232. key: "$growl",
  233. value: function $growl() {
  234. return this.$_growl != null ? this.$_growl : this.$_growl = $(this.html());
  235. }
  236. }, {
  237. key: "html",
  238. value: function html() {
  239. return this.container(this.content());
  240. }
  241. }, {
  242. key: "content",
  243. value: function content() {
  244. return "<div class='" + this.settings.namespace + "-close'>" + this.settings.close + "</div>\n<div class='" + this.settings.namespace + "-title'>" + this.settings.title + "</div>\n<div class='" + this.settings.namespace + "-message'>" + this.settings.message + "</div>";
  245. }
  246. }, {
  247. key: "container",
  248. value: function container(content) {
  249. return "<div class='" + this.settings.namespace + " " + this.settings.namespace + "-" + this.settings.style + " " + this.settings.namespace + "-" + this.settings.size + "'>\n " + content + "\n</div>";
  250. }
  251. }]);
  252.  
  253. return Growl;
  254. }();
  255.  
  256. ;
  257.  
  258. Growl.settings = {
  259. namespace: 'growl',
  260. duration: 3200,
  261. close: "&#215;",
  262. location: "default",
  263. style: "default",
  264. size: "medium",
  265. delayOnHover: true
  266. };
  267.  
  268. return Growl;
  269. }();
  270.  
  271. this.Growl = Growl;
  272.  
  273. $.growl = function () {
  274. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  275.  
  276. return Growl.growl(options);
  277. };
  278.  
  279. $.growl.error = function () {
  280. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  281.  
  282. var settings;
  283. settings = {
  284. title: "Error!",
  285. style: "error"
  286. };
  287. return $.growl($.extend(settings, options));
  288. };
  289.  
  290. $.growl.notice = function () {
  291. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  292.  
  293. var settings;
  294. settings = {
  295. title: "Notice!",
  296. style: "notice"
  297. };
  298. return $.growl($.extend(settings, options));
  299. };
  300.  
  301. $.growl.warning = function () {
  302. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  303.  
  304. var settings;
  305. settings = {
  306. title: "Warning!",
  307. style: "warning"
  308. };
  309. return $.growl($.extend(settings, options));
  310. };
  311. }).call(this);