hkclient.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. var hkclient = new Object();
  2. var errorbox = null;
  3. var errorInfo = null;
  4. //显示加载器
  5. function showLoader() {
  6. //显示加载器.for jQuery Mobile 1.2.0
  7. $.mobile.loading('show', {
  8. text: "", //加载器中显示的文字
  9. textVisible: true, //是否显示文字
  10. theme: 'a', //加载器主题样式a-e
  11. textonly: false, //是否只显示文字
  12. html: "" //要显示的html内容,如图片等
  13. });
  14. }
  15. //隐藏加载器.for jQuery Mobile 1.2.0
  16. function hideLoader() {
  17. //隐藏加载器
  18. $.mobile.loading('hide');
  19. }
  20. hkclient.loadMobilePage = function (id, url, param, callback) {
  21. var obj = $("#" + id);
  22. //showLoader();
  23. var loadDivObj = jQuery('<div><table cellspacing="0" cellpadding="0" height="60"><tr><td width="29%" ><div align="right"><img src="images/progress.gif" /><div><td><td></td></tr></table></div>');
  24. obj.empty().append(loadDivObj);
  25. if (typeof(param) == 'undefined') {
  26. jQuery.ajaxSetup({
  27. cache: false
  28. });
  29. }
  30. obj.load(url, param, function () {
  31. //hideLoader();
  32. loadDivObj.hide("slow");
  33. if (callback) {
  34. callback();
  35. }
  36. });
  37. };
  38. hkclient.showError = function (errorMsg) {
  39. if (errorbox != null && errorInfo != null) {
  40. errorInfo.empty();
  41. jQuery('<div align="right"><img onclick="huimv.closeError();" src="images/close.gif" width="44" height="20"></div>')
  42. .appendTo(errorInfo);
  43. jQuery(errorMsg).appendTo(errorInfo);
  44. errorInfo.show();
  45. errorbox.show();
  46. return;
  47. }
  48. var errorDiv = document.createElement("div");
  49. errorDiv.id = "errorBox";
  50. errorDiv.style.cssText = "position:absolute;left:0px;display:none;top:0px;width:100%;background:#dddddd;text-align:center;filter:Alpha(Opacity=50,Style=0);opacity:0.4";
  51. errorDiv.style.height = ((document.documentElement.clientHeight > document.documentElement.scrollHeight)
  52. ? document.documentElement.clientHeight
  53. : document.documentElement.scrollHeight)
  54. + "px";
  55. var errorInfoDiv = document.createElement("div");
  56. errorInfoDiv.id = "errorInfoDiv";
  57. errorInfoDiv.style.cssText = "position:absolute;width:800px;height:auto;text-align:center;z-index:10001;border: 1px #1fa700 solid;top:"
  58. + (+50 + document.documentElement.scrollTop)
  59. + "px"
  60. + ";left:10%;font-size: 14px;background: url(images/load_bg.gif) repeat-x #ffffff;";
  61. jQuery('<div align="right"><img onclick="huimv.closeError();" src="images/close.gif" width="44" height="20"></div>')
  62. .appendTo(errorInfoDiv);
  63. jQuery(errorMsg).appendTo(errorInfoDiv);
  64. // 解决遮住下拉框
  65. var iframeHTML = '<IFRAME style="DISPLAY: block; Z-INDEX: -1; FILTER: alpha(opacity=0); LEFT: 0px; WIDTH: 100%; ZOOM: 1; POSITION: absolute; TOP: 0px; HEIGHT: 100%" src="javascript:false;document.write(\'\')" frameborder="0" scrolling="no"></IFRAME>';
  66. document.body.appendChild(errorInfoDiv);
  67. document.body.appendChild(errorDiv);
  68. errorbox = jQuery(errorDiv);
  69. errorbox.css('zIndex', (++huimvMaxIndex));
  70. errorInfo = jQuery(errorInfoDiv);
  71. errorbox.append(iframeHTML);
  72. errorInfo.show();
  73. errorbox.show();
  74. };
  75. hkclient.closeError = function () {
  76. errorbox.hide();
  77. errorInfo.hide();
  78. };
  79. hkclient.alertBanner = {
  80. alertTimer: undefined,
  81. alertFragment: document.createDocumentFragment(),
  82. t: 3000,
  83. /**
  84. * @description rise the alertBanner and then vanish
  85. * @param {string} status 状态
  86. * @param {number} t 定时时长,可选,默认3秒
  87. * @param msg 警告栏的内容
  88. * @return 浮现警告栏并自动消失
  89. */
  90. riseAlert: function (status, t, msg) {
  91. clearTimeout(this.alertTimer);
  92. $('.alert').remove();
  93. var alertDiv = document.createElement('DIV');
  94. alertDiv.id = 'alertBanner';
  95. if (!msg) {
  96. if (status) {
  97. msg = "保存成功";
  98. } else {
  99. msg = "保存失败";
  100. }
  101. }
  102. if (status) {
  103. alertDiv.className = 'alert alert-success fade in';
  104. alertDiv.innerHTML = msg;
  105. } else {
  106. alertDiv.className = 'alert alert-danger fade in';
  107. alertDiv.innerHTML = msg;
  108. }
  109. this.alertFragment.appendChild(alertDiv);
  110. document.body.appendChild(this.alertFragment);
  111. if (!t) {
  112. t = this.t;
  113. }
  114. this.alertTimer = setTimeout(function () {
  115. $('.alert').remove();
  116. }, t);
  117. }
  118. };