Skip to content

Commit

Permalink
Transform com_content to ES6 (joomla#97)
Browse files Browse the repository at this point in the history
* com_content 3

* make simple

* TODO

* one left
  • Loading branch information
anuragteapot authored and dneukirchen committed Mar 10, 2018
1 parent cae0d8d commit a823fc7
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 50 deletions.
55 changes: 55 additions & 0 deletions media/com_content/js/admin-articles-modal.es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
(() => {
'use strict';

/**
* Javascript to insert the link
* View element calls jSelectArticle when an article is clicked
* jSelectArticle creates the link tag, sends it to the editor,
* and closes the select frame.
* */
window.jSelectArticle = (id, title, catid, object, link, lang) => {
let hreflang = '';
if (!Joomla.getOptions('xtd-articles')) {
// Something went wrong!
// @TODO Close the modal
return false;
}

const { editor } = Joomla.getOptions('xtd-articles');

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

const tag = `<a ${hreflang} href="${link}">${title}</a>`;
window.parent.Joomla.editors.instances[editor].replaceSelection(tag);
// @TODO Close the modal
return true;
};

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

for (let i = 0, l = elements.length; l > i; i += 1) {
// Listen for click event
elements[i].addEventListener('click', (event) => {
event.preventDefault();
const { target } = event;
const functionName = target.getAttribute('data-function');

if (functionName === 'jSelectArticle') {
// Used in xtd_contacts
window[functionName](target.getAttribute('data-id'), target.getAttribute('data-title'), target.getAttribute('data-cat-id'), null, target.getAttribute('data-uri'), target.getAttribute('data-language'));
} else {
// Used in com_menus
window.parent[functionName](target.getAttribute('data-id'), target.getAttribute('data-title'), target.getAttribute('data-cat-id'), null, target.getAttribute('data-uri'), target.getAttribute('data-language'));
}
});
}
});
})();
108 changes: 58 additions & 50 deletions media/com_content/js/admin-articles-modal.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,63 @@
/**
* PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION.
* OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD.
**/

/**
* @copyright Copyright (C) 2005 - 2017 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 jSelectArticle when an article is clicked
* jSelectArticle creates the link tag, sends it to the editor,
* and closes the select frame.
**/
window.jSelectArticle = function (id, title, catid, object, link, lang) {
var hreflang = '', editor, tag;

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

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

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

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

window.parent.Joomla.editors.instances[editor].replaceSelection(tag);
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++) {
// Listen for click event
elements[i].addEventListener('click', function (event) {
event.preventDefault();
var functionName = event.target.getAttribute('data-function');

if (functionName === 'jSelectArticle') {
// Used in xtd_contacts
window[functionName](event.target.getAttribute('data-id'), event.target.getAttribute('data-title'), event.target.getAttribute('data-cat-id'), null, event.target.getAttribute('data-uri'), event.target.getAttribute('data-language'));
} else {
// Used in com_menus
window.parent[functionName](event.target.getAttribute('data-id'), event.target.getAttribute('data-title'), event.target.getAttribute('data-cat-id'), null, event.target.getAttribute('data-uri'), event.target.getAttribute('data-language'));
}
})
}
});
(function () {
'use strict';

/**
* Javascript to insert the link
* View element calls jSelectArticle when an article is clicked
* jSelectArticle creates the link tag, sends it to the editor,
* and closes the select frame.
* */

window.jSelectArticle = function (id, title, catid, object, link, lang) {
var hreflang = '';
if (!Joomla.getOptions('xtd-articles')) {
// Something went wrong!
// @TODO Close the modal
return false;
}

var _Joomla$getOptions = Joomla.getOptions('xtd-articles'),
editor = _Joomla$getOptions.editor;

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

var tag = '<a ' + hreflang + ' href="' + link + '">' + title + '</a>';
window.parent.Joomla.editors.instances[editor].replaceSelection(tag);
// @TODO Close the modal
return true;
};

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

for (var i = 0, l = elements.length; l > i; i += 1) {
// Listen for click event
elements[i].addEventListener('click', function (event) {
event.preventDefault();
var target = event.target;

var functionName = target.getAttribute('data-function');

if (functionName === 'jSelectArticle') {
// Used in xtd_contacts
window[functionName](target.getAttribute('data-id'), target.getAttribute('data-title'), target.getAttribute('data-cat-id'), null, target.getAttribute('data-uri'), target.getAttribute('data-language'));
} else {
// Used in com_menus
window.parent[functionName](target.getAttribute('data-id'), target.getAttribute('data-title'), target.getAttribute('data-cat-id'), null, target.getAttribute('data-uri'), target.getAttribute('data-language'));
}
});
}
});
})();

0 comments on commit a823fc7

Please sign in to comment.