Enabled custom HTML head content to work within editors

Closes #562
This commit is contained in:
Dan Brown 2017-12-08 11:52:43 +00:00
parent 56d5af1336
commit d7edc389a6
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
6 changed files with 35 additions and 5 deletions

View File

@ -54,6 +54,7 @@ class HomeController extends Controller
/**
* Get a js representation of the current translations
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
* @throws \Exception
*/
public function getTranslations() {
$locale = app()->getLocale();
@ -86,4 +87,13 @@ class HomeController extends Controller
]);
}
/**
* Get custom head HTML, Used in ajax calls to show in editor.
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function customHeadContent()
{
return view('partials/custom-head-content');
}
}

View File

@ -97,6 +97,17 @@ function registerEditorShortcuts(editor) {
}
/**
* Load custom HTML head content from the settings into the editor.
* @param editor
*/
function loadCustomHeadContent(editor) {
window.$http.get(window.baseUrl('/custom-head-content')).then(resp => {
if (!resp.data) return;
let head = editor.getDoc().querySelector('head');
head.innerHTML += resp.data;
});
}
/**
* Create and enable our custom code plugin
@ -322,6 +333,9 @@ module.exports = {
args.content = '';
}
},
init_instance_callback: function(editor) {
loadCustomHeadContent(editor);
},
setup: function (editor) {
editor.on('init ExecCommand change input NodeChange ObjectResized', editorChange);

View File

@ -63,9 +63,10 @@
padding: 0 $-m 0;
margin-left: -1px;
overflow-y: scroll;
.page-content {
margin: 0 auto;
}
}
.markdown-display.page-content {
margin: 0 auto;
max-width: 100%;
}
}
.editor-toolbar {

View File

@ -97,8 +97,7 @@
<div class="editor-toolbar">
<div class="">{{ trans('entities.pages_md_preview') }}</div>
</div>
<div class="markdown-display">
<div class="page-content"></div>
<div class="markdown-display page-content">
</div>
</div>
<input type="hidden" name="html"/>

View File

@ -0,0 +1,5 @@
@if(setting('app-custom-head', false))
<!-- Custom user content -->
{!! setting('app-custom-head') !!}
<!-- End custom user content -->
@endif

View File

@ -135,6 +135,7 @@ Route::group(['middleware' => 'auth'], function () {
// Other Pages
Route::get('/', 'HomeController@index');
Route::get('/home', 'HomeController@index');
Route::get('/custom-head-content', 'HomeController@customHeadContent');
// Settings
Route::group(['prefix' => 'settings'], function() {