@@ -27,42 +27,47 @@ import { initPluginDashboardYuiGuideRuntime } from './yui-guide-runtime'
2727initDarkMode ( )
2828initPluginDashboardYuiGuideRuntime ( )
2929
30- function initDecorativeImageDragGuard ( ) {
31- const markImage = ( img : HTMLImageElement ) => {
32- img . draggable = false
33- img . setAttribute ( 'draggable' , 'false' )
30+ function initNativeDragGuard ( ) {
31+ const markNativeDragSource = ( element : HTMLAnchorElement | HTMLImageElement ) => {
32+ element . draggable = false
33+ element . setAttribute ( 'draggable' , 'false' )
3434 }
3535
36- const markImages = ( root : ParentNode | HTMLImageElement = document ) => {
37- if ( root instanceof HTMLImageElement ) {
38- markImage ( root )
36+ const markNativeDragSources = ( root : ParentNode | HTMLAnchorElement | HTMLImageElement = document ) => {
37+ if ( root instanceof HTMLAnchorElement || root instanceof HTMLImageElement ) {
38+ markNativeDragSource ( root )
3939 return
4040 }
41- root . querySelectorAll < HTMLImageElement > ( 'img' ) . forEach ( markImage )
41+ root . querySelectorAll < HTMLAnchorElement | HTMLImageElement > ( 'a[href], img' ) . forEach ( markNativeDragSource )
4242 }
4343
4444 const handleDragStart = ( event : DragEvent ) => {
45- if ( event . target instanceof HTMLImageElement ) {
45+ const target = event . target
46+ if (
47+ target instanceof HTMLAnchorElement
48+ || target instanceof HTMLImageElement
49+ || ( target instanceof Element && target . closest ( 'a[href], img' ) )
50+ ) {
4651 event . preventDefault ( )
4752 }
4853 }
4954
50- markImages ( document )
55+ markNativeDragSources ( document )
5156 document . addEventListener ( 'dragstart' , handleDragStart , true )
5257
5358 const observer = new MutationObserver ( ( mutations ) => {
5459 mutations . forEach ( ( mutation ) => {
5560 mutation . addedNodes . forEach ( ( node ) => {
5661 if ( node instanceof Element ) {
57- markImages ( node )
62+ markNativeDragSources ( node )
5863 }
5964 } )
6065 } )
6166 } )
6267 observer . observe ( document . documentElement , { childList : true , subtree : true } )
6368}
6469
65- initDecorativeImageDragGuard ( )
70+ initNativeDragGuard ( )
6671
6772console . log ( '🚀 Starting N.E.K.O Plugin Management System...' )
6873
0 commit comments