Viper007Bond
05-22-2008, 10:00 PM
I wanted to be able to close and open threads as I left my reply via the quick reply box, so I wrote this little template mod.
https://vborg.vbsupport.ru/attachment.php?attachmentid=81164&d=1211542516
Features
Checkbox at the bottom of the quick reply box to toggle the current status. Only shows up for people with proper permissions.
Javascript is used to update the reply buttons (to change them from "Reply" to "Closed" and visa-versa).
Javascript is used to change the text next to the checkbox saying what will happen when you reply.
Installation
It's a fairly easy install and only requires editing one template (SHOWTHREAD), and importing a product (for the language phrases). The following instructions are for the default theme, but custom themes will probably be really similiar.
Download and install the product. This will create the new language phrases so you can translate this hack to your liking.
Then open up "SHOWTHREAD" and find this code. It's for the top reply button.
<if condition="$show['largereplybutton']">
<td class="smallfont"><a href="newreply.php?$session[sessionurl]do=newreply&noquote=1&p=$FIRSTPOSTID" rel="nofollow"><if condition="$show['closethread']"><img src="$stylevar[imgdir_button]/reply.gif" alt="$vbphrase[reply]" border="0" /><else /><img src="$stylevar[imgdir_button]/threadclosed.gif" alt="$vbphrase[closed_thread]" border="0" /></if></a></td>
<else />
You will need to give both the open (reply.gif) and the closed (threadclosed.gif) <img> tags a new CSS class called "replybutton" so that the Javascript can update them.
So for the default theme, that would result in this:
<if condition="$show['largereplybutton']">
<td class="smallfont"><a href="newreply.php?$session[sessionurl]do=newreply&noquote=1&p=$FIRSTPOSTID" rel="nofollow"><if condition="$show['closethread']"><img src="$stylevar[imgdir_button]/reply.gif" alt="$vbphrase[reply]" border="0" class="replybutton" /><else /><img src="$stylevar[imgdir_button]/threadclosed.gif" alt="$vbphrase[closed_thread]" border="0" class="replybutton" /></if></a></td>
<else />
Now do the same thing for the bottom reply button (same HTML).
Now we need to add the new code to the bottom of the quick reply box (same template).
Find this code which is the HTML for the "quote message in post" checkbox:
<label for="qr_quickreply"><input type="checkbox" name="quickreply" value="1" id="qr_quickreply" accesskey="w" tabindex="4" />$vbphrase[quote_message_in_reply]</label>
</div>
</fieldset>
After that (and before what is probably a </div>), add all of this:
<if condition="$show['openclose']">
<fieldset class="fieldset" style="margin:$stylevar[formspacer]px 0px 0px 0px">
<legend>$vbphrase[viper_opencloseqr_thread_management]</legend>
<div style="padding:3px">
<div>
<label for="cb_openclose"><input type="checkbox" name="openclose" value="1" id="cb_openclose" tabindex="1" /><span id="qr_openclosestatus"><if condition="$show['closethread']">$vbphrase[viper_opencloseqr_close_thread]<else />$vbphrase[viper_opencloseqr_open_thread]</if></span></label>
</div>
</div>
</fieldset>
<script type="text/javascript">
/* <![CDATA[ */
// Current thread status recorder
var viperThreadOpen = <if condition="$show['closethread']">true<else />false</if>;
// Run the custom function when the quick reply form is submitted
YAHOO.util.Event.addListener(document.getElementBy Id("qrform"), "submit", viperQuikyReply);
// Do some stuff when the form is submitted
function viperQuikyReply() {
var viperOpenCloseCheckbox = document.getElementById("cb_openclose");
var viperQRTextareaChars = document.getElementById("vB_Editor_QR_textarea").value.length;
var viperReplyButtonIMG;
// If the checkbox wasn't checked or the message was too short (simple check), abort
if ( viperOpenCloseCheckbox.checked == false || viperQRTextareaChars == 0 || viperQRTextareaChars < $vboptions[postminchars] ) return;
// Uncheck the checkbox
viperOpenCloseCheckbox.checked = false;
// Change the text and set the reply button image filename
if ( viperThreadOpen == true ) {
document.getElementById("qr_openclosestatus").innerHTML = "$vbphrase[viper_opencloseqr_open_thread]";
viperReplyButtonIMG = "threadclosed.gif";
viperThreadOpen = false;
} else {
document.getElementById("qr_openclosestatus").innerHTML = "$vbphrase[viper_opencloseqr_close_thread]";
viperReplyButtonIMG = "reply.gif";
viperThreadOpen = true;
}
// Get all reply buttons via the new class
var replybuttons = YAHOO.util.Dom.getElementsByClassName("replybutton", "img");
// Loop through each reply button and change it's image URL
var i;
for (i in replybuttons) {
replybuttons[i].src = "$stylevar[imgdir_button]/" + viperReplyButtonIMG;
}
}
/* ]]> */
</script>
</if>
Save and you're all done!
Oh, and don't forget to mark this as installed (https://vborg.vbsupport.ru/vborg_miscactions.php?do=installhack&threadid=180239)! :)
https://vborg.vbsupport.ru/attachment.php?attachmentid=81164&d=1211542516
Features
Checkbox at the bottom of the quick reply box to toggle the current status. Only shows up for people with proper permissions.
Javascript is used to update the reply buttons (to change them from "Reply" to "Closed" and visa-versa).
Javascript is used to change the text next to the checkbox saying what will happen when you reply.
Installation
It's a fairly easy install and only requires editing one template (SHOWTHREAD), and importing a product (for the language phrases). The following instructions are for the default theme, but custom themes will probably be really similiar.
Download and install the product. This will create the new language phrases so you can translate this hack to your liking.
Then open up "SHOWTHREAD" and find this code. It's for the top reply button.
<if condition="$show['largereplybutton']">
<td class="smallfont"><a href="newreply.php?$session[sessionurl]do=newreply&noquote=1&p=$FIRSTPOSTID" rel="nofollow"><if condition="$show['closethread']"><img src="$stylevar[imgdir_button]/reply.gif" alt="$vbphrase[reply]" border="0" /><else /><img src="$stylevar[imgdir_button]/threadclosed.gif" alt="$vbphrase[closed_thread]" border="0" /></if></a></td>
<else />
You will need to give both the open (reply.gif) and the closed (threadclosed.gif) <img> tags a new CSS class called "replybutton" so that the Javascript can update them.
So for the default theme, that would result in this:
<if condition="$show['largereplybutton']">
<td class="smallfont"><a href="newreply.php?$session[sessionurl]do=newreply&noquote=1&p=$FIRSTPOSTID" rel="nofollow"><if condition="$show['closethread']"><img src="$stylevar[imgdir_button]/reply.gif" alt="$vbphrase[reply]" border="0" class="replybutton" /><else /><img src="$stylevar[imgdir_button]/threadclosed.gif" alt="$vbphrase[closed_thread]" border="0" class="replybutton" /></if></a></td>
<else />
Now do the same thing for the bottom reply button (same HTML).
Now we need to add the new code to the bottom of the quick reply box (same template).
Find this code which is the HTML for the "quote message in post" checkbox:
<label for="qr_quickreply"><input type="checkbox" name="quickreply" value="1" id="qr_quickreply" accesskey="w" tabindex="4" />$vbphrase[quote_message_in_reply]</label>
</div>
</fieldset>
After that (and before what is probably a </div>), add all of this:
<if condition="$show['openclose']">
<fieldset class="fieldset" style="margin:$stylevar[formspacer]px 0px 0px 0px">
<legend>$vbphrase[viper_opencloseqr_thread_management]</legend>
<div style="padding:3px">
<div>
<label for="cb_openclose"><input type="checkbox" name="openclose" value="1" id="cb_openclose" tabindex="1" /><span id="qr_openclosestatus"><if condition="$show['closethread']">$vbphrase[viper_opencloseqr_close_thread]<else />$vbphrase[viper_opencloseqr_open_thread]</if></span></label>
</div>
</div>
</fieldset>
<script type="text/javascript">
/* <![CDATA[ */
// Current thread status recorder
var viperThreadOpen = <if condition="$show['closethread']">true<else />false</if>;
// Run the custom function when the quick reply form is submitted
YAHOO.util.Event.addListener(document.getElementBy Id("qrform"), "submit", viperQuikyReply);
// Do some stuff when the form is submitted
function viperQuikyReply() {
var viperOpenCloseCheckbox = document.getElementById("cb_openclose");
var viperQRTextareaChars = document.getElementById("vB_Editor_QR_textarea").value.length;
var viperReplyButtonIMG;
// If the checkbox wasn't checked or the message was too short (simple check), abort
if ( viperOpenCloseCheckbox.checked == false || viperQRTextareaChars == 0 || viperQRTextareaChars < $vboptions[postminchars] ) return;
// Uncheck the checkbox
viperOpenCloseCheckbox.checked = false;
// Change the text and set the reply button image filename
if ( viperThreadOpen == true ) {
document.getElementById("qr_openclosestatus").innerHTML = "$vbphrase[viper_opencloseqr_open_thread]";
viperReplyButtonIMG = "threadclosed.gif";
viperThreadOpen = false;
} else {
document.getElementById("qr_openclosestatus").innerHTML = "$vbphrase[viper_opencloseqr_close_thread]";
viperReplyButtonIMG = "reply.gif";
viperThreadOpen = true;
}
// Get all reply buttons via the new class
var replybuttons = YAHOO.util.Dom.getElementsByClassName("replybutton", "img");
// Loop through each reply button and change it's image URL
var i;
for (i in replybuttons) {
replybuttons[i].src = "$stylevar[imgdir_button]/" + viperReplyButtonIMG;
}
}
/* ]]> */
</script>
</if>
Save and you're all done!
Oh, and don't forget to mark this as installed (https://vborg.vbsupport.ru/vborg_miscactions.php?do=installhack&threadid=180239)! :)