document.write('');
if (location.hostname.indexOf("qidian.com") >= 0) document.domain = "qidian.com";
if (location.hostname.indexOf("qdmm.com") >= 0) document.domain = "qdmm.com";
if (location.hostname.indexOf("qdwenxue.com") >= 0) document.domain = "qdwenxue.com";
//config
var __sosu_opNameCongfig__ = {
enable: 1, //全局开关,0关闭,1开启
proxyID: '__sosu_js_proxy_',
proxyUrl: 'http://a.if.' + document.domain + '/Proxy/sosu.js.proxy.htm'
};
//end config
var addEvent = addEvent || function(target, event, fn) {
if (window.attachEvent) target.attachEvent('on' + event, fn)
else if (window.addEventListener) target.addEventListener(event, fn, false)
else target['on' + event] = fn;
}
var sosuInvokeIframe = function(b) {
var a = document.getElementById(__sosu_opNameCongfig__.proxyID);
if (!a) {
a = document.createElement("iframe");
a.id = __sosu_opNameCongfig__.proxyID;
a.src = __sosu_opNameCongfig__.proxyUrl;
a.style.display = "none";
document.body.insertBefore(a, document.body.childNodes[0])
}
var d = 0;
try {
a.contentWindow.Snda.Ajax
} catch(c) {
d = 1
}
if (d == 0 && a.contentWindow.Snda.Ajax) {
new a.contentWindow.Snda.Ajax().invoke(b)
} else {
addEvent(a, "load",
function() {
new a.contentWindow.Snda.Ajax().invoke(b)
})
}
};
String.prototype.Trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
String.prototype.Format = function() { var t = this; for (var i = 0, j = arguments.length; i < j; i += 1) t = t.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]); return t; };
if (typeof $ == "undefined") { $ = function(element) { return document.getElementById(element); }; };
function SetTxtWordsNoValue() {
var searchtxt = $("txtwords");
if (searchtxt.value == "书号/书名/作者") {
searchtxt.value = "";
searchtxt.style.color = "";
};
};
function SetTxtWordsValue() {
var searchtxt = $("txtwords");
if (searchtxt.value == "") {
searchtxt.value = "书号/书名/作者";
searchtxt.style.color = "Gray";
};
};
if (!window.Snda) var Snda = window.Snda = {};
(function() {
Snda.extend = function(dest, source, replace) {//扩展
for (prop in source) {
if (replace == false && dest[prop] != null) continue;
dest[prop] = source[prop];
};
return dest;
};
if (!window.Snda.Utility) Snda.Utility = {};
Snda.extend(Snda.Utility, {
HightLightElement: function(node, key, className) {//高亮单个元素
if (key.length === 0) return false;
var pattern = new RegExp(key, "gi");
var html = node.innerHTML;
html = html.replace(pattern, "" + key + "");
node.innerHTML = html;
},
Event: {//事件
addEventHandler: function(oTarget, sEventType, fnHandler, bool) {//事件绑定
if (oTarget.addEventListener) oTarget.addEventListener(sEventType, fnHandler, bool); //FF方法
else if (oTarget.attachEvent) oTarget.attachEvent("on" + sEventType, fnHandler); //IE方法
else oTarget["on" + sEventType] = fnHandler; //其他未知浏览器
},
removeEventHandler: function(obj, EventType, Handler, bool) {
if (obj.removeEventListener) obj.removeEventListener(EventType, Handler, bool);
else if (obj.detachEvent) obj.detachEvent('on' + EventType, Handler);
else obj['on' + EventType] = null;
},
getCurrentElem: function(evt) {//获取事件元素
evt = evt || window.event;
return evt.srcElement || evt.target;
},
elementClick: function(e) {//元素点击
if (document.all) e.click();
else if (document.createEvent) {
var ev = document.createEvent('MouseEvents');
ev.initEvent('click', false, true);
e.dispatchEvent(ev);
};
}
},
cancelBubble: function(evt) {//取消冒泡
evt = evt || window.event;
if (window.event) evt.cancelBubble = true;
else evt.stopPropagation();
}
}, false);
Snda.extend(Snda, {
Ajax: function() {
this.xml = false;
this.GetXmlHttp = function() {
try { this.xml = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
try { this.xml = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e2) { this.xml = false; };
};
if (!this.xml && typeof XMLHttpRequest != 'undefined') this.xml = new XMLHttpRequest();
};
this.httpSuccess = function(r) {
try {
return !r.status && location.protocol == "file:" ||
(r.status >= 200 && r.status < 300) ||
r.status == 304 ||
navigator.userAgent.indexOf("Safari") >= 0 && typeof r.status == "undefined";
} catch (e) { };
return false;
};
this.httpData = function(r, type) {
var ct = r.getResponseHeader("content-type");
var data = !type && ct && ct.indexOf("xml") >= 0;
data = type == "xml" || data ? r.responseXML : r.responseText;
if (type == "script") eval.call(window, data);
return data;
};
this.GetXmlHttp();
var xmlHttp = this.xml, ajax = this, requestDone = false, _json = {};
this.updatePage = function() {
if (xmlHttp && xmlHttp.readyState == 4 && !requestDone) {
if (ajax.httpSuccess(xmlHttp)) _json.onSuccess(ajax.httpData(xmlHttp, _json.type));
else _json.onError();
_json.onComplete();
xmlHttp = null;
};
if (requestDone) throw new Error("请求超时");
};
this.invoke = function(options) {
_json = {
type: options.type || "POST",
op: options.op || '-1',
url: options.url || "",
timeout: options.timeout || 5000,
onComplete: options.onComplete || function() { },
onError: options.onError || function() { },
onSuccess: options.onSuccess || function() { },
data: options.data || {}
};
if (xmlHttp) {
setTimeout(function() { requestDone = true; }, _json.timeout);
if (_json.type.toUpperCase() == "GET") {
_json.url += "?opName=" + _json.op + "&" + Snda.Ajax.toQueryString(_json.data);
xmlHttp.onreadystatechange = ajax.updatePage;
xmlHttp.open("GET", _json.url, true);
xmlHttp.setRequestHeader("CMFUAJAX-Ver", "ver1.0");
xmlHttp.send(null);
} else {
_json.url += "?opName=" + _json.op;
var _p = Snda.Ajax.toQueryString(_json.data);
xmlHttp.onreadystatechange = ajax.updatePage;
xmlHttp.open("POST", _json.url, true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("CMFUAJAX-Ver", "ver1.0");
xmlHttp.setRequestHeader("Content-length", _p.length);
xmlHttp.send(_p);
};
};
};
}
}, false);
Snda.Ajax.toQueryString = function(a) {
var s = [];
if (a.constructor == Array) for (var i = 0; i < a.length; i++) s.push(a[i].name + "=" + escape(a[i].value));
else for (var j in a) s.push(j + "=" + escape(a[j]));
return s.join("&");
};
Snda.Suggest = {//下拉提示
_config: {//
id: 'txtwords',
bid: '书号',
bname: '书名',
tbv: '书号/书名/作者',
T1: '
'
},
_sosuOn:true,//下拉智能提示新数据接口开关true开启,false关闭
Init: function() {//初始化
var _ao = {}; //下拉提示目标框
var _div = document.createElement('div');
return {
Event: function(id, config) {
Snda.extend(Snda.Suggest._config, config);
Snda.Suggest._config.T1 = Snda.Suggest._config.T1.Format(Snda.Suggest._config.bid, Snda.Suggest._config.bname);
_ao = $(id);
_div.className = 'autocompletelist';
_div.id = "div_drl_" + Math.floor(Math.random() * 10000000000);
_div.$cache = {}; //查询缓存
_div.$index = 0; //方向选择序列
_div.$search = ''; //搜索值
},
onSucess: function(data) {//请求成功回调
try {
if(!Snda.Suggest._sosuOn){
if (typeof data == 'string') {
data = eval(data);
data = eval(data.replace('var dataSource=', ''))
}
if (data.error || data.length < 1) {
Snda.Suggest.Init.OnBlur(); return false;
}
}else{
if (typeof data == 'string') {
var newdata = eval("("+data+")");
data = new Array();
if (newdata.Flag){
for (var i = 0; i < newdata.Data.search_response.books.length; i++) {
data[i] = {};
data[i].hints = i;
if(newdata.Data.search_response.books[i].type=='user'){
data[i].content = newdata.Data.search_response.books[i].authorname;
if(data[i].content=='none')data[i].content = newdata.Data.search_response.books[i].username;
}
else if(newdata.Data.search_response.books[i].type=='book')
data[i].content = newdata.Data.search_response.books[i].bookname;
}
}else{ return; /*失败直接返回不提示*/}}
}} catch (e) { return false; };
_div.$cache[_div.$search] = data; //插入缓存
Snda.Suggest.Init.Create(data);
},
Create: function(data) {//填充容器
if (data.error) return false;
_div.innerHTML = Snda.Suggest._config.T1; //填充外框
var _li = _div.getElementsByTagName('li')[0]; //获取填充的首元素
_div.$first = _li;
for (var i = 0; i < data.length; i += 1) {
if(data[i].content && data[i].content.length>0){
var _tl = Snda.Suggest.Init.CreateLi(i);
_tl.appendChild(Snda.Suggest.Init.CreateSpan(data[i].content, 'bk', _tl));
if(!Snda.Suggest._sosuOn){ if (new RegExp("^[0-9]*$").test(_div.$search) == true) _tl.appendChild(Snda.Suggest.Init.CreateSpan(data[i].hints, 'bn', _tl));}
_li.parentNode.appendChild(_tl);
}
};
document.body.appendChild(_div); //填充显示位置
var _xy = Snda.Suggest.Init.GetXY($("txtwords"), _div.id);
_div.style.left = _xy.x;
_div.style.top = _xy.y;
if(!Snda.Suggest._sosuOn){ if (new RegExp("^[0-9]*$").test(_div.$search) == true) $("liTitle").style.display = "";}
},
CreateLi: function(i) {//Li元素创建
var _tl = document.createElement('li');
_tl.$index = i + 1;
var MoveLi = function() {//鼠标数据移动
for (var i = 1, j = _tl.parentNode.childNodes.length; i < j; i += 1)
if (_tl.parentNode.childNodes[i] === _tl) {
_tl.className = 'gb';
_div.$index = _tl.$index;
_ao.value = _tl['bk'].innerText || _tl['bk'].textContent;
} else _tl.parentNode.childNodes[i].className = '';
};
Snda.Utility.Event.addEventHandler(_tl, 'mouseover', MoveLi, false);
Snda.Utility.Event.addEventHandler(_tl, 'mouseout', MoveLi, false);
return _tl
},
CreateSpan: function(value, className, li) {//bn bk
var _span = document.createElement('span');
_span.className = className;
_span.innerHTML = value;
Snda.Utility.HightLightElement(_span, _div.$search, 'hightlight'); //高亮关键字
li[className] = _span; //缓存span到li内
return _span;
},
DefaultfindPosX: function(obj) {
var curleft = 0;
if (obj && obj.offsetParent) {
while (obj.offsetParent) {
curleft += obj.offsetLeft;
obj = obj.offsetParent;
};
} else if (obj && obj.x) curleft += obj.x;
return curleft;
},
DefaultfindPosY: function(obj) {
var curtop = 0;
if (obj && obj.offsetParent) {
while (obj.offsetParent) {
curtop += obj.offsetTop;
obj = obj.offsetParent;
};
} else if (obj && obj.y) curtop += obj.y;
return curtop;
},
GetXY: function(obj, Layers) {
var left = Snda.Suggest.Init.DefaultfindPosX(obj);
$(Layers).style.left = left + "px";
var top = Snda.Suggest.Init.DefaultfindPosY(obj) + 20;
$(Layers).style.top = top + "px";
return { x: left, y: top }
},
GetAbsolutePos: function(el) {
var r = { x: el.offsetLeft, y: el.offsetTop };
if (el.offsetParent) {
var tmp = Snda.Suggest.Init.getAbsolutePos(el.offsetParent);
r.x += tmp.x;
r.y += tmp.y;
}
return r;
},
OnKeyUp: function(evt) {//查询
evt = evt || window.event;
_ao = Snda.Utility.Event.getCurrentElem(evt);
var keycode = evt.keyCode;
var _invalidKeyCode = [13, 38, 40, 27, 9, 17, 16];
for (var key in _invalidKeyCode) {
if (keycode == _invalidKeyCode[key])
return false;
};
if (_ao.value.Trim().length != 0 && Snda.Suggest._sosuOn) {//查询不为空并且打开搜索开关
_div.$search = _ao.value.Trim(); //插入查询数据到闭包值
if (_div.$cache[_div.$search]) Snda.Suggest.Init.onSucess(_div.$cache[_div.$search]); //缓存存在
else {
if (__sosu_opNameCongfig__.enable == 1)
sosuInvokeIframe({ op:'GetSosuBookInfoNew', type: 'get', url: "http://a.if." + document.domain + '/AjaxCom.aspx', data: { keyword: _div.$search, type: 'main' }, onSuccess: Snda.Suggest.Init.onSucess });
else
new Snda.Ajax().invoke({ op:'GetSosuBookInfoNew', type: 'get', url: "http://" + window.location.host + '/AjaxCom.aspx', data: { keyword: _div.$search, type: 'main' }, onSuccess: Snda.Suggest.Init.onSucess });
}
}
else {
Snda.Suggest.Init.OnBlur();
};
Snda.Utility.cancelBubble(evt); //取消冒泡
},
OnBlur: function() {//失去焦点
try {
_div.parentNode.removeChild(_div); //移除提示
_div.$index = 0; //重置序列
} catch (e) { };
},
OnKeyDown: function(evt) {//方向键
evt = window.event || evt;
var _o = evt.srcElement || evt.target;
if (_ao != _o) return true;
var SetStyle = function() {//样式设置
for (var i = 1; i < _ul.childNodes.length; i++) {
if (i === _div.$index) {
_ul.childNodes[i].className = 'gb';
_ao.value = _ul.childNodes[i].childNodes[0].innerText || _ul.childNodes[i].childNodes[0].textContent;
} else _ul.childNodes[i].className = ''
};
};
var UP = function() {//上翻
_div.$index--;
if (_div.$index < 1) _div.$index = _ul.childNodes.length - 1;
SetStyle();
};
var DOWN = function() {//下翻
_div.$index++;
if (_div.$index >= _ul.childNodes.length) _div.$index = 1;
SetStyle();
};
if ($(_div.id)) {//查询框存在
var _ul = _div.$first.parentNode;
switch (evt.keyCode) {
case 38: UP(); break; //上
case 40: DOWN(); break; //下
default: break;
};
};
Snda.Utility.cancelBubble(evt); //取消冒泡
},
SetTxtWordsNoValue: function() {
if (_ao.value == Snda.Suggest._config.tbv) {
_ao.value = "";
_ao.style.color = "";
};
},
SetTxtWordsValue: function() {
if (_ao.value == "") {
_ao.value = Snda.Suggest._config.tbv;
_ao.style.color = "Gray";
};
}
};
} (),
Bind: function(data) {//绑定事件显示
if (!data.id)
data.id = 'txtwords';
var $o = $(data.id);
$o.setAttribute("AutoComplete", "off");
Snda.Suggest.Init.Event(data.id, data);
Snda.Utility.Event.addEventHandler($o, 'blur', Snda.Suggest.Init.OnBlur, false);
Snda.Utility.Event.addEventHandler(document.body, 'keydown', Snda.Suggest.Init.OnKeyDown, false);
Snda.Utility.Event.addEventHandler($o, 'click', Snda.Suggest.Init.SetTxtWordsNoValue, false);
Snda.Utility.Event.addEventHandler($o, 'blur', Snda.Suggest.Init.SetTxtWordsValue, false);
if(Snda.Suggest._sosuOn){
Snda.Utility.Event.addEventHandler($o, 'keyup', Snda.Suggest.Init.OnKeyUp, false);
var stype = document.getElementById('searchtype');
if(stype.options.length>3){
stype.options.remove(1);
stype.options.remove(1);
stype.options.remove(1);
stype.options.remove(2);
stype.options.remove(2);
}
}
}
};
})();