From d157ffc746e3e4fdc1b588a3c4642c39085e9851 Mon Sep 17 00:00:00 2001
From: Randall Wilk
Date: Mon, 15 Oct 2018 08:55:20 -0500
Subject: [PATCH 1/5] Emit close and open events
---
dist/vue-context.js | 2 +-
src/vue-context.vue | 16 ++++++++++++----
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/dist/vue-context.js b/dist/vue-context.js
index 230b4b3..a232988 100644
--- a/dist/vue-context.js
+++ b/dist/vue-context.js
@@ -1 +1 @@
-!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(2),r=n.n(o);n.d(t,"VueContext",function(){return r.a})},function(e,t,n){var o=n(8)(n(9),n(10),!1,function(e){n(3)},"data-v-22758dc4",null);e.exports=o.exports},function(e,t,n){var o=n(4);"string"==typeof o&&(o=[[e.i,o,""]]),o.locals&&(e.exports=o.locals);n(6)("727e60ce",o,!0,{})},function(e,t,n){(e.exports=n(5)(!1)).push([e.i,".v-context[data-v-22758dc4]{background:#fafafa;border:1px solid #bdbdbd;box-shadow:0 2px 2px 0 rgba(0,0,0,.14),0 3px 1px -2px rgba(0,0,0,.2),0 1px 5px 0 rgba(0,0,0,.12);display:block;margin:0;padding:0;position:fixed;width:250px;z-index:99999}.v-context ul[data-v-22758dc4]{list-style:none;padding:10px 0;margin:0;font-size:12px;font-weight:600}.v-context ul li[data-v-22758dc4]{margin:0;padding:10px 35px;cursor:pointer}.v-context ul li[data-v-22758dc4]:hover{background:#1e88e5;color:#fafafa}",""])},function(e,t){e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n=function(e,t){var n=e[1]||"",o=e[3];if(!o)return n;if(t&&"function"==typeof btoa){var r=(s=o,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(s))))+" */"),i=o.sources.map(function(e){return"/*# sourceURL="+o.sourceRoot+e+" */"});return[n].concat(i).concat([r]).join("\n")}var s;return[n].join("\n")}(t,e);return t[2]?"@media "+t[2]+"{"+n+"}":n}).join("")},t.i=function(e,n){"string"==typeof e&&(e=[[null,e,""]]);for(var o={},r=0;rn.parts.length&&(o.parts.length=n.parts.length)}else{var s=[];for(r=0;rn&&(e=n),t>o&&(t=o),this.top=e,this.left=t},removeScrollEventListener:function(){window.removeEventListener("scroll",this.close)}},watch:{closeOnScroll:function(e,t){e!==t&&(e?this.addScrollEventListener():this.removeScrollEventListener())}}}},function(e,t){e.exports={render:function(){var e=this.$createElement;return(this._self._c||e)("div",{directives:[{name:"show",rawName:"v-show",value:this.show,expression:"show"}],staticClass:"v-context",style:this.style,attrs:{tabindex:"-1"},on:{blur:this.close,click:this.onClick,"!contextmenu":function(e){e.preventDefault()}}},[this._t("default",null,{data:this.data})],2)},staticRenderFns:[]}}])});
\ No newline at end of file
+!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(2),r=n.n(o);n.d(t,"VueContext",function(){return r.a})},function(e,t,n){var o=n(8)(n(9),n(10),!1,function(e){n(3)},"data-v-18aeaae6",null);e.exports=o.exports},function(e,t,n){var o=n(4);"string"==typeof o&&(o=[[e.i,o,""]]),o.locals&&(e.exports=o.locals);n(6)("50ad4866",o,!0,{})},function(e,t,n){(e.exports=n(5)(!1)).push([e.i,".v-context[data-v-18aeaae6]{background:#fafafa;border:1px solid #bdbdbd;box-shadow:0 2px 2px 0 rgba(0,0,0,.14),0 3px 1px -2px rgba(0,0,0,.2),0 1px 5px 0 rgba(0,0,0,.12);display:block;margin:0;padding:0;position:fixed;width:250px;z-index:99999}.v-context ul[data-v-18aeaae6]{list-style:none;padding:10px 0;margin:0;font-size:12px;font-weight:600}.v-context ul li[data-v-18aeaae6]{margin:0;padding:10px 35px;cursor:pointer}.v-context ul li[data-v-18aeaae6]:hover{background:#1e88e5;color:#fafafa}",""])},function(e,t){e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n=function(e,t){var n=e[1]||"",o=e[3];if(!o)return n;if(t&&"function"==typeof btoa){var r=(s=o,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(s))))+" */"),i=o.sources.map(function(e){return"/*# sourceURL="+o.sourceRoot+e+" */"});return[n].concat(i).concat([r]).join("\n")}var s;return[n].join("\n")}(t,e);return t[2]?"@media "+t[2]+"{"+n+"}":n}).join("")},t.i=function(e,n){"string"==typeof e&&(e=[[null,e,""]]);for(var o={},r=0;rn.parts.length&&(o.parts.length=n.parts.length)}else{var s=[];for(r=0;r0&&void 0!==arguments[0])||arguments[0];this.top=null,this.left=null,this.data=null,this.show=!1,e&&this.$emit("close")},onClick:function(){this.closeOnClick&&this.close(!1)},open:function(e,t){var n=this;this.data=t,this.show=!0,this.$nextTick(function(){n.positionMenu(e.clientY,e.clientX),n.$el.focus(),n.$emit("open",e,n.data,n.top,n.left)})},positionMenu:function(e,t){var n=window.innerHeight-this.$el.offsetHeight-25,o=window.innerWidth-this.$el.offsetWidth-25;e>n&&(e=n),t>o&&(t=o),this.top=e,this.left=t},removeScrollEventListener:function(){window.removeEventListener("scroll",this.close)}},watch:{closeOnScroll:function(e,t){e!==t&&(e?this.addScrollEventListener():this.removeScrollEventListener())}}}},function(e,t){e.exports={render:function(){var e=this.$createElement;return(this._self._c||e)("div",{directives:[{name:"show",rawName:"v-show",value:this.show,expression:"show"}],staticClass:"v-context",style:this.style,attrs:{tabindex:"-1"},on:{blur:this.close,click:this.onClick,"!contextmenu":function(e){e.preventDefault()}}},[this._t("default",null,{data:this.data})],2)},staticRenderFns:[]}}])});
\ No newline at end of file
diff --git a/src/vue-context.vue b/src/vue-context.vue
index daa7a4a..ee8f0d4 100644
--- a/src/vue-context.vue
+++ b/src/vue-context.vue
@@ -45,7 +45,7 @@
return this.show
? { top: `${this.top}px`, left: `${this.left}px` }
: null;
- },
+ }
},
data () {
@@ -79,12 +79,18 @@
/**
* Close the context menu.
+ *
+ * @param {boolean|Event} emit Used to prevent event being emitted twice from when menu is clicked and closed
*/
- close () {
+ close (emit = true) {
this.top = null;
this.left = null;
this.data = null;
this.show = false;
+
+ if (emit) {
+ this.$emit('close');
+ }
},
/**
@@ -92,7 +98,7 @@
*/
onClick () {
if (this.closeOnClick) {
- this.close();
+ this.close(false);
}
},
@@ -109,6 +115,8 @@
this.$nextTick(() => {
this.positionMenu(event.clientY, event.clientX);
this.$el.focus();
+
+ this.$emit('open', event, this.data, this.top, this.left);
});
},
@@ -200,4 +208,4 @@
}
}
}
-
\ No newline at end of file
+
From 604aaa9c1d2ddbe3168bf1c51f14915a0ef4d31d Mon Sep 17 00:00:00 2001
From: Randall Wilk
Date: Mon, 15 Oct 2018 08:59:35 -0500
Subject: [PATCH 2/5] Test event emitting
---
test/index.html | 7 +++++--
test/js/dist/index.js | 4 ++--
test/js/dist/test_issue_4.js | 2 +-
test/js/src/index.js | 12 ++++++++++--
4 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/test/index.html b/test/index.html
index aebc1a6..b367a66 100644
--- a/test/index.html
+++ b/test/index.html
@@ -10,7 +10,10 @@
Right click on me
-
+
- Option 1 {{ child.data && child.data.foo }}
- Option 2
@@ -20,4 +23,4 @@