tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

014.html (2848B)


      1 <!DOCTYPE html>
      2 <title>drag &amp; drop - microdata with sibling itemref loop</title>
      3 <style>
      4  body > div {
      5    height: 200px;
      6    width: 200px;
      7    background-color: orange;
      8    position: absolute;
      9    top: 8px;
     10    left: 8px;
     11  }
     12  body > div *, span {
     13    display: none;
     14  }
     15  body > div + div {
     16    background-color: navy;
     17    left: 250px;
     18  }
     19  body > div + div + div {
     20    background-color: fuchsia;
     21    left: 500px;
     22  }
     23  p:first-of-type {
     24    margin-top: 220px;
     25  }
     26 </style>
     27 
     28 <script>
     29 
     30 function makeEl(eltype,props,contents) {
     31  var elem = document.createElement(eltype);
     32  for( var i in props ) {
     33    if( props.hasOwnProperty(i) ) {
     34      elem.setAttribute(i,props[i]);
     35    }
     36  }
     37  if( contents ) {
     38    elem.innerHTML = contents;
     39  }
     40  return elem;
     41 }
     42 
     43 var orange, fails = [], doneonce = false;
     44 window.onload = function() {
     45  orange = document.getElementsByTagName('div')[0];
     46 
     47  orange.ondragstart = function(e) {
     48    e.dataTransfer.effectAllowed = 'copy';
     49    e.dataTransfer.setData('Text', 'dummy text');
     50    var err;
     51    if( err = checkprops(e.dataTransfer.getData('application/microdata+json')) ) {
     52      fails[fails.length] = e.type + ' ' + err;
     53    }
     54  };
     55  orange.nextSibling.ondragenter = orange.nextSibling.ondragleave = orange.nextSibling.ondragover =
     56  orange.ondrag = orange.ondragend = function(e) {
     57    if( e.type == 'dragover' || e.type == 'dragenter' ) {
     58      e.preventDefault();
     59      e.dataTransfer.dropEffect = 'copy';
     60    }
     61    if( e.dataTransfer.getData('application/microdata+json') ) {
     62      fails[fails.length] = e.type + ' unexpectedly had microdata (security restriction)';
     63    }
     64  };
     65  orange.nextSibling.ondrop = function(e) {
     66    var err;
     67    if( err = checkprops(e.dataTransfer.getData('application/microdata+json')) ) {
     68      fails[fails.length] = e.type + ' ' + err;
     69    }
     70    if( e.type != 'drop' ) { return; }
     71    if( doneonce ) { return; }
     72    doneonce = true;
     73    setTimeout(function () {
     74      document.getElementsByTagName('p')[0].innerHTML = fails.length ? ( 'FAIL: ' + fails.join('<br>') ) : 'PASS';
     75      fails = [];
     76    }, 200 );
     77  };
     78 
     79 };
     80 function checkprops(md) {
     81  // http://dev.w3.org/html5/md/#extracting-json
     82  //"check if the element is a top-level microdata item, and if it is"
     83  //as it has itemprop, it is not a top-level item, and should be ignored
     84  var i;
     85  if( !md ) { return 'no microdata'; }
     86  md = JSON.parse(md);
     87  if( !md.items ) { return 'no items'; }
     88  if( md.items.length != 0 ) { return md.items.length+' items instead of 0'; }
     89  return '';
     90 }
     91 
     92 </script>
     93 
     94 <div draggable='true' itemscope itemprop='foo' id='id1' itemref='id2'></div><div id='id2' itemprop='bar' itemscope itemref='id1'></div><div></div>
     95 
     96 <p>Use your pointing device to drag the orange box to the pink box, then back to the blue box, and release it.</p>
     97 <noscript><p>Enable JavaScript and reload</p></noscript>