Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to insert text outside the editor? #70

Closed
LiamDawe opened this issue Jan 17, 2013 · 23 comments
Closed

How to insert text outside the editor? #70

LiamDawe opened this issue Jan 17, 2013 · 23 comments
Labels

Comments

@LiamDawe
Copy link

Say I want to have a button on comments on my website saying "Quote" and if someone presses it, it then inserts the text from that comment wrapped in quotes tags into the editor, is that easily possible?

@samclarke
Copy link
Owner

Yes, you can use the insert() method to insert BBCode into the editor (assuming you're using the BBCode plugin)

$('textarea').sceditor('instance').insert("[quote=admin]Some text[/quote]");

@LiamDawe
Copy link
Author

That code there how would i place that into a hyperlink? Many thanks! (yeah this is bbcode plugin)

@samclarke
Copy link
Owner

You could do something like this:

<script>
$(function(){
    $('#quote').click(function() {
        $('textarea').sceditor('instance').insert("[quote=admin]Some text[/quote]");
    });
});
</script>

<a id="quote" href="#">Insert Quote</a>

or this:

<script>
function insert_quote()
{
    $('textarea').sceditor('instance').insert("[quote=admin]Some text[/quote]");
}
</script>

<a href="javascript:insert_quote()">Insert Quote</a>

@LiamDawe
Copy link
Author

Right I will have a go at that, many thanks! I think this will totally replace tinymce for me, once you get it installed it works so much better!

@LiamDawe
Copy link
Author

Hmm testing it, neither of them seem to work? Any idea what I could have missed to make it out right not work?

@samclarke
Copy link
Owner

Is textarea selector in $('textarea') the same selector you used to create the editor?

e.g. did you do:

$('textarea').sceditor({
    /* opts */
});

to create it? If not it needs to be set to the same jQuery selector that was used to create the editor.

@LiamDawe
Copy link
Author

Yeah i didn't change the name and the page im testing on has only one textarea.

Here is how i am including it:

jQuery(document).ready(function($){
$('textarea').sceditor({
plugins: 'bbcode',
autoExpand: true,
toolbar: "bold,italic,underline,quote|link,unlink|youtube,emoticon|source",
style: "/jscripts/sce/themes/jquery.sceditor.default.min.css"
}).change(function(e){
var $this = $(this),
$preview = $this.siblings('#preview');

    });

});
</script>

@samclarke
Copy link
Owner

I'm not too sure what's causing the problem.

I've uploaded a demo here the source is here.

@LiamDawe
Copy link
Author

Hmm i don't see anything different, see here: http://www.prxa.info/forum/topic/291 that is my test website for my main one. I put a quick quote link in the top part but it doesn't work.

@LiamDawe
Copy link
Author

Hmmm you included yours inside the "$(document).ready(function() {}" does it have to be inside one of those to work?

@LiamDawe
Copy link
Author

Hah that got it!

@brunoais
Copy link
Collaborator

if you have this:

jQuery.noConflict(); //disable global $ for jQuery

then you may not use:
$

you must use:

jQuery

@samclarke
Copy link
Owner

It's because jQuery is in no conflict mode. Try this:

<script type="text/javascript">
jQuery(function($){
    $('#quote').click(function() {
        $('textarea').sceditor('instance').insert("[quote=admin]Some text[/quote]");
    });
});
</script>

@LiamDawe
Copy link
Author

Infact i just put in this:

<script type="text/javascript">
jQuery.noConflict(); //disable global $ for jQuery
jQuery(document).ready(function($){
    $(function(){
    $('#quote').click(function() {
        $('textarea').sceditor('instance').insert("[quote=admin]Some text[/quote]");
    });
    });
});
</script>

And now it works.

Only thing is i would need to have that code before every post to have the quote updated, is there a way to have it dynamically get the text some how?

@brunoais
Copy link
Collaborator

Anyway I cry a lot seeing jQuery being used like that...
I'll just accept it... no use crying at spoiled milk...

@brunoais
Copy link
Collaborator

Use ajax. I'd tell you the proper way but I know some1 will come here with another solution and you won't use mine... Just check how to use ajax...

@LiamDawe
Copy link
Author

I don't know any javascript/ajax hence me coming here asking for help.

@brunoais
Copy link
Collaborator

you wouldn't build a chair if you didn't know how to build it, right?
go here:
http://www.codecademy.com/

It will get you started on js. It has loads of stuff for you to learn, try and get used to how js works.

@LiamDawe
Copy link
Author

If i had the time to learn another language i would but i don't im on a small timescale here.

@brunoais
Copy link
Collaborator

In that case, you are in deep trouble. You spend more time asking for help all the time and just using pieces of code like they were just some sacred stuff that may not be changed than what you'd spend if you just learned enough to understand it and then do it yourself.

@LiamDawe
Copy link
Author

I learn by tinkering not but reading or going through big tutorials. I learn by doing it. I am not here for a lecture if you aren't going to help please stop replying, thank you.

@samclarke
Copy link
Owner

@LiamDawe If you still need help with this send me an e-mail to sam@samclarke.com and I'll try help.

@LiamDawe
Copy link
Author

Thanks but one of my readers actually came up with a way to do it, thank you anyway! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants