From 244a3cce684826de3c9efa4fe428c1c8a753a288 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 3 Dec 2014 17:46:05 -0800 Subject: [PATCH] Allow scrollbars without categories. --- blockly_compressed.js | 46 +++++++++++++++++++++---------------------- core/inject.js | 39 +++++++++++++++++------------------- 2 files changed, 41 insertions(+), 44 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 1b9de1c03..4681b3f82 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -58,8 +58,8 @@ goog.string.escapeChar=function(a){if(a in goog.string.jsEscapeCache_)return goo goog.string.caseInsensitiveContains=function(a,b){return goog.string.contains(a.toLowerCase(),b.toLowerCase())};goog.string.countOf=function(a,b){return a&&b?a.split(b).length-1:0};goog.string.removeAt=function(a,b,c){var d=a;0<=b&&bb?1:0};goog.string.HASHCODE_MAX_=4294967296;goog.string.hashCode=function(a){for(var b=0,c=0;cb?1:0};goog.string.HASHCODE_MAX_=4294967296;goog.string.hashCode=function(a){for(var b=0,c=0;ce&&(g=2*Math.PI-g);var h=g+Math.PI/2;h>2*Math.PI&&(h-=2*Math.PI);var k=Math.sin(h),l=Math.cos(h),p=this.getBubbleSize(),h=(p.width+p.height)/Blockly.Bubble.ARROW_THICKNESS,h=Math.min(h,p.width,p.height)/2,p=1-Blockly.Bubble.ANCHOR_RADIUS/f,d=b+p*d,e=c+ -p*e,p=b+h*l,m=c+h*k,b=b-h*l,c=c-h*k,k=g+this.arrow_radians_;k>2*Math.PI&&(k-=2*Math.PI);g=Math.sin(k)*f/Blockly.Bubble.ARROW_BEND;f=Math.cos(k)*f/Blockly.Bubble.ARROW_BEND;a.push("M"+p+","+m);a.push("C"+(p+f)+","+(m+g)+" "+d+","+e+" "+d+","+e);a.push("C"+d+","+e+" "+(b+f)+","+(c+g)+" "+b+","+c)}a.push("z");this.bubbleArrow_.setAttribute("d",a.join(" "))};Blockly.Bubble.prototype.setColour=function(a){this.bubbleBack_.setAttribute("fill",a);this.bubbleArrow_.setAttribute("fill",a)}; +p*e,p=b+h*l,n=c+h*k,b=b-h*l,c=c-h*k,k=g+this.arrow_radians_;k>2*Math.PI&&(k-=2*Math.PI);g=Math.sin(k)*f/Blockly.Bubble.ARROW_BEND;f=Math.cos(k)*f/Blockly.Bubble.ARROW_BEND;a.push("M"+p+","+n);a.push("C"+(p+f)+","+(n+g)+" "+d+","+e+" "+d+","+e);a.push("C"+d+","+e+" "+(b+f)+","+(c+g)+" "+b+","+c)}a.push("z");this.bubbleArrow_.setAttribute("d",a.join(" "))};Blockly.Bubble.prototype.setColour=function(a){this.bubbleBack_.setAttribute("fill",a);this.bubbleArrow_.setAttribute("fill",a)}; Blockly.Bubble.prototype.dispose=function(){Blockly.Bubble.unbindDragEvents_();goog.dom.removeNode(this.bubbleGroup_);this.shape_=this.content_=this.workspace_=this.bubbleGroup_=null}; // Copyright 2013 Google Inc. Apache License 2.0 Blockly.Icon=function(a){this.block_=a};Blockly.Icon.RADIUS=8;Blockly.Icon.prototype.bubble_=null;Blockly.Icon.prototype.iconX_=0;Blockly.Icon.prototype.iconY_=0;Blockly.Icon.prototype.createIcon_=function(){this.iconGroup_=Blockly.createSvgElement("g",{},null);this.block_.getSvgRoot().appendChild(this.iconGroup_);Blockly.bindEvent_(this.iconGroup_,"mouseup",this,this.iconClick_);this.updateEditable()}; @@ -1150,7 +1150,7 @@ Blockly.Names.prototype.getDistinctName=function(a,b){for(var c=this.safeName_(a Blockly.Procedures={};Blockly.Procedures.NAME_TYPE="PROCEDURE";Blockly.Procedures.allProcedures=function(){for(var a=Blockly.mainWorkspace.getAllBlocks(),b=[],c=[],d=0;dd?1:ca.contentTop||a.contentTop+a.contentHeight>a.viewHeight+a.viewTop||a.contentLeft<(Blockly.RTL?a.viewLeft:0)||a.contentLeft+a.contentWidth> -(Blockly.RTL?a.viewWidth:a.viewWidth+a.viewLeft))for(var b=Blockly.mainWorkspace.getTopBlocks(!1),c=0,d;d=b[c];c++){var e=d.getRelativeToSurfaceXY(),p=d.getHeightWidth(),m=a.viewTop+25-p.height-e.y;0m&&d.moveBy(0,m);m=25+a.viewLeft-e.x-(Blockly.RTL?0:p.width);0m&&d.moveBy(m,0)}}})));b.appendChild(Blockly.Tooltip.createDom());a.appendChild(b);Blockly.svg=b;Blockly.svgResize(); -Blockly.WidgetDiv.DIV=goog.dom.createDom("div","blocklyWidgetDiv");Blockly.WidgetDiv.DIV.style.direction=Blockly.RTL?"rtl":"ltr";document.body.appendChild(Blockly.WidgetDiv.DIV)}; +(Blockly.hasCategories?Blockly.mainWorkspace.toolbox_=new Blockly.Toolbox(b,a):(Blockly.mainWorkspace.flyout_=new Blockly.Flyout,c=Blockly.mainWorkspace.flyout_,d=c.createDom(),c.autoClose=!1,goog.dom.insertSiblingBefore(d,Blockly.mainWorkspace.svgGroup_)),Blockly.hasScrollbars||Blockly.addChangeListener(function(){if(0==Blockly.Block.dragMode_){var a=Blockly.mainWorkspace.getMetrics(),b=a.viewLeft+a.absoluteLeft,c=a.viewTop+a.absoluteTop;if(a.contentTopa.viewHeight+ +c||a.contentLeft<(Blockly.RTL?a.viewLeft:b)||a.contentLeft+a.contentWidth>(Blockly.RTL?a.viewWidth:a.viewWidth+b))for(var d=Blockly.mainWorkspace.getTopBlocks(!1),e=0,p;p=d[e];e++){var n=p.getRelativeToSurfaceXY(),q=p.getHeightWidth(),m=c+25-q.height-n.y;0m&&p.moveBy(0,m);m=25+b-n.x-(Blockly.RTL?0:q.width);0m&&p.moveBy(m,0)}}}));b.appendChild(Blockly.Tooltip.createDom());a.appendChild(b); +Blockly.svg=b;Blockly.svgResize();Blockly.WidgetDiv.DIV=goog.dom.createDom("div","blocklyWidgetDiv");Blockly.WidgetDiv.DIV.style.direction=Blockly.RTL?"rtl":"ltr";document.body.appendChild(Blockly.WidgetDiv.DIV)}; Blockly.init_=function(){Blockly.bindEvent_(Blockly.svg,"mousedown",null,Blockly.onMouseDown_);Blockly.bindEvent_(Blockly.svg,"contextmenu",null,Blockly.onContextMenu_);Blockly.bindEvent_(Blockly.WidgetDiv.DIV,"contextmenu",null,Blockly.onContextMenu_);Blockly.documentEventsBound_||(Blockly.bindEvent_(window,"resize",document,Blockly.svgResize),Blockly.bindEvent_(document,"keydown",null,Blockly.onKeyDown_),document.addEventListener("mouseup",Blockly.onMouseUp_,!1),goog.userAgent.IPAD&&Blockly.bindEvent_(window, "orientationchange",document,function(){Blockly.fireUiEvent(window,"resize")}),Blockly.documentEventsBound_=!0);if(Blockly.languageTree)if(Blockly.mainWorkspace.toolbox_)Blockly.mainWorkspace.toolbox_.init();else if(Blockly.mainWorkspace.flyout_){Blockly.mainWorkspace.flyout_.init(Blockly.mainWorkspace);Blockly.mainWorkspace.flyout_.show(Blockly.languageTree.childNodes);Blockly.mainWorkspace.scrollX=Blockly.mainWorkspace.flyout_.width_;Blockly.RTL&&(Blockly.mainWorkspace.scrollX*=-1);var a="translate("+ Blockly.mainWorkspace.scrollX+", 0)";Blockly.mainWorkspace.getCanvas().setAttribute("transform",a);Blockly.mainWorkspace.getBubbleCanvas().setAttribute("transform",a)}Blockly.hasScrollbars&&(Blockly.mainWorkspace.scrollbar=new Blockly.ScrollbarPair(Blockly.mainWorkspace),Blockly.mainWorkspace.scrollbar.resize());Blockly.mainWorkspace.addTrashcan();if(Blockly.hasSounds){Blockly.loadAudio_([Blockly.pathToMedia+"click.mp3",Blockly.pathToMedia+"click.wav",Blockly.pathToMedia+"click.ogg"],"click");Blockly.loadAudio_([Blockly.pathToMedia+ diff --git a/core/inject.js b/core/inject.js index 362aca6ca..fd9a11475 100644 --- a/core/inject.js +++ b/core/inject.js @@ -117,14 +117,9 @@ Blockly.parseOptions_ = function(options) { hasDisable = hasCategories; } } - if (tree && !hasCategories) { - // Scrollbars are not compatible with a non-flyout toolbox. - var hasScrollbars = false; - } else { - var hasScrollbars = options['scrollbars']; - if (hasScrollbars === undefined) { - hasScrollbars = true; - } + var hasScrollbars = options['scrollbars']; + if (hasScrollbars === undefined) { + hasScrollbars = hasCategories; } var hasSounds = options['sounds']; if (hasSounds === undefined) { @@ -287,42 +282,44 @@ Blockly.createDom_ = function(container) { flyout.autoClose = false; // Insert the flyout behind the workspace so that blocks appear on top. goog.dom.insertSiblingBefore(flyoutSvg, Blockly.mainWorkspace.svgGroup_); + } + if (!Blockly.hasScrollbars) { var workspaceChanged = function() { if (Blockly.Block.dragMode_ == 0) { var metrics = Blockly.mainWorkspace.getMetrics(); - if (metrics.contentTop < 0 || + var edgeLeft = metrics.viewLeft + metrics.absoluteLeft; + var edgeTop = metrics.viewTop + metrics.absoluteTop; + if (metrics.contentTop < edgeTop || metrics.contentTop + metrics.contentHeight > - metrics.viewHeight + metrics.viewTop || - metrics.contentLeft < (Blockly.RTL ? metrics.viewLeft : 0) || + metrics.viewHeight + edgeTop || + metrics.contentLeft < + (Blockly.RTL ? metrics.viewLeft : edgeLeft) || metrics.contentLeft + metrics.contentWidth > (Blockly.RTL ? - metrics.viewWidth : - metrics.viewWidth + metrics.viewLeft)) { - // One or more blocks is out of bounds. Bump them back in. + metrics.viewWidth : metrics.viewWidth + edgeLeft)) { + // One or more blocks may be out of bounds. Bump them back in. var MARGIN = 25; var blocks = Blockly.mainWorkspace.getTopBlocks(false); for (var b = 0, block; block = blocks[b]; b++) { var blockXY = block.getRelativeToSurfaceXY(); var blockHW = block.getHeightWidth(); // Bump any block that's above the top back inside. - var overflow = metrics.viewTop + MARGIN - blockHW.height - - blockXY.y; + var overflow = edgeTop + MARGIN - blockHW.height - blockXY.y; if (overflow > 0) { block.moveBy(0, overflow); } // Bump any block that's below the bottom back inside. - var overflow = metrics.viewTop + metrics.viewHeight - MARGIN - - blockXY.y; + var overflow = edgeTop + metrics.viewHeight - MARGIN - blockXY.y; if (overflow < 0) { block.moveBy(0, overflow); } // Bump any block that's off the left back inside. - var overflow = MARGIN + metrics.viewLeft - blockXY.x - - (Blockly.RTL ? 0 : blockHW.width); + var overflow = MARGIN + edgeLeft - + blockXY.x - (Blockly.RTL ? 0 : blockHW.width); if (overflow > 0) { block.moveBy(overflow, 0); } // Bump any block that's off the right back inside. - var overflow = metrics.viewLeft + metrics.viewWidth - MARGIN - + var overflow = edgeLeft + metrics.viewWidth - MARGIN - blockXY.x + (Blockly.RTL ? blockHW.width : 0); if (overflow < 0) { block.moveBy(overflow, 0);