www.gusucode.com > 掌柜网店购物系统 4.0码程序 > admin/utils.js

    function getElementsByClassName(className,tagNames,oParent) {
  // grab elements by class, restricting search to certain tags or a parent element
  var doc = (oParent||document);
  var matches = [];
  var i,j;
  var nodes = [];
  if (tagNames && typeof(tagNames)!='string' && typeof(tagNames)!='undefined') {
    for (i=0; i<tagNames.length; i++) {
      if (!nodes || !nodes[tagNames[i]]) {
        nodes[tagNames[i]] = doc.getElementsByTagName(tagNames[i]);
      }
    }
  } else if (tagNames) {
    nodes = doc.getElementsByTagName(tagNames);
  } else {
    nodes = doc.all||doc.getElementsByTagName('*');
  }
  if (typeof(tagNames)!='string' && typeof(tagNames)!='undefined') {
    for (i=0; i<tagNames.length; i++) {
      for (j=0; j<nodes[tagNames[i]].length; j++) {
        if (nodes[tagNames[i]][j].className && nodes[tagNames[i]][j].className.indexOf(className)+1 && (nodes[tagNames[i]][j].className == className || nodes[tagNames[i]][j].className.indexOf(className+' ')+1 || nodes[tagNames[i]][j].className.indexOf(' '+className)+1)) {
          matches[matches.length] = nodes[tagNames[i]][j];
        }
      }
    }
  } else {
    for (i=0; i<nodes.length; i++) {
      if (nodes[i].className && nodes[i].className.indexOf(className)+1 && (nodes[i].className == className || nodes[i].className.indexOf(className+' ')+1 || nodes[i].className.indexOf(' '+className)+1)) {
        matches[matches.length] = nodes[i];
      }
    }
  }
  return matches; // kids, don't play with fire. ;)
}

function BrowserDetect() {
  // Browser Detect  v2.1.6
  // documentation: http://www.dithered.com/javascript/browser_detect/index.html
  // license: http://creativecommons.org/licenses/by/1.0/
  // code by Chris Nott (chris[at]dithered[dot]com)
  var ua = navigator.userAgent.toLowerCase();

  // browser engine name
  this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
  this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

  // browser name
  this.isKonqueror   = (ua.indexOf('konqueror') != -1);
  this.isSafari      = (ua.indexOf('safari') != - 1);
  this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
  this.isOpera       = (ua.indexOf('opera') != -1);
  this.isIcab        = (ua.indexOf('icab') != -1);
  this.isAol         = (ua.indexOf('aol') != -1);
  this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) );
  this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
  this.isFirebird    = (ua.indexOf('firebird/') != -1);
  this.isFirefox     = (ua.indexOf('firefox/') != -1); // scotts
  this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );

  // spoofing and compatible browsers
  this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
  this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);

  // rendering engine versions
  this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
  this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
  this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );

  // browser version
  this.versionMinor = parseFloat(navigator.appVersion);

  // correct version number
  if (this.isGecko && !this.isMozilla) {
    this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
  } else if (this.isMozilla) {
    this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
  } else if (this.isIE && this.versionMinor >= 4) {
    this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
  } else if (this.isKonqueror) {
    this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
  } else if (this.isSafari) {
    this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
  } else if (this.isOmniweb) {
    this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
  } else if (this.isOpera) {
    this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
  } else if (this.isIcab) {
    this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
  }

  this.versionMajor = parseInt(this.versionMinor);
  // dom support
  this.isDOM1 = (document.getElementById);
  this.isDOM2Event = (document.addEventListener && document.removeEventListener);

  // css compatibility mode
  this.mode = document.compatMode ? document.compatMode : 'BackCompat';

  // platform
  this.isWin    = (ua.indexOf('win') != -1);
  this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
  this.isMac    = (ua.indexOf('mac') != -1);
  this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
  this.isLinux  = (ua.indexOf('linux') != -1);

  // specific browser shortcuts
  this.isNS4x = (this.isNS && this.versionMajor == 4);
  this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
  this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
  this.isNS4up = (this.isNS && this.versionMinor >= 4);
  this.isNS6x = (this.isNS && this.versionMajor == 6);
  this.isNS6up = (this.isNS && this.versionMajor >= 6);
  this.isNS7x = (this.isNS && this.versionMajor == 7);
  this.isNS7up = (this.isNS && this.versionMajor >= 7);

  this.isIE4x = (this.isIE && this.versionMajor == 4);
  this.isIE4up = (this.isIE && this.versionMajor >= 4);
  this.isIE5x = (this.isIE && this.versionMajor == 5);
  this.isIE55 = (this.isIE && this.versionMinor == 5.5);
  this.isIE5up = (this.isIE && this.versionMajor >= 5);
  this.isIE6x = (this.isIE && this.versionMajor == 6);
  this.isIE6up = (this.isIE && this.versionMajor >= 6);
  this.isIE4xMac = (this.isIE4x && this.isMac);
}

var ua = new BrowserDetect();

function setCookie(name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + value +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function getCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
      endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function deleteCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 07:06:00 GMT";
  }
}

function pop(url,width,height,params) {
  var newWin = window.open(url,"newwin","width="+width+",height="+height+","+params);
}

function TextControl() {
  this.size = null;
  this.scaleValues = ['0.76em','0.9em','1.1em'];
  this.scaleDefault = this.scaleValues[0];
  this.cookieName = 'textsize'; // cookie name reference
  this.cookieExpire = new Date(new Date().getTime()+(365*24*60*60*1000)); // 1 year

  this.init = function() {
    // assign default size, if cookied
    if (!isNaN(parseInt(getCookie(this.cookieName)))) this.setTextSize(getCookie(this.cookieName),true);
  }

  this.setTextSize = function(sizeIndex,avoidCookie) {
    if (document.body) document.body.style.fontSize = (typeof(sizeIndex)!='undefined' && sizeIndex<this.scaleValues.length)?this.scaleValues[sizeIndex]:this.scaleDefault;
    if (!avoidCookie) setCookie(this.cookieName,sizeIndex,this.cookieExpire,'/','criticalmass.com',null);
    return false;
  }

}

var textControl = new TextControl();

function NewsFilter(){

    this.divs = document.getElementsByTagName("DIV");
    this.index = 0;
    this.items = [];
    this.years = document.getElementById('year-filter').getElementsByTagName('a');

    for (i=0;i<this.divs.length;i++) {
        if(this.divs[i].className && this.divs[i].className=="news-by-year") {
            this.items[this.items.length] = this.divs[i];
        }
    }

    this.applyFilter = function(index) {
        var scroll = true;
        if (index=='init') {
            scroll = false;
            index = 0;
        }
        if (this.items[this.index]) {
          this.items[this.index].style.display = 'none';
        }
        if (this.items[index]) {
          this.items[index].style.display='block';
        }
        if (this.years[this.index+1]) {
          this.years[this.index+1].className = '';
        }
        this.index = index;
        if (this.years[this.index+1]) {
          this.years[this.index+1].className = 'active';
        }
        if (scroll) {
          //window.location.href = '#news';
        }
        return false;
    }

}


function vidObject(mediaType,size,filename,path) {
    this.mediaType=mediaType;
    this.size=size;
    this.filename=filename;
    this.path="../../../../../.."+path; // may need to be absolute?
    this.objectTag="";
    this.init = function(){
      switch(this.mediaType) {
          case('wmv'):
           this.objectTag+='<object id="wmplayer" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="'+this.size+'" height="320">\n';
           this.objectTag+=' <param name="uiMode" value="full" />\n';
           this.objectTag+=' <param name="autoStart" value="true" />\n';
           this.objectTag+=' <param name="URL" value="'+this.path+this.filename+'_'+this.size+'.'+this.mediaType+'" />\n'
           this.objectTag+=' <param name="bgcolor" value="#F0ECE7" />\n';
           this.objectTag+=' <embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" width="'+this.size+'" height="320" src="'+this.path+this.filename+'_'+this.size+'.'+this.mediaType+'" filename="'+this.path+this.filename+'_'+this.size+'.'+this.mediaType+'" bgcolor="#F0ECE7" autostart="True" showcontrols="True" showstatusbar="True" showdisplay="True" autorewind="True">\n';
           // this.objectTag+=' <div style="font-size:x-small">Your browser does not support the ActiveX Windows Media Player.<br /><div style="text-align:left"><<a href="javascript:window.history.go(-1)">go back</a></div></div>\n';
           this.objectTag+=' </embed>';
           this.objectTag+='</object>';
          break;
          case('mov'):
          this.objectTag+='<object classid="clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b" width="'+this.size+'" height="320" codebase="http://www.apple.com/qtactivex/qtplugin.cab">\n';
          this.objectTag+='<param name="src" value="%27+this.path+this.filename+%27_%27+this.size+%27.%27+this.mediaType+%27">\n';
          this.objectTag+='<param name="autoplay" value="true">\n';
          this.objectTag+='<param name="controller" value="true">\n';
          this.objectTag+='<param name="bgcolor" value="#F0ECE7">\n';
          this.objectTag+='<embed src="%27+this.path+this.filename+%27_%27+this.size+%27.%27+this.mediaType+%27" width="'+this.size+'" height="320" autoplay="true" bgcolor="#F0ECE7" controller="true" pluginspage="http://www.apple.com/quicktime/download/"></embed>\n';
          this.objectTag+='</object>';
          break;
        }
    }

    this.renderObject = function() {
        return(this.objectTag);
    }
}