@ -1,12 +1,12 @@
var lastShownContexMenu = null ;
var ContextMenu = new Class ( {
var ContextMenu = new Class ( {
//implements
//implements
Implements : [ Options , Events ] ,
Implements : [ Options , Events ] ,
//options
//options
options : {
options : {
actions : { } ,
actions : { } ,
menu : 'context menu' ,
menu : 'menu_id ' ,
stopEvent : true ,
stopEvent : true ,
targets : 'body' ,
targets : 'body' ,
trigger : 'contextmenu' ,
trigger : 'contextmenu' ,
@ -54,6 +54,57 @@ var ContextMenu = new Class({
} ) ;
} ) ;
} ,
} ,
adjustMenuPosition : function ( e ) {
this . updateMenuItems ( ) ;
// draw the menu off-screen to know the menu dimentions
this . menu . setStyles ( {
left : '-999em' ,
top : '-999em'
} ) ;
// position the menu
var xPos = e . page . x + this . options . offsets . x ;
var yPos = e . page . y + this . options . offsets . y ;
if ( xPos + this . menu . offsetWidth > document . documentElement . clientWidth )
xPos -= this . menu . offsetWidth ;
if ( yPos + this . menu . offsetHeight > document . documentElement . clientHeight )
yPos -= this . menu . offsetHeight ;
if ( xPos < 0 )
xPos = 0 ;
if ( yPos < 0 )
yPos = 0 ;
this . menu . setStyles ( {
left : xPos ,
top : yPos ,
position : 'absolute' ,
'z-index' : '2000'
} ) ;
// position the sub-menu
var uls = this . menu . getElementsByTagName ( 'ul' ) ;
for ( var i = 0 ; i < uls . length ; i ++ ) {
var ul = uls [ i ] ;
var rectParent = ul . parentNode . getBoundingClientRect ( ) ;
var xPosOrigin = rectParent . left ;
var yPosOrigin = rectParent . bottom ;
var xPos = xPosOrigin + rectParent . width - 1 ;
var yPos = yPosOrigin - rectParent . height - 1 ;
if ( xPos + ul . offsetWidth > document . documentElement . clientWidth )
xPos -= ( ul . offsetWidth + rectParent . width - 2 ) ;
if ( yPos + ul . offsetHeight > document . documentElement . clientHeight )
yPos -= ( ul . offsetHeight - rectParent . height - 2 ) ;
if ( xPos < 0 )
xPos = 0 ;
if ( yPos < 0 )
yPos = 0 ;
ul . setStyles ( {
'margin-left' : xPos - xPosOrigin ,
'margin-top' : yPos - yPosOrigin
} ) ;
}
} ,
addTarget : function ( t ) {
addTarget : function ( t ) {
this . targets [ this . targets . length ] = t ;
this . targets [ this . targets . length ] = t ;
t . addEvent ( this . options . trigger , function ( e ) {
t . addEvent ( this . options . trigger , function ( e ) {
@ -65,13 +116,7 @@ var ContextMenu = new Class({
}
}
//record this as the trigger
//record this as the trigger
this . options . element = $ ( t ) ;
this . options . element = $ ( t ) ;
//position the menu
this . adjustMenuPosition ( e ) ;
this . menu . setStyles ( {
top : ( e . page . y + this . options . offsets . y ) ,
left : ( e . page . x + this . options . offsets . x ) ,
position : 'absolute' ,
'z-index' : '2000'
} ) ;
//show the menu
//show the menu
this . show ( ) ;
this . show ( ) ;
}
}
@ -95,13 +140,7 @@ var ContextMenu = new Class({
}
}
//record this as the trigger
//record this as the trigger
this . options . element = $ ( el ) ;
this . options . element = $ ( el ) ;
//position the menu
this . adjustMenuPosition ( e ) ;
this . menu . setStyles ( {
top : ( e . page . y + this . options . offsets . y ) ,
left : ( e . page . x + this . options . offsets . x ) ,
position : 'absolute' ,
'z-index' : '2000'
} ) ;
//show the menu
//show the menu
this . show ( ) ;
this . show ( ) ;
}
}
@ -128,6 +167,76 @@ var ContextMenu = new Class({
} . bind ( this ) ) ;
} . bind ( this ) ) ;
} ,
} ,
updateMenuItems : function ( ) { } ,
//show menu
show : function ( trigger ) {
if ( lastShownContexMenu && lastShownContexMenu != this )
lastShownContexMenu . hide ( ) ;
this . fx . start ( 1 ) ;
this . fireEvent ( 'show' ) ;
this . shown = true ;
lastShownContexMenu = this ;
return this ;
} ,
//hide the menu
hide : function ( trigger ) {
if ( this . shown ) {
this . fx . start ( 0 ) ;
//this.menu.fade('out');
this . fireEvent ( 'hide' ) ;
this . shown = false ;
}
return this ;
} ,
setItemChecked : function ( item , checked ) {
this . menu . getElement ( 'a[href$=' + item + ']' ) . firstChild . style . opacity =
checked ? '1' : '0' ;
return this ;
} ,
getItemChecked : function ( item ) {
return '0' != this . menu . getElement ( 'a[href$=' + item + ']' ) . firstChild . style . opacity ;
} ,
//hide an item
hideItem : function ( item ) {
this . menu . getElement ( 'a[href$=' + item + ']' ) . parentNode . addClass ( 'invisible' ) ;
return this ;
} ,
//show an item
showItem : function ( item ) {
this . menu . getElement ( 'a[href$=' + item + ']' ) . parentNode . removeClass ( 'invisible' ) ;
return this ;
} ,
//disable the entire menu
disable : function ( ) {
this . options . disabled = true ;
return this ;
} ,
//enable the entire menu
enable : function ( ) {
this . options . disabled = false ;
return this ;
} ,
//execute an action
execute : function ( action , element ) {
if ( this . options . actions [ action ] ) {
this . options . actions [ action ] ( element , this ) ;
}
return this ;
}
} ) ;
var TorrentsTableContextMenu = new Class ( {
Extends : ContextMenu ,
updateMenuItems : function ( ) {
updateMenuItems : function ( ) {
all _are _seq _dl = true ;
all _are _seq _dl = true ;
there _are _seq _dl = false ;
there _are _seq _dl = false ;
@ -220,69 +329,40 @@ var ContextMenu = new Class({
this . hideItem ( 'ForceStart' ) ;
this . hideItem ( 'ForceStart' ) ;
else if ( ! there _are _paused && ! there _are _force _start )
else if ( ! there _are _paused && ! there _are _force _start )
this . hideItem ( 'Start' ) ;
this . hideItem ( 'Start' ) ;
} ,
} ,
//show menu
updateCategoriesSubMenu : function ( category _list ) {
show : function ( trigger ) {
var categoryList = $ ( 'contextCategoryList' ) ;
this . updateMenuItems ( ) ;
categoryList . empty ( ) ;
this . fx . start ( 1 ) ;
categoryList . appendChild ( new Element ( 'li' , { html : '<a href="javascript:torrentNewCategoryFN();"><img src="theme/list-add" alt="QBT_TR(New...)QBT_TR"/> QBT_TR(New...)QBT_TR</a>' } ) ) ;
this . fireEvent ( 'show' ) ;
categoryList . appendChild ( new Element ( 'li' , { html : '<a href="javascript:torrentSetCategoryFN(0);"><img src="theme/edit-clear" alt="QBT_TR(Reset)QBT_TR"/> QBT_TR(Reset)QBT_TR</a>' } ) ) ;
this . shown = true ;
return this ;
} ,
//hide the menu
var sortedCategories = [ ]
hide : function ( trigger ) {
Object . each ( category _list , function ( category ) {
if ( this . shown ) {
sortedCategories . push ( category . name ) ;
this . fx . start ( 0 ) ;
} ) ;
//this.menu.fade('out');
sortedCategories . sort ( ) ;
this . fireEvent ( 'hide' ) ;
this . shown = false ;
var first = true ;
}
Object . each ( sortedCategories , function ( categoryName ) {
return this ;
var categoryHash = genHash ( categoryName ) ;
} ,
var el = new Element ( 'li' , { html : '<a href="javascript:torrentSetCategoryFN(\'' + categoryHash + '\');"><img src="theme/inode-directory"/> ' + escapeHtml ( categoryName ) + '</a>' } ) ;
if ( first ) {
setItemChecked : function ( item , checked ) {
el . addClass ( 'separator' ) ;
this . menu . getElement ( 'a[href$=' + item + ']' ) . firstChild . style . opacity =
first = false ;
checked ? '1' : '0' ;
return this ;
} ,
getItemChecked : function ( item ) {
return '0' != this . menu . getElement ( 'a[href$=' + item + ']' ) . firstChild . style . opacity ;
} ,
//hide an item
hideItem : function ( item ) {
this . menu . getElement ( 'a[href$=' + item + ']' ) . parentNode . addClass ( 'invisible' ) ;
return this ;
} ,
//show an item
showItem : function ( item ) {
this . menu . getElement ( 'a[href$=' + item + ']' ) . parentNode . removeClass ( 'invisible' ) ;
return this ;
} ,
//disable the entire menu
disable : function ( ) {
this . options . disabled = true ;
return this ;
} ,
//enable the entire menu
enable : function ( ) {
this . options . disabled = false ;
return this ;
} ,
//execute an action
execute : function ( action , element ) {
if ( this . options . actions [ action ] ) {
this . options . actions [ action ] ( element , this ) ;
}
}
return this ;
categoryList . appendChild ( el ) ;
} ) ;
}
}
} ) ;
var CategoriesFilterContextMenu = new Class ( {
Extends : ContextMenu ,
updateMenuItems : function ( ) {
var id = this . options . element . id ;
if ( id != CATEGORIES _ALL && id != CATEGORIES _UNCATEGORIZED )
this . showItem ( 'DeleteCategory' ) ;
else
this . hideItem ( 'DeleteCategory' ) ;
}
} ) ;
} ) ;