Jump to content

[SOLVED] Basic VERY basic WYSIWYG Editor for smileys


TheFilmGod

Recommended Posts

I would like to add smileys to my blog - but keep it basic basic very basic. Pretty much a simple textarea with the option to add a smiley here and a smiley there. Trick is, I would like the smileys to be added at the cursor's location and even replace text if it's highlighted. - Just like it's done on phpfreaks, but I don't want all the other fancy tags (bold, italics, pictures, font size or face, etc)...

 

Maybe someone knows of a good tutorial or someone can lead me to the right direction. Google hasn't been very helpful.

Perhaps this could be helpful to you:

 

http://www.almsamim.com/create-your-own-advanced-wysiwyg-editor-part-1-t10.html

 

I've not read it myself but the comments seem positive. I dare say in order to create your own custom 'basic' editor, you're probably going to have to learn some of the advanced stuff as well.

I finally got it to work. I just needed some javascript to add "text" smileys at the cursor point.

 

	// Add symbol to textarea
		// Cache textarea
		textarea = document.getElementById('textboxer');

		// IE support
		if (document.selection) {
			textarea.focus();
			sel = document.selection.createRange();
			sel.text = symbol;
		}
		//MOZILLA/NETSCAPE support
		else if (textarea.selectionStart || textarea.selectionStart == '0') {
			textarea.focus();
			var startPos = textarea.selectionStart;
			var endPos = textarea.selectionEnd;
			textarea.value = textarea.value.substring(0, startPos) + symbol + textarea.value.substring(endPos, textarea.value.length);
		}
		// Default to appending the smiley at the end
		else {
			textarea.value += symbol;
		}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.