HornsAndHooves-publify_core 10.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (452) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +102 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README.md +9 -0
  5. data/app/assets/fonts/bootstrap/glyphicons-halflings-regular.eot +0 -0
  6. data/app/assets/fonts/bootstrap/glyphicons-halflings-regular.svg +288 -0
  7. data/app/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf +0 -0
  8. data/app/assets/fonts/bootstrap/glyphicons-halflings-regular.woff +0 -0
  9. data/app/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2 +0 -0
  10. data/app/assets/fonts/open-sans-bold.woff +0 -0
  11. data/app/assets/fonts/open-sans.woff +0 -0
  12. data/app/assets/images/admin/loading.gif +0 -0
  13. data/app/assets/images/admin/typologo.gif +0 -0
  14. data/app/assets/images/calendar_date_select/calendar.gif +0 -0
  15. data/app/assets/images/close.gif +0 -0
  16. data/app/assets/images/closelabel.gif +0 -0
  17. data/app/assets/images/go.png +0 -0
  18. data/app/assets/images/loading.gif +0 -0
  19. data/app/assets/images/nextlabel.gif +0 -0
  20. data/app/assets/images/overlay.png +0 -0
  21. data/app/assets/images/powered.gif +0 -0
  22. data/app/assets/images/prevlabel.gif +0 -0
  23. data/app/assets/images/spinner-blue.gif +0 -0
  24. data/app/assets/images/spinner.gif +0 -0
  25. data/app/assets/images/thumb_blank.jpg +0 -0
  26. data/app/assets/javascripts/application.js +2 -0
  27. data/app/assets/javascripts/bootstrap/affix.js +164 -0
  28. data/app/assets/javascripts/bootstrap/alert.js +95 -0
  29. data/app/assets/javascripts/bootstrap/button.js +125 -0
  30. data/app/assets/javascripts/bootstrap/collapse.js +212 -0
  31. data/app/assets/javascripts/bootstrap/dropdown.js +165 -0
  32. data/app/assets/javascripts/bootstrap/modal.js +358 -0
  33. data/app/assets/javascripts/bootstrap/tab.js +155 -0
  34. data/app/assets/javascripts/bootstrap/transition.js +59 -0
  35. data/app/assets/javascripts/bootstrap-sprockets.js +8 -0
  36. data/app/assets/javascripts/cookies.js +60 -0
  37. data/app/assets/javascripts/datetimepicker.js +1470 -0
  38. data/app/assets/javascripts/lang/da_DK.js +17 -0
  39. data/app/assets/javascripts/lang/default.js +21 -0
  40. data/app/assets/javascripts/lang/en_US.js +21 -0
  41. data/app/assets/javascripts/lang/fr_FR.js +21 -0
  42. data/app/assets/javascripts/lang/nl_NL.js +21 -0
  43. data/app/assets/javascripts/lang/zh_TW.js +17 -0
  44. data/app/assets/javascripts/lightbox.js +350 -0
  45. data/app/assets/javascripts/observe.js +28 -0
  46. data/app/assets/javascripts/publify.js +11 -0
  47. data/app/assets/javascripts/publify_admin.js +104 -0
  48. data/app/assets/javascripts/quicktags.js +448 -0
  49. data/app/assets/javascripts/set-timeago-lang.js +3 -0
  50. data/app/assets/javascripts/sidebar.js +28 -0
  51. data/app/assets/javascripts/spinnable.js +5 -0
  52. data/app/assets/javascripts/tagmanager.js +481 -0
  53. data/app/assets/javascripts/typeahead.js +1139 -0
  54. data/app/assets/stylesheets/_bootstrap-compass.scss +9 -0
  55. data/app/assets/stylesheets/_bootstrap-mincer.scss +19 -0
  56. data/app/assets/stylesheets/_bootstrap-sprockets.scss +9 -0
  57. data/app/assets/stylesheets/_bootstrap.scss +43 -0
  58. data/app/assets/stylesheets/accounts.css.scss +7 -0
  59. data/app/assets/stylesheets/administration_structure.css.scss +255 -0
  60. data/app/assets/stylesheets/bootstrap/_alerts.scss +73 -0
  61. data/app/assets/stylesheets/bootstrap/_button-groups.scss +242 -0
  62. data/app/assets/stylesheets/bootstrap/_buttons.scss +168 -0
  63. data/app/assets/stylesheets/bootstrap/_close.scss +37 -0
  64. data/app/assets/stylesheets/bootstrap/_code.scss +69 -0
  65. data/app/assets/stylesheets/bootstrap/_component-animations.scss +38 -0
  66. data/app/assets/stylesheets/bootstrap/_dropdowns.scss +213 -0
  67. data/app/assets/stylesheets/bootstrap/_forms.scss +586 -0
  68. data/app/assets/stylesheets/bootstrap/_glyphicons.scss +307 -0
  69. data/app/assets/stylesheets/bootstrap/_grid.scss +94 -0
  70. data/app/assets/stylesheets/bootstrap/_labels.scss +66 -0
  71. data/app/assets/stylesheets/bootstrap/_media.scss +66 -0
  72. data/app/assets/stylesheets/bootstrap/_mixins.scss +37 -0
  73. data/app/assets/stylesheets/bootstrap/_modals.scss +150 -0
  74. data/app/assets/stylesheets/bootstrap/_navbar.scss +479 -0
  75. data/app/assets/stylesheets/bootstrap/_navs.scss +242 -0
  76. data/app/assets/stylesheets/bootstrap/_normalize.scss +427 -0
  77. data/app/assets/stylesheets/bootstrap/_pagination.scss +86 -0
  78. data/app/assets/stylesheets/bootstrap/_panels.scss +222 -0
  79. data/app/assets/stylesheets/bootstrap/_print.scss +99 -0
  80. data/app/assets/stylesheets/bootstrap/_scaffolding.scss +160 -0
  81. data/app/assets/stylesheets/bootstrap/_tables.scss +234 -0
  82. data/app/assets/stylesheets/bootstrap/_theme.scss +224 -0
  83. data/app/assets/stylesheets/bootstrap/_type.scss +296 -0
  84. data/app/assets/stylesheets/bootstrap/_utilities.scss +55 -0
  85. data/app/assets/stylesheets/bootstrap/_variables.scss +654 -0
  86. data/app/assets/stylesheets/bootstrap/_wells.scss +29 -0
  87. data/app/assets/stylesheets/bootstrap/mixins/_alerts.scss +15 -0
  88. data/app/assets/stylesheets/bootstrap/mixins/_background-variant.scss +12 -0
  89. data/app/assets/stylesheets/bootstrap/mixins/_border-radius.scss +18 -0
  90. data/app/assets/stylesheets/bootstrap/mixins/_buttons.scss +56 -0
  91. data/app/assets/stylesheets/bootstrap/mixins/_center-block.scss +7 -0
  92. data/app/assets/stylesheets/bootstrap/mixins/_clearfix.scss +22 -0
  93. data/app/assets/stylesheets/bootstrap/mixins/_forms.scss +82 -0
  94. data/app/assets/stylesheets/bootstrap/mixins/_gradients.scss +56 -0
  95. data/app/assets/stylesheets/bootstrap/mixins/_grid-framework.scss +81 -0
  96. data/app/assets/stylesheets/bootstrap/mixins/_grid.scss +122 -0
  97. data/app/assets/stylesheets/bootstrap/mixins/_hide-text.scss +21 -0
  98. data/app/assets/stylesheets/bootstrap/mixins/_image.scss +28 -0
  99. data/app/assets/stylesheets/bootstrap/mixins/_labels.scss +12 -0
  100. data/app/assets/stylesheets/bootstrap/mixins/_nav-divider.scss +10 -0
  101. data/app/assets/stylesheets/bootstrap/mixins/_nav-vertical-align.scss +9 -0
  102. data/app/assets/stylesheets/bootstrap/mixins/_opacity.scss +7 -0
  103. data/app/assets/stylesheets/bootstrap/mixins/_pagination.scss +24 -0
  104. data/app/assets/stylesheets/bootstrap/mixins/_panels.scss +20 -0
  105. data/app/assets/stylesheets/bootstrap/mixins/_reset-filter.scss +8 -0
  106. data/app/assets/stylesheets/bootstrap/mixins/_resize.scss +6 -0
  107. data/app/assets/stylesheets/bootstrap/mixins/_responsive-visibility.scss +17 -0
  108. data/app/assets/stylesheets/bootstrap/mixins/_size.scss +10 -0
  109. data/app/assets/stylesheets/bootstrap/mixins/_tab-focus.scss +9 -0
  110. data/app/assets/stylesheets/bootstrap/mixins/_table-row.scss +28 -0
  111. data/app/assets/stylesheets/bootstrap/mixins/_text-emphasis.scss +12 -0
  112. data/app/assets/stylesheets/bootstrap/mixins/_text-overflow.scss +8 -0
  113. data/app/assets/stylesheets/bootstrap/mixins/_vendor-prefixes.scss +222 -0
  114. data/app/assets/stylesheets/coderay.css +135 -0
  115. data/app/assets/stylesheets/datetimepicker.css +306 -0
  116. data/app/assets/stylesheets/lightbox.css +63 -0
  117. data/app/assets/stylesheets/publify.css.scss +9 -0
  118. data/app/assets/stylesheets/publify_admin.css.scss +10 -0
  119. data/app/assets/stylesheets/rss.css +53 -0
  120. data/app/assets/stylesheets/sidebar_admin.css.scss +36 -0
  121. data/app/assets/stylesheets/tagmanager.css +102 -0
  122. data/app/assets/stylesheets/user-styles.css +29 -0
  123. data/app/controllers/accounts_controller.rb +4 -0
  124. data/app/controllers/admin/base_controller.rb +27 -0
  125. data/app/controllers/admin/content_controller.rb +194 -0
  126. data/app/controllers/admin/dashboard_controller.rb +33 -0
  127. data/app/controllers/admin/feedback_controller.rb +160 -0
  128. data/app/controllers/admin/notes_controller.rb +73 -0
  129. data/app/controllers/admin/pages_controller.rb +73 -0
  130. data/app/controllers/admin/post_types_controller.rb +57 -0
  131. data/app/controllers/admin/profiles_controller.rb +57 -0
  132. data/app/controllers/admin/redirects_controller.rb +51 -0
  133. data/app/controllers/admin/resources_controller.rb +36 -0
  134. data/app/controllers/admin/seo_controller.rb +46 -0
  135. data/app/controllers/admin/settings_controller.rb +53 -0
  136. data/app/controllers/admin/sidebar_controller.rb +67 -0
  137. data/app/controllers/admin/tags_controller.rb +55 -0
  138. data/app/controllers/admin/themes_controller.rb +31 -0
  139. data/app/controllers/admin/users_controller.rb +67 -0
  140. data/app/controllers/articles_controller.rb +215 -0
  141. data/app/controllers/authors_controller.rb +30 -0
  142. data/app/controllers/base_controller.rb +43 -0
  143. data/app/controllers/comments_controller.rb +67 -0
  144. data/app/controllers/content_controller.rb +24 -0
  145. data/app/controllers/feedback_controller.rb +13 -0
  146. data/app/controllers/notes_controller.rb +35 -0
  147. data/app/controllers/setup_controller.rb +61 -0
  148. data/app/controllers/tags_controller.rb +50 -0
  149. data/app/controllers/text_controller.rb +7 -0
  150. data/app/controllers/textfilter_controller.rb +5 -0
  151. data/app/controllers/theme_controller.rb +63 -0
  152. data/app/controllers/xml_controller.rb +20 -0
  153. data/app/helpers/admin/base_helper.rb +87 -0
  154. data/app/helpers/admin/feedback_helper.rb +53 -0
  155. data/app/helpers/articles_helper.rb +10 -0
  156. data/app/helpers/authors_helper.rb +30 -0
  157. data/app/helpers/base_helper.rb +257 -0
  158. data/app/helpers/blog_helper.rb +14 -0
  159. data/app/helpers/xml_helper.rb +18 -0
  160. data/app/jobs/application_job.rb +5 -0
  161. data/app/mailers/notification_mailer.rb +40 -0
  162. data/app/models/ability.rb +53 -0
  163. data/app/models/archives_sidebar.rb +45 -0
  164. data/app/models/article/factory.rb +64 -0
  165. data/app/models/article.rb +308 -0
  166. data/app/models/blog.rb +280 -0
  167. data/app/models/comment.rb +57 -0
  168. data/app/models/config_manager.rb +83 -0
  169. data/app/models/content.rb +118 -0
  170. data/app/models/content_base.rb +88 -0
  171. data/app/models/feedback.rb +250 -0
  172. data/app/models/meta_sidebar.rb +10 -0
  173. data/app/models/note.rb +152 -0
  174. data/app/models/page.rb +42 -0
  175. data/app/models/page_sidebar.rb +14 -0
  176. data/app/models/ping.rb +5 -0
  177. data/app/models/post_type.rb +16 -0
  178. data/app/models/redirect.rb +51 -0
  179. data/app/models/redirection.rb +6 -0
  180. data/app/models/resource.rb +12 -0
  181. data/app/models/search_sidebar.rb +9 -0
  182. data/app/models/sidebar.rb +142 -0
  183. data/app/models/static_sidebar.rb +22 -0
  184. data/app/models/tag.rb +71 -0
  185. data/app/models/tag_sidebar.rb +30 -0
  186. data/app/models/text_filter.rb +141 -0
  187. data/app/models/trackback.rb +46 -0
  188. data/app/models/trigger.rb +34 -0
  189. data/app/models/user.rb +142 -0
  190. data/app/services/title_builder.rb +88 -0
  191. data/app/uploaders/resource_uploader.rb +63 -0
  192. data/app/views/accounts/confirm.html.erb +7 -0
  193. data/app/views/admin/content/_article_list.html.erb +26 -0
  194. data/app/views/admin/content/_form.html.erb +145 -0
  195. data/app/views/admin/content/autosave.js.erb +5 -0
  196. data/app/views/admin/content/edit.html.erb +3 -0
  197. data/app/views/admin/content/index.html.erb +48 -0
  198. data/app/views/admin/content/index.js.erb +1 -0
  199. data/app/views/admin/content/new.html.erb +3 -0
  200. data/app/views/admin/dashboard/_comment.html.erb +18 -0
  201. data/app/views/admin/dashboard/_comments.html.erb +10 -0
  202. data/app/views/admin/dashboard/_drafts.html.erb +25 -0
  203. data/app/views/admin/dashboard/_overview.html.erb +21 -0
  204. data/app/views/admin/dashboard/_welcome.html.erb +28 -0
  205. data/app/views/admin/dashboard/index.html.erb +16 -0
  206. data/app/views/admin/feedback/_button.html.erb +19 -0
  207. data/app/views/admin/feedback/_feedback.html.erb +7 -0
  208. data/app/views/admin/feedback/_ham.html.erb +17 -0
  209. data/app/views/admin/feedback/_spam.html.erb +23 -0
  210. data/app/views/admin/feedback/article.html.erb +69 -0
  211. data/app/views/admin/feedback/edit.html.erb +48 -0
  212. data/app/views/admin/feedback/ham.js +1 -0
  213. data/app/views/admin/feedback/index.html.erb +53 -0
  214. data/app/views/admin/feedback/spam.js +1 -0
  215. data/app/views/admin/migrations/show.html.erb +39 -0
  216. data/app/views/admin/notes/_form.html.erb +37 -0
  217. data/app/views/admin/notes/_header.html.erb +6 -0
  218. data/app/views/admin/notes/_list.html.erb +13 -0
  219. data/app/views/admin/notes/_note.html.erb +14 -0
  220. data/app/views/admin/notes/edit.html.erb +11 -0
  221. data/app/views/admin/notes/index.html.erb +11 -0
  222. data/app/views/admin/notes/show.html.erb +14 -0
  223. data/app/views/admin/pages/_form.html.erb +101 -0
  224. data/app/views/admin/pages/_pages.html.erb +21 -0
  225. data/app/views/admin/pages/edit.html.erb +1 -0
  226. data/app/views/admin/pages/index.html.erb +17 -0
  227. data/app/views/admin/pages/new.html.erb +1 -0
  228. data/app/views/admin/post_types/_index_and_form.html.erb +65 -0
  229. data/app/views/admin/post_types/edit.html.erb +1 -0
  230. data/app/views/admin/post_types/index.html.erb +1 -0
  231. data/app/views/admin/profiles/index.html.erb +10 -0
  232. data/app/views/admin/redirects/_index_and_form.html.erb +68 -0
  233. data/app/views/admin/redirects/edit.html.erb +1 -0
  234. data/app/views/admin/redirects/index.html.erb +1 -0
  235. data/app/views/admin/resources/index.html.erb +72 -0
  236. data/app/views/admin/seo/_general.html.erb +104 -0
  237. data/app/views/admin/seo/_permalinks.html.erb +53 -0
  238. data/app/views/admin/seo/_titles.html.erb +209 -0
  239. data/app/views/admin/seo/show.html.erb +28 -0
  240. data/app/views/admin/settings/display.html.erb +101 -0
  241. data/app/views/admin/settings/feedback.html.erb +118 -0
  242. data/app/views/admin/settings/index.html.erb +73 -0
  243. data/app/views/admin/settings/write.html.erb +69 -0
  244. data/app/views/admin/shared/_edit.html.erb +4 -0
  245. data/app/views/admin/shared/_menu.html.erb +121 -0
  246. data/app/views/admin/shared/_twitter_alert.html.erb +3 -0
  247. data/app/views/admin/sidebar/_available.html.erb +6 -0
  248. data/app/views/admin/sidebar/_available.json.erb +6 -0
  249. data/app/views/admin/sidebar/_config.html.erb +27 -0
  250. data/app/views/admin/sidebar/_target.html.erb +9 -0
  251. data/app/views/admin/sidebar/_target_sidebar.html.erb +20 -0
  252. data/app/views/admin/sidebar/destroy.js.erb +1 -0
  253. data/app/views/admin/sidebar/index.html.erb +31 -0
  254. data/app/views/admin/sidebar/sortable.js.erb +3 -0
  255. data/app/views/admin/sidebar/update.js.erb +2 -0
  256. data/app/views/admin/tags/_index_and_form.html.erb +59 -0
  257. data/app/views/admin/tags/edit.html.erb +1 -0
  258. data/app/views/admin/tags/index.html.erb +1 -0
  259. data/app/views/admin/themes/index.html.erb +27 -0
  260. data/app/views/admin/users/_form.html.erb +215 -0
  261. data/app/views/admin/users/edit.html.erb +8 -0
  262. data/app/views/admin/users/index.html.erb +39 -0
  263. data/app/views/admin/users/new.html.erb +8 -0
  264. data/app/views/archives_sidebar/_content.html.erb +13 -0
  265. data/app/views/articles/_archives_article.html.erb +9 -0
  266. data/app/views/articles/_article.html.erb +9 -0
  267. data/app/views/articles/_article_author.html.erb +4 -0
  268. data/app/views/articles/_article_collection.html.erb +8 -0
  269. data/app/views/articles/_article_content.html.erb +5 -0
  270. data/app/views/articles/_article_excerpt.html.erb +15 -0
  271. data/app/views/articles/_article_links.html.erb +12 -0
  272. data/app/views/articles/_comment.html.erb +1 -0
  273. data/app/views/articles/_comment_errors.html.erb +2 -0
  274. data/app/views/articles/_comment_form.html.erb +48 -0
  275. data/app/views/articles/_comment_list.html.erb +5 -0
  276. data/app/views/articles/_comment_preview.html.erb +4 -0
  277. data/app/views/articles/_full_article_content.html.erb +4 -0
  278. data/app/views/articles/_password_form.html.erb +10 -0
  279. data/app/views/articles/_trackback.html.erb +6 -0
  280. data/app/views/articles/archives.html.erb +15 -0
  281. data/app/views/articles/comment.js.erb +5 -0
  282. data/app/views/articles/comment_failed.js.erb +3 -0
  283. data/app/views/articles/error.html.erb +3 -0
  284. data/app/views/articles/feedback_atom_feed.atom.builder +10 -0
  285. data/app/views/articles/feedback_rss_feed.rss.builder +21 -0
  286. data/app/views/articles/index.html.erb +1 -0
  287. data/app/views/articles/index_atom_feed.atom.builder +9 -0
  288. data/app/views/articles/index_rss_feed.rss.builder +20 -0
  289. data/app/views/articles/live_search.html.erb +10 -0
  290. data/app/views/articles/read.html.erb +43 -0
  291. data/app/views/articles/search.html.erb +8 -0
  292. data/app/views/articles/trackback.xml.builder +7 -0
  293. data/app/views/articles/view_page.html.erb +3 -0
  294. data/app/views/authors/show.html.erb +30 -0
  295. data/app/views/authors/show_atom_feed.atom.builder +9 -0
  296. data/app/views/authors/show_rss_feed.rss.builder +20 -0
  297. data/app/views/comments/_comment.html.erb +17 -0
  298. data/app/views/comments/preview.html.erb +1 -0
  299. data/app/views/comments/preview.js.erb +3 -0
  300. data/app/views/devise/mailer/reset_password_instructions.html.erb +11 -0
  301. data/app/views/devise/passwords/edit.html.erb +28 -0
  302. data/app/views/devise/passwords/new.html.erb +20 -0
  303. data/app/views/devise/registrations/new.html.erb +36 -0
  304. data/app/views/devise/sessions/new.html.erb +32 -0
  305. data/app/views/devise/shared/_links.html.erb +11 -0
  306. data/app/views/errors/404.html.erb +2 -0
  307. data/app/views/feedback/index.atom.builder +9 -0
  308. data/app/views/feedback/index.rss.builder +20 -0
  309. data/app/views/layouts/accounts.html.erb +33 -0
  310. data/app/views/layouts/administration.html.erb +37 -0
  311. data/app/views/layouts/default.html.erb +33 -0
  312. data/app/views/layouts/editor.html.erb +17 -0
  313. data/app/views/meta_sidebar/_content.html.erb +8 -0
  314. data/app/views/notes/_note.html.erb +16 -0
  315. data/app/views/notes/error.html.erb +3 -0
  316. data/app/views/notes/index.html.erb +15 -0
  317. data/app/views/notes/show.html.erb +5 -0
  318. data/app/views/notes/show_in_reply.html.erb +18 -0
  319. data/app/views/notification_mailer/_mail_footer.html.erb +5 -0
  320. data/app/views/notification_mailer/_mail_header.html.erb +3 -0
  321. data/app/views/notification_mailer/article.html.erb +7 -0
  322. data/app/views/notification_mailer/comment.html.erb +12 -0
  323. data/app/views/notification_mailer/notif_user.html.erb +9 -0
  324. data/app/views/page_sidebar/_content.html.erb +12 -0
  325. data/app/views/search_sidebar/_content.html.erb +10 -0
  326. data/app/views/settings/done.html.erb +2 -0
  327. data/app/views/settings/install.html.erb +12 -0
  328. data/app/views/setup/index.html.erb +17 -0
  329. data/app/views/shared/_atom_header.atom.builder +6 -0
  330. data/app/views/shared/_atom_item_article.atom.builder +36 -0
  331. data/app/views/shared/_atom_item_comment.atom.builder +10 -0
  332. data/app/views/shared/_atom_item_trackback.atom.builder +10 -0
  333. data/app/views/shared/_flash.erb +10 -0
  334. data/app/views/shared/_google_analytics.html.erb +8 -0
  335. data/app/views/shared/_page_header.html.erb +23 -0
  336. data/app/views/shared/_rss_item_article.rss.builder +32 -0
  337. data/app/views/shared/_rss_item_comment.rss.builder +9 -0
  338. data/app/views/shared/_rss_item_trackback.rss.builder +9 -0
  339. data/app/views/sidebar/_row.html.erb +1 -0
  340. data/app/views/sidebar/_sidebar.html.erb +5 -0
  341. data/app/views/sidebar/display_plugins.html.erb +5 -0
  342. data/app/views/sidebar/show.html.erb +1 -0
  343. data/app/views/static_sidebar/_content.html.erb +2 -0
  344. data/app/views/tag_sidebar/_content.html.erb +10 -0
  345. data/app/views/tags/index.html.erb +15 -0
  346. data/app/views/tags/show.html.erb +1 -0
  347. data/app/views/theme/static_view_test.html.erb +1 -0
  348. data/app/views/xml/_googlesitemap_item_article.googlesitemap.builder +7 -0
  349. data/app/views/xml/_googlesitemap_item_category.googlesitemap.builder +6 -0
  350. data/app/views/xml/_googlesitemap_item_page.googlesitemap.builder +6 -0
  351. data/app/views/xml/_googlesitemap_item_tag.googlesitemap.builder +6 -0
  352. data/app/views/xml/sitemap.googlesitemap.builder +9 -0
  353. data/config/i18n-tasks.yml +49 -0
  354. data/config/initializers/devise.rb +271 -0
  355. data/config/initializers/mime_types.rb +7 -0
  356. data/config/locales/da.yml +769 -0
  357. data/config/locales/de.yml +769 -0
  358. data/config/locales/en.yml +770 -0
  359. data/config/locales/es-MX.yml +769 -0
  360. data/config/locales/fr.yml +769 -0
  361. data/config/locales/he.yml +769 -0
  362. data/config/locales/it.yml +769 -0
  363. data/config/locales/ja.yml +769 -0
  364. data/config/locales/lt.yml +783 -0
  365. data/config/locales/nb-NO.yml +769 -0
  366. data/config/locales/nl.yml +769 -0
  367. data/config/locales/pl.yml +797 -0
  368. data/config/locales/pt-BR.yml +769 -0
  369. data/config/locales/ro.yml +782 -0
  370. data/config/locales/ru.yml +797 -0
  371. data/config/locales/sidebars.da.yml +20 -0
  372. data/config/locales/sidebars.de.yml +20 -0
  373. data/config/locales/sidebars.en.yml +20 -0
  374. data/config/locales/sidebars.es-MX.yml +20 -0
  375. data/config/locales/sidebars.fr.yml +20 -0
  376. data/config/locales/sidebars.he.yml +20 -0
  377. data/config/locales/sidebars.it.yml +20 -0
  378. data/config/locales/sidebars.ja.yml +20 -0
  379. data/config/locales/sidebars.lt.yml +20 -0
  380. data/config/locales/sidebars.nb-NO.yml +20 -0
  381. data/config/locales/sidebars.nl.yml +20 -0
  382. data/config/locales/sidebars.pl.yml +20 -0
  383. data/config/locales/sidebars.pt-BR.yml +20 -0
  384. data/config/locales/sidebars.ro.yml +20 -0
  385. data/config/locales/sidebars.ru.yml +20 -0
  386. data/config/locales/sidebars.zh-CN.yml +20 -0
  387. data/config/locales/sidebars.zh-TW.yml +20 -0
  388. data/config/locales/zh-CN.yml +768 -0
  389. data/config/locales/zh-TW.yml +769 -0
  390. data/config/routes.rb +174 -0
  391. data/db/migrate/113_initial_schema.rb +210 -0
  392. data/db/migrate/114_fixes_buggy_articles_and_notes.rb +56 -0
  393. data/db/migrate/115_drops_categories_for_tags.rb +37 -0
  394. data/db/migrate/20150207131657_add_missing_indexes.rb +23 -0
  395. data/db/migrate/20150807134129_simplify_redirect_relations.rb +45 -0
  396. data/db/migrate/20150808052637_add_blog_ids.rb +39 -0
  397. data/db/migrate/20150808191127_add_blog_id_to_redirects.rb +19 -0
  398. data/db/migrate/20150810094754_add_blog_id_to_tags.rb +19 -0
  399. data/db/migrate/20160108111120_add_devise_to_users.rb +57 -0
  400. data/db/migrate/20160108184201_move_last_connection_to_last_sign_in_at.rb +20 -0
  401. data/db/migrate/20160110094906_remove_profiles_rights.rb +18 -0
  402. data/db/migrate/20160605103918_replace_profile_id_with_string.rb +32 -0
  403. data/db/migrate/20160605154632_remove_profiles.rb +31 -0
  404. data/db/migrate/20160701061851_demand_blog_id_on_contents.rb +13 -0
  405. data/db/migrate/20160701062604_add_blog_id_to_resources.rb +32 -0
  406. data/db/migrate/20170528093024_move_resources_to_content.rb +9 -0
  407. data/db/migrate/20170528094923_move_tags_to_content.rb +10 -0
  408. data/db/migrate/20170528201606_remove_separate_published_flag.rb +9 -0
  409. data/db/migrate/20170605071626_remove_extra_state_columns_from_feedback.rb +10 -0
  410. data/db/migrate/20170702105201_remove_published_at_from_feedback.rb +9 -0
  411. data/db/migrate/20190208151235_add_text_filter_name_fields.rb +11 -0
  412. data/db/migrate/20190208152646_move_text_filter_to_name.rb +99 -0
  413. data/db/migrate/20190209155717_remove_text_filter_ids.rb +21 -0
  414. data/db/migrate/20190209160610_remove_text_filters.rb +19 -0
  415. data/db/seeds.rb +25 -0
  416. data/lib/email_notify.rb +28 -0
  417. data/lib/format.rb +9 -0
  418. data/lib/publify_core/engine.rb +31 -0
  419. data/lib/publify_core/lang.rb +9 -0
  420. data/lib/publify_core/testing_support/dns_mock.rb +15 -0
  421. data/lib/publify_core/testing_support/factories.rb +242 -0
  422. data/lib/publify_core/testing_support/feed_assertions.rb +48 -0
  423. data/lib/publify_core/testing_support/fixtures/exploit.svg +4 -0
  424. data/lib/publify_core/testing_support/fixtures/fakepng.png +1 -0
  425. data/lib/publify_core/testing_support/fixtures/otherfile.txt +1 -0
  426. data/lib/publify_core/testing_support/fixtures/testfile.png +0 -0
  427. data/lib/publify_core/testing_support/fixtures/testfile.txt +1 -0
  428. data/lib/publify_core/testing_support/upload_fixtures.rb +15 -0
  429. data/lib/publify_core/version.rb +5 -0
  430. data/lib/publify_core.rb +46 -0
  431. data/lib/publify_guid.rb +11 -0
  432. data/lib/publify_plugins.rb +77 -0
  433. data/lib/publify_textfilter_markdown.rb +57 -0
  434. data/lib/publify_textfilter_none.rb +16 -0
  435. data/lib/publify_textfilter_smartypants.rb +16 -0
  436. data/lib/publify_textfilter_textile.rb +23 -0
  437. data/lib/publify_textfilter_twitterfilter.rb +39 -0
  438. data/lib/publify_time.rb +34 -0
  439. data/lib/sidebar_field.rb +127 -0
  440. data/lib/sidebar_registry.rb +35 -0
  441. data/lib/spam_protection.rb +103 -0
  442. data/lib/tasks/i18n.rake +9 -0
  443. data/lib/tasks/manifest.rake +30 -0
  444. data/lib/tasks/publify_core_tasks.rake +6 -0
  445. data/lib/text_filter_plugin.rb +183 -0
  446. data/lib/theme.rb +72 -0
  447. data/lib/transforms.rb +47 -0
  448. data/themes/plain/about.markdown +4 -0
  449. data/themes/plain/javascripts/theme.js +0 -0
  450. data/themes/plain/preview.png +0 -0
  451. data/themes/plain/stylesheets/theme.css +57 -0
  452. metadata +1062 -0
@@ -0,0 +1,1139 @@
1
+ /*!
2
+ * typeahead.js 0.9.3
3
+ * https://github.com/twitter/typeahead
4
+ * Copyright 2013 Twitter, Inc. and other contributors; Licensed MIT
5
+ */
6
+
7
+ (function($) {
8
+ var VERSION = "0.9.3";
9
+ var utils = {
10
+ isMsie: function() {
11
+ var match = /(msie) ([\w.]+)/i.exec(navigator.userAgent);
12
+ return match ? parseInt(match[2], 10) : false;
13
+ },
14
+ isBlankString: function(str) {
15
+ return !str || /^\s*$/.test(str);
16
+ },
17
+ escapeRegExChars: function(str) {
18
+ return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
19
+ },
20
+ isString: function(obj) {
21
+ return typeof obj === "string";
22
+ },
23
+ isNumber: function(obj) {
24
+ return typeof obj === "number";
25
+ },
26
+ isArray: $.isArray,
27
+ isFunction: $.isFunction,
28
+ isObject: $.isPlainObject,
29
+ isUndefined: function(obj) {
30
+ return typeof obj === "undefined";
31
+ },
32
+ bind: $.proxy,
33
+ bindAll: function(obj) {
34
+ var val;
35
+ for (var key in obj) {
36
+ $.isFunction(val = obj[key]) && (obj[key] = $.proxy(val, obj));
37
+ }
38
+ },
39
+ indexOf: function(haystack, needle) {
40
+ for (var i = 0; i < haystack.length; i++) {
41
+ if (haystack[i] === needle) {
42
+ return i;
43
+ }
44
+ }
45
+ return -1;
46
+ },
47
+ each: $.each,
48
+ map: $.map,
49
+ filter: $.grep,
50
+ every: function(obj, test) {
51
+ var result = true;
52
+ if (!obj) {
53
+ return result;
54
+ }
55
+ $.each(obj, function(key, val) {
56
+ if (!(result = test.call(null, val, key, obj))) {
57
+ return false;
58
+ }
59
+ });
60
+ return !!result;
61
+ },
62
+ some: function(obj, test) {
63
+ var result = false;
64
+ if (!obj) {
65
+ return result;
66
+ }
67
+ $.each(obj, function(key, val) {
68
+ if (result = test.call(null, val, key, obj)) {
69
+ return false;
70
+ }
71
+ });
72
+ return !!result;
73
+ },
74
+ mixin: $.extend,
75
+ getUniqueId: function() {
76
+ var counter = 0;
77
+ return function() {
78
+ return counter++;
79
+ };
80
+ }(),
81
+ defer: function(fn) {
82
+ setTimeout(fn, 0);
83
+ },
84
+ debounce: function(func, wait, immediate) {
85
+ var timeout, result;
86
+ return function() {
87
+ var context = this, args = arguments, later, callNow;
88
+ later = function() {
89
+ timeout = null;
90
+ if (!immediate) {
91
+ result = func.apply(context, args);
92
+ }
93
+ };
94
+ callNow = immediate && !timeout;
95
+ clearTimeout(timeout);
96
+ timeout = setTimeout(later, wait);
97
+ if (callNow) {
98
+ result = func.apply(context, args);
99
+ }
100
+ return result;
101
+ };
102
+ },
103
+ throttle: function(func, wait) {
104
+ var context, args, timeout, result, previous, later;
105
+ previous = 0;
106
+ later = function() {
107
+ previous = new Date();
108
+ timeout = null;
109
+ result = func.apply(context, args);
110
+ };
111
+ return function() {
112
+ var now = new Date(), remaining = wait - (now - previous);
113
+ context = this;
114
+ args = arguments;
115
+ if (remaining <= 0) {
116
+ clearTimeout(timeout);
117
+ timeout = null;
118
+ previous = now;
119
+ result = func.apply(context, args);
120
+ } else if (!timeout) {
121
+ timeout = setTimeout(later, remaining);
122
+ }
123
+ return result;
124
+ };
125
+ },
126
+ tokenizeQuery: function(str) {
127
+ return $.trim(str).toLowerCase().split(/[\s]+/);
128
+ },
129
+ tokenizeText: function(str) {
130
+ return $.trim(str).toLowerCase().split(/[\s\-_]+/);
131
+ },
132
+ getProtocol: function() {
133
+ return location.protocol;
134
+ },
135
+ noop: function() {}
136
+ };
137
+ var EventTarget = function() {
138
+ var eventSplitter = /\s+/;
139
+ return {
140
+ on: function(events, callback) {
141
+ var event;
142
+ if (!callback) {
143
+ return this;
144
+ }
145
+ this._callbacks = this._callbacks || {};
146
+ events = events.split(eventSplitter);
147
+ while (event = events.shift()) {
148
+ this._callbacks[event] = this._callbacks[event] || [];
149
+ this._callbacks[event].push(callback);
150
+ }
151
+ return this;
152
+ },
153
+ trigger: function(events, data) {
154
+ var event, callbacks;
155
+ if (!this._callbacks) {
156
+ return this;
157
+ }
158
+ events = events.split(eventSplitter);
159
+ while (event = events.shift()) {
160
+ if (callbacks = this._callbacks[event]) {
161
+ for (var i = 0; i < callbacks.length; i += 1) {
162
+ callbacks[i].call(this, {
163
+ type: event,
164
+ data: data
165
+ });
166
+ }
167
+ }
168
+ }
169
+ return this;
170
+ }
171
+ };
172
+ }();
173
+ var EventBus = function() {
174
+ var namespace = "typeahead:";
175
+ function EventBus(o) {
176
+ if (!o || !o.el) {
177
+ $.error("EventBus initialized without el");
178
+ }
179
+ this.$el = $(o.el);
180
+ }
181
+ utils.mixin(EventBus.prototype, {
182
+ trigger: function(type) {
183
+ var args = [].slice.call(arguments, 1);
184
+ this.$el.trigger(namespace + type, args);
185
+ }
186
+ });
187
+ return EventBus;
188
+ }();
189
+ var PersistentStorage = function() {
190
+ var ls, methods;
191
+ try {
192
+ ls = window.localStorage;
193
+ ls.setItem("~~~", "!");
194
+ ls.removeItem("~~~");
195
+ } catch (err) {
196
+ ls = null;
197
+ }
198
+ function PersistentStorage(namespace) {
199
+ this.prefix = [ "__", namespace, "__" ].join("");
200
+ this.ttlKey = "__ttl__";
201
+ this.keyMatcher = new RegExp("^" + this.prefix);
202
+ }
203
+ if (ls && window.JSON) {
204
+ methods = {
205
+ _prefix: function(key) {
206
+ return this.prefix + key;
207
+ },
208
+ _ttlKey: function(key) {
209
+ return this._prefix(key) + this.ttlKey;
210
+ },
211
+ get: function(key) {
212
+ if (this.isExpired(key)) {
213
+ this.remove(key);
214
+ }
215
+ return decode(ls.getItem(this._prefix(key)));
216
+ },
217
+ set: function(key, val, ttl) {
218
+ if (utils.isNumber(ttl)) {
219
+ ls.setItem(this._ttlKey(key), encode(now() + ttl));
220
+ } else {
221
+ ls.removeItem(this._ttlKey(key));
222
+ }
223
+ return ls.setItem(this._prefix(key), encode(val));
224
+ },
225
+ remove: function(key) {
226
+ ls.removeItem(this._ttlKey(key));
227
+ ls.removeItem(this._prefix(key));
228
+ return this;
229
+ },
230
+ clear: function() {
231
+ var i, key, keys = [], len = ls.length;
232
+ for (i = 0; i < len; i++) {
233
+ if ((key = ls.key(i)).match(this.keyMatcher)) {
234
+ keys.push(key.replace(this.keyMatcher, ""));
235
+ }
236
+ }
237
+ for (i = keys.length; i--; ) {
238
+ this.remove(keys[i]);
239
+ }
240
+ return this;
241
+ },
242
+ isExpired: function(key) {
243
+ var ttl = decode(ls.getItem(this._ttlKey(key)));
244
+ return utils.isNumber(ttl) && now() > ttl ? true : false;
245
+ }
246
+ };
247
+ } else {
248
+ methods = {
249
+ get: utils.noop,
250
+ set: utils.noop,
251
+ remove: utils.noop,
252
+ clear: utils.noop,
253
+ isExpired: utils.noop
254
+ };
255
+ }
256
+ utils.mixin(PersistentStorage.prototype, methods);
257
+ return PersistentStorage;
258
+ function now() {
259
+ return new Date().getTime();
260
+ }
261
+ function encode(val) {
262
+ return JSON.stringify(utils.isUndefined(val) ? null : val);
263
+ }
264
+ function decode(val) {
265
+ return JSON.parse(val);
266
+ }
267
+ }();
268
+ var RequestCache = function() {
269
+ function RequestCache(o) {
270
+ utils.bindAll(this);
271
+ o = o || {};
272
+ this.sizeLimit = o.sizeLimit || 10;
273
+ this.cache = {};
274
+ this.cachedKeysByAge = [];
275
+ }
276
+ utils.mixin(RequestCache.prototype, {
277
+ get: function(url) {
278
+ return this.cache[url];
279
+ },
280
+ set: function(url, resp) {
281
+ var requestToEvict;
282
+ if (this.cachedKeysByAge.length === this.sizeLimit) {
283
+ requestToEvict = this.cachedKeysByAge.shift();
284
+ delete this.cache[requestToEvict];
285
+ }
286
+ this.cache[url] = resp;
287
+ this.cachedKeysByAge.push(url);
288
+ }
289
+ });
290
+ return RequestCache;
291
+ }();
292
+ var Transport = function() {
293
+ var pendingRequestsCount = 0, pendingRequests = {}, maxPendingRequests, requestCache;
294
+ function Transport(o) {
295
+ utils.bindAll(this);
296
+ o = utils.isString(o) ? {
297
+ url: o
298
+ } : o;
299
+ requestCache = requestCache || new RequestCache();
300
+ maxPendingRequests = utils.isNumber(o.maxParallelRequests) ? o.maxParallelRequests : maxPendingRequests || 6;
301
+ this.url = o.url;
302
+ this.wildcard = o.wildcard || "%QUERY";
303
+ this.filter = o.filter;
304
+ this.replace = o.replace;
305
+ this.ajaxSettings = {
306
+ type: "get",
307
+ cache: o.cache,
308
+ timeout: o.timeout,
309
+ dataType: o.dataType || "json",
310
+ beforeSend: o.beforeSend
311
+ };
312
+ this._get = (/^throttle$/i.test(o.rateLimitFn) ? utils.throttle : utils.debounce)(this._get, o.rateLimitWait || 300);
313
+ }
314
+ utils.mixin(Transport.prototype, {
315
+ _get: function(url, cb) {
316
+ var that = this;
317
+ if (belowPendingRequestsThreshold()) {
318
+ this._sendRequest(url).done(done);
319
+ } else {
320
+ this.onDeckRequestArgs = [].slice.call(arguments, 0);
321
+ }
322
+ function done(resp) {
323
+ var data = that.filter ? that.filter(resp) : resp;
324
+ cb && cb(data);
325
+ requestCache.set(url, resp);
326
+ }
327
+ },
328
+ _sendRequest: function(url) {
329
+ var that = this, jqXhr = pendingRequests[url];
330
+ if (!jqXhr) {
331
+ incrementPendingRequests();
332
+ jqXhr = pendingRequests[url] = $.ajax(url, this.ajaxSettings).always(always);
333
+ }
334
+ return jqXhr;
335
+ function always() {
336
+ decrementPendingRequests();
337
+ pendingRequests[url] = null;
338
+ if (that.onDeckRequestArgs) {
339
+ that._get.apply(that, that.onDeckRequestArgs);
340
+ that.onDeckRequestArgs = null;
341
+ }
342
+ }
343
+ },
344
+ get: function(query, cb) {
345
+ var that = this, encodedQuery = encodeURIComponent(query || ""), url, resp;
346
+ cb = cb || utils.noop;
347
+ url = this.replace ? this.replace(this.url, encodedQuery) : this.url.replace(this.wildcard, encodedQuery);
348
+ if (resp = requestCache.get(url)) {
349
+ utils.defer(function() {
350
+ cb(that.filter ? that.filter(resp) : resp);
351
+ });
352
+ } else {
353
+ this._get(url, cb);
354
+ }
355
+ return !!resp;
356
+ }
357
+ });
358
+ return Transport;
359
+ function incrementPendingRequests() {
360
+ pendingRequestsCount++;
361
+ }
362
+ function decrementPendingRequests() {
363
+ pendingRequestsCount--;
364
+ }
365
+ function belowPendingRequestsThreshold() {
366
+ return pendingRequestsCount < maxPendingRequests;
367
+ }
368
+ }();
369
+ var Dataset = function() {
370
+ var keys = {
371
+ thumbprint: "thumbprint",
372
+ protocol: "protocol",
373
+ itemHash: "itemHash",
374
+ adjacencyList: "adjacencyList"
375
+ };
376
+ function Dataset(o) {
377
+ utils.bindAll(this);
378
+ if (utils.isString(o.template) && !o.engine) {
379
+ $.error("no template engine specified");
380
+ }
381
+ if (!o.local && !o.prefetch && !o.remote) {
382
+ $.error("one of local, prefetch, or remote is required");
383
+ }
384
+ this.name = o.name || utils.getUniqueId();
385
+ this.limit = o.limit || 5;
386
+ this.minLength = o.minLength || 1;
387
+ this.header = o.header;
388
+ this.footer = o.footer;
389
+ this.valueKey = o.valueKey || "value";
390
+ this.template = compileTemplate(o.template, o.engine, this.valueKey);
391
+ this.local = o.local;
392
+ this.prefetch = o.prefetch;
393
+ this.remote = o.remote;
394
+ this.itemHash = {};
395
+ this.adjacencyList = {};
396
+ this.storage = o.name ? new PersistentStorage(o.name) : null;
397
+ }
398
+ utils.mixin(Dataset.prototype, {
399
+ _processLocalData: function(data) {
400
+ this._mergeProcessedData(this._processData(data));
401
+ },
402
+ _loadPrefetchData: function(o) {
403
+ var that = this, thumbprint = VERSION + (o.thumbprint || ""), storedThumbprint, storedProtocol, storedItemHash, storedAdjacencyList, isExpired, deferred;
404
+ if (this.storage) {
405
+ storedThumbprint = this.storage.get(keys.thumbprint);
406
+ storedProtocol = this.storage.get(keys.protocol);
407
+ storedItemHash = this.storage.get(keys.itemHash);
408
+ storedAdjacencyList = this.storage.get(keys.adjacencyList);
409
+ }
410
+ isExpired = storedThumbprint !== thumbprint || storedProtocol !== utils.getProtocol();
411
+ o = utils.isString(o) ? {
412
+ url: o
413
+ } : o;
414
+ o.ttl = utils.isNumber(o.ttl) ? o.ttl : 24 * 60 * 60 * 1e3;
415
+ if (storedItemHash && storedAdjacencyList && !isExpired) {
416
+ this._mergeProcessedData({
417
+ itemHash: storedItemHash,
418
+ adjacencyList: storedAdjacencyList
419
+ });
420
+ deferred = $.Deferred().resolve();
421
+ } else {
422
+ deferred = $.getJSON(o.url).done(processPrefetchData);
423
+ }
424
+ return deferred;
425
+ function processPrefetchData(data) {
426
+ var filteredData = o.filter ? o.filter(data) : data, processedData = that._processData(filteredData), itemHash = processedData.itemHash, adjacencyList = processedData.adjacencyList;
427
+ if (that.storage) {
428
+ that.storage.set(keys.itemHash, itemHash, o.ttl);
429
+ that.storage.set(keys.adjacencyList, adjacencyList, o.ttl);
430
+ that.storage.set(keys.thumbprint, thumbprint, o.ttl);
431
+ that.storage.set(keys.protocol, utils.getProtocol(), o.ttl);
432
+ }
433
+ that._mergeProcessedData(processedData);
434
+ }
435
+ },
436
+ _transformDatum: function(datum) {
437
+ var value = utils.isString(datum) ? datum : datum[this.valueKey], tokens = datum.tokens || utils.tokenizeText(value), item = {
438
+ value: value,
439
+ tokens: tokens
440
+ };
441
+ if (utils.isString(datum)) {
442
+ item.datum = {};
443
+ item.datum[this.valueKey] = datum;
444
+ } else {
445
+ item.datum = datum;
446
+ }
447
+ item.tokens = utils.filter(item.tokens, function(token) {
448
+ return !utils.isBlankString(token);
449
+ });
450
+ item.tokens = utils.map(item.tokens, function(token) {
451
+ return token.toLowerCase();
452
+ });
453
+ return item;
454
+ },
455
+ _processData: function(data) {
456
+ var that = this, itemHash = {}, adjacencyList = {};
457
+ utils.each(data, function(i, datum) {
458
+ var item = that._transformDatum(datum), id = utils.getUniqueId(item.value);
459
+ itemHash[id] = item;
460
+ utils.each(item.tokens, function(i, token) {
461
+ var character = token.charAt(0), adjacency = adjacencyList[character] || (adjacencyList[character] = [ id ]);
462
+ !~utils.indexOf(adjacency, id) && adjacency.push(id);
463
+ });
464
+ });
465
+ return {
466
+ itemHash: itemHash,
467
+ adjacencyList: adjacencyList
468
+ };
469
+ },
470
+ _mergeProcessedData: function(processedData) {
471
+ var that = this;
472
+ utils.mixin(this.itemHash, processedData.itemHash);
473
+ utils.each(processedData.adjacencyList, function(character, adjacency) {
474
+ var masterAdjacency = that.adjacencyList[character];
475
+ that.adjacencyList[character] = masterAdjacency ? masterAdjacency.concat(adjacency) : adjacency;
476
+ });
477
+ },
478
+ _getLocalSuggestions: function(terms) {
479
+ var that = this, firstChars = [], lists = [], shortestList, suggestions = [];
480
+ utils.each(terms, function(i, term) {
481
+ var firstChar = term.charAt(0);
482
+ !~utils.indexOf(firstChars, firstChar) && firstChars.push(firstChar);
483
+ });
484
+ utils.each(firstChars, function(i, firstChar) {
485
+ var list = that.adjacencyList[firstChar];
486
+ if (!list) {
487
+ return false;
488
+ }
489
+ lists.push(list);
490
+ if (!shortestList || list.length < shortestList.length) {
491
+ shortestList = list;
492
+ }
493
+ });
494
+ if (lists.length < firstChars.length) {
495
+ return [];
496
+ }
497
+ utils.each(shortestList, function(i, id) {
498
+ var item = that.itemHash[id], isCandidate, isMatch;
499
+ isCandidate = utils.every(lists, function(list) {
500
+ return ~utils.indexOf(list, id);
501
+ });
502
+ isMatch = isCandidate && utils.every(terms, function(term) {
503
+ return utils.some(item.tokens, function(token) {
504
+ return token.indexOf(term) === 0;
505
+ });
506
+ });
507
+ isMatch && suggestions.push(item);
508
+ });
509
+ return suggestions;
510
+ },
511
+ initialize: function() {
512
+ var deferred;
513
+ this.local && this._processLocalData(this.local);
514
+ this.transport = this.remote ? new Transport(this.remote) : null;
515
+ deferred = this.prefetch ? this._loadPrefetchData(this.prefetch) : $.Deferred().resolve();
516
+ this.local = this.prefetch = this.remote = null;
517
+ this.initialize = function() {
518
+ return deferred;
519
+ };
520
+ return deferred;
521
+ },
522
+ getSuggestions: function(query, cb) {
523
+ var that = this, terms, suggestions, cacheHit = false;
524
+ if (query.length < this.minLength) {
525
+ return;
526
+ }
527
+ terms = utils.tokenizeQuery(query);
528
+ suggestions = this._getLocalSuggestions(terms).slice(0, this.limit);
529
+ if (suggestions.length < this.limit && this.transport) {
530
+ cacheHit = this.transport.get(query, processRemoteData);
531
+ }
532
+ !cacheHit && cb && cb(suggestions);
533
+ function processRemoteData(data) {
534
+ suggestions = suggestions.slice(0);
535
+ utils.each(data, function(i, datum) {
536
+ var item = that._transformDatum(datum), isDuplicate;
537
+ isDuplicate = utils.some(suggestions, function(suggestion) {
538
+ return item.value === suggestion.value;
539
+ });
540
+ !isDuplicate && suggestions.push(item);
541
+ return suggestions.length < that.limit;
542
+ });
543
+ cb && cb(suggestions);
544
+ }
545
+ }
546
+ });
547
+ return Dataset;
548
+ function compileTemplate(template, engine, valueKey) {
549
+ var renderFn, compiledTemplate;
550
+ if (utils.isFunction(template)) {
551
+ renderFn = template;
552
+ } else if (utils.isString(template)) {
553
+ compiledTemplate = engine.compile(template);
554
+ renderFn = utils.bind(compiledTemplate.render, compiledTemplate);
555
+ } else {
556
+ renderFn = function(context) {
557
+ return "<p>" + context[valueKey] + "</p>";
558
+ };
559
+ }
560
+ return renderFn;
561
+ }
562
+ }();
563
+ var InputView = function() {
564
+ function InputView(o) {
565
+ var that = this;
566
+ utils.bindAll(this);
567
+ this.specialKeyCodeMap = {
568
+ 9: "tab",
569
+ 27: "esc",
570
+ 37: "left",
571
+ 39: "right",
572
+ 13: "enter",
573
+ 38: "up",
574
+ 40: "down"
575
+ };
576
+ this.$hint = $(o.hint);
577
+ this.$input = $(o.input).on("blur.tt", this._handleBlur).on("focus.tt", this._handleFocus).on("keydown.tt", this._handleSpecialKeyEvent);
578
+ if (!utils.isMsie()) {
579
+ this.$input.on("input.tt", this._compareQueryToInputValue);
580
+ } else {
581
+ this.$input.on("keydown.tt keypress.tt cut.tt paste.tt", function($e) {
582
+ if (that.specialKeyCodeMap[$e.which || $e.keyCode]) {
583
+ return;
584
+ }
585
+ utils.defer(that._compareQueryToInputValue);
586
+ });
587
+ }
588
+ this.query = this.$input.val();
589
+ this.$overflowHelper = buildOverflowHelper(this.$input);
590
+ }
591
+ utils.mixin(InputView.prototype, EventTarget, {
592
+ _handleFocus: function() {
593
+ this.trigger("focused");
594
+ },
595
+ _handleBlur: function() {
596
+ this.trigger("blured");
597
+ },
598
+ _handleSpecialKeyEvent: function($e) {
599
+ var keyName = this.specialKeyCodeMap[$e.which || $e.keyCode];
600
+ keyName && this.trigger(keyName + "Keyed", $e);
601
+ },
602
+ _compareQueryToInputValue: function() {
603
+ var inputValue = this.getInputValue(), isSameQuery = compareQueries(this.query, inputValue), isSameQueryExceptWhitespace = isSameQuery ? this.query.length !== inputValue.length : false;
604
+ if (isSameQueryExceptWhitespace) {
605
+ this.trigger("whitespaceChanged", {
606
+ value: this.query
607
+ });
608
+ } else if (!isSameQuery) {
609
+ this.trigger("queryChanged", {
610
+ value: this.query = inputValue
611
+ });
612
+ }
613
+ },
614
+ destroy: function() {
615
+ this.$hint.off(".tt");
616
+ this.$input.off(".tt");
617
+ this.$hint = this.$input = this.$overflowHelper = null;
618
+ },
619
+ focus: function() {
620
+ this.$input.focus();
621
+ },
622
+ blur: function() {
623
+ this.$input.blur();
624
+ },
625
+ getQuery: function() {
626
+ return this.query;
627
+ },
628
+ setQuery: function(query) {
629
+ this.query = query;
630
+ },
631
+ getInputValue: function() {
632
+ return this.$input.val();
633
+ },
634
+ setInputValue: function(value, silent) {
635
+ this.$input.val(value);
636
+ !silent && this._compareQueryToInputValue();
637
+ },
638
+ getHintValue: function() {
639
+ return this.$hint.val();
640
+ },
641
+ setHintValue: function(value) {
642
+ this.$hint.val(value);
643
+ },
644
+ getLanguageDirection: function() {
645
+ return (this.$input.css("direction") || "ltr").toLowerCase();
646
+ },
647
+ isOverflow: function() {
648
+ this.$overflowHelper.text(this.getInputValue());
649
+ return this.$overflowHelper.width() > this.$input.width();
650
+ },
651
+ isCursorAtEnd: function() {
652
+ var valueLength = this.$input.val().length, selectionStart = this.$input[0].selectionStart, range;
653
+ if (utils.isNumber(selectionStart)) {
654
+ return selectionStart === valueLength;
655
+ } else if (document.selection) {
656
+ range = document.selection.createRange();
657
+ range.moveStart("character", -valueLength);
658
+ return valueLength === range.text.length;
659
+ }
660
+ return true;
661
+ }
662
+ });
663
+ return InputView;
664
+ function buildOverflowHelper($input) {
665
+ return $("<span></span>").css({
666
+ position: "absolute",
667
+ left: "-9999px",
668
+ visibility: "hidden",
669
+ whiteSpace: "nowrap",
670
+ fontFamily: $input.css("font-family"),
671
+ fontSize: $input.css("font-size"),
672
+ fontStyle: $input.css("font-style"),
673
+ fontVariant: $input.css("font-variant"),
674
+ fontWeight: $input.css("font-weight"),
675
+ wordSpacing: $input.css("word-spacing"),
676
+ letterSpacing: $input.css("letter-spacing"),
677
+ textIndent: $input.css("text-indent"),
678
+ textRendering: $input.css("text-rendering"),
679
+ textTransform: $input.css("text-transform")
680
+ }).insertAfter($input);
681
+ }
682
+ function compareQueries(a, b) {
683
+ a = (a || "").replace(/^\s*/g, "").replace(/\s{2,}/g, " ");
684
+ b = (b || "").replace(/^\s*/g, "").replace(/\s{2,}/g, " ");
685
+ return a === b;
686
+ }
687
+ }();
688
+ var DropdownView = function() {
689
+ var html = {
690
+ suggestionsList: '<span class="tt-suggestions"></span>'
691
+ }, css = {
692
+ suggestionsList: {
693
+ display: "block"
694
+ },
695
+ suggestion: {
696
+ whiteSpace: "nowrap",
697
+ cursor: "pointer"
698
+ },
699
+ suggestionChild: {
700
+ whiteSpace: "normal"
701
+ }
702
+ };
703
+ function DropdownView(o) {
704
+ utils.bindAll(this);
705
+ this.isOpen = false;
706
+ this.isEmpty = true;
707
+ this.isMouseOverDropdown = false;
708
+ this.$menu = $(o.menu).on("mouseenter.tt", this._handleMouseenter).on("mouseleave.tt", this._handleMouseleave).on("click.tt", ".tt-suggestion", this._handleSelection).on("mouseover.tt", ".tt-suggestion", this._handleMouseover);
709
+ }
710
+ utils.mixin(DropdownView.prototype, EventTarget, {
711
+ _handleMouseenter: function() {
712
+ this.isMouseOverDropdown = true;
713
+ },
714
+ _handleMouseleave: function() {
715
+ this.isMouseOverDropdown = false;
716
+ },
717
+ _handleMouseover: function($e) {
718
+ var $suggestion = $($e.currentTarget);
719
+ this._getSuggestions().removeClass("tt-is-under-cursor");
720
+ $suggestion.addClass("tt-is-under-cursor");
721
+ },
722
+ _handleSelection: function($e) {
723
+ var $suggestion = $($e.currentTarget);
724
+ this.trigger("suggestionSelected", extractSuggestion($suggestion));
725
+ },
726
+ _show: function() {
727
+ this.$menu.css("display", "block");
728
+ },
729
+ _hide: function() {
730
+ this.$menu.hide();
731
+ },
732
+ _moveCursor: function(increment) {
733
+ var $suggestions, $cur, nextIndex, $underCursor;
734
+ if (!this.isVisible()) {
735
+ return;
736
+ }
737
+ $suggestions = this._getSuggestions();
738
+ $cur = $suggestions.filter(".tt-is-under-cursor");
739
+ $cur.removeClass("tt-is-under-cursor");
740
+ nextIndex = $suggestions.index($cur) + increment;
741
+ nextIndex = (nextIndex + 1) % ($suggestions.length + 1) - 1;
742
+ if (nextIndex === -1) {
743
+ this.trigger("cursorRemoved");
744
+ return;
745
+ } else if (nextIndex < -1) {
746
+ nextIndex = $suggestions.length - 1;
747
+ }
748
+ $underCursor = $suggestions.eq(nextIndex).addClass("tt-is-under-cursor");
749
+ this._ensureVisibility($underCursor);
750
+ this.trigger("cursorMoved", extractSuggestion($underCursor));
751
+ },
752
+ _getSuggestions: function() {
753
+ return this.$menu.find(".tt-suggestions > .tt-suggestion");
754
+ },
755
+ _ensureVisibility: function($el) {
756
+ var menuHeight = this.$menu.height() + parseInt(this.$menu.css("paddingTop"), 10) + parseInt(this.$menu.css("paddingBottom"), 10), menuScrollTop = this.$menu.scrollTop(), elTop = $el.position().top, elBottom = elTop + $el.outerHeight(true);
757
+ if (elTop < 0) {
758
+ this.$menu.scrollTop(menuScrollTop + elTop);
759
+ } else if (menuHeight < elBottom) {
760
+ this.$menu.scrollTop(menuScrollTop + (elBottom - menuHeight));
761
+ }
762
+ },
763
+ destroy: function() {
764
+ this.$menu.off(".tt");
765
+ this.$menu = null;
766
+ },
767
+ isVisible: function() {
768
+ return this.isOpen && !this.isEmpty;
769
+ },
770
+ closeUnlessMouseIsOverDropdown: function() {
771
+ if (!this.isMouseOverDropdown) {
772
+ this.close();
773
+ }
774
+ },
775
+ close: function() {
776
+ if (this.isOpen) {
777
+ this.isOpen = false;
778
+ this.isMouseOverDropdown = false;
779
+ this._hide();
780
+ this.$menu.find(".tt-suggestions > .tt-suggestion").removeClass("tt-is-under-cursor");
781
+ this.trigger("closed");
782
+ }
783
+ },
784
+ open: function() {
785
+ if (!this.isOpen) {
786
+ this.isOpen = true;
787
+ !this.isEmpty && this._show();
788
+ this.trigger("opened");
789
+ }
790
+ },
791
+ setLanguageDirection: function(dir) {
792
+ var ltrCss = {
793
+ left: "0",
794
+ right: "auto"
795
+ }, rtlCss = {
796
+ left: "auto",
797
+ right: " 0"
798
+ };
799
+ dir === "ltr" ? this.$menu.css(ltrCss) : this.$menu.css(rtlCss);
800
+ },
801
+ moveCursorUp: function() {
802
+ this._moveCursor(-1);
803
+ },
804
+ moveCursorDown: function() {
805
+ this._moveCursor(+1);
806
+ },
807
+ getSuggestionUnderCursor: function() {
808
+ var $suggestion = this._getSuggestions().filter(".tt-is-under-cursor").first();
809
+ return $suggestion.length > 0 ? extractSuggestion($suggestion) : null;
810
+ },
811
+ getFirstSuggestion: function() {
812
+ var $suggestion = this._getSuggestions().first();
813
+ return $suggestion.length > 0 ? extractSuggestion($suggestion) : null;
814
+ },
815
+ renderSuggestions: function(dataset, suggestions) {
816
+ var datasetClassName = "tt-dataset-" + dataset.name, wrapper = '<div class="tt-suggestion">%body</div>', compiledHtml, $suggestionsList, $dataset = this.$menu.find("." + datasetClassName), elBuilder, fragment, $el;
817
+ if ($dataset.length === 0) {
818
+ $suggestionsList = $(html.suggestionsList).css(css.suggestionsList);
819
+ $dataset = $("<div></div>").addClass(datasetClassName).append(dataset.header).append($suggestionsList).append(dataset.footer).appendTo(this.$menu);
820
+ }
821
+ if (suggestions.length > 0) {
822
+ this.isEmpty = false;
823
+ this.isOpen && this._show();
824
+ elBuilder = document.createElement("div");
825
+ fragment = document.createDocumentFragment();
826
+ utils.each(suggestions, function(i, suggestion) {
827
+ suggestion.dataset = dataset.name;
828
+ compiledHtml = dataset.template(suggestion.datum);
829
+ elBuilder.innerHTML = wrapper.replace("%body", compiledHtml);
830
+ $el = $(elBuilder.firstChild).css(css.suggestion).data("suggestion", suggestion);
831
+ $el.children().each(function() {
832
+ $(this).css(css.suggestionChild);
833
+ });
834
+ fragment.appendChild($el[0]);
835
+ });
836
+ $dataset.show().find(".tt-suggestions").html(fragment);
837
+ } else {
838
+ this.clearSuggestions(dataset.name);
839
+ }
840
+ this.trigger("suggestionsRendered");
841
+ },
842
+ clearSuggestions: function(datasetName) {
843
+ var $datasets = datasetName ? this.$menu.find(".tt-dataset-" + datasetName) : this.$menu.find('[class^="tt-dataset-"]'), $suggestions = $datasets.find(".tt-suggestions");
844
+ $datasets.hide();
845
+ $suggestions.empty();
846
+ if (this._getSuggestions().length === 0) {
847
+ this.isEmpty = true;
848
+ this._hide();
849
+ }
850
+ }
851
+ });
852
+ return DropdownView;
853
+ function extractSuggestion($el) {
854
+ return $el.data("suggestion");
855
+ }
856
+ }();
857
+ var TypeaheadView = function() {
858
+ var html = {
859
+ wrapper: '<span class="twitter-typeahead"></span>',
860
+ hint: '<input class="tt-hint" type="text" autocomplete="off" spellcheck="off" disabled>',
861
+ dropdown: '<span class="tt-dropdown-menu"></span>'
862
+ }, css = {
863
+ wrapper: {
864
+ position: "relative",
865
+ display: "block"
866
+ },
867
+ hint: {
868
+ position: "absolute",
869
+ top: "0",
870
+ left: "0",
871
+ borderColor: "transparent",
872
+ boxShadow: "none"
873
+ },
874
+ query: {
875
+ position: "relative",
876
+ verticalAlign: "top",
877
+ backgroundColor: "transparent"
878
+ },
879
+ dropdown: {
880
+ position: "absolute",
881
+ top: "100%",
882
+ left: "0",
883
+ zIndex: "100",
884
+ display: "none"
885
+ }
886
+ };
887
+ if (utils.isMsie()) {
888
+ utils.mixin(css.query, {
889
+ backgroundImage: "url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)"
890
+ });
891
+ }
892
+ if (utils.isMsie() && utils.isMsie() <= 7) {
893
+ utils.mixin(css.wrapper, {
894
+ display: "inline",
895
+ zoom: "1"
896
+ });
897
+ utils.mixin(css.query, {
898
+ marginTop: "-1px"
899
+ });
900
+ }
901
+ function TypeaheadView(o) {
902
+ var $menu, $input, $hint;
903
+ utils.bindAll(this);
904
+ this.$node = buildDomStructure(o.input);
905
+ this.datasets = o.datasets;
906
+ this.dir = null;
907
+ this.eventBus = o.eventBus;
908
+ $menu = this.$node.find(".tt-dropdown-menu");
909
+ $input = this.$node.find(".tt-query");
910
+ $hint = this.$node.find(".tt-hint");
911
+ this.dropdownView = new DropdownView({
912
+ menu: $menu
913
+ }).on("suggestionSelected", this._handleSelection).on("cursorMoved", this._clearHint).on("cursorMoved", this._setInputValueToSuggestionUnderCursor).on("cursorRemoved", this._setInputValueToQuery).on("cursorRemoved", this._updateHint).on("suggestionsRendered", this._updateHint).on("opened", this._updateHint).on("closed", this._clearHint).on("opened closed", this._propagateEvent);
914
+ this.inputView = new InputView({
915
+ input: $input,
916
+ hint: $hint
917
+ }).on("focused", this._openDropdown).on("blured", this._closeDropdown).on("blured", this._setInputValueToQuery).on("enterKeyed tabKeyed", this._handleSelection).on("queryChanged", this._clearHint).on("queryChanged", this._clearSuggestions).on("queryChanged", this._getSuggestions).on("whitespaceChanged", this._updateHint).on("queryChanged whitespaceChanged", this._openDropdown).on("queryChanged whitespaceChanged", this._setLanguageDirection).on("escKeyed", this._closeDropdown).on("escKeyed", this._setInputValueToQuery).on("tabKeyed upKeyed downKeyed", this._managePreventDefault).on("upKeyed downKeyed", this._moveDropdownCursor).on("upKeyed downKeyed", this._openDropdown).on("tabKeyed leftKeyed rightKeyed", this._autocomplete);
918
+ }
919
+ utils.mixin(TypeaheadView.prototype, EventTarget, {
920
+ _managePreventDefault: function(e) {
921
+ var $e = e.data, hint, inputValue, preventDefault = false;
922
+ switch (e.type) {
923
+ case "tabKeyed":
924
+ hint = this.inputView.getHintValue();
925
+ inputValue = this.inputView.getInputValue();
926
+ preventDefault = hint && hint !== inputValue;
927
+ break;
928
+
929
+ case "upKeyed":
930
+ case "downKeyed":
931
+ preventDefault = !$e.shiftKey && !$e.ctrlKey && !$e.metaKey;
932
+ break;
933
+ }
934
+ preventDefault && $e.preventDefault();
935
+ },
936
+ _setLanguageDirection: function() {
937
+ var dir = this.inputView.getLanguageDirection();
938
+ if (dir !== this.dir) {
939
+ this.dir = dir;
940
+ this.$node.css("direction", dir);
941
+ this.dropdownView.setLanguageDirection(dir);
942
+ }
943
+ },
944
+ _updateHint: function() {
945
+ var suggestion = this.dropdownView.getFirstSuggestion(), hint = suggestion ? suggestion.value : null, dropdownIsVisible = this.dropdownView.isVisible(), inputHasOverflow = this.inputView.isOverflow(), inputValue, query, escapedQuery, beginsWithQuery, match;
946
+ if (hint && dropdownIsVisible && !inputHasOverflow) {
947
+ inputValue = this.inputView.getInputValue();
948
+ query = inputValue.replace(/\s{2,}/g, " ").replace(/^\s+/g, "");
949
+ escapedQuery = utils.escapeRegExChars(query);
950
+ beginsWithQuery = new RegExp("^(?:" + escapedQuery + ")(.*$)", "i");
951
+ match = beginsWithQuery.exec(hint);
952
+ this.inputView.setHintValue(inputValue + (match ? match[1] : ""));
953
+ }
954
+ },
955
+ _clearHint: function() {
956
+ this.inputView.setHintValue("");
957
+ },
958
+ _clearSuggestions: function() {
959
+ this.dropdownView.clearSuggestions();
960
+ },
961
+ _setInputValueToQuery: function() {
962
+ this.inputView.setInputValue(this.inputView.getQuery());
963
+ },
964
+ _setInputValueToSuggestionUnderCursor: function(e) {
965
+ var suggestion = e.data;
966
+ this.inputView.setInputValue(suggestion.value, true);
967
+ },
968
+ _openDropdown: function() {
969
+ this.dropdownView.open();
970
+ },
971
+ _closeDropdown: function(e) {
972
+ this.dropdownView[e.type === "blured" ? "closeUnlessMouseIsOverDropdown" : "close"]();
973
+ },
974
+ _moveDropdownCursor: function(e) {
975
+ var $e = e.data;
976
+ if (!$e.shiftKey && !$e.ctrlKey && !$e.metaKey) {
977
+ this.dropdownView[e.type === "upKeyed" ? "moveCursorUp" : "moveCursorDown"]();
978
+ }
979
+ },
980
+ _handleSelection: function(e) {
981
+ var byClick = e.type === "suggestionSelected", suggestion = byClick ? e.data : this.dropdownView.getSuggestionUnderCursor();
982
+ if (suggestion) {
983
+ this.inputView.setInputValue(suggestion.value);
984
+ byClick ? this.inputView.focus() : e.data.preventDefault();
985
+ byClick && utils.isMsie() ? utils.defer(this.dropdownView.close) : this.dropdownView.close();
986
+ this.eventBus.trigger("selected", suggestion.datum, suggestion.dataset);
987
+ }
988
+ },
989
+ _getSuggestions: function() {
990
+ var that = this, query = this.inputView.getQuery();
991
+ if (utils.isBlankString(query)) {
992
+ return;
993
+ }
994
+ utils.each(this.datasets, function(i, dataset) {
995
+ dataset.getSuggestions(query, function(suggestions) {
996
+ if (query === that.inputView.getQuery()) {
997
+ that.dropdownView.renderSuggestions(dataset, suggestions);
998
+ }
999
+ });
1000
+ });
1001
+ },
1002
+ _autocomplete: function(e) {
1003
+ var isCursorAtEnd, ignoreEvent, query, hint, suggestion;
1004
+ if (e.type === "rightKeyed" || e.type === "leftKeyed") {
1005
+ isCursorAtEnd = this.inputView.isCursorAtEnd();
1006
+ ignoreEvent = this.inputView.getLanguageDirection() === "ltr" ? e.type === "leftKeyed" : e.type === "rightKeyed";
1007
+ if (!isCursorAtEnd || ignoreEvent) {
1008
+ return;
1009
+ }
1010
+ }
1011
+ query = this.inputView.getQuery();
1012
+ hint = this.inputView.getHintValue();
1013
+ if (hint !== "" && query !== hint) {
1014
+ suggestion = this.dropdownView.getFirstSuggestion();
1015
+ this.inputView.setInputValue(suggestion.value);
1016
+ this.eventBus.trigger("autocompleted", suggestion.datum, suggestion.dataset);
1017
+ }
1018
+ },
1019
+ _propagateEvent: function(e) {
1020
+ this.eventBus.trigger(e.type);
1021
+ },
1022
+ destroy: function() {
1023
+ this.inputView.destroy();
1024
+ this.dropdownView.destroy();
1025
+ destroyDomStructure(this.$node);
1026
+ this.$node = null;
1027
+ },
1028
+ setQuery: function(query) {
1029
+ this.inputView.setQuery(query);
1030
+ this.inputView.setInputValue(query);
1031
+ this._clearHint();
1032
+ this._clearSuggestions();
1033
+ this._getSuggestions();
1034
+ }
1035
+ });
1036
+ return TypeaheadView;
1037
+ function buildDomStructure(input) {
1038
+ var $wrapper = $(html.wrapper), $dropdown = $(html.dropdown), $input = $(input), $hint = $(html.hint);
1039
+ $wrapper = $wrapper.css(css.wrapper);
1040
+ $dropdown = $dropdown.css(css.dropdown);
1041
+ $hint.css(css.hint).css({
1042
+ backgroundAttachment: $input.css("background-attachment"),
1043
+ backgroundClip: $input.css("background-clip"),
1044
+ backgroundColor: $input.css("background-color"),
1045
+ backgroundImage: $input.css("background-image"),
1046
+ backgroundOrigin: $input.css("background-origin"),
1047
+ backgroundPosition: $input.css("background-position"),
1048
+ backgroundRepeat: $input.css("background-repeat"),
1049
+ backgroundSize: $input.css("background-size")
1050
+ });
1051
+ $input.data("ttAttrs", {
1052
+ dir: $input.attr("dir"),
1053
+ autocomplete: $input.attr("autocomplete"),
1054
+ spellcheck: $input.attr("spellcheck"),
1055
+ style: $input.attr("style")
1056
+ });
1057
+ $input.addClass("tt-query").attr({
1058
+ autocomplete: "off",
1059
+ spellcheck: false
1060
+ }).css(css.query);
1061
+ try {
1062
+ !$input.attr("dir") && $input.attr("dir", "auto");
1063
+ } catch (e) {}
1064
+ return $input.wrap($wrapper).parent().prepend($hint).append($dropdown);
1065
+ }
1066
+ function destroyDomStructure($node) {
1067
+ var $input = $node.find(".tt-query");
1068
+ utils.each($input.data("ttAttrs"), function(key, val) {
1069
+ utils.isUndefined(val) ? $input.removeAttr(key) : $input.attr(key, val);
1070
+ });
1071
+ $input.detach().removeData("ttAttrs").removeClass("tt-query").insertAfter($node);
1072
+ $node.remove();
1073
+ }
1074
+ }();
1075
+ (function() {
1076
+ var cache = {}, viewKey = "ttView", methods;
1077
+ methods = {
1078
+ initialize: function(datasetDefs) {
1079
+ var datasets;
1080
+ datasetDefs = utils.isArray(datasetDefs) ? datasetDefs : [ datasetDefs ];
1081
+ if (datasetDefs.length === 0) {
1082
+ $.error("no datasets provided");
1083
+ }
1084
+ datasets = utils.map(datasetDefs, function(o) {
1085
+ var dataset = cache[o.name] ? cache[o.name] : new Dataset(o);
1086
+ if (o.name) {
1087
+ cache[o.name] = dataset;
1088
+ }
1089
+ return dataset;
1090
+ });
1091
+ return this.each(initialize);
1092
+ function initialize() {
1093
+ var $input = $(this), deferreds, eventBus = new EventBus({
1094
+ el: $input
1095
+ });
1096
+ deferreds = utils.map(datasets, function(dataset) {
1097
+ return dataset.initialize();
1098
+ });
1099
+ $input.data(viewKey, new TypeaheadView({
1100
+ input: $input,
1101
+ eventBus: eventBus = new EventBus({
1102
+ el: $input
1103
+ }),
1104
+ datasets: datasets
1105
+ }));
1106
+ $.when.apply($, deferreds).always(function() {
1107
+ utils.defer(function() {
1108
+ eventBus.trigger("initialized");
1109
+ });
1110
+ });
1111
+ }
1112
+ },
1113
+ destroy: function() {
1114
+ return this.each(destroy);
1115
+ function destroy() {
1116
+ var $this = $(this), view = $this.data(viewKey);
1117
+ if (view) {
1118
+ view.destroy();
1119
+ $this.removeData(viewKey);
1120
+ }
1121
+ }
1122
+ },
1123
+ setQuery: function(query) {
1124
+ return this.each(setQuery);
1125
+ function setQuery() {
1126
+ var view = $(this).data(viewKey);
1127
+ view && view.setQuery(query);
1128
+ }
1129
+ }
1130
+ };
1131
+ jQuery.fn.typeahead = function(method) {
1132
+ if (methods[method]) {
1133
+ return methods[method].apply(this, [].slice.call(arguments, 1));
1134
+ } else {
1135
+ return methods.initialize.apply(this, arguments);
1136
+ }
1137
+ };
1138
+ })();
1139
+ })(window.jQuery);