import { Drawing } from './Drawing' ; import { CircularMenu } from './CircularMenu' ; import { MagnetTextManager } from './MagnetTextManager' ; import { Wallpaper } from './Wallpaper' ; import { ErrorMessage } from './ErrorMessage' ; import { GUIActions } from './GUIActions' ; import { Sound } from './Sound' ; import { TestPerformance } from './TestPerformance' ; import { CSSStyleModifier } from './CSSStyleModifier' ; import { BoardNavigation } from './BoardNavigation' ; import { Share } from "./share" ; import { MyMagnets } from "./myMagnets" ; import { MagnetManager } from './magnetManager' ; import { BoardManager } from './boardManager' ; import { UserManager } from './UserManager' ; import { LoadSave } from './LoadSave' ; import { Layout } from './Layout' ; import { Toolbar } from './Toolbar' ; import { Discussion } from './Discussion' ; import { ChalkCursor } from './ChalkCursor' ; import { BackgroundTexture } from './BackgroundTexture' ; import { BackgroundDocuments } from './BackgroundDocuments' ; import { Translation } from './Translation' ; import { Menu } from './Menu' ; import { TouchScreen } from './TouchScreen' ; import { KeyBoardShortCuts } from './KeyBoardShortCuts' ; import { S , Script } from './Script' ; import { Export } from './Export' ; import { Tool } from './Tool' ; import { DesktopApplicationManager } from './DesktopApplicationManager' ; TestPerformance . init ( ) ; window . onload = load ; window [ 'Menu' ] = Menu ; /**
 * this function sets the document.body scrolls to 0
 * It solves some issues:
 * - on smartphones: that we can scroll the page itself
 * - when typing texts in magnet, it makes the screen not to scroll
 */ function installBodyNoScroll ( ) { setInterval ( ( ) => { document . body . scrollLeft = 0 ; document . body . scrollTop = 0 ; } , 1000 ) ; } function load ( ) { try { installBodyNoScroll ( ) ; UserManager . init ( ) ; BackgroundDocuments . init ( ) ; Layout . init ( ) ; Translation . init ( ) ; ChalkCursor . init ( ) ; LoadSave . init ( ) ; Export . init ( ) ; BoardManager . init ( ) ; Menu . init ( ) ; Share . init ( ) ; Toolbar . init ( ) ; Discussion . init ( ) ; CSSStyleModifier . init ( ) ; Drawing . init ( ) ; BoardNavigation . init ( ) ; BackgroundTexture . init ( ) ; GUIActions . init ( ) ; MagnetManager . init ( ) ; MyMagnets . loadMagnets ( ) ; Sound . init ( ) ; Script . init ( ) ; Wallpaper . init ( ) ; Tool . init ( ) ; Drawing . init ( ) ; BoardManager . load ( ) ; DesktopApplicationManager . init ( ) ; Array . from ( document . getElementsByTagName ( "helpbutton" ) ) . map ( ( b ) => ( < HTMLElement > b ) . onclick = ( evt ) => { alert ( ( < HTMLElement > evt . target ) . title ) ; } ) ; document . getElementById ( "buttonMenu" ) . onclick = Menu . toggle ; document . getElementById ( "buttonColors" ) . onclick = ( evt ) => { GUIActions . changeColor ( ) ; evt . stopPropagation ( ) ; } ; document . getElementById ( "buttonChalk" ) . onclick = GUIActions . switchChalkEraser ; document . getElementById ( "buttonEraser" ) . onclick = GUIActions . switchChalkEraser ; document . getElementById ( "buttonTools" ) . onclick = ( evt ) => { GUIActions . toolmenu . show ( { x : UserManager . me . x , y : UserManager . me . y } ) ; evt . stopPropagation ( ) ; } ; document . getElementById ( "buttonText" ) . onclick = ( ) => MagnetTextManager . addMagnetText ( UserManager . me . x , UserManager . me . y ) ; document . getElementById ( "buttonDivide" ) . onclick = ( ) => Share . execute ( "divideScreen" , [ UserManager . me . userID , Layout . getXMiddle ( ) ] ) ; document . getElementById ( "buttonLeft" ) . onclick = BoardNavigation . leftPreviousPage ; document . getElementById ( "buttonRight" ) . onclick = BoardNavigation . rightNextPage ; document . getElementById ( "buttonMap" ) . onclick = Layout . toggleMinimap ; document . getElementById ( "buttonCancel" ) . onclick = ( ) => BoardManager . cancel ( UserManager . me . userID ) ; document . getElementById ( "buttonRedo" ) . onclick = ( ) => BoardManager . redo ( UserManager . me . userID ) ; document . getElementById ( "buttonAskQuestion" ) . onclick = Discussion . askQuestion ; const buttons = document . getElementById ( "controls" ) . children ; for ( let i = 0 ; i < buttons . length ; i ++ ) if ( buttons [ i ] instanceof HTMLButtonElement ) ( < HTMLButtonElement > buttons [ i ] ) . onfocus = ( < HTMLElement > document . activeElement ) . blur ; document . onkeydown = KeyBoardShortCuts . onKeyDown ; document . onkeyup = KeyBoardShortCuts . onKeyUp ; document . getElementById ( "canvasBackground" ) . onpointermove = ( ) => { console . log ( "mousemove on the background should not occur" ) ; } ; document . getElementById ( "previousSlide" ) . onclick = ( ) => BoardManager . previousPausedFrame ( ) ; document . getElementById ( "nextSlide" ) . onclick = ( ) => BoardManager . nextPausedFrame ( ) ; installMouseEventsCanvas ( ) ; } catch ( e ) { console . log ( e ) ; ErrorMessage . show ( "Problem in loading Tableaunoir... please try to clean the cache of your browser." ) ; } } function installMouseEventsCanvas ( ) { const minDurationMouseMove = 100 ; let timeToMouseMove = true ; let ismousedown = false ; setInterval ( ( ) => { timeToMouseMove = true ; } , minDurationMouseMove ) ; document . getElementById ( "canvas" ) . onpointerdown = ( evt ) => { evt . preventDefault ( ) ; ismousedown = true ; window [ "ismousedown" ] = true ; Share . execute ( "mousedown" , [ UserManager . me . userID , evt ] ) ; } ; document . getElementById ( "canvas" ) . onpointermove = ( evt ) => { evt . preventDefault ( ) ; const point = { x : evt . offsetX , y : evt . offsetY } ; window [ "point" ] = point ; S . onmousemove ( point ) ; if ( ( ismousedown && UserManager . me . canWrite ) || timeToMouseMove ) { Share . execute ( "mousemove" , [ UserManager . me . userID , evt ] ) ; timeToMouseMove = false ; } } ; document . getElementById ( "canvas" ) . onpointerup = ( evt ) => { evt . preventDefault ( ) ; ismousedown = false ; window [ "ismousedown" ] = false ; Share . execute ( "mouseup" , [ UserManager . me . userID , evt ] ) ; } ; document . getElementById ( "canvas" ) . onpointerleave = ( evt ) => { evt . preventDefault ( ) ; ismousedown = false ; window [ "ismousedown" ] = false ; Share . execute ( "mouseup" , [ UserManager . me . userID , evt ] ) ; } ; TouchScreen . addTouchEvents ( document . getElementById ( "canvas" ) ) ; document . getElementById ( "controls" ) . onclick = CircularMenu . hide ; document . getElementById ( "animationToolBar" ) . onclick = CircularMenu . hide ; } export function getCanvas ( ) { return < HTMLCanvasElement > document . getElementById ( "canvas" ) ; } export function getCanvasBackground ( ) { return < HTMLCanvasElement > document . getElementById ( "canvasBackground" ) ; } export function getContainer ( ) { return document . getElementById ( "container" ) ; }