summaryrefslogtreecommitdiff
path: root/public/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js')
-rw-r--r--public/js/extra.js13
-rw-r--r--public/js/index.js8
-rw-r--r--public/js/lib/common/constant.ejs2
-rw-r--r--public/js/lib/common/login.js4
-rw-r--r--public/js/lib/editor/index.js16
-rw-r--r--public/js/locale.js2
6 files changed, 22 insertions, 23 deletions
diff --git a/public/js/extra.js b/public/js/extra.js
index a6b01a91..0a95b1b1 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -178,16 +178,11 @@ function slugifyWithUTF8 (text) {
}
export function isValidURL (str) {
- const pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
- '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
- '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
- '(\\#[-a-z\\d_]*)?$', 'i') // fragment locator
- if (!pattern.test(str)) {
+ try {
+ const url = new URL(str)
+ return ['http:', 'https:'].includes(url.protocol)
+ } catch (e) {
return false
- } else {
- return true
}
}
diff --git a/public/js/index.js b/public/js/index.js
index ad20ffff..9946e6fd 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -944,7 +944,8 @@ ui.toolbar.download.rawhtml.click(function (e) {
// pdf
ui.toolbar.download.pdf.attr('download', '').attr('href', noteurl + '/pdf')
// export to dropbox
-ui.toolbar.export.dropbox.click(function () {
+ui.toolbar.export.dropbox.click(function (event) {
+ event.preventDefault()
var filename = renderFilename(ui.area.markdown) + '.md'
var options = {
files: [
@@ -996,7 +997,8 @@ ui.toolbar.export.snippet.click(function () {
})
})
// import from dropbox
-ui.toolbar.import.dropbox.click(function () {
+ui.toolbar.import.dropbox.click(function (event) {
+ event.preventDefault()
var options = {
success: function (files) {
ui.spinner.show()
@@ -1597,7 +1599,7 @@ function toggleNightMode () {
} else {
Cookies.set('nightMode', !isActive, {
expires: 365,
- sameSite: 'strict'
+ sameSite: window.cookiePolicy
})
}
}
diff --git a/public/js/lib/common/constant.ejs b/public/js/lib/common/constant.ejs
index 114a9077..2a32c333 100644
--- a/public/js/lib/common/constant.ejs
+++ b/public/js/lib/common/constant.ejs
@@ -8,3 +8,5 @@ window.allowedUploadMimeTypes = <%- JSON.stringify(allowedUploadMimeTypes) %>
window.linkifyHeaderStyle = '<%- linkifyHeaderStyle %>'
window.DROPBOX_APP_KEY = '<%- DROPBOX_APP_KEY %>'
+
+window.cookiePolicy = '<%- cookiePolicy %>'
diff --git a/public/js/lib/common/login.js b/public/js/lib/common/login.js
index 931c115f..3f7a3e4d 100644
--- a/public/js/lib/common/login.js
+++ b/public/js/lib/common/login.js
@@ -20,12 +20,12 @@ export function resetCheckAuth () {
export function setLoginState (bool, id) {
Cookies.set('loginstate', bool, {
expires: 365,
- sameSite: 'strict'
+ sameSite: window.cookiePolicy
})
if (id) {
Cookies.set('userid', id, {
expires: 365,
- sameSite: 'strict'
+ sameSite: window.cookiePolicy
})
} else {
Cookies.remove('userid')
diff --git a/public/js/lib/editor/index.js b/public/js/lib/editor/index.js
index 07ef58a1..d86ebf3c 100644
--- a/public/js/lib/editor/index.js
+++ b/public/js/lib/editor/index.js
@@ -304,13 +304,13 @@ export default class Editor {
if (this.editor.getOption('indentWithTabs')) {
Cookies.set('indent_type', 'tab', {
expires: 365,
- sameSite: 'strict'
+ sameSite: window.cookiePolicy
})
type.text('Tab Size:')
} else {
Cookies.set('indent_type', 'space', {
expires: 365,
- sameSite: 'strict'
+ sameSite: window.cookiePolicy
})
type.text('Spaces:')
}
@@ -322,12 +322,12 @@ export default class Editor {
if (this.editor.getOption('indentWithTabs')) {
Cookies.set('tab_size', unit, {
expires: 365,
- sameSite: 'strict'
+ sameSite: window.cookiePolicy
})
} else {
Cookies.set('space_units', unit, {
expires: 365,
- sameSite: 'strict'
+ sameSite: window.cookiePolicy
})
}
widthLabel.text(unit)
@@ -396,7 +396,7 @@ export default class Editor {
var keymap = this.editor.getOption('keyMap')
Cookies.set('keymap', keymap, {
expires: 365,
- sameSite: 'strict'
+ sameSite: window.cookiePolicy
})
label.text(keymap)
this.restoreOverrideEditorKeymap()
@@ -445,7 +445,7 @@ export default class Editor {
this.editor.setOption('theme', theme)
Cookies.set('theme', theme, {
expires: 365,
- sameSite: 'strict'
+ sameSite: window.cookiePolicy
})
checkTheme()
@@ -491,7 +491,7 @@ export default class Editor {
}
Cookies.set('spellcheck', mode === 'spell-checker', {
expires: 365,
- sameSite: 'strict'
+ sameSite: window.cookiePolicy
})
checkSpellcheck()
@@ -537,7 +537,7 @@ export default class Editor {
if (overrideBrowserKeymap.is(':checked')) {
Cookies.set('preferences-override-browser-keymap', true, {
expires: 365,
- sameSite: 'strict'
+ sameSite: window.cookiePolicy
})
this.restoreOverrideEditorKeymap()
} else {
diff --git a/public/js/locale.js b/public/js/locale.js
index aca35b98..8baa77fc 100644
--- a/public/js/locale.js
+++ b/public/js/locale.js
@@ -31,7 +31,7 @@ if (localeSelector.length > 0) {
localeSelector.change(function () {
Cookies.set('locale', $(this).val(), {
expires: 365,
- sameSite: 'strict'
+ sameSite: window.cookiePolicy
})
window.location.reload()
})