added basic support for htmx (ajax)
- if there is HX-Request header present we sent only a part of the whole html - we return only specific stream defined by [out ...] ezc statement - the name of the stream is passed in the 'frame' parameter (if not present then 'content' is assumed) - added ezc function: winix_is_htmx_request
This commit is contained in:
@@ -1,2 +1,180 @@
|
||||
|
||||
[if winix_has_htmx]
|
||||
<div id="winix-oob" hx-swap-oob="true">
|
||||
[# content added by htmx library when using hx-swap-oob]
|
||||
|
||||
[if winix_is_htmx_request]
|
||||
|
||||
|
||||
[out "content"]
|
||||
<script>
|
||||
|
||||
function winix_css_download_by_index(css_files, index, callback)
|
||||
\{
|
||||
if( index < css_files.length )
|
||||
\{
|
||||
var link = document.createElement('link');
|
||||
link.classList.add("winix-auto-delete");
|
||||
link.rel = 'stylesheet';
|
||||
link.type = 'text/css';
|
||||
|
||||
link.onload = function() \{
|
||||
console.log("loading external css: " + css_files\[index\]);
|
||||
winix_css_download_by_index(css_files, index+1, callback);
|
||||
\}
|
||||
|
||||
link.href = css_files\[index\];
|
||||
document.head.appendChild(link);
|
||||
\}
|
||||
else
|
||||
\{
|
||||
console.log("all css files downloaded");
|
||||
callback();
|
||||
\}
|
||||
\}
|
||||
|
||||
function winix_css_download(css_files, callback)
|
||||
\{
|
||||
// add test if css_files is a table
|
||||
winix_css_download_by_index(css_files, 0, callback);
|
||||
\}
|
||||
|
||||
|
||||
function winix_js_download_by_index(js_files, index, callback)
|
||||
\{
|
||||
if( index < js_files.length )
|
||||
\{
|
||||
var script = document.createElement('script');
|
||||
script.classList.add("winix-auto-delete");
|
||||
|
||||
script.onload = function() \{
|
||||
console.log("loading external js: " + js_files\[index\]);
|
||||
winix_js_download_by_index(js_files, index+1, callback);
|
||||
\}
|
||||
|
||||
script.src = js_files\[index\];
|
||||
document.head.appendChild(script);
|
||||
\}
|
||||
else
|
||||
\{
|
||||
console.log("all js files downloaded");
|
||||
callback();
|
||||
\}
|
||||
\}
|
||||
|
||||
function winix_js_download(js_files, callback)
|
||||
\{
|
||||
// add test if js_files is a table
|
||||
winix_js_download_by_index(js_files, 0, callback);
|
||||
\}
|
||||
|
||||
</script>
|
||||
[end] [# out "content"]
|
||||
|
||||
|
||||
|
||||
[if winix_function_is "emacs"]
|
||||
[out "content"]
|
||||
|
||||
<style>
|
||||
.CodeMirror-matchingtag \{
|
||||
font-weight: bold;
|
||||
background: none;
|
||||
\}
|
||||
|
||||
.CodeMirror-activeline-background \{
|
||||
background: #f3f3f3;
|
||||
\}
|
||||
|
||||
.CodeMirror \{
|
||||
border: 1px solid #dedede;
|
||||
\}
|
||||
</style>
|
||||
|
||||
|
||||
<script>
|
||||
var winix_code_mirror_editor;
|
||||
|
||||
js_files = \[
|
||||
"[doc_base_url_common]/codemirror/5.59.2/lib/codemirror.js",
|
||||
"[doc_base_url_common]/codemirror/5.59.2/mode/css/css.js",
|
||||
"[doc_base_url_common]/codemirror/5.59.2/mode/javascript/javascript.js",
|
||||
"[doc_base_url_common]/codemirror/5.59.2/mode/xml/xml.js",
|
||||
"[doc_base_url_common]/codemirror/5.59.2/mode/htmlmixed/htmlmixed.js",
|
||||
"[doc_base_url_common]/codemirror/5.59.2/addon/display/fullscreen.js",
|
||||
"[doc_base_url_common]/codemirror/5.59.2/addon/fold/xml-fold.js",
|
||||
"[doc_base_url_common]/codemirror/5.59.2/addon/edit/matchtags.js",
|
||||
"[doc_base_url_common]/codemirror/5.59.2/addon/selection/active-line.js",
|
||||
\];
|
||||
|
||||
css_files = \[
|
||||
"[doc_base_url_common]/codemirror/5.59.2/lib/codemirror.css",
|
||||
"[doc_base_url_common]/codemirror/5.59.2/addon/display/fullscreen.css",
|
||||
\];
|
||||
|
||||
winix_js_download(js_files, winix_initialize_editor);
|
||||
winix_css_download(css_files, function()\{\});
|
||||
|
||||
|
||||
function winix_initialize_editor()
|
||||
\{
|
||||
var text_area = document.getElementById("winix_content_id");
|
||||
if( text_area )
|
||||
\{
|
||||
winix_code_mirror_editor = CodeMirror.fromTextArea(text_area, \{
|
||||
mode: "htmlmixed",
|
||||
theme: "default",
|
||||
indentUnit: 4,
|
||||
smartIndent: true,
|
||||
tabSize: 4,
|
||||
indentWithTabs: true,
|
||||
extraKeys: \{
|
||||
"F11": function(cm) \{ cm.setOption("fullScreen", !cm.getOption("fullScreen")); \},
|
||||
"Esc": function(cm) \{ if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); \}
|
||||
\},
|
||||
lineNumbers: true,
|
||||
lineWiseCopyCut: false,
|
||||
dragDrop: false,
|
||||
matchTags: true,
|
||||
styleActiveLine: true
|
||||
\});
|
||||
\}
|
||||
\}
|
||||
|
||||
</script>
|
||||
[end] [# out "content"]
|
||||
[end] [# if winix_function_is "emacs"]
|
||||
|
||||
|
||||
|
||||
[if winix_function_is "ckeditor"]
|
||||
[out "content"]
|
||||
|
||||
[# what about winix_has_jquery?]
|
||||
|
||||
<script>
|
||||
js_files = \[
|
||||
"[doc_base_url_common]/ckeditor_4.9.2/ckeditor.js",
|
||||
"[doc_base_url_common]/jquery/1.12.4/jquery.min.js",
|
||||
"[doc_base_url_common]/winix/update_button.js",
|
||||
\];
|
||||
|
||||
winix_js_download(js_files, winix_ckeditor_initialize);
|
||||
|
||||
</script>
|
||||
[end]
|
||||
|
||||
|
||||
[end] [# out "content"]
|
||||
[end] [# if winix_function_is "emacs"]
|
||||
|
||||
|
||||
[end] [# if winix_is_htmx_request]
|
||||
</div>
|
||||
[end] [# if winix_has_htmx]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user