MyBB Community Forums

Full Version: Replace most of the javascript
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like to replace the post buttons (rate, report, etc) and moderation tools not to require javascript. How should this be done?

I had a look into the "general.js" and found out the button link.

general.js (only partial, the things related to Raputation):

reputation: function(uid, pid)
	{
		if(!pid)
		{
			var pid = 0;
		}

		MyBB.popupWindow("/reputation.php?action=add&uid="+uid+"&pid="+pid+"&modal=1");
	},

	deleteReputation: function(uid, rid)
	{
		$.prompt(delete_reputation_confirm, {
			buttons:[
					{title: yes_confirm, value: true},
					{title: no_confirm, value: false}
			],
			submit: function(e,v,m,f){
				if(v == true)
				{
					var form = $("<form />",
					{
						method: "post",
						action: "reputation.php?action=delete",
						style: "display: none;"
					});

					form.append(
						$("<input />",
						{
							name: "rid",
							type: "hidden",
							value: rid
						})
					);

					if(my_post_key)
					{
						form.append(
							$("<input />",
							{
								name: "my_post_key",
								type: "hidden",
								value: my_post_key
							})
						);
					}

					form.append(
						$("<input />",
						{
							name: "uid",
							type: "hidden",
							value: uid
						})
					);

					$("body").append(form);
					form.submit();
				}
			}
		});

		return false;
	},

So basically theĀ postbit_rep_button template should have this in it:

<a href="/reputation.php?action=add&uid={$post['uid']}&pid={$post['pid']}&no_modal=1" title="{$lang->postbit_reputation_add}" class="postbit_reputation_add"><span>{$lang->postbit_button_reputation_add}</span></a>

After that it works, but now I need to figure out how to get an delete reputation button aka dislike button created.


How can I add the custom button(s)?

I have created an template for the button called "postbit_rep_button_del". The template content:
<a href="/reputation.php?action=delete&uid={$post['uid']}&pid={$post['pid']}&no_modal=1" title="{$lang->postbit_reputation_del}" class="postbit_reputation_del"><span>{$lang->postbit_button_reputation_del}</span></a>

My posbit template looks like this:
{$ignore_bit}
<a name="pid{$post['pid']}" id="pid{$post['pid']}"></a>
<div class="post {$unapproved_shade}" style="{$post_visibility}" id="post_{$post['pid']}">
<div class="post_author">
	{$post['useravatar']}
	<div class="author_information">
			<strong><span class="largetext">{$post['profilelink']}</span></strong> {$post['onlinestatus']}<br />
			<span class="smalltext">
				{$post['usertitle']}<br />
				{$post['userstars']}
				{$post['groupimage']}
			</span>
	</div>
	<div class="author_statistics">
		{$post['user_details']}
	</div>
</div>
<div class="post_content">
	<div class="post_head">
		{$post['posturl']}
		{$post['icon']}
		<span class="post_date">{$post['postdate']} <span class="post_edit" id="edited_by_{$post['pid']}">{$post['editedmsg']}</span></span>
		{$post['subject_extra']}
	</div>
	<div class="post_body scaleimages" id="pid_{$post['pid']}">
		{$post['message']}
	</div>
	{$post['attachments']}
	{$post['signature']}
	<div class="post_meta" id="post_meta_{$post['pid']}">
		{$post['iplogged']}
	</div>
</div>
<div class="post_controls">
	<div class="postbit_buttons author_buttons float_left">
		{$post['button_email']}{$post['button_pm']}{$post['button_www']}{$post['button_find']}{$post['button_rep']}{$post['button_rep_del']}
	</div>
	<div class="postbit_buttons post_management_buttons float_right">
		{$post['button_edit']}{$post['button_quickdelete']}{$post['button_quickrestore']}{$post['button_quote']}{$post['button_multiquote']}{$post['button_report']}{$post['button_warn']}{$post['button_purgespammer']}{$post['button_reply_pm']}{$post['button_replyall_pm']}{$post['button_forward_pm']}{$post['button_delete_pm']}
	</div>
</div>
</div>
I'm not sure what you mean, you can add the code directly to the postbit template. Otherwise you can use Template Conditionals: http://mybbhacks.zingaburga.com/showthread.php?tid=464 (<template templatename> in another template).
(2015-12-29, 10:28 PM)Destroy666 Wrote: [ -> ]I'm not sure what you mean, you can add the code directly to the postbit template. Otherwise you can use Template Conditionals: http://mybbhacks.zingaburga.com/showthread.php?tid=464 (<template templatename> in another template).

The problem is that I would want it to be styled like the other buttons too. :/
I don't see how that's related to the intial question, but the CSS for buttons is in global.css. In the default theme .postbit_buttons is the wrapper class and shouldn't be a problem if you insert the button code next to other buttons. Then there are also individual classes which are responsible for sprite images, e.g. .postbit_qdelete:
.postbit_buttons a.postbit_qdelete span {
    background-position: 0 -180px;
}
uses the cross image from images/buttons_sprite.png based on the position and size specified in .postbit_buttons a span.