Latest topics
» IconSkouliki Graphics
by skouliki Fri 20 Oct 2017, 05:08

» "Edit this page" feature
by skouliki Fri 20 Oct 2017, 01:37

» Dark Mode + Another Question
by Haggis Thu 19 Oct 2017, 10:36

» [GAME] Count to 1000 using even numbers Van-Helsing Edition
by Van-Helsing Tue 17 Oct 2017, 15:07

» [GAME] What are you thinking right now?
by Ace 1 Tue 17 Oct 2017, 08:09

» [GAME] Count to One Million!
by Ace 1 Tue 17 Oct 2017, 08:07

» [GAME] Last Letter Game
by Ace 1 Tue 17 Oct 2017, 08:06

» [GAME] World Snake
by Ace 1 Tue 17 Oct 2017, 08:06

» [GAME] Never have I ever..
by Ace 1 Tue 17 Oct 2017, 08:06

» [GAME] Animal Game
by universecat Mon 16 Oct 2017, 21:43

» [GAME] Post a random picture
by SLGray Mon 16 Oct 2017, 16:28

» Hi everyone!
by skouliki Mon 16 Oct 2017, 02:01

» Hai Guys~
by skouliki Mon 16 Oct 2017, 01:59

» Add a login popup for the toolbar
by Ape Sun 15 Oct 2017, 13:51

» Mobile Usability Test
by Ange Tuteur Sat 14 Oct 2017, 11:20

Recent Tutorials
Who is online?
In total there are 6 users online :: 0 Registered, 0 Hidden and 6 Guests :: 1 Bot

None

[ View the whole list ]


Most users ever online was 172 on Fri 19 Feb 2016, 05:17

FMD Shoutbox : Create custom buttons

View previous topic View next topic Go down

avatar
Ange Tuteur
Administrator
Title :
Coffee Addict
Gender : Male
Age : 21
Posts : 4698
Points : 9540
Reputation : 2337
Location : Macungie, PA
Language : EN10, FR5
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
Awards :
View all awards
View user profile https://github.com/SethClydesdale https://twitter.com/sethc1995

PostAnge Tuteur on 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 :


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();
    }
  }
});
avatar
Ikerepc

Title :
Gender : Male
Age : 19
Posts : 170
Points : 1774
Reputation : 48
Location : Croatia
Language : English || Croatian
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : Other
Awards :
View all awards
View user profile https://twitter.com/ikerepc

PostIkerepc on 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