|
@@ -2,9 +2,10 @@
|
|
|
/* Author: Sotaro KARASAWA <sotarok@crocos.co.jp>
|
|
/* Author: Sotaro KARASAWA <sotarok@crocos.co.jp>
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-var io = require('socket.io-client');
|
|
|
|
|
-var entities = require("entities");
|
|
|
|
|
-var getLineFromPos = require('get-line-from-pos');
|
|
|
|
|
|
|
+const io = require('socket.io-client');
|
|
|
|
|
+const entities = require("entities");
|
|
|
|
|
+const escapeStringRegexp = require('escape-string-regexp');
|
|
|
|
|
+const getLineFromPos = require('get-line-from-pos');
|
|
|
require('bootstrap-sass');
|
|
require('bootstrap-sass');
|
|
|
require('jquery.cookie');
|
|
require('jquery.cookie');
|
|
|
|
|
|
|
@@ -39,10 +40,11 @@ Crowi.appendEditSectionButtons = function(contentId, markdown) {
|
|
|
$('h1,h2,h3,h4,h5,h6', $content).each(function(idx, elm) {
|
|
$('h1,h2,h3,h4,h5,h6', $content).each(function(idx, elm) {
|
|
|
// get header text string
|
|
// get header text string
|
|
|
const text = $(this).text();
|
|
const text = $(this).text();
|
|
|
|
|
+ const escapedText = escapeStringRegexp(text);
|
|
|
|
|
|
|
|
// search pos for '# ...'
|
|
// search pos for '# ...'
|
|
|
// https://regex101.com/r/y5rpO5/1
|
|
// https://regex101.com/r/y5rpO5/1
|
|
|
- const regexp = new RegExp(`[^\r\n]*#+[^\r\n]*${text}[^\r\n]*`);
|
|
|
|
|
|
|
+ const regexp = new RegExp(`[^\r\n]*#+[^\r\n]*${escapedText}[^\r\n]*`);
|
|
|
let position = markdown.search(regexp);
|
|
let position = markdown.search(regexp);
|
|
|
if (position < 0) { // if not found, search with header text only
|
|
if (position < 0) { // if not found, search with header text only
|
|
|
position = markdown.search(text);
|
|
position = markdown.search(text);
|
|
@@ -189,18 +191,29 @@ Crowi.updateCurrentRevision = function(revisionId) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Crowi.handleKeyEHandler = (event) => {
|
|
Crowi.handleKeyEHandler = (event) => {
|
|
|
|
|
+ // ignore when dom that has 'modal in' classes exists
|
|
|
|
|
+ if (document.getElementsByClassName('modal in').length > 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
// show editor
|
|
// show editor
|
|
|
$('a[data-toggle="tab"][href="#edit-form"]').tab('show');
|
|
$('a[data-toggle="tab"][href="#edit-form"]').tab('show');
|
|
|
|
|
+ event.preventDefault();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Crowi.handleKeyCHandler = (event) => {
|
|
Crowi.handleKeyCHandler = (event) => {
|
|
|
|
|
+ // ignore when dom that has 'modal in' classes exists
|
|
|
|
|
+ if (document.getElementsByClassName('modal in').length > 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
// show modal to create a page
|
|
// show modal to create a page
|
|
|
$('#create-page').modal();
|
|
$('#create-page').modal();
|
|
|
|
|
+ event.preventDefault();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Crowi.handleKeyCtrlSlashHandler = (event) => {
|
|
Crowi.handleKeyCtrlSlashHandler = (event) => {
|
|
|
// show modal to create a page
|
|
// show modal to create a page
|
|
|
$('#shortcuts-modal').modal('toggle');
|
|
$('#shortcuts-modal').modal('toggle');
|
|
|
|
|
+ event.preventDefault();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$(function() {
|
|
$(function() {
|
|
@@ -458,11 +471,8 @@ $(function() {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var escape = function(s) {
|
|
|
|
|
- return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
|
|
|
- };
|
|
|
|
|
path = entities.encodeHTML(path);
|
|
path = entities.encodeHTML(path);
|
|
|
- var pattern = escape(entities.encodeHTML(shortPath)) + '(/)?$';
|
|
|
|
|
|
|
+ var pattern = escapeStringRegexp(entities.encodeHTML(shortPath)) + '(/)?$';
|
|
|
|
|
|
|
|
$link.html(path.replace(new RegExp(pattern), '<strong>' + shortPath + '$1</strong>'));
|
|
$link.html(path.replace(new RegExp(pattern), '<strong>' + shortPath + '$1</strong>'));
|
|
|
});
|
|
});
|
|
@@ -894,6 +904,8 @@ window.addEventListener('load', function(e) {
|
|
|
if (location.hash) {
|
|
if (location.hash) {
|
|
|
if (location.hash == '#edit-form') {
|
|
if (location.hash == '#edit-form') {
|
|
|
$('a[data-toggle="tab"][href="#edit-form"]').tab('show');
|
|
$('a[data-toggle="tab"][href="#edit-form"]').tab('show');
|
|
|
|
|
+ // focus
|
|
|
|
|
+ Crowi.setCaretLineAndFocusToEditor();
|
|
|
}
|
|
}
|
|
|
if (location.hash == '#revision-history') {
|
|
if (location.hash == '#revision-history') {
|
|
|
$('a[data-toggle="tab"][href="#revision-history"]').tab('show');
|
|
$('a[data-toggle="tab"][href="#revision-history"]').tab('show');
|
|
@@ -935,7 +947,6 @@ window.addEventListener('load', function(e) {
|
|
|
Crowi.highlightSelectedSection(location.hash);
|
|
Crowi.highlightSelectedSection(location.hash);
|
|
|
Crowi.modifyScrollTop();
|
|
Crowi.modifyScrollTop();
|
|
|
Crowi.setCaretLineAndFocusToEditor();
|
|
Crowi.setCaretLineAndFocusToEditor();
|
|
|
- Crowi.setCaretLineAndFocusToEditor();
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
window.addEventListener('hashchange', function(e) {
|
|
window.addEventListener('hashchange', function(e) {
|
|
@@ -957,7 +968,7 @@ window.addEventListener('hashchange', function(e) {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-window.addEventListener('keypress', (event) => {
|
|
|
|
|
|
|
+window.addEventListener('keydown', (event) => {
|
|
|
const target = event.target;
|
|
const target = event.target;
|
|
|
|
|
|
|
|
// ignore when target dom is input
|
|
// ignore when target dom is input
|
|
@@ -966,11 +977,6 @@ window.addEventListener('keypress', (event) => {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // ignore when dom that has 'modal in' classes exists
|
|
|
|
|
- if (document.getElementsByClassName('modal in').length > 0) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
switch (event.key) {
|
|
switch (event.key) {
|
|
|
case 'e':
|
|
case 'e':
|
|
|
if (!event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
|
|
if (!event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
|