Ticket #1294 (closed Bug: fixed)
Patch for Image parsing and dialog preview
| Reported by: | ycombarnous | Owned by: | |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | Project : MediaWiki+FCKeditor | Version: | SVN |
| Keywords: | Cc: |
Description
I implemented a rough parsing of images (makeImage function in FCKeditorParser.body.php). Here is the code:
function makeImage( $nt, $options ) {
$imageAtts = $url = $alt = $class = '';
$fkc_mw_image_options = explode( '|', $options) ;
$sk = $this->mOptions->getSkin();
$time = false;
# Get parameter map
$file = wfFindFile( $nt, $time );
$originalLink = $sk->makeImageLink2( $nt, $file);
if (false == strpos($originalLink, "src=\"")) {
$url = "";
$class .= ' fck_mw_notfound';
}
else {
$srcPart = substr($originalLink, strpos($originalLink, "src=")+ 5);
$url = strtok($srcPart, '"');
}
foreach( $fkc_mw_image_options as $option ) {
if ($option == 'thumb' || $option == 'frame' || $option == 'border') {
$imageAtts .= ' _fck_mw_type="' . $option . '"';
if ($option == 'thumb' || $option == 'frame') {
$class .= ' fck_mw_frame';
}
} elseif ($option == 'right' || $option == 'left' || $option == 'center') {
$imageAtts .= ' _fck_mw_location="' . $option . '"';
$class .= ' fck_mw_' . $option;
} elseif ( substr( $option, strlen( $option ) - 2 ) == 'px') {
if (preg_match('/(\d+)x(\d+)/',$option)) {
$imageAtts .= ' _fck_mw_width="' . substr($option,0,strpos($option,'x')) . '"';
$imageAtts .= ' _fck_mw_height="' . substr($option,strpos($option,'x')+1, strlen($option)-(strpos($option,'x')+3)) . '"';
} else {
$imageAtts .= ' _fck_mw_width="' . substr($option,0,strlen( $option ) - 2) . '"';
}
} else {
$alt .= ' ' . $option;
}
}
if (!preg_match('/_fck_mw_location/',$imageAtts)) {
$class .= ' fck_mw_right';
}
$imageTags = '<img src="' . $url . '" _fck_mw_filename="' . substr($nt,6) . '" class="'. trim($class) .'" alt="' . trim($alt) . '" ' . $imageAtts .'>';
return $imageTags;
}
In addition, I implemented an image preview in the dialog:
function UpdatePreviewFromAjax( response )
{
var eImgPreview = window.document.getElementById('prevImg');
eImgPreview.src = response.responseText ;
SetAttribute(eImgPreview, "width" , '180px' ) ;
SetAttribute(eImgPreview, "height", '130px' ) ;
//UpdateImage( eImgPreview, response.responseText ) ;
}
function UpdatePreview()
{
var ajaxArg = GetE('txtUrl').value + '|180x130px';
oEditor.window.parent.sajax_request_type = 'GET' ;
oEditor.window.parent.sajax_do_call( 'wfSajaxGetImageUrl', [ajaxArg], UpdatePreviewFromAjax ) ;
}
You will have to add "UpdatePreview();" to LoadSelection, and modify the first part of table like this:
<tr valign="center"> <td> <span>Image file name</span><br /> <input id="txtUrl" style="width: 100%" type="text" onkeyup="OnUrlChange();" /> <br /> Automatic search results (<span id="xWikiSearchStatus">start typing in the above field</span>)<br /> <select id="xWikiResults" size="5" style="width: 100%; height: 70px" onclick="SetUrl( this.value );UpdatePreview();"> </select> </td> <td width="180px" height="130px"><div style="width:180; height:130; border:solid 1px black;" valign="center" align="center"> <img id="prevImg" width="180px" height="130px" alt="Preview"></div> </td> </tr>
Change History
Note: See
TracTickets for help on using
tickets.