insert image









Insert Image

html, body, button, div, input, select, fieldset { font-family: MS Shell Dlg; font-size: 8pt; position: absolute; };



function _CloseOnEsc() {
if (event.keyCode == 27) { window.close(); return; }
}

function _getTextRange(elm) {
var r = elm.parentTextEdit.createTextRange();
r.moveToElementText(elm);
return r;
}

window.onerror = HandleError

function HandleError(message, url, line) {
var str = "An error has occurred in this dialog." + "\n\n"
+ "Error: " + line + "\n" + message;
alert(str);
window.close();
return true;
}

function Init() {
var elmSelectedImage;
var htmlSelectionControl = "Control";
var globalDoc = window.dialogArguments;
var grngMaster = globalDoc.selection.createRange();

// event handlers
document.body.onkeypress = _CloseOnEsc;
btnOK.onclick = new Function("btnOKClick()");

txtFileName.fImageLoaded = false;
txtFileName.intImageWidth = 0;
txtFileName.intImageHeight = 0;

if (globalDoc.selection.type == htmlSelectionControl) {
if (grngMaster.length == 1) {
elmSelectedImage = grngMaster.item(0);
if (elmSelectedImage.tagName == "IMG") {
txtFileName.fImageLoaded = true;
if (elmSelectedImage.src) {
txtFileName.value = elmSelectedImage.src.replace(/^[^*]*(\*\*\*)/, "$1"); // fix placeholder src values that editor converted to abs paths
txtFileName.intImageHeight = elmSelectedImage.height;
txtFileName.intImageWidth = elmSelectedImage.width;
txtVertical.value = elmSelectedImage.vspace;
txtHorizontal.value = elmSelectedImage.hspace;
txtBorder.value = elmSelectedImage.border;
txtAltText.value = elmSelectedImage.alt;
selAlignment.value = elmSelectedImage.align;
}
}
}
}
txtFileName.value = txtFileName.value || "http://";
txtFileName.focus();
}

function _isValidNumber(txtBox) {
var val = parseInt(txtBox);
if (isNaN(val) || val < 0 || val > 999) { return false; }
return true;
}

function btnOKClick() {
var elmImage;
var intAlignment;
var htmlSelectionControl = "Control";
var globalDoc = window.dialogArguments;
var grngMaster = globalDoc.selection.createRange();

// error checking

if (!txtFileName.value || txtFileName.value == "http://") {
alert("Image URL must be specified.");
txtFileName.focus();
return;
}
if (txtHorizontal.value && !_isValidNumber(txtHorizontal.value)) {
alert("Horizontal spacing must be a number between 0 and 999.");
txtHorizontal.focus();
return;
}
if (txtBorder.value && !_isValidNumber(txtBorder.value)) {
alert("Border thickness must be a number between 0 and 999.");
txtBorder.focus();
return;
}
if (txtVertical.value && !_isValidNumber(txtVertical.value)) {
alert("Vertical spacing must be a number between 0 and 999.");
txtVertical.focus();
return;
}

// delete selected content and replace with image
if (globalDoc.selection.type == htmlSelectionControl && !txtFileName.fImageLoaded) {
grngMaster.execCommand('Delete');
grngMaster = globalDoc.selection.createRange();
}

idstr = "\" id=\"556e697175657e537472696e67"; // new image creation ID
if (!txtFileName.fImageLoaded) {
grngMaster.execCommand("InsertImage", false, idstr);
elmImage = globalDoc.all['556e697175657e537472696e67'];
elmImage.removeAttribute("id");
elmImage.removeAttribute("src");
grngMaster.moveStart("character", -1);
} else {
elmImage = grngMaster.item(0);
if (elmImage.src != txtFileName.value) {
grngMaster.execCommand('Delete');
grngMaster = globalDoc.selection.createRange();
grngMaster.execCommand("InsertImage", false, idstr);
elmImage = globalDoc.all['556e697175657e537472696e67'];
elmImage.removeAttribute("id");
elmImage.removeAttribute("src");
grngMaster.moveStart("character", -1);
txtFileName.fImageLoaded = false;
}
grngMaster = _getTextRange(elmImage);
}

if (txtFileName.fImageLoaded) {
elmImage.style.width = txtFileName.intImageWidth;
elmImage.style.height = txtFileName.intImageHeight;
}

if (txtFileName.value.length > 2040) {
txtFileName.value = txtFileName.value.substring(0,2040);
}

elmImage.src = txtFileName.value;

if (txtHorizontal.value != "") { elmImage.hspace = parseInt(txtHorizontal.value); }
else { elmImage.hspace = 0; }

if (txtVertical.value != "") { elmImage.vspace = parseInt(txtVertical.value); }
else { elmImage.vspace = 0; }

elmImage.alt = txtAltText.value;

if (txtBorder.value != "") { elmImage.border = parseInt(txtBorder.value); }
else { elmImage.border = 0; }

elmImage.align = selAlignment.value;
grngMaster.collapse(false);
grngMaster.select();
window.close();
}




Image URL:


Alternate Text:



Layout



Spacing


Alignment:

Not set
Left
Right
Texttop
Absmiddle
Baseline
Absbottom
Bottom
Middle
Top


Horizontal:


Border Thickness:


Vertical:


OK
Cancel





Wyszukiwarka

Podobne podstrony:
insert image
insert image button
insert image button
insert image button
insert image
insert image button
insert image button
insert image button
insert image
insert image button
insert image button
insert image button
insert image button
insert image button
insert image button

więcej podobnych podstron