package com.sodonsolution.android.components;
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Toast;
import com.sodonsolution.android.R;
import java.io.IOException;
public class SimpleMediaPlayerActivity extends Activity implements
OnBufferingUpdateListener, OnCompletionListener,
OnPreparedListener, OnVideoSizeChangedListener, SurfaceHolder.Callback {
private static final String TAG = "MediaPlayerDemo";
private int mVideoWidth;
private int mVideoHeight;
private MediaPlayer mMediaPlayer;
private SurfaceView mPreview;
private SurfaceHolder holder;
private String path;
private Bundle extras;
private static final String MEDIA = "media";
private static final int LOCAL_AUDIO = 1;
private static final int STREAM_AUDIO = 2;
private static final int RESOURCES_AUDIO = 3;
private static final int LOCAL_VIDEO = 4;
private static final int STREAM_VIDEO = 5;
private boolean mIsVideoSizeKnown = false;
private boolean mIsVideoReadyToBePlayed = false;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.simple);
mPreview = (SurfaceView) findViewById(R.id.surface);
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
extras = getIntent().getExtras();
if (extras == null) {
extras = new Bundle();
extras.putInt(MEDIA, STREAM_VIDEO);
}
}
private void playVideo(Integer Media) {
doCleanUp();
try {
switch (Media) {
case LOCAL_VIDEO:
/*
* TODO: Set the path variable to a local media file path.
*/
path = "";
if (path == "") {
// Tell the user to provide a media file URL.
Toast
.makeText(
SimpleMediaPlayerActivity.this,
"Please edit SimpleMediaPlayerActivity Activity, "
+ "and set the path variable to your media file path."
+ " Your media file must be stored on sdcard.",
Toast.LENGTH_LONG).show();
}
break;
case STREAM_VIDEO:
/*
* TODO: Set path variable to progressive streamable mp4 or
* 3gpp format URL. Http protocol should be used.
* Mediaplayer can only play "progressive streamable
* contents" which basically means: 1. the movie atom has to
* precede all the media data atoms. 2. The clip has to be
* reasonably interleaved.
*
*/
path = "";
if (path == "") {
// Tell the user to provide a media file URL.
Toast
.makeText(
SimpleMediaPlayerActivity.this,
"Please edit SimpleMediaPlayerActivity Activity,"
+ " and set the path variable to your media file URL.",
Toast.LENGTH_LONG).show();
}
break;
default:
break;
}
path = "http://resource.news.mn/politics/video/2011/1/54557d3baf97cf85/9bd9185c6cd73213.flv";
// Create a new media player and set the listeners
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDisplay(holder);
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
Runnable r = new Runnable() {
public void run() {
try {
mMediaPlayer.setDataSource(path);
} catch (IOException e) {
Log.e(TAG, e.getMessage(), e);
}
try {
mMediaPlayer.prepare();
mMediaPlayer.start();
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
Log.v(TAG, "Duration: ===>" + mMediaPlayer.getDuration());
}
};
new Thread(r).start();
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
}
}
public void onBufferingUpdate(MediaPlayer arg0, int percent) {
Log.d(TAG, "onBufferingUpdate percent:" + percent);
}
public void onCompletion(MediaPlayer arg0) {
Log.d(TAG, "onCompletion called");
}
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
Log.v(TAG, "onVideoSizeChanged called");
if (width == 0 || height == 0) {
Log.e(TAG, "invalid video width(" + width + ") or height(" + height + ")");
return;
}
mIsVideoSizeKnown = true;
mVideoWidth = width;
mVideoHeight = height;
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
startVideoPlayback();
}
}
public void onPrepared(MediaPlayer mediaplayer) {
Log.d(TAG, "onPrepared called");
mIsVideoReadyToBePlayed = true;
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
startVideoPlayback();
}
}
public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int k) {
Log.d(TAG, "surfaceChanged called");
}
public void surfaceDestroyed(SurfaceHolder surfaceholder) {
Log.d(TAG, "surfaceDestroyed called");
}
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surfaceCreated called");
playVideo(extras.getInt(MEDIA));
}
@Override
protected void onPause() {
super.onPause();
releaseMediaPlayer();
doCleanUp();
}
@Override
protected void onDestroy() {
super.onDestroy();
releaseMediaPlayer();
doCleanUp();
}
private void releaseMediaPlayer() {
if (mMediaPlayer != null) {
mMediaPlayer.release();
mMediaPlayer = null;
}
}
private void doCleanUp() {
mVideoWidth = 0;
mVideoHeight = 0;
mIsVideoReadyToBePlayed = false;
mIsVideoSizeKnown = false;
}
private void startVideoPlayback() {
Log.v(TAG, "startVideoPlayback");
holder.setFixedSize(mVideoWidth, mVideoHeight);
mMediaPlayer.start();
}
}
Monday, January 17, 2011
Javascript same code
Санаа авхаар зарим нэг script үүд байна
//=======================================================
// 입력값 검사 관련 함수
//
function isNumeric(el){var pattern=/^(-{0,1})([0-9]+)(\.{0,1})([0-9]*)$/;return (pattern.test(el.value)) ? true : doError(el,"숫자형식을 입력하세요.");}
function isEnglish(el){var pattern=/^([a-zA-Z ]+)$/;return (pattern.test(el.value)) ? true : doError(el,"영문자를 입력하세요.");}
function isEngNumeric(el){var pattern=/^([0-9a-zA-Z ]+)$/;return (pattern.test(el.value)) ? true : doError(el,"영문자와 숫자를 입력하세요.");}
function isNotNull(el,msg){return (el.value.replace(/ /g, "").length>0) ? true : doError(el,msg);}
function isGoodID(el){var pattern=/^[a-zA-Z]{1}[_a-zA-Z0-9-]{3,}$/;return (pattern.test(el.value)) ? true : doError(el,"아이디는 영문자로 시작하고 영숫자, 하이픈(-), 언더바(_)를 조합하여 4자이상으로 입력하세요.");}
function isGoodPass(el){var pattern=/^[_a-zA-Z0-9!#$%&()*+\.:;<=>?@{|}~-]{4,}$/;return (pattern.test(el.value)) ? true : doError(el,"비밀번호는 영숫자와 특수문자(!#$%&()*+-.:;<=>?@^_{|}~)를 조합하여 4자이상으로 입력하세요.");}
function isEmail(el){var pattern=/^[_a-zA-Z0-9-\.]+@[\.a-zA-Z0-9-]+\.[a-zA-Z]+$/;return (pattern.test(el.value)) ? true : doError(el,"올바른 메일주소를 입력하세요.");}
function isDomain(el){var pattern=/^(http:\/\/)?(www\.)?([_가-힝a-zA-Z0-9-]+\.)+[a-zA-Z]{2,3}(\/[_가- 힝a-zA-Z0-9-]+)*/i;return (pattern.test(el.value)) ? true : doError(el,"올바른 URL을 입력하세요.");}
function isPhone(el, value){var pattern=/^([0]{1}[0-9]{1,3})-?([1-9]{1}[0-9]{2,3})-?([0-9]{4})$/; var num=value?value:el.value;if(pattern.test(num)){return true;}else{return doError(el,"올바른 전화번호를 입력하세요.");}}
function isRadioChecked(el, msg){var b=false;if(el.length){for(var i=0; i<el.length; i++)if(el[i].checked){b=true; break}}else b=el.checked; return b ? true : doError(el,msg);}
function isSelected(el, msg, n){if(!n)n=0; return el.selectedIndex>n ? true : doError(el,msg);}
//-------------------------------------------------------
function doError(el,msg){alert(msg);try{el.value="";el.focus();}catch(e){} return false;}
function numOnly(e){var key = (window.event) ? event.keyCode : (e.keyCode!=0 ? e.keyCode : e.charCode); if((key!=8&&key!=9&&key!=13&&key!=46&&key<48)||(key>57)){ if(window.event) e.returnValue=false; else e.preventDefault(); }}
function nextInput(e1,e2,m){if(e1.value.length==m) e2.focus();}
//-------------------------------------------------------
function isJumin(el,value){var pattern=/^([0-9]{6})-?([0-9]{7})$/;var num=value?value:el.value;var msg="올바른 주민등록번호를 입력하세요.";
if(!pattern.test(num)) return doError(el,msg);num=RegExp.$1+RegExp.$2;var sum=0;var last=num.charCodeAt(12)-0x30;var bases="234567892345";
for(var i=0;i<12;i++){if(isNaN(num.substring(i,i+1))) return doError(el,msg);sum+=(num.charCodeAt(i)-0x30)*(bases.charCodeAt(i)-0x30);}
var mod=sum%11;return ((11-mod)%10==last) ? true : doError(el,msg);}
function checkJumin(e1,e2){if(e1.value.length>0 && e2.value.length>0){if(!isJumin(e1,e1.value+e2.value)){e2.value="";return false;} else return true;} else return false;}
//-------------------------------------------------------
function isBusinessNum(el,value){var pattern=/^([0-9]{3})-?([0-9]{2})-?([0-9]{5})$/;var num=value?value:el.value;var msg = "올바른 사업자등록번호를 입력하세요.";
if(!pattern.test(num)) return doError(el,msg);num=RegExp.$1+RegExp.$2+RegExp.$3;
var sum=0;var getlist=new Array(10);var chkvalue=new Array("1","3","7","1","3","7","1","3","5");
for(var i=0;i<10;i++){getlist[i]=num.substring(i,i+1);} for(var i=0;i<9;i++){sum+=getlist[i]*chkvalue[i];}
sum=sum+parseInt((getlist[8]*5)/10);sidliy=sum%10;sidchk=0;if(sidliy!=0){sidchk=10-sidliy;}else{sidchk=0;}
return (sidchk==getlist[9]) ? true : doError(el,msg);}
//-------------------------------------------------------
function isForeignNum(el,value){var pattern=/^([0-9]{6})-?([0-9]{7})$/;var num=value?value:el.value;var msg = "올바른 외국인등록번호를 입력하세요.";
if(!pattern.test(num)) return doError(el,msg);num=RegExp.$1+RegExp.$2;
if((num.charAt(6)=="5")||(num.charAt(6)=="6")) birthYear="19"; else if((num.charAt(6)=="7")||(num.charAt(6)=="8")) birthYear="20";
else if((num.charAt(6)=="9")||(num.charAt(6)=="0")) birthYear="18"; else return doError(el, msg);
birthYear+=num.substr(0,2); birthMonth=num.substr(2,2)-1; birthDate=num.substr(4,2); birth=new Date(birthYear, birthMonth, birthDate);
if(birth.getYear()%100!=num.substr(0,2)||birth.getMonth()!=birthMonth||birth.getDate()!=birthDate) return doError(el,msg);
var sum=0;var odd=0;var buf=new Array(13);for(i=0;i<13;i++){buf[i]=parseInt(num.charAt(i));}
odd=buf[7]*10+buf[8];if(odd%2!=0) return doError(el,msg);if((buf[11]!=6)&&(buf[11]!=7)&&(buf[11]!=8)&&(buf[11]!=9)) return doError(el,msg);
multipliers=[2,3,4,5,6,7,8,9,2,3,4,5];for(i=0,sum=0;i<12;i++){sum+=(buf[i]*=multipliers[i]);}
sum=11-(sum%11);if(sum>=10) sum-=10; sum+=2;if(sum>=10) sum-=10; return (sum==buf[12]) ? true : doError(el,msg);}
//-------------------------------------------------------
function isEmailList(el){el.value=el.value.replace(/ /g,'').replace(/(,)+/g,',').replace(/^,/,'').replace(/,$/,'');
var pattern=/^[_a-zA-Z0-9-\.]+@[\.a-zA-Z0-9-]+\.[a-zA-Z]+$/; if(el.value.length>0){var emails = el.value.split(",");
for(var i=0; i<emails.length; i++){if(!pattern.test(emails[i])){alert(emails[i] + " 는 올바른 메일주소가 아닙니다."); el.focus(); return false;}} return true;}return true;}
//-------------------------------------------------------
function isValidExt(el, p){var pt = "," + p.replace(/ /g,'') + ",";if(!el || el.value.replace(/ /g,'').length==0) return false;
var ext = el.value.toLowerCase().substring(el.value.lastIndexOf(".")+1);
if(pt.indexOf("," + ext + ",")<0){alert("올바른 파일형식이 아닙니다."); el.select();
if(window["getSelection"]){if(Browser.safari){window.getSelection().collapse();}else{window.getSelection().removeAllRanges();}}
else if((document.selection)&&(document.selection.clear)){document.selection.clear();} return false;} else return true;}
//-------------------------------------------------------
function isImageExt(el){return isValidExt(el, "jpg,jpeg,gif,png");}
function trim(s){return s ? s.replace(/ +$/,'').replace(/^ +/g,'') : '';}
//=======================================================
// 이미지 관련 함수
//
function imageReSize(el,maxWidth,maxHeight, fit){var width=el.width;var height=el.height;
if(maxWidth<0)maxWidth=0;if(maxHeight<0)maxHeight=0;
if(maxWidth==0&&maxHeight>0&&height>maxHeight){height=height/maxHeight;width=width/(height/maxHeight);}
else if(maxHeight==0&&maxWidth>0&&width>maxWidth){width=width/maxWidth;height=height/(width/maxWidth);}
else if(maxWidth>0&&maxHeight>0){if(width>maxWidth){height=height/(width/maxWidth);width=maxWidth;}
if(height>maxHeight){width=width/(height/maxHeight);height=maxHeight;}
if(fit && width<maxWidth && height<maxHeight){
if(maxWidth>maxHeight){width=width*(maxHeight/height);height=maxHeight;}
else{height=height*(maxWidth/width);width=maxWidth;}
if(width>maxWidth){height=height/(width/maxWidth);width=maxWidth;}
if(height>maxHeight){width=width/(height/maxHeight);height=maxHeight;}}}el.width=width;el.height=height;}
//=======================================================
// Form 관련 함수
//
function getRequestURI(){var u=location.href; return u.indexOf('?')>0 ? u.substring(u.lastIndexOf('/')+1, u.indexOf('?')) : u.substring(u.lastIndexOf('/')+1);}
function setSelectBox(id, value){var el = document.getElementById(id);
if(!el){var els=document.getElementsByName(id);if(els && els.length) el=els[0];}
if(el&&el.length){for(var i=0; i<el.length; i++) el[i].selected=(el[i].value==value);}}
function setRadio(id, value){var el = document.getElementsByName(id);
if(el&&el.length){for(var i=0; i<el.length; i++) el[i].checked=(el[i].value==value);}}
function getRadio(el){if(el.length){for(var i=0;i<el.length;i++)if(el[i].checked){return el[i].value;}}else if(el.checked) return el.value; return '';}
function setCheckbox(id, value){var el = document.getElementById(id);
if(!el){var els=document.getElementsByName(id);if(els && els.length) el=els[0];}
if(el){el.checked=(el.value==value);}}
function setBgColor(el,c){el.style.backgroundColor=c;}
function setBgColorOver(el,c){if(c&&c.length>0)el.style.cursor='pointer'; el.style.backgroundColor=c;}
function deleteAll(query) {
var str = "";
var checkIdxs = document.getElementsByName("checkIdx");
for(var i=0; i<checkIdxs.length; i++) { if(checkIdxs[i].checked) str = str + "," + checkIdxs[i].value; }
if(str.length>1) {
if(confirm("삭제하시겠습니까?")) location.href = getRequestURI() + query + "&mode=delete&idxs=" + str.substr(1);
} else alert("삭제할 항목을 먼저 선택하세요.");
}
function deleteItem(query, idx) {
if(confirm("삭제하시겠습니까?")) location.href = getRequestURI() + query + "&mode=delete&idx=" + idx;
}
function checkAll(el) {
if(el.name=="checkIdxAll") {
var b = el.checked;
var c = el.form.checkIdx; if(!c) return;
if(c.length) { for(var i=c.length-1; i>=0; i--) c[i].checked = b;
} else c.checked = b;
} else if(!el.checked && el.form.checkIdxAll) el.form.checkIdxAll.checked = false;
}
function checkEnter(e, fn) {
var key = window.event ? event.keyCode : e.keyCode;
if(key==13) {
var el = window.event ? event.srcElement : e.target;
if(el && el.value.replace(/ /g,'').length>0) eval(fn);
if(window.event) event.returnValue=false; else e.preventDefault();
}
}
//=======================================================
// 배너 스크롤 처리 함수
//
var isBannerScroll = true;
var bannerFirstScrollY = new Array();
var bannerLastScrollY = new Array(0, 0, 0, 0, 0);
function bannerLayerScroll(n, s) {
if(n<0 || n>=bannerLastScrollY.length) return;
obj = (document.getElementById) ? document.getElementById(s) : (document.all) ? document.all[s] : document.layers[s];
if(!obj) return;
if (typeof window.pageYOffset != 'undefined') {
diffY = window.pageYOffset;
diffH = window.scrollMaxY ? window.innerHeight + window.scrollMaxY : document.body.scrollHeight;
} else if (document.compatMode && document.compatMode != 'BackCompat') {
diffY = document.documentElement.scrollTop;
diffH = document.documentElement.scrollHeight;
} else {
diffY = document.body.scrollTop;
diffH = document.body.scrollHeight;
}
if(obj.offsetParent&&obj.offsetParent.scrollHeight>0) diffH = obj.offsetParent.scrollHeight;
if(!bannerFirstScrollY[n]) bannerFirstScrollY[n] = document.all ? obj.style.pixelTop : parseInt(obj.style.top);
if(!isBannerScroll) diffY = bannerFirstScrollY[n];
if(diffY<0) diffY = 0;
if(diffY != bannerLastScrollY[n]) {
percent = .1 * (diffY-bannerLastScrollY[n]);
if(percent>0) percent = Math.ceil(percent); else percent = Math.floor(percent);
if(diffH>(obj.offsetTop+ obj.offsetHeight + percent)) {
if(document.all) obj.style.pixelTop += percent;
else obj.style.top = (parseInt(obj.style.top) + percent) + 'px';
bannerLastScrollY[n] = bannerLastScrollY[n] + percent;
}
}
}
//=======================================================
// 클립보드 처리
//
function copyClip(meintext) {
if (window.clipboardData) { // IE일 경우
window.clipboardData.setData("Text", meintext);
} else if (window.netscape) { // NS일 경우
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
if (!clip) return false;
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!trans) return false;
trans.addDataFlavor('text/unicode');
var str = new Object(); var len = new Object();
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
var copytext = meintext; // 로컬변수에 복사
str.data = copytext;
trans.setTransferData("text/unicode",str,copytext.length*2);
var clipid = Components.interfaces.nsIClipboard;
if (!clipid) return false;
clip.setData(trans,null,clipid.kGlobalClipboard);
}
alert("저장되었습니다.\n원하는곳에 붙여넣기를 하세요.");
return false;
}
//=======================================================
// 포커스 처리
//
var mouseOverColor = "#666666";
var mouseOverBgColor = "#FFFFFF";
var nowFocusEl = '';
function inputIn(e) { oSrc=(window.event) ? event.srcElement : e.target;
if(oSrc && isFocusElement(oSrc)){nowFocusEl=oSrc.name;oSrc.style.color=mouseOverColor;oSrc.style.backgroundColor=mouseOverBgColor;}}
function inputOut(e) { oSrc=(window.event) ? event.srcElement : e.target;
if(oSrc && isFocusElement(oSrc)){nowFocusEl='';oSrc.style.color="";oSrc.style.backgroundColor="";}}
if(document.all){document.onfocusin = inputIn; document.onfocusout = inputOut;}
function mouseIn(e) { oSrc=(window.event) ? event.srcElement : e.target;
if(oSrc && isFocusElement(oSrc)){oSrc.style.color=mouseOverColor;oSrc.style.backgroundColor=mouseOverBgColor;}
if(oSrc=hasClassName(oSrc,"mouse")) oSrc.style.backgroundColor=mouseOverBgColor;}
function mouseOut(e) { oSrc=(window.event) ? event.srcElement : e.target;
if(oSrc && isFocusElement(oSrc) && nowFocusEl!=oSrc.name){oSrc.style.color="";oSrc.style.backgroundColor="";}
if(oSrc=hasClassName(oSrc,"mouse")) oSrc.style.backgroundColor="";}
function hasClassName(el, n){while(el){if(el.className==n) return el;el=el.parentNode;} return false;}
function isFocusElement(el){
return el.type=="text" || el.type=="password" || el.type=="file" || el.tagName=="TEXTAREA" || el.tagName=="SELECT";
}
// 포커스처리 이벤트 시작
//if(document.all){document.onmouseover = mouseIn; document.onmouseout = mouseOut;}
//=======================================================
// 기타
//
function printWindow() {
window.open("/common/print.php", "printWindow", "width=700, height=500, status=no, scrollbars=yes");
}
function IFramResize(d) {
var el = document.getElementById(d);
if(el && el.tagName=="IFRAME") {
var oDoc = el.contentDocument || el.contentWindow.document;
el.height = oDoc.body.scrollHeight + 30;
}
}
function setCookie(name, value, expiredays) {
var todayDate = new Date();
todayDate.setDate(todayDate.getDate() + expiredays);
document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";";
}
make flash
function MakeFlash(Url,Width,Height){
var s = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' "
+ "codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' "
+ "width='" + Width + "' height='" + Height + "'>\n"
+ "<param name='movie' value='" + Url + "'>\n"
+ "<param name='quality' value='high' />\n"
+ "<param name='menu' value='false'>\n"
+ "<param name='wmode' value='transparent'>\n"
+ "<embed src='" + Url + "' quality='high' pluginspage='https://www.macromedia.com/go/getflashplayer' "
+ "type='application/x-shockwave-flash' wmode='transparent' width='" + Width + "' height='" + Height + "'></embed>\n"
+ "</object>";
document.writeln(s);
}
check userAgent
var Browser = new Object();
Browser.win=(navigator.appVersion.indexOf('Win')!=-1);
Browser.mac=(navigator.appVersion.indexOf('Mac')!=-1);
Browser.lin=(navigator.userAgent.indexOf('Linux')!=-1);
if(!document.layers){
Browser.opera=(navigator.userAgent.indexOf('Opera')!=-1);
Browser.konq=(navigator.userAgent.indexOf('Konqueror')!=-1);
Browser.safari=(navigator.userAgent.indexOf('Safari')!=-1);
Browser.mozilla=(navigator.userAgent.indexOf('Gecko')!=-1&&!Browser.safari&&!Browser.konq);
Browser.ie=(document.all&&!Browser.opera);
Browser.ie4=(Browser.ie&&!document.getElementById);
Browser.ie5x=(document.all&&document.getElementById);
Browser.ie5mac=(Browser.mac&&Browser.ie5x);
Browser.ie5xwin=(Browser.win&&Browser.ie5x);
}
Get Selection
var
textarea = document.getElementById(
"textarea"
);
// code for IE
if
(document.selection)
{
textarea.focus();
var
sel = document.selection.createRange();
// alert the selected text in textarea
alert(sel.text);
// Finally replace the value of the selected text with this new replacement one
sel.text =
'<b>'
+ sel.text +
'</b>'
;
} else {
// code for Mozilla
var
len = textarea.value.length;
var
start = textarea.selectionStart;
var
end = textarea.selectionEnd;
var
sel = textarea.value.substring(start, end);
// This is the selected text and alert it
alert(sel);
var
replace =
'<b>'
+ sel +
'<b>'
;
// Here we are replacing the selected text with this one
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
Simple drop down menu javascript prototype
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Drop-Down Menu</title>
<meta name="keywords" content="">
<meta name="description" content="">
<link rel="stylesheet" type="text/css" href="css/default.css">
<!-- dd menu -->
<script type="text/javascript">
<!--
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;
// open hidden layer
function mopen(id)
{
// cancel close timer
mcancelclosetime();
// close old layer
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
// get new layer and show it
ddmenuitem = document.getElementById(id);
ddmenuitem.style.visibility = 'visible';
}
// close showed layer
function mclose()
{
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}
// go close timer
function mclosetime()
{
closetimer = window.setTimeout(mclose, timeout);
}
// cancel close timer
function mcancelclosetime()
{
if(closetimer)
{
window.clearTimeout(closetimer);
closetimer = null;
}
}
// close layer when click-out
document.onclick = mclose;
// -->
</script>
</head>
<body>
<h1>DropDown Menu</h1>
<p>This menu can be located anywhere on a page:</p>
<ul id="sddm">
<li><a href="#" onmouseover="mopen('m1')" onmouseout="mclosetime()">Home</a>
<div id="m1" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">HTML DropDown</a>
<a href="#">DHTML DropDown menu</a>
<a href="#">JavaScript DropDown</a>
<a href="#">DropDown Menu</a>
<a href="#">CSS DropDown</a>
</div>
</li>
<li><a href="#" onmouseover="mopen('m2')" onmouseout="mclosetime()">Download</a>
<div id="m2" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">ASP Dropdown</a>
<a href="#">Pulldown menu</a>
<a href="#">AJAX dropdown</a>
<a href="#">DIV dropdown</a>
</div>
</li>
<li><a href="#" onmouseover="mopen('m3')" onmouseout="mclosetime()">Order</a>
<div id="m3" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">Visa Credit Card</a>
<a href="#">Paypal</a>
</div>
</li>
<li><a href="#" onmouseover="mopen('m4')" onmouseout="mclosetime()">Help</a>
<div id="m4" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">Download Help File</a>
<a href="#">Read online</a>
</div>
</li>
<li><a href="#" onmouseover="mopen('m5')" onmouseout="mclosetime()">Contact</a>
<div id="m5" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">E-mail</a>
<a href="#">Submit Request Form</a>
<a href="#">Call Center</a>
</div>
</li>
</ul>
<div style="clear:both"></div>
<div style="clear:both"></div>
<p>If you are looking for advanced script, see the <a href="http://javascript-array.com/scripts/multi_level_drop_down_menu/?sddm">Multi-Level Drop-Down Menu</a> based on simple treelike unordered list.
<p>If you want to use this script on your page, please place link to http://javascript-array.com at one of your pages.
<p>© Copyright 2006-2007 <a href="http://javascript-array.com/">javascript-array.com</p>
</body>
</html>
default.css
#sddm
{ margin: 0;
padding: 0;
z-index: 30}
#sddm li
{ margin: 0;
padding: 0;
list-style: none;
float: left;
font: bold 11px arial}
#sddm li a
{ display: block;
margin: 0 1px 0 0;
padding: 4px 10px;
width: 60px;
background: #5970B2;
color: #FFF;
text-align: center;
text-decoration: none}
#sddm li a:hover
{ background: #49A3FF}
#sddm div
{ position: absolute;
visibility: hidden;
margin: 0;
padding: 0;
background: #EAEBD8;
border: 1px solid #5970B2}
#sddm div a
{ position: relative;
display: block;
margin: 0;
padding: 5px 10px;
width: auto;
white-space: nowrap;
text-align: left;
text-decoration: none;
background: #EAEBD8;
color: #2875DE;
font: 11px arial}
#sddm div a:hover
{ background: #49A3FF;
color: #FFF}
<html>
<head>
<title>Drop-Down Menu</title>
<meta name="keywords" content="">
<meta name="description" content="">
<link rel="stylesheet" type="text/css" href="css/default.css">
<!-- dd menu -->
<script type="text/javascript">
<!--
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;
// open hidden layer
function mopen(id)
{
// cancel close timer
mcancelclosetime();
// close old layer
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
// get new layer and show it
ddmenuitem = document.getElementById(id);
ddmenuitem.style.visibility = 'visible';
}
// close showed layer
function mclose()
{
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}
// go close timer
function mclosetime()
{
closetimer = window.setTimeout(mclose, timeout);
}
// cancel close timer
function mcancelclosetime()
{
if(closetimer)
{
window.clearTimeout(closetimer);
closetimer = null;
}
}
// close layer when click-out
document.onclick = mclose;
// -->
</script>
</head>
<body>
<h1>DropDown Menu</h1>
<p>This menu can be located anywhere on a page:</p>
<ul id="sddm">
<li><a href="#" onmouseover="mopen('m1')" onmouseout="mclosetime()">Home</a>
<div id="m1" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">HTML DropDown</a>
<a href="#">DHTML DropDown menu</a>
<a href="#">JavaScript DropDown</a>
<a href="#">DropDown Menu</a>
<a href="#">CSS DropDown</a>
</div>
</li>
<li><a href="#" onmouseover="mopen('m2')" onmouseout="mclosetime()">Download</a>
<div id="m2" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">ASP Dropdown</a>
<a href="#">Pulldown menu</a>
<a href="#">AJAX dropdown</a>
<a href="#">DIV dropdown</a>
</div>
</li>
<li><a href="#" onmouseover="mopen('m3')" onmouseout="mclosetime()">Order</a>
<div id="m3" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">Visa Credit Card</a>
<a href="#">Paypal</a>
</div>
</li>
<li><a href="#" onmouseover="mopen('m4')" onmouseout="mclosetime()">Help</a>
<div id="m4" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">Download Help File</a>
<a href="#">Read online</a>
</div>
</li>
<li><a href="#" onmouseover="mopen('m5')" onmouseout="mclosetime()">Contact</a>
<div id="m5" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">E-mail</a>
<a href="#">Submit Request Form</a>
<a href="#">Call Center</a>
</div>
</li>
</ul>
<div style="clear:both"></div>
<div style="clear:both"></div>
<p>If you are looking for advanced script, see the <a href="http://javascript-array.com/scripts/multi_level_drop_down_menu/?sddm">Multi-Level Drop-Down Menu</a> based on simple treelike unordered list.
<p>If you want to use this script on your page, please place link to http://javascript-array.com at one of your pages.
<p>© Copyright 2006-2007 <a href="http://javascript-array.com/">javascript-array.com</p>
</body>
</html>
default.css
#sddm
{ margin: 0;
padding: 0;
z-index: 30}
#sddm li
{ margin: 0;
padding: 0;
list-style: none;
float: left;
font: bold 11px arial}
#sddm li a
{ display: block;
margin: 0 1px 0 0;
padding: 4px 10px;
width: 60px;
background: #5970B2;
color: #FFF;
text-align: center;
text-decoration: none}
#sddm li a:hover
{ background: #49A3FF}
#sddm div
{ position: absolute;
visibility: hidden;
margin: 0;
padding: 0;
background: #EAEBD8;
border: 1px solid #5970B2}
#sddm div a
{ position: relative;
display: block;
margin: 0;
padding: 5px 10px;
width: auto;
white-space: nowrap;
text-align: left;
text-decoration: none;
background: #EAEBD8;
color: #2875DE;
font: 11px arial}
#sddm div a:hover
{ background: #49A3FF;
color: #FFF}
Thursday, January 6, 2011
Subscribe to:
Posts (Atom)