Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nodenoggin vue3 duplicate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Adam Procter
nodenoggin vue3 duplicate
Commits
373bc8de
Commit
373bc8de
authored
3 years ago
by
Adam Procter
Browse files
Options
Downloads
Patches
Plain Diff
drag v1
parent
0f192309
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/SpaceBase.vue
+78
-20
78 additions, 20 deletions
src/components/SpaceBase.vue
with
78 additions
and
20 deletions
src/components/SpaceBase.vue
+
78
−
20
View file @
373bc8de
<
template
>
<
template
>
<div
v-for=
"(nodes, index) in myArray"
:key=
"index"
>
<svg
xmlns=
"http://www.w3.org/2000/svg"
viewBox=
"0 0 1000 10000"
ref=
"myref"
>
<svg
<g
class=
"draggable-group"
v-for=
"(nodes, index) in myArray"
:key=
"index"
>
xmlns=
"http://www.w3.org/2000/svg"
<rect
width=
"150"
height=
"200"
style=
"fill: rgb(255, 0, 100)"
/>
viewBox=
"0 0 1000 10000"
<foreignObject
id=
"x"
x=
"10"
width=
"131"
height=
"100"
>
onload=
"makeDraggable(evt)"
<textarea
rows=
"3"
cols=
"30"
v-model=
"nodes.node_text"
></textarea>
>
</foreignObject>
<g
class=
"draggable-group"
>
</g>
<rect
width=
"150"
height=
"200"
style=
"fill: rgb(255, 0, 100)"
/>
</svg>
<foreignObject
id=
"x"
x=
"10"
width=
"131"
height=
"100"
>
<textarea
rows=
"3"
cols=
"30"
v-model=
"nodes.node_text"
></textarea>
</foreignObject>
</g>
</svg>
</div>
</
template
>
</
template
>
<
script
>
<
script
>
// @ is an alias to /src
// @ is an alias to /src
import
{
mapState
}
from
'
vuex
'
import
{
mapState
}
from
'
vuex
'
import
drag
from
'
@/mixins/drag
'
//
import drag from '@/mixins/drag'
export
default
{
export
default
{
name
:
'
SpaceBase
'
,
name
:
'
SpaceBase
'
,
...
@@ -61,13 +55,14 @@ export default {
...
@@ -61,13 +55,14 @@ export default {
},
},
},
},
mixins
:
[
//
mixins: [
drag
(
'
something
'
,
function
()
{
//
drag(
this.$refs.svg
, function () {
// drag
//
// drag
}),
//
}),
],
//
],
mounted
()
{
mounted
()
{
makeDraggable
(
this
.
$refs
.
myref
)
setTimeout
(
this
.
loadData
,
500
)
setTimeout
(
this
.
loadData
,
500
)
if
(
localStorage
.
nogg_name
&&
localStorage
.
nogg_microcosm
)
{
if
(
localStorage
.
nogg_name
&&
localStorage
.
nogg_microcosm
)
{
var
devicename
=
localStorage
.
nogg_name
var
devicename
=
localStorage
.
nogg_name
...
@@ -81,6 +76,69 @@ export default {
...
@@ -81,6 +76,69 @@ export default {
}
}
},
},
}
}
// PLAIN JS should be a mixin
function
makeDraggable
(
svg
)
{
// var svg = evt.target
svg
.
addEventListener
(
'
mousedown
'
,
startDrag
)
svg
.
addEventListener
(
'
mousemove
'
,
drag
)
svg
.
addEventListener
(
'
mouseup
'
,
endDrag
)
svg
.
addEventListener
(
'
mouseleave
'
,
endDrag
)
svg
.
addEventListener
(
'
touchstart
'
,
startDrag
)
svg
.
addEventListener
(
'
touchmove
'
,
drag
)
svg
.
addEventListener
(
'
touchend
'
,
endDrag
)
svg
.
addEventListener
(
'
touchleave
'
,
endDrag
)
svg
.
addEventListener
(
'
touchcancel
'
,
endDrag
)
function
getMousePosition
(
evt
)
{
var
CTM
=
svg
.
getScreenCTM
()
if
(
evt
.
touches
)
{
evt
=
evt
.
touches
[
0
]
}
return
{
x
:
(
evt
.
clientX
-
CTM
.
e
)
/
CTM
.
a
,
y
:
(
evt
.
clientY
-
CTM
.
f
)
/
CTM
.
d
,
}
}
var
selectedElement
,
offset
,
transform
function
initialiseDragging
(
evt
)
{
offset
=
getMousePosition
(
evt
)
// Make sure the first transform on the element is a translate transform
var
transforms
=
selectedElement
.
transform
.
baseVal
if
(
transforms
.
length
===
0
||
transforms
.
getItem
(
0
).
type
!==
SVGTransform
.
SVG_TRANSFORM_TRANSLATE
)
{
// Create an transform that translates by (0, 0)
var
translate
=
svg
.
createSVGTransform
()
translate
.
setTranslate
(
0
,
0
)
selectedElement
.
transform
.
baseVal
.
insertItemBefore
(
translate
,
0
)
}
// Get initial translation
transform
=
transforms
.
getItem
(
0
)
offset
.
x
-=
transform
.
matrix
.
e
offset
.
y
-=
transform
.
matrix
.
f
}
function
startDrag
(
evt
)
{
if
(
evt
.
target
.
classList
.
contains
(
'
draggable
'
))
{
selectedElement
=
evt
.
target
initialiseDragging
(
evt
)
}
else
if
(
evt
.
target
.
parentNode
.
classList
.
contains
(
'
draggable-group
'
))
{
selectedElement
=
evt
.
target
.
parentNode
initialiseDragging
(
evt
)
}
}
function
drag
(
evt
)
{
if
(
selectedElement
)
{
evt
.
preventDefault
()
var
coord
=
getMousePosition
(
evt
)
transform
.
setTranslate
(
coord
.
x
-
offset
.
x
,
coord
.
y
-
offset
.
y
)
}
}
function
endDrag
()
{
selectedElement
=
false
}
}
</
script
>
</
script
>
<
style
scoped
>
<
style
scoped
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment