]> BookStack Code Mirror - bookstack/commitdiff
Enabled custom HTML head content to work within editors
authorDan Brown <redacted>
Fri, 8 Dec 2017 11:52:43 +0000 (11:52 +0000)
committerDan Brown <redacted>
Fri, 8 Dec 2017 11:52:43 +0000 (11:52 +0000)
Closes #562

app/Http/Controllers/HomeController.php
resources/assets/js/pages/page-form.js
resources/assets/sass/_forms.scss
resources/views/pages/form.blade.php
resources/views/partials/custom-head-content.blade.php [new file with mode: 0644]
routes/web.php

index 7d109b70a9bb9225e2d8edfccc678e191765acbf..164becd4dc9a04ebf68af822899251b6b0f1f4c8 100644 (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');
+    }
+
 }
index 73a6c976d8af4f5ed58f681fb87c5a2aa8cb1fc6..904403fc1a5afbb2d9ceb2a0924d0eff5589aca4 100644 (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);
index 700c15336ff1d49677d8f20ebc9e8a4ccc17b01a..802a075a252540ef3f56dbcfa0f180627a1da460 100644 (file)
     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 {
index 12f2f3e97c1680732ec9fefd06d99715a9024c28..f450452cec8bce187f238ce89669efc48f0161af 100644 (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"/>
diff --git a/resources/views/partials/custom-head-content.blade.php b/resources/views/partials/custom-head-content.blade.php
new file mode 100644 (file)
index 0000000..b245b7a
--- /dev/null
@@ -0,0 +1,5 @@
+@if(setting('app-custom-head', false))
+    <!-- Custom user content -->
+    {!! setting('app-custom-head') !!}
+    <!-- End custom user content -->
+@endif
\ No newline at end of file
index 8bff3b2ec0c2db0dee51e789b9e7b2cc70b206fa..f5e59f1095a3adeb1289e945ad3da826dff65640 100644 (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() {