locomotivecms 4.1.1 → 4.2.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (301) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +4 -3
  4. data/Rakefile +4 -0
  5. data/app/api/locomotive/api.rb +1 -1
  6. data/app/assets/config/locomotive_manifest.js +2 -0
  7. data/app/assets/javascripts/locomotive.js +2 -2
  8. data/app/assets/stylesheets/locomotive/account.scss +0 -1
  9. data/app/assets/stylesheets/locomotive/application.scss +0 -1
  10. data/app/assets/stylesheets/locomotive/live_editing_error.scss +0 -1
  11. data/app/assets/stylesheets/locomotive/live_editing_iframe.scss +0 -1
  12. data/app/controllers/locomotive/base_controller.rb +1 -1
  13. data/app/controllers/locomotive/concerns/authorization_controller.rb +1 -1
  14. data/app/controllers/locomotive/concerns/redirect_to_main_host_controller.rb +1 -1
  15. data/app/controllers/locomotive/concerns/site_dispatcher_controller.rb +1 -1
  16. data/app/controllers/locomotive/errors_controller.rb +1 -1
  17. data/app/controllers/locomotive/my_account_controller.rb +1 -1
  18. data/app/controllers/locomotive/passwords_controller.rb +3 -1
  19. data/app/controllers/locomotive/registrations_controller.rb +3 -1
  20. data/app/controllers/locomotive/sessions_controller.rb +3 -1
  21. data/app/controllers/locomotive/sites_controller.rb +1 -1
  22. data/app/helpers/locomotive/base_helper.rb +2 -2
  23. data/app/helpers/locomotive/custom_fields_helper.rb +2 -2
  24. data/app/helpers/locomotive/shared/activities_helper.rb +1 -1
  25. data/app/inputs/locomotive/api_key_input.rb +1 -1
  26. data/app/mailers/locomotive/notifications.rb +1 -1
  27. data/app/models/locomotive/account.rb +1 -1
  28. data/app/models/locomotive/concerns/account/api_key.rb +1 -1
  29. data/app/models/locomotive/concerns/content_entry/csv.rb +1 -1
  30. data/app/models/locomotive/concerns/content_entry/slug.rb +5 -5
  31. data/app/models/locomotive/concerns/content_type/entry_template.rb +3 -3
  32. data/app/models/locomotive/concerns/page/templatized.rb +1 -1
  33. data/app/models/locomotive/concerns/shared/json_attribute.rb +21 -2
  34. data/app/models/locomotive/concerns/site/routes.rb +1 -1
  35. data/app/models/locomotive/content_entry.rb +2 -2
  36. data/app/models/locomotive/page.rb +3 -3
  37. data/app/models/locomotive/section.rb +1 -1
  38. data/app/models/locomotive/snippet.rb +1 -1
  39. data/app/models/locomotive/translation.rb +1 -1
  40. data/app/services/locomotive/content_entry_import_service.rb +1 -1
  41. data/app/services/locomotive/content_entry_service.rb +2 -2
  42. data/app/services/locomotive/content_type_service.rb +13 -3
  43. data/app/services/locomotive/custom_field_service.rb +2 -2
  44. data/app/services/locomotive/editor_service.rb +1 -1
  45. data/app/uploaders/locomotive/base_uploader.rb +0 -10
  46. data/app/views/locomotive/dashboard/_activity.html.slim +1 -1
  47. data/app/views/locomotive/page_content/_edit.json.jbuilder +50 -0
  48. data/app/views/locomotive/page_content/edit.html.erb +1 -1
  49. data/app/views/locomotive/page_content/edit.json.jbuilder +52 -50
  50. data/config/initializers/devise.rb +5 -2
  51. data/lib/generators/locomotive/install/templates/locomotive.rb +0 -5
  52. data/lib/locomotive/action_controller/responder.rb +1 -1
  53. data/lib/locomotive/configuration.rb +2 -2
  54. data/lib/locomotive/dependencies.rb +0 -2
  55. data/lib/locomotive/engine.rb +14 -2
  56. data/lib/locomotive/mongoid/patches.rb +25 -65
  57. data/lib/locomotive/steam/services/api_entry_submission_service.rb +1 -0
  58. data/lib/locomotive/version.rb +1 -1
  59. data/vendor/assets/javascripts/locomotive/codemirror/addons/comment/comment.js +203 -0
  60. data/vendor/assets/javascripts/locomotive/codemirror/addons/comment/continuecomment.js +85 -0
  61. data/vendor/assets/javascripts/locomotive/codemirror/addons/dialog/dialog.js +157 -0
  62. data/vendor/assets/javascripts/locomotive/codemirror/addons/display/autorefresh.js +47 -0
  63. data/vendor/assets/javascripts/locomotive/codemirror/addons/display/fullscreen.js +41 -0
  64. data/vendor/assets/javascripts/locomotive/codemirror/addons/display/panel.js +112 -0
  65. data/vendor/assets/javascripts/locomotive/codemirror/addons/display/placeholder.js +62 -0
  66. data/vendor/assets/javascripts/locomotive/codemirror/addons/display/rulers.js +51 -0
  67. data/vendor/assets/javascripts/locomotive/codemirror/addons/edit/closebrackets.js +195 -0
  68. data/vendor/assets/javascripts/locomotive/codemirror/addons/edit/closetag.js +169 -0
  69. data/vendor/assets/javascripts/locomotive/codemirror/addons/edit/continuelist.js +51 -0
  70. data/vendor/assets/javascripts/locomotive/codemirror/addons/edit/matchbrackets.js +120 -0
  71. data/vendor/assets/javascripts/locomotive/codemirror/addons/edit/matchtags.js +66 -0
  72. data/vendor/assets/javascripts/locomotive/codemirror/addons/edit/trailingspace.js +27 -0
  73. data/vendor/assets/javascripts/locomotive/codemirror/addons/fold/brace-fold.js +105 -0
  74. data/vendor/assets/javascripts/locomotive/codemirror/addons/fold/comment-fold.js +59 -0
  75. data/vendor/assets/javascripts/locomotive/codemirror/addons/fold/foldcode.js +150 -0
  76. data/vendor/assets/javascripts/locomotive/codemirror/addons/fold/foldgutter.js +146 -0
  77. data/vendor/assets/javascripts/locomotive/codemirror/addons/fold/indent-fold.js +44 -0
  78. data/vendor/assets/javascripts/locomotive/codemirror/addons/fold/markdown-fold.js +49 -0
  79. data/vendor/assets/javascripts/locomotive/codemirror/addons/fold/xml-fold.js +182 -0
  80. data/vendor/assets/javascripts/locomotive/codemirror/addons/hint/anyword-hint.js +41 -0
  81. data/vendor/assets/javascripts/locomotive/codemirror/addons/hint/css-hint.js +60 -0
  82. data/vendor/assets/javascripts/locomotive/codemirror/addons/hint/html-hint.js +348 -0
  83. data/vendor/assets/javascripts/locomotive/codemirror/addons/hint/javascript-hint.js +146 -0
  84. data/vendor/assets/javascripts/locomotive/codemirror/addons/hint/show-hint.js +437 -0
  85. data/vendor/assets/javascripts/locomotive/codemirror/addons/hint/sql-hint.js +271 -0
  86. data/vendor/assets/javascripts/locomotive/codemirror/addons/hint/xml-hint.js +110 -0
  87. data/vendor/assets/javascripts/locomotive/codemirror/addons/lint/coffeescript-lint.js +41 -0
  88. data/vendor/assets/javascripts/locomotive/codemirror/addons/lint/css-lint.js +35 -0
  89. data/vendor/assets/javascripts/locomotive/codemirror/addons/lint/html-lint.js +46 -0
  90. data/vendor/assets/javascripts/locomotive/codemirror/addons/lint/javascript-lint.js +136 -0
  91. data/vendor/assets/javascripts/locomotive/codemirror/addons/lint/json-lint.js +31 -0
  92. data/vendor/assets/javascripts/locomotive/codemirror/addons/lint/lint.js +239 -0
  93. data/vendor/assets/javascripts/locomotive/codemirror/addons/lint/yaml-lint.js +28 -0
  94. data/vendor/assets/javascripts/locomotive/codemirror/addons/merge/merge.js +773 -0
  95. data/vendor/assets/javascripts/locomotive/codemirror/addons/mode/loadmode.js +64 -0
  96. data/vendor/assets/javascripts/locomotive/codemirror/addons/mode/multiplex.js +123 -0
  97. data/vendor/assets/javascripts/locomotive/codemirror/addons/mode/overlay.js +85 -0
  98. data/vendor/assets/javascripts/locomotive/codemirror/addons/mode/simple.js +213 -0
  99. data/vendor/assets/javascripts/locomotive/codemirror/addons/runmode/colorize.js +40 -0
  100. data/vendor/assets/javascripts/locomotive/codemirror/addons/runmode/runmode-standalone.js +157 -0
  101. data/vendor/assets/javascripts/locomotive/codemirror/addons/runmode/runmode.js +72 -0
  102. data/vendor/assets/javascripts/locomotive/codemirror/addons/runmode/runmode.node.js +179 -0
  103. data/vendor/assets/javascripts/locomotive/codemirror/addons/scroll/annotatescrollbar.js +118 -0
  104. data/vendor/assets/javascripts/locomotive/codemirror/addons/scroll/scrollpastend.js +48 -0
  105. data/vendor/assets/javascripts/locomotive/codemirror/addons/scroll/simplescrollbars.js +152 -0
  106. data/vendor/assets/javascripts/locomotive/codemirror/addons/search/jump-to-line.js +49 -0
  107. data/vendor/assets/javascripts/locomotive/codemirror/addons/search/match-highlighter.js +146 -0
  108. data/vendor/assets/javascripts/locomotive/codemirror/addons/search/matchesonscrollbar.js +97 -0
  109. data/vendor/assets/javascripts/locomotive/codemirror/addons/search/search.js +249 -0
  110. data/vendor/assets/javascripts/locomotive/codemirror/addons/search/searchcursor.js +189 -0
  111. data/vendor/assets/javascripts/locomotive/codemirror/addons/selection/active-line.js +74 -0
  112. data/vendor/assets/javascripts/locomotive/codemirror/addons/selection/mark-selection.js +118 -0
  113. data/vendor/assets/javascripts/locomotive/codemirror/addons/selection/selection-pointer.js +98 -0
  114. data/vendor/assets/javascripts/locomotive/codemirror/addons/tern/tern.js +701 -0
  115. data/vendor/assets/javascripts/locomotive/codemirror/addons/tern/worker.js +44 -0
  116. data/vendor/assets/javascripts/locomotive/codemirror/addons/wrap/hardwrap.js +144 -0
  117. data/vendor/assets/javascripts/locomotive/codemirror/keymaps/emacs.js +412 -0
  118. data/vendor/assets/javascripts/locomotive/codemirror/keymaps/sublime.js +580 -0
  119. data/vendor/assets/javascripts/locomotive/codemirror/keymaps/vim.js +5065 -0
  120. data/vendor/assets/javascripts/locomotive/codemirror/modes/apl.js +174 -0
  121. data/vendor/assets/javascripts/locomotive/codemirror/modes/asciiarmor.js +73 -0
  122. data/vendor/assets/javascripts/locomotive/codemirror/modes/asn.1.js +204 -0
  123. data/vendor/assets/javascripts/locomotive/codemirror/modes/asterisk.js +196 -0
  124. data/vendor/assets/javascripts/locomotive/codemirror/modes/brainfuck.js +85 -0
  125. data/vendor/assets/javascripts/locomotive/codemirror/modes/clike.js +786 -0
  126. data/vendor/assets/javascripts/locomotive/codemirror/modes/clojure.js +306 -0
  127. data/vendor/assets/javascripts/locomotive/codemirror/modes/cmake.js +97 -0
  128. data/vendor/assets/javascripts/locomotive/codemirror/modes/cobol.js +255 -0
  129. data/vendor/assets/javascripts/locomotive/codemirror/modes/coffeescript.js +355 -0
  130. data/vendor/assets/javascripts/locomotive/codemirror/modes/commonlisp.js +123 -0
  131. data/vendor/assets/javascripts/locomotive/codemirror/modes/crystal.js +391 -0
  132. data/vendor/assets/javascripts/locomotive/codemirror/modes/css.js +825 -0
  133. data/vendor/assets/javascripts/locomotive/codemirror/modes/cypher.js +146 -0
  134. data/vendor/assets/javascripts/locomotive/codemirror/modes/d.js +218 -0
  135. data/vendor/assets/javascripts/locomotive/codemirror/modes/dart.js +157 -0
  136. data/vendor/assets/javascripts/locomotive/codemirror/modes/diff.js +47 -0
  137. data/vendor/assets/javascripts/locomotive/codemirror/modes/django.js +356 -0
  138. data/vendor/assets/javascripts/locomotive/codemirror/modes/dockerfile.js +79 -0
  139. data/vendor/assets/javascripts/locomotive/codemirror/modes/dtd.js +142 -0
  140. data/vendor/assets/javascripts/locomotive/codemirror/modes/dylan.js +344 -0
  141. data/vendor/assets/javascripts/locomotive/codemirror/modes/ebnf.js +195 -0
  142. data/vendor/assets/javascripts/locomotive/codemirror/modes/ecl.js +206 -0
  143. data/vendor/assets/javascripts/locomotive/codemirror/modes/eiffel.js +160 -0
  144. data/vendor/assets/javascripts/locomotive/codemirror/modes/elm.js +205 -0
  145. data/vendor/assets/javascripts/locomotive/codemirror/modes/erlang.js +618 -0
  146. data/vendor/assets/javascripts/locomotive/codemirror/modes/factor.js +83 -0
  147. data/vendor/assets/javascripts/locomotive/codemirror/modes/fcl.js +173 -0
  148. data/vendor/assets/javascripts/locomotive/codemirror/modes/forth.js +180 -0
  149. data/vendor/assets/javascripts/locomotive/codemirror/modes/fortran.js +188 -0
  150. data/vendor/assets/javascripts/locomotive/codemirror/modes/gas.js +345 -0
  151. data/vendor/assets/javascripts/locomotive/codemirror/modes/gfm.js +130 -0
  152. data/vendor/assets/javascripts/locomotive/codemirror/modes/gherkin.js +178 -0
  153. data/vendor/assets/javascripts/locomotive/codemirror/modes/go.js +185 -0
  154. data/vendor/assets/javascripts/locomotive/codemirror/modes/groovy.js +230 -0
  155. data/vendor/assets/javascripts/locomotive/codemirror/modes/haml.js +161 -0
  156. data/vendor/assets/javascripts/locomotive/codemirror/modes/handlebars.js +62 -0
  157. data/vendor/assets/javascripts/locomotive/codemirror/modes/haskell-literate.js +43 -0
  158. data/vendor/assets/javascripts/locomotive/codemirror/modes/haskell.js +267 -0
  159. data/vendor/assets/javascripts/locomotive/codemirror/modes/haxe.js +515 -0
  160. data/vendor/assets/javascripts/locomotive/codemirror/modes/htmlembedded.js +28 -0
  161. data/vendor/assets/javascripts/locomotive/codemirror/modes/htmlmixed.js +152 -0
  162. data/vendor/assets/javascripts/locomotive/codemirror/modes/http.js +113 -0
  163. data/vendor/assets/javascripts/locomotive/codemirror/modes/idl.js +290 -0
  164. data/vendor/assets/javascripts/locomotive/codemirror/modes/jade.js +590 -0
  165. data/vendor/assets/javascripts/locomotive/codemirror/modes/javascript.js +748 -0
  166. data/vendor/assets/javascripts/locomotive/codemirror/modes/jinja2.js +142 -0
  167. data/vendor/assets/javascripts/locomotive/codemirror/modes/jsx.js +147 -0
  168. data/vendor/assets/javascripts/locomotive/codemirror/modes/julia.js +392 -0
  169. data/vendor/assets/javascripts/locomotive/codemirror/modes/livescript.js +280 -0
  170. data/vendor/assets/javascripts/locomotive/codemirror/modes/lua.js +159 -0
  171. data/vendor/assets/javascripts/locomotive/codemirror/modes/markdown.js +797 -0
  172. data/vendor/assets/javascripts/locomotive/codemirror/modes/mathematica.js +176 -0
  173. data/vendor/assets/javascripts/locomotive/codemirror/modes/mbox.js +129 -0
  174. data/vendor/assets/javascripts/locomotive/codemirror/modes/mirc.js +193 -0
  175. data/vendor/assets/javascripts/locomotive/codemirror/modes/mllike.js +205 -0
  176. data/vendor/assets/javascripts/locomotive/codemirror/modes/modelica.js +245 -0
  177. data/vendor/assets/javascripts/locomotive/codemirror/modes/mscgen.js +169 -0
  178. data/vendor/assets/javascripts/locomotive/codemirror/modes/mumps.js +148 -0
  179. data/vendor/assets/javascripts/locomotive/codemirror/modes/nginx.js +178 -0
  180. data/vendor/assets/javascripts/locomotive/codemirror/modes/nsis.js +95 -0
  181. data/vendor/assets/javascripts/locomotive/codemirror/modes/ntriples.js +186 -0
  182. data/vendor/assets/javascripts/locomotive/codemirror/modes/octave.js +135 -0
  183. data/vendor/assets/javascripts/locomotive/codemirror/modes/oz.js +252 -0
  184. data/vendor/assets/javascripts/locomotive/codemirror/modes/pascal.js +109 -0
  185. data/vendor/assets/javascripts/locomotive/codemirror/modes/pegjs.js +114 -0
  186. data/vendor/assets/javascripts/locomotive/codemirror/modes/perl.js +837 -0
  187. data/vendor/assets/javascripts/locomotive/codemirror/modes/php.js +234 -0
  188. data/vendor/assets/javascripts/locomotive/codemirror/modes/pig.js +178 -0
  189. data/vendor/assets/javascripts/locomotive/codemirror/modes/powershell.js +396 -0
  190. data/vendor/assets/javascripts/locomotive/codemirror/modes/properties.js +78 -0
  191. data/vendor/assets/javascripts/locomotive/codemirror/modes/protobuf.js +68 -0
  192. data/vendor/assets/javascripts/locomotive/codemirror/modes/puppet.js +220 -0
  193. data/vendor/assets/javascripts/locomotive/codemirror/modes/python.js +340 -0
  194. data/vendor/assets/javascripts/locomotive/codemirror/modes/q.js +139 -0
  195. data/vendor/assets/javascripts/locomotive/codemirror/modes/r.js +164 -0
  196. data/vendor/assets/javascripts/locomotive/codemirror/modes/rpm.js +109 -0
  197. data/vendor/assets/javascripts/locomotive/codemirror/modes/rst.js +557 -0
  198. data/vendor/assets/javascripts/locomotive/codemirror/modes/ruby.js +285 -0
  199. data/vendor/assets/javascripts/locomotive/codemirror/modes/rust.js +71 -0
  200. data/vendor/assets/javascripts/locomotive/codemirror/modes/sas.js +315 -0
  201. data/vendor/assets/javascripts/locomotive/codemirror/modes/sass.js +414 -0
  202. data/vendor/assets/javascripts/locomotive/codemirror/modes/scheme.js +249 -0
  203. data/vendor/assets/javascripts/locomotive/codemirror/modes/shell.js +139 -0
  204. data/vendor/assets/javascripts/locomotive/codemirror/modes/sieve.js +193 -0
  205. data/vendor/assets/javascripts/locomotive/codemirror/modes/slim.js +575 -0
  206. data/vendor/assets/javascripts/locomotive/codemirror/modes/smalltalk.js +168 -0
  207. data/vendor/assets/javascripts/locomotive/codemirror/modes/smarty.js +225 -0
  208. data/vendor/assets/javascripts/locomotive/codemirror/modes/solr.js +104 -0
  209. data/vendor/assets/javascripts/locomotive/codemirror/modes/soy.js +199 -0
  210. data/vendor/assets/javascripts/locomotive/codemirror/modes/sparql.js +180 -0
  211. data/vendor/assets/javascripts/locomotive/codemirror/modes/spreadsheet.js +112 -0
  212. data/vendor/assets/javascripts/locomotive/codemirror/modes/sql.js +413 -0
  213. data/vendor/assets/javascripts/locomotive/codemirror/modes/stex.js +251 -0
  214. data/vendor/assets/javascripts/locomotive/codemirror/modes/stylus.js +769 -0
  215. data/vendor/assets/javascripts/locomotive/codemirror/modes/swift.js +202 -0
  216. data/vendor/assets/javascripts/locomotive/codemirror/modes/tcl.js +139 -0
  217. data/vendor/assets/javascripts/locomotive/codemirror/modes/textile.js +469 -0
  218. data/vendor/assets/javascripts/locomotive/codemirror/modes/tiddlywiki.js +308 -0
  219. data/vendor/assets/javascripts/locomotive/codemirror/modes/tiki.js +312 -0
  220. data/vendor/assets/javascripts/locomotive/codemirror/modes/toml.js +88 -0
  221. data/vendor/assets/javascripts/locomotive/codemirror/modes/tornado.js +68 -0
  222. data/vendor/assets/javascripts/locomotive/codemirror/modes/troff.js +84 -0
  223. data/vendor/assets/javascripts/locomotive/codemirror/modes/ttcn-cfg.js +214 -0
  224. data/vendor/assets/javascripts/locomotive/codemirror/modes/ttcn.js +283 -0
  225. data/vendor/assets/javascripts/locomotive/codemirror/modes/turtle.js +162 -0
  226. data/vendor/assets/javascripts/locomotive/codemirror/modes/twig.js +141 -0
  227. data/vendor/assets/javascripts/locomotive/codemirror/modes/vb.js +276 -0
  228. data/vendor/assets/javascripts/locomotive/codemirror/modes/vbscript.js +350 -0
  229. data/vendor/assets/javascripts/locomotive/codemirror/modes/velocity.js +201 -0
  230. data/vendor/assets/javascripts/locomotive/codemirror/modes/verilog.js +537 -0
  231. data/vendor/assets/javascripts/locomotive/codemirror/modes/vhdl.js +189 -0
  232. data/vendor/assets/javascripts/locomotive/codemirror/modes/vue.js +69 -0
  233. data/vendor/assets/javascripts/locomotive/codemirror/modes/webidl.js +195 -0
  234. data/vendor/assets/javascripts/locomotive/codemirror/modes/xml.js +394 -0
  235. data/vendor/assets/javascripts/locomotive/codemirror/modes/xquery.js +437 -0
  236. data/vendor/assets/javascripts/locomotive/codemirror/modes/yacas.js +204 -0
  237. data/vendor/assets/javascripts/locomotive/codemirror/modes/yaml-frontmatter.js +68 -0
  238. data/vendor/assets/javascripts/locomotive/codemirror/modes/yaml.js +117 -0
  239. data/vendor/assets/javascripts/locomotive/codemirror/modes/z80.js +116 -0
  240. data/vendor/assets/javascripts/locomotive/codemirror.js +8922 -0
  241. data/vendor/assets/javascripts/locomotive/select2.js +436 -175
  242. data/vendor/assets/javascripts/locomotive/wysihtml5x-toolbar.js +1346 -564
  243. data/vendor/assets/stylesheets/locomotive/codemirror/addons/dialog/dialog.css +32 -0
  244. data/vendor/assets/stylesheets/locomotive/codemirror/addons/display/fullscreen.css +6 -0
  245. data/vendor/assets/stylesheets/locomotive/codemirror/addons/fold/foldgutter.css +20 -0
  246. data/vendor/assets/stylesheets/locomotive/codemirror/addons/hint/show-hint.css +37 -0
  247. data/vendor/assets/stylesheets/locomotive/codemirror/addons/lint/lint.css +73 -0
  248. data/vendor/assets/stylesheets/locomotive/codemirror/addons/merge/merge.css +113 -0
  249. data/vendor/assets/stylesheets/locomotive/codemirror/addons/scroll/simplescrollbars.css +66 -0
  250. data/vendor/assets/stylesheets/locomotive/codemirror/addons/search/matchesonscrollbar.css +8 -0
  251. data/vendor/assets/stylesheets/locomotive/codemirror/addons/tern/tern.css +87 -0
  252. data/vendor/assets/stylesheets/locomotive/codemirror/modes/tiddlywiki.css +14 -0
  253. data/vendor/assets/stylesheets/locomotive/codemirror/modes/tiki.css +26 -0
  254. data/vendor/assets/stylesheets/locomotive/codemirror/themes/3024-day.css +41 -0
  255. data/vendor/assets/stylesheets/locomotive/codemirror/themes/3024-night.css +39 -0
  256. data/vendor/assets/stylesheets/locomotive/codemirror/themes/abcdef.css +32 -0
  257. data/vendor/assets/stylesheets/locomotive/codemirror/themes/ambiance-mobile.css +5 -0
  258. data/vendor/assets/stylesheets/locomotive/codemirror/themes/ambiance.css +74 -0
  259. data/vendor/assets/stylesheets/locomotive/codemirror/themes/base16-dark.css +38 -0
  260. data/vendor/assets/stylesheets/locomotive/codemirror/themes/base16-light.css +38 -0
  261. data/vendor/assets/stylesheets/locomotive/codemirror/themes/bespin.css +34 -0
  262. data/vendor/assets/stylesheets/locomotive/codemirror/themes/blackboard.css +32 -0
  263. data/vendor/assets/stylesheets/locomotive/codemirror/themes/cobalt.css +25 -0
  264. data/vendor/assets/stylesheets/locomotive/codemirror/themes/colorforth.css +33 -0
  265. data/vendor/assets/stylesheets/locomotive/codemirror/themes/dracula.css +41 -0
  266. data/vendor/assets/stylesheets/locomotive/codemirror/themes/eclipse.css +23 -0
  267. data/vendor/assets/stylesheets/locomotive/codemirror/themes/elegant.css +13 -0
  268. data/vendor/assets/stylesheets/locomotive/codemirror/themes/erlang-dark.css +34 -0
  269. data/vendor/assets/stylesheets/locomotive/codemirror/themes/hopscotch.css +34 -0
  270. data/vendor/assets/stylesheets/locomotive/codemirror/themes/icecoder.css +43 -0
  271. data/vendor/assets/stylesheets/locomotive/codemirror/themes/isotope.css +34 -0
  272. data/vendor/assets/stylesheets/locomotive/codemirror/themes/lesser-dark.css +47 -0
  273. data/vendor/assets/stylesheets/locomotive/codemirror/themes/liquibyte.css +95 -0
  274. data/vendor/assets/stylesheets/locomotive/codemirror/themes/material.css +53 -0
  275. data/vendor/assets/stylesheets/locomotive/codemirror/themes/mbo.css +37 -0
  276. data/vendor/assets/stylesheets/locomotive/codemirror/themes/mdn-like.css +46 -0
  277. data/vendor/assets/stylesheets/locomotive/codemirror/themes/midnight.css +45 -0
  278. data/vendor/assets/stylesheets/locomotive/codemirror/themes/monokai.css +36 -0
  279. data/vendor/assets/stylesheets/locomotive/codemirror/themes/neat.css +12 -0
  280. data/vendor/assets/stylesheets/locomotive/codemirror/themes/neo.css +43 -0
  281. data/vendor/assets/stylesheets/locomotive/codemirror/themes/night.css +27 -0
  282. data/vendor/assets/stylesheets/locomotive/codemirror/themes/paraiso-dark.css +38 -0
  283. data/vendor/assets/stylesheets/locomotive/codemirror/themes/paraiso-light.css +38 -0
  284. data/vendor/assets/stylesheets/locomotive/codemirror/themes/pastel-on-dark.css +53 -0
  285. data/vendor/assets/stylesheets/locomotive/codemirror/themes/railscasts.css +34 -0
  286. data/vendor/assets/stylesheets/locomotive/codemirror/themes/rubyblue.css +25 -0
  287. data/vendor/assets/stylesheets/locomotive/codemirror/themes/seti.css +44 -0
  288. data/vendor/assets/stylesheets/locomotive/codemirror/themes/solarized.css +169 -0
  289. data/vendor/assets/stylesheets/locomotive/codemirror/themes/the-matrix.css +30 -0
  290. data/vendor/assets/stylesheets/locomotive/codemirror/themes/tomorrow-night-bright.css +35 -0
  291. data/vendor/assets/stylesheets/locomotive/codemirror/themes/tomorrow-night-eighties.css +38 -0
  292. data/vendor/assets/stylesheets/locomotive/codemirror/themes/ttcn.css +64 -0
  293. data/vendor/assets/stylesheets/locomotive/codemirror/themes/twilight.css +32 -0
  294. data/vendor/assets/stylesheets/locomotive/codemirror/themes/vibrant-ink.css +34 -0
  295. data/vendor/assets/stylesheets/locomotive/codemirror/themes/xq-dark.css +53 -0
  296. data/vendor/assets/stylesheets/locomotive/codemirror/themes/xq-light.css +43 -0
  297. data/vendor/assets/stylesheets/locomotive/codemirror/themes/yeti.css +44 -0
  298. data/vendor/assets/stylesheets/locomotive/codemirror/themes/zenburn.css +37 -0
  299. data/vendor/assets/stylesheets/locomotive/codemirror.css +347 -0
  300. data/vendor/assets/stylesheets/locomotive/select2.css +3 -6
  301. metadata +349 -128
@@ -0,0 +1,773 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
4
+ // declare global: diff_match_patch, DIFF_INSERT, DIFF_DELETE, DIFF_EQUAL
5
+
6
+ (function(mod) {
7
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
8
+ mod(require("../../lib/codemirror")); // Note non-packaged dependency diff_match_patch
9
+ else if (typeof define == "function" && define.amd) // AMD
10
+ define(["../../lib/codemirror", "diff_match_patch"], mod);
11
+ else // Plain browser env
12
+ mod(CodeMirror);
13
+ })(function(CodeMirror) {
14
+ "use strict";
15
+ var Pos = CodeMirror.Pos;
16
+ var svgNS = "http://www.w3.org/2000/svg";
17
+
18
+ function DiffView(mv, type) {
19
+ this.mv = mv;
20
+ this.type = type;
21
+ this.classes = type == "left"
22
+ ? {chunk: "CodeMirror-merge-l-chunk",
23
+ start: "CodeMirror-merge-l-chunk-start",
24
+ end: "CodeMirror-merge-l-chunk-end",
25
+ insert: "CodeMirror-merge-l-inserted",
26
+ del: "CodeMirror-merge-l-deleted",
27
+ connect: "CodeMirror-merge-l-connect"}
28
+ : {chunk: "CodeMirror-merge-r-chunk",
29
+ start: "CodeMirror-merge-r-chunk-start",
30
+ end: "CodeMirror-merge-r-chunk-end",
31
+ insert: "CodeMirror-merge-r-inserted",
32
+ del: "CodeMirror-merge-r-deleted",
33
+ connect: "CodeMirror-merge-r-connect"};
34
+ }
35
+
36
+ DiffView.prototype = {
37
+ constructor: DiffView,
38
+ init: function(pane, orig, options) {
39
+ this.edit = this.mv.edit;
40
+ (this.edit.state.diffViews || (this.edit.state.diffViews = [])).push(this);
41
+ this.orig = CodeMirror(pane, copyObj({value: orig, readOnly: !this.mv.options.allowEditingOriginals}, copyObj(options)));
42
+ this.orig.state.diffViews = [this];
43
+
44
+ this.diff = getDiff(asString(orig), asString(options.value));
45
+ this.chunks = getChunks(this.diff);
46
+ this.diffOutOfDate = this.dealigned = false;
47
+
48
+ this.showDifferences = options.showDifferences !== false;
49
+ this.forceUpdate = registerUpdate(this);
50
+ setScrollLock(this, true, false);
51
+ registerScroll(this);
52
+ },
53
+ setShowDifferences: function(val) {
54
+ val = val !== false;
55
+ if (val != this.showDifferences) {
56
+ this.showDifferences = val;
57
+ this.forceUpdate("full");
58
+ }
59
+ }
60
+ };
61
+
62
+ function ensureDiff(dv) {
63
+ if (dv.diffOutOfDate) {
64
+ dv.diff = getDiff(dv.orig.getValue(), dv.edit.getValue());
65
+ dv.chunks = getChunks(dv.diff);
66
+ dv.diffOutOfDate = false;
67
+ CodeMirror.signal(dv.edit, "updateDiff", dv.diff);
68
+ }
69
+ }
70
+
71
+ var updating = false;
72
+ function registerUpdate(dv) {
73
+ var edit = {from: 0, to: 0, marked: []};
74
+ var orig = {from: 0, to: 0, marked: []};
75
+ var debounceChange, updatingFast = false;
76
+ function update(mode) {
77
+ updating = true;
78
+ updatingFast = false;
79
+ if (mode == "full") {
80
+ if (dv.svg) clear(dv.svg);
81
+ if (dv.copyButtons) clear(dv.copyButtons);
82
+ clearMarks(dv.edit, edit.marked, dv.classes);
83
+ clearMarks(dv.orig, orig.marked, dv.classes);
84
+ edit.from = edit.to = orig.from = orig.to = 0;
85
+ }
86
+ ensureDiff(dv);
87
+ if (dv.showDifferences) {
88
+ updateMarks(dv.edit, dv.diff, edit, DIFF_INSERT, dv.classes);
89
+ updateMarks(dv.orig, dv.diff, orig, DIFF_DELETE, dv.classes);
90
+ }
91
+ makeConnections(dv);
92
+
93
+ if (dv.mv.options.connect == "align")
94
+ alignChunks(dv);
95
+ updating = false;
96
+ }
97
+ function setDealign(fast) {
98
+ if (updating) return;
99
+ dv.dealigned = true;
100
+ set(fast);
101
+ }
102
+ function set(fast) {
103
+ if (updating || updatingFast) return;
104
+ clearTimeout(debounceChange);
105
+ if (fast === true) updatingFast = true;
106
+ debounceChange = setTimeout(update, fast === true ? 20 : 250);
107
+ }
108
+ function change(_cm, change) {
109
+ if (!dv.diffOutOfDate) {
110
+ dv.diffOutOfDate = true;
111
+ edit.from = edit.to = orig.from = orig.to = 0;
112
+ }
113
+ // Update faster when a line was added/removed
114
+ setDealign(change.text.length - 1 != change.to.line - change.from.line);
115
+ }
116
+ dv.edit.on("change", change);
117
+ dv.orig.on("change", change);
118
+ dv.edit.on("markerAdded", setDealign);
119
+ dv.edit.on("markerCleared", setDealign);
120
+ dv.orig.on("markerAdded", setDealign);
121
+ dv.orig.on("markerCleared", setDealign);
122
+ dv.edit.on("viewportChange", function() { set(false); });
123
+ dv.orig.on("viewportChange", function() { set(false); });
124
+ update();
125
+ return update;
126
+ }
127
+
128
+ function registerScroll(dv) {
129
+ dv.edit.on("scroll", function() {
130
+ syncScroll(dv, DIFF_INSERT) && makeConnections(dv);
131
+ });
132
+ dv.orig.on("scroll", function() {
133
+ syncScroll(dv, DIFF_DELETE) && makeConnections(dv);
134
+ });
135
+ }
136
+
137
+ function syncScroll(dv, type) {
138
+ // Change handler will do a refresh after a timeout when diff is out of date
139
+ if (dv.diffOutOfDate) return false;
140
+ if (!dv.lockScroll) return true;
141
+ var editor, other, now = +new Date;
142
+ if (type == DIFF_INSERT) { editor = dv.edit; other = dv.orig; }
143
+ else { editor = dv.orig; other = dv.edit; }
144
+ // Don't take action if the position of this editor was recently set
145
+ // (to prevent feedback loops)
146
+ if (editor.state.scrollSetBy == dv && (editor.state.scrollSetAt || 0) + 50 > now) return false;
147
+
148
+ var sInfo = editor.getScrollInfo();
149
+ if (dv.mv.options.connect == "align") {
150
+ targetPos = sInfo.top;
151
+ } else {
152
+ var halfScreen = .5 * sInfo.clientHeight, midY = sInfo.top + halfScreen;
153
+ var mid = editor.lineAtHeight(midY, "local");
154
+ var around = chunkBoundariesAround(dv.chunks, mid, type == DIFF_INSERT);
155
+ var off = getOffsets(editor, type == DIFF_INSERT ? around.edit : around.orig);
156
+ var offOther = getOffsets(other, type == DIFF_INSERT ? around.orig : around.edit);
157
+ var ratio = (midY - off.top) / (off.bot - off.top);
158
+ var targetPos = (offOther.top - halfScreen) + ratio * (offOther.bot - offOther.top);
159
+
160
+ var botDist, mix;
161
+ // Some careful tweaking to make sure no space is left out of view
162
+ // when scrolling to top or bottom.
163
+ if (targetPos > sInfo.top && (mix = sInfo.top / halfScreen) < 1) {
164
+ targetPos = targetPos * mix + sInfo.top * (1 - mix);
165
+ } else if ((botDist = sInfo.height - sInfo.clientHeight - sInfo.top) < halfScreen) {
166
+ var otherInfo = other.getScrollInfo();
167
+ var botDistOther = otherInfo.height - otherInfo.clientHeight - targetPos;
168
+ if (botDistOther > botDist && (mix = botDist / halfScreen) < 1)
169
+ targetPos = targetPos * mix + (otherInfo.height - otherInfo.clientHeight - botDist) * (1 - mix);
170
+ }
171
+ }
172
+
173
+ other.scrollTo(sInfo.left, targetPos);
174
+ other.state.scrollSetAt = now;
175
+ other.state.scrollSetBy = dv;
176
+ return true;
177
+ }
178
+
179
+ function getOffsets(editor, around) {
180
+ var bot = around.after;
181
+ if (bot == null) bot = editor.lastLine() + 1;
182
+ return {top: editor.heightAtLine(around.before || 0, "local"),
183
+ bot: editor.heightAtLine(bot, "local")};
184
+ }
185
+
186
+ function setScrollLock(dv, val, action) {
187
+ dv.lockScroll = val;
188
+ if (val && action != false) syncScroll(dv, DIFF_INSERT) && makeConnections(dv);
189
+ dv.lockButton.innerHTML = val ? "\u21db\u21da" : "\u21db&nbsp;&nbsp;\u21da";
190
+ }
191
+
192
+ // Updating the marks for editor content
193
+
194
+ function clearMarks(editor, arr, classes) {
195
+ for (var i = 0; i < arr.length; ++i) {
196
+ var mark = arr[i];
197
+ if (mark instanceof CodeMirror.TextMarker) {
198
+ mark.clear();
199
+ } else if (mark.parent) {
200
+ editor.removeLineClass(mark, "background", classes.chunk);
201
+ editor.removeLineClass(mark, "background", classes.start);
202
+ editor.removeLineClass(mark, "background", classes.end);
203
+ }
204
+ }
205
+ arr.length = 0;
206
+ }
207
+
208
+ // FIXME maybe add a margin around viewport to prevent too many updates
209
+ function updateMarks(editor, diff, state, type, classes) {
210
+ var vp = editor.getViewport();
211
+ editor.operation(function() {
212
+ if (state.from == state.to || vp.from - state.to > 20 || state.from - vp.to > 20) {
213
+ clearMarks(editor, state.marked, classes);
214
+ markChanges(editor, diff, type, state.marked, vp.from, vp.to, classes);
215
+ state.from = vp.from; state.to = vp.to;
216
+ } else {
217
+ if (vp.from < state.from) {
218
+ markChanges(editor, diff, type, state.marked, vp.from, state.from, classes);
219
+ state.from = vp.from;
220
+ }
221
+ if (vp.to > state.to) {
222
+ markChanges(editor, diff, type, state.marked, state.to, vp.to, classes);
223
+ state.to = vp.to;
224
+ }
225
+ }
226
+ });
227
+ }
228
+
229
+ function markChanges(editor, diff, type, marks, from, to, classes) {
230
+ var pos = Pos(0, 0);
231
+ var top = Pos(from, 0), bot = editor.clipPos(Pos(to - 1));
232
+ var cls = type == DIFF_DELETE ? classes.del : classes.insert;
233
+ function markChunk(start, end) {
234
+ var bfrom = Math.max(from, start), bto = Math.min(to, end);
235
+ for (var i = bfrom; i < bto; ++i) {
236
+ var line = editor.addLineClass(i, "background", classes.chunk);
237
+ if (i == start) editor.addLineClass(line, "background", classes.start);
238
+ if (i == end - 1) editor.addLineClass(line, "background", classes.end);
239
+ marks.push(line);
240
+ }
241
+ // When the chunk is empty, make sure a horizontal line shows up
242
+ if (start == end && bfrom == end && bto == end) {
243
+ if (bfrom)
244
+ marks.push(editor.addLineClass(bfrom - 1, "background", classes.end));
245
+ else
246
+ marks.push(editor.addLineClass(bfrom, "background", classes.start));
247
+ }
248
+ }
249
+
250
+ var chunkStart = 0;
251
+ for (var i = 0; i < diff.length; ++i) {
252
+ var part = diff[i], tp = part[0], str = part[1];
253
+ if (tp == DIFF_EQUAL) {
254
+ var cleanFrom = pos.line + (startOfLineClean(diff, i) ? 0 : 1);
255
+ moveOver(pos, str);
256
+ var cleanTo = pos.line + (endOfLineClean(diff, i) ? 1 : 0);
257
+ if (cleanTo > cleanFrom) {
258
+ if (i) markChunk(chunkStart, cleanFrom);
259
+ chunkStart = cleanTo;
260
+ }
261
+ } else {
262
+ if (tp == type) {
263
+ var end = moveOver(pos, str, true);
264
+ var a = posMax(top, pos), b = posMin(bot, end);
265
+ if (!posEq(a, b))
266
+ marks.push(editor.markText(a, b, {className: cls}));
267
+ pos = end;
268
+ }
269
+ }
270
+ }
271
+ if (chunkStart <= pos.line) markChunk(chunkStart, pos.line + 1);
272
+ }
273
+
274
+ // Updating the gap between editor and original
275
+
276
+ function makeConnections(dv) {
277
+ if (!dv.showDifferences) return;
278
+
279
+ if (dv.svg) {
280
+ clear(dv.svg);
281
+ var w = dv.gap.offsetWidth;
282
+ attrs(dv.svg, "width", w, "height", dv.gap.offsetHeight);
283
+ }
284
+ if (dv.copyButtons) clear(dv.copyButtons);
285
+
286
+ var vpEdit = dv.edit.getViewport(), vpOrig = dv.orig.getViewport();
287
+ var sTopEdit = dv.edit.getScrollInfo().top, sTopOrig = dv.orig.getScrollInfo().top;
288
+ for (var i = 0; i < dv.chunks.length; i++) {
289
+ var ch = dv.chunks[i];
290
+ if (ch.editFrom <= vpEdit.to && ch.editTo >= vpEdit.from &&
291
+ ch.origFrom <= vpOrig.to && ch.origTo >= vpOrig.from)
292
+ drawConnectorsForChunk(dv, ch, sTopOrig, sTopEdit, w);
293
+ }
294
+ }
295
+
296
+ function getMatchingOrigLine(editLine, chunks) {
297
+ var editStart = 0, origStart = 0;
298
+ for (var i = 0; i < chunks.length; i++) {
299
+ var chunk = chunks[i];
300
+ if (chunk.editTo > editLine && chunk.editFrom <= editLine) return null;
301
+ if (chunk.editFrom > editLine) break;
302
+ editStart = chunk.editTo;
303
+ origStart = chunk.origTo;
304
+ }
305
+ return origStart + (editLine - editStart);
306
+ }
307
+
308
+ function findAlignedLines(dv, other) {
309
+ var linesToAlign = [];
310
+ for (var i = 0; i < dv.chunks.length; i++) {
311
+ var chunk = dv.chunks[i];
312
+ linesToAlign.push([chunk.origTo, chunk.editTo, other ? getMatchingOrigLine(chunk.editTo, other.chunks) : null]);
313
+ }
314
+ if (other) {
315
+ for (var i = 0; i < other.chunks.length; i++) {
316
+ var chunk = other.chunks[i];
317
+ for (var j = 0; j < linesToAlign.length; j++) {
318
+ var align = linesToAlign[j];
319
+ if (align[1] == chunk.editTo) {
320
+ j = -1;
321
+ break;
322
+ } else if (align[1] > chunk.editTo) {
323
+ break;
324
+ }
325
+ }
326
+ if (j > -1)
327
+ linesToAlign.splice(j - 1, 0, [getMatchingOrigLine(chunk.editTo, dv.chunks), chunk.editTo, chunk.origTo]);
328
+ }
329
+ }
330
+ return linesToAlign;
331
+ }
332
+
333
+ function alignChunks(dv, force) {
334
+ if (!dv.dealigned && !force) return;
335
+ if (!dv.orig.curOp) return dv.orig.operation(function() {
336
+ alignChunks(dv, force);
337
+ });
338
+
339
+ dv.dealigned = false;
340
+ var other = dv.mv.left == dv ? dv.mv.right : dv.mv.left;
341
+ if (other) {
342
+ ensureDiff(other);
343
+ other.dealigned = false;
344
+ }
345
+ var linesToAlign = findAlignedLines(dv, other);
346
+
347
+ // Clear old aligners
348
+ var aligners = dv.mv.aligners;
349
+ for (var i = 0; i < aligners.length; i++)
350
+ aligners[i].clear();
351
+ aligners.length = 0;
352
+
353
+ var cm = [dv.orig, dv.edit], scroll = [];
354
+ if (other) cm.push(other.orig);
355
+ for (var i = 0; i < cm.length; i++)
356
+ scroll.push(cm[i].getScrollInfo().top);
357
+
358
+ for (var ln = 0; ln < linesToAlign.length; ln++)
359
+ alignLines(cm, linesToAlign[ln], aligners);
360
+
361
+ for (var i = 0; i < cm.length; i++)
362
+ cm[i].scrollTo(null, scroll[i]);
363
+ }
364
+
365
+ function alignLines(cm, lines, aligners) {
366
+ var maxOffset = 0, offset = [];
367
+ for (var i = 0; i < cm.length; i++) if (lines[i] != null) {
368
+ var off = cm[i].heightAtLine(lines[i], "local");
369
+ offset[i] = off;
370
+ maxOffset = Math.max(maxOffset, off);
371
+ }
372
+ for (var i = 0; i < cm.length; i++) if (lines[i] != null) {
373
+ var diff = maxOffset - offset[i];
374
+ if (diff > 1)
375
+ aligners.push(padAbove(cm[i], lines[i], diff));
376
+ }
377
+ }
378
+
379
+ function padAbove(cm, line, size) {
380
+ var above = true;
381
+ if (line > cm.lastLine()) {
382
+ line--;
383
+ above = false;
384
+ }
385
+ var elt = document.createElement("div");
386
+ elt.className = "CodeMirror-merge-spacer";
387
+ elt.style.height = size + "px"; elt.style.minWidth = "1px";
388
+ return cm.addLineWidget(line, elt, {height: size, above: above});
389
+ }
390
+
391
+ function drawConnectorsForChunk(dv, chunk, sTopOrig, sTopEdit, w) {
392
+ var flip = dv.type == "left";
393
+ var top = dv.orig.heightAtLine(chunk.origFrom, "local") - sTopOrig;
394
+ if (dv.svg) {
395
+ var topLpx = top;
396
+ var topRpx = dv.edit.heightAtLine(chunk.editFrom, "local") - sTopEdit;
397
+ if (flip) { var tmp = topLpx; topLpx = topRpx; topRpx = tmp; }
398
+ var botLpx = dv.orig.heightAtLine(chunk.origTo, "local") - sTopOrig;
399
+ var botRpx = dv.edit.heightAtLine(chunk.editTo, "local") - sTopEdit;
400
+ if (flip) { var tmp = botLpx; botLpx = botRpx; botRpx = tmp; }
401
+ var curveTop = " C " + w/2 + " " + topRpx + " " + w/2 + " " + topLpx + " " + (w + 2) + " " + topLpx;
402
+ var curveBot = " C " + w/2 + " " + botLpx + " " + w/2 + " " + botRpx + " -1 " + botRpx;
403
+ attrs(dv.svg.appendChild(document.createElementNS(svgNS, "path")),
404
+ "d", "M -1 " + topRpx + curveTop + " L " + (w + 2) + " " + botLpx + curveBot + " z",
405
+ "class", dv.classes.connect);
406
+ }
407
+ if (dv.copyButtons) {
408
+ var copy = dv.copyButtons.appendChild(elt("div", dv.type == "left" ? "\u21dd" : "\u21dc",
409
+ "CodeMirror-merge-copy"));
410
+ var editOriginals = dv.mv.options.allowEditingOriginals;
411
+ copy.title = editOriginals ? "Push to left" : "Revert chunk";
412
+ copy.chunk = chunk;
413
+ copy.style.top = top + "px";
414
+
415
+ if (editOriginals) {
416
+ var topReverse = dv.orig.heightAtLine(chunk.editFrom, "local") - sTopEdit;
417
+ var copyReverse = dv.copyButtons.appendChild(elt("div", dv.type == "right" ? "\u21dd" : "\u21dc",
418
+ "CodeMirror-merge-copy-reverse"));
419
+ copyReverse.title = "Push to right";
420
+ copyReverse.chunk = {editFrom: chunk.origFrom, editTo: chunk.origTo,
421
+ origFrom: chunk.editFrom, origTo: chunk.editTo};
422
+ copyReverse.style.top = topReverse + "px";
423
+ dv.type == "right" ? copyReverse.style.left = "2px" : copyReverse.style.right = "2px";
424
+ }
425
+ }
426
+ }
427
+
428
+ function copyChunk(dv, to, from, chunk) {
429
+ if (dv.diffOutOfDate) return;
430
+ var editStart = chunk.editTo > to.lastLine() ? Pos(chunk.editFrom - 1) : Pos(chunk.editFrom, 0)
431
+ var origStart = chunk.origTo > from.lastLine() ? Pos(chunk.origFrom - 1) : Pos(chunk.origFrom, 0)
432
+ to.replaceRange(from.getRange(origStart, Pos(chunk.origTo, 0)), editStart, Pos(chunk.editTo, 0))
433
+ }
434
+
435
+ // Merge view, containing 0, 1, or 2 diff views.
436
+
437
+ var MergeView = CodeMirror.MergeView = function(node, options) {
438
+ if (!(this instanceof MergeView)) return new MergeView(node, options);
439
+
440
+ this.options = options;
441
+ var origLeft = options.origLeft, origRight = options.origRight == null ? options.orig : options.origRight;
442
+
443
+ var hasLeft = origLeft != null, hasRight = origRight != null;
444
+ var panes = 1 + (hasLeft ? 1 : 0) + (hasRight ? 1 : 0);
445
+ var wrap = [], left = this.left = null, right = this.right = null;
446
+ var self = this;
447
+
448
+ if (hasLeft) {
449
+ left = this.left = new DiffView(this, "left");
450
+ var leftPane = elt("div", null, "CodeMirror-merge-pane");
451
+ wrap.push(leftPane);
452
+ wrap.push(buildGap(left));
453
+ }
454
+
455
+ var editPane = elt("div", null, "CodeMirror-merge-pane");
456
+ wrap.push(editPane);
457
+
458
+ if (hasRight) {
459
+ right = this.right = new DiffView(this, "right");
460
+ wrap.push(buildGap(right));
461
+ var rightPane = elt("div", null, "CodeMirror-merge-pane");
462
+ wrap.push(rightPane);
463
+ }
464
+
465
+ (hasRight ? rightPane : editPane).className += " CodeMirror-merge-pane-rightmost";
466
+
467
+ wrap.push(elt("div", null, null, "height: 0; clear: both;"));
468
+
469
+ var wrapElt = this.wrap = node.appendChild(elt("div", wrap, "CodeMirror-merge CodeMirror-merge-" + panes + "pane"));
470
+ this.edit = CodeMirror(editPane, copyObj(options));
471
+
472
+ if (left) left.init(leftPane, origLeft, options);
473
+ if (right) right.init(rightPane, origRight, options);
474
+
475
+ if (options.collapseIdentical)
476
+ this.editor().operation(function() {
477
+ collapseIdenticalStretches(self, options.collapseIdentical);
478
+ });
479
+ if (options.connect == "align") {
480
+ this.aligners = [];
481
+ alignChunks(this.left || this.right, true);
482
+ }
483
+
484
+ var onResize = function() {
485
+ if (left) makeConnections(left);
486
+ if (right) makeConnections(right);
487
+ };
488
+ CodeMirror.on(window, "resize", onResize);
489
+ var resizeInterval = setInterval(function() {
490
+ for (var p = wrapElt.parentNode; p && p != document.body; p = p.parentNode) {}
491
+ if (!p) { clearInterval(resizeInterval); CodeMirror.off(window, "resize", onResize); }
492
+ }, 5000);
493
+ };
494
+
495
+ function buildGap(dv) {
496
+ var lock = dv.lockButton = elt("div", null, "CodeMirror-merge-scrolllock");
497
+ lock.title = "Toggle locked scrolling";
498
+ var lockWrap = elt("div", [lock], "CodeMirror-merge-scrolllock-wrap");
499
+ CodeMirror.on(lock, "click", function() { setScrollLock(dv, !dv.lockScroll); });
500
+ var gapElts = [lockWrap];
501
+ if (dv.mv.options.revertButtons !== false) {
502
+ dv.copyButtons = elt("div", null, "CodeMirror-merge-copybuttons-" + dv.type);
503
+ CodeMirror.on(dv.copyButtons, "click", function(e) {
504
+ var node = e.target || e.srcElement;
505
+ if (!node.chunk) return;
506
+ if (node.className == "CodeMirror-merge-copy-reverse") {
507
+ copyChunk(dv, dv.orig, dv.edit, node.chunk);
508
+ return;
509
+ }
510
+ copyChunk(dv, dv.edit, dv.orig, node.chunk);
511
+ });
512
+ gapElts.unshift(dv.copyButtons);
513
+ }
514
+ if (dv.mv.options.connect != "align") {
515
+ var svg = document.createElementNS && document.createElementNS(svgNS, "svg");
516
+ if (svg && !svg.createSVGRect) svg = null;
517
+ dv.svg = svg;
518
+ if (svg) gapElts.push(svg);
519
+ }
520
+
521
+ return dv.gap = elt("div", gapElts, "CodeMirror-merge-gap");
522
+ }
523
+
524
+ MergeView.prototype = {
525
+ constuctor: MergeView,
526
+ editor: function() { return this.edit; },
527
+ rightOriginal: function() { return this.right && this.right.orig; },
528
+ leftOriginal: function() { return this.left && this.left.orig; },
529
+ setShowDifferences: function(val) {
530
+ if (this.right) this.right.setShowDifferences(val);
531
+ if (this.left) this.left.setShowDifferences(val);
532
+ },
533
+ rightChunks: function() {
534
+ if (this.right) { ensureDiff(this.right); return this.right.chunks; }
535
+ },
536
+ leftChunks: function() {
537
+ if (this.left) { ensureDiff(this.left); return this.left.chunks; }
538
+ }
539
+ };
540
+
541
+ function asString(obj) {
542
+ if (typeof obj == "string") return obj;
543
+ else return obj.getValue();
544
+ }
545
+
546
+ // Operations on diffs
547
+
548
+ var dmp = new diff_match_patch();
549
+ function getDiff(a, b) {
550
+ var diff = dmp.diff_main(a, b);
551
+ dmp.diff_cleanupSemantic(diff);
552
+ // The library sometimes leaves in empty parts, which confuse the algorithm
553
+ for (var i = 0; i < diff.length; ++i) {
554
+ var part = diff[i];
555
+ if (!part[1]) {
556
+ diff.splice(i--, 1);
557
+ } else if (i && diff[i - 1][0] == part[0]) {
558
+ diff.splice(i--, 1);
559
+ diff[i][1] += part[1];
560
+ }
561
+ }
562
+ return diff;
563
+ }
564
+
565
+ function getChunks(diff) {
566
+ var chunks = [];
567
+ var startEdit = 0, startOrig = 0;
568
+ var edit = Pos(0, 0), orig = Pos(0, 0);
569
+ for (var i = 0; i < diff.length; ++i) {
570
+ var part = diff[i], tp = part[0];
571
+ if (tp == DIFF_EQUAL) {
572
+ var startOff = startOfLineClean(diff, i) ? 0 : 1;
573
+ var cleanFromEdit = edit.line + startOff, cleanFromOrig = orig.line + startOff;
574
+ moveOver(edit, part[1], null, orig);
575
+ var endOff = endOfLineClean(diff, i) ? 1 : 0;
576
+ var cleanToEdit = edit.line + endOff, cleanToOrig = orig.line + endOff;
577
+ if (cleanToEdit > cleanFromEdit) {
578
+ if (i) chunks.push({origFrom: startOrig, origTo: cleanFromOrig,
579
+ editFrom: startEdit, editTo: cleanFromEdit});
580
+ startEdit = cleanToEdit; startOrig = cleanToOrig;
581
+ }
582
+ } else {
583
+ moveOver(tp == DIFF_INSERT ? edit : orig, part[1]);
584
+ }
585
+ }
586
+ if (startEdit <= edit.line || startOrig <= orig.line)
587
+ chunks.push({origFrom: startOrig, origTo: orig.line + 1,
588
+ editFrom: startEdit, editTo: edit.line + 1});
589
+ return chunks;
590
+ }
591
+
592
+ function endOfLineClean(diff, i) {
593
+ if (i == diff.length - 1) return true;
594
+ var next = diff[i + 1][1];
595
+ if (next.length == 1 || next.charCodeAt(0) != 10) return false;
596
+ if (i == diff.length - 2) return true;
597
+ next = diff[i + 2][1];
598
+ return next.length > 1 && next.charCodeAt(0) == 10;
599
+ }
600
+
601
+ function startOfLineClean(diff, i) {
602
+ if (i == 0) return true;
603
+ var last = diff[i - 1][1];
604
+ if (last.charCodeAt(last.length - 1) != 10) return false;
605
+ if (i == 1) return true;
606
+ last = diff[i - 2][1];
607
+ return last.charCodeAt(last.length - 1) == 10;
608
+ }
609
+
610
+ function chunkBoundariesAround(chunks, n, nInEdit) {
611
+ var beforeE, afterE, beforeO, afterO;
612
+ for (var i = 0; i < chunks.length; i++) {
613
+ var chunk = chunks[i];
614
+ var fromLocal = nInEdit ? chunk.editFrom : chunk.origFrom;
615
+ var toLocal = nInEdit ? chunk.editTo : chunk.origTo;
616
+ if (afterE == null) {
617
+ if (fromLocal > n) { afterE = chunk.editFrom; afterO = chunk.origFrom; }
618
+ else if (toLocal > n) { afterE = chunk.editTo; afterO = chunk.origTo; }
619
+ }
620
+ if (toLocal <= n) { beforeE = chunk.editTo; beforeO = chunk.origTo; }
621
+ else if (fromLocal <= n) { beforeE = chunk.editFrom; beforeO = chunk.origFrom; }
622
+ }
623
+ return {edit: {before: beforeE, after: afterE}, orig: {before: beforeO, after: afterO}};
624
+ }
625
+
626
+ function collapseSingle(cm, from, to) {
627
+ cm.addLineClass(from, "wrap", "CodeMirror-merge-collapsed-line");
628
+ var widget = document.createElement("span");
629
+ widget.className = "CodeMirror-merge-collapsed-widget";
630
+ widget.title = "Identical text collapsed. Click to expand.";
631
+ var mark = cm.markText(Pos(from, 0), Pos(to - 1), {
632
+ inclusiveLeft: true,
633
+ inclusiveRight: true,
634
+ replacedWith: widget,
635
+ clearOnEnter: true
636
+ });
637
+ function clear() {
638
+ mark.clear();
639
+ cm.removeLineClass(from, "wrap", "CodeMirror-merge-collapsed-line");
640
+ }
641
+ CodeMirror.on(widget, "click", clear);
642
+ return {mark: mark, clear: clear};
643
+ }
644
+
645
+ function collapseStretch(size, editors) {
646
+ var marks = [];
647
+ function clear() {
648
+ for (var i = 0; i < marks.length; i++) marks[i].clear();
649
+ }
650
+ for (var i = 0; i < editors.length; i++) {
651
+ var editor = editors[i];
652
+ var mark = collapseSingle(editor.cm, editor.line, editor.line + size);
653
+ marks.push(mark);
654
+ mark.mark.on("clear", clear);
655
+ }
656
+ return marks[0].mark;
657
+ }
658
+
659
+ function unclearNearChunks(dv, margin, off, clear) {
660
+ for (var i = 0; i < dv.chunks.length; i++) {
661
+ var chunk = dv.chunks[i];
662
+ for (var l = chunk.editFrom - margin; l < chunk.editTo + margin; l++) {
663
+ var pos = l + off;
664
+ if (pos >= 0 && pos < clear.length) clear[pos] = false;
665
+ }
666
+ }
667
+ }
668
+
669
+ function collapseIdenticalStretches(mv, margin) {
670
+ if (typeof margin != "number") margin = 2;
671
+ var clear = [], edit = mv.editor(), off = edit.firstLine();
672
+ for (var l = off, e = edit.lastLine(); l <= e; l++) clear.push(true);
673
+ if (mv.left) unclearNearChunks(mv.left, margin, off, clear);
674
+ if (mv.right) unclearNearChunks(mv.right, margin, off, clear);
675
+
676
+ for (var i = 0; i < clear.length; i++) {
677
+ if (clear[i]) {
678
+ var line = i + off;
679
+ for (var size = 1; i < clear.length - 1 && clear[i + 1]; i++, size++) {}
680
+ if (size > margin) {
681
+ var editors = [{line: line, cm: edit}];
682
+ if (mv.left) editors.push({line: getMatchingOrigLine(line, mv.left.chunks), cm: mv.left.orig});
683
+ if (mv.right) editors.push({line: getMatchingOrigLine(line, mv.right.chunks), cm: mv.right.orig});
684
+ var mark = collapseStretch(size, editors);
685
+ if (mv.options.onCollapse) mv.options.onCollapse(mv, line, size, mark);
686
+ }
687
+ }
688
+ }
689
+ }
690
+
691
+ // General utilities
692
+
693
+ function elt(tag, content, className, style) {
694
+ var e = document.createElement(tag);
695
+ if (className) e.className = className;
696
+ if (style) e.style.cssText = style;
697
+ if (typeof content == "string") e.appendChild(document.createTextNode(content));
698
+ else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
699
+ return e;
700
+ }
701
+
702
+ function clear(node) {
703
+ for (var count = node.childNodes.length; count > 0; --count)
704
+ node.removeChild(node.firstChild);
705
+ }
706
+
707
+ function attrs(elt) {
708
+ for (var i = 1; i < arguments.length; i += 2)
709
+ elt.setAttribute(arguments[i], arguments[i+1]);
710
+ }
711
+
712
+ function copyObj(obj, target) {
713
+ if (!target) target = {};
714
+ for (var prop in obj) if (obj.hasOwnProperty(prop)) target[prop] = obj[prop];
715
+ return target;
716
+ }
717
+
718
+ function moveOver(pos, str, copy, other) {
719
+ var out = copy ? Pos(pos.line, pos.ch) : pos, at = 0;
720
+ for (;;) {
721
+ var nl = str.indexOf("\n", at);
722
+ if (nl == -1) break;
723
+ ++out.line;
724
+ if (other) ++other.line;
725
+ at = nl + 1;
726
+ }
727
+ out.ch = (at ? 0 : out.ch) + (str.length - at);
728
+ if (other) other.ch = (at ? 0 : other.ch) + (str.length - at);
729
+ return out;
730
+ }
731
+
732
+ function posMin(a, b) { return (a.line - b.line || a.ch - b.ch) < 0 ? a : b; }
733
+ function posMax(a, b) { return (a.line - b.line || a.ch - b.ch) > 0 ? a : b; }
734
+ function posEq(a, b) { return a.line == b.line && a.ch == b.ch; }
735
+
736
+ function findPrevDiff(chunks, start, isOrig) {
737
+ for (var i = chunks.length - 1; i >= 0; i--) {
738
+ var chunk = chunks[i];
739
+ var to = (isOrig ? chunk.origTo : chunk.editTo) - 1;
740
+ if (to < start) return to;
741
+ }
742
+ }
743
+
744
+ function findNextDiff(chunks, start, isOrig) {
745
+ for (var i = 0; i < chunks.length; i++) {
746
+ var chunk = chunks[i];
747
+ var from = (isOrig ? chunk.origFrom : chunk.editFrom);
748
+ if (from > start) return from;
749
+ }
750
+ }
751
+
752
+ function goNearbyDiff(cm, dir) {
753
+ var found = null, views = cm.state.diffViews, line = cm.getCursor().line;
754
+ if (views) for (var i = 0; i < views.length; i++) {
755
+ var dv = views[i], isOrig = cm == dv.orig;
756
+ ensureDiff(dv);
757
+ var pos = dir < 0 ? findPrevDiff(dv.chunks, line, isOrig) : findNextDiff(dv.chunks, line, isOrig);
758
+ if (pos != null && (found == null || (dir < 0 ? pos > found : pos < found)))
759
+ found = pos;
760
+ }
761
+ if (found != null)
762
+ cm.setCursor(found, 0);
763
+ else
764
+ return CodeMirror.Pass;
765
+ }
766
+
767
+ CodeMirror.commands.goNextDiff = function(cm) {
768
+ return goNearbyDiff(cm, 1);
769
+ };
770
+ CodeMirror.commands.goPrevDiff = function(cm) {
771
+ return goNearbyDiff(cm, -1);
772
+ };
773
+ });