| 1 |
/* $Id: img_assist_popup.js,v 1.2 2008/12/25 19:14:44 sun Exp $ */
|
| 2 |
|
| 3 |
var currentMode;
|
| 4 |
|
| 5 |
function onChangeBrowseBy(el) {
|
| 6 |
frames['img_assist_main'].window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/thumbs/' + el.value;
|
| 7 |
}
|
| 8 |
|
| 9 |
function onClickUpload() {
|
| 10 |
frames['img_assist_main'].window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/upload';
|
| 11 |
}
|
| 12 |
|
| 13 |
function onClickStartOver() {
|
| 14 |
frames['img_assist_main'].window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/thumbs/img_assist_browser';
|
| 15 |
}
|
| 16 |
|
| 17 |
function updateCaption() {
|
| 18 |
var caption = frames['img_assist_main'].document.getElementById('caption');
|
| 19 |
var title = frames['img_assist_main'].document.img_assist['edit-title'].value;
|
| 20 |
var desc = frames['img_assist_main'].document.img_assist['edit-desc'].value;
|
| 21 |
if (desc != '') {
|
| 22 |
title = title + ': ';
|
| 23 |
}
|
| 24 |
caption.innerHTML = '<strong>' + title + '</strong>' + desc;
|
| 25 |
}
|
| 26 |
|
| 27 |
function onChangeHeight() {
|
| 28 |
var formObj = frames['img_assist_main'].document.forms[0];
|
| 29 |
var aspect = formObj['edit-aspect'].value;
|
| 30 |
var height = formObj['edit-height'].value;
|
| 31 |
formObj['edit-width'].value = Math.round(height * aspect);
|
| 32 |
}
|
| 33 |
|
| 34 |
function onChangeWidth() {
|
| 35 |
var formObj = frames['img_assist_main'].document.forms[0];
|
| 36 |
var aspect = formObj['edit-aspect'].value;
|
| 37 |
var width = formObj['edit-width'].value;
|
| 38 |
formObj['edit-height'].value = Math.round(width / aspect);
|
| 39 |
}
|
| 40 |
|
| 41 |
function onChangeLink() {
|
| 42 |
var formObj = frames['img_assist_main'].document.forms[0];
|
| 43 |
if (formObj['edit-link-options-visible'].value == 1) {
|
| 44 |
if (formObj['edit-link'].value == 'url') {
|
| 45 |
showElement('edit-url', 'inline');
|
| 46 |
}
|
| 47 |
else {
|
| 48 |
hideElement('edit-url');
|
| 49 |
}
|
| 50 |
}
|
| 51 |
}
|
| 52 |
|
| 53 |
function onChangeSizeLabel() {
|
| 54 |
var formObj = frames['img_assist_main'].document.forms[0];
|
| 55 |
if (formObj['edit-size-label'].value == 'other') {
|
| 56 |
showElement('size-other', 'inline');
|
| 57 |
}
|
| 58 |
else {
|
| 59 |
hideElement('size-other');
|
| 60 |
// get the new width and height
|
| 61 |
var size = formObj['edit-size-label'].value.split('x');
|
| 62 |
// this array is probably a bounding box size, not an actual image
|
| 63 |
// size, so now we use the known aspect ratio to find the actual size
|
| 64 |
var aspect = formObj['edit-aspect'].value;
|
| 65 |
var width = size[0];
|
| 66 |
var height = size[1];
|
| 67 |
if (Math.round(width / aspect) <= height) {
|
| 68 |
// width is controlling factor
|
| 69 |
height = Math.round(width / aspect);
|
| 70 |
}
|
| 71 |
else {
|
| 72 |
// height is controlling factor
|
| 73 |
width = Math.round(height * aspect);
|
| 74 |
}
|
| 75 |
// fill the hidden width and height textboxes with these values
|
| 76 |
formObj['edit-width'].value = width;
|
| 77 |
formObj['edit-height'].value = height;
|
| 78 |
}
|
| 79 |
}
|
| 80 |
|
| 81 |
function setHeader(mode) {
|
| 82 |
if (currentMode != mode) {
|
| 83 |
frames['img_assist_header'].window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/header/' + mode;
|
| 84 |
}
|
| 85 |
currentMode = mode;
|
| 86 |
}
|
| 87 |
|
| 88 |
function showElement(id, format) {
|
| 89 |
var docObj = frames['img_assist_main'].document;
|
| 90 |
format = (format) ? format : 'block';
|
| 91 |
if (docObj.layers) {
|
| 92 |
docObj.layers[id].display = format;
|
| 93 |
}
|
| 94 |
else if (docObj.all) {
|
| 95 |
docObj.all[id].style.display = format;
|
| 96 |
}
|
| 97 |
else if (docObj.getElementById) {
|
| 98 |
docObj.getElementById(id).style.display = format;
|
| 99 |
}
|
| 100 |
}
|
| 101 |
|
| 102 |
function hideElement(id) {
|
| 103 |
var docObj = frames['img_assist_main'].document;
|
| 104 |
if (docObj.layers) {
|
| 105 |
docObj.layers[id].display = 'none';
|
| 106 |
}
|
| 107 |
else if (docObj.all) {
|
| 108 |
docObj.all[id].style.display = 'none';
|
| 109 |
}
|
| 110 |
else if (docObj.getElementById) {
|
| 111 |
docObj.getElementById(id).style.display = 'none';
|
| 112 |
}
|
| 113 |
}
|
| 114 |
|
| 115 |
function insertImage() {
|
| 116 |
if (window.opener || (tinyMCEPopup.editor && tinyMCEPopup.editor.id)) {
|
| 117 |
// Get variables from the fields on the properties frame
|
| 118 |
var formObj = frames['img_assist_main'].document.forms[0];
|
| 119 |
// Get mode (see img_assist.module for detailed comments)
|
| 120 |
if (formObj['edit-insertmode'].value == 'html') {
|
| 121 |
// return so the page can submit normally and generate the HTML code
|
| 122 |
return true;
|
| 123 |
}
|
| 124 |
else if (formObj['edit-insertmode'].value == 'html2') {
|
| 125 |
// HTML step 2 (processed code, ready to be inserted)
|
| 126 |
var content = getHTML(formObj);
|
| 127 |
}
|
| 128 |
else {
|
| 129 |
// formObj['edit-insertmode'].value == 'filtertag'
|
| 130 |
var content = getFilterTag(formObj);
|
| 131 |
}
|
| 132 |
return insertToEditor(content);
|
| 133 |
}
|
| 134 |
else {
|
| 135 |
alert('The image cannot be inserted because the parent window cannot be found.');
|
| 136 |
return false;
|
| 137 |
}
|
| 138 |
}
|
| 139 |
|
| 140 |
function getHTML(formObj) {
|
| 141 |
return frames['img_assist_main'].document.getElementById('finalhtmlcode').value;
|
| 142 |
}
|