space_diy.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. [Discuz!] (C)2001-2099 Comsenz Inc.
  3. This is NOT a freeware, use is subject to license terms
  4. $Id: space_diy.js 23838 2011-08-11 06:51:58Z monkey $
  5. */
  6. var drag = new Drag();
  7. drag.extend({
  8. setDefalutMenu : function () {
  9. this.addMenu('default', '删除', 'drag.removeBlock(event)');
  10. this.addMenu('block', '属性', 'drag.openBlockEdit(event)');
  11. },
  12. removeBlock : function (e) {
  13. if ( typeof e !== 'string') {
  14. e = Util.event(e);
  15. id = e.aim.id.replace('cmd_','');
  16. } else {
  17. id = e;
  18. }
  19. if (!confirm('您确实要删除吗,删除以后将不可恢复')) return false;
  20. $(id).parentNode.removeChild($(id));
  21. var el = $('chk'+id);
  22. if (el != null) el.className = '';
  23. this.initPosition();
  24. this.initChkBlock();
  25. },
  26. initChkBlock : function (data) {
  27. if (typeof name == 'undefined' || data == null ) data = this.data;
  28. if ( data instanceof Frame) {
  29. this.initChkBlock(data['columns']);
  30. } else if (data instanceof Block) {
  31. var el = $('chk'+data.name);
  32. if (el != null) el.className = 'activity';
  33. } else if (typeof data == 'object') {
  34. for (var i in data) {
  35. this.initChkBlock(data[i]);
  36. }
  37. }
  38. },
  39. toggleBlock : function (blockname) {
  40. var el = $('chk'+blockname);
  41. if (el != null) {
  42. if (el.className == '') {
  43. this.getBlockData(blockname);
  44. el.className = 'activity';
  45. } else {
  46. this.removeBlock(blockname);
  47. this.initPosition();
  48. }
  49. this.setClose();
  50. }
  51. },
  52. getBlockData : function (blockname) {
  53. var el = $(blockname);
  54. if (el != null) {
  55. Util.show(blockname);
  56. } else {
  57. var x = new Ajax();
  58. x.get('home.php?mod=spacecp&ac=index&op=getblock&blockname='+blockname+'&inajax=1',function(s) {
  59. if (s) {
  60. el = document.createElement("div");
  61. el.className = drag.blockClass + ' ' + drag.moveableObject;
  62. el.id = blockname;
  63. s = s.replace(/\<script.*\<\/script\>/ig,'<font color="red"> [javascript脚本保存后显示] </font>');
  64. el.innerHTML = s;
  65. var id = drag.data['diypage'][0]['columns']['frame1_left']['children'][0]['name'];
  66. $('frame1_left').insertBefore(el,$(id));
  67. drag.initPosition();
  68. }
  69. });
  70. }
  71. },
  72. openBlockEdit : function (e) {
  73. e = Util.event(e);
  74. var blockname = e.aim.id.replace('cmd_','');
  75. this.removeMenu();
  76. showWindow('showblock', 'home.php?mod=spacecp&ac=index&op=edit&blockname='+blockname,'get',0);
  77. }
  78. });
  79. var spaceDiy = new DIY();
  80. spaceDiy.extend({
  81. save:function () {
  82. drag.clearClose();
  83. document.diyform.spacecss.value = this.getSpacecssStr();
  84. document.diyform.style.value = this.style;
  85. document.diyform.layoutdata.value = drag.getPositionStr();
  86. document.diyform.currentlayout.value = this.currentLayout;
  87. document.diyform.submit();
  88. },
  89. getdiy : function (type) {
  90. var type_ = type == 'image' ? 'diy' : type;
  91. if (type_) {
  92. var nav = $('controlnav').children;
  93. for (var i in nav) {
  94. if (nav[i].className == 'current') {
  95. nav[i].className = '';
  96. }
  97. }
  98. $('nav'+type_).className = 'current';
  99. var para = '&op='+type;
  100. if (arguments.length > 1) {
  101. for (i = 1; i < arguments.length; i++) {
  102. para += '&' + arguments[i] + '=' + arguments[++i];
  103. }
  104. }
  105. var ajaxtarget = type == 'image' ? 'diyimages' : '';
  106. var x = new Ajax();
  107. x.showId = ajaxtarget;
  108. x.get('home.php?mod=spacecp&ac=index'+para+'&inajax=1&ajaxtarget='+ajaxtarget,function(s) {
  109. if (s) {
  110. drag.deleteFrame(['pb', 'bpb', 'tpb', 'lpb']);
  111. if (type == 'image') {
  112. $('diyimages').innerHTML = s;
  113. } else {
  114. $('controlcontent').innerHTML = s;
  115. x.showId = 'controlcontent';
  116. }
  117. if (type_ == 'block') {
  118. drag.initPosition();
  119. drag.initChkBlock();
  120. } else if (type_ == 'layout') {
  121. $('layout'+spaceDiy.currentLayout).className = 'activity';
  122. } else if (type_ == 'diy' && type != 'image') {
  123. spaceDiy.setCurrentDiy(spaceDiy.currentDiy);
  124. if (spaceDiy.styleSheet.rules.length > 0) {
  125. Util.show('recover_button');
  126. }
  127. }
  128. var evaled = false;
  129. if(s.indexOf('ajaxerror') != -1) {
  130. evalscript(s);
  131. evaled = true;
  132. }
  133. if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
  134. if(x.showId) {
  135. ajaxupdateevents($(x.showId));
  136. }
  137. }
  138. if(!evaled) evalscript(s);
  139. }
  140. });
  141. }
  142. },
  143. menuChange : function (tabs, menu) {
  144. var tabobj = $(tabs);
  145. var aobj = tabobj.getElementsByTagName("li");
  146. for(i=0; i<aobj.length; i++) {
  147. aobj[i].className = '';
  148. $(aobj[i].id+'_content').style.display = 'none';
  149. }
  150. $(menu).className = 'a';
  151. $(menu+'_content').style.display="block";
  152. doane(null);
  153. },
  154. delIframe : function (){
  155. drag.deleteFrame(['m_ctc', 'm_bc', 'm_fc']);
  156. },
  157. showEditSpaceInfo : function () {
  158. $('spaceinfoshow').style.display='none';
  159. if (!$('spaceinfoedit')) {
  160. var dom = document.createElement('h2');
  161. dom.id = 'spaceinfoedit';
  162. Util.insertBefore(dom, $('spaceinfoshow'));
  163. }
  164. ajaxget('home.php?mod=spacecp&ac=index&op=getspaceinfo','spaceinfoedit');
  165. },
  166. spaceInfoCancel : function () {
  167. if ($('spaceinfoedit')) $('spaceinfoedit').style.display = 'none';
  168. if ($('spaceinfoshow')) $('spaceinfoshow').style.display = 'inline';
  169. },
  170. spaceInfoSave : function () {
  171. ajaxpost('savespaceinfo','spaceinfoshow');
  172. },
  173. init : function () {
  174. drag.init();
  175. this.style = document.diyform.style.value;
  176. this.currentLayout = typeof document.diyform.currentlayout == 'undefined' ? '' : document.diyform.currentlayout.value;
  177. this.initStyleSheet();
  178. if (this.styleSheet.rules) this.initDiyStyle();
  179. this.initSpaceInfo();
  180. },
  181. initSpaceInfo : function () {
  182. this.spaceInfoCancel();
  183. if ($('spaceinfoshow')) {
  184. if (!$('infoedit')) {
  185. var dom = document.createElement('em');
  186. dom.id = 'infoedit';
  187. dom.innerHTML = '编辑';
  188. $('spacename').appendChild(dom);
  189. }
  190. $('spaceinfoshow').onmousedown = function () {spaceDiy.showEditSpaceInfo();};
  191. }
  192. if ($('nv')) {
  193. if(!$('nv').getElementsByTagName('li').length) {
  194. $('nv').getElementsByTagName('ul')[0].className = 'mininv';
  195. }
  196. $('nv').onmouseover = function () {spaceDiy.showEditNvInfo();};
  197. $('nv').onmouseout = function () {spaceDiy.hideEditNvInfo();};
  198. }
  199. },
  200. showEditNvInfo : function () {
  201. var nv = $('editnvinfo');
  202. if(!nv) {
  203. var dom = document.createElement('div');
  204. dom.innerHTML = '<span id="editnvinfo" class="edit" style="background-color:#336699;" onclick="spaceDiy.opNvEditInfo();">设置</span>';
  205. $('nv').appendChild(dom.childNodes[0]);
  206. } else {
  207. nv.style.display = '';
  208. }
  209. },
  210. hideEditNvInfo : function () {
  211. var nv = $('editnvinfo');
  212. if(nv) {
  213. nv.style.display = 'none';
  214. }
  215. },
  216. opNvEditInfo : function () {
  217. showWindow('showpersonalnv', 'home.php?mod=spacecp&ac=index&op=editnv','get',0);
  218. },
  219. getPersonalNv : function (show) {
  220. var x = new Ajax();
  221. show = !show ? '' : '&show=1';
  222. x.get('home.php?mod=spacecp&ac=index&op=getpersonalnv&inajax=1'+show, function(s) {
  223. if($('nv')) {
  224. $('hd').removeChild($('nv'));
  225. }
  226. var dom = document.createElement('div');
  227. dom.innerHTML = !s ? '&nbsp;' : s;
  228. $('hd').appendChild(dom.childNodes[0]);
  229. spaceDiy.initSpaceInfo();
  230. });
  231. }
  232. });
  233. spaceDiy.init();