setup_top_menu.js 1.9 KB
Newer Older
1 2
'use strict';

3
const app = require('../../app');
N
nem035 已提交
4 5
const Server = require('../../server');
const Toast = require('../toast');
6
const TopMenu = require('../top_menu');
N
nem035 已提交
7 8 9 10

module.exports = () => {

  // shared
J
Jason Park 已提交
11
  $('#shared').mouseup(function () {
N
nem035 已提交
12 13 14
    $(this).select();
  });

J
Jason Park 已提交
15
  $('#btn_share').click(function () {
N
nem035 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29

    const $icon = $(this).find('.fa-share');
    $icon.addClass('fa-spin fa-spin-faster');

    Server.shareScratchPaper().then((url) => {
      $icon.removeClass('fa-spin fa-spin-faster');
      $('#shared').removeClass('collapse');
      $('#shared').val(url);
      Toast.showInfoToast('Shareable link is created.');
    });
  });

  // control

J
Jason Park 已提交
30
  const $btnRun = $('#btn_run');
G
Gautam krishna.R 已提交
31
  const $btnRunText=ap=$('#btn_run>span');
32 33
  const $btnTrace = $('#btn_trace');
  const $btnPause = $('#btn_pause');
J
Jason Park 已提交
34 35
  const $btnPrev = $('#btn_prev');
  const $btnNext = $('#btn_next');
36 37

  // initially, control buttons are disabled
38
  TopMenu.disableFlowControl();
39 40 41 42 43

  $btnRun.click(() => {
    $btnTrace.click();
    $btnPause.removeClass('active');
    $btnRun.addClass('active');
44
    TopMenu.enableFlowControl();
45
    var err = app.getEditor().execute();
N
nem035 已提交
46 47 48
    if (err) {
      console.error(err);
      Toast.showErrorToast(err);
J
Jason Park 已提交
49
      TopMenu.resetTopMenuButtons();
N
nem035 已提交
50
    }
G
Gautam krishna.R 已提交
51
    else {
G
Gautam krishna.R 已提交
52
      $btnRunText.html("Rerun");
G
Gautam krishna.R 已提交
53
    }
N
nem035 已提交
54
  });
55 56 57 58

  $btnPause.click(() => {
    $btnRun.toggleClass('active');
    $btnPause.toggleClass('active');
59 60
    if (app.getTracerManager().isPause()) {
      app.getTracerManager().resumeStep();
N
nem035 已提交
61
    } else {
62
      app.getTracerManager().pauseStep();
N
nem035 已提交
63 64
    }
  });
65 66 67 68

  $btnPrev.click(() => {
    $btnRun.removeClass('active');
    $btnPause.addClass('active');
69 70
    app.getTracerManager().pauseStep();
    app.getTracerManager().prevStep();
N
nem035 已提交
71
  });
72 73 74 75

  $btnNext.click(() => {
    $btnRun.removeClass('active');
    $btnPause.addClass('active');
76 77
    app.getTracerManager().pauseStep();
    app.getTracerManager().nextStep();
N
nem035 已提交
78 79
  });

80
};