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

📄 twiki.js

📁 8634平台开发重要参考资料
💻 JS
📖 第 1 页 / 共 2 页
字号:
		this.q = null;	}	this.keyValuePairs = new Array();	if (q) {		for(var i=0; i < this.q.split(/[&;]/).length; i++) {			this.keyValuePairs[i] = this.q.split(/[&;]/)[i];		}	}}TWiki.PageQuery.prototype.getKeyValuePairs = function() {	return this.keyValuePairs;}/**@return The query string value; if not found returns -1.*/TWiki.PageQuery.prototype.getValue = function (s) {	for(var j=0; j < this.keyValuePairs.length; j++) {		if(this.keyValuePairs[j].split(/=/)[0] == s)			return this.keyValuePairs[j].split(/=/)[1];	}	return -1;}TWiki.PageQuery.prototype.getParameters = function () {	var a = new Array(this.getLength());	for(var j=0; j < this.keyValuePairs.length; j++) {		a[j] = this.keyValuePairs[j].split(/=/)[0];	}	return a;}TWiki.PageQuery.prototype.getLength = function() {	return this.keyValuePairs.length;}// COOKIE FUNCTIONS/**Add a cookie. If 'days' is set to a non-zero number of days, sets an expiry on the cookie.@deprecated Use setPref.*/function writeCookie(name,value,days) {	var expires = "";	if (days) {		var date = new Date();		date.setTime(date.getTime()+(days*24*60*60*1000));		expires = "; expires="+date.toGMTString();	}	// cumulative	document.cookie = name + "=" + value + expires + "; path=/";}/**Reads the named cookie and returns the value.@deprecated Use getPref.*/function readCookie(name) { 	var nameEQ = name + "=";	var ca = document.cookie.split(';');	if (ca.length == 0) {		ca = document.cookie.split(';');	}	for (var i=0;i < ca.length;++i) {		var c = ca[i];		while (c.charAt(0)==' ')            c = c.substring(1,c.length);		if (c.indexOf(nameEQ) == 0)            return c.substring(nameEQ.length,c.length);	}	return null;}/**Writes a TWiki preference value. If the TWiki preference of given name already exists, a new value is written. If the preference name is new, a new preference is created.Characters '|' and '=' are reserved as separators.@param inPrefName (String): name of the preference to write, for instance 'SHOWATTACHMENTS'@param inPrefValue (String): value to write, for instance '1'*/function setPref(inPrefName, inPrefValue) {	var prefName = _getSafeString(inPrefName);	var prefValue = (isNaN(inPrefValue)) ? _getSafeString(inPrefValue) : inPrefValue;	var cookieString = _getPrefCookie();	var prefs = cookieString.split(COOKIE_PREF_SEPARATOR);	var index = _getKeyValueLoc(prefs, prefName);	if (index != -1) {		// updating this entry is done by removing the existing entry from the array and then pushing the new key-value onto it		prefs.splice(index, 1);	}	// else not found, so don't remove an existing entry	var keyvalueString = prefName + COOKIE_PREF_VALUE_SEPARATOR + prefValue;	prefs.push(keyvalueString);	_writePrefValues(prefs);}/**Reads the value of a preference.Characters '|' and '=' are reserved as separators.@param inPrefName (String): name of the preference to read, for instance 'SHOWATTACHMENTS'@return The value of the preference; an empty string when no value is found.*/function getPref(inPrefName) {	var prefName = _getSafeString(inPrefName);	return getPrefValueFromPrefList(prefName, getPrefList());}/**Reads the value of a preference from an array of key-value pairs. Use in conjunction with getPrefList() when you want to store the key-value pairs for successive look-ups.@param inPrefName (String): name of the preference to read, for instance 'SHOWATTACHMENTS'@param inPrefList (Array): list of key-value pairs, retrieved with getPrefList()@return The value of the preference; an empty string when no value is found.*/function getPrefValueFromPrefList (inPrefName, inPrefList) {	var keyvalue = _getKeyValue(inPrefList, inPrefName);	if (keyvalue != null) return keyvalue[1];	return '';}/**@return The array of key-value pairs.*/function getPrefList () {	var cookieString = _getPrefCookie();	if (!cookieString) return null;	return cookieString.split(COOKIE_PREF_SEPARATOR);}/**Finds a key-value pair in an array.@param inKeyValues: (Array) the array to iterate@param inKey: (String) the key to find in the array@return The first occurrence of a key-value pair, where key == inKey; null if none is found.*/function _getKeyValue (inKeyValues, inKey) {	if (!inKeyValues) return null;	var i = inKeyValues.length;	while (i--) {		var keyvalue = inKeyValues[i].split(COOKIE_PREF_VALUE_SEPARATOR);		if (keyvalue[0] == inKey) return keyvalue;		}	return null;}/**Finds the location of a key-value pair in an array.@param inKeyValues: (Array) the array to iterate@param inKey: (String) the key to find in the array@return The location of the first occurrence of a key-value tuple, where key == inKey; -1 if none is found.*/function _getKeyValueLoc (inKeyValues, inKey) {	if (!inKeyValues) return null;	var i = inKeyValues.length;	while (i--) {		var keyvalue = inKeyValues[i].split(COOKIE_PREF_VALUE_SEPARATOR);		if (keyvalue[0] == inKey) return i;		}	return -1;}/**Writes a cookie with the stringified array values of inValues.@param inValues: (Array) an array with key-value tuples*/function _writePrefValues (inValues) {	var cookieString = (inValues != null) ? inValues.join(COOKIE_PREF_SEPARATOR) : '';	var expiryDate = new Date ();	FixCookieDate (expiryDate); // Correct for Mac date bug - call only once for given Date object!	expiryDate.setTime (expiryDate.getTime() + COOKIE_EXPIRY_TIME);	SetCookie(TWIKI_PREF_COOKIE_NAME, cookieString, expiryDate, '/');}/**Gets the TWiki pref cookie; creates a new cookie if it does not exist.@return The TWiki pref cookie.*/function _getPrefCookie () {	var cookieString = GetCookie(TWIKI_PREF_COOKIE_NAME);	if (cookieString == undefined) {		cookieString = "";	}	return cookieString;}/**Strips reserved characters '|' and '=' from the input string.@return The stripped string.*/function _getSafeString (inString) {	var regex = new RegExp(/[|=]/);	return inString.replace(regex, "");}////  Cookie Functions -- "Night of the Living Cookie" Version (25-Jul-96)////  Written by:  Bill Dortch, hIdaho Design <bdortch@hidaho.com>//  The following functions are released to the public domain.////// "Internal" function to return the decoded value of a cookie//function getCookieVal (offset) {  var endstr = document.cookie.indexOf (";", offset);  if (endstr == -1)    endstr = document.cookie.length;  return unescape(document.cookie.substring(offset, endstr));}////  Function to correct for 2.x Mac date bug.  Call this function to//  fix a date object prior to passing it to SetCookie.//  IMPORTANT:  This function should only be called *once* for//  any given date object!  See example at the end of this document.//function FixCookieDate (date) {  var base = new Date(0);  var skew = base.getTime(); // dawn of (Unix) time - should be 0  if (skew > 0)  // Except on the Mac - ahead of its time    date.setTime (date.getTime() - skew);}////  Function to return the value of the cookie specified by "name".//    name - String object containing the cookie name.//    returns - String object containing the cookie value, or null if//      the cookie does not exist.//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 to create or update a cookie.//    name - String object containing the cookie name.//    value - String object containing the cookie value.  May contain//      any valid string characters.//    [expires] - Date object containing the expiration data of the cookie.  If//      omitted or null, expires the cookie at the end of the current session.//    [path] - String object indicating the path for which the cookie is valid.//      If omitted or null, uses the path of the calling document.//    [domain] - String object indicating the domain for which the cookie is//      valid.  If omitted or null, uses the domain of the calling document.//    [secure] - Boolean (true/false) value indicating whether cookie transmission//      requires a secure channel (HTTPS).  ////  The first two parameters are required.  The others, if supplied, must//  be passed in the order listed above.  To omit an unused optional field,//  use null as a place holder.  For example, to call SetCookie using name,//  value and path, you would code:////      SetCookie ("myCookieName", "myCookieValue", null, "/");////  Note that trailing omitted parameters do not require a placeholder.////  To set a secure cookie for path "/myPath", that expires after the//  current session, you might code:////      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);//function SetCookie (name,value,expires,path,domain,secure) {  var cookieString = name + "=" + escape (value) +    ((expires) ? "; expires=" + expires.toGMTString() : "") +    ((path) ? "; path=" + path : "") +    ((domain) ? "; domain=" + domain : "") +    ((secure) ? "; secure" : "");    document.cookie = cookieString;}//  Function to delete a cookie. (Sets expiration date to start of epoch)//    name -   String object containing the cookie name//    path -   String object containing the path of the cookie to delete. This MUST//             be the same as the path used to create the cookie, or null/omitted if//             no path was specified when creating the cookie.//    domain - String object containing the domain of the cookie to delete.  This MUST//             be the same as the domain used to create the cookie, or null/omitted if//             no domain was specified when creating the cookie.//function DeleteCookie (name,path,domain) {	if (GetCookie(name)) {		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";	}}

⌨️ 快捷键说明

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