olelo 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. data/.gitignore +10 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +3 -0
  4. data/README.markdown +104 -0
  5. data/Rakefile +92 -0
  6. data/bin/olelo +5 -0
  7. data/config.ru +86 -0
  8. data/config/aspects.rb +256 -0
  9. data/config/config.yml.default +154 -0
  10. data/config/initializers/00-mime_types.rb +29 -0
  11. data/config/initializers/01-slim.rb +2 -0
  12. data/config/interwiki.yml +11 -0
  13. data/doc/AUTHORS +7 -0
  14. data/doc/LICENSE +22 -0
  15. data/lib/olelo.rb +39 -0
  16. data/lib/olelo/application.rb +294 -0
  17. data/lib/olelo/attributes.rb +285 -0
  18. data/lib/olelo/config.rb +88 -0
  19. data/lib/olelo/extensions.rb +252 -0
  20. data/lib/olelo/helper.rb +290 -0
  21. data/lib/olelo/hooks.rb +142 -0
  22. data/lib/olelo/html_safe.rb +29 -0
  23. data/lib/olelo/initializer.rb +76 -0
  24. data/lib/olelo/locale.rb +63 -0
  25. data/lib/olelo/locale.yml +284 -0
  26. data/lib/olelo/menu.rb +101 -0
  27. data/lib/olelo/middleware/blacklist.rb +25 -0
  28. data/lib/olelo/middleware/degrade_mime_type.rb +19 -0
  29. data/lib/olelo/middleware/flash.rb +97 -0
  30. data/lib/olelo/middleware/force_encoding.rb +41 -0
  31. data/lib/olelo/page.rb +266 -0
  32. data/lib/olelo/patch.rb +311 -0
  33. data/lib/olelo/plugin.rb +188 -0
  34. data/lib/olelo/repository.rb +225 -0
  35. data/lib/olelo/routing.rb +223 -0
  36. data/lib/olelo/templates.rb +30 -0
  37. data/lib/olelo/user.rb +132 -0
  38. data/lib/olelo/util.rb +233 -0
  39. data/lib/olelo/version.rb +3 -0
  40. data/lib/olelo/virtualfs.rb +161 -0
  41. data/lib/rack/olelo_patches.rb +33 -0
  42. data/lib/rack/relative_redirect.rb +44 -0
  43. data/lib/rack/static_cache.rb +93 -0
  44. data/lib/yard/addons.rb +1 -0
  45. data/lib/yard/addons/hook_handler.rb +25 -0
  46. data/lib/yard/addons/override_tag.rb +14 -0
  47. data/lib/yard/addons/route_handler.rb +33 -0
  48. data/lib/yard/addons/sanitize_anchor.rb +16 -0
  49. data/olelo.gemspec +31 -0
  50. data/plugins/aspects/changelog.rb +45 -0
  51. data/plugins/aspects/documentbrowser.rb +57 -0
  52. data/plugins/aspects/download.rb +11 -0
  53. data/plugins/aspects/highlight.rb +8 -0
  54. data/plugins/aspects/image.rb +41 -0
  55. data/plugins/aspects/imageinfo.rb +64 -0
  56. data/plugins/aspects/locale.yml +60 -0
  57. data/plugins/aspects/main.rb +199 -0
  58. data/plugins/aspects/pageinfo.rb +37 -0
  59. data/plugins/aspects/source.rb +6 -0
  60. data/plugins/aspects/subpages.rb +44 -0
  61. data/plugins/aspects/text.rb +9 -0
  62. data/plugins/blog/blog.css +1 -0
  63. data/plugins/blog/blog.scss +37 -0
  64. data/plugins/blog/locale.yml +12 -0
  65. data/plugins/blog/main.rb +85 -0
  66. data/plugins/editor/locale.yml +18 -0
  67. data/plugins/editor/markup/main.rb +3 -0
  68. data/plugins/editor/markup/script.js +10 -0
  69. data/plugins/editor/markup/script/00-jquery.textselection.js +267 -0
  70. data/plugins/editor/markup/script/01-olelo.markupeditor.js +116 -0
  71. data/plugins/editor/markup/script/init.js +10 -0
  72. data/plugins/editor/preview.rb +52 -0
  73. data/plugins/editor/recaptcha.rb +56 -0
  74. data/plugins/filters/creole.rb +37 -0
  75. data/plugins/filters/disposition.rb +9 -0
  76. data/plugins/filters/editsection.rb +67 -0
  77. data/plugins/filters/fix_img_tag.rb +16 -0
  78. data/plugins/filters/html_wrapper.rb +12 -0
  79. data/plugins/filters/interwiki.rb +19 -0
  80. data/plugins/filters/link_classifier.rb +26 -0
  81. data/plugins/filters/locale.yml +15 -0
  82. data/plugins/filters/main.rb +202 -0
  83. data/plugins/filters/markdown_nowiki.rb +15 -0
  84. data/plugins/filters/numbering.xsl +93 -0
  85. data/plugins/filters/orgmode.rb +6 -0
  86. data/plugins/filters/rubypants.rb +6 -0
  87. data/plugins/filters/s5/main.rb +32 -0
  88. data/plugins/filters/s5/s5.xsl +118 -0
  89. data/plugins/filters/tilt.rb +17 -0
  90. data/plugins/filters/toc.rb +50 -0
  91. data/plugins/filters/xhtml2latex.xsl +232 -0
  92. data/plugins/filters/xslt.rb +22 -0
  93. data/plugins/gallery/gallery.css +1 -0
  94. data/plugins/gallery/gallery.scss +28 -0
  95. data/plugins/gallery/main.rb +34 -0
  96. data/plugins/misc/fancybox/images/blank.gif +0 -0
  97. data/plugins/misc/fancybox/images/fancy_close.png +0 -0
  98. data/plugins/misc/fancybox/images/fancy_loading.png +0 -0
  99. data/plugins/misc/fancybox/images/fancy_nav_left.png +0 -0
  100. data/plugins/misc/fancybox/images/fancy_nav_right.png +0 -0
  101. data/plugins/misc/fancybox/images/fancy_shadow_e.png +0 -0
  102. data/plugins/misc/fancybox/images/fancy_shadow_n.png +0 -0
  103. data/plugins/misc/fancybox/images/fancy_shadow_ne.png +0 -0
  104. data/plugins/misc/fancybox/images/fancy_shadow_nw.png +0 -0
  105. data/plugins/misc/fancybox/images/fancy_shadow_s.png +0 -0
  106. data/plugins/misc/fancybox/images/fancy_shadow_se.png +0 -0
  107. data/plugins/misc/fancybox/images/fancy_shadow_sw.png +0 -0
  108. data/plugins/misc/fancybox/images/fancy_shadow_w.png +0 -0
  109. data/plugins/misc/fancybox/images/fancy_title_left.png +0 -0
  110. data/plugins/misc/fancybox/images/fancy_title_main.png +0 -0
  111. data/plugins/misc/fancybox/images/fancy_title_over.png +0 -0
  112. data/plugins/misc/fancybox/images/fancy_title_right.png +0 -0
  113. data/plugins/misc/fancybox/images/fancybox-x.png +0 -0
  114. data/plugins/misc/fancybox/images/fancybox-y.png +0 -0
  115. data/plugins/misc/fancybox/images/fancybox.png +0 -0
  116. data/plugins/misc/fancybox/jquery.fancybox.css +1 -0
  117. data/plugins/misc/fancybox/jquery.fancybox.scss +323 -0
  118. data/plugins/misc/fancybox/main.rb +4 -0
  119. data/plugins/misc/fancybox/script.js +37 -0
  120. data/plugins/misc/fancybox/script/00-jquery.mousewheel.js +84 -0
  121. data/plugins/misc/fancybox/script/01-jquery.easing.js +205 -0
  122. data/plugins/misc/fancybox/script/02-jquery.fancybox.js +1156 -0
  123. data/plugins/misc/fancybox/script/init.js +18 -0
  124. data/plugins/misc/system.rb +192 -0
  125. data/plugins/misc/variables.rb +29 -0
  126. data/plugins/misc/webdav.rb +45 -0
  127. data/plugins/repositories/git_grep.rb +69 -0
  128. data/plugins/repositories/gitrb_repository.rb +204 -0
  129. data/plugins/repositories/locale.yml +12 -0
  130. data/plugins/repositories/rugged_repository.rb +454 -0
  131. data/plugins/security/acl.rb +57 -0
  132. data/plugins/security/basic_auth.rb +21 -0
  133. data/plugins/security/locale.yml +21 -0
  134. data/plugins/security/persistent_login.rb +32 -0
  135. data/plugins/security/portal.rb +28 -0
  136. data/plugins/security/private_wiki.rb +24 -0
  137. data/plugins/security/readonly_wiki.rb +25 -0
  138. data/plugins/security/stack.rb +20 -0
  139. data/plugins/security/yamlfile.rb +66 -0
  140. data/plugins/tags/code.rb +6 -0
  141. data/plugins/tags/footnotes.rb +35 -0
  142. data/plugins/tags/gist-embed.css +123 -0
  143. data/plugins/tags/gist.rb +13 -0
  144. data/plugins/tags/html.rb +57 -0
  145. data/plugins/tags/include.rb +20 -0
  146. data/plugins/tags/main.rb +353 -0
  147. data/plugins/tags/math.rb +117 -0
  148. data/plugins/tags/scripting.rb +64 -0
  149. data/plugins/tags/sort.rb +7 -0
  150. data/plugins/tags/tabs.rb +20 -0
  151. data/plugins/treeview/images/collapsed.png +0 -0
  152. data/plugins/treeview/images/expanded.png +0 -0
  153. data/plugins/treeview/images/menu.png +0 -0
  154. data/plugins/treeview/images/tree.png +0 -0
  155. data/plugins/treeview/images/wait.gif +0 -0
  156. data/plugins/treeview/main.rb +16 -0
  157. data/plugins/treeview/script.js +5 -0
  158. data/plugins/treeview/script/00-jquery.treeview.js +164 -0
  159. data/plugins/treeview/script/init.js +25 -0
  160. data/plugins/treeview/treeview.css +1 -0
  161. data/plugins/treeview/treeview.scss +113 -0
  162. data/plugins/utils/assets.rb +74 -0
  163. data/plugins/utils/cache.rb +53 -0
  164. data/plugins/utils/image_magick.rb +34 -0
  165. data/plugins/utils/pygments.css +1 -0
  166. data/plugins/utils/pygments.rb +50 -0
  167. data/plugins/utils/pygments.scss +83 -0
  168. data/plugins/utils/semaphore.rb +50 -0
  169. data/plugins/utils/shell.rb +45 -0
  170. data/plugins/utils/store.rb +315 -0
  171. data/plugins/utils/worker.rb +36 -0
  172. data/plugins/utils/xml.rb +29 -0
  173. data/static/images/favicon.png +0 -0
  174. data/static/script.js +267 -0
  175. data/static/script/00-json2.js +486 -0
  176. data/static/script/01-jstorage.js +217 -0
  177. data/static/script/02-jquery.js +9440 -0
  178. data/static/script/03-jquery.ui.core.js +337 -0
  179. data/static/script/04-jquery.ui.widget.js +502 -0
  180. data/static/script/05-jquery.ui.position.js +517 -0
  181. data/static/script/06-jquery.ui.menu.js +609 -0
  182. data/static/script/07-jquery.ui.autocomplete.js +601 -0
  183. data/static/script/08-olelo.i18n.js +37 -0
  184. data/static/script/09-olelo.unsaved.js +68 -0
  185. data/static/script/10-olelo.historytable.js +40 -0
  186. data/static/script/11-olelo.pagination.js +18 -0
  187. data/static/script/13-olelo.tabwidget.js +57 -0
  188. data/static/script/14-olelo.timeago.js +70 -0
  189. data/static/script/15-olelo.underliner.js +31 -0
  190. data/static/script/16-olelo.ui.combobox.js +32 -0
  191. data/static/script/init.js +48 -0
  192. data/static/themes/atlantis/constants.scss +15 -0
  193. data/static/themes/atlantis/iehacks.scss +38 -0
  194. data/static/themes/atlantis/images/actions/delete.png +0 -0
  195. data/static/themes/atlantis/images/actions/edit.png +0 -0
  196. data/static/themes/atlantis/images/actions/history.png +0 -0
  197. data/static/themes/atlantis/images/actions/home.png +0 -0
  198. data/static/themes/atlantis/images/actions/move.png +0 -0
  199. data/static/themes/atlantis/images/actions/new.png +0 -0
  200. data/static/themes/atlantis/images/actions/page.png +0 -0
  201. data/static/themes/atlantis/images/bg/button.png +0 -0
  202. data/static/themes/atlantis/images/bg/container.png +0 -0
  203. data/static/themes/atlantis/images/bg/content.png +0 -0
  204. data/static/themes/atlantis/images/bg/footer.png +0 -0
  205. data/static/themes/atlantis/images/bg/header.jpg +0 -0
  206. data/static/themes/atlantis/images/bg/header.orig.jpg +0 -0
  207. data/static/themes/atlantis/images/bg/header_gray.jpg +0 -0
  208. data/static/themes/atlantis/images/bug.png +0 -0
  209. data/static/themes/atlantis/images/filetypes/7z.png +0 -0
  210. data/static/themes/atlantis/images/filetypes/_archive.png +0 -0
  211. data/static/themes/atlantis/images/filetypes/_audio.png +0 -0
  212. data/static/themes/atlantis/images/filetypes/_code.png +0 -0
  213. data/static/themes/atlantis/images/filetypes/_linux.png +0 -0
  214. data/static/themes/atlantis/images/filetypes/_picture.png +0 -0
  215. data/static/themes/atlantis/images/filetypes/_video.png +0 -0
  216. data/static/themes/atlantis/images/filetypes/bz2.png +0 -0
  217. data/static/themes/atlantis/images/filetypes/doc.png +0 -0
  218. data/static/themes/atlantis/images/filetypes/flac.png +0 -0
  219. data/static/themes/atlantis/images/filetypes/gz.png +0 -0
  220. data/static/themes/atlantis/images/filetypes/html.png +0 -0
  221. data/static/themes/atlantis/images/filetypes/java.png +0 -0
  222. data/static/themes/atlantis/images/filetypes/jpg.png +0 -0
  223. data/static/themes/atlantis/images/filetypes/midi.png +0 -0
  224. data/static/themes/atlantis/images/filetypes/mp3.png +0 -0
  225. data/static/themes/atlantis/images/filetypes/ogg.png +0 -0
  226. data/static/themes/atlantis/images/filetypes/pdf.png +0 -0
  227. data/static/themes/atlantis/images/filetypes/php.png +0 -0
  228. data/static/themes/atlantis/images/filetypes/png.png +0 -0
  229. data/static/themes/atlantis/images/filetypes/ppt.png +0 -0
  230. data/static/themes/atlantis/images/filetypes/psd.png +0 -0
  231. data/static/themes/atlantis/images/filetypes/rar.png +0 -0
  232. data/static/themes/atlantis/images/filetypes/rb.png +0 -0
  233. data/static/themes/atlantis/images/filetypes/sh.png +0 -0
  234. data/static/themes/atlantis/images/filetypes/tar.png +0 -0
  235. data/static/themes/atlantis/images/filetypes/txt.png +0 -0
  236. data/static/themes/atlantis/images/filetypes/wma.png +0 -0
  237. data/static/themes/atlantis/images/filetypes/xls.png +0 -0
  238. data/static/themes/atlantis/images/filetypes/zip.png +0 -0
  239. data/static/themes/atlantis/images/folder.png +0 -0
  240. data/static/themes/atlantis/images/folder_open.png +0 -0
  241. data/static/themes/atlantis/images/loading.gif +0 -0
  242. data/static/themes/atlantis/images/loading.xcf +0 -0
  243. data/static/themes/atlantis/images/not_found.png +0 -0
  244. data/static/themes/atlantis/images/page.png +0 -0
  245. data/static/themes/atlantis/images/search.png +0 -0
  246. data/static/themes/atlantis/layout.scss +115 -0
  247. data/static/themes/atlantis/menu.scss +99 -0
  248. data/static/themes/atlantis/print.scss +129 -0
  249. data/static/themes/atlantis/screen.scss +495 -0
  250. data/static/themes/atlantis/style.css +3 -0
  251. data/static/themes/lib/autocomplete.scss +39 -0
  252. data/static/themes/lib/headlines.scss +10 -0
  253. data/static/themes/lib/horizontal-list.scss +31 -0
  254. data/static/themes/lib/patch.scss +88 -0
  255. data/static/themes/lib/reset.scss +114 -0
  256. data/static/themes/lib/rounded.scss +46 -0
  257. data/static/themes/lib/shadow.scss +14 -0
  258. data/test/config_test.rb +28 -0
  259. data/test/factory_test.rb +29 -0
  260. data/test/hash_extensions_test.rb +16 -0
  261. data/test/helper.rb +38 -0
  262. data/test/hooks_test.rb +85 -0
  263. data/test/object_extensions_test.rb +20 -0
  264. data/test/page_test.rb +168 -0
  265. data/test/request_test.rb +166 -0
  266. data/test/string_extensions_test.rb +32 -0
  267. data/test/templates_test.rb +39 -0
  268. data/test/util_test.rb +71 -0
  269. data/views/changes.slim +22 -0
  270. data/views/compare.slim +8 -0
  271. data/views/delete.slim +9 -0
  272. data/views/deleted.slim +2 -0
  273. data/views/edit.slim +65 -0
  274. data/views/error.slim +6 -0
  275. data/views/history.slim +20 -0
  276. data/views/layout.slim +38 -0
  277. data/views/login.slim +37 -0
  278. data/views/move.slim +10 -0
  279. data/views/not_found.slim +6 -0
  280. data/views/profile.slim +26 -0
  281. data/views/show.slim +9 -0
  282. metadata +488 -0
@@ -0,0 +1,609 @@
1
+ /*!
2
+ * jQuery UI Menu 1.9.0
3
+ * http://jqueryui.com
4
+ *
5
+ * Copyright 2012 jQuery Foundation and other contributors
6
+ * Released under the MIT license.
7
+ * http://jquery.org/license
8
+ *
9
+ * http://api.jqueryui.com/menu/
10
+ *
11
+ * Depends:
12
+ * jquery.ui.core.js
13
+ * jquery.ui.widget.js
14
+ * jquery.ui.position.js
15
+ */
16
+ (function( $, undefined ) {
17
+
18
+ var mouseHandled = false;
19
+
20
+ $.widget( "ui.menu", {
21
+ version: "1.9.0",
22
+ defaultElement: "<ul>",
23
+ delay: 300,
24
+ options: {
25
+ icons: {
26
+ submenu: "ui-icon-carat-1-e"
27
+ },
28
+ menus: "ul",
29
+ position: {
30
+ my: "left top",
31
+ at: "right top"
32
+ },
33
+ role: "menu",
34
+
35
+ // callbacks
36
+ blur: null,
37
+ focus: null,
38
+ select: null
39
+ },
40
+
41
+ _create: function() {
42
+ this.activeMenu = this.element;
43
+ this.element
44
+ .uniqueId()
45
+ .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
46
+ .toggleClass( "ui-menu-icons", !!this.element.find( ".ui-icon" ).length )
47
+ .attr({
48
+ role: this.options.role,
49
+ tabIndex: 0
50
+ })
51
+ // need to catch all clicks on disabled menu
52
+ // not possible through _on
53
+ .bind( "click" + this.eventNamespace, $.proxy(function( event ) {
54
+ if ( this.options.disabled ) {
55
+ event.preventDefault();
56
+ }
57
+ }, this ));
58
+
59
+ if ( this.options.disabled ) {
60
+ this.element
61
+ .addClass( "ui-state-disabled" )
62
+ .attr( "aria-disabled", "true" );
63
+ }
64
+
65
+ this._on({
66
+ // Prevent focus from sticking to links inside menu after clicking
67
+ // them (focus should always stay on UL during navigation).
68
+ "mousedown .ui-menu-item > a": function( event ) {
69
+ event.preventDefault();
70
+ },
71
+ "click .ui-state-disabled > a": function( event ) {
72
+ event.preventDefault();
73
+ },
74
+ "click .ui-menu-item:has(a)": function( event ) {
75
+ var target = $( event.target ).closest( ".ui-menu-item" );
76
+ if ( !mouseHandled && target.not( ".ui-state-disabled" ).length ) {
77
+ mouseHandled = true;
78
+
79
+ this.select( event );
80
+ // Open submenu on click
81
+ if ( target.has( ".ui-menu" ).length ) {
82
+ this.expand( event );
83
+ } else if ( !this.element.is( ":focus" ) ) {
84
+ // Redirect focus to the menu
85
+ this.element.trigger( "focus", [ true ] );
86
+
87
+ // If the active item is on the top level, let it stay active.
88
+ // Otherwise, blur the active item since it is no longer visible.
89
+ if ( this.active && this.active.parents( ".ui-menu" ).length === 1 ) {
90
+ clearTimeout( this.timer );
91
+ }
92
+ }
93
+ }
94
+ },
95
+ "mouseenter .ui-menu-item": function( event ) {
96
+ var target = $( event.currentTarget );
97
+ // Remove ui-state-active class from siblings of the newly focused menu item
98
+ // to avoid a jump caused by adjacent elements both having a class with a border
99
+ target.siblings().children( ".ui-state-active" ).removeClass( "ui-state-active" );
100
+ this.focus( event, target );
101
+ },
102
+ mouseleave: "collapseAll",
103
+ "mouseleave .ui-menu": "collapseAll",
104
+ focus: function( event, keepActiveItem ) {
105
+ // If there's already an active item, keep it active
106
+ // If not, activate the first item
107
+ var item = this.active || this.element.children( ".ui-menu-item" ).eq( 0 );
108
+
109
+ if ( !keepActiveItem ) {
110
+ this.focus( event, item );
111
+ }
112
+ },
113
+ blur: function( event ) {
114
+ this._delay(function() {
115
+ if ( !$.contains( this.element[0], this.document[0].activeElement ) ) {
116
+ this.collapseAll( event );
117
+ }
118
+ });
119
+ },
120
+ keydown: "_keydown"
121
+ });
122
+
123
+ this.refresh();
124
+
125
+ // Clicks outside of a menu collapse any open menus
126
+ this._on( this.document, {
127
+ click: function( event ) {
128
+ if ( !$( event.target ).closest( ".ui-menu" ).length ) {
129
+ this.collapseAll( event );
130
+ }
131
+
132
+ // Reset the mouseHandled flag
133
+ mouseHandled = false;
134
+ }
135
+ });
136
+ },
137
+
138
+ _destroy: function() {
139
+ // Destroy (sub)menus
140
+ this.element
141
+ .removeAttr( "aria-activedescendant" )
142
+ .find( ".ui-menu" ).andSelf()
143
+ .removeClass( "ui-menu ui-widget ui-widget-content ui-corner-all ui-menu-icons" )
144
+ .removeAttr( "role" )
145
+ .removeAttr( "tabIndex" )
146
+ .removeAttr( "aria-labelledby" )
147
+ .removeAttr( "aria-expanded" )
148
+ .removeAttr( "aria-hidden" )
149
+ .removeAttr( "aria-disabled" )
150
+ .removeUniqueId()
151
+ .show();
152
+
153
+ // Destroy menu items
154
+ this.element.find( ".ui-menu-item" )
155
+ .removeClass( "ui-menu-item" )
156
+ .removeAttr( "role" )
157
+ .removeAttr( "aria-disabled" )
158
+ .children( "a" )
159
+ .removeUniqueId()
160
+ .removeClass( "ui-corner-all ui-state-hover" )
161
+ .removeAttr( "tabIndex" )
162
+ .removeAttr( "role" )
163
+ .removeAttr( "aria-haspopup" )
164
+ .children().each( function() {
165
+ var elem = $( this );
166
+ if ( elem.data( "ui-menu-submenu-carat" ) ) {
167
+ elem.remove();
168
+ }
169
+ });
170
+
171
+ // Destroy menu dividers
172
+ this.element.find( ".ui-menu-divider" ).removeClass( "ui-menu-divider ui-widget-content" );
173
+ },
174
+
175
+ _keydown: function( event ) {
176
+ var match, prev, character, skip, regex,
177
+ preventDefault = true;
178
+
179
+ function escape( value ) {
180
+ return value.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" );
181
+ }
182
+
183
+ switch ( event.keyCode ) {
184
+ case $.ui.keyCode.PAGE_UP:
185
+ this.previousPage( event );
186
+ break;
187
+ case $.ui.keyCode.PAGE_DOWN:
188
+ this.nextPage( event );
189
+ break;
190
+ case $.ui.keyCode.HOME:
191
+ this._move( "first", "first", event );
192
+ break;
193
+ case $.ui.keyCode.END:
194
+ this._move( "last", "last", event );
195
+ break;
196
+ case $.ui.keyCode.UP:
197
+ this.previous( event );
198
+ break;
199
+ case $.ui.keyCode.DOWN:
200
+ this.next( event );
201
+ break;
202
+ case $.ui.keyCode.LEFT:
203
+ this.collapse( event );
204
+ break;
205
+ case $.ui.keyCode.RIGHT:
206
+ if ( this.active && !this.active.is( ".ui-state-disabled" ) ) {
207
+ this.expand( event );
208
+ }
209
+ break;
210
+ case $.ui.keyCode.ENTER:
211
+ case $.ui.keyCode.SPACE:
212
+ this._activate( event );
213
+ break;
214
+ case $.ui.keyCode.ESCAPE:
215
+ this.collapse( event );
216
+ break;
217
+ default:
218
+ preventDefault = false;
219
+ prev = this.previousFilter || "";
220
+ character = String.fromCharCode( event.keyCode );
221
+ skip = false;
222
+
223
+ clearTimeout( this.filterTimer );
224
+
225
+ if ( character === prev ) {
226
+ skip = true;
227
+ } else {
228
+ character = prev + character;
229
+ }
230
+
231
+ regex = new RegExp( "^" + escape( character ), "i" );
232
+ match = this.activeMenu.children( ".ui-menu-item" ).filter(function() {
233
+ return regex.test( $( this ).children( "a" ).text() );
234
+ });
235
+ match = skip && match.index( this.active.next() ) !== -1 ?
236
+ this.active.nextAll( ".ui-menu-item" ) :
237
+ match;
238
+
239
+ // If no matches on the current filter, reset to the last character pressed
240
+ // to move down the menu to the first item that starts with that character
241
+ if ( !match.length ) {
242
+ character = String.fromCharCode( event.keyCode );
243
+ regex = new RegExp( "^" + escape( character ), "i" );
244
+ match = this.activeMenu.children( ".ui-menu-item" ).filter(function() {
245
+ return regex.test( $( this ).children( "a" ).text() );
246
+ });
247
+ }
248
+
249
+ if ( match.length ) {
250
+ this.focus( event, match );
251
+ if ( match.length > 1 ) {
252
+ this.previousFilter = character;
253
+ this.filterTimer = this._delay(function() {
254
+ delete this.previousFilter;
255
+ }, 1000 );
256
+ } else {
257
+ delete this.previousFilter;
258
+ }
259
+ } else {
260
+ delete this.previousFilter;
261
+ }
262
+ }
263
+
264
+ if ( preventDefault ) {
265
+ event.preventDefault();
266
+ }
267
+ },
268
+
269
+ _activate: function( event ) {
270
+ if ( !this.active.is( ".ui-state-disabled" ) ) {
271
+ if ( this.active.children( "a[aria-haspopup='true']" ).length ) {
272
+ this.expand( event );
273
+ } else {
274
+ this.select( event );
275
+ }
276
+ }
277
+ },
278
+
279
+ refresh: function() {
280
+ // Initialize nested menus
281
+ var menus,
282
+ icon = this.options.icons.submenu,
283
+ submenus = this.element.find( this.options.menus + ":not(.ui-menu)" )
284
+ .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
285
+ .hide()
286
+ .attr({
287
+ role: this.options.role,
288
+ "aria-hidden": "true",
289
+ "aria-expanded": "false"
290
+ });
291
+
292
+ // Don't refresh list items that are already adapted
293
+ menus = submenus.add( this.element );
294
+
295
+ menus.children( ":not(.ui-menu-item):has(a)" )
296
+ .addClass( "ui-menu-item" )
297
+ .attr( "role", "presentation" )
298
+ .children( "a" )
299
+ .uniqueId()
300
+ .addClass( "ui-corner-all" )
301
+ .attr({
302
+ tabIndex: -1,
303
+ role: this._itemRole()
304
+ });
305
+
306
+ // Initialize unlinked menu-items containing spaces and/or dashes only as dividers
307
+ menus.children( ":not(.ui-menu-item)" ).each(function() {
308
+ var item = $( this );
309
+ // hyphen, em dash, en dash
310
+ if ( !/[^\-—–\s]/.test( item.text() ) ) {
311
+ item.addClass( "ui-widget-content ui-menu-divider" );
312
+ }
313
+ });
314
+
315
+ // Add aria-disabled attribute to any disabled menu item
316
+ menus.children( ".ui-state-disabled" ).attr( "aria-disabled", "true" );
317
+
318
+ submenus.each(function() {
319
+ var menu = $( this ),
320
+ item = menu.prev( "a" ),
321
+ submenuCarat = $( "<span>" )
322
+ .addClass( "ui-menu-icon ui-icon " + icon )
323
+ .data( "ui-menu-submenu-carat", true );
324
+
325
+ item
326
+ .attr( "aria-haspopup", "true" )
327
+ .prepend( submenuCarat );
328
+ menu.attr( "aria-labelledby", item.attr( "id" ) );
329
+ });
330
+
331
+ // If the active item has been removed, blur the menu
332
+ if ( this.active && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
333
+ this.blur();
334
+ }
335
+ },
336
+
337
+ _itemRole: function() {
338
+ return {
339
+ menu: "menuitem",
340
+ listbox: "option"
341
+ }[ this.options.role ];
342
+ },
343
+
344
+ focus: function( event, item ) {
345
+ var nested, focused;
346
+ this.blur( event, event && event.type === "focus" );
347
+
348
+ this._scrollIntoView( item );
349
+
350
+ this.active = item.first();
351
+ focused = this.active.children( "a" ).addClass( "ui-state-focus" );
352
+ // Only update aria-activedescendant if there's a role
353
+ // otherwise we assume focus is managed elsewhere
354
+ if ( this.options.role ) {
355
+ this.element.attr( "aria-activedescendant", focused.attr( "id" ) );
356
+ }
357
+
358
+ // Highlight active parent menu item, if any
359
+ this.active
360
+ .parent()
361
+ .closest( ".ui-menu-item" )
362
+ .children( "a:first" )
363
+ .addClass( "ui-state-active" );
364
+
365
+ if ( event && event.type === "keydown" ) {
366
+ this._close();
367
+ } else {
368
+ this.timer = this._delay(function() {
369
+ this._close();
370
+ }, this.delay );
371
+ }
372
+
373
+ nested = item.children( ".ui-menu" );
374
+ if ( nested.length && ( /^mouse/.test( event.type ) ) ) {
375
+ this._startOpening(nested);
376
+ }
377
+ this.activeMenu = item.parent();
378
+
379
+ this._trigger( "focus", event, { item: item } );
380
+ },
381
+
382
+ _scrollIntoView: function( item ) {
383
+ var borderTop, paddingTop, offset, scroll, elementHeight, itemHeight;
384
+ if ( this._hasScroll() ) {
385
+ borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0;
386
+ paddingTop = parseFloat( $.css( this.activeMenu[0], "paddingTop" ) ) || 0;
387
+ offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop;
388
+ scroll = this.activeMenu.scrollTop();
389
+ elementHeight = this.activeMenu.height();
390
+ itemHeight = item.height();
391
+
392
+ if ( offset < 0 ) {
393
+ this.activeMenu.scrollTop( scroll + offset );
394
+ } else if ( offset + itemHeight > elementHeight ) {
395
+ this.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight );
396
+ }
397
+ }
398
+ },
399
+
400
+ blur: function( event, fromFocus ) {
401
+ if ( !fromFocus ) {
402
+ clearTimeout( this.timer );
403
+ }
404
+
405
+ if ( !this.active ) {
406
+ return;
407
+ }
408
+
409
+ this.active.children( "a" ).removeClass( "ui-state-focus" );
410
+ this.active = null;
411
+
412
+ this._trigger( "blur", event, { item: this.active } );
413
+ },
414
+
415
+ _startOpening: function( submenu ) {
416
+ clearTimeout( this.timer );
417
+
418
+ // Don't open if already open fixes a Firefox bug that caused a .5 pixel
419
+ // shift in the submenu position when mousing over the carat icon
420
+ if ( submenu.attr( "aria-hidden" ) !== "true" ) {
421
+ return;
422
+ }
423
+
424
+ this.timer = this._delay(function() {
425
+ this._close();
426
+ this._open( submenu );
427
+ }, this.delay );
428
+ },
429
+
430
+ _open: function( submenu ) {
431
+ var position = $.extend({
432
+ of: this.active
433
+ }, this.options.position );
434
+
435
+ clearTimeout( this.timer );
436
+ this.element.find( ".ui-menu" ).not( submenu.parents( ".ui-menu" ) )
437
+ .hide()
438
+ .attr( "aria-hidden", "true" );
439
+
440
+ submenu
441
+ .show()
442
+ .removeAttr( "aria-hidden" )
443
+ .attr( "aria-expanded", "true" )
444
+ .position( position );
445
+ },
446
+
447
+ collapseAll: function( event, all ) {
448
+ clearTimeout( this.timer );
449
+ this.timer = this._delay(function() {
450
+ // If we were passed an event, look for the submenu that contains the event
451
+ var currentMenu = all ? this.element :
452
+ $( event && event.target ).closest( this.element.find( ".ui-menu" ) );
453
+
454
+ // If we found no valid submenu ancestor, use the main menu to close all sub menus anyway
455
+ if ( !currentMenu.length ) {
456
+ currentMenu = this.element;
457
+ }
458
+
459
+ this._close( currentMenu );
460
+
461
+ this.blur( event );
462
+ this.activeMenu = currentMenu;
463
+ }, this.delay );
464
+ },
465
+
466
+ // With no arguments, closes the currently active menu - if nothing is active
467
+ // it closes all menus. If passed an argument, it will search for menus BELOW
468
+ _close: function( startMenu ) {
469
+ if ( !startMenu ) {
470
+ startMenu = this.active ? this.active.parent() : this.element;
471
+ }
472
+
473
+ startMenu
474
+ .find( ".ui-menu" )
475
+ .hide()
476
+ .attr( "aria-hidden", "true" )
477
+ .attr( "aria-expanded", "false" )
478
+ .end()
479
+ .find( "a.ui-state-active" )
480
+ .removeClass( "ui-state-active" );
481
+ },
482
+
483
+ collapse: function( event ) {
484
+ var newItem = this.active &&
485
+ this.active.parent().closest( ".ui-menu-item", this.element );
486
+ if ( newItem && newItem.length ) {
487
+ this._close();
488
+ this.focus( event, newItem );
489
+ }
490
+ },
491
+
492
+ expand: function( event ) {
493
+ var newItem = this.active &&
494
+ this.active
495
+ .children( ".ui-menu " )
496
+ .children( ".ui-menu-item" )
497
+ .first();
498
+
499
+ if ( newItem && newItem.length ) {
500
+ this._open( newItem.parent() );
501
+
502
+ // Delay so Firefox will not hide activedescendant change in expanding submenu from AT
503
+ this._delay(function() {
504
+ this.focus( event, newItem );
505
+ });
506
+ }
507
+ },
508
+
509
+ next: function( event ) {
510
+ this._move( "next", "first", event );
511
+ },
512
+
513
+ previous: function( event ) {
514
+ this._move( "prev", "last", event );
515
+ },
516
+
517
+ isFirstItem: function() {
518
+ return this.active && !this.active.prevAll( ".ui-menu-item" ).length;
519
+ },
520
+
521
+ isLastItem: function() {
522
+ return this.active && !this.active.nextAll( ".ui-menu-item" ).length;
523
+ },
524
+
525
+ _move: function( direction, filter, event ) {
526
+ var next;
527
+ if ( this.active ) {
528
+ if ( direction === "first" || direction === "last" ) {
529
+ next = this.active
530
+ [ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" )
531
+ .eq( -1 );
532
+ } else {
533
+ next = this.active
534
+ [ direction + "All" ]( ".ui-menu-item" )
535
+ .eq( 0 );
536
+ }
537
+ }
538
+ if ( !next || !next.length || !this.active ) {
539
+ next = this.activeMenu.children( ".ui-menu-item" )[ filter ]();
540
+ }
541
+
542
+ this.focus( event, next );
543
+ },
544
+
545
+ nextPage: function( event ) {
546
+ var item, base, height;
547
+
548
+ if ( !this.active ) {
549
+ this.next( event );
550
+ return;
551
+ }
552
+ if ( this.isLastItem() ) {
553
+ return;
554
+ }
555
+ if ( this._hasScroll() ) {
556
+ base = this.active.offset().top;
557
+ height = this.element.height();
558
+ this.active.nextAll( ".ui-menu-item" ).each(function() {
559
+ item = $( this );
560
+ return item.offset().top - base - height < 0;
561
+ });
562
+
563
+ this.focus( event, item );
564
+ } else {
565
+ this.focus( event, this.activeMenu.children( ".ui-menu-item" )
566
+ [ !this.active ? "first" : "last" ]() );
567
+ }
568
+ },
569
+
570
+ previousPage: function( event ) {
571
+ var item, base, height;
572
+ if ( !this.active ) {
573
+ this.next( event );
574
+ return;
575
+ }
576
+ if ( this.isFirstItem() ) {
577
+ return;
578
+ }
579
+ if ( this._hasScroll() ) {
580
+ base = this.active.offset().top;
581
+ height = this.element.height();
582
+ this.active.prevAll( ".ui-menu-item" ).each(function() {
583
+ item = $( this );
584
+ return item.offset().top - base + height > 0;
585
+ });
586
+
587
+ this.focus( event, item );
588
+ } else {
589
+ this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
590
+ }
591
+ },
592
+
593
+ _hasScroll: function() {
594
+ return this.element.outerHeight() < this.element.prop( "scrollHeight" );
595
+ },
596
+
597
+ select: function( event ) {
598
+ // TODO: It should never be possible to not have an active item at this
599
+ // point, but the tests don't trigger mouseenter before click.
600
+ this.active = this.active || $( event.target ).closest( ".ui-menu-item" );
601
+ var ui = { item: this.active };
602
+ if ( !this.active.has( ".ui-menu" ).length ) {
603
+ this.collapseAll( event, true );
604
+ }
605
+ this._trigger( "select", event, ui );
606
+ }
607
+ });
608
+
609
+ }( jQuery ));