mirror of
https://github.com/google/blockly.git
synced 2026-01-19 23:07:21 +01:00
Add custom event file.
This commit is contained in:
@@ -39,13 +39,14 @@ window.BLOCKLY_BOOT = function() {
|
||||
}
|
||||
goog.addDependency("../../../" + dir + "/core/block.js", ['Blockly.Block'], ['Blockly.Blocks', 'Blockly.Comment', 'Blockly.Connection', 'Blockly.Input', 'Blockly.Mutator', 'Blockly.Warning', 'Blockly.Workspace', 'Blockly.Xml', 'goog.array', 'goog.asserts', 'goog.math.Coordinate', 'goog.string']);
|
||||
goog.addDependency("../../../" + dir + "/core/block_svg.js", ['Blockly.BlockSvg'], ['Blockly.Block', 'Blockly.ContextMenu', 'goog.Timer', 'goog.asserts', 'goog.dom', 'goog.math.Coordinate', 'goog.userAgent']);
|
||||
goog.addDependency("../../../" + dir + "/core/blockly.js", ['Blockly'], ['Blockly.BlockSvg', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Generator', 'Blockly.Msg', 'Blockly.Procedures', 'Blockly.Toolbox', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.inject', 'Blockly.utils', 'goog.color', 'goog.userAgent']);
|
||||
goog.addDependency("../../../" + dir + "/core/blockly.js", ['Blockly'], ['Blockly.BlockSvg', 'Blockly.Events', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Generator', 'Blockly.Msg', 'Blockly.Procedures', 'Blockly.Toolbox', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.inject', 'Blockly.utils', 'goog.color', 'goog.userAgent']);
|
||||
goog.addDependency("../../../" + dir + "/core/blocks.js", ['Blockly.Blocks'], []);
|
||||
goog.addDependency("../../../" + dir + "/core/bubble.js", ['Blockly.Bubble'], ['Blockly.Workspace', 'goog.dom', 'goog.math', 'goog.userAgent']);
|
||||
goog.addDependency("../../../" + dir + "/core/comment.js", ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Icon', 'goog.userAgent']);
|
||||
goog.addDependency("../../../" + dir + "/core/connection.js", ['Blockly.Connection', 'Blockly.ConnectionDB'], ['goog.dom']);
|
||||
goog.addDependency("../../../" + dir + "/core/contextmenu.js", ['Blockly.ContextMenu'], ['goog.dom', 'goog.events', 'goog.style', 'goog.ui.Menu', 'goog.ui.MenuItem']);
|
||||
goog.addDependency("../../../" + dir + "/core/css.js", ['Blockly.Css'], []);
|
||||
goog.addDependency("../../../" + dir + "/core/events.js", ['Blockly.Events'], []);
|
||||
goog.addDependency("../../../" + dir + "/core/field.js", ['Blockly.Field'], ['goog.asserts', 'goog.dom', 'goog.math.Size', 'goog.style', 'goog.userAgent']);
|
||||
goog.addDependency("../../../" + dir + "/core/field_angle.js", ['Blockly.FieldAngle'], ['Blockly.FieldTextInput', 'goog.math', 'goog.userAgent']);
|
||||
goog.addDependency("../../../" + dir + "/core/field_checkbox.js", ['Blockly.FieldCheckbox'], ['Blockly.Field']);
|
||||
@@ -74,7 +75,7 @@ goog.addDependency("../../../" + dir + "/core/variables.js", ['Blockly.Variables
|
||||
goog.addDependency("../../../" + dir + "/core/warning.js", ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Icon']);
|
||||
goog.addDependency("../../../" + dir + "/core/widgetdiv.js", ['Blockly.WidgetDiv'], ['Blockly.Css', 'goog.dom', 'goog.style']);
|
||||
goog.addDependency("../../../" + dir + "/core/workspace.js", ['Blockly.Workspace'], ['goog.math']);
|
||||
goog.addDependency("../../../" + dir + "/core/workspace_svg.js", ['Blockly.WorkspaceSvg'], ['Blockly.ScrollbarPair', 'Blockly.Trashcan', 'Blockly.ZoomControls', 'Blockly.Workspace', 'Blockly.Xml', 'goog.dom', 'goog.math.Coordinate', 'goog.userAgent']);
|
||||
goog.addDependency("../../../" + dir + "/core/workspace_svg.js", ['Blockly.WorkspaceSvg'], ['Blockly.ScrollbarPair', 'Blockly.Trashcan', 'Blockly.ZoomControls', 'Blockly.Workspace', 'Blockly.Xml', 'goog.dom', 'goog.events', 'goog.math.Coordinate', 'goog.userAgent']);
|
||||
goog.addDependency("../../../" + dir + "/core/xml.js", ['Blockly.Xml'], ['goog.dom']);
|
||||
goog.addDependency("../../../" + dir + "/core/zoom_controls.js", ['Blockly.ZoomControls'], ['goog.dom']);
|
||||
goog.addDependency("../../alltests.js", [], []);
|
||||
@@ -1586,6 +1587,7 @@ goog.require('Blockly.Connection');
|
||||
goog.require('Blockly.ConnectionDB');
|
||||
goog.require('Blockly.ContextMenu');
|
||||
goog.require('Blockly.Css');
|
||||
goog.require('Blockly.Events');
|
||||
goog.require('Blockly.Field');
|
||||
goog.require('Blockly.FieldAngle');
|
||||
goog.require('Blockly.FieldCheckbox');
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
goog.provide('Blockly');
|
||||
|
||||
goog.require('Blockly.BlockSvg');
|
||||
goog.require('Blockly.Events');
|
||||
goog.require('Blockly.FieldAngle');
|
||||
goog.require('Blockly.FieldCheckbox');
|
||||
goog.require('Blockly.FieldColour');
|
||||
|
||||
53
core/events.js
Normal file
53
core/events.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2016 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Events fired as a result of actions in Blockly's editor.
|
||||
* @author fraser@google.com (Neil Fraser)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.Events');
|
||||
|
||||
/**
|
||||
* Allow change events to be created and fired.
|
||||
* @type {boolean}
|
||||
*/
|
||||
Blockly.Events.enabled = true;
|
||||
|
||||
/**
|
||||
* Create a custom event and fire it.
|
||||
* @param {Object} detail Custom data for event.
|
||||
*/
|
||||
Blockly.Events.fire = function(detail) {
|
||||
var workspace = Blockly.Workspace.getById(detail.workspace);
|
||||
if (workspace.rendered) {
|
||||
// Create a custom event in a browser-compatible way.
|
||||
if (typeof CustomEvent == 'function') {
|
||||
// W3
|
||||
var evt = new CustomEvent('blocklyWorkspaceChange', {'detail': detail});
|
||||
} else {
|
||||
// MSIE
|
||||
var evt = document.createEvent('CustomEvent');
|
||||
evt.initCustomEvent(eventName, false, false, detail);
|
||||
}
|
||||
workspace.getCanvas().dispatchEvent(evt);
|
||||
}
|
||||
};
|
||||
@@ -109,6 +109,7 @@ Blockly.FieldTextInput.prototype.setSpellcheck = function(check) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldTextInput.prototype.showEditor_ = function(opt_quietInput) {
|
||||
var workspace = this.sourceBlock_.workspace;
|
||||
var quietInput = opt_quietInput || false;
|
||||
if (!quietInput && (goog.userAgent.MOBILE || goog.userAgent.ANDROID ||
|
||||
goog.userAgent.IPAD)) {
|
||||
@@ -131,8 +132,7 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(opt_quietInput) {
|
||||
// Create the input.
|
||||
var htmlInput = goog.dom.createDom('input', 'blocklyHtmlInput');
|
||||
htmlInput.setAttribute('spellcheck', this.spellcheck_);
|
||||
var fontSize = (Blockly.FieldTextInput.FONTSIZE *
|
||||
this.sourceBlock_.workspace.scale) + 'pt';
|
||||
var fontSize = (Blockly.FieldTextInput.FONTSIZE * workspace.scale) + 'pt';
|
||||
div.style.fontSize = fontSize;
|
||||
htmlInput.style.fontSize = fontSize;
|
||||
/** @type {!HTMLInputElement} */
|
||||
@@ -157,9 +157,8 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(opt_quietInput) {
|
||||
// Bind to keyPress -- repeatedly resize when holding down a key.
|
||||
htmlInput.onKeyPressWrapper_ =
|
||||
Blockly.bindEvent_(htmlInput, 'keypress', this, this.onHtmlInputChange_);
|
||||
var workspaceSvg = this.sourceBlock_.workspace.getCanvas();
|
||||
htmlInput.onWorkspaceChangeWrapper_ =
|
||||
Blockly.bindEvent_(workspaceSvg, 'blocklyWorkspaceChange', this,
|
||||
Blockly.bindEvent_(workspace.getCanvas(), 'blocklyWorkspaceChange', this,
|
||||
this.resizeEditor_);
|
||||
};
|
||||
|
||||
|
||||
@@ -177,19 +177,16 @@ Blockly.fireUiEventNow = function(node, eventName) {
|
||||
list.splice(i, 1);
|
||||
}
|
||||
}
|
||||
// Fire the event in a browser-compatible way.
|
||||
if (document.createEvent) {
|
||||
// Create a UI event in a browser-compatible way.
|
||||
if (typeof UIEvent == 'function') {
|
||||
// W3
|
||||
var evt = document.createEvent('UIEvents');
|
||||
evt.initEvent(eventName, true, true); // event type, bubbling, cancelable
|
||||
node.dispatchEvent(evt);
|
||||
} else if (document.createEventObject) {
|
||||
// MSIE
|
||||
var evt = document.createEventObject();
|
||||
node.fireEvent('on' + eventName, evt);
|
||||
var evt = new UIEvent(eventName, {});
|
||||
} else {
|
||||
throw 'FireEvent: No event creation mechanism.';
|
||||
// MSIE
|
||||
var evt = document.createEvent('UIEvent');
|
||||
evt.initUIEvent(eventName, false, false, window, 0);
|
||||
}
|
||||
node.dispatchEvent(evt);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -472,7 +472,8 @@ Blockly.WorkspaceSvg.prototype.highlightBlock = function(id) {
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.fireChangeEvent = function() {
|
||||
if (this.rendered && this.svgBlockCanvas_) {
|
||||
Blockly.fireUiEvent(this.svgBlockCanvas_, 'blocklyWorkspaceChange');
|
||||
var details = {workspace: this.id};
|
||||
Blockly.Events.fire(details);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user