Skip to content

Commit

Permalink
🐛 fix #429
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed May 23, 2020
1 parent c20a33f commit 32ac24c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

### v3.2.10 / 2020-05-xx

* [429](https://github.com/Vanessa219/vditor/issues/429) localStorage被禁用时,报错 `修复缺陷`
* [427](https://github.com/Vanessa219/vditor/issues/427) headings 大小调整 `改进功能`

### v3.2.9 / 2020-05-22
Expand Down
4 changes: 2 additions & 2 deletions src/ts/ir/process.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Constants} from "../constants";
import {getMarkdown} from "../markdown/getMarkdown";
import {isSafari} from "../util/compatibility";
import {accessLocalStorage, isSafari} from "../util/compatibility";
import {listToggle, renderToc} from "../util/fixBrowserBehavior";
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName, hasClosestByMatchTag} from "../util/hasClosest";
import {getEditorRange, getSelectPosition, setRangeByWbr} from "../util/selection";
Expand Down Expand Up @@ -57,7 +57,7 @@ export const processAfterRender = (vditor: IVditor, options = {
vditor.counter.render(vditor, text);
}

if (vditor.options.cache.enable) {
if (vditor.options.cache.enable && accessLocalStorage()) {
localStorage.setItem(vditor.options.cache.id, text);
if (vditor.options.cache.after) {
vditor.options.cache.after(text);
Expand Down
3 changes: 2 additions & 1 deletion src/ts/sv/inputEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {getMarkdown} from "../markdown/getMarkdown";
import {accessLocalStorage} from "../util/compatibility";

export const inputEvent = (vditor: IVditor, options = {
enableAddUndoStack: true,
Expand All @@ -15,7 +16,7 @@ export const inputEvent = (vditor: IVditor, options = {
if (options.enableHint) {
vditor.hint.render(vditor);
}
if (vditor.options.cache.enable) {
if (vditor.options.cache.enable && accessLocalStorage()) {
localStorage.setItem(vditor.options.cache.id, text);
if (vditor.options.cache.after) {
vditor.options.cache.after(text);
Expand Down
3 changes: 2 additions & 1 deletion src/ts/ui/initUI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Constants} from "../constants";
import {html2md} from "../sv/html2md";
import {setEditMode} from "../toolbar/EditMode";
import {accessLocalStorage} from "../util/compatibility";
import {setContentTheme} from "./setContentTheme";
import {setTheme} from "./setTheme";

Expand Down Expand Up @@ -141,7 +142,7 @@ const afterRender = (vditor: IVditor, contentElement: HTMLElement) => {
});

// set default value
let initValue = localStorage.getItem(vditor.options.cache.id);
let initValue = accessLocalStorage() && localStorage.getItem(vditor.options.cache.id);
if (!vditor.options.cache.enable || !initValue) {
if (vditor.options.value) {
initValue = vditor.options.value;
Expand Down
8 changes: 8 additions & 0 deletions src/ts/util/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ export const isFirefox = () => {
return navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
};

export const accessLocalStorage = () => {
try {
return typeof localStorage !== "undefined";
} catch (e) {
return false;
}
};

// 用户 iPhone 点击延迟/需要双击的处理
export const getEventName = () => {
if (navigator.userAgent.indexOf("iPhone") > -1) {
Expand Down
4 changes: 2 additions & 2 deletions src/ts/wysiwyg/afterRenderEvent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {getMarkdown} from "../markdown/getMarkdown";
import {isSafari} from "../util/compatibility";
import {accessLocalStorage, isSafari} from "../util/compatibility";

export const afterRenderEvent = (vditor: IVditor, options = {
enableAddUndoStack: true,
Expand All @@ -24,7 +24,7 @@ export const afterRenderEvent = (vditor: IVditor, options = {
vditor.counter.render(vditor, text);
}

if (vditor.options.cache.enable) {
if (vditor.options.cache.enable && accessLocalStorage()) {
localStorage.setItem(vditor.options.cache.id, text);
if (vditor.options.cache.after) {
vditor.options.cache.after(text);
Expand Down

0 comments on commit 32ac24c

Please sign in to comment.