common_diy.js 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899
  1. /*
  2. [Discuz!] (C)2001-2099 Comsenz Inc.
  3. This is NOT a freeware, use is subject to license terms
  4. $Id: common_diy.js 31093 2012-07-16 03:54:34Z zhangguosheng $
  5. */
  6. String.prototype.property2js = function(){
  7. var t = this.replace(/-([a-z])/g, function($0, $1) {return $1.toUpperCase();});
  8. return t;
  9. };
  10. function styleCss(n) {
  11. if(typeof n == "number") {
  12. var _s = document.styleSheets[n];
  13. } else {
  14. return false;
  15. }
  16. this.sheet = _s;
  17. this.rules = _s.cssRules ? _s.cssRules : _s.rules;
  18. };
  19. styleCss.prototype.indexOf = function(selector) {
  20. for(var i = 0; i < this.rules.length; i++) {
  21. if (typeof(this.rules[i].selectorText) == 'undefined') continue;
  22. if(this.rules[i].selectorText == selector) {
  23. return i;
  24. }
  25. }
  26. return -1;
  27. };
  28. styleCss.prototype.removeRule = function(n) {
  29. if(typeof n == "number") {
  30. if(n < this.rules.length) {
  31. this.sheet.removeRule ? this.sheet.removeRule(n) : this.sheet.deleteRule(n);
  32. }
  33. } else {
  34. var i = this.indexOf(n);
  35. if (i>0) this.sheet.removeRule ? this.sheet.removeRule(i) : this.sheet.deleteRule(i);
  36. }
  37. };
  38. styleCss.prototype.addRule = function(selector, styles, n, porperty) {
  39. var i = this.indexOf(selector);
  40. var s = '';
  41. var reg = '';
  42. if (i != -1) {
  43. reg = new RegExp('^'+porperty+'.*;','i');
  44. s = this.getRule(selector);
  45. if (s) {
  46. s = s.replace(selector,'').replace('{', '').replace('}', '').replace(/ /g, ' ').replace(/^ | $/g,'');
  47. s = (s != '' && s.substr(-1,1) != ';') ? s+ ';' : s;
  48. s = s.toLowerCase().replace(reg, '');
  49. if (s.length == 1) s = '';
  50. }
  51. this.removeRule(i);
  52. }
  53. s = s.indexOf('!important') > -1 || s.indexOf('! important') > -1 ? s : s.replace(/;/g,' !important;');
  54. s = s + styles;
  55. if (typeof n == 'undefined' || !isNaN(n)) {
  56. n = this.rules.length;
  57. }
  58. if (this.sheet.insertRule) {
  59. this.sheet.insertRule(selector+'{'+s+'}', n);
  60. } else {
  61. if (s) this.sheet.addRule(selector, s, n);
  62. }
  63. };
  64. styleCss.prototype.setRule = function(selector, attribute, value) {
  65. var i = this.indexOf(selector);
  66. if(-1 == i) return false;
  67. this.rules[i].style[attribute] = value;
  68. return true;
  69. };
  70. styleCss.prototype.getRule = function(selector, attribute) {
  71. var i = this.indexOf(selector);
  72. if(-1 == i) return '';
  73. var value = '';
  74. if (typeof attribute == 'undefined') {
  75. value = typeof this.rules[i].cssText != 'undefined' ? this.rules[i].cssText : this.rules[i].style['cssText'];
  76. } else {
  77. value = this.rules[i].style[attribute];
  78. }
  79. return typeof value != 'undefined' ? value : '';
  80. };
  81. styleCss.prototype.removeAllRule = function(noSearch) {
  82. var num = this.rules.length;
  83. var j = 0;
  84. for(var i = 0; i < num; i ++) {
  85. var selector = this.rules[this.rules.length - 1 - j].selectorText;
  86. if(noSearch == 1) {
  87. this.sheet.removeRule ? this.sheet.removeRule(this.rules.length - 1 - j) : this.sheet.deleteRule(this.rules.length - 1 - j);
  88. } else {
  89. j++;
  90. }
  91. }
  92. };
  93. if (!Array.prototype.indexOf) {
  94. Array.prototype.indexOf = function (element, index) {
  95. var length = this.length;
  96. if (index == null) {
  97. index = 0;
  98. } else {
  99. index = (!isNaN(index) ? index : parseInt(index));
  100. if (index < 0) index = length + index;
  101. if (index < 0) index = 0;
  102. }
  103. for (var i = index; i < length; i++) {
  104. var current = this[i];
  105. if (!(typeof(current) === 'undefined') || i in this) {
  106. if (current === element) return i;
  107. }
  108. }
  109. return -1;
  110. };
  111. }
  112. if (!Array.prototype.filter){
  113. Array.prototype.filter = function(fun , thisp){
  114. var len = this.length;
  115. if (typeof fun != "function")
  116. throw new TypeError();
  117. var res = new Array();
  118. var thisp = arguments[1];
  119. for (var i = 0; i < len; i++){
  120. if (i in this){
  121. var val = this[i];
  122. if (fun.call(thisp, val, i, this)) res.push(val);
  123. }
  124. }
  125. return res;
  126. };
  127. }
  128. var Util = {
  129. event: function(event){
  130. Util.e = event || window.event;
  131. Util.e.aim = Util.e.target || Util.e.srcElement;
  132. if (!Util.e.preventDefault) {
  133. Util.e.preventDefault = function(){
  134. Util.e.returnValue = false;
  135. };
  136. }
  137. if (!Util.e.stopPropagation) {
  138. Util.e.stopPropagation = function(){
  139. Util.e.cancelBubble = true;
  140. };
  141. }
  142. if (typeof Util.e.layerX == "undefined") {
  143. Util.e.layerX = Util.e.offsetX;
  144. }
  145. if (typeof Util.e.layerY == "undefined") {
  146. Util.e.layerY = Util.e.offsetY;
  147. }
  148. if (typeof Util.e.which == "undefined") {
  149. Util.e.which = Util.e.button;
  150. }
  151. return Util.e;
  152. },
  153. url: function(s){
  154. var s2 = s.replace(/(\(|\)|\,|\s|\'|\"|\\)/g, '\\$1');
  155. if (/\\\\$/.test(s2)) {
  156. s2 += ' ';
  157. }
  158. return "url('" + s2 + "')";
  159. },
  160. trimUrl : function(s){
  161. var s2 = s.toLowerCase().replace(/url\(|\"|\'|\)/g,'');
  162. return s2;
  163. },
  164. swapDomNodes: function(a, b){
  165. var afterA = a.nextSibling;
  166. if (afterA == b) {
  167. swapDomNodes(b, a);
  168. return;
  169. }
  170. var aParent = a.parentNode;
  171. b.parentNode.replaceChild(a, b);
  172. aParent.insertBefore(b, afterA);
  173. },
  174. hasClass: function(el, name){
  175. return el && el.nodeType == 1 && el.className.split(/\s+/).indexOf(name) != -1;
  176. },
  177. addClass: function(el, name){
  178. el.className += this.hasClass(el, name) ? '' : ' ' + name;
  179. },
  180. removeClass: function(el, name){
  181. var names = el.className.split(/\s+/);
  182. el.className = names.filter(function(n){
  183. return name != n;
  184. }).join(' ');
  185. },
  186. getTarget: function(e, attributeName, value){
  187. var target = e.target || e.srcElement;
  188. while (target != null) {
  189. if (attributeName == 'className') {
  190. if (this.hasClass(target, value)) {
  191. return target;
  192. }
  193. }else if (target[attributeName] == value) {
  194. return target;
  195. }
  196. target = target.parentNode;
  197. }
  198. return false;
  199. },
  200. getOffset:function (el, isLeft) {
  201. var retValue = 0 ;
  202. while (el != null ) {
  203. retValue += el["offset" + (isLeft ? "Left" : "Top" )];
  204. el = el.offsetParent;
  205. }
  206. return retValue;
  207. },
  208. insertBefore: function (newNode, targetNode) {
  209. var parentNode = targetNode.parentNode;
  210. var next = targetNode.nextSibling;
  211. if (targetNode.id && targetNode.id.indexOf('temp')>-1) {
  212. parentNode.insertBefore(newNode,targetNode);
  213. } else if (!next) {
  214. parentNode.appendChild(newNode);
  215. } else {
  216. parentNode.insertBefore(newNode,targetNode);
  217. }
  218. },
  219. insertAfter : function (newNode, targetNode) {
  220. var parentNode = targetNode.parentNode;
  221. var next = targetNode.nextSibling;
  222. if (next) {
  223. parentNode.insertBefore(newNode,next);
  224. } else {
  225. parentNode.appendChild(newNode);
  226. }
  227. },
  228. getScroll: function () {
  229. var t, l, w, h;
  230. if (document.documentElement && document.documentElement.scrollTop) {
  231. t = document.documentElement.scrollTop;
  232. l = document.documentElement.scrollLeft;
  233. w = document.documentElement.scrollWidth;
  234. h = document.documentElement.scrollHeight;
  235. } else if (document.body) {
  236. t = document.body.scrollTop;
  237. l = document.body.scrollLeft;
  238. w = document.body.scrollWidth;
  239. h = document.body.scrollHeight;
  240. }
  241. return {t: t, l: l, w: w, h: h};
  242. },
  243. hide:function (ele){
  244. if (typeof ele == 'string') {ele = $(ele);}
  245. if (ele){ele.style.display = 'none';ele.style.visibility = 'hidden';}
  246. },
  247. show:function (ele){
  248. if (typeof ele == 'string') {ele = $(ele);}
  249. if (ele) {
  250. this.removeClass(ele, 'hide');
  251. ele.style.display = '';
  252. ele.style.visibility = 'visible';
  253. }
  254. },
  255. cancelSelect : function () {
  256. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  257. },
  258. getSelectText : function () {
  259. var t = '';
  260. if (window.getSelection) {
  261. t = window.getSelection();
  262. } else if (document.getSelection) {
  263. t = document.getSelection();
  264. } else if (document.selection) {
  265. t = document.selection.createRange().text;
  266. } else {
  267. t = '';
  268. }
  269. return t;
  270. },
  271. toggleEle : function (ele) {
  272. ele = (typeof ele !='object') ? $(ele) : ele;
  273. if (!ele) return false;
  274. var value = this.getFinallyStyle(ele,'display');
  275. if (value =='none') {
  276. this.show(ele);
  277. this.hide($('uploadmsg_button'));
  278. } else {
  279. this.hide(ele);
  280. this.show($('uploadmsg_button'));
  281. }
  282. },
  283. getFinallyStyle : function (ele,property) {
  284. ele = (typeof ele !='object') ? $(ele) : ele;
  285. var style = (typeof(ele['currentStyle']) == 'undefined') ? window.getComputedStyle(ele,null)[property] : ele['currentStyle'][property];
  286. if (typeof style == 'undefined' && property == 'backgroundPosition') {
  287. style = ele['currentStyle']['backgroundPositionX'] + ' ' +ele['currentStyle']['backgroundPositionY'];
  288. }
  289. return style;
  290. },
  291. recolored:function (){
  292. var b = document.body;
  293. b.style.zoom = b.style.zoom=="1"?"100%":"1";
  294. },
  295. getRandom : function (len,type) {
  296. len = len < 0 ? 0 : len;
  297. type = type && type<=3? type : 3;
  298. var str = '';
  299. for (var i = 0; i < len; i++) {
  300. var j = Math.ceil(Math.random()*type);
  301. if (j == 1) {
  302. str += Math.ceil(Math.random()*9);
  303. } else if (j == 2) {
  304. str += String.fromCharCode(Math.ceil(Math.random()*25+65));
  305. } else {
  306. str += String.fromCharCode(Math.ceil(Math.random()*25+97));
  307. }
  308. }
  309. return str;
  310. },
  311. fade : function(obj,timer,ftype,cur,fn) {
  312. if (this.stack == undefined) {this.stack = [];}
  313. obj = typeof obj == 'string' ? $(obj) : obj;
  314. if (!obj) return false;
  315. for (var i=0;i<this.stack.length;i++) {
  316. if (this.stack[i] == obj && (cur == 0 || cur == 100)) return false;
  317. }
  318. if (cur == 0 || cur == 100) {this.stack.push(obj);}
  319. ftype = ftype != 'in' && ftype != 'out' ? 'out' : ftype;
  320. timer = timer || 400;
  321. var step = 100/(timer/20);
  322. obj.style.filter = 'Alpha(opacity=' + cur + ')';
  323. obj.style.opacity = cur / 100;
  324. cur = ftype == 'in' ? cur + step : cur - step ;
  325. var fadeTimer = (function(){
  326. return setTimeout(function () {
  327. Util.fade(obj, timer, ftype, cur, fn);
  328. }, 20);
  329. })();
  330. this[ftype == 'in' ? 'show' : 'hide'](obj);
  331. if(ftype == 'in' && cur >= 100 || ftype == 'out' && cur <= 0) {
  332. clearTimeout(fadeTimer);
  333. for (i=0;i<this.stack.length;i++) {
  334. if (this.stack[i] == obj ) {
  335. this.stack.splice(i,1);break;
  336. }
  337. }
  338. fn = fn || function(){};
  339. fn(obj);
  340. }
  341. return obj;
  342. },
  343. fadeIn : function (obj,timer,fn) {
  344. return this.fade(obj, timer, 'in', 0, fn);
  345. },
  346. fadeOut : function (obj,timer,fn) {
  347. return this.fade(obj, timer, 'out', 100, fn);
  348. },
  349. getStyle : function (ele) {
  350. if (ele) {
  351. var s = ele.getAttribute('style') || '';
  352. return typeof s == 'object' ? s.cssText : s;
  353. }
  354. return false;
  355. },
  356. setStyle : function (ele,cssText) {
  357. if (ele) {
  358. var s = ele.getAttribute('style') || '';
  359. return typeof s == 'object' ? s.cssText = cssText : ele.setAttribute('style',cssText);
  360. }
  361. return false;
  362. },
  363. getText : function (ele) {
  364. var t = ele.innerText ? ele.innerText : ele.textContent;
  365. return !t ? '' : t;
  366. },
  367. rgb2hex : function (color) {
  368. if (!color) return '';
  369. var reg = new RegExp('(\\d+)[, ]+(\\d+)[, ]+(\\d+)','g');
  370. var rgb = reg.exec(color);
  371. if (rgb == null) rgb = [0,0,0,0];
  372. var red = rgb[1], green = rgb[2], blue = rgb[3];
  373. var decColor = 65536 * parseInt(red) + 256 * parseInt(green) + parseInt(blue);
  374. var hex = decColor.toString(16).toUpperCase();
  375. var pre = new Array(6 - hex.length + 1).join('0');
  376. hex = pre + hex;
  377. return hex;
  378. },
  379. formatColor : function (color) {
  380. return color == '' || color.indexOf('#')>-1 || color.toLowerCase() == 'transparent' ? color : '#'+Util.rgb2hex(color);
  381. }
  382. };
  383. (function(){
  384. Frame = function(name, className, top, left, moveable){
  385. this.name = name;
  386. this.top = top;
  387. this.left = left;
  388. this.moveable = moveable ? true : false;
  389. this.columns = [];
  390. this.className = className;
  391. this.titles = [];
  392. if (typeof Frame._init == 'undefined') {
  393. Frame.prototype.addColumn = function (column) {
  394. if (column instanceof Column) {
  395. this.columns[column.name] = column;
  396. }
  397. };
  398. Frame.prototype.addFrame = function(columnId, frame) {
  399. if (frame instanceof Frame || frame instanceof Tab){
  400. this.columns[columnId].children.push(frame);
  401. }
  402. };
  403. Frame.prototype.addBlock = function(columnId, block) {
  404. if (block instanceof Block){
  405. this.columns[columnId].children.push(block);
  406. }
  407. };
  408. }
  409. Frame._init = true;
  410. };
  411. Column = function (name, className) {
  412. this.name = name;
  413. this.className = className;
  414. this.children = [];
  415. };
  416. Tab = function (name, className, top, left, moveable) {
  417. Frame.apply(this, arguments);
  418. };
  419. Tab.prototype = new Frame();
  420. Block = function(name, className, top, left) {
  421. this.name = name;
  422. this.top = top;
  423. this.left = left;
  424. this.className = className;
  425. this.titles = [];
  426. };
  427. Drag = function () {
  428. this.data = [];
  429. this.scroll = {};
  430. this.menu = [];
  431. this.data = [];
  432. this.allBlocks = [];
  433. this.overObj = '';
  434. this.dragObj = '';
  435. this.dragObjFrame = '';
  436. this.overObjFrame = '';
  437. this.isDragging = false;
  438. this.layout = 2;
  439. this.frameClass = 'frame';
  440. this.blockClass = 'block';
  441. this.areaClass = 'area';
  442. this.moveableArea = [];
  443. this.moveableColumn = 'column';
  444. this.moveableObject = 'move-span';
  445. this.titleClass = 'title';
  446. this.hideClass = 'hide';
  447. this.titleTextClass = 'titletext';
  448. this.frameTitleClass = 'frame-title',
  449. this.tabClass = 'frame-tab';
  450. this.tabActivityClass = 'tabactivity';
  451. this.tabTitleClass = 'tab-title';
  452. this.tabContentClass = 'tb-c';
  453. this.moving = 'moving';
  454. this.contentClass = 'dxb_bc';
  455. this.tmpBoxElement = null ;
  456. this.dargRelative = {};
  457. this.scroll = {};
  458. this.menu = [];
  459. this.rein = [];
  460. this.newFlag = false;
  461. this.isChange = false;
  462. this.fn = '';
  463. this._replaceFlag = false;
  464. this.sampleMode = false;
  465. this.sampleBlocks = null;
  466. this.advancedStyleSheet = null;
  467. };
  468. Drag.prototype = {
  469. getTmpBoxElement : function () {
  470. if (!this.tmpBoxElement) {
  471. this.tmpBoxElement = document.createElement("div");
  472. this.tmpBoxElement.id = 'tmpbox';
  473. this.tmpBoxElement.className = "tmpbox" ;
  474. this.tmpBoxElement.style.width = this.overObj.offsetWidth-4+"px";
  475. this.tmpBoxElement.style.height = this.overObj.offsetHeight-4+"px";
  476. } else if (this.overObj && this.overObj.offsetWidth > 0) {
  477. this.tmpBoxElement.style.width = this.overObj.offsetWidth-4+"px";
  478. }
  479. return this.tmpBoxElement;
  480. },
  481. getPositionStr : function (){
  482. this.initPosition();
  483. var start = '<?xml version="1.0" encoding="ISO-8859-1"?><root>';
  484. var end ="</root>";
  485. var str = "";
  486. for (var i in this.data) {
  487. if (typeof this.data[i] == 'function') continue;
  488. str += '<item id="' + i + '">';
  489. for (var j in this.data[i]) {
  490. if (!(this.data[i][j] instanceof Frame || this.data[i][j] instanceof Tab)) continue;
  491. str += this._getFrameXML(this.data[i][j]);
  492. }
  493. str += '</item>';
  494. }
  495. return start + str + end;
  496. },
  497. _getFrameXML : function (frame) {
  498. if (!(frame instanceof Frame || frame instanceof Tab) || frame.name.indexOf('temp') > 0) return '';
  499. var itemId = frame instanceof Tab ? 'tab' : 'frame';
  500. var Cstr = "";
  501. var name = frame.name;
  502. var frameAttr = this._getAttrXML(frame);
  503. var columns = frame['columns'];
  504. for (var j in columns) {
  505. if (columns[j] instanceof Column) {
  506. var Bstr = '';
  507. var colChildren = columns[j].children;
  508. for (var k in colChildren) {
  509. if (k == 'attr' || typeof colChildren[k] == 'function' || colChildren[k].name.indexOf('temp') > 0) continue;
  510. if (colChildren[k] instanceof Block) {
  511. Bstr += '<item id="block`' + colChildren[k]['name'] + '">';
  512. Bstr += this._getAttrXML(colChildren[k]);
  513. Bstr += '</item>';
  514. } else if (colChildren[k] instanceof Frame || colChildren[k] instanceof Tab) {
  515. Bstr += this._getFrameXML(colChildren[k]);
  516. }
  517. }
  518. var columnAttr = this._getAttrXML(columns[j]);
  519. Cstr += '<item id="column`' + j + '">' + columnAttr + Bstr + '</item>';
  520. }
  521. }
  522. return '<item id="' + itemId + '`' + name + '">' + frameAttr + Cstr + '</item>';
  523. },
  524. _getAttrXML : function (obj) {
  525. var attrXml = '<item id="attr">';
  526. var trimAttr = ['left', 'top'];
  527. var xml = '';
  528. if (obj instanceof Frame || obj instanceof Tab || obj instanceof Block || obj instanceof Column) {
  529. for (var i in obj) {
  530. if (i == 'titles') {
  531. xml += this._getTitlesXML(obj[i]);
  532. }
  533. if (!(typeof obj[i] == 'object' || typeof obj[i] == 'function')) {
  534. if (trimAttr.indexOf(i) >= 0) continue;
  535. xml += '<item id="' + i + '"><![CDATA[' + obj[i] + ']]></item>';
  536. }
  537. }
  538. }else {
  539. xml += '';
  540. }
  541. return attrXml + xml + '</item>';
  542. },
  543. _getTitlesXML : function (titles) {
  544. var xml = '<item id="titles">';
  545. for (var i in titles) {
  546. if (typeof titles[i] == 'function') continue;
  547. xml += '<item id="'+i+'">';
  548. for (var j in titles[i]) {
  549. if (typeof titles[i][j] == 'function') continue;
  550. xml += '<item id="'+j+'"><![CDATA[' + titles[i][j] + ']]></item>';
  551. }
  552. xml += '</item>';
  553. }
  554. xml += '</item>';
  555. return xml;
  556. },
  557. getCurrentOverObj : function (e) {
  558. var _clientX = parseInt(this.dragObj.style.left);
  559. var _clientY = parseInt(this.dragObj.style.top);
  560. var max = 10000000;
  561. for (var i in this.data) {
  562. for (var j in this.data[i]) {
  563. if (!(this.data[i][j] instanceof Frame || this.data[i][j] instanceof Tab)) continue;
  564. var min = this._getMinDistance(this.data[i][j], max);
  565. if (min.distance < max) {
  566. var id = min.id;
  567. max = min.distance;
  568. }
  569. }
  570. }
  571. return $(id);
  572. },
  573. _getMinDistance : function (ele, max) {
  574. if(ele.name==this.dragObj.id) return {"id":ele.name, "distance":max};
  575. var _clientX = parseInt(this.dragObj.style.left);
  576. var _clientY = parseInt(this.dragObj.style.top);
  577. var id;
  578. var isTabInTab = Util.hasClass(this.dragObj, this.tabClass) && Util.hasClass($(ele.name).parentNode.parentNode, this.tabClass);
  579. if (ele instanceof Frame || ele instanceof Tab) {
  580. if (ele.moveable && !isTabInTab) {
  581. var isTab = Util.hasClass(this.dragObj, this.tabClass);
  582. var isFrame = Util.hasClass(this.dragObj, this.frameClass);
  583. var isBlock = Util.hasClass(this.dragObj, this.blockClass) && Util.hasClass($(ele.name).parentNode, this.moveableColumn);
  584. if ( isTab || isFrame || isBlock) {
  585. var _Y = ele['top'] - _clientY;
  586. var _X = ele['left'] - _clientX;
  587. var distance = Math.sqrt(Math.pow(_X, 2) + Math.pow(_Y, 2));
  588. if (distance < max) {
  589. max = distance;
  590. id = ele.name;
  591. }
  592. }
  593. }
  594. for (var i in ele['columns']) {
  595. var column = ele['columns'][i];
  596. if (column instanceof Column) {
  597. for (var j in column['children']) {
  598. if ((column['children'][j] instanceof Tab || column['children'][j] instanceof Frame || column['children'][j] instanceof Block)) {
  599. var min = this._getMinDistance(column['children'][j], max);
  600. if (min.distance < max) {
  601. id = min.id;
  602. max = min.distance;
  603. }
  604. }
  605. }
  606. }
  607. }
  608. return {"id":id, "distance":max};
  609. } else {
  610. if (isTabInTab) return {'id': ele['name'], 'distance': max};
  611. var _Y = ele['top'] - _clientY;
  612. var _X = ele['left'] - _clientX;
  613. var distance = Math.sqrt(Math.pow(_X, 2) + Math.pow(_Y, 2));
  614. if (distance < max) {
  615. return {'id': ele['name'], 'distance': distance};
  616. } else {
  617. return {'id': ele['name'], 'distance': max};
  618. }
  619. }
  620. },
  621. getObjByName : function (name, data) {
  622. if (!name) return false;
  623. data = data || this.data;
  624. if ( data instanceof Frame) {
  625. if (data.name == name) {
  626. return data;
  627. } else {
  628. var d = this.getObjByName(name,data['columns']);
  629. if (name == d.name) return d;
  630. }
  631. } else if (data instanceof Block) {
  632. if (data.name == name) return data;
  633. } else if (typeof data == 'object') {
  634. for (var i in data) {
  635. var d = this.getObjByName(name, data[i]);
  636. if (name == d.name) return d;
  637. }
  638. }
  639. return false;
  640. },
  641. initPosition : function () {
  642. this.data = [],this.allBlocks = [];
  643. var blocks = $C(this.blockClass);
  644. for(var i = 0; i < blocks.length; i++) {
  645. if (blocks[i]['id'].indexOf('temp') < 0) {
  646. this.checkEdit(blocks[i]);
  647. this.allBlocks.push(blocks[i]['id'].replace('portal_block_',''));
  648. }
  649. }
  650. var areaLen = this.moveableArea.length;
  651. for (var j = 0; j < areaLen; j++ ) {
  652. var area = this.moveableArea[j];
  653. var areaData = [];
  654. if (typeof area == 'object') {
  655. this.checkTempDiv(area.id);
  656. var frames = area.childNodes;
  657. for (var i in frames) {
  658. if (typeof(frames[i]) != 'object') continue;
  659. if (Util.hasClass(frames[i], this.frameClass) || Util.hasClass(frames[i], this.blockClass)
  660. || Util.hasClass(frames[i], this.tabClass) || Util.hasClass(frames[i], this.moveableObject)) {
  661. areaData.push(this.initFrame(frames[i]));
  662. }
  663. }
  664. this.data[area.id] = areaData;
  665. }
  666. }
  667. this._replaceFlag = true;
  668. },
  669. removeBlockPointer : function(e) {this.removeBlock(e);},
  670. toggleContent : function (e) {
  671. if ( typeof e !== 'string') {
  672. e = Util.event(e);
  673. var id = e.aim.id.replace('_edit_toggle','');
  674. } else {
  675. id = e;
  676. }
  677. var obj = this.getObjByName(id);
  678. var display = '';
  679. if (obj instanceof Block || obj instanceof Tab) {
  680. display = $(id+'_content').style.display;
  681. Util.toggleEle(id+'_content');
  682. } else {
  683. var col = obj.columns;
  684. for (var i in col) {
  685. display = $(i).style.display;
  686. Util.toggleEle($(i));
  687. }
  688. }
  689. if(display != '') {
  690. e.aim.src=STATICURL+'/image/common/fl_collapsed_no.gif';
  691. } else {
  692. e.aim.src=STATICURL+'/image/common/fl_collapsed_yes.gif';
  693. }
  694. },
  695. checkEdit : function (ele) {
  696. if (!ele || Util.hasClass(ele, 'temp') || ele.getAttribute('noedit')) return false;
  697. var id = ele.id;
  698. var _method = this;
  699. if (!$(id+'_edit')) {
  700. var _method = this;
  701. var dom = document.createElement('div');
  702. dom.className = 'edit hide';
  703. dom.id = id+'_edit';
  704. dom.innerHTML = '<span id="'+id+'_edit_menu">编辑</span>';
  705. ele.appendChild(dom);
  706. $(id+'_edit_menu').onclick = function (e){Drag.prototype.toggleMenu.call(_method, e, this);};
  707. }
  708. ele.onmouseover = function (e) {Drag.prototype.showEdit.call(_method,e);};
  709. ele.onmouseout = function (e) {Drag.prototype.hideEdit.call(_method,e);};
  710. },
  711. initFrame : function (frameEle) {
  712. if (typeof(frameEle) != 'object') return '';
  713. var frameId = frameEle.id;
  714. if(!this.sampleMode) {
  715. this.checkEdit(frameEle);
  716. }
  717. var moveable = Util.hasClass(frameEle, this.moveableObject);
  718. var frameObj = '';
  719. if (Util.hasClass(frameEle, this.tabClass)) {
  720. this._initTabActivity(frameEle);
  721. frameObj = new Tab(frameId, frameEle.className, Util.getOffset(frameEle,false), Util.getOffset(frameEle,true), moveable);
  722. } else if (Util.hasClass(frameEle, this.frameClass) || Util.hasClass(frameEle, this.moveableObject)) {
  723. if (Util.hasClass(frameEle, this.frameClass) && !this._replaceFlag) this._replaceFrameColumn(frameEle);
  724. frameObj = new Frame(frameId, frameEle.className, Util.getOffset(frameEle,false), Util.getOffset(frameEle,true), moveable);
  725. }
  726. this._initColumn(frameObj, frameEle);
  727. return frameObj;
  728. },
  729. _initColumn : function (frameObj,frameEle) {
  730. var columns = frameEle.children;
  731. if (Util.hasClass(frameEle.parentNode.parentNode,this.tabClass)) {
  732. var col2 = $(frameEle.id+'_content').children;
  733. var len = columns.length;
  734. for (var i in col2) {
  735. if (typeof(col2[i]) == 'object') columns[len+i] = col2[i];
  736. }
  737. }
  738. for (var i in columns) {
  739. if (typeof(columns[i]) != 'object') continue;
  740. if (Util.hasClass(columns[i], this.titleClass)) {
  741. this._initTitle(frameObj, columns[i]);
  742. }
  743. this._initEleTitle(frameObj, frameEle);
  744. if (Util.hasClass(columns[i], this.moveableColumn)) {
  745. var columnId = columns[i].id;
  746. var column = new Column(columnId, columns[i].className);
  747. frameObj.addColumn(column);
  748. this.checkTempDiv(columnId);
  749. var elements = columns[i].children;
  750. var eleLen = elements.length;
  751. for (var j = 0; j < eleLen; j++) {
  752. var ele = elements[j];
  753. if (Util.hasClass(ele, this.frameClass) || Util.hasClass(ele, this.tabClass)) {
  754. var frameObj2 = this.initFrame(ele);
  755. frameObj.addFrame(columnId, frameObj2);
  756. } else if (Util.hasClass(ele, this.blockClass) || Util.hasClass(ele, this.moveableObject)) {
  757. var block = new Block(ele.id, ele.className, Util.getOffset(ele, false), Util.getOffset(ele, true));
  758. for (var k in ele.children) {
  759. if (Util.hasClass(ele.children[k], this.titleClass)) this._initTitle(block, ele.children[k]);
  760. }
  761. this._initEleTitle(block, ele);
  762. frameObj.addBlock(columnId, block);
  763. }
  764. }
  765. }
  766. }
  767. },
  768. _initTitle : function (obj, ele) {
  769. if (Util.hasClass(ele, this.titleClass)) {
  770. obj.titles['className'] = [ele.className];
  771. obj.titles['style'] = {};
  772. if (ele.style.backgroundImage) obj.titles['style']['background-image'] = ele.style.backgroundImage;
  773. if (ele.style.backgroundRepeat) obj.titles['style']['background-repeat'] = ele.style.backgroundRepeat;
  774. if (ele.style.backgroundColor) obj.titles['style']['background-color'] = ele.style.backgroundColor;
  775. if (obj instanceof Tab) {
  776. obj.titles['switchType'] = [];
  777. obj.titles['switchType'][0] = ele.getAttribute('switchtype') ? ele.getAttribute('switchtype') : 'click';
  778. }
  779. var ch = ele.children;
  780. for (var k in ch) {
  781. if (Util.hasClass(ch[k], this.titleTextClass)){
  782. this._getTitleData(obj, ch[k], 'first');
  783. } else if (typeof ch[k] == 'object' && !Util.hasClass(ch[k], this.moveableObject)) {
  784. this._getTitleData(obj, ch[k]);
  785. }
  786. }
  787. }
  788. },
  789. _getTitleData : function (obj, ele, i) {
  790. var shref = '',ssize = '',sfloat = '',scolor = '',smargin = '',stext = '', src = '';
  791. var collection = ele.getElementsByTagName('a');
  792. if (collection.length > 0) {
  793. shref = collection[0]['href'];
  794. scolor = collection[0].style['color'] + ' !important';
  795. }
  796. collection = ele.getElementsByTagName('img');
  797. if (collection.length > 0) {
  798. src = collection[0]['src'];
  799. }
  800. stext = Util.getText(ele);
  801. if (stext || src) {
  802. scolor = scolor ? scolor : ele.style['color'];
  803. sfloat = ele.style['styleFloat'] ? ele.style['styleFloat'] : ele.style['cssFloat'] ;
  804. sfloat = sfloat == undefined ? '' : sfloat;
  805. var margin_ = sfloat == '' ? 'left' : sfloat;
  806. smargin = parseInt(ele.style[('margin-'+margin_).property2js()]);
  807. smargin = smargin ? smargin : '';
  808. ssize = parseInt(ele.style['fontSize']);
  809. ssize = ssize ? ssize : '';
  810. var data = {'text':stext, 'href':shref,'color':scolor, 'float':sfloat, 'margin':smargin, 'font-size':ssize, 'className':ele.className, 'src':src};
  811. if (i) {
  812. obj.titles[i] = data;
  813. } else {
  814. obj.titles.push(data);
  815. }
  816. }
  817. },
  818. _initEleTitle : function (obj,ele) {
  819. if (Util.hasClass(ele, this.moveableObject)) {
  820. if (obj.titles['first'] && obj.titles['first']['text']) {
  821. var title = obj.titles['first']['text'];
  822. } else {
  823. var title = obj.name;
  824. }
  825. }
  826. },
  827. showBlockName : function (ele) {
  828. var title = $C('block-name', ele, 'div');
  829. if(title.length) {
  830. Util.show(title[0]);
  831. }
  832. },
  833. hideBlockName : function (ele) {
  834. var title = $C('block-name', ele, 'div');
  835. if(title.length) {
  836. Util.hide(title[0]);
  837. }
  838. },
  839. showEdit : function (e) {
  840. e = Util.event(e);
  841. var targetObject = Util.getTarget(e,'className',this.moveableObject);
  842. if (targetObject) {
  843. Util.show(targetObject.id + '_edit');
  844. targetObject.style.backgroundColor="#fffacd";
  845. this.showBlockName(targetObject);
  846. } else {
  847. var targetFrame = Util.getTarget(e,'className',this.frameClass);
  848. if (typeof targetFrame == 'object') {
  849. Util.show(targetFrame.id + '_edit');
  850. targetFrame.style.backgroundColor="#fffacd";
  851. }
  852. }
  853. },
  854. hideEdit : function (e) {
  855. e = Util.event(e);
  856. var targetObject = Util.getTarget(e,'className',this.moveableObject);
  857. var targetFrame = Util.getTarget(e,'className',this.frameClass);
  858. if (typeof targetFrame == 'object') {
  859. Util.hide(targetFrame.id + '_edit');
  860. targetFrame.style.backgroundColor = '';
  861. }
  862. if (typeof targetObject == 'object') {
  863. Util.hide(targetObject.id + '_edit');
  864. targetObject.style.backgroundColor = '';
  865. this.hideBlockName(targetObject);
  866. }
  867. },
  868. toggleMenu : function (e, obj) {
  869. e = Util.event(e);
  870. e.stopPropagation();
  871. var objPara = {'top' : Util.getOffset( obj, false),'left' : Util.getOffset( obj, true),
  872. 'width' : obj['offsetWidth'], 'height' : obj['offsetHeight']};
  873. var dom = $('edit_menu');
  874. if (dom) {
  875. if (objPara.top + objPara.height == Util.getOffset(dom, false) && objPara.left == Util.getOffset(dom, true)) {
  876. dom.parentNode.removeChild(dom);
  877. } else {
  878. dom.style.top = objPara.top + objPara.height + 'px';
  879. dom.style.left = objPara.left + 'px';
  880. dom.innerHTML = this._getMenuHtml(e, obj);
  881. }
  882. } else {
  883. var html = this._getMenuHtml(e, obj);
  884. if (html != '') {
  885. dom = document.createElement('div');
  886. dom.id = 'edit_menu';
  887. dom.className = 'edit-menu';
  888. dom.style.top = objPara.top + objPara.height + 'px';
  889. dom.style.left = objPara.left + 'px';
  890. dom.innerHTML = html;
  891. document.body.appendChild(dom);
  892. var _method = this;
  893. document.body.onclick = function(e){Drag.prototype.removeMenu.call(_method, e);};
  894. }
  895. }
  896. },
  897. _getMenuHtml : function (e,obj) {
  898. var id = obj.id.replace('_edit_menu','');
  899. var html = '<ul>';
  900. if (typeof this.menu[id] == 'object') html += this._getMenuHtmlLi(id, this.menu[id]);
  901. if (Util.hasClass($(id),this.tabClass) && typeof this.menu['tab'] == 'object') html += this._getMenuHtmlLi(id, this.menu['tab']);
  902. if (Util.hasClass($(id),this.frameClass) && typeof this.menu['frame'] == 'object') html += this._getMenuHtmlLi(id, this.menu['frame']);
  903. if (Util.hasClass($(id),this.blockClass) && typeof this.menu['block'] == 'object') html += this._getMenuHtmlLi(id, this.menu['block']);
  904. if (typeof this.menu['default'] == 'object' && this.getObjByName(id)) html += this._getMenuHtmlLi(id, this.menu['default']);
  905. html += '</ul>';
  906. return html == '<ul></ul>' ? '' : html;
  907. },
  908. _getMenuHtmlLi : function (id, cmds) {
  909. var li = '';
  910. var len = cmds.length;
  911. for (var i=0; i<len; i++) {
  912. li += '<li class="mitem" id="cmd_'+id+'" onclick='+"'"+cmds[i]['cmd']+"'"+'>'+cmds[i]['cmdName']+'</li>';
  913. }
  914. return li;
  915. },
  916. removeMenu : function (e) {
  917. var dom = $('edit_menu');
  918. if (dom) dom.parentNode.removeChild(dom);
  919. document.body.onclick = '';
  920. },
  921. addMenu : function (objId,cmdName,cmd) {
  922. if (typeof this.menu[objId] == 'undefined') this.menu[objId] = [];
  923. this.menu[objId].push({'cmdName':cmdName, 'cmd':cmd});
  924. },
  925. setDefalutMenu : function () {},
  926. setSampleMenu : function () {},
  927. getPositionKey : function (n) {
  928. this.initPosition();
  929. n = parseInt(n);
  930. var i = 0;
  931. for (var k in this.position) {
  932. if (i++ >= n) break;
  933. }
  934. return k;
  935. },
  936. checkTempDiv : function (_id) {
  937. if(_id) {
  938. var id = _id+'_temp';
  939. var dom = $(id);
  940. if (dom == null || typeof dom == 'undefined') {
  941. dom = document.createElement("div");
  942. dom.className = this.moveableObject+' temp';
  943. dom.id = id;
  944. $(_id).appendChild(dom);
  945. }
  946. }
  947. },
  948. _setCssPosition : function (ele, value) {
  949. while (ele && ele.parentNode && ele.id != 'ct') {
  950. if (Util.hasClass(ele,this.frameClass) || Util.hasClass(ele,this.tabClass)) ele.style.position = value;
  951. ele = ele.parentNode;
  952. }
  953. },
  954. initDragObj : function (e) {
  955. e = Util.event(e);
  956. var target = Util.getTarget(e,'className',this.moveableObject);
  957. if (!target) {return false;}
  958. if (this.overObj != target && target.id !='tmpbox') {
  959. this.overObj = target;
  960. this.overObj.style.cursor = 'move';
  961. }
  962. },
  963. dragStart : function (e) {
  964. e = Util.event(e);
  965. if (e.aim['id'] && e.aim['id'].indexOf && e.aim['id'].indexOf('_edit') > 0) return false;
  966. if(e.which != 1 ) {return false;}
  967. this.overObj = this.dragObj = Util.getTarget(e,'className',this.moveableObject);
  968. if (!this.dragObj || Util.hasClass(this.dragObj,'temp')) {return false;}
  969. if (!this.getTmpBoxElement()) return false;
  970. this.getRelative();
  971. this._setCssPosition(this.dragObj.parentNode.parentNode, "static");
  972. var offLeft = Util.getOffset( this.dragObj, true );
  973. var offTop = Util.getOffset( this.dragObj, false );
  974. var offWidth = this.dragObj['offsetWidth'];
  975. this.dragObj.style.position = 'absolute';
  976. this.dragObj.style.left = offLeft + "px";
  977. this.dragObj.style.top = offTop - 3 + "px";
  978. this.dragObj.style.width = offWidth + 'px';
  979. this.dragObj.lastMouseX = e.clientX;
  980. this.dragObj.lastMouseY = e.clientY;
  981. Util.insertBefore(this.tmpBoxElement,this.overObj);
  982. Util.addClass(this.dragObj,this.moving);
  983. this.dragObj.style.zIndex = 500 ;
  984. this.scroll = Util.getScroll();
  985. var _method = this;
  986. document.onscroll = function(){Drag.prototype.resetObj.call(_method, e);};
  987. window.onscroll = function(){Drag.prototype.resetObj.call(_method, e);};
  988. document.onmousemove = function (e){Drag.prototype.drag.call(_method, e);};
  989. },
  990. getRelative : function () {
  991. this.dargRelative = {'up': this.dragObj.previousSibling, 'down': this.dragObj.nextSibling};
  992. },
  993. resetObj : function (e) {
  994. if (this.dragObj){
  995. e = Util.event(e);
  996. var p = Util.getScroll();
  997. var _t = p.t - this.scroll.t;
  998. var _l = p.l - this.scroll.l;
  999. var t = parseInt(this.dragObj.style.top);
  1000. var l = parseInt(this.dragObj.style.left);
  1001. t += _t;
  1002. l += _l;
  1003. this.dragObj.style.top =t+'px';
  1004. this.dragObj.style.left =l+'px';
  1005. this.scroll = Util.getScroll();
  1006. }
  1007. },
  1008. drag : function (e) {
  1009. e = Util.event(e);
  1010. if(!this.isDragging) {
  1011. this.dragObj.style.filter = "alpha(opacity=60)" ;
  1012. this.dragObj.style.opacity = 0.6 ;
  1013. this.isDragging = true ;
  1014. }
  1015. var _clientX = e.clientX;
  1016. var _clientY = e.clientY;
  1017. if (this.dragObj.lastMouseX == _clientX && this.dragObj.lastMouseY == _clientY) return false ;
  1018. var _lastY = parseInt(this.dragObj.style.top);
  1019. var _lastX = parseInt(this.dragObj.style.left);
  1020. _lastX = isNaN(_lastX) ? 0 :_lastX;
  1021. _lastY = isNaN(_lastY) ? 0 :_lastY;
  1022. var newX, newY;
  1023. newY = _lastY + _clientY - this.dragObj.lastMouseY;
  1024. newX = _lastX + _clientX - this.dragObj.lastMouseX;
  1025. this.dragObj.style.left = newX +"px ";
  1026. this.dragObj.style.top = newY + "px ";
  1027. this.dragObj.lastMouseX = _clientX;
  1028. this.dragObj.lastMouseY = _clientY;
  1029. var obj = this.getCurrentOverObj(e);
  1030. if (obj && this.overObj != obj) {
  1031. this.overObj = obj;
  1032. this.getTmpBoxElement();
  1033. Util.insertBefore(this.tmpBoxElement, this.overObj);
  1034. this.dragObjFrame = this.dragObj.parentNode.parentNode;
  1035. this.overObjFrame = this.overObj.parentNode.parentNode;
  1036. }
  1037. Util.cancelSelect();
  1038. },
  1039. _pushTabContent : function (tab, ele){
  1040. if (Util.hasClass(ele, this.frameClass) || Util.hasClass(ele, this.tabClass)) {
  1041. var dom = $(ele.id+'_content');
  1042. if (!dom) {
  1043. dom = document.createElement('div');
  1044. dom.id = ele.id+'_content';
  1045. dom.className = Util.hasClass(ele, this.frameClass) ? this.contentClass+' cl '+ele.className.substr(ele.className.lastIndexOf(' ')+1) : this.contentClass+' cl';
  1046. }
  1047. var frame = this.getObjByName(ele.id);
  1048. if (frame) {
  1049. for (var i in frame['columns']) {
  1050. if (frame['columns'][i] instanceof Column) dom.appendChild($(i));
  1051. }
  1052. } else {
  1053. var children = ele.childNodes;
  1054. var arrDom = [];
  1055. for (var i in children) {
  1056. if (typeof children[i] != 'object') continue;
  1057. if (Util.hasClass(children[i],this.moveableColumn) || Util.hasClass(children[i],this.tabContentClass)) {
  1058. arrDom.push(children[i]);
  1059. }
  1060. }
  1061. var len = arrDom.length;
  1062. for (var i = 0; i < len; i++) {
  1063. dom.appendChild(arrDom[i]);
  1064. }
  1065. }
  1066. $(tab.id+'_content').appendChild(dom);
  1067. } else if (Util.hasClass(ele, this.blockClass)) {
  1068. if ($(ele.id+'_content')) $(tab.id+'_content').appendChild($(ele.id+'_content'));
  1069. }
  1070. },
  1071. _popTabContent : function (tab, ele){
  1072. if (Util.hasClass(ele, this.frameClass) || Util.hasClass(ele, this.tabClass)) {
  1073. Util.removeClass(ele, this.tabActivityClass);
  1074. var eleContent = $(ele.id+'_content');
  1075. if (!eleContent) return false;
  1076. var children = eleContent.childNodes;
  1077. var arrEle = [];
  1078. for (var i in children) {
  1079. if (typeof children[i] == 'object') arrEle.push(children[i]);
  1080. }
  1081. var len = arrEle.length;
  1082. for (var i = 0; i < len; i++) {
  1083. ele.appendChild(arrEle[i]);
  1084. }
  1085. children = '';
  1086. $(tab.id+'_content').removeChild(eleContent);
  1087. } else if (Util.hasClass(ele, this.blockClass)) {
  1088. if ($(ele.id+'_content')) Util.show($(ele.id+'_content'));
  1089. if ($(ele.id+'_content')) ele.appendChild($(ele.id+'_content'));
  1090. }
  1091. },
  1092. _initTabActivity : function (ele) {
  1093. if (!Util.hasClass(ele,this.tabClass)) return false;
  1094. var tabs = $(ele.id+'_title').childNodes;
  1095. var arrTab = [];
  1096. for (var i in tabs) {
  1097. if (typeof tabs[i] != 'object') continue;
  1098. var tabId = tabs[i].id;
  1099. if (Util.hasClass(tabs[i],this.frameClass) || Util.hasClass(tabs[i],this.tabClass)) {
  1100. if (!this._replaceFlag) this._replaceFrameColumn(tabs[i]);
  1101. if (!$(tabId + '_content')) {
  1102. var arrColumn = [];
  1103. for (var j in tabs[i].childNodes) {
  1104. if (Util.hasClass(tabs[i].childNodes[j], this.moveableColumn)) arrColumn.push(tabs[i].childNodes[j]);
  1105. }
  1106. var frameContent = document.createElement('div');
  1107. frameContent.id = tabId + '_content';
  1108. frameContent.className = Util.hasClass(tabs[i], this.frameClass) ? this.contentClass+' cl '+tabs[i].className.substr(tabs[i].className.lastIndexOf(' ')+1) : this.contentClass+' cl';
  1109. var colLen = arrColumn.length;
  1110. for (var k = 0; k < colLen; k++) {
  1111. frameContent.appendChild(arrColumn[k]);
  1112. }
  1113. }
  1114. arrTab.push(tabs[i]);
  1115. } else if (Util.hasClass(tabs[i],this.blockClass)) {
  1116. var frameContent = $(tabId+'_content');
  1117. if (frameContent) {
  1118. frameContent = Util.hasClass(frameContent.parentNode,this.blockClass) ? frameContent : '';
  1119. } else {
  1120. frameContent = document.createElement('div');
  1121. frameContent.id = tabId+'_content';
  1122. }
  1123. arrTab.push(tabs[i]);
  1124. }
  1125. if (frameContent) $(ele.id + '_content').appendChild(frameContent);
  1126. }
  1127. var len = arrTab.length;
  1128. for (var i = 0; i < len; i++) {
  1129. Util[i > 0 ? 'hide' : 'show']($(arrTab[i].id+'_content'));
  1130. }
  1131. },
  1132. dragEnd : function (e) {
  1133. e = Util.event(e);
  1134. if(!this.dragObj) {return false;}
  1135. document.onscroll = function(){};
  1136. window.onscroll = function(){};
  1137. document.onmousemove = function(e){};
  1138. document.onmouseup = '';
  1139. if (this.tmpBoxElement.parentNode) {
  1140. if (this.tmpBoxElement.parentNode == document.body) {
  1141. document.body.removeChild(this.tmpBoxElement);
  1142. document.body.removeChild(this.dragObj);
  1143. this.fn = '';
  1144. } else {
  1145. Util.removeClass(this.dragObj,this.moving);
  1146. this.dragObj.style.display = 'none';
  1147. this.dragObj.style.width = '' ;
  1148. this.dragObj.style.top = '';
  1149. this.dragObj.style.left = '';
  1150. this.dragObj.style.zIndex = '';
  1151. this.dragObj.style.position = 'relative';
  1152. this.dragObj.style.backgroundColor = '';
  1153. this.isDragging = false ;
  1154. this.tmpBoxElement.parentNode.replaceChild(this.dragObj, this.tmpBoxElement);
  1155. Util.fadeIn(this.dragObj);
  1156. this.tmpBoxElement='';
  1157. this._setCssPosition(this.dragObjFrame, 'relative');
  1158. this.doEndDrag();
  1159. this.initPosition();
  1160. if (!(this.dargRelative.up == this.dragObj.previousSibling && this.dargRelative.down == this.dragObj.nextSibling)) {
  1161. this.setClose();
  1162. }
  1163. this.dragObjFrame = this.overObjFrame = null;
  1164. }
  1165. }
  1166. this.newFlag = false;
  1167. if (typeof this.fn == 'function') {this.fn();}
  1168. },
  1169. doEndDrag : function () {
  1170. if (!Util.hasClass(this.dragObjFrame, this.tabClass) && Util.hasClass(this.overObjFrame, this.tabClass)) {
  1171. this._pushTabContent(this.overObjFrame, this.dragObj);
  1172. }else if (Util.hasClass(this.dragObjFrame, this.tabClass) && !Util.hasClass(this.overObjFrame, this.tabClass)) {
  1173. this._popTabContent(this.dragObjFrame, this.dragObj);
  1174. }else if (Util.hasClass(this.dragObjFrame, this.tabClass) && Util.hasClass(this.overObjFrame, this.tabClass)) {
  1175. if (this.dragObjFrame != this.overObjFrame) {
  1176. this._popTabContent(this.dragObjFrame, this.dragObj);
  1177. this._pushTabContent(this.overObjFrame, this.dragObj);
  1178. }
  1179. } else {
  1180. }
  1181. },
  1182. _replaceFrameColumn : function (ele,flag) {
  1183. var children = ele.childNodes;
  1184. var fcn = ele.className.match(/(frame-[\w-]*)/);
  1185. if (!fcn) return false;
  1186. var frameClassName = fcn[1];
  1187. for (var i in children) {
  1188. if (Util.hasClass(children[i], this.moveableColumn)) {
  1189. var className = children[i].className;
  1190. className = className.replace(' col-l', ' '+frameClassName+'-l');
  1191. className = className.replace(' col-r', ' '+frameClassName+'-r');
  1192. className = className.replace(' col-c', ' '+frameClassName+'-c');
  1193. className = className.replace(' mn', ' '+frameClassName+'-l');
  1194. className = className.replace(' sd', ' '+frameClassName+'-r');
  1195. children[i].className = className;
  1196. }
  1197. }
  1198. },
  1199. stopCmd : function () {
  1200. this.rein.length > 0 ? this.rein.pop()() : '';
  1201. },
  1202. setClose : function () {
  1203. if (!this.isChange) {
  1204. window.onbeforeunload = function() {
  1205. return '您的数据已经修改,退出将无法保存您的修改。';
  1206. };
  1207. }
  1208. this.isChange = true;
  1209. },
  1210. clearClose : function () {
  1211. this.isChange = false;
  1212. window.onbeforeunload = function () {};
  1213. },
  1214. _getMoveableArea : function (ele) {
  1215. ele = ele ? ele : document.body;
  1216. this.moveableArea = $C(this.areaClass, ele, 'div');
  1217. },
  1218. initMoveableArea : function () {
  1219. var _method = this;
  1220. this._getMoveableArea();
  1221. var len = this.moveableArea.length;
  1222. for (var i = 0; i < len; i++) {
  1223. var el = this.moveableArea[i];
  1224. if (el == null || typeof el == 'undefined') return false;
  1225. el.ondragstart = function (e) {return false;};
  1226. el.onmouseover = function (e) {Drag.prototype.initDragObj.call(_method, e);};
  1227. el.onmousedown = function (e) {Drag.prototype.dragStart.call(_method, e);};
  1228. el.onmouseup = function (e) {Drag.prototype.dragEnd.call(_method, e);};
  1229. el.onclick = function (e) {e = Util.event(e);e.preventDefault();};
  1230. }
  1231. if ($('contentframe')) $('contentframe').ondragstart = function (e) {return false;};
  1232. },
  1233. disableAdvancedStyleSheet : function () {
  1234. if(this.advancedStyleSheet) {
  1235. this.advancedStyleSheet.disabled = true;
  1236. }
  1237. },
  1238. enableAdvancedStyleSheet : function () {
  1239. if(this.advancedStyleSheet) {
  1240. this.advancedStyleSheet.disabled = false;
  1241. }
  1242. },
  1243. init : function (sampleMode) {
  1244. this.initCommon();
  1245. this.setSampleMode(sampleMode);
  1246. if(!this.sampleMode) {
  1247. this.initAdvanced();
  1248. } else {
  1249. this.initSample();
  1250. }
  1251. return true;
  1252. },
  1253. initAdvanced : function () {
  1254. this.initMoveableArea();
  1255. this.initPosition();
  1256. this.setDefalutMenu();
  1257. this.enableAdvancedStyleSheet();
  1258. this.showControlPanel();
  1259. this.initTips();
  1260. if(this.goonDIY) this.goonDIY();
  1261. this.openfn();
  1262. },
  1263. openfn : function () {
  1264. var openfn = loadUserdata('openfn');
  1265. if(openfn) {
  1266. if(typeof openfn == 'function') {
  1267. openfn();
  1268. } else {
  1269. eval(openfn);
  1270. }
  1271. saveUserdata('openfn', '');
  1272. }
  1273. },
  1274. initCommon : function () {
  1275. this.advancedStyleSheet = $('diy_common');
  1276. this.menu = [];
  1277. },
  1278. initSample : function () {
  1279. this._getMoveableArea();
  1280. this.initPosition();
  1281. this.sampleBlocks = $C(this.blockClass);
  1282. this.initSampleBlocks();
  1283. this.setSampleMenu();
  1284. this.disableAdvancedStyleSheet();
  1285. this.hideControlPanel();
  1286. },
  1287. initSampleBlocks : function () {
  1288. if(this.sampleBlocks) {
  1289. for(var i = 0; i < this.sampleBlocks.length; i++){
  1290. this.checkEdit(this.sampleBlocks[i]);
  1291. }
  1292. }
  1293. },
  1294. setSampleMode : function (sampleMode) {
  1295. if(loadUserdata('diy_advance_mode')) {
  1296. this.sampleMode = '';
  1297. } else {
  1298. this.sampleMode = sampleMode;
  1299. saveUserdata('diy_advance_mode', sampleMode ? '' : '1');
  1300. }
  1301. },
  1302. hideControlPanel : function() {
  1303. Util.show('samplepanel');
  1304. Util.hide('controlpanel');
  1305. Util.hide('diy-tg');
  1306. },
  1307. showControlPanel : function() {
  1308. Util.hide('samplepanel');
  1309. Util.show('controlpanel');
  1310. Util.show('diy-tg');
  1311. },
  1312. checkHasFrame : function (obj) {
  1313. obj = !obj ? this.data : obj;
  1314. for (var i in obj) {
  1315. if (obj[i] instanceof Frame && obj[i].className.indexOf('temp') < 0 ) {
  1316. return true;
  1317. } else if (typeof obj[i] == 'object') {
  1318. if (this.checkHasFrame(obj[i])) return true;
  1319. }
  1320. }
  1321. return false;
  1322. },
  1323. deleteFrame : function (name) {
  1324. if (typeof name == 'string') {
  1325. if (typeof window['c'+name+'_frame'] == 'object' && !BROWSER.ie) delete window['c'+name+'_frame'];
  1326. } else {
  1327. for(var i = 0,L = name.length;i < L;i++) {
  1328. if (typeof window['c'+name[i]+'_frame'] == 'object' && !BROWSER.ie) delete window['c'+name[i]+'_frame'];
  1329. }
  1330. }
  1331. },
  1332. saveViewTip : function (tipname) {
  1333. if(tipname) {
  1334. saveUserdata(tipname, '1');
  1335. Util.hide(tipname);
  1336. }
  1337. doane();
  1338. },
  1339. initTips : function () {
  1340. var tips = ['diy_backup_tip'];
  1341. for(var i = 0; i < tips.length; i++) {
  1342. if(tips[i] && !loadUserdata(tips[i])) {
  1343. Util.show(tips[i]);
  1344. }
  1345. }
  1346. },
  1347. extend : function (obj) {
  1348. for (var i in obj) {
  1349. this[i] = obj[i];
  1350. }
  1351. }
  1352. };
  1353. DIY = function() {
  1354. this.frames = [];
  1355. this.isChange = false;
  1356. this.spacecss = [];
  1357. this.style = 't1';
  1358. this.currentDiy = 'body';
  1359. this.opSet = [];
  1360. this.opPointer = 0;
  1361. this.backFlag = false;
  1362. this.styleSheet = {} ;
  1363. this.scrollHeight = 0 ;
  1364. };
  1365. DIY.prototype = {
  1366. init : function (mod) {
  1367. drag.init(mod);
  1368. this.style = document.diyform.style.value;
  1369. if (this.style == '') {
  1370. var reg = RegExp('topic\(.*)\/style\.css');
  1371. var href = $('style_css') ? $('style_css').href : '';
  1372. var arr = reg.exec(href);
  1373. this.style = arr && arr.length > 1 ? arr[1] : '';
  1374. }
  1375. this.currentLayout = typeof document.diyform.currentlayout == 'undefined' ? '' : document.diyform.currentlayout.value;
  1376. this.initStyleSheet();
  1377. if (this.styleSheet.rules) this.initDiyStyle();
  1378. },
  1379. initStyleSheet : function () {
  1380. var all = document.styleSheets;
  1381. for (var i=0;i<all.length;i++) {
  1382. var ownerNode = all[i].ownerNode || all[i].owningElement;
  1383. if (ownerNode.id == 'diy_style') {
  1384. this.styleSheet = new styleCss(i);
  1385. return true;
  1386. }
  1387. }
  1388. },
  1389. initDiyStyle : function (css) {
  1390. var allCssText = css || $('diy_style').innerHTML;
  1391. allCssText = allCssText ? allCssText.replace(/\n|\r|\t| /g,'') : '';
  1392. var random = Math.random(), rules = '';
  1393. var reg = new RegExp('(.*?) ?\{(.*?)\}','g');
  1394. while((rules = reg.exec(allCssText))) {
  1395. var selector = this.checkSelector(rules[1]);
  1396. var cssText = rules[2];
  1397. var cssarr = cssText.split(';');
  1398. var l = cssarr.length;
  1399. for (var k = 0; k < l; k++) {
  1400. var attribute = trim(cssarr[k].substr(0, cssarr[k].indexOf(':')).toLowerCase());
  1401. var value = cssarr[k].substr(cssarr[k].indexOf(':')+1).toLowerCase();
  1402. if (!attribute || !value) continue;
  1403. if (!this.spacecss[selector]) this.spacecss[selector] = [];
  1404. this.spacecss[selector][attribute] = value;
  1405. if (css) this.setStyle(selector, attribute, value, random);
  1406. }
  1407. }
  1408. },
  1409. checkSelector : function (selector) {
  1410. var s = selector.toLowerCase();
  1411. if (s.toLowerCase().indexOf('body') > -1) {
  1412. var body = BROWSER.ie ? 'BODY' : 'body';
  1413. selector = selector.replace(/body/i,body);
  1414. }
  1415. if (s.indexOf(' a') > -1) {
  1416. selector = BROWSER.ie ? selector.replace(/ [aA]/,' A') : selector.replace(/ [aA]/,' a');
  1417. }
  1418. return selector;
  1419. },
  1420. initPalette : function (id) {
  1421. var bgcolor = '',selector = '',bgimg = '',bgrepeat = '', bgposition = '', bgattachment = '', bgfontColor = '', bglinkColor = '', i = 0;
  1422. var repeat = ['repeat','no-repeat','repeat-x','repeat-y'];
  1423. var attachment = ['scroll','fixed'];
  1424. var position = ['left top','center top','right top','left center','center center','right center','left bottom','center bottom','right bottom'];
  1425. var position_ = ['0% 0%','50% 0%','100% 0%','0% 50%','50% 50%','100% 50%','0% 100%','50% 100%','100% 100%'];
  1426. selector = this.getSelector(id);
  1427. bgcolor = Util.formatColor(this.styleSheet.getRule(selector,'backgroundColor'));
  1428. bgimg = this.styleSheet.getRule(selector,'backgroundImage');
  1429. bgrepeat = this.styleSheet.getRule(selector,'backgroundRepeat');
  1430. bgposition = this.styleSheet.getRule(selector,'backgroundPosition');
  1431. bgattachment = this.styleSheet.getRule(selector,'backgroundAttachment');
  1432. bgfontColor = Util.formatColor(this.styleSheet.getRule(selector,'color'));
  1433. bglinkColor = Util.formatColor(this.styleSheet.getRule(this.getSelector(selector+' a'),'color'));
  1434. var selectedIndex = 0;
  1435. for (i=0;i<repeat.length;i++) {
  1436. if (bgrepeat == repeat[i]) selectedIndex= i;
  1437. }
  1438. $('repeat_mode').selectedIndex = selectedIndex;
  1439. for (i=0;i<attachment.length;i++) {
  1440. $('rabga'+i).checked = (bgattachment == attachment[i] ? true : false);
  1441. }
  1442. var flag = '';
  1443. for (i=0;i<position.length;i++) {
  1444. var className = bgposition == position[i] ? 'red' : '';
  1445. $('bgimgposition'+i).className = className;
  1446. flag = flag ? flag : className;
  1447. }
  1448. if (flag != 'red') {
  1449. for (i=0;i<position_.length;i++) {
  1450. className = bgposition == position_[i] ? 'red' : '';
  1451. $('bgimgposition'+i).className = className;
  1452. }
  1453. }
  1454. $('colorValue').value = bgcolor;
  1455. if ($('cbpb')) $('cbpb').style.backgroundColor = bgcolor;
  1456. $('textColorValue').value = bgfontColor;
  1457. if ($('ctpb')) $('ctpb').style.backgroundColor = bgfontColor;
  1458. $('linkColorValue').value = bglinkColor;
  1459. if ($('clpb')) $('clpb').style.backgroundColor = bglinkColor;
  1460. Util.show($('currentimgdiv'));
  1461. Util.hide($('diyimages'));
  1462. if ($('selectalbum')) $('selectalbum').disabled = 'disabled';
  1463. bgimg = bgimg != '' && bgimg != 'none' ? bgimg.replace(/url\(['|"]{0,1}/,'').replace(/['|"]{0,1}\)/,'') : 'static/image/common/nophotosmall.gif';
  1464. $('currentimg').src = bgimg;
  1465. },
  1466. changeBgImgDiv : function () {
  1467. Util.hide($('currentimgdiv'));
  1468. Util.show($('diyimages'));
  1469. if ($('selectalbum')) $('selectalbum').disabled = '';
  1470. },
  1471. getSpacecssStr : function() {
  1472. var css = '';
  1473. var selectors = ['body', '#hd','#ct', 'BODY'];
  1474. for (var i in this.spacecss) {
  1475. var name = i.split(' ')[0];
  1476. if(selectors.indexOf(name) == -1 && !drag.getObjByName(name.substr(1))) {
  1477. for(var k in this.spacecss) {
  1478. if (k.indexOf(i) > -1) {
  1479. this.spacecss[k] = [];
  1480. }
  1481. }
  1482. continue;
  1483. }
  1484. var rule = this.spacecss[i];
  1485. if (typeof rule == "function") continue;
  1486. var one = '';
  1487. rule = this.formatCssRule(rule);
  1488. for (var j in rule) {
  1489. var content = this.spacecss[i][j];
  1490. if (content && typeof content == "string" && content.length > 0) {
  1491. content = this.trimCssImportant(content);
  1492. content = content ? content + ' !important;' : ';';
  1493. one += j + ":" + content;
  1494. }
  1495. }
  1496. if (one == '') continue;
  1497. css += i + " {" + one + "}";
  1498. }
  1499. return css;
  1500. },
  1501. formatCssRule : function (rule) {
  1502. var arr = ['top', 'right', 'bottom', 'left'], i = 0;
  1503. if (typeof rule['margin-top'] != 'undefined') {
  1504. var margin = rule['margin-bottom'];
  1505. if (margin && margin == rule['margin-top'] && margin == rule['margin-right'] && margin == rule['margin-left']) {
  1506. rule['margin'] = margin;
  1507. for(i=0;i<arr.length;i++) {
  1508. delete rule['margin-'+arr[i]];
  1509. }
  1510. } else {
  1511. delete rule['margin'];
  1512. }
  1513. }
  1514. var border = '', borderb = '', borderr = '', borderl = '';
  1515. if (typeof rule['border-top-color'] != 'undefined' || typeof rule['border-top-width'] != 'undefined' || typeof rule['border-top-style'] != 'undefined') {
  1516. var format = function (css) {
  1517. css = css.join(' ').replace(/!( ?)important/g,'').replace(/ /g,' ').replace(/^ | $/g,'');
  1518. return css ? css + ' !important' : '';
  1519. };
  1520. border = format([rule['border-top-color'], rule['border-top-width'], rule['border-top-style']]);
  1521. borderr = format([rule['border-right-color'], rule['border-right-width'], rule['border-right-style']]);
  1522. borderb = format([rule['border-bottom-color'], rule['border-bottom-width'], rule['border-bottom-style']]);
  1523. borderl = format([rule['border-left-color'], rule['border-left-width'], rule['border-left-style']]);
  1524. } else if (typeof rule['border-top'] != 'undefined') {
  1525. border = rule['border-top'];borderr = rule['border-right'];borderb = rule['border-bottom'];borderl = rule['border-left'];
  1526. }
  1527. if (border) {
  1528. if (border == borderb && border == borderr && border == borderl) {
  1529. rule['border'] = border;
  1530. for(i=0;i<arr.length;i++) {
  1531. delete rule['border-'+arr[i]];
  1532. }
  1533. } else {
  1534. rule['border-top'] = border;rule['border-right'] = borderr;rule['border-bottom'] = borderb;rule['border-left'] = borderl;
  1535. delete rule['border'];
  1536. }
  1537. for(i=0;i<arr.length;i++) {
  1538. delete rule['border-'+arr[i]+'-color'];delete rule['border-'+arr[i]+'-width'];delete rule['border-'+arr[i]+'-style'];
  1539. }
  1540. }
  1541. return rule;
  1542. },
  1543. changeLayout : function (newLayout) {
  1544. if (this.currentLayout == newLayout) return false;
  1545. var data = $('layout'+newLayout).getAttribute('data');
  1546. var dataArr = data.split(' ');
  1547. var currentLayoutLength = this.currentLayout.length;
  1548. var newLayoutLength = newLayout.length;
  1549. if (newLayoutLength == currentLayoutLength){
  1550. $('frame1_left').style.width = dataArr[0]+'px';
  1551. $('frame1_center').style.width = dataArr[1]+'px';
  1552. if (typeof(dataArr[2]) != 'undefined') $('frame1_right').style.width = dataArr[2]+'px';
  1553. } else if (newLayoutLength > currentLayoutLength) {
  1554. var block = this.getRandomBlockName();
  1555. var dom = document.createElement('div');
  1556. dom.id = 'frame1_right';
  1557. dom.className = drag.moveableColumn + ' z';
  1558. dom.appendChild($(block));
  1559. $('frame1').appendChild(dom);
  1560. $('frame1_left').style.width = dataArr[0]+'px';
  1561. $('frame1_center').style.width = dataArr[1]+'px';
  1562. dom.style.width = dataArr[2]+'px';
  1563. } else if (newLayoutLength < currentLayoutLength) {
  1564. var _length = drag.data['diypage'][0]['columns']['frame1_right']['children'].length;
  1565. var tobj = $('frame1_center_temp');
  1566. for (var i = 0; i < _length; i++) {
  1567. var name = drag.data['diypage'][0]['columns']['frame1_right']['children'][i].name;
  1568. if (name.indexOf('temp') < 0) $('frame1_center').insertBefore($(name),tobj);
  1569. }
  1570. $('frame1').removeChild($('frame1_right'));
  1571. $('frame1_left').style.width = dataArr[0]+'px';
  1572. $('frame1_center').style.width = dataArr[1]+'px';
  1573. }
  1574. var className = $('layout'+this.currentLayout).className;
  1575. $('layout'+this.currentLayout).className = '';
  1576. $('layout'+newLayout).className = className;
  1577. this.currentLayout = newLayout;
  1578. drag.initPosition();
  1579. drag.setClose();
  1580. },
  1581. getRandomBlockName : function () {
  1582. var left = drag.data['diypage'][0]['columns']['frame1_left']['children'];
  1583. if (left.length > 2) {
  1584. var block = left[0];
  1585. } else {
  1586. var block = drag.data['diypage'][0]['columns']['frame1_center']['children'][0];
  1587. }
  1588. return block.name;
  1589. },
  1590. changeStyle : function (t) {
  1591. if (t == '') return false;
  1592. $('style_css').href=STATICURL+t+"/style.css";
  1593. if (!this.backFlag) {
  1594. var oldData = [this.style];
  1595. var newData = [t];
  1596. var random = Math.random();
  1597. this.addOpRecord ('this.changeStyle', newData, oldData, random);
  1598. }
  1599. var arr = t.split("/");
  1600. this.style = arr[arr.length-1];
  1601. drag.setClose();
  1602. },
  1603. setCurrentDiy : function (type) {
  1604. if (type) {
  1605. $('diy_tag_'+this.currentDiy).className = '';
  1606. this.currentDiy = type;
  1607. $('diy_tag_'+this.currentDiy).className = 'activity';
  1608. this.initPalette(this.currentDiy);
  1609. }
  1610. },
  1611. hideBg : function () {
  1612. var random = Math.random();
  1613. this.setStyle(this.currentDiy, 'background-image', '', random);
  1614. this.setStyle(this.currentDiy, 'background-color', '', random);
  1615. if (this.currentDiy == 'hd') this.setStyle(this.currentDiy, 'height', '', random);
  1616. this.initPalette(this.currentDiy);
  1617. },
  1618. toggleHeader : function () {
  1619. var random = Math.random();
  1620. if ($('header_hide_cb').checked) {
  1621. this.setStyle('#hd', 'height', '260px', random);
  1622. this.setStyle('#hd', 'background-image', 'none', random);
  1623. this.setStyle('#hd', 'border-width', '0px', random);
  1624. } else {
  1625. this.setStyle('#hd', 'height', '', random);
  1626. this.setStyle('#hd', 'background-image', '', random);
  1627. this.setStyle('#hd', 'border-width', '', random);
  1628. }
  1629. },
  1630. setBgImage : function (value) {
  1631. var path = typeof value == "string" ? value : value.src;
  1632. if (path.indexOf('.thumb') > 0) {
  1633. path = path.substring(0,path.indexOf('.thumb'));
  1634. }
  1635. if (path == '' || path == 'undefined') return false;
  1636. var random = Math.random();
  1637. this.setStyle(this.currentDiy, 'background-image', Util.url(path), random);
  1638. this.setStyle(this.currentDiy, 'background-repeat', 'repeat', random);
  1639. if (this.currentDiy == 'hd') {
  1640. var _method = this;
  1641. var img = new Image();
  1642. img.onload = function () {
  1643. if (parseInt(img.height) < 140) {
  1644. DIY.prototype.setStyle.call(_method, _method.currentDiy, 'background-repeat', 'repeat', random);
  1645. DIY.prototype.setStyle.call(_method, _method.currentDiy, 'height', '', random);
  1646. } else {
  1647. DIY.prototype.setStyle.call(_method, _method.currentDiy, 'height', img.height+"px", random);
  1648. }
  1649. };
  1650. img.src = path;
  1651. }
  1652. },
  1653. setBgRepeat : function (value) {
  1654. var repeat = ['repeat','no-repeat','repeat-x','repeat-y'];
  1655. if (typeof repeat[value] == 'undefined') {return false;}
  1656. this.setStyle(this.currentDiy, 'background-repeat', repeat[value]);
  1657. },
  1658. setBgAttachment : function (value) {
  1659. var attachment = ['scroll','fixed'];
  1660. if (typeof attachment[value] == 'undefined') {return false;}
  1661. this.setStyle(this.currentDiy, 'background-attachment', attachment[value]);
  1662. },
  1663. setBgColor : function (color) {
  1664. this.setStyle(this.currentDiy, 'background-color', color);
  1665. },
  1666. setTextColor : function (color) {
  1667. this.setStyle(this.currentDiy, 'color', color);
  1668. },
  1669. setLinkColor : function (color) {
  1670. this.setStyle(this.currentDiy + ' a', 'color', color);
  1671. },
  1672. setBgPosition : function (id) {
  1673. var td = $(id);
  1674. var i = id.substr(id.length-1);
  1675. var position = ['left top','center top','right top','left center','center center','right center','left bottom','center bottom','right bottom'];
  1676. td.className = 'red';
  1677. for (var j=0;j<9;j++) {
  1678. if (i != j) {
  1679. $('bgimgposition'+j).className = '';
  1680. }
  1681. }
  1682. this.setStyle(this.currentDiy, 'background-position', position[i]);
  1683. },
  1684. getSelector : function (currentDiv) {
  1685. var arr = currentDiv.split(' ');
  1686. currentDiv = arr[0];
  1687. var link = '';
  1688. if (arr.length > 1) {
  1689. link = (arr[arr.length-1].toLowerCase() == 'a') ? link = ' '+arr.pop() : '';
  1690. currentDiv = arr.join(' ');
  1691. }
  1692. var selector = '';
  1693. switch(currentDiv) {
  1694. case 'blocktitle' :
  1695. selector = '#ct .move-span .blocktitle';
  1696. break;
  1697. case 'body' :
  1698. case 'BODY' :
  1699. selector = BROWSER.ie ? 'BODY' : 'body';
  1700. break;
  1701. default :
  1702. selector = currentDiv.indexOf("#")>-1 ? currentDiv : "#"+currentDiv;
  1703. }
  1704. var rega = BROWSER.ie ? ' A' : ' a';
  1705. selector = (selector+link).replace(/ a/i,rega);
  1706. return selector;
  1707. },
  1708. setStyle : function (currentDiv, property, value, random, num){
  1709. property = trim(property).toLowerCase();
  1710. var propertyJs = property.property2js();
  1711. if (typeof value == 'undefined') value = '';
  1712. var selector = this.getSelector(currentDiv);
  1713. if (!this.backFlag) {
  1714. var rule = this.styleSheet.getRule(selector,propertyJs);
  1715. rule = rule.replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
  1716. var oldData = [currentDiv, property, rule];
  1717. var newData = [currentDiv, property, value];
  1718. if (typeof random == 'undefined') random = Math.random();
  1719. this.addOpRecord ('this.setStyle', newData, oldData, random);
  1720. }
  1721. value = this.trimCssImportant(value);
  1722. value = value ? value + ' !important' : '';
  1723. var pvalue = value ? property+':'+value : '';
  1724. this.styleSheet.addRule(selector,pvalue,num,property);
  1725. Util.recolored();
  1726. if (typeof this.spacecss[selector] == 'undefined') {
  1727. this.spacecss[selector] = [];
  1728. }
  1729. this.spacecss[selector][property] = value;
  1730. drag.setClose();
  1731. },
  1732. trimCssImportant : function (value) {
  1733. if (value instanceof Array) value = value.join(' ');
  1734. return value ? value.replace(/!( ?)important/g,'').replace(/ /g,' ').replace(/^ | $/g,'') : '';
  1735. },
  1736. removeCssSelector : function (selector) {
  1737. for (var i in this.spacecss) {
  1738. if (typeof this.spacecss[i] == "function") continue;
  1739. if (i.indexOf(selector) > -1) {
  1740. this.styleSheet.removeRule(i);
  1741. this.spacecss[i] = [];
  1742. }
  1743. }
  1744. },
  1745. undo : function () {
  1746. if (this.opSet.length == 0) return false;
  1747. var oldData = '';
  1748. if (this.opPointer <= 0) {return '';}
  1749. var step = this.opSet[--this.opPointer];
  1750. var random = step['random'];
  1751. var cmd = step['cmd'].split(',');
  1752. var cmdNum = cmd.length;
  1753. if (cmdNum >1) {
  1754. for (var i=0; i<cmdNum; i++) {
  1755. oldData = typeof step['oldData'][i] == 'undefined' || step['oldData'] == '' ? '' : '"' + step['oldData'][i].join('","') + '"';
  1756. this.backFlag = true;
  1757. eval(cmd[i]+'('+oldData+')');
  1758. this.backFlag = false;
  1759. }
  1760. } else {
  1761. oldData = typeof step['oldData'] == 'undefined' || step['oldData'] == '' ? '' : '"' + step['oldData'].join('","') + '"';
  1762. this.backFlag = true;
  1763. eval(cmd+'('+oldData+')');
  1764. this.backFlag = false;
  1765. }
  1766. $('button_redo').className = '';
  1767. if (this.opPointer == 0) {
  1768. $('button_undo').className = 'unusable';
  1769. drag.isChange = false;
  1770. drag.clearClose();
  1771. return '';
  1772. } else if (random == this.opSet[this.opPointer-1]['random']) {
  1773. this.undo();
  1774. return '';
  1775. } else {
  1776. return '';
  1777. }
  1778. },
  1779. redo : function () {
  1780. if (this.opSet.length == 0) return false;
  1781. var newData = '',random = '';
  1782. if (this.opPointer >= this.opSet.length) return '';
  1783. var step = this.opSet[this.opPointer++];
  1784. random = step['random'];
  1785. var cmd = step['cmd'].split(',');
  1786. var cmdNum = cmd.length;
  1787. if (cmdNum >1) {
  1788. for (var i=0; i<cmdNum; i++) {
  1789. newData = typeof step['newData'][i] == 'undefined' || step['oldData'] == '' ? '' : '"' + step['newData'][i].join('","') + '"';
  1790. this.backFlag = true;
  1791. eval(cmd[i]+'('+newData+')');
  1792. this.backFlag = false;
  1793. }
  1794. }else {
  1795. newData = typeof step['newData'] == 'undefined' || step['oldData'] == '' ? '' : '"' + step['newData'].join('","') + '"';
  1796. this.backFlag = true;
  1797. eval(cmd+'('+newData+')');
  1798. this.backFlag = false;
  1799. }
  1800. $('button_undo').className = '';
  1801. if (this.opPointer == this.opSet.length) {
  1802. $('button_redo').className = 'unusable';
  1803. return '';
  1804. } else if(random == this.opSet[this.opPointer]['random']){
  1805. this.redo();
  1806. }
  1807. },
  1808. addOpRecord : function (cmd, newData, oldData, random) {
  1809. if (this.opPointer == 0) this.opSet = [];
  1810. this.opSet[this.opPointer++] = {'cmd':cmd, 'newData':newData, 'oldData':oldData, 'random':random};
  1811. $('button_undo').className = '';
  1812. $('button_redo').className = 'unusable';
  1813. Util.show('recover_button');
  1814. },
  1815. recoverStyle : function () {
  1816. var random = Math.random();
  1817. for (var selector in this.spacecss){
  1818. var style = this.spacecss[selector];
  1819. if (typeof style == "function") {continue;}
  1820. for (var attribute in style) {
  1821. if (typeof style[attribute] == "function") {continue;}
  1822. this.setStyle(selector,attribute,'',random);
  1823. }
  1824. }
  1825. Util.hide('recover_button');
  1826. drag.setClose();
  1827. this.initPalette(this.currentDiy);
  1828. },
  1829. uploadSubmit : function (){
  1830. if (document.uploadpic.attach.value.length<3) {
  1831. alert('请选择您要上传的图片');
  1832. return false;
  1833. }
  1834. if (document.uploadpic.albumid != null) document.uploadpic.albumid.value = $('selectalbum').value;
  1835. return true;
  1836. },
  1837. save : function () {
  1838. return false;
  1839. },
  1840. cancel : function () {
  1841. var flag = false;
  1842. if (this.isChange) {
  1843. flag = confirm(this.cancelConfirm ? this.cancelConfirm : '退出将不会保存您刚才的设置。是否确认退出?');
  1844. }
  1845. if (!this.isChange || flag) {
  1846. location.href = location.href.replace(/[\?|\&]diy\=yes/g,'');
  1847. }
  1848. },
  1849. extend : function (obj) {
  1850. for (var i in obj) {
  1851. this[i] = obj[i];
  1852. }
  1853. }
  1854. };
  1855. })();