/admin/include/admin.js
JavaScript | 467 lines | 314 code | 55 blank | 98 comment | 69 complexity | 7876dfde02db425f457550bb577bfd06 MD5 | raw file
Possible License(s): AGPL-1.0
- /*
- Fcten: Thanks to mg12's excellent work that I can use it with few modifications.
- Author: mg12
- Tutorial URL: http://www.neoease.com/wordpress-menubar-5/
- */
- /** ? */
- var Class = {
- create: function() {
- return function() {
- this.initialize.apply(this, arguments);
- }
- }
- }
- /** ???? */
- var MenuList = Class.create();
- MenuList.prototype = {
- /**
- * ????
- * id: ????
- * opacity: ???? (0.0 - 1.0, 0.0 ????, 1.0 ????)
- */
- initialize: function(id, opacity) {
- // ??????
- this.obj = document.getElementById(id);
- if (!this.obj) { return; }
- /* multi 2009/06/11 ADD START */
- // ???????
- var menus = this.obj.getElementsByTagName('ul');
- for (var i = 0; i < menus.length; i++) {
- // ???????? (????????)
- var menu = menus[i].parentNode;
- // ?????????????, ???????
- if(menu.parentNode === this.obj) {
- new Menu(menu, opacity);
- // ?????????????, ??????????
- } else {
- new Menu(menu, opacity, 1);
- // ???????????? class ?, ??????
- menu.firstChild.className += ' admin_submenu';
- //menu.className = 'admin_submenu';
- }
- }
- /* multi 2009/06/11 ADD END */
- /* multi 2009/06/11 DELETE START */
- /*
- // ???????????????
- var menus = this.obj.childNodes;
- for (var i = 0; i < menus.length; i++) {
- var menu = menus[i];
- if (menu.tagName == 'LI') {
- // ????
- new Menu(menu, opacity);
- }
- }
- */
- /* multi 2009/06/11 DELETE START */
- }
- }
- /** ?? */
- var Menu = Class.create();
- Menu.prototype = {
- /**
- * ????
- * target: ????
- * opacity: ???? (0.0 - 1.0, 0.0 ????, 1.0 ????)
- * sub: ?????? (1 ???, -1 ???) [multi 2009/06/11 ADD]
- */
- initialize: function(target, opacity, sub) {
- this.util = new MenuUtil();
- // ?????? (?????)
- this.obj = this.util.cleanWhitespace(target);
- // ?????, ????
- this.opacity = 0;
- this.maxopacity = opacity || 1;
- /* multi 2009/06/11 ADD START */
- // ??????
- this.sub = sub || -1;
- /* multi 2009/06/11 ADD START */
- // ????
- this.menu = this.obj.childNodes
- // ??! ??????????, ??????
- if (this.menu.length < 2) { return; }
- // ????????
- this.title = this.menu[0];
- this.body = this.menu[1];
- // ??????
- this.util.setStyle(this.body, 'visibility', 'hidden');
- this.util.setStyle(this.body, 'position', 'absolute');
- /* multi 2009/06/11 DELETE START */
- //this.util.setStyle(this.body, 'overflow', 'hidden');
- /* multi 2009/06/11 DELETE END */
- this.util.setStyle(this.body, 'display', 'block');
- // ?????
- this.addListener(this.obj, 'mouseover', this.util.bind(this, this.activate), false);
- this.addListener(this.obj, 'mouseout', this.util.bind(this, this.deactivate), false);
- },
- /**
- * ????
- * ?????????????
- */
- activate: function() {
- /* multi 2009/06/11 CHANGE START */
- // ?????????? (???)
- if(this.sub == 1) {
- var pos = this.util.currentOffset(this.title);
- var left = this.util.getWidth(this.body) + 1;
- var top = pos[1] - 5;
- // ?????????? (??)
- } else {
- var pos = this.util.cumulativeOffset(this.title);
- var left = pos[0] - 10;
- var top = pos[1] + this.util.getHeight(this.title) + 3;
- // ????????????, ?????????, ????.
- // this.util.setStyle(this.body, 'opacity', this.opacity);
- }
- /* multi 2009/06/11 CHANGE START */
- /* multi 2009/06/11 ADD START */
- // ???????? class ??, ??????
- this.title.className += ' current_item';
- /* multi 2009/06/11 ADD END */
- // ???????
- this.util.setStyle(this.body, 'left', left + 'px');
- this.util.setStyle(this.body, 'top', top + 'px');
- this.util.setStyle(this.body, 'visibility', 'visible');
- this.util.setStyle(this.body, 'opacity', this.opacity);
- this.util.setStyle(this.body, 'MozOpacity', this.opacity);
- this.util.setStyle(this.body, 'KhtmlOpacity', this.opacity);
- this.util.setStyle(this.body, 'filter', 'alpha(opacity=' + this.opacity * 100 + ')');
- if(this.tid) {
- clearTimeout(this.tid);
- }
- this.tid = setInterval(this.util.bind(this, this.appear), 30);
- /* multi 2009/06/11 DELETE START */
- // ???????????? (?????????)
- //this.util.setStyle(this.body, 'opacity', this.opacity);
- // IE ????????, ??????????
- //this.util.setStyle(this.body, 'filter', 'alpha(opacity=' + this.opacity * 100 + ')');
- /* multi 2009/06/11 DELETE END */
- },
- appear: function() {
- this.opacity += 0.1;
- if(this.opacity >= this.maxopacity) {
- this.opacity = this.maxopacity;
- clearTimeout(this.tid);
- }
- this.util.setStyle(this.body, 'opacity', this.opacity);
- this.util.setStyle(this.body, 'MozOpacity', this.opacity);
- this.util.setStyle(this.body, 'KhtmlOpacity', this.opacity);
- this.util.setStyle(this.body, 'filter', 'alpha(opacity=' + this.opacity * 100 + ')');
- },
- /**
- * ????
- * ?????????????
- */
- deactivate: function(){
- // ???????
- // this.util.setStyle(this.body, 'visibility', 'hidden');
- if(this.tid) {
- clearTimeout(this.tid);
- }
- /* multi 2009/06/11 ADD START */
- // ????????????? class ?, ???????
- this.title.className = this.title.className.replace('current_item', '');
- /* multi 2009/06/11 ADD END */
- this.tid = setInterval(this.util.bind(this, this.fade), 30);
- },
- fade: function() {
- this.opacity -= 0.1;
- if(this.opacity <= 0) {
- this.opacity = 0;
- this.util.setStyle(this.body, 'visibility', 'hidden');
- clearTimeout(this.tid);
- }
- this.util.setStyle(this.body, 'opacity', this.opacity);
- this.util.setStyle(this.body, 'MozOpacity', this.opacity);
- this.util.setStyle(this.body, 'KhtmlOpacity', this.opacity);
- this.util.setStyle(this.body, 'filter', 'alpha(opacity=' + this.opacity * 100 + ')');
- },
- /**
- * ????
- * element: ????
- * name: ????
- * observer: ?????
- * useCapture: ?????????? (true ? Capture ??, false ? Bubbling ??)
- */
- addListener: function(element, name, observer, useCapture) {
- if(element.addEventListener) {
- element.addEventListener(name, observer, useCapture);
- } else if(element.attachEvent) {
- element.attachEvent('on' + name, observer);
- }
- }
- }
- /** ??????? */
- var MenuUtil = Class.create();
- MenuUtil.prototype = {
- initialize: function() {
- },
- $: function(id) {
- return document.getElementById(id);
- },
- $A: function(iterable) {
- if(!iterable) {
- return [];
- }
- if(iterable.toArray) {
- return iterable.toArray();
- } else {
- var results = [];
- for(var i = 0; i < iterable.length; i++) {
- results.push(iterable[i]);
- }
- return results;
- }
- },
- bind: function() {
- var array = this.$A(arguments);
- var func = array[array.length - 1];
- var _method = func, args = array, object = args.shift();
- return function() {
- return _method.apply(object, args.concat(array));
- }
- },
- getHeight: function(element) {
- return element.offsetHeight;
- },
- setStyle: function(element, key, value) {
- element.style[key] = value;
- },
- getStyle: function(element, key) {
- return element.style[key];
- },
- cleanWhitespace: function(list) {
- var node = list.firstChild;
- while (node) {
- var nextNode = node.nextSibling;
- if(node.nodeType == 3 && !/\S/.test(node.nodeValue)) {
- list.removeChild(node);
- }
- node = nextNode;
- }
- return list;
- },
- cumulativeOffset: function(element) {
- var valueT = 0, valueL = 0;
- do {
- valueT += element.offsetTop || 0;
- valueL += element.offsetLeft || 0;
- element = element.offsetParent;
- } while (element);
- return [valueL, valueT];
- },
- /* multi 2009/06/11 ADD START */
- getWidth: function(element) {
- return element.offsetWidth;
- },
- currentOffset: function(element) {
- var valueT = element.offsetTop || 0;
- var valueL = element.offsetLeft || 0;
- return [valueL, valueT];
- }
- /* multi 2009/06/11 ADD END */
- }
- /*---------------------------------*/
- function ajax_load( BlogPath, M, P, E, I ){
- $("#admin_loading").fadeIn('slow');
- var URL = BlogPath + 'index.php?m=' + M;
- if( P != null ) {
- URL += '&p=' + P;
- }
- if( E != null ) {
- URL += '&page=' + E;
- }
- if( I != null ) {
- URL += '&id=' + I;
- }
- URL += '&ohash=' + ohash;
- $.get(URL,function(data){
- if(data=='forbidden'){
- document.location.href='./';
- return;
- }
- $("#admin_content").html(data);
- $("#admin_loading").fadeOut('slow');
- });
- }
- function ajax_get( BlogPath, M, P, E, I ){
- $("#admin_loading").fadeIn('slow');
- var URL = BlogPath + 'index.php?m=' + M;
- if( P != null ) {
- URL += '&p=' + P;
- }
- if( E != null ) {
- URL += '&page=' + E;
- }
- if( I != null ) {
- URL += '&id=' + I;
- }
- URL += '&ohash=' + ohash;
- $.get(URL,function(data){
- if(data=='forbidden'){
- document.location.href='./';
- return;
- }
- showMessage(data);
- $("#admin_loading").fadeOut('slow');
- });
- }
- function menuClick( e, M, P ){
- ajax_load( AdminPath, M, P );
- if(e) {
- changeSelect(e);
- }
- }
- function Logout(){
- ajax_get( AdminPath, 'login', 'logout' );
- }
- // ???????????????
- function changeSelect(e){
- var el = document.getElementById('admin_menu').childNodes;
- for(var i=0;i<el.length;i++){
- //alert(el.length);
- //alert(el[i].childNodes.length);
- for(var j=0;j<el[i].childNodes.length;j++) {
- el[i].childNodes[j].className = el[i].childNodes[j].className.replace('selected','');
- for(var k=0;k<el[i].childNodes[j].childNodes.length;k++) {
- for(var l=0;l<el[i].childNodes[j].childNodes[k].childNodes.length;l++) {
- el[i].childNodes[j].childNodes[k].childNodes[l].className = el[i].childNodes[j].childNodes[k].childNodes[l].className.replace('selected','');
- }
- }
- }
- }
- e.className += ' selected';
- }
- var h_msg,f_msg = true,op = 0,t_msg = '';
- function showMessage(msg) {
- if( h_msg ) {
- clearTimeout(h_msg);
- }
- if( $("#admin_tips").css('visibility') == 'hidden' ) {
- op = 0;
- $("#admin_tips").html(msg);
- $("#admin_tips").css('opacity', 0);
- $("#admin_tips").css('MozOpacity', 0);
- $("#admin_tips").css('KhtmlOpacity',0);
- $("#admin_tips").css('filter', 'alpha(opacity=0)');
- $("#admin_tips").css('visibility','visible');
- } else {
- if( msg != '' ) {
- t_msg = msg;
- removeMessage();
- }
- }
- if( op < 1)
- op += 0.1;
- $("#admin_tips").css('opacity', op );
- $("#admin_tips").css('MozOpacity', op );
- $("#admin_tips").css('KhtmlOpacity', op );
- $("#admin_tips").css('filter', 'alpha(opacity=' + op * 100 + ')');
- if( op < 1 ) {
- h_msg = window.setTimeout("showMessage('');",30);
- } else {
- if( f_msg ) {
- h_msg = window.setTimeout(removeMessage,5 * 1000);
- }
- }
- }
- function removeMessage() {
- if( h_msg ) {
- clearTimeout(h_msg);
- }
- if( op > 0 )
- op -= 0.1;
- $("#admin_tips").css('opacity', op );
- $("#admin_tips").css('MozOpacity', op );
- $("#admin_tips").css('KhtmlOpacity', op );
- $("#admin_tips").css('filter', 'alpha(opacity=' + op * 100 + ')');
- if( op > 0 ) {
- h_msg = window.setTimeout(removeMessage,30);
- } else {
- $("#admin_tips").css('visibility','hidden');
- if(t_msg != ''){
- showMessage(t_msg);
- t_msg = '';
- }
- }
- }
- function msg_onmouseover() {
- if( h_msg )
- clearTimeout(h_msg);
- f_msg = false;
- h_msg = window.setTimeout("showMessage('')",30);
- }
- function msg_onmouseout() {
- if( h_msg )
- clearTimeout(h_msg);
- f_msg = true;
- h_msg = window.setTimeout("showMessage('')",30);
- }
- function ShowHideDiv(id){
- try{
- var panel=document.getElementById(id);
- if(panel){
- if(panel.style.display=='none'){
- panel.style.display='block';
- }else{
- panel.style.display='none';
- }
- }
- }catch(e){}
- }