dialog.js 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  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 = "__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. if(!url.match(/^http?:\/\//)) url = SITEURL.replace(/(\/+)$/g, '') + '/' + url;
  608. var url_host = getHost(url);
  609. var cur_host = getHost().toLowerCase();
  610. if(url_host && cur_host != url_host) {
  611. url = url.replace(url_host, cur_host);
  612. }
  613. return url;
  614. }
  615. function newfunction(func) {
  616. var args = [];
  617. for(var i=1; i<arguments.length; i++) args.push(arguments[i]);
  618. return function(event) {
  619. doane(event);
  620. window[func].apply(window, args);
  621. return false;
  622. }
  623. }
  624. function evalscript(s) {
  625. if(s.indexOf('<script') == -1) return s;
  626. var p = /<script[^\>]*?>([^\x00]*?)<\/script>/ig;
  627. var arr = [];
  628. while(arr = p.exec(s)) {
  629. var p1 = /<script[^\>]*?src=\"([^\>]*?)\"[^\>]*?(reload=\"1\")?(?:charset=\"([\w\-]+?)\")?><\/script>/i;
  630. var arr1 = [];
  631. arr1 = p1.exec(arr[0]);
  632. if(arr1) {
  633. appendscript(arr1[1], '', arr1[2], arr1[3]);
  634. } else {
  635. p1 = /<script(.*?)>([^\x00]+?)<\/script>/i;
  636. arr1 = p1.exec(arr[0]);
  637. appendscript('', arr1[2], arr1[1].indexOf('reload=') != -1);
  638. }
  639. }
  640. return s;
  641. }
  642. var evalscripts = [];
  643. function appendscript(src, text, reload, charset) {
  644. var id = hash(src + text);
  645. if(!reload && in_array(id, evalscripts)) return;
  646. if(reload && $$(id)) {
  647. $$(id).parentNode.removeChild($$(id));
  648. }
  649. evalscripts.push(id);
  650. var scriptNode = document.createElement("script");
  651. scriptNode.type = "text/javascript";
  652. scriptNode.id = id;
  653. scriptNode.charset = charset ? charset : (BROWSER.firefox ? document.characterSet : document.charset);
  654. try {
  655. if(src) {
  656. scriptNode.src = src;
  657. scriptNode.onloadDone = false;
  658. scriptNode.onload = function () {
  659. scriptNode.onloadDone = true;
  660. JSLOADED[src] = 1;
  661. };
  662. scriptNode.onreadystatechange = function () {
  663. if((scriptNode.readyState == 'loaded' || scriptNode.readyState == 'complete') && !scriptNode.onloadDone) {
  664. scriptNode.onloadDone = true;
  665. JSLOADED[src] = 1;
  666. }
  667. };
  668. } else if(text){
  669. scriptNode.text = text;
  670. }
  671. document.getElementsByTagName('head')[0].appendChild(scriptNode);
  672. } catch(e) {}
  673. }
  674. function ajaxupdateevents(obj, tagName) {
  675. tagName = tagName ? tagName : 'A';
  676. var objs = obj.getElementsByTagName(tagName);
  677. for(k in objs) {
  678. var o = objs[k];
  679. ajaxupdateevent(o);
  680. }
  681. }
  682. function ajaxupdateevent(o) {
  683. if(typeof o == 'object' && o.getAttribute) {
  684. if(o.getAttribute('ajaxtarget')) {
  685. if(!o.id) o.id = Math.random();
  686. var ajaxevent = o.getAttribute('ajaxevent') ? o.getAttribute('ajaxevent') : 'click';
  687. var ajaxurl = o.getAttribute('ajaxurl') ? o.getAttribute('ajaxurl') : o.href;
  688. _attachEvent(o, ajaxevent, newfunction('ajaxget', ajaxurl, o.getAttribute('ajaxtarget'), o.getAttribute('ajaxwaitid'), o.getAttribute('ajaxloading'), o.getAttribute('ajaxdisplay')));
  689. if(o.getAttribute('ajaxfunc')) {
  690. o.getAttribute('ajaxfunc').match(/(\w+)\((.+?)\)/);
  691. _attachEvent(o, ajaxevent, newfunction(RegExp.$1, RegExp.$2));
  692. }
  693. }
  694. }
  695. }
  696. function ajaxget(url, showid, waitid, loading, display, recall) {
  697. waitid = typeof waitid == 'undefined' || waitid === null ? showid : waitid;
  698. var x = new Ajax();
  699. x.setLoading(loading);
  700. x.setWaitId(waitid);
  701. x.display = typeof display == 'undefined' || display == null ? '' : display;
  702. x.showId = $$(showid);
  703. if(url.substr(strlen(url) - 1) == '#') {
  704. url = url.substr(0, strlen(url) - 1);
  705. x.autogoto = 1;
  706. }
  707. var url = url + '&inajax=1&ajaxtarget=' + showid;
  708. x.get(url, function(s, x) {
  709. var evaled = false;
  710. if(s.indexOf('ajaxerror') != -1) {
  711. evalscript(s);
  712. evaled = true;
  713. }
  714. if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
  715. if(x.showId) {
  716. x.showId.style.display = x.display;
  717. ajaxinnerhtml(x.showId, s);
  718. ajaxupdateevents(x.showId);
  719. if(x.autogoto) scroll(0, x.showId.offsetTop);
  720. }
  721. }
  722. ajaxerror = null;
  723. if(recall && typeof recall == 'function') {
  724. recall();
  725. } else if(recall) {
  726. eval(recall);
  727. }
  728. if(!evaled) evalscript(s);
  729. });
  730. }
  731. function ajaxpost(formid, showid, waitid, showidclass, submitbtn, recall) {
  732. var waitid = typeof waitid == 'undefined' || waitid === null ? showid : (waitid !== '' ? waitid : '');
  733. var showidclass = !showidclass ? '' : showidclass;
  734. var ajaxframeid = 'ajaxframe';
  735. var ajaxframe = $$(ajaxframeid);
  736. var formtarget = $$(formid).target;
  737. var handleResult = function() {
  738. var s = '';
  739. var evaled = false;
  740. // showloading('none');
  741. try {
  742. s = $$(ajaxframeid).contentWindow.document.XMLDocument.text;
  743. } catch(e) {
  744. try {
  745. s = $$(ajaxframeid).contentWindow.document.documentElement.firstChild.wholeText;
  746. } catch(e) {
  747. try {
  748. s = $$(ajaxframeid).contentWindow.document.documentElement.firstChild.nodeValue;
  749. } catch(e) {
  750. s = '内部错误,无法显示此内容';
  751. }
  752. }
  753. }
  754. if( s != '' && s.indexOf('ajaxerror') != -1) {
  755. evalscript(s);
  756. evaled = true;
  757. }
  758. if(showidclass) {
  759. if(showidclass != 'onerror') {
  760. $$(showid).className = showidclass;
  761. } else {
  762. showError(s);
  763. ajaxerror = true;
  764. }
  765. }
  766. if(submitbtn) {
  767. submitbtn.disabled = false;
  768. }
  769. if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
  770. ajaxinnerhtml($$(showid), s);
  771. }
  772. ajaxerror = null;
  773. if($$(formid)) $$(formid).target = formtarget;
  774. if(typeof recall == 'function') {
  775. recall();
  776. } else {
  777. eval(recall);
  778. }
  779. if(!evaled) evalscript(s);
  780. ajaxframe.loading = 0;
  781. $$('append_parent').removeChild(ajaxframe.parentNode);
  782. };
  783. if(!ajaxframe) {
  784. var div = document.createElement('div');
  785. div.style.display = 'none';
  786. div.innerHTML = '<iframe name="' + ajaxframeid + '" id="' + ajaxframeid + '" loading="1"></iframe>';
  787. $$('append_parent').appendChild(div);
  788. ajaxframe = $$(ajaxframeid);
  789. } else if(ajaxframe.loading) {
  790. return false;
  791. }
  792. _attachEvent(ajaxframe, 'load', handleResult);
  793. //showloading();
  794. $$(formid).target = ajaxframeid;
  795. var action = $$(formid).getAttribute('action');
  796. action = hostconvert(action);
  797. $$(formid).action = action.replace(/\&inajax\=1/g, '')+'&inajax=1';
  798. $$(formid).submit();
  799. if(submitbtn) {
  800. submitbtn.disabled = true;
  801. }
  802. doane();
  803. return false;
  804. }
  805. function hash(string, length) {
  806. var length = length ? length : 32;
  807. var start = 0;
  808. var i = 0;
  809. var result = '';
  810. filllen = length - string.length % length;
  811. for(i = 0; i < filllen; i++){
  812. string += "0";
  813. }
  814. while(start < string.length) {
  815. result = stringxor(result, string.substr(start, length));
  816. start += length;
  817. }
  818. return result;
  819. }
  820. function stringxor(s1, s2) {
  821. var s = '';
  822. var hash = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  823. var max = Math.max(s1.length, s2.length);
  824. for(var i=0; i<max; i++) {
  825. var k = s1.charCodeAt(i) ^ s2.charCodeAt(i);
  826. s += hash.charAt(k % 52);
  827. }
  828. return s;
  829. }
  830. function showloading(display, waiting) {
  831. var display = display ? display : 'block';
  832. var waiting = waiting ? waiting : '请稍候...';
  833. $$('ajaxwaitid').innerHTML = waiting;
  834. $$('ajaxwaitid').style.display = display;
  835. }
  836. function ajaxinnerhtml(showid, s) {
  837. if(showid.tagName != 'TBODY') {
  838. showid.innerHTML = s;
  839. } else {
  840. while(showid.firstChild) {
  841. showid.firstChild.parentNode.removeChild(showid.firstChild);
  842. }
  843. var div1 = document.createElement('DIV');
  844. div1.id = showid.id+'_div';
  845. div1.innerHTML = '<table><tbody id="'+showid.id+'_tbody">'+s+'</tbody></table>';
  846. $$('append_parent').appendChild(div1);
  847. var trs = div1.getElementsByTagName('TR');
  848. var l = trs.length;
  849. for(var i=0; i<l; i++) {
  850. showid.appendChild(trs[0]);
  851. }
  852. var inputs = div1.getElementsByTagName('INPUT');
  853. var l = inputs.length;
  854. for(var i=0; i<l; i++) {
  855. showid.appendChild(inputs[0]);
  856. }
  857. div1.parentNode.removeChild(div1);
  858. }
  859. }
  860. function doane(event, preventDefault, stopPropagation) {
  861. var preventDefault = isUndefined(preventDefault) ? 1 : preventDefault;
  862. var stopPropagation = isUndefined(stopPropagation) ? 1 : stopPropagation;
  863. e = event ? event : window.event;
  864. if(!e) {
  865. e = getEvent();
  866. }
  867. if(!e) {
  868. return null;
  869. }
  870. if(preventDefault) {
  871. if(e.preventDefault) {
  872. e.preventDefault();
  873. } else {
  874. e.returnValue = false;
  875. }
  876. }
  877. if(stopPropagation) {
  878. if(e.stopPropagation) {
  879. e.stopPropagation();
  880. } else {
  881. e.cancelBubble = true;
  882. }
  883. }
  884. return e;
  885. }
  886. function showMenu(v) {
  887. var ctrlid = isUndefined(v['ctrlid']) ? v : v['ctrlid'];
  888. var showid = isUndefined(v['showid']) ? ctrlid : v['showid'];
  889. var menuid = isUndefined(v['menuid']) ? showid + '_menu' : v['menuid'];
  890. var ctrlObj = $$(ctrlid);
  891. var menuObj = $$(menuid);
  892. if(!menuObj) return;
  893. var mtype = isUndefined(v['mtype']) ? 'menu' : v['mtype'];
  894. var evt = isUndefined(v['evt']) ? 'mouseover' : v['evt'];
  895. var pos = isUndefined(v['pos']) ? '43' : v['pos'];
  896. var layer = isUndefined(v['layer']) ? 1 : v['layer'];
  897. var duration = isUndefined(v['duration']) ? 2 : v['duration'];
  898. var timeout = isUndefined(v['timeout']) ? 250 : v['timeout'];
  899. var maxh = isUndefined(v['maxh']) ? 600 : v['maxh'];
  900. var cache = isUndefined(v['cache']) ? 1 : v['cache'];
  901. var drag = isUndefined(v['drag']) ? '' : v['drag'];
  902. var dragobj = drag && $$(drag) ? $$(drag) : menuObj;
  903. var fade = isUndefined(v['fade']) ? 0 : v['fade'];
  904. var cover = isUndefined(v['cover']) ? 0 : v['cover'];
  905. var zindex = isUndefined(v['zindex']) ? JSMENU['zIndex']['menu'] : v['zindex'];
  906. var ctrlclass = isUndefined(v['ctrlclass']) ? '' : v['ctrlclass'];
  907. var winhandlekey = isUndefined(v['win']) ? '' : v['win'];
  908. zindex = cover ? zindex + 500 : zindex;
  909. if(typeof JSMENU['active'][layer] == 'undefined') {
  910. JSMENU['active'][layer] = [];
  911. }
  912. for(i in EXTRAFUNC['showmenu']) {
  913. try {
  914. eval(EXTRAFUNC['showmenu'][i] + '()');
  915. } catch(e) {}
  916. }
  917. if(evt == 'click' && in_array(menuid, JSMENU['active'][layer]) && mtype != 'win') {
  918. hideMenu(menuid, mtype);
  919. return;
  920. }
  921. if(mtype == 'menu') {
  922. hideMenu(layer, mtype);
  923. }
  924. if(ctrlObj) {
  925. if(!ctrlObj.getAttribute('initialized')) {
  926. ctrlObj.setAttribute('initialized', true);
  927. ctrlObj.unselectable = true;
  928. ctrlObj.outfunc = typeof ctrlObj.onmouseout == 'function' ? ctrlObj.onmouseout : null;
  929. ctrlObj.onmouseout = function() {
  930. if(this.outfunc) this.outfunc();
  931. if(duration < 3 && !JSMENU['timer'][menuid]) {
  932. JSMENU['timer'][menuid] = setTimeout(function () {
  933. hideMenu(menuid, mtype);
  934. }, timeout);
  935. }
  936. };
  937. ctrlObj.overfunc = typeof ctrlObj.onmouseover == 'function' ? ctrlObj.onmouseover : null;
  938. ctrlObj.onmouseover = function(e) {
  939. doane(e);
  940. if(this.overfunc) this.overfunc();
  941. if(evt == 'click') {
  942. clearTimeout(JSMENU['timer'][menuid]);
  943. JSMENU['timer'][menuid] = null;
  944. } else {
  945. for(var i in JSMENU['timer']) {
  946. if(JSMENU['timer'][i]) {
  947. clearTimeout(JSMENU['timer'][i]);
  948. JSMENU['timer'][i] = null;
  949. }
  950. }
  951. }
  952. };
  953. }
  954. }
  955. if(!menuObj.getAttribute('initialized')) {
  956. menuObj.setAttribute('initialized', true);
  957. menuObj.ctrlkey = ctrlid;
  958. menuObj.mtype = mtype;
  959. menuObj.layer = layer;
  960. menuObj.cover = cover;
  961. if(ctrlObj && ctrlObj.getAttribute('fwin')) {menuObj.scrolly = true;}
  962. menuObj.style.position = 'absolute';
  963. menuObj.style.zIndex = zindex + layer;
  964. menuObj.onclick = function(e) {
  965. return doane(e, 0, 1);
  966. };
  967. if(duration < 3) {
  968. if(duration > 1) {
  969. menuObj.onmouseover = function() {
  970. clearTimeout(JSMENU['timer'][menuid]);
  971. JSMENU['timer'][menuid] = null;
  972. };
  973. }
  974. if(duration != 1) {
  975. menuObj.onmouseout = function() {
  976. JSMENU['timer'][menuid] = setTimeout(function () {
  977. hideMenu(menuid, mtype);
  978. }, timeout);
  979. };
  980. }
  981. }
  982. if(cover) {
  983. var coverObj = document.createElement('div');
  984. coverObj.id = menuid + '_cover';
  985. coverObj.style.position = 'absolute';
  986. coverObj.style.zIndex = menuObj.style.zIndex - 1;
  987. coverObj.style.left = coverObj.style.top = '0px';
  988. coverObj.style.width = '100%';
  989. coverObj.style.height = Math.max(document.documentElement.clientHeight, document.body.offsetHeight) + 'px';
  990. coverObj.style.backgroundColor = 'transparent';
  991. coverObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
  992. coverObj.style.opacity = 0;
  993. coverObj.onclick = function () { hideMenu(); };
  994. $$('append_parent').appendChild(coverObj);
  995. _attachEvent(window, 'load', function () {
  996. coverObj.style.height = Math.max(document.documentElement.clientHeight, document.body.offsetHeight) + 'px';
  997. }, document);
  998. }
  999. }
  1000. if(drag) {
  1001. dragobj.style.cursor = 'move';
  1002. dragobj.onmousedown = function(event) {try{dragMenu(menuObj, event, 1);}catch(e){}};
  1003. }
  1004. if(cover) $$(menuid + '_cover').style.display = '';
  1005. if(fade) {
  1006. var O = 0;
  1007. var fadeIn = function(O) {
  1008. if(O > 100) {
  1009. clearTimeout(fadeInTimer);
  1010. return;
  1011. }
  1012. menuObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + O + ')';
  1013. menuObj.style.opacity = O / 100;
  1014. O += 20;
  1015. var fadeInTimer = setTimeout(function () {
  1016. fadeIn(O);
  1017. }, 40);
  1018. };
  1019. fadeIn(O);
  1020. menuObj.fade = true;
  1021. } else {
  1022. menuObj.fade = false;
  1023. }
  1024. menuObj.style.display = '';
  1025. if(ctrlObj && ctrlclass) {
  1026. ctrlObj.className += ' ' + ctrlclass;
  1027. menuObj.setAttribute('ctrlid', ctrlid);
  1028. menuObj.setAttribute('ctrlclass', ctrlclass);
  1029. }
  1030. if(pos != '*') {
  1031. setMenuPosition(showid, menuid, pos);
  1032. }
  1033. if(BROWSER.ie && BROWSER.ie < 7 && winhandlekey && $$('fwin_' + winhandlekey)) {
  1034. $$(menuid).style.left = (parseInt($$(menuid).style.left) - parseInt($$('fwin_' + winhandlekey).style.left)) + 'px';
  1035. $$(menuid).style.top = (parseInt($$(menuid).style.top) - parseInt($$('fwin_' + winhandlekey).style.top)) + 'px';
  1036. }
  1037. if(maxh && menuObj.scrollHeight > maxh) {
  1038. menuObj.style.height = maxh + 'px';
  1039. if(BROWSER.opera) {
  1040. menuObj.style.overflow = 'auto';
  1041. } else {
  1042. menuObj.style.overflowY = 'auto';
  1043. }
  1044. }
  1045. if(!duration) {
  1046. setTimeout('hideMenu(\'' + menuid + '\', \'' + mtype + '\')', timeout);
  1047. }
  1048. if(!in_array(menuid, JSMENU['active'][layer])) JSMENU['active'][layer].push(menuid);
  1049. menuObj.cache = cache;
  1050. if(layer > JSMENU['layer']) {
  1051. JSMENU['layer'] = layer;
  1052. }
  1053. }
  1054. var dragMenuDisabled = false;
  1055. function dragMenu(menuObj, e, op) {
  1056. e = e ? e : window.event;
  1057. if(op == 1) {
  1058. if(dragMenuDisabled || in_array(e.target ? e.target.tagName : e.srcElement.tagName, ['TEXTAREA', 'INPUT', 'BUTTON', 'SELECT'])) {
  1059. return;
  1060. }
  1061. JSMENU['drag'] = [e.clientX, e.clientY];
  1062. JSMENU['drag'][2] = parseInt(menuObj.style.left);
  1063. JSMENU['drag'][3] = parseInt(menuObj.style.top);
  1064. document.onmousemove = function(e) {try{dragMenu(menuObj, e, 2);}catch(err){}};
  1065. document.onmouseup = function(e) {try{dragMenu(menuObj, e, 3);}catch(err){}};
  1066. doane(e);
  1067. }else if(op == 2 && JSMENU['drag'][0]) {
  1068. var menudragnow = [e.clientX, e.clientY];
  1069. menuObj.style.left = (JSMENU['drag'][2] + menudragnow[0] - JSMENU['drag'][0]) + 'px';
  1070. menuObj.style.top = (JSMENU['drag'][3] + menudragnow[1] - JSMENU['drag'][1]) + 'px';
  1071. menuObj.removeAttribute('top_');menuObj.removeAttribute('left_');
  1072. doane(e);
  1073. }else if(op == 3) {
  1074. JSMENU['drag'] = [];
  1075. document.onmousemove = null;
  1076. document.onmouseup = null;
  1077. }
  1078. }
  1079. function setMenuPosition(showid, menuid, pos) {
  1080. var showObj = $$(showid);
  1081. var menuObj = menuid ? $$(menuid) : $$(showid + '_menu');
  1082. if(isUndefined(pos) || !pos) pos = '43';
  1083. var basePoint = parseInt(pos.substr(0, 1));
  1084. var direction = parseInt(pos.substr(1, 1));
  1085. var important = pos.indexOf('!') != -1 ? 1 : 0;
  1086. 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;
  1087. if(!menuObj || (basePoint > 0 && !showObj)) return;
  1088. if(showObj) {
  1089. sxy = fetchOffset(showObj);
  1090. sx = sxy['left'];
  1091. sy = sxy['top'];
  1092. sw = showObj.offsetWidth;
  1093. sh = showObj.offsetHeight;
  1094. }
  1095. mw = menuObj.offsetWidth;
  1096. mcw = menuObj.clientWidth;
  1097. mh = menuObj.offsetHeight;
  1098. mch = menuObj.clientHeight;
  1099. switch(basePoint) {
  1100. case 1:
  1101. bpl = sx;
  1102. bpt = sy;
  1103. break;
  1104. case 2:
  1105. bpl = sx + sw;
  1106. bpt = sy;
  1107. break;
  1108. case 3:
  1109. bpl = sx + sw;
  1110. bpt = sy + sh;
  1111. break;
  1112. case 4:
  1113. bpl = sx;
  1114. bpt = sy + sh;
  1115. break;
  1116. }
  1117. switch(direction) {
  1118. case 0:
  1119. menuObj.style.left = (document.body.clientWidth - menuObj.clientWidth) / 2 + 'px';
  1120. mt = (document.documentElement.clientHeight - menuObj.clientHeight) / 2;
  1121. break;
  1122. case 1:
  1123. ml = bpl - mw;
  1124. mt = bpt - mh;
  1125. break;
  1126. case 2:
  1127. ml = bpl;
  1128. mt = bpt - mh;
  1129. break;
  1130. case 3:
  1131. ml = bpl;
  1132. mt = bpt;
  1133. break;
  1134. case 4:
  1135. ml = bpl - mw;
  1136. mt = bpt;
  1137. break;
  1138. }
  1139. var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  1140. var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
  1141. if(!important) {
  1142. if(in_array(direction, [1, 4]) && ml < 0) {
  1143. ml = bpl;
  1144. if(in_array(basePoint, [1, 4])) ml += sw;
  1145. } else if(ml + mw > scrollLeft + document.body.clientWidth && sx >= mw) {
  1146. ml = bpl - mw;
  1147. if(in_array(basePoint, [2, 3])) {
  1148. ml -= sw;
  1149. } else if(basePoint == 4) {
  1150. ml += sw;
  1151. }
  1152. }
  1153. if(in_array(direction, [1, 2]) && mt < 0) {
  1154. mt = bpt;
  1155. if(in_array(basePoint, [1, 2])) mt += sh;
  1156. } else if(mt + mh > scrollTop + document.documentElement.clientHeight && sy >= mh) {
  1157. mt = bpt - mh;
  1158. if(in_array(basePoint, [3, 4])) mt -= sh;
  1159. }
  1160. }
  1161. if(pos.substr(0, 3) == '210') {
  1162. ml += 69 - sw / 2;
  1163. mt -= 5;
  1164. if(showObj.tagName == 'TEXTAREA') {
  1165. ml -= sw / 2;
  1166. mt += sh / 2;
  1167. }
  1168. }
  1169. if(direction == 0 || menuObj.scrolly) {
  1170. if(BROWSER.ie && BROWSER.ie < 7) {
  1171. if(direction == 0) mt += scrollTop;
  1172. } else {
  1173. if(menuObj.scrolly) mt -= scrollTop;
  1174. menuObj.style.position = 'fixed';
  1175. }
  1176. }
  1177. if(ml) menuObj.style.left = ml + 'px';
  1178. if(mt) menuObj.style.top = mt + 'px';
  1179. if(direction == 0 && BROWSER.ie && !document.documentElement.clientHeight) {
  1180. menuObj.style.position = 'absolute';
  1181. menuObj.style.top = (document.body.clientHeight - menuObj.clientHeight) / 2 + 'px';
  1182. }
  1183. if(menuObj.style.clip && !BROWSER.opera) {
  1184. menuObj.style.clip = 'rect(auto, auto, auto, auto)';
  1185. }
  1186. }
  1187. function hideMenu(attr, mtype) {
  1188. attr = isUndefined(attr) ? '' : attr;
  1189. mtype = isUndefined(mtype) ? 'menu' : mtype;
  1190. if(attr == '') {
  1191. for(var i = 1; i <= JSMENU['layer']; i++) {
  1192. hideMenu(i, mtype);
  1193. }
  1194. return;
  1195. } else if(typeof attr == 'number') {
  1196. for(var j in JSMENU['active'][attr]) {
  1197. hideMenu(JSMENU['active'][attr][j], mtype);
  1198. }
  1199. return;
  1200. }else if(typeof attr == 'string') {
  1201. var menuObj = $$(attr);
  1202. if(!menuObj || (mtype && menuObj.mtype != mtype)) return;
  1203. var ctrlObj = '', ctrlclass = '';
  1204. if((ctrlObj = $$(menuObj.getAttribute('ctrlid'))) && (ctrlclass = menuObj.getAttribute('ctrlclass'))) {
  1205. var reg = new RegExp(' ' + ctrlclass);
  1206. ctrlObj.className = ctrlObj.className.replace(reg, '');
  1207. }
  1208. clearTimeout(JSMENU['timer'][attr]);
  1209. var hide = function() {
  1210. if(menuObj.cache) {
  1211. if(menuObj.style.visibility != 'hidden') {
  1212. menuObj.style.display = 'none';
  1213. if(menuObj.cover) $$(attr + '_cover').style.display = 'none';
  1214. }
  1215. }else {
  1216. menuObj.parentNode.removeChild(menuObj);
  1217. if(menuObj.cover) $$(attr + '_cover').parentNode.removeChild($$(attr + '_cover'));
  1218. }
  1219. var tmp = [];
  1220. for(var k in JSMENU['active'][menuObj.layer]) {
  1221. if(attr != JSMENU['active'][menuObj.layer][k]) tmp.push(JSMENU['active'][menuObj.layer][k]);
  1222. }
  1223. JSMENU['active'][menuObj.layer] = tmp;
  1224. };
  1225. if(menuObj.fade) {
  1226. var O = 100;
  1227. var fadeOut = function(O) {
  1228. if(O == 0) {
  1229. clearTimeout(fadeOutTimer);
  1230. hide();
  1231. return;
  1232. }
  1233. menuObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + O + ')';
  1234. menuObj.style.opacity = O / 100;
  1235. O -= 20;
  1236. var fadeOutTimer = setTimeout(function () {
  1237. fadeOut(O);
  1238. }, 40);
  1239. };
  1240. fadeOut(O);
  1241. } else {
  1242. hide();
  1243. }
  1244. }
  1245. }
  1246. function getCurrentStyle(obj, cssproperty, csspropertyNS) {
  1247. if(obj.style[cssproperty]){
  1248. return obj.style[cssproperty];
  1249. }
  1250. if (obj.currentStyle) {
  1251. return obj.currentStyle[cssproperty];
  1252. } else if (document.defaultView.getComputedStyle(obj, null)) {
  1253. var currentStyle = document.defaultView.getComputedStyle(obj, null);
  1254. var value = currentStyle.getPropertyValue(csspropertyNS);
  1255. if(!value){
  1256. value = currentStyle[cssproperty];
  1257. }
  1258. return value;
  1259. } else if (window.getComputedStyle) {
  1260. var currentStyle = window.getComputedStyle(obj, "");
  1261. return currentStyle.getPropertyValue(csspropertyNS);
  1262. }
  1263. }
  1264. function fetchOffset(obj, mode) {
  1265. var left_offset = 0, top_offset = 0, mode = !mode ? 0 : mode;
  1266. if(obj.getBoundingClientRect && !mode) {
  1267. var rect = obj.getBoundingClientRect();
  1268. var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  1269. var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
  1270. if(document.documentElement.dir == 'rtl') {
  1271. scrollLeft = scrollLeft + document.documentElement.clientWidth - document.documentElement.scrollWidth;
  1272. }
  1273. left_offset = rect.left + scrollLeft - document.documentElement.clientLeft;
  1274. top_offset = rect.top + scrollTop - document.documentElement.clientTop;
  1275. }
  1276. if(left_offset <= 0 || top_offset <= 0) {
  1277. left_offset = obj.offsetLeft;
  1278. top_offset = obj.offsetTop;
  1279. while((obj = obj.offsetParent) != null) {
  1280. position = getCurrentStyle(obj, 'position', 'position');
  1281. if(position == 'relative') {
  1282. continue;
  1283. }
  1284. left_offset += obj.offsetLeft;
  1285. top_offset += obj.offsetTop;
  1286. }
  1287. }
  1288. return {'left' : left_offset, 'top' : top_offset};
  1289. }
  1290. var showDialogST = null;
  1291. function showDialog(msg, mode, t, func, cover, funccancel, leftmsg, confirmtxt, canceltxt, closetime, locationtime) {
  1292. if (mode == 'js'){
  1293. eval(func);
  1294. hideMenu(null, 'dialog');
  1295. return ;
  1296. }
  1297. clearTimeout(showDialogST);
  1298. cover = isUndefined(cover) ? (mode == 'info' ? 0 : 1) : cover;
  1299. leftmsg = isUndefined(leftmsg) ? '' : leftmsg;
  1300. mode = in_array(mode, ['confirm', 'notice', 'info', 'succ']) ? mode : 'alert';
  1301. var menuid = 'fwin_dialog';
  1302. var menuObj = $$(menuid);
  1303. var showconfirm = 1;
  1304. confirmtxtdefault = '确定';
  1305. closetime = isUndefined(closetime) ? '' : closetime;
  1306. closefunc = function () {
  1307. if(typeof func == 'function') func();
  1308. else eval(func);
  1309. hideMenu(menuid, 'dialog');
  1310. };
  1311. if(closetime) {
  1312. leftmsg = closetime + ' 秒后窗口关闭';
  1313. showDialogST = setTimeout(closefunc, closetime * 1000);
  1314. showconfirm = 0;
  1315. }
  1316. locationtime = isUndefined(locationtime) ? '' : locationtime;
  1317. if(locationtime) {
  1318. leftmsg = locationtime + ' 秒后页面跳转';
  1319. showDialogST = setTimeout(closefunc, locationtime * 1000);
  1320. showconfirm = 0;
  1321. }
  1322. confirmtxt = confirmtxt ? confirmtxt : confirmtxtdefault;
  1323. canceltxt = canceltxt ? canceltxt : '取消';
  1324. if(menuObj) hideMenu('fwin_dialog', 'dialog');
  1325. menuObj = document.createElement('div');
  1326. menuObj.style.display = 'none';
  1327. menuObj.className = 'dialog_body';
  1328. menuObj.id = menuid;
  1329. $$('append_parent').appendChild(menuObj);
  1330. var hidedom = '';
  1331. if(!BROWSER.ie) {
  1332. hidedom = '<style type="text/css">object{visibility:hidden;}</style>';
  1333. }
  1334. var s = hidedom + '<h3 class="dialog_head"><span class="dialog_title">';
  1335. s += t ? t : '<span class="dialog_title_icon">提示信息</span>';
  1336. s += '</span><span class="dialog_close_button" id="fwin_dialog_close" onclick="hideMenu(\'' + menuid + '\', \'dialog\')" title="关闭">X</span></h3>';
  1337. if(mode == 'info') {
  1338. s += msg ? msg : '';
  1339. } else {
  1340. s += '<div class="eject_con"><div class="dialog_message_contents">';
  1341. s += '<i class="' + (mode == 'alert' ? 'alert_error' : (mode == 'succ' ? 'alert_right' : 'alert_info')) + '"></i>' + msg + '</div></div>';
  1342. 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>' : '');
  1343. s += mode == 'confirm' ? '<a href="javascript:void(0)" id="fwin_dialog_cancel" class="dialog-bottom-btn" onclick="hideMenu(\'' + menuid + '\', \'dialog\')">'+canceltxt+'</a>' : '';
  1344. s += '</div>';
  1345. }
  1346. menuObj.innerHTML = s;
  1347. if($$('fwin_dialog_submit')) $$('fwin_dialog_submit').onclick = function() {
  1348. if(typeof func == 'function') func();
  1349. else eval(func);
  1350. hideMenu(menuid, 'dialog');
  1351. };
  1352. if($$('fwin_dialog_cancel')) {
  1353. $$('fwin_dialog_cancel').onclick = function() {
  1354. if(typeof funccancel == 'function') funccancel();
  1355. else eval(funccancel);
  1356. hideMenu(menuid, 'dialog');
  1357. };
  1358. $$('fwin_dialog_close').onclick = $$('fwin_dialog_cancel').onclick;
  1359. }
  1360. showMenu({'mtype':'dialog','menuid':menuid,'duration':3,'pos':'00','zindex':JSMENU['zIndex']['dialog'],'cache':0,'cover':cover});
  1361. try {
  1362. if($$('fwin_dialog_submit')) $$('fwin_dialog_submit').focus();
  1363. } catch(e) {}
  1364. }
  1365. function showSucc(msg) {
  1366. var p = /<script[^\>]*?>([^\x00]*?)<\/script>/ig;
  1367. msg = msg.replace(p, '');
  1368. if(msg !== '') {
  1369. showDialog(msg, 'succ', '提示信息', null, true, null, '', '', '', 3);
  1370. }
  1371. }
  1372. function showError(msg) {
  1373. var p = /<script[^\>]*?>([^\x00]*?)<\/script>/ig;
  1374. msg = msg.replace(p, '');
  1375. if(msg !== '') {
  1376. showDialog(msg, 'alert', '错误信息', null, true, null, '', '', '', 3);
  1377. }
  1378. }
  1379. function hideWindow(k, all, clear) {
  1380. all = isUndefined(all) ? 1 : all;
  1381. clear = isUndefined(clear) ? 1 : clear;
  1382. hideMenu('fwin_' + k, 'win');
  1383. if(clear && $$('fwin_' + k)) {
  1384. $$('append_parent').removeChild($$('fwin_' + k));
  1385. }
  1386. if(all) {
  1387. hideMenu();
  1388. }
  1389. }
  1390. function ajax_get_confirm(msg, url){
  1391. if (msg != ''){
  1392. showDialog(msg, 'confirm', '', function(){ajaxget(url);});
  1393. }else{
  1394. ajaxget(url);
  1395. }
  1396. }
  1397. function get_confirm(msg, url){
  1398. if(msg != ''){
  1399. showDialog(msg, 'confirm', '', function(){ window.location = url;});
  1400. }else{
  1401. window.location = url;
  1402. }
  1403. }