',
{
createHref: function(data) {
var agent = navigator.userAgent || '';
if (agent.indexOf('ChaoXingStudy') == -1) {
return data.readurl + '&unitid=7719';
}
var readurl = data.readurl + '&unitid=7719&showpdg=true';
readurl= readurl.replace("https", "http");
return 'javascript: MO.openBook(\''+ data.bookname +'\', \'' + readurl + '\');';
}
}
),
'insertdoc-online-doc-pad' : new Ext.XTemplate(
'
',
'
',
'',
'',
'
',
'',
'',
'
',
'
{bookname}
',
'
{author}
',
'
{publishdate}
',
'
',
{
createHref: function(data) {
var agent = navigator.userAgent || '';
if (agent.indexOf('ChaoXingStudy') == -1) {
return data.readurl + '&unitid=7719';
}
var readurl = data.readurl + '&unitid=7719&showpdg=true';
readurl= readurl.replace("https", "http");
return 'javascript: MO.openBook(\''+ data.bookname +'\', \'' + readurl + '\');';
}
}
),
'insertbook' : new Ext.XTemplate(
'
',
'',
'
',
{
url : function(values){
var url = values.readurl.replace("realRead","innerurl");
if(values.start){
url+="&start="+values.start;
}
if(values.end){
url+="&end="+values.end;
}
return url + "&unitid=7719";
}
},
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
}
},
{
values : replaceComma
}
),
'insertbook-review' : getTemplate(),
'insertbook-online' : new Ext.XTemplate(
'
',
'
',
'',
'',
'
{[this.getBookTips(values)]}{bookname} - {author}
',
'
',
'
',
{
url : function(values){
var url = values.readurl.replace("realRead","innerurl");
if(values.start){
url+="&start="+values.start;
} else {
url+="&start=1";
}
if(values.end){
url+="&end="+values.end;
} else {
url+="&end="+values.size;
}
return url + "&unitid=7719";
}
},
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
}
},
{
values : replaceComma
},{
getBookTips: function(values){
var btime = typeof values.btime == "undefined" ? false : values.btime;
var timing = typeof values.timing == "undefined" ? "0" : values.timing;
if (!!btime && timing != "0") {
return langMap.bookTip2 + timing + langMap.bookTip3;
}
}
}
),
'insertbook-online-review' : getTemplate(),
'insertvideo-online-pad' : new Ext.XTemplate(
'
',
'
',
'任务点
',
'',
'
',
'
',
'',
'
'
),
'insertvideo-pad' : new Ext.XTemplate(
'
'
),
'insertvideo-online' : new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
},
danmu : function(d){
if(d.danmaku == 1){
return 'style="height:610px;"';
}
return '';
},
values : replaceComma
}
),
'insertvideo-online-review' : getTemplate(),
'richvideo' : new Ext.XTemplate(
'
',
'',
'
'
),
'richvideo-review' : getTemplate(),
'insertvideo' : new Ext.XTemplate(
'
',
'{name}',
'{hsize}',
'',
{
values : replaceComma
}
),
'insertvideo-review' : getTemplate(),
'insertdoc-online-ppt' : new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
},
values : replaceComma
}
),
'insertdoc-online-ppt-review' : getTemplate(),
'insertzhuanti' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'insertcxjour' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'insertdoc-online-doc' : new Ext.XTemplate(
'
',
'',
'
'
),
'insertdoc-online-doc-review' : getTemplate(),
'insertdoc-online-pdf' : new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
},
values : replaceComma
}
),
'insertdoc-online-pdf-review' : getTemplate(),
'insertdoc-doc' : new Ext.XTemplate(
'
',
'{name}',
'{hsize}',
''
),
'insertdoc-doc-review' : getTemplate(),
'insertdoc-pdf' : new Ext.XTemplate(
'
',
'{name}',
'{hsize}',
''
),
'insertdoc-pdf-review' : getTemplate(),
'insertdoc-ppt' : new Ext.XTemplate(
'
',
'{name}',
'{hsize}',
''
),
'insertdoc-ppt-review' : getTemplate(),
'downloadfile' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'downloadfile-review':getTemplate(),
'insertdoc-download' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'insertdoc-download-review':getTemplate(),
'insertcxvideo' : new Ext.XTemplate(
'
'
),
'insertmooc' : new Ext.XTemplate(
'
',
'',
'{label} {name}',
'',
'',
'
',
'',
'{title}',
'',
'',
'
',
'',
'{title}',
'',
''
),
'ballchart' : new Ext.XTemplate(
'
',
'
{keyword}',
'
',
'
',
{
encodekeyword : function(d){
return encodeURIComponent(d.keyword);
}
}
),
'erya' : new Ext.XTemplate(
'
'
),
'work' : new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
},
values : replaceComma
}
),
'work-review' :getTemplate(),
'insertlive' : new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
},
values : replaceComma
}
),
'insertlive-review' : getTemplate(),
'insertread' : new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
},
values : replaceComma
}
),
'insertread-review':getTemplate(),
'insertreadV2' : new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
},
values : replaceComma
}
),
'insertreadV2-review':getTemplate(),
'insertvote' : new Ext.XTemplate(
'
',
{
jobid : function(d) {
if (d.jobid) {
return 'jobid="' + d.jobid + '"';
}
return '';
},
values : replaceComma,
}
),
'insertvote-review' : getTemplate(),
'insertvote-old' : new Ext.XTemplate(
'
',
{
jobid : function(d) {
if (d.jobid) {
return 'jobid="' + d.jobid + '"';
}
return '';
},
values : replaceComma,
}
),
'insertvote-old-review':getTemplate(),
'insertnote' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'insertchapter' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'insertsubject' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'realplay': new Ext.XTemplate(
'
'
),
'insertflash-online': new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
// 'insertflash-online-review':getTemplate(),
'insertflash': new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
// 'insertflash-review':getTemplate(),
'insertaudio-online': new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
}
},
{
values : replaceComma
}
),
'insertaudio-online-review': getTemplate(),
'insertaudio-online-pad': new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
}
}
),
'insertvoice-online' : new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
}
},
{
values : replaceComma
}
),
'insertvoice-online-review':getTemplate(),
'questionnaire' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'insertaddresource' : new Ext.XTemplate(
'
{[this.geturl(values)]}',
'',
{
geturl : function(values) {
values = values || '';
if(values.link.indexOf("http") != 0){
values.link = "http://"+values.link;
}
if(values.link){
values.link = values.link.replace(/[<>"]/g,function(c){return {'<':'<','>':'>','&':'&;','"':'"'}[c];});
}
if(values.link.indexOf("zhuanti.chaoxing.com/mobile/mooc/tocourse/") != -1){
return values.link.replace("zhuanti.chaoxing.com/mobile/mooc/tocourse/", "mooc1.chaoxing.com/zt/")+".html";
}else if(values.link.indexOf("special.zhexuezj.cn/mobile/mooc/tocourse/") != -1){
return values.link.replace("special.zhexuezj.cn/mobile/mooc/tocourse/", "mooc1.chaoxing.com/zt/")+".html";
} else if(values.link.indexOf("special.rhky.com/mobile/mooc/tocourse/") != -1){
return values.link.replace("special.rhky.com/mobile/mooc/tocourse/", "mooc1.chaoxing.com/zt/")+".html";
}else{
return values.link;
}
}
}
),
'insertbbs' : new Ext.XTemplate(
'
',
{
values : replaceComma
}
),
'insertbbs-review':getTemplate(),
'inserttopic' : new Ext.XTemplate(
'
',
{
values : replaceComma
}
),
'inserttopic-review':getTemplate(),
'insertmicroCourse' : new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
},
values : replaceComma
}
),
'insertmicroCourse-review':getTemplate(),
'insertlink-review': getTemplate(),
'insertlink' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'resource3d' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
// 'resource3d-review':getTemplate(),
'resourceQj' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
// 'resourceQj-review':getTemplate(),
'resourceVR' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
// 'resourceVR-review':getTemplate(),
'insertclasstask' : new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
},
values : replaceComma
}
),
'insertclasstask-review' : getTemplate(),
'experience' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'sizhenglink' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'iSearch' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'insertcustom' : new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
},
values : replaceComma
}
),
'hyperlink' : new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
},
values : replaceComma,
iframeSize : function(d){
if(d.iframeWidth && d.iframeHeight){
var iframeWidth = d.iframeWidth;
var iframeHeight = d.iframeHeight;
if (iframeHeight.indexOf("%") > -1) {
var baseValue = 480;
var percentage = parseInt(iframeHeight);
var result = baseValue * (percentage / 100);
iframeHeight = result + "px";
}
return 'style="width:' + iframeWidth + ';height:' + iframeHeight + ';"';
}
return '';
},
}
),
'hyperlink-review':getTemplate(),
'knowledgeGraph' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'insertlabreport' : new Ext.XTemplate(
'
',
{
jobid : function(d){
if(d.jobid){
return 'jobid="'+d.jobid+'"';
}
return '';
},
values : replaceComma
}
),
'insertlabreport-review':getTemplate(),
'insertvisuclass' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'insertFX' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'insertTopicGraph' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
'insertTopicPath' : new Ext.XTemplate(
'
',
'',
'
',
{
values : replaceComma
}
),
});
},
getTpl : function (module, data, iframe){
var tpl;
if (data && data.jobid) {
iframe.setAttribute('type', 'online');
}
if (module == 'insertdoc') {
if (data.type == "" && data.name && data.name.toString().indexOf(".") != -1) {
data.type = data.name.toString().substring(data.name.lastIndexOf("."), data.name.length)
}
var type = data.type.slice(1);
type = type.toLowerCase();
data.download = iframe.getAttribute("download");
switch (type) {
case 'pptx' :
case 'ppt' :
type = 'ppt';
break;
case 'docx' :
case 'doc' :
case 'xlsx' :
case 'xls' :
type = 'pdf';
break;
}
try {
if (iframe.getAttribute('type') == 'online') {
tpl = 'insertdoc-online-' + type;
} else {
//tpl = 'insertdoc-' + type;
tpl = 'insertdoc-download';
}
} catch (e) {
tpl = 'insertdoc-online-' + type;
}
var agent = navigator.userAgent || '';
if (agent.indexOf('chaoxing_wisdomclass') != -1) {
tpl = 'insertdoc-download';
}
tpl = tpl + getTplSub(iframe);
} else if (module == 'insertvideo') {
try {
if (iframe.getAttribute('type') == 'online') {
tpl = 'insertvideo-online';
} else {
tpl = 'insertvideo';
}
} catch (e) {
if (data.jobid) {
tpl = 'insertvideo-online';
} else {
tpl = 'insertvideo';
}
}
var agent = navigator.userAgent || '';
if (agent.indexOf('chaoxing_wisdomclass') != -1) {
tpl = tpl + "-pad";
} else {
tpl = tpl + getTplSub(iframe);
}
} else if (module == 'insertbook') {
// ie7 无权限
try {
if (iframe.getAttribute('type') == 'online') {
tpl = 'insertbook-online';
} else {
tpl = 'insertbook';
}
} catch (e) {
if (data.jobid) {
tpl = 'insertbook-online';
} else {
tpl = 'insertbook';
}
}
var agent = navigator.userAgent || '';
if (agent.indexOf('chaoxing_wisdomclass') != -1) {
tpl = tpl + "-pad";
} else {
tpl = tpl + getTplSub(iframe);
}
} else if (module == 'insertaudio') {
tpl = 'insertaudio-online';
var agent = navigator.userAgent || '';
if (agent.indexOf('chaoxing_wisdomclass') != -1) {
tpl = tpl + "-pad";
} else {
tpl = tpl + getTplSub(iframe);
}
} else if (module == 'insertvoice') {
tpl = 'insertvoice-online';
} else if (module == 'insertsubject') {
tpl = 'insertsubject';
} else if (module == 'insertflash') {
try {
if (iframe.getAttribute('type') == 'online') {
tpl = 'insertflash-online';
} else {
tpl = 'insertflash';
}
} catch (e) {
tpl = 'insertflash-online';
}
} else if (module == 'experience') {
tpl = 'experience';
} else if (module == "insertlabreport") {
tpl = 'insertlabreport';
} else if (module == 'insertvote') {
if (parent.location.href.indexOf("/mycourse/teacherstudy") < 0 && parent.location.href.indexOf("mycourse/tch") < 0 && parent.location.href.indexOf("/mycourse/studentstudy") < 0 && location.href.indexOf("/nodedetailcontroller/visitnodedetail") < 0 && location.href.indexOf("/micro-node-detail") < 0 ) {
tpl = 'insertvote-old';
} else {
tpl = 'insertvote';
}
tpl = tpl + getTplSub(iframe);
} else if (module == "insertvisuclass") {
tpl = 'insertvisuclass';
} else {
tpl = module;
}
try {
if(module == "hyperlink" || module == "insertclasstask" || module == "insertmicroCourse" || module == "inserttopic" || module == "insertbbs"
|| module == "insertreadV2" || module == "insertread" || module == "insertlive" || module == "work" || module == "downloadfile" || module == "richvideo" || module == "insertlabreport") {
if(tpl.indexOf("-review") < 0) {
tpl = tpl + getTplSub(iframe);
}
}
} catch (e) {
console.log(e);
}
return this.tpls[tpl];
}
});
Ext.define('ananas.JobCounter',{
alternateClassName : 'JC',
singleton : true,
mixins: {
observable: 'Ext.util.Observable'
},
jobcounter : 0,
attachments : null,
constructor: function () {
var me = this;
me.mixins.observable.constructor.call(me);
me.addEvents('completed');
},
completed : function(index){
var me = this;
if(me.jobcounter<=0 && !me.attachments){
return;
}
if(me.attachments[index].job){
me.jobcounter--;
me.attachments[index].job = false;
//if(me.jobcounter==0){
me.fireEvent('completed');
//}
}
}
});
var $UE = {};
$UE.ajax = function() {
var fnStr = 'XMLHttpRequest()';
try {
new ActiveXObject("Msxml2.XMLHTTP");
fnStr = 'ActiveXObject(\'Msxml2.XMLHTTP\')';
} catch (e) {
try {
new ActiveXObject("Microsoft.XMLHTTP");
fnStr = 'ActiveXObject(\'Microsoft.XMLHTTP\')'
} catch (e) {
}
}
var creatAjaxRequest = new Function('return new ' + fnStr);
function json2str(json) {
var strArr = [];
for (var i in json) {
//忽略默认的几个参数
if(i=="method" || i=="timeout" || i=="async") continue;
//传递过来的对象和函数不在提交之列
if (!((typeof json[i]).toLowerCase() == "function" || (typeof json[i]).toLowerCase() == "object")) {
strArr.push( encodeURIComponent(i) + "="+encodeURIComponent(json[i]) );
}
}
return strArr.join("&");
}
return {
request:function(url, ajaxOptions) {
var ajaxRequest = creatAjaxRequest(),
//是否超时
timeIsOut = false,
//默认参数
defaultAjaxOptions = {
method:"POST",
timeout:5000,
async:true,
data:{},//需要传递对象的话只能覆盖
onsuccess:function() {
},
onerror:function() {
}
};
if (typeof url === "object") {
ajaxOptions = url;
url = ajaxOptions.url;
}
if (!ajaxRequest || !url) return;
var ajaxOpts = ajaxOptions ? Ext.apply(defaultAjaxOptions, ajaxOptions) : defaultAjaxOptions;
var submitStr = json2str(ajaxOpts); // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
//如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
if (ajaxOpts.data){
submitStr += (submitStr? "&":"") + json2str(ajaxOpts.data);
}
//超时检测
var timerID = setTimeout(function() {
if (ajaxRequest.readyState != 4) {
timeIsOut = true;
ajaxRequest.abort();
clearTimeout(timerID);
}
}, ajaxOpts.timeout);
var method = ajaxOpts.method.toUpperCase();
var str = url + (url.indexOf("?")==-1?"?":"&") + (method=="POST"?"":submitStr+ "&noCache=" + +new Date);
ajaxRequest.open(method, str, ajaxOpts.async);
ajaxRequest.onreadystatechange = function() {
if (ajaxRequest.readyState == 4) {
if (!timeIsOut && ajaxRequest.status == 200) {
ajaxOpts.onsuccess(ajaxRequest);
} else {
ajaxOpts.onerror(ajaxRequest);
}
}
};
if (method == "POST") {
ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ajaxRequest.send(submitStr);
} else {
ajaxRequest.send(null);
}
}
};
}();
//by zhanyi
function uParse(selector,opt,params){
var unlock = function(){
var p = window;
while(p){
try {
if(p.onReadComplete){
if(typeof console == 'object')
console.log('call uParse to onReadComplete');
p.onReadComplete();
break;
}
if(p.parent==p){
break;
}
p = p.parent;
} catch(e) {
break;
}
}
},jobcounter=0,attachments;
window.AttachmentSetting = params;
if(params && params.control && params.attachments){
attachments = params.attachments;
for(var i=0;i
'+obj.tag+'>');
return;
}
if (obj.id && doc.getElementById(obj.id)) {
return;
}
var element = doc.createElement(obj.tag);
delete obj.tag;
for (var p in obj) {
element.setAttribute(p, obj[p]);
}
element.onload = element.onreadystatechange = function () {
if (!this.readyState || /loaded|complete/.test(this.readyState)) {
item = getItem(doc,obj);
if (item.funs.length > 0) {
item.ready = 1;
for (var fi; fi = item.funs.pop();) {
fi();
}
}
element.onload = element.onreadystatechange = null;
}
};
element.onerror = function(){
throw Error('The load '+(obj.href||obj.src)+' fails,check the url');
};
doc.getElementsByTagName("head")[0].appendChild(element);
};
}();
var defaultOption = {
liiconpath : 'http://bs.baidu.com/listicon/',
listDefaultPaddingLeft : '20',
'highlightJsUrl':'',
'highlightCssUrl':'',
customRule:function(content){}
};
if(opt){
for(var p in opt){
defaultOption[p] = opt[p];
}
}
(function(){
var contents;
if(document.querySelectorAll){
contents = document.querySelectorAll(selector);
}else{
if(/^#/.test(selector)){
contents = [document.getElementById(selector.replace(/^#/,''))];
}else if(/^\./.test(selector)){
var contents = [];
_each(document.getElementsByTagName('*'),function(node){
if(node.className && new RegExp('\\b' + selector.replace(/^\./,'') + '\\b','i').test(node.className)){
contents.push(node);
}
});
}else{
contents = document.getElementsByTagName(selector);
}
}
_each(contents,function(content){
if(content.tagName.toLowerCase() == 'textarea'){
var tmpNode = document.createElement('div');
if(/^#/.test(selector)){
tmpNode.id = selector.replace(/^#/,'');
}else if(/^\./.test(selector)){
tmpNode.className = selector.replace(/^\./,'');
}
content.parentNode.insertBefore(tmpNode,content);
tmpNode.innerHTML = content.value;
content.parentNode.removeChild(content);
content = tmpNode;
}
function fillNode(nodes){
_each(nodes,function(node){
if(!node.firstChild){
node.innerHTML = ' ';
}
});
}
function replaceModule(iframes){
var items = [];
for(var i=0,len = iframes.length;i-1))
return;
var f = node.style.float,
config = {tag:'span','cls':'ans-img-wrap'};
if(f){
config.cls = "ans-img-wrap float-"+f;
node.style.float = '';
}
var wrapper = Ext.fly(node).wrap(config);
/*
Ext.DomHelper.append(wrapper,{
cls :'ans-img-title',
tag : 'span',
html:node.title
});
*/
});
}
function showTips(content) {
function Tips(ele) {
this.oZlayerRe = document.createElement('span');
this.oZlayerArrow = document.createElement('span');
this.oZlayerAbs = this.oZlayerArrow.cloneNode(false);
this.oZlayerRe.style.cssText = 'position:absolute; display:none; vertical-align:top; background-color:#fff; display:none; top: 2px;z-Index:9999;';
this.oZlayerArrow.style.cssText = 'display:inline-block; position:absolute; left:-115px; top:22px; padding:10px; border:1px #ccc solid; border-radius:3px; background-color:#fff; font-size:12px; line-height:18px; color:#333;text-align:left;min-width:160px;max-width:600px;';
this.oZlayerAbs.style.cssText = 'display:inline-block; position:absolute; left:-75px; top:14px; width:180px; height:9px; background:url(/ananas/css/arrow.gif) center 0 no-repeat; z-index:9;';
this.oZlayerRe.appendChild(this.oZlayerArrow);
this.oZlayerRe.appendChild(this.oZlayerAbs);
this._init(ele);
}
Tips.prototype = {
show : function() {
this.oZlayerRe.style['display'] = 'inline-block';
},
hide : function() {
this.oZlayerRe.style['display'] = 'none';
},
setContent : function(con) {
this.oZlayerArrow.innerHTML = con;
},
getContent : function() {
return this.oZlayerArrow.innerHTML;
},
_init : function(ele) {
ele.appendChild(this.oZlayerRe);
}
};
function Tips2(ele) {
this.parentLable = ele;
this.oZlayerRe1 = document.createElement('div');
this.oZlayerArrow1 = document.createElement('p');
this.oZlayerArrow2 = document.createElement('div');
this.oZlayerRe1.appendChild(this.oZlayerArrow1);
this.oZlayerRe1.appendChild(this.oZlayerArrow2);
this.oZlayerRe1.setAttribute("class","note_Div");
this.oZlayerArrow2.setAttribute("class","note_img_con");
this.oZlayerRe1.style.cssText = 'position:absolute; display:none; vertical-align:top; background-color:#fff;z-Index:9999;text-indent:0;text-align:left;';
this.oZlayerArrow1.style.cssText = 'text-indent:0';
this._init(ele);
}
Tips2.prototype = {
show : function() {
this.oZlayerRe1.style['display'] = 'inline-block';
var bcr;
try{
bcr = this.oZlayerRe1.getBoundingClientRect();
}catch(e){
bcr={left:0,top:0,height:0,width:0}
}
var rect = {
left: Math.round(bcr.left),
top: Math.round(bcr.top),
right: Math.round(bcr.right),
height: Math.round(bcr.bottom - bcr.top),
width: Math.round(bcr.right - bcr.left)
};
var parentBcr;
try{
parentBcr = this.parentLable.getBoundingClientRect();
}catch(e){
parentBcr={left:0,top:0,height:0,width:0}
}
var parentRect = {
left: Math.round(parentBcr.left),
top: Math.round(parentBcr.top),
right: Math.round(parentBcr.right),
height: Math.round(parentBcr.bottom - parentBcr.top),
width: Math.round(parentBcr.right - parentBcr.left)
};
var width = (window.innerWidth || viewportEl.clientWidth) | 0;
var height = (window.innerHeight ||viewportEl.clientHeight) | 0;
var difference = width - rect.left - rect.width;
if( difference < 0){
this.oZlayerRe1.style['left'] = difference + "px";
this.oZlayerRe1.style['top'] = parentBcr.height + "px";
return;
}
//一行的情况
if(parentBcr.height <30){
this.oZlayerRe1.style['left'] = 0 + "px";
this.oZlayerRe1.style['top'] = parentBcr.height + "px";
return;
}
this.oZlayerRe1.style['top'] = parentBcr.height + "px";
this.oZlayerRe1.style['display'] = 'block';
},
hide : function() {
this.oZlayerRe1.style['display'] = 'none';
},
setContent : function(con) {
this.oZlayerArrow1.innerHTML = con;
},
setImg : function(con) {
this.oZlayerArrow2.appendChild(con);
},
setImg : function(con) {
this.oZlayerArrow2.appendChild(con);
},
setChild : function(con) {
this.oZlayerRe1.appendChild(con);
},
getContent : function() {
return this.oZlayerArrow1.innerHTML;
},
getoZlayerRe1 : function() {
return this.oZlayerRe1;
},
_init : function(ele) {
ele.appendChild(this.oZlayerRe1);
}
};
var loadImg = false;
_each(content.getElementsByTagName('a'), function(node){
var type = node.getAttribute('type');
var data = node.getAttribute('data');
var href = node.getAttribute('href');
var insertNotes = node.getAttribute('insertNotes');
var imgs = node.getAttribute('imgs');
var insertChapterUrl = node.getAttribute('insertChapterUrl');
var insertcrossurl = node.getAttribute('insertcrossurl');
if (href && (href.indexOf("cs.ananas.chaoxing.com/download") != -1 || href.indexOf("cs-ans.chaoxing.com/download") != -1)) {
var objId = href.split("?")[0].split("download/")[1];
if (objId) {
if (!data) {
data = objId;
}
$UE.ajax.request('/ananas/status/' + data, {
method: "GET",
timeout: 5000,
async: true,
onsuccess: function (response) {
var oData = eval('(' + response.responseText + ')');
if (oData.download) {
href = oData.download;
if (top.location.protocol.indexOf("https:") != -1 && href.indexOf("http:") != -1) {
href = href.replace("http:", "https:");
} else if (top.location.protocol.indexOf("http:") != -1 && href.indexOf("https:") != -1) {
href = href.replace("https:", "http:");
}
}
node.setAttribute("href", href);
}
})
} else {
if (href.indexOf("http:") != -1 && top.location.protocol.indexOf("https") != -1) {
href = href.replace("cs.ananas.chaoxing.com","cs-ans.chaoxing.com");
href = href.replace("http:","https:");
node.setAttribute("href", href);
}
}
}
if (type && data) {
node.style['position'] = 'relative';
if(insertNotes != 1){
node.innerHTML = '' + node.innerHTML + '';
}
node.tips2 = new Tips2(node);
node.tips = new Tips(node);
var filetype = node.title.substring(node.title.lastIndexOf('.')).toLocaleLowerCase();
if ('.txt' == filetype || insertNotes == 1) {
node.href = "javascript:void(0)";
}
node.onmouseover = function() {
if (!node.tips.getContent()) {
if (type == 'text') {
if(node.tips2.getContent()){
node.tips2.show();
}else{
var imgs = node.getAttribute('imgs');
if(imgs != "" && imgs != null && typeof(imgs) != "undefined"){
var imgSplit = imgs.split(",");
for(var i = imgSplit.length-1; i >= 0; i --){
var imgStr = imgSplit[i];
if(imgStr != ""){
var imgUrlSrc = imgStr;
var imgSpan = document.createElement('span');
var imgLabel = document.createElement('img');
imgLabel.setAttribute("src",imgStr);
imgLabel.setAttribute("data-original",imgStr);
imgLabel.setAttribute("class","imgEnlarge");
imgSpan.appendChild(imgLabel);
node.tips2.setImg(imgSpan);
}
}
}
if(typeof(top.window.tipImgEnlarge) != "undefined"){
top.window.tipImgEnlarge(node.tips2.getoZlayerRe1());
}
try {
if(typeof data != "undefined" && data != "") {
data = data.replace(/<\/?[^>]+>/g,"");
}
} catch (ex) {
console.log(ex);
}
node.tips2.setContent(data);
node.tips2.show();
}
} else if (type == 'resource' && data) {
$UE.ajax.request('/ananas/status/' + data, {
method:"GET",
timeout:5000,
async:true,
onsuccess:function(response) {
var oData = eval('(' + response.responseText + ')');
var src = oData.screenshot || oData.download;
var aAudio = [".aac", ".ac3", ".aif", ".amr", ".ape", ".flac", ".m4a", ".m4r", ".mka", ".mid", ".mmf", ".mpa", ".mpc", ".ogg", ".pcm",
".mp3", ".ra", ".tta", ".voc", ".wav", ".wv", ".wma"];
var aImg = [".gif", ".jpeg", ".png", ".jpg", ".bmp"];
if ('.txt' == filetype) {
$UE.ajax.request('/ananas/file/read?key=' + oData.key + '&url=' + oData.download, {
method:"GET",
timeout: 1000 * 60 * 5,
async:true,
onsuccess: function(txtresponse) {
var oTxtData = eval('(' + txtresponse.responseText + ')');
node.tips.setContent('' + oTxtData.con + '
');
},
onerror: function() {}
});
return;
}
var isAudio = false, isImg = false;
for (var i = 0, len = aAudio.length; i < len; i++) {
if (aImg[i] == filetype) {
isImg = true;
break;
}
}
for (var i = 0, len = aAudio.length; i < len; i++) {
if (aAudio[i] == filetype) {
isAudio = true;
break;
}
}
var videoBg = '';
if (!isImg) {
if (isAudio) {
src = '/ananas/css/music.png';
} else {
videoBg = '/ananas/css/video.png';
}
}
var sImg = '';
if (videoBg) {
sVideoBg = '
';
sImg = '
';
sImg = '' + sVideoBg + sImg + '
';
} else {
sImg = '
';
}
node.tips.setContent(sImg);
node.tips.show();
},
onerror:function() {
}
});
}
} else {
node.tips.show();
}
};
node.onmouseout = function() {
node.tips.hide();
node.tips2.hide();
};
} else if(type && !data && imgs){
node.style['position'] = 'relative';
if(insertNotes != 1){
node.innerHTML = '' + node.innerHTML + '';
}
node.tips2 = new Tips2(node);
node.tips = new Tips(node);
var filetype = node.title.substring(node.title.lastIndexOf('.')).toLocaleLowerCase();
if ('.txt' == filetype || insertNotes == 1) {
node.href = "javascript:void(0)";
}
node.onmouseover = function() {
if (!node.tips.getContent()) {
if(loadImg){
node.tips2.show();
}else {
if (imgs != "" && imgs != null && typeof (imgs) != "undefined") {
var imgSplit = imgs.split(",");
for (var i = imgSplit.length - 1; i >= 0; i--) {
var imgStr = imgSplit[i];
if (imgStr != "") {
var imgSpan = document.createElement('span');
var imgLabel = document.createElement('img');
imgLabel.setAttribute("src", imgStr);
imgLabel.setAttribute("data-original", imgStr);
imgLabel.setAttribute("class", "imgEnlarge");
imgSpan.appendChild(imgLabel);
node.tips2.setImg(imgSpan);
}
}
}
if (typeof (top.window.tipImgEnlarge) != "undefined") {
top.window.tipImgEnlarge(node.tips2.getoZlayerRe1());
}
node.tips2.setContent(data);
node.tips2.show();
loadImg = true;
}
} else {
node.tips.show();
}
};
node.onmouseout = function() {
node.tips.hide();
node.tips2.hide();
};
}
var target = node.getAttribute('target');
function GetQueryString(name) {
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = top.window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[3]); return null;
}
if (target == "readbook") {
function getCookie(objname){
var arrstr = document.cookie.split("; ");
for(var i = 0;i < arrstr.length;i ++){
var temp = arrstr[i].split("=");
if(temp[0] == objname){
return unescape(temp[1]);
}
}
}
if (/\/studentstudy/.test(top.location.pathname)) {
var setting = AttachmentSetting;
var isFiled=setting.defaults.isFiled;
var state=setting.defaults.state;
if (!(isFiled || state)) {
href = href + "&_from_=" + window._from;
}
href = href + "&uid=" + getCookie("_uid");
node.setAttribute("href", href);
}
} else {
if(insertNotes == 1){
href = "javascript:void(0);";
}else if(insertChapterUrl == 1){
var knowledgeId = node.getAttribute('knowledgeId');
var chapterCourseId = node.getAttribute('chapterCourseId');
var clazzId = 0;
var setting = parent.AttachmentSetting || AttachmentSetting;
if(setting && setting.defaults && setting.defaults.clazzId){
clazzId = setting.defaults.clazzId;
}
href = location.protocol + "//" + location.host + "/mooc-ans" + "/knowledge/chaptertransfer?courseid=" + chapterCourseId + "&knowledgeid=" + knowledgeId + "&clazzid=" + clazzId + "&type=1";
}else if(insertcrossurl == 1){
var crossId = node.getAttribute('crossId');
href = "javascript:void(0);";
node.removeAttribute('target');
node.addEventListener('click', function(event) {
event.preventDefault();
parent.parent.crossTransfer(crossId);
});
}else{
var from = GetQueryString("(from|_from_)");
var rtag = GetQueryString("(rtag)");
if (from) {
if (href.indexOf("?") > -1) {
href = href + "&_from_=" + from;
} else {
href = href + "?_from_=" + from;
}
}
if (rtag) {
rtag = rtag.replace(/<\/?[^>]+>/g,"").trim();
if (href.indexOf("?") > -1) {
href = href + "&rtag=" + rtag;
} else {
href = href + "?rtag=" + rtag;
}
}
}
node.setAttribute("href", href);
}
});
_each(content.getElementsByTagName('table'), function(node){
if (!(node.parentNode.className && (node.parentNode.className.indexOf('tableContainer') > -1 || node.parentNode.className.indexOf('table_box') > -1))) {
var tableTemp = document.createElement('div');
tableTemp.className = "tableContainer";
node.parentNode.insertBefore(tableTemp, node);
tableTemp.appendChild(node);
}
if (node.parentNode.className && node.parentNode.className.indexOf('table_box') > -1) {
// 使用闭包确保每次添加事件时都能访问到当前的 table
node.addEventListener('mouseenter', (function(currentTable) {
return function() {
currentTable.parentNode.classList.add('table_box_hover');
};
})(node));
node.addEventListener('mouseleave', (function(currentTable) {
return function() {
currentTable.parentNode.classList.remove('table_box_hover');
};
})(node));
}
});
try {
_each(content.querySelectorAll('.web-iframe.attachment_card'), function(node){
var iframe = document.createElement('iframe');
var iframeSrc = node.getAttribute('data-src');
iframe.src = iframeSrc;
iframe.width = '100%';
iframe.height = '500px';
iframe.frameBorder = '0';
iframe.className="mindMapFrame";
node.appendChild(iframe);
})
} catch (e) {
console.log(e)
}
}
function checkList(nodes){
var customCss = [],
customStyle = {
'cn' : 'cn-1-',
'cn1' : 'cn-2-',
'cn2' : 'cn-3-',
'num' : 'num-1-',
'num1' : 'num-2-',
'num2' : 'num-3-',
'dash' : 'dash',
'dot' : 'dot'
};
_each(nodes,function(list){
if(list.className && /custom_/i.test(list.className)){
var listStyle = list.className.match(/custom_(\w+)/)[1];
if(listStyle == 'dash' || listStyle == 'dot'){
pushItem(customCss,selector +' li.list-' + customStyle[listStyle] + '{background-image:url(' + defaultOption.liiconpath +customStyle[listStyle]+'.gif)}');
pushItem(customCss,selector +' ul.custom_'+listStyle+'{list-style:none;} '+ selector +' ul.custom_'+listStyle+' li{background-position:0 3px;background-repeat:no-repeat}');
}else{
var index = 1;
_each(list.childNodes,function(li){
if(li.tagName == 'LI'){
pushItem(customCss,selector + ' li.list-' + customStyle[listStyle] + index + '{background-image:url(' + defaultOption.liiconpath + 'list-'+customStyle[listStyle] +index + '.gif)}');
index++;
}
});
pushItem(customCss,selector + ' ol.custom_'+listStyle+'{list-style:none;}'+selector+' ol.custom_'+listStyle+' li{background-position:0 3px;background-repeat:no-repeat}');
}
switch(listStyle){
case 'cn':
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-1{padding-left:25px}');
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-2{padding-left:40px}');
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-3{padding-left:55px}');
break;
case 'cn1':
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-1{padding-left:30px}');
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-2{padding-left:40px}');
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-3{padding-left:55px}');
break;
case 'cn2':
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-1{padding-left:40px}');
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-2{padding-left:55px}');
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-3{padding-left:68px}');
break;
case 'num':
case 'num1':
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-1{padding-left:25px}');
break;
case 'num2':
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-1{padding-left:35px}');
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-2{padding-left:40px}');
break;
case 'dash':
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft{padding-left:35px}');
break;
case 'dot':
pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft{padding-left:20px}');
}
}
});
customCss.push(selector +' .list-paddingleft-1{padding-left:0}');
customCss.push(selector +' .list-paddingleft-2{padding-left:'+defaultOption.listDefaultPaddingLeft+'px}');
customCss.push(selector +' .list-paddingleft-3{padding-left:'+defaultOption.listDefaultPaddingLeft*2+'px}');
//
cssRule('list', selector + ' ol,' + selector + ' ul{margin:0;padding:0;}' + selector + ' li{clear:both;}' + customCss.join('\n'), document);
}
//
var needParseTagName = {
'table' : function(){
cssRule('table',
selector +' table.noBorderTable td,'+selector+' table.noBorderTable th,'+selector+' table.noBorderTable caption{border:1px dashed #ddd !important}' +
//
selector +' table{margin-bottom:10px;border-collapse:collapse;display:table;}' +
selector +' td,'+selector+' th{ background:white; padding: 5px 10px;border: 1px solid #DDD;}' +
selector +' caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}' +
selector +' th{border-top:2px solid #BBB;background:#F7F7F7;}' +
selector +' td p{margin:0;padding:0;}',
document);
},
'ol' : checkList,
'ul' : checkList,
/*'pre': function(nodes){
if(typeof XRegExp == "undefined"){
loadFile(document,{
id : "syntaxhighlighter_js",
src : defaultOption.highlightJsUrl,
tag : "script",
type : "text/javascript",
defer : "defer"
},function(){
_each(nodes,function(pi){
if(/brush/i.test(pi.className)){
SyntaxHighlighter.highlight(pi);
var tables = document.getElementsByTagName('table');
for(var t= 0,ti;ti=tables[t++];){
if(/SyntaxHighlighter/i.test(ti.className)){
var tds = ti.getElementsByTagName('td');
for(var i=0,li,ri;li=tds[0].childNodes[i];i++){
ri = tds[1].firstChild.childNodes[i];
if(ri){
ri.style.height = li.style.height = ri.offsetHeight + 'px';
}
}
}
}
}
});
});
}
if(!document.getElementById("syntaxhighlighter_css")){
loadFile(document,{
id : "syntaxhighlighter_css",
tag : "link",
rel : "stylesheet",
type : "text/css",
href : defaultOption.highlightCssUrl
});
}
},*/
'td':fillNode,
'th':fillNode,
'caption':fillNode,
'iframe':replaceModule,
'blockquote' : addHandler,
'img' : addTray
};
for(var tag in needParseTagName){
var nodes = content.getElementsByTagName(tag);
if(nodes.length){
needParseTagName[tag](nodes);
}
}
defaultOption.customRule(content);
showTips(content);
function filterStyle(content){
// 如果p标签下有附件并且p标签上有宽度样式的情况下,把宽度清除
_each(content.getElementsByTagName('p'), function(node){
if (node.querySelectorAll("iframe").length > 0) {
// 获取元素的当前样式字符串
var styleString = node.getAttribute('style') || '';
if (styleString == '') {
return;
}
// 将样式字符串分割为单独的样式声明数组
var styleDeclarations = styleString.split(';');
// 过滤掉包含width的样式声明
var filteredDeclarations = styleDeclarations.filter(function(declaration) {
return !declaration.trim().startsWith('width');
});
// 重新组合剩余的样式声明为一个字符串
var newStyleString = filteredDeclarations.join(';').trim();
// 如果还有剩余的样式,则设置回元素的style属性,否则移除style属性
if (newStyleString) {
node.setAttribute('style', newStyleString);
} else {
node.removeAttribute('style');
}
}
})
}
filterStyle(content);
// 图片拖拽后重新计算比例
function resizeLayoutImgs(layout){
var resizeArr = [],minHeight ,totalWidth = 0;
var allImgs = layout.querySelectorAll('img[src]');
var imgWidth = null, imgFloat = null;
// 并排图片小于一张,去除layout
if(allImgs.length <= 1){
allImgs.forEach(function(img){
img.style.height = null;
imgWidth = img.width;
imgFloat = img.style["float"];
})
var wrap = layout.querySelector('.image_wrap');
if(wrap){
wrap.style.width = null;
var desc = wrap.querySelector('.img_desc');
if (desc && imgWidth) {
desc.style.width = imgWidth + "px";
if (imgFloat) {
desc.style["float"] = img.style["float"];
}
}
}
layout.outerHTML = layout.innerHTML;
}
// 多余一张,计算比例
else {
allImgs.forEach(function(img){
img.style.height = null;
resizeArr.push({
el:img,
width:img.naturalWidth,
height:img.naturalHeight,
wh:img.naturalWidth/img.naturalHeight
})
minHeight = minHeight < img.naturalHeight ? minHeight : img.naturalHeight;
})
minHeight = minHeight < 200 ? 200 : minHeight;
resizeArr.forEach(function(info){
info.showWidth = minHeight * info.wh;
totalWidth += info.showWidth;
})
resizeArr.forEach(function(info){
var rate = info.showWidth / totalWidth;
info.el.closest(".image_wrap").style.width = (rate*100).toFixed(2) + '%';
})
// 使高度完全对齐
var allImgBox = layout.querySelectorAll('.img_box');
var height = 0;
allImgBox.forEach(function(imgBox){
boxHeight = imgBox.clientHeight;
height = height < boxHeight ? boxHeight : height;
})
resizeArr.forEach(function(info){
var wrap = info.el.parentElement.parentElement;
var img = wrap.querySelector('img[src]');
if (!img.style.width) {
// 图片没有调整过大小
img.style.height = height + 'px';
img.style.width = null;
var desc = wrap.querySelector('.img_desc');
if (desc) {
desc.removeAttribute("style");
}
} else {
var scalePercent = img.getAttribute("scalepercent");
if (scalePercent) {
img.style.height = height * parseFloat(scalePercent) + "px";
img.style.width = wrap.clientWidth * parseFloat(scalePercent) + "px";
}
var desc = wrap.querySelector('.img_desc');
if (desc) {
desc.removeAttribute("style");
}
}
})
}
}
function resizeImgLayout(content) {
_each(content.getElementsByClassName('image_layout'), function(layout){
resizeLayoutImgs(layout);
})
}
setTimeout(function() {
resizeImgLayout(content);
}, 50);
// 监听页面大小的改变重新计算图片的尺寸
window.addEventListener('resize', function() {
resizeImgLayout(content);
});
});
})();
}