aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2017-09-15 01:55:42 +0200
committerThomas Lange <code@nerdmind.de>2017-09-15 01:55:42 +0200
commit2c430be8d1cc3e65fdef443f0ab70861103db3eb (patch)
tree9e798501db0cb986b1a3ee9139e5fad2576e0c9b
parentbd5f13aa6c79cb67cf0537db01ab85a7d3141759 (diff)
downloadblog-2c430be8d1cc3e65fdef443f0ab70861103db3eb.tar.gz
blog-2c430be8d1cc3e65fdef443f0ab70861103db3eb.tar.xz
blog-2c430be8d1cc3e65fdef443f0ab70861103db3eb.zip
All occurrences of "var" have been replaced by the new introduced keywords "const" and "let" from ECMAScript 6 (2015), which scopes the variables to the nearest enclosing block instead of the nearest function block.
-rw-r--r--template/admin/rsrc/main.js46
-rw-r--r--template/standard/rsrc/main.js4
2 files changed, 25 insertions, 25 deletions
diff --git a/template/admin/rsrc/main.js b/template/admin/rsrc/main.js
index feb6365..1870ced 100644
--- a/template/admin/rsrc/main.js
+++ b/template/admin/rsrc/main.js
@@ -1,8 +1,8 @@
//==============================================================================
// Elements which contains the location of the previous and next site
//==============================================================================
-var prev = document.getElementById("prev-site");
-var next = document.getElementById("next-site");
+const prev = document.getElementById("prev-site");
+const next = document.getElementById("next-site");
//==============================================================================
// Handle arrow keys and change the location to the desired direction
@@ -17,7 +17,7 @@ document.addEventListener("keyup", function(e) {
//==============================================================================
// Markdown tags to replace
//==============================================================================
-var markdownTags = {
+const markdownTags = {
"bold": ["**", "**"],
"italic": ["*", "*"],
"heading": ["## ", "\n"],
@@ -48,10 +48,10 @@ function setCaretPosition(position) {
// Insert emoticon after cursor in editor
//==============================================================================
function insertEmoticon(target, emoticon) {
- var selectionStart = target.selectionStart;
- var selectionEnd = target.selectionEnd;
+ const selectionStart = target.selectionStart;
+ const selectionEnd = target.selectionEnd;
- var content = target.value;
+ const content = target.value;
target.value = content.slice(0, selectionStart) + emoticon + content.slice(selectionEnd);
delayed(function() {
@@ -63,12 +63,12 @@ function insertEmoticon(target, emoticon) {
// Insert markdown around text in editor
//==============================================================================
function insertMarkdown(target, markdown) {
- var selectionStart = target.selectionStart;
- var selectionEnd = target.selectionEnd;
+ const selectionStart = target.selectionStart;
+ const selectionEnd = target.selectionEnd;
- var selectedText = target.value.substring(selectionStart, selectionEnd);
+ const selectedText = target.value.substring(selectionStart, selectionEnd);
- var content = target.value;
+ const content = target.value;
target.value = content.slice(0, selectionStart) + markdownTags[markdown][0] + selectedText + markdownTags[markdown][1] + content.slice(selectionEnd);
delayed(function() {
@@ -80,7 +80,7 @@ function insertMarkdown(target, markdown) {
// Keep server-side session active if the user is writing a long text
//==============================================================================
setInterval(function() {
- var Request = new XMLHttpRequest();
+ const Request = new XMLHttpRequest();
Request.open("HEAD", "", true);
Request.send();
}, 300000);
@@ -99,13 +99,13 @@ if(document.getElementById("delete-button")) {
//==============================================================================
(function() {
if(document.getElementById("content-editor")) {
- var element = document.getElementById("content-editor");
+ const element = document.getElementById("content-editor");
element.addEventListener("keydown", function(e) {
if(e.keyCode === 9 && !e.ctrlKey) {
- var selectionStart = element.selectionStart;
- var selectionEnd = element.selectionEnd;
+ const selectionStart = element.selectionStart;
+ const selectionEnd = element.selectionEnd;
- var content = element.value;
+ const content = element.value;
if(e.shiftKey) {
if(content.substring(selectionStart, selectionStart -1) === "\t") {
@@ -130,11 +130,11 @@ if(document.getElementById("delete-button")) {
//==============================================================================
(function() {
if(document.getElementById("emoticon-list")) {
- var list = document.getElementById("emoticon-list");
- var node = document.getElementById("content-editor");
- var items = list.getElementsByTagName("li");
+ const list = document.getElementById("emoticon-list");
+ const node = document.getElementById("content-editor");
+ const items = list.getElementsByTagName("li");
- for(var i = 0; i < items.length; ++i) {
+ for(let i = 0; i < items.length; ++i) {
items[i].onmousedown = function(e) {
insertEmoticon(node, e.target.getAttribute("data-emoticon"));
};
@@ -147,11 +147,11 @@ if(document.getElementById("delete-button")) {
//==============================================================================
(function() {
if(document.getElementById("markdown-list")) {
- var list = document.getElementById("markdown-list");
- var node = document.getElementById("content-editor");
- var items = list.getElementsByTagName("li");
+ const list = document.getElementById("markdown-list");
+ const node = document.getElementById("content-editor");
+ const items = list.getElementsByTagName("li");
- for(var i = 0; i < items.length; ++i) {
+ for(let i = 0; i < items.length; ++i) {
items[i].onmousedown = function(e) {
insertMarkdown(node, e.target.getAttribute("data-markdown"));
};
diff --git a/template/standard/rsrc/main.js b/template/standard/rsrc/main.js
index b5d1530..a7a424c 100644
--- a/template/standard/rsrc/main.js
+++ b/template/standard/rsrc/main.js
@@ -1,8 +1,8 @@
//==============================================================================
// Elements which contains the location of the previous and next site
//==============================================================================
-var prev = document.getElementById("prev-site");
-var next = document.getElementById("next-site");
+const prev = document.getElementById("prev-site");
+const next = document.getElementById("next-site");
//==============================================================================
// Handle arrow keys and change the location to the desired direction