Last active
August 29, 2015 14:05
-
-
Save joeytrapp/65598ea84782e9ac4cfa to your computer and use it in GitHub Desktop.
Ember Notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.ApplicationController = Em.Controller.extend({ | |
notifictions: Blocks.Notifications.create(), | |
actions: { | |
notify: function() { | |
if (typeof obj === 'string') { | |
obj = { message: obj }; | |
} | |
this.get('notifications').createNotification(obj); | |
}, | |
clearNotification: function() { | |
this.get('notifications').clearNotification(notification); | |
} | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Notifications = Em.Object.extend({ | |
active: [], | |
inactive: [], | |
timeout: 5000, | |
Notification: Em.Object.extend({ | |
message: '', | |
type: '', | |
sticky: true, | |
willEnter: true, | |
didEnter: false, | |
willLeave: false, | |
didLeave: false | |
}), | |
createNotification: function(obj) { | |
var notification = this.get('Notification').create(obj); | |
this.get('active').unshiftObject(notfication); | |
Em.run.next(function() { | |
notification.setProperties({ | |
willEnter: false, | |
didEnter: true | |
}); | |
}); | |
Em.run.later(this, function() { | |
if (!notification.get('sticky')) { | |
this.clearNotification(notification); | |
} | |
}, this.get('timeout')); | |
}, | |
clearNotification: function(notification) { | |
notification.setProperties({ | |
didEnter: false, | |
willLeave: true | |
}); | |
Em.run.later(this, function() { | |
notification.setProperties({ | |
willLeave: false, | |
didLeave: true | |
}); | |
this.get('active').removeObject(notification); | |
this.get('inactive').unshiftObject(notification); | |
}, 2000); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment