📄 twiki.js
字号:
/*This collection of javascript functions is deprecated.Use the new TWiki library classes instead:twikilib.jstwikiArray.jstwikiCSS.jstwikiEvent.jstwikiForm.jstwikiFunction.jstwikiHTML.jstwikiPref.jstwikiString.js, twikiStringUnicodeChars.jstwikiWindow.jsWhen converting to the new classes: some functions may have changed name or parameters.*/var POPUP_WINDOW_WIDTH = 500;var POPUP_WINDOW_HEIGHT = 480;var POPUP_ATTRIBUTES = "titlebar=0,resizable,scrollbars";var TWIKI_PREF_COOKIE_NAME = "TWIKIPREF";var COOKIE_PREF_SEPARATOR = "|"; // separates key-value pairsvar COOKIE_PREF_VALUE_SEPARATOR = "="; // separates key from valuevar COOKIE_EXPIRY_TIME = 365 * 24 * 60 * 60 * 1000; // one year from now// Constants for the browser typevar ns4 = (document.layers) ? true : false;var ie4 = (document.all) ? true : false;var dom = (document.getElementById) ? true : false;// Unicode conversion tools:// Convert text to hexadecimal Unicode escape sequence (\uXXXX)// http://www.hot-tips.co.uk/useful/unicode_converter.HTML// Convert hexadecimal Unicode escape sequence (\uXXXX) to text// http://www.hot-tips.co.uk/useful/unicode_convert_back.HTML// More international characters in unicode_chars.js// Import file when international support is needed:// <script type="text/javascript" src="%PUBURLPATH%/%TWIKIWEB%/TWikiJavascripts/unicode_chars.js"></script>// unicode_chars.js will overwrite the regexes below// Info on unicode: http://www.fileformat.info/info/unicode/var UPPER_ALPHA_CHARS = "A-Z";var LOWER_ALPHA_CHARS = "a-z";var NUMERIC_CHARS = "\\d";var MIXED_ALPHA_CHARS = UPPER_ALPHA_CHARS + LOWER_ALPHA_CHARS;var MIXED_ALPHANUM_CHARS = MIXED_ALPHA_CHARS + NUMERIC_CHARS;var LOWER_ALPHANUM_CHARS = LOWER_ALPHA_CHARS + NUMERIC_CHARS;var WIKIWORD_REGEX = "^" + "[" + UPPER_ALPHA_CHARS + "]" + "+" + "[" + LOWER_ALPHANUM_CHARS + "]" + "+" + "[" + UPPER_ALPHA_CHARS + "]" + "+" + "[" + MIXED_ALPHANUM_CHARS + "]" + "*";var ALLOWED_URL_CHARS = MIXED_ALPHANUM_CHARS + "-_^";// TWiki namespacevar TWiki = {};// Chain a new load handler onto the existing handler chain// http://simon.incutio.com/archive/2004/05/26/addLoadEvent// if prepend is true, adds the function to the head of the handler list// otherwise it will be added to the end (executed last)function addLoadEvent(func, prepend) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = function() { func(); }; } else { var prependFunc = function() { func(); oldonload(); }; var appendFunc = function() { oldonload(); func(); }; window.onload = prepend ? prependFunc : appendFunc; }}// Stubfunction initForm() {}// Launch a fixed-size help windowfunction launchTheWindow(inPath, inWeb, inTopic, inSkin, inTemplate) { var pathComps = []; if (inWeb != undefined) pathComps.push(inWeb); if (inTopic != undefined) pathComps.push(inTopic); var pathString = inPath + pathComps.join("/"); var params = []; if (inSkin != undefined && inSkin.length > 0) { params.push("skin=" + inSkin); } if (inTemplate != undefined && inTemplate.length > 0) { params.push("template=" + inTemplate); } var paramsString = params.join(";"); if (paramsString.length > 0) paramsString = "?" + paramsString; var name = (inTopic != undefined) ? inTopic : ""; var attributes = []; attributes.push("width=" + POPUP_WINDOW_WIDTH); attributes.push("height=" + POPUP_WINDOW_HEIGHT); attributes.push(POPUP_ATTRIBUTES); var attributesString = attributes.join(","); var win = open(pathString + paramsString, name, attributesString); if (win) win.focus(); return false;}/** Writes html inside container with id inId.*/function insertHtml (inHtml, inId) { var elem = document.getElementById(inId); if (elem) { elem.innerHTML = inHtml; }}// Remove the given class from an element, if it is therefunction removeClass(element, classname) { var classes = getClassList(element); if (!classes) return; var index = indexOf(classname,classes); if (index >= 0) { classes.splice(index,1); setClassList(element, classes); }}// Add the given class to the element, unless it is already therefunction addClass(element, classname) { var classes = getClassList(element); if (!classes) return; if (indexOf(classname, classes) < 0) { classes[classes.length] = classname; setClassList(element,classes); }}// Replace the given class with a different class on the element.// The new class is added even if the old class is not present.function replaceClass(element, oldclass, newclass) { removeClass(element, oldclass); addClass(element, newclass);}// Get an array of the classes on the object.function getClassList(element) { if (element.className && element.className != "") { return element.className.split(' '); } return [];}// Set the classes on an element from an array of class names// Cache the list in the 'classes' attribute on the elementfunction setClassList(element, classlist) { element.className = classlist.join(' ');}// Determine the first index of a string in an array.// Return -1 if the string is not found.// WATCH OUT: the refactored function in twiki.Array returns null with an// invalid array, but CSS class manipulation functions still rely on a // return value of -1function indexOf(inElement, inArray) { if (!inArray || inArray.length == undefined) return -1; var i, ilen = inArray.length; for (i=0; i<ilen; ++i) { if (inArray[i] == inElement) return i; } return -1; }// Applies the given function to all elements in the document of// the given tag typefunction applyToAllElements(fn, type) { var c = document.getElementsByTagName(type); for (var j = 0; j < c.length; j++) { fn(c[j]); }}// Determine if the element has the given class string somewhere in it's// className attribute.function hasClass(node, className) { if (node.className) { var classes = getClassList(node); if (classes) return (indexOf(className, classes) >= 0); return false; }}/**Checks if a string is a WikiWord.@param inValue : string to test@return True if a WikiWord, false if not.*/function isWikiWord(inValue) { var re = new RegExp(WIKIWORD_REGEX); return (inValue.match(re)) ? true : false;}/**Capitalizes words in the string. For example: "A handy dictionary" becomes "A Handy Dictionary".*/String.prototype.capitalize = function() { var re = new RegExp("[" + MIXED_ALPHANUM_CHARS + "]+", "g"); return this.replace(re, function(a) { return a.charAt(0).toLocaleUpperCase() + a.substr(1); });};/**Returns true if the string is either "on", "true" or "1"; otherwise: false.*/String.prototype.toBoolean = function() { return (this == "on") || (this == "true") || (this == "1");};/**@deprecated: Use someString.capitalize().*/function capitalize(inValue) { return inValue.capitalize();}/**Removes spaces from a string. For example: "A Handy Dictionary" becomes "AHandyDictionary".@param inValue : the string to remove spaces from@return A new space free string.*/function removeSpaces(inValue) { var sIn = inValue; var sOut = ''; for ( var i = 0; i < sIn.length; i++ ) { var ch = sIn.charAt( i ); if( ch==' ' ) { chgUpper = true; continue; } sOut += ch; } return sOut;}/**Removes punctuation characters from a string. For example: "A/Z" becomes "AZ".@param inValue : the string to remove chars from@return A new punctuation free string.*/function removePunctuation(inValue) { var allowedRegex = "[^" + ALLOWED_URL_CHARS + "]"; var re = new RegExp(allowedRegex, "g"); return inValue.replace(re, "");}/**Combines removePunctuation and removeSpaces.*/function removeSpacesAndPunctiation(inValue) { return removePunctuation(removeSpaces(inValue));}/**Creates a WikiWord from a string. For example: "A handy dictionary" becomes "AHandyDictionary".@param inValue : the string to wikiwordize@return A new WikiWord string.*/function makeWikiWord(inString) { return removeSpaces(capitalize(inString));}/**Javascript query string parsing.Author: djohnson@ibsys.com {{djohnson}} - you may use this file as you wish but please keep this header with it thanks@use Pass location.search to the constructor:<code>var myPageQuery = new PageQuery(location.search)</code>Retrieve values<code>var myValue = myPageQuery.getValue("param1")</code>*/TWiki.PageQuery = function (q) { if (q.length > 1) { this.q = q.substring(1, q.length); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -