Skip to content

Commit 9ed9c8a

Browse files
committed
reload_scripts without jquery.
1 parent 9751a23 commit 9ed9c8a

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ Install the package from source with pip:
6161

6262
```bash
6363
cd mkdocs-encryptcontent-plugin/
64-
python3 setup.py sdist bdist_wheel
65-
pip3 install dist/mkdocs_encryptcontent_plugin-2.3.1-py3-none-any.whl
64+
python setup.py sdist bdist_wheel
65+
pip install dist/mkdocs_encryptcontent_plugin-2.4.0-py3-none-any.whl
6666
```
6767

6868
Enable the plugin in your `mkdocs.yml`:
@@ -204,7 +204,8 @@ Related to [issue #7](https://github.com/CoinK0in/mkdocs-encryptcontent-plugin/i
204204

205205
This feature add an additional attribute `encrypted` with value `True` to the mkdocs type `mkdocs.nav.page` object.
206206

207-
You can add `tag_encrypted_page: False` in plugin configuration, to disable tagging of encrypted pages. **BUT** This feature is neccessary for others feature working correctly. If you disable this feature, do no use [Encrypt Somethings](https://github.com/CoinK0in/mkdocs-encryptcontent-plugin#encrypt-something),
207+
You can add `tag_encrypted_page: False` in plugin configuration, to disable tagging of encrypted pages. **BUT** This feature is neccessary for others feature working correctly.
208+
If you disable this feature, f.ex. [Encrypt something](#encrypt-something) and [Search index encryption](#search-index-encryption) won't work.
208209

209210
When enable, it becomes possible to use `encrypted` attribute in the jinja template of your theme, as a condition to perform custom modification.
210211

@@ -423,7 +424,7 @@ In order to be able to decrypt the search index (`dynamically`) `mkdocs-material
423424

424425
You'll need some [prerequisites](https://squidfunk.github.io/mkdocs-material/customization/#environment-setup) and also execute these commands:
425426

426-
```
427+
```bash
427428
git clone https://github.com/squidfunk/mkdocs-material
428429
cd mkdocs-material
429430
pip install mkdocs-minify-plugin
@@ -501,14 +502,7 @@ plugins:
501502
- "./js/example.js"
502503
```
503504

504-
This feature use the following JQuery function to remove, add and reload javascripts.
505-
506-
```javascript
507-
var reload_js = function(src) {
508-
$('script[src="' + src + '"]').remove();
509-
$('<script>').attr('src', src).appendTo('head');
510-
};
511-
```
505+
This feature now doesn't use JQuery anymore (related to [issue #30](https://github.com/unverbuggt/mkdocs-encryptcontent-plugin/issues/30)).
512506

513507
### Self-host crypto-js
514508

encryptcontent/decrypt-contents.tpl.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,22 @@ function getItemExpiry(key) {
129129

130130
/* Reload scripts src after decryption process */
131131
function reload_js(src) {
132-
$('script[src="' + src + '"]').remove();
133-
$('<script>').attr('src', src).appendTo('head');
132+
let script_src, script_tag, new_script_tag;
133+
let head = document.getElementsByTagName('head')[0];
134+
135+
if (base_url == '.') {
136+
script_src = src;
137+
} else {
138+
script_src = base_url + '/' + src;
139+
}
140+
141+
script_tag = document.querySelector('script[src="' + script_src + '"]');
142+
if (script_tag) {
143+
script_tag.remove();
144+
new_script_tag = document.createElement('script');
145+
new_script_tag.src = script_src;
146+
head.appendChild(new_script_tag);
147+
}
134148
};
135149

136150
{% if experimental -%}

0 commit comments

Comments
 (0)