Strange behaviour of custom drag and drop function - vuejs2

I'm currently creating an electron application (Frontend is in Vue) which can trigger native Drag-and-Drop-Operations. These Operations behave strange if i trigger them with HTML5 Drag Events (like dragstart, dragstop, etc.). So I have to implement my own Drag-and-Drop Handler using mouseup, mousedown and mousemove. So in simple theory:
If MouseDown is triggered -> Set Flag
If MouseUp is triggered -> Remove Flag
If MouseMove AND Flag -> checkCurrentPosition vs. initialPosition -> Do something
new Vue({
el: "#app",
data: {
mousedown: false
},
methods: {
onMouseDown: function(e){
console.log('mousedown');
this.mousedown = true;
},
onMouseUp: function(e){
console.log('mouseup');
this.mousedown = false;
},
onMouseMove: function(e){
if(this.mousedown) {
console.log('mousedown && mousemove');
console.log('clientX:', e.clientX);
console.log('clientY:', e.clientY);
}
},
}
})
Fiddle
if you check this example, open up your browsers console and play a little bit around with the image (click, drag and drop,...) you will see that if you drag the placeholder image, the mousedown event is triggered and the flag is set. Then I would expect that the mousemove event would be triggered frequently, but this is not happening.
Normally if you bind mousemove to some Div its triggered frequently if you hover with your mouse over it and you can get the actual position for example. But this is not happening after mousedown.
NOTE: The mouseup event in the Fiddle is not bound to Window, so if you Drop the Element outside of its area the mouseup event will not be triggered for the element. So the flag is not removed and then you can see the behaviour I would expect. the mousemove event is frequently triggered. So I think that the problem is that while the mouse is pressed the mousemove event is not triggered correctly.

Related

How to capture event on click of close button in dojo Modaldialog?

I want to do some action on close button for ModalDialog box. I am using "idx.widget.modaldialog" in dojo. Is there any way to capture the close event?
The idx.widget.modaldialog extends the dijit.dialog so you can implement the onClose method.
For example:
onClose: lang.hitch(this, function(){
// some code
}),

TestCafe: how to set a button component on a page to a pressed state where its a click but not released?

I'm creating an automated test to test the different specs or attributes of an element (button component) but in order to do this, I have to force the button to specific states like - pressed and disabled states. I have already done it for the focus and hover states.
how to set a button element/component on a page to a pressed state where the button is clicked but not released - similar to a key down? Asking since the specs (Text color and background color) of a clicked state and a pressed state are different.
how to set a button element/component on a page to a disabled state.
Is it even possible to force element state similar to inspect/dev tools using the browser?
thanks
Currently you cannot provide the mousedown action without a further mouseup action as well as forcing an element state like in DevTools.
However, if you want to set button state to disabled, I think the ClientFunctions mechanism can help you. See the following code:
import { Selector, ClientFunction } from 'testcafe';
fixture ``
.page ``;
const btn = Selector('button');
const setDisabled = ClientFunction(() => {
btn().setAttribute('disabled', 'disabled');
}, { dependencies: { btn } });
test('test', async t => {
await setDisabled();
});

Vue ctrl+s event listener not firing

My application dialog should respond to "Ctrl+S" for a save function and cancel the default browser Save event.
<div
#keyup.83="doSave"
#keyup.ctrl.83="doSave"
#keyup.alt.83="doSave"
tabindex="0">
The doSave event is fired on pressing 's' (and alt+s) but not on ctrl+s.
Why is ctrl+s not fired?
BONUS QUESTION: Is there a way to preventDefault without coding it? Somehow it should be possible adding .once but the docs are vague.
https://codepen.io/cawoodm/pen/qvgxPL
There are several questions packed into your question, so I am going to answer them one by one:
Why is ctrl+s not fired?
Several reasons. You are using the keyup event, while the browser starts to save the page on a keydown event. Your keyup event is thus never fired.
For any event to be registered on your div, your div must have focus, because otherwise the event will not originate from that element, but instead from (presumably) the body.
Is there a way to preventDefault without coding it?
Yes. Add the prevent modifier to your event. In the same way, you can use once to unregister an event after it has triggered once, stop to use stopPropagation() and passive to explicitly not stop propagation. You would use something like: #keydown.ctrl.83.prevent="saveMe".
How do I get this working?
If you are fine with the user having to focus the element before being able to save, and otherwise getting the default behaviour, use the following:
<div
id="app"
tabindex="0"
#keydown.ctrl.83.prevent.stop="saveInsideComponent"
>
<!-- -->
</div>
Otherwise, this is one of the few moments where registering your own event listener is useful. Just make sure to remove it before your component is destroyed, or you will have a rogue event listener throwing errors on other components + a memory leak to deal with.
mounted() {
document.addEventListener("keydown", this.doSave);
},
beforeDestroy() {
document.removeEventListener("keydown", this.doSave);
},
methods: {
doSave(e) {
if (!(e.keyCode === 83 && e.ctrlKey)) {
return;
}
e.preventDefault();
console.log("saving from DOM!");
},
}
#Sumurai8's answer is great but I would add support for apple devices by checking if e.metaKey is == true. The code then looks like this:
mounted() {
document.addEventListener("keydown", this.doSave);
},
beforeDestroy() {
document.removeEventListener("keydown", this.doSave);
},
methods: {
doSave(e) {
if (!(e.keyCode === 83 && (e.ctrlKey || e.metaKey))) {
return;
}
e.preventDefault();
console.log("saving from DOM!");
},
}

Is there a "onExpand" event or similar for dijit.TitlePane?

Is there any way to get an event callback when the dojo-dijit's TitlePane expands?
I can capture onClick on the TitlePane. However, that is not enough for me. I have a button for "Expand All" TitlePanes. When user clicks on that I iterate on all TitlePanes and call it's toggle() method. When that happens, onClick event is not fired (as expected). I was wondering if there is any event fired upon toggle().
Or any other smart ways to address it also will be appreciated.
After looking into documentation in detail, I do not think there is any built in event that is fired during the toggle/expand. I ended up firing a custom event, and that helped me get what I wanted.
This answer helped me - https://stackoverflow.com/a/12852043/3810374
Basically,
First using isOpen() method, ensure the title pane is not already expanded. Then call toggle() method, and fire a custom event like this:
require(["dojo/on"], function(on){
// Send event
on.emit(target, "onExpand", {
bubbles: true,
cancelable: true
});
});
And then handle the event:
require(["dojo/on"], function(on){
// register event handler
on(target, "onExpand", function(e){
// handle event
});
});
You may be wondering, why not just do the work right after toggle(), instead of going through the pain of firing/handling event. I needed to handle the event in a particular closure, where I have access to other objects and variables.

call a function when tapping on mask outside a floating component

I'm working on a Sencha touch app. Inside a listener, I set up a panel with hideOnMaskTap set to true (based on code from the floating components documentation):
onTap: function() {
Ext.Viewport.add({
xtype: 'panel',
modal: true,
hideOnMaskTap: true,
...
}
This works as expected. Apart from hiding the panel, I would like to call a function when the user taps on the mask. After looking at the sencha documentation and having googled many things, I haven't been able to find a way to make such a call.
Any pointers would be greatly appreciated.
When modal:true and hideOnMaskTap:true, once you click on the mask, the component will be hidden. This will fire the hide event.
hide( Ext.Component this, Object eOpts )
Fires whenever the Component is hidden
Write your code in the handler for this event.