/**
* ========================code操作========================
*/
var keyCodeUtil = {
/**
* 源码爱好者代码提取
* @param objname
* @returns {HTMLElement}
*/
"$" : function(objname){
return document.getElementById(objname);
},
/**
* 运行代码,打开新窗口
* @param objname
*/
"runCode" : function(objname) {
var winname = window.open('', "_blank", '');
var obj = $(objname);
winname.document.open('text/html', 'replace');
winname.opener = null // 防止代码对论谈页面修改
winname.document.write(obj.value);
winname.document.close();
},
/**
* 保存代码
* @param objname
*/
"saveCode" : function(objname){
var winname = window.open('', '_blank', 'top=10000');
winname.document.open('text/html', 'replace');
var obj = $(objname);
winname.document.write(obj.value);
winname.document.execCommand('saveas','','code.htm');
winname.close();
},
/**
* 复制代码
* @param objname
*/
"onCopy" : function(objname){
var e=document.getElementById(objname); //对象是contents
e.select(); //选择对象
document.execCommand("Copy"); //执行浏览器复制命令
alert("代码已经被成功复制!");
/*
//html
<div class="table_cell tl m_id">
<div class="t_icontent">{{x.template_id}}</div>
<input type="text" value="{{x.template_id}}" class="t_input" />
<a href="javascript:void(0);" class="btntempidcopy">复制</a>
</div>
//css:复制前,input输入框需要设置成显示状态,并且需要有高度和宽度
.t_input{color:#fff;border: none;background: none;outline: none;width:1px;height:1px;}
//js复制模板编号
$(document).on("click",".btntempidcopy",function(){
var tempid = $(this).siblings(".t_icontent").html();
var $textelem = $(this).siblings(".t_input");
$textelem.val(tempid);
$textelem.focus();
$textelem.select();
if (document.execCommand('Copy')) {
document.execCommand('Copy', false, null);
alert('复制成功!');
} else {
alert('复制失败!');
}
$textelem.blur();
});
*/
},
/**
* 清除选择
* @returns {any}
*/
"clearSelection" : function(){
return window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
},
/**
* 浏览器进入全屏(必须绑定点击事件才能触发)
eg: requestFullScreen($(".content")[0]) // 某个页面元素
requestFullScreen(document.documentElement);// 整个网页
* @param element
*/
"requestFullScreen": function(element){
var requestMethod =
element.requestFullScreen || //W3C
element.webkitRequestFullScreen || //Chrome等
element.mozRequestFullScreen || //FireFox
element.msRequestFullscreen; //IE11
if (requestMethod) {
requestMethod.call(element);
}else if (typeof window.ActiveXObject !== "undefined") {//for Internet Explorer
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}else {
alert("您的浏览器过旧,不支持全屏功能!");
}
},
/**
* 退出全屏
*/
"exitFull": function() {
// 判断各种浏览器,找到正确的方法
var exitMethod =
document.exitFullscreen || //W3C
document.mozCancelFullScreen || //Chrome等
document.webkitExitFullscreen || //FireFox
document.webkitExitFullscreen; //IE11
if (exitMethod) {
exitMethod.call(document);
}
else if (typeof window.ActiveXObject !== "undefined") {//for Internet Explorer
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}else {
alert("您的浏览器过旧,不支持全屏功能!");
}
}
}