content_addtop.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. var userAgent = navigator.userAgent.toLowerCase();
  2. jQuery.browser = {
  3. version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
  4. safari: /webkit/.test( userAgent ),
  5. opera: /opera/.test( userAgent ),
  6. msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
  7. mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
  8. };
  9. function thumb_images(uploadid,returnid) {
  10. var d = window.top.art.dialog({id:uploadid}).data.iframe;
  11. var in_content = d.$("#att-status").html().substring(1);
  12. if(in_content=='') return false;
  13. if(!IsImg(in_content)) {
  14. alert('选择的类型必须为图片类型');
  15. return false;
  16. }
  17. if($('#'+returnid+'_preview').attr('src')) {
  18. $('#'+returnid+'_preview').attr('src',in_content);
  19. }
  20. $('#'+returnid).val(in_content);
  21. }
  22. function change_images(uploadid,returnid){
  23. var d = window.top.art.dialog({id:uploadid}).data.iframe;
  24. var in_content = d.$("#att-status").html().substring(1);
  25. var in_filename = d.$("#att-name").html().substring(1);
  26. var str = $('#'+returnid).html();
  27. var contents = in_content.split('|');
  28. var filenames = in_filename.split('|');
  29. $('#'+returnid+'_tips').css('display','none');
  30. if(contents=='') return true;
  31. $.each( contents, function(i, n) {
  32. var ids = parseInt(Math.random() * 10000 + 10*i);
  33. var filename = filenames[i].substr(0,filenames[i].indexOf('.'));
  34. str += "<li id='image"+ids+"'><input type='text' name='"+returnid+"_url[]' value='"+n+"' style='width:310px;' ondblclick='image_priview(this.value);' class='input-text'> <input type='text' name='"+returnid+"_alt[]' value='"+filename+"' style='width:160px;' 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> </li>";
  35. });
  36. $('#'+returnid).html(str);
  37. }
  38. function change_videoes(uploadid, returnid) {
  39. var d = window.top.art.dialog({id:uploadid}).data.iframe;
  40. var in_content = d.$("#video-paths").html().substring(1);
  41. var in_filename = d.$("#video-name").html().substring(1);
  42. var in_vid = d.$("#video-ids").html().substring(1);
  43. var video_num = parseInt($("#key").val());
  44. var str = $('#'+returnid).html();
  45. var contents = in_content.split('|');
  46. var fields = uploadid.split('_');
  47. var field = fields[0];
  48. var filenames = in_filename.split('|');
  49. var vids = in_vid.split('|');
  50. $('#'+returnid+'_tips').css('display','none');
  51. if(contents=='') return true;
  52. $.each( contents, function(i, n) {
  53. if ($("#thumb").val()==''){
  54. $('#thumb').val(contents[i]);
  55. $('#thumb_preview').attr('src', contents[i]);
  56. }
  57. var ids = parseInt(Math.random() * 10000 + 10*i);
  58. video_num = video_num + 1;
  59. var filename = filenames[i];
  60. str += "<li id=\"video_"+field+"_"+video_num+"\"><div class=\"r1\"><img src=\""+contents[i]+"\" width=\"132\" height=\"75\"><input type=\"text\" name=\""+field+"_video["+video_num+"][title]\" value=\""+filename+"\" class=\"input-text\"><input type='hidden' name='"+field+"_video["+video_num+"][videoid]' value='"+vids[i]+"'><div class=\"r2\"><span class=\"l\"><label>排序</label><input type='text' name='"+field+"_video["+video_num+"][listorder]' value='"+video_num+"' class=\"input-text\"></span><span class=\"r\"> <a href=\"javascript:remove_div('video_"+field+"_"+video_num+"')\">移除</a></span></li>";
  61. });
  62. $('#key').val(video_num);
  63. $('#'+returnid).html(str);
  64. }
  65. function change_multifile(uploadid,returnid){
  66. var d = window.top.art.dialog({id:uploadid}).data.iframe;
  67. var in_content = d.$("#att-status").html().substring(1);
  68. var in_filename = d.$("#att-name").html().substring(1);
  69. var str = '';
  70. var contents = in_content.split('|');
  71. var filenames = in_filename.split('|');
  72. $('#'+returnid+'_tips').css('display','none');
  73. if(contents=='') return true;
  74. $.each( contents, function(i, n) {
  75. var ids = parseInt(Math.random() * 10000 + 10*i);
  76. var filename = filenames[i].substr(0,filenames[i].indexOf('.'));
  77. str += "<li id='multifile"+ids+"'><input type='text' name='"+returnid+"_fileurl[]' value='"+n+"' style='width:310px;' class='input-text'> <input type='text' name='"+returnid+"_filename[]' value='"+filename+"' style='width:160px;' 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('multifile"+ids+"')\">移除</a> </li>";
  78. });
  79. $('#'+returnid).append(str);
  80. }
  81. function add_multifile(returnid) {
  82. var ids = parseInt(Math.random() * 10000);
  83. var str = "<li id='multifile"+ids+"'><input type='text' name='"+returnid+"_fileurl[]' value='' style='width:310px;' class='input-text'> <input type='text' name='"+returnid+"_filename[]' value='附件说明' style='width:160px;' class='input-text'> <a href=\"javascript:remove_div('multifile"+ids+"')\">移除</a> </li>";
  84. $('#'+returnid).append(str);
  85. }
  86. function set_title_color(color) {
  87. $('#title').css('color',color);
  88. $('#style_color').val(color);
  89. }
  90. //-----------------------
  91. function check_content(obj) {
  92. if($.browser.msie) {
  93. CKEDITOR.instances[obj].insertHtml('');
  94. CKEDITOR.instances[obj].focusManager.hasFocus;
  95. }
  96. top.art.dialog({id:'check_content_id'}).close();
  97. return true;
  98. }
  99. function image_priview(img) {
  100. window.top.art.dialog({title:'图片查看',fixed:true, content:'<img src="'+img+'" />',id:'image_priview',time:5});
  101. }
  102. function remove_div(id) {
  103. $('#'+id).remove();
  104. }
  105. function input_font_bold() {
  106. if($('#title').css('font-weight') == '700' || $('#title').css('font-weight')=='bold') {
  107. $('#title').css('font-weight','normal');
  108. $('#style_font_weight').val('');
  109. } else {
  110. $('#title').css('font-weight','bold');
  111. $('#style_font_weight').val('bold');
  112. }
  113. }
  114. function ruselinkurl() {
  115. if($('#islink').attr('checked')=='checked') {
  116. $('#linkurl').attr('disabled',false);
  117. var oEditor = CKEDITOR.instances.content;
  118. oEditor.insertHtml(' ');
  119. return false;
  120. } else {
  121. $('#linkurl').attr('disabled','true');
  122. }
  123. }
  124. function close_window() {
  125. if($('#title').val() !='') {
  126. art.dialog({content:'内容已经录入,确定离开将不保存数据!', fixed:true,yesText:'我要关闭',noText:'返回保存数据',style:'confirm', id:'bnt4_test'}, function(){
  127. window.close();
  128. }, function(){
  129. });
  130. } else {
  131. window.close();
  132. }
  133. return false;
  134. }
  135. function ChangeInput (objSelect,objInput) {
  136. if (!objInput) return;
  137. var str = objInput.value;
  138. var arr = str.split(",");
  139. for (var i=0; i<arr.length; i++){
  140. if(objSelect.value==arr[i])return;
  141. }
  142. if(objInput.value=='' || objInput.value==0 || objSelect.value==0){
  143. objInput.value=objSelect.value
  144. }else{
  145. objInput.value+=','+objSelect.value
  146. }
  147. }
  148. //移除相关文章
  149. function remove_relation(sid,id) {
  150. var relation_ids = $('#relation').val();
  151. if(relation_ids !='' ) {
  152. $('#'+sid).remove();
  153. var r_arr = relation_ids.split('|');
  154. var newrelation_ids = '';
  155. $.each(r_arr, function(i, n){
  156. if(n!=id) {
  157. if(i==0) {
  158. newrelation_ids = n;
  159. } else {
  160. newrelation_ids = newrelation_ids+'|'+n;
  161. }
  162. }
  163. });
  164. $('#relation').val(newrelation_ids);
  165. }
  166. }
  167. //显示相关文章
  168. function show_relation(modelid,id) {
  169. $.getJSON("?m=content&c=content&a=public_getjson_ids&modelid="+modelid+"&id="+id, function(json){
  170. var newrelation_ids = '';
  171. if(json==null) {
  172. alert('没有添加相关文章');
  173. return false;
  174. }
  175. $.each(json, function(i, n){
  176. newrelation_ids += "<li id='"+n.sid+"'>·<span>"+n.title+"</span><a href='javascript:;' class='close' onclick=\"remove_relation('"+n.sid+"',"+n.id+")\"></a></li>";
  177. });
  178. $('#relation_text').html(newrelation_ids);
  179. });
  180. }
  181. //移除ID
  182. function remove_id(id) {
  183. $('#'+id).remove();
  184. }
  185. function strlen_verify(obj, checklen, maxlen) {
  186. var v = obj.value, charlen = 0, maxlen = !maxlen ? 200 : maxlen, curlen = maxlen, len = strlen(v);
  187. for(var i = 0; i < v.length; i++) {
  188. if(v.charCodeAt(i) < 0 || v.charCodeAt(i) > 255) {
  189. curlen -= charset == 'utf-8' ? 2 : 1;
  190. }
  191. }
  192. if(curlen >= len) {
  193. $('#'+checklen).html(curlen - len);
  194. } else {
  195. obj.value = mb_cutstr(v, maxlen, true);
  196. }
  197. }
  198. function mb_cutstr(str, maxlen, dot) {
  199. var len = 0;
  200. var ret = '';
  201. var dot = !dot ? '...' : '';
  202. maxlen = maxlen - dot.length;
  203. for(var i = 0; i < str.length; i++) {
  204. len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset == 'utf-8' ? 3 : 2) : 1;
  205. if(len > maxlen) {
  206. ret += dot;
  207. break;
  208. }
  209. ret += str.substr(i, 1);
  210. }
  211. return ret;
  212. }
  213. function strlen(str) {
  214. return ($.browser.msie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
  215. }