relocate variable declaration

pull/2/head
Leopoldthecoder 2016-08-11 11:11:59 +08:00
parent dcffbbbe0d
commit 4fcfa04a9b
1 changed files with 12 additions and 10 deletions

View File

@ -1,14 +1,14 @@
import Vue from 'vue'; import Vue from 'vue';
var NotificationConstructor = Vue.extend(require('./main.vue')); let NotificationConstructor = Vue.extend(require('./main.vue'));
var instance; let instance;
var instances = []; let instances = [];
var seed = 1; let seed = 1;
var Notification = function(options) { var Notification = function(options) {
options = options || {}; options = options || {};
var userOnClose = options.onClose; let userOnClose = options.onClose;
var id = 'notification_' + seed++; let id = 'notification_' + seed++;
options.onClose = function() { options.onClose = function() {
Notification.close(id, userOnClose); Notification.close(id, userOnClose);
@ -23,8 +23,8 @@ var Notification = function(options) {
instance.vm.visible = true; instance.vm.visible = true;
instance.dom = instance.vm.$el; instance.dom = instance.vm.$el;
var topDist = 0; let topDist = 0;
for (var i = 0, len = instances.length; i < len; i++) { for (let i = 0, len = instances.length; i < len; i++) {
topDist += instances[i].$el.offsetHeight + 16; topDist += instances[i].$el.offsetHeight + 16;
} }
topDist += 16; topDist += 16;
@ -33,13 +33,15 @@ var Notification = function(options) {
}; };
Notification.close = function(id, userOnClose) { Notification.close = function(id, userOnClose) {
let index;
let removedHeight;
for (var i = 0, len = instances.length; i < len; i++) { for (var i = 0, len = instances.length; i < len; i++) {
if (id === instances[i].id) { if (id === instances[i].id) {
if (typeof userOnClose === 'function') { if (typeof userOnClose === 'function') {
userOnClose(instances[i]); userOnClose(instances[i]);
} }
var index = i; index = i;
var removedHeight = instances[i].dom.offsetHeight; removedHeight = instances[i].dom.offsetHeight;
instances.splice(i, 1); instances.splice(i, 1);
break; break;
} }