Merging latest changes from main line canvas
authorAnton Epple <toni.epple@eppleton.de>
Wed, 23 Jan 2013 14:49:52 +0100
branchcanvas
changeset 550d0041e85a350
parent 523 48f01cef55c2
parent 549 8f0a97d446a1
child 551 ca781bc82662
Merging latest changes from main line
javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java
javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml
javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java
javaquery/demo-calculator/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml
launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/console.xhtml
     1.1 --- a/benchmarks/matrix-multiplication/src/test/java/org/apidesign/benchmark/matrixmul/MatrixTest.java	Tue Jan 22 17:53:05 2013 +0100
     1.2 +++ b/benchmarks/matrix-multiplication/src/test/java/org/apidesign/benchmark/matrixmul/MatrixTest.java	Wed Jan 23 14:49:52 2013 +0100
     1.3 @@ -30,7 +30,8 @@
     1.4      public MatrixTest() {
     1.5      }
     1.6  
     1.7 -    @Compare public String tenThousandIterations() throws IOException {
     1.8 +    @Compare(scripting = false) 
     1.9 +    public String tenThousandIterations() throws IOException {
    1.10      
    1.11          Matrix m1 = new Matrix(5);
    1.12          Matrix m2 = new Matrix(5);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/dew/nbactions.xml	Wed Jan 23 14:49:52 2013 +0100
     2.3 @@ -0,0 +1,56 @@
     2.4 +<?xml version="1.0" encoding="UTF-8"?>
     2.5 +<!--
     2.6 +
     2.7 +    Back 2 Browser Bytecode Translator
     2.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     2.9 +
    2.10 +    This program is free software: you can redistribute it and/or modify
    2.11 +    it under the terms of the GNU General Public License as published by
    2.12 +    the Free Software Foundation, version 2 of the License.
    2.13 +
    2.14 +    This program is distributed in the hope that it will be useful,
    2.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.17 +    GNU General Public License for more details.
    2.18 +
    2.19 +    You should have received a copy of the GNU General Public License
    2.20 +    along with this program. Look for COPYING file in the top folder.
    2.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
    2.22 +
    2.23 +-->
    2.24 +<actions>
    2.25 +        <action>
    2.26 +            <actionName>run</actionName>
    2.27 +            <goals>
    2.28 +                <goal>process-classes</goal>
    2.29 +                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
    2.30 +            </goals>
    2.31 +            <properties>
    2.32 +                <exec.args>-classpath %classpath org.apidesign.bck2brwsr.dew.Dew</exec.args>
    2.33 +                <exec.executable>java</exec.executable>
    2.34 +            </properties>
    2.35 +        </action>
    2.36 +        <action>
    2.37 +            <actionName>debug</actionName>
    2.38 +            <goals>
    2.39 +                <goal>process-classes</goal>
    2.40 +                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
    2.41 +            </goals>
    2.42 +            <properties>
    2.43 +                <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath org.apidesign.bck2brwsr.dew.Dew</exec.args>
    2.44 +                <exec.executable>java</exec.executable>
    2.45 +                <jpda.listen>true</jpda.listen>
    2.46 +            </properties>
    2.47 +        </action>
    2.48 +        <action>
    2.49 +            <actionName>profile</actionName>
    2.50 +            <goals>
    2.51 +                <goal>process-classes</goal>
    2.52 +                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
    2.53 +            </goals>
    2.54 +            <properties>
    2.55 +                <exec.args>${profiler.args} -classpath %classpath org.apidesign.bck2brwsr.dew.Dew</exec.args>
    2.56 +                <exec.executable>${profiler.java}</exec.executable>
    2.57 +            </properties>
    2.58 +        </action>
    2.59 +    </actions>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/dew/pom.xml	Wed Jan 23 14:49:52 2013 +0100
     3.3 @@ -0,0 +1,64 @@
     3.4 +<?xml version="1.0"?>
     3.5 +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
     3.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     3.7 +  <modelVersion>4.0.0</modelVersion>
     3.8 +  <parent>
     3.9 +    <groupId>org.apidesign</groupId>
    3.10 +    <artifactId>bck2brwsr</artifactId>
    3.11 +    <version>0.3-SNAPSHOT</version>
    3.12 +  </parent>
    3.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
    3.14 +  <artifactId>dew</artifactId>
    3.15 +  <version>0.3-SNAPSHOT</version>
    3.16 +  <name>Development Environment for Web</name>
    3.17 +  <url>http://maven.apache.org</url>
    3.18 +    <build>
    3.19 +        <plugins>
    3.20 +            <plugin>
    3.21 +                <groupId>org.apache.maven.plugins</groupId>
    3.22 +                <artifactId>maven-compiler-plugin</artifactId>
    3.23 +                <version>2.3.2</version>
    3.24 +                <configuration>
    3.25 +                    <source>1.7</source>
    3.26 +                    <target>1.7</target>
    3.27 +                </configuration>
    3.28 +            </plugin>
    3.29 +        </plugins>
    3.30 +    </build>
    3.31 +    <properties>
    3.32 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    3.33 +  </properties>
    3.34 +  <dependencies>
    3.35 +    <dependency>
    3.36 +      <groupId>org.glassfish.grizzly</groupId>
    3.37 +      <artifactId>grizzly-http-server</artifactId>
    3.38 +      <version>2.2.19</version>
    3.39 +    </dependency>
    3.40 +    <dependency>
    3.41 +      <groupId>${project.groupId}</groupId>
    3.42 +      <artifactId>vm4brwsr</artifactId>
    3.43 +      <version>${project.version}</version>
    3.44 +    </dependency>
    3.45 +    <dependency>
    3.46 +      <groupId>org.json</groupId>
    3.47 +      <artifactId>json</artifactId>
    3.48 +      <version>20090211</version>
    3.49 +    </dependency>
    3.50 +    <dependency>
    3.51 +      <groupId>org.testng</groupId>
    3.52 +      <artifactId>testng</artifactId>
    3.53 +      <scope>test</scope>
    3.54 +      <exclusions>
    3.55 +        <exclusion>
    3.56 +          <artifactId>junit</artifactId>
    3.57 +          <groupId>junit</groupId>
    3.58 +        </exclusion>
    3.59 +      </exclusions>
    3.60 +    </dependency>
    3.61 +    <dependency>
    3.62 +      <groupId>${project.groupId}</groupId>
    3.63 +      <artifactId>javaquery.api</artifactId>
    3.64 +      <version>${project.version}</version>
    3.65 +    </dependency>
    3.66 +  </dependencies>
    3.67 +</project>
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/dew/src/main/java/org/apidesign/bck2brwsr/dew/Compile.java	Wed Jan 23 14:49:52 2013 +0100
     4.3 @@ -0,0 +1,196 @@
     4.4 +/**
     4.5 + * Back 2 Browser Bytecode Translator
     4.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4.7 + *
     4.8 + * This program is free software: you can redistribute it and/or modify
     4.9 + * it under the terms of the GNU General Public License as published by
    4.10 + * the Free Software Foundation, version 2 of the License.
    4.11 + *
    4.12 + * This program is distributed in the hope that it will be useful,
    4.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.15 + * GNU General Public License for more details.
    4.16 + *
    4.17 + * You should have received a copy of the GNU General Public License
    4.18 + * along with this program. Look for COPYING file in the top folder.
    4.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    4.20 + */
    4.21 +package org.apidesign.bck2brwsr.dew;
    4.22 +
    4.23 +import java.io.ByteArrayInputStream;
    4.24 +import java.io.ByteArrayOutputStream;
    4.25 +import java.io.IOException;
    4.26 +import java.io.InputStream;
    4.27 +import java.io.OutputStream;
    4.28 +import java.net.URI;
    4.29 +import java.net.URISyntaxException;
    4.30 +import java.util.ArrayList;
    4.31 +import java.util.Arrays;
    4.32 +import java.util.HashMap;
    4.33 +import java.util.List;
    4.34 +import java.util.Map;
    4.35 +import java.util.regex.Matcher;
    4.36 +import java.util.regex.Pattern;
    4.37 +import javax.tools.Diagnostic;
    4.38 +import javax.tools.DiagnosticListener;
    4.39 +import javax.tools.FileObject;
    4.40 +import javax.tools.ForwardingJavaFileManager;
    4.41 +import javax.tools.JavaFileManager;
    4.42 +import javax.tools.JavaFileObject;
    4.43 +import javax.tools.JavaFileObject.Kind;
    4.44 +import javax.tools.SimpleJavaFileObject;
    4.45 +import javax.tools.StandardJavaFileManager;
    4.46 +import javax.tools.StandardLocation;
    4.47 +import javax.tools.ToolProvider;
    4.48 +
    4.49 +/**
    4.50 + *
    4.51 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    4.52 + */
    4.53 +final class Compile implements DiagnosticListener<JavaFileObject> {
    4.54 +    private final List<Diagnostic<? extends JavaFileObject>> errors = new ArrayList<>();
    4.55 +    private final Map<String, byte[]> classes;
    4.56 +    private final String pkg;
    4.57 +    private final String cls;
    4.58 +
    4.59 +    private Compile(String html, String code) throws IOException {
    4.60 +        this.pkg = findPkg(code);
    4.61 +        this.cls = findCls(code);
    4.62 +        classes = compile(html, code);
    4.63 +    }
    4.64 +
    4.65 +    /** Performs compilation of given HTML page and associated Java code
    4.66 +     */
    4.67 +    public static Compile create(String html, String code) throws IOException {
    4.68 +        return new Compile(html, code);
    4.69 +    }
    4.70 +    
    4.71 +    /** Checks for given class among compiled resources */
    4.72 +    public byte[] get(String res) {
    4.73 +        return classes.get(res);
    4.74 +    }
    4.75 +    
    4.76 +    /** Obtains errors created during compilation.
    4.77 +     */
    4.78 +    public List<Diagnostic<? extends JavaFileObject>> getErrors() {
    4.79 +        List<Diagnostic<? extends JavaFileObject>> err = new ArrayList<>();
    4.80 +        for (Diagnostic<? extends JavaFileObject> diagnostic : errors) {
    4.81 +            if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
    4.82 +                err.add(diagnostic);
    4.83 +            }
    4.84 +        }
    4.85 +        return err;
    4.86 +    }
    4.87 +    
    4.88 +    private Map<String, byte[]> compile(final String html, final String code) throws IOException {
    4.89 +        StandardJavaFileManager sjfm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(this, null, null);
    4.90 +
    4.91 +        final Map<String, ByteArrayOutputStream> class2BAOS = new HashMap<>();
    4.92 +
    4.93 +        JavaFileObject file = new SimpleJavaFileObject(URI.create("mem://mem"), Kind.SOURCE) {
    4.94 +            @Override
    4.95 +            public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
    4.96 +                return code;
    4.97 +            }
    4.98 +        };
    4.99 +        final JavaFileObject htmlFile = new SimpleJavaFileObject(URI.create("mem://mem2"), Kind.OTHER) {
   4.100 +            @Override
   4.101 +            public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
   4.102 +                return html;
   4.103 +            }
   4.104 +
   4.105 +            @Override
   4.106 +            public InputStream openInputStream() throws IOException {
   4.107 +                return new ByteArrayInputStream(html.getBytes());
   4.108 +            }
   4.109 +        };
   4.110 +        
   4.111 +        final URI scratch;
   4.112 +        try {
   4.113 +            scratch = new URI("mem://mem3");
   4.114 +        } catch (URISyntaxException ex) {
   4.115 +            throw new IOException(ex);
   4.116 +        }
   4.117 +        
   4.118 +        JavaFileManager jfm = new ForwardingJavaFileManager<JavaFileManager>(sjfm) {
   4.119 +            @Override
   4.120 +            public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException {
   4.121 +                if (kind  == Kind.CLASS) {
   4.122 +                    final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
   4.123 +
   4.124 +                    class2BAOS.put(className.replace('.', '/') + ".class", buffer);
   4.125 +                    return new SimpleJavaFileObject(sibling.toUri(), kind) {
   4.126 +                        @Override
   4.127 +                        public OutputStream openOutputStream() throws IOException {
   4.128 +                            return buffer;
   4.129 +                        }
   4.130 +                    };
   4.131 +                }
   4.132 +                
   4.133 +                if (kind == Kind.SOURCE) {
   4.134 +                    return new SimpleJavaFileObject(scratch/*sibling.toUri()*/, kind) {
   4.135 +                        private final ByteArrayOutputStream data = new ByteArrayOutputStream();
   4.136 +                        @Override
   4.137 +                        public OutputStream openOutputStream() throws IOException {
   4.138 +                            return data;
   4.139 +                        }
   4.140 +
   4.141 +                        @Override
   4.142 +                        public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
   4.143 +                            data.close();
   4.144 +                            return new String(data.toByteArray());
   4.145 +                        }
   4.146 +                    };
   4.147 +                }
   4.148 +                
   4.149 +                throw new IllegalStateException();
   4.150 +            }
   4.151 +
   4.152 +            @Override
   4.153 +            public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException {
   4.154 +                if (location == StandardLocation.SOURCE_PATH) {
   4.155 +                    if (packageName.equals(pkg)) {
   4.156 +                        return htmlFile;
   4.157 +                    }
   4.158 +                }
   4.159 +                
   4.160 +                return null;
   4.161 +            }
   4.162 +            
   4.163 +        };
   4.164 +
   4.165 +        ToolProvider.getSystemJavaCompiler().getTask(null, jfm, this, /*XXX:*/Arrays.asList("-source", "1.7", "-target", "1.7"), null, Arrays.asList(file)).call();
   4.166 +
   4.167 +        Map<String, byte[]> result = new HashMap<>();
   4.168 +
   4.169 +        for (Map.Entry<String, ByteArrayOutputStream> e : class2BAOS.entrySet()) {
   4.170 +            result.put(e.getKey(), e.getValue().toByteArray());
   4.171 +        }
   4.172 +
   4.173 +        return result;
   4.174 +    }
   4.175 +
   4.176 +
   4.177 +    @Override
   4.178 +    public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
   4.179 +        errors.add(diagnostic);
   4.180 +    }
   4.181 +    private static String findPkg(String java) throws IOException {
   4.182 +        Pattern p = Pattern.compile("package\\p{javaWhitespace}*([\\p{Alnum}\\.]+)\\p{javaWhitespace}*;", Pattern.MULTILINE);
   4.183 +        Matcher m = p.matcher(java);
   4.184 +        if (!m.find()) {
   4.185 +            throw new IOException("Can't find package declaration in the java file");
   4.186 +        }
   4.187 +        String pkg = m.group(1);
   4.188 +        return pkg;
   4.189 +    }
   4.190 +    private static String findCls(String java) throws IOException {
   4.191 +        Pattern p = Pattern.compile("class\\p{javaWhitespace}*([\\p{Alnum}\\.]+)\\p{javaWhitespace}", Pattern.MULTILINE);
   4.192 +        Matcher m = p.matcher(java);
   4.193 +        if (!m.find()) {
   4.194 +            throw new IOException("Can't find package declaration in the java file");
   4.195 +        }
   4.196 +        String cls = m.group(1);
   4.197 +        return cls;
   4.198 +    }
   4.199 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/dew/src/main/java/org/apidesign/bck2brwsr/dew/Dew.java	Wed Jan 23 14:49:52 2013 +0100
     5.3 @@ -0,0 +1,138 @@
     5.4 +/**
     5.5 + * Back 2 Browser Bytecode Translator
     5.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     5.7 + *
     5.8 + * This program is free software: you can redistribute it and/or modify
     5.9 + * it under the terms of the GNU General Public License as published by
    5.10 + * the Free Software Foundation, version 2 of the License.
    5.11 + *
    5.12 + * This program is distributed in the hope that it will be useful,
    5.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.15 + * GNU General Public License for more details.
    5.16 + *
    5.17 + * You should have received a copy of the GNU General Public License
    5.18 + * along with this program. Look for COPYING file in the top folder.
    5.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    5.20 + */
    5.21 +package org.apidesign.bck2brwsr.dew;
    5.22 +
    5.23 +import java.io.ByteArrayInputStream;
    5.24 +import java.io.IOException;
    5.25 +import java.io.InputStream;
    5.26 +import java.io.InputStreamReader;
    5.27 +import java.io.OutputStream;
    5.28 +import java.util.List;
    5.29 +import java.util.Locale;
    5.30 +import javax.tools.Diagnostic;
    5.31 +import javax.tools.JavaFileObject;
    5.32 +import org.apidesign.vm4brwsr.Bck2Brwsr;
    5.33 +import org.glassfish.grizzly.http.Method;
    5.34 +import org.glassfish.grizzly.http.server.HttpHandler;
    5.35 +import org.glassfish.grizzly.http.server.HttpServer;
    5.36 +import org.glassfish.grizzly.http.server.Request;
    5.37 +import org.glassfish.grizzly.http.server.Response;
    5.38 +import org.glassfish.grizzly.http.util.HttpStatus;
    5.39 +import org.json.JSONArray;
    5.40 +import org.json.JSONObject;
    5.41 +import org.json.JSONTokener;
    5.42 +
    5.43 +/**
    5.44 + *
    5.45 + * @author phrebejk
    5.46 + */
    5.47 +final class Dew extends HttpHandler implements Bck2Brwsr.Resources {
    5.48 +    private String html = "";
    5.49 +    private Compile data;
    5.50 +
    5.51 +    public static void main(String... args) throws Exception {
    5.52 +        DewLauncher l = new DewLauncher(null);
    5.53 +        l.addClassLoader(DewLauncher.class.getClassLoader());
    5.54 +        final Dew dew = new Dew();
    5.55 +        HttpServer s = l.initServer(dew);
    5.56 +        s.getServerConfiguration().addHttpHandler(dew, "/dew/");
    5.57 +        l.launchServerAndBrwsr(s, "/dew/");
    5.58 +        System.in.read();
    5.59 +    }
    5.60 +    
    5.61 +    @Override
    5.62 +    public void service(Request request, Response response) throws Exception {
    5.63 +        
    5.64 +        if ( request.getMethod() == Method.POST ) {
    5.65 +            InputStream is = request.getInputStream();
    5.66 +            JSONTokener tok = new JSONTokener(new InputStreamReader(is));
    5.67 +            JSONObject obj = new JSONObject(tok);
    5.68 +            String tmpHtml = obj.getString("html");
    5.69 +            String tmpJava = obj.getString("java");
    5.70 +            
    5.71 +            Compile res = Compile.create(tmpHtml, tmpJava);
    5.72 +            List<Diagnostic<? extends JavaFileObject>> err = res.getErrors();
    5.73 +            if (err.isEmpty()) {
    5.74 +                data = res;
    5.75 +                html = tmpHtml;
    5.76 +                response.getOutputStream().write("[]".getBytes());
    5.77 +                response.setStatus(HttpStatus.OK_200);
    5.78 +            } else {
    5.79 +                
    5.80 +                JSONArray errors = new JSONArray();
    5.81 +                
    5.82 +                for (Diagnostic<? extends JavaFileObject> d : err) {
    5.83 +                    JSONObject e = new JSONObject();
    5.84 +                    e.put("col", d.getColumnNumber());
    5.85 +                    e.put("line", d.getLineNumber());
    5.86 +                    e.put("kind", d.getKind().toString());
    5.87 +                    e.put("msg", d.getMessage(Locale.ENGLISH));
    5.88 +                    errors.put(e);
    5.89 +                }
    5.90 +                
    5.91 +                errors.write(response.getWriter());                
    5.92 +                response.setStatus(HttpStatus.PRECONDITION_FAILED_412);
    5.93 +            }
    5.94 +            
    5.95 +            return;
    5.96 +        }
    5.97 +        
    5.98 +        String r = request.getHttpHandlerPath();
    5.99 +        if (r == null || r.equals("/")) {
   5.100 +            r = "index.html";
   5.101 +        }
   5.102 +        if (r.equals("/result.html")) {
   5.103 +            response.setContentType("text/html");
   5.104 +            response.getOutputBuffer().write(html);
   5.105 +            response.setStatus(HttpStatus.OK_200);
   5.106 +            return;
   5.107 +        }
   5.108 +        
   5.109 +        if (r.startsWith("/")) {
   5.110 +            r = r.substring(1);
   5.111 +        }
   5.112 +        
   5.113 +        if (r.endsWith(".html") || r.endsWith(".xhtml")) {
   5.114 +            response.setContentType("text/html");
   5.115 +        }
   5.116 +        OutputStream os = response.getOutputStream();
   5.117 +        try (InputStream is = Dew.class.getResourceAsStream(r) ) {
   5.118 +            copyStream(is, os, request.getRequestURL().toString() );
   5.119 +        } catch (IOException ex) {
   5.120 +            response.setDetailMessage(ex.getLocalizedMessage());
   5.121 +            response.setError();
   5.122 +            response.setStatus(404);
   5.123 +        }
   5.124 +    }
   5.125 +    
   5.126 +    static void copyStream(InputStream is, OutputStream os, String baseURL) throws IOException {
   5.127 +        for (;;) {
   5.128 +            int ch = is.read();
   5.129 +            if (ch == -1) {
   5.130 +                break;
   5.131 +            }
   5.132 +            os.write(ch);            
   5.133 +        }
   5.134 +    }
   5.135 +
   5.136 +    @Override
   5.137 +    public InputStream get(String r) throws IOException {
   5.138 +        byte[] arr = data == null ? null : data.get(r);
   5.139 +        return arr == null ? null : new ByteArrayInputStream(arr);
   5.140 +    }
   5.141 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/dew/src/main/java/org/apidesign/bck2brwsr/dew/DewLauncher.java	Wed Jan 23 14:49:52 2013 +0100
     6.3 @@ -0,0 +1,201 @@
     6.4 +/**
     6.5 + * Back 2 Browser Bytecode Translator
     6.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     6.7 + *
     6.8 + * This program is free software: you can redistribute it and/or modify
     6.9 + * it under the terms of the GNU General Public License as published by
    6.10 + * the Free Software Foundation, version 2 of the License.
    6.11 + *
    6.12 + * This program is distributed in the hope that it will be useful,
    6.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.15 + * GNU General Public License for more details.
    6.16 + *
    6.17 + * You should have received a copy of the GNU General Public License
    6.18 + * along with this program. Look for COPYING file in the top folder.
    6.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    6.20 + */
    6.21 +package org.apidesign.bck2brwsr.dew;
    6.22 +
    6.23 +import java.io.IOException;
    6.24 +import java.io.InputStream;
    6.25 +import java.io.Writer;
    6.26 +import java.net.URI;
    6.27 +import java.net.URISyntaxException;
    6.28 +import java.net.URL;
    6.29 +import java.util.Arrays;
    6.30 +import java.util.Enumeration;
    6.31 +import java.util.LinkedHashSet;
    6.32 +import java.util.Set;
    6.33 +import java.util.logging.Level;
    6.34 +import java.util.logging.Logger;
    6.35 +import org.apidesign.vm4brwsr.Bck2Brwsr;
    6.36 +import org.glassfish.grizzly.PortRange;
    6.37 +import org.glassfish.grizzly.http.server.HttpHandler;
    6.38 +import org.glassfish.grizzly.http.server.HttpServer;
    6.39 +import org.glassfish.grizzly.http.server.NetworkListener;
    6.40 +import org.glassfish.grizzly.http.server.Request;
    6.41 +import org.glassfish.grizzly.http.server.Response;
    6.42 +import org.glassfish.grizzly.http.server.ServerConfiguration;
    6.43 +
    6.44 +/**
    6.45 + * Lightweight server to launch dew - the Development Environment for Web.
    6.46 + */
    6.47 +final class DewLauncher {
    6.48 +    private static final Logger LOG = Logger.getLogger(DewLauncher.class.getName());
    6.49 +    private Set<ClassLoader> loaders = new LinkedHashSet<>();
    6.50 +    private Set<Bck2Brwsr.Resources> xRes = new LinkedHashSet<>();
    6.51 +    private final Res resources = new Res();
    6.52 +    private final String cmd;
    6.53 +
    6.54 +    public DewLauncher(String cmd) {
    6.55 +        this.cmd = cmd;
    6.56 +    }
    6.57 +    
    6.58 +    public void addClassLoader(ClassLoader url) {
    6.59 +        this.loaders.add(url);
    6.60 +    }
    6.61 +
    6.62 +    final HttpServer initServer(Bck2Brwsr.Resources... extraResources) {
    6.63 +        xRes.addAll(Arrays.asList(extraResources));
    6.64 +        
    6.65 +        HttpServer s = HttpServer.createSimpleServer(".", new PortRange(8080, 65535));
    6.66 +
    6.67 +        final ServerConfiguration conf = s.getServerConfiguration();
    6.68 +        conf.addHttpHandler(new VM(resources), "/bck2brwsr.js");
    6.69 +        conf.addHttpHandler(new VMInit(), "/vm.js");
    6.70 +        conf.addHttpHandler(new Classes(resources), "/classes/");
    6.71 +        return s;
    6.72 +    }
    6.73 +    
    6.74 +    final Object[] launchServerAndBrwsr(HttpServer server, final String page) throws IOException, URISyntaxException, InterruptedException {
    6.75 +        server.start();
    6.76 +        NetworkListener listener = server.getListeners().iterator().next();
    6.77 +        int port = listener.getPort();
    6.78 +        
    6.79 +        URI uri = new URI("http://localhost:" + port + page);
    6.80 +        LOG.log(Level.INFO, "Showing {0}", uri);
    6.81 +        if (cmd == null) {
    6.82 +            try {
    6.83 +                LOG.log(Level.INFO, "Trying Desktop.browse on {0} {2} by {1}", new Object[] {
    6.84 +                    System.getProperty("java.vm.name"),
    6.85 +                    System.getProperty("java.vm.vendor"),
    6.86 +                    System.getProperty("java.vm.version"),
    6.87 +                });
    6.88 +                java.awt.Desktop.getDesktop().browse(uri);
    6.89 +                LOG.log(Level.INFO, "Desktop.browse successfully finished");
    6.90 +                return null;
    6.91 +            } catch (UnsupportedOperationException ex) {
    6.92 +                LOG.log(Level.INFO, "Desktop.browse not supported: {0}", ex.getMessage());
    6.93 +                LOG.log(Level.FINE, null, ex);
    6.94 +            }
    6.95 +        }
    6.96 +        {
    6.97 +            String cmdName = cmd == null ? "xdg-open" : cmd;
    6.98 +            String[] cmdArr = { 
    6.99 +                cmdName, uri.toString()
   6.100 +            };
   6.101 +            LOG.log(Level.INFO, "Launching {0}", Arrays.toString(cmdArr));
   6.102 +            final Process process = Runtime.getRuntime().exec(cmdArr);
   6.103 +            return new Object[] { process, null };
   6.104 +        }
   6.105 +    }
   6.106 +
   6.107 +    private class Res implements Bck2Brwsr.Resources {
   6.108 +        @Override
   6.109 +        public InputStream get(String resource) throws IOException {
   6.110 +            for (ClassLoader l : loaders) {
   6.111 +                URL u = null;
   6.112 +                Enumeration<URL> en = l.getResources(resource);
   6.113 +                while (en.hasMoreElements()) {
   6.114 +                    u = en.nextElement();
   6.115 +                }
   6.116 +                if (u != null) {
   6.117 +                    return u.openStream();
   6.118 +                }
   6.119 +            }
   6.120 +            for (Bck2Brwsr.Resources r : xRes) {
   6.121 +                InputStream is = r.get(resource);
   6.122 +                if (is != null) {
   6.123 +                    return is;
   6.124 +                }
   6.125 +            }
   6.126 +            throw new IOException("Can't find " + resource);
   6.127 +        }
   6.128 +    }
   6.129 +
   6.130 +    private static class VM extends HttpHandler {
   6.131 +        private final Res loader;
   6.132 +
   6.133 +        public VM(Res loader) {
   6.134 +            this.loader = loader;
   6.135 +        }
   6.136 +
   6.137 +        @Override
   6.138 +        public void service(Request request, Response response) throws Exception {
   6.139 +            response.setCharacterEncoding("UTF-8");
   6.140 +            response.setContentType("text/javascript");
   6.141 +            Bck2Brwsr.generate(response.getWriter(), loader);
   6.142 +        }
   6.143 +    }
   6.144 +    private static class VMInit extends HttpHandler {
   6.145 +        public VMInit() {
   6.146 +        }
   6.147 +
   6.148 +        @Override
   6.149 +        public void service(Request request, Response response) throws Exception {
   6.150 +            response.setCharacterEncoding("UTF-8");
   6.151 +            response.setContentType("text/javascript");
   6.152 +            response.getWriter().append(
   6.153 +                "function ldCls(res) {\n"
   6.154 +                + "  var request = new XMLHttpRequest();\n"
   6.155 +                + "  request.open('GET', '/classes/' + res, false);\n"
   6.156 +                + "  request.send();\n"
   6.157 +                + "  var arr = eval('(' + request.responseText + ')');\n"
   6.158 +                + "  return arr;\n"
   6.159 +                + "}\n"
   6.160 +                + "var vm = new bck2brwsr(ldCls);\n");
   6.161 +        }
   6.162 +    }
   6.163 +
   6.164 +    private static class Classes extends HttpHandler {
   6.165 +        private final Res loader;
   6.166 +
   6.167 +        public Classes(Res loader) {
   6.168 +            this.loader = loader;
   6.169 +        }
   6.170 +
   6.171 +        @Override
   6.172 +        public void service(Request request, Response response) throws Exception {
   6.173 +            String res = request.getHttpHandlerPath();
   6.174 +            if (res.startsWith("/")) {
   6.175 +                res = res.substring(1);
   6.176 +            }
   6.177 +            try (InputStream is = loader.get(res)) {
   6.178 +                response.setContentType("text/javascript");
   6.179 +                Writer w = response.getWriter();
   6.180 +                w.append("[");
   6.181 +                for (int i = 0;; i++) {
   6.182 +                    int b = is.read();
   6.183 +                    if (b == -1) {
   6.184 +                        break;
   6.185 +                    }
   6.186 +                    if (i > 0) {
   6.187 +                        w.append(", ");
   6.188 +                    }
   6.189 +                    if (i % 20 == 0) {
   6.190 +                        w.write("\n");
   6.191 +                    }
   6.192 +                    if (b > 127) {
   6.193 +                        b = b - 256;
   6.194 +                    }
   6.195 +                    w.append(Integer.toString(b));
   6.196 +                }
   6.197 +                w.append("\n]");
   6.198 +            } catch (IOException ex) {
   6.199 +                response.setError();
   6.200 +                response.setDetailMessage(ex.getMessage());
   6.201 +            }
   6.202 +        }
   6.203 +    }
   6.204 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/css/app.css	Wed Jan 23 14:49:52 2013 +0100
     7.3 @@ -0,0 +1,54 @@
     7.4 +/* app css stylesheet */
     7.5 +.code-editor, .mono-font, .CodeMirror {
     7.6 +    font-family: "Inconsolata","Monaco","Consolas","Andale Mono","Bitstream Vera Sans Mono","Courier New",Courier,monospace;
     7.7 +    font-size: 13px;
     7.8 +    line-height: 15px;
     7.9 +}
    7.10 +
    7.11 +.CodeMirror {                    
    7.12 +    border: 1px solid #d9edf7;      
    7.13 +    height: 300px;
    7.14 +}
    7.15 +      
    7.16 +.CodeMirror-scroll {
    7.17 +    overflow-y: auto;
    7.18 +    overflow-x: auto;
    7.19 +}
    7.20 +
    7.21 +.error-hover:hover {
    7.22 +    text-decoration: underline;
    7.23 +    cursor: pointer;
    7.24 +} 
    7.25 +
    7.26 +.ic-html5 {
    7.27 +  display: inline-block;  
    7.28 +  height: 20px;
    7.29 +  width: 20px;
    7.30 +  vertical-align: text-bottom;
    7.31 +  background-repeat: no-repeat;  
    7.32 +  background-image: url("../img/html5.png");  
    7.33 +}
    7.34 +
    7.35 +.ic-java {
    7.36 +  display: inline-block;  
    7.37 +  height: 20px;
    7.38 +  width: 20px;
    7.39 +  vertical-align: text-bottom;
    7.40 +  background-repeat: no-repeat;  
    7.41 +  background-image: url("../img/java.png"); 
    7.42 + 
    7.43 +}
    7.44 +
    7.45 +.issues {    
    7.46 +    width: 16px;
    7.47 +}
    7.48 +
    7.49 +.issue { 
    7.50 +    height: 16px;
    7.51 +    width: 16px;
    7.52 +    vertical-align: middle;
    7.53 +    background-repeat: no-repeat;  
    7.54 +    background-image: url("../img/error.png"); 
    7.55 +    /* color: #822; */
    7.56 +}
    7.57 +
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/css/bootstrap-combined.min.css	Wed Jan 23 14:49:52 2013 +0100
     8.3 @@ -0,0 +1,18 @@
     8.4 +/*!
     8.5 + * Bootstrap v2.2.2
     8.6 + *
     8.7 + * Copyright 2012 Twitter, Inc
     8.8 + * Licensed under the Apache License v2.0
     8.9 + * http://www.apache.org/licenses/LICENSE-2.0
    8.10 + *
    8.11 + * Designed and built with all the love in the world @twitter by @mdo and @fat.
    8.12 + */article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block}audio,canvas,video{display:inline-block;*display:inline;*zoom:1}audio:not([controls]){display:none}html{font-size:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}a:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}a:hover,a:active{outline:0}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{width:auto\9;height:auto;max-width:100%;vertical-align:middle;border:0;-ms-interpolation-mode:bicubic}#map_canvas img,.google-maps img{max-width:none}button,input,select,textarea{margin:0;font-size:100%;vertical-align:middle}button,input{*overflow:visible;line-height:normal}button::-moz-focus-inner,input::-moz-focus-inner{padding:0;border:0}button,html input[type="button"],input[type="reset"],input[type="submit"]{cursor:pointer;-webkit-appearance:button}label,select,button,input[type="button"],input[type="reset"],input[type="submit"],input[type="radio"],input[type="checkbox"]{cursor:pointer}input[type="search"]{-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;-webkit-appearance:textfield}input[type="search"]::-webkit-search-decoration,input[type="search"]::-webkit-search-cancel-button{-webkit-appearance:none}textarea{overflow:auto;vertical-align:top}@media print{*{color:#000!important;text-shadow:none!important;background:transparent!important;box-shadow:none!important}a,a:visited{text-decoration:underline}a[href]:after{content:" (" attr(href) ")"}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100%!important}@page{margin:.5cm}p,h2,h3{orphans:3;widows:3}h2,h3{page-break-after:avoid}}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;line-height:0;content:""}.clearfix:after{clear:both}.hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.input-block-level{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}body{margin:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;line-height:20px;color:#333;background-color:#fff}a{color:#08c;text-decoration:none}a:hover{color:#005580;text-decoration:underline}.img-rounded{-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.img-polaroid{padding:4px;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.1);-moz-box-shadow:0 1px 3px rgba(0,0,0,0.1);box-shadow:0 1px 3px rgba(0,0,0,0.1)}.img-circle{-webkit-border-radius:500px;-moz-border-radius:500px;border-radius:500px}.row{margin-left:-20px;*zoom:1}.row:before,.row:after{display:table;line-height:0;content:""}.row:after{clear:both}[class*="span"]{float:left;min-height:1px;margin-left:20px}.container,.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:940px}.span12{width:940px}.span11{width:860px}.span10{width:780px}.span9{width:700px}.span8{width:620px}.span7{width:540px}.span6{width:460px}.span5{width:380px}.span4{width:300px}.span3{width:220px}.span2{width:140px}.span1{width:60px}.offset12{margin-left:980px}.offset11{margin-left:900px}.offset10{margin-left:820px}.offset9{margin-left:740px}.offset8{margin-left:660px}.offset7{margin-left:580px}.offset6{margin-left:500px}.offset5{margin-left:420px}.offset4{margin-left:340px}.offset3{margin-left:260px}.offset2{margin-left:180px}.offset1{margin-left:100px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;line-height:0;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:30px;margin-left:2.127659574468085%;*margin-left:2.074468085106383%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .controls-row [class*="span"]+[class*="span"]{margin-left:2.127659574468085%}.row-fluid .span12{width:100%;*width:99.94680851063829%}.row-fluid .span11{width:91.48936170212765%;*width:91.43617021276594%}.row-fluid .span10{width:82.97872340425532%;*width:82.92553191489361%}.row-fluid .span9{width:74.46808510638297%;*width:74.41489361702126%}.row-fluid .span8{width:65.95744680851064%;*width:65.90425531914893%}.row-fluid .span7{width:57.44680851063829%;*width:57.39361702127659%}.row-fluid .span6{width:48.93617021276595%;*width:48.88297872340425%}.row-fluid .span5{width:40.42553191489362%;*width:40.37234042553192%}.row-fluid .span4{width:31.914893617021278%;*width:31.861702127659576%}.row-fluid .span3{width:23.404255319148934%;*width:23.351063829787233%}.row-fluid .span2{width:14.893617021276595%;*width:14.840425531914894%}.row-fluid .span1{width:6.382978723404255%;*width:6.329787234042553%}.row-fluid .offset12{margin-left:104.25531914893617%;*margin-left:104.14893617021275%}.row-fluid .offset12:first-child{margin-left:102.12765957446808%;*margin-left:102.02127659574467%}.row-fluid .offset11{margin-left:95.74468085106382%;*margin-left:95.6382978723404%}.row-fluid .offset11:first-child{margin-left:93.61702127659574%;*margin-left:93.51063829787232%}.row-fluid .offset10{margin-left:87.23404255319149%;*margin-left:87.12765957446807%}.row-fluid .offset10:first-child{margin-left:85.1063829787234%;*margin-left:84.99999999999999%}.row-fluid .offset9{margin-left:78.72340425531914%;*margin-left:78.61702127659572%}.row-fluid .offset9:first-child{margin-left:76.59574468085106%;*margin-left:76.48936170212764%}.row-fluid .offset8{margin-left:70.2127659574468%;*margin-left:70.10638297872339%}.row-fluid .offset8:first-child{margin-left:68.08510638297872%;*margin-left:67.9787234042553%}.row-fluid .offset7{margin-left:61.70212765957446%;*margin-left:61.59574468085106%}.row-fluid .offset7:first-child{margin-left:59.574468085106375%;*margin-left:59.46808510638297%}.row-fluid .offset6{margin-left:53.191489361702125%;*margin-left:53.085106382978715%}.row-fluid .offset6:first-child{margin-left:51.063829787234035%;*margin-left:50.95744680851063%}.row-fluid .offset5{margin-left:44.68085106382979%;*margin-left:44.57446808510638%}.row-fluid .offset5:first-child{margin-left:42.5531914893617%;*margin-left:42.4468085106383%}.row-fluid .offset4{margin-left:36.170212765957444%;*margin-left:36.06382978723405%}.row-fluid .offset4:first-child{margin-left:34.04255319148936%;*margin-left:33.93617021276596%}.row-fluid .offset3{margin-left:27.659574468085104%;*margin-left:27.5531914893617%}.row-fluid .offset3:first-child{margin-left:25.53191489361702%;*margin-left:25.425531914893618%}.row-fluid .offset2{margin-left:19.148936170212764%;*margin-left:19.04255319148936%}.row-fluid .offset2:first-child{margin-left:17.02127659574468%;*margin-left:16.914893617021278%}.row-fluid .offset1{margin-left:10.638297872340425%;*margin-left:10.53191489361702%}.row-fluid .offset1:first-child{margin-left:8.51063829787234%;*margin-left:8.404255319148938%}[class*="span"].hide,.row-fluid [class*="span"].hide{display:none}[class*="span"].pull-right,.row-fluid [class*="span"].pull-right{float:right}.container{margin-right:auto;margin-left:auto;*zoom:1}.container:before,.container:after{display:table;line-height:0;content:""}.container:after{clear:both}.container-fluid{padding-right:20px;padding-left:20px;*zoom:1}.container-fluid:before,.container-fluid:after{display:table;line-height:0;content:""}.container-fluid:after{clear:both}p{margin:0 0 10px}.lead{margin-bottom:20px;font-size:21px;font-weight:200;line-height:30px}small{font-size:85%}strong{font-weight:bold}em{font-style:italic}cite{font-style:normal}.muted{color:#999}a.muted:hover{color:#808080}.text-warning{color:#c09853}a.text-warning:hover{color:#a47e3c}.text-error{color:#b94a48}a.text-error:hover{color:#953b39}.text-info{color:#3a87ad}a.text-info:hover{color:#2d6987}.text-success{color:#468847}a.text-success:hover{color:#356635}h1,h2,h3,h4,h5,h6{margin:10px 0;font-family:inherit;font-weight:bold;line-height:20px;color:inherit;text-rendering:optimizelegibility}h1 small,h2 small,h3 small,h4 small,h5 small,h6 small{font-weight:normal;line-height:1;color:#999}h1,h2,h3{line-height:40px}h1{font-size:38.5px}h2{font-size:31.5px}h3{font-size:24.5px}h4{font-size:17.5px}h5{font-size:14px}h6{font-size:11.9px}h1 small{font-size:24.5px}h2 small{font-size:17.5px}h3 small{font-size:14px}h4 small{font-size:14px}.page-header{padding-bottom:9px;margin:20px 0 30px;border-bottom:1px solid #eee}ul,ol{padding:0;margin:0 0 10px 25px}ul ul,ul ol,ol ol,ol ul{margin-bottom:0}li{line-height:20px}ul.unstyled,ol.unstyled{margin-left:0;list-style:none}ul.inline,ol.inline{margin-left:0;list-style:none}ul.inline>li,ol.inline>li{display:inline-block;padding-right:5px;padding-left:5px}dl{margin-bottom:20px}dt,dd{line-height:20px}dt{font-weight:bold}dd{margin-left:10px}.dl-horizontal{*zoom:1}.dl-horizontal:before,.dl-horizontal:after{display:table;line-height:0;content:""}.dl-horizontal:after{clear:both}.dl-horizontal dt{float:left;width:160px;overflow:hidden;clear:left;text-align:right;text-overflow:ellipsis;white-space:nowrap}.dl-horizontal dd{margin-left:180px}hr{margin:20px 0;border:0;border-top:1px solid #eee;border-bottom:1px solid #fff}abbr[title],abbr[data-original-title]{cursor:help;border-bottom:1px dotted #999}abbr.initialism{font-size:90%;text-transform:uppercase}blockquote{padding:0 0 0 15px;margin:0 0 20px;border-left:5px solid #eee}blockquote p{margin-bottom:0;font-size:16px;font-weight:300;line-height:25px}blockquote small{display:block;line-height:20px;color:#999}blockquote small:before{content:'\2014 \00A0'}blockquote.pull-right{float:right;padding-right:15px;padding-left:0;border-right:5px solid #eee;border-left:0}blockquote.pull-right p,blockquote.pull-right small{text-align:right}blockquote.pull-right small:before{content:''}blockquote.pull-right small:after{content:'\00A0 \2014'}q:before,q:after,blockquote:before,blockquote:after{content:""}address{display:block;margin-bottom:20px;font-style:normal;line-height:20px}code,pre{padding:0 3px 2px;font-family:Monaco,Menlo,Consolas,"Courier New",monospace;font-size:12px;color:#333;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}code{padding:2px 4px;color:#d14;white-space:nowrap;background-color:#f7f7f9;border:1px solid #e1e1e8}pre{display:block;padding:9.5px;margin:0 0 10px;font-size:13px;line-height:20px;word-break:break-all;word-wrap:break-word;white-space:pre;white-space:pre-wrap;background-color:#f5f5f5;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.15);-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}pre.prettyprint{margin-bottom:20px}pre code{padding:0;color:inherit;white-space:pre;white-space:pre-wrap;background-color:transparent;border:0}.pre-scrollable{max-height:340px;overflow-y:scroll}form{margin:0 0 20px}fieldset{padding:0;margin:0;border:0}legend{display:block;width:100%;padding:0;margin-bottom:20px;font-size:21px;line-height:40px;color:#333;border:0;border-bottom:1px solid #e5e5e5}legend small{font-size:15px;color:#999}label,input,button,select,textarea{font-size:14px;font-weight:normal;line-height:20px}input,button,select,textarea{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif}label{display:block;margin-bottom:5px}select,textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{display:inline-block;height:20px;padding:4px 6px;margin-bottom:10px;font-size:14px;line-height:20px;color:#555;vertical-align:middle;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}input,textarea,.uneditable-input{width:206px}textarea{height:auto}textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{background-color:#fff;border:1px solid #ccc;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border linear .2s,box-shadow linear .2s;-moz-transition:border linear .2s,box-shadow linear .2s;-o-transition:border linear .2s,box-shadow linear .2s;transition:border linear .2s,box-shadow linear .2s}textarea:focus,input[type="text"]:focus,input[type="password"]:focus,input[type="datetime"]:focus,input[type="datetime-local"]:focus,input[type="date"]:focus,input[type="month"]:focus,input[type="time"]:focus,input[type="week"]:focus,input[type="number"]:focus,input[type="email"]:focus,input[type="url"]:focus,input[type="search"]:focus,input[type="tel"]:focus,input[type="color"]:focus,.uneditable-input:focus{border-color:rgba(82,168,236,0.8);outline:0;outline:thin dotted \9;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6)}input[type="radio"],input[type="checkbox"]{margin:4px 0 0;margin-top:1px \9;*margin-top:0;line-height:normal}input[type="file"],input[type="image"],input[type="submit"],input[type="reset"],input[type="button"],input[type="radio"],input[type="checkbox"]{width:auto}select,input[type="file"]{height:30px;*margin-top:4px;line-height:30px}select{width:220px;background-color:#fff;border:1px solid #ccc}select[multiple],select[size]{height:auto}select:focus,input[type="file"]:focus,input[type="radio"]:focus,input[type="checkbox"]:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.uneditable-input,.uneditable-textarea{color:#999;cursor:not-allowed;background-color:#fcfcfc;border-color:#ccc;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.025);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.025);box-shadow:inset 0 1px 2px rgba(0,0,0,0.025)}.uneditable-input{overflow:hidden;white-space:nowrap}.uneditable-textarea{width:auto;height:auto}input:-moz-placeholder,textarea:-moz-placeholder{color:#999}input:-ms-input-placeholder,textarea:-ms-input-placeholder{color:#999}input::-webkit-input-placeholder,textarea::-webkit-input-placeholder{color:#999}.radio,.checkbox{min-height:20px;padding-left:20px}.radio input[type="radio"],.checkbox input[type="checkbox"]{float:left;margin-left:-20px}.controls>.radio:first-child,.controls>.checkbox:first-child{padding-top:5px}.radio.inline,.checkbox.inline{display:inline-block;padding-top:5px;margin-bottom:0;vertical-align:middle}.radio.inline+.radio.inline,.checkbox.inline+.checkbox.inline{margin-left:10px}.input-mini{width:60px}.input-small{width:90px}.input-medium{width:150px}.input-large{width:210px}.input-xlarge{width:270px}.input-xxlarge{width:530px}input[class*="span"],select[class*="span"],textarea[class*="span"],.uneditable-input[class*="span"],.row-fluid input[class*="span"],.row-fluid select[class*="span"],.row-fluid textarea[class*="span"],.row-fluid .uneditable-input[class*="span"]{float:none;margin-left:0}.input-append input[class*="span"],.input-append .uneditable-input[class*="span"],.input-prepend input[class*="span"],.input-prepend .uneditable-input[class*="span"],.row-fluid input[class*="span"],.row-fluid select[class*="span"],.row-fluid textarea[class*="span"],.row-fluid .uneditable-input[class*="span"],.row-fluid .input-prepend [class*="span"],.row-fluid .input-append [class*="span"]{display:inline-block}input,textarea,.uneditable-input{margin-left:0}.controls-row [class*="span"]+[class*="span"]{margin-left:20px}input.span12,textarea.span12,.uneditable-input.span12{width:926px}input.span11,textarea.span11,.uneditable-input.span11{width:846px}input.span10,textarea.span10,.uneditable-input.span10{width:766px}input.span9,textarea.span9,.uneditable-input.span9{width:686px}input.span8,textarea.span8,.uneditable-input.span8{width:606px}input.span7,textarea.span7,.uneditable-input.span7{width:526px}input.span6,textarea.span6,.uneditable-input.span6{width:446px}input.span5,textarea.span5,.uneditable-input.span5{width:366px}input.span4,textarea.span4,.uneditable-input.span4{width:286px}input.span3,textarea.span3,.uneditable-input.span3{width:206px}input.span2,textarea.span2,.uneditable-input.span2{width:126px}input.span1,textarea.span1,.uneditable-input.span1{width:46px}.controls-row{*zoom:1}.controls-row:before,.controls-row:after{display:table;line-height:0;content:""}.controls-row:after{clear:both}.controls-row [class*="span"],.row-fluid .controls-row [class*="span"]{float:left}.controls-row .checkbox[class*="span"],.controls-row .radio[class*="span"]{padding-top:5px}input[disabled],select[disabled],textarea[disabled],input[readonly],select[readonly],textarea[readonly]{cursor:not-allowed;background-color:#eee}input[type="radio"][disabled],input[type="checkbox"][disabled],input[type="radio"][readonly],input[type="checkbox"][readonly]{background-color:transparent}.control-group.warning .control-label,.control-group.warning .help-block,.control-group.warning .help-inline{color:#c09853}.control-group.warning .checkbox,.control-group.warning .radio,.control-group.warning input,.control-group.warning select,.control-group.warning textarea{color:#c09853}.control-group.warning input,.control-group.warning select,.control-group.warning textarea{border-color:#c09853;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.warning input:focus,.control-group.warning select:focus,.control-group.warning textarea:focus{border-color:#a47e3c;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e}.control-group.warning .input-prepend .add-on,.control-group.warning .input-append .add-on{color:#c09853;background-color:#fcf8e3;border-color:#c09853}.control-group.error .control-label,.control-group.error .help-block,.control-group.error .help-inline{color:#b94a48}.control-group.error .checkbox,.control-group.error .radio,.control-group.error input,.control-group.error select,.control-group.error textarea{color:#b94a48}.control-group.error input,.control-group.error select,.control-group.error textarea{border-color:#b94a48;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.error input:focus,.control-group.error select:focus,.control-group.error textarea:focus{border-color:#953b39;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #d59392;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #d59392;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #d59392}.control-group.error .input-prepend .add-on,.control-group.error .input-append .add-on{color:#b94a48;background-color:#f2dede;border-color:#b94a48}.control-group.success .control-label,.control-group.success .help-block,.control-group.success .help-inline{color:#468847}.control-group.success .checkbox,.control-group.success .radio,.control-group.success input,.control-group.success select,.control-group.success textarea{color:#468847}.control-group.success input,.control-group.success select,.control-group.success textarea{border-color:#468847;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.success input:focus,.control-group.success select:focus,.control-group.success textarea:focus{border-color:#356635;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7aba7b;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7aba7b;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7aba7b}.control-group.success .input-prepend .add-on,.control-group.success .input-append .add-on{color:#468847;background-color:#dff0d8;border-color:#468847}.control-group.info .control-label,.control-group.info .help-block,.control-group.info .help-inline{color:#3a87ad}.control-group.info .checkbox,.control-group.info .radio,.control-group.info input,.control-group.info select,.control-group.info textarea{color:#3a87ad}.control-group.info input,.control-group.info select,.control-group.info textarea{border-color:#3a87ad;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.info input:focus,.control-group.info select:focus,.control-group.info textarea:focus{border-color:#2d6987;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7ab5d3;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7ab5d3;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7ab5d3}.control-group.info .input-prepend .add-on,.control-group.info .input-append .add-on{color:#3a87ad;background-color:#d9edf7;border-color:#3a87ad}input:focus:invalid,textarea:focus:invalid,select:focus:invalid{color:#b94a48;border-color:#ee5f5b}input:focus:invalid:focus,textarea:focus:invalid:focus,select:focus:invalid:focus{border-color:#e9322d;-webkit-box-shadow:0 0 6px #f8b9b7;-moz-box-shadow:0 0 6px #f8b9b7;box-shadow:0 0 6px #f8b9b7}.form-actions{padding:19px 20px 20px;margin-top:20px;margin-bottom:20px;background-color:#f5f5f5;border-top:1px solid #e5e5e5;*zoom:1}.form-actions:before,.form-actions:after{display:table;line-height:0;content:""}.form-actions:after{clear:both}.help-block,.help-inline{color:#595959}.help-block{display:block;margin-bottom:10px}.help-inline{display:inline-block;*display:inline;padding-left:5px;vertical-align:middle;*zoom:1}.input-append,.input-prepend{margin-bottom:5px;font-size:0;white-space:nowrap}.input-append input,.input-prepend input,.input-append select,.input-prepend select,.input-append .uneditable-input,.input-prepend .uneditable-input,.input-append .dropdown-menu,.input-prepend .dropdown-menu{font-size:14px}.input-append input,.input-prepend input,.input-append select,.input-prepend select,.input-append .uneditable-input,.input-prepend .uneditable-input{position:relative;margin-bottom:0;*margin-left:0;vertical-align:top;-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-append input:focus,.input-prepend input:focus,.input-append select:focus,.input-prepend select:focus,.input-append .uneditable-input:focus,.input-prepend .uneditable-input:focus{z-index:2}.input-append .add-on,.input-prepend .add-on{display:inline-block;width:auto;height:20px;min-width:16px;padding:4px 5px;font-size:14px;font-weight:normal;line-height:20px;text-align:center;text-shadow:0 1px 0 #fff;background-color:#eee;border:1px solid #ccc}.input-append .add-on,.input-prepend .add-on,.input-append .btn,.input-prepend .btn,.input-append .btn-group>.dropdown-toggle,.input-prepend .btn-group>.dropdown-toggle{vertical-align:top;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.input-append .active,.input-prepend .active{background-color:#a9dba9;border-color:#46a546}.input-prepend .add-on,.input-prepend .btn{margin-right:-1px}.input-prepend .add-on:first-child,.input-prepend .btn:first-child{-webkit-border-radius:4px 0 0 4px;-moz-border-radius:4px 0 0 4px;border-radius:4px 0 0 4px}.input-append input,.input-append select,.input-append .uneditable-input{-webkit-border-radius:4px 0 0 4px;-moz-border-radius:4px 0 0 4px;border-radius:4px 0 0 4px}.input-append input+.btn-group .btn:last-child,.input-append select+.btn-group .btn:last-child,.input-append .uneditable-input+.btn-group .btn:last-child{-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-append .add-on,.input-append .btn,.input-append .btn-group{margin-left:-1px}.input-append .add-on:last-child,.input-append .btn:last-child,.input-append .btn-group:last-child>.dropdown-toggle{-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-prepend.input-append input,.input-prepend.input-append select,.input-prepend.input-append .uneditable-input{-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.input-prepend.input-append input+.btn-group .btn,.input-prepend.input-append select+.btn-group .btn,.input-prepend.input-append .uneditable-input+.btn-group .btn{-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-prepend.input-append .add-on:first-child,.input-prepend.input-append .btn:first-child{margin-right:-1px;-webkit-border-radius:4px 0 0 4px;-moz-border-radius:4px 0 0 4px;border-radius:4px 0 0 4px}.input-prepend.input-append .add-on:last-child,.input-prepend.input-append .btn:last-child{margin-left:-1px;-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.input-prepend.input-append .btn-group:first-child{margin-left:0}input.search-query{padding-right:14px;padding-right:4px \9;padding-left:14px;padding-left:4px \9;margin-bottom:0;-webkit-border-radius:15px;-moz-border-radius:15px;border-radius:15px}.form-search .input-append .search-query,.form-search .input-prepend .search-query{-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.form-search .input-append .search-query{-webkit-border-radius:14px 0 0 14px;-moz-border-radius:14px 0 0 14px;border-radius:14px 0 0 14px}.form-search .input-append .btn{-webkit-border-radius:0 14px 14px 0;-moz-border-radius:0 14px 14px 0;border-radius:0 14px 14px 0}.form-search .input-prepend .search-query{-webkit-border-radius:0 14px 14px 0;-moz-border-radius:0 14px 14px 0;border-radius:0 14px 14px 0}.form-search .input-prepend .btn{-webkit-border-radius:14px 0 0 14px;-moz-border-radius:14px 0 0 14px;border-radius:14px 0 0 14px}.form-search input,.form-inline input,.form-horizontal input,.form-search textarea,.form-inline textarea,.form-horizontal textarea,.form-search select,.form-inline select,.form-horizontal select,.form-search .help-inline,.form-inline .help-inline,.form-horizontal .help-inline,.form-search .uneditable-input,.form-inline .uneditable-input,.form-horizontal .uneditable-input,.form-search .input-prepend,.form-inline .input-prepend,.form-horizontal .input-prepend,.form-search .input-append,.form-inline .input-append,.form-horizontal .input-append{display:inline-block;*display:inline;margin-bottom:0;vertical-align:middle;*zoom:1}.form-search .hide,.form-inline .hide,.form-horizontal .hide{display:none}.form-search label,.form-inline label,.form-search .btn-group,.form-inline .btn-group{display:inline-block}.form-search .input-append,.form-inline .input-append,.form-search .input-prepend,.form-inline .input-prepend{margin-bottom:0}.form-search .radio,.form-search .checkbox,.form-inline .radio,.form-inline .checkbox{padding-left:0;margin-bottom:0;vertical-align:middle}.form-search .radio input[type="radio"],.form-search .checkbox input[type="checkbox"],.form-inline .radio input[type="radio"],.form-inline .checkbox input[type="checkbox"]{float:left;margin-right:3px;margin-left:0}.control-group{margin-bottom:10px}legend+.control-group{margin-top:20px;-webkit-margin-top-collapse:separate}.form-horizontal .control-group{margin-bottom:20px;*zoom:1}.form-horizontal .control-group:before,.form-horizontal .control-group:after{display:table;line-height:0;content:""}.form-horizontal .control-group:after{clear:both}.form-horizontal .control-label{float:left;width:160px;padding-top:5px;text-align:right}.form-horizontal .controls{*display:inline-block;*padding-left:20px;margin-left:180px;*margin-left:0}.form-horizontal .controls:first-child{*padding-left:180px}.form-horizontal .help-block{margin-bottom:0}.form-horizontal input+.help-block,.form-horizontal select+.help-block,.form-horizontal textarea+.help-block,.form-horizontal .uneditable-input+.help-block,.form-horizontal .input-prepend+.help-block,.form-horizontal .input-append+.help-block{margin-top:10px}.form-horizontal .form-actions{padding-left:180px}table{max-width:100%;background-color:transparent;border-collapse:collapse;border-spacing:0}.table{width:100%;margin-bottom:20px}.table th,.table td{padding:8px;line-height:20px;text-align:left;vertical-align:top;border-top:1px solid #ddd}.table th{font-weight:bold}.table thead th{vertical-align:bottom}.table caption+thead tr:first-child th,.table caption+thead tr:first-child td,.table colgroup+thead tr:first-child th,.table colgroup+thead tr:first-child td,.table thead:first-child tr:first-child th,.table thead:first-child tr:first-child td{border-top:0}.table tbody+tbody{border-top:2px solid #ddd}.table .table{background-color:#fff}.table-condensed th,.table-condensed td{padding:4px 5px}.table-bordered{border:1px solid #ddd;border-collapse:separate;*border-collapse:collapse;border-left:0;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.table-bordered th,.table-bordered td{border-left:1px solid #ddd}.table-bordered caption+thead tr:first-child th,.table-bordered caption+tbody tr:first-child th,.table-bordered caption+tbody tr:first-child td,.table-bordered colgroup+thead tr:first-child th,.table-bordered colgroup+tbody tr:first-child th,.table-bordered colgroup+tbody tr:first-child td,.table-bordered thead:first-child tr:first-child th,.table-bordered tbody:first-child tr:first-child th,.table-bordered tbody:first-child tr:first-child td{border-top:0}.table-bordered thead:first-child tr:first-child>th:first-child,.table-bordered tbody:first-child tr:first-child>td:first-child{-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-topleft:4px}.table-bordered thead:first-child tr:first-child>th:last-child,.table-bordered tbody:first-child tr:first-child>td:last-child{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-moz-border-radius-topright:4px}.table-bordered thead:last-child tr:last-child>th:first-child,.table-bordered tbody:last-child tr:last-child>td:first-child,.table-bordered tfoot:last-child tr:last-child>td:first-child{-webkit-border-bottom-left-radius:4px;border-bottom-left-radius:4px;-moz-border-radius-bottomleft:4px}.table-bordered thead:last-child tr:last-child>th:last-child,.table-bordered tbody:last-child tr:last-child>td:last-child,.table-bordered tfoot:last-child tr:last-child>td:last-child{-webkit-border-bottom-right-radius:4px;border-bottom-right-radius:4px;-moz-border-radius-bottomright:4px}.table-bordered tfoot+tbody:last-child tr:last-child td:first-child{-webkit-border-bottom-left-radius:0;border-bottom-left-radius:0;-moz-border-radius-bottomleft:0}.table-bordered tfoot+tbody:last-child tr:last-child td:last-child{-webkit-border-bottom-right-radius:0;border-bottom-right-radius:0;-moz-border-radius-bottomright:0}.table-bordered caption+thead tr:first-child th:first-child,.table-bordered caption+tbody tr:first-child td:first-child,.table-bordered colgroup+thead tr:first-child th:first-child,.table-bordered colgroup+tbody tr:first-child td:first-child{-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-topleft:4px}.table-bordered caption+thead tr:first-child th:last-child,.table-bordered caption+tbody tr:first-child td:last-child,.table-bordered colgroup+thead tr:first-child th:last-child,.table-bordered colgroup+tbody tr:first-child td:last-child{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-moz-border-radius-topright:4px}.table-striped tbody>tr:nth-child(odd)>td,.table-striped tbody>tr:nth-child(odd)>th{background-color:#f9f9f9}.table-hover tbody tr:hover td,.table-hover tbody tr:hover th{background-color:#f5f5f5}table td[class*="span"],table th[class*="span"],.row-fluid table td[class*="span"],.row-fluid table th[class*="span"]{display:table-cell;float:none;margin-left:0}.table td.span1,.table th.span1{float:none;width:44px;margin-left:0}.table td.span2,.table th.span2{float:none;width:124px;margin-left:0}.table td.span3,.table th.span3{float:none;width:204px;margin-left:0}.table td.span4,.table th.span4{float:none;width:284px;margin-left:0}.table td.span5,.table th.span5{float:none;width:364px;margin-left:0}.table td.span6,.table th.span6{float:none;width:444px;margin-left:0}.table td.span7,.table th.span7{float:none;width:524px;margin-left:0}.table td.span8,.table th.span8{float:none;width:604px;margin-left:0}.table td.span9,.table th.span9{float:none;width:684px;margin-left:0}.table td.span10,.table th.span10{float:none;width:764px;margin-left:0}.table td.span11,.table th.span11{float:none;width:844px;margin-left:0}.table td.span12,.table th.span12{float:none;width:924px;margin-left:0}.table tbody tr.success td{background-color:#dff0d8}.table tbody tr.error td{background-color:#f2dede}.table tbody tr.warning td{background-color:#fcf8e3}.table tbody tr.info td{background-color:#d9edf7}.table-hover tbody tr.success:hover td{background-color:#d0e9c6}.table-hover tbody tr.error:hover td{background-color:#ebcccc}.table-hover tbody tr.warning:hover td{background-color:#faf2cc}.table-hover tbody tr.info:hover td{background-color:#c4e3f3}[class^="icon-"],[class*=" icon-"]{display:inline-block;width:14px;height:14px;margin-top:1px;*margin-right:.3em;line-height:14px;vertical-align:text-top;background-image:url("../img/glyphicons-halflings.png");background-position:14px 14px;background-repeat:no-repeat}.icon-white,.nav-pills>.active>a>[class^="icon-"],.nav-pills>.active>a>[class*=" icon-"],.nav-list>.active>a>[class^="icon-"],.nav-list>.active>a>[class*=" icon-"],.navbar-inverse .nav>.active>a>[class^="icon-"],.navbar-inverse .nav>.active>a>[class*=" icon-"],.dropdown-menu>li>a:hover>[class^="icon-"],.dropdown-menu>li>a:hover>[class*=" icon-"],.dropdown-menu>.active>a>[class^="icon-"],.dropdown-menu>.active>a>[class*=" icon-"],.dropdown-submenu:hover>a>[class^="icon-"],.dropdown-submenu:hover>a>[class*=" icon-"]{background-image:url("../img/glyphicons-halflings-white.png")}.icon-glass{background-position:0 0}.icon-music{background-position:-24px 0}.icon-search{background-position:-48px 0}.icon-envelope{background-position:-72px 0}.icon-heart{background-position:-96px 0}.icon-star{background-position:-120px 0}.icon-star-empty{background-position:-144px 0}.icon-user{background-position:-168px 0}.icon-film{background-position:-192px 0}.icon-th-large{background-position:-216px 0}.icon-th{background-position:-240px 0}.icon-th-list{background-position:-264px 0}.icon-ok{background-position:-288px 0}.icon-remove{background-position:-312px 0}.icon-zoom-in{background-position:-336px 0}.icon-zoom-out{background-position:-360px 0}.icon-off{background-position:-384px 0}.icon-signal{background-position:-408px 0}.icon-cog{background-position:-432px 0}.icon-trash{background-position:-456px 0}.icon-home{background-position:0 -24px}.icon-file{background-position:-24px -24px}.icon-time{background-position:-48px -24px}.icon-road{background-position:-72px -24px}.icon-download-alt{background-position:-96px -24px}.icon-download{background-position:-120px -24px}.icon-upload{background-position:-144px -24px}.icon-inbox{background-position:-168px -24px}.icon-play-circle{background-position:-192px -24px}.icon-repeat{background-position:-216px -24px}.icon-refresh{background-position:-240px -24px}.icon-list-alt{background-position:-264px -24px}.icon-lock{background-position:-287px -24px}.icon-flag{background-position:-312px -24px}.icon-headphones{background-position:-336px -24px}.icon-volume-off{background-position:-360px -24px}.icon-volume-down{background-position:-384px -24px}.icon-volume-up{background-position:-408px -24px}.icon-qrcode{background-position:-432px -24px}.icon-barcode{background-position:-456px -24px}.icon-tag{background-position:0 -48px}.icon-tags{background-position:-25px -48px}.icon-book{background-position:-48px -48px}.icon-bookmark{background-position:-72px -48px}.icon-print{background-position:-96px -48px}.icon-camera{background-position:-120px -48px}.icon-font{background-position:-144px -48px}.icon-bold{background-position:-167px -48px}.icon-italic{background-position:-192px -48px}.icon-text-height{background-position:-216px -48px}.icon-text-width{background-position:-240px -48px}.icon-align-left{background-position:-264px -48px}.icon-align-center{background-position:-288px -48px}.icon-align-right{background-position:-312px -48px}.icon-align-justify{background-position:-336px -48px}.icon-list{background-position:-360px -48px}.icon-indent-left{background-position:-384px -48px}.icon-indent-right{background-position:-408px -48px}.icon-facetime-video{background-position:-432px -48px}.icon-picture{background-position:-456px -48px}.icon-pencil{background-position:0 -72px}.icon-map-marker{background-position:-24px -72px}.icon-adjust{background-position:-48px -72px}.icon-tint{background-position:-72px -72px}.icon-edit{background-position:-96px -72px}.icon-share{background-position:-120px -72px}.icon-check{background-position:-144px -72px}.icon-move{background-position:-168px -72px}.icon-step-backward{background-position:-192px -72px}.icon-fast-backward{background-position:-216px -72px}.icon-backward{background-position:-240px -72px}.icon-play{background-position:-264px -72px}.icon-pause{background-position:-288px -72px}.icon-stop{background-position:-312px -72px}.icon-forward{background-position:-336px -72px}.icon-fast-forward{background-position:-360px -72px}.icon-step-forward{background-position:-384px -72px}.icon-eject{background-position:-408px -72px}.icon-chevron-left{background-position:-432px -72px}.icon-chevron-right{background-position:-456px -72px}.icon-plus-sign{background-position:0 -96px}.icon-minus-sign{background-position:-24px -96px}.icon-remove-sign{background-position:-48px -96px}.icon-ok-sign{background-position:-72px -96px}.icon-question-sign{background-position:-96px -96px}.icon-info-sign{background-position:-120px -96px}.icon-screenshot{background-position:-144px -96px}.icon-remove-circle{background-position:-168px -96px}.icon-ok-circle{background-position:-192px -96px}.icon-ban-circle{background-position:-216px -96px}.icon-arrow-left{background-position:-240px -96px}.icon-arrow-right{background-position:-264px -96px}.icon-arrow-up{background-position:-289px -96px}.icon-arrow-down{background-position:-312px -96px}.icon-share-alt{background-position:-336px -96px}.icon-resize-full{background-position:-360px -96px}.icon-resize-small{background-position:-384px -96px}.icon-plus{background-position:-408px -96px}.icon-minus{background-position:-433px -96px}.icon-asterisk{background-position:-456px -96px}.icon-exclamation-sign{background-position:0 -120px}.icon-gift{background-position:-24px -120px}.icon-leaf{background-position:-48px -120px}.icon-fire{background-position:-72px -120px}.icon-eye-open{background-position:-96px -120px}.icon-eye-close{background-position:-120px -120px}.icon-warning-sign{background-position:-144px -120px}.icon-plane{background-position:-168px -120px}.icon-calendar{background-position:-192px -120px}.icon-random{width:16px;background-position:-216px -120px}.icon-comment{background-position:-240px -120px}.icon-magnet{background-position:-264px -120px}.icon-chevron-up{background-position:-288px -120px}.icon-chevron-down{background-position:-313px -119px}.icon-retweet{background-position:-336px -120px}.icon-shopping-cart{background-position:-360px -120px}.icon-folder-close{background-position:-384px -120px}.icon-folder-open{width:16px;background-position:-408px -120px}.icon-resize-vertical{background-position:-432px -119px}.icon-resize-horizontal{background-position:-456px -118px}.icon-hdd{background-position:0 -144px}.icon-bullhorn{background-position:-24px -144px}.icon-bell{background-position:-48px -144px}.icon-certificate{background-position:-72px -144px}.icon-thumbs-up{background-position:-96px -144px}.icon-thumbs-down{background-position:-120px -144px}.icon-hand-right{background-position:-144px -144px}.icon-hand-left{background-position:-168px -144px}.icon-hand-up{background-position:-192px -144px}.icon-hand-down{background-position:-216px -144px}.icon-circle-arrow-right{background-position:-240px -144px}.icon-circle-arrow-left{background-position:-264px -144px}.icon-circle-arrow-up{background-position:-288px -144px}.icon-circle-arrow-down{background-position:-312px -144px}.icon-globe{background-position:-336px -144px}.icon-wrench{background-position:-360px -144px}.icon-tasks{background-position:-384px -144px}.icon-filter{background-position:-408px -144px}.icon-briefcase{background-position:-432px -144px}.icon-fullscreen{background-position:-456px -144px}.dropup,.dropdown{position:relative}.dropdown-toggle{*margin-bottom:-3px}.dropdown-toggle:active,.open .dropdown-toggle{outline:0}.caret{display:inline-block;width:0;height:0;vertical-align:top;border-top:4px solid #000;border-right:4px solid transparent;border-left:4px solid transparent;content:""}.dropdown .caret{margin-top:8px;margin-left:2px}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;list-style:none;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);*border-right-width:2px;*border-bottom-width:2px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;-webkit-box-shadow:0 5px 10px rgba(0,0,0,0.2);-moz-box-shadow:0 5px 10px rgba(0,0,0,0.2);box-shadow:0 5px 10px rgba(0,0,0,0.2);-webkit-background-clip:padding-box;-moz-background-clip:padding;background-clip:padding-box}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{*width:100%;height:1px;margin:9px 1px;*margin:-5px 0 5px;overflow:hidden;background-color:#e5e5e5;border-bottom:1px solid #fff}.dropdown-menu li>a{display:block;padding:3px 20px;clear:both;font-weight:normal;line-height:20px;color:#333;white-space:nowrap}.dropdown-menu li>a:hover,.dropdown-menu li>a:focus,.dropdown-submenu:hover>a{color:#fff;text-decoration:none;background-color:#0081c2;background-image:-moz-linear-gradient(top,#08c,#0077b3);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#0077b3));background-image:-webkit-linear-gradient(top,#08c,#0077b3);background-image:-o-linear-gradient(top,#08c,#0077b3);background-image:linear-gradient(to bottom,#08c,#0077b3);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc',endColorstr='#ff0077b3',GradientType=0)}.dropdown-menu .active>a,.dropdown-menu .active>a:hover{color:#fff;text-decoration:none;background-color:#0081c2;background-image:-moz-linear-gradient(top,#08c,#0077b3);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#0077b3));background-image:-webkit-linear-gradient(top,#08c,#0077b3);background-image:-o-linear-gradient(top,#08c,#0077b3);background-image:linear-gradient(to bottom,#08c,#0077b3);background-repeat:repeat-x;outline:0;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc',endColorstr='#ff0077b3',GradientType=0)}.dropdown-menu .disabled>a,.dropdown-menu .disabled>a:hover{color:#999}.dropdown-menu .disabled>a:hover{text-decoration:none;cursor:default;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.open{*z-index:1000}.open>.dropdown-menu{display:block}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{border-top:0;border-bottom:4px solid #000;content:""}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:1px}.dropdown-submenu{position:relative}.dropdown-submenu>.dropdown-menu{top:0;left:100%;margin-top:-6px;margin-left:-1px;-webkit-border-radius:0 6px 6px 6px;-moz-border-radius:0 6px 6px 6px;border-radius:0 6px 6px 6px}.dropdown-submenu:hover>.dropdown-menu{display:block}.dropup .dropdown-submenu>.dropdown-menu{top:auto;bottom:0;margin-top:0;margin-bottom:-2px;-webkit-border-radius:5px 5px 5px 0;-moz-border-radius:5px 5px 5px 0;border-radius:5px 5px 5px 0}.dropdown-submenu>a:after{display:block;float:right;width:0;height:0;margin-top:5px;margin-right:-10px;border-color:transparent;border-left-color:#ccc;border-style:solid;border-width:5px 0 5px 5px;content:" "}.dropdown-submenu:hover>a:after{border-left-color:#fff}.dropdown-submenu.pull-left{float:none}.dropdown-submenu.pull-left>.dropdown-menu{left:-100%;margin-left:10px;-webkit-border-radius:6px 0 6px 6px;-moz-border-radius:6px 0 6px 6px;border-radius:6px 0 6px 6px}.dropdown .dropdown-menu .nav-header{padding-right:20px;padding-left:20px}.typeahead{z-index:1051;margin-top:2px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.well{min-height:20px;padding:19px;margin-bottom:20px;background-color:#f5f5f5;border:1px solid #e3e3e3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.05);box-shadow:inset 0 1px 1px rgba(0,0,0,0.05)}.well blockquote{border-color:#ddd;border-color:rgba(0,0,0,0.15)}.well-large{padding:24px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.well-small{padding:9px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.fade{opacity:0;-webkit-transition:opacity .15s linear;-moz-transition:opacity .15s linear;-o-transition:opacity .15s linear;transition:opacity .15s linear}.fade.in{opacity:1}.collapse{position:relative;height:0;overflow:hidden;-webkit-transition:height .35s ease;-moz-transition:height .35s ease;-o-transition:height .35s ease;transition:height .35s ease}.collapse.in{height:auto}.close{float:right;font-size:20px;font-weight:bold;line-height:20px;color:#000;text-shadow:0 1px 0 #fff;opacity:.2;filter:alpha(opacity=20)}.close:hover{color:#000;text-decoration:none;cursor:pointer;opacity:.4;filter:alpha(opacity=40)}button.close{padding:0;cursor:pointer;background:transparent;border:0;-webkit-appearance:none}.btn{display:inline-block;*display:inline;padding:4px 12px;margin-bottom:0;*margin-left:.3em;font-size:14px;line-height:20px;color:#333;text-align:center;text-shadow:0 1px 1px rgba(255,255,255,0.75);vertical-align:middle;cursor:pointer;background-color:#f5f5f5;*background-color:#e6e6e6;background-image:-moz-linear-gradient(top,#fff,#e6e6e6);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6));background-image:-webkit-linear-gradient(top,#fff,#e6e6e6);background-image:-o-linear-gradient(top,#fff,#e6e6e6);background-image:linear-gradient(to bottom,#fff,#e6e6e6);background-repeat:repeat-x;border:1px solid #bbb;*border:0;border-color:#e6e6e6 #e6e6e6 #bfbfbf;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);border-bottom-color:#a2a2a2;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff',endColorstr='#ffe6e6e6',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);*zoom:1;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05)}.btn:hover,.btn:active,.btn.active,.btn.disabled,.btn[disabled]{color:#333;background-color:#e6e6e6;*background-color:#d9d9d9}.btn:active,.btn.active{background-color:#ccc \9}.btn:first-child{*margin-left:0}.btn:hover{color:#333;text-decoration:none;background-position:0 -15px;-webkit-transition:background-position .1s linear;-moz-transition:background-position .1s linear;-o-transition:background-position .1s linear;transition:background-position .1s linear}.btn:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.btn.active,.btn:active{background-image:none;outline:0;-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05)}.btn.disabled,.btn[disabled]{cursor:default;background-image:none;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.btn-large{padding:11px 19px;font-size:17.5px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.btn-large [class^="icon-"],.btn-large [class*=" icon-"]{margin-top:4px}.btn-small{padding:2px 10px;font-size:11.9px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-small [class^="icon-"],.btn-small [class*=" icon-"]{margin-top:0}.btn-mini [class^="icon-"],.btn-mini [class*=" icon-"]{margin-top:-1px}.btn-mini{padding:0 6px;font-size:10.5px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-block{display:block;width:100%;padding-right:0;padding-left:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.btn-block+.btn-block{margin-top:5px}input[type="submit"].btn-block,input[type="reset"].btn-block,input[type="button"].btn-block{width:100%}.btn-primary.active,.btn-warning.active,.btn-danger.active,.btn-success.active,.btn-info.active,.btn-inverse.active{color:rgba(255,255,255,0.75)}.btn{border-color:#c5c5c5;border-color:rgba(0,0,0,0.15) rgba(0,0,0,0.15) rgba(0,0,0,0.25)}.btn-primary{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#006dcc;*background-color:#04c;background-image:-moz-linear-gradient(top,#08c,#04c);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#04c));background-image:-webkit-linear-gradient(top,#08c,#04c);background-image:-o-linear-gradient(top,#08c,#04c);background-image:linear-gradient(to bottom,#08c,#04c);background-repeat:repeat-x;border-color:#04c #04c #002a80;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc',endColorstr='#ff0044cc',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-primary:hover,.btn-primary:active,.btn-primary.active,.btn-primary.disabled,.btn-primary[disabled]{color:#fff;background-color:#04c;*background-color:#003bb3}.btn-primary:active,.btn-primary.active{background-color:#039 \9}.btn-warning{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#faa732;*background-color:#f89406;background-image:-moz-linear-gradient(top,#fbb450,#f89406);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fbb450),to(#f89406));background-image:-webkit-linear-gradient(top,#fbb450,#f89406);background-image:-o-linear-gradient(top,#fbb450,#f89406);background-image:linear-gradient(to bottom,#fbb450,#f89406);background-repeat:repeat-x;border-color:#f89406 #f89406 #ad6704;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffbb450',endColorstr='#fff89406',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-warning:hover,.btn-warning:active,.btn-warning.active,.btn-warning.disabled,.btn-warning[disabled]{color:#fff;background-color:#f89406;*background-color:#df8505}.btn-warning:active,.btn-warning.active{background-color:#c67605 \9}.btn-danger{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#da4f49;*background-color:#bd362f;background-image:-moz-linear-gradient(top,#ee5f5b,#bd362f);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#bd362f));background-image:-webkit-linear-gradient(top,#ee5f5b,#bd362f);background-image:-o-linear-gradient(top,#ee5f5b,#bd362f);background-image:linear-gradient(to bottom,#ee5f5b,#bd362f);background-repeat:repeat-x;border-color:#bd362f #bd362f #802420;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffee5f5b',endColorstr='#ffbd362f',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-danger:hover,.btn-danger:active,.btn-danger.active,.btn-danger.disabled,.btn-danger[disabled]{color:#fff;background-color:#bd362f;*background-color:#a9302a}.btn-danger:active,.btn-danger.active{background-color:#942a25 \9}.btn-success{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#5bb75b;*background-color:#51a351;background-image:-moz-linear-gradient(top,#62c462,#51a351);background-image:-webkit-gradient(linear,0 0,0 100%,from(#62c462),to(#51a351));background-image:-webkit-linear-gradient(top,#62c462,#51a351);background-image:-o-linear-gradient(top,#62c462,#51a351);background-image:linear-gradient(to bottom,#62c462,#51a351);background-repeat:repeat-x;border-color:#51a351 #51a351 #387038;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff62c462',endColorstr='#ff51a351',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-success:hover,.btn-success:active,.btn-success.active,.btn-success.disabled,.btn-success[disabled]{color:#fff;background-color:#51a351;*background-color:#499249}.btn-success:active,.btn-success.active{background-color:#408140 \9}.btn-info{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#49afcd;*background-color:#2f96b4;background-image:-moz-linear-gradient(top,#5bc0de,#2f96b4);background-image:-webkit-gradient(linear,0 0,0 100%,from(#5bc0de),to(#2f96b4));background-image:-webkit-linear-gradient(top,#5bc0de,#2f96b4);background-image:-o-linear-gradient(top,#5bc0de,#2f96b4);background-image:linear-gradient(to bottom,#5bc0de,#2f96b4);background-repeat:repeat-x;border-color:#2f96b4 #2f96b4 #1f6377;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de',endColorstr='#ff2f96b4',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-info:hover,.btn-info:active,.btn-info.active,.btn-info.disabled,.btn-info[disabled]{color:#fff;background-color:#2f96b4;*background-color:#2a85a0}.btn-info:active,.btn-info.active{background-color:#24748c \9}.btn-inverse{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#363636;*background-color:#222;background-image:-moz-linear-gradient(top,#444,#222);background-image:-webkit-gradient(linear,0 0,0 100%,from(#444),to(#222));background-image:-webkit-linear-gradient(top,#444,#222);background-image:-o-linear-gradient(top,#444,#222);background-image:linear-gradient(to bottom,#444,#222);background-repeat:repeat-x;border-color:#222 #222 #000;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff444444',endColorstr='#ff222222',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-inverse:hover,.btn-inverse:active,.btn-inverse.active,.btn-inverse.disabled,.btn-inverse[disabled]{color:#fff;background-color:#222;*background-color:#151515}.btn-inverse:active,.btn-inverse.active{background-color:#080808 \9}button.btn,input[type="submit"].btn{*padding-top:3px;*padding-bottom:3px}button.btn::-moz-focus-inner,input[type="submit"].btn::-moz-focus-inner{padding:0;border:0}button.btn.btn-large,input[type="submit"].btn.btn-large{*padding-top:7px;*padding-bottom:7px}button.btn.btn-small,input[type="submit"].btn.btn-small{*padding-top:3px;*padding-bottom:3px}button.btn.btn-mini,input[type="submit"].btn.btn-mini{*padding-top:1px;*padding-bottom:1px}.btn-link,.btn-link:active,.btn-link[disabled]{background-color:transparent;background-image:none;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.btn-link{color:#08c;cursor:pointer;border-color:transparent;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.btn-link:hover{color:#005580;text-decoration:underline;background-color:transparent}.btn-link[disabled]:hover{color:#333;text-decoration:none}.btn-group{position:relative;display:inline-block;*display:inline;*margin-left:.3em;font-size:0;white-space:nowrap;vertical-align:middle;*zoom:1}.btn-group:first-child{*margin-left:0}.btn-group+.btn-group{margin-left:5px}.btn-toolbar{margin-top:10px;margin-bottom:10px;font-size:0}.btn-toolbar>.btn+.btn,.btn-toolbar>.btn-group+.btn,.btn-toolbar>.btn+.btn-group{margin-left:5px}.btn-group>.btn{position:relative;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.btn-group>.btn+.btn{margin-left:-1px}.btn-group>.btn,.btn-group>.dropdown-menu,.btn-group>.popover{font-size:14px}.btn-group>.btn-mini{font-size:10.5px}.btn-group>.btn-small{font-size:11.9px}.btn-group>.btn-large{font-size:17.5px}.btn-group>.btn:first-child{margin-left:0;-webkit-border-bottom-left-radius:4px;border-bottom-left-radius:4px;-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-bottomleft:4px;-moz-border-radius-topleft:4px}.btn-group>.btn:last-child,.btn-group>.dropdown-toggle{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-webkit-border-bottom-right-radius:4px;border-bottom-right-radius:4px;-moz-border-radius-topright:4px;-moz-border-radius-bottomright:4px}.btn-group>.btn.large:first-child{margin-left:0;-webkit-border-bottom-left-radius:6px;border-bottom-left-radius:6px;-webkit-border-top-left-radius:6px;border-top-left-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-topleft:6px}.btn-group>.btn.large:last-child,.btn-group>.large.dropdown-toggle{-webkit-border-top-right-radius:6px;border-top-right-radius:6px;-webkit-border-bottom-right-radius:6px;border-bottom-right-radius:6px;-moz-border-radius-topright:6px;-moz-border-radius-bottomright:6px}.btn-group>.btn:hover,.btn-group>.btn:focus,.btn-group>.btn:active,.btn-group>.btn.active{z-index:2}.btn-group .dropdown-toggle:active,.btn-group.open .dropdown-toggle{outline:0}.btn-group>.btn+.dropdown-toggle{*padding-top:5px;padding-right:8px;*padding-bottom:5px;padding-left:8px;-webkit-box-shadow:inset 1px 0 0 rgba(255,255,255,0.125),inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 1px 0 0 rgba(255,255,255,0.125),inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 1px 0 0 rgba(255,255,255,0.125),inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05)}.btn-group>.btn-mini+.dropdown-toggle{*padding-top:2px;padding-right:5px;*padding-bottom:2px;padding-left:5px}.btn-group>.btn-small+.dropdown-toggle{*padding-top:5px;*padding-bottom:4px}.btn-group>.btn-large+.dropdown-toggle{*padding-top:7px;padding-right:12px;*padding-bottom:7px;padding-left:12px}.btn-group.open .dropdown-toggle{background-image:none;-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05)}.btn-group.open .btn.dropdown-toggle{background-color:#e6e6e6}.btn-group.open .btn-primary.dropdown-toggle{background-color:#04c}.btn-group.open .btn-warning.dropdown-toggle{background-color:#f89406}.btn-group.open .btn-danger.dropdown-toggle{background-color:#bd362f}.btn-group.open .btn-success.dropdown-toggle{background-color:#51a351}.btn-group.open .btn-info.dropdown-toggle{background-color:#2f96b4}.btn-group.open .btn-inverse.dropdown-toggle{background-color:#222}.btn .caret{margin-top:8px;margin-left:0}.btn-mini .caret,.btn-small .caret,.btn-large .caret{margin-top:6px}.btn-large .caret{border-top-width:5px;border-right-width:5px;border-left-width:5px}.dropup .btn-large .caret{border-bottom-width:5px}.btn-primary .caret,.btn-warning .caret,.btn-danger .caret,.btn-info .caret,.btn-success .caret,.btn-inverse .caret{border-top-color:#fff;border-bottom-color:#fff}.btn-group-vertical{display:inline-block;*display:inline;*zoom:1}.btn-group-vertical>.btn{display:block;float:none;max-width:100%;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.btn-group-vertical>.btn+.btn{margin-top:-1px;margin-left:0}.btn-group-vertical>.btn:first-child{-webkit-border-radius:4px 4px 0 0;-moz-border-radius:4px 4px 0 0;border-radius:4px 4px 0 0}.btn-group-vertical>.btn:last-child{-webkit-border-radius:0 0 4px 4px;-moz-border-radius:0 0 4px 4px;border-radius:0 0 4px 4px}.btn-group-vertical>.btn-large:first-child{-webkit-border-radius:6px 6px 0 0;-moz-border-radius:6px 6px 0 0;border-radius:6px 6px 0 0}.btn-group-vertical>.btn-large:last-child{-webkit-border-radius:0 0 6px 6px;-moz-border-radius:0 0 6px 6px;border-radius:0 0 6px 6px}.alert{padding:8px 35px 8px 14px;margin-bottom:20px;text-shadow:0 1px 0 rgba(255,255,255,0.5);background-color:#fcf8e3;border:1px solid #fbeed5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.alert,.alert h4{color:#c09853}.alert h4{margin:0}.alert .close{position:relative;top:-2px;right:-21px;line-height:20px}.alert-success{color:#468847;background-color:#dff0d8;border-color:#d6e9c6}.alert-success h4{color:#468847}.alert-danger,.alert-error{color:#b94a48;background-color:#f2dede;border-color:#eed3d7}.alert-danger h4,.alert-error h4{color:#b94a48}.alert-info{color:#3a87ad;background-color:#d9edf7;border-color:#bce8f1}.alert-info h4{color:#3a87ad}.alert-block{padding-top:14px;padding-bottom:14px}.alert-block>p,.alert-block>ul{margin-bottom:0}.alert-block p+p{margin-top:5px}.nav{margin-bottom:20px;margin-left:0;list-style:none}.nav>li>a{display:block}.nav>li>a:hover{text-decoration:none;background-color:#eee}.nav>li>a>img{max-width:none}.nav>.pull-right{float:right}.nav-header{display:block;padding:3px 15px;font-size:11px;font-weight:bold;line-height:20px;color:#999;text-shadow:0 1px 0 rgba(255,255,255,0.5);text-transform:uppercase}.nav li+.nav-header{margin-top:9px}.nav-list{padding-right:15px;padding-left:15px;margin-bottom:0}.nav-list>li>a,.nav-list .nav-header{margin-right:-15px;margin-left:-15px;text-shadow:0 1px 0 rgba(255,255,255,0.5)}.nav-list>li>a{padding:3px 15px}.nav-list>.active>a,.nav-list>.active>a:hover{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.2);background-color:#08c}.nav-list [class^="icon-"],.nav-list [class*=" icon-"]{margin-right:2px}.nav-list .divider{*width:100%;height:1px;margin:9px 1px;*margin:-5px 0 5px;overflow:hidden;background-color:#e5e5e5;border-bottom:1px solid #fff}.nav-tabs,.nav-pills{*zoom:1}.nav-tabs:before,.nav-pills:before,.nav-tabs:after,.nav-pills:after{display:table;line-height:0;content:""}.nav-tabs:after,.nav-pills:after{clear:both}.nav-tabs>li,.nav-pills>li{float:left}.nav-tabs>li>a,.nav-pills>li>a{padding-right:12px;padding-left:12px;margin-right:2px;line-height:14px}.nav-tabs{border-bottom:1px solid #ddd}.nav-tabs>li{margin-bottom:-1px}.nav-tabs>li>a{padding-top:8px;padding-bottom:8px;line-height:20px;border:1px solid transparent;-webkit-border-radius:4px 4px 0 0;-moz-border-radius:4px 4px 0 0;border-radius:4px 4px 0 0}.nav-tabs>li>a:hover{border-color:#eee #eee #ddd}.nav-tabs>.active>a,.nav-tabs>.active>a:hover{color:#555;cursor:default;background-color:#fff;border:1px solid #ddd;border-bottom-color:transparent}.nav-pills>li>a{padding-top:8px;padding-bottom:8px;margin-top:2px;margin-bottom:2px;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.nav-pills>.active>a,.nav-pills>.active>a:hover{color:#fff;background-color:#08c}.nav-stacked>li{float:none}.nav-stacked>li>a{margin-right:0}.nav-tabs.nav-stacked{border-bottom:0}.nav-tabs.nav-stacked>li>a{border:1px solid #ddd;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.nav-tabs.nav-stacked>li:first-child>a{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-topright:4px;-moz-border-radius-topleft:4px}.nav-tabs.nav-stacked>li:last-child>a{-webkit-border-bottom-right-radius:4px;border-bottom-right-radius:4px;-webkit-border-bottom-left-radius:4px;border-bottom-left-radius:4px;-moz-border-radius-bottomright:4px;-moz-border-radius-bottomleft:4px}.nav-tabs.nav-stacked>li>a:hover{z-index:2;border-color:#ddd}.nav-pills.nav-stacked>li>a{margin-bottom:3px}.nav-pills.nav-stacked>li:last-child>a{margin-bottom:1px}.nav-tabs .dropdown-menu{-webkit-border-radius:0 0 6px 6px;-moz-border-radius:0 0 6px 6px;border-radius:0 0 6px 6px}.nav-pills .dropdown-menu{-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.nav .dropdown-toggle .caret{margin-top:6px;border-top-color:#08c;border-bottom-color:#08c}.nav .dropdown-toggle:hover .caret{border-top-color:#005580;border-bottom-color:#005580}.nav-tabs .dropdown-toggle .caret{margin-top:8px}.nav .active .dropdown-toggle .caret{border-top-color:#fff;border-bottom-color:#fff}.nav-tabs .active .dropdown-toggle .caret{border-top-color:#555;border-bottom-color:#555}.nav>.dropdown.active>a:hover{cursor:pointer}.nav-tabs .open .dropdown-toggle,.nav-pills .open .dropdown-toggle,.nav>li.dropdown.open.active>a:hover{color:#fff;background-color:#999;border-color:#999}.nav li.dropdown.open .caret,.nav li.dropdown.open.active .caret,.nav li.dropdown.open a:hover .caret{border-top-color:#fff;border-bottom-color:#fff;opacity:1;filter:alpha(opacity=100)}.tabs-stacked .open>a:hover{border-color:#999}.tabbable{*zoom:1}.tabbable:before,.tabbable:after{display:table;line-height:0;content:""}.tabbable:after{clear:both}.tab-content{overflow:auto}.tabs-below>.nav-tabs,.tabs-right>.nav-tabs,.tabs-left>.nav-tabs{border-bottom:0}.tab-content>.tab-pane,.pill-content>.pill-pane{display:none}.tab-content>.active,.pill-content>.active{display:block}.tabs-below>.nav-tabs{border-top:1px solid #ddd}.tabs-below>.nav-tabs>li{margin-top:-1px;margin-bottom:0}.tabs-below>.nav-tabs>li>a{-webkit-border-radius:0 0 4px 4px;-moz-border-radius:0 0 4px 4px;border-radius:0 0 4px 4px}.tabs-below>.nav-tabs>li>a:hover{border-top-color:#ddd;border-bottom-color:transparent}.tabs-below>.nav-tabs>.active>a,.tabs-below>.nav-tabs>.active>a:hover{border-color:transparent #ddd #ddd #ddd}.tabs-left>.nav-tabs>li,.tabs-right>.nav-tabs>li{float:none}.tabs-left>.nav-tabs>li>a,.tabs-right>.nav-tabs>li>a{min-width:74px;margin-right:0;margin-bottom:3px}.tabs-left>.nav-tabs{float:left;margin-right:19px;border-right:1px solid #ddd}.tabs-left>.nav-tabs>li>a{margin-right:-1px;-webkit-border-radius:4px 0 0 4px;-moz-border-radius:4px 0 0 4px;border-radius:4px 0 0 4px}.tabs-left>.nav-tabs>li>a:hover{border-color:#eee #ddd #eee #eee}.tabs-left>.nav-tabs .active>a,.tabs-left>.nav-tabs .active>a:hover{border-color:#ddd transparent #ddd #ddd;*border-right-color:#fff}.tabs-right>.nav-tabs{float:right;margin-left:19px;border-left:1px solid #ddd}.tabs-right>.nav-tabs>li>a{margin-left:-1px;-webkit-border-radius:0 4px 4px 0;-moz-border-radius:0 4px 4px 0;border-radius:0 4px 4px 0}.tabs-right>.nav-tabs>li>a:hover{border-color:#eee #eee #eee #ddd}.tabs-right>.nav-tabs .active>a,.tabs-right>.nav-tabs .active>a:hover{border-color:#ddd #ddd #ddd transparent;*border-left-color:#fff}.nav>.disabled>a{color:#999}.nav>.disabled>a:hover{text-decoration:none;cursor:default;background-color:transparent}.navbar{*position:relative;*z-index:2;margin-bottom:20px;overflow:visible}.navbar-inner{min-height:40px;padding-right:20px;padding-left:20px;background-color:#fafafa;background-image:-moz-linear-gradient(top,#fff,#f2f2f2);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#f2f2f2));background-image:-webkit-linear-gradient(top,#fff,#f2f2f2);background-image:-o-linear-gradient(top,#fff,#f2f2f2);background-image:linear-gradient(to bottom,#fff,#f2f2f2);background-repeat:repeat-x;border:1px solid #d4d4d4;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff',endColorstr='#fff2f2f2',GradientType=0);*zoom:1;-webkit-box-shadow:0 1px 4px rgba(0,0,0,0.065);-moz-box-shadow:0 1px 4px rgba(0,0,0,0.065);box-shadow:0 1px 4px rgba(0,0,0,0.065)}.navbar-inner:before,.navbar-inner:after{display:table;line-height:0;content:""}.navbar-inner:after{clear:both}.navbar .container{width:auto}.nav-collapse.collapse{height:auto;overflow:visible}.navbar .brand{display:block;float:left;padding:10px 20px 10px;margin-left:-20px;font-size:20px;font-weight:200;color:#777;text-shadow:0 1px 0 #fff}.navbar .brand:hover{text-decoration:none}.navbar-text{margin-bottom:0;line-height:40px;color:#777}.navbar-link{color:#777}.navbar-link:hover{color:#333}.navbar .divider-vertical{height:40px;margin:0 9px;border-right:1px solid #fff;border-left:1px solid #f2f2f2}.navbar .btn,.navbar .btn-group{margin-top:5px}.navbar .btn-group .btn,.navbar .input-prepend .btn,.navbar .input-append .btn{margin-top:0}.navbar-form{margin-bottom:0;*zoom:1}.navbar-form:before,.navbar-form:after{display:table;line-height:0;content:""}.navbar-form:after{clear:both}.navbar-form input,.navbar-form select,.navbar-form .radio,.navbar-form .checkbox{margin-top:5px}.navbar-form input,.navbar-form select,.navbar-form .btn{display:inline-block;margin-bottom:0}.navbar-form input[type="image"],.navbar-form input[type="checkbox"],.navbar-form input[type="radio"]{margin-top:3px}.navbar-form .input-append,.navbar-form .input-prepend{margin-top:5px;white-space:nowrap}.navbar-form .input-append input,.navbar-form .input-prepend input{margin-top:0}.navbar-search{position:relative;float:left;margin-top:5px;margin-bottom:0}.navbar-search .search-query{padding:4px 14px;margin-bottom:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;font-weight:normal;line-height:1;-webkit-border-radius:15px;-moz-border-radius:15px;border-radius:15px}.navbar-static-top{position:static;margin-bottom:0}.navbar-static-top .navbar-inner{-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.navbar-fixed-top,.navbar-fixed-bottom{position:fixed;right:0;left:0;z-index:1030;margin-bottom:0}.navbar-fixed-top .navbar-inner,.navbar-static-top .navbar-inner{border-width:0 0 1px}.navbar-fixed-bottom .navbar-inner{border-width:1px 0 0}.navbar-fixed-top .navbar-inner,.navbar-fixed-bottom .navbar-inner{padding-right:0;padding-left:0;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:940px}.navbar-fixed-top{top:0}.navbar-fixed-top .navbar-inner,.navbar-static-top .navbar-inner{-webkit-box-shadow:0 1px 10px rgba(0,0,0,0.1);-moz-box-shadow:0 1px 10px rgba(0,0,0,0.1);box-shadow:0 1px 10px rgba(0,0,0,0.1)}.navbar-fixed-bottom{bottom:0}.navbar-fixed-bottom .navbar-inner{-webkit-box-shadow:0 -1px 10px rgba(0,0,0,0.1);-moz-box-shadow:0 -1px 10px rgba(0,0,0,0.1);box-shadow:0 -1px 10px rgba(0,0,0,0.1)}.navbar .nav{position:relative;left:0;display:block;float:left;margin:0 10px 0 0}.navbar .nav.pull-right{float:right;margin-right:0}.navbar .nav>li{float:left}.navbar .nav>li>a{float:none;padding:10px 15px 10px;color:#777;text-decoration:none;text-shadow:0 1px 0 #fff}.navbar .nav .dropdown-toggle .caret{margin-top:8px}.navbar .nav>li>a:focus,.navbar .nav>li>a:hover{color:#333;text-decoration:none;background-color:transparent}.navbar .nav>.active>a,.navbar .nav>.active>a:hover,.navbar .nav>.active>a:focus{color:#555;text-decoration:none;background-color:#e5e5e5;-webkit-box-shadow:inset 0 3px 8px rgba(0,0,0,0.125);-moz-box-shadow:inset 0 3px 8px rgba(0,0,0,0.125);box-shadow:inset 0 3px 8px rgba(0,0,0,0.125)}.navbar .btn-navbar{display:none;float:right;padding:7px 10px;margin-right:5px;margin-left:5px;color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#ededed;*background-color:#e5e5e5;background-image:-moz-linear-gradient(top,#f2f2f2,#e5e5e5);background-image:-webkit-gradient(linear,0 0,0 100%,from(#f2f2f2),to(#e5e5e5));background-image:-webkit-linear-gradient(top,#f2f2f2,#e5e5e5);background-image:-o-linear-gradient(top,#f2f2f2,#e5e5e5);background-image:linear-gradient(to bottom,#f2f2f2,#e5e5e5);background-repeat:repeat-x;border-color:#e5e5e5 #e5e5e5 #bfbfbf;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2f2f2',endColorstr='#ffe5e5e5',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.075);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.075);box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.075)}.navbar .btn-navbar:hover,.navbar .btn-navbar:active,.navbar .btn-navbar.active,.navbar .btn-navbar.disabled,.navbar .btn-navbar[disabled]{color:#fff;background-color:#e5e5e5;*background-color:#d9d9d9}.navbar .btn-navbar:active,.navbar .btn-navbar.active{background-color:#ccc \9}.navbar .btn-navbar .icon-bar{display:block;width:18px;height:2px;background-color:#f5f5f5;-webkit-border-radius:1px;-moz-border-radius:1px;border-radius:1px;-webkit-box-shadow:0 1px 0 rgba(0,0,0,0.25);-moz-box-shadow:0 1px 0 rgba(0,0,0,0.25);box-shadow:0 1px 0 rgba(0,0,0,0.25)}.btn-navbar .icon-bar+.icon-bar{margin-top:3px}.navbar .nav>li>.dropdown-menu:before{position:absolute;top:-7px;left:9px;display:inline-block;border-right:7px solid transparent;border-bottom:7px solid #ccc;border-left:7px solid transparent;border-bottom-color:rgba(0,0,0,0.2);content:''}.navbar .nav>li>.dropdown-menu:after{position:absolute;top:-6px;left:10px;display:inline-block;border-right:6px solid transparent;border-bottom:6px solid #fff;border-left:6px solid transparent;content:''}.navbar-fixed-bottom .nav>li>.dropdown-menu:before{top:auto;bottom:-7px;border-top:7px solid #ccc;border-bottom:0;border-top-color:rgba(0,0,0,0.2)}.navbar-fixed-bottom .nav>li>.dropdown-menu:after{top:auto;bottom:-6px;border-top:6px solid #fff;border-bottom:0}.navbar .nav li.dropdown>a:hover .caret{border-top-color:#555;border-bottom-color:#555}.navbar .nav li.dropdown.open>.dropdown-toggle,.navbar .nav li.dropdown.active>.dropdown-toggle,.navbar .nav li.dropdown.open.active>.dropdown-toggle{color:#555;background-color:#e5e5e5}.navbar .nav li.dropdown>.dropdown-toggle .caret{border-top-color:#777;border-bottom-color:#777}.navbar .nav li.dropdown.open>.dropdown-toggle .caret,.navbar .nav li.dropdown.active>.dropdown-toggle .caret,.navbar .nav li.dropdown.open.active>.dropdown-toggle .caret{border-top-color:#555;border-bottom-color:#555}.navbar .pull-right>li>.dropdown-menu,.navbar .nav>li>.dropdown-menu.pull-right{right:0;left:auto}.navbar .pull-right>li>.dropdown-menu:before,.navbar .nav>li>.dropdown-menu.pull-right:before{right:12px;left:auto}.navbar .pull-right>li>.dropdown-menu:after,.navbar .nav>li>.dropdown-menu.pull-right:after{right:13px;left:auto}.navbar .pull-right>li>.dropdown-menu .dropdown-menu,.navbar .nav>li>.dropdown-menu.pull-right .dropdown-menu{right:100%;left:auto;margin-right:-1px;margin-left:0;-webkit-border-radius:6px 0 6px 6px;-moz-border-radius:6px 0 6px 6px;border-radius:6px 0 6px 6px}.navbar-inverse .navbar-inner{background-color:#1b1b1b;background-image:-moz-linear-gradient(top,#222,#111);background-image:-webkit-gradient(linear,0 0,0 100%,from(#222),to(#111));background-image:-webkit-linear-gradient(top,#222,#111);background-image:-o-linear-gradient(top,#222,#111);background-image:linear-gradient(to bottom,#222,#111);background-repeat:repeat-x;border-color:#252525;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff222222',endColorstr='#ff111111',GradientType=0)}.navbar-inverse .brand,.navbar-inverse .nav>li>a{color:#999;text-shadow:0 -1px 0 rgba(0,0,0,0.25)}.navbar-inverse .brand:hover,.navbar-inverse .nav>li>a:hover{color:#fff}.navbar-inverse .brand{color:#999}.navbar-inverse .navbar-text{color:#999}.navbar-inverse .nav>li>a:focus,.navbar-inverse .nav>li>a:hover{color:#fff;background-color:transparent}.navbar-inverse .nav .active>a,.navbar-inverse .nav .active>a:hover,.navbar-inverse .nav .active>a:focus{color:#fff;background-color:#111}.navbar-inverse .navbar-link{color:#999}.navbar-inverse .navbar-link:hover{color:#fff}.navbar-inverse .divider-vertical{border-right-color:#222;border-left-color:#111}.navbar-inverse .nav li.dropdown.open>.dropdown-toggle,.navbar-inverse .nav li.dropdown.active>.dropdown-toggle,.navbar-inverse .nav li.dropdown.open.active>.dropdown-toggle{color:#fff;background-color:#111}.navbar-inverse .nav li.dropdown>a:hover .caret{border-top-color:#fff;border-bottom-color:#fff}.navbar-inverse .nav li.dropdown>.dropdown-toggle .caret{border-top-color:#999;border-bottom-color:#999}.navbar-inverse .nav li.dropdown.open>.dropdown-toggle .caret,.navbar-inverse .nav li.dropdown.active>.dropdown-toggle .caret,.navbar-inverse .nav li.dropdown.open.active>.dropdown-toggle .caret{border-top-color:#fff;border-bottom-color:#fff}.navbar-inverse .navbar-search .search-query{color:#fff;background-color:#515151;border-color:#111;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1),0 1px 0 rgba(255,255,255,0.15);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1),0 1px 0 rgba(255,255,255,0.15);box-shadow:inset 0 1px 2px rgba(0,0,0,0.1),0 1px 0 rgba(255,255,255,0.15);-webkit-transition:none;-moz-transition:none;-o-transition:none;transition:none}.navbar-inverse .navbar-search .search-query:-moz-placeholder{color:#ccc}.navbar-inverse .navbar-search .search-query:-ms-input-placeholder{color:#ccc}.navbar-inverse .navbar-search .search-query::-webkit-input-placeholder{color:#ccc}.navbar-inverse .navbar-search .search-query:focus,.navbar-inverse .navbar-search .search-query.focused{padding:5px 15px;color:#333;text-shadow:0 1px 0 #fff;background-color:#fff;border:0;outline:0;-webkit-box-shadow:0 0 3px rgba(0,0,0,0.15);-moz-box-shadow:0 0 3px rgba(0,0,0,0.15);box-shadow:0 0 3px rgba(0,0,0,0.15)}.navbar-inverse .btn-navbar{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#0e0e0e;*background-color:#040404;background-image:-moz-linear-gradient(top,#151515,#040404);background-image:-webkit-gradient(linear,0 0,0 100%,from(#151515),to(#040404));background-image:-webkit-linear-gradient(top,#151515,#040404);background-image:-o-linear-gradient(top,#151515,#040404);background-image:linear-gradient(to bottom,#151515,#040404);background-repeat:repeat-x;border-color:#040404 #040404 #000;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff151515',endColorstr='#ff040404',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.navbar-inverse .btn-navbar:hover,.navbar-inverse .btn-navbar:active,.navbar-inverse .btn-navbar.active,.navbar-inverse .btn-navbar.disabled,.navbar-inverse .btn-navbar[disabled]{color:#fff;background-color:#040404;*background-color:#000}.navbar-inverse .btn-navbar:active,.navbar-inverse .btn-navbar.active{background-color:#000 \9}.breadcrumb{padding:8px 15px;margin:0 0 20px;list-style:none;background-color:#f5f5f5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.breadcrumb>li{display:inline-block;*display:inline;text-shadow:0 1px 0 #fff;*zoom:1}.breadcrumb>li>.divider{padding:0 5px;color:#ccc}.breadcrumb>.active{color:#999}.pagination{margin:20px 0}.pagination ul{display:inline-block;*display:inline;margin-bottom:0;margin-left:0;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;*zoom:1;-webkit-box-shadow:0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:0 1px 2px rgba(0,0,0,0.05);box-shadow:0 1px 2px rgba(0,0,0,0.05)}.pagination ul>li{display:inline}.pagination ul>li>a,.pagination ul>li>span{float:left;padding:4px 12px;line-height:20px;text-decoration:none;background-color:#fff;border:1px solid #ddd;border-left-width:0}.pagination ul>li>a:hover,.pagination ul>.active>a,.pagination ul>.active>span{background-color:#f5f5f5}.pagination ul>.active>a,.pagination ul>.active>span{color:#999;cursor:default}.pagination ul>.disabled>span,.pagination ul>.disabled>a,.pagination ul>.disabled>a:hover{color:#999;cursor:default;background-color:transparent}.pagination ul>li:first-child>a,.pagination ul>li:first-child>span{border-left-width:1px;-webkit-border-bottom-left-radius:4px;border-bottom-left-radius:4px;-webkit-border-top-left-radius:4px;border-top-left-radius:4px;-moz-border-radius-bottomleft:4px;-moz-border-radius-topleft:4px}.pagination ul>li:last-child>a,.pagination ul>li:last-child>span{-webkit-border-top-right-radius:4px;border-top-right-radius:4px;-webkit-border-bottom-right-radius:4px;border-bottom-right-radius:4px;-moz-border-radius-topright:4px;-moz-border-radius-bottomright:4px}.pagination-centered{text-align:center}.pagination-right{text-align:right}.pagination-large ul>li>a,.pagination-large ul>li>span{padding:11px 19px;font-size:17.5px}.pagination-large ul>li:first-child>a,.pagination-large ul>li:first-child>span{-webkit-border-bottom-left-radius:6px;border-bottom-left-radius:6px;-webkit-border-top-left-radius:6px;border-top-left-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-topleft:6px}.pagination-large ul>li:last-child>a,.pagination-large ul>li:last-child>span{-webkit-border-top-right-radius:6px;border-top-right-radius:6px;-webkit-border-bottom-right-radius:6px;border-bottom-right-radius:6px;-moz-border-radius-topright:6px;-moz-border-radius-bottomright:6px}.pagination-mini ul>li:first-child>a,.pagination-small ul>li:first-child>a,.pagination-mini ul>li:first-child>span,.pagination-small ul>li:first-child>span{-webkit-border-bottom-left-radius:3px;border-bottom-left-radius:3px;-webkit-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-bottomleft:3px;-moz-border-radius-topleft:3px}.pagination-mini ul>li:last-child>a,.pagination-small ul>li:last-child>a,.pagination-mini ul>li:last-child>span,.pagination-small ul>li:last-child>span{-webkit-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-border-bottom-right-radius:3px;border-bottom-right-radius:3px;-moz-border-radius-topright:3px;-moz-border-radius-bottomright:3px}.pagination-small ul>li>a,.pagination-small ul>li>span{padding:2px 10px;font-size:11.9px}.pagination-mini ul>li>a,.pagination-mini ul>li>span{padding:0 6px;font-size:10.5px}.pager{margin:20px 0;text-align:center;list-style:none;*zoom:1}.pager:before,.pager:after{display:table;line-height:0;content:""}.pager:after{clear:both}.pager li{display:inline}.pager li>a,.pager li>span{display:inline-block;padding:5px 14px;background-color:#fff;border:1px solid #ddd;-webkit-border-radius:15px;-moz-border-radius:15px;border-radius:15px}.pager li>a:hover{text-decoration:none;background-color:#f5f5f5}.pager .next>a,.pager .next>span{float:right}.pager .previous>a,.pager .previous>span{float:left}.pager .disabled>a,.pager .disabled>a:hover,.pager .disabled>span{color:#999;cursor:default;background-color:#fff}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1040;background-color:#000}.modal-backdrop.fade{opacity:0}.modal-backdrop,.modal-backdrop.fade.in{opacity:.8;filter:alpha(opacity=80)}.modal{position:fixed;top:10%;left:50%;z-index:1050;width:560px;margin-left:-280px;background-color:#fff;border:1px solid #999;border:1px solid rgba(0,0,0,0.3);*border:1px solid #999;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;outline:0;-webkit-box-shadow:0 3px 7px rgba(0,0,0,0.3);-moz-box-shadow:0 3px 7px rgba(0,0,0,0.3);box-shadow:0 3px 7px rgba(0,0,0,0.3);-webkit-background-clip:padding-box;-moz-background-clip:padding-box;background-clip:padding-box}.modal.fade{top:-25%;-webkit-transition:opacity .3s linear,top .3s ease-out;-moz-transition:opacity .3s linear,top .3s ease-out;-o-transition:opacity .3s linear,top .3s ease-out;transition:opacity .3s linear,top .3s ease-out}.modal.fade.in{top:10%}.modal-header{padding:9px 15px;border-bottom:1px solid #eee}.modal-header .close{margin-top:2px}.modal-header h3{margin:0;line-height:30px}.modal-body{position:relative;max-height:400px;padding:15px;overflow-y:auto}.modal-form{margin-bottom:0}.modal-footer{padding:14px 15px 15px;margin-bottom:0;text-align:right;background-color:#f5f5f5;border-top:1px solid #ddd;-webkit-border-radius:0 0 6px 6px;-moz-border-radius:0 0 6px 6px;border-radius:0 0 6px 6px;*zoom:1;-webkit-box-shadow:inset 0 1px 0 #fff;-moz-box-shadow:inset 0 1px 0 #fff;box-shadow:inset 0 1px 0 #fff}.modal-footer:before,.modal-footer:after{display:table;line-height:0;content:""}.modal-footer:after{clear:both}.modal-footer .btn+.btn{margin-bottom:0;margin-left:5px}.modal-footer .btn-group .btn+.btn{margin-left:-1px}.modal-footer .btn-block+.btn-block{margin-left:0}.tooltip{position:absolute;z-index:1030;display:block;padding:5px;font-size:11px;opacity:0;filter:alpha(opacity=0);visibility:visible}.tooltip.in{opacity:.8;filter:alpha(opacity=80)}.tooltip.top{margin-top:-3px}.tooltip.right{margin-left:3px}.tooltip.bottom{margin-top:3px}.tooltip.left{margin-left:-3px}.tooltip-inner{max-width:200px;padding:3px 8px;color:#fff;text-align:center;text-decoration:none;background-color:#000;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.tooltip-arrow{position:absolute;width:0;height:0;border-color:transparent;border-style:solid}.tooltip.top .tooltip-arrow{bottom:0;left:50%;margin-left:-5px;border-top-color:#000;border-width:5px 5px 0}.tooltip.right .tooltip-arrow{top:50%;left:0;margin-top:-5px;border-right-color:#000;border-width:5px 5px 5px 0}.tooltip.left .tooltip-arrow{top:50%;right:0;margin-top:-5px;border-left-color:#000;border-width:5px 0 5px 5px}.tooltip.bottom .tooltip-arrow{top:0;left:50%;margin-left:-5px;border-bottom-color:#000;border-width:0 5px 5px}.popover{position:absolute;top:0;left:0;z-index:1010;display:none;width:236px;padding:1px;text-align:left;white-space:normal;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;-webkit-box-shadow:0 5px 10px rgba(0,0,0,0.2);-moz-box-shadow:0 5px 10px rgba(0,0,0,0.2);box-shadow:0 5px 10px rgba(0,0,0,0.2);-webkit-background-clip:padding-box;-moz-background-clip:padding;background-clip:padding-box}.popover.top{margin-top:-10px}.popover.right{margin-left:10px}.popover.bottom{margin-top:10px}.popover.left{margin-left:-10px}.popover-title{padding:8px 14px;margin:0;font-size:14px;font-weight:normal;line-height:18px;background-color:#f7f7f7;border-bottom:1px solid #ebebeb;-webkit-border-radius:5px 5px 0 0;-moz-border-radius:5px 5px 0 0;border-radius:5px 5px 0 0}.popover-content{padding:9px 14px}.popover .arrow,.popover .arrow:after{position:absolute;display:block;width:0;height:0;border-color:transparent;border-style:solid}.popover .arrow{border-width:11px}.popover .arrow:after{border-width:10px;content:""}.popover.top .arrow{bottom:-11px;left:50%;margin-left:-11px;border-top-color:#999;border-top-color:rgba(0,0,0,0.25);border-bottom-width:0}.popover.top .arrow:after{bottom:1px;margin-left:-10px;border-top-color:#fff;border-bottom-width:0}.popover.right .arrow{top:50%;left:-11px;margin-top:-11px;border-right-color:#999;border-right-color:rgba(0,0,0,0.25);border-left-width:0}.popover.right .arrow:after{bottom:-10px;left:1px;border-right-color:#fff;border-left-width:0}.popover.bottom .arrow{top:-11px;left:50%;margin-left:-11px;border-bottom-color:#999;border-bottom-color:rgba(0,0,0,0.25);border-top-width:0}.popover.bottom .arrow:after{top:1px;margin-left:-10px;border-bottom-color:#fff;border-top-width:0}.popover.left .arrow{top:50%;right:-11px;margin-top:-11px;border-left-color:#999;border-left-color:rgba(0,0,0,0.25);border-right-width:0}.popover.left .arrow:after{right:1px;bottom:-10px;border-left-color:#fff;border-right-width:0}.thumbnails{margin-left:-20px;list-style:none;*zoom:1}.thumbnails:before,.thumbnails:after{display:table;line-height:0;content:""}.thumbnails:after{clear:both}.row-fluid .thumbnails{margin-left:0}.thumbnails>li{float:left;margin-bottom:20px;margin-left:20px}.thumbnail{display:block;padding:4px;line-height:20px;border:1px solid #ddd;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.055);-moz-box-shadow:0 1px 3px rgba(0,0,0,0.055);box-shadow:0 1px 3px rgba(0,0,0,0.055);-webkit-transition:all .2s ease-in-out;-moz-transition:all .2s ease-in-out;-o-transition:all .2s ease-in-out;transition:all .2s ease-in-out}a.thumbnail:hover{border-color:#08c;-webkit-box-shadow:0 1px 4px rgba(0,105,214,0.25);-moz-box-shadow:0 1px 4px rgba(0,105,214,0.25);box-shadow:0 1px 4px rgba(0,105,214,0.25)}.thumbnail>img{display:block;max-width:100%;margin-right:auto;margin-left:auto}.thumbnail .caption{padding:9px;color:#555}.media,.media-body{overflow:hidden;*overflow:visible;zoom:1}.media,.media .media{margin-top:15px}.media:first-child{margin-top:0}.media-object{display:block}.media-heading{margin:0 0 5px}.media .pull-left{margin-right:10px}.media .pull-right{margin-left:10px}.media-list{margin-left:0;list-style:none}.label,.badge{display:inline-block;padding:2px 4px;font-size:11.844px;font-weight:bold;line-height:14px;color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);white-space:nowrap;vertical-align:baseline;background-color:#999}.label{-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.badge{padding-right:9px;padding-left:9px;-webkit-border-radius:9px;-moz-border-radius:9px;border-radius:9px}.label:empty,.badge:empty{display:none}a.label:hover,a.badge:hover{color:#fff;text-decoration:none;cursor:pointer}.label-important,.badge-important{background-color:#b94a48}.label-important[href],.badge-important[href]{background-color:#953b39}.label-warning,.badge-warning{background-color:#f89406}.label-warning[href],.badge-warning[href]{background-color:#c67605}.label-success,.badge-success{background-color:#468847}.label-success[href],.badge-success[href]{background-color:#356635}.label-info,.badge-info{background-color:#3a87ad}.label-info[href],.badge-info[href]{background-color:#2d6987}.label-inverse,.badge-inverse{background-color:#333}.label-inverse[href],.badge-inverse[href]{background-color:#1a1a1a}.btn .label,.btn .badge{position:relative;top:-1px}.btn-mini .label,.btn-mini .badge{top:0}@-webkit-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-moz-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-ms-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-o-keyframes progress-bar-stripes{from{background-position:0 0}to{background-position:40px 0}}@keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}.progress{height:20px;margin-bottom:20px;overflow:hidden;background-color:#f7f7f7;background-image:-moz-linear-gradient(top,#f5f5f5,#f9f9f9);background-image:-webkit-gradient(linear,0 0,0 100%,from(#f5f5f5),to(#f9f9f9));background-image:-webkit-linear-gradient(top,#f5f5f5,#f9f9f9);background-image:-o-linear-gradient(top,#f5f5f5,#f9f9f9);background-image:linear-gradient(to bottom,#f5f5f5,#f9f9f9);background-repeat:repeat-x;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5',endColorstr='#fff9f9f9',GradientType=0);-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1);box-shadow:inset 0 1px 2px rgba(0,0,0,0.1)}.progress .bar{float:left;width:0;height:100%;font-size:12px;color:#fff;text-align:center;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#0e90d2;background-image:-moz-linear-gradient(top,#149bdf,#0480be);background-image:-webkit-gradient(linear,0 0,0 100%,from(#149bdf),to(#0480be));background-image:-webkit-linear-gradient(top,#149bdf,#0480be);background-image:-o-linear-gradient(top,#149bdf,#0480be);background-image:linear-gradient(to bottom,#149bdf,#0480be);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff149bdf',endColorstr='#ff0480be',GradientType=0);-webkit-box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);-moz-box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;-webkit-transition:width .6s ease;-moz-transition:width .6s ease;-o-transition:width .6s ease;transition:width .6s ease}.progress .bar+.bar{-webkit-box-shadow:inset 1px 0 0 rgba(0,0,0,0.15),inset 0 -1px 0 rgba(0,0,0,0.15);-moz-box-shadow:inset 1px 0 0 rgba(0,0,0,0.15),inset 0 -1px 0 rgba(0,0,0,0.15);box-shadow:inset 1px 0 0 rgba(0,0,0,0.15),inset 0 -1px 0 rgba(0,0,0,0.15)}.progress-striped .bar{background-color:#149bdf;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);-webkit-background-size:40px 40px;-moz-background-size:40px 40px;-o-background-size:40px 40px;background-size:40px 40px}.progress.active .bar{-webkit-animation:progress-bar-stripes 2s linear infinite;-moz-animation:progress-bar-stripes 2s linear infinite;-ms-animation:progress-bar-stripes 2s linear infinite;-o-animation:progress-bar-stripes 2s linear infinite;animation:progress-bar-stripes 2s linear infinite}.progress-danger .bar,.progress .bar-danger{background-color:#dd514c;background-image:-moz-linear-gradient(top,#ee5f5b,#c43c35);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#c43c35));background-image:-webkit-linear-gradient(top,#ee5f5b,#c43c35);background-image:-o-linear-gradient(top,#ee5f5b,#c43c35);background-image:linear-gradient(to bottom,#ee5f5b,#c43c35);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffee5f5b',endColorstr='#ffc43c35',GradientType=0)}.progress-danger.progress-striped .bar,.progress-striped .bar-danger{background-color:#ee5f5b;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-success .bar,.progress .bar-success{background-color:#5eb95e;background-image:-moz-linear-gradient(top,#62c462,#57a957);background-image:-webkit-gradient(linear,0 0,0 100%,from(#62c462),to(#57a957));background-image:-webkit-linear-gradient(top,#62c462,#57a957);background-image:-o-linear-gradient(top,#62c462,#57a957);background-image:linear-gradient(to bottom,#62c462,#57a957);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff62c462',endColorstr='#ff57a957',GradientType=0)}.progress-success.progress-striped .bar,.progress-striped .bar-success{background-color:#62c462;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-info .bar,.progress .bar-info{background-color:#4bb1cf;background-image:-moz-linear-gradient(top,#5bc0de,#339bb9);background-image:-webkit-gradient(linear,0 0,0 100%,from(#5bc0de),to(#339bb9));background-image:-webkit-linear-gradient(top,#5bc0de,#339bb9);background-image:-o-linear-gradient(top,#5bc0de,#339bb9);background-image:linear-gradient(to bottom,#5bc0de,#339bb9);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de',endColorstr='#ff339bb9',GradientType=0)}.progress-info.progress-striped .bar,.progress-striped .bar-info{background-color:#5bc0de;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-warning .bar,.progress .bar-warning{background-color:#faa732;background-image:-moz-linear-gradient(top,#fbb450,#f89406);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fbb450),to(#f89406));background-image:-webkit-linear-gradient(top,#fbb450,#f89406);background-image:-o-linear-gradient(top,#fbb450,#f89406);background-image:linear-gradient(to bottom,#fbb450,#f89406);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffbb450',endColorstr='#fff89406',GradientType=0)}.progress-warning.progress-striped .bar,.progress-striped .bar-warning{background-color:#fbb450;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.accordion{margin-bottom:20px}.accordion-group{margin-bottom:2px;border:1px solid #e5e5e5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.accordion-heading{border-bottom:0}.accordion-heading .accordion-toggle{display:block;padding:8px 15px}.accordion-toggle{cursor:pointer}.accordion-inner{padding:9px 15px;border-top:1px solid #e5e5e5}.carousel{position:relative;margin-bottom:20px;line-height:1}.carousel-inner{position:relative;width:100%;overflow:hidden}.carousel-inner>.item{position:relative;display:none;-webkit-transition:.6s ease-in-out left;-moz-transition:.6s ease-in-out left;-o-transition:.6s ease-in-out left;transition:.6s ease-in-out left}.carousel-inner>.item>img{display:block;line-height:1}.carousel-inner>.active,.carousel-inner>.next,.carousel-inner>.prev{display:block}.carousel-inner>.active{left:0}.carousel-inner>.next,.carousel-inner>.prev{position:absolute;top:0;width:100%}.carousel-inner>.next{left:100%}.carousel-inner>.prev{left:-100%}.carousel-inner>.next.left,.carousel-inner>.prev.right{left:0}.carousel-inner>.active.left{left:-100%}.carousel-inner>.active.right{left:100%}.carousel-control{position:absolute;top:40%;left:15px;width:40px;height:40px;margin-top:-20px;font-size:60px;font-weight:100;line-height:30px;color:#fff;text-align:center;background:#222;border:3px solid #fff;-webkit-border-radius:23px;-moz-border-radius:23px;border-radius:23px;opacity:.5;filter:alpha(opacity=50)}.carousel-control.right{right:15px;left:auto}.carousel-control:hover{color:#fff;text-decoration:none;opacity:.9;filter:alpha(opacity=90)}.carousel-caption{position:absolute;right:0;bottom:0;left:0;padding:15px;background:#333;background:rgba(0,0,0,0.75)}.carousel-caption h4,.carousel-caption p{line-height:20px;color:#fff}.carousel-caption h4{margin:0 0 5px}.carousel-caption p{margin-bottom:0}.hero-unit{padding:60px;margin-bottom:30px;font-size:18px;font-weight:200;line-height:30px;color:inherit;background-color:#eee;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.hero-unit h1{margin-bottom:0;font-size:60px;line-height:1;letter-spacing:-1px;color:inherit}.hero-unit li{line-height:30px}.pull-right{float:right}.pull-left{float:left}.hide{display:none}.show{display:block}.invisible{visibility:hidden}.affix{position:fixed}
    8.13 +/*!
    8.14 + * Bootstrap Responsive v2.2.2
    8.15 + *
    8.16 + * Copyright 2012 Twitter, Inc
    8.17 + * Licensed under the Apache License v2.0
    8.18 + * http://www.apache.org/licenses/LICENSE-2.0
    8.19 + *
    8.20 + * Designed and built with all the love in the world @twitter by @mdo and @fat.
    8.21 + */@-ms-viewport{width:device-width}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;line-height:0;content:""}.clearfix:after{clear:both}.hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.input-block-level{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.hidden{display:none;visibility:hidden}.visible-phone{display:none!important}.visible-tablet{display:none!important}.hidden-desktop{display:none!important}.visible-desktop{display:inherit!important}@media(min-width:768px) and (max-width:979px){.hidden-desktop{display:inherit!important}.visible-desktop{display:none!important}.visible-tablet{display:inherit!important}.hidden-tablet{display:none!important}}@media(max-width:767px){.hidden-desktop{display:inherit!important}.visible-desktop{display:none!important}.visible-phone{display:inherit!important}.hidden-phone{display:none!important}}@media(min-width:1200px){.row{margin-left:-30px;*zoom:1}.row:before,.row:after{display:table;line-height:0;content:""}.row:after{clear:both}[class*="span"]{float:left;min-height:1px;margin-left:30px}.container,.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:1170px}.span12{width:1170px}.span11{width:1070px}.span10{width:970px}.span9{width:870px}.span8{width:770px}.span7{width:670px}.span6{width:570px}.span5{width:470px}.span4{width:370px}.span3{width:270px}.span2{width:170px}.span1{width:70px}.offset12{margin-left:1230px}.offset11{margin-left:1130px}.offset10{margin-left:1030px}.offset9{margin-left:930px}.offset8{margin-left:830px}.offset7{margin-left:730px}.offset6{margin-left:630px}.offset5{margin-left:530px}.offset4{margin-left:430px}.offset3{margin-left:330px}.offset2{margin-left:230px}.offset1{margin-left:130px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;line-height:0;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:30px;margin-left:2.564102564102564%;*margin-left:2.5109110747408616%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .controls-row [class*="span"]+[class*="span"]{margin-left:2.564102564102564%}.row-fluid .span12{width:100%;*width:99.94680851063829%}.row-fluid .span11{width:91.45299145299145%;*width:91.39979996362975%}.row-fluid .span10{width:82.90598290598291%;*width:82.8527914166212%}.row-fluid .span9{width:74.35897435897436%;*width:74.30578286961266%}.row-fluid .span8{width:65.81196581196582%;*width:65.75877432260411%}.row-fluid .span7{width:57.26495726495726%;*width:57.21176577559556%}.row-fluid .span6{width:48.717948717948715%;*width:48.664757228587014%}.row-fluid .span5{width:40.17094017094017%;*width:40.11774868157847%}.row-fluid .span4{width:31.623931623931625%;*width:31.570740134569924%}.row-fluid .span3{width:23.076923076923077%;*width:23.023731587561375%}.row-fluid .span2{width:14.52991452991453%;*width:14.476723040552828%}.row-fluid .span1{width:5.982905982905983%;*width:5.929714493544281%}.row-fluid .offset12{margin-left:105.12820512820512%;*margin-left:105.02182214948171%}.row-fluid .offset12:first-child{margin-left:102.56410256410257%;*margin-left:102.45771958537915%}.row-fluid .offset11{margin-left:96.58119658119658%;*margin-left:96.47481360247316%}.row-fluid .offset11:first-child{margin-left:94.01709401709402%;*margin-left:93.91071103837061%}.row-fluid .offset10{margin-left:88.03418803418803%;*margin-left:87.92780505546462%}.row-fluid .offset10:first-child{margin-left:85.47008547008548%;*margin-left:85.36370249136206%}.row-fluid .offset9{margin-left:79.48717948717949%;*margin-left:79.38079650845607%}.row-fluid .offset9:first-child{margin-left:76.92307692307693%;*margin-left:76.81669394435352%}.row-fluid .offset8{margin-left:70.94017094017094%;*margin-left:70.83378796144753%}.row-fluid .offset8:first-child{margin-left:68.37606837606839%;*margin-left:68.26968539734497%}.row-fluid .offset7{margin-left:62.393162393162385%;*margin-left:62.28677941443899%}.row-fluid .offset7:first-child{margin-left:59.82905982905982%;*margin-left:59.72267685033642%}.row-fluid .offset6{margin-left:53.84615384615384%;*margin-left:53.739770867430444%}.row-fluid .offset6:first-child{margin-left:51.28205128205128%;*margin-left:51.175668303327875%}.row-fluid .offset5{margin-left:45.299145299145295%;*margin-left:45.1927623204219%}.row-fluid .offset5:first-child{margin-left:42.73504273504273%;*margin-left:42.62865975631933%}.row-fluid .offset4{margin-left:36.75213675213675%;*margin-left:36.645753773413354%}.row-fluid .offset4:first-child{margin-left:34.18803418803419%;*margin-left:34.081651209310785%}.row-fluid .offset3{margin-left:28.205128205128204%;*margin-left:28.0987452264048%}.row-fluid .offset3:first-child{margin-left:25.641025641025642%;*margin-left:25.53464266230224%}.row-fluid .offset2{margin-left:19.65811965811966%;*margin-left:19.551736679396257%}.row-fluid .offset2:first-child{margin-left:17.094017094017094%;*margin-left:16.98763411529369%}.row-fluid .offset1{margin-left:11.11111111111111%;*margin-left:11.004728132387708%}.row-fluid .offset1:first-child{margin-left:8.547008547008547%;*margin-left:8.440625568285142%}input,textarea,.uneditable-input{margin-left:0}.controls-row [class*="span"]+[class*="span"]{margin-left:30px}input.span12,textarea.span12,.uneditable-input.span12{width:1156px}input.span11,textarea.span11,.uneditable-input.span11{width:1056px}input.span10,textarea.span10,.uneditable-input.span10{width:956px}input.span9,textarea.span9,.uneditable-input.span9{width:856px}input.span8,textarea.span8,.uneditable-input.span8{width:756px}input.span7,textarea.span7,.uneditable-input.span7{width:656px}input.span6,textarea.span6,.uneditable-input.span6{width:556px}input.span5,textarea.span5,.uneditable-input.span5{width:456px}input.span4,textarea.span4,.uneditable-input.span4{width:356px}input.span3,textarea.span3,.uneditable-input.span3{width:256px}input.span2,textarea.span2,.uneditable-input.span2{width:156px}input.span1,textarea.span1,.uneditable-input.span1{width:56px}.thumbnails{margin-left:-30px}.thumbnails>li{margin-left:30px}.row-fluid .thumbnails{margin-left:0}}@media(min-width:768px) and (max-width:979px){.row{margin-left:-20px;*zoom:1}.row:before,.row:after{display:table;line-height:0;content:""}.row:after{clear:both}[class*="span"]{float:left;min-height:1px;margin-left:20px}.container,.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:724px}.span12{width:724px}.span11{width:662px}.span10{width:600px}.span9{width:538px}.span8{width:476px}.span7{width:414px}.span6{width:352px}.span5{width:290px}.span4{width:228px}.span3{width:166px}.span2{width:104px}.span1{width:42px}.offset12{margin-left:764px}.offset11{margin-left:702px}.offset10{margin-left:640px}.offset9{margin-left:578px}.offset8{margin-left:516px}.offset7{margin-left:454px}.offset6{margin-left:392px}.offset5{margin-left:330px}.offset4{margin-left:268px}.offset3{margin-left:206px}.offset2{margin-left:144px}.offset1{margin-left:82px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;line-height:0;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:30px;margin-left:2.7624309392265194%;*margin-left:2.709239449864817%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .controls-row [class*="span"]+[class*="span"]{margin-left:2.7624309392265194%}.row-fluid .span12{width:100%;*width:99.94680851063829%}.row-fluid .span11{width:91.43646408839778%;*width:91.38327259903608%}.row-fluid .span10{width:82.87292817679558%;*width:82.81973668743387%}.row-fluid .span9{width:74.30939226519337%;*width:74.25620077583166%}.row-fluid .span8{width:65.74585635359117%;*width:65.69266486422946%}.row-fluid .span7{width:57.18232044198895%;*width:57.12912895262725%}.row-fluid .span6{width:48.61878453038674%;*width:48.56559304102504%}.row-fluid .span5{width:40.05524861878453%;*width:40.00205712942283%}.row-fluid .span4{width:31.491712707182323%;*width:31.43852121782062%}.row-fluid .span3{width:22.92817679558011%;*width:22.87498530621841%}.row-fluid .span2{width:14.3646408839779%;*width:14.311449394616199%}.row-fluid .span1{width:5.801104972375691%;*width:5.747913483013988%}.row-fluid .offset12{margin-left:105.52486187845304%;*margin-left:105.41847889972962%}.row-fluid .offset12:first-child{margin-left:102.76243093922652%;*margin-left:102.6560479605031%}.row-fluid .offset11{margin-left:96.96132596685082%;*margin-left:96.8549429881274%}.row-fluid .offset11:first-child{margin-left:94.1988950276243%;*margin-left:94.09251204890089%}.row-fluid .offset10{margin-left:88.39779005524862%;*margin-left:88.2914070765252%}.row-fluid .offset10:first-child{margin-left:85.6353591160221%;*margin-left:85.52897613729868%}.row-fluid .offset9{margin-left:79.8342541436464%;*margin-left:79.72787116492299%}.row-fluid .offset9:first-child{margin-left:77.07182320441989%;*margin-left:76.96544022569647%}.row-fluid .offset8{margin-left:71.2707182320442%;*margin-left:71.16433525332079%}.row-fluid .offset8:first-child{margin-left:68.50828729281768%;*margin-left:68.40190431409427%}.row-fluid .offset7{margin-left:62.70718232044199%;*margin-left:62.600799341718584%}.row-fluid .offset7:first-child{margin-left:59.94475138121547%;*margin-left:59.838368402492065%}.row-fluid .offset6{margin-left:54.14364640883978%;*margin-left:54.037263430116376%}.row-fluid .offset6:first-child{margin-left:51.38121546961326%;*margin-left:51.27483249088986%}.row-fluid .offset5{margin-left:45.58011049723757%;*margin-left:45.47372751851417%}.row-fluid .offset5:first-child{margin-left:42.81767955801105%;*margin-left:42.71129657928765%}.row-fluid .offset4{margin-left:37.01657458563536%;*margin-left:36.91019160691196%}.row-fluid .offset4:first-child{margin-left:34.25414364640884%;*margin-left:34.14776066768544%}.row-fluid .offset3{margin-left:28.45303867403315%;*margin-left:28.346655695309746%}.row-fluid .offset3:first-child{margin-left:25.69060773480663%;*margin-left:25.584224756083227%}.row-fluid .offset2{margin-left:19.88950276243094%;*margin-left:19.783119783707537%}.row-fluid .offset2:first-child{margin-left:17.12707182320442%;*margin-left:17.02068884448102%}.row-fluid .offset1{margin-left:11.32596685082873%;*margin-left:11.219583872105325%}.row-fluid .offset1:first-child{margin-left:8.56353591160221%;*margin-left:8.457152932878806%}input,textarea,.uneditable-input{margin-left:0}.controls-row [class*="span"]+[class*="span"]{margin-left:20px}input.span12,textarea.span12,.uneditable-input.span12{width:710px}input.span11,textarea.span11,.uneditable-input.span11{width:648px}input.span10,textarea.span10,.uneditable-input.span10{width:586px}input.span9,textarea.span9,.uneditable-input.span9{width:524px}input.span8,textarea.span8,.uneditable-input.span8{width:462px}input.span7,textarea.span7,.uneditable-input.span7{width:400px}input.span6,textarea.span6,.uneditable-input.span6{width:338px}input.span5,textarea.span5,.uneditable-input.span5{width:276px}input.span4,textarea.span4,.uneditable-input.span4{width:214px}input.span3,textarea.span3,.uneditable-input.span3{width:152px}input.span2,textarea.span2,.uneditable-input.span2{width:90px}input.span1,textarea.span1,.uneditable-input.span1{width:28px}}@media(max-width:767px){body{padding-right:20px;padding-left:20px}.navbar-fixed-top,.navbar-fixed-bottom,.navbar-static-top{margin-right:-20px;margin-left:-20px}.container-fluid{padding:0}.dl-horizontal dt{float:none;width:auto;clear:none;text-align:left}.dl-horizontal dd{margin-left:0}.container{width:auto}.row-fluid{width:100%}.row,.thumbnails{margin-left:0}.thumbnails>li{float:none;margin-left:0}[class*="span"],.uneditable-input[class*="span"],.row-fluid [class*="span"]{display:block;float:none;width:100%;margin-left:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.span12,.row-fluid .span12{width:100%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="offset"]:first-child{margin-left:0}.input-large,.input-xlarge,.input-xxlarge,input[class*="span"],select[class*="span"],textarea[class*="span"],.uneditable-input{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.input-prepend input,.input-append input,.input-prepend input[class*="span"],.input-append input[class*="span"]{display:inline-block;width:auto}.controls-row [class*="span"]+[class*="span"]{margin-left:0}.modal{position:fixed;top:20px;right:20px;left:20px;width:auto;margin:0}.modal.fade{top:-100px}.modal.fade.in{top:20px}}@media(max-width:480px){.nav-collapse{-webkit-transform:translate3d(0,0,0)}.page-header h1 small{display:block;line-height:20px}input[type="checkbox"],input[type="radio"]{border:1px solid #ccc}.form-horizontal .control-label{float:none;width:auto;padding-top:0;text-align:left}.form-horizontal .controls{margin-left:0}.form-horizontal .control-list{padding-top:0}.form-horizontal .form-actions{padding-right:10px;padding-left:10px}.media .pull-left,.media .pull-right{display:block;float:none;margin-bottom:10px}.media-object{margin-right:0;margin-left:0}.modal{top:10px;right:10px;left:10px}.modal-header .close{padding:10px;margin:-10px}.carousel-caption{position:static}}@media(max-width:979px){body{padding-top:0}.navbar-fixed-top,.navbar-fixed-bottom{position:static}.navbar-fixed-top{margin-bottom:20px}.navbar-fixed-bottom{margin-top:20px}.navbar-fixed-top .navbar-inner,.navbar-fixed-bottom .navbar-inner{padding:5px}.navbar .container{width:auto;padding:0}.navbar .brand{padding-right:10px;padding-left:10px;margin:0 0 0 -5px}.nav-collapse{clear:both}.nav-collapse .nav{float:none;margin:0 0 10px}.nav-collapse .nav>li{float:none}.nav-collapse .nav>li>a{margin-bottom:2px}.nav-collapse .nav>.divider-vertical{display:none}.nav-collapse .nav .nav-header{color:#777;text-shadow:none}.nav-collapse .nav>li>a,.nav-collapse .dropdown-menu a{padding:9px 15px;font-weight:bold;color:#777;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.nav-collapse .btn{padding:4px 10px 4px;font-weight:normal;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.nav-collapse .dropdown-menu li+li a{margin-bottom:2px}.nav-collapse .nav>li>a:hover,.nav-collapse .dropdown-menu a:hover{background-color:#f2f2f2}.navbar-inverse .nav-collapse .nav>li>a,.navbar-inverse .nav-collapse .dropdown-menu a{color:#999}.navbar-inverse .nav-collapse .nav>li>a:hover,.navbar-inverse .nav-collapse .dropdown-menu a:hover{background-color:#111}.nav-collapse.in .btn-group{padding:0;margin-top:5px}.nav-collapse .dropdown-menu{position:static;top:auto;left:auto;display:none;float:none;max-width:none;padding:0;margin:0 15px;background-color:transparent;border:0;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.nav-collapse .open>.dropdown-menu{display:block}.nav-collapse .dropdown-menu:before,.nav-collapse .dropdown-menu:after{display:none}.nav-collapse .dropdown-menu .divider{display:none}.nav-collapse .nav>li>.dropdown-menu:before,.nav-collapse .nav>li>.dropdown-menu:after{display:none}.nav-collapse .navbar-form,.nav-collapse .navbar-search{float:none;padding:10px 15px;margin:10px 0;border-top:1px solid #f2f2f2;border-bottom:1px solid #f2f2f2;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1);box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1)}.navbar-inverse .nav-collapse .navbar-form,.navbar-inverse .nav-collapse .navbar-search{border-top-color:#111;border-bottom-color:#111}.navbar .nav-collapse .nav.pull-right{float:none;margin-left:0}.nav-collapse,.nav-collapse.collapse{height:0;overflow:hidden}.navbar .btn-navbar{display:block}.navbar-static .navbar-inner{padding-right:10px;padding-left:10px}}@media(min-width:980px){.nav-collapse.collapse{height:auto!important;overflow:visible!important}}
     9.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/error.png has changed
    10.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/glyphicons-halflings-white.png has changed
    11.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/glyphicons-halflings.png has changed
    12.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/html5.png has changed
    13.1 Binary file dew/src/main/resources/org/apidesign/bck2brwsr/dew/img/java.png has changed
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/index.html	Wed Jan 23 14:49:52 2013 +0100
    14.3 @@ -0,0 +1,98 @@
    14.4 +<!--
    14.5 +To change this template, choose Tools | Templates
    14.6 +and open the template in the editor.
    14.7 +-->
    14.8 +<!DOCTYPE html>
    14.9 +<html lang="en" ng-app="bck2brwsr" ng-controller="DevCtrl">
   14.10 +    <head>
   14.11 +        <title>Back2Browser - DEW</title>
   14.12 +        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   14.13 +        <meta name="viewport" content="width=device-width, initial-scale=1.0">
   14.14 +        <link rel="stylesheet" href="css/bootstrap-combined.min.css"/>  
   14.15 +        <link rel="stylesheet" href="js/codemirror/codemirror.css">
   14.16 +        <link rel="stylesheet" href="js/codemirror/theme/elegant.css"/>
   14.17 +        <link rel="stylesheet" href="css/app.css"/>
   14.18 +    </head>
   14.19 +    <body>
   14.20 +                
   14.21 +        <div class="navbar navbar-fixed-top" style="width: 100%"> 
   14.22 +        <div class="navbar-inner" style="padding-left: 12px; padding-right: 12px;">
   14.23 +            <!-- a class="brand" style="font-size: 100%"><span class="text-info"><b>Java and HTML5</b></span><small>- Together at Last!</small></a-->
   14.24 +            <form class="navbar-form pull-right">
   14.25 +                <!-- select class="span2"></select -->
   14.26 +                <button ng-click="post()" class="btn btn-warning">Rebuild</button>
   14.27 +              </form>
   14.28 +            <!-- ul class="nav">                          
   14.29 +                <li><select class="btn-small" type="text"></select></li>
   14.30 +            </ul -->
   14.31 +            <!-- form class="form form-horizontal pull-right">
   14.32 +                <button class="btn btn-warning btn-small pull-right top" ng-click="post()">Rebuild</button>
   14.33 +            </form -->
   14.34 +            <!-- ul class="nav pull-right">
   14.35 +                
   14.36 +            </ul-->     
   14.37 +        </div>  
   14.38 +        </div>
   14.39 +
   14.40 +        <div class="container-fluid">        
   14.41 +        
   14.42 +        <div style="height: 4em;">&nbsp;</div>    
   14.43 +            
   14.44 +        <div class="row-fluid">
   14.45 +            <div class="span6" style="margin-bottom: 10px;"> 
   14.46 +                <table class="table table-condensed" style="margin-bottom: 2px">
   14.47 +                <tr><td><i class="ic-html5"></i> HTML5</td></tr>               
   14.48 +                </table>
   14.49 +                <div>
   14.50 +                    <textarea ui-codemirror='{ lineNumbers : true, mode : "xml", theme : "elegant", matchBrackets : true, lineWrapping : true }' ng-model="html"></textarea>
   14.51 +                    <div class="alert alert-error" ng-show="doc.modelError">
   14.52 +                        <small>{{doc.modelError.toString()}}</small>
   14.53 +                    </div>
   14.54 +                </div>    
   14.55 +            </div>
   14.56 +            
   14.57 +            <div class="span6">  
   14.58 +                <table class="table table-condensed" style="margin-bottom: 2px">
   14.59 +                <tr><td><i class="ic-java"></i> Java</td></tr>               
   14.60 +                </table>                
   14.61 +                <div>
   14.62 +                    <textarea id="editorJava" ui-codemirror='{ lineNumbers : true, mode : "text/x-java", theme : "elegant", matchBrackets : true, lineWrapping : true, gutters: ["CodeMirror-linenumbers", "issues"] }' ng-model="java"></textarea>
   14.63 +                    <div class="alert alert-error" ng-show="doc.modelError">
   14.64 +                        <small>{{doc.modelError.toString()}}</small>
   14.65 +                    </div>
   14.66 +                </div>
   14.67 +            </div>
   14.68 +        
   14.69 +        </div>    
   14.70 +            
   14.71 +        <table class="table table-condensed">
   14.72 +            <tr ng-click="gotoError(e.line, e.col)" ng-repeat="e in errors" ng-class="errorClass(e.kind)">
   14.73 +                <td style="text-align: right">{{e.line}}</td> 
   14.74 +                <td>:</td> 
   14.75 +                <td style="text-align: left">{{e.col}}</td> 
   14.76 +                <td width="100%" class="text-error error-hover">{{e.msg}} <i class="icon-play"/></td>
   14.77 +            </tr>            
   14.78 +        </table>    
   14.79 +            
   14.80 +        
   14.81 +        <div>&nbsp;</div>    
   14.82 +            
   14.83 +        <ul class="nav nav-tabs">
   14.84 +            <li ng-class="'active'"><a href="#">Result</a></li>
   14.85 +        </ul>    
   14.86 +        
   14.87 +        
   14.88 +        <!-- button class="btn" ng-click="reload()">Reload</button -->
   14.89 +        <iframe id="result" frameborder="0" scrolling="yes" width="100%" style="height: 1000px; overflow: auto; border: 1px solid #DFDFDF;" src="result.html">
   14.90 +            <p>Your browser does not support iframes.</p>
   14.91 +        </iframe>
   14.92 +            
   14.93 +        </div>
   14.94 +        
   14.95 +        <script src="js/angular/angular.min.js"></script>
   14.96 +        <script src="js/codemirror/codemirror.js"></script>
   14.97 +        <script src="js/codemirror/mode/xml.js"></script>
   14.98 +        <script src="js/codemirror/mode/clike.js"></script>
   14.99 +        <script src="js/app.js"></script>
  14.100 +    </body>
  14.101 +</html>
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/angular/angular.min.js	Wed Jan 23 14:49:52 2013 +0100
    15.3 @@ -0,0 +1,159 @@
    15.4 +/*
    15.5 + AngularJS v1.0.3
    15.6 + (c) 2010-2012 Google, Inc. http://angularjs.org
    15.7 + License: MIT
    15.8 +*/
    15.9 +(function(U,ca,p){'use strict';function m(b,a,c){var d;if(b)if(N(b))for(d in b)d!="prototype"&&d!="length"&&d!="name"&&b.hasOwnProperty(d)&&a.call(c,b[d],d);else if(b.forEach&&b.forEach!==m)b.forEach(a,c);else if(L(b)&&wa(b.length))for(d=0;d<b.length;d++)a.call(c,b[d],d);else for(d in b)b.hasOwnProperty(d)&&a.call(c,b[d],d);return b}function lb(b){var a=[],c;for(c in b)b.hasOwnProperty(c)&&a.push(c);return a.sort()}function ec(b,a,c){for(var d=lb(b),e=0;e<d.length;e++)a.call(c,b[d[e]],d[e]);return d}
   15.10 +function mb(b){return function(a,c){b(c,a)}}function xa(){for(var b=Z.length,a;b;){b--;a=Z[b].charCodeAt(0);if(a==57)return Z[b]="A",Z.join("");if(a==90)Z[b]="0";else return Z[b]=String.fromCharCode(a+1),Z.join("")}Z.unshift("0");return Z.join("")}function x(b){m(arguments,function(a){a!==b&&m(a,function(a,d){b[d]=a})});return b}function G(b){return parseInt(b,10)}function ya(b,a){return x(new (x(function(){},{prototype:b})),a)}function D(){}function ma(b){return b}function I(b){return function(){return b}}
   15.11 +function t(b){return typeof b=="undefined"}function v(b){return typeof b!="undefined"}function L(b){return b!=null&&typeof b=="object"}function F(b){return typeof b=="string"}function wa(b){return typeof b=="number"}function na(b){return Sa.apply(b)=="[object Date]"}function J(b){return Sa.apply(b)=="[object Array]"}function N(b){return typeof b=="function"}function oa(b){return b&&b.document&&b.location&&b.alert&&b.setInterval}function R(b){return F(b)?b.replace(/^\s*/,"").replace(/\s*$/,""):b}function fc(b){return b&&
   15.12 +(b.nodeName||b.bind&&b.find)}function Ta(b,a,c){var d=[];m(b,function(b,g,i){d.push(a.call(c,b,g,i))});return d}function gc(b,a){var c=0,d;if(J(b)||F(b))return b.length;else if(L(b))for(d in b)(!a||b.hasOwnProperty(d))&&c++;return c}function za(b,a){if(b.indexOf)return b.indexOf(a);for(var c=0;c<b.length;c++)if(a===b[c])return c;return-1}function Ua(b,a){var c=za(b,a);c>=0&&b.splice(c,1);return a}function V(b,a){if(oa(b)||b&&b.$evalAsync&&b.$watch)throw B("Can't copy Window or Scope");if(a){if(b===
   15.13 +a)throw B("Can't copy equivalent objects or arrays");if(J(b)){for(;a.length;)a.pop();for(var c=0;c<b.length;c++)a.push(V(b[c]))}else for(c in m(a,function(b,c){delete a[c]}),b)a[c]=V(b[c])}else(a=b)&&(J(b)?a=V(b,[]):na(b)?a=new Date(b.getTime()):L(b)&&(a=V(b,{})));return a}function hc(b,a){var a=a||{},c;for(c in b)b.hasOwnProperty(c)&&c.substr(0,2)!=="$$"&&(a[c]=b[c]);return a}function ha(b,a){if(b===a)return!0;if(b===null||a===null)return!1;if(b!==b&&a!==a)return!0;var c=typeof b,d;if(c==typeof a&&
   15.14 +c=="object")if(J(b)){if((c=b.length)==a.length){for(d=0;d<c;d++)if(!ha(b[d],a[d]))return!1;return!0}}else if(na(b))return na(a)&&b.getTime()==a.getTime();else{if(b&&b.$evalAsync&&b.$watch||a&&a.$evalAsync&&a.$watch||oa(b)||oa(a))return!1;c={};for(d in b){if(d.charAt(0)!=="$"&&!N(b[d])&&!ha(b[d],a[d]))return!1;c[d]=!0}for(d in a)if(!c[d]&&d.charAt(0)!=="$"&&!N(a[d]))return!1;return!0}return!1}function Va(b,a){var c=arguments.length>2?ia.call(arguments,2):[];return N(a)&&!(a instanceof RegExp)?c.length?
   15.15 +function(){return arguments.length?a.apply(b,c.concat(ia.call(arguments,0))):a.apply(b,c)}:function(){return arguments.length?a.apply(b,arguments):a.call(b)}:a}function ic(b,a){var c=a;/^\$+/.test(b)?c=p:oa(a)?c="$WINDOW":a&&ca===a?c="$DOCUMENT":a&&a.$evalAsync&&a.$watch&&(c="$SCOPE");return c}function da(b,a){return JSON.stringify(b,ic,a?"  ":null)}function nb(b){return F(b)?JSON.parse(b):b}function Wa(b){b&&b.length!==0?(b=E(""+b),b=!(b=="f"||b=="0"||b=="false"||b=="no"||b=="n"||b=="[]")):b=!1;
   15.16 +return b}function pa(b){b=u(b).clone();try{b.html("")}catch(a){}return u("<div>").append(b).html().match(/^(<[^>]+>)/)[1].replace(/^<([\w\-]+)/,function(a,b){return"<"+E(b)})}function Xa(b){var a={},c,d;m((b||"").split("&"),function(b){b&&(c=b.split("="),d=decodeURIComponent(c[0]),a[d]=v(c[1])?decodeURIComponent(c[1]):!0)});return a}function ob(b){var a=[];m(b,function(b,d){a.push(Ya(d,!0)+(b===!0?"":"="+Ya(b,!0)))});return a.length?a.join("&"):""}function Za(b){return Ya(b,!0).replace(/%26/gi,"&").replace(/%3D/gi,
   15.17 +"=").replace(/%2B/gi,"+")}function Ya(b,a){return encodeURIComponent(b).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(a?null:/%20/g,"+")}function jc(b,a){function c(a){a&&d.push(a)}var d=[b],e,g,i=["ng:app","ng-app","x-ng-app","data-ng-app"],f=/\sng[:\-]app(:\s*([\w\d_]+);?)?\s/;m(i,function(a){i[a]=!0;c(ca.getElementById(a));a=a.replace(":","\\:");b.querySelectorAll&&(m(b.querySelectorAll("."+a),c),m(b.querySelectorAll("."+a+"\\:"),c),m(b.querySelectorAll("["+
   15.18 +a+"]"),c))});m(d,function(a){if(!e){var b=f.exec(" "+a.className+" ");b?(e=a,g=(b[2]||"").replace(/\s+/g,",")):m(a.attributes,function(b){if(!e&&i[b.name])e=a,g=b.value})}});e&&a(e,g?[g]:[])}function pb(b,a){b=u(b);a=a||[];a.unshift(["$provide",function(a){a.value("$rootElement",b)}]);a.unshift("ng");var c=qb(a);c.invoke(["$rootScope","$rootElement","$compile","$injector",function(a,b,c,i){a.$apply(function(){b.data("$injector",i);c(b)(a)})}]);return c}function $a(b,a){a=a||"_";return b.replace(kc,
   15.19 +function(b,d){return(d?a:"")+b.toLowerCase()})}function qa(b,a,c){if(!b)throw new B("Argument '"+(a||"?")+"' is "+(c||"required"));return b}function ra(b,a,c){c&&J(b)&&(b=b[b.length-1]);qa(N(b),a,"not a function, got "+(b&&typeof b=="object"?b.constructor.name||"Object":typeof b));return b}function lc(b){function a(a,b,e){return a[b]||(a[b]=e())}return a(a(b,"angular",Object),"module",function(){var b={};return function(d,e,g){e&&b.hasOwnProperty(d)&&(b[d]=null);return a(b,d,function(){function a(c,
   15.20 +d,e){return function(){b[e||"push"]([c,d,arguments]);return j}}if(!e)throw B("No module: "+d);var b=[],c=[],k=a("$injector","invoke"),j={_invokeQueue:b,_runBlocks:c,requires:e,name:d,provider:a("$provide","provider"),factory:a("$provide","factory"),service:a("$provide","service"),value:a("$provide","value"),constant:a("$provide","constant","unshift"),filter:a("$filterProvider","register"),controller:a("$controllerProvider","register"),directive:a("$compileProvider","directive"),config:k,run:function(a){c.push(a);
   15.21 +return this}};g&&k(g);return j})}})}function rb(b){return b.replace(mc,function(a,b,d,e){return e?d.toUpperCase():d}).replace(nc,"Moz$1")}function ab(b,a){function c(){var e;for(var b=[this],c=a,i,f,h,k,j,l;b.length;){i=b.shift();f=0;for(h=i.length;f<h;f++){k=u(i[f]);c?k.triggerHandler("$destroy"):c=!c;j=0;for(e=(l=k.children()).length,k=e;j<k;j++)b.push(ja(l[j]))}}return d.apply(this,arguments)}var d=ja.fn[b],d=d.$original||d;c.$original=d;ja.fn[b]=c}function Q(b){if(b instanceof Q)return b;if(!(this instanceof
   15.22 +Q)){if(F(b)&&b.charAt(0)!="<")throw B("selectors not implemented");return new Q(b)}if(F(b)){var a=ca.createElement("div");a.innerHTML="<div>&#160;</div>"+b;a.removeChild(a.firstChild);bb(this,a.childNodes);this.remove()}else bb(this,b)}function cb(b){return b.cloneNode(!0)}function sa(b){sb(b);for(var a=0,b=b.childNodes||[];a<b.length;a++)sa(b[a])}function tb(b,a,c){var d=$(b,"events");$(b,"handle")&&(t(a)?m(d,function(a,c){db(b,c,a);delete d[c]}):t(c)?(db(b,a,d[a]),delete d[a]):Ua(d[a],c))}function sb(b){var a=
   15.23 +b[Aa],c=Ba[a];c&&(c.handle&&(c.events.$destroy&&c.handle({},"$destroy"),tb(b)),delete Ba[a],b[Aa]=p)}function $(b,a,c){var d=b[Aa],d=Ba[d||-1];if(v(c))d||(b[Aa]=d=++oc,d=Ba[d]={}),d[a]=c;else return d&&d[a]}function ub(b,a,c){var d=$(b,"data"),e=v(c),g=!e&&v(a),i=g&&!L(a);!d&&!i&&$(b,"data",d={});if(e)d[a]=c;else if(g)if(i)return d&&d[a];else x(d,a);else return d}function Ca(b,a){return(" "+b.className+" ").replace(/[\n\t]/g," ").indexOf(" "+a+" ")>-1}function vb(b,a){a&&m(a.split(" "),function(a){b.className=
   15.24 +R((" "+b.className+" ").replace(/[\n\t]/g," ").replace(" "+R(a)+" "," "))})}function wb(b,a){a&&m(a.split(" "),function(a){if(!Ca(b,a))b.className=R(b.className+" "+R(a))})}function bb(b,a){if(a)for(var a=!a.nodeName&&v(a.length)&&!oa(a)?a:[a],c=0;c<a.length;c++)b.push(a[c])}function xb(b,a){return Da(b,"$"+(a||"ngController")+"Controller")}function Da(b,a,c){b=u(b);for(b[0].nodeType==9&&(b=b.find("html"));b.length;){if(c=b.data(a))return c;b=b.parent()}}function yb(b,a){var c=Ea[a.toLowerCase()];
   15.25 +return c&&zb[b.nodeName]&&c}function pc(b,a){var c=function(c,e){if(!c.preventDefault)c.preventDefault=function(){c.returnValue=!1};if(!c.stopPropagation)c.stopPropagation=function(){c.cancelBubble=!0};if(!c.target)c.target=c.srcElement||ca;if(t(c.defaultPrevented)){var g=c.preventDefault;c.preventDefault=function(){c.defaultPrevented=!0;g.call(c)};c.defaultPrevented=!1}c.isDefaultPrevented=function(){return c.defaultPrevented};m(a[e||c.type],function(a){a.call(b,c)});aa<=8?(c.preventDefault=null,
   15.26 +c.stopPropagation=null,c.isDefaultPrevented=null):(delete c.preventDefault,delete c.stopPropagation,delete c.isDefaultPrevented)};c.elem=b;return c}function ga(b){var a=typeof b,c;if(a=="object"&&b!==null)if(typeof(c=b.$$hashKey)=="function")c=b.$$hashKey();else{if(c===p)c=b.$$hashKey=xa()}else c=b;return a+":"+c}function Fa(b){m(b,this.put,this)}function eb(){}function Ab(b){var a,c;if(typeof b=="function"){if(!(a=b.$inject))a=[],c=b.toString().replace(qc,""),c=c.match(rc),m(c[1].split(sc),function(b){b.replace(tc,
   15.27 +function(b,c,d){a.push(d)})}),b.$inject=a}else J(b)?(c=b.length-1,ra(b[c],"fn"),a=b.slice(0,c)):ra(b,"fn",!0);return a}function qb(b){function a(a){return function(b,c){if(L(b))m(b,mb(a));else return a(b,c)}}function c(a,b){N(b)&&(b=l.instantiate(b));if(!b.$get)throw B("Provider "+a+" must define $get factory method.");return j[a+f]=b}function d(a,b){return c(a,{$get:b})}function e(a){var b=[];m(a,function(a){if(!k.get(a))if(k.put(a,!0),F(a)){var c=ta(a);b=b.concat(e(c.requires)).concat(c._runBlocks);
   15.28 +try{for(var d=c._invokeQueue,c=0,f=d.length;c<f;c++){var h=d[c],g=h[0]=="$injector"?l:l.get(h[0]);g[h[1]].apply(g,h[2])}}catch(n){throw n.message&&(n.message+=" from "+a),n;}}else if(N(a))try{b.push(l.invoke(a))}catch(i){throw i.message&&(i.message+=" from "+a),i;}else if(J(a))try{b.push(l.invoke(a))}catch(j){throw j.message&&(j.message+=" from "+String(a[a.length-1])),j;}else ra(a,"module")});return b}function g(a,b){function c(d){if(typeof d!=="string")throw B("Service name expected");if(a.hasOwnProperty(d)){if(a[d]===
   15.29 +i)throw B("Circular dependency: "+h.join(" <- "));return a[d]}else try{return h.unshift(d),a[d]=i,a[d]=b(d)}finally{h.shift()}}function d(a,b,e){var f=[],k=Ab(a),g,n,i;n=0;for(g=k.length;n<g;n++)i=k[n],f.push(e&&e.hasOwnProperty(i)?e[i]:c(i,h));a.$inject||(a=a[g]);switch(b?-1:f.length){case 0:return a();case 1:return a(f[0]);case 2:return a(f[0],f[1]);case 3:return a(f[0],f[1],f[2]);case 4:return a(f[0],f[1],f[2],f[3]);case 5:return a(f[0],f[1],f[2],f[3],f[4]);case 6:return a(f[0],f[1],f[2],f[3],
   15.30 +f[4],f[5]);case 7:return a(f[0],f[1],f[2],f[3],f[4],f[5],f[6]);case 8:return a(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7]);case 9:return a(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8]);case 10:return a(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8],f[9]);default:return a.apply(b,f)}}return{invoke:d,instantiate:function(a,b){var c=function(){},e;c.prototype=(J(a)?a[a.length-1]:a).prototype;c=new c;e=d(a,c,b);return L(e)?e:c},get:c,annotate:Ab}}var i={},f="Provider",h=[],k=new Fa,j={$provide:{provider:a(c),
   15.31 +factory:a(d),service:a(function(a,b){return d(a,["$injector",function(a){return a.instantiate(b)}])}),value:a(function(a,b){return d(a,I(b))}),constant:a(function(a,b){j[a]=b;o[a]=b}),decorator:function(a,b){var c=l.get(a+f),d=c.$get;c.$get=function(){var a=r.invoke(d,c);return r.invoke(b,null,{$delegate:a})}}}},l=g(j,function(){throw B("Unknown provider: "+h.join(" <- "));}),o={},r=o.$injector=g(o,function(a){a=l.get(a+f);return r.invoke(a.$get,a)});m(e(b),function(a){r.invoke(a||D)});return r}function uc(){var b=
   15.32 +!0;this.disableAutoScrolling=function(){b=!1};this.$get=["$window","$location","$rootScope",function(a,c,d){function e(a){var b=null;m(a,function(a){!b&&E(a.nodeName)==="a"&&(b=a)});return b}function g(){var b=c.hash(),d;b?(d=i.getElementById(b))?d.scrollIntoView():(d=e(i.getElementsByName(b)))?d.scrollIntoView():b==="top"&&a.scrollTo(0,0):a.scrollTo(0,0)}var i=a.document;b&&d.$watch(function(){return c.hash()},function(){d.$evalAsync(g)});return g}]}function vc(b,a,c,d){function e(a){try{a.apply(null,
   15.33 +ia.call(arguments,1))}finally{if(n--,n===0)for(;w.length;)try{w.pop()()}catch(b){c.error(b)}}}function g(a,b){(function ea(){m(q,function(a){a()});s=b(ea,a)})()}function i(){O!=f.url()&&(O=f.url(),m(A,function(a){a(f.url())}))}var f=this,h=a[0],k=b.location,j=b.history,l=b.setTimeout,o=b.clearTimeout,r={};f.isMock=!1;var n=0,w=[];f.$$completeOutstandingRequest=e;f.$$incOutstandingRequestCount=function(){n++};f.notifyWhenNoOutstandingRequests=function(a){m(q,function(a){a()});n===0?a():w.push(a)};
   15.34 +var q=[],s;f.addPollFn=function(a){t(s)&&g(100,l);q.push(a);return a};var O=k.href,C=a.find("base");f.url=function(a,b){if(a){if(O!=a)return O=a,d.history?b?j.replaceState(null,"",a):(j.pushState(null,"",a),C.attr("href",C.attr("href"))):b?k.replace(a):k.href=a,f}else return k.href.replace(/%27/g,"'")};var A=[],K=!1;f.onUrlChange=function(a){K||(d.history&&u(b).bind("popstate",i),d.hashchange?u(b).bind("hashchange",i):f.addPollFn(i),K=!0);A.push(a);return a};f.baseHref=function(){var a=C.attr("href");
   15.35 +return a?a.replace(/^https?\:\/\/[^\/]*/,""):a};var W={},y="",M=f.baseHref();f.cookies=function(a,b){var d,e,f,k;if(a)if(b===p)h.cookie=escape(a)+"=;path="+M+";expires=Thu, 01 Jan 1970 00:00:00 GMT";else{if(F(b))d=(h.cookie=escape(a)+"="+escape(b)+";path="+M).length+1,d>4096&&c.warn("Cookie '"+a+"' possibly not set or overflowed because it was too large ("+d+" > 4096 bytes)!"),W.length>20&&c.warn("Cookie '"+a+"' possibly not set or overflowed because too many cookies were already set ("+W.length+
   15.36 +" > 20 )")}else{if(h.cookie!==y){y=h.cookie;d=y.split("; ");W={};for(f=0;f<d.length;f++)e=d[f],k=e.indexOf("="),k>0&&(W[unescape(e.substring(0,k))]=unescape(e.substring(k+1)))}return W}};f.defer=function(a,b){var c;n++;c=l(function(){delete r[c];e(a)},b||0);r[c]=!0;return c};f.defer.cancel=function(a){return r[a]?(delete r[a],o(a),e(D),!0):!1}}function wc(){this.$get=["$window","$log","$sniffer","$document",function(b,a,c,d){return new vc(b,d,a,c)}]}function xc(){this.$get=function(){function b(b,
   15.37 +d){function e(a){if(a!=l){if(o){if(o==a)o=a.n}else o=a;g(a.n,a.p);g(a,l);l=a;l.n=null}}function g(a,b){if(a!=b){if(a)a.p=b;if(b)b.n=a}}if(b in a)throw B("cacheId "+b+" taken");var i=0,f=x({},d,{id:b}),h={},k=d&&d.capacity||Number.MAX_VALUE,j={},l=null,o=null;return a[b]={put:function(a,b){var c=j[a]||(j[a]={key:a});e(c);t(b)||(a in h||i++,h[a]=b,i>k&&this.remove(o.key))},get:function(a){var b=j[a];if(b)return e(b),h[a]},remove:function(a){var b=j[a];if(b){if(b==l)l=b.p;if(b==o)o=b.n;g(b.n,b.p);delete j[a];
   15.38 +delete h[a];i--}},removeAll:function(){h={};i=0;j={};l=o=null},destroy:function(){j=f=h=null;delete a[b]},info:function(){return x({},f,{size:i})}}}var a={};b.info=function(){var b={};m(a,function(a,e){b[e]=a.info()});return b};b.get=function(b){return a[b]};return b}}function yc(){this.$get=["$cacheFactory",function(b){return b("templates")}]}function Bb(b){var a={},c="Directive",d=/^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/,e=/(([\d\w\-_]+)(?:\:([^;]+))?;?)/,g="Template must have exactly one root element. was: ";
   15.39 +this.directive=function f(d,e){F(d)?(qa(e,"directive"),a.hasOwnProperty(d)||(a[d]=[],b.factory(d+c,["$injector","$exceptionHandler",function(b,c){var e=[];m(a[d],function(a){try{var f=b.invoke(a);if(N(f))f={compile:I(f)};else if(!f.compile&&f.link)f.compile=I(f.link);f.priority=f.priority||0;f.name=f.name||d;f.require=f.require||f.controller&&f.name;f.restrict=f.restrict||"A";e.push(f)}catch(k){c(k)}});return e}])),a[d].push(e)):m(d,mb(f));return this};this.$get=["$injector","$interpolate","$exceptionHandler",
   15.40 +"$http","$templateCache","$parse","$controller","$rootScope",function(b,h,k,j,l,o,r,n){function w(a,b,c){a instanceof u||(a=u(a));m(a,function(b,c){b.nodeType==3&&(a[c]=u(b).wrap("<span></span>").parent()[0])});var d=s(a,b,a,c);return function(b,c){qa(b,"scope");var e=c?ua.clone.call(a):a;e.data("$scope",b);q(e,"ng-scope");c&&c(e,b);d&&d(b,e,e);return e}}function q(a,b){try{a.addClass(b)}catch(c){}}function s(a,b,c,d){function e(a,c,d,k){for(var g,h,j,n,o,l=0,r=0,q=f.length;l<q;r++)j=c[r],g=f[l++],
   15.41 +h=f[l++],g?(g.scope?(n=a.$new(L(g.scope)),u(j).data("$scope",n)):n=a,(o=g.transclude)||!k&&b?g(h,n,j,d,function(b){return function(c){var d=a.$new();return b(d,c).bind("$destroy",Va(d,d.$destroy))}}(o||b)):g(h,n,j,p,k)):h&&h(a,j.childNodes,p,k)}for(var f=[],k,g,h,j=0;j<a.length;j++)g=new ea,k=O(a[j],[],g,d),g=(k=k.length?C(k,a[j],g,b,c):null)&&k.terminal||!a[j].childNodes.length?null:s(a[j].childNodes,k?k.transclude:b),f.push(k),f.push(g),h=h||k||g;return h?e:null}function O(a,b,c,f){var k=c.$attr,
   15.42 +g;switch(a.nodeType){case 1:A(b,fa(Cb(a).toLowerCase()),"E",f);var h,j,n;g=a.attributes;for(var o=0,l=g&&g.length;o<l;o++)if(h=g[o],h.specified)j=h.name,n=fa(j.toLowerCase()),k[n]=j,c[n]=h=R(aa&&j=="href"?decodeURIComponent(a.getAttribute(j,2)):h.value),yb(a,n)&&(c[n]=!0),X(a,b,h,n),A(b,n,"A",f);a=a.className;if(F(a)&&a!=="")for(;g=e.exec(a);)n=fa(g[2]),A(b,n,"C",f)&&(c[n]=R(g[3])),a=a.substr(g.index+g[0].length);break;case 3:H(b,a.nodeValue);break;case 8:try{if(g=d.exec(a.nodeValue))n=fa(g[1]),A(b,
   15.43 +n,"M",f)&&(c[n]=R(g[2]))}catch(r){}}b.sort(y);return b}function C(a,b,c,d,e){function f(a,b){if(a)a.require=z.require,l.push(a);if(b)b.require=z.require,ba.push(b)}function h(a,b){var c,d="data",e=!1;if(F(a)){for(;(c=a.charAt(0))=="^"||c=="?";)a=a.substr(1),c=="^"&&(d="inheritedData"),e=e||c=="?";c=b[d]("$"+a+"Controller");if(!c&&!e)throw B("No controller: "+a);}else J(a)&&(c=[],m(a,function(a){c.push(h(a,b))}));return c}function j(a,d,e,f,g){var n,q,w,K,s;n=b===e?c:hc(c,new ea(u(e),c.$attr));q=n.$$element;
   15.44 +if(C){var zc=/^\s*([@=&])\s*(\w*)\s*$/,O=d.$parent||d;m(C.scope,function(a,b){var c=a.match(zc)||[],e=c[2]||b,f,g,k;switch(c[1]){case "@":n.$observe(e,function(a){d[b]=a});n.$$observers[e].$$scope=O;break;case "=":g=o(n[e]);k=g.assign||function(){f=d[b]=g(O);throw B(Db+n[e]+" (directive: "+C.name+")");};f=d[b]=g(O);d.$watch(function(){var a=g(O);a!==d[b]&&(a!==f?f=d[b]=a:k(O,a=f=d[b]));return a});break;case "&":g=o(n[e]);d[b]=function(a){return g(O,a)};break;default:throw B("Invalid isolate scope definition for directive "+
   15.45 +C.name+": "+a);}})}t&&m(t,function(a){var b={$scope:d,$element:q,$attrs:n,$transclude:g};s=a.controller;s=="@"&&(s=n[a.name]);q.data("$"+a.name+"Controller",r(s,b))});f=0;for(w=l.length;f<w;f++)try{K=l[f],K(d,q,n,K.require&&h(K.require,q))}catch(y){k(y,pa(q))}a&&a(d,e.childNodes,p,g);f=0;for(w=ba.length;f<w;f++)try{K=ba[f],K(d,q,n,K.require&&h(K.require,q))}catch(Ha){k(Ha,pa(q))}}for(var n=-Number.MAX_VALUE,l=[],ba=[],s=null,C=null,A=null,y=c.$$element=u(b),z,H,X,D,v=d,t,x,Y,E=0,G=a.length;E<G;E++){z=
   15.46 +a[E];X=p;if(n>z.priority)break;if(Y=z.scope)M("isolated scope",C,z,y),L(Y)&&(q(y,"ng-isolate-scope"),C=z),q(y,"ng-scope"),s=s||z;H=z.name;if(Y=z.controller)t=t||{},M("'"+H+"' controller",t[H],z,y),t[H]=z;if(Y=z.transclude)M("transclusion",D,z,y),D=z,n=z.priority,Y=="element"?(X=u(b),y=c.$$element=u("<\!-- "+H+": "+c[H]+" --\>"),b=y[0],Ga(e,u(X[0]),b),v=w(X,d,n)):(X=u(cb(b)).contents(),y.html(""),v=w(X,d));if(Y=z.template)if(M("template",A,z,y),A=z,Y=Ha(Y),z.replace){X=u("<div>"+R(Y)+"</div>").contents();
   15.47 +b=X[0];if(X.length!=1||b.nodeType!==1)throw new B(g+Y);Ga(e,y,b);H={$attr:{}};a=a.concat(O(b,a.splice(E+1,a.length-(E+1)),H));K(c,H);G=a.length}else y.html(Y);if(z.templateUrl)M("template",A,z,y),A=z,j=W(a.splice(E,a.length-E),j,y,c,e,z.replace,v),G=a.length;else if(z.compile)try{x=z.compile(y,c,v),N(x)?f(null,x):x&&f(x.pre,x.post)}catch(I){k(I,pa(y))}if(z.terminal)j.terminal=!0,n=Math.max(n,z.priority)}j.scope=s&&s.scope;j.transclude=D&&v;return j}function A(d,e,g,h){var j=!1;if(a.hasOwnProperty(e))for(var n,
   15.48 +e=b.get(e+c),o=0,l=e.length;o<l;o++)try{if(n=e[o],(h===p||h>n.priority)&&n.restrict.indexOf(g)!=-1)d.push(n),j=!0}catch(r){k(r)}return j}function K(a,b){var c=b.$attr,d=a.$attr,e=a.$$element;m(a,function(d,e){e.charAt(0)!="$"&&(b[e]&&(d+=(e==="style"?";":" ")+b[e]),a.$set(e,d,!0,c[e]))});m(b,function(b,f){f=="class"?(q(e,b),a["class"]=(a["class"]?a["class"]+" ":"")+b):f=="style"?e.attr("style",e.attr("style")+";"+b):f.charAt(0)!="$"&&!a.hasOwnProperty(f)&&(a[f]=b,d[f]=c[f])})}function W(a,b,c,d,e,
   15.49 +f,k){var h=[],n,o,r=c[0],q=a.shift(),w=x({},q,{controller:null,templateUrl:null,transclude:null,scope:null});c.html("");j.get(q.templateUrl,{cache:l}).success(function(j){var l,q,j=Ha(j);if(f){q=u("<div>"+R(j)+"</div>").contents();l=q[0];if(q.length!=1||l.nodeType!==1)throw new B(g+j);j={$attr:{}};Ga(e,c,l);O(l,a,j);K(d,j)}else l=r,c.html(j);a.unshift(w);n=C(a,c,d,k);for(o=s(c.contents(),k);h.length;){var ba=h.pop(),j=h.pop();q=h.pop();var y=h.pop(),m=l;q!==r&&(m=cb(l),Ga(j,u(q),m));n(function(){b(o,
   15.50 +y,m,e,ba)},y,m,e,ba)}h=null}).error(function(a,b,c,d){throw B("Failed to load template: "+d.url);});return function(a,c,d,e,f){h?(h.push(c),h.push(d),h.push(e),h.push(f)):n(function(){b(o,c,d,e,f)},c,d,e,f)}}function y(a,b){return b.priority-a.priority}function M(a,b,c,d){if(b)throw B("Multiple directives ["+b.name+", "+c.name+"] asking for "+a+" on: "+pa(d));}function H(a,b){var c=h(b,!0);c&&a.push({priority:0,compile:I(function(a,b){var d=b.parent(),e=d.data("$binding")||[];e.push(c);q(d.data("$binding",
   15.51 +e),"ng-binding");a.$watch(c,function(a){b[0].nodeValue=a})})})}function X(a,b,c,d){var e=h(c,!0);e&&b.push({priority:100,compile:I(function(a,b,c){b=c.$$observers||(c.$$observers={});d==="class"&&(e=h(c[d],!0));c[d]=p;(b[d]||(b[d]=[])).$$inter=!0;(c.$$observers&&c.$$observers[d].$$scope||a).$watch(e,function(a){c.$set(d,a)})})})}function Ga(a,b,c){var d=b[0],e=d.parentNode,f,g;if(a){f=0;for(g=a.length;f<g;f++)if(a[f]==d){a[f]=c;break}}e&&e.replaceChild(c,d);c[u.expando]=d[u.expando];b[0]=c}var ea=
   15.52 +function(a,b){this.$$element=a;this.$attr=b||{}};ea.prototype={$normalize:fa,$set:function(a,b,c,d){var e=yb(this.$$element[0],a),f=this.$$observers;e&&(this.$$element.prop(a,b),d=e);this[a]=b;d?this.$attr[a]=d:(d=this.$attr[a])||(this.$attr[a]=d=$a(a,"-"));c!==!1&&(b===null||b===p?this.$$element.removeAttr(d):this.$$element.attr(d,b));f&&m(f[a],function(a){try{a(b)}catch(c){k(c)}})},$observe:function(a,b){var c=this,d=c.$$observers||(c.$$observers={}),e=d[a]||(d[a]=[]);e.push(b);n.$evalAsync(function(){e.$$inter||
   15.53 +b(c[a])});return b}};var D=h.startSymbol(),ba=h.endSymbol(),Ha=D=="{{"||ba=="}}"?ma:function(a){return a.replace(/\{\{/g,D).replace(/}}/g,ba)};return w}]}function fa(b){return rb(b.replace(Ac,""))}function Bc(){var b={};this.register=function(a,c){L(a)?x(b,a):b[a]=c};this.$get=["$injector","$window",function(a,c){return function(d,e){if(F(d)){var g=d,d=b.hasOwnProperty(g)?b[g]:fb(e.$scope,g,!0)||fb(c,g,!0);ra(d,g,!0)}return a.instantiate(d,e)}}]}function Cc(){this.$get=["$window",function(b){return u(b.document)}]}
   15.54 +function Dc(){this.$get=["$log",function(b){return function(a,c){b.error.apply(b,arguments)}}]}function Ec(){var b="{{",a="}}";this.startSymbol=function(a){return a?(b=a,this):b};this.endSymbol=function(b){return b?(a=b,this):a};this.$get=["$parse",function(c){function d(d,f){for(var h,k,j=0,l=[],o=d.length,r=!1,n=[];j<o;)(h=d.indexOf(b,j))!=-1&&(k=d.indexOf(a,h+e))!=-1?(j!=h&&l.push(d.substring(j,h)),l.push(j=c(r=d.substring(h+e,k))),j.exp=r,j=k+g,r=!0):(j!=o&&l.push(d.substring(j)),j=o);if(!(o=
   15.55 +l.length))l.push(""),o=1;if(!f||r)return n.length=o,j=function(a){for(var b=0,c=o,d;b<c;b++){if(typeof(d=l[b])=="function")d=d(a),d==null||d==p?d="":typeof d!="string"&&(d=da(d));n[b]=d}return n.join("")},j.exp=d,j.parts=l,j}var e=b.length,g=a.length;d.startSymbol=function(){return b};d.endSymbol=function(){return a};return d}]}function Eb(b){for(var b=b.split("/"),a=b.length;a--;)b[a]=Za(b[a]);return b.join("/")}function va(b,a){var c=Fb.exec(b),c={protocol:c[1],host:c[3],port:G(c[5])||Gb[c[1]]||
   15.56 +null,path:c[6]||"/",search:c[8],hash:c[10]};if(a)a.$$protocol=c.protocol,a.$$host=c.host,a.$$port=c.port;return c}function ka(b,a,c){return b+"://"+a+(c==Gb[b]?"":":"+c)}function Fc(b,a,c){var d=va(b);return decodeURIComponent(d.path)!=a||t(d.hash)||d.hash.indexOf(c)!==0?b:ka(d.protocol,d.host,d.port)+a.substr(0,a.lastIndexOf("/"))+d.hash.substr(c.length)}function Gc(b,a,c){var d=va(b);if(decodeURIComponent(d.path)==a)return b;else{var e=d.search&&"?"+d.search||"",g=d.hash&&"#"+d.hash||"",i=a.substr(0,
   15.57 +a.lastIndexOf("/")),f=d.path.substr(i.length);if(d.path.indexOf(i)!==0)throw B('Invalid url "'+b+'", missing path prefix "'+i+'" !');return ka(d.protocol,d.host,d.port)+a+"#"+c+f+e+g}}function gb(b,a,c){a=a||"";this.$$parse=function(b){var c=va(b,this);if(c.path.indexOf(a)!==0)throw B('Invalid url "'+b+'", missing path prefix "'+a+'" !');this.$$path=decodeURIComponent(c.path.substr(a.length));this.$$search=Xa(c.search);this.$$hash=c.hash&&decodeURIComponent(c.hash)||"";this.$$compose()};this.$$compose=
   15.58 +function(){var b=ob(this.$$search),c=this.$$hash?"#"+Za(this.$$hash):"";this.$$url=Eb(this.$$path)+(b?"?"+b:"")+c;this.$$absUrl=ka(this.$$protocol,this.$$host,this.$$port)+a+this.$$url};this.$$rewriteAppUrl=function(a){if(a.indexOf(c)==0)return a};this.$$parse(b)}function Ia(b,a,c){var d;this.$$parse=function(b){var c=va(b,this);if(c.hash&&c.hash.indexOf(a)!==0)throw B('Invalid url "'+b+'", missing hash prefix "'+a+'" !');d=c.path+(c.search?"?"+c.search:"");c=Hc.exec((c.hash||"").substr(a.length));
   15.59 +this.$$path=c[1]?(c[1].charAt(0)=="/"?"":"/")+decodeURIComponent(c[1]):"";this.$$search=Xa(c[3]);this.$$hash=c[5]&&decodeURIComponent(c[5])||"";this.$$compose()};this.$$compose=function(){var b=ob(this.$$search),c=this.$$hash?"#"+Za(this.$$hash):"";this.$$url=Eb(this.$$path)+(b?"?"+b:"")+c;this.$$absUrl=ka(this.$$protocol,this.$$host,this.$$port)+d+(this.$$url?"#"+a+this.$$url:"")};this.$$rewriteAppUrl=function(a){if(a.indexOf(c)==0)return a};this.$$parse(b)}function Hb(b,a,c,d){Ia.apply(this,arguments);
   15.60 +this.$$rewriteAppUrl=function(b){if(b.indexOf(c)==0)return c+d+"#"+a+b.substr(c.length)}}function Ja(b){return function(){return this[b]}}function Ib(b,a){return function(c){if(t(c))return this[b];this[b]=a(c);this.$$compose();return this}}function Ic(){var b="",a=!1;this.hashPrefix=function(a){return v(a)?(b=a,this):b};this.html5Mode=function(b){return v(b)?(a=b,this):a};this.$get=["$rootScope","$browser","$sniffer","$rootElement",function(c,d,e,g){function i(a){c.$broadcast("$locationChangeSuccess",
   15.61 +f.absUrl(),a)}var f,h,k,j=d.url(),l=va(j);a?(h=d.baseHref()||"/",k=h.substr(0,h.lastIndexOf("/")),l=ka(l.protocol,l.host,l.port)+k+"/",f=e.history?new gb(Fc(j,h,b),k,l):new Hb(Gc(j,h,b),b,l,h.substr(k.length+1))):(l=ka(l.protocol,l.host,l.port)+(l.path||"")+(l.search?"?"+l.search:"")+"#"+b+"/",f=new Ia(j,b,l));g.bind("click",function(a){if(!a.ctrlKey&&!(a.metaKey||a.which==2)){for(var b=u(a.target);E(b[0].nodeName)!=="a";)if(b[0]===g[0]||!(b=b.parent())[0])return;var d=b.prop("href"),e=f.$$rewriteAppUrl(d);
   15.62 +d&&!b.attr("target")&&e&&(f.$$parse(e),c.$apply(),a.preventDefault(),U.angular["ff-684208-preventDefault"]=!0)}});f.absUrl()!=j&&d.url(f.absUrl(),!0);d.onUrlChange(function(a){f.absUrl()!=a&&(c.$evalAsync(function(){var b=f.absUrl();f.$$parse(a);i(b)}),c.$$phase||c.$digest())});var o=0;c.$watch(function(){var a=d.url(),b=f.$$replace;if(!o||a!=f.absUrl())o++,c.$evalAsync(function(){c.$broadcast("$locationChangeStart",f.absUrl(),a).defaultPrevented?f.$$parse(a):(d.url(f.absUrl(),b),i(a))});f.$$replace=
   15.63 +!1;return o});return f}]}function Jc(){this.$get=["$window",function(b){function a(a){a instanceof B&&(a.stack?a=a.message&&a.stack.indexOf(a.message)===-1?"Error: "+a.message+"\n"+a.stack:a.stack:a.sourceURL&&(a=a.message+"\n"+a.sourceURL+":"+a.line));return a}function c(c){var e=b.console||{},g=e[c]||e.log||D;return g.apply?function(){var b=[];m(arguments,function(c){b.push(a(c))});return g.apply(e,b)}:function(a,b){g(a,b)}}return{log:c("log"),warn:c("warn"),info:c("info"),error:c("error")}}]}function Kc(b,
   15.64 +a){function c(a){return a.indexOf(q)!=-1}function d(){return n+1<b.length?b.charAt(n+1):!1}function e(a){return"0"<=a&&a<="9"}function g(a){return a==" "||a=="\r"||a=="\t"||a=="\n"||a=="\u000b"||a=="\u00a0"}function i(a){return"a"<=a&&a<="z"||"A"<=a&&a<="Z"||"_"==a||a=="$"}function f(a){return a=="-"||a=="+"||e(a)}function h(a,c,d){d=d||n;throw B("Lexer Error: "+a+" at column"+(v(c)?"s "+c+"-"+n+" ["+b.substring(c,d)+"]":" "+d)+" in expression ["+b+"].");}function k(){for(var a="",c=n;n<b.length;){var k=
   15.65 +E(b.charAt(n));if(k=="."||e(k))a+=k;else{var g=d();if(k=="e"&&f(g))a+=k;else if(f(k)&&g&&e(g)&&a.charAt(a.length-1)=="e")a+=k;else if(f(k)&&(!g||!e(g))&&a.charAt(a.length-1)=="e")h("Invalid exponent");else break}n++}a*=1;o.push({index:c,text:a,json:!0,fn:function(){return a}})}function j(){for(var c="",d=n,f,k,h;n<b.length;){var j=b.charAt(n);if(j=="."||i(j)||e(j))j=="."&&(f=n),c+=j;else break;n++}if(f)for(k=n;k<b.length;){j=b.charAt(k);if(j=="("){h=c.substr(f-d+1);c=c.substr(0,f-d);n=k;break}if(g(j))k++;
   15.66 +else break}d={index:d,text:c};if(Ka.hasOwnProperty(c))d.fn=d.json=Ka[c];else{var l=Jb(c,a);d.fn=x(function(a,b){return l(a,b)},{assign:function(a,b){return Kb(a,c,b)}})}o.push(d);h&&(o.push({index:f,text:".",json:!1}),o.push({index:f+1,text:h,json:!1}))}function l(a){var c=n;n++;for(var d="",e=a,f=!1;n<b.length;){var k=b.charAt(n);e+=k;if(f)k=="u"?(k=b.substring(n+1,n+5),k.match(/[\da-f]{4}/i)||h("Invalid unicode escape [\\u"+k+"]"),n+=4,d+=String.fromCharCode(parseInt(k,16))):(f=Lc[k],d+=f?f:k),
   15.67 +f=!1;else if(k=="\\")f=!0;else if(k==a){n++;o.push({index:c,text:e,string:d,json:!0,fn:function(){return d}});return}else d+=k;n++}h("Unterminated quote",c)}for(var o=[],r,n=0,w=[],q,s=":";n<b.length;){q=b.charAt(n);if(c("\"'"))l(q);else if(e(q)||c(".")&&e(d()))k();else if(i(q)){if(j(),"{,".indexOf(s)!=-1&&w[0]=="{"&&(r=o[o.length-1]))r.json=r.text.indexOf(".")==-1}else if(c("(){}[].,;:"))o.push({index:n,text:q,json:":[,".indexOf(s)!=-1&&c("{[")||c("}]:,")}),c("{[")&&w.unshift(q),c("}]")&&w.shift(),
   15.68 +n++;else if(g(q)){n++;continue}else{var m=q+d(),C=Ka[q],A=Ka[m];A?(o.push({index:n,text:m,fn:A}),n+=2):C?(o.push({index:n,text:q,fn:C,json:"[,:".indexOf(s)!=-1&&c("+-")}),n+=1):h("Unexpected next character ",n,n+1)}s=q}return o}function Mc(b,a,c,d){function e(a,c){throw B("Syntax Error: Token '"+c.text+"' "+a+" at column "+(c.index+1)+" of the expression ["+b+"] starting at ["+b.substring(c.index)+"].");}function g(){if(M.length===0)throw B("Unexpected end of expression: "+b);return M[0]}function i(a,
   15.69 +b,c,d){if(M.length>0){var e=M[0],f=e.text;if(f==a||f==b||f==c||f==d||!a&&!b&&!c&&!d)return e}return!1}function f(b,c,d,f){return(b=i(b,c,d,f))?(a&&!b.json&&e("is not valid json",b),M.shift(),b):!1}function h(a){f(a)||e("is unexpected, expecting ["+a+"]",i())}function k(a,b){return function(c,d){return a(c,d,b)}}function j(a,b,c){return function(d,e){return b(d,e,a,c)}}function l(){for(var a=[];;)if(M.length>0&&!i("}",")",";","]")&&a.push(v()),!f(";"))return a.length==1?a[0]:function(b,c){for(var d,
   15.70 +e=0;e<a.length;e++){var f=a[e];f&&(d=f(b,c))}return d}}function o(){for(var a=f(),b=c(a.text),d=[];;)if(a=f(":"))d.push(H());else{var e=function(a,c,e){for(var e=[e],f=0;f<d.length;f++)e.push(d[f](a,c));return b.apply(a,e)};return function(){return e}}}function r(){for(var a=n(),b;;)if(b=f("||"))a=j(a,b.fn,n());else return a}function n(){var a=w(),b;if(b=f("&&"))a=j(a,b.fn,n());return a}function w(){var a=q(),b;if(b=f("==","!="))a=j(a,b.fn,w());return a}function q(){var a;a=s();for(var b;b=f("+",
   15.71 +"-");)a=j(a,b.fn,s());if(b=f("<",">","<=",">="))a=j(a,b.fn,q());return a}function s(){for(var a=m(),b;b=f("*","/","%");)a=j(a,b.fn,m());return a}function m(){var a;return f("+")?C():(a=f("-"))?j(W,a.fn,m()):(a=f("!"))?k(a.fn,m()):C()}function C(){var a;if(f("("))a=v(),h(")");else if(f("["))a=A();else if(f("{"))a=K();else{var b=f();(a=b.fn)||e("not a primary expression",b)}for(var c;b=f("(","[",".");)b.text==="("?(a=u(a,c),c=null):b.text==="["?(c=a,a=ea(a)):b.text==="."?(c=a,a=t(a)):e("IMPOSSIBLE");
   15.72 +return a}function A(){var a=[];if(g().text!="]"){do a.push(H());while(f(","))}h("]");return function(b,c){for(var d=[],e=0;e<a.length;e++)d.push(a[e](b,c));return d}}function K(){var a=[];if(g().text!="}"){do{var b=f(),b=b.string||b.text;h(":");var c=H();a.push({key:b,value:c})}while(f(","))}h("}");return function(b,c){for(var d={},e=0;e<a.length;e++){var f=a[e],k=f.value(b,c);d[f.key]=k}return d}}var W=I(0),y,M=Kc(b,d),H=function(){var a=r(),c,d;return(d=f("="))?(a.assign||e("implies assignment but ["+
   15.73 +b.substring(0,d.index)+"] can not be assigned to",d),c=r(),function(b,d){return a.assign(b,c(b,d),d)}):a},u=function(a,b){var c=[];if(g().text!=")"){do c.push(H());while(f(","))}h(")");return function(d,e){for(var f=[],k=b?b(d,e):d,h=0;h<c.length;h++)f.push(c[h](d,e));h=a(d,e)||D;return h.apply?h.apply(k,f):h(f[0],f[1],f[2],f[3],f[4])}},t=function(a){var b=f().text,c=Jb(b,d);return x(function(b,d){return c(a(b,d),d)},{assign:function(c,d,e){return Kb(a(c,e),b,d)}})},ea=function(a){var b=H();h("]");
   15.74 +return x(function(c,d){var e=a(c,d),f=b(c,d),k;if(!e)return p;if((e=e[f])&&e.then){k=e;if(!("$$v"in e))k.$$v=p,k.then(function(a){k.$$v=a});e=e.$$v}return e},{assign:function(c,d,e){return a(c,e)[b(c,e)]=d}})},v=function(){for(var a=H(),b;;)if(b=f("|"))a=j(a,b.fn,o());else return a};a?(H=r,u=t=ea=v=function(){e("is not valid json",{text:b,index:0})},y=C()):y=l();M.length!==0&&e("is an unexpected token",M[0]);return y}function Kb(b,a,c){for(var a=a.split("."),d=0;a.length>1;d++){var e=a.shift(),g=
   15.75 +b[e];g||(g={},b[e]=g);b=g}return b[a.shift()]=c}function fb(b,a,c){if(!a)return b;for(var a=a.split("."),d,e=b,g=a.length,i=0;i<g;i++)d=a[i],b&&(b=(e=b)[d]);return!c&&N(b)?Va(e,b):b}function Lb(b,a,c,d,e){return function(g,i){var f=i&&i.hasOwnProperty(b)?i:g,h;if(f===null||f===p)return f;if((f=f[b])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}if(!a||f===null||f===p)return f;if((f=f[a])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}if(!c||f===
   15.76 +null||f===p)return f;if((f=f[c])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}if(!d||f===null||f===p)return f;if((f=f[d])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}if(!e||f===null||f===p)return f;if((f=f[e])&&f.then){if(!("$$v"in f))h=f,h.$$v=p,h.then(function(a){h.$$v=a});f=f.$$v}return f}}function Jb(b,a){if(hb.hasOwnProperty(b))return hb[b];var c=b.split("."),d=c.length,e;if(a)e=d<6?Lb(c[0],c[1],c[2],c[3],c[4]):function(a,b){var e=0,
   15.77 +k;do k=Lb(c[e++],c[e++],c[e++],c[e++],c[e++])(a,b),b=p,a=k;while(e<d);return k};else{var g="var l, fn, p;\n";m(c,function(a,b){g+="if(s === null || s === undefined) return s;\nl=s;\ns="+(b?"s":'((k&&k.hasOwnProperty("'+a+'"))?k:s)')+'["'+a+'"];\nif (s && s.then) {\n if (!("$$v" in s)) {\n p=s;\n p.$$v = undefined;\n p.then(function(v) {p.$$v=v;});\n}\n s=s.$$v\n}\n'});g+="return s;";e=Function("s","k",g);e.toString=function(){return g}}return hb[b]=e}function Nc(){var b={};this.$get=["$filter","$sniffer",
   15.78 +function(a,c){return function(d){switch(typeof d){case "string":return b.hasOwnProperty(d)?b[d]:b[d]=Mc(d,!1,a,c.csp);case "function":return d;default:return D}}}]}function Oc(){this.$get=["$rootScope","$exceptionHandler",function(b,a){return Pc(function(a){b.$evalAsync(a)},a)}]}function Pc(b,a){function c(a){return a}function d(a){return i(a)}var e=function(){var f=[],h,k;return k={resolve:function(a){if(f){var c=f;f=p;h=g(a);c.length&&b(function(){for(var a,b=0,d=c.length;b<d;b++)a=c[b],h.then(a[0],
   15.79 +a[1])})}},reject:function(a){k.resolve(i(a))},promise:{then:function(b,k){var g=e(),i=function(d){try{g.resolve((b||c)(d))}catch(e){a(e),g.reject(e)}},n=function(b){try{g.resolve((k||d)(b))}catch(c){a(c),g.reject(c)}};f?f.push([i,n]):h.then(i,n);return g.promise}}}},g=function(a){return a&&a.then?a:{then:function(c){var d=e();b(function(){d.resolve(c(a))});return d.promise}}},i=function(a){return{then:function(c,k){var g=e();b(function(){g.resolve((k||d)(a))});return g.promise}}};return{defer:e,reject:i,
   15.80 +when:function(f,h,k){var j=e(),l,o=function(b){try{return(h||c)(b)}catch(d){return a(d),i(d)}},r=function(b){try{return(k||d)(b)}catch(c){return a(c),i(c)}};b(function(){g(f).then(function(a){l||(l=!0,j.resolve(g(a).then(o,r)))},function(a){l||(l=!0,j.resolve(r(a)))})});return j.promise},all:function(a){var b=e(),c=a.length,d=[];c?m(a,function(a,e){g(a).then(function(a){e in d||(d[e]=a,--c||b.resolve(d))},function(a){e in d||b.reject(a)})}):b.resolve(d);return b.promise}}}function Qc(){var b={};this.when=
   15.81 +function(a,c){b[a]=x({reloadOnSearch:!0},c);if(a){var d=a[a.length-1]=="/"?a.substr(0,a.length-1):a+"/";b[d]={redirectTo:a}}return this};this.otherwise=function(a){this.when(null,a);return this};this.$get=["$rootScope","$location","$routeParams","$q","$injector","$http","$templateCache",function(a,c,d,e,g,i,f){function h(){var b=k(),h=r.current;if(b&&h&&b.$route===h.$route&&ha(b.pathParams,h.pathParams)&&!b.reloadOnSearch&&!o)h.params=b.params,V(h.params,d),a.$broadcast("$routeUpdate",h);else if(b||
   15.82 +h)o=!1,a.$broadcast("$routeChangeStart",b,h),(r.current=b)&&b.redirectTo&&(F(b.redirectTo)?c.path(j(b.redirectTo,b.params)).search(b.params).replace():c.url(b.redirectTo(b.pathParams,c.path(),c.search())).replace()),e.when(b).then(function(){if(b){var a=[],c=[],d;m(b.resolve||{},function(b,d){a.push(d);c.push(F(b)?g.get(b):g.invoke(b))});if(!v(d=b.template))if(v(d=b.templateUrl))d=i.get(d,{cache:f}).then(function(a){return a.data});v(d)&&(a.push("$template"),c.push(d));return e.all(c).then(function(b){var c=
   15.83 +{};m(b,function(b,d){c[a[d]]=b});return c})}}).then(function(c){if(b==r.current){if(b)b.locals=c,V(b.params,d);a.$broadcast("$routeChangeSuccess",b,h)}},function(c){b==r.current&&a.$broadcast("$routeChangeError",b,h,c)})}function k(){var a,d;m(b,function(b,e){if(!d&&(a=l(c.path(),e)))d=ya(b,{params:x({},c.search(),a),pathParams:a}),d.$route=b});return d||b[null]&&ya(b[null],{params:{},pathParams:{}})}function j(a,b){var c=[];m((a||"").split(":"),function(a,d){if(d==0)c.push(a);else{var e=a.match(/(\w+)(.*)/),
   15.84 +f=e[1];c.push(b[f]);c.push(e[2]||"");delete b[f]}});return c.join("")}var l=function(a,b){var c="^"+b.replace(/([\.\\\(\)\^\$])/g,"\\$1")+"$",d=[],e={};m(b.split(/\W/),function(a){if(a){var b=RegExp(":"+a+"([\\W])");c.match(b)&&(c=c.replace(b,"([^\\/]*)$1"),d.push(a))}});var f=a.match(RegExp(c));f&&m(d,function(a,b){e[a]=f[b+1]});return f?e:null},o=!1,r={routes:b,reload:function(){o=!0;a.$evalAsync(h)}};a.$on("$locationChangeSuccess",h);return r}]}function Rc(){this.$get=I({})}function Sc(){var b=
   15.85 +10;this.digestTtl=function(a){arguments.length&&(b=a);return b};this.$get=["$injector","$exceptionHandler","$parse",function(a,c,d){function e(){this.$id=xa();this.$$phase=this.$parent=this.$$watchers=this.$$nextSibling=this.$$prevSibling=this.$$childHead=this.$$childTail=null;this["this"]=this.$root=this;this.$$asyncQueue=[];this.$$listeners={}}function g(a){if(h.$$phase)throw B(h.$$phase+" already in progress");h.$$phase=a}function i(a,b){var c=d(a);ra(c,b);return c}function f(){}e.prototype={$new:function(a){if(N(a))throw B("API-CHANGE: Use $controller to instantiate controllers.");
   15.86 +a?(a=new e,a.$root=this.$root):(a=function(){},a.prototype=this,a=new a,a.$id=xa());a["this"]=a;a.$$listeners={};a.$parent=this;a.$$asyncQueue=[];a.$$watchers=a.$$nextSibling=a.$$childHead=a.$$childTail=null;a.$$prevSibling=this.$$childTail;this.$$childHead?this.$$childTail=this.$$childTail.$$nextSibling=a:this.$$childHead=this.$$childTail=a;return a},$watch:function(a,b,c){var d=i(a,"watch"),e=this.$$watchers,g={fn:b,last:f,get:d,exp:a,eq:!!c};if(!N(b)){var h=i(b||D,"listener");g.fn=function(a,b,
   15.87 +c){h(c)}}if(!e)e=this.$$watchers=[];e.unshift(g);return function(){Ua(e,g)}},$digest:function(){var a,d,e,i,r,n,m,q=b,s,p=[],C,A;g("$digest");do{m=!1;s=this;do{for(r=s.$$asyncQueue;r.length;)try{s.$eval(r.shift())}catch(K){c(K)}if(i=s.$$watchers)for(n=i.length;n--;)try{if(a=i[n],(d=a.get(s))!==(e=a.last)&&!(a.eq?ha(d,e):typeof d=="number"&&typeof e=="number"&&isNaN(d)&&isNaN(e)))m=!0,a.last=a.eq?V(d):d,a.fn(d,e===f?d:e,s),q<5&&(C=4-q,p[C]||(p[C]=[]),A=N(a.exp)?"fn: "+(a.exp.name||a.exp.toString()):
   15.88 +a.exp,A+="; newVal: "+da(d)+"; oldVal: "+da(e),p[C].push(A))}catch(W){c(W)}if(!(i=s.$$childHead||s!==this&&s.$$nextSibling))for(;s!==this&&!(i=s.$$nextSibling);)s=s.$parent}while(s=i);if(m&&!q--)throw h.$$phase=null,B(b+" $digest() iterations reached. Aborting!\nWatchers fired in the last 5 iterations: "+da(p));}while(m||r.length);h.$$phase=null},$destroy:function(){if(h!=this){var a=this.$parent;this.$broadcast("$destroy");if(a.$$childHead==this)a.$$childHead=this.$$nextSibling;if(a.$$childTail==
   15.89 +this)a.$$childTail=this.$$prevSibling;if(this.$$prevSibling)this.$$prevSibling.$$nextSibling=this.$$nextSibling;if(this.$$nextSibling)this.$$nextSibling.$$prevSibling=this.$$prevSibling;this.$parent=this.$$nextSibling=this.$$prevSibling=this.$$childHead=this.$$childTail=null}},$eval:function(a,b){return d(a)(this,b)},$evalAsync:function(a){this.$$asyncQueue.push(a)},$apply:function(a){try{return g("$apply"),this.$eval(a)}catch(b){c(b)}finally{h.$$phase=null;try{h.$digest()}catch(d){throw c(d),d;}}},
   15.90 +$on:function(a,b){var c=this.$$listeners[a];c||(this.$$listeners[a]=c=[]);c.push(b);return function(){c[za(c,b)]=null}},$emit:function(a,b){var d=[],e,f=this,g=!1,h={name:a,targetScope:f,stopPropagation:function(){g=!0},preventDefault:function(){h.defaultPrevented=!0},defaultPrevented:!1},i=[h].concat(ia.call(arguments,1)),m,p;do{e=f.$$listeners[a]||d;h.currentScope=f;m=0;for(p=e.length;m<p;m++)if(e[m])try{if(e[m].apply(null,i),g)return h}catch(C){c(C)}else e.splice(m,1),m--,p--;f=f.$parent}while(f);
   15.91 +return h},$broadcast:function(a,b){var d=this,e=this,f={name:a,targetScope:this,preventDefault:function(){f.defaultPrevented=!0},defaultPrevented:!1},g=[f].concat(ia.call(arguments,1)),h,i;do{d=e;f.currentScope=d;e=d.$$listeners[a]||[];h=0;for(i=e.length;h<i;h++)if(e[h])try{e[h].apply(null,g)}catch(m){c(m)}else e.splice(h,1),h--,i--;if(!(e=d.$$childHead||d!==this&&d.$$nextSibling))for(;d!==this&&!(e=d.$$nextSibling);)d=d.$parent}while(d=e);return f}};var h=new e;return h}]}function Tc(){this.$get=
   15.92 +["$window",function(b){var a={},c=G((/android (\d+)/.exec(E(b.navigator.userAgent))||[])[1]);return{history:!(!b.history||!b.history.pushState||c<4),hashchange:"onhashchange"in b&&(!b.document.documentMode||b.document.documentMode>7),hasEvent:function(c){if(c=="input"&&aa==9)return!1;if(t(a[c])){var e=b.document.createElement("div");a[c]="on"+c in e}return a[c]},csp:!1}}]}function Uc(){this.$get=I(U)}function Mb(b){var a={},c,d,e;if(!b)return a;m(b.split("\n"),function(b){e=b.indexOf(":");c=E(R(b.substr(0,
   15.93 +e)));d=R(b.substr(e+1));c&&(a[c]?a[c]+=", "+d:a[c]=d)});return a}function Nb(b){var a=L(b)?b:p;return function(c){a||(a=Mb(b));return c?a[E(c)]||null:a}}function Ob(b,a,c){if(N(c))return c(b,a);m(c,function(c){b=c(b,a)});return b}function Vc(){var b=/^\s*(\[|\{[^\{])/,a=/[\}\]]\s*$/,c=/^\)\]\}',?\n/,d=this.defaults={transformResponse:[function(d){F(d)&&(d=d.replace(c,""),b.test(d)&&a.test(d)&&(d=nb(d,!0)));return d}],transformRequest:[function(a){return L(a)&&Sa.apply(a)!=="[object File]"?da(a):a}],
   15.94 +headers:{common:{Accept:"application/json, text/plain, */*","X-Requested-With":"XMLHttpRequest"},post:{"Content-Type":"application/json;charset=utf-8"},put:{"Content-Type":"application/json;charset=utf-8"}}},e=this.responseInterceptors=[];this.$get=["$httpBackend","$browser","$cacheFactory","$rootScope","$q","$injector",function(a,b,c,h,k,j){function l(a){function c(a){var b=x({},a,{data:Ob(a.data,a.headers,f)});return 200<=a.status&&a.status<300?b:k.reject(b)}a.method=la(a.method);var e=a.transformRequest||
   15.95 +d.transformRequest,f=a.transformResponse||d.transformResponse,h=d.headers,h=x({"X-XSRF-TOKEN":b.cookies()["XSRF-TOKEN"]},h.common,h[E(a.method)],a.headers),e=Ob(a.data,Nb(h),e),g;t(a.data)&&delete h["Content-Type"];g=o(a,e,h);g=g.then(c,c);m(w,function(a){g=a(g)});g.success=function(b){g.then(function(c){b(c.data,c.status,c.headers,a)});return g};g.error=function(b){g.then(null,function(c){b(c.data,c.status,c.headers,a)});return g};return g}function o(b,c,d){function e(a,b,c){m&&(200<=a&&a<300?m.put(w,
   15.96 +[a,b,Mb(c)]):m.remove(w));f(b,a,c);h.$apply()}function f(a,c,d){c=Math.max(c,0);(200<=c&&c<300?j.resolve:j.reject)({data:a,status:c,headers:Nb(d),config:b})}function i(){var a=za(l.pendingRequests,b);a!==-1&&l.pendingRequests.splice(a,1)}var j=k.defer(),o=j.promise,m,p,w=r(b.url,b.params);l.pendingRequests.push(b);o.then(i,i);b.cache&&b.method=="GET"&&(m=L(b.cache)?b.cache:n);if(m)if(p=m.get(w))if(p.then)return p.then(i,i),p;else J(p)?f(p[1],p[0],V(p[2])):f(p,200,{});else m.put(w,o);p||a(b.method,
   15.97 +w,c,e,d,b.timeout,b.withCredentials);return o}function r(a,b){if(!b)return a;var c=[];ec(b,function(a,b){a==null||a==p||(L(a)&&(a=da(a)),c.push(encodeURIComponent(b)+"="+encodeURIComponent(a)))});return a+(a.indexOf("?")==-1?"?":"&")+c.join("&")}var n=c("$http"),w=[];m(e,function(a){w.push(F(a)?j.get(a):j.invoke(a))});l.pendingRequests=[];(function(a){m(arguments,function(a){l[a]=function(b,c){return l(x(c||{},{method:a,url:b}))}})})("get","delete","head","jsonp");(function(a){m(arguments,function(a){l[a]=
   15.98 +function(b,c,d){return l(x(d||{},{method:a,url:b,data:c}))}})})("post","put");l.defaults=d;return l}]}function Wc(){this.$get=["$browser","$window","$document",function(b,a,c){return Xc(b,Yc,b.defer,a.angular.callbacks,c[0],a.location.protocol.replace(":",""))}]}function Xc(b,a,c,d,e,g){function i(a,b){var c=e.createElement("script"),d=function(){e.body.removeChild(c);b&&b()};c.type="text/javascript";c.src=a;aa?c.onreadystatechange=function(){/loaded|complete/.test(c.readyState)&&d()}:c.onload=c.onerror=
   15.99 +d;e.body.appendChild(c)}return function(e,h,k,j,l,o,r){function n(a,c,d,e){c=(h.match(Fb)||["",g])[1]=="file"?d?200:404:c;a(c==1223?204:c,d,e);b.$$completeOutstandingRequest(D)}b.$$incOutstandingRequestCount();h=h||b.url();if(E(e)=="jsonp"){var p="_"+(d.counter++).toString(36);d[p]=function(a){d[p].data=a};i(h.replace("JSON_CALLBACK","angular.callbacks."+p),function(){d[p].data?n(j,200,d[p].data):n(j,-2);delete d[p]})}else{var q=new a;q.open(e,h,!0);m(l,function(a,b){a&&q.setRequestHeader(b,a)});
  15.100 +var s;q.onreadystatechange=function(){q.readyState==4&&n(j,s||q.status,q.responseText,q.getAllResponseHeaders())};if(r)q.withCredentials=!0;q.send(k||"");o>0&&c(function(){s=-1;q.abort()},o)}}}function Zc(){this.$get=function(){return{id:"en-us",NUMBER_FORMATS:{DECIMAL_SEP:".",GROUP_SEP:",",PATTERNS:[{minInt:1,minFrac:0,maxFrac:3,posPre:"",posSuf:"",negPre:"-",negSuf:"",gSize:3,lgSize:3},{minInt:1,minFrac:2,maxFrac:2,posPre:"\u00a4",posSuf:"",negPre:"(\u00a4",negSuf:")",gSize:3,lgSize:3}],CURRENCY_SYM:"$"},
  15.101 +DATETIME_FORMATS:{MONTH:"January,February,March,April,May,June,July,August,September,October,November,December".split(","),SHORTMONTH:"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(","),DAY:"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(","),SHORTDAY:"Sun,Mon,Tue,Wed,Thu,Fri,Sat".split(","),AMPMS:["AM","PM"],medium:"MMM d, y h:mm:ss a","short":"M/d/yy h:mm a",fullDate:"EEEE, MMMM d, y",longDate:"MMMM d, y",mediumDate:"MMM d, y",shortDate:"M/d/yy",mediumTime:"h:mm:ss a",
  15.102 +shortTime:"h:mm a"},pluralCat:function(b){return b===1?"one":"other"}}}}function $c(){this.$get=["$rootScope","$browser","$q","$exceptionHandler",function(b,a,c,d){function e(e,f,h){var k=c.defer(),j=k.promise,l=v(h)&&!h,f=a.defer(function(){try{k.resolve(e())}catch(a){k.reject(a),d(a)}l||b.$apply()},f),h=function(){delete g[j.$$timeoutId]};j.$$timeoutId=f;g[f]=k;j.then(h,h);return j}var g={};e.cancel=function(b){return b&&b.$$timeoutId in g?(g[b.$$timeoutId].reject("canceled"),a.defer.cancel(b.$$timeoutId)):
  15.103 +!1};return e}]}function Pb(b){function a(a,e){return b.factory(a+c,e)}var c="Filter";this.register=a;this.$get=["$injector",function(a){return function(b){return a.get(b+c)}}];a("currency",Qb);a("date",Rb);a("filter",ad);a("json",bd);a("limitTo",cd);a("lowercase",dd);a("number",Sb);a("orderBy",Tb);a("uppercase",ed)}function ad(){return function(b,a){if(!(b instanceof Array))return b;var c=[];c.check=function(a){for(var b=0;b<c.length;b++)if(!c[b](a))return!1;return!0};var d=function(a,b){if(b.charAt(0)===
  15.104 +"!")return!d(a,b.substr(1));switch(typeof a){case "boolean":case "number":case "string":return(""+a).toLowerCase().indexOf(b)>-1;case "object":for(var c in a)if(c.charAt(0)!=="$"&&d(a[c],b))return!0;return!1;case "array":for(c=0;c<a.length;c++)if(d(a[c],b))return!0;return!1;default:return!1}};switch(typeof a){case "boolean":case "number":case "string":a={$:a};case "object":for(var e in a)e=="$"?function(){var b=(""+a[e]).toLowerCase();b&&c.push(function(a){return d(a,b)})}():function(){var b=e,f=
  15.105 +(""+a[e]).toLowerCase();f&&c.push(function(a){return d(fb(a,b),f)})}();break;case "function":c.push(a);break;default:return b}for(var g=[],i=0;i<b.length;i++){var f=b[i];c.check(f)&&g.push(f)}return g}}function Qb(b){var a=b.NUMBER_FORMATS;return function(b,d){if(t(d))d=a.CURRENCY_SYM;return Ub(b,a.PATTERNS[1],a.GROUP_SEP,a.DECIMAL_SEP,2).replace(/\u00A4/g,d)}}function Sb(b){var a=b.NUMBER_FORMATS;return function(b,d){return Ub(b,a.PATTERNS[0],a.GROUP_SEP,a.DECIMAL_SEP,d)}}function Ub(b,a,c,d,e){if(isNaN(b)||
  15.106 +!isFinite(b))return"";var g=b<0,b=Math.abs(b),i=b+"",f="",h=[],k=!1;if(i.indexOf("e")!==-1){var j=i.match(/([\d\.]+)e(-?)(\d+)/);j&&j[2]=="-"&&j[3]>e+1?i="0":(f=i,k=!0)}if(!k){i=(i.split(Vb)[1]||"").length;t(e)&&(e=Math.min(Math.max(a.minFrac,i),a.maxFrac));var i=Math.pow(10,e),b=Math.round(b*i)/i,b=(""+b).split(Vb),i=b[0],b=b[1]||"",k=0,j=a.lgSize,l=a.gSize;if(i.length>=j+l)for(var k=i.length-j,o=0;o<k;o++)(k-o)%l===0&&o!==0&&(f+=c),f+=i.charAt(o);for(o=k;o<i.length;o++)(i.length-o)%j===0&&o!==0&&
  15.107 +(f+=c),f+=i.charAt(o);for(;b.length<e;)b+="0";e&&(f+=d+b.substr(0,e))}h.push(g?a.negPre:a.posPre);h.push(f);h.push(g?a.negSuf:a.posSuf);return h.join("")}function ib(b,a,c){var d="";b<0&&(d="-",b=-b);for(b=""+b;b.length<a;)b="0"+b;c&&(b=b.substr(b.length-a));return d+b}function P(b,a,c,d){return function(e){e=e["get"+b]();if(c>0||e>-c)e+=c;e===0&&c==-12&&(e=12);return ib(e,a,d)}}function La(b,a){return function(c,d){var e=c["get"+b](),g=la(a?"SHORT"+b:b);return d[g][e]}}function Rb(b){function a(a){var b;
  15.108 +if(b=a.match(c)){var a=new Date(0),g=0,i=0;b[9]&&(g=G(b[9]+b[10]),i=G(b[9]+b[11]));a.setUTCFullYear(G(b[1]),G(b[2])-1,G(b[3]));a.setUTCHours(G(b[4]||0)-g,G(b[5]||0)-i,G(b[6]||0),G(b[7]||0))}return a}var c=/^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;return function(c,e){var g="",i=[],f,h,e=e||"mediumDate",e=b.DATETIME_FORMATS[e]||e;F(c)&&(c=fd.test(c)?G(c):a(c));wa(c)&&(c=new Date(c));if(!na(c))return c;for(;e;)(h=gd.exec(e))?(i=i.concat(ia.call(h,
  15.109 +1)),e=i.pop()):(i.push(e),e=null);m(i,function(a){f=hd[a];g+=f?f(c,b.DATETIME_FORMATS):a.replace(/(^'|'$)/g,"").replace(/''/g,"'")});return g}}function bd(){return function(b){return da(b,!0)}}function cd(){return function(b,a){if(!(b instanceof Array))return b;var a=G(a),c=[],d,e;if(!b||!(b instanceof Array))return c;a>b.length?a=b.length:a<-b.length&&(a=-b.length);a>0?(d=0,e=a):(d=b.length+a,e=b.length);for(;d<e;d++)c.push(b[d]);return c}}function Tb(b){return function(a,c,d){function e(a,b){return Wa(b)?
  15.110 +function(b,c){return a(c,b)}:a}if(!(a instanceof Array))return a;if(!c)return a;for(var c=J(c)?c:[c],c=Ta(c,function(a){var c=!1,d=a||ma;if(F(a)){if(a.charAt(0)=="+"||a.charAt(0)=="-")c=a.charAt(0)=="-",a=a.substring(1);d=b(a)}return e(function(a,b){var c;c=d(a);var e=d(b),f=typeof c,g=typeof e;f==g?(f=="string"&&(c=c.toLowerCase()),f=="string"&&(e=e.toLowerCase()),c=c===e?0:c<e?-1:1):c=f<g?-1:1;return c},c)}),g=[],i=0;i<a.length;i++)g.push(a[i]);return g.sort(e(function(a,b){for(var d=0;d<c.length;d++){var e=
  15.111 +c[d](a,b);if(e!==0)return e}return 0},d))}}function S(b){N(b)&&(b={link:b});b.restrict=b.restrict||"AC";return I(b)}function Wb(b,a){function c(a,c){c=c?"-"+$a(c,"-"):"";b.removeClass((a?Ma:Na)+c).addClass((a?Na:Ma)+c)}var d=this,e=b.parent().controller("form")||Oa,g=0,i=d.$error={};d.$name=a.name;d.$dirty=!1;d.$pristine=!0;d.$valid=!0;d.$invalid=!1;e.$addControl(d);b.addClass(Pa);c(!0);d.$addControl=function(a){a.$name&&!d.hasOwnProperty(a.$name)&&(d[a.$name]=a)};d.$removeControl=function(a){a.$name&&
  15.112 +d[a.$name]===a&&delete d[a.$name];m(i,function(b,c){d.$setValidity(c,!0,a)})};d.$setValidity=function(a,b,k){var j=i[a];if(b){if(j&&(Ua(j,k),!j.length)){g--;if(!g)c(b),d.$valid=!0,d.$invalid=!1;i[a]=!1;c(!0,a);e.$setValidity(a,!0,d)}}else{g||c(b);if(j){if(za(j,k)!=-1)return}else i[a]=j=[],g++,c(!1,a),e.$setValidity(a,!1,d);j.push(k);d.$valid=!1;d.$invalid=!0}};d.$setDirty=function(){b.removeClass(Pa).addClass(Xb);d.$dirty=!0;d.$pristine=!1;e.$setDirty()}}function T(b){return t(b)||b===""||b===null||
  15.113 +b!==b}function Qa(b,a,c,d,e,g){var i=function(){var c=R(a.val());d.$viewValue!==c&&b.$apply(function(){d.$setViewValue(c)})};if(e.hasEvent("input"))a.bind("input",i);else{var f;a.bind("keydown",function(a){a=a.keyCode;a===91||15<a&&a<19||37<=a&&a<=40||f||(f=g.defer(function(){i();f=null}))});a.bind("change",i)}d.$render=function(){a.val(T(d.$viewValue)?"":d.$viewValue)};var h=c.ngPattern,k=function(a,b){return T(b)||a.test(b)?(d.$setValidity("pattern",!0),b):(d.$setValidity("pattern",!1),p)};h&&(h.match(/^\/(.*)\/$/)?
  15.114 +(h=RegExp(h.substr(1,h.length-2)),e=function(a){return k(h,a)}):e=function(a){var c=b.$eval(h);if(!c||!c.test)throw new B("Expected "+h+" to be a RegExp but was "+c);return k(c,a)},d.$formatters.push(e),d.$parsers.push(e));if(c.ngMinlength){var j=G(c.ngMinlength),e=function(a){return!T(a)&&a.length<j?(d.$setValidity("minlength",!1),p):(d.$setValidity("minlength",!0),a)};d.$parsers.push(e);d.$formatters.push(e)}if(c.ngMaxlength){var l=G(c.ngMaxlength),c=function(a){return!T(a)&&a.length>l?(d.$setValidity("maxlength",
  15.115 +!1),p):(d.$setValidity("maxlength",!0),a)};d.$parsers.push(c);d.$formatters.push(c)}}function jb(b,a){b="ngClass"+b;return S(function(c,d,e){function g(b,d){if(a===!0||c.$index%2===a)d&&b!==d&&i(d),f(b)}function i(a){L(a)&&!J(a)&&(a=Ta(a,function(a,b){if(a)return b}));d.removeClass(J(a)?a.join(" "):a)}function f(a){L(a)&&!J(a)&&(a=Ta(a,function(a,b){if(a)return b}));a&&d.addClass(J(a)?a.join(" "):a)}c.$watch(e[b],g,!0);e.$observe("class",function(){var a=c.$eval(e[b]);g(a,a)});b!=="ngClass"&&c.$watch("$index",
  15.116 +function(d,g){var j=d%2;j!==g%2&&(j==a?f(c.$eval(e[b])):i(c.$eval(e[b])))})})}var E=function(b){return F(b)?b.toLowerCase():b},la=function(b){return F(b)?b.toUpperCase():b},B=U.Error,aa=G((/msie (\d+)/.exec(E(navigator.userAgent))||[])[1]),u,ja,ia=[].slice,Ra=[].push,Sa=Object.prototype.toString,Yb=U.angular||(U.angular={}),ta,Cb,Z=["0","0","0"];D.$inject=[];ma.$inject=[];Cb=aa<9?function(b){b=b.nodeName?b:b[0];return b.scopeName&&b.scopeName!="HTML"?la(b.scopeName+":"+b.nodeName):b.nodeName}:function(b){return b.nodeName?
  15.117 +b.nodeName:b[0].nodeName};var kc=/[A-Z]/g,id={full:"1.0.3",major:1,minor:0,dot:3,codeName:"bouncy-thunder"},Ba=Q.cache={},Aa=Q.expando="ng-"+(new Date).getTime(),oc=1,Zb=U.document.addEventListener?function(b,a,c){b.addEventListener(a,c,!1)}:function(b,a,c){b.attachEvent("on"+a,c)},db=U.document.removeEventListener?function(b,a,c){b.removeEventListener(a,c,!1)}:function(b,a,c){b.detachEvent("on"+a,c)},mc=/([\:\-\_]+(.))/g,nc=/^moz([A-Z])/,ua=Q.prototype={ready:function(b){function a(){c||(c=!0,b())}
  15.118 +var c=!1;this.bind("DOMContentLoaded",a);Q(U).bind("load",a)},toString:function(){var b=[];m(this,function(a){b.push(""+a)});return"["+b.join(", ")+"]"},eq:function(b){return b>=0?u(this[b]):u(this[this.length+b])},length:0,push:Ra,sort:[].sort,splice:[].splice},Ea={};m("multiple,selected,checked,disabled,readOnly,required".split(","),function(b){Ea[E(b)]=b});var zb={};m("input,select,option,textarea,button,form".split(","),function(b){zb[la(b)]=!0});m({data:ub,inheritedData:Da,scope:function(b){return Da(b,
  15.119 +"$scope")},controller:xb,injector:function(b){return Da(b,"$injector")},removeAttr:function(b,a){b.removeAttribute(a)},hasClass:Ca,css:function(b,a,c){a=rb(a);if(v(c))b.style[a]=c;else{var d;aa<=8&&(d=b.currentStyle&&b.currentStyle[a],d===""&&(d="auto"));d=d||b.style[a];aa<=8&&(d=d===""?p:d);return d}},attr:function(b,a,c){var d=E(a);if(Ea[d])if(v(c))c?(b[a]=!0,b.setAttribute(a,d)):(b[a]=!1,b.removeAttribute(d));else return b[a]||(b.attributes.getNamedItem(a)||D).specified?d:p;else if(v(c))b.setAttribute(a,
  15.120 +c);else if(b.getAttribute)return b=b.getAttribute(a,2),b===null?p:b},prop:function(b,a,c){if(v(c))b[a]=c;else return b[a]},text:x(aa<9?function(b,a){if(b.nodeType==1){if(t(a))return b.innerText;b.innerText=a}else{if(t(a))return b.nodeValue;b.nodeValue=a}}:function(b,a){if(t(a))return b.textContent;b.textContent=a},{$dv:""}),val:function(b,a){if(t(a))return b.value;b.value=a},html:function(b,a){if(t(a))return b.innerHTML;for(var c=0,d=b.childNodes;c<d.length;c++)sa(d[c]);b.innerHTML=a}},function(b,
  15.121 +a){Q.prototype[a]=function(a,d){var e,g;if((b.length==2&&b!==Ca&&b!==xb?a:d)===p)if(L(a)){for(e=0;e<this.length;e++)if(b===ub)b(this[e],a);else for(g in a)b(this[e],g,a[g]);return this}else{if(this.length)return b(this[0],a,d)}else{for(e=0;e<this.length;e++)b(this[e],a,d);return this}return b.$dv}});m({removeData:sb,dealoc:sa,bind:function a(c,d,e){var g=$(c,"events"),i=$(c,"handle");g||$(c,"events",g={});i||$(c,"handle",i=pc(c,g));m(d.split(" "),function(d){var h=g[d];if(!h){if(d=="mouseenter"||
  15.122 +d=="mouseleave"){var k=0;g.mouseenter=[];g.mouseleave=[];a(c,"mouseover",function(a){k++;k==1&&i(a,"mouseenter")});a(c,"mouseout",function(a){k--;k==0&&i(a,"mouseleave")})}else Zb(c,d,i),g[d]=[];h=g[d]}h.push(e)})},unbind:tb,replaceWith:function(a,c){var d,e=a.parentNode;sa(a);m(new Q(c),function(c){d?e.insertBefore(c,d.nextSibling):e.replaceChild(c,a);d=c})},children:function(a){var c=[];m(a.childNodes,function(a){a.nodeName!="#text"&&c.push(a)});return c},contents:function(a){return a.childNodes},
  15.123 +append:function(a,c){m(new Q(c),function(c){a.nodeType===1&&a.appendChild(c)})},prepend:function(a,c){if(a.nodeType===1){var d=a.firstChild;m(new Q(c),function(c){d?a.insertBefore(c,d):(a.appendChild(c),d=c)})}},wrap:function(a,c){var c=u(c)[0],d=a.parentNode;d&&d.replaceChild(c,a);c.appendChild(a)},remove:function(a){sa(a);var c=a.parentNode;c&&c.removeChild(a)},after:function(a,c){var d=a,e=a.parentNode;m(new Q(c),function(a){e.insertBefore(a,d.nextSibling);d=a})},addClass:wb,removeClass:vb,toggleClass:function(a,
  15.124 +c,d){t(d)&&(d=!Ca(a,c));(d?wb:vb)(a,c)},parent:function(a){return(a=a.parentNode)&&a.nodeType!==11?a:null},next:function(a){return a.nextSibling},find:function(a,c){return a.getElementsByTagName(c)},clone:cb,triggerHandler:function(a,c){var d=($(a,"events")||{})[c];m(d,function(c){c.call(a,null)})}},function(a,c){Q.prototype[c]=function(c,e){for(var g,i=0;i<this.length;i++)g==p?(g=a(this[i],c,e),g!==p&&(g=u(g))):bb(g,a(this[i],c,e));return g==p?this:g}});Fa.prototype={put:function(a,c){this[ga(a)]=
  15.125 +c},get:function(a){return this[ga(a)]},remove:function(a){var c=this[a=ga(a)];delete this[a];return c}};eb.prototype={push:function(a,c){var d=this[a=ga(a)];d?d.push(c):this[a]=[c]},shift:function(a){var c=this[a=ga(a)];if(c)return c.length==1?(delete this[a],c[0]):c.shift()},peek:function(a){if(a=this[ga(a)])return a[0]}};var rc=/^function\s*[^\(]*\(\s*([^\)]*)\)/m,sc=/,/,tc=/^\s*(_?)(\S+?)\1\s*$/,qc=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg,Db="Non-assignable model expression: ";Bb.$inject=["$provide"];
  15.126 +var Ac=/^(x[\:\-_]|data[\:\-_])/i,Fb=/^([^:]+):\/\/(\w+:{0,1}\w*@)?([\w\.-]*)(:([0-9]+))?(\/[^\?#]*)?(\?([^#]*))?(#(.*))?$/,$b=/^([^\?#]*)?(\?([^#]*))?(#(.*))?$/,Hc=$b,Gb={http:80,https:443,ftp:21};gb.prototype={$$replace:!1,absUrl:Ja("$$absUrl"),url:function(a,c){if(t(a))return this.$$url;var d=$b.exec(a);d[1]&&this.path(decodeURIComponent(d[1]));if(d[2]||d[1])this.search(d[3]||"");this.hash(d[5]||"",c);return this},protocol:Ja("$$protocol"),host:Ja("$$host"),port:Ja("$$port"),path:Ib("$$path",function(a){return a.charAt(0)==
  15.127 +"/"?a:"/"+a}),search:function(a,c){if(t(a))return this.$$search;v(c)?c===null?delete this.$$search[a]:this.$$search[a]=c:this.$$search=F(a)?Xa(a):a;this.$$compose();return this},hash:Ib("$$hash",ma),replace:function(){this.$$replace=!0;return this}};Ia.prototype=ya(gb.prototype);Hb.prototype=ya(Ia.prototype);var Ka={"null":function(){return null},"true":function(){return!0},"false":function(){return!1},undefined:D,"+":function(a,c,d,e){d=d(a,c);e=e(a,c);return v(d)?v(e)?d+e:d:v(e)?e:p},"-":function(a,
  15.128 +c,d,e){d=d(a,c);e=e(a,c);return(v(d)?d:0)-(v(e)?e:0)},"*":function(a,c,d,e){return d(a,c)*e(a,c)},"/":function(a,c,d,e){return d(a,c)/e(a,c)},"%":function(a,c,d,e){return d(a,c)%e(a,c)},"^":function(a,c,d,e){return d(a,c)^e(a,c)},"=":D,"==":function(a,c,d,e){return d(a,c)==e(a,c)},"!=":function(a,c,d,e){return d(a,c)!=e(a,c)},"<":function(a,c,d,e){return d(a,c)<e(a,c)},">":function(a,c,d,e){return d(a,c)>e(a,c)},"<=":function(a,c,d,e){return d(a,c)<=e(a,c)},">=":function(a,c,d,e){return d(a,c)>=e(a,
  15.129 +c)},"&&":function(a,c,d,e){return d(a,c)&&e(a,c)},"||":function(a,c,d,e){return d(a,c)||e(a,c)},"&":function(a,c,d,e){return d(a,c)&e(a,c)},"|":function(a,c,d,e){return e(a,c)(a,c,d(a,c))},"!":function(a,c,d){return!d(a,c)}},Lc={n:"\n",f:"\u000c",r:"\r",t:"\t",v:"\u000b","'":"'",'"':'"'},hb={},Yc=U.XMLHttpRequest||function(){try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(c){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(d){}throw new B("This browser does not support XMLHttpRequest.");
  15.130 +};Pb.$inject=["$provide"];Qb.$inject=["$locale"];Sb.$inject=["$locale"];var Vb=".",hd={yyyy:P("FullYear",4),yy:P("FullYear",2,0,!0),y:P("FullYear",1),MMMM:La("Month"),MMM:La("Month",!0),MM:P("Month",2,1),M:P("Month",1,1),dd:P("Date",2),d:P("Date",1),HH:P("Hours",2),H:P("Hours",1),hh:P("Hours",2,-12),h:P("Hours",1,-12),mm:P("Minutes",2),m:P("Minutes",1),ss:P("Seconds",2),s:P("Seconds",1),EEEE:La("Day"),EEE:La("Day",!0),a:function(a,c){return a.getHours()<12?c.AMPMS[0]:c.AMPMS[1]},Z:function(a){a=a.getTimezoneOffset();
  15.131 +return ib(a/60,2)+ib(Math.abs(a%60),2)}},gd=/((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/,fd=/^\d+$/;Rb.$inject=["$locale"];var dd=I(E),ed=I(la);Tb.$inject=["$parse"];var jd=I({restrict:"E",compile:function(a,c){c.href||c.$set("href","");return function(a,c){c.bind("click",function(a){if(!c.attr("href"))return a.preventDefault(),!1})}}}),kb={};m(Ea,function(a,c){var d=fa("ng-"+c);kb[d]=function(){return{priority:100,compile:function(){return function(a,g,i){a.$watch(i[d],
  15.132 +function(a){i.$set(c,!!a)})}}}}});m(["src","href"],function(a){var c=fa("ng-"+a);kb[c]=function(){return{priority:99,link:function(d,e,g){g.$observe(c,function(c){c&&(g.$set(a,c),aa&&e.prop(a,c))})}}}});var Oa={$addControl:D,$removeControl:D,$setValidity:D,$setDirty:D};Wb.$inject=["$element","$attrs","$scope"];var Ra=function(a){return["$timeout",function(c){var d={name:"form",restrict:"E",controller:Wb,compile:function(){return{pre:function(a,d,i,f){if(!i.action){var h=function(a){a.preventDefault?
  15.133 +a.preventDefault():a.returnValue=!1};Zb(d[0],"submit",h);d.bind("$destroy",function(){c(function(){db(d[0],"submit",h)},0,!1)})}var k=d.parent().controller("form"),j=i.name||i.ngForm;j&&(a[j]=f);k&&d.bind("$destroy",function(){k.$removeControl(f);j&&(a[j]=p);x(f,Oa)})}}}};return a?x(V(d),{restrict:"EAC"}):d}]},kd=Ra(),ld=Ra(!0),md=/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/,nd=/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/,od=/^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/,
  15.134 +ac={text:Qa,number:function(a,c,d,e,g,i){Qa(a,c,d,e,g,i);e.$parsers.push(function(a){var c=T(a);return c||od.test(a)?(e.$setValidity("number",!0),a===""?null:c?a:parseFloat(a)):(e.$setValidity("number",!1),p)});e.$formatters.push(function(a){return T(a)?"":""+a});if(d.min){var f=parseFloat(d.min),a=function(a){return!T(a)&&a<f?(e.$setValidity("min",!1),p):(e.$setValidity("min",!0),a)};e.$parsers.push(a);e.$formatters.push(a)}if(d.max){var h=parseFloat(d.max),d=function(a){return!T(a)&&a>h?(e.$setValidity("max",
  15.135 +!1),p):(e.$setValidity("max",!0),a)};e.$parsers.push(d);e.$formatters.push(d)}e.$formatters.push(function(a){return T(a)||wa(a)?(e.$setValidity("number",!0),a):(e.$setValidity("number",!1),p)})},url:function(a,c,d,e,g,i){Qa(a,c,d,e,g,i);a=function(a){return T(a)||md.test(a)?(e.$setValidity("url",!0),a):(e.$setValidity("url",!1),p)};e.$formatters.push(a);e.$parsers.push(a)},email:function(a,c,d,e,g,i){Qa(a,c,d,e,g,i);a=function(a){return T(a)||nd.test(a)?(e.$setValidity("email",!0),a):(e.$setValidity("email",
  15.136 +!1),p)};e.$formatters.push(a);e.$parsers.push(a)},radio:function(a,c,d,e){t(d.name)&&c.attr("name",xa());c.bind("click",function(){c[0].checked&&a.$apply(function(){e.$setViewValue(d.value)})});e.$render=function(){c[0].checked=d.value==e.$viewValue};d.$observe("value",e.$render)},checkbox:function(a,c,d,e){var g=d.ngTrueValue,i=d.ngFalseValue;F(g)||(g=!0);F(i)||(i=!1);c.bind("click",function(){a.$apply(function(){e.$setViewValue(c[0].checked)})});e.$render=function(){c[0].checked=e.$viewValue};e.$formatters.push(function(a){return a===
  15.137 +g});e.$parsers.push(function(a){return a?g:i})},hidden:D,button:D,submit:D,reset:D},bc=["$browser","$sniffer",function(a,c){return{restrict:"E",require:"?ngModel",link:function(d,e,g,i){i&&(ac[E(g.type)]||ac.text)(d,e,g,i,c,a)}}}],Na="ng-valid",Ma="ng-invalid",Pa="ng-pristine",Xb="ng-dirty",pd=["$scope","$exceptionHandler","$attrs","$element","$parse",function(a,c,d,e,g){function i(a,c){c=c?"-"+$a(c,"-"):"";e.removeClass((a?Ma:Na)+c).addClass((a?Na:Ma)+c)}this.$modelValue=this.$viewValue=Number.NaN;
  15.138 +this.$parsers=[];this.$formatters=[];this.$viewChangeListeners=[];this.$pristine=!0;this.$dirty=!1;this.$valid=!0;this.$invalid=!1;this.$name=d.name;var f=g(d.ngModel),h=f.assign;if(!h)throw B(Db+d.ngModel+" ("+pa(e)+")");this.$render=D;var k=e.inheritedData("$formController")||Oa,j=0,l=this.$error={};e.addClass(Pa);i(!0);this.$setValidity=function(a,c){if(l[a]!==!c){if(c){if(l[a]&&j--,!j)i(!0),this.$valid=!0,this.$invalid=!1}else i(!1),this.$invalid=!0,this.$valid=!1,j++;l[a]=!c;i(c,a);k.$setValidity(a,
  15.139 +c,this)}};this.$setViewValue=function(d){this.$viewValue=d;if(this.$pristine)this.$dirty=!0,this.$pristine=!1,e.removeClass(Pa).addClass(Xb),k.$setDirty();m(this.$parsers,function(a){d=a(d)});if(this.$modelValue!==d)this.$modelValue=d,h(a,d),m(this.$viewChangeListeners,function(a){try{a()}catch(d){c(d)}})};var o=this;a.$watch(function(){var c=f(a);if(o.$modelValue!==c){var d=o.$formatters,e=d.length;for(o.$modelValue=c;e--;)c=d[e](c);if(o.$viewValue!==c)o.$viewValue=c,o.$render()}})}],qd=function(){return{require:["ngModel",
  15.140 +"^?form"],controller:pd,link:function(a,c,d,e){var g=e[0],i=e[1]||Oa;i.$addControl(g);c.bind("$destroy",function(){i.$removeControl(g)})}}},rd=I({require:"ngModel",link:function(a,c,d,e){e.$viewChangeListeners.push(function(){a.$eval(d.ngChange)})}}),cc=function(){return{require:"?ngModel",link:function(a,c,d,e){if(e){d.required=!0;var g=function(a){if(d.required&&(T(a)||a===!1))e.$setValidity("required",!1);else return e.$setValidity("required",!0),a};e.$formatters.push(g);e.$parsers.unshift(g);
  15.141 +d.$observe("required",function(){g(e.$viewValue)})}}}},sd=function(){return{require:"ngModel",link:function(a,c,d,e){var g=(a=/\/(.*)\//.exec(d.ngList))&&RegExp(a[1])||d.ngList||",";e.$parsers.push(function(a){var c=[];a&&m(a.split(g),function(a){a&&c.push(R(a))});return c});e.$formatters.push(function(a){return J(a)?a.join(", "):p})}}},td=/^(true|false|\d+)$/,ud=function(){return{priority:100,compile:function(a,c){return td.test(c.ngValue)?function(a,c,g){g.$set("value",a.$eval(g.ngValue))}:function(a,
  15.142 +c,g){a.$watch(g.ngValue,function(a){g.$set("value",a,!1)})}}}},vd=S(function(a,c,d){c.addClass("ng-binding").data("$binding",d.ngBind);a.$watch(d.ngBind,function(a){c.text(a==p?"":a)})}),wd=["$interpolate",function(a){return function(c,d,e){c=a(d.attr(e.$attr.ngBindTemplate));d.addClass("ng-binding").data("$binding",c);e.$observe("ngBindTemplate",function(a){d.text(a)})}}],xd=[function(){return function(a,c,d){c.addClass("ng-binding").data("$binding",d.ngBindHtmlUnsafe);a.$watch(d.ngBindHtmlUnsafe,
  15.143 +function(a){c.html(a||"")})}}],yd=jb("",!0),zd=jb("Odd",0),Ad=jb("Even",1),Bd=S({compile:function(a,c){c.$set("ngCloak",p);a.removeClass("ng-cloak")}}),Cd=[function(){return{scope:!0,controller:"@"}}],Dd=["$sniffer",function(a){return{priority:1E3,compile:function(){a.csp=!0}}}],dc={};m("click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave".split(" "),function(a){var c=fa("ng-"+a);dc[c]=["$parse",function(d){return function(e,g,i){var f=d(i[c]);g.bind(E(a),function(a){e.$apply(function(){f(e,
  15.144 +{$event:a})})})}}]});var Ed=S(function(a,c,d){c.bind("submit",function(){a.$apply(d.ngSubmit)})}),Fd=["$http","$templateCache","$anchorScroll","$compile",function(a,c,d,e){return{restrict:"ECA",terminal:!0,compile:function(g,i){var f=i.ngInclude||i.src,h=i.onload||"",k=i.autoscroll;return function(g,i){var o=0,m,n=function(){m&&(m.$destroy(),m=null);i.html("")};g.$watch(f,function(f){var p=++o;f?a.get(f,{cache:c}).success(function(a){p===o&&(m&&m.$destroy(),m=g.$new(),i.html(a),e(i.contents())(m),
  15.145 +v(k)&&(!k||g.$eval(k))&&d(),m.$emit("$includeContentLoaded"),g.$eval(h))}).error(function(){p===o&&n()}):n()})}}}}],Gd=S({compile:function(){return{pre:function(a,c,d){a.$eval(d.ngInit)}}}}),Hd=S({terminal:!0,priority:1E3}),Id=["$locale","$interpolate",function(a,c){var d=/{}/g;return{restrict:"EA",link:function(e,g,i){var f=i.count,h=g.attr(i.$attr.when),k=i.offset||0,j=e.$eval(h),l={},o=c.startSymbol(),r=c.endSymbol();m(j,function(a,e){l[e]=c(a.replace(d,o+f+"-"+k+r))});e.$watch(function(){var c=
  15.146 +parseFloat(e.$eval(f));return isNaN(c)?"":(j[c]||(c=a.pluralCat(c-k)),l[c](e,g,!0))},function(a){g.text(a)})}}}],Jd=S({transclude:"element",priority:1E3,terminal:!0,compile:function(a,c,d){return function(a,c,i){var f=i.ngRepeat,i=f.match(/^\s*(.+)\s+in\s+(.*)\s*$/),h,k,j;if(!i)throw B("Expected ngRepeat in form of '_item_ in _collection_' but got '"+f+"'.");f=i[1];h=i[2];i=f.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/);if(!i)throw B("'item' in 'item in collection' should be identifier or (key, value) but got '"+
  15.147 +f+"'.");k=i[3]||i[1];j=i[2];var l=new eb;a.$watch(function(a){var e,f,i=a.$eval(h),m=gc(i,!0),p,u=new eb,C,A,v,t,y=c;if(J(i))v=i||[];else{v=[];for(C in i)i.hasOwnProperty(C)&&C.charAt(0)!="$"&&v.push(C);v.sort()}e=0;for(f=v.length;e<f;e++){C=i===v?e:v[e];A=i[C];if(t=l.shift(A)){p=t.scope;u.push(A,t);if(e!==t.index)t.index=e,y.after(t.element);y=t.element}else p=a.$new();p[k]=A;j&&(p[j]=C);p.$index=e;p.$first=e===0;p.$last=e===m-1;p.$middle=!(p.$first||p.$last);t||d(p,function(a){y.after(a);t={scope:p,
  15.148 +element:y=a,index:e};u.push(A,t)})}for(C in l)if(l.hasOwnProperty(C))for(v=l[C];v.length;)A=v.pop(),A.element.remove(),A.scope.$destroy();l=u})}}}),Kd=S(function(a,c,d){a.$watch(d.ngShow,function(a){c.css("display",Wa(a)?"":"none")})}),Ld=S(function(a,c,d){a.$watch(d.ngHide,function(a){c.css("display",Wa(a)?"none":"")})}),Md=S(function(a,c,d){a.$watch(d.ngStyle,function(a,d){d&&a!==d&&m(d,function(a,d){c.css(d,"")});a&&c.css(a)},!0)}),Nd=I({restrict:"EA",compile:function(a,c){var d=c.ngSwitch||c.on,
  15.149 +e={};a.data("ng-switch",e);return function(a,i){var f,h,k;a.$watch(d,function(d){h&&(k.$destroy(),h.remove(),h=k=null);if(f=e["!"+d]||e["?"])a.$eval(c.change),k=a.$new(),f(k,function(a){h=a;i.append(a)})})}}}),Od=S({transclude:"element",priority:500,compile:function(a,c,d){a=a.inheritedData("ng-switch");qa(a);a["!"+c.ngSwitchWhen]=d}}),Pd=S({transclude:"element",priority:500,compile:function(a,c,d){a=a.inheritedData("ng-switch");qa(a);a["?"]=d}}),Qd=S({controller:["$transclude","$element",function(a,
  15.150 +c){a(function(a){c.append(a)})}]}),Rd=["$http","$templateCache","$route","$anchorScroll","$compile","$controller",function(a,c,d,e,g,i){return{restrict:"ECA",terminal:!0,link:function(a,c,k){function j(){var j=d.current&&d.current.locals,k=j&&j.$template;if(k){c.html(k);l&&(l.$destroy(),l=null);var k=g(c.contents()),p=d.current;l=p.scope=a.$new();if(p.controller)j.$scope=l,j=i(p.controller,j),c.contents().data("$ngControllerController",j);k(l);l.$emit("$viewContentLoaded");l.$eval(m);e()}else c.html(""),
  15.151 +l&&(l.$destroy(),l=null)}var l,m=k.onload||"";a.$on("$routeChangeSuccess",j);j()}}}],Sd=["$templateCache",function(a){return{restrict:"E",terminal:!0,compile:function(c,d){d.type=="text/ng-template"&&a.put(d.id,c[0].text)}}}],Td=I({terminal:!0}),Ud=["$compile","$parse",function(a,c){var d=/^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w\d]*)|(?:\(\s*([\$\w][\$\w\d]*)\s*,\s*([\$\w][\$\w\d]*)\s*\)))\s+in\s+(.*)$/,e={$setViewValue:D};return{restrict:"E",require:["select",
  15.152 +"?ngModel"],controller:["$element","$scope","$attrs",function(a,c,d){var h=this,k={},j=e,l;h.databound=d.ngModel;h.init=function(a,c,d){j=a;l=d};h.addOption=function(c){k[c]=!0;j.$viewValue==c&&(a.val(c),l.parent()&&l.remove())};h.removeOption=function(a){this.hasOption(a)&&(delete k[a],j.$viewValue==a&&this.renderUnknownOption(a))};h.renderUnknownOption=function(c){c="? "+ga(c)+" ?";l.val(c);a.prepend(l);a.val(c);l.prop("selected",!0)};h.hasOption=function(a){return k.hasOwnProperty(a)};c.$on("$destroy",
  15.153 +function(){h.renderUnknownOption=D})}],link:function(e,i,f,h){function k(a,c,d,e){d.$render=function(){var a=d.$viewValue;e.hasOption(a)?(A.parent()&&A.remove(),c.val(a),a===""&&s.prop("selected",!0)):t(a)&&s?c.val(""):e.renderUnknownOption(a)};c.bind("change",function(){a.$apply(function(){A.parent()&&A.remove();d.$setViewValue(c.val())})})}function j(a,c,d){var e;d.$render=function(){var a=new Fa(d.$viewValue);m(c.children(),function(c){c.selected=v(a.get(c.value))})};a.$watch(function(){ha(e,d.$viewValue)||
  15.154 +(e=V(d.$viewValue),d.$render())});c.bind("change",function(){a.$apply(function(){var a=[];m(c.children(),function(c){c.selected&&a.push(c.value)});d.$setViewValue(a)})})}function l(e,f,g){function h(){var a={"":[]},c=[""],d,i,s,t,u;s=g.$modelValue;t=r(e)||[];var y=l?lb(t):t,A,w,x;w={};u=!1;var z,B;if(n)u=new Fa(s);else if(s===null||q)a[""].push({selected:s===null,id:"",label:""}),u=!0;for(x=0;A=y.length,x<A;x++){w[k]=t[l?w[l]=y[x]:x];d=m(e,w)||"";if(!(i=a[d]))i=a[d]=[],c.push(d);n?d=u.remove(o(e,
  15.155 +w))!=p:(d=s===o(e,w),u=u||d);z=j(e,w);z=z===p?"":z;i.push({id:l?y[x]:x,label:z,selected:d})}!n&&!u&&a[""].unshift({id:"?",label:"",selected:!0});w=0;for(y=c.length;w<y;w++){d=c[w];i=a[d];if(v.length<=w)s={element:C.clone().attr("label",d),label:i.label},t=[s],v.push(t),f.append(s.element);else if(t=v[w],s=t[0],s.label!=d)s.element.attr("label",s.label=d);z=null;x=0;for(A=i.length;x<A;x++)if(d=i[x],u=t[x+1]){z=u.element;if(u.label!==d.label)z.text(u.label=d.label);if(u.id!==d.id)z.val(u.id=d.id);if(u.element.selected!==
  15.156 +d.selected)z.prop("selected",u.selected=d.selected)}else d.id===""&&q?B=q:(B=D.clone()).val(d.id).attr("selected",d.selected).text(d.label),t.push({element:B,label:d.label,id:d.id,selected:d.selected}),z?z.after(B):s.element.append(B),z=B;for(x++;t.length>x;)t.pop().element.remove()}for(;v.length>w;)v.pop()[0].element.remove()}var i;if(!(i=w.match(d)))throw B("Expected ngOptions in form of '_select_ (as _label_)? for (_key_,)?_value_ in _collection_' but got '"+w+"'.");var j=c(i[2]||i[1]),k=i[4]||
  15.157 +i[6],l=i[5],m=c(i[3]||""),o=c(i[2]?i[1]:k),r=c(i[7]),v=[[{element:f,label:""}]];q&&(a(q)(e),q.removeClass("ng-scope"),q.remove());f.html("");f.bind("change",function(){e.$apply(function(){var a,c=r(e)||[],d={},h,i,j,m,q,s;if(n){i=[];m=0;for(s=v.length;m<s;m++){a=v[m];j=1;for(q=a.length;j<q;j++)if((h=a[j].element)[0].selected)h=h.val(),l&&(d[l]=h),d[k]=c[h],i.push(o(e,d))}}else h=f.val(),h=="?"?i=p:h==""?i=null:(d[k]=c[h],l&&(d[l]=h),i=o(e,d));g.$setViewValue(i)})});g.$render=h;e.$watch(h)}if(h[1]){for(var o=
  15.158 +h[0],r=h[1],n=f.multiple,w=f.ngOptions,q=!1,s,D=u(ca.createElement("option")),C=u(ca.createElement("optgroup")),A=D.clone(),h=0,x=i.children(),E=x.length;h<E;h++)if(x[h].value==""){s=q=x.eq(h);break}o.init(r,q,A);if(n&&(f.required||f.ngRequired)){var y=function(a){r.$setValidity("required",!f.required||a&&a.length);return a};r.$parsers.push(y);r.$formatters.unshift(y);f.$observe("required",function(){y(r.$viewValue)})}w?l(e,i,r):n?j(e,i,r):k(e,i,r,o)}}}}],Vd=["$interpolate",function(a){var c={addOption:D,
  15.159 +removeOption:D};return{restrict:"E",priority:100,compile:function(d,e){if(t(e.value)){var g=a(d.text(),!0);g||e.$set("value",d.text())}return function(a,d,e){var k=d.parent(),j=k.data("$selectController")||k.parent().data("$selectController");j&&j.databound?d.prop("selected",!1):j=c;g?a.$watch(g,function(a,c){e.$set("value",a);a!==c&&j.removeOption(c);j.addOption(a)}):j.addOption(e.value);d.bind("$destroy",function(){j.removeOption(e.value)})}}}}],Wd=I({restrict:"E",terminal:!0});(ja=U.jQuery)?(u=
  15.160 +ja,x(ja.fn,{scope:ua.scope,controller:ua.controller,injector:ua.injector,inheritedData:ua.inheritedData}),ab("remove",!0),ab("empty"),ab("html")):u=Q;Yb.element=u;(function(a){x(a,{bootstrap:pb,copy:V,extend:x,equals:ha,element:u,forEach:m,injector:qb,noop:D,bind:Va,toJson:da,fromJson:nb,identity:ma,isUndefined:t,isDefined:v,isString:F,isFunction:N,isObject:L,isNumber:wa,isElement:fc,isArray:J,version:id,isDate:na,lowercase:E,uppercase:la,callbacks:{counter:0}});ta=lc(U);try{ta("ngLocale")}catch(c){ta("ngLocale",
  15.161 +[]).provider("$locale",Zc)}ta("ng",["ngLocale"],["$provide",function(a){a.provider("$compile",Bb).directive({a:jd,input:bc,textarea:bc,form:kd,script:Sd,select:Ud,style:Wd,option:Vd,ngBind:vd,ngBindHtmlUnsafe:xd,ngBindTemplate:wd,ngClass:yd,ngClassEven:Ad,ngClassOdd:zd,ngCsp:Dd,ngCloak:Bd,ngController:Cd,ngForm:ld,ngHide:Ld,ngInclude:Fd,ngInit:Gd,ngNonBindable:Hd,ngPluralize:Id,ngRepeat:Jd,ngShow:Kd,ngSubmit:Ed,ngStyle:Md,ngSwitch:Nd,ngSwitchWhen:Od,ngSwitchDefault:Pd,ngOptions:Td,ngView:Rd,ngTransclude:Qd,
  15.162 +ngModel:qd,ngList:sd,ngChange:rd,required:cc,ngRequired:cc,ngValue:ud}).directive(kb).directive(dc);a.provider({$anchorScroll:uc,$browser:wc,$cacheFactory:xc,$controller:Bc,$document:Cc,$exceptionHandler:Dc,$filter:Pb,$interpolate:Ec,$http:Vc,$httpBackend:Wc,$location:Ic,$log:Jc,$parse:Nc,$route:Qc,$routeParams:Rc,$rootScope:Sc,$q:Oc,$sniffer:Tc,$templateCache:yc,$timeout:$c,$window:Uc})}])})(Yb);u(ca).ready(function(){jc(ca,pb)})})(window,document);angular.element(document).find("head").append('<style type="text/css">@charset "UTF-8";[ng\\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak{display:none;}ng\\:form{display:block;}</style>');
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/app.js	Wed Jan 23 14:49:52 2013 +0100
    16.3 @@ -0,0 +1,224 @@
    16.4 +// 'use strict';
    16.5 +
    16.6 +// Declare app level module which depends on filters, and services
    16.7 +angular.module('bck2brwsr', []).
    16.8 +  directive('uiCodemirror', ['$timeout', function($timeout) {
    16.9 +        'use strict';
   16.10 +
   16.11 +        var events = ["cursorActivity", "viewportChange", "gutterClick", "focus", "blur", "scroll", "update"];
   16.12 +        return {
   16.13 +            restrict: 'A',
   16.14 +            require: 'ngModel',
   16.15 +            link: function(scope, elm, attrs, ngModel) {
   16.16 +                var options, opts, onChange, deferCodeMirror, codeMirror, timeoutId, val;
   16.17 +
   16.18 +                if (elm[0].type !== 'textarea') {
   16.19 +                    throw new Error('uiCodemirror3 can only be applied to a textarea element');
   16.20 +                }
   16.21 +
   16.22 +                options = /* uiConfig.codemirror  || */ {};
   16.23 +                opts = angular.extend({}, options, scope.$eval(attrs.uiCodemirror));
   16.24 +
   16.25 +                onChange = function(instance, changeObj) {                    
   16.26 +                    val = instance.getValue();
   16.27 +                    $timeout.cancel(timeoutId);
   16.28 +                    timeoutId = $timeout(function() {
   16.29 +                        ngModel.$setViewValue(val);                        
   16.30 +                      }, 500);                    
   16.31 +                };
   16.32 +                
   16.33 +                deferCodeMirror = function() {
   16.34 +                    codeMirror = CodeMirror.fromTextArea(elm[0], opts);
   16.35 +                    elm[0].codeMirror = codeMirror;
   16.36 +                    // codeMirror.on("change", onChange(opts.onChange));
   16.37 +                    codeMirror.on("change", onChange);
   16.38 +
   16.39 +                    for (var i = 0, n = events.length, aEvent; i < n; ++i) {
   16.40 +                        aEvent = opts["on" + events[i].charAt(0).toUpperCase() + events[i].slice(1)];
   16.41 +                        if (aEvent === void 0)
   16.42 +                            continue;
   16.43 +                        if (typeof aEvent !== "function")
   16.44 +                            continue;
   16.45 +                                                
   16.46 +                        var bound = _.bind( aEvent, scope );
   16.47 +                        
   16.48 +                        codeMirror.on(events[i], bound);
   16.49 +                    }
   16.50 +
   16.51 +                    // CodeMirror expects a string, so make sure it gets one.
   16.52 +                    // This does not change the model.
   16.53 +                    ngModel.$formatters.push(function(value) {
   16.54 +                        if (angular.isUndefined(value) || value === null) {
   16.55 +                            return '';
   16.56 +                        }
   16.57 +                        else if (angular.isObject(value) || angular.isArray(value)) {
   16.58 +                            throw new Error('ui-codemirror cannot use an object or an array as a model');
   16.59 +                        }
   16.60 +                        return value;
   16.61 +                    });
   16.62 +
   16.63 +                    // Override the ngModelController $render method, which is what gets called when the model is updated.
   16.64 +                    // This takes care of the synchronizing the codeMirror element with the underlying model, in the case that it is changed by something else.
   16.65 +                    ngModel.$render = function() {
   16.66 +                        codeMirror.setValue(ngModel.$viewValue);
   16.67 +                    };
   16.68 +
   16.69 +                };
   16.70 +
   16.71 +                $timeout(deferCodeMirror);
   16.72 +
   16.73 +            }
   16.74 +        };
   16.75 +}]);
   16.76 +
   16.77 +function DevCtrl( $scope, $http ) {
   16.78 +    var templateHtml = 
   16.79 +"<html><body>\n" +
   16.80 +"  <input data-bind=\"value: value, valueUpdate: 'afterkeydown'\" \n" +
   16.81 +"     value=\"0\" type=\"number\">\n" +
   16.82 +"  </input>\n" +
   16.83 +"  * <span data-bind=\"text: value\">0</span> \n" +
   16.84 +"  = <span data-bind=\"text: powerValue\">0</span>\n" +
   16.85 +"  <br/>\n" +
   16.86 +"  <button id='dupl'>Duplicate!</button>\n" +
   16.87 +"  <button id=\"clear\">Clear!</button>" +
   16.88 +" <hr/>\n" +
   16.89 +"\n" +
   16.90 +"\n" +
   16.91 +"\n" +
   16.92 +"\n" +
   16.93 +"\n" +
   16.94 +"\n" +
   16.95 +"\n" +
   16.96 +"\n" +
   16.97 +"\n" +
   16.98 +"\n" +
   16.99 +"\n" +
  16.100 +"\n" +
  16.101 +"\n" +
  16.102 +"\n" +
  16.103 +"\n" +
  16.104 +"\n" +
  16.105 +"\n" +
  16.106 +"\n" +
  16.107 +"\n" +
  16.108 +"\n" +
  16.109 +" <script src=\"/bck2brwsr.js\"></script>\n" +
  16.110 +" <script type=\"text/javascript\">\n" +
  16.111 +"   function ldCls(res) {\n" +
  16.112 +"     var request = new XMLHttpRequest();\n" +
  16.113 +"     request.open('GET', '/classes/' + res, false);\n" +
  16.114 +"     request.send();\n" +
  16.115 +"     var arr = eval('(' + request.responseText + ')');\n" +
  16.116 +"     return arr;\n" +
  16.117 +"   }\n" +
  16.118 +"   var vm = new bck2brwsr(ldCls);\n" +
  16.119 +"   vm.loadClass('bck2brwsr.demo.YourFirstHTML5PageInRealLanguage');\n" +
  16.120 +" </script>\n" +
  16.121 +"</body></html>";
  16.122 +    var templateJava = 
  16.123 +"package bck2brwsr.demo;\n" +
  16.124 +"import org.apidesign.bck2brwsr.htmlpage.api.*;\n" +
  16.125 +"import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;\n" +
  16.126 +"\n" +
  16.127 +"@Page(xhtml=\"index.html\", className=\"Index\", properties={\n" +
  16.128 +"  @Property(name=\"value\", type=int.class)\n" +
  16.129 +"})\n" +
  16.130 +"class YourFirstHTML5PageInRealLanguage {\n" +
  16.131 +"  static { new Index().applyBindings(); }\n" +
  16.132 +"  @On(event=CLICK, id=\"dupl\") static void duplicateValue(Index m) {\n" +
  16.133 +"    m.setValue(m.getValue() * 2);\n" +
  16.134 +"  }\n" +
  16.135 +"  @On(event=CLICK, id=\"clear\") static void zeroTheValue(Index m) {\n" +
  16.136 +"     m.setValue(0);;\n" +
  16.137 +"  }\n" +
  16.138 +"  @ComputedProperty static int powerValue(int value) {\n" +
  16.139 +"    return value * value;\n" +
  16.140 +"  }\n" +
  16.141 +"}";
  16.142 +
  16.143 +    
  16.144 +    $scope.makeMarker = function( editor, line ) {
  16.145 +        var marker = document.createElement("div");
  16.146 +        marker.innerHTML = " ";
  16.147 +        marker.className = "issue";
  16.148 +        
  16.149 +        var info = editor.lineInfo(line);
  16.150 +        editor.setGutterMarker(line, "issues", info.markers ? null : marker);
  16.151 +        
  16.152 +        return marker;
  16.153 +    };
  16.154 +    
  16.155 +    
  16.156 +    // Returns a function, that, as long as it continues to be invoked, will not
  16.157 +    // be triggered. The function will be called after it stops being called for
  16.158 +    // N milliseconds. If `immediate` is passed, trigger the function on the
  16.159 +    // leading edge, instead of the trailing.
  16.160 +    $scope.debounce = function(func, wait, immediate) {
  16.161 +      var timeout, result;
  16.162 +      return function() {
  16.163 +        var context = this, args = arguments;
  16.164 +        var later = function() {
  16.165 +          timeout = null;
  16.166 +          if (!immediate) result = func.apply(context, args);
  16.167 +        };
  16.168 +        var callNow = immediate && !timeout;
  16.169 +        clearTimeout(timeout);
  16.170 +        timeout = setTimeout(later, wait);
  16.171 +        if (callNow) result = func.apply(context, args);
  16.172 +        return result;
  16.173 +      };
  16.174 +    };
  16.175 +    
  16.176 +    $scope.reload = function() {
  16.177 +        $scope.errors = null;
  16.178 +        var frame = document.getElementById("result");        
  16.179 +        frame.src = "result.html";
  16.180 +        frame.contentDocument.location.reload(true);
  16.181 +        frame.contentWindow.location.reload();
  16.182 +        document.getElementById("editorJava").codeMirror.clearGutter("issues");   
  16.183 +    };
  16.184 +    
  16.185 +    $scope.fail = function( data ) {
  16.186 +        $scope.errors = eval( data );
  16.187 +        var editor = document.getElementById("editorJava").codeMirror;   
  16.188 +        editor.clearGutter( "issues" );
  16.189 +        
  16.190 +        for( var i = 0; i < $scope.errors.length; i ++ ) {
  16.191 +            $scope.makeMarker( editor, $scope.errors[i].line - 1 );
  16.192 +        }
  16.193 +        
  16.194 +    };
  16.195 +    
  16.196 +    $scope.post = function() {
  16.197 +        return $http({url: ".",
  16.198 +            method: "POST",
  16.199 +            //headers: this.headers,
  16.200 +            data: { html : $scope.html, java : $scope.java} 
  16.201 +        }).success( $scope.reload ).error( $scope.fail );
  16.202 +    };
  16.203 +    
  16.204 +    $scope.errorClass = function( kind ) {
  16.205 +        switch( kind ) {
  16.206 +            case "ERROR" :
  16.207 +                return "error";
  16.208 +            default :         
  16.209 +                return "warning";   
  16.210 +        }
  16.211 +    };
  16.212 +    
  16.213 +    $scope.gotoError = function( line, col ) {
  16.214 +        var editor = document.getElementById("editorJava").codeMirror;   
  16.215 +        editor.setCursor({ line: line - 1, ch : col - 1 });
  16.216 +        editor.focus();
  16.217 +    };
  16.218 +    
  16.219 +    $scope.tab = "html";
  16.220 +    $scope.html= templateHtml;  
  16.221 +    $scope.java = templateJava;  
  16.222 +    
  16.223 +    $scope.$watch( "html", $scope.debounce( $scope.post, 2000 ) );
  16.224 +    $scope.$watch( "java", $scope.debounce( $scope.post, 2000 ) );
  16.225 +    $scope.post();
  16.226 +    
  16.227 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/codemirror.css	Wed Jan 23 14:49:52 2013 +0100
    17.3 @@ -0,0 +1,239 @@
    17.4 +/* BASICS */
    17.5 +
    17.6 +.CodeMirror {
    17.7 +  /* Set height, width, borders, and global font properties here */
    17.8 +  font-family: monospace;
    17.9 +  height: 300px;
   17.10 +}
   17.11 +.CodeMirror-scroll {
   17.12 +  /* Set scrolling behaviour here */
   17.13 +  overflow: auto;
   17.14 +}
   17.15 +
   17.16 +/* PADDING */
   17.17 +
   17.18 +.CodeMirror-lines {
   17.19 +  padding: 4px 0; /* Vertical padding around content */
   17.20 +}
   17.21 +.CodeMirror pre {
   17.22 +  padding: 0 4px; /* Horizontal padding of content */
   17.23 +}
   17.24 +
   17.25 +.CodeMirror-scrollbar-filler {
   17.26 +  background-color: white; /* The little square between H and V scrollbars */
   17.27 +}
   17.28 +
   17.29 +/* GUTTER */
   17.30 +
   17.31 +.CodeMirror-gutters {
   17.32 +  border-right: 1px solid #ddd;
   17.33 +  background-color: #f7f7f7;
   17.34 +}
   17.35 +.CodeMirror-linenumbers {}
   17.36 +.CodeMirror-linenumber {
   17.37 +  padding: 0 3px 0 5px;
   17.38 +  min-width: 20px;
   17.39 +  text-align: right;
   17.40 +  color: #999;
   17.41 +}
   17.42 +
   17.43 +/* CURSOR */
   17.44 +
   17.45 +.CodeMirror pre.CodeMirror-cursor {
   17.46 +  border-left: 1px solid black;
   17.47 +}
   17.48 +/* Shown when moving in bi-directional text */
   17.49 +.CodeMirror pre.CodeMirror-secondarycursor {
   17.50 +  border-left: 1px solid silver;
   17.51 +}
   17.52 +.cm-keymap-fat-cursor pre.CodeMirror-cursor {
   17.53 +  width: auto;
   17.54 +  border: 0;
   17.55 +  background: transparent;
   17.56 +  background: rgba(0, 200, 0, .4);
   17.57 +  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#6600c800, endColorstr=#4c00c800);
   17.58 +}
   17.59 +/* Kludge to turn off filter in ie9+, which also accepts rgba */
   17.60 +.cm-keymap-fat-cursor pre.CodeMirror-cursor:not(#nonsense_id) {
   17.61 +  filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
   17.62 +}
   17.63 +/* Can style cursor different in overwrite (non-insert) mode */
   17.64 +.CodeMirror pre.CodeMirror-cursor.CodeMirror-overwrite {}
   17.65 +
   17.66 +/* DEFAULT THEME */
   17.67 +
   17.68 +.cm-s-default .cm-keyword {color: #708;}
   17.69 +.cm-s-default .cm-atom {color: #219;}
   17.70 +.cm-s-default .cm-number {color: #164;}
   17.71 +.cm-s-default .cm-def {color: #00f;}
   17.72 +.cm-s-default .cm-variable {color: black;}
   17.73 +.cm-s-default .cm-variable-2 {color: #05a;}
   17.74 +.cm-s-default .cm-variable-3 {color: #085;}
   17.75 +.cm-s-default .cm-property {color: black;}
   17.76 +.cm-s-default .cm-operator {color: black;}
   17.77 +.cm-s-default .cm-comment {color: #a50;}
   17.78 +.cm-s-default .cm-string {color: #a11;}
   17.79 +.cm-s-default .cm-string-2 {color: #f50;}
   17.80 +.cm-s-default .cm-meta {color: #555;}
   17.81 +.cm-s-default .cm-error {color: #f00;}
   17.82 +.cm-s-default .cm-qualifier {color: #555;}
   17.83 +.cm-s-default .cm-builtin {color: #30a;}
   17.84 +.cm-s-default .cm-bracket {color: #997;}
   17.85 +.cm-s-default .cm-tag {color: #170;}
   17.86 +.cm-s-default .cm-attribute {color: #00c;}
   17.87 +.cm-s-default .cm-header {color: blue;}
   17.88 +.cm-s-default .cm-quote {color: #090;}
   17.89 +.cm-s-default .cm-hr {color: #999;}
   17.90 +.cm-s-default .cm-link {color: #00c;}
   17.91 +
   17.92 +.cm-negative {color: #d44;}
   17.93 +.cm-positive {color: #292;}
   17.94 +.cm-header, .cm-strong {font-weight: bold;}
   17.95 +.cm-em {font-style: italic;}
   17.96 +.cm-emstrong {font-style: italic; font-weight: bold;}
   17.97 +.cm-link {text-decoration: underline;}
   17.98 +
   17.99 +.cm-invalidchar {color: #f00;}
  17.100 +
  17.101 +div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
  17.102 +div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
  17.103 +
  17.104 +/* STOP */
  17.105 +
  17.106 +/* The rest of this file contains styles related to the mechanics of
  17.107 +   the editor. You probably shouldn't touch them. */
  17.108 +
  17.109 +.CodeMirror {
  17.110 +  line-height: 1;
  17.111 +  position: relative;
  17.112 +  overflow: hidden;
  17.113 +}
  17.114 +
  17.115 +.CodeMirror-scroll {
  17.116 +  /* 30px is the magic margin used to hide the element's real scrollbars */
  17.117 +  /* See overflow: hidden in .CodeMirror, and the paddings in .CodeMirror-sizer */
  17.118 +  margin-bottom: -30px; margin-right: -30px;
  17.119 +  padding-bottom: 30px; padding-right: 30px;
  17.120 +  height: 100%;
  17.121 +  outline: none; /* Prevent dragging from highlighting the element */
  17.122 +  position: relative;
  17.123 +}
  17.124 +.CodeMirror-sizer {
  17.125 +  position: relative;
  17.126 +}
  17.127 +
  17.128 +/* The fake, visible scrollbars. Used to force redraw during scrolling
  17.129 +   before actuall scrolling happens, thus preventing shaking and
  17.130 +   flickering artifacts. */
  17.131 +.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler {
  17.132 +  position: absolute;
  17.133 +  z-index: 6;
  17.134 +  display: none;
  17.135 +}
  17.136 +.CodeMirror-vscrollbar {
  17.137 +  right: 0; top: 0;
  17.138 +  overflow-x: hidden;
  17.139 +  overflow-y: scroll;
  17.140 +}
  17.141 +.CodeMirror-hscrollbar {
  17.142 +  bottom: 0; left: 0;
  17.143 +  overflow-y: hidden;
  17.144 +  overflow-x: scroll;
  17.145 +}
  17.146 +.CodeMirror-scrollbar-filler {
  17.147 +  right: 0; bottom: 0;
  17.148 +  z-index: 6;
  17.149 +}
  17.150 +
  17.151 +.CodeMirror-gutters {
  17.152 +  position: absolute; left: 0; top: 0;
  17.153 +  height: 100%;
  17.154 +  z-index: 3;
  17.155 +}
  17.156 +.CodeMirror-gutter {
  17.157 +  height: 100%;
  17.158 +  display: inline-block;
  17.159 +  /* Hack to make IE7 behave */
  17.160 +  *zoom:1;
  17.161 +  *display:inline;
  17.162 +}
  17.163 +.CodeMirror-gutter-elt {
  17.164 +  position: absolute;
  17.165 +  cursor: default;
  17.166 +  z-index: 4;
  17.167 +}
  17.168 +
  17.169 +.CodeMirror-lines {
  17.170 +  cursor: text;
  17.171 +}
  17.172 +.CodeMirror pre {
  17.173 +  /* Reset some styles that the rest of the page might have set */
  17.174 +  -moz-border-radius: 0; -webkit-border-radius: 0; -o-border-radius: 0; border-radius: 0;
  17.175 +  border-width: 0;
  17.176 +  background: transparent;
  17.177 +  font-family: inherit;
  17.178 +  font-size: inherit;
  17.179 +  margin: 0;
  17.180 +  white-space: pre;
  17.181 +  word-wrap: normal;
  17.182 +  line-height: inherit;
  17.183 +  color: inherit;
  17.184 +  z-index: 2;
  17.185 +  position: relative;
  17.186 +  overflow: visible;
  17.187 +}
  17.188 +.CodeMirror-wrap pre {
  17.189 +  word-wrap: break-word;
  17.190 +  white-space: pre-wrap;
  17.191 +  word-break: normal;
  17.192 +}
  17.193 +.CodeMirror-linebackground {
  17.194 +  position: absolute;
  17.195 +  left: 0; right: 0; top: 0; bottom: 0;
  17.196 +  z-index: 0;
  17.197 +}
  17.198 +
  17.199 +.CodeMirror-linewidget {
  17.200 +  position: relative;
  17.201 +  z-index: 2;
  17.202 +}
  17.203 +
  17.204 +.CodeMirror-wrap .CodeMirror-scroll {
  17.205 +  overflow-x: hidden;
  17.206 +}
  17.207 +
  17.208 +.CodeMirror-measure {
  17.209 +  position: absolute;
  17.210 +  width: 100%; height: 0px;
  17.211 +  overflow: hidden;
  17.212 +  visibility: hidden;
  17.213 +}
  17.214 +.CodeMirror-measure pre { position: static; }
  17.215 +
  17.216 +.CodeMirror pre.CodeMirror-cursor {
  17.217 +  position: absolute;
  17.218 +  visibility: hidden;
  17.219 +  border-right: none;
  17.220 +  width: 0;
  17.221 +}
  17.222 +.CodeMirror-focused pre.CodeMirror-cursor {
  17.223 +  visibility: visible;
  17.224 +}
  17.225 +
  17.226 +.CodeMirror-selected { background: #d9d9d9; }
  17.227 +.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
  17.228 +
  17.229 +.CodeMirror-searching {
  17.230 +  background: #ffa;
  17.231 +  background: rgba(255, 255, 0, .4);
  17.232 +}
  17.233 +
  17.234 +/* IE7 hack to prevent it from returning funny offsetTops on the spans */
  17.235 +.CodeMirror span { *vertical-align: text-bottom; }
  17.236 +
  17.237 +@media print {
  17.238 +  /* Hide the cursor when printing */
  17.239 +  .CodeMirror pre.CodeMirror-cursor {
  17.240 +    visibility: hidden;
  17.241 +  }
  17.242 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/codemirror.js	Wed Jan 23 14:49:52 2013 +0100
    18.3 @@ -0,0 +1,4553 @@
    18.4 +// CodeMirror version 3.0
    18.5 +//
    18.6 +// CodeMirror is the only global var we claim
    18.7 +window.CodeMirror = (function() {
    18.8 +  "use strict";
    18.9 +
   18.10 +  // BROWSER SNIFFING
   18.11 +
   18.12 +  // Crude, but necessary to handle a number of hard-to-feature-detect
   18.13 +  // bugs and behavior differences.
   18.14 +  var gecko = /gecko\/\d/i.test(navigator.userAgent);
   18.15 +  var ie = /MSIE \d/.test(navigator.userAgent);
   18.16 +  var ie_lt8 = /MSIE [1-7]\b/.test(navigator.userAgent);
   18.17 +  var ie_lt9 = /MSIE [1-8]\b/.test(navigator.userAgent);
   18.18 +  var webkit = /WebKit\//.test(navigator.userAgent);
   18.19 +  var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(navigator.userAgent);
   18.20 +  var chrome = /Chrome\//.test(navigator.userAgent);
   18.21 +  var opera = /Opera\//.test(navigator.userAgent);
   18.22 +  var safari = /Apple Computer/.test(navigator.vendor);
   18.23 +  var khtml = /KHTML\//.test(navigator.userAgent);
   18.24 +  var mac_geLion = /Mac OS X 1\d\D([7-9]|\d\d)\D/.test(navigator.userAgent);
   18.25 +  var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent);
   18.26 +  var phantom = /PhantomJS/.test(navigator.userAgent);
   18.27 +
   18.28 +  var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
   18.29 +  // This is woefully incomplete. Suggestions for alternative methods welcome.
   18.30 +  var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent);
   18.31 +  var mac = ios || /Mac/.test(navigator.platform);
   18.32 +
   18.33 +  // Optimize some code when these features are not used
   18.34 +  var sawReadOnlySpans = false, sawCollapsedSpans = false;
   18.35 +
   18.36 +  // CONSTRUCTOR
   18.37 +
   18.38 +  function CodeMirror(place, options) {
   18.39 +    if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
   18.40 +    
   18.41 +    this.options = options = options || {};
   18.42 +    // Determine effective options based on given values and defaults.
   18.43 +    for (var opt in defaults) if (!options.hasOwnProperty(opt) && defaults.hasOwnProperty(opt))
   18.44 +      options[opt] = defaults[opt];
   18.45 +    setGuttersForLineNumbers(options);
   18.46 +
   18.47 +    var display = this.display = makeDisplay(place);
   18.48 +    display.wrapper.CodeMirror = this;
   18.49 +    updateGutters(this);
   18.50 +    if (options.autofocus && !mobile) focusInput(this);
   18.51 +
   18.52 +    this.view = makeView(new BranchChunk([new LeafChunk([makeLine("", null, textHeight(display))])]));
   18.53 +    this.nextOpId = 0;
   18.54 +    loadMode(this);
   18.55 +    themeChanged(this);
   18.56 +    if (options.lineWrapping)
   18.57 +      this.display.wrapper.className += " CodeMirror-wrap";
   18.58 +
   18.59 +    // Initialize the content.
   18.60 +    this.setValue(options.value || "");
   18.61 +    // Override magic textarea content restore that IE sometimes does
   18.62 +    // on our hidden textarea on reload
   18.63 +    if (ie) setTimeout(bind(resetInput, this, true), 20);
   18.64 +    this.view.history = makeHistory();
   18.65 +
   18.66 +    registerEventHandlers(this);
   18.67 +    // IE throws unspecified error in certain cases, when
   18.68 +    // trying to access activeElement before onload
   18.69 +    var hasFocus; try { hasFocus = (document.activeElement == display.input); } catch(e) { }
   18.70 +    if (hasFocus || (options.autofocus && !mobile)) setTimeout(bind(onFocus, this), 20);
   18.71 +    else onBlur(this);
   18.72 +
   18.73 +    operation(this, function() {
   18.74 +      for (var opt in optionHandlers)
   18.75 +        if (optionHandlers.propertyIsEnumerable(opt))
   18.76 +          optionHandlers[opt](this, options[opt], Init);
   18.77 +      for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
   18.78 +    })();
   18.79 +  }
   18.80 +
   18.81 +  // DISPLAY CONSTRUCTOR
   18.82 +
   18.83 +  function makeDisplay(place) {
   18.84 +    var d = {};
   18.85 +    var input = d.input = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none;");
   18.86 +    input.setAttribute("wrap", "off"); input.setAttribute("autocorrect", "off"); input.setAttribute("autocapitalize", "off");
   18.87 +    // Wraps and hides input textarea
   18.88 +    d.inputDiv = elt("div", [input], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
   18.89 +    // The actual fake scrollbars.
   18.90 +    d.scrollbarH = elt("div", [elt("div", null, null, "height: 1px")], "CodeMirror-hscrollbar");
   18.91 +    d.scrollbarV = elt("div", [elt("div", null, null, "width: 1px")], "CodeMirror-vscrollbar");
   18.92 +    d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
   18.93 +    // DIVs containing the selection and the actual code
   18.94 +    d.lineDiv = elt("div");
   18.95 +    d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
   18.96 +    // Blinky cursor, and element used to ensure cursor fits at the end of a line
   18.97 +    d.cursor = elt("pre", "\u00a0", "CodeMirror-cursor");
   18.98 +    // Secondary cursor, shown when on a 'jump' in bi-directional text
   18.99 +    d.otherCursor = elt("pre", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor");
  18.100 +    // Used to measure text size
  18.101 +    d.measure = elt("div", null, "CodeMirror-measure");
  18.102 +    // Wraps everything that needs to exist inside the vertically-padded coordinate system
  18.103 +    d.lineSpace = elt("div", [d.measure, d.selectionDiv, d.lineDiv, d.cursor, d.otherCursor],
  18.104 +                         null, "position: relative; outline: none");
  18.105 +    // Moved around its parent to cover visible view
  18.106 +    d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative");
  18.107 +    // Set to the height of the text, causes scrolling
  18.108 +    d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
  18.109 +    // D is needed because behavior of elts with overflow: auto and padding is inconsistent across browsers
  18.110 +    d.heightForcer = elt("div", "\u00a0", null, "position: absolute; height: " + scrollerCutOff + "px");
  18.111 +    // Will contain the gutters, if any
  18.112 +    d.gutters = elt("div", null, "CodeMirror-gutters");
  18.113 +    d.lineGutter = null;
  18.114 +    // Helper element to properly size the gutter backgrounds
  18.115 +    var scrollerInner = elt("div", [d.sizer, d.heightForcer, d.gutters], null, "position: relative; min-height: 100%");
  18.116 +    // Provides scrolling
  18.117 +    d.scroller = elt("div", [scrollerInner], "CodeMirror-scroll");
  18.118 +    d.scroller.setAttribute("tabIndex", "-1");
  18.119 +    // The element in which the editor lives.
  18.120 +    d.wrapper = elt("div", [d.inputDiv, d.scrollbarH, d.scrollbarV,
  18.121 +                            d.scrollbarFiller, d.scroller], "CodeMirror");
  18.122 +    // Work around IE7 z-index bug
  18.123 +    if (ie_lt8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
  18.124 +    if (place.appendChild) place.appendChild(d.wrapper); else place(d.wrapper);
  18.125 +
  18.126 +    // Needed to hide big blue blinking cursor on Mobile Safari
  18.127 +    if (ios) input.style.width = "0px";
  18.128 +    if (!webkit) d.scroller.draggable = true;
  18.129 +    // Needed to handle Tab key in KHTML
  18.130 +    if (khtml) { d.inputDiv.style.height = "1px"; d.inputDiv.style.position = "absolute"; }
  18.131 +    // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
  18.132 +    else if (ie_lt8) d.scrollbarH.style.minWidth = d.scrollbarV.style.minWidth = "18px";
  18.133 +
  18.134 +    // Current visible range (may be bigger than the view window).
  18.135 +    d.viewOffset = d.showingFrom = d.showingTo = d.lastSizeC = 0;
  18.136 +
  18.137 +    // Used to only resize the line number gutter when necessary (when
  18.138 +    // the amount of lines crosses a boundary that makes its width change)
  18.139 +    d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
  18.140 +    // See readInput and resetInput
  18.141 +    d.prevInput = "";
  18.142 +    // Set to true when a non-horizontal-scrolling widget is added. As
  18.143 +    // an optimization, widget aligning is skipped when d is false.
  18.144 +    d.alignWidgets = false;
  18.145 +    // Flag that indicates whether we currently expect input to appear
  18.146 +    // (after some event like 'keypress' or 'input') and are polling
  18.147 +    // intensively.
  18.148 +    d.pollingFast = false;
  18.149 +    // Self-resetting timeout for the poller
  18.150 +    d.poll = new Delayed();
  18.151 +    // True when a drag from the editor is active
  18.152 +    d.draggingText = false;
  18.153 +
  18.154 +    d.cachedCharWidth = d.cachedTextHeight = null;
  18.155 +    d.measureLineCache = [];
  18.156 +    d.measureLineCachePos = 0;
  18.157 +
  18.158 +    // Tracks when resetInput has punted to just putting a short
  18.159 +    // string instead of the (large) selection.
  18.160 +    d.inaccurateSelection = false;
  18.161 +
  18.162 +    // Used to adjust overwrite behaviour when a paste has been
  18.163 +    // detected
  18.164 +    d.pasteIncoming = false;
  18.165 +
  18.166 +    return d;
  18.167 +  }
  18.168 +
  18.169 +  // VIEW CONSTRUCTOR
  18.170 +
  18.171 +  function makeView(doc) {
  18.172 +    var selPos = {line: 0, ch: 0};
  18.173 +    return {
  18.174 +      doc: doc,
  18.175 +      // frontier is the point up to which the content has been parsed,
  18.176 +      frontier: 0, highlight: new Delayed(),
  18.177 +      sel: {from: selPos, to: selPos, head: selPos, anchor: selPos, shift: false, extend: false},
  18.178 +      scrollTop: 0, scrollLeft: 0,
  18.179 +      overwrite: false, focused: false,
  18.180 +      // Tracks the maximum line length so that
  18.181 +      // the horizontal scrollbar can be kept
  18.182 +      // static when scrolling.
  18.183 +      maxLine: getLine(doc, 0),
  18.184 +      maxLineLength: 0,
  18.185 +      maxLineChanged: false,
  18.186 +      suppressEdits: false,
  18.187 +      goalColumn: null,
  18.188 +      cantEdit: false,
  18.189 +      keyMaps: []
  18.190 +    };
  18.191 +  }
  18.192 +
  18.193 +  // STATE UPDATES
  18.194 +
  18.195 +  // Used to get the editor into a consistent state again when options change.
  18.196 +
  18.197 +  function loadMode(cm) {
  18.198 +    var doc = cm.view.doc;
  18.199 +    cm.view.mode = CodeMirror.getMode(cm.options, cm.options.mode);
  18.200 +    doc.iter(0, doc.size, function(line) { line.stateAfter = null; });
  18.201 +    cm.view.frontier = 0;
  18.202 +    startWorker(cm, 100);
  18.203 +  }
  18.204 +
  18.205 +  function wrappingChanged(cm) {
  18.206 +    var doc = cm.view.doc, th = textHeight(cm.display);
  18.207 +    if (cm.options.lineWrapping) {
  18.208 +      cm.display.wrapper.className += " CodeMirror-wrap";
  18.209 +      var perLine = cm.display.scroller.clientWidth / charWidth(cm.display) - 3;
  18.210 +      doc.iter(0, doc.size, function(line) {
  18.211 +        if (line.height == 0) return;
  18.212 +        var guess = Math.ceil(line.text.length / perLine) || 1;
  18.213 +        if (guess != 1) updateLineHeight(line, guess * th);
  18.214 +      });
  18.215 +      cm.display.sizer.style.minWidth = "";
  18.216 +    } else {
  18.217 +      cm.display.wrapper.className = cm.display.wrapper.className.replace(" CodeMirror-wrap", "");
  18.218 +      computeMaxLength(cm.view);
  18.219 +      doc.iter(0, doc.size, function(line) {
  18.220 +        if (line.height != 0) updateLineHeight(line, th);
  18.221 +      });
  18.222 +    }
  18.223 +    regChange(cm, 0, doc.size);
  18.224 +    clearCaches(cm);
  18.225 +    setTimeout(function(){updateScrollbars(cm.display, cm.view.doc.height);}, 100);
  18.226 +  }
  18.227 +
  18.228 +  function keyMapChanged(cm) {
  18.229 +    var style = keyMap[cm.options.keyMap].style;
  18.230 +    cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-keymap-\S+/g, "") +
  18.231 +      (style ? " cm-keymap-" + style : "");
  18.232 +  }
  18.233 +
  18.234 +  function themeChanged(cm) {
  18.235 +    cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
  18.236 +      cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
  18.237 +    clearCaches(cm);
  18.238 +  }
  18.239 +
  18.240 +  function guttersChanged(cm) {
  18.241 +    updateGutters(cm);
  18.242 +    updateDisplay(cm, true);
  18.243 +  }
  18.244 +
  18.245 +  function updateGutters(cm) {
  18.246 +    var gutters = cm.display.gutters, specs = cm.options.gutters;
  18.247 +    removeChildren(gutters);
  18.248 +    for (var i = 0; i < specs.length; ++i) {
  18.249 +      var gutterClass = specs[i];
  18.250 +      var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
  18.251 +      if (gutterClass == "CodeMirror-linenumbers") {
  18.252 +        cm.display.lineGutter = gElt;
  18.253 +        gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
  18.254 +      }
  18.255 +    }
  18.256 +    gutters.style.display = i ? "" : "none";
  18.257 +  }
  18.258 +
  18.259 +  function lineLength(doc, line) {
  18.260 +    if (line.height == 0) return 0;
  18.261 +    var len = line.text.length, merged, cur = line;
  18.262 +    while (merged = collapsedSpanAtStart(cur)) {
  18.263 +      var found = merged.find();
  18.264 +      cur = getLine(doc, found.from.line);
  18.265 +      len += found.from.ch - found.to.ch;
  18.266 +    }
  18.267 +    cur = line;
  18.268 +    while (merged = collapsedSpanAtEnd(cur)) {
  18.269 +      var found = merged.find();
  18.270 +      len -= cur.text.length - found.from.ch;
  18.271 +      cur = getLine(doc, found.to.line);
  18.272 +      len += cur.text.length - found.to.ch;
  18.273 +    }
  18.274 +    return len;
  18.275 +  }
  18.276 +
  18.277 +  function computeMaxLength(view) {
  18.278 +    view.maxLine = getLine(view.doc, 0);
  18.279 +    view.maxLineLength = lineLength(view.doc, view.maxLine);
  18.280 +    view.maxLineChanged = true;
  18.281 +    view.doc.iter(1, view.doc.size, function(line) {
  18.282 +      var len = lineLength(view.doc, line);
  18.283 +      if (len > view.maxLineLength) {
  18.284 +        view.maxLineLength = len;
  18.285 +        view.maxLine = line;
  18.286 +      }
  18.287 +    });
  18.288 +  }
  18.289 +
  18.290 +  // Make sure the gutters options contains the element
  18.291 +  // "CodeMirror-linenumbers" when the lineNumbers option is true.
  18.292 +  function setGuttersForLineNumbers(options) {
  18.293 +    var found = false;
  18.294 +    for (var i = 0; i < options.gutters.length; ++i) {
  18.295 +      if (options.gutters[i] == "CodeMirror-linenumbers") {
  18.296 +        if (options.lineNumbers) found = true;
  18.297 +        else options.gutters.splice(i--, 1);
  18.298 +      }
  18.299 +    }
  18.300 +    if (!found && options.lineNumbers)
  18.301 +      options.gutters.push("CodeMirror-linenumbers");
  18.302 +  }
  18.303 +
  18.304 +  // SCROLLBARS
  18.305 +
  18.306 +  // Re-synchronize the fake scrollbars with the actual size of the
  18.307 +  // content. Optionally force a scrollTop.
  18.308 +  function updateScrollbars(d /* display */, docHeight) {
  18.309 +    var totalHeight = docHeight + 2 * paddingTop(d);
  18.310 +    d.sizer.style.minHeight = d.heightForcer.style.top = totalHeight + "px";
  18.311 +    var scrollHeight = Math.max(totalHeight, d.scroller.scrollHeight);
  18.312 +    var needsH = d.scroller.scrollWidth > d.scroller.clientWidth;
  18.313 +    var needsV = scrollHeight > d.scroller.clientHeight;
  18.314 +    if (needsV) {
  18.315 +      d.scrollbarV.style.display = "block";
  18.316 +      d.scrollbarV.style.bottom = needsH ? scrollbarWidth(d.measure) + "px" : "0";
  18.317 +      d.scrollbarV.firstChild.style.height = 
  18.318 +        (scrollHeight - d.scroller.clientHeight + d.scrollbarV.clientHeight) + "px";
  18.319 +    } else d.scrollbarV.style.display = "";
  18.320 +    if (needsH) {
  18.321 +      d.scrollbarH.style.display = "block";
  18.322 +      d.scrollbarH.style.right = needsV ? scrollbarWidth(d.measure) + "px" : "0";
  18.323 +      d.scrollbarH.firstChild.style.width =
  18.324 +        (d.scroller.scrollWidth - d.scroller.clientWidth + d.scrollbarH.clientWidth) + "px";
  18.325 +    } else d.scrollbarH.style.display = "";
  18.326 +    if (needsH && needsV) {
  18.327 +      d.scrollbarFiller.style.display = "block";
  18.328 +      d.scrollbarFiller.style.height = d.scrollbarFiller.style.width = scrollbarWidth(d.measure) + "px";
  18.329 +    } else d.scrollbarFiller.style.display = "";
  18.330 +
  18.331 +    if (mac_geLion && scrollbarWidth(d.measure) === 0)
  18.332 +      d.scrollbarV.style.minWidth = d.scrollbarH.style.minHeight = mac_geMountainLion ? "18px" : "12px";
  18.333 +  }
  18.334 +
  18.335 +  function visibleLines(display, doc, viewPort) {
  18.336 +    var top = display.scroller.scrollTop, height = display.wrapper.clientHeight;
  18.337 +    if (typeof viewPort == "number") top = viewPort;
  18.338 +    else if (viewPort) {top = viewPort.top; height = viewPort.bottom - viewPort.top;}
  18.339 +    top = Math.floor(top - paddingTop(display));
  18.340 +    var bottom = Math.ceil(top + height);
  18.341 +    return {from: lineAtHeight(doc, top), to: lineAtHeight(doc, bottom)};
  18.342 +  }
  18.343 +
  18.344 +  // LINE NUMBERS
  18.345 +
  18.346 +  function alignHorizontally(cm) {
  18.347 +    var display = cm.display;
  18.348 +    if (!display.alignWidgets && !display.gutters.firstChild) return;
  18.349 +    var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.view.scrollLeft;
  18.350 +    var gutterW = display.gutters.offsetWidth, l = comp + "px";
  18.351 +    for (var n = display.lineDiv.firstChild; n; n = n.nextSibling) if (n.alignable) {
  18.352 +      for (var i = 0, a = n.alignable; i < a.length; ++i) a[i].style.left = l;
  18.353 +    }
  18.354 +    display.gutters.style.left = (comp + gutterW) + "px";
  18.355 +  }
  18.356 +
  18.357 +  function maybeUpdateLineNumberWidth(cm) {
  18.358 +    if (!cm.options.lineNumbers) return false;
  18.359 +    var doc = cm.view.doc, last = lineNumberFor(cm.options, doc.size - 1), display = cm.display;
  18.360 +    if (last.length != display.lineNumChars) {
  18.361 +      var test = display.measure.appendChild(elt("div", [elt("div", last)],
  18.362 +                                                 "CodeMirror-linenumber CodeMirror-gutter-elt"));
  18.363 +      var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
  18.364 +      display.lineGutter.style.width = "";
  18.365 +      display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding);
  18.366 +      display.lineNumWidth = display.lineNumInnerWidth + padding;
  18.367 +      display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
  18.368 +      display.lineGutter.style.width = display.lineNumWidth + "px";
  18.369 +      return true;
  18.370 +    }
  18.371 +    return false;
  18.372 +  }
  18.373 +
  18.374 +  function lineNumberFor(options, i) {
  18.375 +    return String(options.lineNumberFormatter(i + options.firstLineNumber));
  18.376 +  }
  18.377 +  function compensateForHScroll(display) {
  18.378 +    return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left;
  18.379 +  }
  18.380 +
  18.381 +  // DISPLAY DRAWING
  18.382 +
  18.383 +  function updateDisplay(cm, changes, viewPort) {
  18.384 +    var oldFrom = cm.display.showingFrom, oldTo = cm.display.showingTo;
  18.385 +    var updated = updateDisplayInner(cm, changes, viewPort);
  18.386 +    if (updated) {
  18.387 +      signalLater(cm, cm, "update", cm);
  18.388 +      if (cm.display.showingFrom != oldFrom || cm.display.showingTo != oldTo)
  18.389 +        signalLater(cm, cm, "viewportChange", cm, cm.display.showingFrom, cm.display.showingTo);
  18.390 +    }
  18.391 +    updateSelection(cm);
  18.392 +    updateScrollbars(cm.display, cm.view.doc.height);
  18.393 +
  18.394 +    return updated;
  18.395 +  }
  18.396 +
  18.397 +  // Uses a set of changes plus the current scroll position to
  18.398 +  // determine which DOM updates have to be made, and makes the
  18.399 +  // updates.
  18.400 +  function updateDisplayInner(cm, changes, viewPort) {
  18.401 +    var display = cm.display, doc = cm.view.doc;
  18.402 +    if (!display.wrapper.clientWidth) {
  18.403 +      display.showingFrom = display.showingTo = display.viewOffset = 0;
  18.404 +      return;
  18.405 +    }
  18.406 +
  18.407 +    // Compute the new visible window
  18.408 +    // If scrollTop is specified, use that to determine which lines
  18.409 +    // to render instead of the current scrollbar position.
  18.410 +    var visible = visibleLines(display, doc, viewPort);
  18.411 +    // Bail out if the visible area is already rendered and nothing changed.
  18.412 +    if (changes !== true && changes.length == 0 &&
  18.413 +        visible.from > display.showingFrom && visible.to < display.showingTo)
  18.414 +      return;
  18.415 +
  18.416 +    if (changes && maybeUpdateLineNumberWidth(cm))
  18.417 +      changes = true;
  18.418 +    display.sizer.style.marginLeft = display.scrollbarH.style.left = display.gutters.offsetWidth + "px";
  18.419 +
  18.420 +    // When merged lines are present, the line that needs to be
  18.421 +    // redrawn might not be the one that was changed.
  18.422 +    if (changes !== true && sawCollapsedSpans)
  18.423 +      for (var i = 0; i < changes.length; ++i) {
  18.424 +        var ch = changes[i], merged;
  18.425 +        while (merged = collapsedSpanAtStart(getLine(doc, ch.from))) {
  18.426 +          var from = merged.find().from.line;
  18.427 +          if (ch.diff) ch.diff -= ch.from - from;
  18.428 +          ch.from = from;
  18.429 +        }
  18.430 +      }
  18.431 +
  18.432 +    // Used to determine which lines need their line numbers updated
  18.433 +    var positionsChangedFrom = changes === true ? 0 : Infinity;
  18.434 +    if (cm.options.lineNumbers && changes && changes !== true)
  18.435 +      for (var i = 0; i < changes.length; ++i)
  18.436 +        if (changes[i].diff) { positionsChangedFrom = changes[i].from; break; }
  18.437 +
  18.438 +    var from = Math.max(visible.from - cm.options.viewportMargin, 0);
  18.439 +    var to = Math.min(doc.size, visible.to + cm.options.viewportMargin);
  18.440 +    if (display.showingFrom < from && from - display.showingFrom < 20) from = display.showingFrom;
  18.441 +    if (display.showingTo > to && display.showingTo - to < 20) to = Math.min(doc.size, display.showingTo);
  18.442 +    if (sawCollapsedSpans) {
  18.443 +      from = lineNo(visualLine(doc, getLine(doc, from)));
  18.444 +      while (to < doc.size && lineIsHidden(getLine(doc, to))) ++to;
  18.445 +    }
  18.446 +
  18.447 +    // Create a range of theoretically intact lines, and punch holes
  18.448 +    // in that using the change info.
  18.449 +    var intact = changes === true ? [] :
  18.450 +      computeIntact([{from: display.showingFrom, to: display.showingTo}], changes);
  18.451 +    // Clip off the parts that won't be visible
  18.452 +    var intactLines = 0;
  18.453 +    for (var i = 0; i < intact.length; ++i) {
  18.454 +      var range = intact[i];
  18.455 +      if (range.from < from) range.from = from;
  18.456 +      if (range.to > to) range.to = to;
  18.457 +      if (range.from >= range.to) intact.splice(i--, 1);
  18.458 +      else intactLines += range.to - range.from;
  18.459 +    }
  18.460 +    if (intactLines == to - from && from == display.showingFrom && to == display.showingTo)
  18.461 +      return;
  18.462 +    intact.sort(function(a, b) {return a.from - b.from;});
  18.463 +
  18.464 +    if (intactLines < (to - from) * .7) display.lineDiv.style.display = "none";
  18.465 +    patchDisplay(cm, from, to, intact, positionsChangedFrom);
  18.466 +    display.lineDiv.style.display = "";
  18.467 +
  18.468 +    var different = from != display.showingFrom || to != display.showingTo ||
  18.469 +      display.lastSizeC != display.wrapper.clientHeight;
  18.470 +    // This is just a bogus formula that detects when the editor is
  18.471 +    // resized or the font size changes.
  18.472 +    if (different) display.lastSizeC = display.wrapper.clientHeight;
  18.473 +    display.showingFrom = from; display.showingTo = to;
  18.474 +    startWorker(cm, 100);
  18.475 +
  18.476 +    var prevBottom = display.lineDiv.offsetTop;
  18.477 +    for (var node = display.lineDiv.firstChild, height; node; node = node.nextSibling) if (node.lineObj) {
  18.478 +      if (ie_lt8) {
  18.479 +        var bot = node.offsetTop + node.offsetHeight;
  18.480 +        height = bot - prevBottom;
  18.481 +        prevBottom = bot;
  18.482 +      } else {
  18.483 +        var box = node.getBoundingClientRect();
  18.484 +        height = box.bottom - box.top;
  18.485 +      }
  18.486 +      var diff = node.lineObj.height - height;
  18.487 +      if (height < 2) height = textHeight(display);
  18.488 +      if (diff > .001 || diff < -.001)
  18.489 +        updateLineHeight(node.lineObj, height);
  18.490 +    }
  18.491 +    display.viewOffset = heightAtLine(cm, getLine(doc, from));
  18.492 +    // Position the mover div to align with the current virtual scroll position
  18.493 +    display.mover.style.top = display.viewOffset + "px";
  18.494 +    return true;
  18.495 +  }
  18.496 +
  18.497 +  function computeIntact(intact, changes) {
  18.498 +    for (var i = 0, l = changes.length || 0; i < l; ++i) {
  18.499 +      var change = changes[i], intact2 = [], diff = change.diff || 0;
  18.500 +      for (var j = 0, l2 = intact.length; j < l2; ++j) {
  18.501 +        var range = intact[j];
  18.502 +        if (change.to <= range.from && change.diff) {
  18.503 +          intact2.push({from: range.from + diff, to: range.to + diff});
  18.504 +        } else if (change.to <= range.from || change.from >= range.to) {
  18.505 +          intact2.push(range);
  18.506 +        } else {
  18.507 +          if (change.from > range.from)
  18.508 +            intact2.push({from: range.from, to: change.from});
  18.509 +          if (change.to < range.to)
  18.510 +            intact2.push({from: change.to + diff, to: range.to + diff});
  18.511 +        }
  18.512 +      }
  18.513 +      intact = intact2;
  18.514 +    }
  18.515 +    return intact;
  18.516 +  }
  18.517 +
  18.518 +  function getDimensions(cm) {
  18.519 +    var d = cm.display, left = {}, width = {};
  18.520 +    for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
  18.521 +      left[cm.options.gutters[i]] = n.offsetLeft;
  18.522 +      width[cm.options.gutters[i]] = n.offsetWidth;
  18.523 +    }
  18.524 +    return {fixedPos: compensateForHScroll(d),
  18.525 +            gutterTotalWidth: d.gutters.offsetWidth,
  18.526 +            gutterLeft: left,
  18.527 +            gutterWidth: width,
  18.528 +            wrapperWidth: d.wrapper.clientWidth};
  18.529 +  }
  18.530 +
  18.531 +  function patchDisplay(cm, from, to, intact, updateNumbersFrom) {
  18.532 +    var dims = getDimensions(cm);
  18.533 +    var display = cm.display, lineNumbers = cm.options.lineNumbers;
  18.534 +    // IE does bad things to nodes when .innerHTML = "" is used on a parent
  18.535 +    // we still need widgets and markers intact to add back to the new content later
  18.536 +    if (!intact.length && !ie && (!webkit || !cm.display.currentWheelTarget))
  18.537 +      removeChildren(display.lineDiv);
  18.538 +    var container = display.lineDiv, cur = container.firstChild;
  18.539 +
  18.540 +    function rm(node) {
  18.541 +      var next = node.nextSibling;
  18.542 +      if (webkit && mac && cm.display.currentWheelTarget == node) {
  18.543 +        node.style.display = "none";
  18.544 +        node.lineObj = null;
  18.545 +      } else {
  18.546 +        container.removeChild(node);
  18.547 +      }
  18.548 +      return next;
  18.549 +    }
  18.550 +
  18.551 +    var nextIntact = intact.shift(), lineNo = from;
  18.552 +    cm.view.doc.iter(from, to, function(line) {
  18.553 +      if (nextIntact && nextIntact.to == lineNo) nextIntact = intact.shift();
  18.554 +      if (lineIsHidden(line)) {
  18.555 +        if (line.height != 0) updateLineHeight(line, 0);
  18.556 +      } else if (nextIntact && nextIntact.from <= lineNo && nextIntact.to > lineNo) {
  18.557 +        // This line is intact. Skip to the actual node. Update its
  18.558 +        // line number if needed.
  18.559 +        while (cur.lineObj != line) cur = rm(cur);
  18.560 +        if (lineNumbers && updateNumbersFrom <= lineNo && cur.lineNumber)
  18.561 +          setTextContent(cur.lineNumber, lineNumberFor(cm.options, lineNo));
  18.562 +        cur = cur.nextSibling;
  18.563 +      } else {
  18.564 +        // This line needs to be generated.
  18.565 +        var lineNode = buildLineElement(cm, line, lineNo, dims);
  18.566 +        container.insertBefore(lineNode, cur);
  18.567 +        lineNode.lineObj = line;
  18.568 +      }
  18.569 +      ++lineNo;
  18.570 +    });
  18.571 +    while (cur) cur = rm(cur);
  18.572 +  }
  18.573 +
  18.574 +  function buildLineElement(cm, line, lineNo, dims) {
  18.575 +    var lineElement = lineContent(cm, line);
  18.576 +    var markers = line.gutterMarkers, display = cm.display;
  18.577 +
  18.578 +    if (!cm.options.lineNumbers && !markers && !line.bgClass && !line.wrapClass &&
  18.579 +        (!line.widgets || !line.widgets.length)) return lineElement;
  18.580 +
  18.581 +    // Lines with gutter elements or a background class need
  18.582 +    // to be wrapped again, and have the extra elements added
  18.583 +    // to the wrapper div
  18.584 +
  18.585 +    var wrap = elt("div", null, line.wrapClass, "position: relative");
  18.586 +    if (cm.options.lineNumbers || markers) {
  18.587 +      var gutterWrap = wrap.appendChild(elt("div", null, null, "position: absolute; left: " +
  18.588 +                                            dims.fixedPos + "px"));
  18.589 +      wrap.alignable = [gutterWrap];
  18.590 +      if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
  18.591 +        wrap.lineNumber = gutterWrap.appendChild(
  18.592 +          elt("div", lineNumberFor(cm.options, lineNo),
  18.593 +              "CodeMirror-linenumber CodeMirror-gutter-elt",
  18.594 +              "left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: "
  18.595 +              + display.lineNumInnerWidth + "px"));
  18.596 +      if (markers)
  18.597 +        for (var k = 0; k < cm.options.gutters.length; ++k) {
  18.598 +          var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id];
  18.599 +          if (found)
  18.600 +            gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", "left: " +
  18.601 +                                       dims.gutterLeft[id] + "px; width: " + dims.gutterWidth[id] + "px"));
  18.602 +        }
  18.603 +    }
  18.604 +    // Kludge to make sure the styled element lies behind the selection (by z-index)
  18.605 +    if (line.bgClass)
  18.606 +      wrap.appendChild(elt("div", "\u00a0", line.bgClass + " CodeMirror-linebackground"));
  18.607 +    wrap.appendChild(lineElement);
  18.608 +    if (line.widgets)
  18.609 +      for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
  18.610 +        var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
  18.611 +        node.widget = widget;
  18.612 +        if (widget.noHScroll) {
  18.613 +          (wrap.alignable || (wrap.alignable = [])).push(node);
  18.614 +          var width = dims.wrapperWidth;
  18.615 +          node.style.left = dims.fixedPos + "px";
  18.616 +          if (!widget.coverGutter) {
  18.617 +            width -= dims.gutterTotalWidth;
  18.618 +            node.style.paddingLeft = dims.gutterTotalWidth + "px";
  18.619 +          }
  18.620 +          node.style.width = width + "px";
  18.621 +        }
  18.622 +        if (widget.coverGutter) {
  18.623 +          node.style.zIndex = 5;
  18.624 +          node.style.position = "relative";
  18.625 +          if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px";
  18.626 +        }
  18.627 +        if (widget.above)
  18.628 +          wrap.insertBefore(node, cm.options.lineNumbers && line.height != 0 ? gutterWrap : lineElement);
  18.629 +        else
  18.630 +          wrap.appendChild(node);
  18.631 +      }
  18.632 +
  18.633 +    if (ie_lt8) wrap.style.zIndex = 2;
  18.634 +    return wrap;
  18.635 +  }
  18.636 +
  18.637 +  // SELECTION / CURSOR
  18.638 +
  18.639 +  function updateSelection(cm) {
  18.640 +    var display = cm.display;
  18.641 +    var collapsed = posEq(cm.view.sel.from, cm.view.sel.to);
  18.642 +    if (collapsed || cm.options.showCursorWhenSelecting)
  18.643 +      updateSelectionCursor(cm);
  18.644 +    else
  18.645 +      display.cursor.style.display = display.otherCursor.style.display = "none";
  18.646 +    if (!collapsed)
  18.647 +      updateSelectionRange(cm);
  18.648 +    else
  18.649 +      display.selectionDiv.style.display = "none";
  18.650 +
  18.651 +    // Move the hidden textarea near the cursor to prevent scrolling artifacts
  18.652 +    var headPos = cursorCoords(cm, cm.view.sel.head, "div");
  18.653 +    var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
  18.654 +    display.inputDiv.style.top = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
  18.655 +                                                      headPos.top + lineOff.top - wrapOff.top)) + "px";
  18.656 +    display.inputDiv.style.left = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
  18.657 +                                                       headPos.left + lineOff.left - wrapOff.left)) + "px";
  18.658 +  }
  18.659 +
  18.660 +  // No selection, plain cursor
  18.661 +  function updateSelectionCursor(cm) {
  18.662 +    var display = cm.display, pos = cursorCoords(cm, cm.view.sel.head, "div");
  18.663 +    display.cursor.style.left = pos.left + "px";
  18.664 +    display.cursor.style.top = pos.top + "px";
  18.665 +    display.cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
  18.666 +    display.cursor.style.display = "";
  18.667 +
  18.668 +    if (pos.other) {
  18.669 +      display.otherCursor.style.display = "";
  18.670 +      display.otherCursor.style.left = pos.other.left + "px";
  18.671 +      display.otherCursor.style.top = pos.other.top + "px";
  18.672 +      display.otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
  18.673 +    } else { display.otherCursor.style.display = "none"; }
  18.674 +  }
  18.675 +
  18.676 +  // Highlight selection
  18.677 +  function updateSelectionRange(cm) {
  18.678 +    var display = cm.display, doc = cm.view.doc, sel = cm.view.sel;
  18.679 +    var fragment = document.createDocumentFragment();
  18.680 +    var clientWidth = display.lineSpace.offsetWidth, pl = paddingLeft(cm.display);
  18.681 +
  18.682 +    function add(left, top, width, bottom) {
  18.683 +      if (top < 0) top = 0;
  18.684 +      fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
  18.685 +                               "px; top: " + top + "px; width: " + (width == null ? clientWidth - left : width) +
  18.686 +                               "px; height: " + (bottom - top) + "px"));
  18.687 +    }
  18.688 +
  18.689 +    function drawForLine(line, fromArg, toArg, retTop) {
  18.690 +      var lineObj = getLine(doc, line);
  18.691 +      var lineLen = lineObj.text.length, rVal = retTop ? Infinity : -Infinity;
  18.692 +      function coords(ch) {
  18.693 +        return charCoords(cm, {line: line, ch: ch}, "div", lineObj);
  18.694 +      }
  18.695 +
  18.696 +      iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
  18.697 +        var leftPos = coords(dir == "rtl" ? to - 1 : from);
  18.698 +        var rightPos = coords(dir == "rtl" ? from : to - 1);
  18.699 +        var left = leftPos.left, right = rightPos.right;
  18.700 +        if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
  18.701 +          add(left, leftPos.top, null, leftPos.bottom);
  18.702 +          left = pl;
  18.703 +          if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
  18.704 +        }
  18.705 +        if (toArg == null && to == lineLen) right = clientWidth;
  18.706 +        if (fromArg == null && from == 0) left = pl;
  18.707 +        rVal = retTop ? Math.min(rightPos.top, rVal) : Math.max(rightPos.bottom, rVal);
  18.708 +        if (left < pl + 1) left = pl;
  18.709 +        add(left, rightPos.top, right - left, rightPos.bottom);
  18.710 +      });
  18.711 +      return rVal;
  18.712 +    }
  18.713 +
  18.714 +    if (sel.from.line == sel.to.line) {
  18.715 +      drawForLine(sel.from.line, sel.from.ch, sel.to.ch);
  18.716 +    } else {
  18.717 +      var fromObj = getLine(doc, sel.from.line);
  18.718 +      var cur = fromObj, merged, path = [sel.from.line, sel.from.ch], singleLine;
  18.719 +      while (merged = collapsedSpanAtEnd(cur)) {
  18.720 +        var found = merged.find();
  18.721 +        path.push(found.from.ch, found.to.line, found.to.ch);
  18.722 +        if (found.to.line == sel.to.line) {
  18.723 +          path.push(sel.to.ch);
  18.724 +          singleLine = true;
  18.725 +          break;
  18.726 +        }
  18.727 +        cur = getLine(doc, found.to.line);
  18.728 +      }
  18.729 +
  18.730 +      // This is a single, merged line
  18.731 +      if (singleLine) {
  18.732 +        for (var i = 0; i < path.length; i += 3)
  18.733 +          drawForLine(path[i], path[i+1], path[i+2]);
  18.734 +      } else {
  18.735 +        var middleTop, middleBot, toObj = getLine(doc, sel.to.line);
  18.736 +        if (sel.from.ch)
  18.737 +          // Draw the first line of selection.
  18.738 +          middleTop = drawForLine(sel.from.line, sel.from.ch, null, false);
  18.739 +        else
  18.740 +          // Simply include it in the middle block.
  18.741 +          middleTop = heightAtLine(cm, fromObj) - display.viewOffset;
  18.742 +
  18.743 +        if (!sel.to.ch)
  18.744 +          middleBot = heightAtLine(cm, toObj) - display.viewOffset;
  18.745 +        else
  18.746 +          middleBot = drawForLine(sel.to.line, collapsedSpanAtStart(toObj) ? null : 0, sel.to.ch, true);
  18.747 +
  18.748 +        if (middleTop < middleBot) add(pl, middleTop, null, middleBot);
  18.749 +      }
  18.750 +    }
  18.751 +
  18.752 +    removeChildrenAndAdd(display.selectionDiv, fragment);
  18.753 +    display.selectionDiv.style.display = "";
  18.754 +  }
  18.755 +
  18.756 +  // Cursor-blinking
  18.757 +  function restartBlink(cm) {
  18.758 +    var display = cm.display;
  18.759 +    clearInterval(display.blinker);
  18.760 +    var on = true;
  18.761 +    display.cursor.style.visibility = display.otherCursor.style.visibility = "";
  18.762 +    display.blinker = setInterval(function() {
  18.763 +      if (!display.cursor.offsetHeight) return;
  18.764 +      display.cursor.style.visibility = display.otherCursor.style.visibility = (on = !on) ? "" : "hidden";
  18.765 +    }, cm.options.cursorBlinkRate);
  18.766 +  }
  18.767 +
  18.768 +  // HIGHLIGHT WORKER
  18.769 +
  18.770 +  function startWorker(cm, time) {
  18.771 +    if (cm.view.frontier < cm.display.showingTo)
  18.772 +      cm.view.highlight.set(time, bind(highlightWorker, cm));
  18.773 +  }
  18.774 +
  18.775 +  function highlightWorker(cm) {
  18.776 +    var view = cm.view, doc = view.doc;
  18.777 +    if (view.frontier >= cm.display.showingTo) return;
  18.778 +    var end = +new Date + cm.options.workTime;
  18.779 +    var state = copyState(view.mode, getStateBefore(cm, view.frontier));
  18.780 +    var changed = [], prevChange;
  18.781 +    doc.iter(view.frontier, Math.min(doc.size, cm.display.showingTo + 500), function(line) {
  18.782 +      if (view.frontier >= cm.display.showingFrom) { // Visible
  18.783 +        if (highlightLine(cm, line, state) && view.frontier >= cm.display.showingFrom) {
  18.784 +          if (prevChange && prevChange.end == view.frontier) prevChange.end++;
  18.785 +          else changed.push(prevChange = {start: view.frontier, end: view.frontier + 1});
  18.786 +        }
  18.787 +        line.stateAfter = copyState(view.mode, state);
  18.788 +      } else {
  18.789 +        processLine(cm, line, state);
  18.790 +        line.stateAfter = view.frontier % 5 == 0 ? copyState(view.mode, state) : null;
  18.791 +      }
  18.792 +      ++view.frontier;
  18.793 +      if (+new Date > end) {
  18.794 +        startWorker(cm, cm.options.workDelay);
  18.795 +        return true;
  18.796 +      }
  18.797 +    });
  18.798 +    if (changed.length)
  18.799 +      operation(cm, function() {
  18.800 +        for (var i = 0; i < changed.length; ++i)
  18.801 +          regChange(this, changed[i].start, changed[i].end);
  18.802 +      })();
  18.803 +  }
  18.804 +
  18.805 +  // Finds the line to start with when starting a parse. Tries to
  18.806 +  // find a line with a stateAfter, so that it can start with a
  18.807 +  // valid state. If that fails, it returns the line with the
  18.808 +  // smallest indentation, which tends to need the least context to
  18.809 +  // parse correctly.
  18.810 +  function findStartLine(cm, n) {
  18.811 +    var minindent, minline, doc = cm.view.doc;
  18.812 +    for (var search = n, lim = n - 100; search > lim; --search) {
  18.813 +      if (search == 0) return 0;
  18.814 +      var line = getLine(doc, search-1);
  18.815 +      if (line.stateAfter) return search;
  18.816 +      var indented = countColumn(line.text, null, cm.options.tabSize);
  18.817 +      if (minline == null || minindent > indented) {
  18.818 +        minline = search - 1;
  18.819 +        minindent = indented;
  18.820 +      }
  18.821 +    }
  18.822 +    return minline;
  18.823 +  }
  18.824 +
  18.825 +  function getStateBefore(cm, n) {
  18.826 +    var view = cm.view;
  18.827 +    var pos = findStartLine(cm, n), state = pos && getLine(view.doc, pos-1).stateAfter;
  18.828 +    if (!state) state = startState(view.mode);
  18.829 +    else state = copyState(view.mode, state);
  18.830 +    view.doc.iter(pos, n, function(line) {
  18.831 +      processLine(cm, line, state);
  18.832 +      var save = pos == n - 1 || pos % 5 == 0 || pos >= view.showingFrom && pos < view.showingTo;
  18.833 +      line.stateAfter = save ? copyState(view.mode, state) : null;
  18.834 +      ++pos;
  18.835 +    });
  18.836 +    return state;
  18.837 +  }
  18.838 +
  18.839 +  // POSITION MEASUREMENT
  18.840 +  
  18.841 +  function paddingTop(display) {return display.lineSpace.offsetTop;}
  18.842 +  function paddingLeft(display) {
  18.843 +    var e = removeChildrenAndAdd(display.measure, elt("pre")).appendChild(elt("span", "x"));
  18.844 +    return e.offsetLeft;
  18.845 +  }
  18.846 +
  18.847 +  function measureChar(cm, line, ch, data) {
  18.848 +    var data = data || measureLine(cm, line), dir = -1;
  18.849 +    for (var pos = ch;; pos += dir) {
  18.850 +      var r = data[pos];
  18.851 +      if (r) break;
  18.852 +      if (dir < 0 && pos == 0) dir = 1;
  18.853 +    }
  18.854 +    return {left: pos < ch ? r.right : r.left,
  18.855 +            right: pos > ch ? r.left : r.right,
  18.856 +            top: r.top, bottom: r.bottom};
  18.857 +  }
  18.858 +
  18.859 +  function measureLine(cm, line) {
  18.860 +    // First look in the cache
  18.861 +    var display = cm.display, cache = cm.display.measureLineCache;
  18.862 +    for (var i = 0; i < cache.length; ++i) {
  18.863 +      var memo = cache[i];
  18.864 +      if (memo.text == line.text && memo.markedSpans == line.markedSpans &&
  18.865 +          display.scroller.clientWidth == memo.width)
  18.866 +        return memo.measure;
  18.867 +    }
  18.868 +    
  18.869 +    var measure = measureLineInner(cm, line);
  18.870 +    // Store result in the cache
  18.871 +    var memo = {text: line.text, width: display.scroller.clientWidth,
  18.872 +                markedSpans: line.markedSpans, measure: measure};
  18.873 +    if (cache.length == 16) cache[++display.measureLineCachePos % 16] = memo;
  18.874 +    else cache.push(memo);
  18.875 +    return measure;
  18.876 +  }
  18.877 +
  18.878 +  function measureLineInner(cm, line) {
  18.879 +    var display = cm.display, measure = emptyArray(line.text.length);
  18.880 +    var pre = lineContent(cm, line, measure);
  18.881 +
  18.882 +    // IE does not cache element positions of inline elements between
  18.883 +    // calls to getBoundingClientRect. This makes the loop below,
  18.884 +    // which gathers the positions of all the characters on the line,
  18.885 +    // do an amount of layout work quadratic to the number of
  18.886 +    // characters. When line wrapping is off, we try to improve things
  18.887 +    // by first subdividing the line into a bunch of inline blocks, so
  18.888 +    // that IE can reuse most of the layout information from caches
  18.889 +    // for those blocks. This does interfere with line wrapping, so it
  18.890 +    // doesn't work when wrapping is on, but in that case the
  18.891 +    // situation is slightly better, since IE does cache line-wrapping
  18.892 +    // information and only recomputes per-line.
  18.893 +    if (ie && !ie_lt8 && !cm.options.lineWrapping && pre.childNodes.length > 100) {
  18.894 +      var fragment = document.createDocumentFragment();
  18.895 +      var chunk = 10, n = pre.childNodes.length;
  18.896 +      for (var i = 0, chunks = Math.ceil(n / chunk); i < chunks; ++i) {
  18.897 +        var wrap = elt("div", null, null, "display: inline-block");
  18.898 +        for (var j = 0; j < chunk && n; ++j) {
  18.899 +          wrap.appendChild(pre.firstChild);
  18.900 +          --n;
  18.901 +        }
  18.902 +        fragment.appendChild(wrap);
  18.903 +      }
  18.904 +      pre.appendChild(fragment);
  18.905 +    }
  18.906 +
  18.907 +    removeChildrenAndAdd(display.measure, pre);
  18.908 +
  18.909 +    var outer = display.lineDiv.getBoundingClientRect();
  18.910 +    var vranges = [], data = emptyArray(line.text.length), maxBot = pre.offsetHeight;
  18.911 +    for (var i = 0, cur; i < measure.length; ++i) if (cur = measure[i]) {
  18.912 +      var size = cur.getBoundingClientRect();
  18.913 +      var top = Math.max(0, size.top - outer.top), bot = Math.min(size.bottom - outer.top, maxBot);
  18.914 +      for (var j = 0; j < vranges.length; j += 2) {
  18.915 +        var rtop = vranges[j], rbot = vranges[j+1];
  18.916 +        if (rtop > bot || rbot < top) continue;
  18.917 +        if (rtop <= top && rbot >= bot ||
  18.918 +            top <= rtop && bot >= rbot ||
  18.919 +            Math.min(bot, rbot) - Math.max(top, rtop) >= (bot - top) >> 1) {
  18.920 +          vranges[j] = Math.min(top, rtop);
  18.921 +          vranges[j+1] = Math.max(bot, rbot);
  18.922 +          break;
  18.923 +        }
  18.924 +      }
  18.925 +      if (j == vranges.length) vranges.push(top, bot);
  18.926 +      data[i] = {left: size.left - outer.left, right: size.right - outer.left, top: j};
  18.927 +    }
  18.928 +    for (var i = 0, cur; i < data.length; ++i) if (cur = data[i]) {
  18.929 +      var vr = cur.top;
  18.930 +      cur.top = vranges[vr]; cur.bottom = vranges[vr+1];
  18.931 +    }
  18.932 +    return data;
  18.933 +  }
  18.934 +
  18.935 +  function clearCaches(cm) {
  18.936 +    cm.display.measureLineCache.length = cm.display.measureLineCachePos = 0;
  18.937 +    cm.display.cachedCharWidth = cm.display.cachedTextHeight = null;
  18.938 +    cm.view.maxLineChanged = true;
  18.939 +  }
  18.940 +
  18.941 +  // Context is one of "line", "div" (display.lineDiv), "local"/null (editor), or "page"
  18.942 +  function intoCoordSystem(cm, lineObj, rect, context) {
  18.943 +    if (lineObj.widgets) for (var i = 0; i < lineObj.widgets.length; ++i) if (lineObj.widgets[i].above) {
  18.944 +      var size = lineObj.widgets[i].node.offsetHeight;
  18.945 +      rect.top += size; rect.bottom += size;
  18.946 +    }
  18.947 +    if (context == "line") return rect;
  18.948 +    if (!context) context = "local";
  18.949 +    var yOff = heightAtLine(cm, lineObj);
  18.950 +    if (context != "local") yOff -= cm.display.viewOffset;
  18.951 +    if (context == "page") {
  18.952 +      var lOff = cm.display.lineSpace.getBoundingClientRect();
  18.953 +      yOff += lOff.top + (window.pageYOffset || (document.documentElement || document.body).scrollTop);
  18.954 +      var xOff = lOff.left + (window.pageXOffset || (document.documentElement || document.body).scrollLeft);
  18.955 +      rect.left += xOff; rect.right += xOff;
  18.956 +    }
  18.957 +    rect.top += yOff; rect.bottom += yOff;
  18.958 +    return rect;
  18.959 +  }
  18.960 +
  18.961 +  function charCoords(cm, pos, context, lineObj) {
  18.962 +    if (!lineObj) lineObj = getLine(cm.view.doc, pos.line);
  18.963 +    return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch), context);
  18.964 +  }
  18.965 +
  18.966 +  function cursorCoords(cm, pos, context, lineObj, measurement) {
  18.967 +    lineObj = lineObj || getLine(cm.view.doc, pos.line);
  18.968 +    if (!measurement) measurement = measureLine(cm, lineObj);
  18.969 +    function get(ch, right) {
  18.970 +      var m = measureChar(cm, lineObj, ch, measurement);
  18.971 +      if (right) m.left = m.right; else m.right = m.left;
  18.972 +      return intoCoordSystem(cm, lineObj, m, context);
  18.973 +    }
  18.974 +    var order = getOrder(lineObj), ch = pos.ch;
  18.975 +    if (!order) return get(ch);
  18.976 +    var main, other, linedir = order[0].level;
  18.977 +    for (var i = 0; i < order.length; ++i) {
  18.978 +      var part = order[i], rtl = part.level % 2, nb, here;
  18.979 +      if (part.from < ch && part.to > ch) return get(ch, rtl);
  18.980 +      var left = rtl ? part.to : part.from, right = rtl ? part.from : part.to;
  18.981 +      if (left == ch) {
  18.982 +        // Opera and IE return bogus offsets and widths for edges
  18.983 +        // where the direction flips, but only for the side with the
  18.984 +        // lower level. So we try to use the side with the higher
  18.985 +        // level.
  18.986 +        if (i && part.level < (nb = order[i-1]).level) here = get(nb.level % 2 ? nb.from : nb.to - 1, true);
  18.987 +        else here = get(rtl && part.from != part.to ? ch - 1 : ch);
  18.988 +        if (rtl == linedir) main = here; else other = here;
  18.989 +      } else if (right == ch) {
  18.990 +        var nb = i < order.length - 1 && order[i+1];
  18.991 +        if (!rtl && nb && nb.from == nb.to) continue;
  18.992 +        if (nb && part.level < nb.level) here = get(nb.level % 2 ? nb.to - 1 : nb.from);
  18.993 +        else here = get(rtl ? ch : ch - 1, true);
  18.994 +        if (rtl == linedir) main = here; else other = here;
  18.995 +      }
  18.996 +    }
  18.997 +    if (linedir && !ch) other = get(order[0].to - 1);
  18.998 +    if (!main) return other;
  18.999 +    if (other) main.other = other;
 18.1000 +    return main;
 18.1001 +  }
 18.1002 +
 18.1003 +  // Coords must be lineSpace-local
 18.1004 +  function coordsChar(cm, x, y) {
 18.1005 +    var doc = cm.view.doc;
 18.1006 +    y += cm.display.viewOffset;
 18.1007 +    if (y < 0) return {line: 0, ch: 0, outside: true};
 18.1008 +    var lineNo = lineAtHeight(doc, y);
 18.1009 +    if (lineNo >= doc.size) return {line: doc.size - 1, ch: getLine(doc, doc.size - 1).text.length};
 18.1010 +    if (x < 0) x = 0;
 18.1011 +
 18.1012 +    for (;;) {
 18.1013 +      var lineObj = getLine(doc, lineNo);
 18.1014 +      var found = coordsCharInner(cm, lineObj, lineNo, x, y);
 18.1015 +      var merged = collapsedSpanAtEnd(lineObj);
 18.1016 +      if (merged && found.ch == lineRight(lineObj))
 18.1017 +        lineNo = merged.find().to.line;
 18.1018 +      else
 18.1019 +        return found;
 18.1020 +    }
 18.1021 +  }
 18.1022 +
 18.1023 +  function coordsCharInner(cm, lineObj, lineNo, x, y) {
 18.1024 +    var innerOff = y - heightAtLine(cm, lineObj);
 18.1025 +    var wrongLine = false, cWidth = cm.display.wrapper.clientWidth;
 18.1026 +    var measurement = measureLine(cm, lineObj);
 18.1027 +
 18.1028 +    function getX(ch) {
 18.1029 +      var sp = cursorCoords(cm, {line: lineNo, ch: ch}, "line",
 18.1030 +                            lineObj, measurement);
 18.1031 +      wrongLine = true;
 18.1032 +      if (innerOff > sp.bottom) return Math.max(0, sp.left - cWidth);
 18.1033 +      else if (innerOff < sp.top) return sp.left + cWidth;
 18.1034 +      else wrongLine = false;
 18.1035 +      return sp.left;
 18.1036 +    }
 18.1037 +
 18.1038 +    var bidi = getOrder(lineObj), dist = lineObj.text.length;
 18.1039 +    var from = lineLeft(lineObj), to = lineRight(lineObj);
 18.1040 +    var fromX = paddingLeft(cm.display), toX = getX(to);
 18.1041 +
 18.1042 +    if (x > toX) return {line: lineNo, ch: to, outside: wrongLine};
 18.1043 +    // Do a binary search between these bounds.
 18.1044 +    for (;;) {
 18.1045 +      if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
 18.1046 +        var after = x - fromX < toX - x, ch = after ? from : to;
 18.1047 +        while (isExtendingChar.test(lineObj.text.charAt(ch))) ++ch;
 18.1048 +        return {line: lineNo, ch: ch, after: after, outside: wrongLine};
 18.1049 +      }
 18.1050 +      var step = Math.ceil(dist / 2), middle = from + step;
 18.1051 +      if (bidi) {
 18.1052 +        middle = from;
 18.1053 +        for (var i = 0; i < step; ++i) middle = moveVisually(lineObj, middle, 1);
 18.1054 +      }
 18.1055 +      var middleX = getX(middle);
 18.1056 +      if (middleX > x) {to = middle; toX = middleX; if (wrongLine) toX += 1000; dist -= step;}
 18.1057 +      else {from = middle; fromX = middleX; dist = step;}
 18.1058 +    }
 18.1059 +  }
 18.1060 +
 18.1061 +  var measureText;
 18.1062 +  function textHeight(display) {
 18.1063 +    if (display.cachedTextHeight != null) return display.cachedTextHeight;
 18.1064 +    if (measureText == null) {
 18.1065 +      measureText = elt("pre");
 18.1066 +      // Measure a bunch of lines, for browsers that compute
 18.1067 +      // fractional heights.
 18.1068 +      for (var i = 0; i < 49; ++i) {
 18.1069 +        measureText.appendChild(document.createTextNode("x"));
 18.1070 +        measureText.appendChild(elt("br"));
 18.1071 +      }
 18.1072 +      measureText.appendChild(document.createTextNode("x"));
 18.1073 +    }
 18.1074 +    removeChildrenAndAdd(display.measure, measureText);
 18.1075 +    var height = measureText.offsetHeight / 50;
 18.1076 +    if (height > 3) display.cachedTextHeight = height;
 18.1077 +    removeChildren(display.measure);
 18.1078 +    return height || 1;
 18.1079 +  }
 18.1080 +
 18.1081 +  function charWidth(display) {
 18.1082 +    if (display.cachedCharWidth != null) return display.cachedCharWidth;
 18.1083 +    var anchor = elt("span", "x");
 18.1084 +    var pre = elt("pre", [anchor]);
 18.1085 +    removeChildrenAndAdd(display.measure, pre);
 18.1086 +    var width = anchor.offsetWidth;
 18.1087 +    if (width > 2) display.cachedCharWidth = width;
 18.1088 +    return width || 10;
 18.1089 +  }
 18.1090 +
 18.1091 +  // OPERATIONS
 18.1092 +
 18.1093 +  // Operations are used to wrap changes in such a way that each
 18.1094 +  // change won't have to update the cursor and display (which would
 18.1095 +  // be awkward, slow, and error-prone), but instead updates are
 18.1096 +  // batched and then all combined and executed at once.
 18.1097 +
 18.1098 +  function startOperation(cm) {
 18.1099 +    if (cm.curOp) ++cm.curOp.depth;
 18.1100 +    else cm.curOp = {
 18.1101 +      // Nested operations delay update until the outermost one
 18.1102 +      // finishes.
 18.1103 +      depth: 1,
 18.1104 +      // An array of ranges of lines that have to be updated. See
 18.1105 +      // updateDisplay.
 18.1106 +      changes: [],
 18.1107 +      delayedCallbacks: [],
 18.1108 +      updateInput: null,
 18.1109 +      userSelChange: null,
 18.1110 +      textChanged: null,
 18.1111 +      selectionChanged: false,
 18.1112 +      updateMaxLine: false,
 18.1113 +      id: ++cm.nextOpId
 18.1114 +    };
 18.1115 +  }
 18.1116 +
 18.1117 +  function endOperation(cm) {
 18.1118 +    var op = cm.curOp;
 18.1119 +    if (--op.depth) return;
 18.1120 +    cm.curOp = null;
 18.1121 +    var view = cm.view, display = cm.display;
 18.1122 +    if (op.updateMaxLine) computeMaxLength(view);
 18.1123 +    if (view.maxLineChanged && !cm.options.lineWrapping) {
 18.1124 +      var width = measureChar(cm, view.maxLine, view.maxLine.text.length).right;
 18.1125 +      display.sizer.style.minWidth = (width + 3 + scrollerCutOff) + "px";
 18.1126 +      view.maxLineChanged = false;
 18.1127 +    }
 18.1128 +    var newScrollPos, updated;
 18.1129 +    if (op.selectionChanged) {
 18.1130 +      var coords = cursorCoords(cm, view.sel.head);
 18.1131 +      newScrollPos = calculateScrollPos(cm, coords.left, coords.top, coords.left, coords.bottom);
 18.1132 +    }
 18.1133 +    if (op.changes.length || newScrollPos && newScrollPos.scrollTop != null)
 18.1134 +      updated = updateDisplay(cm, op.changes, newScrollPos && newScrollPos.scrollTop);
 18.1135 +    if (!updated && op.selectionChanged) updateSelection(cm);
 18.1136 +    if (newScrollPos) scrollCursorIntoView(cm);
 18.1137 +    if (op.selectionChanged) restartBlink(cm);
 18.1138 +
 18.1139 +    if (view.focused && op.updateInput)
 18.1140 +      resetInput(cm, op.userSelChange);
 18.1141 +
 18.1142 +    if (op.textChanged)
 18.1143 +      signal(cm, "change", cm, op.textChanged);
 18.1144 +    if (op.selectionChanged) signal(cm, "cursorActivity", cm);
 18.1145 +    for (var i = 0; i < op.delayedCallbacks.length; ++i) op.delayedCallbacks[i](cm);
 18.1146 +  }
 18.1147 +
 18.1148 +  // Wraps a function in an operation. Returns the wrapped function.
 18.1149 +  function operation(cm1, f) {
 18.1150 +    return function() {
 18.1151 +      var cm = cm1 || this;
 18.1152 +      startOperation(cm);
 18.1153 +      try {var result = f.apply(cm, arguments);}
 18.1154 +      finally {endOperation(cm);}
 18.1155 +      return result;
 18.1156 +    };
 18.1157 +  }
 18.1158 +
 18.1159 +  function regChange(cm, from, to, lendiff) {
 18.1160 +    cm.curOp.changes.push({from: from, to: to, diff: lendiff});
 18.1161 +  }
 18.1162 +
 18.1163 +  // INPUT HANDLING
 18.1164 +
 18.1165 +  function slowPoll(cm) {
 18.1166 +    if (cm.view.pollingFast) return;
 18.1167 +    cm.display.poll.set(cm.options.pollInterval, function() {
 18.1168 +      readInput(cm);
 18.1169 +      if (cm.view.focused) slowPoll(cm);
 18.1170 +    });
 18.1171 +  }
 18.1172 +
 18.1173 +  function fastPoll(cm) {
 18.1174 +    var missed = false;
 18.1175 +    cm.display.pollingFast = true;
 18.1176 +    function p() {
 18.1177 +      var changed = readInput(cm);
 18.1178 +      if (!changed && !missed) {missed = true; cm.display.poll.set(60, p);}
 18.1179 +      else {cm.display.pollingFast = false; slowPoll(cm);}
 18.1180 +    }
 18.1181 +    cm.display.poll.set(20, p);
 18.1182 +  }
 18.1183 +
 18.1184 +  // prevInput is a hack to work with IME. If we reset the textarea
 18.1185 +  // on every change, that breaks IME. So we look for changes
 18.1186 +  // compared to the previous content instead. (Modern browsers have
 18.1187 +  // events that indicate IME taking place, but these are not widely
 18.1188 +  // supported or compatible enough yet to rely on.)
 18.1189 +  function readInput(cm) {
 18.1190 +    var input = cm.display.input, prevInput = cm.display.prevInput, view = cm.view, sel = view.sel;
 18.1191 +    if (!view.focused || hasSelection(input) || isReadOnly(cm)) return false;
 18.1192 +    var text = input.value;
 18.1193 +    if (text == prevInput && posEq(sel.from, sel.to)) return false;
 18.1194 +    startOperation(cm);
 18.1195 +    view.sel.shift = false;
 18.1196 +    var same = 0, l = Math.min(prevInput.length, text.length);
 18.1197 +    while (same < l && prevInput[same] == text[same]) ++same;
 18.1198 +    var from = sel.from, to = sel.to;
 18.1199 +    if (same < prevInput.length)
 18.1200 +      from = {line: from.line, ch: from.ch - (prevInput.length - same)};
 18.1201 +    else if (view.overwrite && posEq(from, to) && !cm.display.pasteIncoming)
 18.1202 +      to = {line: to.line, ch: Math.min(getLine(cm.view.doc, to.line).text.length, to.ch + (text.length - same))};
 18.1203 +    var updateInput = cm.curOp.updateInput;
 18.1204 +    updateDoc(cm, from, to, splitLines(text.slice(same)), "end",
 18.1205 +              cm.display.pasteIncoming ? "paste" : "input", {from: from, to: to});
 18.1206 +    cm.curOp.updateInput = updateInput;
 18.1207 +    if (text.length > 1000) input.value = cm.display.prevInput = "";
 18.1208 +    else cm.display.prevInput = text;
 18.1209 +    endOperation(cm);
 18.1210 +    cm.display.pasteIncoming = false;
 18.1211 +    return true;
 18.1212 +  }
 18.1213 +
 18.1214 +  function resetInput(cm, user) {
 18.1215 +    var view = cm.view, minimal, selected;
 18.1216 +    if (!posEq(view.sel.from, view.sel.to)) {
 18.1217 +      cm.display.prevInput = "";
 18.1218 +      minimal = hasCopyEvent &&
 18.1219 +        (view.sel.to.line - view.sel.from.line > 100 || (selected = cm.getSelection()).length > 1000);
 18.1220 +      if (minimal) cm.display.input.value = "-";
 18.1221 +      else cm.display.input.value = selected || cm.getSelection();
 18.1222 +      if (view.focused) selectInput(cm.display.input);
 18.1223 +    } else if (user) cm.display.prevInput = cm.display.input.value = "";
 18.1224 +    cm.display.inaccurateSelection = minimal;
 18.1225 +  }
 18.1226 +
 18.1227 +  function focusInput(cm) {
 18.1228 +    if (cm.options.readOnly != "nocursor" && (ie || document.activeElement != cm.display.input))
 18.1229 +      cm.display.input.focus();
 18.1230 +  }
 18.1231 +
 18.1232 +  function isReadOnly(cm) {
 18.1233 +    return cm.options.readOnly || cm.view.cantEdit;
 18.1234 +  }
 18.1235 +
 18.1236 +  // EVENT HANDLERS
 18.1237 +
 18.1238 +  function registerEventHandlers(cm) {
 18.1239 +    var d = cm.display;
 18.1240 +    on(d.scroller, "mousedown", operation(cm, onMouseDown));
 18.1241 +    on(d.scroller, "dblclick", operation(cm, e_preventDefault));
 18.1242 +    on(d.lineSpace, "selectstart", function(e) {
 18.1243 +      if (!mouseEventInWidget(d, e)) e_preventDefault(e);
 18.1244 +    });
 18.1245 +    // Gecko browsers fire contextmenu *after* opening the menu, at
 18.1246 +    // which point we can't mess with it anymore. Context menu is
 18.1247 +    // handled in onMouseDown for Gecko.
 18.1248 +    if (!gecko) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e);});
 18.1249 +
 18.1250 +    on(d.scroller, "scroll", function() {
 18.1251 +      setScrollTop(cm, d.scroller.scrollTop);
 18.1252 +      setScrollLeft(cm, d.scroller.scrollLeft, true);
 18.1253 +      signal(cm, "scroll", cm);
 18.1254 +    });
 18.1255 +    on(d.scrollbarV, "scroll", function() {
 18.1256 +      setScrollTop(cm, d.scrollbarV.scrollTop);
 18.1257 +    });
 18.1258 +    on(d.scrollbarH, "scroll", function() {
 18.1259 +      setScrollLeft(cm, d.scrollbarH.scrollLeft);
 18.1260 +    });
 18.1261 +
 18.1262 +    on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e);});
 18.1263 +    on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e);});
 18.1264 +
 18.1265 +    function reFocus() { if (cm.view.focused) setTimeout(bind(focusInput, cm), 0); }
 18.1266 +    on(d.scrollbarH, "mousedown", reFocus);
 18.1267 +    on(d.scrollbarV, "mousedown", reFocus);
 18.1268 +    // Prevent wrapper from ever scrolling
 18.1269 +    on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
 18.1270 +    on(window, "resize", function resizeHandler() {
 18.1271 +      // Might be a text scaling operation, clear size caches.
 18.1272 +      d.cachedCharWidth = d.cachedTextHeight = null;
 18.1273 +      clearCaches(cm);
 18.1274 +      if (d.wrapper.parentNode) updateDisplay(cm, true);
 18.1275 +      else off(window, "resize", resizeHandler);
 18.1276 +    });
 18.1277 +
 18.1278 +    on(d.input, "keyup", operation(cm, function(e) {
 18.1279 +      if (cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
 18.1280 +      if (e_prop(e, "keyCode") == 16) cm.view.sel.shift = false;
 18.1281 +    }));
 18.1282 +    on(d.input, "input", bind(fastPoll, cm));
 18.1283 +    on(d.input, "keydown", operation(cm, onKeyDown));
 18.1284 +    on(d.input, "keypress", operation(cm, onKeyPress));
 18.1285 +    on(d.input, "focus", bind(onFocus, cm));
 18.1286 +    on(d.input, "blur", bind(onBlur, cm));
 18.1287 +
 18.1288 +    function drag_(e) {
 18.1289 +      if (cm.options.onDragEvent && cm.options.onDragEvent(cm, addStop(e))) return;
 18.1290 +      e_stop(e);
 18.1291 +    }
 18.1292 +    if (cm.options.dragDrop) {
 18.1293 +      on(d.scroller, "dragstart", function(e){onDragStart(cm, e);});
 18.1294 +      on(d.scroller, "dragenter", drag_);
 18.1295 +      on(d.scroller, "dragover", drag_);
 18.1296 +      on(d.scroller, "drop", operation(cm, onDrop));
 18.1297 +    }
 18.1298 +    on(d.scroller, "paste", function(){focusInput(cm); fastPoll(cm);});
 18.1299 +    on(d.input, "paste", function() {
 18.1300 +      d.pasteIncoming = true;
 18.1301 +      fastPoll(cm);
 18.1302 +    });
 18.1303 +
 18.1304 +    function prepareCopy() {
 18.1305 +      if (d.inaccurateSelection) {
 18.1306 +        d.prevInput = "";
 18.1307 +        d.inaccurateSelection = false;
 18.1308 +        d.input.value = cm.getSelection();
 18.1309 +        selectInput(d.input);
 18.1310 +      }
 18.1311 +    }
 18.1312 +    on(d.input, "cut", prepareCopy);
 18.1313 +    on(d.input, "copy", prepareCopy);
 18.1314 +
 18.1315 +    // Needed to handle Tab key in KHTML
 18.1316 +    if (khtml) on(d.sizer, "mouseup", function() {
 18.1317 +        if (document.activeElement == d.input) d.input.blur();
 18.1318 +        focusInput(cm);
 18.1319 +    });
 18.1320 +  }
 18.1321 +
 18.1322 +  function mouseEventInWidget(display, e) {
 18.1323 +    for (var n = e_target(e); n != display.wrapper; n = n.parentNode)
 18.1324 +      if (/\bCodeMirror-(?:line)?widget\b/.test(n.className) ||
 18.1325 +          n.parentNode == display.sizer && n != display.mover) return true;
 18.1326 +  }
 18.1327 +
 18.1328 +  function posFromMouse(cm, e, liberal) {
 18.1329 +    var display = cm.display;
 18.1330 +    if (!liberal) {
 18.1331 +      var target = e_target(e);
 18.1332 +      if (target == display.scrollbarH || target == display.scrollbarH.firstChild ||
 18.1333 +          target == display.scrollbarV || target == display.scrollbarV.firstChild ||
 18.1334 +          target == display.scrollbarFiller) return null;
 18.1335 +    }
 18.1336 +    var x, y, space = display.lineSpace.getBoundingClientRect();
 18.1337 +    // Fails unpredictably on IE[67] when mouse is dragged around quickly.
 18.1338 +    try { x = e.clientX; y = e.clientY; } catch (e) { return null; }
 18.1339 +    return coordsChar(cm, x - space.left, y - space.top);
 18.1340 +  }
 18.1341 +
 18.1342 +  var lastClick, lastDoubleClick;
 18.1343 +  function onMouseDown(e) {
 18.1344 +    var cm = this, display = cm.display, view = cm.view, sel = view.sel, doc = view.doc;
 18.1345 +    sel.shift = e_prop(e, "shiftKey");
 18.1346 +
 18.1347 +    if (mouseEventInWidget(display, e)) {
 18.1348 +      if (!webkit) {
 18.1349 +        display.scroller.draggable = false;
 18.1350 +        setTimeout(function(){display.scroller.draggable = true;}, 100);
 18.1351 +      }
 18.1352 +      return;
 18.1353 +    }
 18.1354 +    if (clickInGutter(cm, e)) return;
 18.1355 +    var start = posFromMouse(cm, e);
 18.1356 +
 18.1357 +    switch (e_button(e)) {
 18.1358 +    case 3:
 18.1359 +      if (gecko) onContextMenu.call(cm, cm, e);
 18.1360 +      return;
 18.1361 +    case 2:
 18.1362 +      if (start) extendSelection(cm, start);
 18.1363 +      setTimeout(bind(focusInput, cm), 20);
 18.1364 +      e_preventDefault(e);
 18.1365 +      return;
 18.1366 +    }
 18.1367 +    // For button 1, if it was clicked inside the editor
 18.1368 +    // (posFromMouse returning non-null), we have to adjust the
 18.1369 +    // selection.
 18.1370 +    if (!start) {if (e_target(e) == display.scroller) e_preventDefault(e); return;}
 18.1371 +
 18.1372 +    if (!view.focused) onFocus(cm);
 18.1373 +
 18.1374 +    var now = +new Date, type = "single";
 18.1375 +    if (lastDoubleClick && lastDoubleClick.time > now - 400 && posEq(lastDoubleClick.pos, start)) {
 18.1376 +      type = "triple";
 18.1377 +      e_preventDefault(e);
 18.1378 +      setTimeout(bind(focusInput, cm), 20);
 18.1379 +      selectLine(cm, start.line);
 18.1380 +    } else if (lastClick && lastClick.time > now - 400 && posEq(lastClick.pos, start)) {
 18.1381 +      type = "double";
 18.1382 +      lastDoubleClick = {time: now, pos: start};
 18.1383 +      e_preventDefault(e);
 18.1384 +      var word = findWordAt(getLine(doc, start.line).text, start);
 18.1385 +      extendSelection(cm, word.from, word.to);
 18.1386 +    } else { lastClick = {time: now, pos: start}; }
 18.1387 +
 18.1388 +    var last = start;
 18.1389 +    if (cm.options.dragDrop && dragAndDrop && !isReadOnly(cm) && !posEq(sel.from, sel.to) &&
 18.1390 +        !posLess(start, sel.from) && !posLess(sel.to, start) && type == "single") {
 18.1391 +      var dragEnd = operation(cm, function(e2) {
 18.1392 +        if (webkit) display.scroller.draggable = false;
 18.1393 +        view.draggingText = false;
 18.1394 +        off(document, "mouseup", dragEnd);
 18.1395 +        off(display.scroller, "drop", dragEnd);
 18.1396 +        if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
 18.1397 +          e_preventDefault(e2);
 18.1398 +          extendSelection(cm, start);
 18.1399 +          focusInput(cm);
 18.1400 +        }
 18.1401 +      });
 18.1402 +      // Let the drag handler handle this.
 18.1403 +      if (webkit) display.scroller.draggable = true;
 18.1404 +      view.draggingText = dragEnd;
 18.1405 +      // IE's approach to draggable
 18.1406 +      if (display.scroller.dragDrop) display.scroller.dragDrop();
 18.1407 +      on(document, "mouseup", dragEnd);
 18.1408 +      on(display.scroller, "drop", dragEnd);
 18.1409 +      return;
 18.1410 +    }
 18.1411 +    e_preventDefault(e);
 18.1412 +    if (type == "single") extendSelection(cm, clipPos(doc, start));
 18.1413 +
 18.1414 +    var startstart = sel.from, startend = sel.to;
 18.1415 +
 18.1416 +    function doSelect(cur) {
 18.1417 +      if (type == "single") {
 18.1418 +        extendSelection(cm, clipPos(doc, start), cur);
 18.1419 +        return;
 18.1420 +      }
 18.1421 +
 18.1422 +      startstart = clipPos(doc, startstart);
 18.1423 +      startend = clipPos(doc, startend);
 18.1424 +      if (type == "double") {
 18.1425 +        var word = findWordAt(getLine(doc, cur.line).text, cur);
 18.1426 +        if (posLess(cur, startstart)) extendSelection(cm, word.from, startend);
 18.1427 +        else extendSelection(cm, startstart, word.to);
 18.1428 +      } else if (type == "triple") {
 18.1429 +        if (posLess(cur, startstart)) extendSelection(cm, startend, clipPos(doc, {line: cur.line, ch: 0}));
 18.1430 +        else extendSelection(cm, startstart, clipPos(doc, {line: cur.line + 1, ch: 0}));
 18.1431 +      }
 18.1432 +    }
 18.1433 +
 18.1434 +    var editorSize = display.wrapper.getBoundingClientRect();
 18.1435 +    // Used to ensure timeout re-tries don't fire when another extend
 18.1436 +    // happened in the meantime (clearTimeout isn't reliable -- at
 18.1437 +    // least on Chrome, the timeouts still happen even when cleared,
 18.1438 +    // if the clear happens after their scheduled firing time).
 18.1439 +    var counter = 0;
 18.1440 +
 18.1441 +    function extend(e) {
 18.1442 +      var curCount = ++counter;
 18.1443 +      var cur = posFromMouse(cm, e, true);
 18.1444 +      if (!cur) return;
 18.1445 +      if (!posEq(cur, last)) {
 18.1446 +        if (!view.focused) onFocus(cm);
 18.1447 +        last = cur;
 18.1448 +        doSelect(cur);
 18.1449 +        var visible = visibleLines(display, doc);
 18.1450 +        if (cur.line >= visible.to || cur.line < visible.from)
 18.1451 +          setTimeout(operation(cm, function(){if (counter == curCount) extend(e);}), 150);
 18.1452 +      } else {
 18.1453 +        var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
 18.1454 +        if (outside) setTimeout(operation(cm, function() {
 18.1455 +          if (counter != curCount) return;
 18.1456 +          display.scroller.scrollTop += outside;
 18.1457 +          extend(e);
 18.1458 +        }), 50);
 18.1459 +      }
 18.1460 +    }
 18.1461 +
 18.1462 +    function done(e) {
 18.1463 +      counter = Infinity;
 18.1464 +      var cur = posFromMouse(cm, e);
 18.1465 +      if (cur) doSelect(cur);
 18.1466 +      e_preventDefault(e);
 18.1467 +      focusInput(cm);
 18.1468 +      off(document, "mousemove", move);
 18.1469 +      off(document, "mouseup", up);
 18.1470 +    }
 18.1471 +
 18.1472 +    var move = operation(cm, function(e) {
 18.1473 +      if (!ie && !e_button(e)) done(e);
 18.1474 +      else extend(e);
 18.1475 +    });
 18.1476 +    var up = operation(cm, done);
 18.1477 +    on(document, "mousemove", move);
 18.1478 +    on(document, "mouseup", up);
 18.1479 +  }
 18.1480 +
 18.1481 +  function onDrop(e) {
 18.1482 +    var cm = this;
 18.1483 +    if (cm.options.onDragEvent && cm.options.onDragEvent(cm, addStop(e))) return;
 18.1484 +    e_preventDefault(e);
 18.1485 +    var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
 18.1486 +    if (!pos || isReadOnly(cm)) return;
 18.1487 +    if (files && files.length && window.FileReader && window.File) {
 18.1488 +      var n = files.length, text = Array(n), read = 0;
 18.1489 +      var loadFile = function(file, i) {
 18.1490 +        var reader = new FileReader;
 18.1491 +        reader.onload = function() {
 18.1492 +          text[i] = reader.result;
 18.1493 +          if (++read == n) {
 18.1494 +            pos = clipPos(cm.view.doc, pos);
 18.1495 +            operation(cm, function() {
 18.1496 +              var end = replaceRange(cm, text.join(""), pos, pos, "paste");
 18.1497 +              setSelection(cm, pos, end);
 18.1498 +            })();
 18.1499 +          }
 18.1500 +        };
 18.1501 +        reader.readAsText(file);
 18.1502 +      };
 18.1503 +      for (var i = 0; i < n; ++i) loadFile(files[i], i);
 18.1504 +    } else {
 18.1505 +      // Don't do a replace if the drop happened inside of the selected text.
 18.1506 +      if (cm.view.draggingText && !(posLess(pos, cm.view.sel.from) || posLess(cm.view.sel.to, pos))) {
 18.1507 +        cm.view.draggingText(e);
 18.1508 +        if (ie) setTimeout(bind(focusInput, cm), 50);
 18.1509 +        return;
 18.1510 +      }
 18.1511 +      try {
 18.1512 +        var text = e.dataTransfer.getData("Text");
 18.1513 +        if (text) {
 18.1514 +          var curFrom = cm.view.sel.from, curTo = cm.view.sel.to;
 18.1515 +          setSelection(cm, pos, pos);
 18.1516 +          if (cm.view.draggingText) replaceRange(cm, "", curFrom, curTo, "paste");
 18.1517 +          cm.replaceSelection(text, null, "paste");
 18.1518 +          focusInput(cm);
 18.1519 +          onFocus(cm);
 18.1520 +        }
 18.1521 +      }
 18.1522 +      catch(e){}
 18.1523 +    }
 18.1524 +  }
 18.1525 +
 18.1526 +  function clickInGutter(cm, e) {
 18.1527 +    var display = cm.display;
 18.1528 +    try { var mX = e.clientX, mY = e.clientY; }
 18.1529 +    catch(e) { return false; }
 18.1530 +
 18.1531 +    if (mX >= Math.floor(display.gutters.getBoundingClientRect().right)) return false;
 18.1532 +    e_preventDefault(e);
 18.1533 +    if (!hasHandler(cm, "gutterClick")) return true;
 18.1534 +
 18.1535 +    var lineBox = display.lineDiv.getBoundingClientRect();
 18.1536 +    if (mY > lineBox.bottom) return true;
 18.1537 +    mY -= lineBox.top - display.viewOffset;
 18.1538 +
 18.1539 +    for (var i = 0; i < cm.options.gutters.length; ++i) {
 18.1540 +      var g = display.gutters.childNodes[i];
 18.1541 +      if (g && g.getBoundingClientRect().right >= mX) {
 18.1542 +        var line = lineAtHeight(cm.view.doc, mY);
 18.1543 +        var gutter = cm.options.gutters[i];
 18.1544 +        signalLater(cm, cm, "gutterClick", cm, line, gutter, e);
 18.1545 +        break;
 18.1546 +      }
 18.1547 +    }
 18.1548 +    return true;
 18.1549 +  }
 18.1550 +
 18.1551 +  function onDragStart(cm, e) {
 18.1552 +    var txt = cm.getSelection();
 18.1553 +    e.dataTransfer.setData("Text", txt);
 18.1554 +
 18.1555 +    // Use dummy image instead of default browsers image.
 18.1556 +    // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
 18.1557 +    if (e.dataTransfer.setDragImage && !safari)
 18.1558 +      e.dataTransfer.setDragImage(elt('img'), 0, 0);
 18.1559 +  }
 18.1560 +
 18.1561 +  function setScrollTop(cm, val) {
 18.1562 +    if (Math.abs(cm.view.scrollTop - val) < 2) return;
 18.1563 +    cm.view.scrollTop = val;
 18.1564 +    if (!gecko) updateDisplay(cm, [], val);
 18.1565 +    if (cm.display.scroller.scrollTop != val) cm.display.scroller.scrollTop = val;
 18.1566 +    if (cm.display.scrollbarV.scrollTop != val) cm.display.scrollbarV.scrollTop = val;
 18.1567 +    if (gecko) updateDisplay(cm, []);
 18.1568 +  }
 18.1569 +  function setScrollLeft(cm, val, isScroller) {
 18.1570 +    if (isScroller ? val == cm.view.scrollLeft : Math.abs(cm.view.scrollLeft - val) < 2) return;
 18.1571 +    cm.view.scrollLeft = val;
 18.1572 +    alignHorizontally(cm);
 18.1573 +    if (cm.display.scroller.scrollLeft != val) cm.display.scroller.scrollLeft = val;
 18.1574 +    if (cm.display.scrollbarH.scrollLeft != val) cm.display.scrollbarH.scrollLeft = val;
 18.1575 +  }
 18.1576 +
 18.1577 +  // Since the delta values reported on mouse wheel events are
 18.1578 +  // unstandardized between browsers and even browser versions, and
 18.1579 +  // generally horribly unpredictable, this code starts by measuring
 18.1580 +  // the scroll effect that the first few mouse wheel events have,
 18.1581 +  // and, from that, detects the way it can convert deltas to pixel
 18.1582 +  // offsets afterwards.
 18.1583 +  //
 18.1584 +  // The reason we want to know the amount a wheel event will scroll
 18.1585 +  // is that it gives us a chance to update the display before the
 18.1586 +  // actual scrolling happens, reducing flickering.
 18.1587 +
 18.1588 +  var wheelSamples = 0, wheelDX, wheelDY, wheelStartX, wheelStartY, wheelPixelsPerUnit = null;
 18.1589 +  // Fill in a browser-detected starting value on browsers where we
 18.1590 +  // know one. These don't have to be accurate -- the result of them
 18.1591 +  // being wrong would just be a slight flicker on the first wheel
 18.1592 +  // scroll (if it is large enough).
 18.1593 +  if (ie) wheelPixelsPerUnit = -.53;
 18.1594 +  else if (gecko) wheelPixelsPerUnit = 15;
 18.1595 +  else if (chrome) wheelPixelsPerUnit = -.7;
 18.1596 +  else if (safari) wheelPixelsPerUnit = -1/3;
 18.1597 +
 18.1598 +  function onScrollWheel(cm, e) {
 18.1599 +    var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
 18.1600 +    if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail;
 18.1601 +    if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail;
 18.1602 +    else if (dy == null) dy = e.wheelDelta;
 18.1603 +
 18.1604 +    // Webkit browsers on OS X abort momentum scrolls when the target
 18.1605 +    // of the scroll event is removed from the scrollable element.
 18.1606 +    // This hack (see related code in patchDisplay) makes sure the
 18.1607 +    // element is kept around.
 18.1608 +    if (dy && mac && webkit) {
 18.1609 +      for (var cur = e.target; cur != scroll; cur = cur.parentNode) {
 18.1610 +        if (cur.lineObj) {
 18.1611 +          cm.display.currentWheelTarget = cur;
 18.1612 +          break;
 18.1613 +        }
 18.1614 +      }
 18.1615 +    }
 18.1616 +
 18.1617 +    var scroll = cm.display.scroller;
 18.1618 +    // On some browsers, horizontal scrolling will cause redraws to
 18.1619 +    // happen before the gutter has been realigned, causing it to
 18.1620 +    // wriggle around in a most unseemly way. When we have an
 18.1621 +    // estimated pixels/delta value, we just handle horizontal
 18.1622 +    // scrolling entirely here. It'll be slightly off from native, but
 18.1623 +    // better than glitching out.
 18.1624 +    if (dx && !gecko && !opera && wheelPixelsPerUnit != null) {
 18.1625 +      if (dy)
 18.1626 +        setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
 18.1627 +      setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
 18.1628 +      e_preventDefault(e);
 18.1629 +      wheelStartX = null; // Abort measurement, if in progress
 18.1630 +      return;
 18.1631 +    }
 18.1632 +
 18.1633 +    if (dy && wheelPixelsPerUnit != null) {
 18.1634 +      var pixels = dy * wheelPixelsPerUnit;
 18.1635 +      var top = cm.view.scrollTop, bot = top + cm.display.wrapper.clientHeight;
 18.1636 +      if (pixels < 0) top = Math.max(0, top + pixels - 50);
 18.1637 +      else bot = Math.min(cm.view.doc.height, bot + pixels + 50);
 18.1638 +      updateDisplay(cm, [], {top: top, bottom: bot});
 18.1639 +    }
 18.1640 +
 18.1641 +    if (wheelSamples < 20) {
 18.1642 +      if (wheelStartX == null) {
 18.1643 +        wheelStartX = scroll.scrollLeft; wheelStartY = scroll.scrollTop;
 18.1644 +        wheelDX = dx; wheelDY = dy;
 18.1645 +        setTimeout(function() {
 18.1646 +          if (wheelStartX == null) return;
 18.1647 +          var movedX = scroll.scrollLeft - wheelStartX;
 18.1648 +          var movedY = scroll.scrollTop - wheelStartY;
 18.1649 +          var sample = (movedY && wheelDY && movedY / wheelDY) ||
 18.1650 +            (movedX && wheelDX && movedX / wheelDX);
 18.1651 +          wheelStartX = wheelStartY = null;
 18.1652 +          if (!sample) return;
 18.1653 +          wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
 18.1654 +          ++wheelSamples;
 18.1655 +        }, 200);
 18.1656 +      } else {
 18.1657 +        wheelDX += dx; wheelDY += dy;
 18.1658 +      }
 18.1659 +    }
 18.1660 +  }
 18.1661 +
 18.1662 +  function doHandleBinding(cm, bound, dropShift) {
 18.1663 +    if (typeof bound == "string") {
 18.1664 +      bound = commands[bound];
 18.1665 +      if (!bound) return false;
 18.1666 +    }
 18.1667 +    // Ensure previous input has been read, so that the handler sees a
 18.1668 +    // consistent view of the document
 18.1669 +    if (cm.display.pollingFast && readInput(cm)) cm.display.pollingFast = false;
 18.1670 +    var view = cm.view, prevShift = view.sel.shift;
 18.1671 +    try {
 18.1672 +      if (isReadOnly(cm)) view.suppressEdits = true;
 18.1673 +      if (dropShift) view.sel.shift = false;
 18.1674 +      bound(cm);
 18.1675 +    } catch(e) {
 18.1676 +      if (e != Pass) throw e;
 18.1677 +      return false;
 18.1678 +    } finally {
 18.1679 +      view.sel.shift = prevShift;
 18.1680 +      view.suppressEdits = false;
 18.1681 +    }
 18.1682 +    return true;
 18.1683 +  }
 18.1684 +
 18.1685 +  function allKeyMaps(cm) {
 18.1686 +    var maps = cm.view.keyMaps.slice(0);
 18.1687 +    maps.push(cm.options.keyMap);
 18.1688 +    if (cm.options.extraKeys) maps.unshift(cm.options.extraKeys);
 18.1689 +    return maps;
 18.1690 +  }
 18.1691 +
 18.1692 +  var maybeTransition;
 18.1693 +  function handleKeyBinding(cm, e) {
 18.1694 +    // Handle auto keymap transitions
 18.1695 +    var startMap = getKeyMap(cm.options.keyMap), next = startMap.auto;
 18.1696 +    clearTimeout(maybeTransition);
 18.1697 +    if (next && !isModifierKey(e)) maybeTransition = setTimeout(function() {
 18.1698 +      if (getKeyMap(cm.options.keyMap) == startMap)
 18.1699 +        cm.options.keyMap = (next.call ? next.call(null, cm) : next);
 18.1700 +    }, 50);
 18.1701 +
 18.1702 +    var name = keyNames[e_prop(e, "keyCode")], handled = false;
 18.1703 +    var flipCtrlCmd = mac && (opera || qtwebkit);
 18.1704 +    if (name == null || e.altGraphKey) return false;
 18.1705 +    if (e_prop(e, "altKey")) name = "Alt-" + name;
 18.1706 +    if (e_prop(e, flipCtrlCmd ? "metaKey" : "ctrlKey")) name = "Ctrl-" + name;
 18.1707 +    if (e_prop(e, flipCtrlCmd ? "ctrlKey" : "metaKey")) name = "Cmd-" + name;
 18.1708 +
 18.1709 +    var stopped = false;
 18.1710 +    function stop() { stopped = true; }
 18.1711 +    var keymaps = allKeyMaps(cm);
 18.1712 +
 18.1713 +    if (e_prop(e, "shiftKey")) {
 18.1714 +      handled = lookupKey("Shift-" + name, keymaps,
 18.1715 +                          function(b) {return doHandleBinding(cm, b, true);}, stop)
 18.1716 +        || lookupKey(name, keymaps, function(b) {
 18.1717 +          if (typeof b == "string" && /^go[A-Z]/.test(b)) return doHandleBinding(cm, b);
 18.1718 +        }, stop);
 18.1719 +    } else {
 18.1720 +      handled = lookupKey(name, keymaps,
 18.1721 +                          function(b) { return doHandleBinding(cm, b); }, stop);
 18.1722 +    }
 18.1723 +    if (stopped) handled = false;
 18.1724 +    if (handled) {
 18.1725 +      e_preventDefault(e);
 18.1726 +      restartBlink(cm);
 18.1727 +      if (ie_lt9) { e.oldKeyCode = e.keyCode; e.keyCode = 0; }
 18.1728 +    }
 18.1729 +    return handled;
 18.1730 +  }
 18.1731 +
 18.1732 +  function handleCharBinding(cm, e, ch) {
 18.1733 +    var handled = lookupKey("'" + ch + "'", allKeyMaps(cm),
 18.1734 +                            function(b) { return doHandleBinding(cm, b, true); });
 18.1735 +    if (handled) {
 18.1736 +      e_preventDefault(e);
 18.1737 +      restartBlink(cm);
 18.1738 +    }
 18.1739 +    return handled;
 18.1740 +  }
 18.1741 +
 18.1742 +  var lastStoppedKey = null;
 18.1743 +  function onKeyDown(e) {
 18.1744 +    var cm = this;
 18.1745 +    if (!cm.view.focused) onFocus(cm);
 18.1746 +    if (ie && e.keyCode == 27) { e.returnValue = false; }
 18.1747 +    if (cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
 18.1748 +    var code = e_prop(e, "keyCode");
 18.1749 +    // IE does strange things with escape.
 18.1750 +    cm.view.sel.shift = code == 16 || e_prop(e, "shiftKey");
 18.1751 +    // First give onKeyEvent option a chance to handle this.
 18.1752 +    var handled = handleKeyBinding(cm, e);
 18.1753 +    if (opera) {
 18.1754 +      lastStoppedKey = handled ? code : null;
 18.1755 +      // Opera has no cut event... we try to at least catch the key combo
 18.1756 +      if (!handled && code == 88 && !hasCopyEvent && e_prop(e, mac ? "metaKey" : "ctrlKey"))
 18.1757 +        cm.replaceSelection("");
 18.1758 +    }
 18.1759 +  }
 18.1760 +
 18.1761 +  function onKeyPress(e) {
 18.1762 +    var cm = this;
 18.1763 +    if (cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
 18.1764 +    var keyCode = e_prop(e, "keyCode"), charCode = e_prop(e, "charCode");
 18.1765 +    if (opera && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
 18.1766 +    if (((opera && (!e.which || e.which < 10)) || khtml) && handleKeyBinding(cm, e)) return;
 18.1767 +    var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
 18.1768 +    if (this.options.electricChars && this.view.mode.electricChars &&
 18.1769 +        this.options.smartIndent && !isReadOnly(this) &&
 18.1770 +        this.view.mode.electricChars.indexOf(ch) > -1)
 18.1771 +      setTimeout(operation(cm, function() {indentLine(cm, cm.view.sel.to.line, "smart");}), 75);
 18.1772 +    if (handleCharBinding(cm, e, ch)) return;
 18.1773 +    fastPoll(cm);
 18.1774 +  }
 18.1775 +
 18.1776 +  function onFocus(cm) {
 18.1777 +    if (cm.options.readOnly == "nocursor") return;
 18.1778 +    if (!cm.view.focused) {
 18.1779 +      signal(cm, "focus", cm);
 18.1780 +      cm.view.focused = true;
 18.1781 +      if (cm.display.scroller.className.search(/\bCodeMirror-focused\b/) == -1)
 18.1782 +        cm.display.scroller.className += " CodeMirror-focused";
 18.1783 +      resetInput(cm, true);
 18.1784 +    }
 18.1785 +    slowPoll(cm);
 18.1786 +    restartBlink(cm);
 18.1787 +  }
 18.1788 +  function onBlur(cm) {
 18.1789 +    if (cm.view.focused) {
 18.1790 +      signal(cm, "blur", cm);
 18.1791 +      cm.view.focused = false;
 18.1792 +      cm.display.scroller.className = cm.display.scroller.className.replace(" CodeMirror-focused", "");
 18.1793 +    }
 18.1794 +    clearInterval(cm.display.blinker);
 18.1795 +    setTimeout(function() {if (!cm.view.focused) cm.view.sel.shift = false;}, 150);
 18.1796 +  }
 18.1797 +
 18.1798 +  var detectingSelectAll;
 18.1799 +  function onContextMenu(cm, e) {
 18.1800 +    var display = cm.display, sel = cm.view.sel;
 18.1801 +    var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
 18.1802 +    if (!pos || opera) return; // Opera is difficult.
 18.1803 +    if (posEq(sel.from, sel.to) || posLess(pos, sel.from) || !posLess(pos, sel.to))
 18.1804 +      operation(cm, setSelection)(cm, pos, pos);
 18.1805 +
 18.1806 +    var oldCSS = display.input.style.cssText;
 18.1807 +    display.inputDiv.style.position = "absolute";
 18.1808 +    display.input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) +
 18.1809 +      "px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: white; outline: none;" +
 18.1810 +      "border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
 18.1811 +    focusInput(cm);
 18.1812 +    resetInput(cm, true);
 18.1813 +    // Adds "Select all" to context menu in FF
 18.1814 +    if (posEq(sel.from, sel.to)) display.input.value = display.prevInput = " ";
 18.1815 +
 18.1816 +    function rehide() {
 18.1817 +      display.inputDiv.style.position = "relative";
 18.1818 +      display.input.style.cssText = oldCSS;
 18.1819 +      if (ie_lt9) display.scrollbarV.scrollTop = display.scroller.scrollTop = scrollPos;
 18.1820 +      slowPoll(cm);
 18.1821 +
 18.1822 +      // Try to detect the user choosing select-all 
 18.1823 +      if (display.input.selectionStart != null) {
 18.1824 +        clearTimeout(detectingSelectAll);
 18.1825 +        var extval = display.input.value = " " + (posEq(sel.from, sel.to) ? "" : display.input.value), i = 0;
 18.1826 +        display.prevInput = " ";
 18.1827 +        display.input.selectionStart = 1; display.input.selectionEnd = extval.length;
 18.1828 +        detectingSelectAll = setTimeout(function poll(){
 18.1829 +          if (display.prevInput == " " && display.input.selectionStart == 0)
 18.1830 +            operation(cm, commands.selectAll)(cm);
 18.1831 +          else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500);
 18.1832 +          else resetInput(cm);
 18.1833 +        }, 200);
 18.1834 +      }
 18.1835 +    }
 18.1836 +
 18.1837 +    if (gecko) {
 18.1838 +      e_stop(e);
 18.1839 +      on(window, "mouseup", function mouseup() {
 18.1840 +        off(window, "mouseup", mouseup);
 18.1841 +        setTimeout(rehide, 20);
 18.1842 +      });
 18.1843 +    } else {
 18.1844 +      setTimeout(rehide, 50);
 18.1845 +    }
 18.1846 +  }
 18.1847 +
 18.1848 +  // UPDATING
 18.1849 +
 18.1850 +  // Replace the range from from to to by the strings in newText.
 18.1851 +  // Afterwards, set the selection to selFrom, selTo.
 18.1852 +  function updateDoc(cm, from, to, newText, selUpdate, origin) {
 18.1853 +    // Possibly split or suppress the update based on the presence
 18.1854 +    // of read-only spans in its range.
 18.1855 +    var split = sawReadOnlySpans &&
 18.1856 +      removeReadOnlyRanges(cm.view.doc, from, to);
 18.1857 +    if (split) {
 18.1858 +      for (var i = split.length - 1; i >= 1; --i)
 18.1859 +        updateDocInner(cm, split[i].from, split[i].to, [""], origin);
 18.1860 +      if (split.length)
 18.1861 +        return updateDocInner(cm, split[0].from, split[0].to, newText, selUpdate, origin);
 18.1862 +    } else {
 18.1863 +      return updateDocInner(cm, from, to, newText, selUpdate, origin);
 18.1864 +    }
 18.1865 +  }
 18.1866 +
 18.1867 +  function updateDocInner(cm, from, to, newText, selUpdate, origin) {
 18.1868 +    if (cm.view.suppressEdits) return;
 18.1869 +
 18.1870 +    var view = cm.view, doc = view.doc, old = [];
 18.1871 +    doc.iter(from.line, to.line + 1, function(line) {
 18.1872 +      old.push(newHL(line.text, line.markedSpans));
 18.1873 +    });
 18.1874 +    var startSelFrom = view.sel.from, startSelTo = view.sel.to;
 18.1875 +    var lines = updateMarkedSpans(hlSpans(old[0]), hlSpans(lst(old)), from.ch, to.ch, newText);
 18.1876 +    var retval = updateDocNoUndo(cm, from, to, lines, selUpdate, origin);
 18.1877 +    if (view.history) addChange(cm, from.line, newText.length, old, origin,
 18.1878 +                                startSelFrom, startSelTo, view.sel.from, view.sel.to);
 18.1879 +    return retval;
 18.1880 +  }
 18.1881 +
 18.1882 +  function unredoHelper(cm, type) {
 18.1883 +    var doc = cm.view.doc, hist = cm.view.history;
 18.1884 +    var set = (type == "undo" ? hist.done : hist.undone).pop();
 18.1885 +    if (!set) return;
 18.1886 +    var anti = {events: [], fromBefore: set.fromAfter, toBefore: set.toAfter,
 18.1887 +                fromAfter: set.fromBefore, toAfter: set.toBefore};
 18.1888 +    for (var i = set.events.length - 1; i >= 0; i -= 1) {
 18.1889 +      hist.dirtyCounter += type == "undo" ? -1 : 1;
 18.1890 +      var change = set.events[i];
 18.1891 +      var replaced = [], end = change.start + change.added;
 18.1892 +      doc.iter(change.start, end, function(line) { replaced.push(newHL(line.text, line.markedSpans)); });
 18.1893 +      anti.events.push({start: change.start, added: change.old.length, old: replaced});
 18.1894 +      var selPos = i ? null : {from: set.fromBefore, to: set.toBefore};
 18.1895 +      updateDocNoUndo(cm, {line: change.start, ch: 0}, {line: end - 1, ch: getLine(doc, end-1).text.length},
 18.1896 +                      change.old, selPos, type);
 18.1897 +    }
 18.1898 +    (type == "undo" ? hist.undone : hist.done).push(anti);
 18.1899 +  }
 18.1900 +
 18.1901 +  function updateDocNoUndo(cm, from, to, lines, selUpdate, origin) {
 18.1902 +    var view = cm.view, doc = view.doc, display = cm.display;
 18.1903 +    if (view.suppressEdits) return;
 18.1904 +
 18.1905 +    var nlines = to.line - from.line, firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
 18.1906 +    var recomputeMaxLength = false, checkWidthStart = from.line;
 18.1907 +    if (!cm.options.lineWrapping) {
 18.1908 +      checkWidthStart = lineNo(visualLine(doc, firstLine));
 18.1909 +      doc.iter(checkWidthStart, to.line + 1, function(line) {
 18.1910 +        if (lineLength(doc, line) == view.maxLineLength) {
 18.1911 +          recomputeMaxLength = true;
 18.1912 +          return true;
 18.1913 +        }
 18.1914 +      });
 18.1915 +    }
 18.1916 +
 18.1917 +    var lastHL = lst(lines), th = textHeight(display);
 18.1918 +
 18.1919 +    // First adjust the line structure
 18.1920 +    if (from.ch == 0 && to.ch == 0 && hlText(lastHL) == "") {
 18.1921 +      // This is a whole-line replace. Treated specially to make
 18.1922 +      // sure line objects move the way they are supposed to.
 18.1923 +      var added = [];
 18.1924 +      for (var i = 0, e = lines.length - 1; i < e; ++i)
 18.1925 +        added.push(makeLine(hlText(lines[i]), hlSpans(lines[i]), th));
 18.1926 +      updateLine(cm, lastLine, lastLine.text, hlSpans(lastHL));
 18.1927 +      if (nlines) doc.remove(from.line, nlines, cm);
 18.1928 +      if (added.length) doc.insert(from.line, added);
 18.1929 +    } else if (firstLine == lastLine) {
 18.1930 +      if (lines.length == 1) {
 18.1931 +        updateLine(cm, firstLine, firstLine.text.slice(0, from.ch) + hlText(lines[0]) +
 18.1932 +                   firstLine.text.slice(to.ch), hlSpans(lines[0]));
 18.1933 +      } else {
 18.1934 +        for (var added = [], i = 1, e = lines.length - 1; i < e; ++i)
 18.1935 +          added.push(makeLine(hlText(lines[i]), hlSpans(lines[i]), th));
 18.1936 +        added.push(makeLine(hlText(lastHL) + firstLine.text.slice(to.ch), hlSpans(lastHL), th));
 18.1937 +        updateLine(cm, firstLine, firstLine.text.slice(0, from.ch) + hlText(lines[0]), hlSpans(lines[0]));
 18.1938 +        doc.insert(from.line + 1, added);
 18.1939 +      }
 18.1940 +    } else if (lines.length == 1) {
 18.1941 +      updateLine(cm, firstLine, firstLine.text.slice(0, from.ch) + hlText(lines[0]) +
 18.1942 +                 lastLine.text.slice(to.ch), hlSpans(lines[0]));
 18.1943 +      doc.remove(from.line + 1, nlines, cm);
 18.1944 +    } else {
 18.1945 +      var added = [];
 18.1946 +      updateLine(cm, firstLine, firstLine.text.slice(0, from.ch) + hlText(lines[0]), hlSpans(lines[0]));
 18.1947 +      updateLine(cm, lastLine, hlText(lastHL) + lastLine.text.slice(to.ch), hlSpans(lastHL));
 18.1948 +      for (var i = 1, e = lines.length - 1; i < e; ++i)
 18.1949 +        added.push(makeLine(hlText(lines[i]), hlSpans(lines[i]), th));
 18.1950 +      if (nlines > 1) doc.remove(from.line + 1, nlines - 1, cm);
 18.1951 +      doc.insert(from.line + 1, added);
 18.1952 +    }
 18.1953 +
 18.1954 +    if (cm.options.lineWrapping) {
 18.1955 +      var perLine = Math.max(5, display.scroller.clientWidth / charWidth(display) - 3);
 18.1956 +      doc.iter(from.line, from.line + lines.length, function(line) {
 18.1957 +        if (line.height == 0) return;
 18.1958 +        var guess = (Math.ceil(line.text.length / perLine) || 1) * th;
 18.1959 +        if (guess != line.height) updateLineHeight(line, guess);
 18.1960 +      });
 18.1961 +    } else {
 18.1962 +      doc.iter(checkWidthStart, from.line + lines.length, function(line) {
 18.1963 +        var len = lineLength(doc, line);
 18.1964 +        if (len > view.maxLineLength) {
 18.1965 +          view.maxLine = line;
 18.1966 +          view.maxLineLength = len;
 18.1967 +          view.maxLineChanged = true;
 18.1968 +          recomputeMaxLength = false;
 18.1969 +        }
 18.1970 +      });
 18.1971 +      if (recomputeMaxLength) cm.curOp.updateMaxLine = true;
 18.1972 +    }
 18.1973 +
 18.1974 +    // Adjust frontier, schedule worker
 18.1975 +    view.frontier = Math.min(view.frontier, from.line);
 18.1976 +    startWorker(cm, 400);
 18.1977 +
 18.1978 +    var lendiff = lines.length - nlines - 1;
 18.1979 +    // Remember that these lines changed, for updating the display
 18.1980 +    regChange(cm, from.line, to.line + 1, lendiff);
 18.1981 +    if (hasHandler(cm, "change")) {
 18.1982 +      // Normalize lines to contain only strings, since that's what
 18.1983 +      // the change event handler expects
 18.1984 +      for (var i = 0; i < lines.length; ++i)
 18.1985 +        if (typeof lines[i] != "string") lines[i] = lines[i].text;
 18.1986 +      var changeObj = {from: from, to: to, text: lines, origin: origin};
 18.1987 +      if (cm.curOp.textChanged) {
 18.1988 +        for (var cur = cm.curOp.textChanged; cur.next; cur = cur.next) {}
 18.1989 +        cur.next = changeObj;
 18.1990 +      } else cm.curOp.textChanged = changeObj;
 18.1991 +    }
 18.1992 +
 18.1993 +    // Update the selection
 18.1994 +    var newSelFrom, newSelTo, end = {line: from.line + lines.length - 1,
 18.1995 +                                     ch: hlText(lastHL).length  + (lines.length == 1 ? from.ch : 0)};
 18.1996 +    if (selUpdate && typeof selUpdate != "string") {
 18.1997 +      if (selUpdate.from) { newSelFrom = selUpdate.from; newSelTo = selUpdate.to; }
 18.1998 +      else newSelFrom = newSelTo = selUpdate;
 18.1999 +    } else if (selUpdate == "end") {
 18.2000 +      newSelFrom = newSelTo = end;
 18.2001 +    } else if (selUpdate == "start") {
 18.2002 +      newSelFrom = newSelTo = from;
 18.2003 +    } else if (selUpdate == "around") {
 18.2004 +      newSelFrom = from; newSelTo = end;
 18.2005 +    } else {
 18.2006 +      var adjustPos = function(pos) {
 18.2007 +        if (posLess(pos, from)) return pos;
 18.2008 +        if (!posLess(to, pos)) return end;
 18.2009 +        var line = pos.line + lendiff;
 18.2010 +        var ch = pos.ch;
 18.2011 +        if (pos.line == to.line)
 18.2012 +          ch += hlText(lastHL).length - (to.ch - (to.line == from.line ? from.ch : 0));
 18.2013 +        return {line: line, ch: ch};
 18.2014 +      };
 18.2015 +      newSelFrom = adjustPos(view.sel.from);
 18.2016 +      newSelTo = adjustPos(view.sel.to);
 18.2017 +    }
 18.2018 +    setSelection(cm, newSelFrom, newSelTo, null, true);
 18.2019 +    return end;
 18.2020 +  }
 18.2021 +
 18.2022 +  function replaceRange(cm, code, from, to, origin) {
 18.2023 +    if (!to) to = from;
 18.2024 +    if (posLess(to, from)) { var tmp = to; to = from; from = tmp; }
 18.2025 +    return updateDoc(cm, from, to, splitLines(code), null, origin);
 18.2026 +  }
 18.2027 +
 18.2028 +  // SELECTION
 18.2029 +
 18.2030 +  function posEq(a, b) {return a.line == b.line && a.ch == b.ch;}
 18.2031 +  function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);}
 18.2032 +  function copyPos(x) {return {line: x.line, ch: x.ch};}
 18.2033 +
 18.2034 +  function clipLine(doc, n) {return Math.max(0, Math.min(n, doc.size-1));}
 18.2035 +  function clipPos(doc, pos) {
 18.2036 +    if (pos.line < 0) return {line: 0, ch: 0};
 18.2037 +    if (pos.line >= doc.size) return {line: doc.size-1, ch: getLine(doc, doc.size-1).text.length};
 18.2038 +    var ch = pos.ch, linelen = getLine(doc, pos.line).text.length;
 18.2039 +    if (ch == null || ch > linelen) return {line: pos.line, ch: linelen};
 18.2040 +    else if (ch < 0) return {line: pos.line, ch: 0};
 18.2041 +    else return pos;
 18.2042 +  }
 18.2043 +  function isLine(doc, l) {return l >= 0 && l < doc.size;}
 18.2044 +
 18.2045 +  // If shift is held, this will move the selection anchor. Otherwise,
 18.2046 +  // it'll set the whole selection.
 18.2047 +  function extendSelection(cm, pos, other, bias) {
 18.2048 +    var sel = cm.view.sel;
 18.2049 +    if (sel.shift || sel.extend) {
 18.2050 +      var anchor = sel.anchor;
 18.2051 +      if (other) {
 18.2052 +        var posBefore = posLess(pos, anchor);
 18.2053 +        if (posBefore != posLess(other, anchor)) {
 18.2054 +          anchor = pos;
 18.2055 +          pos = other;
 18.2056 +        } else if (posBefore != posLess(pos, other)) {
 18.2057 +          pos = other;
 18.2058 +        }
 18.2059 +      }
 18.2060 +      setSelection(cm, anchor, pos, bias);
 18.2061 +    } else {
 18.2062 +      setSelection(cm, pos, other || pos, bias);
 18.2063 +    }
 18.2064 +    cm.curOp.userSelChange = true;
 18.2065 +  }
 18.2066 +
 18.2067 +  // Update the selection. Last two args are only used by
 18.2068 +  // updateDoc, since they have to be expressed in the line
 18.2069 +  // numbers before the update.
 18.2070 +  function setSelection(cm, anchor, head, bias, checkAtomic) {
 18.2071 +    cm.view.goalColumn = null;
 18.2072 +    var sel = cm.view.sel;
 18.2073 +    // Skip over atomic spans.
 18.2074 +    if (checkAtomic || !posEq(anchor, sel.anchor))
 18.2075 +      anchor = skipAtomic(cm, anchor, bias, checkAtomic != "push");
 18.2076 +    if (checkAtomic || !posEq(head, sel.head))
 18.2077 +      head = skipAtomic(cm, head, bias, checkAtomic != "push");
 18.2078 +
 18.2079 +    if (posEq(sel.anchor, anchor) && posEq(sel.head, head)) return;
 18.2080 +
 18.2081 +    sel.anchor = anchor; sel.head = head;
 18.2082 +    var inv = posLess(head, anchor);
 18.2083 +    sel.from = inv ? head : anchor;
 18.2084 +    sel.to = inv ? anchor : head;
 18.2085 +
 18.2086 +    cm.curOp.updateInput = true;
 18.2087 +    cm.curOp.selectionChanged = true;
 18.2088 +  }
 18.2089 +
 18.2090 +  function reCheckSelection(cm) {
 18.2091 +    setSelection(cm, cm.view.sel.from, cm.view.sel.to, null, "push");
 18.2092 +  }
 18.2093 +
 18.2094 +  function skipAtomic(cm, pos, bias, mayClear) {
 18.2095 +    var doc = cm.view.doc, flipped = false, curPos = pos;
 18.2096 +    var dir = bias || 1;
 18.2097 +    cm.view.cantEdit = false;
 18.2098 +    search: for (;;) {
 18.2099 +      var line = getLine(doc, curPos.line), toClear;
 18.2100 +      if (line.markedSpans) {
 18.2101 +        for (var i = 0; i < line.markedSpans.length; ++i) {
 18.2102 +          var sp = line.markedSpans[i], m = sp.marker;
 18.2103 +          if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) &&
 18.2104 +              (sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) {
 18.2105 +            if (mayClear && m.clearOnEnter) {
 18.2106 +              (toClear || (toClear = [])).push(m);
 18.2107 +              continue;
 18.2108 +            } else if (!m.atomic) continue;
 18.2109 +            var newPos = m.find()[dir < 0 ? "from" : "to"];
 18.2110 +            if (posEq(newPos, curPos)) {
 18.2111 +              newPos.ch += dir;
 18.2112 +              if (newPos.ch < 0) {
 18.2113 +                if (newPos.line) newPos = clipPos(doc, {line: newPos.line - 1});
 18.2114 +                else newPos = null;
 18.2115 +              } else if (newPos.ch > line.text.length) {
 18.2116 +                if (newPos.line < doc.size - 1) newPos = {line: newPos.line + 1, ch: 0};
 18.2117 +                else newPos = null;
 18.2118 +              }
 18.2119 +              if (!newPos) {
 18.2120 +                if (flipped) {
 18.2121 +                  // Driven in a corner -- no valid cursor position found at all
 18.2122 +                  // -- try again *with* clearing, if we didn't already
 18.2123 +                  if (!mayClear) return skipAtomic(cm, pos, bias, true);
 18.2124 +                  // Otherwise, turn off editing until further notice, and return the start of the doc
 18.2125 +                  cm.view.cantEdit = true;
 18.2126 +                  return {line: 0, ch: 0};
 18.2127 +                }
 18.2128 +                flipped = true; newPos = pos; dir = -dir;
 18.2129 +              }
 18.2130 +            }
 18.2131 +            curPos = newPos;
 18.2132 +            continue search;
 18.2133 +          }
 18.2134 +        }
 18.2135 +        if (toClear) for (var i = 0; i < toClear.length; ++i) toClear[i].clear();
 18.2136 +      }
 18.2137 +      return curPos;
 18.2138 +    }
 18.2139 +  }
 18.2140 +
 18.2141 +  // SCROLLING
 18.2142 +
 18.2143 +  function scrollCursorIntoView(cm) {
 18.2144 +    var view = cm.view;
 18.2145 +    var coords = scrollPosIntoView(cm, view.sel.head);
 18.2146 +    if (!view.focused) return;
 18.2147 +    var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
 18.2148 +    if (coords.top + box.top < 0) doScroll = true;
 18.2149 +    else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
 18.2150 +    if (doScroll != null && !phantom) {
 18.2151 +      var hidden = display.cursor.style.display == "none";
 18.2152 +      if (hidden) {
 18.2153 +        display.cursor.style.display = "";
 18.2154 +        display.cursor.style.left = coords.left + "px";
 18.2155 +        display.cursor.style.top = (coords.top - display.viewOffset) + "px";
 18.2156 +      }
 18.2157 +      display.cursor.scrollIntoView(doScroll);
 18.2158 +      if (hidden) display.cursor.style.display = "none";
 18.2159 +    }
 18.2160 +  }
 18.2161 +
 18.2162 +  function scrollPosIntoView(cm, pos) {
 18.2163 +    for (;;) {
 18.2164 +      var changed = false, coords = cursorCoords(cm, pos);
 18.2165 +      var scrollPos = calculateScrollPos(cm, coords.left, coords.top, coords.left, coords.bottom);
 18.2166 +      var startTop = cm.view.scrollTop, startLeft = cm.view.scrollLeft;
 18.2167 +      if (scrollPos.scrollTop != null) {
 18.2168 +        setScrollTop(cm, scrollPos.scrollTop);
 18.2169 +        if (Math.abs(cm.view.scrollTop - startTop) > 1) changed = true;
 18.2170 +      }
 18.2171 +      if (scrollPos.scrollLeft != null) {
 18.2172 +        setScrollLeft(cm, scrollPos.scrollLeft);
 18.2173 +        if (Math.abs(cm.view.scrollLeft - startLeft) > 1) changed = true;
 18.2174 +      }
 18.2175 +      if (!changed) return coords;
 18.2176 +    }
 18.2177 +  }
 18.2178 +
 18.2179 +  function scrollIntoView(cm, x1, y1, x2, y2) {
 18.2180 +    var scrollPos = calculateScrollPos(cm, x1, y1, x2, y2);
 18.2181 +    if (scrollPos.scrollTop != null) setScrollTop(cm, scrollPos.scrollTop);
 18.2182 +    if (scrollPos.scrollLeft != null) setScrollLeft(cm, scrollPos.scrollLeft);
 18.2183 +  }
 18.2184 +
 18.2185 +  function calculateScrollPos(cm, x1, y1, x2, y2) {
 18.2186 +    var display = cm.display, pt = paddingTop(display);
 18.2187 +    y1 += pt; y2 += pt;
 18.2188 +    var screen = display.scroller.clientHeight - scrollerCutOff, screentop = display.scroller.scrollTop, result = {};
 18.2189 +    var docBottom = cm.view.doc.height + 2 * pt;
 18.2190 +    var atTop = y1 < pt + 10, atBottom = y2 + pt > docBottom - 10;
 18.2191 +    if (y1 < screentop) result.scrollTop = atTop ? 0 : Math.max(0, y1);
 18.2192 +    else if (y2 > screentop + screen) result.scrollTop = (atBottom ? docBottom : y2) - screen;
 18.2193 +
 18.2194 +    var screenw = display.scroller.clientWidth - scrollerCutOff, screenleft = display.scroller.scrollLeft;
 18.2195 +    x1 += display.gutters.offsetWidth; x2 += display.gutters.offsetWidth;
 18.2196 +    var gutterw = display.gutters.offsetWidth;
 18.2197 +    var atLeft = x1 < gutterw + 10;
 18.2198 +    if (x1 < screenleft + gutterw || atLeft) {
 18.2199 +      if (atLeft) x1 = 0;
 18.2200 +      result.scrollLeft = Math.max(0, x1 - 10 - gutterw);
 18.2201 +    } else if (x2 > screenw + screenleft - 3) {
 18.2202 +      result.scrollLeft = x2 + 10 - screenw;
 18.2203 +    }
 18.2204 +    return result;
 18.2205 +  }
 18.2206 +
 18.2207 +  // API UTILITIES
 18.2208 +
 18.2209 +  function indentLine(cm, n, how, aggressive) {
 18.2210 +    var doc = cm.view.doc;
 18.2211 +    if (!how) how = "add";
 18.2212 +    if (how == "smart") {
 18.2213 +      if (!cm.view.mode.indent) how = "prev";
 18.2214 +      else var state = getStateBefore(cm, n);
 18.2215 +    }
 18.2216 +
 18.2217 +    var tabSize = cm.options.tabSize;
 18.2218 +    var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
 18.2219 +    var curSpaceString = line.text.match(/^\s*/)[0], indentation;
 18.2220 +    if (how == "smart") {
 18.2221 +      indentation = cm.view.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
 18.2222 +      if (indentation == Pass) {
 18.2223 +        if (!aggressive) return;
 18.2224 +        how = "prev";
 18.2225 +      }
 18.2226 +    }
 18.2227 +    if (how == "prev") {
 18.2228 +      if (n) indentation = countColumn(getLine(doc, n-1).text, null, tabSize);
 18.2229 +      else indentation = 0;
 18.2230 +    }
 18.2231 +    else if (how == "add") indentation = curSpace + cm.options.indentUnit;
 18.2232 +    else if (how == "subtract") indentation = curSpace - cm.options.indentUnit;
 18.2233 +    indentation = Math.max(0, indentation);
 18.2234 +
 18.2235 +    var indentString = "", pos = 0;
 18.2236 +    if (cm.options.indentWithTabs)
 18.2237 +      for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
 18.2238 +    if (pos < indentation) indentString += spaceStr(indentation - pos);
 18.2239 +
 18.2240 +    if (indentString != curSpaceString)
 18.2241 +      replaceRange(cm, indentString, {line: n, ch: 0}, {line: n, ch: curSpaceString.length}, "input");
 18.2242 +    line.stateAfter = null;
 18.2243 +  }
 18.2244 +
 18.2245 +  function changeLine(cm, handle, op) {
 18.2246 +    var no = handle, line = handle, doc = cm.view.doc;
 18.2247 +    if (typeof handle == "number") line = getLine(doc, clipLine(doc, handle));
 18.2248 +    else no = lineNo(handle);
 18.2249 +    if (no == null) return null;
 18.2250 +    if (op(line, no)) regChange(cm, no, no + 1);
 18.2251 +    else return null;
 18.2252 +    return line;
 18.2253 +  }
 18.2254 +
 18.2255 +  function findPosH(cm, dir, unit, visually) {
 18.2256 +    var doc = cm.view.doc, end = cm.view.sel.head, line = end.line, ch = end.ch;
 18.2257 +    var lineObj = getLine(doc, line);
 18.2258 +    function findNextLine() {
 18.2259 +      var l = line + dir;
 18.2260 +      if (l < 0 || l == doc.size) return false;
 18.2261 +      line = l;
 18.2262 +      return lineObj = getLine(doc, l);
 18.2263 +    }
 18.2264 +    function moveOnce(boundToLine) {
 18.2265 +      var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
 18.2266 +      if (next == null) {
 18.2267 +        if (!boundToLine && findNextLine()) {
 18.2268 +          if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
 18.2269 +          else ch = dir < 0 ? lineObj.text.length : 0;
 18.2270 +        } else return false;
 18.2271 +      } else ch = next;
 18.2272 +      return true;
 18.2273 +    }
 18.2274 +    if (unit == "char") moveOnce();
 18.2275 +    else if (unit == "column") moveOnce(true);
 18.2276 +    else if (unit == "word") {
 18.2277 +      var sawWord = false;
 18.2278 +      for (;;) {
 18.2279 +        if (dir < 0) if (!moveOnce()) break;
 18.2280 +        if (isWordChar(lineObj.text.charAt(ch))) sawWord = true;
 18.2281 +        else if (sawWord) {if (dir < 0) {dir = 1; moveOnce();} break;}
 18.2282 +        if (dir > 0) if (!moveOnce()) break;
 18.2283 +      }
 18.2284 +    }
 18.2285 +    return skipAtomic(cm, {line: line, ch: ch}, dir, true);
 18.2286 +  }
 18.2287 +
 18.2288 +  function findWordAt(line, pos) {
 18.2289 +    var start = pos.ch, end = pos.ch;
 18.2290 +    if (line) {
 18.2291 +      if (pos.after === false || end == line.length) --start; else ++end;
 18.2292 +      var startChar = line.charAt(start);
 18.2293 +      var check = isWordChar(startChar) ? isWordChar :
 18.2294 +        /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);} :
 18.2295 +      function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
 18.2296 +      while (start > 0 && check(line.charAt(start - 1))) --start;
 18.2297 +      while (end < line.length && check(line.charAt(end))) ++end;
 18.2298 +    }
 18.2299 +    return {from: {line: pos.line, ch: start}, to: {line: pos.line, ch: end}};
 18.2300 +  }
 18.2301 +
 18.2302 +  function selectLine(cm, line) {
 18.2303 +    extendSelection(cm, {line: line, ch: 0}, clipPos(cm.view.doc, {line: line + 1, ch: 0}));
 18.2304 +  }
 18.2305 +
 18.2306 +  // PROTOTYPE
 18.2307 +
 18.2308 +  // The publicly visible API. Note that operation(null, f) means
 18.2309 +  // 'wrap f in an operation, performed on its `this` parameter'
 18.2310 +
 18.2311 +  CodeMirror.prototype = {
 18.2312 +    getValue: function(lineSep) {
 18.2313 +      var text = [], doc = this.view.doc;
 18.2314 +      doc.iter(0, doc.size, function(line) { text.push(line.text); });
 18.2315 +      return text.join(lineSep || "\n");
 18.2316 +    },
 18.2317 +
 18.2318 +    setValue: operation(null, function(code) {
 18.2319 +      var doc = this.view.doc, top = {line: 0, ch: 0}, lastLen = getLine(doc, doc.size-1).text.length;
 18.2320 +      updateDocInner(this, top, {line: doc.size - 1, ch: lastLen}, splitLines(code), top, top, "setValue");
 18.2321 +    }),
 18.2322 +
 18.2323 +    getSelection: function(lineSep) { return this.getRange(this.view.sel.from, this.view.sel.to, lineSep); },
 18.2324 +
 18.2325 +    replaceSelection: operation(null, function(code, collapse, origin) {
 18.2326 +      var sel = this.view.sel;
 18.2327 +      updateDoc(this, sel.from, sel.to, splitLines(code), collapse || "around", origin);
 18.2328 +    }),
 18.2329 +
 18.2330 +    focus: function(){window.focus(); focusInput(this); onFocus(this); fastPoll(this);},
 18.2331 +
 18.2332 +    setOption: function(option, value) {
 18.2333 +      var options = this.options, old = options[option];
 18.2334 +      if (options[option] == value && option != "mode") return;
 18.2335 +      options[option] = value;
 18.2336 +      if (optionHandlers.hasOwnProperty(option))
 18.2337 +        operation(this, optionHandlers[option])(this, value, old);
 18.2338 +    },
 18.2339 +
 18.2340 +    getOption: function(option) {return this.options[option];},
 18.2341 +
 18.2342 +    getMode: function() {return this.view.mode;},
 18.2343 +
 18.2344 +    addKeyMap: function(map) {
 18.2345 +      this.view.keyMaps.push(map);
 18.2346 +    },
 18.2347 +
 18.2348 +    removeKeyMap: function(map) {
 18.2349 +      var maps = this.view.keyMaps;
 18.2350 +      for (var i = 0; i < maps.length; ++i)
 18.2351 +        if ((typeof map == "string" ? maps[i].name : maps[i]) == map) {
 18.2352 +          maps.splice(i, 1);
 18.2353 +          return true;
 18.2354 +        }
 18.2355 +    },
 18.2356 +
 18.2357 +    undo: operation(null, function() {unredoHelper(this, "undo");}),
 18.2358 +    redo: operation(null, function() {unredoHelper(this, "redo");}),
 18.2359 +
 18.2360 +    indentLine: operation(null, function(n, dir, aggressive) {
 18.2361 +      if (typeof dir != "string") {
 18.2362 +        if (dir == null) dir = this.options.smartIndent ? "smart" : "prev";
 18.2363 +        else dir = dir ? "add" : "subtract";
 18.2364 +      }
 18.2365 +      if (isLine(this.view.doc, n)) indentLine(this, n, dir, aggressive);
 18.2366 +    }),
 18.2367 +
 18.2368 +    indentSelection: operation(null, function(how) {
 18.2369 +      var sel = this.view.sel;
 18.2370 +      if (posEq(sel.from, sel.to)) return indentLine(this, sel.from.line, how);
 18.2371 +      var e = sel.to.line - (sel.to.ch ? 0 : 1);
 18.2372 +      for (var i = sel.from.line; i <= e; ++i) indentLine(this, i, how);
 18.2373 +    }),
 18.2374 +
 18.2375 +    historySize: function() {
 18.2376 +      var hist = this.view.history;
 18.2377 +      return {undo: hist.done.length, redo: hist.undone.length};
 18.2378 +    },
 18.2379 +
 18.2380 +    clearHistory: function() {this.view.history = makeHistory();},
 18.2381 +
 18.2382 +    markClean: function() {
 18.2383 +      this.view.history.dirtyCounter = 0;
 18.2384 +      this.view.history.lastOp = this.view.history.lastOrigin = null;
 18.2385 +    },
 18.2386 +
 18.2387 +    isClean: function () {return this.view.history.dirtyCounter == 0;},
 18.2388 +      
 18.2389 +    getHistory: function() {
 18.2390 +      var hist = this.view.history;
 18.2391 +      function cp(arr) {
 18.2392 +        for (var i = 0, nw = [], nwelt; i < arr.length; ++i) {
 18.2393 +          var set = arr[i];
 18.2394 +          nw.push({events: nwelt = [], fromBefore: set.fromBefore, toBefore: set.toBefore,
 18.2395 +                   fromAfter: set.fromAfter, toAfter: set.toAfter});
 18.2396 +          for (var j = 0, elt = set.events; j < elt.length; ++j) {
 18.2397 +            var old = [], cur = elt[j];
 18.2398 +            nwelt.push({start: cur.start, added: cur.added, old: old});
 18.2399 +            for (var k = 0; k < cur.old.length; ++k) old.push(hlText(cur.old[k]));
 18.2400 +          }
 18.2401 +        }
 18.2402 +        return nw;
 18.2403 +      }
 18.2404 +      return {done: cp(hist.done), undone: cp(hist.undone)};
 18.2405 +    },
 18.2406 +
 18.2407 +    setHistory: function(histData) {
 18.2408 +      var hist = this.view.history = makeHistory();
 18.2409 +      hist.done = histData.done;
 18.2410 +      hist.undone = histData.undone;
 18.2411 +    },
 18.2412 +
 18.2413 +    // Fetch the parser token for a given character. Useful for hacks
 18.2414 +    // that want to inspect the mode state (say, for completion).
 18.2415 +    getTokenAt: function(pos) {
 18.2416 +      var doc = this.view.doc;
 18.2417 +      pos = clipPos(doc, pos);
 18.2418 +      var state = getStateBefore(this, pos.line), mode = this.view.mode;
 18.2419 +      var line = getLine(doc, pos.line);
 18.2420 +      var stream = new StringStream(line.text, this.options.tabSize);
 18.2421 +      while (stream.pos < pos.ch && !stream.eol()) {
 18.2422 +        stream.start = stream.pos;
 18.2423 +        var style = mode.token(stream, state);
 18.2424 +      }
 18.2425 +      return {start: stream.start,
 18.2426 +              end: stream.pos,
 18.2427 +              string: stream.current(),
 18.2428 +              className: style || null, // Deprecated, use 'type' instead
 18.2429 +              type: style || null,
 18.2430 +              state: state};
 18.2431 +    },
 18.2432 +
 18.2433 +    getStateAfter: function(line) {
 18.2434 +      var doc = this.view.doc;
 18.2435 +      line = clipLine(doc, line == null ? doc.size - 1: line);
 18.2436 +      return getStateBefore(this, line + 1);
 18.2437 +    },
 18.2438 +
 18.2439 +    cursorCoords: function(start, mode) {
 18.2440 +      var pos, sel = this.view.sel;
 18.2441 +      if (start == null) pos = sel.head;
 18.2442 +      else if (typeof start == "object") pos = clipPos(this.view.doc, start);
 18.2443 +      else pos = start ? sel.from : sel.to;
 18.2444 +      return cursorCoords(this, pos, mode || "page");
 18.2445 +    },
 18.2446 +
 18.2447 +    charCoords: function(pos, mode) {
 18.2448 +      return charCoords(this, clipPos(this.view.doc, pos), mode || "page");
 18.2449 +    },
 18.2450 +
 18.2451 +    coordsChar: function(coords) {
 18.2452 +      var off = this.display.lineSpace.getBoundingClientRect();
 18.2453 +      return coordsChar(this, coords.left - off.left, coords.top - off.top);
 18.2454 +    },
 18.2455 +
 18.2456 +    defaultTextHeight: function() { return textHeight(this.display); },
 18.2457 +
 18.2458 +    markText: operation(null, function(from, to, options) {
 18.2459 +      return markText(this, clipPos(this.view.doc, from), clipPos(this.view.doc, to),
 18.2460 +                      options, "range");
 18.2461 +    }),
 18.2462 +
 18.2463 +    setBookmark: operation(null, function(pos, widget) {
 18.2464 +      pos = clipPos(this.view.doc, pos);
 18.2465 +      return markText(this, pos, pos, widget ? {replacedWith: widget} : {}, "bookmark");
 18.2466 +    }),
 18.2467 +
 18.2468 +    findMarksAt: function(pos) {
 18.2469 +      var doc = this.view.doc;
 18.2470 +      pos = clipPos(doc, pos);
 18.2471 +      var markers = [], spans = getLine(doc, pos.line).markedSpans;
 18.2472 +      if (spans) for (var i = 0; i < spans.length; ++i) {
 18.2473 +        var span = spans[i];
 18.2474 +        if ((span.from == null || span.from <= pos.ch) &&
 18.2475 +            (span.to == null || span.to >= pos.ch))
 18.2476 +          markers.push(span.marker);
 18.2477 +      }
 18.2478 +      return markers;
 18.2479 +    },
 18.2480 +
 18.2481 +    setGutterMarker: operation(null, function(line, gutterID, value) {
 18.2482 +      return changeLine(this, line, function(line) {
 18.2483 +        var markers = line.gutterMarkers || (line.gutterMarkers = {});
 18.2484 +        markers[gutterID] = value;
 18.2485 +        if (!value && isEmpty(markers)) line.gutterMarkers = null;
 18.2486 +        return true;
 18.2487 +      });
 18.2488 +    }),
 18.2489 +
 18.2490 +    clearGutter: operation(null, function(gutterID) {
 18.2491 +      var i = 0, cm = this, doc = cm.view.doc;
 18.2492 +      doc.iter(0, doc.size, function(line) {
 18.2493 +        if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
 18.2494 +          line.gutterMarkers[gutterID] = null;
 18.2495 +          regChange(cm, i, i + 1);
 18.2496 +          if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null;
 18.2497 +        }
 18.2498 +        ++i;
 18.2499 +      });
 18.2500 +    }),
 18.2501 +
 18.2502 +    addLineClass: operation(null, function(handle, where, cls) {
 18.2503 +      return changeLine(this, handle, function(line) {
 18.2504 +        var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : "wrapClass";
 18.2505 +        if (!line[prop]) line[prop] = cls;
 18.2506 +        else if (new RegExp("\\b" + cls + "\\b").test(line[prop])) return false;
 18.2507 +        else line[prop] += " " + cls;
 18.2508 +        return true;
 18.2509 +      });
 18.2510 +    }),
 18.2511 +
 18.2512 +    removeLineClass: operation(null, function(handle, where, cls) {
 18.2513 +      return changeLine(this, handle, function(line) {
 18.2514 +        var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : "wrapClass";
 18.2515 +        var cur = line[prop];
 18.2516 +        if (!cur) return false;
 18.2517 +        else if (cls == null) line[prop] = null;
 18.2518 +        else {
 18.2519 +          var upd = cur.replace(new RegExp("^" + cls + "\\b\\s*|\\s*\\b" + cls + "\\b"), "");
 18.2520 +          if (upd == cur) return false;
 18.2521 +          line[prop] = upd || null;
 18.2522 +        }
 18.2523 +        return true;
 18.2524 +      });
 18.2525 +    }),
 18.2526 +
 18.2527 +    addLineWidget: operation(null, function(handle, node, options) {
 18.2528 +      var widget = options || {};
 18.2529 +      widget.node = node;
 18.2530 +      if (widget.noHScroll) this.display.alignWidgets = true;
 18.2531 +      changeLine(this, handle, function(line) {
 18.2532 +        (line.widgets || (line.widgets = [])).push(widget);
 18.2533 +        widget.line = line;
 18.2534 +        return true;
 18.2535 +      });
 18.2536 +      return widget;
 18.2537 +    }),
 18.2538 +
 18.2539 +    removeLineWidget: operation(null, function(widget) {
 18.2540 +      var ws = widget.line.widgets, no = lineNo(widget.line);
 18.2541 +      if (no == null) return;
 18.2542 +      for (var i = 0; i < ws.length; ++i) if (ws[i] == widget) ws.splice(i--, 1);
 18.2543 +      regChange(this, no, no + 1);
 18.2544 +    }),
 18.2545 +
 18.2546 +    lineInfo: function(line) {
 18.2547 +      if (typeof line == "number") {
 18.2548 +        if (!isLine(this.view.doc, line)) return null;
 18.2549 +        var n = line;
 18.2550 +        line = getLine(this.view.doc, line);
 18.2551 +        if (!line) return null;
 18.2552 +      } else {
 18.2553 +        var n = lineNo(line);
 18.2554 +        if (n == null) return null;
 18.2555 +      }
 18.2556 +      return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
 18.2557 +              textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
 18.2558 +              widgets: line.widgets};
 18.2559 +    },
 18.2560 +
 18.2561 +    getViewport: function() { return {from: this.display.showingFrom, to: this.display.showingTo};},
 18.2562 +
 18.2563 +    addWidget: function(pos, node, scroll, vert, horiz) {
 18.2564 +      var display = this.display;
 18.2565 +      pos = cursorCoords(this, clipPos(this.view.doc, pos));
 18.2566 +      var top = pos.top, left = pos.left;
 18.2567 +      node.style.position = "absolute";
 18.2568 +      display.sizer.appendChild(node);
 18.2569 +      if (vert == "over") top = pos.top;
 18.2570 +      else if (vert == "near") {
 18.2571 +        var vspace = Math.max(display.wrapper.clientHeight, this.view.doc.height),
 18.2572 +        hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
 18.2573 +        if (pos.bottom + node.offsetHeight > vspace && pos.top > node.offsetHeight)
 18.2574 +          top = pos.top - node.offsetHeight;
 18.2575 +        if (left + node.offsetWidth > hspace)
 18.2576 +          left = hspace - node.offsetWidth;
 18.2577 +      }
 18.2578 +      node.style.top = (top + paddingTop(display)) + "px";
 18.2579 +      node.style.left = node.style.right = "";
 18.2580 +      if (horiz == "right") {
 18.2581 +        left = display.sizer.clientWidth - node.offsetWidth;
 18.2582 +        node.style.right = "0px";
 18.2583 +      } else {
 18.2584 +        if (horiz == "left") left = 0;
 18.2585 +        else if (horiz == "middle") left = (display.sizer.clientWidth - node.offsetWidth) / 2;
 18.2586 +        node.style.left = left + "px";
 18.2587 +      }
 18.2588 +      if (scroll)
 18.2589 +        scrollIntoView(this, left, top, left + node.offsetWidth, top + node.offsetHeight);
 18.2590 +    },
 18.2591 +
 18.2592 +    lineCount: function() {return this.view.doc.size;},
 18.2593 +
 18.2594 +    clipPos: function(pos) {return clipPos(this.view.doc, pos);},
 18.2595 +
 18.2596 +    getCursor: function(start) {
 18.2597 +      var sel = this.view.sel, pos;
 18.2598 +      if (start == null || start == "head") pos = sel.head;
 18.2599 +      else if (start == "anchor") pos = sel.anchor;
 18.2600 +      else if (start == "end" || start === false) pos = sel.to;
 18.2601 +      else pos = sel.from;
 18.2602 +      return copyPos(pos);
 18.2603 +    },
 18.2604 +
 18.2605 +    somethingSelected: function() {return !posEq(this.view.sel.from, this.view.sel.to);},
 18.2606 +
 18.2607 +    setCursor: operation(null, function(line, ch, extend) {
 18.2608 +      var pos = clipPos(this.view.doc, typeof line == "number" ? {line: line, ch: ch || 0} : line);
 18.2609 +      if (extend) extendSelection(this, pos);
 18.2610 +      else setSelection(this, pos, pos);
 18.2611 +    }),
 18.2612 +
 18.2613 +    setSelection: operation(null, function(anchor, head) {
 18.2614 +      var doc = this.view.doc;
 18.2615 +      setSelection(this, clipPos(doc, anchor), clipPos(doc, head || anchor));
 18.2616 +    }),
 18.2617 +
 18.2618 +    extendSelection: operation(null, function(from, to) {
 18.2619 +      var doc = this.view.doc;
 18.2620 +      extendSelection(this, clipPos(doc, from), to && clipPos(doc, to));
 18.2621 +    }),
 18.2622 +
 18.2623 +    setExtending: function(val) {this.view.sel.extend = val;},
 18.2624 +
 18.2625 +    getLine: function(line) {var l = this.getLineHandle(line); return l && l.text;},
 18.2626 +
 18.2627 +    getLineHandle: function(line) {
 18.2628 +      var doc = this.view.doc;
 18.2629 +      if (isLine(doc, line)) return getLine(doc, line);
 18.2630 +    },
 18.2631 +
 18.2632 +    getLineNumber: function(line) {return lineNo(line);},
 18.2633 +
 18.2634 +    setLine: operation(null, function(line, text) {
 18.2635 +      if (isLine(this.view.doc, line))
 18.2636 +        replaceRange(this, text, {line: line, ch: 0}, {line: line, ch: getLine(this.view.doc, line).text.length});
 18.2637 +    }),
 18.2638 +
 18.2639 +    removeLine: operation(null, function(line) {
 18.2640 +      if (isLine(this.view.doc, line))
 18.2641 +        replaceRange(this, "", {line: line, ch: 0}, clipPos(this.view.doc, {line: line+1, ch: 0}));
 18.2642 +    }),
 18.2643 +
 18.2644 +    replaceRange: operation(null, function(code, from, to) {
 18.2645 +      var doc = this.view.doc;
 18.2646 +      from = clipPos(doc, from);
 18.2647 +      to = to ? clipPos(doc, to) : from;
 18.2648 +      return replaceRange(this, code, from, to);
 18.2649 +    }),
 18.2650 +
 18.2651 +    getRange: function(from, to, lineSep) {
 18.2652 +      var doc = this.view.doc;
 18.2653 +      from = clipPos(doc, from); to = clipPos(doc, to);
 18.2654 +      var l1 = from.line, l2 = to.line;
 18.2655 +      if (l1 == l2) return getLine(doc, l1).text.slice(from.ch, to.ch);
 18.2656 +      var code = [getLine(doc, l1).text.slice(from.ch)];
 18.2657 +      doc.iter(l1 + 1, l2, function(line) { code.push(line.text); });
 18.2658 +      code.push(getLine(doc, l2).text.slice(0, to.ch));
 18.2659 +      return code.join(lineSep || "\n");
 18.2660 +    },
 18.2661 +
 18.2662 +    triggerOnKeyDown: operation(null, onKeyDown),
 18.2663 +
 18.2664 +    execCommand: function(cmd) {return commands[cmd](this);},
 18.2665 +
 18.2666 +    // Stuff used by commands, probably not much use to outside code.
 18.2667 +    moveH: operation(null, function(dir, unit) {
 18.2668 +      var sel = this.view.sel, pos = dir < 0 ? sel.from : sel.to;
 18.2669 +      if (sel.shift || sel.extend || posEq(sel.from, sel.to)) pos = findPosH(this, dir, unit, true);
 18.2670 +      extendSelection(this, pos, pos, dir);
 18.2671 +    }),
 18.2672 +
 18.2673 +    deleteH: operation(null, function(dir, unit) {
 18.2674 +      var sel = this.view.sel;
 18.2675 +      if (!posEq(sel.from, sel.to)) replaceRange(this, "", sel.from, sel.to, "delete");
 18.2676 +      else replaceRange(this, "", sel.from, findPosH(this, dir, unit, false), "delete");
 18.2677 +      this.curOp.userSelChange = true;
 18.2678 +    }),
 18.2679 +
 18.2680 +    moveV: operation(null, function(dir, unit) {
 18.2681 +      var view = this.view, doc = view.doc, display = this.display;
 18.2682 +      var cur = view.sel.head, pos = cursorCoords(this, cur, "div");
 18.2683 +      var x = pos.left, y;
 18.2684 +      if (view.goalColumn != null) x = view.goalColumn;
 18.2685 +      if (unit == "page") {
 18.2686 +        var pageSize = Math.min(display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
 18.2687 +        y = pos.top + dir * pageSize;
 18.2688 +      } else if (unit == "line") {
 18.2689 +        y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
 18.2690 +      }
 18.2691 +      do {
 18.2692 +        var target = coordsChar(this, x, y);
 18.2693 +        y += dir * 5;
 18.2694 +      } while (target.outside && (dir < 0 ? y > 0 : y < doc.height));
 18.2695 +
 18.2696 +      if (unit == "page") display.scrollbarV.scrollTop += charCoords(this, target, "div").top - pos.top;
 18.2697 +      extendSelection(this, target, target, dir);
 18.2698 +      view.goalColumn = x;
 18.2699 +    }),
 18.2700 +
 18.2701 +    toggleOverwrite: function() {
 18.2702 +      if (this.view.overwrite = !this.view.overwrite)
 18.2703 +        this.display.cursor.className += " CodeMirror-overwrite";
 18.2704 +      else
 18.2705 +        this.display.cursor.className = this.display.cursor.className.replace(" CodeMirror-overwrite", "");
 18.2706 +    },
 18.2707 +
 18.2708 +    posFromIndex: function(off) {
 18.2709 +      var lineNo = 0, ch, doc = this.view.doc;
 18.2710 +      doc.iter(0, doc.size, function(line) {
 18.2711 +        var sz = line.text.length + 1;
 18.2712 +        if (sz > off) { ch = off; return true; }
 18.2713 +        off -= sz;
 18.2714 +        ++lineNo;
 18.2715 +      });
 18.2716 +      return clipPos(doc, {line: lineNo, ch: ch});
 18.2717 +    },
 18.2718 +    indexFromPos: function (coords) {
 18.2719 +      if (coords.line < 0 || coords.ch < 0) return 0;
 18.2720 +      var index = coords.ch;
 18.2721 +      this.view.doc.iter(0, coords.line, function (line) {
 18.2722 +        index += line.text.length + 1;
 18.2723 +      });
 18.2724 +      return index;
 18.2725 +    },
 18.2726 +
 18.2727 +    scrollTo: function(x, y) {
 18.2728 +      if (x != null) this.display.scrollbarH.scrollLeft = this.display.scroller.scrollLeft = x;
 18.2729 +      if (y != null) this.display.scrollbarV.scrollTop = this.display.scroller.scrollTop = y;
 18.2730 +      updateDisplay(this, []);
 18.2731 +    },
 18.2732 +    getScrollInfo: function() {
 18.2733 +      var scroller = this.display.scroller, co = scrollerCutOff;
 18.2734 +      return {left: scroller.scrollLeft, top: scroller.scrollTop,
 18.2735 +              height: scroller.scrollHeight - co, width: scroller.scrollWidth - co,
 18.2736 +              clientHeight: scroller.clientHeight - co, clientWidth: scroller.clientWidth - co};
 18.2737 +    },
 18.2738 +
 18.2739 +    scrollIntoView: function(pos) {
 18.2740 +      if (typeof pos == "number") pos = {line: pos, ch: 0};
 18.2741 +      pos = pos ? clipPos(this.view.doc, pos) : this.view.sel.head;
 18.2742 +      scrollPosIntoView(this, pos);
 18.2743 +    },
 18.2744 +
 18.2745 +    setSize: function(width, height) {
 18.2746 +      function interpret(val) {
 18.2747 +        return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val;
 18.2748 +      }
 18.2749 +      if (width != null) this.display.wrapper.style.width = interpret(width);
 18.2750 +      if (height != null) this.display.wrapper.style.height = interpret(height);
 18.2751 +      this.refresh();
 18.2752 +    },
 18.2753 +
 18.2754 +    on: function(type, f) {on(this, type, f);},
 18.2755 +    off: function(type, f) {off(this, type, f);},
 18.2756 +
 18.2757 +    operation: function(f){return operation(this, f)();},
 18.2758 +
 18.2759 +    refresh: function() {
 18.2760 +      clearCaches(this);
 18.2761 +      if (this.display.scroller.scrollHeight > this.view.scrollTop)
 18.2762 +        this.display.scrollbarV.scrollTop = this.display.scroller.scrollTop = this.view.scrollTop;
 18.2763 +      updateDisplay(this, true);
 18.2764 +    },
 18.2765 +
 18.2766 +    getInputField: function(){return this.display.input;},
 18.2767 +    getWrapperElement: function(){return this.display.wrapper;},
 18.2768 +    getScrollerElement: function(){return this.display.scroller;},
 18.2769 +    getGutterElement: function(){return this.display.gutters;}
 18.2770 +  };
 18.2771 +
 18.2772 +  // OPTION DEFAULTS
 18.2773 +
 18.2774 +  var optionHandlers = CodeMirror.optionHandlers = {};
 18.2775 +
 18.2776 +  // The default configuration options.
 18.2777 +  var defaults = CodeMirror.defaults = {};
 18.2778 +
 18.2779 +  function option(name, deflt, handle, notOnInit) {
 18.2780 +    CodeMirror.defaults[name] = deflt;
 18.2781 +    if (handle) optionHandlers[name] =
 18.2782 +      notOnInit ? function(cm, val, old) {if (old != Init) handle(cm, val, old);} : handle;
 18.2783 +  }
 18.2784 +
 18.2785 +  var Init = CodeMirror.Init = {toString: function(){return "CodeMirror.Init";}};
 18.2786 +
 18.2787 +  // These two are, on init, called from the constructor because they
 18.2788 +  // have to be initialized before the editor can start at all.
 18.2789 +  option("value", "", function(cm, val) {cm.setValue(val);}, true);
 18.2790 +  option("mode", null, loadMode, true);
 18.2791 +
 18.2792 +  option("indentUnit", 2, loadMode, true);
 18.2793 +  option("indentWithTabs", false);
 18.2794 +  option("smartIndent", true);
 18.2795 +  option("tabSize", 4, function(cm) {
 18.2796 +    loadMode(cm);
 18.2797 +    clearCaches(cm);
 18.2798 +    updateDisplay(cm, true);
 18.2799 +  }, true);
 18.2800 +  option("electricChars", true);
 18.2801 +
 18.2802 +  option("theme", "default", function(cm) {
 18.2803 +    themeChanged(cm);
 18.2804 +    guttersChanged(cm);
 18.2805 +  }, true);
 18.2806 +  option("keyMap", "default", keyMapChanged);
 18.2807 +  option("extraKeys", null);
 18.2808 +
 18.2809 +  option("onKeyEvent", null);
 18.2810 +  option("onDragEvent", null);
 18.2811 +
 18.2812 +  option("lineWrapping", false, wrappingChanged, true);
 18.2813 +  option("gutters", [], function(cm) {
 18.2814 +    setGuttersForLineNumbers(cm.options);
 18.2815 +    guttersChanged(cm);
 18.2816 +  }, true);
 18.2817 +  option("lineNumbers", false, function(cm) {
 18.2818 +    setGuttersForLineNumbers(cm.options);
 18.2819 +    guttersChanged(cm);
 18.2820 +  }, true);
 18.2821 +  option("firstLineNumber", 1, guttersChanged, true);
 18.2822 +  option("lineNumberFormatter", function(integer) {return integer;}, guttersChanged, true);
 18.2823 +  option("showCursorWhenSelecting", false, updateSelection, true);
 18.2824 +  
 18.2825 +  option("readOnly", false, function(cm, val) {
 18.2826 +    if (val == "nocursor") {onBlur(cm); cm.display.input.blur();}
 18.2827 +    else if (!val) resetInput(cm, true);
 18.2828 +  });
 18.2829 +  option("dragDrop", true);
 18.2830 +
 18.2831 +  option("cursorBlinkRate", 530);
 18.2832 +  option("cursorHeight", 1);
 18.2833 +  option("workTime", 100);
 18.2834 +  option("workDelay", 100);
 18.2835 +  option("flattenSpans", true);
 18.2836 +  option("pollInterval", 100);
 18.2837 +  option("undoDepth", 40);
 18.2838 +  option("viewportMargin", 10, function(cm){cm.refresh();}, true);
 18.2839 +
 18.2840 +  option("tabindex", null, function(cm, val) {
 18.2841 +    cm.display.input.tabIndex = val || "";
 18.2842 +  });
 18.2843 +  option("autofocus", null);
 18.2844 +
 18.2845 +  // MODE DEFINITION AND QUERYING
 18.2846 +
 18.2847 +  // Known modes, by name and by MIME
 18.2848 +  var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
 18.2849 +
 18.2850 +  CodeMirror.defineMode = function(name, mode) {
 18.2851 +    if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
 18.2852 +    if (arguments.length > 2) {
 18.2853 +      mode.dependencies = [];
 18.2854 +      for (var i = 2; i < arguments.length; ++i) mode.dependencies.push(arguments[i]);
 18.2855 +    }
 18.2856 +    modes[name] = mode;
 18.2857 +  };
 18.2858 +
 18.2859 +  CodeMirror.defineMIME = function(mime, spec) {
 18.2860 +    mimeModes[mime] = spec;
 18.2861 +  };
 18.2862 +
 18.2863 +  CodeMirror.resolveMode = function(spec) {
 18.2864 +    if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
 18.2865 +      spec = mimeModes[spec];
 18.2866 +    else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec))
 18.2867 +      return CodeMirror.resolveMode("application/xml");
 18.2868 +    if (typeof spec == "string") return {name: spec};
 18.2869 +    else return spec || {name: "null"};
 18.2870 +  };
 18.2871 +
 18.2872 +  CodeMirror.getMode = function(options, spec) {
 18.2873 +    var spec = CodeMirror.resolveMode(spec);
 18.2874 +    var mfactory = modes[spec.name];
 18.2875 +    if (!mfactory) return CodeMirror.getMode(options, "text/plain");
 18.2876 +    var modeObj = mfactory(options, spec);
 18.2877 +    if (modeExtensions.hasOwnProperty(spec.name)) {
 18.2878 +      var exts = modeExtensions[spec.name];
 18.2879 +      for (var prop in exts) {
 18.2880 +        if (!exts.hasOwnProperty(prop)) continue;
 18.2881 +        if (modeObj.hasOwnProperty(prop)) modeObj["_" + prop] = modeObj[prop];
 18.2882 +        modeObj[prop] = exts[prop];
 18.2883 +      }
 18.2884 +    }
 18.2885 +    modeObj.name = spec.name;
 18.2886 +    return modeObj;
 18.2887 +  };
 18.2888 +
 18.2889 +  CodeMirror.defineMode("null", function() {
 18.2890 +    return {token: function(stream) {stream.skipToEnd();}};
 18.2891 +  });
 18.2892 +  CodeMirror.defineMIME("text/plain", "null");
 18.2893 +
 18.2894 +  var modeExtensions = CodeMirror.modeExtensions = {};
 18.2895 +  CodeMirror.extendMode = function(mode, properties) {
 18.2896 +    var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
 18.2897 +    for (var prop in properties) if (properties.hasOwnProperty(prop))
 18.2898 +      exts[prop] = properties[prop];
 18.2899 +  };
 18.2900 +
 18.2901 +  // EXTENSIONS
 18.2902 +
 18.2903 +  CodeMirror.defineExtension = function(name, func) {
 18.2904 +    CodeMirror.prototype[name] = func;
 18.2905 +  };
 18.2906 +
 18.2907 +  CodeMirror.defineOption = option;
 18.2908 +
 18.2909 +  var initHooks = [];
 18.2910 +  CodeMirror.defineInitHook = function(f) {initHooks.push(f);};
 18.2911 +
 18.2912 +  // MODE STATE HANDLING
 18.2913 +
 18.2914 +  // Utility functions for working with state. Exported because modes
 18.2915 +  // sometimes need to do this.
 18.2916 +  function copyState(mode, state) {
 18.2917 +    if (state === true) return state;
 18.2918 +    if (mode.copyState) return mode.copyState(state);
 18.2919 +    var nstate = {};
 18.2920 +    for (var n in state) {
 18.2921 +      var val = state[n];
 18.2922 +      if (val instanceof Array) val = val.concat([]);
 18.2923 +      nstate[n] = val;
 18.2924 +    }
 18.2925 +    return nstate;
 18.2926 +  }
 18.2927 +  CodeMirror.copyState = copyState;
 18.2928 +
 18.2929 +  function startState(mode, a1, a2) {
 18.2930 +    return mode.startState ? mode.startState(a1, a2) : true;
 18.2931 +  }
 18.2932 +  CodeMirror.startState = startState;
 18.2933 +
 18.2934 +  CodeMirror.innerMode = function(mode, state) {
 18.2935 +    while (mode.innerMode) {
 18.2936 +      var info = mode.innerMode(state);
 18.2937 +      state = info.state;
 18.2938 +      mode = info.mode;
 18.2939 +    }
 18.2940 +    return info || {mode: mode, state: state};
 18.2941 +  };
 18.2942 +
 18.2943 +  // STANDARD COMMANDS
 18.2944 +
 18.2945 +  var commands = CodeMirror.commands = {
 18.2946 +    selectAll: function(cm) {cm.setSelection({line: 0, ch: 0}, {line: cm.lineCount() - 1});},
 18.2947 +    killLine: function(cm) {
 18.2948 +      var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
 18.2949 +      if (!sel && cm.getLine(from.line).length == from.ch)
 18.2950 +        cm.replaceRange("", from, {line: from.line + 1, ch: 0}, "delete");
 18.2951 +      else cm.replaceRange("", from, sel ? to : {line: from.line}, "delete");
 18.2952 +    },
 18.2953 +    deleteLine: function(cm) {
 18.2954 +      var l = cm.getCursor().line;
 18.2955 +      cm.replaceRange("", {line: l, ch: 0}, {line: l}, "delete");
 18.2956 +    },
 18.2957 +    undo: function(cm) {cm.undo();},
 18.2958 +    redo: function(cm) {cm.redo();},
 18.2959 +    goDocStart: function(cm) {cm.extendSelection({line: 0, ch: 0});},
 18.2960 +    goDocEnd: function(cm) {cm.extendSelection({line: cm.lineCount() - 1});},
 18.2961 +    goLineStart: function(cm) {
 18.2962 +      cm.extendSelection(lineStart(cm, cm.getCursor().line));
 18.2963 +    },
 18.2964 +    goLineStartSmart: function(cm) {
 18.2965 +      var cur = cm.getCursor(), start = lineStart(cm, cur.line);
 18.2966 +      var line = cm.getLineHandle(start.line);
 18.2967 +      var order = getOrder(line);
 18.2968 +      if (!order || order[0].level == 0) {
 18.2969 +        var firstNonWS = Math.max(0, line.text.search(/\S/));
 18.2970 +        var inWS = cur.line == start.line && cur.ch <= firstNonWS && cur.ch;
 18.2971 +        cm.extendSelection({line: start.line, ch: inWS ? 0 : firstNonWS});
 18.2972 +      } else cm.extendSelection(start);
 18.2973 +    },
 18.2974 +    goLineEnd: function(cm) {
 18.2975 +      cm.extendSelection(lineEnd(cm, cm.getCursor().line));
 18.2976 +    },
 18.2977 +    goLineUp: function(cm) {cm.moveV(-1, "line");},
 18.2978 +    goLineDown: function(cm) {cm.moveV(1, "line");},
 18.2979 +    goPageUp: function(cm) {cm.moveV(-1, "page");},
 18.2980 +    goPageDown: function(cm) {cm.moveV(1, "page");},
 18.2981 +    goCharLeft: function(cm) {cm.moveH(-1, "char");},
 18.2982 +    goCharRight: function(cm) {cm.moveH(1, "char");},
 18.2983 +    goColumnLeft: function(cm) {cm.moveH(-1, "column");},
 18.2984 +    goColumnRight: function(cm) {cm.moveH(1, "column");},
 18.2985 +    goWordLeft: function(cm) {cm.moveH(-1, "word");},
 18.2986 +    goWordRight: function(cm) {cm.moveH(1, "word");},
 18.2987 +    delCharBefore: function(cm) {cm.deleteH(-1, "char");},
 18.2988 +    delCharAfter: function(cm) {cm.deleteH(1, "char");},
 18.2989 +    delWordBefore: function(cm) {cm.deleteH(-1, "word");},
 18.2990 +    delWordAfter: function(cm) {cm.deleteH(1, "word");},
 18.2991 +    indentAuto: function(cm) {cm.indentSelection("smart");},
 18.2992 +    indentMore: function(cm) {cm.indentSelection("add");},
 18.2993 +    indentLess: function(cm) {cm.indentSelection("subtract");},
 18.2994 +    insertTab: function(cm) {cm.replaceSelection("\t", "end", "input");},
 18.2995 +    defaultTab: function(cm) {
 18.2996 +      if (cm.somethingSelected()) cm.indentSelection("add");
 18.2997 +      else cm.replaceSelection("\t", "end", "input");
 18.2998 +    },
 18.2999 +    transposeChars: function(cm) {
 18.3000 +      var cur = cm.getCursor(), line = cm.getLine(cur.line);
 18.3001 +      if (cur.ch > 0 && cur.ch < line.length - 1)
 18.3002 +        cm.replaceRange(line.charAt(cur.ch) + line.charAt(cur.ch - 1),
 18.3003 +                        {line: cur.line, ch: cur.ch - 1}, {line: cur.line, ch: cur.ch + 1});
 18.3004 +    },
 18.3005 +    newlineAndIndent: function(cm) {
 18.3006 +      operation(cm, function() {
 18.3007 +        cm.replaceSelection("\n", "end", "input");
 18.3008 +        cm.indentLine(cm.getCursor().line, null, true);
 18.3009 +      })();
 18.3010 +    },
 18.3011 +    toggleOverwrite: function(cm) {cm.toggleOverwrite();}
 18.3012 +  };
 18.3013 +
 18.3014 +  // STANDARD KEYMAPS
 18.3015 +
 18.3016 +  var keyMap = CodeMirror.keyMap = {};
 18.3017 +  keyMap.basic = {
 18.3018 +    "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
 18.3019 +    "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
 18.3020 +    "Delete": "delCharAfter", "Backspace": "delCharBefore", "Tab": "defaultTab", "Shift-Tab": "indentAuto",
 18.3021 +    "Enter": "newlineAndIndent", "Insert": "toggleOverwrite"
 18.3022 +  };
 18.3023 +  // Note that the save and find-related commands aren't defined by
 18.3024 +  // default. Unknown commands are simply ignored.
 18.3025 +  keyMap.pcDefault = {
 18.3026 +    "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
 18.3027 +    "Ctrl-Home": "goDocStart", "Alt-Up": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Down": "goDocEnd",
 18.3028 +    "Ctrl-Left": "goWordLeft", "Ctrl-Right": "goWordRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
 18.3029 +    "Ctrl-Backspace": "delWordBefore", "Ctrl-Delete": "delWordAfter", "Ctrl-S": "save", "Ctrl-F": "find",
 18.3030 +    "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
 18.3031 +    "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
 18.3032 +    fallthrough: "basic"
 18.3033 +  };
 18.3034 +  keyMap.macDefault = {
 18.3035 +    "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
 18.3036 +    "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goWordLeft",
 18.3037 +    "Alt-Right": "goWordRight", "Cmd-Left": "goLineStart", "Cmd-Right": "goLineEnd", "Alt-Backspace": "delWordBefore",
 18.3038 +    "Ctrl-Alt-Backspace": "delWordAfter", "Alt-Delete": "delWordAfter", "Cmd-S": "save", "Cmd-F": "find",
 18.3039 +    "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
 18.3040 +    "Cmd-[": "indentLess", "Cmd-]": "indentMore",
 18.3041 +    fallthrough: ["basic", "emacsy"]
 18.3042 +  };
 18.3043 +  keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
 18.3044 +  keyMap.emacsy = {
 18.3045 +    "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
 18.3046 +    "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
 18.3047 +    "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
 18.3048 +    "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
 18.3049 +  };
 18.3050 +
 18.3051 +  // KEYMAP DISPATCH
 18.3052 +
 18.3053 +  function getKeyMap(val) {
 18.3054 +    if (typeof val == "string") return keyMap[val];
 18.3055 +    else return val;
 18.3056 +  }
 18.3057 +
 18.3058 +  function lookupKey(name, maps, handle, stop) {
 18.3059 +    function lookup(map) {
 18.3060 +      map = getKeyMap(map);
 18.3061 +      var found = map[name];
 18.3062 +      if (found === false) {
 18.3063 +        if (stop) stop();
 18.3064 +        return true;
 18.3065 +      }
 18.3066 +      if (found != null && handle(found)) return true;
 18.3067 +      if (map.nofallthrough) {
 18.3068 +        if (stop) stop();
 18.3069 +        return true;
 18.3070 +      }
 18.3071 +      var fallthrough = map.fallthrough;
 18.3072 +      if (fallthrough == null) return false;
 18.3073 +      if (Object.prototype.toString.call(fallthrough) != "[object Array]")
 18.3074 +        return lookup(fallthrough);
 18.3075 +      for (var i = 0, e = fallthrough.length; i < e; ++i) {
 18.3076 +        if (lookup(fallthrough[i])) return true;
 18.3077 +      }
 18.3078 +      return false;
 18.3079 +    }
 18.3080 +
 18.3081 +    for (var i = 0; i < maps.length; ++i)
 18.3082 +      if (lookup(maps[i])) return true;
 18.3083 +  }
 18.3084 +  function isModifierKey(event) {
 18.3085 +    var name = keyNames[e_prop(event, "keyCode")];
 18.3086 +    return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
 18.3087 +  }
 18.3088 +  CodeMirror.isModifierKey = isModifierKey;
 18.3089 +
 18.3090 +  // FROMTEXTAREA
 18.3091 +
 18.3092 +  CodeMirror.fromTextArea = function(textarea, options) {
 18.3093 +    if (!options) options = {};
 18.3094 +    options.value = textarea.value;
 18.3095 +    if (!options.tabindex && textarea.tabindex)
 18.3096 +      options.tabindex = textarea.tabindex;
 18.3097 +    // Set autofocus to true if this textarea is focused, or if it has
 18.3098 +    // autofocus and no other element is focused.
 18.3099 +    if (options.autofocus == null) {
 18.3100 +      var hasFocus = document.body;
 18.3101 +      // doc.activeElement occasionally throws on IE
 18.3102 +      try { hasFocus = document.activeElement; } catch(e) {}
 18.3103 +      options.autofocus = hasFocus == textarea ||
 18.3104 +        textarea.getAttribute("autofocus") != null && hasFocus == document.body;
 18.3105 +    }
 18.3106 +
 18.3107 +    function save() {textarea.value = cm.getValue();}
 18.3108 +    if (textarea.form) {
 18.3109 +      // Deplorable hack to make the submit method do the right thing.
 18.3110 +      on(textarea.form, "submit", save);
 18.3111 +      var form = textarea.form, realSubmit = form.submit;
 18.3112 +      try {
 18.3113 +        form.submit = function wrappedSubmit() {
 18.3114 +          save();
 18.3115 +          form.submit = realSubmit;
 18.3116 +          form.submit();
 18.3117 +          form.submit = wrappedSubmit;
 18.3118 +        };
 18.3119 +      } catch(e) {}
 18.3120 +    }
 18.3121 +
 18.3122 +    textarea.style.display = "none";
 18.3123 +    var cm = CodeMirror(function(node) {
 18.3124 +      textarea.parentNode.insertBefore(node, textarea.nextSibling);
 18.3125 +    }, options);
 18.3126 +    cm.save = save;
 18.3127 +    cm.getTextArea = function() { return textarea; };
 18.3128 +    cm.toTextArea = function() {
 18.3129 +      save();
 18.3130 +      textarea.parentNode.removeChild(cm.getWrapperElement());
 18.3131 +      textarea.style.display = "";
 18.3132 +      if (textarea.form) {
 18.3133 +        off(textarea.form, "submit", save);
 18.3134 +        if (typeof textarea.form.submit == "function")
 18.3135 +          textarea.form.submit = realSubmit;
 18.3136 +      }
 18.3137 +    };
 18.3138 +    return cm;
 18.3139 +  };
 18.3140 +
 18.3141 +  // STRING STREAM
 18.3142 +
 18.3143 +  // Fed to the mode parsers, provides helper functions to make
 18.3144 +  // parsers more succinct.
 18.3145 +
 18.3146 +  // The character stream used by a mode's parser.
 18.3147 +  function StringStream(string, tabSize) {
 18.3148 +    this.pos = this.start = 0;
 18.3149 +    this.string = string;
 18.3150 +    this.tabSize = tabSize || 8;
 18.3151 +  }
 18.3152 +
 18.3153 +  StringStream.prototype = {
 18.3154 +    eol: function() {return this.pos >= this.string.length;},
 18.3155 +    sol: function() {return this.pos == 0;},
 18.3156 +    peek: function() {return this.string.charAt(this.pos) || undefined;},
 18.3157 +    next: function() {
 18.3158 +      if (this.pos < this.string.length)
 18.3159 +        return this.string.charAt(this.pos++);
 18.3160 +    },
 18.3161 +    eat: function(match) {
 18.3162 +      var ch = this.string.charAt(this.pos);
 18.3163 +      if (typeof match == "string") var ok = ch == match;
 18.3164 +      else var ok = ch && (match.test ? match.test(ch) : match(ch));
 18.3165 +      if (ok) {++this.pos; return ch;}
 18.3166 +    },
 18.3167 +    eatWhile: function(match) {
 18.3168 +      var start = this.pos;
 18.3169 +      while (this.eat(match)){}
 18.3170 +      return this.pos > start;
 18.3171 +    },
 18.3172 +    eatSpace: function() {
 18.3173 +      var start = this.pos;
 18.3174 +      while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
 18.3175 +      return this.pos > start;
 18.3176 +    },
 18.3177 +    skipToEnd: function() {this.pos = this.string.length;},
 18.3178 +    skipTo: function(ch) {
 18.3179 +      var found = this.string.indexOf(ch, this.pos);
 18.3180 +      if (found > -1) {this.pos = found; return true;}
 18.3181 +    },
 18.3182 +    backUp: function(n) {this.pos -= n;},
 18.3183 +    column: function() {return countColumn(this.string, this.start, this.tabSize);},
 18.3184 +    indentation: function() {return countColumn(this.string, null, this.tabSize);},
 18.3185 +    match: function(pattern, consume, caseInsensitive) {
 18.3186 +      if (typeof pattern == "string") {
 18.3187 +        var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
 18.3188 +        if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
 18.3189 +          if (consume !== false) this.pos += pattern.length;
 18.3190 +          return true;
 18.3191 +        }
 18.3192 +      } else {
 18.3193 +        var match = this.string.slice(this.pos).match(pattern);
 18.3194 +        if (match && match.index > 0) return null;
 18.3195 +        if (match && consume !== false) this.pos += match[0].length;
 18.3196 +        return match;
 18.3197 +      }
 18.3198 +    },
 18.3199 +    current: function(){return this.string.slice(this.start, this.pos);}
 18.3200 +  };
 18.3201 +  CodeMirror.StringStream = StringStream;
 18.3202 +
 18.3203 +  // TEXTMARKERS
 18.3204 +
 18.3205 +  function TextMarker(cm, type) {
 18.3206 +    this.lines = [];
 18.3207 +    this.type = type;
 18.3208 +    this.cm = cm;
 18.3209 +  }
 18.3210 +
 18.3211 +  TextMarker.prototype.clear = function() {
 18.3212 +    if (this.explicitlyCleared) return;
 18.3213 +    startOperation(this.cm);
 18.3214 +    var min = null, max = null;
 18.3215 +    for (var i = 0; i < this.lines.length; ++i) {
 18.3216 +      var line = this.lines[i];
 18.3217 +      var span = getMarkedSpanFor(line.markedSpans, this);
 18.3218 +      if (span.to != null) max = lineNo(line);
 18.3219 +      line.markedSpans = removeMarkedSpan(line.markedSpans, span);
 18.3220 +      if (span.from != null)
 18.3221 +        min = lineNo(line);
 18.3222 +      else if (this.collapsed && !lineIsHidden(line))
 18.3223 +        updateLineHeight(line, textHeight(this.cm.display));
 18.3224 +    }
 18.3225 +    if (min != null) regChange(this.cm, min, max + 1);
 18.3226 +    this.lines.length = 0;
 18.3227 +    this.explicitlyCleared = true;
 18.3228 +    if (this.collapsed && this.cm.view.cantEdit) {
 18.3229 +      this.cm.view.cantEdit = false;
 18.3230 +      reCheckSelection(this.cm);
 18.3231 +    }
 18.3232 +    endOperation(this.cm);
 18.3233 +    signalLater(this.cm, this, "clear");
 18.3234 +  };
 18.3235 +
 18.3236 +  TextMarker.prototype.find = function() {
 18.3237 +    var from, to;
 18.3238 +    for (var i = 0; i < this.lines.length; ++i) {
 18.3239 +      var line = this.lines[i];
 18.3240 +      var span = getMarkedSpanFor(line.markedSpans, this);
 18.3241 +      if (span.from != null || span.to != null) {
 18.3242 +        var found = lineNo(line);
 18.3243 +        if (span.from != null) from = {line: found, ch: span.from};
 18.3244 +        if (span.to != null) to = {line: found, ch: span.to};
 18.3245 +      }
 18.3246 +    }
 18.3247 +    if (this.type == "bookmark") return from;
 18.3248 +    return from && {from: from, to: to};
 18.3249 +  };
 18.3250 +
 18.3251 +  function markText(cm, from, to, options, type) {
 18.3252 +    var doc = cm.view.doc;
 18.3253 +    var marker = new TextMarker(cm, type);
 18.3254 +    if (type == "range" && !posLess(from, to)) return marker;
 18.3255 +    if (options) for (var opt in options) if (options.hasOwnProperty(opt))
 18.3256 +      marker[opt] = options[opt];
 18.3257 +    if (marker.replacedWith) {
 18.3258 +      marker.collapsed = true;
 18.3259 +      marker.replacedWith = elt("span", [marker.replacedWith], "CodeMirror-widget");
 18.3260 +    }
 18.3261 +    if (marker.collapsed) sawCollapsedSpans = true;
 18.3262 +
 18.3263 +    var curLine = from.line, size = 0, collapsedAtStart, collapsedAtEnd;
 18.3264 +    doc.iter(curLine, to.line + 1, function(line) {
 18.3265 +      var span = {from: null, to: null, marker: marker};
 18.3266 +      size += line.text.length;
 18.3267 +      if (curLine == from.line) {span.from = from.ch; size -= from.ch;}
 18.3268 +      if (curLine == to.line) {span.to = to.ch; size -= line.text.length - to.ch;}
 18.3269 +      if (marker.collapsed) {
 18.3270 +        if (curLine == to.line) collapsedAtEnd = collapsedSpanAt(line, to.ch);
 18.3271 +        if (curLine == from.line) collapsedAtStart = collapsedSpanAt(line, from.ch);
 18.3272 +        else updateLineHeight(line, 0);
 18.3273 +      }
 18.3274 +      addMarkedSpan(line, span);
 18.3275 +      if (marker.collapsed && curLine == from.line && lineIsHidden(line))
 18.3276 +        updateLineHeight(line, 0);
 18.3277 +      ++curLine;
 18.3278 +    });
 18.3279 +
 18.3280 +    if (marker.readOnly) {
 18.3281 +      sawReadOnlySpans = true;
 18.3282 +      if (cm.view.history.done.length || cm.view.history.undone.length)
 18.3283 +        cm.clearHistory();
 18.3284 +    }
 18.3285 +    if (marker.collapsed) {
 18.3286 +      if (collapsedAtStart != collapsedAtEnd)
 18.3287 +        throw new Error("Inserting collapsed marker overlapping an existing one");
 18.3288 +      marker.size = size;
 18.3289 +      marker.atomic = true;
 18.3290 +    }
 18.3291 +    if (marker.className || marker.startStyle || marker.endStyle || marker.collapsed)
 18.3292 +      regChange(cm, from.line, to.line + 1);
 18.3293 +    if (marker.atomic) reCheckSelection(cm);
 18.3294 +    return marker;
 18.3295 +  }
 18.3296 +
 18.3297 +  // TEXTMARKER SPANS
 18.3298 +
 18.3299 +  function getMarkedSpanFor(spans, marker) {
 18.3300 +    if (spans) for (var i = 0; i < spans.length; ++i) {
 18.3301 +      var span = spans[i];
 18.3302 +      if (span.marker == marker) return span;
 18.3303 +    }
 18.3304 +  }
 18.3305 +  function removeMarkedSpan(spans, span) {
 18.3306 +    for (var r, i = 0; i < spans.length; ++i)
 18.3307 +      if (spans[i] != span) (r || (r = [])).push(spans[i]);
 18.3308 +    return r;
 18.3309 +  }
 18.3310 +  function addMarkedSpan(line, span) {
 18.3311 +    line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
 18.3312 +    span.marker.lines.push(line);
 18.3313 +  }
 18.3314 +
 18.3315 +  function markedSpansBefore(old, startCh) {
 18.3316 +    if (old) for (var i = 0, nw; i < old.length; ++i) {
 18.3317 +      var span = old[i], marker = span.marker;
 18.3318 +      var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
 18.3319 +      if (startsBefore || marker.type == "bookmark" && span.from == startCh) {
 18.3320 +        var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);
 18.3321 +        (nw || (nw = [])).push({from: span.from,
 18.3322 +                                to: endsAfter ? null : span.to,
 18.3323 +                                marker: marker});
 18.3324 +      }
 18.3325 +    }
 18.3326 +    return nw;
 18.3327 +  }
 18.3328 +
 18.3329 +  function markedSpansAfter(old, startCh, endCh) {
 18.3330 +    if (old) for (var i = 0, nw; i < old.length; ++i) {
 18.3331 +      var span = old[i], marker = span.marker;
 18.3332 +      var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
 18.3333 +      if (endsAfter || marker.type == "bookmark" && span.from == endCh && span.from != startCh) {
 18.3334 +        var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);
 18.3335 +        (nw || (nw = [])).push({from: startsBefore ? null : span.from - endCh,
 18.3336 +                                to: span.to == null ? null : span.to - endCh,
 18.3337 +                                marker: marker});
 18.3338 +      }
 18.3339 +    }
 18.3340 +    return nw;
 18.3341 +  }
 18.3342 +
 18.3343 +  function updateMarkedSpans(oldFirst, oldLast, startCh, endCh, newText) {
 18.3344 +    if (!oldFirst && !oldLast) return newText;
 18.3345 +    // Get the spans that 'stick out' on both sides
 18.3346 +    var first = markedSpansBefore(oldFirst, startCh);
 18.3347 +    var last = markedSpansAfter(oldLast, startCh, endCh);
 18.3348 +
 18.3349 +    // Next, merge those two ends
 18.3350 +    var sameLine = newText.length == 1, offset = lst(newText).length + (sameLine ? startCh : 0);
 18.3351 +    if (first) {
 18.3352 +      // Fix up .to properties of first
 18.3353 +      for (var i = 0; i < first.length; ++i) {
 18.3354 +        var span = first[i];
 18.3355 +        if (span.to == null) {
 18.3356 +          var found = getMarkedSpanFor(last, span.marker);
 18.3357 +          if (!found) span.to = startCh;
 18.3358 +          else if (sameLine) span.to = found.to == null ? null : found.to + offset;
 18.3359 +        }
 18.3360 +      }
 18.3361 +    }
 18.3362 +    if (last) {
 18.3363 +      // Fix up .from in last (or move them into first in case of sameLine)
 18.3364 +      for (var i = 0; i < last.length; ++i) {
 18.3365 +        var span = last[i];
 18.3366 +        if (span.to != null) span.to += offset;
 18.3367 +        if (span.from == null) {
 18.3368 +          var found = getMarkedSpanFor(first, span.marker);
 18.3369 +          if (!found) {
 18.3370 +            span.from = offset;
 18.3371 +            if (sameLine) (first || (first = [])).push(span);
 18.3372 +          }
 18.3373 +        } else {
 18.3374 +          span.from += offset;
 18.3375 +          if (sameLine) (first || (first = [])).push(span);
 18.3376 +        }
 18.3377 +      }
 18.3378 +    }
 18.3379 +
 18.3380 +    var newMarkers = [newHL(newText[0], first)];
 18.3381 +    if (!sameLine) {
 18.3382 +      // Fill gap with whole-line-spans
 18.3383 +      var gap = newText.length - 2, gapMarkers;
 18.3384 +      if (gap > 0 && first)
 18.3385 +        for (var i = 0; i < first.length; ++i)
 18.3386 +          if (first[i].to == null)
 18.3387 +            (gapMarkers || (gapMarkers = [])).push({from: null, to: null, marker: first[i].marker});
 18.3388 +      for (var i = 0; i < gap; ++i)
 18.3389 +        newMarkers.push(newHL(newText[i+1], gapMarkers));
 18.3390 +      newMarkers.push(newHL(lst(newText), last));
 18.3391 +    }
 18.3392 +    return newMarkers;
 18.3393 +  }
 18.3394 +
 18.3395 +  function removeReadOnlyRanges(doc, from, to) {
 18.3396 +    var markers = null;
 18.3397 +    doc.iter(from.line, to.line + 1, function(line) {
 18.3398 +      if (line.markedSpans) for (var i = 0; i < line.markedSpans.length; ++i) {
 18.3399 +        var mark = line.markedSpans[i].marker;
 18.3400 +        if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
 18.3401 +          (markers || (markers = [])).push(mark);
 18.3402 +      }
 18.3403 +    });
 18.3404 +    if (!markers) return null;
 18.3405 +    var parts = [{from: from, to: to}];
 18.3406 +    for (var i = 0; i < markers.length; ++i) {
 18.3407 +      var m = markers[i].find();
 18.3408 +      for (var j = 0; j < parts.length; ++j) {
 18.3409 +        var p = parts[j];
 18.3410 +        if (!posLess(m.from, p.to) || posLess(m.to, p.from)) continue;
 18.3411 +        var newParts = [j, 1];
 18.3412 +        if (posLess(p.from, m.from)) newParts.push({from: p.from, to: m.from});
 18.3413 +        if (posLess(m.to, p.to)) newParts.push({from: m.to, to: p.to});
 18.3414 +        parts.splice.apply(parts, newParts);
 18.3415 +        j += newParts.length - 1;
 18.3416 +      }
 18.3417 +    }
 18.3418 +    return parts;
 18.3419 +  }
 18.3420 +
 18.3421 +  function collapsedSpanAt(line, ch) {
 18.3422 +    var sps = sawCollapsedSpans && line.markedSpans, found;
 18.3423 +    if (sps) for (var sp, i = 0; i < sps.length; ++i) {
 18.3424 +      sp = sps[i];
 18.3425 +      if (!sp.marker.collapsed) continue;
 18.3426 +      if ((sp.from == null || sp.from < ch) &&
 18.3427 +          (sp.to == null || sp.to > ch) &&
 18.3428 +          (!found || found.width < sp.marker.width))
 18.3429 +        found = sp.marker;
 18.3430 +    }
 18.3431 +    return found;
 18.3432 +  }
 18.3433 +  function collapsedSpanAtStart(line) { return collapsedSpanAt(line, -1); }
 18.3434 +  function collapsedSpanAtEnd(line) { return collapsedSpanAt(line, line.text.length + 1); }
 18.3435 +
 18.3436 +  function visualLine(doc, line) {
 18.3437 +    var merged;
 18.3438 +    while (merged = collapsedSpanAtStart(line))
 18.3439 +      line = getLine(doc, merged.find().from.line);
 18.3440 +    return line;
 18.3441 +  }
 18.3442 +
 18.3443 +  function lineIsHidden(line) {
 18.3444 +    var sps = sawCollapsedSpans && line.markedSpans;
 18.3445 +    if (sps) for (var sp, i = 0; i < sps.length; ++i) {
 18.3446 +      sp = sps[i];
 18.3447 +      if (!sp.marker.collapsed) continue;
 18.3448 +      if (sp.from == null) return true;
 18.3449 +      if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(line, sp))
 18.3450 +        return true;
 18.3451 +    }
 18.3452 +  }
 18.3453 +  window.lineIsHidden = lineIsHidden;
 18.3454 +  function lineIsHiddenInner(line, span) {
 18.3455 +    if (span.to == null || span.marker.inclusiveRight && span.to == line.text.length)
 18.3456 +      return true;
 18.3457 +    for (var sp, i = 0; i < line.markedSpans.length; ++i) {
 18.3458 +      sp = line.markedSpans[i];
 18.3459 +      if (sp.marker.collapsed && sp.from == span.to &&
 18.3460 +          (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
 18.3461 +          lineIsHiddenInner(line, sp)) return true;
 18.3462 +    }
 18.3463 +  }
 18.3464 +
 18.3465 +  // hl stands for history-line, a data structure that can be either a
 18.3466 +  // string (line without markers) or a {text, markedSpans} object.
 18.3467 +  function hlText(val) { return typeof val == "string" ? val : val.text; }
 18.3468 +  function hlSpans(val) {
 18.3469 +    if (typeof val == "string") return null;
 18.3470 +    var spans = val.markedSpans, out = null;
 18.3471 +    for (var i = 0; i < spans.length; ++i) {
 18.3472 +      if (spans[i].marker.explicitlyCleared) { if (!out) out = spans.slice(0, i); }
 18.3473 +      else if (out) out.push(spans[i]);
 18.3474 +    }
 18.3475 +    return !out ? spans : out.length ? out : null;
 18.3476 +  }
 18.3477 +  function newHL(text, spans) { return spans ? {text: text, markedSpans: spans} : text; }
 18.3478 +
 18.3479 +  function detachMarkedSpans(line) {
 18.3480 +    var spans = line.markedSpans;
 18.3481 +    if (!spans) return;
 18.3482 +    for (var i = 0; i < spans.length; ++i) {
 18.3483 +      var lines = spans[i].marker.lines;
 18.3484 +      var ix = indexOf(lines, line);
 18.3485 +      lines.splice(ix, 1);
 18.3486 +    }
 18.3487 +    line.markedSpans = null;
 18.3488 +  }
 18.3489 +
 18.3490 +  function attachMarkedSpans(line, spans) {
 18.3491 +    if (!spans) return;
 18.3492 +    for (var i = 0; i < spans.length; ++i)
 18.3493 +      spans[i].marker.lines.push(line);
 18.3494 +    line.markedSpans = spans;
 18.3495 +  }
 18.3496 +
 18.3497 +  // LINE DATA STRUCTURE
 18.3498 +
 18.3499 +  // Line objects. These hold state related to a line, including
 18.3500 +  // highlighting info (the styles array).
 18.3501 +  function makeLine(text, markedSpans, height) {
 18.3502 +    var line = {text: text, height: height};
 18.3503 +    attachMarkedSpans(line, markedSpans);
 18.3504 +    if (lineIsHidden(line)) line.height = 0;
 18.3505 +    return line;
 18.3506 +  }
 18.3507 +
 18.3508 +  function updateLine(cm, line, text, markedSpans) {
 18.3509 +    line.text = text;
 18.3510 +    line.stateAfter = line.styles = null;
 18.3511 +    if (line.order != null) line.order = null;
 18.3512 +    detachMarkedSpans(line);
 18.3513 +    attachMarkedSpans(line, markedSpans);
 18.3514 +    if (lineIsHidden(line)) line.height = 0;
 18.3515 +    else if (!line.height) line.height = textHeight(cm.display);
 18.3516 +    signalLater(cm, line, "change");
 18.3517 +  }
 18.3518 +
 18.3519 +  function cleanUpLine(line) {
 18.3520 +    line.parent = null;
 18.3521 +    detachMarkedSpans(line);
 18.3522 +  }
 18.3523 +
 18.3524 +  // Run the given mode's parser over a line, update the styles
 18.3525 +  // array, which contains alternating fragments of text and CSS
 18.3526 +  // classes.
 18.3527 +  function highlightLine(cm, line, state) {
 18.3528 +    var mode = cm.view.mode, flattenSpans = cm.options.flattenSpans;
 18.3529 +    var changed = !line.styles, pos = 0, curText = "", curStyle = null;
 18.3530 +    var stream = new StringStream(line.text, cm.options.tabSize), st = line.styles || (line.styles = []);
 18.3531 +    if (line.text == "" && mode.blankLine) mode.blankLine(state);
 18.3532 +    while (!stream.eol()) {
 18.3533 +      var style = mode.token(stream, state), substr = stream.current();
 18.3534 +      stream.start = stream.pos;
 18.3535 +      if (!flattenSpans || curStyle != style) {
 18.3536 +        if (curText) {
 18.3537 +          changed = changed || pos >= st.length || curText != st[pos] || curStyle != st[pos+1];
 18.3538 +          st[pos++] = curText; st[pos++] = curStyle;
 18.3539 +        }
 18.3540 +        curText = substr; curStyle = style;
 18.3541 +      } else curText = curText + substr;
 18.3542 +      // Give up when line is ridiculously long
 18.3543 +      if (stream.pos > 5000) break;
 18.3544 +    }
 18.3545 +    if (curText) {
 18.3546 +      changed = changed || pos >= st.length || curText != st[pos] || curStyle != st[pos+1];
 18.3547 +      st[pos++] = curText; st[pos++] = curStyle;
 18.3548 +    }
 18.3549 +    if (stream.pos > 5000) { st[pos++] = line.text.slice(stream.pos); st[pos++] = null; }
 18.3550 +    if (pos != st.length) { st.length = pos; changed = true; }
 18.3551 +    return changed;
 18.3552 +  }
 18.3553 +
 18.3554 +  // Lightweight form of highlight -- proceed over this line and
 18.3555 +  // update state, but don't save a style array.
 18.3556 +  function processLine(cm, line, state) {
 18.3557 +    var mode = cm.view.mode;
 18.3558 +    var stream = new StringStream(line.text, cm.options.tabSize);
 18.3559 +    if (line.text == "" && mode.blankLine) mode.blankLine(state);
 18.3560 +    while (!stream.eol() && stream.pos <= 5000) {
 18.3561 +      mode.token(stream, state);
 18.3562 +      stream.start = stream.pos;
 18.3563 +    }
 18.3564 +  }
 18.3565 +
 18.3566 +  var styleToClassCache = {};
 18.3567 +  function styleToClass(style) {
 18.3568 +    if (!style) return null;
 18.3569 +    return styleToClassCache[style] ||
 18.3570 +      (styleToClassCache[style] = "cm-" + style.replace(/ +/g, " cm-"));
 18.3571 +  }
 18.3572 +
 18.3573 +  function lineContent(cm, realLine, measure) {
 18.3574 +    var merged, line = realLine, lineBefore, sawBefore, simple = true;
 18.3575 +    while (merged = collapsedSpanAtStart(line)) {
 18.3576 +      simple = false;
 18.3577 +      line = getLine(cm.view.doc, merged.find().from.line);
 18.3578 +      if (!lineBefore) lineBefore = line;
 18.3579 +    }
 18.3580 +
 18.3581 +    var builder = {pre: elt("pre"), col: 0, pos: 0, display: !measure,
 18.3582 +                   measure: null, addedOne: false, cm: cm};
 18.3583 +    if (line.textClass) builder.pre.className = line.textClass;
 18.3584 +
 18.3585 +    do {
 18.3586 +      if (!line.styles)
 18.3587 +        highlightLine(cm, line, line.stateAfter = getStateBefore(cm, lineNo(line)));
 18.3588 +      builder.measure = line == realLine && measure;
 18.3589 +      builder.pos = 0;
 18.3590 +      builder.addToken = builder.measure ? buildTokenMeasure : buildToken;
 18.3591 +      if (measure && sawBefore && line != realLine && !builder.addedOne) {
 18.3592 +        measure[0] = builder.pre.appendChild(zeroWidthElement(cm.display.measure));
 18.3593 +        builder.addedOne = true;
 18.3594 +      }
 18.3595 +      var next = insertLineContent(line, builder);
 18.3596 +      sawBefore = line == lineBefore;
 18.3597 +      if (next) {
 18.3598 +        line = getLine(cm.view.doc, next.to.line);
 18.3599 +        simple = false;
 18.3600 +      }
 18.3601 +    } while (next);
 18.3602 +
 18.3603 +    if (measure && !builder.addedOne)
 18.3604 +      measure[0] = builder.pre.appendChild(simple ? elt("span", "\u00a0") : zeroWidthElement(cm.display.measure));
 18.3605 +    if (!builder.pre.firstChild && !lineIsHidden(realLine))
 18.3606 +      builder.pre.appendChild(document.createTextNode("\u00a0"));
 18.3607 +
 18.3608 +    return builder.pre;
 18.3609 +  }
 18.3610 +
 18.3611 +  var tokenSpecialChars = /[\t\u0000-\u0019\u200b\u2028\u2029\uFEFF]/g;
 18.3612 +  function buildToken(builder, text, style, startStyle, endStyle) {
 18.3613 +    if (!text) return;
 18.3614 +    if (!tokenSpecialChars.test(text)) {
 18.3615 +      builder.col += text.length;
 18.3616 +      var content = document.createTextNode(text);
 18.3617 +    } else {
 18.3618 +      var content = document.createDocumentFragment(), pos = 0;
 18.3619 +      while (true) {
 18.3620 +        tokenSpecialChars.lastIndex = pos;
 18.3621 +        var m = tokenSpecialChars.exec(text);
 18.3622 +        var skipped = m ? m.index - pos : text.length - pos;
 18.3623 +        if (skipped) {
 18.3624 +          content.appendChild(document.createTextNode(text.slice(pos, pos + skipped)));
 18.3625 +          builder.col += skipped;
 18.3626 +        }
 18.3627 +        if (!m) break;
 18.3628 +        pos += skipped + 1;
 18.3629 +        if (m[0] == "\t") {
 18.3630 +          var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
 18.3631 +          content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
 18.3632 +          builder.col += tabWidth;
 18.3633 +        } else {
 18.3634 +          var token = elt("span", "\u2022", "cm-invalidchar");
 18.3635 +          token.title = "\\u" + m[0].charCodeAt(0).toString(16);
 18.3636 +          content.appendChild(token);
 18.3637 +          builder.col += 1;
 18.3638 +        }
 18.3639 +      }
 18.3640 +    }
 18.3641 +    if (style || startStyle || endStyle || builder.measure) {
 18.3642 +      var fullStyle = style || "";
 18.3643 +      if (startStyle) fullStyle += startStyle;
 18.3644 +      if (endStyle) fullStyle += endStyle;
 18.3645 +      return builder.pre.appendChild(elt("span", [content], fullStyle));
 18.3646 +    }
 18.3647 +    builder.pre.appendChild(content);
 18.3648 +  }
 18.3649 +
 18.3650 +  function buildTokenMeasure(builder, text, style, startStyle, endStyle) {
 18.3651 +    for (var i = 0; i < text.length; ++i) {
 18.3652 +      if (i && i < text.length - 1 &&
 18.3653 +          builder.cm.options.lineWrapping &&
 18.3654 +          spanAffectsWrapping.test(text.slice(i - 1, i + 1)))
 18.3655 +        builder.pre.appendChild(elt("wbr"));
 18.3656 +      builder.measure[builder.pos++] =
 18.3657 +        buildToken(builder, text.charAt(i), style,
 18.3658 +                   i == 0 && startStyle, i == text.length - 1 && endStyle);
 18.3659 +    }
 18.3660 +    if (text.length) builder.addedOne = true;
 18.3661 +  }
 18.3662 +
 18.3663 +  function buildCollapsedSpan(builder, size, widget) {
 18.3664 +    if (widget) {
 18.3665 +      if (!builder.display) widget = widget.cloneNode(true);
 18.3666 +      builder.pre.appendChild(widget);
 18.3667 +      if (builder.measure && size) {
 18.3668 +        builder.measure[builder.pos] = widget;
 18.3669 +        builder.addedOne = true;
 18.3670 +      }
 18.3671 +    }
 18.3672 +    builder.pos += size;
 18.3673 +  }
 18.3674 +
 18.3675 +  // Outputs a number of spans to make up a line, taking highlighting
 18.3676 +  // and marked text into account.
 18.3677 +  function insertLineContent(line, builder) {
 18.3678 +    var st = line.styles, spans = line.markedSpans;
 18.3679 +    if (!spans) {
 18.3680 +      for (var i = 0; i < st.length; i+=2)
 18.3681 +        builder.addToken(builder, st[i], styleToClass(st[i+1]));
 18.3682 +      return;
 18.3683 +    }
 18.3684 +
 18.3685 +    var allText = line.text, len = allText.length;
 18.3686 +    var pos = 0, i = 0, text = "", style;
 18.3687 +    var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, collapsed;
 18.3688 +    for (;;) {
 18.3689 +      if (nextChange == pos) { // Update current marker set
 18.3690 +        spanStyle = spanEndStyle = spanStartStyle = "";
 18.3691 +        collapsed = null; nextChange = Infinity;
 18.3692 +        var foundBookmark = null;
 18.3693 +        for (var j = 0; j < spans.length; ++j) {
 18.3694 +          var sp = spans[j], m = sp.marker;
 18.3695 +          if (sp.from <= pos && (sp.to == null || sp.to > pos)) {
 18.3696 +            if (sp.to != null && nextChange > sp.to) { nextChange = sp.to; spanEndStyle = ""; }
 18.3697 +            if (m.className) spanStyle += " " + m.className;
 18.3698 +            if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle;
 18.3699 +            if (m.endStyle && sp.to == nextChange) spanEndStyle += " " + m.endStyle;
 18.3700 +            if (m.collapsed && (!collapsed || collapsed.marker.width < m.width))
 18.3701 +              collapsed = sp;
 18.3702 +          } else if (sp.from > pos && nextChange > sp.from) {
 18.3703 +            nextChange = sp.from;
 18.3704 +          }
 18.3705 +          if (m.type == "bookmark" && sp.from == pos && m.replacedWith)
 18.3706 +            foundBookmark = m.replacedWith;
 18.3707 +        }
 18.3708 +        if (collapsed && (collapsed.from || 0) == pos) {
 18.3709 +          buildCollapsedSpan(builder, (collapsed.to == null ? len : collapsed.to) - pos,
 18.3710 +                             collapsed.from != null && collapsed.marker.replacedWith);
 18.3711 +          if (collapsed.to == null) return collapsed.marker.find();
 18.3712 +        }
 18.3713 +        if (foundBookmark && !collapsed) buildCollapsedSpan(builder, 0, foundBookmark);
 18.3714 +      }
 18.3715 +      if (pos >= len) break;
 18.3716 +
 18.3717 +      var upto = Math.min(len, nextChange);
 18.3718 +      while (true) {
 18.3719 +        if (text) {
 18.3720 +          var end = pos + text.length;
 18.3721 +          if (!collapsed) {
 18.3722 +            var tokenText = end > upto ? text.slice(0, upto - pos) : text;
 18.3723 +            builder.addToken(builder, tokenText, style + spanStyle,
 18.3724 +                             spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "");
 18.3725 +          }
 18.3726 +          if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
 18.3727 +          pos = end;
 18.3728 +          spanStartStyle = "";
 18.3729 +        }
 18.3730 +        text = st[i++]; style = styleToClass(st[i++]);
 18.3731 +      }
 18.3732 +    }
 18.3733 +  }
 18.3734 +
 18.3735 +  // DOCUMENT DATA STRUCTURE
 18.3736 +
 18.3737 +  function LeafChunk(lines) {
 18.3738 +    this.lines = lines;
 18.3739 +    this.parent = null;
 18.3740 +    for (var i = 0, e = lines.length, height = 0; i < e; ++i) {
 18.3741 +      lines[i].parent = this;
 18.3742 +      height += lines[i].height;
 18.3743 +    }
 18.3744 +    this.height = height;
 18.3745 +  }
 18.3746 +
 18.3747 +  LeafChunk.prototype = {
 18.3748 +    chunkSize: function() { return this.lines.length; },
 18.3749 +    remove: function(at, n, cm) {
 18.3750 +      for (var i = at, e = at + n; i < e; ++i) {
 18.3751 +        var line = this.lines[i];
 18.3752 +        this.height -= line.height;
 18.3753 +        cleanUpLine(line);
 18.3754 +        signalLater(cm, line, "delete");
 18.3755 +      }
 18.3756 +      this.lines.splice(at, n);
 18.3757 +    },
 18.3758 +    collapse: function(lines) {
 18.3759 +      lines.splice.apply(lines, [lines.length, 0].concat(this.lines));
 18.3760 +    },
 18.3761 +    insertHeight: function(at, lines, height) {
 18.3762 +      this.height += height;
 18.3763 +      this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
 18.3764 +      for (var i = 0, e = lines.length; i < e; ++i) lines[i].parent = this;
 18.3765 +    },
 18.3766 +    iterN: function(at, n, op) {
 18.3767 +      for (var e = at + n; at < e; ++at)
 18.3768 +        if (op(this.lines[at])) return true;
 18.3769 +    }
 18.3770 +  };
 18.3771 +
 18.3772 +  function BranchChunk(children) {
 18.3773 +    this.children = children;
 18.3774 +    var size = 0, height = 0;
 18.3775 +    for (var i = 0, e = children.length; i < e; ++i) {
 18.3776 +      var ch = children[i];
 18.3777 +      size += ch.chunkSize(); height += ch.height;
 18.3778 +      ch.parent = this;
 18.3779 +    }
 18.3780 +    this.size = size;
 18.3781 +    this.height = height;
 18.3782 +    this.parent = null;
 18.3783 +  }
 18.3784 +
 18.3785 +  BranchChunk.prototype = {
 18.3786 +    chunkSize: function() { return this.size; },
 18.3787 +    remove: function(at, n, callbacks) {
 18.3788 +      this.size -= n;
 18.3789 +      for (var i = 0; i < this.children.length; ++i) {
 18.3790 +        var child = this.children[i], sz = child.chunkSize();
 18.3791 +        if (at < sz) {
 18.3792 +          var rm = Math.min(n, sz - at), oldHeight = child.height;
 18.3793 +          child.remove(at, rm, callbacks);
 18.3794 +          this.height -= oldHeight - child.height;
 18.3795 +          if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
 18.3796 +          if ((n -= rm) == 0) break;
 18.3797 +          at = 0;
 18.3798 +        } else at -= sz;
 18.3799 +      }
 18.3800 +      if (this.size - n < 25) {
 18.3801 +        var lines = [];
 18.3802 +        this.collapse(lines);
 18.3803 +        this.children = [new LeafChunk(lines)];
 18.3804 +        this.children[0].parent = this;
 18.3805 +      }
 18.3806 +    },
 18.3807 +    collapse: function(lines) {
 18.3808 +      for (var i = 0, e = this.children.length; i < e; ++i) this.children[i].collapse(lines);
 18.3809 +    },
 18.3810 +    insert: function(at, lines) {
 18.3811 +      var height = 0;
 18.3812 +      for (var i = 0, e = lines.length; i < e; ++i) height += lines[i].height;
 18.3813 +      this.insertHeight(at, lines, height);
 18.3814 +    },
 18.3815 +    insertHeight: function(at, lines, height) {
 18.3816 +      this.size += lines.length;
 18.3817 +      this.height += height;
 18.3818 +      for (var i = 0, e = this.children.length; i < e; ++i) {
 18.3819 +        var child = this.children[i], sz = child.chunkSize();
 18.3820 +        if (at <= sz) {
 18.3821 +          child.insertHeight(at, lines, height);
 18.3822 +          if (child.lines && child.lines.length > 50) {
 18.3823 +            while (child.lines.length > 50) {
 18.3824 +              var spilled = child.lines.splice(child.lines.length - 25, 25);
 18.3825 +              var newleaf = new LeafChunk(spilled);
 18.3826 +              child.height -= newleaf.height;
 18.3827 +              this.children.splice(i + 1, 0, newleaf);
 18.3828 +              newleaf.parent = this;
 18.3829 +            }
 18.3830 +            this.maybeSpill();
 18.3831 +          }
 18.3832 +          break;
 18.3833 +        }
 18.3834 +        at -= sz;
 18.3835 +      }
 18.3836 +    },
 18.3837 +    maybeSpill: function() {
 18.3838 +      if (this.children.length <= 10) return;
 18.3839 +      var me = this;
 18.3840 +      do {
 18.3841 +        var spilled = me.children.splice(me.children.length - 5, 5);
 18.3842 +        var sibling = new BranchChunk(spilled);
 18.3843 +        if (!me.parent) { // Become the parent node
 18.3844 +          var copy = new BranchChunk(me.children);
 18.3845 +          copy.parent = me;
 18.3846 +          me.children = [copy, sibling];
 18.3847 +          me = copy;
 18.3848 +        } else {
 18.3849 +          me.size -= sibling.size;
 18.3850 +          me.height -= sibling.height;
 18.3851 +          var myIndex = indexOf(me.parent.children, me);
 18.3852 +          me.parent.children.splice(myIndex + 1, 0, sibling);
 18.3853 +        }
 18.3854 +        sibling.parent = me.parent;
 18.3855 +      } while (me.children.length > 10);
 18.3856 +      me.parent.maybeSpill();
 18.3857 +    },
 18.3858 +    iter: function(from, to, op) { this.iterN(from, to - from, op); },
 18.3859 +    iterN: function(at, n, op) {
 18.3860 +      for (var i = 0, e = this.children.length; i < e; ++i) {
 18.3861 +        var child = this.children[i], sz = child.chunkSize();
 18.3862 +        if (at < sz) {
 18.3863 +          var used = Math.min(n, sz - at);
 18.3864 +          if (child.iterN(at, used, op)) return true;
 18.3865 +          if ((n -= used) == 0) break;
 18.3866 +          at = 0;
 18.3867 +        } else at -= sz;
 18.3868 +      }
 18.3869 +    }
 18.3870 +  };
 18.3871 +
 18.3872 +  // LINE UTILITIES
 18.3873 +
 18.3874 +  function getLine(chunk, n) {
 18.3875 +    while (!chunk.lines) {
 18.3876 +      for (var i = 0;; ++i) {
 18.3877 +        var child = chunk.children[i], sz = child.chunkSize();
 18.3878 +        if (n < sz) { chunk = child; break; }
 18.3879 +        n -= sz;
 18.3880 +      }
 18.3881 +    }
 18.3882 +    return chunk.lines[n];
 18.3883 +  }
 18.3884 +
 18.3885 +  function updateLineHeight(line, height) {
 18.3886 +    var diff = height - line.height;
 18.3887 +    for (var n = line; n; n = n.parent) n.height += diff;
 18.3888 +  }
 18.3889 +
 18.3890 +  function lineNo(line) {
 18.3891 +    if (line.parent == null) return null;
 18.3892 +    var cur = line.parent, no = indexOf(cur.lines, line);
 18.3893 +    for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
 18.3894 +      for (var i = 0;; ++i) {
 18.3895 +        if (chunk.children[i] == cur) break;
 18.3896 +        no += chunk.children[i].chunkSize();
 18.3897 +      }
 18.3898 +    }
 18.3899 +    return no;
 18.3900 +  }
 18.3901 +
 18.3902 +  function lineAtHeight(chunk, h) {
 18.3903 +    var n = 0;
 18.3904 +    outer: do {
 18.3905 +      for (var i = 0, e = chunk.children.length; i < e; ++i) {
 18.3906 +        var child = chunk.children[i], ch = child.height;
 18.3907 +        if (h < ch) { chunk = child; continue outer; }
 18.3908 +        h -= ch;
 18.3909 +        n += child.chunkSize();
 18.3910 +      }
 18.3911 +      return n;
 18.3912 +    } while (!chunk.lines);
 18.3913 +    for (var i = 0, e = chunk.lines.length; i < e; ++i) {
 18.3914 +      var line = chunk.lines[i], lh = line.height;
 18.3915 +      if (h < lh) break;
 18.3916 +      h -= lh;
 18.3917 +    }
 18.3918 +    return n + i;
 18.3919 +  }
 18.3920 +
 18.3921 +  function heightAtLine(cm, lineObj) {
 18.3922 +    lineObj = visualLine(cm.view.doc, lineObj);
 18.3923 +
 18.3924 +    var h = 0, chunk = lineObj.parent;
 18.3925 +    for (var i = 0; i < chunk.lines.length; ++i) {
 18.3926 +      var line = chunk.lines[i];
 18.3927 +      if (line == lineObj) break;
 18.3928 +      else h += line.height;
 18.3929 +    }
 18.3930 +    for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
 18.3931 +      for (var i = 0; i < p.children.length; ++i) {
 18.3932 +        var cur = p.children[i];
 18.3933 +        if (cur == chunk) break;
 18.3934 +        else h += cur.height;
 18.3935 +      }
 18.3936 +    }
 18.3937 +    return h;
 18.3938 +  }
 18.3939 +
 18.3940 +  function getOrder(line) {
 18.3941 +    var order = line.order;
 18.3942 +    if (order == null) order = line.order = bidiOrdering(line.text);
 18.3943 +    return order;
 18.3944 +  }
 18.3945 +
 18.3946 +  // HISTORY
 18.3947 +
 18.3948 +  function makeHistory() {
 18.3949 +    return {
 18.3950 +      // Arrays of history events. Doing something adds an event to
 18.3951 +      // done and clears undo. Undoing moves events from done to
 18.3952 +      // undone, redoing moves them in the other direction.
 18.3953 +      done: [], undone: [],
 18.3954 +      // Used to track when changes can be merged into a single undo
 18.3955 +      // event
 18.3956 +      lastTime: 0, lastOp: null, lastOrigin: null,
 18.3957 +      // Used by the isClean() method
 18.3958 +      dirtyCounter: 0
 18.3959 +    };
 18.3960 +  }
 18.3961 +
 18.3962 +  function addChange(cm, start, added, old, origin, fromBefore, toBefore, fromAfter, toAfter) {
 18.3963 +    var history = cm.view.history;
 18.3964 +    history.undone.length = 0;
 18.3965 +    var time = +new Date, cur = lst(history.done);
 18.3966 +    
 18.3967 +    if (cur &&
 18.3968 +        (history.lastOp == cm.curOp.id ||
 18.3969 +         history.lastOrigin == origin && (origin == "input" || origin == "delete") &&
 18.3970 +         history.lastTime > time - 600)) {
 18.3971 +      // Merge this change into the last event
 18.3972 +      var last = lst(cur.events);
 18.3973 +      if (last.start > start + old.length || last.start + last.added < start) {
 18.3974 +        // Doesn't intersect with last sub-event, add new sub-event
 18.3975 +        cur.events.push({start: start, added: added, old: old});
 18.3976 +      } else {
 18.3977 +        // Patch up the last sub-event
 18.3978 +        var startBefore = Math.max(0, last.start - start),
 18.3979 +        endAfter = Math.max(0, (start + old.length) - (last.start + last.added));
 18.3980 +        for (var i = startBefore; i > 0; --i) last.old.unshift(old[i - 1]);
 18.3981 +        for (var i = endAfter; i > 0; --i) last.old.push(old[old.length - i]);
 18.3982 +        if (startBefore) last.start = start;
 18.3983 +        last.added += added - (old.length - startBefore - endAfter);
 18.3984 +      }
 18.3985 +      cur.fromAfter = fromAfter; cur.toAfter = toAfter;
 18.3986 +    } else {
 18.3987 +      // Can not be merged, start a new event.
 18.3988 +      cur = {events: [{start: start, added: added, old: old}],
 18.3989 +             fromBefore: fromBefore, toBefore: toBefore, fromAfter: fromAfter, toAfter: toAfter};
 18.3990 +      history.done.push(cur);
 18.3991 +      while (history.done.length > cm.options.undoDepth)
 18.3992 +        history.done.shift();
 18.3993 +      if (history.dirtyCounter < 0)
 18.3994 +          // The user has made a change after undoing past the last clean state. 
 18.3995 +          // We can never get back to a clean state now until markClean() is called.
 18.3996 +          history.dirtyCounter = NaN;
 18.3997 +      else
 18.3998 +        history.dirtyCounter++;
 18.3999 +    }
 18.4000 +    history.lastTime = time;
 18.4001 +    history.lastOp = cm.curOp.id;
 18.4002 +    history.lastOrigin = origin;
 18.4003 +  }
 18.4004 +
 18.4005 +  // EVENT OPERATORS
 18.4006 +
 18.4007 +  function stopMethod() {e_stop(this);}
 18.4008 +  // Ensure an event has a stop method.
 18.4009 +  function addStop(event) {
 18.4010 +    if (!event.stop) event.stop = stopMethod;
 18.4011 +    return event;
 18.4012 +  }
 18.4013 +
 18.4014 +  function e_preventDefault(e) {
 18.4015 +    if (e.preventDefault) e.preventDefault();
 18.4016 +    else e.returnValue = false;
 18.4017 +  }
 18.4018 +  function e_stopPropagation(e) {
 18.4019 +    if (e.stopPropagation) e.stopPropagation();
 18.4020 +    else e.cancelBubble = true;
 18.4021 +  }
 18.4022 +  function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
 18.4023 +  CodeMirror.e_stop = e_stop;
 18.4024 +  CodeMirror.e_preventDefault = e_preventDefault;
 18.4025 +  CodeMirror.e_stopPropagation = e_stopPropagation;
 18.4026 +
 18.4027 +  function e_target(e) {return e.target || e.srcElement;}
 18.4028 +  function e_button(e) {
 18.4029 +    var b = e.which;
 18.4030 +    if (b == null) {
 18.4031 +      if (e.button & 1) b = 1;
 18.4032 +      else if (e.button & 2) b = 3;
 18.4033 +      else if (e.button & 4) b = 2;
 18.4034 +    }
 18.4035 +    if (mac && e.ctrlKey && b == 1) b = 3;
 18.4036 +    return b;
 18.4037 +  }
 18.4038 +
 18.4039 +  // Allow 3rd-party code to override event properties by adding an override
 18.4040 +  // object to an event object.
 18.4041 +  function e_prop(e, prop) {
 18.4042 +    var overridden = e.override && e.override.hasOwnProperty(prop);
 18.4043 +    return overridden ? e.override[prop] : e[prop];
 18.4044 +  }
 18.4045 +
 18.4046 +  // EVENT HANDLING
 18.4047 +
 18.4048 +  function on(emitter, type, f) {
 18.4049 +    if (emitter.addEventListener)
 18.4050 +      emitter.addEventListener(type, f, false);
 18.4051 +    else if (emitter.attachEvent)
 18.4052 +      emitter.attachEvent("on" + type, f);
 18.4053 +    else {
 18.4054 +      var map = emitter._handlers || (emitter._handlers = {});
 18.4055 +      var arr = map[type] || (map[type] = []);
 18.4056 +      arr.push(f);
 18.4057 +    }
 18.4058 +  }
 18.4059 +
 18.4060 +  function off(emitter, type, f) {
 18.4061 +    if (emitter.removeEventListener)
 18.4062 +      emitter.removeEventListener(type, f, false);
 18.4063 +    else if (emitter.detachEvent)
 18.4064 +      emitter.detachEvent("on" + type, f);
 18.4065 +    else {
 18.4066 +      var arr = emitter._handlers && emitter._handlers[type];
 18.4067 +      if (!arr) return;
 18.4068 +      for (var i = 0; i < arr.length; ++i)
 18.4069 +        if (arr[i] == f) { arr.splice(i, 1); break; }
 18.4070 +    }
 18.4071 +  }
 18.4072 +
 18.4073 +  function signal(emitter, type /*, values...*/) {
 18.4074 +    var arr = emitter._handlers && emitter._handlers[type];
 18.4075 +    if (!arr) return;
 18.4076 +    var args = Array.prototype.slice.call(arguments, 2);
 18.4077 +    for (var i = 0; i < arr.length; ++i) arr[i].apply(null, args);
 18.4078 +  }
 18.4079 +
 18.4080 +  function signalLater(cm, emitter, type /*, values...*/) {
 18.4081 +    var arr = emitter._handlers && emitter._handlers[type];
 18.4082 +    if (!arr) return;
 18.4083 +    var args = Array.prototype.slice.call(arguments, 3), flist = cm.curOp && cm.curOp.delayedCallbacks;
 18.4084 +    function bnd(f) {return function(){f.apply(null, args);};};
 18.4085 +    for (var i = 0; i < arr.length; ++i)
 18.4086 +      if (flist) flist.push(bnd(arr[i]));
 18.4087 +      else arr[i].apply(null, args);
 18.4088 +  }
 18.4089 +
 18.4090 +  function hasHandler(emitter, type) {
 18.4091 +    var arr = emitter._handlers && emitter._handlers[type];
 18.4092 +    return arr && arr.length > 0;
 18.4093 +  }
 18.4094 +
 18.4095 +  CodeMirror.on = on; CodeMirror.off = off; CodeMirror.signal = signal;
 18.4096 +
 18.4097 +  // MISC UTILITIES
 18.4098 +
 18.4099 +  // Number of pixels added to scroller and sizer to hide scrollbar
 18.4100 +  var scrollerCutOff = 30;
 18.4101 +
 18.4102 +  // Returned or thrown by various protocols to signal 'I'm not
 18.4103 +  // handling this'.
 18.4104 +  var Pass = CodeMirror.Pass = {toString: function(){return "CodeMirror.Pass";}};
 18.4105 +
 18.4106 +  function Delayed() {this.id = null;}
 18.4107 +  Delayed.prototype = {set: function(ms, f) {clearTimeout(this.id); this.id = setTimeout(f, ms);}};
 18.4108 +
 18.4109 +  // Counts the column offset in a string, taking tabs into account.
 18.4110 +  // Used mostly to find indentation.
 18.4111 +  function countColumn(string, end, tabSize) {
 18.4112 +    if (end == null) {
 18.4113 +      end = string.search(/[^\s\u00a0]/);
 18.4114 +      if (end == -1) end = string.length;
 18.4115 +    }
 18.4116 +    for (var i = 0, n = 0; i < end; ++i) {
 18.4117 +      if (string.charAt(i) == "\t") n += tabSize - (n % tabSize);
 18.4118 +      else ++n;
 18.4119 +    }
 18.4120 +    return n;
 18.4121 +  }
 18.4122 +  CodeMirror.countColumn = countColumn;
 18.4123 +
 18.4124 +  var spaceStrs = [""];
 18.4125 +  function spaceStr(n) {
 18.4126 +    while (spaceStrs.length <= n)
 18.4127 +      spaceStrs.push(lst(spaceStrs) + " ");
 18.4128 +    return spaceStrs[n];
 18.4129 +  }
 18.4130 +
 18.4131 +  function lst(arr) { return arr[arr.length-1]; }
 18.4132 +
 18.4133 +  function selectInput(node) {
 18.4134 +    if (ios) { // Mobile Safari apparently has a bug where select() is broken.
 18.4135 +      node.selectionStart = 0;
 18.4136 +      node.selectionEnd = node.value.length;
 18.4137 +    } else node.select();
 18.4138 +  }
 18.4139 +
 18.4140 +  function indexOf(collection, elt) {
 18.4141 +    if (collection.indexOf) return collection.indexOf(elt);
 18.4142 +    for (var i = 0, e = collection.length; i < e; ++i)
 18.4143 +      if (collection[i] == elt) return i;
 18.4144 +    return -1;
 18.4145 +  }
 18.4146 +
 18.4147 +  function emptyArray(size) {
 18.4148 +    for (var a = [], i = 0; i < size; ++i) a.push(undefined);
 18.4149 +    return a;
 18.4150 +  }
 18.4151 +
 18.4152 +  function bind(f) {
 18.4153 +    var args = Array.prototype.slice.call(arguments, 1);
 18.4154 +    return function(){return f.apply(null, args);};
 18.4155 +  }
 18.4156 +
 18.4157 +  var nonASCIISingleCaseWordChar = /[\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc]/;
 18.4158 +  function isWordChar(ch) {
 18.4159 +    return /\w/.test(ch) || ch > "\x80" &&
 18.4160 +      (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
 18.4161 +  }
 18.4162 +
 18.4163 +  function isEmpty(obj) {
 18.4164 +    var c = 0;
 18.4165 +    for (var n in obj) if (obj.hasOwnProperty(n) && obj[n]) ++c;
 18.4166 +    return !c;
 18.4167 +  }
 18.4168 +
 18.4169 +  var isExtendingChar = /[\u0300-\u036F\u0483-\u0487\u0488-\u0489\u0591-\u05BD\u05BF\u05C1-\u05C2\u05C4-\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7-\u06E8\u06EA-\u06ED\uA66F\uA670-\uA672\uA674-\uA67D\uA69F]/;
 18.4170 +
 18.4171 +  // DOM UTILITIES
 18.4172 +
 18.4173 +  function elt(tag, content, className, style) {
 18.4174 +    var e = document.createElement(tag);
 18.4175 +    if (className) e.className = className;
 18.4176 +    if (style) e.style.cssText = style;
 18.4177 +    if (typeof content == "string") setTextContent(e, content);
 18.4178 +    else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
 18.4179 +    return e;
 18.4180 +  }
 18.4181 +
 18.4182 +  function removeChildren(e) {
 18.4183 +    e.innerHTML = "";
 18.4184 +    return e;
 18.4185 +  }
 18.4186 +
 18.4187 +  function removeChildrenAndAdd(parent, e) {
 18.4188 +    return removeChildren(parent).appendChild(e);
 18.4189 +  }
 18.4190 +
 18.4191 +  function setTextContent(e, str) {
 18.4192 +    if (ie_lt9) {
 18.4193 +      e.innerHTML = "";
 18.4194 +      e.appendChild(document.createTextNode(str));
 18.4195 +    } else e.textContent = str;
 18.4196 +  }
 18.4197 +
 18.4198 +  // FEATURE DETECTION
 18.4199 +
 18.4200 +  // Detect drag-and-drop
 18.4201 +  var dragAndDrop = function() {
 18.4202 +    // There is *some* kind of drag-and-drop support in IE6-8, but I
 18.4203 +    // couldn't get it to work yet.
 18.4204 +    if (ie_lt9) return false;
 18.4205 +    var div = elt('div');
 18.4206 +    return "draggable" in div || "dragDrop" in div;
 18.4207 +  }();
 18.4208 +
 18.4209 +  // For a reason I have yet to figure out, some browsers disallow
 18.4210 +  // word wrapping between certain characters *only* if a new inline
 18.4211 +  // element is started between them. This makes it hard to reliably
 18.4212 +  // measure the position of things, since that requires inserting an
 18.4213 +  // extra span. This terribly fragile set of regexps matches the
 18.4214 +  // character combinations that suffer from this phenomenon on the
 18.4215 +  // various browsers.
 18.4216 +  var spanAffectsWrapping = /^$/; // Won't match any two-character string
 18.4217 +  if (gecko) spanAffectsWrapping = /$'/;
 18.4218 +  else if (safari) spanAffectsWrapping = /\-[^ \-?]|\?[^ !'\"\),.\-\/:;\?\]\}]/;
 18.4219 +  else if (chrome) spanAffectsWrapping = /\-[^ \-\.?]|\?[^ \-\.?\]\}:;!'\"\),\/]|[\.!\"#&%\)*+,:;=>\]|\}~][\(\{\[<]|\$'/;
 18.4220 +
 18.4221 +  var knownScrollbarWidth;
 18.4222 +  function scrollbarWidth(measure) {
 18.4223 +    if (knownScrollbarWidth != null) return knownScrollbarWidth;
 18.4224 +    var test = elt("div", null, null, "width: 50px; height: 50px; overflow-x: scroll");
 18.4225 +    removeChildrenAndAdd(measure, test);
 18.4226 +    if (test.offsetWidth)
 18.4227 +      knownScrollbarWidth = test.offsetHeight - test.clientHeight;
 18.4228 +    return knownScrollbarWidth || 0;
 18.4229 +  }
 18.4230 +
 18.4231 +  var zwspSupported;
 18.4232 +  function zeroWidthElement(measure) {
 18.4233 +    if (zwspSupported == null) {
 18.4234 +      var test = elt("span", "\u200b");
 18.4235 +      removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
 18.4236 +      if (measure.firstChild.offsetHeight != 0)
 18.4237 +        zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !ie_lt8;
 18.4238 +    }
 18.4239 +    if (zwspSupported) return elt("span", "\u200b");
 18.4240 +    else return elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
 18.4241 +  }
 18.4242 +
 18.4243 +  // See if "".split is the broken IE version, if so, provide an
 18.4244 +  // alternative way to split lines.
 18.4245 +  var splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
 18.4246 +    var pos = 0, result = [], l = string.length;
 18.4247 +    while (pos <= l) {
 18.4248 +      var nl = string.indexOf("\n", pos);
 18.4249 +      if (nl == -1) nl = string.length;
 18.4250 +      var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
 18.4251 +      var rt = line.indexOf("\r");
 18.4252 +      if (rt != -1) {
 18.4253 +        result.push(line.slice(0, rt));
 18.4254 +        pos += rt + 1;
 18.4255 +      } else {
 18.4256 +        result.push(line);
 18.4257 +        pos = nl + 1;
 18.4258 +      }
 18.4259 +    }
 18.4260 +    return result;
 18.4261 +  } : function(string){return string.split(/\r\n?|\n/);};
 18.4262 +  CodeMirror.splitLines = splitLines;
 18.4263 +
 18.4264 +  var hasSelection = window.getSelection ? function(te) {
 18.4265 +    try { return te.selectionStart != te.selectionEnd; }
 18.4266 +    catch(e) { return false; }
 18.4267 +  } : function(te) {
 18.4268 +    try {var range = te.ownerDocument.selection.createRange();}
 18.4269 +    catch(e) {}
 18.4270 +    if (!range || range.parentElement() != te) return false;
 18.4271 +    return range.compareEndPoints("StartToEnd", range) != 0;
 18.4272 +  };
 18.4273 +
 18.4274 +  var hasCopyEvent = (function() {
 18.4275 +    var e = elt("div");
 18.4276 +    if ("oncopy" in e) return true;
 18.4277 +    e.setAttribute("oncopy", "return;");
 18.4278 +    return typeof e.oncopy == 'function';
 18.4279 +  })();
 18.4280 +
 18.4281 +  // KEY NAMING
 18.4282 +
 18.4283 +  var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
 18.4284 +                  19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
 18.4285 +                  36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
 18.4286 +                  46: "Delete", 59: ";", 91: "Mod", 92: "Mod", 93: "Mod", 109: "-", 107: "=", 127: "Delete",
 18.4287 +                  186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
 18.4288 +                  221: "]", 222: "'", 63276: "PageUp", 63277: "PageDown", 63275: "End", 63273: "Home",
 18.4289 +                  63234: "Left", 63232: "Up", 63235: "Right", 63233: "Down", 63302: "Insert", 63272: "Delete"};
 18.4290 +  CodeMirror.keyNames = keyNames;
 18.4291 +  (function() {
 18.4292 +    // Number keys
 18.4293 +    for (var i = 0; i < 10; i++) keyNames[i + 48] = String(i);
 18.4294 +    // Alphabetic keys
 18.4295 +    for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
 18.4296 +    // Function keys
 18.4297 +    for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
 18.4298 +  })();
 18.4299 +
 18.4300 +  // BIDI HELPERS
 18.4301 +
 18.4302 +  function iterateBidiSections(order, from, to, f) {
 18.4303 +    if (!order) return f(from, to, "ltr");
 18.4304 +    for (var i = 0; i < order.length; ++i) {
 18.4305 +      var part = order[i];
 18.4306 +      if (part.from < to && part.to > from)
 18.4307 +        f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr");
 18.4308 +    }
 18.4309 +  }
 18.4310 +
 18.4311 +  function bidiLeft(part) { return part.level % 2 ? part.to : part.from; }
 18.4312 +  function bidiRight(part) { return part.level % 2 ? part.from : part.to; }
 18.4313 +
 18.4314 +  function lineLeft(line) { var order = getOrder(line); return order ? bidiLeft(order[0]) : 0; }
 18.4315 +  function lineRight(line) {
 18.4316 +    var order = getOrder(line);
 18.4317 +    if (!order) return line.text.length;
 18.4318 +    return bidiRight(lst(order));
 18.4319 +  }
 18.4320 +
 18.4321 +  function lineStart(cm, lineN) {
 18.4322 +    var line = getLine(cm.view.doc, lineN);
 18.4323 +    var visual = visualLine(cm.view.doc, line);
 18.4324 +    if (visual != line) lineN = lineNo(visual);
 18.4325 +    var order = getOrder(visual);
 18.4326 +    var ch = !order ? 0 : order[0].level % 2 ? lineRight(visual) : lineLeft(visual);
 18.4327 +    return {line: lineN, ch: ch};
 18.4328 +  }
 18.4329 +  function lineEnd(cm, lineNo) {
 18.4330 +    var merged, line;
 18.4331 +    while (merged = collapsedSpanAtEnd(line = getLine(cm.view.doc, lineNo)))
 18.4332 +      lineNo = merged.find().to.line;
 18.4333 +    var order = getOrder(line);
 18.4334 +    var ch = !order ? line.text.length : order[0].level % 2 ? lineLeft(line) : lineRight(line);
 18.4335 +    return {line: lineNo, ch: ch};
 18.4336 +  }
 18.4337 +
 18.4338 +  // This is somewhat involved. It is needed in order to move
 18.4339 +  // 'visually' through bi-directional text -- i.e., pressing left
 18.4340 +  // should make the cursor go left, even when in RTL text. The
 18.4341 +  // tricky part is the 'jumps', where RTL and LTR text touch each
 18.4342 +  // other. This often requires the cursor offset to move more than
 18.4343 +  // one unit, in order to visually move one unit.
 18.4344 +  function moveVisually(line, start, dir, byUnit) {
 18.4345 +    var bidi = getOrder(line);
 18.4346 +    if (!bidi) return moveLogically(line, start, dir, byUnit);
 18.4347 +    var moveOneUnit = byUnit ? function(pos, dir) {
 18.4348 +      do pos += dir;
 18.4349 +      while (pos > 0 && isExtendingChar.test(line.text.charAt(pos)));
 18.4350 +      return pos;
 18.4351 +    } : function(pos, dir) { return pos + dir; };
 18.4352 +    var linedir = bidi[0].level;
 18.4353 +    for (var i = 0; i < bidi.length; ++i) {
 18.4354 +      var part = bidi[i], sticky = part.level % 2 == linedir;
 18.4355 +      if ((part.from < start && part.to > start) ||
 18.4356 +          (sticky && (part.from == start || part.to == start))) break;
 18.4357 +    }
 18.4358 +    var target = moveOneUnit(start, part.level % 2 ? -dir : dir);
 18.4359 +
 18.4360 +    while (target != null) {
 18.4361 +      if (part.level % 2 == linedir) {
 18.4362 +        if (target < part.from || target > part.to) {
 18.4363 +          part = bidi[i += dir];
 18.4364 +          target = part && (dir > 0 == part.level % 2 ? moveOneUnit(part.to, -1) : moveOneUnit(part.from, 1));
 18.4365 +        } else break;
 18.4366 +      } else {
 18.4367 +        if (target == bidiLeft(part)) {
 18.4368 +          part = bidi[--i];
 18.4369 +          target = part && bidiRight(part);
 18.4370 +        } else if (target == bidiRight(part)) {
 18.4371 +          part = bidi[++i];
 18.4372 +          target = part && bidiLeft(part);
 18.4373 +        } else break;
 18.4374 +      }
 18.4375 +    }
 18.4376 +
 18.4377 +    return target < 0 || target > line.text.length ? null : target;
 18.4378 +  }
 18.4379 +
 18.4380 +  function moveLogically(line, start, dir, byUnit) {
 18.4381 +    var target = start + dir;
 18.4382 +    if (byUnit) while (target > 0 && isExtendingChar.test(line.text.charAt(target))) target += dir;
 18.4383 +    return target < 0 || target > line.text.length ? null : target;
 18.4384 +  }
 18.4385 +
 18.4386 +  // Bidirectional ordering algorithm
 18.4387 +  // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
 18.4388 +  // that this (partially) implements.
 18.4389 +
 18.4390 +  // One-char codes used for character types:
 18.4391 +  // L (L):   Left-to-Right
 18.4392 +  // R (R):   Right-to-Left
 18.4393 +  // r (AL):  Right-to-Left Arabic
 18.4394 +  // 1 (EN):  European Number
 18.4395 +  // + (ES):  European Number Separator
 18.4396 +  // % (ET):  European Number Terminator
 18.4397 +  // n (AN):  Arabic Number
 18.4398 +  // , (CS):  Common Number Separator
 18.4399 +  // m (NSM): Non-Spacing Mark
 18.4400 +  // b (BN):  Boundary Neutral
 18.4401 +  // s (B):   Paragraph Separator
 18.4402 +  // t (S):   Segment Separator
 18.4403 +  // w (WS):  Whitespace
 18.4404 +  // N (ON):  Other Neutrals
 18.4405 +
 18.4406 +  // Returns null if characters are ordered as they appear
 18.4407 +  // (left-to-right), or an array of sections ({from, to, level}
 18.4408 +  // objects) in the order in which they occur visually.
 18.4409 +  var bidiOrdering = (function() {
 18.4410 +    // Character types for codepoints 0 to 0xff
 18.4411 +    var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLL";
 18.4412 +    // Character types for codepoints 0x600 to 0x6ff
 18.4413 +    var arabicTypes = "rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmmrrrrrrrrrrrrrrrrrr";
 18.4414 +    function charType(code) {
 18.4415 +      if (code <= 0xff) return lowTypes.charAt(code);
 18.4416 +      else if (0x590 <= code && code <= 0x5f4) return "R";
 18.4417 +      else if (0x600 <= code && code <= 0x6ff) return arabicTypes.charAt(code - 0x600);
 18.4418 +      else if (0x700 <= code && code <= 0x8ac) return "r";
 18.4419 +      else return "L";
 18.4420 +    }
 18.4421 +
 18.4422 +    var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
 18.4423 +    var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
 18.4424 +
 18.4425 +    return function charOrdering(str) {
 18.4426 +      if (!bidiRE.test(str)) return false;
 18.4427 +      var len = str.length, types = [], startType = null;
 18.4428 +      for (var i = 0, type; i < len; ++i) {
 18.4429 +        types.push(type = charType(str.charCodeAt(i)));
 18.4430 +        if (startType == null) {
 18.4431 +          if (type == "L") startType = "L";
 18.4432 +          else if (type == "R" || type == "r") startType = "R";
 18.4433 +        }
 18.4434 +      }
 18.4435 +      if (startType == null) startType = "L";
 18.4436 +
 18.4437 +      // W1. Examine each non-spacing mark (NSM) in the level run, and
 18.4438 +      // change the type of the NSM to the type of the previous
 18.4439 +      // character. If the NSM is at the start of the level run, it will
 18.4440 +      // get the type of sor.
 18.4441 +      for (var i = 0, prev = startType; i < len; ++i) {
 18.4442 +        var type = types[i];
 18.4443 +        if (type == "m") types[i] = prev;
 18.4444 +        else prev = type;
 18.4445 +      }
 18.4446 +
 18.4447 +      // W2. Search backwards from each instance of a European number
 18.4448 +      // until the first strong type (R, L, AL, or sor) is found. If an
 18.4449 +      // AL is found, change the type of the European number to Arabic
 18.4450 +      // number.
 18.4451 +      // W3. Change all ALs to R.
 18.4452 +      for (var i = 0, cur = startType; i < len; ++i) {
 18.4453 +        var type = types[i];
 18.4454 +        if (type == "1" && cur == "r") types[i] = "n";
 18.4455 +        else if (isStrong.test(type)) { cur = type; if (type == "r") types[i] = "R"; }
 18.4456 +      }
 18.4457 +
 18.4458 +      // W4. A single European separator between two European numbers
 18.4459 +      // changes to a European number. A single common separator between
 18.4460 +      // two numbers of the same type changes to that type.
 18.4461 +      for (var i = 1, prev = types[0]; i < len - 1; ++i) {
 18.4462 +        var type = types[i];
 18.4463 +        if (type == "+" && prev == "1" && types[i+1] == "1") types[i] = "1";
 18.4464 +        else if (type == "," && prev == types[i+1] &&
 18.4465 +                 (prev == "1" || prev == "n")) types[i] = prev;
 18.4466 +        prev = type;
 18.4467 +      }
 18.4468 +
 18.4469 +      // W5. A sequence of European terminators adjacent to European
 18.4470 +      // numbers changes to all European numbers.
 18.4471 +      // W6. Otherwise, separators and terminators change to Other
 18.4472 +      // Neutral.
 18.4473 +      for (var i = 0; i < len; ++i) {
 18.4474 +        var type = types[i];
 18.4475 +        if (type == ",") types[i] = "N";
 18.4476 +        else if (type == "%") {
 18.4477 +          for (var end = i + 1; end < len && types[end] == "%"; ++end) {}
 18.4478 +          var replace = (i && types[i-1] == "!") || (end < len - 1 && types[end] == "1") ? "1" : "N";
 18.4479 +          for (var j = i; j < end; ++j) types[j] = replace;
 18.4480 +          i = end - 1;
 18.4481 +        }
 18.4482 +      }
 18.4483 +
 18.4484 +      // W7. Search backwards from each instance of a European number
 18.4485 +      // until the first strong type (R, L, or sor) is found. If an L is
 18.4486 +      // found, then change the type of the European number to L.
 18.4487 +      for (var i = 0, cur = startType; i < len; ++i) {
 18.4488 +        var type = types[i];
 18.4489 +        if (cur == "L" && type == "1") types[i] = "L";
 18.4490 +        else if (isStrong.test(type)) cur = type;
 18.4491 +      }
 18.4492 +
 18.4493 +      // N1. A sequence of neutrals takes the direction of the
 18.4494 +      // surrounding strong text if the text on both sides has the same
 18.4495 +      // direction. European and Arabic numbers act as if they were R in
 18.4496 +      // terms of their influence on neutrals. Start-of-level-run (sor)
 18.4497 +      // and end-of-level-run (eor) are used at level run boundaries.
 18.4498 +      // N2. Any remaining neutrals take the embedding direction.
 18.4499 +      for (var i = 0; i < len; ++i) {
 18.4500 +        if (isNeutral.test(types[i])) {
 18.4501 +          for (var end = i + 1; end < len && isNeutral.test(types[end]); ++end) {}
 18.4502 +          var before = (i ? types[i-1] : startType) == "L";
 18.4503 +          var after = (end < len - 1 ? types[end] : startType) == "L";
 18.4504 +          var replace = before || after ? "L" : "R";
 18.4505 +          for (var j = i; j < end; ++j) types[j] = replace;
 18.4506 +          i = end - 1;
 18.4507 +        }
 18.4508 +      }
 18.4509 +
 18.4510 +      // Here we depart from the documented algorithm, in order to avoid
 18.4511 +      // building up an actual levels array. Since there are only three
 18.4512 +      // levels (0, 1, 2) in an implementation that doesn't take
 18.4513 +      // explicit embedding into account, we can build up the order on
 18.4514 +      // the fly, without following the level-based algorithm.
 18.4515 +      var order = [], m;
 18.4516 +      for (var i = 0; i < len;) {
 18.4517 +        if (countsAsLeft.test(types[i])) {
 18.4518 +          var start = i;
 18.4519 +          for (++i; i < len && countsAsLeft.test(types[i]); ++i) {}
 18.4520 +          order.push({from: start, to: i, level: 0});
 18.4521 +        } else {
 18.4522 +          var pos = i, at = order.length;
 18.4523 +          for (++i; i < len && types[i] != "L"; ++i) {}
 18.4524 +          for (var j = pos; j < i;) {
 18.4525 +            if (countsAsNum.test(types[j])) {
 18.4526 +              if (pos < j) order.splice(at, 0, {from: pos, to: j, level: 1});
 18.4527 +              var nstart = j;
 18.4528 +              for (++j; j < i && countsAsNum.test(types[j]); ++j) {}
 18.4529 +              order.splice(at, 0, {from: nstart, to: j, level: 2});
 18.4530 +              pos = j;
 18.4531 +            } else ++j;
 18.4532 +          }
 18.4533 +          if (pos < i) order.splice(at, 0, {from: pos, to: i, level: 1});
 18.4534 +        }
 18.4535 +      }
 18.4536 +      if (order[0].level == 1 && (m = str.match(/^\s+/))) {
 18.4537 +        order[0].from = m[0].length;
 18.4538 +        order.unshift({from: 0, to: m[0].length, level: 0});
 18.4539 +      }
 18.4540 +      if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
 18.4541 +        lst(order).to -= m[0].length;
 18.4542 +        order.push({from: len - m[0].length, to: len, level: 0});
 18.4543 +      }
 18.4544 +      if (order[0].level != lst(order).level)
 18.4545 +        order.push({from: len, to: len, level: order[0].level});
 18.4546 +
 18.4547 +      return order;
 18.4548 +    };
 18.4549 +  })();
 18.4550 +
 18.4551 +  // THE END
 18.4552 +
 18.4553 +  CodeMirror.version = "3.0";
 18.4554 +
 18.4555 +  return CodeMirror;
 18.4556 +})();
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/mode/clike.js	Wed Jan 23 14:49:52 2013 +0100
    19.3 @@ -0,0 +1,300 @@
    19.4 +CodeMirror.defineMode("clike", function(config, parserConfig) {
    19.5 +  var indentUnit = config.indentUnit,
    19.6 +      statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
    19.7 +      keywords = parserConfig.keywords || {},
    19.8 +      builtin = parserConfig.builtin || {},
    19.9 +      blockKeywords = parserConfig.blockKeywords || {},
   19.10 +      atoms = parserConfig.atoms || {},
   19.11 +      hooks = parserConfig.hooks || {},
   19.12 +      multiLineStrings = parserConfig.multiLineStrings;
   19.13 +  var isOperatorChar = /[+\-*&%=<>!?|\/]/;
   19.14 +
   19.15 +  var curPunc;
   19.16 +
   19.17 +  function tokenBase(stream, state) {
   19.18 +    var ch = stream.next();
   19.19 +    if (hooks[ch]) {
   19.20 +      var result = hooks[ch](stream, state);
   19.21 +      if (result !== false) return result;
   19.22 +    }
   19.23 +    if (ch == '"' || ch == "'") {
   19.24 +      state.tokenize = tokenString(ch);
   19.25 +      return state.tokenize(stream, state);
   19.26 +    }
   19.27 +    if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
   19.28 +      curPunc = ch;
   19.29 +      return null;
   19.30 +    }
   19.31 +    if (/\d/.test(ch)) {
   19.32 +      stream.eatWhile(/[\w\.]/);
   19.33 +      return "number";
   19.34 +    }
   19.35 +    if (ch == "/") {
   19.36 +      if (stream.eat("*")) {
   19.37 +        state.tokenize = tokenComment;
   19.38 +        return tokenComment(stream, state);
   19.39 +      }
   19.40 +      if (stream.eat("/")) {
   19.41 +        stream.skipToEnd();
   19.42 +        return "comment";
   19.43 +      }
   19.44 +    }
   19.45 +    if (isOperatorChar.test(ch)) {
   19.46 +      stream.eatWhile(isOperatorChar);
   19.47 +      return "operator";
   19.48 +    }
   19.49 +    stream.eatWhile(/[\w\$_]/);
   19.50 +    var cur = stream.current();
   19.51 +    if (keywords.propertyIsEnumerable(cur)) {
   19.52 +      if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
   19.53 +      return "keyword";
   19.54 +    }
   19.55 +    if (builtin.propertyIsEnumerable(cur)) {
   19.56 +      if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
   19.57 +      return "builtin";
   19.58 +    }
   19.59 +    if (atoms.propertyIsEnumerable(cur)) return "atom";
   19.60 +    return "variable";
   19.61 +  }
   19.62 +
   19.63 +  function tokenString(quote) {
   19.64 +    return function(stream, state) {
   19.65 +      var escaped = false, next, end = false;
   19.66 +      while ((next = stream.next()) != null) {
   19.67 +        if (next == quote && !escaped) {end = true; break;}
   19.68 +        escaped = !escaped && next == "\\";
   19.69 +      }
   19.70 +      if (end || !(escaped || multiLineStrings))
   19.71 +        state.tokenize = null;
   19.72 +      return "string";
   19.73 +    };
   19.74 +  }
   19.75 +
   19.76 +  function tokenComment(stream, state) {
   19.77 +    var maybeEnd = false, ch;
   19.78 +    while (ch = stream.next()) {
   19.79 +      if (ch == "/" && maybeEnd) {
   19.80 +        state.tokenize = null;
   19.81 +        break;
   19.82 +      }
   19.83 +      maybeEnd = (ch == "*");
   19.84 +    }
   19.85 +    return "comment";
   19.86 +  }
   19.87 +
   19.88 +  function Context(indented, column, type, align, prev) {
   19.89 +    this.indented = indented;
   19.90 +    this.column = column;
   19.91 +    this.type = type;
   19.92 +    this.align = align;
   19.93 +    this.prev = prev;
   19.94 +  }
   19.95 +  function pushContext(state, col, type) {
   19.96 +    var indent = state.indented;
   19.97 +    if (state.context && state.context.type == "statement")
   19.98 +      indent = state.context.indented;
   19.99 +    return state.context = new Context(indent, col, type, null, state.context);
  19.100 +  }
  19.101 +  function popContext(state) {
  19.102 +    var t = state.context.type;
  19.103 +    if (t == ")" || t == "]" || t == "}")
  19.104 +      state.indented = state.context.indented;
  19.105 +    return state.context = state.context.prev;
  19.106 +  }
  19.107 +
  19.108 +  // Interface
  19.109 +
  19.110 +  return {
  19.111 +    startState: function(basecolumn) {
  19.112 +      return {
  19.113 +        tokenize: null,
  19.114 +        context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
  19.115 +        indented: 0,
  19.116 +        startOfLine: true
  19.117 +      };
  19.118 +    },
  19.119 +
  19.120 +    token: function(stream, state) {
  19.121 +      var ctx = state.context;
  19.122 +      if (stream.sol()) {
  19.123 +        if (ctx.align == null) ctx.align = false;
  19.124 +        state.indented = stream.indentation();
  19.125 +        state.startOfLine = true;
  19.126 +      }
  19.127 +      if (stream.eatSpace()) return null;
  19.128 +      curPunc = null;
  19.129 +      var style = (state.tokenize || tokenBase)(stream, state);
  19.130 +      if (style == "comment" || style == "meta") return style;
  19.131 +      if (ctx.align == null) ctx.align = true;
  19.132 +
  19.133 +      if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state);
  19.134 +      else if (curPunc == "{") pushContext(state, stream.column(), "}");
  19.135 +      else if (curPunc == "[") pushContext(state, stream.column(), "]");
  19.136 +      else if (curPunc == "(") pushContext(state, stream.column(), ")");
  19.137 +      else if (curPunc == "}") {
  19.138 +        while (ctx.type == "statement") ctx = popContext(state);
  19.139 +        if (ctx.type == "}") ctx = popContext(state);
  19.140 +        while (ctx.type == "statement") ctx = popContext(state);
  19.141 +      }
  19.142 +      else if (curPunc == ctx.type) popContext(state);
  19.143 +      else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement"))
  19.144 +        pushContext(state, stream.column(), "statement");
  19.145 +      state.startOfLine = false;
  19.146 +      return style;
  19.147 +    },
  19.148 +
  19.149 +    indent: function(state, textAfter) {
  19.150 +      if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
  19.151 +      var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
  19.152 +      if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
  19.153 +      var closing = firstChar == ctx.type;
  19.154 +      if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
  19.155 +      else if (ctx.align) return ctx.column + (closing ? 0 : 1);
  19.156 +      else return ctx.indented + (closing ? 0 : indentUnit);
  19.157 +    },
  19.158 +
  19.159 +    electricChars: "{}"
  19.160 +  };
  19.161 +});
  19.162 +
  19.163 +(function() {
  19.164 +  function words(str) {
  19.165 +    var obj = {}, words = str.split(" ");
  19.166 +    for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
  19.167 +    return obj;
  19.168 +  }
  19.169 +  var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
  19.170 +    "double static else struct entry switch extern typedef float union for unsigned " +
  19.171 +    "goto while enum void const signed volatile";
  19.172 +
  19.173 +  function cppHook(stream, state) {
  19.174 +    if (!state.startOfLine) return false;
  19.175 +    for (;;) {
  19.176 +      if (stream.skipTo("\\")) {
  19.177 +        stream.next();
  19.178 +        if (stream.eol()) {
  19.179 +          state.tokenize = cppHook;
  19.180 +          break;
  19.181 +        }
  19.182 +      } else {
  19.183 +        stream.skipToEnd();
  19.184 +        state.tokenize = null;
  19.185 +        break;
  19.186 +      }
  19.187 +    }
  19.188 +    return "meta";
  19.189 +  }
  19.190 +
  19.191 +  // C#-style strings where "" escapes a quote.
  19.192 +  function tokenAtString(stream, state) {
  19.193 +    var next;
  19.194 +    while ((next = stream.next()) != null) {
  19.195 +      if (next == '"' && !stream.eat('"')) {
  19.196 +        state.tokenize = null;
  19.197 +        break;
  19.198 +      }
  19.199 +    }
  19.200 +    return "string";
  19.201 +  }
  19.202 +
  19.203 +  function mimes(ms, mode) {
  19.204 +    for (var i = 0; i < ms.length; ++i) CodeMirror.defineMIME(ms[i], mode);
  19.205 +  }
  19.206 +
  19.207 +  mimes(["text/x-csrc", "text/x-c", "text/x-chdr"], {
  19.208 +    name: "clike",
  19.209 +    keywords: words(cKeywords),
  19.210 +    blockKeywords: words("case do else for if switch while struct"),
  19.211 +    atoms: words("null"),
  19.212 +    hooks: {"#": cppHook}
  19.213 +  });
  19.214 +  mimes(["text/x-c++src", "text/x-c++hdr"], {
  19.215 +    name: "clike",
  19.216 +    keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
  19.217 +                    "static_cast typeid catch operator template typename class friend private " +
  19.218 +                    "this using const_cast inline public throw virtual delete mutable protected " +
  19.219 +                    "wchar_t"),
  19.220 +    blockKeywords: words("catch class do else finally for if struct switch try while"),
  19.221 +    atoms: words("true false null"),
  19.222 +    hooks: {"#": cppHook}
  19.223 +  });
  19.224 +  CodeMirror.defineMIME("text/x-java", {
  19.225 +    name: "clike",
  19.226 +    keywords: words("abstract assert boolean break byte case catch char class const continue default " + 
  19.227 +                    "do double else enum extends final finally float for goto if implements import " +
  19.228 +                    "instanceof int interface long native new package private protected public " +
  19.229 +                    "return short static strictfp super switch synchronized this throw throws transient " +
  19.230 +                    "try void volatile while"),
  19.231 +    blockKeywords: words("catch class do else finally for if switch try while"),
  19.232 +    atoms: words("true false null"),
  19.233 +    hooks: {
  19.234 +      "@": function(stream) {
  19.235 +        stream.eatWhile(/[\w\$_]/);
  19.236 +        return "meta";
  19.237 +      }
  19.238 +    }
  19.239 +  });
  19.240 +  CodeMirror.defineMIME("text/x-csharp", {
  19.241 +    name: "clike",
  19.242 +    keywords: words("abstract as base break case catch checked class const continue" + 
  19.243 +                    " default delegate do else enum event explicit extern finally fixed for" + 
  19.244 +                    " foreach goto if implicit in interface internal is lock namespace new" + 
  19.245 +                    " operator out override params private protected public readonly ref return sealed" + 
  19.246 +                    " sizeof stackalloc static struct switch this throw try typeof unchecked" + 
  19.247 +                    " unsafe using virtual void volatile while add alias ascending descending dynamic from get" + 
  19.248 +                    " global group into join let orderby partial remove select set value var yield"),
  19.249 +    blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
  19.250 +    builtin: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" +
  19.251 +                    " Guid Int16 Int32 Int64 Object SByte Single String TimeSpan UInt16 UInt32" +
  19.252 +                    " UInt64 bool byte char decimal double short int long object"  +
  19.253 +                    " sbyte float string ushort uint ulong"),
  19.254 +    atoms: words("true false null"),
  19.255 +    hooks: {
  19.256 +      "@": function(stream, state) {
  19.257 +        if (stream.eat('"')) {
  19.258 +          state.tokenize = tokenAtString;
  19.259 +          return tokenAtString(stream, state);
  19.260 +        }
  19.261 +        stream.eatWhile(/[\w\$_]/);
  19.262 +        return "meta";
  19.263 +      }
  19.264 +    }
  19.265 +  });
  19.266 +  CodeMirror.defineMIME("text/x-scala", {
  19.267 +    name: "clike",
  19.268 +    keywords: words(
  19.269 +      
  19.270 +      /* scala */
  19.271 +      "abstract case catch class def do else extends false final finally for forSome if " +
  19.272 +      "implicit import lazy match new null object override package private protected return " +
  19.273 +      "sealed super this throw trait try trye type val var while with yield _ : = => <- <: " +
  19.274 +      "<% >: # @ " +
  19.275 +                    
  19.276 +      /* package scala */
  19.277 +      "assert assume require print println printf readLine readBoolean readByte readShort " +
  19.278 +      "readChar readInt readLong readFloat readDouble " +
  19.279 +      
  19.280 +      "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
  19.281 +      "Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " +
  19.282 +      "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
  19.283 +      "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
  19.284 +      "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector :: #:: " +
  19.285 +      
  19.286 +      /* package java.lang */            
  19.287 +      "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
  19.288 +      "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
  19.289 +      "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
  19.290 +      "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
  19.291 +      
  19.292 +      
  19.293 +    ),
  19.294 +    blockKeywords: words("catch class do else finally for forSome if match switch try while"),
  19.295 +    atoms: words("true false null"),
  19.296 +    hooks: {
  19.297 +      "@": function(stream) {
  19.298 +        stream.eatWhile(/[\w\$_]/);
  19.299 +        return "meta";
  19.300 +      }
  19.301 +    }
  19.302 +  });
  19.303 +}());
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/mode/xml.js	Wed Jan 23 14:49:52 2013 +0100
    20.3 @@ -0,0 +1,324 @@
    20.4 +CodeMirror.defineMode("xml", function(config, parserConfig) {
    20.5 +  var indentUnit = config.indentUnit;
    20.6 +  var Kludges = parserConfig.htmlMode ? {
    20.7 +    autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
    20.8 +                      'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
    20.9 +                      'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
   20.10 +                      'track': true, 'wbr': true},
   20.11 +    implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
   20.12 +                       'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
   20.13 +                       'th': true, 'tr': true},
   20.14 +    contextGrabbers: {
   20.15 +      'dd': {'dd': true, 'dt': true},
   20.16 +      'dt': {'dd': true, 'dt': true},
   20.17 +      'li': {'li': true},
   20.18 +      'option': {'option': true, 'optgroup': true},
   20.19 +      'optgroup': {'optgroup': true},
   20.20 +      'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
   20.21 +            'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
   20.22 +            'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
   20.23 +            'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
   20.24 +            'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
   20.25 +      'rp': {'rp': true, 'rt': true},
   20.26 +      'rt': {'rp': true, 'rt': true},
   20.27 +      'tbody': {'tbody': true, 'tfoot': true},
   20.28 +      'td': {'td': true, 'th': true},
   20.29 +      'tfoot': {'tbody': true},
   20.30 +      'th': {'td': true, 'th': true},
   20.31 +      'thead': {'tbody': true, 'tfoot': true},
   20.32 +      'tr': {'tr': true}
   20.33 +    },
   20.34 +    doNotIndent: {"pre": true},
   20.35 +    allowUnquoted: true,
   20.36 +    allowMissing: true
   20.37 +  } : {
   20.38 +    autoSelfClosers: {},
   20.39 +    implicitlyClosed: {},
   20.40 +    contextGrabbers: {},
   20.41 +    doNotIndent: {},
   20.42 +    allowUnquoted: false,
   20.43 +    allowMissing: false
   20.44 +  };
   20.45 +  var alignCDATA = parserConfig.alignCDATA;
   20.46 +
   20.47 +  // Return variables for tokenizers
   20.48 +  var tagName, type;
   20.49 +
   20.50 +  function inText(stream, state) {
   20.51 +    function chain(parser) {
   20.52 +      state.tokenize = parser;
   20.53 +      return parser(stream, state);
   20.54 +    }
   20.55 +
   20.56 +    var ch = stream.next();
   20.57 +    if (ch == "<") {
   20.58 +      if (stream.eat("!")) {
   20.59 +        if (stream.eat("[")) {
   20.60 +          if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
   20.61 +          else return null;
   20.62 +        }
   20.63 +        else if (stream.match("--")) return chain(inBlock("comment", "-->"));
   20.64 +        else if (stream.match("DOCTYPE", true, true)) {
   20.65 +          stream.eatWhile(/[\w\._\-]/);
   20.66 +          return chain(doctype(1));
   20.67 +        }
   20.68 +        else return null;
   20.69 +      }
   20.70 +      else if (stream.eat("?")) {
   20.71 +        stream.eatWhile(/[\w\._\-]/);
   20.72 +        state.tokenize = inBlock("meta", "?>");
   20.73 +        return "meta";
   20.74 +      }
   20.75 +      else {
   20.76 +        var isClose = stream.eat("/");
   20.77 +        tagName = "";
   20.78 +        var c;
   20.79 +        while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
   20.80 +        if (!tagName) return "error";
   20.81 +        type = isClose ? "closeTag" : "openTag";
   20.82 +        state.tokenize = inTag;
   20.83 +        return "tag";
   20.84 +      }
   20.85 +    }
   20.86 +    else if (ch == "&") {
   20.87 +      var ok;
   20.88 +      if (stream.eat("#")) {
   20.89 +        if (stream.eat("x")) {
   20.90 +          ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");          
   20.91 +        } else {
   20.92 +          ok = stream.eatWhile(/[\d]/) && stream.eat(";");
   20.93 +        }
   20.94 +      } else {
   20.95 +        ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
   20.96 +      }
   20.97 +      return ok ? "atom" : "error";
   20.98 +    }
   20.99 +    else {
  20.100 +      stream.eatWhile(/[^&<]/);
  20.101 +      return null;
  20.102 +    }
  20.103 +  }
  20.104 +
  20.105 +  function inTag(stream, state) {
  20.106 +    var ch = stream.next();
  20.107 +    if (ch == ">" || (ch == "/" && stream.eat(">"))) {
  20.108 +      state.tokenize = inText;
  20.109 +      type = ch == ">" ? "endTag" : "selfcloseTag";
  20.110 +      return "tag";
  20.111 +    }
  20.112 +    else if (ch == "=") {
  20.113 +      type = "equals";
  20.114 +      return null;
  20.115 +    }
  20.116 +    else if (/[\'\"]/.test(ch)) {
  20.117 +      state.tokenize = inAttribute(ch);
  20.118 +      return state.tokenize(stream, state);
  20.119 +    }
  20.120 +    else {
  20.121 +      stream.eatWhile(/[^\s\u00a0=<>\"\']/);
  20.122 +      return "word";
  20.123 +    }
  20.124 +  }
  20.125 +
  20.126 +  function inAttribute(quote) {
  20.127 +    return function(stream, state) {
  20.128 +      while (!stream.eol()) {
  20.129 +        if (stream.next() == quote) {
  20.130 +          state.tokenize = inTag;
  20.131 +          break;
  20.132 +        }
  20.133 +      }
  20.134 +      return "string";
  20.135 +    };
  20.136 +  }
  20.137 +
  20.138 +  function inBlock(style, terminator) {
  20.139 +    return function(stream, state) {
  20.140 +      while (!stream.eol()) {
  20.141 +        if (stream.match(terminator)) {
  20.142 +          state.tokenize = inText;
  20.143 +          break;
  20.144 +        }
  20.145 +        stream.next();
  20.146 +      }
  20.147 +      return style;
  20.148 +    };
  20.149 +  }
  20.150 +  function doctype(depth) {
  20.151 +    return function(stream, state) {
  20.152 +      var ch;
  20.153 +      while ((ch = stream.next()) != null) {
  20.154 +        if (ch == "<") {
  20.155 +          state.tokenize = doctype(depth + 1);
  20.156 +          return state.tokenize(stream, state);
  20.157 +        } else if (ch == ">") {
  20.158 +          if (depth == 1) {
  20.159 +            state.tokenize = inText;
  20.160 +            break;
  20.161 +          } else {
  20.162 +            state.tokenize = doctype(depth - 1);
  20.163 +            return state.tokenize(stream, state);
  20.164 +          }
  20.165 +        }
  20.166 +      }
  20.167 +      return "meta";
  20.168 +    };
  20.169 +  }
  20.170 +
  20.171 +  var curState, setStyle;
  20.172 +  function pass() {
  20.173 +    for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
  20.174 +  }
  20.175 +  function cont() {
  20.176 +    pass.apply(null, arguments);
  20.177 +    return true;
  20.178 +  }
  20.179 +
  20.180 +  function pushContext(tagName, startOfLine) {
  20.181 +    var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent);
  20.182 +    curState.context = {
  20.183 +      prev: curState.context,
  20.184 +      tagName: tagName,
  20.185 +      indent: curState.indented,
  20.186 +      startOfLine: startOfLine,
  20.187 +      noIndent: noIndent
  20.188 +    };
  20.189 +  }
  20.190 +  function popContext() {
  20.191 +    if (curState.context) curState.context = curState.context.prev;
  20.192 +  }
  20.193 +
  20.194 +  function element(type) {
  20.195 +    if (type == "openTag") {
  20.196 +      curState.tagName = tagName;
  20.197 +      return cont(attributes, endtag(curState.startOfLine));
  20.198 +    } else if (type == "closeTag") {
  20.199 +      var err = false;
  20.200 +      if (curState.context) {
  20.201 +        if (curState.context.tagName != tagName) {
  20.202 +          if (Kludges.implicitlyClosed.hasOwnProperty(curState.context.tagName.toLowerCase())) {
  20.203 +            popContext();
  20.204 +          }
  20.205 +          err = !curState.context || curState.context.tagName != tagName;
  20.206 +        }
  20.207 +      } else {
  20.208 +        err = true;
  20.209 +      }
  20.210 +      if (err) setStyle = "error";
  20.211 +      return cont(endclosetag(err));
  20.212 +    }
  20.213 +    return cont();
  20.214 +  }
  20.215 +  function endtag(startOfLine) {
  20.216 +    return function(type) {
  20.217 +      var tagName = curState.tagName;
  20.218 +      curState.tagName = null;
  20.219 +      if (type == "selfcloseTag" ||
  20.220 +          (type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(tagName.toLowerCase()))) {
  20.221 +        maybePopContext(tagName.toLowerCase());
  20.222 +        return cont();
  20.223 +      }
  20.224 +      if (type == "endTag") {
  20.225 +        maybePopContext(tagName.toLowerCase());
  20.226 +        pushContext(tagName, startOfLine);
  20.227 +        return cont();
  20.228 +      }
  20.229 +      return cont();
  20.230 +    };
  20.231 +  }
  20.232 +  function endclosetag(err) {
  20.233 +    return function(type) {
  20.234 +      if (err) setStyle = "error";
  20.235 +      if (type == "endTag") { popContext(); return cont(); }
  20.236 +      setStyle = "error";
  20.237 +      return cont(arguments.callee);
  20.238 +    };
  20.239 +  }
  20.240 +  function maybePopContext(nextTagName) {
  20.241 +    var parentTagName;
  20.242 +    while (true) {
  20.243 +      if (!curState.context) {
  20.244 +        return;
  20.245 +      }
  20.246 +      parentTagName = curState.context.tagName.toLowerCase();
  20.247 +      if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) ||
  20.248 +          !Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
  20.249 +        return;
  20.250 +      }
  20.251 +      popContext();
  20.252 +    }
  20.253 +  }
  20.254 +
  20.255 +  function attributes(type) {
  20.256 +    if (type == "word") {setStyle = "attribute"; return cont(attribute, attributes);}
  20.257 +    if (type == "endTag" || type == "selfcloseTag") return pass();
  20.258 +    setStyle = "error";
  20.259 +    return cont(attributes);
  20.260 +  }
  20.261 +  function attribute(type) {
  20.262 +    if (type == "equals") return cont(attvalue, attributes);
  20.263 +    if (!Kludges.allowMissing) setStyle = "error";
  20.264 +    else if (type == "word") setStyle = "attribute";
  20.265 +    return (type == "endTag" || type == "selfcloseTag") ? pass() : cont();
  20.266 +  }
  20.267 +  function attvalue(type) {
  20.268 +    if (type == "string") return cont(attvaluemaybe);
  20.269 +    if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();}
  20.270 +    setStyle = "error";
  20.271 +    return (type == "endTag" || type == "selfCloseTag") ? pass() : cont();
  20.272 +  }
  20.273 +  function attvaluemaybe(type) {
  20.274 +    if (type == "string") return cont(attvaluemaybe);
  20.275 +    else return pass();
  20.276 +  }
  20.277 +
  20.278 +  return {
  20.279 +    startState: function() {
  20.280 +      return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null};
  20.281 +    },
  20.282 +
  20.283 +    token: function(stream, state) {
  20.284 +      if (stream.sol()) {
  20.285 +        state.startOfLine = true;
  20.286 +        state.indented = stream.indentation();
  20.287 +      }
  20.288 +      if (stream.eatSpace()) return null;
  20.289 +
  20.290 +      setStyle = type = tagName = null;
  20.291 +      var style = state.tokenize(stream, state);
  20.292 +      state.type = type;
  20.293 +      if ((style || type) && style != "comment") {
  20.294 +        curState = state;
  20.295 +        while (true) {
  20.296 +          var comb = state.cc.pop() || element;
  20.297 +          if (comb(type || style)) break;
  20.298 +        }
  20.299 +      }
  20.300 +      state.startOfLine = false;
  20.301 +      return setStyle || style;
  20.302 +    },
  20.303 +
  20.304 +    indent: function(state, textAfter, fullLine) {
  20.305 +      var context = state.context;
  20.306 +      if ((state.tokenize != inTag && state.tokenize != inText) ||
  20.307 +          context && context.noIndent)
  20.308 +        return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
  20.309 +      if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
  20.310 +      if (context && /^<\//.test(textAfter))
  20.311 +        context = context.prev;
  20.312 +      while (context && !context.startOfLine)
  20.313 +        context = context.prev;
  20.314 +      if (context) return context.indent + indentUnit;
  20.315 +      else return 0;
  20.316 +    },
  20.317 +
  20.318 +    electricChars: "/",
  20.319 +
  20.320 +    configuration: parserConfig.htmlMode ? "html" : "xml"
  20.321 +  };
  20.322 +});
  20.323 +
  20.324 +CodeMirror.defineMIME("text/xml", "xml");
  20.325 +CodeMirror.defineMIME("application/xml", "xml");
  20.326 +if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
  20.327 +  CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/dew/src/main/resources/org/apidesign/bck2brwsr/dew/js/codemirror/theme/elegant.css	Wed Jan 23 14:49:52 2013 +0100
    21.3 @@ -0,0 +1,10 @@
    21.4 +.cm-s-elegant span.cm-number, .cm-s-elegant span.cm-string, .cm-s-elegant span.cm-atom {color: #762;}
    21.5 +.cm-s-elegant span.cm-comment {color: #262; font-style: italic; line-height: 1em;}
    21.6 +.cm-s-elegant span.cm-meta {color: #555; font-style: italic; line-height: 1em;}
    21.7 +.cm-s-elegant span.cm-variable {color: black;}
    21.8 +.cm-s-elegant span.cm-variable-2 {color: #b11;}
    21.9 +.cm-s-elegant span.cm-qualifier {color: #555;}
   21.10 +.cm-s-elegant span.cm-keyword {color: #730;}
   21.11 +.cm-s-elegant span.cm-builtin {color: #30a;}
   21.12 +.cm-s-elegant span.cm-error {background-color: #fdd;}
   21.13 +.cm-s-elegant span.cm-link {color: #762;}
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/dew/src/test/java/org/apidesign/bck2brwsr/dew/CompileTest.java	Wed Jan 23 14:49:52 2013 +0100
    22.3 @@ -0,0 +1,45 @@
    22.4 +/**
    22.5 + * Back 2 Browser Bytecode Translator
    22.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    22.7 + *
    22.8 + * This program is free software: you can redistribute it and/or modify
    22.9 + * it under the terms of the GNU General Public License as published by
   22.10 + * the Free Software Foundation, version 2 of the License.
   22.11 + *
   22.12 + * This program is distributed in the hope that it will be useful,
   22.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   22.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   22.15 + * GNU General Public License for more details.
   22.16 + *
   22.17 + * You should have received a copy of the GNU General Public License
   22.18 + * along with this program. Look for COPYING file in the top folder.
   22.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   22.20 + */
   22.21 +package org.apidesign.bck2brwsr.dew;
   22.22 +
   22.23 +import java.io.IOException;
   22.24 +import static org.testng.Assert.*;
   22.25 +import org.testng.annotations.Test;
   22.26 +
   22.27 +/**
   22.28 + *
   22.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   22.30 + */
   22.31 +public class CompileTest  {
   22.32 +    @Test public void testCompile() throws IOException {
   22.33 +        String html = "<html><body>"
   22.34 +                + " <button id='btn'>Hello!</button>"
   22.35 +                + "</body></html>";
   22.36 +        String java = "package x.y.z;"
   22.37 +                + "import org.apidesign.bck2brwsr.htmlpage.api.*;"
   22.38 +                + "import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;"
   22.39 +            + "@Page(xhtml=\"index.html\", className=\"Index\")"
   22.40 +            + "class X { "
   22.41 +            + "   @On(event=CLICK, id=\"btn\") static void clcs() {}"
   22.42 +            + "}";
   22.43 +        Compile result = Compile.create(html, java);
   22.44 +
   22.45 +        assertNotNull(result.get("x/y/z/X.class"), "Class X is compiled: " + result);
   22.46 +        assertNotNull(result.get("x/y/z/Index.class"), "Class Index is compiled: " + result);
   22.47 +    }
   22.48 +}
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/emul/src/main/java/java/lang/Runnable.java	Wed Jan 23 14:49:52 2013 +0100
    23.3 @@ -0,0 +1,69 @@
    23.4 +/*
    23.5 + * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
    23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    23.7 + *
    23.8 + * This code is free software; you can redistribute it and/or modify it
    23.9 + * under the terms of the GNU General Public License version 2 only, as
   23.10 + * published by the Free Software Foundation.  Oracle designates this
   23.11 + * particular file as subject to the "Classpath" exception as provided
   23.12 + * by Oracle in the LICENSE file that accompanied this code.
   23.13 + *
   23.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   23.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   23.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   23.17 + * version 2 for more details (a copy is included in the LICENSE file that
   23.18 + * accompanied this code).
   23.19 + *
   23.20 + * You should have received a copy of the GNU General Public License version
   23.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   23.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   23.23 + *
   23.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   23.25 + * or visit www.oracle.com if you need additional information or have any
   23.26 + * questions.
   23.27 + */
   23.28 +
   23.29 +package java.lang;
   23.30 +
   23.31 +/**
   23.32 + * The <code>Runnable</code> interface should be implemented by any
   23.33 + * class whose instances are intended to be executed by a thread. The
   23.34 + * class must define a method of no arguments called <code>run</code>.
   23.35 + * <p>
   23.36 + * This interface is designed to provide a common protocol for objects that
   23.37 + * wish to execute code while they are active. For example,
   23.38 + * <code>Runnable</code> is implemented by class <code>Thread</code>.
   23.39 + * Being active simply means that a thread has been started and has not
   23.40 + * yet been stopped.
   23.41 + * <p>
   23.42 + * In addition, <code>Runnable</code> provides the means for a class to be
   23.43 + * active while not subclassing <code>Thread</code>. A class that implements
   23.44 + * <code>Runnable</code> can run without subclassing <code>Thread</code>
   23.45 + * by instantiating a <code>Thread</code> instance and passing itself in
   23.46 + * as the target.  In most cases, the <code>Runnable</code> interface should
   23.47 + * be used if you are only planning to override the <code>run()</code>
   23.48 + * method and no other <code>Thread</code> methods.
   23.49 + * This is important because classes should not be subclassed
   23.50 + * unless the programmer intends on modifying or enhancing the fundamental
   23.51 + * behavior of the class.
   23.52 + *
   23.53 + * @author  Arthur van Hoff
   23.54 + * @see     java.lang.Thread
   23.55 + * @see     java.util.concurrent.Callable
   23.56 + * @since   JDK1.0
   23.57 + */
   23.58 +public
   23.59 +interface Runnable {
   23.60 +    /**
   23.61 +     * When an object implementing interface <code>Runnable</code> is used
   23.62 +     * to create a thread, starting the thread causes the object's
   23.63 +     * <code>run</code> method to be called in that separately executing
   23.64 +     * thread.
   23.65 +     * <p>
   23.66 +     * The general contract of the method <code>run</code> is that it may
   23.67 +     * take any action whatsoever.
   23.68 +     *
   23.69 +     * @see     java.lang.Thread#run()
   23.70 +     */
   23.71 +    public abstract void run();
   23.72 +}
    24.1 --- a/javaquery/api/pom.xml	Tue Jan 22 17:53:05 2013 +0100
    24.2 +++ b/javaquery/api/pom.xml	Wed Jan 23 14:49:52 2013 +0100
    24.3 @@ -64,5 +64,11 @@
    24.4        <type>jar</type>
    24.5        <scope>test</scope>
    24.6      </dependency>
    24.7 +    <dependency>
    24.8 +      <groupId>${project.groupId}</groupId>
    24.9 +      <artifactId>vmtest</artifactId>
   24.10 +      <version>${project.version}</version>
   24.11 +      <scope>test</scope>
   24.12 +    </dependency>
   24.13    </dependencies>
   24.14  </project>
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/Knockout.java	Wed Jan 23 14:49:52 2013 +0100
    25.3 @@ -0,0 +1,93 @@
    25.4 +/**
    25.5 + * Back 2 Browser Bytecode Translator
    25.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    25.7 + *
    25.8 + * This program is free software: you can redistribute it and/or modify
    25.9 + * it under the terms of the GNU General Public License as published by
   25.10 + * the Free Software Foundation, version 2 of the License.
   25.11 + *
   25.12 + * This program is distributed in the hope that it will be useful,
   25.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   25.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   25.15 + * GNU General Public License for more details.
   25.16 + *
   25.17 + * You should have received a copy of the GNU General Public License
   25.18 + * along with this program. Look for COPYING file in the top folder.
   25.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   25.20 + */
   25.21 +package org.apidesign.bck2brwsr.htmlpage;
   25.22 +
   25.23 +import java.lang.reflect.Method;
   25.24 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
   25.25 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
   25.26 +
   25.27 +/** Provides binding between models and 
   25.28 + *
   25.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   25.30 + */
   25.31 +@ExtraJavaScript(resource = "/org/apidesign/bck2brwsr/htmlpage/knockout-2.2.1.js")
   25.32 +public class Knockout {
   25.33 +    /** used by tests */
   25.34 +    static Knockout next;
   25.35 +    
   25.36 +    Knockout() {
   25.37 +    }
   25.38 +    
   25.39 +    public static <M> Knockout applyBindings(
   25.40 +        Class<M> modelClass, M model, String[] propsGettersAndSetters
   25.41 +    ) {
   25.42 +        Knockout bindings = next;
   25.43 +        next = null;
   25.44 +        if (bindings == null) {
   25.45 +            bindings = new Knockout();
   25.46 +        }
   25.47 +        for (int i = 0; i < propsGettersAndSetters.length; i += 4) {
   25.48 +            try {
   25.49 +                Method getter = modelClass.getMethod(propsGettersAndSetters[i + 3]);
   25.50 +                bind(bindings, model, propsGettersAndSetters[i],
   25.51 +                    propsGettersAndSetters[i + 1],
   25.52 +                    propsGettersAndSetters[i + 2],
   25.53 +                    getter.getReturnType().isPrimitive()
   25.54 +                );
   25.55 +            } catch (NoSuchMethodException ex) {
   25.56 +                throw new IllegalStateException(ex.getMessage());
   25.57 +            }
   25.58 +        }
   25.59 +        applyBindings(bindings);
   25.60 +        return bindings;
   25.61 +    }
   25.62 +
   25.63 +    @JavaScriptBody(args = { "prop" }, body =
   25.64 +        "this[prop].valueHasMutated();"
   25.65 +    )
   25.66 +    public void valueHasMutated(String prop) {
   25.67 +    }
   25.68 +    
   25.69 +
   25.70 +    @JavaScriptBody(args = { "id", "ev" }, body = "ko.utils.triggerEvent(window.document.getElementById(id), ev.substring(2));")
   25.71 +    public static void triggerEvent(String id, String ev) {
   25.72 +    }
   25.73 +    
   25.74 +    @JavaScriptBody(args = { "bindings", "model", "prop", "getter", "setter", "primitive" }, body =
   25.75 +          "var bnd = {\n"
   25.76 +        + "  read: function() {\n"
   25.77 +        + "    var v = model[getter]();\n"
   25.78 +        + "    return v;\n"
   25.79 +        + "  },\n"
   25.80 +        + "  owner: bindings\n"
   25.81 +        + "};\n"
   25.82 +        + "if (setter != null) {\n"
   25.83 +        + "  bnd.write = function(val) {\n"
   25.84 +        + "    model[setter](primitive ? new Number(val) : val);\n"
   25.85 +        + "  };\n"
   25.86 +        + "}\n"
   25.87 +        + "bindings[prop] = ko.computed(bnd);"
   25.88 +    )
   25.89 +    private static void bind(
   25.90 +        Object bindings, Object model, String prop, String getter, String setter, boolean primitive
   25.91 +    ) {
   25.92 +    }
   25.93 +    
   25.94 +    @JavaScriptBody(args = { "bindings" }, body = "ko.applyBindings(bindings);")
   25.95 +    private static void applyBindings(Object bindings) {}
   25.96 +}
    26.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java	Tue Jan 22 17:53:05 2013 +0100
    26.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java	Wed Jan 23 14:49:52 2013 +0100
    26.3 @@ -22,9 +22,13 @@
    26.4  import java.io.OutputStreamWriter;
    26.5  import java.io.Writer;
    26.6  import java.util.ArrayList;
    26.7 +import java.util.Collection;
    26.8  import java.util.Collections;
    26.9 +import java.util.HashMap;
   26.10 +import java.util.LinkedHashSet;
   26.11  import java.util.List;
   26.12  import java.util.Locale;
   26.13 +import java.util.Map;
   26.14  import java.util.Set;
   26.15  import javax.annotation.processing.AbstractProcessor;
   26.16  import javax.annotation.processing.Completion;
   26.17 @@ -39,12 +43,16 @@
   26.18  import javax.lang.model.element.Modifier;
   26.19  import javax.lang.model.element.PackageElement;
   26.20  import javax.lang.model.element.TypeElement;
   26.21 +import javax.lang.model.element.VariableElement;
   26.22 +import javax.lang.model.type.MirroredTypeException;
   26.23  import javax.lang.model.type.TypeMirror;
   26.24  import javax.tools.Diagnostic;
   26.25  import javax.tools.FileObject;
   26.26  import javax.tools.StandardLocation;
   26.27 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
   26.28  import org.apidesign.bck2brwsr.htmlpage.api.On;
   26.29  import org.apidesign.bck2brwsr.htmlpage.api.Page;
   26.30 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
   26.31  import org.openide.util.lookup.ServiceProvider;
   26.32  
   26.33  /** Annotation processor to process an XHTML page and generate appropriate 
   26.34 @@ -62,6 +70,9 @@
   26.35      public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   26.36          for (Element e : roundEnv.getElementsAnnotatedWith(Page.class)) {
   26.37              Page p = e.getAnnotation(Page.class);
   26.38 +            if (p == null) {
   26.39 +                continue;
   26.40 +            }
   26.41              PackageElement pe = (PackageElement)e.getEnclosingElement();
   26.42              String pkg = pe.getQualifiedName().toString();
   26.43              
   26.44 @@ -86,19 +97,44 @@
   26.45                  try {
   26.46                      w.append("package " + pkg + ";\n");
   26.47                      w.append("import org.apidesign.bck2brwsr.htmlpage.api.*;\n");
   26.48 -                    w.append("class ").append(className).append(" {\n");
   26.49 +                    w.append("final class ").append(className).append(" {\n");
   26.50 +                    w.append("  private boolean locked;\n");
   26.51 +                    if (!initializeOnClick(className, (TypeElement) e, w, pp)) {
   26.52 +                        return false;
   26.53 +                    }
   26.54                      for (String id : pp.ids()) {
   26.55                          String tag = pp.tagNameForId(id);
   26.56                          String type = type(tag);
   26.57 -                        w.append("  ").append("public static final ").
   26.58 +                        w.append("  ").append("public final ").
   26.59                              append(type).append(' ').append(cnstnt(id)).append(" = new ").
   26.60                              append(type).append("(\"").append(id).append("\");\n");
   26.61                      }
   26.62 -                    w.append("  static {\n");
   26.63 -                    if (!initializeOnClick((TypeElement) e, w, pp)) {
   26.64 -                        return false;
   26.65 +                    List<String> propsGetSet = new ArrayList<String>();
   26.66 +                    Map<String,Collection<String>> propsDeps = new HashMap<String, Collection<String>>();
   26.67 +                    generateComputedProperties(w, e.getEnclosedElements(), propsGetSet, propsDeps);
   26.68 +                    generateProperties(w, p.properties(), propsGetSet, propsDeps);
   26.69 +                    w.append("  private org.apidesign.bck2brwsr.htmlpage.Knockout ko;\n");
   26.70 +                    if (!propsGetSet.isEmpty()) {
   26.71 +                        w.write("public " + className + " applyBindings() {\n");
   26.72 +                        w.write("  ko = org.apidesign.bck2brwsr.htmlpage.Knockout.applyBindings(");
   26.73 +                        w.write(className + ".class, this, ");
   26.74 +                        w.write("new String[] {\n");
   26.75 +                        String sep = "";
   26.76 +                        for (String n : propsGetSet) {
   26.77 +                            w.write(sep);
   26.78 +                            if (n == null) {
   26.79 +                                w.write("    null");
   26.80 +                            } else {
   26.81 +                                w.write("    \"" + n + "\"");
   26.82 +                            }
   26.83 +                            sep = ",\n";
   26.84 +                        }
   26.85 +                        w.write("\n  });\n  return this;\n}\n");
   26.86 +                        
   26.87 +                        w.write("public void triggerEvent(Element e, OnEvent ev) {\n");
   26.88 +                        w.write("  org.apidesign.bck2brwsr.htmlpage.Knockout.triggerEvent(e.getId(), ev.getElementPropertyName());\n");
   26.89 +                        w.write("}\n");
   26.90                      }
   26.91 -                    w.append("  }\n");
   26.92                      w.append("}\n");
   26.93                  } finally {
   26.94                      w.close();
   26.95 @@ -144,12 +180,17 @@
   26.96          return id.toUpperCase(Locale.ENGLISH).replace('.', '_').replace('-', '_');
   26.97      }
   26.98  
   26.99 -    private boolean initializeOnClick(TypeElement type, Writer w, ProcessPage pp) throws IOException {
  26.100 +    private boolean initializeOnClick(
  26.101 +        String className, TypeElement type, Writer w, ProcessPage pp
  26.102 +    ) throws IOException {
  26.103          TypeMirror stringType = processingEnv.getElementUtils().getTypeElement("java.lang.String").asType();
  26.104          { //for (Element clazz : pe.getEnclosedElements()) {
  26.105            //  if (clazz.getKind() != ElementKind.CLASS) {
  26.106              //    continue;
  26.107             // }
  26.108 +            w.append("  public ").append(className).append("() {\n");
  26.109 +            StringBuilder dispatch = new StringBuilder();
  26.110 +            int dispatchCnt = 0;
  26.111              for (Element method : type.getEnclosedElements()) {
  26.112                  On oc = method.getAnnotation(On.class);
  26.113                  if (oc != null) {
  26.114 @@ -159,15 +200,33 @@
  26.115                              return false;
  26.116                          }
  26.117                          ExecutableElement ee = (ExecutableElement)method;
  26.118 -                        boolean hasParam;
  26.119 -                        if (ee.getParameters().isEmpty()) {
  26.120 -                            hasParam = false;
  26.121 -                        } else {
  26.122 -                            if (ee.getParameters().size() != 1 || ee.getParameters().get(0).asType() != stringType) {
  26.123 -                                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@On method should either have no arguments or one String argument", ee);
  26.124 +                        StringBuilder params = new StringBuilder();
  26.125 +                        {
  26.126 +                            boolean first = true;
  26.127 +                            for (VariableElement ve : ee.getParameters()) {
  26.128 +                                if (!first) {
  26.129 +                                    params.append(", ");
  26.130 +                                }
  26.131 +                                first = false;
  26.132 +                                if (ve.asType() == stringType) {
  26.133 +                                    params.append('"').append(id).append('"');
  26.134 +                                    continue;
  26.135 +                                }
  26.136 +                                String rn = ve.asType().toString();
  26.137 +                                int last = rn.lastIndexOf('.');
  26.138 +                                if (last >= 0) {
  26.139 +                                    rn = rn.substring(last + 1);
  26.140 +                                }
  26.141 +                                if (rn.equals(className)) {
  26.142 +                                    params.append(className).append(".this");
  26.143 +                                    continue;
  26.144 +                                }
  26.145 +                                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, 
  26.146 +                                    "@On method can only accept String or " + className + " arguments",
  26.147 +                                    ee
  26.148 +                                );
  26.149                                  return false;
  26.150                              }
  26.151 -                            hasParam = true;
  26.152                          }
  26.153                          if (!ee.getModifiers().contains(Modifier.STATIC)) {
  26.154                              processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@On method has to be static", ee);
  26.155 @@ -178,17 +237,33 @@
  26.156                              return false;
  26.157                          }
  26.158                          w.append("  OnEvent." + oc.event()).append(".of(").append(cnstnt(id)).
  26.159 -                            append(").perform(new Runnable() { public void run() {\n");
  26.160 -                        w.append("    ").append(type.getSimpleName().toString()).
  26.161 -                            append('.').append(ee.getSimpleName()).append("(");
  26.162 -                        if (hasParam) {
  26.163 -                            w.append("\"").append(id).append("\"");
  26.164 -                        }
  26.165 -                        w.append(");\n");
  26.166 -                        w.append("  }});\n");
  26.167 -                    }           
  26.168 +                            append(").perform(new OnDispatch(" + dispatchCnt + "));\n");
  26.169 +
  26.170 +                        dispatch.
  26.171 +                            append("      case ").append(dispatchCnt).append(": ").
  26.172 +                            append(type.getSimpleName().toString()).
  26.173 +                            append('.').append(ee.getSimpleName()).append("(").
  26.174 +                            append(params).
  26.175 +                            append("); break;\n");
  26.176 +                        
  26.177 +                        dispatchCnt++;
  26.178 +                    }
  26.179                  }
  26.180              }
  26.181 +            w.append("  }\n");
  26.182 +            if (dispatchCnt > 0) {
  26.183 +                w.append("class OnDispatch implements Runnable {\n");
  26.184 +                w.append("  private final int dispatch;\n");
  26.185 +                w.append("  OnDispatch(int d) { dispatch = d; }\n");
  26.186 +                w.append("  public void run() {\n");
  26.187 +                w.append("    switch (dispatch) {\n");
  26.188 +                w.append(dispatch);
  26.189 +                w.append("    }\n");
  26.190 +                w.append("  }\n");
  26.191 +                w.append("}\n");
  26.192 +            }
  26.193 +            
  26.194 +
  26.195          }
  26.196          return true;
  26.197      }
  26.198 @@ -235,4 +310,126 @@
  26.199          }
  26.200          return e.getEnclosingElement();
  26.201      }
  26.202 +
  26.203 +    private static void generateProperties(
  26.204 +        Writer w, Property[] properties, Collection<String> props,
  26.205 +        Map<String,Collection<String>> deps
  26.206 +    ) throws IOException {
  26.207 +        for (Property p : properties) {
  26.208 +            final String tn = typeName(p);
  26.209 +            String[] gs = toGetSet(p.name(), tn);
  26.210 +
  26.211 +            w.write("private " + tn + " prop_" + p.name() + ";\n");
  26.212 +            w.write("public " + tn + " " + gs[0] + "() {\n");
  26.213 +            w.write("  if (locked) throw new IllegalStateException();\n");
  26.214 +            w.write("  return prop_" + p.name() + ";\n");
  26.215 +            w.write("}\n");
  26.216 +            w.write("public void " + gs[1] + "(" + tn + " v) {\n");
  26.217 +            w.write("  if (locked) throw new IllegalStateException();\n");
  26.218 +            w.write("  prop_" + p.name() + " = v;\n");
  26.219 +            w.write("  if (ko != null) {\n");
  26.220 +            w.write("    ko.valueHasMutated(\"" + p.name() + "\");\n");
  26.221 +            final Collection<String> dependants = deps.get(p.name());
  26.222 +            if (dependants != null) {
  26.223 +                for (String depProp : dependants) {
  26.224 +                    w.write("    ko.valueHasMutated(\"" + depProp + "\");\n");
  26.225 +                }
  26.226 +            }
  26.227 +            w.write("  }\n");
  26.228 +            w.write("}\n");
  26.229 +            
  26.230 +            props.add(p.name());
  26.231 +            props.add(gs[2]);
  26.232 +            props.add(gs[3]);
  26.233 +            props.add(gs[0]);
  26.234 +        }
  26.235 +    }
  26.236 +
  26.237 +    private boolean generateComputedProperties(
  26.238 +        Writer w, Collection<? extends Element> arr, Collection<String> props,
  26.239 +        Map<String,Collection<String>> deps
  26.240 +    ) throws IOException {
  26.241 +        for (Element e : arr) {
  26.242 +            if (e.getKind() != ElementKind.METHOD) {
  26.243 +                continue;
  26.244 +            }
  26.245 +            if (e.getAnnotation(ComputedProperty.class) == null) {
  26.246 +                continue;
  26.247 +            }
  26.248 +            ExecutableElement ee = (ExecutableElement)e;
  26.249 +            final String tn = ee.getReturnType().toString();
  26.250 +            final String sn = ee.getSimpleName().toString();
  26.251 +            String[] gs = toGetSet(sn, tn);
  26.252 +            
  26.253 +            w.write("public " + tn + " " + gs[0] + "() {\n");
  26.254 +            w.write("  if (locked) throw new IllegalStateException();\n");
  26.255 +            int arg = 0;
  26.256 +            for (VariableElement pe : ee.getParameters()) {
  26.257 +                final String dn = pe.getSimpleName().toString();
  26.258 +                final String dt = pe.asType().toString();
  26.259 +                String[] call = toGetSet(dn, dt);
  26.260 +                w.write("  " + dt + " arg" + (++arg) + " = ");
  26.261 +                w.write(call[0] + "();\n");
  26.262 +                
  26.263 +                Collection<String> depends = deps.get(dn);
  26.264 +                if (depends == null) {
  26.265 +                    depends = new LinkedHashSet<String>();
  26.266 +                    deps.put(dn, depends);
  26.267 +                }
  26.268 +                depends.add(sn);
  26.269 +            }
  26.270 +            w.write("  try {\n");
  26.271 +            w.write("    locked = true;\n");
  26.272 +            w.write("    return " + e.getEnclosingElement().getSimpleName() + '.' + e.getSimpleName() + "(");
  26.273 +            String sep = "";
  26.274 +            for (int i = 1; i <= arg; i++) {
  26.275 +                w.write(sep);
  26.276 +                w.write("arg" + i);
  26.277 +                sep = ", ";
  26.278 +            }
  26.279 +            w.write(");\n");
  26.280 +            w.write("  } finally {\n");
  26.281 +            w.write("    locked = false;\n");
  26.282 +            w.write("  }\n");
  26.283 +            w.write("}\n");
  26.284 +            
  26.285 +            props.add(e.getSimpleName().toString());
  26.286 +            props.add(gs[2]);
  26.287 +            props.add(null);
  26.288 +            props.add(gs[0]);
  26.289 +        }
  26.290 +        
  26.291 +        return true;
  26.292 +    }
  26.293 +
  26.294 +    private static String[] toGetSet(String name, String type) {
  26.295 +        String n = Character.toUpperCase(name.charAt(0)) + name.substring(1);
  26.296 +        String bck2brwsrType = "L" + type.replace('.', '_') + "_2";
  26.297 +        if ("int".equals(type)) {
  26.298 +            bck2brwsrType = "I";
  26.299 +        }
  26.300 +        if ("double".equals(type)) {
  26.301 +            bck2brwsrType = "D";
  26.302 +        }
  26.303 +        String pref = "get";
  26.304 +        if ("boolean".equals(type)) {
  26.305 +            pref = "is";
  26.306 +            bck2brwsrType = "Z";
  26.307 +        }
  26.308 +        final String nu = n.replace('.', '_');
  26.309 +        return new String[]{
  26.310 +            pref + n, 
  26.311 +            "set" + n, 
  26.312 +            pref + nu + "__" + bck2brwsrType,
  26.313 +            "set" + nu + "__V" + bck2brwsrType
  26.314 +        };
  26.315 +    }
  26.316 +
  26.317 +    private static String typeName(Property p) {
  26.318 +        try {
  26.319 +            return p.type().getName();
  26.320 +        } catch (MirroredTypeException ex) {
  26.321 +            return ex.getTypeMirror().toString();
  26.322 +        }
  26.323 +    }
  26.324  }
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/ComputedProperty.java	Wed Jan 23 14:49:52 2013 +0100
    27.3 @@ -0,0 +1,38 @@
    27.4 +/**
    27.5 + * Back 2 Browser Bytecode Translator
    27.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    27.7 + *
    27.8 + * This program is free software: you can redistribute it and/or modify
    27.9 + * it under the terms of the GNU General Public License as published by
   27.10 + * the Free Software Foundation, version 2 of the License.
   27.11 + *
   27.12 + * This program is distributed in the hope that it will be useful,
   27.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   27.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   27.15 + * GNU General Public License for more details.
   27.16 + *
   27.17 + * You should have received a copy of the GNU General Public License
   27.18 + * along with this program. Look for COPYING file in the top folder.
   27.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   27.20 + */
   27.21 +package org.apidesign.bck2brwsr.htmlpage.api;
   27.22 +
   27.23 +import java.lang.annotation.ElementType;
   27.24 +import java.lang.annotation.Retention;
   27.25 +import java.lang.annotation.RetentionPolicy;
   27.26 +import java.lang.annotation.Target;
   27.27 +
   27.28 +/** Can be used in classes annotated with {@link Page} annotation to
   27.29 + * define a derived property. Value of derived property is based on values
   27.30 + * of {@link Property} as enumerated by {@link Page#properties()}.
   27.31 + * <p>
   27.32 + * The name of the derived property is the name of the method. The arguments
   27.33 + * of the method define the property names (from {@link Page#properties()} list)
   27.34 + * the value of property depends on. 
   27.35 + *
   27.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   27.37 + */
   27.38 +@Retention(RetentionPolicy.SOURCE)
   27.39 +@Target(ElementType.METHOD)
   27.40 +public @interface ComputedProperty {
   27.41 +}
    28.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Tue Jan 22 17:53:05 2013 +0100
    28.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Wed Jan 23 14:49:52 2013 +0100
    28.3 @@ -30,6 +30,13 @@
    28.4          this.id = id;
    28.5      }
    28.6      
    28.7 +    /** Id of the element in the document.
    28.8 +     * @return the id for this element
    28.9 +     */
   28.10 +    public String getId() {
   28.11 +        return id;
   28.12 +    }
   28.13 +    
   28.14      abstract void dontSubclass();
   28.15      
   28.16      @JavaScriptBody(
   28.17 @@ -61,7 +68,8 @@
   28.18          body="var e = window.document.getElementById(this.fld_id);\n"
   28.19             + "e[ev.fld_id] = function() { r.run__V(); };\n"
   28.20      )
   28.21 -    final native void on(OnEvent ev, Runnable r);
   28.22 +    final void on(OnEvent ev, Runnable r) {
   28.23 +    }
   28.24  
   28.25      /** Shows alert message dialog in a browser.
   28.26       * @param msg the message to show
    29.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/OnEvent.java	Tue Jan 22 17:53:05 2013 +0100
    29.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/OnEvent.java	Wed Jan 23 14:49:52 2013 +0100
    29.3 @@ -26,6 +26,7 @@
    29.4      BLUR("onblur"),
    29.5      CAN_PLAY("oncanplay"),
    29.6      CAN_PLAY_THROUGH("oncanplaythrough"),
    29.7 +    CHANGE("onchange"),
    29.8      CLICK("onclick"),
    29.9      CONTEXT_MENU("oncontextmenu"),
   29.10      DBL_CLICK("ondblclick"),
   29.11 @@ -82,6 +83,13 @@
   29.12          this.id = id;
   29.13      }
   29.14      
   29.15 +    /** The name of property this event is referenced by from an {@link Element}.
   29.16 +     * For {@link OnEvent#CHANGE}, it is <code>onchange</code>.
   29.17 +     */
   29.18 +    public String getElementPropertyName() {
   29.19 +        return id;
   29.20 +    }
   29.21 +    
   29.22      /** What should happen when this even happen on one
   29.23       * of associated elements. Continue by calling {@link OnController#perform(java.lang.Runnable)}
   29.24       * method.
    30.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Page.java	Tue Jan 22 17:53:05 2013 +0100
    30.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Page.java	Wed Jan 23 14:49:52 2013 +0100
    30.3 @@ -36,4 +36,7 @@
    30.4       * found elements with IDs.
    30.5       */
    30.6      String className() default "";
    30.7 +    /** List of properties generated into the page.
    30.8 +     */
    30.9 +    Property[] properties() default {};
   30.10  }
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Property.java	Wed Jan 23 14:49:52 2013 +0100
    31.3 @@ -0,0 +1,34 @@
    31.4 +/**
    31.5 + * Back 2 Browser Bytecode Translator
    31.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    31.7 + *
    31.8 + * This program is free software: you can redistribute it and/or modify
    31.9 + * it under the terms of the GNU General Public License as published by
   31.10 + * the Free Software Foundation, version 2 of the License.
   31.11 + *
   31.12 + * This program is distributed in the hope that it will be useful,
   31.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   31.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   31.15 + * GNU General Public License for more details.
   31.16 + *
   31.17 + * You should have received a copy of the GNU General Public License
   31.18 + * along with this program. Look for COPYING file in the top folder.
   31.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   31.20 + */
   31.21 +package org.apidesign.bck2brwsr.htmlpage.api;
   31.22 +
   31.23 +import java.lang.annotation.Retention;
   31.24 +import java.lang.annotation.RetentionPolicy;
   31.25 +import java.lang.annotation.Target;
   31.26 +
   31.27 +/** Represents a property in a generated model of an HTML
   31.28 + * {@link Page}.
   31.29 + *
   31.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   31.31 + */
   31.32 +@Retention(RetentionPolicy.SOURCE)
   31.33 +@Target({})
   31.34 +public @interface Property {
   31.35 +    String name();
   31.36 +    Class<?> type();
   31.37 +}
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/javaquery/api/src/main/resources/org/apidesign/bck2brwsr/htmlpage/knockout-2.2.1.js	Wed Jan 23 14:49:52 2013 +0100
    32.3 @@ -0,0 +1,3587 @@
    32.4 +// Knockout JavaScript library v2.2.1
    32.5 +// (c) Steven Sanderson - http://knockoutjs.com/
    32.6 +// License: MIT (http://www.opensource.org/licenses/mit-license.php)
    32.7 +
    32.8 +(function(){
    32.9 +var DEBUG=true;
   32.10 +(function(window,document,navigator,jQuery,undefined){
   32.11 +!function(factory) {
   32.12 +    // Support three module loading scenarios
   32.13 +    if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
   32.14 +        // [1] CommonJS/Node.js
   32.15 +        var target = module['exports'] || exports; // module.exports is for Node.js
   32.16 +        factory(target);
   32.17 +    } else if (typeof define === 'function' && define['amd']) {
   32.18 +        // [2] AMD anonymous module
   32.19 +        define(['exports'], factory);
   32.20 +    } else {
   32.21 +        // [3] No module loader (plain <script> tag) - put directly in global namespace
   32.22 +        factory(window['ko'] = {});
   32.23 +    }
   32.24 +}(function(koExports){
   32.25 +// Internally, all KO objects are attached to koExports (even the non-exported ones whose names will be minified by the closure compiler).
   32.26 +// In the future, the following "ko" variable may be made distinct from "koExports" so that private objects are not externally reachable.
   32.27 +var ko = typeof koExports !== 'undefined' ? koExports : {};
   32.28 +// Google Closure Compiler helpers (used only to make the minified file smaller)
   32.29 +ko.exportSymbol = function(koPath, object) {
   32.30 +	var tokens = koPath.split(".");
   32.31 +
   32.32 +	// In the future, "ko" may become distinct from "koExports" (so that non-exported objects are not reachable)
   32.33 +	// At that point, "target" would be set to: (typeof koExports !== "undefined" ? koExports : ko)
   32.34 +	var target = ko;
   32.35 +
   32.36 +	for (var i = 0; i < tokens.length - 1; i++)
   32.37 +		target = target[tokens[i]];
   32.38 +	target[tokens[tokens.length - 1]] = object;
   32.39 +};
   32.40 +ko.exportProperty = function(owner, publicName, object) {
   32.41 +  owner[publicName] = object;
   32.42 +};
   32.43 +ko.version = "2.2.1";
   32.44 +
   32.45 +ko.exportSymbol('version', ko.version);
   32.46 +ko.utils = new (function () {
   32.47 +    var stringTrimRegex = /^(\s|\u00A0)+|(\s|\u00A0)+$/g;
   32.48 +
   32.49 +    // Represent the known event types in a compact way, then at runtime transform it into a hash with event name as key (for fast lookup)
   32.50 +    var knownEvents = {}, knownEventTypesByEventName = {};
   32.51 +    var keyEventTypeName = /Firefox\/2/i.test(navigator.userAgent) ? 'KeyboardEvent' : 'UIEvents';
   32.52 +    knownEvents[keyEventTypeName] = ['keyup', 'keydown', 'keypress'];
   32.53 +    knownEvents['MouseEvents'] = ['click', 'dblclick', 'mousedown', 'mouseup', 'mousemove', 'mouseover', 'mouseout', 'mouseenter', 'mouseleave'];
   32.54 +    for (var eventType in knownEvents) {
   32.55 +        var knownEventsForType = knownEvents[eventType];
   32.56 +        if (knownEventsForType.length) {
   32.57 +            for (var i = 0, j = knownEventsForType.length; i < j; i++)
   32.58 +                knownEventTypesByEventName[knownEventsForType[i]] = eventType;
   32.59 +        }
   32.60 +    }
   32.61 +    var eventsThatMustBeRegisteredUsingAttachEvent = { 'propertychange': true }; // Workaround for an IE9 issue - https://github.com/SteveSanderson/knockout/issues/406
   32.62 +
   32.63 +    // Detect IE versions for bug workarounds (uses IE conditionals, not UA string, for robustness)
   32.64 +    // Note that, since IE 10 does not support conditional comments, the following logic only detects IE < 10.
   32.65 +    // Currently this is by design, since IE 10+ behaves correctly when treated as a standard browser.
   32.66 +    // If there is a future need to detect specific versions of IE10+, we will amend this.
   32.67 +    var ieVersion = (function() {
   32.68 +        var version = 3, div = document.createElement('div'), iElems = div.getElementsByTagName('i');
   32.69 +
   32.70 +        // Keep constructing conditional HTML blocks until we hit one that resolves to an empty fragment
   32.71 +        while (
   32.72 +            div.innerHTML = '<!--[if gt IE ' + (++version) + ']><i></i><![endif]-->',
   32.73 +            iElems[0]
   32.74 +        );
   32.75 +        return version > 4 ? version : undefined;
   32.76 +    }());
   32.77 +    var isIe6 = ieVersion === 6,
   32.78 +        isIe7 = ieVersion === 7;
   32.79 +
   32.80 +    function isClickOnCheckableElement(element, eventType) {
   32.81 +        if ((ko.utils.tagNameLower(element) !== "input") || !element.type) return false;
   32.82 +        if (eventType.toLowerCase() != "click") return false;
   32.83 +        var inputType = element.type;
   32.84 +        return (inputType == "checkbox") || (inputType == "radio");
   32.85 +    }
   32.86 +
   32.87 +    return {
   32.88 +        fieldsIncludedWithJsonPost: ['authenticity_token', /^__RequestVerificationToken(_.*)?$/],
   32.89 +
   32.90 +        arrayForEach: function (array, action) {
   32.91 +            for (var i = 0, j = array.length; i < j; i++)
   32.92 +                action(array[i]);
   32.93 +        },
   32.94 +
   32.95 +        arrayIndexOf: function (array, item) {
   32.96 +            if (typeof Array.prototype.indexOf == "function")
   32.97 +                return Array.prototype.indexOf.call(array, item);
   32.98 +            for (var i = 0, j = array.length; i < j; i++)
   32.99 +                if (array[i] === item)
  32.100 +                    return i;
  32.101 +            return -1;
  32.102 +        },
  32.103 +
  32.104 +        arrayFirst: function (array, predicate, predicateOwner) {
  32.105 +            for (var i = 0, j = array.length; i < j; i++)
  32.106 +                if (predicate.call(predicateOwner, array[i]))
  32.107 +                    return array[i];
  32.108 +            return null;
  32.109 +        },
  32.110 +
  32.111 +        arrayRemoveItem: function (array, itemToRemove) {
  32.112 +            var index = ko.utils.arrayIndexOf(array, itemToRemove);
  32.113 +            if (index >= 0)
  32.114 +                array.splice(index, 1);
  32.115 +        },
  32.116 +
  32.117 +        arrayGetDistinctValues: function (array) {
  32.118 +            array = array || [];
  32.119 +            var result = [];
  32.120 +            for (var i = 0, j = array.length; i < j; i++) {
  32.121 +                if (ko.utils.arrayIndexOf(result, array[i]) < 0)
  32.122 +                    result.push(array[i]);
  32.123 +            }
  32.124 +            return result;
  32.125 +        },
  32.126 +
  32.127 +        arrayMap: function (array, mapping) {
  32.128 +            array = array || [];
  32.129 +            var result = [];
  32.130 +            for (var i = 0, j = array.length; i < j; i++)
  32.131 +                result.push(mapping(array[i]));
  32.132 +            return result;
  32.133 +        },
  32.134 +
  32.135 +        arrayFilter: function (array, predicate) {
  32.136 +            array = array || [];
  32.137 +            var result = [];
  32.138 +            for (var i = 0, j = array.length; i < j; i++)
  32.139 +                if (predicate(array[i]))
  32.140 +                    result.push(array[i]);
  32.141 +            return result;
  32.142 +        },
  32.143 +
  32.144 +        arrayPushAll: function (array, valuesToPush) {
  32.145 +            if (valuesToPush instanceof Array)
  32.146 +                array.push.apply(array, valuesToPush);
  32.147 +            else
  32.148 +                for (var i = 0, j = valuesToPush.length; i < j; i++)
  32.149 +                    array.push(valuesToPush[i]);
  32.150 +            return array;
  32.151 +        },
  32.152 +
  32.153 +        extend: function (target, source) {
  32.154 +            if (source) {
  32.155 +                for(var prop in source) {
  32.156 +                    if(source.hasOwnProperty(prop)) {
  32.157 +                        target[prop] = source[prop];
  32.158 +                    }
  32.159 +                }
  32.160 +            }
  32.161 +            return target;
  32.162 +        },
  32.163 +
  32.164 +        emptyDomNode: function (domNode) {
  32.165 +            while (domNode.firstChild) {
  32.166 +                ko.removeNode(domNode.firstChild);
  32.167 +            }
  32.168 +        },
  32.169 +
  32.170 +        moveCleanedNodesToContainerElement: function(nodes) {
  32.171 +            // Ensure it's a real array, as we're about to reparent the nodes and
  32.172 +            // we don't want the underlying collection to change while we're doing that.
  32.173 +            var nodesArray = ko.utils.makeArray(nodes);
  32.174 +
  32.175 +            var container = document.createElement('div');
  32.176 +            for (var i = 0, j = nodesArray.length; i < j; i++) {
  32.177 +                container.appendChild(ko.cleanNode(nodesArray[i]));
  32.178 +            }
  32.179 +            return container;
  32.180 +        },
  32.181 +
  32.182 +        cloneNodes: function (nodesArray, shouldCleanNodes) {
  32.183 +            for (var i = 0, j = nodesArray.length, newNodesArray = []; i < j; i++) {
  32.184 +                var clonedNode = nodesArray[i].cloneNode(true);
  32.185 +                newNodesArray.push(shouldCleanNodes ? ko.cleanNode(clonedNode) : clonedNode);
  32.186 +            }
  32.187 +            return newNodesArray;
  32.188 +        },
  32.189 +
  32.190 +        setDomNodeChildren: function (domNode, childNodes) {
  32.191 +            ko.utils.emptyDomNode(domNode);
  32.192 +            if (childNodes) {
  32.193 +                for (var i = 0, j = childNodes.length; i < j; i++)
  32.194 +                    domNode.appendChild(childNodes[i]);
  32.195 +            }
  32.196 +        },
  32.197 +
  32.198 +        replaceDomNodes: function (nodeToReplaceOrNodeArray, newNodesArray) {
  32.199 +            var nodesToReplaceArray = nodeToReplaceOrNodeArray.nodeType ? [nodeToReplaceOrNodeArray] : nodeToReplaceOrNodeArray;
  32.200 +            if (nodesToReplaceArray.length > 0) {
  32.201 +                var insertionPoint = nodesToReplaceArray[0];
  32.202 +                var parent = insertionPoint.parentNode;
  32.203 +                for (var i = 0, j = newNodesArray.length; i < j; i++)
  32.204 +                    parent.insertBefore(newNodesArray[i], insertionPoint);
  32.205 +                for (var i = 0, j = nodesToReplaceArray.length; i < j; i++) {
  32.206 +                    ko.removeNode(nodesToReplaceArray[i]);
  32.207 +                }
  32.208 +            }
  32.209 +        },
  32.210 +
  32.211 +        setOptionNodeSelectionState: function (optionNode, isSelected) {
  32.212 +            // IE6 sometimes throws "unknown error" if you try to write to .selected directly, whereas Firefox struggles with setAttribute. Pick one based on browser.
  32.213 +            if (ieVersion < 7)
  32.214 +                optionNode.setAttribute("selected", isSelected);
  32.215 +            else
  32.216 +                optionNode.selected = isSelected;
  32.217 +        },
  32.218 +
  32.219 +        stringTrim: function (string) {
  32.220 +            return (string || "").replace(stringTrimRegex, "");
  32.221 +        },
  32.222 +
  32.223 +        stringTokenize: function (string, delimiter) {
  32.224 +            var result = [];
  32.225 +            var tokens = (string || "").split(delimiter);
  32.226 +            for (var i = 0, j = tokens.length; i < j; i++) {
  32.227 +                var trimmed = ko.utils.stringTrim(tokens[i]);
  32.228 +                if (trimmed !== "")
  32.229 +                    result.push(trimmed);
  32.230 +            }
  32.231 +            return result;
  32.232 +        },
  32.233 +
  32.234 +        stringStartsWith: function (string, startsWith) {
  32.235 +            string = string || "";
  32.236 +            if (startsWith.length > string.length)
  32.237 +                return false;
  32.238 +            return string.substring(0, startsWith.length) === startsWith;
  32.239 +        },
  32.240 +
  32.241 +        domNodeIsContainedBy: function (node, containedByNode) {
  32.242 +            if (containedByNode.compareDocumentPosition)
  32.243 +                return (containedByNode.compareDocumentPosition(node) & 16) == 16;
  32.244 +            while (node != null) {
  32.245 +                if (node == containedByNode)
  32.246 +                    return true;
  32.247 +                node = node.parentNode;
  32.248 +            }
  32.249 +            return false;
  32.250 +        },
  32.251 +
  32.252 +        domNodeIsAttachedToDocument: function (node) {
  32.253 +            return ko.utils.domNodeIsContainedBy(node, node.ownerDocument);
  32.254 +        },
  32.255 +
  32.256 +        tagNameLower: function(element) {
  32.257 +            // For HTML elements, tagName will always be upper case; for XHTML elements, it'll be lower case.
  32.258 +            // Possible future optimization: If we know it's an element from an XHTML document (not HTML),
  32.259 +            // we don't need to do the .toLowerCase() as it will always be lower case anyway.
  32.260 +            return element && element.tagName && element.tagName.toLowerCase();
  32.261 +        },
  32.262 +
  32.263 +        registerEventHandler: function (element, eventType, handler) {
  32.264 +            var mustUseAttachEvent = ieVersion && eventsThatMustBeRegisteredUsingAttachEvent[eventType];
  32.265 +            if (!mustUseAttachEvent && typeof jQuery != "undefined") {
  32.266 +                if (isClickOnCheckableElement(element, eventType)) {
  32.267 +                    // For click events on checkboxes, jQuery interferes with the event handling in an awkward way:
  32.268 +                    // it toggles the element checked state *after* the click event handlers run, whereas native
  32.269 +                    // click events toggle the checked state *before* the event handler.
  32.270 +                    // Fix this by intecepting the handler and applying the correct checkedness before it runs.
  32.271 +                    var originalHandler = handler;
  32.272 +                    handler = function(event, eventData) {
  32.273 +                        var jQuerySuppliedCheckedState = this.checked;
  32.274 +                        if (eventData)
  32.275 +                            this.checked = eventData.checkedStateBeforeEvent !== true;
  32.276 +                        originalHandler.call(this, event);
  32.277 +                        this.checked = jQuerySuppliedCheckedState; // Restore the state jQuery applied
  32.278 +                    };
  32.279 +                }
  32.280 +                jQuery(element)['bind'](eventType, handler);
  32.281 +            } else if (!mustUseAttachEvent && typeof element.addEventListener == "function")
  32.282 +                element.addEventListener(eventType, handler, false);
  32.283 +            else if (typeof element.attachEvent != "undefined")
  32.284 +                element.attachEvent("on" + eventType, function (event) {
  32.285 +                    handler.call(element, event);
  32.286 +                });
  32.287 +            else
  32.288 +                throw new Error("Browser doesn't support addEventListener or attachEvent");
  32.289 +        },
  32.290 +
  32.291 +        triggerEvent: function (element, eventType) {
  32.292 +            if (!(element && element.nodeType))
  32.293 +                throw new Error("element must be a DOM node when calling triggerEvent");
  32.294 +
  32.295 +            if (typeof jQuery != "undefined") {
  32.296 +                var eventData = [];
  32.297 +                if (isClickOnCheckableElement(element, eventType)) {
  32.298 +                    // Work around the jQuery "click events on checkboxes" issue described above by storing the original checked state before triggering the handler
  32.299 +                    eventData.push({ checkedStateBeforeEvent: element.checked });
  32.300 +                }
  32.301 +                jQuery(element)['trigger'](eventType, eventData);
  32.302 +            } else if (typeof document.createEvent == "function") {
  32.303 +                if (typeof element.dispatchEvent == "function") {
  32.304 +                    var eventCategory = knownEventTypesByEventName[eventType] || "HTMLEvents";
  32.305 +                    var event = document.createEvent(eventCategory);
  32.306 +                    event.initEvent(eventType, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, element);
  32.307 +                    element.dispatchEvent(event);
  32.308 +                }
  32.309 +                else
  32.310 +                    throw new Error("The supplied element doesn't support dispatchEvent");
  32.311 +            } else if (typeof element.fireEvent != "undefined") {
  32.312 +                // Unlike other browsers, IE doesn't change the checked state of checkboxes/radiobuttons when you trigger their "click" event
  32.313 +                // so to make it consistent, we'll do it manually here
  32.314 +                if (isClickOnCheckableElement(element, eventType))
  32.315 +                    element.checked = element.checked !== true;
  32.316 +                element.fireEvent("on" + eventType);
  32.317 +            }
  32.318 +            else
  32.319 +                throw new Error("Browser doesn't support triggering events");
  32.320 +        },
  32.321 +
  32.322 +        unwrapObservable: function (value) {
  32.323 +            return ko.isObservable(value) ? value() : value;
  32.324 +        },
  32.325 +
  32.326 +        peekObservable: function (value) {
  32.327 +            return ko.isObservable(value) ? value.peek() : value;
  32.328 +        },
  32.329 +
  32.330 +        toggleDomNodeCssClass: function (node, classNames, shouldHaveClass) {
  32.331 +            if (classNames) {
  32.332 +                var cssClassNameRegex = /[\w-]+/g,
  32.333 +                    currentClassNames = node.className.match(cssClassNameRegex) || [];
  32.334 +                ko.utils.arrayForEach(classNames.match(cssClassNameRegex), function(className) {
  32.335 +                    var indexOfClass = ko.utils.arrayIndexOf(currentClassNames, className);
  32.336 +                    if (indexOfClass >= 0) {
  32.337 +                        if (!shouldHaveClass)
  32.338 +                            currentClassNames.splice(indexOfClass, 1);
  32.339 +                    } else {
  32.340 +                        if (shouldHaveClass)
  32.341 +                            currentClassNames.push(className);
  32.342 +                    }
  32.343 +                });
  32.344 +                node.className = currentClassNames.join(" ");
  32.345 +            }
  32.346 +        },
  32.347 +
  32.348 +        setTextContent: function(element, textContent) {
  32.349 +            var value = ko.utils.unwrapObservable(textContent);
  32.350 +            if ((value === null) || (value === undefined))
  32.351 +                value = "";
  32.352 +
  32.353 +            if (element.nodeType === 3) {
  32.354 +                element.data = value;
  32.355 +            } else {
  32.356 +                // We need there to be exactly one child: a text node.
  32.357 +                // If there are no children, more than one, or if it's not a text node,
  32.358 +                // we'll clear everything and create a single text node.
  32.359 +                var innerTextNode = ko.virtualElements.firstChild(element);
  32.360 +                if (!innerTextNode || innerTextNode.nodeType != 3 || ko.virtualElements.nextSibling(innerTextNode)) {
  32.361 +                    ko.virtualElements.setDomNodeChildren(element, [document.createTextNode(value)]);
  32.362 +                } else {
  32.363 +                    innerTextNode.data = value;
  32.364 +                }
  32.365 +
  32.366 +                ko.utils.forceRefresh(element);
  32.367 +            }
  32.368 +        },
  32.369 +
  32.370 +        setElementName: function(element, name) {
  32.371 +            element.name = name;
  32.372 +
  32.373 +            // Workaround IE 6/7 issue
  32.374 +            // - https://github.com/SteveSanderson/knockout/issues/197
  32.375 +            // - http://www.matts411.com/post/setting_the_name_attribute_in_ie_dom/
  32.376 +            if (ieVersion <= 7) {
  32.377 +                try {
  32.378 +                    element.mergeAttributes(document.createElement("<input name='" + element.name + "'/>"), false);
  32.379 +                }
  32.380 +                catch(e) {} // For IE9 with doc mode "IE9 Standards" and browser mode "IE9 Compatibility View"
  32.381 +            }
  32.382 +        },
  32.383 +
  32.384 +        forceRefresh: function(node) {
  32.385 +            // Workaround for an IE9 rendering bug - https://github.com/SteveSanderson/knockout/issues/209
  32.386 +            if (ieVersion >= 9) {
  32.387 +                // For text nodes and comment nodes (most likely virtual elements), we will have to refresh the container
  32.388 +                var elem = node.nodeType == 1 ? node : node.parentNode;
  32.389 +                if (elem.style)
  32.390 +                    elem.style.zoom = elem.style.zoom;
  32.391 +            }
  32.392 +        },
  32.393 +
  32.394 +        ensureSelectElementIsRenderedCorrectly: function(selectElement) {
  32.395 +            // Workaround for IE9 rendering bug - it doesn't reliably display all the text in dynamically-added select boxes unless you force it to re-render by updating the width.
  32.396 +            // (See https://github.com/SteveSanderson/knockout/issues/312, http://stackoverflow.com/questions/5908494/select-only-shows-first-char-of-selected-option)
  32.397 +            if (ieVersion >= 9) {
  32.398 +                var originalWidth = selectElement.style.width;
  32.399 +                selectElement.style.width = 0;
  32.400 +                selectElement.style.width = originalWidth;
  32.401 +            }
  32.402 +        },
  32.403 +
  32.404 +        range: function (min, max) {
  32.405 +            min = ko.utils.unwrapObservable(min);
  32.406 +            max = ko.utils.unwrapObservable(max);
  32.407 +            var result = [];
  32.408 +            for (var i = min; i <= max; i++)
  32.409 +                result.push(i);
  32.410 +            return result;
  32.411 +        },
  32.412 +
  32.413 +        makeArray: function(arrayLikeObject) {
  32.414 +            var result = [];
  32.415 +            for (var i = 0, j = arrayLikeObject.length; i < j; i++) {
  32.416 +                result.push(arrayLikeObject[i]);
  32.417 +            };
  32.418 +            return result;
  32.419 +        },
  32.420 +
  32.421 +        isIe6 : isIe6,
  32.422 +        isIe7 : isIe7,
  32.423 +        ieVersion : ieVersion,
  32.424 +
  32.425 +        getFormFields: function(form, fieldName) {
  32.426 +            var fields = ko.utils.makeArray(form.getElementsByTagName("input")).concat(ko.utils.makeArray(form.getElementsByTagName("textarea")));
  32.427 +            var isMatchingField = (typeof fieldName == 'string')
  32.428 +                ? function(field) { return field.name === fieldName }
  32.429 +                : function(field) { return fieldName.test(field.name) }; // Treat fieldName as regex or object containing predicate
  32.430 +            var matches = [];
  32.431 +            for (var i = fields.length - 1; i >= 0; i--) {
  32.432 +                if (isMatchingField(fields[i]))
  32.433 +                    matches.push(fields[i]);
  32.434 +            };
  32.435 +            return matches;
  32.436 +        },
  32.437 +
  32.438 +        parseJson: function (jsonString) {
  32.439 +            if (typeof jsonString == "string") {
  32.440 +                jsonString = ko.utils.stringTrim(jsonString);
  32.441 +                if (jsonString) {
  32.442 +                    if (window.JSON && window.JSON.parse) // Use native parsing where available
  32.443 +                        return window.JSON.parse(jsonString);
  32.444 +                    return (new Function("return " + jsonString))(); // Fallback on less safe parsing for older browsers
  32.445 +                }
  32.446 +            }
  32.447 +            return null;
  32.448 +        },
  32.449 +
  32.450 +        stringifyJson: function (data, replacer, space) {   // replacer and space are optional
  32.451 +            if ((typeof JSON == "undefined") || (typeof JSON.stringify == "undefined"))
  32.452 +                throw new Error("Cannot find JSON.stringify(). Some browsers (e.g., IE < 8) don't support it natively, but you can overcome this by adding a script reference to json2.js, downloadable from http://www.json.org/json2.js");
  32.453 +            return JSON.stringify(ko.utils.unwrapObservable(data), replacer, space);
  32.454 +        },
  32.455 +
  32.456 +        postJson: function (urlOrForm, data, options) {
  32.457 +            options = options || {};
  32.458 +            var params = options['params'] || {};
  32.459 +            var includeFields = options['includeFields'] || this.fieldsIncludedWithJsonPost;
  32.460 +            var url = urlOrForm;
  32.461 +
  32.462 +            // If we were given a form, use its 'action' URL and pick out any requested field values
  32.463 +            if((typeof urlOrForm == 'object') && (ko.utils.tagNameLower(urlOrForm) === "form")) {
  32.464 +                var originalForm = urlOrForm;
  32.465 +                url = originalForm.action;
  32.466 +                for (var i = includeFields.length - 1; i >= 0; i--) {
  32.467 +                    var fields = ko.utils.getFormFields(originalForm, includeFields[i]);
  32.468 +                    for (var j = fields.length - 1; j >= 0; j--)
  32.469 +                        params[fields[j].name] = fields[j].value;
  32.470 +                }
  32.471 +            }
  32.472 +
  32.473 +            data = ko.utils.unwrapObservable(data);
  32.474 +            var form = document.createElement("form");
  32.475 +            form.style.display = "none";
  32.476 +            form.action = url;
  32.477 +            form.method = "post";
  32.478 +            for (var key in data) {
  32.479 +                var input = document.createElement("input");
  32.480 +                input.name = key;
  32.481 +                input.value = ko.utils.stringifyJson(ko.utils.unwrapObservable(data[key]));
  32.482 +                form.appendChild(input);
  32.483 +            }
  32.484 +            for (var key in params) {
  32.485 +                var input = document.createElement("input");
  32.486 +                input.name = key;
  32.487 +                input.value = params[key];
  32.488 +                form.appendChild(input);
  32.489 +            }
  32.490 +            document.body.appendChild(form);
  32.491 +            options['submitter'] ? options['submitter'](form) : form.submit();
  32.492 +            setTimeout(function () { form.parentNode.removeChild(form); }, 0);
  32.493 +        }
  32.494 +    }
  32.495 +})();
  32.496 +
  32.497 +ko.exportSymbol('utils', ko.utils);
  32.498 +ko.exportSymbol('utils.arrayForEach', ko.utils.arrayForEach);
  32.499 +ko.exportSymbol('utils.arrayFirst', ko.utils.arrayFirst);
  32.500 +ko.exportSymbol('utils.arrayFilter', ko.utils.arrayFilter);
  32.501 +ko.exportSymbol('utils.arrayGetDistinctValues', ko.utils.arrayGetDistinctValues);
  32.502 +ko.exportSymbol('utils.arrayIndexOf', ko.utils.arrayIndexOf);
  32.503 +ko.exportSymbol('utils.arrayMap', ko.utils.arrayMap);
  32.504 +ko.exportSymbol('utils.arrayPushAll', ko.utils.arrayPushAll);
  32.505 +ko.exportSymbol('utils.arrayRemoveItem', ko.utils.arrayRemoveItem);
  32.506 +ko.exportSymbol('utils.extend', ko.utils.extend);
  32.507 +ko.exportSymbol('utils.fieldsIncludedWithJsonPost', ko.utils.fieldsIncludedWithJsonPost);
  32.508 +ko.exportSymbol('utils.getFormFields', ko.utils.getFormFields);
  32.509 +ko.exportSymbol('utils.peekObservable', ko.utils.peekObservable);
  32.510 +ko.exportSymbol('utils.postJson', ko.utils.postJson);
  32.511 +ko.exportSymbol('utils.parseJson', ko.utils.parseJson);
  32.512 +ko.exportSymbol('utils.registerEventHandler', ko.utils.registerEventHandler);
  32.513 +ko.exportSymbol('utils.stringifyJson', ko.utils.stringifyJson);
  32.514 +ko.exportSymbol('utils.range', ko.utils.range);
  32.515 +ko.exportSymbol('utils.toggleDomNodeCssClass', ko.utils.toggleDomNodeCssClass);
  32.516 +ko.exportSymbol('utils.triggerEvent', ko.utils.triggerEvent);
  32.517 +ko.exportSymbol('utils.unwrapObservable', ko.utils.unwrapObservable);
  32.518 +
  32.519 +if (!Function.prototype['bind']) {
  32.520 +    // Function.prototype.bind is a standard part of ECMAScript 5th Edition (December 2009, http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf)
  32.521 +    // In case the browser doesn't implement it natively, provide a JavaScript implementation. This implementation is based on the one in prototype.js
  32.522 +    Function.prototype['bind'] = function (object) {
  32.523 +        var originalFunction = this, args = Array.prototype.slice.call(arguments), object = args.shift();
  32.524 +        return function () {
  32.525 +            return originalFunction.apply(object, args.concat(Array.prototype.slice.call(arguments)));
  32.526 +        };
  32.527 +    };
  32.528 +}
  32.529 +
  32.530 +ko.utils.domData = new (function () {
  32.531 +    var uniqueId = 0;
  32.532 +    var dataStoreKeyExpandoPropertyName = "__ko__" + (new Date).getTime();
  32.533 +    var dataStore = {};
  32.534 +    return {
  32.535 +        get: function (node, key) {
  32.536 +            var allDataForNode = ko.utils.domData.getAll(node, false);
  32.537 +            return allDataForNode === undefined ? undefined : allDataForNode[key];
  32.538 +        },
  32.539 +        set: function (node, key, value) {
  32.540 +            if (value === undefined) {
  32.541 +                // Make sure we don't actually create a new domData key if we are actually deleting a value
  32.542 +                if (ko.utils.domData.getAll(node, false) === undefined)
  32.543 +                    return;
  32.544 +            }
  32.545 +            var allDataForNode = ko.utils.domData.getAll(node, true);
  32.546 +            allDataForNode[key] = value;
  32.547 +        },
  32.548 +        getAll: function (node, createIfNotFound) {
  32.549 +            var dataStoreKey = node[dataStoreKeyExpandoPropertyName];
  32.550 +            var hasExistingDataStore = dataStoreKey && (dataStoreKey !== "null") && dataStore[dataStoreKey];
  32.551 +            if (!hasExistingDataStore) {
  32.552 +                if (!createIfNotFound)
  32.553 +                    return undefined;
  32.554 +                dataStoreKey = node[dataStoreKeyExpandoPropertyName] = "ko" + uniqueId++;
  32.555 +                dataStore[dataStoreKey] = {};
  32.556 +            }
  32.557 +            return dataStore[dataStoreKey];
  32.558 +        },
  32.559 +        clear: function (node) {
  32.560 +            var dataStoreKey = node[dataStoreKeyExpandoPropertyName];
  32.561 +            if (dataStoreKey) {
  32.562 +                delete dataStore[dataStoreKey];
  32.563 +                node[dataStoreKeyExpandoPropertyName] = null;
  32.564 +                return true; // Exposing "did clean" flag purely so specs can infer whether things have been cleaned up as intended
  32.565 +            }
  32.566 +            return false;
  32.567 +        }
  32.568 +    }
  32.569 +})();
  32.570 +
  32.571 +ko.exportSymbol('utils.domData', ko.utils.domData);
  32.572 +ko.exportSymbol('utils.domData.clear', ko.utils.domData.clear); // Exporting only so specs can clear up after themselves fully
  32.573 +
  32.574 +ko.utils.domNodeDisposal = new (function () {
  32.575 +    var domDataKey = "__ko_domNodeDisposal__" + (new Date).getTime();
  32.576 +    var cleanableNodeTypes = { 1: true, 8: true, 9: true };       // Element, Comment, Document
  32.577 +    var cleanableNodeTypesWithDescendants = { 1: true, 9: true }; // Element, Document
  32.578 +
  32.579 +    function getDisposeCallbacksCollection(node, createIfNotFound) {
  32.580 +        var allDisposeCallbacks = ko.utils.domData.get(node, domDataKey);
  32.581 +        if ((allDisposeCallbacks === undefined) && createIfNotFound) {
  32.582 +            allDisposeCallbacks = [];
  32.583 +            ko.utils.domData.set(node, domDataKey, allDisposeCallbacks);
  32.584 +        }
  32.585 +        return allDisposeCallbacks;
  32.586 +    }
  32.587 +    function destroyCallbacksCollection(node) {
  32.588 +        ko.utils.domData.set(node, domDataKey, undefined);
  32.589 +    }
  32.590 +
  32.591 +    function cleanSingleNode(node) {
  32.592 +        // Run all the dispose callbacks
  32.593 +        var callbacks = getDisposeCallbacksCollection(node, false);
  32.594 +        if (callbacks) {
  32.595 +            callbacks = callbacks.slice(0); // Clone, as the array may be modified during iteration (typically, callbacks will remove themselves)
  32.596 +            for (var i = 0; i < callbacks.length; i++)
  32.597 +                callbacks[i](node);
  32.598 +        }
  32.599 +
  32.600 +        // Also erase the DOM data
  32.601 +        ko.utils.domData.clear(node);
  32.602 +
  32.603 +        // Special support for jQuery here because it's so commonly used.
  32.604 +        // Many jQuery plugins (including jquery.tmpl) store data using jQuery's equivalent of domData
  32.605 +        // so notify it to tear down any resources associated with the node & descendants here.
  32.606 +        if ((typeof jQuery == "function") && (typeof jQuery['cleanData'] == "function"))
  32.607 +            jQuery['cleanData']([node]);
  32.608 +
  32.609 +        // Also clear any immediate-child comment nodes, as these wouldn't have been found by
  32.610 +        // node.getElementsByTagName("*") in cleanNode() (comment nodes aren't elements)
  32.611 +        if (cleanableNodeTypesWithDescendants[node.nodeType])
  32.612 +            cleanImmediateCommentTypeChildren(node);
  32.613 +    }
  32.614 +
  32.615 +    function cleanImmediateCommentTypeChildren(nodeWithChildren) {
  32.616 +        var child, nextChild = nodeWithChildren.firstChild;
  32.617 +        while (child = nextChild) {
  32.618 +            nextChild = child.nextSibling;
  32.619 +            if (child.nodeType === 8)
  32.620 +                cleanSingleNode(child);
  32.621 +        }
  32.622 +    }
  32.623 +
  32.624 +    return {
  32.625 +        addDisposeCallback : function(node, callback) {
  32.626 +            if (typeof callback != "function")
  32.627 +                throw new Error("Callback must be a function");
  32.628 +            getDisposeCallbacksCollection(node, true).push(callback);
  32.629 +        },
  32.630 +
  32.631 +        removeDisposeCallback : function(node, callback) {
  32.632 +            var callbacksCollection = getDisposeCallbacksCollection(node, false);
  32.633 +            if (callbacksCollection) {
  32.634 +                ko.utils.arrayRemoveItem(callbacksCollection, callback);
  32.635 +                if (callbacksCollection.length == 0)
  32.636 +                    destroyCallbacksCollection(node);
  32.637 +            }
  32.638 +        },
  32.639 +
  32.640 +        cleanNode : function(node) {
  32.641 +            // First clean this node, where applicable
  32.642 +            if (cleanableNodeTypes[node.nodeType]) {
  32.643 +                cleanSingleNode(node);
  32.644 +
  32.645 +                // ... then its descendants, where applicable
  32.646 +                if (cleanableNodeTypesWithDescendants[node.nodeType]) {
  32.647 +                    // Clone the descendants list in case it changes during iteration
  32.648 +                    var descendants = [];
  32.649 +                    ko.utils.arrayPushAll(descendants, node.getElementsByTagName("*"));
  32.650 +                    for (var i = 0, j = descendants.length; i < j; i++)
  32.651 +                        cleanSingleNode(descendants[i]);
  32.652 +                }
  32.653 +            }
  32.654 +            return node;
  32.655 +        },
  32.656 +
  32.657 +        removeNode : function(node) {
  32.658 +            ko.cleanNode(node);
  32.659 +            if (node.parentNode)
  32.660 +                node.parentNode.removeChild(node);
  32.661 +        }
  32.662 +    }
  32.663 +})();
  32.664 +ko.cleanNode = ko.utils.domNodeDisposal.cleanNode; // Shorthand name for convenience
  32.665 +ko.removeNode = ko.utils.domNodeDisposal.removeNode; // Shorthand name for convenience
  32.666 +ko.exportSymbol('cleanNode', ko.cleanNode);
  32.667 +ko.exportSymbol('removeNode', ko.removeNode);
  32.668 +ko.exportSymbol('utils.domNodeDisposal', ko.utils.domNodeDisposal);
  32.669 +ko.exportSymbol('utils.domNodeDisposal.addDisposeCallback', ko.utils.domNodeDisposal.addDisposeCallback);
  32.670 +ko.exportSymbol('utils.domNodeDisposal.removeDisposeCallback', ko.utils.domNodeDisposal.removeDisposeCallback);
  32.671 +(function () {
  32.672 +    var leadingCommentRegex = /^(\s*)<!--(.*?)-->/;
  32.673 +
  32.674 +    function simpleHtmlParse(html) {
  32.675 +        // Based on jQuery's "clean" function, but only accounting for table-related elements.
  32.676 +        // If you have referenced jQuery, this won't be used anyway - KO will use jQuery's "clean" function directly
  32.677 +
  32.678 +        // Note that there's still an issue in IE < 9 whereby it will discard comment nodes that are the first child of
  32.679 +        // a descendant node. For example: "<div><!-- mycomment -->abc</div>" will get parsed as "<div>abc</div>"
  32.680 +        // This won't affect anyone who has referenced jQuery, and there's always the workaround of inserting a dummy node
  32.681 +        // (possibly a text node) in front of the comment. So, KO does not attempt to workaround this IE issue automatically at present.
  32.682 +
  32.683 +        // Trim whitespace, otherwise indexOf won't work as expected
  32.684 +        var tags = ko.utils.stringTrim(html).toLowerCase(), div = document.createElement("div");
  32.685 +
  32.686 +        // Finds the first match from the left column, and returns the corresponding "wrap" data from the right column
  32.687 +        var wrap = tags.match(/^<(thead|tbody|tfoot)/)              && [1, "<table>", "</table>"] ||
  32.688 +                   !tags.indexOf("<tr")                             && [2, "<table><tbody>", "</tbody></table>"] ||
  32.689 +                   (!tags.indexOf("<td") || !tags.indexOf("<th"))   && [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
  32.690 +                   /* anything else */                                 [0, "", ""];
  32.691 +
  32.692 +        // Go to html and back, then peel off extra wrappers
  32.693 +        // Note that we always prefix with some dummy text, because otherwise, IE<9 will strip out leading comment nodes in descendants. Total madness.
  32.694 +        var markup = "ignored<div>" + wrap[1] + html + wrap[2] + "</div>";
  32.695 +        if (typeof window['innerShiv'] == "function") {
  32.696 +            div.appendChild(window['innerShiv'](markup));
  32.697 +        } else {
  32.698 +            div.innerHTML = markup;
  32.699 +        }
  32.700 +
  32.701 +        // Move to the right depth
  32.702 +        while (wrap[0]--)
  32.703 +            div = div.lastChild;
  32.704 +
  32.705 +        return ko.utils.makeArray(div.lastChild.childNodes);
  32.706 +    }
  32.707 +
  32.708 +    function jQueryHtmlParse(html) {
  32.709 +        // jQuery's "parseHTML" function was introduced in jQuery 1.8.0 and is a documented public API.
  32.710 +        if (jQuery['parseHTML']) {
  32.711 +            return jQuery['parseHTML'](html);
  32.712 +        } else {
  32.713 +            // For jQuery < 1.8.0, we fall back on the undocumented internal "clean" function.
  32.714 +            var elems = jQuery['clean']([html]);
  32.715 +
  32.716 +            // As of jQuery 1.7.1, jQuery parses the HTML by appending it to some dummy parent nodes held in an in-memory document fragment.
  32.717 +            // Unfortunately, it never clears the dummy parent nodes from the document fragment, so it leaks memory over time.
  32.718 +            // Fix this by finding the top-most dummy parent element, and detaching it from its owner fragment.
  32.719 +            if (elems && elems[0]) {
  32.720 +                // Find the top-most parent element that's a direct child of a document fragment
  32.721 +                var elem = elems[0];
  32.722 +                while (elem.parentNode && elem.parentNode.nodeType !== 11 /* i.e., DocumentFragment */)
  32.723 +                    elem = elem.parentNode;
  32.724 +                // ... then detach it
  32.725 +                if (elem.parentNode)
  32.726 +                    elem.parentNode.removeChild(elem);
  32.727 +            }
  32.728 +
  32.729 +            return elems;
  32.730 +        }
  32.731 +    }
  32.732 +
  32.733 +    ko.utils.parseHtmlFragment = function(html) {
  32.734 +        return typeof jQuery != 'undefined' ? jQueryHtmlParse(html)   // As below, benefit from jQuery's optimisations where possible
  32.735 +                                            : simpleHtmlParse(html);  // ... otherwise, this simple logic will do in most common cases.
  32.736 +    };
  32.737 +
  32.738 +    ko.utils.setHtml = function(node, html) {
  32.739 +        ko.utils.emptyDomNode(node);
  32.740 +
  32.741 +        // There's no legitimate reason to display a stringified observable without unwrapping it, so we'll unwrap it
  32.742 +        html = ko.utils.unwrapObservable(html);
  32.743 +
  32.744 +        if ((html !== null) && (html !== undefined)) {
  32.745 +            if (typeof html != 'string')
  32.746 +                html = html.toString();
  32.747 +
  32.748 +            // jQuery contains a lot of sophisticated code to parse arbitrary HTML fragments,
  32.749 +            // for example <tr> elements which are not normally allowed to exist on their own.
  32.750 +            // If you've referenced jQuery we'll use that rather than duplicating its code.
  32.751 +            if (typeof jQuery != 'undefined') {
  32.752 +                jQuery(node)['html'](html);
  32.753 +            } else {
  32.754 +                // ... otherwise, use KO's own parsing logic.
  32.755 +                var parsedNodes = ko.utils.parseHtmlFragment(html);
  32.756 +                for (var i = 0; i < parsedNodes.length; i++)
  32.757 +                    node.appendChild(parsedNodes[i]);
  32.758 +            }
  32.759 +        }
  32.760 +    };
  32.761 +})();
  32.762 +
  32.763 +ko.exportSymbol('utils.parseHtmlFragment', ko.utils.parseHtmlFragment);
  32.764 +ko.exportSymbol('utils.setHtml', ko.utils.setHtml);
  32.765 +
  32.766 +ko.memoization = (function () {
  32.767 +    var memos = {};
  32.768 +
  32.769 +    function randomMax8HexChars() {
  32.770 +        return (((1 + Math.random()) * 0x100000000) | 0).toString(16).substring(1);
  32.771 +    }
  32.772 +    function generateRandomId() {
  32.773 +        return randomMax8HexChars() + randomMax8HexChars();
  32.774 +    }
  32.775 +    function findMemoNodes(rootNode, appendToArray) {
  32.776 +        if (!rootNode)
  32.777 +            return;
  32.778 +        if (rootNode.nodeType == 8) {
  32.779 +            var memoId = ko.memoization.parseMemoText(rootNode.nodeValue);
  32.780 +            if (memoId != null)
  32.781 +                appendToArray.push({ domNode: rootNode, memoId: memoId });
  32.782 +        } else if (rootNode.nodeType == 1) {
  32.783 +            for (var i = 0, childNodes = rootNode.childNodes, j = childNodes.length; i < j; i++)
  32.784 +                findMemoNodes(childNodes[i], appendToArray);
  32.785 +        }
  32.786 +    }
  32.787 +
  32.788 +    return {
  32.789 +        memoize: function (callback) {
  32.790 +            if (typeof callback != "function")
  32.791 +                throw new Error("You can only pass a function to ko.memoization.memoize()");
  32.792 +            var memoId = generateRandomId();
  32.793 +            memos[memoId] = callback;
  32.794 +            return "<!--[ko_memo:" + memoId + "]-->";
  32.795 +        },
  32.796 +
  32.797 +        unmemoize: function (memoId, callbackParams) {
  32.798 +            var callback = memos[memoId];
  32.799 +            if (callback === undefined)
  32.800 +                throw new Error("Couldn't find any memo with ID " + memoId + ". Perhaps it's already been unmemoized.");
  32.801 +            try {
  32.802 +                callback.apply(null, callbackParams || []);
  32.803 +                return true;
  32.804 +            }
  32.805 +            finally { delete memos[memoId]; }
  32.806 +        },
  32.807 +
  32.808 +        unmemoizeDomNodeAndDescendants: function (domNode, extraCallbackParamsArray) {
  32.809 +            var memos = [];
  32.810 +            findMemoNodes(domNode, memos);
  32.811 +            for (var i = 0, j = memos.length; i < j; i++) {
  32.812 +                var node = memos[i].domNode;
  32.813 +                var combinedParams = [node];
  32.814 +                if (extraCallbackParamsArray)
  32.815 +                    ko.utils.arrayPushAll(combinedParams, extraCallbackParamsArray);
  32.816 +                ko.memoization.unmemoize(memos[i].memoId, combinedParams);
  32.817 +                node.nodeValue = ""; // Neuter this node so we don't try to unmemoize it again
  32.818 +                if (node.parentNode)
  32.819 +                    node.parentNode.removeChild(node); // If possible, erase it totally (not always possible - someone else might just hold a reference to it then call unmemoizeDomNodeAndDescendants again)
  32.820 +            }
  32.821 +        },
  32.822 +
  32.823 +        parseMemoText: function (memoText) {
  32.824 +            var match = memoText.match(/^\[ko_memo\:(.*?)\]$/);
  32.825 +            return match ? match[1] : null;
  32.826 +        }
  32.827 +    };
  32.828 +})();
  32.829 +
  32.830 +ko.exportSymbol('memoization', ko.memoization);
  32.831 +ko.exportSymbol('memoization.memoize', ko.memoization.memoize);
  32.832 +ko.exportSymbol('memoization.unmemoize', ko.memoization.unmemoize);
  32.833 +ko.exportSymbol('memoization.parseMemoText', ko.memoization.parseMemoText);
  32.834 +ko.exportSymbol('memoization.unmemoizeDomNodeAndDescendants', ko.memoization.unmemoizeDomNodeAndDescendants);
  32.835 +ko.extenders = {
  32.836 +    'throttle': function(target, timeout) {
  32.837 +        // Throttling means two things:
  32.838 +
  32.839 +        // (1) For dependent observables, we throttle *evaluations* so that, no matter how fast its dependencies
  32.840 +        //     notify updates, the target doesn't re-evaluate (and hence doesn't notify) faster than a certain rate
  32.841 +        target['throttleEvaluation'] = timeout;
  32.842 +
  32.843 +        // (2) For writable targets (observables, or writable dependent observables), we throttle *writes*
  32.844 +        //     so the target cannot change value synchronously or faster than a certain rate
  32.845 +        var writeTimeoutInstance = null;
  32.846 +        return ko.dependentObservable({
  32.847 +            'read': target,
  32.848 +            'write': function(value) {
  32.849 +                clearTimeout(writeTimeoutInstance);
  32.850 +                writeTimeoutInstance = setTimeout(function() {
  32.851 +                    target(value);
  32.852 +                }, timeout);
  32.853 +            }
  32.854 +        });
  32.855 +    },
  32.856 +
  32.857 +    'notify': function(target, notifyWhen) {
  32.858 +        target["equalityComparer"] = notifyWhen == "always"
  32.859 +            ? function() { return false } // Treat all values as not equal
  32.860 +            : ko.observable["fn"]["equalityComparer"];
  32.861 +        return target;
  32.862 +    }
  32.863 +};
  32.864 +
  32.865 +function applyExtenders(requestedExtenders) {
  32.866 +    var target = this;
  32.867 +    if (requestedExtenders) {
  32.868 +        for (var key in requestedExtenders) {
  32.869 +            var extenderHandler = ko.extenders[key];
  32.870 +            if (typeof extenderHandler == 'function') {
  32.871 +                target = extenderHandler(target, requestedExtenders[key]);
  32.872 +            }
  32.873 +        }
  32.874 +    }
  32.875 +    return target;
  32.876 +}
  32.877 +
  32.878 +ko.exportSymbol('extenders', ko.extenders);
  32.879 +
  32.880 +ko.subscription = function (target, callback, disposeCallback) {
  32.881 +    this.target = target;
  32.882 +    this.callback = callback;
  32.883 +    this.disposeCallback = disposeCallback;
  32.884 +    ko.exportProperty(this, 'dispose', this.dispose);
  32.885 +};
  32.886 +ko.subscription.prototype.dispose = function () {
  32.887 +    this.isDisposed = true;
  32.888 +    this.disposeCallback();
  32.889 +};
  32.890 +
  32.891 +ko.subscribable = function () {
  32.892 +    this._subscriptions = {};
  32.893 +
  32.894 +    ko.utils.extend(this, ko.subscribable['fn']);
  32.895 +    ko.exportProperty(this, 'subscribe', this.subscribe);
  32.896 +    ko.exportProperty(this, 'extend', this.extend);
  32.897 +    ko.exportProperty(this, 'getSubscriptionsCount', this.getSubscriptionsCount);
  32.898 +}
  32.899 +
  32.900 +var defaultEvent = "change";
  32.901 +
  32.902 +ko.subscribable['fn'] = {
  32.903 +    subscribe: function (callback, callbackTarget, event) {
  32.904 +        event = event || defaultEvent;
  32.905 +        var boundCallback = callbackTarget ? callback.bind(callbackTarget) : callback;
  32.906 +
  32.907 +        var subscription = new ko.subscription(this, boundCallback, function () {
  32.908 +            ko.utils.arrayRemoveItem(this._subscriptions[event], subscription);
  32.909 +        }.bind(this));
  32.910 +
  32.911 +        if (!this._subscriptions[event])
  32.912 +            this._subscriptions[event] = [];
  32.913 +        this._subscriptions[event].push(subscription);
  32.914 +        return subscription;
  32.915 +    },
  32.916 +
  32.917 +    "notifySubscribers": function (valueToNotify, event) {
  32.918 +        event = event || defaultEvent;
  32.919 +        if (this._subscriptions[event]) {
  32.920 +            ko.dependencyDetection.ignore(function() {
  32.921 +                ko.utils.arrayForEach(this._subscriptions[event].slice(0), function (subscription) {
  32.922 +                    // In case a subscription was disposed during the arrayForEach cycle, check
  32.923 +                    // for isDisposed on each subscription before invoking its callback
  32.924 +                    if (subscription && (subscription.isDisposed !== true))
  32.925 +                        subscription.callback(valueToNotify);
  32.926 +                });
  32.927 +            }, this);
  32.928 +        }
  32.929 +    },
  32.930 +
  32.931 +    getSubscriptionsCount: function () {
  32.932 +        var total = 0;
  32.933 +        for (var eventName in this._subscriptions) {
  32.934 +            if (this._subscriptions.hasOwnProperty(eventName))
  32.935 +                total += this._subscriptions[eventName].length;
  32.936 +        }
  32.937 +        return total;
  32.938 +    },
  32.939 +
  32.940 +    extend: applyExtenders
  32.941 +};
  32.942 +
  32.943 +
  32.944 +ko.isSubscribable = function (instance) {
  32.945 +    return typeof instance.subscribe == "function" && typeof instance["notifySubscribers"] == "function";
  32.946 +};
  32.947 +
  32.948 +ko.exportSymbol('subscribable', ko.subscribable);
  32.949 +ko.exportSymbol('isSubscribable', ko.isSubscribable);
  32.950 +
  32.951 +ko.dependencyDetection = (function () {
  32.952 +    var _frames = [];
  32.953 +
  32.954 +    return {
  32.955 +        begin: function (callback) {
  32.956 +            _frames.push({ callback: callback, distinctDependencies:[] });
  32.957 +        },
  32.958 +
  32.959 +        end: function () {
  32.960 +            _frames.pop();
  32.961 +        },
  32.962 +
  32.963 +        registerDependency: function (subscribable) {
  32.964 +            if (!ko.isSubscribable(subscribable))
  32.965 +                throw new Error("Only subscribable things can act as dependencies");
  32.966 +            if (_frames.length > 0) {
  32.967 +                var topFrame = _frames[_frames.length - 1];
  32.968 +                if (!topFrame || ko.utils.arrayIndexOf(topFrame.distinctDependencies, subscribable) >= 0)
  32.969 +                    return;
  32.970 +                topFrame.distinctDependencies.push(subscribable);
  32.971 +                topFrame.callback(subscribable);
  32.972 +            }
  32.973 +        },
  32.974 +
  32.975 +        ignore: function(callback, callbackTarget, callbackArgs) {
  32.976 +            try {
  32.977 +                _frames.push(null);
  32.978 +                return callback.apply(callbackTarget, callbackArgs || []);
  32.979 +            } finally {
  32.980 +                _frames.pop();
  32.981 +            }
  32.982 +        }
  32.983 +    };
  32.984 +})();
  32.985 +var primitiveTypes = { 'undefined':true, 'boolean':true, 'number':true, 'string':true };
  32.986 +
  32.987 +ko.observable = function (initialValue) {
  32.988 +    var _latestValue = initialValue;
  32.989 +
  32.990 +    function observable() {
  32.991 +        if (arguments.length > 0) {
  32.992 +            // Write
  32.993 +
  32.994 +            // Ignore writes if the value hasn't changed
  32.995 +            if ((!observable['equalityComparer']) || !observable['equalityComparer'](_latestValue, arguments[0])) {
  32.996 +                observable.valueWillMutate();
  32.997 +                _latestValue = arguments[0];
  32.998 +                if (DEBUG) observable._latestValue = _latestValue;
  32.999 +                observable.valueHasMutated();
 32.1000 +            }
 32.1001 +            return this; // Permits chained assignments
 32.1002 +        }
 32.1003 +        else {
 32.1004 +            // Read
 32.1005 +            ko.dependencyDetection.registerDependency(observable); // The caller only needs to be notified of changes if they did a "read" operation
 32.1006 +            return _latestValue;
 32.1007 +        }
 32.1008 +    }
 32.1009 +    if (DEBUG) observable._latestValue = _latestValue;
 32.1010 +    ko.subscribable.call(observable);
 32.1011 +    observable.peek = function() { return _latestValue };
 32.1012 +    observable.valueHasMutated = function () { observable["notifySubscribers"](_latestValue); }
 32.1013 +    observable.valueWillMutate = function () { observable["notifySubscribers"](_latestValue, "beforeChange"); }
 32.1014 +    ko.utils.extend(observable, ko.observable['fn']);
 32.1015 +
 32.1016 +    ko.exportProperty(observable, 'peek', observable.peek);
 32.1017 +    ko.exportProperty(observable, "valueHasMutated", observable.valueHasMutated);
 32.1018 +    ko.exportProperty(observable, "valueWillMutate", observable.valueWillMutate);
 32.1019 +
 32.1020 +    return observable;
 32.1021 +}
 32.1022 +
 32.1023 +ko.observable['fn'] = {
 32.1024 +    "equalityComparer": function valuesArePrimitiveAndEqual(a, b) {
 32.1025 +        var oldValueIsPrimitive = (a === null) || (typeof(a) in primitiveTypes);
 32.1026 +        return oldValueIsPrimitive ? (a === b) : false;
 32.1027 +    }
 32.1028 +};
 32.1029 +
 32.1030 +var protoProperty = ko.observable.protoProperty = "__ko_proto__";
 32.1031 +ko.observable['fn'][protoProperty] = ko.observable;
 32.1032 +
 32.1033 +ko.hasPrototype = function(instance, prototype) {
 32.1034 +    if ((instance === null) || (instance === undefined) || (instance[protoProperty] === undefined)) return false;
 32.1035 +    if (instance[protoProperty] === prototype) return true;
 32.1036 +    return ko.hasPrototype(instance[protoProperty], prototype); // Walk the prototype chain
 32.1037 +};
 32.1038 +
 32.1039 +ko.isObservable = function (instance) {
 32.1040 +    return ko.hasPrototype(instance, ko.observable);
 32.1041 +}
 32.1042 +ko.isWriteableObservable = function (instance) {
 32.1043 +    // Observable
 32.1044 +    if ((typeof instance == "function") && instance[protoProperty] === ko.observable)
 32.1045 +        return true;
 32.1046 +    // Writeable dependent observable
 32.1047 +    if ((typeof instance == "function") && (instance[protoProperty] === ko.dependentObservable) && (instance.hasWriteFunction))
 32.1048 +        return true;
 32.1049 +    // Anything else
 32.1050 +    return false;
 32.1051 +}
 32.1052 +
 32.1053 +
 32.1054 +ko.exportSymbol('observable', ko.observable);
 32.1055 +ko.exportSymbol('isObservable', ko.isObservable);
 32.1056 +ko.exportSymbol('isWriteableObservable', ko.isWriteableObservable);
 32.1057 +ko.observableArray = function (initialValues) {
 32.1058 +    if (arguments.length == 0) {
 32.1059 +        // Zero-parameter constructor initializes to empty array
 32.1060 +        initialValues = [];
 32.1061 +    }
 32.1062 +    if ((initialValues !== null) && (initialValues !== undefined) && !('length' in initialValues))
 32.1063 +        throw new Error("The argument passed when initializing an observable array must be an array, or null, or undefined.");
 32.1064 +
 32.1065 +    var result = ko.observable(initialValues);
 32.1066 +    ko.utils.extend(result, ko.observableArray['fn']);
 32.1067 +    return result;
 32.1068 +}
 32.1069 +
 32.1070 +ko.observableArray['fn'] = {
 32.1071 +    'remove': function (valueOrPredicate) {
 32.1072 +        var underlyingArray = this.peek();
 32.1073 +        var removedValues = [];
 32.1074 +        var predicate = typeof valueOrPredicate == "function" ? valueOrPredicate : function (value) { return value === valueOrPredicate; };
 32.1075 +        for (var i = 0; i < underlyingArray.length; i++) {
 32.1076 +            var value = underlyingArray[i];
 32.1077 +            if (predicate(value)) {
 32.1078 +                if (removedValues.length === 0) {
 32.1079 +                    this.valueWillMutate();
 32.1080 +                }
 32.1081 +                removedValues.push(value);
 32.1082 +                underlyingArray.splice(i, 1);
 32.1083 +                i--;
 32.1084 +            }
 32.1085 +        }
 32.1086 +        if (removedValues.length) {
 32.1087 +            this.valueHasMutated();
 32.1088 +        }
 32.1089 +        return removedValues;
 32.1090 +    },
 32.1091 +
 32.1092 +    'removeAll': function (arrayOfValues) {
 32.1093 +        // If you passed zero args, we remove everything
 32.1094 +        if (arrayOfValues === undefined) {
 32.1095 +            var underlyingArray = this.peek();
 32.1096 +            var allValues = underlyingArray.slice(0);
 32.1097 +            this.valueWillMutate();
 32.1098 +            underlyingArray.splice(0, underlyingArray.length);
 32.1099 +            this.valueHasMutated();
 32.1100 +            return allValues;
 32.1101 +        }
 32.1102 +        // If you passed an arg, we interpret it as an array of entries to remove
 32.1103 +        if (!arrayOfValues)
 32.1104 +            return [];
 32.1105 +        return this['remove'](function (value) {
 32.1106 +            return ko.utils.arrayIndexOf(arrayOfValues, value) >= 0;
 32.1107 +        });
 32.1108 +    },
 32.1109 +
 32.1110 +    'destroy': function (valueOrPredicate) {
 32.1111 +        var underlyingArray = this.peek();
 32.1112 +        var predicate = typeof valueOrPredicate == "function" ? valueOrPredicate : function (value) { return value === valueOrPredicate; };
 32.1113 +        this.valueWillMutate();
 32.1114 +        for (var i = underlyingArray.length - 1; i >= 0; i--) {
 32.1115 +            var value = underlyingArray[i];
 32.1116 +            if (predicate(value))
 32.1117 +                underlyingArray[i]["_destroy"] = true;
 32.1118 +        }
 32.1119 +        this.valueHasMutated();
 32.1120 +    },
 32.1121 +
 32.1122 +    'destroyAll': function (arrayOfValues) {
 32.1123 +        // If you passed zero args, we destroy everything
 32.1124 +        if (arrayOfValues === undefined)
 32.1125 +            return this['destroy'](function() { return true });
 32.1126 +
 32.1127 +        // If you passed an arg, we interpret it as an array of entries to destroy
 32.1128 +        if (!arrayOfValues)
 32.1129 +            return [];
 32.1130 +        return this['destroy'](function (value) {
 32.1131 +            return ko.utils.arrayIndexOf(arrayOfValues, value) >= 0;
 32.1132 +        });
 32.1133 +    },
 32.1134 +
 32.1135 +    'indexOf': function (item) {
 32.1136 +        var underlyingArray = this();
 32.1137 +        return ko.utils.arrayIndexOf(underlyingArray, item);
 32.1138 +    },
 32.1139 +
 32.1140 +    'replace': function(oldItem, newItem) {
 32.1141 +        var index = this['indexOf'](oldItem);
 32.1142 +        if (index >= 0) {
 32.1143 +            this.valueWillMutate();
 32.1144 +            this.peek()[index] = newItem;
 32.1145 +            this.valueHasMutated();
 32.1146 +        }
 32.1147 +    }
 32.1148 +}
 32.1149 +
 32.1150 +// Populate ko.observableArray.fn with read/write functions from native arrays
 32.1151 +// Important: Do not add any additional functions here that may reasonably be used to *read* data from the array
 32.1152 +// because we'll eval them without causing subscriptions, so ko.computed output could end up getting stale
 32.1153 +ko.utils.arrayForEach(["pop", "push", "reverse", "shift", "sort", "splice", "unshift"], function (methodName) {
 32.1154 +    ko.observableArray['fn'][methodName] = function () {
 32.1155 +        // Use "peek" to avoid creating a subscription in any computed that we're executing in the context of
 32.1156 +        // (for consistency with mutating regular observables)
 32.1157 +        var underlyingArray = this.peek();
 32.1158 +        this.valueWillMutate();
 32.1159 +        var methodCallResult = underlyingArray[methodName].apply(underlyingArray, arguments);
 32.1160 +        this.valueHasMutated();
 32.1161 +        return methodCallResult;
 32.1162 +    };
 32.1163 +});
 32.1164 +
 32.1165 +// Populate ko.observableArray.fn with read-only functions from native arrays
 32.1166 +ko.utils.arrayForEach(["slice"], function (methodName) {
 32.1167 +    ko.observableArray['fn'][methodName] = function () {
 32.1168 +        var underlyingArray = this();
 32.1169 +        return underlyingArray[methodName].apply(underlyingArray, arguments);
 32.1170 +    };
 32.1171 +});
 32.1172 +
 32.1173 +ko.exportSymbol('observableArray', ko.observableArray);
 32.1174 +ko.dependentObservable = function (evaluatorFunctionOrOptions, evaluatorFunctionTarget, options) {
 32.1175 +    var _latestValue,
 32.1176 +        _hasBeenEvaluated = false,
 32.1177 +        _isBeingEvaluated = false,
 32.1178 +        readFunction = evaluatorFunctionOrOptions;
 32.1179 +
 32.1180 +    if (readFunction && typeof readFunction == "object") {
 32.1181 +        // Single-parameter syntax - everything is on this "options" param
 32.1182 +        options = readFunction;
 32.1183 +        readFunction = options["read"];
 32.1184 +    } else {
 32.1185 +        // Multi-parameter syntax - construct the options according to the params passed
 32.1186 +        options = options || {};
 32.1187 +        if (!readFunction)
 32.1188 +            readFunction = options["read"];
 32.1189 +    }
 32.1190 +    if (typeof readFunction != "function")
 32.1191 +        throw new Error("Pass a function that returns the value of the ko.computed");
 32.1192 +
 32.1193 +    function addSubscriptionToDependency(subscribable) {
 32.1194 +        _subscriptionsToDependencies.push(subscribable.subscribe(evaluatePossiblyAsync));
 32.1195 +    }
 32.1196 +
 32.1197 +    function disposeAllSubscriptionsToDependencies() {
 32.1198 +        ko.utils.arrayForEach(_subscriptionsToDependencies, function (subscription) {
 32.1199 +            subscription.dispose();
 32.1200 +        });
 32.1201 +        _subscriptionsToDependencies = [];
 32.1202 +    }
 32.1203 +
 32.1204 +    function evaluatePossiblyAsync() {
 32.1205 +        var throttleEvaluationTimeout = dependentObservable['throttleEvaluation'];
 32.1206 +        if (throttleEvaluationTimeout && throttleEvaluationTimeout >= 0) {
 32.1207 +            clearTimeout(evaluationTimeoutInstance);
 32.1208 +            evaluationTimeoutInstance = setTimeout(evaluateImmediate, throttleEvaluationTimeout);
 32.1209 +        } else
 32.1210 +            evaluateImmediate();
 32.1211 +    }
 32.1212 +
 32.1213 +    function evaluateImmediate() {
 32.1214 +        if (_isBeingEvaluated) {
 32.1215 +            // If the evaluation of a ko.computed causes side effects, it's possible that it will trigger its own re-evaluation.
 32.1216 +            // This is not desirable (it's hard for a developer to realise a chain of dependencies might cause this, and they almost
 32.1217 +            // certainly didn't intend infinite re-evaluations). So, for predictability, we simply prevent ko.computeds from causing
 32.1218 +            // their own re-evaluation. Further discussion at https://github.com/SteveSanderson/knockout/pull/387
 32.1219 +            return;
 32.1220 +        }
 32.1221 +
 32.1222 +        // Don't dispose on first evaluation, because the "disposeWhen" callback might
 32.1223 +        // e.g., dispose when the associated DOM element isn't in the doc, and it's not
 32.1224 +        // going to be in the doc until *after* the first evaluation
 32.1225 +        if (_hasBeenEvaluated && disposeWhen()) {
 32.1226 +            dispose();
 32.1227 +            return;
 32.1228 +        }
 32.1229 +
 32.1230 +        _isBeingEvaluated = true;
 32.1231 +        try {
 32.1232 +            // Initially, we assume that none of the subscriptions are still being used (i.e., all are candidates for disposal).
 32.1233 +            // Then, during evaluation, we cross off any that are in fact still being used.
 32.1234 +            var disposalCandidates = ko.utils.arrayMap(_subscriptionsToDependencies, function(item) {return item.target;});
 32.1235 +
 32.1236 +            ko.dependencyDetection.begin(function(subscribable) {
 32.1237 +                var inOld;
 32.1238 +                if ((inOld = ko.utils.arrayIndexOf(disposalCandidates, subscribable)) >= 0)
 32.1239 +                    disposalCandidates[inOld] = undefined; // Don't want to dispose this subscription, as it's still being used
 32.1240 +                else
 32.1241 +                    addSubscriptionToDependency(subscribable); // Brand new subscription - add it
 32.1242 +            });
 32.1243 +
 32.1244 +            var newValue = readFunction.call(evaluatorFunctionTarget);
 32.1245 +
 32.1246 +            // For each subscription no longer being used, remove it from the active subscriptions list and dispose it
 32.1247 +            for (var i = disposalCandidates.length - 1; i >= 0; i--) {
 32.1248 +                if (disposalCandidates[i])
 32.1249 +                    _subscriptionsToDependencies.splice(i, 1)[0].dispose();
 32.1250 +            }
 32.1251 +            _hasBeenEvaluated = true;
 32.1252 +
 32.1253 +            dependentObservable["notifySubscribers"](_latestValue, "beforeChange");
 32.1254 +            _latestValue = newValue;
 32.1255 +            if (DEBUG) dependentObservable._latestValue = _latestValue;
 32.1256 +        } finally {
 32.1257 +            ko.dependencyDetection.end();
 32.1258 +        }
 32.1259 +
 32.1260 +        dependentObservable["notifySubscribers"](_latestValue);
 32.1261 +        _isBeingEvaluated = false;
 32.1262 +        if (!_subscriptionsToDependencies.length)
 32.1263 +            dispose();
 32.1264 +    }
 32.1265 +
 32.1266 +    function dependentObservable() {
 32.1267 +        if (arguments.length > 0) {
 32.1268 +            if (typeof writeFunction === "function") {
 32.1269 +                // Writing a value
 32.1270 +                writeFunction.apply(evaluatorFunctionTarget, arguments);
 32.1271 +            } else {
 32.1272 +                throw new Error("Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters.");
 32.1273 +            }
 32.1274 +            return this; // Permits chained assignments
 32.1275 +        } else {
 32.1276 +            // Reading the value
 32.1277 +            if (!_hasBeenEvaluated)
 32.1278 +                evaluateImmediate();
 32.1279 +            ko.dependencyDetection.registerDependency(dependentObservable);
 32.1280 +            return _latestValue;
 32.1281 +        }
 32.1282 +    }
 32.1283 +
 32.1284 +    function peek() {
 32.1285 +        if (!_hasBeenEvaluated)
 32.1286 +            evaluateImmediate();
 32.1287 +        return _latestValue;
 32.1288 +    }
 32.1289 +
 32.1290 +    function isActive() {
 32.1291 +        return !_hasBeenEvaluated || _subscriptionsToDependencies.length > 0;
 32.1292 +    }
 32.1293 +
 32.1294 +    // By here, "options" is always non-null
 32.1295 +    var writeFunction = options["write"],
 32.1296 +        disposeWhenNodeIsRemoved = options["disposeWhenNodeIsRemoved"] || options.disposeWhenNodeIsRemoved || null,
 32.1297 +        disposeWhen = options["disposeWhen"] || options.disposeWhen || function() { return false; },
 32.1298 +        dispose = disposeAllSubscriptionsToDependencies,
 32.1299 +        _subscriptionsToDependencies = [],
 32.1300 +        evaluationTimeoutInstance = null;
 32.1301 +
 32.1302 +    if (!evaluatorFunctionTarget)
 32.1303 +        evaluatorFunctionTarget = options["owner"];
 32.1304 +
 32.1305 +    dependentObservable.peek = peek;
 32.1306 +    dependentObservable.getDependenciesCount = function () { return _subscriptionsToDependencies.length; };
 32.1307 +    dependentObservable.hasWriteFunction = typeof options["write"] === "function";
 32.1308 +    dependentObservable.dispose = function () { dispose(); };
 32.1309 +    dependentObservable.isActive = isActive;
 32.1310 +    dependentObservable.valueHasMutated = function() {
 32.1311 +        _hasBeenEvaluated = false;
 32.1312 +        evaluateImmediate();
 32.1313 +    };
 32.1314 +
 32.1315 +    ko.subscribable.call(dependentObservable);
 32.1316 +    ko.utils.extend(dependentObservable, ko.dependentObservable['fn']);
 32.1317 +
 32.1318 +    ko.exportProperty(dependentObservable, 'peek', dependentObservable.peek);
 32.1319 +    ko.exportProperty(dependentObservable, 'dispose', dependentObservable.dispose);
 32.1320 +    ko.exportProperty(dependentObservable, 'isActive', dependentObservable.isActive);
 32.1321 +    ko.exportProperty(dependentObservable, 'getDependenciesCount', dependentObservable.getDependenciesCount);
 32.1322 +
 32.1323 +    // Evaluate, unless deferEvaluation is true
 32.1324 +    if (options['deferEvaluation'] !== true)
 32.1325 +        evaluateImmediate();
 32.1326 +
 32.1327 +    // Build "disposeWhenNodeIsRemoved" and "disposeWhenNodeIsRemovedCallback" option values.
 32.1328 +    // But skip if isActive is false (there will never be any dependencies to dispose).
 32.1329 +    // (Note: "disposeWhenNodeIsRemoved" option both proactively disposes as soon as the node is removed using ko.removeNode(),
 32.1330 +    // plus adds a "disposeWhen" callback that, on each evaluation, disposes if the node was removed by some other means.)
 32.1331 +    if (disposeWhenNodeIsRemoved && isActive()) {
 32.1332 +        dispose = function() {
 32.1333 +            ko.utils.domNodeDisposal.removeDisposeCallback(disposeWhenNodeIsRemoved, arguments.callee);
 32.1334 +            disposeAllSubscriptionsToDependencies();
 32.1335 +        };
 32.1336 +        ko.utils.domNodeDisposal.addDisposeCallback(disposeWhenNodeIsRemoved, dispose);
 32.1337 +        var existingDisposeWhenFunction = disposeWhen;
 32.1338 +        disposeWhen = function () {
 32.1339 +            return !ko.utils.domNodeIsAttachedToDocument(disposeWhenNodeIsRemoved) || existingDisposeWhenFunction();
 32.1340 +        }
 32.1341 +    }
 32.1342 +
 32.1343 +    return dependentObservable;
 32.1344 +};
 32.1345 +
 32.1346 +ko.isComputed = function(instance) {
 32.1347 +    return ko.hasPrototype(instance, ko.dependentObservable);
 32.1348 +};
 32.1349 +
 32.1350 +var protoProp = ko.observable.protoProperty; // == "__ko_proto__"
 32.1351 +ko.dependentObservable[protoProp] = ko.observable;
 32.1352 +
 32.1353 +ko.dependentObservable['fn'] = {};
 32.1354 +ko.dependentObservable['fn'][protoProp] = ko.dependentObservable;
 32.1355 +
 32.1356 +ko.exportSymbol('dependentObservable', ko.dependentObservable);
 32.1357 +ko.exportSymbol('computed', ko.dependentObservable); // Make "ko.computed" an alias for "ko.dependentObservable"
 32.1358 +ko.exportSymbol('isComputed', ko.isComputed);
 32.1359 +
 32.1360 +(function() {
 32.1361 +    var maxNestedObservableDepth = 10; // Escape the (unlikely) pathalogical case where an observable's current value is itself (or similar reference cycle)
 32.1362 +
 32.1363 +    ko.toJS = function(rootObject) {
 32.1364 +        if (arguments.length == 0)
 32.1365 +            throw new Error("When calling ko.toJS, pass the object you want to convert.");
 32.1366 +
 32.1367 +        // We just unwrap everything at every level in the object graph
 32.1368 +        return mapJsObjectGraph(rootObject, function(valueToMap) {
 32.1369 +            // Loop because an observable's value might in turn be another observable wrapper
 32.1370 +            for (var i = 0; ko.isObservable(valueToMap) && (i < maxNestedObservableDepth); i++)
 32.1371 +                valueToMap = valueToMap();
 32.1372 +            return valueToMap;
 32.1373 +        });
 32.1374 +    };
 32.1375 +
 32.1376 +    ko.toJSON = function(rootObject, replacer, space) {     // replacer and space are optional
 32.1377 +        var plainJavaScriptObject = ko.toJS(rootObject);
 32.1378 +        return ko.utils.stringifyJson(plainJavaScriptObject, replacer, space);
 32.1379 +    };
 32.1380 +
 32.1381 +    function mapJsObjectGraph(rootObject, mapInputCallback, visitedObjects) {
 32.1382 +        visitedObjects = visitedObjects || new objectLookup();
 32.1383 +
 32.1384 +        rootObject = mapInputCallback(rootObject);
 32.1385 +        var canHaveProperties = (typeof rootObject == "object") && (rootObject !== null) && (rootObject !== undefined) && (!(rootObject instanceof Date));
 32.1386 +        if (!canHaveProperties)
 32.1387 +            return rootObject;
 32.1388 +
 32.1389 +        var outputProperties = rootObject instanceof Array ? [] : {};
 32.1390 +        visitedObjects.save(rootObject, outputProperties);
 32.1391 +
 32.1392 +        visitPropertiesOrArrayEntries(rootObject, function(indexer) {
 32.1393 +            var propertyValue = mapInputCallback(rootObject[indexer]);
 32.1394 +
 32.1395 +            switch (typeof propertyValue) {
 32.1396 +                case "boolean":
 32.1397 +                case "number":
 32.1398 +                case "string":
 32.1399 +                case "function":
 32.1400 +                    outputProperties[indexer] = propertyValue;
 32.1401 +                    break;
 32.1402 +                case "object":
 32.1403 +                case "undefined":
 32.1404 +                    var previouslyMappedValue = visitedObjects.get(propertyValue);
 32.1405 +                    outputProperties[indexer] = (previouslyMappedValue !== undefined)
 32.1406 +                        ? previouslyMappedValue
 32.1407 +                        : mapJsObjectGraph(propertyValue, mapInputCallback, visitedObjects);
 32.1408 +                    break;
 32.1409 +            }
 32.1410 +        });
 32.1411 +
 32.1412 +        return outputProperties;
 32.1413 +    }
 32.1414 +
 32.1415 +    function visitPropertiesOrArrayEntries(rootObject, visitorCallback) {
 32.1416 +        if (rootObject instanceof Array) {
 32.1417 +            for (var i = 0; i < rootObject.length; i++)
 32.1418 +                visitorCallback(i);
 32.1419 +
 32.1420 +            // For arrays, also respect toJSON property for custom mappings (fixes #278)
 32.1421 +            if (typeof rootObject['toJSON'] == 'function')
 32.1422 +                visitorCallback('toJSON');
 32.1423 +        } else {
 32.1424 +            for (var propertyName in rootObject)
 32.1425 +                visitorCallback(propertyName);
 32.1426 +        }
 32.1427 +    };
 32.1428 +
 32.1429 +    function objectLookup() {
 32.1430 +        var keys = [];
 32.1431 +        var values = [];
 32.1432 +        this.save = function(key, value) {
 32.1433 +            var existingIndex = ko.utils.arrayIndexOf(keys, key);
 32.1434 +            if (existingIndex >= 0)
 32.1435 +                values[existingIndex] = value;
 32.1436 +            else {
 32.1437 +                keys.push(key);
 32.1438 +                values.push(value);
 32.1439 +            }
 32.1440 +        };
 32.1441 +        this.get = function(key) {
 32.1442 +            var existingIndex = ko.utils.arrayIndexOf(keys, key);
 32.1443 +            return (existingIndex >= 0) ? values[existingIndex] : undefined;
 32.1444 +        };
 32.1445 +    };
 32.1446 +})();
 32.1447 +
 32.1448 +ko.exportSymbol('toJS', ko.toJS);
 32.1449 +ko.exportSymbol('toJSON', ko.toJSON);
 32.1450 +(function () {
 32.1451 +    var hasDomDataExpandoProperty = '__ko__hasDomDataOptionValue__';
 32.1452 +
 32.1453 +    // Normally, SELECT elements and their OPTIONs can only take value of type 'string' (because the values
 32.1454 +    // are stored on DOM attributes). ko.selectExtensions provides a way for SELECTs/OPTIONs to have values
 32.1455 +    // that are arbitrary objects. This is very convenient when implementing things like cascading dropdowns.
 32.1456 +    ko.selectExtensions = {
 32.1457 +        readValue : function(element) {
 32.1458 +            switch (ko.utils.tagNameLower(element)) {
 32.1459 +                case 'option':
 32.1460 +                    if (element[hasDomDataExpandoProperty] === true)
 32.1461 +                        return ko.utils.domData.get(element, ko.bindingHandlers.options.optionValueDomDataKey);
 32.1462 +                    return ko.utils.ieVersion <= 7
 32.1463 +                        ? (element.getAttributeNode('value').specified ? element.value : element.text)
 32.1464 +                        : element.value;
 32.1465 +                case 'select':
 32.1466 +                    return element.selectedIndex >= 0 ? ko.selectExtensions.readValue(element.options[element.selectedIndex]) : undefined;
 32.1467 +                default:
 32.1468 +                    return element.value;
 32.1469 +            }
 32.1470 +        },
 32.1471 +
 32.1472 +        writeValue: function(element, value) {
 32.1473 +            switch (ko.utils.tagNameLower(element)) {
 32.1474 +                case 'option':
 32.1475 +                    switch(typeof value) {
 32.1476 +                        case "string":
 32.1477 +                            ko.utils.domData.set(element, ko.bindingHandlers.options.optionValueDomDataKey, undefined);
 32.1478 +                            if (hasDomDataExpandoProperty in element) { // IE <= 8 throws errors if you delete non-existent properties from a DOM node
 32.1479 +                                delete element[hasDomDataExpandoProperty];
 32.1480 +                            }
 32.1481 +                            element.value = value;
 32.1482 +                            break;
 32.1483 +                        default:
 32.1484 +                            // Store arbitrary object using DomData
 32.1485 +                            ko.utils.domData.set(element, ko.bindingHandlers.options.optionValueDomDataKey, value);
 32.1486 +                            element[hasDomDataExpandoProperty] = true;
 32.1487 +
 32.1488 +                            // Special treatment of numbers is just for backward compatibility. KO 1.2.1 wrote numerical values to element.value.
 32.1489 +                            element.value = typeof value === "number" ? value : "";
 32.1490 +                            break;
 32.1491 +                    }
 32.1492 +                    break;
 32.1493 +                case 'select':
 32.1494 +                    for (var i = element.options.length - 1; i >= 0; i--) {
 32.1495 +                        if (ko.selectExtensions.readValue(element.options[i]) == value) {
 32.1496 +                            element.selectedIndex = i;
 32.1497 +                            break;
 32.1498 +                        }
 32.1499 +                    }
 32.1500 +                    break;
 32.1501 +                default:
 32.1502 +                    if ((value === null) || (value === undefined))
 32.1503 +                        value = "";
 32.1504 +                    element.value = value;
 32.1505 +                    break;
 32.1506 +            }
 32.1507 +        }
 32.1508 +    };
 32.1509 +})();
 32.1510 +
 32.1511 +ko.exportSymbol('selectExtensions', ko.selectExtensions);
 32.1512 +ko.exportSymbol('selectExtensions.readValue', ko.selectExtensions.readValue);
 32.1513 +ko.exportSymbol('selectExtensions.writeValue', ko.selectExtensions.writeValue);
 32.1514 +ko.expressionRewriting = (function () {
 32.1515 +    var restoreCapturedTokensRegex = /\@ko_token_(\d+)\@/g;
 32.1516 +    var javaScriptReservedWords = ["true", "false"];
 32.1517 +
 32.1518 +    // Matches something that can be assigned to--either an isolated identifier or something ending with a property accessor
 32.1519 +    // This is designed to be simple and avoid false negatives, but could produce false positives (e.g., a+b.c).
 32.1520 +    var javaScriptAssignmentTarget = /^(?:[$_a-z][$\w]*|(.+)(\.\s*[$_a-z][$\w]*|\[.+\]))$/i;
 32.1521 +
 32.1522 +    function restoreTokens(string, tokens) {
 32.1523 +        var prevValue = null;
 32.1524 +        while (string != prevValue) { // Keep restoring tokens until it no longer makes a difference (they may be nested)
 32.1525 +            prevValue = string;
 32.1526 +            string = string.replace(restoreCapturedTokensRegex, function (match, tokenIndex) {
 32.1527 +                return tokens[tokenIndex];
 32.1528 +            });
 32.1529 +        }
 32.1530 +        return string;
 32.1531 +    }
 32.1532 +
 32.1533 +    function getWriteableValue(expression) {
 32.1534 +        if (ko.utils.arrayIndexOf(javaScriptReservedWords, ko.utils.stringTrim(expression).toLowerCase()) >= 0)
 32.1535 +            return false;
 32.1536 +        var match = expression.match(javaScriptAssignmentTarget);
 32.1537 +        return match === null ? false : match[1] ? ('Object(' + match[1] + ')' + match[2]) : expression;
 32.1538 +    }
 32.1539 +
 32.1540 +    function ensureQuoted(key) {
 32.1541 +        var trimmedKey = ko.utils.stringTrim(key);
 32.1542 +        switch (trimmedKey.length && trimmedKey.charAt(0)) {
 32.1543 +            case "'":
 32.1544 +            case '"':
 32.1545 +                return key;
 32.1546 +            default:
 32.1547 +                return "'" + trimmedKey + "'";
 32.1548 +        }
 32.1549 +    }
 32.1550 +
 32.1551 +    return {
 32.1552 +        bindingRewriteValidators: [],
 32.1553 +
 32.1554 +        parseObjectLiteral: function(objectLiteralString) {
 32.1555 +            // A full tokeniser+lexer would add too much weight to this library, so here's a simple parser
 32.1556 +            // that is sufficient just to split an object literal string into a set of top-level key-value pairs
 32.1557 +
 32.1558 +            var str = ko.utils.stringTrim(objectLiteralString);
 32.1559 +            if (str.length < 3)
 32.1560 +                return [];
 32.1561 +            if (str.charAt(0) === "{")// Ignore any braces surrounding the whole object literal
 32.1562 +                str = str.substring(1, str.length - 1);
 32.1563 +
 32.1564 +            // Pull out any string literals and regex literals
 32.1565 +            var tokens = [];
 32.1566 +            var tokenStart = null, tokenEndChar;
 32.1567 +            for (var position = 0; position < str.length; position++) {
 32.1568 +                var c = str.charAt(position);
 32.1569 +                if (tokenStart === null) {
 32.1570 +                    switch (c) {
 32.1571 +                        case '"':
 32.1572 +                        case "'":
 32.1573 +                        case "/":
 32.1574 +                            tokenStart = position;
 32.1575 +                            tokenEndChar = c;
 32.1576 +                            break;
 32.1577 +                    }
 32.1578 +                } else if ((c == tokenEndChar) && (str.charAt(position - 1) !== "\\")) {
 32.1579 +                    var token = str.substring(tokenStart, position + 1);
 32.1580 +                    tokens.push(token);
 32.1581 +                    var replacement = "@ko_token_" + (tokens.length - 1) + "@";
 32.1582 +                    str = str.substring(0, tokenStart) + replacement + str.substring(position + 1);
 32.1583 +                    position -= (token.length - replacement.length);
 32.1584 +                    tokenStart = null;
 32.1585 +                }
 32.1586 +            }
 32.1587 +
 32.1588 +            // Next pull out balanced paren, brace, and bracket blocks
 32.1589 +            tokenStart = null;
 32.1590 +            tokenEndChar = null;
 32.1591 +            var tokenDepth = 0, tokenStartChar = null;
 32.1592 +            for (var position = 0; position < str.length; position++) {
 32.1593 +                var c = str.charAt(position);
 32.1594 +                if (tokenStart === null) {
 32.1595 +                    switch (c) {
 32.1596 +                        case "{": tokenStart = position; tokenStartChar = c;
 32.1597 +                                  tokenEndChar = "}";
 32.1598 +                                  break;
 32.1599 +                        case "(": tokenStart = position; tokenStartChar = c;
 32.1600 +                                  tokenEndChar = ")";
 32.1601 +                                  break;
 32.1602 +                        case "[": tokenStart = position; tokenStartChar = c;
 32.1603 +                                  tokenEndChar = "]";
 32.1604 +                                  break;
 32.1605 +                    }
 32.1606 +                }
 32.1607 +
 32.1608 +                if (c === tokenStartChar)
 32.1609 +                    tokenDepth++;
 32.1610 +                else if (c === tokenEndChar) {
 32.1611 +                    tokenDepth--;
 32.1612 +                    if (tokenDepth === 0) {
 32.1613 +                        var token = str.substring(tokenStart, position + 1);
 32.1614 +                        tokens.push(token);
 32.1615 +                        var replacement = "@ko_token_" + (tokens.length - 1) + "@";
 32.1616 +                        str = str.substring(0, tokenStart) + replacement + str.substring(position + 1);
 32.1617 +                        position -= (token.length - replacement.length);
 32.1618 +                        tokenStart = null;
 32.1619 +                    }
 32.1620 +                }
 32.1621 +            }
 32.1622 +
 32.1623 +            // Now we can safely split on commas to get the key/value pairs
 32.1624 +            var result = [];
 32.1625 +            var keyValuePairs = str.split(",");
 32.1626 +            for (var i = 0, j = keyValuePairs.length; i < j; i++) {
 32.1627 +                var pair = keyValuePairs[i];
 32.1628 +                var colonPos = pair.indexOf(":");
 32.1629 +                if ((colonPos > 0) && (colonPos < pair.length - 1)) {
 32.1630 +                    var key = pair.substring(0, colonPos);
 32.1631 +                    var value = pair.substring(colonPos + 1);
 32.1632 +                    result.push({ 'key': restoreTokens(key, tokens), 'value': restoreTokens(value, tokens) });
 32.1633 +                } else {
 32.1634 +                    result.push({ 'unknown': restoreTokens(pair, tokens) });
 32.1635 +                }
 32.1636 +            }
 32.1637 +            return result;
 32.1638 +        },
 32.1639 +
 32.1640 +        preProcessBindings: function (objectLiteralStringOrKeyValueArray) {
 32.1641 +            var keyValueArray = typeof objectLiteralStringOrKeyValueArray === "string"
 32.1642 +                ? ko.expressionRewriting.parseObjectLiteral(objectLiteralStringOrKeyValueArray)
 32.1643 +                : objectLiteralStringOrKeyValueArray;
 32.1644 +            var resultStrings = [], propertyAccessorResultStrings = [];
 32.1645 +
 32.1646 +            var keyValueEntry;
 32.1647 +            for (var i = 0; keyValueEntry = keyValueArray[i]; i++) {
 32.1648 +                if (resultStrings.length > 0)
 32.1649 +                    resultStrings.push(",");
 32.1650 +
 32.1651 +                if (keyValueEntry['key']) {
 32.1652 +                    var quotedKey = ensureQuoted(keyValueEntry['key']), val = keyValueEntry['value'];
 32.1653 +                    resultStrings.push(quotedKey);
 32.1654 +                    resultStrings.push(":");
 32.1655 +                    resultStrings.push(val);
 32.1656 +
 32.1657 +                    if (val = getWriteableValue(ko.utils.stringTrim(val))) {
 32.1658 +                        if (propertyAccessorResultStrings.length > 0)
 32.1659 +                            propertyAccessorResultStrings.push(", ");
 32.1660 +                        propertyAccessorResultStrings.push(quotedKey + " : function(__ko_value) { " + val + " = __ko_value; }");
 32.1661 +                    }
 32.1662 +                } else if (keyValueEntry['unknown']) {
 32.1663 +                    resultStrings.push(keyValueEntry['unknown']);
 32.1664 +                }
 32.1665 +            }
 32.1666 +
 32.1667 +            var combinedResult = resultStrings.join("");
 32.1668 +            if (propertyAccessorResultStrings.length > 0) {
 32.1669 +                var allPropertyAccessors = propertyAccessorResultStrings.join("");
 32.1670 +                combinedResult = combinedResult + ", '_ko_property_writers' : { " + allPropertyAccessors + " } ";
 32.1671 +            }
 32.1672 +
 32.1673 +            return combinedResult;
 32.1674 +        },
 32.1675 +
 32.1676 +        keyValueArrayContainsKey: function(keyValueArray, key) {
 32.1677 +            for (var i = 0; i < keyValueArray.length; i++)
 32.1678 +                if (ko.utils.stringTrim(keyValueArray[i]['key']) == key)
 32.1679 +                    return true;
 32.1680 +            return false;
 32.1681 +        },
 32.1682 +
 32.1683 +        // Internal, private KO utility for updating model properties from within bindings
 32.1684 +        // property:            If the property being updated is (or might be) an observable, pass it here
 32.1685 +        //                      If it turns out to be a writable observable, it will be written to directly
 32.1686 +        // allBindingsAccessor: All bindings in the current execution context.
 32.1687 +        //                      This will be searched for a '_ko_property_writers' property in case you're writing to a non-observable
 32.1688 +        // key:                 The key identifying the property to be written. Example: for { hasFocus: myValue }, write to 'myValue' by specifying the key 'hasFocus'
 32.1689 +        // value:               The value to be written
 32.1690 +        // checkIfDifferent:    If true, and if the property being written is a writable observable, the value will only be written if
 32.1691 +        //                      it is !== existing value on that writable observable
 32.1692 +        writeValueToProperty: function(property, allBindingsAccessor, key, value, checkIfDifferent) {
 32.1693 +            if (!property || !ko.isWriteableObservable(property)) {
 32.1694 +                var propWriters = allBindingsAccessor()['_ko_property_writers'];
 32.1695 +                if (propWriters && propWriters[key])
 32.1696 +                    propWriters[key](value);
 32.1697 +            } else if (!checkIfDifferent || property.peek() !== value) {
 32.1698 +                property(value);
 32.1699 +            }
 32.1700 +        }
 32.1701 +    };
 32.1702 +})();
 32.1703 +
 32.1704 +ko.exportSymbol('expressionRewriting', ko.expressionRewriting);
 32.1705 +ko.exportSymbol('expressionRewriting.bindingRewriteValidators', ko.expressionRewriting.bindingRewriteValidators);
 32.1706 +ko.exportSymbol('expressionRewriting.parseObjectLiteral', ko.expressionRewriting.parseObjectLiteral);
 32.1707 +ko.exportSymbol('expressionRewriting.preProcessBindings', ko.expressionRewriting.preProcessBindings);
 32.1708 +
 32.1709 +// For backward compatibility, define the following aliases. (Previously, these function names were misleading because
 32.1710 +// they referred to JSON specifically, even though they actually work with arbitrary JavaScript object literal expressions.)
 32.1711 +ko.exportSymbol('jsonExpressionRewriting', ko.expressionRewriting);
 32.1712 +ko.exportSymbol('jsonExpressionRewriting.insertPropertyAccessorsIntoJson', ko.expressionRewriting.preProcessBindings);(function() {
 32.1713 +    // "Virtual elements" is an abstraction on top of the usual DOM API which understands the notion that comment nodes
 32.1714 +    // may be used to represent hierarchy (in addition to the DOM's natural hierarchy).
 32.1715 +    // If you call the DOM-manipulating functions on ko.virtualElements, you will be able to read and write the state
 32.1716 +    // of that virtual hierarchy
 32.1717 +    //
 32.1718 +    // The point of all this is to support containerless templates (e.g., <!-- ko foreach:someCollection -->blah<!-- /ko -->)
 32.1719 +    // without having to scatter special cases all over the binding and templating code.
 32.1720 +
 32.1721 +    // IE 9 cannot reliably read the "nodeValue" property of a comment node (see https://github.com/SteveSanderson/knockout/issues/186)
 32.1722 +    // but it does give them a nonstandard alternative property called "text" that it can read reliably. Other browsers don't have that property.
 32.1723 +    // So, use node.text where available, and node.nodeValue elsewhere
 32.1724 +    var commentNodesHaveTextProperty = document.createComment("test").text === "<!--test-->";
 32.1725 +
 32.1726 +    var startCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*ko(?:\s+(.+\s*\:[\s\S]*))?\s*-->$/ : /^\s*ko(?:\s+(.+\s*\:[\s\S]*))?\s*$/;
 32.1727 +    var endCommentRegex =   commentNodesHaveTextProperty ? /^<!--\s*\/ko\s*-->$/ : /^\s*\/ko\s*$/;
 32.1728 +    var htmlTagsWithOptionallyClosingChildren = { 'ul': true, 'ol': true };
 32.1729 +
 32.1730 +    function isStartComment(node) {
 32.1731 +        return (node.nodeType == 8) && (commentNodesHaveTextProperty ? node.text : node.nodeValue).match(startCommentRegex);
 32.1732 +    }
 32.1733 +
 32.1734 +    function isEndComment(node) {
 32.1735 +        return (node.nodeType == 8) && (commentNodesHaveTextProperty ? node.text : node.nodeValue).match(endCommentRegex);
 32.1736 +    }
 32.1737 +
 32.1738 +    function getVirtualChildren(startComment, allowUnbalanced) {
 32.1739 +        var currentNode = startComment;
 32.1740 +        var depth = 1;
 32.1741 +        var children = [];
 32.1742 +        while (currentNode = currentNode.nextSibling) {
 32.1743 +            if (isEndComment(currentNode)) {
 32.1744 +                depth--;
 32.1745 +                if (depth === 0)
 32.1746 +                    return children;
 32.1747 +            }
 32.1748 +
 32.1749 +            children.push(currentNode);
 32.1750 +
 32.1751 +            if (isStartComment(currentNode))
 32.1752 +                depth++;
 32.1753 +        }
 32.1754 +        if (!allowUnbalanced)
 32.1755 +            throw new Error("Cannot find closing comment tag to match: " + startComment.nodeValue);
 32.1756 +        return null;
 32.1757 +    }
 32.1758 +
 32.1759 +    function getMatchingEndComment(startComment, allowUnbalanced) {
 32.1760 +        var allVirtualChildren = getVirtualChildren(startComment, allowUnbalanced);
 32.1761 +        if (allVirtualChildren) {
 32.1762 +            if (allVirtualChildren.length > 0)
 32.1763 +                return allVirtualChildren[allVirtualChildren.length - 1].nextSibling;
 32.1764 +            return startComment.nextSibling;
 32.1765 +        } else
 32.1766 +            return null; // Must have no matching end comment, and allowUnbalanced is true
 32.1767 +    }
 32.1768 +
 32.1769 +    function getUnbalancedChildTags(node) {
 32.1770 +        // e.g., from <div>OK</div><!-- ko blah --><span>Another</span>, returns: <!-- ko blah --><span>Another</span>
 32.1771 +        //       from <div>OK</div><!-- /ko --><!-- /ko -->,             returns: <!-- /ko --><!-- /ko -->
 32.1772 +        var childNode = node.firstChild, captureRemaining = null;
 32.1773 +        if (childNode) {
 32.1774 +            do {
 32.1775 +                if (captureRemaining)                   // We already hit an unbalanced node and are now just scooping up all subsequent nodes
 32.1776 +                    captureRemaining.push(childNode);
 32.1777 +                else if (isStartComment(childNode)) {
 32.1778 +                    var matchingEndComment = getMatchingEndComment(childNode, /* allowUnbalanced: */ true);
 32.1779 +                    if (matchingEndComment)             // It's a balanced tag, so skip immediately to the end of this virtual set
 32.1780 +                        childNode = matchingEndComment;
 32.1781 +                    else
 32.1782 +                        captureRemaining = [childNode]; // It's unbalanced, so start capturing from this point
 32.1783 +                } else if (isEndComment(childNode)) {
 32.1784 +                    captureRemaining = [childNode];     // It's unbalanced (if it wasn't, we'd have skipped over it already), so start capturing
 32.1785 +                }
 32.1786 +            } while (childNode = childNode.nextSibling);
 32.1787 +        }
 32.1788 +        return captureRemaining;
 32.1789 +    }
 32.1790 +
 32.1791 +    ko.virtualElements = {
 32.1792 +        allowedBindings: {},
 32.1793 +
 32.1794 +        childNodes: function(node) {
 32.1795 +            return isStartComment(node) ? getVirtualChildren(node) : node.childNodes;
 32.1796 +        },
 32.1797 +
 32.1798 +        emptyNode: function(node) {
 32.1799 +            if (!isStartComment(node))
 32.1800 +                ko.utils.emptyDomNode(node);
 32.1801 +            else {
 32.1802 +                var virtualChildren = ko.virtualElements.childNodes(node);
 32.1803 +                for (var i = 0, j = virtualChildren.length; i < j; i++)
 32.1804 +                    ko.removeNode(virtualChildren[i]);
 32.1805 +            }
 32.1806 +        },
 32.1807 +
 32.1808 +        setDomNodeChildren: function(node, childNodes) {
 32.1809 +            if (!isStartComment(node))
 32.1810 +                ko.utils.setDomNodeChildren(node, childNodes);
 32.1811 +            else {
 32.1812 +                ko.virtualElements.emptyNode(node);
 32.1813 +                var endCommentNode = node.nextSibling; // Must be the next sibling, as we just emptied the children
 32.1814 +                for (var i = 0, j = childNodes.length; i < j; i++)
 32.1815 +                    endCommentNode.parentNode.insertBefore(childNodes[i], endCommentNode);
 32.1816 +            }
 32.1817 +        },
 32.1818 +
 32.1819 +        prepend: function(containerNode, nodeToPrepend) {
 32.1820 +            if (!isStartComment(containerNode)) {
 32.1821 +                if (containerNode.firstChild)
 32.1822 +                    containerNode.insertBefore(nodeToPrepend, containerNode.firstChild);
 32.1823 +                else
 32.1824 +                    containerNode.appendChild(nodeToPrepend);
 32.1825 +            } else {
 32.1826 +                // Start comments must always have a parent and at least one following sibling (the end comment)
 32.1827 +                containerNode.parentNode.insertBefore(nodeToPrepend, containerNode.nextSibling);
 32.1828 +            }
 32.1829 +        },
 32.1830 +
 32.1831 +        insertAfter: function(containerNode, nodeToInsert, insertAfterNode) {
 32.1832 +            if (!insertAfterNode) {
 32.1833 +                ko.virtualElements.prepend(containerNode, nodeToInsert);
 32.1834 +            } else if (!isStartComment(containerNode)) {
 32.1835 +                // Insert after insertion point
 32.1836 +                if (insertAfterNode.nextSibling)
 32.1837 +                    containerNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling);
 32.1838 +                else
 32.1839 +                    containerNode.appendChild(nodeToInsert);
 32.1840 +            } else {
 32.1841 +                // Children of start comments must always have a parent and at least one following sibling (the end comment)
 32.1842 +                containerNode.parentNode.insertBefore(nodeToInsert, insertAfterNode.nextSibling);
 32.1843 +            }
 32.1844 +        },
 32.1845 +
 32.1846 +        firstChild: function(node) {
 32.1847 +            if (!isStartComment(node))
 32.1848 +                return node.firstChild;
 32.1849 +            if (!node.nextSibling || isEndComment(node.nextSibling))
 32.1850 +                return null;
 32.1851 +            return node.nextSibling;
 32.1852 +        },
 32.1853 +
 32.1854 +        nextSibling: function(node) {
 32.1855 +            if (isStartComment(node))
 32.1856 +                node = getMatchingEndComment(node);
 32.1857 +            if (node.nextSibling && isEndComment(node.nextSibling))
 32.1858 +                return null;
 32.1859 +            return node.nextSibling;
 32.1860 +        },
 32.1861 +
 32.1862 +        virtualNodeBindingValue: function(node) {
 32.1863 +            var regexMatch = isStartComment(node);
 32.1864 +            return regexMatch ? regexMatch[1] : null;
 32.1865 +        },
 32.1866 +
 32.1867 +        normaliseVirtualElementDomStructure: function(elementVerified) {
 32.1868 +            // Workaround for https://github.com/SteveSanderson/knockout/issues/155
 32.1869 +            // (IE <= 8 or IE 9 quirks mode parses your HTML weirdly, treating closing </li> tags as if they don't exist, thereby moving comment nodes
 32.1870 +            // that are direct descendants of <ul> into the preceding <li>)
 32.1871 +            if (!htmlTagsWithOptionallyClosingChildren[ko.utils.tagNameLower(elementVerified)])
 32.1872 +                return;
 32.1873 +
 32.1874 +            // Scan immediate children to see if they contain unbalanced comment tags. If they do, those comment tags
 32.1875 +            // must be intended to appear *after* that child, so move them there.
 32.1876 +            var childNode = elementVerified.firstChild;
 32.1877 +            if (childNode) {
 32.1878 +                do {
 32.1879 +                    if (childNode.nodeType === 1) {
 32.1880 +                        var unbalancedTags = getUnbalancedChildTags(childNode);
 32.1881 +                        if (unbalancedTags) {
 32.1882 +                            // Fix up the DOM by moving the unbalanced tags to where they most likely were intended to be placed - *after* the child
 32.1883 +                            var nodeToInsertBefore = childNode.nextSibling;
 32.1884 +                            for (var i = 0; i < unbalancedTags.length; i++) {
 32.1885 +                                if (nodeToInsertBefore)
 32.1886 +                                    elementVerified.insertBefore(unbalancedTags[i], nodeToInsertBefore);
 32.1887 +                                else
 32.1888 +                                    elementVerified.appendChild(unbalancedTags[i]);
 32.1889 +                            }
 32.1890 +                        }
 32.1891 +                    }
 32.1892 +                } while (childNode = childNode.nextSibling);
 32.1893 +            }
 32.1894 +        }
 32.1895 +    };
 32.1896 +})();
 32.1897 +ko.exportSymbol('virtualElements', ko.virtualElements);
 32.1898 +ko.exportSymbol('virtualElements.allowedBindings', ko.virtualElements.allowedBindings);
 32.1899 +ko.exportSymbol('virtualElements.emptyNode', ko.virtualElements.emptyNode);
 32.1900 +//ko.exportSymbol('virtualElements.firstChild', ko.virtualElements.firstChild);     // firstChild is not minified
 32.1901 +ko.exportSymbol('virtualElements.insertAfter', ko.virtualElements.insertAfter);
 32.1902 +//ko.exportSymbol('virtualElements.nextSibling', ko.virtualElements.nextSibling);   // nextSibling is not minified
 32.1903 +ko.exportSymbol('virtualElements.prepend', ko.virtualElements.prepend);
 32.1904 +ko.exportSymbol('virtualElements.setDomNodeChildren', ko.virtualElements.setDomNodeChildren);
 32.1905 +(function() {
 32.1906 +    var defaultBindingAttributeName = "data-bind";
 32.1907 +
 32.1908 +    ko.bindingProvider = function() {
 32.1909 +        this.bindingCache = {};
 32.1910 +    };
 32.1911 +
 32.1912 +    ko.utils.extend(ko.bindingProvider.prototype, {
 32.1913 +        'nodeHasBindings': function(node) {
 32.1914 +            switch (node.nodeType) {
 32.1915 +                case 1: return node.getAttribute(defaultBindingAttributeName) != null;   // Element
 32.1916 +                case 8: return ko.virtualElements.virtualNodeBindingValue(node) != null; // Comment node
 32.1917 +                default: return false;
 32.1918 +            }
 32.1919 +        },
 32.1920 +
 32.1921 +        'getBindings': function(node, bindingContext) {
 32.1922 +            var bindingsString = this['getBindingsString'](node, bindingContext);
 32.1923 +            return bindingsString ? this['parseBindingsString'](bindingsString, bindingContext, node) : null;
 32.1924 +        },
 32.1925 +
 32.1926 +        // The following function is only used internally by this default provider.
 32.1927 +        // It's not part of the interface definition for a general binding provider.
 32.1928 +        'getBindingsString': function(node, bindingContext) {
 32.1929 +            switch (node.nodeType) {
 32.1930 +                case 1: return node.getAttribute(defaultBindingAttributeName);   // Element
 32.1931 +                case 8: return ko.virtualElements.virtualNodeBindingValue(node); // Comment node
 32.1932 +                default: return null;
 32.1933 +            }
 32.1934 +        },
 32.1935 +
 32.1936 +        // The following function is only used internally by this default provider.
 32.1937 +        // It's not part of the interface definition for a general binding provider.
 32.1938 +        'parseBindingsString': function(bindingsString, bindingContext, node) {
 32.1939 +            try {
 32.1940 +                var bindingFunction = createBindingsStringEvaluatorViaCache(bindingsString, this.bindingCache);
 32.1941 +                return bindingFunction(bindingContext, node);
 32.1942 +            } catch (ex) {
 32.1943 +                throw new Error("Unable to parse bindings.\nMessage: " + ex + ";\nBindings value: " + bindingsString);
 32.1944 +            }
 32.1945 +        }
 32.1946 +    });
 32.1947 +
 32.1948 +    ko.bindingProvider['instance'] = new ko.bindingProvider();
 32.1949 +
 32.1950 +    function createBindingsStringEvaluatorViaCache(bindingsString, cache) {
 32.1951 +        var cacheKey = bindingsString;
 32.1952 +        return cache[cacheKey]
 32.1953 +            || (cache[cacheKey] = createBindingsStringEvaluator(bindingsString));
 32.1954 +    }
 32.1955 +
 32.1956 +    function createBindingsStringEvaluator(bindingsString) {
 32.1957 +        // Build the source for a function that evaluates "expression"
 32.1958 +        // For each scope variable, add an extra level of "with" nesting
 32.1959 +        // Example result: with(sc1) { with(sc0) { return (expression) } }
 32.1960 +        var rewrittenBindings = ko.expressionRewriting.preProcessBindings(bindingsString),
 32.1961 +            functionBody = "with($context){with($data||{}){return{" + rewrittenBindings + "}}}";
 32.1962 +        return new Function("$context", "$element", functionBody);
 32.1963 +    }
 32.1964 +})();
 32.1965 +
 32.1966 +ko.exportSymbol('bindingProvider', ko.bindingProvider);
 32.1967 +(function () {
 32.1968 +    ko.bindingHandlers = {};
 32.1969 +
 32.1970 +    ko.bindingContext = function(dataItem, parentBindingContext, dataItemAlias) {
 32.1971 +        if (parentBindingContext) {
 32.1972 +            ko.utils.extend(this, parentBindingContext); // Inherit $root and any custom properties
 32.1973 +            this['$parentContext'] = parentBindingContext;
 32.1974 +            this['$parent'] = parentBindingContext['$data'];
 32.1975 +            this['$parents'] = (parentBindingContext['$parents'] || []).slice(0);
 32.1976 +            this['$parents'].unshift(this['$parent']);
 32.1977 +        } else {
 32.1978 +            this['$parents'] = [];
 32.1979 +            this['$root'] = dataItem;
 32.1980 +            // Export 'ko' in the binding context so it will be available in bindings and templates
 32.1981 +            // even if 'ko' isn't exported as a global, such as when using an AMD loader.
 32.1982 +            // See https://github.com/SteveSanderson/knockout/issues/490
 32.1983 +            this['ko'] = ko;
 32.1984 +        }
 32.1985 +        this['$data'] = dataItem;
 32.1986 +        if (dataItemAlias)
 32.1987 +            this[dataItemAlias] = dataItem;
 32.1988 +    }
 32.1989 +    ko.bindingContext.prototype['createChildContext'] = function (dataItem, dataItemAlias) {
 32.1990 +        return new ko.bindingContext(dataItem, this, dataItemAlias);
 32.1991 +    };
 32.1992 +    ko.bindingContext.prototype['extend'] = function(properties) {
 32.1993 +        var clone = ko.utils.extend(new ko.bindingContext(), this);
 32.1994 +        return ko.utils.extend(clone, properties);
 32.1995 +    };
 32.1996 +
 32.1997 +    function validateThatBindingIsAllowedForVirtualElements(bindingName) {
 32.1998 +        var validator = ko.virtualElements.allowedBindings[bindingName];
 32.1999 +        if (!validator)
 32.2000 +            throw new Error("The binding '" + bindingName + "' cannot be used with virtual elements")
 32.2001 +    }
 32.2002 +
 32.2003 +    function applyBindingsToDescendantsInternal (viewModel, elementOrVirtualElement, bindingContextsMayDifferFromDomParentElement) {
 32.2004 +        var currentChild, nextInQueue = ko.virtualElements.firstChild(elementOrVirtualElement);
 32.2005 +        while (currentChild = nextInQueue) {
 32.2006 +            // Keep a record of the next child *before* applying bindings, in case the binding removes the current child from its position
 32.2007 +            nextInQueue = ko.virtualElements.nextSibling(currentChild);
 32.2008 +            applyBindingsToNodeAndDescendantsInternal(viewModel, currentChild, bindingContextsMayDifferFromDomParentElement);
 32.2009 +        }
 32.2010 +    }
 32.2011 +
 32.2012 +    function applyBindingsToNodeAndDescendantsInternal (viewModel, nodeVerified, bindingContextMayDifferFromDomParentElement) {
 32.2013 +        var shouldBindDescendants = true;
 32.2014 +
 32.2015 +        // Perf optimisation: Apply bindings only if...
 32.2016 +        // (1) We need to store the binding context on this node (because it may differ from the DOM parent node's binding context)
 32.2017 +        //     Note that we can't store binding contexts on non-elements (e.g., text nodes), as IE doesn't allow expando properties for those
 32.2018 +        // (2) It might have bindings (e.g., it has a data-bind attribute, or it's a marker for a containerless template)
 32.2019 +        var isElement = (nodeVerified.nodeType === 1);
 32.2020 +        if (isElement) // Workaround IE <= 8 HTML parsing weirdness
 32.2021 +            ko.virtualElements.normaliseVirtualElementDomStructure(nodeVerified);
 32.2022 +
 32.2023 +        var shouldApplyBindings = (isElement && bindingContextMayDifferFromDomParentElement)             // Case (1)
 32.2024 +                               || ko.bindingProvider['instance']['nodeHasBindings'](nodeVerified);       // Case (2)
 32.2025 +        if (shouldApplyBindings)
 32.2026 +            shouldBindDescendants = applyBindingsToNodeInternal(nodeVerified, null, viewModel, bindingContextMayDifferFromDomParentElement).shouldBindDescendants;
 32.2027 +
 32.2028 +        if (shouldBindDescendants) {
 32.2029 +            // We're recursing automatically into (real or virtual) child nodes without changing binding contexts. So,
 32.2030 +            //  * For children of a *real* element, the binding context is certainly the same as on their DOM .parentNode,
 32.2031 +            //    hence bindingContextsMayDifferFromDomParentElement is false
 32.2032 +            //  * For children of a *virtual* element, we can't be sure. Evaluating .parentNode on those children may
 32.2033 +            //    skip over any number of intermediate virtual elements, any of which might define a custom binding context,
 32.2034 +            //    hence bindingContextsMayDifferFromDomParentElement is true
 32.2035 +            applyBindingsToDescendantsInternal(viewModel, nodeVerified, /* bindingContextsMayDifferFromDomParentElement: */ !isElement);
 32.2036 +        }
 32.2037 +    }
 32.2038 +
 32.2039 +    function applyBindingsToNodeInternal (node, bindings, viewModelOrBindingContext, bindingContextMayDifferFromDomParentElement) {
 32.2040 +        // Need to be sure that inits are only run once, and updates never run until all the inits have been run
 32.2041 +        var initPhase = 0; // 0 = before all inits, 1 = during inits, 2 = after all inits
 32.2042 +
 32.2043 +        // Each time the dependentObservable is evaluated (after data changes),
 32.2044 +        // the binding attribute is reparsed so that it can pick out the correct
 32.2045 +        // model properties in the context of the changed data.
 32.2046 +        // DOM event callbacks need to be able to access this changed data,
 32.2047 +        // so we need a single parsedBindings variable (shared by all callbacks
 32.2048 +        // associated with this node's bindings) that all the closures can access.
 32.2049 +        var parsedBindings;
 32.2050 +        function makeValueAccessor(bindingKey) {
 32.2051 +            return function () { return parsedBindings[bindingKey] }
 32.2052 +        }
 32.2053 +        function parsedBindingsAccessor() {
 32.2054 +            return parsedBindings;
 32.2055 +        }
 32.2056 +
 32.2057 +        var bindingHandlerThatControlsDescendantBindings;
 32.2058 +        ko.dependentObservable(
 32.2059 +            function () {
 32.2060 +                // Ensure we have a nonnull binding context to work with
 32.2061 +                var bindingContextInstance = viewModelOrBindingContext && (viewModelOrBindingContext instanceof ko.bindingContext)
 32.2062 +                    ? viewModelOrBindingContext
 32.2063 +                    : new ko.bindingContext(ko.utils.unwrapObservable(viewModelOrBindingContext));
 32.2064 +                var viewModel = bindingContextInstance['$data'];
 32.2065 +
 32.2066 +                // Optimization: Don't store the binding context on this node if it's definitely the same as on node.parentNode, because
 32.2067 +                // we can easily recover it just by scanning up the node's ancestors in the DOM
 32.2068 +                // (note: here, parent node means "real DOM parent" not "virtual parent", as there's no O(1) way to find the virtual parent)
 32.2069 +                if (bindingContextMayDifferFromDomParentElement)
 32.2070 +                    ko.storedBindingContextForNode(node, bindingContextInstance);
 32.2071 +
 32.2072 +                // Use evaluatedBindings if given, otherwise fall back on asking the bindings provider to give us some bindings
 32.2073 +                var evaluatedBindings = (typeof bindings == "function") ? bindings(bindingContextInstance, node) : bindings;
 32.2074 +                parsedBindings = evaluatedBindings || ko.bindingProvider['instance']['getBindings'](node, bindingContextInstance);
 32.2075 +
 32.2076 +                if (parsedBindings) {
 32.2077 +                    // First run all the inits, so bindings can register for notification on changes
 32.2078 +                    if (initPhase === 0) {
 32.2079 +                        initPhase = 1;
 32.2080 +                        for (var bindingKey in parsedBindings) {
 32.2081 +                            var binding = ko.bindingHandlers[bindingKey];
 32.2082 +                            if (binding && node.nodeType === 8)
 32.2083 +                                validateThatBindingIsAllowedForVirtualElements(bindingKey);
 32.2084 +
 32.2085 +                            if (binding && typeof binding["init"] == "function") {
 32.2086 +                                var handlerInitFn = binding["init"];
 32.2087 +                                var initResult = handlerInitFn(node, makeValueAccessor(bindingKey), parsedBindingsAccessor, viewModel, bindingContextInstance);
 32.2088 +
 32.2089 +                                // If this binding handler claims to control descendant bindings, make a note of this
 32.2090 +                                if (initResult && initResult['controlsDescendantBindings']) {
 32.2091 +                                    if (bindingHandlerThatControlsDescendantBindings !== undefined)
 32.2092 +                                        throw new Error("Multiple bindings (" + bindingHandlerThatControlsDescendantBindings + " and " + bindingKey + ") are trying to control descendant bindings of the same element. You cannot use these bindings together on the same element.");
 32.2093 +                                    bindingHandlerThatControlsDescendantBindings = bindingKey;
 32.2094 +                                }
 32.2095 +                            }
 32.2096 +                        }
 32.2097 +                        initPhase = 2;
 32.2098 +                    }
 32.2099 +
 32.2100 +                    // ... then run all the updates, which might trigger changes even on the first evaluation
 32.2101 +                    if (initPhase === 2) {
 32.2102 +                        for (var bindingKey in parsedBindings) {
 32.2103 +                            var binding = ko.bindingHandlers[bindingKey];
 32.2104 +                            if (binding && typeof binding["update"] == "function") {
 32.2105 +                                var handlerUpdateFn = binding["update"];
 32.2106 +                                handlerUpdateFn(node, makeValueAccessor(bindingKey), parsedBindingsAccessor, viewModel, bindingContextInstance);
 32.2107 +                            }
 32.2108 +                        }
 32.2109 +                    }
 32.2110 +                }
 32.2111 +            },
 32.2112 +            null,
 32.2113 +            { disposeWhenNodeIsRemoved : node }
 32.2114 +        );
 32.2115 +
 32.2116 +        return {
 32.2117 +            shouldBindDescendants: bindingHandlerThatControlsDescendantBindings === undefined
 32.2118 +        };
 32.2119 +    };
 32.2120 +
 32.2121 +    var storedBindingContextDomDataKey = "__ko_bindingContext__";
 32.2122 +    ko.storedBindingContextForNode = function (node, bindingContext) {
 32.2123 +        if (arguments.length == 2)
 32.2124 +            ko.utils.domData.set(node, storedBindingContextDomDataKey, bindingContext);
 32.2125 +        else
 32.2126 +            return ko.utils.domData.get(node, storedBindingContextDomDataKey);
 32.2127 +    }
 32.2128 +
 32.2129 +    ko.applyBindingsToNode = function (node, bindings, viewModel) {
 32.2130 +        if (node.nodeType === 1) // If it's an element, workaround IE <= 8 HTML parsing weirdness
 32.2131 +            ko.virtualElements.normaliseVirtualElementDomStructure(node);
 32.2132 +        return applyBindingsToNodeInternal(node, bindings, viewModel, true);
 32.2133 +    };
 32.2134 +
 32.2135 +    ko.applyBindingsToDescendants = function(viewModel, rootNode) {
 32.2136 +        if (rootNode.nodeType === 1 || rootNode.nodeType === 8)
 32.2137 +            applyBindingsToDescendantsInternal(viewModel, rootNode, true);
 32.2138 +    };
 32.2139 +
 32.2140 +    ko.applyBindings = function (viewModel, rootNode) {
 32.2141 +        if (rootNode && (rootNode.nodeType !== 1) && (rootNode.nodeType !== 8))
 32.2142 +            throw new Error("ko.applyBindings: first parameter should be your view model; second parameter should be a DOM node");
 32.2143 +        rootNode = rootNode || window.document.body; // Make "rootNode" parameter optional
 32.2144 +
 32.2145 +        applyBindingsToNodeAndDescendantsInternal(viewModel, rootNode, true);
 32.2146 +    };
 32.2147 +
 32.2148 +    // Retrieving binding context from arbitrary nodes
 32.2149 +    ko.contextFor = function(node) {
 32.2150 +        // We can only do something meaningful for elements and comment nodes (in particular, not text nodes, as IE can't store domdata for them)
 32.2151 +        switch (node.nodeType) {
 32.2152 +            case 1:
 32.2153 +            case 8:
 32.2154 +                var context = ko.storedBindingContextForNode(node);
 32.2155 +                if (context) return context;
 32.2156 +                if (node.parentNode) return ko.contextFor(node.parentNode);
 32.2157 +                break;
 32.2158 +        }
 32.2159 +        return undefined;
 32.2160 +    };
 32.2161 +    ko.dataFor = function(node) {
 32.2162 +        var context = ko.contextFor(node);
 32.2163 +        return context ? context['$data'] : undefined;
 32.2164 +    };
 32.2165 +
 32.2166 +    ko.exportSymbol('bindingHandlers', ko.bindingHandlers);
 32.2167 +    ko.exportSymbol('applyBindings', ko.applyBindings);
 32.2168 +    ko.exportSymbol('applyBindingsToDescendants', ko.applyBindingsToDescendants);
 32.2169 +    ko.exportSymbol('applyBindingsToNode', ko.applyBindingsToNode);
 32.2170 +    ko.exportSymbol('contextFor', ko.contextFor);
 32.2171 +    ko.exportSymbol('dataFor', ko.dataFor);
 32.2172 +})();
 32.2173 +var attrHtmlToJavascriptMap = { 'class': 'className', 'for': 'htmlFor' };
 32.2174 +ko.bindingHandlers['attr'] = {
 32.2175 +    'update': function(element, valueAccessor, allBindingsAccessor) {
 32.2176 +        var value = ko.utils.unwrapObservable(valueAccessor()) || {};
 32.2177 +        for (var attrName in value) {
 32.2178 +            if (typeof attrName == "string") {
 32.2179 +                var attrValue = ko.utils.unwrapObservable(value[attrName]);
 32.2180 +
 32.2181 +                // To cover cases like "attr: { checked:someProp }", we want to remove the attribute entirely
 32.2182 +                // when someProp is a "no value"-like value (strictly null, false, or undefined)
 32.2183 +                // (because the absence of the "checked" attr is how to mark an element as not checked, etc.)
 32.2184 +                var toRemove = (attrValue === false) || (attrValue === null) || (attrValue === undefined);
 32.2185 +                if (toRemove)
 32.2186 +                    element.removeAttribute(attrName);
 32.2187 +
 32.2188 +                // In IE <= 7 and IE8 Quirks Mode, you have to use the Javascript property name instead of the
 32.2189 +                // HTML attribute name for certain attributes. IE8 Standards Mode supports the correct behavior,
 32.2190 +                // but instead of figuring out the mode, we'll just set the attribute through the Javascript
 32.2191 +                // property for IE <= 8.
 32.2192 +                if (ko.utils.ieVersion <= 8 && attrName in attrHtmlToJavascriptMap) {
 32.2193 +                    attrName = attrHtmlToJavascriptMap[attrName];
 32.2194 +                    if (toRemove)
 32.2195 +                        element.removeAttribute(attrName);
 32.2196 +                    else
 32.2197 +                        element[attrName] = attrValue;
 32.2198 +                } else if (!toRemove) {
 32.2199 +                    element.setAttribute(attrName, attrValue.toString());
 32.2200 +                }
 32.2201 +
 32.2202 +                // Treat "name" specially - although you can think of it as an attribute, it also needs
 32.2203 +                // special handling on older versions of IE (https://github.com/SteveSanderson/knockout/pull/333)
 32.2204 +                // Deliberately being case-sensitive here because XHTML would regard "Name" as a different thing
 32.2205 +                // entirely, and there's no strong reason to allow for such casing in HTML.
 32.2206 +                if (attrName === "name") {
 32.2207 +                    ko.utils.setElementName(element, toRemove ? "" : attrValue.toString());
 32.2208 +                }
 32.2209 +            }
 32.2210 +        }
 32.2211 +    }
 32.2212 +};
 32.2213 +ko.bindingHandlers['checked'] = {
 32.2214 +    'init': function (element, valueAccessor, allBindingsAccessor) {
 32.2215 +        var updateHandler = function() {
 32.2216 +            var valueToWrite;
 32.2217 +            if (element.type == "checkbox") {
 32.2218 +                valueToWrite = element.checked;
 32.2219 +            } else if ((element.type == "radio") && (element.checked)) {
 32.2220 +                valueToWrite = element.value;
 32.2221 +            } else {
 32.2222 +                return; // "checked" binding only responds to checkboxes and selected radio buttons
 32.2223 +            }
 32.2224 +
 32.2225 +            var modelValue = valueAccessor(), unwrappedValue = ko.utils.unwrapObservable(modelValue);
 32.2226 +            if ((element.type == "checkbox") && (unwrappedValue instanceof Array)) {
 32.2227 +                // For checkboxes bound to an array, we add/remove the checkbox value to that array
 32.2228 +                // This works for both observable and non-observable arrays
 32.2229 +                var existingEntryIndex = ko.utils.arrayIndexOf(unwrappedValue, element.value);
 32.2230 +                if (element.checked && (existingEntryIndex < 0))
 32.2231 +                    modelValue.push(element.value);
 32.2232 +                else if ((!element.checked) && (existingEntryIndex >= 0))
 32.2233 +                    modelValue.splice(existingEntryIndex, 1);
 32.2234 +            } else {
 32.2235 +                ko.expressionRewriting.writeValueToProperty(modelValue, allBindingsAccessor, 'checked', valueToWrite, true);
 32.2236 +            }
 32.2237 +        };
 32.2238 +        ko.utils.registerEventHandler(element, "click", updateHandler);
 32.2239 +
 32.2240 +        // IE 6 won't allow radio buttons to be selected unless they have a name
 32.2241 +        if ((element.type == "radio") && !element.name)
 32.2242 +            ko.bindingHandlers['uniqueName']['init'](element, function() { return true });
 32.2243 +    },
 32.2244 +    'update': function (element, valueAccessor) {
 32.2245 +        var value = ko.utils.unwrapObservable(valueAccessor());
 32.2246 +
 32.2247 +        if (element.type == "checkbox") {
 32.2248 +            if (value instanceof Array) {
 32.2249 +                // When bound to an array, the checkbox being checked represents its value being present in that array
 32.2250 +                element.checked = ko.utils.arrayIndexOf(value, element.value) >= 0;
 32.2251 +            } else {
 32.2252 +                // When bound to anything other value (not an array), the checkbox being checked represents the value being trueish
 32.2253 +                element.checked = value;
 32.2254 +            }
 32.2255 +        } else if (element.type == "radio") {
 32.2256 +            element.checked = (element.value == value);
 32.2257 +        }
 32.2258 +    }
 32.2259 +};
 32.2260 +var classesWrittenByBindingKey = '__ko__cssValue';
 32.2261 +ko.bindingHandlers['css'] = {
 32.2262 +    'update': function (element, valueAccessor) {
 32.2263 +        var value = ko.utils.unwrapObservable(valueAccessor());
 32.2264 +        if (typeof value == "object") {
 32.2265 +            for (var className in value) {
 32.2266 +                var shouldHaveClass = ko.utils.unwrapObservable(value[className]);
 32.2267 +                ko.utils.toggleDomNodeCssClass(element, className, shouldHaveClass);
 32.2268 +            }
 32.2269 +        } else {
 32.2270 +            value = String(value || ''); // Make sure we don't try to store or set a non-string value
 32.2271 +            ko.utils.toggleDomNodeCssClass(element, element[classesWrittenByBindingKey], false);
 32.2272 +            element[classesWrittenByBindingKey] = value;
 32.2273 +            ko.utils.toggleDomNodeCssClass(element, value, true);
 32.2274 +        }
 32.2275 +    }
 32.2276 +};
 32.2277 +ko.bindingHandlers['enable'] = {
 32.2278 +    'update': function (element, valueAccessor) {
 32.2279 +        var value = ko.utils.unwrapObservable(valueAccessor());
 32.2280 +        if (value && element.disabled)
 32.2281 +            element.removeAttribute("disabled");
 32.2282 +        else if ((!value) && (!element.disabled))
 32.2283 +            element.disabled = true;
 32.2284 +    }
 32.2285 +};
 32.2286 +
 32.2287 +ko.bindingHandlers['disable'] = {
 32.2288 +    'update': function (element, valueAccessor) {
 32.2289 +        ko.bindingHandlers['enable']['update'](element, function() { return !ko.utils.unwrapObservable(valueAccessor()) });
 32.2290 +    }
 32.2291 +};
 32.2292 +// For certain common events (currently just 'click'), allow a simplified data-binding syntax
 32.2293 +// e.g. click:handler instead of the usual full-length event:{click:handler}
 32.2294 +function makeEventHandlerShortcut(eventName) {
 32.2295 +    ko.bindingHandlers[eventName] = {
 32.2296 +        'init': function(element, valueAccessor, allBindingsAccessor, viewModel) {
 32.2297 +            var newValueAccessor = function () {
 32.2298 +                var result = {};
 32.2299 +                result[eventName] = valueAccessor();
 32.2300 +                return result;
 32.2301 +            };
 32.2302 +            return ko.bindingHandlers['event']['init'].call(this, element, newValueAccessor, allBindingsAccessor, viewModel);
 32.2303 +        }
 32.2304 +    }
 32.2305 +}
 32.2306 +
 32.2307 +ko.bindingHandlers['event'] = {
 32.2308 +    'init' : function (element, valueAccessor, allBindingsAccessor, viewModel) {
 32.2309 +        var eventsToHandle = valueAccessor() || {};
 32.2310 +        for(var eventNameOutsideClosure in eventsToHandle) {
 32.2311 +            (function() {
 32.2312 +                var eventName = eventNameOutsideClosure; // Separate variable to be captured by event handler closure
 32.2313 +                if (typeof eventName == "string") {
 32.2314 +                    ko.utils.registerEventHandler(element, eventName, function (event) {
 32.2315 +                        var handlerReturnValue;
 32.2316 +                        var handlerFunction = valueAccessor()[eventName];
 32.2317 +                        if (!handlerFunction)
 32.2318 +                            return;
 32.2319 +                        var allBindings = allBindingsAccessor();
 32.2320 +
 32.2321 +                        try {
 32.2322 +                            // Take all the event args, and prefix with the viewmodel
 32.2323 +                            var argsForHandler = ko.utils.makeArray(arguments);
 32.2324 +                            argsForHandler.unshift(viewModel);
 32.2325 +                            handlerReturnValue = handlerFunction.apply(viewModel, argsForHandler);
 32.2326 +                        } finally {
 32.2327 +                            if (handlerReturnValue !== true) { // Normally we want to prevent default action. Developer can override this be explicitly returning true.
 32.2328 +                                if (event.preventDefault)
 32.2329 +                                    event.preventDefault();
 32.2330 +                                else
 32.2331 +                                    event.returnValue = false;
 32.2332 +                            }
 32.2333 +                        }
 32.2334 +
 32.2335 +                        var bubble = allBindings[eventName + 'Bubble'] !== false;
 32.2336 +                        if (!bubble) {
 32.2337 +                            event.cancelBubble = true;
 32.2338 +                            if (event.stopPropagation)
 32.2339 +                                event.stopPropagation();
 32.2340 +                        }
 32.2341 +                    });
 32.2342 +                }
 32.2343 +            })();
 32.2344 +        }
 32.2345 +    }
 32.2346 +};
 32.2347 +// "foreach: someExpression" is equivalent to "template: { foreach: someExpression }"
 32.2348 +// "foreach: { data: someExpression, afterAdd: myfn }" is equivalent to "template: { foreach: someExpression, afterAdd: myfn }"
 32.2349 +ko.bindingHandlers['foreach'] = {
 32.2350 +    makeTemplateValueAccessor: function(valueAccessor) {
 32.2351 +        return function() {
 32.2352 +            var modelValue = valueAccessor(),
 32.2353 +                unwrappedValue = ko.utils.peekObservable(modelValue);    // Unwrap without setting a dependency here
 32.2354 +
 32.2355 +            // If unwrappedValue is the array, pass in the wrapped value on its own
 32.2356 +            // The value will be unwrapped and tracked within the template binding
 32.2357 +            // (See https://github.com/SteveSanderson/knockout/issues/523)
 32.2358 +            if ((!unwrappedValue) || typeof unwrappedValue.length == "number")
 32.2359 +                return { 'foreach': modelValue, 'templateEngine': ko.nativeTemplateEngine.instance };
 32.2360 +
 32.2361 +            // If unwrappedValue.data is the array, preserve all relevant options and unwrap again value so we get updates
 32.2362 +            ko.utils.unwrapObservable(modelValue);
 32.2363 +            return {
 32.2364 +                'foreach': unwrappedValue['data'],
 32.2365 +                'as': unwrappedValue['as'],
 32.2366 +                'includeDestroyed': unwrappedValue['includeDestroyed'],
 32.2367 +                'afterAdd': unwrappedValue['afterAdd'],
 32.2368 +                'beforeRemove': unwrappedValue['beforeRemove'],
 32.2369 +                'afterRender': unwrappedValue['afterRender'],
 32.2370 +                'beforeMove': unwrappedValue['beforeMove'],
 32.2371 +                'afterMove': unwrappedValue['afterMove'],
 32.2372 +                'templateEngine': ko.nativeTemplateEngine.instance
 32.2373 +            };
 32.2374 +        };
 32.2375 +    },
 32.2376 +    'init': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
 32.2377 +        return ko.bindingHandlers['template']['init'](element, ko.bindingHandlers['foreach'].makeTemplateValueAccessor(valueAccessor));
 32.2378 +    },
 32.2379 +    'update': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
 32.2380 +        return ko.bindingHandlers['template']['update'](element, ko.bindingHandlers['foreach'].makeTemplateValueAccessor(valueAccessor), allBindingsAccessor, viewModel, bindingContext);
 32.2381 +    }
 32.2382 +};
 32.2383 +ko.expressionRewriting.bindingRewriteValidators['foreach'] = false; // Can't rewrite control flow bindings
 32.2384 +ko.virtualElements.allowedBindings['foreach'] = true;
 32.2385 +var hasfocusUpdatingProperty = '__ko_hasfocusUpdating';
 32.2386 +ko.bindingHandlers['hasfocus'] = {
 32.2387 +    'init': function(element, valueAccessor, allBindingsAccessor) {
 32.2388 +        var handleElementFocusChange = function(isFocused) {
 32.2389 +            // Where possible, ignore which event was raised and determine focus state using activeElement,
 32.2390 +            // as this avoids phantom focus/blur events raised when changing tabs in modern browsers.
 32.2391 +            // However, not all KO-targeted browsers (Firefox 2) support activeElement. For those browsers,
 32.2392 +            // prevent a loss of focus when changing tabs/windows by setting a flag that prevents hasfocus
 32.2393 +            // from calling 'blur()' on the element when it loses focus.
 32.2394 +            // Discussion at https://github.com/SteveSanderson/knockout/pull/352
 32.2395 +            element[hasfocusUpdatingProperty] = true;
 32.2396 +            var ownerDoc = element.ownerDocument;
 32.2397 +            if ("activeElement" in ownerDoc) {
 32.2398 +                isFocused = (ownerDoc.activeElement === element);
 32.2399 +            }
 32.2400 +            var modelValue = valueAccessor();
 32.2401 +            ko.expressionRewriting.writeValueToProperty(modelValue, allBindingsAccessor, 'hasfocus', isFocused, true);
 32.2402 +            element[hasfocusUpdatingProperty] = false;
 32.2403 +        };
 32.2404 +        var handleElementFocusIn = handleElementFocusChange.bind(null, true);
 32.2405 +        var handleElementFocusOut = handleElementFocusChange.bind(null, false);
 32.2406 +
 32.2407 +        ko.utils.registerEventHandler(element, "focus", handleElementFocusIn);
 32.2408 +        ko.utils.registerEventHandler(element, "focusin", handleElementFocusIn); // For IE
 32.2409 +        ko.utils.registerEventHandler(element, "blur",  handleElementFocusOut);
 32.2410 +        ko.utils.registerEventHandler(element, "focusout",  handleElementFocusOut); // For IE
 32.2411 +    },
 32.2412 +    'update': function(element, valueAccessor) {
 32.2413 +        var value = ko.utils.unwrapObservable(valueAccessor());
 32.2414 +        if (!element[hasfocusUpdatingProperty]) {
 32.2415 +            value ? element.focus() : element.blur();
 32.2416 +            ko.dependencyDetection.ignore(ko.utils.triggerEvent, null, [element, value ? "focusin" : "focusout"]); // For IE, which doesn't reliably fire "focus" or "blur" events synchronously
 32.2417 +        }
 32.2418 +    }
 32.2419 +};
 32.2420 +ko.bindingHandlers['html'] = {
 32.2421 +    'init': function() {
 32.2422 +        // Prevent binding on the dynamically-injected HTML (as developers are unlikely to expect that, and it has security implications)
 32.2423 +        return { 'controlsDescendantBindings': true };
 32.2424 +    },
 32.2425 +    'update': function (element, valueAccessor) {
 32.2426 +        // setHtml will unwrap the value if needed
 32.2427 +        ko.utils.setHtml(element, valueAccessor());
 32.2428 +    }
 32.2429 +};
 32.2430 +var withIfDomDataKey = '__ko_withIfBindingData';
 32.2431 +// Makes a binding like with or if
 32.2432 +function makeWithIfBinding(bindingKey, isWith, isNot, makeContextCallback) {
 32.2433 +    ko.bindingHandlers[bindingKey] = {
 32.2434 +        'init': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
 32.2435 +            ko.utils.domData.set(element, withIfDomDataKey, {});
 32.2436 +            return { 'controlsDescendantBindings': true };
 32.2437 +        },
 32.2438 +        'update': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
 32.2439 +            var withIfData = ko.utils.domData.get(element, withIfDomDataKey),
 32.2440 +                dataValue = ko.utils.unwrapObservable(valueAccessor()),
 32.2441 +                shouldDisplay = !isNot !== !dataValue, // equivalent to isNot ? !dataValue : !!dataValue
 32.2442 +                isFirstRender = !withIfData.savedNodes,
 32.2443 +                needsRefresh = isFirstRender || isWith || (shouldDisplay !== withIfData.didDisplayOnLastUpdate);
 32.2444 +
 32.2445 +            if (needsRefresh) {
 32.2446 +                if (isFirstRender) {
 32.2447 +                    withIfData.savedNodes = ko.utils.cloneNodes(ko.virtualElements.childNodes(element), true /* shouldCleanNodes */);
 32.2448 +                }
 32.2449 +
 32.2450 +                if (shouldDisplay) {
 32.2451 +                    if (!isFirstRender) {
 32.2452 +                        ko.virtualElements.setDomNodeChildren(element, ko.utils.cloneNodes(withIfData.savedNodes));
 32.2453 +                    }
 32.2454 +                    ko.applyBindingsToDescendants(makeContextCallback ? makeContextCallback(bindingContext, dataValue) : bindingContext, element);
 32.2455 +                } else {
 32.2456 +                    ko.virtualElements.emptyNode(element);
 32.2457 +                }
 32.2458 +
 32.2459 +                withIfData.didDisplayOnLastUpdate = shouldDisplay;
 32.2460 +            }
 32.2461 +        }
 32.2462 +    };
 32.2463 +    ko.expressionRewriting.bindingRewriteValidators[bindingKey] = false; // Can't rewrite control flow bindings
 32.2464 +    ko.virtualElements.allowedBindings[bindingKey] = true;
 32.2465 +}
 32.2466 +
 32.2467 +// Construct the actual binding handlers
 32.2468 +makeWithIfBinding('if');
 32.2469 +makeWithIfBinding('ifnot', false /* isWith */, true /* isNot */);
 32.2470 +makeWithIfBinding('with', true /* isWith */, false /* isNot */,
 32.2471 +    function(bindingContext, dataValue) {
 32.2472 +        return bindingContext['createChildContext'](dataValue);
 32.2473 +    }
 32.2474 +);
 32.2475 +function ensureDropdownSelectionIsConsistentWithModelValue(element, modelValue, preferModelValue) {
 32.2476 +    if (preferModelValue) {
 32.2477 +        if (modelValue !== ko.selectExtensions.readValue(element))
 32.2478 +            ko.selectExtensions.writeValue(element, modelValue);
 32.2479 +    }
 32.2480 +
 32.2481 +    // No matter which direction we're syncing in, we want the end result to be equality between dropdown value and model value.
 32.2482 +    // If they aren't equal, either we prefer the dropdown value, or the model value couldn't be represented, so either way,
 32.2483 +    // change the model value to match the dropdown.
 32.2484 +    if (modelValue !== ko.selectExtensions.readValue(element))
 32.2485 +        ko.dependencyDetection.ignore(ko.utils.triggerEvent, null, [element, "change"]);
 32.2486 +};
 32.2487 +
 32.2488 +ko.bindingHandlers['options'] = {
 32.2489 +    'update': function (element, valueAccessor, allBindingsAccessor) {
 32.2490 +        if (ko.utils.tagNameLower(element) !== "select")
 32.2491 +            throw new Error("options binding applies only to SELECT elements");
 32.2492 +
 32.2493 +        var selectWasPreviouslyEmpty = element.length == 0;
 32.2494 +        var previousSelectedValues = ko.utils.arrayMap(ko.utils.arrayFilter(element.childNodes, function (node) {
 32.2495 +            return node.tagName && (ko.utils.tagNameLower(node) === "option") && node.selected;
 32.2496 +        }), function (node) {
 32.2497 +            return ko.selectExtensions.readValue(node) || node.innerText || node.textContent;
 32.2498 +        });
 32.2499 +        var previousScrollTop = element.scrollTop;
 32.2500 +
 32.2501 +        var value = ko.utils.unwrapObservable(valueAccessor());
 32.2502 +        var selectedValue = element.value;
 32.2503 +
 32.2504 +        // Remove all existing <option>s.
 32.2505 +        // Need to use .remove() rather than .removeChild() for <option>s otherwise IE behaves oddly (https://github.com/SteveSanderson/knockout/issues/134)
 32.2506 +        while (element.length > 0) {
 32.2507 +            ko.cleanNode(element.options[0]);
 32.2508 +            element.remove(0);
 32.2509 +        }
 32.2510 +
 32.2511 +        if (value) {
 32.2512 +            var allBindings = allBindingsAccessor(),
 32.2513 +                includeDestroyed = allBindings['optionsIncludeDestroyed'];
 32.2514 +
 32.2515 +            if (typeof value.length != "number")
 32.2516 +                value = [value];
 32.2517 +            if (allBindings['optionsCaption']) {
 32.2518 +                var option = document.createElement("option");
 32.2519 +                ko.utils.setHtml(option, allBindings['optionsCaption']);
 32.2520 +                ko.selectExtensions.writeValue(option, undefined);
 32.2521 +                element.appendChild(option);
 32.2522 +            }
 32.2523 +
 32.2524 +            for (var i = 0, j = value.length; i < j; i++) {
 32.2525 +                // Skip destroyed items
 32.2526 +                var arrayEntry = value[i];
 32.2527 +                if (arrayEntry && arrayEntry['_destroy'] && !includeDestroyed)
 32.2528 +                    continue;
 32.2529 +
 32.2530 +                var option = document.createElement("option");
 32.2531 +
 32.2532 +                function applyToObject(object, predicate, defaultValue) {
 32.2533 +                    var predicateType = typeof predicate;
 32.2534 +                    if (predicateType == "function")    // Given a function; run it against the data value
 32.2535 +                        return predicate(object);
 32.2536 +                    else if (predicateType == "string") // Given a string; treat it as a property name on the data value
 32.2537 +                        return object[predicate];
 32.2538 +                    else                                // Given no optionsText arg; use the data value itself
 32.2539 +                        return defaultValue;
 32.2540 +                }
 32.2541 +
 32.2542 +                // Apply a value to the option element
 32.2543 +                var optionValue = applyToObject(arrayEntry, allBindings['optionsValue'], arrayEntry);
 32.2544 +                ko.selectExtensions.writeValue(option, ko.utils.unwrapObservable(optionValue));
 32.2545 +
 32.2546 +                // Apply some text to the option element
 32.2547 +                var optionText = applyToObject(arrayEntry, allBindings['optionsText'], optionValue);
 32.2548 +                ko.utils.setTextContent(option, optionText);
 32.2549 +
 32.2550 +                element.appendChild(option);
 32.2551 +            }
 32.2552 +
 32.2553 +            // IE6 doesn't like us to assign selection to OPTION nodes before they're added to the document.
 32.2554 +            // That's why we first added them without selection. Now it's time to set the selection.
 32.2555 +            var newOptions = element.getElementsByTagName("option");
 32.2556 +            var countSelectionsRetained = 0;
 32.2557 +            for (var i = 0, j = newOptions.length; i < j; i++) {
 32.2558 +                if (ko.utils.arrayIndexOf(previousSelectedValues, ko.selectExtensions.readValue(newOptions[i])) >= 0) {
 32.2559 +                    ko.utils.setOptionNodeSelectionState(newOptions[i], true);
 32.2560 +                    countSelectionsRetained++;
 32.2561 +                }
 32.2562 +            }
 32.2563 +
 32.2564 +            element.scrollTop = previousScrollTop;
 32.2565 +
 32.2566 +            if (selectWasPreviouslyEmpty && ('value' in allBindings)) {
 32.2567 +                // Ensure consistency between model value and selected option.
 32.2568 +                // If the dropdown is being populated for the first time here (or was otherwise previously empty),
 32.2569 +                // the dropdown selection state is meaningless, so we preserve the model value.
 32.2570 +                ensureDropdownSelectionIsConsistentWithModelValue(element, ko.utils.peekObservable(allBindings['value']), /* preferModelValue */ true);
 32.2571 +            }
 32.2572 +
 32.2573 +            // Workaround for IE9 bug
 32.2574 +            ko.utils.ensureSelectElementIsRenderedCorrectly(element);
 32.2575 +        }
 32.2576 +    }
 32.2577 +};
 32.2578 +ko.bindingHandlers['options'].optionValueDomDataKey = '__ko.optionValueDomData__';
 32.2579 +ko.bindingHandlers['selectedOptions'] = {
 32.2580 +    'init': function (element, valueAccessor, allBindingsAccessor) {
 32.2581 +        ko.utils.registerEventHandler(element, "change", function () {
 32.2582 +            var value = valueAccessor(), valueToWrite = [];
 32.2583 +            ko.utils.arrayForEach(element.getElementsByTagName("option"), function(node) {
 32.2584 +                if (node.selected)
 32.2585 +                    valueToWrite.push(ko.selectExtensions.readValue(node));
 32.2586 +            });
 32.2587 +            ko.expressionRewriting.writeValueToProperty(value, allBindingsAccessor, 'value', valueToWrite);
 32.2588 +        });
 32.2589 +    },
 32.2590 +    'update': function (element, valueAccessor) {
 32.2591 +        if (ko.utils.tagNameLower(element) != "select")
 32.2592 +            throw new Error("values binding applies only to SELECT elements");
 32.2593 +
 32.2594 +        var newValue = ko.utils.unwrapObservable(valueAccessor());
 32.2595 +        if (newValue && typeof newValue.length == "number") {
 32.2596 +            ko.utils.arrayForEach(element.getElementsByTagName("option"), function(node) {
 32.2597 +                var isSelected = ko.utils.arrayIndexOf(newValue, ko.selectExtensions.readValue(node)) >= 0;
 32.2598 +                ko.utils.setOptionNodeSelectionState(node, isSelected);
 32.2599 +            });
 32.2600 +        }
 32.2601 +    }
 32.2602 +};
 32.2603 +ko.bindingHandlers['style'] = {
 32.2604 +    'update': function (element, valueAccessor) {
 32.2605 +        var value = ko.utils.unwrapObservable(valueAccessor() || {});
 32.2606 +        for (var styleName in value) {
 32.2607 +            if (typeof styleName == "string") {
 32.2608 +                var styleValue = ko.utils.unwrapObservable(value[styleName]);
 32.2609 +                element.style[styleName] = styleValue || ""; // Empty string removes the value, whereas null/undefined have no effect
 32.2610 +            }
 32.2611 +        }
 32.2612 +    }
 32.2613 +};
 32.2614 +ko.bindingHandlers['submit'] = {
 32.2615 +    'init': function (element, valueAccessor, allBindingsAccessor, viewModel) {
 32.2616 +        if (typeof valueAccessor() != "function")
 32.2617 +            throw new Error("The value for a submit binding must be a function");
 32.2618 +        ko.utils.registerEventHandler(element, "submit", function (event) {
 32.2619 +            var handlerReturnValue;
 32.2620 +            var value = valueAccessor();
 32.2621 +            try { handlerReturnValue = value.call(viewModel, element); }
 32.2622 +            finally {
 32.2623 +                if (handlerReturnValue !== true) { // Normally we want to prevent default action. Developer can override this be explicitly returning true.
 32.2624 +                    if (event.preventDefault)
 32.2625 +                        event.preventDefault();
 32.2626 +                    else
 32.2627 +                        event.returnValue = false;
 32.2628 +                }
 32.2629 +            }
 32.2630 +        });
 32.2631 +    }
 32.2632 +};
 32.2633 +ko.bindingHandlers['text'] = {
 32.2634 +    'update': function (element, valueAccessor) {
 32.2635 +        ko.utils.setTextContent(element, valueAccessor());
 32.2636 +    }
 32.2637 +};
 32.2638 +ko.virtualElements.allowedBindings['text'] = true;
 32.2639 +ko.bindingHandlers['uniqueName'] = {
 32.2640 +    'init': function (element, valueAccessor) {
 32.2641 +        if (valueAccessor()) {
 32.2642 +            var name = "ko_unique_" + (++ko.bindingHandlers['uniqueName'].currentIndex);
 32.2643 +            ko.utils.setElementName(element, name);
 32.2644 +        }
 32.2645 +    }
 32.2646 +};
 32.2647 +ko.bindingHandlers['uniqueName'].currentIndex = 0;
 32.2648 +ko.bindingHandlers['value'] = {
 32.2649 +    'init': function (element, valueAccessor, allBindingsAccessor) {
 32.2650 +        // Always catch "change" event; possibly other events too if asked
 32.2651 +        var eventsToCatch = ["change"];
 32.2652 +        var requestedEventsToCatch = allBindingsAccessor()["valueUpdate"];
 32.2653 +        var propertyChangedFired = false;
 32.2654 +        if (requestedEventsToCatch) {
 32.2655 +            if (typeof requestedEventsToCatch == "string") // Allow both individual event names, and arrays of event names
 32.2656 +                requestedEventsToCatch = [requestedEventsToCatch];
 32.2657 +            ko.utils.arrayPushAll(eventsToCatch, requestedEventsToCatch);
 32.2658 +            eventsToCatch = ko.utils.arrayGetDistinctValues(eventsToCatch);
 32.2659 +        }
 32.2660 +
 32.2661 +        var valueUpdateHandler = function() {
 32.2662 +            propertyChangedFired = false;
 32.2663 +            var modelValue = valueAccessor();
 32.2664 +            var elementValue = ko.selectExtensions.readValue(element);
 32.2665 +            ko.expressionRewriting.writeValueToProperty(modelValue, allBindingsAccessor, 'value', elementValue);
 32.2666 +        }
 32.2667 +
 32.2668 +        // Workaround for https://github.com/SteveSanderson/knockout/issues/122
 32.2669 +        // IE doesn't fire "change" events on textboxes if the user selects a value from its autocomplete list
 32.2670 +        var ieAutoCompleteHackNeeded = ko.utils.ieVersion && element.tagName.toLowerCase() == "input" && element.type == "text"
 32.2671 +                                       && element.autocomplete != "off" && (!element.form || element.form.autocomplete != "off");
 32.2672 +        if (ieAutoCompleteHackNeeded && ko.utils.arrayIndexOf(eventsToCatch, "propertychange") == -1) {
 32.2673 +            ko.utils.registerEventHandler(element, "propertychange", function () { propertyChangedFired = true });
 32.2674 +            ko.utils.registerEventHandler(element, "blur", function() {
 32.2675 +                if (propertyChangedFired) {
 32.2676 +                    valueUpdateHandler();
 32.2677 +                }
 32.2678 +            });
 32.2679 +        }
 32.2680 +
 32.2681 +        ko.utils.arrayForEach(eventsToCatch, function(eventName) {
 32.2682 +            // The syntax "after<eventname>" means "run the handler asynchronously after the event"
 32.2683 +            // This is useful, for example, to catch "keydown" events after the browser has updated the control
 32.2684 +            // (otherwise, ko.selectExtensions.readValue(this) will receive the control's value *before* the key event)
 32.2685 +            var handler = valueUpdateHandler;
 32.2686 +            if (ko.utils.stringStartsWith(eventName, "after")) {
 32.2687 +                handler = function() { setTimeout(valueUpdateHandler, 0) };
 32.2688 +                eventName = eventName.substring("after".length);
 32.2689 +            }
 32.2690 +            ko.utils.registerEventHandler(element, eventName, handler);
 32.2691 +        });
 32.2692 +    },
 32.2693 +    'update': function (element, valueAccessor) {
 32.2694 +        var valueIsSelectOption = ko.utils.tagNameLower(element) === "select";
 32.2695 +        var newValue = ko.utils.unwrapObservable(valueAccessor());
 32.2696 +        var elementValue = ko.selectExtensions.readValue(element);
 32.2697 +        var valueHasChanged = (newValue != elementValue);
 32.2698 +
 32.2699 +        // JavaScript's 0 == "" behavious is unfortunate here as it prevents writing 0 to an empty text box (loose equality suggests the values are the same).
 32.2700 +        // We don't want to do a strict equality comparison as that is more confusing for developers in certain cases, so we specifically special case 0 != "" here.
 32.2701 +        if ((newValue === 0) && (elementValue !== 0) && (elementValue !== "0"))
 32.2702 +            valueHasChanged = true;
 32.2703 +
 32.2704 +        if (valueHasChanged) {
 32.2705 +            var applyValueAction = function () { ko.selectExtensions.writeValue(element, newValue); };
 32.2706 +            applyValueAction();
 32.2707 +
 32.2708 +            // Workaround for IE6 bug: It won't reliably apply values to SELECT nodes during the same execution thread
 32.2709 +            // right after you've changed the set of OPTION nodes on it. So for that node type, we'll schedule a second thread
 32.2710 +            // to apply the value as well.
 32.2711 +            var alsoApplyAsynchronously = valueIsSelectOption;
 32.2712 +            if (alsoApplyAsynchronously)
 32.2713 +                setTimeout(applyValueAction, 0);
 32.2714 +        }
 32.2715 +
 32.2716 +        // If you try to set a model value that can't be represented in an already-populated dropdown, reject that change,
 32.2717 +        // because you're not allowed to have a model value that disagrees with a visible UI selection.
 32.2718 +        if (valueIsSelectOption && (element.length > 0))
 32.2719 +            ensureDropdownSelectionIsConsistentWithModelValue(element, newValue, /* preferModelValue */ false);
 32.2720 +    }
 32.2721 +};
 32.2722 +ko.bindingHandlers['visible'] = {
 32.2723 +    'update': function (element, valueAccessor) {
 32.2724 +        var value = ko.utils.unwrapObservable(valueAccessor());
 32.2725 +        var isCurrentlyVisible = !(element.style.display == "none");
 32.2726 +        if (value && !isCurrentlyVisible)
 32.2727 +            element.style.display = "";
 32.2728 +        else if ((!value) && isCurrentlyVisible)
 32.2729 +            element.style.display = "none";
 32.2730 +    }
 32.2731 +};
 32.2732 +// 'click' is just a shorthand for the usual full-length event:{click:handler}
 32.2733 +makeEventHandlerShortcut('click');
 32.2734 +// If you want to make a custom template engine,
 32.2735 +//
 32.2736 +// [1] Inherit from this class (like ko.nativeTemplateEngine does)
 32.2737 +// [2] Override 'renderTemplateSource', supplying a function with this signature:
 32.2738 +//
 32.2739 +//        function (templateSource, bindingContext, options) {
 32.2740 +//            // - templateSource.text() is the text of the template you should render
 32.2741 +//            // - bindingContext.$data is the data you should pass into the template
 32.2742 +//            //   - you might also want to make bindingContext.$parent, bindingContext.$parents,
 32.2743 +//            //     and bindingContext.$root available in the template too
 32.2744 +//            // - options gives you access to any other properties set on "data-bind: { template: options }"
 32.2745 +//            //
 32.2746 +//            // Return value: an array of DOM nodes
 32.2747 +//        }
 32.2748 +//
 32.2749 +// [3] Override 'createJavaScriptEvaluatorBlock', supplying a function with this signature:
 32.2750 +//
 32.2751 +//        function (script) {
 32.2752 +//            // Return value: Whatever syntax means "Evaluate the JavaScript statement 'script' and output the result"
 32.2753 +//            //               For example, the jquery.tmpl template engine converts 'someScript' to '${ someScript }'
 32.2754 +//        }
 32.2755 +//
 32.2756 +//     This is only necessary if you want to allow data-bind attributes to reference arbitrary template variables.
 32.2757 +//     If you don't want to allow that, you can set the property 'allowTemplateRewriting' to false (like ko.nativeTemplateEngine does)
 32.2758 +//     and then you don't need to override 'createJavaScriptEvaluatorBlock'.
 32.2759 +
 32.2760 +ko.templateEngine = function () { };
 32.2761 +
 32.2762 +ko.templateEngine.prototype['renderTemplateSource'] = function (templateSource, bindingContext, options) {
 32.2763 +    throw new Error("Override renderTemplateSource");
 32.2764 +};
 32.2765 +
 32.2766 +ko.templateEngine.prototype['createJavaScriptEvaluatorBlock'] = function (script) {
 32.2767 +    throw new Error("Override createJavaScriptEvaluatorBlock");
 32.2768 +};
 32.2769 +
 32.2770 +ko.templateEngine.prototype['makeTemplateSource'] = function(template, templateDocument) {
 32.2771 +    // Named template
 32.2772 +    if (typeof template == "string") {
 32.2773 +        templateDocument = templateDocument || document;
 32.2774 +        var elem = templateDocument.getElementById(template);
 32.2775 +        if (!elem)
 32.2776 +            throw new Error("Cannot find template with ID " + template);
 32.2777 +        return new ko.templateSources.domElement(elem);
 32.2778 +    } else if ((template.nodeType == 1) || (template.nodeType == 8)) {
 32.2779 +        // Anonymous template
 32.2780 +        return new ko.templateSources.anonymousTemplate(template);
 32.2781 +    } else
 32.2782 +        throw new Error("Unknown template type: " + template);
 32.2783 +};
 32.2784 +
 32.2785 +ko.templateEngine.prototype['renderTemplate'] = function (template, bindingContext, options, templateDocument) {
 32.2786 +    var templateSource = this['makeTemplateSource'](template, templateDocument);
 32.2787 +    return this['renderTemplateSource'](templateSource, bindingContext, options);
 32.2788 +};
 32.2789 +
 32.2790 +ko.templateEngine.prototype['isTemplateRewritten'] = function (template, templateDocument) {
 32.2791 +    // Skip rewriting if requested
 32.2792 +    if (this['allowTemplateRewriting'] === false)
 32.2793 +        return true;
 32.2794 +    return this['makeTemplateSource'](template, templateDocument)['data']("isRewritten");
 32.2795 +};
 32.2796 +
 32.2797 +ko.templateEngine.prototype['rewriteTemplate'] = function (template, rewriterCallback, templateDocument) {
 32.2798 +    var templateSource = this['makeTemplateSource'](template, templateDocument);
 32.2799 +    var rewritten = rewriterCallback(templateSource['text']());
 32.2800 +    templateSource['text'](rewritten);
 32.2801 +    templateSource['data']("isRewritten", true);
 32.2802 +};
 32.2803 +
 32.2804 +ko.exportSymbol('templateEngine', ko.templateEngine);
 32.2805 +
 32.2806 +ko.templateRewriting = (function () {
 32.2807 +    var memoizeDataBindingAttributeSyntaxRegex = /(<[a-z]+\d*(\s+(?!data-bind=)[a-z0-9\-]+(=(\"[^\"]*\"|\'[^\']*\'))?)*\s+)data-bind=(["'])([\s\S]*?)\5/gi;
 32.2808 +    var memoizeVirtualContainerBindingSyntaxRegex = /<!--\s*ko\b\s*([\s\S]*?)\s*-->/g;
 32.2809 +
 32.2810 +    function validateDataBindValuesForRewriting(keyValueArray) {
 32.2811 +        var allValidators = ko.expressionRewriting.bindingRewriteValidators;
 32.2812 +        for (var i = 0; i < keyValueArray.length; i++) {
 32.2813 +            var key = keyValueArray[i]['key'];
 32.2814 +            if (allValidators.hasOwnProperty(key)) {
 32.2815 +                var validator = allValidators[key];
 32.2816 +
 32.2817 +                if (typeof validator === "function") {
 32.2818 +                    var possibleErrorMessage = validator(keyValueArray[i]['value']);
 32.2819 +                    if (possibleErrorMessage)
 32.2820 +                        throw new Error(possibleErrorMessage);
 32.2821 +                } else if (!validator) {
 32.2822 +                    throw new Error("This template engine does not support the '" + key + "' binding within its templates");
 32.2823 +                }
 32.2824 +            }
 32.2825 +        }
 32.2826 +    }
 32.2827 +
 32.2828 +    function constructMemoizedTagReplacement(dataBindAttributeValue, tagToRetain, templateEngine) {
 32.2829 +        var dataBindKeyValueArray = ko.expressionRewriting.parseObjectLiteral(dataBindAttributeValue);
 32.2830 +        validateDataBindValuesForRewriting(dataBindKeyValueArray);
 32.2831 +        var rewrittenDataBindAttributeValue = ko.expressionRewriting.preProcessBindings(dataBindKeyValueArray);
 32.2832 +
 32.2833 +        // For no obvious reason, Opera fails to evaluate rewrittenDataBindAttributeValue unless it's wrapped in an additional
 32.2834 +        // anonymous function, even though Opera's built-in debugger can evaluate it anyway. No other browser requires this
 32.2835 +        // extra indirection.
 32.2836 +        var applyBindingsToNextSiblingScript =
 32.2837 +            "ko.__tr_ambtns(function($context,$element){return(function(){return{ " + rewrittenDataBindAttributeValue + " } })()})";
 32.2838 +        return templateEngine['createJavaScriptEvaluatorBlock'](applyBindingsToNextSiblingScript) + tagToRetain;
 32.2839 +    }
 32.2840 +
 32.2841 +    return {
 32.2842 +        ensureTemplateIsRewritten: function (template, templateEngine, templateDocument) {
 32.2843 +            if (!templateEngine['isTemplateRewritten'](template, templateDocument))
 32.2844 +                templateEngine['rewriteTemplate'](template, function (htmlString) {
 32.2845 +                    return ko.templateRewriting.memoizeBindingAttributeSyntax(htmlString, templateEngine);
 32.2846 +                }, templateDocument);
 32.2847 +        },
 32.2848 +
 32.2849 +        memoizeBindingAttributeSyntax: function (htmlString, templateEngine) {
 32.2850 +            return htmlString.replace(memoizeDataBindingAttributeSyntaxRegex, function () {
 32.2851 +                return constructMemoizedTagReplacement(/* dataBindAttributeValue: */ arguments[6], /* tagToRetain: */ arguments[1], templateEngine);
 32.2852 +            }).replace(memoizeVirtualContainerBindingSyntaxRegex, function() {
 32.2853 +                return constructMemoizedTagReplacement(/* dataBindAttributeValue: */ arguments[1], /* tagToRetain: */ "<!-- ko -->", templateEngine);
 32.2854 +            });
 32.2855 +        },
 32.2856 +
 32.2857 +        applyMemoizedBindingsToNextSibling: function (bindings) {
 32.2858 +            return ko.memoization.memoize(function (domNode, bindingContext) {
 32.2859 +                if (domNode.nextSibling)
 32.2860 +                    ko.applyBindingsToNode(domNode.nextSibling, bindings, bindingContext);
 32.2861 +            });
 32.2862 +        }
 32.2863 +    }
 32.2864 +})();
 32.2865 +
 32.2866 +
 32.2867 +// Exported only because it has to be referenced by string lookup from within rewritten template
 32.2868 +ko.exportSymbol('__tr_ambtns', ko.templateRewriting.applyMemoizedBindingsToNextSibling);
 32.2869 +(function() {
 32.2870 +    // A template source represents a read/write way of accessing a template. This is to eliminate the need for template loading/saving
 32.2871 +    // logic to be duplicated in every template engine (and means they can all work with anonymous templates, etc.)
 32.2872 +    //
 32.2873 +    // Two are provided by default:
 32.2874 +    //  1. ko.templateSources.domElement       - reads/writes the text content of an arbitrary DOM element
 32.2875 +    //  2. ko.templateSources.anonymousElement - uses ko.utils.domData to read/write text *associated* with the DOM element, but
 32.2876 +    //                                           without reading/writing the actual element text content, since it will be overwritten
 32.2877 +    //                                           with the rendered template output.
 32.2878 +    // You can implement your own template source if you want to fetch/store templates somewhere other than in DOM elements.
 32.2879 +    // Template sources need to have the following functions:
 32.2880 +    //   text() 			- returns the template text from your storage location
 32.2881 +    //   text(value)		- writes the supplied template text to your storage location
 32.2882 +    //   data(key)			- reads values stored using data(key, value) - see below
 32.2883 +    //   data(key, value)	- associates "value" with this template and the key "key". Is used to store information like "isRewritten".
 32.2884 +    //
 32.2885 +    // Optionally, template sources can also have the following functions:
 32.2886 +    //   nodes()            - returns a DOM element containing the nodes of this template, where available
 32.2887 +    //   nodes(value)       - writes the given DOM element to your storage location
 32.2888 +    // If a DOM element is available for a given template source, template engines are encouraged to use it in preference over text()
 32.2889 +    // for improved speed. However, all templateSources must supply text() even if they don't supply nodes().
 32.2890 +    //
 32.2891 +    // Once you've implemented a templateSource, make your template engine use it by subclassing whatever template engine you were
 32.2892 +    // using and overriding "makeTemplateSource" to return an instance of your custom template source.
 32.2893 +
 32.2894 +    ko.templateSources = {};
 32.2895 +
 32.2896 +    // ---- ko.templateSources.domElement -----
 32.2897 +
 32.2898 +    ko.templateSources.domElement = function(element) {
 32.2899 +        this.domElement = element;
 32.2900 +    }
 32.2901 +
 32.2902 +    ko.templateSources.domElement.prototype['text'] = function(/* valueToWrite */) {
 32.2903 +        var tagNameLower = ko.utils.tagNameLower(this.domElement),
 32.2904 +            elemContentsProperty = tagNameLower === "script" ? "text"
 32.2905 +                                 : tagNameLower === "textarea" ? "value"
 32.2906 +                                 : "innerHTML";
 32.2907 +
 32.2908 +        if (arguments.length == 0) {
 32.2909 +            return this.domElement[elemContentsProperty];
 32.2910 +        } else {
 32.2911 +            var valueToWrite = arguments[0];
 32.2912 +            if (elemContentsProperty === "innerHTML")
 32.2913 +                ko.utils.setHtml(this.domElement, valueToWrite);
 32.2914 +            else
 32.2915 +                this.domElement[elemContentsProperty] = valueToWrite;
 32.2916 +        }
 32.2917 +    };
 32.2918 +
 32.2919 +    ko.templateSources.domElement.prototype['data'] = function(key /*, valueToWrite */) {
 32.2920 +        if (arguments.length === 1) {
 32.2921 +            return ko.utils.domData.get(this.domElement, "templateSourceData_" + key);
 32.2922 +        } else {
 32.2923 +            ko.utils.domData.set(this.domElement, "templateSourceData_" + key, arguments[1]);
 32.2924 +        }
 32.2925 +    };
 32.2926 +
 32.2927 +    // ---- ko.templateSources.anonymousTemplate -----
 32.2928 +    // Anonymous templates are normally saved/retrieved as DOM nodes through "nodes".
 32.2929 +    // For compatibility, you can also read "text"; it will be serialized from the nodes on demand.
 32.2930 +    // Writing to "text" is still supported, but then the template data will not be available as DOM nodes.
 32.2931 +
 32.2932 +    var anonymousTemplatesDomDataKey = "__ko_anon_template__";
 32.2933 +    ko.templateSources.anonymousTemplate = function(element) {
 32.2934 +        this.domElement = element;
 32.2935 +    }
 32.2936 +    ko.templateSources.anonymousTemplate.prototype = new ko.templateSources.domElement();
 32.2937 +    ko.templateSources.anonymousTemplate.prototype['text'] = function(/* valueToWrite */) {
 32.2938 +        if (arguments.length == 0) {
 32.2939 +            var templateData = ko.utils.domData.get(this.domElement, anonymousTemplatesDomDataKey) || {};
 32.2940 +            if (templateData.textData === undefined && templateData.containerData)
 32.2941 +                templateData.textData = templateData.containerData.innerHTML;
 32.2942 +            return templateData.textData;
 32.2943 +        } else {
 32.2944 +            var valueToWrite = arguments[0];
 32.2945 +            ko.utils.domData.set(this.domElement, anonymousTemplatesDomDataKey, {textData: valueToWrite});
 32.2946 +        }
 32.2947 +    };
 32.2948 +    ko.templateSources.domElement.prototype['nodes'] = function(/* valueToWrite */) {
 32.2949 +        if (arguments.length == 0) {
 32.2950 +            var templateData = ko.utils.domData.get(this.domElement, anonymousTemplatesDomDataKey) || {};
 32.2951 +            return templateData.containerData;
 32.2952 +        } else {
 32.2953 +            var valueToWrite = arguments[0];
 32.2954 +            ko.utils.domData.set(this.domElement, anonymousTemplatesDomDataKey, {containerData: valueToWrite});
 32.2955 +        }
 32.2956 +    };
 32.2957 +
 32.2958 +    ko.exportSymbol('templateSources', ko.templateSources);
 32.2959 +    ko.exportSymbol('templateSources.domElement', ko.templateSources.domElement);
 32.2960 +    ko.exportSymbol('templateSources.anonymousTemplate', ko.templateSources.anonymousTemplate);
 32.2961 +})();
 32.2962 +(function () {
 32.2963 +    var _templateEngine;
 32.2964 +    ko.setTemplateEngine = function (templateEngine) {
 32.2965 +        if ((templateEngine != undefined) && !(templateEngine instanceof ko.templateEngine))
 32.2966 +            throw new Error("templateEngine must inherit from ko.templateEngine");
 32.2967 +        _templateEngine = templateEngine;
 32.2968 +    }
 32.2969 +
 32.2970 +    function invokeForEachNodeOrCommentInContinuousRange(firstNode, lastNode, action) {
 32.2971 +        var node, nextInQueue = firstNode, firstOutOfRangeNode = ko.virtualElements.nextSibling(lastNode);
 32.2972 +        while (nextInQueue && ((node = nextInQueue) !== firstOutOfRangeNode)) {
 32.2973 +            nextInQueue = ko.virtualElements.nextSibling(node);
 32.2974 +            if (node.nodeType === 1 || node.nodeType === 8)
 32.2975 +                action(node);
 32.2976 +        }
 32.2977 +    }
 32.2978 +
 32.2979 +    function activateBindingsOnContinuousNodeArray(continuousNodeArray, bindingContext) {
 32.2980 +        // To be used on any nodes that have been rendered by a template and have been inserted into some parent element
 32.2981 +        // Walks through continuousNodeArray (which *must* be continuous, i.e., an uninterrupted sequence of sibling nodes, because
 32.2982 +        // the algorithm for walking them relies on this), and for each top-level item in the virtual-element sense,
 32.2983 +        // (1) Does a regular "applyBindings" to associate bindingContext with this node and to activate any non-memoized bindings
 32.2984 +        // (2) Unmemoizes any memos in the DOM subtree (e.g., to activate bindings that had been memoized during template rewriting)
 32.2985 +
 32.2986 +        if (continuousNodeArray.length) {
 32.2987 +            var firstNode = continuousNodeArray[0], lastNode = continuousNodeArray[continuousNodeArray.length - 1];
 32.2988 +
 32.2989 +            // Need to applyBindings *before* unmemoziation, because unmemoization might introduce extra nodes (that we don't want to re-bind)
 32.2990 +            // whereas a regular applyBindings won't introduce new memoized nodes
 32.2991 +            invokeForEachNodeOrCommentInContinuousRange(firstNode, lastNode, function(node) {
 32.2992 +                ko.applyBindings(bindingContext, node);
 32.2993 +            });
 32.2994 +            invokeForEachNodeOrCommentInContinuousRange(firstNode, lastNode, function(node) {
 32.2995 +                ko.memoization.unmemoizeDomNodeAndDescendants(node, [bindingContext]);
 32.2996 +            });
 32.2997 +        }
 32.2998 +    }
 32.2999 +
 32.3000 +    function getFirstNodeFromPossibleArray(nodeOrNodeArray) {
 32.3001 +        return nodeOrNodeArray.nodeType ? nodeOrNodeArray
 32.3002 +                                        : nodeOrNodeArray.length > 0 ? nodeOrNodeArray[0]
 32.3003 +                                        : null;
 32.3004 +    }
 32.3005 +
 32.3006 +    function executeTemplate(targetNodeOrNodeArray, renderMode, template, bindingContext, options) {
 32.3007 +        options = options || {};
 32.3008 +        var firstTargetNode = targetNodeOrNodeArray && getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
 32.3009 +        var templateDocument = firstTargetNode && firstTargetNode.ownerDocument;
 32.3010 +        var templateEngineToUse = (options['templateEngine'] || _templateEngine);
 32.3011 +        ko.templateRewriting.ensureTemplateIsRewritten(template, templateEngineToUse, templateDocument);
 32.3012 +        var renderedNodesArray = templateEngineToUse['renderTemplate'](template, bindingContext, options, templateDocument);
 32.3013 +
 32.3014 +        // Loosely check result is an array of DOM nodes
 32.3015 +        if ((typeof renderedNodesArray.length != "number") || (renderedNodesArray.length > 0 && typeof renderedNodesArray[0].nodeType != "number"))
 32.3016 +            throw new Error("Template engine must return an array of DOM nodes");
 32.3017 +
 32.3018 +        var haveAddedNodesToParent = false;
 32.3019 +        switch (renderMode) {
 32.3020 +            case "replaceChildren":
 32.3021 +                ko.virtualElements.setDomNodeChildren(targetNodeOrNodeArray, renderedNodesArray);
 32.3022 +                haveAddedNodesToParent = true;
 32.3023 +                break;
 32.3024 +            case "replaceNode":
 32.3025 +                ko.utils.replaceDomNodes(targetNodeOrNodeArray, renderedNodesArray);
 32.3026 +                haveAddedNodesToParent = true;
 32.3027 +                break;
 32.3028 +            case "ignoreTargetNode": break;
 32.3029 +            default:
 32.3030 +                throw new Error("Unknown renderMode: " + renderMode);
 32.3031 +        }
 32.3032 +
 32.3033 +        if (haveAddedNodesToParent) {
 32.3034 +            activateBindingsOnContinuousNodeArray(renderedNodesArray, bindingContext);
 32.3035 +            if (options['afterRender'])
 32.3036 +                ko.dependencyDetection.ignore(options['afterRender'], null, [renderedNodesArray, bindingContext['$data']]);
 32.3037 +        }
 32.3038 +
 32.3039 +        return renderedNodesArray;
 32.3040 +    }
 32.3041 +
 32.3042 +    ko.renderTemplate = function (template, dataOrBindingContext, options, targetNodeOrNodeArray, renderMode) {
 32.3043 +        options = options || {};
 32.3044 +        if ((options['templateEngine'] || _templateEngine) == undefined)
 32.3045 +            throw new Error("Set a template engine before calling renderTemplate");
 32.3046 +        renderMode = renderMode || "replaceChildren";
 32.3047 +
 32.3048 +        if (targetNodeOrNodeArray) {
 32.3049 +            var firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
 32.3050 +
 32.3051 +            var whenToDispose = function () { return (!firstTargetNode) || !ko.utils.domNodeIsAttachedToDocument(firstTargetNode); }; // Passive disposal (on next evaluation)
 32.3052 +            var activelyDisposeWhenNodeIsRemoved = (firstTargetNode && renderMode == "replaceNode") ? firstTargetNode.parentNode : firstTargetNode;
 32.3053 +
 32.3054 +            return ko.dependentObservable( // So the DOM is automatically updated when any dependency changes
 32.3055 +                function () {
 32.3056 +                    // Ensure we've got a proper binding context to work with
 32.3057 +                    var bindingContext = (dataOrBindingContext && (dataOrBindingContext instanceof ko.bindingContext))
 32.3058 +                        ? dataOrBindingContext
 32.3059 +                        : new ko.bindingContext(ko.utils.unwrapObservable(dataOrBindingContext));
 32.3060 +
 32.3061 +                    // Support selecting template as a function of the data being rendered
 32.3062 +                    var templateName = typeof(template) == 'function' ? template(bindingContext['$data'], bindingContext) : template;
 32.3063 +
 32.3064 +                    var renderedNodesArray = executeTemplate(targetNodeOrNodeArray, renderMode, templateName, bindingContext, options);
 32.3065 +                    if (renderMode == "replaceNode") {
 32.3066 +                        targetNodeOrNodeArray = renderedNodesArray;
 32.3067 +                        firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
 32.3068 +                    }
 32.3069 +                },
 32.3070 +                null,
 32.3071 +                { disposeWhen: whenToDispose, disposeWhenNodeIsRemoved: activelyDisposeWhenNodeIsRemoved }
 32.3072 +            );
 32.3073 +        } else {
 32.3074 +            // We don't yet have a DOM node to evaluate, so use a memo and render the template later when there is a DOM node
 32.3075 +            return ko.memoization.memoize(function (domNode) {
 32.3076 +                ko.renderTemplate(template, dataOrBindingContext, options, domNode, "replaceNode");
 32.3077 +            });
 32.3078 +        }
 32.3079 +    };
 32.3080 +
 32.3081 +    ko.renderTemplateForEach = function (template, arrayOrObservableArray, options, targetNode, parentBindingContext) {
 32.3082 +        // Since setDomNodeChildrenFromArrayMapping always calls executeTemplateForArrayItem and then
 32.3083 +        // activateBindingsCallback for added items, we can store the binding context in the former to use in the latter.
 32.3084 +        var arrayItemContext;
 32.3085 +
 32.3086 +        // This will be called by setDomNodeChildrenFromArrayMapping to get the nodes to add to targetNode
 32.3087 +        var executeTemplateForArrayItem = function (arrayValue, index) {
 32.3088 +            // Support selecting template as a function of the data being rendered
 32.3089 +            arrayItemContext = parentBindingContext['createChildContext'](ko.utils.unwrapObservable(arrayValue), options['as']);
 32.3090 +            arrayItemContext['$index'] = index;
 32.3091 +            var templateName = typeof(template) == 'function' ? template(arrayValue, arrayItemContext) : template;
 32.3092 +            return executeTemplate(null, "ignoreTargetNode", templateName, arrayItemContext, options);
 32.3093 +        }
 32.3094 +
 32.3095 +        // This will be called whenever setDomNodeChildrenFromArrayMapping has added nodes to targetNode
 32.3096 +        var activateBindingsCallback = function(arrayValue, addedNodesArray, index) {
 32.3097 +            activateBindingsOnContinuousNodeArray(addedNodesArray, arrayItemContext);
 32.3098 +            if (options['afterRender'])
 32.3099 +                options['afterRender'](addedNodesArray, arrayValue);
 32.3100 +        };
 32.3101 +
 32.3102 +        return ko.dependentObservable(function () {
 32.3103 +            var unwrappedArray = ko.utils.unwrapObservable(arrayOrObservableArray) || [];
 32.3104 +            if (typeof unwrappedArray.length == "undefined") // Coerce single value into array
 32.3105 +                unwrappedArray = [unwrappedArray];
 32.3106 +
 32.3107 +            // Filter out any entries marked as destroyed
 32.3108 +            var filteredArray = ko.utils.arrayFilter(unwrappedArray, function(item) {
 32.3109 +                return options['includeDestroyed'] || item === undefined || item === null || !ko.utils.unwrapObservable(item['_destroy']);
 32.3110 +            });
 32.3111 +
 32.3112 +            // Call setDomNodeChildrenFromArrayMapping, ignoring any observables unwrapped within (most likely from a callback function).
 32.3113 +            // If the array items are observables, though, they will be unwrapped in executeTemplateForArrayItem and managed within setDomNodeChildrenFromArrayMapping.
 32.3114 +            ko.dependencyDetection.ignore(ko.utils.setDomNodeChildrenFromArrayMapping, null, [targetNode, filteredArray, executeTemplateForArrayItem, options, activateBindingsCallback]);
 32.3115 +
 32.3116 +        }, null, { disposeWhenNodeIsRemoved: targetNode });
 32.3117 +    };
 32.3118 +
 32.3119 +    var templateComputedDomDataKey = '__ko__templateComputedDomDataKey__';
 32.3120 +    function disposeOldComputedAndStoreNewOne(element, newComputed) {
 32.3121 +        var oldComputed = ko.utils.domData.get(element, templateComputedDomDataKey);
 32.3122 +        if (oldComputed && (typeof(oldComputed.dispose) == 'function'))
 32.3123 +            oldComputed.dispose();
 32.3124 +        ko.utils.domData.set(element, templateComputedDomDataKey, (newComputed && newComputed.isActive()) ? newComputed : undefined);
 32.3125 +    }
 32.3126 +
 32.3127 +    ko.bindingHandlers['template'] = {
 32.3128 +        'init': function(element, valueAccessor) {
 32.3129 +            // Support anonymous templates
 32.3130 +            var bindingValue = ko.utils.unwrapObservable(valueAccessor());
 32.3131 +            if ((typeof bindingValue != "string") && (!bindingValue['name']) && (element.nodeType == 1 || element.nodeType == 8)) {
 32.3132 +                // It's an anonymous template - store the element contents, then clear the element
 32.3133 +                var templateNodes = element.nodeType == 1 ? element.childNodes : ko.virtualElements.childNodes(element),
 32.3134 +                    container = ko.utils.moveCleanedNodesToContainerElement(templateNodes); // This also removes the nodes from their current parent
 32.3135 +                new ko.templateSources.anonymousTemplate(element)['nodes'](container);
 32.3136 +            }
 32.3137 +            return { 'controlsDescendantBindings': true };
 32.3138 +        },
 32.3139 +        'update': function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
 32.3140 +            var templateName = ko.utils.unwrapObservable(valueAccessor()),
 32.3141 +                options = {},
 32.3142 +                shouldDisplay = true,
 32.3143 +                dataValue,
 32.3144 +                templateComputed = null;
 32.3145 +
 32.3146 +            if (typeof templateName != "string") {
 32.3147 +                options = templateName;
 32.3148 +                templateName = options['name'];
 32.3149 +
 32.3150 +                // Support "if"/"ifnot" conditions
 32.3151 +                if ('if' in options)
 32.3152 +                    shouldDisplay = ko.utils.unwrapObservable(options['if']);
 32.3153 +                if (shouldDisplay && 'ifnot' in options)
 32.3154 +                    shouldDisplay = !ko.utils.unwrapObservable(options['ifnot']);
 32.3155 +
 32.3156 +                dataValue = ko.utils.unwrapObservable(options['data']);
 32.3157 +            }
 32.3158 +
 32.3159 +            if ('foreach' in options) {
 32.3160 +                // Render once for each data point (treating data set as empty if shouldDisplay==false)
 32.3161 +                var dataArray = (shouldDisplay && options['foreach']) || [];
 32.3162 +                templateComputed = ko.renderTemplateForEach(templateName || element, dataArray, options, element, bindingContext);
 32.3163 +            } else if (!shouldDisplay) {
 32.3164 +                ko.virtualElements.emptyNode(element);
 32.3165 +            } else {
 32.3166 +                // Render once for this single data point (or use the viewModel if no data was provided)
 32.3167 +                var innerBindingContext = ('data' in options) ?
 32.3168 +                    bindingContext['createChildContext'](dataValue, options['as']) :  // Given an explitit 'data' value, we create a child binding context for it
 32.3169 +                    bindingContext;                                                        // Given no explicit 'data' value, we retain the same binding context
 32.3170 +                templateComputed = ko.renderTemplate(templateName || element, innerBindingContext, options, element);
 32.3171 +            }
 32.3172 +
 32.3173 +            // It only makes sense to have a single template computed per element (otherwise which one should have its output displayed?)
 32.3174 +            disposeOldComputedAndStoreNewOne(element, templateComputed);
 32.3175 +        }
 32.3176 +    };
 32.3177 +
 32.3178 +    // Anonymous templates can't be rewritten. Give a nice error message if you try to do it.
 32.3179 +    ko.expressionRewriting.bindingRewriteValidators['template'] = function(bindingValue) {
 32.3180 +        var parsedBindingValue = ko.expressionRewriting.parseObjectLiteral(bindingValue);
 32.3181 +
 32.3182 +        if ((parsedBindingValue.length == 1) && parsedBindingValue[0]['unknown'])
 32.3183 +            return null; // It looks like a string literal, not an object literal, so treat it as a named template (which is allowed for rewriting)
 32.3184 +
 32.3185 +        if (ko.expressionRewriting.keyValueArrayContainsKey(parsedBindingValue, "name"))
 32.3186 +            return null; // Named templates can be rewritten, so return "no error"
 32.3187 +        return "This template engine does not support anonymous templates nested within its templates";
 32.3188 +    };
 32.3189 +
 32.3190 +    ko.virtualElements.allowedBindings['template'] = true;
 32.3191 +})();
 32.3192 +
 32.3193 +ko.exportSymbol('setTemplateEngine', ko.setTemplateEngine);
 32.3194 +ko.exportSymbol('renderTemplate', ko.renderTemplate);
 32.3195 +
 32.3196 +ko.utils.compareArrays = (function () {
 32.3197 +    var statusNotInOld = 'added', statusNotInNew = 'deleted';
 32.3198 +
 32.3199 +    // Simple calculation based on Levenshtein distance.
 32.3200 +    function compareArrays(oldArray, newArray, dontLimitMoves) {
 32.3201 +        oldArray = oldArray || [];
 32.3202 +        newArray = newArray || [];
 32.3203 +
 32.3204 +        if (oldArray.length <= newArray.length)
 32.3205 +            return compareSmallArrayToBigArray(oldArray, newArray, statusNotInOld, statusNotInNew, dontLimitMoves);
 32.3206 +        else
 32.3207 +            return compareSmallArrayToBigArray(newArray, oldArray, statusNotInNew, statusNotInOld, dontLimitMoves);
 32.3208 +    }
 32.3209 +
 32.3210 +    function compareSmallArrayToBigArray(smlArray, bigArray, statusNotInSml, statusNotInBig, dontLimitMoves) {
 32.3211 +        var myMin = Math.min,
 32.3212 +            myMax = Math.max,
 32.3213 +            editDistanceMatrix = [],
 32.3214 +            smlIndex, smlIndexMax = smlArray.length,
 32.3215 +            bigIndex, bigIndexMax = bigArray.length,
 32.3216 +            compareRange = (bigIndexMax - smlIndexMax) || 1,
 32.3217 +            maxDistance = smlIndexMax + bigIndexMax + 1,
 32.3218 +            thisRow, lastRow,
 32.3219 +            bigIndexMaxForRow, bigIndexMinForRow;
 32.3220 +
 32.3221 +        for (smlIndex = 0; smlIndex <= smlIndexMax; smlIndex++) {
 32.3222 +            lastRow = thisRow;
 32.3223 +            editDistanceMatrix.push(thisRow = []);
 32.3224 +            bigIndexMaxForRow = myMin(bigIndexMax, smlIndex + compareRange);
 32.3225 +            bigIndexMinForRow = myMax(0, smlIndex - 1);
 32.3226 +            for (bigIndex = bigIndexMinForRow; bigIndex <= bigIndexMaxForRow; bigIndex++) {
 32.3227 +                if (!bigIndex)
 32.3228 +                    thisRow[bigIndex] = smlIndex + 1;
 32.3229 +                else if (!smlIndex)  // Top row - transform empty array into new array via additions
 32.3230 +                    thisRow[bigIndex] = bigIndex + 1;
 32.3231 +                else if (smlArray[smlIndex - 1] === bigArray[bigIndex - 1])
 32.3232 +                    thisRow[bigIndex] = lastRow[bigIndex - 1];                  // copy value (no edit)
 32.3233 +                else {
 32.3234 +                    var northDistance = lastRow[bigIndex] || maxDistance;       // not in big (deletion)
 32.3235 +                    var westDistance = thisRow[bigIndex - 1] || maxDistance;    // not in small (addition)
 32.3236 +                    thisRow[bigIndex] = myMin(northDistance, westDistance) + 1;
 32.3237 +                }
 32.3238 +            }
 32.3239 +        }
 32.3240 +
 32.3241 +        var editScript = [], meMinusOne, notInSml = [], notInBig = [];
 32.3242 +        for (smlIndex = smlIndexMax, bigIndex = bigIndexMax; smlIndex || bigIndex;) {
 32.3243 +            meMinusOne = editDistanceMatrix[smlIndex][bigIndex] - 1;
 32.3244 +            if (bigIndex && meMinusOne === editDistanceMatrix[smlIndex][bigIndex-1]) {
 32.3245 +                notInSml.push(editScript[editScript.length] = {     // added
 32.3246 +                    'status': statusNotInSml,
 32.3247 +                    'value': bigArray[--bigIndex],
 32.3248 +                    'index': bigIndex });
 32.3249 +            } else if (smlIndex && meMinusOne === editDistanceMatrix[smlIndex - 1][bigIndex]) {
 32.3250 +                notInBig.push(editScript[editScript.length] = {     // deleted
 32.3251 +                    'status': statusNotInBig,
 32.3252 +                    'value': smlArray[--smlIndex],
 32.3253 +                    'index': smlIndex });
 32.3254 +            } else {
 32.3255 +                editScript.push({
 32.3256 +                    'status': "retained",
 32.3257 +                    'value': bigArray[--bigIndex] });
 32.3258 +                --smlIndex;
 32.3259 +            }
 32.3260 +        }
 32.3261 +
 32.3262 +        if (notInSml.length && notInBig.length) {
 32.3263 +            // Set a limit on the number of consecutive non-matching comparisons; having it a multiple of
 32.3264 +            // smlIndexMax keeps the time complexity of this algorithm linear.
 32.3265 +            var limitFailedCompares = smlIndexMax * 10, failedCompares,
 32.3266 +                a, d, notInSmlItem, notInBigItem;
 32.3267 +            // Go through the items that have been added and deleted and try to find matches between them.
 32.3268 +            for (failedCompares = a = 0; (dontLimitMoves || failedCompares < limitFailedCompares) && (notInSmlItem = notInSml[a]); a++) {
 32.3269 +                for (d = 0; notInBigItem = notInBig[d]; d++) {
 32.3270 +                    if (notInSmlItem['value'] === notInBigItem['value']) {
 32.3271 +                        notInSmlItem['moved'] = notInBigItem['index'];
 32.3272 +                        notInBigItem['moved'] = notInSmlItem['index'];
 32.3273 +                        notInBig.splice(d,1);       // This item is marked as moved; so remove it from notInBig list
 32.3274 +                        failedCompares = d = 0;     // Reset failed compares count because we're checking for consecutive failures
 32.3275 +                        break;
 32.3276 +                    }
 32.3277 +                }
 32.3278 +                failedCompares += d;
 32.3279 +            }
 32.3280 +        }
 32.3281 +        return editScript.reverse();
 32.3282 +    }
 32.3283 +
 32.3284 +    return compareArrays;
 32.3285 +})();
 32.3286 +
 32.3287 +ko.exportSymbol('utils.compareArrays', ko.utils.compareArrays);
 32.3288 +
 32.3289 +(function () {
 32.3290 +    // Objective:
 32.3291 +    // * Given an input array, a container DOM node, and a function from array elements to arrays of DOM nodes,
 32.3292 +    //   map the array elements to arrays of DOM nodes, concatenate together all these arrays, and use them to populate the container DOM node
 32.3293 +    // * Next time we're given the same combination of things (with the array possibly having mutated), update the container DOM node
 32.3294 +    //   so that its children is again the concatenation of the mappings of the array elements, but don't re-map any array elements that we
 32.3295 +    //   previously mapped - retain those nodes, and just insert/delete other ones
 32.3296 +
 32.3297 +    // "callbackAfterAddingNodes" will be invoked after any "mapping"-generated nodes are inserted into the container node
 32.3298 +    // You can use this, for example, to activate bindings on those nodes.
 32.3299 +
 32.3300 +    function fixUpNodesToBeMovedOrRemoved(contiguousNodeArray) {
 32.3301 +        // Before moving, deleting, or replacing a set of nodes that were previously outputted by the "map" function, we have to reconcile
 32.3302 +        // them against what is in the DOM right now. It may be that some of the nodes have already been removed from the document,
 32.3303 +        // or that new nodes might have been inserted in the middle, for example by a binding. Also, there may previously have been
 32.3304 +        // leading comment nodes (created by rewritten string-based templates) that have since been removed during binding.
 32.3305 +        // So, this function translates the old "map" output array into its best guess of what set of current DOM nodes should be removed.
 32.3306 +        //
 32.3307 +        // Rules:
 32.3308 +        //   [A] Any leading nodes that aren't in the document any more should be ignored
 32.3309 +        //       These most likely correspond to memoization nodes that were already removed during binding
 32.3310 +        //       See https://github.com/SteveSanderson/knockout/pull/440
 32.3311 +        //   [B] We want to output a contiguous series of nodes that are still in the document. So, ignore any nodes that
 32.3312 +        //       have already been removed, and include any nodes that have been inserted among the previous collection
 32.3313 +
 32.3314 +        // Rule [A]
 32.3315 +        while (contiguousNodeArray.length && !ko.utils.domNodeIsAttachedToDocument(contiguousNodeArray[0]))
 32.3316 +            contiguousNodeArray.splice(0, 1);
 32.3317 +
 32.3318 +        // Rule [B]
 32.3319 +        if (contiguousNodeArray.length > 1) {
 32.3320 +            // Build up the actual new contiguous node set
 32.3321 +            var current = contiguousNodeArray[0], last = contiguousNodeArray[contiguousNodeArray.length - 1], newContiguousSet = [current];
 32.3322 +            while (current !== last) {
 32.3323 +                current = current.nextSibling;
 32.3324 +                if (!current) // Won't happen, except if the developer has manually removed some DOM elements (then we're in an undefined scenario)
 32.3325 +                    return;
 32.3326 +                newContiguousSet.push(current);
 32.3327 +            }
 32.3328 +
 32.3329 +            // ... then mutate the input array to match this.
 32.3330 +            // (The following line replaces the contents of contiguousNodeArray with newContiguousSet)
 32.3331 +            Array.prototype.splice.apply(contiguousNodeArray, [0, contiguousNodeArray.length].concat(newContiguousSet));
 32.3332 +        }
 32.3333 +        return contiguousNodeArray;
 32.3334 +    }
 32.3335 +
 32.3336 +    function mapNodeAndRefreshWhenChanged(containerNode, mapping, valueToMap, callbackAfterAddingNodes, index) {
 32.3337 +        // Map this array value inside a dependentObservable so we re-map when any dependency changes
 32.3338 +        var mappedNodes = [];
 32.3339 +        var dependentObservable = ko.dependentObservable(function() {
 32.3340 +            var newMappedNodes = mapping(valueToMap, index) || [];
 32.3341 +
 32.3342 +            // On subsequent evaluations, just replace the previously-inserted DOM nodes
 32.3343 +            if (mappedNodes.length > 0) {
 32.3344 +                ko.utils.replaceDomNodes(fixUpNodesToBeMovedOrRemoved(mappedNodes), newMappedNodes);
 32.3345 +                if (callbackAfterAddingNodes)
 32.3346 +                    ko.dependencyDetection.ignore(callbackAfterAddingNodes, null, [valueToMap, newMappedNodes, index]);
 32.3347 +            }
 32.3348 +
 32.3349 +            // Replace the contents of the mappedNodes array, thereby updating the record
 32.3350 +            // of which nodes would be deleted if valueToMap was itself later removed
 32.3351 +            mappedNodes.splice(0, mappedNodes.length);
 32.3352 +            ko.utils.arrayPushAll(mappedNodes, newMappedNodes);
 32.3353 +        }, null, { disposeWhenNodeIsRemoved: containerNode, disposeWhen: function() { return (mappedNodes.length == 0) || !ko.utils.domNodeIsAttachedToDocument(mappedNodes[0]) } });
 32.3354 +        return { mappedNodes : mappedNodes, dependentObservable : (dependentObservable.isActive() ? dependentObservable : undefined) };
 32.3355 +    }
 32.3356 +
 32.3357 +    var lastMappingResultDomDataKey = "setDomNodeChildrenFromArrayMapping_lastMappingResult";
 32.3358 +
 32.3359 +    ko.utils.setDomNodeChildrenFromArrayMapping = function (domNode, array, mapping, options, callbackAfterAddingNodes) {
 32.3360 +        // Compare the provided array against the previous one
 32.3361 +        array = array || [];
 32.3362 +        options = options || {};
 32.3363 +        var isFirstExecution = ko.utils.domData.get(domNode, lastMappingResultDomDataKey) === undefined;
 32.3364 +        var lastMappingResult = ko.utils.domData.get(domNode, lastMappingResultDomDataKey) || [];
 32.3365 +        var lastArray = ko.utils.arrayMap(lastMappingResult, function (x) { return x.arrayEntry; });
 32.3366 +        var editScript = ko.utils.compareArrays(lastArray, array);
 32.3367 +
 32.3368 +        // Build the new mapping result
 32.3369 +        var newMappingResult = [];
 32.3370 +        var lastMappingResultIndex = 0;
 32.3371 +        var newMappingResultIndex = 0;
 32.3372 +
 32.3373 +        var nodesToDelete = [];
 32.3374 +        var itemsToProcess = [];
 32.3375 +        var itemsForBeforeRemoveCallbacks = [];
 32.3376 +        var itemsForMoveCallbacks = [];
 32.3377 +        var itemsForAfterAddCallbacks = [];
 32.3378 +        var mapData;
 32.3379 +
 32.3380 +        function itemMovedOrRetained(editScriptIndex, oldPosition) {
 32.3381 +            mapData = lastMappingResult[oldPosition];
 32.3382 +            if (newMappingResultIndex !== oldPosition)
 32.3383 +                itemsForMoveCallbacks[editScriptIndex] = mapData;
 32.3384 +            // Since updating the index might change the nodes, do so before calling fixUpNodesToBeMovedOrRemoved
 32.3385 +            mapData.indexObservable(newMappingResultIndex++);
 32.3386 +            fixUpNodesToBeMovedOrRemoved(mapData.mappedNodes);
 32.3387 +            newMappingResult.push(mapData);
 32.3388 +            itemsToProcess.push(mapData);
 32.3389 +        }
 32.3390 +
 32.3391 +        function callCallback(callback, items) {
 32.3392 +            if (callback) {
 32.3393 +                for (var i = 0, n = items.length; i < n; i++) {
 32.3394 +                    if (items[i]) {
 32.3395 +                        ko.utils.arrayForEach(items[i].mappedNodes, function(node) {
 32.3396 +                            callback(node, i, items[i].arrayEntry);
 32.3397 +                        });
 32.3398 +                    }
 32.3399 +                }
 32.3400 +            }
 32.3401 +        }
 32.3402 +
 32.3403 +        for (var i = 0, editScriptItem, movedIndex; editScriptItem = editScript[i]; i++) {
 32.3404 +            movedIndex = editScriptItem['moved'];
 32.3405 +            switch (editScriptItem['status']) {
 32.3406 +                case "deleted":
 32.3407 +                    if (movedIndex === undefined) {
 32.3408 +                        mapData = lastMappingResult[lastMappingResultIndex];
 32.3409 +
 32.3410 +                        // Stop tracking changes to the mapping for these nodes
 32.3411 +                        if (mapData.dependentObservable)
 32.3412 +                            mapData.dependentObservable.dispose();
 32.3413 +
 32.3414 +                        // Queue these nodes for later removal
 32.3415 +                        nodesToDelete.push.apply(nodesToDelete, fixUpNodesToBeMovedOrRemoved(mapData.mappedNodes));
 32.3416 +                        if (options['beforeRemove']) {
 32.3417 +                            itemsForBeforeRemoveCallbacks[i] = mapData;
 32.3418 +                            itemsToProcess.push(mapData);
 32.3419 +                        }
 32.3420 +                    }
 32.3421 +                    lastMappingResultIndex++;
 32.3422 +                    break;
 32.3423 +
 32.3424 +                case "retained":
 32.3425 +                    itemMovedOrRetained(i, lastMappingResultIndex++);
 32.3426 +                    break;
 32.3427 +
 32.3428 +                case "added":
 32.3429 +                    if (movedIndex !== undefined) {
 32.3430 +                        itemMovedOrRetained(i, movedIndex);
 32.3431 +                    } else {
 32.3432 +                        mapData = { arrayEntry: editScriptItem['value'], indexObservable: ko.observable(newMappingResultIndex++) };
 32.3433 +                        newMappingResult.push(mapData);
 32.3434 +                        itemsToProcess.push(mapData);
 32.3435 +                        if (!isFirstExecution)
 32.3436 +                            itemsForAfterAddCallbacks[i] = mapData;
 32.3437 +                    }
 32.3438 +                    break;
 32.3439 +            }
 32.3440 +        }
 32.3441 +
 32.3442 +        // Call beforeMove first before any changes have been made to the DOM
 32.3443 +        callCallback(options['beforeMove'], itemsForMoveCallbacks);
 32.3444 +
 32.3445 +        // Next remove nodes for deleted items (or just clean if there's a beforeRemove callback)
 32.3446 +        ko.utils.arrayForEach(nodesToDelete, options['beforeRemove'] ? ko.cleanNode : ko.removeNode);
 32.3447 +
 32.3448 +        // Next add/reorder the remaining items (will include deleted items if there's a beforeRemove callback)
 32.3449 +        for (var i = 0, nextNode = ko.virtualElements.firstChild(domNode), lastNode, node; mapData = itemsToProcess[i]; i++) {
 32.3450 +            // Get nodes for newly added items
 32.3451 +            if (!mapData.mappedNodes)
 32.3452 +                ko.utils.extend(mapData, mapNodeAndRefreshWhenChanged(domNode, mapping, mapData.arrayEntry, callbackAfterAddingNodes, mapData.indexObservable));
 32.3453 +
 32.3454 +            // Put nodes in the right place if they aren't there already
 32.3455 +            for (var j = 0; node = mapData.mappedNodes[j]; nextNode = node.nextSibling, lastNode = node, j++) {
 32.3456 +                if (node !== nextNode)
 32.3457 +                    ko.virtualElements.insertAfter(domNode, node, lastNode);
 32.3458 +            }
 32.3459 +
 32.3460 +            // Run the callbacks for newly added nodes (for example, to apply bindings, etc.)
 32.3461 +            if (!mapData.initialized && callbackAfterAddingNodes) {
 32.3462 +                callbackAfterAddingNodes(mapData.arrayEntry, mapData.mappedNodes, mapData.indexObservable);
 32.3463 +                mapData.initialized = true;
 32.3464 +            }
 32.3465 +        }
 32.3466 +
 32.3467 +        // If there's a beforeRemove callback, call it after reordering.
 32.3468 +        // Note that we assume that the beforeRemove callback will usually be used to remove the nodes using
 32.3469 +        // some sort of animation, which is why we first reorder the nodes that will be removed. If the
 32.3470 +        // callback instead removes the nodes right away, it would be more efficient to skip reordering them.
 32.3471 +        // Perhaps we'll make that change in the future if this scenario becomes more common.
 32.3472 +        callCallback(options['beforeRemove'], itemsForBeforeRemoveCallbacks);
 32.3473 +
 32.3474 +        // Finally call afterMove and afterAdd callbacks
 32.3475 +        callCallback(options['afterMove'], itemsForMoveCallbacks);
 32.3476 +        callCallback(options['afterAdd'], itemsForAfterAddCallbacks);
 32.3477 +
 32.3478 +        // Store a copy of the array items we just considered so we can difference it next time
 32.3479 +        ko.utils.domData.set(domNode, lastMappingResultDomDataKey, newMappingResult);
 32.3480 +    }
 32.3481 +})();
 32.3482 +
 32.3483 +ko.exportSymbol('utils.setDomNodeChildrenFromArrayMapping', ko.utils.setDomNodeChildrenFromArrayMapping);
 32.3484 +ko.nativeTemplateEngine = function () {
 32.3485 +    this['allowTemplateRewriting'] = false;
 32.3486 +}
 32.3487 +
 32.3488 +ko.nativeTemplateEngine.prototype = new ko.templateEngine();
 32.3489 +ko.nativeTemplateEngine.prototype['renderTemplateSource'] = function (templateSource, bindingContext, options) {
 32.3490 +    var useNodesIfAvailable = !(ko.utils.ieVersion < 9), // IE<9 cloneNode doesn't work properly
 32.3491 +        templateNodesFunc = useNodesIfAvailable ? templateSource['nodes'] : null,
 32.3492 +        templateNodes = templateNodesFunc ? templateSource['nodes']() : null;
 32.3493 +
 32.3494 +    if (templateNodes) {
 32.3495 +        return ko.utils.makeArray(templateNodes.cloneNode(true).childNodes);
 32.3496 +    } else {
 32.3497 +        var templateText = templateSource['text']();
 32.3498 +        return ko.utils.parseHtmlFragment(templateText);
 32.3499 +    }
 32.3500 +};
 32.3501 +
 32.3502 +ko.nativeTemplateEngine.instance = new ko.nativeTemplateEngine();
 32.3503 +ko.setTemplateEngine(ko.nativeTemplateEngine.instance);
 32.3504 +
 32.3505 +ko.exportSymbol('nativeTemplateEngine', ko.nativeTemplateEngine);
 32.3506 +(function() {
 32.3507 +    ko.jqueryTmplTemplateEngine = function () {
 32.3508 +        // Detect which version of jquery-tmpl you're using. Unfortunately jquery-tmpl
 32.3509 +        // doesn't expose a version number, so we have to infer it.
 32.3510 +        // Note that as of Knockout 1.3, we only support jQuery.tmpl 1.0.0pre and later,
 32.3511 +        // which KO internally refers to as version "2", so older versions are no longer detected.
 32.3512 +        var jQueryTmplVersion = this.jQueryTmplVersion = (function() {
 32.3513 +            if ((typeof(jQuery) == "undefined") || !(jQuery['tmpl']))
 32.3514 +                return 0;
 32.3515 +            // Since it exposes no official version number, we use our own numbering system. To be updated as jquery-tmpl evolves.
 32.3516 +            try {
 32.3517 +                if (jQuery['tmpl']['tag']['tmpl']['open'].toString().indexOf('__') >= 0) {
 32.3518 +                    // Since 1.0.0pre, custom tags should append markup to an array called "__"
 32.3519 +                    return 2; // Final version of jquery.tmpl
 32.3520 +                }
 32.3521 +            } catch(ex) { /* Apparently not the version we were looking for */ }
 32.3522 +
 32.3523 +            return 1; // Any older version that we don't support
 32.3524 +        })();
 32.3525 +
 32.3526 +        function ensureHasReferencedJQueryTemplates() {
 32.3527 +            if (jQueryTmplVersion < 2)
 32.3528 +                throw new Error("Your version of jQuery.tmpl is too old. Please upgrade to jQuery.tmpl 1.0.0pre or later.");
 32.3529 +        }
 32.3530 +
 32.3531 +        function executeTemplate(compiledTemplate, data, jQueryTemplateOptions) {
 32.3532 +            return jQuery['tmpl'](compiledTemplate, data, jQueryTemplateOptions);
 32.3533 +        }
 32.3534 +
 32.3535 +        this['renderTemplateSource'] = function(templateSource, bindingContext, options) {
 32.3536 +            options = options || {};
 32.3537 +            ensureHasReferencedJQueryTemplates();
 32.3538 +
 32.3539 +            // Ensure we have stored a precompiled version of this template (don't want to reparse on every render)
 32.3540 +            var precompiled = templateSource['data']('precompiled');
 32.3541 +            if (!precompiled) {
 32.3542 +                var templateText = templateSource['text']() || "";
 32.3543 +                // Wrap in "with($whatever.koBindingContext) { ... }"
 32.3544 +                templateText = "{{ko_with $item.koBindingContext}}" + templateText + "{{/ko_with}}";
 32.3545 +
 32.3546 +                precompiled = jQuery['template'](null, templateText);
 32.3547 +                templateSource['data']('precompiled', precompiled);
 32.3548 +            }
 32.3549 +
 32.3550 +            var data = [bindingContext['$data']]; // Prewrap the data in an array to stop jquery.tmpl from trying to unwrap any arrays
 32.3551 +            var jQueryTemplateOptions = jQuery['extend']({ 'koBindingContext': bindingContext }, options['templateOptions']);
 32.3552 +
 32.3553 +            var resultNodes = executeTemplate(precompiled, data, jQueryTemplateOptions);
 32.3554 +            resultNodes['appendTo'](document.createElement("div")); // Using "appendTo" forces jQuery/jQuery.tmpl to perform necessary cleanup work
 32.3555 +
 32.3556 +            jQuery['fragments'] = {}; // Clear jQuery's fragment cache to avoid a memory leak after a large number of template renders
 32.3557 +            return resultNodes;
 32.3558 +        };
 32.3559 +
 32.3560 +        this['createJavaScriptEvaluatorBlock'] = function(script) {
 32.3561 +            return "{{ko_code ((function() { return " + script + " })()) }}";
 32.3562 +        };
 32.3563 +
 32.3564 +        this['addTemplate'] = function(templateName, templateMarkup) {
 32.3565 +            document.write("<script type='text/html' id='" + templateName + "'>" + templateMarkup + "</script>");
 32.3566 +        };
 32.3567 +
 32.3568 +        if (jQueryTmplVersion > 0) {
 32.3569 +            jQuery['tmpl']['tag']['ko_code'] = {
 32.3570 +                open: "__.push($1 || '');"
 32.3571 +            };
 32.3572 +            jQuery['tmpl']['tag']['ko_with'] = {
 32.3573 +                open: "with($1) {",
 32.3574 +                close: "} "
 32.3575 +            };
 32.3576 +        }
 32.3577 +    };
 32.3578 +
 32.3579 +    ko.jqueryTmplTemplateEngine.prototype = new ko.templateEngine();
 32.3580 +
 32.3581 +    // Use this one by default *only if jquery.tmpl is referenced*
 32.3582 +    var jqueryTmplTemplateEngineInstance = new ko.jqueryTmplTemplateEngine();
 32.3583 +    if (jqueryTmplTemplateEngineInstance.jQueryTmplVersion > 0)
 32.3584 +        ko.setTemplateEngine(jqueryTmplTemplateEngineInstance);
 32.3585 +
 32.3586 +    ko.exportSymbol('jqueryTmplTemplateEngine', ko.jqueryTmplTemplateEngine);
 32.3587 +})();
 32.3588 +});
 32.3589 +})(window,document,navigator,window["jQuery"]);
 32.3590 +})();
 32.3591 \ No newline at end of file
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/KnockoutTest.java	Wed Jan 23 14:49:52 2013 +0100
    33.3 @@ -0,0 +1,62 @@
    33.4 +/**
    33.5 + * Back 2 Browser Bytecode Translator
    33.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    33.7 + *
    33.8 + * This program is free software: you can redistribute it and/or modify
    33.9 + * it under the terms of the GNU General Public License as published by
   33.10 + * the Free Software Foundation, version 2 of the License.
   33.11 + *
   33.12 + * This program is distributed in the hope that it will be useful,
   33.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   33.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   33.15 + * GNU General Public License for more details.
   33.16 + *
   33.17 + * You should have received a copy of the GNU General Public License
   33.18 + * along with this program. Look for COPYING file in the top folder.
   33.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   33.20 + */
   33.21 +package org.apidesign.bck2brwsr.htmlpage;
   33.22 +
   33.23 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
   33.24 +import org.apidesign.bck2brwsr.htmlpage.api.OnEvent;
   33.25 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
   33.26 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
   33.27 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
   33.28 +import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
   33.29 +import org.apidesign.bck2brwsr.vmtest.VMTest;
   33.30 +import org.testng.annotations.Factory;
   33.31 +
   33.32 +/**
   33.33 + *
   33.34 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   33.35 + */
   33.36 +@Page(xhtml="Knockout.xhtml", className="KnockoutModel", properties={
   33.37 +    @Property(name="name", type=String.class)
   33.38 +}) 
   33.39 +public class KnockoutTest {
   33.40 +    
   33.41 +    @HtmlFragment(
   33.42 +        "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
   33.43 +        "Your name: <input id='input' data-bind=\"value: name\"></input>\n" +
   33.44 +        "<button id=\"hello\">Say Hello!</button>\n"
   33.45 +    )
   33.46 +    @BrwsrTest public void modifyValueAssertChangeInModel() {
   33.47 +        KnockoutModel m = new KnockoutModel();
   33.48 +        m.setName("Kukuc");
   33.49 +        m.applyBindings();
   33.50 +        assert "Kukuc".equals(m.INPUT.getValue()) : "Value is really kukuc: " + m.INPUT.getValue();
   33.51 +        m.INPUT.setValue("Jardo");
   33.52 +        m.triggerEvent(m.INPUT, OnEvent.CHANGE);
   33.53 +        assert "Jardo".equals(m.getName()) : "Name property updated: " + m.getName();
   33.54 +    }
   33.55 +    
   33.56 +    @ComputedProperty
   33.57 +    static String helloMessage(String name) {
   33.58 +        return "Hello " + name + "!";
   33.59 +    }
   33.60 +    
   33.61 +    @Factory
   33.62 +    public static Object[] create() {
   33.63 +        return VMTest.create(KnockoutTest.class);
   33.64 +    }
   33.65 +}
    34.1 --- a/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ModelTest.java	Tue Jan 22 17:53:05 2013 +0100
    34.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ModelTest.java	Wed Jan 23 14:49:52 2013 +0100
    34.3 @@ -17,18 +17,103 @@
    34.4   */
    34.5  package org.apidesign.bck2brwsr.htmlpage;
    34.6  
    34.7 +import java.util.ArrayList;
    34.8 +import java.util.List;
    34.9 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
   34.10  import org.apidesign.bck2brwsr.htmlpage.api.Page;
   34.11 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
   34.12  import static org.testng.Assert.*;
   34.13 +import org.testng.annotations.BeforeMethod;
   34.14  import org.testng.annotations.Test;
   34.15  
   34.16  /**
   34.17   *
   34.18   * @author Jaroslav Tulach <jtulach@netbeans.org>
   34.19   */
   34.20 -@Page(xhtml = "Empty.html", className = "Model")
   34.21 +@Page(xhtml = "Empty.html", className = "Model", properties = {
   34.22 +    @Property(name = "value", type = int.class),
   34.23 +    @Property(name = "unrelated", type = long.class)
   34.24 +})
   34.25  public class ModelTest {
   34.26 -    @Test public void classGenerated() {
   34.27 -        Class<?> c = Model.class;
   34.28 -        assertNotNull(c, "Class for empty page generated");
   34.29 +    private Model model;
   34.30 +    private static Model leakedModel;
   34.31 +    
   34.32 +    @BeforeMethod
   34.33 +    public void createModel() {
   34.34 +        model = new Model();
   34.35 +    }
   34.36 +    
   34.37 +    @Test public void classGeneratedWithSetterGetter() {
   34.38 +        model.setValue(10);
   34.39 +        assertEquals(10, model.getValue(), "Value changed");
   34.40 +    }
   34.41 +    
   34.42 +    @Test public void computedMethod() {
   34.43 +        model.setValue(4);
   34.44 +        assertEquals(16, model.getPowerValue());
   34.45 +    }
   34.46 +    
   34.47 +    @Test public void derivedPropertiesAreNotified() {
   34.48 +        MockKnockout my = new MockKnockout();
   34.49 +        MockKnockout.next = my;
   34.50 +        
   34.51 +        model.applyBindings();
   34.52 +        
   34.53 +        model.setValue(33);
   34.54 +        
   34.55 +        assertEquals(my.mutated.size(), 2, "Two properties changed: " + my.mutated);
   34.56 +        assertTrue(my.mutated.contains("powerValue"), "Power value is in there: " + my.mutated);
   34.57 +        assertTrue(my.mutated.contains("value"), "Simple value is in there: " + my.mutated);
   34.58 +        
   34.59 +        my.mutated.clear();
   34.60 +        
   34.61 +        model.setUnrelated(44);
   34.62 +        assertEquals(my.mutated.size(), 1, "One property changed");
   34.63 +        assertTrue(my.mutated.contains("unrelated"), "Its name is unrelated");
   34.64 +    }
   34.65 +    
   34.66 +    @Test public void computedPropertyCannotWriteToModel() {
   34.67 +        leakedModel = model;
   34.68 +        try {
   34.69 +            String res = model.getNotAllowedWrite();
   34.70 +            fail("We should not be allowed to write to the model: " + res);
   34.71 +        } catch (IllegalStateException ex) {
   34.72 +            // OK, we can't read
   34.73 +        }
   34.74 +    }
   34.75 +
   34.76 +    @Test public void computedPropertyCannotReadToModel() {
   34.77 +        leakedModel = model;
   34.78 +        try {
   34.79 +            String res = model.getNotAllowedRead();
   34.80 +            fail("We should not be allowed to read from the model: " + res);
   34.81 +        } catch (IllegalStateException ex) {
   34.82 +            // OK, we can't read
   34.83 +        }
   34.84 +    }
   34.85 +    
   34.86 +    @ComputedProperty
   34.87 +    static int powerValue(int value) {
   34.88 +        return value * value;
   34.89 +    }
   34.90 +    
   34.91 +    @ComputedProperty
   34.92 +    static String notAllowedRead() {
   34.93 +        return "Not allowed callback: " + leakedModel.getUnrelated();
   34.94 +    }
   34.95 +
   34.96 +    @ComputedProperty
   34.97 +    static String notAllowedWrite() {
   34.98 +        leakedModel.setUnrelated(11);
   34.99 +        return "Not allowed callback!";
  34.100 +    }
  34.101 +    
  34.102 +    static class MockKnockout extends Knockout {
  34.103 +        List<String> mutated = new ArrayList<String>();
  34.104 +        
  34.105 +        @Override
  34.106 +        public void valueHasMutated(String prop) {
  34.107 +            mutated.add(prop);
  34.108 +        }
  34.109      }
  34.110  }
    35.1 --- a/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageController.java	Tue Jan 22 17:53:05 2013 +0100
    35.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageController.java	Wed Jan 23 14:49:52 2013 +0100
    35.3 @@ -43,9 +43,14 @@
    35.4   */
    35.5  @Page(xhtml="TestPage.html")
    35.6  public class PageController {
    35.7 +    private static final TestPage PAGE = new TestPage();
    35.8 +    
    35.9      @On(event = CLICK, id="pg.button")
   35.10 -    static void updateTitle() {
   35.11 -        TestPage.PG_TITLE.setText("You want this window to be named " + TestPage.PG_TEXT.getValue());
   35.12 +    static void updateTitle(TestPage ref) {
   35.13 +        if (PAGE != ref) {
   35.14 +            throw new IllegalStateException("Both references should be the same. " + ref + " != " + PAGE);
   35.15 +        }
   35.16 +        ref.PG_TITLE.setText("You want this window to be named " + ref.PG_TEXT.getValue());
   35.17      }
   35.18      
   35.19      @On(event = CLICK, id={ "pg.title", "pg.text" })
   35.20 @@ -53,6 +58,6 @@
   35.21          if (!id.equals("pg.title")) {
   35.22              throw new IllegalStateException();
   35.23          }
   35.24 -        TestPage.PG_TITLE.setText(id);
   35.25 +        PAGE.PG_TITLE.setText(id);
   35.26      }
   35.27  }
    36.1 --- a/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java	Tue Jan 22 17:53:05 2013 +0100
    36.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java	Wed Jan 23 14:49:52 2013 +0100
    36.3 @@ -108,7 +108,9 @@
    36.4              + "\n"
    36.5              + "window.document = doc;\n"
    36.6          );
    36.7 -        Invocable i = compileClass(sb, "org/apidesign/bck2brwsr/htmlpage/PageController");
    36.8 +        Invocable i = compileClass(sb, 
    36.9 +            "org/apidesign/bck2brwsr/htmlpage/PageController"
   36.10 +        );
   36.11  
   36.12          Object ret = null;
   36.13          try {
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/javaquery/api/src/test/resources/org/apidesign/bck2brwsr/htmlpage/Knockout.xhtml	Wed Jan 23 14:49:52 2013 +0100
    37.3 @@ -0,0 +1,25 @@
    37.4 +<?xml version="1.0" encoding="UTF-8"?>
    37.5 +<!--
    37.6 +
    37.7 +    Back 2 Browser Bytecode Translator
    37.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    37.9 +
   37.10 +    This program is free software: you can redistribute it and/or modify
   37.11 +    it under the terms of the GNU General Public License as published by
   37.12 +    the Free Software Foundation, version 2 of the License.
   37.13 +
   37.14 +    This program is distributed in the hope that it will be useful,
   37.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   37.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   37.17 +    GNU General Public License for more details.
   37.18 +
   37.19 +    You should have received a copy of the GNU General Public License
   37.20 +    along with this program. Look for COPYING file in the top folder.
   37.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
   37.22 +
   37.23 +-->
   37.24 +<p>
   37.25 +    <h1 data-bind="text: helloMessage">Loading Bck2Brwsr's Hello World...</h1>
   37.26 +    Your name: <input id="input" data-bind="value: name, valueUpdate: 'afterkeydown'"></input>
   37.27 +    <button id="hello">Say Hello!</button>
   37.28 +</p>
    38.1 --- a/javaquery/demo-calculator-dynamic/pom.xml	Tue Jan 22 17:53:05 2013 +0100
    38.2 +++ b/javaquery/demo-calculator-dynamic/pom.xml	Wed Jan 23 14:49:52 2013 +0100
    38.3 @@ -28,7 +28,7 @@
    38.4                      </execution>
    38.5                  </executions>
    38.6                  <configuration>
    38.7 -                    <startpage>org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml</startpage>
    38.8 +                    <startpage>org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml</startpage>
    38.9                  </configuration>
   38.10              </plugin>
   38.11           <plugin>
   38.12 @@ -54,5 +54,11 @@
   38.13        <artifactId>javaquery.api</artifactId>
   38.14        <version>0.3-SNAPSHOT</version>
   38.15      </dependency>
   38.16 +    <dependency>
   38.17 +      <groupId>org.testng</groupId>
   38.18 +      <artifactId>testng</artifactId>
   38.19 +      <version>6.5.2</version>
   38.20 +      <scope>test</scope>
   38.21 +    </dependency>
   38.22    </dependencies>
   38.23  </project>
    39.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.2 +++ b/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java	Wed Jan 23 14:49:52 2013 +0100
    39.3 @@ -0,0 +1,112 @@
    39.4 +/**
    39.5 + * Back 2 Browser Bytecode Translator
    39.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    39.7 + *
    39.8 + * This program is free software: you can redistribute it and/or modify
    39.9 + * it under the terms of the GNU General Public License as published by
   39.10 + * the Free Software Foundation, version 2 of the License.
   39.11 + *
   39.12 + * This program is distributed in the hope that it will be useful,
   39.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   39.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   39.15 + * GNU General Public License for more details.
   39.16 + *
   39.17 + * You should have received a copy of the GNU General Public License
   39.18 + * along with this program. Look for COPYING file in the top folder.
   39.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   39.20 + */
   39.21 +package org.apidesign.bck2brwsr.demo.calc;
   39.22 +
   39.23 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
   39.24 +import org.apidesign.bck2brwsr.htmlpage.api.On;
   39.25 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
   39.26 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
   39.27 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
   39.28 +
   39.29 +/** HTML5 & Java demo showing the power of 
   39.30 + * <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
   39.31 + * as well as other goodies.
   39.32 + * 
   39.33 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   39.34 + */
   39.35 +@Page(xhtml="Calculator.xhtml", properties = {
   39.36 +    @Property(name = "memory", type = double.class),
   39.37 +    @Property(name = "display", type = double.class),
   39.38 +    @Property(name = "operation", type = String.class),
   39.39 +    @Property(name = "hover", type = boolean.class)
   39.40 +})
   39.41 +public class Calc {
   39.42 +    static {
   39.43 +        new Calculator().applyBindings();
   39.44 +    }
   39.45 +    
   39.46 +    @On(event = CLICK, id="clear")
   39.47 +    static void clear(Calculator c) {
   39.48 +        c.setMemory(0);
   39.49 +        c.setOperation(null);
   39.50 +        c.setDisplay(0);
   39.51 +    }
   39.52 +    
   39.53 +    @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
   39.54 +    static void applyOp(Calculator c, String op) {
   39.55 +        c.setMemory(c.getDisplay());
   39.56 +        c.setOperation(op);
   39.57 +        c.setDisplay(0);
   39.58 +    }
   39.59 +
   39.60 +    @On(event = MOUSE_OVER, id= { "result" })
   39.61 +    static void attemptingIn(Calculator c, String op) {
   39.62 +        c.setHover(true);
   39.63 +    }
   39.64 +    @On(event = MOUSE_OUT, id= { "result" })
   39.65 +    static void attemptingOut(Calculator c, String op) {
   39.66 +        c.setHover(false);
   39.67 +    }
   39.68 +    
   39.69 +    @On(event = CLICK, id="result")
   39.70 +    static void computeTheValue(Calculator c) {
   39.71 +        c.setDisplay(compute(
   39.72 +            c.getOperation(), 
   39.73 +            c.getMemory(), 
   39.74 +            c.getDisplay()
   39.75 +        ));
   39.76 +        c.setMemory(0);
   39.77 +    }
   39.78 +    
   39.79 +    private static double compute(String op, double memory, double display) {
   39.80 +        switch (op) {
   39.81 +            case "plus": return memory + display;
   39.82 +            case "minus": return memory - display;
   39.83 +            case "mul": return memory * display;
   39.84 +            case "div": return memory / display;
   39.85 +            default: throw new IllegalStateException(op);
   39.86 +        }
   39.87 +    }
   39.88 +    
   39.89 +    @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"}) 
   39.90 +    static void addDigit(String digit, Calculator c) {
   39.91 +        digit = digit.substring(1);
   39.92 +        
   39.93 +        double v = c.getDisplay();
   39.94 +        if (v == 0.0) {
   39.95 +            c.setDisplay(Integer.parseInt(digit));
   39.96 +        } else {
   39.97 +            String txt = Double.toString(v);
   39.98 +            if (txt.endsWith(".0")) {
   39.99 +                txt = txt.substring(0, txt.length() - 2);
  39.100 +            }
  39.101 +            txt = txt + digit;
  39.102 +            c.setDisplay(Double.parseDouble(txt));
  39.103 +        }
  39.104 +    }
  39.105 +
  39.106 +    @ComputedProperty
  39.107 +    public static String displayPreview(
  39.108 +        double display, boolean hover, double memory, String operation
  39.109 +    ) {
  39.110 +        if (!hover) {
  39.111 +            return "Type numbers and perform simple operations! Press '=' to get result.";
  39.112 +        }
  39.113 +        return "Attempt to compute " + memory + " " + operation + " " + display + " = " + compute(operation, memory, display);
  39.114 +    }
  39.115 +}
    40.1 --- a/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java	Tue Jan 22 17:53:05 2013 +0100
    40.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.3 @@ -1,89 +0,0 @@
    40.4 -/**
    40.5 - * Back 2 Browser Bytecode Translator
    40.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    40.7 - *
    40.8 - * This program is free software: you can redistribute it and/or modify
    40.9 - * it under the terms of the GNU General Public License as published by
   40.10 - * the Free Software Foundation, version 2 of the License.
   40.11 - *
   40.12 - * This program is distributed in the hope that it will be useful,
   40.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   40.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   40.15 - * GNU General Public License for more details.
   40.16 - *
   40.17 - * You should have received a copy of the GNU General Public License
   40.18 - * along with this program. Look for COPYING file in the top folder.
   40.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   40.20 - */
   40.21 -package org.apidesign.bck2brwsr.mavenhtml;
   40.22 -
   40.23 -import org.apidesign.bck2brwsr.htmlpage.api.On;
   40.24 -import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
   40.25 -import org.apidesign.bck2brwsr.htmlpage.api.Page;
   40.26 -
   40.27 -/** HTML5 & Java demo showing the power of 
   40.28 - * <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
   40.29 - * as well as other goodies.
   40.30 - * 
   40.31 - * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   40.32 - */
   40.33 -@Page(xhtml="Calculator.xhtml")
   40.34 -public class App {
   40.35 -    private static double memory;
   40.36 -    private static String operation;
   40.37 -    
   40.38 -    @On(event = CLICK, id="clear")
   40.39 -    static void clear() {
   40.40 -        memory = 0;
   40.41 -        operation = null;
   40.42 -        Calculator.DISPLAY.setValue("0");
   40.43 -    }
   40.44 -    
   40.45 -    @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
   40.46 -    static void applyOp(String op) {
   40.47 -        memory = getValue();
   40.48 -        operation = op;
   40.49 -        Calculator.DISPLAY.setValue("0");
   40.50 -    }
   40.51 -    
   40.52 -    @On(event = CLICK, id="result")
   40.53 -    static void computeTheValue() {
   40.54 -        switch (operation) {
   40.55 -            case "plus": setValue(memory + getValue()); break;
   40.56 -            case "minus": setValue(memory - getValue()); break;
   40.57 -            case "mul": setValue(memory * getValue()); break;
   40.58 -            case "div": setValue(memory / getValue()); break;
   40.59 -            default: throw new IllegalStateException(operation);
   40.60 -        }
   40.61 -    }
   40.62 -    
   40.63 -    @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"}) 
   40.64 -    static void addDigit(String digit) {
   40.65 -        digit = digit.substring(1);
   40.66 -        String v = Calculator.DISPLAY.getValue();
   40.67 -        if (getValue() == 0.0) {
   40.68 -            Calculator.DISPLAY.setValue(digit);
   40.69 -        } else {
   40.70 -            Calculator.DISPLAY.setValue(v + digit);
   40.71 -        }
   40.72 -    }
   40.73 -    
   40.74 -    private static void setValue(double v) {
   40.75 -        StringBuilder sb = new StringBuilder();
   40.76 -        sb.append(v);
   40.77 -        if (sb.toString().endsWith(".0")) {
   40.78 -            final int l = sb.length();
   40.79 -            sb.delete(l - 2, l);
   40.80 -        }
   40.81 -        Calculator.DISPLAY.setValue(sb.toString());
   40.82 -    }
   40.83 -
   40.84 -    private static double getValue() {
   40.85 -        try {
   40.86 -            return Double.parseDouble(Calculator.DISPLAY.getValue());
   40.87 -        } catch (NumberFormatException ex) {
   40.88 -            Calculator.DISPLAY.setValue("err");
   40.89 -            return 0.0;
   40.90 -        }
   40.91 -    }
   40.92 -}
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml	Wed Jan 23 14:49:52 2013 +0100
    41.3 @@ -0,0 +1,159 @@
    41.4 +<?xml version="1.0" encoding="UTF-8"?>
    41.5 +<!--
    41.6 +
    41.7 +    Back 2 Browser Bytecode Translator
    41.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    41.9 +
   41.10 +    This program is free software: you can redistribute it and/or modify
   41.11 +    it under the terms of the GNU General Public License as published by
   41.12 +    the Free Software Foundation, version 2 of the License.
   41.13 +
   41.14 +    This program is distributed in the hope that it will be useful,
   41.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   41.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   41.17 +    GNU General Public License for more details.
   41.18 +
   41.19 +    You should have received a copy of the GNU General Public License
   41.20 +    along with this program. Look for COPYING file in the top folder.
   41.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
   41.22 +
   41.23 +-->
   41.24 +<!DOCTYPE html>
   41.25 +<html xmlns="http://www.w3.org/1999/xhtml">
   41.26 +    <head>
   41.27 +        <title>Simple Calculator in HTML5 and Java</title>
   41.28 +
   41.29 +        <style type="text/css">
   41.30 +        body {color: #ffffff; background-color: #121e31; font-family: Monospaced}
   41.31 +        pre {color: #ffffff; background-color: #121e31; font-family: Monospaced}
   41.32 +        table {color: #ffffff; background-color: #121e31; font-family: Monospaced}
   41.33 +        .string {color: #e2ce00}
   41.34 +        a {color: #e2ce00}
   41.35 +        .ST1 {color: #0000cc; font-family: Monospaced; font-weight: bold}
   41.36 +        .ST0 {color: #0000ff}
   41.37 +        .comment {color: #428bdd}
   41.38 +        .keyword-directive {color: #f8bb00}
   41.39 +        .tag {color: #f8bb00}
   41.40 +        .ST0 {color: #628fb5; background-color: #1b3450}
   41.41 +        .sgml-comment {color: #808080}
   41.42 +        .value {color: #99006b}
   41.43 +        .argument {color: #007c00}
   41.44 +        .sgml-declaration {color: #bf9221}
   41.45 +        </style>    
   41.46 +        </head>
   41.47 +    <body>
   41.48 +        <h1>Java and HTML5 - Together at Last!</h1>
   41.49 +        <table border="0" cellspacing="2">
   41.50 +            <tbody>
   41.51 +                <tr>
   41.52 +                    <td colspan="4"><input data-bind="value: display" value="0" 
   41.53 +                            style="text-align: right"/>
   41.54 +                </td>
   41.55 +                </tr>
   41.56 +                <tr>
   41.57 +                    <td><button id="n1">1</button></td>
   41.58 +                    <td><button id="n2">2</button></td>
   41.59 +                    <td><button id="n3">3</button></td>
   41.60 +                    <td><button id="plus">+</button></td>
   41.61 +                </tr>
   41.62 +                <tr>
   41.63 +                    <td><button id="n4">4</button></td>
   41.64 +                    <td><button id="n5">5</button></td>
   41.65 +                    <td><button id="n6">6</button></td>
   41.66 +                    <td><button id="minus">-</button></td>
   41.67 +                </tr>
   41.68 +                <tr>
   41.69 +                    <td><button id="n7">7</button></td>
   41.70 +                    <td><button id="n8">8</button></td>
   41.71 +                    <td><button id="n9">9</button></td>
   41.72 +                    <td><button id="mul">*</button></td>
   41.73 +                </tr>
   41.74 +                <tr>
   41.75 +                    <td><button id="clear">C</button></td>
   41.76 +                    <td><button id="n0">0</button></td>
   41.77 +                    <td><button id="result">=</button></td>
   41.78 +                    <td><button id="div">/</button></td>
   41.79 +                </tr>
   41.80 +            </tbody>
   41.81 +        </table>
   41.82 +        <div data-bind="text: displayPreview"></div>
   41.83 +        
   41.84 +        <script src="/bck2brwsr.js"></script>
   41.85 +        <script src="/vm.js"></script>
   41.86 +        <script type="text/javascript">
   41.87 +            vm.loadClass('org.apidesign.bck2brwsr.demo.calc.Calc');
   41.88 +        </script>
   41.89 +        
   41.90 +        <hr/>
   41.91 +    <pre>
   41.92 +    <span class="keyword-directive">package</span> org.apidesign.bck2brwsr.mavenhtml;
   41.93 +
   41.94 +    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.OnClick;
   41.95 +    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.Page;
   41.96 +
   41.97 +    <span class="comment">/**</span> <span class="comment">HTML5</span><span class="comment"> &amp; </span><span class="comment">Java</span> <span class="comment">demo</span> <span class="comment">showing</span> <span class="comment">the</span> <span class="comment">power</span> <span class="comment">of</span> <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
   41.98 +    <span class="comment"> * </span><span class="comment">as</span> <span class="comment">well</span> <span class="comment">as</span> <span class="comment">other</span> <span class="comment">goodies</span><span class="comment">, including type-safe association between</span>
   41.99 +    <span class="comment"> * </span><span class="comment">an XHTML page and Java.</span>
  41.100 +    <span class="comment"> * </span>
  41.101 +    <span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">Jaroslav</span> <span class="comment">Tulach</span> <span class="ST0">&lt;jaroslav.tulach@apidesign.org&gt;</span>
  41.102 +     <span class="comment">*/</span>
  41.103 +    @Page(xhtml=<span class="string">&quot;</span><span class="string">Calculator.xhtml</span><span class="string">&quot;</span>)
  41.104 +    <span class="keyword-directive">public</span> <span class="keyword-directive">class</span> App {
  41.105 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> memory;
  41.106 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> String operation;
  41.107 +
  41.108 +        @OnClick(id=<span class="string">&quot;</span><span class="string">clear</span><span class="string">&quot;</span>)
  41.109 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> clear() {
  41.110 +            memory = <span class="number">0</span>;
  41.111 +            operation = <span class="keyword-directive">null</span>;
  41.112 +            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
  41.113 +        }
  41.114 +
  41.115 +        @OnClick(id= { <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span> })
  41.116 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> applyOp(String op) {
  41.117 +            memory = getValue();
  41.118 +            operation = op;
  41.119 +            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
  41.120 +        }
  41.121 +
  41.122 +        @OnClick(id=<span class="string">&quot;</span><span class="string">result</span><span class="string">&quot;</span>)
  41.123 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> computeTheValue() {
  41.124 +            <span class="keyword-directive">switch</span> (operation) {
  41.125 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>: setValue(memory + getValue()); <span class="keyword-directive">break</span>;
  41.126 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>: setValue(memory - getValue()); <span class="keyword-directive">break</span>;
  41.127 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>: setValue(memory * getValue()); <span class="keyword-directive">break</span>;
  41.128 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span>: setValue(memory / getValue()); <span class="keyword-directive">break</span>;
  41.129 +                <span class="keyword-directive">default</span>: <span class="keyword-directive">throw</span> <span class="keyword-directive">new</span> IllegalStateException(operation);
  41.130 +            }
  41.131 +        }
  41.132 +
  41.133 +        @OnClick(id={<span class="string">&quot;</span><span class="string">n0</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n1</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n2</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n3</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n4</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n5</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n6</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n7</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n8</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n9</span><span class="string">&quot;</span>}) 
  41.134 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> addDigit(String digit) {
  41.135 +            digit = digit.substring(<span class="number">1</span>);
  41.136 +            String v = Calculator.DISPLAY.getValue();
  41.137 +            <span class="keyword-directive">if</span> (getValue() == <span class="number">0.0</span>) {
  41.138 +                Calculator.DISPLAY.setValue(digit);
  41.139 +            } <span class="keyword-directive">else</span> {
  41.140 +                Calculator.DISPLAY.setValue(v + digit);
  41.141 +            }
  41.142 +        }
  41.143 +
  41.144 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> setValue(<span class="keyword-directive">double</span> v) {
  41.145 +            StringBuilder sb = <span class="keyword-directive">new</span> StringBuilder();
  41.146 +            sb.append(v);
  41.147 +            Calculator.DISPLAY.setValue(sb.toString());
  41.148 +        }
  41.149 +
  41.150 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> getValue() {
  41.151 +            <span class="keyword-directive">try</span> {
  41.152 +                <span class="keyword-directive">return</span> Double.parseDouble(Calculator.DISPLAY.getValue());
  41.153 +            } <span class="keyword-directive">catch</span> (NumberFormatException ex) {
  41.154 +                Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">err</span><span class="string">&quot;</span>);
  41.155 +                <span class="keyword-directive">return</span> <span class="number">0.0</span>;
  41.156 +            }
  41.157 +        }
  41.158 +    }
  41.159 +
  41.160 +    </pre>
  41.161 +    </body>
  41.162 +</html>
    42.1 --- a/javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml	Tue Jan 22 17:53:05 2013 +0100
    42.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.3 @@ -1,158 +0,0 @@
    42.4 -<?xml version="1.0" encoding="UTF-8"?>
    42.5 -<!--
    42.6 -
    42.7 -    Back 2 Browser Bytecode Translator
    42.8 -    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    42.9 -
   42.10 -    This program is free software: you can redistribute it and/or modify
   42.11 -    it under the terms of the GNU General Public License as published by
   42.12 -    the Free Software Foundation, version 2 of the License.
   42.13 -
   42.14 -    This program is distributed in the hope that it will be useful,
   42.15 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   42.16 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   42.17 -    GNU General Public License for more details.
   42.18 -
   42.19 -    You should have received a copy of the GNU General Public License
   42.20 -    along with this program. Look for COPYING file in the top folder.
   42.21 -    If not, see http://opensource.org/licenses/GPL-2.0.
   42.22 -
   42.23 --->
   42.24 -<!DOCTYPE html>
   42.25 -<html xmlns="http://www.w3.org/1999/xhtml">
   42.26 -    <head>
   42.27 -        <title>Simple Calculator in HTML5 and Java</title>
   42.28 -
   42.29 -        <style type="text/css">
   42.30 -        body {color: #ffffff; background-color: #121e31; font-family: Monospaced}
   42.31 -        pre {color: #ffffff; background-color: #121e31; font-family: Monospaced}
   42.32 -        table {color: #ffffff; background-color: #121e31; font-family: Monospaced}
   42.33 -        .string {color: #e2ce00}
   42.34 -        a {color: #e2ce00}
   42.35 -        .ST1 {color: #0000cc; font-family: Monospaced; font-weight: bold}
   42.36 -        .ST0 {color: #0000ff}
   42.37 -        .comment {color: #428bdd}
   42.38 -        .keyword-directive {color: #f8bb00}
   42.39 -        .tag {color: #f8bb00}
   42.40 -        .ST0 {color: #628fb5; background-color: #1b3450}
   42.41 -        .sgml-comment {color: #808080}
   42.42 -        .value {color: #99006b}
   42.43 -        .argument {color: #007c00}
   42.44 -        .sgml-declaration {color: #bf9221}
   42.45 -        </style>    
   42.46 -        </head>
   42.47 -    <body>
   42.48 -        <h1>Java and HTML5 - Together at Last!</h1>
   42.49 -        <table border="0" cellspacing="2">
   42.50 -            <tbody>
   42.51 -                <tr>
   42.52 -                    <td colspan="4"><input id="display" value="0" 
   42.53 -                            style="text-align: right"/>
   42.54 -                </td>
   42.55 -                </tr>
   42.56 -                <tr>
   42.57 -                    <td><button id="n1">1</button></td>
   42.58 -                    <td><button id="n2">2</button></td>
   42.59 -                    <td><button id="n3">3</button></td>
   42.60 -                    <td><button id="plus">+</button></td>
   42.61 -                </tr>
   42.62 -                <tr>
   42.63 -                    <td><button id="n4">4</button></td>
   42.64 -                    <td><button id="n5">5</button></td>
   42.65 -                    <td><button id="n6">6</button></td>
   42.66 -                    <td><button id="minus">-</button></td>
   42.67 -                </tr>
   42.68 -                <tr>
   42.69 -                    <td><button id="n7">7</button></td>
   42.70 -                    <td><button id="n8">8</button></td>
   42.71 -                    <td><button id="n9">9</button></td>
   42.72 -                    <td><button id="mul">*</button></td>
   42.73 -                </tr>
   42.74 -                <tr>
   42.75 -                    <td><button id="clear">C</button></td>
   42.76 -                    <td><button id="n0">0</button></td>
   42.77 -                    <td><button id="result">=</button></td>
   42.78 -                    <td><button id="div">/</button></td>
   42.79 -                </tr>
   42.80 -            </tbody>
   42.81 -        </table>
   42.82 -
   42.83 -        <script src="/bck2brwsr.js"></script>
   42.84 -        <script src="/vm.js"></script>
   42.85 -        <script type="text/javascript">
   42.86 -            vm.loadClass('org.apidesign.bck2brwsr.mavenhtml.Calculator');
   42.87 -        </script>
   42.88 -        
   42.89 -        <hr/>
   42.90 -    <pre>
   42.91 -    <span class="keyword-directive">package</span> org.apidesign.bck2brwsr.mavenhtml;
   42.92 -
   42.93 -    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.OnClick;
   42.94 -    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.Page;
   42.95 -
   42.96 -    <span class="comment">/**</span> <span class="comment">HTML5</span><span class="comment"> &amp; </span><span class="comment">Java</span> <span class="comment">demo</span> <span class="comment">showing</span> <span class="comment">the</span> <span class="comment">power</span> <span class="comment">of</span> <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
   42.97 -    <span class="comment"> * </span><span class="comment">as</span> <span class="comment">well</span> <span class="comment">as</span> <span class="comment">other</span> <span class="comment">goodies</span><span class="comment">, including type-safe association between</span>
   42.98 -    <span class="comment"> * </span><span class="comment">an XHTML page and Java.</span>
   42.99 -    <span class="comment"> * </span>
  42.100 -    <span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">Jaroslav</span> <span class="comment">Tulach</span> <span class="ST0">&lt;jaroslav.tulach@apidesign.org&gt;</span>
  42.101 -     <span class="comment">*/</span>
  42.102 -    @Page(xhtml=<span class="string">&quot;</span><span class="string">Calculator.xhtml</span><span class="string">&quot;</span>)
  42.103 -    <span class="keyword-directive">public</span> <span class="keyword-directive">class</span> App {
  42.104 -        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> memory;
  42.105 -        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> String operation;
  42.106 -
  42.107 -        @OnClick(id=<span class="string">&quot;</span><span class="string">clear</span><span class="string">&quot;</span>)
  42.108 -        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> clear() {
  42.109 -            memory = <span class="number">0</span>;
  42.110 -            operation = <span class="keyword-directive">null</span>;
  42.111 -            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
  42.112 -        }
  42.113 -
  42.114 -        @OnClick(id= { <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span> })
  42.115 -        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> applyOp(String op) {
  42.116 -            memory = getValue();
  42.117 -            operation = op;
  42.118 -            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
  42.119 -        }
  42.120 -
  42.121 -        @OnClick(id=<span class="string">&quot;</span><span class="string">result</span><span class="string">&quot;</span>)
  42.122 -        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> computeTheValue() {
  42.123 -            <span class="keyword-directive">switch</span> (operation) {
  42.124 -                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>: setValue(memory + getValue()); <span class="keyword-directive">break</span>;
  42.125 -                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>: setValue(memory - getValue()); <span class="keyword-directive">break</span>;
  42.126 -                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>: setValue(memory * getValue()); <span class="keyword-directive">break</span>;
  42.127 -                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span>: setValue(memory / getValue()); <span class="keyword-directive">break</span>;
  42.128 -                <span class="keyword-directive">default</span>: <span class="keyword-directive">throw</span> <span class="keyword-directive">new</span> IllegalStateException(operation);
  42.129 -            }
  42.130 -        }
  42.131 -
  42.132 -        @OnClick(id={<span class="string">&quot;</span><span class="string">n0</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n1</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n2</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n3</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n4</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n5</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n6</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n7</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n8</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n9</span><span class="string">&quot;</span>}) 
  42.133 -        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> addDigit(String digit) {
  42.134 -            digit = digit.substring(<span class="number">1</span>);
  42.135 -            String v = Calculator.DISPLAY.getValue();
  42.136 -            <span class="keyword-directive">if</span> (getValue() == <span class="number">0.0</span>) {
  42.137 -                Calculator.DISPLAY.setValue(digit);
  42.138 -            } <span class="keyword-directive">else</span> {
  42.139 -                Calculator.DISPLAY.setValue(v + digit);
  42.140 -            }
  42.141 -        }
  42.142 -
  42.143 -        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> setValue(<span class="keyword-directive">double</span> v) {
  42.144 -            StringBuilder sb = <span class="keyword-directive">new</span> StringBuilder();
  42.145 -            sb.append(v);
  42.146 -            Calculator.DISPLAY.setValue(sb.toString());
  42.147 -        }
  42.148 -
  42.149 -        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> getValue() {
  42.150 -            <span class="keyword-directive">try</span> {
  42.151 -                <span class="keyword-directive">return</span> Double.parseDouble(Calculator.DISPLAY.getValue());
  42.152 -            } <span class="keyword-directive">catch</span> (NumberFormatException ex) {
  42.153 -                Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">err</span><span class="string">&quot;</span>);
  42.154 -                <span class="keyword-directive">return</span> <span class="number">0.0</span>;
  42.155 -            }
  42.156 -        }
  42.157 -    }
  42.158 -
  42.159 -    </pre>
  42.160 -    </body>
  42.161 -</html>
    43.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.2 +++ b/javaquery/demo-calculator-dynamic/src/test/java/org/apidesign/bck2brwsr/demo/calc/CalcTest.java	Wed Jan 23 14:49:52 2013 +0100
    43.3 @@ -0,0 +1,46 @@
    43.4 +/**
    43.5 + * Back 2 Browser Bytecode Translator
    43.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    43.7 + *
    43.8 + * This program is free software: you can redistribute it and/or modify
    43.9 + * it under the terms of the GNU General Public License as published by
   43.10 + * the Free Software Foundation, version 2 of the License.
   43.11 + *
   43.12 + * This program is distributed in the hope that it will be useful,
   43.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   43.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   43.15 + * GNU General Public License for more details.
   43.16 + *
   43.17 + * You should have received a copy of the GNU General Public License
   43.18 + * along with this program. Look for COPYING file in the top folder.
   43.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   43.20 + */
   43.21 +package org.apidesign.bck2brwsr.demo.calc;
   43.22 +
   43.23 +import static org.testng.Assert.*;
   43.24 +import org.testng.annotations.BeforeMethod;
   43.25 +import org.testng.annotations.Test;
   43.26 +
   43.27 +/** Demonstrating POJO testing of HTML page model.
   43.28 + *
   43.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   43.30 + */
   43.31 +public class CalcTest {
   43.32 +    private Calculator model;
   43.33 +    
   43.34 +
   43.35 +    @BeforeMethod
   43.36 +    public void initModel() {
   43.37 +        model = new Calculator().applyBindings();
   43.38 +    }
   43.39 +
   43.40 +    @Test
   43.41 +    public void testSomeMethod() {
   43.42 +        model.setDisplay(10);
   43.43 +        Calc.applyOp(model, "plus");
   43.44 +        assertEquals(0.0, model.getDisplay(), "Cleared after pressing +");
   43.45 +        model.setDisplay(5);
   43.46 +        Calc.computeTheValue(model);
   43.47 +        assertEquals(15.0, model.getDisplay(), "Shows fifteen");
   43.48 +    }
   43.49 +}
    44.1 --- a/javaquery/demo-calculator/pom.xml	Tue Jan 22 17:53:05 2013 +0100
    44.2 +++ b/javaquery/demo-calculator/pom.xml	Wed Jan 23 14:49:52 2013 +0100
    44.3 @@ -42,7 +42,7 @@
    44.4                  <configuration>
    44.5                      <executable>xdg-open</executable>
    44.6                      <arguments>
    44.7 -                        <argument>${project.build.directory}/classes/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml</argument>
    44.8 +                        <argument>${project.build.directory}/classes/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calculator.xhtml</argument>
    44.9                      </arguments>
   44.10                  </configuration>
   44.11              </plugin>
    45.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.2 +++ b/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calc.java	Wed Jan 23 14:49:52 2013 +0100
    45.3 @@ -0,0 +1,112 @@
    45.4 +/**
    45.5 + * Back 2 Browser Bytecode Translator
    45.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    45.7 + *
    45.8 + * This program is free software: you can redistribute it and/or modify
    45.9 + * it under the terms of the GNU General Public License as published by
   45.10 + * the Free Software Foundation, version 2 of the License.
   45.11 + *
   45.12 + * This program is distributed in the hope that it will be useful,
   45.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   45.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   45.15 + * GNU General Public License for more details.
   45.16 + *
   45.17 + * You should have received a copy of the GNU General Public License
   45.18 + * along with this program. Look for COPYING file in the top folder.
   45.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   45.20 + */
   45.21 +package org.apidesign.bck2brwsr.demo.calc.staticcompilation;
   45.22 +
   45.23 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
   45.24 +import org.apidesign.bck2brwsr.htmlpage.api.On;
   45.25 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
   45.26 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
   45.27 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
   45.28 +
   45.29 +/** HTML5 & Java demo showing the power of 
   45.30 + * <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
   45.31 + * as well as other goodies.
   45.32 + * 
   45.33 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   45.34 + */
   45.35 +@Page(xhtml="Calculator.xhtml", properties = {
   45.36 +    @Property(name = "memory", type = double.class),
   45.37 +    @Property(name = "display", type = double.class),
   45.38 +    @Property(name = "operation", type = String.class),
   45.39 +    @Property(name = "hover", type = boolean.class)
   45.40 +})
   45.41 +public class Calc {
   45.42 +    static {
   45.43 +        new Calculator().applyBindings();
   45.44 +    }
   45.45 +    
   45.46 +    @On(event = CLICK, id="clear")
   45.47 +    static void clear(Calculator c) {
   45.48 +        c.setMemory(0);
   45.49 +        c.setOperation(null);
   45.50 +        c.setDisplay(0);
   45.51 +    }
   45.52 +    
   45.53 +    @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
   45.54 +    static void applyOp(Calculator c, String op) {
   45.55 +        c.setMemory(c.getDisplay());
   45.56 +        c.setOperation(op);
   45.57 +        c.setDisplay(0);
   45.58 +    }
   45.59 +
   45.60 +    @On(event = MOUSE_OVER, id= { "result" })
   45.61 +    static void attemptingIn(Calculator c, String op) {
   45.62 +        c.setHover(true);
   45.63 +    }
   45.64 +    @On(event = MOUSE_OUT, id= { "result" })
   45.65 +    static void attemptingOut(Calculator c, String op) {
   45.66 +        c.setHover(false);
   45.67 +    }
   45.68 +    
   45.69 +    @On(event = CLICK, id="result")
   45.70 +    static void computeTheValue(Calculator c) {
   45.71 +        c.setDisplay(compute(
   45.72 +            c.getOperation(), 
   45.73 +            c.getMemory(), 
   45.74 +            c.getDisplay()
   45.75 +        ));
   45.76 +        c.setMemory(0);
   45.77 +    }
   45.78 +    
   45.79 +    private static double compute(String op, double memory, double display) {
   45.80 +        switch (op) {
   45.81 +            case "plus": return memory + display;
   45.82 +            case "minus": return memory - display;
   45.83 +            case "mul": return memory * display;
   45.84 +            case "div": return memory / display;
   45.85 +            default: throw new IllegalStateException(op);
   45.86 +        }
   45.87 +    }
   45.88 +    
   45.89 +    @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"}) 
   45.90 +    static void addDigit(String digit, Calculator c) {
   45.91 +        digit = digit.substring(1);
   45.92 +        
   45.93 +        double v = c.getDisplay();
   45.94 +        if (v == 0.0) {
   45.95 +            c.setDisplay(Integer.parseInt(digit));
   45.96 +        } else {
   45.97 +            String txt = Double.toString(v);
   45.98 +            if (txt.endsWith(".0")) {
   45.99 +                txt = txt.substring(0, txt.length() - 2);
  45.100 +            }
  45.101 +            txt = txt + digit;
  45.102 +            c.setDisplay(Double.parseDouble(txt));
  45.103 +        }
  45.104 +    }
  45.105 +
  45.106 +    @ComputedProperty
  45.107 +    public static String displayPreview(
  45.108 +        double display, boolean hover, double memory, String operation
  45.109 +    ) {
  45.110 +        if (!hover) {
  45.111 +            return "Type numbers and perform simple operations! Press '=' to get result.";
  45.112 +        }
  45.113 +        return "Attempt to compute " + memory + " " + operation + " " + display + " = " + compute(operation, memory, display);
  45.114 +    }
  45.115 +}
    46.1 --- a/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/mavenhtml/App.java	Tue Jan 22 17:53:05 2013 +0100
    46.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.3 @@ -1,89 +0,0 @@
    46.4 -/**
    46.5 - * Back 2 Browser Bytecode Translator
    46.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    46.7 - *
    46.8 - * This program is free software: you can redistribute it and/or modify
    46.9 - * it under the terms of the GNU General Public License as published by
   46.10 - * the Free Software Foundation, version 2 of the License.
   46.11 - *
   46.12 - * This program is distributed in the hope that it will be useful,
   46.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   46.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   46.15 - * GNU General Public License for more details.
   46.16 - *
   46.17 - * You should have received a copy of the GNU General Public License
   46.18 - * along with this program. Look for COPYING file in the top folder.
   46.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   46.20 - */
   46.21 -package org.apidesign.bck2brwsr.mavenhtml;
   46.22 -
   46.23 -import org.apidesign.bck2brwsr.htmlpage.api.On;
   46.24 -import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
   46.25 -import org.apidesign.bck2brwsr.htmlpage.api.Page;
   46.26 -
   46.27 -/** HTML5 & Java demo showing the power of 
   46.28 - * <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
   46.29 - * as well as other goodies.
   46.30 - * 
   46.31 - * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   46.32 - */
   46.33 -@Page(xhtml="Calculator.xhtml")
   46.34 -public class App {
   46.35 -    private static double memory;
   46.36 -    private static String operation;
   46.37 -    
   46.38 -    @On(event = CLICK, id="clear")
   46.39 -    static void clear() {
   46.40 -        memory = 0;
   46.41 -        operation = null;
   46.42 -        Calculator.DISPLAY.setValue("0");
   46.43 -    }
   46.44 -    
   46.45 -    @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
   46.46 -    static void applyOp(String op) {
   46.47 -        memory = getValue();
   46.48 -        operation = op;
   46.49 -        Calculator.DISPLAY.setValue("0");
   46.50 -    }
   46.51 -    
   46.52 -    @On(event = CLICK, id="result")
   46.53 -    static void computeTheValue() {
   46.54 -        switch (operation) {
   46.55 -            case "plus": setValue(memory + getValue()); break;
   46.56 -            case "minus": setValue(memory - getValue()); break;
   46.57 -            case "mul": setValue(memory * getValue()); break;
   46.58 -            case "div": setValue(memory / getValue()); break;
   46.59 -            default: throw new IllegalStateException(operation);
   46.60 -        }
   46.61 -    }
   46.62 -    
   46.63 -    @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"}) 
   46.64 -    static void addDigit(String digit) {
   46.65 -        digit = digit.substring(1);
   46.66 -        String v = Calculator.DISPLAY.getValue();
   46.67 -        if (getValue() == 0.0) {
   46.68 -            Calculator.DISPLAY.setValue(digit);
   46.69 -        } else {
   46.70 -            Calculator.DISPLAY.setValue(v + digit);
   46.71 -        }
   46.72 -    }
   46.73 -    
   46.74 -    private static void setValue(double v) {
   46.75 -        StringBuilder sb = new StringBuilder();
   46.76 -        sb.append(v);
   46.77 -        if (sb.toString().endsWith(".0")) {
   46.78 -            final int l = sb.length();
   46.79 -            sb.delete(l - 2, l);
   46.80 -        }
   46.81 -        Calculator.DISPLAY.setValue(sb.toString());
   46.82 -    }
   46.83 -
   46.84 -    private static double getValue() {
   46.85 -        try {
   46.86 -            return Double.parseDouble(Calculator.DISPLAY.getValue());
   46.87 -        } catch (NumberFormatException ex) {
   46.88 -            Calculator.DISPLAY.setValue("err");
   46.89 -            return 0.0;
   46.90 -        }
   46.91 -    }
   46.92 -}
    47.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.2 +++ b/javaquery/demo-calculator/src/main/resources/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calculator.xhtml	Wed Jan 23 14:49:52 2013 +0100
    47.3 @@ -0,0 +1,154 @@
    47.4 +<?xml version="1.0" encoding="UTF-8"?>
    47.5 +<!--
    47.6 +
    47.7 +    Back 2 Browser Bytecode Translator
    47.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    47.9 +
   47.10 +    This program is free software: you can redistribute it and/or modify
   47.11 +    it under the terms of the GNU General Public License as published by
   47.12 +    the Free Software Foundation, version 2 of the License.
   47.13 +
   47.14 +    This program is distributed in the hope that it will be useful,
   47.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   47.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   47.17 +    GNU General Public License for more details.
   47.18 +
   47.19 +    You should have received a copy of the GNU General Public License
   47.20 +    along with this program. Look for COPYING file in the top folder.
   47.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
   47.22 +
   47.23 +-->
   47.24 +<!DOCTYPE html>
   47.25 +<html xmlns="http://www.w3.org/1999/xhtml">
   47.26 +    <head>
   47.27 +        <title>Simple Calculator in HTML5 and Java</title>
   47.28 +
   47.29 +        <style type="text/css">
   47.30 +        body {color: #ffffff; background-color: #121e31; font-family: Monospaced}
   47.31 +        pre {color: #ffffff; background-color: #121e31; font-family: Monospaced}
   47.32 +        table {color: #ffffff; background-color: #121e31; font-family: Monospaced}
   47.33 +        .string {color: #e2ce00}
   47.34 +        a {color: #e2ce00}
   47.35 +        .ST1 {color: #0000cc; font-family: Monospaced; font-weight: bold}
   47.36 +        .ST0 {color: #0000ff}
   47.37 +        .comment {color: #428bdd}
   47.38 +        .keyword-directive {color: #f8bb00}
   47.39 +        .tag {color: #f8bb00}
   47.40 +        .ST0 {color: #628fb5; background-color: #1b3450}
   47.41 +        .sgml-comment {color: #808080}
   47.42 +        .value {color: #99006b}
   47.43 +        .argument {color: #007c00}
   47.44 +        .sgml-declaration {color: #bf9221}
   47.45 +        </style>    
   47.46 +        </head>
   47.47 +    <body>
   47.48 +        <h1>Java and HTML5 - Together at Last!</h1>
   47.49 +        <table border="0" cellspacing="2">
   47.50 +            <tbody>
   47.51 +                <tr>
   47.52 +                    <td colspan="4"><input data-bind="value: display" value="0" 
   47.53 +                            style="text-align: right"/>
   47.54 +                </td>
   47.55 +                </tr>
   47.56 +                <tr>
   47.57 +                    <td><button id="n1">1</button></td>
   47.58 +                    <td><button id="n2">2</button></td>
   47.59 +                    <td><button id="n3">3</button></td>
   47.60 +                    <td><button id="plus">+</button></td>
   47.61 +                </tr>
   47.62 +                <tr>
   47.63 +                    <td><button id="n4">4</button></td>
   47.64 +                    <td><button id="n5">5</button></td>
   47.65 +                    <td><button id="n6">6</button></td>
   47.66 +                    <td><button id="minus">-</button></td>
   47.67 +                </tr>
   47.68 +                <tr>
   47.69 +                    <td><button id="n7">7</button></td>
   47.70 +                    <td><button id="n8">8</button></td>
   47.71 +                    <td><button id="n9">9</button></td>
   47.72 +                    <td><button id="mul">*</button></td>
   47.73 +                </tr>
   47.74 +                <tr>
   47.75 +                    <td><button id="clear">C</button></td>
   47.76 +                    <td><button id="n0">0</button></td>
   47.77 +                    <td><button id="result">=</button></td>
   47.78 +                    <td><button id="div">/</button></td>
   47.79 +                </tr>
   47.80 +            </tbody>
   47.81 +        </table>
   47.82 +        <div data-bind="text: displayPreview"></div>
   47.83 +        <script src="bootjava.js"/>
   47.84 +        
   47.85 +        <hr/>
   47.86 +    <pre>
   47.87 +    <span class="keyword-directive">package</span> org.apidesign.bck2brwsr.mavenhtml;
   47.88 +
   47.89 +    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.OnClick;
   47.90 +    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.Page;
   47.91 +
   47.92 +    <span class="comment">/**</span> <span class="comment">HTML5</span><span class="comment"> &amp; </span><span class="comment">Java</span> <span class="comment">demo</span> <span class="comment">showing</span> <span class="comment">the</span> <span class="comment">power</span> <span class="comment">of</span> <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
   47.93 +    <span class="comment"> * </span><span class="comment">as</span> <span class="comment">well</span> <span class="comment">as</span> <span class="comment">other</span> <span class="comment">goodies</span><span class="comment">, including type-safe association between</span>
   47.94 +    <span class="comment"> * </span><span class="comment">an XHTML page and Java.</span>
   47.95 +    <span class="comment"> * </span>
   47.96 +    <span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">Jaroslav</span> <span class="comment">Tulach</span> <span class="ST0">&lt;jaroslav.tulach@apidesign.org&gt;</span>
   47.97 +     <span class="comment">*/</span>
   47.98 +    @Page(xhtml=<span class="string">&quot;</span><span class="string">Calculator.xhtml</span><span class="string">&quot;</span>)
   47.99 +    <span class="keyword-directive">public</span> <span class="keyword-directive">class</span> App {
  47.100 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> memory;
  47.101 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> String operation;
  47.102 +
  47.103 +        @OnClick(id=<span class="string">&quot;</span><span class="string">clear</span><span class="string">&quot;</span>)
  47.104 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> clear() {
  47.105 +            memory = <span class="number">0</span>;
  47.106 +            operation = <span class="keyword-directive">null</span>;
  47.107 +            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
  47.108 +        }
  47.109 +
  47.110 +        @OnClick(id= { <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span> })
  47.111 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> applyOp(String op) {
  47.112 +            memory = getValue();
  47.113 +            operation = op;
  47.114 +            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
  47.115 +        }
  47.116 +
  47.117 +        @OnClick(id=<span class="string">&quot;</span><span class="string">result</span><span class="string">&quot;</span>)
  47.118 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> computeTheValue() {
  47.119 +            <span class="keyword-directive">switch</span> (operation) {
  47.120 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>: setValue(memory + getValue()); <span class="keyword-directive">break</span>;
  47.121 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>: setValue(memory - getValue()); <span class="keyword-directive">break</span>;
  47.122 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>: setValue(memory * getValue()); <span class="keyword-directive">break</span>;
  47.123 +                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span>: setValue(memory / getValue()); <span class="keyword-directive">break</span>;
  47.124 +                <span class="keyword-directive">default</span>: <span class="keyword-directive">throw</span> <span class="keyword-directive">new</span> IllegalStateException(operation);
  47.125 +            }
  47.126 +        }
  47.127 +
  47.128 +        @OnClick(id={<span class="string">&quot;</span><span class="string">n0</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n1</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n2</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n3</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n4</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n5</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n6</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n7</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n8</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n9</span><span class="string">&quot;</span>}) 
  47.129 +        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> addDigit(String digit) {
  47.130 +            digit = digit.substring(<span class="number">1</span>);
  47.131 +            String v = Calculator.DISPLAY.getValue();
  47.132 +            <span class="keyword-directive">if</span> (getValue() == <span class="number">0.0</span>) {
  47.133 +                Calculator.DISPLAY.setValue(digit);
  47.134 +            } <span class="keyword-directive">else</span> {
  47.135 +                Calculator.DISPLAY.setValue(v + digit);
  47.136 +            }
  47.137 +        }
  47.138 +
  47.139 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> setValue(<span class="keyword-directive">double</span> v) {
  47.140 +            StringBuilder sb = <span class="keyword-directive">new</span> StringBuilder();
  47.141 +            sb.append(v);
  47.142 +            Calculator.DISPLAY.setValue(sb.toString());
  47.143 +        }
  47.144 +
  47.145 +        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> getValue() {
  47.146 +            <span class="keyword-directive">try</span> {
  47.147 +                <span class="keyword-directive">return</span> Double.parseDouble(Calculator.DISPLAY.getValue());
  47.148 +            } <span class="keyword-directive">catch</span> (NumberFormatException ex) {
  47.149 +                Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">err</span><span class="string">&quot;</span>);
  47.150 +                <span class="keyword-directive">return</span> <span class="number">0.0</span>;
  47.151 +            }
  47.152 +        }
  47.153 +    }
  47.154 +
  47.155 +    </pre>
  47.156 +    </body>
  47.157 +</html>
    48.1 --- a/javaquery/demo-calculator/src/main/resources/org/apidesign/bck2brwsr/mavenhtml/Calculator.xhtml	Tue Jan 22 17:53:05 2013 +0100
    48.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.3 @@ -1,154 +0,0 @@
    48.4 -<?xml version="1.0" encoding="UTF-8"?>
    48.5 -<!--
    48.6 -
    48.7 -    Back 2 Browser Bytecode Translator
    48.8 -    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    48.9 -
   48.10 -    This program is free software: you can redistribute it and/or modify
   48.11 -    it under the terms of the GNU General Public License as published by
   48.12 -    the Free Software Foundation, version 2 of the License.
   48.13 -
   48.14 -    This program is distributed in the hope that it will be useful,
   48.15 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   48.16 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   48.17 -    GNU General Public License for more details.
   48.18 -
   48.19 -    You should have received a copy of the GNU General Public License
   48.20 -    along with this program. Look for COPYING file in the top folder.
   48.21 -    If not, see http://opensource.org/licenses/GPL-2.0.
   48.22 -
   48.23 --->
   48.24 -<!DOCTYPE html>
   48.25 -<html xmlns="http://www.w3.org/1999/xhtml">
   48.26 -    <head>
   48.27 -        <title>Simple Calculator in HTML5 and Java</title>
   48.28 -
   48.29 -        <style type="text/css">
   48.30 -        body {color: #ffffff; background-color: #121e31; font-family: Monospaced}
   48.31 -        pre {color: #ffffff; background-color: #121e31; font-family: Monospaced}
   48.32 -        table {color: #ffffff; background-color: #121e31; font-family: Monospaced}
   48.33 -        .string {color: #e2ce00}
   48.34 -        a {color: #e2ce00}
   48.35 -        .ST1 {color: #0000cc; font-family: Monospaced; font-weight: bold}
   48.36 -        .ST0 {color: #0000ff}
   48.37 -        .comment {color: #428bdd}
   48.38 -        .keyword-directive {color: #f8bb00}
   48.39 -        .tag {color: #f8bb00}
   48.40 -        .ST0 {color: #628fb5; background-color: #1b3450}
   48.41 -        .sgml-comment {color: #808080}
   48.42 -        .value {color: #99006b}
   48.43 -        .argument {color: #007c00}
   48.44 -        .sgml-declaration {color: #bf9221}
   48.45 -        </style>    
   48.46 -        </head>
   48.47 -    <body>
   48.48 -        <h1>Java and HTML5 - Together at Last!</h1>
   48.49 -        <table border="0" cellspacing="2">
   48.50 -            <tbody>
   48.51 -                <tr>
   48.52 -                    <td colspan="4"><input id="display" value="0" 
   48.53 -                            style="text-align: right"/>
   48.54 -                </td>
   48.55 -                </tr>
   48.56 -                <tr>
   48.57 -                    <td><button id="n1">1</button></td>
   48.58 -                    <td><button id="n2">2</button></td>
   48.59 -                    <td><button id="n3">3</button></td>
   48.60 -                    <td><button id="plus">+</button></td>
   48.61 -                </tr>
   48.62 -                <tr>
   48.63 -                    <td><button id="n4">4</button></td>
   48.64 -                    <td><button id="n5">5</button></td>
   48.65 -                    <td><button id="n6">6</button></td>
   48.66 -                    <td><button id="minus">-</button></td>
   48.67 -                </tr>
   48.68 -                <tr>
   48.69 -                    <td><button id="n7">7</button></td>
   48.70 -                    <td><button id="n8">8</button></td>
   48.71 -                    <td><button id="n9">9</button></td>
   48.72 -                    <td><button id="mul">*</button></td>
   48.73 -                </tr>
   48.74 -                <tr>
   48.75 -                    <td><button id="clear">C</button></td>
   48.76 -                    <td><button id="n0">0</button></td>
   48.77 -                    <td><button id="result">=</button></td>
   48.78 -                    <td><button id="div">/</button></td>
   48.79 -                </tr>
   48.80 -            </tbody>
   48.81 -        </table>
   48.82 -
   48.83 -        <script src="bootjava.js"/>
   48.84 -        
   48.85 -        <hr/>
   48.86 -    <pre>
   48.87 -    <span class="keyword-directive">package</span> org.apidesign.bck2brwsr.mavenhtml;
   48.88 -
   48.89 -    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.OnClick;
   48.90 -    <span class="keyword-directive">import</span> org.apidesign.bck2brwsr.htmlpage.api.Page;
   48.91 -
   48.92 -    <span class="comment">/**</span> <span class="comment">HTML5</span><span class="comment"> &amp; </span><span class="comment">Java</span> <span class="comment">demo</span> <span class="comment">showing</span> <span class="comment">the</span> <span class="comment">power</span> <span class="comment">of</span> <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
   48.93 -    <span class="comment"> * </span><span class="comment">as</span> <span class="comment">well</span> <span class="comment">as</span> <span class="comment">other</span> <span class="comment">goodies</span><span class="comment">, including type-safe association between</span>
   48.94 -    <span class="comment"> * </span><span class="comment">an XHTML page and Java.</span>
   48.95 -    <span class="comment"> * </span>
   48.96 -    <span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">Jaroslav</span> <span class="comment">Tulach</span> <span class="ST0">&lt;jaroslav.tulach@apidesign.org&gt;</span>
   48.97 -     <span class="comment">*/</span>
   48.98 -    @Page(xhtml=<span class="string">&quot;</span><span class="string">Calculator.xhtml</span><span class="string">&quot;</span>)
   48.99 -    <span class="keyword-directive">public</span> <span class="keyword-directive">class</span> App {
  48.100 -        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> memory;
  48.101 -        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> String operation;
  48.102 -
  48.103 -        @OnClick(id=<span class="string">&quot;</span><span class="string">clear</span><span class="string">&quot;</span>)
  48.104 -        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> clear() {
  48.105 -            memory = <span class="number">0</span>;
  48.106 -            operation = <span class="keyword-directive">null</span>;
  48.107 -            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
  48.108 -        }
  48.109 -
  48.110 -        @OnClick(id= { <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span> })
  48.111 -        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> applyOp(String op) {
  48.112 -            memory = getValue();
  48.113 -            operation = op;
  48.114 -            Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">0</span><span class="string">&quot;</span>);
  48.115 -        }
  48.116 -
  48.117 -        @OnClick(id=<span class="string">&quot;</span><span class="string">result</span><span class="string">&quot;</span>)
  48.118 -        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> computeTheValue() {
  48.119 -            <span class="keyword-directive">switch</span> (operation) {
  48.120 -                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">plus</span><span class="string">&quot;</span>: setValue(memory + getValue()); <span class="keyword-directive">break</span>;
  48.121 -                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">minus</span><span class="string">&quot;</span>: setValue(memory - getValue()); <span class="keyword-directive">break</span>;
  48.122 -                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">mul</span><span class="string">&quot;</span>: setValue(memory * getValue()); <span class="keyword-directive">break</span>;
  48.123 -                <span class="keyword-directive">case</span> <span class="string">&quot;</span><span class="string">div</span><span class="string">&quot;</span>: setValue(memory / getValue()); <span class="keyword-directive">break</span>;
  48.124 -                <span class="keyword-directive">default</span>: <span class="keyword-directive">throw</span> <span class="keyword-directive">new</span> IllegalStateException(operation);
  48.125 -            }
  48.126 -        }
  48.127 -
  48.128 -        @OnClick(id={<span class="string">&quot;</span><span class="string">n0</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n1</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n2</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n3</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n4</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n5</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n6</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n7</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n8</span><span class="string">&quot;</span>, <span class="string">&quot;</span><span class="string">n9</span><span class="string">&quot;</span>}) 
  48.129 -        <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> addDigit(String digit) {
  48.130 -            digit = digit.substring(<span class="number">1</span>);
  48.131 -            String v = Calculator.DISPLAY.getValue();
  48.132 -            <span class="keyword-directive">if</span> (getValue() == <span class="number">0.0</span>) {
  48.133 -                Calculator.DISPLAY.setValue(digit);
  48.134 -            } <span class="keyword-directive">else</span> {
  48.135 -                Calculator.DISPLAY.setValue(v + digit);
  48.136 -            }
  48.137 -        }
  48.138 -
  48.139 -        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">void</span> setValue(<span class="keyword-directive">double</span> v) {
  48.140 -            StringBuilder sb = <span class="keyword-directive">new</span> StringBuilder();
  48.141 -            sb.append(v);
  48.142 -            Calculator.DISPLAY.setValue(sb.toString());
  48.143 -        }
  48.144 -
  48.145 -        <span class="keyword-directive">private</span> <span class="keyword-directive">static</span> <span class="keyword-directive">double</span> getValue() {
  48.146 -            <span class="keyword-directive">try</span> {
  48.147 -                <span class="keyword-directive">return</span> Double.parseDouble(Calculator.DISPLAY.getValue());
  48.148 -            } <span class="keyword-directive">catch</span> (NumberFormatException ex) {
  48.149 -                Calculator.DISPLAY.setValue(<span class="string">&quot;</span><span class="string">err</span><span class="string">&quot;</span>);
  48.150 -                <span class="keyword-directive">return</span> <span class="number">0.0</span>;
  48.151 -            }
  48.152 -        }
  48.153 -    }
  48.154 -
  48.155 -    </pre>
  48.156 -    </body>
  48.157 -</html>
    49.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Tue Jan 22 17:53:05 2013 +0100
    49.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Wed Jan 23 14:49:52 2013 +0100
    49.3 @@ -55,7 +55,7 @@
    49.4   */
    49.5  final class Bck2BrwsrLauncher extends Launcher implements Closeable {
    49.6      private static final Logger LOG = Logger.getLogger(Bck2BrwsrLauncher.class.getName());
    49.7 -    private static final MethodInvocation END = new MethodInvocation(null, null);
    49.8 +    private static final MethodInvocation END = new MethodInvocation(null, null, null);
    49.9      private Set<ClassLoader> loaders = new LinkedHashSet<>();
   49.10      private BlockingQueue<MethodInvocation> methods = new LinkedBlockingQueue<>();
   49.11      private long timeOut;
   49.12 @@ -70,9 +70,9 @@
   49.13      }
   49.14      
   49.15      @Override
   49.16 -    public MethodInvocation addMethod(Class<?> clazz, String method) throws IOException {
   49.17 +     MethodInvocation addMethod(Class<?> clazz, String method, String html) throws IOException {
   49.18          loaders.add(clazz.getClassLoader());
   49.19 -        MethodInvocation c = new MethodInvocation(clazz.getName(), method);
   49.20 +        MethodInvocation c = new MethodInvocation(clazz.getName(), method, html);
   49.21          methods.add(c);
   49.22          try {
   49.23              c.await(timeOut);
   49.24 @@ -174,7 +174,13 @@
   49.25                      + "className: '" + cn + "', "
   49.26                      + "methodName: '" + mn + "', "
   49.27                      + "request: " + cnt
   49.28 -                    + "}");
   49.29 +                );
   49.30 +                if (mi.html != null) {
   49.31 +                    response.getWriter().write(", html: '");
   49.32 +                    response.getWriter().write(encodeJSON(mi.html));
   49.33 +                    response.getWriter().write("'");
   49.34 +                }
   49.35 +                response.getWriter().write("}");
   49.36                  cnt++;
   49.37              }
   49.38          }, "/data");
   49.39 @@ -182,6 +188,22 @@
   49.40          this.brwsr = launchServerAndBrwsr(server, "/execute");
   49.41      }
   49.42      
   49.43 +    private static String encodeJSON(String in) {
   49.44 +        StringBuilder sb = new StringBuilder();
   49.45 +        for (int i = 0; i < in.length(); i++) {
   49.46 +            char ch = in.charAt(i);
   49.47 +            if (ch < 32 || ch == '\'' || ch == '"') {
   49.48 +                sb.append("\\u");
   49.49 +                String hs = "0000" + Integer.toHexString(ch);
   49.50 +                hs = hs.substring(hs.length() - 4);
   49.51 +                sb.append(hs);
   49.52 +            } else {
   49.53 +                sb.append(ch);
   49.54 +            }
   49.55 +        }
   49.56 +        return sb.toString();
   49.57 +    }
   49.58 +    
   49.59      @Override
   49.60      public void shutdown() throws IOException {
   49.61          methods.offer(END);
   49.62 @@ -239,6 +261,11 @@
   49.63          LOG.log(Level.INFO, "Showing {0}", uri);
   49.64          if (cmd == null) {
   49.65              try {
   49.66 +                LOG.log(Level.INFO, "Trying Desktop.browse on {0} {2} by {1}", new Object[] {
   49.67 +                    System.getProperty("java.vm.name"),
   49.68 +                    System.getProperty("java.vm.vendor"),
   49.69 +                    System.getProperty("java.vm.version"),
   49.70 +                });
   49.71                  java.awt.Desktop.getDesktop().browse(uri);
   49.72                  LOG.log(Level.INFO, "Desktop.browse successfully finished");
   49.73                  return null;
   49.74 @@ -348,7 +375,7 @@
   49.75          public Page(Res res, String resource, String... args) {
   49.76              this.res = res;
   49.77              this.resource = resource;
   49.78 -            this.args = args;
   49.79 +            this.args = args.length == 0 ? new String[] { "$0" } : args;
   49.80          }
   49.81  
   49.82          @Override
    50.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java	Tue Jan 22 17:53:05 2013 +0100
    50.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java	Wed Jan 23 14:49:52 2013 +0100
    50.3 @@ -34,12 +34,6 @@
    50.4      static {
    50.5          turnAssetionStatusOn();
    50.6      }
    50.7 -    public static String welcome() {
    50.8 -        return "HellofromBck2Brwsr";
    50.9 -    }
   50.10 -    public static String multiply() {
   50.11 -        return String.valueOf(Integer.MAX_VALUE / 2 + Integer.MAX_VALUE);
   50.12 -    }
   50.13      
   50.14      @JavaScriptBody(args = {"id", "attr"}, body = 
   50.15          "return window.document.getElementById(id)[attr].toString();")
   50.16 @@ -53,7 +47,7 @@
   50.17      private static native void closeWindow();
   50.18  
   50.19      private static void log(String newText) {
   50.20 -        String id = "result";
   50.21 +        String id = "bck2brwsr.result";
   50.22          String attr = "value";
   50.23          setAttr(id, attr, getAttr(id, attr) + "\n" + newText);
   50.24          setAttr(id, "scrollTop", getAttr(id, "scrollHeight"));
   50.25 @@ -63,7 +57,7 @@
   50.26          String clazz = (String) getAttr("clazz", "value");
   50.27          String method = (String) getAttr("method", "value");
   50.28          Object res = invokeMethod(clazz, method);
   50.29 -        setAttr("result", "value", res);
   50.30 +        setAttr("bck2brwsr.result", "value", res);
   50.31      }
   50.32  
   50.33      @JavaScriptBody(args = { "url", "callback", "arr" }, body = ""
   50.34 @@ -111,10 +105,14 @@
   50.35                  }
   50.36                  
   50.37                  Case c = Case.parseData(data);
   50.38 +                if (c.getHtmlFragment() != null) {
   50.39 +                    setAttr("bck2brwsr.fragment", "innerHTML", c.getHtmlFragment());
   50.40 +                }
   50.41                  log("Invoking " + c.getClassName() + '.' + c.getMethodName() + " as request: " + c.getRequestId());
   50.42  
   50.43                  Object result = invokeMethod(c.getClassName(), c.getMethodName());
   50.44                  
   50.45 +                setAttr("bck2brwsr.fragment", "innerHTML", "");
   50.46                  log("Result: " + result);
   50.47                  
   50.48                  result = encodeURL("" + result);
   50.49 @@ -202,7 +200,7 @@
   50.50                  } else {
   50.51                      res = found.invoke(c.newInstance());
   50.52                  }
   50.53 -            } catch (Exception | Error ex) {
   50.54 +            } catch (Throwable ex) {
   50.55                  res = ex.getClass().getName() + ":" + ex.getMessage();
   50.56              }
   50.57          } else {
   50.58 @@ -237,11 +235,19 @@
   50.59          public String getRequestId() {
   50.60              return value("request", data);
   50.61          }
   50.62 +
   50.63 +        public String getHtmlFragment() {
   50.64 +            return value("html", data);
   50.65 +        }
   50.66          
   50.67          @JavaScriptBody(args = "s", body = "return eval('(' + s + ')');")
   50.68          private static native Object toJSON(String s);
   50.69          
   50.70 -        @JavaScriptBody(args = {"p", "d"}, body = "return d[p].toString();")
   50.71 +        @JavaScriptBody(args = {"p", "d"}, body = 
   50.72 +              "var v = d[p];\n"
   50.73 +            + "if (typeof v === 'undefined') return null;\n"
   50.74 +            + "return v.toString();"
   50.75 +        )
   50.76          private static native String value(String p, Object d);
   50.77      }
   50.78  }
    51.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/JSLauncher.java	Tue Jan 22 17:53:05 2013 +0100
    51.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/JSLauncher.java	Wed Jan 23 14:49:52 2013 +0100
    51.3 @@ -42,10 +42,9 @@
    51.4      private Object console;
    51.5      
    51.6      
    51.7 -    @Override
    51.8 -    public MethodInvocation addMethod(Class<?> clazz, String method) {
    51.9 +    @Override MethodInvocation addMethod(Class<?> clazz, String method, String html) {
   51.10          loaders.add(clazz.getClassLoader());
   51.11 -        MethodInvocation mi = new MethodInvocation(clazz.getName(), method);
   51.12 +        MethodInvocation mi = new MethodInvocation(clazz.getName(), method, html);
   51.13          try {
   51.14              mi.result(code.invokeMethod(
   51.15                  console,
    52.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java	Tue Jan 22 17:53:05 2013 +0100
    52.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java	Wed Jan 23 14:49:52 2013 +0100
    52.3 @@ -32,12 +32,12 @@
    52.4      Launcher() {
    52.5      }
    52.6      
    52.7 -    abstract MethodInvocation addMethod(Class<?> clazz, String method) throws IOException; 
    52.8 +    abstract MethodInvocation addMethod(Class<?> clazz, String method, String html) throws IOException; 
    52.9  
   52.10      public abstract void initialize() throws IOException;
   52.11      public abstract void shutdown() throws IOException;
   52.12 -    public MethodInvocation invokeMethod(Class<?> clazz, String method) throws IOException {
   52.13 -        return addMethod(clazz, method);
   52.14 +    public MethodInvocation invokeMethod(Class<?> clazz, String method, String html) throws IOException {
   52.15 +        return addMethod(clazz, method, html);
   52.16      }
   52.17      
   52.18      
    53.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/MethodInvocation.java	Tue Jan 22 17:53:05 2013 +0100
    53.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/MethodInvocation.java	Wed Jan 23 14:49:52 2013 +0100
    53.3 @@ -28,12 +28,14 @@
    53.4      final CountDownLatch wait = new CountDownLatch(1);
    53.5      final String className;
    53.6      final String methodName;
    53.7 +    final String html;
    53.8      private String result;
    53.9      private Throwable exception;
   53.10  
   53.11 -    MethodInvocation(String className, String methodName) {
   53.12 +    MethodInvocation(String className, String methodName, String html) {
   53.13          this.className = className;
   53.14          this.methodName = methodName;
   53.15 +        this.html = html;
   53.16      }
   53.17      
   53.18      void await(long timeOut) throws InterruptedException {
    54.1 --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/console.xhtml	Tue Jan 22 17:53:05 2013 +0100
    54.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.3 @@ -1,52 +0,0 @@
    54.4 -<?xml version="1.0" encoding="UTF-8"?>
    54.5 -<!--
    54.6 -
    54.7 -    Back 2 Browser Bytecode Translator
    54.8 -    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    54.9 -
   54.10 -    This program is free software: you can redistribute it and/or modify
   54.11 -    it under the terms of the GNU General Public License as published by
   54.12 -    the Free Software Foundation, version 2 of the License.
   54.13 -
   54.14 -    This program is distributed in the hope that it will be useful,
   54.15 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   54.16 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   54.17 -    GNU General Public License for more details.
   54.18 -
   54.19 -    You should have received a copy of the GNU General Public License
   54.20 -    along with this program. Look for COPYING file in the top folder.
   54.21 -    If not, see http://opensource.org/licenses/GPL-2.0.
   54.22 -
   54.23 --->
   54.24 -<!DOCTYPE html>
   54.25 -<html xmlns="http://www.w3.org/1999/xhtml">
   54.26 -    <head>
   54.27 -        <title>Bck2Brwsr Launcher</title>
   54.28 -    </head>
   54.29 -    <body>
   54.30 -        <script src="/bck2brwsr.js"></script>
   54.31 -        <script src="/vm.js"></script>
   54.32 -        
   54.33 -        <h1>Bck2Browser Console Launcher</h1>
   54.34 -        
   54.35 -        Class Name:
   54.36 -        <input id="clazz" value="$0"/>
   54.37 -        <br/>
   54.38 -        Method Name:
   54.39 -
   54.40 -        <input id="method" value="$1"/>
   54.41 -        <br/>
   54.42 -        
   54.43 -        <button onclick="vm.loadClass('org.apidesign.bck2brwsr.launcher.Console').execute__V();">Execute!</button>
   54.44 -        
   54.45 -        <hr/>
   54.46 -        <textarea id="result" rows="10" cols="80" disabled="">
   54.47 -        </textarea>
   54.48 -        
   54.49 -        <script type="text/javascript">
   54.50 -            if ($2) {
   54.51 -                vm.loadClass('org.apidesign.bck2brwsr.launcher.Console').execute__V();
   54.52 -            }
   54.53 -        </script>
   54.54 -    </body>
   54.55 -</html>
    55.1 --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/harness.xhtml	Tue Jan 22 17:53:05 2013 +0100
    55.2 +++ b/launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/harness.xhtml	Wed Jan 23 14:49:52 2013 +0100
    55.3 @@ -27,10 +27,12 @@
    55.4          <script src="/bck2brwsr.js"></script>
    55.5          <script src="/vm.js"></script>
    55.6          
    55.7 -        <h1>Bck2Browser Execution Harness</h1>
    55.8 +        <h1>Bck2Brwsr Execution Harness</h1>
    55.9          
   55.10 -        <textarea id="result" rows="25" style="width: 100%;" disabled="">
   55.11 +        <textarea id="bck2brwsr.result" rows="25" style="width: 100%;" disabled="">
   55.12          </textarea>
   55.13 +
   55.14 +        <div id="bck2brwsr.fragment"/>
   55.15          
   55.16          <script type="text/javascript">
   55.17              vm.loadClass('org.apidesign.bck2brwsr.launcher.Console').harness__VLjava_lang_String_2('$U/../data');
    56.1 --- a/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java	Tue Jan 22 17:53:05 2013 +0100
    56.2 +++ b/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java	Wed Jan 23 14:49:52 2013 +0100
    56.3 @@ -82,7 +82,10 @@
    56.4          List<URL> arr = new ArrayList<URL>();
    56.5          arr.add(root.toURI().toURL());
    56.6          for (Artifact a : deps) {
    56.7 -            arr.add(a.getFile().toURI().toURL());
    56.8 +            final File f = a.getFile();
    56.9 +            if (f != null) {
   56.10 +                arr.add(f.toURI().toURL());
   56.11 +            }
   56.12          }
   56.13          return new URLClassLoader(arr.toArray(new URL[0]), BrswrMojo.class.getClassLoader());
   56.14      }
    57.1 --- a/mojo/src/main/resources/META-INF/maven/archetype-metadata.xml	Tue Jan 22 17:53:05 2013 +0100
    57.2 +++ b/mojo/src/main/resources/META-INF/maven/archetype-metadata.xml	Wed Jan 23 14:49:52 2013 +0100
    57.3 @@ -23,7 +23,7 @@
    57.4      <fileSet filtered="true" packaged="true">
    57.5        <directory>src/main/java</directory>
    57.6        <includes>
    57.7 -        <include>**/*.java</include>
    57.8 +        <include>**/App.java</include>
    57.9        </includes>
   57.10      </fileSet>
   57.11      <fileSet filtered="true" packaged="true">
   57.12 @@ -32,6 +32,12 @@
   57.13          <include>**/*.xhtml</include>
   57.14        </includes>
   57.15      </fileSet>
   57.16 +    <fileSet filtered="true" packaged="true">
   57.17 +      <directory>src/test/java</directory>
   57.18 +      <includes>
   57.19 +        <include>**/*Test.java</include>
   57.20 +      </includes>
   57.21 +    </fileSet>
   57.22      <fileSet filtered="false" packaged="false">
   57.23        <directory></directory>
   57.24        <includes>
    58.1 --- a/mojo/src/main/resources/archetype-resources/pom.xml	Tue Jan 22 17:53:05 2013 +0100
    58.2 +++ b/mojo/src/main/resources/archetype-resources/pom.xml	Wed Jan 23 14:49:52 2013 +0100
    58.3 @@ -53,5 +53,17 @@
    58.4        <artifactId>javaquery.api</artifactId>
    58.5        <version>0.3-SNAPSHOT</version>
    58.6      </dependency>
    58.7 +    <dependency>
    58.8 +      <groupId>org.testng</groupId>
    58.9 +      <artifactId>testng</artifactId>
   58.10 +      <version>6.5.2</version>
   58.11 +      <scope>test</scope>
   58.12 +    </dependency>
   58.13 +    <dependency>
   58.14 +      <groupId>${project.groupId}</groupId>
   58.15 +      <artifactId>vmtest</artifactId>
   58.16 +      <version>0.3-SNAPSHOT</version>
   58.17 +      <scope>test</scope>
   58.18 +    </dependency>
   58.19    </dependencies>
   58.20  </project>
    59.1 --- a/mojo/src/main/resources/archetype-resources/src/main/java/App.java	Tue Jan 22 17:53:05 2013 +0100
    59.2 +++ b/mojo/src/main/resources/archetype-resources/src/main/java/App.java	Wed Jan 23 14:49:52 2013 +0100
    59.3 @@ -3,15 +3,32 @@
    59.4  import org.apidesign.bck2brwsr.htmlpage.api.*;
    59.5  import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
    59.6  import org.apidesign.bck2brwsr.htmlpage.api.Page;
    59.7 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
    59.8 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
    59.9  
   59.10  /** Edit the index.xhtml file. Use 'id' to name certain HTML elements.
   59.11   * Use this class to define behavior of the elements.
   59.12   */
   59.13 -@Page(xhtml="index.xhtml", className="Index")
   59.14 +@Page(xhtml="index.xhtml", className="Index", properties={
   59.15 +    @Property(name="name", type=String.class)
   59.16 +})
   59.17  public class App {
   59.18 +    static {
   59.19 +        Index model = new Index();
   59.20 +        model.setName("World");
   59.21 +        model.applyBindings();
   59.22 +    }
   59.23 +    
   59.24      @On(event = CLICK, id="hello")
   59.25 -    static void hello() {
   59.26 -        Index.HELLO.setDisabled(true);
   59.27 -        Element.alert("Hello World!");
   59.28 +    static void hello(Index m) {
   59.29 +        GraphicsContext g = m.CANVAS.getContext();
   59.30 +        g.clearRect(0, 0, 1000, 1000);
   59.31 +        g.setFont("italic 40px Calibri");
   59.32 +        g.fillText(m.getHelloMessage(), 10, 40);
   59.33 +    }
   59.34 +    
   59.35 +    @ComputedProperty
   59.36 +    static String helloMessage(String name) {
   59.37 +        return "Hello " + name + "!";
   59.38      }
   59.39  }
    60.1 --- a/mojo/src/main/resources/archetype-resources/src/main/resources/index.xhtml	Tue Jan 22 17:53:05 2013 +0100
    60.2 +++ b/mojo/src/main/resources/archetype-resources/src/main/resources/index.xhtml	Wed Jan 23 14:49:52 2013 +0100
    60.3 @@ -5,12 +5,18 @@
    60.4          <title>Bck2Brwsr's Hello World</title>
    60.5      </head>
    60.6      <body>
    60.7 -        <button id="hello">Hello World!</button>
    60.8 +        <h1 data-bind="text: helloMessage">Loading Bck2Brwsr's Hello World...</h1>
    60.9 +        Your name: <input id='input' data-bind="value: name, valueUpdate: 'afterkeydown'"></input>
   60.10 +        <button id="hello">Say Hello!</button>
   60.11 +        <p>
   60.12 +            <canvas id="canvas" width="300" height="50">
   60.13 +            </canvas>
   60.14 +        </p>
   60.15  
   60.16          <script src="/bck2brwsr.js"></script>
   60.17          <script src="/vm.js"></script>
   60.18          <script type="text/javascript">
   60.19 -            vm.loadClass('${package}.Index');
   60.20 +            vm.loadClass('${package}.App');
   60.21          </script>
   60.22      </body>
   60.23  </html>
    61.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.2 +++ b/mojo/src/main/resources/archetype-resources/src/test/java/AppTest.java	Wed Jan 23 14:49:52 2013 +0100
    61.3 @@ -0,0 +1,26 @@
    61.4 +package ${package};
    61.5 +
    61.6 +import static org.testng.Assert.*;
    61.7 +import org.testng.annotations.BeforeMethod;
    61.8 +import org.testng.annotations.Test;
    61.9 +
   61.10 +/** Demonstrating POJO testing of HTML page model. Runs in good old HotSpot
   61.11 + * as it does not reference any HTML elements or browser functionality. Just
   61.12 + * operates on the page model.
   61.13 + *
   61.14 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   61.15 + */
   61.16 +public class AppTest {
   61.17 +    private Index model;
   61.18 +    
   61.19 +
   61.20 +    @BeforeMethod
   61.21 +    public void initModel() {
   61.22 +        model = new Index().applyBindings();
   61.23 +    }
   61.24 +
   61.25 +    @Test public void testHelloMessage() {
   61.26 +        model.setName("Joe");
   61.27 +        assertEquals(model.getHelloMessage(), "Hello Joe!", "Cleared after pressing +");
   61.28 +    }
   61.29 +}
    62.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.2 +++ b/mojo/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java	Wed Jan 23 14:49:52 2013 +0100
    62.3 @@ -0,0 +1,40 @@
    62.4 +package ${package};
    62.5 +
    62.6 +import org.apidesign.bck2brwsr.vmtest.Compare;
    62.7 +import org.apidesign.bck2brwsr.vmtest.VMTest;
    62.8 +import org.testng.annotations.Factory;
    62.9 +
   62.10 +/** Bck2brwsr cares about compatibility with real Java. Whatever API is
   62.11 + * supported by bck2brwsr, it needs to behave the same way as when running
   62.12 + * in HotSpot VM. 
   62.13 + * <p>
   62.14 + * There can be bugs, however. To help us fix them, we kindly ask you to 
   62.15 + * write an "inconsistency" test. A test that compares behavior of the API
   62.16 + * between real VM and bck2brwsr VM. This class is skeleton of such test.
   62.17 + *
   62.18 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   62.19 + */
   62.20 +public class InconsistencyTest {
   62.21 +    /** A method to demonstrate inconsistency between bck2brwsr and HotSpot.
   62.22 +     * Make calls to an API that behaves strangely, return some result at
   62.23 +     * the end. No need to use any <code>assert</code>.
   62.24 +     * 
   62.25 +     * @return value to compare between HotSpot and bck2brwsr
   62.26 +     */
   62.27 +    @Compare
   62.28 +    public int checkStringHashCode() throws Exception {
   62.29 +        return "Is string hashCode the same?".hashCode();
   62.30 +    }
   62.31 +
   62.32 +    /** Factory method that creates a three tests for each method annotated with
   62.33 +     * {@link org.apidesign.bck2brwsr.vmtest.Compare}. One executes the code in
   62.34 +     * HotSpot, one in Rhino and the last one compares the results.
   62.35 +     * 
   62.36 +     * @see org.apidesign.bck2brwsr.vmtest.VMTest
   62.37 +     */
   62.38 +    @Factory
   62.39 +    public static Object[] create() {
   62.40 +        return VMTest.create(InconsistencyTest.class);
   62.41 +    }
   62.42 +    
   62.43 +}
    63.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.2 +++ b/mojo/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java	Wed Jan 23 14:49:52 2013 +0100
    63.3 @@ -0,0 +1,46 @@
    63.4 +package ${package};
    63.5 +
    63.6 +import org.apidesign.bck2brwsr.htmlpage.api.OnEvent;
    63.7 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
    63.8 +import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
    63.9 +import org.apidesign.bck2brwsr.vmtest.VMTest;
   63.10 +import org.testng.annotations.Factory;
   63.11 +
   63.12 +/** Sometimes it is useful to run tests inside of the real browser. 
   63.13 + * To do that just annotate your method with {@link org.apidesign.bck2brwsr.vmtest.BrwsrTest}
   63.14 + * and that is it. If your code references elements on the HTML page,
   63.15 + * you can pass in an {@link org.apidesign.bck2brwsr.vmtest.HtmlFragment} which
   63.16 + * will be made available on the page before your test starts.
   63.17 + *
   63.18 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   63.19 + */
   63.20 +public class IntegrationTest {
   63.21 +    
   63.22 +    /** Write to testing code here. Use <code>assert</code> (but not TestNG's
   63.23 +     * Assert, as TestNG is not compiled with target 1.6 yet).
   63.24 +     */
   63.25 +    @HtmlFragment(
   63.26 +        "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
   63.27 +        "Your name: <input id='input' data-bind=\"value: name, valueUpdate: 'afterkeydown'\"></input>\n" +
   63.28 +        "<button id=\"hello\">Say Hello!</button>\n" +
   63.29 +        "<p>\n" +
   63.30 +        "    <canvas id=\"canvas\" width=\"300\" height=\"50\"></canvas>\n" +
   63.31 +        "</p>\n"
   63.32 +    )
   63.33 +    @BrwsrTest
   63.34 +    public void modifyValueAssertChangeInModel() {
   63.35 +        Index m = new Index();
   63.36 +        m.setName("Joe Hacker");
   63.37 +        m.applyBindings();
   63.38 +        assert "Joe Hacker".equals(m.INPUT.getValue()) : "Value is really Joe Hacker: " + m.INPUT.getValue();
   63.39 +        m.INPUT.setValue("Happy Joe");
   63.40 +        m.triggerEvent(m.INPUT, OnEvent.CHANGE);
   63.41 +        assert "Happy Joe".equals(m.getName()) : "Name property updated to Happy Joe: " + m.getName();
   63.42 +    }
   63.43 +
   63.44 +    @Factory
   63.45 +    public static Object[] create() {
   63.46 +        return VMTest.create(IntegrationTest.class);
   63.47 +    }
   63.48 +    
   63.49 +}
    64.1 --- a/pom.xml	Tue Jan 22 17:53:05 2013 +0100
    64.2 +++ b/pom.xml	Wed Jan 23 14:49:52 2013 +0100
    64.3 @@ -10,6 +10,7 @@
    64.4      <module>vm</module>
    64.5      <module>emul</module>
    64.6      <module>core</module>
    64.7 +    <module>dew</module>
    64.8      <module>mojo</module>
    64.9      <module>javaquery</module>
   64.10      <module>javap</module>
   64.11 @@ -74,7 +75,9 @@
   64.12                         <exclude>*</exclude>
   64.13                         <exclude>.*/**</exclude>
   64.14                         <exclude>mojo/src/main/resources/archetype-resources/**</exclude>
   64.15 +                       <exclude>dew/src/main/resources/org/apidesign/bck2brwsr/dew/**</exclude>
   64.16                         <exclude>vmtest/src/test/resources/**</exclude>
   64.17 +                       <exclude>javaquery/api/src/main/resources/org/apidesign/bck2brwsr/htmlpage/knockout*.js</exclude>
   64.18                    </excludes>
   64.19                </configuration>
   64.20            </plugin>
   64.21 @@ -112,4 +115,4 @@
   64.22    <properties>
   64.23        <license>COPYING</license>
   64.24    </properties>
   64.25 -</project>
   64.26 \ No newline at end of file
   64.27 +</project>
    65.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Tue Jan 22 17:53:05 2013 +0100
    65.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Wed Jan 23 14:49:52 2013 +0100
    65.3 @@ -212,7 +212,7 @@
    65.4          out.append("\n    return this;");
    65.5          out.append("\n  }");
    65.6          out.append("\n  return arguments[0] ? new CLS() : CLS.prototype;");
    65.7 -        out.append("\n}");
    65.8 +        out.append("\n};");
    65.9          StringBuilder sb = new StringBuilder();
   65.10          for (String init : toInitilize.toArray()) {
   65.11              sb.append("\n").append(init).append("();");
    66.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java	Tue Jan 22 17:53:05 2013 +0100
    66.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java	Wed Jan 23 14:49:52 2013 +0100
    66.3 @@ -45,7 +45,9 @@
    66.4          sb.append("\n  return c[method]();");
    66.5          sb.append("\n}");
    66.6          
    66.7 -        
    66.8 +        sb.append("\nfunction checkKO() {");
    66.9 +        sb.append("\n  return ko !== null;");
   66.10 +        sb.append("\n}");
   66.11         
   66.12          ScriptEngine[] arr = { null };
   66.13          code = StaticMethodTest.compileClass(sb, arr,
   66.14 @@ -71,6 +73,9 @@
   66.15          assertExec("ko is defined", "test", true,
   66.16              Script.class.getName(), "checkNotNull__Z"
   66.17          );
   66.18 +        
   66.19 +        Object res = code.invokeFunction("checkKO");
   66.20 +        assertEquals(res, true, "KO is defined on a global level");
   66.21      }
   66.22  
   66.23      private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
    67.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Compare.java	Tue Jan 22 17:53:05 2013 +0100
    67.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Compare.java	Wed Jan 23 14:49:52 2013 +0100
    67.3 @@ -24,7 +24,7 @@
    67.4  
    67.5  /** Can be applied on a method that yields a return value. 
    67.6   * Together with {@link VMTest#create} it can be used to write
    67.7 - * methods which are executed in real as well as JavaScript VMs and
    67.8 + * methods which are executed in real VM as well as JavaScript VMs and
    67.9   * their results are compared.
   67.10   *
   67.11   * @author Jaroslav Tulach <jtulach@netbeans.org>
   67.12 @@ -32,4 +32,14 @@
   67.13  @Retention(RetentionPolicy.RUNTIME)
   67.14  @Target(ElementType.METHOD)
   67.15  public @interface Compare {
   67.16 +    /** Specifies whether the system should internal JavaScript interpreter
   67.17 +     * as available via {@link javax.script.ScriptEngine}. Defaults to true,
   67.18 +     * but in some situations (benchmarking comes to my mind), one may set this
   67.19 +     * to <code>false</code>. In such case only browsers provided via
   67.20 +     * <code>vmtest.brwsrs</code> property are used. For example
   67.21 +     * <code>"vmtest.brwsrs=firefox,google-chrome"</code> would run the test
   67.22 +     * in HotSpot VM, firefox and chrome and would compare the results.
   67.23 +     * @return 
   67.24 +     */
   67.25 +    boolean scripting() default true;
   67.26  }
    68.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    68.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/HtmlFragment.java	Wed Jan 23 14:49:52 2013 +0100
    68.3 @@ -0,0 +1,38 @@
    68.4 +/**
    68.5 + * Back 2 Browser Bytecode Translator
    68.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    68.7 + *
    68.8 + * This program is free software: you can redistribute it and/or modify
    68.9 + * it under the terms of the GNU General Public License as published by
   68.10 + * the Free Software Foundation, version 2 of the License.
   68.11 + *
   68.12 + * This program is distributed in the hope that it will be useful,
   68.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   68.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   68.15 + * GNU General Public License for more details.
   68.16 + *
   68.17 + * You should have received a copy of the GNU General Public License
   68.18 + * along with this program. Look for COPYING file in the top folder.
   68.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   68.20 + */
   68.21 +package org.apidesign.bck2brwsr.vmtest;
   68.22 +
   68.23 +import java.lang.annotation.ElementType;
   68.24 +import java.lang.annotation.Retention;
   68.25 +import java.lang.annotation.RetentionPolicy;
   68.26 +import java.lang.annotation.Target;
   68.27 +
   68.28 +/** Allows to specify an HTML fragment for a given {@link BrwsrTest}. 
   68.29 + * Apply either to the method or to enclosing class. The fragment will be
   68.30 + * made available in the page that executes given test. Its elements shall
   68.31 + * be regularly accessible from the test.
   68.32 + *
   68.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   68.34 + */
   68.35 +@Retention(RetentionPolicy.RUNTIME)
   68.36 +@Target({ ElementType.METHOD, ElementType.TYPE})
   68.37 +public @interface HtmlFragment {
   68.38 +    /** HTML code fragment to be exposed on the testing page.
   68.39 +     */
   68.40 +    String value();
   68.41 +}
    69.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java	Tue Jan 22 17:53:05 2013 +0100
    69.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java	Wed Jan 23 14:49:52 2013 +0100
    69.3 @@ -40,20 +40,20 @@
    69.4      private final String type;
    69.5      private final boolean fail;
    69.6      Object value;
    69.7 -    private static final Map<Class, Object[]> compiled = new WeakHashMap<>();
    69.8 -    private Object inst;
    69.9 +    private final String html;
   69.10  
   69.11 -    Bck2BrwsrCase(Method m, String type, Launcher l, boolean fail) {
   69.12 +    Bck2BrwsrCase(Method m, String type, Launcher l, boolean fail, String html) {
   69.13          this.l = l;
   69.14          this.m = m;
   69.15          this.type = type;
   69.16          this.fail = fail;
   69.17 +        this.html = html;
   69.18      }
   69.19  
   69.20      @Test(groups = "run")
   69.21      public void executeCode() throws Throwable {
   69.22          if (l != null) {
   69.23 -            MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName());
   69.24 +            MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName(), html);
   69.25              String res = c.toString();
   69.26              value = res;
   69.27              if (fail) {
    70.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java	Tue Jan 22 17:53:05 2013 +0100
    70.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java	Wed Jan 23 14:49:52 2013 +0100
    70.3 @@ -18,9 +18,6 @@
    70.4  package org.apidesign.bck2brwsr.vmtest.impl;
    70.5  
    70.6  import org.apidesign.bck2brwsr.vmtest.*;
    70.7 -import java.io.File;
    70.8 -import java.io.FileWriter;
    70.9 -import java.io.IOException;
   70.10  import java.lang.reflect.Method;
   70.11  import java.util.ArrayList;
   70.12  import java.util.List;
   70.13 @@ -114,15 +111,17 @@
   70.14          if (c == null) {
   70.15              return;
   70.16          }
   70.17 -        final Bck2BrwsrCase real = new Bck2BrwsrCase(m, "Java", null, false);
   70.18 -        final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l.javaScript(), false);
   70.19 +        final Bck2BrwsrCase real = new Bck2BrwsrCase(m, "Java", null, false, null);
   70.20          ret.add(real);
   70.21 -        ret.add(js);
   70.22 -        ret.add(new CompareCase(m, real, js));
   70.23 +        if (c.scripting()) {
   70.24 +            final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l.javaScript(), false, null);
   70.25 +            ret.add(js);
   70.26 +            ret.add(new CompareCase(m, real, js));
   70.27 +        }
   70.28          for (String b : brwsr) {
   70.29              final Launcher s = l.brwsr(b);
   70.30              ret.add(s);
   70.31 -            final Bck2BrwsrCase cse = new Bck2BrwsrCase(m, b, s, false);
   70.32 +            final Bck2BrwsrCase cse = new Bck2BrwsrCase(m, b, s, false, null);
   70.33              ret.add(cse);
   70.34              ret.add(new CompareCase(m, real, cse));
   70.35          }
   70.36 @@ -132,15 +131,20 @@
   70.37          if (c == null) {
   70.38              return;
   70.39          }
   70.40 +        HtmlFragment f = m.getAnnotation(HtmlFragment.class);
   70.41 +        if (f == null) {
   70.42 +            f = m.getDeclaringClass().getAnnotation(HtmlFragment.class);
   70.43 +        }
   70.44 +        String html = f == null ? null : f.value();
   70.45          if (brwsr.length == 0) {
   70.46              final Launcher s = l.brwsr(null);
   70.47              ret.add(s);
   70.48 -            ret.add(new Bck2BrwsrCase(m, "Brwsr", s, true));
   70.49 +            ret.add(new Bck2BrwsrCase(m, "Brwsr", s, true, html));
   70.50          } else {
   70.51              for (String b : brwsr) {
   70.52                  final Launcher s = l.brwsr(b);
   70.53                  ret.add(s);
   70.54 -                ret.add(new Bck2BrwsrCase(m, b, s, true));
   70.55 +                ret.add(new Bck2BrwsrCase(m, b, s, true, html));
   70.56              }
   70.57          }
   70.58      }
    71.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/BrwsrCheckTest.java	Tue Jan 22 17:53:05 2013 +0100
    71.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/BrwsrCheckTest.java	Wed Jan 23 14:49:52 2013 +0100
    71.3 @@ -19,6 +19,7 @@
    71.4  
    71.5  import org.apidesign.bck2brwsr.core.JavaScriptBody;
    71.6  import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
    71.7 +import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
    71.8  import org.apidesign.bck2brwsr.vmtest.VMTest;
    71.9  import org.testng.annotations.Factory;
   71.10  
   71.11 @@ -27,17 +28,30 @@
   71.12   * @author Jaroslav Tulach <jtulach@netbeans.org>
   71.13   */
   71.14  public class BrwsrCheckTest {
   71.15 -    
   71.16 +
   71.17      @BrwsrTest public void assertWindowObjectIsDefined() {
   71.18          assert window() != null : "No window object found!";
   71.19      }
   71.20 +
   71.21 +    
   71.22 +    
   71.23 +    
   71.24 +    @HtmlFragment("<h1 id='hello'>\n"
   71.25 +        + "Hello!\n"
   71.26 +        + "</h1>\n")
   71.27 +    @BrwsrTest public void accessProvidedFragment() {
   71.28 +        assert getElementById("hello") != null : "Element with 'hello' ID found";
   71.29 +    }
   71.30      
   71.31      @Factory
   71.32      public static Object[] create() {
   71.33          return VMTest.create(BrwsrCheckTest.class);
   71.34      }
   71.35 +    
   71.36  
   71.37      @JavaScriptBody(args = {}, body = "return window;")
   71.38      private static native Object window();
   71.39 -    
   71.40 +
   71.41 +    @JavaScriptBody(args = { "id" }, body = "return window.document.getElementById(id);")
   71.42 +    private static native Object getElementById(String id);
   71.43  }