primo commit
This commit is contained in:
42
media/com_contenthistory/js/admin-compare-compare.js
Normal file
42
media/com_contenthistory/js/admin-compare-compare.js
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
(() => {
|
||||
|
||||
// This method is used to decode HTML entities
|
||||
const decodeHtml = html => {
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.innerHTML = Joomla.sanitizeHtml(html);
|
||||
return textarea.value;
|
||||
};
|
||||
const compare = (original, changed) => {
|
||||
const display = changed.nextElementSibling;
|
||||
const diff = window.Diff.diffWords(original.innerHTML, changed.innerHTML);
|
||||
const fragment = document.createDocumentFragment();
|
||||
diff.forEach(part => {
|
||||
let color = '';
|
||||
if (part.added) {
|
||||
color = '#a6f3a6';
|
||||
}
|
||||
if (part.removed) {
|
||||
color = '#f8cbcb';
|
||||
}
|
||||
|
||||
// @todo use the tag MARK here not SPAN
|
||||
const span = document.createElement('span');
|
||||
span.style.backgroundColor = color;
|
||||
span.style.borderRadius = '.2rem';
|
||||
span.appendChild(document.createTextNode(decodeHtml(part.value)));
|
||||
fragment.appendChild(span);
|
||||
});
|
||||
display.appendChild(fragment);
|
||||
};
|
||||
const onBoot = () => {
|
||||
document.querySelectorAll('.original').forEach(fragment => compare(fragment, fragment.nextElementSibling));
|
||||
|
||||
// Cleanup
|
||||
document.removeEventListener('DOMContentLoaded', onBoot);
|
||||
};
|
||||
document.addEventListener('DOMContentLoaded', onBoot);
|
||||
})();
|
||||
4
media/com_contenthistory/js/admin-compare-compare.min.js
vendored
Normal file
4
media/com_contenthistory/js/admin-compare-compare.min.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/(()=>{const r=e=>{const n=document.createElement("textarea");return n.innerHTML=Joomla.sanitizeHtml(e),n.value},i=(e,n)=>{const l=n.nextElementSibling,m=window.Diff.diffWords(e.innerHTML,n.innerHTML),c=document.createDocumentFragment();m.forEach(o=>{let d="";o.added&&(d="#a6f3a6"),o.removed&&(d="#f8cbcb");const t=document.createElement("span");t.style.backgroundColor=d,t.style.borderRadius=".2rem",t.appendChild(document.createTextNode(r(o.value))),c.appendChild(t)}),l.appendChild(c)},a=()=>{document.querySelectorAll(".original").forEach(e=>i(e,e.nextElementSibling)),document.removeEventListener("DOMContentLoaded",a)};document.addEventListener("DOMContentLoaded",a)})();
|
||||
BIN
media/com_contenthistory/js/admin-compare-compare.min.js.gz
Normal file
BIN
media/com_contenthistory/js/admin-compare-compare.min.js.gz
Normal file
Binary file not shown.
72
media/com_contenthistory/js/admin-history-modal.js
Normal file
72
media/com_contenthistory/js/admin-history-modal.js
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
((document, Joomla) => {
|
||||
|
||||
if (!Joomla || typeof Joomla.Text._ !== 'function') {
|
||||
throw new Error('core.js was not properly initialised');
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.getElementById('toolbar-load').addEventListener('click', () => {
|
||||
const toolbarLoad = document.getElementById('toolbar-load');
|
||||
if (!toolbarLoad.disabled) {
|
||||
const ids = document.querySelectorAll('input[id*="cb"]:checked');
|
||||
if (ids.length === 1) {
|
||||
// Add version item id to URL
|
||||
const url = `${toolbarLoad.childNodes[1].getAttribute('data-url')}&version_id=${ids[0].value}`;
|
||||
if (window.parent && url) {
|
||||
window.parent.location = url;
|
||||
}
|
||||
} else {
|
||||
Joomla.renderMessages({
|
||||
error: [Joomla.Text._('COM_CONTENTHISTORY_BUTTON_SELECT_ONE_VERSION')]
|
||||
});
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
document.getElementById('toolbar-preview').addEventListener('click', () => {
|
||||
const toolbarPreview = document.getElementById('toolbar-preview');
|
||||
if (!toolbarPreview.disabled) {
|
||||
const windowSizeArray = ['width=800, height=600, resizable=yes, scrollbars=yes'];
|
||||
const ids = document.querySelectorAll('input[id*="cb"]:checked');
|
||||
if (ids.length === 1) {
|
||||
// Add version item id to URL
|
||||
const url = `${toolbarPreview.childNodes[1].getAttribute('data-url')}&version_id=${ids[0].value}`;
|
||||
if (window.parent && url) {
|
||||
window.open(url, '', windowSizeArray.toString());
|
||||
}
|
||||
} else {
|
||||
Joomla.renderMessages({
|
||||
error: [Joomla.Text._('COM_CONTENTHISTORY_BUTTON_SELECT_ONE_VERSION')]
|
||||
});
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
document.getElementById('toolbar-compare').addEventListener('click', () => {
|
||||
const toolbarCompare = document.getElementById('toolbar-compare');
|
||||
if (!toolbarCompare.disabled) {
|
||||
const windowSizeArray = ['width=1000, height=600, resizable=yes, scrollbars=yes'];
|
||||
const ids = document.querySelectorAll('input[id*="cb"]:checked');
|
||||
if (ids.length === 0) {
|
||||
Joomla.renderMessages({
|
||||
error: [Joomla.Text._('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST')]
|
||||
});
|
||||
} else if (ids.length === 2) {
|
||||
// Add version item ids to URL
|
||||
const url = `${toolbarCompare.childNodes[1].getAttribute('data-url')}&id1=${ids[0].value}&id2=${ids[1].value}`;
|
||||
if (window.parent && url) {
|
||||
window.open(url, '', windowSizeArray.toString());
|
||||
}
|
||||
} else {
|
||||
Joomla.renderMessages({
|
||||
error: [Joomla.Text._('COM_CONTENTHISTORY_BUTTON_SELECT_TWO_VERSIONS')]
|
||||
});
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
})(document, Joomla);
|
||||
4
media/com_contenthistory/js/admin-history-modal.min.js
vendored
Normal file
4
media/com_contenthistory/js/admin-history-modal.min.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/((e,r)=>{if(!r||typeof r.Text._!="function")throw new Error("core.js was not properly initialised");e.addEventListener("DOMContentLoaded",()=>{e.getElementById("toolbar-load").addEventListener("click",()=>{const i=e.getElementById("toolbar-load");if(!i.disabled){const s=e.querySelectorAll('input[id*="cb"]:checked');if(s.length===1){const t=`${i.childNodes[1].getAttribute("data-url")}&version_id=${s[0].value}`;window.parent&&t&&(window.parent.location=t)}else r.renderMessages({error:[r.Text._("COM_CONTENTHISTORY_BUTTON_SELECT_ONE_VERSION")]})}return!1}),e.getElementById("toolbar-preview").addEventListener("click",()=>{const i=e.getElementById("toolbar-preview");if(!i.disabled){const s=["width=800, height=600, resizable=yes, scrollbars=yes"],t=e.querySelectorAll('input[id*="cb"]:checked');if(t.length===1){const l=`${i.childNodes[1].getAttribute("data-url")}&version_id=${t[0].value}`;window.parent&&l&&window.open(l,"",s.toString())}else r.renderMessages({error:[r.Text._("COM_CONTENTHISTORY_BUTTON_SELECT_ONE_VERSION")]})}return!1}),e.getElementById("toolbar-compare").addEventListener("click",()=>{const i=e.getElementById("toolbar-compare");if(!i.disabled){const s=["width=1000, height=600, resizable=yes, scrollbars=yes"],t=e.querySelectorAll('input[id*="cb"]:checked');if(t.length===0)r.renderMessages({error:[r.Text._("JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST")]});else if(t.length===2){const l=`${i.childNodes[1].getAttribute("data-url")}&id1=${t[0].value}&id2=${t[1].value}`;window.parent&&l&&window.open(l,"",s.toString())}else r.renderMessages({error:[r.Text._("COM_CONTENTHISTORY_BUTTON_SELECT_TWO_VERSIONS")]})}return!1})})})(document,Joomla);
|
||||
BIN
media/com_contenthistory/js/admin-history-modal.min.js.gz
Normal file
BIN
media/com_contenthistory/js/admin-history-modal.min.js.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user