Seite 1 von 1

[Fix_BBCode] Fix BBCode and Emoticon insertion - EaysMOD-Ver

Verfasst: 05.06.2007 21:26
von hanker
Betrifft MOD: [mod=Fix_BBCode]Fix BBCode and Emoticon insertion[/mod]

Hallo!

Habe mal wieder zugeschlagen, und eine weitere EaysMOD-fähige Variante erstellt. Getestet mit EasyMOD 0.3.0 und phpBB 2.0.22.

Code: Alles auswählen

################################################################################
##
## Mod Title:		Fix BBCode and Emoticon insertion
## Mod Author:		AmigaLink < webmaster@amigalink.de > (Markus Schmidt) http://www.EssenMitFreude.info & http://www.AmigaLink.de
##
## Mod Description:	Insert BBCode and Emoticons, into a post, at the caret position instead of putting it at the bottom.
##
## Mod Version:		1.0.1a
##
##
## Compatibility:	2.0.8 - 2.0.22
## Installation Level:	Easy
## Installation Time:	2 Minutes
##
## Files To Edit:	2
##			templates/subSilver/posting_body.tpl
##			templates/subSilver/posting_smilies.tpl
##
## Included Files:	0
##
##
## Author Notes:	This MOD based on works from Lord Z (Jelle Aalbers) http://www.znok.tk (Accurate BBCode Insertion MOD)
##			and Joe Dalton http://www.jawe.net which can be found under http://www.phpbb.com/community/viewtopic.php?t=247629
##			I only extended the code to insert correctly the font size, the font color and the emoticons.
##			In addition I corrected the emoticon insert from the popup window.
##
## Copyright:		©2007 AmigaLink
##
################################################################################
##
##  The following sites also contain the latest version of this MOD:
## 
##  http://www.AmigaLink.de
##  http://www.phpBBhacks.com
## 
##  Full support for this MOD can be obtained at:
##
##  http://www.AmigaLink.de
##
################################################################################
##
##  This MOD is released under the GPL License v2. 
##  This MOD can be freely used, but not distributed, without permission.
##  Intellectual Property Rights are retained by the hack author(s) 
##  listed above.
##
################################################################################
##
## MOD History:
##
##   2007-06-05 - Version 1.0.1a
##	- Fix typo posing_body.tpl (hanker@rpg-domain.de)
##	- Fix some problem with EasyMOD and phpBB 2.0.22 (if (donotinsert) {  // Close all open tags [...])
##
##   2007-06-01 - Version 1.0.1
##	- Fix the jump to top of large texts problem
##
##   2007-05-31 - Version 1.0.0
##	- First release
##
################################################################################
##
##  Before adding this hack to your forum, you should back up all files related to this MOD.
##
################################################################################
#
#-----[ OPEN ]----------------------------------------------------------------
#

templates/subSilver/posting_body.tpl

#
#-----[ FIND ]----------------------------------------------------------------
#

function emoticon(text) {
	var txtarea = document.post.message;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

#
#-----[ REPLACE WITH ]--------------------------------------------------------
#

function bbplace(text) {
	var txtarea = document.post.message;
	var scrollTop = (typeof(txtarea.scrollTop) == 'number' ? txtarea.scrollTop : -1);
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else if (txtarea.selectionStart || txtarea.selectionStart == '0') {
		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		txtarea.value = txtarea.value.substring(0, startPos)
			+ text
			+ txtarea.value.substring(endPos, txtarea.value.length);
		txtarea.focus();
		txtarea.selectionStart = startPos + text.length;
		txtarea.selectionEnd = startPos + text.length;
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
	if(scrollTop >= 0 ) { txtarea.scrollTop = scrollTop;}
}

function emoticon(text) {
	text = ' ' + text + ' ';
	bbplace(text);
}

#
#-----[ FIND ]----------------------------------------------------------------
#

		if (!theSelection) {
			txtarea.value += bbopen + bbclose;
			txtarea.focus();

#
#-----[ REPLACE WITH ]--------------------------------------------------------
#

		if (!theSelection) {
			bbplace(bbopen + bbclose);

#
#-----[ FIND ]----------------------------------------------------------------
#

	else
	{
		txtarea.value += bbopen + bbclose;
		txtarea.focus();

#
#-----[ REPLACE WITH ]--------------------------------------------------------
#

	else
	{
		bbplace(bbopen + bbclose);

#
#-----[ FIND ]----------------------------------------------------------------
#

	if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];

#
#-----[ REPLACE WITH ]--------------------------------------------------------
#

	if (donotinsert) {      // Close all open tags up to the one just clicked & default button names
		 while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				bbplace(bbtags[butnumber + 1]);

#
#-----[ FIND ]----------------------------------------------------------------
#

		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			txtarea.value += bbtags[15];

#
#-----[ REPLACE WITH ]--------------------------------------------------------
#

		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			bbplace(bbtags[15]);

#
#-----[ FIND ]----------------------------------------------------------------
#

		// Open tag
		txtarea.value += bbtags[bbnumber];

#
#-----[ REPLACE WITH ]--------------------------------------------------------
#

		// Open tag
		bbplace(bbtags[bbnumber]);

#
#-----[ FIND ]----------------------------------------------------------------
#

// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2) 
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}

#
#-----[ REPLACE WITH ]--------------------------------------------------------
#

// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
	if (txtarea.selectionEnd > txtarea.value.length) { txtarea.selectionEnd = txtarea.value.length; }

	var oldPos = txtarea.scrollTop;
	var oldHght = txtarea.scrollHeight;

	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd+open.length;

	txtarea.value = txtarea.value.slice(0,selStart)+open+txtarea.value.slice(selStart); 
	txtarea.value = txtarea.value.slice(0,selEnd)+close+txtarea.value.slice(selEnd);

	txtarea.selectionStart = selStart+open.length;
	txtarea.selectionEnd = selEnd;

	var newHght = txtarea.scrollHeight - oldHght;
	txtarea.scrollTop = oldPos + newHght;

	txtarea.focus();
}

#
#-----[ OPEN ]----------------------------------------------------------------
#

templates/subSilver/posting_smilies.tpl

#
#-----[ FIND ]----------------------------------------------------------------
#

function emoticon(text) {
	text = ' ' + text + ' ';
	if (opener.document.forms['post'].message.createTextRange && opener.document.forms['post'].message.caretPos) {
		var caretPos = opener.document.forms['post'].message.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		opener.document.forms['post'].message.focus();
	} else {
	opener.document.forms['post'].message.value  += text;
	opener.document.forms['post'].message.focus();
	}
}

#
#-----[ REPLACE WITH ]--------------------------------------------------------
#

function emoticon(text) {
	text = ' ' + text + ' ';
	var txtarea = opener.document.forms['post'].message;
	var scrollTop = (typeof(txtarea.scrollTop) == 'number' ? txtarea.scrollTop : -1);
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else if (txtarea.selectionStart || txtarea.selectionStart == '0') {
		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		txtarea.value = txtarea.value.substring(0, startPos)
			+ text
			+ txtarea.value.substring(endPos, txtarea.value.length);
	txtarea.focus();
	txtarea.selectionStart = startPos + text.length;
	txtarea.selectionEnd = startPos + text.length;
	} else {
		opener.document.forms['post'].message.value  += text;
		opener.document.forms['post'].message.focus();
	}
	if(scrollTop >= 0 ) { txtarea.scrollTop = scrollTop;}
}

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------------
#
# EoM
René