Skip to content

Commit c203043

Browse files
committed
Improved chatgpt.alert() performance
± Merged early return conditions - Rid laggy `willChange` prop + Made `transition` more specific
1 parent 548afd7 commit c203043

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

chatgpt.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,14 @@ const chatgpt = {
127127

128128
drag: {
129129
mousedown(event) { // find modal, update styles, attach listeners, init XY offsets
130-
if (event.button != 0) return // prevent non-left-click drag
131-
if (!/auto|default/.test(getComputedStyle(event.target).cursor))
132-
return // prevent drag on interactive elems
130+
if ( // prevent drag when...
131+
event.button != 0 // non-left-click
132+
|| !/auto|default/.test(getComputedStyle(event.target).cursor) // cursor changed
133+
) return
133134
chatgpt.draggingModal = event.currentTarget
134135
event.preventDefault() // prevent sub-elems like icons being draggable
135136
Object.assign(chatgpt.draggingModal.style, {
136-
transition: '0.1s', willChange: 'transform', transform: 'scale(1.05)' })
137+
transition: 'transform 0.1s ease', transform: 'scale(1.05)' })
137138
document.body.style.cursor = 'grabbing' // update cursor
138139
;[...chatgpt.draggingModal.children] // prevent hover FX if drag lags behind cursor
139140
.forEach(child => child.style.pointerEvents = 'none')
@@ -153,7 +154,7 @@ const chatgpt = {
153154

154155
mouseup() { // restore styles/pointer events, remove listeners, reset chatgpt.draggingModal
155156
Object.assign(chatgpt.draggingModal.style, { // restore styles
156-
cursor: 'inherit', transition: 'inherit', willChange: 'auto', transform: 'scale(1)' })
157+
cursor: 'inherit', transition: 'inherit', transform: 'scale(1)' })
157158
document.body.style.cursor = '' // restore cursor
158159
;[...chatgpt.draggingModal.children] // restore pointer events
159160
.forEach(child => child.style.pointerEvents = '')

0 commit comments

Comments
 (0)