index.js 2.1 KB
Newer Older
N
nem035 已提交
1 2 3
'use strict';

const RSVP = require('rsvp');
4
const app = require('./app');
N
nem035 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18
const AppConstructor = require('./app/constructor');
const DOM = require('./dom');
const Server = require('./server');
const modules = require('./module');

const {
  extend
} = $;

$.ajaxSetup({
  cache: false,
  dataType: 'text'
});

19 20 21 22 23
const {
  isScratchPaper
} = require('./utils');

const {
24 25
  getHashValue,
  getParameterByName,
26 27 28
  getPath
} = require('./server/helpers');

N
nem035 已提交
29
// set global promise error handler
30
RSVP.on('error', function (reason) {
N
nem035 已提交
31 32 33 34 35 36
  console.assert(false, reason);
});

$(() => {

  // initialize the application and attach in to the instance module
37 38
  const appConstructor = new AppConstructor();
  extend(true, app, appConstructor);
N
nem035 已提交
39 40 41 42 43

  // load modules to the global scope so they can be evaled
  extend(true, window, modules);

  Server.loadCategories().then((data) => {
44
    app.setCategories(data);
45
    DOM.addCategories();
N
nem035 已提交
46

47 48
    //enable search feature
    DOM.enableSearch ();
E
EC2 Default User 已提交
49 50
    //enable fullscreen feature
    DOM.enableFullScreen ();
51

N
nem035 已提交
52 53
    // determine if the app is loading a pre-existing scratch-pad
    // or the home page
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    const {
      category,
      algorithm,
      file
    } = getPath();
    if (isScratchPaper(category)) {
      if (algorithm) {
        Server.loadScratchPaper(algorithm).then(({category, algorithm, data}) => {
          DOM.showAlgorithm(category, algorithm, data);
        });
      } else {
        Server.loadAlgorithm(category).then((data) => {
          DOM.showAlgorithm(category, null, data);
        });
      }
    } else if (category && algorithm) {
      DOM.showRequestedAlgorithm(category, algorithm, file);
N
nem035 已提交
71 72 73
    } else {
      DOM.showFirstAlgorithm();
    }
K
more!  
Kevin Nadro 已提交
74

N
nem035 已提交
75
  });
J
show md  
Jason Park 已提交
76 77

  Server.loadWikiList().then((data) => {
J
Jason Park 已提交
78
    app.setWikiList(data.wikis);
J
Jason Park 已提交
79 80

    DOM.showWiki('Tracer');
81 82 83 84 85 86 87 88 89
  });

  var v1LoadedScratch = getHashValue('scratch-paper');
  var v2LoadedScratch = getParameterByName('scratch-paper');
  var vLoadedScratch = v1LoadedScratch || v2LoadedScratch;
  if (vLoadedScratch) {
    window.location.href = window.location.protocol + '//' + window.location.host + window.location.pathname + '#path=scratch/' + vLoadedScratch;
  }

E
EC2 Default User 已提交
90
});