PageRenderTime 62ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/include/admin.js

http://xklog.googlecode.com/
JavaScript | 467 lines | 314 code | 55 blank | 98 comment | 69 complexity | 7876dfde02db425f457550bb577bfd06 MD5 | raw file
Possible License(s): AGPL-1.0
  1. /*
  2. Fcten: Thanks to mg12's excellent work that I can use it with few modifications.
  3. Author: mg12
  4. Tutorial URL: http://www.neoease.com/wordpress-menubar-5/
  5. */
  6. /** ? */
  7. var Class = {
  8. create: function() {
  9. return function() {
  10. this.initialize.apply(this, arguments);
  11. }
  12. }
  13. }
  14. /** ???? */
  15. var MenuList = Class.create();
  16. MenuList.prototype = {
  17. /**
  18. * ????
  19. * id: ????
  20. * opacity: ???? (0.0 - 1.0, 0.0 ????, 1.0 ????)
  21. */
  22. initialize: function(id, opacity) {
  23. // ??????
  24. this.obj = document.getElementById(id);
  25. if (!this.obj) { return; }
  26. /* multi 2009/06/11 ADD START */
  27. // ???????
  28. var menus = this.obj.getElementsByTagName('ul');
  29. for (var i = 0; i < menus.length; i++) {
  30. // ???????? (????????)
  31. var menu = menus[i].parentNode;
  32. // ?????????????, ???????
  33. if(menu.parentNode === this.obj) {
  34. new Menu(menu, opacity);
  35. // ?????????????, ??????????
  36. } else {
  37. new Menu(menu, opacity, 1);
  38. // ???????????? class ?, ??????
  39. menu.firstChild.className += ' admin_submenu';
  40. //menu.className = 'admin_submenu';
  41. }
  42. }
  43. /* multi 2009/06/11 ADD END */
  44. /* multi 2009/06/11 DELETE START */
  45. /*
  46. // ???????????????
  47. var menus = this.obj.childNodes;
  48. for (var i = 0; i < menus.length; i++) {
  49. var menu = menus[i];
  50. if (menu.tagName == 'LI') {
  51. // ????
  52. new Menu(menu, opacity);
  53. }
  54. }
  55. */
  56. /* multi 2009/06/11 DELETE START */
  57. }
  58. }
  59. /** ?? */
  60. var Menu = Class.create();
  61. Menu.prototype = {
  62. /**
  63. * ????
  64. * target: ????
  65. * opacity: ???? (0.0 - 1.0, 0.0 ????, 1.0 ????)
  66. * sub: ?????? (1 ???, -1 ???) [multi 2009/06/11 ADD]
  67. */
  68. initialize: function(target, opacity, sub) {
  69. this.util = new MenuUtil();
  70. // ?????? (?????)
  71. this.obj = this.util.cleanWhitespace(target);
  72. // ?????, ????
  73. this.opacity = 0;
  74. this.maxopacity = opacity || 1;
  75. /* multi 2009/06/11 ADD START */
  76. // ??????
  77. this.sub = sub || -1;
  78. /* multi 2009/06/11 ADD START */
  79. // ????
  80. this.menu = this.obj.childNodes
  81. // ??! ??????????, ??????
  82. if (this.menu.length < 2) { return; }
  83. // ????????
  84. this.title = this.menu[0];
  85. this.body = this.menu[1];
  86. // ??????
  87. this.util.setStyle(this.body, 'visibility', 'hidden');
  88. this.util.setStyle(this.body, 'position', 'absolute');
  89. /* multi 2009/06/11 DELETE START */
  90. //this.util.setStyle(this.body, 'overflow', 'hidden');
  91. /* multi 2009/06/11 DELETE END */
  92. this.util.setStyle(this.body, 'display', 'block');
  93. // ?????
  94. this.addListener(this.obj, 'mouseover', this.util.bind(this, this.activate), false);
  95. this.addListener(this.obj, 'mouseout', this.util.bind(this, this.deactivate), false);
  96. },
  97. /**
  98. * ????
  99. * ?????????????
  100. */
  101. activate: function() {
  102. /* multi 2009/06/11 CHANGE START */
  103. // ?????????? (???)
  104. if(this.sub == 1) {
  105. var pos = this.util.currentOffset(this.title);
  106. var left = this.util.getWidth(this.body) + 1;
  107. var top = pos[1] - 5;
  108. // ?????????? (??)
  109. } else {
  110. var pos = this.util.cumulativeOffset(this.title);
  111. var left = pos[0] - 10;
  112. var top = pos[1] + this.util.getHeight(this.title) + 3;
  113. // ????????????, ?????????, ????.
  114. // this.util.setStyle(this.body, 'opacity', this.opacity);
  115. }
  116. /* multi 2009/06/11 CHANGE START */
  117. /* multi 2009/06/11 ADD START */
  118. // ???????? class ??, ??????
  119. this.title.className += ' current_item';
  120. /* multi 2009/06/11 ADD END */
  121. // ???????
  122. this.util.setStyle(this.body, 'left', left + 'px');
  123. this.util.setStyle(this.body, 'top', top + 'px');
  124. this.util.setStyle(this.body, 'visibility', 'visible');
  125. this.util.setStyle(this.body, 'opacity', this.opacity);
  126. this.util.setStyle(this.body, 'MozOpacity', this.opacity);
  127. this.util.setStyle(this.body, 'KhtmlOpacity', this.opacity);
  128. this.util.setStyle(this.body, 'filter', 'alpha(opacity=' + this.opacity * 100 + ')');
  129. if(this.tid) {
  130. clearTimeout(this.tid);
  131. }
  132. this.tid = setInterval(this.util.bind(this, this.appear), 30);
  133. /* multi 2009/06/11 DELETE START */
  134. // ???????????? (?????????)
  135. //this.util.setStyle(this.body, 'opacity', this.opacity);
  136. // IE ????????, ??????????
  137. //this.util.setStyle(this.body, 'filter', 'alpha(opacity=' + this.opacity * 100 + ')');
  138. /* multi 2009/06/11 DELETE END */
  139. },
  140. appear: function() {
  141. this.opacity += 0.1;
  142. if(this.opacity >= this.maxopacity) {
  143. this.opacity = this.maxopacity;
  144. clearTimeout(this.tid);
  145. }
  146. this.util.setStyle(this.body, 'opacity', this.opacity);
  147. this.util.setStyle(this.body, 'MozOpacity', this.opacity);
  148. this.util.setStyle(this.body, 'KhtmlOpacity', this.opacity);
  149. this.util.setStyle(this.body, 'filter', 'alpha(opacity=' + this.opacity * 100 + ')');
  150. },
  151. /**
  152. * ????
  153. * ?????????????
  154. */
  155. deactivate: function(){
  156. // ???????
  157. // this.util.setStyle(this.body, 'visibility', 'hidden');
  158. if(this.tid) {
  159. clearTimeout(this.tid);
  160. }
  161. /* multi 2009/06/11 ADD START */
  162. // ????????????? class ?, ???????
  163. this.title.className = this.title.className.replace('current_item', '');
  164. /* multi 2009/06/11 ADD END */
  165. this.tid = setInterval(this.util.bind(this, this.fade), 30);
  166. },
  167. fade: function() {
  168. this.opacity -= 0.1;
  169. if(this.opacity <= 0) {
  170. this.opacity = 0;
  171. this.util.setStyle(this.body, 'visibility', 'hidden');
  172. clearTimeout(this.tid);
  173. }
  174. this.util.setStyle(this.body, 'opacity', this.opacity);
  175. this.util.setStyle(this.body, 'MozOpacity', this.opacity);
  176. this.util.setStyle(this.body, 'KhtmlOpacity', this.opacity);
  177. this.util.setStyle(this.body, 'filter', 'alpha(opacity=' + this.opacity * 100 + ')');
  178. },
  179. /**
  180. * ????
  181. * element: ????
  182. * name: ????
  183. * observer: ?????
  184. * useCapture: ?????????? (true ? Capture ??, false ? Bubbling ??)
  185. */
  186. addListener: function(element, name, observer, useCapture) {
  187. if(element.addEventListener) {
  188. element.addEventListener(name, observer, useCapture);
  189. } else if(element.attachEvent) {
  190. element.attachEvent('on' + name, observer);
  191. }
  192. }
  193. }
  194. /** ??????? */
  195. var MenuUtil = Class.create();
  196. MenuUtil.prototype = {
  197. initialize: function() {
  198. },
  199. $: function(id) {
  200. return document.getElementById(id);
  201. },
  202. $A: function(iterable) {
  203. if(!iterable) {
  204. return [];
  205. }
  206. if(iterable.toArray) {
  207. return iterable.toArray();
  208. } else {
  209. var results = [];
  210. for(var i = 0; i < iterable.length; i++) {
  211. results.push(iterable[i]);
  212. }
  213. return results;
  214. }
  215. },
  216. bind: function() {
  217. var array = this.$A(arguments);
  218. var func = array[array.length - 1];
  219. var _method = func, args = array, object = args.shift();
  220. return function() {
  221. return _method.apply(object, args.concat(array));
  222. }
  223. },
  224. getHeight: function(element) {
  225. return element.offsetHeight;
  226. },
  227. setStyle: function(element, key, value) {
  228. element.style[key] = value;
  229. },
  230. getStyle: function(element, key) {
  231. return element.style[key];
  232. },
  233. cleanWhitespace: function(list) {
  234. var node = list.firstChild;
  235. while (node) {
  236. var nextNode = node.nextSibling;
  237. if(node.nodeType == 3 && !/\S/.test(node.nodeValue)) {
  238. list.removeChild(node);
  239. }
  240. node = nextNode;
  241. }
  242. return list;
  243. },
  244. cumulativeOffset: function(element) {
  245. var valueT = 0, valueL = 0;
  246. do {
  247. valueT += element.offsetTop || 0;
  248. valueL += element.offsetLeft || 0;
  249. element = element.offsetParent;
  250. } while (element);
  251. return [valueL, valueT];
  252. },
  253. /* multi 2009/06/11 ADD START */
  254. getWidth: function(element) {
  255. return element.offsetWidth;
  256. },
  257. currentOffset: function(element) {
  258. var valueT = element.offsetTop || 0;
  259. var valueL = element.offsetLeft || 0;
  260. return [valueL, valueT];
  261. }
  262. /* multi 2009/06/11 ADD END */
  263. }
  264. /*---------------------------------*/
  265. function ajax_load( BlogPath, M, P, E, I ){
  266. $("#admin_loading").fadeIn('slow');
  267. var URL = BlogPath + 'index.php?m=' + M;
  268. if( P != null ) {
  269. URL += '&p=' + P;
  270. }
  271. if( E != null ) {
  272. URL += '&page=' + E;
  273. }
  274. if( I != null ) {
  275. URL += '&id=' + I;
  276. }
  277. URL += '&ohash=' + ohash;
  278. $.get(URL,function(data){
  279. if(data=='forbidden'){
  280. document.location.href='./';
  281. return;
  282. }
  283. $("#admin_content").html(data);
  284. $("#admin_loading").fadeOut('slow');
  285. });
  286. }
  287. function ajax_get( BlogPath, M, P, E, I ){
  288. $("#admin_loading").fadeIn('slow');
  289. var URL = BlogPath + 'index.php?m=' + M;
  290. if( P != null ) {
  291. URL += '&p=' + P;
  292. }
  293. if( E != null ) {
  294. URL += '&page=' + E;
  295. }
  296. if( I != null ) {
  297. URL += '&id=' + I;
  298. }
  299. URL += '&ohash=' + ohash;
  300. $.get(URL,function(data){
  301. if(data=='forbidden'){
  302. document.location.href='./';
  303. return;
  304. }
  305. showMessage(data);
  306. $("#admin_loading").fadeOut('slow');
  307. });
  308. }
  309. function menuClick( e, M, P ){
  310. ajax_load( AdminPath, M, P );
  311. if(e) {
  312. changeSelect(e);
  313. }
  314. }
  315. function Logout(){
  316. ajax_get( AdminPath, 'login', 'logout' );
  317. }
  318. // ???????????????……
  319. function changeSelect(e){
  320. var el = document.getElementById('admin_menu').childNodes;
  321. for(var i=0;i<el.length;i++){
  322. //alert(el.length);
  323. //alert(el[i].childNodes.length);
  324. for(var j=0;j<el[i].childNodes.length;j++) {
  325. el[i].childNodes[j].className = el[i].childNodes[j].className.replace('selected','');
  326. for(var k=0;k<el[i].childNodes[j].childNodes.length;k++) {
  327. for(var l=0;l<el[i].childNodes[j].childNodes[k].childNodes.length;l++) {
  328. el[i].childNodes[j].childNodes[k].childNodes[l].className = el[i].childNodes[j].childNodes[k].childNodes[l].className.replace('selected','');
  329. }
  330. }
  331. }
  332. }
  333. e.className += ' selected';
  334. }
  335. var h_msg,f_msg = true,op = 0,t_msg = '';
  336. function showMessage(msg) {
  337. if( h_msg ) {
  338. clearTimeout(h_msg);
  339. }
  340. if( $("#admin_tips").css('visibility') == 'hidden' ) {
  341. op = 0;
  342. $("#admin_tips").html(msg);
  343. $("#admin_tips").css('opacity', 0);
  344. $("#admin_tips").css('MozOpacity', 0);
  345. $("#admin_tips").css('KhtmlOpacity',0);
  346. $("#admin_tips").css('filter', 'alpha(opacity=0)');
  347. $("#admin_tips").css('visibility','visible');
  348. } else {
  349. if( msg != '' ) {
  350. t_msg = msg;
  351. removeMessage();
  352. }
  353. }
  354. if( op < 1)
  355. op += 0.1;
  356. $("#admin_tips").css('opacity', op );
  357. $("#admin_tips").css('MozOpacity', op );
  358. $("#admin_tips").css('KhtmlOpacity', op );
  359. $("#admin_tips").css('filter', 'alpha(opacity=' + op * 100 + ')');
  360. if( op < 1 ) {
  361. h_msg = window.setTimeout("showMessage('');",30);
  362. } else {
  363. if( f_msg ) {
  364. h_msg = window.setTimeout(removeMessage,5 * 1000);
  365. }
  366. }
  367. }
  368. function removeMessage() {
  369. if( h_msg ) {
  370. clearTimeout(h_msg);
  371. }
  372. if( op > 0 )
  373. op -= 0.1;
  374. $("#admin_tips").css('opacity', op );
  375. $("#admin_tips").css('MozOpacity', op );
  376. $("#admin_tips").css('KhtmlOpacity', op );
  377. $("#admin_tips").css('filter', 'alpha(opacity=' + op * 100 + ')');
  378. if( op > 0 ) {
  379. h_msg = window.setTimeout(removeMessage,30);
  380. } else {
  381. $("#admin_tips").css('visibility','hidden');
  382. if(t_msg != ''){
  383. showMessage(t_msg);
  384. t_msg = '';
  385. }
  386. }
  387. }
  388. function msg_onmouseover() {
  389. if( h_msg )
  390. clearTimeout(h_msg);
  391. f_msg = false;
  392. h_msg = window.setTimeout("showMessage('')",30);
  393. }
  394. function msg_onmouseout() {
  395. if( h_msg )
  396. clearTimeout(h_msg);
  397. f_msg = true;
  398. h_msg = window.setTimeout("showMessage('')",30);
  399. }
  400. function ShowHideDiv(id){
  401. try{
  402. var panel=document.getElementById(id);
  403. if(panel){
  404. if(panel.style.display=='none'){
  405. panel.style.display='block';
  406. }else{
  407. panel.style.display='none';
  408. }
  409. }
  410. }catch(e){}
  411. }