/***
|''Name:''|MathSVGPlugin|
|''Description:''|This plugin translates a subset of the LaTeX math notation to MathML with a customisable image fallback when MathML is not supported. It also provides an easy way to produce mathematical SVG graphics with dynamical features and animation.|
|''Version:''|1.2.2|
|''Date:''|2009-06-25|
|''Source:''|http://www.math.ist.utl.pt/~psoares/mathsvg.html|
|''Author:''|Paulo Soares|
|''License:''|[[GNU Lesser General Public License|http://www.gnu.org/licences/lgpl.html]]|
|''~CoreVersion:''|2.5.0|
!Original copyright notice
{{{
ASCIIMathML.js
==============
Version 2.1 Oct 8, 2008, (c) Peter Jipsen http://www.chapman.edu/~jipsen
This version extends ASCIIMathML.js with LaTeXMathML.js and ASCIIsvg.js.
Latest version at http://www.chapman.edu/~jipsen/mathml/ASCIIMathML.js
If you use it on a webpage, please send the URL to jipsen@chapman.edu
The LaTeXMathML modifications were made by Douglas Woodall, June 2006.
(for details see header on the LaTeXMathML part in middle of file)
Extensive clean-up and improvements by Paulo Soares, Oct 2007.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
(at http://www.gnu.org/licences/lgpl.html) for more details.
}}}
!~MathSVG code (minified)
***/
//{{{
Math.sec=function(a){return 1/Math.cos(a)};Math.csc=function(a){return 1/Math.sin(a)};Math.cot=function(a){return 1/Math.tan(a)};Math.asec=function(a){return Math.acos(1/a)};Math.acsc=function(a){return Math.asin(1/a)};Math.acot=function(a){return Math.atan(1/a)};Math.sinh=function(a){return(Math.exp(a)-Math.exp(-a))/2};Math.cosh=function(a){return(Math.exp(a)+Math.exp(-a))/2};Math.tanh=function(a){return(Math.exp(a)-Math.exp(-a))/(Math.exp(a)+Math.exp(-a))};Math.sech=function(a){return 1/Math.cosh(a)};Math.csch=function(a){return 1/Math.sinh(a)};Math.coth=function(a){return 1/Math.tanh(a)};Math.asinh=function(a){return Math.log(a+Math.sqrt(a*a+1))};Math.acosh=function(a){return Math.log(a+Math.sqrt(a*a-1))};Math.atanh=function(a){return Math.log((1+a)/(1-a))/2};Math.sech=function(a){return 1/Math.cosh(a)};Math.csch=function(a){return 1/Math.sinh(a)};Math.coth=function(a){return 1/Math.tanh(a)};Math.asech=function(a){return Math.acosh(1/a)};Math.acsch=function(a){return Math.asinh(1/a)};Math.acoth=function(a){return Math.atanh(1/a)};Math.sign=function(a){return(a===0?0:(a<0?-1:1))};Math.step=function(a,c,b){return(a<0?(b?b:0):(c?c:1))};Math.root=function(a,b){return Math.pow(a,1/b)};Math.factorial=function(b){if(b===0){return 1}if(b<0){if((b%1)===0){return}if(b>-1){return Math.factorial(b+1)/(b+1)}return -Math.PI/(Math.factorial(-1-b)*Math.sin(Math.PI*b))}var a=b;if((b%1)===0){while(b>1){b=b-1;a=a*b}}else{a=Math.exp((b+0.5)*Math.log(b+1)-b-b*(0.1121105+b*0.08106103)/(1.452342+b*(2.410858+b)))}return a};Math.Gamma=function(a){return Math.factorial(a-1)};Math.Beta=function(a,b){return Math.Gamma(a)*Math.Gamma(b)/Math.Gamma(a+b)};Math.C=function(a,b){var c=1/((a+1)*Math.Beta(b+1,a-b+1));return c};Math.truncate=function(a,c){var b=c||0;return Math.floor(a*Math.pow(10,b))/Math.pow(10,b)};Math.randomString=function(a,g){var f=(g||"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz").split("");var e=[],c=Math.random;var d=f.length;for(var b=0;b<a;b++){e[b]=f[0|c()*d]}return e.join("")};Math.runif=function(d,c,f){var e=f||0;return Math.truncate((c+Math.pow(10,-e)-d)*Math.random()+d,e)};Math.rnormal=function(a,b){a=a||0;b=b||1;var d=0,c=0;while(d*c===0){d=Math.random();c=Math.random()}return b*(Math.sqrt(-2*Math.log(d))*Math.cos(2*Math.PI*c))+a};var MSVG=function(j){var s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";var q=["\uD835\uDC9C","\u212C","\uD835\uDC9E","\uD835\uDC9F","\u2130","\u2131","\uD835\uDCA2","\u210B","\u2110","\uD835\uDCA5","\uD835\uDCA6","\u2112","\u2133","\uD835\uDCA9","\uD835\uDCAA","\uD835\uDCAB","\uD835\uDCAC","\u211B","\uD835\uDCAE","\uD835\uDCAF","\uD835\uDCB0","\uD835\uDCB1","\uD835\uDCB2","\uD835\uDCB3","\uD835\uDCB4","\uD835\uDCB5","\uD835\uDCB6","\uD835\uDCB7","\uD835\uDCB8","\uD835\uDCB9","\u212F","\uD835\uDCBB","\u210A","\uD835\uDCBD","\uD835\uDCBE","\uD835\uDCBF","\uD835\uDCC0","\uD835\uDCC1","\uD835\uDCC2","\uD835\uDCC3","\u2134","\uD835\uDCC5","\uD835\uDCC6","\uD835\uDCC7","\uD835\uDCC8","\uD835\uDCC9","\uD835\uDCCA","\uD835\uDCCB","\uD835\uDCCC","\uD835\uDCCD","\uD835\uDCCE","\uD835\uDCCF"];var B=["\uD835\uDD04","\uD835\uDD05","\u212D","\uD835\uDD07","\uD835\uDD08","\uD835\uDD09","\uD835\uDD0A","\u210C","\u2111","\uD835\uDD0D","\uD835\uDD0E","\uD835\uDD0F","\uD835\uDD10","\uD835\uDD11","\uD835\uDD12","\uD835\uDD13","\uD835\uDD14","\u211C","\uD835\uDD16","\uD835\uDD17","\uD835\uDD18","\uD835\uDD19","\uD835\uDD1A","\uD835\uDD1B","\uD835\uDD1C","\u2128","\uD835\uDD1E","\uD835\uDD1F","\uD835\uDD20","\uD835\uDD21","\uD835\uDD22","\uD835\uDD23","\uD835\uDD24","\uD835\uDD25","\uD835\uDD26","\uD835\uDD27","\uD835\uDD28","\uD835\uDD29","\uD835\uDD2A","\uD835\uDD2B","\uD835\uDD2C","\uD835\uDD2D","\uD835\uDD2E","\uD835\uDD2F","\uD835\uDD30","\uD835\uDD31","\uD835\uDD32","\uD835\uDD33","\uD835\uDD34","\uD835\uDD35","\uD835\uDD36","\uD835\uDD37"];var p=["\uD835\uDD38","\uD835\uDD39","\u2102","\uD835\uDD3B","\uD835\uDD3C","\uD835\uDD3D","\uD835\uDD3E","\u210D","\uD835\uDD40","\uD835\uDD41","\uD835\uDD42","\uD835\uDD43","\uD835\uDD44","\u2115","\uD835\uDD46","\u2119","\u211A","\u211D","\uD835\uDD4A","\uD835\uDD4B","\uD835\uDD4C","\uD835\uDD4D","\uD835\uDD4E","\uD835\uDD4F","\uD835\uDD50","\u2124","\uD835\uDD52","\uD835\uDD53","\uD835\uDD54","\uD835\uDD55","\uD835\uDD56","\uD835\uDD57","\uD835\uDD58","\uD835\uDD59","\uD835\uDD5A","\uD835\uDD5B","\uD835\uDD5C","\uD835\uDD5D","\uD835\uDD5E","\uD835\uDD5F","\uD835\uDD60","\uD835\uDD61","\uD835\uDD62","\uD835\uDD63","\uD835\uDD64","\uD835\uDD65","\uD835\uDD66","\uD835\uDD67","\uD835\uDD68","\uD835\uDD69","\uD835\uDD6A","\uD835\uDD6B"];var x=0,b=1,c=2,m=3,v=4,d=5,n=6,o=7,l=8,e=9,z=10,y=11,g=13,i=14;var a=[{input:"\\varepsilon",tag:"mi",output:"\u025B",ttype:x},{input:"\\varsigma",tag:"mi",output:"\u03C2",ttype:x},{input:"\\vartheta",tag:"mi",output:"\u03D1",ttype:x},{input:"\\varphi",tag:"mi",output:"\u03D5",ttype:x},{input:"\\varpi",tag:"mi",output:"\u03D6",ttype:x},{input:"\\varrho",tag:"mi",output:"\u03F1",ttype:x},{input:"\\alpha",tag:"mi",output:"\u03B1",ttype:x},{input:"\\beta",tag:"mi",output:"\u03B2",ttype:x},{input:"\\gamma",tag:"mi",output:"\u03B3",ttype:x},{input:"\\delta",tag:"mi",output:"\u03B4",ttype:x},{input:"\\epsilon",tag:"mi",output:"\u03B5",ttype:x},{input:"\\zeta",tag:"mi",output:"\u03B6",ttype:x},{input:"\\eta",tag:"mi",output:"\u03B7",ttype:x},{input:"\\theta",tag:"mi",output:"\u03B8",ttype:x},{input:"\\iota",tag:"mi",output:"\u03B9",ttype:x},{input:"\\kappa",tag:"mi",output:"\u03BA",ttype:x},{input:"\\lambda",tag:"mi",output:"\u03BB",ttype:x},{input:"\\mu",tag:"mi",output:"\u03BC",ttype:x},{input:"\\nu",tag:"mi",output:"\u03BD",ttype:x},{input:"\\xi",tag:"mi",output:"\u03BE",ttype:x},{input:"\\omicron",tag:"mi",output:"\u03BF",ttype:x},{input:"\\pi",tag:"mi",output:"\u03C0",ttype:x},{input:"\\rho",tag:"mi",output:"\u03C1",ttype:x},{input:"\\sigma",tag:"mi",output:"\u03C3",ttype:x},{input:"\\tau",tag:"mi",output:"\u03C4",ttype:x},{input:"\\upsilon",tag:"mi",output:"\u03C5",ttype:x},{input:"\\phi",tag:"mi",output:"\u03C6",ttype:x},{input:"\\chi",tag:"mi",output:"\u03C7",ttype:x},{input:"\\psi",tag:"mi",output:"\u03C8",ttype:x},{input:"\\omega",tag:"mi",output:"\u03C9",ttype:x},{input:"\\Alpha",tag:"mo",output:"\u0391",ttype:x},{input:"\\Beta",tag:"mo",output:"\u0392",ttype:x},{input:"\\Gamma",tag:"mo",output:"\u0393",ttype:x},{input:"\\Delta",tag:"mo",output:"\u0394",ttype:x},{input:"\\Epsilon",tag:"mo",output:"\u0395",ttype:x},{input:"\\Zeta",tag:"mo",output:"\u0396",ttype:x},{input:"\\Eta",tag:"mo",output:"\u0397",ttype:x},{input:"\\Theta",tag:"mo",output:"\u0398",ttype:x},{input:"\\Iota",tag:"mo",output:"\u0399",ttype:x},{input:"\\Kappa",tag:"mo",output:"\u039A",ttype:x},{input:"\\Lambda",tag:"mo",output:"\u039B",ttype:x},{input:"\\Mu",tag:"mo",output:"\u039C",ttype:x},{input:"\\Nu",tag:"mo",output:"\u039D",ttype:x},{input:"\\Xi",tag:"mo",output:"\u039E",ttype:x},{input:"\\Omicron",tag:"mo",output:"\u039F",ttype:x},{input:"\\Pi",tag:"mo",output:"\u03A0",ttype:x},{input:"\\Rho",tag:"mo",output:"\u03A1",ttype:x},{input:"\\Sigma",tag:"mo",output:"\u03A3",ttype:x},{input:"\\Tau",tag:"mo",output:"\u03A4",ttype:x},{input:"\\Upsilon",tag:"mo",output:"\u03A5",ttype:x},{input:"\\Phi",tag:"mo",output:"\u03A6",ttype:x},{input:"\\Chi",tag:"mo",output:"\u03A7",ttype:x},{input:"\\Psi",tag:"mo",output:"\u03A8",ttype:x},{input:"\\Omega",tag:"mo",output:"\u03A9",ttype:x},{input:"\\frac12",tag:"mo",output:"\u00BD",ttype:x},{input:"\\frac14",tag:"mo",output:"\u00BC",ttype:x},{input:"\\frac34",tag:"mo",output:"\u00BE",ttype:x},{input:"\\frac13",tag:"mo",output:"\u2153",ttype:x},{input:"\\frac23",tag:"mo",output:"\u2154",ttype:x},{input:"\\frac15",tag:"mo",output:"\u2155",ttype:x},{input:"\\frac25",tag:"mo",output:"\u2156",ttype:x},{input:"\\frac35",tag:"mo",output:"\u2157",ttype:x},{input:"\\frac45",tag:"mo",output:"\u2158",ttype:x},{input:"\\frac16",tag:"mo",output:"\u2159",ttype:x},{input:"\\frac56",tag:"mo",output:"\u215A",ttype:x},{input:"\\frac18",tag:"mo",output:"\u215B",ttype:x},{input:"\\frac38",tag:"mo",output:"\u215C",ttype:x},{input:"\\frac58",tag:"mo",output:"\u215D",ttype:x},{input:"\\frac78",tag:"mo",output:"\u215E",ttype:x},{input:"\\pm",tag:"mo",output:"\u00B1",ttype:x},{input:"\\mp",tag:"mo",output:"\u2213",ttype:x},{input:"\\triangleleft",tag:"mo",output:"\u22B2",ttype:x},{input:"\\triangleright",tag:"mo",output:"\u22B3",ttype:x},{input:"\\cdot",tag:"mo",output:"\u22C5",ttype:x},{input:"\\star",tag:"mo",output:"\u22C6",ttype:x},{input:"\\ast",tag:"mo",output:"\u002A",ttype:x},{input:"\\times",tag:"mo",output:"\u00D7",ttype:x},{input:"\\div",tag:"mo",output:"\u00F7",ttype:x},{input:"\\circ",tag:"mo",output:"\u2218",ttype:x},{input:"\\bullet",tag:"mo",output:"\u2022",ttype:x},{input:"\\oplus",tag:"mo",output:"\u2295",ttype:x},{input:"\\ominus",tag:"mo",output:"\u2296",ttype:x},{input:"\\otimes",tag:"mo",output:"\u2297",ttype:x},{input:"\\bigcirc",tag:"mo",output:"\u25CB",ttype:x},{input:"\\oslash",tag:"mo",output:"\u2298",ttype:x},{input:"\\odot",tag:"mo",output:"\u2299",ttype:x},{input:"\\land",tag:"mo",output:"\u2227",ttype:x},{input:"\\wedge",tag:"mo",output:"\u2227",ttype:x},{input:"\\lor",tag:"mo",output:"\u2228",ttype:x},{input:"\\vee",tag:"mo",output:"\u2228",ttype:x},{input:"\\cap",tag:"mo",output:"\u2229",ttype:x},{input:"\\cup",tag:"mo",output:"\u222A",ttype:x},{input:"\\sqcap",tag:"mo",output:"\u2293",ttype:x},{input:"\\sqcup",tag:"mo",output:"\u2294",ttype:x},{input:"\\uplus",tag:"mo",output:"\u228E",ttype:x},{input:"\\amalg",tag:"mo",output:"\u2210",ttype:x},{input:"\\bigtriangleup",tag:"mo",output:"\u25B3",ttype:x},{input:"\\bigtriangledown",tag:"mo",output:"\u25BD",ttype:x},{input:"\\dag",tag:"mo",output:"\u2020",ttype:x},{input:"\\dagger",tag:"mo",output:"\u2020",ttype:x},{input:"\\ddag",tag:"mo",output:"\u2021",ttype:x},{input:"\\ddagger",tag:"mo",output:"\u2021",ttype:x},{input:"\\lhd",tag:"mo",output:"\u22B2",ttype:x},{input:"\\rhd",tag:"mo",output:"\u22B3",ttype:x},{input:"\\unlhd",tag:"mo",output:"\u22B4",ttype:x},{input:"\\unrhd",tag:"mo",output:"\u22B5",ttype:x},{input:"\\sum",tag:"mo",output:"\u2211",ttype:o},{input:"\\prod",tag:"mo",output:"\u220F",ttype:o},{input:"\\bigcap",tag:"mo",output:"\u22C2",ttype:o},{input:"\\bigcup",tag:"mo",output:"\u22C3",ttype:o},{input:"\\bigwedge",tag:"mo",output:"\u22C0",ttype:o},{input:"\\bigvee",tag:"mo",output:"\u22C1",ttype:o},{input:"\\bigsqcap",tag:"mo",output:"\u2A05",ttype:o},{input:"\\bigsqcup",tag:"mo",output:"\u2A06",ttype:o},{input:"\\coprod",tag:"mo",output:"\u2210",ttype:o},{input:"\\bigoplus",tag:"mo",output:"\u2A01",ttype:o},{input:"\\bigotimes",tag:"mo",output:"\u2A02",ttype:o},{input:"\\bigodot",tag:"mo",output:"\u2A00",ttype:o},{input:"\\biguplus",tag:"mo",output:"\u2A04",ttype:o},{input:"\\int",tag:"mo",output:"\u222B",ttype:x},{input:"\\oint",tag:"mo",output:"\u222E",ttype:x},{input:":=",tag:"mo",output:":=",ttype:x},{input:"\\lt",tag:"mo",output:"<",ttype:x},{input:"\\gt",tag:"mo",output:">",ttype:x},{input:"\\ne",tag:"mo",output:"\u2260",ttype:x},{input:"\\neq",tag:"mo",output:"\u2260",ttype:x},{input:"\\le",tag:"mo",output:"\u2264",ttype:x},{input:"\\leq",tag:"mo",output:"\u2264",ttype:x},{input:"\\leqslant",tag:"mo",output:"\u2264",ttype:x},{input:"\\ge",tag:"mo",output:"\u2265",ttype:x},{input:"\\geq",tag:"mo",output:"\u2265",ttype:x},{input:"\\geqslant",tag:"mo",output:"\u2265",ttype:x},{input:"\\equiv",tag:"mo",output:"\u2261",ttype:x},{input:"\\ll",tag:"mo",output:"\u226A",ttype:x},{input:"\\gg",tag:"mo",output:"\u226B",ttype:x},{input:"\\doteq",tag:"mo",output:"\u2250",ttype:x},{input:"\\prec",tag:"mo",output:"\u227A",ttype:x},{input:"\\succ",tag:"mo",output:"\u227B",ttype:x},{input:"\\preceq",tag:"mo",output:"\u227C",ttype:x},{input:"\\succeq",tag:"mo",output:"\u227D",ttype:x},{input:"\\subset",tag:"mo",output:"\u2282",ttype:x},{input:"\\supset",tag:"mo",output:"\u2283",ttype:x},{input:"\\subseteq",tag:"mo",output:"\u2286",ttype:x},{input:"\\supseteq",tag:"mo",output:"\u2287",ttype:x},{input:"\\sqsubset",tag:"mo",output:"\u228F",ttype:x},{input:"\\sqsupset",tag:"mo",output:"\u2290",ttype:x},{input:"\\sqsubseteq",tag:"mo",output:"\u2291",ttype:x},{input:"\\sqsupseteq",tag:"mo",output:"\u2292",ttype:x},{input:"\\sim",tag:"mo",output:"\u223C",ttype:x},{input:"\\simeq",tag:"mo",output:"\u2243",ttype:x},{input:"\\approx",tag:"mo",output:"\u2248",ttype:x},{input:"\\cong",tag:"mo",output:"\u2245",ttype:x},{input:"\\Join",tag:"mo",output:"\u22C8",ttype:x},{input:"\\bowtie",tag:"mo",output:"\u22C8",ttype:x},{input:"\\in",tag:"mo",output:"\u2208",ttype:x},{input:"\\ni",tag:"mo",output:"\u220B",ttype:x},{input:"\\owns",tag:"mo",output:"\u220B",ttype:x},{input:"\\propto",tag:"mo",output:"\u221D",ttype:x},{input:"\\vdash",tag:"mo",output:"\u22A2",ttype:x},{input:"\\dashv",tag:"mo",output:"\u22A3",ttype:x},{input:"\\models",tag:"mo",output:"\u22A8",ttype:x},{input:"\\perp",tag:"mo",output:"\u22A5",ttype:x},{input:"\\smile",tag:"mo",output:"\u2323",ttype:x},{input:"\\frown",tag:"mo",output:"\u2322",ttype:x},{input:"\\asymp",tag:"mo",output:"\u224D",ttype:x},{input:"\\notin",tag:"mo",output:"\u2209",ttype:x},{input:"\\begin{eqnarray}",output:"X",ttype:i,invisible:true},{input:"\\begin{array}",output:"X",ttype:i,invisible:true},{input:"\\\\",output:"}&{",ttype:l},{input:"\\end{eqnarray}",output:"}}",ttype:l},{input:"\\end{array}",output:"}}",ttype:l},{input:"\\big",tag:"mo",output:"X",atval:"1.2",ttype:y},{input:"\\Big",tag:"mo",output:"X",atval:"1.8",ttype:y},{input:"\\bigg",tag:"mo",output:"X",atval:"2.3",ttype:y},{input:"\\Bigg",tag:"mo",output:"X",atval:"2.9",ttype:y},{input:"\\left",tag:"mo",output:"X",ttype:v},{input:"\\right",tag:"mo",output:"X",ttype:d},{input:"{",output:"{",ttype:v,invisible:true},{input:"}",output:"}",ttype:d,invisible:true},{input:"(",tag:"mo",output:"(",atval:"1",ttype:g},{input:"[",tag:"mo",output:"[",atval:"1",ttype:g},{input:"\\lbrack",tag:"mo",output:"[",atval:"1",ttype:g},{input:"\\{",tag:"mo",output:"{",atval:"1",ttype:g},{input:"\\lbrace",tag:"mo",output:"{",atval:"1",ttype:g},{input:"\\langle",tag:"mo",output:"\u2329",atval:"1",ttype:g},{input:"\\lfloor",tag:"mo",output:"\u230A",atval:"1",ttype:g},{input:"\\lceil",tag:"mo",output:"\u2308",atval:"1",ttype:g},{input:")",tag:"mo",output:")",rtag:"mi",atval:"1",ttype:g},{input:"]",tag:"mo",output:"]",rtag:"mi",atval:"1",ttype:g},{input:"\\rbrack",tag:"mo",output:"]",rtag:"mi",atval:"1",ttype:g},{input:"\\}",tag:"mo",output:"}",rtag:"mi",atval:"1",ttype:g},{input:"\\rbrace",tag:"mo",output:"}",rtag:"mi",atval:"1",ttype:g},{input:"\\rangle",tag:"mo",output:"\u232A",rtag:"mi",atval:"1",ttype:g},{input:"\\rfloor",tag:"mo",output:"\u230B",rtag:"mi",atval:"1",ttype:g},{input:"\\rceil",tag:"mo",output:"\u2309",rtag:"mi",atval:"1",ttype:g},{input:"|",tag:"mo",output:"\u2223",atval:"1",ttype:g},{input:"\\|",tag:"mo",output:"\u2225",atval:"1",ttype:g},{input:"\\vert",tag:"mo",output:"\u2223",atval:"1",ttype:g},{input:"\\Vert",tag:"mo",output:"\u2225",atval:"1",ttype:g},{input:"\\mid",tag:"mo",output:"\u2223",atval:"1",ttype:g},{input:"\\parallel",tag:"mo",output:"\u2225",atval:"1",ttype:g},{input:"/",tag:"mo",output:"/",atval:"1.01",ttype:g},{input:"\\backslash",tag:"mo",output:"\u2216",atval:"1",ttype:g},{input:"\\setminus",tag:"mo",output:"\\",ttype:x},{input:"\\!",tag:"mspace",atname:"width",atval:"-0.167em",ttype:n},{input:"\\,",tag:"mspace",atname:"width",atval:"0.167em",ttype:n},{input:"\\>",tag:"mspace",atname:"width",atval:"0.222em",ttype:n},{input:"\\:",tag:"mspace",atname:"width",atval:"0.222em",ttype:n},{input:"\\;",tag:"mspace",atname:"width",atval:"0.278em",ttype:n},{input:"~",tag:"mspace",atname:"width",atval:"0.333em",ttype:n},{input:"\\quad",tag:"mspace",atname:"width",atval:"1em",ttype:n},{input:"\\qquad",tag:"mspace",atname:"width",atval:"2em",ttype:n},{input:"\\prime",tag:"mo",output:"\u2032",ttype:x},{input:"'",tag:"mo",output:"\u02B9",ttype:x},{input:"''",tag:"mo",output:"\u02BA",ttype:x},{input:"'''",tag:"mo",output:"\u2034",ttype:x},{input:"''''",tag:"mo",output:"\u2057",ttype:x},{input:"\\ldots",tag:"mo",output:"\u2026",ttype:x},{input:"\\cdots",tag:"mo",output:"\u22EF",ttype:x},{input:"\\vdots",tag:"mo",output:"\u22EE",ttype:x},{input:"\\ddots",tag:"mo",output:"\u22F1",ttype:x},{input:"\\forall",tag:"mo",output:"\u2200",ttype:x},{input:"\\exists",tag:"mo",output:"\u2203",ttype:x},{input:"\\Re",tag:"mo",output:"\u211C",ttype:x},{input:"\\Im",tag:"mo",output:"\u2111",ttype:x},{input:"\\aleph",tag:"mo",output:"\u2135",ttype:x},{input:"\\hbar",tag:"mo",output:"\u210F",ttype:x},{input:"\\ell",tag:"mo",output:"\u2113",ttype:x},{input:"\\wp",tag:"mo",output:"\u2118",ttype:x},{input:"\\emptyset",tag:"mo",output:"\u2205",ttype:x},{input:"\\infty",tag:"mo",output:"\u221E",ttype:x},{input:"\\surd",tag:"mo",output:"\\sqrt{}",ttype:l},{input:"\\partial",tag:"mo",output:"\u2202",ttype:x},{input:"\\nabla",tag:"mo",output:"\u2207",ttype:x},{input:"\\triangle",tag:"mo",output:"\u25B3",ttype:x},{input:"\\therefore",tag:"mo",output:"\u2234",ttype:x},{input:"\\angle",tag:"mo",output:"\u2220",ttype:x},{input:"\\diamond",tag:"mo",output:"\u22C4",ttype:x},{input:"\\Diamond",tag:"mo",output:"\u25C7",ttype:x},{input:"\\neg",tag:"mo",output:"\u00AC",ttype:x},{input:"\\lnot",tag:"mo",output:"\u00AC",ttype:x},{input:"\\bot",tag:"mo",output:"\u22A5",ttype:x},{input:"\\top",tag:"mo",output:"\u22A4",ttype:x},{input:"\\square",tag:"mo",output:"\u25AB",ttype:x},{input:"\\Box",tag:"mo",output:"\u25A1",ttype:x},{input:"\\wr",tag:"mo",output:"\u2240",ttype:x},{input:"\\arccos",tag:"mi",output:"arccos",ttype:b,func:true},{input:"\\arcsin",tag:"mi",output:"arcsin",ttype:b,func:true},{input:"\\arctan",tag:"mi",output:"arctan",ttype:b,func:true},{input:"\\arg",tag:"mi",output:"arg",ttype:b,func:true},{input:"\\cos",tag:"mi",output:"cos",ttype:b,func:true},{input:"\\cosh",tag:"mi",output:"cosh",ttype:b,func:true},{input:"\\cot",tag:"mi",output:"cot",ttype:b,func:true},{input:"\\coth",tag:"mi",output:"coth",ttype:b,func:true},{input:"\\csc",tag:"mi",output:"csc",ttype:b,func:true},{input:"\\deg",tag:"mi",output:"deg",ttype:b,func:true},{input:"\\det",tag:"mi",output:"det",ttype:b,func:true},{input:"\\dim",tag:"mi",output:"dim",ttype:b,func:true},{input:"\\exp",tag:"mi",output:"exp",ttype:b,func:true},{input:"\\gcd",tag:"mi",output:"gcd",ttype:b,func:true},{input:"\\hom",tag:"mi",output:"hom",ttype:b,func:true},{input:"\\inf",tag:"mo",output:"inf",ttype:o},{input:"\\ker",tag:"mi",output:"ker",ttype:b,func:true},{input:"\\lg",tag:"mi",output:"lg",ttype:b,func:true},{input:"\\lim",tag:"mo",output:"lim",ttype:o},{input:"\\liminf",tag:"mo",output:"liminf",ttype:o},{input:"\\limsup",tag:"mo",output:"limsup",ttype:o},{input:"\\ln",tag:"mi",output:"ln",ttype:b,func:true},{input:"\\log",tag:"mi",output:"log",ttype:b,func:true},{input:"\\max",tag:"mo",output:"max",ttype:o},{input:"\\min",tag:"mo",output:"min",ttype:o},{input:"\\Pr",tag:"mi",output:"Pr",ttype:b,func:true},{input:"\\sec",tag:"mi",output:"sec",ttype:b,func:true},{input:"\\sin",tag:"mi",output:"sin",ttype:b,func:true},{input:"\\sinh",tag:"mi",output:"sinh",ttype:b,func:true},{input:"\\sup",tag:"mo",output:"sup",ttype:o},{input:"\\tan",tag:"mi",output:"tan",ttype:b,func:true},{input:"\\tanh",tag:"mi",output:"tanh",ttype:b,func:true},{input:"\\gets",tag:"mo",output:"\u2190",ttype:x},{input:"\\leftarrow",tag:"mo",output:"\u2190",ttype:x},{input:"\\to",tag:"mo",output:"\u2192",ttype:x},{input:"\\rightarrow",tag:"mo",output:"\u2192",ttype:x},{input:"\\leftrightarrow",tag:"mo",output:"\u2194",ttype:x},{input:"\\uparrow",tag:"mo",output:"\u2191",ttype:x},{input:"\\downarrow",tag:"mo",output:"\u2193",ttype:x},{input:"\\updownarrow",tag:"mo",output:"\u2195",ttype:x},{input:"\\Leftarrow",tag:"mo",output:"\u21D0",ttype:x},{input:"\\Rightarrow",tag:"mo",output:"\u21D2",ttype:x},{input:"\\Leftrightarrow",tag:"mo",output:"\u21D4",ttype:x},{input:"\\iff",tag:"mo",output:"~\\Longleftrightarrow~",ttype:l},{input:"\\Uparrow",tag:"mo",output:"\u21D1",ttype:x},{input:"\\Downarrow",tag:"mo",output:"\u21D3",ttype:x},{input:"\\Updownarrow",tag:"mo",output:"\u21D5",ttype:x},{input:"\\mapsto",tag:"mo",output:"\u21A6",ttype:x},{input:"\\longleftarrow",tag:"mo",output:"\u27F5",ttype:x},{input:"\\longrightarrow",tag:"mo",output:"\u27F6",ttype:x},{input:"\\longleftrightarrow",tag:"mo",output:"\u27F7",ttype:x},{input:"\\Longleftarrow",tag:"mo",output:"\u27F8",ttype:x},{input:"\\Longrightarrow",tag:"mo",output:"\u27F9",ttype:x},{input:"\\Longleftrightarrow",tag:"mo",output:"\u27FA",ttype:x},{input:"\\longmapsto",tag:"mo",output:"\u27FC",ttype:x},{input:"\\sqrt",tag:"msqrt",output:"sqrt",ttype:b},{input:"\\root",tag:"mroot",output:"root",ttype:c},{input:"\\frac",tag:"mfrac",output:"/",ttype:c},{input:"\\stackrel",tag:"mover",output:"stackrel",ttype:c},{input:"\\atop",tag:"mfrac",output:"",ttype:m},{input:"\\choose",tag:"mfrac",output:"",ttype:m},{input:"_",tag:"msub",output:"_",ttype:m},{input:"^",tag:"msup",output:"^",ttype:m},{input:"\\mbox",tag:"mtext",output:"mbox",ttype:z},{input:"\\acute",tag:"mover",output:"\u00B4",ttype:b,acc:true},{input:"\\grave",tag:"mover",output:"\u0060",ttype:b,acc:true},{input:"\\breve",tag:"mover",output:"\u02D8",ttype:b,acc:true},{input:"\\check",tag:"mover",output:"\u02C7",ttype:b,acc:true},{input:"\\dot",tag:"mover",output:".",ttype:b,acc:true},{input:"\\ddot",tag:"mover",output:"..",ttype:b,acc:true},{input:"\\mathring",tag:"mover",output:"\u00B0",ttype:b,acc:true},{input:"\\vec",tag:"mover",output:"\u20D7",ttype:b,acc:true},{input:"\\overrightarrow",tag:"mover",output:"\u20D7",ttype:b,acc:true},{input:"\\overleftarrow",tag:"mover",output:"\u20D6",ttype:b,acc:true},{input:"\\hat",tag:"mover",output:"\u005E",ttype:b,acc:true},{input:"\\widehat",tag:"mover",output:"\u0302",ttype:b,acc:true},{input:"\\tilde",tag:"mover",output:"~",ttype:b,acc:true},{input:"\\widetilde",tag:"mover",output:"\u02DC",ttype:b,acc:true},{input:"\\bar",tag:"mover",output:"\u203E",ttype:b,acc:true},{input:"\\overbrace",tag:"mover",output:"\u23B4",ttype:b,acc:true},{input:"\\overline",tag:"mover",output:"\u00AF",ttype:b,acc:true},{input:"\\underbrace",tag:"munder",output:"\u23B5",ttype:b,acc:true},{input:"\\underline",tag:"munder",output:"\u00AF",ttype:b,acc:true},{input:"\\displaystyle",tag:"mstyle",atname:"displaystyle",atval:"true",ttype:b},{input:"\\textstyle",tag:"mstyle",atname:"displaystyle",atval:"false",ttype:b},{input:"\\scriptstyle",tag:"mstyle",atname:"scriptlevel",atval:"1",ttype:b},{input:"\\scriptscriptstyle",tag:"mstyle",atname:"scriptlevel",atval:"2",ttype:b},{input:"\\mathrm",tag:"mtext",output:"text",ttype:z},{input:"\\textrm",tag:"mtext",output:"text",ttype:z},{input:"\\mathbf",tag:"mstyle",atname:"mathvariant",atval:"bold",ttype:b,codes:s},{input:"\\textbf",tag:"mstyle",atname:"mathvariant",atval:"bold",ttype:b,codes:s},{input:"\\mathit",tag:"mstyle",atname:"mathvariant",atval:"italic",ttype:b},{input:"\\textit",tag:"mstyle",atname:"mathvariant",atval:"italic",ttype:b},{input:"\\mathtt",tag:"mstyle",atname:"mathvariant",atval:"monospace",ttype:b,codes:s},{input:"\\texttt",tag:"mstyle",atname:"mathvariant",atval:"monospace",ttype:b,codes:s},{input:"\\mathsf",tag:"mstyle",atname:"mathvariant",atval:"sans-serif",ttype:b,codes:s},{input:"\\mathbb",tag:"mstyle",atname:"mathvariant",atval:"double-struck",ttype:b,codes:p},{input:"\\mathcal",tag:"mstyle",atname:"mathvariant",atval:"script",ttype:b,codes:q},{input:"\\mathfrak",tag:"mstyle",atname:"mathvariant",atval:"fraktur",ttype:b,codes:B}];var r=[];function k(){return(j.browser.mozilla||j.browser.opera)}function E(F,G){if(F.input>G.input){return 1}else{return -1}}function u(){var F=a.length;a.sort(E);for(var G=0;G<F;G++){r[G]=a[G].input}}function w(F,G){return j.trim(F.slice(G))}function C(G,I){var H=r.indexOf(G,I);if(H<0){var F=r.concat([G]);F.sort();H=F.indexOf(G,I)}return H}function t(M){var F=0;var G=0;var I;var O;var N;var J="";var L=true;var K=M.length;for(var H=1;H<=K&&L;H++){O=M.slice(0,H);G=F;F=C(O,G);if(F<r.length&&M.slice(0,r[F].length)==r[F]){J=r[F];I=F;H=J.length}L=F<r.length&&M.slice(0,r[F].length)>=r[F]}if(J!==""){return a[I]}F=1;O=M.slice(0,1);if("0"<=O&&O<="9"){N="mn"}else{N=(("A">O||O>"Z")&&("a">O||O>"z")?"mo":"mi")}return{input:O,tag:N,output:O,ttype:x}}function f(N){var I,G,S,H,K,Q,M=document.createDocumentFragment();N=j.trim(N);I=t(N);if(I===null||I.ttype==d){return[null,N,null]}if(I.ttype==l){N=I.output+w(N,I.input.length);I=t(N);if(I===null||I.ttype==d){return[null,N,null]}}N=w(N,I.input.length);switch(I.ttype){case n:G=A(I.tag);G.setAttribute(I.atname,I.atval);return[G,N,I.tag];case o:return[A(I.tag,document.createTextNode(I.output)),N,I.tag];case x:G=A(I.tag,document.createTextNode(I.output));return[G,N,I.tag];case g:G=A(I.tag,document.createTextNode(I.output));if(I.input=="|"||I.input=="\\vert"||I.input=="\\|"||I.input=="\\Vert"){G.setAttribute("lspace","0em");G.setAttribute("rspace","0em")}G.setAttribute("maxsize",I.atval);if(I.rtag!==null){return[G,N,I.rtag]}else{return[G,N,I.tag]}case y:var L=I.atval;I=t(N);if(I===null){return[null,N,null]}N=w(N,I.input.length);G=A(I.tag,document.createTextNode(I.output));G.setAttribute("minsize",L);G.setAttribute("maxsize",L);return[G,N,I.tag];case v:if(I.input=="\\left"){I=t(N);if(I!==null){if(I.input=="."){I.invisible=true}N=w(N,I.input.length)}}S=h(N,true,false);if(I===null||(typeof I.invisible=="boolean"&&I.invisible)){G=A("mrow",S[0])}else{G=A("mo",document.createTextNode(I.output));G=A("mrow",G);G.appendChild(S[0])}return[G,S[1],S[2]];case i:if(I.input=="\\begin{array}"){var R="";I=t(N);N=j.trim(N);if(I===null){R="l"}else{N=w(N,I.input.length);if(I.input!="{"){R="l"}else{do{I=t(N);if(I!==null){N=w(N,I.input.length);if(I.input!="}"){R=R+I.input}}}while(I!==null&&I.input!==""&&I.input!="}")}}S=h("{"+N,true,true);G=A("mtable",S[0]);R=R.replace(/l/g,"left ");R=R.replace(/r/g,"right ");R=R.replace(/c/g,"center ");G.setAttribute("columnalign",R);G.setAttribute("displaystyle","false");return[G,S[1],null]}else{S=h("{"+N,true,true);G=A("mtable",S[0]);G.setAttribute("columnspacing","0.167em");G.setAttribute("columnalign","right center left");G.setAttribute("displaystyle","true");G=A("mrow",G);return[G,S[1],null]}case z:if(N.charAt(0)=="{"){K=N.indexOf("}")}else{K=0}if(K==-1){K=N.length}Q=N.slice(1,K);M.appendChild(A(I.tag,document.createTextNode(Q)));N=w(N,K+1);return[A("mrow",M),N,null];case b:S=f(N);if(S[0]===null){return[A(I.tag,document.createTextNode(I.output)),N]}if(typeof I.func=="boolean"&&I.func){Q=N.charAt(0);if(Q=="^"||Q=="_"||Q==","){return[A(I.tag,document.createTextNode(I.output)),N,I.tag]}else{G=A("mrow",A(I.tag,document.createTextNode(I.output)));G.appendChild(S[0]);return[G,S[1],I.tag]}}if(I.input=="\\sqrt"){return[A(I.tag,S[0]),S[1],I.tag]}else{if(typeof I.acc=="boolean"&&I.acc){G=A(I.tag,S[0]);var F=I.output;var P=A("mo",document.createTextNode(F));if(I.input=="\\vec"||I.input=="\\check"){P.setAttribute("maxsize","1.2")}if(I.input=="\\underbrace"||I.input=="\\underline"){P.setAttribute("accentunder","true")}else{P.setAttribute("accent","true")}G.appendChild(P);if(I.input=="\\overbrace"||I.input=="\\underbrace"){G.ttype=o}return[G,S[1],I.tag]}else{if(typeof I.codes!="undefined"){for(K=0;K<S[0].childNodes.length;K++){if(S[0].childNodes[K].nodeName=="mi"||S[0].nodeName=="mi"){Q=(S[0].nodeName=="mi"?S[0].firstChild.nodeValue:S[0].childNodes[K].firstChild.nodeValue);var O=[];for(var J=0;J<Q.length;J++){if(Q.charCodeAt(J)>64&&Q.charCodeAt(J)<91){O=O+I.codes[Q.charCodeAt(J)-65]}else{if(Q.charCodeAt(J)>96&&Q.charCodeAt(J)<123){O=O+I.codes[Q.charCodeAt(J)-71]}}}if(S[0].nodeName=="mi"){S[0]=A("mo").appendChild(document.createTextNode(O))}else{S[0].replaceChild(A("mo").appendChild(document.createTextNode(O)),S[0].childNodes[K])}}}}G=A(I.tag,S[0]);G.setAttribute(I.atname,I.atval);if(I.input=="\\scriptstyle"||I.input=="\\scriptscriptstyle"){G.setAttribute("displaystyle","false")}return[G,S[1],I.tag]}}case c:S=f(N);if(S[0]===null){return[A("mo",document.createTextNode(I.input)),N,null]}H=f(S[1]);if(H[0]===null){return[A("mo",document.createTextNode(I.input)),N,null]}if(I.input=="\\root"||I.input=="\\stackrel"){M.appendChild(H[0])}M.appendChild(S[0]);if(I.input=="\\frac"){M.appendChild(H[0])}return[A(I.tag,M),H[1],I.tag];case m:N=w(N,I.input.length);return[A("mo",document.createTextNode(I.output)),N,I.tag];default:return[A(I.tag,document.createTextNode(I.output)),N,I.tag]}}function D(K){var J,H,G,I,M,N,L;H=t(K);M=f(K);I=M[0];K=M[1];N=M[2];J=t(K);if(J.ttype==m){K=w(K,J.input.length);M=f(K);if(M[0]===null){M[0]=A("mo",document.createTextNode("\u25A1"))}K=M[1];N=M[2];if(J.input=="_"||J.input=="^"){G=t(K);N=null;L=((H.ttype==o)||(I.ttype==o));if(J.input=="_"&&G.input=="^"){K=w(K,G.input.length);var F=f(K);K=F[1];N=F[2];I=A((L?"munderover":"msubsup"),I);I.appendChild(M[0]);I.appendChild(F[0])}else{if(J.input=="_"){I=A((L?"munder":"msub"),I);I.appendChild(M[0])}else{I=A((L?"mover":"msup"),I);I.appendChild(M[0])}}I=A("mrow",I)}else{I=A(J.tag,I);if(J.input=="\\atop"||J.input=="\\choose"){I.setAttribute("linethickness","0ex")}I.appendChild(M[0]);if(J.input=="\\choose"){I=A("mfenced",I)}}}return[I,K,N]}function h(M,L,R){var Q,N,I,T,X,J=document.createDocumentFragment();do{M=j.trim(M);I=D(M);N=I[0];M=I[1];X=I[2];Q=t(M);if(N!=undefined){if((X=="mn"||X=="mi")&&Q!==null&&typeof Q.func=="boolean"&&Q.func){var W=A("mspace");W.setAttribute("width","0.167em");N=A("mrow",N);N.appendChild(W)}J.appendChild(N)}}while((Q.ttype!=d)&&Q!==null&&Q.output!="");X=null;if(Q.ttype==d){if(Q.input=="\\right"){M=w(M,Q.input.length);Q=t(M);if(Q!==null&&Q.input=="."){Q.invisible=true}if(Q!==null){X=Q.rtag}}if(Q!==null){M=w(M,Q.input.length)}var U=J.childNodes.length;if(R&&U>0&&J.childNodes[U-1].nodeName=="mrow"&&U>1&&J.childNodes[U-2].nodeName=="mo"&&J.childNodes[U-2].firstChild.nodeValue=="&"){var G=[];var O=J.childNodes.length;for(T=0;R&&T<O;T=T+2){G[T]=[];N=J.childNodes[T];for(var S=0;S<N.childNodes.length;S++){if(N.childNodes[S].firstChild.nodeValue=="&"){G[T][G[T].length]=S}}}var H,F,K,P,V=document.createDocumentFragment();for(T=0;T<O;T=T+2){H=document.createDocumentFragment();F=document.createDocumentFragment();N=J.firstChild;K=N.childNodes.length;P=0;for(S=0;S<K;S++){if(typeof G[T][P]!="undefined"&&S==G[T][P]){N.removeChild(N.firstChild);H.appendChild(A("mtd",F));P++}else{F.appendChild(N.firstChild)}}H.appendChild(A("mtd",F));if(J.childNodes.length>2){J.removeChild(J.firstChild);J.removeChild(J.firstChild)}V.appendChild(A("mtr",H))}return[V,M]}if(typeof Q.invisible!="boolean"||!Q.invisible){N=A("mo",document.createTextNode(Q.output));J.appendChild(N)}}return[J,M,X]}if(!document.createElementNS){document.createElementNS=function(G,F){return this.createElement(F)}}function A(F,H){var G=document.createElementNS("http://www.w3.org/1998/Math/MathML",F);if(H){j(G).append(H)}return G}return{showFormulaOnMouseOver:false,latexImages:false,latexConverter:"http://www.forkosh.dreamhost.com/mimetex.cgi?",mathColor:"black",mathFontSize:"",mathFontFamily:"",createElementXHTML:function(F,G,I){var H=document.createElementNS("http://www.w3.org/1999/xhtml",F);if(G){H.id=G}if(I){H.className=I}return H},define:function(H,I){if(MSVG.latexImages){return}if((typeof H)=="string"){H=[H];I=[I]}var G,F=H.length;if(F!=I.length){return}for(G=0;G<F;G++){a=a.concat([{input:"\\"+H[G],tag:"mo",output:I[G],ttype:l}])}u()},parseMath:function(J,I,G,F){if(J===null){return null}var K=h(J.replace(/^\s+/g,""),false,false)[0];var H=A("mstyle",K);if(I){j(H).attr({displaystyle:"true"})}j(H).attr({mathcolor:F||MSVG.mathColor,fontsize:G||MSVG.mathFontSize,fontfamily:MSVG.mathFontFamily});H=A("math",H);if(MSVG.showFormulaOnMouseOver){j(H).attr({title:J.replace(/\s+/g," ")})}return H},parseMathExternal:function(K,J,G,F){if(K===null){return null}var I=MSVG.createElementXHTML("img");var H=MSVG.latexConverter+K;j(I).attr({src:H});if(MSVG.showFormulaOnMouseOver){j(I).attr({title:K.replace(/\s+/g," ")})}return I},generic:function(){if(MSVG.latexImages||!k()){MSVG.parseMath=MSVG.parseMathExternal}else{u()}if(!(window.SVGElement||j.browser.opera||j.browser.safari)){ASVG.drawPictures=ASVG.removePictures}}}}(jQuery);var ASVG=function($){var SVG;var collection=[];var markerChars="o*sSx+<>|";function createSVGElement(elType){return document.createElementNS("http://www.w3.org/2000/svg",elType)}function getSVGElement(id,el){var node,res={node:null,newEl:false};if(id){id=SVG.id+"_"+id;res.node=$("#"+id)[0]}if(!res.node){res.node=createSVGElement(el);if(id){res.node.id=id}res.newEl=true}return res}function appendSVG(elmt){if(elmt.newEl){$(SVG.canvas).append(elmt.node)}}function setButton(text,title,func){var node=MSVG.createElementXHTML("span",null,"svgButton");node.title=title;node.onclick=func;$(node).append(text);$(node).css({paddingRight:"0.5em",paddingLeft:"0.5em",fontSize:"1em",fontFamily:"monospace",background:"blue",color:"yellow",cursor:"pointer"});$(node).mouseover(function(){$(this).css({background:"yellow",color:"blue"})});$(node).mouseout(function(){$(this).css({background:"blue",color:"yellow"})});node.setAttribute("owner",SVG.id);return node}function pictureAttributes(){this.id=null;this.stroke="blue";this.strokewidth=1;this.strokeopacity=1;this.strokedasharray="none";this.fill="none";this.fillopacity=1;this.fontstyle="normal";this.fontfamily="serif";this.fontweight="normal";this.fontsize=12;this.fontstroke="none";this.fontstrokewidth=1;this.fontstrokeopacity=1;this.fontstrokedasharray="none";this.fontfill="black";this.fontfillopacity=1;this.sector=false;this.largearc=0;this.marker="o";this.size=8;this.orient="auto";this.units="userSpaceOnUse";this.markerstroke="blue";this.markerstrokewidth=1;this.markerstrokeopacity=1;this.markerstrokedasharray="none";this.markerfill="none";this.markerfillopacity=1;this.sweep=0;this.rx=0;this.ry=0;this.closed=false;this.curve="";this.direction=[1,0];this.ticklabels="";this.pos="";this.points=200;this.backgroundcolor="none";this.backgroundopacity=1}function pictureObject(){this.id=null;this.pos=null;this.src="";this.canvas=null;this.border=0;this.width=300;this.height=200;this.factor=1;this.xmin=-5;this.xmax=5;this.ymin=null;this.ymax=null;this.xunitlength=null;this.yunitlength=null;this.origin=[0,0];this.coords="cartesian";this.mouse=[null,null];this.drag=null;this.pan=true;this.locked=false;this.attr=new pictureAttributes()}function refresh(){translateAndEval(SVG.id)}function translateAndEval(id){var errstr;var src=SVG.src;$("#"+SVG.id+" .svgMarker").remove();$("#"+SVG.id+"Canvas").empty();$("#"+SVG.id+"mml").empty();ASVG.dynamic[id]={};src=src.replace(/dynamic\./g,"ASVG.dynamic."+id+".");SVG.attr=new pictureAttributes();try{with(Math){eval(src)}}catch(err){if(typeof err=="object"){errstr=err.name+" "+err.message+" "+err.number+" "+err.description}else{errstr=err}alert(errstr+"\n"+src)}collection[SVG.id]=SVG}function setOptions(atr){for(var i in atr){SVG.attr[i]=atr[i]}}function getOptions(attr,options,prefix){var pref=prefix||"";if(typeof attr=="string"){return(options[pref+attr]==undefined?SVG.attr[pref+attr]:options[pref+attr])}else{var i,newAttr={},len=attr.length,item;for(i=0;i<len;i++){item=attr[i];newAttr[item]=options[pref+item]==undefined?SVG.attr[pref+item]:options[pref+item]}return newAttr}}function setAction(evt,fn,id){if(!$.isFunction(fn)){return}var node=id?$("#"+SVG.id+"_"+id):$("#"+SVG.id);$(node).bind(evt,fn)}function getPosition(evt){var off=$(evt.currentTarget.parentNode).offset();var posX=(evt.pageX-off.left-SVG.origin[0]-SVG.border)/SVG.xunitlength;var posY=(SVG.height-SVG.origin[1]-evt.pageY+off.top+SVG.border)/SVG.yunitlength;return[posX,posY]}function getAngle(p){p=p||[0,0];var res=Math.atan2(SVG.mouse[1]-p[1],SVG.mouse[0]-p[0]);res=(res<0)?res+2*Math.PI:res;return res}function getDistance(p){p=p||[0,0];return Math.sqrt(Math.pow(SVG.mouse[0]-p[0],2)+Math.pow(SVG.mouse[1]-p[1],2))}function updateButton(obj){var id=$(obj).attr("owner");var node=$("#"+id+"src");if(obj.firstChild.nodeValue=="Edit"){obj.firstChild.nodeValue="Update";obj.title="Update picture";node.val(SVG.src).css("display","block")}else{SVG.src=node.val();translateAndEval(id)}}function switchTo(evt){var name=evt.currentTarget.id;if(SVG.id==name||SVG.locked){return}SVG=collection[name]}function onWheel(evt){if(SVG.locked){return false}evt=evt||window.event;var factor=1;if(evt.wheelDelta){factor=(evt.wheelDelta>0)?0.8:1.25}else{if(evt.detail){factor=(evt.detail<0)?0.8:1.25}}if(evt.shiftKey){changeSize(factor)}else{changeScales(factor)}evt.preventDefault();evt.stopPropagation();return false}function onClick(evt){if(evt.button===0){if(evt.shiftKey){$("#"+SVG.id+"toolbar").slideToggle();$("#"+SVG.id+"src").val(SVG.src);SVG.locked=!SVG.locked;evt.stopImmediatePropagation()}else{if(SVG.pan&&!SVG.locked){SVG.drag=[evt.clientX,evt.clientY]}}}return false}function onDrop(evt){if(SVG.drag==null){return false}var xlen=(SVG.drag[0]-evt.clientX)/SVG.xunitlength;var ylen=(-SVG.drag[1]+evt.clientY)/SVG.yunitlength;SVG.drag=null;if(xlen==0&&ylen==0){return false}changeScales(1,[SVG.xmin+xlen,SVG.xmax+xlen,SVG.ymin+ylen,SVG.ymax+ylen]);return false}function setScales(){SVG.xunitlength=SVG.width/(SVG.xmax-SVG.xmin);SVG.yunitlength=SVG.height/(SVG.ymax-SVG.ymin);SVG.origin=[-SVG.xmin*SVG.xunitlength,-SVG.ymin*SVG.yunitlength]}function getScales(scales){scales=scales||[];var res=[null,null,null,null];switch(scales.length){case 0:res[0]=SVG.xmin;res[1]=SVG.xmax;break;case 2:res[0]=scales[0];res[1]=scales[1];break;case 4:res=scales}return res}function setSize(){var picture=$("#"+SVG.id)[0];picture.setAttribute("width",SVG.width);picture.setAttribute("height",SVG.height);picture.parentNode.style.width=SVG.width+"px";picture.parentNode.style.height=SVG.height+"px";var node=$("#"+SVG.id+"ClipPath")[0];node.firstChild.setAttribute("d","M0,0 "+SVG.width+",0 "+SVG.width+","+SVG.height+" 0,"+SVG.height);node=$("#"+SVG.id+"Coords")[0];if(node){node.setAttribute("x",SVG.width);node.setAttribute("y",SVG.height-2)}}function changeSize(factor){SVG.factor*=factor;SVG.width/=factor;SVG.height/=factor;setSize();setScales();translateAndEval(SVG.id)}function changeScales(factor,trans){trans=trans||[SVG.xmin,SVG.xmax,SVG.ymin,SVG.ymax];SVG.factor*=factor;var dx=(SVG.xmax-SVG.xmin)*(1-factor)*0.5;var dy=(SVG.ymax-SVG.ymin)*(1-factor)*0.5;SVG.xmin=trans[0]+dx;SVG.xmax=trans[1]-dx;SVG.ymin=trans[2]+dy;SVG.ymax=trans[3]-dy;setScales();translateAndEval(SVG.id)}function updateCoord(evt){if(SVG.locked){return false}if($.browser.opera){switchTo(evt)}SVG.mouse=getPosition(evt);if(SVG.coords!="none"){var coords;if(SVG.coords=="cartesian"){coords="C: ("+SVG.mouse[0].toFixed(2)+", "+SVG.mouse[1].toFixed(2)+")"}else{coords="P: ("+getDistance().toFixed(2)+", "+getAngle().toFixed(2)+")"}$("#"+SVG.id+"Coords").text(coords)}return false}function removeCoord(){$("#"+SVG.id+"Coords").text("")}function exportSVG(obj){var name=$(obj).attr("owner");var pic=$("#"+name)[0].parentNode.innerHTML;var pos=pic.indexOf("</svg")+6;pic=pic.substr(0,pos);var svg="<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n";if(pic.indexOf("svgCoords")>-1){pos=pic.lastIndexOf("<text");svg+=pic.substr(0,pos);pos=pic.lastIndexOf("</text")+7;svg+=pic.substr(pos)}else{svg+=pic}svg=svg.replace(/ /g,"");svg=svg.replace(/><(?!\/)/g,">\n<");obj.previousSibling.firstChild.nodeValue="Edit";$("#"+name+"src").val(svg).css("display","block")}function toSVG(p){var x=p[0]*SVG.xunitlength+SVG.origin[0];var y=SVG.height-p[1]*SVG.yunitlength-SVG.origin[1];return[x,y]}function toSVGPair(p){var q=toSVG(p);return q[0]+" "+q[1]}function setStrokeAndFill(node,options,prefix){var attributes=["stroke","strokewidth","strokedasharray","strokeopacity","fill","fillopacity"];var attr=getOptions(attributes,options,prefix);node.setAttribute("stroke",attr.stroke);node.setAttribute("stroke-width",attr.strokewidth/SVG.factor);node.setAttribute("stroke-dasharray",attr.strokedasharray);node.setAttribute("stroke-opacity",attr.strokeopacity);node.setAttribute("fill",attr.fill);node.setAttribute("fill-opacity",attr.fillopacity)}function button(p,q,txt,action,options){options=options||{};options.id=(options.id||Math.randomString(8));rect(p,q,options);setAction("click",action,options.id);options.fill=null;options.fillopacity=1;options.id+="_t";text([(p[0]+q[0])*0.5,(p[1]+q[1])*0.5],txt,options);setAction("click",action,options.id)}function setMarkers(obj,options){var attributes=["marker","size","units","orient","markerstroke","markerstrokeopacity"];var attr=getOptions(attributes,options);var node,node2,i,id,pos=["marker-start","marker-mid","marker-end"];var lim=attr.marker.length;for(i=0;i<lim;i++){var type=attr.marker.charAt(i);if(type=="-"||markerChars.indexOf(type)<0){continue}id=(options.id||Math.randomString(8))+"Marker_"+markerChars.indexOf(type);node=$("#"+SVG.id+"_"+id)[0];if(!node){node=getSVGElement(id,"marker").node;node.setAttribute("class","svgMarker");node.setAttribute("viewBox","0 0 10 10");node.setAttribute("refX",5);node.setAttribute("refY",5);node.setAttribute("orient",attr.orient);node.setAttribute("markerUnits",attr.units);switch(type){case"*":case"o":node2=createSVGElement("circle");node2.setAttribute("cx",5);node2.setAttribute("cy",5);node2.setAttribute("r",4);break;case">":node2=createSVGElement("path");node2.setAttribute("d","M0 0 L10 5 L0 10 z");node.setAttribute("refX",10);break;case"<":node2=createSVGElement("path");node2.setAttribute("d","M10 0 L10 10 L0 5 z");node.setAttribute("refX",0);break;case"x":node2=createSVGElement("path");node2.setAttribute("d","M0 0 L10 10 M0 10 L10 0");break;case"+":node2=createSVGElement("path");node2.setAttribute("d","M5 0 L5 10 M0 5 L10 5");break;case"|":node2=createSVGElement("path");node2.setAttribute("d","M5 0 L5 10");break;case"S":case"s":node2=createSVGElement("rect");node2.setAttribute("x",0);node2.setAttribute("y",0);node2.setAttribute("width",10);node2.setAttribute("height",10)}setStrokeAndFill(node2,options,"marker");if("*<>S".indexOf(type)>-1){node2.setAttribute("fill",attr.markerstroke);node2.setAttribute("fill-opacity",attr.markerstrokeopacity)}$(node).append(node2);$("#"+SVG.id+"_Defs:first").append(node)}node.setAttribute("markerWidth",attr.size/SVG.factor);node.setAttribute("markerHeight",attr.size/SVG.factor);obj.setAttribute(pos[i],"url(#"+SVG.id+"_"+id+")")}}function setLabels(p,options){var i,point,pos;var label=(typeof options.label=="string")?[options.label]:options.label;var labelpos=getOptions("pos",options);labelpos=(typeof labelpos=="string")?[labelpos]:labelpos;var poslen=labelpos.length;var size=options.size||SVG.attr.size;var dx=(0.5*size/SVG.xunitlength)/SVG.factor;var dy=(0.5*size/SVG.yunitlength)/SVG.factor;for(i=0;i<label.length;i++){options.isLabel="_label"+i;point=p[i];pos=(poslen>i)?labelpos[i].toUpperCase():pos;if(/E/.test(pos)){point[0]+=dx}if(/W/.test(pos)){point[0]-=dx}if(/N/.test(pos)){point[1]+=dy}if(/S/.test(pos)){point[1]-=dy}options.pos=pos;text(point,label[i],options)}}function line(p,q,options){options=options||{};options.closed=false;options.curve="";path([p,q],options)}function dot(p,options){options=options||{};var direction=getOptions("direction",options);var q=[p[0]+direction[0]/SVG.xunitlength,p[1]+direction[1]/SVG.yunitlength];var elmt=getSVGElement(options.id,"path");var st="M"+toSVGPair(p)+" "+toSVGPair(q);elmt.node.setAttribute("d",st);elmt.node.setAttribute("stroke","none");setMarkers(elmt.node,options);if(options.label){setLabels([p,q],options)}appendSVG(elmt)}function path(list,options){options=options||{};var st,i,elmt=getSVGElement(options.id,"path");var attr=getOptions(["curve","closed"],options);var len=list.length;if(len===0){return}st="M"+toSVGPair(list[0])+" "+attr.curve;for(i=1;i<len;i++){st+=toSVGPair(list[i])+" "}if(attr.closed){st+="Z"}elmt.node.setAttribute("d",st);setStrokeAndFill(elmt.node,options);if(options.marker){setMarkers(elmt.node,options)}if(options.label){setLabels(list,options)}appendSVG(elmt)}function rotate(id,angle,options){if(!id||!angle){return}var node=$("#"+SVG.id+"_"+id)[0];if(node){options=options||{};var center=options.center?toSVG(options.center):SVG.origin;angle=-angle*180/Math.PI;var transform=node.getAttribute("transform")||"";transform="rotate("+angle+" "+center+") "+(options.replace?"":transform);node.setAttribute("transform",transform)}}function translate(id,delta,options){if(!id||!delta){return}var node=$("#"+SVG.id+"_"+id)[0];if(node){options=options||{};delta=toSVG(delta);var transform=node.getAttribute("transform")||"";transform="translate("+(delta[0]-SVG.origin[0])+" "+(SVG.origin[1]+delta[1]-SVG.height)+") "+(options.replace?"":transform);node.setAttribute("transform",transform)}}function curve(list,options){options=options||{};options.curve=options.curve||"T";path(list,options)}function circle(center,radius,options){ellipse(center,radius,radius,options)}function loop(p,options){options=options||{};var d=options.direction||[1,0];options.curve="C";options.closed=false;path([p,[p[0]+d[0],p[1]+d[1]],[p[0]-d[1],p[1]+d[0]],p],options)}function arc(options){options=options||{};var start=options.start;var end=options.end;var center=options.center;var startangle=options.startangle;var endangle=options.endangle;var st="M",elmt=getSVGElement(options.id,"path");var attr=getOptions(["largearc","sweep","closed","sector"],options);var radius=options.radius;if(center!=null&&startangle!=null&&endangle!=null&&radius!=null){start=[radius*Math.cos(startangle)+center[0],radius*Math.sin(startangle)+center[1]];end=[radius*Math.cos(endangle)+center[0],radius*Math.sin(endangle)+center[1]]}if(start==null||end==null){return}if(!radius){var v=[end[0]-start[0],end[1]-start[1]];radius=Math.sqrt(v[0]*v[0]+v[1]*v[1])}if(attr.sector){st+=toSVGPair(center)+" "}st+=toSVGPair(start)+" A"+radius*SVG.xunitlength+","+radius*SVG.yunitlength+" 0 "+attr.largearc+","+attr.sweep+" "+toSVGPair(end);if(attr.sector||attr.closed){st+=" z"}elmt.node.setAttribute("d",st);setStrokeAndFill(elmt.node,options);if(options.marker){setMarkers(elmt.node,options)}if(options.label){setLabels([start,end],options)}appendSVG(elmt)}function sector(options){if(!options.center||!options.startangle||!options.endangle||!options.radius){return}options.sector=true;arc(options)}function ellipse(center,rx,ry,options){options=options||{};var elmt=getSVGElement(options.id,"ellipse");center=toSVG(center);elmt.node.setAttribute("cx",center[0]);elmt.node.setAttribute("cy",center[1]);elmt.node.setAttribute("rx",rx*SVG.xunitlength);elmt.node.setAttribute("ry",ry*SVG.yunitlength);setStrokeAndFill(elmt.node,options);appendSVG(elmt)}function polygon(list,options){options=options||{};options.closed=true;path(list,options)}function rect(p,q,options){options=options||{};var elmt=getSVGElement(options.id,"rect");var attr=getOptions(["rx","ry"],options);elmt.node.setAttribute("x",toSVG(p)[0]);elmt.node.setAttribute("y",toSVG(q)[1]);elmt.node.setAttribute("width",(q[0]-p[0])*SVG.xunitlength);elmt.node.setAttribute("height",(q[1]-p[1])*SVG.yunitlength);elmt.node.setAttribute("rx",attr.rx*SVG.xunitlength);elmt.node.setAttribute("ry",attr.ry*SVG.yunitlength);setStrokeAndFill(elmt.node,options);appendSVG(elmt)}function text(p,st,options){options=options||{};var id=options.id;var fill=getOptions("fontfill",options);if(id&&options.isLabel){id+=options.isLabel}var pos=getOptions("pos",options).toUpperCase();var fontsize=getOptions("fontsize",options)/SVG.factor;var node,dx=0,dy=0,str=st.toString();var q=toSVG(p);if(/\$/.test(str)){if(p[0]>SVG.xmax||p[0]<SVG.xmin||p[1]>SVG.ymax||p[1]<SVG.ymin){return}var dnode=$("#"+SVG.id+"mml:first");if(id){node=$("#"+id)[0]}if(!node){node=MSVG.createElementXHTML("div",id);node.style.position="absolute";dnode.append(node)}else{$(node).empty()}str=$.trim(str);str=str.substr(1,str.length-2);$(node).append(MSVG.parseMath(str,true,fontsize+"px",fill));dx=-node.offsetWidth/2;dy=-node.offsetHeight/2;if(/N/.test(pos)){dy=-node.offsetHeight}if(/S/.test(pos)){dy=0}if(/E/.test(pos)){dx=0}if(/W/.test(pos)){dx=-node.offsetWidth}node.style.left=(q[0]+dx)+"px";node.style.top=(q[1]+dy)+"px"}else{var baseline="middle",textanchor="middle";if(/E/.test(pos)){textanchor="start"}if(/W/.test(pos)){textanchor="end"}if(/N/.test(pos)){baseline="text-after-edge"}if(/S/.test(pos)){baseline="text-before-edge"}var attr=getOptions(["fontstyle","fontfamily","fontweight"],options);var elmt=getSVGElement(id,"text");$(elmt.node).empty().text(str);elmt.node.setAttribute("x",q[0]);elmt.node.setAttribute("y",q[1]);elmt.node.setAttribute("font-style",attr.fontstyle);elmt.node.setAttribute("font-family",attr.fontfamily);elmt.node.setAttribute("font-weight",attr.fontweight);elmt.node.setAttribute("font-size",fontsize);elmt.node.setAttribute("text-anchor",textanchor);elmt.node.setAttribute("dominant-baseline",baseline);setStrokeAndFill(elmt.node,options,"font");appendSVG(elmt)}}function image(url,options){options=options||{};var elmt=getSVGElement(options.id,"image");var height=options.height||SVG.height;var width=options.width||SVG.width;var point=toSVG(options.point||[SVG.xmin,SVG.ymin]);var pos=(options.pos||"").toUpperCase();var x=point[0]-width*0.5;var y=point[1]-height*0.5;if(/N/.test(pos)){y-=height*0.5}if(/S/.test(pos)){y+=height*0.5}if(/E/.test(pos)){x+=width*0.5}if(/W/.test(pos)){x-=width*0.5}elmt.node.setAttribute("x",x);elmt.node.setAttribute("y",y);elmt.node.setAttribute("width",width);elmt.node.setAttribute("height",height);elmt.node.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",url);appendSVG(elmt)}function grid(options){options=options||{};var dx,dy,x,y,k;var orig=options.origin||[0,0];options.stroke=options.stroke||"grey";options.strokewidth=(options.strokewidth||SVG.attr.strokewidth*0.25)/SVG.factor;var lim=getScales(options.scales);lim[2]=lim[2]||SVG.ymin;lim[3]=lim[3]||SVG.ymax;var group=getSVGElement("Grid","g");$(group.node).empty();var tempNode=SVG.canvas;SVG.canvas=group.node;if(SVG.coords=="polar"){dx=options.dx||1;dy=options.dy||3;var limit=Math.max(Math.abs(lim[0]),Math.abs(lim[1]),Math.abs(lim[2]),Math.abs(lim[3]));for(x=dx;x<limit;x+=dx){circle(orig,x,options)}if(dy>1){for(y=1;y<dy;y++){k=Math.tan(y*Math.PI/(2*dy));line([lim[0],(lim[0]-orig[0])*k+orig[1]],[SVG.xmax,(lim[1]-orig[0])*k+orig[1]],options);line([lim[0],-(lim[0]-orig[0])*k+orig[1]],[SVG.xmax,-(lim[1]-orig[0])*k+orig[1]],options)}}}else{dx=options.dx||1;dy=options.dy||dx;for(x=orig[0];x<lim[1];x+=dx){line([x,lim[2]],[x,lim[3]],options)}for(x=orig[0]-dx;x>lim[0];x-=dx){line([x,lim[2]],[x,lim[3]],options)}for(y=orig[1];y<lim[3];y+=dy){line([lim[0],y],[lim[1],y],options)}for(y=orig[1]-dy;y>lim[2];y-=dy){line([lim[0],y],[lim[1],y],options)}}SVG.canvas=tempNode;appendSVG(group)}function axes(options){options=options||{};options.marker="-|"+(options.marker?options.marker.charAt(0):"-");var x,y,start,stop;var orig=options.origin||[0,0];var origin=toSVG(orig);var dx=options.dx||1;var dy=options.dy||dx;var fontsize=getOptions("fontsize",options);var ddx=Math.max(0,Math.floor(-Math.log(dx+1e-9)/Math.log(10))+1);var ddy=Math.max(0,Math.floor(-Math.log(dy+1e-9)/Math.log(10))+1);options.stroke=options.stroke||"black";options.strokewidth=options.strokewidth||SVG.attr.strokewidth*0.5;options.markerstroke=options.stroke;options.markerstrokewidth=2*options.strokewidth;options.units="strokeWidth";options.size=fontsize*SVG.factor;var lim=getScales(options.scales);lim[2]=lim[2]||SVG.ymin;lim[3]=lim[3]||SVG.ymax;var list1=[],label1=[];start=orig[0]+dx;stop=lim[1]-0.25*dx;for(x=start;x<stop;x+=dx){list1.push([x,orig[1]]);label1.push(String(x.toFixed(ddx)))}list1.push([lim[1],orig[1]]);label1.push("");var list2=[],label2=[];start=orig[0]-dx;stop=lim[0]+0.25*dx;for(x=start;x>stop;x-=dx){list2.push([x,orig[1]]);label2.push(String(x.toFixed(ddx)))}list2.push([lim[0],orig[1]]);label2.push("");list2.reverse();list2=list2.concat(list1);if(options.ticklabels!=false){label2.reverse();options.label=label2.concat(label1);options.pos=(SVG.height-origin[1]>2*fontsize)?"S":"N"}var group=getSVGElement("Axes","g");$(group.node).empty();var tempNode=SVG.canvas;SVG.canvas=group.node;path(list2,options);list1=[],label1=[];start=orig[1]+dy;stop=lim[3]-0.25*dy;for(y=start;y<stop;y+=dy){list1.push([orig[0],y]);label1.push(String(y.toFixed(ddy)))}list1.push([orig[0],lim[3]]);label1.push("");list2=[];label2=[];start=orig[1]-dy;stop=lim[2]+0.25*dy;for(y=start;y>stop;y-=dy){list2.push([orig[0],y]);label2.push(String(y.toFixed(ddy)))}list2.push([orig[0],lim[2]]);label2.push("");list2.reverse();list2=list2.concat(list1);if(options.ticklabels!=false){label2.reverse();options.label=label2.concat(label1);options.pos=(origin[0]>2*fontsize)?"W":"E"}options.stroke=options.markerstroke;path(list2,options);SVG.canvas=tempNode;appendSVG(group)}function list(fun,tmin,tmax,options){var inc=(tmax-tmin)/getOptions("points",options);if(inc<=0||fun.length==0){return}var t,pth,g=[],xt,yt;for(t=1;t>=0;t--){if($.isFunction(fun[t])){g[t]=fun[t]}else{if(typeof fun[t]=="string"){with(Math){eval("g["+t+"] = function(x){return "+fun[t]+"}")}}else{return}}}if(g.length<2){return}pth=[];for(t=tmin;t<=tmax;t+=inc){xt=g[0](t);yt=g[1](t);if(isFinite(xt)&&isFinite(yt)){pth[pth.length]=[xt,yt]}}return pth}function plot(fun,options){options=options||{};var i,steps=options.steps||[];if(steps.length===0){plotter(fun,options)}else{var leftMarkers=options.leftMarkers||"-";var rightMarkers=options.rightMarkers||"-";var n_steps=steps.length-1;options.max=steps[0];options.marker="--"+leftMarkers.charAt(0);plotter(fun,options);for(i=0;i<n_steps;i++){options.max=steps[i+1];options.min=steps[i];options.marker=rightMarkers.charAt((rightMarkers.length>i)?i:0)+"-"+leftMarkers.charAt((leftMarkers.length>i+1)?i+1:0);plotter(fun,options)}options.max=null;options.min=steps[n_steps];options.marker=rightMarkers.charAt((rightMarkers.length==n_steps)?n_steps-1:0)+"--";plotter(fun,options)}}function plotter(fun,options){options=options||{};options.closed=false;options.curve="";var xmin=(options.min==null)?SVG.xmin:options.min;var xmax=(options.max==null)?SVG.xmax:options.max;var pth=list(["x",fun],xmin,xmax,options);if(pth){path(pth,options)}}function area(fun1,fun2,options){options=options||{};options.curve="";options.closed=true;var xmin=(options.min==null)?SVG.xmin:options.min;var xmax=(options.max==null)?SVG.xmax:options.max;var pth1=list(["x",fun1],xmin,xmax,options);var pth2=list(["x",fun2],xmin,xmax,options);if(pth1&&pth2){pth2.reverse();pth1=pth1.concat(pth2);path(pth1,options)}}function polarPlot(fun,options){var g1,g2;if(typeof fun=="string"){with(Math){eval("g1 = function(x){return ("+fun+")*cos(x)}");eval("g2 = function(x){return ("+fun+")*sin(x)}")}}else{if($.isFunction(fun)){with(Math){eval("g1 = function(x){return fun(x)*cos(x)}");eval("g2 = function(x){return fun(x)*sin(x)}")}}}parametricPlot(g1,g2,options)}function parametricPlot(fun1,fun2,options){options=options||{};options.closed=false;options.curve="";var xmin=(options.min==null)?0:options.min;var xmax=(options.max==null)?2*Math.PI:options.max;var pth=list([fun1,fun2],xmin,xmax,options);if(pth){path(pth,options)}}function slopeField(fun,options){options=options||{};var g=fun;if(typeof fun=="string"){with(Math){eval("g = function(x,y){return "+fun+"}")}}var gxy,x,y,u,v,dz;var dx=(options.dx==null)?1:options.dx;var dy=(options.dy==null)?1:options.dy;dz=Math.sqrt(dx*dx+dy*dy)/6;var xmin=Math.ceil(SVG.xmin/dx);var ymin=Math.ceil(SVG.ymin/dy);for(x=xmin;x<=SVG.xmax;x+=dx){for(y=ymin;y<=SVG.ymax;y+=dy){gxy=g(x,y);if(!isNaN(gxy)){if(Math.abs(gxy)=="Infinity"){u=0;v=dz}else{u=dz/Math.sqrt(1+gxy*gxy);v=gxy*u}line([x-u,y-v],[x+u,y+v],options)}}}}return{dynamic:{},removePictures:function(obj){var pictures=obj?[obj]:$(".svgGraph");$(pictures).each(function(){var target=this.parentNode;$(this).remove();$(target).css({color:"red",background:"yellow"});$(target).text("Missing picture: your browser does not support inline SVG");window.setTimeout(function(){$(target).remove()},10000)})},drawPictures:function(obj){var options,xmin,xmax,ymin,ymax;var pictures=obj?[obj]:$(".svgGraph");$(pictures).each(function(){SVG=new pictureObject();options=this.getAttribute("options");if(options!=""){with(Math){eval("options="+options)}setOptions(options)}else{options={}}SVG.pos=options.pos||SVG.pos;if(SVG.pos=="inline"){$(this).wrap("<span></span>")}else{$(this).wrap("<div></div>")}SVG.width=options.width||SVG.width;SVG.height=options.height||SVG.height;SVG.coords=options.coords||SVG.coords;SVG.border=options.borderwidth||SVG.border;var borderstroke=options.borderstroke||"black";var borderstyle=options.borderstyle||"solid";if(options.pan==false){SVG.pan=false}SVG.src=this.getAttribute("script");var container=this.parentNode;switch(SVG.pos){case"left":$(container).css("float","left");break;case"right":$(container).css("float","right");break;case"center":$(container).css("margin","auto auto")}$(container).css("border",SVG.border+"px "+borderstyle+" "+borderstroke);container.removeChild(this);var scales=getScales(options.scales);SVG.xmin=scales[0];SVG.xmax=scales[1];SVG.ymin=scales[2];SVG.ymax=scales[3];if(SVG.xmin>=SVG.xmax){throw"Incorrect values: xmax<=xmin."}var xunitlength=SVG.width/(SVG.xmax-SVG.xmin);if(typeof SVG.ymin!="number"){SVG.ymin=-SVG.height/(2*xunitlength);SVG.ymax=-SVG.ymin}else{if(SVG.ymin>=SVG.ymax){throw"Incorrect values: ymax<=ymin."}}setScales();SVG.id=Math.randomString(16);var qnode=createSVGElement("svg");qnode.id=SVG.id;qnode.setAttribute("xmlns","http://www.w3.org/2000/svg");var node=createSVGElement("clipPath");node.id=SVG.id+"ClipPath";var node2=createSVGElement("path");$(node).append(node2);node2=createSVGElement("defs");node2.id=SVG.id+"_Defs";$(node2).append(node);$(qnode).append(node2);node=createSVGElement("rect");node.setAttribute("class","svgBackground");node.setAttribute("x","0");node.setAttribute("y","0");node.setAttribute("width","100%");node.setAttribute("height","100%");node.setAttribute("fill",SVG.attr.backgroundcolor);node.setAttribute("fill-opacity",SVG.attr.backgroundopacity);$(qnode).append(node);node=createSVGElement("g");node.id=SVG.id+"Canvas";node.setAttribute("clip-path","url(#"+SVG.id+"ClipPath)");SVG.canvas=node;$(qnode).append(node);if(SVG.coords!="none"&&SVG.pos!="inline"){node=createSVGElement("text");node.id=SVG.id+"Coords";node.setAttribute("class","svgCoords");node.setAttribute("text-anchor","end");node.setAttribute("font-size",(SVG.attr.fontsize*0.8));$(qnode).append(node)}$(container).append(qnode);container.style.position="relative";node=MSVG.createElementXHTML("span",SVG.id+"mml");$(container).append(node);if(SVG.pos!="inline"){node=MSVG.createElementXHTML("span",SVG.id+"toolbar");node.style.position="absolute";node.style.textAlign="left";node.style.zIndex=10;node2=setButton("Update","Edit script",function(){updateButton(this)});$(node).append(node2);node2=setButton("SVG","View SVG code",function(){exportSVG(this)});$(node).append(node2);node2=setButton("-","Zoom out",function(){changeScales(1.25)});$(node).append(node2);node2=setButton("+","Zoom in",function(){changeScales(0.8)});$(node).append(node2);node2=setButton("\u2191","Enlarge picture",function(){changeSize(0.8)});$(node).append(node2);node2=setButton("\u2193","Reduce picture",function(){changeSize(1.25)});$(node).append(node2);$(node).append("<br />");node2=MSVG.createElementXHTML("textarea",SVG.id+"src");$(node2).attr({rows:8,cols:80});$(node).append(node2);$(node).hide();$(container).append(node);setAction("mousemove",updateCoord);setAction("mouseout",removeCoord);setAction("mousedown",onClick);if(SVG.pan){setAction("mouseup",onDrop)}if(window.addEventListener){var evt=$.browser.mozilla?"DOMMouseScroll":"mousewheel";qnode.addEventListener(evt,onWheel,false)}}setAction("mouseover",switchTo);setSize();translateAndEval(SVG.id)})}}}(jQuery);
//}}}
/***
!~TiddlyWiki formatters
***/
//{{{
if(!version.extensions.MathSVGPlugin) { //# ensure that the plugin is only installed once
version.extensions.MathSVGPlugin = {installed: true};
MSVG.generic();
config.formatterHelpers.MathSVGHelper = function(w) {
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch){
var eq = MSVG.parseMath(lookaheadMatch[1],this.displaystyle);
if(this.displaystyle){
var node = createTiddlyElement(w.output,"div");
node.style.textAlign='center';
node.appendChild(eq);
w.output.appendChild(node);
} else {w.output.appendChild(eq);}
w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
}
}
config.formatters.push( {
name: "clatex",
match: "\\$\\$",
lookaheadRegExp: /\$\$((?:.|\n)*?)\$\$/mg,
displaystyle: true,
handler: config.formatterHelpers.MathSVGHelper
})
config.formatters.push( {
name: "clatex2",
match: "\\\\\\\[",
lookaheadRegExp: /\\\[\s*(.*?)\s*\\\]/mg,
displaystyle: true,
handler: config.formatterHelpers.MathSVGHelper
})
config.formatters.push( {
name: "latex",
match: "\\$",
lookaheadRegExp: /\$((?:.|\n)*?)\$/mg,
displaystyle: false,
handler: config.formatterHelpers.MathSVGHelper
})
config.formatters.push( {
name: "graph",
match: "\\(:graph",
lookaheadRegExp: /\(:graph(?:\((\{.+?\})?\))?[\s]+((?:.|\n)*?)[\s]+:\)/mg,
handler: function(w){
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch){
var svg = createTiddlyElement(w.output,"embed");
svg.className="svgGraph";
svg.setAttribute('options',lookaheadMatch[1]||"");
svg.setAttribute('script',lookaheadMatch[2]);
ASVG.drawPictures(svg);
w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
}
}
})
}
//}}}
/***
|''Name:''|WikiBar|
|''Version:''|2.0.0 beta3|
|''Source:''|[[AiddlyWiki|http://aiddlywiki.sourceforge.net]]|
|''Author:''|[[Arphen Lin|mailto:arphenlin@gmail.com]]|
|''Type:''|toolbar macro command extension|
|''Required:''|TiddlyWiki 2.0.0 beta6|
!Description
WikiBar is a toolbar that gives access to most of TiddlyWiki's formatting features with a few clicks. It's a handy tool for people who are not familiar with TiddlyWiki syntax.
Besides, with WikiBar-addons, users can extend the power of WikiBar.
!Support browser
*Firefox 1.5
!Revision history
*v2.0.0 beta3 (2005/12/30)
** remove macros (replaced by TWMacro addon)
** add wikibar command in toolbar automatically
** rename DOIT to HANDLER
** rename TIP to TOOLTIP
*v2.0.0 beta2 (2005/12/21)
** re-design Wikibar addon framework
*v2.0.0 beta1 (2005/12/14)
** Note:
*** WikiBarPlugin is renamed to WikiBar
** New Features:
*** support TiddlyWiki 2.0.0 template mechanism
*** new wikibar data structure
*** new wikibar-addon framework for developers
**** support dynamic popup menu generator
*** support most new macros added in TiddlyWiki 2.0.0
*** multi-level popup menu
*** fix wikibar tab stop
*** remove paletteSelector
** Known Bugs:
*** popup-menu and color-picker can't be closed correctly
*** some macros can't be displayed correctly in previewer
*** text in previewer will be displayed italic
*v1.2.0 (2005/11/21)
**New Features:
***User defined color palettes supported
####Get color palettes from [[ColorZilla Palettes|http://www.iosart.com/firefox/colorzilla/palettes.html]].
####Save the palette file(*.gpl) as a new tiddler and tag it with 'ColorPalettes', then you can use it in WikiBar.
***WikiBar style sheet supported
***Click on document to close current colorPicker, paletteSelector or aboutWikibar
*v1.1.1 (2005/11/03)
**Bugs fixed:
***'Not enough parameters!' message is displayed when the parameter includes '%+number', ex: 'hello%20world!'
*v1.1.0 (2005/11/01)
**Bugs fixed:
***WikiBar overruns (reported by by GeoffS <gslocock@yahoo.co.uk>)
**New features:
***Insert a color code at the cursor. (Thanks to RunningUtes <RunningUtes@gmail.com>)
***Enable gradient macro. (Thanks to RunningUtes <RunningUtes@gmail.com>)
***Insert tiddler comment tags {{{/% ... %/}}}. (new feature supported by TiddlyWiki 1.2.37)
***Insert DateFormatString for {{{<<today>>}}} macro. (new feature supported by TiddlyWiki 1.2.37)
**Enhanced:
***Allow optional parameters in syntax.
**Bugs:
***'Not enough parameters!' message is displayed when the parameter includes '%+number', ex: 'hello%20world!'
*v1.0.0 (2005/10/30)
**Initial release
!Code
***/
//{{{
config.macros.wikibar = {major: 2, minor: 0, revision: 0, beta: 3, date: new Date(2005,12,30)};
config.macros.wikibar.handler = function(place,macroName,params,wikifier,paramString,tiddler){
if(!(tiddler instanceof Tiddler)) {return;}
story.setDirty(tiddler.title,true);
place.id = 'wikibar'+tiddler.title;
place.className = 'toolbar wikibar';
};
function wikibar_install(){
config.commands.wikibar = {
text: 'wikibar',
tooltip: 'wikibar on/off',
handler: function(e,src,title) {
if(!e){ e = window.event; }
var theButton = resolveTarget(e);
theButton.id = 'wikibarButton'+title;
wikibarPopup.remove();
wikibar_installAddons(theButton, title);
wikibar_createWikibar(title);
return(false);
}
};
config.shadowTiddlers['EditTemplate'] = wikibar_addWikibarCommand(config.shadowTiddlers['EditTemplate']);
var tiddler = store.getTiddler('EditTemplate');
if(tiddler){
tiddler.text = wikibar_addWikibarCommand(tiddler.text);
}
}
function wikibar_installAddons(theButton, title){
var tiddlers = store.getTaggedTiddlers('wikibarAddons');
if(!tiddlers) { return; }
theButton.addons=[];
for(var i=0; i<tiddlers.length; i++){
try{
eval(tiddlers[i].text);
try{
wikibar_addonInstall(title);
wikibar_addonInstall = null;
theButton.addons.push({ok:true, name:tiddlers[i].title});
}catch(ex){
theButton.addons.push({ok:false, name:tiddlers[i].title, error:ex});
}
}catch(ex){
theButton.addons.push({ok:false, name:tiddlers[i].title, error:ex});
}
}
}
function wikibar_addWikibarCommand(tiddlerText){
var div = document.createElement('div');
div.style.display = 'none';
div.innerHTML = tiddlerText;
for(var i=0; i<div.childNodes.length; i++){
var o=div.childNodes[i];
if(o.tagName==='DIV'){
if(o.className=='toolbar'){
var macroText = o.getAttribute('macro').trim();
if(macroText.search('wikibar')<=0){
macroText += ' wikibar';
o.setAttribute('macro', macroText);
}
break;
}
}
}
return div.innerHTML.replace(/\"/g, "\'");
}
function wikibar_processSyntaxParams(theSyntax, params){
try{
var pcr = 'AplWikibarPcr';
var rx=null;
var allParams=null;
if(params){
if(typeof(params)=='object'){
for(var i=0; i<params.length; i++){
if(params[i]){
params[i] = params[i].replace(new RegExp('%','g'), pcr).trim();
rx = '(\\[%'+(i+1)+'\\])' + '|' + '(%'+(i+1)+')';
theSyntax = theSyntax.replace(new RegExp(rx,'g'), params[i] );
}
}
allParams = params.join(' ').trim();
}else{
allParams = params.replace(new RegExp('%','g'), pcr).trim();
rx = /(\[%1{1}\])|(%1{1})/g;
theSyntax = theSyntax.replace(rx, allParams);
}
}
if(allParams){
theSyntax = theSyntax.replace(new RegExp('%N{1}','g'), allParams);
}
rx=/\[%(([1-9]{1,}[0-9]{0,})|(N{1}))\]/g;
theSyntax = theSyntax.replace(rx, '');
rx=/%(([1-9]{1,}[0-9]{0,})|(N{1}))/g;
if( theSyntax.match(rx) ){
throw 'Not enough parameters! ' + theSyntax;
}
theSyntax=theSyntax.replace(new RegExp(pcr,'g'), '%');
return theSyntax;
} catch(ex){
return null;
}
}
function wikibar_resolveEditItem(tiddlerWrapper, itemName){
if(tiddlerWrapper.hasChildNodes()){
var c=tiddlerWrapper.childNodes;
for(var i=0; i<c.length; i++){
var txt=wikibar_resolveEditItem(c[i], itemName);
if(!txt){
continue;
}else{
return txt;
}
}
}
return ((tiddlerWrapper.getAttribute && tiddlerWrapper.getAttribute('edit')==itemName)? tiddlerWrapper : null);
}
function wikibar_resolveEditItemValue(tiddlerWrapper, itemName){
var o = wikibar_resolveEditItem(tiddlerWrapper, itemName);
return (o? o.value.replace(/\r/mg,'') : null);
}
function wikibar_resolveTiddlerEditorWrapper(obj){
if(obj.id=='tiddlerDisplay'){return null;}
if((obj.getAttribute && obj.getAttribute('macro')=='edit text')){return obj;}
return wikibar_resolveTiddlerEditorWrapper(obj.parentNode);
}
function wikibar_resolveTiddlerEditor(obj){
if(obj.hasChildNodes()){
var c = obj.childNodes;
for(var i=0; i<c.length; i++){
var o=wikibar_resolveTiddlerEditor(c[i]);
if(o){ return o;}
}
}
return ((obj.getAttribute && obj.getAttribute('edit')=='text')? obj : null);
}
function wikibar_resolveTargetButton(obj){
if(obj.id && obj.id.substring(0,7)=='wikibar'){ return null; }
if(obj.tiddlerTitle){
return obj;
}else{
return wikibar_resolveTargetButton(obj.parentNode);
}
}
function wikibar_isValidMenuItem(tool){
if(!tool){ return false; }
if(tool.TYPE=='MENU' || tool.TYPE=='MAIN_MENU'){
for(var key in tool){
if(key.substring(0,8)=='DYNAITEM'){ return true; }
if(wikibar_isValidMenuItem(tool[key])){ return true; }
}
return false;
}else{
return (tool.HANDLER? true : false);
}
}
function wikibar_editFormat(param){
var editor = param.button.editor;
var params = param.params;
clearMessage();
if(!editor){ return; }
var repText = wikibar_processSyntaxParams(this.syntax, params);
if(repText===null){ return; }
var st = editor.scrollTop;
var ss = editor.selectionStart;
var se = editor.selectionEnd;
var frontText= '';
var endText = '';
var fullText = editor.value;
if(se>ss && ss>=0){
frontText = fullText.substring(0, ss);
endText = fullText.substring(se, fullText.length);
}
else if(ss===0 && (se===0 || se == fullText.length) ){
endText = fullText;
}
else if(se==ss && ss>0){
frontText = fullText.substring(0, ss);
endText = fullText.substring(se, fullText.length);
}
if(repText.indexOf('user_text')>=0 && this.hint){
repText = repText.replace('user_text', this.hint);
}
editor.value = frontText + repText + endText;
editor.selectionStart = ss;
editor.selectionEnd = ss + repText.length;
editor.scrollTop = st;
editor.focus();
}
function wikibar_editFormatByWord(param){
var editor = param.button.editor;
var params = param.params;
clearMessage();
if(!editor){return;}
var repText = wikibar_processSyntaxParams(this.syntax, params);
if(repText===null){ return; }
var st = editor.scrollTop;
var ss = editor.selectionStart;
var se = editor.selectionEnd;
var frontText= '';
var selText = '';
var endText = '';
var fullText = editor.value;
if(se>ss && ss>=0){
frontText = fullText.substring(0, ss);
selText = fullText.substring(ss,se);
endText = fullText.substring(se, fullText.length);
}
else if(ss===0 && (se===0 || se == fullText.length) ){
endText = fullText;
}
else if(se==ss && ss>0){
frontText = fullText.substring(0, ss);
endText = fullText.substring(se, fullText.length);
if(!( fullText.charAt(ss-1).match(/\W/gi) || fullText.charAt(ss).match(/\W/gi) )){
var m = frontText.match(/\W/gi);
if(m){
ss = frontText.lastIndexOf(m[m.length-1])+1;
}
else{
ss = 0;
}
m = endText.match(/\W/gi);
if(m){
se += endText.indexOf(m[0]);
}
else{
se = fullText.length;
}
frontText = fullText.substring(0, ss);
endText = fullText.substring(se, fullText.length);
selText = fullText.substring(ss,se);
}
}
if(selText.length>0){
repText = repText.replace('user_text', selText);
}
if(repText.indexOf('user_text')>=0 && this.hint){
repText = repText.replace('user_text', this.hint);
}
editor.value = frontText + repText + endText;
editor.selectionStart = ss;
editor.selectionEnd = ss + repText.length;
editor.scrollTop = st;
editor.focus();
}
function wikibar_editFormatByCursor(param){
var editor = param.button.editor;
var params = param.params;
clearMessage();
if(!editor){ return; }
var repText = wikibar_processSyntaxParams(this.syntax, params);
if(repText===null){ return; }
var st = editor.scrollTop;
var ss = editor.selectionStart;
var se = editor.selectionEnd;
var frontText= '';
var endText = '';
var fullText = editor.value;
if(se>ss && ss>=0){
frontText = fullText.substring(0, ss);
endText = fullText.substring(se, fullText.length);
}
else if(ss===0 && (se===0 || se == fullText.length) ){
endText = fullText;
}
else if(se==ss && ss>0){
frontText = fullText.substring(0, ss);
endText = fullText.substring(se, fullText.length);
}
if(repText.indexOf('user_text')>=0 && this.hint){
repText = repText.replace('user_text', this.hint);
}
editor.value = frontText + repText + endText;
editor.selectionStart = ss;
editor.selectionEnd = ss + repText.length;
editor.scrollTop = st;
editor.focus();
}
function wikibar_editFormatByLine(param){
var editor = param.button.editor;
var params = param.params;
clearMessage();
if(!editor){ return; }
var repText = wikibar_processSyntaxParams(this.syntax, params);
if(repText===null){ return; }
var st = editor.scrollTop;
var ss = editor.selectionStart;
var se = editor.selectionEnd;
var frontText= '';
var selText = '';
var endText = '';
var fullText = editor.value;
if(se>ss && ss>=0){
if(this.byBlock){
frontText = fullText.substring(0, ss);
selText = fullText.substring(ss,se);
endText = fullText.substring(se, fullText.length);
}
else{
se = ss;
}
}
if(ss===0 && (se===0 || se == fullText.length) ){
var m=fullText.match(/(\n|\r)/g);
if(m){
se = fullText.indexOf(m[0]);
}else{
se = fullText.length;
}
selText = fullText.substring(0, se);
endText = fullText.substring(se, fullText.length);
}
else if(se==ss && ss>0){
frontText = fullText.substring(0, ss);
endText = fullText.substring(se, fullText.length);
m = frontText.match(/(\n|\r)/g);
if(m){
ss = frontText.lastIndexOf(m[m.length-1])+1;
}
else{
ss = 0;
}
m = endText.match(/(\n|\r)/g);
if(m){
se += endText.indexOf(m[0]);
}
else{
se = fullText.length;
}
frontText = fullText.substring(0, ss);
selText = fullText.substring(ss,se);
endText = fullText.substring(se, fullText.length);
}
if(selText.length>0){
repText = repText.replace('user_text', selText);
}
if(repText.indexOf('user_text')>=0 && this.hint){
repText = repText.replace('user_text', this.hint);
}
if(this.byBlock){
if( (frontText.charAt(frontText.length-1)!='\n') && ss>0 ){
repText = '\n' + repText;
}
if( (endText.charAt(0)!='\n') || se==fullText.length){
repText += '\n';
}
}
editor.value = frontText + repText + endText;
editor.selectionStart = ss;
editor.selectionEnd = ss + repText.length;
editor.scrollTop = st;
editor.focus();
}
function wikibar_editFormatByTableCell(param){
var editor = param.button.editor;
var params = param.params;
clearMessage();
if(!editor){ return; }
var repText = wikibar_processSyntaxParams(this.syntax, params);
if(repText===null){ return; }
var st = editor.scrollTop;
var ss = editor.selectionStart;
var se = editor.selectionEnd;
var frontText= '';
var selText = '';
var endText = '';
var fullText = editor.value;
if(ss===0 || ss==fullText.length){
throw 'not valid cell!';
}
se=ss;
frontText = fullText.substring(0, ss);
endText = fullText.substring(se, fullText.length);
i=frontText.lastIndexOf('\n');
j=frontText.lastIndexOf('|');
if(i>j || j<0){
throw 'not valid cell!';
}
ss = j+1;
i=endText.indexOf('\n');
j=endText.indexOf('|');
if(i<j || j<0){
throw 'not valid cell!';
}
se += j;
frontText = fullText.substring(0, ss-1);
selText = fullText.substring(ss,se);
endText = fullText.substring(se+1, fullText.length);
if(this.key.substring(0,5)=='align'){
selText = selText.trim();
if( selText=='>' || selText=='~' || selText.substring(0,8)=='bgcolor(') {return; }
}
if(selText.length>0){
repText = repText.replace('user_text', selText);
}
if(repText.indexOf('user_text')>=0 && this.hint){
repText = repText.replace('user_text', this.hint);
}
editor.value = frontText + repText + endText;
editor.selectionStart = ss;
editor.selectionEnd = ss + repText.length - 2;
editor.scrollTop = st;
editor.focus();
}
function wikibar_editSelectAll(param){
var editor = param.button.editor;
editor.selectionStart = 0;
editor.selectionEnd = editor.value.length;
editor.scrollTop = 0;
editor.focus();
}
function wikibar_doPreview(param){
var theButton = param.button;
var editor = param.button.editor;
var wikibar = theButton.parentNode;
if(!wikibar) { return; }
title = theButton.tiddlerTitle;
var editorWrapper = wikibar_resolveTiddlerEditorWrapper(editor);
var tiddlerWrapper = editorWrapper.parentNode;
var previewer = document.getElementById('previewer'+title);
if(previewer){
previewer.parentNode.removeChild(previewer);
editorWrapper.style.display = 'block';
visible=true;
}else{
previewer = document.createElement('div');
previewer.id = 'previewer'+title;
previewer.className = 'viewer previewer';
previewer.style.height = (editor.offsetHeight) + 'px';
wikify(editor.value, previewer);
tiddlerWrapper.insertBefore(previewer, editorWrapper);
editorWrapper.style.display = 'none';
visible=false;
}
var pv=null;
for(var i=0; i<wikibar.childNodes.length; i++){
try{
var btn = wikibar.childNodes[i];
if(btn.toolItem.key == 'preview'){ pv=btn; }
if(btn.toolItem.key != 'preview'){
btn.style.display = visible ? '': 'none';
}
}catch(ex){}
}
if(!pv) { return; }
if(visible){
pv.innerHTML = '<font face=\"verdana\">∞</font>';
pv.title = 'preview current tiddler';
}
else{
pv.innerHTML = '<font face=\"verdana\">←</font>';
pv.title = 'back to editor';
}
}
function wikibar_doListAddons(param){
clearMessage();
var title = param.button.tiddlerTitle;
var wikibarButton = document.getElementById('wikibarButton'+title);
var ok=0, fail=0;
for(var i=0; i<wikibarButton.addons.length; i++){
var addon=wikibarButton.addons[i];
if(addon.ok){
displayMessage('[ o ] '+addon.name);
ok++;
}
else{
displayMessage('[ x ] '+addon.name + ': ' + addon.error);
fail++;
}
}
displayMessage('---------------------------------');
displayMessage(ok + ' ok ; ' + fail + ' failed');
}
function wikibar_getColorCode(param){
var cbOnPickColor = function(colorCode, param){
param.params = colorCode;
param.button.toolItem.doMore(param);
};
wikibarColorTool.openColorPicker(param.button, cbOnPickColor, param);
}
function wikibar_getLinkUrl(param){
var url= prompt('Please enter the link target', (this.param? this.param : ''));
if (url && url.trim().length>0){
param.params = url;
this.doMore(param);
}
}
function wikibar_getTableRowCol(param){
var rc= prompt('Please enter (rows x cols) of the table', '2 x 3');
if (!rc || (rc.trim()).length<=0){ return; }
var arr = rc.toUpperCase().split('X');
if(arr.length != 2) { return; }
for(var i=0; i<arr.length; i++){
if(isNaN(arr[i].trim())) { return; }
}
var rows = parseInt(arr[0].trim(), 10);
var cols = parseInt(arr[1].trim(), 10);
var txtTable='';
for(var r=0; r<rows; r++){
for(var c=0; c<=cols; c++){
if(c===0){
txtTable += '|';
}else{
txtTable += ' |';
}
}
txtTable += '\n';
}
if(txtTable.trim().length>0){
param.params = txtTable.trim();
this.doMore(param);
}
}
function wikibar_getMacroParam(param){
var p = prompt('Please enter the parameters of macro \"' + this.key + '\":' +
'\nSyntax: ' + this.syntax +
'\n\nNote: '+
'\n%1,%2,... - parameter needed'+
'\n[%1] - optional parameter'+
'\n%N - more than one parameter(1~n)'+
'\n[%N] - any number of parameters(0~n)'+
'\n\nPS:'+
'\n1. Parameters should be seperated with space character'+
'\n2. Use \" to wrap the parameter that includes space character, ex: \"hello world\"'+
'\n3. Input the word(null) for the optional parameter ignored',
(this.param? this.param : '') );
if(!p) { return; }
p=p.readMacroParams();
for(var i=0; i<p.length; i++){
var s=p[i].trim();
if(s.indexOf(' ')>0){ p[i]="'"+s+"'"; }
if(s.toLowerCase()=='null'){ p[i]=null; }
}
param.params = p;
this.doMore(param);
}
function wikibar_getMorePalette(unused){
clearMessage();
displayMessage('Get more color palettes(*.gpl) from ColorZilla Palettes site', 'http:\/\/www.iosart.com/firefox/colorzilla/palettes.html');
displayMessage('Save it as a new tiddler with \"ColorPalettes\" tag');
}
function wikibar_createWikibar(title){
var theWikibar = document.getElementById('wikibar' + title);
if(theWikibar){
if(theWikibar.hasChildNodes()){
theWikibar.style.display = (theWikibar.style.display=='block'? 'none':'block');
return;
}
}
var tiddlerWrapper = document.getElementById('tiddler'+title);
var theTextarea = wikibar_resolveTiddlerEditor(tiddlerWrapper);
if(!theTextarea){
clearMessage();
displayMessage('WikiBar only works in tiddler edit mode now');
return;
}else{
if(!theTextarea.id){ theTextarea.id = 'editor'+title; }
if(!theTextarea.parentNode.id){ theTextarea.parentNode.id='editorWrapper'+title; }
}
if(theWikibar){
theWikibar = document.getElementById('wikibar'+title);
}else{
var editorWrapper = wikibar_resolveTiddlerEditorWrapper(theTextarea);
theWikibar = createTiddlyElement(tiddlerWrapper, 'div', 'wikibar'+title, 'toolbar');
addClass(theWikibar, 'wikibar');
var previewer = document.getElementById('previewer'+title);
if(previewer){
tiddlerWrapper.insertBefore(theWikibar, previewer);
}else{
tiddlerWrapper.insertBefore(theWikibar, editorWrapper);
}
}
wikibar_createMenu(theWikibar,wikibarStore,title,theTextarea);
if(config.options['chkWikibarSetEditorHeight'] && config.options['txtWikibarEditorRows']){
theTextarea.rows = config.options['txtWikibarEditorRows'];
}
setStylesheet(
'.wikibar{text-align:left;visibility:visible;margin:2px;padding:1px;}.previewer{overflow:auto;display:block;border:1px solid;}#colorPicker{position:absolute;display:none;z-index:10;margin:0px;padding:0px;}#colorPicker table{margin:0px;padding:0px;border:2px solid #000;border-spacing:0px;border-collapse:collapse;}#colorPicker td{margin:0px;padding:0px;border:1px solid;font-size:11px;text-align:center;cursor:auto;}#colorPicker .header{background-color:#fff;}#colorPicker .button{background-color:#fff;cursor:pointer;cursor:hand;}#colorPicker .button:hover{padding-top:3px;padding-bottom:3px;color:#fff;background-color:#136;}#colorPicker .cell{padding:4px;font-size:7px;cursor:crosshair;}#colorPicker .cell:hover{padding:10px;}.wikibarPopup{position:absolute;z-index:10;border:1px solid #014;color:#014;background-color:#cef;}.wikibarPopup table{margin:0;padding:0;border:0;border-spacing:0;border-collapse:collapse;}.wikibarPopup .button:hover{color:#eee;background-color:#014;}.wikibarPopup .disabled{color:#888;}.wikibarPopup .disabled:hover{color:#888;background-color:#cef;}.wikibarPopup tr .seperator hr{margin:0;padding:0;background-color:#cef;width:100%;border:0;border-top:1px dashed #014;}.wikibarPopup tr .icon{font-family:verdana;font-weight:bolder;}.wikibarPopup tr .marker{font-family:verdana;font-weight:bolder;}.wikibarPopup td{font-size:0.9em;padding:2px;}.wikibarPopup input{border:0;border-bottom:1px solid #014;margin:0;padding:0;font-family:arial;font-size:100%;background-color:#fff;}',
'WikiBarStyleSheet');
}
function wikibar_createMenu(place,toolset,title,editor){
if(!wikibar_isValidMenuItem(toolset)){return;}
if(!(toolset.TYPE=='MAIN_MENU' || toolset.TYPE=='MENU')){ return; }
for(var key in toolset){
if(key.substring(0,9)=='SEPERATOR'){
wikibar_createMenuSeperator(place);
continue;
}
if(key.substring(0,8)=='DYNAITEM'){
var dynaTools = toolset[key](title,editor);
if(dynaTools.TYPE && dynaTools.TYPE=='MENU'){
wikibar_createMenuItem(place,dynaTools,null,editor,title);
}else{
dynaTools.TYPE = 'MENU';
wikibar_createMenu(place, dynaTools, title, editor);
}
continue;
}
if((toolset[key].TYPE!='MENU' && toolset[key].TYPE!='MAIN_MENU') && !toolset[key].HANDLER){continue;}
wikibar_createMenuItem(place,toolset,key,editor,title);
}
}
function wikibar_createMenuItem(place,toolset,key,editor,title){
if(!key){
var tool = toolset;
}else{
tool = toolset[key];
tool.key = key;
}
if(!wikibar_isValidMenuItem(tool)){return;}
var toolIsOnMainMenu = (toolset.TYPE=='MAIN_MENU');
var toolIsMenu = (tool.TYPE=='MENU');
var theButton;
if(toolIsOnMainMenu){
theButton = createTiddlyButton(
place,
'',
(tool.TOOLTIP? tool.TOOLTIP : ''),
(toolIsMenu? wikibar_onClickMenuItem : wikibar_onClickItem),
'button');
theButton.innerHTML = (tool.CAPTION? tool.CAPTION : key);
theButton.isOnMainMenu = true;
addClass(theButton, (toolIsMenu? 'menu' : 'item'));
place.appendChild( document.createTextNode('\n') );
if(!toolIsMenu){
if(config.options['chkWikibarPopmenuOnMouseOver']){
theButton.onmouseover = function(e){ wikibarPopup.remove(); };
}
}
}else{
theButton=createTiddlyElement(place, 'tr',key,'button');
theButton.title = (tool.TOOLTIP? tool.TOOLTIP : '');
theButton.onclick = (toolIsMenu? wikibar_onClickMenuItem : wikibar_onClickItem);
var tdL = createTiddlyElement(theButton, 'td','','marker');
var td = createTiddlyElement(theButton, 'td');
var tdR = createTiddlyElement(theButton, 'td','','marker');
td.innerHTML = (tool.CAPTION? tool.CAPTION : key);
if(toolIsMenu){
tdR.innerHTML=' ›';
}
if(tool.SELECTED){
tdL.innerHTML = '√ ';
addClass(theButton, 'selected');
}
if(tool.DISABLED){
addClass(theButton, 'disabled');
}
}
theButton.tiddlerTitle = title;
theButton.toolItem = tool;
theButton.editor = editor;
theButton.tabIndex = 999;
if(toolIsMenu){
if(config.options['chkWikibarPopmenuOnMouseOver']){
theButton.onmouseover = wikibar_onClickMenuItem;
}
}
}
function wikibar_createMenuSeperator(place){
if(place.id.substring(0,7)=='wikibar') { return; }
var onclickSeperator=function(e){
if(!e){ e = window.event; }
e.cancelBubble = true;
if (e.stopPropagation){ e.stopPropagation(); }
return(false);
};
var theButton=createTiddlyElement(place,'tr','','seperator');
var td = createTiddlyElement(theButton, 'td','','seperator');
td.colSpan=3;
theButton.onclick=onclickSeperator;
td.innerHTML = '<hr>';
}
function wikibar_genWikibarAbout(){
var toolset={};
toolset.version = {
CAPTION: '<center>WikiBar ' +
config.macros.wikibar.major + '.' +
config.macros.wikibar.minor + '.' +
config.macros.wikibar.revision +
(config.macros.wikibar.beta? ' beta '+config.macros.wikibar.beta : '') +
'</center>',
HANDLER: function(){}
};
toolset.SEPERATOR = {};
toolset.author = {
CAPTION: '<center>Arphen Lin<br>arphenlin@gmail.com</center>',
TOOLTIP: 'send mail to the author',
HANDLER: function(){ window.open('mailto:arphenlin@gmail.com'); }
};
toolset.website = {
CAPTION: '<center>aiddlywiki.sourceforge.net</center>',
TOOLTIP: 'go to the web site of WikiBar',
HANDLER: function(){ window.open('http:\/\/aiddlywiki.sourceforge.net/'); }
};
return toolset;
}
function wikibar_genWikibarOptions(title, editor){
var toolset={};
toolset.popOnMouseOver = {
CAPTION:'popup menu on mouse over',
SELECTED: config.options['chkWikibarPopmenuOnMouseOver'],
HANDLER: function(param){
config.options['chkWikibarPopmenuOnMouseOver'] = !config.options['chkWikibarPopmenuOnMouseOver'];
saveOptionCookie('chkWikibarPopmenuOnMouseOver');
var title = param.button.tiddlerTitle;
var wikibar = document.getElementById('wikibar'+title);
if(wikibar){ wikibar.parentNode.removeChild(wikibar); }
wikibar_createWikibar(title);
}
};
toolset.setEditorSize = {
CAPTION:'set editor height: <input id=\"txtWikibarEditorRows\" type=text size=1 MAXLENGTH=3 value=\"' +
(config.options['txtWikibarEditorRows']? config.options['txtWikibarEditorRows']:editor.rows) + '\"> ok',
HANDLER: function(param){
var input = document.getElementById('txtWikibarEditorRows');
if(input){
var rows = parseInt(input.value, 10);
if(!isNaN(rows)){
var editor = param.button.editor;
editor.rows = rows;
}else{
rows=config.maxEditRows;
}
config.options['txtWikibarEditorRows'] = rows;
saveOptionCookie('txtWikibarEditorRows');
config.maxEditRows = rows;
}
}
};
toolset.setEditorSizeOnLoadingWikibar = {
CAPTION:'set editor height on loading wikibar',
SELECTED: config.options['chkWikibarSetEditorHeight'],
HANDLER: function(param){
config.options['chkWikibarSetEditorHeight'] = !config.options['chkWikibarSetEditorHeight'];
saveOptionCookie('chkWikibarSetEditorHeight');
if(config.options['chkWikibarSetEditorHeight']){
var rows = config.options['txtWikibarEditorRows'];
if(!isNaN(rows)){ rows = 15; }
var editor = param.button.editor;
editor.rows = rows;
config.options['txtWikibarEditorRows'] = rows;
saveOptionCookie('txtWikibarEditorRows');
}
}
};
toolset.SEPERATOR = {};
toolset.update = {
CAPTION: 'check for updates',
DISABLED: true,
HANDLER: function(){}
};
return toolset;
}
function wikibar_genPaletteSelector(){
try{
var cpTiddlers = store.getTaggedTiddlers('ColorPalettes');
if(!cpTiddlers) { return; }
var palettes=[];
palettes.push(wikibarColorTool.defaultPaletteName);
for(var i=0; i<cpTiddlers.length; i++){
palettes.push(cpTiddlers[i].title.trim());
}
var toolset={};
for(i=0; i<palettes.length; i++){
toolset[palettes[i]] = {
TOOLTIP: palettes[i],
SELECTED: (palettes[i]==wikibarColorTool.paletteName),
HANDLER: wikibar_doSelectPalette
};
}
return toolset;
}catch(ex){ return null; }
}
function wikibar_onClickItem(e){
if(!e){ e = window.event; }
var theTarget = resolveTarget(e);
if(theTarget.tagName=='INPUT'){
e.cancelBubble = true;
if (e.stopPropagation){ e.stopPropagation(); }
return;
}
var theButton = wikibar_resolveTargetButton(theTarget);
if(!theButton){ return(false); }
var o = theButton.toolItem;
if(!o) { return; }
var param = {
event: e,
button: theButton
};
if(o.HANDLER){ o.HANDLER(param); }
if(o.DISABLED){
e.cancelBubble = true;
if (e.stopPropagation){ e.stopPropagation(); }
}
return(false);
}
function wikibar_onClickMenuItem(e){
if(!e){ e = window.event; }
var theButton = wikibar_resolveTargetButton(resolveTarget(e));
if(!theButton){ return(false); }
e.cancelBubble = true;
if (e.stopPropagation){ e.stopPropagation(); }
var title = theButton.tiddlerTitle;
var editor = theButton.editor;
var tool = theButton.toolItem;
if(!tool) { return; }
var popup = wikibarPopup.create(this);
if(popup){
wikibar_createMenu(popup,tool,title,editor);
if(!popup.hasChildNodes()){
wikibarPopup.remove();
}else{
wikibarPopup.show(popup, false);
}
}
return(false);
}
var wikibarColorTool = {
defaultPaletteName : 'default',
defaultColumns : 16,
defaultPalette : [
'#FFF','#DDD','#CCC','#BBB','#AAA','#999','#666','#333','#111','#000','#FC0','#F90','#F60','#F30','#C30','#C03',
'#9C0','#9D0','#9E0','#E90','#D90','#C90','#FC3','#FC6','#F96','#F63','#600','#900','#C00','#F00','#F36','#F03',
'#CF0','#CF3','#330','#660','#990','#CC0','#FF0','#C93','#C63','#300','#933','#C33','#F33','#C36','#F69','#F06',
'#9F0','#CF6','#9C3','#663','#993','#CC3','#FF3','#960','#930','#633','#C66','#F66','#903','#C39','#F6C','#F09',
'#6F0','#9F6','#6C3','#690','#996','#CC6','#FF6','#963','#630','#966','#F99','#F39','#C06','#906','#F3C','#F0C',
'#3F0','#6F3','#390','#6C0','#9F3','#CC9','#FF9','#C96','#C60','#C99','#F9C','#C69','#936','#603','#C09','#303',
'#0C0','#3C0','#360','#693','#9C6','#CF9','#FFC','#FC9','#F93','#FCC','#C9C','#969','#939','#909','#636','#606',
'#060','#3C3','#6C6','#0F0','#3F3','#6F6','#9F9','#CFC','#9CF','#FCF','#F9F','#F6F','#F3F','#F0F','#C6C','#C3C',
'#030','#363','#090','#393','#696','#9C9','#CFF','#39F','#69C','#CCF','#C9F','#96C','#639','#306','#90C','#C0C',
'#0F3','#0C3','#063','#396','#6C9','#9FC','#9CC','#06C','#369','#99F','#99C','#93F','#60C','#609','#C3F','#C0F',
'#0F6','#3F6','#093','#0C6','#3F9','#9FF','#699','#036','#039','#66F','#66C','#669','#309','#93C','#C6F','#90F',
'#0F9','#6F9','#3C6','#096','#6FF','#6CC','#366','#069','#36C','#33F','#33C','#339','#336','#63C','#96F','#60F',
'#0FC','#6FC','#3C9','#3FF','#3CC','#399','#033','#39C','#69F','#00F','#00C','#009','#006','#003','#63F','#30F',
'#0C9','#3FC','#0FF','#0CC','#099','#066','#3CF','#6CF','#09C','#36F','#0CF','#09F','#06F','#03F','#03C','#30C'
],
colorPicker : null,
pickColorHandler: null,
userData: null
};
wikibarColorTool.paletteName = wikibarColorTool.defaultPaletteName;
wikibarColorTool.columns = wikibarColorTool.defaultColumns;
wikibarColorTool.palette = wikibarColorTool.defaultPalette;
wikibarColorTool.onPickColor = function(e){
if (!e){ e = window.event; }
var theCell = resolveTarget(e);
if(!theCell){ return(false); }
color = theCell.bgColor.toLowerCase();
if(!color) { return; }
wikibarColorTool.displayColorPicker(false);
if(wikibarColorTool.pickColorHandler){
wikibarColorTool.pickColorHandler(color, wikibarColorTool.userData);
}
return(false);
};
wikibarColorTool.onMouseOver = function(e){
if (!e){ e = window.event; }
var theButton = resolveTarget(e);
if(!theButton){ return(false); }
if(!wikibarColorTool) { return; }
color = theButton.bgColor.toUpperCase();
if(!color) { return; }
td=document.getElementById('colorPickerInfo');
if(!td) { return; }
td.bgColor = color;
td.innerHTML = '<span style=\"color:#000;\">'+color+'</span> ' +
'<span style=\"color:#fff;\">'+color+'</span>';
e.cancelBubble = true;
if (e.stopPropagation){ e.stopPropagation(); }
return(false);
};
wikibarColorTool.openColorPicker = function(theTarget, pickColorHandler, userData){
wikibarColorTool.skipClickDocumentEvent = true;
wikibarColorTool.pickColorHandler = pickColorHandler;
wikibarColorTool.userData = userData;
wikibarColorTool.moveColorPicker(theTarget);
};
wikibarColorTool.convert3to6HexColor = function(c){
c=c.trim();
var rx=/^\#(\d|[a-f])(\d|[a-f])(\d|[a-f])$/gi;
return (rx.test(c)? c.replace(rx, '#$1$1$2$2$3$3') : c);
};
wikibarColorTool.numToHexColor = function (n){
if(typeof(n)=='number' && (n>=0 && n<=255)) {
s = n.toString(16).toLowerCase();
return ((s.length==1)? '0'+s : s);
}else{
return null;
}
};
wikibarColorTool.renderColorPalette = function(){
if(wikibarColorTool.paletteName==wikibarColorTool.defaultPaletteName){
wikibarColorTool.palette=wikibarColorTool.defaultPalette;
wikibarColorTool.columns=wikibarColorTool.defaultColumns;
return;
}
tiddlerText = (store.getTiddlerText(wikibarColorTool.paletteName, '')).trim();
if(tiddlerText.length<=0) { return; }
var cpContents = tiddlerText.split('\n');
var colors=[];
columns = wikibarColorTool.defaultColumns;
var tmpArray=null;
errCount=0;
for(var i=0; i<cpContents.length; i++){
cpLine=cpContents[i].trim();
if( (!cpLine) || (cpLine.length<=0) || (cpLine.charAt(0) == '#') ){ continue; }
if(cpLine.substring(0,8).toLowerCase()=='columns:'){
tmpArray = cpLine.split(':');
try{
columns = parseInt(tmpArray[1],10);
}catch(ex){
columns = wikibarColorTool.defaultColumns;
}
}else{
tmpArray = cpLine.replace('\t', ' ').split(/[ ]{1,}/);
try{
color='';
for(var j=0; j<3; j++){
c=parseInt(tmpArray[j].trim(), 10);
if(isNaN(c)){
break;
}else{
c=wikibarColorTool.numToHexColor(c);
if(!c) {break;}
color+=c;
}
}
if(color.length==6){
colors.push('#'+color);
} else {
throw 'error';
}
}catch(ex){
}
}
}
if(colors.length>0){
wikibarColorTool.palette = colors;
wikibarColorTool.columns = columns;
}else{
throw 'renderColorPalette(): No color defined in the palette.';
}
};
wikibarColorTool.displayColorPicker = function(visible){
if(wikibarColorTool.colorPicker){
wikibarColorTool.colorPicker.style.display = (visible? 'block' : 'none');
}
};
wikibarColorTool.moveColorPicker = function(theTarget){
if(!wikibarColorTool.colorPicker){
wikibarColorTool.createColorPicker();
}
var cp = wikibarColorTool.colorPicker;
var rootLeft = findPosX(theTarget);
var rootTop = findPosY(theTarget);
var popupLeft = rootLeft;
var popupTop = rootTop;
var popupWidth = cp.offsetWidth;
var winWidth = findWindowWidth();
if(popupLeft + popupWidth > winWidth){
popupLeft = winWidth - popupWidth;
}
cp.style.left = popupLeft + 'px';
cp.style.top = popupTop + 'px';
wikibarColorTool.displayColorPicker(true);
};
wikibarColorTool.createColorPicker = function(unused, palette){
if(palette){ wikibarColorTool.paletteName=palette; }
wikibarColorTool.renderColorPalette();
wikibarColorTool.colorPicker = document.createElement('div');
wikibarColorTool.colorPicker.id = 'colorPicker';
document.body.appendChild(wikibarColorTool.colorPicker);
var theTable = document.createElement('table');
wikibarColorTool.colorPicker.appendChild(theTable);
var theTR = document.createElement('tr');
theTable.appendChild(theTR);
var theTD = document.createElement('td');
theTD.className = 'header';
theTD.colSpan = wikibarColorTool.columns;
theTD.innerHTML = wikibarColorTool.paletteName;
theTR.appendChild(theTD);
for(var i=0; i<wikibarColorTool.palette.length; i++){
if((i%wikibarColorTool.columns)===0){
theTR = document.createElement('tr');
theTable.appendChild(theTR);
}
theTD = document.createElement('td');
theTD.className = 'cell';
theTD.bgColor = wikibarColorTool.convert3to6HexColor(wikibarColorTool.palette[i]);
theTD.onclick = wikibarColorTool.onPickColor;
theTD.onmouseover = wikibarColorTool.onMouseOver;
theTR.appendChild(theTD);
}
rest = wikibarColorTool.palette.length % wikibarColorTool.columns;
if(rest>0){
theTD = document.createElement('td');
theTD.colSpan = wikibarColorTool.columns-rest;
theTD.bgColor = '#000000';
theTR.appendChild(theTD);
}
theTR = document.createElement('tr');
theTable.appendChild(theTR);
theTD = document.createElement('td');
theTD.colSpan = wikibarColorTool.columns;
theTD.id = 'colorPickerInfo';
theTR.appendChild(theTD);
};
wikibarColorTool.onDocumentClick = function(e){
if (!e){ e = window.event; }
if(wikibarColorTool.skipClickDocumentEvent) {
wikibarColorTool.skipClickDocumentEvent = false;
return true;
}
if((!e.eventPhase) || e.eventPhase == Event.BUBBLING_PHASE || e.eventPhase == Event.AT_TARGET){
wikibarColorTool.displayColorPicker(false);
}
return true;
};
function wikibar_doSelectPalette(param){
clearMessage();
var theButton = param.button;
if(!theButton.toolItem.key) { return; }
var palette = theButton.toolItem.key;
var oldPaletteName = wikibarColorTool.paletteName;
if(oldPaletteName != palette){
try{
wikibarColorTool.createColorPicker(theButton, palette);
displayMessage('Palette \"'+palette+'\" ('+ wikibarColorTool.palette.length +' colors) is selected');
}catch(ex){
errMsg = ex;
if(errMsg.substring(0,18)=='renderColorPalette'){
displayMessage('Invalid palette \"' + palette + '\", please check it out!');
wikibarColorTool.createColorPicker(theButton, oldPaletteName);
}
}
}
}
var wikibarPopup = {
skipClickDocumentEvent: false,
stack: []
};
wikibarPopup.resolveRootPopup = function(o){
if(o.isOnMainMenu){ return null; }
if(o.className.substring(0,12)=='wikibarPopup'){ return o;}
return wikibarPopup.resolveRootPopup(o.parentNode);
};
wikibarPopup.create = function(root){
for(var i=0; i<wikibarPopup.stack.length; i++){
var p=wikibarPopup.stack[i];
if(p.root==root){
wikibarPopup.removeFrom(i+1);
return null;
}
}
var rootPopup = wikibarPopup.resolveRootPopup(root);
if(!rootPopup){
wikibarPopup.remove();
}else{
wikibarPopup.removeFromRootPopup(rootPopup);
}
var popup = createTiddlyElement(document.body,'div','wikibarPopup'+root.toolItem.key,'wikibarPopup');
var pop = createTiddlyElement(popup,'table','','');
wikibarPopup.stack.push({rootPopup: rootPopup, root: root, popup: popup});
return pop;
};
wikibarPopup.show = function(unused,slowly){
var curr = wikibarPopup.stack[wikibarPopup.stack.length-1];
var overlayWidth = 1;
var rootLeft, rootTop, rootWidth, rootHeight, popupLeft, popupTop, popupWidth;
if(curr.rootPopup){
rootLeft = findPosX(curr.rootPopup);
rootTop = findPosY(curr.root);
rootWidth = curr.rootPopup.offsetWidth;
popupLeft = rootLeft + rootWidth - overlayWidth;
popupTop = rootTop;
}else{
rootLeft = findPosX(curr.root);
rootTop = findPosY(curr.root);
rootHeight = curr.root.offsetHeight;
popupLeft = rootLeft;
popupTop = rootTop + rootHeight;
}
var winWidth = findWindowWidth();
popupWidth = curr.popup.offsetWidth;
if(popupLeft + popupWidth > winWidth){
popupLeft = rootLeft - popupWidth + overlayWidth;
}
curr.popup.style.left = popupLeft + 'px';
curr.popup.style.top = popupTop + 'px';
curr.popup.style.display = 'block';
addClass(curr.root, 'highlight');
if(config.options.chkAnimate){
anim.startAnimating(new Scroller(curr.popup,slowly));
}else{
window.scrollTo(0,ensureVisible(curr.popup));
}
};
wikibarPopup.remove = function(){
if(wikibarPopup.stack.length > 0){
wikibarPopup.removeFrom(0);
}
};
wikibarPopup.removeFrom = function(from){
for(var t=wikibarPopup.stack.length-1; t>=from; t--){
var p = wikibarPopup.stack[t];
removeClass(p.root,'highlight');
p.popup.parentNode.removeChild(p.popup);
}
wikibarPopup.stack = wikibarPopup.stack.slice(0,from);
};
wikibarPopup.removeFromRootPopup = function(from){
for(var t=0; t<wikibarPopup.stack.length; t++){
var p = wikibarPopup.stack[t];
if(p.rootPopup==from){
wikibarPopup.removeFrom(t);
break;
}
}
};
wikibarPopup.onDocumentClick = function(e){
if (!e){ e = window.event; }
if(wikibarPopup.skipClickDocumentEvent){
wikibarPopup.skipClickDocumentEvent=false;
return true;
}
if((!e.eventPhase) || e.eventPhase == Event.BUBBLING_PHASE || e.eventPhase == Event.AT_TARGET){
wikibarPopup.remove();
}
return true;
};
var wikibarStore = {
TYPE: 'MAIN_MENU',
help:{
TYPE:'MENU',
CAPTION: '<font face=\"verdana\">?</font>',
TOOLTIP: 'about WikiBar',
options:{
TYPE:'MENU',
DYNAITEM: wikibar_genWikibarOptions
},
about:{
TYPE:'MENU',
DYNAITEM: wikibar_genWikibarAbout
}
},
preview:{
TOOLTIP: 'preview this tiddler',
CAPTION: '<font face=\"verdana\">∞</font>',
HANDLER: wikibar_doPreview
},
line:{
TOOLTIP: 'horizontal line',
CAPTION: '<font face=\"verdana\">—</font>',
syntax: '\n----\n',
HANDLER: wikibar_editFormatByCursor
},
crlf:{
TOOLTIP: 'new line',
CAPTION: '<font face=\"verdana\">¶</font>',
syntax: '\n',
HANDLER: wikibar_editFormatByCursor
},
selectAll:{
TOOLTIP: 'select all',
CAPTION: '<font face=\"verdana\">§</font>',
HANDLER: wikibar_editSelectAll
},
deleteSelected:{
TOOLTIP: 'delete selected',
CAPTION: '<font face=\"verdana\">×</font>',
syntax: '',
HANDLER: wikibar_editFormat
},
textFormat:{
TYPE: 'MENU',
CAPTION: 'text',
TOOLTIP: 'text formatters',
ignore:{
TOOLTIP: 'ignore wiki word',
CAPTION: 'ignore wikiWord',
syntax: '~user_text',
hint: 'wiki_word',
HANDLER: wikibar_editFormatByWord
},
bolder:{
TOOLTIP: 'bolder text',
CAPTION: '<strong>bolder</strong>',
syntax: "''user_text''",
hint: 'bold_text',
HANDLER: wikibar_editFormatByWord
},
italic:{
TOOLTIP: 'italic text',
CAPTION: '<em>italic</em>',
syntax: '\/\/user_text\/\/',
hint: 'italic_text',
HANDLER: wikibar_editFormatByWord
},
underline:{
TOOLTIP: 'underline text',
CAPTION: '<u>underline</u>',
syntax: '__user_text__',
hint: 'underline_text',
HANDLER: wikibar_editFormatByWord
},
strikethrough:{
TOOLTIP: 'strikethrough text',
CAPTION: '<strike>strikethrough</strike>',
syntax: '==user_text==',
hint: 'strikethrough_text',
HANDLER: wikibar_editFormatByWord
},
superscript:{
TOOLTIP: 'superscript text',
CAPTION: 'X<sup>superscript</sup>',
syntax: '^^user_text^^',
hint: 'superscript_text',
HANDLER: wikibar_editFormatByWord
},
subscript:{
TOOLTIP: 'subscript text',
CAPTION: 'X<sub>subscript</sub>',
syntax: '~~user_text~~',
hint: 'subscript_text',
HANDLER: wikibar_editFormatByWord
},
comment:{
TOOLTIP: 'comment text',
CAPTION: 'comment text',
syntax: '/%user_text%/',
hint: 'comment_text',
HANDLER: wikibar_editFormatByWord
},
monospaced:{
TOOLTIP: 'monospaced text',
CAPTION: '<code>monospaced</code>',
syntax: '{{{user_text}}}',
hint: 'monospaced_text',
HANDLER: wikibar_editFormatByWord
}
},
paragraph:{
TYPE: 'MENU',
TOOLTIP: 'paragarph formatters',
list:{
TYPE: 'MENU',
TOOLTIP: 'list tools',
bullet:{
TOOLTIP: 'bullet point',
syntax: '*user_text',
hint: 'bullet_text',
HANDLER: wikibar_editFormatByLine
},
numbered:{
TOOLTIP: 'numbered list',
syntax: '#user_text',
hint: 'numbered_text',
HANDLER: wikibar_editFormatByLine
}
},
heading:{
TYPE: 'MENU',
heading1:{
CAPTION:'<h1>Heading 1</h1>',
TOOLTIP: 'Heading 1',
syntax: '!user_text',
hint: 'heading_1',
HANDLER: wikibar_editFormatByLine
},
heading2:{
CAPTION:'<h2>Heading 2<h2>',
TOOLTIP: 'Heading 2',
syntax: '!!user_text',
hint: 'heading_2',
HANDLER: wikibar_editFormatByLine
},
heading3:{
CAPTION:'<h3>Heading 3</h3>',
TOOLTIP: 'Heading 3',
syntax: '!!!user_text',
hint: 'heading_3',
HANDLER: wikibar_editFormatByLine
},
heading4:{
CAPTION:'<h4>Heading 4</h4>',
TOOLTIP: 'Heading 4',
syntax: '!!!!user_text',
hint: 'heading_4',
HANDLER: wikibar_editFormatByLine
},
heading5:{
CAPTION:'<h5>Heading 5</h5>',
TOOLTIP: 'Heading 5',
syntax: '!!!!!user_text',
hint: 'heading_5',
HANDLER: wikibar_editFormatByLine
}
},
comment:{
TYPE: 'MENU',
commentByLine:{
CAPTION:'comment by line',
TOOLTIP: 'line comment',
syntax: '/%user_text%/',
hint: 'comment_text',
HANDLER: wikibar_editFormatByLine
},
commentByBlock:{
CAPTION:'comment by block',
TOOLTIP: 'block comment',
syntax: '/%\nuser_text\n%/',
hint: 'comment_text',
byBlock: true,
HANDLER: wikibar_editFormatByLine
}
},
monospaced:{
TYPE: 'MENU',
monosByLine:{
CAPTION: 'monospaced by line',
TOOLTIP: 'line monospaced',
syntax: '{{{\nuser_text\n}}}',
hint: 'monospaced_text',
HANDLER: wikibar_editFormatByLine
},
monosByBlock:{
CAPTION: 'monospaced by block',
TOOLTIP: 'block monospaced',
syntax: '{{{\nuser_text\n}}}',
hint: 'monospaced_text',
byBlock: true,
HANDLER: wikibar_editFormatByLine
}
},
quote:{
TYPE: 'MENU',
quoteByLine:{
CAPTION: 'quote by line',
TOOLTIP: 'line quote',
syntax: '>user_text',
hint: 'quote_text',
HANDLER: wikibar_editFormatByLine
},
quoteByBlcok:{
CAPTION: 'quote by block',
TOOLTIP: 'block quote',
syntax: '<<<\nuser_text\n<<<',
hint: 'quote_text',
byBlock: true,
HANDLER: wikibar_editFormatByLine
}
},
plugin:{
TYPE: 'MENU',
code:{
CAPTION: 'code area',
TOOLTIP: 'block monospaced for plugin',
syntax: '\n\/\/{{{\nuser_text\n\/\/}}}\n',
hint: 'monospaced_plugin_code',
byBlock: true,
HANDLER: wikibar_editFormatByLine
},
commentByLine:{
CAPTION: 'comment by line',
TOOLTIP: 'line comment',
syntax: '\/\/user_text',
hint: 'plugin_comment',
HANDLER: wikibar_editFormatByLine
},
commentByBlock:{
CAPTION: 'comment by block',
TOOLTIP: 'block comment',
syntax: '\/\***\nuser_text\n***\/',
hint: 'plugin_comment',
byBlock: true,
HANDLER: wikibar_editFormatByLine
}
},
css:{
TYPE: 'MENU',
code:{
CAPTION: 'code area',
TOOLTIP: 'block monospaced for css',
syntax: '\n\nuser_text\n\n',
hint: 'monospaced_css_code',
byBlock: true,
HANDLER: wikibar_editFormatByLine
},
commentByLine:{
CAPTION: 'comment by line',
TOOLTIP: 'line comment',
syntax: '',
hint: 'css_comment',
HANDLER: wikibar_editFormatByLine
},
commentByBlock:{
CAPTION: 'comment by block',
TOOLTIP: 'block comment',
syntax: '',
hint: 'css_comment',
byBlock: true,
HANDLER: wikibar_editFormatByLine
}
}
},
color:{
TYPE: 'MENU',
TOOLTIP: 'color tools',
highlight:{
CAPTION:'highlight text',
TOOLTIP: 'highlight text',
syntax: '@@user_text@@',
hint: 'highlight_text',
HANDLER: wikibar_editFormatByWord
},
color:{
CAPTION:'text color',
TOOLTIP: 'text color',
hint: 'your_text',
syntax: '@@color(%1):user_text@@',
HANDLER: wikibar_getColorCode,
doMore: wikibar_editFormatByWord
},
bgcolor:{
CAPTION:'background color',
TOOLTIP: 'background color',
hint: 'your_text',
syntax: '@@bgcolor(%1):user_text@@',
HANDLER: wikibar_getColorCode,
doMore: wikibar_editFormatByWord
},
colorcode:{
CAPTION:'color code',
TOOLTIP: 'insert color code',
syntax: '%1',
HANDLER: wikibar_getColorCode,
doMore: wikibar_editFormatByCursor
},
'color palette':{
TYPE:'MENU',
DYNAITEM: wikibar_genPaletteSelector,
SEPERATOR:{},
morePalette:{
CAPTION:'more palettes',
TOOLTIP:'get more palettes',
HANDLER: wikibar_getMorePalette
}
}
},
link:{
TYPE: 'MENU',
TOOLTIP: 'insert link',
wiki:{
CAPTION:'wiki link',
TOOLTIP: 'wiki link',
syntax: '[[user_text]]',
hint: 'wiki_word',
HANDLER: wikibar_editFormatByWord
},
pretty:{
CAPTION: 'pretty link',
TOOLTIP: 'pretty link',
syntax: '[[user_text|%1]]',
hint: 'pretty_word',
param: 'PrettyLink Target',
HANDLER: wikibar_getLinkUrl,
doMore: wikibar_editFormatByWord
},
url:{
TOOLTIP: 'url link',
syntax: '[[user_text|%1]]',
hint: 'your_text',
param: 'http:\/\/...',
HANDLER: wikibar_getLinkUrl,
doMore: wikibar_editFormatByWord
},
image:{
TOOLTIP: 'image link',
syntax: '[img[user_text|%1]]',
hint: 'alt_text',
param: 'image/icon.jpg',
HANDLER: wikibar_getLinkUrl,
doMore: wikibar_editFormatByWord
}
},
macro:{},
more:{
TYPE: 'MENU',
TOOLTIP: 'more tools',
table:{
TYPE: 'MENU',
TOOLTIP: 'table',
table:{
CAPTION:'create table',
TOOLTIP: 'create a new table',
syntax: '\n%1\n',
HANDLER: wikibar_getTableRowCol,
doMore: wikibar_editFormatByWord
},
header:{
TOOLTIP: 'table header text',
syntax: '|user_text|c',
hint: 'table_header',
HANDLER: wikibar_editFormatByWord
},
cell:{
TOOLTIP: 'create a tabel cell',
syntax: '|user_text|',
hint: 'your_text',
HANDLER: wikibar_editFormatByWord
},
columnHeader:{
CAPTION:'column header',
TOOLTIP: 'create a column header cell',
syntax: '|!user_text|',
hint: 'column_header',
HANDLER: wikibar_editFormatByWord
},
cell:{
TYPE: 'MENU',
CAPTION: 'cell options',
bgcolor:{
CAPTION: 'background color',
TOOLTIP: 'cell bgcolor',
syntax: '|bgcolor(%1):user_text|',
hint: 'your_text',
HANDLER: wikibar_getColorCode,
doMore: wikibar_editFormatByTableCell
},
alignLeft:{
CAPTION: 'align left',
TOOLTIP: 'left align cell text',
syntax: '|user_text|',
hint: 'your_text',
HANDLER: wikibar_editFormatByTableCell
},
alignCenter:{
CAPTION: 'align center',
TOOLTIP: 'center align cell text',
syntax: '| user_text |',
hint: 'your_text',
HANDLER: wikibar_editFormatByTableCell
},
alignRight:{
CAPTION: 'align right',
TOOLTIP: 'right align cell text',
syntax: '| user_text|',
hint: 'your_text',
HANDLER: wikibar_editFormatByTableCell
}
}
},
html:{
TYPE: 'MENU',
html:{
CAPTION: '<html>',
TOOLTIP: 'html tag',
syntax: '<html>\nuser_text\n</html>',
hint: 'html_content',
byBlock: true,
HANDLER: wikibar_editFormatByLine
}
}
},
addon:{
TYPE: 'MENU',
TOOLTIP:'3rd party tools',
'about addons':{
TOOLTIP: 'list loaded addons',
HANDLER: wikibar_doListAddons
},
SEPERATOR:{}
}
};
addEvent(document, 'click', wikibarColorTool.onDocumentClick);
addEvent(document, 'click', wikibarPopup.onDocumentClick);
wikibar_install();
//}}}sys