Browse Source

Add BBCode editor toolbar

spaghetti 8 years ago
parent
commit
180f84e240

+ 1
- 1
design/views/generic/textarea/textarea.phtml View File

@@ -1,4 +1,4 @@
1 1
 
2 2
 <div id="textarea_wrap_<?=$NID?>" class="field_div textarea_wrap">
3
-  <textarea name="<?=$Name?>" id="<?=$ID?>" cols="<?=$Cols?>" rows="<?=$Rows?>" <?=$Attributes?>><?=$Value?></textarea>
3
+  <textarea name="<?=$Name?>" id="<?=$ID?>" class="bbcode_editor" cols="<?=$Cols?>" rows="<?=$Rows?>" <?=$Attributes?>><?=$Value?></textarea>
4 4
 </div>

+ 1
- 1
sections/forums/newthread.php View File

@@ -88,7 +88,7 @@ View::show_header('Forums &gt; '.$Forum['Name'].' &gt; New Topic', 'comments,bbc
88 88
         </tr>
89 89
         <tr>
90 90
           <td class="label">Body:</td>
91
-          <td><textarea id="posttext" class="required" style="width: 98%;" onkeyup="resize('posttext');" name="body" cols="90" rows="8"></textarea></td>
91
+          <td><textarea id="posttext" class="required bbcode_editor" style="width: 98%;" onkeyup="resize('posttext');" name="body" cols="90" rows="8"></textarea></td>
92 92
         </tr>
93 93
         <tr>
94 94
           <td></td>

+ 51
- 0
static/functions/bbcode.js View File

@@ -15,3 +15,54 @@ var BBCode = {
15 15
     }
16 16
   }
17 17
 };
18
+
19
+function wrapSelected(box, wrap, offset) {
20
+  if (!Array.isArray(wrap)) wrap = [wrap, wrap]
21
+  if (wrap.length < 2) wrap[1] = wrap[0]
22
+  let s = box.selectionStart
23
+  let e = box.selectionEnd
24
+  let v = box.value
25
+  box.value = v.slice(0,s)+wrap[0]+v.slice(s,e)+wrap[1]+v.slice(e)
26
+  box.focus()
27
+  box.selectionEnd = (offset!==undefined?s+offset:e+wrap[0].length)
28
+}
29
+
30
+function BBEditor(box) {
31
+  let buttons = [
32
+    {short:'B', name:'Bold', wrap:['[b]','[/b]']},
33
+    {short:'I', name:'Italic', wrap:['[i]','[/i]']},
34
+    {short:'U', name:'Underline', wrap:['[u]','[/u]']},
35
+    {short:'S', name:'Strikethrough', wrap:['[s]','[/s]']},
36
+    {short:'Left', name:'Align Left', wrap:['[align=left]','[/align]']},
37
+    {short:'Center', name:'Align Center', wrap:['[align=center]','[/align]']},
38
+    {short:'Right', name:'Align Right', wrap:['[align=right]','[/align]']},
39
+    {short:'Pre', name:'Preformatted', wrap:['[pre]','[/pre]']},
40
+    {short:'H1', name:'Subheading 1', wrap:'=='},
41
+    {short:'H2', name:'Subheading 2', wrap:'==='},
42
+    {short:'H3', name:'Subheading 3', wrap:'===='},
43
+    {short:'Color', name:'Color', wrap:['[color=]','[/color]'], offset:7},
44
+    {short:'TeX', name:'LaTeX', wrap:['[tex]','[/tex]']},
45
+    {short:'Quote', name:'Quote', wrap:['[quote]','[/quote]']},
46
+    {short:'List', name:'List', wrap:['[*]','']},
47
+    {short:'Hide', name:'Spoiler', wrap:['[spoiler]','[/spoiler]']},
48
+    {short:'Img', name:'Image', wrap:['[img]','[/img]']},
49
+    {short:'Vid', name:'Video', wrap:['[embed]','[/embed]']},
50
+    {short:'Link', name:'Link', wrap:['[url]','[/url]']},
51
+    {short:'Torr', name:'Torrent', wrap:['[torrent]','[/torrent]']}
52
+  ]
53
+  let bar = document.createElement('ul')
54
+  bar.className = "bbcode_bar"
55
+  bar.style.width = box.offsetWidth+'px'
56
+  for (let button of buttons) {
57
+    li = document.createElement('li')
58
+    b = document.createElement('a')
59
+    b.setAttribute('title', button.name)
60
+    b.innerHTML = button.short
61
+    b.addEventListener('click', e=>wrapSelected(box, button.wrap, button.offset))
62
+    li.appendChild(b)
63
+    bar.appendChild(li)
64
+  }
65
+  box.parentNode.insertBefore(bar, box)
66
+}
67
+
68
+$('.bbcode_editor').each(function(i, el) { BBEditor(el) })

+ 14
- 5
static/styles/beluga/style.css View File

@@ -1005,7 +1005,10 @@ ul.navigation a.selected {
1005 1005
 td.label {
1006 1006
   font-weight: 300;
1007 1007
   text-align: right;
1008
-  width: 260px
1008
+  width: 180px
1009
+}
1010
+.filter_torrents td.label {
1011
+  width: 260px;
1009 1012
 }
1010 1013
 
1011 1014
 table.slice {
@@ -1496,7 +1499,7 @@ pre {
1496 1499
 }
1497 1500
 
1498 1501
 #forums .box.pad {
1499
-  padding: 0!important;
1502
+  padding: 1em 0;
1500 1503
   background-color: #23252a;
1501 1504
 }
1502 1505
 
@@ -1518,13 +1521,17 @@ pre {
1518 1521
   height: 387px
1519 1522
 }
1520 1523
 
1524
+.textarea_wrap {
1525
+  padding-top: 15px;
1526
+}
1527
+
1521 1528
 #quickpost {
1522 1529
   color: #eee!important;
1523 1530
   font-size: 1.1em!important
1524 1531
 }
1525 1532
 
1526 1533
 #quickpostform {
1527
-  background-color: transparent
1534
+  background-color: transparent;
1528 1535
 }
1529 1536
 
1530 1537
 #quickreplybuttons input[value=Editor] {
@@ -1535,8 +1542,10 @@ div.contenth #quickpost {
1535 1542
   right: -2px
1536 1543
 }
1537 1544
 
1538
-#user .bbcode-btntoolbar,#user .bbcode-smileys {
1539
-  background-color: #2c2f36!important
1545
+.bbcode_bar {
1546
+  background: #373a42;
1547
+  border: 1px solid #5b5e64;
1548
+  border-bottom: none;
1540 1549
 }
1541 1550
 
1542 1551
 #friends table[width="100%"] td {

+ 22
- 1
static/styles/global.css View File

@@ -217,6 +217,7 @@ pre {
217 217
 
218 218
 form textarea, form input {
219 219
   max-width: 100%;
220
+  box-sizing: border-box;
220 221
 }
221 222
 
222 223
 textarea {
@@ -268,7 +269,27 @@ div#AddArtists a {
268 269
 }
269 270
 
270 271
 #forums #quickpost {
271
-  width: 95%
272
+  width: 95%;
273
+}
274
+
275
+.bbcode_bar {
276
+  list-style: none;
277
+  margin: 0px 0px -4px;
278
+  box-sizing: border-box;
279
+  text-align: center;
280
+  display: inline-block;
281
+}
282
+.bbcode_bar > li {
283
+  display: inline-block;
284
+  margin: 0px;
285
+}
286
+.bbcode_bar > li > a {
287
+  display: inline-block;
288
+  height: 26px;
289
+  line-height: 26px;
290
+  cursor: pointer;
291
+  min-width: 20px;
292
+  margin: 0px 4px;
272 293
 }
273 294
 
274 295
 td.label, .valign_top {

+ 7
- 0
static/styles/oppai/style.css View File

@@ -1066,6 +1066,13 @@ input.inputtext {
1066 1066
 input.inputtext:focus {
1067 1067
   border-bottom: 1px solid #E197E5;
1068 1068
 }
1069
+
1070
+.bbcode_bar {
1071
+  background: white;
1072
+  border: 1px solid #c7c7c7;
1073
+  border-bottom: none;
1074
+}
1075
+
1069 1076
 .collage_images .collage_image {
1070 1077
   margin: 1px;
1071 1078
   width: 121px;

Loading…
Cancel
Save