* Adapted serendipity_editor.js to provide more global (though

deprecated) API access methods for plugins like amazonchooser
      and linktrimmer, to perform insertion. Also fixed the
      insertion of text when the ID of the element is not prefixed

(You may need to reload your browsercache to get the new JS)
This commit is contained in:
Garvin Hicking 2014-05-26 12:07:29 +02:00
parent ca530221eb
commit dab92bdca6
2 changed files with 41 additions and 4 deletions

View File

@ -4,6 +4,11 @@
Version 2.0-beta3 ()
------------------------------------------------------------------------
* Adapted serendipity_editor.js to provide more global (though
deprecated) API access methods for plugins like amazonchooser
and linktrimmer, to perform insertion. Also fixed the
insertion of text when the ID of the element is not prefixed
* Move sort by name to simple filter in ML, replace file extension
* Remember selected media library folder

View File

@ -66,6 +66,11 @@
// http://stackoverflow.com/questions/1712417/jquery-wrap-selected-text-in-a-textarea
var $txtarea = $(txtarea);
if (!$txtarea.length) {
return;
}
var len = $txtarea.val().length;
var start = $txtarea[0].selectionStart;
var end = $txtarea[0].selectionEnd;
@ -73,8 +78,8 @@
var replacement = openTag + selectedText + closeTag;
$txtarea.val($txtarea.val().substring(0, start) + replacement + $txtarea.val().substring(end, len));
$txtarea[0].selectionStart = start + replacement.length
$txtarea[0].selectionEnd = start + replacement.length
$txtarea[0].selectionStart = start + replacement.length;
$txtarea[0].selectionEnd = start + replacement.length;
if (scrollPos) {
txtarea.focus();
@ -243,7 +248,19 @@
// which works fine in NO WYSIWYG mode
// NOTE: the serendipity_imageSelector_addToBody could add any valid HTML string to the textarea
serendipity.noWysiwygAdd = function(str, textarea) {
serendipity.wrapSelection($('#'+serendipity.escapeBrackets(textarea)), str, '');
escapedElement = serendipity.escapeBrackets(textarea);
if ($('#' + escapedElement).length) {
// Proper ID was specified (hopefully by plugins)
} else {
// Let's try the serendipity[] prefix
escapedElement = serendipity.escapeBrackets('serendipity[' + textarea + ']');
if (!$('#' + escapedElement).length) {
console.log("Serendipity plugin error: " + escapedElement + " not found.");
}
}
serendipity.wrapSelection($('#'+escapedElement), str, '');
}
// Inserting media db img markup including s9y-specific container markup
@ -1463,7 +1480,7 @@ $(function() {
});
// This is kept for older plugins. Use of $(document).ready() is encouraged.
// At some point, this will be removed.
// At some point, these will be removed.
addLoadEvent = function(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
@ -1475,3 +1492,18 @@ $(function() {
}
}
}
// Several plugins use this in the global scope. Those API functions are
// vital, so they reference to our new serendipity scope. This global
// scope is deprecated and subject to removal in the future.
serendipity_imageSelector_addToBody = function(block, textarea) {
return serendipity.serendipity_imageSelector_addToBody(block, textarea);
}
serendipity_imageSelector_done = function(textarea) {
return serendipity.serendipity_imageSelector_done(textarea);
}
serendipity_imageSelector_addToElement = function(str, id) {
return serendipity.serendipity_imageSelector_addToElement(str, id);
}