Skip to content

Commit

Permalink
Merge pull request #1134 from waterbearlang/1133_scroll_while_dragging
Browse files Browse the repository at this point in the history
fix scroll and move output
  • Loading branch information
dethe committed Apr 19, 2015
2 parents 6138d5a + c688061 commit 7d1fa39
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
7 changes: 7 additions & 0 deletions css/app.css
Expand Up @@ -43,6 +43,12 @@ body > header > h1{
line-height: 34px;
}

body > output{
flex: 0 0 24px;
background: #EFEDEA;
color: #111111;
}

.menu{
flex: 0 0 34px;
background-color: #666666;
Expand Down Expand Up @@ -182,6 +188,7 @@ sidebar.trashcan:after{
wb-workspace > wb-contains{
border: 2px inset #CCC;
position: relative;
padding-bottom: 16px;
}

wb-contains:empty::before{
Expand Down
3 changes: 1 addition & 2 deletions css/widget.css
Expand Up @@ -73,7 +73,6 @@ wb-workspace{
display: flex;
flex-direction: column;
flex: 2 1;
overflow-x: auto;
}

wb-workspace > header{
Expand All @@ -90,7 +89,7 @@ wb-workspace > wb-locals{

wb-workspace > wb-contains{
flex: 3 1;
overflow-y: auto;
overflow: auto;
}

@keyframes slidey-stripes {
Expand Down
29 changes: 28 additions & 1 deletion js/block.js
Expand Up @@ -15,6 +15,7 @@
'use strict';
var elem = dom.html;
var workspace = dom.find(document.body, 'wb-workspace');
var scriptspace = dom.find(document.body, 'wb-workspace > wb-contains');
var selectedType = 'null';
var BLOCK_MENU = document.querySelector('sidebar');

Expand Down Expand Up @@ -825,13 +826,36 @@ function startDragBlock(evt){
}
if (dragStart === 'script'){
origTarget.classList.add('hide');
dom.child(origTarget.parentElement, 'input, select').classList.remove('hide');
var siblingInput = dom.child(origTarget.parentElement, 'input, select');
if (siblingInput){
siblingInput.classList.remove('hide');
}
}
dragTarget.classList.add('dragging');
dragTarget.style.left = (evt.pageX - 15) + 'px';
dragTarget.style.top = (evt.pageY - 15) + 'px';
}


function checkForScroll(evt){
requestAnimationFrame(checkForScroll);
if (!dragTarget){ return; }
var x = Event.pointerX;
var y = Event.pointerY;
var rect = scriptspace.getBoundingClientRect();
if (x < rect.left){
scriptspace.scrollLeft -= 5;
}else if (x > rect.right){
scriptspace.scrollLeft += 5;
}
if (y < rect.top){
scriptspace.scrollTop -= 5;
}else if (y > rect.bottom){
scriptspace.scrollTop += 5;
}
console.log('bottom: %s, scrollTop: %s, y: %s', rect.bottom, scriptspace.scrollTop, y);
}

function dragBlock(evt){
if (!dragTarget){ return; }
evt.preventDefault();
Expand Down Expand Up @@ -1088,6 +1112,9 @@ Event.on(document.body, 'editor:dragging', null, dragBlock);
Event.on(document.body, 'editor:drag-end', null, endDragBlock);
Event.on(document.body, 'editor:drag-cancel', null, cancelDragBlock);

requestAnimationFrame(checkForScroll);


Event.on(workspace, 'editor:input', 'input', resizeInputOnChange);
Event.on(workspace, 'editor:input', 'input, select', changeValueOnInputChange);

Expand Down
1 change: 1 addition & 0 deletions js/event.js
Expand Up @@ -216,6 +216,7 @@
}else{
evt.invalid = true;
evt.invalidReason = 'Multiple touches present';
console.log('multiple touches');
return evt;
}
evt.target = touch.target;
Expand Down
2 changes: 1 addition & 1 deletion playground.html
Expand Up @@ -1087,7 +1087,6 @@ <h1>Waterbear with Custom Elements</h1>
<wb-splitter></wb-splitter>
<wb-workspace>
<header>Workspace</header>
<output class="feedback"></output>
<wb-contains></wb-contains>
</wb-workspace>
</wb-workbox>
Expand Down Expand Up @@ -1128,6 +1127,7 @@ <h1>Waterbear Tutorials</h1>
</wb-displaybox>
</wb-vbox>
</wb-hbox>
<output class="feedback"></output>
<svg class="sekrit-svg"><text class="resize-tester"></text></svg>
<!-- polyfill for custom elements -->
<script src="lib/ajax.js"></script>
Expand Down

0 comments on commit 7d1fa39

Please sign in to comment.