aura 0.0.1.pre10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. data/.gitignore +6 -0
  2. data/.travis.yml +3 -0
  3. data/Gemfile +2 -0
  4. data/HISTORY.md +95 -0
  5. data/README.md +53 -0
  6. data/Rakefile +27 -0
  7. data/Scribefile +8 -0
  8. data/app/css/_utilities.scss +88 -0
  9. data/app/css/admin.scss +21 -0
  10. data/app/css/admin/_settings.scss +136 -0
  11. data/app/css/admin/chrome.scss +208 -0
  12. data/app/css/admin/common.scss +78 -0
  13. data/app/css/admin/forms.scss +342 -0
  14. data/app/css/admin/jquery_wysiwyg.scss +96 -0
  15. data/app/css/admin/loading.scss +18 -0
  16. data/app/css/admin/meta.scss +42 -0
  17. data/app/css/admin/reset.scss +46 -0
  18. data/app/css/admin/sections.scss +79 -0
  19. data/app/css/admin/setup.scss +22 -0
  20. data/app/css/admin/sidebar.scss +136 -0
  21. data/app/css/admin/slug.scss +78 -0
  22. data/app/css/admin/uiscreen.scss +22 -0
  23. data/app/css/admin/wysiwyg_field.scss +11 -0
  24. data/app/css/admin_watermark.scss +23 -0
  25. data/app/css/default_home_page.scss +13 -0
  26. data/app/css/login.scss +47 -0
  27. data/app/helpers/admin_helpers.rb +59 -0
  28. data/app/helpers/flash_helpers.rb +86 -0
  29. data/app/helpers/form_builder_helpers.rb +9 -0
  30. data/app/helpers/html_helpers.rb +27 -0
  31. data/app/helpers/jquery_helpers.rb +26 -0
  32. data/app/helpers/main_helpers.rb +67 -0
  33. data/app/helpers/page_helpers.rb +92 -0
  34. data/app/helpers/template_helpers.rb +94 -0
  35. data/app/helpers/user_helpers.rb +45 -0
  36. data/app/init/admin.rb +34 -0
  37. data/app/init/extensions.rb +18 -0
  38. data/app/init/pistol.rb +11 -0
  39. data/app/init/sequel.rb +11 -0
  40. data/app/main.rb +106 -0
  41. data/app/migrations/page.rb +29 -0
  42. data/app/migrations/settings.rb +11 -0
  43. data/app/migrations/user.rb +13 -0
  44. data/app/models/page.rb +116 -0
  45. data/app/models/page_seed.rb +47 -0
  46. data/app/models/settings.rb +59 -0
  47. data/app/models/user.rb +60 -0
  48. data/app/routes/admin.rb +44 -0
  49. data/app/routes/css_js.rb +53 -0
  50. data/app/routes/design_tests.rb +15 -0
  51. data/app/routes/editor.rb +152 -0
  52. data/app/routes/site.rb +33 -0
  53. data/app/routes/user.rb +48 -0
  54. data/app/views/admin/_back_to_dashboard.haml +3 -0
  55. data/app/views/admin/dashboard.haml +46 -0
  56. data/app/views/admin/layout.haml +73 -0
  57. data/app/views/admin/settings.haml +40 -0
  58. data/app/views/admin/settings/database.haml +42 -0
  59. data/app/views/base/crumbs.haml +50 -0
  60. data/app/views/base/delete.haml +19 -0
  61. data/app/views/base/edit.haml +61 -0
  62. data/app/views/base/errors.haml +10 -0
  63. data/app/views/base/form.haml +11 -0
  64. data/app/views/base/list.haml +14 -0
  65. data/app/views/base/list_actions.haml +4 -0
  66. data/app/views/base/list_item.haml +7 -0
  67. data/app/views/base/nav.haml +36 -0
  68. data/app/views/base/new.haml +36 -0
  69. data/app/views/base/preview.haml +28 -0
  70. data/app/views/base/tabs.haml +12 -0
  71. data/app/views/default_home_page.haml +15 -0
  72. data/app/views/design_tests/admin_styles.haml +58 -0
  73. data/app/views/form_builder/builder.haml +29 -0
  74. data/app/views/page/edit.haml +29 -0
  75. data/app/views/page/form.haml +22 -0
  76. data/app/views/page/meta_form.haml +22 -0
  77. data/app/views/page/new.haml +26 -0
  78. data/app/views/user/edit.haml +52 -0
  79. data/app/views/user/form.haml +43 -0
  80. data/app/views/user/list.haml +11 -0
  81. data/app/views/user/login.haml +33 -0
  82. data/app/views/user/new.haml +25 -0
  83. data/app/views/user/welcome.haml +29 -0
  84. data/app/views/watermark/watermark.haml +16 -0
  85. data/aura.gemspec +36 -0
  86. data/bin/aura +8 -0
  87. data/config/database.rb +12 -0
  88. data/config/extensions.rb +5 -0
  89. data/config/scss.rb +14 -0
  90. data/config/user.rb +10 -0
  91. data/default/.gitignore +6 -0
  92. data/default/Gemfile +11 -0
  93. data/default/README.md +24 -0
  94. data/default/Rakefile +8 -0
  95. data/default/app/README +3 -0
  96. data/default/app/css/.gitignore +0 -0
  97. data/default/app/helpers/helpers.rb.example +9 -0
  98. data/default/app/js/.gitignore +0 -0
  99. data/default/app/migrations/model.rb.example +20 -0
  100. data/default/app/models/model.rb.example +11 -0
  101. data/default/app/models/page-ext.rb.example +17 -0
  102. data/default/app/routes/site.rb.example +5 -0
  103. data/default/app/views/hello.haml.example +1 -0
  104. data/default/config.ru +3 -0
  105. data/default/config/.gitignore +0 -0
  106. data/default/config/database.rb.example +30 -0
  107. data/default/config/extensions.rb +5 -0
  108. data/default/config/user.rb.example +10 -0
  109. data/default/db/.gitignore +0 -0
  110. data/default/init.rb +15 -0
  111. data/default/public/.gitignore +0 -0
  112. data/extensions/contact_form/migrations/contact_form.rb +13 -0
  113. data/extensions/contact_form/models/contact_form.rb +13 -0
  114. data/extensions/contact_form/routes/contact_form.rb +11 -0
  115. data/extensions/contact_form/views/contact_form/edit.haml +8 -0
  116. data/extensions/contact_form/views/contact_form/form.haml +3 -0
  117. data/extensions/contact_form/views/contact_form/nav.haml +42 -0
  118. data/extensions/contact_form/views/contact_form/responses.haml +20 -0
  119. data/extensions/contact_form/views/contact_form/tabs.haml +8 -0
  120. data/extensions/default_theme/css/theme/_settings.scss +3 -0
  121. data/extensions/default_theme/css/theme/chrome.scss +66 -0
  122. data/extensions/default_theme/css/theme/reset.scss +34 -0
  123. data/extensions/default_theme/css/theme/style.scss +3 -0
  124. data/extensions/default_theme/info.yml +2 -0
  125. data/extensions/default_theme/public/browse.png +0 -0
  126. data/extensions/default_theme/views/base/id_portfolio.haml +32 -0
  127. data/extensions/default_theme/views/base/show.haml +31 -0
  128. data/extensions/default_theme/views/errors/error.haml +9 -0
  129. data/extensions/default_theme/views/errors/not_found.haml +11 -0
  130. data/extensions/default_theme/views/layout.haml +33 -0
  131. data/lib/aura.rb +315 -0
  132. data/lib/aura/admin.rb +41 -0
  133. data/lib/aura/app.rb +4 -0
  134. data/lib/aura/cli.rb +19 -0
  135. data/lib/aura/cli/base.rb +89 -0
  136. data/lib/aura/cli/helpers.rb +32 -0
  137. data/lib/aura/editor.rb +30 -0
  138. data/lib/aura/extension.rb +189 -0
  139. data/lib/aura/files.rb +38 -0
  140. data/lib/aura/menu.rb +142 -0
  141. data/lib/aura/models.rb +80 -0
  142. data/lib/aura/public.rb +68 -0
  143. data/lib/aura/rendering.rb +134 -0
  144. data/lib/aura/seeder.rb +38 -0
  145. data/lib/aura/slugs.rb +87 -0
  146. data/lib/aura/subtype.rb +48 -0
  147. data/lib/aura/tasks.rb +24 -0
  148. data/lib/aura/tasks/common.rb +17 -0
  149. data/lib/aura/tasks/db.rake +54 -0
  150. data/lib/aura/utils.rb +81 -0
  151. data/lib/aura/version.rb +25 -0
  152. data/lib/core/hasharray.rb +65 -0
  153. data/lib/core/object_ext.rb +9 -0
  154. data/lib/sequel/plugins/aura_custom.rb +16 -0
  155. data/lib/sequel/plugins/aura_editable.rb +39 -0
  156. data/lib/sequel/plugins/aura_hierarchy.rb +82 -0
  157. data/lib/sequel/plugins/aura_model.rb +271 -0
  158. data/lib/sequel/plugins/aura_renderable.rb +42 -0
  159. data/lib/sequel/plugins/aura_sluggable.rb +103 -0
  160. data/lib/sequel/plugins/aura_subtyped.rb +83 -0
  161. data/lib/terra.rb +185 -0
  162. data/lib/terra/ext.rb +16 -0
  163. data/lib/terra/field.rb +98 -0
  164. data/lib/terra/fields.rb +122 -0
  165. data/lib/terra/fieldset.rb +93 -0
  166. data/lib/terra/form.rb +111 -0
  167. data/manual/configuration.md +42 -0
  168. data/manual/extensions.md +45 -0
  169. data/manual/files.md +70 -0
  170. data/manual/helpers.md +39 -0
  171. data/manual/index.md +65 -0
  172. data/manual/models.md +58 -0
  173. data/manual/recipes.md +38 -0
  174. data/manual/recipes/bundling_sample_data.md +30 -0
  175. data/manual/recipes/creating_themes.md +10 -0
  176. data/manual/recipes/using_markdown_or_textile.md +24 -0
  177. data/manual/routes.md +39 -0
  178. data/manual/theming.md +55 -0
  179. data/manual/views.md +128 -0
  180. data/public/hi.html +0 -0
  181. data/public/images/admin/back.png +0 -0
  182. data/public/images/admin/browse.png +0 -0
  183. data/public/images/admin/mock-bg.png +0 -0
  184. data/public/images/admin/top-loader.gif +0 -0
  185. data/public/images/admin/uiscreen-loader.gif +0 -0
  186. data/public/images/admin_icons/add.png +0 -0
  187. data/public/images/admin_icons/contact.png +0 -0
  188. data/public/images/admin_icons/dashboard.png +0 -0
  189. data/public/images/admin_icons/generic.png +0 -0
  190. data/public/images/admin_icons/home-12.png +0 -0
  191. data/public/images/admin_icons/page.png +0 -0
  192. data/public/images/admin_icons/settings.png +0 -0
  193. data/public/images/jquery.wysiwyg.gif +0 -0
  194. data/public/js/admin.form_builder.js +15 -0
  195. data/public/js/admin.js +62 -0
  196. data/public/js/admin.layout.js +53 -0
  197. data/public/js/admin.nav.js +241 -0
  198. data/public/js/admin.slug.js +46 -0
  199. data/public/js/admin.subpage.js +15 -0
  200. data/public/js/jquery.hashlisten.js +85 -0
  201. data/public/js/jquery.js +166 -0
  202. data/public/js/jquery.livenavigate.js +58 -0
  203. data/public/js/jquery.livequery.js +226 -0
  204. data/public/js/jquery.quickvalidate.js +164 -0
  205. data/public/js/jquery.tmpl.js +486 -0
  206. data/public/js/jquery.uiscreen.js +150 -0
  207. data/public/js/jquery.wysiwyg.js +2339 -0
  208. data/public/js/jqueryui.js +766 -0
  209. data/public/js/lib.dirty.js +11 -0
  210. data/public/js/lib.loading.js +23 -0
  211. data/public/js/lib.wysiwyg.js +155 -0
  212. data/public/js/underscore-1.1.7.js +27 -0
  213. data/test/app/app/css/test_raw.css +1 -0
  214. data/test/app/app/css/test_sass.sass +3 -0
  215. data/test/app/app/damogram.txt +1 -0
  216. data/test/app/app/js/test_coffee.coffee +4 -0
  217. data/test/app/app/js/test_javascript.js +4 -0
  218. data/test/app/init.rb +5 -0
  219. data/test/stories/admin_css_story.rb +18 -0
  220. data/test/stories/css_js_story.rb +29 -0
  221. data/test/stories/first_login_story.rb +29 -0
  222. data/test/stories/visit_story.rb +39 -0
  223. data/test/stories_helper.rb +58 -0
  224. data/test/test_cli_helper.rb +31 -0
  225. data/test/test_helper.rb +111 -0
  226. data/test/test_temp_helper.rb +9 -0
  227. data/test/unit/cli_test.rb +38 -0
  228. data/test/unit/dump_test.rb +14 -0
  229. data/test/unit/extensions_test.rb +18 -0
  230. data/test/unit/files_test.rb +14 -0
  231. data/test/unit/flash_helper_test.rb +36 -0
  232. data/test/unit/html_helper_test.rb +29 -0
  233. data/test/unit/jquery_helper_test.rb +18 -0
  234. data/test/unit/model_test.rb +34 -0
  235. data/test/unit/page_helpers_test.rb +36 -0
  236. data/test/unit/seeder_test.rb +15 -0
  237. data/test/unit/settings_test.rb +29 -0
  238. data/test/unit/slug_test.rb +39 -0
  239. data/test/unit/ss_migration_test.rb +14 -0
  240. data/test/unit/terra_test.rb +125 -0
  241. data/test/unit/utils_test.rb +11 -0
  242. data/vendor/sinatra-sequel/.gitignore +3 -0
  243. data/vendor/sinatra-sequel/COPYING +18 -0
  244. data/vendor/sinatra-sequel/README.md +84 -0
  245. data/vendor/sinatra-sequel/Rakefile +67 -0
  246. data/vendor/sinatra-sequel/lib/sinatra/sequel.rb +73 -0
  247. data/vendor/sinatra-sequel/sinatra-sequel.gemspec +39 -0
  248. data/vendor/sinatra-sequel/spec/spec_sinatra_sequel.rb +70 -0
  249. metadata +536 -0
@@ -0,0 +1,58 @@
1
+ // In-page navigation that doesn't break the back button and actually changes
2
+ // the URL.
3
+ //
4
+ // What it solves:
5
+ //
6
+ // The usual approach to single-page apps are URL's like
7
+ // `http://domain.com/#!1938/article`. Livenavigate does the same thing,
8
+ // except that it your URL will be `http://domain.com/1938/article`, yet
9
+ // everything will be in-place via AJAX.
10
+ //
11
+ // This is only supported if your browser supports history states (FF4/Safari).
12
+ // Don't worry though--it will fallback to the hashbang method otherwise.
13
+ //
14
+ // For hashbang URL's, this relies on the awesome jQuery.hashListen. It
15
+ // uses the hash change event, and falls back to window timers if it's not
16
+ // available.
17
+ //
18
+ // End result: in-place navigation with nice URL's, no matter what browser.
19
+ //
20
+ // Usage:
21
+ //
22
+ // /* Bind this to like, say, <a> links */
23
+ // $.navigate('/admin/products');
24
+ //
25
+ // If the history states are available (Safari/FF4), it will change the actual URL
26
+ // of the page, yet still /not/ load the URL directly (but instead just trigger the
27
+ // `navigate` event).
28
+ //
29
+ // /* Here's how you listen to new pages */
30
+ // $(window).bind('navigate', function (e, href) {
31
+ // /* href == '/admin/products' */
32
+ // });
33
+ //
34
+ // If history states are not available, it will fall back to hashListen.
35
+ //
36
+ ;(function ($) {
37
+ if (window.history.pushState) {
38
+ $.navigate = function (href) {
39
+ window.history.pushState({ href: href }, "", href);
40
+ $(window).trigger('navigate', href);
41
+ };
42
+
43
+ window.onpopstate = function (e, state) {
44
+ $(window).trigger('navigate', window.location.pathname);
45
+ };
46
+ }
47
+
48
+ else {
49
+ $.navigate = function (href) {
50
+ if (window.location.hash == '#!'+href) { return; }
51
+ window.location.hash = "#!" + href;
52
+ };
53
+
54
+ $.hashListen('!(.*)', function (href) {
55
+ $(window).trigger('navigate', href);
56
+ });
57
+ };
58
+ })(jQuery);
@@ -0,0 +1,226 @@
1
+ /*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
2
+ * Dual licensed under the MIT (MIT_LICENSE.txt)
3
+ * and GPL Version 2 (GPL_LICENSE.txt) licenses.
4
+ *
5
+ * Version: 1.1.1
6
+ * Requires jQuery 1.3+
7
+ * Docs: http://docs.jquery.com/Plugins/livequery
8
+ */
9
+
10
+ (function($) {
11
+
12
+ $.extend($.fn, {
13
+ livequery: function(type, fn, fn2) {
14
+ var self = this, q;
15
+
16
+ // Handle different call patterns
17
+ if ($.isFunction(type))
18
+ fn2 = fn, fn = type, type = undefined;
19
+
20
+ // See if Live Query already exists
21
+ $.each( $.livequery.queries, function(i, query) {
22
+ if ( self.selector == query.selector && self.context == query.context &&
23
+ type == query.type && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) )
24
+ // Found the query, exit the each loop
25
+ return (q = query) && false;
26
+ });
27
+
28
+ // Create new Live Query if it wasn't found
29
+ q = q || new $.livequery(this.selector, this.context, type, fn, fn2);
30
+
31
+ // Make sure it is running
32
+ q.stopped = false;
33
+
34
+ // Run it immediately for the first time
35
+ q.run();
36
+
37
+ // Contnue the chain
38
+ return this;
39
+ },
40
+
41
+ expire: function(type, fn, fn2) {
42
+ var self = this;
43
+
44
+ // Handle different call patterns
45
+ if ($.isFunction(type))
46
+ fn2 = fn, fn = type, type = undefined;
47
+
48
+ // Find the Live Query based on arguments and stop it
49
+ $.each( $.livequery.queries, function(i, query) {
50
+ if ( self.selector == query.selector && self.context == query.context &&
51
+ (!type || type == query.type) && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) && !this.stopped )
52
+ $.livequery.stop(query.id);
53
+ });
54
+
55
+ // Continue the chain
56
+ return this;
57
+ }
58
+ });
59
+
60
+ $.livequery = function(selector, context, type, fn, fn2) {
61
+ this.selector = selector;
62
+ this.context = context;
63
+ this.type = type;
64
+ this.fn = fn;
65
+ this.fn2 = fn2;
66
+ this.elements = [];
67
+ this.stopped = false;
68
+
69
+ // The id is the index of the Live Query in $.livequery.queries
70
+ this.id = $.livequery.queries.push(this)-1;
71
+
72
+ // Mark the functions for matching later on
73
+ fn.$lqguid = fn.$lqguid || $.livequery.guid++;
74
+ if (fn2) fn2.$lqguid = fn2.$lqguid || $.livequery.guid++;
75
+
76
+ // Return the Live Query
77
+ return this;
78
+ };
79
+
80
+ $.livequery.prototype = {
81
+ stop: function() {
82
+ var query = this;
83
+
84
+ if ( this.type )
85
+ // Unbind all bound events
86
+ this.elements.unbind(this.type, this.fn);
87
+ else if (this.fn2)
88
+ // Call the second function for all matched elements
89
+ this.elements.each(function(i, el) {
90
+ query.fn2.apply(el);
91
+ });
92
+
93
+ // Clear out matched elements
94
+ this.elements = [];
95
+
96
+ // Stop the Live Query from running until restarted
97
+ this.stopped = true;
98
+ },
99
+
100
+ run: function() {
101
+ // Short-circuit if stopped
102
+ if ( this.stopped ) return;
103
+ var query = this;
104
+
105
+ var oEls = this.elements,
106
+ els = $(this.selector, this.context),
107
+ nEls = els.not(oEls);
108
+
109
+ // Set elements to the latest set of matched elements
110
+ this.elements = els;
111
+
112
+ if (this.type) {
113
+ // Bind events to newly matched elements
114
+ nEls.bind(this.type, this.fn);
115
+
116
+ // Unbind events to elements no longer matched
117
+ if (oEls.length > 0)
118
+ $.each(oEls, function(i, el) {
119
+ if ( $.inArray(el, els) < 0 )
120
+ $.event.remove(el, query.type, query.fn);
121
+ });
122
+ }
123
+ else {
124
+ // Call the first function for newly matched elements
125
+ nEls.each(function() {
126
+ query.fn.apply(this);
127
+ });
128
+
129
+ // Call the second function for elements no longer matched
130
+ if ( this.fn2 && oEls.length > 0 )
131
+ $.each(oEls, function(i, el) {
132
+ if ( $.inArray(el, els) < 0 )
133
+ query.fn2.apply(el);
134
+ });
135
+ }
136
+ }
137
+ };
138
+
139
+ $.extend($.livequery, {
140
+ guid: 0,
141
+ queries: [],
142
+ queue: [],
143
+ running: false,
144
+ timeout: null,
145
+
146
+ checkQueue: function() {
147
+ if ( $.livequery.running && $.livequery.queue.length ) {
148
+ var length = $.livequery.queue.length;
149
+ // Run each Live Query currently in the queue
150
+ while ( length-- )
151
+ $.livequery.queries[ $.livequery.queue.shift() ].run();
152
+ }
153
+ },
154
+
155
+ pause: function() {
156
+ // Don't run anymore Live Queries until restarted
157
+ $.livequery.running = false;
158
+ },
159
+
160
+ play: function() {
161
+ // Restart Live Queries
162
+ $.livequery.running = true;
163
+ // Request a run of the Live Queries
164
+ $.livequery.run();
165
+ },
166
+
167
+ registerPlugin: function() {
168
+ $.each( arguments, function(i,n) {
169
+ // Short-circuit if the method doesn't exist
170
+ if (!$.fn[n]) return;
171
+
172
+ // Save a reference to the original method
173
+ var old = $.fn[n];
174
+
175
+ // Create a new method
176
+ $.fn[n] = function() {
177
+ // Call the original method
178
+ var r = old.apply(this, arguments);
179
+
180
+ // Request a run of the Live Queries
181
+ $.livequery.run();
182
+
183
+ // Return the original methods result
184
+ return r;
185
+ }
186
+ });
187
+ },
188
+
189
+ run: function(id) {
190
+ if (id != undefined) {
191
+ // Put the particular Live Query in the queue if it doesn't already exist
192
+ if ( $.inArray(id, $.livequery.queue) < 0 )
193
+ $.livequery.queue.push( id );
194
+ }
195
+ else
196
+ // Put each Live Query in the queue if it doesn't already exist
197
+ $.each( $.livequery.queries, function(id) {
198
+ if ( $.inArray(id, $.livequery.queue) < 0 )
199
+ $.livequery.queue.push( id );
200
+ });
201
+
202
+ // Clear timeout if it already exists
203
+ if ($.livequery.timeout) clearTimeout($.livequery.timeout);
204
+ // Create a timeout to check the queue and actually run the Live Queries
205
+ $.livequery.timeout = setTimeout($.livequery.checkQueue, 20);
206
+ },
207
+
208
+ stop: function(id) {
209
+ if (id != undefined)
210
+ // Stop are particular Live Query
211
+ $.livequery.queries[ id ].stop();
212
+ else
213
+ // Stop all Live Queries
214
+ $.each( $.livequery.queries, function(id) {
215
+ $.livequery.queries[ id ].stop();
216
+ });
217
+ }
218
+ });
219
+
220
+ // Register core DOM manipulation methods
221
+ $.livequery.registerPlugin('append', 'prepend', 'after', 'before', 'wrap', 'attr', 'removeAttr', 'addClass', 'removeClass', 'toggleClass', 'empty', 'remove', 'html');
222
+
223
+ // Run Live Queries when the Document is ready
224
+ $(function() { $.livequery.play(); });
225
+
226
+ })(jQuery);
@@ -0,0 +1,164 @@
1
+ ;(function ($) {
2
+ $.qvalidate = function() {};
3
+
4
+ // Stop form submissions for forms that don't validate.
5
+ // Trigger the `submit_error` event.
6
+ //
7
+ $('form:not(.skip-validation)').live('submit', function (e) {
8
+ // Validate all fields that need validations.
9
+ $(this).find('input, textarea, select').trigger('blur');
10
+
11
+ // all .assert's that fail will have the class .error after validations.
12
+ if ($(this).find('.error').length) {
13
+ $(this).trigger('submit_error');
14
+ $(this).find('.error').find('input, textarea, select').first().focus();
15
+ e.stopPropagation();
16
+ return false;
17
+ }
18
+ });
19
+
20
+ // Do validations after every 'blur'.
21
+ // Call the `validate` event for these; the event handlers will
22
+ // be the ones to call the function validate().
23
+ //
24
+ // The function validate() will mark if fields are either errors
25
+ // or ok's. This event handler either trigger the `assert_error`
26
+ // or `assert_ok` on these fields, depending on the outcome.
27
+ //
28
+ $('.assert').find('input, textarea, select').live('blur', function () {
29
+ var $p = $(this).closest('.assert');
30
+ $p.trigger('validate', [$(this)]);
31
+
32
+ var data = ($p.data('assert_data') || {});
33
+
34
+ if (data.status == 'error') {
35
+ $p.addClass('error');
36
+ $p.trigger('assert_error', [data.type]);
37
+ } else {
38
+ $p.removeClass('error');
39
+ $p.trigger('assert_ok', [data.type]);
40
+ }
41
+
42
+ $p.data('assert_data', null);
43
+ });
44
+
45
+ // Called by the `validate` event handlers.
46
+ // If the given condition is false, mark it as an error.
47
+ //
48
+ function validate($p, condition, type) {
49
+ var data = ($p.data('assert_data') || {});
50
+
51
+ if (data.status != 'error') {
52
+ data.type = type;
53
+ data.status = condition ? 'ok' : 'error';
54
+ }
55
+
56
+ $p.data('assert_data', data);
57
+ };
58
+
59
+ /*
60
+ * Validations
61
+ */
62
+
63
+ // Required fields
64
+ $('.assert.required, .assert.present').live('validate', function (e, $input) {
65
+ validate($(this), ($input.val() != ''), 'required');
66
+ });
67
+
68
+ // Numeric fields
69
+ $('.assert.numeric').live('validate', function (e, $input) {
70
+ validate($(this), $input.val().match(/^[0-9]*$/) !== null, 'numeric');
71
+ });
72
+
73
+ // Minimum lengths
74
+ $('.assert[data-min-length]').live('validate', function (e, $input) {
75
+ var len = $input.val().length;
76
+ var min = parseInt($(this).attr('data-min-length'));
77
+ validate($(this), (len >= min) || (len == 0), 'min-length');
78
+ });
79
+
80
+ // Matches next
81
+ // Always paired with a `matches-previous`. Good for password fields.
82
+ $('.assert.matches-next').live('validate', function () {
83
+ var $p0 = $(this);
84
+ var $p1 = $p0.nextAll('.assert.matches-previous').first();
85
+
86
+ var $input1 = $p1.find('input, textarea, select');
87
+ var $input0 = $p0.find('input');
88
+
89
+ if (($input1.val() != '') || ($input0.val() == '')) {
90
+ $input1.trigger('blur');
91
+ }
92
+ });
93
+
94
+ // Matches previous
95
+ // Always paired with a `matches-next`. Good for password fields.
96
+ $('.assert.matches-previous').live('validate', function () {
97
+ var $p1 = $(this);
98
+ var $p0 = $p1.prevAll('.assert.matches-next').first();
99
+
100
+ var $input0 = $p0.find('input, textarea, select');
101
+ var $input1 = $p1.find('input');
102
+
103
+ var condition = ($input0.val() == $input1.val());
104
+ validate($p1, condition, 'matches');
105
+ });
106
+
107
+ /*
108
+ * Default handlers
109
+ */
110
+
111
+ function onAssertError (e, type) {
112
+ var msg = "";
113
+ if (type == 'required') { msg = "Required"; }
114
+ if (type == 'min-length') { msg = "Should be at least " + $(this).attr('data-min-length') + " chars"; }
115
+ if (type == 'numeric') { msg = "Should be a number"; }
116
+ if (type == 'matches') { msg = "Doesn't match"; }
117
+
118
+ var $n = $(this).find('.notice');
119
+
120
+ if ($n.length) { $n.html(msg); }
121
+
122
+ else {
123
+ var t = $("<div class='notice'>" + msg + "</div>");
124
+ $(this).append(t);
125
+ t.hide().fadeIn();
126
+ }
127
+ };
128
+
129
+ function onAssertOk (e, type) {
130
+ var $n = $(this).find('.notice');
131
+ if ($n) {
132
+ $n.html("OK!");
133
+ window.setTimeout(function () {
134
+ $n.fadeOut(function () { $n.remove(); });
135
+ }, 500);
136
+ }
137
+ };
138
+
139
+ function onSubmitError () {
140
+ alert("Please check your form for errors.");
141
+ };
142
+
143
+ function bindDefaults() {
144
+ $('.assert')
145
+ .live('assert_error', onAssertError)
146
+ .live('assert_ok', onAssertOk);
147
+
148
+ $('form').live('submit_error', onSubmitError);
149
+ }
150
+
151
+ function unbindDefaults() {
152
+ $('.assert')
153
+ .die('assert_error', onAssertError)
154
+ .die('assert_ok', onAssertOk);
155
+
156
+ $('form').die('submit_error', onSubmitError);
157
+ }
158
+
159
+ bindDefaults();
160
+
161
+ // Export
162
+ $.qvalidate.validate = validate;
163
+ $.qvalidate.unbindDefaults = unbindDefaults;
164
+ })(jQuery);
@@ -0,0 +1,486 @@
1
+ /*
2
+ * jQuery Templating Plugin
3
+ * Copyright 2010, John Resig
4
+ * Dual licensed under the MIT or GPL Version 2 licenses.
5
+ */
6
+ (function( jQuery, undefined ){
7
+ var oldManip = jQuery.fn.domManip, tmplItmAtt = "_tmplitem", htmlExpr = /^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,
8
+ newTmplItems = {}, wrappedItems = {}, appendToTmplItems, topTmplItem = { key: 0, data: {} }, itemKey = 0, cloneIndex = 0, stack = [];
9
+
10
+ function newTmplItem( options, parentItem, fn, data ) {
11
+ // Returns a template item data structure for a new rendered instance of a template (a 'template item').
12
+ // The content field is a hierarchical array of strings and nested items (to be
13
+ // removed and replaced by nodes field of dom elements, once inserted in DOM).
14
+ var newItem = {
15
+ data: data || (parentItem ? parentItem.data : {}),
16
+ _wrap: parentItem ? parentItem._wrap : null,
17
+ tmpl: null,
18
+ parent: parentItem || null,
19
+ nodes: [],
20
+ calls: tiCalls,
21
+ nest: tiNest,
22
+ wrap: tiWrap,
23
+ html: tiHtml,
24
+ update: tiUpdate
25
+ };
26
+ if ( options ) {
27
+ jQuery.extend( newItem, options, { nodes: [], parent: parentItem } );
28
+ }
29
+ if ( fn ) {
30
+ // Build the hierarchical content to be used during insertion into DOM
31
+ newItem.tmpl = fn;
32
+ newItem._ctnt = newItem._ctnt || newItem.tmpl( jQuery, newItem );
33
+ newItem.key = ++itemKey;
34
+ // Keep track of new template item, until it is stored as jQuery Data on DOM element
35
+ (stack.length ? wrappedItems : newTmplItems)[itemKey] = newItem;
36
+ }
37
+ return newItem;
38
+ }
39
+
40
+ // Override appendTo etc., in order to provide support for targeting multiple elements. (This code would disappear if integrated in jquery core).
41
+ jQuery.each({
42
+ appendTo: "append",
43
+ prependTo: "prepend",
44
+ insertBefore: "before",
45
+ insertAfter: "after",
46
+ replaceAll: "replaceWith"
47
+ }, function( name, original ) {
48
+ jQuery.fn[ name ] = function( selector ) {
49
+ var ret = [], insert = jQuery( selector ), elems, i, l, tmplItems,
50
+ parent = this.length === 1 && this[0].parentNode;
51
+
52
+ appendToTmplItems = newTmplItems || {};
53
+ if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
54
+ insert[ original ]( this[0] );
55
+ ret = this;
56
+ } else {
57
+ for ( i = 0, l = insert.length; i < l; i++ ) {
58
+ cloneIndex = i;
59
+ elems = (i > 0 ? this.clone(true) : this).get();
60
+ jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
61
+ ret = ret.concat( elems );
62
+ }
63
+ cloneIndex = 0;
64
+ ret = this.pushStack( ret, name, insert.selector );
65
+ }
66
+ tmplItems = appendToTmplItems;
67
+ appendToTmplItems = null;
68
+ jQuery.tmpl.complete( tmplItems );
69
+ return ret;
70
+ };
71
+ });
72
+
73
+ jQuery.fn.extend({
74
+ // Use first wrapped element as template markup.
75
+ // Return wrapped set of template items, obtained by rendering template against data.
76
+ tmpl: function( data, options, parentItem ) {
77
+ return jQuery.tmpl( this[0], data, options, parentItem );
78
+ },
79
+
80
+ // Find which rendered template item the first wrapped DOM element belongs to
81
+ tmplItem: function() {
82
+ return jQuery.tmplItem( this[0] );
83
+ },
84
+
85
+ // Consider the first wrapped element as a template declaration, and get the compiled template or store it as a named template.
86
+ template: function( name ) {
87
+ return jQuery.template( name, this[0] );
88
+ },
89
+
90
+ domManip: function( args, table, callback, options ) {
91
+ // This appears to be a bug in the appendTo, etc. implementation
92
+ // it should be doing .call() instead of .apply(). See #6227
93
+ if ( args[0] && args[0].nodeType ) {
94
+ var dmArgs = jQuery.makeArray( arguments ), argsLength = args.length, i = 0, tmplItem;
95
+ while ( i < argsLength && !(tmplItem = jQuery.data( args[i++], "tmplItem" ))) {}
96
+ if ( argsLength > 1 ) {
97
+ dmArgs[0] = [jQuery.makeArray( args )];
98
+ }
99
+ if ( tmplItem && cloneIndex ) {
100
+ dmArgs[2] = function( fragClone ) {
101
+ // Handler called by oldManip when rendered template has been inserted into DOM.
102
+ jQuery.tmpl.afterManip( this, fragClone, callback );
103
+ };
104
+ }
105
+ oldManip.apply( this, dmArgs );
106
+ } else {
107
+ oldManip.apply( this, arguments );
108
+ }
109
+ cloneIndex = 0;
110
+ if ( !appendToTmplItems ) {
111
+ jQuery.tmpl.complete( newTmplItems );
112
+ }
113
+ return this;
114
+ }
115
+ });
116
+
117
+ jQuery.extend({
118
+ // Return wrapped set of template items, obtained by rendering template against data.
119
+ tmpl: function( tmpl, data, options, parentItem ) {
120
+ var ret, topLevel = !parentItem;
121
+ if ( topLevel ) {
122
+ // This is a top-level tmpl call (not from a nested template using {{tmpl}})
123
+ parentItem = topTmplItem;
124
+ tmpl = jQuery.template[tmpl] || jQuery.template( null, tmpl );
125
+ wrappedItems = {}; // Any wrapped items will be rebuilt, since this is top level
126
+ } else if ( !tmpl ) {
127
+ // The template item is already associated with DOM - this is a refresh.
128
+ // Re-evaluate rendered template for the parentItem
129
+ tmpl = parentItem.tmpl;
130
+ newTmplItems[parentItem.key] = parentItem;
131
+ parentItem.nodes = [];
132
+ if ( parentItem.wrapped ) {
133
+ updateWrapped( parentItem, parentItem.wrapped );
134
+ }
135
+ // Rebuild, without creating a new template item
136
+ return jQuery( build( parentItem, null, parentItem.tmpl( jQuery, parentItem ) ));
137
+ }
138
+ if ( !tmpl ) {
139
+ return []; // Could throw...
140
+ }
141
+ if ( typeof data === "function" ) {
142
+ data = data.call( parentItem || {} );
143
+ }
144
+ if ( options && options.wrapped ) {
145
+ updateWrapped( options, options.wrapped );
146
+ }
147
+ ret = jQuery.isArray( data ) ?
148
+ jQuery.map( data, function( dataItem ) {
149
+ return dataItem ? newTmplItem( options, parentItem, tmpl, dataItem ) : null;
150
+ }) :
151
+ [ newTmplItem( options, parentItem, tmpl, data ) ];
152
+ return topLevel ? jQuery( build( parentItem, null, ret ) ) : ret;
153
+ },
154
+
155
+ // Return rendered template item for an element.
156
+ tmplItem: function( elem ) {
157
+ var tmplItem;
158
+ if ( elem instanceof jQuery ) {
159
+ elem = elem[0];
160
+ }
161
+ while ( elem && elem.nodeType === 1 && !(tmplItem = jQuery.data( elem, "tmplItem" )) && (elem = elem.parentNode) ) {}
162
+ return tmplItem || topTmplItem;
163
+ },
164
+
165
+ // Set:
166
+ // Use $.template( name, tmpl ) to cache a named template,
167
+ // where tmpl is a template string, a script element or a jQuery instance wrapping a script element, etc.
168
+ // Use $( "selector" ).template( name ) to provide access by name to a script block template declaration.
169
+
170
+ // Get:
171
+ // Use $.template( name ) to access a cached template.
172
+ // Also $( selectorToScriptBlock ).template(), or $.template( null, templateString )
173
+ // will return the compiled template, without adding a name reference.
174
+ // If templateString includes at least one HTML tag, $.template( templateString ) is equivalent
175
+ // to $.template( null, templateString )
176
+ template: function( name, tmpl ) {
177
+ if (tmpl) {
178
+ // Compile template and associate with name
179
+ if ( typeof tmpl === "string" ) {
180
+ // This is an HTML string being passed directly in.
181
+ tmpl = buildTmplFn( tmpl )
182
+ } else if ( tmpl instanceof jQuery ) {
183
+ tmpl = tmpl[0] || {};
184
+ }
185
+ if ( tmpl.nodeType ) {
186
+ // If this is a template block, use cached copy, or generate tmpl function and cache.
187
+ tmpl = jQuery.data( tmpl, "tmpl" ) || jQuery.data( tmpl, "tmpl", buildTmplFn( tmpl.innerHTML ));
188
+ }
189
+ return typeof name === "string" ? (jQuery.template[name] = tmpl) : tmpl;
190
+ }
191
+ // Return named compiled template
192
+ return name ? (typeof name !== "string" ? jQuery.template( null, name ):
193
+ (jQuery.template[name] ||
194
+ // If not in map, treat as a selector. (If integrated with core, use quickExpr.exec)
195
+ jQuery.template( null, htmlExpr.test( name ) ? name : jQuery( name )))) : null;
196
+ },
197
+
198
+ encode: function( text ) {
199
+ // Do HTML encoding replacing < > & and ' and " by corresponding entities.
200
+ return ("" + text).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;");
201
+ }
202
+ });
203
+
204
+ jQuery.extend( jQuery.tmpl, {
205
+ tag: {
206
+ "tmpl": {
207
+ _default: { $2: "null" },
208
+ open: "if($notnull_1){_=_.concat($item.nest($1,$2));}"
209
+ // tmpl target parameter can be of type function, so use $1, not $1a (so not auto detection of functions)
210
+ // This means that {{tmpl foo}} treats foo as a template (which IS a function).
211
+ // Explicit parens can be used if foo is a function that returns a template: {{tmpl foo()}}.
212
+ },
213
+ "wrap": {
214
+ _default: { $2: "null" },
215
+ open: "$item.calls(_,$1,$2);_=[];",
216
+ close: "call=$item.calls();_=call._.concat($item.wrap(call,_));"
217
+ },
218
+ "each": {
219
+ _default: { $2: "$index, $value" },
220
+ open: "if($notnull_1){$.each($1a,function($2){with(this){",
221
+ close: "}});}"
222
+ },
223
+ "if": {
224
+ open: "if(($notnull_1) && $1a){",
225
+ close: "}"
226
+ },
227
+ "else": {
228
+ _default: { $1: "true" },
229
+ open: "}else if(($notnull_1) && $1a){"
230
+ },
231
+ "html": {
232
+ // Unecoded expression evaluation.
233
+ open: "if($notnull_1){_.push($1a);}"
234
+ },
235
+ "=": {
236
+ // Encoded expression evaluation. Abbreviated form is ${}.
237
+ _default: { $1: "$data" },
238
+ open: "if($notnull_1){_.push($.encode($1a));}"
239
+ },
240
+ "!": {
241
+ // Comment tag. Skipped by parser
242
+ open: ""
243
+ }
244
+ },
245
+
246
+ // This stub can be overridden, e.g. in jquery.tmplPlus for providing rendered events
247
+ complete: function( items ) {
248
+ newTmplItems = {};
249
+ },
250
+
251
+ // Call this from code which overrides domManip, or equivalent
252
+ // Manage cloning/storing template items etc.
253
+ afterManip: function afterManip( elem, fragClone, callback ) {
254
+ // Provides cloned fragment ready for fixup prior to and after insertion into DOM
255
+ var content = fragClone.nodeType === 11 ?
256
+ jQuery.makeArray(fragClone.childNodes) :
257
+ fragClone.nodeType === 1 ? [fragClone] : [];
258
+
259
+ // Return fragment to original caller (e.g. append) for DOM insertion
260
+ callback.call( elem, fragClone );
261
+
262
+ // Fragment has been inserted:- Add inserted nodes to tmplItem data structure. Replace inserted element annotations by jQuery.data.
263
+ storeTmplItems( content );
264
+ cloneIndex++;
265
+ }
266
+ });
267
+
268
+ //========================== Private helper functions, used by code above ==========================
269
+
270
+ function build( tmplItem, nested, content ) {
271
+ // Convert hierarchical content into flat string array
272
+ // and finally return array of fragments ready for DOM insertion
273
+ var frag, ret = content ? jQuery.map( content, function( item ) {
274
+ return (typeof item === "string") ?
275
+ // Insert template item annotations, to be converted to jQuery.data( "tmplItem" ) when elems are inserted into DOM.
276
+ (tmplItem.key ? item.replace( /(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g, "$1 " + tmplItmAtt + "=\"" + tmplItem.key + "\" $2" ) : item) :
277
+ // This is a child template item. Build nested template.
278
+ build( item, tmplItem, item._ctnt );
279
+ }) :
280
+ // If content is not defined, insert tmplItem directly. Not a template item. May be a string, or a string array, e.g. from {{html $item.html()}}.
281
+ tmplItem;
282
+ if ( nested ) {
283
+ return ret;
284
+ }
285
+
286
+ // top-level template
287
+ ret = ret.join("");
288
+
289
+ // Support templates which have initial or final text nodes, or consist only of text
290
+ // Also support HTML entities within the HTML markup.
291
+ ret.replace( /^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/, function( all, before, middle, after) {
292
+ frag = jQuery( middle ).get();
293
+
294
+ storeTmplItems( frag );
295
+ if ( before ) {
296
+ frag = unencode( before ).concat(frag);
297
+ }
298
+ if ( after ) {
299
+ frag = frag.concat(unencode( after ));
300
+ }
301
+ });
302
+ return frag ? frag : unencode( ret );
303
+ }
304
+
305
+ function unencode( text ) {
306
+ // Use createElement, since createTextNode will not render HTML entities correctly
307
+ var el = document.createElement( "div" );
308
+ el.innerHTML = text;
309
+ return jQuery.makeArray(el.childNodes);
310
+ }
311
+
312
+ // Generate a reusable function that will serve to render a template against data
313
+ function buildTmplFn( markup ) {
314
+ return new Function("jQuery","$item",
315
+ "var $=jQuery,call,_=[],$data=$item.data;" +
316
+
317
+ // Introduce the data as local variables using with(){}
318
+ "with($data){_.push('" +
319
+
320
+ // Convert the template into pure JavaScript
321
+ jQuery.trim(markup)
322
+ .replace( /([\\'])/g, "\\$1" )
323
+ .replace( /[\r\t\n]/g, " " )
324
+ .replace( /\$\{([^\}]*)\}/g, "{{= $1}}" )
325
+ .replace( /\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,
326
+ function( all, slash, type, fnargs, target, parens, args ) {
327
+ var tag = jQuery.tmpl.tag[ type ], def, expr, exprAutoFnDetect;
328
+ if ( !tag ) {
329
+ throw "Template command not found: " + type;
330
+ }
331
+ def = tag._default || [];
332
+ if ( parens && !/\w$/.test(target)) {
333
+ target += parens;
334
+ parens = "";
335
+ }
336
+ if ( target ) {
337
+ target = unescape( target );
338
+ args = args ? ("," + unescape( args ) + ")") : (parens ? ")" : "");
339
+ // Support for target being things like a.toLowerCase();
340
+ // In that case don't call with template item as 'this' pointer. Just evaluate...
341
+ expr = parens ? (target.indexOf(".") > -1 ? target + parens : ("(" + target + ").call($item" + args)) : target;
342
+ exprAutoFnDetect = parens ? expr : "(typeof(" + target + ")==='function'?(" + target + ").call($item):(" + target + "))";
343
+ } else {
344
+ exprAutoFnDetect = expr = def.$1 || "null";
345
+ }
346
+ fnargs = unescape( fnargs );
347
+ return "');" +
348
+ tag[ slash ? "close" : "open" ]
349
+ .split( "$notnull_1" ).join( target ? "typeof(" + target + ")!=='undefined' && (" + target + ")!=null" : "true" )
350
+ .split( "$1a" ).join( exprAutoFnDetect )
351
+ .split( "$1" ).join( expr )
352
+ .split( "$2" ).join( fnargs ?
353
+ fnargs.replace( /\s*([^\(]+)\s*(\((.*?)\))?/g, function( all, name, parens, params ) {
354
+ params = params ? ("," + params + ")") : (parens ? ")" : "");
355
+ return params ? ("(" + name + ").call($item" + params) : all;
356
+ })
357
+ : (def.$2||"")
358
+ ) +
359
+ "_.push('";
360
+ }) +
361
+ "');}return _;"
362
+ );
363
+ }
364
+ function updateWrapped( options, wrapped ) {
365
+ // Build the wrapped content.
366
+ options._wrap = build( options, true,
367
+ // Suport imperative scenario in which options.wrapped can be set to a selector or an HTML string.
368
+ jQuery.isArray( wrapped ) ? wrapped : [htmlExpr.test( wrapped ) ? wrapped : jQuery( wrapped ).html()]
369
+ ).join("");
370
+ }
371
+
372
+ function unescape( args ) {
373
+ return args ? args.replace( /\\'/g, "'").replace(/\\\\/g, "\\" ) : null;
374
+ }
375
+ function outerHtml( elem ) {
376
+ var div = document.createElement("div");
377
+ div.appendChild( elem.cloneNode(true) );
378
+ return div.innerHTML;
379
+ }
380
+
381
+ // Store template items in jQuery.data(), ensuring a unique tmplItem data data structure for each rendered template instance.
382
+ function storeTmplItems( content ) {
383
+ var keySuffix = "_" + cloneIndex, elem, elems, newClonedItems = {}, i, l, m;
384
+ for ( i = 0, l = content.length; i < l; i++ ) {
385
+ if ( (elem = content[i]).nodeType !== 1 ) {
386
+ continue;
387
+ }
388
+ elems = elem.getElementsByTagName("*");
389
+ for ( m = elems.length - 1; m >= 0; m-- ) {
390
+ processItemKey( elems[m] );
391
+ }
392
+ processItemKey( elem );
393
+ }
394
+ function processItemKey( el ) {
395
+ var pntKey, pntNode = el, pntItem, tmplItem, key;
396
+ // Ensure that each rendered template inserted into the DOM has its own template item,
397
+ if ( (key = el.getAttribute( tmplItmAtt ))) {
398
+ while ( pntNode.parentNode && (pntNode = pntNode.parentNode).nodeType === 1 && !(pntKey = pntNode.getAttribute( tmplItmAtt ))) { }
399
+ if ( pntKey !== key ) {
400
+ // The next ancestor with a _tmplitem expando is on a different key than this one.
401
+ // So this is a top-level element within this template item
402
+ // Set pntNode to the key of the parentNode, or to 0 if pntNode.parentNode is null, or pntNode is a fragment.
403
+ pntNode = pntNode.parentNode ? (pntNode.nodeType === 11 ? 0 : (pntNode.getAttribute( tmplItmAtt ) || 0)) : 0;
404
+ if ( !(tmplItem = newTmplItems[key]) ) {
405
+ // The item is for wrapped content, and was copied from the temporary parent wrappedItem.
406
+ tmplItem = wrappedItems[key];
407
+ tmplItem = newTmplItem( tmplItem, newTmplItems[pntNode]||wrappedItems[pntNode], null, true );
408
+ tmplItem.key = ++itemKey;
409
+ newTmplItems[itemKey] = tmplItem;
410
+ }
411
+ if ( cloneIndex ) {
412
+ cloneTmplItem( key );
413
+ }
414
+ }
415
+ el.removeAttribute( tmplItmAtt );
416
+ } else if ( cloneIndex && (tmplItem = jQuery.data( el, "tmplItem" )) ) {
417
+ // This was a rendered element, cloned during append or appendTo etc.
418
+ // TmplItem stored in jQuery data has already been cloned in cloneCopyEvent. We must replace it with a fresh cloned tmplItem.
419
+ cloneTmplItem( tmplItem.key );
420
+ newTmplItems[tmplItem.key] = tmplItem;
421
+ pntNode = jQuery.data( el.parentNode, "tmplItem" );
422
+ pntNode = pntNode ? pntNode.key : 0;
423
+ }
424
+ if ( tmplItem ) {
425
+ pntItem = tmplItem;
426
+ // Find the template item of the parent element.
427
+ // (Using !=, not !==, since pntItem.key is number, and pntNode may be a string)
428
+ while ( pntItem && pntItem.key != pntNode ) {
429
+ // Add this element as a top-level node for this rendered template item, as well as for any
430
+ // ancestor items between this item and the item of its parent element
431
+ pntItem.nodes.push( el );
432
+ pntItem = pntItem.parent;
433
+ }
434
+ // Delete content built during rendering - reduce API surface area and memory use, and avoid exposing of stale data after rendering...
435
+ delete tmplItem._ctnt;
436
+ delete tmplItem._wrap;
437
+ // Store template item as jQuery data on the element
438
+ jQuery.data( el, "tmplItem", tmplItem );
439
+ }
440
+ function cloneTmplItem( key ) {
441
+ key = key + keySuffix;
442
+ tmplItem = newClonedItems[key] =
443
+ (newClonedItems[key] || newTmplItem( tmplItem, newTmplItems[tmplItem.parent.key + keySuffix] || tmplItem.parent, null, true ));
444
+ }
445
+ }
446
+ }
447
+
448
+ //---- Helper functions for template item ----
449
+
450
+ function tiCalls( content, tmpl, data, options ) {
451
+ if ( !content ) {
452
+ return stack.pop();
453
+ }
454
+ stack.push({ _: content, tmpl: tmpl, item:this, data: data, options: options });
455
+ }
456
+
457
+ function tiNest( tmpl, data, options ) {
458
+ // nested template, using {{tmpl}} tag
459
+ return jQuery.tmpl( jQuery.template( tmpl ), data, options, this );
460
+ }
461
+
462
+ function tiWrap( call, wrapped ) {
463
+ // nested template, using {{wrap}} tag
464
+ var options = call.options || {};
465
+ options.wrapped = wrapped;
466
+ // Apply the template, which may incorporate wrapped content,
467
+ return jQuery.tmpl( jQuery.template( call.tmpl ), call.data, options, call.item );
468
+ }
469
+
470
+ function tiHtml( filter, textOnly ) {
471
+ var wrapped = this._wrap;
472
+ return jQuery.map(
473
+ jQuery( jQuery.isArray( wrapped ) ? wrapped.join("") : wrapped ).filter( filter || "*" ),
474
+ function(e) {
475
+ return textOnly ?
476
+ e.innerText || e.textContent :
477
+ e.outerHTML || outerHtml(e);
478
+ });
479
+ }
480
+
481
+ function tiUpdate() {
482
+ var coll = this.nodes;
483
+ jQuery.tmpl( null, null, null, this).insertBefore( coll[0] );
484
+ jQuery( coll ).remove();
485
+ }
486
+ })( jQuery );