39f15280966a35f745f273f47c9d1f8d62c33b32.svn-base 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * 显示加载中控件 2016/8/9 康国前加
  3. */
  4. ;(function($,window,document,undefined) {
  5. $.extend({
  6. /**
  7. * 获取加载中不同的样式
  8. */
  9. getLoadingCSS : function(idx,loadingText){
  10. var result = "";
  11. switch (idx){
  12. case 1 ://系统加载样式一
  13. result = {
  14. 'loadingBgClass':'work-loading-bg',
  15. 'loadingBoxClass':'work-loading-box',
  16. 'loadingText':loadingText ==null ?"页面加载中...":loadingText
  17. //'loadingHtml':'<span>页面加载中...</span>'
  18. };
  19. break;
  20. case 2 ://系统加载样式二
  21. result = {
  22. 'loadingBgClass':'single-loading-bg',
  23. 'loadingBoxClass':'single-loading-box',
  24. 'loadingText':loadingText
  25. };
  26. }
  27. return result;
  28. }
  29. });
  30. var IndexLoading = function (ele,opts){
  31. this.$loadingBg,
  32. this.$loadingBox,
  33. this.$ele = ele,
  34. this.defaults = {
  35. 'loadingBgClass':'idxModule-loading-bg',
  36. 'loadingBoxClass':'idxModule-loading-box',
  37. 'loadingHtml':'',
  38. 'loadingText':'正在加载中...'
  39. },
  40. this.options = $.extend({},this.defaults,opts);
  41. };
  42. IndexLoading.prototype = {
  43. init:function(){
  44. if(this.$ele.find("."+this.options.loadingBgClass).length!=0){
  45. this.$loadingBg = this.$ele.find("."+this.options.loadingBgClass).last();
  46. this.$loadingBox = this.$ele.find("."+this.options.loadingBoxClass).last();
  47. }else{
  48. var loadHtml = '<span>'+this.options.loadingText+'</span>';
  49. if(this.options.loadingHtml && this.options.loadingHtml!=null && this.options.loadingHtml!=""){
  50. loadHtml = this.options.loadingHtml;
  51. }
  52. this.$loadingBg = $('<div class="'+this.options.loadingBgClass+'" ></div>');
  53. this.$loadingBox = $('<div class="'+this.options.loadingBoxClass+'">'+loadHtml+'</div>');
  54. this.$ele.append(this.$loadingBg).append(this.$loadingBox);
  55. };
  56. },
  57. destroy:function(){//释放节点所占内存
  58. this.$loadingBg = null;
  59. this.$loadingBox = null;
  60. this.$ele = null;
  61. },
  62. show:function(){
  63. return this.$loadingBg.css({'display':'block'}),this.$loadingBox.css({'display':'block'}),this.destroy();
  64. },
  65. hide:function(){
  66. return this.$loadingBg.css({'display':'none'}),this.$loadingBox.css({'display':'none'}),this.destroy();
  67. }
  68. };
  69. $.fn.indexLoading = function (options){
  70. var indexLoad = new IndexLoading(this,options);
  71. indexLoad.init();
  72. return indexLoad;
  73. };
  74. })(jQuery,window,document);