dialog.js 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520
  1. __DIALOG_WRAPPER__ = {};
  2. /* IE6有个Bug,如果不给定对话框的宽度的话,在IE6下,对话框将以100%宽度显示 */
  3. DialogManager = {
  4. 'create' :function(id){
  5. var d = {};
  6. if (!__DIALOG_WRAPPER__[id])
  7. {
  8. d = new Dialog(id);
  9. __DIALOG_WRAPPER__[id] = d;
  10. }
  11. else
  12. {
  13. d = DialogManager.get(id);
  14. }
  15. return d;
  16. },
  17. 'get' :function(id){
  18. return __DIALOG_WRAPPER__[id];
  19. },
  20. 'set' :function(id, val){
  21. __DIALOG_WRAPPER__[id] = val;
  22. },
  23. 'close' :function(id){
  24. if (__DIALOG_WRAPPER__[id].close())
  25. {
  26. __DIALOG_WRAPPER__[id] = null;
  27. }
  28. },
  29. 'onClose' :function (){
  30. return true;
  31. },
  32. /* 加载对话框样式 */
  33. 'loadStyle' :function(){
  34. var _dialog_js_path = $('#dialog_js').attr('src');
  35. var _path = _dialog_js_path.split('/');
  36. var _dialog_css = _path.slice(0, _path.length - 1).join('/') + '/dialog.css';
  37. $('#dialog_js').after('<link href="' + _dialog_css + '" rel="stylesheet" type="text/css" />');
  38. }
  39. };
  40. ScreenLocker = {
  41. 'style' : {
  42. 'position' : 'absolute',
  43. 'top' : '0px',
  44. 'left' : '0px',
  45. 'backgroundColor' : 'transparent',
  46. 'opacity' : 0,
  47. 'zIndex' : 999
  48. },
  49. 'masker' : null,
  50. 'lock' : function(zIndex){
  51. if (this.masker !== null)
  52. {
  53. this.masker.width($(document).width()).height($(document).height());
  54. return true;
  55. }
  56. this.masker = $('<div id="dialog_manage_screen_locker"></div>');
  57. /* 样式 */
  58. this.masker.css(this.style);
  59. if (zIndex)
  60. {
  61. this.masker.css('zIndex', zIndex);
  62. }
  63. /* 整个文档的宽高 */
  64. this.masker.width($(document).width()).height($(document).height());
  65. $(document.body).append(this.masker);
  66. $("#dialog_manage_screen_locker").show();
  67. },
  68. 'unlock' : function(){
  69. if (this.masker === null)
  70. {
  71. return true;
  72. }
  73. this.masker.remove();
  74. this.masker = null;
  75. }
  76. };
  77. Dialog = function (id){
  78. /* 构造函数生成对话框代码,并加入到文档中 */
  79. this.id = id;
  80. this.init();
  81. };
  82. Dialog.prototype = {
  83. /* 唯一标识 */
  84. 'id' : null,
  85. /* 文档对象 */
  86. 'dom' : null,
  87. 'lastPos' : null,
  88. 'status' : 'complete',
  89. 'onClose' : function (){
  90. return true;
  91. },
  92. 'tmp' : {},
  93. /* 初始化 */
  94. 'init' : function(){
  95. this.dom = {'wrapper' : null, 'body':null, 'head':null, 'title':null, 'close_button':null, 'content':null};
  96. /* 创建外层容器 */
  97. this.dom.wrapper = $('<div id="fwin_' + this.id + '" class="dialog_wrapper"></div>').get(0);
  98. /* 创建对话框主体 */
  99. this.dom.body = $('<div class="dialog_body"></div>').get(0);
  100. /* 创建标题栏 */
  101. this.dom.head = $('<h3 class="dialog_head"></h3>').get(0);
  102. /* 创建标题文本 */
  103. this.dom.title = $('<span class="dialog_title_icon"></span>').get(0);
  104. /* 创建关闭按钮 */
  105. this.dom.close_button = $('<span class="dialog_close_button">X</span>').get(0);
  106. /* 创建内容区域 */
  107. this.dom.content = $('<div class="dialog_content"></div>').get(0);
  108. /* 组合 */
  109. $(this.dom.head).append($('<span class="dialog_title"></span>').append(this.dom.title)).append(this.dom.close_button);
  110. $(this.dom.body).append(this.dom.head).append(this.dom.content);
  111. $(this.dom.wrapper).append(this.dom.body).append('<div style="clear:both; display:block;"></div>');
  112. /* 初始化样式 */
  113. $(this.dom.wrapper).css({
  114. 'zIndex' : 1100,
  115. 'display' : 'none',
  116. 'position' : 'absolute'
  117. });
  118. $(this.dom.body).css({
  119. 'position' : 'relative'
  120. });
  121. $(this.dom.head).css({
  122. 'cursor' : 'move'
  123. });
  124. $(this.dom.content).css({
  125. 'margin' : '0px',
  126. 'padding' : '0px'
  127. });
  128. var self = this;
  129. /* 初始化组件事件 */
  130. $(this.dom.close_button).click(function(){
  131. DialogManager.close(self.id);
  132. });
  133. /* 可拖放 */
  134. // if(typeof draggable != 'undefined'){
  135. // $(this.dom.wrapper).draggable({
  136. // 'handle' : this.dom.head
  137. // });
  138. // }
  139. /* 放入文档流 */
  140. $(document.body).append(this.dom.wrapper);
  141. },
  142. /* 隐藏 */
  143. 'hide' : function(){
  144. $(this.dom.wrapper).hide();
  145. },
  146. /* 显示 */
  147. 'show' : function(pos,lock){
  148. if (pos)
  149. {
  150. this.setPosition(pos);
  151. }
  152. /* 锁定屏幕 */
  153. if (lock == 1) ScreenLocker.lock(999);
  154. $(this.dom.wrapper).draggable({
  155. 'handle' : this.dom.head
  156. });
  157. /* 显示对话框 */
  158. $(this.dom.wrapper).show();
  159. },
  160. /* 关闭 */
  161. 'close' : function(lock){
  162. if (!this.onClose())
  163. {
  164. return false;
  165. }
  166. /* 关闭对话框 */
  167. $(this.dom.wrapper).remove();
  168. /* 解锁屏幕 */
  169. if (typeof lock == 'undefined'){
  170. ScreenLocker.unlock();
  171. }
  172. DialogManager.set(this.id,null);
  173. return true;
  174. },
  175. /* 对话框标题 */
  176. 'setTitle' : function(title){
  177. $(this.dom.title).html(title);
  178. },
  179. /* 改变对话框内容 */
  180. 'setContents' : function(type, options){
  181. contents = this.createContents(type, options);
  182. if (typeof(contents) == 'string')
  183. {
  184. $(this.dom.content).html(contents);
  185. }
  186. else
  187. {
  188. $(this.dom.content).empty();
  189. $(this.dom.content).append(contents);
  190. }
  191. },
  192. /* 设置对话框样式 */
  193. 'setStyle' : function(style){
  194. if (typeof(style) == 'object')
  195. {
  196. /* 否则为CSS */
  197. $(this.dom.wrapper).css(style);
  198. }
  199. else
  200. {
  201. /* 如果是字符串,则认为是样式名 */
  202. $(this.dom.wrapper).addClass(style);
  203. }
  204. },
  205. 'setWidth' : function(width){
  206. this.setStyle({'width' : width + 'px'});
  207. },
  208. 'setHeight' : function(height){
  209. this.setStyle({'height' : height + 'px'});
  210. },
  211. /* 生成对话框内容 */
  212. 'createContents' : function(type, options){
  213. var _html = '',
  214. self = this,
  215. status= 'complete';
  216. if (!options)
  217. {
  218. /* 如果只有一个参数,则认为其传递的是HTML字符串 */
  219. this.setStatus(status);
  220. return type;
  221. }
  222. switch(type){
  223. case 'ajax':
  224. /* 通过Ajax取得HTML,显示到页面上,此过程是异步的 */
  225. $.get(options, function(data){
  226. self.setContents(data);
  227. /* 使用上次定位重新定位窗口位置 */
  228. self.setPosition(self.lastPos);
  229. });
  230. /* 先提示正在加载 */
  231. _html = this.createContents('loading', {'text' : 'loading...'});
  232. break;
  233. case 'ajax_notice':
  234. /* 通过Ajax取得HTML,显示到页面上,此过程是异步的 */
  235. $.get(options, function(data) {
  236. var json = eval('(' + data + ')');
  237. var MsgTxt = '<div class="dialog_message_body"></div><div class="dialog_message_contents dialog_message_notice">' + json.Msg + '</div><div class="dialog_buttons_bar"></div>'
  238. self.setContents(MsgTxt);
  239. /* 使用上次定位重新定位窗口位置 */
  240. self.setPosition(self.lastPos);
  241. });
  242. /* 先提示正在加载 */
  243. _html = this.createContents('loading', { 'text': '正在处理...' });
  244. break;
  245. /* 以下是内置的几种对话框类型 */
  246. case 'loading':
  247. _html = '<div class="dialog_loading"><div class="dialog_loading_text">' + options.text + '</div></div>';
  248. status = 'loading';
  249. break;
  250. case 'message':
  251. var type = 'notice';
  252. if (options.type)
  253. {
  254. type = options.type;
  255. }
  256. _message_body = $('<div class="dialog_message_body"></div>');
  257. _message_contents = $('<div class="dialog_message_contents dialog_message_' + type + '">' + options.text + '</div>');
  258. _buttons_bar = $('<div class="dialog_buttons_bar"></div>');
  259. switch (type){
  260. case 'notice':
  261. case 'warning':
  262. var button_name = '确定';
  263. if (options.button_name)
  264. {
  265. button_name = options.button_name;
  266. }
  267. _ok_button = $('<input type="button" class="btn1" value="' + button_name + '" />');
  268. $(_ok_button).click(function(){
  269. if (options.onclick)
  270. {
  271. if(!options.onclick.call())
  272. {
  273. return;
  274. }
  275. }
  276. DialogManager.close(self.id);
  277. });
  278. $(_buttons_bar).append(_ok_button);
  279. break;
  280. case 'confirm':
  281. var yes_button_name = "确定";
  282. var no_button_name = "取消";
  283. if (options.yes_button_name)
  284. {
  285. yes_button_name = options.yes_button_name;
  286. }
  287. if (options.no_button_name)
  288. {
  289. no_button_name = options.no_button_name;
  290. }
  291. _yes_button = $('<input type="button" class="btn1" value="' + yes_button_name + '" />');
  292. _no_button = $('<input type="button" class="btn2" value="' + no_button_name + '" />');
  293. $(_yes_button).click(function(){
  294. if (options.onClickYes)
  295. {
  296. if (options.onClickYes.call() === false)
  297. {
  298. return;
  299. }
  300. }
  301. DialogManager.close(self.id);
  302. });
  303. $(_no_button).click(function(){
  304. if (options.onClickNo)
  305. {
  306. if (!options.onClickNo.call())
  307. {
  308. return;
  309. }
  310. }
  311. DialogManager.close(self.id);
  312. });
  313. $(_buttons_bar).append(_yes_button).append(_no_button);
  314. break;
  315. }
  316. _html = $(_message_body).append(_message_contents).append(_buttons_bar);
  317. break;
  318. }
  319. this.setStatus(status);
  320. return _html;
  321. },
  322. /* 定位 */
  323. 'setPosition' : function(pos){
  324. /* 上次定位 */
  325. this.lastPos = pos;
  326. if (typeof(pos) == 'string')
  327. {
  328. switch(pos){
  329. case 'center':
  330. var left = 0;
  331. var top = 0;
  332. var dialog_width = $(this.dom.wrapper).width();
  333. var dialog_height = $(this.dom.wrapper).height();
  334. /* left=滚动条的宽度 + (当前可视区的宽度 - 对话框的宽度 ) / 2 */
  335. left = $(window).scrollLeft() + ($(window).width() - dialog_width) / 2;
  336. /* top =滚动条的高度 + (当前可视区的高度 - 对话框的高度 ) / 2 */
  337. top = $(window).scrollTop() + ($(window).height() - dialog_height) / 2;
  338. $(this.dom.wrapper).css({left:left + 'px', top:top + 'px'});
  339. break;
  340. }
  341. }
  342. else
  343. {
  344. var _pos = {};
  345. if (typeof(pos.left) != 'undefined')
  346. {
  347. _pos.left = pos.left;
  348. }
  349. if (typeof(pos.top) != 'undefined')
  350. {
  351. _pos.top = pos.top;
  352. }
  353. $(this.dom.wrapper).css(_pos);
  354. }
  355. },
  356. /* 设置状态 */
  357. 'setStatus' : function(code){
  358. this.status = code;
  359. },
  360. /* 获取状态 */
  361. 'getStatus' : function(){
  362. return this.status;
  363. },
  364. 'disableClose' : function(msg){
  365. this.tmp['oldOnClose'] = this.onClose;
  366. this.onClose = function(){
  367. if(msg)alert(msg);
  368. return false;
  369. };
  370. },
  371. 'enableClose' : function(){
  372. this.onClose = this.tmp['oldOnClose'];
  373. this.tmp['oldOnClose'] = null;
  374. }
  375. };
  376. DialogManager.loadStyle();
  377. /*common2.2.js*/
  378. DIALOGIMGDIR = SITEURL+"/"+'resource/js/dialog/images/dialog';
  379. var BROWSER = {};
  380. var USERAGENT = navigator.userAgent.toLowerCase();
  381. browserVersion({'ie':'msie','firefox':'','chrome':'','opera':'','safari':'','mozilla':'','webkit':'','maxthon':'','qq':'qqbrowser'});
  382. if(BROWSER.safari) {
  383. BROWSER.firefox = true;
  384. }
  385. BROWSER.opera = BROWSER.opera ? opera.version() : 0;
  386. HTMLNODE = document.getElementsByTagName('head')[0].parentNode;
  387. if(BROWSER.ie) {
  388. BROWSER.iemode = parseInt(typeof document.documentMode != 'undefined' ? document.documentMode : BROWSER.ie);
  389. HTMLNODE.className = 'ie_all ie' + BROWSER.iemode;
  390. }
  391. var JSLOADED = [];
  392. var JSMENU = [];
  393. JSMENU['active'] = [];
  394. JSMENU['timer'] = [];
  395. JSMENU['drag'] = [];
  396. JSMENU['layer'] = 0;
  397. JSMENU['zIndex'] = {'win':1000,'menu':1100,'dialog':1200,'prompt':1300};
  398. JSMENU['float'] = '';
  399. var CURRENTSTYPE = null;
  400. var EXTRAFUNC = [], EXTRASTR = '';
  401. if(BROWSER.firefox && window.HTMLElement) {
  402. HTMLElement.prototype.__defineGetter__( "innerText", function(){
  403. var anyString = "";
  404. var childS = this.childNodes;
  405. for(var i=0; i <childS.length; i++) {
  406. if(childS[i].nodeType==1) {
  407. anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
  408. } else if(childS[i].nodeType==3) {
  409. anyString += childS[i].nodeValue;
  410. }
  411. }
  412. return anyString;
  413. });
  414. HTMLElement.prototype.__defineSetter__( "innerText", function(sText){
  415. this.textContent=sText;
  416. });
  417. HTMLElement.prototype.__defineSetter__('outerHTML', function(sHTML) {
  418. var r = this.ownerDocument.createRange();
  419. r.setStartBefore(this);
  420. var df = r.createContextualFragment(sHTML);
  421. this.parentNode.replaceChild(df,this);
  422. return sHTML;
  423. });
  424. HTMLElement.prototype.__defineGetter__('outerHTML', function() {
  425. var attr;
  426. var attrs = this.attributes;
  427. var str = '<' + this.tagName.toLowerCase();
  428. for(var i = 0;i < attrs.length;i++){
  429. attr = attrs[i];
  430. if(attr.specified)
  431. str += ' ' + attr.name + '="' + attr.value + '"';
  432. }
  433. if(!this.canHaveChildren) {
  434. return str + '>';
  435. }
  436. return str + '>' + this.innerHTML + '</' + this.tagName.toLowerCase() + '>';
  437. });
  438. HTMLElement.prototype.__defineGetter__('canHaveChildren', function() {
  439. switch(this.tagName.toLowerCase()) {
  440. case 'area':case 'base':case 'basefont':case 'col':case 'frame':case 'hr':case 'img':case 'br':case 'input':case 'isindex':case 'link':case 'meta':case 'param':
  441. return false;
  442. }
  443. return true;
  444. });
  445. }
  446. function $$(id) {
  447. return !id ? null : document.getElementById(id);
  448. }
  449. function _attachEvent(obj, evt, func, eventobj) {
  450. eventobj = !eventobj ? obj : eventobj;
  451. if(obj.addEventListener) {
  452. obj.addEventListener(evt, func, false);
  453. } else if(eventobj.attachEvent) {
  454. obj.attachEvent('on' + evt, func);
  455. }
  456. }
  457. function browserVersion(types) {
  458. var other = 1;
  459. for(i in types) {
  460. var v = types[i] ? types[i] : i;
  461. if(USERAGENT.indexOf(v) != -1) {
  462. var re = new RegExp(v + '(\\/|\\s)([\\d\\.]+)', 'ig');
  463. var matches = re.exec(USERAGENT);
  464. var ver = matches != null ? matches[2] : 0;
  465. other = ver !== 0 && v != 'mozilla' ? 0 : other;
  466. }else {
  467. var ver = 0;
  468. }
  469. eval('BROWSER.' + i + '= ver');
  470. }
  471. BROWSER.other = other;
  472. }
  473. function getEvent() {
  474. if(document.all) return window.event;
  475. func = getEvent.caller;
  476. while(func != null) {
  477. var arg0 = func.arguments[0];
  478. if (arg0) {
  479. if((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof(arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
  480. return arg0;
  481. }
  482. }
  483. func=func.caller;
  484. }
  485. return null;
  486. }
  487. function isUndefined(variable) {
  488. return typeof variable == 'undefined' ? true : false;
  489. }
  490. function in_array(needle, haystack) {
  491. if(typeof needle == 'string' || typeof needle == 'number') {
  492. for(var i in haystack) {
  493. if(haystack[i] == needle) {
  494. return true;
  495. }
  496. }
  497. }
  498. return false;
  499. }
  500. function strlen(str) {
  501. return (BROWSER.ie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
  502. }
  503. function Ajax(recvType, waitId) {
  504. var aj = new Object();
  505. aj.loading = '请稍候...';
  506. aj.recvType = recvType ? recvType : 'XML';
  507. aj.waitId = waitId ? $$(waitId) : null;
  508. aj.resultHandle = null;
  509. aj.sendString = '';
  510. aj.targetUrl = '';
  511. aj.setLoading = function(loading) {
  512. if(typeof loading !== 'undefined' && loading !== null) aj.loading = loading;
  513. };
  514. aj.setRecvType = function(recvtype) {
  515. aj.recvType = recvtype;
  516. };
  517. aj.setWaitId = function(waitid) {
  518. aj.waitId = typeof waitid == 'object' ? waitid : $$(waitid);
  519. };
  520. aj.createXMLHttpRequest = function() {
  521. var request = false;
  522. if(window.XMLHttpRequest) {
  523. request = new XMLHttpRequest();
  524. if(request.overrideMimeType) {
  525. request.overrideMimeType('text/xml');
  526. }
  527. } else if(window.ActiveXObject) {
  528. var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
  529. for(var i=0; i<versions.length; i++) {
  530. try {
  531. request = new ActiveXObject(versions[i]);
  532. if(request) {
  533. return request;
  534. }
  535. } catch(e) {}
  536. }
  537. }
  538. return request;
  539. };
  540. aj.XMLHttpRequest = aj.createXMLHttpRequest();
  541. aj.showLoading = function() {
  542. if(aj.waitId && (aj.XMLHttpRequest.readyState != 4 || aj.XMLHttpRequest.status != 200)) {
  543. aj.waitId.style.display = '';
  544. aj.waitId.innerHTML = '<span><img src="' + DIALOGIMGDIR + '/loading.gif" class="vm"> ' + aj.loading + '</span>';
  545. }
  546. };
  547. aj.processHandle = function() {
  548. if(aj.XMLHttpRequest.readyState == 4 && aj.XMLHttpRequest.status == 200) {
  549. if(aj.waitId) {
  550. aj.waitId.style.display = 'none';
  551. }
  552. if(aj.recvType == 'HTML') {
  553. aj.resultHandle(aj.XMLHttpRequest.responseText, aj);
  554. } else if(aj.recvType == 'XML') {
  555. if(!aj.XMLHttpRequest.responseXML || !aj.XMLHttpRequest.responseXML.lastChild || aj.XMLHttpRequest.responseXML.lastChild.localName == 'parsererror') {
  556. aj.resultHandle('<a href="' + aj.targetUrl + '" target="_blank" style="color:red">内部错误,无法显示此内容</a>' , aj);
  557. } else {
  558. aj.resultHandle(aj.XMLHttpRequest.responseXML.lastChild.firstChild.nodeValue, aj);
  559. }
  560. }
  561. }
  562. };
  563. aj.get = function(targetUrl, resultHandle) {
  564. targetUrl = hostconvert(targetUrl);
  565. setTimeout(function(){aj.showLoading()}, 250);
  566. aj.targetUrl = targetUrl;
  567. aj.XMLHttpRequest.onreadystatechange = aj.processHandle;
  568. aj.resultHandle = resultHandle;
  569. var attackevasive = isUndefined(attackevasive) ? 0 : attackevasive;
  570. if(window.XMLHttpRequest) {
  571. aj.XMLHttpRequest.open('GET', aj.targetUrl);
  572. aj.XMLHttpRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  573. aj.XMLHttpRequest.send(null);
  574. } else {
  575. aj.XMLHttpRequest.open("GET", targetUrl, true);
  576. aj.XMLHttpRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  577. aj.XMLHttpRequest.send();
  578. }
  579. };
  580. aj.post = function(targetUrl, sendString, resultHandle) {
  581. targetUrl = hostconvert(targetUrl);
  582. setTimeout(function(){aj.showLoading()}, 250);
  583. aj.targetUrl = targetUrl;
  584. aj.sendString = sendString;
  585. aj.XMLHttpRequest.onreadystatechange = aj.processHandle;
  586. aj.resultHandle = resultHandle;
  587. aj.XMLHttpRequest.open('POST', targetUrl);
  588. aj.XMLHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  589. aj.XMLHttpRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  590. aj.XMLHttpRequest.send(aj.sendString);
  591. };
  592. return aj;
  593. }
  594. function getHost(url) {
  595. var host = "null";
  596. if(typeof url == "undefined"|| null == url) {
  597. url = window.location.href;
  598. }
  599. var regex = /^\w+\:\/\/([^\/]*).*/;
  600. var match = url.match(regex);
  601. if(typeof match != "undefined" && null != match) {
  602. host = match[1];
  603. }
  604. return host;
  605. }
  606. function hostconvert(url)
  607. {
  608. if(!url.match(/^http[s]?:\/\//)) {
  609. url = SITEURL.replace(/(\/+)$/g, '') + '/' + url;
  610. }
  611. var url_host = getHost(url);
  612. var cur_host = getHost().toLowerCase();
  613. if(url_host && cur_host != url_host) {
  614. url = url.replace(url_host, cur_host);
  615. }
  616. return url;
  617. }
  618. function newfunction(func) {
  619. var args = [];
  620. for(var i=1; i<arguments.length; i++) args.push(arguments[i]);
  621. return function(event) {
  622. doane(event);
  623. window[func].apply(window, args);
  624. return false;
  625. }
  626. }
  627. function evalscript(s) {
  628. if(s.indexOf('<script') == -1) return s;
  629. var p = /<script[^\>]*?>([^\x00]*?)<\/script>/ig;
  630. var arr = [];
  631. while(arr = p.exec(s)) {
  632. var p1 = /<script[^\>]*?src=\"([^\>]*?)\"[^\>]*?(reload=\"1\")?(?:charset=\"([\w\-]+?)\")?><\/script>/i;
  633. var arr1 = [];
  634. arr1 = p1.exec(arr[0]);
  635. if(arr1) {
  636. appendscript(arr1[1], '', arr1[2], arr1[3]);
  637. } else {
  638. p1 = /<script(.*?)>([^\x00]+?)<\/script>/i;
  639. arr1 = p1.exec(arr[0]);
  640. appendscript('', arr1[2], arr1[1].indexOf('reload=') != -1);
  641. }
  642. }
  643. return s;
  644. }
  645. var evalscripts = [];
  646. function appendscript(src, text, reload, charset) {
  647. var id = hash(src + text);
  648. if(!reload && in_array(id, evalscripts)) return;
  649. if(reload && $$(id)) {
  650. $$(id).parentNode.removeChild($$(id));
  651. }
  652. evalscripts.push(id);
  653. var scriptNode = document.createElement("script");
  654. scriptNode.type = "text/javascript";
  655. scriptNode.id = id;
  656. scriptNode.charset = charset ? charset : (BROWSER.firefox ? document.characterSet : document.charset);
  657. try {
  658. if(src) {
  659. scriptNode.src = src;
  660. scriptNode.onloadDone = false;
  661. scriptNode.onload = function () {
  662. scriptNode.onloadDone = true;
  663. JSLOADED[src] = 1;
  664. };
  665. scriptNode.onreadystatechange = function () {
  666. if((scriptNode.readyState == 'loaded' || scriptNode.readyState == 'complete') && !scriptNode.onloadDone) {
  667. scriptNode.onloadDone = true;
  668. JSLOADED[src] = 1;
  669. }
  670. };
  671. } else if(text){
  672. scriptNode.text = text;
  673. }
  674. document.getElementsByTagName('head')[0].appendChild(scriptNode);
  675. } catch(e) {}
  676. }
  677. function ajaxupdateevents(obj, tagName) {
  678. tagName = tagName ? tagName : 'A';
  679. var objs = obj.getElementsByTagName(tagName);
  680. for(k in objs) {
  681. var o = objs[k];
  682. ajaxupdateevent(o);
  683. }
  684. }
  685. function ajaxupdateevent(o) {
  686. if(typeof o == 'object' && o.getAttribute) {
  687. if(o.getAttribute('ajaxtarget')) {
  688. if(!o.id) o.id = Math.random();
  689. var ajaxevent = o.getAttribute('ajaxevent') ? o.getAttribute('ajaxevent') : 'click';
  690. var ajaxurl = o.getAttribute('ajaxurl') ? o.getAttribute('ajaxurl') : o.href;
  691. _attachEvent(o, ajaxevent, newfunction('ajaxget', ajaxurl, o.getAttribute('ajaxtarget'), o.getAttribute('ajaxwaitid'), o.getAttribute('ajaxloading'), o.getAttribute('ajaxdisplay')));
  692. if(o.getAttribute('ajaxfunc')) {
  693. o.getAttribute('ajaxfunc').match(/(\w+)\((.+?)\)/);
  694. _attachEvent(o, ajaxevent, newfunction(RegExp.$1, RegExp.$2));
  695. }
  696. }
  697. }
  698. }
  699. function ajaxget(url, showid, waitid, loading, display, recall) {
  700. waitid = typeof waitid == 'undefined' || waitid === null ? showid : waitid;
  701. var x = new Ajax();
  702. x.setLoading(loading);
  703. x.setWaitId(waitid);
  704. x.display = typeof display == 'undefined' || display == null ? '' : display;
  705. x.showId = $$(showid);
  706. if(url.substr(strlen(url) - 1) == '#') {
  707. url = url.substr(0, strlen(url) - 1);
  708. x.autogoto = 1;
  709. }
  710. // var url = url + '&inajax=1&ajaxtarget=' + showid;
  711. var url = url + '&inajax=1&ajaxtarget=';
  712. x.get(url, function(s, x) {
  713. var evaled = false;
  714. if(s.indexOf('ajaxerror') != -1) {
  715. evalscript(s);
  716. evaled = true;
  717. }
  718. if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
  719. if(x.showId) {
  720. x.showId.style.display = x.display;
  721. ajaxinnerhtml(x.showId, s);
  722. ajaxupdateevents(x.showId);
  723. if(x.autogoto) scroll(0, x.showId.offsetTop);
  724. }
  725. }
  726. ajaxerror = null;
  727. if(recall && typeof recall == 'function') {
  728. recall();
  729. } else if(recall) {
  730. eval(recall);
  731. }
  732. if(!evaled) evalscript(s);
  733. });
  734. }
  735. function ajaxpost(formid, showid, waitid, showidclass, submitbtn, recall) {
  736. var waitid = typeof waitid == 'undefined' || waitid === null ? showid : (waitid !== '' ? waitid : '');
  737. var showidclass = '';
  738. var ajaxframeid = 'ajaxframe';
  739. var ajaxframe = $$(ajaxframeid);
  740. var formtarget = $$(formid).target;
  741. var handleResult = function()
  742. {
  743. var s = '';
  744. var evaled = false;
  745. try {
  746. s = $$(ajaxframeid).contentWindow.document.XMLDocument.text;
  747. } catch(e) {
  748. try {
  749. s = $$(ajaxframeid).contentWindow.document.documentElement.firstChild.wholeText;
  750. } catch(e) {
  751. try {
  752. s = $$(ajaxframeid).contentWindow.document.documentElement.firstChild.nodeValue;
  753. } catch(e) {
  754. s = '内部错误,无法显示此内容';
  755. }
  756. }
  757. }
  758. if( s != '' && s.indexOf('ajaxerror') != -1) {
  759. evalscript(s);
  760. evaled = true;
  761. }
  762. if(showidclass) {
  763. if(showidclass != 'onerror') {
  764. $$(showid).className = showidclass;
  765. } else {
  766. showError(s);
  767. ajaxerror = true;
  768. }
  769. }
  770. if(submitbtn) {
  771. submitbtn.disabled = false;
  772. }
  773. if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
  774. //ajaxinnerhtml($$(showid), s);
  775. }
  776. ajaxerror = null;
  777. if($$(formid)) $$(formid).target = formtarget;
  778. if(typeof recall == 'function') {
  779. recall();
  780. } else {
  781. eval(recall);
  782. }
  783. if(!evaled) evalscript(s);
  784. ajaxframe.loading = 0;
  785. $$('append_parent').removeChild(ajaxframe.parentNode);
  786. };
  787. if(!ajaxframe) {
  788. var div = document.createElement('div');
  789. div.style.display = 'none';
  790. div.innerHTML = '<iframe name="' + ajaxframeid + '" id="' + ajaxframeid + '" loading="1"></iframe>';
  791. $$('append_parent').appendChild(div);
  792. ajaxframe = $$(ajaxframeid);
  793. } else if(ajaxframe.loading) {
  794. return false;
  795. }
  796. _attachEvent(ajaxframe, 'load', handleResult);
  797. //showloading();
  798. $$(formid).target = ajaxframeid;
  799. var action = $$(formid).getAttribute('action');
  800. console.log('action=' + action);
  801. action = hostconvert(action);
  802. console.log('action=' + action);
  803. $$(formid).action = action.replace(/\&inajax\=1/g, '')+'&inajax=1';
  804. $$(formid).submit();
  805. if(submitbtn) {
  806. submitbtn.disabled = true;
  807. }
  808. doane();
  809. return false;
  810. }
  811. function hash(string, length) {
  812. var length = length ? length : 32;
  813. var start = 0;
  814. var i = 0;
  815. var result = '';
  816. filllen = length - string.length % length;
  817. for(i = 0; i < filllen; i++){
  818. string += "0";
  819. }
  820. while(start < string.length) {
  821. result = stringxor(result, string.substr(start, length));
  822. start += length;
  823. }
  824. return result;
  825. }
  826. function stringxor(s1, s2) {
  827. var s = '';
  828. var hash = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  829. var max = Math.max(s1.length, s2.length);
  830. for(var i=0; i<max; i++) {
  831. var k = s1.charCodeAt(i) ^ s2.charCodeAt(i);
  832. s += hash.charAt(k % 52);
  833. }
  834. return s;
  835. }
  836. function showloading(display, waiting) {
  837. var display = display ? display : 'block';
  838. var waiting = waiting ? waiting : '请稍候...';
  839. $$('ajaxwaitid').innerHTML = waiting;
  840. $$('ajaxwaitid').style.display = display;
  841. }
  842. function ajaxinnerhtml(showid, s) {
  843. if(showid.tagName != 'TBODY') {
  844. showid.innerHTML = s;
  845. } else {
  846. while(showid.firstChild) {
  847. showid.firstChild.parentNode.removeChild(showid.firstChild);
  848. }
  849. var div1 = document.createElement('DIV');
  850. div1.id = showid.id+'_div';
  851. div1.innerHTML = '<table><tbody id="'+showid.id+'_tbody">'+s+'</tbody></table>';
  852. $$('append_parent').appendChild(div1);
  853. var trs = div1.getElementsByTagName('TR');
  854. var l = trs.length;
  855. for(var i=0; i<l; i++) {
  856. showid.appendChild(trs[0]);
  857. }
  858. var inputs = div1.getElementsByTagName('INPUT');
  859. var l = inputs.length;
  860. for(var i=0; i<l; i++) {
  861. showid.appendChild(inputs[0]);
  862. }
  863. div1.parentNode.removeChild(div1);
  864. }
  865. }
  866. function doane(event, preventDefault, stopPropagation) {
  867. var preventDefault = isUndefined(preventDefault) ? 1 : preventDefault;
  868. var stopPropagation = isUndefined(stopPropagation) ? 1 : stopPropagation;
  869. e = event ? event : window.event;
  870. if(!e) {
  871. e = getEvent();
  872. }
  873. if(!e) {
  874. return null;
  875. }
  876. if(preventDefault) {
  877. if(e.preventDefault) {
  878. e.preventDefault();
  879. } else {
  880. e.returnValue = false;
  881. }
  882. }
  883. if(stopPropagation) {
  884. if(e.stopPropagation) {
  885. e.stopPropagation();
  886. } else {
  887. e.cancelBubble = true;
  888. }
  889. }
  890. return e;
  891. }
  892. function showMenu(v) {
  893. var ctrlid = isUndefined(v['ctrlid']) ? v : v['ctrlid'];
  894. var showid = isUndefined(v['showid']) ? ctrlid : v['showid'];
  895. var menuid = isUndefined(v['menuid']) ? showid + '_menu' : v['menuid'];
  896. var ctrlObj = $$(ctrlid);
  897. var menuObj = $$(menuid);
  898. if(!menuObj) return;
  899. var mtype = isUndefined(v['mtype']) ? 'menu' : v['mtype'];
  900. var evt = isUndefined(v['evt']) ? 'mouseover' : v['evt'];
  901. var pos = isUndefined(v['pos']) ? '43' : v['pos'];
  902. var layer = isUndefined(v['layer']) ? 1 : v['layer'];
  903. var duration = isUndefined(v['duration']) ? 2 : v['duration'];
  904. var timeout = isUndefined(v['timeout']) ? 250 : v['timeout'];
  905. var maxh = isUndefined(v['maxh']) ? 600 : v['maxh'];
  906. var cache = isUndefined(v['cache']) ? 1 : v['cache'];
  907. var drag = isUndefined(v['drag']) ? '' : v['drag'];
  908. var dragobj = drag && $$(drag) ? $$(drag) : menuObj;
  909. var fade = isUndefined(v['fade']) ? 0 : v['fade'];
  910. var cover = isUndefined(v['cover']) ? 0 : v['cover'];
  911. var zindex = isUndefined(v['zindex']) ? JSMENU['zIndex']['menu'] : v['zindex'];
  912. var ctrlclass = isUndefined(v['ctrlclass']) ? '' : v['ctrlclass'];
  913. var winhandlekey = isUndefined(v['win']) ? '' : v['win'];
  914. zindex = cover ? zindex + 500 : zindex;
  915. if(typeof JSMENU['active'][layer] == 'undefined') {
  916. JSMENU['active'][layer] = [];
  917. }
  918. for(i in EXTRAFUNC['showmenu']) {
  919. try {
  920. eval(EXTRAFUNC['showmenu'][i] + '()');
  921. } catch(e) {}
  922. }
  923. if(evt == 'click' && in_array(menuid, JSMENU['active'][layer]) && mtype != 'win') {
  924. hideMenu(menuid, mtype);
  925. return;
  926. }
  927. if(mtype == 'menu') {
  928. hideMenu(layer, mtype);
  929. }
  930. if(ctrlObj) {
  931. if(!ctrlObj.getAttribute('initialized')) {
  932. ctrlObj.setAttribute('initialized', true);
  933. ctrlObj.unselectable = true;
  934. ctrlObj.outfunc = typeof ctrlObj.onmouseout == 'function' ? ctrlObj.onmouseout : null;
  935. ctrlObj.onmouseout = function() {
  936. if(this.outfunc) this.outfunc();
  937. if(duration < 3 && !JSMENU['timer'][menuid]) {
  938. JSMENU['timer'][menuid] = setTimeout(function () {
  939. hideMenu(menuid, mtype);
  940. }, timeout);
  941. }
  942. };
  943. ctrlObj.overfunc = typeof ctrlObj.onmouseover == 'function' ? ctrlObj.onmouseover : null;
  944. ctrlObj.onmouseover = function(e) {
  945. doane(e);
  946. if(this.overfunc) this.overfunc();
  947. if(evt == 'click') {
  948. clearTimeout(JSMENU['timer'][menuid]);
  949. JSMENU['timer'][menuid] = null;
  950. } else {
  951. for(var i in JSMENU['timer']) {
  952. if(JSMENU['timer'][i]) {
  953. clearTimeout(JSMENU['timer'][i]);
  954. JSMENU['timer'][i] = null;
  955. }
  956. }
  957. }
  958. };
  959. }
  960. }
  961. if(!menuObj.getAttribute('initialized')) {
  962. menuObj.setAttribute('initialized', true);
  963. menuObj.ctrlkey = ctrlid;
  964. menuObj.mtype = mtype;
  965. menuObj.layer = layer;
  966. menuObj.cover = cover;
  967. if(ctrlObj && ctrlObj.getAttribute('fwin')) {menuObj.scrolly = true;}
  968. menuObj.style.position = 'absolute';
  969. menuObj.style.zIndex = zindex + layer;
  970. menuObj.onclick = function(e) {
  971. return doane(e, 0, 1);
  972. };
  973. if(duration < 3) {
  974. if(duration > 1) {
  975. menuObj.onmouseover = function() {
  976. clearTimeout(JSMENU['timer'][menuid]);
  977. JSMENU['timer'][menuid] = null;
  978. };
  979. }
  980. if(duration != 1) {
  981. menuObj.onmouseout = function() {
  982. JSMENU['timer'][menuid] = setTimeout(function () {
  983. hideMenu(menuid, mtype);
  984. }, timeout);
  985. };
  986. }
  987. }
  988. if(cover) {
  989. var coverObj = document.createElement('div');
  990. coverObj.id = menuid + '_cover';
  991. coverObj.style.position = 'absolute';
  992. coverObj.style.zIndex = menuObj.style.zIndex - 1;
  993. coverObj.style.left = coverObj.style.top = '0px';
  994. coverObj.style.width = '100%';
  995. coverObj.style.height = Math.max(document.documentElement.clientHeight, document.body.offsetHeight) + 'px';
  996. coverObj.style.backgroundColor = 'transparent';
  997. coverObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
  998. coverObj.style.opacity = 0;
  999. coverObj.onclick = function () { hideMenu(); };
  1000. $$('append_parent').appendChild(coverObj);
  1001. _attachEvent(window, 'load', function () {
  1002. coverObj.style.height = Math.max(document.documentElement.clientHeight, document.body.offsetHeight) + 'px';
  1003. }, document);
  1004. }
  1005. }
  1006. if(drag) {
  1007. dragobj.style.cursor = 'move';
  1008. dragobj.onmousedown = function(event) {try{dragMenu(menuObj, event, 1);}catch(e){}};
  1009. }
  1010. if(cover) $$(menuid + '_cover').style.display = '';
  1011. if(fade) {
  1012. var O = 0;
  1013. var fadeIn = function(O) {
  1014. if(O > 100) {
  1015. clearTimeout(fadeInTimer);
  1016. return;
  1017. }
  1018. menuObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + O + ')';
  1019. menuObj.style.opacity = O / 100;
  1020. O += 20;
  1021. var fadeInTimer = setTimeout(function () {
  1022. fadeIn(O);
  1023. }, 40);
  1024. };
  1025. fadeIn(O);
  1026. menuObj.fade = true;
  1027. } else {
  1028. menuObj.fade = false;
  1029. }
  1030. menuObj.style.display = '';
  1031. if(ctrlObj && ctrlclass) {
  1032. ctrlObj.className += ' ' + ctrlclass;
  1033. menuObj.setAttribute('ctrlid', ctrlid);
  1034. menuObj.setAttribute('ctrlclass', ctrlclass);
  1035. }
  1036. if(pos != '*') {
  1037. setMenuPosition(showid, menuid, pos);
  1038. }
  1039. if(BROWSER.ie && BROWSER.ie < 7 && winhandlekey && $$('fwin_' + winhandlekey)) {
  1040. $$(menuid).style.left = (parseInt($$(menuid).style.left) - parseInt($$('fwin_' + winhandlekey).style.left)) + 'px';
  1041. $$(menuid).style.top = (parseInt($$(menuid).style.top) - parseInt($$('fwin_' + winhandlekey).style.top)) + 'px';
  1042. }
  1043. if(maxh && menuObj.scrollHeight > maxh) {
  1044. menuObj.style.height = maxh + 'px';
  1045. if(BROWSER.opera) {
  1046. menuObj.style.overflow = 'auto';
  1047. } else {
  1048. menuObj.style.overflowY = 'auto';
  1049. }
  1050. }
  1051. if(!duration) {
  1052. setTimeout('hideMenu(\'' + menuid + '\', \'' + mtype + '\')', timeout);
  1053. }
  1054. if(!in_array(menuid, JSMENU['active'][layer])) JSMENU['active'][layer].push(menuid);
  1055. menuObj.cache = cache;
  1056. if(layer > JSMENU['layer']) {
  1057. JSMENU['layer'] = layer;
  1058. }
  1059. }
  1060. var dragMenuDisabled = false;
  1061. function dragMenu(menuObj, e, op) {
  1062. e = e ? e : window.event;
  1063. if(op == 1) {
  1064. if(dragMenuDisabled || in_array(e.target ? e.target.tagName : e.srcElement.tagName, ['TEXTAREA', 'INPUT', 'BUTTON', 'SELECT'])) {
  1065. return;
  1066. }
  1067. JSMENU['drag'] = [e.clientX, e.clientY];
  1068. JSMENU['drag'][2] = parseInt(menuObj.style.left);
  1069. JSMENU['drag'][3] = parseInt(menuObj.style.top);
  1070. document.onmousemove = function(e) {try{dragMenu(menuObj, e, 2);}catch(err){}};
  1071. document.onmouseup = function(e) {try{dragMenu(menuObj, e, 3);}catch(err){}};
  1072. doane(e);
  1073. }else if(op == 2 && JSMENU['drag'][0]) {
  1074. var menudragnow = [e.clientX, e.clientY];
  1075. menuObj.style.left = (JSMENU['drag'][2] + menudragnow[0] - JSMENU['drag'][0]) + 'px';
  1076. menuObj.style.top = (JSMENU['drag'][3] + menudragnow[1] - JSMENU['drag'][1]) + 'px';
  1077. menuObj.removeAttribute('top_');menuObj.removeAttribute('left_');
  1078. doane(e);
  1079. }else if(op == 3) {
  1080. JSMENU['drag'] = [];
  1081. document.onmousemove = null;
  1082. document.onmouseup = null;
  1083. }
  1084. }
  1085. function setMenuPosition(showid, menuid, pos) {
  1086. var showObj = $$(showid);
  1087. var menuObj = menuid ? $$(menuid) : $$(showid + '_menu');
  1088. if(isUndefined(pos) || !pos) pos = '43';
  1089. var basePoint = parseInt(pos.substr(0, 1));
  1090. var direction = parseInt(pos.substr(1, 1));
  1091. var important = pos.indexOf('!') != -1 ? 1 : 0;
  1092. var sxy = 0, sx = 0, sy = 0, sw = 0, sh = 0, ml = 0, mt = 0, mw = 0, mcw = 0, mh = 0, mch = 0, bpl = 0, bpt = 0;
  1093. if(!menuObj || (basePoint > 0 && !showObj)) return;
  1094. if(showObj) {
  1095. sxy = fetchOffset(showObj);
  1096. sx = sxy['left'];
  1097. sy = sxy['top'];
  1098. sw = showObj.offsetWidth;
  1099. sh = showObj.offsetHeight;
  1100. }
  1101. mw = menuObj.offsetWidth;
  1102. mcw = menuObj.clientWidth;
  1103. mh = menuObj.offsetHeight;
  1104. mch = menuObj.clientHeight;
  1105. switch(basePoint) {
  1106. case 1:
  1107. bpl = sx;
  1108. bpt = sy;
  1109. break;
  1110. case 2:
  1111. bpl = sx + sw;
  1112. bpt = sy;
  1113. break;
  1114. case 3:
  1115. bpl = sx + sw;
  1116. bpt = sy + sh;
  1117. break;
  1118. case 4:
  1119. bpl = sx;
  1120. bpt = sy + sh;
  1121. break;
  1122. }
  1123. switch(direction) {
  1124. case 0:
  1125. menuObj.style.left = (document.body.clientWidth - menuObj.clientWidth) / 2 + 'px';
  1126. mt = (document.documentElement.clientHeight - menuObj.clientHeight) / 2;
  1127. break;
  1128. case 1:
  1129. ml = bpl - mw;
  1130. mt = bpt - mh;
  1131. break;
  1132. case 2:
  1133. ml = bpl;
  1134. mt = bpt - mh;
  1135. break;
  1136. case 3:
  1137. ml = bpl;
  1138. mt = bpt;
  1139. break;
  1140. case 4:
  1141. ml = bpl - mw;
  1142. mt = bpt;
  1143. break;
  1144. }
  1145. var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  1146. var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
  1147. if(!important) {
  1148. if(in_array(direction, [1, 4]) && ml < 0) {
  1149. ml = bpl;
  1150. if(in_array(basePoint, [1, 4])) ml += sw;
  1151. } else if(ml + mw > scrollLeft + document.body.clientWidth && sx >= mw) {
  1152. ml = bpl - mw;
  1153. if(in_array(basePoint, [2, 3])) {
  1154. ml -= sw;
  1155. } else if(basePoint == 4) {
  1156. ml += sw;
  1157. }
  1158. }
  1159. if(in_array(direction, [1, 2]) && mt < 0) {
  1160. mt = bpt;
  1161. if(in_array(basePoint, [1, 2])) mt += sh;
  1162. } else if(mt + mh > scrollTop + document.documentElement.clientHeight && sy >= mh) {
  1163. mt = bpt - mh;
  1164. if(in_array(basePoint, [3, 4])) mt -= sh;
  1165. }
  1166. }
  1167. if(pos.substr(0, 3) == '210') {
  1168. ml += 69 - sw / 2;
  1169. mt -= 5;
  1170. if(showObj.tagName == 'TEXTAREA') {
  1171. ml -= sw / 2;
  1172. mt += sh / 2;
  1173. }
  1174. }
  1175. if(direction == 0 || menuObj.scrolly) {
  1176. if(BROWSER.ie && BROWSER.ie < 7) {
  1177. if(direction == 0) mt += scrollTop;
  1178. } else {
  1179. if(menuObj.scrolly) mt -= scrollTop;
  1180. menuObj.style.position = 'fixed';
  1181. }
  1182. }
  1183. if(ml) menuObj.style.left = ml + 'px';
  1184. if(mt) menuObj.style.top = mt + 'px';
  1185. if(direction == 0 && BROWSER.ie && !document.documentElement.clientHeight) {
  1186. menuObj.style.position = 'absolute';
  1187. menuObj.style.top = (document.body.clientHeight - menuObj.clientHeight) / 2 + 'px';
  1188. }
  1189. if(menuObj.style.clip && !BROWSER.opera) {
  1190. menuObj.style.clip = 'rect(auto, auto, auto, auto)';
  1191. }
  1192. }
  1193. function hideMenu(attr, mtype) {
  1194. attr = isUndefined(attr) ? '' : attr;
  1195. mtype = isUndefined(mtype) ? 'menu' : mtype;
  1196. if(attr == '') {
  1197. for(var i = 1; i <= JSMENU['layer']; i++) {
  1198. hideMenu(i, mtype);
  1199. }
  1200. return;
  1201. } else if(typeof attr == 'number') {
  1202. for(var j in JSMENU['active'][attr]) {
  1203. hideMenu(JSMENU['active'][attr][j], mtype);
  1204. }
  1205. return;
  1206. }else if(typeof attr == 'string') {
  1207. var menuObj = $$(attr);
  1208. if(!menuObj || (mtype && menuObj.mtype != mtype)) return;
  1209. var ctrlObj = '', ctrlclass = '';
  1210. if((ctrlObj = $$(menuObj.getAttribute('ctrlid'))) && (ctrlclass = menuObj.getAttribute('ctrlclass'))) {
  1211. var reg = new RegExp(' ' + ctrlclass);
  1212. ctrlObj.className = ctrlObj.className.replace(reg, '');
  1213. }
  1214. clearTimeout(JSMENU['timer'][attr]);
  1215. var hide = function() {
  1216. if(menuObj.cache) {
  1217. if(menuObj.style.visibility != 'hidden') {
  1218. menuObj.style.display = 'none';
  1219. if(menuObj.cover) $$(attr + '_cover').style.display = 'none';
  1220. }
  1221. }else {
  1222. menuObj.parentNode.removeChild(menuObj);
  1223. if(menuObj.cover) $$(attr + '_cover').parentNode.removeChild($$(attr + '_cover'));
  1224. }
  1225. var tmp = [];
  1226. for(var k in JSMENU['active'][menuObj.layer]) {
  1227. if(attr != JSMENU['active'][menuObj.layer][k]) tmp.push(JSMENU['active'][menuObj.layer][k]);
  1228. }
  1229. JSMENU['active'][menuObj.layer] = tmp;
  1230. };
  1231. if(menuObj.fade) {
  1232. var O = 100;
  1233. var fadeOut = function(O) {
  1234. if(O == 0) {
  1235. clearTimeout(fadeOutTimer);
  1236. hide();
  1237. return;
  1238. }
  1239. menuObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + O + ')';
  1240. menuObj.style.opacity = O / 100;
  1241. O -= 20;
  1242. var fadeOutTimer = setTimeout(function () {
  1243. fadeOut(O);
  1244. }, 40);
  1245. };
  1246. fadeOut(O);
  1247. } else {
  1248. hide();
  1249. }
  1250. }
  1251. }
  1252. function getCurrentStyle(obj, cssproperty, csspropertyNS) {
  1253. if(obj.style[cssproperty]){
  1254. return obj.style[cssproperty];
  1255. }
  1256. if (obj.currentStyle) {
  1257. return obj.currentStyle[cssproperty];
  1258. } else if (document.defaultView.getComputedStyle(obj, null)) {
  1259. var currentStyle = document.defaultView.getComputedStyle(obj, null);
  1260. var value = currentStyle.getPropertyValue(csspropertyNS);
  1261. if(!value){
  1262. value = currentStyle[cssproperty];
  1263. }
  1264. return value;
  1265. } else if (window.getComputedStyle) {
  1266. var currentStyle = window.getComputedStyle(obj, "");
  1267. return currentStyle.getPropertyValue(csspropertyNS);
  1268. }
  1269. }
  1270. function fetchOffset(obj, mode) {
  1271. var left_offset = 0, top_offset = 0, mode = !mode ? 0 : mode;
  1272. if(obj.getBoundingClientRect && !mode) {
  1273. var rect = obj.getBoundingClientRect();
  1274. var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  1275. var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
  1276. if(document.documentElement.dir == 'rtl') {
  1277. scrollLeft = scrollLeft + document.documentElement.clientWidth - document.documentElement.scrollWidth;
  1278. }
  1279. left_offset = rect.left + scrollLeft - document.documentElement.clientLeft;
  1280. top_offset = rect.top + scrollTop - document.documentElement.clientTop;
  1281. }
  1282. if(left_offset <= 0 || top_offset <= 0) {
  1283. left_offset = obj.offsetLeft;
  1284. top_offset = obj.offsetTop;
  1285. while((obj = obj.offsetParent) != null) {
  1286. position = getCurrentStyle(obj, 'position', 'position');
  1287. if(position == 'relative') {
  1288. continue;
  1289. }
  1290. left_offset += obj.offsetLeft;
  1291. top_offset += obj.offsetTop;
  1292. }
  1293. }
  1294. return {'left' : left_offset, 'top' : top_offset};
  1295. }
  1296. var showDialogST = null;
  1297. function showDialog(msg, mode, t, func, cover, funccancel, leftmsg, confirmtxt, canceltxt, closetime, locationtime) {
  1298. if (mode == 'js'){
  1299. if(typeof func == 'function') func();
  1300. else eval(func);
  1301. //hideMenu(null, 'dialog');
  1302. return ;
  1303. }
  1304. clearTimeout(showDialogST);
  1305. cover = isUndefined(cover) ? (mode == 'info' ? 0 : 1) : cover;
  1306. leftmsg = isUndefined(leftmsg) ? '' : leftmsg;
  1307. mode = in_array(mode, ['confirm', 'notice', 'info', 'succ','js']) ? mode : 'alert';
  1308. var menuid = 'fwin_dialog';
  1309. var menuObj = $$(menuid);
  1310. var showconfirm = 1;
  1311. confirmtxtdefault = '确定';
  1312. closetime = isUndefined(closetime) ? '' : closetime;
  1313. closefunc = function () {
  1314. if(typeof func == 'function') func();
  1315. else eval(func);
  1316. hideMenu(menuid, 'dialog');
  1317. };
  1318. if(closetime) {
  1319. leftmsg = closetime + ' 秒后窗口关闭';
  1320. showDialogST = setTimeout(closefunc, closetime * 1000);
  1321. showconfirm = 0;
  1322. }
  1323. locationtime = isUndefined(locationtime) ? '' : locationtime;
  1324. if(locationtime) {
  1325. leftmsg = locationtime + ' 秒后页面跳转';
  1326. showDialogST = setTimeout(closefunc, locationtime * 1000);
  1327. showconfirm = 0;
  1328. }
  1329. confirmtxt = confirmtxt ? confirmtxt : confirmtxtdefault;
  1330. canceltxt = canceltxt ? canceltxt : '取消';
  1331. if(menuObj) hideMenu('fwin_dialog', 'dialog');
  1332. menuObj = document.createElement('div');
  1333. menuObj.style.display = 'none';
  1334. menuObj.className = 'dialog_body';
  1335. menuObj.id = menuid;
  1336. $$('append_parent').appendChild(menuObj);
  1337. var hidedom = '';
  1338. if(!BROWSER.ie) {
  1339. hidedom = '<style type="text/css">object{visibility:hidden;}</style>';
  1340. }
  1341. var s = hidedom + '<h3 class="dialog_head"><span class="dialog_title">';
  1342. s += t ? t : '<span class="dialog_title_icon">提示信息</span>';
  1343. s += '</span><span class="dialog_close_button" id="fwin_dialog_close" onclick="hideMenu(\'' + menuid + '\', \'dialog\')" title="关闭">X</span></h3>';
  1344. if(mode == 'info') {
  1345. s += msg ? msg : '';
  1346. } else {
  1347. s += '<div class="eject_con"><div class="dialog_message_contents">';
  1348. s += '<i class="' + (mode == 'alert' ? 'alert_error' : (mode == 'succ' ? 'alert_right' : 'alert_info')) + '"></i>' + msg + '</div></div>';
  1349. s += '<div class="dialog_buttons_bar">' + (leftmsg ? '<time class="countdown">'+'<i class="icon-time"></i>' + leftmsg + '</time>' : '') + (showconfirm ? '<a href="javascript:void(0)" id="fwin_dialog_submit" class="dialog-bottom-btn dialog-bottom-btn mr10">'+confirmtxt+'</a>' : '');
  1350. s += mode == 'confirm' ? '<a href="javascript:void(0)" id="fwin_dialog_cancel" class="dialog-bottom-btn" onclick="hideMenu(\'' + menuid + '\', \'dialog\')">'+canceltxt+'</a>' : '';
  1351. s += '</div>';
  1352. }
  1353. menuObj.innerHTML = s;
  1354. if($$('fwin_dialog_submit')) $$('fwin_dialog_submit').onclick = function() {
  1355. if(typeof func == 'function') func();
  1356. else eval(func);
  1357. hideMenu(menuid, 'dialog');
  1358. };
  1359. if($$('fwin_dialog_cancel')) {
  1360. $$('fwin_dialog_cancel').onclick = function() {
  1361. if(typeof funccancel == 'function') funccancel();
  1362. else eval(funccancel);
  1363. hideMenu(menuid, 'dialog');
  1364. };
  1365. $$('fwin_dialog_close').onclick = $$('fwin_dialog_cancel').onclick;
  1366. }
  1367. showMenu({'mtype':'dialog','menuid':menuid,'duration':3,'pos':'00','zindex':JSMENU['zIndex']['dialog'],'cache':0,'cover':cover});
  1368. try {
  1369. if($$('fwin_dialog_submit')) $$('fwin_dialog_submit').focus();
  1370. } catch(e) {}
  1371. }
  1372. function showSucc(msg) {
  1373. var p = /<script[^\>]*?>([^\x00]*?)<\/script>/ig;
  1374. msg = msg.replace(p, '');
  1375. if(msg !== '') {
  1376. showDialog(msg, 'succ', '提示信息', null, true, null, '', '', '', 3);
  1377. }
  1378. }
  1379. function showError(msg) {
  1380. var p = /<script[^\>]*?>([^\x00]*?)<\/script>/ig;
  1381. msg = msg.replace(p, '');
  1382. if(msg !== '') {
  1383. showDialog(msg, 'alert', '错误信息', null, true, null, '', '', '', 3);
  1384. }
  1385. }
  1386. function hideWindow(k, all, clear) {
  1387. all = isUndefined(all) ? 1 : all;
  1388. clear = isUndefined(clear) ? 1 : clear;
  1389. hideMenu('fwin_' + k, 'win');
  1390. if(clear && $$('fwin_' + k)) {
  1391. $$('append_parent').removeChild($$('fwin_' + k));
  1392. }
  1393. if(all) {
  1394. hideMenu();
  1395. }
  1396. }
  1397. function ajax_get_confirm(msg, url){
  1398. if (msg != ''){
  1399. showDialog(msg, 'confirm', '', function(){ajaxget(url);});
  1400. }else{
  1401. ajaxget(url);
  1402. }
  1403. }
  1404. function get_confirm(msg, url){
  1405. if(msg != ''){
  1406. showDialog(msg, 'confirm', '', function(){ window.location = url;});
  1407. }else{
  1408. window.location = url;
  1409. }
  1410. }