Skip to content

Commit

Permalink
plugin works in joomla4 now
Browse files Browse the repository at this point in the history
  • Loading branch information
lavipr committed Aug 31, 2017
1 parent 49f4c85 commit e3edb17
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 34 deletions.
26 changes: 20 additions & 6 deletions administrator/components/com_content/tmpl/article/showdiff.php
Expand Up @@ -19,7 +19,7 @@
JHtml::_('script', 'com_content/admin-article-showdiff.min.js', array('version' => 'auto', 'relative' => true));


//JHtml::_('script', 'com_contenthistory/diff_match_patch.js', array('version' => 'auto', 'relative' => true));
JHtml::_('script', 'vendor/diff/diff.js', array('version' => 'auto', 'relative' => true));
JHtml::_('stylesheet', 'com_contenthistory/jquery.pretty-text-diff.css', array('version' => 'auto', 'relative' => true));
JHtml::_('script', 'com_content/admin-article-showdiff.js', array('version' => 'auto', 'relative' => true));

Expand All @@ -33,12 +33,9 @@
$document->setTitle(JText::_('COM_CONTENT_PAGEBREAK_DOC_TITLE'));

$input = JFactory::getApplication()->input;
//JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_contenthistory/Model/');

/** @var Joomla\Component\Contenthistory\Administrator\Model\History $contentHistory */
//$contentHistory = JModelLegacy::getInstance('History', 'Joomla/Component/Contenthistory/Administrator/Model/');
$contentHistory = new History;
//$contentHistory = JModelLegacy::getInstance('History', '');

$itemId = $contentHistory->getState('item_id', $input->get('id'));
$typeId = $contentHistory->getState('type_id', 5);
Expand All @@ -59,9 +56,26 @@
$dbObject = $contentHistory->getItems();

?>
<!-- These Buttons toogle the shown text between one including HTML-Tags and one that doesn´t -->
<div>
<button class="diff-header btn hasTooltip"
title="<?php echo JText::_('COM_CONTENTHISTORY_BUTTON_COMPARE_HTML_DESC'); ?>"
onclick="jQuery('.diff_html, .diffhtml-header').show(); jQuery('.diff_text, .diff-header').hide()">

<span class="icon-wrench" aria-hidden="true"></span>
<?php echo JText::_('COM_CONTENTHISTORY_BUTTON_COMPARE_HTML'); ?>
</button>
<button class="diffhtml-header btn hasTooltip"
title="<?php echo JText::_('COM_CONTENTHISTORY_BUTTON_COMPARE_TEXT_DESC'); ?>"
onclick="jQuery('.diff_html, .diffhtml-header').hide(); jQuery('.diff_text, .diff-header').show()"
style="display:none">
<span class="icon-pencil"
aria-hidden="true"></span> <?php echo JText::_('COM_CONTENTHISTORY_BUTTON_COMPARE_TEXT'); ?></button>
</div>

<div id="diff_area" class="container-popup" style="height: auto"><?php
if (count($dbObject) > 1)
<div id="diff_area" class="container-popup" style="height: auto">
<?php
if (count($dbObject) > 1)
{
$object = ContenthistoryHelper::decodeFields($dbObject[$previousVersion]->version_data);
if ($object->fulltext != null)
Expand Down
70 changes: 42 additions & 28 deletions media/com_content/js/admin-article-showdiff.js
Expand Up @@ -11,46 +11,60 @@
jQuery(document).ready(function () {
var text1 = document.getElementById("diff_area").innerHTML,
text2 = parent.document.getElementById("jform_articletext_ifr").contentDocument.getElementById("tinymce").innerHTML,
innerHTML = '',
innerHTML2 = '',
diff_text;
diff_text, diff_html, span, color, fragment, spanParent;

parent.window.onresize = styling_things;
styling_things();
parent.window.onresize = popup_position;
popup_position();

diff_text = JsDiff.diffWords(text1, text2);
diff_text.forEach(function (elem) {
innerHTML2 += elem;
innerHTML += make_pretty_diff(elem);
diff_html = JsDiff.diffWords(text1, text2);
fragment = document.createDocumentFragment();

diff_html.forEach(function (part) {
color = part.added ? '#a6f3a6' : part.removed ? '#f8cbcb' : '';
span = document.createElement('span');
span.style.backgroundColor = color;
span.style.borderRadius = '.2rem';
span.appendChild(document.createTextNode(part.value));
span.className = "diff_html";
span.style.display = "none";
fragment.appendChild(span);
});

diff_text = JsDiff.diffWords(clean_tags(text1), clean_tags(text2));
diff_text.forEach(function (part) {
color = part.added ? '#a6f3a6' : part.removed ? '#f8cbcb' : '';
span = document.createElement('span');
span.style.backgroundColor = color;
span.style.borderRadius = '.2rem';
span.appendChild(document.createTextNode(part.value));
span.className = "diff_text";
fragment.appendChild(span);
});
document.getElementById("diff_area").innerHTML = innerHTML;

spanParent = document.createElement('div');
spanParent.id = "diff_area";
spanParent.appendChild(fragment);

document.getElementById("diff_area").replaceWith(spanParent);

}
);

function make_pretty_diff(diff) {
var data, html, operation, pattern_amp, pattern_gt, pattern_lt, pattern_para, text;
html = [];
pattern_amp = /&/g;
pattern_lt = /</g;
pattern_gt = />/g;
pattern_para = /\n/g;
operation = diff[0], data = diff[1];
text = data.replace(pattern_amp, '&amp;').replace(pattern_lt, '&lt;').replace(pattern_gt, '&gt;').replace(pattern_para, '<br>');
switch (operation) {
case DIFF_INSERT:
return '<ins>' + text + '</ins>';
case DIFF_DELETE:
return '<del>' + text + '</del>';
case DIFF_EQUAL:
return '<span>' + text + '</span>';
//Deletes all HTML-Text it finds in the given text
function clean_tags(text) {
var text_clean = new String(text),
regexp = new RegExp('<.*?>');

while (regexp.test(text_clean)) {
text_clean = text_clean.replace(regexp.exec(text_clean).toString(), '');
}
return text_clean;
}

/*
/ positioning of the show-diff-popup.
*/
function styling_things() {
*/
function popup_position() {
var popupContainer = parent.document.getElementsByClassName("mce-floatpanel")[0],
popupBody = popupContainer.getElementsByClassName("mce-container-body")[0],
popupFoot = popupContainer.getElementsByClassName("mce-foot")[0],
Expand Down

0 comments on commit e3edb17

Please sign in to comment.