View Single Post
ישן 26-05-06, 20:57   # 1
-roee-
חבר על
 
מיני פרופיל
תאריך הצטרפות: Nov 2005
מיקום: IL
הודעות: 864

-roee- לא מחובר  

למה זה לא עובד לי? ב JS

זה אמור להיות מערכת עם BBCODES...

editor.html
קוד:
<head>

<script language='Javascript' src='jscripts/editor.js'></script>
</head>
<script language="javascript">
var b_prompt = "&#228;&#235;&#240;&#241; &#224;&#250; &#228;&#232;÷&#241;&#232; &#249;&#225;&#248;&#246;&#229;&#240;&#234; &#236;&#228;&#227;&#226;&#233;&#249;";
var i_prompt = "&#228;&#235;&#240;&#241; &#224;&#250; &#228;&#232;÷&#241;&#232; &#249;&#224;&#250;&#228; &#248;&#229;&#246;&#228; &#249;&#233;&#228;&#233;&#228; &#240;&#232;&#229;&#233;";
var u_prompt = "&#228;&#235;&#240;&#241; &#224;&#250; &#228;&#232;÷&#241;&#232; &#249;&#225;&#248;&#246;&#229;&#240;&#234; &#236;&#228;&#229;&#241;&#233;&#243; &#236;&#229; ÷&#229; &#250;&#231;&#250;&#229;&#239;";
var font_prompt = "&#228;&#235;&#240;&#241; &#224;&#250; &#228;&#232;÷&#241;&#232; &#249;&#225;&#248;&#246;&#229;&#240;&#234; &#236;&#249;&#240;&#229;&#250; &#236;&#229; &#224;&#250; &#228;&#244;&#229;&#240;&#232;";
var size_prompt = "&#228;&#235;&#240;&#241; &#224;&#250; &#228;&#232;÷&#241;&#232; &#249;&#225;&#248;&#246;&#229;&#240;&#234; &#236;&#249;&#240;&#229;&#250; &#236;&#229; &#224;&#250; &#228;&#226;&#229;&#227;&#236;";
var color_prompt = "&#228;&#235;&#240;&#241; &#224;&#250; &#228;&#232;÷&#241;&#232; &#249;&#225;&#248;&#246;&#229;&#240;&#234; &#236;&#249;&#240;&#229;&#250; &#236;&#229; &#224;&#250; &#228;&#246;&#225;&#242;";
var align_prompt = "&#228;&#235;&#240;&#241; &#224;&#250; &#228;&#232;÷&#241;&#232; &#249;&#225;&#248;&#246;&#229;&#240;&#234; &#236;&#233;&#233;&#249;&#248;";
var quote_prompt = "&#228;&#235;&#240;&#241; &#224;&#250; &#228;&#232;÷&#241;&#232; &#249;&#225;&#248;&#246;&#229;&#240;&#234; &#236;&#246;&#232;&#232;";
var code_prompt = "&#228;&#235;&#240;&#241; &#224;&#250; &#228;&#232;÷&#241;&#232; &#249;&#225;&#248;&#246;&#229;&#240;&#234; &#236;&#228;&#229;&#241;&#233;&#243; &#236;&#229; &#250;&#226;&#233;&#227; ÷&#229;&#227;";
var php_prompt = "&#228;&#235;&#240;&#241; &#224;&#250; &#228;&#232;÷&#241;&#232; &#249;&#225;&#248;&#246;&#229;&#240;&#234; &#236;&#228;&#229;&#241;&#233;&#243; &#236;&#229; &#250;&#226;&#233; PHP";
</script>
<tr>
<td bgcolor="#F0F0F0">
<table cellspacing="0" cellpadding="2" border="0"><tr>
<td>
<select name="font" onchange="insertCode('font', this.options[this.selectedIndex].value)">
<option value="-">&#244;&#229;&#240;&#232;</option>
<option value="Arial">Arial</option>
<option value="Courier">Courier</option>
<option value="Impact">Impact</option>
<option value="Tahoma">Tahoma</option>
<option value="Times New Roman">Times New Roman</option>
<option value="Trebuchet MS">Terbuchet MS</option>
<option value="Verdana">Verdana</option>
</select>
</td>
<td>
<select name="size" onchange="insertCode('size', this.options[this.selectedIndex].value)">
<option value="-">&#226;&#229;&#227;&#236;</option>
<option value="small">÷&#232;&#239;</option>
<option value="medium">&#225;&#233;&#240;&#229;&#240;&#233;</option>
<option value="large">&#226;&#227;&#229;&#236;</option>
<option value="x-large">&#226;&#227;&#229;&#236; &#238;&#224;&#229;&#227;</option>
<option value="xx-large">&#242;&#240;÷</option>
</select>
</td>
<td>
<select name="color" onchange="insertCode('color', this.options[this.selectedIndex].value)">
<option value="-">&#246;&#225;&#242;</option>
<option value="white" style="color:white;">&#236;&#225;&#239;</option>
<option value="black" style="color:black;">&#249;&#231;&#229;&#248;</option>
<option value="red" style="color:red;">&#224;&#227;&#229;&#237;</option>
<option value="yellow" style="color:yellow;">&#246;&#228;&#229;&#225;</option>
<option value="pink" style="color:pink;">&#229;&#248;&#229;&#227;</option>
<option value="green" style="color:green;">&#233;&#248;&#229;÷</option>
<option value="orange" style="color:orange;">&#235;&#250;&#229;&#237;</option>
<option value="purple" style="color:purple;">&#241;&#226;&#229;&#236;</option>
<option value="blue" style="color:blue;">&#235;&#231;&#229;&#236;</option>
<option value="beige" style="color:beige;">&#225;&#230;</option>
<option value="brown" style="color:brown;">&#231;&#229;&#237;</option>
<option value="teal" style="color:teal;">&#250;&#235;&#236;&#250;</option>
<option value="navy" style="color:navy;">&#235;&#231;&#229;&#236; &#235;&#228;&#228;</option>
<option value="maroon" style="color:maroon;">&#225;&#229;&#248;&#227;&#229;</option>
<option value="limegreen" style="color:limegreen;">&#233;&#248;&#229;÷ &#236;&#233;&#238;&#229;&#239;</option></select>
</select>
</td>
</tr></table>
</td>
<td nowrap bgcolor="#F0F0F0" align="right"><input type="button" style="color: red; font: bold 11px verdana" value="&#241;&#226;&#229;&#248; &#224;&#250; &#235;&#236; &#228;&#250;&#226;&#233;&#237;" onclick="closeTags()"></td>
</tr>
<tr>
<td nowrap bgcolor="#F0F0F0" colspan="2">
<table cellspacing="0" cellpadding="0" border="0"><tr>
<td>
<img name="b" src="./images/editor/bold.gif" onclick="insertCode('b')" onMouseOver="toolbarHover('b')" onMouseOut="toolbarUnHover('b')" onMouseDown="toolbarMouseDown('b')" alt="&#232;÷&#241;&#232; &#225;&#229;&#236;&#232;">
<img name="i" src="./images/editor/italics.gif" onclick="insertCode('i')" onMouseOver="toolbarHover('i')" onMouseOut="toolbarUnHover('i')" onMouseDown="toolbarMouseDown('i')" alt="&#232;÷&#241;&#232; &#240;&#232;&#229;&#233;">
<img name="u" src="./images/editor/underline.gif" onclick="insertCode('u')" onMouseOver="toolbarHover('u')" onMouseOut="toolbarUnHover('u')" onMouseDown="toolbarMouseDown('u')" alt="÷&#229; &#250;&#231;&#250;&#229;&#239;">
<img src="./images/editor/sep.gif" class="toolbar_normal">
<img name="align_left" src="./images/editor/align_left.gif" onclick="insertCode('align', 'left')" onMouseOver="toolbarHover('align_left')" onMouseOut="toolbarUnHover('align_left')" onMouseDown="toolbarMouseDown('align_left')" alt="&#233;&#233;&#249;&#229;&#248; &#236;&#249;&#238;&#224;&#236;">
<img name="align_center" src="./images/editor/align_center.gif" onclick="insertCode('align', 'center')" onMouseOver="toolbarHover('align_center')" onMouseOut="toolbarUnHover('align_center')" onMouseDown="toolbarMouseDown('align_center')" alt="&#233;&#233;&#249;&#229;&#248; &#236;&#224;&#238;&#246;&#242;">
<img name="align_right" src="./images/editor/align_right.gif" onclick="insertCode('align', 'right')" onMouseOver="toolbarHover('align_right')" onMouseOut="toolbarUnHover('align_right')" onMouseDown="toolbarMouseDown('align_right')" alt="&#233;&#249;&#229;&#248; &#236;&#233;&#238;&#233;&#239;">
<img name="align_justify" src="./images/editor/align_justify.gif" onclick="insertCode('align', 'justify')" onMouseOver="toolbarHover('align_justify')" onMouseOut="toolbarUnHover('align_justify')" onMouseDown="toolbarMouseDown('align_justify')" alt="Justify">
<img src="./images/editor/sep.gif">
<img name="list_num" src="./images/editor/list_num.gif" onclick="insertCode('list', '1')" onMouseOver="toolbarHover('list_num')" onMouseOut="toolbarUnHover('list_num')" onMouseDown="toolbarMouseDown('list_num')" alt="&#248;&#249;&#233;&#238;&#228; &#238;&#238;&#229;&#241;&#244;&#248;&#250;">
<img name="list_bullet" src="./images/editor/list_bullet.gif" onclick="insertCode('list')" onMouseOver="toolbarHover('list_bullet')" onMouseOut="toolbarUnHover('list_bullet')" onMouseDown="toolbarMouseDown('list_bullet')" alt="&#248;&#249;&#233;&#238;&#228;">
<img src="./images/editor/sep.gif">
<img name="img" src="./images/editor/image.gif" onclick="insertCode('img')" onMouseOver="toolbarHover('img')" onMouseOut="toolbarUnHover('img')" onMouseDown="toolbarMouseDown('img')" alt="&#250;&#238;&#229;&#240;&#228;">
<img name="url" src="./images/editor/url.gif" onclick="insertCode('url')" onMouseOver="toolbarHover('url')" onMouseOut="toolbarUnHover('url')" onMouseDown="toolbarMouseDown('url')" alt="÷&#233;&#249;&#229;&#248;">
<img name="email" src="./images/editor/email.gif" onclick="insertCode('email')" onMouseOver="toolbarHover('email')" onMouseOut="toolbarUnHover('email')" onMouseDown="toolbarMouseDown('email')" alt="&#227;&#229;&#224;&#248; &#224;&#236;÷&#232;&#248;&#229;&#240;&#233;">
<img src="./images/editor/sep.gif">
<img name="quote" src="./images/editor/quote.gif" onclick="insertCode('quote')"  onMouseOver="toolbarHover('quote')" onMouseOut="toolbarUnHover('quote')" onMouseDown="toolbarMouseDown('quote')" alt="&#246;&#233;&#232;&#229;&#232;">
<img name="code" src="./images/editor/code.gif" onclick="insertCode('code')" onMouseOver="toolbarHover('code')" onMouseOut="toolbarUnHover('code')" onMouseDown="toolbarMouseDown('code')" alt="÷&#229;&#227;">
<img name="php" src="./images/editor/php.gif" onclick="insertCode('php')" onMouseOver="toolbarHover('php')" onMouseOut="toolbarUnHover('php')" onMouseDown="toolbarMouseDown('php')" alt="PHP">
</td>
</tr></table>
</td>
</tr>

<textarea name="message" rows="20" cols="70" tabindex="3"></textarea>
jscripts/editor.js
HTML קוד:
var myTags = new Array();
var buttonOver = "";

init();

function init() {
	var cookies = document.cookie;
	var cookiename = "cb_mode=";
	var cstart = cookies.indexOf("; "+cookiename);
	if(cstart == -1) {
		cstart = cookies.indexOf(" "+cookiename);
		if(cstart != 0) {
			normalmode = false;
		}
	} else {
		cstart += 2;
	}
	var end = cookies.indexOf(";", cstart);
	if(end == -1) {
		end = cookies.length;
	}
	theMode = unescape(cookies.substring((cstart + cookiename.length)+1, end));
	if(theMode == "normal") {
		document.input.mode[0].checked = true;
		document.input.mode[1].checked = false;
		normalmode = true;
	} else {
		document.input.mode[1].checked = true;
		document.input.mode[0].checked = false;
		normalmode = false;
	}
}

function changeMode(newMode) {
	document.cookie = "cb_mode="+newMode+"; path=/; expires=Wed, 1 Jan 2020 00:00:00 GMT;";
	if(newMode == "normal") {
		normalmode = true;
	} else {
		normalmode = false;
	}
}

function garraySize(arrayName) {
	for (i=0;i<arrayName.length;i++) {
		if((arrayName[i] == "undefined") || (arrayName[i] == "") || (arrayName[i] == null)) {
			return i;
		}
	}
	return arrayName.length;
}

function arrayPush(arrayName, arrayValue) {
	arraySize = garraySize(arrayName);
	arrayName[arraySize] = arrayValue;
}

function arrayPop(arrayName) {
	arrayMo = garraySize(arrayName);
	arrayValue = arrayName[arrayMo - 1];
	delete arrayName[arrayMo - 1];
	return arrayValue;
}

function inArray(item, arrayName) {
	for(i=0;i<arrayName.length;i++) {
		if(arrayName[i] == item) {
			return true;
		}
	}
	return false;
}
function arrayPos(item, arrayName) {
	for(i=0;i<arrayName.length;i++) {
		if(arrayName[i] == item) {
			return i;
		}
	}
	return 0;
}

function insertList(type) {
	if(type) {
		theList = "[list="+type+"]\n";
	} else {
		theList = "[list]\n";
	}
	promptRes = "1";
	while((promptRes != "") && (promptRes != null)) {
		promptRes = prompt("Enter a list item. Click cancel or leave blank to end the list.", "");
		if((promptRes != "") && (promptRes != null)) {
			theList = theList+"[*]"+promptRes+"\n";
		}
	}
	theList = theList+"[/list]\n";
	doInsert(theList);
}
function insertHyperlink() {
	var url = prompt("Please enter the URL of the website.", "http://");
	if(url) {
		var urltitle = prompt("If you wish to, you may also insert a title to be shown instead of the URL.", "");
		if(urltitle) {
			doInsert("[url="+url+"]"+urltitle+"[/url]", "", false);
		} else {
			doInsert("[url]"+url+"[/url]", "", false);
		}
	} else {
		alert("Error!\n\nYou did not enter a URL for the website. Please try again.");
	}
}
function insertImage() {
	var image = prompt("Please enter the remote URL of the image.", "http://");
	if(image) {
		doInsert("[img]"+image+"[/img]", "", false);
	} else {
		alert("Error!\n\nYou did not enter a URL for the image. Please try again.");
	}
}
function insertEmail() {
	var email = prompt("Please enter the email address.", "");
	if(email) {
		var emailtitle = prompt("If you wish to, you may also insert a title to be shown instead of the email address.", "My Email Address");
		if(emailtitle) {
			doInsert("[email="+email+"]"+emailtitle+"[/email]", "", false);
		} else {
			doInsert("[email]"+email+"[/email]", "", false);
		}
	} else {
		alert("Error!\n\nYou did not enter a valid email address. Please try again.");
	}
}
function insertCode(myCode,selItem) {
	if(myCode == "list") {
		insertList(selItem);
	} else if(myCode == "url") {
		insertHyperlink();
	} else if(myCode == "img") {
		insertImage();
	} else if(myCode == "email") {
		insertEmail();
	} else {
		if(normalmode) {
			var prompttext = eval(myCode + "_prompt");
			if(selItem) {
				if(selItem != "-") {
					promptres = prompt(prompttext + "\n["+myCode+"="+selItem+"]xxx[/"+myCode+"]", "");
				}
			} else {
				promptres = prompt(prompttext + "\n["+myCode+"]xxx[/"+myCode+"]", "");
			}
			if((promptres != null) && (promptres != "")) {
				if(selItem) {
					if(selItem != "-") {
						doInsert("["+myCode+"="+selItem+"]"+promptres+"[/"+myCode+"]");
					}
				} else {
					doInsert("["+myCode+"]"+promptres+"[/"+myCode+"]");
				}
			} 
		} else {
			var thingA = myCode+"_"+selItem;
			args = thingA.split("_");
			lastIndex = 0;
			alreadyopen = false;
			for(i=0;i<myTags.length;i++) {
				theTag = myTags[i];
				if(theTag) {
					args2 = theTag.split("_");
					if(args2[0] == args[0]) {
						alreadyopen = true;
						lastIndex = i;
					}
				}
			}
			if(alreadyopen) {
				while(myTags[lastIndex]) {
					tagRemove = arrayPop(myTags);
					thingB = tagRemove.split("_");
					doInsert("[/"+thingB[0]+"]", "", false);
					// unclick it
					element = eval("document.images['"+tagRemove+"']");
					if(element && !element.disabled && element.nodeName == "IMG") {
						if(buttonOver == tagRemove) {
							element.className = "toolbar_hover";
						} else {
							element.className = "toolbar_normal";
						}
					}
					if(thingA == tagRemove) { // silly check =P
						noInsert = true;
					}
				}
			}

			if(selItem && selItem != "-" && !noInsert) {
				isClosed = doInsert("["+myCode+"="+selItem+"]", "[/"+myCode+"]", true);
				if(!isClosed) {
					arrayPush(myTags, myCode+"_"+selItem);
				} else {
					// change the buttons status to closed :P
					element = eval("document.images['"+myCode+"']");
					if(element && !element.disabled && element.nodeName == "IMG") {
						element.className = "toolbar_normal";
					}
				}
			}
			else if(!selItem && !alreadyopen) {
				isClosed = doInsert("["+myCode+"]", "[/"+myCode+"]", true);
				if(!isClosed) {
					arrayPush(myTags, myCode);
				} else {
					// change the buttons status to closed :P
					element = eval("document.images['"+myCode+"']");
					if(element && !element.disabled && element.nodeName == "IMG") {
						element.className = "toolbar_normal";
					}
				}
			}
			var alreadyopen = false;
			var noInsert = false;
		}
		if(myCode == "font")
		{
			document.input.font.selectedIndex = "0";
		}
		else if(myCode == "size")
		{
			document.input.size.selectedIndex = "0";
		}
		else if(myCode == "color")
		{
			document.input.color.selectedIndex = "0";
		}
	}
	setFocus(document.input.message);	
}

function closeTags() {
	if(myTags[0]) {
		while(myTags[0]) {
			tagRemove = arrayPop(myTags);
			args = tagRemove.split("_");
			isClosed = doInsert("[/"+args[0]+"]", "", false, true);
			element = eval("document.images['"+tagRemove+"']");
			if(element && !element.disabled && element.nodeName == "IMG") {
				element.className = "toolbar_normal";
			}
		}
	}
	myTags = new Array();
	setFocus(document.input.message);
}

function doInsert(myCode, myClose, singleTag, ignoreSel) {
	isClosed = true;
	if(ignoreSel != true) {
		ignoreSel = false;
	}
	if(!myClose)
	{
		myClose = "";
	}
	var messageBox = document.input.message;
	if(is_ie && is_win && (agt_ver >= 4)) {
		setFocus(messageBox);
		var seltext = document.selection;
		var range = seltext.createRange();
		if(ignoreSel != false) {
			range.collapse;
		}
		if(((seltext.type == "Text" || seltext.type == "None") && range != null) && ignoreSel != true) {
			if(myClose != "" && range.text.length > 0) {
				myCode = myCode+range.text+myClose;
			} else {
				if(singleTag) {
					isClosed = false;
				}
			}
			range.text = myCode;
		} else {
			messageBox.value += myCode;
		}
	}
	else if(is_mozilla && messageBox.selectionEnd) {
		var select_start = messageBox.selectionStart;
		var select_end = messageBox.selectionEnd;
		if(select_end <= 2) {
			select_end = messageBox.textLength;
		}
		var start = (messageBox.value).substring(0, select_start);
		var middle = (messageBox.value).substring(select_start, select_end);
		var end = (messageBox.value).substring(select_end, messageBox.textLength);
		if((messageBox.selectionEnd - messageBox.selectionStart > 0) && ignoreSel != true && myClose != "") {
			middle = myCode+middle+myClose;
		} else {
			if(singleTag) {
				isClosed = false;
			}
			//middle = myCode+middle;
			middle = myCode;
		}
		messageBox.value = start+middle+end;
	}
	else {
		messageBox.value += myCode;
		if(singleTag) {
			isClosed = false;
		}
	}
	setFocus(messageBox);
				
	return isClosed;
}
function setFocus(formElement) {
	formElement.focus();
}
function addsmilie(smilie) {
	doInsert(smilie);
}

// these are our cool functions for hovering/highlighting etc...nifty...huh?
function toolbarHover(myCode, method) {
	element = eval("document.images['"+myCode+"']");
	if(element && !element.disabled && element.nodeName == "IMG") {
		element.className = "toolbar_hover";
		buttonOver = myCode;
	}
}
function toolbarUnHover(myCode) {
	element = eval("document.images['"+myCode+"']");
	if(element && !element.disabled && element.nodeName == "IMG") {
		if(inArray(myCode, myTags)) {
			element.className = "toolbar_clicked";
		} else {
			element.className = "toolbar_normal";
		}
	}
	buttonOver = "";
}
function toolbarMouseDown(myCode) {
	element = eval("document.images['"+myCode+"']");
	if(element && !element.disabled && element.nodeName == "IMG") {
		element.className = "toolbar_mousedown";
	}
}
ובבקשה אל תתחילו לחפור שלקחתי את זה ושאני מעתיקן כי אני יודע שלקחתי את זה ואני רוצה לשלב את זה באתר שלי..
  Reply With Quote