proposed getSelectedContent() additon to plgEditorXXX class

17 views
Skip to first unread message

pollen8

unread,
Nov 16, 2009, 3:53:43 PM11/16/09
to Joomla! CMS Development
Hey All

I'm wondering if you would consider this proposal to add a
getSelectedContent() method to each of the plgEditor classes
(plgEditorTinymce, plgEditorTinymce etc)

I came across the need for this when writing an editor-xtd button to
load up a Fabrik form, and I think its something that a lot of plugin
devs would find useful.

Here's some background to what I was trying to achieve:
When you press the fabrik xtd button, If no selection is made in the
wysiwyg editor, then the iframe window opens allowing the user to add
a new record via a fabrik form. The iframe window closes and a
reference to the form is inserted into the Joomla article:

{fabrik view=form id=70 rowid=5 layout=bluesky}

What I wanted to be able to do was:
In the wysiwyg editor, select that inserted fabrik reference and
reload the record (from rowid=5) in the iframe.


Proposed changes:

libraries/joomla/html/editor.php add:

[code]
/**
* Get the editor's selected content
*
* @param string The name of the editor control
*/
public function getSelectedContent($editor)
{
$this->_loadEditor();

$args['name'] = $editor;
$args['event'] = 'onGetSelectedContent';

$return = '';
$results[] = $this->_editor->update($args);
foreach ($results as $result) {
if (trim($result)) {
$return .= $result;
}
}
return $return;
}
[/code]

In each of the standard editor's add the onGetSelectedContent()
method , e.,g. for tinymce edit plugins/editors/tinymce.php

[code]
function onGetSelectedContent( $editor ) {
return "function(){return tinyMCE.activeEditor.selection.getContent
();}";
}
[/code]

in plugins/editors/none.php

[code]
function onGetSelectedContent( $editor ) {
return "function(){
if(window.ie)
{
var content=document.getElementById('$editor');
content.focus();
var selection=document.selection.createRange();
var str=selection.text;
}else{
var content=document.getElementById('$editor');
var str=content.getValue().substring(content.selectionStart,
content.selectionEnd);
}
return str;
}";
}
[/code]

(Sorry I dont know anything about the codemirror editor plugin)

Here's the final code for my plugin the intresting part is this:

var fn = " . $this->_subject->getSelectedContent($name) . ";
var c = fn();

which is where we load in the editors js code as an anonymous function
and call that to get the selected content.
Afterwards I parse that selected text and populate the pop ups
querystring with any of the found variables.

[code]
function onDisplay($name)
{
$app =& JFactory::getApplication();
$db = JFactory::getDBO();

$doc =& JFactory::getDocument();
$template = $app->getTemplate();
$id = JRequest::getVar('cid');
if (is_array($id)){
$id = $id[0];
}
$section = JRequest::getInt('section', JRequest::getInt
('sectionid'));
$db->setQuery("select catid from #__content where id = $id");
$catid = $db->loadResult();

$link = 'index.php?
option=com_fabrik&c=form&task=cck&tmpl=component&e_name='.
$name.'&catid='.$catid.'&section='.$section;

JHTML::_('behavior.modal');

$doc->addStyleDeclaration(
".button2-left .fabrik{
background:transparent url(../administrator/components/com_fabrik/
images/j_button2_fabrik.png) no-repeat right top;
}"
);
$doc->addScriptDeclaration("
function getESelection(){
//var ed = tinyMCE.activeEditor;
//var c = ed.selection.getContent();

var fn = " . $this->_subject->getSelectedContent($name) . ";
var c = fn();
c = \$A(c.split(' '));
document.getElement('a[title=Fabrik]').href = '$link';
c.each(function(pair){
var bits = pair.split('=');
switch(bits[0]){
case 'rowid':
document.getElement('a[title=Fabrik]').href += '&' + bits[0] +
'=' +bits[1].replace('}', '');
break;
case 'layout':
case 'view':
document.getElement('a[title=Fabrik]').href += '&cck_' + bits[0]
+ '=' +bits[1].replace('}', '');
break;
}
});
}
");

$button = new JObject();
$button->set( 'modal', true );
$button->set('onclick', 'getESelection();');
$button->set( 'link', $link );
$button->set( 'text', JText::_( 'Fabrik' ) );
$button->set( 'name', 'fabrik' );
$button->set( 'options', "{handler: 'iframe', size: {x: 570, y:
400}}" );

return $button;
}

Andrew Eddie

unread,
Nov 16, 2009, 4:49:13 PM11/16/09
to joomla-...@googlegroups.com
Hey.

Could you make that into a SVN diff patch and put it on the 1.6 feature tracker?
http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemBrowse&tracker_id=8549

That will just make is easier to process. Sounds like a reasonable idea though.

Regards,
Andrew Eddie
http://www.theartofjoomla.com - the art of becoming a Joomla developer




2009/11/17 pollen8 <r...@pollen-8.co.uk>:
Reply all
Reply to author
Forward
0 new messages