⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spmenu.js

📁 一种Portal的实现源码
💻 JS
📖 第 1 页 / 共 4 页
字号:
function spm_getMenuClickAction(oNode)
{
  //'function to determine if menu item has action associated (URL)
  if (spm_getAttr(oNode, "runat", '').length)
    return "__doPostBack(this._m_sNSpace, '" + spm_getAttr(oNode, "id", "") + "');";
  if (spm_getAttr(oNode, "server", '').length)
    return "__doPostBack(this._m_sNSpace, '" + spm_getAttr(oNode, "id", "") + "');";

  var sURL = spm_getAttr(oNode, "url", "");
  if (sURL.length)
	{
		if (sURL.toLowerCase().substr(0, "javascript:".length) == "javascript:")
			return sURL.substr("javascript:".length) + ";";
		else
			return "document.location.href='" + sURL + "';"
	}
	return '';
	
}

function spm_getMenuSpacingImage(sPos, me)
{
  var sAlign = me.menuAlignment;

  if ((sPos == 'left' && sAlign == 'Right') || (sPos == 'right' && sAlign == 'Left'))
		return "       <td width=\"100%\">" + spm_getSpacer(me) + "</td>";

  if ((sPos == 'right' && sAlign == 'Left') || (sPos == 'left' && sAlign == 'Right'))
		return "       <td width=\"3px\">" + spm_getSpacer(me) + "</td>";

	if (sAlign == 'Center')
		return "       <td width=\"33%\">" + spm_getSpacer(me) + "</td>";
	
	return '';   
}

function spm_getSpacer(me) 
{
  return spm_getMenuImage('spacer.gif', me, false);
    //return '&nbsp;'; //"<IMG SRC=\"" + me.systemImagesPath + "spacer.gif\">";
}

function spm_getImage(oAttr, me)
{
  //'retrieves an image for a passed in XMLAttribute
  var sImage = spm_getAttr(oAttr, 'image', '');

  if (sImage.length)
  {
    return spm_getHTMLImage(sImage, spm_getAttr(oAttr, 'imagepath', me.iconImagesPath));
  }
  else
    return spm_getMenuImage('spacer.gif', me);
}

function spm_getItemHTML(oNode, sSide, sDef)
{
  if (sDef == null) sDef = '';
  return spm_getAttr(oNode, sSide + "html", sDef);
}

function spm_getMenuImage(sImage, me, bForce)
{
    //'generates html for image using the SystemImagesPath property
    return spm_getHTMLImage(sImage, me.systemImagesPath, bForce);
}

function spm_getHTMLImage(sImage, sPath, bForce)
{
    //'generates html for image using the SystemImagesPath property
    if (spm_browserNeedsSpacer() == false && sImage == 'spacer.gif' && bForce == null)
        return '&nbsp;'; 
    else
        return "<IMG SRC=\"" + sPath + sImage + "\" ALT=\"" + sImage + "\">";
}

function spm_browserNeedsSpacer()
{
  return true;
}

function MyIIf(bFlag, sTrue, sFalse) 
{
    if (bFlag)
		return sTrue;
	else
		return sFalse;
}

function spm_getArrow(sImg, me) 
{
  //FIX
    if (sImg.length)
        return spm_getMenuImage(sImg, me);
    else
        return "4"; //'defaults to using wingdings font (4 = arrow)
    
}

function spm_getMenuBorderStyle(me, shColor, hlColor, width)
{
  if (shColor == null) shColor = me.shColor;
  if (hlColor == null) hlColor = me.hlColor;
  if (width == null) width = me.borderWidth;
  
  //border-bottom: Gray 1px solid; border-left: White 1px solid; border-top: White 1px solid; border-right: Gray 1px solid;
  //return 'border-bottom: ' + shColor + ' ' + width + 'px solid; border-left: ' + hlColor + ' ' + width + 'px solid;  border-top: ' + hlColor + ' ' + width + 'px solid; border-right: ' + shColor + ' ' + width + 'px solid;';
  return getBorderStyle('border-bottom', shColor, width) + getBorderStyle('border-left', hlColor, width) + getBorderStyle('border-top', hlColor, width) + getBorderStyle('border-right', shColor, width);
}

function getBorderStyle(type, color, width)
{  
  return type + ': ' + color + ' ' + width + 'px solid; ';
}



//------------------------//
String.prototype.ltrim = function () { return this.replace(/^\s*/, "");}
String.prototype.rtrim = function () { return this.replace(/\s*$/, "");}
String.prototype.trim  = function () { return this.ltrim().rtrim(); }

if (spm_browserType() != 'ie')
{
  Document.prototype.loadXML = function (s) 
    {
    
      // parse the string to a new doc
      var doc2 = (new DOMParser()).parseFromString(s, "text/xml");

      // remove all initial children
      while (this.hasChildNodes())
      this.removeChild(this.lastChild);

      // insert and import nodes
      for (var i = 0; i < doc2.childNodes.length; i++) 
      {
      this.appendChild(this.importNode(doc2.childNodes[i], true));
      }
    }

    function _Node_getXML() 
    {
      //create a new XMLSerializer
      var objXMLSerializer = new XMLSerializer;
      
      //get the XML string
      var strXML = objXMLSerializer.serializeToString(this);
      
      //return the XML string
      return strXML;
    }
    Node.prototype.__defineGetter__("xml", _Node_getXML);
}

function spm_createDOMDoc()
{
	if (spm_browserType() == 'ie')
	{
		var o = new ActiveXObject('MSXML.DOMDocument');
		o.async = false;
		return o;
	}
	else
		return document.implementation.createDocument("", "", null);
}

function spm_getById(sID)
{
  if (document.all == null)
    return document.getElementById(sID);
  else
    return document.all(sID);
}

function spm_getTags(sTag, oCtl)
{
	if (oCtl == null)
		oCtl = document;
	
	if (spm_browserType() == 'ie')
    return oCtl.all.tags(sTag);
  else
    return oCtl.getElementsByTagName(sTag);
}

function spm_browserType()
{
  var agt=navigator.userAgent.toLowerCase();

  if (agt.indexOf('netscape') != -1) 
    return 'ns'
  if (agt.indexOf('msie') != -1)
    return 'ie';
  
  return 'mo';  
}

function isMac()
{
//return true;
  var agt=navigator.userAgent.toLowerCase();
  if (agt.indexOf('mac') != -1) 
    return true;
  else
    return false;
  
}

function isOpera()
{
//return true;
  var agt=navigator.userAgent.toLowerCase();
  if (agt.indexOf('opera') != -1) 
    return true;
  else
    return false;
  
}

//taken from http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&threadm=b42qj3%24r8s1%40ripley.netscape.com&rnum=1&prev=/groups%3Fq%3Dmozilla%2B%2522currentstyle%2522%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26safe%3Doff%26scoring%3Dd 
function spm_getCurrentStyle(el, property) {
  if (document.defaultView) 
  {
    // Get computed style information:
    if (el.nodeType != el.ELEMENT_NODE) return null;
    return document.defaultView.getComputedStyle(el,'').getPropertyValue(property.split('-').join(''));
  }
  if (el.currentStyle) 
  {
    // Get el.currentStyle property value:
    return el.currentStyle[property.split('-').join('')];
    //return el.currentStyle.getAttribute(property.split('-').join(''));  //We need to get rid of slashes
  }
  if (el.style) 
  {
    // Get el.style property value:
    return el.style.getAttribute(property.split('-').join(''));  // We need to get rid of slashes
  } return  null;
}

function spm_getAttr(o, sAttr, sDef)
{
  if (sDef == null)
    sDef = '';
  var s = o.getAttribute(sAttr);
  if (s != null && s.length > 0)
    return o.getAttribute(sAttr);
  else
    return sDef;
}

function spm_setAttr(o, sAttr, sVal)
{
	if (sVal.length > 0)
		o.setAttribute(sAttr, sVal);
	else
		o.removeAttribute(sAttr);
}


function spm_fixUnit(s)
{
  if (s.length && isNaN(s) == false)
    return s + 'px';

}

function spm_nodeHasChildren(node)
{
  if (typeof(node.selectSingleNode) != 'undefined') //(node.selectSingleNode != null) //(spm_browserType() == 'ie')
    return node.selectSingleNode('./menuitem') != null;
  else
  {
    if (node.childNodes.length > 0)
    {
      //Netscape/Mozilla counts an empty <menuitem id></menuitem> as having a child...
      for (var i=0; i< node.childNodes.length; i++)
      {
        if (node.childNodes[i].nodeName == 'menuitem')
            return true;
      }
    }
  }
  return false;  
}

function spm_findNode(oParent, sID)
{
	for (var i = 0; i < oParent.childNodes.length; i++)
	{
		oNode = oParent.childNodes[i];

		if (oNode.nodeType != 3)  //exclude nodeType of Text (Netscape/Mozilla) issue!
		{

			if ((oNode.nodeName == "menuitem" || oNode.nodeName == "menubreak") && oNode.getAttribute("id") == sID)
				return oNode;

			if (oNode.childNodes.length > 0)
			{
				var o = spm_findNode(oNode, sID);
				if (o != null)
					return o;
			}
		}
	}
}

function spm_getSibling(oNode, iOffset)
{
	var sID = spm_getAttr(oNode, 'id');
	var o;
	for (var i=0; i<oNode.parentNode.childNodes.length; i++)
	{
		o = oNode.parentNode.childNodes[i];
		if (o.nodeType != 3)
		{
			if (spm_getAttr(o, 'id') == sID)
				return getOffsetNode(o.parentNode, i, iOffset);
		}
	}
}

function spm_stopEventBubbling(e)
{
    if (spm_browserType() == 'ie')
			window.event.cancelBubble = true;
		else
			e.stopPropagation();
}

//--- if you have a better solution send me an email - jhenning@solpart.com ---//
function spm_appendFunction(from_func, to_func)
{
  if (from_func == null)
    return new Function ( to_func ); 
  return new Function ( spm_parseFunctionContents(from_func) + '\n' + spm_parseFunctionContents(to_func) );
}
function spm_parseFunctionContents(fnc)
{
  var s =String(fnc).trim();
  if (s.indexOf('{') > -1)
		s = s.substring(s.indexOf('{') + 1, s.length - 1);
  return s;
}




//--- For JS DOM ---//
function SPJSXMLNode(sNodeName, sID, oParent, sTitle, sURL, sImage, sImagePath, sRightHTML, sLeftHTML, sRunAtServer, sItemStyle, sImageStyle) 
{ 
  this.nodeName = sNodeName;
  this.id=sID;
  this.childNodes = new Array();
  //this.nodeType = 3;
  
  
  this.parentNode = oParent;            
  if (oParent != null)
  {
    oParent.childNodes[oParent.childNodes.length] = this;
    
    if (oParent.documentElement == null)
      this.documentElement = oParent;
    else
      this.documentElement = oParent.documentElement;
  }
  else
    this.documentElement = this;
    
  this.title = sTitle;
  this.url = sURL;
  this.image = sImage;
  this.imagepath = sImagePath;
  this.righthtml = sRightHTML;
  this.lefthtml = sLeftHTML;
  this.server = sRunAtServer;
  this.itemstyle = sItemStyle;
  this.imagestyle = sImageStyle;
}      
SPJSXMLNode.prototype.getAttribute = function(s)
{
  return this[s];
}


  var m_iSPTimer;
  var m_iSPTotalTimer=0;
  var m_sSPDebugText;
  var m_oSPDebugCtl;
  var m_bSPDebug = false;
  
  function __db(s)
  {
    if (spm_browserType() != 'ie' || m_bSPDebug == false)
      return;
     
    var sT = new Date() - m_iSPTimer;
    if (sT > 120000)
    {
      sT = ''
      m_oSPDebugCtl.value = '---reset---';
      m_iSPTotalTimer=0;
    }
    else if (sT > 100)
    {
      m_iSPTotalTimer+= sT;
      sT = ' *** [' + sT + '] *** ';
    }
    else if (sT > 0)
    {
      m_iSPTotalTimer+= sT;
      sT = ' [' + sT + ']';
    }
    else
      sT = '';
      
    if (document.forms.length > 0 && m_oSPDebugCtl == null)
    {      
      document.forms(0).all(0).insertAdjacentHTML('afterEnd', '<TEXTAREA ID="my__Debug" STYLE="WIDTH: 100%; HEIGHT: 300px"></TEXTAREA>');
      m_oSPDebugCtl = document.all('my__Debug');
    }

    if (m_oSPDebugCtl != null)
      m_oSPDebugCtl.value += '[' + m_iSPTotalTimer + '] ' + s + sT + '\n';
    else
      m_sSPDebugText += '[' + m_iSPTotalTimer + '] ' + s + sT + '\n'; 
      
    m_iSPTimer = new Date();
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -