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

📄 pjpc.js

📁 Punjab is a jabber XMLRPC/SOAP/REST client. It is a xmlrpc, soap, or REST server that allows for p
💻 JS
字号:
/*
 * Punjab JavaScript functions 
 */


function set_hideoffline(val)
{
     set_cookie('punjab_hideoffline',val);
}

function get_hideoffline(val)
{
  return get_cookie('punjab_hideoffline');
}

function set_session(sid) {
    set_cookie('punjab_sid',sid);
}

function get_session() {
   return get_cookie('punjab_sid');
}

function is_logged_in() {
       var session = get_session();
       if ((session!=null)&&(session.length)>3) {
          return true;
       }
       return false;
}


function punjab_login(jid,pass,port,login_cb) {       
        if (jid && pass && port) {
           postURL('/login.js?event=login','jid='+jid+'&pass='+pass+'&port='+port,login_cb,'application/x-www-form-urlencoded',null);
        } else {
          alert('You need to provide a username and password');
        }
}

function punjab_logout(logout_cb) {
  postURL('/logout.js?event=logout&sid='+get_session(),'sid='+get_session(),logout_cb,'application/x-www-form-urlencoded',null);
}

function get_presence(cb,to,from) {
   getURL('/presence.js?event=presence&to='+escape(to)+'&sid='+get_session(),cb);
}

function get_presence_stream(cb,to,from) {
   var query_string = '?event=presence&sid='+get_session()+'';
   if (to != null) {
      query_string = query_string + '&to='+to;
   }
   if (from != null) {
      query_string = query_string + '&from='+from;
   }

   getURL('/presence.js'+query_string,cb);
}

function get_message(cb,to,from) {
   var query_string = '?event=message&sid='+get_session();
   if (to != null) {
      query_string = query_string + '&to='+to; 
   }
   if (from != null) {
      query_string = query_string + '&from='+from; 
   }
   getURL('/message.js'+query_string,cb);
}

function get_message_stream(cb,to,from,check) {
   var query_string = '?event=message&sid='+get_session()+'';
   if (to != null) {
      query_string = query_string + '&to='+to; 
   }
   if (from != null) {
      query_string = query_string + '&from='+from; 
   }
   if (check != null) {
      query_string = query_string + '&check=1'; 
   }
   	  
   getURL('/message.js'+query_string,cb);
}

function send_presence(cb,from,to,status,show,type) {
   var post_string = 'event=presence';
   if (status != null) {
      post_string = post_string + '&status='+status;
   }
   if (show != null) {
      post_string = post_string + '&show='+show;
   }
   if (type != null) {
      post_string = post_string + '&type='+type;
   }	 
   postURL('/presence.js?event=presence&sid='+get_session(),post_string,cb,'application/x-www-form-urlencoded',null);
}

function get_roster(cb) {
   getURL('/roster.js?event=roster&sid='+get_session(),cb);
}


function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = /  /g;
   while (temp.match(obj)) { temp = temp.replace(obj, " "); }
   var at = /@/;
   while (temp.match(at)) { temp = temp.replace(at, "_"); }
   var period = /\./;
   while (temp.match(period)) { temp = temp.replace(period, "_"); }

   return temp;
}



/* *** *** *** *** *** *** *** *** ***
 * this code is taken from http://webfx.eae.net/dhtml/xmlextras/xmlextras.html 
 * *** *** *** *** *** *** *** *** ***
 */

//<script>

// used to find the Automation server name
function getDomDocumentPrefix() {
	if (getDomDocumentPrefix.prefix)
		return getDomDocumentPrefix.prefix;
	
	var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
	var o;
	for (var i = 0; i < prefixes.length; i++) {
		try {
			// try to create the objects
			o = new ActiveXObject(prefixes[i] + ".DomDocument");
			return getDomDocumentPrefix.prefix = prefixes[i];
		}
		catch (ex) {};
	}
	
	throw new Error("Could not find an installed XML parser");
}

// XmlDocument factory
function XmlDocument() {}

XmlDocument.create = function () {
	try {
		// DOM2
		if (document.implementation && document.implementation.createDocument) {
			var doc = document.implementation.createDocument("", "", null);
			
			// some versions of Moz do not support the readyState property
			// and the onreadystate event so we patch it!
			if (doc.readyState == null) {
				doc.readyState = 1;
				doc.addEventListener("load", function () {
					doc.readyState = 4;
					if (typeof doc.onreadystatechange == "function")
						doc.onreadystatechange();
				}, false);
			}
			
			return doc;
		}
		if (window.ActiveXObject)
			return new ActiveXObject(getDomDocumentPrefix() + ".DomDocument");
	}
	catch (ex) {}
	throw new Error("Your browser does not support XmlDocument objects");
};

// Create the loadXML method and xml getter for Mozilla
if (window.DOMParser &&
	window.XMLSerializer &&
	window.Node && Node.prototype && Node.prototype.__defineGetter__) {

	// XMLDocument did not extend the Document interface in some versions
	// of Mozilla. Extend both!
	//XMLDocument.prototype.loadXML = 
	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));
		}
	};
	
	
	/*
	 * xml getter
	 *
	 * This serializes the DOM tree to an XML String
	 *
	 * Usage: var sXml = oNode.xml
	 *
	 */
	// XMLDocument did not extend the Document interface in some versions
	// of Mozilla. Extend both!
// 	XMLDocument.prototype.__defineGetter__("xml", function () {
// 		return (new XMLSerializer()).serializeToString(this);
// 	});
	Document.prototype.__defineGetter__("xml", function () {
		return (new XMLSerializer()).serializeToString(this);
	});

	/* doesn't work correctly in mozi */
// 	Node.prototype.__defineGetter__("xml", function () {
// 		return (new XMLSerializer()).serializeToString(this);
// 	});
}

⌨️ 快捷键说明

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