Jump to content

User:Topaz/util.js: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Topaz (talk | contribs)
+escape
Topaz (talk | contribs)
fixing stupid mistake
 
Line 17: Line 17:
return parent.appendChild(el);
return parent.appendChild(el);
},
},
escape:function(text) {
fullescape:function(text) {
return escape(text.replace(/\+/g,"%2B"));
return escape(text).replace(/\+/g,"%2B");
},
},
mousebtnmap:{
mousebtnmap:{

Latest revision as of 19:32, 28 June 2007

topaz.util = {
getobj:function(id) {
  return document.getElementById ?
             document.getElementById(id) :
             document.all[id];
},
time:function() {
  return((new Date()).getTime()/1000);
},
add:function(parent, tag, attr) {
  var el = document.createElement(tag);
  if (attr) {
    for (key in attr) {
      el[key] = attr[key];
    }
  }
  return parent.appendChild(el);
},
fullescape:function(text) {
  return escape(text).replace(/\+/g,"%2B");
},
mousebtnmap:{
  ns:[null,1,3,2],
  ie:[null,1,2,null,3]
},
xmlhttpreq:function() {
  if (window.XMLHttpRequest) {
    xmlhttpobj = new XMLHttpRequest()
  } else {
    try {
      xmlhttpobj = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttpobj = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        xmlhttpobj = null;
      }
    }
  }
  return xmlhttpobj;
},

cookie:{
  noexpire:(function(){
    var d = new Date();
    d.setTime(d.getTime()+(365*24*60*60*1000));
    return d.toGMTString();
  })(),

  expire:(function(){
    var d = new Date();
    d.setTime(d.getTime()-1);
    return d.toGMTString();
  })(),

  get:function(name) {
    var cl = document.cookie.split(/;\s*/);
    for (var i=0; i<cl.length; i++) {
      var curc = cl[i].split(/\=/);
      if (curc[0] == name) {
        return(curc[1]);
      }
    }
    return null;
  },

  set:function(name, value) {
    document.cookie = name + "=" + escape(value) +
        "; expires=" + topaz.util.cookie.noexpire +
        "; path=/";
  },

  del:function(name) {
    document.cookie = name+"=; expires="+topaz.util.coookie.expire+"; path=/";
  }
}
};