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

Allow multiple (different) editors in one page #12561

Merged
merged 23 commits into from Feb 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -23,14 +23,25 @@
JHtml::_('behavior.core');
JHtml::_('bootstrap.tooltip', '.hasTooltip', array('placement' => 'bottom'));
JHtml::_('formbehavior.chosen', 'select');
JHtml::_('behavior.polyfill', array('event'), 'lt IE 9');
JHtml::_('script', 'com_contact/admin-contacts-modal.min.js', array('version' => 'auto', 'relative' => true));

// Special case for the search field tooltip.
$searchFilterDesc = $this->filterForm->getFieldAttribute('search', 'description', null, 'filter');
JHtml::_('bootstrap.tooltip', '#filter_search', array('title' => JText::_($searchFilterDesc), 'placement' => 'bottom'));

$function = $app->input->getCmd('function', 'jSelectContact');
$editor = $app->input->getCmd('editor', '');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$onclick = $this->escape($function);

if (!empty($editor))
{
// This view is used also in com_menus. Load the xtd script only if the editor is set!
JFactory::getDocument()->addScriptOptions('xtd-contacts', array('editor' => $editor));
$onclick = "jSelectContact";
}
?>
<div class="container-popup">

Expand Down Expand Up @@ -108,7 +119,9 @@
<span class="<?php echo $iconStates[$this->escape($item->published)]; ?>"></span>
</td>
<td>
<a href="javascript:void(0);" onclick="if (window.parent) window.parent.<?php echo $this->escape($function); ?>('<?php echo $item->id; ?>', '<?php echo $this->escape(addslashes($item->name)); ?>', '<?php echo $this->escape($item->catid); ?>', null, '<?php echo $this->escape(ContactHelperRoute::getContactRoute($item->id, $item->catid, $item->language)); ?>', '<?php echo $this->escape($lang); ?>', null);">
<a class="select-link" href="javascript:void(0)" data-function="<?php echo $this->escape($onclick); ?>" data-id="<?php echo $item->id; ?>" data-title="<?php echo $this->escape(addslashes($item->name)); ?>" data-uri="<?php echo $this->escape(ContactHelperRoute::getContactRoute($item->id, $item->catid, $item->language)); ?>" data-language="<?php echo $this->escape($lang); ?>">
<?php echo $this->escape($item->name); ?>
</a>
<?php echo $this->escape($item->name); ?></a>
<div class="small">
<?php echo JText::_('JCATEGORY') . ': ' . $this->escape($item->category_title); ?>
Expand Down
Expand Up @@ -71,7 +71,7 @@
' . $this->form->getField('articletext')->save() . '
Joomla.submitform(task, document.getElementById("item-form"));

// @deprecated 4.0 The following js is not needed since 3.7.0.
// @deprecated 4.0 The following js is not needed since __DEPLOY_VERSION__.
if (task !== "article.apply")
{
window.parent.jQuery("#articleEdit' . (int) $this->item->id . 'Modal").modal("hide");
Expand Down
Expand Up @@ -9,27 +9,15 @@

defined('_JEXEC') or die;

$script = 'function insertPagebreak() {' . "\n\t";

// Get the pagebreak title
$script .= 'var title = document.getElementById("title").value;' . "\n\t";
$script .= 'if (title != \'\') {' . "\n\t\t";
$script .= 'title = "title=\""+title+"\" ";' . "\n\t";
$script .= '}' . "\n\t";

// Get the pagebreak toc alias -- not inserting for now
// don't know which attribute to use...
$script .= 'var alt = document.getElementById("alt").value;' . "\n\t";
$script .= 'if (alt != \'\') {' . "\n\t\t";
$script .= 'alt = "alt=\""+alt+"\" ";' . "\n\t";
$script .= '}' . "\n\t";
$script .= 'var tag = "<hr class=\"system-pagebreak\" "+title+" "+alt+"/>";' . "\n\t";
$script .= 'window.parent.jInsertEditorText(tag, ' . json_encode($this->eName) . ');' . "\n\t";
$script .= 'window.parent.jModalClose();' . "\n\t";
$script .= 'return false;' . "\n";
$script .= '}' . "\n";

JFactory::getDocument()->addScriptDeclaration($script);
JHtml::_('behavior.core');
JHtml::_('behavior.polyfill', array('event'), 'lt IE 9');
JHtml::_('script', 'com_content/admin-article-pagebreak.min.js', array('version' => 'auto', 'relative' => true));

$document = JFactory::getDocument();
$this->eName = JFactory::getApplication()->input->getCmd('e_name', '');
$this->eName = preg_replace('#[^A-Z0-9\-\_\[\]]#i', '', $this->eName);

$document->setTitle(JText::_('COM_CONTENT_PAGEBREAK_DOC_TITLE'));
?>
<div class="container-popup">
<form class="form-horizontal">
Expand All @@ -44,7 +32,9 @@
<div class="controls"><input type="text" id="alt" name="alt" /></div>
</div>

<button onclick="insertPagebreak();" class="btn btn-primary"><?php echo JText::_('COM_CONTENT_PAGEBREAK_INSERT_BUTTON'); ?></button>
<button onclick="insertPagebreak('<?php echo $this->eName; ?>');" class="btn btn-success pull-right">
<?php echo JText::_('COM_CONTENT_PAGEBREAK_INSERT_BUTTON'); ?>
</button>

</form>
</div>
Expand Up @@ -57,11 +57,6 @@ public function display($tpl = null)
{
if ($this->getLayout() == 'pagebreak')
{
// TODO: This is really dogy - should change this one day.
$eName = JFactory::getApplication()->input->getCmd('e_name');
$eName = preg_replace('#[^A-Z0-9\-\_\[\]]#i', '', $eName);
$this->document->setTitle(JText::_('COM_CONTENT_PAGEBREAK_DOC_TITLE'));
$this->eName = &$eName;

return parent::display($tpl);
}
Expand Down
25 changes: 22 additions & 3 deletions administrator/components/com_content/views/articles/tmpl/modal.php
Expand Up @@ -22,6 +22,8 @@
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');

JHtml::_('behavior.core');
JHtml::_('behavior.polyfill', array('event'), 'lt IE 9');
JHtml::_('script', 'com_content/admin-articles-modal.min.js', array('version' => 'auto', 'relative' => true));
JHtml::_('bootstrap.tooltip', '.hasTooltip', array('placement' => 'bottom'));
JHtml::_('formbehavior.chosen', 'select');

Expand All @@ -30,12 +32,21 @@
JHtml::_('bootstrap.tooltip', '#filter_search', array('title' => JText::_($searchFilterDesc), 'placement' => 'bottom'));

$function = $app->input->getCmd('function', 'jSelectArticle');
$editor = $app->input->getCmd('editor', '');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$onclick = $this->escape($function);

if (!empty($editor))
{
// This view is used also in com_menus. Load the xtd script only if the editor is set!
JFactory::getDocument()->addScriptOptions('xtd-articles', array('editor' => $editor));
$onclick = "jSelectArticle";
}
?>
<div class="container-popup">

<form action="<?php echo JRoute::_('index.php?option=com_content&view=articles&layout=modal&tmpl=component&function=' . $function . '&' . JSession::getFormToken() . '=1'); ?>" method="post" name="adminForm" id="adminForm" class="form-inline">
<form action="<?php echo JRoute::_('index.php?option=com_content&view=articles&layout=modal&tmpl=component&function=' . $function . '&' . JSession::getFormToken() . '=1&editor=' . $editor); ?>" method="post" name="adminForm" id="adminForm" class="form-inline">

<?php echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?>

Expand Down Expand Up @@ -111,8 +122,16 @@
<span class="<?php echo $iconStates[$this->escape($item->state)]; ?>"></span>
</td>
<td>
<a href="javascript:void(0);" onclick="if (window.parent) window.parent.<?php echo $this->escape($function); ?>('<?php echo $item->id; ?>', '<?php echo $this->escape(addslashes($item->title)); ?>', '<?php echo $this->escape($item->catid); ?>', null, '<?php echo $this->escape(ContentHelperRoute::getArticleRoute($item->id, $item->catid, $item->language)); ?>', '<?php echo $this->escape($lang); ?>', null);">
<?php echo $this->escape($item->title); ?></a>
<?php $attribs = 'data-function="' . $this->escape($onclick) . '"'
. ' data-id="' . $item->id . '"'
. ' data-title="' . $this->escape(addslashes($item->title)) . '"'
. ' data-cat-id="' . $this->escape($item->catid) . '"'
. ' data-uri="' . $this->escape(ContentHelperRoute::getArticleRoute($item->id, $item->catid, $item->language)) . '"'
. ' data-language="' . $this->escape($lang) . '"';
?>
<a class="select-link" href="javascript:void(0)" <?php echo $attribs; ?>>
<?php echo $this->escape($item->title); ?>
</a>
<div class="small">
<?php echo JText::_('JCATEGORY') . ': ' . $this->escape($item->category_title); ?>
</div>
Expand Down
29 changes: 12 additions & 17 deletions administrator/components/com_menus/views/items/tmpl/modal.php
Expand Up @@ -19,6 +19,8 @@
JHtml::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/helpers/html');

JHtml::_('behavior.core');
JHtml::_('behavior.polyfill', array('event'), 'lt IE 9');
JHtml::_('script', 'com_menus/admin-items-modal.min.js', array('version' => 'auto', 'relative' => true));
JHtml::_('bootstrap.tooltip', '.hasTooltip', array('placement' => 'bottom'));
JHtml::_('formbehavior.chosen', 'select');

Expand All @@ -27,19 +29,16 @@
JHtml::_('bootstrap.tooltip', '#filter_search', array('title' => JText::_($searchFilterDesc), 'placement' => 'bottom'));

$function = $app->input->get('function', 'jSelectMenuItem', 'cmd');
$editor = $app->input->getCmd('editor', '');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));

$app->getDocument()->addScriptDeclaration("
jQuery(document).ready(function($) {
$('body').on('click', '.select-link', function() {
// Run function on parent window.
if(self != top)
{
window.parent." . $function . "(this.getAttribute('data-id'), this.getAttribute('data-title'), null, null, this.getAttribute('data-uri'), this.getAttribute('data-language'), null);
}
});
});");
if (!empty($editor))
{
// This view is used also in com_menus. Load the xtd script only if the editor is set!
JFactory::getDocument()->addScriptOptions('xtd-menus', array('editor' => $editor));
$onclick = "jSelectMenuItem";
}
?>
<div class="container-popup">

Expand Down Expand Up @@ -111,13 +110,9 @@
<td>
<?php $prefix = JLayoutHelper::render('joomla.html.treeprefix', array('level' => $item->level)); ?>
<?php echo $prefix; ?>
<a class="select-link" href="javascript:void(0)"
data-function="<?php echo $this->escape($function); ?>"
data-id="<?php echo $item->id; ?>"
data-title="<?php echo $this->escape($item->title); ?>"
data-uri="<?php echo 'index.php?Itemid=' . $item->id; ?>"
data-language="<?php echo $this->escape($language); ?>">
<?php echo $this->escape($item->title); ?></a>
<a class="select-link" href="javascript:void(0)" data-function="<?php echo $this->escape($function); ?>" data-id="<?php echo $item->id; ?>" data-title="<?php echo $this->escape($item->title); ?>" data-uri="<?php echo 'index.php?Itemid=' . $item->id; ?>" data-language="<?php echo $this->escape($language); ?>">
<?php echo $this->escape($item->title); ?>
</a>
<span class="small">
<?php if (empty($item->note)) : ?>
<?php echo JText::sprintf('JGLOBAL_LIST_ALIAS', $this->escape($item->alias)); ?>
Expand Down
21 changes: 9 additions & 12 deletions administrator/components/com_modules/views/modules/tmpl/modal.php
Expand Up @@ -14,27 +14,22 @@
JSession::checkToken('get') or die(JText::_('JINVALID_TOKEN'));
}

// Load needed scripts
JHtml::_('behavior.core');
JHtml::_('bootstrap.tooltip', '.hasTooltip', array('placement' => 'bottom'));
JHtml::_('formbehavior.chosen', 'select');

// Scripts for the modules xtd-button
JHtml::_('behavior.polyfill', array('event'), 'lt IE 9');
JHtml::_('script', 'com_modules/admin-modules-modal.min.js', array('version' => 'auto', 'relative' => true));

// Special case for the search field tooltip.
$searchFilterDesc = $this->filterForm->getFieldAttribute('search', 'description', null, 'filter');
JHtml::_('bootstrap.tooltip', '#filter_search', array('title' => JText::_($searchFilterDesc), 'placement' => 'bottom'));

$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$editor = JFactory::getApplication()->input->get('editor', '', 'cmd');

JFactory::getDocument()->addScriptDeclaration('
moduleIns = function(type, name) {
window.parent.jInsertEditorText("{loadmodule " + type + "," + name + "}", "' . $editor . '");
window.parent.jModalClose();
};
modulePosIns = function(position) {
window.parent.jInsertEditorText("{loadposition " + position + "}", "' . $editor . '");
window.parent.jModalClose();
};');
?>
<div class="container-popup">

Expand Down Expand Up @@ -93,11 +88,13 @@
<span class="<?php echo $iconStates[$this->escape($item->published)]; ?>"></span>
</td>
<td class="has-context">
<a class="btn btn-small btn-block btn-success" href="#" onclick="moduleIns('<?php echo $this->escape($item->module); ?>', '<?php echo $this->escape($item->title); ?>');"><?php echo $this->escape($item->title); ?></a>
<a class="js-module-insert btn btn-small btn-block btn-success" href="#" data-module="<?php echo $this->escape($item->module); ?>" data-title="<?php echo $this->escape($item->title); ?>" data-editor="<?php echo $this->escape($editor); ?>">
<?php echo $this->escape($item->title); ?>
</a>
</td>
<td class="small hidden-phone">
<?php if ($item->position) : ?>
<a class="btn btn-small btn-block btn-warning" href="#" onclick="modulePosIns('<?php echo $this->escape($item->position); ?>');"><?php echo $this->escape($item->position); ?></a>
<a class="js-position-insert btn btn-small btn-block btn-warning" href="#" data-position="<?php echo $this->escape($item->position); ?>" data-editor="<?php echo $this->escape($editor); ?>"><?php echo $this->escape($item->position); ?></a>
<?php else : ?>
<span class="label"><?php echo JText::_('JNONE'); ?></span>
<?php endif; ?>
Expand Down
62 changes: 62 additions & 0 deletions media/com_contact/js/admin-contacts-modal.js
@@ -0,0 +1,62 @@
/**
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
(function() {
"use strict";
/**
* Javascript to insert the link
* View element calls jSelectContact when a contact is clicked
* jSelectContact creates the link tag, sends it to the editor,
* and closes the select frame.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it would be nice to have since tags in js too.. Any thoughts on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be a way, have to do some testing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yvesh so what is the @since supposed to be for all these scripts, because ok now they are static files but the code comes from way back?

*/

window.jSelectContact = function(id, title, catid, object, link, lang)
{
var hreflang = '', tag, editor;

if (!Joomla.getOptions('xtd-contacts')) {
// Something went wrong!
window.parent.jModalClose();
return false;
}

editor = Joomla.getOptions('xtd-contacts').editor;

if (lang !== '') {
hreflang = ' hreflang = "' + lang + '"';
}

tag = '<a' + hreflang + ' href="' + link + '">' + title + '</a>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally i would prefer when you do a document.createElement('a') here etc. then hardcoding a link into a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too fast, we do support IE8, so not possible

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm document.createElement should work in IE8?


/** Use the API, if editor supports it **/
if (window.Joomla && window.Joomla.editors && Joomla.editors.instances && Joomla.editors.instances.hasOwnProperty(editor)) {
Joomla.editors.instances[editor].replaceSelection(tag)
} else {
window.parent.jInsertEditorText(tag, editor);
}

window.parent.jModalClose();
};

document.addEventListener('DOMContentLoaded', function(){
// Get the elements
var elements = document.querySelectorAll('.select-link');

for(var i = 0, l = elements.length; l>i; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, why are you saving elements length in a variable? ;) cs btw.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need for speed 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

itar in phpstorm create those...

// Listen for click event
elements[i].addEventListener('click', function (event) {
event.preventDefault();
var functionName = event.target.getAttribute('data-function');

if (functionName === 'jSelectContact') {
// Used in xtd_contacts
window[functionName](event.target.getAttribute('data-id'), event.target.getAttribute('data-title'), null, null, event.target.getAttribute('data-uri'), event.target.getAttribute('data-language'), null);
} else {
// Used in com_menus
window.parent[functionName](event.target.getAttribute('data-id'), event.target.getAttribute('data-title'), null, null, event.target.getAttribute('data-uri'), event.target.getAttribute('data-language'), null);
}
})
}
});
})();
1 change: 1 addition & 0 deletions media/com_contact/js/admin-contacts-modal.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions media/com_content/js/admin-article-pagebreak.js
@@ -0,0 +1,37 @@
/**
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
(function() {
"use strict";

window.insertPagebreak = function(editor) {
/** Get the pagebreak title **/
var alt, tag, title = document.getElementById('title').value;

if (!window.parent.Joomla.getOptions('xtd-pagebreak')) {
// Something went wrong!
window.parent.jModalClose();
return false;
}

/** Get the pagebreak toc alias -- not inserting for now **/
/** don't know which attribute to use... **/
alt = document.getElementById('alt').value;

title = (title != '') ? 'title="' + title + '"' : '';
alt = (alt != '') ? 'alt="' + alt + '"' : '';

tag = '<hr class="system-pagebreak" ' + title + ' ' + alt + '/>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, wouldn't document.createElement be nicer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IE8

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm it should work fine in IE8? Shouldn't it? We use document.createElement in a lot of other JS files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it shouldn't be any problem, just checked...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yvesh checking this again, I am not in favour as we are passing a string to the editor and I have no clue if all editors out there will be happy with an element instead of a string


/** Use the API, if editor supports it **/
if (window.Joomla && window.Joomla.editors && Joomla.editors.instances && Joomla.editors.instances.hasOwnProperty(editor)) {
Joomla.editors.instances[editor].replaceSelection(tag)
} else {
window.parent.jInsertEditorText(tag, editor);
}

window.parent.jModalClose();
return false;
};
})();
1 change: 1 addition & 0 deletions media/com_content/js/admin-article-pagebreak.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions media/com_content/js/admin-article-readmore.js
@@ -0,0 +1,30 @@
/**
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

window.insertReadmore = function(editor) {
"use strict";
if (!Joomla.getOptions('xtd-readmore')) {
// Something went wrong!
return false;
}

var options, content;

options = window.parent.Joomla.getOptions('xtd-readmore');

content = (new Function('return ' + options.editor))();

if (content.match(/<hr\s+id=("|')system-readmore("|')\s*\/*>/i)) {
alert(options.exists);
Copy link
Member

@yvesh yvesh Nov 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alert? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's what was there, what else can it be?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why it is there any ways, but not a fan of alerts at all ;) Maybe use Joomla.renderMessages instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess is the same story as the buttons of the toolbar, where also an alert is utilised...
Honestly I don't mind changing it to Joomla.renderMessages()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yvesh This was a great idea generator, so J4 will come with some shiny new thingy that will cover those cases

return false;
} else {
/** Use the API, if editor supports it **/
if (window.Joomla && window.Joomla.editors && Joomla.editors.instances && Joomla.editors.instances.hasOwnProperty(editor)) {
Joomla.editors.instances[editor].replaceSelection('<hr id="system-readmore" />')
} else {
window.parent.jInsertEditorText('<hr id="system-readmore" />', editor);
}
}
};
1 change: 1 addition & 0 deletions media/com_content/js/admin-article-readmore.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.