我的收藏:
<#--
功能描述:我要收藏控件(收藏成功提示)
必要条件:在页面导入<#include "common/提示框.htm">
宏定义:在使用处加入<@我要收藏 topicId />
topicId:为试题id
代码案例:
<@我要收藏 topicId />
-->
<script type="text/javascript">
function collectTopic(e,id){
var btn=e||window.event;
btn.disabled="disabled";
$.get(
'collect/collectTopic.action',
{topicId:id},
function(data){
if(data=="true"){
tWen.alertInfo('试题收藏成功');
}else{
tWen.errorInfo('不能重复收藏');
}
},
"json")}
</script>
<#macro 我要收藏 topicId>
<input type="button" onclick="collectTopic(this,'${topicId}')" value="我要收藏" class="btn01"/>
</#macro>
------------------------------------------------------------------------------------------------------------------------------------
提示框:
<#--
功能描述:js提示框
必要条件:无
宏定义:无
js定义: tWen.提示种类(参数1(可选),参数2(可选),参数3(可选),参数4(可选));
参数1:提示信息;参数2:回调函数;参数3:提示框宽度;参数4:标题;
提示种类:alertInfo, succeedInfo, errorInfo, confirmInfo
代码案例:
<input type="button"
onclick="javascript:tWen.confirmInfo('提示',function(result){alert(result)},200,'标题')"
/>
-->
<link rel="stylesheet" href="commons/tWen/css/tWen.css" />
<@htm.lazyJs js=["commons/tWen/tWen.min.js"] />
---------------------------------------------------------------------
commons/tWen/css/tWen.css:
var tWen={cfg:["message","handler","width","title"],m_Color:"#000",m_Alpha:0.1,d_Cfg:{message:"/u5185/u5bb9",width:250,handler:function(){}},apply:function(d){if(d&&typeof d=="object")for(var c in d)this[c]=d[c]},show:function(d){this.apply(this.d_Cfg);if(!this.isInit)this.init(),this.isInit=!0;for(var d=Array.prototype.slice.call(d,0),c=0,e=d.length;c<e;c++)d[c]&&(this[this.cfg[c]]=d[c]);this.showWin();this.showMask();this.resizeInfo()},isInit:!1,mkBtn:function(d,c){return"<input type='button' onclick='tWen.doHandler(/""+
c+"/")' value='"+d+"' /> "}},okBtn=tWen.mkBtn(" /u786e /u5b9a ","ok"),cancelBtn=tWen.mkBtn(" /u53d6 /u6d88 ","cancel");
tWen.apply({alertInfo:function(){tWen.winType="alert";tWen.title="/u4fe1/u606f/u63d0/u793a";tWen.buttons=[okBtn];tWen.show(arguments)},succeedInfo:function(){tWen.winType="success";tWen.title="/u6210/u529f/u63d0/u793a";tWen.buttons=[okBtn];tWen.show(arguments)},errorInfo:function(){tWen.winType="error";tWen.title="/u5931/u8d25/u63d0/u793a";tWen.buttons=[okBtn];tWen.show(arguments)},confirmInfo:function(){tWen.winType="confirm";tWen.title="/u4fe1/u606f/u786e/u8ba4";tWen.buttons=[okBtn,cancelBtn];tWen.show(arguments)}});
tWen.init=function(){var d=document,c=d.body,e=tWen,g=function(b,c,a){a=a||d;k?a.attachEvent("on"+b,c):a.addEventListener(b,c,!1)},h=navigator.userAgent.toLowerCase().indexOf("opera")!=-1,k=navigator.userAgent.toLowerCase().indexOf("msie")!=-1!=-1&&d.all&&!h;if(!c||typeof c!="object")return g("load",arguments.callee,window);var f=d.compatMode=="CSS1Compat"?d.documentElement:c,i={},a=function(b){var a=i[b];return a?a:i[b]=d.getElementById(b)},j=function(b,a,c){!c?h?b.setAttribute("style",a):b.style.cssText=
a:h?b.setAttribute("style",b.getAttribute("style")+a):b.style.cssText+=a},l=function(b){if(!a("tWen_container")||a("tWen_container").style.display=="none")return!0;b=window.event||b;a("tWen_button").childNodes[0].focus();if(b.keyCode==13)return!0;try{b.keyCode=0,b.cancelBubble=!0,b.returnValue=!1}catch(c){try{b.stopPropagation(),b.preventDefault()}catch(d){}}};e.showMask=function(){if(a("m_frame"))a("m_frame").style.display="";a("m_div").style.display="";c.onselectstart=function(){return!1};c.oncontextmenu=
function(){return!1}};e.resizeInfo=function(){if(a("m_div").style.display!="none"){a("m_div").style.width=(f.scrollLeft==0?f.clientWidth:f.scrollWidth)+"px";a("m_div").style.height=(f.scrollTop==0?f.clientHeight:f.scrollHeight)+"px";var b=";width:"+e.width+"px;position:absolute;left:"+((f.clientWidth-e.width)/2+f.scrollLeft)+"px;top:"+((f.clientHeight-280)/2+f.scrollTop)+"px;z-index:10001";j(a("tWen_container"),b)}};e.showWin=function(){a("tWen_title").innerHTML=e.title;a("tWen_content").innerHTML=
e.message;a("tWen_container").className="tWen_"+e.winType;a("tWen_button").innerHTML="";for(var b=0;b<e.buttons.length;b++)a("tWen_button").innerHTML+=e.buttons[b];a("tWen_container").style.display=""};e.doHandler=function(b){a("m_div").style.display="none";if(a("m_frame"))a("m_frame").style.display="none";a("tWen_container").style.display="none";c.onselectstart=function(){return!0};c.oncontextmenu=function(){return!0};try{eval(this.handler).call(window,b)}catch(d){}};(function(){var b="position:absolute;top:0px;left:0px;width:0;height:0;background:"+
e.m_Color+";text-align:center;z-index:10000;filter:alpha(opacity="+e.m_Alpha*100+");opacity:"+e.m_Alpha;try{c.appendChild(d.createElement("<div id='m_div' style='"+b+"'></div>")),c.appendChild(d.createElement("<iframe id='m_frame'></iframe>")),j(a("m_frame"),a("m_div").style.cssText+";z-index:9999;filter:alpha(opacity=0);opacity:0")}catch(f){var g=d.createElement("div");g.id="m_div";g.setAttribute("style",b);c.appendChild(g)}})();(function(){var a="<p id='tWen_content'></p>";a+="<div id='tWen_button'></div>";
var f=d.createElement("div");f.id="tWen_container";f.innerHTML="<h1 id='tWen_title'>/u63d0/u793a/u4fe1/u606f</h1>"+a;c.appendChild(f);g("keydown",l);g("resize",e.resizeInfo,window);g("scroll",e.resizeInfo,window)})()};
---------------------
<@htm.lazyJs js=["commons/tWen/tWen.min.js"] />:
//改写ymPrompt.js 消息提示组件version:'2.01'
var tWen={
cfg:['message','handler','width','title'],//调用时参数顺序与这个一致
m_Color:'#000', //遮罩透明色
m_Alpha:0.1, //遮罩透明度
d_Cfg:{//默认配置
message:'内容', //消息框按钮
width:250, //宽
handler: function(){} //回调事件
},
apply:function(c){//实现对象继承
if (c && typeof c == 'object') {
for (var p in c) {
this[p] = c[p]
}
}
},
show:function(args){
this.apply(this.d_Cfg);
if(!this.isInit){
this.init();
this.isInit = true;
}
var a=Array.prototype.slice.call(args,0);
for(var i=0,l=a.length;i<l;i++){
if(a[i]){this[this.cfg[i]]=a[i]}
}
this.showWin();
this.showMask();
this.resizeInfo();
},
isInit: false,
mkBtn:function(txt,sign){
return "<input type='button' onclick='tWen.doHandler(/""+sign+"/")' value='"+txt+"' /> "
}
};
var okBtn=tWen.mkBtn(' 确 定 ','ok'), cancelBtn=tWen.mkBtn(' 取 消 ','cancel');
tWen.apply({
alertInfo:function(){
tWen.winType='alert';
tWen.title='信息提示';
tWen.buttons=[okBtn];
tWen.show(arguments);
},
succeedInfo:function(){
tWen.winType='success';
tWen.title='成功提示';
tWen.buttons=[okBtn];
tWen.show(arguments);
},
errorInfo:function() {
tWen.winType='error';
tWen.title='失败提示';
tWen.buttons=[okBtn];
tWen.show(arguments);
},
confirmInfo:function() {
tWen.winType='confirm';
tWen.title='信息确认';
tWen.buttons=[okBtn,cancelBtn];
tWen.show(arguments);
}
});
tWen.init=(function(){
var d=document,db=d.body,y=tWen;
//为元素绑定事件的函数
var addEvent=function(env,fn,obj){
obj=obj||d; //默认是document对象
isIE?obj.attachEvent('on'+env,fn):obj.addEventListener(env,fn,false);
};
//浏览器类型判断
var browser=function(s){return navigator.userAgent.toLowerCase().indexOf(s)!=-1};
var isOpera=browser('opera'),isIE=browser('msie')!=-1&&(d.all&&!isOpera);
//等待页面加载完成
if(!db||(typeof db!='object')){
return addEvent('load',arguments.callee,window);
}
//根据html Doctype获取html根节点,以兼容非xhtml的页面
var rootEl=d.compatMode=='CSS1Compat'?d.documentElement:db; //根元素
//公用函数区域,cache为元素缓存
var cache={},$=function(id){
var cc=cache[id];
return cc?cc:cache[id]=d.getElementById(id)
};
//为元素添加css。obj:要添加css的对象,css:css文本,append:追加还是覆盖,默认覆盖
var addCSS=function(obj,css,append){
!append?(isOpera?obj.setAttribute('style',css):obj.style.cssText=css):(isOpera?obj.setAttribute('style',obj.getAttribute('style')+css):obj.style.cssText+=css);
}
//弹出消息框时监听键盘事件
var listenKeydown=function(){
//无弹出框或弹出框隐藏则不屏蔽操作
if(!$('tWen_container')||$('tWen_container').style.display=='none') return true;
var ev=window.event||arguments[0];
var inputs=$('tWen_button').childNodes;
inputs[0].focus();
if(ev.keyCode==13)return true; //允许回车键
//屏蔽所有键盘操作包括刷新等
try{
ev.keyCode=0;
ev.cancelBubble=true;
ev.returnValue=false;
}catch(e){
try{ //2007-11-13 避免IE下event.keycode=0执行出错后转向此处而报错,先暂时用try..catch解决吧
ev.stopPropagation();
ev.preventDefault();
}catch(e){}
}
}
//遮罩层
function createMask(){
var shieldStyle='position:absolute;top:0px;left:0px;width:0;height:0;background:'+y.m_Color+';text-align:center;z-index:10000;filter:alpha(opacity='+(y.m_Alpha*100)+');opacity:'+y.m_Alpha;
try{ //IE
db.appendChild(d.createElement("<div id='m_div' style=/'"+shieldStyle+"/'></div>"));
db.appendChild(d.createElement("<iframe id='m_frame'></iframe>"));
addCSS($('m_frame'),$('m_div').style.cssText+';z-index:9999;filter:alpha(opacity=0);opacity:0');
}catch(e){
var promptShield=d.createElement('div');
promptShield.id='m_div';
promptShield.setAttribute('style',shieldStyle);
db.appendChild(promptShield);
promptShield=null;
}
}
y.showMask=function(){
//计算蒙板的高宽,因为页面内容可能变化,所以每次弹出都应该更新宽高
//$('m_div').style.display='none'; //如果显示则先隐藏便于后面计算页面的高宽
//添加Iframe遮罩,仅在IE下才会存在Iframe遮罩
if($('m_frame')){$('m_frame').style.display=''};
//显示蒙板
$('m_div').style.display='';
//禁止对页面的任何操作
db.onselectstart = function(){return false};
db.oncontextmenu = function(){return false};
}
//重新计算遮罩大小
y.resizeInfo=function(){
if($("m_div").style.display!="none"){
//使用scrollTop和scrollWidth判断是否有滚动条更加准确,但需要加上onscroll监听,一旦发现有scrollTop或scrollLeft则使用scrollWidth/Height
$('m_div').style.width=(rootEl.scrollLeft==0?rootEl.clientWidth:rootEl.scrollWidth)+"px";
$('m_div').style.height=(rootEl.scrollTop==0?rootEl.clientHeight:rootEl.scrollHeight)+"px";
//总容器的样式
var outerStyle=';width:'+y.width+'px;position:absolute;left:'+((rootEl.clientWidth-y.width)/2+rootEl.scrollLeft)+'px;top:'+((rootEl.clientHeight-280)/2+rootEl.scrollTop)+'px;z-index:10001';
addCSS($('tWen_container'),outerStyle); //居中定位消息框
}
}
//弹出窗体
function createWin(){
//标题容器层
var title_div="<h1 id='tWen_title'>提示信息</h1>";
//内容容器层
var content_div="<p id='tWen_content'></p>";
//按钮区
content_div+="<div id='tWen_button'></div>";
//创建总容器
var outContainer=d.createElement('div');
outContainer.id='tWen_container';
outContainer.innerHTML=title_div+content_div;
db.appendChild(outContainer);
//添加监听事件
addEvent("keydown",listenKeydown);//键盘按下事件
addEvent("resize",y.resizeInfo,window);
addEvent("scroll",y.resizeInfo,window);
}
y.showWin=function(){
$('tWen_title').innerHTML=y.title; //标题
$('tWen_content').innerHTML=y.message; //内容
$('tWen_container').className="tWen_"+y.winType; //图标类型
$('tWen_button').innerHTML="";
for(var i=0;i<y.buttons.length;i++){
$('tWen_button').innerHTML+=y.buttons[i]; //更新按钮类型
}
$('tWen_container').style.display=''; //显示容器
}
y.doHandler=function(sign){
//隐藏背景层
$('m_div').style.display='none';
if($('m_frame')){$('m_frame').style.display='none'};
$('tWen_container').style.display='none'; //隐藏容器;
db.onselectstart = function(){return true};
db.oncontextmenu = function(){return true};
try{eval(this['handler']).call(window,sign)}catch(e){}
}
createMask();
createWin();
});