js 生成组合彩信并生成smil

把一下代码直接复制到html中,运行一下,再回头研究下,主要用 微软 运行时组件(ActiveXObject)
______________________
<!DOCTYPE HTML PUBLIC "-//W<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="3" unitname="C">3C</chmetcnv>//DTD HTML 4.01 Transitional//EN"

 

"http://www.w3.org/TR/html4/loose.dtd">

 

<html>

 

<head>

 

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

 

<title>mmsCreator</title>

 

</head>

 

<body>

 

 <span><font size=2 color=green>添加彩信素材,生成彩信</font></span><br/>

 

<a href="javascript:void(0)" onClick="addAttach(content)">添加附件</a>

 

<div id="content"></div>

 

</body>

 

</html>

 

<script type="text/javascript">

 

var ID=1;

 

var isValid=false;

 

var fso=new ActiveXObject("Scripting.FileSystemObject");

 

//添加附件

 

function addAttach(obj){

 

 fileID="element"+ID;

 

 var objChild=document.createElement("div"); //构造条状容器对象

 

 var file= document.createElement("<INPUT TYPE='file' SIZE='12'/>"); //生成file

 

 file.id=fileID; //设置fileID

 

  file.name=fileID; //设置fileName

 

 

 var timeField=document.createElement("<input type='text' size='2' maxLength='2' />"); //时间字段

 

 timeField.name=fileID;

 

 timeField.value=1;

 

 timeField.title="输入时间, 10";

 

 timeField.attachEvent("onkeyup",fun(timeField,null,'checkNum')); //附件事件

 

 var timeSelect=document.createElement("select");

 

  timeSelect.name=fileID;

 

  var second=document.createElement("option");

 

 second.text="秒钟";

 

 second.value="s"

 

 second.title="时间单位:秒钟";

 

  var minute=document.createElement("option");

 

 minute.text="分钟";

 

 minute.value="min";

 

 second.title="时间单位:分钟";

 

  var hour=document.createElement("option");

 

 hour.text="小时";

 

 hour.value="h";

 

 second.title="时间单位:小时";

 

 timeSelect.add(minute);

 

 timeSelect.add(second);

 

 timeSelect.add(hour);

 

 

 

 var split1=document.createElement("<br/>");

 

 split1.name=fileID;

 

//

 

 var myA= document.createElement("A"); //生成 删除

 

 myA.innerHTML="<font size=2 color='red'></font>";

 

 myA.href="javascript:void(0)";

 

 myA.name=fileID;

 

 myA.attachEvent("onclick",fun(obj,objChild,'del')); //附件事件

 

 

 

 

 //组合

 

 objChild.insertBefore(file);

 

 objChild.insertBefore(timeField);

 

 objChild.insertBefore(timeSelect);

 

 objChild.insertBefore(myA);

 

 objChild.insertBefore(split1);

 

 obj.appendChild(objChild);

 

 obj.refresh;

 

 if(document.getElementById("done")==null){ //若无 完成,则建

 

 var create=document.createElement("a");

 

 create.id="done";

 

 create.innerHTML="<font size=2 color='red'>完成</font>";

 

 create.href="javascript:void(0)";

 

 create.attachEvent("onclick",fun(obj,null,'done'));

 

 document.body.appendChild(create);

 

 document.body.refresh;

 

 }

 

 <state w:st="on"><place w:st="on">ID++</place></state>;

 

}

 

//关联事件(关联到removeElement)

 

var fun=function(parentObj,childArray,flag){

 

 if(flag=="<state w:st="on"><place w:st="on">del</place></state>"){

 

 return function(){

 

 removeElement(parentObj,childArray)

 

 } 

 

 }else if(flag=="done"){

 

 return function(){

 

 done(parentObj);

 

 }

 

 }else if(flag=="checkNum"){

 

 return function(){

 

 parentObj.value=parentObj.value.replace(/[^\d]/g,''); 

 

 }

 

 }

 

}

 

//删除 

 

function removeElement(obj,objChild){

 

 if(obj.contains(objChild)) 

 

 obj.removeChild(objChild);

 

 // 无附件,则无 完成

 

 var objs = obj.getElementsByTagName("div");

 

 if(objs.length==0){

 

  document.body.removeChild(document.getElementById("done"));

 

 }

 

}

 

//鉴定数字

 

function checkNumber(parent){

 

 

 

}

 

function done(obj){

 

 

 

  var paths=new Array();

 

  var path="";

 

  var time=5;

 

  var timeType="m";

 

 var objs = obj.getElementsByTagName("div");

 

 //smil header

 

 var smil = "<?xml version='1.0' encoding='UTF-8'?>"

 

 + "<smil>"

 

 + "<head>"

 

 + "<layout>"

 

 + ". <root-layout width='126' height='126'/>"

 

 + "..<region id='Text' top='0%' left='0%' height='100%' width='100%'/>"

 

 + "..<region id='Image' top='0%' left='0%' height='100%' width='100%'/>"

 

 + ".</layout>" + "</head>" +

 

  "<body>";

 

 

 

 for(i=0;i<objs.length;i++){

 

 for(j=0;j<objs[i].children.length;j++){

 

 var one=objs[i].children[j];

 

 //非空

 

 if(one.nodeName=="INPUT"&&one.value==""){

 

 one.focus();

 

 return; 

 

 }

 

 

 

 if(one.nodeName=="INPUT"&&one.getAttribute("type")=="file"){

 

 path=one.value; 

 

 }else if(one.nodeName=="INPUT"&&one.getAttribute("type")=="text"){

 

 time=parseInt(one.value);

 

 }else if(one.nodeName=="SELECT"&&one.getAttribute("type")=="select-one"){

 

 timeType=one.value;

 

 } 

 

 }

 

 //放文件路径

 

 paths[i]=path;

 

 //smil body

 

 var fName=fso.getFileName(path);

 

 end=fName.substr(fName.indexOf(".")+1);

 

 if(end=="txt"){

 

 smil+="<par dur='"+time+timeType+"'><text src='"+fName+"' region='Text'/></par>"; 

 

 }else if(end=="gif"||end=="jpg"||end=="jpeg"){

 

 smil+="<par dur='"+time+timeType+"'><img src='"+fName+"' region='Image'/></par>"; 

 

 }else if(end=="wav"||end=="mid"){

 

 smil+="<par dur='"+time+timeType+"'><audio src='"+fName+"'/></par>"; 

 

 }

 

 }

 

 smil+="</body></smil>";

 

 

 

 //当前目录生成彩信目录

 

 var str=window.prompt("输入彩信名称如","aaa");

 

 if(str==null||str==""){

 

 return;

 

 }

 

 var basePath=fso.GetAbsolutePathName("")+"/"+str;

 

 

 

 if(fso.FolderExists(basePath)){//存在,1:覆盖,2:删除,3重命名

 

 if(confirm("目录已存在,确定要覆盖吗?")){

 

 fso.deleteFolder(basePath); 

 

 }else{

 

 str=window.prompt("输入彩信名称如","bbb");

 

 if(str==null||str==""){

 

 return;

 

  }

 

 basePath=fso.GetAbsolutePathName("")+"/"+str;

 

 }

 

 }

 

 

 

  var dir=fso.createFolder(basePath);

 

  //copy文件

 

  for(i=0;i<paths.length;i++)

 

   fso.copyFile(paths[i],dir+"/",true);

 

 

 

 //生成smil

 

 var sfile=fso.createTextFile(dir+"/a.smil")

 

 sfile.write(smil);

 

 sfile.close();

 

 

 
alert("彩信所在目录:"+dir);

 

}

 

</script>

 

你可能感兴趣的:(JavaScript,html,J#)