simplifying media db function in serendipity_editor.js and correcting a mixup with serendipity[isLink] in media_chooser

This commit is contained in:
onli 2013-02-25 21:09:25 +01:00
parent 49b855c55f
commit 2a88167957
2 changed files with 66 additions and 144 deletions

View File

@ -130,71 +130,40 @@ function wrapInsImage(txtarea) {
} }
/* end Better-Editor functions */ /* end Better-Editor functions */
// "Transfer" value from media db popup to form element? // "Transfer" value from media db popup to form element, used for example for selecting a category-icon
function serendipity_imageSelector_addToElement (str, el) { function serendipity_imageSelector_addToElement (str, id) {
document.getElementById(el).value = str; var $input = jQuery('#'+id);
$input.val(str);
if (document.getElementById(el).type != 'hidden' && document.getElementById(el).focus) { if ($input.attr('type') != 'hidden') {
document.getElementById(el).focus(); $input.focus(); // IE would generate an error when focusing an hidden element
} }
if (document.getElementById(el).onchange) { // calling the change-event for doing stuff like generating the preview-image
document.getElementById(el).onchange(); $input.change();
}
} }
// "Transfer" value from media db popup to wysiwyg? // "Transfer" value from media db popup to textarea, including wysiwyg
// This gets textarea="body"/"extended" and tries to insert into the textarea named serendipity[body]/serendipity[extended]
function serendipity_imageSelector_addToBody (str, textarea) { function serendipity_imageSelector_addToBody (str, textarea) {
// check for FCKEditor usage var oEditor;
if (typeof(FCKeditorAPI) != 'undefined') { if (typeof(FCKeditorAPI) != 'undefined') {
// if here the blog uses FCK editor oEditor = FCKeditorAPI.GetInstance('serendipity[' + textarea + ']') ;
var oEditor = FCKeditorAPI.GetInstance('serendipity[' + textarea + ']') ;
if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG) { if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG) {
// if here the editior is in WYSIWYG mode so use the insert html function
oEditor.InsertHtml(str); oEditor.InsertHtml(str);
} else { return;
// if here just insert the text to the textarea ( named with the value of textarea variable )
noWysiwygAdd( str, textarea );
} }
} else if(typeof(xinha_editors) != 'undefined') { } else if(typeof(xinha_editors) != 'undefined') {
// if here the blog uses Xinha editor
var oEditor;
if (typeof(xinha_editors['serendipity[' + textarea + ']']) != 'undefined') { if (typeof(xinha_editors['serendipity[' + textarea + ']']) != 'undefined') {
// this is good for the two default editors (body & extended)
oEditor = xinha_editors['serendipity['+ textarea +']']; oEditor = xinha_editors['serendipity['+ textarea +']'];
} else if (typeof(xinha_editors[textarea]) != 'undefined') {
// this should work in any other cases than previous one
oEditor = xinha_editors[textarea];
} else {
// this is the last chance to retrieve the instance of the editor !
// editor has not been registered by the name of it's textarea
// so we must iterate over editors to find the good one
for (var editorName in xinha_editors) {
if ('serendipity[' + textarea + ']' == xinha_editors[editorName]._textArea.name) {
oEditor = xinha_editors[editorName];
break;
}
}
} }
// the actual insert for the xinha editor
if (oEditor) { if (oEditor) {
if (oEditor._editMode != 'textmode') { oEditor.insertHTML(str);
// if here the editior is in WYSIWYG mode so use the insert html function return;
oEditor.insertHTML(str);
} else {
// if here just insert the text to the textarea ( named with the value of textarea variable )
noWysiwygAdd(str, textarea);
}
} else {
noWysiwygAdd(str, textarea);
} }
} else if(typeof(HTMLArea) != 'undefined') { } else if(typeof(HTMLArea) != 'undefined') {
// if here the blog uses HTMLArea editor
var oEditor;
if (textarea == 'body' && typeof(editorbody) != 'undefined') { if (textarea == 'body' && typeof(editorbody) != 'undefined') {
oEditor = editorbody; oEditor = editorbody;
} else if (textarea == 'extended' && typeof(editorextended) != 'undefined') { } else if (textarea == 'extended' && typeof(editorextended) != 'undefined') {
@ -203,46 +172,27 @@ function serendipity_imageSelector_addToBody (str, textarea) {
oEditor = htmlarea_editors[textarea]; oEditor = htmlarea_editors[textarea];
} }
// the actual insert for the HTMLArea editor
if (oEditor._editMode != 'textmode') { if (oEditor._editMode != 'textmode') {
// if here the editior is in WYSIWYG mode so use the insert html function
oEditor.insertHTML(str); oEditor.insertHTML(str);
} else { return;
// if here just insert the text to the textarea ( named with the value of textarea variable ) }
noWysiwygAdd(str, textarea);
}
} else if(typeof(TinyMCE) != 'undefined') { } else if(typeof(TinyMCE) != 'undefined') {
// for the TinyMCE editor we do not have a text mode insert // for the TinyMCE editor we do not have a text mode insert
//tinyMCE.execCommand('mceInsertContent', false, str);
tinyMCE.execInstanceCommand('serendipity[' + textarea + ']', 'mceInsertContent', false, str); tinyMCE.execInstanceCommand('serendipity[' + textarea + ']', 'mceInsertContent', false, str);
} else { return;
noWysiwygAdd(str, textarea);
} }
noWysiwygAdd(str, textarea);
} }
// The noWysiwygAdd JS function is the vanila serendipity_imageSelector_addToBody js function // The noWysiwygAdd JS function is the vanila serendipity_imageSelector_addToBody js function
// which works fine in NO WYSIWYG mode // which works fine in NO WYSIWYG mode
// NOTE: the serendipity_imageSelector_addToBody could add any valid HTML string to the textarea // NOTE: the serendipity_imageSelector_addToBody could add any valid HTML string to the textarea
function noWysiwygAdd( str, textarea ) { function noWysiwygAdd( str, textarea ) {
// default case: no wysiwyg editor wrapSelection(jQuery('textarea[name="serendipity['+textarea+']"]'), str, '');
eltarget = '';
if (document.forms['serendipityEntry'] && document.forms['serendipityEntry']['serendipity['+ textarea +']']) {
eltarget = document.forms['serendipityEntry']['serendipity['+ textarea +']']
} else if (document.forms['serendipityEntry'] && document.forms['serendipityEntry'][textarea]) {
eltarget = document.forms['serendipityEntry'][textarea];
} else {
eltarget = document.forms[0].elements[0];
}
wrapSelection(eltarget, str, '');
eltarget.focus();
} }
// Inserting media db img markup including s9y-specific container markup? // Inserting media db img markup including s9y-specific container markup
function serendipity_imageSelector_done(textarea) { function serendipity_imageSelector_done(textarea) {
var insert = ''; var insert = '';
var img = ''; var img = '';
@ -252,36 +202,34 @@ function serendipity_imageSelector_done(textarea) {
var f = document.forms['serendipity[selForm]'].elements; var f = document.forms['serendipity[selForm]'].elements;
img = f['imgName'].value;
var imgWidth = f['imgWidth'].value;
var imgHeight = f['imgHeight'].value;
if (f['serendipity[linkThumbnail]'] && f['serendipity[linkThumbnail]'][0].checked == true) { if (f['serendipity[linkThumbnail]'] && f['serendipity[linkThumbnail]'][0].checked == true) {
img = f['thumbName'].value; img = f['thumbName'].value;
imgWidth = f['imgThumbWidth'].value; imgWidth = f['imgThumbWidth'].value;
imgHeight = f['imgThumbHeight'].value; imgHeight = f['imgThumbHeight'].value;
} else {
img = f['imgName'].value;
imgWidth = f['imgWidth'].value;
imgHeight = f['imgHeight'].value;
} }
if (f['serendipity[filename_only]']) { if (f['serendipity[filename_only]']) {
if (f['serendipity[htmltarget]']) { // this part is used when selecting only the image without further markup (-> category-icon)
starget = f['serendipity[htmltarget]'].value; var starget = f['serendipity[htmltarget]'] ? f['serendipity[htmltarget]'].value : 'serendipity[' + textarea + ']';
} else {
starget = 'serendipity[' + textarea + ']';
}
if (f['serendipity[filename_only]'].value == 'true') { switch(f['serendipity[filename_only]'].value) {
case 'true':
parent.self.opener.serendipity_imageSelector_addToElement(img, f['serendipity[htmltarget]'].value); parent.self.opener.serendipity_imageSelector_addToElement(img, f['serendipity[htmltarget]'].value);
parent.self.close(); parent.self.close();
return true; return true;
} else if (f['serendipity[filename_only]'].value == 'id') { case 'id':
parent.self.opener.serendipity_imageSelector_addToElement(f['imgID'].value, starget); parent.self.opener.serendipity_imageSelector_addToElement(f['imgID'].value, starget);
parent.self.close(); parent.self.close();
return true; return true;
} else if (f['serendipity[filename_only]'].value == 'thumb') { case 'thumb':
parent.self.opener.serendipity_imageSelector_addToElement(f['thumbName'].value, starget); parent.self.opener.serendipity_imageSelector_addToElement(f['thumbName'].value, starget);
parent.self.close(); parent.self.close();
return true; return true;
} else if (f['serendipity[filename_only]'].value == 'big') { case 'big':
parent.self.opener.serendipity_imageSelector_addToElement(f['imgName'].value, starget); parent.self.opener.serendipity_imageSelector_addToElement(f['imgName'].value, starget);
parent.self.close(); parent.self.close();
return true; return true;
@ -290,82 +238,58 @@ function serendipity_imageSelector_done(textarea) {
alt = f['serendipity[alt]'].value.replace(/"/g, """); alt = f['serendipity[alt]'].value.replace(/"/g, """);
title = f['serendipity[title]'].value.replace(/"/g, """); title = f['serendipity[title]'].value.replace(/"/g, """);
styled = false; // Templates now do this.
imgID = 0;
var imgID = 0;
if (f['imgID']) { if (f['imgID']) {
imgID = f['imgID'].value; imgID = f['imgID'].value;
} }
baseURL = '';
if (f['baseURL']) { var floating = jQuery(':input[name="serendipity[align]"]:checked').val();
baseURL = f['baseURL'].value; if (floating == "") {
floating = "center";
} }
img = "<!-- s9ymdb:" + imgID + " --><img class=\"serendipity_image_"+ floating +"\" width=\"" + imgWidth + "\" height=\"" + imgHeight + '" src="' + img + "\" " + (title != '' ? 'title="' + title + '"' : '') + " alt=\"" + alt + "\" />";
floating = 'center'; if (jQuery("#radio_islink_yes").attr("checked")) {
// wrap the img in a link to the image. TODO: The label in the media_chooser.tpl explains it wrong
var targetval = jQuery('#select_image_target').val();
if (f['serendipity[align]'][0].checked == true) { var prepend = '';
img = "<!-- s9ymdb:" + imgID + " --><img class=\"serendipity_image_center\" width=\"" + imgWidth + "\" height=\"" + imgHeight + "\" " + (styled ? 'style="border: 0px; padding-left: 5px; padding-right: 5px;"' : '') + ' src="' + img + "\" " + (title != '' ? 'title="' + title + '"' : '') + " alt=\"" + alt + "\" />"; var ilink = f['serendipity[url]'].value;
} else if (f['serendipity[align]'][1].checked == true) { var itarget = '';
img = "<!-- s9ymdb:" + imgID + " --><img class=\"serendipity_image_left\" width=\"" + imgWidth + "\" height=\"" + imgHeight + "\" " + (styled ? 'style="float: left; border: 0px; padding-left: 5px; padding-right: 5px;"' : '') + ' src="' + img + "\" " + (title != '' ? 'title="' + title + '"' : '') + " alt=\"" + alt + "\" />";
floating = 'left';
} else if (f['serendipity[align]'][2].checked == true) {
img = "<!-- s9ymdb:" + imgID + " --><img class=\"serendipity_image_right\" width=\"" + imgWidth + "\" height=\"" + imgHeight + "\" " + (styled ? 'style="float: right; border: 0px; padding-left: 5px; padding-right: 5px;"' : '') + ' src="' + img + "\" " + (title != '' ? 'title="' + title + '"' : '') + " alt=\"" + alt + "\" />";
floating = 'right';
}
if (f['serendipity[isLink]'][1].checked == true) { switch (targetval) {
if (f['serendipity[target]'].selectedIndex) { case 'js':
targetval = f['serendipity[target]'].options[f['serendipity[target]'].selectedIndex].value; var itarget = ' onclick="F1 = window.open(\'' + f['serendipity[url]'].value + '\',\'Zoom\',\''
} else {
targetval = '';
}
prepend = '';
ilink = f['serendipity[url]'].value;
if (!targetval || targetval == 'none') {
itarget = '';
} else if (targetval == 'js') {
itarget = ' onclick="F1 = window.open(\'' + f['serendipity[url]'].value + '\',\'Zoom\',\''
+ 'height=' + (parseInt(f['imgHeight'].value) + 15) + ',' + 'height=' + (parseInt(f['imgHeight'].value) + 15) + ','
+ 'width=' + (parseInt(f['imgWidth'].value) + 15) + ',' + 'width=' + (parseInt(f['imgWidth'].value) + 15) + ','
+ 'top=' + (screen.height - f['imgHeight'].value) /2 + ',' + 'top=' + (screen.height - f['imgHeight'].value) /2 + ','
+ 'left=' + (screen.width - f['imgWidth'].value) /2 + ',' + 'left=' + (screen.width - f['imgWidth'].value) /2 + ','
+ 'toolbar=no,menubar=no,location=no,resize=1,resizable=1,scrollbars=yes\'); return false;"'; + 'toolbar=no,menubar=no,location=no,resize=1,resizable=1,scrollbars=yes\'); return false;"';
} else if (targetval == '_blank') { break;
itarget = ' target="_blank"'; case '_blank':
} else if (targetval == 'plugin') { var itarget = ' target="_blank"';
itarget = ' id="s9yisphref' + imgID + '" onclick="javascript:this.href = this.href + \'&amp;serendipity[from]=\' + self.location.href;"'; break;
case 'plugin':
var itarget = ' id="s9yisphref' + imgID + '" onclick="javascript:this.href = this.href + \'&amp;serendipity[from]=\' + self.location.href;"';
prepend = '<a title="' + ilink + '" id="s9yisp' + imgID + '"></a>'; prepend = '<a title="' + ilink + '" id="s9yisp' + imgID + '"></a>';
ilink = baseURL + 'serendipity_admin_image_selector.php?serendipity[step]=showItem&amp;serendipity[image]=' + imgID; ilink = f['baseURL'].value + 'serendipity_admin_image_selector.php?serendipity[step]=showItem&amp;serendipity[image]=' + imgID;
break;
} }
insert = prepend + "<a class=\"serendipity_image_link\" " + (title != '' ? 'title="' + title + '"' : '') + " href='" + ilink + "'" + itarget + ">" + img + "</a>"; var img = prepend + "<a class=\"serendipity_image_link\" " + (title != '' ? 'title="' + title + '"' : '') + " href='" + ilink + "'" + itarget + ">" + img + "</a>";
} else { }
insert = img;
}
if (document.getElementById('serendipity_imagecomment').value != '') { if (jQuery('#serendipity_imagecomment').val() != '') {
comment = f['serendipity[imagecomment]'].value; var comment = f['serendipity[imagecomment]'].value;
block = '<div class="serendipity_imageComment_' + floating + '" style="width: ' + imgWidth + 'px">' var img = '<div class="serendipity_imageComment_' + floating + '" style="width: ' + imgWidth + 'px">'
+ '<div class="serendipity_imageComment_img">' + insert + '</div>' + '<div class="serendipity_imageComment_img">' + img + '</div>'
+ '<div class="serendipity_imageComment_txt">' + comment + '</div>' + '<div class="serendipity_imageComment_txt">' + comment + '</div>'
+ '</div>'; + '</div>';
} else {
block = insert;
}
if (typeof(parent.self.opener.htmlarea_editors) != 'undefined' && typeof(parent.self.opener.htmlarea_editors[textarea]) != 'undefined') {
parent.self.opener.htmlarea_editors[textarea].surroundHTML(block, '');
} else if (parent.self.opener.editorref) {
parent.self.opener.editorref.surroundHTML(block, '');
} else {
parent.self.opener.serendipity_imageSelector_addToBody(block, textarea);
} }
parent.self.opener.serendipity_imageSelector_addToBody(img, textarea);
parent.self.close(); parent.self.close();
} }
@ -394,8 +318,6 @@ function toggle_extended(setCookie) {
} }
} }
// Collapses/expands the category selector // Collapses/expands the category selector
function showItem(id) { function showItem(id) {
if (id == undefined) { if (id == undefined) {

View File

@ -171,8 +171,8 @@
<b>{$CONST.IMAGE_AS_A_LINK}:</b> <b>{$CONST.IMAGE_AS_A_LINK}:</b>
<br /> <br />
<input class="input_radio" type="radio" id="radio_islink_yes" type="radio" name="serendipity[isLink]" value="yes" {'isLink'|@ifRemember:'yes':true} /><label for="radio_islink_yes"> {$CONST.I_WANT_NO_LINK}</label><br /> <input class="input_radio" type="radio" id="radio_islink_no" type="radio" name="serendipity[isLink]" value="no" {'isLink'|@ifRemember:'no':true} /><label for="radio_islink_no"> {$CONST.I_WANT_NO_LINK}</label><br />
<input class="input_radio" type="radio" id="radio_islink_no" type="radio" name="serendipity[isLink]" value="no" {'isLink'|@ifRemember:'no'} /><label for="radio_islink_no"> {$CONST.I_WANT_IT_TO_LINK}</label> <input class="input_radio" type="radio" id="radio_islink_yes" type="radio" name="serendipity[isLink]" value="yes" {'isLink'|@ifRemember:'yes'} /><label for="radio_islink_yes"> {$CONST.I_WANT_IT_TO_LINK}</label>
{if $media.file.hotlink} {if $media.file.hotlink}
<input class="input_textbox" type="text" name="serendipity[url]" size="30" value="{$media.file.path}" /><br /> <input class="input_textbox" type="text" name="serendipity[url]" size="30" value="{$media.file.path}" /><br />
@ -181,7 +181,7 @@
<input class="input_textbox" type="text" name="serendipity[url]" size="30" value="{$media.file.links.imagelinkurl}" /><br /> <input class="input_textbox" type="text" name="serendipity[url]" size="30" value="{$media.file.links.imagelinkurl}" /><br />
{/if} {/if}
<label id="select_image_target">{$CONST.MEDIA_TARGET}</label> <label for="select_image_target">{$CONST.MEDIA_TARGET}</label>
<select name="serendipity[target]" id="select_image_target"> <select name="serendipity[target]" id="select_image_target">
<option value="none" {'target'|@ifRemember:'none':false:'selected'}>{$CONST.NONE}</option> <option value="none" {'target'|@ifRemember:'none':false:'selected'}>{$CONST.NONE}</option>
<option value="js" {'target'|@ifRemember:'js':false:'selected'}>{$CONST.MEDIA_TARGET_JS}</option> <option value="js" {'target'|@ifRemember:'js':false:'selected'}>{$CONST.MEDIA_TARGET_JS}</option>