Browse Source

BBcode Toolbar: Add to ajax-created edit boxes too

spaghetti 8 years ago
parent
commit
55e42a1ddf
2 changed files with 15 additions and 27 deletions
  1. 6
    0
      static/functions/bbcode.js
  2. 9
    27
      static/functions/comments.js

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

28
 }
28
 }
29
 
29
 
30
 function BBEditor(box) {
30
 function BBEditor(box) {
31
+  if (box.previousSibling.className == 'bbcode_bar') return
31
   let buttons = [
32
   let buttons = [
32
     {short:'B', name:'Bold', wrap:['[b]','[/b]']},
33
     {short:'B', name:'Bold', wrap:['[b]','[/b]']},
33
     {short:'I', name:'Italic', wrap:['[i]','[/i]']},
34
     {short:'I', name:'Italic', wrap:['[i]','[/i]']},
53
   let bar = document.createElement('ul')
54
   let bar = document.createElement('ul')
54
   bar.className = "bbcode_bar"
55
   bar.className = "bbcode_bar"
55
   bar.style.width = box.offsetWidth+'px'
56
   bar.style.width = box.offsetWidth+'px'
57
+  // Let the DOM update and then snap the size again (twice)
58
+  setTimeout(function() {
59
+    bar.style.width = box.offsetWidth+'px'
60
+    bar.style.width = box.offsetWidth+'px'
61
+  }, 1)
56
   for (let button of buttons) {
62
   for (let button of buttons) {
57
     li = document.createElement('li')
63
     li = document.createElement('li')
58
     b = document.createElement('a')
64
     b = document.createElement('a')

+ 9
- 27
static/functions/comments.js View File

118
   //If no edit is already going underway or a previous edit was finished, make the necessary dom changes.
118
   //If no edit is already going underway or a previous edit was finished, make the necessary dom changes.
119
   if (!$('#editbox' + postid).results() || $('#editbox' + postid + '.hidden').results()) {
119
   if (!$('#editbox' + postid).results() || $('#editbox' + postid + '.hidden').results()) {
120
     $('#reply_box').ghide();
120
     $('#reply_box').ghide();
121
-    if (location.href.match(/torrents\.php/)
122
-        || location.href.match(/artist\.php/)) {
123
-      boxWidth = "50";
124
-    } else {
125
-      boxWidth = "80";
126
-    }
121
+    boxWidth = (location.href.match(/torrents\.php/) || location.href.match(/artist\.php/)) ? "50" : "80";
127
     postuserid = $('#post' + postid + ' strong a').attr('href').split('=')[1];
122
     postuserid = $('#post' + postid + ' strong a').attr('href').split('=')[1];
128
-    if (postuserid != userid) {
129
-      pmbox = '<span id="pmbox' + postid + '"><label>PM user on edit? <input type="checkbox" name="pm" value="1" /></label></span>';
130
-    } else {
131
-      pmbox = '';
132
-    };
133
-    if (location.href.match(/forums\.php/)) {
134
-      inputname = "post";
135
-    } else {
136
-      inputname = "postid";
137
-    }
123
+    pmbox = (postuserid != userid) ? '<span id="pmbox' + postid + '"><label>PM user on edit? <input type="checkbox" name="pm" value="1" /></label></span>' : '';
124
+    inputname = (location.href.match(/forums\.php/)) ? "post" : "postid";
138
     $('#bar' + postid).raw().cancel = $('#content' + postid).raw().innerHTML;
125
     $('#bar' + postid).raw().cancel = $('#content' + postid).raw().innerHTML;
139
     $('#bar' + postid).raw().oldbar = $('#bar' + postid).raw().innerHTML;
126
     $('#bar' + postid).raw().oldbar = $('#bar' + postid).raw().innerHTML;
140
     $('#content' + postid).raw().innerHTML = "<div id=\"preview" + postid + "\"></div><form id=\"form" + postid + "\" method=\"post\" action=\"\">" + pmbox + "<input type=\"hidden\" name=\"auth\" value=\"" + authkey + "\" /><input type=\"hidden\" name=\"key\" value=\"" + key + "\" /><input type=\"hidden\" name=\"" + inputname + "\" value=\"" + postid + "\" /><textarea id=\"editbox" + postid + "\" onkeyup=\"resize('editbox" + postid + "');\" name=\"body\" cols=\"" + boxWidth + "\" rows=\"10\"></textarea></form>";
127
     $('#content' + postid).raw().innerHTML = "<div id=\"preview" + postid + "\"></div><form id=\"form" + postid + "\" method=\"post\" action=\"\">" + pmbox + "<input type=\"hidden\" name=\"auth\" value=\"" + authkey + "\" /><input type=\"hidden\" name=\"key\" value=\"" + key + "\" /><input type=\"hidden\" name=\"" + inputname + "\" value=\"" + postid + "\" /><textarea id=\"editbox" + postid + "\" onkeyup=\"resize('editbox" + postid + "');\" name=\"body\" cols=\"" + boxWidth + "\" rows=\"10\"></textarea></form>";
144
    * If editing is already underway and edit is pressed again, reset the post
131
    * If editing is already underway and edit is pressed again, reset the post
145
    * (keeps current functionality, move into brackets to stop from happening).
132
    * (keeps current functionality, move into brackets to stop from happening).
146
    */
133
    */
147
-  if (location.href.match(/forums\.php/)) {
148
-    ajax.get("?action=get_post&post=" + postid, function(response) {
149
-      $('#editbox' + postid).raw().value = html_entity_decode(response);
150
-      resize('editbox' + postid);
151
-    });
152
-  } else {
153
-    ajax.get("comments.php?action=get&postid=" + postid, function(response) {
154
-      $('#editbox' + postid).raw().value = html_entity_decode(response);
155
-      resize('editbox' + postid);
156
-    });
157
-  }
134
+  var post_endpoint = (location.href.match(/forums\.php/)) ? '?action=get_post&post=' : 'comments.php?action=get&postid=';
135
+  ajax.get(post_endpoint + postid, function(response) {
136
+    $('#editbox' + postid).raw().value = html_entity_decode(response);
137
+    resize('editbox' + postid);
138
+    BBEditor($('#editbox' + postid).raw());
139
+  });
158
 }
140
 }
159
 
141
 
160
 function Cancel_Edit(postid) {
142
 function Cancel_Edit(postid) {

Loading…
Cancel
Save