liquid_cms 0.3.1.0 → 0.3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. data/CHANGELOG.rdoc +10 -0
  2. data/Gemfile +0 -3
  3. data/README.rdoc +16 -2
  4. data/TODO.rdoc +0 -2
  5. data/app/controllers/cms/assets_controller.rb +20 -6
  6. data/app/controllers/cms/components_controller.rb +11 -3
  7. data/app/controllers/cms/pages_controller.rb +15 -4
  8. data/app/helpers/cms/common_helper.rb +31 -32
  9. data/app/liquid/cms_paperclip_extension.rb +75 -3
  10. data/app/liquid/tags/{data_tag.rb → cms/data_tag.rb} +0 -0
  11. data/app/models/cms/asset.rb +1 -1
  12. data/app/models/cms/component.rb +3 -3
  13. data/app/views/cms/assets/_form.html.erb +1 -2
  14. data/app/views/cms/assets/update.js.rjs +1 -0
  15. data/app/views/cms/components/update.js.rjs +1 -0
  16. data/app/views/cms/pages/_form.html.erb +3 -3
  17. data/app/views/cms/pages/update.js.rjs +1 -0
  18. data/app/views/layouts/cms.html.erb +4 -3
  19. data/config/initializers/cms/simple_form.rb +70 -12
  20. data/config/initializers/cms/simple_form_updates.rb +9 -3
  21. data/config/locales/cms/en.yml +6 -0
  22. data/lib/generators/liquid_cms/install_generator.rb +5 -1
  23. data/lib/generators/liquid_cms/templates/migration_rev2.rb +13 -0
  24. data/lib/generators/liquid_cms/templates/public/cms/codemirror/LICENSE +16 -20
  25. data/lib/generators/liquid_cms/templates/public/cms/codemirror/lib/codemirror.css +68 -0
  26. data/lib/generators/liquid_cms/templates/public/cms/codemirror/lib/codemirror.js +2197 -0
  27. data/lib/generators/liquid_cms/templates/public/cms/codemirror/lib/overlay.js +51 -0
  28. data/lib/generators/liquid_cms/templates/public/cms/codemirror/lib/runmode.js +27 -0
  29. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/clike/clike.js +247 -0
  30. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/clike/index.html +102 -0
  31. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/clojure/clojure.js +207 -0
  32. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/clojure/index.html +85 -0
  33. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/LICENSE +22 -0
  34. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/coffeescript.js +325 -0
  35. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/index.html +722 -0
  36. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/css/css.js +124 -0
  37. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/css/index.html +56 -0
  38. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/diff.css +3 -0
  39. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/diff.js +13 -0
  40. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/index.html +99 -0
  41. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/haskell/haskell.js +242 -0
  42. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/haskell/index.html +60 -0
  43. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/htmlmixed/htmlmixed.js +79 -0
  44. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/htmlmixed/index.html +52 -0
  45. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/javascript/index.html +78 -0
  46. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/javascript/javascript.js +352 -0
  47. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/jinja2/index.html +38 -0
  48. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/jinja2/jinja2.js +42 -0
  49. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/lua/index.html +72 -0
  50. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/lua/lua.js +140 -0
  51. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/index.html +340 -0
  52. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/markdown.css +10 -0
  53. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/markdown.js +230 -0
  54. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ntriples/index.html +33 -0
  55. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ntriples/ntriples.js +172 -0
  56. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/LICENSE +7 -0
  57. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/index.html +49 -0
  58. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/pascal.js +138 -0
  59. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/php/index.html +49 -0
  60. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/php/php.js +116 -0
  61. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/plsql/index.html +63 -0
  62. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/plsql/plsql.js +217 -0
  63. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/python/LICENSE.txt +21 -0
  64. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/python/index.html +123 -0
  65. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/python/python.js +320 -0
  66. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/r/LICENSE +24 -0
  67. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/r/index.html +74 -0
  68. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/r/r.js +141 -0
  69. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/index.html +526 -0
  70. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/rst.css +75 -0
  71. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/rst.js +333 -0
  72. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/LICENSE +24 -0
  73. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/index.html +172 -0
  74. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/ruby.js +195 -0
  75. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/scheme/index.html +65 -0
  76. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/scheme/scheme.js +202 -0
  77. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/smalltalk/index.html +56 -0
  78. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/smalltalk/smalltalk.js +122 -0
  79. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/sparql/index.html +41 -0
  80. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/sparql/sparql.js +143 -0
  81. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/stex/index.html +96 -0
  82. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/stex/stex.js +167 -0
  83. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/velocity/index.html +103 -0
  84. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/velocity/velocity.js +146 -0
  85. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/xml/index.html +42 -0
  86. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/xml/xml.js +231 -0
  87. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/xmlpure/index.html +60 -0
  88. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/xmlpure/xmlpure.js +481 -0
  89. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/yaml/index.html +68 -0
  90. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/yaml/yaml.js +95 -0
  91. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/cobalt.css +17 -0
  92. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/default.css +19 -0
  93. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/eclipse.css +24 -0
  94. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/elegant.css +9 -0
  95. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/neat.css +8 -0
  96. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/night.css +20 -0
  97. data/lib/generators/liquid_cms/templates/public/cms/javascripts/cms.js +1 -1
  98. data/lib/generators/liquid_cms/templates/public/cms/javascripts/codemirror_custom.js +96 -0
  99. data/lib/generators/liquid_cms/templates/public/cms/stylesheets/codemirror_changes.css +26 -0
  100. data/lib/generators/liquid_cms/templates/public/cms/stylesheets/liquid.css +7 -0
  101. data/lib/generators/liquid_cms/templates/public/cms/stylesheets/simple_form.css +0 -8
  102. data/lib/liquid_cms/version.rb +1 -1
  103. data/liquid_cms.gemspec +1 -1
  104. data/test/functional/assets_controller_test.rb +35 -20
  105. data/test/functional/components_controller_test.rb +15 -5
  106. data/test/functional/pages_controller_test.rb +19 -6
  107. data/test/rails_app/Gemfile +1 -2
  108. data/test/rails_app/config/locales/cms/en.yml +26 -4
  109. data/test/rails_app/db/migrate/20110511161859_create_liquid_cms_upgrade_rev2.rb +13 -0
  110. data/test/unit/asset_test.rb +1 -1
  111. data/test/unit/component_test.rb +1 -1
  112. metadata +89 -32
  113. data/generators/liquid_cms/templates/migration_rev1.rb +0 -38
  114. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/csscolors.css +0 -55
  115. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/docs.css +0 -158
  116. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/font.js +0 -15
  117. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/jscolors.css +0 -59
  118. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/sparqlcolors.css +0 -43
  119. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/xmlcolors.css +0 -55
  120. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/codemirror.js +0 -582
  121. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/editor.js +0 -1671
  122. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/highlight.js +0 -68
  123. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/mirrorframe.js +0 -81
  124. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsecss.js +0 -161
  125. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsedummy.js +0 -32
  126. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsehtmlmixed.js +0 -93
  127. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsejavascript.js +0 -359
  128. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsesparql.js +0 -162
  129. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsexml.js +0 -291
  130. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/select.js +0 -699
  131. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/stringstream.js +0 -159
  132. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/tokenize.js +0 -57
  133. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/tokenizejavascript.js +0 -174
  134. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/undo.js +0 -413
  135. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/unittests.js +0 -44
  136. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/util.js +0 -133
@@ -1,158 +0,0 @@
1
- body {
2
- font-family: Arial, sans-serif;
3
- line-height: 1.5;
4
- max-width: 64.3em;
5
- margin: 3em auto;
6
- padding: 0 1em;
7
- }
8
- body.droid {
9
- font-family: Droid Sans, Arial, sans-serif;
10
- }
11
-
12
- h1 {
13
- letter-spacing: -3px;
14
- font-size: 3.23em;
15
- font-weight: bold;
16
- margin: 0;
17
- }
18
-
19
- h2 {
20
- font-size: 1.23em;
21
- font-weight: bold;
22
- margin: .5em 0;
23
- letter-spacing: -1px;
24
- }
25
-
26
- h3 {
27
- font-size: 1em;
28
- font-weight: bold;
29
- margin: .4em 0;
30
- }
31
-
32
- pre {
33
- font-family: Courier New, monospaced;
34
- background-color: #eee;
35
- -moz-border-radius: 6px;
36
- -webkit-border-radius: 6px;
37
- border-radius: 6px;
38
- padding: 1em;
39
- }
40
-
41
- pre.code {
42
- margin: 0 1em;
43
- }
44
-
45
- .grey {
46
- font-size: 2em;
47
- padding: .5em 1em;
48
- line-height: 1.2em;
49
- margin-top: .5em;
50
- position: relative;
51
- }
52
-
53
- img.logo {
54
- position: absolute;
55
- right: -25px;
56
- bottom: 4px;
57
- }
58
-
59
- a:link, a:visited, .quasilink {
60
- color: #df0019;
61
- cursor: pointer;
62
- text-decoration: none;
63
- }
64
-
65
- a:hover, .quasilink:hover {
66
- color: #800004;
67
- }
68
-
69
- h1 a:link, h1 a:visited, h1 a:hover {
70
- color: black;
71
- }
72
-
73
- ul {
74
- margin: 0;
75
- padding-left: 1.2em;
76
- }
77
-
78
- a.download {
79
- color: white;
80
- background-color: #df0019;
81
- width: 100%;
82
- display: block;
83
- text-align: center;
84
- font-size: 1.23em;
85
- font-weight: bold;
86
- text-decoration: none;
87
- -moz-border-radius: 6px;
88
- -webkit-border-radius: 6px;
89
- border-radius: 6px;
90
- padding: .5em 0;
91
- margin-bottom: 1em;
92
- }
93
-
94
- a.download:hover {
95
- background-color: #bb0010;
96
- }
97
-
98
- .rel {
99
- margin-bottom: 0;
100
- }
101
-
102
- .rel-note {
103
- color: #777;
104
- font-size: .9em;
105
- margin-top: .1em;
106
- }
107
-
108
- .logo-braces {
109
- color: #df0019;
110
- position: relative;
111
- top: -4px;
112
- }
113
-
114
- .blk {
115
- float: left;
116
- }
117
-
118
- .left {
119
- width: 37em;
120
- padding-right: 6.53em;
121
- padding-bottom: 1em;
122
- }
123
-
124
- .left1 {
125
- width: 15.24em;
126
- padding-right: 6.45em;
127
- }
128
-
129
- .left2 {
130
- width: 15.24em;
131
- }
132
-
133
- .right {
134
- width: 20.68em;
135
- }
136
-
137
- .leftbig {
138
- width: 42.44em;
139
- padding-right: 6.53em;
140
- }
141
-
142
- .rightsmall {
143
- width: 15.24em;
144
- }
145
-
146
- .clear:after {
147
- visibility: hidden;
148
- display: block;
149
- font-size: 0;
150
- content: " ";
151
- clear: both;
152
- height: 0;
153
- }
154
- .clear { display: inline-block; }
155
- /* start commented backslash hack \*/
156
- * html .clear { height: 1%; }
157
- .clear { display: block; }
158
- /* close commented backslash hack */
@@ -1,15 +0,0 @@
1
- function waitForStyles() {
2
- for (var i = 0; i < document.styleSheets.length; i++)
3
- if (/googleapis/.test(document.styleSheets[i].href))
4
- return document.body.className += " droid";
5
- setTimeout(waitForStyles, 100);
6
- }
7
- setTimeout(function() {
8
- if (/AppleWebKit/.test(navigator.userAgent) && /iP[oa]d|iPhone/.test(navigator.userAgent)) return;
9
- var link = document.createElement("LINK");
10
- link.type = "text/css";
11
- link.rel = "stylesheet";
12
- link.href = "http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans:bold";
13
- document.documentElement.getElementsByTagName("HEAD")[0].appendChild(link);
14
- waitForStyles();
15
- }, 20);
@@ -1,59 +0,0 @@
1
- html {
2
- cursor: text;
3
- }
4
-
5
- .editbox {
6
- margin: .4em;
7
- padding: 0;
8
- font-family: monospace;
9
- font-size: 10pt;
10
- color: black;
11
- }
12
-
13
- pre.code, .editbox {
14
- color: #666666;
15
- }
16
-
17
- .editbox p {
18
- margin: 0;
19
- }
20
-
21
- span.js-punctuation {
22
- color: #666666;
23
- }
24
-
25
- span.js-operator {
26
- color: #666666;
27
- }
28
-
29
- span.js-keyword {
30
- color: #770088;
31
- }
32
-
33
- span.js-atom {
34
- color: #228811;
35
- }
36
-
37
- span.js-variable {
38
- color: black;
39
- }
40
-
41
- span.js-variabledef {
42
- color: #0000FF;
43
- }
44
-
45
- span.js-localvariable {
46
- color: #004499;
47
- }
48
-
49
- span.js-property {
50
- color: black;
51
- }
52
-
53
- span.js-comment {
54
- color: #AA7700;
55
- }
56
-
57
- span.js-string {
58
- color: #AA2222;
59
- }
@@ -1,43 +0,0 @@
1
- html {
2
- cursor: text;
3
- }
4
-
5
- .editbox {
6
- margin: .4em;
7
- padding: 0;
8
- font-family: monospace;
9
- font-size: 10pt;
10
- color: black;
11
- }
12
-
13
- .editbox p {
14
- margin: 0;
15
- }
16
-
17
- span.sp-keyword {
18
- color: #708;
19
- }
20
-
21
- span.sp-prefixed {
22
- color: #5d1;
23
- }
24
-
25
- span.sp-var {
26
- color: #00c;
27
- }
28
-
29
- span.sp-comment {
30
- color: #a70;
31
- }
32
-
33
- span.sp-literal {
34
- color: #a22;
35
- }
36
-
37
- span.sp-uri {
38
- color: #292;
39
- }
40
-
41
- span.sp-operator {
42
- color: #088;
43
- }
@@ -1,55 +0,0 @@
1
- html {
2
- cursor: text;
3
- }
4
-
5
- .editbox {
6
- margin: .4em;
7
- padding: 0;
8
- font-family: monospace;
9
- font-size: 10pt;
10
- color: black;
11
- }
12
-
13
- .editbox p {
14
- margin: 0;
15
- }
16
-
17
- span.xml-tagname {
18
- color: #A0B;
19
- }
20
-
21
- span.xml-attribute {
22
- color: #281;
23
- }
24
-
25
- span.xml-punctuation {
26
- color: black;
27
- }
28
-
29
- span.xml-attname {
30
- color: #00F;
31
- }
32
-
33
- span.xml-comment {
34
- color: #A70;
35
- }
36
-
37
- span.xml-cdata {
38
- color: #48A;
39
- }
40
-
41
- span.xml-processing {
42
- color: #999;
43
- }
44
-
45
- span.xml-entity {
46
- color: #A22;
47
- }
48
-
49
- span.xml-error {
50
- color: #F00 !important;
51
- }
52
-
53
- span.xml-text {
54
- color: black;
55
- }
@@ -1,582 +0,0 @@
1
- /* CodeMirror main module (http://codemirror.net/)
2
- *
3
- * Implements the CodeMirror constructor and prototype, which take care
4
- * of initializing the editor frame, and providing the outside interface.
5
- */
6
-
7
- // The CodeMirrorConfig object is used to specify a default
8
- // configuration. If you specify such an object before loading this
9
- // file, the values you put into it will override the defaults given
10
- // below. You can also assign to it after loading.
11
- var CodeMirrorConfig = window.CodeMirrorConfig || {};
12
-
13
- var CodeMirror = (function(){
14
- function setDefaults(object, defaults) {
15
- for (var option in defaults) {
16
- if (!object.hasOwnProperty(option))
17
- object[option] = defaults[option];
18
- }
19
- }
20
- function forEach(array, action) {
21
- for (var i = 0; i < array.length; i++)
22
- action(array[i]);
23
- }
24
- function createHTMLElement(el) {
25
- if (document.createElementNS && document.documentElement.namespaceURI !== null)
26
- return document.createElementNS("http://www.w3.org/1999/xhtml", el)
27
- else
28
- return document.createElement(el)
29
- }
30
-
31
- // These default options can be overridden by passing a set of
32
- // options to a specific CodeMirror constructor. See manual.html for
33
- // their meaning.
34
- setDefaults(CodeMirrorConfig, {
35
- stylesheet: [],
36
- path: "",
37
- parserfile: [],
38
- basefiles: ["util.js", "stringstream.js", "select.js", "undo.js", "editor.js", "tokenize.js"],
39
- iframeClass: null,
40
- passDelay: 200,
41
- passTime: 50,
42
- lineNumberDelay: 200,
43
- lineNumberTime: 50,
44
- continuousScanning: false,
45
- saveFunction: null,
46
- onLoad: null,
47
- onChange: null,
48
- undoDepth: 50,
49
- undoDelay: 800,
50
- disableSpellcheck: true,
51
- textWrapping: true,
52
- readOnly: false,
53
- width: "",
54
- height: "300px",
55
- minHeight: 100,
56
- autoMatchParens: false,
57
- markParen: null,
58
- unmarkParen: null,
59
- parserConfig: null,
60
- tabMode: "indent", // or "spaces", "default", "shift"
61
- enterMode: "indent", // or "keep", "flat"
62
- electricChars: true,
63
- reindentOnLoad: false,
64
- activeTokens: null,
65
- onCursorActivity: null,
66
- lineNumbers: false,
67
- firstLineNumber: 1,
68
- onLineNumberClick: null,
69
- indentUnit: 2,
70
- domain: null,
71
- noScriptCaching: false,
72
- incrementalLoading: false
73
- });
74
-
75
- function addLineNumberDiv(container, firstNum) {
76
- var nums = createHTMLElement("div"),
77
- scroller = createHTMLElement("div");
78
- nums.style.position = "absolute";
79
- nums.style.height = "100%";
80
- if (nums.style.setExpression) {
81
- try {nums.style.setExpression("height", "this.previousSibling.offsetHeight + 'px'");}
82
- catch(e) {} // Seems to throw 'Not Implemented' on some IE8 versions
83
- }
84
- nums.style.top = "0px";
85
- nums.style.left = "0px";
86
- nums.style.overflow = "hidden";
87
- container.appendChild(nums);
88
- scroller.className = "CodeMirror-line-numbers";
89
- nums.appendChild(scroller);
90
- scroller.innerHTML = "<div>" + firstNum + "</div>";
91
- return nums;
92
- }
93
-
94
- function frameHTML(options) {
95
- if (typeof options.parserfile == "string")
96
- options.parserfile = [options.parserfile];
97
- if (typeof options.basefiles == "string")
98
- options.basefiles = [options.basefiles];
99
- if (typeof options.stylesheet == "string")
100
- options.stylesheet = [options.stylesheet];
101
-
102
- var sp = " spellcheck=\"" + (options.disableSpellcheck ? "false" : "true") + "\"";
103
- var html = ["<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html" + sp + "><head>"];
104
- // Hack to work around a bunch of IE8-specific problems.
105
- html.push("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=EmulateIE7\"/>");
106
- var queryStr = options.noScriptCaching ? "?nocache=" + new Date().getTime().toString(16) : "";
107
- forEach(options.stylesheet, function(file) {
108
- html.push("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + file + queryStr + "\"/>");
109
- });
110
- forEach(options.basefiles.concat(options.parserfile), function(file) {
111
- if (!/^https?:/.test(file)) file = options.path + file;
112
- html.push("<script type=\"text/javascript\" src=\"" + file + queryStr + "\"><" + "/script>");
113
- });
114
- html.push("</head><body style=\"border-width: 0;\" class=\"editbox\"" + sp + "></body></html>");
115
- return html.join("");
116
- }
117
-
118
- var internetExplorer = document.selection && window.ActiveXObject && /MSIE/.test(navigator.userAgent);
119
-
120
- function CodeMirror(place, options) {
121
- // Use passed options, if any, to override defaults.
122
- this.options = options = options || {};
123
- setDefaults(options, CodeMirrorConfig);
124
-
125
- // Backward compatibility for deprecated options.
126
- if (options.dumbTabs) options.tabMode = "spaces";
127
- else if (options.normalTab) options.tabMode = "default";
128
- if (options.cursorActivity) options.onCursorActivity = options.cursorActivity;
129
-
130
- var frame = this.frame = createHTMLElement("iframe");
131
- if (options.iframeClass) frame.className = options.iframeClass;
132
- frame.frameBorder = 0;
133
- frame.style.border = "0";
134
- frame.style.width = '100%';
135
- frame.style.height = '100%';
136
- // display: block occasionally suppresses some Firefox bugs, so we
137
- // always add it, redundant as it sounds.
138
- frame.style.display = "block";
139
-
140
- var div = this.wrapping = createHTMLElement("div");
141
- div.style.position = "relative";
142
- div.className = "CodeMirror-wrapping";
143
- div.style.width = options.width;
144
- div.style.height = (options.height == "dynamic") ? options.minHeight + "px" : options.height;
145
- // This is used by Editor.reroutePasteEvent
146
- var teHack = this.textareaHack = createHTMLElement("textarea");
147
- div.appendChild(teHack);
148
- teHack.style.position = "absolute";
149
- teHack.style.left = "-10000px";
150
- teHack.style.width = "10px";
151
- teHack.tabIndex = 100000;
152
-
153
- // Link back to this object, so that the editor can fetch options
154
- // and add a reference to itself.
155
- frame.CodeMirror = this;
156
- if (options.domain && internetExplorer) {
157
- this.html = frameHTML(options);
158
- frame.src = "javascript:(function(){document.open();" +
159
- (options.domain ? "document.domain=\"" + options.domain + "\";" : "") +
160
- "document.write(window.frameElement.CodeMirror.html);document.close();})()";
161
- }
162
- else {
163
- frame.src = "javascript:;";
164
- }
165
-
166
- if (place.appendChild) place.appendChild(div);
167
- else place(div);
168
- div.appendChild(frame);
169
- if (options.lineNumbers) this.lineNumbers = addLineNumberDiv(div, options.firstLineNumber);
170
-
171
- this.win = frame.contentWindow;
172
- if (!options.domain || !internetExplorer) {
173
- this.win.document.open();
174
- this.win.document.write(frameHTML(options));
175
- this.win.document.close();
176
- }
177
- }
178
-
179
- CodeMirror.prototype = {
180
- init: function() {
181
- // Deprecated, but still supported.
182
- if (this.options.initCallback) this.options.initCallback(this);
183
- if (this.options.onLoad) this.options.onLoad(this);
184
- if (this.options.lineNumbers) this.activateLineNumbers();
185
- if (this.options.reindentOnLoad) this.reindent();
186
- if (this.options.height == "dynamic") this.setDynamicHeight();
187
- },
188
-
189
- getCode: function() {return this.editor.getCode();},
190
- setCode: function(code) {this.editor.importCode(code);},
191
- selection: function() {this.focusIfIE(); return this.editor.selectedText();},
192
- reindent: function() {this.editor.reindent();},
193
- reindentSelection: function() {this.focusIfIE(); this.editor.reindentSelection(null);},
194
-
195
- focusIfIE: function() {
196
- // in IE, a lot of selection-related functionality only works when the frame is focused
197
- if (this.win.select.ie_selection && document.activeElement != this.frame)
198
- this.focus();
199
- },
200
- focus: function() {
201
- this.win.focus();
202
- if (this.editor.selectionSnapshot) // IE hack
203
- this.win.select.setBookmark(this.win.document.body, this.editor.selectionSnapshot);
204
- },
205
- replaceSelection: function(text) {
206
- this.focus();
207
- this.editor.replaceSelection(text);
208
- return true;
209
- },
210
- replaceChars: function(text, start, end) {
211
- this.editor.replaceChars(text, start, end);
212
- },
213
- getSearchCursor: function(string, fromCursor, caseFold) {
214
- return this.editor.getSearchCursor(string, fromCursor, caseFold);
215
- },
216
-
217
- undo: function() {this.editor.history.undo();},
218
- redo: function() {this.editor.history.redo();},
219
- historySize: function() {return this.editor.history.historySize();},
220
- clearHistory: function() {this.editor.history.clear();},
221
-
222
- grabKeys: function(callback, filter) {this.editor.grabKeys(callback, filter);},
223
- ungrabKeys: function() {this.editor.ungrabKeys();},
224
-
225
- setParser: function(name, parserConfig) {this.editor.setParser(name, parserConfig);},
226
- setSpellcheck: function(on) {this.win.document.body.spellcheck = on;},
227
- setStylesheet: function(names) {
228
- if (typeof names === "string") names = [names];
229
- var activeStylesheets = {};
230
- var matchedNames = {};
231
- var links = this.win.document.getElementsByTagName("link");
232
- // Create hashes of active stylesheets and matched names.
233
- // This is O(n^2) but n is expected to be very small.
234
- for (var x = 0, link; link = links[x]; x++) {
235
- if (link.rel.indexOf("stylesheet") !== -1) {
236
- for (var y = 0; y < names.length; y++) {
237
- var name = names[y];
238
- if (link.href.substring(link.href.length - name.length) === name) {
239
- activeStylesheets[link.href] = true;
240
- matchedNames[name] = true;
241
- }
242
- }
243
- }
244
- }
245
- // Activate the selected stylesheets and disable the rest.
246
- for (var x = 0, link; link = links[x]; x++) {
247
- if (link.rel.indexOf("stylesheet") !== -1) {
248
- link.disabled = !(link.href in activeStylesheets);
249
- }
250
- }
251
- // Create any new stylesheets.
252
- for (var y = 0; y < names.length; y++) {
253
- var name = names[y];
254
- if (!(name in matchedNames)) {
255
- var link = this.win.document.createElement("link");
256
- link.rel = "stylesheet";
257
- link.type = "text/css";
258
- link.href = name;
259
- this.win.document.getElementsByTagName('head')[0].appendChild(link);
260
- }
261
- }
262
- },
263
- setTextWrapping: function(on) {
264
- if (on == this.options.textWrapping) return;
265
- this.win.document.body.style.whiteSpace = on ? "" : "nowrap";
266
- this.options.textWrapping = on;
267
- if (this.lineNumbers) {
268
- this.setLineNumbers(false);
269
- this.setLineNumbers(true);
270
- }
271
- },
272
- setIndentUnit: function(unit) {this.win.indentUnit = unit;},
273
- setUndoDepth: function(depth) {this.editor.history.maxDepth = depth;},
274
- setTabMode: function(mode) {this.options.tabMode = mode;},
275
- setEnterMode: function(mode) {this.options.enterMode = mode;},
276
- setLineNumbers: function(on) {
277
- if (on && !this.lineNumbers) {
278
- this.lineNumbers = addLineNumberDiv(this.wrapping,this.options.firstLineNumber);
279
- this.activateLineNumbers();
280
- }
281
- else if (!on && this.lineNumbers) {
282
- this.wrapping.removeChild(this.lineNumbers);
283
- this.wrapping.style.paddingLeft = "";
284
- this.lineNumbers = null;
285
- }
286
- },
287
-
288
- cursorPosition: function(start) {this.focusIfIE(); return this.editor.cursorPosition(start);},
289
- firstLine: function() {return this.editor.firstLine();},
290
- lastLine: function() {return this.editor.lastLine();},
291
- nextLine: function(line) {return this.editor.nextLine(line);},
292
- prevLine: function(line) {return this.editor.prevLine(line);},
293
- lineContent: function(line) {return this.editor.lineContent(line);},
294
- setLineContent: function(line, content) {this.editor.setLineContent(line, content);},
295
- removeLine: function(line){this.editor.removeLine(line);},
296
- insertIntoLine: function(line, position, content) {this.editor.insertIntoLine(line, position, content);},
297
- selectLines: function(startLine, startOffset, endLine, endOffset) {
298
- this.win.focus();
299
- this.editor.selectLines(startLine, startOffset, endLine, endOffset);
300
- },
301
- nthLine: function(n) {
302
- var line = this.firstLine();
303
- for (; n > 1 && line !== false; n--)
304
- line = this.nextLine(line);
305
- return line;
306
- },
307
- lineNumber: function(line) {
308
- var num = 0;
309
- while (line !== false) {
310
- num++;
311
- line = this.prevLine(line);
312
- }
313
- return num;
314
- },
315
- jumpToLine: function(line) {
316
- if (typeof line == "number") line = this.nthLine(line);
317
- this.selectLines(line, 0);
318
- this.win.focus();
319
- },
320
- currentLine: function() { // Deprecated, but still there for backward compatibility
321
- return this.lineNumber(this.cursorLine());
322
- },
323
- cursorLine: function() {
324
- return this.cursorPosition().line;
325
- },
326
- cursorCoords: function(start) {return this.editor.cursorCoords(start);},
327
-
328
- activateLineNumbers: function() {
329
- var frame = this.frame, win = frame.contentWindow, doc = win.document, body = doc.body,
330
- nums = this.lineNumbers, scroller = nums.firstChild, self = this;
331
- var barWidth = null;
332
-
333
- nums.onclick = function(e) {
334
- var handler = self.options.onLineNumberClick;
335
- if (handler) {
336
- var div = (e || window.event).target || (e || window.event).srcElement;
337
- var num = div == nums ? NaN : Number(div.innerHTML);
338
- if (!isNaN(num)) handler(num, div);
339
- }
340
- };
341
-
342
- function sizeBar() {
343
- if (frame.offsetWidth == 0) return;
344
- for (var root = frame; root.parentNode; root = root.parentNode){}
345
- if (!nums.parentNode || root != document || !win.Editor) {
346
- // Clear event handlers (their nodes might already be collected, so try/catch)
347
- try{clear();}catch(e){}
348
- clearInterval(sizeInterval);
349
- return;
350
- }
351
-
352
- if (nums.offsetWidth != barWidth) {
353
- barWidth = nums.offsetWidth;
354
- frame.parentNode.style.paddingLeft = barWidth + "px";
355
- }
356
- }
357
- function doScroll() {
358
- nums.scrollTop = body.scrollTop || doc.documentElement.scrollTop || 0;
359
- }
360
- // Cleanup function, registered by nonWrapping and wrapping.
361
- var clear = function(){};
362
- sizeBar();
363
- var sizeInterval = setInterval(sizeBar, 500);
364
-
365
- function ensureEnoughLineNumbers(fill) {
366
- var lineHeight = scroller.firstChild.offsetHeight;
367
- if (lineHeight == 0) return;
368
- var targetHeight = 50 + Math.max(body.offsetHeight, Math.max(frame.offsetHeight, body.scrollHeight || 0)),
369
- lastNumber = Math.ceil(targetHeight / lineHeight);
370
- for (var i = scroller.childNodes.length; i <= lastNumber; i++) {
371
- var div = createHTMLElement("div");
372
- div.appendChild(document.createTextNode(fill ? String(i + self.options.firstLineNumber) : "\u00a0"));
373
- scroller.appendChild(div);
374
- }
375
- }
376
-
377
- function nonWrapping() {
378
- function update() {
379
- ensureEnoughLineNumbers(true);
380
- doScroll();
381
- }
382
- self.updateNumbers = update;
383
- var onScroll = win.addEventHandler(win, "scroll", doScroll, true),
384
- onResize = win.addEventHandler(win, "resize", update, true);
385
- clear = function(){
386
- onScroll(); onResize();
387
- if (self.updateNumbers == update) self.updateNumbers = null;
388
- };
389
- update();
390
- }
391
-
392
- function wrapping() {
393
- var node, lineNum, next, pos, changes = [], styleNums = self.options.styleNumbers;
394
-
395
- function setNum(n, node) {
396
- // Does not typically happen (but can, if you mess with the
397
- // document during the numbering)
398
- if (!lineNum) lineNum = scroller.appendChild(createHTMLElement("div"));
399
- if (styleNums) styleNums(lineNum, node, n);
400
- // Changes are accumulated, so that the document layout
401
- // doesn't have to be recomputed during the pass
402
- changes.push(lineNum); changes.push(n);
403
- pos = lineNum.offsetHeight + lineNum.offsetTop;
404
- lineNum = lineNum.nextSibling;
405
- }
406
- function commitChanges() {
407
- for (var i = 0; i < changes.length; i += 2)
408
- changes[i].innerHTML = changes[i + 1];
409
- changes = [];
410
- }
411
- function work() {
412
- if (!scroller.parentNode || scroller.parentNode != self.lineNumbers) return;
413
-
414
- var endTime = new Date().getTime() + self.options.lineNumberTime;
415
- while (node) {
416
- setNum(next++, node.previousSibling);
417
- for (; node && !win.isBR(node); node = node.nextSibling) {
418
- var bott = node.offsetTop + node.offsetHeight;
419
- while (scroller.offsetHeight && bott - 3 > pos) {
420
- var oldPos = pos;
421
- setNum("&nbsp;");
422
- if (pos <= oldPos) break;
423
- }
424
- }
425
- if (node) node = node.nextSibling;
426
- if (new Date().getTime() > endTime) {
427
- commitChanges();
428
- pending = setTimeout(work, self.options.lineNumberDelay);
429
- return;
430
- }
431
- }
432
- while (lineNum) setNum(next++);
433
- commitChanges();
434
- doScroll();
435
- }
436
- function start(firstTime) {
437
- doScroll();
438
- ensureEnoughLineNumbers(firstTime);
439
- node = body.firstChild;
440
- lineNum = scroller.firstChild;
441
- pos = 0;
442
- next = self.options.firstLineNumber;
443
- work();
444
- }
445
-
446
- start(true);
447
- var pending = null;
448
- function update() {
449
- if (pending) clearTimeout(pending);
450
- if (self.editor.allClean()) start();
451
- else pending = setTimeout(update, 200);
452
- }
453
- self.updateNumbers = update;
454
- var onScroll = win.addEventHandler(win, "scroll", doScroll, true),
455
- onResize = win.addEventHandler(win, "resize", update, true);
456
- clear = function(){
457
- if (pending) clearTimeout(pending);
458
- if (self.updateNumbers == update) self.updateNumbers = null;
459
- onScroll();
460
- onResize();
461
- };
462
- }
463
- (this.options.textWrapping || this.options.styleNumbers ? wrapping : nonWrapping)();
464
- },
465
-
466
- setDynamicHeight: function() {
467
- var self = this, activity = self.options.onCursorActivity, win = self.win, body = win.document.body,
468
- lineHeight = null, timeout = null, vmargin = 2 * self.frame.offsetTop;
469
- body.style.overflowY = "hidden";
470
- win.document.documentElement.style.overflowY = "hidden";
471
- this.frame.scrolling = "no";
472
-
473
- function updateHeight() {
474
- var trailingLines = 0, node = body.lastChild, computedHeight;
475
- while (node && win.isBR(node)) {
476
- if (!node.hackBR) trailingLines++;
477
- node = node.previousSibling;
478
- }
479
- if (node) {
480
- lineHeight = node.offsetHeight;
481
- computedHeight = node.offsetTop + (1 + trailingLines) * lineHeight;
482
- }
483
- else if (lineHeight) {
484
- computedHeight = trailingLines * lineHeight;
485
- }
486
- if (computedHeight)
487
- self.wrapping.style.height = Math.max(vmargin + computedHeight, self.options.minHeight) + "px";
488
- }
489
- setTimeout(updateHeight, 300);
490
- self.options.onCursorActivity = function(x) {
491
- if (activity) activity(x);
492
- clearTimeout(timeout);
493
- timeout = setTimeout(updateHeight, 100);
494
- };
495
- }
496
- };
497
-
498
- CodeMirror.InvalidLineHandle = {toString: function(){return "CodeMirror.InvalidLineHandle";}};
499
-
500
- CodeMirror.replace = function(element) {
501
- if (typeof element == "string")
502
- element = document.getElementById(element);
503
- return function(newElement) {
504
- element.parentNode.replaceChild(newElement, element);
505
- };
506
- };
507
-
508
- CodeMirror.fromTextArea = function(area, options) {
509
- if (typeof area == "string")
510
- area = document.getElementById(area);
511
-
512
- options = options || {};
513
- if (area.style.width && options.width == null)
514
- options.width = area.style.width;
515
- if (area.style.height && options.height == null)
516
- options.height = area.style.height;
517
- if (options.content == null) options.content = area.value;
518
-
519
- function updateField() {
520
- area.value = mirror.getCode();
521
- }
522
- if (area.form) {
523
- if (typeof area.form.addEventListener == "function")
524
- area.form.addEventListener("submit", updateField, false);
525
- else
526
- area.form.attachEvent("onsubmit", updateField);
527
- var realSubmit = area.form.submit;
528
- function wrapSubmit() {
529
- updateField();
530
- // Can't use realSubmit.apply because IE6 is too stupid
531
- area.form.submit = realSubmit;
532
- area.form.submit();
533
- area.form.submit = wrapSubmit;
534
- }
535
- try {area.form.submit = wrapSubmit;} catch(e){}
536
- }
537
-
538
- function insert(frame) {
539
- if (area.nextSibling)
540
- area.parentNode.insertBefore(frame, area.nextSibling);
541
- else
542
- area.parentNode.appendChild(frame);
543
- }
544
-
545
- area.style.display = "none";
546
- var mirror = new CodeMirror(insert, options);
547
- mirror.save = updateField;
548
- mirror.toTextArea = function() {
549
- updateField();
550
- area.parentNode.removeChild(mirror.wrapping);
551
- area.style.display = "";
552
- if (area.form) {
553
- try {area.form.submit = realSubmit;} catch(e) {}
554
- if (typeof area.form.removeEventListener == "function")
555
- area.form.removeEventListener("submit", updateField, false);
556
- else
557
- area.form.detachEvent("onsubmit", updateField);
558
- }
559
- };
560
-
561
- return mirror;
562
- };
563
-
564
- CodeMirror.isProbablySupported = function() {
565
- // This is rather awful, but can be useful.
566
- var match;
567
- if (window.opera)
568
- return Number(window.opera.version()) >= 9.52;
569
- else if (/Apple Computer, Inc/.test(navigator.vendor) && (match = navigator.userAgent.match(/Version\/(\d+(?:\.\d+)?)\./)))
570
- return Number(match[1]) >= 3;
571
- else if (document.selection && window.ActiveXObject && (match = navigator.userAgent.match(/MSIE (\d+(?:\.\d*)?)\b/)))
572
- return Number(match[1]) >= 6;
573
- else if (match = navigator.userAgent.match(/gecko\/(\d{8})/i))
574
- return Number(match[1]) >= 20050901;
575
- else if (match = navigator.userAgent.match(/AppleWebKit\/(\d+)/))
576
- return Number(match[1]) >= 525;
577
- else
578
- return null;
579
- };
580
-
581
- return CodeMirror;
582
- })();