diff --git a/src/editor/blocks/BlockArg.js b/src/editor/blocks/BlockArg.js index c5839a1e..33529a89 100644 --- a/src/editor/blocks/BlockArg.js +++ b/src/editor/blocks/BlockArg.js @@ -3,7 +3,7 @@ import BlockSpecs from './BlockSpecs'; import Menu from './Menu'; import Undo from '../ui/Undo'; import {setCanvasSize, setProps, writeText, scaleMultiplier, - newHTML, newDiv, newCanvas, getStringSize, isTablet, + newHTML, newDiv, newCanvas, getStringSize, newP, globalx, globaly} from '../../utils/lib'; import Localization from '../../utils/Localization'; @@ -295,7 +295,7 @@ export default class BlockArg { } pressDropDown (e, fcn) { - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } if (ScratchJr.onHold) { diff --git a/src/editor/blocks/Menu.js b/src/editor/blocks/Menu.js index d5b7d7d3..93abebd6 100644 --- a/src/editor/blocks/Menu.js +++ b/src/editor/blocks/Menu.js @@ -1,5 +1,5 @@ import BlockSpecs from './BlockSpecs'; -import {scaleMultiplier, setProps, setCanvasSize, newHTML, isTablet, +import {scaleMultiplier, setProps, setCanvasSize, newHTML, newDiv, getDocumentHeight, drawThumbnail, frame, globalx, globaly} from '../../utils/lib'; let openMenu = undefined; @@ -82,7 +82,7 @@ export default class Menu { fcn(evt, mu, block, c); }; function handleTouchStart (e) { - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } e.preventDefault(); diff --git a/src/editor/engine/Sprite.js b/src/editor/engine/Sprite.js index 72c98c4b..69236310 100755 --- a/src/editor/engine/Sprite.js +++ b/src/editor/engine/Sprite.js @@ -26,7 +26,7 @@ import ScratchAudio from '../../utils/ScratchAudio'; import Scripts from '../ui/Scripts'; import {newHTML, newDiv, newP, gn, setCanvasSizeScaledToWindowDocumentHeight, - DEGTOR, getIdFor, setProps, isTablet, isiOS, + DEGTOR, getIdFor, setProps, isiOS, isAndroid, fitInRect, scaleMultiplier, setCanvasSize, globaly, globalx, rgbToHex} from '../../utils/lib'; @@ -911,13 +911,9 @@ export default class Sprite { me.unfocusText(); }); } else { - if (isTablet) { + setTimeout(function () { ti.focus(); - } else { - setTimeout(function () { - ti.focus(); - }, 100); - } + }, 100); } } diff --git a/src/editor/ui/Grid.js b/src/editor/ui/Grid.js index a37d2e33..3f531bec 100644 --- a/src/editor/ui/Grid.js +++ b/src/editor/ui/Grid.js @@ -5,7 +5,7 @@ import ScratchJr from '../ScratchJr'; import Events from '../../utils/Events'; import Localization from '../../utils/Localization'; -import {gn, scaleMultiplier, isTablet, newDiv, setProps, newP, newCanvas} from '../../utils/lib'; +import {gn, scaleMultiplier, newDiv, setProps, newP, newCanvas} from '../../utils/lib'; let width = 482; let height = 362; @@ -69,15 +69,12 @@ export default class Grid { ctx.stroke(); dy += size; } - if (isTablet) { - cnv.ontouchstart = function (evt) { - ScratchJr.stage.mouseDown(evt); - }; - } else { - cnv.onmousedown = function (evt) { - ScratchJr.stage.mouseDown(evt); - }; - } + cnv.ontouchstart = function (evt) { + ScratchJr.stage.mouseDown(evt); + }; + cnv.onmousedown = function (evt) { + ScratchJr.stage.mouseDown(evt); + }; } static createNumbering (w, h) { @@ -153,15 +150,12 @@ export default class Grid { var cnv = newCanvas(gc, 0, 0, size + 2, size + 2, { position: 'absolute' }); - if (isTablet) { - cnv.ontouchstart = function (evt) { - Grid.mouseDownOnCursor(evt); - }; - } else { - cnv.onmousedown = function (evt) { - Grid.mouseDownOnCursor(evt); - }; - } + cnv.ontouchstart = function (evt) { + Grid.mouseDownOnCursor(evt); + }; + cnv.onmousedown = function (evt) { + Grid.mouseDownOnCursor(evt); + }; var ctx = cnv.getContext('2d'); ctx.globalAlpha = 0.5; ctx.fillStyle = '#28A5DA'; @@ -169,11 +163,8 @@ export default class Grid { ctx.lineWidth = 3; ctx.strokeRect(3, 3, size - 6, size - 6); ctx.fillRect(3, 3, size - 6, size - 6); - if (isTablet) { - gc.ontouchstart = Grid.mouseDownOnCursor; - } else { - gc.onmousedown = Grid.mouseDownOnCursor; - } + gc.ontouchstart = Grid.mouseDownOnCursor; + gc.onmousedown = Grid.mouseDownOnCursor; } static mouseDownOnCursor (e) { diff --git a/src/editor/ui/Palette.js b/src/editor/ui/Palette.js index 76fa1c4d..b26d8ba7 100644 --- a/src/editor/ui/Palette.js +++ b/src/editor/ui/Palette.js @@ -14,7 +14,7 @@ import Rectangle from '../../geom/Rectangle'; import DrawPath from '../../utils/DrawPath'; import ScratchAudio from '../../utils/ScratchAudio'; import Record from './Record'; -import {frame, gn, localx, newHTML, scaleMultiplier, isTablet, newDiv, +import {frame, gn, localx, newHTML, scaleMultiplier, newDiv, setProps, globalx, localy, globaly, drawScaled, newCanvas, setCanvasSize, hitRect, writeText, getStringSize} from '../../utils/lib'; @@ -71,7 +71,7 @@ export default class Palette { } static paletteMouseDown (e) { - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } if (ScratchJr.onHold) { diff --git a/src/editor/ui/Scripts.js b/src/editor/ui/Scripts.js index a367ef6f..6096da1c 100644 --- a/src/editor/ui/Scripts.js +++ b/src/editor/ui/Scripts.js @@ -9,7 +9,7 @@ import ScriptsPane from './ScriptsPane'; import Events from '../../utils/Events'; import ScratchAudio from '../../utils/ScratchAudio'; import {gn, newHTML, setCanvasSize, setProps, - localx, localy, scaleMultiplier, hit3DRect, isTablet} from '../../utils/lib'; + localx, localy, scaleMultiplier, hit3DRect} from '../../utils/lib'; export default class Scripts { constructor (spr) { @@ -43,7 +43,7 @@ export default class Scripts { //////////////////////////////////////////////// scriptsMouseDown (e) { - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } if (ScratchJr.onHold) { diff --git a/src/editor/ui/ScriptsPane.js b/src/editor/ui/ScriptsPane.js index 885cc5a6..d318b151 100644 --- a/src/editor/ui/ScriptsPane.js +++ b/src/editor/ui/ScriptsPane.js @@ -8,7 +8,7 @@ import Events from '../../utils/Events'; import Scroll from './Scroll'; import Menu from '../blocks/Menu'; import ScratchAudio from '../../utils/ScratchAudio'; -import {gn, localx, localy, newHTML, isTablet, +import {gn, localx, localy, newHTML, globalx, globaly, setCanvasSize, getDocumentHeight, frame} from '../../utils/lib'; let scroll = undefined; @@ -254,7 +254,7 @@ export default class ScriptsPane { if (Menu.openMenu) { return; } - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } e.preventDefault(); @@ -270,21 +270,18 @@ export default class ScriptsPane { } static setDragBackgroundEvents (fcnmove, fcnup) { - if (isTablet) { // setDragBackgroundEvents - window.ontouchmove = function (evt) { - fcnmove(evt); - }; - window.ontouchend = function (evt) { - fcnup(evt); - }; - } else { - window.onmousemove = function (evt) { - fcnmove(evt); - }; - window.onmouseup = function (evt) { - fcnup(evt); - }; - } + window.ontouchmove = function (evt) { + fcnmove(evt); + }; + window.ontouchend = function (evt) { + fcnup(evt); + }; + window.onmousemove = function (evt) { + fcnmove(evt); + }; + window.onmouseup = function (evt) { + fcnup(evt); + }; } static dragMove (e) { diff --git a/src/editor/ui/Scroll.js b/src/editor/ui/Scroll.js index 179ad749..2793b14d 100644 --- a/src/editor/ui/Scroll.js +++ b/src/editor/ui/Scroll.js @@ -3,7 +3,7 @@ //////////////////////////////////////////////// import Events from '../../utils/Events'; -import {newDiv, newHTML, CSSTransition3D, isTablet, setCanvasSize} from '../../utils/lib'; +import {newDiv, newHTML, CSSTransition3D, setCanvasSize} from '../../utils/lib'; export default class Scroll { constructor (div, id, w, h, cfcn, ofcn) { @@ -50,45 +50,33 @@ export default class Scroll { newHTML('div', 'halign down', this.adown); var me = this; - if (isTablet) { - this.aup.ontouchstart = function (e) { - me.scrolldown(e); - }; - } else { - this.aup.onmousedown = function (e) { - me.scrolldown(e); - }; - } + this.aup.ontouchstart = function (e) { + me.scrolldown(e); + }; + this.aup.onmousedown = function (e) { + me.scrolldown(e); + }; - if (isTablet) { - this.adown.ontouchstart = function (e) { - me.scrollup(e); - }; - } else { - this.adown.onmousedown = function (e) { - me.scrollup(e); - }; - } + this.adown.ontouchstart = function (e) { + me.scrollup(e); + }; + this.adown.onmousedown = function (e) { + me.scrollup(e); + }; - if (isTablet) { - this.aleft.ontouchstart = function (e) { - me.scrollright(e); - }; - } else { - this.aleft.onmousedown = function (e) { - me.scrollright(e); - }; - } + this.aleft.ontouchstart = function (e) { + me.scrollright(e); + }; + this.aleft.onmousedown = function (e) { + me.scrollright(e); + }; - if (isTablet) { - this.aright.ontouchstart = function (e) { - me.scrollleft(e); - }; - } else { - this.aright.onmousedown = function (e) { - me.scrollleft(e); - }; - } + this.aright.ontouchstart = function (e) { + me.scrollleft(e); + }; + this.aright.onmousedown = function (e) { + me.scrollleft(e); + }; } @@ -329,7 +317,7 @@ export default class Scroll { //////////////////////////////////////////////////////////// scrolldown (e) { - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } e.preventDefault(); @@ -357,7 +345,7 @@ export default class Scroll { } scrollup (e) { - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } e.preventDefault(); @@ -385,7 +373,7 @@ export default class Scroll { } scrollright (e) { - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } e.preventDefault(); @@ -413,7 +401,7 @@ export default class Scroll { } scrollleft (e) { - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } e.preventDefault(); diff --git a/src/editor/ui/Thumbs.js b/src/editor/ui/Thumbs.js index 790f13e8..0e5bddc7 100644 --- a/src/editor/ui/Thumbs.js +++ b/src/editor/ui/Thumbs.js @@ -12,7 +12,7 @@ import OS from '../../tablet/OS'; import Events from '../../utils/Events'; import ScratchAudio from '../../utils/ScratchAudio'; import {frame, gn, localx, newHTML, scaleMultiplier, getIdFor, - isTablet, newImage, localy, setProps} from '../../utils/lib'; + newImage, localy, setProps} from '../../utils/lib'; let caret = undefined; @@ -360,7 +360,7 @@ export default class Thumbs { } static clickOnEmptyPage (e) { - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } ScratchAudio.sndFX('tap.wav'); diff --git a/src/editor/ui/UI.js b/src/editor/ui/UI.js index b9f2016f..494eb835 100644 --- a/src/editor/ui/UI.js +++ b/src/editor/ui/UI.js @@ -21,7 +21,7 @@ import Events from '../../utils/Events'; import Localization from '../../utils/Localization'; import ScratchAudio from '../../utils/ScratchAudio'; import {frame, gn, CSSTransition, localx, newHTML, scaleMultiplier, fullscreenScaleMultiplier, - getIdFor, isTablet, newDiv, newTextInput, isAndroid, getDocumentWidth, getDocumentHeight, + getIdFor, newDiv, newTextInput, isAndroid, getDocumentWidth, getDocumentHeight, setProps, globalx} from '../../utils/lib'; let projectNameTextInput = null; @@ -598,7 +598,7 @@ export default class UI { ////////////////////////////////// static spriteThumbsActions (e) { - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } if (ScratchJr.onHold) { diff --git a/src/editor/ui/Undo.js b/src/editor/ui/Undo.js index 2ca71aab..bf0082a8 100755 --- a/src/editor/ui/Undo.js +++ b/src/editor/ui/Undo.js @@ -8,7 +8,7 @@ import Project from './Project'; import Palette from './Palette'; import UI from './UI'; import ScratchAudio from '../../utils/ScratchAudio'; -import {newHTML, isTablet, gn} from '../../utils/lib'; +import {newHTML, gn} from '../../utils/lib'; let buffer = []; let index = 0; @@ -72,7 +72,7 @@ export default class Undo { //////////////////////////////// static prevStep (e) { - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } e.preventDefault(); @@ -93,7 +93,7 @@ export default class Undo { } static nextStep (e) { - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } e.preventDefault(); diff --git a/src/lobby/Home.js b/src/lobby/Home.js index 354ac9bf..ad10c19c 100755 --- a/src/lobby/Home.js +++ b/src/lobby/Home.js @@ -9,7 +9,8 @@ import Project from '../editor/ui/Project'; import Localization from '../utils/Localization'; import ScratchAudio from '../utils/ScratchAudio'; import Vector from '../geom/Vector'; -import {gn, newHTML, isTablet} from '../utils/lib'; +import Events from '../utils/Events'; +import {gn, newHTML} from '../utils/lib'; let frame; let scrollvalue; @@ -320,25 +321,3 @@ export default class Home { } } } - -class Events { - static getTargetPoint (e) { - if (isTablet) { - if (e.touches && (e.touches.length > 0)) { - return { - x: e.touches[0].pageX, - y: e.touches[0].pageY - }; - } else if (e.changedTouches) { - return { - x: e.changedTouches[0].pageX, - y: e.changedTouches[0].pageY - }; - } - } - return { - x: e.clientX, - y: e.clientY - }; - } -} diff --git a/src/painteditor/Paint.js b/src/painteditor/Paint.js index 0ea01da9..59273411 100644 --- a/src/painteditor/Paint.js +++ b/src/painteditor/Paint.js @@ -16,7 +16,7 @@ import Camera from './Camera'; import Events from '../utils/Events'; import Transform from './Transform'; import Vector from '../geom/Vector'; -import {gn, newHTML, setCanvasSize, isTablet, getIdFor, isAndroid, setProps, hitRect, frame} from '../utils/lib'; +import {gn, newHTML, setCanvasSize, supportTouch, getIdFor, isAndroid, setProps, hitRect, frame} from '../utils/lib'; // Originally several files (Paint.js, PaintIO.js, PaintLayout.js) // were all contributing utility functions to the Paint object. @@ -359,7 +359,7 @@ export default class Paint { } static mouseDown (e) { - if ((isTablet && e.target.ontouchstart) || e.target.ontouchstart) { + if ((supportTouch && e.target.ontouchstart) || e.target.ontouchstart) { return; } var pt = Events.getTargetPoint(e); diff --git a/src/painteditor/PaintAction.js b/src/painteditor/PaintAction.js index 9736a3b9..0d143383 100644 --- a/src/painteditor/PaintAction.js +++ b/src/painteditor/PaintAction.js @@ -13,7 +13,7 @@ import SVGImage from './SVGImage'; import Camera from './Camera'; import Events from '../utils/Events'; import Rectangle from '../geom/Rectangle'; -import {gn, isTablet, getIdFor} from '../utils/lib'; +import {gn, supportTouch, getIdFor} from '../utils/lib'; /* Type of objects: - fixed: Only exists on Assets Backgrounds and can it only be fill (color or camera) or removed @@ -762,7 +762,7 @@ export default class PaintAction { } static cameraMouseUp (evt) { - if (isTablet) { + if (supportTouch) { PaintAction.fingerUp(evt); } if (currentShape == undefined) { diff --git a/src/painteditor/Path.js b/src/painteditor/Path.js index f0b7fb86..c682e164 100644 --- a/src/painteditor/Path.js +++ b/src/painteditor/Path.js @@ -17,7 +17,7 @@ import PaintUndo from './PaintUndo'; import PaintAction from './PaintAction'; import Ghost from './Ghost'; import Events from '../utils/Events'; -import {gn, getIdFor, setCanvasSize, isTablet} from '../utils/lib'; +import {gn, getIdFor, setCanvasSize, supportTouch} from '../utils/lib'; // Previous "PathEdit" globals let lineDotColor = 'white'; @@ -139,7 +139,7 @@ export default class Path { var j = 0; var plist = []; plist.push(points[0]); - var dist = isTablet ? 40 : 30; + var dist = supportTouch ? 40 : 30; var before, here, after; while (i < n - 1) { before = points[j]; @@ -763,7 +763,7 @@ export default class Path { static getDot (g, cmd, pt) { cmd = cmd.toUpperCase(); var iscurve = SVG2Canvas.curveoptions.indexOf(cmd) > -1; - var radius = Math.floor((isTablet ? idotsize : dotsize) / Paint.currentZoom) + 1; + var radius = Math.floor((supportTouch ? idotsize : dotsize) / Paint.currentZoom) + 1; var skip = (cmd == 'Z'); var cp = SVGTools.addChild(g, 'circle', { 'id': getIdFor('grab'), @@ -990,7 +990,7 @@ export default class Path { } var pt = PaintAction.getScreenPt(evt); var closestdot = Path.getClosestDotTo(pt, - Math.floor((isTablet ? idotsize + 4 : dotsize) / Paint.currentZoom) * 2); + Math.floor((supportTouch ? idotsize + 4 : dotsize) / Paint.currentZoom) * 2); if (closestdot) { PaintAction.target = closestdot; } diff --git a/src/utils/Events.js b/src/utils/Events.js index c0984384..495571c9 100644 --- a/src/utils/Events.js +++ b/src/utils/Events.js @@ -2,7 +2,7 @@ the caller should define the window event and call startDrag with the appropiate values */ -import {gn, scaleMultiplier, isTablet} from './lib'; +import {gn, scaleMultiplier, supportTouch} from './lib'; let dragged = false; let dragthumbnail = undefined; @@ -118,7 +118,7 @@ export default class Events { Events.holdit(c, athold); } updatefcn = atdrag; - if (isTablet) { // startDrag event setting + if (supportTouch) { // startDrag event setting delta = 10 * scaleMultiplier; window.ontouchleave = function (evt) { Events.mouseUp(evt); @@ -258,7 +258,7 @@ export default class Events { */ static getTargetPoint (e) { - if (isTablet) { + if (supportTouch) { if (e.touches && (e.touches.length > 0)) { return { x: e.touches[0].pageX, diff --git a/src/utils/lib.js b/src/utils/lib.js index 7a825fee..38136ca1 100755 --- a/src/utils/lib.js +++ b/src/utils/lib.js @@ -1,7 +1,5 @@ export var frame; -// XXX: isTablet is legacy code that can be used to detect if we're running on a desktop browser -// There are references to it throughout the codebase, should possibly be removed at some point -export const isTablet = ('ontouchstart' in document.documentElement); +export const supportTouch = ('ontouchstart' in document.documentElement); export const DEGTOR = Math.PI / 180; export const WINDOW_INNER_HEIGHT = window.innerHeight; export const WINDOW_INNER_WIDTH = window.innerWidth;