Quantcast
Channel: MyBB Community Forums - Tutorials
Viewing all articles
Browse latest Browse all 685

[1.8] How add spoiler tag button with description supoort

$
0
0
Ps. This only work with latest version of mybb 1.8 Beta 2 of Github
https://github.com/mybb/mybb/archive/feature.zip

Ps2. If need modification in final version of mybb 1.8 to this work, i will update this tutorial, don´t worry.
Ps3. Plz, not request to me or send PM asking how to add buttons in the editor. I'll just ignore it. Please do not insist. Yes, i will made tutorial of imgur button.

Mybb 1.8 use SCEditor http://www.sceditor.com/
This one is WYSIWYG editor. So add new button is not easy, because WYSIWYG editor has WYSIWYG mode and Source mode, and mybb 1.6 editor has only source mode. That means you need to add code for both ways.

To add new button you have to edit the following files:
  • root/jscripts/bbcodes_sceditor.js
  • root/jscripts/sceditor/jquery.sceditor.mybb.css
  • root/jscripts/sceditor/editor_themes/extrabuttons.css
  • codebuttons (template)

1 - Edit root/jscripts/sceditor/jquery.sceditor.mybb.css (this used to style spoiler tag in WYSIWYG mode)

1.1 - Find

PHP Code:
blockquote cite {
    
font-weightbold;
    
font-stylenormal;
    
displayblock;
    
font-size1em;
    
border-bottom1px solid #ccc;
    
margin-bottom10px;
    
padding-bottom3px;


1.2 - Add after

PHP Code:
blockquote.spoiler:before {
    
positionabsolute;
    
content'SPOILER:';
    
top: -1.35em;
    
left0;
    
font-size0.8em;
    
displayblock;
    
text-alignleft;
    
font-weightbold;
}
blockquote.spoiler {
    
margin-top1.5em;
    
background-color#F5F5F5;    


2 - Edit root/jscripts/sceditor/editor_themes/extrabuttons.css (this is used to specify the path to the image used on the button)

2.1 - Add after all

PHP Code:
.sceditor-button-spoiler div {

  
background-image:url(s.png);



3 - Copy s.png
.png  s.png (Size: 1.28 KB / Downloads: 102) in root/jscripts/sceditor/editor_themes/ (you can use any image in 16x16 or use attached file)

4 - Edit root/jscripts/bbcodes_sceditor.js (this used to add new command in sceditor)

4.1 - Find

PHP Code:
    /********************************************
     * Update quote to support pid and dateline *
     ********************************************/
    
$.sceditor.plugins.bbcode.bbcode.set('quote', {
        
format: function(elementcontent) {
            var    
author '',
                
$elm  = $(element),
                
$cite $elm.children('cite').first(); 

4.2 - Add after

PHP Code:
            if ($(element[0]).hasClass('spoiler')) {
                var 
desc '';
                if(
$cite.length === || $elm.data('desc')) {
                    
desc $elm.data('desc') || $cite.text() ;

                    
$elm.data('desc'desc);
                    
$cite.remove();

                    
content this.elementToBbcode($(element));
                    
desc  '=' desc;

                    
$elm.prepend($cite);
                }

                return 
'[spoiler' desc ']' content '[/spoiler]';
            } 

4.3 - Find

PHP Code:
        tooltip'Insert a video'
    
}); 

4.4 - Add after

PHP Code:
    /***********************
     * Add Spoiler command *
     ***********************/
    
$.sceditor.plugins.bbcode.bbcode.set("spoiler", {
        
allowsEmptytrue,
        
isInlinefalse,    
        
format: function(elementcontent) {
            var    
desc '',
                
$elm = $(element),
                
$cite $elm.children('cite').first();

            if(
$cite.length === || $elm.data('desc')) {
                
desc $elm.data('desc') || $cite.text() ;

                
$elm.data('desc'desc);
                
$cite.remove();

                
content this.elementToBbcode($(element));
                
desc '=' desc;

                
$elm.prepend($cite);
            }

            return 
'[spoiler' desc ']' content '[/spoiler]';
        },
        
html: function (tokenattrscontent) {
            var 
data '';
            
            if (
attrs.defaultattr) {
                
content '<cite>' attrs.defaultattr '</cite>' content;
                
data += ' data-desc="' attrs.defaultattr '"';
            }
                
            return 
'<blockquote' data ' class="spoiler">' content '</blockquote>';
        },
        
breakStarttrue,
        
breakEndtrue
    
});
    
    $.
sceditor.command.set("spoiler", {
        
_dropDown: function (editorcallerhtml) {
            var 
$content;

            
$content = $(
                
'<div>' +
                    
'<label for="des">' editor._('Description (optional):') + '</label> ' +
                    
'<input type="text" id="des" />' +
                
'</div>' +
                
'<div><input type="button" class="button" value="' editor._('Insert') + '" /></div>'
            
);

            
$content.find('.button').click(function (e) {
                var    
description $content.find('#des').val(),
                    
descriptionAttr '',
                    
before '[spoiler]',
                    
end '[/spoiler]';
                
                if (
description) {
                   
descriptionAttr '=' description '';
                   
before '[spoiler'descriptionAttr +']';
                }
                
                if (
html) {
                    
before before html end;
                    
end    null;
                }
                
                
editor.insert(beforeend);
                
editor.closeDropDown(true);
                
e.preventDefault();
            });

            
editor.createDropDown(caller'insertspoiler'$content);
        },        
        
exec: function (caller) {
            $.
sceditor.command.get('spoiler')._dropDown(thiscaller);
        },
        
txtExec: function (caller) {
            $.
sceditor.command.get('spoiler')._dropDown(thiscaller);
        },
    
tooltip'Insert a spoiler'
}); 

4.5 - Find
PHP Code:
$.sceditor.plugins.bbcode.bbcode.remove('code').remove('php').remove('quote').remove('video').remove('img'); 

4.6 - Replace

PHP Code:
$.sceditor.plugins.bbcode.bbcode.remove('code').remove('php').remove('quote').remove('video').remove('img').remove('spoiler'); 

5 - Go to codebuttons template in ACP

5.1 - Find

PHP Code:
toolbar"{$basic1}{$align}{$font}{$size}{$color}{$removeformat}{$basic2}image,{$email}{$link}|video{$emoticon}|{$list}{$code}quote|maximize,source"

5.2 - Replace

PHP Code:
toolbar"{$basic1}{$align}{$font}{$size}{$color}{$removeformat}{$basic2}image,{$email}{$link}|video{$emoticon}|{$list}{$code}quote,spoiler|maximize,source"

6 - Now you need add spoiler mycode or plugin of spoiler with description support. I recommend that use plugin because plugin is nestable and mycode is not. I recommend this one http://mods.mybb.com/view/spoiler-advance . Of course you need edit plugin to work with 1.8

Find:

Code:
"compatibility" => "16*"

Replace:

Code:
"compatibility" => "1*"

If you use tapatalk and has problem with spoiler-advance so read this https://support.tapatalk.com/threads/adv...ost-133893

Preview:
http://i.imgur.com/FXSo1mv.png

Viewing all articles
Browse latest Browse all 685

Trending Articles