HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div class="columns hax-accessible">
<!-- drop zones (need to add these via jquery) -->
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
<h1 data-draggable="item">Accessible Drag and Drop</h1>
<p data-draggable="item"><strong>Directions:</strong> Tab to this item. To select, press spacebar. Tab to a new drop zone location. Press Enter to confirm the move. To release a selection, press escape. NOTE: Only drop zones will allow you to move a selection.</p>
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
<div class="row layout-group" data-draggable="item" data-equalizer>
<div class="columns small-8 sub-target" data-draggable="target" data-equalizer-watch></div>
<div class="columns small-4 sub-target" data-draggable="target" data-equalizer-watch></div>
</div>
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
<div class="row layout-group" data-draggable="item" data-equalizer>
<div class="columns small-8 sub-target" data-draggable="target" data-equalizer-watch>
<img data-draggable="item" src="http://placehold.co/1200x400">
<img data-draggable="item" src="http://placehold.co/1200x400">
</div>
<div class="columns small-4 sub-target" data-draggable="target" data-equalizer-watch>
<img data-draggable="item" src="http://placehold.co/1200x400">
</div>
</div>
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
<div class="row layout-group" data-draggable="item" data-equalizer>
<div class="columns small-4 sub-target" data-draggable="target" data-equalizer-watch>
<img data-draggable="item" src="http://placehold.co/1200x400">
</div>
<div class="columns small-8 sub-target" data-draggable="target" data-equalizer-watch>
<img data-draggable="item" src="http://placehold.co/1200x400">
</div>
</div>
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
<div class="row layout-group" data-draggable="item" data-equalizer>
<div class="columns small-6 sub-target" data-draggable="target" data-equalizer-watch><img data-draggable="item" src="http://placehold.co/1200x400"></div>
<div class="columns small-6 sub-target" data-draggable="target" data-equalizer-watch><img data-draggable="item" src="http://placehold.co/1200x400"></div>
</div>
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
<div class="row layout-group" data-draggable="item" data-equalizer>
<div class="columns small-4 sub-target" data-draggable="target" data-equalizer-watch><img data-draggable="item" src="http://placehold.co/1200x400"></div>
<div class="columns small-4 sub-target" data-draggable="target" data-equalizer-watch><img data-draggable="item" src="http://placehold.co/1200x400"></div>
<div class="columns small-4 sub-target" data-draggable="target" data-equalizer-watch><img data-draggable="item" src="http://placehold.co/1200x400"></div>
</div>
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
<div class="row layout-group" data-draggable="item" data-equalizer>
<div class="columns small-3 sub-target" data-draggable="target" data-equalizer-watch></div>
<div class="columns small-3 sub-target" data-draggable="target" data-equalizer-watch></div>
<div class="columns small-3 sub-target" data-draggable="target" data-equalizer-watch></div>
<div class="columns small-3 sub-target" data-draggable="target" data-equalizer-watch></div>
</div>
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target " data-draggable="target">
</div>
</div>
<div class="row layout-garage collapse">
<div class="columns small-12 sub-target" data-draggable="target">
</div>
</div>
///////////////////////
.hax-accessible .row {
[data-draggable="target"],[data-draggable="item"] {
-webkit-transition: background-color 700ms cubic-bezier(0.000, 0.655, 0.205, 0.995);
-moz-transition: background-color 700ms cubic-bezier(0.000, 0.655, 0.205, 0.995);
-o-transition: background-color 700ms cubic-bezier(0.000, 0.655, 0.205, 0.995);
transition: background-color 700ms cubic-bezier(0.000, 0.655, 0.205, 0.995); /* custom */
-webkit-transition-timing-function: cubic-bezier(0.000, 0.655, 0.205, 0.995);
-moz-transition-timing-function: cubic-bezier(0.000, 0.655, 0.205, 0.995);
-o-transition-timing-function: cubic-bezier(0.000, 0.655, 0.205, 0.995);
transition-timing-function: cubic-bezier(0.000, 0.655, 0.205, 0.995); /* custom */
}
}
////////////////////////////
////////////////////////////
// http://www.sitepoint.com/accessible-drag-drop
////////////////////////////
////////////////////////////
/* draggable targets */
[data-draggable="target"]
{
padding:0.5rem 0.5rem 0.5rem;
border:2px solid #efefef;
border-radius:12px;
background:#fff;
color:#555;
min-height:2.75rem;
margin-top: 0.5rem;
}
/* drop target state */
[data-draggable="target"][aria-dropeffect="move"]
{
border-color:#68b;
background:#fff;
}
/* drop target focus and dragover state */
[data-draggable="target"][aria-dropeffect="move"]:focus,
[data-draggable="target"][aria-dropeffect="move"].dragover
{
outline:none;
border:4px solid #68b;
color:#a4bde4;
background:#68b;
min-height:2.75rem;
&:before {
position:absolute;
top:0.4rem;
left:0.5rem;
z-index:1;
font-size: 1rem;
color:#fff;
line-height: 1rem;
content:"ENTER TO MOVE";
display:block;
padding:0.25rem 0.5rem;
height:1.5rem;
margin:auto auto;
text-align:center;
background:#333;
border-radius:3px;
opacity:0.9;
}
}
[data-draggable="target"][aria-dropeffect="move"]:focus [data-draggable="item"],
[data-draggable="target"][aria-dropeffect="move"].dragover [data-draggable="item"] {
border:2px solid #68b;
}
/* draggable items */
[data-draggable="item"]
{
padding:1rem;
border-radius:0.2em;
border:2px dashed #efefef;
margin:1rem 0 1rem 0;
/*&:last-child {
margin:0 0 0 0;
padding:0;
}*/
}
/* items focus state */
[data-draggable="item"]:focus
{
outline:none;
background:#fff;
border:2px solid #68b;
&:before {
position:absolute;
font-size: 1rem;
color:#fff;
line-height: 1rem;
content:"SPACEBAR TO SELECT";
display:block;
padding:0.25rem 0.5rem;
height:1.5rem;
margin:-2.8rem auto 0;
text-align:center;
background:#68b;
border-radius:3px;
opacity:1;
z-index:1;
}
}
/* items grabbed state */
[data-draggable="item"][aria-grabbed="true"]
{
background:#8ad;
color:#fff;
border:2px solid #68b;
&:before {
position:relative;
font-family: "foundation-icons";
font-size: 1rem;
color:#68b;
line-height: 1rem;
content:"\f10c";
display:block;
padding:0;
height:1rem;
width:1rem;
margin:-2rem auto 1rem;
text-align:center;
opacity:1;
background:transparent;
}
&:after {
font-family: "foundation-icons";
font-size: 1rem;
color:#68b;
line-height: 1rem;
content:"\f109";
display:block;
height:1rem;
width:1rem;
margin:1rem auto -2rem;
text-align:center;
}
}
[data-draggable="target"].sub-target {
padding:1rem;
}
.layout-garage [data-draggable="target"]{
border-color:#fff;
}
.layout-garage [data-draggable="item"].layout-group [data-draggable="target"].sub-target {
background:#fff;
border-color: #ececec;
border-style:solid;
border-radius:0;
border-width:2px 1px 2px 1px;
&:first-child {
border-radius:4px 0px 0px 4px;
border-width:2px 1px 2px 2px;
}
&:last-child {
border-radius:0px 4px 4px 0px;
border-width:2px 2px 2px 1px;
}
&:only-child {
border-radius:4px 4px 4px 4px;
border-width:2px 2px 2px 2px;
}
}
[data-draggable="item"].row.layout-group {
border:4px solid #ececec;
background: #ececec;
border-radius:12px;
padding:0.25rem 0.5rem;
min-height:3rem;
margin-bottom:0.5rem;
.layout-group {
border-radius:0px;
border:4px solid #ececec;
margin-bottom:0rem;
}
}
[data-draggable="item"].row.layout-group:focus {
border:4px solid #68b;
background:#ccc;
&:before {
position:absolute;
font-size: 1rem;
color:#fff;
line-height: 1rem;
content:"SPACEBAR TO SELECT";
display:inline-block;
padding:0.25rem 0.5rem;
height:1.5rem;
margin:-1.85rem auto 0;
text-align:center;
background:#68b;
border-radius:3px;
opacity:1;
z-index:3;
}
}
[data-draggable="item"].row.layout-group[aria-grabbed="true"] {
border:4px solid #68b;
padding:0.75rem 0.5rem;
min-height:3rem;
background:#8ad;
&:before {
position:relative;
font-family: "foundation-icons";
font-size: 1rem;
color:#68b;
line-height: 0.5rem;
content:"\f10c";
display:block;
padding:0;
height:1rem;
width:1rem;
margin:-1.5rem auto 0rem;
text-align:center;
opacity:1;
background:transparent;
}
&:after {
font-family: "foundation-icons";
font-size: 1rem;
color:#68b;
line-height: 1.5rem;
content:"\f109";
display:block;
height:1rem;
width:1rem;
margin:0rem auto -1.5rem;
text-align:center;
}
}
[data-draggable="target"] [data-draggable="target"].sub-target {
margin:0.25rem 0;
}
$(document).foundation();
////////////////////////////
////////////////////////////
// http://www.sitepoint.com/accessible-drag-drop
// With some modifications to work with Zurb Foundation 5 Equalizer JS
////////////////////////////
////////////////////////////
(function()
{
//exclude older browsers by the features we need them to support
//and legacy opera explicitly so we don't waste time on a dead browser
if (!document.querySelectorAll ||
!('draggable' in document.createElement('span')) ||
window.opera
) {
return;
}
//get the collection of draggable targets and add their draggable attribute
for (var
targets = document.querySelectorAll('[data-draggable="target"]'),
len = targets.length,
i = 0; i < len; i++) {
targets[i].setAttribute('aria-dropeffect', 'none');
}
//get the collection of draggable items and add their draggable attributes
for (var
items = document.querySelectorAll('[data-draggable="item"]'),
len = items.length,
i = 0; i < len; i++) {
items[i].setAttribute('draggable', 'true');
items[i].setAttribute('aria-grabbed', 'false');
items[i].setAttribute('tabindex', '0');
}
//dictionary for storing the selections data
//comprising an array of the currently selected items
//a reference to the selected items' owning container
//and a refernce to the current drop target container
var selections = {
items: [],
owner: null,
droptarget: null
};
// That's all.
//function for selecting an item
function addSelection(item) {
//if the owner reference is still null, set it to this item's parent
//so that further selection is only allowed within the same container
if (!selections.owner) {
selections.owner = item.parentNode;
}
//or if that's already happened then compare it with this item's parent
//and if they're not the same container, return to prevent selection
else if (selections.owner != item.parentNode) {
return;
}
//set this item's grabbed state
item.setAttribute('aria-grabbed', 'true');
//add it to the items array
selections.items.push(item);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// https://github.com/RubaXa/Sortable#cdn
// TODO - FIX this
// Drag sorting of elements
/*var sortlist = selections.owner;
var sort = Sortable.create(sortlist); // That's all.
$( sortlist ).mouseup(function() {
sort.destroy();
}); */
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
//function for unselecting an item
function removeSelection(item) {
//reset this item's grabbed state
item.setAttribute('aria-grabbed', 'false');
//then find and remove this item from the existing items array
for (var len = selections.items.length, i = 0; i < len; i++) {
if (selections.items[i] == item) {
selections.items.splice(i, 1);
break;
}
}
}
//function for resetting all selections
function clearSelections() {
//if we have any selected items
if (selections.items.length) {
//reset the owner reference
selections.owner = null;
//reset the grabbed state on every selected item
for (var len = selections.items.length, i = 0; i < len; i++) {
selections.items[i].setAttribute('aria-grabbed', 'false');
}
//then reset the items array
selections.items = [];
}
}
//shorctut function for testing whether a selection modifier is pressed
function hasModifier(e) {
return (e.ctrlKey || e.metaKey || e.shiftKey);
}
//function for applying dropeffect to the target containers
function addDropeffects() {
//apply aria-dropeffect and tabindex to all targets apart from the owner
for (var len = targets.length, i = 0; i < len; i++) {
if (
targets[i] != selections.owner &&
targets[i].getAttribute('aria-dropeffect') == 'none'
) {
targets[i].setAttribute('aria-dropeffect', 'move');
targets[i].setAttribute('tabindex', '0');
}
}
//remove aria-grabbed and tabindex from all items inside those containers
for (var len = items.length, i = 0; i < len; i++) {
if (
items[i].parentNode != selections.owner &&
items[i].getAttribute('aria-grabbed')
) {
items[i].removeAttribute('aria-grabbed');
items[i].removeAttribute('tabindex');
}
}
}
//function for removing dropeffect from the target containers
function clearDropeffects() {
//if we have any selected items
if (selections.items.length) {
//reset aria-dropeffect and remove tabindex from all targets
for (var len = targets.length, i = 0; i < len; i++) {
if (targets[i].getAttribute('aria-dropeffect') != 'none') {
targets[i].setAttribute('aria-dropeffect', 'none');
targets[i].removeAttribute('tabindex');
}
}
//restore aria-grabbed and tabindex to all selectable items
//without changing the grabbed value of any existing selected items
for (var len = items.length, i = 0; i < len; i++) {
if (!items[i].getAttribute('aria-grabbed')) {
items[i].setAttribute('aria-grabbed', 'false');
items[i].setAttribute('tabindex', '0');
} else if (items[i].getAttribute('aria-grabbed') == 'true') {
items[i].setAttribute('tabindex', '0');
}
}
}
}
//shortcut function for identifying an event element's target container
function getContainer(element) {
do {
if (element.nodeType == 1 && element.getAttribute('aria-dropeffect')) {
return element;
}
}
while (element = element.parentNode);
return null;
}
//mousedown event to implement single selection
document.addEventListener('mousedown', function(e) {
//if the element is a draggable item
if (e.target.getAttribute('draggable')) {
//clear dropeffect from the target containers
clearDropeffects();
//if the multiple selection modifier is not pressed
//and the item's grabbed state is currently false
if (!hasModifier(e) &&
e.target.getAttribute('aria-grabbed') == 'false'
) {
//clear all existing selections
clearSelections();
//then add this new selection
addSelection(e.target);
}
}
//else [if the element is anything else]
//and the selection modifier is not pressed
else if (!hasModifier(e)) {
//clear dropeffect from the target containers
clearDropeffects();
//clear all existing selections
clearSelections();
}
//else [if the element is anything else and the modifier is pressed]
else {
//clear dropeffect from the target containers
clearDropeffects();
}
}, false);
//mouseup event to implement multiple selection
document.addEventListener('mouseup', function(e) {
//if the element is a draggable item
//and the multipler selection modifier is pressed
if (e.target.getAttribute('draggable') && hasModifier(e)) {
//if the item's grabbed state is currently true
if (e.target.getAttribute('aria-grabbed') == 'true') {
//unselect this item
removeSelection(e.target);
//if that was the only selected item
//then reset the owner container reference
if (!selections.items.length) {
selections.owner = null;
}
}
//else [if the item's grabbed state is false]
else {
//add this additional selection
addSelection(e.target);
}
}
}, false);
//dragstart event to initiate mouse dragging
document.addEventListener('dragstart', function(e) {
//if the element's parent is not the owner, then block this event
if (selections.owner != e.target.parentNode) {
e.preventDefault();
return;
}
//[else] if the multiple selection modifier is pressed
//and the item's grabbed state is currently false
if (
hasModifier(e) &&
e.target.getAttribute('aria-grabbed') == 'false'
) {
//add this additional selection
addSelection(e.target);
}
//we don't need the transfer data, but we have to define something
//otherwise the drop action won't work at all in firefox
//most browsers support the proper mime-type syntax, eg. "text/plain"
//but we have to use this incorrect syntax for the benefit of IE10+
e.dataTransfer.setData('text', '');
//apply dropeffect to the target containers
addDropeffects();
}, false);
//keydown event to implement selection and abort
document.addEventListener('keydown', function(e) {
//if the element is a grabbable item
if (e.target.getAttribute('aria-grabbed')) {
//Space is the selection or unselection keystroke
if (e.keyCode == 32) {
//if the multiple selection modifier is pressed
if (hasModifier(e)) {
//if the item's grabbed state is currently true
if (e.target.getAttribute('aria-grabbed') == 'true') {
//if this is the only selected item, clear dropeffect
//from the target containers, which we must do first
//in case subsequent unselection sets owner to null
if (selections.items.length == 1) {
clearDropeffects();
}
//unselect this item
removeSelection(e.target);
//if we have any selections
//apply dropeffect to the target containers,
//in case earlier selections were made by mouse
if (selections.items.length) {
addDropeffects();
}
//if that was the only selected item
//then reset the owner container reference
if (!selections.items.length) {
selections.owner = null;
}
}
//else [if its grabbed state is currently false]
else {
//add this additional selection
addSelection(e.target);
//apply dropeffect to the target containers
addDropeffects();
}
}
//else [if the multiple selection modifier is not pressed]
//and the item's grabbed state is currently false
else if (e.target.getAttribute('aria-grabbed') == 'false') {
//clear dropeffect from the target containers
clearDropeffects();
//clear all existing selections
clearSelections();
//add this new selection
addSelection(e.target);
//apply dropeffect to the target containers
addDropeffects();
}
//else [if modifier is not pressed and grabbed is already true]
else {
//apply dropeffect to the target containers
addDropeffects();
}
//then prevent default to avoid any conflict with native actions
e.preventDefault();
}
//Modifier + M is the end-of-selection keystroke
if (e.keyCode == 77 && hasModifier(e)) {
//if we have any selected items
if (selections.items.length) {
//apply dropeffect to the target containers
//in case earlier selections were made by mouse
addDropeffects();
//if the owner container is the last one, focus the first one
if (selections.owner == targets[targets.length - 1]) {
targets[0].focus();
}
//else [if it's not the last one], find and focus the next one
else {
for (var len = targets.length, i = 0; i < len; i++) {
if (selections.owner == targets[i]) {
targets[i + 1].focus();
break;
}
}
}
}
//then prevent default to avoid any conflict with native actions
e.preventDefault();
}
}
//Escape is the abort keystroke (for any target element)
if (e.keyCode == 27) {
//if we have any selected items
if (selections.items.length) {
//clear dropeffect from the target containers
clearDropeffects();
//then set focus back on the last item that was selected, which is
//necessary because we've removed tabindex from the current focus
selections.items[selections.items.length - 1].focus();
//clear all existing selections
clearSelections();
//but don't prevent default so that native actions can still occur
}
}
}, false);
//related variable is needed to maintain a reference to the
//dragleave's relatedTarget, since it doesn't have e.relatedTarget
var related = null;
//dragenter event to set that variable
document.addEventListener('dragenter', function(e) {
related = e.target;
}, false);
//dragleave event to maintain target highlighting using that variable
document.addEventListener('dragleave', function(e) {
//get a drop target reference from the relatedTarget
var droptarget = getContainer(related);
//if the target is the owner then it's not a valid drop target
if (droptarget == selections.owner) {
droptarget = null;
}
//if the drop target is different from the last stored reference
//(or we have one of those references but not the other one)
if (droptarget != selections.droptarget) {
//if we have a saved reference, clear its existing dragover class
if (selections.droptarget) {
selections.droptarget.className =
selections.droptarget.className.replace(/ dragover/g, '');
}
//apply the dragover class to the new drop target reference
if (droptarget) {
droptarget.className += ' dragover';
}
//then save that reference for next time
selections.droptarget = droptarget;
}
}, false);
//dragover event to allow the drag by preventing its default
document.addEventListener('dragover', function(e) {
//if we have any selected items, allow them to be dragged
if (selections.items.length) {
e.preventDefault();
}
}, false);
//dragend event to implement items being validly dropped into targets,
//or invalidly dropped elsewhere, and to clean-up the interface either way
document.addEventListener('dragend', function(e) {
//if we have a valid drop target reference
//(which implies that we have some selected items)
if (selections.droptarget) {
//append the selected items to the end of the target container
for (var len = selections.items.length, i = 0; i < len; i++) {
selections.droptarget.appendChild(selections.items[i]);
}
//prevent default to allow the action
e.preventDefault();
/////////////////
/////////////////
/////////////////
// Reflow foundation for equal height adjustments
$(document).foundation('equalizer', 'reflow');
/////////////////
/////////////////
/////////////////
}
//if we have any selected items
if (selections.items.length) {
//clear dropeffect from the target containers
clearDropeffects();
//if we have a valid drop target reference
if (selections.droptarget) {
//reset the selections array
clearSelections();
//reset the target's dragover class
selections.droptarget.className =
selections.droptarget.className.replace(/ dragover/g, '');
//reset the target reference
selections.droptarget = null;
}
}
}, false);
//keydown event to implement items being dropped into targets
document.addEventListener('keydown', function(e) {
//if the element is a drop target container
if (e.target.getAttribute('aria-dropeffect')) {
//Enter or Modifier + M is the drop keystroke
if (e.keyCode == 13 || (e.keyCode == 77 && hasModifier(e))) {
//append the selected items to the end of the target container
for (var len = selections.items.length, i = 0; i < len; i++) {
e.target.appendChild(selections.items[i]);
}
//clear dropeffect from the target containers
clearDropeffects();
//then set focus back on the last item that was selected, which is
//necessary because we've removed tabindex from the current focus
selections.items[selections.items.length - 1].focus();
//reset the selections array
clearSelections();
//prevent default to to avoid any conflict with native actions
e.preventDefault();
/////////////////
/////////////////
/////////////////
// Reflow foundation for equal height adjustments
$(document).foundation('equalizer', 'reflow');
/////////////////
/////////////////
/////////////////
}
}
}, false);
})();
Also see: Tab Triggers