📄 menu-for-applications.js
字号:
/************************************************************************************************************
@fileoverview
DHTML Suite for Applications.
Copyright (C) 2006 Alf Magne Kalleland(post@dhtmlgoodies.com)<br>
<br>
This library is free software; you can redistribute it and/or<br>
modify it under the terms of the GNU Lesser General Public<br>
License as published by the Free Software Foundation; either<br>
version 2.1 of the License, or (at your option) any later version.<br>
<br>
This library is distributed in the hope that it will be useful,<br>
but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
Lesser General Public License for more details.<br>
<br>
You should have received a copy of the GNU Lesser General Public<br>
License along with this library; if not, write to the Free Software<br>
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA<br>
<br>
<br>
www.dhtmlgoodies.com<br>
Alf Magne Kalleland<br>
************************************************************************************************************/
/**
*
* @package DHTMLSuite for applications
* @copyright Copyright © 2006, www.dhtmlgoodies.com
* @author Alf Magne Kalleland <post@dhtmlgoodies.com>
*/
/************************************************************************************************************
*
* Global variables
*
************************************************************************************************************/
// {{{ DHTMLSuite.createStandardObjects()
/**
* Create objects used by all scripts
*
* @public
*/
var DHTMLSuite = new Object();
var standardObjectsCreated = false; // The classes below will check this variable, if it is false, default help objects will be created
DHTMLSuite.eventElements = new Array(); // Array of elements that has been assigned to an event handler.
DHTMLSuite.createStandardObjects = function()
{
DHTMLSuite.clientInfoObj = new DHTMLSuite.clientInfo(); // Create browser info object
DHTMLSuite.clientInfoObj.init();
if(!DHTMLSuite.configObj){ // If this object isn't allready created, create it.
DHTMLSuite.configObj = new DHTMLSuite.config(); // Create configuration object.
DHTMLSuite.configObj.init();
}
DHTMLSuite.commonObj = new DHTMLSuite.common(); // Create configuration object.
DHTMLSuite.variableStorage = new DHTMLSuite.globalVariableStorage();; // Create configuration object.
DHTMLSuite.commonObj.init();
window.onunload = function() { DHTMLSuite.commonObj.__clearGarbage(); }
standardObjectsCreated = true;
}
DHTMLSuite.discardElement = function(element) {
element = DHTMLSuite.commonObj.getEl(element);
var gBin = document.getElementById('IELeakGBin');
if (!gBin) {
gBin = document.createElement('DIV');
gBin.id = 'IELeakGBin';
gBin.style.display = 'none';
document.body.appendChild(gBin);
}
// move the element to the garbage bin
gBin.appendChild(element);
gBin.innerHTML = '';
}
/************************************************************************************************************
* Configuration class used by most of the scripts
*
* Created: August, 19th, 2006
* Update log:
*
************************************************************************************************************/
/**
* @constructor
* @class Store global variables/configurations used by the classes below. Example: If you want to
* change the path to the images used by the scripts, change it here. An object of this
* class will always be available to the other classes. The name of this object is
* "DHTMLSuite.configObj". <br><br>
*
* If you want to create an object of this class manually, remember to name it "DHTMLSuite.configObj"
* This object should then be created before any other objects. This is nescessary if you want
* the other objects to use the values you have put into the object. <br>
* @version 1.0
* @version 1.0
* @author Alf Magne Kalleland(www.dhtmlgoodies.com)
**/
DHTMLSuite.config = function()
{
var imagePath; // Path to images used by the classes.
var cssPath; // Path to CSS files used by the DHTML suite.
}
DHTMLSuite.config.prototype = {
// {{{ init()
/**
*
* @public
*/
init : function()
{
this.imagePath = '../images_dhtmlsuite/'; // Path to images
this.cssPath = '../css_dhtmlsuite/'; // Path to images
}
// }}}
,
// {{{ setCssPath()
/**
* This method will save a new CSS path, i.e. where the css files of the dhtml suite are located.
*
* @param string newCssPath = New path to css files
* @public
*/
setCssPath : function(newCssPath)
{
this.cssPath = newCssPath;
}
// }}}
,
// {{{ setImagePath()
/**
* This method will save a new image file path, i.e. where the image files used by the dhtml suite ar located
*
* @param string newImagePath = New path to image files
* @public
*/
setImagePath : function(newImagePath)
{
this.imagePath = newImagePath;
}
// }}}
}
DHTMLSuite.globalVariableStorage = function()
{
var menuBar_highlightedItems; // Array of highlighted menu bar items
this.menuBar_highlightedItems = new Array();
var arrayDSObjects; // Array of objects of class menuItem.
this.arrayDSObjects = new Array();
}
DHTMLSuite.globalVariableStorage.prototype = {
}
/************************************************************************************************************
* A class with general methods used by most of the scripts
*
* Created: August, 19th, 2006
* Purpose of class: A class containing common method used by one or more of the gui classes below,
* example: loadCSS.
* An object("DHTMLSuite.commonObj") of this class will always be available to the other classes.
* Update log:
*
************************************************************************************************************/
/**
* @constructor
* @class A class containing common method used by one or more of the gui classes below, example: loadCSS. An object("DHTMLSuite.commonObj") of this class will always be available to the other classes.
* @version 1.0
* @author Alf Magne Kalleland(www.dhtmlgoodies.com)
**/
DHTMLSuite.common = function()
{
var loadedCSSFiles; // Array of loaded CSS files. Prevent same CSS file from being loaded twice.
var cssCacheStatus; // Css cache status
var eventElements;
this.cssCacheStatus = true; // Caching of css files = on(Default)
this.eventElements = new Array();
}
DHTMLSuite.common.prototype = {
// {{{ init()
/**
* This method initializes the DHTMLSuite_common object.
*
* @public
*/
init : function()
{
this.loadedCSSFiles = new Array();
}
// }}}
,
// {{{ loadCSS()
/**
* This method loads a CSS file(Cascading Style Sheet) dynamically - i.e. an alternative to <link> tag in the document.
*
* @param string cssFileName = New path to image files
* @public
*/
loadCSS : function(cssFileName)
{
if(!this.loadedCSSFiles[cssFileName]){
this.loadedCSSFiles[cssFileName] = true;
var linkTag = document.createElement('LINK');
if(!this.cssCacheStatus){
if(cssFileName.indexOf('?')>=0)cssFileName = cssFileName + '&'; else cssFileName = cssFileName + '?';
cssFileName = cssFileName + 'rand='+ Math.random(); // To prevent caching
}
linkTag.href = DHTMLSuite.configObj.cssPath + cssFileName;
linkTag.rel = 'stylesheet';
linkTag.media = 'screen';
linkTag.type = 'text/css';
document.getElementsByTagName('HEAD')[0].appendChild(linkTag);
}
}
// }}}
,
// {{{ getTopPos()
/**
* This method will return the top coordinate(pixel) of an object
*
* @param Object inputObj = Reference to HTML element
* @public
*/
getTopPos : function(inputObj)
{
var returnValue = inputObj.offsetTop;
while((inputObj = inputObj.offsetParent) != null){
if(inputObj.tagName!='HTML'){
returnValue += (inputObj.offsetTop - inputObj.scrollTop);
if(document.all)returnValue+=inputObj.clientTop;
}
}
return returnValue;
}
// }}}
,
// {{{ setCssCacheStatus()
/**
* Specify if css files should be cached or not.
*
* @param Boolean cssCacheStatus = true = cache on, false = cache off
*
* @public
*/
setCssCacheStatus : function(cssCacheStatus)
{
this.cssCacheStatus = cssCacheStatus;
}
// }}}
,
// {{{ getLeftPos()
/**
* This method will return the left coordinate(pixel) of an object
*
* @param Object inputObj = Reference to HTML element
* @public
*/
getLeftPos : function(inputObj)
{
var returnValue = inputObj.offsetLeft;
while((inputObj = inputObj.offsetParent) != null){
if(inputObj.tagName!='HTML'){
returnValue += inputObj.offsetLeft;
if(document.all)returnValue+=inputObj.clientLeft;
}
}
return returnValue;
}
// }}}
,
// {{{ cancelEvent()
/**
*
* This function only returns false. It is used to cancel selections and drag
*
*
* @public
*/
cancelEvent : function()
{
return false;
}
// }}}
,
// {{{ addEvent()
/**
*
* This function adds an event listener to an element on the page.
*
* @param Object whichObject = Reference to HTML element(Which object to assigne the event)
* @param String eventType = Which type of event, example "mousemove" or "mouseup"
* @param functionName = Name of function to execute.
*
* @public
*/
addEvent : function(whichObject,eventType,functionName)
{
if(whichObject.attachEvent){
whichObject['e'+eventType+functionName] = functionName;
whichObject[eventType+functionName] = function(){whichObject['e'+eventType+functionName]( window.event );}
whichObject.attachEvent( 'on'+eventType, whichObject[eventType+functionName] );
} else
whichObject.addEventListener(eventType,functionName,false);
this.__addEventEl(whichObject);
delete(whichObject);
// whichObject = null;
}
// }}}
,
// {{{ removeEvent()
/**
*
* This function removes an event listener from an element on the page.
*
* @param Object whichObject = Reference to HTML element(Which object to assigne the event)
* @param String eventType = Which type of event, example "mousemove" or "mouseup"
* @param functionName = Name of function to execute.
*
* @public
*/
removeEvent : function(whichObject,eventType,functionName)
{
if(whichObject.detachEvent){
whichObject.detachEvent('on'+eventType, whichObject[eventType+functionName]);
whichObject[eventType+functionName] = null;
} else
whichObject.removeEventListener(eventType,functionName,false);
}
,
// {{{ __clearGarbage()
/**
*
* This function is used for Internet Explorer in order to clear memory when the page unloads.
*
*
* @private
*/
__clearGarbage : function()
{
/* Example of event which causes memory leakage in IE
DHTMLSuite.commonObj.addEvent(expandRef,"click",function(){ window.refToMyMenuBar[index].__changeMenuBarState(this); })
We got a circular reference.
*/
if(!DHTMLSuite.clientInfoObj.isMSIE)return;
for(var no in DHTMLSuite.variableStorage.arrayDSObjects){
DHTMLSuite.variableStorage.arrayDSObjects[no] = false;
}
for(var no=0;no<DHTMLSuite.eventElements.length;no++){
DHTMLSuite.eventElements[no].onclick = null;
DHTMLSuite.eventElements[no].onmousedown = null;
DHTMLSuite.eventElements[no].onmousemove = null;
DHTMLSuite.eventElements[no].onmouseout = null;
DHTMLSuite.eventElements[no].onmouseover = null;
DHTMLSuite.eventElements[no].onmouseup = null;
DHTMLSuite.eventElements[no].onfocus = null;
DHTMLSuite.eventElements[no].onblur = null;
DHTMLSuite.eventElements[no].onkeydown = null;
DHTMLSuite.eventElements[no].onkeypress = null;
DHTMLSuite.eventElements[no].onkeyup = null;
DHTMLSuite.eventElements[no].onselectstart = null;
DHTMLSuite.eventElements[no].ondragstart = null;
DHTMLSuite.eventElements[no].oncontextmenu = null;
DHTMLSuite.eventElements[no].onscroll = null;
}
window.onunload = null;
DHTMLSuite = null;
}
,
// {{{ __addEventEl()
/**
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -