Head and Footer Scripts Inserter - Version 4.22

Version Description

  • Updated the method of loading the addons of the CodeMirror library.
  • Added the addon 'autorefresh.js' to the CodeMirror editor. The code for manual refreshing the CodeMirror editor is deleted.
Download this release

Release Info

Developer Arthur Gareginyan
Plugin Icon 128x128 Head and Footer Scripts Inserter
Version 4.22
Comparing to
See all releases

Code changes from version 4.21 to 4.22

header-and-footer-scripts-inserter.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Easily add your scripts to the WordPress website's head and footer sections. This is a must have tool for authors and website's owners.
6
  * Author: Space X-Chimp
7
  * Author URI: https://www.spacexchimp.com
8
- * Version: 4.21
9
  * License: GPL3
10
  * Text Domain: header-and-footer-scripts-inserter
11
  * Domain Path: /languages/
5
  * Description: Easily add your scripts to the WordPress website's head and footer sections. This is a must have tool for authors and website's owners.
6
  * Author: Space X-Chimp
7
  * Author URI: https://www.spacexchimp.com
8
+ * Version: 4.22
9
  * License: GPL3
10
  * Text Domain: header-and-footer-scripts-inserter
11
  * Domain Path: /languages/
inc/js/admin.js CHANGED
@@ -34,11 +34,9 @@ jQuery(document).ready(function($) {
34
  }
35
  });
36
 
37
- // Find all textareas on page
38
  $('textarea').each(function(index, elements) {
39
-
40
- // Change textarea to CodeMirror editor
41
- var editor = CodeMirror.fromTextArea( elements , {
42
  lineNumbers: true,
43
  firstLineNumber: 1,
44
  matchBrackets: true,
@@ -46,11 +44,6 @@ jQuery(document).ready(function($) {
46
  mode: 'text/html',
47
  styleActiveLine: true
48
  });
49
-
50
- // Refresh CodeMirror editor after 1 second
51
- setTimeout(function() {
52
- editor.refresh();
53
- },1);
54
  });
55
 
56
  });
34
  }
35
  });
36
 
37
+ // Find textareas on page and replace them with the CodeMirror editor
38
  $('textarea').each(function(index, elements) {
39
+ var editor = CodeMirror.fromTextArea( elements, {
 
 
40
  lineNumbers: true,
41
  firstLineNumber: 1,
42
  matchBrackets: true,
44
  mode: 'text/html',
45
  styleActiveLine: true
46
  });
 
 
 
 
 
47
  });
48
 
49
  });
inc/lib/codemirror/addon/display/autorefresh.js ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"))
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror"], mod)
9
+ else // Plain browser env
10
+ mod(CodeMirror)
11
+ })(function(CodeMirror) {
12
+ "use strict"
13
+
14
+ CodeMirror.defineOption("autoRefresh", false, function(cm, val) {
15
+ if (cm.state.autoRefresh) {
16
+ stopListening(cm, cm.state.autoRefresh)
17
+ cm.state.autoRefresh = null
18
+ }
19
+ if (val && cm.display.wrapper.offsetHeight == 0)
20
+ startListening(cm, cm.state.autoRefresh = {delay: val.delay || 250})
21
+ })
22
+
23
+ function startListening(cm, state) {
24
+ function check() {
25
+ if (cm.display.wrapper.offsetHeight) {
26
+ stopListening(cm, state)
27
+ if (cm.display.lastWrapHeight != cm.display.wrapper.clientHeight)
28
+ cm.refresh()
29
+ } else {
30
+ state.timeout = setTimeout(check, state.delay)
31
+ }
32
+ }
33
+ state.timeout = setTimeout(check, state.delay)
34
+ state.hurry = function() {
35
+ clearTimeout(state.timeout)
36
+ state.timeout = setTimeout(check, 50)
37
+ }
38
+ CodeMirror.on(window, "mouseup", state.hurry)
39
+ CodeMirror.on(window, "keyup", state.hurry)
40
+ }
41
+
42
+ function stopListening(_cm, state) {
43
+ clearTimeout(state.timeout)
44
+ CodeMirror.off(window, "mouseup", state.hurry)
45
+ CodeMirror.off(window, "keyup", state.hurry)
46
+ }
47
+ });
inc/php/enqueue.php CHANGED
@@ -38,9 +38,14 @@ function spacexchimp_p006_load_scripts_admin( $hook ) {
38
  foreach ( $modes as $mode ) {
39
  wp_enqueue_script( $prefix . '-codemirror-mode-' . $mode . '-js', $url . 'inc/lib/codemirror/mode/' . $mode . '/' . $mode . '.js', array(), $version, true );
40
  }
41
- $addons = array( 'active-line' );
42
- foreach ( $addons as $addon ) {
43
- wp_enqueue_script( $prefix . '-codemirror-addon-' . $addon . '-js', $url . 'inc/lib/codemirror/addon/selection/' . $addon . '.js', array(), $version, false );
 
 
 
 
 
44
  }
45
 
46
  // Style sheet
38
  foreach ( $modes as $mode ) {
39
  wp_enqueue_script( $prefix . '-codemirror-mode-' . $mode . '-js', $url . 'inc/lib/codemirror/mode/' . $mode . '/' . $mode . '.js', array(), $version, true );
40
  }
41
+ $addons = array(
42
+ 'display' => array( 'autorefresh' ),
43
+ 'selection' => array( 'active-line' )
44
+ );
45
+ foreach ( $addons as $addons_group_name => $addons_group ) {
46
+ foreach ( $addons_group as $addon ) {
47
+ wp_enqueue_script( $prefix . '-codemirror-addon-' . $addon . '-js', $url . 'inc/lib/codemirror/addon/' . $addons_group_name . '/' . $addon . '.js', array(), $version, false );
48
+ }
49
  }
50
 
51
  // Style sheet
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: inject, insert, insert scripts, insert javascript, insert js, insert html,
4
  Donate link: https://www.spacexchimp.com/donate.html
5
  Requires at least: 3.9
6
  Tested up to: 4.9
7
- Stable tag: 4.21
8
  License: GPL3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -170,7 +170,7 @@ A. Yes, any contributions are very welcome! Please visit [our donation page](htt
170
  **License**
171
 
172
  This plugin is licensed under the [GNU General Public License, version 3 (GPLv3)](http://www.gnu.org/licenses/gpl-3.0.html) and is distributed free of charge.
173
- Commercial licensing (e.g. for projects that can’t use an open-source license) is available upon request.
174
 
175
  **Credits**
176
 
@@ -187,6 +187,10 @@ Commercial licensing (e.g. for projects that can’t use an open-source license)
187
 
188
  == Changelog ==
189
 
 
 
 
 
190
  = 4.21 =
191
  * CodeMirror library updated to the latest version v5.38.0. The directory structure is changed (files are better organized). Added a test files for the CodeMirror modes.
192
  * Updated the method of loading the modes and addons of the CodeMirror library.
4
  Donate link: https://www.spacexchimp.com/donate.html
5
  Requires at least: 3.9
6
  Tested up to: 4.9
7
+ Stable tag: 4.22
8
  License: GPL3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
170
  **License**
171
 
172
  This plugin is licensed under the [GNU General Public License, version 3 (GPLv3)](http://www.gnu.org/licenses/gpl-3.0.html) and is distributed free of charge.
173
+ Commercial licensing (e.g. for projects that can’t use an open-source licence) is available upon request.
174
 
175
  **Credits**
176
 
187
 
188
  == Changelog ==
189
 
190
+ = 4.22 =
191
+ * Updated the method of loading the addons of the CodeMirror library.
192
+ * Added the addon 'autorefresh.js' to the CodeMirror editor. The code for manual refreshing the CodeMirror editor is deleted.
193
+
194
  = 4.21 =
195
  * CodeMirror library updated to the latest version v5.38.0. The directory structure is changed (files are better organized). Added a test files for the CodeMirror modes.
196
  * Updated the method of loading the modes and addons of the CodeMirror library.