content_addtop.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. //弹出对话框
  2. function omnipotent(id, linkurl, title, close_type, w, h) {
  3. if (!w) w = 700;
  4. if (!h) h = 500;
  5. Wind.use("artDialog","iframeTools",function(){
  6. art.dialog.open(linkurl, {
  7. id: id,
  8. title: title,
  9. width: w,
  10. height: h,
  11. lock: true,
  12. fixed: true,
  13. background:"#CCCCCC",
  14. opacity:0,
  15. button: [{
  16. name: '确定',
  17. callback: function () {
  18. if (close_type == 1) {
  19. return true;
  20. } else {
  21. var d = this.iframe.contentWindow;
  22. var form = d.document.getElementById('dosubmit');
  23. form.click();
  24. }
  25. return false;
  26. },
  27. focus: true
  28. }]
  29. });
  30. });
  31. }
  32. /**
  33. swf上传完回调方法
  34. uploadid dialog id
  35. name dialog名称
  36. textareaid 最后数据返回插入的容器id
  37. funcName 回调函数
  38. args 参数
  39. module 所属模块
  40. catid 栏目id
  41. authkey 参数密钥,验证args
  42. **/
  43. function flashupload(uploadid, name, textareaid, funcName, args, module, catid, authkey) {
  44. var args = args ? '&args=' + args : '';
  45. var setting = '&module=' + module + '&catid=' + catid ;
  46. Wind.use("artDialog","iframeTools",function(){
  47. art.dialog.open(GV.DIMAUB+'index.php?a=swfupload&m=asset&g=asset' + args + setting, {
  48. title: name,
  49. id: uploadid,
  50. width: '650px',
  51. height: '420px',
  52. lock: true,
  53. fixed: true,
  54. background:"#CCCCCC",
  55. opacity:0,
  56. ok: function() {
  57. if (funcName) {
  58. funcName.apply(this, [this, textareaid]);
  59. } else {
  60. submit_ckeditor(this, textareaid);
  61. }
  62. },
  63. cancel: true
  64. });
  65. });
  66. }
  67. //多图上传,SWF回调函数
  68. function change_images(uploadid, returnid) {
  69. var d = uploadid.iframe.contentWindow;
  70. var in_content = d.$("#att-status").html().substring(1);
  71. var in_filename = d.$("#att-name").html().substring(1);
  72. var str = $('#' + returnid).html();
  73. var contents = in_content.split('|');
  74. var filenames = in_filename.split('|');
  75. $('#' + returnid + '_tips').css('display', 'none');
  76. if (contents == '') return true;
  77. $.each(contents, function(i, n) {
  78. var ids = parseInt(Math.random() * 10000 + 10 * i);
  79. var filename = filenames[i].substr(0, filenames[i].indexOf('.'));
  80. str += "<li id='image" + ids + "'><input title='双击查看' type='text' name='" + returnid + "_url[]' value='" + n + "' style='width:310px;' ondblclick='image_priview(this.value);' class='input image-url-input'> <input type='text' name='" + returnid + "_alt[]' value='" + filename + "' style='width:160px;' class='input image-alt-input' onfocus=\"if(this.value == this.defaultValue) this.value = ''\" onblur=\"if(this.value.replace(' ','') == '') this.value = this.defaultValue;\"> <a href=\"javascript:flashupload('replace_albums_images', '图片替换','image"+ids+"',replace_image,'10,gif|jpg|jpeg|png|bmp,0','','','')\">替换</a> <a href=\"javascript:remove_div('image" + ids + "')\">移除</a> </li>";
  81. });
  82. $('#' + returnid).html(str);
  83. }
  84. function replace_image(uploadid, returnid) {
  85. var d = uploadid.iframe.contentWindow;
  86. var in_content = d.$("#att-status").html().substring(1);
  87. var in_filename = d.$("#att-name").html().substring(1);
  88. var str = $('#' + returnid).html();
  89. var contents = in_content.split('|');
  90. var filenames = in_filename.split('|');
  91. $('#' + returnid + '_tips').css('display', 'none');
  92. if (contents == '') return true;
  93. $("#"+returnid).find(".image-url-input").val(contents[0]);
  94. var filename = filenames[0].substr(0, filenames[0].indexOf('.'));
  95. $("#"+returnid).find(".image-alt-input").val(filename);
  96. }
  97. //多图上传,SWF回调函数
  98. function upload_zip(uploadid, returnid) {
  99. var d = uploadid.iframe.contentWindow;
  100. var in_content = d.$("#att-status").html().substring(1);
  101. var in_filename = d.$("#att-name").html().substring(1);
  102. var str = $('#' + returnid).html();
  103. var contents = in_content.split('|');
  104. var filenames = in_filename.split('|');
  105. $('#' + returnid + '_tips').css('display', 'none');
  106. if (contents == '') return true;
  107. $.each(contents, function(i, n) {
  108. var ids = parseInt(Math.random() * 10000 + 10 * i);
  109. var filename = filenames[i].substr(0, filenames[i].indexOf('.'));
  110. str += "<li id='image" + ids + "'><input title='双击查看' type='text' name='" + returnid + "_url' value='" + n + "' style='width:310px;' ondblclick='image_priview(this.value);' class='input'> <input type='text' name='" + returnid + "_alt[]' value='" + filename + "' style='width:160px;' class='input' 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>";
  111. });
  112. $('#' + returnid).html(str);
  113. }
  114. //编辑器ue附件上传
  115. function ueAttachment(uploadid, returnid){
  116. var d = uploadid.iframe.contentWindow;
  117. var in_content = d.$("#att-status").html().substring(1);
  118. if (in_content == ''){
  119. return false;
  120. }
  121. in_content = in_content.split("|");
  122. var i;
  123. var in_filename = d.$("#att-name").html().substring(1);
  124. var filenames = in_filename.split('|');
  125. eval("var ue = editor"+ returnid);
  126. for(i=0; i<in_content.length; i++){
  127. ue.execCommand('inserthtml', '<a href="'+in_content[i]+'" target="_blank">附件:'+filenames[i]+'</a>');
  128. }
  129. }
  130. //多文件上传回调
  131. function change_multifile(uploadid, returnid) {
  132. var d = uploadid.iframe.contentWindow;
  133. var in_content = d.$("#att-status").html().substring(1);
  134. var in_filename = d.$("#att-name").html().substring(1);
  135. var str = '';
  136. var contents = in_content.split('|');
  137. var filenames = in_filename.split('|');
  138. $('#' + returnid + '_tips').css('display', 'none');
  139. if (contents == '') return true;
  140. $.each(contents, function(i, n) {
  141. var ids = parseInt(Math.random() * 10000 + 10 * i);
  142. var filename = filenames[i].substr(0, filenames[i].indexOf('.'));
  143. str += "<li id='multifile" + ids + "'><input type='text' name='" + returnid + "_fileurl[]' value='" + n + "' style='width:310px;' class='input'> <input type='text' name='" + returnid + "_filename[]' value='" + filename + "' style='width:160px;' class='input' 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>";
  144. });
  145. $('#' + returnid).append(str);
  146. }
  147. //缩图上传回调
  148. function thumb_images(uploadid, returnid) {
  149. //取得iframe对象
  150. var d = uploadid.iframe.contentWindow;
  151. //取得选择的图片
  152. var in_content = d.$("#att-status").html().substring(1);
  153. if (in_content == '') return false;
  154. if (!IsImg(in_content)) {
  155. isalert('选择的类型必须为图片类型!');
  156. return false;
  157. }
  158. if ($('#' + returnid + '_preview').attr('src')) {
  159. $('#' + returnid + '_preview').attr('src', in_content);
  160. }
  161. $('#' + returnid).val(in_content);
  162. }
  163. function change_onefile(uploadid, returnid){
  164. var d = uploadid.iframe.contentWindow;
  165. var in_content = d.$("#att-status").html().substring(1);
  166. var in_filename = d.$("#att-name").html().substring(1);
  167. var str = '';
  168. var contents = in_content.split('|');
  169. var filenames = in_filename.split('|');
  170. $('#' + returnid + '_tips').css('display', 'none');
  171. if (contents == '') return true;
  172. $('#' + returnid).val(contents[0]);
  173. }
  174. //提示框 alert
  175. function isalert(content,icon){
  176. if(content == ''){
  177. return;
  178. }
  179. icon = icon|| "error";
  180. Wind.use("artDialog",function(){
  181. art.dialog({
  182. id:icon,
  183. icon: icon,
  184. fixed: true,
  185. lock: true,
  186. background:"#CCCCCC",
  187. opacity:0,
  188. content: content,
  189. cancelVal: '确定',
  190. cancel: true
  191. });
  192. });
  193. }
  194. //图片使用dialog查看
  195. function image_priview(img) {
  196. if(img == ''){
  197. return;
  198. }
  199. if (!IsImg(img)) {
  200. isalert('选择的类型必须为图片类型!');
  201. return false;
  202. }
  203. Wind.use("artDialog",function(){
  204. art.dialog({
  205. title: '图片查看',
  206. fixed: true,
  207. width:"600px",
  208. height: '420px',
  209. id:"image_priview",
  210. lock: true,
  211. background:"#CCCCCC",
  212. opacity:0,
  213. content: '<img src="' + img + '" />',
  214. time: 5
  215. });
  216. });
  217. }
  218. //添加/修改文章时,标题加粗
  219. function input_font_bold() {
  220. if ($('#title').css('font-weight') == '700' || $('#title').css('font-weight') == 'bold') {
  221. $('#title').css('font-weight', 'normal');
  222. $('#style_font_weight').val('');
  223. } else {
  224. $('#title').css('font-weight', 'bold');
  225. $('#style_font_weight').val('bold');
  226. }
  227. }
  228. //图片上传回调
  229. function submit_images(uploadid, returnid) {
  230. var d = uploadid.iframe.contentWindow;
  231. var in_content = d.$("#att-status").html().substring(1);
  232. var in_content = in_content.split('|');
  233. IsImg(in_content[0]) ? $('#' + returnid).attr("value", in_content[0]) : alert('选择的类型必须为图片类型');
  234. }
  235. //移除ID
  236. function remove_id(id) {
  237. $('#' + id).remove();
  238. }
  239. //输入长度提示
  240. function strlen_verify(obj, checklen, maxlen) {
  241. var v = obj.value,
  242. charlen = 0,
  243. maxlen = !maxlen ? 200 : maxlen,
  244. curlen = maxlen,
  245. len = strlen(v);
  246. var charset = 'utf-8';
  247. for (var i = 0; i < v.length; i++) {
  248. if (v.charCodeAt(i) < 0 || v.charCodeAt(i) > 255) {
  249. curlen -= charset == 'utf-8' ? 2 : 1;
  250. }
  251. }
  252. if (curlen >= len) {
  253. $('#' + checklen).html(curlen - len);
  254. } else {
  255. obj.value = mb_cutstr(v, maxlen, true);
  256. }
  257. }
  258. //长度统计
  259. function strlen(str) {
  260. return ($.browser.msie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
  261. }
  262. function mb_cutstr(str, maxlen, dot) {
  263. var len = 0;
  264. var ret = '';
  265. var dot = !dot ? '...' : '';
  266. maxlen = maxlen - dot.length;
  267. for (var i = 0; i < str.length; i++) {
  268. len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset == 'utf-8' ? 3 : 2) : 1;
  269. if (len > maxlen) {
  270. ret += dot;
  271. break;
  272. }
  273. ret += str.substr(i, 1);
  274. }
  275. return ret;
  276. }
  277. //移除指定id内容
  278. function remove_div(id) {
  279. $('#' + id).remove();
  280. }
  281. //转向地址
  282. function ruselinkurl() {
  283. if ($('#islink').is(':checked') == true) {
  284. $('#linkurl').attr('disabled', null);
  285. return false;
  286. } else {
  287. $('#linkurl').attr('disabled', 'true');
  288. }
  289. }
  290. //验证地址是否为图片
  291. function IsImg(url) {
  292. var sTemp;
  293. var b = false;
  294. var opt = "jpg|gif|png|bmp|jpeg|zip";
  295. var s = opt.toUpperCase().split("|");
  296. for (var i = 0; i < s.length; i++) {
  297. sTemp = url.substr(url.length - s[i].length - 1);
  298. sTemp = sTemp.toUpperCase();
  299. s[i] = "." + s[i];
  300. if (s[i] == sTemp) {
  301. b = true;
  302. break;
  303. }
  304. }
  305. return b;
  306. }
  307. //验证地址是否为Flash
  308. function IsSwf(url) {
  309. var sTemp;
  310. var b = false;
  311. var opt = "swf";
  312. var s = opt.toUpperCase().split("|");
  313. for (var i = 0; i < s.length; i++) {
  314. sTemp = url.substr(url.length - s[i].length - 1);
  315. sTemp = sTemp.toUpperCase();
  316. s[i] = "." + s[i];
  317. if (s[i] == sTemp) {
  318. b = true;
  319. break;
  320. }
  321. }
  322. return b;
  323. }
  324. //添加地址
  325. function add_multifile(returnid) {
  326. var ids = parseInt(Math.random() * 10000);
  327. var str = "<li id='multifile" + ids + "'><input type='text' name='" + returnid + "_fileurl[]' value='' style='width:310px;' class='input'> <input type='text' name='" + returnid + "_filename[]' value='附件说明' style='width:160px;' class='input'> <a href=\"javascript:remove_div('multifile" + ids + "')\">移除</a> </li>";
  328. $('#' + returnid).append(str);
  329. }