textdiff.php
1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* @package Joomla.Administrator
* @subpackage com_contenthistory
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_PLATFORM') or die;
/**
* HTML utility class for creating text diffs using jQuery, diff_patch_match.js and jquery.pretty-text-diff.js JavaScript libraries.
*
* @since 3.2
*
* @deprecated 4.0 No replacement
*/
abstract class JHtmlTextdiff
{
/**
* @var array Array containing information for loaded files
* @since 3.2
*/
protected static $loaded = array();
/**
* Method to load Javascript text diff
*
* @param string $containerId DOM id of the element where the diff will be rendered
*
* @return void
*
* @since 3.2
*/
public static function textdiff($containerId)
{
// Only load once
if (isset(static::$loaded[__METHOD__]))
{
return;
}
// Depends on jQuery UI
JHtml::_('bootstrap.framework');
JHtml::_('script', 'com_contenthistory/diff_match_patch.js', array('version' => 'auto', 'relative' => true));
JHtml::_('script', 'com_contenthistory/jquery.pretty-text-diff.min.js', array('version' => 'auto', 'relative' => true));
JHtml::_('stylesheet', 'com_contenthistory/jquery.pretty-text-diff.css', array('version' => 'auto', 'relative' => true));
// Attach diff to document
JFactory::getDocument()->addScriptDeclaration("
(function ($){
$(document).ready(function (){
$('#" . $containerId . " tr').prettyTextDiff();
});
})(jQuery);
"
);
// Set static array
static::$loaded[__METHOD__] = true;
return;
}
}