Super simple instructions to add your click-to-add-your-MyCode buttons

Spartak

Well-known member
Member
Joined
9 yrs. 9 mth. 5 days
Messages
587
Reaction score
8,878
Wallet
0$
Super simple instructions to add your click-to-add-your-MyCode buttons

This is for real basic buttons. You just click it and the MyCode is slapped down in the editor, around selected text if applicable. <br />
<br />
This tutorial only covers the editor buttons. You'll have to work out the actual MyCode yourself.<br />
<br />
<span style="font-weight: bold;" class="mycode_b"><span style="font-size: medium;" class="mycode_size">Step 1: The Code</span></span><br />
<pre data-deferred="true" class="block-code line-numbers language-none"><code class="language-none">/*YourCode button*/
$.sceditor.command.set(&quot;YourCode&quot;, {
_dropDown: function (editor, caller) {
var $content;

$content = $(
'&lt;div&gt;' +
'&lt;div&gt;' +
'&lt;label for=&quot;YourCode&quot;&gt;' + editor._('YourCode') + ':&lt;/label&gt; ' +
'&lt;textarea type=&quot;text&quot; id=&quot;YourCode&quot;&gt;&lt;/textarea&gt;' +
'&lt;/div&gt;' +
'&lt;div&gt;&lt;input type=&quot;button&quot; class=&quot;button&quot; value=&quot;' + editor._('Insert') + '&quot; /&gt;&lt;/div&gt;' +
'&lt;/div&gt;'
);

setTimeout(function () {
$content.find('#YourCode').trigger('focus');
}, 100);

$content.find('.button').on('click', function (e) {
var val = $content.find('#YourCode').val(),
before = '[YourCode]',
end = '[/YourCode]';

if (val) {
before = before + val + end;
end = null;
}

editor.insert(before, end);
editor.closeDropDown(true);
e.preventDefault();
});

editor.createDropDown(caller, 'insertYourCode', $content.get(0));
},
exec: function (caller) {
if ($.trim(this.getRangeHelper().selectedRange())) {
this.insert('[YourCode]', '[/YourCode]');
return;
}
$.sceditor.command.get('YourCode')._dropDown(this, caller);
},
txtExec: ['[YourCode]', '[/YourCode]'],
tooltip: 'YourCode'
});
/*YourCode button*/</code></pre><br />
Take this, replace "<span style="color: #E82A1F;" class="mycode_color">YourCode</span>" with the name of your MyCode. The tooltip bit at the end is help text, so change that to be as descriptive and helpful as you think it should be.<br />
<br />
If your code takes parameters in the first tag (such as how <span style="font-weight: bold;" class="mycode_b"><span style="color: #B10DC9;" class="mycode_color">[i<span style="font-style: italic;" class="mycode_i"></span>mg]</span></span> tags can be <span style="color: #B10DC9;" class="mycode_color">[im<span style="font-style: italic;" class="mycode_i"></span>g=widthxheight]</span>), replace every instance of <span style="color: #E82A1F;" class="mycode_color">[YourCode]</span> in brackets like that with <span style="color: #2ECC40;" class="mycode_color">[YourCode=Suggested Parameter]</span>.<br />
<br />
(This is, essentially, a complete lift of the existing "[c<span style="font-weight: bold;" class="mycode_b"></span>ode] tags button" code. If something is wrong, such as you're reading this post years in the future and it's not MyBB 1.8.5 anymore, dig up your existing version of that code and see if you can figure out how to update.)<br />
<br />
<span style="font-weight: bold;" class="mycode_b"><span style="font-size: medium;" class="mycode_size">Step 2: Actually Implementing The Code</span></span><br />
The file you're looking for is, by default, <span style="color: #B10DC9;" class="mycode_color"><span style="font-weight: bold;" class="mycode_b">[your mybb folder]/jscripts/bbcodes_sceditor.js</span></span> .<br />
<br />
Find the bit in there where there are a bunch of blocks starting with <span style="font-weight: bold;" class="mycode_b"><span style="color: #B10DC9;" class="mycode_color">&#36;.sceditor.command.set("[something or another]")</span></span>, and insert your modified code in there alongside them.<br />
<br />
<span style="font-weight: bold;" class="mycode_b"><span style="font-size: medium;" class="mycode_size">Step 3: The Button</span></span><br />
<span style="color: #B10DC9;" class="mycode_color">ACP -&gt; Templates -&gt; Search/Replace</span> -&gt; Scroll down to "Search Template Titles", and find "codebuttons".<br />
<br />
In <span style="font-style: italic;" class="mycode_i">every</span> non-Master template that comes up, edit the codebuttons template and find the line that looks approximately like this:<br />
<pre data-deferred="true" class="block-code line-numbers language-none"><code class="language-none">toolbar: &quot;{$basic1}{$align}{$font}{$size}{$color}{$removeformat}{$basic2}image,{$link}|video{$emoticon}|{$list}{$code}quote|maximize,source&quot;,</code></pre>Assuming you've done no modifications, this represents the default toolbar:<br />
<img src="
Please, Log in or Register to view URLs content!
" data-original-url="https://cdn.discordapp.com/attachments/796134868828160030/818914717371990046/unknown.png" loading="lazy" alt="[Image: unknown.png]" class="mycode_img" /><br />
<br />
You can probably figure out which bits refer to which buttons. Commas divide buttons, and pipes <span style="font-weight: bold;" class="mycode_b"><span style="color: #005DC2;" class="mycode_color">|</span></span> divide groups of buttons, and <span style="color: #005DC2;" class="mycode_color">{templates}</span> are a bunch of predefined pipes and buttons all together. Figure out where you want your button to appear and insert <span style="color: #17B529;" class="mycode_color">YourCode</span> accordingly.<br />
<br />
Save, open up a new post, and hard refresh. Congratulations, you've got a YouTube button that inserts your MyCode! ... Wait.<br />
<br />
<span style="font-weight: bold;" class="mycode_b"><span style="font-size: medium;" class="mycode_size">Step 3.5: The Button <span style="font-style: italic;" class="mycode_i">Image</span></span></span><br />
First, get yourself a 16x16 image that represents your MyCode. I'm no artist, so I can't help you with this part. <span style="font-weight: bold;" class="mycode_b">Do not put spaces in the image name</span>, it screws things up. There's probably a way to fix that but I don't know it.<br />
<br />
Then, head on to <span style="color: #B10DC9;" class="mycode_color"><span style="font-weight: bold;" class="mycode_b">[your mybb folder]/jscripts/sceditor/themes/</span></span>. Put your image into that folder, but don't go anywhere just yet, cause we've got CSS to edit.<br />
<br />
<span style="color: #B10DC9;" class="mycode_color">mybb.css</span> is the default sceditor theme. If any of your themes use a different one (check in <span style="color: #B10DC9;" class="mycode_color">ACP -&gt; Themes -&gt; [Some Theme]</span> -&gt; scroll down to "Editor Style"), edit those as well.<br />
<br />
In every file you're editing, scroll down to the bottom and add the following:<br />
<br />
<pre data-deferred="true" class="block-code line-numbers language-none"><code class="language-none">.sceditor-button-YourCode div {
background-image: url(YourImage.png)
}</code></pre>... replacing YourCode with the name of your MyCode and YourImage.png with the name of your image, of course.<br />
<br />
Go back to the new post page and hard refresh again.<br />
<br />
<img src="
Please, Log in or Register to view URLs content!
" data-original-url="https://cdn.discordapp.com/attachments/796134868828160030/818917686452682762/unknown.png" loading="lazy" alt="[Image: unknown.png]" class="mycode_img" /><br />
<br />
Rejoice.


Please, Log in or Register to view URLs content!
 
Top Bottom