dialog.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  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. /*支持拖拽*/
  155. $(this.dom.wrapper).draggable({
  156. 'handle': this.dom.head
  157. });
  158. /* 显示对话框 */
  159. $(this.dom.wrapper).show();
  160. },
  161. /* 关闭 */
  162. 'close' : function(lock){
  163. if (!this.onClose())
  164. {
  165. return false;
  166. }
  167. /* 关闭对话框 */
  168. $(this.dom.wrapper).remove();
  169. /* 解锁屏幕 */
  170. if (typeof lock == 'undefined'){
  171. ScreenLocker.unlock();
  172. }
  173. DialogManager.set(this.id,null);
  174. return true;
  175. },
  176. /* 对话框标题 */
  177. 'setTitle' : function(title){
  178. $(this.dom.title).html(title);
  179. },
  180. /* 改变对话框内容 */
  181. 'setContents' : function(type, options){
  182. contents = this.createContents(type, options);
  183. if (typeof(contents) == 'string')
  184. {
  185. $(this.dom.content).html(contents);
  186. }
  187. else
  188. {
  189. $(this.dom.content).empty();
  190. $(this.dom.content).append(contents);
  191. }
  192. },
  193. /* 设置对话框样式 */
  194. 'setStyle' : function(style){
  195. if (typeof(style) == 'object')
  196. {
  197. /* 否则为CSS */
  198. $(this.dom.wrapper).css(style);
  199. }
  200. else
  201. {
  202. /* 如果是字符串,则认为是样式名 */
  203. $(this.dom.wrapper).addClass(style);
  204. }
  205. },
  206. 'setWidth' : function(width){
  207. this.setStyle({'width' : width + 'px'});
  208. },
  209. 'setHeight' : function(height){
  210. this.setStyle({'height' : height + 'px'});
  211. },
  212. /* 生成对话框内容 */
  213. 'createContents' : function(type, options){
  214. var _html = '',
  215. self = this,
  216. status= 'complete';
  217. if (!options)
  218. {
  219. /* 如果只有一个参数,则认为其传递的是HTML字符串 */
  220. this.setStatus(status);
  221. return type;
  222. }
  223. switch(type){
  224. case 'ajax':
  225. /* 通过Ajax取得HTML,显示到页面上,此过程是异步的 */
  226. $.get(options, function(data){
  227. self.setContents(data);
  228. /* 使用上次定位重新定位窗口位置 */
  229. self.setPosition(self.lastPos);
  230. });
  231. /* 先提示正在加载 */
  232. _html = this.createContents('loading', {'text' : 'loading...'});
  233. break;
  234. case 'ajax_notice':
  235. /* 通过Ajax取得HTML,显示到页面上,此过程是异步的 */
  236. $.get(options, function(data) {
  237. var json = eval('(' + data + ')');
  238. 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>'
  239. self.setContents(MsgTxt);
  240. /* 使用上次定位重新定位窗口位置 */
  241. self.setPosition(self.lastPos);
  242. });
  243. /* 先提示正在加载 */
  244. _html = this.createContents('loading', { 'text': '正在处理...' });
  245. break;
  246. /* 以下是内置的几种对话框类型 */
  247. case 'loading':
  248. _html = '<div class="dialog_loading"><div class="dialog_loading_text">' + options.text + '</div></div>';
  249. status = 'loading';
  250. break;
  251. case 'message':
  252. var type = 'notice';
  253. if (options.type)
  254. {
  255. type = options.type;
  256. }
  257. _message_body = $('<div class="dialog_message_body"></div>');
  258. _message_contents = $('<div class="dialog_message_contents dialog_message_' + type + '">' + options.text + '</div>');
  259. _buttons_bar = $('<div class="dialog_buttons_bar"></div>');
  260. switch (type){
  261. case 'notice':
  262. case 'warning':
  263. var button_name = '确定';
  264. if (options.button_name)
  265. {
  266. button_name = options.button_name;
  267. }
  268. _ok_button = $('<input type="button" class="btn1" value="' + button_name + '" />');
  269. $(_ok_button).click(function(){
  270. if (options.onclick)
  271. {
  272. if(!options.onclick.call())
  273. {
  274. return;
  275. }
  276. }
  277. DialogManager.close(self.id);
  278. });
  279. $(_buttons_bar).append(_ok_button);
  280. break;
  281. case 'confirm':
  282. var yes_button_name = "确定";
  283. var no_button_name = "取消";
  284. if (options.yes_button_name)
  285. {
  286. yes_button_name = options.yes_button_name;
  287. }
  288. if (options.no_button_name)
  289. {
  290. no_button_name = options.no_button_name;
  291. }
  292. _yes_button = $('<input type="button" class="btn1" value="' + yes_button_name + '" />');
  293. _no_button = $('<input type="button" class="btn2" value="' + no_button_name + '" />');
  294. $(_yes_button).click(function(){
  295. if (options.onClickYes)
  296. {
  297. if (options.onClickYes.call() === false)
  298. {
  299. return;
  300. }
  301. }
  302. DialogManager.close(self.id);
  303. });
  304. $(_no_button).click(function(){
  305. if (options.onClickNo)
  306. {
  307. if (!options.onClickNo.call())
  308. {
  309. return;
  310. }
  311. }
  312. DialogManager.close(self.id);
  313. });
  314. $(_buttons_bar).append(_yes_button).append(_no_button);
  315. break;
  316. }
  317. _html = $(_message_body).append(_message_contents).append(_buttons_bar);
  318. break;
  319. }
  320. this.setStatus(status);
  321. return _html;
  322. },
  323. /* 定位 */
  324. 'setPosition' : function(pos){
  325. /* 上次定位 */
  326. this.lastPos = pos;
  327. if (typeof(pos) == 'string')
  328. {
  329. switch(pos){
  330. case 'center':
  331. var left = 0;
  332. var top = 0;
  333. var dialog_width = $(this.dom.wrapper).width();
  334. var dialog_height = $(this.dom.wrapper).height();
  335. /* left=滚动条的宽度 + (当前可视区的宽度 - 对话框的宽度 ) / 2 */
  336. left = $(window).scrollLeft() + ($(window).width() - dialog_width) / 2;
  337. /* top =滚动条的高度 + (当前可视区的高度 - 对话框的高度 ) / 2 */
  338. top = $(window).scrollTop() + ($(window).height() - dialog_height) / 2;
  339. $(this.dom.wrapper).css({left:left + 'px', top:top + 'px'});
  340. break;
  341. }
  342. }
  343. else
  344. {
  345. var _pos = {};
  346. if (typeof(pos.left) != 'undefined')
  347. {
  348. _pos.left = pos.left;
  349. }
  350. if (typeof(pos.top) != 'undefined')
  351. {
  352. _pos.top = pos.top;
  353. }
  354. $(this.dom.wrapper).css(_pos);
  355. }
  356. },
  357. /* 设置状态 */
  358. 'setStatus' : function(code){
  359. this.status = code;
  360. },
  361. /* 获取状态 */
  362. 'getStatus' : function(){
  363. return this.status;
  364. },
  365. 'disableClose' : function(msg){
  366. this.tmp['oldOnClose'] = this.onClose;
  367. this.onClose = function(){
  368. if(msg)alert(msg);
  369. return false;
  370. };
  371. },
  372. 'enableClose' : function(){
  373. this.onClose = this.tmp['oldOnClose'];
  374. this.tmp['oldOnClose'] = null;
  375. }
  376. };
  377. DialogManager.loadStyle();
  378. /*common2.2.js*/
  379. DIALOGIMGDIR = BASESITEROOT+'/static/plugins/js/dialog/images/dialog';
  380. var BROWSER = {};
  381. var USERAGENT = navigator.userAgent.toLowerCase();
  382. browserVersion({'ie':'msie','firefox':'','chrome':'','opera':'','safari':'','mozilla':'','webkit':'','maxthon':'','qq':'qqbrowser'});
  383. if(BROWSER.safari) {
  384. BROWSER.firefox = true;
  385. }
  386. BROWSER.opera = BROWSER.opera ? opera.version() : 0;
  387. HTMLNODE = document.getElementsByTagName('head')[0].parentNode;
  388. if(BROWSER.ie) {
  389. BROWSER.iemode = parseInt(typeof document.documentMode != 'undefined' ? document.documentMode : BROWSER.ie);
  390. HTMLNODE.className = 'ie_all ie' + BROWSER.iemode;
  391. }
  392. var JSLOADED = [];
  393. var JSMENU = [];
  394. JSMENU['active'] = [];
  395. JSMENU['timer'] = [];
  396. JSMENU['drag'] = [];
  397. JSMENU['layer'] = 0;
  398. JSMENU['zIndex'] = {'win':1000,'menu':1100,'dialog':1200,'prompt':1300};
  399. JSMENU['float'] = '';
  400. var CURRENTSTYPE = null;
  401. var EXTRAFUNC = [], EXTRASTR = '';
  402. if(BROWSER.firefox && window.HTMLElement) {
  403. HTMLElement.prototype.__defineGetter__( "innerText", function(){
  404. var anyString = "";
  405. var childS = this.childNodes;
  406. for(var i=0; i <childS.length; i++) {
  407. if(childS[i].nodeType==1) {
  408. anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
  409. } else if(childS[i].nodeType==3) {
  410. anyString += childS[i].nodeValue;
  411. }
  412. }
  413. return anyString;
  414. });
  415. HTMLElement.prototype.__defineSetter__( "innerText", function(sText){
  416. this.textContent=sText;
  417. });
  418. HTMLElement.prototype.__defineSetter__('outerHTML', function(sHTML) {
  419. var r = this.ownerDocument.createRange();
  420. r.setStartBefore(this);
  421. var df = r.createContextualFragment(sHTML);
  422. this.parentNode.replaceChild(df,this);
  423. return sHTML;
  424. });
  425. HTMLElement.prototype.__defineGetter__('outerHTML', function() {
  426. var attr;
  427. var attrs = this.attributes;
  428. var str = '<' + this.tagName.toLowerCase();
  429. for(var i = 0;i < attrs.length;i++){
  430. attr = attrs[i];
  431. if(attr.specified)
  432. str += ' ' + attr.name + '="' + attr.value + '"';
  433. }
  434. if(!this.canHaveChildren) {
  435. return str + '>';
  436. }
  437. return str + '>' + this.innerHTML + '</' + this.tagName.toLowerCase() + '>';
  438. });
  439. HTMLElement.prototype.__defineGetter__('canHaveChildren', function() {
  440. switch(this.tagName.toLowerCase()) {
  441. 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':
  442. return false;
  443. }
  444. return true;
  445. });
  446. }
  447. function $$(id) {
  448. return !id ? null : document.getElementById(id);
  449. }
  450. function _attachEvent(obj, evt, func, eventobj) {
  451. eventobj = !eventobj ? obj : eventobj;
  452. if(obj.addEventListener) {
  453. obj.addEventListener(evt, func, false);
  454. } else if(eventobj.attachEvent) {
  455. obj.attachEvent('on' + evt, func);
  456. }
  457. }
  458. function browserVersion(types) {
  459. var other = 1;
  460. for(i in types) {
  461. var v = types[i] ? types[i] : i;
  462. if(USERAGENT.indexOf(v) != -1) {
  463. var re = new RegExp(v + '(\\/|\\s)([\\d\\.]+)', 'ig');
  464. var matches = re.exec(USERAGENT);
  465. var ver = matches != null ? matches[2] : 0;
  466. other = ver !== 0 && v != 'mozilla' ? 0 : other;
  467. }else {
  468. var ver = 0;
  469. }
  470. eval('BROWSER.' + i + '= ver');
  471. }
  472. BROWSER.other = other;
  473. }
  474. function getEvent() {
  475. if(document.all) return window.event;
  476. func = getEvent.caller;
  477. while(func != null) {
  478. var arg0 = func.arguments[0];
  479. if (arg0) {
  480. if((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof(arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
  481. return arg0;
  482. }
  483. }
  484. func=func.caller;
  485. }
  486. return null;
  487. }
  488. function isUndefined(variable) {
  489. return typeof variable == 'undefined' ? true : false;
  490. }
  491. function in_array(needle, haystack) {
  492. if(typeof needle == 'string' || typeof needle == 'number') {
  493. for(var i in haystack) {
  494. if(haystack[i] == needle) {
  495. return true;
  496. }
  497. }
  498. }
  499. return false;
  500. }
  501. function strlen(str) {
  502. return (BROWSER.ie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
  503. }
  504. function Ajax(recvType, waitId) {
  505. var aj = new Object();
  506. aj.loading = '请稍候...';
  507. aj.recvType = recvType ? recvType : 'XML';
  508. aj.waitId = waitId ? $$(waitId) : null;
  509. aj.resultHandle = null;
  510. aj.sendString = '';
  511. aj.targetUrl = '';
  512. aj.setLoading = function(loading) {
  513. if(typeof loading !== 'undefined' && loading !== null) aj.loading = loading;
  514. };
  515. aj.setRecvType = function(recvtype) {
  516. aj.recvType = recvtype;
  517. };
  518. aj.setWaitId = function(waitid) {
  519. aj.waitId = typeof waitid == 'object' ? waitid : $$(waitid);
  520. };
  521. aj.createXMLHttpRequest = function() {
  522. var request = false;
  523. if(window.XMLHttpRequest) {
  524. request = new XMLHttpRequest();
  525. if(request.overrideMimeType) {
  526. request.overrideMimeType('text/xml');
  527. }
  528. } else if(window.ActiveXObject) {
  529. 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'];
  530. for(var i=0; i<versions.length; i++) {
  531. try {
  532. request = new ActiveXObject(versions[i]);
  533. if(request) {
  534. return request;
  535. }
  536. } catch(e) {}
  537. }
  538. }
  539. return request;
  540. };
  541. aj.XMLHttpRequest = aj.createXMLHttpRequest();
  542. aj.showLoading = function() {
  543. if(aj.waitId && (aj.XMLHttpRequest.readyState != 4 || aj.XMLHttpRequest.status != 200)) {
  544. aj.waitId.style.display = '';
  545. aj.waitId.innerHTML = '<span><img src="' + DIALOGIMGDIR + '/loading.gif" class="vm"> ' + aj.loading + '</span>';
  546. }
  547. };
  548. aj.processHandle = function() {
  549. if(aj.XMLHttpRequest.readyState == 4 && aj.XMLHttpRequest.status == 200) {
  550. if(aj.waitId) {
  551. aj.waitId.style.display = 'none';
  552. }
  553. if(aj.recvType == 'HTML') {
  554. aj.resultHandle(aj.XMLHttpRequest.responseText, aj);
  555. } else if(aj.recvType == 'XML') {
  556. if(!aj.XMLHttpRequest.responseXML || !aj.XMLHttpRequest.responseXML.lastChild || aj.XMLHttpRequest.responseXML.lastChild.localName == 'parsererror') {
  557. aj.resultHandle('<a href="' + aj.targetUrl + '" target="_blank" style="color:red">内部错误,无法显示此内容</a>' , aj);
  558. } else {
  559. aj.resultHandle(aj.XMLHttpRequest.responseXML.lastChild.firstChild.nodeValue, aj);
  560. }
  561. }
  562. }
  563. };
  564. aj.get = function(targetUrl, resultHandle) {
  565. targetUrl = hostconvert(targetUrl);
  566. setTimeout(function(){aj.showLoading()}, 250);
  567. aj.targetUrl = targetUrl;
  568. aj.XMLHttpRequest.onreadystatechange = aj.processHandle;
  569. aj.resultHandle = resultHandle;
  570. var attackevasive = isUndefined(attackevasive) ? 0 : attackevasive;
  571. if(window.XMLHttpRequest) {
  572. aj.XMLHttpRequest.open('GET', aj.targetUrl);
  573. aj.XMLHttpRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  574. aj.XMLHttpRequest.send(null);
  575. } else {
  576. aj.XMLHttpRequest.open("GET", targetUrl, true);
  577. aj.XMLHttpRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  578. aj.XMLHttpRequest.send();
  579. }
  580. };
  581. aj.post = function(targetUrl, sendString, resultHandle) {
  582. targetUrl = hostconvert(targetUrl);
  583. setTimeout(function(){aj.showLoading()}, 250);
  584. aj.targetUrl = targetUrl;
  585. aj.sendString = sendString;
  586. aj.XMLHttpRequest.onreadystatechange = aj.processHandle;
  587. aj.resultHandle = resultHandle;
  588. aj.XMLHttpRequest.open('POST', targetUrl);
  589. aj.XMLHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  590. aj.XMLHttpRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  591. aj.XMLHttpRequest.send(aj.sendString);
  592. };
  593. return aj;
  594. }
  595. function getHost(url) {
  596. var host = "null";
  597. if(typeof url == "undefined"|| null == url) {
  598. url = window.location.href;
  599. }
  600. var regex = /^\w+\:\/\/([^\/]*).*/;
  601. var match = url.match(regex);
  602. if(typeof match != "undefined" && null != match) {
  603. host = match[1];
  604. }
  605. return host;
  606. }
  607. function hostconvert(url) {
  608. return url;
  609. if (!url.match(/^http?:\/\//))
  610. url = BASESITEROOT.replace(/(\/+)$/g, '') + '/' + url;
  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 hash(string, length) {
  678. var length = length ? length : 32;
  679. var start = 0;
  680. var i = 0;
  681. var result = '';
  682. filllen = length - string.length % length;
  683. for(i = 0; i < filllen; i++){
  684. string += "0";
  685. }
  686. while(start < string.length) {
  687. result = stringxor(result, string.substr(start, length));
  688. start += length;
  689. }
  690. return result;
  691. }
  692. function stringxor(s1, s2) {
  693. var s = '';
  694. var hash = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  695. var max = Math.max(s1.length, s2.length);
  696. for(var i=0; i<max; i++) {
  697. var k = s1.charCodeAt(i) ^ s2.charCodeAt(i);
  698. s += hash.charAt(k % 52);
  699. }
  700. return s;
  701. }
  702. function showloading(display, waiting) {
  703. var display = display ? display : 'block';
  704. var waiting = waiting ? waiting : '请稍候...';
  705. $$('ajaxwaitid').innerHTML = waiting;
  706. $$('ajaxwaitid').style.display = display;
  707. }
  708. function ajaxinnerhtml(showid, s) {
  709. if(showid.tagName != 'TBODY') {
  710. showid.innerHTML = s;
  711. } else {
  712. while(showid.firstChild) {
  713. showid.firstChild.parentNode.removeChild(showid.firstChild);
  714. }
  715. var div1 = document.createElement('DIV');
  716. div1.id = showid.id+'_div';
  717. div1.innerHTML = '<table><tbody id="'+showid.id+'_tbody">'+s+'</tbody></table>';
  718. $$('append_parent').appendChild(div1);
  719. var trs = div1.getElementsByTagName('TR');
  720. var l = trs.length;
  721. for(var i=0; i<l; i++) {
  722. showid.appendChild(trs[0]);
  723. }
  724. var inputs = div1.getElementsByTagName('INPUT');
  725. var l = inputs.length;
  726. for(var i=0; i<l; i++) {
  727. showid.appendChild(inputs[0]);
  728. }
  729. div1.parentNode.removeChild(div1);
  730. }
  731. }
  732. function doane(event, preventDefault, stopPropagation) {
  733. var preventDefault = isUndefined(preventDefault) ? 1 : preventDefault;
  734. var stopPropagation = isUndefined(stopPropagation) ? 1 : stopPropagation;
  735. e = event ? event : window.event;
  736. if(!e) {
  737. e = getEvent();
  738. }
  739. if(!e) {
  740. return null;
  741. }
  742. if(preventDefault) {
  743. if(e.preventDefault) {
  744. e.preventDefault();
  745. } else {
  746. e.returnValue = false;
  747. }
  748. }
  749. if(stopPropagation) {
  750. if(e.stopPropagation) {
  751. e.stopPropagation();
  752. } else {
  753. e.cancelBubble = true;
  754. }
  755. }
  756. return e;
  757. }
  758. function showMenu(v) {
  759. var ctrlid = isUndefined(v['ctrlid']) ? v : v['ctrlid'];
  760. var showid = isUndefined(v['showid']) ? ctrlid : v['showid'];
  761. var menuid = isUndefined(v['menuid']) ? showid + '_menu' : v['menuid'];
  762. var ctrlObj = $$(ctrlid);
  763. var menuObj = $$(menuid);
  764. if(!menuObj) return;
  765. var mtype = isUndefined(v['mtype']) ? 'menu' : v['mtype'];
  766. var evt = isUndefined(v['evt']) ? 'mouseover' : v['evt'];
  767. var pos = isUndefined(v['pos']) ? '43' : v['pos'];
  768. var layer = isUndefined(v['layer']) ? 1 : v['layer'];
  769. var duration = isUndefined(v['duration']) ? 2 : v['duration'];
  770. var timeout = isUndefined(v['timeout']) ? 250 : v['timeout'];
  771. var maxh = isUndefined(v['maxh']) ? 600 : v['maxh'];
  772. var cache = isUndefined(v['cache']) ? 1 : v['cache'];
  773. var drag = isUndefined(v['drag']) ? '' : v['drag'];
  774. var dragobj = drag && $$(drag) ? $$(drag) : menuObj;
  775. var fade = isUndefined(v['fade']) ? 0 : v['fade'];
  776. var cover = isUndefined(v['cover']) ? 0 : v['cover'];
  777. var zindex = isUndefined(v['zindex']) ? JSMENU['zIndex']['menu'] : v['zindex'];
  778. var ctrlclass = isUndefined(v['ctrlclass']) ? '' : v['ctrlclass'];
  779. var winhandlekey = isUndefined(v['win']) ? '' : v['win'];
  780. zindex = cover ? zindex + 500 : zindex;
  781. if(typeof JSMENU['active'][layer] == 'undefined') {
  782. JSMENU['active'][layer] = [];
  783. }
  784. for(i in EXTRAFUNC['showmenu']) {
  785. try {
  786. eval(EXTRAFUNC['showmenu'][i] + '()');
  787. } catch(e) {}
  788. }
  789. if(evt == 'click' && in_array(menuid, JSMENU['active'][layer]) && mtype != 'win') {
  790. hideMenu(menuid, mtype);
  791. return;
  792. }
  793. if(mtype == 'menu') {
  794. hideMenu(layer, mtype);
  795. }
  796. if(ctrlObj) {
  797. if(!ctrlObj.getAttribute('initialized')) {
  798. ctrlObj.setAttribute('initialized', true);
  799. ctrlObj.unselectable = true;
  800. ctrlObj.outfunc = typeof ctrlObj.onmouseout == 'function' ? ctrlObj.onmouseout : null;
  801. ctrlObj.onmouseout = function() {
  802. if(this.outfunc) this.outfunc();
  803. if(duration < 3 && !JSMENU['timer'][menuid]) {
  804. JSMENU['timer'][menuid] = setTimeout(function () {
  805. hideMenu(menuid, mtype);
  806. }, timeout);
  807. }
  808. };
  809. ctrlObj.overfunc = typeof ctrlObj.onmouseover == 'function' ? ctrlObj.onmouseover : null;
  810. ctrlObj.onmouseover = function(e) {
  811. doane(e);
  812. if(this.overfunc) this.overfunc();
  813. if(evt == 'click') {
  814. clearTimeout(JSMENU['timer'][menuid]);
  815. JSMENU['timer'][menuid] = null;
  816. } else {
  817. for(var i in JSMENU['timer']) {
  818. if(JSMENU['timer'][i]) {
  819. clearTimeout(JSMENU['timer'][i]);
  820. JSMENU['timer'][i] = null;
  821. }
  822. }
  823. }
  824. };
  825. }
  826. }
  827. if(!menuObj.getAttribute('initialized')) {
  828. menuObj.setAttribute('initialized', true);
  829. menuObj.ctrlkey = ctrlid;
  830. menuObj.mtype = mtype;
  831. menuObj.layer = layer;
  832. menuObj.cover = cover;
  833. if(ctrlObj && ctrlObj.getAttribute('fwin')) {menuObj.scrolly = true;}
  834. menuObj.style.position = 'absolute';
  835. menuObj.style.zIndex = zindex + layer;
  836. menuObj.onclick = function(e) {
  837. return doane(e, 0, 1);
  838. };
  839. if(duration < 3) {
  840. if(duration > 1) {
  841. menuObj.onmouseover = function() {
  842. clearTimeout(JSMENU['timer'][menuid]);
  843. JSMENU['timer'][menuid] = null;
  844. };
  845. }
  846. if(duration != 1) {
  847. menuObj.onmouseout = function() {
  848. JSMENU['timer'][menuid] = setTimeout(function () {
  849. hideMenu(menuid, mtype);
  850. }, timeout);
  851. };
  852. }
  853. }
  854. if(cover) {
  855. var coverObj = document.createElement('div');
  856. coverObj.id = menuid + '_cover';
  857. coverObj.style.position = 'absolute';
  858. coverObj.style.zIndex = menuObj.style.zIndex - 1;
  859. coverObj.style.left = coverObj.style.top = '0px';
  860. coverObj.style.width = '100%';
  861. coverObj.style.height = Math.max(document.documentElement.clientHeight, document.body.offsetHeight) + 'px';
  862. coverObj.style.backgroundColor = 'transparent';
  863. coverObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
  864. coverObj.style.opacity = 0;
  865. coverObj.onclick = function () { hideMenu(); };
  866. $$('append_parent').appendChild(coverObj);
  867. _attachEvent(window, 'load', function () {
  868. coverObj.style.height = Math.max(document.documentElement.clientHeight, document.body.offsetHeight) + 'px';
  869. }, document);
  870. }
  871. }
  872. if(drag) {
  873. dragobj.style.cursor = 'move';
  874. dragobj.onmousedown = function(event) {try{dragMenu(menuObj, event, 1);}catch(e){}};
  875. }
  876. if(cover) $$(menuid + '_cover').style.display = '';
  877. if(fade) {
  878. var O = 0;
  879. var fadeIn = function(O) {
  880. if(O > 100) {
  881. clearTimeout(fadeInTimer);
  882. return;
  883. }
  884. menuObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + O + ')';
  885. menuObj.style.opacity = O / 100;
  886. O += 20;
  887. var fadeInTimer = setTimeout(function () {
  888. fadeIn(O);
  889. }, 40);
  890. };
  891. fadeIn(O);
  892. menuObj.fade = true;
  893. } else {
  894. menuObj.fade = false;
  895. }
  896. menuObj.style.display = '';
  897. if(ctrlObj && ctrlclass) {
  898. ctrlObj.className += ' ' + ctrlclass;
  899. menuObj.setAttribute('ctrlid', ctrlid);
  900. menuObj.setAttribute('ctrlclass', ctrlclass);
  901. }
  902. if(pos != '*') {
  903. setMenuPosition(showid, menuid, pos);
  904. }
  905. if(BROWSER.ie && BROWSER.ie < 7 && winhandlekey && $$('fwin_' + winhandlekey)) {
  906. $$(menuid).style.left = (parseInt($$(menuid).style.left) - parseInt($$('fwin_' + winhandlekey).style.left)) + 'px';
  907. $$(menuid).style.top = (parseInt($$(menuid).style.top) - parseInt($$('fwin_' + winhandlekey).style.top)) + 'px';
  908. }
  909. if(maxh && menuObj.scrollHeight > maxh) {
  910. menuObj.style.height = maxh + 'px';
  911. if(BROWSER.opera) {
  912. menuObj.style.overflow = 'auto';
  913. } else {
  914. menuObj.style.overflowY = 'auto';
  915. }
  916. }
  917. if(!duration) {
  918. setTimeout('hideMenu(\'' + menuid + '\', \'' + mtype + '\')', timeout);
  919. }
  920. if(!in_array(menuid, JSMENU['active'][layer])) JSMENU['active'][layer].push(menuid);
  921. menuObj.cache = cache;
  922. if(layer > JSMENU['layer']) {
  923. JSMENU['layer'] = layer;
  924. }
  925. }
  926. var dragMenuDisabled = false;
  927. function dragMenu(menuObj, e, op) {
  928. e = e ? e : window.event;
  929. if(op == 1) {
  930. if(dragMenuDisabled || in_array(e.target ? e.target.tagName : e.srcElement.tagName, ['TEXTAREA', 'INPUT', 'BUTTON', 'SELECT'])) {
  931. return;
  932. }
  933. JSMENU['drag'] = [e.clientX, e.clientY];
  934. JSMENU['drag'][2] = parseInt(menuObj.style.left);
  935. JSMENU['drag'][3] = parseInt(menuObj.style.top);
  936. document.onmousemove = function(e) {try{dragMenu(menuObj, e, 2);}catch(err){}};
  937. document.onmouseup = function(e) {try{dragMenu(menuObj, e, 3);}catch(err){}};
  938. doane(e);
  939. }else if(op == 2 && JSMENU['drag'][0]) {
  940. var menudragnow = [e.clientX, e.clientY];
  941. menuObj.style.left = (JSMENU['drag'][2] + menudragnow[0] - JSMENU['drag'][0]) + 'px';
  942. menuObj.style.top = (JSMENU['drag'][3] + menudragnow[1] - JSMENU['drag'][1]) + 'px';
  943. menuObj.removeAttribute('top_');menuObj.removeAttribute('left_');
  944. doane(e);
  945. }else if(op == 3) {
  946. JSMENU['drag'] = [];
  947. document.onmousemove = null;
  948. document.onmouseup = null;
  949. }
  950. }
  951. function setMenuPosition(showid, menuid, pos) {
  952. var showObj = $$(showid);
  953. var menuObj = menuid ? $$(menuid) : $$(showid + '_menu');
  954. if(isUndefined(pos) || !pos) pos = '43';
  955. var basePoint = parseInt(pos.substr(0, 1));
  956. var direction = parseInt(pos.substr(1, 1));
  957. var important = pos.indexOf('!') != -1 ? 1 : 0;
  958. 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;
  959. if(!menuObj || (basePoint > 0 && !showObj)) return;
  960. if(showObj) {
  961. sxy = fetchOffset(showObj);
  962. sx = sxy['left'];
  963. sy = sxy['top'];
  964. sw = showObj.offsetWidth;
  965. sh = showObj.offsetHeight;
  966. }
  967. mw = menuObj.offsetWidth;
  968. mcw = menuObj.clientWidth;
  969. mh = menuObj.offsetHeight;
  970. mch = menuObj.clientHeight;
  971. switch(basePoint) {
  972. case 1:
  973. bpl = sx;
  974. bpt = sy;
  975. break;
  976. case 2:
  977. bpl = sx + sw;
  978. bpt = sy;
  979. break;
  980. case 3:
  981. bpl = sx + sw;
  982. bpt = sy + sh;
  983. break;
  984. case 4:
  985. bpl = sx;
  986. bpt = sy + sh;
  987. break;
  988. }
  989. switch(direction) {
  990. case 0:
  991. menuObj.style.left = (document.body.clientWidth - menuObj.clientWidth) / 2 + 'px';
  992. mt = (document.documentElement.clientHeight - menuObj.clientHeight) / 2;
  993. break;
  994. case 1:
  995. ml = bpl - mw;
  996. mt = bpt - mh;
  997. break;
  998. case 2:
  999. ml = bpl;
  1000. mt = bpt - mh;
  1001. break;
  1002. case 3:
  1003. ml = bpl;
  1004. mt = bpt;
  1005. break;
  1006. case 4:
  1007. ml = bpl - mw;
  1008. mt = bpt;
  1009. break;
  1010. }
  1011. var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  1012. var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
  1013. if(!important) {
  1014. if(in_array(direction, [1, 4]) && ml < 0) {
  1015. ml = bpl;
  1016. if(in_array(basePoint, [1, 4])) ml += sw;
  1017. } else if(ml + mw > scrollLeft + document.body.clientWidth && sx >= mw) {
  1018. ml = bpl - mw;
  1019. if(in_array(basePoint, [2, 3])) {
  1020. ml -= sw;
  1021. } else if(basePoint == 4) {
  1022. ml += sw;
  1023. }
  1024. }
  1025. if(in_array(direction, [1, 2]) && mt < 0) {
  1026. mt = bpt;
  1027. if(in_array(basePoint, [1, 2])) mt += sh;
  1028. } else if(mt + mh > scrollTop + document.documentElement.clientHeight && sy >= mh) {
  1029. mt = bpt - mh;
  1030. if(in_array(basePoint, [3, 4])) mt -= sh;
  1031. }
  1032. }
  1033. if(pos.substr(0, 3) == '210') {
  1034. ml += 69 - sw / 2;
  1035. mt -= 5;
  1036. if(showObj.tagName == 'TEXTAREA') {
  1037. ml -= sw / 2;
  1038. mt += sh / 2;
  1039. }
  1040. }
  1041. if(direction == 0 || menuObj.scrolly) {
  1042. if(BROWSER.ie && BROWSER.ie < 7) {
  1043. if(direction == 0) mt += scrollTop;
  1044. } else {
  1045. if(menuObj.scrolly) mt -= scrollTop;
  1046. menuObj.style.position = 'fixed';
  1047. }
  1048. }
  1049. if(ml) menuObj.style.left = ml + 'px';
  1050. if(mt) menuObj.style.top = mt + 'px';
  1051. if(direction == 0 && BROWSER.ie && !document.documentElement.clientHeight) {
  1052. menuObj.style.position = 'absolute';
  1053. menuObj.style.top = (document.body.clientHeight - menuObj.clientHeight) / 2 + 'px';
  1054. }
  1055. if(menuObj.style.clip && !BROWSER.opera) {
  1056. menuObj.style.clip = 'rect(auto, auto, auto, auto)';
  1057. }
  1058. }
  1059. function hideMenu(attr, mtype) {
  1060. attr = isUndefined(attr) ? '' : attr;
  1061. mtype = isUndefined(mtype) ? 'menu' : mtype;
  1062. if(attr == '') {
  1063. for(var i = 1; i <= JSMENU['layer']; i++) {
  1064. hideMenu(i, mtype);
  1065. }
  1066. return;
  1067. } else if(typeof attr == 'number') {
  1068. for(var j in JSMENU['active'][attr]) {
  1069. hideMenu(JSMENU['active'][attr][j], mtype);
  1070. }
  1071. return;
  1072. }else if(typeof attr == 'string') {
  1073. var menuObj = $$(attr);
  1074. if(!menuObj || (mtype && menuObj.mtype != mtype)) return;
  1075. var ctrlObj = '', ctrlclass = '';
  1076. if((ctrlObj = $$(menuObj.getAttribute('ctrlid'))) && (ctrlclass = menuObj.getAttribute('ctrlclass'))) {
  1077. var reg = new RegExp(' ' + ctrlclass);
  1078. ctrlObj.className = ctrlObj.className.replace(reg, '');
  1079. }
  1080. clearTimeout(JSMENU['timer'][attr]);
  1081. var hide = function() {
  1082. if(menuObj.cache) {
  1083. if(menuObj.style.visibility != 'hidden') {
  1084. menuObj.style.display = 'none';
  1085. if(menuObj.cover) $$(attr + '_cover').style.display = 'none';
  1086. }
  1087. }else {
  1088. menuObj.parentNode.removeChild(menuObj);
  1089. if(menuObj.cover) $$(attr + '_cover').parentNode.removeChild($$(attr + '_cover'));
  1090. }
  1091. var tmp = [];
  1092. for(var k in JSMENU['active'][menuObj.layer]) {
  1093. if(attr != JSMENU['active'][menuObj.layer][k]) tmp.push(JSMENU['active'][menuObj.layer][k]);
  1094. }
  1095. JSMENU['active'][menuObj.layer] = tmp;
  1096. };
  1097. if(menuObj.fade) {
  1098. var O = 100;
  1099. var fadeOut = function(O) {
  1100. if(O == 0) {
  1101. clearTimeout(fadeOutTimer);
  1102. hide();
  1103. return;
  1104. }
  1105. menuObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + O + ')';
  1106. menuObj.style.opacity = O / 100;
  1107. O -= 20;
  1108. var fadeOutTimer = setTimeout(function () {
  1109. fadeOut(O);
  1110. }, 40);
  1111. };
  1112. fadeOut(O);
  1113. } else {
  1114. hide();
  1115. }
  1116. }
  1117. }
  1118. function getCurrentStyle(obj, cssproperty, csspropertyNS) {
  1119. if(obj.style[cssproperty]){
  1120. return obj.style[cssproperty];
  1121. }
  1122. if (obj.currentStyle) {
  1123. return obj.currentStyle[cssproperty];
  1124. } else if (document.defaultView.getComputedStyle(obj, null)) {
  1125. var currentStyle = document.defaultView.getComputedStyle(obj, null);
  1126. var value = currentStyle.getPropertyValue(csspropertyNS);
  1127. if(!value){
  1128. value = currentStyle[cssproperty];
  1129. }
  1130. return value;
  1131. } else if (window.getComputedStyle) {
  1132. var currentStyle = window.getComputedStyle(obj, "");
  1133. return currentStyle.getPropertyValue(csspropertyNS);
  1134. }
  1135. }
  1136. function fetchOffset(obj, mode) {
  1137. var left_offset = 0, top_offset = 0, mode = !mode ? 0 : mode;
  1138. if(obj.getBoundingClientRect && !mode) {
  1139. var rect = obj.getBoundingClientRect();
  1140. var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  1141. var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
  1142. if(document.documentElement.dir == 'rtl') {
  1143. scrollLeft = scrollLeft + document.documentElement.clientWidth - document.documentElement.scrollWidth;
  1144. }
  1145. left_offset = rect.left + scrollLeft - document.documentElement.clientLeft;
  1146. top_offset = rect.top + scrollTop - document.documentElement.clientTop;
  1147. }
  1148. if(left_offset <= 0 || top_offset <= 0) {
  1149. left_offset = obj.offsetLeft;
  1150. top_offset = obj.offsetTop;
  1151. while((obj = obj.offsetParent) != null) {
  1152. position = getCurrentStyle(obj, 'position', 'position');
  1153. if(position == 'relative') {
  1154. continue;
  1155. }
  1156. left_offset += obj.offsetLeft;
  1157. top_offset += obj.offsetTop;
  1158. }
  1159. }
  1160. return {'left' : left_offset, 'top' : top_offset};
  1161. }
  1162. var showDialogST = null;
  1163. function showDialog(msg, mode, t, func, cover, funccancel, leftmsg, confirmtxt, canceltxt, closetime, locationtime) {
  1164. if (mode == 'js'){
  1165. if(typeof func == 'function') func();
  1166. else eval(func);
  1167. //hideMenu(null, 'dialog');
  1168. return ;
  1169. }
  1170. clearTimeout(showDialogST);
  1171. cover = isUndefined(cover) ? (mode == 'info' ? 0 : 1) : cover;
  1172. leftmsg = isUndefined(leftmsg) ? '' : leftmsg;
  1173. mode = in_array(mode, ['confirm', 'notice', 'info', 'succ','js']) ? mode : 'alert';
  1174. var menuid = 'fwin_dialog';
  1175. var menuObj = $$(menuid);
  1176. var showconfirm = 1;
  1177. confirmtxtdefault = '确定';
  1178. closetime = isUndefined(closetime) ? '' : closetime;
  1179. closefunc = function () {
  1180. if(typeof func == 'function') func();
  1181. else eval(func);
  1182. hideMenu(menuid, 'dialog');
  1183. };
  1184. if(closetime) {
  1185. leftmsg = closetime + ' 秒后窗口关闭';
  1186. showDialogST = setTimeout(closefunc, closetime * 1000);
  1187. showconfirm = 0;
  1188. }
  1189. locationtime = isUndefined(locationtime) ? '' : locationtime;
  1190. if(locationtime) {
  1191. leftmsg = locationtime + ' 秒后页面跳转';
  1192. showDialogST = setTimeout(closefunc, locationtime * 1000);
  1193. showconfirm = 0;
  1194. }
  1195. confirmtxt = confirmtxt ? confirmtxt : confirmtxtdefault;
  1196. canceltxt = canceltxt ? canceltxt : '取消';
  1197. if(menuObj) hideMenu('fwin_dialog', 'dialog');
  1198. menuObj = document.createElement('div');
  1199. menuObj.style.display = 'none';
  1200. menuObj.className = 'dialog_body';
  1201. menuObj.id = menuid;
  1202. $$('append_parent').appendChild(menuObj);
  1203. var hidedom = '';
  1204. if(!BROWSER.ie) {
  1205. hidedom = '<style type="text/css">object{visibility:hidden;}</style>';
  1206. }
  1207. var s = hidedom + '<h3 class="dialog_head"><span class="dialog_title">';
  1208. s += t ? t : '<span class="dialog_title_icon">提示信息</span>';
  1209. s += '</span><span class="dialog_close_button" id="fwin_dialog_close" onclick="hideMenu(\'' + menuid + '\', \'dialog\')" title="关闭">X</span></h3>';
  1210. if(mode == 'info') {
  1211. s += msg ? msg : '';
  1212. } else {
  1213. s += '<div class="eject_con"><div class="dialog_message_contents">';
  1214. s += '<i class="' + (mode == 'alert' ? 'alert_error' : (mode == 'succ' ? 'alert_right' : 'alert_info')) + '"></i>' + msg + '</div></div>';
  1215. s += '<div class="dialog_buttons_bar">' + (leftmsg ? '<time class="countdown">'+'<i class="fa fa-clock-o"></i>' + leftmsg + '</time>' : '') + (showconfirm ? '<a href="javascript:void(0)" id="fwin_dialog_submit" class="dialog-bottom-btn dialog-bottom-btn mr10">'+confirmtxt+'</a>' : '');
  1216. s += mode == 'confirm' ? '<a href="javascript:void(0)" id="fwin_dialog_cancel" class="dialog-bottom-btn" onclick="hideMenu(\'' + menuid + '\', \'dialog\')">'+canceltxt+'</a>' : '';
  1217. s += '</div>';
  1218. }
  1219. menuObj.innerHTML = s;
  1220. if($$('fwin_dialog_submit')) $$('fwin_dialog_submit').onclick = function() {
  1221. if(typeof func == 'function') func();
  1222. else eval(func);
  1223. hideMenu(menuid, 'dialog');
  1224. };
  1225. if($$('fwin_dialog_cancel')) {
  1226. $$('fwin_dialog_cancel').onclick = function() {
  1227. if(typeof funccancel == 'function') funccancel();
  1228. else eval(funccancel);
  1229. hideMenu(menuid, 'dialog');
  1230. };
  1231. $$('fwin_dialog_close').onclick = $$('fwin_dialog_cancel').onclick;
  1232. }
  1233. showMenu({'mtype':'dialog','menuid':menuid,'duration':3,'pos':'00','zindex':JSMENU['zIndex']['dialog'],'cache':0,'cover':cover});
  1234. try {
  1235. if($$('fwin_dialog_submit')) $$('fwin_dialog_submit').focus();
  1236. } catch(e) {}
  1237. }
  1238. function hideWindow(k, all, clear) {
  1239. all = isUndefined(all) ? 1 : all;
  1240. clear = isUndefined(clear) ? 1 : clear;
  1241. hideMenu('fwin_' + k, 'win');
  1242. if(clear && $$('fwin_' + k)) {
  1243. $$('append_parent').removeChild($$('fwin_' + k));
  1244. }
  1245. if(all) {
  1246. hideMenu();
  1247. }
  1248. }