All pastes #97525 Raw Edit

Something

public text v1 · immutable
#97525 ·published 2006-07-23 20:41 UTC
rendered paste body
		<script language="javascript">
			//<!--
			
			var chat_history = [];
			var index = -1;
			var limit = 10;
			
			$("#input_form").bind("submit", function(e) {
				if($("#input_message").val() !== "") {
					index = -1;
					chat_history.unshift($("#input_message").val());
					$("#input_form").get(0).submit();
					$("#input_message").set("value", "").get(0).focus();
					return false;
				}
			});
			
			$("#input_message").bind("keydown", function(e) {
				// increase or decrease index
				if(e.keyCode == 38 || e.keyCode == 40) {
					if(e.keyCode == 38) {
						if(index < chat_history.length) {
							index++;
						}
					} else {
						if(index >= 0) {
							index--;
						}
					}
					
					// limiting the array
					if(chat_history.length - 1 == limit) {
						chat_history.pop();
					}
					
					// returning the string
					ret = "";
					if(typeof chat_history[index] != "undefined") {
						ret = chat_history[index];
					}
					$(this).val(ret);
				}
			});
			
			//-->
		</script>