admincp.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. /*
  2. [Discuz!] (C)2001-2099 Comsenz Inc.
  3. This is NOT a freeware, use is subject to license terms
  4. $Id: admincp.js 31631 2012-09-17 06:36:25Z monkey $
  5. */
  6. function redirect(url) {
  7. window.location.replace(url);
  8. }
  9. function scrollTopBody() {
  10. return Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  11. }
  12. function checkAll(type, form, value, checkall, changestyle) {
  13. var checkall = checkall ? checkall : 'chkall';
  14. for(var i = 0; i < form.elements.length; i++) {
  15. var e = form.elements[i];
  16. if(type == 'option' && e.type == 'radio' && e.value == value && e.disabled != true) {
  17. e.checked = true;
  18. } else if(type == 'value' && e.type == 'checkbox' && e.getAttribute('chkvalue') == value) {
  19. e.checked = form.elements[checkall].checked;
  20. if(changestyle) {
  21. multiupdate(e);
  22. }
  23. } else if(type == 'prefix' && e.name && e.name != checkall && (!value || (value && e.name.match(value)))) {
  24. e.checked = form.elements[checkall].checked;
  25. if(changestyle) {
  26. if(e.parentNode && e.parentNode.tagName.toLowerCase() == 'li') {
  27. e.parentNode.className = e.checked ? 'checked' : '';
  28. }
  29. if(e.parentNode.parentNode && e.parentNode.parentNode.tagName.toLowerCase() == 'div') {
  30. e.parentNode.parentNode.className = e.checked ? 'item checked' : 'item';
  31. }
  32. }
  33. }
  34. }
  35. }
  36. function altStyle(obj, disabled) {
  37. function altStyleClear(obj) {
  38. var input, lis, i;
  39. lis = obj.parentNode.getElementsByTagName('li');
  40. for(i=0; i < lis.length; i++){
  41. lis[i].className = '';
  42. }
  43. }
  44. var disabled = !disabled ? 0 : disabled;
  45. if(disabled) {
  46. return;
  47. }
  48. var input, lis, i, cc, o;
  49. cc = 0;
  50. lis = obj.getElementsByTagName('li');
  51. for(i=0; i < lis.length; i++){
  52. lis[i].onclick = function(e) {
  53. o = BROWSER.ie ? event.srcElement.tagName : e.target.tagName;
  54. altKey = BROWSER.ie ? window.event.altKey : e.altKey;
  55. if(cc) {
  56. return;
  57. }
  58. cc = 1;
  59. input = this.getElementsByTagName('input')[0];
  60. if(input.getAttribute('type') == 'checkbox' || input.getAttribute('type') == 'radio') {
  61. if(input.getAttribute('type') == 'radio') {
  62. altStyleClear(this);
  63. }
  64. if(BROWSER.ie || o != 'INPUT' && input.onclick) {
  65. input.click();
  66. }
  67. if(this.className != 'checked') {
  68. this.className = 'checked';
  69. input.checked = true;
  70. } else {
  71. this.className = '';
  72. input.checked = false;
  73. }
  74. if(altKey && input.name.match(/^multinew\[\d+\]/)) {
  75. miid = input.id.split('|');
  76. mi = 0;
  77. while($(miid[0] + '|' + mi)) {
  78. $(miid[0] + '|' + mi).checked = input.checked;
  79. if(input.getAttribute('type') == 'radio') {
  80. altStyleClear($(miid[0] + '|' + mi).parentNode);
  81. }
  82. $(miid[0] + '|' + mi).parentNode.className = input.checked ? 'checked' : '';
  83. mi++;
  84. }
  85. }
  86. }
  87. };
  88. lis[i].onmouseup = function(e) {
  89. cc = 0;
  90. }
  91. }
  92. }
  93. var addrowdirect = 0;
  94. var addrowkey = 0;
  95. function addrow(obj, type) {
  96. var table = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
  97. if(!addrowdirect) {
  98. var row = table.insertRow(obj.parentNode.parentNode.parentNode.rowIndex);
  99. } else {
  100. var row = table.insertRow(obj.parentNode.parentNode.parentNode.rowIndex + 1);
  101. }
  102. var typedata = rowtypedata[type];
  103. for(var i = 0; i <= typedata.length - 1; i++) {
  104. var cell = row.insertCell(i);
  105. cell.colSpan = typedata[i][0];
  106. var tmp = typedata[i][1];
  107. if(typedata[i][2]) {
  108. cell.className = typedata[i][2];
  109. }
  110. tmp = tmp.replace(/\{(n)\}/g, function($1) {return addrowkey;});
  111. tmp = tmp.replace(/\{(\d+)\}/g, function($1, $2) {return addrow.arguments[parseInt($2) + 1];});
  112. cell.innerHTML = tmp;
  113. }
  114. addrowkey ++;
  115. addrowdirect = 0;
  116. }
  117. function deleterow(obj) {
  118. var table = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
  119. var tr = obj.parentNode.parentNode.parentNode;
  120. table.deleteRow(tr.rowIndex);
  121. }
  122. function dropmenu(obj){
  123. showMenu({'ctrlid':obj.id, 'menuid':obj.id + 'child', 'evt':'mouseover'});
  124. $(obj.id + 'child').style.top = (parseInt($(obj.id + 'child').style.top) - Math.max(document.body.scrollTop, document.documentElement.scrollTop)) + 'px';
  125. if(BROWSER.ie > 6 || !BROWSER.ie) {
  126. $(obj.id + 'child').style.left = (parseInt($(obj.id + 'child').style.left) - Math.max(document.body.scrollLeft, document.documentElement.scrollLeft)) + 'px';
  127. }
  128. }
  129. function insertunit(obj, text, textend) {
  130. obj.focus();
  131. textend = isUndefined(textend) ? '' : textend;
  132. if(!isUndefined(obj.selectionStart)) {
  133. var opn = obj.selectionStart + 0;
  134. if(textend != '') {
  135. text = text + obj.substring(obj.selectionStart, obj.selectionEnd) + textend;
  136. }
  137. obj.value = obj.value.substr(0, obj.selectionStart) + text + obj.value.substr(obj.selectionEnd);
  138. obj.selectionStart = opn + strlen(text);
  139. obj.selectionEnd = opn + strlen(text);
  140. } else if(document.selection && document.selection.createRange) {
  141. var sel = document.selection.createRange();
  142. if(textend != '') {
  143. text = text + sel.text + textend;
  144. }
  145. sel.text = text.replace(/\r?\n/g, '\r\n');
  146. sel.moveStart('character', -strlen(text));
  147. } else {
  148. obj.value += text;
  149. }
  150. obj.focus();
  151. }
  152. var heightag = BROWSER.chrome ? 4 : 0;
  153. function textareakey(obj, event) {
  154. if(event.keyCode == 9) {
  155. insertunit(obj, '\t');
  156. doane(event);
  157. }
  158. }
  159. function textareasize(obj, op) {
  160. if(!op) {
  161. if(obj.scrollHeight > 70) {
  162. obj.style.height = (obj.scrollHeight < 300 ? obj.scrollHeight - heightag: 300) + 'px';
  163. if(obj.style.position == 'absolute') {
  164. obj.parentNode.style.height = (parseInt(obj.style.height) + 20) + 'px';
  165. }
  166. }
  167. } else {
  168. if(obj.style.position == 'absolute') {
  169. obj.style.position = '';
  170. obj.style.width = '';
  171. obj.parentNode.style.height = '';
  172. } else {
  173. obj.parentNode.style.height = obj.parentNode.offsetHeight + 'px';
  174. obj.style.width = BROWSER.ie > 6 || !BROWSER.ie ? '90%' : '600px';
  175. obj.style.position = 'absolute';
  176. }
  177. }
  178. }
  179. function showanchor(obj) {
  180. var navs = $('submenu').getElementsByTagName('li');
  181. for(var i = 0; i < navs.length; i++) {
  182. if(navs[i].id.substr(0, 4) == 'nav_' && navs[i].id != obj.id) {
  183. if($(navs[i].id.substr(4))) {
  184. navs[i].className = '';
  185. $(navs[i].id.substr(4)).style.display = 'none';
  186. if($(navs[i].id.substr(4) + '_tips')) $(navs[i].id.substr(4) + '_tips').style.display = 'none';
  187. }
  188. }
  189. }
  190. obj.className = 'current';
  191. currentAnchor = obj.id.substr(4);
  192. $(currentAnchor).style.display = '';
  193. if($(currentAnchor + '_tips')) $(currentAnchor + '_tips').style.display = '';
  194. if($(currentAnchor + 'form')) {
  195. $(currentAnchor + 'form').anchor.value = currentAnchor;
  196. } else if($('cpform')) {
  197. $('cpform').anchor.value = currentAnchor;
  198. }
  199. }
  200. function updatecolorpreview(obj) {
  201. $(obj).style.background = $(obj + '_v').value;
  202. }
  203. function entersubmit(e, name) {
  204. if(loadUserdata('is_blindman')) {
  205. return false;
  206. }
  207. e = e ? e : event;
  208. if(e.keyCode != 13) {
  209. return;
  210. }
  211. var tag = BROWSER.ie ? e.srcElement.tagName : e.target.tagName;
  212. if(tag != 'TEXTAREA') {
  213. doane(e);
  214. if($('submit_' + name).offsetWidth) {
  215. $('formscrolltop').value = document.documentElement.scrollTop;
  216. $('submit_' + name).click();
  217. }
  218. }
  219. }
  220. function parsetag(tag) {
  221. var parse = function (tds) {
  222. for(var i = 0; i < tds.length; i++) {
  223. if(tds[i].getAttribute('s') == '1') {
  224. var str = tds[i].innerHTML.replace(/(^|>)([^<]+)(?=<|$)/ig, function($1, $2, $3) {
  225. if(tag && $3.indexOf(tag) != -1) {
  226. re = new RegExp(tag, "g");
  227. $3 = $3.replace(re, '<h_>');
  228. }
  229. return $2 + $3;
  230. });
  231. tds[i].innerHTML = str.replace(/<h_>/ig, function($1, $2) {
  232. return '<font class="highlight">' + tag + '</font>';
  233. });
  234. }
  235. }
  236. };
  237. parse(document.body.getElementsByTagName('td'));
  238. parse(document.body.getElementsByTagName('span'));
  239. }
  240. function sdisplay(id, obj) {
  241. obj.innerHTML = $(id).style.display == 'none' ? '<img src="static/image/admincp/desc.gif" style="vertical-align:middle" />' : '<img src="static/image/admincp/add.gif" style="vertical-align:middle" />';
  242. display(id);
  243. }
  244. if(ISFRAME) {
  245. try {
  246. _attachEvent(document.documentElement, 'keydown', parent.resetEscAndF5);
  247. } catch(e) {}
  248. }
  249. var multiids = new Array();
  250. function multiupdate(obj) {
  251. v = obj.value;
  252. if(obj.checked) {
  253. multiids[v] = v;
  254. } else {
  255. multiids[v] = null;
  256. }
  257. }
  258. function getmultiids() {
  259. var ids = '', comma = '';
  260. for(i in multiids) {
  261. if(multiids[i] != null) {
  262. ids += comma + multiids[i];
  263. comma = ',';
  264. }
  265. }
  266. return ids;
  267. }
  268. function toggle_group(oid, obj, conf) {
  269. obj = obj ? obj : $('a_'+oid);
  270. if(!conf) {
  271. var conf = {'show':'[-]','hide':'[+]'};
  272. }
  273. var obody = $(oid);
  274. if(obody.style.display == 'none') {
  275. obody.style.display = '';
  276. obj.innerHTML = conf.show;
  277. } else {
  278. obody.style.display = 'none';
  279. obj.innerHTML = conf.hide;
  280. }
  281. }
  282. function show_all() {
  283. var tbodys = $("cpform").getElementsByTagName('tbody');
  284. for(var i = 0; i < tbodys.length; i++) {
  285. var re = /^group_(\d+)$/;
  286. var matches = re.exec(tbodys[i].id);
  287. if(matches != null) {
  288. tbodys[i].style.display = '';
  289. $('a_group_' + matches[1]).innerHTML = '[-]';
  290. }
  291. }
  292. }
  293. function hide_all() {
  294. var tbodys = $("cpform").getElementsByTagName('tbody');
  295. for(var i = 0; i < tbodys.length; i++) {
  296. var re = /^group_(\d+)$/;
  297. var matches = re.exec(tbodys[i].id);
  298. if(matches != null) {
  299. tbodys[i].style.display = 'none';
  300. $('a_group_' + matches[1]).innerHTML = '[+]';
  301. }
  302. }
  303. }
  304. function show_all_hook(prefix, tagname) {
  305. var tbodys = $("cpform").getElementsByTagName(tagname);
  306. for(var i = 0; i < tbodys.length; i++) {
  307. var re = new RegExp('^' + prefix + '(.+)$');
  308. var matches = re.exec(tbodys[i].id);
  309. if(matches != null) {
  310. tbodys[i].style.display = '';
  311. $('a_' + prefix + matches[1]).innerHTML = '[-]';
  312. }
  313. }
  314. }
  315. function hide_all_hook(prefix, tagname) {
  316. var tbodys = $("cpform").getElementsByTagName(tagname);
  317. for(var i = 0; i < tbodys.length; i++) {
  318. var re = new RegExp('^' + prefix + '(.+)$');
  319. var matches = re.exec(tbodys[i].id);
  320. if(matches != null) {
  321. tbodys[i].style.display = 'none';
  322. $('a_' + prefix + matches[1]).innerHTML = '[+]';
  323. }
  324. }
  325. }
  326. function srchforum() {
  327. var fname = $('srchforumipt').value.toLowerCase();
  328. if(!fname) return false;
  329. var inputs = $("cpform").getElementsByTagName('input');
  330. for(var i = 0; i < inputs.length; i++) {
  331. if(inputs[i].name.match(/^name\[\d+\]$/)) {
  332. if(inputs[i].value.toLowerCase().indexOf(fname) !== -1) {
  333. inputs[i].parentNode.parentNode.parentNode.parentNode.style.display = '';
  334. inputs[i].parentNode.parentNode.parentNode.style.background = '#eee';
  335. window.scrollTo(0, fetchOffset(inputs[i]).top - 100);
  336. return false;
  337. }
  338. }
  339. }
  340. return false;
  341. }
  342. function setfaq(obj, id) {
  343. if(!$(id)) {
  344. return;
  345. }
  346. $(id).style.display = '';
  347. if(!obj.onmouseout) {
  348. obj.onmouseout = function () {
  349. $(id).style.display = 'none';
  350. }
  351. }
  352. }
  353. function floatbottom(id) {
  354. if(!$(id)) {
  355. return;
  356. }
  357. $(id).style.position = 'fixed';
  358. $(id).style.bottom = '0';
  359. $(id).parentNode.style.paddingBottom = '15px';
  360. if(!BROWSER.ie || BROWSER.ie && BROWSER.ie > 6) {
  361. window.onscroll = function() {
  362. var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
  363. $(id).style.marginLeft = '-' + scrollLeft + 'px';
  364. };
  365. $(id).style.display = '';
  366. }
  367. }
  368. var sethtml_id = null;
  369. function sethtml(id) {
  370. $(id).className = 'txt html';
  371. $(id).contentEditable = true;
  372. $(id).onkeyup = function () {
  373. $(id + '_v').value = $(id).innerHTML;
  374. };
  375. var curvalue = $(id).innerHTML;
  376. var div = document.createElement('div');
  377. div.id = id + '_c_menu';
  378. div.style.display = 'none';
  379. div.innerHTML = '<iframe id="' + id + '_c_frame" src="" frameborder="0" width="210" height="148" scrolling="no"></iframe>';
  380. $(id).parentNode.appendChild(div);
  381. var btn = document.createElement('input');
  382. btn.id = id + '_c';
  383. btn.type = 'button';
  384. btn.className = 'htmlbtn c';
  385. if(curvalue.search(/<font/ig) !== -1) {
  386. btn.className = 'htmlbtn c current';
  387. }
  388. btn.onclick = function() {
  389. $(id + '_c_frame').src = 'static/image/admincp/getcolor.htm?||sethtml_color';
  390. showMenu({'ctrlid' : id + '_c'});
  391. sethtml_id = id;
  392. };
  393. $(id).parentNode.appendChild(btn);
  394. var btn = document.createElement('input');
  395. btn.id = id + '_b';
  396. btn.type = 'button';
  397. btn.className = 'htmlbtn b';
  398. if(curvalue.search(/<b>/ig) !== -1) {
  399. btn.className = 'htmlbtn b current';
  400. }
  401. btn.onclick = function() {
  402. var oldvalue = $(id).innerHTML;
  403. $(id).innerHTML = preg_replace(['<b>', '</b>'], '', $(id).innerHTML);
  404. if(oldvalue == $(id).innerHTML) {
  405. $(id + '_b').className = 'htmlbtn b current';
  406. $(id).innerHTML = '<b>' + $(id).innerHTML + '</b>';
  407. } else {
  408. $(id + '_b').className = 'htmlbtn b';
  409. }
  410. $(id + '_v').value = $(id).innerHTML;
  411. };
  412. $(id).parentNode.appendChild(btn);
  413. var btn = document.createElement('input');
  414. btn.id = id + '_i';
  415. btn.type = 'button';
  416. btn.className = 'htmlbtn i';
  417. if(curvalue.search(/<i>/ig) !== -1) {
  418. btn.className = 'htmlbtn i current';
  419. }
  420. btn.onclick = function() {
  421. var oldvalue = $(id).innerHTML;
  422. $(id).innerHTML = preg_replace(['<i>', '</i>'], '', $(id).innerHTML);
  423. if(oldvalue == $(id).innerHTML) {
  424. $(id + '_i').className = 'htmlbtn i current';
  425. $(id).innerHTML = '<i>' + $(id).innerHTML + '</i>';
  426. } else {
  427. $(id + '_i').className = 'htmlbtn i';
  428. }
  429. $(id + '_v').value = $(id).innerHTML;
  430. };
  431. $(id).parentNode.appendChild(btn);
  432. var btn = document.createElement('input');
  433. btn.id = id + '_u';
  434. btn.type = 'button';
  435. btn.style.textDecoration = 'underline';
  436. btn.className = 'htmlbtn u';
  437. if(curvalue.search(/<u>/ig) !== -1) {
  438. btn.className = 'htmlbtn u current';
  439. }
  440. btn.onclick = function() {
  441. var oldvalue = $(id).innerHTML;
  442. $(id).innerHTML = preg_replace(['<u>', '</u>'], '', $(id).innerHTML);
  443. if(oldvalue == $(id).innerHTML) {
  444. $(id + '_u').className = 'htmlbtn u current';
  445. $(id).innerHTML = '<u>' + $(id).innerHTML + '</u>';
  446. } else {
  447. $(id + '_u').className = 'htmlbtn u';
  448. }
  449. $(id + '_v').value = $(id).innerHTML;
  450. };
  451. $(id).parentNode.appendChild(btn);
  452. }
  453. function sethtml_color(color) {
  454. $(sethtml_id).innerHTML = preg_replace(['<font[^>]+?>', '</font>'], '', $(sethtml_id).innerHTML);
  455. if(color != 'transparent') {
  456. $(sethtml_id + '_c').className = 'htmlbtn c current';
  457. $(sethtml_id).innerHTML = '<font color=' + color + '>' + $(sethtml_id).innerHTML + '</font>';
  458. } else {
  459. $(sethtml_id + '_c').className = 'htmlbtn c';
  460. }
  461. $(sethtml_id + '_v').value = $(sethtml_id).innerHTML;
  462. }
  463. function uploadthreadtypexml(formobj, formaction) {
  464. formobj.action = formaction;
  465. formobj.submit();
  466. }