1 | var Annotator, |
---|
2 | __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, |
---|
3 | __hasProp = Object.prototype.hasOwnProperty, |
---|
4 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; |
---|
5 | |
---|
6 | Annotator = Annotator || {}; |
---|
7 | |
---|
8 | Annotator.Notification = (function(_super) { |
---|
9 | |
---|
10 | __extends(Notification, _super); |
---|
11 | |
---|
12 | Notification.prototype.events = { |
---|
13 | "click": "hide" |
---|
14 | }; |
---|
15 | |
---|
16 | Notification.prototype.options = { |
---|
17 | html: "<div class='annotator-notice'></div>", |
---|
18 | classes: { |
---|
19 | show: "annotator-notice-show", |
---|
20 | info: "annotator-notice-info", |
---|
21 | success: "annotator-notice-success", |
---|
22 | error: "annotator-notice-error" |
---|
23 | } |
---|
24 | }; |
---|
25 | |
---|
26 | function Notification(options) { |
---|
27 | this.hide = __bind(this.hide, this); |
---|
28 | this.show = __bind(this.show, this); Notification.__super__.constructor.call(this, $(this.options.html).appendTo(document.body)[0], options); |
---|
29 | } |
---|
30 | |
---|
31 | Notification.prototype.show = function(message, status) { |
---|
32 | if (status == null) status = Annotator.Notification.INFO; |
---|
33 | $(this.element).addClass(this.options.classes.show).addClass(this.options.classes[status]).escape(message || ""); |
---|
34 | setTimeout(this.hide, 5000); |
---|
35 | return this; |
---|
36 | }; |
---|
37 | |
---|
38 | Notification.prototype.hide = function() { |
---|
39 | $(this.element).removeClass(this.options.classes.show); |
---|
40 | return this; |
---|
41 | }; |
---|
42 | |
---|
43 | return Notification; |
---|
44 | |
---|
45 | })(Delegator); |
---|
46 | |
---|
47 | Annotator.Notification.INFO = 'show'; |
---|
48 | |
---|
49 | Annotator.Notification.SUCCESS = 'success'; |
---|
50 | |
---|
51 | Annotator.Notification.ERROR = 'error'; |
---|
52 | |
---|
53 | $(function() { |
---|
54 | var notification; |
---|
55 | notification = new Annotator.Notification; |
---|
56 | Annotator.showNotification = notification.show; |
---|
57 | return Annotator.hideNotification = notification.hide; |
---|
58 | }); |
---|