matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: create a button
I use this class js code: /*
* -----
* Screenshot Sender - __script_menu.js
* -----
* Menu creator for Screenshot Sender
* -----
*/
var ScriptMenu = function () {
this.ScriptMenu = '';
}
ScriptMenu.prototype = {
/*
Name: AddItem
Purpose: Add an item to the script menu
Parameters: sId - The id of the menu item
sLabel - The label of menu item
bEnabled - If the menu item will be enabled
Return: None
*/
"AddItem" : function (sId, sLabel, bEnabled) {
if (typeof bEnabled === 'undefined') bEnabled = true;
this.ScriptMenu += '<MenuEntry Id=\''+sId+'\' Enabled=\''+bEnabled+'\'>'+sLabel+'</MenuEntry>';
},
/*
Name: AddSubMenu
Purpose: Add a submenu to the menu
Parameters: sLabel - Submenu label
bEnabled - If the submenu is enabled or not
Return: None
*/
"AddSubMenu" : function (sLabel, bEnabled) {
if (typeof bEnabled === 'undefined') bEnabled = true;
this.ScriptMenu += '<SubMenu Label=\''+sLabel+'\' Enabled=\''+bEnabled+'\'>';
},
/*
Name: CloseSubMenu
Purpose: Close the currently open submenu
Parameters: None
Return: None
*/
"CloseSubMenu" : function () {
this.ScriptMenu += '</SubMenu>';
},
/*
Name: AddSeperator
Purpose: Creates a seperator in the menu
Parameters: None
Return: None
*/
"AddSeperator" : function () {
this.ScriptMenu += '<Separator />';
},
/*
Name: ExportMenu
Purpose: Export the xml formed menu
Parameters: None
Return: The menu in xml form
*/
"ExportMenu" : function () {
return '<ScriptMenu>'+this.ScriptMenu+'</ScriptMenu>';
}
}
Which in turn is used like this:
js code: function OnGetScriptMenu(nLocation) {
var bEnabled = (Messenger.MyStatus > STATUS_INVISIBLE);
var bSignedIn = (Messenger.MyStatus >= STATUS_INVISIBLE);
var oMenu = new ScriptMenu();
with (oMenu) {
if (nLocation === MENULOC_CHATWND ) {
AddSubMenu(_lang.text['MenuActiveWindow']);
AddItem('/ssactive', _lang.text['SubMenuSendActiveWindow'], bEnabled);
AddItem('/sssactive', _lang.text['SubMenuSaveActiveWindow'], bSignedIn);
AddSeperator();
AddItem('/ssactive ' + objPreferences['tTimeDelay'], _lang.text['SubMenuSendActiveWindowDelay'], bEnabled);
AddItem('/sssactive ' + objPreferences['tTimeDelay'], _lang.text['SubMenuSaveActiveWindowDelay'], bSignedIn);
CloseSubMenu();
AddSubMenu(_lang.text['MenuFullscreen']);
AddItem('/ssfullscreen', _lang.text['SubMenuSendFullscreen'], bEnabled);
AddItem('/sssfullscreen', _lang.text['SubMenuSaveFullscreen'], bSignedIn);
AddSeperator();
AddItem('/ssfullscreen ' + objPreferences['tTimeDelay'], _lang.text['SubMenuSendFullscreenDelay'], bEnabled);
AddItem('/sssfullscreen ' + objPreferences['tTimeDelay'], _lang.text['SubMenuSaveFullscreenDelay'], bSignedIn);
CloseSubMenu();
AddSubMenu(_lang.text['MenuSelectArea']);
AddItem('/ssselect', _lang.text['SubMenuSendSelectArea'], bEnabled);
AddItem('/sssselect', _lang.text['SubMenuSaveSelectArea'], bSignedIn);
AddSeperator();
AddItem('/ssselect ' + objPreferences['tTimeDelay'], _lang.text['SubMenuSendSelectAreaDelay'], bEnabled);
AddItem('/sssselect ' + objPreferences['tTimeDelay'], _lang.text['SubMenuSaveSelectAreaDelay'], bSignedIn);
CloseSubMenu();
AddSubMenu(_lang.text['MenuClipboard']);
AddItem('/ssclipboard', _lang.text['SubMenuSendClipboard'], bEnabled);
AddItem('/sssclipboard', _lang.text['SubMenuSaveClipboard'], bSignedIn);
CloseSubMenu();
AddSubMenu(_lang.text['MenuPointClickCapture']);
AddItem('/sspcc', _lang.text['SubMenuSendPointClickCapture'], bEnabled);
AddItem('/ssspcc', _lang.text['SubMenuSavePointClickCapture'], bSignedIn);
CloseSubMenu();
if (SelectedMonitor(0, 0, 0, 0, true) > 1) {
AddSubMenu(_lang.text['MenuSelectedMonitor']);
AddItem('/ssmonitor', _lang.text['SubMenuSendSelectedMonitor'], bEnabled);
AddItem('/sssmonitor', _lang.text['SubMenuSaveSelectedMonitor'], bSignedIn);
CloseSubMenu();
}
AddSubMenu(_lang.text['MenuByWindowTitle']);
AddItem('/sswindow', _lang.text['SubMenuSendWindowByTitle'], bEnabled);
AddItem('/ssswindow', _lang.text['SubMenuSaveWindowByTitle'], bSignedIn);
CloseSubMenu();
AddSeperator();
}
if (IsTimerActive == true) {
AddItem('CancelTimer', _lang.text['MenuCancelTimer'], bEnabled);
AddSeperator();
}
AddItem('OpenDirectory', _lang.text['MenuOpenDirectory'], bSignedIn);
AddItem('ScreenshotViewer', _lang.text['MenuScreenshotViewer'], bSignedIn);
if (nLocation === MENULOC_CHATWND && SessionImages.Images.length > 0) {
AddItem('RecentImages', _lang.text['MenuRecentImages'], bEnabled);
AddSeperator();
}
AddItem('Preferences', _lang.text['MenuPreferences'], bSignedIn)
AddSeperator();
AddItem('About', _lang.text['MenuAbout'], bSignedIn)
}
return oMenu.ExportMenu();
}
This post was edited on 02-26-2010 at 05:57 PM by matty.
|
|