content_addtop.js 13 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 + 'admin.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;height:48px;' ondblclick='image_priview(this.value);' class='input image-url-input'> <input type='text' name='" + returnid + "_alt[]' value='" + filename + "' style='width:160px;height:48px;' class='input image-alt-input' onfocus=\"if(this.value == this.defaultValue) this.value = ''\" onblur=\"if(this.value.replace(' ','') == '') this.value = this.defaultValue;\"><a class='img_a' href=\"javascript:onClick=image_priview('" + n + "')\"><img class='img_prew' src='" + n + "' style='height:50px;'></img></a> <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. $("#" + returnid).find(".img_prew").attr('src', contents[0]);
  95. $("#" + returnid).find(".img_a").attr('href', "javascript:onClick=image_priview('" + contents[0] + "')");
  96. var filename = filenames[0].substr(0, filenames[0].indexOf('.'));
  97. $("#" + returnid).find(".image-alt-input").val(filename);
  98. }
  99. //多图上传,SWF回调函数
  100. function upload_zip(uploadid, returnid) {
  101. var d = uploadid.iframe.contentWindow;
  102. var in_content = d.$("#att-status").html().substring(1);
  103. var in_filename = d.$("#att-name").html().substring(1);
  104. var str = $('#' + returnid).html();
  105. var contents = in_content.split('|');
  106. var filenames = in_filename.split('|');
  107. $('#' + returnid + '_tips').css('display', 'none');
  108. if (contents == '') return true;
  109. $.each(contents, function (i, n) {
  110. var ids = parseInt(Math.random() * 10000 + 10 * i);
  111. var filename = filenames[i].substr(0, filenames[i].indexOf('.'));
  112. str += "<li id='image" + ids + "'><input title='双击查看' type='text' name='" + returnid + "_url' value='" + n + "' style='width:310px;height:48px;' ondblclick='image_priview(this.value);' class='input'> <input type='text' name='" + returnid + "_alt[]' value='" + filename + "' style='width:160px;height:48px;' class='input' onfocus=\"if(this.value == this.defaultValue) this.value = ''\" onblur=\"if(this.value.replace(' ','') == '') this.value = this.defaultValue;\"><a class='img_a' href=\"javascript:onClick=image_priview('" + n + "')\"><img class='img_prew' src='" + n + "' style='height:50px;'></img></a> <a href=\"javascript:remove_div('image" + ids + "')\">移除</a> </li>";
  113. });
  114. $('#' + returnid).html(str);
  115. }
  116. //编辑器ue附件上传
  117. function ueAttachment(uploadid, returnid) {
  118. var d = uploadid.iframe.contentWindow;
  119. var in_content = d.$("#att-status").html().substring(1);
  120. if (in_content == '') {
  121. return false;
  122. }
  123. in_content = in_content.split("|");
  124. var i;
  125. var in_filename = d.$("#att-name").html().substring(1);
  126. var filenames = in_filename.split('|');
  127. eval("var ue = editor" + returnid);
  128. for (i = 0; i < in_content.length; i ++) {
  129. ue.execCommand('inserthtml', '<a href="' + in_content[i] + '" target="_blank">附件:' + filenames[i] + '</a>');
  130. }
  131. }
  132. //多文件上传回调
  133. function change_multifile(uploadid, returnid) {
  134. var d = uploadid.iframe.contentWindow;
  135. var in_content = d.$("#att-status").html().substring(1);
  136. var in_filename = d.$("#att-name").html().substring(1);
  137. var str = '';
  138. var contents = in_content.split('|');
  139. var filenames = in_filename.split('|');
  140. $('#' + returnid + '_tips').css('display', 'none');
  141. if (contents == '') return true;
  142. $.each(contents, function (i, n) {
  143. var ids = parseInt(Math.random() * 10000 + 10 * i);
  144. var filename = filenames[i].substr(0, filenames[i].indexOf('.'));
  145. 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>";
  146. });
  147. $('#' + returnid).append(str);
  148. }
  149. //缩图上传回调
  150. function thumb_images(uploadid, returnid) {
  151. //取得iframe对象
  152. var d = uploadid.iframe.contentWindow;
  153. //取得选择的图片
  154. var in_content = d.$("#att-status").html().substring(1);
  155. if (in_content == '') return false;
  156. if (! IsImg(in_content)) {
  157. isalert('选择的类型必须为图片类型!');
  158. return false;
  159. }
  160. if ($('#' + returnid + '_preview').attr('src')) {
  161. $('#' + returnid + '_preview').attr('src', in_content);
  162. }
  163. $('#' + returnid).val(in_content);
  164. }
  165. function change_onefile(uploadid, returnid) {
  166. var d = uploadid.iframe.contentWindow;
  167. var in_content = d.$("#att-status").html().substring(1);
  168. var in_filename = d.$("#att-name").html().substring(1);
  169. var str = '';
  170. var contents = in_content.split('|');
  171. var filenames = in_filename.split('|');
  172. $('#' + returnid + '_tips').css('display', 'none');
  173. if (contents == '') return true;
  174. $('#' + returnid).val(contents[0]);
  175. }
  176. //提示框 alert
  177. function isalert(content, icon) {
  178. if (content == '') {
  179. return;
  180. }
  181. icon = icon || "error";
  182. Wind.use("artDialog", function () {
  183. art.dialog({
  184. id : icon,
  185. icon : icon,
  186. fixed : true,
  187. lock : true,
  188. background: "#CCCCCC",
  189. opacity : 0,
  190. content : content,
  191. cancelVal : '确定',
  192. cancel : true
  193. });
  194. });
  195. }
  196. //图片使用dialog查看
  197. function image_priview(img) {
  198. if (img == '') {
  199. return;
  200. }
  201. if (! IsImg(img)) {
  202. isalert('选择的类型必须为图片类型!');
  203. return false;
  204. }
  205. Wind.use("artDialog", function () {
  206. art.dialog({
  207. title : '图片查看',
  208. fixed : true,
  209. width : "600px",
  210. height : '420px',
  211. id : "image_priview",
  212. lock : true,
  213. background: "#CCCCCC",
  214. opacity : 0,
  215. content : '<img src="' + img + '" />',
  216. time : 5
  217. });
  218. });
  219. }
  220. //添加/修改文章时,标题加粗
  221. function input_font_bold() {
  222. if ($('#title').css('font-weight') == '700' || $('#title').css('font-weight') == 'bold') {
  223. $('#title').css('font-weight', 'normal');
  224. $('#style_font_weight').val('');
  225. } else {
  226. $('#title').css('font-weight', 'bold');
  227. $('#style_font_weight').val('bold');
  228. }
  229. }
  230. //图片上传回调
  231. function submit_images(uploadid, returnid) {
  232. var d = uploadid.iframe.contentWindow;
  233. var in_content = d.$("#att-status").html().substring(1);
  234. var in_content = in_content.split('|');
  235. IsImg(in_content[0]) ? $('#' + returnid).attr("value", in_content[0]) : alert('选择的类型必须为图片类型');
  236. }
  237. //移除ID
  238. function remove_id(id) {
  239. $('#' + id).remove();
  240. }
  241. //输入长度提示
  242. function strlen_verify(obj, checklen, maxlen) {
  243. var v = obj.value,
  244. charlen = 0,
  245. maxlen = ! maxlen ? 200 : maxlen,
  246. curlen = maxlen,
  247. len = strlen(v);
  248. var charset = 'utf-8';
  249. for (var i = 0; i < v.length; i ++) {
  250. if (v.charCodeAt(i) < 0 || v.charCodeAt(i) > 255) {
  251. curlen -= charset == 'utf-8' ? 2 : 1;
  252. }
  253. }
  254. if (curlen >= len) {
  255. $('#' + checklen).html(curlen - len);
  256. } else {
  257. obj.value = mb_cutstr(v, maxlen, true);
  258. }
  259. }
  260. //长度统计
  261. function strlen(str) {
  262. return ($.browser.msie && str.indexOf('\n') != - 1) ? str.replace(/\r?\n/g, '_').length : str.length;
  263. }
  264. function mb_cutstr(str, maxlen, dot) {
  265. var len = 0;
  266. var ret = '';
  267. var dot = ! dot ? '...' : '';
  268. maxlen = maxlen - dot.length;
  269. for (var i = 0; i < str.length; i ++) {
  270. len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset == 'utf-8' ? 3 : 2) : 1;
  271. if (len > maxlen) {
  272. ret += dot;
  273. break;
  274. }
  275. ret += str.substr(i, 1);
  276. }
  277. return ret;
  278. }
  279. //移除指定id内容
  280. function remove_div(id) {
  281. $('#' + id).remove();
  282. }
  283. //转向地址
  284. function ruselinkurl() {
  285. if ($('#islink').is(':checked') == true) {
  286. $('#linkurl').attr('disabled', null);
  287. return false;
  288. } else {
  289. $('#linkurl').attr('disabled', 'true');
  290. }
  291. }
  292. //验证地址是否为图片
  293. function IsImg(url) {
  294. var sTemp;
  295. var b = false;
  296. var opt = "jpg|gif|png|bmp|jpeg|zip";
  297. var s = opt.toUpperCase().split("|");
  298. for (var i = 0; i < s.length; i ++) {
  299. sTemp = url.substr(url.length - s[i].length - 1);
  300. sTemp = sTemp.toUpperCase();
  301. s[i] = "." + s[i];
  302. if (s[i] == sTemp) {
  303. b = true;
  304. break;
  305. }
  306. }
  307. return b;
  308. }
  309. //验证地址是否为Flash
  310. function IsSwf(url) {
  311. var sTemp;
  312. var b = false;
  313. var opt = "swf";
  314. var s = opt.toUpperCase().split("|");
  315. for (var i = 0; i < s.length; i ++) {
  316. sTemp = url.substr(url.length - s[i].length - 1);
  317. sTemp = sTemp.toUpperCase();
  318. s[i] = "." + s[i];
  319. if (s[i] == sTemp) {
  320. b = true;
  321. break;
  322. }
  323. }
  324. return b;
  325. }
  326. //添加地址
  327. function add_multifile(returnid) {
  328. var ids = parseInt(Math.random() * 10000);
  329. 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>";
  330. $('#' + returnid).append(str);
  331. }