Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor 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
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
f166654b
Commit
f166654b
authored
4 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-4644: reactive point events, remove document listener, stop 2x stop
parent
b6573d5b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/webapp/static/js/jquery/openolat/jquery.paint.js
+42
-12
42 additions, 12 deletions
src/main/webapp/static/js/jquery/openolat/jquery.paint.js
with
42 additions
and
12 deletions
src/main/webapp/static/js/jquery/openolat/jquery.paint.js
+
42
−
12
View file @
f166654b
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
var
usePointerApi
=
false
;
var
usePointerApi
=
false
;
if
(
window
.
PointerEvent
)
{
if
(
window
.
PointerEvent
)
{
usePointerApi
=
fals
e
;
usePointerApi
=
tru
e
;
}
}
var
useRequestAnimationFrame
=
false
;
var
useRequestAnimationFrame
=
false
;
...
@@ -113,7 +113,7 @@
...
@@ -113,7 +113,7 @@
var
startEvents
=
usePointerApi
?
'
pointerdown
'
:
'
mousedown touchstart
'
;
var
startEvents
=
usePointerApi
?
'
pointerdown
'
:
'
mousedown touchstart
'
;
var
leaveEvents
=
usePointerApi
?
'
pointerleave
'
:
'
mouseleave
'
;
var
leaveEvents
=
usePointerApi
?
'
pointerleave
'
:
'
mouseleave
'
;
var
enterEvents
=
usePointerApi
?
'
pointerenter
'
:
'
mouseenter
'
;
var
enterEvents
=
usePointerApi
?
'
pointerenter
'
:
'
mouseenter
'
;
var
stopLeaveEvents
=
usePointerApi
?
'
pointerup
click
'
:
'
mouseup touchend
'
;
var
stopLeaveEvents
=
usePointerApi
?
'
pointerup
'
:
'
mouseup touchend
'
;
var
stopEvents
=
usePointerApi
?
'
pointerup click
'
:
'
mouseup click touchend
'
;
var
stopEvents
=
usePointerApi
?
'
pointerup click
'
:
'
mouseup click touchend
'
;
var
moveEvents
=
usePointerApi
?
'
pointermove
'
:
'
mousemove touchmove
'
;
var
moveEvents
=
usePointerApi
?
'
pointermove
'
:
'
mousemove touchmove
'
;
...
@@ -123,12 +123,15 @@
...
@@ -123,12 +123,15 @@
});
});
/* Mouse Capturing Work out of the canvas */
/* Mouse Capturing Work out of the canvas */
jQuery
(
document
).
on
(
moveEvents
,
function
(
e
)
{
jQuery
(
document
).
on
(
moveEvents
,
function
catchMouseLeave
(
e
)
{
if
(
mouse
.
leave
)
{
if
(
mouse
.
leave
)
{
var
rect
=
tmp_canvas
.
getBoundingClientRect
();
var
rect
=
tmp_canvas
.
getBoundingClientRect
();
mouse
.
out_x
=
e
.
clientX
-
rect
.
left
;
mouse
.
out_x
=
e
.
clientX
-
rect
.
left
;
mouse
.
out_y
=
e
.
clientY
-
rect
.
top
;
mouse
.
out_y
=
e
.
clientY
-
rect
.
top
;
}
}
if
(
jQuery
(
"
#
"
+
sketchId
).
length
==
0
)
{
jQuery
(
document
).
off
(
moveEvents
,
catchMouseLeave
);
}
});
});
jQuery
(
this
.
canvas
).
on
(
moveEvents
,
function
(
e
)
{
jQuery
(
this
.
canvas
).
on
(
moveEvents
,
function
(
e
)
{
...
@@ -171,9 +174,10 @@
...
@@ -171,9 +174,10 @@
if
(
tool
==
"
brush
"
)
{
if
(
tool
==
"
brush
"
)
{
ppts
.
push
({
x
:
-
1
,
y
:
-
1
});
ppts
.
push
({
x
:
-
1
,
y
:
-
1
});
}
}
jQuery
(
document
).
on
(
stopLeaveEvents
,
function
(
e
)
{
jQuery
(
document
).
on
(
stopLeaveEvents
,
function
stopListener
()
{
stopPainting
();
stopPainting
();
jQuery
(
document
).
off
(
stopLeaveEvents
,
stopListener
);
});
});
});
});
...
@@ -204,8 +208,10 @@
...
@@ -204,8 +208,10 @@
};
};
var
stopPainting
=
function
()
{
var
stopPainting
=
function
()
{
jQuery
(
tmp_canvas
).
off
(
moveEvents
,
onPaint
);
if
(
!
mouse
.
paint
)
return
;
mouse
.
paint
=
false
;
jQuery
(
tmp_canvas
).
off
(
moveEvents
,
onPaint
);
// for erasing
// for erasing
ctx
.
globalCompositeOperation
=
'
source-over
'
;
ctx
.
globalCompositeOperation
=
'
source-over
'
;
//spraying tool.
//spraying tool.
...
@@ -271,11 +277,11 @@
...
@@ -271,11 +277,11 @@
modal
+=
'
</div>
'
;
modal
+=
'
</div>
'
;
modal
+=
'
</div>
'
;
modal
+=
'
</div>
'
;
jQuery
(
"
body
"
).
append
(
modal
);
jQuery
(
"
body
"
).
append
(
modal
);
$
(
'
#paintModal
'
).
modal
(
'
show
'
);
jQuery
(
'
#paintModal
'
).
modal
(
'
show
'
);
$
(
'
#paintModal button.btn-primary
'
).
on
(
'
click
'
,
function
()
{
jQuery
(
'
#paintModal button.btn-primary
'
).
on
(
'
click
'
,
function
()
{
ctx
.
clearRect
(
0
,
0
,
tmp_canvas
.
width
,
tmp_canvas
.
height
);
ctx
.
clearRect
(
0
,
0
,
tmp_canvas
.
width
,
tmp_canvas
.
height
);
});
});
$
(
'
#paintModal
'
).
on
(
'
hidden.bs.modal
'
,
function
(
event
)
{
jQuery
(
'
#paintModal
'
).
on
(
'
hidden.bs.modal
'
,
function
(
event
)
{
jQuery
(
"
#paintModal
"
).
remove
();
jQuery
(
"
#paintModal
"
).
remove
();
});
});
o_scrollToElement
(
'
#o_top
'
);
o_scrollToElement
(
'
#o_top
'
);
...
@@ -313,6 +319,10 @@
...
@@ -313,6 +319,10 @@
};
};
var
drawPaintBrush
=
function
()
{
var
drawPaintBrush
=
function
()
{
if
(
!
mouse
.
paint
)
{
return
;
}
// Tmp canvas is always cleared up before drawing.
// Tmp canvas is always cleared up before drawing.
tmp_ctx
.
clearRect
(
0
,
0
,
tmp_canvas
.
width
,
tmp_canvas
.
height
);
tmp_ctx
.
clearRect
(
0
,
0
,
tmp_canvas
.
width
,
tmp_canvas
.
height
);
...
@@ -345,6 +355,10 @@
...
@@ -345,6 +355,10 @@
};
};
var
onPaintLine
=
function
()
{
var
onPaintLine
=
function
()
{
if
(
!
mouse
.
paint
)
{
return
;
}
// Tmp canvas is always cleared up before drawing.
// Tmp canvas is always cleared up before drawing.
tmp_ctx
.
clearRect
(
0
,
0
,
tmp_canvas
.
width
,
tmp_canvas
.
height
);
tmp_ctx
.
clearRect
(
0
,
0
,
tmp_canvas
.
width
,
tmp_canvas
.
height
);
...
@@ -356,6 +370,10 @@
...
@@ -356,6 +370,10 @@
};
};
var
onPaintCircle
=
function
()
{
var
onPaintCircle
=
function
()
{
if
(
!
mouse
.
paint
)
{
return
;
}
// Tmp canvas is always cleared up before drawing.
// Tmp canvas is always cleared up before drawing.
tmp_ctx
.
clearRect
(
0
,
0
,
tmp_canvas
.
width
,
tmp_canvas
.
height
);
tmp_ctx
.
clearRect
(
0
,
0
,
tmp_canvas
.
width
,
tmp_canvas
.
height
);
...
@@ -364,15 +382,19 @@
...
@@ -364,15 +382,19 @@
var
x
=
(
mx
+
start_mouse
.
x
)
/
2
;
var
x
=
(
mx
+
start_mouse
.
x
)
/
2
;
var
y
=
(
my
+
start_mouse
.
y
)
/
2
;
var
y
=
(
my
+
start_mouse
.
y
)
/
2
;
var
r
adius
=
Math
.
max
(
Math
.
abs
(
mx
-
start_mouse
.
x
),
Math
.
abs
(
my
-
start_mouse
.
y
))
/
2
;
var
circleR
adius
=
Math
.
max
(
Math
.
abs
(
mx
-
start_mouse
.
x
),
Math
.
abs
(
my
-
start_mouse
.
y
))
/
2
;
tmp_ctx
.
beginPath
();
tmp_ctx
.
beginPath
();
tmp_ctx
.
arc
(
x
,
y
,
r
adius
,
0
,
Math
.
PI
*
2
,
false
);
tmp_ctx
.
arc
(
x
,
y
,
circleR
adius
,
0
,
Math
.
PI
*
2
,
false
);
tmp_ctx
.
stroke
();
tmp_ctx
.
stroke
();
tmp_ctx
.
closePath
();
tmp_ctx
.
closePath
();
};
};
var
onPaintRect
=
function
()
{
var
onPaintRect
=
function
()
{
if
(
!
mouse
.
paint
)
{
return
;
}
// Tmp canvas is always cleared up before drawing.
// Tmp canvas is always cleared up before drawing.
tmp_ctx
.
clearRect
(
0
,
0
,
tmp_canvas
.
width
,
tmp_canvas
.
height
);
tmp_ctx
.
clearRect
(
0
,
0
,
tmp_canvas
.
width
,
tmp_canvas
.
height
);
...
@@ -386,7 +408,11 @@
...
@@ -386,7 +408,11 @@
tmp_ctx
.
strokeRect
(
x
,
y
,
width
,
height
);
tmp_ctx
.
strokeRect
(
x
,
y
,
width
,
height
);
};
};
function
onPaintEllipse
(
ctx
)
{
function
onPaintEllipse
()
{
if
(
!
mouse
.
paint
)
{
return
;
}
tmp_ctx
.
clearRect
(
0
,
0
,
tmp_canvas
.
width
,
tmp_canvas
.
height
);
tmp_ctx
.
clearRect
(
0
,
0
,
tmp_canvas
.
width
,
tmp_canvas
.
height
);
var
mx
=
mouse
.
leave
?
mouse
.
out_x
:
mouse
.
x
;
var
mx
=
mouse
.
leave
?
mouse
.
out_x
:
mouse
.
x
;
...
@@ -417,6 +443,10 @@
...
@@ -417,6 +443,10 @@
}
}
var
onErase
=
function
()
{
var
onErase
=
function
()
{
if
(
!
mouse
.
paint
)
{
return
;
}
// Saving all the points in an array
// Saving all the points in an array
ppts
.
push
({
x
:
mouse
.
x
,
y
:
mouse
.
y
});
ppts
.
push
({
x
:
mouse
.
x
,
y
:
mouse
.
y
});
...
...
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