PageSourceSearch

https://dash.reviews.io/growl/javascripts/jquery.growl.js

js reviews.io collected 2026-09-24 08:25:59 UTC 6,735 bytes, 240 lines download raw bytes

1// Generated by CoffeeScript 1.9.3
2
3/*
4jQuery Growl
5Copyright 2015 Kevin Sylvestre
61.2.8
7 */
8
9(function() {
10  "use strict";
11  var $, Animation, Growl,
12    bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
13
14  $ = jQuery;
15
16  Animation = (function() {
17    function Animation() {}
18
19    Animation.transitions = {
20      "webkitTransition": "webkitTransitionEnd",
21      "mozTransition": "mozTransitionEnd",
22      "oTransition": "oTransitionEnd",
23      "transition": "transitionend"
24    };
25
26    Animation.transition = function($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    return Animation;
39
40  })();
41
42  Growl = (function() {
43    Growl.settings = {
44      namespace: 'growl',
45      duration: 3200,
46      close: "×",
47      location: "default",
48      style: "default",
49      size: "medium"
50    };
51
52    Growl.growl = function(settings) {
53      if (settings == null) {
54        settings = {};
55      }
56      this.initialize();
57      return new Growl(settings);
58    };
59
60    Growl.initialize = function() {
61      return $("body:not(:has(#growls))").append('<div id="growls" />');
62    };
63
64    function Growl(settings) {
65      if (settings == null) {
66        settings = {};
67      }
68      this.html = bind(this.html, this);
69      this.$growl = bind(this.$growl, this);
70      this.$growls = bind(this.$growls, this);
71      this.animate = bind(this.animate, this);
72      this.remove = bind(this.remove, this);
73      this.dismiss = bind(this.dismiss, this);
74      this.present = bind(this.present, this);
75      this.cycle = bind(this.cycle, this);
76      this.close = bind(this.close, this);
77      this.click = bind(this.click, this);
78      this.unbind = bind(this.unbind, this);
79      this.bind = bind(this.bind, this);
80      this.render = bind(this.render, this);
81      this.settings = $.extend({}, Growl.settings, settings);
82      this.$growls().attr('class', this.settings.location);
83      this.render();
84    }
85
86    Growl.prototype.render = function() {
87      var $growl;
88      $growl = this.$growl();
89      this.$growls().append($growl);
90      if (this.settings['static'] != null) {
91        if (typeof console !== "undefined" && console !== null) {
92          if (typeof console.debug === "function") {
93            console.debug('jquery.growl DEPRECATION: "static" has been renamed to "fixed" and will be removed in the next release');
94          }
95        }
96        this.settings['fixed'] = this.settings['static'];
97      }
98      if (this.settings.fixed) {
99        this.present();
100      } else {
101        this.cycle();
102      }
103    };
104
105    Growl.prototype.bind = function($growl) {
106      if ($growl == null) {
107        $growl = this.$growl();
108      }
109      $growl.on("click", this.click);
110      return $growl.on("contextmenu", this.close).find("." + this.settings.namespace + "-close").on("click", this.close);
111    };
112
113    Growl.prototype.unbind = function($growl) {
114      if ($growl == null) {
115        $growl = this.$growl();
116      }
117      $growl.off("click", this.click);
118      return $growl.off("contextmenu", this.close).find("." + this.settings.namespace + "-close").off("click", this.close);
119    };
120
121    Growl.prototype.click = function(event) {
122      if (this.settings.url != null) {
123        event.preventDefault();
124        event.stopPropagation();
125        return window.open(this.settings.url);
126      }
127    };
128
129    Growl.prototype.close = function(event) {
130      var $growl;
131      event.preventDefault();
132      event.stopPropagation();
133      $growl = this.$growl();
134      return $growl.stop().queue(this.dismiss).queue(this.remove);
135    };
136
137    Growl.prototype.cycle = function() {
138      var $growl;
139      $growl = this.$growl();
140      return $growl.queue(this.present).delay(this.settings.duration).queue(this.dismiss).queue(this.remove);
141    };
142
143    Growl.prototype.present = function(callback) {
144      var $growl;
145      $growl = this.$growl();
146      this.bind($growl);
147      return this.animate($growl, this.settings.namespace + "-incoming", 'out', 
147callback);
148    };
149
150    Growl.prototype.dismiss = function(callback) {
151      var $growl;
152      $growl = this.$growl();
153      this.unbind($growl);
154      return this.animate($growl, this.settings.namespace + "-outgoing", 'in', callback);
155    };
156
157    Growl.prototype.remove = function(callback) {
158      this.$growl().remove();
159      return callback();
160    };
161
162    Growl.prototype.animate = function($element, name, direction, callback) {
163      var transition;
164      if (direction == null) {
165        direction = 'in';
166      }
167      transition = Animation.transition($element);
168      $element[direction === 'in' ? 'removeClass' : 'addClass'](name);
169      $element.offset().position;
170      $element[direction === 'in' ? 'addClass' : 'removeClass'](name);
171      if (callback == null) {
172        return;
173      }
174      if (transition != null) {
175        $element.one(transition, callback);
176      } else {
177        callback();
178      }
179    };
180
181    Growl.prototype.$growls = function() {
182      return this.$_growls != null ? this.$_growls : this.$_growls = $('#growls');
183    };
184
185    Growl.prototype.$growl = function() {
186      return this.$_growl != null ? this.$_growl : this.$_growl = $(this.html());
187    };
188
189    Growl.prototype.html = function() {
190      return "<div class='" + this.settings.namespace + " " + this.settings.namespace + "-" + this.settings.style + " " + this.settings.namespace + "-" + this.settings.size + "'>\n  <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>\n</div>";
191    };
192
193    return Growl;
194
195  })();
196
197  $.growl = function(options) {
198    if (options == null) {
199      options = {};
200    }
201    return Growl.growl(options);
202  };
203
204  $.growl.error = function(options) {
205    var settings;
206    if (options == null) {
207      options = {};
208    }
209    settings = {
210      title: "Error!",
211      style: "error"
212    };
213    return $.growl($.extend(settings, options));
214  };
215
216  $.growl.notice = function(options) {
217    var settings;
218    if (options == null) {
219      options = {};
220    }
221    settings = {
222      title: "Notice!",
223      style: "notice"
224    };
225    return $.growl($.extend(settings, options));
226  };
227
228  $.growl.warning = function(options) {
229    var settings;
230    if (options == null) {
231      options = {};
232    }
233    settings = {
234      title: "Warning!",
235      style: "warning"
236    };
237    return $.growl($.extend(settings, options));
238  };
239
240}).call(this);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.