Skip to content

Commit

Permalink
Scrollbox resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
blythechan committed Jan 20, 2024
1 parent e506532 commit 21e29b2
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The goal of this repo and plugin is to provide users with the BBCode suite that
- [ ] Center Block
- [x] Background ✔️
- [x] Border ✔️
- [ ] Scroll Box
- [x] Scroll Box
- [ ] Div Box
- [ ] Anchors
- [ ] Rows & Columns
Expand Down
11 changes: 11 additions & 0 deletions assets/javascripts/bbcode-parser.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,16 @@
return toNode('span', { class: 'bb-pindent' }, node.content);
};

/**
* @file Adds [scroll] to bbcode
* @example [scroll]content[/scroll]
*/
const scroll = (node) => {
const attrs = preprocessAttr(node.attrs)._default;
const heightInput = parseHeight(attrs);
return toNode("div", { class:"bb-scroll", style: `height: ${heightInput}px` }, node.content);
}

const side = (node) => {
const attrs = preprocessAttr(node.attrs)._default || "left";
return toNode("div", { class: "bb-side", "data-side": attrs }, node.content);
Expand Down Expand Up @@ -534,6 +544,7 @@
note,
ooc,
pindent,
scroll,
side,
size,
spoiler,
Expand Down
1 change: 1 addition & 0 deletions assets/javascripts/lib/discourse-markdown/bbcode-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export function setup(helper) {
"div.bb-note-tape",
"div.bb-ooc",
"div.bb-right",
"div.bb-scroll",
"div.bb-side",
"div.bb-spoiler-content",
"div[style=*]",
Expand Down
1 change: 1 addition & 0 deletions assets/stylesheets/common/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@import 'note.scss';
@import 'ooc.scss';
@import 'pindent.scss';
@import 'scroll.scss';
@import 'side.scss';
@import 'size.scss';
@import 'spoiler.scss';
Expand Down
6 changes: 6 additions & 0 deletions assets/stylesheets/common/scroll.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.bb-scroll {
max-width: 100%;
padding: 5px;
overflow:auto;
border: 1px solid;
}
2 changes: 2 additions & 0 deletions bbcode-src/preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { nobr } from "./tags/nobr";
import { note } from "./tags/note";
import { ooc } from "./tags/ooc";
import { pindent } from "./tags/pindent";
import { scroll } from "./tags/scroll";
import { side } from "./tags/side";
import { size } from "./tags/size";
import { inlinespoiler, spoiler } from "./tags/spoiler";
Expand All @@ -39,6 +40,7 @@ const tags = {
note,
ooc,
pindent,
scroll,
side,
size,
spoiler,
Expand Down
32 changes: 32 additions & 0 deletions bbcode-src/tags/scroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { preprocessAttr, toNode } from "../utils/common";

/**
* Parse the user provided height and return a valid height value
* @param {Number} heightValue obtains the input of the user entered height (default is 700)
* @returns A validated number less than 0.
*/
function parseHeight(heightValue) {
const maxHeight = 700;
const parsedHeight = heightValue && heightValue.trim() !== ""
? heightValue.replace ( /[^\d.]/g, '' )
: 0;

if(parsedHeight && parsedHeight >= 0 && parsedHeight <= maxHeight) {
return parsedHeight;
} else {
// if the value = 0 then nothing will be returned
return parsedHeight === 0
? 0
: maxHeight;
}
}

/**
* @file Adds [scroll] to bbcode
* @example [scroll]content[/scroll]
*/
export const scroll = (node) => {
const attrs = preprocessAttr(node.attrs)._default;
const heightInput = parseHeight(attrs);
return toNode("div", { class: "bb-scroll",style: `height: ${heightInput}px` }, node.content);
}

0 comments on commit 21e29b2

Please sign in to comment.