Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Code and examples for scripting drag-and-drop in lists run by Sortable.js

NotificationsYou must be signed in to change notification settings

kemokid/scripting-sortable

Repository files navigation

Code and examples for scripting drag-and-drop in lists run by Sortable.js

Contents

This repo contains a script for automating drag-and-drop in lists run by Sortable.js. This is not straightforward, and should enable scripting and testing of UI elements that were not possible before.

script_sortable_dnd.js contains the key code. RuntriggerSortableDragAndDrop('#drag', '#drop'); to drag element with iddrag to the element with iddrop.

Examples

There's a simple example of scripting a Sortable list insortable_example.html.

A simple, non-Sortable example isnon_sortable_example.html, which is an adaption ofW3School's example code. This requires a more general version of the script, which is inscript_sortable_dnd_more_general.js.

History

One recent day, I was trying to script drag-and-drop actions on a Sortable list (that is, one controlled bySortable.js library, as it happened as part of theAngular Sortable library).

Due to abug in Selenium's support for Google Chrome which the developers do not seem at all inclined to fix, I could not use the simple method of sending an HTML5 drag-and-drop event to the page.

After much searching I found some useful links and scripts for mimicking drag-and-drop with individual browser events. One of these isdrag_and_drop_helper.js provided byrcorreia@blurb.com. Another useful resource was a script fordrag-and-drop for Casper which I used as the starting point for the script included here.

I removed many of the events and introduced two key changes to get Sortable.js to respond properly:

  • I put delays in between important groups of events.
  • I added a check to see if the target element has moved; if not, the script retries a few times. This is necessary because Sortable does some funky stuff in terms of adding a "ghost" element into the list, and also because, unlike most drag-and-drop actions, the target may move (in fact, that's the point).

Hints if you run into trouble

The script is very hacky. If it's not working for your browser / page / Sortable.js version, you may want to add in some additional events or delays, or just increase DELAY_INTERVAL_MS or MAX_TRIES. For debugging, you can increase DELAY_INTERVAL_MS and watch the DOM elements change to understand what Sortable is doing. That code is ... let's say not easy to grok.

One thing you'll want to check is that the script works both for an element dragged to an elementabove it on the list and as well as to an elementbelow it on the list.

Other notes

I found this page onscripting in Protractor to be helpful early in my process of working this out.

About

Code and examples for scripting drag-and-drop in lists run by Sortable.js

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp