member_common.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. * 会员中心公用js
  3. *
  4. */
  5. /**
  6. * 隐藏html element
  7. */
  8. function hide_element(name) {
  9. $('#'+name+'').fadeOut("slow");
  10. }
  11. /**
  12. * 显示html element
  13. */
  14. function show_element(name) {
  15. $('#'+name+'').fadeIn("slow");
  16. }
  17. $(document).ready(function(){
  18.   $("input.input-text").blur(function () { this.className='input-text'; } );
  19.   $(":text").focus(function(){this.className='input-focus';});
  20. });
  21. /**
  22. * url跳转
  23. */
  24. function redirect(url) {
  25. if(url.indexOf('://') == -1 && url.substr(0, 1) != '/' && url.substr(0, 1) != '?') url = $('base').attr('href')+url;
  26. location.href = url;
  27. }
  28. function thumb_images(uploadid,returnid) {
  29. var d = window.top.art.dialog({id:uploadid}).data.iframe;
  30. var in_content = d.$("#att-status").html().substring(1);
  31. if(in_content=='') return false;
  32. if($('#'+returnid+'_preview').attr('src')) {
  33. $('#'+returnid+'_preview').attr('src',in_content);
  34. }
  35. $('#'+returnid).val(in_content);
  36. }
  37. function change_images(uploadid,returnid){
  38. var d = window.top.art.dialog({id:uploadid}).data.iframe;
  39. var in_content = d.$("#att-status").html().substring(1);
  40. var str = $('#'+returnid).html();
  41. var contents = in_content.split('|');
  42. $('#'+returnid+'_tips').css('display','none');
  43. $.each( contents, function(i, n) {
  44. var ids = parseInt(Math.random() * 10000 + 10*i);
  45. str += "<div id='image"+ids+"'><input type='text' name='"+returnid+"_url[]' value='"+n+"' style='width:360px;' ondblclick='image_priview(this.value);' class='input-text'> <input type='text' name='"+returnid+"_alt[]' value='图片说明"+(i+1)+"' style='width:100px;' class='input-text' onfocus=\"if(this.value == this.defaultValue) this.value = ''\" onblur=\"if(this.value.replace(' ','') == '') this.value = this.defaultValue;\"> <a href=\"javascript:remove_div('image"+ids+"')\">移除</a> </div><div class='bk10'></div>";
  46. });
  47. $('#'+returnid).html(str);
  48. }
  49. function image_priview(img) {
  50. window.top.art.dialog({title:'图片查看',fixed:true, content:'<img src="'+img+'" />',id:'image_priview',time:5});
  51. }
  52. function remove_div(id) {
  53. $('#'+id).html(' ');
  54. }
  55. function select_catids() {
  56. $('#addbutton').attr('disabled',false);
  57. }
  58. //商业用户会添加 num,普通用户默认为5
  59. function transact(update,fromfiled,tofiled, num) {
  60. if(update=='delete') {
  61. var fieldvalue = $('#'+tofiled).val();
  62. $("#"+tofiled+" option").each(function() {
  63. if($(this).val() == fieldvalue){
  64. $(this).remove();
  65. }
  66. });
  67. } else {
  68. var fieldvalue = $('#'+fromfiled).val();
  69. var have_exists = 0;
  70. var len = $("#"+tofiled+" option").size();
  71. if(len>=num) {
  72. alert('最多添加 '+num+' 项');
  73. return false;
  74. }
  75. $("#"+tofiled+" option").each(function() {
  76. if($(this).val() == fieldvalue){
  77. have_exists = 1;
  78. alert('已经添加到列表中');
  79. return false;
  80. }
  81. });
  82. if(have_exists==0) {
  83. obj = $('#'+fromfiled+' option:selected');
  84. text = obj.text();
  85. text = text.replace('│', '');
  86. text = text.replace('├ ', '');
  87. text = text.replace('└ ', '');
  88. text = text.trim();
  89. fieldvalue = "<option value='"+fieldvalue+"'>"+text+"</option>"
  90. $('#'+tofiled).append(fieldvalue);
  91. $('#deletebutton').attr('disabled','');
  92. }
  93. }
  94. }
  95. function omnipotent(id,linkurl,title,close_type,w,h) {
  96. if(!w) w=700;
  97. if(!h) h=500;
  98. art.dialog({id:id,iframe:linkurl, title:title, width:w, height:h, lock:true},
  99. function(){
  100. if(close_type==1) {
  101. art.dialog({id:id}).close()
  102. } else {
  103. var d = art.dialog({id:id}).data.iframe;
  104. var form = d.document.getElementById('dosubmit');form.click();
  105. }
  106. return false;
  107. },
  108. function(){
  109. art.dialog({id:id}).close()
  110. });void(0);
  111. }
  112. String.prototype.trim = function() {
  113. var str = this,
  114. whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
  115. for (var i = 0,len = str.length; i < len; i++) {
  116. if (whitespace.indexOf(str.charAt(i)) === -1) {
  117. str = str.substring(i);
  118. break;
  119. }
  120. }
  121. for (i = str.length - 1; i >= 0; i--) {
  122. if (whitespace.indexOf(str.charAt(i)) === -1) {
  123. str = str.substring(0, i + 1);
  124. break;
  125. }
  126. }
  127. return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
  128. }