mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Changes per neil's comments, plus a rebuild
This commit is contained in:
parent
7d435bdb99
commit
1d1321a00d
5 changed files with 16 additions and 14 deletions
|
@ -879,10 +879,10 @@ Blockly.Touch={};Blockly.Touch.touchIdentifier_=null;Blockly.Touch.onTouchUpWrap
|
|||
Blockly.longStop_=function(){Blockly.longPid_&&(clearTimeout(Blockly.longPid_),Blockly.longPid_=0)};
|
||||
Blockly.onMouseUp_=function(a){a=Blockly.getMainWorkspace();a.dragMode_!=Blockly.DRAG_NONE&&(Blockly.Touch.clearTouchIdentifier(),Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN),a.dragMode_=Blockly.DRAG_NONE,Blockly.Touch.onTouchUpWrapper_&&(Blockly.unbindEvent_(Blockly.Touch.onTouchUpWrapper_),Blockly.Touch.onTouchUpWrapper_=null),Blockly.onMouseMoveWrapper_&&(Blockly.unbindEvent_(Blockly.onMouseMoveWrapper_),Blockly.onMouseMoveWrapper_=null))};
|
||||
Blockly.onMouseMove_=function(a){var b=Blockly.getMainWorkspace();if(b.dragMode_!=Blockly.DRAG_NONE){var c=a.clientX-b.startDragMouseX,d=a.clientY-b.startDragMouseY,e=b.startDragMetrics,f=b.startScrollX+c,g=b.startScrollY+d,f=Math.min(f,-e.contentLeft),g=Math.min(g,-e.contentTop),f=Math.max(f,e.viewWidth-e.contentLeft-e.contentWidth),g=Math.max(g,e.viewHeight-e.contentTop-e.contentHeight);b.scrollbar.set(-f-e.contentLeft,-g-e.contentTop);Math.sqrt(c*c+d*d)>Blockly.DRAG_RADIUS&&(Blockly.longStop_(),
|
||||
b.dragMode_=Blockly.DRAG_FREE);a.stopPropagation();a.preventDefault()}};Blockly.Touch.clearTouchIdentifier=function(){console.trace("\tclearing touch identifier");null==Blockly.Touch.touchIdentifier_&&console.log("\t\ttouch identifier was already null");Blockly.Touch.touchIdentifier_=null};Blockly.Touch.shouldHandleEvent=function(a){return!Blockly.Touch.isMouseOrTouchEvent(a)||Blockly.Touch.checkTouchIdentifier(a)};
|
||||
Blockly.Touch.checkTouchIdentifier=function(a){var b;try{b=a.changedTouches&&a.changedTouches.item(0)&&void 0!=a.changedTouches.item(0).identifier&&null!=a.changedTouches.item(0).identifier?a.changedTouches.item(0).identifier:"mouse"}catch(c){b=a.changedTouches&&a.changedTouches[0]&&void 0!=a.changedTouches[0].identifier&&null!=a.changedTouches[0].identifier?a.changedTouches[0].identifier:"mouse"}return void 0!=Blockly.Touch.touchIdentifier_&&null!=Blockly.Touch.touchIdentifier_?Blockly.Touch.touchIdentifier_==
|
||||
b:"mousedown"==a.type||"touchstart"==a.type?(console.trace("setting touch identfier"),Blockly.Touch.touchIdentifier_=b,!0):!1};Blockly.Touch.setClientFromTouch=function(a){if(0==a.type.indexOf("touch")){var b=a.changedTouches[0];a.clientX=b.clientX;a.clientY=b.clientY}};Blockly.Touch.isMouseOrTouchEvent=function(a){return 0==a.type.indexOf("touch")||0==a.type.indexOf("mouse")};
|
||||
Blockly.Touch.splitEventByTouches=function(a){var b=[];if(a.changedTouches)for(var c=0;c<a.changedTouches.length;c++)b.push({type:a.type,changedTouches:[a.changedTouches[c]],target:a.target,stopPropagation:function(){a.stopPropagation()},preventDefault:function(){a.preventDefault()}});else b.push(a);return b};
|
||||
b.dragMode_=Blockly.DRAG_FREE);a.stopPropagation();a.preventDefault()}};Blockly.Touch.clearTouchIdentifier=function(){Blockly.Touch.touchIdentifier_=null};Blockly.Touch.shouldHandleEvent=function(a){return!Blockly.Touch.isMouseOrTouchEvent(a)||Blockly.Touch.checkTouchIdentifier(a)};
|
||||
Blockly.Touch.checkTouchIdentifier=function(a){var b=a.changedTouches&&a.changedTouches[0]&&void 0!=a.changedTouches[0].identifier&&null!=a.changedTouches[0].identifier?a.changedTouches[0].identifier:"mouse";return void 0!=Blockly.Touch.touchIdentifier_&&null!=Blockly.Touch.touchIdentifier_?Blockly.Touch.touchIdentifier_==b:"mousedown"==a.type||"touchstart"==a.type?(Blockly.Touch.touchIdentifier_=b,!0):!1};
|
||||
Blockly.Touch.setClientFromTouch=function(a){if(goog.string.startsWith(a.type,"touch")){var b=a.changedTouches[0];a.clientX=b.clientX;a.clientY=b.clientY}};Blockly.Touch.isMouseOrTouchEvent=function(a){return goog.string.startsWith(a.type,"touch")||goog.string.startsWith(a.type,"mouse")};
|
||||
Blockly.Touch.splitEventByTouches=function(a){var b=[];if(a.changedTouches)for(var c=0;c<a.changedTouches.length;c++)b[c]={type:a.type,changedTouches:[a.changedTouches[c]],target:a.target,stopPropagation:function(){a.stopPropagation()},preventDefault:function(){a.preventDefault()}};else b.push(a);return b};
|
||||
// Copyright 2012 Google Inc. Apache License 2.0
|
||||
Blockly.Workspace=function(a){this.id=Blockly.genUid();Blockly.Workspace.WorkspaceDB_[this.id]=this;this.options=a||{};this.RTL=!!this.options.RTL;this.horizontalLayout=!!this.options.horizontalLayout;this.toolboxPosition=this.options.toolboxPosition;this.topBlocks_=[];this.listeners_=[];this.undoStack_=[];this.redoStack_=[];this.blockDB_=Object.create(null);this.variableList=[]};Blockly.Workspace.prototype.rendered=!1;Blockly.Workspace.prototype.MAX_UNDO=1024;
|
||||
Blockly.Workspace.prototype.dispose=function(){this.listeners_.length=0;this.clear();delete Blockly.Workspace.WorkspaceDB_[this.id]};Blockly.Workspace.SCAN_ANGLE=3;Blockly.Workspace.prototype.addTopBlock=function(a){this.topBlocks_.push(a);if(this.isFlyout){a=Blockly.Variables.allUsedVariables(a);for(var b=0;b<a.length;b++)-1==this.variableList.indexOf(a[b])&&this.variableList.push(a[b])}};
|
||||
|
@ -1400,8 +1400,8 @@ Blockly.Toolbox.prototype.syncTrees_=function(a,b,c){for(var d=null,e=null,f=0,g
|
|||
Blockly.Toolbox.prototype.addColour_=function(a){a=(a||this.tree_).getChildren();for(var b=0,c;c=a[b];b++){var d=c.getRowElement();if(d){var e=this.hasColours_?"8px solid "+(c.hexColour||"#ddd"):"none";this.workspace_.RTL?d.style.borderRight=e:d.style.borderLeft=e}this.addColour_(c)}};Blockly.Toolbox.prototype.clearSelection=function(){this.tree_.setSelectedItem(null)};
|
||||
Blockly.Toolbox.prototype.getClientRect=function(){if(!this.HtmlDiv)return null;var a=this.HtmlDiv.getBoundingClientRect(),b=a.left,c=a.top,d=a.width,a=a.height;return this.toolboxPosition==Blockly.TOOLBOX_AT_LEFT?new goog.math.Rect(-1E7,-1E7,1E7+b+d,2E7):this.toolboxPosition==Blockly.TOOLBOX_AT_RIGHT?new goog.math.Rect(b,-1E7,1E7+d,2E7):this.toolboxPosition==Blockly.TOOLBOX_AT_TOP?new goog.math.Rect(-1E7,-1E7,2E7,1E7+c+a):new goog.math.Rect(0,c,2E7,1E7+d)};
|
||||
Blockly.Toolbox.prototype.refreshSelection=function(){var a=this.tree_.getSelectedItem();a&&a.blocks&&this.flyout_.show(a.blocks)};Blockly.Toolbox.TreeControl=function(a,b){this.toolbox_=a;goog.ui.tree.TreeControl.call(this,goog.html.SafeHtml.EMPTY,b)};goog.inherits(Blockly.Toolbox.TreeControl,goog.ui.tree.TreeControl);
|
||||
Blockly.Toolbox.TreeControl.prototype.enterDocument=function(){Blockly.Toolbox.TreeControl.superClass_.enterDocument.call(this);var a=this.getElement();goog.events.BrowserFeature.TOUCH_ENABLED&&Blockly.bindEvent_(a,goog.events.EventType.TOUCHSTART,this,this.handleTouchEvent_);Blockly.bindEvent_(a,"mouseup",this,Blockly.Touch.clearTouchIdentifier)};
|
||||
Blockly.Toolbox.TreeControl.prototype.handleTouchEvent_=function(a){a.preventDefault();var b=this.getNodeFromEvent_(a);b&&a.type===goog.events.EventType.TOUCHSTART&&setTimeout(function(){b.onMouseDown(a)},1)};Blockly.Toolbox.TreeControl.prototype.createNode=function(a){return new Blockly.Toolbox.TreeNode(this.toolbox_,a?goog.html.SafeHtml.htmlEscape(a):goog.html.SafeHtml.EMPTY,this.getConfig(),this.getDomHelper())};
|
||||
Blockly.Toolbox.TreeControl.prototype.enterDocument=function(){Blockly.Toolbox.TreeControl.superClass_.enterDocument.call(this);var a=this.getElement();goog.events.BrowserFeature.TOUCH_ENABLED&&Blockly.bindEvent_(a,goog.events.EventType.TOUCHSTART,this,this.handleTouchEvent_)};Blockly.Toolbox.TreeControl.prototype.handleTouchEvent_=function(a){a.preventDefault();var b=this.getNodeFromEvent_(a);b&&a.type===goog.events.EventType.TOUCHSTART&&setTimeout(function(){b.onMouseDown(a)},1)};
|
||||
Blockly.Toolbox.TreeControl.prototype.createNode=function(a){return new Blockly.Toolbox.TreeNode(this.toolbox_,a?goog.html.SafeHtml.htmlEscape(a):goog.html.SafeHtml.EMPTY,this.getConfig(),this.getDomHelper())};
|
||||
Blockly.Toolbox.TreeControl.prototype.setSelectedItem=function(a){var b=this.toolbox_;if(a!=this.selectedItem_&&a!=b.tree_){b.lastCategory_&&(b.lastCategory_.getRowElement().style.backgroundColor="");if(a){var c=a.hexColour||"#57e";a.getRowElement().style.backgroundColor=c;b.addColour_(a)}c=this.getSelectedItem();goog.ui.tree.TreeControl.prototype.setSelectedItem.call(this,a);a&&a.blocks&&a.blocks.length?(b.flyout_.show(a.blocks),b.lastCategory_!=a&&b.flyout_.scrollToStart()):b.flyout_.hide();c!=
|
||||
a&&c!=this&&(c=new Blockly.Events.Ui(null,"category",c&&c.getHtml(),a&&a.getHtml()),c.workspaceId=b.workspace_.id,Blockly.Events.fire(c));a&&(b.lastCategory_=a)}};Blockly.Toolbox.TreeNode=function(a,b,c,d){goog.ui.tree.TreeNode.call(this,b,c,d);a&&(this.horizontalLayout_=a.horizontalLayout_,b=function(){Blockly.svgResize(a.workspace_)},goog.events.listen(a.tree_,goog.ui.tree.BaseNode.EventType.EXPAND,b),goog.events.listen(a.tree_,goog.ui.tree.BaseNode.EventType.COLLAPSE,b))};
|
||||
goog.inherits(Blockly.Toolbox.TreeNode,goog.ui.tree.TreeNode);Blockly.Toolbox.TreeNode.prototype.getExpandIconSafeHtml=function(){return goog.html.SafeHtml.create("span")};Blockly.Toolbox.TreeNode.prototype.onMouseDown=function(a){this.hasChildren()&&this.isUserCollapsible_?(this.toggle(),this.select()):this.isSelected()?this.getTree().setSelectedItem(null):this.select();this.updateRow()};Blockly.Toolbox.TreeNode.prototype.onDoubleClick_=function(a){};
|
||||
|
|
|
@ -83,7 +83,7 @@ goog.addDependency("../../../" + dir + "/core/field_angle.js", ['Blockly.FieldAn
|
|||
goog.addDependency("../../../" + dir + "/core/zoom_controls.js", ['Blockly.ZoomControls'], ['Blockly.Touch', 'goog.dom']);
|
||||
goog.addDependency("../../../" + dir + "/core/workspace.js", ['Blockly.Workspace'], ['goog.math']);
|
||||
goog.addDependency("../../../" + dir + "/core/field_date.js", ['Blockly.FieldDate'], ['Blockly.Field', 'goog.date', 'goog.dom', 'goog.events', 'goog.i18n.DateTimeSymbols', 'goog.i18n.DateTimeSymbols_he', 'goog.style', 'goog.ui.DatePicker']);
|
||||
goog.addDependency("../../../" + dir + "/core/touch.js", ['Blockly.Touch'], ['goog.events', 'goog.events.BrowserFeature']);
|
||||
goog.addDependency("../../../" + dir + "/core/touch.js", ['Blockly.Touch'], ['goog.events', 'goog.events.BrowserFeature', 'goog.string']);
|
||||
goog.addDependency("../../../" + dir + "/core/generator.js", ['Blockly.Generator'], ['Blockly.Block', 'goog.asserts']);
|
||||
goog.addDependency("../../../" + dir + "/core/inject.js", ['Blockly.inject'], ['Blockly.Css', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'goog.dom', 'goog.ui.Component', 'goog.userAgent']);
|
||||
goog.addDependency("../../../" + dir + "/core/connection_db.js", ['Blockly.ConnectionDB'], ['Blockly.Connection']);
|
||||
|
|
|
@ -599,7 +599,7 @@ Blockly.Scrollbar.prototype.setVisible = function(visible) {
|
|||
* @private
|
||||
*/
|
||||
Blockly.Scrollbar.prototype.onMouseDownBar_ = function(e) {
|
||||
Blockly.Touch.clearTouchIdentifier(); // This is really a click.
|
||||
Blockly.Touch.clearTouchIdentifier(); // This is really a click.
|
||||
this.cleanUp_();
|
||||
if (Blockly.isRightButton(e)) {
|
||||
// Right-click.
|
||||
|
|
|
@ -164,7 +164,7 @@ Blockly.Toolbox.prototype.init = function() {
|
|||
// Just close popups.
|
||||
Blockly.hideChaff(true);
|
||||
}
|
||||
Blockly.Touch.clearTouchIdentifier(); // Don't block future drags.
|
||||
Blockly.Touch.clearTouchIdentifier(); // Don't block future drags.
|
||||
});
|
||||
var workspaceOptions = {
|
||||
disabledPatternId: workspace.options.disabledPatternId,
|
||||
|
|
|
@ -28,6 +28,7 @@ goog.provide('Blockly.Touch');
|
|||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.BrowserFeature');
|
||||
goog.require('goog.string');
|
||||
|
||||
/**
|
||||
* Which touch events are we currently paying attention to?
|
||||
|
@ -71,7 +72,7 @@ Blockly.longPid_ = 0;
|
|||
* if the touch event terminates early.
|
||||
* @param {!Event} e Touch start event.
|
||||
* @param {!Blockly.Block|!Blockly.WorkspaceSvg} uiObject The block or workspace
|
||||
* under the touchstart event.
|
||||
* under the touchstart event.
|
||||
* @private
|
||||
*/
|
||||
Blockly.longStart_ = function(e, uiObject) {
|
||||
|
@ -167,7 +168,7 @@ Blockly.Touch.clearTouchIdentifier = function() {
|
|||
* with one touch stream at a time. All other events should always be handled.
|
||||
* @param {!Event} e The event to check.
|
||||
* @return {boolean} True if this event should be passed through to the
|
||||
* registered handler; false if it should be blocked.
|
||||
* registered handler; false if it should be blocked.
|
||||
*/
|
||||
Blockly.Touch.shouldHandleEvent = function(e) {
|
||||
return !Blockly.Touch.isMouseOrTouchEvent(e) ||
|
||||
|
@ -218,7 +219,7 @@ Blockly.Touch.checkTouchIdentifier = function(e) {
|
|||
* @param {!Event} e A touch event.
|
||||
*/
|
||||
Blockly.Touch.setClientFromTouch = function(e) {
|
||||
if (e.type.indexOf('touch') == 0) {
|
||||
if (goog.string.startsWith(e.type, 'touch')) {
|
||||
// Map the touch event's properties to the event.
|
||||
var touchPoint = e.changedTouches[0];
|
||||
e.clientX = touchPoint.clientX;
|
||||
|
@ -232,7 +233,8 @@ Blockly.Touch.setClientFromTouch = function(e) {
|
|||
* @return {boolean} true if it is a mouse or touch event; false otherwise.
|
||||
*/
|
||||
Blockly.Touch.isMouseOrTouchEvent = function(e) {
|
||||
return e.type.indexOf('touch') == 0 || e.type.indexOf('mouse') == 0;
|
||||
return goog.string.startsWith(e.type, 'touch') ||
|
||||
goog.string.startsWith(e.type, 'mouse');
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -254,7 +256,7 @@ Blockly.Touch.splitEventByTouches = function(e) {
|
|||
stopPropagation: function(){ e.stopPropagation(); },
|
||||
preventDefault: function(){ e.preventDefault(); }
|
||||
};
|
||||
events.push(newEvent);
|
||||
events[i] = newEvent;
|
||||
}
|
||||
} else {
|
||||
events.push(e);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue