-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support Grid Item Movement via External Element (outside Grid) Drag #3024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
| <title>Title area drag from outside GridStack item</title> | ||
|
|
||
| <link rel="stylesheet" href="demo.css" /> | ||
| <script src="../dist/gridstack-all.js"></script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div class="container-fluid"> | ||
| <h1>Title area drag from outside GridStack item</h1> | ||
| <br><br> | ||
| <div class="card-header outside">- Drag here -</div> | ||
| <div class="grid-stack"> | ||
| <div class="grid-stack-item external" gs-w="3" gs-h="3"> | ||
| <div class="grid-stack-item-content"> | ||
| <div class="card">Hover on the panel to toggle drag title (which is outside grid-stack-item) visibility. The | ||
| rest of the panel content doesn't drag.</div> | ||
| </div> | ||
| </div> | ||
| <div class="grid-stack-item" gs-w="3" gs-h="3"> | ||
| <div class="grid-stack-item-content"> | ||
| <div class="card-header">- Drag here -</div> | ||
| <div class="card">This panel has title inside grid item. Only title drags, rest of the panel content doesn't drag.</div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <script src="events.js"></script> | ||
| <script type="text/javascript"> | ||
| let grid = GridStack.init({ | ||
| handle: '.card-header' | ||
| }); // drag by the header only | ||
| addEvents(grid); | ||
| const itemWithExternalTitle = document.querySelector('.grid-stack-item.external'); | ||
| const externalTitle = document.querySelector('.card-header.outside'); | ||
| grid.update(itemWithExternalTitle, {noResize: true, noMove: true}); | ||
| GridStack.setupDragIn([itemWithExternalTitle], { | ||
| dragElements: [externalTitle] | ||
| }); | ||
| grid.update(itemWithExternalTitle, {noResize: false, noMove: false}); | ||
| itemWithExternalTitle.addEventListener('mouseover', () => { | ||
| externalTitle.style.display = 'block'; | ||
| externalTitle.style.left = `calc(${itemWithExternalTitle.getBoundingClientRect().left}px + 10px)`; | ||
| externalTitle.style.top = `calc(${itemWithExternalTitle.getBoundingClientRect().top}px - 14px)`; | ||
| }); | ||
| itemWithExternalTitle.addEventListener('mouseout', () => { | ||
| externalTitle.style.display = ''; | ||
| }); | ||
| grid.on('dragstop', () => { | ||
| externalTitle.style.left = `calc(${itemWithExternalTitle.getBoundingClientRect().left}px + 10px)`; | ||
| }); | ||
| </script> | ||
| </body> | ||
|
|
||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
honestly this wouldn't work in general since you assume a fix set of elements (really a single one shared in your case) which doesn't work for dynamic elements. what happens when you add/remove/reparent items ?