Skip to content
Snippets Groups Projects
Commit 28c06e08 authored by Xiao Gui's avatar Xiao Gui Committed by xgui3783
Browse files

bugfix: firefox drag should no longer highlight dom elements

parent 2bea689d
No related branches found
No related tags found
No related merge requests found
import { Component, ViewChild, ViewContainerRef,ComponentRef, HostBinding, HostListener, Output, EventEmitter, Input } from "@angular/core"; import { Component, ViewChild, ViewContainerRef,ComponentRef, HostBinding, HostListener, Output, EventEmitter, Input, ElementRef } from "@angular/core";
import { WidgetServices } from "./widgetService.service"; import { WidgetServices } from "./widgetService.service";
...@@ -11,6 +11,7 @@ import { WidgetServices } from "./widgetService.service"; ...@@ -11,6 +11,7 @@ import { WidgetServices } from "./widgetService.service";
export class WidgetUnit { export class WidgetUnit {
@ViewChild('container',{read:ViewContainerRef}) container : ViewContainerRef @ViewChild('container',{read:ViewContainerRef}) container : ViewContainerRef
@ViewChild('emptyspan',{read:ElementRef}) emtpy : ElementRef
@HostBinding('attr.state') @HostBinding('attr.state')
public state : 'docked' | 'floating' = 'docked' public state : 'docked' | 'floating' = 'docked'
...@@ -96,31 +97,34 @@ export class WidgetUnit { ...@@ -96,31 +97,34 @@ export class WidgetUnit {
reposStartMousePos : [number,number] = [0,0] reposStartMousePos : [number,number] = [0,0]
repositionFlag : boolean = false repositionFlag : boolean = false
@HostListener('document:mousemove',['$event']) /* nb FF does not provide event.clientX / event.clientY on drag event. So will have to attach dragover event listener */
/* ref: https://bugzilla.mozilla.org/show_bug.cgi?id=505521 */
@HostListener('document:dragover',['$event'])
mousemove(ev:MouseEvent){ mousemove(ev:MouseEvent){
if(!this.repositionFlag) return if(this.repositionFlag){
this.position[0] = this.reposStartViewPos[0] - this.reposStartMousePos[0] + ev.clientX
this.position[1] = this.reposStartViewPos[1] - this.reposStartMousePos[1] + ev.clientY
}
}
this.position[0] = this.reposStartViewPos[0] - this.reposStartMousePos[0] + ev.clientX dragend(ev:DragEvent){
this.position[1] = this.reposStartViewPos[1] - this.reposStartMousePos[1] + ev.clientY this.repositionFlag = false
} }
mousedown(ev:MouseEvent){ dragstart(ev:DragEvent){
this.reposStartMousePos[0] = ev.clientX this.reposStartMousePos[0] = ev.clientX
this.reposStartMousePos[1] = ev.clientY this.reposStartMousePos[1] = ev.clientY
this.reposStartViewPos[0] = this.position[0] this.reposStartViewPos[0] = this.position[0]
this.reposStartViewPos[1] = this.position[1] this.reposStartViewPos[1] = this.position[1]
this.repositionFlag = true; this.repositionFlag = true
document.body.style.pointerEvents = 'none'
document.body.style.userSelect = 'none' /* nb FF requires dataTransfer.setData in order to fire the drag or dragover event */
} ev.dataTransfer.setData('application/node type', '')
@HostListener('document:mouseup',['$event']) /* nb FF will render any invisible DOM element as a file icon. */
mouseup(_ev:MouseEvent){ ev.dataTransfer.setDragImage(this.emtpy.nativeElement, 0, 0)
this.repositionFlag = false;
document.body.style.pointerEvents = 'all'
document.body.style.userSelect = 'initial'
} }
get transform(){ get transform(){
......
...@@ -41,4 +41,9 @@ panel-component[widgetUnitPanel] ...@@ -41,4 +41,9 @@ panel-component[widgetUnitPanel]
:host-context([state='floating']) div[widgetUnitHeading]:hover :host-context([state='floating']) div[widgetUnitHeading]:hover
{ {
cursor : move; cursor : move;
}
[emptyspan]
{
opacity:0.01;
} }
\ No newline at end of file
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
[style.transform] = "transform" [style.transform] = "transform"
[containerClass] = "containerClass" [containerClass] = "containerClass"
widgetUnitPanel widgetUnitPanel
[bodyCollapsable] = "state === 'docked'" [bodyCollapsable] = "state === 'docked'">
>
<div <div
(mousedown) = "mousedown($event)" draggable = "true"
(dragend) = "dragend($event)"
(dragstart) = "dragstart($event)"
widgetUnitHeading widgetUnitHeading
heading> heading>
<div #emptyspan emptyspan>.</div>
<div title>{{ title }}</div> <div title>{{ title }}</div>
<div icons> <div icons>
<i *ngIf = "state === 'floating'" <i *ngIf = "state === 'floating'"
......
...@@ -45,8 +45,10 @@ export class DropdownComponent{ ...@@ -45,8 +45,10 @@ export class DropdownComponent{
@HostListener('document:click',['$event']) @HostListener('document:click',['$event'])
close(event:MouseEvent){ close(event:MouseEvent){
/* FF does not implement event.srcElement so use event.originalTarget to polyfill for FF */ /* FF <62 does not implement event.srcElement so use event.originalTarget to polyfill for FF */
const contains = this.dropdownToggle.nativeElement.contains(event.srcElement) || this.dropdownToggle.nativeElement.contains((event as any).originalTarget) const contains = event.srcElement
? this.dropdownToggle.nativeElement.contains(event.srcElement)
: this.dropdownToggle.nativeElement.contains((event as any).originalTarget)
if(contains) if(contains)
this.openState = !this.openState this.openState = !this.openState
else else
......
...@@ -185,8 +185,11 @@ export class AtlasBanner implements OnDestroy{ ...@@ -185,8 +185,11 @@ export class AtlasBanner implements OnDestroy{
if(!this.inputRegionPopover) if(!this.inputRegionPopover)
return return
/* FF does not implement event.srcElement so use event.originalTarget to polyfill for FF */ /* FF < 62 does not implement event.srcElement so use event.originalTarget to polyfill for FF */
const contains = this.inputRegionPopover.nativeElement.contains(event.srcElement) || this.inputRegionPopover.nativeElement.contains((event as any).originalTarget)
const contains = event.srcElement
? this.inputRegionPopover.nativeElement.contains(event.srcElement)
: this.inputRegionPopover.nativeElement.contains((event as any).originalTarget)
if(contains) if(contains)
this.showRegionTree = true this.showRegionTree = true
else else
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment