You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			35 lines
		
	
	
		
			972 B
		
	
	
	
		
			JavaScript
		
	
			
		
		
	
	
			35 lines
		
	
	
		
			972 B
		
	
	
	
		
			JavaScript
		
	
var Whisper = Whisper || {};
 | 
						|
(function () {
 | 
						|
  'use strict';
 | 
						|
 | 
						|
  // This is an ephemeral collection of global notification messages to be
 | 
						|
  // presented in some nice way to the user. In this case they will fade in/out
 | 
						|
  // one at a time.
 | 
						|
 | 
						|
  var queue = new Backbone.Collection();
 | 
						|
  var view  = new (Backbone.View.extend({
 | 
						|
    className: 'help',
 | 
						|
    initialize: function() {
 | 
						|
      this.$el.appendTo($('body'));
 | 
						|
      this.listenToOnce(queue, 'add', this.presentNext);
 | 
						|
    },
 | 
						|
    presentNext: function() {
 | 
						|
      var next = queue.shift();
 | 
						|
      if (next) {
 | 
						|
        this.$el.text(next.get('message')).fadeIn(this.setFadeOut.bind(this));
 | 
						|
      } else {
 | 
						|
        this.listenToOnce(queue, 'add', this.presentNext);
 | 
						|
      }
 | 
						|
    },
 | 
						|
    setFadeOut: function() {
 | 
						|
      setTimeout(this.fadeOut.bind(this), 1500);
 | 
						|
    },
 | 
						|
    fadeOut: function() {
 | 
						|
      this.$el.fadeOut(this.presentNext.bind(this));
 | 
						|
    },
 | 
						|
  }))();
 | 
						|
 | 
						|
  Whisper.notify = function(str) { queue.add({message: str}); }
 | 
						|
 | 
						|
})();
 |