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
Changes from all commits
0ab0eeb
4df0509
ac0d2ce
8f933f6
3f0a936
a0060f0
9ed34f7
9131a5f
9e75d6b
bcd82d7
b31ad4e
7c91094
ab4decf
a776eb2
690fa4d
3382446
e3a24ce
0c62941
a4d5ccc
3db07d6
6a76e7e
2f3f3a5
3550213
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
*/ | ||
|
||
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>'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too fast, we do support IE8, so not possible There was a problem hiding this comment. Choose a reason for hiding this commentThe 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++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need for speed 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
}) | ||
} | ||
}); | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 + '/>'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, wouldn't document.createElement be nicer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IE8 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually it shouldn't be any problem, just checked... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
}; | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alert? :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's what was there, what else can it be? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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); | ||
} | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?