Okay so i followed a tutorial on how to create a wysiwyg rich text editor. The script has a function that makes it possible to take an image uploaded on an another site and use it. What i want though is to let the user upload an image directly into the text editor. Is there a way to do that in javascript? and if so, can you guys please help me write it, cause i can't find anything on the web about it... ?
btw, is it possible to write a function that allows the user to show a video from youtube just by entering the url address?
[syntax=php]function iFrameOn(){
richTextField.document.designMode = 'On';
}
function iBold(){
richTextField.document.execCommand('bold',false,null);
}
function iUnderline(){
richTextField.document.execCommand('underline',false,null);
}
function iItalic(){
richTextField.document.execCommand('italic',false,null);
}
function iFontSize(){
var size = prompt('Enter a size 1 - 7', '');
richTextField.document.execCommand('FontSize',false,size);
}
function iForeColor(){
var color = prompt('Define a basic color or apply a hexadecimal color code for advanced colors:', '');
richTextField.document.execCommand('ForeColor',false,color);
}
function iHorizontalRule(){
richTextField.document.execCommand('inserthorizontalrule',false,null);
}
function iUnorderedList(){
richTextField.document.execCommand("InsertOrderedList", false,"newOL");
}
function iOrderedList(){
richTextField.document.execCommand("InsertUnorderedList", false,"newUL");
}
function iLink(){
var linkURL = prompt("Enter the URL for this link:", "http://");
richTextField.document.execCommand("CreateLink", false, linkURL);
}
function iUnLink(){
richTextField.document.execCommand("Unlink", false, null);
}
function iImage(){
var imgSrc = prompt('Enter image location', '');
if(imgSrc != null){
richTextField.document.execCommand('insertimage', false, imgSrc);
}
}
function submit_form(){
var theForm = document.getElementById("form1");
theForm.elements["content"].value = window.frames['richTextField'].document.body.innerHTML;
theForm.submit();
}[/syntax]
Essentially it seems this script adds images from URLs entered by the user. In order to upload directly to your editor you would need a few things. One of them would be an upload script, which would likely be a PHP or ASP script that handles an upload form. Secondly, you would need a place to store all of the images since you are now handling the uploads yourself rather than linking to existing files on the internet. You may also need some additional scripts to handle/manage the uploaded files.
As for displaying YouTube videos from only the URL, this can be done using YouTube's new embed code and a simple JavaScript function like so:
Wait, you mean... You're writing your own wysiwyg editor from scratch? If so, and i don't mean to be a smartass, but why are you doing that?
As for uploading images, that cannot be executed without server side coding. I'm not sure if you're accidently on the wrong subforum, but you can't actually upload an image with Javascript. That's more of a PHP question. Once you upload it with ASP or PHP and you get the new image URL as a response, your problem will get real trivial real fast.
Youtube question - Yes, it is. You need to go to any Youtube video and copy the embed code. Then you need to remove the Youtube ID from it. Then you need a user to enter some video URL as you said you'd like them to. Then, you apply a regular expression to extract the video ID from that URL. And finally you insert that ID into the embed code where the ID goes and write that onto the document.
i love easter eggs
(if you got any creative easter eggs, send me a PM)
Bookmarks