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 12 users online :: 0 Registered, 0 Hidden and 12 Guests :: 1 Bot

None

[ View the whole list ]


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

[SOLVED] Javascript question

View previous topic View next topic Go down

Wolfuryo
Wolfuryo

Gender : Male
Posts : 256
Points : 3598
Reputation : 81
Language : Romanian and English
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : Other

PostWolfuryo Wed 20 Apr 2016, 12:54

Hello, everyone!

I made a little code that adds a button in the editor which once clicked will add some text in the editor according to what forum you are making a topic in. The code is:
Code:
$(function(){
$(function(){
var f='No predefinited model';
    if (location.pathname == "/post" && location.search == "?f=2&mode=newtopic") {
var f='Predefinited model';
    }
 $('<a class="sceditor-button" unselectable="on" title="Insert predefinited model">
 <div unselectable="on" style="background:url(http://i1370.photobucket.com/albums/ag257/AppleDrink/attention-sign%201.png)"></div>
 </a>').insertBefore('.sceditor-button-size').click(function(){
 $('#text_editor_textarea').sceditor("instance").insertText(f)})
 });
})

I want to add a line brake between Predefinited and model(look and the variable f). I tried using
Code:
<br>
and
Code:
[br]
, but it is not working.
Ange Tuteur
Ange Tuteur
Administrator
Gender : Male
Posts : 4741
Points : 12044
Reputation : 2375
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 Wed 20 Apr 2016, 13:16

Hey,

To insert a line break in a string use the "\n" character. Like this for example :
Code:
var string = 'Hello\nworld\n!';

Also, you should try using
Code:
$.sceditor.command.set
to define new buttons. Here's an example :
Code:
location.search == "?f=2&mode=newtopic" && $(function() {
  // TEXT TO INSERT
  window.scePredefinitedModel = ['[b]EXAMPLE', '[/b]\n\n[i]EXAMPLE 2[/i]'];

  if ($.sceditor) {
    // SET THE NEW SCEDITOR COMMAND
    $.sceditor.command.set('predefinited-model', {

      // WYSIWYG METHOD
      exec : function() {
        this.insert(scePredefinitedModel[0], scePredefinitedModel[1]);
      },
 
      // SOURCE CODE METHOD
      txtExec : function() {
        this.insert(scePredefinitedModel[0], scePredefinitedModel[1]);
      },
 
      tooltip : 'Insert predefinited model' // BUTTON TOOLTIP
    });
 
    toolbar = toolbar.replace(/code/, 'code,predefinited-model'); // INSERT BUTTON INTO TOOLBAR
  }
});

// BUTTON IMAGE
document.write('<style type="text/css">.sceditor-button-predefinited-model div{background-image:url(http://i1370.photobucket.com/albums/ag257/AppleDrink/attention-sign%201.png)!important}</style>');

There's a bunch of docs on it here if you're interested. Wink
Wolfuryo
Wolfuryo

Gender : Male
Posts : 256
Points : 3598
Reputation : 81
Language : Romanian and English
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : Other

PostWolfuryo Wed 20 Apr 2016, 14:17

Thank you, sloved it now. I found the link you posted usefull(http://www.sceditor.com/documentation/getting-started/).
Wolfuryo
Wolfuryo

Gender : Male
Posts : 256
Points : 3598
Reputation : 81
Language : Romanian and English
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : Other

PostWolfuryo Wed 20 Apr 2016, 14:35

Ange Tuteur wrote:
Code:
location.search == "?f=2&mode=newtopic" && $(function() {
  // TEXT TO INSERT
  window.scePredefinitedModel = ['[b]EXAMPLE', '[/b]\n\n[i]EXAMPLE 2[/i]'];

  if ($.sceditor) {
    // SET THE NEW SCEDITOR COMMAND
    $.sceditor.command.set('predefinited-model', {

      // WYSIWYG METHOD
      exec : function() {
        this.insert(scePredefinitedModel[0], scePredefinitedModel[1]);
      },
  
      // SOURCE CODE METHOD
      txtExec : function() {
        this.insert(scePredefinitedModel[0], scePredefinitedModel[1]);
      },
  
      tooltip : 'Insert predefinited model' // BUTTON TOOLTIP
    });
  
    toolbar = toolbar.replace(/code/, 'code,predefinited-model'); // INSERT BUTTON INTO TOOLBAR
  }
});

// BUTTON IMAGE
document.write('<style type="text/css">.sceditor-button-predefinited-model div{background-image:url(http://i1370.photobucket.com/albums/ag257/AppleDrink/attention-sign%201.png)!important}</style>');
I think you forget the
Code:
if
. Razz
Ange Tuteur
Ange Tuteur
Administrator
Gender : Male
Posts : 4741
Points : 12044
Reputation : 2375
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 Wed 20 Apr 2016, 15:40

Andrei34 wrote:Thank you, sloved it now. I found the link you posted usefull(http://www.sceditor.com/documentation/getting-started/).
No problem. Wink

Andrei34 wrote:I think you forget the
Code:
if
. Razz
Oh, are you talking about this ?
Code:
location.search == "?f=2&mode=newtopic" &&

If
Code:
location.search == "?f=2&mode=newtopic"
evaluates to true it'll execute the function after
Code:
&&
. For example, if the condition evaluates to true it moves onto the next statement, however, if it evaluates to false it doesn't move onto the next statement :
[SOLVED] Javascript question Captur45


It's more of a shorthand condition like :
Code:
_userdata.user_level ? 'Staff' : 'Member';
Which when executed in the console will return either 'Staff' or 'Member' depending on what your permission level is.
[SOLVED] Javascript question Captur44

The equivalent is :
Code:
if (_userdata.user_level) {
  'Staff';
} else {
  'Member';
}

This has some shorthand examples too :
http://www.sitepoint.com/shorthand-javascript-techniques/

They're useful, however sometimes it's best to stick with the good old if .. else because they're easier to read. Wink
Wolfuryo
Wolfuryo

Gender : Male
Posts : 256
Points : 3598
Reputation : 81
Language : Romanian and English
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : Other

PostWolfuryo Thu 21 Apr 2016, 04:48

OK. Thank you for answering my questions. Smile
Sponsored content

PostSponsored content

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