News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Problems inserting text into post using my mod....

Started by dougiefresh, April 06, 2015, 09:13:33 AM

Previous topic - Next topic

dougiefresh

I've updated my Post and PM Inline Attachments mod for SMF 2.1 Beta 1, however, I can't seem to get the mod to insert the "[attachment=x][/attachment]" text into the post.  This is my "onclick" statement that works in in SMF 2.0.x line, without the SCeditor mod installed:
onclick="replaceText(\'[attachment=', (empty($context['current_attachments']) ? 0 : count($context['current_attachments'])) ,'][/attachment]\', document.forms.postmodify.', $context['post_box_name'], '); return false;"

Can anyone help me modify this line so that it works with SMF 2.1 Beta 1 and/or SMF 2.0 with SCeditor installed?  With SMF 2.0, it's likely to need a helper function written in order to work with both SMF 2.0 with and without SCeditor installed....

Thanks in advance!!!


margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Suki

Inserting text to the editor is somehow easy, it all depends on having the right js vars, if this is for SMf 2.1 then take a look at how partial quotes are been inserted:  https://github.com/SimpleMachines/SMF2.1/blob/release-2.1/Themes/default/scripts/quotedText.js#L59

oEditorID is just the editor ID which is defined somewhere in Display.php and can be used by mods to reference the current editor instance.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

dougiefresh

Quote from: margarett on April 15, 2015, 02:12:30 PM
* margarett VS JavaScript: 0 - 231
;D
Same problem here....  I'm getting better at it little by little....

Quote from: Suki on April 15, 2015, 07:49:46 PM
Inserting text to the editor is somehow easy, it all depends on having the right js vars, if this is for SMf 2.1 then take a look at how partial quotes are been inserted:  https://github.com/SimpleMachines/SMF2.1/blob/release-2.1/Themes/default/scripts/quotedText.js#L59

oEditorID is just the editor ID which is defined somewhere in Display.php and can be used by mods to reference the current editor instance.
I found the right variable.  This is what I'm using to insert the attachment tag:
$(\'#', $context['post_box_name'], '\').data(\'sceditor\').InsertText(\'[attachment=\' + id + \']\');
My only problem with it is that regardless of where the cursor is, the new text is ALWAYS placed at the end.  Any suggestions?

BTW, I've built a helper function for SMF 2.0.  It looks like this:
function insertAttachment(id)
{
if ($.sceditor == \'undefined\')
replaceText(\'[attachment=\' + id + \']\', document.forms.postmodify.', $context['post_box_name'], ');
else
$(\'#', $context['post_box_name'], '\').data(\'sceditor\').InsertText(\'[attachment=\' + id + \']\');
}

It works without SCEditor installed, however, I'm having difficulty figuring out what the variable is for the SCEditor in SMF 2.0.  Any thoughts?  Thanks in advance...

dougiefresh

Quote from: dougiefresh on May 01, 2015, 08:55:12 AM
I found the right variable.  This is what I'm using to insert the attachment tag:
$(\'#', $context['post_box_name'], '\').data(\'sceditor\').InsertText(\'[attachment=\' + id + \']\');
My only problem with it is that regardless of where the cursor is, the new text is ALWAYS placed at the end.  Any suggestions?
I managed to fix this problem by changing the line to this:
$(\'#', $context['post_box_name'], '\').data(\'sceditor\').sourceEditorInsertText(\'[attachment=\' + id + \']\', 0);

Quote from: dougiefresh on May 01, 2015, 08:55:12 AM
BTW, I've built a helper function for SMF 2.0.  It looks like this:
function insertAttachment(id)
{
if ($.sceditor == \'undefined\')
replaceText(\'[attachment=\' + id + \']\', document.forms.postmodify.', $context['post_box_name'], ');
else
$(\'#', $context['post_box_name'], '\').data(\'sceditor\').InsertText(\'[attachment=\' + id + \']\');
}

It works without SCEditor installed, however, I'm having difficulty figuring out what the variable is for the SCEditor in SMF 2.0.  Any thoughts?  Thanks in advance...
No progress here....

Suki

There is no SCEditor var for SMF 2.0 as SMF 2.0 doesn't use SCEditor editor.

I believe you are talking about the mod that ports that editor to 2.0, in that case just review its code, it has to be pretty similar to what 2.1 does.

You can always build such var yourself, if there is no real reference (an actual JS var) you can make one for your mod and use that, thats what I did for partial quotes.

Yep, I should probably change that insertText to sourceEditorInsertText  I just didn't thought it will be an issues but it seems there is going to be some complains so better change it now.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

dougiefresh

Quote from: Suki on May 01, 2015, 12:42:17 PM
There is no SCEditor var for SMF 2.0 as SMF 2.0 doesn't use SCEditor editor.
Never meant to imply that SMF 2.0.x had SCEditor built-in...

Quote from: Suki on May 01, 2015, 12:42:17 PM
I believe you are talking about the mod that ports that editor to 2.0,
Yup yup

Quote from: Suki on May 01, 2015, 12:42:17 PM
in that case just review its code, it has to be pretty similar to what 2.1 does.

You can always build such var yourself, if there is no real reference (an actual JS var) you can make one for your mod and use that, thats what I did for partial quotes.
I tried using the same code for the SCEditor mod for SMF 2.0 as what works for SMF 2.1, but it just doesn't work....  I'm not sure how I should be referring to the class/object/whatever properly....  Hence the need to ask for assistance...

Suki

Subs-SCEditor::331


$context['html_headers'] .= '
var options = getEditorOptions();
'.$sceditor->qrtabindex.'
$(smfmod_editor).sceditorBBCodePlugin(options);
'.($sceditor->emotion == 0?'':'
$(smfmod_editor).data("sceditor").createPermanentDropDown();').'
$(".sceditor-container").height("100%");
$(".sceditor-container").width("100%");
'.$sceditor->advancedEnabled.'
if (!(is_ie || is_ff || is_opera || is_safari || is_chrome)) {
$(smfmod_editor).data("sceditor").setTextMode();
$(".sceditor-button-source").hide();
}
});
// ]]></script>';


smfmod_editor is the var that references the current editor, that mod is using a hook and $context['html_headers'] to add its JS so you need to be absolutely sure your function is called after this mod's function otherwise that var won't be set by the time you use it.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

dougiefresh

I even tried that one, but it turns out that the function itself wasn't right because the code wouldn't execute without the SCEditor mod installed either.   :o

So here is what I did:

function insertAttachment(id)
{', (file_exists($sourcedir . '/Subs-SCEditor.php') ? '
$(smfmod_editor).data(\'sceditor\').insertText(\'[attachment=\' + id + \']\');' : '
replaceText(\'[attachment=\' + id + \']\', document.forms.postmodify.' . $context['post_box_name'] . ');'), '
}

This works for both with and without SCEditor installed. 

Thanks very much for helping me out with this!

Advertisement: