Browse Source

Migrate some inline JS

spaghetti 7 years ago
parent
commit
cef83063a2

+ 1
- 1
classes/mediainfo.class.php View File

@@ -88,7 +88,7 @@ class ParseManager {
88 88
         if (!isset($this->parsers['general'])) return $string;
89 89
 
90 90
         $midiv_start = '<div class="spoilerContainer hideContainer">
91
-            <input type="button" class="spoilerButton" onclick="BBCode.spoiler(this);" value="Show '.
91
+            <input type="button" class="spoilerButton" value="Show '.
92 92
             $this->parsers['general'][0]->filename.
93 93
             '" /><blockquote class="spoiler hidden">';
94 94
         $midiv_end = "</blockquote></div>";

+ 3
- 15
classes/text.class.php View File

@@ -4,7 +4,7 @@ class Text {
4 4
    * Array of valid tags; tag => max number of attributes
5 5
    * @var array $ValidTags
6 6
    */
7
-  private static $ValidTags = array('b'=>0, 'u'=>0, 'i'=>0, 's'=>0, '*'=>0, '#'=>0, 'ch'=>0, 'uch'=>0, 'artist'=>0, 'user'=>0, 'n'=>0, 'inlineurl'=>0, 'inlinesize'=>1, 'headline'=>1, 'align'=>1, 'color'=>1, 'colour'=>1, 'size'=>1, 'url'=>1, 'img'=>1, 'quote'=>1, 'pre'=>1, 'code'=>1, 'tex'=>0, 'hide'=>1, 'spoiler' => 1, 'plain'=>0, 'important'=>0, 'torrent'=>0, 'rule'=>0, 'mature'=>1, 'embed'=>0,
7
+  private static $ValidTags = array('b'=>0, 'u'=>0, 'i'=>0, 's'=>0, '*'=>0, '#'=>0, 'ch'=>0, 'uch'=>0, 'artist'=>0, 'user'=>0, 'n'=>0, 'inlineurl'=>0, 'inlinesize'=>1, 'headline'=>1, 'align'=>1, 'color'=>1, 'colour'=>1, 'size'=>1, 'url'=>1, 'img'=>1, 'quote'=>1, 'pre'=>1, 'code'=>1, 'tex'=>0, 'hide'=>1, 'spoiler' => 1, 'plain'=>0, 'important'=>0, 'torrent'=>0, 'rule'=>0, 'embed'=>0,
8 8
   );
9 9
 
10 10
   /**
@@ -563,9 +563,6 @@ class Text {
563 563
         case 'hide':
564 564
           $Array[$ArrayPos] = array('Type'=>'hide', 'Attr'=>$Attrib, 'Val'=>self::parse($Block));
565 565
           break;
566
-        case 'mature':
567
-          $Array[$ArrayPos] = array('Type'=>'mature', 'Attr'=>$Attrib, 'Val'=>self::parse($Block));
568
-          break;
569 566
         case 'embed':
570 567
           $Array[$ArrayPos] = array('Type'=>'embed', 'Val'=>$Block);
571 568
           break;
@@ -820,7 +817,7 @@ class Text {
820 817
           self::$NoImg++; // No images inside quote tags
821 818
           self::$InQuotes++;
822 819
           if (self::$InQuotes == self::$NestsBeforeHide) { //Put quotes that are nested beyond the specified limit in [hide] tags.
823
-            $Str .= '<strong>Older quotes</strong>: <a href="javascript:void(0);" onclick="BBCode.spoiler(this);">Show</a>';
820
+            $Str .= '<strong>Older quotes</strong>: <a class="spoilerButton">Show</a>';
824 821
             $Str .= '<blockquote class="hidden spoiler">';
825 822
           }
826 823
           if (!empty($Block['Attr'])) {
@@ -842,18 +839,9 @@ class Text {
842 839
           self::$InQuotes--;
843 840
           break;
844 841
         case 'hide':
845
-          $Str .= '<strong>'.(($Block['Attr']) ? $Block['Attr'] : 'Hidden text').'</strong>: <a href="javascript:void(0);" onclick="BBCode.spoiler(this);">Show</a>';
842
+          $Str .= '<strong>'.(($Block['Attr']) ? $Block['Attr'] : 'Hidden text').'</strong>: <a class="spoilerButton">Show</a>';
846 843
           $Str .= '<blockquote class="hidden spoiler">'.self::to_html($Block['Val']).'</blockquote>';
847 844
           break;
848
-        case 'mature':
849
-          if (!empty($Block['Attr'])) {
850
-            $Str .= '<strong class="mature" style="font-size: 1.2em;">Mature content:</strong><strong> ' . $Block['Attr'] . '</strong><br /> <a href="javascript:void(0);" onclick="BBCode.spoiler(this);">Show</a>';
851
-            $Str .= '<blockquote class="hidden spoiler">'.self::to_html($Block['Val']).'</blockquote>';
852
-          }
853
-          else {
854
-            $Str .= '<strong>Use of the [mature] tag requires a description.</strong> The correct format is as follows: <strong>[mature=description] ...content... [/mature]</strong>, where "description" is a mandatory description of the post. Misleading descriptions will be penalized. For further information on our mature content policies, please refer to this <a href="wiki.php?action=article&amp;id=1063">wiki</a>.';
855
-          }
856
-          break;
857 845
         case 'img':
858 846
           if (self::$NoImg > 0 && self::valid_url($Block['Val'])) {
859 847
             $Str .= '<a rel="noreferrer" target="_blank" href="'.$Block['Val'].'">'.$Block['Val'].'</a> (image)';

+ 8
- 8
classes/torrent_form.class.php View File

@@ -234,12 +234,12 @@ Source: <input type="text" value="<?=Users::get_upload_sources()[0]?>" size="20"
234 234
           foreach ($Torrent['Artists'] as $Num => $Artist) { ?>
235 235
             <input type="text" id="idols_<?=$Num?>" name="idols[]" size="45" value="<?=display_str($Artist['name'])?>" <?=$this->Disabled?>/>
236 236
             <? if ($Num == 0) { ?>
237
-              <a href="#" onclick="AddArtistField(); return false;" class="brackets">+</a> <a href="#" onclick="RemoveArtistField(); return false;" class="brackets">&minus;</a>
237
+              <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
238 238
             <? }
239 239
             }
240 240
           } else { ?>
241 241
             <input type="text" id="idols_0" name="idols[]" size="45" value="" <?=$this->Disabled?> />
242
-            <a href="#" onclick="AddArtistField(); return false;" class="brackets">+</a> <a href="#" onclick="RemoveArtistField(); return false;" class="brackets">&minus;</a>
242
+            <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
243 243
 <?        } ?>
244 244
         </td>
245 245
       </tr>
@@ -496,12 +496,12 @@ Source: <input type="text" value="<?=Users::get_upload_sources()[0]?>" size="20"
496 496
           foreach ($Torrent['Artists'] as $Num => $Artist) { ?>
497 497
             <input type="text" id="idols_<?=$Num?>" name="idols[]" size="45" value="<?=display_str($Artist['name'])?>" <?=$this->Disabled?> />
498 498
             <? if ($Num == 0) { ?>
499
-              <a href="#" onclick="AddArtistField(); return false;" class="brackets">+</a> <a href="#" onclick="RemoveArtistField(); return false;" class="brackets">&minus;</a>
499
+              <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
500 500
             <? }
501 501
             }
502 502
           } else { ?>
503 503
             <input type="text" id="idols_0" name="idols[]" size="45" value="" <?=$this->Disabled?> />
504
-            <a href="#" onclick="AddArtistField(); return false;" class="brackets">+</a> <a href="#" onclick="RemoveArtistField(); return false;" class="brackets">&minus;</a>
504
+            <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
505 505
 <?        } ?>
506 506
         </td>
507 507
       </tr>
@@ -749,12 +749,12 @@ Source: <input type="text" value="<?=Users::get_upload_sources()[0]?>" size="20"
749 749
           foreach ($Torrent['Artists'] as $Num => $Artist) { ?>
750 750
             <input type="text" id="idols_<?=$Num?>" name="idols[]" size="45" value="<?=display_str($Artist['name'])?>" <?=$this->Disabled?> />
751 751
             <? if ($Num == 0) { ?>
752
-              <a href="#" onclick="AddArtistField(); return false;" class="brackets">+</a> <a href="#" onclick="RemoveArtistField(); return false;" class="brackets">&minus;</a>
752
+              <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
753 753
             <? }
754 754
             }
755 755
           } else { ?>
756 756
             <input type="text" id="idols_0" name="idols[]" size="45" value="" <?=$this->Disabled?> />
757
-            <a href="#" onclick="AddArtistField(); return false;" class="brackets">+</a> <a href="#" onclick="RemoveArtistField(); return false;" class="brackets">&minus;</a>
757
+            <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
758 758
 <?        } ?>
759 759
         </td>
760 760
       </tr>
@@ -995,12 +995,12 @@ new TEXTAREA_PREVIEW('album_desc', 'album_desc', display_str($Torrent['GroupDesc
995 995
           foreach ($Torrent['Artists'] as $Num => $Artist) { ?>
996 996
             <input type="text" id="idols_<?=$Num?>" name="idols[]" size="45" value="<?=display_str($Artist['name'])?>" <?=$this->Disabled?> />
997 997
             <? if ($Num == 0) { ?>
998
-              <a href="#" onclick="AddArtistField(); return false;" class="brackets">+</a> <a href="#" onclick="RemoveArtistField(); return false;" class="brackets">&minus;</a>
998
+              <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
999 999
             <? }
1000 1000
             }
1001 1001
           } else { ?>
1002 1002
             <input type="text" id="idols_0" name="idols[]" size="45" value="" <?=$this->Disabled?> />
1003
-            <a href="#" onclick="AddArtistField(); return false;" class="brackets">+</a> <a href="#" onclick="RemoveArtistField(); return false;" class="brackets">&minus;</a>
1003
+            <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
1004 1004
 <?        } ?>
1005 1005
         </td>
1006 1006
       </tr>

+ 2
- 2
sections/requests/new_edit.php View File

@@ -155,14 +155,14 @@ View::show_header(($NewRequest ? 'Create a request' : 'Edit a request'), 'reques
155 155
       foreach ($ArtistForm as $Artist) {
156 156
 ?>
157 157
             <input type="text" id="artist_0" name="artists[]"<? Users::has_autocomplete_enabled('other'); ?> size="45" value="<?=display_str($Artist['name']) ?>" <?=$Disabled?>/>
158
-            <? if (empty($Disabled)) { if ($First) { ?><a href="#" onclick="AddArtistField(); return false;" class="brackets">+</a> <a href="#" onclick="RemoveArtistField(); return false;" class="brackets">&minus;</a><? } $First = false; } ?>
158
+            <? if (empty($Disabled)) { if ($First) { ?><a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a><? } $First = false; } ?>
159 159
             <br />
160 160
 <?
161 161
       }
162 162
     } else {
163 163
 ?>            <input type="text" id="artist_0" name="artists[]"<? Users::has_autocomplete_enabled('other'); ?> size="45" onblur="CheckVA();" <?=$Disabled?>/>
164 164
 <? if (empty($Disabled)) { ?>
165
-            <a href="#" onclick="AddArtistField(); return false;" class="brackets">+</a> <a href="#" onclick="RemoveArtistField(); return false;" class="brackets">&minus;</a>
165
+            <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
166 166
 <? } ?>
167 167
 <?
168 168
     }

+ 1
- 1
sections/torrents/details.php View File

@@ -598,7 +598,7 @@ foreach ($TorrentList as $Torrent) {
598 598
       } else {
599 599
 ?>
600 600
   <div class="spoilerContainer hideContainer">
601
-    <input type="button" class="spoilerButton" onclick="BBCode.spoiler(this);" value="Show MediaInfo" /><blockquote class="spoiler hidden">
601
+    <input type="button" class="spoilerButton" value="Show MediaInfo" /><blockquote class="spoiler hidden">
602 602
 <?
603 603
         echo Text::full_format($MediaInfo);
604 604
 ?>

+ 1
- 1
sections/torrents/editgroup.php View File

@@ -200,7 +200,7 @@ if ($CategoryID == 1) {
200 200
         </td>
201 201
         <td id="idolfields">
202 202
           <input type="text" id="idol_0" name="idols[]" size="45" value="<?=$Artists[0]['name']?>"/>
203
-          <a onclick="AddArtistField()" class="brackets">+</a> <a onclick="RemoveArtistField()" class="brackets">&minus;</a>
203
+          <a class="add_artist_button brackets">+</a> <a class="remove_artist_button brackets">&minus;</a>
204 204
 <?
205 205
   for ($i = 1; $i < count($Artists); $i++) {
206 206
     print '<br><input type="text" id="idol_'.$i.'" name="idols[]" size="45" value="'.$Artists[$i]['name'].'"/>';

+ 20
- 23
static/functions/bbcode.js View File

@@ -1,27 +1,25 @@
1
-var BBCode = {
2
-  spoiler: function(link) {
3
-    if ($(link.nextSibling).has_class('hidden')) {
4
-      $(link.nextSibling).gshow();
5
-      $(link).html('Hide');
6
-      if ($(link).attr("value")) {
7
-        $(link).attr("value", "Hide" + $(link).attr("value").substring(4))
8
-      }
9
-    } else {
10
-      $(link.nextSibling).ghide();
11
-      $(link).html('Show');
12
-      if ($(link).attr("value")) {
13
-        $(link).attr("value", "Show" + $(link).attr("value").substring(4))
14
-      }
1
+function BBSpoiler(link) {
2
+  if ($(link.nextSibling).has_class('hidden')) {
3
+    $(link.nextSibling).gshow();
4
+    $(link).html('Hide');
5
+    if ($(link).attr("value")) {
6
+      $(link).attr("value", "Hide" + $(link).attr("value").substring(4))
7
+    }
8
+  } else {
9
+    $(link.nextSibling).ghide();
10
+    $(link).html('Show');
11
+    if ($(link).attr("value")) {
12
+      $(link).attr("value", "Show" + $(link).attr("value").substring(4))
15 13
     }
16 14
   }
17
-};
15
+}
18 16
 
19 17
 function wrapSelected(box, wrap, offset) {
20 18
   if (!Array.isArray(wrap)) wrap = [wrap, wrap]
21 19
   if (wrap.length < 2) wrap[1] = wrap[0]
22
-  let s = box.selectionStart
23
-  let e = box.selectionEnd
24
-  let v = box.value
20
+  var s = box.selectionStart
21
+  var e = box.selectionEnd
22
+  var v = box.value
25 23
   box.value = v.slice(0,s)+wrap[0]+v.slice(s,e)+wrap[1]+v.slice(e)
26 24
   box.focus()
27 25
   box.selectionEnd = (offset!==undefined?s+offset:e+wrap[0].length)
@@ -71,10 +69,9 @@ function BBEditor(box) {
71 69
   box.parentNode.insertBefore(bar, box)
72 70
 }
73 71
 
74
-if (document.readyState == 'complete') {
72
+$(function() {
75 73
   $('.bbcode_editor').each(function(i, el) { BBEditor(el) })
76
-} else {
77
-  document.addEventListener("DOMContentLoaded", function() {
78
-    $('.bbcode_editor').each(function(i, el) { BBEditor(el) })
74
+  $('.spoilerButton').each(function(i, el) {
75
+    el.addEventListener("click", ()=>BBSpoiler(el))
79 76
   })
80
-}
77
+})

+ 2
- 0
static/functions/browse.js View File

@@ -317,4 +317,6 @@ $(function() {
317 317
     var a = $('a[data-cover]')[0]
318 318
     if (a) preload(a.attributes['data-cover'].value)
319 319
   }
320
+  $('.add_artist_button').each(function(i, el) {el.addEventListener('click', AddArtistField)})
321
+  $('.remove_artist_button').each(function(i, el) {el.addEventListener('click', RemoveArtistField)})
320 322
 })

+ 1
- 1
static/functions/reportsv2.js View File

@@ -232,7 +232,7 @@ function ReportSelectorInit() {
232 232
   }
233 233
 }
234 234
 
235
-if (document.readyState == 'complete') {
235
+if (document.readyState != 'loading') {
236 236
   ReportSelectorInit();
237 237
 } else {
238 238
   document.addEventListener("DOMContentLoaded", ReportSelectorInit);

+ 2
- 0
static/functions/requests.js View File

@@ -239,4 +239,6 @@ $(function() {
239 239
       ({'jav':JavAutofill})[el.attributes['autofill'].value]()
240 240
     })
241 241
   })
242
+  $('.add_artist_button').each(function(i, el) {el.addEventListener('click', AddArtistField)})
243
+  $('.remove_artist_button').each(function(i, el) {el.addEventListener('click', RemoveArtistField)})
242 244
 })

+ 5
- 5
static/functions/upload.js View File

@@ -517,12 +517,12 @@ function MediaInfoExtract() {
517 517
   })
518 518
 }
519 519
 
520
-function initAutofill() {
521
-  document.querySelectorAll('[autofill]').forEach(function(el) {
520
+$(function() {
521
+  $('[autofill]').each(function(i, el) {
522 522
     el.addEventListener('click', function(event) {
523 523
       ({'douj':DoujAutofill, 'anime':AnidbAutofill, 'jav':JavAutofill})[el.attributes['autofill'].value]()
524 524
     })
525 525
   })
526
-}
527
-
528
-$(initAutofill)
526
+  $('.add_artist_button').each(function(i, el) {el.addEventListener('click', AddArtistField)})
527
+  $('.remove_artist_button').each(function(i, el) {el.addEventListener('click', RemoveArtistField)})
528
+})

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

@@ -125,6 +125,7 @@ button, input[type=button], input[type=submit] {
125 125
 }
126 126
 
127 127
 .spoilerButton {
128
+  cursor: pointer;
128 129
   overflow: hidden;
129 130
   text-overflow: ellipsis;
130 131
 }

Loading…
Cancel
Save