Skip to content
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.

Commit

Permalink
Deal with javascript linter warnings
Browse files Browse the repository at this point in the history
And fixed some bugs
  • Loading branch information
yuntan committed Dec 21, 2015
1 parent 2ee413d commit 0fa410d
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 112 deletions.
6 changes: 6 additions & 0 deletions dtsm.json
Expand Up @@ -24,6 +24,12 @@
},
"toastr/toastr.d.ts": {
"ref": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe"
},
"mathjax/mathjax.d.ts": {
"ref": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe"
},
"highlightjs/highlightjs.d.ts": {
"ref": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe"
}
}
}
67 changes: 32 additions & 35 deletions editorjs/editor.js
@@ -1,5 +1,8 @@
/// <reference path="../typings/bundle.d.ts" />
/* global syaro */
/* global hljs */
/* global convert */
/* global emojify */
import tableFormatter from './tableformatter'
import emojiAutoComplete from './emojiautocomplete'
import mathEditor from './matheditor'
Expand All @@ -11,16 +14,17 @@ var editor,
math,
initialized = false,
modified = false,
timeoutId = '',
timeoutId = 0,
wikiPath = '',
fileName = '',
preview = true,
syncScroll = true;

function init() {
// set wiki path
wikiPath = get_url_vars()["wpath"];
fileName = wikiPath.split('/');
fileName = fileName[fileName.length-1];
var pathlist = wikiPath.split('/');
fileName = pathlist[pathlist.length-1];

// update title
document.title = fileName;
Expand Down Expand Up @@ -66,8 +70,8 @@ function get_url_vars() {
}

function initUi() {
$('.alert').hide()
$('.modal').hide()
$('.alert').hide();
$('.modal').hide();

//
// navbar
Expand Down Expand Up @@ -131,11 +135,11 @@ function initUi() {
$('#mdlSave').modal('hide');
toastr.info("", "Saving...");
});
$('#mdlBackup-restore').on('click', function() {
$('#mdlBackup-restore').on('click', function () {
editor.getSession().getDocument().setValue(getBackup());// FIXME
$('#mdlBackup').modal('hide');
});
$('#mdlBackup-discard').on('click', function() {
$('#mdlBackup-discard').on('click', function () {
backup(true); // remove backup
$('#mdlBackup').modal('hide');
});
Expand All @@ -147,36 +151,29 @@ function initUi() {
$('#optionSyncScroll > span').toggleClass('glyphicon-check', true);
// $('#optionMathJax > span').toggleClass('glyphicon-unchecked', true);

$('#optionPreview').on('click', function() {
preview = !preview
$('#optionPreview > span').toggleClass('glyphicon-check')
$('#optionPreview > span').toggleClass('glyphicon-unchecked')
$('#optionMathJax').parent('li').toggleClass('disabled')
return false
})
$('#optionPreview').on('click', function () {
preview = !preview;
$('#optionPreview > span').toggleClass('glyphicon-check');
$('#optionPreview > span').toggleClass('glyphicon-unchecked');
$('#optionMathJax').parent('li').toggleClass('disabled');
return false;
});

$('#optionSyncScroll').on('click', function() {
$('#optionSyncScroll').on('click', function () {
syncScroll = !syncScroll;
$('#optionSyncScroll > span').toggleClass('glyphicon-check');
$('#optionSyncScroll > span').toggleClass('glyphicon-unchecked');
return false
})

$('#optionMathJax').on('click', function() {
mathjax = !mathjax
$('#optionMathJax > span').toggleClass('glyphicon-check')
$('#optionMathJax > span').toggleClass('glyphicon-unchecked')
return false
})
return false;
});

//
// alert
//
$(window).on('beforeunload', function () {
if (modified) {
return 'Document will not be saved. OK?'
return 'Document will not be saved. OK?';
}
})
});
}

function initAce() {
Expand All @@ -192,7 +189,7 @@ function initAce() {
editor.setShowInvisibles(true);
editor.session.setNewLineMode('unix');
editor.setOptions({
'scrollPastEnd': true,
scrollPastEnd: true,
cursorStyle: 'smooth', // "ace"|"slim"|"smooth"|"wide"
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
Expand All @@ -206,22 +203,22 @@ function initAce() {
modified = true;

// update title
document.title = '* '+fileName;
document.title = '* ' + fileName;

$('#btnSave').addClass('modified');

if(timeoutId !== "") { clearTimeout(timeoutId); }
if (!timeoutId) { clearTimeout(timeoutId); }

timeoutId = setTimeout(() => {
if (initialized) {
backup(false);
}
renderPreview();
}, 600);
})
});

// sync scroll
editor.getSession().on('changeScrollTop', scroll)
editor.getSession().on('changeScrollTop', scroll);

// Ctrl-S: save
var HashHandler = ace.require('ace/keyboard/hash_handler').HashHandler;
Expand All @@ -240,8 +237,8 @@ function initAce() {

function initEmojify() {
emojify.setConfig({
mode: 'sprites',
ignore_emoticons: true,
mode: 'sprites',
ignore_emoticons: true,
});
}

Expand Down Expand Up @@ -286,7 +283,7 @@ function simpleSave() {
toastr.error(err, "Error!");
}
};
api.update(wikiPath, editor.getSession().getValue(), callback);
api.update(wikiPath, editor.getSession().getValue(), callback, null, null, null);
toastr.info("Saving...");
}

Expand All @@ -311,7 +308,7 @@ function scroll() {

var previewHeight = $preview[0].scrollHeight,
previewVisible = $preview.height(),
previewTop = $preview[0].scrollTop,
// previewTop = $preview[0].scrollTop,
editorHeight = editor.getSession().getLength(),
editorVisible = editor.getLastVisibleRow() - editor.getFirstVisibleRow(),
editorTop = editor.getFirstVisibleRow();
Expand Down
4 changes: 2 additions & 2 deletions editorjs/emojiautocomplete.js
Expand Up @@ -35,14 +35,14 @@ function cursorMoveAction(editor) {
}

function tabKeyAction(editor) {
return function() {
return function () {
if (maybe.length > 0) {
insertEmoji(editor, maybe[0]);
hideSuggest();
return true;
}
return false;
}
};
}

function detectSuggestableEmoji(editor) {
Expand Down
12 changes: 6 additions & 6 deletions editorjs/matheditor.js
Expand Up @@ -11,7 +11,7 @@ var editor,
export default function mathEditor(edit) {
editor = edit;
typemath = new TypeMath($("#mdlMath-field"), $("#mdlMath-latex"),
$("#mdlMath-candy"), $("#mdlMath-ghost"), $("#mdlMath-select"));
$("#mdlMath-candy"), $("#mdlMath-ghost"), $("#mdlMath-select"), null);

$('#mdlMath').on('shown.bs.modal', function () {
$('#mdlMath-latex').focus();
Expand Down Expand Up @@ -77,10 +77,10 @@ function detectMath () {
// inline math $x$
var c1 = (line.slice(0, pos.column).match(/\$/g) || []).length;
var c2 = (line.slice(pos.column).match(/\$/g) || []).length;
if (c1%2 == 1 && c2 > 0) {
if (c1%2 === 1 && c2 > 0) {
inline = true;
var startCol = line.slice(0, pos.column).lastIndexOf('$');
var endCol = pos.column + line.slice(pos.column).indexOf('$') + 1;
let startCol = line.slice(0, pos.column).lastIndexOf('$');
let endCol = pos.column + line.slice(pos.column).indexOf('$') + 1;
mathRange = new Range(pos.row, startCol, pos.row, endCol);
return;
}
Expand All @@ -90,8 +90,8 @@ function detectMath () {
c2 = (line.slice(pos.column).match(/\$\$/g) || []).length;
if (c1 > 0 && c2 > 0) {
inline = false;
var startCol = line.slice(0, pos.column).lastIndexOf('$$');
var endCol = pos.column + line.slice(pos.column).indexOf('$$') + 2;
let startCol = line.slice(0, pos.column).lastIndexOf('$$');
let endCol = pos.column + line.slice(pos.column).indexOf('$$') + 2;
mathRange = new Range(pos.row, startCol, pos.row, endCol);
return;
}
Expand Down
6 changes: 3 additions & 3 deletions editorjs/tableformatter.js
Expand Up @@ -40,7 +40,7 @@ function execHashHandler(forward) {
// allow other ace commands to handle event
return false;
}
}
};
}

var CellAlign = Object.freeze({
Expand Down Expand Up @@ -112,7 +112,7 @@ function getTableInfo(session, cursorPos, minLineNum, maxLineNum) {
var numRows = table.length;
var numColumns = 0;

var rowNum, row, columnNum, cell;
var rowNum, columnNum, cell;

var alignRowNum = -1;

Expand Down Expand Up @@ -287,7 +287,7 @@ function moveCursorForward(editor, session, tableInfo, newLine) {
// move to the next column in the same row
moveCursorToCell(editor, tableInfo, focusPos.row, focusPos.column + 1);
}
else if (focusPos.row === 0 && focusPos.column == tableInfo.numColumns - 1) {
else if (focusPos.row === 0 && focusPos.column === tableInfo.numColumns - 1) {
// move to the last of the header row
session.insert(
{
Expand Down

0 comments on commit 0fa410d

Please sign in to comment.