FM Design
Would you like to react to this message? Create an account in a few clicks or log in to continue.

IMPORTANT

FM Design is in read-only mode, please click here for more information.

Latest topics
» Forumactif Edge - Releases
by Ange Tuteur Tue 03 Sep 2019, 11:49

» GIFActif - Giphy Button for the Editor
by Ange Tuteur Wed 08 May 2019, 17:21

» Forum Closure
by Ange Tuteur Mon 01 Jan 2018, 01:28

» Chit Chat Thread
by Valoish Sun 31 Dec 2017, 19:15

» Font/Text background color.
by Valoish Sun 31 Dec 2017, 19:11

» Forumactif Messenger - Instant Message Application for Forumotion
by Wolfuryo Sun 31 Dec 2017, 18:24

» [GAME] Count to One Million!
by brandon_g Fri 29 Dec 2017, 18:58

» Post Cards
by manikbiradar Wed 20 Dec 2017, 07:50

» [GAME] Countdown from 200,000
by Valoish Wed 13 Dec 2017, 23:22

» GeekPolice Tech Support Forums - GeekPolice.net
by Dr Jay Mon 11 Dec 2017, 19:12

» Asking about some plugin for Forumotion
by Dr Jay Mon 11 Dec 2017, 19:10

» [GAME] What are you thinking right now?
by Van-Helsing Sat 09 Dec 2017, 14:51

» Widget : Similar topics
by ranbac Wed 06 Dec 2017, 18:11

» Change the Background of the Forum and put an image and how to make prefixs?
by Clement Wed 06 Dec 2017, 15:19

» Hello from Western Australia
by SarkZKalie Wed 06 Dec 2017, 05:34

Recent Tutorials
Top posting users this month

Who is online?
In total there are 39 users online :: 0 Registered, 0 Hidden and 39 Guests :: 2 Bots

None

[ View the whole list ]


Most users ever online was 515 on Tue 14 Sep 2021, 15:24

FMD Shoutbox : Create custom buttons

View previous topic View next topic Go down

Ange Tuteur
Ange Tuteur
Administrator
Gender : Male
Posts : 4741
Points : 12253
Reputation : 2376
Location : Pennsylvania
Language : EN, JA, FR
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
https://sethclydesdale.github.io/ https://twitter.com/sethc1995

PostAnge Tuteur Mon 16 Feb 2015, 23:39

This topic will explain the basics for creating two types of buttons for the shoutbox; Format and Advanced.


Formatting

Format buttons are buttons which can be toggled on and off. They make use of a CSS style string to show the result in the input box. The CSS property value is used to apply the format on submission and change the state of the button.

This is an example of a format button :
Code:
button({
  name : 'bold',
  text : 'B',
  css : 'font-weight:bold',
  tags : ['[b]','[/b]'],
  where : actions
});

name : The name of your format button. This is used as the title and cookie name.

text : The text that displays inside the button.

css : A CSS style string that should consist of a single property and value without spaces and semi-colons ! This is used to add a "WYSIWYG" feel to the message box, but also to identify if the custom format is enabled. For content you don't want to see the changes of, but have enabled, you should use the content property. For example :
Code:
css : 'content:"myCustomFormat"'

This allows you to create a majority of formats by using a simple string. i.e. "myCustomFormat"

tags : These are the beginning and end tags that will be applied to your message when it's sent. The first tag is the opening tag and the second tag is the closing tag. Not all tags will be supported for the style you want, so I've added a custom tag. Here's an example :
Code:
tags : ['[custom style="text-shadow: 1px 1px 1px"]','[/custom]']

This custom tag will be formatted as a <SPAN> tag. You can use the style attribute, classnames, etc.. to create a majority of format styles.

where : This is where your custom button will appear. Currently there are two options : actions and options. A button appended to actions will display in the footer of the shoutbox, whereas a button appended to options will display in the header of the shoutbox.

style : Not used in the example, but takes a string of CSS properties and values. This is used to add a custom style to your button, such as a color, background, border...
Code:
style : 'color:red;background:blue;border-color:green'


Advanced

Advanced buttons go past the simple formatting and allow you to use JavaScript to achieve what you desire.

This is an example of an advanced button :
Code:
button({
  name : 'refresh messages',
  text : 'Refresh',
  where : options,
  advanced : function(b) {
    b.onclick = function() {
      idle = 0;
      getMessages({
        apply : function() { b.style.opacity = 0.3 },
        callback : function() {
          b.style.opacity = '';
          scrollBox();
        }
      });
    }
  }
});

The name property is used only for titles when the tags property is omitted.

advanced : Contains JavaScript code that you want to execute. It should be set like so :
Code:
advanced : function (b) {
  // do something here
  b.onclick = function() { alert('You clicked me !') }
}

The argument in the function "b" refers to the button you created. You can bind events, such as onclick to execute code when you click the button. You can also use jQuery if that's your style. Wink
Code:
advanced : function (b) {
  // do something here
  $(b).click(function() { alert('You clicked me !') });
}

The advanced function can also be applied to format buttons too, depending on how creative you want to get. Smile


Installing custom buttons

For ease of use, I've added a "plugins" function to the config. This allows you to insert custom buttons, popups, etc.. into the shoutbox with ease. Simply copy the code you want to install and paste it inside plugins :

FMD Shoutbox : Create custom buttons Captu103

If you understand JavaScript, then you can add your custom code wherever.. Wink


Example snippets

To get you thinking and give you examples, here are some custom buttons for you to play with.

Glow :
Applies a glow to your text. The color is influenced by your text color.
Code:
button({
  name : 'glow',
  text : 'G',
  css : 'text-shadow:1px 1px 1px',
  tags : ['[custom style="text-shadow: 1px 1px 1px"]','[/custom]'],
  where : actions
});

Table :
An example of utilizing a classname to make a custom format.
Code:
button({
  name : 'tableA',
  text : 'table',
  css : 'content:"customTable"',
  tags : ['[custom class="tableA"]','[/custom]'],
  where : actions
});

You can then style the table above with CSS :
Code:
.tableA {
  color:#999;
  font-weight:bold;
  text-shadow:1px 1px 1px #FFF;
  background:#EEE;
  border:1px solid #CCC;
  border-radius:3px;
  display:block;
  padding:3px;
}


The red button
A silly joke that emerged during development. Clicking the button flips the shoutbox upside down and sends a message saying the member pressed it.
Code:
button({
  name : 'Don\'t click the red button !',
  text : 'Click me',
  style : 'background:#F66;color:#633;border-color:#C66;text-shadow:none',
  where : actions,
  advanced : function(b) {
    b.onclick = function() {
      fmd_chat.style.transform ? fmd_chat.style.transform = '' : fmd_chat.style.transform = 'rotate(180deg)';
      message.value = '[color=#ff0000][b]'+_userdata.username+' clicked the red button ![/b][/color]';
      sendMessage();
    }
  }
});
Ikerepc
Ikerepc

Gender : Male
Age : 26
Posts : 170
Points : 4361
Reputation : 48
Location : Croatia
Language : English || Croatian
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : Other
https://twitter.com/ikerepc

PostIkerepc Tue 24 Feb 2015, 11:20

Awesome, now I have chatbox with red button! Love your work @Ange Tuteur Smile

View previous topic View next topic Back to top

Create an account or log in to leave a reply

You need to be a member in order to leave a reply.

Create an account

Join our community by creating a new account. It's easy!


Create a new account

Log in

Already have an account? No problem, log in here.


Log in

 
Permissions in this forum:
You cannot reply to topics in this forum