/**//*
** 著者 : Jonllen
** 作成 : 2010-05-01
** 更新 : 2010-05-09
** SVN : 153
** ウェブサイト: http://www.jonllen.com/
*/
var ContextMenu = function (settings) ...{
for( p in this.settings)
...{
if ( !settings.hasOwnProperty(p) ) 設定[p] = this.settings[p];
}
this.settings = 設定;
this.settings.menu = document.createElement('div');
this.settings.menu.className = this.settings.css;
this.settings.menu.style.cssText = '位置:絶対;表示:なし;';
document.body.insertBefore(this.settings.menu,document.body.childNodes[0]);
これを返します;
}
ContextMenu.prototype = ...{
list : new Array()、
active : new Array()、
iframes : new Array()、
settings : ...{
メニュー : null,
excursionX : 0,
excursionY : 0,
css : 'contextmenu',
コンテナ : null,
ロック : false
},
item : ...{
id : null,
level : 1,
parentId : 0,
html : '',
title : '',
href : 'javascript:;'、
ターゲット : '_self'、
css : null、
要素 : null、
childElement : null、
親 : null、
子: null,
type : 'static',
click : null,
clickClose : false
},
push : function (item) ...{
var list = Object .prototype.toString.apply(item) === '[オブジェクト配列]' ?アイテム : [アイテム];
for( var i=0; i
var _item = list[i];
for( p in this.item) ...{
if( !_item.hasOwnProperty(p) ) _item[p] = this.item[p];
}
_item.element = null;
if( _item.name ) _item.html = _item.name;
if( _item.url ) _item.href = _item.url;
if( _item.type == 'static') ...{
this.list.push(_item);
}else ...{
if(this.dynamic == null) this.dynamic = new Array();
this.dynamic.push(_item);
}
}
これを返します;
},
bind : function ()...{
var _this = this;
for( var i=0; this.dynamic && i...{
var item = this.dynamic[i];
var itemElem = document.createElement('div');
itemElem.title = item.title;
itemElem.innerHTML = '' item.html '';
itemElem.className = 'item ' (item.css?' ' item.css:'');
item.element = itemElem;
if( item.click ) ...{
(function (item)...{
item.element.childNodes[0].onclick = function (e)...{
if( item.clickClose) _this.hidden();
return item.click(e)
})(item);
}
itemElem.contextmenu = アイテム;
itemElem.onmouseover = function (e)...{ _this.hidden(item.level);};
var インデックス = item.index || 0;
if(index >= this.settings.menu.childNodes.length)
index = this.settings.menu.childNodes.length - 1;
if(index this.settings.menu.appendChild(itemElem);
else
this.settings.menu.insertBefore(itemElem, this.settings.menu.childNodes[index]);
}
},
render : function (container) ...{
var _this = this;
コンテナ = コンテナ || this.settings.container;
this.settings.menu.innerHTML = '';
for( var i=0;i < this.list.length; i )
...{
var item = this.list[i];
if ( item.parentId != 0 ) 続行;
var itemElem = document.createElement('div');
itemElem.title = item.title;
itemElem.innerHTML = '' item.html '';
itemElem.className = 'item ' (item.css?' ' item.css:'');
vardisabled = _this.hasClass(itemElem, 'disabled');
if (無効) ...{
itemElem.childNodes[0].disabled = true;
itemElem.childNodes[0].className = '無効';
itemElem.childNodes[0].removeAttribute('href');
}
if ( _this.hasClass(itemElem, 'hidden') ) ...{
itemElem.style.display = 'none';
}
if( item.click ) ...{
(function (item)...{
item.element.childNodes[0].onclick = function (e)... {
if( item.clickClose) _this.hidden();
return item.click(e)
})(item);
}
itemElem.contextmenu = アイテム;
itemElem.contextmenu.children = this.getChlid(item.id);
if( itemElem.contextmenu.children.length > 0 )
itemElem.childNodes[0].className = ' hasChild';
itemElem.onmouseover = function (e)...{ _this.renderChlid(this);};
this.settings.menu.appendChild(itemElem);
}
this.active[0] = ...{ 要素 : _this.settings.menu };
this.settings.menu.contextmenu = _this;
container.oncontextmenu = function (e)...{
e = window.event || e;
var target = e.target || e.src要素;
if( e.preventDefault)
e.preventDefault();
var MouseCoords = _this.mouseCoords(e);
_this.settings.menu.style.left = MouseCoords.x _this.settings.excursionX 'px';
_this.settings.menu.style.top = MouseCoords.y _this.settings.excursionY 'px';
_this.hidden();
_this.show(0, ターゲット);
false を返します。
};
this.addEvent(document, 'click', function (e)...{
e = window.event || e;
var target = e.target || e.srcElement;
var isContextMenu = !!target.contextmenu;
if( isContextMenu == false) ...{
varparent = target.parentNode;
while(parent!=null) >if(parent.contextmenu) ...{
isContextMenu = true;
}
parent =parent.parentNode; == false) ...{
_this.hidden()
}
});
},
renderChlid : function ( target )...{
if(this.settings.locked) return;
var contextmenu = target.contextmenu;
var currentLevel = contextmenu.level;
this.hidden(currentLevel);
var hasChild = false;
for( var j=0;jif( (' ' contextmenu.children[j].css ' ').indexOf(' hidden ') == -1) ...{
hasChild = true;
休憩;
}
}
if( !hasChild) return;
var childElem = contextmenu.element;
if (childElem == null) ...{
childElem = document.createElement('div');
childElem.className = this.settings.css;
childElem.style.position = '絶対';
childElem.style.zIndex = 1000 contextmenu.level;
var _this = this;
for( var i=0;i < contextmenu.children.length; i )
...{
var childItem = contextmenu.children[i];
var childItemElem = document.createElement('div');
childItemElem.title = childItem.title;
childItemElem.innerHTML = '' childItem.html '';
childItemElem.className = 'item' (childItem.css?' ' childItem.css : '');
vardisabled = this.hasClass(childItemElem, 'disabled');
if (無効) ...{
childItemElem.childNodes[0].disabled = true;
childItemElem.childNodes[0].removeAttribute('href');
}
if ( this.hasClass(childItemElem, 'hidden') ) ...{
childItemElem.style.display = 'none';
}
if( childItem.click ) ...{
(function (childItem)...{
childItem.element.childNodes[0].onclick = function (e)... {
if( childItem.clickClose) _this.hidden();
return childItem.click(e)
})(childItem);
}
childItem.parent = contextmenu;
childItemElem.contextmenu = childItem;
childItemElem.contextmenu.children = this.getChlid(childItem.id);
var hasChild = false;
for( var j=0; jif( (' ' childItemElem.contextmenu.children[j].css ' ').indexOf( ' 非表示 ') == -1) ...{
hasChild = true;
休憩;
}
}
if( hasChild ) ...{
childItemElem.childNodes[0].className = ' hasChild';
}
childItemElem.onmouseover = function (e)...{ _this.renderChlid(this);};
childElem.appendChild(childItemElem);
}
document.body.insertBefore(childElem,document.body.childNodes[0]);
contextmenu.element = childElem;
}
this.active[currentLevel] = contextmenu;
var xy = this.elemOffset(target);
var x = xy.x target.offsetWidth this.settings.excursionX;
var y = xy.y this.settings.excursionY;
childElem.style.left = x 'px';
childElem.style.top = y 'px';
childElem.style.display = 'ブロック';
this.show(currentLevel);
},
getChlid : function (id) ...{
var list = new Array();
for( var i=0;i < this.list.length; i )
...{
var item = this.list[i];
if( item.parentId == id)
...{
list.push(item);
}
}
リストを返します。
},
show : function (level, target) ...{
if(this.settings.locked) return;
レベル = レベル || 0;
var item = this.active[レベル];
if ( level == 0 ) ...{
for( var i=0;this.dynamic && i < this.dynamic.length; i )
...{
var DynamicItemElem = this.dynamic[i].element;
if(dynamicItemElem !=null)dynamicItemElem.parentNode.removeChild(dynamicItemElem);
}
if (this.dynamic) this.dynamic.length = 0;
this.onShow(ターゲット, this);
}
var menuElem = item.element;
menuElem.style.display = 'ブロック';
var iframeElem = this.iframes[レベル];
if ( iframeElem == null) ...{
iframeElem = document.createElement('iframe');
iframeElem.scrolling = 'いいえ';
iframeElem.frameBorder = 0;
iframeElem.style.cssText = '位置:絶対;オーバーフロー:非表示;';
document.body.insertBefore(iframeElem,document.body.childNodes[0]);
this.iframes.push(iframeElem);
}
iframeElem.width = menuElem.offsetWidth;
iframeElem.height = menuElem.offsetHeight;
var menuElemOffset = this.elemOffset(menuElem);
iframeElem.style.left = menuElemOffset.x 'px';
iframeElem.style.top = menuElemOffset.y 'px';
iframeElem.style.display = 'ブロック';
},
onShow : function (target, _this) ...{
if( target.nodeType == 1 && target.tagName == 'A' && target.innerHTML.indexOf('.rar') != -1 )...{
//解压文件
_this.push( ...{
html : '解压缩到“' target.innerHTML.substring(0,target.innerHTML.lastIndexOf( '.')) '\”...',
click : function (e)...{
e = e || e .target;
srcElement.className = 'on';
srcElement.innerHTML = '解压缩へ' target.innerHTML.substring(0,target.innerHTML.lastIndexOf('.')) '\”。 ..';
var url = '/Ajax/FileZip.aspx?mode=unzip&files=' target.href.substring(target.href.replace('//','xx').indexOf('/' ));
if( Ajax のタイプ == '未定義') return;
Ajax.get(url, function (data, _this)...{
_this.settings.locked = true;
eval(data);
if( rs.success ) ...{
location.reload();
}else...{
alert(rs.error); _this.hidden();
}
}, _this);
srcElement.onclick = null;
},
clickClose : false;
インデックス : 2、
タイプ : '動的'
});
}
else if( target.nodeType == 1 && target.title.indexOf('追加へ') == 0) ...{
// 追加单个压缩文件
_this. Push( ...{
html : target.title,
title : target.title,
click : function (e)...{
varindex = target.href.indexOf(' ?path=');
if(index != -1)...{
var fullName = target.href.substring(index '?path='.length);
}else .. .{
var fullName = target.href.substring(target.href.replace('//','xx').indexOf('/'));
}
e = e || window.event;
var srcElement = e.srcElement || e.target;
srcElement.className = '正在追加' fullName.lastIndexOf ('/') 1) '.rar”...';
var url = '/Ajax/FileZip.aspx?mode=zip&files='
if( typeof Ajax == 'unknown') return;
Ajax.get(url, function (data, _this)...{
_this.settings.locked = true;
eval(data);
if( rs.success ) . ..{
location.reload();
}else...{
alert(rs.error);
}
}; );
srcElement.onclick = null;
_this.settings.locked = true;
},
clickClose : false,
index : 2,
type : 'dynamic',
css : 'on'
});
}else ...{
// 多个压缩文件を追加
var fileName = '';
var ファイル = new Array();
var ids = document.getElementsByName('ids');
for( var i=0; iif( !ids[i].checked) continue;
var ファイル = ids[i].value;
files.push(ファイル);
if( files.length == 1) ...{
fileName = file.substring(file.lastIndexOf('/') 1) '.rar';
}
}
if( files.length > 0 )...{
_this.push( ...{
html : '追加' files.length '个文件到压缩包“' fileName '”',
click : function (e)...{
e = e ||
var srcElement = e.srcElement || 🎜>srcElement.className = 'on';
srcElement.innerHTML = '正在追加“' fileName '”...'
var url = '/Ajax/FileZip.aspx?mode=zip&files='; files.join('|');
if( typeof Ajax == '未定義') return;
Ajax.get(url, function (data, _this)...{
_this.settings.ロック = true;
eval(data);
if( rs.success ) ...{
location.reload();
alert(rs.エラー);
_this.hidden();
}
}, _this);
_this.settings.locked = true; 🎜>clickClose : false,
index : 2,
type : 'dynamic'
});
}
}
if( target.nodeType == 1 && target.tagName == 'A') ...{
_this.push( ...{
html : 'プロパティ”' target.innerHTML '”',
href : target.href,
click : function (e)...{
prompt(' プロパティ”' target.innerHTML '”',target. href);
return false;
}、
clickClose : true、
index : 3、
type : 'dynamic'
});
}
varselection = window.getSelection ? window.getSelection().toString() : document.selection.createRange().text;
if(selection) ...{
_this.push( ...{
html : '复制“' (selection.length > 15 ?selection.substring(0,12) '.. .' : 選択) '”',
タイトル : '复制”' 選択 '”',
クリック : function (e) ...{
if(window.clipboardData) ...{
window.clipboardData.clearData();
window.clipboardData.setData("テキスト",
}else ...{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var Clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!clip || !trans) return;
trans.addDataFlavor('text/unicode');
var len = 新しいオブジェクト();
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
str.data = 選択;
trans.setTransferData("text/unicode",str,selection.length*2);
var Clipid=Components.interfaces.nsIClipboard;
if (!clip) は false を返します。
clip.setData(trans,null,clipid.kGlobalClipboard);
}
},
clickClose : true,
index : 0,
type : 'dynamic'
});
}
_this.bind();
},
hidden : 関数 (レベル) ...{
レベル = レベル || 0;
for( var i = level; ivar item = this.active[i];
var iframeElem = this.iframes[i];
if ( iframeElem !=null)
iframeElem.style.display = 'none';
if(this.settings.locked) return;
var menuElem = item.element;
if ( menuElem !=null)
menuElem.style.display = 'none';
}
this.onHidden(レベル);
},
onHidden : 関数 (レベル) ...{
},
hasClass : 関数 (elem, 名前)
...{
return !!elem && ( ' ' elem.className ' ').indexOf(' ' 名前 ' ') != -1;
},
elemOffset : function(elem)...{
var left = 0;
var トップ = 0;
while (elem.offsetParent)...{
left = elem.offsetLeft;
トップ = elem.offsetTop;
elem = elem.offsetParent;
}
left = elem.offsetLeft;
トップ = elem.offsetTop;
return ...{x:left, y:top};
},
mouseCoords : function (e)...{
if (e.pageX && e.pageY) ...{
return ...{
x: e. pageX,
y: e.pageY
};
}
var d = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement : document.body;
return ...{
x: e.clientX d.scrollLeft,
y: e.clientY d.scrollTop
};
},
addEvent : function(target,eventType,func)...{
if(target.attachEvent)
...{
target.attachEvent("on"eventType,関数);
}else if(target.addEventListener)
...{
target.addEventListener(eventType == 'mousewheel' ? 'DOMMouseScroll' :eventType, func, false);
}
これを返します;
},
removeEvent : function(target,eventType,func)...{
if(target.detachEvent)
...{
target.detachEvent("on"eventType,関数);
}else if(target.removeEventListener)
...{
target.removeEventListener(eventType == 'mousewheel' ? 'DOMMouseScroll' :eventType, func, false);
}
これを返します;
}
}