cross.ui.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * cross ui_form.js
  3. */
  4. $(function(){
  5. $.fn.formFocus = function (){
  6. var $this = $(this);
  7. if($this.parents('.input-group').find('span.input-group-addon').length>0 && $this.attr('data-form')=="focus"){
  8. $span = $this.parents('.input-group').find('span.input-group-addon');
  9. $span.addClass('focus');
  10. $this.on('blur',function(){
  11. $span.removeClass('focus');
  12. });
  13. }
  14. if($this.attr('data-form')=="clear"){
  15. var $clear = $('<div class="input-clear"></div>').insertAfter($this);
  16. $this.on('blur',function(){
  17. setTimeout(function(){$clear.remove();},200);
  18. });
  19. $clear.on('click',function(){
  20. $this.val('').focus();
  21. });
  22. }
  23. }
  24. $(document).on('focus','input[data-form="focus"],input[data-form="clear"]',function(){
  25. $(this).formFocus();
  26. });
  27. $('body').on('click','label.input-group-checkbox',function(e){
  28. if (e || e.preventDefault()) e.preventDefault(); else window.event.returnValue = false;
  29. var $el=$(this),
  30. $div=$el.children('.input-group-pack'),
  31. $input=$div.children(':checkbox');
  32. if($div.is('.input-group-pack-disabled')){
  33. return false;
  34. }
  35. if($div.is('.checked')) {
  36. $div.removeClass('checked');
  37. $input.prop({'checked':false});
  38. } else {
  39. $div.addClass('checked');
  40. $input.prop({'checked':true});
  41. }
  42. });
  43. $('body').on('click','label.input-group-radio',function(e){
  44. if (e || e.preventDefault()) e.preventDefault(); else window.event.returnValue = false;
  45. var $el=$(this),
  46. $div=$el.children('.input-group-pack'),
  47. $input=$div.children(':radio');
  48. if($div.is('.input-group-pack-disabled')){
  49. return false;
  50. }
  51. $el.parent().find('.input-group-radio').children('.input-group-pack').removeClass('checked').find(':radio').prop({'checked':false});
  52. $div.addClass('checked');
  53. $input.prop({'checked':true});
  54. });
  55. });
  56. var myLayer = {
  57. alert: function(content,time,callback){
  58. if($(".c-alert-box").is(":visible")){
  59. $(".c-alert-box").remove();
  60. }
  61. if(time == undefined || time == "" || time == null){
  62. time = 3000;
  63. }
  64. var ahtml = '<div class="c-alert-box">'+content+'</div><div class="c-al-screen"></div>';
  65. $("body").append(ahtml);
  66. var aleL = ($(window).width() - $(".c-alert-box").width() - 20) / 2;
  67. $(".c-alert-box").css('left', aleL + "px");
  68. setTimeout(function(){
  69. $(".c-alert-box,.c-al-screen").remove();
  70. if (callback){callback();}
  71. },time);
  72. },
  73. load: function(content){
  74. if($(".c-load-box").is(":visible")){
  75. $(".c-load-box").remove();
  76. }
  77. if(content == undefined || content == "" || content == null){
  78. content = "\u52a0\u8f7d\u4e2d..."
  79. }
  80. var lhtml = '<div class="c-load-box"><span class="loadgif"></span><p>'+content+'</p></div><div class="c-al-screen"></div>';
  81. $("body").append(lhtml);
  82. var totW = $(window).width();
  83. var aleL = (totW - $(".c-load-box").width() - 60) / 2;
  84. $(".c-load-box").css('left', aleL + "px");
  85. },
  86. clear: function(){
  87. $(".c-load-box,.c-al-screen").remove();
  88. },
  89. confirm: function(options){
  90. var dft= {
  91. title:'',
  92. con:'',
  93. cancel: null,
  94. cancelValue:'\u53d6\u6d88',
  95. ok: null,
  96. okValue:'\u786e\u5b9a'
  97. }
  98. var ops = $.extend(dft,options);
  99. var chtml = '<div class="c-conf-screen"></div>';
  100. chtml += '<div class="c-conf-box">';
  101. if(ops.title != ""){
  102. chtml += '<div class="conftitle">'+ops.title+'</div>';
  103. }
  104. chtml += '<div class="confcontent">'+ops.con+'</div>';
  105. if(ops.cancel != null){
  106. chtml += '<div class="c-confbtn"><a href="javascript:;" class="c-twobtn" id="popcanclebtn">'+ops.cancelValue+'</a><a href="javascript:;" class="c-twobtn" id="popsurebtn">'+ops.okValue+'</a></div>';
  107. }else{
  108. chtml += '<div class="c-confbtn"><a href="javascript:;" class="c-onebtn" id="popsurebtn">'+ops.okValue+'</a></div>';
  109. }
  110. chtml += '</div></div>';
  111. $("body").append(chtml);
  112. var aleT = ($(".c-conf-box").height() + 15) / 2;
  113. $(".c-conf-box").css('margin-top', -aleT);
  114. $("#popcanclebtn").click(function(){
  115. if (ops.cancel){ops.cancel();}
  116. $(".c-conf-box,.c-conf-screen").remove();
  117. });
  118. $("#popsurebtn").click(function(){
  119. if (ops.ok){ops.ok();}
  120. $(".c-conf-box,.c-conf-screen").remove();
  121. });
  122. }
  123. }