├── README.md ├── Trice Example ├── Trice Example.html ├── grammar.json └── tracery │ ├── LICENSE.MD │ ├── iterator.js │ ├── mods-eng-basic.js │ ├── tracery-vis.js │ ├── tracery.js │ └── vendor │ ├── jquery.min.js │ └── seedrandom.js ├── Trice.html └── Trice.js /README.md: -------------------------------------------------------------------------------- 1 | # Trice 2 | A wrapper for [Tracery] (by @[galaxykate]) for [Twine] _(2.x [Sugar Cube] format)_. 3 | This project was heavily inspired by [Twincery] (a Twine 1.x wrapper for Tracery) by @[mrfb]. 4 | If you have any problems or questions about Trice, let me know here or at @[incobalt]. 5 | 6 | There is an excelent [Tracery tutorial] that you can use to learn more about using Tracery. You can also check out the [Twine 2 Guide] for information about getting started with Twine. 7 | 8 | The purpose of Trice is the same as Twinecery: 9 | 10 | 1. Make it easy to author and use Tracery grammars using the Twine 2 interface 11 | 2. Use Tracery to generate text within Twine 2 passages 12 | 13 | ## Table of Contents 14 | 15 | - [Setting up Trice](#setting-up-trice) 16 | - [Authoring Grammars](#authoring-grammars) 17 | - [A Brief Explanation of Tracery Grammars](#a-brief-explanation-of-tracery-grammars) 18 | - [Building a Grammar with Twine Passages](#building-a-grammar-with-twine-passages) 19 | - [Outputting Grammars](#outputting-grammars) 20 | - [Compiling the Grammar](#compiling-the-grammar) 21 | - [Generating Text in Passages](#generating-text-in-passages) 22 | - [The <\> Macro](#the-trace-macro) 23 | - [The trace() Function](#the-trace-function) 24 | - [Trice Links](#trice-links) 25 | - [Trice Example](#trice-example) 26 | 27 | ## Setting up Trice 28 | There are two ways to set up Trice. If you're starting a new Twine, you can simply import the provided Trice.html from the Twine 2 main menu. The other way to set up Trice is to open the Trice.js file and copy its contents. Then open a story or create a new one. With the story open, click on the arrow menu in the lower left and select Edit Story JavaScript from the menu that appears. Go to the end of the file and paste the text you copied earlier. 29 | In order to test files published with Trice, you will need to place the files for Tracery in a subfolder named "tracery". This folder needs to be in the same location as the published file. As of this version, Trice needs to find the following files: tracery.js, mods-end-basic.js, and vendor/seedrandom.js. You can adjust what files get loaded in the section of the script prefaced by "Load your external scripts here." 30 | **Note:** Due to the nature of the Twine 2 browser, you won't be able to play or test your story from inside the Twine interface. You will always need to publish to a file. 31 | 32 | ## Authoring Grammars 33 | ### A Brief Explanation of Tracery Grammars 34 | A Tracery grammar is a JSON object that has string keys (**symbols**) and an array of potential results (**rules**). For example: 35 | ``` 36 | { 37 | "origin": ["The #animal# #action.ed# with #style#."], 38 | "animal": ["cat", "dog", "bird", "octopus", "camel"], 39 | "action": ["walk", "shuffle", "waffle", "climb"], 40 | "style": ["fervor", "denial", "flair", "cheer", "melancholy", "pizazz"] 41 | } 42 | ``` 43 | which would provide results like: 44 | ``` 45 | The camel walked with fervor. 46 | The dog walked with denial. 47 | The bird climbed with flair. 48 | The cat walked with cheer. 49 | The octopus shuffled with pizazz. 50 | ``` 51 | An important part about grammars is that the rules can just be plain text (like the rules in the animal symbol) or they can tell Tracery to generate text. #animal# in the origin symbol's only rule asks Tracery to choose a rule from the animal symbol. Tracery can also put modifiers on these (#action.ed# to properly add past tense 'ed' to the result of #action#). Tracery has a lot more to offer, so take a look at the [Tracery tutorial] to find out more. 52 | ### Building a Grammar with Twine Passages 53 | One of the features of Trice is to allow you to build a Tracery grammar entirely using Twine passages. This grammar can then be used within the story to generate text, or exported to be used in another implementation of Tracery. 54 | Each Twine passage with the **"grammar" tag** represents a symbol and a list of rules. The title of the passage becomes the symbol (e.g., animal). The text of the passage becomes a list of rules, with each new rule on a new line. For example the animal passage would look like this: 55 | ``` 56 | cat 57 | dog 58 | bird 59 | octopus 60 | camel 61 | ``` 62 | Tracery rules can link to other rules (e.g., "The #animal# "). In Trice, you use regular Twine link syntax to do this. So the origin passage would look like this: 63 | ``` 64 | The [[animal]] [[action<-ed]] with [[style]]. 65 | ``` 66 | This will cause Twine to show a link arrow from the origin passage to the animal, action, and style passages. If you have a lot of interconnected rules, it might get messy, so you can still use the regular Tracery style instead, like so: 67 | ``` 68 | The #animal# #action.ed# with #style#. 69 | ``` 70 | Notice that in the Trice style, you use an arrow (<-) to start a list of modifiers. This makes passage linking work nicely in Twine. Only the first arrow is used, the rest use periods to separate them, so you would write "[[action<-ed.a.capitalize]]" if you wanted to add all three modifiers. 71 | ##### Comments and Blank Lines in Grammar Passages 72 | Trice ignores Sugar Cube supported comments and blank lines in grammar passages. That means you can space out your rules as you like, and add helpful comments for yourself or anyone reading your Twine source! The supported styles are `/* */`, `/% %/` and ``. 73 | Trice won't catch these if they are padded like `/***`, but you can put them on their own line. Additionally, inline // style comments are also ignored. Inline comments can also be on their own line. If you don't want comments to be ignored by Trice, you can add the `noComments` tag to the grammar passage. Note that Trice will still take the comments line by line in this situation. 74 | See the gHabitatFeature passage in TriceExample.html for an example of how you can use comments. 75 | ### Outputting Grammars 76 | Sometimes you just want to use Twine's interface to build a grammar, but don't actually want to use Tracery to generate text in a Twine story. If this is the case, then you can use the <\> macro in any passage **except the starting passage** to output a string of JSON that you can then copy into another implementation of Tracery. 77 | ### Compiling the Grammar 78 | By default, Trice will grab any passage tagged "grammar" and compile these into a grammar, but there are other ways of compiling a grammar for Trice. You can instead paste a JSON string into a single passage and tell Trice to parse that string into a grammar, or you can load a grammar from a JSON file. To change how Trice loads grammars, go to the section of the script titled "Load your external scripts here." and find the place where it says "load your grammar here!" 79 | Normally, it will say "generateGrammar();" which tells Trice to search for passages tagged "grammar" and make a Tracery grammar from them. You can change this to "grammarFromPassage("PassageTitle")" to have Trice take the text of the passage with the title PassageTitle, and convert it to a grammar. "grammarFromFile("Path")" will read JSON from the file at Path and convert it to a grammar. If you use either of these methods, you don't need to tag any passages with "grammar" _unless_ you want to make use of Trice links (see the section on Trice links below). 80 | ## Generating Text in Passages 81 | The main feature of Tracery is generating text based on rules supplied by a grammar. Trice makes this easy to do in Twine using a few macros and functions. 82 | **Note: Since Trice loads Tracery after the page has started loading, you cannot generate any text in the starting passage. If you want to use generative text in the first passage the player sees, use a <\> macro in the starting passage to immediately forward the player to a new passage.** 83 | ### The <\> Macro 84 | Whenever you want to generate some text and display it, use the <\> macro. <\> takes a string argument that tells Tracery to expand that argument into generated text. For example, <\> will ask Tracery to generate a result from the animal symbol in the grammar. You can even build a full rule like <\> To get a result like "The cat shuffles." Note that if you want to do this, you need to use full Tracery syntax. If you're just expanding a single symbol, then you don't need the hash marks, just "animal" will do. You can also give <\> no argument. When you do this, it will expand the "origin" symbol, which is only useful if your grammar has one. 85 | Whenever you use <\>, it stores the output in the $TrResult variable. This can be helpful for repeating it throughout a passage, but it's overwritten every time you use the macro. If you need to store the result longer, use the trace() function. 86 | ### The trace() Function 87 | The trace() function is almost identical to the <\> macro, except that it's meant to be used in expressions like <\>. trace() will not print anything to the current passage, and it won't store the result in a temporary variable. It simply returns the result. Trace takes the same arguments that the <\>macro does, and omitting an argument will expand the "origin" symbol. 88 | ### Trice Links 89 | The final way you can generate text is by using Trice links. A Trice link is a Twine link that will replace the text of the link and the passage it links to with generated text. This means that every time the player visits the passage, the link will say something different and link to a different passage. 90 | Trice links are simply regular Twine links that point to a passage that has the "grammar" tag. Thus, the "[[animal]]" link points to the animal passage which has the "grammar" tag. When the link gets displayed, though, it will show up as something like "[[cat]]" or "[[octopus]]" instead. These links will now go to the "cat" and "octopus" passages respectively. Like when building grammars, you can start a list of modifiers for the link using the left arrow (<-) symbol. Thus "[[animal<-capitalize.a]]" might result in a link like "[[A dog]]". Nevertheless, this link will still only point to the "dog" passage, so you don't have to make a different passage for every modifier you might want to include in your links. 91 | Trice links only work when you have passages with "grammar" tags on them. If you're using another method to compile the grammar for Tracery, then you probably won't have these kinds of passages already in your story. That said, there's nothing stopping you from making passages with "grammar" tags anyway. Trice links only look at the passage titles and tags to see if they should generate a new link. 92 | ## Trice Example 93 | The Twine story "The Zoo of Unnamed Creatures" is included in the Trice Example folder (Trice Example.html). This is a Twine story that uses all the functions of Trice described above. Many of the Twine passages in the story have comments explaining the use of various Trice features used in that passage. The Trice Example folder also shows the way to set up Tracery so that Trice can find it. 94 | Feel free to modify, expand, or otherwise use this example as you see fit. It is intentionally small, and it can serve as a good jumping-off point. 95 | 96 | [//]: # 97 | [Tracery]: 98 | [Tracery tutorial]: 99 | [Twincery]: 100 | [Twine]: 101 | [Twine 2 Guide]: 102 | [Cheap Bots Done Quick]: 103 | [mrfb]: 104 | [galaxykate]: 105 | [incobalt]: 106 | [Sugar Cube]: 107 | -------------------------------------------------------------------------------- /Trice Example/grammar.json: -------------------------------------------------------------------------------- 1 | { "gAction" : ["shimmer","glow","blaze","flow","sing","emit"], "gAnimal" : ["cat","dog","bear","bird","fox","anteater","elephant","rhinocerous","horse","unicorn"], "gColor" : ["red","yellow","blue","green","violet","orange","mauve","chartreuse","periwinkle","taupe"], "gCovering" : ["fur","skin","scales","feathers","hair"], "gForest" : ["forest","wood","copse"], "gHabitat" : ["tundra","plains","forest"], "gHabitatFeature" : ["#gSize# #gScenery.s# with #gColor# #gShape.s# all about","#gColor# #gScenery.s# strewn about the area","#gColor# #gShape.s# floating from the sky"], "gPlains" : ["plain","savannah","scrubland","mesa"], "gScenery" : ["rock","tree","river","bridge"], "gShape" : ["star","stripe","dot","flower","spiral","diamond"], "gSize" : ["big","small","enormous","tiny","large"], "gTundra" : ["tundra","taiga","snowfield","ice flat"] } -------------------------------------------------------------------------------- /Trice Example/tracery/LICENSE.MD: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Trice Example/tracery/iterator.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Kate 3 | */ 4 | 5 | function NodeIterator(node) { 6 | this.node = node; 7 | this.childIndex = -1; 8 | 9 | this.mode = 0; 10 | 11 | }; 12 | 13 | var itSpacer = ""; 14 | // Go to the next 15 | NodeIterator.prototype.next = function() { 16 | 17 | // Actions for this node 18 | // 0: Just entered 19 | // 1: Start children 20 | // 2: Children finished, exit 21 | 22 | switch(this.mode) { 23 | case 0: 24 | itSpacer += " "; 25 | this.mode = 1; 26 | return { 27 | log : itSpacer + "Enter " + this.node 28 | }; 29 | 30 | break; 31 | case 1: 32 | if (!this.node.children || this.node.children.length === 0) { 33 | this.mode = 2; 34 | return { 35 | log : itSpacer + "start children: no children" 36 | }; 37 | } else { 38 | var childCount = this.node.children.length; 39 | this.node = this.node.children[0]; 40 | this.mode = 0; 41 | return { 42 | log : itSpacer + "starting 0 of " + childCount + " children" 43 | }; 44 | } 45 | break; 46 | case 2: 47 | itSpacer = itSpacer.substring(3); 48 | 49 | // Find a sibling 50 | if (this.node.parent) { 51 | 52 | // Attempt sibling 53 | var nextSib = (this.node.childIndex + 1); 54 | if (this.node.parent.children[nextSib] !== undefined) { 55 | this.node = this.node.parent.children[nextSib]; 56 | this.mode = 0; 57 | return { 58 | log : itSpacer + " starting sibling " + nextSib 59 | }; 60 | } else { 61 | this.node = this.node.parent; 62 | this.mode = 2; 63 | return { 64 | log : itSpacer + " no remaining siblings, exit to parent" 65 | }; 66 | } 67 | 68 | } else { 69 | 70 | return null; 71 | 72 | } 73 | 74 | break; 75 | }; 76 | 77 | }; 78 | -------------------------------------------------------------------------------- /Trice Example/tracery/mods-eng-basic.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Kate 3 | */ 4 | 5 | function isVowel(c) { 6 | var c2 = c.toLowerCase(); 7 | return (c2 === 'a') || (c2 === 'e') || (c2 === 'i') || (c2 === 'o') || (c2 === 'u'); 8 | }; 9 | 10 | function isAlphaNum(c) { 11 | return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); 12 | }; 13 | function escapeRegExp(str) { 14 | return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); 15 | } 16 | 17 | var baseEngModifiers = { 18 | 19 | replace : function(s, params) { 20 | //http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript 21 | return s.replace(new RegExp(escapeRegExp(params[0]), 'g'), params[1]); 22 | }, 23 | 24 | capitalizeAll : function(s) { 25 | var s2 = ""; 26 | var capNext = true; 27 | for (var i = 0; i < s.length; i++) { 28 | 29 | if (!isAlphaNum(s.charAt(i))) { 30 | capNext = true; 31 | s2 += s.charAt(i); 32 | } else { 33 | if (!capNext) { 34 | s2 += s.charAt(i); 35 | } else { 36 | s2 += s.charAt(i).toUpperCase(); 37 | capNext = false; 38 | } 39 | 40 | } 41 | } 42 | return s2; 43 | }, 44 | 45 | capitalize : function(s) { 46 | return s.charAt(0).toUpperCase() + s.substring(1); 47 | }, 48 | 49 | a : function(s) { 50 | if (s.length > 0) { 51 | if (s.charAt(0).toLowerCase() === 'u') { 52 | if (s.length > 2) { 53 | if (s.charAt(2).toLowerCase() === 'i') 54 | return "a " + s; 55 | } 56 | } 57 | 58 | if (isVowel(s.charAt(0))) { 59 | return "an " + s; 60 | } 61 | } 62 | 63 | return "a " + s; 64 | 65 | }, 66 | 67 | firstS : function(s) { 68 | console.log(s); 69 | var s2 = s.split(" "); 70 | 71 | var finished = baseEngModifiers.s(s2[0]) + " " + s2.slice(1).join(" "); 72 | console.log(finished); 73 | return finished; 74 | }, 75 | 76 | s : function(s) { 77 | switch (s.charAt(s.length -1)) { 78 | case 's': 79 | return s + "es"; 80 | break; 81 | case 'h': 82 | return s + "es"; 83 | break; 84 | case 'x': 85 | return s + "es"; 86 | break; 87 | case 'y': 88 | if (!isVowel(s.charAt(s.length - 2))) 89 | return s.substring(0, s.length - 1) + "ies"; 90 | else 91 | return s + "s"; 92 | break; 93 | default: 94 | return s + "s"; 95 | } 96 | }, 97 | ed : function(s) { 98 | switch (s.charAt(s.length -1)) { 99 | case 's': 100 | return s + "ed"; 101 | break; 102 | case 'e': 103 | return s + "d"; 104 | break; 105 | case 'h': 106 | return s + "ed"; 107 | break; 108 | case 'x': 109 | return s + "ed"; 110 | break; 111 | case 'y': 112 | if (!isVowel(s.charAt(s.length - 2))) 113 | return s.substring(0, s.length - 1) + "ied"; 114 | else 115 | return s + "d"; 116 | break; 117 | default: 118 | return s + "ed"; 119 | } 120 | } 121 | }; 122 | 123 | -------------------------------------------------------------------------------- /Trice Example/tracery/tracery-vis.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Kate 3 | */ 4 | 5 | tracery.Grammar.prototype.calculateDepth = function(originWord) { 6 | // Iterate through the grammar and tag each symbol with the depth it's visited at 7 | var keys = Object.keys(this.symbols); 8 | var symbols = this.symbols; 9 | $.each(keys, function(index, key) { 10 | 11 | var symbol = symbols[key]; 12 | symbol.stats = { 13 | visits : [], 14 | leafPct : 0, 15 | }; 16 | 17 | // Flag if a leaf symbol 18 | var rules = symbol.getActiveRules(); 19 | // console.log(rules); 20 | 21 | }); 22 | }; 23 | 24 | tracery.Grammar.prototype.distributionVisualization = function(holder, settings) { 25 | // Create the visualization of usages 26 | // For each symbol in the grammar, count how many times it was used 27 | holder.html(""); 28 | var keys = Object.keys(this.symbols); 29 | var unused = []; 30 | $.each(keys, function(index, key) { 31 | var s = app.grammar.symbols[key]; 32 | if (s.uses.length > 0) { 33 | // Analyze use data 34 | var totalDepth = 0; 35 | for (var i = 0; i < s.uses.length; i++) { 36 | totalDepth += s.uses[i].node.depth; 37 | } 38 | totalDepth /= s.uses.length; 39 | 40 | var div = $("
", { 41 | class : "tracery-usage-graph", 42 | }).appendTo(holder); 43 | 44 | var label = $("
", { 45 | class : "label", 46 | text : key + ": " + s.uses.length + " d:" + totalDepth.toFixed(1) 47 | }).appendTo(div); 48 | 49 | var graph = $("
", { 50 | class : "bars", 51 | }).appendTo(div); 52 | 53 | /* 54 | $.each(s.uses, function(index, use) { 55 | var use = $("
", { 56 | class : "use", 57 | html : use.node.raw + " " + use.node.depth, 58 | }).appendTo(graph); 59 | }); 60 | */ 61 | 62 | if (s.baseRules.defaultRules) { 63 | var count = s.baseRules.defaultRules.length; 64 | var max = 0; 65 | $.each(s.baseRules.defaultRules, function(index, rule) { 66 | if (s.baseRules.defaultUses[index]) 67 | max = Math.max(s.baseRules.defaultUses[index], max); 68 | }); 69 | $.each(s.baseRules.defaultRules, function(index, rule) { 70 | 71 | var useCount = 0; 72 | var h = 1; 73 | if (s.baseRules.defaultUses[index]) { 74 | h = s.baseRules.defaultUses[index] / max * 100; 75 | useCount = s.baseRules.defaultUses[index]; 76 | } 77 | var bar = $("
", { 78 | class : "bar", 79 | }).appendTo(graph).css({ 80 | width : h + "%", 81 | top : ((index / count) * 100) + "%", 82 | height : ((1 / count) * 100) + "%", 83 | 84 | }); 85 | 86 | var label = $("
", { 87 | class : "bar-label", 88 | text : useCount + " " + rule , 89 | }).appendTo(bar); 90 | 91 | }); 92 | } 93 | } else { 94 | unused.push(s); 95 | } 96 | // console.log(unused); 97 | }); 98 | 99 | }; 100 | 101 | tracery.Grammar.prototype.cascadeVisualization = function(holder, settings) { 102 | var symbols = $("
", { 103 | class : "grammar-viz", 104 | }).appendTo(holder); 105 | 106 | for (var key in this.symbols) { 107 | var symbol = this.symbols[key]; 108 | 109 | var symbolDiv = $("
", { 110 | class : "symbol", 111 | }).appendTo(symbols); 112 | 113 | var header = $("
", { 114 | class : "header", 115 | text : key 116 | }).appendTo(symbolDiv); 117 | 118 | // Show all the rules 119 | 120 | var baseRuleHolder = $("
", { 121 | class : "rules", 122 | 123 | }).appendTo(symbolDiv); 124 | 125 | var rules = symbol.baseRules; 126 | if (!rules) { 127 | console.log(symbol); 128 | } 129 | 130 | for (var i = 0; i < rules.length; i++) { 131 | ruleToDiv(rules[i]).appendTo(baseRuleHolder); 132 | } 133 | } 134 | }; 135 | 136 | function ruleToDiv(rule) { 137 | var sections = tracery.parse(rule); 138 | 139 | var div = $("
", { 140 | class : "rule", 141 | 142 | }); 143 | 144 | for (var i = 0; i < sections.length; i++) { 145 | var sectionDiv = $("
", { 146 | class : "section section" + sections[i].type, 147 | text : sections[i].raw, 148 | }).appendTo(div); 149 | } 150 | 151 | return div; 152 | }; 153 | 154 | tracery.Grammar.prototype.referenceVisualization = function(holder, settings) { 155 | 156 | }; 157 | 158 | tracery.TraceryNode.prototype.visualizeExpansion = function(holder, settings) { 159 | 160 | var div = $("
", { 161 | class : "tracery-node tracery-node" + this.type, 162 | }).appendTo(holder); 163 | 164 | if (this === settings.active) { 165 | div.addClass("active"); 166 | } 167 | 168 | if (this.grammar.symbols[this.symbol]) { 169 | 170 | if (this.grammar.symbols[this.symbol].isDynamic) { 171 | div.addClass("dynamic"); 172 | } 173 | } else { 174 | div.addClass("missing"); 175 | 176 | } 177 | 178 | var header = $("
", { 179 | class : "header", 180 | }).appendTo(div); 181 | 182 | if (this.type === 1) { 183 | header.text(this.symbol); 184 | } else { 185 | header.text(this.finishedText); 186 | } 187 | 188 | if (this.preActions) { 189 | $.each(this.preActions, function(index, action) { 190 | var command = $("
", { 191 | class : "action-command", 192 | text : action.target + ":" + action.rule 193 | }).appendTo(div); 194 | 195 | var text = $("
", { 196 | class : "action-text", 197 | text : action.ruleText 198 | }).appendTo(div); 199 | }); 200 | } 201 | 202 | if (this.children) { 203 | var childHolder = $("
", { 204 | class : "children", 205 | 206 | }).appendTo(div); 207 | 208 | for (var i = 0; i < this.children.length; i++) { 209 | this.children[i].visualizeExpansion(childHolder, settings); 210 | } 211 | } 212 | }; 213 | 214 | tracery.rawGrammarToPrettyHTML = function(raw) { 215 | 216 | // Escape any raw html 217 | var s = ""; 218 | var keyOutputs = []; 219 | for (var key in raw) { 220 | if (raw.hasOwnProperty(key)) { 221 | var rules = JSON.stringify(raw[key]); 222 | rules = escapeHTML(rules); 223 | keyOutputs.push("\"" + key + "\":" + rules); 224 | } 225 | } 226 | return keyOutputs.join(",
"); 227 | }; 228 | 229 | -------------------------------------------------------------------------------- /Trice Example/tracery/tracery.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Kate 3 | */ 4 | 5 | var tracery = function() { 6 | var rng = Math.random; 7 | 8 | var setRng = function setRng(newRng) { 9 | rng = newRng; 10 | }; 11 | 12 | var TraceryNode = function(parent, childIndex, settings) { 13 | this.errors = []; 14 | 15 | // No input? Add an error, but continue anyways 16 | if (settings.raw === undefined) { 17 | this.errors.push("Empty input for node"); 18 | settings.raw = ""; 19 | } 20 | 21 | // If the root node of an expansion, it will have the grammar passed as the 'parent' 22 | // set the grammar from the 'parent', and set all other values for a root node 23 | if ( parent instanceof tracery.Grammar) { 24 | this.grammar = parent; 25 | this.parent = null; 26 | this.depth = 0; 27 | this.childIndex = 0; 28 | } else { 29 | this.grammar = parent.grammar; 30 | this.parent = parent; 31 | this.depth = parent.depth + 1; 32 | this.childIndex = childIndex; 33 | } 34 | 35 | this.raw = settings.raw; 36 | this.type = settings.type; 37 | this.isExpanded = false; 38 | 39 | if (!this.grammar) { 40 | console.warn("No grammar specified for this node", this); 41 | } 42 | 43 | }; 44 | 45 | TraceryNode.prototype.toString = function() { 46 | return "Node('" + this.raw + "' " + this.type + " d:" + this.depth + ")"; 47 | }; 48 | 49 | // Expand the node (with the given child rule) 50 | // Make children if the node has any 51 | TraceryNode.prototype.expandChildren = function(childRule, preventRecursion) { 52 | this.children = []; 53 | this.finishedText = ""; 54 | 55 | // Set the rule for making children, 56 | // and expand it into section 57 | this.childRule = childRule; 58 | if (this.childRule !== undefined) { 59 | var sections = tracery.parse(childRule); 60 | 61 | // Add errors to this 62 | if (sections.errors.length > 0) { 63 | this.errors = this.errors.concat(sections.errors); 64 | 65 | } 66 | 67 | for (var i = 0; i < sections.length; i++) { 68 | this.children[i] = new TraceryNode(this, i, sections[i]); 69 | if (!preventRecursion) 70 | this.children[i].expand(preventRecursion); 71 | 72 | // Add in the finished text 73 | this.finishedText += this.children[i].finishedText; 74 | } 75 | } else { 76 | // In normal operation, this shouldn't ever happen 77 | this.errors.push("No child rule provided, can't expand children"); 78 | console.warn("No child rule provided, can't expand children"); 79 | } 80 | }; 81 | 82 | // Expand this rule (possibly creating children) 83 | TraceryNode.prototype.expand = function(preventRecursion) { 84 | 85 | if (!this.isExpanded) { 86 | this.isExpanded = true; 87 | 88 | this.expansionErrors = []; 89 | 90 | // Types of nodes 91 | // -1: raw, needs parsing 92 | // 0: Plaintext 93 | // 1: Tag ("#symbol.mod.mod2.mod3#" or "#[pushTarget:pushRule]symbol.mod") 94 | // 2: Action ("[pushTarget:pushRule], [pushTarget:POP]", more in the future) 95 | 96 | switch(this.type) { 97 | // Raw rule 98 | case -1: 99 | 100 | this.expandChildren(this.raw, preventRecursion); 101 | break; 102 | 103 | // plaintext, do nothing but copy text into finsihed text 104 | case 0: 105 | this.finishedText = this.raw; 106 | break; 107 | 108 | // Tag 109 | case 1: 110 | // Parse to find any actions, and figure out what the symbol is 111 | this.preactions = []; 112 | this.postactions = []; 113 | 114 | var parsed = tracery.parseTag(this.raw); 115 | 116 | // Break into symbol actions and modifiers 117 | this.symbol = parsed.symbol; 118 | this.modifiers = parsed.modifiers; 119 | 120 | // Create all the preactions from the raw syntax 121 | for (var i = 0; i < parsed.preactions.length; i++) { 122 | this.preactions[i] = new NodeAction(this, parsed.preactions[i].raw); 123 | } 124 | for (var i = 0; i < parsed.postactions.length; i++) { 125 | // this.postactions[i] = new NodeAction(this, parsed.postactions[i].raw); 126 | } 127 | 128 | // Make undo actions for all preactions (pops for each push) 129 | for (var i = 0; i < this.preactions.length; i++) { 130 | if (this.preactions[i].type === 0) 131 | this.postactions.push(this.preactions[i].createUndo()); 132 | } 133 | 134 | // Activate all the preactions 135 | for (var i = 0; i < this.preactions.length; i++) { 136 | this.preactions[i].activate(); 137 | } 138 | 139 | this.finishedText = this.raw; 140 | 141 | // Expand (passing the node, this allows tracking of recursion depth) 142 | 143 | var selectedRule = this.grammar.selectRule(this.symbol, this, this.errors); 144 | 145 | this.expandChildren(selectedRule, preventRecursion); 146 | 147 | // Apply modifiers 148 | // TODO: Update parse function to not trigger on hashtags within parenthesis within tags, 149 | // so that modifier parameters can contain tags "#story.replace(#protagonist#, #newCharacter#)#" 150 | for (var i = 0; i < this.modifiers.length; i++) { 151 | var modName = this.modifiers[i]; 152 | var modParams = []; 153 | if (modName.indexOf("(") > 0) { 154 | var regExp = /\(([^)]+)\)/; 155 | 156 | // Todo: ignore any escaped commas. For now, commas always split 157 | var results = regExp.exec(this.modifiers[i]); 158 | if (!results || results.length < 2) { 159 | } else { 160 | var modParams = results[1].split(","); 161 | modName = this.modifiers[i].substring(0, modName.indexOf("(")); 162 | } 163 | 164 | } 165 | 166 | var mod = this.grammar.modifiers[modName]; 167 | 168 | // Missing modifier? 169 | if (!mod) { 170 | this.errors.push("Missing modifier " + modName); 171 | this.finishedText += "((." + modName + "))"; 172 | } else { 173 | this.finishedText = mod(this.finishedText, modParams); 174 | 175 | } 176 | 177 | } 178 | 179 | // Perform post-actions 180 | for (var i = 0; i < this.postactions.length; i++) { 181 | this.postactions[i].activate(); 182 | } 183 | break; 184 | case 2: 185 | 186 | // Just a bare action? Expand it! 187 | this.action = new NodeAction(this, this.raw); 188 | this.action.activate(); 189 | 190 | // No visible text for an action 191 | // TODO: some visible text for if there is a failure to perform the action? 192 | this.finishedText = ""; 193 | break; 194 | 195 | } 196 | 197 | } else { 198 | //console.warn("Already expanded " + this); 199 | } 200 | 201 | }; 202 | 203 | TraceryNode.prototype.clearEscapeChars = function() { 204 | 205 | this.finishedText = this.finishedText.replace(/\\\\/g, "DOUBLEBACKSLASH").replace(/\\/g, "").replace(/DOUBLEBACKSLASH/g, "\\"); 206 | }; 207 | 208 | // An action that occurs when a node is expanded 209 | // Types of actions: 210 | // 0 Push: [key:rule] 211 | // 1 Pop: [key:POP] 212 | // 2 function: [functionName(param0,param1)] (TODO!) 213 | function NodeAction(node, raw) { 214 | /* 215 | if (!node) 216 | console.warn("No node for NodeAction"); 217 | if (!raw) 218 | console.warn("No raw commands for NodeAction"); 219 | */ 220 | 221 | this.node = node; 222 | 223 | var sections = raw.split(":"); 224 | this.target = sections[0]; 225 | 226 | // No colon? A function! 227 | if (sections.length === 1) { 228 | this.type = 2; 229 | 230 | } 231 | 232 | // Colon? It's either a push or a pop 233 | else { 234 | this.rule = sections[1]; 235 | if (this.rule === "POP") { 236 | this.type = 1; 237 | } else { 238 | this.type = 0; 239 | } 240 | } 241 | } 242 | 243 | 244 | NodeAction.prototype.createUndo = function() { 245 | if (this.type === 0) { 246 | return new NodeAction(this.node, this.target + ":POP"); 247 | } 248 | // TODO Not sure how to make Undo actions for functions or POPs 249 | return null; 250 | }; 251 | 252 | NodeAction.prototype.activate = function() { 253 | var grammar = this.node.grammar; 254 | switch(this.type) { 255 | case 0: 256 | // split into sections (the way to denote an array of rules) 257 | this.ruleSections = this.rule.split(","); 258 | this.finishedRules = []; 259 | this.ruleNodes = []; 260 | for (var i = 0; i < this.ruleSections.length; i++) { 261 | var n = new TraceryNode(grammar, 0, { 262 | type : -1, 263 | raw : this.ruleSections[i] 264 | }); 265 | 266 | n.expand(); 267 | 268 | this.finishedRules.push(n.finishedText); 269 | } 270 | 271 | // TODO: escape commas properly 272 | grammar.pushRules(this.target, this.finishedRules, this); 273 | break; 274 | case 1: 275 | grammar.popRules(this.target); 276 | break; 277 | case 2: 278 | grammar.flatten(this.target, true); 279 | break; 280 | } 281 | 282 | }; 283 | 284 | NodeAction.prototype.toText = function() { 285 | switch(this.type) { 286 | case 0: 287 | return this.target + ":" + this.rule; 288 | case 1: 289 | return this.target + ":POP"; 290 | case 2: 291 | return "((some function))"; 292 | default: 293 | return "((Unknown Action))"; 294 | } 295 | }; 296 | 297 | // Sets of rules 298 | // Can also contain conditional or fallback sets of rulesets) 299 | function RuleSet(grammar, raw) { 300 | this.raw = raw; 301 | this.grammar = grammar; 302 | this.falloff = 1; 303 | 304 | if (Array.isArray(raw)) { 305 | this.defaultRules = raw; 306 | } else if ( typeof raw === 'string' || raw instanceof String) { 307 | this.defaultRules = [raw]; 308 | } else if (raw === 'object') { 309 | // TODO: support for conditional and hierarchical rule sets 310 | } 311 | 312 | }; 313 | 314 | RuleSet.prototype.selectRule = function(errors) { 315 | // console.log("Get rule", this.raw); 316 | // Is there a conditional? 317 | if (this.conditionalRule) { 318 | var value = this.grammar.expand(this.conditionalRule, true); 319 | // does this value match any of the conditionals? 320 | if (this.conditionalValues[value]) { 321 | var v = this.conditionalValues[value].selectRule(errors); 322 | if (v !== null && v !== undefined) 323 | return v; 324 | } 325 | // No returned value? 326 | } 327 | 328 | // Is there a ranked order? 329 | if (this.ranking) { 330 | for (var i = 0; i < this.ranking.length; i++) { 331 | var v = this.ranking.selectRule(); 332 | if (v !== null && v !== undefined) 333 | return v; 334 | } 335 | 336 | // Still no returned value? 337 | } 338 | 339 | if (this.defaultRules !== undefined) { 340 | var index = 0; 341 | // Select from this basic array of rules 342 | 343 | // Get the distribution from the grammar if there is no other 344 | var distribution = this.distribution; 345 | if (!distribution) 346 | distribution = this.grammar.distribution; 347 | 348 | switch(distribution) { 349 | case "shuffle": 350 | 351 | // create a shuffle desk 352 | if (!this.shuffledDeck || this.shuffledDeck.length === 0) { 353 | // make an array 354 | this.shuffledDeck = fyshuffle(Array.apply(null, { 355 | length : this.defaultRules.length 356 | }).map(Number.call, Number), this.falloff); 357 | 358 | } 359 | 360 | index = this.shuffledDeck.pop(); 361 | 362 | break; 363 | case "weighted": 364 | errors.push("Weighted distribution not yet implemented"); 365 | break; 366 | case "falloff": 367 | errors.push("Falloff distribution not yet implemented"); 368 | break; 369 | default: 370 | 371 | index = Math.floor(Math.pow(rng(), this.falloff) * this.defaultRules.length); 372 | break; 373 | } 374 | 375 | if (!this.defaultUses) 376 | this.defaultUses = []; 377 | this.defaultUses[index] = ++this.defaultUses[index] || 1; 378 | return this.defaultRules[index]; 379 | } 380 | 381 | errors.push("No default rules defined for " + this); 382 | return null; 383 | 384 | }; 385 | 386 | RuleSet.prototype.clearState = function() { 387 | 388 | if (this.defaultUses) { 389 | this.defaultUses = []; 390 | } 391 | }; 392 | 393 | function fyshuffle(array, falloff) { 394 | var currentIndex = array.length, 395 | temporaryValue, 396 | randomIndex; 397 | 398 | // While there remain elements to shuffle... 399 | while (0 !== currentIndex) { 400 | 401 | // Pick a remaining element... 402 | randomIndex = Math.floor(rng() * currentIndex); 403 | currentIndex -= 1; 404 | 405 | // And swap it with the current element. 406 | temporaryValue = array[currentIndex]; 407 | array[currentIndex] = array[randomIndex]; 408 | array[randomIndex] = temporaryValue; 409 | } 410 | 411 | return array; 412 | } 413 | 414 | var Symbol = function(grammar, key, rawRules) { 415 | // Symbols can be made with a single value, and array, or array of objects of (conditions/values) 416 | this.key = key; 417 | this.grammar = grammar; 418 | this.rawRules = rawRules; 419 | 420 | this.baseRules = new RuleSet(this.grammar, rawRules); 421 | this.clearState(); 422 | 423 | }; 424 | 425 | Symbol.prototype.clearState = function() { 426 | 427 | // Clear the stack and clear all ruleset usages 428 | this.stack = [this.baseRules]; 429 | 430 | this.uses = []; 431 | this.baseRules.clearState(); 432 | }; 433 | 434 | Symbol.prototype.pushRules = function(rawRules) { 435 | var rules = new RuleSet(this.grammar, rawRules); 436 | this.stack.push(rules); 437 | }; 438 | 439 | Symbol.prototype.popRules = function() { 440 | this.stack.pop(); 441 | }; 442 | 443 | Symbol.prototype.selectRule = function(node, errors) { 444 | this.uses.push({ 445 | node : node 446 | }); 447 | 448 | if (this.stack.length === 0) { 449 | errors.push("The rule stack for '" + this.key + "' is empty, too many pops?"); 450 | return "((" + this.key + "))"; 451 | } 452 | 453 | return this.stack[this.stack.length - 1].selectRule(); 454 | }; 455 | 456 | Symbol.prototype.getActiveRules = function() { 457 | if (this.stack.length === 0) { 458 | return null; 459 | } 460 | return this.stack[this.stack.length - 1].selectRule(); 461 | }; 462 | 463 | Symbol.prototype.rulesToJSON = function() { 464 | return JSON.stringify(this.rawRules); 465 | }; 466 | 467 | var Grammar = function(raw, settings) { 468 | this.modifiers = {}; 469 | this.loadFromRawObj(raw); 470 | }; 471 | 472 | Grammar.prototype.clearState = function() { 473 | var keys = Object.keys(this.symbols); 474 | for (var i = 0; i < keys.length; i++) { 475 | this.symbols[keys[i]].clearState(); 476 | } 477 | }; 478 | 479 | Grammar.prototype.addModifiers = function(mods) { 480 | 481 | // copy over the base modifiers 482 | for (var key in mods) { 483 | if (mods.hasOwnProperty(key)) { 484 | this.modifiers[key] = mods[key]; 485 | } 486 | }; 487 | 488 | }; 489 | 490 | Grammar.prototype.loadFromRawObj = function(raw) { 491 | 492 | this.raw = raw; 493 | this.symbols = {}; 494 | this.subgrammars = []; 495 | 496 | if (this.raw) { 497 | // Add all rules to the grammar 498 | for (var key in this.raw) { 499 | if (this.raw.hasOwnProperty(key)) { 500 | this.symbols[key] = new Symbol(this, key, this.raw[key]); 501 | } 502 | } 503 | } 504 | }; 505 | 506 | Grammar.prototype.createRoot = function(rule) { 507 | // Create a node and subnodes 508 | var root = new TraceryNode(this, 0, { 509 | type : -1, 510 | raw : rule, 511 | }); 512 | 513 | return root; 514 | }; 515 | 516 | Grammar.prototype.expand = function(rule, allowEscapeChars) { 517 | var root = this.createRoot(rule); 518 | root.expand(); 519 | if (!allowEscapeChars) 520 | root.clearEscapeChars(); 521 | 522 | return root; 523 | }; 524 | 525 | Grammar.prototype.flatten = function(rule, allowEscapeChars) { 526 | var root = this.expand(rule, allowEscapeChars); 527 | 528 | return root.finishedText; 529 | }; 530 | 531 | Grammar.prototype.toJSON = function() { 532 | var keys = Object.keys(this.symbols); 533 | var symbolJSON = []; 534 | for (var i = 0; i < keys.length; i++) { 535 | var key = keys[i]; 536 | symbolJSON.push(' "' + key + '" : ' + this.symbols[key].rulesToJSON()); 537 | } 538 | return "{\n" + symbolJSON.join(",\n") + "\n}"; 539 | }; 540 | 541 | // Create or push rules 542 | Grammar.prototype.pushRules = function(key, rawRules, sourceAction) { 543 | 544 | if (this.symbols[key] === undefined) { 545 | this.symbols[key] = new Symbol(this, key, rawRules); 546 | if (sourceAction) 547 | this.symbols[key].isDynamic = true; 548 | } else { 549 | this.symbols[key].pushRules(rawRules); 550 | } 551 | }; 552 | 553 | Grammar.prototype.popRules = function(key) { 554 | if (!this.symbols[key]) 555 | this.errors.push("Can't pop: no symbol for key " + key); 556 | this.symbols[key].popRules(); 557 | }; 558 | 559 | Grammar.prototype.selectRule = function(key, node, errors) { 560 | if (this.symbols[key]) { 561 | var rule = this.symbols[key].selectRule(node, errors); 562 | 563 | return rule; 564 | } 565 | 566 | // Failover to alternative subgrammars 567 | for (var i = 0; i < this.subgrammars.length; i++) { 568 | 569 | if (this.subgrammars[i].symbols[key]) 570 | return this.subgrammars[i].symbols[key].selectRule(); 571 | } 572 | 573 | // No symbol? 574 | errors.push("No symbol for '" + key + "'"); 575 | return "((" + key + "))"; 576 | }; 577 | 578 | // Parses a plaintext rule in the tracery syntax 579 | tracery = { 580 | 581 | createGrammar : function(raw) { 582 | return new Grammar(raw); 583 | }, 584 | 585 | // Parse the contents of a tag 586 | parseTag : function(tagContents) { 587 | 588 | var parsed = { 589 | symbol : undefined, 590 | preactions : [], 591 | postactions : [], 592 | modifiers : [] 593 | }; 594 | var sections = tracery.parse(tagContents); 595 | var symbolSection = undefined; 596 | for (var i = 0; i < sections.length; i++) { 597 | if (sections[i].type === 0) { 598 | if (symbolSection === undefined) { 599 | symbolSection = sections[i].raw; 600 | } else { 601 | throw ("multiple main sections in " + tagContents); 602 | } 603 | } else { 604 | parsed.preactions.push(sections[i]); 605 | } 606 | } 607 | 608 | if (symbolSection === undefined) { 609 | // throw ("no main section in " + tagContents); 610 | } else { 611 | var components = symbolSection.split("."); 612 | parsed.symbol = components[0]; 613 | parsed.modifiers = components.slice(1); 614 | } 615 | return parsed; 616 | }, 617 | 618 | parse : function(rule) { 619 | var depth = 0; 620 | var inTag = false; 621 | var sections = []; 622 | var escaped = false; 623 | 624 | var errors = []; 625 | var start = 0; 626 | 627 | var escapedSubstring = ""; 628 | var lastEscapedChar = undefined; 629 | 630 | if (rule === null) { 631 | var sections = []; 632 | sections.errors = errors; 633 | 634 | return sections; 635 | } 636 | 637 | function createSection(start, end, type) { 638 | if (end - start < 1) { 639 | if (type === 1) 640 | errors.push(start + ": empty tag"); 641 | if (type === 2) 642 | errors.push(start + ": empty action"); 643 | 644 | } 645 | var rawSubstring; 646 | if (lastEscapedChar !== undefined) { 647 | rawSubstring = escapedSubstring + "\\" + rule.substring(lastEscapedChar + 1, end); 648 | 649 | } else { 650 | rawSubstring = rule.substring(start, end); 651 | } 652 | sections.push({ 653 | type : type, 654 | raw : rawSubstring 655 | }); 656 | lastEscapedChar = undefined; 657 | escapedSubstring = ""; 658 | }; 659 | 660 | for (var i = 0; i < rule.length; i++) { 661 | 662 | if (!escaped) { 663 | var c = rule.charAt(i); 664 | 665 | switch(c) { 666 | 667 | // Enter a deeper bracketed section 668 | case '[': 669 | if (depth === 0 && !inTag) { 670 | if (start < i) 671 | createSection(start, i, 0); 672 | start = i + 1; 673 | } 674 | depth++; 675 | break; 676 | 677 | case ']': 678 | depth--; 679 | 680 | // End a bracketed section 681 | if (depth === 0 && !inTag) { 682 | createSection(start, i, 2); 683 | start = i + 1; 684 | } 685 | break; 686 | 687 | // Hashtag 688 | // ignore if not at depth 0, that means we are in a bracket 689 | case '#': 690 | if (depth === 0) { 691 | if (inTag) { 692 | createSection(start, i, 1); 693 | start = i + 1; 694 | } else { 695 | if (start < i) 696 | createSection(start, i, 0); 697 | start = i + 1; 698 | } 699 | inTag = !inTag; 700 | } 701 | break; 702 | 703 | case '\\': 704 | escaped = true; 705 | escapedSubstring = escapedSubstring + rule.substring(start, i); 706 | start = i + 1; 707 | lastEscapedChar = i; 708 | break; 709 | } 710 | } else { 711 | escaped = false; 712 | } 713 | } 714 | if (start < rule.length) 715 | createSection(start, rule.length, 0); 716 | 717 | if (inTag) { 718 | errors.push("Unclosed tag"); 719 | } 720 | if (depth > 0) { 721 | errors.push("Too many ["); 722 | } 723 | if (depth < 0) { 724 | errors.push("Too many ]"); 725 | } 726 | 727 | // Strip out empty plaintext sections 728 | 729 | sections = sections.filter(function(section) { 730 | if (section.type === 0 && section.raw.length === 0) 731 | return false; 732 | return true; 733 | }); 734 | sections.errors = errors; 735 | return sections; 736 | }, 737 | }; 738 | 739 | // Externalize 740 | tracery.TraceryNode = TraceryNode; 741 | 742 | tracery.Grammar = Grammar; 743 | tracery.Symbol = Symbol; 744 | tracery.RuleSet = RuleSet; 745 | 746 | tracery.setRng = setRng; 747 | 748 | return tracery; 749 | }(); 750 | 751 | //module.exports = tracery; -------------------------------------------------------------------------------- /Trice Example/tracery/vendor/jquery.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v2.1.4 | (c) 2005, 2015 jQuery Foundation, Inc. | jquery.org/license */ 2 | !function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l=a.document,m="2.1.4",n=function(a,b){return new n.fn.init(a,b)},o=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};n.fn=n.prototype={jquery:m,constructor:n,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=n.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return n.each(this,a,b)},map:function(a){return this.pushStack(n.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},n.extend=n.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||n.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(n.isPlainObject(d)||(e=n.isArray(d)))?(e?(e=!1,f=c&&n.isArray(c)?c:[]):f=c&&n.isPlainObject(c)?c:{},g[b]=n.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},n.extend({expando:"jQuery"+(m+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===n.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){return!n.isArray(a)&&a-parseFloat(a)+1>=0},isPlainObject:function(a){return"object"!==n.type(a)||a.nodeType||n.isWindow(a)?!1:a.constructor&&!j.call(a.constructor.prototype,"isPrototypeOf")?!1:!0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(a){var b,c=eval;a=n.trim(a),a&&(1===a.indexOf("use strict")?(b=l.createElement("script"),b.text=a,l.head.appendChild(b).parentNode.removeChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=s(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(o,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(s(Object(a))?n.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:g.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;c>d;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=s(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(c=a[b],b=a,a=c),n.isFunction(a)?(e=d.call(arguments,2),f=function(){return a.apply(b||this,e.concat(d.call(arguments)))},f.guid=a.guid=a.guid||n.guid++,f):void 0},now:Date.now,support:k}),n.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function s(a){var b="length"in a&&a.length,c=n.type(a);return"function"===c||n.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var t=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+1*new Date,v=a.document,w=0,x=0,y=ha(),z=ha(),A=ha(),B=function(a,b){return a===b&&(l=!0),0},C=1<<31,D={}.hasOwnProperty,E=[],F=E.pop,G=E.push,H=E.push,I=E.slice,J=function(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},K="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",L="[\\x20\\t\\r\\n\\f]",M="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",N=M.replace("w","w#"),O="\\["+L+"*("+M+")(?:"+L+"*([*^$|!~]?=)"+L+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+N+"))|)"+L+"*\\]",P=":("+M+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+O+")*)|.*)\\)|)",Q=new RegExp(L+"+","g"),R=new RegExp("^"+L+"+|((?:^|[^\\\\])(?:\\\\.)*)"+L+"+$","g"),S=new RegExp("^"+L+"*,"+L+"*"),T=new RegExp("^"+L+"*([>+~]|"+L+")"+L+"*"),U=new RegExp("="+L+"*([^\\]'\"]*?)"+L+"*\\]","g"),V=new RegExp(P),W=new RegExp("^"+N+"$"),X={ID:new RegExp("^#("+M+")"),CLASS:new RegExp("^\\.("+M+")"),TAG:new RegExp("^("+M.replace("w","w*")+")"),ATTR:new RegExp("^"+O),PSEUDO:new RegExp("^"+P),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+L+"*(even|odd|(([+-]|)(\\d*)n|)"+L+"*(?:([+-]|)"+L+"*(\\d+)|))"+L+"*\\)|)","i"),bool:new RegExp("^(?:"+K+")$","i"),needsContext:new RegExp("^"+L+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+L+"*((?:-\\d)?\\d*)"+L+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,aa=/[+~]/,ba=/'|\\/g,ca=new RegExp("\\\\([\\da-f]{1,6}"+L+"?|("+L+")|.)","ig"),da=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)},ea=function(){m()};try{H.apply(E=I.call(v.childNodes),v.childNodes),E[v.childNodes.length].nodeType}catch(fa){H={apply:E.length?function(a,b){G.apply(a,I.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function ga(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],k=b.nodeType,"string"!=typeof a||!a||1!==k&&9!==k&&11!==k)return d;if(!e&&p){if(11!==k&&(f=_.exec(a)))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return H.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName)return H.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=1!==k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(ba,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+ra(o[l]);w=aa.test(a)&&pa(b.parentNode)||b,x=o.join(",")}if(x)try{return H.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function ha(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function ia(a){return a[u]=!0,a}function ja(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function ka(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function la(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||C)-(~a.sourceIndex||C);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function ma(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function na(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function oa(a){return ia(function(b){return b=+b,ia(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function pa(a){return a&&"undefined"!=typeof a.getElementsByTagName&&a}c=ga.support={},f=ga.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=ga.setDocument=function(a){var b,e,g=a?a.ownerDocument||a:v;return g!==n&&9===g.nodeType&&g.documentElement?(n=g,o=g.documentElement,e=g.defaultView,e&&e!==e.top&&(e.addEventListener?e.addEventListener("unload",ea,!1):e.attachEvent&&e.attachEvent("onunload",ea)),p=!f(g),c.attributes=ja(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ja(function(a){return a.appendChild(g.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(g.getElementsByClassName),c.getById=ja(function(a){return o.appendChild(a).id=u,!g.getElementsByName||!g.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if("undefined"!=typeof b.getElementById&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(ca,da);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(ca,da);return function(a){var c="undefined"!=typeof a.getAttributeNode&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return"undefined"!=typeof b.getElementsByTagName?b.getElementsByTagName(a):c.qsa?b.querySelectorAll(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(g.querySelectorAll))&&(ja(function(a){o.appendChild(a).innerHTML="",a.querySelectorAll("[msallowcapture^='']").length&&q.push("[*^$]="+L+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+L+"*(?:value|"+K+")"),a.querySelectorAll("[id~="+u+"-]").length||q.push("~="),a.querySelectorAll(":checked").length||q.push(":checked"),a.querySelectorAll("a#"+u+"+*").length||q.push(".#.+[+~]")}),ja(function(a){var b=g.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+L+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ja(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",P)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===g||a.ownerDocument===v&&t(v,a)?-1:b===g||b.ownerDocument===v&&t(v,b)?1:k?J(k,a)-J(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,e=a.parentNode,f=b.parentNode,h=[a],i=[b];if(!e||!f)return a===g?-1:b===g?1:e?-1:f?1:k?J(k,a)-J(k,b):0;if(e===f)return la(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?la(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},g):n},ga.matches=function(a,b){return ga(a,null,null,b)},ga.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return ga(b,n,null,[a]).length>0},ga.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},ga.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&D.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},ga.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},ga.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=ga.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=ga.selectors={cacheLength:50,createPseudo:ia,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(ca,da),a[3]=(a[3]||a[4]||a[5]||"").replace(ca,da),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||ga.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&ga.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(ca,da).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+L+")"+a+"("+L+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||"undefined"!=typeof a.getAttribute&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=ga.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e.replace(Q," ")+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||ga.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?ia(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=J(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:ia(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?ia(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),b[0]=null,!c.pop()}}),has:ia(function(a){return function(b){return ga(a,b).length>0}}),contains:ia(function(a){return a=a.replace(ca,da),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ia(function(a){return W.test(a||"")||ga.error("unsupported lang: "+a),a=a.replace(ca,da).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:oa(function(){return[0]}),last:oa(function(a,b){return[b-1]}),eq:oa(function(a,b,c){return[0>c?c+b:c]}),even:oa(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:oa(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:oa(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:oa(function(a,b,c){for(var d=0>c?c+b:c;++db;b++)d+=a[b].value;return d}function sa(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function ta(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function ua(a,b,c){for(var d=0,e=b.length;e>d;d++)ga(a,b[d],c);return c}function va(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function wa(a,b,c,d,e,f){return d&&!d[u]&&(d=wa(d)),e&&!e[u]&&(e=wa(e,f)),ia(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||ua(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:va(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=va(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?J(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=va(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):H.apply(g,r)})}function xa(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=sa(function(a){return a===b},h,!0),l=sa(function(a){return J(b,a)>-1},h,!0),m=[function(a,c,d){var e=!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d));return b=null,e}];f>i;i++)if(c=d.relative[a[i].type])m=[sa(ta(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return wa(i>1&&ta(m),i>1&&ra(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&xa(a.slice(i,e)),f>e&&xa(a=a.slice(e)),f>e&&ra(a))}m.push(c)}return ta(m)}function ya(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=F.call(i));s=va(s)}H.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&ga.uniqueSort(i)}return k&&(w=v,j=t),r};return c?ia(f):f}return h=ga.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=xa(b[c]),f[u]?d.push(f):e.push(f);f=A(a,ya(e,d)),f.selector=a}return f},i=ga.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(ca,da),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(ca,da),aa.test(j[0].type)&&pa(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&ra(j),!a)return H.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,aa.test(a)&&pa(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ja(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),ja(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||ka("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ja(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||ka("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ja(function(a){return null==a.getAttribute("disabled")})||ka(K,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),ga}(a);n.find=t,n.expr=t.selectors,n.expr[":"]=n.expr.pseudos,n.unique=t.uniqueSort,n.text=t.getText,n.isXMLDoc=t.isXML,n.contains=t.contains;var u=n.expr.match.needsContext,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^.[^:#\[\.,]*$/;function x(a,b,c){if(n.isFunction(b))return n.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return n.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(w.test(b))return n.filter(b,a,c);b=n.filter(b,a)}return n.grep(a,function(a){return g.call(b,a)>=0!==c})}n.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?n.find.matchesSelector(d,a)?[d]:[]:n.find.matches(a,n.grep(b,function(a){return 1===a.nodeType}))},n.fn.extend({find:function(a){var b,c=this.length,d=[],e=this;if("string"!=typeof a)return this.pushStack(n(a).filter(function(){for(b=0;c>b;b++)if(n.contains(e[b],this))return!0}));for(b=0;c>b;b++)n.find(a,e[b],d);return d=this.pushStack(c>1?n.unique(d):d),d.selector=this.selector?this.selector+" "+a:a,d},filter:function(a){return this.pushStack(x(this,a||[],!1))},not:function(a){return this.pushStack(x(this,a||[],!0))},is:function(a){return!!x(this,"string"==typeof a&&u.test(a)?n(a):a||[],!1).length}});var y,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=n.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||y).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof n?b[0]:b,n.merge(this,n.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:l,!0)),v.test(c[1])&&n.isPlainObject(b))for(c in b)n.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}return d=l.getElementById(c[2]),d&&d.parentNode&&(this.length=1,this[0]=d),this.context=l,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):n.isFunction(a)?"undefined"!=typeof y.ready?y.ready(a):a(n):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),n.makeArray(a,this))};A.prototype=n.fn,y=n(l);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};n.extend({dir:function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&n(a).is(c))break;d.push(a)}return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),n.fn.extend({has:function(a){var b=n(a,this),c=b.length;return this.filter(function(){for(var a=0;c>a;a++)if(n.contains(this,b[a]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=u.test(a)||"string"!=typeof a?n(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&n.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?n.unique(f):f)},index:function(a){return a?"string"==typeof a?g.call(n(a),this[0]):g.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(n.unique(n.merge(this.get(),n(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){while((a=a[b])&&1!==a.nodeType);return a}n.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return n.dir(a,"parentNode")},parentsUntil:function(a,b,c){return n.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return n.dir(a,"nextSibling")},prevAll:function(a){return n.dir(a,"previousSibling")},nextUntil:function(a,b,c){return n.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return n.dir(a,"previousSibling",c)},siblings:function(a){return n.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return n.sibling(a.firstChild)},contents:function(a){return a.contentDocument||n.merge([],a.childNodes)}},function(a,b){n.fn[a]=function(c,d){var e=n.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=n.filter(d,e)),this.length>1&&(C[a]||n.unique(e),B.test(a)&&e.reverse()),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return n.each(a.match(E)||[],function(a,c){b[c]=!0}),b}n.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):n.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(b=a.memory&&l,c=!0,g=e||0,e=0,f=h.length,d=!0;h&&f>g;g++)if(h[g].apply(l[0],l[1])===!1&&a.stopOnFalse){b=!1;break}d=!1,h&&(i?i.length&&j(i.shift()):b?h=[]:k.disable())},k={add:function(){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this},remove:function(){return h&&n.each(arguments,function(a,b){var c;while((c=n.inArray(b,h,c))>-1)h.splice(c,1),d&&(f>=c&&f--,g>=c&&g--)}),this},has:function(a){return a?n.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],f=0,this},disable:function(){return h=i=b=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,b||k.disable(),this},locked:function(){return!i},fireWith:function(a,b){return!h||c&&!i||(b=b||[],b=[a,b.slice?b.slice():b],d?i.push(b):j(b)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!c}};return k},n.extend({Deferred:function(a){var b=[["resolve","done",n.Callbacks("once memory"),"resolved"],["reject","fail",n.Callbacks("once memory"),"rejected"],["notify","progress",n.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return n.Deferred(function(c){n.each(b,function(b,f){var g=n.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&n.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?n.extend(a,d):d}},e={};return d.pipe=d.then,n.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&n.isFunction(a.promise)?e:0,g=1===f?a:n.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&n.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;n.fn.ready=function(a){return n.ready.promise().done(a),this},n.extend({isReady:!1,readyWait:1,holdReady:function(a){a?n.readyWait++:n.ready(!0)},ready:function(a){(a===!0?--n.readyWait:n.isReady)||(n.isReady=!0,a!==!0&&--n.readyWait>0||(H.resolveWith(l,[n]),n.fn.triggerHandler&&(n(l).triggerHandler("ready"),n(l).off("ready"))))}});function I(){l.removeEventListener("DOMContentLoaded",I,!1),a.removeEventListener("load",I,!1),n.ready()}n.ready.promise=function(b){return H||(H=n.Deferred(),"complete"===l.readyState?setTimeout(n.ready):(l.addEventListener("DOMContentLoaded",I,!1),a.addEventListener("load",I,!1))),H.promise(b)},n.ready.promise();var J=n.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===n.type(c)){e=!0;for(h in c)n.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,n.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(n(a),c)})),b))for(;i>h;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f};n.acceptData=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function K(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=n.expando+K.uid++}K.uid=1,K.accepts=n.acceptData,K.prototype={key:function(a){if(!K.accepts(a))return 0;var b={},c=a[this.expando];if(!c){c=K.uid++;try{b[this.expando]={value:c},Object.defineProperties(a,b)}catch(d){b[this.expando]=c,n.extend(a,b)}}return this.cache[c]||(this.cache[c]={}),c},set:function(a,b,c){var d,e=this.key(a),f=this.cache[e];if("string"==typeof b)f[b]=c;else if(n.isEmptyObject(f))n.extend(this.cache[e],b);else for(d in b)f[d]=b[d];return f},get:function(a,b){var c=this.cache[this.key(a)];return void 0===b?c:c[b]},access:function(a,b,c){var d;return void 0===b||b&&"string"==typeof b&&void 0===c?(d=this.get(a,b),void 0!==d?d:this.get(a,n.camelCase(b))):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d,e,f=this.key(a),g=this.cache[f];if(void 0===b)this.cache[f]={};else{n.isArray(b)?d=b.concat(b.map(n.camelCase)):(e=n.camelCase(b),b in g?d=[b,e]:(d=e,d=d in g?[d]:d.match(E)||[])),c=d.length;while(c--)delete g[d[c]]}},hasData:function(a){return!n.isEmptyObject(this.cache[a[this.expando]]||{})},discard:function(a){a[this.expando]&&delete this.cache[a[this.expando]]}};var L=new K,M=new K,N=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,O=/([A-Z])/g;function P(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(O,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:N.test(c)?n.parseJSON(c):c}catch(e){}M.set(a,b,c)}else c=void 0;return c}n.extend({hasData:function(a){return M.hasData(a)||L.hasData(a)},data:function(a,b,c){ 3 | return M.access(a,b,c)},removeData:function(a,b){M.remove(a,b)},_data:function(a,b,c){return L.access(a,b,c)},_removeData:function(a,b){L.remove(a,b)}}),n.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=M.get(f),1===f.nodeType&&!L.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=n.camelCase(d.slice(5)),P(f,d,e[d])));L.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){M.set(this,a)}):J(this,function(b){var c,d=n.camelCase(a);if(f&&void 0===b){if(c=M.get(f,a),void 0!==c)return c;if(c=M.get(f,d),void 0!==c)return c;if(c=P(f,d,void 0),void 0!==c)return c}else this.each(function(){var c=M.get(this,d);M.set(this,d,b),-1!==a.indexOf("-")&&void 0!==c&&M.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){M.remove(this,a)})}}),n.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=L.get(a,b),c&&(!d||n.isArray(c)?d=L.access(a,b,n.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=n.queue(a,b),d=c.length,e=c.shift(),f=n._queueHooks(a,b),g=function(){n.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return L.get(a,c)||L.access(a,c,{empty:n.Callbacks("once memory").add(function(){L.remove(a,[b+"queue",c])})})}}),n.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.lengthx",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var U="undefined";k.focusinBubbles="onfocusin"in a;var V=/^key/,W=/^(?:mouse|pointer|contextmenu)|click/,X=/^(?:focusinfocus|focusoutblur)$/,Y=/^([^.]*)(?:\.(.+)|)$/;function Z(){return!0}function $(){return!1}function _(){try{return l.activeElement}catch(a){}}n.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.get(a);if(r){c.handler&&(f=c,c=f.handler,e=f.selector),c.guid||(c.guid=n.guid++),(i=r.events)||(i=r.events={}),(g=r.handle)||(g=r.handle=function(b){return typeof n!==U&&n.event.triggered!==b.type?n.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(E)||[""],j=b.length;while(j--)h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o&&(l=n.event.special[o]||{},o=(e?l.delegateType:l.bindType)||o,l=n.event.special[o]||{},k=n.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&n.expr.match.needsContext.test(e),namespace:p.join(".")},f),(m=i[o])||(m=i[o]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,p,g)!==!1||a.addEventListener&&a.addEventListener(o,g,!1)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),n.event.global[o]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.hasData(a)&&L.get(a);if(r&&(i=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=n.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,m=i[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&q!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||n.removeEvent(a,o,r.handle),delete i[o])}else for(o in i)n.event.remove(a,o+b[j],c,d,!0);n.isEmptyObject(i)&&(delete r.handle,L.remove(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,m,o,p=[d||l],q=j.call(b,"type")?b.type:b,r=j.call(b,"namespace")?b.namespace.split("."):[];if(g=h=d=d||l,3!==d.nodeType&&8!==d.nodeType&&!X.test(q+n.event.triggered)&&(q.indexOf(".")>=0&&(r=q.split("."),q=r.shift(),r.sort()),k=q.indexOf(":")<0&&"on"+q,b=b[n.expando]?b:new n.Event(q,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=r.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:n.makeArray(c,[b]),o=n.event.special[q]||{},e||!o.trigger||o.trigger.apply(d,c)!==!1)){if(!e&&!o.noBubble&&!n.isWindow(d)){for(i=o.delegateType||q,X.test(i+q)||(g=g.parentNode);g;g=g.parentNode)p.push(g),h=g;h===(d.ownerDocument||l)&&p.push(h.defaultView||h.parentWindow||a)}f=0;while((g=p[f++])&&!b.isPropagationStopped())b.type=f>1?i:o.bindType||q,m=(L.get(g,"events")||{})[b.type]&&L.get(g,"handle"),m&&m.apply(g,c),m=k&&g[k],m&&m.apply&&n.acceptData(g)&&(b.result=m.apply(g,c),b.result===!1&&b.preventDefault());return b.type=q,e||b.isDefaultPrevented()||o._default&&o._default.apply(p.pop(),c)!==!1||!n.acceptData(d)||k&&n.isFunction(d[q])&&!n.isWindow(d)&&(h=d[k],h&&(d[k]=null),n.event.triggered=q,d[q](),n.event.triggered=void 0,h&&(d[k]=h)),b.result}},dispatch:function(a){a=n.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(L.get(this,"events")||{})[a.type]||[],k=n.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=n.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,c=0;while((g=f.handlers[c++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(g.namespace))&&(a.handleObj=g,a.data=g.data,e=((n.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(a.result=e)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!==this;i=i.parentNode||this)if(i.disabled!==!0||"click"!==a.type){for(d=[],c=0;h>c;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?n(e,this).index(i)>=0:n.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h]*)\/>/gi,ba=/<([\w:]+)/,ca=/<|&#?\w+;/,da=/<(?:script|style|link)/i,ea=/checked\s*(?:[^=]|=\s*.checked.)/i,fa=/^$|\/(?:java|ecma)script/i,ga=/^true\/(.*)/,ha=/^\s*\s*$/g,ia={option:[1,""],thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};ia.optgroup=ia.option,ia.tbody=ia.tfoot=ia.colgroup=ia.caption=ia.thead,ia.th=ia.td;function ja(a,b){return n.nodeName(a,"table")&&n.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function ka(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function la(a){var b=ga.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function ma(a,b){for(var c=0,d=a.length;d>c;c++)L.set(a[c],"globalEval",!b||L.get(b[c],"globalEval"))}function na(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(L.hasData(a)&&(f=L.access(a),g=L.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)n.event.add(b,e,j[e][c])}M.hasData(a)&&(h=M.access(a),i=n.extend({},h),M.set(b,i))}}function oa(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&n.nodeName(a,b)?n.merge([a],c):c}function pa(a,b){var c=b.nodeName.toLowerCase();"input"===c&&T.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}n.extend({clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=n.contains(a.ownerDocument,a);if(!(k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||n.isXMLDoc(a)))for(g=oa(h),f=oa(a),d=0,e=f.length;e>d;d++)pa(f[d],g[d]);if(b)if(c)for(f=f||oa(a),g=g||oa(h),d=0,e=f.length;e>d;d++)na(f[d],g[d]);else na(a,h);return g=oa(h,"script"),g.length>0&&ma(g,!i&&oa(a,"script")),h},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,k=b.createDocumentFragment(),l=[],m=0,o=a.length;o>m;m++)if(e=a[m],e||0===e)if("object"===n.type(e))n.merge(l,e.nodeType?[e]:e);else if(ca.test(e)){f=f||k.appendChild(b.createElement("div")),g=(ba.exec(e)||["",""])[1].toLowerCase(),h=ia[g]||ia._default,f.innerHTML=h[1]+e.replace(aa,"<$1>")+h[2],j=h[0];while(j--)f=f.lastChild;n.merge(l,f.childNodes),f=k.firstChild,f.textContent=""}else l.push(b.createTextNode(e));k.textContent="",m=0;while(e=l[m++])if((!d||-1===n.inArray(e,d))&&(i=n.contains(e.ownerDocument,e),f=oa(k.appendChild(e),"script"),i&&ma(f),c)){j=0;while(e=f[j++])fa.test(e.type||"")&&c.push(e)}return k},cleanData:function(a){for(var b,c,d,e,f=n.event.special,g=0;void 0!==(c=a[g]);g++){if(n.acceptData(c)&&(e=c[L.expando],e&&(b=L.cache[e]))){if(b.events)for(d in b.events)f[d]?n.event.remove(c,d):n.removeEvent(c,d,b.handle);L.cache[e]&&delete L.cache[e]}delete M.cache[c[M.expando]]}}}),n.fn.extend({text:function(a){return J(this,function(a){return void 0===a?n.text(this):this.empty().each(function(){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&(this.textContent=a)})},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=ja(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=ja(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?n.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||n.cleanData(oa(c)),c.parentNode&&(b&&n.contains(c.ownerDocument,c)&&ma(oa(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(n.cleanData(oa(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return n.clone(this,a,b)})},html:function(a){return J(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!da.test(a)&&!ia[(ba.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(aa,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(n.cleanData(oa(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,n.cleanData(oa(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,m=this,o=l-1,p=a[0],q=n.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&ea.test(p))return this.each(function(c){var d=m.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(c=n.buildFragment(a,this[0].ownerDocument,!1,this),d=c.firstChild,1===c.childNodes.length&&(c=d),d)){for(f=n.map(oa(c,"script"),ka),g=f.length;l>j;j++)h=c,j!==o&&(h=n.clone(h,!0,!0),g&&n.merge(f,oa(h,"script"))),b.call(this[j],h,j);if(g)for(i=f[f.length-1].ownerDocument,n.map(f,la),j=0;g>j;j++)h=f[j],fa.test(h.type||"")&&!L.access(h,"globalEval")&&n.contains(i,h)&&(h.src?n._evalUrl&&n._evalUrl(h.src):n.globalEval(h.textContent.replace(ha,"")))}return this}}),n.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){n.fn[a]=function(a){for(var c,d=[],e=n(a),g=e.length-1,h=0;g>=h;h++)c=h===g?this:this.clone(!0),n(e[h])[b](c),f.apply(d,c.get());return this.pushStack(d)}});var qa,ra={};function sa(b,c){var d,e=n(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:n.css(e[0],"display");return e.detach(),f}function ta(a){var b=l,c=ra[a];return c||(c=sa(a,b),"none"!==c&&c||(qa=(qa||n("