| 1 |
// $Id: img_assist_textarea.js,v 1.6 2008/12/25 19:14:44 sun Exp $
|
| 2 |
/**
|
| 3 |
* This javascript file allows img_assist to work with a plain textarea.
|
| 4 |
* This file is used instead of img_assist_tinymce.js if img_assist is called
|
| 5 |
* from the textarea button.
|
| 6 |
* Additional JS files similar to img_assist_textarea.js and
|
| 7 |
* img_assist_tinymce.js could be created for using img_assist with other
|
| 8 |
* WYSIWYG editors. Some minor code changes to the menu function in
|
| 9 |
* img_assist.module will be necessary, at least in img_assist_menu() and
|
| 10 |
* img_assist_loader().
|
| 11 |
*/
|
| 12 |
|
| 13 |
// Declare global variables
|
| 14 |
var myDoc, myForm, myTextarea, hasInputFormat;
|
| 15 |
|
| 16 |
function initLoader() {
|
| 17 |
// Save the references to the parent form and textarea to be used later.
|
| 18 |
myDoc = window.opener.document; // global (so don't use var keyword)
|
| 19 |
myForm = '';
|
| 20 |
myTextarea = '';
|
| 21 |
hasInputFormat = false;
|
| 22 |
|
| 23 |
var args = getArgs(); // get the querystring arguments
|
| 24 |
var textarea = args.textarea;
|
| 25 |
|
| 26 |
// Reference the form object for this textarea.
|
| 27 |
if (myDoc.getElementsByTagName) {
|
| 28 |
var f = myDoc.getElementsByTagName('form');
|
| 29 |
for (var i=0; i<f.length; i++) {
|
| 30 |
// Is this textarea is using an input format?
|
| 31 |
if (f[i]['edit-format']) {
|
| 32 |
hasInputFormat = true;
|
| 33 |
}
|
| 34 |
if (f[i][textarea]) {
|
| 35 |
myForm = f[i];
|
| 36 |
myTextarea = f[i][textarea];
|
| 37 |
break;
|
| 38 |
}
|
| 39 |
}
|
| 40 |
}
|
| 41 |
frames['img_assist_main'].window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/thumbs/img_assist_browser';
|
| 42 |
}
|
| 43 |
|
| 44 |
function initProperties() {
|
| 45 |
setHeader('properties');
|
| 46 |
updateCaption();
|
| 47 |
onChangeLink();
|
| 48 |
onChangeSizeLabel();
|
| 49 |
}
|
| 50 |
|
| 51 |
function initThumbs() {
|
| 52 |
setHeader('browse');
|
| 53 |
}
|
| 54 |
|
| 55 |
function initHeader() {
|
| 56 |
}
|
| 57 |
|
| 58 |
function initUpload() {
|
| 59 |
setHeader('uploading');
|
| 60 |
}
|
| 61 |
|
| 62 |
function getFilterTag(formObj) {
|
| 63 |
var nid = formObj['edit-nid'].value;
|
| 64 |
var captionTitle = formObj['edit-title'].value;
|
| 65 |
var captionDesc = formObj['edit-desc'].value;
|
| 66 |
var link = formObj['edit-link'].value;
|
| 67 |
var url = formObj['edit-url'].value;
|
| 68 |
var align = formObj['edit-align'].value;
|
| 69 |
var width = formObj['edit-width'].value;
|
| 70 |
var height = formObj['edit-height'].value;
|
| 71 |
|
| 72 |
// Create the image placeholder tag
|
| 73 |
var miscAttribs = 'nid=' + nid + '|title=' + captionTitle + '|desc=' + captionDesc + '|link=' + link;
|
| 74 |
if (url != formObj['edit-default-url'].value) {
|
| 75 |
miscAttribs += '|url=' + url;
|
| 76 |
}
|
| 77 |
var content = '[img_assist|' + miscAttribs + '' + '|align=' + align + '|width=' + width + '|height=' + height + ']';
|
| 78 |
|
| 79 |
return content;
|
| 80 |
}
|
| 81 |
|
| 82 |
function insertToEditor(content) {
|
| 83 |
// Insert the image
|
| 84 |
if (myDoc.selection) {
|
| 85 |
// IE
|
| 86 |
myTextarea.focus();
|
| 87 |
cursor = myDoc.selection.createRange();
|
| 88 |
cursor.text = content;
|
| 89 |
}
|
| 90 |
else if (myTextarea.selectionStart || myTextarea.selectionStart == "0") {
|
| 91 |
// Gecko-based engines: Mozilla, Camino, Firefox, Netscape
|
| 92 |
var startPos = myTextarea.selectionStart;
|
| 93 |
var endPos = myTextarea.selectionEnd;
|
| 94 |
var body = myTextarea.value;
|
| 95 |
myTextarea.value = body.substring(0, startPos) + content + body.substring(endPos, body.length);
|
| 96 |
}
|
| 97 |
else {
|
| 98 |
// Worst case scenario: browsers that don't know about cursor position:
|
| 99 |
// Safari, OmniWeb, Konqueror
|
| 100 |
myTextarea.value += content;
|
| 101 |
}
|
| 102 |
|
| 103 |
// Close the dialog
|
| 104 |
return cancelAction();
|
| 105 |
}
|
| 106 |
|
| 107 |
function cancelAction() {
|
| 108 |
// Close the dialog
|
| 109 |
window.close();
|
| 110 |
return false;
|
| 111 |
}
|
| 112 |
|
| 113 |
/**
|
| 114 |
* getArgs() by Jim K - From Orielly JSB pp 244
|
| 115 |
*
|
| 116 |
* This function parses comma separated name=value argument pairs from the query
|
| 117 |
* string of the URL. It stores the name=value pairs in properties of an object
|
| 118 |
* and then returns that object.
|
| 119 |
*
|
| 120 |
* @example
|
| 121 |
* var args = getArgs();
|
| 122 |
* alert(args.CSSPATH);
|
| 123 |
*/
|
| 124 |
function getArgs() {
|
| 125 |
var args = new Object();
|
| 126 |
|
| 127 |
var query = location.search.substring(1); // Get Query String
|
| 128 |
var pairs = query.split("&"); // Split query at the ampersand
|
| 129 |
|
| 130 |
for(var i = 0; i < pairs.length; i++) { // Begin loop through the querystring
|
| 131 |
var pos = pairs[i].indexOf('='); // Look for "name=value"
|
| 132 |
if (pos == -1) continue; // if not found, skip to next
|
| 133 |
|
| 134 |
var argname = pairs[i].substring(0,pos); // Extract the name
|
| 135 |
var value = pairs[i].substring(pos+1); // Extract the value
|
| 136 |
args[argname] = unescape(value); // Store as a property
|
| 137 |
}
|
| 138 |
return args; // Return the Object
|
| 139 |
}
|
| 140 |
|