vue-notifications
Advanced tools
Comparing version 0.7.2 to 0.7.3
{ | ||
"name": "vue-notifications", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"description": "Vuejs notifications", | ||
@@ -5,0 +5,0 @@ "main": "dist/vue-notifications.js", |
@@ -33,201 +33,221 @@ ;(function(root, factory) { | ||
/** | ||
* @param {Object} Vue | ||
* @return {Object} | ||
*/ | ||
function getVersion(Vue) { | ||
var version = Vue.version.match(/(\d+)/g); | ||
return { | ||
major: +version[0], | ||
regular: +version[1], | ||
minor: +version[2] | ||
}; | ||
} | ||
var innerMethods = { | ||
/** | ||
* @param {Object} Vue | ||
* @return {Object} | ||
*/ | ||
getVersion: function getVersion(Vue) { | ||
var version = Vue.version.match(/(\d+)/g); | ||
return { | ||
major: +version[0], | ||
regular: +version[1], | ||
minor: +version[2] | ||
}; | ||
}, | ||
/** | ||
* @param {String} msg | ||
* @param {String} type | ||
* @param {Object} types | ||
*/ | ||
function showInConsole(msg, type, types) { | ||
if (type === types.error) console.error(msg);else if (type === types.warn) console.warn(msg);else if (type === types.success) console.info(msg);else console.log(msg); | ||
} | ||
/** | ||
* @param {String} type | ||
* @param {String} message | ||
* @param {String} title | ||
* @param {String} debugMsg | ||
* @return {String} | ||
*/ | ||
function showDefaultMessage(_ref) { | ||
var type = _ref.type, | ||
message = _ref.message, | ||
title = _ref.title, | ||
debugMsg = _ref.debugMsg; | ||
/** | ||
* @param {String} msg | ||
* @param {String} type | ||
* @param {Object} types | ||
*/ | ||
showInConsole: function showInConsole(msg, type, types) { | ||
if (type === types.error) console.error(msg);else if (type === types.warn) console.warn(msg);else if (type === types.success) console.info(msg);else console.log(msg); | ||
}, | ||
var msg = 'Title: ' + title + ', Message: ' + message + ', DebugMsg: ' + debugMsg + ', type: ' + type; | ||
showInConsole(msg, type, TYPE); | ||
/** | ||
* @param {String} type | ||
* @param {String} message | ||
* @param {String} title | ||
* @param {String} debugMsg | ||
* @param {Object} vueApp | ||
* @return {String} | ||
*/ | ||
showDefaultMessage: function showDefaultMessage(_ref, vueApp) { | ||
var type = _ref.type, | ||
message = _ref.message, | ||
title = _ref.title, | ||
debugMsg = _ref.debugMsg; | ||
return msg; | ||
} | ||
var msg = 'Title: ' + title + ', Message: ' + message + ', DebugMsg: ' + debugMsg + ', type: ' + type; | ||
/** | ||
* @param {String} id | ||
* @param {String} type | ||
* @param {String} timeout | ||
* @param {String} title | ||
* @param {String} message | ||
* @param {Function} computed // TODO (S.Panfilov) or not fn? | ||
* @param {String} debugMsg | ||
* @param {Function} cb | ||
* @return {String} | ||
*/ | ||
function showInlineMessage(_ref2) { | ||
var id = _ref2.id, | ||
type = _ref2.type, | ||
timeout = _ref2.timeout, | ||
title = _ref2.title, | ||
message = _ref2.message, | ||
computed = _ref2.computed, | ||
debugMsg = _ref2.debugMsg, | ||
cb = _ref2.cb; | ||
innerMethods.showInConsole(msg, type, TYPE); | ||
// TODO (S.Panfilov) handle class add and remove here | ||
if (debugMsg) showInConsole(debugMsg, type, TYPE); | ||
var elem = document.getElementById(id); | ||
return msg; | ||
}, | ||
var msg = message; | ||
if (title) msg = title + ': ' + msg; | ||
/** | ||
* @param {Object} elem | ||
*/ | ||
clearFn: function clearFn(elem) { | ||
elem.innerText = ''; | ||
}, | ||
elem.innerText = msg; | ||
/** | ||
* @param {String} id | ||
* @param {String} type | ||
* @param {String} timeout | ||
* @param {String} title | ||
* @param {String} message | ||
* @param {Function} computed // TODO (S.Panfilov) or not fn? | ||
* @param {String} debugMsg | ||
* @param {Function} cb | ||
* @param {Object} vueApp | ||
* @return {String} | ||
*/ | ||
showInlineMessage: function showInlineMessage(_ref2, vueApp) { | ||
var id = _ref2.id, | ||
type = _ref2.type, | ||
timeout = _ref2.timeout, | ||
title = _ref2.title, | ||
message = _ref2.message, | ||
computed = _ref2.computed, | ||
debugMsg = _ref2.debugMsg, | ||
cb = _ref2.cb; | ||
function clearFn(elem) { | ||
elem.innerText = ''; | ||
} | ||
// TODO (S.Panfilov) handle class add and remove here | ||
if (debugMsg) innerMethods.showInConsole(debugMsg, type, TYPE); | ||
var elem = document.getElementById(id); | ||
if (timeout && !computed) { | ||
setTimeout(function () { | ||
clearFn(elem); | ||
}, timeout); | ||
} else {} | ||
// TODO (S.Panfilov) Computed property doesn't work yet | ||
// const interval = setInterval(() => { | ||
// if (!computed) clearInterval(interval) | ||
// }, 50) | ||
var msg = message; | ||
if (title) msg = title + ': ' + msg; | ||
elem.innerText = msg; | ||
// TODO (S.Panfilov) BUG: Weird behaviour: cb calls 2 times | ||
if (cb) { | ||
cb(elem, clearFn); | ||
} | ||
if (timeout && !computed) { | ||
setTimeout(function () { | ||
innerMethods.clearFn.call(vueApp, elem); | ||
}, timeout); | ||
} else {} | ||
// TODO (S.Panfilov) Computed property doesn't work yet | ||
// const interval = setInterval(() => { | ||
// console.info(computed) | ||
// if (!computed) clearInterval(interval) | ||
// }, 50) | ||
return msg; | ||
} | ||
/** | ||
* @param {Object} vueApp | ||
* @param {Object} config | ||
* @return {Object} | ||
*/ | ||
function getValues(vueApp, config) { | ||
var result = {}; | ||
// TODO (S.Panfilov) BUG: Weird behaviour: cb calls 2 times | ||
console.warn(this); | ||
if (cb) { | ||
// TODO (S.Panfilov) bug here | ||
cb.call(vueApp, elem, function () { | ||
return innerMethods.clearFn.call(innerMethods, elem); | ||
}); | ||
} | ||
Object.keys(config).forEach(function (field) { | ||
if (field !== 'cb') { | ||
result[field] = typeof config[field] === 'function' ? config[field].call(vueApp) : config[field]; | ||
return msg; | ||
}, | ||
/** | ||
* @param {Object} vueApp | ||
* @param {Object} config | ||
* @return {Object} | ||
*/ | ||
getValues: function getValues(vueApp, config) { | ||
var result = {}; | ||
Object.keys(config).forEach(function (field) { | ||
if (field !== 'cb') { | ||
result[field] = typeof config[field] === 'function' ? config[field].call(vueApp) : config[field]; | ||
} else { | ||
console.info(vueApp); | ||
result[field] = config[field].bind(vueApp); | ||
} | ||
}); | ||
return result; | ||
}, | ||
/** | ||
* @param {Object} config | ||
* @param {Object} options | ||
* @param {Object} vueApp | ||
*/ | ||
showMessage: function showMessage(config, options, vueApp) { | ||
var valuesObj = innerMethods.getValues(vueApp, config); | ||
var isLinkedToElem = !!valuesObj.id; | ||
if (isLinkedToElem) { | ||
innerMethods.showInlineMessage(valuesObj, vueApp); | ||
} else { | ||
result[field] = config[field]; | ||
var isMethodOverridden = options && options[valuesObj.type]; | ||
var method = isMethodOverridden ? options[valuesObj.type] : innerMethods.showDefaultMessage; | ||
method(valuesObj, vueApp); | ||
} | ||
}); | ||
return result; | ||
} | ||
if (config.cb) return config.cb(); | ||
}, | ||
/** | ||
* @param {Object} config | ||
* @param {Object} options | ||
* @param {Object} vueApp | ||
*/ | ||
function showMessage(config, options, vueApp) { | ||
var valuesObj = getValues(vueApp, config); | ||
var isLinkedToElem = !!valuesObj.id; | ||
if (isLinkedToElem) { | ||
showInlineMessage(valuesObj); | ||
} else { | ||
var isMethodOverridden = options && options[valuesObj.type]; | ||
var method = isMethodOverridden ? options[valuesObj.type] : showDefaultMessage; | ||
method(valuesObj); | ||
} | ||
/** | ||
* @param {Object} targetObj | ||
* @param {Object} typesObj | ||
* @param {Object} options | ||
* @return {undefined} | ||
* */ | ||
addMethods: function addMethods(targetObj, typesObj, options) { | ||
Object.keys(typesObj).forEach(function (v) { | ||
targetObj[typesObj[v]] = function (config) { | ||
config.type = typesObj[v]; | ||
// TODO (S.Panfilov)fix 'vueApp' in param | ||
return innerMethods.showMessage(config, options); | ||
}; | ||
}); | ||
}, | ||
if (config.cb) return config.cb(); | ||
} | ||
/** | ||
* @param {Object} targetObj | ||
* @param {Object} typesObj | ||
* @param {Object} options | ||
* @return {undefined} | ||
* */ | ||
function addMethods(targetObj, typesObj, options) { | ||
Object.keys(typesObj).forEach(function (v) { | ||
targetObj[typesObj[v]] = function (config) { | ||
config.type = typesObj[v]; | ||
// TODO (S.Panfilov)fix 'vueApp' in param | ||
return showMessage(config, options); | ||
}; | ||
}); | ||
} | ||
/** | ||
* @param {Object} vueApp | ||
* @param {String} name | ||
* @param {Object} options | ||
* @param {Object} pluginOptions | ||
*/ | ||
setMethod: function setMethod(vueApp, name, options, pluginOptions) { | ||
if (!options.methods) options.methods = {}; | ||
/** | ||
* @param {Object} vueApp | ||
* @param {String} name | ||
* @param {Object} options | ||
* @param {Object} pluginOptions | ||
*/ | ||
function setMethod(vueApp, name, options, pluginOptions) { | ||
if (!options.methods) options.methods = {}; | ||
if (options.methods[name]) { | ||
// TODO (S.Panfilov) not sure - throw error here or just warn | ||
// if (options.methods[name]) throw console.error(MESSAGES.methodNameConflict + name) | ||
console.error(MESSAGES.methodNameConflict + name); | ||
} else { | ||
options.methods[name] = innerMethods.makeMethod(vueApp, name, options, pluginOptions); | ||
} | ||
}, | ||
if (options.methods[name]) { | ||
// TODO (S.Panfilov) not sure - throw error here or just warn | ||
// if (options.methods[name]) throw console.error(MESSAGES.methodNameConflict + name) | ||
console.error(MESSAGES.methodNameConflict + name); | ||
} else { | ||
options.methods[name] = makeMethod(vueApp, name, options, pluginOptions); | ||
} | ||
} | ||
/** | ||
* @param {Object} vueApp | ||
* @param {String} configName | ||
* @param {Object} options | ||
* @param {Object} pluginOptions | ||
* @return {Function} | ||
*/ | ||
function makeMethod(vueApp, configName, options, pluginOptions) { | ||
return function (config) { | ||
var newConfig = {}; | ||
Object.assign(newConfig, VueNotifications.config); | ||
Object.assign(newConfig, options[VueNotifications.propertyName][configName]); | ||
Object.assign(newConfig, config); | ||
/** | ||
* @param {Object} vueApp | ||
* @param {String} configName | ||
* @param {Object} options | ||
* @param {Object} pluginOptions | ||
* @return {Function} | ||
*/ | ||
makeMethod: function makeMethod(vueApp, configName, options, pluginOptions) { | ||
return function (config) { | ||
var newConfig = {}; | ||
Object.assign(newConfig, VueNotifications.config); | ||
Object.assign(newConfig, options[VueNotifications.propertyName][configName]); | ||
Object.assign(newConfig, config); | ||
return showMessage(newConfig, pluginOptions, vueApp); | ||
}; | ||
} | ||
return innerMethods.showMessage(newConfig, pluginOptions, vueApp); | ||
}; | ||
}, | ||
/** | ||
* @param {Object} vueApp | ||
* @param {Object} notifications | ||
* @param {Object} pluginOptions | ||
*/ | ||
function initVueNotificationPlugin(vueApp, notifications, pluginOptions) { | ||
if (!notifications) return; | ||
Object.keys(notifications).forEach(function (name) { | ||
setMethod(vueApp, name, vueApp.$options, pluginOptions); | ||
}); | ||
/** | ||
* @param {Object} vueApp | ||
* @param {Object} notifications | ||
* @param {Object} pluginOptions | ||
*/ | ||
initVueNotificationPlugin: function initVueNotificationPlugin(vueApp, notifications, pluginOptions) { | ||
if (!notifications) return; | ||
Object.keys(notifications).forEach(function (name) { | ||
innerMethods.setMethod(vueApp, name, vueApp.$options, pluginOptions); | ||
}); | ||
vueApp.$emit(PACKAGE_NAME + '-initiated'); | ||
} | ||
vueApp.$emit(PACKAGE_NAME + '-initiated'); | ||
} | ||
}; | ||
@@ -255,4 +275,4 @@ var VueNotifications = { | ||
if (this.installed) throw console.error(MESSAGES.alreadyInstalled); | ||
if (getVersion(Vue).major === VUE_VERSION.evangelion) hook = 'init'; | ||
if (getVersion(Vue).major === VUE_VERSION.ghostInTheShell) hook = 'beforeCreate'; | ||
if (innerMethods.getVersion(Vue).major === VUE_VERSION.evangelion) hook = 'init'; | ||
if (innerMethods.getVersion(Vue).major === VUE_VERSION.ghostInTheShell) hook = 'beforeCreate'; | ||
@@ -264,7 +284,7 @@ mixin[hook] = function () { | ||
initVueNotificationPlugin(vueApp, notificationsField, pluginOptions); | ||
innerMethods.initVueNotificationPlugin(vueApp, notificationsField, pluginOptions); | ||
}; | ||
Vue.mixin(mixin); | ||
addMethods(this, this.type, pluginOptions); | ||
innerMethods.addMethods(this, this.type, pluginOptions); | ||
@@ -271,0 +291,0 @@ this.installed = true; |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?module.exports=n():e.VueNotifications=n()}(this,function(){"use strict";function e(e){var n=e.version.match(/(\d+)/g);return{major:+n[0],regular:+n[1],minor:+n[2]}}function n(e,n,t){n===t.error?console.error(e):n===t.warn?console.warn(e):n===t.success?console.info(e):console.log(e)}function t(e){var t=e.type,o=e.message,i=e.title,r=e.debugMsg,s="Title: "+i+", Message: "+o+", DebugMsg: "+r+", type: "+t;return n(s,t,m),s}function o(e){function t(e){e.innerText=""}var o=e.id,i=e.type,r=e.timeout,s=e.title,c=e.message,a=e.computed,u=e.debugMsg,f=e.cb;u&&n(u,i,m);var l=document.getElementById(o),d=c;return s&&(d=s+": "+d),l.innerText=d,r&&!a&&setTimeout(function(){t(l)},r),f&&f(l,t),d}function i(e,n){var t={};return Object.keys(n).forEach(function(o){"cb"!==o?t[o]="function"==typeof n[o]?n[o].call(e):n[o]:t[o]=n[o]}),t}function r(e,n,r){var s=i(r,e),c=!!s.id;if(c)o(s);else{var a=n&&n[s.type],u=a?n[s.type]:t;u(s)}if(e.cb)return e.cb()}function s(e,n,t){Object.keys(n).forEach(function(o){e[n[o]]=function(e){return e.type=n[o],r(e,t)}})}function c(e,n,t,o){t.methods||(t.methods={}),t.methods[n]?console.error(p.methodNameConflict+n):t.methods[n]=a(e,n,t,o)}function a(e,n,t,o){return function(i){var s={};return Object.assign(s,g.config),Object.assign(s,t[g.propertyName][n]),Object.assign(s,i),r(s,o,e)}}function u(e,n,t){n&&(Object.keys(n).forEach(function(n){c(e,n,e.$options,t)}),e.$emit(l+"-initiated"))}var f="VueNotifications",l="vue-notifications",d="notifications",m={error:"error",warn:"warn",info:"info",success:"success"},h={evangelion:1,ghostInTheShell:2},p={alreadyInstalled:f+": plugin already installed",methodNameConflict:f+": names conflict - "},g={type:m,propertyName:d,config:{type:m.info,timeout:3e3},installed:!1,install:function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o={},i=void 0;if(this.installed)throw console.error(p.alreadyInstalled);e(n).major===h.evangelion&&(i="init"),e(n).major===h.ghostInTheShell&&(i="beforeCreate"),o[i]=function(){var e=this,n=this.$options,o=n[g.propertyName];u(e,o,t)},n.mixin(o),s(this,this.type,t),this.installed=!0}};return"undefined"!=typeof window&&window.Vue&&window.Vue.use(g),g}); | ||
!function(e,n){"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?module.exports=n():e.VueNotifications=n()}(this,function(){"use strict";var e="VueNotifications",n="vue-notifications",t="notifications",o={error:"error",warn:"warn",info:"info",success:"success"},i={evangelion:1,ghostInTheShell:2},s={alreadyInstalled:e+": plugin already installed",methodNameConflict:e+": names conflict - "},r={getVersion:function(e){var n=e.version.match(/(\d+)/g);return{major:+n[0],regular:+n[1],minor:+n[2]}},showInConsole:function(e,n,t){n===t.error?console.error(e):n===t.warn?console.warn(e):n===t.success?console.info(e):console.log(e)},showDefaultMessage:function(e,n){var t=e.type,i=e.message,s=e.title,a=e.debugMsg,c="Title: "+s+", Message: "+i+", DebugMsg: "+a+", type: "+t;return r.showInConsole(c,t,o),c},clearFn:function(e){e.innerText=""},showInlineMessage:function(e,n){var t=e.id,i=e.type,s=e.timeout,a=e.title,c=e.message,l=e.computed,u=e.debugMsg,f=e.cb;u&&r.showInConsole(u,i,o);var d=document.getElementById(t),h=c;return a&&(h=a+": "+h),d.innerText=h,s&&!l&&setTimeout(function(){r.clearFn.call(n,d)},s),console.warn(this),f&&f.call(n,d,function(){return r.clearFn.call(r,d)}),h},getValues:function(e,n){var t={};return Object.keys(n).forEach(function(o){"cb"!==o?t[o]="function"==typeof n[o]?n[o].call(e):n[o]:(console.info(e),t[o]=n[o].bind(e))}),t},showMessage:function(e,n,t){var o=r.getValues(t,e),i=!!o.id;if(i)r.showInlineMessage(o,t);else{var s=n&&n[o.type],a=s?n[o.type]:r.showDefaultMessage;a(o,t)}if(e.cb)return e.cb()},addMethods:function(e,n,t){Object.keys(n).forEach(function(o){e[n[o]]=function(e){return e.type=n[o],r.showMessage(e,t)}})},setMethod:function(e,n,t,o){t.methods||(t.methods={}),t.methods[n]?console.error(s.methodNameConflict+n):t.methods[n]=r.makeMethod(e,n,t,o)},makeMethod:function(e,n,t,o){return function(i){var s={};return Object.assign(s,a.config),Object.assign(s,t[a.propertyName][n]),Object.assign(s,i),r.showMessage(s,o,e)}},initVueNotificationPlugin:function(e,t,o){t&&(Object.keys(t).forEach(function(n){r.setMethod(e,n,e.$options,o)}),e.$emit(n+"-initiated"))}},a={type:o,propertyName:t,config:{type:o.info,timeout:3e3},installed:!1,install:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t={},o=void 0;if(this.installed)throw console.error(s.alreadyInstalled);r.getVersion(e).major===i.evangelion&&(o="init"),r.getVersion(e).major===i.ghostInTheShell&&(o="beforeCreate"),t[o]=function(){var e=this,t=this.$options,o=t[a.propertyName];r.initVueNotificationPlugin(e,o,n)},e.mixin(t),r.addMethods(this,this.type,n),this.installed=!0}};return"undefined"!=typeof window&&window.Vue&&window.Vue.use(a),a}); | ||
//# sourceMappingURL=vue-notifications.es5.min.js.map |
@@ -22,191 +22,199 @@ const PLUGIN_NAME = 'VueNotifications' | ||
/** | ||
* @param {Object} Vue | ||
* @return {Object} | ||
*/ | ||
function getVersion (Vue) { | ||
const version = Vue.version.match(/(\d+)/g) | ||
return { | ||
major: +version[0], | ||
regular: +version[1], | ||
minor: +version[2] | ||
} | ||
} | ||
const innerMethods = { | ||
/** | ||
* @param {Object} Vue | ||
* @return {Object} | ||
*/ | ||
getVersion (Vue) { | ||
const version = Vue.version.match(/(\d+)/g) | ||
return { | ||
major: +version[0], | ||
regular: +version[1], | ||
minor: +version[2] | ||
} | ||
}, | ||
/** | ||
* @param {String} msg | ||
* @param {String} type | ||
* @param {Object} types | ||
*/ | ||
function showInConsole (msg, type, types) { | ||
if (type === types.error) console.error(msg) | ||
else if (type === types.warn) console.warn(msg) | ||
else if (type === types.success) console.info(msg) | ||
else console.log(msg) | ||
} | ||
/** | ||
* @param {String} msg | ||
* @param {String} type | ||
* @param {Object} types | ||
*/ | ||
showInConsole (msg, type, types) { | ||
if (type === types.error) console.error(msg) | ||
else if (type === types.warn) console.warn(msg) | ||
else if (type === types.success) console.info(msg) | ||
else console.log(msg) | ||
}, | ||
/** | ||
* @param {String} type | ||
* @param {String} message | ||
* @param {String} title | ||
* @param {String} debugMsg | ||
* @return {String} | ||
*/ | ||
function showDefaultMessage ({ type, message, title, debugMsg }) { | ||
let msg = `Title: ${title}, Message: ${message}, DebugMsg: ${debugMsg}, type: ${type}` | ||
/** | ||
* @param {String} type | ||
* @param {String} message | ||
* @param {String} title | ||
* @param {String} debugMsg | ||
* @param {Object} vueApp | ||
* @return {String} | ||
*/ | ||
showDefaultMessage ({ type, message, title, debugMsg }, vueApp) { | ||
let msg = `Title: ${title}, Message: ${message}, DebugMsg: ${debugMsg}, type: ${type}` | ||
showInConsole(msg, type, TYPE) | ||
innerMethods.showInConsole(msg, type, TYPE) | ||
return msg | ||
} | ||
return msg | ||
}, | ||
/** | ||
* @param {Object} elem | ||
*/ | ||
clearFn (elem) { | ||
elem.innerText = '' | ||
}, | ||
/** | ||
* @param {String} id | ||
* @param {String} type | ||
* @param {String} timeout | ||
* @param {String} title | ||
* @param {String} message | ||
* @param {Function} computed // TODO (S.Panfilov) or not fn? | ||
* @param {String} debugMsg | ||
* @param {Function} cb | ||
* @param {Object} vueApp | ||
* @return {String} | ||
*/ | ||
showInlineMessage ({ id, type, timeout, title, message, computed, debugMsg, cb }, vueApp) { | ||
// TODO (S.Panfilov) handle class add and remove here | ||
if (debugMsg) innerMethods.showInConsole(debugMsg, type, TYPE) | ||
const elem = document.getElementById(id) | ||
/** | ||
* @param {String} id | ||
* @param {String} type | ||
* @param {String} timeout | ||
* @param {String} title | ||
* @param {String} message | ||
* @param {Function} computed // TODO (S.Panfilov) or not fn? | ||
* @param {String} debugMsg | ||
* @param {Function} cb | ||
* @return {String} | ||
*/ | ||
function showInlineMessage ({ id, type, timeout, title, message, computed, debugMsg, cb }) { | ||
// TODO (S.Panfilov) handle class add and remove here | ||
if (debugMsg) showInConsole(debugMsg, type, TYPE) | ||
const elem = document.getElementById(id) | ||
let msg = message | ||
if (title) msg = `${title}: ${msg}` | ||
let msg = message | ||
if (title) msg = `${title}: ${msg}` | ||
elem.innerText = msg | ||
elem.innerText = msg | ||
if (timeout && !computed) { | ||
setTimeout(() => { | ||
innerMethods.clearFn.call(vueApp, elem) | ||
}, timeout) | ||
} else { | ||
// TODO (S.Panfilov) Computed property doesn't work yet | ||
// const interval = setInterval(() => { | ||
// console.info(computed) | ||
// if (!computed) clearInterval(interval) | ||
// }, 50) | ||
} | ||
function clearFn (elem) { | ||
elem.innerText = '' | ||
} | ||
// TODO (S.Panfilov) BUG: Weird behaviour: cb calls 2 times | ||
console.warn(this) | ||
if (cb) { | ||
// TODO (S.Panfilov) bug here | ||
cb.call(vueApp, elem, () => innerMethods.clearFn.call(innerMethods, elem)) | ||
} | ||
if (timeout && !computed) { | ||
setTimeout(() => { | ||
clearFn(elem) | ||
}, timeout) | ||
} else { | ||
// TODO (S.Panfilov) Computed property doesn't work yet | ||
// const interval = setInterval(() => { | ||
// if (!computed) clearInterval(interval) | ||
// }, 50) | ||
} | ||
return msg | ||
}, | ||
// TODO (S.Panfilov) BUG: Weird behaviour: cb calls 2 times | ||
if (cb) { | ||
cb(elem, clearFn) | ||
} | ||
/** | ||
* @param {Object} vueApp | ||
* @param {Object} config | ||
* @return {Object} | ||
*/ | ||
getValues (vueApp, config) { | ||
const result = {} | ||
return msg | ||
} | ||
Object.keys(config).forEach(field => { | ||
if (field !== 'cb') { | ||
result[field] = (typeof config[field] === 'function') ? config[field].call(vueApp) : config[field] | ||
} else { | ||
console.info(vueApp) | ||
result[field] = config[field].bind(vueApp) | ||
} | ||
}) | ||
/** | ||
* @param {Object} vueApp | ||
* @param {Object} config | ||
* @return {Object} | ||
*/ | ||
function getValues (vueApp, config) { | ||
const result = {} | ||
return result | ||
}, | ||
Object.keys(config).forEach(field => { | ||
if (field !== 'cb') { | ||
result[field] = (typeof config[field] === 'function') ? config[field].call(vueApp) : config[field] | ||
/** | ||
* @param {Object} config | ||
* @param {Object} options | ||
* @param {Object} vueApp | ||
*/ | ||
showMessage (config, options, vueApp) { | ||
const valuesObj = innerMethods.getValues(vueApp, config) | ||
const isLinkedToElem = !!valuesObj.id | ||
if (isLinkedToElem) { | ||
innerMethods.showInlineMessage(valuesObj, vueApp) | ||
} else { | ||
result[field] = config[field] | ||
const isMethodOverridden = options && options[valuesObj.type] | ||
const method = isMethodOverridden ? options[valuesObj.type] : innerMethods.showDefaultMessage | ||
method(valuesObj, vueApp) | ||
} | ||
}) | ||
return result | ||
} | ||
if (config.cb) return config.cb() | ||
}, | ||
/** | ||
* @param {Object} config | ||
* @param {Object} options | ||
* @param {Object} vueApp | ||
*/ | ||
function showMessage (config, options, vueApp) { | ||
const valuesObj = getValues(vueApp, config) | ||
const isLinkedToElem = !!valuesObj.id | ||
/** | ||
* @param {Object} targetObj | ||
* @param {Object} typesObj | ||
* @param {Object} options | ||
* @return {undefined} | ||
* */ | ||
addMethods (targetObj, typesObj, options) { | ||
Object.keys(typesObj).forEach(v => { | ||
targetObj[typesObj[v]] = function (config) { | ||
config.type = typesObj[v] | ||
// TODO (S.Panfilov)fix 'vueApp' in param | ||
return innerMethods.showMessage(config, options) | ||
} | ||
}) | ||
}, | ||
if (isLinkedToElem) { | ||
showInlineMessage(valuesObj) | ||
} else { | ||
const isMethodOverridden = options && options[valuesObj.type] | ||
const method = isMethodOverridden ? options[valuesObj.type] : showDefaultMessage | ||
method(valuesObj) | ||
} | ||
/** | ||
* @param {Object} vueApp | ||
* @param {String} name | ||
* @param {Object} options | ||
* @param {Object} pluginOptions | ||
*/ | ||
setMethod (vueApp, name, options, pluginOptions) { | ||
if (!options.methods) options.methods = {} | ||
if (config.cb) return config.cb() | ||
} | ||
/** | ||
* @param {Object} targetObj | ||
* @param {Object} typesObj | ||
* @param {Object} options | ||
* @return {undefined} | ||
* */ | ||
function addMethods (targetObj, typesObj, options) { | ||
Object.keys(typesObj).forEach(v => { | ||
targetObj[typesObj[v]] = function (config) { | ||
config.type = typesObj[v] | ||
// TODO (S.Panfilov)fix 'vueApp' in param | ||
return showMessage(config, options) | ||
if (options.methods[name]) { | ||
// TODO (S.Panfilov) not sure - throw error here or just warn | ||
// if (options.methods[name]) throw console.error(MESSAGES.methodNameConflict + name) | ||
console.error(MESSAGES.methodNameConflict + name) | ||
} else { | ||
options.methods[name] = innerMethods.makeMethod(vueApp, name, options, pluginOptions) | ||
} | ||
}) | ||
} | ||
}, | ||
/** | ||
* @param {Object} vueApp | ||
* @param {String} name | ||
* @param {Object} options | ||
* @param {Object} pluginOptions | ||
*/ | ||
function setMethod (vueApp, name, options, pluginOptions) { | ||
if (!options.methods) options.methods = {} | ||
/** | ||
* @param {Object} vueApp | ||
* @param {String} configName | ||
* @param {Object} options | ||
* @param {Object} pluginOptions | ||
* @return {Function} | ||
*/ | ||
makeMethod (vueApp, configName, options, pluginOptions) { | ||
return function (config) { | ||
const newConfig = {} | ||
Object.assign(newConfig, VueNotifications.config) | ||
Object.assign(newConfig, options[VueNotifications.propertyName][configName]) | ||
Object.assign(newConfig, config) | ||
if (options.methods[name]) { | ||
// TODO (S.Panfilov) not sure - throw error here or just warn | ||
// if (options.methods[name]) throw console.error(MESSAGES.methodNameConflict + name) | ||
console.error(MESSAGES.methodNameConflict + name) | ||
} else { | ||
options.methods[name] = makeMethod(vueApp, name, options, pluginOptions) | ||
} | ||
} | ||
return innerMethods.showMessage(newConfig, pluginOptions, vueApp) | ||
} | ||
}, | ||
/** | ||
* @param {Object} vueApp | ||
* @param {Object} notifications | ||
* @param {Object} pluginOptions | ||
*/ | ||
initVueNotificationPlugin (vueApp, notifications, pluginOptions) { | ||
if (!notifications) return | ||
Object.keys(notifications).forEach(name => { | ||
innerMethods.setMethod(vueApp, name, vueApp.$options, pluginOptions) | ||
}) | ||
/** | ||
* @param {Object} vueApp | ||
* @param {String} configName | ||
* @param {Object} options | ||
* @param {Object} pluginOptions | ||
* @return {Function} | ||
*/ | ||
function makeMethod (vueApp, configName, options, pluginOptions) { | ||
return function (config) { | ||
const newConfig = {} | ||
Object.assign(newConfig, VueNotifications.config) | ||
Object.assign(newConfig, options[VueNotifications.propertyName][configName]) | ||
Object.assign(newConfig, config) | ||
return showMessage(newConfig, pluginOptions, vueApp) | ||
vueApp.$emit(`${PACKAGE_NAME}-initiated`) | ||
} | ||
} | ||
/** | ||
* @param {Object} vueApp | ||
* @param {Object} notifications | ||
* @param {Object} pluginOptions | ||
*/ | ||
function initVueNotificationPlugin (vueApp, notifications, pluginOptions) { | ||
if (!notifications) return | ||
Object.keys(notifications).forEach(name => { | ||
setMethod(vueApp, name, vueApp.$options, pluginOptions) | ||
}) | ||
vueApp.$emit(`${PACKAGE_NAME}-initiated`) | ||
} | ||
const VueNotifications = { | ||
@@ -231,4 +239,4 @@ type: TYPE, | ||
if (this.installed) throw console.error(MESSAGES.alreadyInstalled) | ||
if (getVersion(Vue).major === VUE_VERSION.evangelion) hook = 'init' | ||
if (getVersion(Vue).major === VUE_VERSION.ghostInTheShell) hook = 'beforeCreate' | ||
if (innerMethods.getVersion(Vue).major === VUE_VERSION.evangelion) hook = 'init' | ||
if (innerMethods.getVersion(Vue).major === VUE_VERSION.ghostInTheShell) hook = 'beforeCreate' | ||
@@ -240,7 +248,7 @@ mixin[hook] = function () { | ||
initVueNotificationPlugin(vueApp, notificationsField, pluginOptions) | ||
innerMethods.initVueNotificationPlugin(vueApp, notificationsField, pluginOptions) | ||
} | ||
Vue.mixin(mixin) | ||
addMethods(this, this.type, pluginOptions) | ||
innerMethods.addMethods(this, this.type, pluginOptions) | ||
@@ -247,0 +255,0 @@ this.installed = true |
@@ -1,1 +0,1 @@ | ||
'use strict';var PLUGIN_NAME='VueNotifications',PACKAGE_NAME='vue-notifications',PROPERTY_NAME='notifications',TYPE={error:'error',warn:'warn',info:'info',success:'success'},VUE_VERSION={evangelion:1,ghostInTheShell:2},MESSAGES={alreadyInstalled:PLUGIN_NAME+': plugin already installed',methodNameConflict:PLUGIN_NAME+': names conflict - '};function getVersion(a){var b=a.version.match(/(\d+)/g);return{major:+b[0],regular:+b[1],minor:+b[2]}}function showInConsole(a,b,c){b===c.error?console.error(a):b===c.warn?console.warn(a):b===c.success?console.info(a):console.log(a)}function showDefaultMessage(_ref){var a=_ref.type,b=_ref.message,c=_ref.title,d=_ref.debugMsg,e='Title: '+c+', Message: '+b+', DebugMsg: '+d+', type: '+a;return showInConsole(e,a,TYPE),e}function showInlineMessage(_ref2){function i(l){l.innerText=''}var a=_ref2.id,b=_ref2.type,c=_ref2.timeout,d=_ref2.title,e=_ref2.message,f=_ref2.computed,g=_ref2.debugMsg,h=_ref2.cb;g&&showInConsole(g,b,TYPE);var j=document.getElementById(a),k=e;return d&&(k=d+': '+k),j.innerText=k,c&&!f&&setTimeout(function(){i(j)},c),h&&h(j,i),k}function getValues(a,b){var c={};return Object.keys(b).forEach(function(d){c[d]='cb'===d?b[d]:'function'==typeof b[d]?b[d].call(a):b[d]}),c}function showMessage(a,b,c){var d=getValues(c,a),e=!!d.id;if(e)showInlineMessage(d);else{var f=b&&b[d.type],g=f?b[d.type]:showDefaultMessage;g(d)}return a.cb?a.cb():void 0}function addMethods(a,b,c){Object.keys(b).forEach(function(d){a[b[d]]=function(e){return e.type=b[d],showMessage(e,c)}})}function setMethod(a,b,c,d){c.methods||(c.methods={}),c.methods[b]?console.error(MESSAGES.methodNameConflict+b):c.methods[b]=makeMethod(a,b,c,d)}function makeMethod(a,b,c,d){return function(e){var f={};return Object.assign(f,VueNotifications.config),Object.assign(f,c[VueNotifications.propertyName][b]),Object.assign(f,e),showMessage(f,d,a)}}function initVueNotificationPlugin(a,b,c){b&&(Object.keys(b).forEach(function(d){setMethod(a,d,a.$options,c)}),a.$emit(PACKAGE_NAME+'-initiated'))}var VueNotifications={type:TYPE,propertyName:PROPERTY_NAME,config:{type:TYPE.info,timeout:3000},installed:!1,install:function install(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c={},d=void 0;if(this.installed)throw console.error(MESSAGES.alreadyInstalled);getVersion(a).major===VUE_VERSION.evangelion&&(d='init'),getVersion(a).major===VUE_VERSION.ghostInTheShell&&(d='beforeCreate'),c[d]=function(){var e=this,f=this.$options,g=f[VueNotifications.propertyName];initVueNotificationPlugin(e,g,b)},a.mixin(c),addMethods(this,this.type,b),this.installed=!0}};'undefined'!=typeof window&&window.Vue&&window.Vue.use(VueNotifications); | ||
'use strict';var PLUGIN_NAME='VueNotifications',PACKAGE_NAME='vue-notifications',PROPERTY_NAME='notifications',TYPE={error:'error',warn:'warn',info:'info',success:'success'},VUE_VERSION={evangelion:1,ghostInTheShell:2},MESSAGES={alreadyInstalled:PLUGIN_NAME+': plugin already installed',methodNameConflict:PLUGIN_NAME+': names conflict - '},innerMethods={getVersion:function getVersion(a){var b=a.version.match(/(\d+)/g);return{major:+b[0],regular:+b[1],minor:+b[2]}},showInConsole:function showInConsole(a,b,c){b===c.error?console.error(a):b===c.warn?console.warn(a):b===c.success?console.info(a):console.log(a)},showDefaultMessage:function showDefaultMessage(_ref){var a=_ref.type,b=_ref.message,c=_ref.title,d=_ref.debugMsg,e='Title: '+c+', Message: '+b+', DebugMsg: '+d+', type: '+a;return innerMethods.showInConsole(e,a,TYPE),e},clearFn:function clearFn(a){a.innerText=''},showInlineMessage:function showInlineMessage(_ref2,i){var a=_ref2.id,b=_ref2.type,c=_ref2.timeout,d=_ref2.title,e=_ref2.message,f=_ref2.computed,g=_ref2.debugMsg,h=_ref2.cb;g&&innerMethods.showInConsole(g,b,TYPE);var j=document.getElementById(a),k=e;return d&&(k=d+': '+k),j.innerText=k,c&&!f&&setTimeout(function(){innerMethods.clearFn.call(i,j)},c),console.warn(this),h&&h.call(i,j,function(){return innerMethods.clearFn.call(innerMethods,j)}),k},getValues:function getValues(a,b){var c={};return Object.keys(b).forEach(function(d){'cb'===d?(console.info(a),c[d]=b[d].bind(a)):c[d]='function'==typeof b[d]?b[d].call(a):b[d]}),c},showMessage:function showMessage(a,b,c){var d=innerMethods.getValues(c,a),e=!!d.id;if(e)innerMethods.showInlineMessage(d,c);else{var f=b&&b[d.type],g=f?b[d.type]:innerMethods.showDefaultMessage;g(d,c)}return a.cb?a.cb():void 0},addMethods:function addMethods(a,b,c){Object.keys(b).forEach(function(d){a[b[d]]=function(e){return e.type=b[d],innerMethods.showMessage(e,c)}})},setMethod:function setMethod(a,b,c,d){c.methods||(c.methods={}),c.methods[b]?console.error(MESSAGES.methodNameConflict+b):c.methods[b]=innerMethods.makeMethod(a,b,c,d)},makeMethod:function makeMethod(a,b,c,d){return function(e){var f={};return Object.assign(f,VueNotifications.config),Object.assign(f,c[VueNotifications.propertyName][b]),Object.assign(f,e),innerMethods.showMessage(f,d,a)}},initVueNotificationPlugin:function initVueNotificationPlugin(a,b,c){b&&(Object.keys(b).forEach(function(d){innerMethods.setMethod(a,d,a.$options,c)}),a.$emit(PACKAGE_NAME+'-initiated'))}},VueNotifications={type:TYPE,propertyName:PROPERTY_NAME,config:{type:TYPE.info,timeout:3000},installed:!1,install:function install(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c={},d=void 0;if(this.installed)throw console.error(MESSAGES.alreadyInstalled);innerMethods.getVersion(a).major===VUE_VERSION.evangelion&&(d='init'),innerMethods.getVersion(a).major===VUE_VERSION.ghostInTheShell&&(d='beforeCreate'),c[d]=function(){var e=this,f=this.$options,g=f[VueNotifications.propertyName];innerMethods.initVueNotificationPlugin(e,g,b)},a.mixin(c),innerMethods.addMethods(this,this.type,b),this.installed=!0}};'undefined'!=typeof window&&window.Vue&&window.Vue.use(VueNotifications); |
{ | ||
"name": "vue-notifications", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"description": "Vuejs notifications", | ||
@@ -5,0 +5,0 @@ "main": "dist/vue-notifications.es5.js", |
11
TODO.md
### TODOs | ||
| Filename | line # | TODO | ||
|:------|:------:|:------ | ||
| main.js | 74 | @S.Panfilov handle class add and remove here | ||
| main.js | 92 | @S.Panfilov Computed property doesn't work yet | ||
| main.js | 98 | @S.Panfilov BUG: Weird behaviour: cb calls 2 times | ||
| main.js | 155 | @S.Panfilov fix 'vueApp' in param | ||
| main.js | 171 | @S.Panfilov not sure - throw error here or just warn | ||
| main.js | 82 | @S.Panfilov handle class add and remove here | ||
| main.js | 96 | @S.Panfilov Computed property doesn't work yet | ||
| main.js | 103 | @S.Panfilov BUG: Weird behaviour: cb calls 2 times | ||
| main.js | 106 | @S.Panfilov bug here | ||
| main.js | 163 | @S.Panfilov fix 'vueApp' in param | ||
| main.js | 179 | @S.Panfilov not sure - throw error here or just warn | ||
| unit/main.spec.js | 280 | @S.Panfilov fix this test |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59205
912