Jump to content


- - - - -

Snippets In The Content Editor


  • You cannot reply to this topic
5 replies to this topic

#1 arabdev

    Etomite Forum Newbie

  • Member
  • 5 posts

Posted 03 April 2005 - 09:43 AM

hi

i just worked on Etomite for a couple of weeks only i found that i need a drop down list in the document editor that from this list i can select the snippets that i want to insert it into the document it works for chunk to

so i did this section and here is the code
after the selection of the content Type list add this lines in mutate_content.dynamic.action.php
-------------------------------------------------------------------------------------
<TR>
<TD class='warning'><?=$_lang['insert_snippet'];?></TD>
<TD>
<select size=1 name="contentsnippet" class="inputBox" onChange='documentDirty=true;InsertSnippet(this)' style="width:150px">
    <option value=""> - </option>
<?php
	$sqlsnippets = "select name from $dbase.".$table_prefix."site_snippets ";
	$rssnippets = mysql_query($sqlsnippets);
	while ($rowsnippets = mysql_fetch_assoc($rssnippets))
  {
  ?><option value="[[<?=$rowsnippets['name']?>]]"><?=$rowsnippets['name']?></option><?
  }
?>
</select>
&nbsp;&nbsp;<img src="media/images/icons/b02_trans.gif" onMouseover="this.src='media/images/icons/b02.gif';" onMouseout="this.src='media/images/icons/b02_trans.gif';" alt="<?=$_lang['insert_snippet_help']; ?>" onClick="alert(this.alt);" style="cursor:help;">
<script>
function InsertSnippet(selected1)
{
	SnippetName=selected1.options[selected1.selectedIndex].value;
	if (document.selection) {
          if(typeof(editor)!="undefined")
                   {
                   editor.insertHTML(SnippetName)
                   }
          else
                   {
                   mutate.ta.focus();
                   sel = document.selection.createRange();
                   sel.text = SnippetName;
                   }
	}
}
</script>
</TD>
</TR>
-------------------------------------------------------------------------------------


:betterwink:

#2 Dean

    Loves Etomite Forums!

  • Admin
  • 4,758 posts
  • Gender:Male

Posted 30 April 2005 - 12:20 PM

Hiya - where exactly does this fit in the file (I can't find it in the file) :blink:

#3 arabdev

    Etomite Forum Newbie

  • Member
  • 5 posts

Posted 30 April 2005 - 01:17 PM

Dean, on Apr 30 2005, 04:20 PM, said:

Hiya - where exactly does this fit in the file (I can't find it in the file)  :blink:


it should be after these lines

<input type="hidden" name="richtext" value="0" />
<input type="hidden" name="type" value="reference" />
<?php } ?>

#4 c@csvp

    Etomite Forum Newbie

  • Member
  • 5 posts

Posted 12 May 2005 - 02:59 AM

Sounds interesting, so I added the code to my file.. I don't see anything different in the editor. How is this supposed to work?

Thanks for your help, it would be a great feature to have.

#5 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 12 May 2005 - 03:57 AM

I installed the code and have the drop-down but it doesn't really do anything... It gives me a list of snippets but selecting one doesn't place it in my document... Are you sure that you placed this code in manager/actions/dynamic/mutate_content.dynamic.action.php...:?: I'll check the code out more tomorrow... B)

#6 fetchall

    Etomite Forum Newbie

  • Member
  • 17 posts

Posted 28 July 2005 - 01:16 AM

Same here. Installed the code but selecting a snippet doesn't add anything in the editor. I did get it to work in a fashion with the HTMLArea editor in 0.6.1RC1. Here's the code I added to mutate_content.dynamic.action.php (approx. line 540, directly after
elseif($which_editor==2) {
  ?>

This is virtually the same code except that I'm only loading snippets in the select box which are not locked. I've also retrieved the description which is used as a title attribute, thus popping up as a tooltip when you mouse over the snippets.

<table>
<TR>
<TD class='warning'><?=$_lang['insert_snippet'];?></TD>
<TD>
<select size=1 name="contentsnippet" class="inputBox" onChange='documentDirty=true;InsertSnippet(this)' style="width:150px">
   <option value=""> - </option>
<?php
$sqlsnippets = "select name,description from $dbase.".$table_prefix."site_snippets WHERE locked=0 ";
$rssnippets = mysql_query($sqlsnippets);
while ($rowsnippets = mysql_fetch_assoc($rssnippets))
 {
 ?><option value="[[<?=$rowsnippets['name']?>]]" title="<?=$rowsnippets['description']?>"><?=$rowsnippets['name']?></option><?
 }
?>
</select>
&nbsp;&nbsp;<img src="media/images/icons/b02_trans.gif" onMouseover="this.src='media/images/icons/b02.gif';" onMouseout="this.src='media/images/icons/b02_trans.gif';" alt="<?=$_lang['insert_snippet_help']; ?>" onClick="alert(this.alt);" style="cursor:help;">
<script>
function InsertSnippet(selected1)
{
SnippetName = selected1.options[selected1.selectedIndex].value;
if(editor){ editor.insertHTML(SnippetName) };
}
</script>
</TD>
</TR>    
</table>

To make it work in HTMLArea I've replaced the insertSnippet() javascript function which now makes a HTMLArea API call to insert the snippet into the content. This is still not ideal because it doesn't become part of HTMLArea's undo list. I don't know HTMLArea well enough yet to fix this. Ideally though, the selectbox should be part of the editor's toolbar instead of being separated.

Anyway, if you're using HTMLArea at least here's some kind of solution for you.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users