Fixed mobile layout issues and improved editor layout styles
This commit is contained in:
parent
b5d9d28f2e
commit
40f9206190
3 changed files with 47 additions and 34 deletions
|
@ -15,7 +15,7 @@ body {
|
||||||
letter-spacing: 0.025em;
|
letter-spacing: 0.025em;
|
||||||
line-height: 1.25;
|
line-height: 1.25;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
min-height: 100%;
|
height: auto !important;
|
||||||
overflow-y: hidden !important;
|
overflow-y: hidden !important;
|
||||||
-webkit-overflow-scrolling: touch;
|
-webkit-overflow-scrolling: touch;
|
||||||
}
|
}
|
||||||
|
|
|
@ -530,6 +530,7 @@ var ui = {
|
||||||
edit: $(".ui-edit-area"),
|
edit: $(".ui-edit-area"),
|
||||||
view: $(".ui-view-area"),
|
view: $(".ui-view-area"),
|
||||||
codemirror: $(".ui-edit-area .CodeMirror"),
|
codemirror: $(".ui-edit-area .CodeMirror"),
|
||||||
|
codemirrorScroll: $(".ui-edit-area .CodeMirror .CodeMirror-scroll"),
|
||||||
markdown: $(".ui-view-area .markdown-body")
|
markdown: $(".ui-view-area .markdown-body")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -703,7 +704,7 @@ function locationHashChanged(e) {
|
||||||
var windowResizeDebounce = 200;
|
var windowResizeDebounce = 200;
|
||||||
var windowResize = _.debounce(windowResizeInner, windowResizeDebounce);
|
var windowResize = _.debounce(windowResizeInner, windowResizeDebounce);
|
||||||
|
|
||||||
function windowResizeInner() {
|
function windowResizeInner(callback) {
|
||||||
checkLayout();
|
checkLayout();
|
||||||
checkResponsive();
|
checkResponsive();
|
||||||
checkEditorStyle();
|
checkEditorStyle();
|
||||||
|
@ -711,18 +712,29 @@ function windowResizeInner() {
|
||||||
checkCursorMenu();
|
checkCursorMenu();
|
||||||
//refresh editor
|
//refresh editor
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
editor.setOption('viewportMargin', Infinity);
|
if (editor.getOption('scrollbarStyle') === 'native') {
|
||||||
setTimeout(function () {
|
|
||||||
clearMap();
|
clearMap();
|
||||||
syncScrollToView();
|
syncScrollToView();
|
||||||
editor.setOption('viewportMargin', viewportMargin);
|
|
||||||
//add or update user cursors
|
|
||||||
for (var i = 0; i < onlineUsers.length; i++) {
|
|
||||||
if (onlineUsers[i].id != personalInfo.id)
|
|
||||||
buildCursor(onlineUsers[i]);
|
|
||||||
}
|
|
||||||
updateScrollspy();
|
updateScrollspy();
|
||||||
}, 100);
|
if (callback && typeof callback === 'function')
|
||||||
|
callback();
|
||||||
|
} else {
|
||||||
|
// force it load all docs at once to prevent scroll knob blink
|
||||||
|
editor.setOption('viewportMargin', Infinity);
|
||||||
|
setTimeout(function () {
|
||||||
|
clearMap();
|
||||||
|
syncScrollToView();
|
||||||
|
editor.setOption('viewportMargin', viewportMargin);
|
||||||
|
//add or update user cursors
|
||||||
|
for (var i = 0; i < onlineUsers.length; i++) {
|
||||||
|
if (onlineUsers[i].id != personalInfo.id)
|
||||||
|
buildCursor(onlineUsers[i]);
|
||||||
|
}
|
||||||
|
updateScrollspy();
|
||||||
|
if (callback && typeof callback === 'function')
|
||||||
|
callback();
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,25 +766,16 @@ function checkResponsive() {
|
||||||
var lastEditorWidth = 0;
|
var lastEditorWidth = 0;
|
||||||
|
|
||||||
function checkEditorStyle() {
|
function checkEditorStyle() {
|
||||||
|
var desireHeight = statusBar ? (ui.area.edit.height() - statusBar.outerHeight()) : ui.area.edit.height();
|
||||||
|
// set editor height and min height based on scrollbar style and mode
|
||||||
var scrollbarStyle = editor.getOption('scrollbarStyle');
|
var scrollbarStyle = editor.getOption('scrollbarStyle');
|
||||||
if (scrollbarStyle == 'overlay' || currentMode == modeType.both) {
|
if (scrollbarStyle == 'overlay' || currentMode == modeType.both) {
|
||||||
//save last editor scroll top
|
ui.area.codemirrorScroll.css('height', desireHeight + 'px');
|
||||||
var lastTop = editor.getScrollInfo().top;
|
ui.area.codemirrorScroll.css('min-height', '');
|
||||||
ui.area.codemirror.css('height', '');
|
|
||||||
//set editor size to keep status bar on the bottom
|
|
||||||
editor.setSize(null, ui.area.edit.height());
|
|
||||||
//restore last editor scroll top
|
|
||||||
editor.scrollTo(null, lastTop);
|
|
||||||
} else if (scrollbarStyle == 'native') {
|
} else if (scrollbarStyle == 'native') {
|
||||||
ui.area.codemirror.css('height', 'auto');
|
ui.area.codemirrorScroll.css('height', '');
|
||||||
$('.CodeMirror-gutters').css('height', $('.CodeMirror-sizer').height());
|
ui.area.codemirrorScroll.css('min-height', desireHeight + 'px');
|
||||||
}
|
}
|
||||||
//set editor parent height to fill status bar
|
|
||||||
if (statusBar)
|
|
||||||
statusBar.parent().css('height', ui.area.edit.height() - statusBar.outerHeight() + 'px');
|
|
||||||
//set sizer height to make it at least height as editor
|
|
||||||
var editorSizerHeight = ui.area.edit.height() - (statusBar ? statusBar.outerHeight() : 0);
|
|
||||||
$('.CodeMirror-sizer').css('height', editorSizerHeight + 'px');
|
|
||||||
//make editor resizable
|
//make editor resizable
|
||||||
ui.area.edit.resizable({
|
ui.area.edit.resizable({
|
||||||
handles: 'e',
|
handles: 'e',
|
||||||
|
@ -879,6 +882,7 @@ function toggleMode() {
|
||||||
var lastMode = null;
|
var lastMode = null;
|
||||||
|
|
||||||
function changeMode(type) {
|
function changeMode(type) {
|
||||||
|
// lock navbar to prevent it hide after changeMode
|
||||||
lockNavbar();
|
lockNavbar();
|
||||||
saveInfo();
|
saveInfo();
|
||||||
if (type) {
|
if (type) {
|
||||||
|
@ -949,16 +953,15 @@ function changeMode(type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
windowResizeInner();
|
windowResizeInner();
|
||||||
|
|
||||||
restoreInfo();
|
restoreInfo();
|
||||||
|
|
||||||
if (lastMode == modeType.view && currentMode == modeType.both) {
|
if (lastMode == modeType.view && currentMode == modeType.both) {
|
||||||
if (!scrollMap || !lineHeightMap)
|
syncScrollToEdit();
|
||||||
buildMapInner();
|
}
|
||||||
var scrollMapNearest = closestIndex(scrollMap, lastInfo.view.scroll.top);
|
|
||||||
var lineHeightMapNearest = closestIndex(lineHeightMap, scrollMapNearest);
|
if (lastMode != modeType.edit && currentMode == modeType.edit) {
|
||||||
var height = lineHeightMapNearest * defaultTextHeight;
|
editor.refresh();
|
||||||
editor.scrollTo(null, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.toolbar.both.removeClass("active");
|
ui.toolbar.both.removeClass("active");
|
||||||
|
@ -987,6 +990,15 @@ var unlockNavbar = _.debounce(function () {
|
||||||
$('.navbar').removeClass('locked');
|
$('.navbar').removeClass('locked');
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|
||||||
|
function syncScrollToEdit() {
|
||||||
|
if (!scrollMap || !lineHeightMap)
|
||||||
|
buildMapInner();
|
||||||
|
var scrollMapNearest = closestIndex(scrollMap, lastInfo.view.scroll.top);
|
||||||
|
var lineHeightMapNearest = closestIndex(lineHeightMap, scrollMapNearest);
|
||||||
|
var height = lineHeightMapNearest * defaultTextHeight;
|
||||||
|
editor.scrollTo(null, height);
|
||||||
|
}
|
||||||
|
|
||||||
function closestIndex(arr, closestTo) {
|
function closestIndex(arr, closestTo) {
|
||||||
var closest = Math.max.apply(null, arr); //Get the highest number in arr in case it match nothing.
|
var closest = Math.max.apply(null, arr); //Get the highest number in arr in case it match nothing.
|
||||||
var index = 0;
|
var index = 0;
|
||||||
|
|
|
@ -116,6 +116,7 @@ var viewScrollingTimer = null;
|
||||||
|
|
||||||
//editor.on('scroll', _.throttle(syncScrollToView, editorScrollThrottle));
|
//editor.on('scroll', _.throttle(syncScrollToView, editorScrollThrottle));
|
||||||
editor.on('scroll', syncScrollToView);
|
editor.on('scroll', syncScrollToView);
|
||||||
|
ui.area.codemirrorScroll.on('scroll', syncScrollToView);
|
||||||
ui.area.view.on('scroll', function () {
|
ui.area.view.on('scroll', function () {
|
||||||
viewScrolling = true;
|
viewScrolling = true;
|
||||||
clearTimeout(viewScrollingTimer);
|
clearTimeout(viewScrollingTimer);
|
||||||
|
|
Loading…
Reference in a new issue