The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Add a "Bump" button for the Sceditor

View previous topic View next topic Go down

Add a "Bump" button for the Sceditor

Post by YoshiGM on October 10th 2016, 2:36 am

With this code you can add a new button in your Sceditor, that inserts automatically a "Bump" text:



Code:

$(function(){
    $(function(){
          $('<a class="sceditor-button sceditor-button-bump" unselectable="on" title="Bump"><div unselectable="on" style="background-image:url(http://i97.servimg.com/u/f97/13/45/80/80/new-go10.png)">Bump</div></a>').insertAfter('.sceditor-button-fahide').click(function(){
              $('#text_editor_textarea').sceditor("instance").insertText("Bump");
          });
      });
});

If you want to change the button icon, just edit the link:

Code:
http://i97.servimg.com/u/f97/13/45/80/80/new-go10.png


YoshiGM
Forumember

Male Posts : 533
Reputation : 80
Language : Spanish & English
Location : Mexico

http://asistencia.foroactivo.com/u21373

Back to top Go down

Re: Add a "Bump" button for the Sceditor

Post by Ange Tuteur on October 12th 2016, 4:49 pm

@YoshiGM nice work and interesting idea. I have a suggestion though. Instead of creating the button via an HTML string you can set custom commands with the SCEditor's API. See this page : http://www.sceditor.com/documentation/custom-commands/

You need to use $.sceditor.command.set to create your custom button, then you have to modify the global variable "toolbar" which contains the SCEditor toolbar string -- basically adding your button name into it. Defining your commands this way will prevent any bugs from occurring especially in WYSIWYG mode. See the example below :
Code:
$(function() {

  // check if $.sceditor and toolbar are defined
  if ($.sceditor && window.toolbar) {

    // function to execute when button is clicked
    var exec = function () {
      this.insertText('Bump');
    };

    // set SCEditor command
    $.sceditor.command.set('bump', {
      tooltip : 'Bump',

      exec : exec, // WYSIWYG mode
      txtExec : exec // Source mode
    });

    // add button to the editor toolbar
    toolbar = toolbar.replace(/fahide/, 'fahide,bump');
  }

});

NOTE : With this method you'll have to add CSS to your stylesheet :
Code:
.sceditor-button-bump div {
  background-image:url(http://i97.servimg.com/u/f97/13/45/80/80/new-go10.png) !important;
}
You can also just document.write the style in via JS as well.

I wanted to let you know of this method, because it's a lot more convenient for defining commands ; you don't have to mess with HTML strings so it's easier to read and define functions. Wink

P.S.
What would make this even better is if it automatically submitted the post when you clicked the button. Think of it as a coding challenge I bestow upon any of you willing to take it on. Shifty

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Re: Add a "Bump" button for the Sceditor

Post by YoshiGM on October 12th 2016, 6:07 pm

Oh.. I no had idea of that information about the Sceditor
I'm still a bit of a novice with jQuery but thank you for your suggestion.
Regards!

YoshiGM
Forumember

Male Posts : 533
Reputation : 80
Language : Spanish & English
Location : Mexico

http://asistencia.foroactivo.com/u21373

Back to top Go down

Re: Add a "Bump" button for the Sceditor

Post by Ace 1 on October 20th 2016, 7:10 pm

@Ange Tuteur

Code:
$(function() {
 
  // check if $.sceditor and toolbar are defined
  if ($.sceditor && window.toolbar) {
 
    // function to execute when button is clicked
    var exec = function () {
      this.insertText('Bump');

      // submit post
      document.forms.post.post.click();
    };
 
    // set SCEditor command
    $.sceditor.command.set('bump', {
      tooltip : 'Bump',
 
      exec : exec, // WYSIWYG mode
      txtExec : exec // Source mode
    });
 
    // add button to the editor toolbar
    toolbar = toolbar.replace(/fahide/, 'fahide,bump');

    $('head').append('<style type="text/css">' +
        '.sceditor-button-bump div {' +
            'background-image:url(http://i97.servimg.com/u/f97/13/45/80/80/new-go10.png) !important;' +
        '}' +
    '</style>');
  }
 
});

@YoshiGM You can change the
Code:
this.insertText('Bump');
to
Code:
this.val('Bump');
if you want them to only post the word Bump and nothing else.

Ace 1
Helper
Helper

Male Posts : 767
Reputation : 51
Language : English - French?
Location : Druid Hill Park

http://help.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


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