| 1 |
"use strict"; |
| 2 |
|
| 3 |
; |
| 4 |
(function ($, window, document, undefined) { |
| 5 |
jQuery(document).ready(function ($) { |
| 6 |
if (typeof wp.codeEditor !== 'undefined') { |
| 7 |
var settings = wp.codeEditor.defaultSettings ? _.clone(wp.codeEditor.defaultSettings) : {}; |
| 8 |
|
| 9 |
// To use a theme need to get required CSS from https://github.com/codemirror/codemirror5/tree/master/theme |
| 10 |
// settings.codemirror.theme = '3024-day'; |
| 11 |
|
| 12 |
// Initialize codeEditor for CSS fields |
| 13 |
$('.merchant-field-custom_css textarea').each(function () { |
| 14 |
var editor = wp.codeEditor.initialize(this, settings).codemirror; |
| 15 |
|
| 16 |
// Trigger event on any change |
| 17 |
editor.on('change', function () { |
| 18 |
$(editor.getTextArea()).trigger('change'); |
| 19 |
}); |
| 20 |
}); |
| 21 |
|
| 22 |
// Initialize codeEditor for JS fields |
| 23 |
$('.merchant-field-custom_js textarea').each(function () { |
| 24 |
var jsSettings = _.clone(settings); |
| 25 |
jsSettings.codemirror.mode = 'javascript'; |
| 26 |
var editor = wp.codeEditor.initialize(this, jsSettings).codemirror; |
| 27 |
|
| 28 |
// Trigger event on any change |
| 29 |
editor.on('change', function () { |
| 30 |
$(editor.getTextArea()).trigger('change'); |
| 31 |
}); |
| 32 |
}); |
| 33 |
} |
| 34 |
}); |
| 35 |
})(jQuery, window, document); |