diff --git a/winixd/core/app.cpp b/winixd/core/app.cpp index 45146ce..ef30631 100644 --- a/winixd/core/app.cpp +++ b/winixd/core/app.cpp @@ -724,6 +724,25 @@ void App::SaveSessionsIfNeeded() +const std::wstring * App::CreateFrameAnswer() +{ + Request & req = *cur.request; + auto i = req.out_streams.streams_map.begin(); + const std::wstring * frame = cur.request->ParamValuep(L"frame"); + + for( ; i != req.out_streams.streams_map.end() ; ++i) + { + if( (frame && i->first == *frame) || (!frame && i->first == L"content") ) + { + return &i->second->Str(); + break; + } + } + + return nullptr; +} + + void App::CreateJSONAnswer() { Request & req = *cur.request; @@ -1764,11 +1783,12 @@ return header; void App::SendTextAnswer() { -const std::wstring * source; +const std::wstring * source = nullptr; bool compressing = false; int compress_encoding = 0; size_t output_size = 0; + Header header = GetHTTPStatusCode(); if( CanSendContent() ) @@ -1781,6 +1801,17 @@ size_t output_size = 0; source = &json_out_stream.Str(); // json_out_stream was prepared by CreateJSONAnswer() } else + if( cur.request->headers_in.has_key(L"HX-Request") || cur.request->headers_in.has_key(L"hx_request") ) // fastcgi will change the header to hx_request + { + source = CreateFrameAnswer(); + + if( !source ) + { + empty_response.clear(); + source = &empty_response; + } + } + else { source = &cur.request->out_main_stream.Str(); } diff --git a/winixd/core/app.h b/winixd/core/app.h index 6d1172a..3bef5c8 100644 --- a/winixd/core/app.h +++ b/winixd/core/app.h @@ -164,6 +164,7 @@ private: std::wstring http_header_name; std::wstring http_header_value; std::string http_header_8bit; + std::wstring empty_response; morm::ModelConnector model_connector; // main thread model connector, each thread has its own connector morm::JSONConnector json_connector; @@ -206,6 +207,7 @@ private: void SaveSessionsIfNeeded(); // !! IMPROVE ME wywalic do menagera sesji?? void LogAccess(); void SendData(const BinaryPage & page, FCGX_Stream * out); + const std::wstring * CreateFrameAnswer(); void CreateJSONAnswer(); void ReadRequest(); diff --git a/winixd/html/ckeditor.html b/winixd/html/ckeditor.html index da0c890..b4a2ea4 100644 --- a/winixd/html/ckeditor.html +++ b/winixd/html/ckeditor.html @@ -3,13 +3,17 @@ [# blocks are not connected with languages yet, so don't use \{ but {] - - -if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) -{ - CKEDITOR.tools.enableHtml5Elements( document ); +function winix_ckeditor_old_browser_support() { + if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) + { + CKEDITOR.tools.enableHtml5Elements( document ); + } } +[if not winix_is_htmx_request] + winix_ckeditor_old_browser_support(); +[end] + [end] @@ -22,6 +26,7 @@ if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) [block ckeditor] diff --git a/winixd/html/index_bottom_adder.html b/winixd/html/index_bottom_adder.html index 139597f..72a6e76 100644 --- a/winixd/html/index_bottom_adder.html +++ b/winixd/html/index_bottom_adder.html @@ -1,2 +1,180 @@ +[if winix_has_htmx] +
+ [# content added by htmx library when using hx-swap-oob] + + [if winix_is_htmx_request] + + + [out "content"] + + [end] [# out "content"] + + + + [if winix_function_is "emacs"] + [out "content"] + + + + + + [end] [# out "content"] + [end] [# if winix_function_is "emacs"] + + + + [if winix_function_is "ckeditor"] + [out "content"] + + [# what about winix_has_jquery?] + + + [end] + + + [end] [# out "content"] + [end] [# if winix_function_is "emacs"] + + + [end] [# if winix_is_htmx_request] +
+[end] [# if winix_has_htmx] + + + + + diff --git a/winixd/html/index_head_adder.html b/winixd/html/index_head_adder.html index a316488..83bf60e 100644 --- a/winixd/html/index_head_adder.html +++ b/winixd/html/index_head_adder.html @@ -37,10 +37,27 @@ [if winix_load_htmx] [def winix_has_htmx true] + [end] +[if winix_has_htmx] + +[end] [if winix_function_is "emacs"] diff --git a/winixd/templates/templates.cpp b/winixd/templates/templates.cpp index 1a74c55..87c1130 100644 --- a/winixd/templates/templates.cpp +++ b/winixd/templates/templates.cpp @@ -766,6 +766,7 @@ void Templates::CreateFunctions() ezc_functions.Insert("winix_locale_tab", winix_locale_tab); ezc_functions.Insert("winix_locale_tab_id", winix_locale_tab_id); ezc_functions.Insert("winix_locale_tab_name", winix_locale_tab_name); + ezc_functions.Insert("winix_is_htmx_request", winix_is_htmx_request); /* diff --git a/winixd/templates/templates.h b/winixd/templates/templates.h index 0491235..27744c8 100644 --- a/winixd/templates/templates.h +++ b/winixd/templates/templates.h @@ -661,7 +661,7 @@ namespace TemplatesFunctions void winix_locale_tab(Info & i); void winix_locale_tab_id(Info & i); void winix_locale_tab_name(Info & i); - + void winix_is_htmx_request(Info & i); /* who diff --git a/winixd/templates/winix.cpp b/winixd/templates/winix.cpp index 7116215..7654291 100644 --- a/winixd/templates/winix.cpp +++ b/winixd/templates/winix.cpp @@ -375,6 +375,15 @@ void winix_locale_tab_name(Info & i) } +void winix_is_htmx_request(Info & i) +{ + if( cur->request->headers_in.has_key(L"HX-Request") || cur->request->headers_in.has_key(L"hx_request") ) + { + // fastcgi will change the header to hx_request + i.res = true; + } +} +