/* Javascript for OCAMLWIKI.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: editor.js,v 1.2 2004/10/26 17:17:08 rich Exp $
+ * $Id: editor.js,v 1.3 2004/10/26 17:42:08 rich Exp $
*/
var delay = 1000; // Delay in milliseconds before updating.
div.innerHTML = edit_buttons_html;
}
-function replace_selection (content_id, fn)
+function replace_selection (content_id, fn, warning)
{
var textarea = document.getElementById (content_id);
var replacement = fn (text);
textarea.value = textarea.value.substring (0, start) +
replacement + textarea.value.substring (end);
- }
+ } else
+ if (warning) alert (warning);
} else if (document.selection) { // IE
var range = document.selection.createRange ();
if (range.parentElement () == textarea && range.text != "") {
// Replace \r\n with just \n.
text = text.replace ("\r\n", "\n");
- /*
- var wtf;
- for (i = 0; i < len; ++i) {
- wtf += "," + text.charCodeAt (i);
- if ((i % 32) == 0) wtf += "\n";
- }
- alert (wtf);
- */
-
// IE's selections often include a trailing space or carriage
// return. Ignore this whitespace when calling the replacement
// function.
if (append) replacement += "\n";
range.text = replacement;
- }
+ } else
+ if (warning) alert (warning);
}
}
else
return "[[" + text + "]]";
};
- replace_selection (content_id, fn);
+ var warning = "Select an area of text first.";
+ replace_selection (content_id, fn, warning);
update_preview_now (content_id, preview_id);
}
else
return "<b>" + text + "</b>";
};
- replace_selection (content_id, fn);
+ var warning = "Select an area of text first.";
+ replace_selection (content_id, fn, warning);
update_preview_now (content_id, preview_id);
}
else
return "<i>" + text + "</i>";
};
- replace_selection (content_id, fn);
+ var warning = "Select an area of text first.";
+ replace_selection (content_id, fn, warning);
update_preview_now (content_id, preview_id);
}
else
return "<s>" + text + "</s>";
};
- replace_selection (content_id, fn);
+ var warning = "Select an area of text first.";
+ replace_selection (content_id, fn, warning);
update_preview_now (content_id, preview_id);
}
else
return "* " + text.replace (/\n/g, "\n* ");
};
- replace_selection (content_id, fn);
+ var warning = "Select some whole lines of text first.";
+ replace_selection (content_id, fn, warning);
update_preview_now (content_id, preview_id);
}
else
return "# " + text.replace (/\n/g, "\n# ");
};
- replace_selection (content_id, fn);
+ var warning = "Select some whole lines of text first.";
+ replace_selection (content_id, fn, warning);
update_preview_now (content_id, preview_id);
}