| 1 |
// $Id: img_assist_tinymce.js,v 1.6 2009/01/18 04:10:25 sun Exp $
|
| 2 |
/**
|
| 3 |
* This javascript file allows img_assist to work with TinyMCE via the
|
| 4 |
* drupalimage plugin for TinyMCE.
|
| 5 |
* This file is used instead of img_assist_textarea.js if img_assist is called
|
| 6 |
* from the drupalimage plugin.
|
| 7 |
* Additional JS files similar to img_assist_textarea.js and
|
| 8 |
* img_assist_tinymce.js could be created for using img_assist with other
|
| 9 |
* WYSIWYG editors. Some minor code changes to the menu function in
|
| 10 |
* img_assist.module will be necessary, at least in img_assist_menu() and
|
| 11 |
* img_assist_loader().
|
| 12 |
*/
|
| 13 |
|
| 14 |
// This doesn't work right. tiny_mce_popup.js needs to be loaded BEFORE any
|
| 15 |
// setWindowArg() commands are issued.
|
| 16 |
// document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + BASE_URL + 'modules/tinymce/tinymce/jscripts/tiny_mce/tiny_mce_popup.js"><\/script>');
|
| 17 |
|
| 18 |
// get variables that were passed to this window from the tinyMCE editor
|
| 19 |
var nid, captionTitle, captionDesc, link, url, align, width, height;
|
| 20 |
|
| 21 |
function initLoader() {
|
| 22 |
nid = tinyMCEPopup.getWindowArg('nid');
|
| 23 |
captionTitle = '' + tinyMCEPopup.getWindowArg('captionTitle');
|
| 24 |
captionDesc = '' + tinyMCEPopup.getWindowArg('captionDesc');
|
| 25 |
link = '' + tinyMCEPopup.getWindowArg('link');
|
| 26 |
url = '' + tinyMCEPopup.getWindowArg('url');
|
| 27 |
align = '' + tinyMCEPopup.getWindowArg('align');
|
| 28 |
width = '' + tinyMCEPopup.getWindowArg('width');
|
| 29 |
height = '' + tinyMCEPopup.getWindowArg('height');
|
| 30 |
|
| 31 |
if (nid > 0) {
|
| 32 |
frames['img_assist_main'].window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/properties/' + nid + '/update';
|
| 33 |
}
|
| 34 |
else {
|
| 35 |
frames['img_assist_main'].window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/thumbs/img_assist_browser';
|
| 36 |
}
|
| 37 |
}
|
| 38 |
|
| 39 |
function initProperties() {
|
| 40 |
var formObj = frames['img_assist_main'].document.forms[0];
|
| 41 |
if (formObj['edit-update'].value == 1) {
|
| 42 |
formObj['edit-title'].value = captionTitle;
|
| 43 |
formObj['edit-desc'].value = captionDesc;
|
| 44 |
// Backwards compatibility: Also parse link/url in the format link=url,foo.
|
| 45 |
if(link.indexOf(',') != -1) {
|
| 46 |
link = link.split(',', 2);
|
| 47 |
formObj['edit-link'].value = link[0];
|
| 48 |
if (link[0] == 'url') {
|
| 49 |
formObj['edit-url'].value = link[1];
|
| 50 |
}
|
| 51 |
}
|
| 52 |
else {
|
| 53 |
formObj['edit-link'].value = link;
|
| 54 |
if(typeof url != 'undefined' && url != '') {
|
| 55 |
formObj['edit-url'].value = url;
|
| 56 |
}
|
| 57 |
}
|
| 58 |
formObj['edit-align'].value = align;
|
| 59 |
|
| 60 |
// When editing the properties of an image placed with
|
| 61 |
// img_assist, it's not easy to figure out what standard
|
| 62 |
// size was used. Until such code is written we will
|
| 63 |
// just set the size to "other". Of course, if custom
|
| 64 |
// isn't an option then I guess the image size will default
|
| 65 |
// back to thumbnail.
|
| 66 |
formObj['edit-size-label'].value = "other";
|
| 67 |
formObj['edit-width'].value = width;
|
| 68 |
formObj['edit-height'].value = height;
|
| 69 |
}
|
| 70 |
setHeader('properties');
|
| 71 |
updateCaption();
|
| 72 |
onChangeLink();
|
| 73 |
onChangeSizeLabel();
|
| 74 |
}
|
| 75 |
|
| 76 |
function initThumbs() {
|
| 77 |
setHeader('browse');
|
| 78 |
}
|
| 79 |
|
| 80 |
function initHeader() {
|
| 81 |
}
|
| 82 |
|
| 83 |
function initUpload() {
|
| 84 |
setHeader('uploading');
|
| 85 |
}
|
| 86 |
|
| 87 |
function getFilterTag(formObj) {
|
| 88 |
nid = formObj['edit-nid'].value;
|
| 89 |
captionTitle = formObj['edit-title'].value;
|
| 90 |
captionDesc = formObj['edit-desc'].value;
|
| 91 |
link = formObj['edit-link'].value;
|
| 92 |
url = formObj['edit-url'].value;
|
| 93 |
align = formObj['edit-align'].value;
|
| 94 |
width = formObj['edit-width'].value;
|
| 95 |
height = formObj['edit-height'].value;
|
| 96 |
var size = formObj['edit-size-label'].value;
|
| 97 |
|
| 98 |
// Create the image placeholder tag
|
| 99 |
// @see TinyMCE_drupalimage_cleanup() in drupalimage plugin.
|
| 100 |
// Backwards compatibility: Also parse link/url in the format link=url,foo.
|
| 101 |
var miscAttribs = 'nid=' + nid + '|title=' + captionTitle + '|desc=' + captionDesc + '|link=' + link;
|
| 102 |
if(typeof url != 'undefined' && url != formObj['edit-default-url'].value) {
|
| 103 |
miscAttribs += '|url=' + url;
|
| 104 |
}
|
| 105 |
miscAttribs = encodeURIComponent(miscAttribs);
|
| 106 |
var content = '<img src="' + Drupal.settings.basePath + 'index.php?q=image/view/' + nid + '"'
|
| 107 |
+ ' width="' + width + '" height="' + height + '" align="' + align + '"'
|
| 108 |
+ ' alt="' + miscAttribs + '" title="' + miscAttribs + '"'
|
| 109 |
+ ' name="mceItemDrupalImage" class="img-assist" />';
|
| 110 |
|
| 111 |
return content;
|
| 112 |
}
|
| 113 |
|
| 114 |
function insertToEditor(content) {
|
| 115 |
// Insert the image
|
| 116 |
tinyMCEPopup.editor.execCommand('mceInsertContent', false, content);
|
| 117 |
|
| 118 |
// Close the dialog
|
| 119 |
return cancelAction();
|
| 120 |
}
|
| 121 |
|
| 122 |
function cancelAction() {
|
| 123 |
// Close the dialog
|
| 124 |
tinyMCEPopup.close();
|
| 125 |
return false;
|
| 126 |
}
|
| 127 |
|