From 2f5cd342ce12d43c37cbf5d46f694e0b3dfcdff9 Mon Sep 17 00:00:00 2001
From: weru <fromweru@gmail.com>
Date: Sun, 06 Dec 2020 16:32:50 +0000
Subject: [PATCH] refactor file
---
assets/js/functions.js | 26 ++++++++++----------------
1 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/assets/js/functions.js b/assets/js/functions.js
index c0208f3..d1958b3 100644
--- a/assets/js/functions.js
+++ b/assets/js/functions.js
@@ -1,9 +1,3 @@
-const parentURL = '{{ absURL "" }}';
-const doc = document.documentElement;
-const toggleId = 'toggle';
-const showId = 'show';
-const menu = 'menu';
-
function isObj(obj) {
return (obj && typeof obj === 'object' && obj !== null) ? true : false;
}
@@ -23,7 +17,7 @@
}
function elems(selector, parent = document) {
- let elems = isObj(parent) ?parent.querySelectorAll(selector) : [];
+ let elems = isObj(parent) ? parent.querySelectorAll(selector) : [];
return elems.length ? elems : false;
}
@@ -120,18 +114,18 @@
let close = `</${wrapper}>`;
function wrap(context) {
let c = context.innerHTML;
- let index = c.indexOf(text);
- if (index >= 0) {
- let stop = index + text.length;
- let s = c.substring(index,stop);
- let before = c.substring(0,index);
- let after = c.substring(stop);
- c = `${before}${open}${s}${close}${after}`;
- context.innerHTML = c;
+ let pattern = new RegExp(text, "gi");
+ let matches = text.length ? c.match(pattern) : null;
+
+ if(matches) {
+ matches.forEach(function(matchStr){
+ c = c.replaceAll(matchStr, `${open}${matchStr}${close}`);
+ context.innerHTML = c;
+ });
}
}
- const contents = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "code", "td", "pre"];
+ const contents = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "code", "td"];
contents.forEach(function(c){
const cs = elems(c, context);
--
Gitblit v1.10.0