Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
- ---> Default code from /theme/content.css The code can be found at lines 856-869 in the text editor.
- .postbody .content::-webkit-scrollbar,
- .topicreview::-webkit-scrollbar,
- .post_details::-webkit-scrollbar,
- .codebox code::-webkit-scrollbar,
- .attachbox dd::-webkit-scrollbar,
- .attach-image::-webkit-scrollbar,
- .dropdown-extended ul::-webkit-scrollbar {
- width: 8px;
- height: 8px;
- -webkit-appearance: none;
- background: rgba(0, 0, 0, .1);
- border-radius: 3px;
- }
- .postbody .content::-webkit-scrollbar-thumb,
- .topicreview::-webkit-scrollbar-thumb,
- .post_details::-webkit-scrollbar-thumb,
- .codebox code::-webkit-scrollbar-thumb,
- .attachbox dd::-webkit-scrollbar-thumb,
- .attach-image::-webkit-scrollbar-thumb,
- .dropdown-extended ul::-webkit-scrollbar-thumb {
- background: rgba(0, 0, 0, .3);
- border-radius: 3px;
- }
- -----------------------------------------------------------------------
- // Removed from default code these two.
- .codebox code::-webkit-scrollbar
- .codebox code::-webkit-scrollbar-thumb
- // we put these in /theme/content.css
- .postbody .content::-webkit-scrollbar,
- .topicreview::-webkit-scrollbar,
- .post_details::-webkit-scrollbar,
- .attachbox dd::-webkit-scrollbar,
- .attach-image::-webkit-scrollbar,
- .dropdown-extended ul::-webkit-scrollbar {
- width: 8px;
- height: 8px;
- -webkit-appearance: none;
- background: rgba(0, 0, 0, .1);
- border-radius: 3px;
- }
- .postbody .content::-webkit-scrollbar-thumb,
- .topicreview::-webkit-scrollbar-thumb,
- .post_details::-webkit-scrollbar-thumb,
- .attachbox dd::-webkit-scrollbar-thumb,
- .attach-image::-webkit-scrollbar-thumb,
- .dropdown-extended ul::-webkit-scrollbar-thumb {
- background: rgba(0, 0, 0, .3);
- border-radius: 3px;
- }
- -----------------------------------------------------------------------
- ---> Watch the video to see what I modify/remove from /theme/content.css and /theme/colours.css
- ---> default code from /theme/content.css // The code can be found at lines 512-542 in the text editor.
- /* Code block */
- .codebox {
- border: 1px solid transparent;
- font-size: 1em;
- margin: 1em 0 1.2em 0;
- word-wrap: normal;
- }
- .codebox p {
- text-transform: uppercase;
- border-bottom: 1px solid transparent;
- margin-bottom: 0;
- padding: 3px;
- font-size: 0.8em !important;
- font-weight: bold;
- display: block;
- }
- blockquote .codebox {
- margin-left: 0;
- }
- .codebox code {
- overflow: auto;
- display: block;
- height: auto;
- max-height: 200px;
- padding: 5px 3px;
- font: 0.9em Monaco, "Andale Mono","Courier New", Courier, monospace;
- line-height: 1.3em;
- }
- ---> default code from /theme/colours.css // The code can be found at lines 426-438 in the text editor.
- /* Code block */
- .codebox {
- background-color: #FFFFFF;
- border-color: #C9D2D8;
- }
- .codebox p {
- border-bottom-color: #CCCCCC;
- }
- .codebox code {
- color: #2E8B57;
- }
- ---> In the code below, I extracted the styles from the /theme/content.css and /theme/colours.css files and added them to custom.css to avoid overlapping with the default styles. I made a few minor modifications to the CSS, and for this video, I preferred to centralize them in custom.css
- /* Code block styling */
- .codebox {
- background-color: #23241f;
- border: 1px solid #C9D2D8;
- overflow: hidden; /* Hides the default scrollbar */
- position: relative;
- margin: 1em 0 1.2em 0;
- font-size: 1em;
- }
- blockquote .codebox {
- margin-left: 0;
- }
- .codebox-header {
- background-color: #f5f5f5;
- padding: 8px;
- /* font-family: Arial, sans-serif; */
- font-size: 0.8em;
- text-transform: uppercase;
- }
- .codebox-header p {
- margin: 0;
- }
- .codebox-header a {
- color: #007bff;
- text-decoration: none;
- }
- .codebox-header p a:first-of-type {
- margin-left: 5px; /* Adjust this value as needed */
- }
- .codebox-header a:hover {
- text-decoration: underline;
- }
- .codebox code {
- display: block;
- max-height: 200px; /* Limits height for scrolling */
- overflow-y: auto; /* Enables vertical scrolling */
- box-sizing: border-box;
- font: 0.9em Monaco, "Andale Mono", "Courier New", Courier, monospace;
- line-height: 1.3em;
- position: relative; /* Ensures it is positioned relative for overflow control */
- }
- /* Allows full expansion for the custom scrollbar */
- .codebox.expanded code {
- max-height: none; /* Removes height limitation */
- overflow-y: auto; /* Enables custom vertical scrolling */
- }
- /* Masks the white corner at the intersection of scrollbars */
- .codebox::after {
- content: "";
- position: absolute;
- bottom: 0;
- right: 0;
- width: 8px; /* Matches the width of the scrollbar */
- height: 8px; /* Matches the height of the scrollbar */
- background-color: #23241f; /* Matches the background of .codebox */
- }
- /* These two rules are from the default content.css */
- /* Custom scrollbar */
- .codebox code::-webkit-scrollbar {
- width: 8px; /* Scrollbar width */
- height: 8px;
- -webkit-appearance: none;
- background: transparent; /* Transparent background */
- }
- .codebox code::-webkit-scrollbar-thumb {
- background: rgba(0, 0, 0, .3);
- border-radius: 3px;
- }
- -----------------------------------------------------------------------
- ---> Code from /template/forum_fn.js // The code can be found at lines 146-198 in the text editor.
- ---> This is the default java code for selecting the code:
- function selectCode(a) {
- 'use strict';
- // Get ID of code block
- var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
- var s, r;
- // Not IE and IE9+
- if (window.getSelection) {
- s = window.getSelection();
- // Safari and Chrome
- if (s.setBaseAndExtent) {
- var l = (e.innerText.length > 1) ? e.innerText.length - 1 : 1;
- try {
- s.setBaseAndExtent(e, 0, e, l);
- } catch (error) {
- r = document.createRange();
- r.selectNodeContents(e);
- s.removeAllRanges();
- s.addRange(r);
- }
- }
- // Firefox and Opera
- else {
- // workaround for bug # 42885
- if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) === '<BR>') {
- e.innerHTML = e.innerHTML + ' ';
- }
- r = document.createRange();
- r.selectNodeContents(e);
- s.removeAllRanges();
- s.addRange(r);
- }
- }
- // Some older browsers
- else if (document.getSelection) {
- s = document.getSelection();
- r = document.createRange();
- r.selectNodeContents(e);
- s.removeAllRanges();
- s.addRange(r);
- }
- // IE
- else if (document.selection) {
- r = document.body.createTextRange();
- r.moveToElementText(e);
- r.select();
- }
- }
- ---> replace the default code with the one below, because I added expand/collapse and the default code no longer worked to select the code.
- -----------------------------------------------------------------------
- ---> Use this code instead of the default one above.
- function selectCode(a, event) {
- 'use strict';
- // Prevent the default behavior of the link
- event.preventDefault();
- // Get the CODE element within the respective block
- var e = a.parentNode.parentNode.parentNode.querySelector('code');
- var s, r;
- // Non-IE and IE9+
- if (window.getSelection) {
- s = window.getSelection();
- // Safari and Chrome
- if (s.setBaseAndExtent) {
- var l = (e.innerText.length > 1) ? e.innerText.length - 1 : 1;
- try {
- s.setBaseAndExtent(e, 0, e, l);
- } catch (error) {
- r = document.createRange();
- r.selectNodeContents(e);
- s.removeAllRanges();
- s.addRange(r);
- }
- }
- // Firefox and Opera
- else {
- // Workaround for bug #42885
- if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) === '<BR>') {
- e.innerHTML = e.innerHTML + ' ';
- }
- r = document.createRange();
- r.selectNodeContents(e);
- s.removeAllRanges();
- s.addRange(r);
- }
- }
- // Some older browsers
- else if (document.getSelection) {
- s = document.getSelection();
- r = document.createRange();
- r.selectNodeContents(e);
- s.removeAllRanges();
- s.addRange(r);
- }
- // IE
- else if (document.selection) {
- r = document.body.createTextRange();
- r.moveToElementText(e);
- r.select();
- }
- }
- -----------------------------------------------------------------------
- This small JavaScript code, responsible for expand/collapse functionality, should be placed in
- /template/overall_footer.html. However, it can also be placed directly in /template/forum_fn.js
- below the code responsible for selecting content, by removing the <script></script> tags and keeping only the function.
- <script>
- function expandAll(element) {
- const codebox = element.closest('.codebox');
- const codeBlock = codebox.querySelector('code');
- if (codeBlock) {
- codebox.classList.add('expanded'); // Add the expanded class to the codebox
- codeBlock.style.overflowY = 'auto'; // Ensure vertical scrolling is enabled
- }
- }
- function collapseAll(element) {
- const codebox = element.closest('.codebox');
- const codeBlock = codebox.querySelector('code');
- if (codeBlock) {
- codebox.classList.remove('expanded'); // Remove expanded class
- codeBlock.style.overflowY = 'auto'; // Enable vertical scrolling
- }
- }
- </script>
- -----------------------------------------------------------------------
- The code below has had the `<script></script>` tags removed, keeping only the functions. It can now be placed directly in `/template/forum_fn.js` instead of being placed in the HTML. The code can be placed below the code responsible for selecting the content.
- function expandAll(element) {
- const codebox = element.closest('.codebox');
- const codeBlock = codebox.querySelector('code');
- if (codeBlock) {
- codebox.classList.add('expanded'); // Add the "expanded" class to the codebox
- codeBlock.style.overflowY = 'auto'; // Ensure vertical scrolling is enabled
- }
- }
- function collapseAll(element) {
- const codebox = element.closest('.codebox');
- const codeBlock = codebox.querySelector('code');
- if (codeBlock) {
- codebox.classList.remove('expanded'); // Remove the "expanded" class
- codeBlock.style.overflowY = 'auto'; // Ensure vertical scrolling is enabled
- }
- }
- -----------------------------------------------------------------------
- ---> Code from /template/bbcode.html // The code can be found at lines 57-58 in the text editor.
- // Default code:
- <!-- BEGIN code_open --><div class="codebox"><p>{L_CODE}{L_COLON} <a href="#" onclick="selectCode(this); return false;">{L_SELECT_ALL_CODE}</a></p><pre><code><!-- END code_open -->
- <!-- BEGIN code_close --></code></pre></div><!-- END code_close -->
- // Custom code:
- <!-- BEGIN code_open -->
- <div class="codebox">
- <div class="codebox-header">
- <p>{L_CODE}{L_COLON}
- <a href="#" onclick="selectCode(this, event); return false;">{L_SELECT_ALL_CODE}</a> |
- <a href="#" onclick="expandAll(this); return false;">Expand All</a> |
- <a href="#" onclick="collapseAll(this); return false;">Collapse All</a>
- </p>
- </div>
- <pre><code>
- <!-- END code_open -->
- <!-- BEGIN code_close -->
- </code></pre>
- </div>
- <!-- END code_close -->
- -----------------------------------------------------------------------
- To import Highlight.js, you can choose between two methods:
- 1. Using a CDN
- Import the required resources directly from a CDN.
- 2. Downloading Resources
- Download the Highlight.js files from the CDN and include them locally in your project.
- - Advantages
- The advantage of downloading resources from the CDN is that you have full control to modify them as needed, allowing you to customize them to suit your project’s specific requirements.
- I conducted tests both using the CDN and locally. However, I only tested the implementation in /template/overall_header.html.
- Ideally, JavaScript scripts should be placed in overall_footer.html, as that is the standard location for them to function properly. However, I have not tested this setup in overall_footer.html.
- Typically, CSS files like:
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/styles/monokai-sublime.min.css">
- should be included in the <head> section of the document.
- JavaScript scripts, however, are generally placed in the overall_footer.html file for better performance and to ensure they load after the page content.
- Example: Local Highlight.js Setup
- <!-- Include Highlight.js CSS and JS -->
- <link rel="stylesheet" href="{T_THEME_PATH}/highlightjs/monokai-sublime.css">
- <script src="{T_THEME_PATH}/highlightjs/highlight.min.js"></script>
- <script>
- // Enable automatic detection for all <code> blocks
- document.addEventListener("DOMContentLoaded", (event) => {
- document.querySelectorAll('pre code').forEach((block) => {
- hljs.highlightElement(block);
- });
- });
- </script>
- Alternatively, you can use a shorter script to highlight all code blocks:
- <!-- Include Highlight.js CSS and JS -->
- <link rel="stylesheet" href="{T_THEME_PATH}/highlightjs/monokai-sublime.css">
- <script src="{T_THEME_PATH}/highlightjs/highlight.min.js"></script>
- <script>
- hljs.highlightAll();
- </script>
- Example: Importing Highlight.js via CDN
- This method uses the CDN to directly load Highlight.js resources into your project.
- <!-- Include Highlight.js CSS and JS -->
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/styles/monokai-sublime.min.css">
- <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js"></script>
- <script>
- hljs.highlightAll();
- </script>
- -----------------------------------------------------------------------
- /*
- Monokai Sublime style. Derived from Monokai by noformnocontent http://nn.mit-license.org/
- */
- In the example below, I will leave a small edit for monokai-sublime.css. There is a comment in the CSS code regarding what I have edited.
- You have both minified and unminified CSS sources available when downloading Highlight.js from the CDN. You can easily edit the unminified version and then minify it quickly using an online tool.
- Explanation:
- I edited the color of the .hljs-attr class to green (#a6e22e) instead of the original default color (#f92672), which is used for keywords, selector tags, and names.
- The comment /* Changed to green */ indicates this modification in the CSS.
- // Custom code:
- .hljs-keyword,
- .hljs-selector-tag,
- .hljs-name {
- color: #f92672;
- }
- .hljs-attr {
- color: #a6e22e; /* Changed to green */
- }
- // Default code:
- // In the text editor, within the monokai-sublime.css file, you can find this code at lines 44–51:
- .hljs-keyword,
- .hljs-selector-tag,
- .hljs-name,
- .hljs-attr {
- color: #f92672
- }
- -----------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement