locomotive_cms 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (607) hide show
  1. data/Gemfile +45 -0
  2. data/README.textile +23 -0
  3. data/app/controllers/admin/accounts_controller.rb +24 -0
  4. data/app/controllers/admin/asset_collections_controller.rb +66 -0
  5. data/app/controllers/admin/assets_controller.rb +48 -0
  6. data/app/controllers/admin/base_controller.rb +55 -0
  7. data/app/controllers/admin/content_types_controller.rb +52 -0
  8. data/app/controllers/admin/contents_controller.rb +72 -0
  9. data/app/controllers/admin/current_sites_controller.rb +33 -0
  10. data/app/controllers/admin/layouts_controller.rb +56 -0
  11. data/app/controllers/admin/memberships_controller.rb +39 -0
  12. data/app/controllers/admin/my_accounts_controller.rb +21 -0
  13. data/app/controllers/admin/page_parts_controller.rb +12 -0
  14. data/app/controllers/admin/pages_controller.rb +70 -0
  15. data/app/controllers/admin/passwords_controller.rb +11 -0
  16. data/app/controllers/admin/rendering_controller.rb +15 -0
  17. data/app/controllers/admin/sessions_controller.rb +17 -0
  18. data/app/controllers/admin/sites_controller.rb +48 -0
  19. data/app/controllers/admin/snippets_controller.rb +56 -0
  20. data/app/controllers/admin/theme_assets_controller.rb +79 -0
  21. data/app/controllers/application_controller.rb +3 -0
  22. data/app/controllers/home_controller.rb +7 -0
  23. data/app/helpers/admin/accounts_helper.rb +8 -0
  24. data/app/helpers/admin/assets_helper.rb +15 -0
  25. data/app/helpers/admin/base_helper.rb +54 -0
  26. data/app/helpers/admin/custom_fields_helper.rb +24 -0
  27. data/app/helpers/admin/login_helper.rb +17 -0
  28. data/app/helpers/admin/pages_helper.rb +23 -0
  29. data/app/helpers/admin/sites_helper.rb +24 -0
  30. data/app/models/account.rb +46 -0
  31. data/app/models/asset.rb +38 -0
  32. data/app/models/asset_collection.rb +60 -0
  33. data/app/models/content_instance.rb +29 -0
  34. data/app/models/content_type.rb +63 -0
  35. data/app/models/extensions/asset/vignette.rb +40 -0
  36. data/app/models/extensions/page/parts.rb +54 -0
  37. data/app/models/extensions/page/render.rb +19 -0
  38. data/app/models/extensions/page/tree.rb +97 -0
  39. data/app/models/layout.rb +49 -0
  40. data/app/models/liquid_template.rb +32 -0
  41. data/app/models/membership.rb +36 -0
  42. data/app/models/page.rb +87 -0
  43. data/app/models/page_part.rb +38 -0
  44. data/app/models/site.rb +93 -0
  45. data/app/models/snippet.rb +3 -0
  46. data/app/models/theme_asset.rb +101 -0
  47. data/app/uploaders/asset_uploader.rb +68 -0
  48. data/app/uploaders/theme_asset_uploader.rb +42 -0
  49. data/app/views/admin/accounts/new.html.haml +22 -0
  50. data/app/views/admin/asset_collections/_asset.html.haml +7 -0
  51. data/app/views/admin/asset_collections/edit.html.haml +30 -0
  52. data/app/views/admin/asset_collections/index.html.haml +8 -0
  53. data/app/views/admin/asset_collections/new.html.haml +17 -0
  54. data/app/views/admin/assets/_form.html.haml +18 -0
  55. data/app/views/admin/assets/edit.html.haml +15 -0
  56. data/app/views/admin/assets/new.html.haml +12 -0
  57. data/app/views/admin/content_types/_form.html.haml +13 -0
  58. data/app/views/admin/content_types/edit.html.haml +16 -0
  59. data/app/views/admin/content_types/new.html.haml +15 -0
  60. data/app/views/admin/contents/_form.html.haml +10 -0
  61. data/app/views/admin/contents/edit.html.haml +16 -0
  62. data/app/views/admin/contents/index.html.haml +35 -0
  63. data/app/views/admin/contents/new.html.haml +15 -0
  64. data/app/views/admin/current_sites/_form.html.haml +45 -0
  65. data/app/views/admin/current_sites/edit.html.haml +15 -0
  66. data/app/views/admin/layouts/_form.html.haml +10 -0
  67. data/app/views/admin/layouts/_layout.html.haml +7 -0
  68. data/app/views/admin/layouts/edit.html.haml +18 -0
  69. data/app/views/admin/layouts/index.html.haml +15 -0
  70. data/app/views/admin/layouts/new.html.haml +15 -0
  71. data/app/views/admin/memberships/new.html.haml +15 -0
  72. data/app/views/admin/my_accounts/edit.html.haml +42 -0
  73. data/app/views/admin/pages/_form.html.haml +37 -0
  74. data/app/views/admin/pages/_page.html.haml +16 -0
  75. data/app/views/admin/pages/edit.html.haml +15 -0
  76. data/app/views/admin/pages/index.html.haml +18 -0
  77. data/app/views/admin/pages/new.html.haml +12 -0
  78. data/app/views/admin/passwords/edit.html.haml +18 -0
  79. data/app/views/admin/passwords/new.html.haml +17 -0
  80. data/app/views/admin/sessions/new.html.haml +15 -0
  81. data/app/views/admin/shared/_custom_fields.html.haml +47 -0
  82. data/app/views/admin/shared/_footer.html.haml +5 -0
  83. data/app/views/admin/shared/_form_actions.html.haml +15 -0
  84. data/app/views/admin/shared/_head.html.haml +18 -0
  85. data/app/views/admin/shared/_header.html.haml +8 -0
  86. data/app/views/admin/shared/_menu.html.haml +5 -0
  87. data/app/views/admin/shared/menu/_assets.html.haml +7 -0
  88. data/app/views/admin/shared/menu/_contents.html.haml +27 -0
  89. data/app/views/admin/shared/menu/_settings.html.haml +6 -0
  90. data/app/views/admin/sites/_form.html.haml +35 -0
  91. data/app/views/admin/sites/new.html.haml +12 -0
  92. data/app/views/admin/snippets/_form.html.haml +11 -0
  93. data/app/views/admin/snippets/_snippet.html.haml +7 -0
  94. data/app/views/admin/snippets/edit.html.haml +15 -0
  95. data/app/views/admin/snippets/index.html.haml +15 -0
  96. data/app/views/admin/snippets/new.html.haml +12 -0
  97. data/app/views/admin/theme_assets/_asset.html.haml +12 -0
  98. data/app/views/admin/theme_assets/_form.html.haml +39 -0
  99. data/app/views/admin/theme_assets/edit.html.haml +15 -0
  100. data/app/views/admin/theme_assets/images.html.haml +15 -0
  101. data/app/views/admin/theme_assets/index.html.haml +27 -0
  102. data/app/views/admin/theme_assets/new.html.haml +12 -0
  103. data/app/views/devise/confirmations/new.html.haml +12 -0
  104. data/app/views/devise/mailer/confirmation_instructions.html.haml +8 -0
  105. data/app/views/devise/mailer/reset_password_instructions.html.haml +12 -0
  106. data/app/views/devise/mailer/unlock_instructions.html.haml +10 -0
  107. data/app/views/devise/registrations/edit.html.haml +35 -0
  108. data/app/views/devise/registrations/new.html.haml +20 -0
  109. data/app/views/devise/sessions/new.html.haml +22 -0
  110. data/app/views/devise/shared/_links.haml +20 -0
  111. data/app/views/devise/unlocks/new.html.haml +12 -0
  112. data/app/views/home/show.html.haml +4 -0
  113. data/app/views/layouts/admin/application.html.haml +26 -0
  114. data/app/views/layouts/admin/login.html.haml +17 -0
  115. data/app/views/layouts/application.html.haml +7 -0
  116. data/config/application.rb +48 -0
  117. data/config/boot.rb +17 -0
  118. data/config/cucumber.yml +8 -0
  119. data/config/database.yml +20 -0
  120. data/config/environment.rb +5 -0
  121. data/config/environments/development.rb +35 -0
  122. data/config/environments/production.rb +33 -0
  123. data/config/environments/test.rb +33 -0
  124. data/config/initializers/backtrace_silencers.rb +7 -0
  125. data/config/initializers/carrierwave.rb +57 -0
  126. data/config/initializers/devise.rb +119 -0
  127. data/config/initializers/formtastic.rb +5 -0
  128. data/config/initializers/inflections.rb +10 -0
  129. data/config/initializers/locomotive.rb +7 -0
  130. data/config/initializers/mime_types.rb +5 -0
  131. data/config/initializers/mongoid.rb +61 -0
  132. data/config/initializers/rspec_generator.rb +8 -0
  133. data/config/locales/admin_ui_en.yml +211 -0
  134. data/config/locales/admin_ui_fr.yml +21 -0
  135. data/config/locales/carrierwave_en.yml +4 -0
  136. data/config/locales/carrierwave_fr.yml +4 -0
  137. data/config/locales/default_en.yml +29 -0
  138. data/config/locales/default_fr.yml +30 -0
  139. data/config/locales/devise.en.yml +36 -0
  140. data/config/routes.rb +57 -0
  141. data/lib/core_ext.rb +32 -0
  142. data/lib/generators/locomotive_generator.rb +14 -0
  143. data/lib/locomotive.rb +35 -0
  144. data/lib/locomotive/configuration.rb +67 -0
  145. data/lib/locomotive/devise/sessions_controller.rb +2 -0
  146. data/lib/locomotive/engine.rb +21 -0
  147. data/lib/locomotive/liquid.rb +5 -0
  148. data/lib/locomotive/liquid/db_file_system.rb +18 -0
  149. data/lib/locomotive/liquid/drops/asset_collections.rb +19 -0
  150. data/lib/locomotive/liquid/drops/base.rb +50 -0
  151. data/lib/locomotive/liquid/drops/content.rb +19 -0
  152. data/lib/locomotive/liquid/drops/contents.rb +63 -0
  153. data/lib/locomotive/liquid/drops/javascripts.rb +18 -0
  154. data/lib/locomotive/liquid/drops/stylesheets.rb +19 -0
  155. data/lib/locomotive/liquid/filters/date.rb +30 -0
  156. data/lib/locomotive/liquid/filters/html.rb +114 -0
  157. data/lib/locomotive/liquid/filters/misc.rb +30 -0
  158. data/lib/locomotive/liquid/liquify_template.rb +57 -0
  159. data/lib/locomotive/liquid/tags/blueprint.rb +21 -0
  160. data/lib/locomotive/liquid/tags/jquery.rb +17 -0
  161. data/lib/locomotive/liquid/tags/paginate.rb +100 -0
  162. data/lib/locomotive/liquid/tags/snippet.rb +42 -0
  163. data/lib/locomotive/liquid/tags/with_scope.rb +39 -0
  164. data/lib/locomotive/mongoid.rb +2 -0
  165. data/lib/locomotive/mongoid/document.rb +20 -0
  166. data/lib/locomotive/mongoid/model_extensions.rb +1 -0
  167. data/lib/locomotive/patches.rb +2 -0
  168. data/lib/locomotive/regexps.rb +13 -0
  169. data/lib/locomotive/render.rb +59 -0
  170. data/lib/locomotive/routing/default_constraint.rb +45 -0
  171. data/lib/locomotive/routing/site_dispatcher.rb +48 -0
  172. data/lib/misc_form_builder.rb +35 -0
  173. data/lib/tasks/cucumber.rake +53 -0
  174. data/lib/tasks/rspec.rake +69 -0
  175. data/public/images/admin/background/body.png +0 -0
  176. data/public/images/admin/background/footer.png +0 -0
  177. data/public/images/admin/background/light.png +0 -0
  178. data/public/images/admin/buttons/action-left.png +0 -0
  179. data/public/images/admin/buttons/action-right.png +0 -0
  180. data/public/images/admin/buttons/add-left.png +0 -0
  181. data/public/images/admin/buttons/add-right.png +0 -0
  182. data/public/images/admin/buttons/dark-gray-left.png +0 -0
  183. data/public/images/admin/buttons/dark-gray-right.png +0 -0
  184. data/public/images/admin/buttons/emboss-left.png +0 -0
  185. data/public/images/admin/buttons/emboss-right.png +0 -0
  186. data/public/images/admin/buttons/gray-left.png +0 -0
  187. data/public/images/admin/buttons/gray-right.png +0 -0
  188. data/public/images/admin/buttons/light-gray-left.png +0 -0
  189. data/public/images/admin/buttons/light-gray-right.png +0 -0
  190. data/public/images/admin/buttons/search.png +0 -0
  191. data/public/images/admin/buttons/transparent-left.png +0 -0
  192. data/public/images/admin/buttons/transparent-right.png +0 -0
  193. data/public/images/admin/form/big_item.png +0 -0
  194. data/public/images/admin/form/error-arrow.png +0 -0
  195. data/public/images/admin/form/field.png +0 -0
  196. data/public/images/admin/form/folded-arrow-off.png +0 -0
  197. data/public/images/admin/form/folded-arrow-on.png +0 -0
  198. data/public/images/admin/form/folded.png +0 -0
  199. data/public/images/admin/form/footer.png +0 -0
  200. data/public/images/admin/form/growl-error.png +0 -0
  201. data/public/images/admin/form/growl-notice.png +0 -0
  202. data/public/images/admin/form/header-first-on.png +0 -0
  203. data/public/images/admin/form/header-left-on.png +0 -0
  204. data/public/images/admin/form/header-on.png +0 -0
  205. data/public/images/admin/form/header-right-on.png +0 -0
  206. data/public/images/admin/form/header.png +0 -0
  207. data/public/images/admin/form/icons/drag.png +0 -0
  208. data/public/images/admin/form/icons/spinner.gif +0 -0
  209. data/public/images/admin/form/icons/trash.png +0 -0
  210. data/public/images/admin/form/item.png +0 -0
  211. data/public/images/admin/form/pen.png +0 -0
  212. data/public/images/admin/icons/filetype/medium/AC3.png +0 -0
  213. data/public/images/admin/icons/filetype/medium/ACE.png +0 -0
  214. data/public/images/admin/icons/filetype/medium/ADE.png +0 -0
  215. data/public/images/admin/icons/filetype/medium/ADP.png +0 -0
  216. data/public/images/admin/icons/filetype/medium/AI.png +0 -0
  217. data/public/images/admin/icons/filetype/medium/AIFF.png +0 -0
  218. data/public/images/admin/icons/filetype/medium/AU.png +0 -0
  219. data/public/images/admin/icons/filetype/medium/AVI.png +0 -0
  220. data/public/images/admin/icons/filetype/medium/BAT.png +0 -0
  221. data/public/images/admin/icons/filetype/medium/BIN.png +0 -0
  222. data/public/images/admin/icons/filetype/medium/BMP.png +0 -0
  223. data/public/images/admin/icons/filetype/medium/BUP.png +0 -0
  224. data/public/images/admin/icons/filetype/medium/CAB.png +0 -0
  225. data/public/images/admin/icons/filetype/medium/CAT.png +0 -0
  226. data/public/images/admin/icons/filetype/medium/CHM.png +0 -0
  227. data/public/images/admin/icons/filetype/medium/CSS.png +0 -0
  228. data/public/images/admin/icons/filetype/medium/CUE.png +0 -0
  229. data/public/images/admin/icons/filetype/medium/DAT.png +0 -0
  230. data/public/images/admin/icons/filetype/medium/DCR.png +0 -0
  231. data/public/images/admin/icons/filetype/medium/DER.png +0 -0
  232. data/public/images/admin/icons/filetype/medium/DIC.png +0 -0
  233. data/public/images/admin/icons/filetype/medium/DIVX.png +0 -0
  234. data/public/images/admin/icons/filetype/medium/DIZ.png +0 -0
  235. data/public/images/admin/icons/filetype/medium/DLL.png +0 -0
  236. data/public/images/admin/icons/filetype/medium/DOC.png +0 -0
  237. data/public/images/admin/icons/filetype/medium/DOCX.png +0 -0
  238. data/public/images/admin/icons/filetype/medium/DOS.png +0 -0
  239. data/public/images/admin/icons/filetype/medium/DVD.png +0 -0
  240. data/public/images/admin/icons/filetype/medium/DWG.png +0 -0
  241. data/public/images/admin/icons/filetype/medium/DWT.png +0 -0
  242. data/public/images/admin/icons/filetype/medium/EMF.png +0 -0
  243. data/public/images/admin/icons/filetype/medium/EXC.png +0 -0
  244. data/public/images/admin/icons/filetype/medium/FON.png +0 -0
  245. data/public/images/admin/icons/filetype/medium/GIF.png +0 -0
  246. data/public/images/admin/icons/filetype/medium/HLP.png +0 -0
  247. data/public/images/admin/icons/filetype/medium/HTML.png +0 -0
  248. data/public/images/admin/icons/filetype/medium/IFO.png +0 -0
  249. data/public/images/admin/icons/filetype/medium/INF.png +0 -0
  250. data/public/images/admin/icons/filetype/medium/INI.png +0 -0
  251. data/public/images/admin/icons/filetype/medium/INS.png +0 -0
  252. data/public/images/admin/icons/filetype/medium/IP.png +0 -0
  253. data/public/images/admin/icons/filetype/medium/ISO.png +0 -0
  254. data/public/images/admin/icons/filetype/medium/ISP.png +0 -0
  255. data/public/images/admin/icons/filetype/medium/JAVA.png +0 -0
  256. data/public/images/admin/icons/filetype/medium/JFIF.png +0 -0
  257. data/public/images/admin/icons/filetype/medium/JPEG.png +0 -0
  258. data/public/images/admin/icons/filetype/medium/JPG.png +0 -0
  259. data/public/images/admin/icons/filetype/medium/LOG.png +0 -0
  260. data/public/images/admin/icons/filetype/medium/M4A.png +0 -0
  261. data/public/images/admin/icons/filetype/medium/MID.png +0 -0
  262. data/public/images/admin/icons/filetype/medium/MMF.png +0 -0
  263. data/public/images/admin/icons/filetype/medium/MMM.png +0 -0
  264. data/public/images/admin/icons/filetype/medium/MOV.png +0 -0
  265. data/public/images/admin/icons/filetype/medium/MOVIE.png +0 -0
  266. data/public/images/admin/icons/filetype/medium/MP2.png +0 -0
  267. data/public/images/admin/icons/filetype/medium/MP2V.png +0 -0
  268. data/public/images/admin/icons/filetype/medium/MP3.png +0 -0
  269. data/public/images/admin/icons/filetype/medium/MP4.png +0 -0
  270. data/public/images/admin/icons/filetype/medium/MPE.png +0 -0
  271. data/public/images/admin/icons/filetype/medium/MPEG.png +0 -0
  272. data/public/images/admin/icons/filetype/medium/MPG.png +0 -0
  273. data/public/images/admin/icons/filetype/medium/MPV2.png +0 -0
  274. data/public/images/admin/icons/filetype/medium/NFO.png +0 -0
  275. data/public/images/admin/icons/filetype/medium/PDD.png +0 -0
  276. data/public/images/admin/icons/filetype/medium/PDF.png +0 -0
  277. data/public/images/admin/icons/filetype/medium/PHP.png +0 -0
  278. data/public/images/admin/icons/filetype/medium/PNG.png +0 -0
  279. data/public/images/admin/icons/filetype/medium/PPT.png +0 -0
  280. data/public/images/admin/icons/filetype/medium/PPTX.png +0 -0
  281. data/public/images/admin/icons/filetype/medium/PSD.png +0 -0
  282. data/public/images/admin/icons/filetype/medium/RAR.png +0 -0
  283. data/public/images/admin/icons/filetype/medium/REG.png +0 -0
  284. data/public/images/admin/icons/filetype/medium/RTF.png +0 -0
  285. data/public/images/admin/icons/filetype/medium/SCP.png +0 -0
  286. data/public/images/admin/icons/filetype/medium/THEME.png +0 -0
  287. data/public/images/admin/icons/filetype/medium/TIF.png +0 -0
  288. data/public/images/admin/icons/filetype/medium/TIFF.png +0 -0
  289. data/public/images/admin/icons/filetype/medium/TLB.png +0 -0
  290. data/public/images/admin/icons/filetype/medium/TTF.png +0 -0
  291. data/public/images/admin/icons/filetype/medium/TXT.png +0 -0
  292. data/public/images/admin/icons/filetype/medium/Thumbs.db +0 -0
  293. data/public/images/admin/icons/filetype/medium/UIS.png +0 -0
  294. data/public/images/admin/icons/filetype/medium/URL.png +0 -0
  295. data/public/images/admin/icons/filetype/medium/VBS.png +0 -0
  296. data/public/images/admin/icons/filetype/medium/VCR.png +0 -0
  297. data/public/images/admin/icons/filetype/medium/VOB.png +0 -0
  298. data/public/images/admin/icons/filetype/medium/WAV.png +0 -0
  299. data/public/images/admin/icons/filetype/medium/WBA.png +0 -0
  300. data/public/images/admin/icons/filetype/medium/WMA.png +0 -0
  301. data/public/images/admin/icons/filetype/medium/WMV.png +0 -0
  302. data/public/images/admin/icons/filetype/medium/WPL.png +0 -0
  303. data/public/images/admin/icons/filetype/medium/WRI.png +0 -0
  304. data/public/images/admin/icons/filetype/medium/WTX.png +0 -0
  305. data/public/images/admin/icons/filetype/medium/XLS.png +0 -0
  306. data/public/images/admin/icons/filetype/medium/XLSX.png +0 -0
  307. data/public/images/admin/icons/filetype/medium/XML.png +0 -0
  308. data/public/images/admin/icons/filetype/medium/XSL.png +0 -0
  309. data/public/images/admin/icons/filetype/medium/ZAP.png +0 -0
  310. data/public/images/admin/icons/filetype/medium/ZIP.png +0 -0
  311. data/public/images/admin/icons/filetype/medium/unknown.png +0 -0
  312. data/public/images/admin/icons/filetype/thumb/AC3.png +0 -0
  313. data/public/images/admin/icons/filetype/thumb/ACE.png +0 -0
  314. data/public/images/admin/icons/filetype/thumb/ADE.png +0 -0
  315. data/public/images/admin/icons/filetype/thumb/ADP.png +0 -0
  316. data/public/images/admin/icons/filetype/thumb/AI.png +0 -0
  317. data/public/images/admin/icons/filetype/thumb/AIFF.png +0 -0
  318. data/public/images/admin/icons/filetype/thumb/AU.png +0 -0
  319. data/public/images/admin/icons/filetype/thumb/AVI.png +0 -0
  320. data/public/images/admin/icons/filetype/thumb/BAT.png +0 -0
  321. data/public/images/admin/icons/filetype/thumb/BIN.png +0 -0
  322. data/public/images/admin/icons/filetype/thumb/BMP.png +0 -0
  323. data/public/images/admin/icons/filetype/thumb/BUP.png +0 -0
  324. data/public/images/admin/icons/filetype/thumb/CAB.png +0 -0
  325. data/public/images/admin/icons/filetype/thumb/CAT.png +0 -0
  326. data/public/images/admin/icons/filetype/thumb/CHM.png +0 -0
  327. data/public/images/admin/icons/filetype/thumb/CSS.png +0 -0
  328. data/public/images/admin/icons/filetype/thumb/CUE.png +0 -0
  329. data/public/images/admin/icons/filetype/thumb/DAT.png +0 -0
  330. data/public/images/admin/icons/filetype/thumb/DCR.png +0 -0
  331. data/public/images/admin/icons/filetype/thumb/DER.png +0 -0
  332. data/public/images/admin/icons/filetype/thumb/DIC.png +0 -0
  333. data/public/images/admin/icons/filetype/thumb/DIVX.png +0 -0
  334. data/public/images/admin/icons/filetype/thumb/DIZ.png +0 -0
  335. data/public/images/admin/icons/filetype/thumb/DLL.png +0 -0
  336. data/public/images/admin/icons/filetype/thumb/DOC.png +0 -0
  337. data/public/images/admin/icons/filetype/thumb/DOCX.png +0 -0
  338. data/public/images/admin/icons/filetype/thumb/DOS.png +0 -0
  339. data/public/images/admin/icons/filetype/thumb/DVD.png +0 -0
  340. data/public/images/admin/icons/filetype/thumb/DWG.png +0 -0
  341. data/public/images/admin/icons/filetype/thumb/DWT.png +0 -0
  342. data/public/images/admin/icons/filetype/thumb/EMF.png +0 -0
  343. data/public/images/admin/icons/filetype/thumb/EXC.png +0 -0
  344. data/public/images/admin/icons/filetype/thumb/FON.png +0 -0
  345. data/public/images/admin/icons/filetype/thumb/GIF.png +0 -0
  346. data/public/images/admin/icons/filetype/thumb/HLP.png +0 -0
  347. data/public/images/admin/icons/filetype/thumb/HTML.png +0 -0
  348. data/public/images/admin/icons/filetype/thumb/IFO.png +0 -0
  349. data/public/images/admin/icons/filetype/thumb/INF.png +0 -0
  350. data/public/images/admin/icons/filetype/thumb/INI.png +0 -0
  351. data/public/images/admin/icons/filetype/thumb/INS.png +0 -0
  352. data/public/images/admin/icons/filetype/thumb/IP.png +0 -0
  353. data/public/images/admin/icons/filetype/thumb/ISO.png +0 -0
  354. data/public/images/admin/icons/filetype/thumb/ISP.png +0 -0
  355. data/public/images/admin/icons/filetype/thumb/JAVA.png +0 -0
  356. data/public/images/admin/icons/filetype/thumb/JFIF.png +0 -0
  357. data/public/images/admin/icons/filetype/thumb/JPEG.png +0 -0
  358. data/public/images/admin/icons/filetype/thumb/JPG.png +0 -0
  359. data/public/images/admin/icons/filetype/thumb/LOG.png +0 -0
  360. data/public/images/admin/icons/filetype/thumb/M4A.png +0 -0
  361. data/public/images/admin/icons/filetype/thumb/MID.png +0 -0
  362. data/public/images/admin/icons/filetype/thumb/MMF.png +0 -0
  363. data/public/images/admin/icons/filetype/thumb/MMM.png +0 -0
  364. data/public/images/admin/icons/filetype/thumb/MOV.png +0 -0
  365. data/public/images/admin/icons/filetype/thumb/MOVIE.png +0 -0
  366. data/public/images/admin/icons/filetype/thumb/MP2.png +0 -0
  367. data/public/images/admin/icons/filetype/thumb/MP2V.png +0 -0
  368. data/public/images/admin/icons/filetype/thumb/MP3.png +0 -0
  369. data/public/images/admin/icons/filetype/thumb/MP4.png +0 -0
  370. data/public/images/admin/icons/filetype/thumb/MPE.png +0 -0
  371. data/public/images/admin/icons/filetype/thumb/MPEG.png +0 -0
  372. data/public/images/admin/icons/filetype/thumb/MPG.png +0 -0
  373. data/public/images/admin/icons/filetype/thumb/MPV2.png +0 -0
  374. data/public/images/admin/icons/filetype/thumb/NFO.png +0 -0
  375. data/public/images/admin/icons/filetype/thumb/PDD.png +0 -0
  376. data/public/images/admin/icons/filetype/thumb/PDF.png +0 -0
  377. data/public/images/admin/icons/filetype/thumb/PHP.png +0 -0
  378. data/public/images/admin/icons/filetype/thumb/PNG.png +0 -0
  379. data/public/images/admin/icons/filetype/thumb/PPT.png +0 -0
  380. data/public/images/admin/icons/filetype/thumb/PPTX.png +0 -0
  381. data/public/images/admin/icons/filetype/thumb/PSD.png +0 -0
  382. data/public/images/admin/icons/filetype/thumb/RAR.png +0 -0
  383. data/public/images/admin/icons/filetype/thumb/REG.png +0 -0
  384. data/public/images/admin/icons/filetype/thumb/RTF.png +0 -0
  385. data/public/images/admin/icons/filetype/thumb/SCP.png +0 -0
  386. data/public/images/admin/icons/filetype/thumb/THEME.png +0 -0
  387. data/public/images/admin/icons/filetype/thumb/TIF.png +0 -0
  388. data/public/images/admin/icons/filetype/thumb/TIFF.png +0 -0
  389. data/public/images/admin/icons/filetype/thumb/TLB.png +0 -0
  390. data/public/images/admin/icons/filetype/thumb/TTF.png +0 -0
  391. data/public/images/admin/icons/filetype/thumb/TXT.png +0 -0
  392. data/public/images/admin/icons/filetype/thumb/UIS.png +0 -0
  393. data/public/images/admin/icons/filetype/thumb/URL.png +0 -0
  394. data/public/images/admin/icons/filetype/thumb/VBS.png +0 -0
  395. data/public/images/admin/icons/filetype/thumb/VCR.png +0 -0
  396. data/public/images/admin/icons/filetype/thumb/VOB.png +0 -0
  397. data/public/images/admin/icons/filetype/thumb/WAV.png +0 -0
  398. data/public/images/admin/icons/filetype/thumb/WBA.png +0 -0
  399. data/public/images/admin/icons/filetype/thumb/WMA.png +0 -0
  400. data/public/images/admin/icons/filetype/thumb/WMV.png +0 -0
  401. data/public/images/admin/icons/filetype/thumb/WPL.png +0 -0
  402. data/public/images/admin/icons/filetype/thumb/WRI.png +0 -0
  403. data/public/images/admin/icons/filetype/thumb/WTX.png +0 -0
  404. data/public/images/admin/icons/filetype/thumb/XLS.png +0 -0
  405. data/public/images/admin/icons/filetype/thumb/XLSX.png +0 -0
  406. data/public/images/admin/icons/filetype/thumb/XML.png +0 -0
  407. data/public/images/admin/icons/filetype/thumb/XSL.png +0 -0
  408. data/public/images/admin/icons/filetype/thumb/ZAP.png +0 -0
  409. data/public/images/admin/icons/filetype/thumb/ZIP.png +0 -0
  410. data/public/images/admin/icons/filetype/thumb/unknown.png +0 -0
  411. data/public/images/admin/icons/flags/en.png +0 -0
  412. data/public/images/admin/icons/flags/fr.png +0 -0
  413. data/public/images/admin/list/empty.png +0 -0
  414. data/public/images/admin/list/icons/cross.png +0 -0
  415. data/public/images/admin/list/icons/drag.png +0 -0
  416. data/public/images/admin/list/icons/node_closed.png +0 -0
  417. data/public/images/admin/list/icons/node_open.png +0 -0
  418. data/public/images/admin/list/icons/trash.png +0 -0
  419. data/public/images/admin/list/item-left.png +0 -0
  420. data/public/images/admin/list/item-right.png +0 -0
  421. data/public/images/admin/list/item.png +0 -0
  422. data/public/images/admin/list/none.png +0 -0
  423. data/public/images/admin/list/thumb.png +0 -0
  424. data/public/images/admin/login/bottom_panel_bg.png +0 -0
  425. data/public/images/admin/login/buttons/left_bg.png +0 -0
  426. data/public/images/admin/login/buttons/right_bg.png +0 -0
  427. data/public/images/admin/login/content_panel_bg.png +0 -0
  428. data/public/images/admin/login/input_bg.png +0 -0
  429. data/public/images/admin/login/light_bg.png +0 -0
  430. data/public/images/admin/login/top_panel_bg.png +0 -0
  431. data/public/images/admin/login/wrapper_bg.png +0 -0
  432. data/public/images/admin/menu/arrow.png +0 -0
  433. data/public/images/admin/menu/blue-bg.png +0 -0
  434. data/public/images/admin/menu/blue-border.png +0 -0
  435. data/public/images/admin/menu/gray-bg.png +0 -0
  436. data/public/images/admin/menu/gray-border.png +0 -0
  437. data/public/images/admin/menu/green-bg.png +0 -0
  438. data/public/images/admin/menu/green-border.png +0 -0
  439. data/public/images/admin/menu/icons/add.png +0 -0
  440. data/public/images/admin/menu/icons/bullet.png +0 -0
  441. data/public/images/admin/menu/icons/folder.png +0 -0
  442. data/public/images/admin/menu/icons/settings.png +0 -0
  443. data/public/images/admin/menu/left.png +0 -0
  444. data/public/images/admin/menu/popup-body.png +0 -0
  445. data/public/images/admin/menu/popup-footer.png +0 -0
  446. data/public/images/admin/menu/popup-header.png +0 -0
  447. data/public/images/admin/menu/right.png +0 -0
  448. data/public/images/admin/menu/shadow.png +0 -0
  449. data/public/images/admin/menu/top-left.png +0 -0
  450. data/public/images/admin/menu/top.png +0 -0
  451. data/public/images/admin/nocoffee.gif +0 -0
  452. data/public/images/admin/plugins/fancybox/blank.gif +0 -0
  453. data/public/images/admin/plugins/fancybox/fancy_close.png +0 -0
  454. data/public/images/admin/plugins/fancybox/fancy_loading.png +0 -0
  455. data/public/images/admin/plugins/fancybox/fancy_nav_left.png +0 -0
  456. data/public/images/admin/plugins/fancybox/fancy_nav_right.png +0 -0
  457. data/public/images/admin/plugins/fancybox/fancy_shadow_e.png +0 -0
  458. data/public/images/admin/plugins/fancybox/fancy_shadow_n.png +0 -0
  459. data/public/images/admin/plugins/fancybox/fancy_shadow_ne.png +0 -0
  460. data/public/images/admin/plugins/fancybox/fancy_shadow_nw.png +0 -0
  461. data/public/images/admin/plugins/fancybox/fancy_shadow_s.png +0 -0
  462. data/public/images/admin/plugins/fancybox/fancy_shadow_se.png +0 -0
  463. data/public/images/admin/plugins/fancybox/fancy_shadow_sw.png +0 -0
  464. data/public/images/admin/plugins/fancybox/fancy_shadow_w.png +0 -0
  465. data/public/images/admin/plugins/fancybox/fancy_title_left.png +0 -0
  466. data/public/images/admin/plugins/fancybox/fancy_title_main.png +0 -0
  467. data/public/images/admin/plugins/fancybox/fancy_title_over.png +0 -0
  468. data/public/images/admin/plugins/fancybox/fancy_title_right.png +0 -0
  469. data/public/images/admin/plugins/fancybox/fancybox-x.png +0 -0
  470. data/public/images/admin/plugins/fancybox/fancybox-y.png +0 -0
  471. data/public/images/admin/plugins/fancybox/fancybox.png +0 -0
  472. data/public/images/admin/plugins/toggle_handle-bg.png +0 -0
  473. data/public/images/admin/plugins/toggle_handle_left-bg.png +0 -0
  474. data/public/images/admin/plugins/toggle_handle_right-bg.png +0 -0
  475. data/public/images/admin/plugins/toggle_shadow-bg.png +0 -0
  476. data/public/images/admin/rails.png +0 -0
  477. data/public/javascripts/admin/application.js +105 -0
  478. data/public/javascripts/admin/asset_collections.js +50 -0
  479. data/public/javascripts/admin/content_types.js +16 -0
  480. data/public/javascripts/admin/contents.js +17 -0
  481. data/public/javascripts/admin/custom_fields.js +113 -0
  482. data/public/javascripts/admin/jquery.js +154 -0
  483. data/public/javascripts/admin/jquery.ui.js +404 -0
  484. data/public/javascripts/admin/page_parts.js +83 -0
  485. data/public/javascripts/admin/pages.js +67 -0
  486. data/public/javascripts/admin/plugins/codemirror/codemirror.js +469 -0
  487. data/public/javascripts/admin/plugins/codemirror/editor.js +1465 -0
  488. data/public/javascripts/admin/plugins/codemirror/highlight.js +68 -0
  489. data/public/javascripts/admin/plugins/codemirror/mirrorframe.js +81 -0
  490. data/public/javascripts/admin/plugins/codemirror/parsecss.js +155 -0
  491. data/public/javascripts/admin/plugins/codemirror/parsedummy.js +32 -0
  492. data/public/javascripts/admin/plugins/codemirror/parsehtmlmixed.js +74 -0
  493. data/public/javascripts/admin/plugins/codemirror/parsejavascript.js +352 -0
  494. data/public/javascripts/admin/plugins/codemirror/parseliquid.js +409 -0
  495. data/public/javascripts/admin/plugins/codemirror/parsesparql.js +162 -0
  496. data/public/javascripts/admin/plugins/codemirror/parsexml.js +286 -0
  497. data/public/javascripts/admin/plugins/codemirror/select.js +619 -0
  498. data/public/javascripts/admin/plugins/codemirror/stringstream.js +140 -0
  499. data/public/javascripts/admin/plugins/codemirror/tokenize.js +57 -0
  500. data/public/javascripts/admin/plugins/codemirror/tokenizejavascript.js +174 -0
  501. data/public/javascripts/admin/plugins/codemirror/undo.js +410 -0
  502. data/public/javascripts/admin/plugins/codemirror/util.js +130 -0
  503. data/public/javascripts/admin/plugins/cookie.js +96 -0
  504. data/public/javascripts/admin/plugins/fancybox.js +1077 -0
  505. data/public/javascripts/admin/plugins/growl.js +143 -0
  506. data/public/javascripts/admin/plugins/json2.js +478 -0
  507. data/public/javascripts/admin/plugins/plupload/gears_init.js +86 -0
  508. data/public/javascripts/admin/plugins/plupload/jquery.plupload.queue.min.js +1 -0
  509. data/public/javascripts/admin/plugins/plupload/plupload.browserplus.min.js +1 -0
  510. data/public/javascripts/admin/plugins/plupload/plupload.flash.min.js +1 -0
  511. data/public/javascripts/admin/plugins/plupload/plupload.flash.swf +0 -0
  512. data/public/javascripts/admin/plugins/plupload/plupload.full.js +1 -0
  513. data/public/javascripts/admin/plugins/plupload/plupload.gears.min.js +1 -0
  514. data/public/javascripts/admin/plugins/plupload/plupload.html4.min.js +1 -0
  515. data/public/javascripts/admin/plugins/plupload/plupload.html5.min.js +1 -0
  516. data/public/javascripts/admin/plugins/plupload/plupload.js +1 -0
  517. data/public/javascripts/admin/plugins/plupload/plupload.silverlight.min.js +1 -0
  518. data/public/javascripts/admin/plugins/plupload/plupload.silverlight.xap +0 -0
  519. data/public/javascripts/admin/plugins/scrollTo.js +11 -0
  520. data/public/javascripts/admin/plugins/toggle.js +109 -0
  521. data/public/javascripts/admin/plugins/wslide.js +125 -0
  522. data/public/javascripts/admin/rails.js +127 -0
  523. data/public/javascripts/admin/site.js +36 -0
  524. data/public/javascripts/admin/snippets.js +16 -0
  525. data/public/javascripts/admin/theme_assets.js +103 -0
  526. data/public/stylesheets/admin/application.css +257 -0
  527. data/public/stylesheets/admin/blueprint/ie.css +26 -0
  528. data/public/stylesheets/admin/blueprint/plugins/buttons/icons/cross.png +0 -0
  529. data/public/stylesheets/admin/blueprint/plugins/buttons/icons/key.png +0 -0
  530. data/public/stylesheets/admin/blueprint/plugins/buttons/icons/tick.png +0 -0
  531. data/public/stylesheets/admin/blueprint/plugins/buttons/readme.txt +32 -0
  532. data/public/stylesheets/admin/blueprint/plugins/buttons/screen.css +97 -0
  533. data/public/stylesheets/admin/blueprint/plugins/fancy-type/readme.txt +14 -0
  534. data/public/stylesheets/admin/blueprint/plugins/fancy-type/screen.css +71 -0
  535. data/public/stylesheets/admin/blueprint/plugins/link-icons/icons/doc.png +0 -0
  536. data/public/stylesheets/admin/blueprint/plugins/link-icons/icons/email.png +0 -0
  537. data/public/stylesheets/admin/blueprint/plugins/link-icons/icons/external.png +0 -0
  538. data/public/stylesheets/admin/blueprint/plugins/link-icons/icons/feed.png +0 -0
  539. data/public/stylesheets/admin/blueprint/plugins/link-icons/icons/im.png +0 -0
  540. data/public/stylesheets/admin/blueprint/plugins/link-icons/icons/pdf.png +0 -0
  541. data/public/stylesheets/admin/blueprint/plugins/link-icons/icons/visited.png +0 -0
  542. data/public/stylesheets/admin/blueprint/plugins/link-icons/icons/xls.png +0 -0
  543. data/public/stylesheets/admin/blueprint/plugins/link-icons/readme.txt +18 -0
  544. data/public/stylesheets/admin/blueprint/plugins/link-icons/screen.css +40 -0
  545. data/public/stylesheets/admin/blueprint/plugins/rtl/readme.txt +10 -0
  546. data/public/stylesheets/admin/blueprint/plugins/rtl/screen.css +109 -0
  547. data/public/stylesheets/admin/blueprint/print.css +30 -0
  548. data/public/stylesheets/admin/blueprint/screen.css +253 -0
  549. data/public/stylesheets/admin/blueprint/src/forms.css +49 -0
  550. data/public/stylesheets/admin/blueprint/src/grid.css +213 -0
  551. data/public/stylesheets/admin/blueprint/src/grid.png +0 -0
  552. data/public/stylesheets/admin/blueprint/src/ie.css +59 -0
  553. data/public/stylesheets/admin/blueprint/src/print.css +85 -0
  554. data/public/stylesheets/admin/blueprint/src/reset.css +38 -0
  555. data/public/stylesheets/admin/blueprint/src/typography.css +105 -0
  556. data/public/stylesheets/admin/box.css +14 -0
  557. data/public/stylesheets/admin/buttons.css +67 -0
  558. data/public/stylesheets/admin/formtastic.css +137 -0
  559. data/public/stylesheets/admin/formtastic_changes.css +461 -0
  560. data/public/stylesheets/admin/layout.css +175 -0
  561. data/public/stylesheets/admin/login.css +141 -0
  562. data/public/stylesheets/admin/menu.css +241 -0
  563. data/public/stylesheets/admin/page_parts.css +60 -0
  564. data/public/stylesheets/admin/plugins/codemirror/csscolors.css +51 -0
  565. data/public/stylesheets/admin/plugins/codemirror/docs.css +50 -0
  566. data/public/stylesheets/admin/plugins/codemirror/javascriptcolors.css +56 -0
  567. data/public/stylesheets/admin/plugins/codemirror/jscolors.css +59 -0
  568. data/public/stylesheets/admin/plugins/codemirror/liquidcolors.css +35 -0
  569. data/public/stylesheets/admin/plugins/codemirror/people.jpg +0 -0
  570. data/public/stylesheets/admin/plugins/codemirror/sparqlcolors.css +43 -0
  571. data/public/stylesheets/admin/plugins/codemirror/xmlcolors.css +55 -0
  572. data/public/stylesheets/admin/plugins/fancybox.css +363 -0
  573. data/public/stylesheets/admin/plugins/toggle.css +42 -0
  574. data/spec/factories.rb +77 -0
  575. data/spec/lib/locomotive/liquid/filters/html_spec.rb +82 -0
  576. data/spec/lib/locomotive/liquid/filters/misc_spec.rb +36 -0
  577. data/spec/lib/locomotive/liquid/tags/paginate_spec.rb +99 -0
  578. data/spec/lib/locomotive/liquid/tags/snippet_spec.rb +20 -0
  579. data/spec/lib/locomotive/liquid/tags/with_scope_spec.rb +20 -0
  580. data/spec/lib/locomotive/render_spec.rb +85 -0
  581. data/spec/models/account_spec.rb +65 -0
  582. data/spec/models/asset_collections_spec.rb +174 -0
  583. data/spec/models/content_instance_spec.rb +33 -0
  584. data/spec/models/content_type_spec.rb +49 -0
  585. data/spec/models/layout_spec.rb +64 -0
  586. data/spec/models/liquid_template_spec.rb +19 -0
  587. data/spec/models/membership_spec.rb +55 -0
  588. data/spec/models/page_spec.rb +329 -0
  589. data/spec/models/site_spec.rb +143 -0
  590. data/spec/models/snippet_spec.rb +9 -0
  591. data/spec/models/theme_asset_spec.rb +89 -0
  592. data/spec/spec_helper.rb +17 -0
  593. data/spec/support/be_valid.rb +31 -0
  594. data/spec/support/carrierwave.rb +32 -0
  595. data/spec/support/locomotive.rb +41 -0
  596. data/vendor/plugins/custom_fields/MIT-LICENSE +20 -0
  597. data/vendor/plugins/custom_fields/README +13 -0
  598. data/vendor/plugins/custom_fields/Rakefile +23 -0
  599. data/vendor/plugins/custom_fields/init.rb +2 -0
  600. data/vendor/plugins/custom_fields/install.rb +1 -0
  601. data/vendor/plugins/custom_fields/lib/custom_fields.rb +14 -0
  602. data/vendor/plugins/custom_fields/lib/custom_fields/custom_field.rb +84 -0
  603. data/vendor/plugins/custom_fields/lib/custom_fields/custom_fields_for.rb +49 -0
  604. data/vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/embeds_many.rb +24 -0
  605. data/vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/document.rb +35 -0
  606. data/vendor/plugins/custom_fields/uninstall.rb +1 -0
  607. metadata +848 -0
@@ -0,0 +1,286 @@
1
+ /* This file defines an XML parser, with a few kludges to make it
2
+ * useable for HTML. autoSelfClosers defines a set of tag names that
3
+ * are expected to not have a closing tag, and doNotIndent specifies
4
+ * the tags inside of which no indentation should happen (see Config
5
+ * object). These can be disabled by passing the editor an object like
6
+ * {useHTMLKludges: false} as parserConfig option.
7
+ */
8
+
9
+ var XMLParser = Editor.Parser = (function() {
10
+ var Kludges = {
11
+ autoSelfClosers: {"br": true, "img": true, "hr": true, "link": true, "input": true,
12
+ "meta": true, "col": true, "frame": true, "base": true, "area": true},
13
+ doNotIndent: {"pre": true, "!cdata": true}
14
+ };
15
+ var NoKludges = {autoSelfClosers: {}, doNotIndent: {"!cdata": true}};
16
+ var UseKludges = Kludges;
17
+ var alignCDATA = false;
18
+
19
+ // Simple stateful tokenizer for XML documents. Returns a
20
+ // MochiKit-style iterator, with a state property that contains a
21
+ // function encapsulating the current state. See tokenize.js.
22
+ var tokenizeXML = (function() {
23
+ function inText(source, setState) {
24
+ var ch = source.next();
25
+ if (ch == "<") {
26
+ if (source.equals("!")) {
27
+ source.next();
28
+ if (source.equals("[")) {
29
+ if (source.lookAhead("[CDATA[", true)) {
30
+ setState(inBlock("xml-cdata", "]]>"));
31
+ return null;
32
+ }
33
+ else {
34
+ return "xml-text";
35
+ }
36
+ }
37
+ else if (source.lookAhead("--", true)) {
38
+ setState(inBlock("xml-comment", "-->"));
39
+ return null;
40
+ }
41
+ else {
42
+ return "xml-text";
43
+ }
44
+ }
45
+ else if (source.equals("?")) {
46
+ source.next();
47
+ source.nextWhileMatches(/[\w\._\-]/);
48
+ setState(inBlock("xml-processing", "?>"));
49
+ return "xml-processing";
50
+ }
51
+ else {
52
+ if (source.equals("/")) source.next();
53
+ setState(inTag);
54
+ return "xml-punctuation";
55
+ }
56
+ }
57
+ else if (ch == "&") {
58
+ while (!source.endOfLine()) {
59
+ if (source.next() == ";")
60
+ break;
61
+ }
62
+ return "xml-entity";
63
+ }
64
+ else {
65
+ source.nextWhileMatches(/[^&<\n]/);
66
+ return "xml-text";
67
+ }
68
+ }
69
+
70
+ function inTag(source, setState) {
71
+ var ch = source.next();
72
+ if (ch == ">") {
73
+ setState(inText);
74
+ return "xml-punctuation";
75
+ }
76
+ else if (/[?\/]/.test(ch) && source.equals(">")) {
77
+ source.next();
78
+ setState(inText);
79
+ return "xml-punctuation";
80
+ }
81
+ else if (ch == "=") {
82
+ return "xml-punctuation";
83
+ }
84
+ else if (/[\'\"]/.test(ch)) {
85
+ setState(inAttribute(ch));
86
+ return null;
87
+ }
88
+ else {
89
+ source.nextWhileMatches(/[^\s\u00a0=<>\"\'\/?]/);
90
+ return "xml-name";
91
+ }
92
+ }
93
+
94
+ function inAttribute(quote) {
95
+ return function(source, setState) {
96
+ while (!source.endOfLine()) {
97
+ if (source.next() == quote) {
98
+ setState(inTag);
99
+ break;
100
+ }
101
+ }
102
+ return "xml-attribute";
103
+ };
104
+ }
105
+
106
+ function inBlock(style, terminator) {
107
+ return function(source, setState) {
108
+ while (!source.endOfLine()) {
109
+ if (source.lookAhead(terminator, true)) {
110
+ setState(inText);
111
+ break;
112
+ }
113
+ source.next();
114
+ }
115
+ return style;
116
+ };
117
+ }
118
+
119
+ return function(source, startState) {
120
+ return tokenizer(source, startState || inText);
121
+ };
122
+ })();
123
+
124
+ // The parser. The structure of this function largely follows that of
125
+ // parseJavaScript in parsejavascript.js (there is actually a bit more
126
+ // shared code than I'd like), but it is quite a bit simpler.
127
+ function parseXML(source) {
128
+ var tokens = tokenizeXML(source), token;
129
+ var cc = [base];
130
+ var tokenNr = 0, indented = 0;
131
+ var currentTag = null, context = null;
132
+ var consume;
133
+
134
+ function push(fs) {
135
+ for (var i = fs.length - 1; i >= 0; i--)
136
+ cc.push(fs[i]);
137
+ }
138
+ function cont() {
139
+ push(arguments);
140
+ consume = true;
141
+ }
142
+ function pass() {
143
+ push(arguments);
144
+ consume = false;
145
+ }
146
+
147
+ function markErr() {
148
+ token.style += " xml-error";
149
+ }
150
+ function expect(text) {
151
+ return function(style, content) {
152
+ if (content == text) cont();
153
+ else {markErr(); cont(arguments.callee);}
154
+ };
155
+ }
156
+
157
+ function pushContext(tagname, startOfLine) {
158
+ var noIndent = UseKludges.doNotIndent.hasOwnProperty(tagname) || (context && context.noIndent);
159
+ context = {prev: context, name: tagname, indent: indented, startOfLine: startOfLine, noIndent: noIndent};
160
+ }
161
+ function popContext() {
162
+ context = context.prev;
163
+ }
164
+ function computeIndentation(baseContext) {
165
+ return function(nextChars, current) {
166
+ var context = baseContext;
167
+ if (context && context.noIndent)
168
+ return current;
169
+ if (alignCDATA && /<!\[CDATA\[/.test(nextChars))
170
+ return 0;
171
+ if (context && /^<\//.test(nextChars))
172
+ context = context.prev;
173
+ while (context && !context.startOfLine)
174
+ context = context.prev;
175
+ if (context)
176
+ return context.indent + indentUnit;
177
+ else
178
+ return 0;
179
+ };
180
+ }
181
+
182
+ function base() {
183
+ return pass(element, base);
184
+ }
185
+ var harmlessTokens = {"xml-text": true, "xml-entity": true, "xml-comment": true, "xml-processing": true};
186
+ function element(style, content) {
187
+ if (content == "<") cont(tagname, attributes, endtag(tokenNr == 1));
188
+ else if (content == "</") cont(closetagname, expect(">"));
189
+ else if (style == "xml-cdata") {
190
+ if (!context || context.name != "!cdata") pushContext("!cdata");
191
+ if (/\]\]>$/.test(content)) popContext();
192
+ cont();
193
+ }
194
+ else if (harmlessTokens.hasOwnProperty(style)) cont();
195
+ else {markErr(); cont();}
196
+ }
197
+ function tagname(style, content) {
198
+ if (style == "xml-name") {
199
+ currentTag = content.toLowerCase();
200
+ token.style = "xml-tagname";
201
+ cont();
202
+ }
203
+ else {
204
+ currentTag = null;
205
+ pass();
206
+ }
207
+ }
208
+ function closetagname(style, content) {
209
+ if (style == "xml-name") {
210
+ token.style = "xml-tagname";
211
+ if (context && content.toLowerCase() == context.name) popContext();
212
+ else markErr();
213
+ }
214
+ cont();
215
+ }
216
+ function endtag(startOfLine) {
217
+ return function(style, content) {
218
+ if (content == "/>" || (content == ">" && UseKludges.autoSelfClosers.hasOwnProperty(currentTag))) cont();
219
+ else if (content == ">") {pushContext(currentTag, startOfLine); cont();}
220
+ else {markErr(); cont(arguments.callee);}
221
+ };
222
+ }
223
+ function attributes(style) {
224
+ if (style == "xml-name") {token.style = "xml-attname"; cont(attribute, attributes);}
225
+ else pass();
226
+ }
227
+ function attribute(style, content) {
228
+ if (content == "=") cont(value);
229
+ else if (content == ">" || content == "/>") pass(endtag);
230
+ else pass();
231
+ }
232
+ function value(style) {
233
+ if (style == "xml-attribute") cont(value);
234
+ else pass();
235
+ }
236
+
237
+ return {
238
+ indentation: function() {return indented;},
239
+
240
+ next: function(){
241
+ token = tokens.next();
242
+ if (token.style == "whitespace" && tokenNr == 0)
243
+ indented = token.value.length;
244
+ else
245
+ tokenNr++;
246
+ if (token.content == "\n") {
247
+ indented = tokenNr = 0;
248
+ token.indentation = computeIndentation(context);
249
+ }
250
+
251
+ if (token.style == "whitespace" || token.type == "xml-comment")
252
+ return token;
253
+
254
+ while(true){
255
+ consume = false;
256
+ cc.pop()(token.style, token.content);
257
+ if (consume) return token;
258
+ }
259
+ },
260
+
261
+ copy: function(){
262
+ var _cc = cc.concat([]), _tokenState = tokens.state, _context = context;
263
+ var parser = this;
264
+
265
+ return function(input){
266
+ cc = _cc.concat([]);
267
+ tokenNr = indented = 0;
268
+ context = _context;
269
+ tokens = tokenizeXML(input, _tokenState);
270
+ return parser;
271
+ };
272
+ }
273
+ };
274
+ }
275
+
276
+ return {
277
+ make: parseXML,
278
+ electricChars: "/",
279
+ configure: function(config) {
280
+ if (config.useHTMLKludges != null)
281
+ UseKludges = config.useHTMLKludges ? Kludges : NoKludges;
282
+ if (config.alignCDATA)
283
+ alignCDATA = config.alignCDATA;
284
+ }
285
+ };
286
+ })();
@@ -0,0 +1,619 @@
1
+ /* Functionality for finding, storing, and restoring selections
2
+ *
3
+ * This does not provide a generic API, just the minimal functionality
4
+ * required by the CodeMirror system.
5
+ */
6
+
7
+ // Namespace object.
8
+ var select = {};
9
+
10
+ (function() {
11
+ select.ie_selection = document.selection && document.selection.createRangeCollection;
12
+
13
+ // Find the 'top-level' (defined as 'a direct child of the node
14
+ // passed as the top argument') node that the given node is
15
+ // contained in. Return null if the given node is not inside the top
16
+ // node.
17
+ function topLevelNodeAt(node, top) {
18
+ while (node && node.parentNode != top)
19
+ node = node.parentNode;
20
+ return node;
21
+ }
22
+
23
+ // Find the top-level node that contains the node before this one.
24
+ function topLevelNodeBefore(node, top) {
25
+ while (!node.previousSibling && node.parentNode != top)
26
+ node = node.parentNode;
27
+ return topLevelNodeAt(node.previousSibling, top);
28
+ }
29
+
30
+ var fourSpaces = "\u00a0\u00a0\u00a0\u00a0";
31
+
32
+ select.scrollToNode = function(element) {
33
+ if (!element) return;
34
+ var doc = element.ownerDocument, body = doc.body,
35
+ win = (doc.defaultView || doc.parentWindow),
36
+ html = doc.documentElement,
37
+ atEnd = !element.nextSibling || !element.nextSibling.nextSibling
38
+ || !element.nextSibling.nextSibling.nextSibling;
39
+ // In Opera (and recent Webkit versions), BR elements *always*
40
+ // have a offsetTop property of zero.
41
+ var compensateHack = 0;
42
+ while (element && !element.offsetTop) {
43
+ compensateHack++;
44
+ element = element.previousSibling;
45
+ }
46
+ // atEnd is another kludge for these browsers -- if the cursor is
47
+ // at the end of the document, and the node doesn't have an
48
+ // offset, just scroll to the end.
49
+ if (compensateHack == 0) atEnd = false;
50
+
51
+ var y = compensateHack * (element ? element.offsetHeight : 0), x = 0, pos = element;
52
+ while (pos && pos.offsetParent) {
53
+ y += pos.offsetTop;
54
+ // Don't count X offset for <br> nodes
55
+ if (!isBR(pos))
56
+ x += pos.offsetLeft;
57
+ pos = pos.offsetParent;
58
+ }
59
+
60
+ var scroll_x = body.scrollLeft || html.scrollLeft || 0,
61
+ scroll_y = body.scrollTop || html.scrollTop || 0,
62
+ screen_x = x - scroll_x, screen_y = y - scroll_y, scroll = false;
63
+
64
+ if (screen_x < 0 || screen_x > (win.innerWidth || html.clientWidth || 0)) {
65
+ scroll_x = x;
66
+ scroll = true;
67
+ }
68
+ if (screen_y < 0 || atEnd || screen_y > (win.innerHeight || html.clientHeight || 0) - 50) {
69
+ scroll_y = atEnd ? 1e6 : y;
70
+ scroll = true;
71
+ }
72
+ if (scroll) win.scrollTo(scroll_x, scroll_y);
73
+ };
74
+
75
+ select.scrollToCursor = function(container) {
76
+ select.scrollToNode(select.selectionTopNode(container, true) || container.firstChild);
77
+ };
78
+
79
+ // Used to prevent restoring a selection when we do not need to.
80
+ var currentSelection = null;
81
+
82
+ select.snapshotChanged = function() {
83
+ if (currentSelection) currentSelection.changed = true;
84
+ };
85
+
86
+ // This is called by the code in editor.js whenever it is replacing
87
+ // a text node. The function sees whether the given oldNode is part
88
+ // of the current selection, and updates this selection if it is.
89
+ // Because nodes are often only partially replaced, the length of
90
+ // the part that gets replaced has to be taken into account -- the
91
+ // selection might stay in the oldNode if the newNode is smaller
92
+ // than the selection's offset. The offset argument is needed in
93
+ // case the selection does move to the new object, and the given
94
+ // length is not the whole length of the new node (part of it might
95
+ // have been used to replace another node).
96
+ select.snapshotReplaceNode = function(from, to, length, offset) {
97
+ if (!currentSelection) return;
98
+
99
+ function replace(point) {
100
+ if (from == point.node) {
101
+ currentSelection.changed = true;
102
+ if (length && point.offset > length) {
103
+ point.offset -= length;
104
+ }
105
+ else {
106
+ point.node = to;
107
+ point.offset += (offset || 0);
108
+ }
109
+ }
110
+ }
111
+ replace(currentSelection.start);
112
+ replace(currentSelection.end);
113
+ };
114
+
115
+ select.snapshotMove = function(from, to, distance, relative, ifAtStart) {
116
+ if (!currentSelection) return;
117
+
118
+ function move(point) {
119
+ if (from == point.node && (!ifAtStart || point.offset == 0)) {
120
+ currentSelection.changed = true;
121
+ point.node = to;
122
+ if (relative) point.offset = Math.max(0, point.offset + distance);
123
+ else point.offset = distance;
124
+ }
125
+ }
126
+ move(currentSelection.start);
127
+ move(currentSelection.end);
128
+ };
129
+
130
+ // Most functions are defined in two ways, one for the IE selection
131
+ // model, one for the W3C one.
132
+ if (select.ie_selection) {
133
+ function selectionNode(win, start) {
134
+ var range = win.document.selection.createRange();
135
+ range.collapse(start);
136
+
137
+ function nodeAfter(node) {
138
+ var found = null;
139
+ while (!found && node) {
140
+ found = node.nextSibling;
141
+ node = node.parentNode;
142
+ }
143
+ return nodeAtStartOf(found);
144
+ }
145
+
146
+ function nodeAtStartOf(node) {
147
+ while (node && node.firstChild) node = node.firstChild;
148
+ return {node: node, offset: 0};
149
+ }
150
+
151
+ var containing = range.parentElement();
152
+ if (!isAncestor(win.document.body, containing)) return null;
153
+ if (!containing.firstChild) return nodeAtStartOf(containing);
154
+
155
+ var working = range.duplicate();
156
+ working.moveToElementText(containing);
157
+ working.collapse(true);
158
+ for (var cur = containing.firstChild; cur; cur = cur.nextSibling) {
159
+ if (cur.nodeType == 3) {
160
+ var size = cur.nodeValue.length;
161
+ working.move("character", size);
162
+ }
163
+ else {
164
+ working.moveToElementText(cur);
165
+ working.collapse(false);
166
+ }
167
+
168
+ var dir = range.compareEndPoints("StartToStart", working);
169
+ if (dir == 0) return nodeAfter(cur);
170
+ if (dir == 1) continue;
171
+ if (cur.nodeType != 3) return nodeAtStartOf(cur);
172
+
173
+ working.setEndPoint("StartToEnd", range);
174
+ return {node: cur, offset: size - working.text.length};
175
+ }
176
+ return nodeAfter(containing);
177
+ }
178
+
179
+ select.markSelection = function(win) {
180
+ currentSelection = null;
181
+ var sel = win.document.selection;
182
+ if (!sel) return;
183
+ var start = selectionNode(win, true),
184
+ end = selectionNode(win, false);
185
+ if (!start || !end) return;
186
+ currentSelection = {start: start, end: end, window: win, changed: false};
187
+ };
188
+
189
+ select.selectMarked = function() {
190
+ if (!currentSelection || !currentSelection.changed) return;
191
+ var win = currentSelection.window, doc = win.document;
192
+
193
+ function makeRange(point) {
194
+ var range = doc.body.createTextRange(),
195
+ node = point.node;
196
+ if (!node) {
197
+ range.moveToElementText(currentSelection.window.document.body);
198
+ range.collapse(false);
199
+ }
200
+ else if (node.nodeType == 3) {
201
+ range.moveToElementText(node.parentNode);
202
+ var offset = point.offset;
203
+ while (node.previousSibling) {
204
+ node = node.previousSibling;
205
+ offset += (node.innerText || "").length;
206
+ }
207
+ range.move("character", offset);
208
+ }
209
+ else {
210
+ range.moveToElementText(node);
211
+ range.collapse(true);
212
+ }
213
+ return range;
214
+ }
215
+
216
+ var start = makeRange(currentSelection.start), end = makeRange(currentSelection.end);
217
+ start.setEndPoint("StartToEnd", end);
218
+ start.select();
219
+ };
220
+
221
+ // Get the top-level node that one end of the cursor is inside or
222
+ // after. Note that this returns false for 'no cursor', and null
223
+ // for 'start of document'.
224
+ select.selectionTopNode = function(container, start) {
225
+ var selection = container.ownerDocument.selection;
226
+ if (!selection) return false;
227
+
228
+ var range = selection.createRange(), range2 = range.duplicate();
229
+ range.collapse(start);
230
+ var around = range.parentElement();
231
+ if (around && isAncestor(container, around)) {
232
+ // Only use this node if the selection is not at its start.
233
+ range2.moveToElementText(around);
234
+ if (range.compareEndPoints("StartToStart", range2) == 1)
235
+ return topLevelNodeAt(around, container);
236
+ }
237
+
238
+ // Move the start of a range to the start of a node,
239
+ // compensating for the fact that you can't call
240
+ // moveToElementText with text nodes.
241
+ function moveToNodeStart(range, node) {
242
+ if (node.nodeType == 3) {
243
+ var count = 0, cur = node.previousSibling;
244
+ while (cur && cur.nodeType == 3) {
245
+ count += cur.nodeValue.length;
246
+ cur = cur.previousSibling;
247
+ }
248
+ if (cur) {
249
+ try{range.moveToElementText(cur);}
250
+ catch(e){return false;}
251
+ range.collapse(false);
252
+ }
253
+ else range.moveToElementText(node.parentNode);
254
+ if (count) range.move("character", count);
255
+ }
256
+ else {
257
+ try{range.moveToElementText(node);}
258
+ catch(e){return false;}
259
+ }
260
+ return true;
261
+ }
262
+
263
+ // Do a binary search through the container object, comparing
264
+ // the start of each node to the selection
265
+ var start = 0, end = container.childNodes.length - 1;
266
+ while (start < end) {
267
+ var middle = Math.ceil((end + start) / 2), node = container.childNodes[middle];
268
+ if (!node) return false; // Don't ask. IE6 manages this sometimes.
269
+ if (!moveToNodeStart(range2, node)) return false;
270
+ if (range.compareEndPoints("StartToStart", range2) == 1)
271
+ start = middle;
272
+ else
273
+ end = middle - 1;
274
+ }
275
+ return container.childNodes[start] || null;
276
+ };
277
+
278
+ // Place the cursor after this.start. This is only useful when
279
+ // manually moving the cursor instead of restoring it to its old
280
+ // position.
281
+ select.focusAfterNode = function(node, container) {
282
+ var range = container.ownerDocument.body.createTextRange();
283
+ range.moveToElementText(node || container);
284
+ range.collapse(!node);
285
+ range.select();
286
+ };
287
+
288
+ select.somethingSelected = function(win) {
289
+ var sel = win.document.selection;
290
+ return sel && (sel.createRange().text != "");
291
+ };
292
+
293
+ function insertAtCursor(window, html) {
294
+ var selection = window.document.selection;
295
+ if (selection) {
296
+ var range = selection.createRange();
297
+ range.pasteHTML(html);
298
+ range.collapse(false);
299
+ range.select();
300
+ }
301
+ }
302
+
303
+ // Used to normalize the effect of the enter key, since browsers
304
+ // do widely different things when pressing enter in designMode.
305
+ select.insertNewlineAtCursor = function(window) {
306
+ insertAtCursor(window, "<br>");
307
+ };
308
+
309
+ select.insertTabAtCursor = function(window) {
310
+ insertAtCursor(window, fourSpaces);
311
+ };
312
+
313
+ // Get the BR node at the start of the line on which the cursor
314
+ // currently is, and the offset into the line. Returns null as
315
+ // node if cursor is on first line.
316
+ select.cursorPos = function(container, start) {
317
+ var selection = container.ownerDocument.selection;
318
+ if (!selection) return null;
319
+
320
+ var topNode = select.selectionTopNode(container, start);
321
+ while (topNode && !isBR(topNode))
322
+ topNode = topNode.previousSibling;
323
+
324
+ var range = selection.createRange(), range2 = range.duplicate();
325
+ range.collapse(start);
326
+ if (topNode) {
327
+ range2.moveToElementText(topNode);
328
+ range2.collapse(false);
329
+ }
330
+ else {
331
+ // When nothing is selected, we can get all kinds of funky errors here.
332
+ try { range2.moveToElementText(container); }
333
+ catch (e) { return null; }
334
+ range2.collapse(true);
335
+ }
336
+ range.setEndPoint("StartToStart", range2);
337
+
338
+ return {node: topNode, offset: range.text.length};
339
+ };
340
+
341
+ select.setCursorPos = function(container, from, to) {
342
+ function rangeAt(pos) {
343
+ var range = container.ownerDocument.body.createTextRange();
344
+ if (!pos.node) {
345
+ range.moveToElementText(container);
346
+ range.collapse(true);
347
+ }
348
+ else {
349
+ range.moveToElementText(pos.node);
350
+ range.collapse(false);
351
+ }
352
+ range.move("character", pos.offset);
353
+ return range;
354
+ }
355
+
356
+ var range = rangeAt(from);
357
+ if (to && to != from)
358
+ range.setEndPoint("EndToEnd", rangeAt(to));
359
+ range.select();
360
+ }
361
+
362
+ // Some hacks for storing and re-storing the selection when the editor loses and regains focus.
363
+ select.getBookmark = function (container) {
364
+ var from = select.cursorPos(container, true), to = select.cursorPos(container, false);
365
+ if (from && to) return {from: from, to: to};
366
+ };
367
+
368
+ // Restore a stored selection.
369
+ select.setBookmark = function(container, mark) {
370
+ if (!mark) return;
371
+ select.setCursorPos(container, mark.from, mark.to);
372
+ };
373
+ }
374
+ // W3C model
375
+ else {
376
+ // Store start and end nodes, and offsets within these, and refer
377
+ // back to the selection object from those nodes, so that this
378
+ // object can be updated when the nodes are replaced before the
379
+ // selection is restored.
380
+ select.markSelection = function (win) {
381
+ var selection = win.getSelection();
382
+ if (!selection || selection.rangeCount == 0)
383
+ return (currentSelection = null);
384
+ var range = selection.getRangeAt(0);
385
+
386
+ currentSelection = {
387
+ start: {node: range.startContainer, offset: range.startOffset},
388
+ end: {node: range.endContainer, offset: range.endOffset},
389
+ window: win,
390
+ changed: false
391
+ };
392
+
393
+ // We want the nodes right at the cursor, not one of their
394
+ // ancestors with a suitable offset. This goes down the DOM tree
395
+ // until a 'leaf' is reached (or is it *up* the DOM tree?).
396
+ function normalize(point){
397
+ while (point.node.nodeType != 3 && !isBR(point.node)) {
398
+ var newNode = point.node.childNodes[point.offset] || point.node.nextSibling;
399
+ point.offset = 0;
400
+ while (!newNode && point.node.parentNode) {
401
+ point.node = point.node.parentNode;
402
+ newNode = point.node.nextSibling;
403
+ }
404
+ point.node = newNode;
405
+ if (!newNode)
406
+ break;
407
+ }
408
+ }
409
+
410
+ normalize(currentSelection.start);
411
+ normalize(currentSelection.end);
412
+ };
413
+
414
+ select.selectMarked = function () {
415
+ var cs = currentSelection;
416
+ // on webkit-based browsers, it is apparently possible that the
417
+ // selection gets reset even when a node that is not one of the
418
+ // endpoints get messed with. the most common situation where
419
+ // this occurs is when a selection is deleted or overwitten. we
420
+ // check for that here.
421
+ function focusIssue() {
422
+ return cs.start.node == cs.end.node && cs.start.offset == 0 && cs.end.offset == 0;
423
+ }
424
+ if (!cs || !(cs.changed || (webkit && focusIssue()))) return;
425
+ var win = cs.window, range = win.document.createRange();
426
+
427
+ function setPoint(point, which) {
428
+ if (point.node) {
429
+ // Some magic to generalize the setting of the start and end
430
+ // of a range.
431
+ if (point.offset == 0)
432
+ range["set" + which + "Before"](point.node);
433
+ else
434
+ range["set" + which](point.node, point.offset);
435
+ }
436
+ else {
437
+ range.setStartAfter(win.document.body.lastChild || win.document.body);
438
+ }
439
+ }
440
+
441
+ setPoint(cs.end, "End");
442
+ setPoint(cs.start, "Start");
443
+ selectRange(range, win);
444
+ };
445
+
446
+ // Helper for selecting a range object.
447
+ function selectRange(range, window) {
448
+ var selection = window.getSelection();
449
+ selection.removeAllRanges();
450
+ selection.addRange(range);
451
+ }
452
+ function selectionRange(window) {
453
+ var selection = window.getSelection();
454
+ if (!selection || selection.rangeCount == 0)
455
+ return false;
456
+ else
457
+ return selection.getRangeAt(0);
458
+ }
459
+
460
+ // Finding the top-level node at the cursor in the W3C is, as you
461
+ // can see, quite an involved process.
462
+ select.selectionTopNode = function(container, start) {
463
+ var range = selectionRange(container.ownerDocument.defaultView);
464
+ if (!range) return false;
465
+
466
+ var node = start ? range.startContainer : range.endContainer;
467
+ var offset = start ? range.startOffset : range.endOffset;
468
+ // Work around (yet another) bug in Opera's selection model.
469
+ if (window.opera && !start && range.endContainer == container && range.endOffset == range.startOffset + 1 &&
470
+ container.childNodes[range.startOffset] && isBR(container.childNodes[range.startOffset]))
471
+ offset--;
472
+
473
+ // For text nodes, we look at the node itself if the cursor is
474
+ // inside, or at the node before it if the cursor is at the
475
+ // start.
476
+ if (node.nodeType == 3){
477
+ if (offset > 0)
478
+ return topLevelNodeAt(node, container);
479
+ else
480
+ return topLevelNodeBefore(node, container);
481
+ }
482
+ // Occasionally, browsers will return the HTML node as
483
+ // selection. If the offset is 0, we take the start of the frame
484
+ // ('after null'), otherwise, we take the last node.
485
+ else if (node.nodeName.toUpperCase() == "HTML") {
486
+ return (offset == 1 ? null : container.lastChild);
487
+ }
488
+ // If the given node is our 'container', we just look up the
489
+ // correct node by using the offset.
490
+ else if (node == container) {
491
+ return (offset == 0) ? null : node.childNodes[offset - 1];
492
+ }
493
+ // In any other case, we have a regular node. If the cursor is
494
+ // at the end of the node, we use the node itself, if it is at
495
+ // the start, we use the node before it, and in any other
496
+ // case, we look up the child before the cursor and use that.
497
+ else {
498
+ if (offset == node.childNodes.length)
499
+ return topLevelNodeAt(node, container);
500
+ else if (offset == 0)
501
+ return topLevelNodeBefore(node, container);
502
+ else
503
+ return topLevelNodeAt(node.childNodes[offset - 1], container);
504
+ }
505
+ };
506
+
507
+ select.focusAfterNode = function(node, container) {
508
+ var win = container.ownerDocument.defaultView,
509
+ range = win.document.createRange();
510
+ range.setStartBefore(container.firstChild || container);
511
+ // In Opera, setting the end of a range at the end of a line
512
+ // (before a BR) will cause the cursor to appear on the next
513
+ // line, so we set the end inside of the start node when
514
+ // possible.
515
+ if (node && !node.firstChild)
516
+ range.setEndAfter(node);
517
+ else if (node)
518
+ range.setEnd(node, node.childNodes.length);
519
+ else
520
+ range.setEndBefore(container.firstChild || container);
521
+ range.collapse(false);
522
+ selectRange(range, win);
523
+ };
524
+
525
+ select.somethingSelected = function(win) {
526
+ var range = selectionRange(win);
527
+ return range && !range.collapsed;
528
+ };
529
+
530
+ function insertNodeAtCursor(window, node) {
531
+ var range = selectionRange(window);
532
+ if (!range) return;
533
+
534
+ range.deleteContents();
535
+ range.insertNode(node);
536
+ webkitLastLineHack(window.document.body);
537
+ range = window.document.createRange();
538
+ range.selectNode(node);
539
+ range.collapse(false);
540
+ selectRange(range, window);
541
+ }
542
+
543
+ select.insertNewlineAtCursor = function(window) {
544
+ insertNodeAtCursor(window, window.document.createElement("BR"));
545
+ };
546
+
547
+ select.insertTabAtCursor = function(window) {
548
+ insertNodeAtCursor(window, window.document.createTextNode(fourSpaces));
549
+ };
550
+
551
+ select.cursorPos = function(container, start) {
552
+ var range = selectionRange(window);
553
+ if (!range) return;
554
+
555
+ var topNode = select.selectionTopNode(container, start);
556
+ while (topNode && !isBR(topNode))
557
+ topNode = topNode.previousSibling;
558
+
559
+ range = range.cloneRange();
560
+ range.collapse(start);
561
+ if (topNode)
562
+ range.setStartAfter(topNode);
563
+ else
564
+ range.setStartBefore(container);
565
+ return {node: topNode, offset: range.toString().length};
566
+ };
567
+
568
+ select.setCursorPos = function(container, from, to) {
569
+ var win = container.ownerDocument.defaultView,
570
+ range = win.document.createRange();
571
+
572
+ function setPoint(node, offset, side) {
573
+ if (offset == 0 && node && !node.nextSibling) {
574
+ range["set" + side + "After"](node);
575
+ return true;
576
+ }
577
+
578
+ if (!node)
579
+ node = container.firstChild;
580
+ else
581
+ node = node.nextSibling;
582
+
583
+ if (!node) return;
584
+
585
+ if (offset == 0) {
586
+ range["set" + side + "Before"](node);
587
+ return true;
588
+ }
589
+
590
+ var backlog = []
591
+ function decompose(node) {
592
+ if (node.nodeType == 3)
593
+ backlog.push(node);
594
+ else
595
+ forEach(node.childNodes, decompose);
596
+ }
597
+ while (true) {
598
+ while (node && !backlog.length) {
599
+ decompose(node);
600
+ node = node.nextSibling;
601
+ }
602
+ var cur = backlog.shift();
603
+ if (!cur) return false;
604
+
605
+ var length = cur.nodeValue.length;
606
+ if (length >= offset) {
607
+ range["set" + side](cur, offset);
608
+ return true;
609
+ }
610
+ offset -= length;
611
+ }
612
+ }
613
+
614
+ to = to || from;
615
+ if (setPoint(to.node, to.offset, "End") && setPoint(from.node, from.offset, "Start"))
616
+ selectRange(range, win);
617
+ };
618
+ }
619
+ })();