Scripts n Styles - Version 2.0.1.1

Version Description

Download this release

Release Info

Developer WraithKenny
Plugin Icon wp plugin Scripts n Styles
Version 2.0.1.1
Comparing to
See all releases

Code changes from version 3.1 to 2.0.1.1

Files changed (68) hide show
  1. README.txt +12 -63
  2. css/code-editor.css +0 -20
  3. css/less.css +0 -24
  4. css/meta-box-styles.css +63 -90
  5. css/options-styles.css +2 -12
  6. images/icon32.png +0 -0
  7. images/menu.png +0 -0
  8. includes/class.SnS_AJAX.php +0 -215
  9. includes/class.SnS_Admin.php +45 -158
  10. includes/class.SnS_Admin_Code_Editor.php +0 -90
  11. includes/class.SnS_Admin_Meta_Box.php +137 -334
  12. includes/class.SnS_Form.php +0 -169
  13. includes/class.SnS_Global_Page.php +0 -164
  14. includes/class.SnS_List_Usage.php +0 -176
  15. includes/class.SnS_Settings_Page.php +238 -127
  16. includes/class.SnS_Usage_Page.php +0 -87
  17. js/code-editor.js +0 -42
  18. js/global-page.js +0 -85
  19. js/meta-box-scripts.js +8 -426
  20. js/options-scripts.js +10 -0
  21. js/settings-page.js +0 -18
  22. languages/scripts-n-styles.pot +0 -398
  23. libraries/CodeMirror2/lib/codemirror.css +0 -126
  24. libraries/CodeMirror2/lib/codemirror.js +0 -3062
  25. libraries/CodeMirror2/mode/clike/clike.js +0 -234
  26. libraries/CodeMirror2/mode/clike/index.html +0 -101
  27. libraries/CodeMirror2/mode/css/index.html +0 -55
  28. libraries/CodeMirror2/mode/htmlmixed/index.html +0 -51
  29. libraries/CodeMirror2/mode/javascript/index.html +0 -77
  30. libraries/CodeMirror2/mode/less/less.js +0 -232
  31. libraries/CodeMirror2/mode/php/index.html +0 -48
  32. libraries/CodeMirror2/mode/php/php.js +0 -150
  33. libraries/CodeMirror2/mode/xml/index.html +0 -44
  34. libraries/CodeMirror2/mode/xml/xml.js +0 -325
  35. libraries/CodeMirror2/theme/ambiance.css +0 -82
  36. libraries/CodeMirror2/theme/blackboard.css +0 -25
  37. libraries/CodeMirror2/theme/cobalt.css +0 -18
  38. libraries/CodeMirror2/theme/eclipse.css +0 -25
  39. libraries/CodeMirror2/theme/lesser-dark.css +0 -45
  40. libraries/CodeMirror2/theme/monokai.css +0 -28
  41. libraries/CodeMirror2/theme/neat.css +0 -9
  42. libraries/CodeMirror2/theme/rubyblue.css +0 -21
  43. libraries/CodeMirror2/theme/xq-dark.css +0 -46
  44. libraries/{CodeMirror2 → codemirror}/LICENSE +1 -5
  45. libraries/codemirror/lib/codemirror.css +64 -0
  46. libraries/codemirror/lib/codemirror.js +2071 -0
  47. libraries/codemirror/lib/overlay.js +51 -0
  48. libraries/codemirror/lib/runmode.js +27 -0
  49. libraries/{CodeMirror2/mode/css → codemirror/mode}/css.js +4 -4
  50. libraries/{CodeMirror2/mode/htmlmixed → codemirror/mode}/htmlmixed.js +4 -15
  51. libraries/{CodeMirror2/mode/javascript → codemirror/mode}/javascript.js +15 -28
  52. libraries/codemirror/mode/xml.js +206 -0
  53. libraries/codemirror/theme/default.css +18 -0
  54. libraries/{CodeMirror2 → codemirror}/theme/elegant.css +2 -3
  55. libraries/codemirror/theme/neat.css +8 -0
  56. libraries/{CodeMirror2 → codemirror}/theme/night.css +4 -5
  57. libraries/less/LICENSE +0 -179
  58. libraries/less/dist/less-1.3.0.js +0 -3478
  59. libraries/less/dist/less-1.3.0.min.js +0 -9
  60. license.txt +258 -651
  61. screenshot-1.png +0 -0
  62. screenshot-2.png +0 -0
  63. screenshot-3.png +0 -0
  64. screenshot-4.png +0 -0
  65. screenshot-5.png +0 -0
  66. screenshot-6.png +0 -0
  67. scripts-n-styles.php +79 -116
  68. uninstall.php +12 -18
README.txt CHANGED
@@ -1,26 +1,24 @@
1
  === Scripts n Styles ===
2
  Contributors: WraithKenny, Touvan
 
3
  Tags: admin, CSS, javascript, code, custom, Style
4
- Requires at least: 3.3
5
- Tested up to: 3.4-beta3
6
- Stable tag: 3.1
7
- License: GPLv3 or later
8
 
9
  This plugin allows Admin users to individually add custom CSS, Classes and JavaScript directly to Post, Pages or any other custom post types.
10
 
11
  == Description ==
12
 
13
- This plugin allows Admin users the ability to add custom CSS and JavaScript directly into individual Post, Pages or any other registered custom post types. You can also add classes to the body tag and the post container. There is a Global settings page for which you can write Scripts n Styles for the entire blog.
14
-
15
- Admin's can also add classes to the TinyMCE "Formats" dropdown which users can use to style posts and pages directly. As of Scripts n Styles 3+ styles are reflected in the post editor.
16
 
17
  Because only well trusted users should ever be allowed to insert JavaScript directly into the pages of your site, this plugin restricts usage to admin type users. Admin's have access to even more sensitive areas by definition, so that should be relatively safe ;)
18
 
19
  A few notes about the implementation:
20
 
21
- * Admin users, or more specifically, *any user with the `manage_options` and `unfiltered_html` capabilities* (which by default is *only* the admin type user) can use this plugin's functionality. Some plugins extend user rolls, and so this plugin would naturally extend include rolls that have the appropriate capability.
22
- * CSS Styles are embeded, not linked, at the bottom of the `head` element with `style` tags by using `wp-head`. If your theme doesn't have this hook, this plugin (as well as most others) won't work.
23
- * JavaScript is embeded, not linked, at the bottom of the `body` (or `head`) element with `script` tags by using `wp-footer` (or `wp-head`). If your theme doesn't have this hook, this plugin (as well as most others) won't work.
24
  * **There is no input validation.** This plugin puts exactly what you type in the meta box directly into the `html` with no error checking. You are an Admin, and we trust you to be carefull. Try not to break anything.
25
 
26
  == Installation ==
@@ -39,49 +37,15 @@ Well, because plugins are supposed to, and should be expected to clean up after
39
 
40
  = Can I get around that somehow? =
41
 
42
- Sure, if you are an Admin, just go to the plugin editor and wipe out the uninstall.php and then WordPress will not delete the meta data on uninstall.
43
 
44
  == Screenshots ==
45
 
46
- 1. Settings Page for Writing Scripts n Styles that apply to the whole blog.
47
- 2. The Scripts panel of the Meta Box.
48
- 3. The Styles panel of the Meta Box.
49
- 4. The Classes panel. Add classes to the Style dropdown!
50
- 5. Enqueue panel. You can enqueue jQuery from here if you need!
51
- 6. Your styles are reflected in the Editor.
52
 
53
  == Changelog ==
54
 
55
- = 3.1 =
56
- * Feature: Dynamic Shortcodes.
57
- * Feature: LESS.js support.
58
- * Bug Fix: Proper output escaping.
59
-
60
- = 3.0.3 =
61
- * Bug Fix: wpautop formatting.
62
-
63
- = 3.0.2 =
64
- * Bug Fix: Fatal Error on post save
65
-
66
- = 3.0.1 =
67
- * Option to show Metabox by default
68
- * Check upgrade in more places
69
- * Fix double Settings Message on general-options
70
- * Fix empty post showing on usage
71
- * Cleaned up constants (internal)
72
-
73
- = 3 =
74
- * AJAX Saving of Meta-box
75
- * Dynamically populate the Styles Dropdown for TinyMCE
76
- * Styles preview in Post Editor
77
- * Enqueue dependant scripts if you need (like jQuery)
78
- * Adjustable menu placement
79
- * CodeMirror Themes
80
-
81
- = 2.0.3 =
82
- * fixed some bugs
83
-
84
- = 2.0.1 =
85
  * Better selection of `post_types` to add Scripts-n-Styles
86
  * micro-optimization for storage of class names.
87
  * Adds option page for globally adding Scripts and Styles.
@@ -107,21 +71,6 @@ Sure, if you are an Admin, just go to the plugin editor and wipe out the uninsta
107
 
108
  == Upgrade Notice ==
109
 
110
- = 3.1 =
111
- New Features and Bug fixes
112
-
113
- = 3.0.3 =
114
- Bug fix (wpauto issue)
115
-
116
- = 3.0.2 =
117
- Bug fix
118
-
119
- = 3.0.1 =
120
- Bug fixes
121
-
122
- = 3 =
123
- Adds new features.
124
-
125
  = 2 =
126
  Adds new features.
127
 
@@ -135,4 +84,4 @@ Minor update. Adds a few new features.
135
  Some small plugin meta data updates.
136
 
137
  = 1.0 =
138
- Initial Release, there is nothing to upgrade from.
1
  === Scripts n Styles ===
2
  Contributors: WraithKenny, Touvan
3
+ Donate link: http://wordpressfoundation.org/donate/
4
  Tags: admin, CSS, javascript, code, custom, Style
5
+ Requires at least: 3.1
6
+ Tested up to: 3.2
7
+ Stable tag: 2.0.1.1
 
8
 
9
  This plugin allows Admin users to individually add custom CSS, Classes and JavaScript directly to Post, Pages or any other custom post types.
10
 
11
  == Description ==
12
 
13
+ This plugin allows Admin users the ability to add custom CSS (at the bottom of the 'head' tag) and JavaScript (at the bottom of the 'body' tag) directly into individual Post, Pages or any other registered custom post types. You can also add classes to the body tag and the post container (if your theme supports `body_class()` and `post_class()` functions).
 
 
14
 
15
  Because only well trusted users should ever be allowed to insert JavaScript directly into the pages of your site, this plugin restricts usage to admin type users. Admin's have access to even more sensitive areas by definition, so that should be relatively safe ;)
16
 
17
  A few notes about the implementation:
18
 
19
+ * Admin users, or more specifically, *any user with the `manage_options` capability* (which by default is *only* the admin type user) can use this plugin's functionality. Some plugins extend user rolls, and so this plugin would naturally extend include rolls that have the appropriate capability.
20
+ * CSS Styles are included inline, not linked, at the bottom of the `head` element with `style` tags by using `wp-head`. If your theme doesn't have this hook, this plugin (as well as most others) won't work.
21
+ * JavaScript is included inline, not linked, at the bottom of the `body` element with `script` tags by using `wp-footer`. If your theme doesn't have this hook, this plugin (as well as most others) won't work.
22
  * **There is no input validation.** This plugin puts exactly what you type in the meta box directly into the `html` with no error checking. You are an Admin, and we trust you to be carefull. Try not to break anything.
23
 
24
  == Installation ==
37
 
38
  = Can I get around that somehow? =
39
 
40
+ Sure, if you are an Admin, just go to the plugin editor and wipe out the uninstall.php (Replace everything with a space character) and then WordPress will not delete the meta data on uninstall.
41
 
42
  == Screenshots ==
43
 
44
+ 1. The New and Improved Meta Box.
 
 
 
 
 
45
 
46
  == Changelog ==
47
 
48
+ = 2 =
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  * Better selection of `post_types` to add Scripts-n-Styles
50
  * micro-optimization for storage of class names.
51
  * Adds option page for globally adding Scripts and Styles.
71
 
72
  == Upgrade Notice ==
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  = 2 =
75
  Adds new features.
76
 
84
  Some small plugin meta data updates.
85
 
86
  = 1.0 =
87
+ Initial Release, there is nothing to upgrade from.
css/code-editor.css DELETED
@@ -1,20 +0,0 @@
1
- #newcontent {
2
- display: block;
3
- }
4
- .CodeMirror {
5
- border: 1px solid #DFDFDF;
6
- background-color: white;
7
- border-radius: 3px;
8
- margin: 8px 0;
9
- -moz-background-clip: padding;
10
- -webkit-background-clip: padding-box;
11
- background-clip: padding-box;
12
- overflow: hidden;
13
- }
14
- body .CodeMirror-scroll {
15
- height: auto;
16
- overflow: auto;
17
- }
18
- #template .CodeMirror div {
19
- margin-right: 0;
20
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
css/less.css DELETED
@@ -1,24 +0,0 @@
1
- /* Loosely based on the Midlesscss Textmate theme */
2
-
3
- .cm-s-lesscss { background: #262626; color: #f8f8f8; }
4
- .cm-s-lesscss span.CodeMirror-selected { background: #a8f !important; }
5
- .cm-s-lesscss .CodeMirror-gutter { background: #0a001f; border-right: 1px solid #aaa; }
6
- .cm-s-lesscss .CodeMirror-gutter-text { color: #f8f8f8; }
7
- .cm-s-lesscss .CodeMirror-cursor { border-left: 1px solid white !important; }
8
-
9
- .cm-s-lesscss span.cm-variable { color: #D9BF8C; }
10
- .cm-s-lesscss span.cm-comment { color: #666; }
11
- .cm-s-lesscss span.cm-atom { color: #C2B470; /*#845dc4;*/ }
12
- .cm-s-lesscss span.cm-number,
13
- .cm-s-lesscss span.cm-attribute { color: #B35E4D; }
14
- .cm-s-lesscss span.cm-keyword { color: #599eff; }
15
- .cm-s-lesscss span.cm-string { color: #BCD279; }
16
- .cm-s-lesscss span.cm-meta { color: #738C73; }
17
- .cm-s-lesscss span.cm-variable-2,
18
- .cm-s-lesscss span.cm-tag { color: #669199; }
19
- .cm-s-lesscss span.cm-variable-3,
20
- .cm-s-lesscss span.cm-def { color: white; }
21
- .cm-s-lesscss span.cm-error { color: #9d1e15; }
22
- .cm-s-lesscss span.cm-bracket { color: #EBEFE7; }
23
- .cm-s-lesscss span.cm-builtin,
24
- .cm-s-lesscss span.cm-special { color: #ff9e59; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
css/meta-box-styles.css CHANGED
@@ -1,128 +1,101 @@
1
  /* MetaBox.css */
2
 
3
-
4
- .wp-tab-bar {
5
- display: none;
6
- }
7
- body.js .wp-tab-bar {
8
  display: block;
9
- }
10
- #SnS_meta_box .title {
11
  margin-top: 1.5em;
12
  }
13
- body.js #SnS_meta_box .title,
14
- body.js .wp-tab-panel {
15
  display: none;
16
  }
17
- body.js .wp-tabs-panel-active {
18
- display: block;
19
- }
20
 
21
- .CodeMirror {
22
- border: 1px solid #DFDFDF;
23
- background-color: white;
24
- border-radius: 3px;
25
- margin: 8px 0;
26
- -moz-background-clip: padding;
27
- -webkit-background-clip: padding-box;
28
- background-clip: padding-box;
29
  overflow: hidden;
30
  }
31
- .CodeMirror, #editorcontainer #content {
32
- font-family: "Courier New", Courier, monospace;
 
33
  }
34
- .CodeMirror-scroll {
35
- height: auto;
36
- min-height: 50px;
37
- max-height: 300px;
38
- overflow: auto;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  }
40
 
41
- /* temp fix border-bottom rounding error problem.
42
- #side-sortables .wp-tab-bar {
43
- margin-bottom: 0px;
44
- min-height: 19px;
45
- }*/
46
 
47
- /* core styles */
48
- #post-body .wp-tab-bar a {
49
- text-decoration: underline;
50
- }
51
- #post-body .wp-tab-bar {
52
  float: left;
53
  margin: 0 -120px 0 5px;
54
  padding: 0;
55
  text-align: right;
56
  width: 120px;
57
  }
58
- #post-body .wp-tab-bar li {
59
  padding: 8px;
60
- display: list-item;
61
  }
62
- #post-body .wp-tab-active {
63
- border-radius: 3px 0 0 3px;
 
 
 
 
64
  border-style: solid none solid solid;
65
  border-width: 1px 0 1px 1px;
66
  margin-right: -1px;
67
- }
68
- #post-body .wp-tab-active a {
69
  font-weight: bold;
70
  text-decoration: none;
71
  }
72
- #post-body .wp-tab-panel {
73
- margin: 0 5px 0 125px;
 
 
 
 
74
  border-style: solid;
75
  border-width: 1px;
76
- height: 200px;
77
- overflow: auto;
78
- padding: 0.5em 0.9em;
79
- }
80
- /* end core styles */
81
-
82
- #post-body #SnS_meta_box .wp-tab-bar li {
83
- padding: 0px;
84
- }
85
- #post-body #SnS_meta_box .wp-tab-bar a {
86
- padding: 8px;
87
- display: block;
88
- }
89
- #SnS_meta_box .wp-tab-panel {
90
- height: auto;
91
  min-height: 200px;
92
- }
93
-
94
- #add-mce-dropdown-names label {
95
- width: 50px;
96
- display: inline-block
97
- }
98
- .sns-ajax-loading {
99
- vertical-align: middle;
100
- }
101
- .sns-ajax-wrap {
102
- height: 23px;
103
- }
104
- #sns-classes {
105
  overflow: hidden;
106
- width: 100%;
107
- }
108
- #SnS_classes_mce_wrapper {
109
- margin: 6px 0;
110
  }
111
- #mce-dropdown-names {
112
- display: none;
113
  }
114
- body.js #mce-dropdown-names {
 
 
 
115
  display: block;
116
  }
117
- #delete-mce-dropdown-names .sns-ajax-delete {
118
- cursor: pointer;
119
- display: inline-block;
120
- height: 10px;
121
- overflow: hidden;
122
- text-indent: -9999px;
123
- width: 10px;
124
- background: url("/wp-admin/images/xit.gif") no-repeat scroll 0 0 transparent;
125
  }
126
- #delete-mce-dropdown-names .sns-ajax-delete:hover {
127
- background: url("/wp-admin/images/xit.gif") no-repeat scroll -10px 0 transparent;
 
 
 
128
  }
1
  /* MetaBox.css */
2
 
3
+ #uFp_meta_box .title {
 
 
 
 
4
  display: block;
 
 
5
  margin-top: 1.5em;
6
  }
7
+ #uFp_meta_box .tabs-vertical .title,
8
+ #uFp_meta_box .tabs-horizontal .title {
9
  display: none;
10
  }
 
 
 
11
 
12
+ #uFp_meta_box .tabs-vertical,
13
+ #uFp_meta_box .tabs-horizontal,
14
+ #uFp_meta_box .ui-tabs-panel {
 
 
 
 
 
15
  overflow: hidden;
16
  }
17
+
18
+ #uFp_meta_box .tabs-vertical .wp-tab-bar {
19
+ margin-bottom: 3px;
20
  }
21
+ #uFp_meta_box .tabs-vertical .wp-tab-bar li {
22
+ display: inline;
23
+ line-height: 1.35em;
24
+ }
25
+ #uFp_meta_box .tabs-vertical .wp-tab-bar .ui-state-active {
26
+ background-color: #FFFFFF;
27
+ border-color: #DFDFDF;
28
+ border-style: solid solid none;
29
+ border-width: 1px 1px 0;
30
+ }
31
+ #uFp_meta_box .tabs-vertical .wp-tab-bar .ui-state-active a {
32
+ color: #333333;
33
+ }
34
+ #uFp_meta_box .tabs-vertical .ui-tabs-panel {
35
+ border-style: solid;
36
+ border-width: 1px;
37
+ padding: 0.5em 0.9em;
38
+ background-color: #FFFFFF;
39
+ border-color: #DFDFDF;
40
  }
41
 
 
 
 
 
 
42
 
43
+ #uFp_meta_box .tabs-horizontal .wp-tab-bar {
 
 
 
 
44
  float: left;
45
  margin: 0 -120px 0 5px;
46
  padding: 0;
47
  text-align: right;
48
  width: 120px;
49
  }
50
+ #uFp_meta_box .tabs-horizontal .wp-tab-bar li {
51
  padding: 8px;
52
+ display: block;
53
  }
54
+ #uFp_meta_box .tabs-horizontal .wp-tab-bar li a {
55
+ display: block;
56
+ }
57
+ #uFp_meta_box .tabs-horizontal .wp-tab-bar .ui-state-active {
58
+ background-color: #FFFFFF;
59
+ border-color: #DFDFDF;
60
  border-style: solid none solid solid;
61
  border-width: 1px 0 1px 1px;
62
  margin-right: -1px;
63
+ border-radius: 3px 0 0 3px;
 
64
  font-weight: bold;
65
  text-decoration: none;
66
  }
67
+ #uFp_meta_box .tabs-horizontal .wp-tab-bar .ui-state-active a {
68
+ color: #333333;
69
+ }
70
+ #uFp_meta_box .tabs-horizontal .ui-tabs-panel {
71
+ background-color: #FFFFFF;
72
+ border-color: #DFDFDF;
73
  border-style: solid;
74
  border-width: 1px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  min-height: 200px;
76
+ margin: 0 5px 0 125px;
 
 
 
 
 
 
 
 
 
 
 
 
77
  overflow: hidden;
78
+ padding: 0.5em 0.9em;
 
 
 
79
  }
80
+ #uFp_meta_box .tabs-horizontal .inside div {
81
+ overflow: hidden;
82
  }
83
+
84
+ .ui-tabs .ui-tabs-hide {
85
+ position: absolute;
86
+ left: -10000px;
87
  display: block;
88
  }
89
+
90
+ .CodeMirror {
91
+ border: 1px solid #DFDFDF;
92
+ background-color: white;
93
+ border-radius: 3px;
94
+ margin: 8px 0;
 
 
95
  }
96
+ .CodeMirror-scroll {
97
+ height: auto;
98
+ min-height: 50px;
99
+ max-height: 300px;
100
+ overflow: auto;
101
  }
css/options-styles.css CHANGED
@@ -1,24 +1,14 @@
1
  /* Options.css */
2
 
3
- textarea.code {
4
- display: block;
5
- }
6
  .CodeMirror {
7
  border: 1px solid #DFDFDF;
8
  background-color: white;
9
  border-radius: 3px;
10
  margin: 8px 0;
11
- -moz-background-clip: padding;
12
- -webkit-background-clip: padding-box;
13
- background-clip: padding-box;
14
- overflow: hidden;
15
  }
16
- body .CodeMirror-scroll {
17
  height: auto;
18
  min-height: 50px;
19
  max-height: 300px;
20
  overflow: auto;
21
- }
22
- #icon-sns {
23
- background: no-repeat center url('../images/icon32.png');
24
- }
1
  /* Options.css */
2
 
 
 
 
3
  .CodeMirror {
4
  border: 1px solid #DFDFDF;
5
  background-color: white;
6
  border-radius: 3px;
7
  margin: 8px 0;
 
 
 
 
8
  }
9
+ .CodeMirror-scroll {
10
  height: auto;
11
  min-height: 50px;
12
  max-height: 300px;
13
  overflow: auto;
14
+ }
 
 
 
images/icon32.png DELETED
Binary file
images/menu.png DELETED
Binary file
includes/class.SnS_AJAX.php DELETED
@@ -1,215 +0,0 @@
1
- <?php
2
- class SnS_AJAX
3
- {
4
- function init() {
5
- // Keep track of current tab.
6
- add_action( 'wp_ajax_sns_update_tab', array( __CLASS__, 'update_tab' ) );
7
- // TinyMCE requests a css file.
8
- add_action( 'wp_ajax_sns_tinymce_styles', array( __CLASS__, 'tinymce_styles' ) );
9
-
10
- // Ajax Saves.
11
- add_action( 'wp_ajax_sns_classes', array( __CLASS__, 'classes' ) );
12
- add_action( 'wp_ajax_sns_scripts', array( __CLASS__, 'scripts' ) );
13
- add_action( 'wp_ajax_sns_styles', array( __CLASS__, 'styles' ) );
14
- add_action( 'wp_ajax_sns_dropdown', array( __CLASS__, 'dropdown' ) );
15
- add_action( 'wp_ajax_sns_delete_class', array( __CLASS__, 'delete_class' ) );
16
- }
17
- function update_tab() {
18
- check_ajax_referer( Scripts_n_Styles::$file );
19
-
20
- $active_tab = isset( $_POST[ 'active_tab' ] ) ? 's'.$_POST[ 'active_tab' ] : 's0';
21
-
22
- if ( ! $user = wp_get_current_user() ) exit( 'Bad User' );
23
-
24
- $success = update_user_option( $user->ID, 'current_sns_tab', $active_tab, true);
25
- exit();
26
- }
27
- function tinymce_styles() {
28
- check_ajax_referer( 'sns_tinymce_styles' );
29
-
30
- if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
31
- $post_id = absint( $_REQUEST[ 'post_id' ] );
32
-
33
- $options = get_option( 'SnS_options' );
34
- $SnS = get_post_meta( $post_id, '_SnS', true );
35
- $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
36
-
37
- header('Content-Type: text/css; charset=' . get_option('blog_charset'));
38
-
39
- if ( ! empty( $options[ 'styles' ] ) ) echo $options[ 'styles' ];
40
-
41
- if ( ! empty( $styles[ 'styles' ] ) ) echo $styles[ 'styles' ];
42
-
43
- exit();
44
- }
45
-
46
- // AJAX handlers
47
- function classes() {
48
- check_ajax_referer( Scripts_n_Styles::$file );
49
- if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
50
-
51
- if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
52
- if ( ! isset( $_REQUEST[ 'classes_body' ], $_REQUEST[ 'classes_post' ] ) ) exit( 'Data missing.' );
53
-
54
- $post_id = absint( $_REQUEST[ 'post_id' ] );
55
- $SnS = get_post_meta( $post_id, '_SnS', true );
56
- $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
57
-
58
- $styles = self::maybe_set( $styles, 'classes_body' );
59
- $styles = self::maybe_set( $styles, 'classes_post' );
60
-
61
- if ( empty( $styles ) ) {
62
- if ( isset( $SnS['styles'] ) )
63
- unset( $SnS['styles'] );
64
- } else {
65
- $SnS[ 'styles' ] = $styles;
66
- }
67
- self::maybe_update( $post_id, '_SnS', $SnS );
68
-
69
- header('Content-Type: application/json; charset=' . get_option('blog_charset'));
70
- echo json_encode( array(
71
- "classes_post" => $_REQUEST[ 'classes_post' ],
72
- "classes_body" => $_REQUEST[ 'classes_body' ]
73
- ) );
74
-
75
- exit();
76
- }
77
- function scripts() {
78
- check_ajax_referer( Scripts_n_Styles::$file );
79
- if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
80
-
81
- if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
82
- if ( ! isset( $_REQUEST[ 'scripts' ], $_REQUEST[ 'scripts_in_head' ] ) ) exit( 'Data incorrectly sent.' );
83
-
84
- $post_id = absint( $_REQUEST[ 'post_id' ] );
85
- $SnS = get_post_meta( $post_id, '_SnS', true );
86
- $scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
87
-
88
- $scripts = self::maybe_set( $scripts, 'scripts_in_head' );
89
- $scripts = self::maybe_set( $scripts, 'scripts' );
90
-
91
- if ( empty( $scripts ) ) {
92
- if ( isset( $SnS['scripts'] ) )
93
- unset( $SnS['scripts'] );
94
- } else {
95
- $SnS[ 'scripts' ] = $scripts;
96
- }
97
- self::maybe_update( $post_id, '_SnS', $SnS );
98
-
99
- header('Content-Type: application/json; charset=' . get_option('blog_charset'));
100
- echo json_encode( array(
101
- "scripts" => $_REQUEST[ 'scripts' ],
102
- "scripts_in_head" => $_REQUEST[ 'scripts_in_head' ],
103
- ) );
104
-
105
- exit();
106
- }
107
- function styles() {
108
- check_ajax_referer( Scripts_n_Styles::$file );
109
- if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
110
-
111
- if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
112
- if ( ! isset( $_REQUEST[ 'styles' ] ) ) exit( 'Data incorrectly sent.' );
113
-
114
- $post_id = absint( $_REQUEST[ 'post_id' ] );
115
- $SnS = get_post_meta( $post_id, '_SnS', true );
116
- $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
117
-
118
- $styles = self::maybe_set( $styles, 'styles' );
119
-
120
- if ( empty( $styles ) ) {
121
- if ( isset( $SnS['styles'] ) )
122
- unset( $SnS['styles'] );
123
- } else {
124
- $SnS[ 'styles' ] = $styles;
125
- }
126
- self::maybe_update( $post_id, '_SnS', $SnS );
127
-
128
- header('Content-Type: application/json; charset=' . get_option('blog_charset'));
129
- echo json_encode( array(
130
- "styles" => $_REQUEST[ 'styles' ],
131
- ) );
132
-
133
- exit();
134
- }
135
- function dropdown() {
136
- check_ajax_referer( Scripts_n_Styles::$file );
137
- if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
138
-
139
- if ( empty( $_REQUEST[ 'format' ] ) ) exit( 'Missing Format.' );
140
- if ( empty( $_REQUEST[ 'format' ][ 'title' ] ) ) exit( 'Title is required.' );
141
- if ( empty( $_REQUEST[ 'format' ][ 'classes' ] ) ) exit( 'Classes is required.' );
142
- if (
143
- empty( $_REQUEST[ 'format' ][ 'inline' ] ) &&
144
- empty( $_REQUEST[ 'format' ][ 'block' ] ) &&
145
- empty( $_REQUEST[ 'format' ][ 'selector' ] )
146
- ) exit( 'A type is required.' );
147
-
148
- if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
149
- $post_id = absint( $_REQUEST[ 'post_id' ] );
150
-
151
- $SnS = get_post_meta( $post_id, '_SnS', true );
152
- $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
153
-
154
- if ( ! isset( $styles[ 'classes_mce' ] ) ) $styles[ 'classes_mce' ] = array();
155
-
156
- // pass title as key to be able to delete.
157
- $styles[ 'classes_mce' ][ $_REQUEST[ 'format' ][ 'title' ] ] = $_REQUEST[ 'format' ];
158
-
159
- $SnS[ 'styles' ] = $styles;
160
- update_post_meta( $post_id, '_SnS', $SnS );
161
-
162
- header('Content-Type: application/json; charset=' . get_option('blog_charset'));
163
- echo json_encode( array(
164
- "classes_mce" => array_values( $styles[ 'classes_mce' ] )
165
- ) );
166
-
167
- exit();
168
- }
169
- function delete_class() {
170
- check_ajax_referer( Scripts_n_Styles::$file );
171
- if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
172
-
173
- if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
174
- $post_id = absint( $_REQUEST[ 'post_id' ] );
175
- $SnS = get_post_meta( $post_id, '_SnS', true );
176
- $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
177
-
178
- $title = $_REQUEST[ 'delete' ];
179
-
180
- if ( isset( $styles[ 'classes_mce' ][ $title ] ) ) unset( $styles[ 'classes_mce' ][ $title ] );
181
- else exit ( 'No Format of that name.' );
182
-
183
- if ( empty( $styles[ 'classes_mce' ] ) ) unset( $styles[ 'classes_mce' ] );
184
-
185
- if ( empty( $styles ) ) {
186
- if ( isset( $SnS['styles'] ) )
187
- unset( $SnS['styles'] );
188
- } else {
189
- $SnS[ 'styles' ] = $styles;
190
- }
191
- self::maybe_update( $post_id, '_SnS', $SnS );
192
-
193
- if ( ! isset( $styles[ 'classes_mce' ] ) ) $styles[ 'classes_mce' ] = array( 'Empty' );
194
-
195
- header('Content-Type: application/json; charset=' . get_option('blog_charset'));
196
- echo json_encode( array(
197
- "classes_mce" => array_values( $styles[ 'classes_mce' ] )
198
- ) );
199
-
200
- exit();
201
- }
202
-
203
- // Differs from SnS_Admin_Meta_Box::maybe_set() in that this needs no prefix.
204
- function maybe_set( $o, $i ) {
205
- if ( empty( $_REQUEST[ $i ] ) ) {
206
- if ( isset( $o[ $i ] ) ) unset( $o[ $i ] );
207
- } else $o[ $i ] = $_REQUEST[ $i ];
208
- return $o;
209
- }
210
- function maybe_update( $id, $name, $meta ) {
211
- if ( empty( $meta ) ) delete_post_meta( $id, $name );
212
- else update_post_meta( $id, $name, $meta );
213
- }
214
- }
215
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class.SnS_Admin.php CHANGED
@@ -6,38 +6,23 @@
6
  * and JavaScript directly to individual Post, Pages or custom
7
  * post types.
8
  */
9
-
10
- require_once( 'class.SnS_Admin_Meta_Box.php' );
11
- require_once( 'class.SnS_Admin_Code_Editor.php' );
12
- require_once( 'class.SnS_Settings_Page.php' );
13
- require_once( 'class.SnS_Usage_Page.php' );
14
- require_once( 'class.SnS_Global_Page.php' );
15
- require_once( 'class.SnS_AJAX.php' );
16
- require_once( 'class.SnS_Form.php' );
17
 
18
  class SnS_Admin
19
  {
20
- /**#@+
21
- * Constants
22
- */
23
- const OPTION_GROUP = 'scripts_n_styles';
24
- const MENU_SLUG = 'sns';
25
- static $parent_slug = '';
26
- /**#@-*/
27
 
28
- /**
29
  * Initializing method.
30
- * @static
31
- */
32
  static function init() {
33
- add_action( 'admin_menu', array( 'SnS_Admin_Meta_Box', 'init' ) );
34
- add_action( 'admin_menu', array( 'SnS_Admin_Code_Editor', 'init' ) );
35
- add_action( 'network_admin_menu', array( 'SnS_Admin_Code_Editor', 'init' ) );
36
-
37
- add_action( 'admin_menu', array( __CLASS__, 'menu' ) );
38
-
39
- add_action( 'admin_init', array( 'SnS_AJAX', 'init' ) );
40
- add_action( 'admin_init', array( __CLASS__, 'load_plugin_textdomain' ) );
41
 
42
  $plugin_file = plugin_basename( Scripts_n_Styles::$file );
43
  add_filter( "plugin_action_links_$plugin_file", array( __CLASS__, 'plugin_action_links') );
@@ -45,153 +30,55 @@ class SnS_Admin
45
  register_activation_hook( Scripts_n_Styles::$file, array( __CLASS__, 'upgrade' ) );
46
  }
47
 
48
- function load_plugin_textdomain() {
49
- load_plugin_textdomain( 'scripts-n-styles', false, dirname( plugin_basename( Scripts_n_Styles::$file ) ) . '/languages/' );
50
- }
51
- function menu() {
52
- if ( ! current_user_can( 'manage_options' ) || ! current_user_can( 'unfiltered_html' ) ) return;
53
-
54
- $options = get_option( 'SnS_options' );
55
- $menu_spot = isset( $options[ 'menu_position' ] ) ? $options[ 'menu_position' ]: '';
56
- $top_spots = array( 'menu', 'object', 'utility' );
57
- $sub_spots = array( 'tools.php', 'options-general.php', 'themes.php' );
58
-
59
- if ( in_array( $menu_spot, $top_spots ) ) $parent_slug = SnS_Admin::MENU_SLUG;
60
- else if ( in_array( $menu_spot, $sub_spots ) ) $parent_slug = $menu_spot;
61
- else $parent_slug = 'tools.php';
62
-
63
- self::$parent_slug = $parent_slug;
64
-
65
- switch( $menu_spot ) {
66
- case 'menu':
67
- add_menu_page( __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Scripts n Styles', 'scripts-n-styles' ), 'unfiltered_html', $parent_slug, array( 'SnS_Form', 'page' ), plugins_url( 'images/menu.png', Scripts_n_Styles::$file ) );
68
- break;
69
- case 'object':
70
- add_object_page( __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Scripts n Styles', 'scripts-n-styles' ), 'unfiltered_html', $parent_slug, array( 'SnS_Form', 'page' ), plugins_url( 'images/menu.png', Scripts_n_Styles::$file ) );
71
- break;
72
- case 'utility':
73
- add_utility_page( __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Scripts n Styles', 'scripts-n-styles' ), 'unfiltered_html', $parent_slug, array( 'SnS_Form', 'page' ), plugins_url( 'images/menu.png', Scripts_n_Styles::$file ) );
74
- break;
75
- }
76
- SnS_Global_Page::init();
77
- SnS_Settings_Page::init();
78
- SnS_Usage_Page::init();
79
- }
80
-
81
- /**
82
- * Nav Tabs
83
- */
84
- function nav() {
85
- $options = get_option( 'SnS_options' );
86
- $page = $_REQUEST[ 'page' ];
87
- ?>
88
- <?php screen_icon(); ?>
89
- <h2>Scripts n Styles</h2>
90
- <?php if ( ! isset( $options[ 'menu_position' ] ) || 'options-general.php' != $options[ 'menu_position' ] ) settings_errors(); ?>
91
- <?php screen_icon( 'none' ); ?>
92
- <h3 class="nav-tab-wrapper">
93
- <a class="nav-tab<?php echo ( self::MENU_SLUG == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG ); ?>"><?php _e( 'Global', 'scripts-n-styles' ); ?></a>
94
- <a class="nav-tab<?php echo ( self::MENU_SLUG . '_settings' == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG . '_settings' ); ?>"><?php _e( 'Settings', 'scripts-n-styles' ); ?></a>
95
- <a class="nav-tab<?php echo ( self::MENU_SLUG . '_usage' == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG . '_usage' ); ?>"><?php _e( 'Usage', 'scripts-n-styles' ); ?></a>
96
- </h3>
97
- <?php
98
- }
99
-
100
- /**
101
- * Settings Page help
102
- */
103
- function help() {
104
- $help = '<p>' . __( 'In default (non MultiSite) WordPress installs, both <em>Administrators</em> and <em>Editors</em> can access <em>Scripts-n-Styles</em> on individual edit screens. Only <em>Administrators</em> can access this Options Page. In MultiSite WordPress installs, only <em>"Super Admin"</em> users can access either <em>Scripts-n-Styles</em> on individual edit screens or this Options Page. If other plugins change capabilities (specifically "unfiltered_html"), other users can be granted access.', 'scripts-n-styles' ) . '</p>';
105
- $help .= '<p><strong>' . __( 'Reference: jQuery Wrappers', 'scripts-n-styles' ) . '</strong></p>' .
106
- '<pre><code>jQuery(document).ready(function($) {
107
- // $() will work as an alias for jQuery() inside of this function
108
- });</code></pre>';
109
- $help .= '<pre><code>(function($) {
110
- // $() will work as an alias for jQuery() inside of this function
111
- })(jQuery);</code></pre>';
112
- $sidebar = '<p><strong>' . __( 'For more information:', 'scripts-n-styles' ) . '</strong></p>' .
113
- '<p>' . __( '<a href="http://wordpress.org/extend/plugins/scripts-n-styles/faq/" target="_blank">Frequently Asked Questions</a>', 'scripts-n-styles' ) . '</p>' .
114
- '<p>' . __( '<a href="https://github.com/unFocus/Scripts-n-Styles" target="_blank">Source on github</a>', 'scripts-n-styles' ) . '</p>' .
115
- '<p>' . __( '<a href="http://wordpress.org/tags/scripts-n-styles" target="_blank">Support Forums</a>', 'scripts-n-styles' ) . '</p>';
116
- $screen = get_current_screen();
117
- if ( method_exists( $screen, 'add_help_tab' ) ) {
118
- $screen->add_help_tab( array(
119
- 'title' => __( 'Scripts n Styles', 'scripts-n-styles' ),
120
- 'id' => 'scripts-n-styles',
121
- 'content' => $help
122
- )
123
- );
124
- if ( 'post' != $screen->id )
125
- $screen->set_help_sidebar( $sidebar );
126
- } else {
127
- add_contextual_help( $screen, $help . $sidebar );
128
- }
129
- }
130
-
131
- /**
132
  * Utility Method: Sets defaults if not previously set. Sets stored 'version' to VERSION.
133
- */
134
  static function upgrade() {
135
  $options = get_option( 'SnS_options' );
136
- if ( ! $options ) $options = array();
137
- $options[ 'version' ] = Scripts_n_Styles::VERSION;
138
- update_option( 'SnS_options', $options );
139
 
140
- /*
141
- * upgrade proceedure
142
- */
143
- $posts = get_posts(
144
- array(
145
- 'numberposts' => -1,
146
- 'post_type' => 'any',
147
- 'post_status' => 'any',
148
- 'meta_query' => array(
149
- 'relation' => 'OR',
150
- array( 'key' => '_SnS_scripts' ),
151
- array( 'key' => '_SnS_styles' ),
152
- array( 'key' => 'uFp_scripts' ),
153
- array( 'key' => 'uFp_styles' )
154
- )
155
- )
156
- );
157
 
158
- foreach( $posts as $post) {
159
- $styles = get_post_meta( $post->ID, '_SnS_styles', true );
160
- if ( empty( $styles ) )
161
- $styles = get_post_meta( $post->ID, 'uFp_styles', true );
162
-
163
- $scripts = get_post_meta( $post->ID, '_SnS_scripts', true );
164
- if ( empty( $scripts ) )
165
- $scripts = get_post_meta( $post->ID, 'uFp_scripts', true );
166
-
167
- $SnS = array();
168
- if ( ! empty( $styles ) )
169
- $SnS[ 'styles' ] = $styles;
170
-
171
- if ( ! empty( $scripts ) )
172
- $SnS[ 'scripts' ] = $scripts;
173
-
174
- if ( ! empty( $SnS ) )
175
- update_post_meta( $post->ID, '_SnS', $SnS );
176
-
177
- delete_post_meta( $post->ID, 'uFp_styles' );
178
- delete_post_meta( $post->ID, 'uFp_scripts' );
179
- delete_post_meta( $post->ID, '_SnS_styles' );
180
- delete_post_meta( $post->ID, '_SnS_scripts' );
181
- }
182
 
 
 
 
 
 
 
183
  }
184
 
185
- /**
186
  * Adds link to the Settings Page in the WordPress "Plugin Action Links" array.
187
  * @param array $actions
188
  * @return array
189
- */
190
  static function plugin_action_links( $actions ) {
191
- $actions[ 'settings' ] = '<a href="' . menu_page_url( SnS_Settings_Page::MENU_SLUG, false ) . '"/>' . __( 'Settings' ) . '</a>';
192
  return $actions;
193
  }
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  }
196
 
197
  ?>
6
  * and JavaScript directly to individual Post, Pages or custom
7
  * post types.
8
  */
 
 
 
 
 
 
 
 
9
 
10
  class SnS_Admin
11
  {
12
+ /**#@+
13
+ * Constants
14
+ */
15
+ const MENU_SLUG = 'Scripts-n-Styles';
16
+ const VERSION = '1.0.3-beta';
17
+ /**#@-*/
 
18
 
19
+ /**
20
  * Initializing method.
21
+ * @static
22
+ */
23
  static function init() {
24
+ add_action( 'admin_menu', array( __CLASS__, 'admin_meta_box' ) );
25
+ add_action( 'admin_menu', array( __CLASS__, 'settings_page' ) );
 
 
 
 
 
 
26
 
27
  $plugin_file = plugin_basename( Scripts_n_Styles::$file );
28
  add_filter( "plugin_action_links_$plugin_file", array( __CLASS__, 'plugin_action_links') );
30
  register_activation_hook( Scripts_n_Styles::$file, array( __CLASS__, 'upgrade' ) );
31
  }
32
 
33
+ /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  * Utility Method: Sets defaults if not previously set. Sets stored 'version' to VERSION.
35
+ */
36
  static function upgrade() {
37
  $options = get_option( 'SnS_options' );
 
 
 
38
 
39
+ if ( ! isset( $options[ 'show_usage' ] ) )
40
+ $options[ 'show_usage' ] = 'no';
41
+ $options[ 'version' ] = self::VERSION;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
+ update_option( 'SnS_options', $options );
44
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
+ /**
47
+ * Utility Method: Compares VERSION to stored 'version' value.
48
+ */
49
+ static function upgrade_check() {
50
+ if ( ! isset( $options[ 'version' ] ) || version_compare( self::VERSION, $options[ 'version' ], '>' ) )
51
+ self::upgrade();
52
  }
53
 
54
+ /**
55
  * Adds link to the Settings Page in the WordPress "Plugin Action Links" array.
56
  * @param array $actions
57
  * @return array
58
+ */
59
  static function plugin_action_links( $actions ) {
60
+ $actions[ 'settings' ] = '<a href="' . menu_page_url( self::MENU_SLUG, false ) . '"/>Settings</a>';
61
  return $actions;
62
  }
63
 
64
+ /**
65
+ * Settings Page
66
+ * Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
67
+ */
68
+ static function admin_meta_box() {
69
+ include_once( 'class.SnS_Admin_Meta_Box.php' );
70
+ SnS_Admin_Meta_Box::init();
71
+ }
72
+
73
+ /**
74
+ * Settings Page
75
+ * Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
76
+ */
77
+ static function settings_page() {
78
+ /* NOTE: Even when Scripts n Styles is not restricted by 'manage_options', Editors still can't submit the option page */
79
+ include_once( 'class.SnS_Settings_Page.php' );
80
+ SnS_Settings_Page::init();
81
+ }
82
  }
83
 
84
  ?>
includes/class.SnS_Admin_Code_Editor.php DELETED
@@ -1,90 +0,0 @@
1
- <?php
2
- /**
3
- * SnS_Admin_Code_Editor
4
- */
5
-
6
- class SnS_Admin_Code_Editor
7
- {
8
- /**
9
- * Initializing method.
10
- */
11
- function init() {
12
- add_action( 'admin_head-theme-editor.php', array( __CLASS__, 'styles' ) );
13
- add_action( 'admin_head-plugin-editor.php', array( __CLASS__, 'styles' ) );
14
-
15
- }
16
-
17
- function styles() {
18
- $options = get_option( 'SnS_options' );
19
- $cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
20
-
21
- wp_enqueue_style( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.css', Scripts_n_Styles::$file), array(), '2.2' );
22
-
23
- if ( in_array( $cm_theme, array( 'cobalt', 'eclipse', 'elegant', 'monokai', 'neat', 'night', 'rubyblue' ) ) )
24
- wp_enqueue_style( "codemirror-$cm_theme", plugins_url( "libraries/CodeMirror2/theme/$cm_theme.css", Scripts_n_Styles::$file), array( 'codemirror' ), '2.2' );
25
-
26
- wp_enqueue_style( 'sns-code-editor', plugins_url( 'css/code-editor.css', Scripts_n_Styles::$file), array( 'codemirror' ), Scripts_n_Styles::VERSION );
27
-
28
- wp_enqueue_script(
29
- 'codemirror',
30
- plugins_url( 'libraries/CodeMirror2/lib/codemirror.js', Scripts_n_Styles::$file),
31
- array(),
32
- '2.2' );
33
- wp_enqueue_script(
34
- 'codemirror-css',
35
- plugins_url( 'libraries/CodeMirror2/mode/css/css.js', Scripts_n_Styles::$file),
36
- array( 'codemirror' ),
37
- '2.2' );
38
- wp_enqueue_script(
39
- 'codemirror-less',
40
- plugins_url( 'libraries/CodeMirror2/mode/less/less.js', Scripts_n_Styles::$file),
41
- array( 'codemirror' ),
42
- '2.2' );
43
- wp_enqueue_script(
44
- 'codemirror-javascript',
45
- plugins_url( 'libraries/CodeMirror2/mode/javascript/javascript.js', Scripts_n_Styles::$file),
46
- array( 'codemirror' ),
47
- '2.2' );
48
- wp_register_script(
49
- 'codemirror-xml',
50
- plugins_url( 'libraries/CodeMirror2/mode/xml/xml.js', Scripts_n_Styles::$file),
51
- array( 'codemirror' ),
52
- '2.2' );
53
- wp_register_script(
54
- 'codemirror-htmlmixed',
55
- plugins_url( 'libraries/CodeMirror2/mode/htmlmixed/htmlmixed.js', Scripts_n_Styles::$file),
56
- array( 'codemirror-xml',
57
- 'codemirror-css',
58
- 'codemirror-javascript'
59
- ),
60
- '2.2' );
61
- wp_register_script(
62
- 'codemirror-clike',
63
- plugins_url( 'libraries/CodeMirror2/mode/clike/clike.js', Scripts_n_Styles::$file),
64
- array( 'codemirror' ),
65
- '2.2' );
66
- wp_register_script(
67
- 'codemirror-php',
68
- plugins_url( 'libraries/CodeMirror2/mode/php/php.js', Scripts_n_Styles::$file),
69
- array( 'codemirror-xml',
70
- 'codemirror-css',
71
- 'codemirror-javascript',
72
- 'codemirror-clike'
73
- ),
74
- '2.2' );
75
- wp_enqueue_script(
76
- 'sns-code-editor',
77
- plugins_url( 'js/code-editor.js', Scripts_n_Styles::$file),
78
- array( 'editor',
79
- 'jquery-ui-tabs',
80
- 'codemirror-javascript',
81
- 'codemirror-css',
82
- 'codemirror-htmlmixed',
83
- 'codemirror-php'
84
- ),
85
- Scripts_n_Styles::VERSION, true );
86
-
87
- wp_localize_script( 'sns-code-editor', 'codemirror_options', array( 'theme' => $cm_theme ) );
88
- }
89
- }
90
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class.SnS_Admin_Meta_Box.php CHANGED
@@ -6,407 +6,210 @@
6
  * and JavaScript directly to individual Post, Pages or custom
7
  * post types.
8
  */
 
 
 
9
 
10
  class SnS_Admin_Meta_Box
11
  {
12
- /*
13
- * Constants
14
- */
15
  const NONCE_NAME = 'scripts_n_styles_noncename';
16
 
17
  static $post_types;
18
 
19
- /**
20
- * Initializing method.
21
- */
 
22
  static function init() {
23
  add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
24
  add_action( 'save_post', array( __CLASS__, 'save_post' ) );
25
  }
26
 
27
- function mce_buttons_2( $buttons ) {
28
- global $post;
29
- $SnS = get_post_meta( $post->ID, '_SnS', true );
30
- $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
31
-
32
- if ( ! empty( $styles[ 'classes_mce' ] ) )
33
- array_unshift( $buttons, 'styleselect' );
34
-
35
- return $buttons;
36
- }
37
- function tiny_mce_before_init( $initArray ) {
38
- global $post;
39
- $SnS = get_post_meta( $post->ID, '_SnS', true );
40
- $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
41
-
42
- // Add div as a format option, should probably use a string replace thing here.
43
- // Better yet, a setting for adding these. Postpone for now.
44
- //$initArray['theme_advanced_blockformats'] = "p,address,pre,h1,h2,h3,h4,h5,h6,div";
45
-
46
- if ( ( ! empty( $styles[ 'classes_body' ] ) || ! empty( $styles[ 'classes_post' ] ) ) && ! isset( $initArray['body_class'] ) )
47
- $initArray['body_class'] = '';
48
-
49
- // Add body_class (and/or maybe post_class) values... somewhat problematic.
50
- if ( ! empty( $styles[ 'classes_body' ] ) )
51
- $initArray['body_class'] .= ' ' . $styles[ 'classes_body' ];
52
- if ( ! empty( $styles[ 'classes_post' ] ) )
53
- $initArray['body_class'] .= ' ' . $styles[ 'classes_post' ];
54
-
55
- // In case Themes or plugins have added style_formats, not tested.
56
- if ( isset( $initArray['style_formats'] ) )
57
- $style_formats = json_decode( $initArray['style_formats'], true );
58
- else
59
- $style_formats = array();
60
-
61
- if ( ! empty( $styles[ 'classes_mce' ] ) )
62
- foreach ( $styles[ 'classes_mce' ] as $format )
63
- $style_formats[] = $format;
64
-
65
- if ( ! empty( $style_formats ) )
66
- $initArray['style_formats'] = json_encode( $style_formats );
67
-
68
- return $initArray;
69
- }
70
-
71
- /**
72
- * Admin Action: 'mce_css'
73
- * Adds a styles sheet to TinyMCE via ajax that contains the current styles data.
74
- */
75
- static function mce_css( $mce_css ) {
76
- global $post;
77
- $url = admin_url( 'admin-ajax.php' );
78
- $url = wp_nonce_url( $url, 'sns_tinymce_styles' );
79
- $url = add_query_arg( 'post_id', $post->ID, $url );
80
- $url = add_query_arg( 'action', 'sns_tinymce_styles', $url );
81
- $mce_css .= ',' . $url;
82
- return $mce_css;
83
- }
84
-
85
- /**
86
  * Admin Action: 'add_meta_boxes'
87
  * Main Meta Box function. Checks restriction options and display options, calls add_meta_box() and adds actions for adding admin CSS and JavaScript.
88
- */
89
  static function add_meta_boxes() {
90
  if ( current_user_can( 'unfiltered_html' ) ) {
91
- $post_type = get_current_screen()->post_type;
92
- if ( in_array( $post_type, get_post_types( array('show_ui' => true, 'public' => true ) ) ) ) {
93
- add_meta_box( 'SnS_meta_box', __( 'Scripts n Styles', 'scripts-n-styles' ), array( __CLASS__, 'admin_meta_box' ), $post_type, 'normal', 'high' );
94
- add_filter( 'default_hidden_meta_boxes', array( __CLASS__, 'default_hidden_meta_boxes' ) );
95
- add_action( "admin_print_styles", array( __CLASS__, 'meta_box_styles'));
96
- add_action( "admin_print_scripts", array( __CLASS__, 'meta_box_scripts'));
97
- add_filter( 'contextual_help', array( 'SnS_Admin', 'help' ) );
98
- add_filter( 'mce_buttons_2', array( __CLASS__, 'mce_buttons_2' ) );
99
- add_filter( 'tiny_mce_before_init', array( __CLASS__, 'tiny_mce_before_init' ) );
100
- add_filter( 'mce_css', array( __CLASS__, 'mce_css' ) );
101
  }
 
 
 
 
102
  }
103
  }
104
-
105
  static function default_hidden_meta_boxes( $hidden ) {
106
- $options = get_option( 'SnS_options' );
107
- if ( ! ( isset( $options[ 'metabox' ] ) && 'yes' == $options[ 'metabox' ] ) ) {
108
- $hidden[] = 'SnS_meta_box';
109
- $hidden[] = 'SnS_shortcode';
110
- }
111
- return $hidden;
 
 
 
 
 
 
112
  }
 
113
 
114
- /**
115
  * Admin Action: 'add_meta_boxes'
116
  * Outputs the Meta Box. Only called on callback from add_meta_box() during the add_meta_boxes action.
117
  * @param unknown_type WordPress Post object.
118
- */
119
- static function admin_meta_box( $post ) {
120
  $registered_handles = Scripts_n_Styles::get_wp_registered();
121
- $SnS = get_post_meta( $post->ID, '_SnS', true );
122
- $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
123
- $scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
124
-
125
- $position = get_user_option( "current_sns_tab" );
126
- if ( ! in_array( $position, array( 's0', 's1', 's2', 's3', 's4' ) ) ) $position = 's0';
127
- wp_nonce_field( Scripts_n_Styles::$file, self::NONCE_NAME );
128
  ?>
129
- <ul class="wp-tab-bar">
130
- <li<?php echo ( 's0' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_scripts-tab"><?php _e( 'Scripts', 'scripts-n-styles' ) ?></a></li>
131
- <li<?php echo ( 's1' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_styles-tab"><?php _e( 'Styles', 'scripts-n-styles' ) ?></a></li>
132
- <li<?php echo ( 's2' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_classes_body-tab"><?php _e( 'Classes', 'scripts-n-styles' ) ?></a></li>
133
- <li<?php echo ( 's3' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_enqueue_scripts-tab"><?php _e( 'Include Scripts', 'scripts-n-styles' ) ?></a></li>
134
- <li<?php echo ( 's4' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_shortcodes-tab"><?php _e( 'Shortcodes', 'scripts-n-styles' ) ?></a></li>
 
 
 
135
  </ul>
136
 
137
- <div class="wp-tab-panel" id="SnS_scripts-tab">
138
- <p><em><?php _e( "This code will be included <strong>verbatim</strong> in <code>&lt;script></code> tags at the end of your page's (or post's)", 'scripts-n-styles' ) ?> ...</em></p>
139
- <label for="SnS_scripts_in_head" class="title"><?php _e( '<strong>Scripts</strong> (for the <code>head</code> element):', 'scripts-n-styles' ) ?> </label>
140
- <textarea class="codemirror js" name="SnS_scripts_in_head" id="SnS_scripts_in_head" rows="5" cols="40" style="width: 98%;"><?php echo isset( $scripts[ 'scripts_in_head' ] ) ? esc_textarea( $scripts[ 'scripts_in_head' ] ) : ''; ?></textarea>
141
- <p><em>... <code>&lt;/head></code> <?php _e( 'tag', 'scripts-n-styles' ) ?>.</em></p>
142
- <label for="SnS_scripts" class="title"><strong>Scripts</strong>: </label>
143
- <textarea class="codemirror js" name="SnS_scripts" id="SnS_scripts" rows="5" cols="40" style="width: 98%;"><?php echo isset( $scripts[ 'scripts' ] ) ? esc_textarea( $scripts[ 'scripts' ] ) : ''; ?></textarea>
144
- <p><em>... <code>&lt;/body></code> <?php _e( 'tag', 'scripts-n-styles' ) ?>.</em></p>
145
  </div>
146
 
147
- <div class="wp-tab-panel" id="SnS_styles-tab">
148
- <label for="SnS_styles" class="title"><?php _e( '<strong>Styles</strong>:', 'scripts-n-styles' ) ?> </label>
149
- <textarea class="codemirror css" name="SnS_styles" id="SnS_styles" rows="5" cols="40" style="width: 98%;"><?php echo isset( $styles[ 'styles' ] ) ? esc_textarea( $styles[ 'styles' ] ) : ''; ?></textarea>
150
- <p><em><?php _e( 'This code will be included <strong>verbatim</strong> in <code>&lt;style></code> tags in the <code>&lt;head></code> tag of your page (or post).', 'scripts-n-styles' ) ?></em></p>
 
 
151
  </div>
152
 
153
- <div class="wp-tab-panel" id="SnS_classes_body-tab">
154
- <strong class="title"><?php _e( 'Classes', 'scripts-n-styles' ) ?></strong>
155
- <div id="sns-classes">
156
- <p>
157
- <label for="SnS_classes_body"><?php _e( '<strong>Body Classes</strong>:', 'scripts-n-styles' ) ?> </label>
158
- <input name="SnS_classes_body" id="SnS_classes_body" type="text" class="code" style="width: 99%;"
159
- value="<?php echo isset( $styles[ 'classes_body' ] ) ? esc_attr( $styles[ 'classes_body' ] ) : ''; ?>" />
160
- <small><?php _e( 'Standard:', 'scripts-n-styles' ) ?> <code><?php self::current_classes( 'body', $post->ID ); ?></code></small>
161
- </p>
162
- <p>
163
- <label for="SnS_classes_post"><strong>Post Classes</strong>: </label>
164
- <input name="SnS_classes_post" id="SnS_classes_post" type="text" class="code" style="width: 99%;"
165
- value="<?php echo isset( $styles[ 'classes_post' ] ) ? esc_attr( $styles[ 'classes_post' ] ) : ''; ?>" />
166
- <small><?php _e( 'Standard:', 'scripts-n-styles' ) ?> <code><?php self::current_classes( 'post', $post->ID ); ?></code></small>
167
- </p>
168
- <p><em><?php _e( 'These <strong>space separated</strong> class names will be added to the <code>body_class()</code> or <code>post_class()</code> function (provided your theme uses these functions).', 'scripts-n-styles' ) ?></em></p>
169
- </div>
170
-
171
- <?php
172
- /*
173
- * Note: Styles Dropdown section only makes sense when Javascript is enabled. (Otherwise, no TinyMCE.)
174
- */
175
- ?>
176
- <div id="mce-dropdown-names" style="display: none;">
177
- <h4><?php _e( 'The Styles Dropdown', 'scripts-n-styles' ) ?></h4>
178
- <div id="add-mce-dropdown-names">
179
- <p><?php _e( 'Add (or update) a class for the "Styles" drop-down:', 'scripts-n-styles' ) ?></p>
180
- <p class="sns-mce-title">
181
- <label for="SnS_classes_mce_title"><?php _e( 'Title:', 'scripts-n-styles' ) ?></label>
182
- <input name="SnS_classes_mce_title" id="SnS_classes_mce_title"
183
- value="" type="text" class="code" style="width: 80px;" />
184
- </p>
185
- <p class="sns-mce-type">
186
- <label for="SnS_classes_mce_type"><?php _e( 'Type:', 'scripts-n-styles' ) ?></label>
187
- <select name="SnS_classes_mce_type" id="SnS_classes_mce_type" style="width: 80px;">
188
- <option value="inline"><?php _ex( 'Inline', 'css type', 'scripts-n-styles' ) ?></option>
189
- <option value="block"><?php _ex( 'Block', 'css type', 'scripts-n-styles' ) ?></option>
190
- <option value="selector"><?php _ex( 'Selector:', 'css type', 'scripts-n-styles' ) ?></option>
191
- </select>
192
- </p>
193
- <p class="sns-mce-element">
194
- <label for="SnS_classes_mce_element"><?php _e( 'Element:', 'scripts-n-styles' ) ?></label>
195
- <input name="SnS_classes_mce_element" id="SnS_classes_mce_element"
196
- value="" type="text" class="code" style="width: 80px;" />
197
- </p>
198
- <p class="sns-mce-classes">
199
- <label for="SnS_classes_mce_classes"><?php _e( 'Classes:', 'scripts-n-styles' ) ?></label>
200
- <input name="SnS_classes_mce_classes" id="SnS_classes_mce_classes"
201
- value="" type="text" class="code" style="width: 80px;" />
202
- </p>
203
- <p class="sns-mce-wrapper" style="display: none;">
204
- <label for="SnS_classes_mce_wrapper"><?php _e( 'Wrapper:', 'scripts-n-styles' ) ?></label>
205
- <input name="SnS_classes_mce_wrapper" id="SnS_classes_mce_wrapper" type="checkbox" value="true" />
206
- </p>
207
- </div>
208
-
209
- <div id="delete-mce-dropdown-names" style="display: none;">
210
- <p id="instructions-mce-dropdown-names"><?php _e( 'Classes currently in the dropdown:', 'scripts-n-styles' ) ?></p>
211
- </div>
212
- </div>
213
  </div>
214
 
215
- <div class="wp-tab-panel" id="SnS_enqueue_scripts-tab">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  <strong class="title">Include Scripts</strong>
217
- <select name="SnS_enqueue_scripts[]" id="SnS_enqueue_scripts" size="5" multiple="multiple" style="height: auto; float: left; margin: 6px 10px 8px 0;">
218
- <?php
219
  if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) {
220
  foreach ( $registered_handles as $value ) { ?>
221
- <option value="<?php echo esc_attr( $value ) ?>"<?php foreach ( $scripts[ 'enqueue_scripts' ] as $handle ) selected( $handle, $value ); ?>><?php echo esc_html( $value ) ?></option>
222
  <?php }
223
  } else {
224
  foreach ( $registered_handles as $value ) { ?>
225
- <option value="<?php echo esc_attr( $value ) ?>"><?php echo esc_html( $value ) ?></option>
226
  <?php }
227
  } ?>
228
  </select>
229
  <?php if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) { ?>
230
- <p><?php _e( 'Currently Enqueued Scripts:', 'scripts-n-styles' ) ?>
231
- <?php foreach ( $scripts[ 'enqueue_scripts' ] as $handle ) echo '<code>' . esc_html( $handle ) . '</code> '; ?>
232
  </p>
233
  <?php } ?>
234
- <p><em><?php _e( 'The chosen scripts will be enqueued and placed before your codes if your code is dependant on certain scripts (like jQuery).', 'scripts-n-styles' ) ?></em></p>
235
- </div>
236
-
237
- <div class="wp-tab-panel" id="SnS_shortcodes-tab">
238
- <?php
239
- $meta_name = 'SnS_shortcodes';
240
- $SnS = get_post_meta( $post->ID, '_SnS', true );
241
- $shortcodes = isset( $SnS['shortcodes'] ) ? $SnS[ 'shortcodes' ] : array();
242
- ?>
243
- <strong class="title">Shortcodes</strong>
244
- <h4>Add New</h4>
245
- <label for="<?php echo $meta_name; ?>">Name: </label>
246
- <input id="<?php echo $meta_name; ?>" name="<?php echo $meta_name . '[new][name]'; ?>" type="text" />
247
- <textarea class="codemirror htmlmixed" name="<?php echo $meta_name . '[new][value]'; ?>" rows="5" cols="40" style="width: 98%;"></textarea>
248
- <?php if ( ! empty( $shortcodes ) ) { ?>
249
- <h4>Existing</h4>
250
- <?php
251
- foreach ( $shortcodes as $key => $value ) {
252
- ?>
253
- <label for="<?php echo $meta_name . '[existing][' . $key . ']'; ?>">[sns_shortcode name="<?php echo $key ?>"]</label>
254
- <textarea class="codemirror htmlmixed" name="<?php echo $meta_name . '[existing][' . $key . ']'; ?>" rows="5" cols="40" style="width: 98%;"><?php echo esc_textarea( $value ); ?></textarea>
255
- <?php
256
- }
257
- } ?>
258
  </div>
 
 
259
  <?php
260
  }
261
 
262
- function current_classes( $type, $post_id ) {
263
- if ( 'body' == $type ) {
264
- global $wp_query, $pagenow;
265
-
266
- if ( 'post-new.php' == $pagenow ) {
267
- echo join( ' ', get_body_class( '', $post_id ) );
268
- echo ' ' . __( '(plus others once saved.)', 'scripts-n-styles' );
269
- return;
270
- }
271
- // This returns more of what actually get used on the theme side.
272
- $save = $wp_query;
273
- $param = ( 'page' == get_post_type( $post_id ) ) ? 'page_id': 'p';
274
- $wp_query = new WP_Query( "$param=$post_id" );
275
- echo join( ' ', get_body_class( '', $post_id ) );
276
- $wp_query = $save;
277
-
278
- } else {
279
- echo join( ' ', get_post_class( '', $post_id ) );
280
- }
281
- }
282
-
283
- /**
284
  * Admin Action: 'admin_print_styles' Action added during 'add_meta_boxes' (which restricts output to Edit Screens).
285
  * Enqueues the CSS for admin styling of the Meta Box.
286
- */
287
  static function meta_box_styles() {
288
- $options = get_option( 'SnS_options' );
289
- $cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
290
- $cm_version = '2.4';
291
- wp_enqueue_style( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.css', Scripts_n_Styles::$file), array(), $cm_version );
292
- if ( in_array( $cm_theme, array( 'cobalt', 'eclipse', 'elegant', 'monokai', 'neat', 'night', 'rubyblue' ) ) )
293
- wp_enqueue_style( "codemirror-$cm_theme", plugins_url( "libraries/CodeMirror2/theme/$cm_theme.css", Scripts_n_Styles::$file), array( 'codemirror' ), $cm_version );
294
- wp_enqueue_style( 'sns-meta-box-styles', plugins_url( 'css/meta-box-styles.css', Scripts_n_Styles::$file), array( 'codemirror' ), Scripts_n_Styles::VERSION );
295
  }
296
 
297
- /**
298
  * Admin Action: 'admin_print_styles' Action added during 'add_meta_boxes' (which restricts output to Edit Screens).
299
  * Enqueues the JavaScript for the admin Meta Box.
300
- */
301
  static function meta_box_scripts() {
302
- $options = get_option( 'SnS_options' );
303
- $cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
304
- $cm_version = '2.4';
305
- $cm_dir = plugins_url( 'libraries/CodeMirror2/', Scripts_n_Styles::$file);
306
-
307
- wp_register_script( 'codemirror', $cm_dir . 'lib/codemirror.js', array(), $cm_version );
308
- wp_register_script( 'codemirror-css', $cm_dir . 'mode/css/css.js', array( 'codemirror' ), $cm_version );
309
- wp_register_script( 'codemirror-less', $cm_dir . 'mode/less/less.js', array( 'codemirror-css' ), $cm_version ); // load css first so less doesn't overwrite mime.
310
- wp_register_script( 'codemirror-javascript', $cm_dir . 'mode/javascript/javascript.js', array( 'codemirror' ), $cm_version );
311
- wp_register_script( 'codemirror-htmlmixed', $cm_dir . 'mode/htmlmixed/htmlmixed.js', array( 'codemirror-xml', 'codemirror-css', 'codemirror-javascript' ), $cm_version );
312
- wp_register_script( 'codemirror-clike', $cm_dir . 'mode/clike/clike.js', array( 'codemirror' ), $cm_version );
313
- wp_register_script( 'codemirror-xml', $cm_dir . 'mode/xml/xml.js', array( 'codemirror' ), $cm_version );
314
- wp_register_script( 'codemirror-php', $cm_dir . 'mode/php/php.js', array( 'codemirror-xml', 'codemirror-css', 'codemirror-javascript', 'codemirror-clike' ), $cm_version );
315
-
316
- wp_enqueue_script( 'sns-meta-box-scripts', plugins_url( 'js/meta-box-scripts.js', Scripts_n_Styles::$file), array( 'editor', 'jquery-ui-tabs', 'codemirror-less', 'codemirror-htmlmixed',
317
- //'codemirror-php',
318
- ), Scripts_n_Styles::VERSION, true );
319
-
320
- wp_localize_script( 'sns-meta-box-scripts', 'codemirror_options', array( 'theme' => $cm_theme ) );
321
  }
322
 
323
- /**
324
  * Admin Action: 'save_post'
325
  * Saves the values entered in the Meta Box when a post is saved (on the Edit Screen only, excluding autosaves) if the user has permission.
326
  * @param int $post_id ID value of the WordPress post.
327
- */
328
  static function save_post( $post_id ) {
329
- if ( ! isset( $_POST[ self::NONCE_NAME ] ) || ! wp_verify_nonce( $_POST[ self::NONCE_NAME ], Scripts_n_Styles::$file )
330
- || ! current_user_can( 'unfiltered_html' )
331
- || wp_is_post_revision( $post_id ) // is needed for get_post_meta compatibility.
332
- || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
333
- ) return;
334
 
335
- /*
336
- NOTE: There is no current_user_can( 'edit_post' ) check here, because as far as I
337
- can tell, in /wp-admin/post.php the calls edit_post(), write_post(), post_preview(),
338
- wp_untrash_post(), etc., the check is already done prior to the 'save_post' action,
339
- which is where this function is called. Other calls are from other pages so the
340
- NONCE covers those cases, and that leaves autosave, which is also checked here.
341
- */
342
-
343
- $SnS = get_post_meta( $post_id, '_SnS', true );
344
- $scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
345
- $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
346
-
347
- $scripts = self::maybe_set( $scripts, 'scripts_in_head' );
348
- $scripts = self::maybe_set( $scripts, 'scripts' );
349
- $scripts = self::maybe_set( $scripts, 'enqueue_scripts' );
350
- $styles = self::maybe_set( $styles, 'styles' );
351
- $styles = self::maybe_set( $styles, 'classes_body' );
352
- $styles = self::maybe_set( $styles, 'classes_post' );
353
-
354
- $shortcodes = array();
355
- $SnS_shortcodes = isset( $_REQUEST[ 'SnS_shortcodes' ] ) ? $_REQUEST[ 'SnS_shortcodes' ]: array();
356
-
357
- $existing_shortcodes = isset( $SnS_shortcodes[ 'existing' ] ) ? $SnS_shortcodes[ 'existing' ]: array();
358
- foreach ( $existing_shortcodes as $key => $value )
359
- if ( ! empty( $value ) )
360
- $shortcodes[ $key ] = $value;
361
-
362
- $new_shortcode = isset( $SnS_shortcodes[ 'new' ] ) ? $SnS_shortcodes[ 'new' ]: array();
363
- if ( ! empty( $new_shortcode[ 'value' ] ) ) {
364
- $key = ( empty( $new_shortcode[ 'name' ] ) ) ? count( $shortcodes ): $new_shortcode[ 'name' ];
365
- $shortcodes[ $key ] = $new_shortcode[ 'value' ];
366
- }
367
-
368
- // This one isn't posted, it's ajax only. Cleanup anyway.
369
- if ( isset( $styles[ 'classes_mce' ] ) && empty( $styles[ 'classes_mce' ] ) )
370
- unset( $styles[ 'classes_mce' ] );
371
-
372
- if ( empty( $scripts ) ) {
373
- if ( isset( $SnS['scripts'] ) )
374
- unset( $SnS['scripts'] );
375
- } else {
376
- $SnS['scripts'] = $scripts;
377
- }
378
-
379
- if ( empty( $styles ) ) {
380
- if ( isset( $SnS['styles'] ) )
381
- unset( $SnS['styles'] );
382
- } else {
383
- $SnS['styles'] = $styles;
384
- }
385
-
386
- if ( empty( $shortcodes ) ) {
387
- if ( isset( $SnS['shortcodes'] ) )
388
- unset( $SnS['shortcodes'] );
389
- } else {
390
- $SnS['shortcodes'] = $shortcodes;
391
- }
392
-
393
- if ( empty( $SnS ) )
394
- delete_post_meta( $post_id, '_SnS' );
395
- else
396
- update_post_meta( $post_id, '_SnS', $SnS );
397
- }
398
-
399
- /**
400
- * maybe_set()
401
- * Filters $o and Checks if the sent data $i is empty (intended to clear). If not, updates.
402
- */
403
- function maybe_set( $o, $i, $p = 'SnS_' ) {
404
- if ( empty( $_REQUEST[ $p . $i ] ) ) {
405
- if ( isset( $o[ $i ] ) ) unset( $o[ $i ] );
406
- } else {
407
- $o[ $i ] = $_REQUEST[ $p . $i ];
408
  }
409
- return $o;
410
  }
411
  }
412
  ?>
6
  * and JavaScript directly to individual Post, Pages or custom
7
  * post types.
8
  */
9
+
10
+ // $hook_suffix = 'tools_page_Scripts-n-Styles'; // kept here for reference
11
+ // $plugin_file = 'scripts-n-styles/scripts-n-styles.php'; // kept here for reference
12
 
13
  class SnS_Admin_Meta_Box
14
  {
15
+ /*
16
+ * Constants
17
+ */
18
  const NONCE_NAME = 'scripts_n_styles_noncename';
19
 
20
  static $post_types;
21
 
22
+ /**
23
+ * Initializing method. Checks if is_admin() and registers action hooks for admin if true. Sets filters and actions for Theme side functions.
24
+ * @static
25
+ */
26
  static function init() {
27
  add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
28
  add_action( 'save_post', array( __CLASS__, 'save_post' ) );
29
  }
30
 
31
+ /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  * Admin Action: 'add_meta_boxes'
33
  * Main Meta Box function. Checks restriction options and display options, calls add_meta_box() and adds actions for adding admin CSS and JavaScript.
34
+ */
35
  static function add_meta_boxes() {
36
  if ( current_user_can( 'unfiltered_html' ) ) {
37
+ self::$post_types = get_post_types( array('show_ui' => true, 'publicly_queryable' => true) );
38
+ foreach ( self::$post_types as $post_type ) {
39
+ add_meta_box( 'uFp_meta_box', 'Scripts n Styles', array( __CLASS__, 'meta_box' ), $post_type, 'normal', 'high' );
 
 
 
 
 
 
 
40
  }
41
+ add_filter( 'default_hidden_meta_boxes', array( __CLASS__, 'default_hidden_meta_boxes' ) );
42
+ add_action( "admin_print_styles", array( __CLASS__, 'meta_box_styles'));
43
+ add_action( "admin_print_scripts", array( __CLASS__, 'meta_box_scripts'));
44
+ add_filter( 'contextual_help', array( __CLASS__, 'contextual_help_filter' ), 10, 3 );
45
  }
46
  }
 
47
  static function default_hidden_meta_boxes( $hidden ) {
48
+ $hidden[] = 'uFp_meta_box';
49
+ return $hidden;
50
+ }
51
+
52
+ function contextual_help_filter( $text, $screen_id, $screen ) {
53
+ if ( in_array( $screen->post_type, self::$post_types ) )
54
+ $text .= '<p>In default (non MultiSite) WordPress installs, both <em>Administrators</em> and
55
+ <em>Editors</em> can access <em>Scripts-n-Styles</em> on individual edit screens.
56
+ Only <em>Administrators</em> can access this Options Page. In MultiSite WordPress installs, only <em>"Super Admin"</em> users can access either
57
+ <em>Scripts-n-Styles</em> on individual edit screens or this Options Page. If other plugins change capabilities (specifically "unfiltered_html"),
58
+ other users can be granted access.</p>';
59
+ return $text;
60
  }
61
+
62
 
63
+ /**
64
  * Admin Action: 'add_meta_boxes'
65
  * Outputs the Meta Box. Only called on callback from add_meta_box() during the add_meta_boxes action.
66
  * @param unknown_type WordPress Post object.
67
+ */
68
+ static function meta_box( $post ) {
69
  $registered_handles = Scripts_n_Styles::get_wp_registered();
70
+ $styles = get_post_meta( $post->ID, 'uFp_styles', true );
71
+ $scripts = get_post_meta( $post->ID, 'uFp_scripts', true );
 
 
 
 
 
72
  ?>
73
+ <div class="tabs-horizontal">
74
+ <ul class="wp-tab-bar" style="display: none;">
75
+ <li><a href="#uFp_scripts-tab">Scripts (bottom)</a></li>
76
+ <li><a href="#uFp_styles-tab">Styles</a></li>
77
+ <li><a href="#uFp_scripts_in_head-tab">Scripts (top)</a></li>
78
+ <li><a href="#uFp_classes_body-tab">Classes</a></li>
79
+ <?php /** / ?>
80
+ <li><a href="#uFp_enqueue_scripts-tab">Include Scripts</a></li>
81
+ <?php /**/ ?>
82
  </ul>
83
 
84
+ <div id="uFp_scripts-tab">
85
+ <input type="hidden" name="<?php echo self::NONCE_NAME ?>" id="<?php echo self::NONCE_NAME ?>" value="<?php echo wp_create_nonce( Scripts_n_Styles::$file ) ?>" />
86
+ <p>
87
+ <label for="uFp_scripts" class="title"><strong>Scripts</strong>: </label>
88
+ <textarea class="code js" name="uFp_scripts" id="uFp_scripts" rows="5" cols="40" style="width: 98%;"><?php echo isset( $scripts[ 'scripts' ] ) ? $scripts[ 'scripts' ] : ''; ?></textarea>
89
+ <em>This code will be included <strong>verbatim</strong> in <code>&lt;script></code> tags at the end of your page's (or post's) <code>&lt;body></code> tag.</em>
90
+ </p>
 
91
  </div>
92
 
93
+ <div id="uFp_styles-tab">
94
+ <p>
95
+ <label for="uFp_styles" class="title"><strong>Styles</strong>: </label>
96
+ <textarea class="code css" name="uFp_styles" id="uFp_styles" rows="5" cols="40" style="width: 98%;"><?php echo isset( $styles[ 'styles' ] ) ? $styles[ 'styles' ] : ''; ?></textarea>
97
+ <em>This code will be included <strong>verbatim</strong> in <code>&lt;style></code> tags in the <code>&lt;head></code> tag of your page (or post).</em>
98
+ </p>
99
  </div>
100
 
101
+ <div id="uFp_scripts_in_head-tab">
102
+ <p>
103
+ <label for="uFp_scripts_in_head" class="title"><strong>Scripts</strong> (for the <code>head</code> element): </label>
104
+ <textarea class="codemirror js" name="uFp_scripts_in_head" id="uFp_scripts_in_head" rows="5" cols="40" style="width: 98%;"><?php echo isset( $scripts[ 'scripts_in_head' ] ) ? $scripts[ 'scripts_in_head' ] : ''; ?></textarea>
105
+ <em>This code will be included <strong>verbatim</strong> in <code>&lt;script></code> tags at the end of your page's (or post's) <code>&lt;head></code> tag.</em>
106
+ </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  </div>
108
 
109
+ <div id="uFp_classes_body-tab">
110
+ <strong class="title">Classes</strong>
111
+ <p>
112
+ <label for="uFp_classes_body">body classes: </label>
113
+ <input style="width: 99%;" name="uFp_classes_body" id="uFp_classes_body" value="<?php echo isset( $styles[ 'classes_body' ] ) ? $styles[ 'classes_body' ] : ''; ?>" type="text" class="code" />
114
+ </p>
115
+ <p>
116
+ <label for="uFp_classes_post">post classes: </label>
117
+ <input style="width: 99%;" name="uFp_classes_post" id="uFp_classes_post" value="<?php echo isset( $styles[ 'classes_post' ] ) ? $styles[ 'classes_post' ] : ''; ?>" type="text" class="code" />
118
+ </p>
119
+ <p><em>These <strong>space separated</strong> class names will be pushed into the <code>body_class()</code> or <code>post_class()</code> function (provided your theme uses these functions).</em></p>
120
+ </div>
121
+
122
+ <?php /** / ?>
123
+ <div id="uFp_enqueue_scripts-tab">
124
  <strong class="title">Include Scripts</strong>
125
+ <select name="uFp_enqueue_scripts[]" id="uFp_enqueue_scripts" size="5" multiple="multiple" style="height: auto; float: left; margin: 6px 10px 8px 0;">
126
+ <?php // This is a bit intense here...
127
  if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) {
128
  foreach ( $registered_handles as $value ) { ?>
129
+ <option value="<?php echo $value ?>"<?php foreach ( $scripts[ 'enqueue_scripts' ] as $handle ) selected( $handle, $value ); ?>><?php echo $value ?></option>
130
  <?php }
131
  } else {
132
  foreach ( $registered_handles as $value ) { ?>
133
+ <option value="<?php echo $value ?>"><?php echo $value ?></option>
134
  <?php }
135
  } ?>
136
  </select>
137
  <?php if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) { ?>
138
+ <p>Currently Enqueued Scripts:
139
+ <?php foreach ( $scripts[ 'enqueue_scripts' ] as $handle ) echo '<code>' . $handle . '</code> '; ?>
140
  </p>
141
  <?php } ?>
142
+ <p><em>The chosen scripts will be enqueued and placed before your codes if your code is dependant on certain scripts (like jQuery).</em></p>
143
+ <p>NOTE: Not all Scripts in the list are appropriate for use in themes. This is merely a generated list of all currently available registered scripts. It's possible some scripts could be registered only on the "front end" and therefore not listed here.</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  </div>
145
+ <?php /**/ ?>
146
+ </div>
147
  <?php
148
  }
149
 
150
+ /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  * Admin Action: 'admin_print_styles' Action added during 'add_meta_boxes' (which restricts output to Edit Screens).
152
  * Enqueues the CSS for admin styling of the Meta Box.
153
+ */
154
  static function meta_box_styles() {
155
+ wp_enqueue_style( 'sns-meta-box-styles', plugins_url( 'css/meta-box-styles.css', Scripts_n_Styles::$file), array( 'codemirror-default' ), SnS_Admin::VERSION );
156
+ wp_enqueue_style( 'codemirror', plugins_url( 'libraries/codemirror/lib/codemirror.css', Scripts_n_Styles::$file), array(), '2.1' );
157
+ wp_enqueue_style( 'codemirror-default', plugins_url( 'libraries/codemirror/theme/default.css', Scripts_n_Styles::$file), array( 'codemirror' ), '2.1' );
 
 
 
 
158
  }
159
 
160
+ /**
161
  * Admin Action: 'admin_print_styles' Action added during 'add_meta_boxes' (which restricts output to Edit Screens).
162
  * Enqueues the JavaScript for the admin Meta Box.
163
+ */
164
  static function meta_box_scripts() {
165
+ wp_enqueue_script( 'sns-meta-box-scripts', plugins_url( 'js/meta-box-scripts.js', Scripts_n_Styles::$file), array( 'jquery-ui-tabs', 'codemirror-css', 'codemirror-javascript' ), SnS_Admin::VERSION, true );
166
+ wp_enqueue_script( 'codemirror', plugins_url( 'libraries/codemirror/lib/codemirror.js', Scripts_n_Styles::$file), array(), '2.1' );
167
+ wp_enqueue_script( 'codemirror-css', plugins_url( 'libraries/codemirror/mode/css.js', Scripts_n_Styles::$file), array( 'codemirror' ), '2.1' );
168
+ wp_enqueue_script( 'codemirror-javascript', plugins_url( 'libraries/codemirror/mode/javascript.js', Scripts_n_Styles::$file), array( 'codemirror' ), '2.1' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  }
170
 
171
+ /**
172
  * Admin Action: 'save_post'
173
  * Saves the values entered in the Meta Box when a post is saved (on the Edit Screen only, excluding autosaves) if the user has permission.
174
  * @param int $post_id ID value of the WordPress post.
175
+ */
176
  static function save_post( $post_id ) {
177
+ if ( isset( $_POST[ self::NONCE_NAME ] ) && wp_verify_nonce( $_POST[ self::NONCE_NAME ], Scripts_n_Styles::$file )
178
+ && current_user_can( 'unfiltered_html' )
179
+ && ! ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ) {
 
 
180
 
181
+ /*
182
+ NOTE: There is no current_user_can( 'edit_post' ) check here, because as far as I
183
+ can tell, in /wp-admin/post.php the calls edit_post(), write_post(), post_preview(),
184
+ wp_untrash_post(), etc., the check is already done prior to the 'save_post' action,
185
+ which is where this function is called. Other calls are from other pages so the
186
+ NONCE covers those cases, and that leaves autosave, which is also checked here.
187
+ */
188
+
189
+ $scripts = array();
190
+ $styles = array();
191
+
192
+ if ( ! empty( $_POST[ 'uFp_scripts' ] ) )
193
+ $scripts[ 'scripts' ] = $_POST[ 'uFp_scripts' ];
194
+
195
+ if ( ! empty( $_POST[ 'uFp_styles' ] ) )
196
+ $styles[ 'styles' ] = $_POST[ 'uFp_styles' ];
197
+
198
+ if ( ! empty( $_POST[ 'uFp_scripts_in_head' ] ) )
199
+ $scripts[ 'scripts_in_head' ] = $_POST[ 'uFp_scripts_in_head' ];
200
+
201
+ if ( ! empty( $_POST[ 'uFp_classes_body' ] ) )
202
+ $styles[ 'classes_body' ] = $_POST[ 'uFp_classes_body' ];
203
+
204
+ if ( ! empty( $_POST[ 'uFp_classes_post' ] ) )
205
+ $styles[ 'classes_post' ] = $_POST[ 'uFp_classes_post' ];
206
+
207
+ if ( ! empty( $_POST[ 'uFp_enqueue_scripts' ] ) )
208
+ $scripts[ 'enqueue_scripts' ] = $_POST[ 'uFp_enqueue_scripts' ];
209
+
210
+ update_post_meta( $post_id, 'uFp_scripts', $scripts );
211
+ update_post_meta( $post_id, 'uFp_styles', $styles );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  }
 
213
  }
214
  }
215
  ?>
includes/class.SnS_Form.php DELETED
@@ -1,169 +0,0 @@
1
- <?php
2
- /**
3
- * SnS_Global_Page
4
- *
5
- * Allows WordPress admin users the ability to add custom CSS
6
- * and JavaScript directly to individual Post, Pages or custom
7
- * post types.
8
- */
9
-
10
- class SnS_Form
11
- {
12
- /**
13
- * Settings Page
14
- * Outputs a textarea for setting 'scripts_in_head'.
15
- */
16
- function textarea( $args ) {
17
- extract( $args );
18
- $options = get_option( $setting );
19
- $value = isset( $options[ $label_for ] ) ? $options[ $label_for ] : '';
20
- $output = '<textarea';
21
- $output .= ( $style ) ? ' style="' . $style . '"': '';
22
- $output .= ( $class ) ? ' class="' . $class . '"': '';
23
- $output .= ( $rows ) ? ' rows="' . $rows . '"': '';
24
- $output .= ( $cols ) ? ' cols="' . $cols . '"': '';
25
- $output .= ' name="' . $setting . '[' . $label_for . ']"';
26
- $output .= ' id="' . $label_for . '">';
27
- $output .= esc_textarea( $value ) . '</textarea>';
28
- if ( $description ) {
29
- $output .= $description;
30
- }
31
- echo $output;
32
- }
33
-
34
- function radio( $args ) {
35
- extract( $args );
36
- $options = get_option( $setting );
37
- $default = isset( $default ) ? $default : '';
38
- $value = isset( $options[ $label_for ] ) ? $options[ $label_for ] : $default;
39
- $output = '<fieldset>';
40
- if ( $legend ) {
41
- $output .= '<legend class="screen-reader-text"><span>';
42
- $output .= $legend;
43
- $output .= '</span></legend>';
44
- }
45
- $output .= '<p>';
46
- foreach ( $choices as $choice ) {
47
- $output .= '<label>';
48
- $output .= '<input type="radio"';
49
- $output .= checked( $value, $choice, false );
50
- $output .= ' value="' . $choice . '" name="' . $setting . '[' . $label_for . ']"> ' . $choice;
51
- $output .= '</label>';
52
- $output .= ( ! isset( $layout ) || 'horizontal' != $layout ) ? '<br>' : ' &nbsp; ';
53
- }
54
- $output .= '</p></fieldset>';
55
- if ( $description ) {
56
- $output .= $description;
57
- }
58
- echo $output;
59
- }
60
-
61
- /**
62
- * Settings Page
63
- * Outputs a select element for selecting options to set scripts for including.
64
- */
65
- function select( $args ) {
66
- extract( $args );
67
- $options = get_option( $setting );
68
- $selected = isset( $options[ $label_for ] ) ? $options[ $label_for ] : array();
69
-
70
- $output = '<select';
71
- $output .= ' id="' . $label_for . '"';
72
- $output .= ' name="' . $setting . '[' . $label_for . ']';
73
- if ( isset( $multiple ) && $multiple )
74
- $output .= '[]" multiple="multiple"';
75
- else
76
- $output .= '"';
77
- $output .= ( $size ) ? ' size="' . $size . '"': '';
78
- $output .= ( $style ) ? ' style="' . $style . '"': '';
79
- $output .= '>';
80
- foreach ( $choices as $choice ) {
81
- $output .= '<option value="' . $choice . '"';
82
- if ( isset( $multiple ) && $multiple )
83
- foreach ( $selected as $handle ) $output .= selected( $handle, $choice, false );
84
- else
85
- $output .= selected( $selected, $choice, false );
86
- $output .= '>' . $choice . '</option> ';
87
- }
88
- $output .= '</select>';
89
- if ( ! empty( $show_current ) && ! empty( $selected ) ) {
90
- $output .= '<p>' . $show_current;
91
- foreach ( $selected as $handle ) $output .= '<code>' . $handle . '</code> ';
92
- $output .= '</p>';
93
- }
94
- echo $output;
95
- }
96
-
97
- /**
98
- * Settings Page
99
- * Outputs the Admin Page and calls the Settings registered with the Settings API.
100
- */
101
- function take_action() {
102
- global $action, $option_page, $page, $new_whitelist_options;
103
-
104
- if ( ! current_user_can( 'manage_options' ) || ! current_user_can( 'unfiltered_html' ) || ( is_multisite() && ! is_super_admin() ) )
105
- wp_die( __( 'Cheatin&#8217; uh?' ) );
106
-
107
- if ( isset( $_REQUEST[ 'message' ] ) && $_REQUEST[ 'message' ] )
108
- add_settings_error( $page, 'settings_updated', __( 'Settings saved.' ), 'updated' );
109
-
110
- if ( ! isset( $_REQUEST[ 'action' ], $_REQUEST[ 'option_page' ], $_REQUEST[ 'page' ] ) )
111
- return;
112
-
113
- wp_reset_vars( array( 'action', 'option_page', 'page' ) );
114
-
115
- check_admin_referer( $option_page . '-options' );
116
-
117
- if ( ! isset( $new_whitelist_options[ $option_page ] ) )
118
- return;
119
-
120
- $options = $new_whitelist_options[ $option_page ];
121
- foreach ( (array) $options as $option ) {
122
- $old = get_option( $option );
123
- $option = trim( $option );
124
- $value = null;
125
- if ( isset($_POST[ $option ]) )
126
- $value = $_POST[ $option ];
127
- if ( !is_array( $value ) )
128
- $value = trim( $value );
129
-
130
- $value = array_merge( $old, stripslashes_deep( $value ) );
131
- update_option( $option, $value );
132
- }
133
-
134
- if ( ! count( get_settings_errors() ) )
135
- add_settings_error( $page, 'settings_updated', __( 'Settings saved.' ), 'updated' );
136
-
137
- if ( isset( $_POST[ $option ][ 'menu_position' ] ) && ( $value[ 'menu_position' ] != SnS_Admin::$parent_slug ) ) {
138
- switch( $value[ 'menu_position' ] ) {
139
- case 'menu':
140
- case 'object':
141
- case 'utility':
142
- wp_redirect( add_query_arg( 'message', 1, admin_url( 'admin.php?page=sns_settings' ) ) );
143
- break;
144
- default:
145
- wp_redirect( add_query_arg( 'message', 1, admin_url( $value[ 'menu_position' ].'?page=sns_settings' ) ) );
146
- break;
147
- }
148
- }
149
- return;
150
- }
151
-
152
- /**
153
- * Settings Page
154
- * Outputs the Admin Page and calls the Settings registered with the Settings API in init_options_page().
155
- */
156
- function page() {
157
- ?>
158
- <div class="wrap">
159
- <?php SnS_Admin::nav(); ?>
160
- <form action="" method="post" autocomplete="off">
161
- <?php settings_fields( SnS_Admin::OPTION_GROUP ); ?>
162
- <?php do_settings_sections( SnS_Admin::MENU_SLUG ); ?>
163
- <?php submit_button(); ?>
164
- </form>
165
- </div>
166
- <?php
167
- }
168
- }
169
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class.SnS_Global_Page.php DELETED
@@ -1,164 +0,0 @@
1
- <?php
2
- /**
3
- * SnS_Global_Page
4
- *
5
- * Allows WordPress admin users the ability to add custom CSS
6
- * and JavaScript directly to individual Post, Pages or custom
7
- * post types.
8
- */
9
-
10
- class SnS_Global_Page
11
- {
12
- /**
13
- * Initializing method.
14
- * @static
15
- */
16
- function init() {
17
- if ( SnS_Admin::$parent_slug == SnS_Admin::MENU_SLUG ) $menu_title = __( 'Global', 'scripts-n-styles' );
18
- else $menu_title = __( 'Scripts n Styles', 'scripts-n-styles' );
19
-
20
- $hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), $menu_title, 'unfiltered_html', SnS_Admin::MENU_SLUG, array( 'SnS_Form', 'page' ) );
21
-
22
- add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
23
- add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
24
- add_action( "load-$hook_suffix", array( 'SnS_Form', 'take_action'), 49 );
25
- add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'admin_enqueue_scripts' ) );
26
- }
27
-
28
- function admin_enqueue_scripts() {
29
- $options = get_option( 'SnS_options' );
30
- $cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
31
- $localize = array( 'theme' => $cm_theme );
32
- $cm_version = '2.4';
33
-
34
- wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array( 'codemirror' ), Scripts_n_Styles::VERSION );
35
- wp_enqueue_style( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.css', Scripts_n_Styles::$file), array(), $cm_version );
36
- if ( in_array( $cm_theme, array( 'cobalt', 'eclipse', 'elegant', 'lesser-dark', 'monokai', 'neat', 'night', 'rubyblue', 'xq-dark' ) ) )
37
- wp_enqueue_style( "codemirror-$cm_theme", plugins_url( "libraries/CodeMirror2/theme/$cm_theme.css", Scripts_n_Styles::$file), array( 'codemirror' ), $cm_version );
38
-
39
- wp_enqueue_script( 'sns-global-page-scripts', plugins_url('js/global-page.js', Scripts_n_Styles::$file), array( 'jquery', 'codemirror-less', 'codemirror-css', 'codemirror-javascript', 'less.js' ), Scripts_n_Styles::VERSION, true );
40
- wp_localize_script( 'sns-global-page-scripts', '_SnS_options', $localize );
41
-
42
- wp_enqueue_script( 'less.js', plugins_url( 'libraries/less/dist/less-1.3.0.min.js', Scripts_n_Styles::$file), array(), '1.3.0' );
43
- wp_enqueue_script( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.js', Scripts_n_Styles::$file), array(), $cm_version );
44
- wp_enqueue_script( 'codemirror-css', plugins_url( 'libraries/CodeMirror2/mode/css/css.js', Scripts_n_Styles::$file), array( 'codemirror' ), $cm_version );
45
- wp_enqueue_script( 'codemirror-javascript', plugins_url( 'libraries/CodeMirror2/mode/javascript/javascript.js', Scripts_n_Styles::$file), array( 'codemirror' ), $cm_version );
46
- wp_enqueue_script( 'codemirror-less', plugins_url( 'libraries/CodeMirror2/mode/less/less.js', Scripts_n_Styles::$file), array( 'codemirror-css' ), $cm_version ); // load css first so less doesn't overwrite mime.
47
- wp_enqueue_script( 'codemirror-htmlmixed', plugins_url( 'libraries/CodeMirror2/mode/php/php.js', Scripts_n_Styles::$file), array( 'codemirror-xml', 'codemirror-css', 'codemirror-javascript' ), $cm_version );
48
- wp_enqueue_script( 'codemirror-php', plugins_url( 'libraries/CodeMirror2/mode/php/php.js', Scripts_n_Styles::$file), array( 'codemirror-xml', 'codemirror-css', 'codemirror-javascript', 'codemirror-clike' ), $cm_version );
49
- }
50
- /**
51
- * Settings Page
52
- * Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
53
- */
54
- function admin_load() {
55
-
56
- register_setting(
57
- SnS_Admin::OPTION_GROUP,
58
- 'SnS_options' );
59
-
60
- add_settings_section(
61
- 'global',
62
- __( 'Global Scripts n Styles', 'scripts-n-styles' ),
63
- array( __CLASS__, 'global_section' ),
64
- SnS_Admin::MENU_SLUG );
65
-
66
- add_settings_field(
67
- 'less',
68
- __( '<strong>LESS:</strong> ', 'scripts-n-styles' ),
69
- array( __CLASS__, 'less_fields' ),
70
- SnS_Admin::MENU_SLUG,
71
- 'global',
72
- array( 'label_for' => 'less' ) );
73
- add_settings_field(
74
- 'styles',
75
- __( '<strong>Styles:</strong> ', 'scripts-n-styles' ),
76
- array( 'SnS_Form', 'textarea' ),
77
- SnS_Admin::MENU_SLUG,
78
- 'global',
79
- array(
80
- 'label_for' => 'styles',
81
- 'setting' => 'SnS_options',
82
- 'class' => 'code css',
83
- 'rows' => 5,
84
- 'cols' => 40,
85
- 'style' => 'min-width: 500px; width:97%;',
86
- 'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The "Styles" will be included <strong>verbatim</strong> in <code>&lt;style></code> tags in the <code>&lt;head></code> element of your html.</span>', 'scripts-n-styles' )
87
- ) );
88
- add_settings_field(
89
- 'scripts_in_head',
90
- __( '<strong>Scripts</strong><br />(for the <code>head</code> element): ', 'scripts-n-styles' ),
91
- array( 'SnS_Form', 'textarea' ),
92
- SnS_Admin::MENU_SLUG,
93
- 'global',
94
- array(
95
- 'label_for' => 'scripts_in_head',
96
- 'setting' => 'SnS_options',
97
- 'class' => 'code js',
98
- 'rows' => 5,
99
- 'cols' => 40,
100
- 'style' => 'min-width: 500px; width:97%;',
101
- 'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts (in head)" will be included <strong>verbatim</strong> in <code>&lt;script></code> tags in the <code>&lt;head></code> element of your html.</span>', 'scripts-n-styles' )
102
- ) );
103
- add_settings_field(
104
- 'scripts',
105
- __( '<strong>Scripts:</strong> ', 'scripts-n-styles' ),
106
- array( 'SnS_Form', 'textarea' ),
107
- SnS_Admin::MENU_SLUG,
108
- 'global',
109
- array(
110
- 'label_for' => 'scripts',
111
- 'setting' => 'SnS_options',
112
- 'class' => 'code js',
113
- 'rows' => 5,
114
- 'cols' => 40,
115
- 'style' => 'min-width: 500px; width:97%;',
116
- 'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts" will be included <strong>verbatim</strong> in <code>&lt;script></code> tags at the bottom of the <code>&lt;body></code> element of your html.</span>', 'scripts-n-styles' )
117
- ) );
118
- add_settings_field(
119
- 'enqueue_scripts',
120
- __( '<strong>Enqueue Scripts</strong>: ', 'scripts-n-styles' ),
121
- array( 'SnS_Form', 'select' ),
122
- SnS_Admin::MENU_SLUG,
123
- 'global',
124
- array(
125
- 'label_for' => 'enqueue_scripts',
126
- 'setting' => 'SnS_options',
127
- 'choices' => Scripts_n_Styles::get_wp_registered(),
128
- 'size' => 5,
129
- 'style' => 'height: auto;',
130
- 'multiple' => true,
131
- 'show_current' => __( 'Currently Enqueued Scripts: ', 'scripts-n-styles' )
132
- ) );
133
- }
134
-
135
- function less_fields() {
136
- $options = get_option( 'SnS_options' );
137
- $less = isset( $options[ 'less' ] ) ? $options[ 'less' ] : '';
138
- $compiled = isset( $options[ 'compiled' ] ) ? $options[ 'compiled' ] : '';
139
- ?>
140
- <div style="overflow: hidden;">
141
- <div style="width: 49%; float: left; overflow: hidden; margin-right: 2%;">
142
- <textarea id="less" name="SnS_options[less]" style="min-width: 250px; width:47%; float: left" class="code less" rows="5" cols="40"><?php echo esc_textarea( $less ) ?></textarea>
143
- </div>
144
- <div style="width: 49%; float: left; overflow: hidden;">
145
- <textarea id="compiled" name="SnS_options[compiled]" style="min-width: 250px; width:47%;" class="code css" rows="5" cols="40"><?php echo esc_textarea( $compiled ) ?></textarea>
146
- <div id="compiled_error" style="display: none" class="error settings-error below-h2"></div>
147
- </div>
148
- </div>
149
- <?php
150
- }
151
-
152
- /**
153
- * Settings Page
154
- * Outputs Description text for the Global Section.
155
- */
156
- function global_section() {
157
- ?>
158
- <div style="max-width: 55em;">
159
- <p><?php _e( 'Code entered here will be included in <em>every page (and post) of your site</em>, including the homepage and archives. The code will appear <strong>before</strong> Scripts and Styles registered individually.', 'scripts-n-styles' )?></p>
160
- </div>
161
- <?php
162
- }
163
- }
164
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class.SnS_List_Usage.php DELETED
@@ -1,176 +0,0 @@
1
- <?php
2
- if ( ! class_exists( 'WP_List_Table' ) ) require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
3
-
4
- class SnS_List_Usage extends WP_List_Table {
5
-
6
- function ajax_user_can() {
7
- return current_user_can( 'unfiltered_html' ) && current_user_can( 'manage_options' );
8
- }
9
-
10
- function column_default( $post, $column_name ) {
11
- $return = '';
12
- switch( $column_name ){
13
- case 'status':
14
- return $post->post_status;
15
- case 'ID':
16
- case 'post_type':
17
- return $post->$column_name;
18
- case 'script_data':
19
- if ( isset( $post->sns_scripts[ 'scripts_in_head' ] ) ) {
20
- $return .= '<div>' . __( 'Scripts (head)', 'scripts-n-styles' ) . '</div>';
21
- }
22
- if ( isset( $post->sns_scripts[ 'scripts' ] ) ) {
23
- $return .= '<div>' . __( 'Scripts', 'scripts-n-styles' ) . '</div>';
24
- }
25
- if ( isset( $post->sns_scripts[ 'enqueue_scripts' ] ) ) {
26
- $return .= '<div>' . __( 'Enqueued Scripts', 'scripts-n-styles' ) . '</div>';
27
- }
28
- return $return;
29
- case 'style_data':
30
- if ( isset( $post->sns_styles[ 'classes_mce' ] ) ) {
31
- $return .= '<div>' . __( 'TinyMCE Formats', 'scripts-n-styles' ) . '</div>';
32
- }
33
- if ( isset( $post->sns_styles[ 'styles' ] ) ) {
34
- $return .= '<div>' . __( 'Styles', 'scripts-n-styles' ) . '</div>';
35
- }
36
- if ( isset( $post->sns_styles[ 'classes_post' ] ) ) {
37
- $return .= '<div>' . __( 'Post Classes', 'scripts-n-styles' ) . '</div>';
38
- }
39
- if ( isset( $post->sns_styles[ 'classes_body' ] ) ) {
40
- $return .= '<div>' . __( 'Body Classes', 'scripts-n-styles' ) . '</div>';
41
- }
42
- return $return;
43
- default:
44
- return print_r( $post, true );
45
- }
46
- }
47
-
48
- function column_title( $post ) {
49
- $edit_link = esc_url( get_edit_post_link( $post->ID ) );
50
- $edit_title = esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $post->post_title ) );
51
-
52
- $actions = array(
53
- 'edit' => sprintf( '<a title="%s" href="%s">%s</a>', $edit_title, $edit_link, __( 'Edit' ) ),
54
- );
55
-
56
- $return = '<strong>';
57
- if ( $this->ajax_user_can() && $post->post_status != 'trash' ) {
58
- $return .= '<a class="row-title"';
59
- $return .= ' href="'. $edit_link .'"';
60
- $return .= ' title="'. $edit_title .'">';
61
- $return .= $post->post_title;
62
- $return .= '</a>';
63
- } else {
64
- $return .= $post->post_title;
65
- }
66
- $this->_post_states( $post );
67
- $return .= '</strong>';
68
- $return .= $this->row_actions( $actions );
69
-
70
- return $return;
71
- }
72
-
73
- function get_columns() {
74
- $columns = array(
75
- 'title' => __( 'Title' ),
76
- 'ID' => __( 'ID' ),
77
- 'status' => __( 'Status' ),
78
- 'post_type' => __( 'Post Type', 'scripts-n-styles' ),
79
- 'script_data' => __( 'Script Data', 'scripts-n-styles' ),
80
- 'style_data' => __( 'Style Data', 'scripts-n-styles' )
81
- );
82
-
83
- return $columns;
84
- }
85
-
86
- function prepare_items() {
87
- $screen_id = get_current_screen()->id;
88
- $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$screen_id}_per_page" ) );
89
-
90
- $this->_column_headers = array(
91
- $this->get_columns(),
92
- array(),
93
- $this->get_sortable_columns()
94
- );
95
-
96
- /**
97
- * Get Relavent Posts.
98
- */
99
- $posts = get_posts( array(
100
- 'numberposts' => -1,
101
- 'post_type' => 'any',
102
- 'post_status' => 'any',
103
- 'orderby' => 'ID',
104
- 'order' => 'ASC',
105
- 'meta_key' => '_SnS'
106
- ) );
107
-
108
- $items = $this->_add_meta_data( $posts );
109
-
110
- $total_items = count( $items );
111
-
112
- /**
113
- * Reduce items to current page's posts.
114
- */
115
- $this->items = array_slice(
116
- $items,
117
- ( ( $this->get_pagenum() - 1 ) * $per_page ),
118
- $per_page
119
- );
120
-
121
- $this->set_pagination_args( compact( 'total_items', 'per_page' ) );
122
- }
123
-
124
- function _post_states( $post ) {
125
- $post_states = array();
126
- $return = '';
127
- if ( isset($_GET[ 'post_status' ]) )
128
- $post_status = $_GET[ 'post_status' ];
129
- else
130
- $post_status = '';
131
-
132
- if ( ! empty( $post->post_password ) )
133
- $post_states[ 'protected' ] = __( 'Password protected' );
134
- if ( 'private' == $post->post_status && 'private' != $post_status )
135
- $post_states[ 'private' ] = __( 'Private' );
136
- if ( 'draft' == $post->post_status && 'draft' != $post_status )
137
- $post_states[ 'draft' ] = __( 'Draft' );
138
- if ( 'pending' == $post->post_status && 'pending' != $post_status )
139
- /* translators: post state */
140
- $post_states[ 'pending' ] = _x( 'Pending', 'post state' );
141
- if ( is_sticky($post->ID) )
142
- $post_states[ 'sticky' ] = __( 'Sticky' );
143
-
144
- $post_states = apply_filters( 'display_post_states', $post_states );
145
-
146
- if ( ! empty( $post_states ) ) {
147
- $state_count = count( $post_states );
148
- $i = 0;
149
- $return .= ' - ';
150
- foreach ( $post_states as $state ) {
151
- ++$i;
152
- ( $i == $state_count ) ? $sep = '' : $sep = ', ';
153
- $return .= "<span class='post-state'>$state$sep</span>";
154
- }
155
- }
156
-
157
- if ( get_post_format( $post->ID ) )
158
- $return .= ' - <span class="post-state-format">' . get_post_format_string( get_post_format( $post->ID ) ) . '</span>';
159
-
160
- return $return;
161
- }
162
-
163
- function _add_meta_data( $posts ) {
164
- foreach( $posts as $post) {
165
- $SnS = get_post_meta( $post->ID, '_SnS', true );
166
- $styles = isset( $SnS[ 'styles' ] ) ? $SnS[ 'styles' ]: array();
167
- $scripts = isset( $SnS[ 'scripts' ] ) ? $SnS[ 'scripts' ]: array();
168
- if ( ! empty( $styles ) )
169
- $post->sns_styles = $styles;
170
- if ( ! empty( $scripts ) )
171
- $post->sns_scripts = $scripts;
172
- }
173
- return $posts;
174
- }
175
- }
176
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class.SnS_Settings_Page.php CHANGED
@@ -6,163 +6,274 @@
6
  * and JavaScript directly to individual Post, Pages or custom
7
  * post types.
8
  */
 
 
 
9
 
10
  class SnS_Settings_Page
11
  {
12
- /**
13
- * Constants
14
- */
15
- const MENU_SLUG = 'sns_settings';
16
 
17
- /**
18
  * Initializing method.
19
- * @static
20
- */
21
- function init() {
22
- $hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Settings' ), 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
23
-
24
- add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
25
- add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
26
- add_action( "load-$hook_suffix", array( 'SnS_Form', 'take_action' ), 49 );
27
- add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'admin_enqueue_scripts' ) );
28
-
29
- // Make the page into a tab.
30
- if ( SnS_Admin::MENU_SLUG != SnS_Admin::$parent_slug ) {
31
- remove_submenu_page( SnS_Admin::$parent_slug, self::MENU_SLUG );
32
- add_filter( 'parent_file', array( __CLASS__, 'parent_file') );
 
 
 
 
 
 
33
  }
34
  }
35
 
36
- function admin_enqueue_scripts() {
37
- $options = get_option( 'SnS_options' );
38
- $cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : '';
39
- $cm_version = '2.4';
40
- wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array( 'codemirror' ), Scripts_n_Styles::VERSION );
41
- wp_enqueue_style( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.css', Scripts_n_Styles::$file), array(), $cm_version );
42
-
43
- foreach ( array( 'cobalt', 'eclipse', 'elegant', 'lesser-dark', 'monokai', 'neat', 'night', 'rubyblue', 'xq-dark' ) as $theme )
44
- wp_enqueue_style( "codemirror-$theme", plugins_url( "libraries/CodeMirror2/theme/$theme.css", Scripts_n_Styles::$file), array( 'codemirror' ), $cm_version );
45
-
46
- wp_enqueue_script( 'sns-settings-page-scripts', plugins_url('js/settings-page.js', Scripts_n_Styles::$file), array( 'jquery', 'codemirror-less', 'codemirror-css', 'codemirror-javascript' ), Scripts_n_Styles::VERSION, true );
47
- wp_localize_script( 'sns-settings-page-scripts', 'codemirror_options', array( 'theme' => $cm_theme ) );
48
- wp_enqueue_script( 'codemirror', plugins_url( 'libraries/CodeMirror2/lib/codemirror.js', Scripts_n_Styles::$file), array(), $cm_version );
49
- wp_enqueue_script( 'codemirror-css', plugins_url( 'libraries/CodeMirror2/mode/css/css.js', Scripts_n_Styles::$file), array( 'codemirror' ), $cm_version );
50
- wp_enqueue_script( 'codemirror-less', plugins_url( 'libraries/CodeMirror2/mode/less/less.js', Scripts_n_Styles::$file), array( 'codemirror-css' ), $cm_version ); // load css first so less doesn't overwrite mime.
51
- wp_enqueue_script( 'codemirror-javascript', plugins_url( 'libraries/CodeMirror2/mode/javascript/javascript.js', Scripts_n_Styles::$file), array( 'codemirror' ), $cm_version );
52
- wp_enqueue_script( 'codemirror-htmlmixed', plugins_url( 'libraries/CodeMirror2/mode/php/php.js', Scripts_n_Styles::$file), array( 'codemirror-xml', 'codemirror-css', 'codemirror-javascript' ), $cm_version );
53
-
54
- wp_enqueue_script( 'codemirror-xml', plugins_url( 'libraries/CodeMirror2/mode/xml/xml.js', Scripts_n_Styles::$file), array( 'codemirror' ), $cm_version );
55
- wp_enqueue_script( 'codemirror-clike', plugins_url( 'libraries/CodeMirror2/mode/clike/clike.js', Scripts_n_Styles::$file), array( 'codemirror' ), $cm_version );
56
- wp_enqueue_script( 'codemirror-php', plugins_url( 'libraries/CodeMirror2/mode/php/php.js', Scripts_n_Styles::$file), array( 'codemirror-xml', 'codemirror-css', 'codemirror-javascript', 'codemirror-clike' ), $cm_version );
57
  }
58
 
59
- static function parent_file( $parent_file ) {
60
- global $plugin_page, $submenu_file;
61
- if ( self::MENU_SLUG == $plugin_page ) $submenu_file = SnS_Admin::MENU_SLUG;
62
- return $parent_file;
63
- }
64
-
65
-
66
- /**
67
  * Settings Page
68
  * Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
69
- */
70
- function admin_load() {
71
- wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array(), Scripts_n_Styles::VERSION );
72
-
73
  register_setting(
74
- SnS_Admin::OPTION_GROUP,
75
- 'SnS_options' );
76
-
 
 
 
 
77
  add_settings_section(
78
- 'settings',
79
- __( 'Scripts n Styles Settings', 'scripts-n-styles' ),
80
- array( __CLASS__, 'settings_section' ),
81
- SnS_Admin::MENU_SLUG );
82
-
83
  add_settings_field(
84
- 'metabox',
85
- __( '<strong>Hide Metabox by default</strong>: ', 'scripts-n-styles' ),
86
- array( 'SnS_Form', 'radio' ),
87
- SnS_Admin::MENU_SLUG,
88
- 'settings',
89
- array(
90
- 'label_for' => 'metabox',
91
- 'setting' => 'SnS_options',
92
- 'choices' => array( 'yes', 'no' ),
93
- 'layout' => 'horizontal',
94
- 'default' => 'yes',
95
- 'legend' => __( 'Hide Metabox by default', 'scripts-n-styles' ),
96
- 'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">This is overridable via Screen Options on each edit screen.</span>', 'scripts-n-styles' )
97
- ) );
98
-
99
  add_settings_field(
100
- 'menu_position',
101
- __( '<strong>Menu Position</strong>: ', 'scripts-n-styles' ),
102
- array( 'SnS_Form', 'select' ),
103
- SnS_Admin::MENU_SLUG,
104
- 'settings',
105
- array(
106
- 'label_for' => 'menu_position',
107
- 'setting' => 'SnS_options',
108
- 'choices' => array( 'menu', 'object', 'utility', 'tools.php', 'options-general.php', 'themes.php' ),
109
- 'size' => 6,
110
- 'style' => 'height: auto;'
111
- ) );
112
-
113
- add_settings_section(
114
- 'demo',
115
- __( 'Code Mirror Demo', 'scripts-n-styles' ),
116
- array( __CLASS__, 'demo_section' ),
117
- SnS_Admin::MENU_SLUG );
118
-
119
  add_settings_field(
120
- 'cm_theme',
121
- __( '<strong>Theme</strong>: ', 'scripts-n-styles' ),
122
- array( 'SnS_Form', 'radio' ),
123
- SnS_Admin::MENU_SLUG,
124
- 'demo',
125
- array(
126
- 'label_for' => 'cm_theme',
127
- 'setting' => 'SnS_options',
128
- 'choices' => array( 'cobalt', 'eclipse', 'elegant', 'lesser-dark', 'monokai', 'neat', 'night', 'rubyblue', 'xq-dark' ),
129
- 'default' => 'default',
130
- 'legend' => __( 'Theme', 'scripts-n-styles' ),
131
- 'layout' => 'horizontal',
132
- 'description' => ''
133
- ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  }
135
 
136
- /**
 
 
 
 
 
 
 
 
 
 
 
137
  * Settings Page
138
  * Outputs Description text for the Global Section.
139
  */
140
- function settings_section() {
141
  ?>
142
  <div style="max-width: 55em;">
143
- <p><?php _e( 'Control how and where Scripts n Styles menus and metaboxes appear. These options are here because sometimes users really care about this stuff. Feel free to adjust to your liking. :-)', 'scripts-n-styles' ) ?></p>
144
  </div>
145
  <?php
146
  }
147
 
148
- /**
149
  * Settings Page
150
- * Outputs Description text for the Global Section.
151
- */
152
- function demo_section() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  ?>
154
- <div style="max-width: 55em;">
155
- <textarea id="codemirror_demo" name="code" style="min-width: 500px; width:97%;" rows="5" cols="40">
156
- <?php echo esc_textarea( '<?php
157
- function hello($who) {
158
- return "Hello " . $who;
159
- }
160
- ?>
161
- <p>The program says <?= hello("World") ?>.</p>
162
- <script>
163
- alert("And here is some JS code"); // also colored
164
- </script>' ); ?>
165
- </textarea>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  </div>
167
  <?php
168
  }
6
  * and JavaScript directly to individual Post, Pages or custom
7
  * post types.
8
  */
9
+
10
+ // $hook_suffix = 'tools_page_Scripts-n-Styles'; // kept here for reference
11
+ // $plugin_file = 'scripts-n-styles/scripts-n-styles.php'; // kept here for reference
12
 
13
  class SnS_Settings_Page
14
  {
15
+ /**
16
+ * Constants
17
+ */
18
+ const OPTION_GROUP = 'scripts_n_styles';
19
 
20
+ /**
21
  * Initializing method.
22
+ * @static
23
+ */
24
+ static function init() {
25
+ /* NOTE: Even when Scripts n Styles is not restricted by 'manage_options', Editors still can't submit the option page */
26
+ if ( current_user_can( 'manage_options' ) ) { // if they can't, they won't be able to save anyway.
27
+ $hook_suffix = add_management_page(
28
+ 'Scripts n Styles Settings', // $page_title (string) (required) The text to be displayed in the title tags of the page when the menu is selected
29
+ 'Scripts n Styles', // $menu_title (string) (required) The text to be used for the menu
30
+ 'unfiltered_html', // $capability (string) (required) The capability required for this menu to be displayed to the user.
31
+ SnS_Admin::MENU_SLUG, // $menu_slug (string) (required) The slug name to refer to this menu by (should be unique for this menu).
32
+ array( __CLASS__, 'options_page' ) // $function (callback) (optional) The function to be called to output the content for this page.
33
+ );
34
+ Scripts_n_Styles::$hook_suffix = $hook_suffix;
35
+ add_action( "load-$hook_suffix", array( __CLASS__, 'init_options_page' ) );
36
+ add_action( "load-options.php", array( __CLASS__, 'init_options_page' ) );
37
+
38
+ add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'options_styles'));
39
+ add_action( "admin_print_scripts-$hook_suffix", array( __CLASS__, 'options_scripts'));
40
+
41
+ add_contextual_help( $hook_suffix, self::contextual_help() );
42
  }
43
  }
44
 
45
+ /**
46
+ * Settings Page help
47
+ */
48
+ function contextual_help() {
49
+ $contextual_help = '<p>In default (non MultiSite) WordPress installs, both <em>Administrators</em> and
50
+ <em>Editors</em> can access <em>Scripts-n-Styles</em> on individual edit screens.
51
+ Only <em>Administrators</em> can access this Options Page. In MultiSite WordPress installs, only <em>"Super Admin"</em> users can access either
52
+ <em>Scripts-n-Styles</em> on individual edit screens or this Options Page. If other plugins change capabilities (specifically "unfiltered_html"),
53
+ other users can be granted access.</p>';
54
+ return $contextual_help;
 
 
 
 
 
 
 
 
 
 
 
55
  }
56
 
57
+ /**
 
 
 
 
 
 
 
58
  * Settings Page
59
  * Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
60
+ */
61
+ static function init_options_page() {
 
 
62
  register_setting(
63
+ self::OPTION_GROUP, // $option_group (string) (required) A settings group name. Can be anything.
64
+ 'SnS_options' // $option_name (string) (required) The name of an option to sanitize and save.
65
+ );
66
+ register_setting(
67
+ self::OPTION_GROUP,
68
+ 'SnS_enqueue_scripts'
69
+ );
70
  add_settings_section(
71
+ 'global',
72
+ 'Global Scripts n Styles',
73
+ array( __CLASS__, 'global_section' ),
74
+ SnS_Admin::MENU_SLUG
75
+ );
76
  add_settings_field(
77
+ 'scripts',
78
+ '<label for="scripts"><strong>Scripts:</strong> </label>',
79
+ array( __CLASS__, 'scripts_field' ),
80
+ SnS_Admin::MENU_SLUG,
81
+ 'global'
82
+ );
 
 
 
 
 
 
 
 
 
83
  add_settings_field(
84
+ 'styles',
85
+ '<label for="styles"><strong>Styles:</strong> </label>',
86
+ array( __CLASS__, 'styles_field' ),
87
+ SnS_Admin::MENU_SLUG,
88
+ 'global'
89
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  add_settings_field(
91
+ 'scripts_in_head',
92
+ '<label for="scripts_in_head"><strong>Scripts</strong><br />(for the <code>head</code> element): </label>',
93
+ array( __CLASS__, 'scripts_in_head_field' ),
94
+ SnS_Admin::MENU_SLUG,
95
+ 'global'
96
+ );
97
+ /*add_settings_field(
98
+ 'enqueue_scripts',
99
+ '<label for="enqueue_scripts"><strong>Enqueue Scripts</strong>: </label>',
100
+ array( __CLASS__, 'enqueue_scripts_field' ),
101
+ SnS_Admin::MENU_SLUG,
102
+ 'global'
103
+ );*/
104
+ add_settings_section(
105
+ 'usage',
106
+ 'Scripts n Styles Usage',
107
+ array( __CLASS__, 'usage_section' ),
108
+ SnS_Admin::MENU_SLUG
109
+ );
110
+ }
111
+
112
+ /**
113
+ * Settings Page
114
+ * Adds CSS styles to the Scripts n Styles Admin Page.
115
+ */
116
+ static function options_styles() {
117
+ wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array( 'codemirror-default' ), SnS_Admin::VERSION );
118
+ wp_enqueue_style( 'codemirror', plugins_url( 'libraries/codemirror/lib/codemirror.css', Scripts_n_Styles::$file), array(), '2.1' );
119
+ wp_enqueue_style( 'codemirror-default', plugins_url( 'libraries/codemirror/theme/default.css', Scripts_n_Styles::$file), array( 'codemirror' ), '2.1' );
120
  }
121
 
122
+ /**
123
+ * Settings Page
124
+ * Adds JavaScript to the Scripts n Styles Admin Page.
125
+ */
126
+ static function options_scripts() {
127
+ wp_enqueue_script( 'sns-options-scripts', plugins_url('js/options-scripts.js', Scripts_n_Styles::$file), array( 'jquery', 'codemirror-css', 'codemirror-javascript' ), SnS_Admin::VERSION, true );
128
+ wp_enqueue_script( 'codemirror', plugins_url( 'libraries/codemirror/lib/codemirror.js', Scripts_n_Styles::$file), array(), '2.1' );
129
+ wp_enqueue_script( 'codemirror-css', plugins_url( 'libraries/codemirror/mode/css.js', Scripts_n_Styles::$file), array( 'codemirror' ), '2.1' );
130
+ wp_enqueue_script( 'codemirror-javascript', plugins_url( 'libraries/codemirror/mode/javascript.js', Scripts_n_Styles::$file), array( 'codemirror' ), '2.1' );
131
+ }
132
+
133
+ /**
134
  * Settings Page
135
  * Outputs Description text for the Global Section.
136
  */
137
+ static function global_section() {
138
  ?>
139
  <div style="max-width: 55em;">
140
+ <p>Code entered here will be included in <em>every page (and post) of your site</em>, including the homepage and archives. The code will appear <strong>before</strong> Scripts and Styles registered individually.</p>
141
  </div>
142
  <?php
143
  }
144
 
145
+ /**
146
  * Settings Page
147
+ * Outputs the Usage Section.
148
+ */
149
+ static function usage_section() {
150
+ $options = get_option( 'SnS_options' );
151
+
152
+ $all_posts = get_posts( array( 'numberposts' => -1, 'post_type' => 'any', 'post_status' => 'any' ) );
153
+ $sns_posts = array();
154
+ foreach( $all_posts as $post) {
155
+ $temp_styles = get_post_meta( $post->ID, 'uFp_styles', true );
156
+ $temp_scripts = get_post_meta( $post->ID, 'uFp_scripts', true );
157
+ if ( ! empty( $temp_styles ) || ! empty( $temp_scripts ) )
158
+ $sns_posts[] = $post;
159
+ }
160
+
161
+ if ( ! empty( $sns_posts ) ) {
162
+ ?>
163
+ <table cellspacing="0" class="widefat">
164
+ <thead>
165
+ <tr>
166
+ <th>Title</th>
167
+ <th>ID</th>
168
+ <th>Status</th>
169
+ <th>Post Type</th>
170
+ </tr>
171
+ </thead>
172
+ <tbody>
173
+ <?php foreach( $sns_posts as $post) {
174
+ $temp_styles = get_post_meta( $post->ID, 'uFp_styles', true );
175
+ $temp_scripts = get_post_meta( $post->ID, 'uFp_scripts', true );
176
+ if ( ! empty( $temp_styles ) || ! empty( $temp_scripts ) ) { ?>
177
+ <tr>
178
+ <td>
179
+ <strong><a class="row-title" title="Edit &#8220;<?php echo esc_attr( $post->post_title ); ?>&#8221;" href="<?php echo esc_url( get_edit_post_link( $post->ID ) ); ?>"><?php echo $post->post_title; ?></a></strong>
180
+ <div class="row-actions"><span class="edit"><a title="Edit this item" href="<?php echo esc_url( get_edit_post_link( $post->ID ) ); ?>">Edit</a></span></div>
181
+ </td>
182
+ <td><?php echo $post->ID; ?></td>
183
+ <td><?php echo $post->post_status; ?></td>
184
+ <td><?php echo $post->post_type; ?></td>
185
+ </tr>
186
+ <?php }
187
+ } ?>
188
+ </tbody>
189
+ <tfoot>
190
+ <tr>
191
+ <th>Title</th>
192
+ <th>ID</th>
193
+ <th>Status</th>
194
+ <th>Post Type</th>
195
+ </tr>
196
+ </tfoot>
197
+ </table>
198
+ <?php
199
+ } else {
200
+ ?>
201
+ <div style="max-width: 55em;">
202
+ <p>No content items are currently using Scripts-n-Styles data.</p>
203
+ </div>
204
+ <?php
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Settings Page
210
+ * Outputs a textarea for setting 'scripts'.
211
+ */
212
+ static function scripts_field() {
213
+ $options = get_option( 'SnS_options' );
214
+ ?><textarea style="min-width: 500px; width:97%;" class="code js" rows="5" cols="40" name="SnS_options[scripts]" id="scripts"><?php echo isset( $options[ 'scripts' ] ) ? $options[ 'scripts' ] : ''; ?></textarea><br />
215
+ <span class="description" style="max-width: 500px; display: inline-block;">The "Scripts" will be included <strong>verbatim</strong> in <code>&lt;script></code> tags at the bottom of the <code>&lt;body></code> element of your html.</span>
216
+ <?php
217
+ }
218
+
219
+ /**
220
+ * Settings Page
221
+ * Outputs a textarea for setting 'styles'.
222
+ */
223
+ static function styles_field() {
224
+ $options = get_option( 'SnS_options' );
225
+ ?><textarea style="min-width: 500px; width:97%;" class="code css" rows="5" cols="40" name="SnS_options[styles]" id="styles"><?php echo isset( $options[ 'styles' ] ) ? $options[ 'styles' ] : ''; ?></textarea><br />
226
+ <span class="description" style="max-width: 500px; display: inline-block;">The "Styles" will be included <strong>verbatim</strong> in <code>&lt;style></code> tags in the <code>&lt;head></code> element of your html.</span><?php
227
+ }
228
+
229
+ /**
230
+ * Settings Page
231
+ * Outputs a textarea for setting 'scripts_in_head'.
232
+ */
233
+ static function scripts_in_head_field() {
234
+ $options = get_option( 'SnS_options' );
235
+ ?><textarea style="min-width: 500px; width:97%;" class="code js" rows="5" cols="40" name="SnS_options[scripts_in_head]" id="scripts_in_head"><?php echo isset( $options[ 'scripts_in_head' ] ) ? $options[ 'scripts_in_head' ] : ''; ?></textarea><br />
236
+ <span class="description" style="max-width: 500px; display: inline-block;">The "Scripts (in head)" will be included <strong>verbatim</strong> in <code>&lt;script></code> tags in the <code>&lt;head></code> element of your html.</span>
237
+ <?php
238
+ }
239
+
240
+ /**
241
+ * Settings Page
242
+ * Outputs a select element for selecting options to set $sns_enqueue_scripts.
243
+ */
244
+ static function enqueue_scripts_field() {
245
+ $registered_handles = Scripts_n_Styles::get_wp_registered();
246
+ $sns_enqueue_scripts = get_option( 'SnS_enqueue_scripts' );
247
+ if ( ! is_array( $sns_enqueue_scripts ) ) $sns_enqueue_scripts = array();
248
  ?>
249
+ <select name="SnS_enqueue_scripts[]" id="enqueue_scripts" size="5" multiple="multiple" style="height: auto;">
250
+ <?php foreach ( $registered_handles as $value ) { ?>
251
+ <option value="<?php echo $value ?>"<?php foreach ( $sns_enqueue_scripts as $handle ) selected( $handle, $value ); ?>><?php echo $value ?></option>
252
+ <?php } ?>
253
+ </select>
254
+ <?php if ( ! empty( $sns_enqueue_scripts ) && is_array( $sns_enqueue_scripts ) ) { ?>
255
+ <p>Currently Enqueued Scripts:
256
+ <?php foreach ( $sns_enqueue_scripts as $handle ) echo '<code>' . $handle . '</code> '; ?>
257
+ </p>
258
+ <?php }
259
+ }
260
+
261
+ /**
262
+ * Settings Page
263
+ * Outputs the Admin Page and calls the Settings registered with the Settings API in init_options_page().
264
+ */
265
+ static function options_page() {
266
+ SnS_Admin::upgrade_check();
267
+ global $title;
268
+ ?>
269
+ <div class="wrap">
270
+ <?php screen_icon(); ?>
271
+ <h2><?php echo esc_html($title); ?></h2>
272
+ <form action="options.php" method="post" autocomplete="off">
273
+ <?php settings_fields( self::OPTION_GROUP ); ?>
274
+ <?php do_settings_sections( SnS_Admin::MENU_SLUG ); ?>
275
+ <?php submit_button(); ?>
276
+ </form>
277
  </div>
278
  <?php
279
  }
includes/class.SnS_Usage_Page.php DELETED
@@ -1,87 +0,0 @@
1
- <?php
2
- /**
3
- * SnS_Settings_Page
4
- *
5
- * Allows WordPress admin users the ability to add custom CSS
6
- * and JavaScript directly to individual Post, Pages or custom
7
- * post types.
8
- */
9
-
10
- class SnS_Usage_Page
11
- {
12
- /**
13
- * Constants
14
- */
15
- const MENU_SLUG = 'sns_usage';
16
-
17
- /**
18
- * Initializing method.
19
- * @static
20
- */
21
- function init() {
22
- $hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Usage', 'scripts-n-styles' ), 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
23
-
24
- add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
25
- add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
26
-
27
- // Make the page into a tab.
28
- if ( SnS_Admin::MENU_SLUG != SnS_Admin::$parent_slug ) {
29
- remove_submenu_page( SnS_Admin::$parent_slug, self::MENU_SLUG );
30
- add_filter( 'parent_file', array( __CLASS__, 'parent_file') );
31
- }
32
- }
33
-
34
- static function parent_file( $parent_file ) {
35
- global $plugin_page, $submenu_file;
36
- if ( self::MENU_SLUG == $plugin_page ) $submenu_file = SnS_Admin::MENU_SLUG;
37
- return $parent_file;
38
- }
39
-
40
- /**
41
- * Settings Page
42
- * Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
43
- */
44
- function admin_load() {
45
- wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array(), Scripts_n_Styles::VERSION );
46
-
47
- add_screen_option( 'per_page', array( 'label' => __( 'Per Page' ), 'default' => 20 ) );
48
- add_filter( 'set-screen-option', array( __CLASS__, 'set_screen_option' ), 10, 3 );
49
- // hack for core limitation: see http://core.trac.wordpress.org/ticket/18954
50
- set_screen_options();
51
-
52
- add_settings_section(
53
- 'usage',
54
- __( 'Scripts n Styles Usage', 'scripts-n-styles' ),
55
- array( __CLASS__, 'usage_section' ),
56
- SnS_Admin::MENU_SLUG );
57
- }
58
-
59
- function set_screen_option( $false, $option, $value ) {
60
- $screen_id = get_current_screen()->id;
61
- $this_option = str_replace( '-', '_', "{$screen_id}_per_page" );
62
- if ( $this_option != $option )
63
- return false;
64
-
65
- $value = (int) $value;
66
- if ( $value < 1 || $value > 999 )
67
- return false;
68
-
69
- return $value;
70
- }
71
-
72
- /**
73
- * Settings Page
74
- * Outputs the Usage Section.
75
- */
76
- function usage_section() { ?>
77
- <div style="max-width: 55em;">
78
- <p><?php _e( 'The following table shows content that utilizes Scripts n Styles.', 'scripts-n-styles' ) ?></p>
79
- </div>
80
- <?php
81
- require_once( 'class.SnS_List_Usage.php' );
82
- $usageTable = new SnS_List_Usage();
83
- $usageTable->prepare_items();
84
- $usageTable->display();
85
- }
86
- }
87
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/code-editor.js DELETED
@@ -1,42 +0,0 @@
1
- // Options JavaScript
2
-
3
- jQuery( document ).ready( function( $ ) {
4
- var theme = codemirror_options.theme ? codemirror_options.theme: 'default';
5
- var file = $( 'input[name="file"]' ).val();
6
- var fileType = file.slice( file.lastIndexOf(".")+1 );
7
-
8
- var $submitWrap = $( '#submit' ).parent();
9
- var modHeight = $submitWrap.height()
10
- + parseInt( $submitWrap.css( 'marginTop' ) )
11
- + parseInt( $submitWrap.css( 'marginBottom' ) )
12
- + parseInt( $submitWrap.css( 'paddingTop' ) )
13
- + parseInt( $submitWrap.css( 'paddingBottom' ) );
14
-
15
- var $documentation = $( '#documentation:visible' );
16
- if ( $documentation.length ) {
17
- modHeight += $documentation.height() + parseInt( $documentation.css( 'marginTop' ) );
18
- }
19
-
20
- var height = $(window).height() - $( '#newcontent' ).offset().top - $( '#wpadminbar' ).height() - modHeight;
21
-
22
- var config = { lineNumbers: true, mode: "javascript", theme: theme };
23
-
24
- if ( "js" == fileType )
25
- config.mode = "javascript";
26
- else if ( "css" == fileType )
27
- config.mode = "css";
28
- else if ( "less" == fileType )
29
- config.mode = "less";
30
- else if ( "html" == fileType || "htm" == fileType )
31
- config.mode = "html";
32
- else if ( "php" == fileType )
33
- config.mode = "php";
34
- else
35
- config.mode = "txt";
36
-
37
- CodeMirror.commands.save = function (){ jQuery('#submit').click(); };
38
-
39
- CodeMirror.fromTextArea( $( '#newcontent' ).get(0), config );
40
-
41
- if ( height < $( '.CodeMirror-scroll ' ).height() ) $( '.CodeMirror-scroll ' ).height( height );
42
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/global-page.js DELETED
@@ -1,85 +0,0 @@
1
- // Options JavaScript
2
-
3
- jQuery( document ).ready( function( $ ) {
4
- var theme = _SnS_options.theme ? _SnS_options.theme: 'default';
5
- var lessMirror, lessOutput, errorLine, errorText, errors, loaded,
6
- lessMirrorConfig = { lineNumbers: true, mode: "text/x-less", theme: theme, indentWithTabs: true };
7
-
8
- CodeMirror.commands.save = saveLessMirror;
9
- lessMirrorConfig.onChange = compile;
10
-
11
- $( "textarea.js" ).each( function() {
12
- CodeMirror.fromTextArea( this, { lineNumbers: true, mode: "javascript", theme: theme } );
13
- });
14
-
15
- $( "textarea.css" ).not( '#compiled' ).each( function() {
16
- CodeMirror.fromTextArea( this, { lineNumbers: true, mode: "css", theme: theme } );
17
- });
18
-
19
- lessOutput = CodeMirror.fromTextArea( $( '#compiled' ).get(0), { lineNumbers: true, mode: "css", theme: theme, readOnly: true } );
20
-
21
- $( "textarea.less" ).each( function() {
22
- lessMirror = CodeMirror.fromTextArea( this, lessMirrorConfig );
23
- });
24
-
25
- compile();
26
- loaded = true;
27
- $( "#less" ).closest('form').submit( compile );
28
-
29
- function saveLessMirror(){
30
- // Ajax Save.
31
- }
32
- function compile() {
33
- lessMirror.save();
34
- var parser = new( less.Parser );
35
- parser.parse( lessMirror.getValue(), function ( err, tree ) {
36
- if ( err ){
37
- doError( err );
38
- } else {
39
- try {
40
- $( '#compiled_error' ).hide();
41
- lessOutput.setValue( tree.toCSS() );
42
- lessOutput.save();
43
- $( '#compiled' ).next( '.CodeMirror' ).show();
44
- lessOutput.refresh();
45
- clearCompileError();
46
- }
47
- catch ( err ) {
48
- doError( err );
49
- }
50
- }
51
- });
52
- }
53
- function doError( err ) {
54
- //console.dir( err );
55
- $( '#compiled' ).next( '.CodeMirror' ).hide();
56
- if ( loaded ) {
57
- $( '#compiled_error' ).removeClass( 'error' ).addClass( 'updated' );
58
- $( '#compiled_error' ).show().html( "<p><strong>Warning: &nbsp; </strong>" + err.message + "</p>" );
59
- } else {
60
- $( '#compiled_error' ).show().html( "<p><strong>Error: &nbsp; </strong>" + err.message + "</p>" );
61
- }
62
- clearCompileError();
63
-
64
- errorLine = lessMirror.setMarker( err.line - 1, '<strong>*%N%</strong>', "cm-error");
65
- lessMirror.setLineClass( errorLine, "cm-error");
66
-
67
- var pos = lessMirror.posFromIndex( err.index + 1 );
68
- var token = lessMirror.getTokenAt( pos );
69
- var start = lessMirror.posFromIndex( err.index );
70
- var end = lessMirror.posFromIndex( err.index + token.string.length )
71
- errorText = lessMirror.markText( start, end, "cm-error");
72
-
73
- lessOutput.setValue( "" );
74
- lessOutput.save();
75
- }
76
- function clearCompileError() {
77
- if ( errorLine ) {
78
- lessMirror.clearMarker( errorLine );
79
- lessMirror.setLineClass( errorLine, null );
80
- errorLine = false;
81
- }
82
- if ( errorText ) errorText.clear();
83
- errorText = false;
84
- }
85
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/meta-box-scripts.js CHANGED
@@ -1,430 +1,12 @@
 
 
1
  jQuery( document ).ready( function( $ ) {
 
2
 
3
- // For compat: 3.3 || 3.2
4
- var initData = tinyMCEPreInit.mceInit["content"],
5
- context = '#SnS_meta_box',
6
- currentCodeMirror = [],
7
- mceBodyClass = getMCEBodyClasses(),
8
- nonce = $( '#scripts_n_styles_noncename' ).val(),
9
- theme = codemirror_options.theme ? codemirror_options.theme: 'default';
10
-
11
- //$('textarea', context).attr('autocomplete','off');
12
-
13
- // Refresh when panel becomes unhidden
14
- $( context + '-hide, '
15
- + context + ' .hndle, '
16
- + context + ' .handlediv ' )
17
- .live( 'click', refreshCodeMirrors );
18
-
19
- // add tab-switch handler
20
- $( '.wp-tab-bar a', context ).live( 'click', onTabSwitch );
21
-
22
- // activate first run
23
- $( '.wp-tab-active a', context ).trigger( 'click' );
24
-
25
- // must run before ajax click handlers are added.
26
- setupAjaxUI();
27
-
28
- refreshDeleteBtns();
29
-
30
-
31
- $('#sns-ajax-update-scripts').click(function( event ){
32
- event.preventDefault();
33
- $(this).next().show();
34
- $(currentCodeMirror).each(function (){ this.save(); });
35
- var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
36
-
37
- args.action = 'sns_scripts';
38
- args.scripts = $( '#SnS_scripts' ).val();
39
- args.scripts_in_head = $( '#SnS_scripts_in_head' ).val();
40
-
41
- $.post( ajaxurl, args, function() { refreshMCE(); } );
42
- });
43
-
44
- $('#sns-ajax-update-styles').click(function( event ){
45
- event.preventDefault();
46
- $(this).next().show();
47
- $(currentCodeMirror).each(function (){ this.save(); });
48
- var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
49
-
50
- args.action = 'sns_styles';
51
- args.styles = $( '#SnS_styles' ).val();
52
-
53
- $.post( ajaxurl, args, function() { refreshMCE(); } );
54
- });
55
-
56
- /*
57
- * Expects return data.
58
- */
59
- $('#sns-ajax-update-classes').click(function( event ){
60
- event.preventDefault();
61
- $(this).next().show();
62
- var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
63
-
64
- args.action = 'sns_classes';
65
- args.classes_body = $( '#SnS_classes_body' ).val();
66
- args.classes_post = $( '#SnS_classes_post' ).val();
67
-
68
- $.post( ajaxurl, args, function( data ) { refreshBodyClass( data ); } );
69
- });
70
-
71
- /*
72
- * Expects return data.
73
- */
74
- $('#sns-ajax-update-dropdown').click(function( event ){
75
- event.preventDefault();
76
- $(this).next().show();
77
- var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
78
-
79
- args.action = 'sns_dropdown';
80
- var format = {};
81
- format.title = $( '#SnS_classes_mce_title' ).val();
82
- format.classes = $( '#SnS_classes_mce_classes' ).val();
83
- switch ( $( '#SnS_classes_mce_type' ).val() ) {
84
- case 'inline':
85
- format.inline = $( '#SnS_classes_mce_element' ).val();
86
- break;
87
- case 'block':
88
- format.block = $( '#SnS_classes_mce_element' ).val();
89
- if ( $( '#SnS_classes_mce_wrapper' ).prop('checked') )
90
- format.wrapper = true;
91
- break;
92
- case 'selector':
93
- format.selector = $( '#SnS_classes_mce_element' ).val();
94
- break;
95
- default:
96
- return;
97
- }
98
- args.format = format;
99
-
100
- $.post( ajaxurl, args, function( data ) { refreshStyleFormats( data ); } );
101
  });
102
-
103
- /*
104
- * Expects return data.
105
- */
106
- $('#delete-mce-dropdown-names .sns-ajax-delete').live( "click", function( event ){
107
- event.preventDefault();
108
- $(this).next().show();
109
- var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
110
-
111
- args.action = 'sns_delete_class';
112
- args.delete = $( this ).attr( 'id' );
113
-
114
- $.post( ajaxurl, args, function( data ) { refreshStyleFormats( data ); } );
115
  });
116
-
117
- /*
118
- * Returns the body_class of TinyMCE minus the Scripts n Styles values.
119
- */
120
- function getMCEBodyClasses() {
121
- var t = [];
122
- if ( initData.body_class )
123
- t = initData.body_class.split(' ');
124
-
125
- var bc = $('#SnS_classes_body').val().split(' ');
126
- var pc = $('#SnS_classes_post').val().split(' ');
127
- var p;
128
- for ( var i = 0; i < t.length; i++ ) {
129
- p = $.inArray( bc[i], t )
130
- if ( -1 != p )
131
- t.splice( p, 1 );
132
- }
133
- for ( var i = 0; i < t.length; i++ ) {
134
- p = $.inArray( pc[i], t )
135
- if ( -1 != p )
136
- t.splice( p, 1 );
137
- }
138
- t = t.join(' ');
139
- return t;
140
- }
141
-
142
- /*
143
- * Builds and Adds the DOM for AJAX functionality.
144
- */
145
- function setupAjaxUI() {
146
- // set up ajax ui. (need to come up with a better ID naming scheme.)
147
- $('#SnS_scripts-tab').append(
148
- '<div class="sns-ajax-wrap">'
149
- + '<a id="sns-ajax-update-scripts" href="#" class="button">Update Scripts</a>'
150
- + ' '
151
- + '<img class="sns-ajax-loading" src="/wp-admin/images/wpspin_light.gif">'
152
- + '</div>'
153
- );
154
-
155
- $('#SnS_styles-tab').append(
156
- '<div class="sns-ajax-wrap">'
157
- + '<a id="sns-ajax-update-styles" href="#" class="button">Update Styles</a>'
158
- + ' '
159
- + '<img class="sns-ajax-loading" src="/wp-admin/images/wpspin_light.gif">'
160
- + '</div>'
161
- );
162
-
163
- $('#sns-classes').append(
164
- '<div class="sns-ajax-wrap">'
165
- + '<a id="sns-ajax-update-classes" href="#" class="button">Update Classes</a>'
166
- + ' '
167
- + '<img class="sns-ajax-loading" src="/wp-admin/images/wpspin_light.gif">'
168
- + '</div>'
169
- );
170
-
171
- $('#add-mce-dropdown-names').append(
172
- '<div class="sns-ajax-wrap">'
173
- + '<a id="sns-ajax-update-dropdown" href="#" class="button">Add Class</a>'
174
- + ' '
175
- + '<img class="sns-ajax-loading" src="/wp-admin/images/wpspin_light.gif">'
176
- + '</div>'
177
- );
178
-
179
- $('.sns-ajax-loading').hide();
180
-
181
- if ( $( '#SnS_classes_mce_type').val() == 'block' ) {
182
- $('#add-mce-dropdown-names .sns-mce-wrapper').show();
183
- } else {
184
- $('#add-mce-dropdown-names .sns-mce-wrapper').hide();
185
- }
186
-
187
- $( '#SnS_classes_mce_type' ).change(function() {
188
- if ( $(this).val() == 'block' ) {
189
- $('#add-mce-dropdown-names .sns-mce-wrapper').show();
190
- } else {
191
- $('#add-mce-dropdown-names .sns-mce-wrapper').hide();
192
- }
193
- });
194
-
195
- $( '#mce-dropdown-names', context ).show();
196
- }
197
-
198
- /*
199
- * Main Tab Switch Handler.
200
- */
201
- function onTabSwitch( event ) {
202
- event.preventDefault();
203
-
204
- clearCodeMirrors();
205
-
206
- /*
207
- * There is a weird bug where if clearCodeMirrors() is called right before
208
- * loadCodeMirrors(), loading the page with the Styles tab active, and
209
- * then switching to the Script tab, you can lose data from the second
210
- * CodeMirror if leaving and returning to that tab. I've no idea what's
211
- * going on there. Leaving code inbetween them is a fraggle, but working,
212
- * workaround. Maybe has to do with execution time? No idea.
213
- */
214
-
215
- // switch active classes
216
- $( '.wp-tab-active', context ).removeClass( 'wp-tab-active' );
217
- $( this ).parent( 'li' ).addClass( 'wp-tab-active' );
218
-
219
- $( '.wp-tabs-panel-active', context ).hide().removeClass( 'wp-tabs-panel-active' );
220
- $( $( this ).attr( 'href' ) ).show().addClass( 'wp-tabs-panel-active' );
221
-
222
- loadCodeMirrors();
223
-
224
- $.post( ajaxurl, {
225
- action: 'sns_update_tab',
226
- _ajax_nonce: nonce,
227
- active_tab: $( '.wp-tab-bar li', context ).index( $( this ).parent( 'li' ).get(0) )
228
- }
229
- );
230
- }
231
-
232
- /*
233
- * CodeMirror Utilities.
234
- */
235
- function clearCodeMirrors() {
236
- $(currentCodeMirror).each(function (){
237
- this.toTextArea();
238
- });
239
- currentCodeMirror = [];
240
- }
241
- function refreshCodeMirrors() {
242
- $(currentCodeMirror).each( function(){
243
- this.refresh();
244
- });
245
- }
246
- function loadCodeMirrors() {
247
- // collect codemirrors
248
- var settings;
249
- // loop codemirrors
250
- $( '.wp-tabs-panel-active textarea.codemirror', context ).each(function (){
251
- if ( $(this).hasClass( 'js' ) )
252
- settings = {
253
- mode: "text/javascript",
254
- theme: theme,
255
- lineNumbers: true,
256
- tabMode: "shift",
257
- indentUnit: 4,
258
- indentWithTabs: true
259
- };
260
- else if ( $(this).hasClass( 'css' ) )
261
- settings = {
262
- mode: "text/css",
263
- theme: theme,
264
- lineNumbers: true,
265
- tabMode: "shift",
266
- indentUnit: 4,
267
- indentWithTabs: true
268
- };
269
- else if ( $(this).hasClass( 'less' ) )
270
- settings = {
271
- mode: "text/x-less",
272
- theme: theme,
273
- lineNumbers: true,
274
- tabMode: "shift",
275
- indentUnit: 4,
276
- indentWithTabs: true,
277
- };
278
- else if ( $(this).hasClass( 'htmlmixed' ) )
279
- settings = {
280
- mode: "text/html",
281
- theme: theme,
282
- lineNumbers: true,
283
- tabMode: "shift",
284
- indentUnit: 4,
285
- indentWithTabs: true,
286
- enterMode: "keep",
287
- matchBrackets: true
288
- };
289
- /*else if ( $(this).hasClass( 'php' ) )
290
- settings = {
291
- mode: "application/x-httpd-php",
292
- lineNumbers: true,
293
- tabMode: "shift",
294
- indentUnit: 4,
295
- indentWithTabs: true,
296
- enterMode: "keep",
297
- matchBrackets: true
298
- };*/
299
- else
300
- return;
301
-
302
- // initialize and store active codemirrors
303
- currentCodeMirror.push( CodeMirror.fromTextArea( this, settings ) );
304
- });
305
- }
306
-
307
- /*
308
- * Refresh after AJAX.
309
- */
310
- function refreshDeleteBtns() {
311
- // responsible for clearing out Delete Buttons, and Adding new ones.
312
- // initData should always contain the latest settings.
313
- if ( initData.style_formats && initData.style_formats.length ) {
314
- $( '#delete-mce-dropdown-names .sns-ajax-delete-p' ).remove();
315
- $( '#delete-mce-dropdown-names', context ).show();
316
- var formats = initData.style_formats;
317
- for ( var i = 0; i < formats.length; i++ ) {
318
- var deleteBtn = {};
319
- if ( formats[i].inline ) {
320
- deleteBtn.element = formats[i].inline;
321
- deleteBtn.wrapper = '';
322
- } else if ( formats[i].block ) {
323
- deleteBtn.element = formats[i].block;
324
- if ( formats[i].wrapper )
325
- deleteBtn.wrapper = ' (wrapper)';
326
- else
327
- deleteBtn.wrapper = '';
328
- } else if ( formats[i].selector ) {
329
- deleteBtn.element = formats[i].selector;
330
- deleteBtn.wrapper = '';
331
- } else {
332
- alert( 'ERROR!' );
333
- }
334
- deleteBtn.title = formats[i].title;
335
- deleteBtn.classes = formats[i].classes;
336
- $( '#instructions-mce-dropdown-names', context ).after(
337
- '<p class="sns-ajax-delete-p"><a title="delete" class="sns-ajax-delete" id="'
338
- + deleteBtn.title + '">X</a> "'
339
- + deleteBtn.title + '" <code>&lt;'
340
- + deleteBtn.element + ' class="'
341
- + deleteBtn.classes + '"&gt;</code>'
342
- + deleteBtn.wrapper + '</p>'
343
- );
344
- }
345
- } else {
346
- $( '#delete-mce-dropdown-names', context ).hide();
347
- }
348
- }
349
- function refreshBodyClass( data ) {
350
- initData.body_class = mceBodyClass + ' ' + data.classes_body + ' ' + data.classes_post;
351
-
352
- refreshMCE();
353
- }
354
- function refreshStyleFormats( data ) {
355
- // error check
356
- console.log(data.classes_mce);
357
- if ( typeof data.classes_mce === 'undefined' ) {
358
- alert( data );
359
- $('.sns-ajax-loading').hide();
360
- return;
361
- } else if ( data.classes_mce.length && data.classes_mce != 'Empty' ) {
362
- var style_formats = [];
363
-
364
- for ( var i = 0; i < data.classes_mce.length; i++ ) { // loop returned classes_mce
365
- var format = {};
366
- format.title = data.classes_mce[i].title;
367
-
368
- if ( data.classes_mce[i].inline )
369
- format.inline = data.classes_mce[i].inline;
370
- else if ( data.classes_mce[i].block ) {
371
- format.block = data.classes_mce[i].block;
372
- if (data.classes_mce[i].wrapper)
373
- format.wrapper = true;
374
- } else if ( data.classes_mce[i].selector )
375
- format.selector = data.classes_mce[i].selector;
376
- else
377
- alert('dropdown format has bad type.');
378
-
379
- format.classes = data.classes_mce[i].classes;
380
- style_formats.push( format );
381
- }
382
- initData.style_formats = style_formats;
383
-
384
- if ( initData.theme_advanced_buttons2.indexOf( "styleselect" ) == -1 ) {
385
- var tempString = "styleselect,";
386
- initData.theme_advanced_buttons2 = tempString.concat(initData.theme_advanced_buttons2);
387
- }
388
-
389
- $( '#delete-mce-dropdown-names', context ).show();
390
- } else {
391
- delete initData.style_formats;
392
- initData.theme_advanced_buttons2 = initData.theme_advanced_buttons2.replace("styleselect,", "");
393
-
394
- $( '#delete-mce-dropdown-names', context ).hide();
395
- }
396
-
397
- refreshDeleteBtns();
398
- refreshMCE();
399
- }
400
- function refreshMCE() {
401
- var ed = tinyMCE.editors["content"];
402
- // If Visual has been activated.
403
- if ( ed ) {
404
- if ( ed.isHidden() ) {
405
- refreshMCEhelper(ed);
406
- } else {
407
- $('#content-html').click(); // 3.3
408
-
409
- refreshMCEhelper(ed);
410
-
411
- $('#content-tmce').click(); // 3.3
412
- }
413
-
414
- }
415
- // Else nothing.
416
-
417
- $('.sns-ajax-loading').hide();
418
- }
419
- function refreshMCEhelper(ed) {
420
- ed.save();
421
- ed.destroy();
422
- ed.remove();
423
- if ( initData && initData.wpautop )
424
- $('#content').val( switchEditors.wpautop( $('#content').val() ) );
425
- ed = new tinymce.Editor( 'content', initData );
426
- ed.render();
427
- ed.hide();
428
- }
429
-
430
- });
1
+ // Meta Box JavaScript
2
+
3
  jQuery( document ).ready( function( $ ) {
4
+ $( "#uFp_meta_box" ).tabs().find( ".wp-tab-bar" ).show();
5
 
6
+ $( "textarea.js" ).each( function() {
7
+ CodeMirror.fromTextArea( this, { lineNumbers: true, mode: "javascript" } );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  });
9
+ $( "textarea.css" ).each( function() {
10
+ CodeMirror.fromTextArea( this, { lineNumbers: true, mode: "css" } );
 
 
 
 
 
 
 
 
 
 
 
11
  });
12
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/options-scripts.js ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ // Options JavaScript
2
+
3
+ jQuery( document ).ready( function( $ ) {
4
+ $( "textarea.js" ).each( function() {
5
+ CodeMirror.fromTextArea( this, { lineNumbers: true, mode: "javascript" } );
6
+ });
7
+ $( "textarea.css" ).each( function() {
8
+ CodeMirror.fromTextArea( this, { lineNumbers: true, mode: "css" } );
9
+ });
10
+ });
js/settings-page.js DELETED
@@ -1,18 +0,0 @@
1
- // Options JavaScript
2
-
3
- jQuery( document ).ready( function( $ ) {
4
- var theme = codemirror_options.theme ? codemirror_options.theme: 'default';
5
- var editor = CodeMirror.fromTextArea(document.getElementById("codemirror_demo"), {
6
- lineNumbers: true,
7
- matchBrackets: true,
8
- mode: "application/x-httpd-php",
9
- indentUnit: 4,
10
- indentWithTabs: true,
11
- enterMode: "keep",
12
- tabMode: "shift",
13
- theme: theme
14
- });
15
- $('input[name="SnS_options[cm_theme]"]').change( function(){
16
- editor.setOption("theme", $(this).val());
17
- });
18
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
languages/scripts-n-styles.pot DELETED
@@ -1,398 +0,0 @@
1
- # Copyright (C) 2010 Scripts n Styles
2
- # This file is distributed under the same license as the Scripts n Styles package.
3
- msgid ""
4
- msgstr ""
5
- "Project-Id-Version: Scripts n Styles 3.0\n"
6
- "Report-Msgid-Bugs-To: http://wordpress.org/tag/scripts-n-styles\n"
7
- "POT-Creation-Date: 2011-12-09 20:46:53+00:00\n"
8
- "MIME-Version: 1.0\n"
9
- "Content-Type: text/plain; charset=UTF-8\n"
10
- "Content-Transfer-Encoding: 8bit\n"
11
- "PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n"
12
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
- "Language-Team: LANGUAGE <LL@li.org>\n"
14
-
15
- #. #-#-#-#-# plugin.pot (Scripts n Styles 3.0) #-#-#-#-#
16
- #. Plugin Name of the plugin/theme
17
- #: includes/class.SnS_Admin_Meta_Box.php:97
18
- #: includes/class.SnS_Settings_Page.php:22
19
- #: includes/class.SnS_Usage_Page.php:22 includes/class.SnS_Global_Page.php:18
20
- #: includes/class.SnS_Global_Page.php:20 includes/class.SnS_Admin.php:64
21
- #: includes/class.SnS_Admin.php:67 includes/class.SnS_Admin.php:70
22
- #: includes/class.SnS_Admin.php:106 includes/class.SnS_Admin.php:126
23
- msgid "Scripts n Styles"
24
- msgstr ""
25
-
26
- #: includes/class.SnS_Admin_Meta_Box.php:133
27
- #: includes/class.SnS_List_Usage.php:23
28
- msgid "Scripts"
29
- msgstr ""
30
-
31
- #: includes/class.SnS_Admin_Meta_Box.php:134
32
- #: includes/class.SnS_List_Usage.php:34
33
- msgid "Styles"
34
- msgstr ""
35
-
36
- #: includes/class.SnS_Admin_Meta_Box.php:135
37
- #: includes/class.SnS_Admin_Meta_Box.php:156
38
- msgid "Classes"
39
- msgstr ""
40
-
41
- #: includes/class.SnS_Admin_Meta_Box.php:136
42
- msgid "Include Scripts"
43
- msgstr ""
44
-
45
- #: includes/class.SnS_Admin_Meta_Box.php:140
46
- msgid ""
47
- "This code will be included <strong>verbatim</strong> in <code>&lt;script></"
48
- "code> tags at the end of your page's (or post's)"
49
- msgstr ""
50
-
51
- #: includes/class.SnS_Admin_Meta_Box.php:141
52
- msgid "<strong>Scripts</strong> (for the <code>head</code> element):"
53
- msgstr ""
54
-
55
- #: includes/class.SnS_Admin_Meta_Box.php:143
56
- #: includes/class.SnS_Admin_Meta_Box.php:146
57
- msgid "tag"
58
- msgstr ""
59
-
60
- #: includes/class.SnS_Admin_Meta_Box.php:150
61
- msgid "<strong>Styles</strong>:"
62
- msgstr ""
63
-
64
- #: includes/class.SnS_Admin_Meta_Box.php:152
65
- msgid ""
66
- "This code will be included <strong>verbatim</strong> in <code>&lt;style></"
67
- "code> tags in the <code>&lt;head></code> tag of your page (or post)."
68
- msgstr ""
69
-
70
- #: includes/class.SnS_Admin_Meta_Box.php:159
71
- msgid "<strong>Body Classes</strong>:"
72
- msgstr ""
73
-
74
- #: includes/class.SnS_Admin_Meta_Box.php:162
75
- #: includes/class.SnS_Admin_Meta_Box.php:168
76
- msgid "Standard:"
77
- msgstr ""
78
-
79
- #: includes/class.SnS_Admin_Meta_Box.php:170
80
- msgid ""
81
- "These <strong>space separated</strong> class names will be added to the "
82
- "<code>body_class()</code> or <code>post_class()</code> function (provided "
83
- "your theme uses these functions)."
84
- msgstr ""
85
-
86
- #: includes/class.SnS_Admin_Meta_Box.php:179
87
- msgid "The Styles Dropdown"
88
- msgstr ""
89
-
90
- #: includes/class.SnS_Admin_Meta_Box.php:181
91
- msgid "Add (or update) a class for the \"Styles\" drop-down:"
92
- msgstr ""
93
-
94
- #: includes/class.SnS_Admin_Meta_Box.php:183
95
- msgid "Title:"
96
- msgstr ""
97
-
98
- #: includes/class.SnS_Admin_Meta_Box.php:188
99
- msgid "Type:"
100
- msgstr ""
101
-
102
- #: includes/class.SnS_Admin_Meta_Box.php:190
103
- msgctxt "css type"
104
- msgid "Inline"
105
- msgstr ""
106
-
107
- #: includes/class.SnS_Admin_Meta_Box.php:191
108
- msgctxt "css type"
109
- msgid "Block"
110
- msgstr ""
111
-
112
- #: includes/class.SnS_Admin_Meta_Box.php:192
113
- msgctxt "css type"
114
- msgid "Selector:"
115
- msgstr ""
116
-
117
- #: includes/class.SnS_Admin_Meta_Box.php:196
118
- msgid "Element:"
119
- msgstr ""
120
-
121
- #: includes/class.SnS_Admin_Meta_Box.php:201
122
- msgid "Classes:"
123
- msgstr ""
124
-
125
- #: includes/class.SnS_Admin_Meta_Box.php:206
126
- msgid "Wrapper:"
127
- msgstr ""
128
-
129
- #: includes/class.SnS_Admin_Meta_Box.php:212
130
- msgid "Classes currently in the dropdown:"
131
- msgstr ""
132
-
133
- #: includes/class.SnS_Admin_Meta_Box.php:232
134
- msgid "Currently Enqueued Scripts:"
135
- msgstr ""
136
-
137
- #: includes/class.SnS_Admin_Meta_Box.php:236
138
- msgid ""
139
- "The chosen scripts will be enqueued and placed before your codes if your "
140
- "code is dependant on certain scripts (like jQuery)."
141
- msgstr ""
142
-
143
- #: includes/class.SnS_Admin_Meta_Box.php:247
144
- msgid "(plus others once saved.)"
145
- msgstr ""
146
-
147
- #: includes/class.SnS_Settings_Page.php:22 includes/class.SnS_Admin.php:91
148
- #: includes/class.SnS_Admin.php:202
149
- msgid "Settings"
150
- msgstr ""
151
-
152
- #: includes/class.SnS_Settings_Page.php:77
153
- msgid "Scripts n Styles Settings"
154
- msgstr ""
155
-
156
- #: includes/class.SnS_Settings_Page.php:83
157
- msgid "<strong>Menu Position</strong>: "
158
- msgstr ""
159
-
160
- #: includes/class.SnS_Settings_Page.php:97
161
- msgid "<strong>CodeMirror Theme</strong>: "
162
- msgstr ""
163
-
164
- #: includes/class.SnS_Settings_Page.php:111
165
- msgid "<strong>Hide Metabox by default</strong>: "
166
- msgstr ""
167
-
168
- #: includes/class.SnS_Settings_Page.php:120
169
- msgid "Hide Metabox by default"
170
- msgstr ""
171
-
172
- #: includes/class.SnS_Settings_Page.php:121
173
- msgid ""
174
- "<span class=\"description\" style=\"max-width: 500px; display: inline-block;"
175
- "\">This is overridable via Screen Options on each edit screen.</span>"
176
- msgstr ""
177
-
178
- #: includes/class.SnS_Settings_Page.php:126
179
- msgid "Code Mirror Demo"
180
- msgstr ""
181
-
182
- #: includes/class.SnS_Settings_Page.php:138
183
- msgid ""
184
- "Control how and where Scripts n Styles menus and metaboxes appear. These "
185
- "options are here because sometimes users really care about this stuff. Feel "
186
- "free to adjust to your liking. :-)"
187
- msgstr ""
188
-
189
- #: includes/class.SnS_List_Usage.php:20
190
- msgid "Scripts (head)"
191
- msgstr ""
192
-
193
- #: includes/class.SnS_List_Usage.php:26
194
- msgid "Enqueued Scripts"
195
- msgstr ""
196
-
197
- #: includes/class.SnS_List_Usage.php:31
198
- msgid "TinyMCE Formats"
199
- msgstr ""
200
-
201
- #: includes/class.SnS_List_Usage.php:37
202
- msgid "Post Classes"
203
- msgstr ""
204
-
205
- #: includes/class.SnS_List_Usage.php:40
206
- msgid "Body Classes"
207
- msgstr ""
208
-
209
- #: includes/class.SnS_List_Usage.php:50
210
- msgid "Edit &#8220;%s&#8221;"
211
- msgstr ""
212
-
213
- #: includes/class.SnS_List_Usage.php:53
214
- msgid "Edit"
215
- msgstr ""
216
-
217
- #: includes/class.SnS_List_Usage.php:75
218
- msgid "Title"
219
- msgstr ""
220
-
221
- #: includes/class.SnS_List_Usage.php:76
222
- msgid "ID"
223
- msgstr ""
224
-
225
- #: includes/class.SnS_List_Usage.php:77
226
- msgid "Status"
227
- msgstr ""
228
-
229
- #: includes/class.SnS_List_Usage.php:78
230
- msgid "Post Type"
231
- msgstr ""
232
-
233
- #: includes/class.SnS_List_Usage.php:79
234
- msgid "Script Data"
235
- msgstr ""
236
-
237
- #: includes/class.SnS_List_Usage.php:80
238
- msgid "Style Data"
239
- msgstr ""
240
-
241
- #: includes/class.SnS_List_Usage.php:133
242
- msgid "Password protected"
243
- msgstr ""
244
-
245
- #: includes/class.SnS_List_Usage.php:135
246
- msgid "Private"
247
- msgstr ""
248
-
249
- #: includes/class.SnS_List_Usage.php:137
250
- msgid "Draft"
251
- msgstr ""
252
-
253
- #. translators: post state
254
- #: includes/class.SnS_List_Usage.php:140
255
- msgctxt "post state"
256
- msgid "Pending"
257
- msgstr ""
258
-
259
- #: includes/class.SnS_List_Usage.php:142
260
- msgid "Sticky"
261
- msgstr ""
262
-
263
- #: includes/class.SnS_Usage_Page.php:22 includes/class.SnS_Admin.php:92
264
- msgid "Usage"
265
- msgstr ""
266
-
267
- #: includes/class.SnS_Usage_Page.php:47
268
- msgid "Per Page"
269
- msgstr ""
270
-
271
- #: includes/class.SnS_Usage_Page.php:54
272
- msgid "Scripts n Styles Usage"
273
- msgstr ""
274
-
275
- #: includes/class.SnS_Usage_Page.php:78
276
- msgid "The following table shows content that utilizes Scripts n Styles."
277
- msgstr ""
278
-
279
- #: includes/class.SnS_Global_Page.php:17 includes/class.SnS_Admin.php:90
280
- msgid "Global"
281
- msgstr ""
282
-
283
- #: includes/class.SnS_Global_Page.php:53
284
- msgid "Global Scripts n Styles"
285
- msgstr ""
286
-
287
- #: includes/class.SnS_Global_Page.php:59
288
- msgid "<strong>Scripts:</strong> "
289
- msgstr ""
290
-
291
- #: includes/class.SnS_Global_Page.php:70
292
- msgid ""
293
- "<span class=\"description\" style=\"max-width: 500px; display: inline-block;"
294
- "\">The \"Scripts\" will be included <strong>verbatim</strong> in <code>&lt;"
295
- "script></code> tags at the bottom of the <code>&lt;body></code> element of "
296
- "your html.</span>"
297
- msgstr ""
298
-
299
- #: includes/class.SnS_Global_Page.php:74
300
- msgid "<strong>Styles:</strong> "
301
- msgstr ""
302
-
303
- #: includes/class.SnS_Global_Page.php:85
304
- msgid ""
305
- "<span class=\"description\" style=\"max-width: 500px; display: inline-block;"
306
- "\">The \"Styles\" will be included <strong>verbatim</strong> in <code>&lt;"
307
- "style></code> tags in the <code>&lt;head></code> element of your html.</span>"
308
- msgstr ""
309
-
310
- #: includes/class.SnS_Global_Page.php:89
311
- msgid "<strong>Scripts</strong><br />(for the <code>head</code> element): "
312
- msgstr ""
313
-
314
- #: includes/class.SnS_Global_Page.php:100
315
- msgid ""
316
- "<span class=\"description\" style=\"max-width: 500px; display: inline-block;"
317
- "\">The \"Scripts (in head)\" will be included <strong>verbatim</strong> in "
318
- "<code>&lt;script></code> tags in the <code>&lt;head></code> element of your "
319
- "html.</span>"
320
- msgstr ""
321
-
322
- #: includes/class.SnS_Global_Page.php:104
323
- msgid "<strong>Enqueue Scripts</strong>: "
324
- msgstr ""
325
-
326
- #: includes/class.SnS_Global_Page.php:115
327
- msgid "Currently Enqueued Scripts: "
328
- msgstr ""
329
-
330
- #: includes/class.SnS_Global_Page.php:126
331
- msgid ""
332
- "Code entered here will be included in <em>every page (and post) of your "
333
- "site</em>, including the homepage and archives. The code will appear "
334
- "<strong>before</strong> Scripts and Styles registered individually."
335
- msgstr ""
336
-
337
- #: includes/class.SnS_Form.php:105
338
- msgid "Cheatin&#8217; uh?"
339
- msgstr ""
340
-
341
- #: includes/class.SnS_Form.php:108 includes/class.SnS_Form.php:135
342
- msgid "Settings saved."
343
- msgstr ""
344
-
345
- #: includes/class.SnS_Admin.php:109 includes/class.SnS_Admin.php:129
346
- msgid ""
347
- "<p>In default (non MultiSite) WordPress installs, both <em>Administrators</"
348
- "em> and \r\n"
349
- "\t\t\t\t\t\t<em>Editors</em> can access <em>Scripts-n-Styles</em> on "
350
- "individual edit screens. \r\n"
351
- "\t\t\t\t\t\tOnly <em>Administrators</em> can access this Options Page. In "
352
- "MultiSite WordPress installs, only \r\n"
353
- "\t\t\t\t\t\t<em>\"Super Admin\"</em> users can access either\r\n"
354
- "\t\t\t\t\t\t<em>Scripts-n-Styles</em> on individual edit screens or this "
355
- "Options Page. If other plugins change \r\n"
356
- "\t\t\t\t\t\tcapabilities (specifically \"unfiltered_html\"), \r\n"
357
- "\t\t\t\t\t\tother users can be granted access.</p>"
358
- msgstr ""
359
-
360
- #: includes/class.SnS_Admin.php:119
361
- msgid "For more information:"
362
- msgstr ""
363
-
364
- #: includes/class.SnS_Admin.php:120
365
- msgid ""
366
- "<a href=\"http://wordpress.org/extend/plugins/scripts-n-styles/faq/\" target="
367
- "\"_blank\">Frequently Asked Questions</a>"
368
- msgstr ""
369
-
370
- #: includes/class.SnS_Admin.php:121
371
- msgid ""
372
- "<a href=\"https://github.com/unFocus/Scripts-n-Styles\" target=\"_blank"
373
- "\">Source on github</a>"
374
- msgstr ""
375
-
376
- #: includes/class.SnS_Admin.php:122
377
- msgid ""
378
- "<a href=\"http://wordpress.org/tags/scripts-n-styles\" target=\"_blank"
379
- "\">Support Forums</a>"
380
- msgstr ""
381
-
382
- #. Plugin URI of the plugin/theme
383
- msgid "http://www.unfocus.com/projects/scripts-n-styles/"
384
- msgstr ""
385
-
386
- #. Description of the plugin/theme
387
- msgid ""
388
- "Allows WordPress admin users the ability to add custom CSS and JavaScript "
389
- "directly to individual Post, Pages or custom post types."
390
- msgstr ""
391
-
392
- #. Author of the plugin/theme
393
- msgid "unFocus Projects"
394
- msgstr ""
395
-
396
- #. Author URI of the plugin/theme
397
- msgid "http://www.unfocus.com/"
398
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/lib/codemirror.css DELETED
@@ -1,126 +0,0 @@
1
- .CodeMirror {
2
- line-height: 1em;
3
- font-family: monospace;
4
- }
5
-
6
- .CodeMirror-scroll {
7
- overflow: auto;
8
- height: 300px;
9
- /* This is needed to prevent an IE[67] bug where the scrolled content
10
- is visible outside of the scrolling box. */
11
- position: relative;
12
- outline: none;
13
- }
14
-
15
- .CodeMirror-gutter {
16
- position: absolute; left: 0; top: 0;
17
- z-index: 10;
18
- background-color: #f7f7f7;
19
- border-right: 1px solid #eee;
20
- min-width: 2em;
21
- height: 100%;
22
- }
23
- .CodeMirror-gutter-text {
24
- color: #aaa;
25
- text-align: right;
26
- padding: .4em .2em .4em .4em;
27
- white-space: pre !important;
28
- }
29
- .CodeMirror-lines {
30
- padding: .4em;
31
- white-space: pre;
32
- }
33
-
34
- .CodeMirror pre {
35
- -moz-border-radius: 0;
36
- -webkit-border-radius: 0;
37
- -o-border-radius: 0;
38
- border-radius: 0;
39
- border-width: 0; margin: 0; padding: 0; background: transparent;
40
- font-family: inherit;
41
- font-size: inherit;
42
- padding: 0; margin: 0;
43
- white-space: pre;
44
- word-wrap: normal;
45
- line-height: inherit;
46
- color: inherit;
47
- }
48
-
49
- .CodeMirror-wrap pre {
50
- word-wrap: break-word;
51
- white-space: pre-wrap;
52
- word-break: normal;
53
- }
54
- .CodeMirror-wrap .CodeMirror-scroll {
55
- overflow-x: hidden;
56
- }
57
-
58
- .CodeMirror textarea {
59
- outline: none !important;
60
- }
61
-
62
- .CodeMirror pre.CodeMirror-cursor {
63
- z-index: 10;
64
- position: absolute;
65
- visibility: hidden;
66
- border-left: 1px solid black;
67
- border-right: none;
68
- width: 0;
69
- }
70
- .cm-keymap-fat-cursor pre.CodeMirror-cursor {
71
- width: auto;
72
- border: 0;
73
- background: transparent;
74
- background: rgba(0, 200, 0, .4);
75
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#6600c800, endColorstr=#4c00c800);
76
- }
77
- /* Kludge to turn off filter in ie9+, which also accepts rgba */
78
- .cm-keymap-fat-cursor pre.CodeMirror-cursor:not(#nonsense_id) {
79
- filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
80
- }
81
- .CodeMirror pre.CodeMirror-cursor.CodeMirror-overwrite {}
82
- .CodeMirror-focused pre.CodeMirror-cursor {
83
- visibility: visible;
84
- }
85
-
86
- div.CodeMirror-selected { background: #d9d9d9; }
87
- .CodeMirror-focused div.CodeMirror-selected { background: #d7d4f0; }
88
-
89
- .CodeMirror-searching {
90
- background: #ffa;
91
- background: rgba(255, 255, 0, .4);
92
- }
93
-
94
- /* Default theme */
95
-
96
- .cm-s-default span.cm-keyword {color: #708;}
97
- .cm-s-default span.cm-atom {color: #219;}
98
- .cm-s-default span.cm-number {color: #164;}
99
- .cm-s-default span.cm-def {color: #00f;}
100
- .cm-s-default span.cm-variable {color: black;}
101
- .cm-s-default span.cm-variable-2 {color: #05a;}
102
- .cm-s-default span.cm-variable-3 {color: #085;}
103
- .cm-s-default span.cm-property {color: black;}
104
- .cm-s-default span.cm-operator {color: black;}
105
- .cm-s-default span.cm-comment {color: #a50;}
106
- .cm-s-default span.cm-string {color: #a11;}
107
- .cm-s-default span.cm-string-2 {color: #f50;}
108
- .cm-s-default span.cm-meta {color: #555;}
109
- .cm-s-default span.cm-error {color: #f00;}
110
- .cm-s-default span.cm-qualifier {color: #555;}
111
- .cm-s-default span.cm-builtin {color: #30a;}
112
- .cm-s-default span.cm-bracket {color: #cc7;}
113
- .cm-s-default span.cm-tag {color: #170;}
114
- .cm-s-default span.cm-attribute {color: #00c;}
115
- .cm-s-default span.cm-header {color: blue;}
116
- .cm-s-default span.cm-quote {color: #090;}
117
- .cm-s-default span.cm-hr {color: #999;}
118
- .cm-s-default span.cm-link {color: #00c;}
119
-
120
- span.cm-header, span.cm-strong {font-weight: bold;}
121
- span.cm-em {font-style: italic;}
122
- span.cm-emstrong {font-style: italic; font-weight: bold;}
123
- span.cm-link {text-decoration: underline;}
124
-
125
- div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
126
- div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/lib/codemirror.js DELETED
@@ -1,3062 +0,0 @@
1
- // All functions that need access to the editor's state live inside
2
- // the CodeMirror function. Below that, at the bottom of the file,
3
- // some utilities are defined.
4
-
5
- // CodeMirror is the only global var we claim
6
- var CodeMirror = (function() {
7
- // This is the function that produces an editor instance. Its
8
- // closure is used to store the editor state.
9
- function CodeMirror(place, givenOptions) {
10
- // Determine effective options based on given values and defaults.
11
- var options = {}, defaults = CodeMirror.defaults;
12
- for (var opt in defaults)
13
- if (defaults.hasOwnProperty(opt))
14
- options[opt] = (givenOptions && givenOptions.hasOwnProperty(opt) ? givenOptions : defaults)[opt];
15
-
16
- // The element in which the editor lives.
17
- var wrapper = document.createElement("div");
18
- wrapper.className = "CodeMirror" + (options.lineWrapping ? " CodeMirror-wrap" : "");
19
- // This mess creates the base DOM structure for the editor.
20
- wrapper.innerHTML =
21
- '<div style="overflow: hidden; position: relative; width: 3px; height: 0px;">' + // Wraps and hides input textarea
22
- '<textarea style="position: absolute; padding: 0; width: 1px; height: 1em" wrap="off" ' +
23
- 'autocorrect="off" autocapitalize="off"></textarea></div>' +
24
- '<div class="CodeMirror-scroll" tabindex="-1">' +
25
- '<div style="position: relative">' + // Set to the height of the text, causes scrolling
26
- '<div style="position: relative">' + // Moved around its parent to cover visible view
27
- '<div class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div>' +
28
- // Provides positioning relative to (visible) text origin
29
- '<div class="CodeMirror-lines"><div style="position: relative; z-index: 0">' +
30
- '<div style="position: absolute; width: 100%; height: 0; overflow: hidden; visibility: hidden;"></div>' +
31
- '<pre class="CodeMirror-cursor">&#160;</pre>' + // Absolutely positioned blinky cursor
32
- '<div style="position: relative; z-index: -1"></div><div></div>' + // DIVs containing the selection and the actual code
33
- '</div></div></div></div></div>';
34
- if (place.appendChild) place.appendChild(wrapper); else place(wrapper);
35
- // I've never seen more elegant code in my life.
36
- var inputDiv = wrapper.firstChild, input = inputDiv.firstChild,
37
- scroller = wrapper.lastChild, code = scroller.firstChild,
38
- mover = code.firstChild, gutter = mover.firstChild, gutterText = gutter.firstChild,
39
- lineSpace = gutter.nextSibling.firstChild, measure = lineSpace.firstChild,
40
- cursor = measure.nextSibling, selectionDiv = cursor.nextSibling,
41
- lineDiv = selectionDiv.nextSibling;
42
- themeChanged(); keyMapChanged();
43
- // Needed to hide big blue blinking cursor on Mobile Safari
44
- if (ios) input.style.width = "0px";
45
- if (!webkit) lineSpace.draggable = true;
46
- lineSpace.style.outline = "none";
47
- if (options.tabindex != null) input.tabIndex = options.tabindex;
48
- if (options.autofocus) focusInput();
49
- if (!options.gutter && !options.lineNumbers) gutter.style.display = "none";
50
- // Needed to handle Tab key in KHTML
51
- if (khtml) inputDiv.style.height = "1px", inputDiv.style.position = "absolute";
52
-
53
- // Check for problem with IE innerHTML not working when we have a
54
- // P (or similar) parent node.
55
- try { stringWidth("x"); }
56
- catch (e) {
57
- if (e.message.match(/runtime/i))
58
- e = new Error("A CodeMirror inside a P-style element does not work in Internet Explorer. (innerHTML bug)");
59
- throw e;
60
- }
61
-
62
- // Delayed object wrap timeouts, making sure only one is active. blinker holds an interval.
63
- var poll = new Delayed(), highlight = new Delayed(), blinker;
64
-
65
- // mode holds a mode API object. doc is the tree of Line objects,
66
- // work an array of lines that should be parsed, and history the
67
- // undo history (instance of History constructor).
68
- var mode, doc = new BranchChunk([new LeafChunk([new Line("")])]), work, focused;
69
- loadMode();
70
- // The selection. These are always maintained to point at valid
71
- // positions. Inverted is used to remember that the user is
72
- // selecting bottom-to-top.
73
- var sel = {from: {line: 0, ch: 0}, to: {line: 0, ch: 0}, inverted: false};
74
- // Selection-related flags. shiftSelecting obviously tracks
75
- // whether the user is holding shift.
76
- var shiftSelecting, lastClick, lastDoubleClick, lastScrollPos = 0, draggingText,
77
- overwrite = false, suppressEdits = false;
78
- // Variables used by startOperation/endOperation to track what
79
- // happened during the operation.
80
- var updateInput, userSelChange, changes, textChanged, selectionChanged, leaveInputAlone,
81
- gutterDirty, callbacks;
82
- // Current visible range (may be bigger than the view window).
83
- var displayOffset = 0, showingFrom = 0, showingTo = 0, lastSizeC = 0;
84
- // bracketHighlighted is used to remember that a bracket has been
85
- // marked.
86
- var bracketHighlighted;
87
- // Tracks the maximum line length so that the horizontal scrollbar
88
- // can be kept static when scrolling.
89
- var maxLine = "", maxWidth;
90
- var tabCache = {};
91
-
92
- // Initialize the content.
93
- operation(function(){setValue(options.value || ""); updateInput = false;})();
94
- var history = new History();
95
-
96
- // Register our event handlers.
97
- connect(scroller, "mousedown", operation(onMouseDown));
98
- connect(scroller, "dblclick", operation(onDoubleClick));
99
- connect(lineSpace, "selectstart", e_preventDefault);
100
- // Gecko browsers fire contextmenu *after* opening the menu, at
101
- // which point we can't mess with it anymore. Context menu is
102
- // handled in onMouseDown for Gecko.
103
- if (!gecko) connect(scroller, "contextmenu", onContextMenu);
104
- connect(scroller, "scroll", function() {
105
- lastScrollPos = scroller.scrollTop;
106
- updateDisplay([]);
107
- if (options.fixedGutter) gutter.style.left = scroller.scrollLeft + "px";
108
- if (options.onScroll) options.onScroll(instance);
109
- });
110
- connect(window, "resize", function() {updateDisplay(true);});
111
- connect(input, "keyup", operation(onKeyUp));
112
- connect(input, "input", fastPoll);
113
- connect(input, "keydown", operation(onKeyDown));
114
- connect(input, "keypress", operation(onKeyPress));
115
- connect(input, "focus", onFocus);
116
- connect(input, "blur", onBlur);
117
-
118
- if (options.dragDrop) {
119
- connect(lineSpace, "dragstart", onDragStart);
120
- function drag_(e) {
121
- if (options.onDragEvent && options.onDragEvent(instance, addStop(e))) return;
122
- e_stop(e);
123
- }
124
- connect(scroller, "dragenter", drag_);
125
- connect(scroller, "dragover", drag_);
126
- connect(scroller, "drop", operation(onDrop));
127
- }
128
- connect(scroller, "paste", function(){focusInput(); fastPoll();});
129
- connect(input, "paste", fastPoll);
130
- connect(input, "cut", operation(function(){
131
- if (!options.readOnly) replaceSelection("");
132
- }));
133
-
134
- // Needed to handle Tab key in KHTML
135
- if (khtml) connect(code, "mouseup", function() {
136
- if (document.activeElement == input) input.blur();
137
- focusInput();
138
- });
139
-
140
- // IE throws unspecified error in certain cases, when
141
- // trying to access activeElement before onload
142
- var hasFocus; try { hasFocus = (document.activeElement == input); } catch(e) { }
143
- if (hasFocus || options.autofocus) setTimeout(onFocus, 20);
144
- else onBlur();
145
-
146
- function isLine(l) {return l >= 0 && l < doc.size;}
147
- // The instance object that we'll return. Mostly calls out to
148
- // local functions in the CodeMirror function. Some do some extra
149
- // range checking and/or clipping. operation is used to wrap the
150
- // call so that changes it makes are tracked, and the display is
151
- // updated afterwards.
152
- var instance = wrapper.CodeMirror = {
153
- getValue: getValue,
154
- setValue: operation(setValue),
155
- getSelection: getSelection,
156
- replaceSelection: operation(replaceSelection),
157
- focus: function(){window.focus(); focusInput(); onFocus(); fastPoll();},
158
- setOption: function(option, value) {
159
- var oldVal = options[option];
160
- options[option] = value;
161
- if (option == "mode" || option == "indentUnit") loadMode();
162
- else if (option == "readOnly" && value == "nocursor") {onBlur(); input.blur();}
163
- else if (option == "readOnly" && !value) {resetInput(true);}
164
- else if (option == "theme") themeChanged();
165
- else if (option == "lineWrapping" && oldVal != value) operation(wrappingChanged)();
166
- else if (option == "tabSize") updateDisplay(true);
167
- else if (option == "keyMap") keyMapChanged();
168
- if (option == "lineNumbers" || option == "gutter" || option == "firstLineNumber" || option == "theme") {
169
- gutterChanged();
170
- updateDisplay(true);
171
- }
172
- },
173
- getOption: function(option) {return options[option];},
174
- undo: operation(undo),
175
- redo: operation(redo),
176
- indentLine: operation(function(n, dir) {
177
- if (typeof dir != "string") {
178
- if (dir == null) dir = options.smartIndent ? "smart" : "prev";
179
- else dir = dir ? "add" : "subtract";
180
- }
181
- if (isLine(n)) indentLine(n, dir);
182
- }),
183
- indentSelection: operation(indentSelected),
184
- historySize: function() {return {undo: history.done.length, redo: history.undone.length};},
185
- clearHistory: function() {history = new History();},
186
- matchBrackets: operation(function(){matchBrackets(true);}),
187
- getTokenAt: operation(function(pos) {
188
- pos = clipPos(pos);
189
- return getLine(pos.line).getTokenAt(mode, getStateBefore(pos.line), pos.ch);
190
- }),
191
- getStateAfter: function(line) {
192
- line = clipLine(line == null ? doc.size - 1: line);
193
- return getStateBefore(line + 1);
194
- },
195
- cursorCoords: function(start, mode) {
196
- if (start == null) start = sel.inverted;
197
- return this.charCoords(start ? sel.from : sel.to, mode);
198
- },
199
- charCoords: function(pos, mode) {
200
- pos = clipPos(pos);
201
- if (mode == "local") return localCoords(pos, false);
202
- if (mode == "div") return localCoords(pos, true);
203
- return pageCoords(pos);
204
- },
205
- coordsChar: function(coords) {
206
- var off = eltOffset(lineSpace);
207
- return coordsChar(coords.x - off.left, coords.y - off.top);
208
- },
209
- markText: operation(markText),
210
- setBookmark: setBookmark,
211
- findMarksAt: findMarksAt,
212
- setMarker: operation(addGutterMarker),
213
- clearMarker: operation(removeGutterMarker),
214
- setLineClass: operation(setLineClass),
215
- hideLine: operation(function(h) {return setLineHidden(h, true);}),
216
- showLine: operation(function(h) {return setLineHidden(h, false);}),
217
- onDeleteLine: function(line, f) {
218
- if (typeof line == "number") {
219
- if (!isLine(line)) return null;
220
- line = getLine(line);
221
- }
222
- (line.handlers || (line.handlers = [])).push(f);
223
- return line;
224
- },
225
- lineInfo: lineInfo,
226
- addWidget: function(pos, node, scroll, vert, horiz) {
227
- pos = localCoords(clipPos(pos));
228
- var top = pos.yBot, left = pos.x;
229
- node.style.position = "absolute";
230
- code.appendChild(node);
231
- if (vert == "over") top = pos.y;
232
- else if (vert == "near") {
233
- var vspace = Math.max(scroller.offsetHeight, doc.height * textHeight()),
234
- hspace = Math.max(code.clientWidth, lineSpace.clientWidth) - paddingLeft();
235
- if (pos.yBot + node.offsetHeight > vspace && pos.y > node.offsetHeight)
236
- top = pos.y - node.offsetHeight;
237
- if (left + node.offsetWidth > hspace)
238
- left = hspace - node.offsetWidth;
239
- }
240
- node.style.top = (top + paddingTop()) + "px";
241
- node.style.left = node.style.right = "";
242
- if (horiz == "right") {
243
- left = code.clientWidth - node.offsetWidth;
244
- node.style.right = "0px";
245
- } else {
246
- if (horiz == "left") left = 0;
247
- else if (horiz == "middle") left = (code.clientWidth - node.offsetWidth) / 2;
248
- node.style.left = (left + paddingLeft()) + "px";
249
- }
250
- if (scroll)
251
- scrollIntoView(left, top, left + node.offsetWidth, top + node.offsetHeight);
252
- },
253
-
254
- lineCount: function() {return doc.size;},
255
- clipPos: clipPos,
256
- getCursor: function(start) {
257
- if (start == null) start = sel.inverted;
258
- return copyPos(start ? sel.from : sel.to);
259
- },
260
- somethingSelected: function() {return !posEq(sel.from, sel.to);},
261
- setCursor: operation(function(line, ch, user) {
262
- if (ch == null && typeof line.line == "number") setCursor(line.line, line.ch, user);
263
- else setCursor(line, ch, user);
264
- }),
265
- setSelection: operation(function(from, to, user) {
266
- (user ? setSelectionUser : setSelection)(clipPos(from), clipPos(to || from));
267
- }),
268
- getLine: function(line) {if (isLine(line)) return getLine(line).text;},
269
- getLineHandle: function(line) {if (isLine(line)) return getLine(line);},
270
- setLine: operation(function(line, text) {
271
- if (isLine(line)) replaceRange(text, {line: line, ch: 0}, {line: line, ch: getLine(line).text.length});
272
- }),
273
- removeLine: operation(function(line) {
274
- if (isLine(line)) replaceRange("", {line: line, ch: 0}, clipPos({line: line+1, ch: 0}));
275
- }),
276
- replaceRange: operation(replaceRange),
277
- getRange: function(from, to) {return getRange(clipPos(from), clipPos(to));},
278
-
279
- triggerOnKeyDown: operation(onKeyDown),
280
- execCommand: function(cmd) {return commands[cmd](instance);},
281
- // Stuff used by commands, probably not much use to outside code.
282
- moveH: operation(moveH),
283
- deleteH: operation(deleteH),
284
- moveV: operation(moveV),
285
- toggleOverwrite: function() {
286
- if(overwrite){
287
- overwrite = false;
288
- cursor.className = cursor.className.replace(" CodeMirror-overwrite", "");
289
- } else {
290
- overwrite = true;
291
- cursor.className += " CodeMirror-overwrite";
292
- }
293
- },
294
-
295
- posFromIndex: function(off) {
296
- var lineNo = 0, ch;
297
- doc.iter(0, doc.size, function(line) {
298
- var sz = line.text.length + 1;
299
- if (sz > off) { ch = off; return true; }
300
- off -= sz;
301
- ++lineNo;
302
- });
303
- return clipPos({line: lineNo, ch: ch});
304
- },
305
- indexFromPos: function (coords) {
306
- if (coords.line < 0 || coords.ch < 0) return 0;
307
- var index = coords.ch;
308
- doc.iter(0, coords.line, function (line) {
309
- index += line.text.length + 1;
310
- });
311
- return index;
312
- },
313
- scrollTo: function(x, y) {
314
- if (x != null) scroller.scrollLeft = x;
315
- if (y != null) scroller.scrollTop = y;
316
- updateDisplay([]);
317
- },
318
-
319
- operation: function(f){return operation(f)();},
320
- compoundChange: function(f){return compoundChange(f);},
321
- refresh: function(){
322
- updateDisplay(true);
323
- if (scroller.scrollHeight > lastScrollPos)
324
- scroller.scrollTop = lastScrollPos;
325
- },
326
- getInputField: function(){return input;},
327
- getWrapperElement: function(){return wrapper;},
328
- getScrollerElement: function(){return scroller;},
329
- getGutterElement: function(){return gutter;}
330
- };
331
-
332
- function getLine(n) { return getLineAt(doc, n); }
333
- function updateLineHeight(line, height) {
334
- gutterDirty = true;
335
- var diff = height - line.height;
336
- for (var n = line; n; n = n.parent) n.height += diff;
337
- }
338
-
339
- function setValue(code) {
340
- var top = {line: 0, ch: 0};
341
- updateLines(top, {line: doc.size - 1, ch: getLine(doc.size-1).text.length},
342
- splitLines(code), top, top);
343
- updateInput = true;
344
- }
345
- function getValue() {
346
- var text = [];
347
- doc.iter(0, doc.size, function(line) { text.push(line.text); });
348
- return text.join("\n");
349
- }
350
-
351
- function onMouseDown(e) {
352
- setShift(e_prop(e, "shiftKey"));
353
- // Check whether this is a click in a widget
354
- for (var n = e_target(e); n != wrapper; n = n.parentNode)
355
- if (n.parentNode == code && n != mover) return;
356
-
357
- // See if this is a click in the gutter
358
- for (var n = e_target(e); n != wrapper; n = n.parentNode)
359
- if (n.parentNode == gutterText) {
360
- if (options.onGutterClick)
361
- options.onGutterClick(instance, indexOf(gutterText.childNodes, n) + showingFrom, e);
362
- return e_preventDefault(e);
363
- }
364
-
365
- var start = posFromMouse(e);
366
-
367
- switch (e_button(e)) {
368
- case 3:
369
- if (gecko && !mac) onContextMenu(e);
370
- return;
371
- case 2:
372
- if (start) setCursor(start.line, start.ch, true);
373
- setTimeout(focusInput, 20);
374
- return;
375
- }
376
- // For button 1, if it was clicked inside the editor
377
- // (posFromMouse returning non-null), we have to adjust the
378
- // selection.
379
- if (!start) {if (e_target(e) == scroller) e_preventDefault(e); return;}
380
-
381
- if (!focused) onFocus();
382
-
383
- var now = +new Date;
384
- if (lastDoubleClick && lastDoubleClick.time > now - 400 && posEq(lastDoubleClick.pos, start)) {
385
- e_preventDefault(e);
386
- setTimeout(focusInput, 20);
387
- return selectLine(start.line);
388
- } else if (lastClick && lastClick.time > now - 400 && posEq(lastClick.pos, start)) {
389
- lastDoubleClick = {time: now, pos: start};
390
- e_preventDefault(e);
391
- return selectWordAt(start);
392
- } else { lastClick = {time: now, pos: start}; }
393
-
394
- var last = start, going;
395
- if (options.dragDrop && dragAndDrop && !options.readOnly && !posEq(sel.from, sel.to) &&
396
- !posLess(start, sel.from) && !posLess(sel.to, start)) {
397
- // Let the drag handler handle this.
398
- if (webkit) lineSpace.draggable = true;
399
- function dragEnd(e2) {
400
- if (webkit) lineSpace.draggable = false;
401
- draggingText = false;
402
- up(); drop();
403
- if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
404
- e_preventDefault(e2);
405
- setCursor(start.line, start.ch, true);
406
- focusInput();
407
- }
408
- }
409
- var up = connect(document, "mouseup", operation(dragEnd), true);
410
- var drop = connect(scroller, "drop", operation(dragEnd), true);
411
- draggingText = true;
412
- // IE's approach to draggable
413
- if (lineSpace.dragDrop) lineSpace.dragDrop();
414
- return;
415
- }
416
- e_preventDefault(e);
417
- setCursor(start.line, start.ch, true);
418
-
419
- function extend(e) {
420
- var cur = posFromMouse(e, true);
421
- if (cur && !posEq(cur, last)) {
422
- if (!focused) onFocus();
423
- last = cur;
424
- setSelectionUser(start, cur);
425
- updateInput = false;
426
- var visible = visibleLines();
427
- if (cur.line >= visible.to || cur.line < visible.from)
428
- going = setTimeout(operation(function(){extend(e);}), 150);
429
- }
430
- }
431
-
432
- function done(e) {
433
- clearTimeout(going);
434
- var cur = posFromMouse(e);
435
- if (cur) setSelectionUser(start, cur);
436
- e_preventDefault(e);
437
- focusInput();
438
- updateInput = true;
439
- move(); up();
440
- }
441
- var move = connect(document, "mousemove", operation(function(e) {
442
- clearTimeout(going);
443
- e_preventDefault(e);
444
- if (!ie && !e_button(e)) done(e);
445
- else extend(e);
446
- }), true);
447
- var up = connect(document, "mouseup", operation(done), true);
448
- }
449
- function onDoubleClick(e) {
450
- for (var n = e_target(e); n != wrapper; n = n.parentNode)
451
- if (n.parentNode == gutterText) return e_preventDefault(e);
452
- var start = posFromMouse(e);
453
- if (!start) return;
454
- lastDoubleClick = {time: +new Date, pos: start};
455
- e_preventDefault(e);
456
- selectWordAt(start);
457
- }
458
- function onDrop(e) {
459
- if (options.onDragEvent && options.onDragEvent(instance, addStop(e))) return;
460
- e.preventDefault();
461
- var pos = posFromMouse(e, true), files = e.dataTransfer.files;
462
- if (!pos || options.readOnly) return;
463
- if (files && files.length && window.FileReader && window.File) {
464
- function loadFile(file, i) {
465
- var reader = new FileReader;
466
- reader.onload = function() {
467
- text[i] = reader.result;
468
- if (++read == n) {
469
- pos = clipPos(pos);
470
- operation(function() {
471
- var end = replaceRange(text.join(""), pos, pos);
472
- setSelectionUser(pos, end);
473
- })();
474
- }
475
- };
476
- reader.readAsText(file);
477
- }
478
- var n = files.length, text = Array(n), read = 0;
479
- for (var i = 0; i < n; ++i) loadFile(files[i], i);
480
- }
481
- else {
482
- try {
483
- var text = e.dataTransfer.getData("Text");
484
- if (text) {
485
- compoundChange(function() {
486
- var curFrom = sel.from, curTo = sel.to;
487
- setSelectionUser(pos, pos);
488
- if (draggingText) replaceRange("", curFrom, curTo);
489
- replaceSelection(text);
490
- focusInput();
491
- });
492
- }
493
- }
494
- catch(e){}
495
- }
496
- }
497
- function onDragStart(e) {
498
- var txt = getSelection();
499
- e.dataTransfer.setData("Text", txt);
500
-
501
- // Use dummy image instead of default browsers image.
502
- if (gecko || chrome) {
503
- var img = document.createElement('img');
504
- img.scr = 'data:image/gif;base64,R0lGODdhAgACAIAAAAAAAP///ywAAAAAAgACAAACAoRRADs='; //1x1 image
505
- e.dataTransfer.setDragImage(img, 0, 0);
506
- }
507
- }
508
-
509
- function doHandleBinding(bound, dropShift) {
510
- if (typeof bound == "string") {
511
- bound = commands[bound];
512
- if (!bound) return false;
513
- }
514
- var prevShift = shiftSelecting;
515
- try {
516
- if (options.readOnly) suppressEdits = true;
517
- if (dropShift) shiftSelecting = null;
518
- bound(instance);
519
- } catch(e) {
520
- if (e != Pass) throw e;
521
- return false;
522
- } finally {
523
- shiftSelecting = prevShift;
524
- suppressEdits = false;
525
- }
526
- return true;
527
- }
528
- function handleKeyBinding(e) {
529
- // Handle auto keymap transitions
530
- var startMap = getKeyMap(options.keyMap), next = startMap.auto;
531
- clearTimeout(maybeTransition);
532
- if (next && !isModifierKey(e)) maybeTransition = setTimeout(function() {
533
- if (getKeyMap(options.keyMap) == startMap) {
534
- options.keyMap = (next.call ? next.call(null, instance) : next);
535
- }
536
- }, 50);
537
-
538
- var name = keyNames[e_prop(e, "keyCode")], handled = false;
539
- if (name == null || e.altGraphKey) return false;
540
- if (e_prop(e, "altKey")) name = "Alt-" + name;
541
- if (e_prop(e, "ctrlKey")) name = "Ctrl-" + name;
542
- if (e_prop(e, "metaKey")) name = "Cmd-" + name;
543
-
544
- var stopped = false;
545
- function stop() { stopped = true; }
546
-
547
- if (e_prop(e, "shiftKey")) {
548
- handled = lookupKey("Shift-" + name, options.extraKeys, options.keyMap,
549
- function(b) {return doHandleBinding(b, true);}, stop)
550
- || lookupKey(name, options.extraKeys, options.keyMap, function(b) {
551
- if (typeof b == "string" && /^go[A-Z]/.test(b)) return doHandleBinding(b);
552
- }, stop);
553
- } else {
554
- handled = lookupKey(name, options.extraKeys, options.keyMap, doHandleBinding, stop);
555
- }
556
- if (stopped) handled = false;
557
- if (handled) {
558
- e_preventDefault(e);
559
- restartBlink();
560
- if (ie) { e.oldKeyCode = e.keyCode; e.keyCode = 0; }
561
- }
562
- return handled;
563
- }
564
- function handleCharBinding(e, ch) {
565
- var handled = lookupKey("'" + ch + "'", options.extraKeys,
566
- options.keyMap, function(b) { return doHandleBinding(b, true); });
567
- if (handled) {
568
- e_preventDefault(e);
569
- restartBlink();
570
- }
571
- return handled;
572
- }
573
-
574
- var lastStoppedKey = null, maybeTransition;
575
- function onKeyDown(e) {
576
- if (!focused) onFocus();
577
- if (ie && e.keyCode == 27) { e.returnValue = false; }
578
- if (pollingFast) { if (readInput()) pollingFast = false; }
579
- if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
580
- var code = e_prop(e, "keyCode");
581
- // IE does strange things with escape.
582
- setShift(code == 16 || e_prop(e, "shiftKey"));
583
- // First give onKeyEvent option a chance to handle this.
584
- var handled = handleKeyBinding(e);
585
- if (window.opera) {
586
- lastStoppedKey = handled ? code : null;
587
- // Opera has no cut event... we try to at least catch the key combo
588
- if (!handled && code == 88 && e_prop(e, mac ? "metaKey" : "ctrlKey"))
589
- replaceSelection("");
590
- }
591
- }
592
- function onKeyPress(e) {
593
- if (pollingFast) readInput();
594
- if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
595
- var keyCode = e_prop(e, "keyCode"), charCode = e_prop(e, "charCode");
596
- if (window.opera && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
597
- if (((window.opera && !e.which) || khtml) && handleKeyBinding(e)) return;
598
- var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
599
- if (options.electricChars && mode.electricChars && options.smartIndent && !options.readOnly) {
600
- if (mode.electricChars.indexOf(ch) > -1)
601
- setTimeout(operation(function() {indentLine(sel.to.line, "smart");}), 75);
602
- }
603
- if (handleCharBinding(e, ch)) return;
604
- fastPoll();
605
- }
606
- function onKeyUp(e) {
607
- if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
608
- if (e_prop(e, "keyCode") == 16) shiftSelecting = null;
609
- }
610
-
611
- function onFocus() {
612
- if (options.readOnly == "nocursor") return;
613
- if (!focused) {
614
- if (options.onFocus) options.onFocus(instance);
615
- focused = true;
616
- if (wrapper.className.search(/\bCodeMirror-focused\b/) == -1)
617
- wrapper.className += " CodeMirror-focused";
618
- if (!leaveInputAlone) resetInput(true);
619
- }
620
- slowPoll();
621
- restartBlink();
622
- }
623
- function onBlur() {
624
- if (focused) {
625
- if (options.onBlur) options.onBlur(instance);
626
- focused = false;
627
- if (bracketHighlighted)
628
- operation(function(){
629
- if (bracketHighlighted) { bracketHighlighted(); bracketHighlighted = null; }
630
- })();
631
- wrapper.className = wrapper.className.replace(" CodeMirror-focused", "");
632
- }
633
- clearInterval(blinker);
634
- setTimeout(function() {if (!focused) shiftSelecting = null;}, 150);
635
- }
636
-
637
- // Replace the range from from to to by the strings in newText.
638
- // Afterwards, set the selection to selFrom, selTo.
639
- function updateLines(from, to, newText, selFrom, selTo) {
640
- if (suppressEdits) return;
641
- if (history) {
642
- var old = [];
643
- doc.iter(from.line, to.line + 1, function(line) { old.push(line.text); });
644
- history.addChange(from.line, newText.length, old);
645
- while (history.done.length > options.undoDepth) history.done.shift();
646
- }
647
- updateLinesNoUndo(from, to, newText, selFrom, selTo);
648
- }
649
- function unredoHelper(from, to) {
650
- if (!from.length) return;
651
- var set = from.pop(), out = [];
652
- for (var i = set.length - 1; i >= 0; i -= 1) {
653
- var change = set[i];
654
- var replaced = [], end = change.start + change.added;
655
- doc.iter(change.start, end, function(line) { replaced.push(line.text); });
656
- out.push({start: change.start, added: change.old.length, old: replaced});
657
- var pos = clipPos({line: change.start + change.old.length - 1,
658
- ch: editEnd(replaced[replaced.length-1], change.old[change.old.length-1])});
659
- updateLinesNoUndo({line: change.start, ch: 0}, {line: end - 1, ch: getLine(end-1).text.length}, change.old, pos, pos);
660
- }
661
- updateInput = true;
662
- to.push(out);
663
- }
664
- function undo() {unredoHelper(history.done, history.undone);}
665
- function redo() {unredoHelper(history.undone, history.done);}
666
-
667
- function updateLinesNoUndo(from, to, newText, selFrom, selTo) {
668
- if (suppressEdits) return;
669
- var recomputeMaxLength = false, maxLineLength = maxLine.length;
670
- if (!options.lineWrapping)
671
- doc.iter(from.line, to.line + 1, function(line) {
672
- if (line.text.length == maxLineLength) {recomputeMaxLength = true; return true;}
673
- });
674
- if (from.line != to.line || newText.length > 1) gutterDirty = true;
675
-
676
- var nlines = to.line - from.line, firstLine = getLine(from.line), lastLine = getLine(to.line);
677
- // First adjust the line structure, taking some care to leave highlighting intact.
678
- if (from.ch == 0 && to.ch == 0 && newText[newText.length - 1] == "") {
679
- // This is a whole-line replace. Treated specially to make
680
- // sure line objects move the way they are supposed to.
681
- var added = [], prevLine = null;
682
- if (from.line) {
683
- prevLine = getLine(from.line - 1);
684
- prevLine.fixMarkEnds(lastLine);
685
- } else lastLine.fixMarkStarts();
686
- for (var i = 0, e = newText.length - 1; i < e; ++i)
687
- added.push(Line.inheritMarks(newText[i], prevLine));
688
- if (nlines) doc.remove(from.line, nlines, callbacks);
689
- if (added.length) doc.insert(from.line, added);
690
- } else if (firstLine == lastLine) {
691
- if (newText.length == 1)
692
- firstLine.replace(from.ch, to.ch, newText[0]);
693
- else {
694
- lastLine = firstLine.split(to.ch, newText[newText.length-1]);
695
- firstLine.replace(from.ch, null, newText[0]);
696
- firstLine.fixMarkEnds(lastLine);
697
- var added = [];
698
- for (var i = 1, e = newText.length - 1; i < e; ++i)
699
- added.push(Line.inheritMarks(newText[i], firstLine));
700
- added.push(lastLine);
701
- doc.insert(from.line + 1, added);
702
- }
703
- } else if (newText.length == 1) {
704
- firstLine.replace(from.ch, null, newText[0]);
705
- lastLine.replace(null, to.ch, "");
706
- firstLine.append(lastLine);
707
- doc.remove(from.line + 1, nlines, callbacks);
708
- } else {
709
- var added = [];
710
- firstLine.replace(from.ch, null, newText[0]);
711
- lastLine.replace(null, to.ch, newText[newText.length-1]);
712
- firstLine.fixMarkEnds(lastLine);
713
- for (var i = 1, e = newText.length - 1; i < e; ++i)
714
- added.push(Line.inheritMarks(newText[i], firstLine));
715
- if (nlines > 1) doc.remove(from.line + 1, nlines - 1, callbacks);
716
- doc.insert(from.line + 1, added);
717
- }
718
- if (options.lineWrapping) {
719
- var perLine = Math.max(5, scroller.clientWidth / charWidth() - 3);
720
- doc.iter(from.line, from.line + newText.length, function(line) {
721
- if (line.hidden) return;
722
- var guess = Math.ceil(line.text.length / perLine) || 1;
723
- if (guess != line.height) updateLineHeight(line, guess);
724
- });
725
- } else {
726
- doc.iter(from.line, from.line + newText.length, function(line) {
727
- var l = line.text;
728
- if (l.length > maxLineLength) {
729
- maxLine = l; maxLineLength = l.length; maxWidth = null;
730
- recomputeMaxLength = false;
731
- }
732
- });
733
- if (recomputeMaxLength) {
734
- maxLineLength = 0; maxLine = ""; maxWidth = null;
735
- doc.iter(0, doc.size, function(line) {
736
- var l = line.text;
737
- if (l.length > maxLineLength) {
738
- maxLineLength = l.length; maxLine = l;
739
- }
740
- });
741
- }
742
- }
743
-
744
- // Add these lines to the work array, so that they will be
745
- // highlighted. Adjust work lines if lines were added/removed.
746
- var newWork = [], lendiff = newText.length - nlines - 1;
747
- for (var i = 0, l = work.length; i < l; ++i) {
748
- var task = work[i];
749
- if (task < from.line) newWork.push(task);
750
- else if (task > to.line) newWork.push(task + lendiff);
751
- }
752
- var hlEnd = from.line + Math.min(newText.length, 500);
753
- highlightLines(from.line, hlEnd);
754
- newWork.push(hlEnd);
755
- work = newWork;
756
- startWorker(100);
757
- // Remember that these lines changed, for updating the display
758
- changes.push({from: from.line, to: to.line + 1, diff: lendiff});
759
- var changeObj = {from: from, to: to, text: newText};
760
- if (textChanged) {
761
- for (var cur = textChanged; cur.next; cur = cur.next) {}
762
- cur.next = changeObj;
763
- } else textChanged = changeObj;
764
-
765
- // Update the selection
766
- function updateLine(n) {return n <= Math.min(to.line, to.line + lendiff) ? n : n + lendiff;}
767
- setSelection(selFrom, selTo, updateLine(sel.from.line), updateLine(sel.to.line));
768
-
769
- // Make sure the scroll-size div has the correct height.
770
- if (scroller.clientHeight)
771
- code.style.height = (doc.height * textHeight() + 2 * paddingTop()) + "px";
772
- }
773
-
774
- function replaceRange(code, from, to) {
775
- from = clipPos(from);
776
- if (!to) to = from; else to = clipPos(to);
777
- code = splitLines(code);
778
- function adjustPos(pos) {
779
- if (posLess(pos, from)) return pos;
780
- if (!posLess(to, pos)) return end;
781
- var line = pos.line + code.length - (to.line - from.line) - 1;
782
- var ch = pos.ch;
783
- if (pos.line == to.line)
784
- ch += code[code.length-1].length - (to.ch - (to.line == from.line ? from.ch : 0));
785
- return {line: line, ch: ch};
786
- }
787
- var end;
788
- replaceRange1(code, from, to, function(end1) {
789
- end = end1;
790
- return {from: adjustPos(sel.from), to: adjustPos(sel.to)};
791
- });
792
- return end;
793
- }
794
- function replaceSelection(code, collapse) {
795
- replaceRange1(splitLines(code), sel.from, sel.to, function(end) {
796
- if (collapse == "end") return {from: end, to: end};
797
- else if (collapse == "start") return {from: sel.from, to: sel.from};
798
- else return {from: sel.from, to: end};
799
- });
800
- }
801
- function replaceRange1(code, from, to, computeSel) {
802
- var endch = code.length == 1 ? code[0].length + from.ch : code[code.length-1].length;
803
- var newSel = computeSel({line: from.line + code.length - 1, ch: endch});
804
- updateLines(from, to, code, newSel.from, newSel.to);
805
- }
806
-
807
- function getRange(from, to) {
808
- var l1 = from.line, l2 = to.line;
809
- if (l1 == l2) return getLine(l1).text.slice(from.ch, to.ch);
810
- var code = [getLine(l1).text.slice(from.ch)];
811
- doc.iter(l1 + 1, l2, function(line) { code.push(line.text); });
812
- code.push(getLine(l2).text.slice(0, to.ch));
813
- return code.join("\n");
814
- }
815
- function getSelection() {
816
- return getRange(sel.from, sel.to);
817
- }
818
-
819
- var pollingFast = false; // Ensures slowPoll doesn't cancel fastPoll
820
- function slowPoll() {
821
- if (pollingFast) return;
822
- poll.set(options.pollInterval, function() {
823
- startOperation();
824
- readInput();
825
- if (focused) slowPoll();
826
- endOperation();
827
- });
828
- }
829
- function fastPoll() {
830
- var missed = false;
831
- pollingFast = true;
832
- function p() {
833
- startOperation();
834
- var changed = readInput();
835
- if (!changed && !missed) {missed = true; poll.set(60, p);}
836
- else {pollingFast = false; slowPoll();}
837
- endOperation();
838
- }
839
- poll.set(20, p);
840
- }
841
-
842
- // Previnput is a hack to work with IME. If we reset the textarea
843
- // on every change, that breaks IME. So we look for changes
844
- // compared to the previous content instead. (Modern browsers have
845
- // events that indicate IME taking place, but these are not widely
846
- // supported or compatible enough yet to rely on.)
847
- var prevInput = "";
848
- function readInput() {
849
- if (leaveInputAlone || !focused || hasSelection(input) || options.readOnly) return false;
850
- var text = input.value;
851
- if (text == prevInput) return false;
852
- shiftSelecting = null;
853
- var same = 0, l = Math.min(prevInput.length, text.length);
854
- while (same < l && prevInput[same] == text[same]) ++same;
855
- if (same < prevInput.length)
856
- sel.from = {line: sel.from.line, ch: sel.from.ch - (prevInput.length - same)};
857
- else if (overwrite && posEq(sel.from, sel.to))
858
- sel.to = {line: sel.to.line, ch: Math.min(getLine(sel.to.line).text.length, sel.to.ch + (text.length - same))};
859
- replaceSelection(text.slice(same), "end");
860
- prevInput = text;
861
- return true;
862
- }
863
- function resetInput(user) {
864
- if (!posEq(sel.from, sel.to)) {
865
- prevInput = "";
866
- input.value = getSelection();
867
- selectInput(input);
868
- } else if (user) prevInput = input.value = "";
869
- }
870
-
871
- function focusInput() {
872
- if (options.readOnly != "nocursor") input.focus();
873
- }
874
-
875
- function scrollEditorIntoView() {
876
- if (!cursor.getBoundingClientRect) return;
877
- var rect = cursor.getBoundingClientRect();
878
- // IE returns bogus coordinates when the instance sits inside of an iframe and the cursor is hidden
879
- if (ie && rect.top == rect.bottom) return;
880
- var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
881
- if (rect.top < 0 || rect.bottom > winH) cursor.scrollIntoView();
882
- }
883
- function scrollCursorIntoView() {
884
- var cursor = localCoords(sel.inverted ? sel.from : sel.to);
885
- var x = options.lineWrapping ? Math.min(cursor.x, lineSpace.offsetWidth) : cursor.x;
886
- return scrollIntoView(x, cursor.y, x, cursor.yBot);
887
- }
888
- function scrollIntoView(x1, y1, x2, y2) {
889
- var pl = paddingLeft(), pt = paddingTop();
890
- y1 += pt; y2 += pt; x1 += pl; x2 += pl;
891
- var screen = scroller.clientHeight, screentop = scroller.scrollTop, scrolled = false, result = true;
892
- if (y1 < screentop) {scroller.scrollTop = Math.max(0, y1); scrolled = true;}
893
- else if (y2 > screentop + screen) {scroller.scrollTop = y2 - screen; scrolled = true;}
894
-
895
- var screenw = scroller.clientWidth, screenleft = scroller.scrollLeft;
896
- var gutterw = options.fixedGutter ? gutter.clientWidth : 0;
897
- var atLeft = x1 < gutterw + pl + 10;
898
- if (x1 < screenleft + gutterw || atLeft) {
899
- if (atLeft) x1 = 0;
900
- scroller.scrollLeft = Math.max(0, x1 - 10 - gutterw);
901
- scrolled = true;
902
- }
903
- else if (x2 > screenw + screenleft - 3) {
904
- scroller.scrollLeft = x2 + 10 - screenw;
905
- scrolled = true;
906
- if (x2 > code.clientWidth) result = false;
907
- }
908
- if (scrolled && options.onScroll) options.onScroll(instance);
909
- return result;
910
- }
911
-
912
- function visibleLines() {
913
- var lh = textHeight(), top = scroller.scrollTop - paddingTop();
914
- var fromHeight = Math.max(0, Math.floor(top / lh));
915
- var toHeight = Math.ceil((top + scroller.clientHeight) / lh);
916
- return {from: lineAtHeight(doc, fromHeight),
917
- to: lineAtHeight(doc, toHeight)};
918
- }
919
- // Uses a set of changes plus the current scroll position to
920
- // determine which DOM updates have to be made, and makes the
921
- // updates.
922
- function updateDisplay(changes, suppressCallback) {
923
- if (!scroller.clientWidth) {
924
- showingFrom = showingTo = displayOffset = 0;
925
- return;
926
- }
927
- // Compute the new visible window
928
- var visible = visibleLines();
929
- // Bail out if the visible area is already rendered and nothing changed.
930
- if (changes !== true && changes.length == 0 && visible.from > showingFrom && visible.to < showingTo) return;
931
- var from = Math.max(visible.from - 100, 0), to = Math.min(doc.size, visible.to + 100);
932
- if (showingFrom < from && from - showingFrom < 20) from = showingFrom;
933
- if (showingTo > to && showingTo - to < 20) to = Math.min(doc.size, showingTo);
934
-
935
- // Create a range of theoretically intact lines, and punch holes
936
- // in that using the change info.
937
- var intact = changes === true ? [] :
938
- computeIntact([{from: showingFrom, to: showingTo, domStart: 0}], changes);
939
- // Clip off the parts that won't be visible
940
- var intactLines = 0;
941
- for (var i = 0; i < intact.length; ++i) {
942
- var range = intact[i];
943
- if (range.from < from) {range.domStart += (from - range.from); range.from = from;}
944
- if (range.to > to) range.to = to;
945
- if (range.from >= range.to) intact.splice(i--, 1);
946
- else intactLines += range.to - range.from;
947
- }
948
- if (intactLines == to - from && from == showingFrom && to == showingTo) return;
949
- intact.sort(function(a, b) {return a.domStart - b.domStart;});
950
-
951
- var th = textHeight(), gutterDisplay = gutter.style.display;
952
- lineDiv.style.display = "none";
953
- patchDisplay(from, to, intact);
954
- lineDiv.style.display = gutter.style.display = "";
955
-
956
- // Position the mover div to align with the lines it's supposed
957
- // to be showing (which will cover the visible display)
958
- var different = from != showingFrom || to != showingTo || lastSizeC != scroller.clientHeight + th;
959
- // This is just a bogus formula that detects when the editor is
960
- // resized or the font size changes.
961
- if (different) lastSizeC = scroller.clientHeight + th;
962
- showingFrom = from; showingTo = to;
963
- displayOffset = heightAtLine(doc, from);
964
- mover.style.top = (displayOffset * th) + "px";
965
- if (scroller.clientHeight)
966
- code.style.height = (doc.height * th + 2 * paddingTop()) + "px";
967
-
968
- // Since this is all rather error prone, it is honoured with the
969
- // only assertion in the whole file.
970
- if (lineDiv.childNodes.length != showingTo - showingFrom)
971
- throw new Error("BAD PATCH! " + JSON.stringify(intact) + " size=" + (showingTo - showingFrom) +
972
- " nodes=" + lineDiv.childNodes.length);
973
-
974
- function checkHeights() {
975
- maxWidth = scroller.clientWidth;
976
- var curNode = lineDiv.firstChild, heightChanged = false;
977
- doc.iter(showingFrom, showingTo, function(line) {
978
- if (!line.hidden) {
979
- var height = Math.round(curNode.offsetHeight / th) || 1;
980
- if (line.height != height) {
981
- updateLineHeight(line, height);
982
- gutterDirty = heightChanged = true;
983
- }
984
- }
985
- curNode = curNode.nextSibling;
986
- });
987
- if (heightChanged)
988
- code.style.height = (doc.height * th + 2 * paddingTop()) + "px";
989
- return heightChanged;
990
- }
991
-
992
- if (options.lineWrapping) {
993
- checkHeights();
994
- } else {
995
- if (maxWidth == null) maxWidth = stringWidth(maxLine);
996
- if (maxWidth > scroller.clientWidth) {
997
- lineSpace.style.width = maxWidth + "px";
998
- // Needed to prevent odd wrapping/hiding of widgets placed in here.
999
- code.style.width = "";
1000
- code.style.width = scroller.scrollWidth + "px";
1001
- } else {
1002
- lineSpace.style.width = code.style.width = "";
1003
- }
1004
- }
1005
-
1006
- gutter.style.display = gutterDisplay;
1007
- if (different || gutterDirty) {
1008
- // If the gutter grew in size, re-check heights. If those changed, re-draw gutter.
1009
- updateGutter() && options.lineWrapping && checkHeights() && updateGutter();
1010
- }
1011
- updateSelection();
1012
- if (!suppressCallback && options.onUpdate) options.onUpdate(instance);
1013
- return true;
1014
- }
1015
-
1016
- function computeIntact(intact, changes) {
1017
- for (var i = 0, l = changes.length || 0; i < l; ++i) {
1018
- var change = changes[i], intact2 = [], diff = change.diff || 0;
1019
- for (var j = 0, l2 = intact.length; j < l2; ++j) {
1020
- var range = intact[j];
1021
- if (change.to <= range.from && change.diff)
1022
- intact2.push({from: range.from + diff, to: range.to + diff,
1023
- domStart: range.domStart});
1024
- else if (change.to <= range.from || change.from >= range.to)
1025
- intact2.push(range);
1026
- else {
1027
- if (change.from > range.from)
1028
- intact2.push({from: range.from, to: change.from, domStart: range.domStart});
1029
- if (change.to < range.to)
1030
- intact2.push({from: change.to + diff, to: range.to + diff,
1031
- domStart: range.domStart + (change.to - range.from)});
1032
- }
1033
- }
1034
- intact = intact2;
1035
- }
1036
- return intact;
1037
- }
1038
-
1039
- function patchDisplay(from, to, intact) {
1040
- // The first pass removes the DOM nodes that aren't intact.
1041
- if (!intact.length) lineDiv.innerHTML = "";
1042
- else {
1043
- function killNode(node) {
1044
- var tmp = node.nextSibling;
1045
- node.parentNode.removeChild(node);
1046
- return tmp;
1047
- }
1048
- var domPos = 0, curNode = lineDiv.firstChild, n;
1049
- for (var i = 0; i < intact.length; ++i) {
1050
- var cur = intact[i];
1051
- while (cur.domStart > domPos) {curNode = killNode(curNode); domPos++;}
1052
- for (var j = 0, e = cur.to - cur.from; j < e; ++j) {curNode = curNode.nextSibling; domPos++;}
1053
- }
1054
- while (curNode) curNode = killNode(curNode);
1055
- }
1056
- // This pass fills in the lines that actually changed.
1057
- var nextIntact = intact.shift(), curNode = lineDiv.firstChild, j = from;
1058
- var scratch = document.createElement("div");
1059
- doc.iter(from, to, function(line) {
1060
- if (nextIntact && nextIntact.to == j) nextIntact = intact.shift();
1061
- if (!nextIntact || nextIntact.from > j) {
1062
- if (line.hidden) var html = scratch.innerHTML = "<pre></pre>";
1063
- else {
1064
- var html = '<pre' + (line.className ? ' class="' + line.className + '"' : '') + '>'
1065
- + line.getHTML(makeTab) + '</pre>';
1066
- // Kludge to make sure the styled element lies behind the selection (by z-index)
1067
- if (line.bgClassName)
1068
- html = '<div style="position: relative"><pre class="' + line.bgClassName +
1069
- '" style="position: absolute; left: 0; right: 0; top: 0; bottom: 0; z-index: -2">&#160;</pre>' + html + "</div>";
1070
- }
1071
- scratch.innerHTML = html;
1072
- lineDiv.insertBefore(scratch.firstChild, curNode);
1073
- } else {
1074
- curNode = curNode.nextSibling;
1075
- }
1076
- ++j;
1077
- });
1078
- }
1079
-
1080
- function updateGutter() {
1081
- if (!options.gutter && !options.lineNumbers) return;
1082
- var hText = mover.offsetHeight, hEditor = scroller.clientHeight;
1083
- gutter.style.height = (hText - hEditor < 2 ? hEditor : hText) + "px";
1084
- var html = [], i = showingFrom, normalNode;
1085
- doc.iter(showingFrom, Math.max(showingTo, showingFrom + 1), function(line) {
1086
- if (line.hidden) {
1087
- html.push("<pre></pre>");
1088
- } else {
1089
- var marker = line.gutterMarker;
1090
- var text = options.lineNumbers ? i + options.firstLineNumber : null;
1091
- if (marker && marker.text)
1092
- text = marker.text.replace("%N%", text != null ? text : "");
1093
- else if (text == null)
1094
- text = "\u00a0";
1095
- html.push((marker && marker.style ? '<pre class="' + marker.style + '">' : "<pre>"), text);
1096
- for (var j = 1; j < line.height; ++j) html.push("<br/>&#160;");
1097
- html.push("</pre>");
1098
- if (!marker) normalNode = i;
1099
- }
1100
- ++i;
1101
- });
1102
- gutter.style.display = "none";
1103
- gutterText.innerHTML = html.join("");
1104
- // Make sure scrolling doesn't cause number gutter size to pop
1105
- if (normalNode != null) {
1106
- var node = gutterText.childNodes[normalNode - showingFrom];
1107
- var minwidth = String(doc.size).length, val = eltText(node), pad = "";
1108
- while (val.length + pad.length < minwidth) pad += "\u00a0";
1109
- if (pad) node.insertBefore(document.createTextNode(pad), node.firstChild);
1110
- }
1111
- gutter.style.display = "";
1112
- var resized = Math.abs((parseInt(lineSpace.style.marginLeft) || 0) - gutter.offsetWidth) > 2;
1113
- lineSpace.style.marginLeft = gutter.offsetWidth + "px";
1114
- gutterDirty = false;
1115
- return resized;
1116
- }
1117
- function updateSelection() {
1118
- var collapsed = posEq(sel.from, sel.to);
1119
- var fromPos = localCoords(sel.from, true);
1120
- var toPos = collapsed ? fromPos : localCoords(sel.to, true);
1121
- var headPos = sel.inverted ? fromPos : toPos, th = textHeight();
1122
- var wrapOff = eltOffset(wrapper), lineOff = eltOffset(lineDiv);
1123
- inputDiv.style.top = Math.max(0, Math.min(scroller.offsetHeight, headPos.y + lineOff.top - wrapOff.top)) + "px";
1124
- inputDiv.style.left = Math.max(0, Math.min(scroller.offsetWidth, headPos.x + lineOff.left - wrapOff.left)) + "px";
1125
- if (collapsed) {
1126
- cursor.style.top = headPos.y + "px";
1127
- cursor.style.left = (options.lineWrapping ? Math.min(headPos.x, lineSpace.offsetWidth) : headPos.x) + "px";
1128
- cursor.style.display = "";
1129
- selectionDiv.style.display = "none";
1130
- } else {
1131
- var sameLine = fromPos.y == toPos.y, html = "";
1132
- var clientWidth = lineSpace.clientWidth || lineSpace.offsetWidth;
1133
- var clientHeight = lineSpace.clientHeight || lineSpace.offsetHeight;
1134
- function add(left, top, right, height) {
1135
- var rstyle = quirksMode ? "width: " + (!right ? clientWidth : clientWidth - right - left) + "px"
1136
- : "right: " + right + "px";
1137
- html += '<div class="CodeMirror-selected" style="position: absolute; left: ' + left +
1138
- 'px; top: ' + top + 'px; ' + rstyle + '; height: ' + height + 'px"></div>';
1139
- }
1140
- if (sel.from.ch && fromPos.y >= 0) {
1141
- var right = sameLine ? clientWidth - toPos.x : 0;
1142
- add(fromPos.x, fromPos.y, right, th);
1143
- }
1144
- var middleStart = Math.max(0, fromPos.y + (sel.from.ch ? th : 0));
1145
- var middleHeight = Math.min(toPos.y, clientHeight) - middleStart;
1146
- if (middleHeight > 0.2 * th)
1147
- add(0, middleStart, 0, middleHeight);
1148
- if ((!sameLine || !sel.from.ch) && toPos.y < clientHeight - .5 * th)
1149
- add(0, toPos.y, clientWidth - toPos.x, th);
1150
- selectionDiv.innerHTML = html;
1151
- cursor.style.display = "none";
1152
- selectionDiv.style.display = "";
1153
- }
1154
- }
1155
-
1156
- function setShift(val) {
1157
- if (val) shiftSelecting = shiftSelecting || (sel.inverted ? sel.to : sel.from);
1158
- else shiftSelecting = null;
1159
- }
1160
- function setSelectionUser(from, to) {
1161
- var sh = shiftSelecting && clipPos(shiftSelecting);
1162
- if (sh) {
1163
- if (posLess(sh, from)) from = sh;
1164
- else if (posLess(to, sh)) to = sh;
1165
- }
1166
- setSelection(from, to);
1167
- userSelChange = true;
1168
- }
1169
- // Update the selection. Last two args are only used by
1170
- // updateLines, since they have to be expressed in the line
1171
- // numbers before the update.
1172
- function setSelection(from, to, oldFrom, oldTo) {
1173
- goalColumn = null;
1174
- if (oldFrom == null) {oldFrom = sel.from.line; oldTo = sel.to.line;}
1175
- if (posEq(sel.from, from) && posEq(sel.to, to)) return;
1176
- if (posLess(to, from)) {var tmp = to; to = from; from = tmp;}
1177
-
1178
- // Skip over hidden lines.
1179
- if (from.line != oldFrom) {
1180
- var from1 = skipHidden(from, oldFrom, sel.from.ch);
1181
- // If there is no non-hidden line left, force visibility on current line
1182
- if (!from1) setLineHidden(from.line, false);
1183
- else from = from1;
1184
- }
1185
- if (to.line != oldTo) to = skipHidden(to, oldTo, sel.to.ch);
1186
-
1187
- if (posEq(from, to)) sel.inverted = false;
1188
- else if (posEq(from, sel.to)) sel.inverted = false;
1189
- else if (posEq(to, sel.from)) sel.inverted = true;
1190
-
1191
- if (options.autoClearEmptyLines && posEq(sel.from, sel.to)) {
1192
- var head = sel.inverted ? from : to;
1193
- if (head.line != sel.from.line && sel.from.line < doc.size) {
1194
- var oldLine = getLine(sel.from.line);
1195
- if (/^\s+$/.test(oldLine.text))
1196
- setTimeout(operation(function() {
1197
- if (oldLine.parent && /^\s+$/.test(oldLine.text)) {
1198
- var no = lineNo(oldLine);
1199
- replaceRange("", {line: no, ch: 0}, {line: no, ch: oldLine.text.length});
1200
- }
1201
- }, 10));
1202
- }
1203
- }
1204
-
1205
- sel.from = from; sel.to = to;
1206
- selectionChanged = true;
1207
- }
1208
- function skipHidden(pos, oldLine, oldCh) {
1209
- function getNonHidden(dir) {
1210
- var lNo = pos.line + dir, end = dir == 1 ? doc.size : -1;
1211
- while (lNo != end) {
1212
- var line = getLine(lNo);
1213
- if (!line.hidden) {
1214
- var ch = pos.ch;
1215
- if (toEnd || ch > oldCh || ch > line.text.length) ch = line.text.length;
1216
- return {line: lNo, ch: ch};
1217
- }
1218
- lNo += dir;
1219
- }
1220
- }
1221
- var line = getLine(pos.line);
1222
- var toEnd = pos.ch == line.text.length && pos.ch != oldCh;
1223
- if (!line.hidden) return pos;
1224
- if (pos.line >= oldLine) return getNonHidden(1) || getNonHidden(-1);
1225
- else return getNonHidden(-1) || getNonHidden(1);
1226
- }
1227
- function setCursor(line, ch, user) {
1228
- var pos = clipPos({line: line, ch: ch || 0});
1229
- (user ? setSelectionUser : setSelection)(pos, pos);
1230
- }
1231
-
1232
- function clipLine(n) {return Math.max(0, Math.min(n, doc.size-1));}
1233
- function clipPos(pos) {
1234
- if (pos.line < 0) return {line: 0, ch: 0};
1235
- if (pos.line >= doc.size) return {line: doc.size-1, ch: getLine(doc.size-1).text.length};
1236
- var ch = pos.ch, linelen = getLine(pos.line).text.length;
1237
- if (ch == null || ch > linelen) return {line: pos.line, ch: linelen};
1238
- else if (ch < 0) return {line: pos.line, ch: 0};
1239
- else return pos;
1240
- }
1241
-
1242
- function findPosH(dir, unit) {
1243
- var end = sel.inverted ? sel.from : sel.to, line = end.line, ch = end.ch;
1244
- var lineObj = getLine(line);
1245
- function findNextLine() {
1246
- for (var l = line + dir, e = dir < 0 ? -1 : doc.size; l != e; l += dir) {
1247
- var lo = getLine(l);
1248
- if (!lo.hidden) { line = l; lineObj = lo; return true; }
1249
- }
1250
- }
1251
- function moveOnce(boundToLine) {
1252
- if (ch == (dir < 0 ? 0 : lineObj.text.length)) {
1253
- if (!boundToLine && findNextLine()) ch = dir < 0 ? lineObj.text.length : 0;
1254
- else return false;
1255
- } else ch += dir;
1256
- return true;
1257
- }
1258
- if (unit == "char") moveOnce();
1259
- else if (unit == "column") moveOnce(true);
1260
- else if (unit == "word") {
1261
- var sawWord = false;
1262
- for (;;) {
1263
- if (dir < 0) if (!moveOnce()) break;
1264
- if (isWordChar(lineObj.text.charAt(ch))) sawWord = true;
1265
- else if (sawWord) {if (dir < 0) {dir = 1; moveOnce();} break;}
1266
- if (dir > 0) if (!moveOnce()) break;
1267
- }
1268
- }
1269
- return {line: line, ch: ch};
1270
- }
1271
- function moveH(dir, unit) {
1272
- var pos = dir < 0 ? sel.from : sel.to;
1273
- if (shiftSelecting || posEq(sel.from, sel.to)) pos = findPosH(dir, unit);
1274
- setCursor(pos.line, pos.ch, true);
1275
- }
1276
- function deleteH(dir, unit) {
1277
- if (!posEq(sel.from, sel.to)) replaceRange("", sel.from, sel.to);
1278
- else if (dir < 0) replaceRange("", findPosH(dir, unit), sel.to);
1279
- else replaceRange("", sel.from, findPosH(dir, unit));
1280
- userSelChange = true;
1281
- }
1282
- var goalColumn = null;
1283
- function moveV(dir, unit) {
1284
- var dist = 0, pos = localCoords(sel.inverted ? sel.from : sel.to, true);
1285
- if (goalColumn != null) pos.x = goalColumn;
1286
- if (unit == "page") dist = Math.min(scroller.clientHeight, window.innerHeight || document.documentElement.clientHeight);
1287
- else if (unit == "line") dist = textHeight();
1288
- var target = coordsChar(pos.x, pos.y + dist * dir + 2);
1289
- if (unit == "page") scroller.scrollTop += localCoords(target, true).y - pos.y;
1290
- setCursor(target.line, target.ch, true);
1291
- goalColumn = pos.x;
1292
- }
1293
-
1294
- function selectWordAt(pos) {
1295
- var line = getLine(pos.line).text;
1296
- var start = pos.ch, end = pos.ch;
1297
- while (start > 0 && isWordChar(line.charAt(start - 1))) --start;
1298
- while (end < line.length && isWordChar(line.charAt(end))) ++end;
1299
- setSelectionUser({line: pos.line, ch: start}, {line: pos.line, ch: end});
1300
- }
1301
- function selectLine(line) {
1302
- setSelectionUser({line: line, ch: 0}, clipPos({line: line + 1, ch: 0}));
1303
- }
1304
- function indentSelected(mode) {
1305
- if (posEq(sel.from, sel.to)) return indentLine(sel.from.line, mode);
1306
- var e = sel.to.line - (sel.to.ch ? 0 : 1);
1307
- for (var i = sel.from.line; i <= e; ++i) indentLine(i, mode);
1308
- }
1309
-
1310
- function indentLine(n, how) {
1311
- if (!how) how = "add";
1312
- if (how == "smart") {
1313
- if (!mode.indent) how = "prev";
1314
- else var state = getStateBefore(n);
1315
- }
1316
-
1317
- var line = getLine(n), curSpace = line.indentation(options.tabSize),
1318
- curSpaceString = line.text.match(/^\s*/)[0], indentation;
1319
- if (how == "prev") {
1320
- if (n) indentation = getLine(n-1).indentation(options.tabSize);
1321
- else indentation = 0;
1322
- }
1323
- else if (how == "smart") indentation = mode.indent(state, line.text.slice(curSpaceString.length), line.text);
1324
- else if (how == "add") indentation = curSpace + options.indentUnit;
1325
- else if (how == "subtract") indentation = curSpace - options.indentUnit;
1326
- indentation = Math.max(0, indentation);
1327
- var diff = indentation - curSpace;
1328
-
1329
- if (!diff) {
1330
- if (sel.from.line != n && sel.to.line != n) return;
1331
- var indentString = curSpaceString;
1332
- }
1333
- else {
1334
- var indentString = "", pos = 0;
1335
- if (options.indentWithTabs)
1336
- for (var i = Math.floor(indentation / options.tabSize); i; --i) {pos += options.tabSize; indentString += "\t";}
1337
- while (pos < indentation) {++pos; indentString += " ";}
1338
- }
1339
-
1340
- replaceRange(indentString, {line: n, ch: 0}, {line: n, ch: curSpaceString.length});
1341
- }
1342
-
1343
- function loadMode() {
1344
- mode = CodeMirror.getMode(options, options.mode);
1345
- doc.iter(0, doc.size, function(line) { line.stateAfter = null; });
1346
- work = [0];
1347
- startWorker();
1348
- }
1349
- function gutterChanged() {
1350
- var visible = options.gutter || options.lineNumbers;
1351
- gutter.style.display = visible ? "" : "none";
1352
- if (visible) gutterDirty = true;
1353
- else lineDiv.parentNode.style.marginLeft = 0;
1354
- }
1355
- function wrappingChanged(from, to) {
1356
- if (options.lineWrapping) {
1357
- wrapper.className += " CodeMirror-wrap";
1358
- var perLine = scroller.clientWidth / charWidth() - 3;
1359
- doc.iter(0, doc.size, function(line) {
1360
- if (line.hidden) return;
1361
- var guess = Math.ceil(line.text.length / perLine) || 1;
1362
- if (guess != 1) updateLineHeight(line, guess);
1363
- });
1364
- lineSpace.style.width = code.style.width = "";
1365
- } else {
1366
- wrapper.className = wrapper.className.replace(" CodeMirror-wrap", "");
1367
- maxWidth = null; maxLine = "";
1368
- doc.iter(0, doc.size, function(line) {
1369
- if (line.height != 1 && !line.hidden) updateLineHeight(line, 1);
1370
- if (line.text.length > maxLine.length) maxLine = line.text;
1371
- });
1372
- }
1373
- changes.push({from: 0, to: doc.size});
1374
- }
1375
- function makeTab(col) {
1376
- var w = options.tabSize - col % options.tabSize, cached = tabCache[w];
1377
- if (cached) return cached;
1378
- for (var str = '<span class="cm-tab">', i = 0; i < w; ++i) str += " ";
1379
- return (tabCache[w] = {html: str + "</span>", width: w});
1380
- }
1381
- function themeChanged() {
1382
- scroller.className = scroller.className.replace(/\s*cm-s-\S+/g, "") +
1383
- options.theme.replace(/(^|\s)\s*/g, " cm-s-");
1384
- }
1385
- function keyMapChanged() {
1386
- var style = keyMap[options.keyMap].style;
1387
- wrapper.className = wrapper.className.replace(/\s*cm-keymap-\S+/g, "") +
1388
- (style ? " cm-keymap-" + style : "");
1389
- }
1390
-
1391
- function TextMarker() { this.set = []; }
1392
- TextMarker.prototype.clear = operation(function() {
1393
- var min = Infinity, max = -Infinity;
1394
- for (var i = 0, e = this.set.length; i < e; ++i) {
1395
- var line = this.set[i], mk = line.marked;
1396
- if (!mk || !line.parent) continue;
1397
- var lineN = lineNo(line);
1398
- min = Math.min(min, lineN); max = Math.max(max, lineN);
1399
- for (var j = 0; j < mk.length; ++j)
1400
- if (mk[j].marker == this) mk.splice(j--, 1);
1401
- }
1402
- if (min != Infinity)
1403
- changes.push({from: min, to: max + 1});
1404
- });
1405
- TextMarker.prototype.find = function() {
1406
- var from, to;
1407
- for (var i = 0, e = this.set.length; i < e; ++i) {
1408
- var line = this.set[i], mk = line.marked;
1409
- for (var j = 0; j < mk.length; ++j) {
1410
- var mark = mk[j];
1411
- if (mark.marker == this) {
1412
- if (mark.from != null || mark.to != null) {
1413
- var found = lineNo(line);
1414
- if (found != null) {
1415
- if (mark.from != null) from = {line: found, ch: mark.from};
1416
- if (mark.to != null) to = {line: found, ch: mark.to};
1417
- }
1418
- }
1419
- }
1420
- }
1421
- }
1422
- return {from: from, to: to};
1423
- };
1424
-
1425
- function markText(from, to, className) {
1426
- from = clipPos(from); to = clipPos(to);
1427
- var tm = new TextMarker();
1428
- if (!posLess(from, to)) return tm;
1429
- function add(line, from, to, className) {
1430
- getLine(line).addMark(new MarkedText(from, to, className, tm));
1431
- }
1432
- if (from.line == to.line) add(from.line, from.ch, to.ch, className);
1433
- else {
1434
- add(from.line, from.ch, null, className);
1435
- for (var i = from.line + 1, e = to.line; i < e; ++i)
1436
- add(i, null, null, className);
1437
- add(to.line, null, to.ch, className);
1438
- }
1439
- changes.push({from: from.line, to: to.line + 1});
1440
- return tm;
1441
- }
1442
-
1443
- function setBookmark(pos) {
1444
- pos = clipPos(pos);
1445
- var bm = new Bookmark(pos.ch);
1446
- getLine(pos.line).addMark(bm);
1447
- return bm;
1448
- }
1449
-
1450
- function findMarksAt(pos) {
1451
- pos = clipPos(pos);
1452
- var markers = [], marked = getLine(pos.line).marked;
1453
- if (!marked) return markers;
1454
- for (var i = 0, e = marked.length; i < e; ++i) {
1455
- var m = marked[i];
1456
- if ((m.from == null || m.from <= pos.ch) &&
1457
- (m.to == null || m.to >= pos.ch))
1458
- markers.push(m.marker || m);
1459
- }
1460
- return markers;
1461
- }
1462
-
1463
- function addGutterMarker(line, text, className) {
1464
- if (typeof line == "number") line = getLine(clipLine(line));
1465
- line.gutterMarker = {text: text, style: className};
1466
- gutterDirty = true;
1467
- return line;
1468
- }
1469
- function removeGutterMarker(line) {
1470
- if (typeof line == "number") line = getLine(clipLine(line));
1471
- line.gutterMarker = null;
1472
- gutterDirty = true;
1473
- }
1474
-
1475
- function changeLine(handle, op) {
1476
- var no = handle, line = handle;
1477
- if (typeof handle == "number") line = getLine(clipLine(handle));
1478
- else no = lineNo(handle);
1479
- if (no == null) return null;
1480
- if (op(line, no)) changes.push({from: no, to: no + 1});
1481
- else return null;
1482
- return line;
1483
- }
1484
- function setLineClass(handle, className, bgClassName) {
1485
- return changeLine(handle, function(line) {
1486
- if (line.className != className || line.bgClassName != bgClassName) {
1487
- line.className = className;
1488
- line.bgClassName = bgClassName;
1489
- return true;
1490
- }
1491
- });
1492
- }
1493
- function setLineHidden(handle, hidden) {
1494
- return changeLine(handle, function(line, no) {
1495
- if (line.hidden != hidden) {
1496
- line.hidden = hidden;
1497
- updateLineHeight(line, hidden ? 0 : 1);
1498
- var fline = sel.from.line, tline = sel.to.line;
1499
- if (hidden && (fline == no || tline == no)) {
1500
- var from = fline == no ? skipHidden({line: fline, ch: 0}, fline, 0) : sel.from;
1501
- var to = tline == no ? skipHidden({line: tline, ch: 0}, tline, 0) : sel.to;
1502
- // Can't hide the last visible line, we'd have no place to put the cursor
1503
- if (!to) return;
1504
- setSelection(from, to);
1505
- }
1506
- return (gutterDirty = true);
1507
- }
1508
- });
1509
- }
1510
-
1511
- function lineInfo(line) {
1512
- if (typeof line == "number") {
1513
- if (!isLine(line)) return null;
1514
- var n = line;
1515
- line = getLine(line);
1516
- if (!line) return null;
1517
- }
1518
- else {
1519
- var n = lineNo(line);
1520
- if (n == null) return null;
1521
- }
1522
- var marker = line.gutterMarker;
1523
- return {line: n, handle: line, text: line.text, markerText: marker && marker.text,
1524
- markerClass: marker && marker.style, lineClass: line.className, bgClass: line.bgClassName};
1525
- }
1526
-
1527
- function stringWidth(str) {
1528
- measure.innerHTML = "<pre><span>x</span></pre>";
1529
- measure.firstChild.firstChild.firstChild.nodeValue = str;
1530
- return measure.firstChild.firstChild.offsetWidth || 10;
1531
- }
1532
- // These are used to go from pixel positions to character
1533
- // positions, taking varying character widths into account.
1534
- function charFromX(line, x) {
1535
- if (x <= 0) return 0;
1536
- var lineObj = getLine(line), text = lineObj.text;
1537
- function getX(len) {
1538
- return measureLine(lineObj, len).left;
1539
- }
1540
- var from = 0, fromX = 0, to = text.length, toX;
1541
- // Guess a suitable upper bound for our search.
1542
- var estimated = Math.min(to, Math.ceil(x / charWidth()));
1543
- for (;;) {
1544
- var estX = getX(estimated);
1545
- if (estX <= x && estimated < to) estimated = Math.min(to, Math.ceil(estimated * 1.2));
1546
- else {toX = estX; to = estimated; break;}
1547
- }
1548
- if (x > toX) return to;
1549
- // Try to guess a suitable lower bound as well.
1550
- estimated = Math.floor(to * 0.8); estX = getX(estimated);
1551
- if (estX < x) {from = estimated; fromX = estX;}
1552
- // Do a binary search between these bounds.
1553
- for (;;) {
1554
- if (to - from <= 1) return (toX - x > x - fromX) ? from : to;
1555
- var middle = Math.ceil((from + to) / 2), middleX = getX(middle);
1556
- if (middleX > x) {to = middle; toX = middleX;}
1557
- else {from = middle; fromX = middleX;}
1558
- }
1559
- }
1560
-
1561
- var tempId = "CodeMirror-temp-" + Math.floor(Math.random() * 0xffffff).toString(16);
1562
- function measureLine(line, ch) {
1563
- if (ch == 0) return {top: 0, left: 0};
1564
- var wbr = options.lineWrapping && ch < line.text.length &&
1565
- spanAffectsWrapping.test(line.text.slice(ch - 1, ch + 1));
1566
- measure.innerHTML = "<pre>" + line.getHTML(makeTab, ch, tempId, wbr) + "</pre>";
1567
- var elt = document.getElementById(tempId);
1568
- var top = elt.offsetTop, left = elt.offsetLeft;
1569
- // Older IEs report zero offsets for spans directly after a wrap
1570
- if (ie && top == 0 && left == 0) {
1571
- var backup = document.createElement("span");
1572
- backup.innerHTML = "x";
1573
- elt.parentNode.insertBefore(backup, elt.nextSibling);
1574
- top = backup.offsetTop;
1575
- }
1576
- return {top: top, left: left};
1577
- }
1578
- function localCoords(pos, inLineWrap) {
1579
- var x, lh = textHeight(), y = lh * (heightAtLine(doc, pos.line) - (inLineWrap ? displayOffset : 0));
1580
- if (pos.ch == 0) x = 0;
1581
- else {
1582
- var sp = measureLine(getLine(pos.line), pos.ch);
1583
- x = sp.left;
1584
- if (options.lineWrapping) y += Math.max(0, sp.top);
1585
- }
1586
- return {x: x, y: y, yBot: y + lh};
1587
- }
1588
- // Coords must be lineSpace-local
1589
- function coordsChar(x, y) {
1590
- if (y < 0) y = 0;
1591
- var th = textHeight(), cw = charWidth(), heightPos = displayOffset + Math.floor(y / th);
1592
- var lineNo = lineAtHeight(doc, heightPos);
1593
- if (lineNo >= doc.size) return {line: doc.size - 1, ch: getLine(doc.size - 1).text.length};
1594
- var lineObj = getLine(lineNo), text = lineObj.text;
1595
- var tw = options.lineWrapping, innerOff = tw ? heightPos - heightAtLine(doc, lineNo) : 0;
1596
- if (x <= 0 && innerOff == 0) return {line: lineNo, ch: 0};
1597
- function getX(len) {
1598
- var sp = measureLine(lineObj, len);
1599
- if (tw) {
1600
- var off = Math.round(sp.top / th);
1601
- return Math.max(0, sp.left + (off - innerOff) * scroller.clientWidth);
1602
- }
1603
- return sp.left;
1604
- }
1605
- var from = 0, fromX = 0, to = text.length, toX;
1606
- // Guess a suitable upper bound for our search.
1607
- var estimated = Math.min(to, Math.ceil((x + innerOff * scroller.clientWidth * .9) / cw));
1608
- for (;;) {
1609
- var estX = getX(estimated);
1610
- if (estX <= x && estimated < to) estimated = Math.min(to, Math.ceil(estimated * 1.2));
1611
- else {toX = estX; to = estimated; break;}
1612
- }
1613
- if (x > toX) return {line: lineNo, ch: to};
1614
- // Try to guess a suitable lower bound as well.
1615
- estimated = Math.floor(to * 0.8); estX = getX(estimated);
1616
- if (estX < x) {from = estimated; fromX = estX;}
1617
- // Do a binary search between these bounds.
1618
- for (;;) {
1619
- if (to - from <= 1) return {line: lineNo, ch: (toX - x > x - fromX) ? from : to};
1620
- var middle = Math.ceil((from + to) / 2), middleX = getX(middle);
1621
- if (middleX > x) {to = middle; toX = middleX;}
1622
- else {from = middle; fromX = middleX;}
1623
- }
1624
- }
1625
- function pageCoords(pos) {
1626
- var local = localCoords(pos, true), off = eltOffset(lineSpace);
1627
- return {x: off.left + local.x, y: off.top + local.y, yBot: off.top + local.yBot};
1628
- }
1629
-
1630
- var cachedHeight, cachedHeightFor, measureText;
1631
- function textHeight() {
1632
- if (measureText == null) {
1633
- measureText = "<pre>";
1634
- for (var i = 0; i < 49; ++i) measureText += "x<br/>";
1635
- measureText += "x</pre>";
1636
- }
1637
- var offsetHeight = lineDiv.clientHeight;
1638
- if (offsetHeight == cachedHeightFor) return cachedHeight;
1639
- cachedHeightFor = offsetHeight;
1640
- measure.innerHTML = measureText;
1641
- cachedHeight = measure.firstChild.offsetHeight / 50 || 1;
1642
- measure.innerHTML = "";
1643
- return cachedHeight;
1644
- }
1645
- var cachedWidth, cachedWidthFor = 0;
1646
- function charWidth() {
1647
- if (scroller.clientWidth == cachedWidthFor) return cachedWidth;
1648
- cachedWidthFor = scroller.clientWidth;
1649
- return (cachedWidth = stringWidth("x"));
1650
- }
1651
- function paddingTop() {return lineSpace.offsetTop;}
1652
- function paddingLeft() {return lineSpace.offsetLeft;}
1653
-
1654
- function posFromMouse(e, liberal) {
1655
- var offW = eltOffset(scroller, true), x, y;
1656
- // Fails unpredictably on IE[67] when mouse is dragged around quickly.
1657
- try { x = e.clientX; y = e.clientY; } catch (e) { return null; }
1658
- // This is a mess of a heuristic to try and determine whether a
1659
- // scroll-bar was clicked or not, and to return null if one was
1660
- // (and !liberal).
1661
- if (!liberal && (x - offW.left > scroller.clientWidth || y - offW.top > scroller.clientHeight))
1662
- return null;
1663
- var offL = eltOffset(lineSpace, true);
1664
- return coordsChar(x - offL.left, y - offL.top);
1665
- }
1666
- function onContextMenu(e) {
1667
- var pos = posFromMouse(e), scrollPos = scroller.scrollTop;
1668
- if (!pos || window.opera) return; // Opera is difficult.
1669
- if (posEq(sel.from, sel.to) || posLess(pos, sel.from) || !posLess(pos, sel.to))
1670
- operation(setCursor)(pos.line, pos.ch);
1671
-
1672
- var oldCSS = input.style.cssText;
1673
- inputDiv.style.position = "absolute";
1674
- input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) +
1675
- "px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: white; " +
1676
- "border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
1677
- leaveInputAlone = true;
1678
- var val = input.value = getSelection();
1679
- focusInput();
1680
- selectInput(input);
1681
- function rehide() {
1682
- var newVal = splitLines(input.value).join("\n");
1683
- if (newVal != val) operation(replaceSelection)(newVal, "end");
1684
- inputDiv.style.position = "relative";
1685
- input.style.cssText = oldCSS;
1686
- if (ie_lt9) scroller.scrollTop = scrollPos;
1687
- leaveInputAlone = false;
1688
- resetInput(true);
1689
- slowPoll();
1690
- }
1691
-
1692
- if (gecko) {
1693
- e_stop(e);
1694
- var mouseup = connect(window, "mouseup", function() {
1695
- mouseup();
1696
- setTimeout(rehide, 20);
1697
- }, true);
1698
- } else {
1699
- setTimeout(rehide, 50);
1700
- }
1701
- }
1702
-
1703
- // Cursor-blinking
1704
- function restartBlink() {
1705
- clearInterval(blinker);
1706
- var on = true;
1707
- cursor.style.visibility = "";
1708
- blinker = setInterval(function() {
1709
- cursor.style.visibility = (on = !on) ? "" : "hidden";
1710
- }, 650);
1711
- }
1712
-
1713
- var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
1714
- function matchBrackets(autoclear) {
1715
- var head = sel.inverted ? sel.from : sel.to, line = getLine(head.line), pos = head.ch - 1;
1716
- var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
1717
- if (!match) return;
1718
- var ch = match.charAt(0), forward = match.charAt(1) == ">", d = forward ? 1 : -1, st = line.styles;
1719
- for (var off = pos + 1, i = 0, e = st.length; i < e; i+=2)
1720
- if ((off -= st[i].length) <= 0) {var style = st[i+1]; break;}
1721
-
1722
- var stack = [line.text.charAt(pos)], re = /[(){}[\]]/;
1723
- function scan(line, from, to) {
1724
- if (!line.text) return;
1725
- var st = line.styles, pos = forward ? 0 : line.text.length - 1, cur;
1726
- for (var i = forward ? 0 : st.length - 2, e = forward ? st.length : -2; i != e; i += 2*d) {
1727
- var text = st[i];
1728
- if (st[i+1] != null && st[i+1] != style) {pos += d * text.length; continue;}
1729
- for (var j = forward ? 0 : text.length - 1, te = forward ? text.length : -1; j != te; j += d, pos+=d) {
1730
- if (pos >= from && pos < to && re.test(cur = text.charAt(j))) {
1731
- var match = matching[cur];
1732
- if (match.charAt(1) == ">" == forward) stack.push(cur);
1733
- else if (stack.pop() != match.charAt(0)) return {pos: pos, match: false};
1734
- else if (!stack.length) return {pos: pos, match: true};
1735
- }
1736
- }
1737
- }
1738
- }
1739
- for (var i = head.line, e = forward ? Math.min(i + 100, doc.size) : Math.max(-1, i - 100); i != e; i+=d) {
1740
- var line = getLine(i), first = i == head.line;
1741
- var found = scan(line, first && forward ? pos + 1 : 0, first && !forward ? pos : line.text.length);
1742
- if (found) break;
1743
- }
1744
- if (!found) found = {pos: null, match: false};
1745
- var style = found.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
1746
- var one = markText({line: head.line, ch: pos}, {line: head.line, ch: pos+1}, style),
1747
- two = found.pos != null && markText({line: i, ch: found.pos}, {line: i, ch: found.pos + 1}, style);
1748
- var clear = operation(function(){one.clear(); two && two.clear();});
1749
- if (autoclear) setTimeout(clear, 800);
1750
- else bracketHighlighted = clear;
1751
- }
1752
-
1753
- // Finds the line to start with when starting a parse. Tries to
1754
- // find a line with a stateAfter, so that it can start with a
1755
- // valid state. If that fails, it returns the line with the
1756
- // smallest indentation, which tends to need the least context to
1757
- // parse correctly.
1758
- function findStartLine(n) {
1759
- var minindent, minline;
1760
- for (var search = n, lim = n - 40; search > lim; --search) {
1761
- if (search == 0) return 0;
1762
- var line = getLine(search-1);
1763
- if (line.stateAfter) return search;
1764
- var indented = line.indentation(options.tabSize);
1765
- if (minline == null || minindent > indented) {
1766
- minline = search - 1;
1767
- minindent = indented;
1768
- }
1769
- }
1770
- return minline;
1771
- }
1772
- function getStateBefore(n) {
1773
- var start = findStartLine(n), state = start && getLine(start-1).stateAfter;
1774
- if (!state) state = startState(mode);
1775
- else state = copyState(mode, state);
1776
- doc.iter(start, n, function(line) {
1777
- line.highlight(mode, state, options.tabSize);
1778
- line.stateAfter = copyState(mode, state);
1779
- });
1780
- if (start < n) changes.push({from: start, to: n});
1781
- if (n < doc.size && !getLine(n).stateAfter) work.push(n);
1782
- return state;
1783
- }
1784
- function highlightLines(start, end) {
1785
- var state = getStateBefore(start);
1786
- doc.iter(start, end, function(line) {
1787
- line.highlight(mode, state, options.tabSize);
1788
- line.stateAfter = copyState(mode, state);
1789
- });
1790
- }
1791
- function highlightWorker() {
1792
- var end = +new Date + options.workTime;
1793
- var foundWork = work.length;
1794
- while (work.length) {
1795
- if (!getLine(showingFrom).stateAfter) var task = showingFrom;
1796
- else var task = work.pop();
1797
- if (task >= doc.size) continue;
1798
- var start = findStartLine(task), state = start && getLine(start-1).stateAfter;
1799
- if (state) state = copyState(mode, state);
1800
- else state = startState(mode);
1801
-
1802
- var unchanged = 0, compare = mode.compareStates, realChange = false,
1803
- i = start, bail = false;
1804
- doc.iter(i, doc.size, function(line) {
1805
- var hadState = line.stateAfter;
1806
- if (+new Date > end) {
1807
- work.push(i);
1808
- startWorker(options.workDelay);
1809
- if (realChange) changes.push({from: task, to: i + 1});
1810
- return (bail = true);
1811
- }
1812
- var changed = line.highlight(mode, state, options.tabSize);
1813
- if (changed) realChange = true;
1814
- line.stateAfter = copyState(mode, state);
1815
- var done = null;
1816
- if (compare) {
1817
- var same = hadState && compare(hadState, state);
1818
- if (same != Pass) done = !!same;
1819
- }
1820
- if (done == null) {
1821
- if (changed !== false || !hadState) unchanged = 0;
1822
- else if (++unchanged > 3 && (!mode.indent || mode.indent(hadState, "") == mode.indent(state, "")))
1823
- done = true;
1824
- }
1825
- if (done) return true;
1826
- ++i;
1827
- });
1828
- if (bail) return;
1829
- if (realChange) changes.push({from: task, to: i + 1});
1830
- }
1831
- if (foundWork && options.onHighlightComplete)
1832
- options.onHighlightComplete(instance);
1833
- }
1834
- function startWorker(time) {
1835
- if (!work.length) return;
1836
- highlight.set(time, operation(highlightWorker));
1837
- }
1838
-
1839
- // Operations are used to wrap changes in such a way that each
1840
- // change won't have to update the cursor and display (which would
1841
- // be awkward, slow, and error-prone), but instead updates are
1842
- // batched and then all combined and executed at once.
1843
- function startOperation() {
1844
- updateInput = userSelChange = textChanged = null;
1845
- changes = []; selectionChanged = false; callbacks = [];
1846
- }
1847
- function endOperation() {
1848
- var reScroll = false, updated;
1849
- if (selectionChanged) reScroll = !scrollCursorIntoView();
1850
- if (changes.length) updated = updateDisplay(changes, true);
1851
- else {
1852
- if (selectionChanged) updateSelection();
1853
- if (gutterDirty) updateGutter();
1854
- }
1855
- if (reScroll) scrollCursorIntoView();
1856
- if (selectionChanged) {scrollEditorIntoView(); restartBlink();}
1857
-
1858
- if (focused && !leaveInputAlone &&
1859
- (updateInput === true || (updateInput !== false && selectionChanged)))
1860
- resetInput(userSelChange);
1861
-
1862
- if (selectionChanged && options.matchBrackets)
1863
- setTimeout(operation(function() {
1864
- if (bracketHighlighted) {bracketHighlighted(); bracketHighlighted = null;}
1865
- if (posEq(sel.from, sel.to)) matchBrackets(false);
1866
- }), 20);
1867
- var tc = textChanged, cbs = callbacks; // these can be reset by callbacks
1868
- if (selectionChanged && options.onCursorActivity)
1869
- options.onCursorActivity(instance);
1870
- if (tc && options.onChange && instance)
1871
- options.onChange(instance, tc);
1872
- for (var i = 0; i < cbs.length; ++i) cbs[i](instance);
1873
- if (updated && options.onUpdate) options.onUpdate(instance);
1874
- }
1875
- var nestedOperation = 0;
1876
- function operation(f) {
1877
- return function() {
1878
- if (!nestedOperation++) startOperation();
1879
- try {var result = f.apply(this, arguments);}
1880
- finally {if (!--nestedOperation) endOperation();}
1881
- return result;
1882
- };
1883
- }
1884
-
1885
- function compoundChange(f) {
1886
- history.startCompound();
1887
- try { return f(); } finally { history.endCompound(); }
1888
- }
1889
-
1890
- for (var ext in extensions)
1891
- if (extensions.propertyIsEnumerable(ext) &&
1892
- !instance.propertyIsEnumerable(ext))
1893
- instance[ext] = extensions[ext];
1894
- return instance;
1895
- } // (end of function CodeMirror)
1896
-
1897
- // The default configuration options.
1898
- CodeMirror.defaults = {
1899
- value: "",
1900
- mode: null,
1901
- theme: "default",
1902
- indentUnit: 2,
1903
- indentWithTabs: false,
1904
- smartIndent: true,
1905
- tabSize: 4,
1906
- keyMap: "default",
1907
- extraKeys: null,
1908
- electricChars: true,
1909
- autoClearEmptyLines: false,
1910
- onKeyEvent: null,
1911
- onDragEvent: null,
1912
- lineWrapping: false,
1913
- lineNumbers: false,
1914
- gutter: false,
1915
- fixedGutter: false,
1916
- firstLineNumber: 1,
1917
- readOnly: false,
1918
- dragDrop: true,
1919
- onChange: null,
1920
- onCursorActivity: null,
1921
- onGutterClick: null,
1922
- onHighlightComplete: null,
1923
- onUpdate: null,
1924
- onFocus: null, onBlur: null, onScroll: null,
1925
- matchBrackets: false,
1926
- workTime: 100,
1927
- workDelay: 200,
1928
- pollInterval: 100,
1929
- undoDepth: 40,
1930
- tabindex: null,
1931
- autofocus: null
1932
- };
1933
-
1934
- var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
1935
- var mac = ios || /Mac/.test(navigator.platform);
1936
- var win = /Win/.test(navigator.platform);
1937
-
1938
- // Known modes, by name and by MIME
1939
- var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
1940
- CodeMirror.defineMode = function(name, mode) {
1941
- if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
1942
- if (arguments.length > 2) {
1943
- mode.dependencies = [];
1944
- for (var i = 2; i < arguments.length; ++i) mode.dependencies.push(arguments[i]);
1945
- }
1946
- modes[name] = mode;
1947
- };
1948
- CodeMirror.defineMIME = function(mime, spec) {
1949
- mimeModes[mime] = spec;
1950
- };
1951
- CodeMirror.resolveMode = function(spec) {
1952
- if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
1953
- spec = mimeModes[spec];
1954
- else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec))
1955
- return CodeMirror.resolveMode("application/xml");
1956
- if (typeof spec == "string") return {name: spec};
1957
- else return spec || {name: "null"};
1958
- };
1959
- CodeMirror.getMode = function(options, spec) {
1960
- var spec = CodeMirror.resolveMode(spec);
1961
- var mfactory = modes[spec.name];
1962
- if (!mfactory) return CodeMirror.getMode(options, "text/plain");
1963
- return mfactory(options, spec);
1964
- };
1965
- CodeMirror.listModes = function() {
1966
- var list = [];
1967
- for (var m in modes)
1968
- if (modes.propertyIsEnumerable(m)) list.push(m);
1969
- return list;
1970
- };
1971
- CodeMirror.listMIMEs = function() {
1972
- var list = [];
1973
- for (var m in mimeModes)
1974
- if (mimeModes.propertyIsEnumerable(m)) list.push({mime: m, mode: mimeModes[m]});
1975
- return list;
1976
- };
1977
-
1978
- var extensions = CodeMirror.extensions = {};
1979
- CodeMirror.defineExtension = function(name, func) {
1980
- extensions[name] = func;
1981
- };
1982
-
1983
- var commands = CodeMirror.commands = {
1984
- selectAll: function(cm) {cm.setSelection({line: 0, ch: 0}, {line: cm.lineCount() - 1});},
1985
- killLine: function(cm) {
1986
- var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
1987
- if (!sel && cm.getLine(from.line).length == from.ch) cm.replaceRange("", from, {line: from.line + 1, ch: 0});
1988
- else cm.replaceRange("", from, sel ? to : {line: from.line});
1989
- },
1990
- deleteLine: function(cm) {var l = cm.getCursor().line; cm.replaceRange("", {line: l, ch: 0}, {line: l});},
1991
- undo: function(cm) {cm.undo();},
1992
- redo: function(cm) {cm.redo();},
1993
- goDocStart: function(cm) {cm.setCursor(0, 0, true);},
1994
- goDocEnd: function(cm) {cm.setSelection({line: cm.lineCount() - 1}, null, true);},
1995
- goLineStart: function(cm) {cm.setCursor(cm.getCursor().line, 0, true);},
1996
- goLineStartSmart: function(cm) {
1997
- var cur = cm.getCursor();
1998
- var text = cm.getLine(cur.line), firstNonWS = Math.max(0, text.search(/\S/));
1999
- cm.setCursor(cur.line, cur.ch <= firstNonWS && cur.ch ? 0 : firstNonWS, true);
2000
- },
2001
- goLineEnd: function(cm) {cm.setSelection({line: cm.getCursor().line}, null, true);},
2002
- goLineUp: function(cm) {cm.moveV(-1, "line");},
2003
- goLineDown: function(cm) {cm.moveV(1, "line");},
2004
- goPageUp: function(cm) {cm.moveV(-1, "page");},
2005
- goPageDown: function(cm) {cm.moveV(1, "page");},
2006
- goCharLeft: function(cm) {cm.moveH(-1, "char");},
2007
- goCharRight: function(cm) {cm.moveH(1, "char");},
2008
- goColumnLeft: function(cm) {cm.moveH(-1, "column");},
2009
- goColumnRight: function(cm) {cm.moveH(1, "column");},
2010
- goWordLeft: function(cm) {cm.moveH(-1, "word");},
2011
- goWordRight: function(cm) {cm.moveH(1, "word");},
2012
- delCharLeft: function(cm) {cm.deleteH(-1, "char");},
2013
- delCharRight: function(cm) {cm.deleteH(1, "char");},
2014
- delWordLeft: function(cm) {cm.deleteH(-1, "word");},
2015
- delWordRight: function(cm) {cm.deleteH(1, "word");},
2016
- indentAuto: function(cm) {cm.indentSelection("smart");},
2017
- indentMore: function(cm) {cm.indentSelection("add");},
2018
- indentLess: function(cm) {cm.indentSelection("subtract");},
2019
- insertTab: function(cm) {cm.replaceSelection("\t", "end");},
2020
- defaultTab: function(cm) {
2021
- if (cm.somethingSelected()) cm.indentSelection("add");
2022
- else cm.replaceSelection("\t", "end");
2023
- },
2024
- transposeChars: function(cm) {
2025
- var cur = cm.getCursor(), line = cm.getLine(cur.line);
2026
- if (cur.ch > 0 && cur.ch < line.length - 1)
2027
- cm.replaceRange(line.charAt(cur.ch) + line.charAt(cur.ch - 1),
2028
- {line: cur.line, ch: cur.ch - 1}, {line: cur.line, ch: cur.ch + 1});
2029
- },
2030
- newlineAndIndent: function(cm) {
2031
- cm.replaceSelection("\n", "end");
2032
- cm.indentLine(cm.getCursor().line);
2033
- },
2034
- toggleOverwrite: function(cm) {cm.toggleOverwrite();}
2035
- };
2036
-
2037
- var keyMap = CodeMirror.keyMap = {};
2038
- keyMap.basic = {
2039
- "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
2040
- "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
2041
- "Delete": "delCharRight", "Backspace": "delCharLeft", "Tab": "defaultTab", "Shift-Tab": "indentAuto",
2042
- "Enter": "newlineAndIndent", "Insert": "toggleOverwrite"
2043
- };
2044
- // Note that the save and find-related commands aren't defined by
2045
- // default. Unknown commands are simply ignored.
2046
- keyMap.pcDefault = {
2047
- "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
2048
- "Ctrl-Home": "goDocStart", "Alt-Up": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Down": "goDocEnd",
2049
- "Ctrl-Left": "goWordLeft", "Ctrl-Right": "goWordRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
2050
- "Ctrl-Backspace": "delWordLeft", "Ctrl-Delete": "delWordRight", "Ctrl-S": "save", "Ctrl-F": "find",
2051
- "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
2052
- "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
2053
- fallthrough: "basic"
2054
- };
2055
- keyMap.macDefault = {
2056
- "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
2057
- "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goWordLeft",
2058
- "Alt-Right": "goWordRight", "Cmd-Left": "goLineStart", "Cmd-Right": "goLineEnd", "Alt-Backspace": "delWordLeft",
2059
- "Ctrl-Alt-Backspace": "delWordRight", "Alt-Delete": "delWordRight", "Cmd-S": "save", "Cmd-F": "find",
2060
- "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
2061
- "Cmd-[": "indentLess", "Cmd-]": "indentMore",
2062
- fallthrough: ["basic", "emacsy"]
2063
- };
2064
- keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
2065
- keyMap.emacsy = {
2066
- "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
2067
- "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
2068
- "Ctrl-V": "goPageUp", "Shift-Ctrl-V": "goPageDown", "Ctrl-D": "delCharRight", "Ctrl-H": "delCharLeft",
2069
- "Alt-D": "delWordRight", "Alt-Backspace": "delWordLeft", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
2070
- };
2071
-
2072
- function getKeyMap(val) {
2073
- if (typeof val == "string") return keyMap[val];
2074
- else return val;
2075
- }
2076
- function lookupKey(name, extraMap, map, handle, stop) {
2077
- function lookup(map) {
2078
- map = getKeyMap(map);
2079
- var found = map[name];
2080
- if (found != null && handle(found)) return true;
2081
- if (map.nofallthrough) {
2082
- if (stop) stop();
2083
- return true;
2084
- }
2085
- var fallthrough = map.fallthrough;
2086
- if (fallthrough == null) return false;
2087
- if (Object.prototype.toString.call(fallthrough) != "[object Array]")
2088
- return lookup(fallthrough);
2089
- for (var i = 0, e = fallthrough.length; i < e; ++i) {
2090
- if (lookup(fallthrough[i])) return true;
2091
- }
2092
- return false;
2093
- }
2094
- if (extraMap && lookup(extraMap)) return true;
2095
- return lookup(map);
2096
- }
2097
- function isModifierKey(event) {
2098
- var name = keyNames[e_prop(event, "keyCode")];
2099
- return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
2100
- }
2101
-
2102
- CodeMirror.fromTextArea = function(textarea, options) {
2103
- if (!options) options = {};
2104
- options.value = textarea.value;
2105
- if (!options.tabindex && textarea.tabindex)
2106
- options.tabindex = textarea.tabindex;
2107
- if (options.autofocus == null && textarea.getAttribute("autofocus") != null)
2108
- options.autofocus = true;
2109
-
2110
- function save() {textarea.value = instance.getValue();}
2111
- if (textarea.form) {
2112
- // Deplorable hack to make the submit method do the right thing.
2113
- var rmSubmit = connect(textarea.form, "submit", save, true);
2114
- if (typeof textarea.form.submit == "function") {
2115
- var realSubmit = textarea.form.submit;
2116
- function wrappedSubmit() {
2117
- save();
2118
- textarea.form.submit = realSubmit;
2119
- textarea.form.submit();
2120
- textarea.form.submit = wrappedSubmit;
2121
- }
2122
- textarea.form.submit = wrappedSubmit;
2123
- }
2124
- }
2125
-
2126
- textarea.style.display = "none";
2127
- var instance = CodeMirror(function(node) {
2128
- textarea.parentNode.insertBefore(node, textarea.nextSibling);
2129
- }, options);
2130
- instance.save = save;
2131
- instance.getTextArea = function() { return textarea; };
2132
- instance.toTextArea = function() {
2133
- save();
2134
- textarea.parentNode.removeChild(instance.getWrapperElement());
2135
- textarea.style.display = "";
2136
- if (textarea.form) {
2137
- rmSubmit();
2138
- if (typeof textarea.form.submit == "function")
2139
- textarea.form.submit = realSubmit;
2140
- }
2141
- };
2142
- return instance;
2143
- };
2144
-
2145
- // Utility functions for working with state. Exported because modes
2146
- // sometimes need to do this.
2147
- function copyState(mode, state) {
2148
- if (state === true) return state;
2149
- if (mode.copyState) return mode.copyState(state);
2150
- var nstate = {};
2151
- for (var n in state) {
2152
- var val = state[n];
2153
- if (val instanceof Array) val = val.concat([]);
2154
- nstate[n] = val;
2155
- }
2156
- return nstate;
2157
- }
2158
- CodeMirror.copyState = copyState;
2159
- function startState(mode, a1, a2) {
2160
- return mode.startState ? mode.startState(a1, a2) : true;
2161
- }
2162
- CodeMirror.startState = startState;
2163
-
2164
- // The character stream used by a mode's parser.
2165
- function StringStream(string, tabSize) {
2166
- this.pos = this.start = 0;
2167
- this.string = string;
2168
- this.tabSize = tabSize || 8;
2169
- }
2170
- StringStream.prototype = {
2171
- eol: function() {return this.pos >= this.string.length;},
2172
- sol: function() {return this.pos == 0;},
2173
- peek: function() {return this.string.charAt(this.pos);},
2174
- next: function() {
2175
- if (this.pos < this.string.length)
2176
- return this.string.charAt(this.pos++);
2177
- },
2178
- eat: function(match) {
2179
- var ch = this.string.charAt(this.pos);
2180
- if (typeof match == "string") var ok = ch == match;
2181
- else var ok = ch && (match.test ? match.test(ch) : match(ch));
2182
- if (ok) {++this.pos; return ch;}
2183
- },
2184
- eatWhile: function(match) {
2185
- var start = this.pos;
2186
- while (this.eat(match)){}
2187
- return this.pos > start;
2188
- },
2189
- eatSpace: function() {
2190
- var start = this.pos;
2191
- while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
2192
- return this.pos > start;
2193
- },
2194
- skipToEnd: function() {this.pos = this.string.length;},
2195
- skipTo: function(ch) {
2196
- var found = this.string.indexOf(ch, this.pos);
2197
- if (found > -1) {this.pos = found; return true;}
2198
- },
2199
- backUp: function(n) {this.pos -= n;},
2200
- column: function() {return countColumn(this.string, this.start, this.tabSize);},
2201
- indentation: function() {return countColumn(this.string, null, this.tabSize);},
2202
- match: function(pattern, consume, caseInsensitive) {
2203
- if (typeof pattern == "string") {
2204
- function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
2205
- if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
2206
- if (consume !== false) this.pos += pattern.length;
2207
- return true;
2208
- }
2209
- }
2210
- else {
2211
- var match = this.string.slice(this.pos).match(pattern);
2212
- if (match && consume !== false) this.pos += match[0].length;
2213
- return match;
2214
- }
2215
- },
2216
- current: function(){return this.string.slice(this.start, this.pos);}
2217
- };
2218
- CodeMirror.StringStream = StringStream;
2219
-
2220
- function MarkedText(from, to, className, marker) {
2221
- this.from = from; this.to = to; this.style = className; this.marker = marker;
2222
- }
2223
- MarkedText.prototype = {
2224
- attach: function(line) { this.marker.set.push(line); },
2225
- detach: function(line) {
2226
- var ix = indexOf(this.marker.set, line);
2227
- if (ix > -1) this.marker.set.splice(ix, 1);
2228
- },
2229
- split: function(pos, lenBefore) {
2230
- if (this.to <= pos && this.to != null) return null;
2231
- var from = this.from < pos || this.from == null ? null : this.from - pos + lenBefore;
2232
- var to = this.to == null ? null : this.to - pos + lenBefore;
2233
- return new MarkedText(from, to, this.style, this.marker);
2234
- },
2235
- dup: function() { return new MarkedText(null, null, this.style, this.marker); },
2236
- clipTo: function(fromOpen, from, toOpen, to, diff) {
2237
- if (fromOpen && to > this.from && (to < this.to || this.to == null))
2238
- this.from = null;
2239
- else if (this.from != null && this.from >= from)
2240
- this.from = Math.max(to, this.from) + diff;
2241
- if (toOpen && (from < this.to || this.to == null) && (from > this.from || this.from == null))
2242
- this.to = null;
2243
- else if (this.to != null && this.to > from)
2244
- this.to = to < this.to ? this.to + diff : from;
2245
- },
2246
- isDead: function() { return this.from != null && this.to != null && this.from >= this.to; },
2247
- sameSet: function(x) { return this.marker == x.marker; }
2248
- };
2249
-
2250
- function Bookmark(pos) {
2251
- this.from = pos; this.to = pos; this.line = null;
2252
- }
2253
- Bookmark.prototype = {
2254
- attach: function(line) { this.line = line; },
2255
- detach: function(line) { if (this.line == line) this.line = null; },
2256
- split: function(pos, lenBefore) {
2257
- if (pos < this.from) {
2258
- this.from = this.to = (this.from - pos) + lenBefore;
2259
- return this;
2260
- }
2261
- },
2262
- isDead: function() { return this.from > this.to; },
2263
- clipTo: function(fromOpen, from, toOpen, to, diff) {
2264
- if ((fromOpen || from < this.from) && (toOpen || to > this.to)) {
2265
- this.from = 0; this.to = -1;
2266
- } else if (this.from > from) {
2267
- this.from = this.to = Math.max(to, this.from) + diff;
2268
- }
2269
- },
2270
- sameSet: function(x) { return false; },
2271
- find: function() {
2272
- if (!this.line || !this.line.parent) return null;
2273
- return {line: lineNo(this.line), ch: this.from};
2274
- },
2275
- clear: function() {
2276
- if (this.line) {
2277
- var found = indexOf(this.line.marked, this);
2278
- if (found != -1) this.line.marked.splice(found, 1);
2279
- this.line = null;
2280
- }
2281
- }
2282
- };
2283
-
2284
- // Line objects. These hold state related to a line, including
2285
- // highlighting info (the styles array).
2286
- function Line(text, styles) {
2287
- this.styles = styles || [text, null];
2288
- this.text = text;
2289
- this.height = 1;
2290
- this.marked = this.gutterMarker = this.className = this.bgClassName = this.handlers = null;
2291
- this.stateAfter = this.parent = this.hidden = null;
2292
- }
2293
- Line.inheritMarks = function(text, orig) {
2294
- var ln = new Line(text), mk = orig && orig.marked;
2295
- if (mk) {
2296
- for (var i = 0; i < mk.length; ++i) {
2297
- if (mk[i].to == null && mk[i].style) {
2298
- var newmk = ln.marked || (ln.marked = []), mark = mk[i];
2299
- var nmark = mark.dup(); newmk.push(nmark); nmark.attach(ln);
2300
- }
2301
- }
2302
- }
2303
- return ln;
2304
- }
2305
- Line.prototype = {
2306
- // Replace a piece of a line, keeping the styles around it intact.
2307
- replace: function(from, to_, text) {
2308
- var st = [], mk = this.marked, to = to_ == null ? this.text.length : to_;
2309
- copyStyles(0, from, this.styles, st);
2310
- if (text) st.push(text, null);
2311
- copyStyles(to, this.text.length, this.styles, st);
2312
- this.styles = st;
2313
- this.text = this.text.slice(0, from) + text + this.text.slice(to);
2314
- this.stateAfter = null;
2315
- if (mk) {
2316
- var diff = text.length - (to - from);
2317
- for (var i = 0; i < mk.length; ++i) {
2318
- var mark = mk[i];
2319
- mark.clipTo(from == null, from || 0, to_ == null, to, diff);
2320
- if (mark.isDead()) {mark.detach(this); mk.splice(i--, 1);}
2321
- }
2322
- }
2323
- },
2324
- // Split a part off a line, keeping styles and markers intact.
2325
- split: function(pos, textBefore) {
2326
- var st = [textBefore, null], mk = this.marked;
2327
- copyStyles(pos, this.text.length, this.styles, st);
2328
- var taken = new Line(textBefore + this.text.slice(pos), st);
2329
- if (mk) {
2330
- for (var i = 0; i < mk.length; ++i) {
2331
- var mark = mk[i];
2332
- var newmark = mark.split(pos, textBefore.length);
2333
- if (newmark) {
2334
- if (!taken.marked) taken.marked = [];
2335
- taken.marked.push(newmark); newmark.attach(taken);
2336
- if (newmark == mark) mk.splice(i--, 1);
2337
- }
2338
- }
2339
- }
2340
- return taken;
2341
- },
2342
- append: function(line) {
2343
- var mylen = this.text.length, mk = line.marked, mymk = this.marked;
2344
- this.text += line.text;
2345
- copyStyles(0, line.text.length, line.styles, this.styles);
2346
- if (mymk) {
2347
- for (var i = 0; i < mymk.length; ++i)
2348
- if (mymk[i].to == null) mymk[i].to = mylen;
2349
- }
2350
- if (mk && mk.length) {
2351
- if (!mymk) this.marked = mymk = [];
2352
- outer: for (var i = 0; i < mk.length; ++i) {
2353
- var mark = mk[i];
2354
- if (!mark.from) {
2355
- for (var j = 0; j < mymk.length; ++j) {
2356
- var mymark = mymk[j];
2357
- if (mymark.to == mylen && mymark.sameSet(mark)) {
2358
- mymark.to = mark.to == null ? null : mark.to + mylen;
2359
- if (mymark.isDead()) {
2360
- mymark.detach(this);
2361
- mk.splice(i--, 1);
2362
- }
2363
- continue outer;
2364
- }
2365
- }
2366
- }
2367
- mymk.push(mark);
2368
- mark.attach(this);
2369
- mark.from += mylen;
2370
- if (mark.to != null) mark.to += mylen;
2371
- }
2372
- }
2373
- },
2374
- fixMarkEnds: function(other) {
2375
- var mk = this.marked, omk = other.marked;
2376
- if (!mk) return;
2377
- for (var i = 0; i < mk.length; ++i) {
2378
- var mark = mk[i], close = mark.to == null;
2379
- if (close && omk) {
2380
- for (var j = 0; j < omk.length; ++j)
2381
- if (omk[j].sameSet(mark)) {close = false; break;}
2382
- }
2383
- if (close) mark.to = this.text.length;
2384
- }
2385
- },
2386
- fixMarkStarts: function() {
2387
- var mk = this.marked;
2388
- if (!mk) return;
2389
- for (var i = 0; i < mk.length; ++i)
2390
- if (mk[i].from == null) mk[i].from = 0;
2391
- },
2392
- addMark: function(mark) {
2393
- mark.attach(this);
2394
- if (this.marked == null) this.marked = [];
2395
- this.marked.push(mark);
2396
- this.marked.sort(function(a, b){return (a.from || 0) - (b.from || 0);});
2397
- },
2398
- // Run the given mode's parser over a line, update the styles
2399
- // array, which contains alternating fragments of text and CSS
2400
- // classes.
2401
- highlight: function(mode, state, tabSize) {
2402
- var stream = new StringStream(this.text, tabSize), st = this.styles, pos = 0;
2403
- var changed = false, curWord = st[0], prevWord;
2404
- if (this.text == "" && mode.blankLine) mode.blankLine(state);
2405
- while (!stream.eol()) {
2406
- var style = mode.token(stream, state);
2407
- var substr = this.text.slice(stream.start, stream.pos);
2408
- stream.start = stream.pos;
2409
- if (pos && st[pos-1] == style)
2410
- st[pos-2] += substr;
2411
- else if (substr) {
2412
- if (!changed && (st[pos+1] != style || (pos && st[pos-2] != prevWord))) changed = true;
2413
- st[pos++] = substr; st[pos++] = style;
2414
- prevWord = curWord; curWord = st[pos];
2415
- }
2416
- // Give up when line is ridiculously long
2417
- if (stream.pos > 5000) {
2418
- st[pos++] = this.text.slice(stream.pos); st[pos++] = null;
2419
- break;
2420
- }
2421
- }
2422
- if (st.length != pos) {st.length = pos; changed = true;}
2423
- if (pos && st[pos-2] != prevWord) changed = true;
2424
- // Short lines with simple highlights return null, and are
2425
- // counted as changed by the driver because they are likely to
2426
- // highlight the same way in various contexts.
2427
- return changed || (st.length < 5 && this.text.length < 10 ? null : false);
2428
- },
2429
- // Fetch the parser token for a given character. Useful for hacks
2430
- // that want to inspect the mode state (say, for completion).
2431
- getTokenAt: function(mode, state, ch) {
2432
- var txt = this.text, stream = new StringStream(txt);
2433
- while (stream.pos < ch && !stream.eol()) {
2434
- stream.start = stream.pos;
2435
- var style = mode.token(stream, state);
2436
- }
2437
- return {start: stream.start,
2438
- end: stream.pos,
2439
- string: stream.current(),
2440
- className: style || null,
2441
- state: state};
2442
- },
2443
- indentation: function(tabSize) {return countColumn(this.text, null, tabSize);},
2444
- // Produces an HTML fragment for the line, taking selection,
2445
- // marking, and highlighting into account.
2446
- getHTML: function(makeTab, wrapAt, wrapId, wrapWBR) {
2447
- var html = [], first = true, col = 0;
2448
- function span_(text, style) {
2449
- if (!text) return;
2450
- // Work around a bug where, in some compat modes, IE ignores leading spaces
2451
- if (first && ie && text.charAt(0) == " ") text = "\u00a0" + text.slice(1);
2452
- first = false;
2453
- if (text.indexOf("\t") == -1) {
2454
- col += text.length;
2455
- var escaped = htmlEscape(text);
2456
- } else {
2457
- var escaped = "";
2458
- for (var pos = 0;;) {
2459
- var idx = text.indexOf("\t", pos);
2460
- if (idx == -1) {
2461
- escaped += htmlEscape(text.slice(pos));
2462
- col += text.length - pos;
2463
- break;
2464
- } else {
2465
- col += idx - pos;
2466
- var tab = makeTab(col);
2467
- escaped += htmlEscape(text.slice(pos, idx)) + tab.html;
2468
- col += tab.width;
2469
- pos = idx + 1;
2470
- }
2471
- }
2472
- }
2473
- if (style) html.push('<span class="', style, '">', escaped, "</span>");
2474
- else html.push(escaped);
2475
- }
2476
- var span = span_;
2477
- if (wrapAt != null) {
2478
- var outPos = 0, open = "<span id=\"" + wrapId + "\">";
2479
- span = function(text, style) {
2480
- var l = text.length;
2481
- if (wrapAt >= outPos && wrapAt < outPos + l) {
2482
- if (wrapAt > outPos) {
2483
- span_(text.slice(0, wrapAt - outPos), style);
2484
- // See comment at the definition of spanAffectsWrapping
2485
- if (wrapWBR) html.push("<wbr>");
2486
- }
2487
- html.push(open);
2488
- var cut = wrapAt - outPos;
2489
- span_(window.opera ? text.slice(cut, cut + 1) : text.slice(cut), style);
2490
- html.push("</span>");
2491
- if (window.opera) span_(text.slice(cut + 1), style);
2492
- wrapAt--;
2493
- outPos += l;
2494
- } else {
2495
- outPos += l;
2496
- span_(text, style);
2497
- // Output empty wrapper when at end of line
2498
- if (outPos == wrapAt && outPos == len) html.push(open + " </span>");
2499
- // Stop outputting HTML when gone sufficiently far beyond measure
2500
- else if (outPos > wrapAt + 10 && /\s/.test(text)) span = function(){};
2501
- }
2502
- }
2503
- }
2504
-
2505
- var st = this.styles, allText = this.text, marked = this.marked;
2506
- var len = allText.length;
2507
- function styleToClass(style) {
2508
- if (!style) return null;
2509
- return "cm-" + style.replace(/ +/g, " cm-");
2510
- }
2511
-
2512
- if (!allText && wrapAt == null) {
2513
- span(" ");
2514
- } else if (!marked || !marked.length) {
2515
- for (var i = 0, ch = 0; ch < len; i+=2) {
2516
- var str = st[i], style = st[i+1], l = str.length;
2517
- if (ch + l > len) str = str.slice(0, len - ch);
2518
- ch += l;
2519
- span(str, styleToClass(style));
2520
- }
2521
- } else {
2522
- var pos = 0, i = 0, text = "", style, sg = 0;
2523
- var nextChange = marked[0].from || 0, marks = [], markpos = 0;
2524
- function advanceMarks() {
2525
- var m;
2526
- while (markpos < marked.length &&
2527
- ((m = marked[markpos]).from == pos || m.from == null)) {
2528
- if (m.style != null) marks.push(m);
2529
- ++markpos;
2530
- }
2531
- nextChange = markpos < marked.length ? marked[markpos].from : Infinity;
2532
- for (var i = 0; i < marks.length; ++i) {
2533
- var to = marks[i].to || Infinity;
2534
- if (to == pos) marks.splice(i--, 1);
2535
- else nextChange = Math.min(to, nextChange);
2536
- }
2537
- }
2538
- var m = 0;
2539
- while (pos < len) {
2540
- if (nextChange == pos) advanceMarks();
2541
- var upto = Math.min(len, nextChange);
2542
- while (true) {
2543
- if (text) {
2544
- var end = pos + text.length;
2545
- var appliedStyle = style;
2546
- for (var j = 0; j < marks.length; ++j)
2547
- appliedStyle = (appliedStyle ? appliedStyle + " " : "") + marks[j].style;
2548
- span(end > upto ? text.slice(0, upto - pos) : text, appliedStyle);
2549
- if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
2550
- pos = end;
2551
- }
2552
- text = st[i++]; style = styleToClass(st[i++]);
2553
- }
2554
- }
2555
- }
2556
- return html.join("");
2557
- },
2558
- cleanUp: function() {
2559
- this.parent = null;
2560
- if (this.marked)
2561
- for (var i = 0, e = this.marked.length; i < e; ++i) this.marked[i].detach(this);
2562
- }
2563
- };
2564
- // Utility used by replace and split above
2565
- function copyStyles(from, to, source, dest) {
2566
- for (var i = 0, pos = 0, state = 0; pos < to; i+=2) {
2567
- var part = source[i], end = pos + part.length;
2568
- if (state == 0) {
2569
- if (end > from) dest.push(part.slice(from - pos, Math.min(part.length, to - pos)), source[i+1]);
2570
- if (end >= from) state = 1;
2571
- }
2572
- else if (state == 1) {
2573
- if (end > to) dest.push(part.slice(0, to - pos), source[i+1]);
2574
- else dest.push(part, source[i+1]);
2575
- }
2576
- pos = end;
2577
- }
2578
- }
2579
-
2580
- // Data structure that holds the sequence of lines.
2581
- function LeafChunk(lines) {
2582
- this.lines = lines;
2583
- this.parent = null;
2584
- for (var i = 0, e = lines.length, height = 0; i < e; ++i) {
2585
- lines[i].parent = this;
2586
- height += lines[i].height;
2587
- }
2588
- this.height = height;
2589
- }
2590
- LeafChunk.prototype = {
2591
- chunkSize: function() { return this.lines.length; },
2592
- remove: function(at, n, callbacks) {
2593
- for (var i = at, e = at + n; i < e; ++i) {
2594
- var line = this.lines[i];
2595
- this.height -= line.height;
2596
- line.cleanUp();
2597
- if (line.handlers)
2598
- for (var j = 0; j < line.handlers.length; ++j) callbacks.push(line.handlers[j]);
2599
- }
2600
- this.lines.splice(at, n);
2601
- },
2602
- collapse: function(lines) {
2603
- lines.splice.apply(lines, [lines.length, 0].concat(this.lines));
2604
- },
2605
- insertHeight: function(at, lines, height) {
2606
- this.height += height;
2607
- // The trick below is apparently too advanced for IE, which
2608
- // occasionally corrupts this.lines (duplicating elements) when
2609
- // it is used.
2610
- if (ie) this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
2611
- else this.lines.splice.apply(this.lines, [at, 0].concat(lines));
2612
- for (var i = 0, e = lines.length; i < e; ++i) lines[i].parent = this;
2613
- },
2614
- iterN: function(at, n, op) {
2615
- for (var e = at + n; at < e; ++at)
2616
- if (op(this.lines[at])) return true;
2617
- }
2618
- };
2619
- function BranchChunk(children) {
2620
- this.children = children;
2621
- var size = 0, height = 0;
2622
- for (var i = 0, e = children.length; i < e; ++i) {
2623
- var ch = children[i];
2624
- size += ch.chunkSize(); height += ch.height;
2625
- ch.parent = this;
2626
- }
2627
- this.size = size;
2628
- this.height = height;
2629
- this.parent = null;
2630
- }
2631
- BranchChunk.prototype = {
2632
- chunkSize: function() { return this.size; },
2633
- remove: function(at, n, callbacks) {
2634
- this.size -= n;
2635
- for (var i = 0; i < this.children.length; ++i) {
2636
- var child = this.children[i], sz = child.chunkSize();
2637
- if (at < sz) {
2638
- var rm = Math.min(n, sz - at), oldHeight = child.height;
2639
- child.remove(at, rm, callbacks);
2640
- this.height -= oldHeight - child.height;
2641
- if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
2642
- if ((n -= rm) == 0) break;
2643
- at = 0;
2644
- } else at -= sz;
2645
- }
2646
- if (this.size - n < 25) {
2647
- var lines = [];
2648
- this.collapse(lines);
2649
- this.children = [new LeafChunk(lines)];
2650
- this.children[0].parent = this;
2651
- }
2652
- },
2653
- collapse: function(lines) {
2654
- for (var i = 0, e = this.children.length; i < e; ++i) this.children[i].collapse(lines);
2655
- },
2656
- insert: function(at, lines) {
2657
- var height = 0;
2658
- for (var i = 0, e = lines.length; i < e; ++i) height += lines[i].height;
2659
- this.insertHeight(at, lines, height);
2660
- },
2661
- insertHeight: function(at, lines, height) {
2662
- this.size += lines.length;
2663
- this.height += height;
2664
- for (var i = 0, e = this.children.length; i < e; ++i) {
2665
- var child = this.children[i], sz = child.chunkSize();
2666
- if (at <= sz) {
2667
- child.insertHeight(at, lines, height);
2668
- if (child.lines && child.lines.length > 50) {
2669
- while (child.lines.length > 50) {
2670
- var spilled = child.lines.splice(child.lines.length - 25, 25);
2671
- var newleaf = new LeafChunk(spilled);
2672
- child.height -= newleaf.height;
2673
- this.children.splice(i + 1, 0, newleaf);
2674
- newleaf.parent = this;
2675
- }
2676
- this.maybeSpill();
2677
- }
2678
- break;
2679
- }
2680
- at -= sz;
2681
- }
2682
- },
2683
- maybeSpill: function() {
2684
- if (this.children.length <= 10) return;
2685
- var me = this;
2686
- do {
2687
- var spilled = me.children.splice(me.children.length - 5, 5);
2688
- var sibling = new BranchChunk(spilled);
2689
- if (!me.parent) { // Become the parent node
2690
- var copy = new BranchChunk(me.children);
2691
- copy.parent = me;
2692
- me.children = [copy, sibling];
2693
- me = copy;
2694
- } else {
2695
- me.size -= sibling.size;
2696
- me.height -= sibling.height;
2697
- var myIndex = indexOf(me.parent.children, me);
2698
- me.parent.children.splice(myIndex + 1, 0, sibling);
2699
- }
2700
- sibling.parent = me.parent;
2701
- } while (me.children.length > 10);
2702
- me.parent.maybeSpill();
2703
- },
2704
- iter: function(from, to, op) { this.iterN(from, to - from, op); },
2705
- iterN: function(at, n, op) {
2706
- for (var i = 0, e = this.children.length; i < e; ++i) {
2707
- var child = this.children[i], sz = child.chunkSize();
2708
- if (at < sz) {
2709
- var used = Math.min(n, sz - at);
2710
- if (child.iterN(at, used, op)) return true;
2711
- if ((n -= used) == 0) break;
2712
- at = 0;
2713
- } else at -= sz;
2714
- }
2715
- }
2716
- };
2717
-
2718
- function getLineAt(chunk, n) {
2719
- while (!chunk.lines) {
2720
- for (var i = 0;; ++i) {
2721
- var child = chunk.children[i], sz = child.chunkSize();
2722
- if (n < sz) { chunk = child; break; }
2723
- n -= sz;
2724
- }
2725
- }
2726
- return chunk.lines[n];
2727
- }
2728
- function lineNo(line) {
2729
- if (line.parent == null) return null;
2730
- var cur = line.parent, no = indexOf(cur.lines, line);
2731
- for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
2732
- for (var i = 0, e = chunk.children.length; ; ++i) {
2733
- if (chunk.children[i] == cur) break;
2734
- no += chunk.children[i].chunkSize();
2735
- }
2736
- }
2737
- return no;
2738
- }
2739
- function lineAtHeight(chunk, h) {
2740
- var n = 0;
2741
- outer: do {
2742
- for (var i = 0, e = chunk.children.length; i < e; ++i) {
2743
- var child = chunk.children[i], ch = child.height;
2744
- if (h < ch) { chunk = child; continue outer; }
2745
- h -= ch;
2746
- n += child.chunkSize();
2747
- }
2748
- return n;
2749
- } while (!chunk.lines);
2750
- for (var i = 0, e = chunk.lines.length; i < e; ++i) {
2751
- var line = chunk.lines[i], lh = line.height;
2752
- if (h < lh) break;
2753
- h -= lh;
2754
- }
2755
- return n + i;
2756
- }
2757
- function heightAtLine(chunk, n) {
2758
- var h = 0;
2759
- outer: do {
2760
- for (var i = 0, e = chunk.children.length; i < e; ++i) {
2761
- var child = chunk.children[i], sz = child.chunkSize();
2762
- if (n < sz) { chunk = child; continue outer; }
2763
- n -= sz;
2764
- h += child.height;
2765
- }
2766
- return h;
2767
- } while (!chunk.lines);
2768
- for (var i = 0; i < n; ++i) h += chunk.lines[i].height;
2769
- return h;
2770
- }
2771
-
2772
- // The history object 'chunks' changes that are made close together
2773
- // and at almost the same time into bigger undoable units.
2774
- function History() {
2775
- this.time = 0;
2776
- this.done = []; this.undone = [];
2777
- this.compound = 0;
2778
- this.closed = false;
2779
- }
2780
- History.prototype = {
2781
- addChange: function(start, added, old) {
2782
- this.undone.length = 0;
2783
- var time = +new Date, cur = this.done[this.done.length - 1], last = cur && cur[cur.length - 1];
2784
- var dtime = time - this.time;
2785
-
2786
- if (this.compound && cur && !this.closed) {
2787
- cur.push({start: start, added: added, old: old});
2788
- } else if (dtime > 400 || !last || this.closed ||
2789
- last.start > start + old.length || last.start + last.added < start) {
2790
- this.done.push([{start: start, added: added, old: old}]);
2791
- this.closed = false;
2792
- } else {
2793
- var startBefore = Math.max(0, last.start - start),
2794
- endAfter = Math.max(0, (start + old.length) - (last.start + last.added));
2795
- for (var i = startBefore; i > 0; --i) last.old.unshift(old[i - 1]);
2796
- for (var i = endAfter; i > 0; --i) last.old.push(old[old.length - i]);
2797
- if (startBefore) last.start = start;
2798
- last.added += added - (old.length - startBefore - endAfter);
2799
- }
2800
- this.time = time;
2801
- },
2802
- startCompound: function() {
2803
- if (!this.compound++) this.closed = true;
2804
- },
2805
- endCompound: function() {
2806
- if (!--this.compound) this.closed = true;
2807
- }
2808
- };
2809
-
2810
- function stopMethod() {e_stop(this);}
2811
- // Ensure an event has a stop method.
2812
- function addStop(event) {
2813
- if (!event.stop) event.stop = stopMethod;
2814
- return event;
2815
- }
2816
-
2817
- function e_preventDefault(e) {
2818
- if (e.preventDefault) e.preventDefault();
2819
- else e.returnValue = false;
2820
- }
2821
- function e_stopPropagation(e) {
2822
- if (e.stopPropagation) e.stopPropagation();
2823
- else e.cancelBubble = true;
2824
- }
2825
- function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
2826
- CodeMirror.e_stop = e_stop;
2827
- CodeMirror.e_preventDefault = e_preventDefault;
2828
- CodeMirror.e_stopPropagation = e_stopPropagation;
2829
-
2830
- function e_target(e) {return e.target || e.srcElement;}
2831
- function e_button(e) {
2832
- if (e.which) return e.which;
2833
- else if (e.button & 1) return 1;
2834
- else if (e.button & 2) return 3;
2835
- else if (e.button & 4) return 2;
2836
- }
2837
-
2838
- // Allow 3rd-party code to override event properties by adding an override
2839
- // object to an event object.
2840
- function e_prop(e, prop) {
2841
- var overridden = e.override && e.override.hasOwnProperty(prop);
2842
- return overridden ? e.override[prop] : e[prop];
2843
- }
2844
-
2845
- // Event handler registration. If disconnect is true, it'll return a
2846
- // function that unregisters the handler.
2847
- function connect(node, type, handler, disconnect) {
2848
- if (typeof node.addEventListener == "function") {
2849
- node.addEventListener(type, handler, false);
2850
- if (disconnect) return function() {node.removeEventListener(type, handler, false);};
2851
- }
2852
- else {
2853
- var wrapHandler = function(event) {handler(event || window.event);};
2854
- node.attachEvent("on" + type, wrapHandler);
2855
- if (disconnect) return function() {node.detachEvent("on" + type, wrapHandler);};
2856
- }
2857
- }
2858
- CodeMirror.connect = connect;
2859
-
2860
- function Delayed() {this.id = null;}
2861
- Delayed.prototype = {set: function(ms, f) {clearTimeout(this.id); this.id = setTimeout(f, ms);}};
2862
-
2863
- var Pass = CodeMirror.Pass = {toString: function(){return "CodeMirror.Pass";}};
2864
-
2865
- var gecko = /gecko\/\d{7}/i.test(navigator.userAgent);
2866
- var ie = /MSIE \d/.test(navigator.userAgent);
2867
- var ie_lt9 = /MSIE [1-8]\b/.test(navigator.userAgent);
2868
- var quirksMode = ie && document.documentMode == 5;
2869
- var webkit = /WebKit\//.test(navigator.userAgent);
2870
- var chrome = /Chrome\//.test(navigator.userAgent);
2871
- var safari = /Apple Computer/.test(navigator.vendor);
2872
- var khtml = /KHTML\//.test(navigator.userAgent);
2873
-
2874
- // Detect drag-and-drop
2875
- var dragAndDrop = function() {
2876
- // There is *some* kind of drag-and-drop support in IE6-8, but I
2877
- // couldn't get it to work yet.
2878
- if (ie_lt9) return false;
2879
- var div = document.createElement('div');
2880
- return "draggable" in div || "dragDrop" in div;
2881
- }();
2882
-
2883
- // Feature-detect whether newlines in textareas are converted to \r\n
2884
- var lineSep = function () {
2885
- var te = document.createElement("textarea");
2886
- te.value = "foo\nbar";
2887
- if (te.value.indexOf("\r") > -1) return "\r\n";
2888
- return "\n";
2889
- }();
2890
-
2891
- // For a reason I have yet to figure out, some browsers disallow
2892
- // word wrapping between certain characters *only* if a new inline
2893
- // element is started between them. This makes it hard to reliably
2894
- // measure the position of things, since that requires inserting an
2895
- // extra span. This terribly fragile set of regexps matches the
2896
- // character combinations that suffer from this phenomenon on the
2897
- // various browsers.
2898
- var spanAffectsWrapping = /^$/; // Won't match any two-character string
2899
- if (gecko) spanAffectsWrapping = /$'/;
2900
- else if (safari) spanAffectsWrapping = /\-[^ \-?]|\?[^ !'\"\),.\-\/:;\?\]\}]/;
2901
- else if (chrome) spanAffectsWrapping = /\-[^ \-\.?]|\?[^ \-\.?\]\}:;!'\"\),\/]|[\.!\"#&%\)*+,:;=>\]|\}~][\(\{\[<]|\$'/;
2902
-
2903
- // Counts the column offset in a string, taking tabs into account.
2904
- // Used mostly to find indentation.
2905
- function countColumn(string, end, tabSize) {
2906
- if (end == null) {
2907
- end = string.search(/[^\s\u00a0]/);
2908
- if (end == -1) end = string.length;
2909
- }
2910
- for (var i = 0, n = 0; i < end; ++i) {
2911
- if (string.charAt(i) == "\t") n += tabSize - (n % tabSize);
2912
- else ++n;
2913
- }
2914
- return n;
2915
- }
2916
-
2917
- function computedStyle(elt) {
2918
- if (elt.currentStyle) return elt.currentStyle;
2919
- return window.getComputedStyle(elt, null);
2920
- }
2921
-
2922
- // Find the position of an element by following the offsetParent chain.
2923
- // If screen==true, it returns screen (rather than page) coordinates.
2924
- function eltOffset(node, screen) {
2925
- var bod = node.ownerDocument.body;
2926
- var x = 0, y = 0, skipBody = false;
2927
- for (var n = node; n; n = n.offsetParent) {
2928
- var ol = n.offsetLeft, ot = n.offsetTop;
2929
- // Firefox reports weird inverted offsets when the body has a border.
2930
- if (n == bod) { x += Math.abs(ol); y += Math.abs(ot); }
2931
- else { x += ol, y += ot; }
2932
- if (screen && computedStyle(n).position == "fixed")
2933
- skipBody = true;
2934
- }
2935
- var e = screen && !skipBody ? null : bod;
2936
- for (var n = node.parentNode; n != e; n = n.parentNode)
2937
- if (n.scrollLeft != null) { x -= n.scrollLeft; y -= n.scrollTop;}
2938
- return {left: x, top: y};
2939
- }
2940
- // Use the faster and saner getBoundingClientRect method when possible.
2941
- if (document.documentElement.getBoundingClientRect != null) eltOffset = function(node, screen) {
2942
- // Take the parts of bounding client rect that we are interested in so we are able to edit if need be,
2943
- // since the returned value cannot be changed externally (they are kept in sync as the element moves within the page)
2944
- try { var box = node.getBoundingClientRect(); box = { top: box.top, left: box.left }; }
2945
- catch(e) { box = {top: 0, left: 0}; }
2946
- if (!screen) {
2947
- // Get the toplevel scroll, working around browser differences.
2948
- if (window.pageYOffset == null) {
2949
- var t = document.documentElement || document.body.parentNode;
2950
- if (t.scrollTop == null) t = document.body;
2951
- box.top += t.scrollTop; box.left += t.scrollLeft;
2952
- } else {
2953
- box.top += window.pageYOffset; box.left += window.pageXOffset;
2954
- }
2955
- }
2956
- return box;
2957
- };
2958
-
2959
- // Get a node's text content.
2960
- function eltText(node) {
2961
- return node.textContent || node.innerText || node.nodeValue || "";
2962
- }
2963
- function selectInput(node) {
2964
- if (ios) { // Mobile Safari apparently has a bug where select() is broken.
2965
- node.selectionStart = 0;
2966
- node.selectionEnd = node.value.length;
2967
- } else node.select();
2968
- }
2969
-
2970
- // Operations on {line, ch} objects.
2971
- function posEq(a, b) {return a.line == b.line && a.ch == b.ch;}
2972
- function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);}
2973
- function copyPos(x) {return {line: x.line, ch: x.ch};}
2974
-
2975
- var escapeElement = document.createElement("pre");
2976
- function htmlEscape(str) {
2977
- escapeElement.textContent = str;
2978
- return escapeElement.innerHTML;
2979
- }
2980
- // Recent (late 2011) Opera betas insert bogus newlines at the start
2981
- // of the textContent, so we strip those.
2982
- if (htmlEscape("a") == "\na")
2983
- htmlEscape = function(str) {
2984
- escapeElement.textContent = str;
2985
- return escapeElement.innerHTML.slice(1);
2986
- };
2987
- // Some IEs don't preserve tabs through innerHTML
2988
- else if (htmlEscape("\t") != "\t")
2989
- htmlEscape = function(str) {
2990
- escapeElement.innerHTML = "";
2991
- escapeElement.appendChild(document.createTextNode(str));
2992
- return escapeElement.innerHTML;
2993
- };
2994
- CodeMirror.htmlEscape = htmlEscape;
2995
-
2996
- // Used to position the cursor after an undo/redo by finding the
2997
- // last edited character.
2998
- function editEnd(from, to) {
2999
- if (!to) return 0;
3000
- if (!from) return to.length;
3001
- for (var i = from.length, j = to.length; i >= 0 && j >= 0; --i, --j)
3002
- if (from.charAt(i) != to.charAt(j)) break;
3003
- return j + 1;
3004
- }
3005
-
3006
- function indexOf(collection, elt) {
3007
- if (collection.indexOf) return collection.indexOf(elt);
3008
- for (var i = 0, e = collection.length; i < e; ++i)
3009
- if (collection[i] == elt) return i;
3010
- return -1;
3011
- }
3012
- function isWordChar(ch) {
3013
- return /\w/.test(ch) || ch.toUpperCase() != ch.toLowerCase();
3014
- }
3015
-
3016
- // See if "".split is the broken IE version, if so, provide an
3017
- // alternative way to split lines.
3018
- var splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
3019
- var pos = 0, nl, result = [];
3020
- while ((nl = string.indexOf("\n", pos)) > -1) {
3021
- result.push(string.slice(pos, string.charAt(nl-1) == "\r" ? nl - 1 : nl));
3022
- pos = nl + 1;
3023
- }
3024
- result.push(string.slice(pos));
3025
- return result;
3026
- } : function(string){return string.split(/\r?\n/);};
3027
- CodeMirror.splitLines = splitLines;
3028
-
3029
- var hasSelection = window.getSelection ? function(te) {
3030
- try { return te.selectionStart != te.selectionEnd; }
3031
- catch(e) { return false; }
3032
- } : function(te) {
3033
- try {var range = te.ownerDocument.selection.createRange();}
3034
- catch(e) {}
3035
- if (!range || range.parentElement() != te) return false;
3036
- return range.compareEndPoints("StartToEnd", range) != 0;
3037
- };
3038
-
3039
- CodeMirror.defineMode("null", function() {
3040
- return {token: function(stream) {stream.skipToEnd();}};
3041
- });
3042
- CodeMirror.defineMIME("text/plain", "null");
3043
-
3044
- var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
3045
- 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
3046
- 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
3047
- 46: "Delete", 59: ";", 91: "Mod", 92: "Mod", 93: "Mod", 127: "Delete", 186: ";", 187: "=", 188: ",",
3048
- 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\", 221: "]", 222: "'", 63276: "PageUp",
3049
- 63277: "PageDown", 63275: "End", 63273: "Home", 63234: "Left", 63232: "Up", 63235: "Right",
3050
- 63233: "Down", 63302: "Insert", 63272: "Delete"};
3051
- CodeMirror.keyNames = keyNames;
3052
- (function() {
3053
- // Number keys
3054
- for (var i = 0; i < 10; i++) keyNames[i + 48] = String(i);
3055
- // Alphabetic keys
3056
- for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
3057
- // Function keys
3058
- for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
3059
- })();
3060
-
3061
- return CodeMirror;
3062
- })();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/mode/clike/clike.js DELETED
@@ -1,234 +0,0 @@
1
- CodeMirror.defineMode("clike", function(config, parserConfig) {
2
- var indentUnit = config.indentUnit,
3
- keywords = parserConfig.keywords || {},
4
- blockKeywords = parserConfig.blockKeywords || {},
5
- atoms = parserConfig.atoms || {},
6
- hooks = parserConfig.hooks || {},
7
- multiLineStrings = parserConfig.multiLineStrings;
8
- var isOperatorChar = /[+\-*&%=<>!?|\/]/;
9
-
10
- var curPunc;
11
-
12
- function tokenBase(stream, state) {
13
- var ch = stream.next();
14
- if (hooks[ch]) {
15
- var result = hooks[ch](stream, state);
16
- if (result !== false) return result;
17
- }
18
- if (ch == '"' || ch == "'") {
19
- state.tokenize = tokenString(ch);
20
- return state.tokenize(stream, state);
21
- }
22
- if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
23
- curPunc = ch;
24
- return null;
25
- }
26
- if (/\d/.test(ch)) {
27
- stream.eatWhile(/[\w\.]/);
28
- return "number";
29
- }
30
- if (ch == "/") {
31
- if (stream.eat("*")) {
32
- state.tokenize = tokenComment;
33
- return tokenComment(stream, state);
34
- }
35
- if (stream.eat("/")) {
36
- stream.skipToEnd();
37
- return "comment";
38
- }
39
- }
40
- if (isOperatorChar.test(ch)) {
41
- stream.eatWhile(isOperatorChar);
42
- return "operator";
43
- }
44
- stream.eatWhile(/[\w\$_]/);
45
- var cur = stream.current();
46
- if (keywords.propertyIsEnumerable(cur)) {
47
- if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
48
- return "keyword";
49
- }
50
- if (atoms.propertyIsEnumerable(cur)) return "atom";
51
- return "word";
52
- }
53
-
54
- function tokenString(quote) {
55
- return function(stream, state) {
56
- var escaped = false, next, end = false;
57
- while ((next = stream.next()) != null) {
58
- if (next == quote && !escaped) {end = true; break;}
59
- escaped = !escaped && next == "\\";
60
- }
61
- if (end || !(escaped || multiLineStrings))
62
- state.tokenize = null;
63
- return "string";
64
- };
65
- }
66
-
67
- function tokenComment(stream, state) {
68
- var maybeEnd = false, ch;
69
- while (ch = stream.next()) {
70
- if (ch == "/" && maybeEnd) {
71
- state.tokenize = null;
72
- break;
73
- }
74
- maybeEnd = (ch == "*");
75
- }
76
- return "comment";
77
- }
78
-
79
- function Context(indented, column, type, align, prev) {
80
- this.indented = indented;
81
- this.column = column;
82
- this.type = type;
83
- this.align = align;
84
- this.prev = prev;
85
- }
86
- function pushContext(state, col, type) {
87
- return state.context = new Context(state.indented, col, type, null, state.context);
88
- }
89
- function popContext(state) {
90
- var t = state.context.type;
91
- if (t == ")" || t == "]" || t == "}")
92
- state.indented = state.context.indented;
93
- return state.context = state.context.prev;
94
- }
95
-
96
- // Interface
97
-
98
- return {
99
- startState: function(basecolumn) {
100
- return {
101
- tokenize: null,
102
- context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
103
- indented: 0,
104
- startOfLine: true
105
- };
106
- },
107
-
108
- token: function(stream, state) {
109
- var ctx = state.context;
110
- if (stream.sol()) {
111
- if (ctx.align == null) ctx.align = false;
112
- state.indented = stream.indentation();
113
- state.startOfLine = true;
114
- }
115
- if (stream.eatSpace()) return null;
116
- curPunc = null;
117
- var style = (state.tokenize || tokenBase)(stream, state);
118
- if (style == "comment" || style == "meta") return style;
119
- if (ctx.align == null) ctx.align = true;
120
-
121
- if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
122
- else if (curPunc == "{") pushContext(state, stream.column(), "}");
123
- else if (curPunc == "[") pushContext(state, stream.column(), "]");
124
- else if (curPunc == "(") pushContext(state, stream.column(), ")");
125
- else if (curPunc == "}") {
126
- while (ctx.type == "statement") ctx = popContext(state);
127
- if (ctx.type == "}") ctx = popContext(state);
128
- while (ctx.type == "statement") ctx = popContext(state);
129
- }
130
- else if (curPunc == ctx.type) popContext(state);
131
- else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
132
- pushContext(state, stream.column(), "statement");
133
- state.startOfLine = false;
134
- return style;
135
- },
136
-
137
- indent: function(state, textAfter) {
138
- if (state.tokenize != tokenBase && state.tokenize != null) return 0;
139
- var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
140
- if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
141
- var closing = firstChar == ctx.type;
142
- if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
143
- else if (ctx.align) return ctx.column + (closing ? 0 : 1);
144
- else return ctx.indented + (closing ? 0 : indentUnit);
145
- },
146
-
147
- electricChars: "{}"
148
- };
149
- });
150
-
151
- (function() {
152
- function words(str) {
153
- var obj = {}, words = str.split(" ");
154
- for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
155
- return obj;
156
- }
157
- var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
158
- "double static else struct entry switch extern typedef float union for unsigned " +
159
- "goto while enum void const signed volatile";
160
-
161
- function cppHook(stream, state) {
162
- if (!state.startOfLine) return false;
163
- stream.skipToEnd();
164
- return "meta";
165
- }
166
-
167
- // C#-style strings where "" escapes a quote.
168
- function tokenAtString(stream, state) {
169
- var next;
170
- while ((next = stream.next()) != null) {
171
- if (next == '"' && !stream.eat('"')) {
172
- state.tokenize = null;
173
- break;
174
- }
175
- }
176
- return "string";
177
- }
178
-
179
- CodeMirror.defineMIME("text/x-csrc", {
180
- name: "clike",
181
- keywords: words(cKeywords),
182
- blockKeywords: words("case do else for if switch while struct"),
183
- atoms: words("null"),
184
- hooks: {"#": cppHook}
185
- });
186
- CodeMirror.defineMIME("text/x-c++src", {
187
- name: "clike",
188
- keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
189
- "static_cast typeid catch operator template typename class friend private " +
190
- "this using const_cast inline public throw virtual delete mutable protected " +
191
- "wchar_t"),
192
- blockKeywords: words("catch class do else finally for if struct switch try while"),
193
- atoms: words("true false null"),
194
- hooks: {"#": cppHook}
195
- });
196
- CodeMirror.defineMIME("text/x-java", {
197
- name: "clike",
198
- keywords: words("abstract assert boolean break byte case catch char class const continue default " +
199
- "do double else enum extends final finally float for goto if implements import " +
200
- "instanceof int interface long native new package private protected public " +
201
- "return short static strictfp super switch synchronized this throw throws transient " +
202
- "try void volatile while"),
203
- blockKeywords: words("catch class do else finally for if switch try while"),
204
- atoms: words("true false null"),
205
- hooks: {
206
- "@": function(stream, state) {
207
- stream.eatWhile(/[\w\$_]/);
208
- return "meta";
209
- }
210
- }
211
- });
212
- CodeMirror.defineMIME("text/x-csharp", {
213
- name: "clike",
214
- keywords: words("abstract as base bool break byte case catch char checked class const continue decimal" +
215
- " default delegate do double else enum event explicit extern finally fixed float for" +
216
- " foreach goto if implicit in int interface internal is lock long namespace new object" +
217
- " operator out override params private protected public readonly ref return sbyte sealed short" +
218
- " sizeof stackalloc static string struct switch this throw try typeof uint ulong unchecked" +
219
- " unsafe ushort using virtual void volatile while add alias ascending descending dynamic from get" +
220
- " global group into join let orderby partial remove select set value var yield"),
221
- blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
222
- atoms: words("true false null"),
223
- hooks: {
224
- "@": function(stream, state) {
225
- if (stream.eat('"')) {
226
- state.tokenize = tokenAtString;
227
- return tokenAtString(stream, state);
228
- }
229
- stream.eatWhile(/[\w\$_]/);
230
- return "meta";
231
- }
232
- }
233
- });
234
- }());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/mode/clike/index.html DELETED
@@ -1,101 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>CodeMirror: C-like mode</title>
5
- <link rel="stylesheet" href="../../lib/codemirror.css">
6
- <script src="../../lib/codemirror.js"></script>
7
- <script src="clike.js"></script>
8
- <link rel="stylesheet" href="../../doc/docs.css">
9
- <style>.CodeMirror {border: 2px inset #dee;}</style>
10
- </head>
11
- <body>
12
- <h1>CodeMirror: C-like mode</h1>
13
-
14
- <form><textarea id="code" name="code">
15
- /* C demo code */
16
-
17
- #include <zmq.h>
18
- #include <pthread.h>
19
- #include <semaphore.h>
20
- #include <time.h>
21
- #include <stdio.h>
22
- #include <fcntl.h>
23
- #include <malloc.h>
24
-
25
- typedef struct {
26
- void* arg_socket;
27
- zmq_msg_t* arg_msg;
28
- char* arg_string;
29
- unsigned long arg_len;
30
- int arg_int, arg_command;
31
-
32
- int signal_fd;
33
- int pad;
34
- void* context;
35
- sem_t sem;
36
- } acl_zmq_context;
37
-
38
- #define p(X) (context->arg_##X)
39
-
40
- void* zmq_thread(void* context_pointer) {
41
- acl_zmq_context* context = (acl_zmq_context*)context_pointer;
42
- char ok = 'K', err = 'X';
43
- int res;
44
-
45
- while (1) {
46
- while ((res = sem_wait(&amp;context->sem)) == EINTR);
47
- if (res) {write(context->signal_fd, &amp;err, 1); goto cleanup;}
48
- switch(p(command)) {
49
- case 0: goto cleanup;
50
- case 1: p(socket) = zmq_socket(context->context, p(int)); break;
51
- case 2: p(int) = zmq_close(p(socket)); break;
52
- case 3: p(int) = zmq_bind(p(socket), p(string)); break;
53
- case 4: p(int) = zmq_connect(p(socket), p(string)); break;
54
- case 5: p(int) = zmq_getsockopt(p(socket), p(int), (void*)p(string), &amp;p(len)); break;
55
- case 6: p(int) = zmq_setsockopt(p(socket), p(int), (void*)p(string), p(len)); break;
56
- case 7: p(int) = zmq_send(p(socket), p(msg), p(int)); break;
57
- case 8: p(int) = zmq_recv(p(socket), p(msg), p(int)); break;
58
- case 9: p(int) = zmq_poll(p(socket), p(int), p(len)); break;
59
- }
60
- p(command) = errno;
61
- write(context->signal_fd, &amp;ok, 1);
62
- }
63
- cleanup:
64
- close(context->signal_fd);
65
- free(context_pointer);
66
- return 0;
67
- }
68
-
69
- void* zmq_thread_init(void* zmq_context, int signal_fd) {
70
- acl_zmq_context* context = malloc(sizeof(acl_zmq_context));
71
- pthread_t thread;
72
-
73
- context->context = zmq_context;
74
- context->signal_fd = signal_fd;
75
- sem_init(&amp;context->sem, 1, 0);
76
- pthread_create(&amp;thread, 0, &amp;zmq_thread, context);
77
- pthread_detach(thread);
78
- return context;
79
- }
80
- </textarea></form>
81
-
82
- <script>
83
- var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
84
- lineNumbers: true,
85
- matchBrackets: true,
86
- mode: "text/x-csrc"
87
- });
88
- </script>
89
-
90
- <p>Simple mode that tries to handle C-like languages as well as it
91
- can. Takes two configuration parameters: <code>keywords</code>, an
92
- object whose property names are the keywords in the language,
93
- and <code>useCPP</code>, which determines whether C preprocessor
94
- directives are recognized.</p>
95
-
96
- <p><strong>MIME types defined:</strong> <code>text/x-csrc</code>
97
- (C code), <code>text/x-c++src</code> (C++
98
- code), <code>text/x-java</code> (Java
99
- code), <code>text/x-csharp</code> (C#).</p>
100
- </body>
101
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/mode/css/index.html DELETED
@@ -1,55 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>CodeMirror: CSS mode</title>
5
- <link rel="stylesheet" href="../../lib/codemirror.css">
6
- <script src="../../lib/codemirror.js"></script>
7
- <script src="css.js"></script>
8
- <style>.CodeMirror {background: #f8f8f8;}</style>
9
- <link rel="stylesheet" href="../../doc/docs.css">
10
- </head>
11
- <body>
12
- <h1>CodeMirror: CSS mode</h1>
13
- <form><textarea id="code" name="code">
14
- /* Some example CSS */
15
-
16
- @import url("something.css");
17
-
18
- body {
19
- margin: 0;
20
- padding: 3em 6em;
21
- font-family: tahoma, arial, sans-serif;
22
- color: #000;
23
- }
24
-
25
- #navigation a {
26
- font-weight: bold;
27
- text-decoration: none !important;
28
- }
29
-
30
- h1 {
31
- font-size: 2.5em;
32
- }
33
-
34
- h2 {
35
- font-size: 1.7em;
36
- }
37
-
38
- h1:before, h2:before {
39
- content: "::";
40
- }
41
-
42
- code {
43
- font-family: courier, monospace;
44
- font-size: 80%;
45
- color: #418A8A;
46
- }
47
- </textarea></form>
48
- <script>
49
- var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
50
- </script>
51
-
52
- <p><strong>MIME types defined:</strong> <code>text/css</code>.</p>
53
-
54
- </body>
55
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/mode/htmlmixed/index.html DELETED
@@ -1,51 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>CodeMirror: HTML mixed mode</title>
5
- <link rel="stylesheet" href="../../lib/codemirror.css">
6
- <script src="../../lib/codemirror.js"></script>
7
- <script src="../xml/xml.js"></script>
8
- <script src="../javascript/javascript.js"></script>
9
- <script src="../css/css.js"></script>
10
- <script src="htmlmixed.js"></script>
11
- <link rel="stylesheet" href="../../doc/docs.css">
12
- <style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
13
- </head>
14
- <body>
15
- <h1>CodeMirror: HTML mixed mode</h1>
16
- <form><textarea id="code" name="code">
17
- <html style="color: green">
18
- <!-- this is a comment -->
19
- <head>
20
- <title>Mixed HTML Example</title>
21
- <style type="text/css">
22
- h1 {font-family: comic sans; color: #f0f;}
23
- div {background: yellow !important;}
24
- body {
25
- max-width: 50em;
26
- margin: 1em 2em 1em 5em;
27
- }
28
- </style>
29
- </head>
30
- <body>
31
- <h1>Mixed HTML Example</h1>
32
- <script>
33
- function jsFunc(arg1, arg2) {
34
- if (arg1 && arg2) document.body.innerHTML = "achoo";
35
- }
36
- </script>
37
- </body>
38
- </html>
39
- </textarea></form>
40
- <script>
41
- var editor = CodeMirror.fromTextArea(document.getElementById("code"), {mode: "text/html", tabMode: "indent"});
42
- </script>
43
-
44
- <p>The HTML mixed mode depends on the XML, JavaScript, and CSS modes.</p>
45
-
46
- <p><strong>MIME types defined:</strong> <code>text/html</code>
47
- (redefined, only takes effect if you load this parser after the
48
- XML parser).</p>
49
-
50
- </body>
51
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/mode/javascript/index.html DELETED
@@ -1,77 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>CodeMirror: JavaScript mode</title>
5
- <link rel="stylesheet" href="../../lib/codemirror.css">
6
- <script src="../../lib/codemirror.js"></script>
7
- <script src="javascript.js"></script>
8
- <link rel="stylesheet" href="../../doc/docs.css">
9
- <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
10
- </head>
11
- <body>
12
- <h1>CodeMirror: JavaScript mode</h1>
13
-
14
- <div><textarea id="code" name="code">
15
- // Demo code (the actual new parser character stream implementation)
16
-
17
- function StringStream(string) {
18
- this.pos = 0;
19
- this.string = string;
20
- }
21
-
22
- StringStream.prototype = {
23
- done: function() {return this.pos >= this.string.length;},
24
- peek: function() {return this.string.charAt(this.pos);},
25
- next: function() {
26
- if (this.pos &lt; this.string.length)
27
- return this.string.charAt(this.pos++);
28
- },
29
- eat: function(match) {
30
- var ch = this.string.charAt(this.pos);
31
- if (typeof match == "string") var ok = ch == match;
32
- else var ok = ch &amp;&amp; match.test ? match.test(ch) : match(ch);
33
- if (ok) {this.pos++; return ch;}
34
- },
35
- eatWhile: function(match) {
36
- var start = this.pos;
37
- while (this.eat(match));
38
- if (this.pos > start) return this.string.slice(start, this.pos);
39
- },
40
- backUp: function(n) {this.pos -= n;},
41
- column: function() {return this.pos;},
42
- eatSpace: function() {
43
- var start = this.pos;
44
- while (/\s/.test(this.string.charAt(this.pos))) this.pos++;
45
- return this.pos - start;
46
- },
47
- match: function(pattern, consume, caseInsensitive) {
48
- if (typeof pattern == "string") {
49
- function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
50
- if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
51
- if (consume !== false) this.pos += str.length;
52
- return true;
53
- }
54
- }
55
- else {
56
- var match = this.string.slice(this.pos).match(pattern);
57
- if (match &amp;&amp; consume !== false) this.pos += match[0].length;
58
- return match;
59
- }
60
- }
61
- };
62
- </textarea></div>
63
-
64
- <script>
65
- var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
66
- lineNumbers: true,
67
- matchBrackets: true
68
- });
69
- </script>
70
-
71
- <p>JavaScript mode supports a single configuration
72
- option, <code>json</code>, which will set the mode to expect JSON
73
- data rather than a JavaScript program.</p>
74
-
75
- <p><strong>MIME types defined:</strong> <code>text/javascript</code>, <code>application/json</code>.</p>
76
- </body>
77
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/mode/less/less.js DELETED
@@ -1,232 +0,0 @@
1
- /*
2
- LESS mode - http://www.lesscss.org/
3
- Ported to CodeMirror by Peter Kroon
4
- */
5
-
6
- CodeMirror.defineMode("less", function(config) {
7
- var indentUnit = config.indentUnit, type;
8
- function ret(style, tp) {type = tp; return style;}
9
- //html5 tags
10
- var tags = ["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","big","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","command","datalist","dd","del","details","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","keygen","kbd","label","legend","li","link","map","mark","menu","meta","meter","nav","noframes","noscript","object","ol","optgroup","option","output","p","param","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strike","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr"];
11
-
12
- function inTagsArray(val){
13
- for(var i=0; i<tags.length; i++){
14
- if(val === tags[i]){
15
- return true;
16
- }
17
- }
18
- }
19
-
20
- function tokenBase(stream, state) {
21
- var ch = stream.next();
22
-
23
- if (ch == "@") {stream.eatWhile(/[\w\-]/); return ret("meta", stream.current());}
24
- else if (ch == "/" && stream.eat("*")) {
25
- state.tokenize = tokenCComment;
26
- return tokenCComment(stream, state);
27
- }
28
- else if (ch == "<" && stream.eat("!")) {
29
- state.tokenize = tokenSGMLComment;
30
- return tokenSGMLComment(stream, state);
31
- }
32
- else if (ch == "=") ret(null, "compare");
33
- else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
34
- else if (ch == "\"" || ch == "'") {
35
- state.tokenize = tokenString(ch);
36
- return state.tokenize(stream, state);
37
- }
38
- else if (ch == "/") { // lesscss e.g.: .png will not be parsed as a class
39
- if(stream.eat("/")){
40
- state.tokenize = tokenSComment
41
- return tokenSComment(stream, state);
42
- }else{
43
- stream.eatWhile(/[\a-zA-Z0-9\-_.\s]/);
44
- if(/\/|\)|#/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == ")")))return ret("string", "string");//let url(/images/logo.png) without quotes return as string
45
- return ret("number", "unit");
46
- }
47
- }
48
- else if (ch == "!") {
49
- stream.match(/^\s*\w*/);
50
- return ret("keyword", "important");
51
- }
52
- else if (/\d/.test(ch)) {
53
- stream.eatWhile(/[\w.%]/);
54
- return ret("number", "unit");
55
- }
56
- else if (/[,+<>*\/]/.test(ch)) {//removed . dot character original was [,.+>*\/]
57
- return ret(null, "select-op");
58
- }
59
- else if (/[;{}:\[\]()]/.test(ch)) { //added () char for lesscss original was [;{}:\[\]]
60
- if(ch == ":"){
61
- stream.eatWhile(/[active|hover|link|visited]/);
62
- if( stream.current().match(/active|hover|link|visited/)){
63
- return ret("tag", "tag");
64
- }else{
65
- return ret(null, ch);
66
- }
67
- }else{
68
- return ret(null, ch);
69
- }
70
- }
71
- else if (ch == ".") { // lesscss
72
- stream.eatWhile(/[\a-zA-Z0-9\-_]/);
73
- return ret("tag", "tag");
74
- }
75
- else if (ch == "#") { // lesscss
76
- //we don't eat white-space, we want the hex color and or id only
77
- stream.eatWhile(/[A-Za-z0-9]/);
78
- //check if there is a proper hex color length e.g. #eee || #eeeEEE
79
- if(stream.current().length ===4 || stream.current().length ===7){
80
- if(stream.current().match(/[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}/,false) != null){//is there a valid hex color value present in the current stream
81
- //when not a valid hex value, parse as id
82
- if(stream.current().substring(1) != stream.current().match(/[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}/,false))return ret("atom", "tag");
83
- //eat white-space
84
- stream.eatSpace();
85
- //when hex value declaration doesn't end with [;,] but is does with a slash/cc comment treat it as an id, just like the other hex values that don't end with[;,]
86
- if( /[\/<>.(){!$%^&*_\-\\?=+\|#'~`]/.test(stream.peek()) )return ret("atom", "tag");
87
- //#time { color: #aaa }
88
- else if(stream.peek() == "}" )return ret("number", "unit");
89
- //we have a valid hex color value, parse as id whenever an element/class is defined after the hex(id) value e.g. #eee aaa || #eee .aaa
90
- else if( /[a-zA-Z\\]/.test(stream.peek()) )return ret("atom", "tag");
91
- //when a hex value is on the end of a line, parse as id
92
- else if(stream.eol())return ret("atom", "tag");
93
- //default
94
- else return ret("number", "unit");
95
- }else{//when not a valid hexvalue in the current stream e.g. #footer
96
- stream.eatWhile(/[\w\\\-]/);
97
- return ret("atom", "tag");
98
- }
99
- }else{
100
- stream.eatWhile(/[\w\\\-]/);
101
- return ret("atom", "tag");
102
- }
103
- }
104
- else if (ch == "&") {
105
- stream.eatWhile(/[\w\-]/);
106
- return ret(null, ch);
107
- }
108
- else {
109
- stream.eatWhile(/[\w\\\-_%.{]/);
110
- if(stream.current().match(/http|https/) != null){
111
- stream.eatWhile(/[\w\\\-_%.{:\/]/);
112
- return ret("string", "string");
113
- }else if(stream.peek() == "<" || stream.peek() == ">"){
114
- return ret("tag", "tag");
115
- }else if( stream.peek().match(/\(/) != null ){// lessc
116
- return ret(null, ch);
117
- }else if (stream.peek() == "/" && state.stack[state.stack.length-1] != undefined){ // url(dir/center/image.png)
118
- return ret("string", "string");
119
- }else if( stream.current().match(/\-\d|\-.\d/) ){ // lesscss match e.g.: -5px -0.4 etc... only colorize the minus sign
120
- //stream.backUp(stream.current().length-1); //commment out these 2 comment if you want the minus sign to be parsed as null -500px
121
- //return ret(null, ch);
122
- return ret("number", "unit");
123
- }else if( inTagsArray(stream.current()) ){ // lesscss match html tags
124
- return ret("tag", "tag");
125
- }else if( /\/|[\s\)]/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == "/")) && stream.current().indexOf(".") !== -1){
126
- if(stream.current().substring(stream.current().length-1,stream.current().length) == "{"){
127
- stream.backUp(1);
128
- return ret("tag", "tag");
129
- }//end if
130
- if( (stream.eatSpace() && stream.peek().match(/[{<>.a-zA-Z]/) != null) || stream.eol() )return ret("tag", "tag");//e.g. button.icon-plus
131
- return ret("string", "string");//let url(/images/logo.png) without quotes return as string
132
- }else if( stream.eol() ){
133
- if(stream.current().substring(stream.current().length-1,stream.current().length) == "{")stream.backUp(1);
134
- return ret("tag", "tag");
135
- }else{
136
- return ret("variable", "variable");
137
- }
138
- }
139
-
140
- }
141
-
142
- function tokenSComment(stream, state) {// SComment = Slash comment
143
- stream.skipToEnd();
144
- state.tokenize = tokenBase;
145
- return ret("comment", "comment");
146
- }
147
-
148
- function tokenCComment(stream, state) {
149
- var maybeEnd = false, ch;
150
- while ((ch = stream.next()) != null) {
151
- if (maybeEnd && ch == "/") {
152
- state.tokenize = tokenBase;
153
- break;
154
- }
155
- maybeEnd = (ch == "*");
156
- }
157
- return ret("comment", "comment");
158
- }
159
-
160
- function tokenSGMLComment(stream, state) {
161
- var dashes = 0, ch;
162
- while ((ch = stream.next()) != null) {
163
- if (dashes >= 2 && ch == ">") {
164
- state.tokenize = tokenBase;
165
- break;
166
- }
167
- dashes = (ch == "-") ? dashes + 1 : 0;
168
- }
169
- return ret("comment", "comment");
170
- }
171
-
172
- function tokenString(quote) {
173
- return function(stream, state) {
174
- var escaped = false, ch;
175
- while ((ch = stream.next()) != null) {
176
- if (ch == quote && !escaped)
177
- break;
178
- escaped = !escaped && ch == "\\";
179
- }
180
- if (!escaped) state.tokenize = tokenBase;
181
- return ret("string", "string");
182
- };
183
- }
184
-
185
- return {
186
- startState: function(base) {
187
- return {tokenize: tokenBase,
188
- baseIndent: base || 0,
189
- stack: []};
190
- },
191
-
192
- token: function(stream, state) {
193
- if (stream.eatSpace()) return null;
194
- var style = state.tokenize(stream, state);
195
-
196
- var context = state.stack[state.stack.length-1];
197
- if (type == "hash" && context == "rule") style = "atom";
198
- else if (style == "variable") {
199
- if (context == "rule") style = null; //"tag"
200
- else if (!context || context == "@media{"){
201
- style = stream.current() == "when" ? "variable" :
202
- stream.string.match(/#/g) != undefined ? null :
203
- /[\s,|\s\)]/.test(stream.peek()) ? "tag" : null;
204
- }
205
- }
206
-
207
- if (context == "rule" && /^[\{\};]$/.test(type))
208
- state.stack.pop();
209
- if (type == "{") {
210
- if (context == "@media") state.stack[state.stack.length-1] = "@media{";
211
- else state.stack.push("{");
212
- }
213
- else if (type == "}") state.stack.pop();
214
- else if (type == "@media") state.stack.push("@media");
215
- else if (context == "{" && type != "comment") state.stack.push("rule");
216
- return style;
217
- },
218
-
219
- indent: function(state, textAfter) {
220
- var n = state.stack.length;
221
- if (/^\}/.test(textAfter))
222
- n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
223
- return state.baseIndent + n * indentUnit;
224
- },
225
-
226
- electricChars: "}"
227
- };
228
- });
229
-
230
- CodeMirror.defineMIME("text/x-less", "less");
231
- if (!CodeMirror.mimeModes.hasOwnProperty("text/css"))
232
- CodeMirror.defineMIME("text/css", "less");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/mode/php/index.html DELETED
@@ -1,48 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>CodeMirror: PHP mode</title>
5
- <link rel="stylesheet" href="../../lib/codemirror.css">
6
- <script src="../../lib/codemirror.js"></script>
7
- <script src="../xml/xml.js"></script>
8
- <script src="../javascript/javascript.js"></script>
9
- <script src="../css/css.js"></script>
10
- <script src="../clike/clike.js"></script>
11
- <script src="php.js"></script>
12
- <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
13
- <link rel="stylesheet" href="../../doc/docs.css">
14
- </head>
15
- <body>
16
- <h1>CodeMirror: PHP mode</h1>
17
-
18
- <form><textarea id="code" name="code">
19
- <?php
20
- function hello($who) {
21
- return "Hello " . $who;
22
- }
23
- ?>
24
- <p>The program says <?= hello("World") ?>.</p>
25
- <script>
26
- alert("And here is some JS code"); // also colored
27
- </script>
28
- </textarea></form>
29
-
30
- <script>
31
- var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
32
- lineNumbers: true,
33
- matchBrackets: true,
34
- mode: "application/x-httpd-php",
35
- indentUnit: 4,
36
- indentWithTabs: true,
37
- enterMode: "keep",
38
- tabMode: "shift"
39
- });
40
- </script>
41
-
42
- <p>Simple HTML/PHP mode based on
43
- the <a href="../clike/">C-like</a> mode. Depends on XML,
44
- JavaScript, CSS, and C-like modes.</p>
45
-
46
- <p><strong>MIME types defined:</strong> <code>application/x-httpd-php</code> (HTML with PHP code), <code>text/x-php</code> (plain, non-wrapped PHP code).</p>
47
- </body>
48
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/mode/php/php.js DELETED
@@ -1,150 +0,0 @@
1
- (function() {
2
- function keywords(str) {
3
- var obj = {}, words = str.split(" ");
4
- for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
5
- return obj;
6
- }
7
- function heredoc(delim) {
8
- return function(stream, state) {
9
- if (stream.match(delim)) state.tokenize = null;
10
- else stream.skipToEnd();
11
- return "string";
12
- }
13
- }
14
- var phpConfig = {
15
- name: "clike",
16
- keywords: keywords("abstract and array as break case catch class clone const continue declare default " +
17
- "do else elseif enddeclare endfor endforeach endif endswitch endwhile extends final " +
18
- "for foreach function global goto if implements interface instanceof namespace " +
19
- "new or private protected public static switch throw trait try use var while xor " +
20
- "die echo empty exit eval include include_once isset list require require_once return " +
21
- "print unset __halt_compiler self static parent"),
22
- blockKeywords: keywords("catch do else elseif for foreach if switch try while"),
23
- atoms: keywords("true false null TRUE FALSE NULL"),
24
- multiLineStrings: true,
25
- hooks: {
26
- "$": function(stream, state) {
27
- stream.eatWhile(/[\w\$_]/);
28
- return "variable-2";
29
- },
30
- "<": function(stream, state) {
31
- if (stream.match(/<</)) {
32
- stream.eatWhile(/[\w\.]/);
33
- state.tokenize = heredoc(stream.current().slice(3));
34
- return state.tokenize(stream, state);
35
- }
36
- return false;
37
- },
38
- "#": function(stream, state) {
39
- while (!stream.eol() && !stream.match("?>", false)) stream.next();
40
- return "comment";
41
- },
42
- "/": function(stream, state) {
43
- if (stream.eat("/")) {
44
- while (!stream.eol() && !stream.match("?>", false)) stream.next();
45
- return "comment";
46
- }
47
- return false;
48
- }
49
- }
50
- };
51
-
52
- CodeMirror.defineMode("php", function(config, parserConfig) {
53
- var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
54
- var jsMode = CodeMirror.getMode(config, "javascript");
55
- var cssMode = CodeMirror.getMode(config, "css");
56
- var phpMode = CodeMirror.getMode(config, phpConfig);
57
-
58
- function dispatch(stream, state) { // TODO open PHP inside text/css
59
- var isPHP = state.mode == "php";
60
- if (stream.sol() && state.pending != '"') state.pending = null;
61
- if (state.curMode == htmlMode) {
62
- if (stream.match(/^<\?\w*/)) {
63
- state.curMode = phpMode;
64
- state.curState = state.php;
65
- state.curClose = "?>";
66
- state.mode = "php";
67
- return "meta";
68
- }
69
- if (state.pending == '"') {
70
- while (!stream.eol() && stream.next() != '"') {}
71
- var style = "string";
72
- } else if (state.pending && stream.pos < state.pending.end) {
73
- stream.pos = state.pending.end;
74
- var style = state.pending.style;
75
- } else {
76
- var style = htmlMode.token(stream, state.curState);
77
- }
78
- state.pending = null;
79
- var cur = stream.current(), openPHP = cur.search(/<\?/);
80
- if (openPHP != -1) {
81
- if (style == "string" && /\"$/.test(cur) && !/\?>/.test(cur)) state.pending = '"';
82
- else state.pending = {end: stream.pos, style: style};
83
- stream.backUp(cur.length - openPHP);
84
- } else if (style == "tag" && stream.current() == ">" && state.curState.context) {
85
- if (/^script$/i.test(state.curState.context.tagName)) {
86
- state.curMode = jsMode;
87
- state.curState = jsMode.startState(htmlMode.indent(state.curState, ""));
88
- state.curClose = /^<\/\s*script\s*>/i;
89
- state.mode = "javascript";
90
- }
91
- else if (/^style$/i.test(state.curState.context.tagName)) {
92
- state.curMode = cssMode;
93
- state.curState = cssMode.startState(htmlMode.indent(state.curState, ""));
94
- state.curClose = /^<\/\s*style\s*>/i;
95
- state.mode = "css";
96
- }
97
- }
98
- return style;
99
- } else if ((!isPHP || state.php.tokenize == null) &&
100
- stream.match(state.curClose, isPHP)) {
101
- state.curMode = htmlMode;
102
- state.curState = state.html;
103
- state.curClose = null;
104
- state.mode = "html";
105
- if (isPHP) return "meta";
106
- else return dispatch(stream, state);
107
- } else {
108
- return state.curMode.token(stream, state.curState);
109
- }
110
- }
111
-
112
- return {
113
- startState: function() {
114
- var html = htmlMode.startState();
115
- return {html: html,
116
- php: phpMode.startState(),
117
- curMode: parserConfig.startOpen ? phpMode : htmlMode,
118
- curState: parserConfig.startOpen ? phpMode.startState() : html,
119
- curClose: parserConfig.startOpen ? /^\?>/ : null,
120
- mode: parserConfig.startOpen ? "php" : "html",
121
- pending: null}
122
- },
123
-
124
- copyState: function(state) {
125
- var html = state.html, htmlNew = CodeMirror.copyState(htmlMode, html),
126
- php = state.php, phpNew = CodeMirror.copyState(phpMode, php), cur;
127
- if (state.curState == html) cur = htmlNew;
128
- else if (state.curState == php) cur = phpNew;
129
- else cur = CodeMirror.copyState(state.curMode, state.curState);
130
- return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur,
131
- curClose: state.curClose, mode: state.mode,
132
- pending: state.pending};
133
- },
134
-
135
- token: dispatch,
136
-
137
- indent: function(state, textAfter) {
138
- if ((state.curMode != phpMode && /^\s*<\//.test(textAfter)) ||
139
- (state.curMode == phpMode && /^\?>/.test(textAfter)))
140
- return htmlMode.indent(state.html, textAfter);
141
- return state.curMode.indent(state.curState, textAfter);
142
- },
143
-
144
- electricChars: "/{}:"
145
- }
146
- }, "xml", "clike", "javascript", "css");
147
- CodeMirror.defineMIME("application/x-httpd-php", "php");
148
- CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true});
149
- CodeMirror.defineMIME("text/x-php", phpConfig);
150
- })();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/mode/xml/index.html DELETED
@@ -1,44 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>CodeMirror: XML mode</title>
5
- <link rel="stylesheet" href="../../lib/codemirror.css">
6
- <script src="../../lib/codemirror.js"></script>
7
- <script src="xml.js"></script>
8
- <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
9
- <link rel="stylesheet" href="../../doc/docs.css">
10
- </head>
11
- <body>
12
- <h1>CodeMirror: XML mode</h1>
13
- <form><textarea id="code" name="code">
14
- &lt;html style="color: green"&gt;
15
- &lt;!-- this is a comment --&gt;
16
- &lt;head&gt;
17
- &lt;title&gt;HTML Example&lt;/title&gt;
18
- &lt;/head&gt;
19
- &lt;body&gt;
20
- The indentation tries to be &lt;em&gt;somewhat &amp;quot;do what
21
- I mean&amp;quot;&lt;/em&gt;... but might not match your style.
22
- &lt;/body&gt;
23
- &lt;/html&gt;
24
- </textarea></form>
25
- <script>
26
- var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
27
- mode: {name: "xml", alignCDATA: true},
28
- lineNumbers: true
29
- });
30
- </script>
31
- <p>The XML mode supports two configuration parameters:</p>
32
- <dl>
33
- <dt><code>htmlMode (boolean)</code></dt>
34
- <dd>This switches the mode to parse HTML instead of XML. This
35
- means attributes do not have to be quoted, and some elements
36
- (such as <code>br</code>) do not require a closing tag.</dd>
37
- <dt><code>alignCDATA (boolean)</code></dt>
38
- <dd>Setting this to true will force the opening tag of CDATA
39
- blocks to not be indented.</dd>
40
- </dl>
41
-
42
- <p><strong>MIME types defined:</strong> <code>application/xml</code>, <code>text/html</code>.</p>
43
- </body>
44
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/mode/xml/xml.js DELETED
@@ -1,325 +0,0 @@
1
- CodeMirror.defineMode("xml", function(config, parserConfig) {
2
- var indentUnit = config.indentUnit;
3
- var Kludges = parserConfig.htmlMode ? {
4
- autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
5
- 'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
6
- 'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
7
- 'track': true, 'wbr': true},
8
- implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
9
- 'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
10
- 'th': true, 'tr': true},
11
- contextGrabbers: {
12
- 'dd': {'dd': true, 'dt': true},
13
- 'dt': {'dd': true, 'dt': true},
14
- 'li': {'li': true},
15
- 'option': {'option': true, 'optgroup': true},
16
- 'optgroup': {'optgroup': true},
17
- 'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
18
- 'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
19
- 'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
20
- 'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
21
- 'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
22
- 'rp': {'rp': true, 'rt': true},
23
- 'rt': {'rp': true, 'rt': true},
24
- 'tbody': {'tbody': true, 'tfoot': true},
25
- 'td': {'td': true, 'th': true},
26
- 'tfoot': {'tbody': true},
27
- 'th': {'td': true, 'th': true},
28
- 'thead': {'tbody': true, 'tfoot': true},
29
- 'tr': {'tr': true}
30
- },
31
- doNotIndent: {"pre": true},
32
- allowUnquoted: true,
33
- allowMissing: false
34
- } : {
35
- autoSelfClosers: {},
36
- implicitlyClosed: {},
37
- contextGrabbers: {},
38
- doNotIndent: {},
39
- allowUnquoted: false,
40
- allowMissing: false
41
- };
42
- var alignCDATA = parserConfig.alignCDATA;
43
-
44
- // Return variables for tokenizers
45
- var tagName, type;
46
-
47
- function inText(stream, state) {
48
- function chain(parser) {
49
- state.tokenize = parser;
50
- return parser(stream, state);
51
- }
52
-
53
- var ch = stream.next();
54
- if (ch == "<") {
55
- if (stream.eat("!")) {
56
- if (stream.eat("[")) {
57
- if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
58
- else return null;
59
- }
60
- else if (stream.match("--")) return chain(inBlock("comment", "-->"));
61
- else if (stream.match("DOCTYPE", true, true)) {
62
- stream.eatWhile(/[\w\._\-]/);
63
- return chain(doctype(1));
64
- }
65
- else return null;
66
- }
67
- else if (stream.eat("?")) {
68
- stream.eatWhile(/[\w\._\-]/);
69
- state.tokenize = inBlock("meta", "?>");
70
- return "meta";
71
- }
72
- else {
73
- type = stream.eat("/") ? "closeTag" : "openTag";
74
- stream.eatSpace();
75
- tagName = "";
76
- var c;
77
- while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
78
- state.tokenize = inTag;
79
- return "tag";
80
- }
81
- }
82
- else if (ch == "&") {
83
- var ok;
84
- if (stream.eat("#")) {
85
- if (stream.eat("x")) {
86
- ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
87
- } else {
88
- ok = stream.eatWhile(/[\d]/) && stream.eat(";");
89
- }
90
- } else {
91
- ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
92
- }
93
- return ok ? "atom" : "error";
94
- }
95
- else {
96
- stream.eatWhile(/[^&<]/);
97
- return null;
98
- }
99
- }
100
-
101
- function inTag(stream, state) {
102
- var ch = stream.next();
103
- if (ch == ">" || (ch == "/" && stream.eat(">"))) {
104
- state.tokenize = inText;
105
- type = ch == ">" ? "endTag" : "selfcloseTag";
106
- return "tag";
107
- }
108
- else if (ch == "=") {
109
- type = "equals";
110
- return null;
111
- }
112
- else if (/[\'\"]/.test(ch)) {
113
- state.tokenize = inAttribute(ch);
114
- return state.tokenize(stream, state);
115
- }
116
- else {
117
- stream.eatWhile(/[^\s\u00a0=<>\"\'\/?]/);
118
- return "word";
119
- }
120
- }
121
-
122
- function inAttribute(quote) {
123
- return function(stream, state) {
124
- while (!stream.eol()) {
125
- if (stream.next() == quote) {
126
- state.tokenize = inTag;
127
- break;
128
- }
129
- }
130
- return "string";
131
- };
132
- }
133
-
134
- function inBlock(style, terminator) {
135
- return function(stream, state) {
136
- while (!stream.eol()) {
137
- if (stream.match(terminator)) {
138
- state.tokenize = inText;
139
- break;
140
- }
141
- stream.next();
142
- }
143
- return style;
144
- };
145
- }
146
- function doctype(depth) {
147
- return function(stream, state) {
148
- var ch;
149
- while ((ch = stream.next()) != null) {
150
- if (ch == "<") {
151
- state.tokenize = doctype(depth + 1);
152
- return state.tokenize(stream, state);
153
- } else if (ch == ">") {
154
- if (depth == 1) {
155
- state.tokenize = inText;
156
- break;
157
- } else {
158
- state.tokenize = doctype(depth - 1);
159
- return state.tokenize(stream, state);
160
- }
161
- }
162
- }
163
- return "meta";
164
- };
165
- }
166
-
167
- var curState, setStyle;
168
- function pass() {
169
- for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
170
- }
171
- function cont() {
172
- pass.apply(null, arguments);
173
- return true;
174
- }
175
-
176
- function pushContext(tagName, startOfLine) {
177
- var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent);
178
- curState.context = {
179
- prev: curState.context,
180
- tagName: tagName,
181
- indent: curState.indented,
182
- startOfLine: startOfLine,
183
- noIndent: noIndent
184
- };
185
- }
186
- function popContext() {
187
- if (curState.context) curState.context = curState.context.prev;
188
- }
189
-
190
- function element(type) {
191
- if (type == "openTag") {
192
- curState.tagName = tagName;
193
- return cont(attributes, endtag(curState.startOfLine));
194
- } else if (type == "closeTag") {
195
- var err = false;
196
- if (curState.context) {
197
- if (curState.context.tagName != tagName) {
198
- if (Kludges.implicitlyClosed.hasOwnProperty(curState.context.tagName.toLowerCase())) {
199
- popContext();
200
- }
201
- err = !curState.context || curState.context.tagName != tagName;
202
- }
203
- } else {
204
- err = true;
205
- }
206
- if (err) setStyle = "error";
207
- return cont(endclosetag(err));
208
- }
209
- return cont();
210
- }
211
- function endtag(startOfLine) {
212
- return function(type) {
213
- if (type == "selfcloseTag" ||
214
- (type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase()))) {
215
- maybePopContext(curState.tagName.toLowerCase());
216
- return cont();
217
- }
218
- if (type == "endTag") {
219
- maybePopContext(curState.tagName.toLowerCase());
220
- pushContext(curState.tagName, startOfLine);
221
- return cont();
222
- }
223
- return cont();
224
- };
225
- }
226
- function endclosetag(err) {
227
- return function(type) {
228
- if (err) setStyle = "error";
229
- if (type == "endTag") { popContext(); return cont(); }
230
- setStyle = "error";
231
- return cont(arguments.callee);
232
- }
233
- }
234
- function maybePopContext(nextTagName) {
235
- var parentTagName;
236
- while (true) {
237
- if (!curState.context) {
238
- return;
239
- }
240
- parentTagName = curState.context.tagName.toLowerCase();
241
- if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) ||
242
- !Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
243
- return;
244
- }
245
- popContext();
246
- }
247
- }
248
-
249
- function attributes(type) {
250
- if (type == "word") {setStyle = "attribute"; return cont(attribute, attributes);}
251
- if (type == "endTag" || type == "selfcloseTag") return pass();
252
- setStyle = "error";
253
- return cont(attributes);
254
- }
255
- function attribute(type) {
256
- if (type == "equals") return cont(attvalue, attributes);
257
- if (!Kludges.allowMissing) setStyle = "error";
258
- return (type == "endTag" || type == "selfcloseTag") ? pass() : cont();
259
- }
260
- function attvalue(type) {
261
- if (type == "string") return cont(attvaluemaybe);
262
- if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();}
263
- setStyle = "error";
264
- return (type == "endTag" || type == "selfCloseTag") ? pass() : cont();
265
- }
266
- function attvaluemaybe(type) {
267
- if (type == "string") return cont(attvaluemaybe);
268
- else return pass();
269
- }
270
-
271
- return {
272
- startState: function() {
273
- return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null};
274
- },
275
-
276
- token: function(stream, state) {
277
- if (stream.sol()) {
278
- state.startOfLine = true;
279
- state.indented = stream.indentation();
280
- }
281
- if (stream.eatSpace()) return null;
282
-
283
- setStyle = type = tagName = null;
284
- var style = state.tokenize(stream, state);
285
- state.type = type;
286
- if ((style || type) && style != "comment") {
287
- curState = state;
288
- while (true) {
289
- var comb = state.cc.pop() || element;
290
- if (comb(type || style)) break;
291
- }
292
- }
293
- state.startOfLine = false;
294
- return setStyle || style;
295
- },
296
-
297
- indent: function(state, textAfter, fullLine) {
298
- var context = state.context;
299
- if ((state.tokenize != inTag && state.tokenize != inText) ||
300
- context && context.noIndent)
301
- return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
302
- if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
303
- if (context && /^<\//.test(textAfter))
304
- context = context.prev;
305
- while (context && !context.startOfLine)
306
- context = context.prev;
307
- if (context) return context.indent + indentUnit;
308
- else return 0;
309
- },
310
-
311
- compareStates: function(a, b) {
312
- if (a.indented != b.indented || a.tokenize != b.tokenize) return false;
313
- for (var ca = a.context, cb = b.context; ; ca = ca.prev, cb = cb.prev) {
314
- if (!ca || !cb) return ca == cb;
315
- if (ca.tagName != cb.tagName) return false;
316
- }
317
- },
318
-
319
- electricChars: "/"
320
- };
321
- });
322
-
323
- CodeMirror.defineMIME("application/xml", "xml");
324
- if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
325
- CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/theme/ambiance.css DELETED
@@ -1,82 +0,0 @@
1
- /* ambiance theme for code-mirror */
2
-
3
- /* Color scheme */
4
-
5
- .cm-s-ambiance .cm-keyword { color: #cda869; }
6
- .cm-s-ambiance .cm-atom { color: #CF7EA9; }
7
- .cm-s-ambiance .cm-number { color: #78CF8A; }
8
- .cm-s-ambiance .cm-def { color: #aac6e3; }
9
- .cm-s-ambiance .cm-variable { color: #ffb795; }
10
- .cm-s-ambiance .cm-variable-2 { color: #eed1b3; }
11
- .cm-s-ambiance .cm-variable-3 { color: #faded3; }
12
- .cm-s-ambiance .cm-property { color: #eed1b3; }
13
- .cm-s-ambiance .cm-operator {color: #fa8d6a;}
14
- .cm-s-ambiance .cm-comment { color: #555; font-style:italic; }
15
- .cm-s-ambiance .cm-string { color: #8f9d6a; }
16
- .cm-s-ambiance .cm-string-2 { color: #9d937c; }
17
- .cm-s-ambiance .cm-meta { color: #D2A8A1; }
18
- .cm-s-ambiance .cm-error { color: #AF2018; }
19
- .cm-s-ambiance .cm-qualifier { color: yellow; }
20
- .cm-s-ambiance .cm-builtin { color: #9999cc; }
21
- .cm-s-ambiance .cm-bracket { color: #24C2C7; }
22
- .cm-s-ambiance .cm-tag { color: #fee4ff }
23
- .cm-s-ambiance .cm-attribute { color: #9B859D; }
24
- .cm-s-ambiance .cm-header {color: #blue;}
25
- .cm-s-ambiance .cm-quote { color: #24C2C7; }
26
- .cm-s-ambiance .cm-hr { color: pink; }
27
- .cm-s-ambiance .cm-link { color: #F4C20B; }
28
- .cm-s-ambiance .cm-special { color: #FF9D00; }
29
-
30
- .cm-s-ambiance .CodeMirror-matchingbracket { color: #0f0; }
31
- .cm-s-ambiance .CodeMirror-nonmatchingbracket { color: #f22; }
32
-
33
- .cm-s-ambiance .CodeMirror-selected {
34
- background: rgba(255, 255, 255, 0.15);
35
- }
36
- .CodeMirror-focused .cm-s-ambiance .CodeMirror-selected {
37
- background: rgba(255, 255, 255, 0.10);
38
- }
39
-
40
- /* Editor styling */
41
-
42
- .cm-s-ambiance {
43
- line-height: 1.40em;
44
- font-family: Monaco, Menlo,"Andale Mono","lucida console","Courier New",monospace !important;
45
- font-size: 12px;
46
- color: #E6E1DC;
47
- background-color: #202020;
48
- -webkit-box-shadow: inset 0 0 10px black;
49
- -moz-box-shadow: inset 0 0 10px black;
50
- -o-box-shadow: inset 0 0 10px black;
51
- box-shadow: inset 0 0 10px black;
52
- }
53
-
54
- .cm-s-ambiance .CodeMirror-gutter {
55
- background: #3D3D3D;
56
- padding: 0 5px;
57
- text-shadow: #333 1px 1px;
58
- border-right: 1px solid #4D4D4D;
59
- box-shadow: 0 10px 20px black;
60
- }
61
-
62
- .cm-s-ambiance .CodeMirror-gutter .CodeMirror-gutter-text {
63
- text-shadow: 0px 1px 1px #4d4d4d;
64
- color: #222;
65
- }
66
-
67
- .cm-s-ambiance .CodeMirror-lines {
68
-
69
- }
70
-
71
- .cm-s-ambiance .CodeMirror-lines .CodeMirror-cursor {
72
- border-left: 1px solid #7991E8;
73
- }
74
-
75
- .cm-s-ambiance .activeline {
76
- background: none repeat scroll 0% 0% rgba(255, 255, 255, 0.031);
77
- }
78
-
79
- .cm-s-ambiance,
80
- .cm-s-ambiance .CodeMirror-gutter {
81
- background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAQAAAAHUWYVAABFFUlEQVQYGbzBCeDVU/74/6fj9HIcx/FRHx9JCFmzMyGRURhLZIkUsoeRfUjS2FNDtr6WkMhO9sm+S8maJfu+Jcsg+/o/c+Z4z/t97/vezy3z+z8ekGlnYICG/o7gdk+wmSHZ1z4pJItqapjoKXWahm8NmV6eOTbWUOp6/6a/XIg6GQqmenJ2lDHyvCFZ2cBDbmtHA043VFhHwXxClWmeYAdLhV00Bd85go8VmaFCkbVkzlQENzfBDZ5gtN7HwF0KDrTwJ0dypSOzpaKCMwQHKTIreYIxlmhXTzTWkVm+LTynZhiSBT3RZQ7aGfjGEd3qyXQ1FDymqbKxpspERQN2MiRjNZlFFQXfCNFm9nM1zpAsoYjmtRTc5ajwuaXc5xrWskT97RaKzAGe5ARHhVUsDbjKklziiX5WROcJwSNCNI+9w1Jwv4Zb2r7lCMZ4oq5C0EdTx+2GzNuKpJ+iFf38JEWkHJn9DNF7mmBDITrWEg0VWL3pHU20tSZnuqWu+R3BtYa8XxV1HO7GyD32UkOpL/yDloINFTmvtId+nmAjxRw40VMwVKiwrKLE4bK5UOVntYwhOcSSXKrJHKPJedocpGjVz/ZMIbnYUPB10/eKCrs5apqpgVmWzBYWpmtKHecJPjaUuEgRDDaU0oZghCJ6zNMQ5ZhDYx05r5v2muQdM0EILtXUsaKiQX9WMEUotagQzFbUNN6NUPC2nm5pxEWGCjMc3GdJHjSU2kORLK/JGSrkfGEIjncU/CYUnOipoYemwj8tST9NsJmB7TUVXtbUtXATJVZXBMvYeTXJfobgJUPmGMP/yFaWonaa6BcFO3nqcIqCozSZoZoSr1g4zJOzuyGnxTEX3lUEJ7WcZgme8ddaWvWJo2AJR9DZU3CUIbhCSG6ybSwN6qtJVnCU2svDTP2ZInOw2cBTrqtQahtNZn9NcJ4l2NaSmSkkP1noZWnVwkLmdUPOwLZEwy2Z3S3R+4rIG9hcbpPXHFVWcQdZkn2FOta3cKWQnNRC5g1LsJah4GCzSVsKnCOY5OAFRTBekyyryeyilhFKva75r4Mc0aWanGEaThcy31s439KKxTzJYY5WTHPU1FtIHjQU3Oip4xlNzj/lBw23dYZVliQa7WAXf4shetcQfatI+jWRDBPmyNeW6A1P5kdDgyYJlba0BIM8BZu1JfrFwItyjcAMR3K0BWOIrtMEXyhyrlVEx3ui5dUBjmB/Q3CXW85R4mBD0s7B+4q5tKUjOlb9qqmhi5AZ6GFIC5HXtOobdYGlVdMVbNJ8toNTFcHxnoL+muBagcctjWnbNMuR00uI7nQESwg5q2qqrKWIfrNUmeQocY6HuyxJV02wj36w00yhpmUFenv4p6fUkZYqLyuinx2RGOjhCXYyJF84oiU00YMOOhhquNdfbOB7gU88pY4xJO8LVdp6/q2voeB4R04vIdhSE40xZObx1HGGJ/ja0LBthFInKaLPPFzuCaYaoj8JjPME8yoyxo6zlBqkiUZYgq00OYMswbWO5NGmq+xhipxHLRW29ARjNKXO0wRnear8XSg4XFPLKEPUS1GqvyLwiuBUoa7zpZ0l5xxFwWmWZC1H5h5FwU8eQ7K+g8UcVY6TMQreVQT/8uQ8Z+ALIXnSEa2pYZQneE9RZbSBNYXfWYJzW/h/4j4Dp1tYVcFIC5019Vyi4ThPqSFCzjGWaHQTBU8q6vrVwgxP9Lkm840imWKpcLCjYTtrKuwvsKSnrvHCXGkSMk9p6lhckfRpIeis+N2PiszT+mFLspyGleUhDwcLrZqmyeylxwjBcKHEapqkmyangyLZRVOijwOtCY5SsG5zL0OwlCJ4y5KznF3EUNDDrinwiyLZRzOXtlBbK5ITHFGLp8Q0R6ab6mS7enI2cFrxOyHvOCFaT1HThS1krjCwqWeurCkk+willhCC+RSZnRXBiZaC5RXRIZYKp2lyfrHwiKPKR0JDzrdU2EFgpidawlFDR6FgXUMNa+g1FY3bUQh2cLCwosRdnuQTS/S+JVrGLeWIvtQUvONJxlqSQYYKpwoN2kaocLjdVsis4Mk80ESF2YpSkzwldjHkjFCUutI/r+EHDU8oCs6yzL3PhWiEooZdFMkymlas4AcI3KmoMMNSQ3tHzjGWCrcJJdYyZC7QFGwjRL9p+MrRkAGWzIaWCn9W0F3TsK01c2ZvQw0byvxuQU0r1lM0qJO7wW0kRIMdDTtXEdzi4VIh+EoIHm0mWtAtpCixlabgn83fKTI7anJe9ST7WIK1DMGpQmYeA58ImV6ezOGOzK2Kgq01pd60cKWiUi9Lievb/0vIDPHQ05Kzt4ddPckQBQtoaurjyHnek/nKzpQLrVgKPjIkh2v4uyezpv+Xoo7fPFXaGFp1vaLKxQ4uUpQQS5VuQs7BCq4xRJv7fwpVvvFEB3j+620haOuocqMhWd6TTPAEx+mdFNGHdranFe95WrWmIvlY4F1Dle2ECgc6cto7SryuqGGGha0tFQ5V53migUKmg6XKAo4qS3mik+0OZpAhOLeZKicacgaYcyx5hypYQE02ZA4xi/pNhOQxR4klNKyqacj+mpxnLTnnGSo85++3ZCZq6lrZkXlGEX3o+C9FieccJbZWVFjC0Yo1FZnJhoYMFoI1hEZ9r6hwg75HwzBNhbZCdJEfJwTPGzJvaKImw1yYX1HDAmpXR+ZJQ/SmgqMNVQb5vgamGwLtt7VwvP7Qk1xpiM5x5Cyv93E06MZmgs0Nya2azIKOYKCGBQQW97RmhKNKF02JZqHEJ4o58qp7X5EcZmc56trXEqzjCBZ1MFGR87Ql2tSTs6CGxS05PTzRQorkbw7aKoKXFDXsYW42VJih/q+FP2BdTzDTwVqOYB13liM50vG7wy28qagyuIXMeQI/Oqq8bcn5wJI50xH00CRntyfpL1T4hydYpoXgNiFzoIUTDZnLNRzh4TBHwbYGDvZkxmlyJloyr6tRihpeUG94GnKtIznREF0tzJG/OOr73JBcrSh1k6WuTprgLU+mnSGnv6Zge0NNz+kTDdH8nuAuTdJDCNb21LCiIuqlYbqGzT3RAoZofQfjFazkqeNWdYaGvYTM001EW2oKPvVk1ldUGSgUtHFwjKM1h9jnFcmy5lChoLNaQMGGDsYbKixlaMBmmsx1QjCfflwTfO/gckW0ruZ3jugKR3R5W9hGUWqCgxuFgsuaCHorotGKzGaeZB9DMsaTnKCpMtwTvOzhYk0rdrArKCqcaWmVk1+F372ur1YkKxgatI8Qfe1gIX9wE9FgS8ESmuABIXnRUbCapcKe+nO7slClSZFzpV/LkLncEb1qiO42fS3R855Su2mCLh62t1SYZZYVmKwIHjREF2uihTzB20JOkz7dkxzYQnK0UOU494wh+VWRc6Un2kpTaVgLDFEkJ/uhzRcI0YKGgpGWOlocBU/a4fKoJ/pEaNV6jip3+Es9VXY078rGnmAdf7t9ylPXS34RBSuYPs1UecZTU78WanhBCHpZ5sAoTz0LGZKjPf9TRypqWEiTvOFglL1fCEY3wY/++rbk7C8bWebA6p6om6PgOL2kp44TFJlVNBXae2rqqdZztOJpT87GQsE9jqCPIe9VReZuQ/CIgacsyZdCpIScSYqcZk8r+nsyCzhyfhOqHGOIvrLknC8wTpFcaYiGC/RU1NRbUeUpocQOnkRpGOrIOcNRx+1uA0UrzhSSt+VyS3SJpnFWkzNDqOFGIWcfR86DnmARTQ1HKIL33ExPiemeOhYSSjzlSUZZuE4TveoJLnBUOFof6KiysCbnAEcZgcUNTDOwkqWu3RWtmGpZwlHhJENdZ3miGz0lJlsKnjbwqSHQjpxnFDlTLLwqJPMZMjd7KrzkSG7VsxXBZE+F8YZkb01Oe00yyRK9psh5SYh29ySPKBo2ylNht7ZkZnsKenjKNJu9PNEyZpaCHv4Kt6RQsLvAVp7M9kIimmCUwGeWqLMmGuIotYMmWNpSahkhZw9FqZsVnKJhsjAHvtHMsTM9fCI06Dx/u3vfUXCqfsKRc4oFY2jMsoo/7DJDwZ1CsIKnJu+J9ldkpmiCxQx1rWjI+T9FwcWWzOuaYH0Hj7klNRVWEQpmaqosakiGNTFHdjS/qnUdmf0NJW5xsL0HhimCCZZSRzmSPTXJQ4aaztAwtZnoabebJ+htCaZ7Cm535ByoqXKbX1WRc4Eh2MkRXWzImVc96Cj4VdOKVxR84VdQsIUM8Psoou2byVHyZFuq7O8otbSQ2UAoeEWTudATLGSpZzVLlXVkPU2Jc+27lsw2jmg5T5VhbeE3BT083K9WsTTkFU/Osi0rC5lRlpwRHUiesNS0sOvmqGML1aRbPAxTJD9ZKtxuob+hhl8cwYGWpJ8nub7t5p6coYbMovZ1BTdaKn1jYD6h4GFDNFyT/Kqe1XCXphXHOKLZmuRSRdBPEfVUXQzJm5YGPGGJdvAEr7hHNdGZnuBvrpciGmopOLf5N0uVMy0FfYToJk90uUCbJupaVpO53UJXR2bVpoU00V2KOo4zMFrBd0Jtz2pa0clT5Q5L8IpQ177mWQejPMEJhuQjS10ref6HHjdEhy1P1EYR7GtO0uSsKJQYLiTnG1rVScj5lyazpqWGl5uBbRWl7m6ixGOOnEsMJR7z8J0n6KMnCdxhiNYQCoZ6CmYLnO8omC3MkW3bktlPmEt/VQQHejL3+dOE5FlPdK/Mq8hZxxJtLyRrepLThYKbLZxkSb5W52vYxNOaOxUF0yxMUPwBTYqCzy01XayYK0sJyWBLqX0MwU5CzoymRzV0EjjeUeLgDpTo6ij42ZAzvD01dHUUTPLU96MdLbBME8nFBn7zJCMtJcZokn8YoqU0FS5WFKyniHobguMcmW8N0XkWZjkyN3hqOMtS08r+/xTBwpZSZ3qiVRX8SzMHHjfUNFjgHEPmY9PL3ykEzxkSre/1ZD6z/NuznuB0RcE1TWTm9zRgfUWVJiG6yrzgmWPXC8EAR4Wxhlad0ZbgQyEz3pG5RVEwwDJH2mgKpjcTiCOzn1lfUWANFbZ2BA8balnEweJC9J0iuaeZoI+ippFCztEKVvckR2iice1JvhVytrQwUAZpgsubCPaU7xUe9vWnaOpaSBEspalykhC9bUlOMpT42ZHca6hyrqKmw/wMR8H5ZmdFoBVJb03O4UL0tSNnvIeRmkrLWqrs78gcrEn2tpcboh0UPOW3UUR9PMk4T4nnNKWmCjlrefhCwxRNztfmIQVdDElvS4m1/WuOujoZCs5XVOjtKPGokJzsYCtFYoWonSPT21DheU/wWhM19FcElwqNGOsp9Q8N/cwXaiND1MmeL1Q5XROtYYgGeFq1aTMsoMmcrKjQrOFQTQ1fmBYhmW6o8Jkjc7iDJRTBIo5kgJD5yMEYA3srCg7VFKwiVJkmRCc5ohGOKhsYMn/XBLdo5taZjlb9YAlGWRimqbCsoY7HFAXLa5I1HPRxMMsQDHFkWtRNniqT9UEeNjcE7RUlrCJ4R2CSJuqlKHWvJXjAUNcITYkenuBRB84TbeepcqTj3zZyFJzgYQdHnqfgI0ddUwS6GqWpsKWhjq9cV0vBAEMN2znq+EBfIWT+pClYw5xsTlJU6GeIBsjGmmANTzJZiIYpgrM0Oa8ZMjd7NP87jxhqGOhJlnQtjuQpB+8aEE00wZFznSJPyHxgH3HkPOsJFvYk8zqCHzTs1BYOa4J3PFU+UVRZxlHDM4YavlNUuMoRveiZA2d7grMNc2g+RbSCEKzmgYsUmWmazFJyoiOZ4KnyhKOGRzWJa0+moyV4TVHDzn51Awtqaphfk/lRQ08FX1iiqxTB/kLwd0VynKfEvI6cd4XMV5bMhZ7gZUWVzYQ6Nm2BYzxJbw3bGthEUUMfgbGeorae6DxHtJoZ6alhZ0+ytiVoK1R4z5PTrOECT/SugseEOlb1MMNR4VRNcJy+V1Hg9ONClSZFZjdHlc6W6FBLdJja2MC5hhpu0DBYEY1TFGwiFAxRRCsYkiM9JRb0JNMVkW6CZYT/2EiTGWmo8k+h4FhDNE7BvppoTSFnmCV5xZKzvcCdDo7VVPnIU+I+Rc68juApC90MwcFCsJ5hDqxgScYKreruyQwTqrzoqDCmhWi4IbhB0Yrt3RGa6GfDv52rKXWhh28dyZaWUvcZeMTBaZoSGyiCtRU5J8iviioHaErs7Jkj61syVzTTgOcUOQ8buFBTYWdL5g3T4qlpe0+wvD63heAXRfCCIed9RbCsp2CiI7raUOYOTU13N8PNHvpaGvayo4a3LLT1lDrVEPT2zLUlheB1R+ZTRfKWJ+dcocLJfi11vyJ51lLqJ0WD7tRwryezjiV5W28uJO9qykzX8JDe2lHl/9oyBwa2UMfOngpXCixvKdXTk3wrsKmiVYdZIqsoWEERjbcUNDuiaQomGoIbFdEHmsyWnuR+IeriKDVLnlawlyNHKwKlSU631PKep8J4Q+ayjkSLKYLhalNHlYvttb6fHm0p6OApsZ4l2VfdqZkjuysy6ysKLlckf1KUutCTs39bmCgEyyoasIWlVaMF7mgmWtBT8Kol5xpH9IGllo8cJdopcvZ2sImlDmMIbtDk3KIpeNiS08lQw11NFPTwVFlPP6pJ2gvRfI7gQUfmNAtf6Gs0wQxDsKGlVBdF8rCa3jzdwMaGHOsItrZk7hAyOzpK9VS06j5F49b0VNGOOfKs3lDToMsMBe9ZWtHFEgxTJLs7qrygKZjUnmCYoeAqeU6jqWuLJup4WghOdvCYJnrSkSzoyRkm5M2StQwVltPkfCAk58tET/CSg+8MUecmotMEnhBKfWBIZsg2ihruMJQaoIm+tkTLKEqspMh00w95gvFCQRtDwTT1gVDDSEVdlwqZfxoQRbK0g+tbiBZxzKlpnpypejdDwTaeOvorMk/IJE10h9CqRe28hhLbe0pMsdSwv4ZbhKivo2BjDWfL8UKJgeavwlwb5KlwhyE4u4XkGE2ytZCznKLCDZZq42VzT8HLCrpruFbIfOIINmh/qCdZ1ZBc65kLHR1Bkyf5zn6pN3SvGKIlFNGplhrO9QSXanLOMQTLCa0YJCRrCZm/CZmrLTm7WzCK4GJDiWUdFeYx1LCFg3NMd0XmCuF3Y5rITLDUsYS9zoHVzwnJoYpSTQoObyEzr4cFBNqYTopoaU/wkyLZ2lPhX/5Y95ulxGTV7KjhWrOZgl8MyUUafjYraNjNU1N3IWcjT5WzWqjwtoarHSUObGYO3GCJZpsBlnJGPd6ZYLyl1GdCA2625IwwJDP8GUKymbzuyPlZlvTUsaUh5zFDhRWFzPKKZLAlWdcQbObgF9tOqOsmB1dqcqYJmWstFbZRRI9poolmqiLnU0POvxScpah2iSL5UJNzgScY5+AuIbpO0YD3NCW+dLMszFSdFCWGqG6eVq2uYVNDdICGD6W7EPRWZEY5gpsE9rUkS3mijzzJnm6UpUFXG1hCUeVoS5WfNcFpblELL2qqrCvMvRfd45oalvKU2tiQ6ePJOVMRXase9iTtLJztPxJKLWpo2CRDcJwn2sWSLKIO1WQWNTCvpVUvOZhgSC40JD0dOctaSqzkCRbXsKlb11Oip6PCJ0IwSJM31j3akRxlP7Rwn6aGaUL0qiLnJkvB3xWZ2+Q1TfCwpQH3G0o92UzmX4o/oJNQMMSQc547wVHhdk+VCw01DFYEnTxzZKAm74QmeNNR1w6WzEhNK15VJzuCdxQ53dRUDws5KvwgBMOEgpcVNe0hZI6RXT1Jd0cyj5nsaEAHgVmGaJIlWdsc5Ui2ElrRR6jrRAttNMEAIWrTDFubkZaok7/AkzfIwfuWVq0jHzuCK4QabtLUMVPB3kJ0oyHTSVFlqMALilJf2Rf8k5aaHtMfayocLBS8L89oKoxpJvnAkDPa0qp5DAUTHKWmCcnthlou8iCKaFFLHWcINd1nyIwXqrSxMNmSs6KmoL2QrKuWtlQ5V0120xQ5vRyZS1rgFkWwhiOwiuQbR0OOVhQM9iS3tiXp4RawRPMp5tDletOOBL95MpM01dZTBM9pkn5qF010rIeHFcFZhmSGpYpTsI6nwhqe5C9ynhlpp5ophuRb6WcJFldkVnVEwwxVfrVkvnWUuNLCg5bgboFHPDlDPDmnK7hUrWiIbjadDclujlZcaokOFup4Ri1kacV6jmrrK1hN9bGwpKEBQ4Q6DvIUXOmo6U5LqQM6EPyiKNjVkPnJkDPNEaxhiFay5ExW1NXVUGqcpYYdPcGiCq7z/TSlbhL4pplWXKd7NZO5QQFrefhRQW/NHOsqcIglc4UhWklR8K0QzbAw08CBDnpbgqXdeD/QUsM4RZXDFBW6WJKe/mFPdH0LtBgiq57wFLzlyQzz82qYx5D5WJP5yVJDW01BfyHnS6HKO/reZqId1WGa4Hkh2kWodJ8i6KoIPlAj2hPt76CzXsVR6koPRzWTfKqIentatYpQw2me4AA3y1Kind3SwoOKZDcFXTwl9tWU6mfgRk9d71sKtlNwrjnYw5tC5n5LdKiGry3JKNlHEd3oaMCFHrazBPMp/uNJ+V7IudcSbeOIdjUEdwl0VHCOZo5t6YluEuaC9mQeMgSfOyKnYGFHcIeQ84yQWbuJYJpZw5CzglDH7gKnWqqM9ZTaXcN0TeYhR84eQtJT76JJ1lREe7WnnvsMmRc9FQ7SBBM9mV3lCUdmHk/S2RAMt0QjFNFqQpWjDPQ01DXWUdDBkXziKPjGEP3VP+zIWU2t7im41FOloyWzn/L6dkUy3VLDaZ6appgDLHPjJEsyvJngWEPUyVBiAaHCTEXwrLvSEbV1e1gKJniicWorC1MUrVjB3uDhJE/wgSOzk1DXpk0k73qCM8xw2UvD5kJmDUfOomqMpWCkJRlvKXGmoeBm18USjVIk04SClxTB6YrgLAPLWYK9HLUt5cmc0vYES8GnTeRc6skZbQkWdxRsIcyBRzx1DbTk9FbU0caTPOgJHhJKnOGIVhQqvKmo0llRw9sabrZkDtdg3PqaKi9oatjY8B+G371paMg6+mZFNNtQ04mWBq3rYLOmtWWQp8KJnpy9DdFensyjdqZ+yY40VJlH8wcdLzC8PZnvHMFUTZUrDTkLyQaGus5X5LzpYAf3i+e/ZlhqGqWhh6Ou6xTR9Z6oi5AZZtp7Mj2EEm8oSpxiYZCHU/1fbGdNNNRRoZMhmilEb2gqHOEJDtXkHK/JnG6IrvbPCwV3NhONVdS1thBMs1T4QOBcTWa2IzhMk2nW5Kyn9tXUtpv9RsG2msxk+ZsQzRQacJncpgke0+T8y5Fzj8BiGo7XlJjaTIlpQs7KFjpqGnKuoyEPeIKnFMkZHvopgh81ySxNFWvJWcKRs70j2FOT012IllEEO1n4pD1513Yg2ssQPOThOkvyrqHUdEXOSEsihmBbTbKX1kLBPWqWkLOqJbjB3GBIZmoa8qWl4CG/iZ7oiA72ZL7TJNeZUY7kFQftDcHHluBzRbCegzMtrRjVQpX2lgoPKKLJAkcbMl01XK2p7yhL8pCBbQ3BN2avJgKvttcrWDK3CiUOVxQ8ZP+pqXKyIxnmBymCg5vJjNfkPK4+c8cIfK8ocVt7kmfd/I5SR1hKvCzUtb+lhgc00ZaO6CyhIQP1Uv4yIZjload72PXX0OIJvnFU+0Zf6MhsJwTfW0r0UwQfW4LNLZl5HK261JCZ4qnBaAreVAS3WrjV0LBnNDUNNDToCEeFfwgcb4gOEqLRhirWkexrCEYKVV711DLYEE1XBEsp5tpTGjorkomKYF9FDXv7fR3BGwbettSxnyL53MBPjsxDZjMh+VUW9NRxq1DhVk+FSxQcaGjV9Pawv6eGByw5qzoy7xk4RsOShqjJwWKe/1pEEfzkobeD/dQJmpqedcyBTy2sr4nGNRH0c0SPWTLrqAc0OQcb/gemKgqucQT7ySWKCn2EUotoCvpZct7RO2sy/QW0IWcXd7pQRQyZVwT2USRO87uhjioTLKV2brpMUcMQRbKH/N2T+UlTpaMls6cmc6CCNy3JdYYSUzzJQ4oSD3oKLncULOiJvjBEC2oqnCJkJluCYy2ZQ5so9YYlZ1VLlQU1mXEW1jZERwj/MUSRc24TdexlqLKfQBtDTScJUV8FszXBEY5ktpD5Ur9hYB4Nb1iikw3JoYpkKX+RodRKFt53MMuRnKSpY31PwYaGaILh3wxJGz9TkTPEETxoCWZrgvOlmyMzxFEwVJE5xZKzvyJ4WxEc16Gd4Xe3Weq4XH2jKRikqOkGQ87hQnC7wBmGYLAnesX3M+S87eFATauuN+Qcrh7xIxXJbUIdMw3JGE3ylCWzrieaqCn4zhGM19TQ3z1oH1AX+pWEqIc7wNGAkULBo/ZxRaV9NNyh4Br3rCHZzbzmSfawBL0dNRwpW1kK9mxPXR9povcdrGSZK9c2k0xwFGzjuniCtRSZCZ6ccZ7gaktmgAOtKbG/JnOkJrjcQTdFMsxRQ2cLY3WTIrlCw1eWKn8R6pvt4GFDso3QoL4a3nLk3G6JrtME3dSenpx7PNFTmga0EaJTLQ061sEeQoWXhSo9LTXsaSjoJQRXeZLtDclbCrYzfzHHeaKjHCVOUkQHO3JeEepr56mhiyaYYKjjNU+Fed1wS5VlhWSqI/hYUdDOkaxiKehoyOnrCV5yBHtbWFqTHCCwtpDcYolesVR5yUzTZBb3RNMd0d6WP+SvhuBmRcGxnuQzT95IC285cr41cLGQ6aJJhmi4TMGempxeimBRQw1tFKV+8jd6KuzoSTqqDxzRtpZkurvKEHxlqXKRIjjfUNNXQsNOsRScoWFLT+YeRZVD3GRN0MdQcKqQjHDMrdGGVu3iYJpQx3WGUvfbmxwFfR20WBq0oYY7LMFhhgYtr8jpaEnaOzjawWWaTP8mMr0t/EPDPoqcnxTBI5o58L7uoWnMrpoqPwgVrlAUWE+V+TQl9rawoyP6QGAlQw2TPRX+YSkxyBC8Z6jhHkXBgQL7WII3DVFnRfCrBfxewv9D6xsyjys4VkhWb9pUU627JllV0YDNHMku/ldNMMXDEo4aFnAkk4U6frNEU4XgZUPmEKHUl44KrzmYamjAbh0JFvGnaTLPu1s9jPCwjFpYiN7z1DTOk/nc07CfDFzmCf7i+bfNHXhDtLeBXzTBT5rkMvWOIxpl4EMh2LGJBu2syDnAEx2naEhHDWMMzPZEhygyS1mS5RTJr5ZkoKbEUoYqr2kqdDUE8ztK7OaIntJkFrIECwv8LJTaVx5XJE86go8dFeZ3FN3rjabCAYpoYEeC9zzJVULBbmZhDyd7ko09ydpNZ3nm2Kee4FPPXHnYEF1nqOFEC08LUVcDvYXkJHW8gTaKCk9YGOeIJhqiE4ToPEepdp7IWFjdwnWaufGMwJJCMtUTTBBK9BGCOy2tGGrJTHIwyEOzp6aPzNMOtlZkDvcEWpP5SVNhfkvDxhmSazTJXYrM9U1E0xwFVwqZQwzJxw6+kGGGUj2FglGGmnb1/G51udRSMNlTw6GGnCcUwVcOpmsqTHa06o72sw1RL02p9z0VbnMLOaIX3QKaYKSCFQzBKEUNHTSc48k53RH9wxGMtpQa5KjjW0W0n6XCCCG4yxNNdhQ4R4l1Ff+2sSd6UFHiIEOyqqFgT01mEUMD+joy75jPhOA+oVVLm309FR4yVOlp4RhLiScNmSmaYF5Pw0STrOIoWMSR2UkRXOMp+M4SHW8o8Zoi6OZgjKOaFar8zZDzkWzvKOjkKBjmCXby8JahhjXULY4KlzgKLvAwxVGhvyd4zxB1d9T0piazmKLCVZY5sKiD0y2ZSYrkUEPUbIk+dlQ4SJHTR50k1DPaUWIdTZW9NJwnJMOECgd7ou/MnppMJ02O1VT4Wsh85MnZzcFTngpXGKo84qmwgKbCL/orR/SzJ2crA+t6Mp94KvxJUeIbT3CQu1uIdlQEOzlKfS3UMcrTiFmOuroocrZrT2AcmamOKg8YomeEKm/rlT2sociMaybaUlFhuqHCM2qIJ+rg4EcDFymiDSxzaHdPcpE62pD5kyM5SBMoA1PaUtfIthS85ig1VPiPPYXgYEMNk4Qq7TXBgo7oT57gPUdwgCHzhIVFPFU6OYJzHAX9m5oNrVjeE61miDrqQ4VSa1oiURTsKHC0IfjNwU2WzK6eqK8jWln4g15TVBnqmDteCJ501PGAocJhhqjZdtBEB6lnhLreFJKxmlKbeGrqLiSThVIbCdGzloasa6lpMQXHCME2boLpJgT7yWaemu6wBONbqGNVRS0PKIL7LckbjmQtR7K8I5qtqel+T/ChJTNIKLjdUMNIRyvOEko9YYl2cwQveBikCNawJKcLBbc7+JM92mysNvd/Fqp8a0k6CNEe7cnZrxlW0wQXaXjaktnRwNOGZKYiONwS7a1JVheq3WgJHlQUGKHKmp4KAxXR/ULURcNgoa4zhKSLpZR3kxRRb0NmD0OFn+UCS7CzI1nbP6+o4x47QZE5xRCt3ZagnYcvmpYQktXdk5YKXTzBC57kKEe0VVuiSYqapssMS3C9p2CKkHOg8B8Pa8p5atrIw3qezIWanMGa5HRDNF6RM9wcacl0N+Q8Z8hsIkSnaIIdHRUOEebAPy1zbCkhM062FCJtif7PU+UtoVXzWKqM1PxXO8cfdruhFQ/a6x3JKYagvVDhQEtNiyiiSQ7OsuRsZUku0CRNDs4Sog6KKjsZgk2bYJqijgsEenoKeniinRXBn/U3lgpPdyDZynQx8IiioMnCep5Ky8mjGs6Wty0l1hUQTcNWswS3WRp2kCNZwJG8omG8JphPUaFbC8lEfabwP7VtM9yoaNCAjpR41VNhrD9LkbN722v0CoZMByFzhaW+MyzRYEWFDQwN2M4/JiT76PuljT3VU/A36eaIThb+R9oZGOAJ9tewkgGvqOMNRWYjT/Cwu99Q8LqDE4TgbLWxJ1jaDDAERsFOFrobgjUsBScaguXU8kKm2RL19tRypSHnHNlHiIZqgufs4opgQdVdwxBNNFBR6kVFqb8ogimOzB6a6HTzrlDHEpYaxjiiA4TMQobkDg2vejjfwJGWmnbVFAw3H3hq2NyQfG7hz4aC+w3BbwbesG0swYayvpAs6++Ri1Vfzx93mFChvyN5xVHTS+0p9aqCAxyZ6ZacZyw5+7uuQkFPR9DDk9NOiE7X1PCYJVjVUqq7JlrHwWALF5nfHNGjApdpqgzx5OwilDhCiDYTgnc9waGW4BdLNNUQvOtpzDOWHDH8D7TR/A/85KljEQu3NREc4Pl/6B1Hhc8Umb5CsKMmGC9EPcxoT2amwHNCmeOEnOPbklnMkbOgIvO5UMOpQrS9UGVdt6iH/fURjhI/WOpaW9OKLYRod6HCUEdOX000wpDZQ6hwg6LgZfOqo1RfT/CrJzjekXOGhpc1VW71ZLbXyyp+93ILbC1kPtIEYx0FIx1VDrLoVzXRKRYWk809yYlC9ImcrinxtabKnzRJk3lAU1OLEN1j2zrYzr2myHRXJFf4h4QKT1qSTzTB5+ZNTzTRkAxX8FcLV2uS8eoQQ2aAkFzvCM72sJIcJET3WPjRk5wi32uSS9rfZajpWEvj9hW42F4o5NytSXYy8IKHay10VYdrcl4SkqscrXpMwyGOgtkajheSxdQqmpxP1L3t4R5PqasFnrQEjytq6qgp9Y09Qx9o4S1FzhUCn1kyHSzBWLemoSGvOqLNhZyBjmCaAUYpMgt4Ck7wBBMMwWKWgjsUwTaGVsxWC1mYoKiyqqeGKYqonSIRQ3KIkHO0pmAxTdBHkbOvfllfr+AA+7gnc50huVKYK393FOyg7rbPO/izI7hE4CnHHHnJ0ogNPRUGeUpsrZZTBJcrovUcJe51BPsr6GkJdhCCsZ6aTtMEb2pqWkqeVtDXE/QVggsU/Nl86d9RMF3DxvZTA58agu810RWawCiSzzXBeU3MMW9oyJUedvNEvQyNu1f10BSMddR1vaLCYpYa/mGocLSiYDcLbQz8aMn5iyF4xBNMs1P0QEOV7o5gaWGuzSeLue4tt3ro7y4Tgm4G/mopdZgl6q0o6KzJWE3mMksNr3r+a6CbT8g5wZNzT9O7fi/zpaOmnz3BRoqos+tv9zMbdpxsqDBOEewtJLt7cg5wtKKbvldpSzRRCD43VFheCI7yZLppggMVBS/KMAdHODJvOwq2NQSbKKKPLdFWQs7Fqo+mpl01JXYRgq8dnGLhTiFzqmWsUMdpllZdbKlyvSdYxhI9YghOtxR8LgSLWHK62mGGVoxzBE8LNWzqH9CUesQzFy5RQzTc56mhi6fgXEWwpKfE5Z7M05ZgZUPmo6auiv8YKzDYwWBLMErIbKHJvOwIrvEdhOBcQ9JdU1NHQ7CXn2XIDFBKU2WAgcX9UAUzDXWd5alwuyJ41Z9rjKLCL4aCp4WarhPm2rH+SaHUYE001JDZ2ZAzXPjdMpZWvC9wmqIB2lLhQ01D5jO06hghWMndbM7yRJMsoCj1vYbnFQVrW9jak3OlEJ3s/96+p33dEPRV5GxiqaGjIthUU6FFEZyqCa5qJrpBdzSw95IUnOPIrCUUjRZQFrbw5PR0R1qiYx3cb6nrWUMrBmmiBQxVHtTew5ICP/ip6g4hed/Akob/32wvBHsIOX83cI8hGeNeNPCIkPmXe8fPKx84OMSRM1MTdXSwjCZ4S30jVGhvqTRak/OVhgGazHuOCud5onEO1lJr6ecVyaOK6H7zqlBlIaHE0oroCgfvGJIdPcmfLNGLjpz7hZwZQpUbFME0A1cIJa7VNORkgfsMBatbKgwwJM9bSvQXeNOvbIjelg6WWvo5kvbKaJJNHexkKNHL9xRyFlH8Ti2riB5wVPhUk7nGkJnoCe428LR/wRGdYIlmWebCyxou1rCk4g/ShugBDX0V0ZQWkh0dOVsagkM0yV6OoLd5ye+pRlsCr0n+KiQrGuq5yJDzrTAXHtLUMduTDBVKrSm3eHL+6ijxhFDX9Z5gVU/wliHYTMiMFpKLNMEywu80wd3meoFmt6VbRMPenhrOc6DVe4pgXU8DnnHakLOIIrlF4FZPIw6R+zxBP0dyq6OOZ4Q5sLKCcz084ok+VsMMyQhNZmmBgX5xIXOEJTmi7VsGTvMTNdHHhpzdbE8Du2oKxgvBqQKdDDnTFOylCFaxR1syz2iqrOI/FEpNc3C6f11/7+ASS6l2inq2ciTrCCzgyemrCL5SVPjQkdPZUmGy2c9Sw9FtR1sS30RmsKPCS4rkIC/2U0MduwucYolGaPjKEyhzmiPYXagyWbYz8LWBDdzRimAXzxx4z8K9hpzlhLq+NiQ97HuKorMUfK/OVvC2JfiHUPCQI/q7J2gjK+tTDNxkCc4TMssqCs4TGtLVwQihyoAWgj9bosU80XGW6Ac9TJGziaUh5+hnFcHOnlaM1iRn29NaqGENTTTSUHCH2tWTeV0osUhH6psuVLjRUmGWhm6OZEshGeNowABHcJ2Bpy2ZszRcKkRXd2QuKVEeXnbfaEq825FguqfgfE2whlChSRMdron+LATTPQ2Z369t4B9C5gs/ylzv+CMmepIDPclFQl13W0rspPd1JOcbghGOEutqCv5qacURQl3dDKyvyJlqKXGPgcM9FfawJAMVmdcspcYKOZc4GjDYkFlK05olNMHyHn4zFNykyOxt99RkHlfwmiHo60l2EKI+mhreEKp080Tbug08BVPcgoqC5zWt+NLDTZ7oNSF51N1qie7Va3uCCwyZbkINf/NED6jzOsBdZjFN8oqG3wxVunqCSYYKf3EdhJyf9YWGf7tRU2oH3VHgPr1fe5J9hOgHd7xQ0y7qBwXr23aGErP0cm64JVjZwsOGqL+mhNgZmhJLW2oY4UhedsyBgzrCKrq7BmcpNVhR6jBPq64Vgi+kn6XE68pp8J5/+0wRHGOpsKenQn9DZntPzjRLZpDAdD2fnSgkG9tmIXnUwQ6WVighs7Yi2MxQ0N3CqYaCXkJ0oyOztMDJjmSSpcpvlrk0RMMOjmArQ04PRV1DO1FwhCVaUVPpKUM03JK5SxPsIWRu8/CGHi8UHChiqGFDTbSRJWeYUDDcH6vJWUxR4k1FXbMUwV6e4AJFXS8oMqsZKqzvYQ9DDQdZckY4aGsIhtlubbd2r3j4QBMoTamdPZk7O/Bf62lacZwneNjQoGcdVU7zJOd7ghsUHOkosagic6cnWc8+4gg285R6zZP5s1/LUbCKIznTwK36PkdwlOrl4U1LwfdCCa+IrvFkmgw1PCAUXKWo0sURXWcI2muKJlgyFzhynCY4RBOsqCjoI1R5zREco0n2Vt09BQtYSizgKNHfUmUrQ5UOCh51BFcLmY7umhYqXKQomOop8bUnWNNQcIiBcYaC6xzMNOS8JQQfeqKBmmglB+97ok/lfk3ygaHSyZaCRTzRxQo6GzLfa2jWBPepw+UmT7SQEJyiyRkhBLMVOfcoMjcK0eZChfUNzFAUzCsEN5vP/X1uP/n/aoMX+K+nw/Hjr/9xOo7j7Pju61tLcgvJpTWXNbfN5jLpi6VfCOviTktKlFusQixdEKWmEBUKNaIpjZRSSOXSgzaaKLdabrm1/9nZ+/f+vd/vz/v9+Xy+zZ7PRorYoZqyLrCwQdEAixxVOEXNNnjX2nUSRlkqGmWowk8lxR50JPy9Bo6qJXaXwNvREBvnThPEPrewryLhcAnj5WE15Fqi8W7R1sAuEu86S4ENikItFN4xkv9Af4nXSnUVcLiA9xzesFpivRRVeFKtsMRaKBhuSbjOELnAUtlSQUpXgdfB4Z1oSbnFEetbQ0IrAe+Y+pqnDcEJFj6S8LDZzZHwY4e3XONNlARraomNEt2bkvGsosA3ioyHm+6jCMbI59wqt4eeara28IzEmyPgoRaUOEDhTVdEJhmCoTWfC0p8aNkCp0oYqih2iqGi4yXeMkOsn4LdLLnmKfh/YogjNsPebeFGR4m9BJHLzB61XQ3BtpISfS2FugsK9FAtLWX1dCRcrCnUp44CNzuCowUZmxSRgYaE6Za0W2u/E7CVXCiI/UOR8aAm1+OSyE3mOUcwyc1zBBeoX1kiKy0Zfxck1Gsyulti11i83QTBF5Kg3pDQThFMVHiPSlK+0cSedng/VaS8bOZbtsBcTcZAR8JP5KeqQ1OYKAi20njdNNRpgnsU//K+JnaXJaGTomr7aYIphoRn9aeShJWKEq9LcozSF7QleEfDI5LYm5bgVkFkRwVDBCVu0DDIkGupo8TZBq+/pMQURYErJQmPKGKjNDkWOLx7Jd5QizdUweIaKrlP7SwJDhZvONjLkOsBBX9UpGxnydhXkfBLQ8IxgojQbLFnJf81JytSljclYYyEFyx0kVBvKWOFJmONpshGAcsduQY5giVNCV51eOdJYo/pLhbvM0uDHSevNKRcrKZIqnCtJeEsO95RoqcgGK4ocZcho1tTYtcZvH41pNQ7vA0WrhIfOSraIIntIAi+NXWCErdbkvrWwjRLrt0NKUdL6KSOscTOdMSOUtBHwL6OLA0vNSdynaWQEnCpIvKaIrJJEbvHkmuNhn6OjM8VkSGSqn1uYJCGHnq9I3aLhNME3t6GjIkO7xrNFumpyTNX/NrwX7CrIRiqqWijI9JO4d1iieykyfiposQIQ8YjjsjlBh6oHWbwRjgYJQn2NgSnNycmJAk3NiXhx44Sxykihxm8ybUwT1OVKySc7vi3OXVkdBJ4AyXBeksDXG0IhgtYY0lY5ahCD0ehborIk5aUWRJviMA7Xt5kyRjonrXENkm8yYqgs8VzgrJmClK20uMM3jRJ0FiQICQF9hdETlLQWRIb5ki6WDfWRPobvO6a4GP5mcOrNzDFELtTkONLh9dXE8xypEg7z8A9jkhrQ6Fhjlg/QVktJXxt4WXzT/03Q8IaQWSqIuEvloQ2mqC9Jfi7wRul4RX3pSPlzpoVlmCtI2jvKHCFhjcM3sN6lqF6HxnKelLjXWbwrpR4xzuCrTUZx2qq9oAh8p6ixCUGr78g8oyjRAtB5CZFwi80VerVpI0h+IeBxa6Zg6kWvpDHaioYYuEsRbDC3eOmC2JvGYLeioxGknL2UATNJN6hmtj1DlpLvDVmocYbrGCVJKOrg4X6DgddLA203BKMFngdJJFtFd7vJLm6KEpc5yjQrkk7M80SGe34X24nSex1Ra5Omgb71JKyg8SrU3i/kARKwWpH0kOGhKkObyfd0ZGjvyXlAkVZ4xRbYJ2irFMkFY1SwyWxr2oo4zlNiV+7zmaweFpT4kR3kaDAFW6xpSqzJay05FtYR4HmZhc9UxKbbfF2V8RG1MBmSaE+kmC6JnaRXK9gsiXhJHl/U0qM0WTcbyhwkYIvFGwjSbjfwhiJt8ZSQU+Bd5+marPMOkVkD0muxYLIfEuhh60x/J92itguihJSEMySVPQnTewnEm+620rTQEMsOfo4/kP/0ARvWjitlpSX7GxBgcMEsd3EEeYWvdytd+Saawi6aCIj1CkGb6Aj9rwhx16Cf3vAwFy5pyLhVonXzy51FDpdEblbkdJbUcEPDEFzQ8qNmhzzLTmmKWKbFCXeEuRabp6rxbvAtLF442QjQ+wEA9eL1xSR7Q0JXzlSHjJ4exq89yR0laScJ/FW6z4a73pFMEfDiRZvuvijIt86RaSFOl01riV2mD1UEvxGk/Geg5aWwGki1zgKPG9J2U8PEg8qYvMsZeytiTRXBMslCU8JSlxi8EabjwUldlDNLfzTUmCgxWsjqWCOHavYAqsknKFIO0yQ61VL5AVFxk6WhEaCAkdJgt9aSkzXlKNX2jEa79waYuc7gq0N3GDJGCBhoiTXUEPsdknCUE1CK0fwsiaylSF2uiDyO4XX3pFhNd7R4itFGc0k/ElBZwWvq+GC6szVeEoS/MZ+qylwpKNKv9Z469UOjqCjwlusicyTxG6VpNxcQ8IncoR4RhLbR+NdpGGmJWOcIzJGUuKPGpQg8rrG21dOMqQssJQ4RxH5jaUqnZuQ0F4Q+cjxLwPtpZbIAk3QTJHQWBE5S1BokoVtDd6lhqr9UpHSUxMcIYl9pojsb8h4SBOsMQcqvOWC2E8EVehqiJ1hrrAEbQxeK0NGZ0Gkq+guSRgniM23bIHVkqwx4hiHd7smaOyglyIyQuM978j4VS08J/A2G1KeMBRo4fBaSNhKUEZfQewVQ/C1I+MgfbEleEzCUw7mKXI0M3hd1EESVji8x5uQ41nxs1q4RMJCCXs7Iq9acpxn22oSDnQ/sJTxsCbHIYZiLyhY05TY0ZLIOQrGaSJDDN4t8pVaIrsqqFdEegtizc1iTew5Q4ayBDMUsQMkXocaYkc0hZua412siZ1rSXlR460zRJ5SlHGe5j801RLMlJTxtaOM3Q1pvxJ45zUlWFD7rsAbpfEm1JHxG0eh8w2R7QQVzBUw28FhFp5QZzq8t2rx2joqulYTWSuJdTYfWwqMFMcovFmSyJPNyLhE4E10pHzYjOC3huArRa571ZsGajQpQx38SBP5pyZB6lMU3khDnp0MBV51BE9o2E+TY5Ml2E8S7C0o6w1xvCZjf0HkVEHCzFoyNmqC+9wdcqN+Tp7jSDheE9ws8Y5V0NJCn2bk2tqSY4okdrEhx1iDN8cSudwepWmAGXKcJXK65H9to8jYQRH7SBF01ESUJdd0TayVInaWhLkOjlXE5irKGOnI6GSWGCJa482zBI9rCr0jyTVcEuzriC1vcr6mwFGSiqy5zMwxBH/TJHwjSPhL8+01kaaSUuMFKTcLEvaUePcrSmwn8DZrgikWb7CGPxkSjhQwrRk57tctmxLsb9sZvL9LSlyuSLlWkqOjwduo8b6Uv1DkmudIeFF2dHCgxVtk8dpIvHpBxhEOdhKk7OLIUSdJ+cSRY57B+0DgGUUlNfpthTfGkauzxrvTsUUaCVhlKeteTXCoJDCa2NOKhOmC4G1H8JBd4OBZReSRGkqcb/CO1PyLJTLB4j1q8JYaIutEjSLX8YKM+a6phdMsdLFUoV5RTm9JSkuDN8WcIon0NZMNZWh1q8C7SJEwV5HxrmnnTrf3KoJBlmCYI2ilSLlfEvlE4011NNgjgthzEua0oKK7JLE7HZHlEl60BLMVFewg4EWNt0ThrVNEVkkiTwpKXSWJzdRENgvKGq4IhjsiezgSFtsfCUq8qki5S1LRQeYQQ4nemmCkImWMw3tFUoUBZk4NOeZYEp4XRKTGa6wJjrWNHBVJR4m3FCnbuD6aak2WsMTh3SZImGCIPKNgsDpVwnsa70K31lCFJZYcwwSMFcQulGTsZuEaSdBXkPGZhu0FsdUO73RHjq8MPGGIfaGIbVTk6iuI3GFgucHrIQkmWSJdBd7BBu+uOryWAhY7+Lki9rK5wtEQzWwvtbqGhIMFwWRJsElsY4m9IIg9L6lCX0VklaPAYkfkZEGDnOWowlBJjtMUkcGK4Lg6EtoZInMUBVYLgn0UsdmCyCz7gIGHFfk+k1QwTh5We7A9x+IdJ6CvIkEagms0hR50eH9UnTQJ+2oiKyVlLFUE+8gBGu8MQ3CppUHesnjTHN4QB/UGPhCTHLFPHMFrCqa73gqObUJGa03wgbhHkrCfpEpzNLE7JDS25FMKhlhKKWKfCgqstLCPu1zBXy0J2ztwjtixBu8UTRn9LVtkmCN2iyFhtME70JHRQ1KVZXqKI/KNIKYMCYs1GUMEKbM1bKOI9LDXC7zbHS+bt+1MTWS9odA9DtrYtpbImQJ2VHh/lisEwaHqUk1kjKTAKknkBEXkbkdMGwq0dnhzLJF3NJH3JVwrqOB4Sca2hti75nmJN0WzxS6UxDYoEpxpa4htVlRjkYE7DZGzJVU72uC9IyhQL4i8YfGWSYLLNcHXloyz7QhNifmKSE9JgfGmuyLhc403Xm9vqcp6gXe3xuuv8F6VJNxkyTHEkHG2g0aKXL0MsXc1bGfgas2//dCONXiNLCX+5mB7eZIl1kHh7ajwpikyzlUUWOVOsjSQlsS+M0R+pPje/dzBXRZGO0rMtgQrLLG9VSu9n6CMXS3BhwYmSoIBhsjNBmZbgusE9BCPCP5triU4VhNbJfE+swSP27aayE8tuTpYYjtrYjMVGZdp2NpS1s6aBnKSHDsbKuplKbHM4a0wMFd/5/DmGyKrJSUaW4IBrqUhx0vyfzTBBLPIUcnZdrAkNsKR0sWRspumSns6Ch0v/qqIbBYUWKvPU/CFoyrDJGwSNFhbA/MlzKqjrO80hRbpKx0Jewsi/STftwGSlKc1JZyAzx05dhLEdnfQvhZOqiHWWEAHC7+30FuRcZUgaO5gpaIK+xsiHRUsqaPElTV40xQZQ107Q9BZE1nryDVGU9ZSQ47bmhBpLcYpUt7S+xuK/FiT8qKjwXYw5ypS2iuCv7q1gtgjhuBuB8LCFY5cUuCNtsQOFcT+4Ih9JX+k8Ea6v0iCIRZOtCT0Et00JW5UeC85Cg0ScK0k411HcG1zKtre3SeITBRk7WfwDhEvaYLTHP9le0m8By0JDwn4TlLW/aJOvGHxdjYUes+ScZigCkYQdNdEOhkiezgShqkx8ueKjI8lDfK2oNiOFvrZH1hS+tk7NV7nOmLHicGWEgubkXKdwdtZknCLJXaCpkrjZBtLZFsDP9CdxWsSr05Sxl6CMmoFbCOgryX40uDtamB7SVmXW4Ihlgpmq+00tBKUUa83WbjLUNkzDmY7cow1JDygyPGlhgGKYKz4vcV7QBNbJIgM11TUqZaMdwTeSguH6rOaw1JRKzaaGyxVm2EJ/uCIrVWUcZUkcp2grMsEjK+DMwS59jQk3Kd6SEq1d0S6uVmO4Bc1lDXTUcHjluCXEq+1OlBDj1pi9zgiXxnKuE0SqTXwhqbETW6RggMEnGl/q49UT2iCzgJvRwVXS2K/d6+ZkyUl7jawSVLit46EwxVljDZwoSQ20sDBihztHfk2yA8NVZghiXwrYHQdfKAOtzsayjhY9bY0yE2CWEeJ9xfzO423xhL5syS2TFJofO2pboHob0nY4GiAgRrvGQEDa/FWSsoaaYl0syRsEt3kWoH3B01shCXhTUWe9w3Bt44SC9QCh3eShQctwbaK2ApLroGCMlZrYqvlY3qYhM0aXpFkPOuoqJ3Dm6fxXrGwVF9gCWZagjPqznfkuMKQ8DPTQRO8ZqG1hPGKEm9IgpGW4DZDgTNriTxvFiq+Lz+0cKfp4wj6OCK9JSnzNSn9LFU7UhKZZMnYwcJ8s8yRsECScK4j5UOB95HFO0CzhY4xJxuCix0lDlEUeMdS6EZBkTsUkZ4K74dugyTXS7aNgL8aqjDfkCE0ZbwkCXpaWCKhl8P7VD5jxykivSyxyZrYERbe168LYu9ZYh86IkscgVLE7tWPKmJv11CgoyJltMEbrohtVAQfO4ImltiHEroYEs7RxAarVpY8AwXMcMReFOTYWe5iiLRQxJ5Q8DtJ8LQhWOhIeFESPGsILhbNDRljNbHzNRlTFbk2S3L0NOS6V1KFJYKUbSTcIIhM0wQ/s2TM0SRMNcQmSap3jCH4yhJZKSkwyRHpYYgsFeQ4U7xoCB7VVOExhXepo9ABBsYbvGWKXPME3lyH95YioZ0gssQRWWbI+FaSMkXijZXwgiTlYdPdkNLaETxlyDVIwqeaEus0aTcYcg0RVOkpR3CSJqIddK+90JCxzsDVloyrFd5ZAr4TBKfaWa6boEA7C7s6EpYaeFPjveooY72mjIccLHJ9HUwVlDhKkmutJDJBwnp1rvulJZggKDRfbXAkvC/4l3ozQOG9a8lxjx0i7nV4jSXc7vhe3OwIxjgSHjdEhhsif9YkPGlus3iLFDnWOFhtCZbJg0UbQcIaR67JjthoCyMEZRwhiXWyxO5QxI6w5NhT4U1WsJvDO60J34fW9hwzwlKij6ZAW9ne4L0s8C6XeBMEkd/LQy1VucBRot6QMlbivaBhoBgjqGiCJNhsqVp/S2SsG6DIONCR0dXhvWbJ+MRRZJkkuEjgDXJjFQW6SSL7GXK8Z2CZg7cVsbWGoKmEpzQ5elpiy8Ryg7dMkLLUEauzeO86CuwlSOlgYLojZWeJ9xM3S1PWfEfKl5ISLQ0MEKR8YOB2QfCxJBjrKPCN4f9MkaSsqoVXJBmP7EpFZ9UQfOoOFwSzBN4MQ8LsGrymlipcJQhmy0GaQjPqCHaXRwuCZwRbqK2Fg9wlClZqYicrIgMdZfxTQ0c7TBIbrChxmuzoKG8XRaSrIhhiyNFJkrC7oIAWMEOQa5aBekPCRknCo4IKPrYkvCDI8aYmY7WFtprgekcJZ3oLIqssCSMtFbQTJKwXYy3BY5oCh2iKPCpJOE+zRdpYgi6O2KmOAgvVCYaU4ySRek1sgyFhJ403QFHiVEmJHwtybO1gs8Hr5+BETQX3War0qZngYGgtVZtoqd6vFSk/UwdZElYqyjrF4HXUeFspIi9IGKf4j92pKGAdCYMVsbcV3kRF0N+R8LUd5PCsIGWoxDtBkCI0nKofdJQxT+LtZflvuc8Q3CjwWkq8KwUpHzkK/NmSsclCL0nseQdj5FRH5CNHSgtLiW80Of5HU9Hhlsga9bnBq3fEVltKfO5IaSTmGjjc4J0otcP7QsJUSQM8pEj5/wCuUuC2DWz8AAAAAElFTkSuQmCC");
82
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/theme/blackboard.css DELETED
@@ -1,25 +0,0 @@
1
- /* Port of TextMate's Blackboard theme */
2
-
3
- .cm-s-blackboard { background: #0C1021; color: #F8F8F8; }
4
- .cm-s-blackboard .CodeMirror-selected { background: #253B76 !important; }
5
- .cm-s-blackboard .CodeMirror-gutter { background: #0C1021; border-right: 0; }
6
- .cm-s-blackboard .CodeMirror-gutter-text { color: #888; }
7
- .cm-s-blackboard .CodeMirror-cursor { border-left: 1px solid #A7A7A7 !important; }
8
-
9
- .cm-s-blackboard .cm-keyword { color: #FBDE2D; }
10
- .cm-s-blackboard .cm-atom { color: #D8FA3C; }
11
- .cm-s-blackboard .cm-number { color: #D8FA3C; }
12
- .cm-s-blackboard .cm-def { color: #8DA6CE; }
13
- .cm-s-blackboard .cm-variable { color: #FF6400; }
14
- .cm-s-blackboard .cm-operator { color: #FBDE2D;}
15
- .cm-s-blackboard .cm-comment { color: #AEAEAE; }
16
- .cm-s-blackboard .cm-string { color: #61CE3C; }
17
- .cm-s-blackboard .cm-string-2 { color: #61CE3C; }
18
- .cm-s-blackboard .cm-meta { color: #D8FA3C; }
19
- .cm-s-blackboard .cm-error { background: #9D1E15; color: #F8F8F8; }
20
- .cm-s-blackboard .cm-builtin { color: #8DA6CE; }
21
- .cm-s-blackboard .cm-tag { color: #8DA6CE; }
22
- .cm-s-blackboard .cm-attribute { color: #8DA6CE; }
23
- .cm-s-blackboard .cm-header { color: #FF6400; }
24
- .cm-s-blackboard .cm-hr { color: #AEAEAE; }
25
- .cm-s-blackboard .cm-link { color: #8DA6CE; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/theme/cobalt.css DELETED
@@ -1,18 +0,0 @@
1
- .cm-s-cobalt { background: #002240; color: white; }
2
- .cm-s-cobalt div.CodeMirror-selected { background: #b36539 !important; }
3
- .cm-s-cobalt .CodeMirror-gutter { background: #002240; border-right: 1px solid #aaa; }
4
- .cm-s-cobalt .CodeMirror-gutter-text { color: #d0d0d0; }
5
- .cm-s-cobalt .CodeMirror-cursor { border-left: 1px solid white !important; }
6
-
7
- .cm-s-cobalt span.cm-comment { color: #08f; }
8
- .cm-s-cobalt span.cm-atom { color: #845dc4; }
9
- .cm-s-cobalt span.cm-number, .cm-s-cobalt span.cm-attribute { color: #ff80e1; }
10
- .cm-s-cobalt span.cm-keyword { color: #ffee80; }
11
- .cm-s-cobalt span.cm-string { color: #3ad900; }
12
- .cm-s-cobalt span.cm-meta { color: #ff9d00; }
13
- .cm-s-cobalt span.cm-variable-2, .cm-s-cobalt span.cm-tag { color: #9effff; }
14
- .cm-s-cobalt span.cm-variable-3, .cm-s-cobalt span.cm-def { color: white; }
15
- .cm-s-cobalt span.cm-error { color: #9d1e15; }
16
- .cm-s-cobalt span.cm-bracket { color: #d8d8d8; }
17
- .cm-s-cobalt span.cm-builtin, .cm-s-cobalt span.cm-special { color: #ff9e59; }
18
- .cm-s-cobalt span.cm-link { color: #845dc4; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/theme/eclipse.css DELETED
@@ -1,25 +0,0 @@
1
- .cm-s-eclipse span.cm-meta {color: #FF1717;}
2
- .cm-s-eclipse span.cm-keyword { line-height: 1em; font-weight: bold; color: #7F0055; }
3
- .cm-s-eclipse span.cm-atom {color: #219;}
4
- .cm-s-eclipse span.cm-number {color: #164;}
5
- .cm-s-eclipse span.cm-def {color: #00f;}
6
- .cm-s-eclipse span.cm-variable {color: black;}
7
- .cm-s-eclipse span.cm-variable-2 {color: #0000C0;}
8
- .cm-s-eclipse span.cm-variable-3 {color: #0000C0;}
9
- .cm-s-eclipse span.cm-property {color: black;}
10
- .cm-s-eclipse span.cm-operator {color: black;}
11
- .cm-s-eclipse span.cm-comment {color: #3F7F5F;}
12
- .cm-s-eclipse span.cm-string {color: #2A00FF;}
13
- .cm-s-eclipse span.cm-string-2 {color: #f50;}
14
- .cm-s-eclipse span.cm-error {color: #f00;}
15
- .cm-s-eclipse span.cm-qualifier {color: #555;}
16
- .cm-s-eclipse span.cm-builtin {color: #30a;}
17
- .cm-s-eclipse span.cm-bracket {color: #cc7;}
18
- .cm-s-eclipse span.cm-tag {color: #170;}
19
- .cm-s-eclipse span.cm-attribute {color: #00c;}
20
- .cm-s-eclipse span.cm-link {color: #219;}
21
-
22
- .cm-s-eclipse .CodeMirror-matchingbracket {
23
- border:1px solid grey;
24
- color:black !important;;
25
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/theme/lesser-dark.css DELETED
@@ -1,45 +0,0 @@
1
- /*
2
- http://lesscss.org/ dark theme
3
- Ported to CodeMirror by Peter Kroon
4
- */
5
- .CodeMirror{
6
- line-height: 15px;
7
- }
8
- .cm-s-lesser-dark {
9
- font-family: 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', 'Monaco', Courier, monospace !important;
10
- font-size:12px;
11
- }
12
-
13
- .cm-s-lesser-dark { background: #262626; color: #EBEFE7; text-shadow: 0 -1px 1px #262626; }
14
- .cm-s-lesser-dark div.CodeMirror-selected {background: #45443B !important;} /* 33322B*/
15
- .cm-s-lesser-dark .CodeMirror-cursor { border-left: 1px solid white !important; }
16
- .cm-s-lesser-dark .CodeMirror-lines { margin-left:3px; margin-right:3px; }/*editable code holder*/
17
-
18
- div.CodeMirror span.CodeMirror-matchingbracket { color: #7EFC7E; }/*65FC65*/
19
-
20
- .cm-s-lesser-dark .CodeMirror-gutter { background: #262626; border-right:1px solid #aaa; padding-right:3px; min-width:2.5em; }
21
- .cm-s-lesser-dark .CodeMirror-gutter-text { color: #777; }
22
-
23
- .cm-s-lesser-dark span.cm-keyword { color: #599eff; }
24
- .cm-s-lesser-dark span.cm-atom { color: #C2B470; }
25
- .cm-s-lesser-dark span.cm-number { color: #B35E4D; }
26
- .cm-s-lesser-dark span.cm-def {color: white;}
27
- .cm-s-lesser-dark span.cm-variable { color:#D9BF8C; }
28
- .cm-s-lesser-dark span.cm-variable-2 { color: #669199; }
29
- .cm-s-lesser-dark span.cm-variable-3 { color: white; }
30
- .cm-s-lesser-dark span.cm-property {color: #92A75C;}
31
- .cm-s-lesser-dark span.cm-operator {color: #92A75C;}
32
- .cm-s-lesser-dark span.cm-comment { color: #666; }
33
- .cm-s-lesser-dark span.cm-string { color: #BCD279; }
34
- .cm-s-lesser-dark span.cm-string-2 {color: #f50;}
35
- .cm-s-lesser-dark span.cm-meta { color: #738C73; }
36
- .cm-s-lesser-dark span.cm-error { color: #9d1e15; }
37
- .cm-s-lesser-dark span.cm-qualifier {color: #555;}
38
- .cm-s-lesser-dark span.cm-builtin { color: #ff9e59; }
39
- .cm-s-lesser-dark span.cm-bracket { color: #EBEFE7; }
40
- .cm-s-lesser-dark span.cm-tag { color: #669199; }
41
- .cm-s-lesser-dark span.cm-attribute {color: #00c;}
42
- .cm-s-lesser-dark span.cm-header {color: #a0a;}
43
- .cm-s-lesser-dark span.cm-quote {color: #090;}
44
- .cm-s-lesser-dark span.cm-hr {color: #999;}
45
- .cm-s-lesser-dark span.cm-link {color: #00c;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/theme/monokai.css DELETED
@@ -1,28 +0,0 @@
1
- /* Based on Sublime Text's Monokai theme */
2
-
3
- .cm-s-monokai {background: #272822; color: #f8f8f2;}
4
- .cm-s-monokai div.CodeMirror-selected {background: #49483E !important;}
5
- .cm-s-monokai .CodeMirror-gutter {background: #272822; border-right: 0px;}
6
- .cm-s-monokai .CodeMirror-gutter-text {color: #d0d0d0;}
7
- .cm-s-monokai .CodeMirror-cursor {border-left: 1px solid #f8f8f0 !important;}
8
-
9
- .cm-s-monokai span.cm-comment {color: #75715e;}
10
- .cm-s-monokai span.cm-atom {color: #ae81ff;}
11
- .cm-s-monokai span.cm-number {color: #ae81ff;}
12
-
13
- .cm-s-monokai span.cm-property, .cm-s-monokai span.cm-attribute {color: #a6e22e;}
14
- .cm-s-monokai span.cm-keyword {color: #f92672;}
15
- .cm-s-monokai span.cm-string {color: #e6db74;}
16
-
17
- .cm-s-monokai span.cm-variable {color: #a6e22e;}
18
- .cm-s-monokai span.cm-variable-2 {color: #9effff;}
19
- .cm-s-monokai span.cm-def {color: #fd971f;}
20
- .cm-s-monokai span.cm-error {background: #f92672; color: #f8f8f0;}
21
- .cm-s-monokai span.cm-bracket {color: #f8f8f2;}
22
- .cm-s-monokai span.cm-tag {color: #f92672;}
23
- .cm-s-monokai span.cm-link {color: #ae81ff;}
24
-
25
- .cm-s-monokai .CodeMirror-matchingbracket {
26
- text-decoration: underline;
27
- color: white !important;
28
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/theme/neat.css DELETED
@@ -1,9 +0,0 @@
1
- .cm-s-neat span.cm-comment { color: #a86; }
2
- .cm-s-neat span.cm-keyword { line-height: 1em; font-weight: bold; color: blue; }
3
- .cm-s-neat span.cm-string { color: #a22; }
4
- .cm-s-neat span.cm-builtin { line-height: 1em; font-weight: bold; color: #077; }
5
- .cm-s-neat span.cm-special { line-height: 1em; font-weight: bold; color: #0aa; }
6
- .cm-s-neat span.cm-variable { color: black; }
7
- .cm-s-neat span.cm-number, .cm-s-neat span.cm-atom { color: #3a3; }
8
- .cm-s-neat span.cm-meta {color: #555;}
9
- .cm-s-neat span.cm-link { color: #3a3; }
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/theme/rubyblue.css DELETED
@@ -1,21 +0,0 @@
1
- .cm-s-rubyblue { font:13px/1.4em Trebuchet, Verdana, sans-serif; } /* - customized editor font - */
2
-
3
- .cm-s-rubyblue { background: #112435; color: white; }
4
- .cm-s-rubyblue div.CodeMirror-selected { background: #38566F !important; }
5
- .cm-s-rubyblue .CodeMirror-gutter { background: #1F4661; border-right: 7px solid #3E7087; min-width:2.5em; }
6
- .cm-s-rubyblue .CodeMirror-gutter-text { color: white; }
7
- .cm-s-rubyblue .CodeMirror-cursor { border-left: 1px solid white !important; }
8
-
9
- .cm-s-rubyblue span.cm-comment { color: #999; font-style:italic; line-height: 1em; }
10
- .cm-s-rubyblue span.cm-atom { color: #F4C20B; }
11
- .cm-s-rubyblue span.cm-number, .cm-s-rubyblue span.cm-attribute { color: #82C6E0; }
12
- .cm-s-rubyblue span.cm-keyword { color: #F0F; }
13
- .cm-s-rubyblue span.cm-string { color: #F08047; }
14
- .cm-s-rubyblue span.cm-meta { color: #F0F; }
15
- .cm-s-rubyblue span.cm-variable-2, .cm-s-rubyblue span.cm-tag { color: #7BD827; }
16
- .cm-s-rubyblue span.cm-variable-3, .cm-s-rubyblue span.cm-def { color: white; }
17
- .cm-s-rubyblue span.cm-error { color: #AF2018; }
18
- .cm-s-rubyblue span.cm-bracket { color: #F0F; }
19
- .cm-s-rubyblue span.cm-link { color: #F4C20B; }
20
- .cm-s-rubyblue span.CodeMirror-matchingbracket { color:#F0F !important; }
21
- .cm-s-rubyblue span.cm-builtin, .cm-s-rubyblue span.cm-special { color: #FF9D00; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/CodeMirror2/theme/xq-dark.css DELETED
@@ -1,46 +0,0 @@
1
- /*
2
- Copyright (C) 2011 by MarkLogic Corporation
3
- Author: Mike Brevoort <mike@brevoort.com>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
22
- */
23
- .cm-s-xq-dark { background: #0a001f; color: #f8f8f8; }
24
- .cm-s-xq-dark span.CodeMirror-selected { background: #a8f !important; }
25
- .cm-s-xq-dark .CodeMirror-gutter { background: #0a001f; border-right: 1px solid #aaa; }
26
- .cm-s-xq-dark .CodeMirror-gutter-text { color: #f8f8f8; }
27
- .cm-s-xq-dark .CodeMirror-cursor { border-left: 1px solid white !important; }
28
-
29
- .cm-s-xq-dark span.cm-keyword {color: #FFBD40;}
30
- .cm-s-xq-dark span.cm-atom {color: #6C8CD5;}
31
- .cm-s-xq-dark span.cm-number {color: #164;}
32
- .cm-s-xq-dark span.cm-def {color: #FFF; text-decoration:underline;}
33
- .cm-s-xq-dark span.cm-variable {color: #FFF;}
34
- .cm-s-xq-dark span.cm-variable-2 {color: #EEE;}
35
- .cm-s-xq-dark span.cm-variable-3 {color: #DDD;}
36
- .cm-s-xq-dark span.cm-property {}
37
- .cm-s-xq-dark span.cm-operator {}
38
- .cm-s-xq-dark span.cm-comment {color: gray;}
39
- .cm-s-xq-dark span.cm-string {color: #9FEE00;}
40
- .cm-s-xq-dark span.cm-meta {color: yellow;}
41
- .cm-s-xq-dark span.cm-error {color: #f00;}
42
- .cm-s-xq-dark span.cm-qualifier {color: #FFF700;}
43
- .cm-s-xq-dark span.cm-builtin {color: #30a;}
44
- .cm-s-xq-dark span.cm-bracket {color: #cc7;}
45
- .cm-s-xq-dark span.cm-tag {color: #FFBD40;}
46
- .cm-s-xq-dark span.cm-attribute {color: #FFF700;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/{CodeMirror2 → codemirror}/LICENSE RENAMED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2012 by Marijn Haverbeke <marijnh@gmail.com>
2
 
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
  of this software and associated documentation files (the "Software"), to deal
@@ -17,7 +17,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
  THE SOFTWARE.
20
-
21
- Please note that some subdirectories of the CodeMirror distribution
22
- include their own LICENSE files, and are released under different
23
- licences.
1
+ Copyright (C) 2011 by Marijn Haverbeke <marijnh@gmail.com>
2
 
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
  of this software and associated documentation files (the "Software"), to deal
17
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
  THE SOFTWARE.
 
 
 
 
libraries/codemirror/lib/codemirror.css ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .CodeMirror {
2
+ line-height: 1em;
3
+ font-family: monospace;
4
+ }
5
+
6
+ .CodeMirror-scroll {
7
+ overflow: auto;
8
+ height: 300px;
9
+ }
10
+
11
+ .CodeMirror-gutter {
12
+ position: absolute; left: 0; top: 0;
13
+ background-color: #f7f7f7;
14
+ border-right: 1px solid #eee;
15
+ min-width: 2em;
16
+ height: 100%;
17
+ }
18
+ .CodeMirror-gutter-text {
19
+ color: #aaa;
20
+ text-align: right;
21
+ padding: .4em .2em .4em .4em;
22
+ }
23
+ .CodeMirror-lines {
24
+ padding: .4em;
25
+ }
26
+
27
+ .CodeMirror pre {
28
+ -moz-border-radius: 0;
29
+ -webkit-border-radius: 0;
30
+ -o-border-radius: 0;
31
+ border-radius: 0;
32
+ border-width: 0; margin: 0; padding: 0; background: transparent;
33
+ font-family: inherit;
34
+ font-size: inherit;
35
+ padding: 0; margin: 0;
36
+ white-space: pre;
37
+ word-wrap: normal;
38
+ }
39
+
40
+ .CodeMirror textarea {
41
+ font-family: inherit !important;
42
+ font-size: inherit !important;
43
+ }
44
+
45
+ .CodeMirror-cursor {
46
+ z-index: 10;
47
+ position: absolute;
48
+ visibility: hidden;
49
+ border-left: 1px solid black !important;
50
+ }
51
+ .CodeMirror-focused .CodeMirror-cursor {
52
+ visibility: visible;
53
+ }
54
+
55
+ span.CodeMirror-selected {
56
+ background: #ccc !important;
57
+ color: HighlightText !important;
58
+ }
59
+ .CodeMirror-focused span.CodeMirror-selected {
60
+ background: Highlight !important;
61
+ }
62
+
63
+ .CodeMirror-matchingbracket {color: #0f0 !important;}
64
+ .CodeMirror-nonmatchingbracket {color: #f22 !important;}
libraries/codemirror/lib/codemirror.js ADDED
@@ -0,0 +1,2071 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // All functions that need access to the editor's state live inside
2
+ // the CodeMirror function. Below that, at the bottom of the file,
3
+ // some utilities are defined.
4
+
5
+ // CodeMirror is the only global var we claim
6
+ var CodeMirror = (function() {
7
+ // This is the function that produces an editor instance. It's
8
+ // closure is used to store the editor state.
9
+ function CodeMirror(place, givenOptions) {
10
+ // Determine effective options based on given values and defaults.
11
+ var options = {}, defaults = CodeMirror.defaults;
12
+ for (var opt in defaults)
13
+ if (defaults.hasOwnProperty(opt))
14
+ options[opt] = (givenOptions && givenOptions.hasOwnProperty(opt) ? givenOptions : defaults)[opt];
15
+
16
+ var targetDocument = options["document"];
17
+ // The element in which the editor lives.
18
+ var wrapper = targetDocument.createElement("div");
19
+ wrapper.className = "CodeMirror";
20
+ // This mess creates the base DOM structure for the editor.
21
+ wrapper.innerHTML =
22
+ '<div style="overflow: hidden; position: relative; width: 1px; height: 0px;">' + // Wraps and hides input textarea
23
+ '<textarea style="position: absolute; width: 2px;" wrap="off"></textarea></div>' +
24
+ '<div class="CodeMirror-scroll cm-s-' + options.theme + '">' +
25
+ '<div style="position: relative">' + // Set to the height of the text, causes scrolling
26
+ '<div style="position: absolute; height: 0; width: 0; overflow: hidden;"></div>' +
27
+ '<div style="position: relative">' + // Moved around its parent to cover visible view
28
+ '<div class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div>' +
29
+ // Provides positioning relative to (visible) text origin
30
+ '<div class="CodeMirror-lines"><div style="position: relative">' +
31
+ '<pre class="CodeMirror-cursor">&#160;</pre>' + // Absolutely positioned blinky cursor
32
+ '<div></div>' + // This DIV contains the actual code
33
+ '</div></div></div></div></div>';
34
+ if (place.appendChild) place.appendChild(wrapper); else place(wrapper);
35
+ // I've never seen more elegant code in my life.
36
+ var inputDiv = wrapper.firstChild, input = inputDiv.firstChild,
37
+ scroller = wrapper.lastChild, code = scroller.firstChild,
38
+ measure = code.firstChild, mover = measure.nextSibling,
39
+ gutter = mover.firstChild, gutterText = gutter.firstChild,
40
+ lineSpace = gutter.nextSibling.firstChild,
41
+ cursor = lineSpace.firstChild, lineDiv = cursor.nextSibling;
42
+ if (options.tabindex != null) input.tabindex = options.tabindex;
43
+ if (!options.gutter && !options.lineNumbers) gutter.style.display = "none";
44
+
45
+ // Delayed object wrap timeouts, making sure only one is active. blinker holds an interval.
46
+ var poll = new Delayed(), highlight = new Delayed(), blinker;
47
+
48
+ // mode holds a mode API object. lines an array of Line objects
49
+ // (see Line constructor), work an array of lines that should be
50
+ // parsed, and history the undo history (instance of History
51
+ // constructor).
52
+ var mode, lines = [new Line("")], work, history = new History(), focused;
53
+ loadMode();
54
+ // The selection. These are always maintained to point at valid
55
+ // positions. Inverted is used to remember that the user is
56
+ // selecting bottom-to-top.
57
+ var sel = {from: {line: 0, ch: 0}, to: {line: 0, ch: 0}, inverted: false};
58
+ // Selection-related flags. shiftSelecting obviously tracks
59
+ // whether the user is holding shift. reducedSelection is a hack
60
+ // to get around the fact that we can't create inverted
61
+ // selections. See below.
62
+ var shiftSelecting, reducedSelection, lastDoubleClick;
63
+ // Variables used by startOperation/endOperation to track what
64
+ // happened during the operation.
65
+ var updateInput, changes, textChanged, selectionChanged, leaveInputAlone;
66
+ // Current visible range (may be bigger than the view window).
67
+ var showingFrom = 0, showingTo = 0, lastHeight = 0, curKeyId = null;
68
+ // editing will hold an object describing the things we put in the
69
+ // textarea, to help figure out whether something changed.
70
+ // bracketHighlighted is used to remember that a backet has been
71
+ // marked.
72
+ var editing, bracketHighlighted;
73
+ // Tracks the maximum line length so that the horizontal scrollbar
74
+ // can be kept static when scrolling.
75
+ var maxLine = "";
76
+
77
+ // Initialize the content. Somewhat hacky (delayed prepareInput)
78
+ // to work around browser issues.
79
+ operation(function(){setValue(options.value || ""); updateInput = false;})();
80
+ setTimeout(prepareInput, 20);
81
+
82
+ // Register our event handlers.
83
+ connect(scroller, "mousedown", operation(onMouseDown));
84
+ // Gecko browsers fire contextmenu *after* opening the menu, at
85
+ // which point we can't mess with it anymore. Context menu is
86
+ // handled in onMouseDown for Gecko.
87
+ if (!gecko) connect(scroller, "contextmenu", operation(onContextMenu));
88
+ connect(code, "dblclick", operation(onDblClick));
89
+ connect(scroller, "scroll", function() {updateDisplay([]); if (options.onScroll) options.onScroll(instance);});
90
+ connect(window, "resize", function() {updateDisplay(true);});
91
+ connect(input, "keyup", operation(onKeyUp));
92
+ connect(input, "keydown", operation(onKeyDown));
93
+ connect(input, "keypress", operation(onKeyPress));
94
+ connect(input, "focus", onFocus);
95
+ connect(input, "blur", onBlur);
96
+
97
+ connect(scroller, "dragenter", function(e){e.stop();});
98
+ connect(scroller, "dragover", function(e){e.stop();});
99
+ connect(scroller, "drop", operation(onDrop));
100
+ connect(scroller, "paste", function(){focusInput(); fastPoll();});
101
+ connect(input, "paste", function(){fastPoll();});
102
+ connect(input, "cut", function(){fastPoll();});
103
+
104
+ // IE throws unspecified error in certain cases, when
105
+ // trying to access activeElement before onload
106
+ var hasFocus; try { hasFocus = (targetDocument.activeElement == input); } catch(e) { }
107
+ if (hasFocus) onFocus();
108
+ else onBlur();
109
+
110
+ function isLine(l) {return l >= 0 && l < lines.length;}
111
+ // The instance object that we'll return. Mostly calls out to
112
+ // local functions in the CodeMirror function. Some do some extra
113
+ // range checking and/or clipping. operation is used to wrap the
114
+ // call so that changes it makes are tracked, and the display is
115
+ // updated afterwards.
116
+ var instance = {
117
+ getValue: getValue,
118
+ setValue: operation(setValue),
119
+ getSelection: getSelection,
120
+ replaceSelection: operation(replaceSelection),
121
+ focus: function(){focusInput(); onFocus(); prepareInput(); fastPoll();},
122
+ setOption: function(option, value) {
123
+ options[option] = value;
124
+ if (option == "lineNumbers" || option == "gutter") gutterChanged();
125
+ else if (option == "mode" || option == "indentUnit") loadMode();
126
+ else if (option == "readOnly" && value == "nocursor") input.blur();
127
+ else if (option == "theme") scroller.className = scroller.className.replace(/cm-s-\w+/, "cm-s-" + value);
128
+ },
129
+ getOption: function(option) {return options[option];},
130
+ undo: operation(undo),
131
+ redo: operation(redo),
132
+ indentLine: operation(function(n) {if (isLine(n)) indentLine(n, "smart");}),
133
+ historySize: function() {return {undo: history.done.length, redo: history.undone.length};},
134
+ matchBrackets: operation(function(){matchBrackets(true);}),
135
+ getTokenAt: function(pos) {
136
+ pos = clipPos(pos);
137
+ return lines[pos.line].getTokenAt(mode, getStateBefore(pos.line), pos.ch);
138
+ },
139
+ cursorCoords: function(start){
140
+ if (start == null) start = sel.inverted;
141
+ return pageCoords(start ? sel.from : sel.to);
142
+ },
143
+ charCoords: function(pos){return pageCoords(clipPos(pos));},
144
+ coordsChar: function(coords) {
145
+ var off = eltOffset(lineSpace);
146
+ var line = clipLine(Math.min(lines.length - 1, showingFrom + Math.floor((coords.y - off.top) / lineHeight())));
147
+ return clipPos({line: line, ch: charFromX(clipLine(line), coords.x - off.left)});
148
+ },
149
+ getSearchCursor: function(query, pos, caseFold) {return new SearchCursor(query, pos, caseFold);},
150
+ markText: operation(function(a, b, c){return operation(markText(a, b, c));}),
151
+ setMarker: addGutterMarker,
152
+ clearMarker: removeGutterMarker,
153
+ setLineClass: operation(setLineClass),
154
+ lineInfo: lineInfo,
155
+ addWidget: function(pos, node, scroll) {
156
+ var pos = localCoords(clipPos(pos), true);
157
+ node.style.top = (showingFrom * lineHeight() + pos.yBot + paddingTop()) + "px";
158
+ node.style.left = (pos.x + paddingLeft()) + "px";
159
+ code.appendChild(node);
160
+ if (scroll)
161
+ scrollIntoView(pos.x, pos.yBot, pos.x + node.offsetWidth, pos.yBot + node.offsetHeight);
162
+ },
163
+
164
+ lineCount: function() {return lines.length;},
165
+ getCursor: function(start) {
166
+ if (start == null) start = sel.inverted;
167
+ return copyPos(start ? sel.from : sel.to);
168
+ },
169
+ somethingSelected: function() {return !posEq(sel.from, sel.to);},
170
+ setCursor: operation(function(line, ch) {
171
+ if (ch == null && typeof line.line == "number") setCursor(line.line, line.ch);
172
+ else setCursor(line, ch);
173
+ }),
174
+ setSelection: operation(function(from, to) {setSelection(clipPos(from), clipPos(to || from));}),
175
+ getLine: function(line) {if (isLine(line)) return lines[line].text;},
176
+ setLine: operation(function(line, text) {
177
+ if (isLine(line)) replaceRange(text, {line: line, ch: 0}, {line: line, ch: lines[line].text.length});
178
+ }),
179
+ removeLine: operation(function(line) {
180
+ if (isLine(line)) replaceRange("", {line: line, ch: 0}, clipPos({line: line+1, ch: 0}));
181
+ }),
182
+ replaceRange: operation(replaceRange),
183
+ getRange: function(from, to) {return getRange(clipPos(from), clipPos(to));},
184
+
185
+ operation: function(f){return operation(f)();},
186
+ refresh: function(){updateDisplay(true);},
187
+ getInputField: function(){return input;},
188
+ getWrapperElement: function(){return wrapper;}
189
+ };
190
+
191
+ function setValue(code) {
192
+ history = null;
193
+ var top = {line: 0, ch: 0};
194
+ updateLines(top, {line: lines.length - 1, ch: lines[lines.length-1].text.length},
195
+ splitLines(code), top, top);
196
+ history = new History();
197
+ }
198
+ function getValue(code) {
199
+ var text = [];
200
+ for (var i = 0, l = lines.length; i < l; ++i)
201
+ text.push(lines[i].text);
202
+ return text.join("\n");
203
+ }
204
+
205
+ function onMouseDown(e) {
206
+ var ld = lastDoubleClick; lastDoubleClick = null;
207
+ // First, see if this is a click in the gutter
208
+ for (var n = e.target(); n != wrapper; n = n.parentNode)
209
+ if (n.parentNode == gutterText) {
210
+ if (options.onGutterClick)
211
+ options.onGutterClick(instance, indexOf(gutterText.childNodes, n) + showingFrom);
212
+ return e.stop();
213
+ }
214
+
215
+ if (gecko && e.button() == 3) onContextMenu(e);
216
+ if (e.button() != 1) return;
217
+ // For button 1, if it was clicked inside the editor
218
+ // (posFromMouse returning non-null), we have to adjust the
219
+ // selection.
220
+ var start = posFromMouse(e), last = start, going;
221
+ if (!start) {if (e.target() == scroller) e.stop(); return;}
222
+
223
+ if (!focused) onFocus();
224
+ e.stop();
225
+ if (ld && +new Date - ld < 400) return selectLine(start.line);
226
+
227
+ setCursor(start.line, start.ch, true);
228
+ // And then we have to see if it's a drag event, in which case
229
+ // the dragged-over text must be selected.
230
+ function end() {
231
+ focusInput();
232
+ updateInput = true;
233
+ move(); up();
234
+ }
235
+ function extend(e) {
236
+ var cur = posFromMouse(e, true);
237
+ if (cur && !posEq(cur, last)) {
238
+ if (!focused) onFocus();
239
+ last = cur;
240
+ setSelectionUser(start, cur);
241
+ updateInput = false;
242
+ var visible = visibleLines();
243
+ if (cur.line >= visible.to || cur.line < visible.from)
244
+ going = setTimeout(operation(function(){extend(e);}), 150);
245
+ }
246
+ }
247
+
248
+ var move = connect(targetDocument, "mousemove", operation(function(e) {
249
+ clearTimeout(going);
250
+ e.stop();
251
+ extend(e);
252
+ }), true);
253
+ var up = connect(targetDocument, "mouseup", operation(function(e) {
254
+ clearTimeout(going);
255
+ var cur = posFromMouse(e);
256
+ if (cur) setSelectionUser(start, cur);
257
+ e.stop();
258
+ end();
259
+ }), true);
260
+ }
261
+ function onDblClick(e) {
262
+ var pos = posFromMouse(e);
263
+ if (!pos) return;
264
+ selectWordAt(pos);
265
+ e.stop();
266
+ lastDoubleClick = +new Date;
267
+ }
268
+ function onDrop(e) {
269
+ var pos = posFromMouse(e, true), files = e.e.dataTransfer.files;
270
+ if (!pos || options.readOnly) return;
271
+ if (files && files.length && window.FileReader && window.File) {
272
+ var n = files.length, text = Array(n), read = 0;
273
+ for (var i = 0; i < n; ++i) loadFile(files[i], i);
274
+ function loadFile(file, i) {
275
+ var reader = new FileReader;
276
+ reader.onload = function() {
277
+ text[i] = reader.result;
278
+ if (++read == n) replaceRange(text.join(""), clipPos(pos), clipPos(pos));
279
+ };
280
+ reader.readAsText(file);
281
+ }
282
+ }
283
+ else {
284
+ try {
285
+ var text = e.e.dataTransfer.getData("Text");
286
+ if (text) replaceRange(text, pos, pos);
287
+ }
288
+ catch(e){}
289
+ }
290
+ }
291
+ function onKeyDown(e) {
292
+ if (!focused) onFocus();
293
+
294
+ var code = e.e.keyCode;
295
+ // IE does strange things with escape.
296
+ if (ie && code == 27) { e.e.returnValue = false; }
297
+ // Tries to detect ctrl on non-mac, cmd on mac.
298
+ var mod = (mac ? e.e.metaKey : e.e.ctrlKey) && !e.e.altKey, anyMod = e.e.ctrlKey || e.e.altKey || e.e.metaKey;
299
+ if (code == 16 || e.e.shiftKey) shiftSelecting = shiftSelecting || (sel.inverted ? sel.to : sel.from);
300
+ else shiftSelecting = null;
301
+ // First give onKeyEvent option a chance to handle this.
302
+ if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e.e))) return;
303
+
304
+ if (code == 33 || code == 34) {scrollPage(code == 34); return e.stop();} // page up/down
305
+ if (mod && ((code == 36 || code == 35) || // ctrl-home/end
306
+ mac && (code == 38 || code == 40))) { // cmd-up/down
307
+ scrollEnd(code == 36 || code == 38); return e.stop();
308
+ }
309
+ if (mod && code == 65) {selectAll(); return e.stop();} // ctrl-a
310
+ if (!options.readOnly) {
311
+ if (!anyMod && code == 13) {return;} // enter
312
+ if (!anyMod && code == 9 && handleTab(e.e.shiftKey)) return e.stop(); // tab
313
+ if (mod && code == 90) {undo(); return e.stop();} // ctrl-z
314
+ if (mod && ((e.e.shiftKey && code == 90) || code == 89)) {redo(); return e.stop();} // ctrl-shift-z, ctrl-y
315
+ }
316
+
317
+ // Key id to use in the movementKeys map. We also pass it to
318
+ // fastPoll in order to 'self learn'. We need this because
319
+ // reducedSelection, the hack where we collapse the selection to
320
+ // its start when it is inverted and a movement key is pressed
321
+ // (and later restore it again), shouldn't be used for
322
+ // non-movement keys.
323
+ curKeyId = (mod ? "c" : "") + code;
324
+ if (sel.inverted && movementKeys.hasOwnProperty(curKeyId)) {
325
+ var range = selRange(input);
326
+ if (range) {
327
+ reducedSelection = {anchor: range.start};
328
+ setSelRange(input, range.start, range.start);
329
+ }
330
+ }
331
+ fastPoll(curKeyId);
332
+ }
333
+ function onKeyUp(e) {
334
+ if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e.e))) return;
335
+ if (reducedSelection) {
336
+ reducedSelection = null;
337
+ updateInput = true;
338
+ }
339
+ if (e.e.keyCode == 16) shiftSelecting = null;
340
+ }
341
+ function onKeyPress(e) {
342
+ if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e.e))) return;
343
+ if (options.electricChars && mode.electricChars) {
344
+ var ch = String.fromCharCode(e.e.charCode == null ? e.e.keyCode : e.e.charCode);
345
+ if (mode.electricChars.indexOf(ch) > -1)
346
+ setTimeout(operation(function() {indentLine(sel.to.line, "smart");}), 50);
347
+ }
348
+ var code = e.e.keyCode;
349
+ // Re-stop tab and enter. Necessary on some browsers.
350
+ if (code == 13) {if (!options.readOnly) handleEnter(); e.stop();}
351
+ else if (!e.e.ctrlKey && !e.e.altKey && !e.e.metaKey && code == 9 && options.tabMode != "default") e.stop();
352
+ else fastPoll(curKeyId);
353
+ }
354
+
355
+ function onFocus() {
356
+ if (options.readOnly == "nocursor") return;
357
+ if (!focused && options.onFocus) options.onFocus(instance);
358
+ focused = true;
359
+ slowPoll();
360
+ if (wrapper.className.search(/\bCodeMirror-focused\b/) == -1)
361
+ wrapper.className += " CodeMirror-focused";
362
+ restartBlink();
363
+ }
364
+ function onBlur() {
365
+ if (focused && options.onBlur) options.onBlur(instance);
366
+ clearInterval(blinker);
367
+ shiftSelecting = null;
368
+ focused = false;
369
+ wrapper.className = wrapper.className.replace(" CodeMirror-focused", "");
370
+ }
371
+
372
+ // Replace the range from from to to by the strings in newText.
373
+ // Afterwards, set the selection to selFrom, selTo.
374
+ function updateLines(from, to, newText, selFrom, selTo) {
375
+ if (history) {
376
+ var old = [];
377
+ for (var i = from.line, e = to.line + 1; i < e; ++i) old.push(lines[i].text);
378
+ history.addChange(from.line, newText.length, old);
379
+ while (history.done.length > options.undoDepth) history.done.shift();
380
+ }
381
+ updateLinesNoUndo(from, to, newText, selFrom, selTo);
382
+ if (newText.length < 5)
383
+ highlightLines(from.line, from.line + newText.length)
384
+ }
385
+ function unredoHelper(from, to) {
386
+ var change = from.pop();
387
+ if (change) {
388
+ var replaced = [], end = change.start + change.added;
389
+ for (var i = change.start; i < end; ++i) replaced.push(lines[i].text);
390
+ to.push({start: change.start, added: change.old.length, old: replaced});
391
+ var pos = clipPos({line: change.start + change.old.length - 1,
392
+ ch: editEnd(replaced[replaced.length-1], change.old[change.old.length-1])});
393
+ updateLinesNoUndo({line: change.start, ch: 0}, {line: end - 1, ch: lines[end-1].text.length}, change.old, pos, pos);
394
+ }
395
+ }
396
+ function undo() {unredoHelper(history.done, history.undone);}
397
+ function redo() {unredoHelper(history.undone, history.done);}
398
+
399
+ function updateLinesNoUndo(from, to, newText, selFrom, selTo) {
400
+ var recomputeMaxLength = false, maxLineLength = maxLine.length;
401
+ for (var i = from.line; i <= to.line; ++i) {
402
+ if (lines[i].text.length == maxLineLength) {recomputeMaxLength = true; break;}
403
+ }
404
+
405
+ var nlines = to.line - from.line, firstLine = lines[from.line], lastLine = lines[to.line];
406
+ // First adjust the line structure, taking some care to leave highlighting intact.
407
+ if (firstLine == lastLine) {
408
+ if (newText.length == 1)
409
+ firstLine.replace(from.ch, to.ch, newText[0]);
410
+ else {
411
+ lastLine = firstLine.split(to.ch, newText[newText.length-1]);
412
+ var spliceargs = [from.line + 1, nlines];
413
+ firstLine.replace(from.ch, firstLine.text.length, newText[0]);
414
+ for (var i = 1, e = newText.length - 1; i < e; ++i) spliceargs.push(new Line(newText[i]));
415
+ spliceargs.push(lastLine);
416
+ lines.splice.apply(lines, spliceargs);
417
+ }
418
+ }
419
+ else if (newText.length == 1) {
420
+ firstLine.replace(from.ch, firstLine.text.length, newText[0] + lastLine.text.slice(to.ch));
421
+ lines.splice(from.line + 1, nlines);
422
+ }
423
+ else {
424
+ var spliceargs = [from.line + 1, nlines - 1];
425
+ firstLine.replace(from.ch, firstLine.text.length, newText[0]);
426
+ lastLine.replace(0, to.ch, newText[newText.length-1]);
427
+ for (var i = 1, e = newText.length - 1; i < e; ++i) spliceargs.push(new Line(newText[i]));
428
+ lines.splice.apply(lines, spliceargs);
429
+ }
430
+
431
+
432
+ for (var i = from.line, e = i + newText.length; i < e; ++i) {
433
+ var l = lines[i].text;
434
+ if (l.length > maxLineLength) {
435
+ maxLine = l; maxLineLength = l.length;
436
+ recomputeMaxLength = false;
437
+ }
438
+ }
439
+ if (recomputeMaxLength) {
440
+ maxLineLength = 0; maxLine = "";
441
+ for (var i = 0, e = lines.length; i < e; ++i) {
442
+ var l = lines[i].text;
443
+ if (l.length > maxLineLength) {
444
+ maxLineLength = l.length; maxLine = l;
445
+ }
446
+ }
447
+ }
448
+
449
+ // Add these lines to the work array, so that they will be
450
+ // highlighted. Adjust work lines if lines were added/removed.
451
+ var newWork = [], lendiff = newText.length - nlines - 1;
452
+ for (var i = 0, l = work.length; i < l; ++i) {
453
+ var task = work[i];
454
+ if (task < from.line) newWork.push(task);
455
+ else if (task > to.line) newWork.push(task + lendiff);
456
+ }
457
+ if (newText.length) newWork.push(from.line);
458
+ work = newWork;
459
+ startWorker(100);
460
+ // Remember that these lines changed, for updating the display
461
+ changes.push({from: from.line, to: to.line + 1, diff: lendiff});
462
+ textChanged = {from: from, to: to, text: newText};
463
+
464
+ // Update the selection
465
+ function updateLine(n) {return n <= Math.min(to.line, to.line + lendiff) ? n : n + lendiff;}
466
+ setSelection(selFrom, selTo, updateLine(sel.from.line), updateLine(sel.to.line));
467
+
468
+ // Make sure the scroll-size div has the correct height.
469
+ code.style.height = (lines.length * lineHeight() + 2 * paddingTop()) + "px";
470
+ }
471
+
472
+ function replaceRange(code, from, to) {
473
+ from = clipPos(from);
474
+ if (!to) to = from; else to = clipPos(to);
475
+ code = splitLines(code);
476
+ function adjustPos(pos) {
477
+ if (posLess(pos, from)) return pos;
478
+ if (!posLess(to, pos)) return end;
479
+ var line = pos.line + code.length - (to.line - from.line) - 1;
480
+ var ch = pos.ch;
481
+ if (pos.line == to.line)
482
+ ch += code[code.length-1].length - (to.ch - (to.line == from.line ? from.ch : 0));
483
+ return {line: line, ch: ch};
484
+ }
485
+ var end;
486
+ replaceRange1(code, from, to, function(end1) {
487
+ end = end1;
488
+ return {from: adjustPos(sel.from), to: adjustPos(sel.to)};
489
+ });
490
+ return end;
491
+ }
492
+ function replaceSelection(code, collapse) {
493
+ replaceRange1(splitLines(code), sel.from, sel.to, function(end) {
494
+ if (collapse == "end") return {from: end, to: end};
495
+ else if (collapse == "start") return {from: sel.from, to: sel.from};
496
+ else return {from: sel.from, to: end};
497
+ });
498
+ }
499
+ function replaceRange1(code, from, to, computeSel) {
500
+ var endch = code.length == 1 ? code[0].length + from.ch : code[code.length-1].length;
501
+ var newSel = computeSel({line: from.line + code.length - 1, ch: endch});
502
+ updateLines(from, to, code, newSel.from, newSel.to);
503
+ }
504
+
505
+ function getRange(from, to) {
506
+ var l1 = from.line, l2 = to.line;
507
+ if (l1 == l2) return lines[l1].text.slice(from.ch, to.ch);
508
+ var code = [lines[l1].text.slice(from.ch)];
509
+ for (var i = l1 + 1; i < l2; ++i) code.push(lines[i].text);
510
+ code.push(lines[l2].text.slice(0, to.ch));
511
+ return code.join("\n");
512
+ }
513
+ function getSelection() {
514
+ return getRange(sel.from, sel.to);
515
+ }
516
+
517
+ var pollingFast = false; // Ensures slowPoll doesn't cancel fastPoll
518
+ function slowPoll() {
519
+ if (pollingFast) return;
520
+ poll.set(2000, function() {
521
+ startOperation();
522
+ readInput();
523
+ if (focused) slowPoll();
524
+ endOperation();
525
+ });
526
+ }
527
+ function fastPoll(keyId) {
528
+ var missed = false;
529
+ pollingFast = true;
530
+ function p() {
531
+ startOperation();
532
+ var changed = readInput();
533
+ if (changed == "moved" && keyId) movementKeys[keyId] = true;
534
+ if (!changed && !missed) {missed = true; poll.set(80, p);}
535
+ else {pollingFast = false; slowPoll();}
536
+ endOperation();
537
+ }
538
+ poll.set(20, p);
539
+ }
540
+
541
+ // Inspects the textarea, compares its state (content, selection)
542
+ // to the data in the editing variable, and updates the editor
543
+ // content or cursor if something changed.
544
+ function readInput() {
545
+ if (leaveInputAlone) return;
546
+ var changed = false, text = input.value, sr = selRange(input);
547
+ if (!sr) return false;
548
+ var changed = editing.text != text, rs = reducedSelection;
549
+ var moved = changed || sr.start != editing.start || sr.end != (rs ? editing.start : editing.end);
550
+ if (!moved && !rs) return false;
551
+ if (changed) {
552
+ shiftSelecting = reducedSelection = null;
553
+ if (options.readOnly) {updateInput = true; return "changed";}
554
+ }
555
+
556
+ // Compute selection start and end based on start/end offsets in textarea
557
+ function computeOffset(n, startLine) {
558
+ var pos = 0;
559
+ for (;;) {
560
+ var found = text.indexOf("\n", pos);
561
+ if (found == -1 || (text.charAt(found-1) == "\r" ? found - 1 : found) >= n)
562
+ return {line: startLine, ch: n - pos};
563
+ ++startLine;
564
+ pos = found + 1;
565
+ }
566
+ }
567
+ var from = computeOffset(sr.start, editing.from),
568
+ to = computeOffset(sr.end, editing.from);
569
+ // Here we have to take the reducedSelection hack into account,
570
+ // so that you can, for example, press shift-up at the start of
571
+ // your selection and have the right thing happen.
572
+ if (rs) {
573
+ var head = sr.start == rs.anchor ? to : from;
574
+ var tail = shiftSelecting ? sel.to : sr.start == rs.anchor ? from : to;
575
+ if (sel.inverted = posLess(head, tail)) { from = head; to = tail; }
576
+ else { reducedSelection = null; from = tail; to = head; }
577
+ }
578
+
579
+ // In some cases (cursor on same line as before), we don't have
580
+ // to update the textarea content at all.
581
+ if (from.line == to.line && from.line == sel.from.line && from.line == sel.to.line && !shiftSelecting)
582
+ updateInput = false;
583
+
584
+ // Magic mess to extract precise edited range from the changed
585
+ // string.
586
+ if (changed) {
587
+ var start = 0, end = text.length, len = Math.min(end, editing.text.length);
588
+ var c, line = editing.from, nl = -1;
589
+ while (start < len && (c = text.charAt(start)) == editing.text.charAt(start)) {
590
+ ++start;
591
+ if (c == "\n") {line++; nl = start;}
592
+ }
593
+ var ch = nl > -1 ? start - nl : start, endline = editing.to - 1, edend = editing.text.length;
594
+ for (;;) {
595
+ c = editing.text.charAt(edend);
596
+ if (text.charAt(end) != c) {++end; ++edend; break;}
597
+ if (c == "\n") endline--;
598
+ if (edend <= start || end <= start) break;
599
+ --end; --edend;
600
+ }
601
+ var nl = editing.text.lastIndexOf("\n", edend - 1), endch = nl == -1 ? edend : edend - nl - 1;
602
+ updateLines({line: line, ch: ch}, {line: endline, ch: endch}, splitLines(text.slice(start, end)), from, to);
603
+ if (line != endline || from.line != line) updateInput = true;
604
+ }
605
+ else setSelection(from, to);
606
+
607
+ editing.text = text; editing.start = sr.start; editing.end = sr.end;
608
+ return changed ? "changed" : moved ? "moved" : false;
609
+ }
610
+
611
+ // Set the textarea content and selection range to match the
612
+ // editor state.
613
+ function prepareInput() {
614
+ var text = [];
615
+ var from = Math.max(0, sel.from.line - 1), to = Math.min(lines.length, sel.to.line + 2);
616
+ for (var i = from; i < to; ++i) text.push(lines[i].text);
617
+ text = input.value = text.join(lineSep);
618
+ var startch = sel.from.ch, endch = sel.to.ch;
619
+ for (var i = from; i < sel.from.line; ++i)
620
+ startch += lineSep.length + lines[i].text.length;
621
+ for (var i = from; i < sel.to.line; ++i)
622
+ endch += lineSep.length + lines[i].text.length;
623
+ editing = {text: text, from: from, to: to, start: startch, end: endch};
624
+ setSelRange(input, startch, reducedSelection ? startch : endch);
625
+ }
626
+ function focusInput() {
627
+ if (options.readOnly != "nocursor") input.focus();
628
+ }
629
+
630
+ function scrollCursorIntoView() {
631
+ var cursor = localCoords(sel.inverted ? sel.from : sel.to);
632
+ return scrollIntoView(cursor.x, cursor.y, cursor.x, cursor.yBot);
633
+ }
634
+ function scrollIntoView(x1, y1, x2, y2) {
635
+ var pl = paddingLeft(), pt = paddingTop(), lh = lineHeight();
636
+ y1 += pt; y2 += pt; x1 += pl; x2 += pl;
637
+ var screen = scroller.clientHeight, screentop = scroller.scrollTop, scrolled = false, result = true;
638
+ if (y1 < screentop) {scroller.scrollTop = Math.max(0, y1 - 2*lh); scrolled = true;}
639
+ else if (y2 > screentop + screen) {scroller.scrollTop = y2 + lh - screen; scrolled = true;}
640
+
641
+ var screenw = scroller.clientWidth, screenleft = scroller.scrollLeft;
642
+ if (x1 < screenleft) {
643
+ if (x1 < 50) x1 = 0;
644
+ scroller.scrollLeft = Math.max(0, x1 - 10);
645
+ scrolled = true;
646
+ }
647
+ else if (x2 > screenw + screenleft) {
648
+ scroller.scrollLeft = x2 + 10 - screenw;
649
+ scrolled = true;
650
+ if (x2 > code.clientWidth) result = false;
651
+ }
652
+ if (scrolled && options.onScroll) options.onScroll(instance);
653
+ return result;
654
+ }
655
+
656
+ function visibleLines() {
657
+ var lh = lineHeight(), top = scroller.scrollTop - paddingTop();
658
+ return {from: Math.min(lines.length, Math.max(0, Math.floor(top / lh))),
659
+ to: Math.min(lines.length, Math.ceil((top + scroller.clientHeight) / lh))};
660
+ }
661
+ // Uses a set of changes plus the current scroll position to
662
+ // determine which DOM updates have to be made, and makes the
663
+ // updates.
664
+ function updateDisplay(changes) {
665
+ if (!scroller.clientWidth) {
666
+ showingFrom = showingTo = 0;
667
+ return;
668
+ }
669
+ // First create a range of theoretically intact lines, and punch
670
+ // holes in that using the change info.
671
+ var intact = changes === true ? [] : [{from: showingFrom, to: showingTo, domStart: 0}];
672
+ for (var i = 0, l = changes.length || 0; i < l; ++i) {
673
+ var change = changes[i], intact2 = [], diff = change.diff || 0;
674
+ for (var j = 0, l2 = intact.length; j < l2; ++j) {
675
+ var range = intact[j];
676
+ if (change.to <= range.from)
677
+ intact2.push({from: range.from + diff, to: range.to + diff, domStart: range.domStart});
678
+ else if (range.to <= change.from)
679
+ intact2.push(range);
680
+ else {
681
+ if (change.from > range.from)
682
+ intact2.push({from: range.from, to: change.from, domStart: range.domStart})
683
+ if (change.to < range.to)
684
+ intact2.push({from: change.to + diff, to: range.to + diff,
685
+ domStart: range.domStart + (change.to - range.from)});
686
+ }
687
+ }
688
+ intact = intact2;
689
+ }
690
+
691
+ // Then, determine which lines we'd want to see, and which
692
+ // updates have to be made to get there.
693
+ var visible = visibleLines();
694
+ var from = Math.min(showingFrom, Math.max(visible.from - 3, 0)),
695
+ to = Math.min(lines.length, Math.max(showingTo, visible.to + 3)),
696
+ updates = [], domPos = 0, domEnd = showingTo - showingFrom, pos = from, changedLines = 0;
697
+
698
+ for (var i = 0, l = intact.length; i < l; ++i) {
699
+ var range = intact[i];
700
+ if (range.to <= from) continue;
701
+ if (range.from >= to) break;
702
+ if (range.domStart > domPos || range.from > pos) {
703
+ updates.push({from: pos, to: range.from, domSize: range.domStart - domPos, domStart: domPos});
704
+ changedLines += range.from - pos;
705
+ }
706
+ pos = range.to;
707
+ domPos = range.domStart + (range.to - range.from);
708
+ }
709
+ if (domPos != domEnd || pos != to) {
710
+ changedLines += Math.abs(to - pos);
711
+ updates.push({from: pos, to: to, domSize: domEnd - domPos, domStart: domPos});
712
+ }
713
+
714
+ if (!updates.length) return;
715
+ lineDiv.style.display = "none";
716
+ // If more than 30% of the screen needs update, just do a full
717
+ // redraw (which is quicker than patching)
718
+ if (changedLines > (visible.to - visible.from) * .3)
719
+ refreshDisplay(from = Math.max(visible.from - 10, 0), to = Math.min(visible.to + 7, lines.length));
720
+ // Otherwise, only update the stuff that needs updating.
721
+ else
722
+ patchDisplay(updates);
723
+ lineDiv.style.display = "";
724
+
725
+ // Position the mover div to align with the lines it's supposed
726
+ // to be showing (which will cover the visible display)
727
+ var different = from != showingFrom || to != showingTo || lastHeight != scroller.clientHeight;
728
+ showingFrom = from; showingTo = to;
729
+ mover.style.top = (from * lineHeight()) + "px";
730
+ if (different) {
731
+ lastHeight = scroller.clientHeight;
732
+ code.style.height = (lines.length * lineHeight() + 2 * paddingTop()) + "px";
733
+ updateGutter();
734
+ }
735
+
736
+ var textWidth = stringWidth(maxLine);
737
+ lineSpace.style.width = textWidth > scroller.clientWidth ? textWidth + "px" : "";
738
+
739
+ // Since this is all rather error prone, it is honoured with the
740
+ // only assertion in the whole file.
741
+ if (lineDiv.childNodes.length != showingTo - showingFrom)
742
+ throw new Error("BAD PATCH! " + JSON.stringify(updates) + " size=" + (showingTo - showingFrom) +
743
+ " nodes=" + lineDiv.childNodes.length);
744
+ updateCursor();
745
+ }
746
+
747
+ function refreshDisplay(from, to) {
748
+ var html = [], start = {line: from, ch: 0}, inSel = posLess(sel.from, start) && !posLess(sel.to, start);
749
+ for (var i = from; i < to; ++i) {
750
+ var ch1 = null, ch2 = null;
751
+ if (inSel) {
752
+ ch1 = 0;
753
+ if (sel.to.line == i) {inSel = false; ch2 = sel.to.ch;}
754
+ }
755
+ else if (sel.from.line == i) {
756
+ if (sel.to.line == i) {ch1 = sel.from.ch; ch2 = sel.to.ch;}
757
+ else {inSel = true; ch1 = sel.from.ch;}
758
+ }
759
+ html.push(lines[i].getHTML(ch1, ch2, true));
760
+ }
761
+ lineDiv.innerHTML = html.join("");
762
+ }
763
+ function patchDisplay(updates) {
764
+ // Slightly different algorithm for IE (badInnerHTML), since
765
+ // there .innerHTML on PRE nodes is dumb, and discards
766
+ // whitespace.
767
+ var sfrom = sel.from.line, sto = sel.to.line, off = 0,
768
+ scratch = badInnerHTML && targetDocument.createElement("div");
769
+ for (var i = 0, e = updates.length; i < e; ++i) {
770
+ var rec = updates[i];
771
+ var extra = (rec.to - rec.from) - rec.domSize;
772
+ var nodeAfter = lineDiv.childNodes[rec.domStart + rec.domSize + off] || null;
773
+ if (badInnerHTML)
774
+ for (var j = Math.max(-extra, rec.domSize); j > 0; --j)
775
+ lineDiv.removeChild(nodeAfter ? nodeAfter.previousSibling : lineDiv.lastChild);
776
+ else if (extra) {
777
+ for (var j = Math.max(0, extra); j > 0; --j)
778
+ lineDiv.insertBefore(targetDocument.createElement("pre"), nodeAfter);
779
+ for (var j = Math.max(0, -extra); j > 0; --j)
780
+ lineDiv.removeChild(nodeAfter ? nodeAfter.previousSibling : lineDiv.lastChild);
781
+ }
782
+ var node = lineDiv.childNodes[rec.domStart + off], inSel = sfrom < rec.from && sto >= rec.from;
783
+ for (var j = rec.from; j < rec.to; ++j) {
784
+ var ch1 = null, ch2 = null;
785
+ if (inSel) {
786
+ ch1 = 0;
787
+ if (sto == j) {inSel = false; ch2 = sel.to.ch;}
788
+ }
789
+ else if (sfrom == j) {
790
+ if (sto == j) {ch1 = sel.from.ch; ch2 = sel.to.ch;}
791
+ else {inSel = true; ch1 = sel.from.ch;}
792
+ }
793
+ if (badInnerHTML) {
794
+ scratch.innerHTML = lines[j].getHTML(ch1, ch2, true);
795
+ lineDiv.insertBefore(scratch.firstChild, nodeAfter);
796
+ }
797
+ else {
798
+ node.innerHTML = lines[j].getHTML(ch1, ch2, false);
799
+ node.className = lines[j].className || "";
800
+ node = node.nextSibling;
801
+ }
802
+ }
803
+ off += extra;
804
+ }
805
+ }
806
+
807
+ function updateGutter() {
808
+ if (!options.gutter && !options.lineNumbers) return;
809
+ var hText = mover.offsetHeight, hEditor = scroller.clientHeight;
810
+ gutter.style.height = (hText - hEditor < 2 ? hEditor : hText) + "px";
811
+ var html = [];
812
+ for (var i = showingFrom; i < Math.max(showingTo, showingFrom + 1); ++i) {
813
+ var marker = lines[i].gutterMarker;
814
+ var text = options.lineNumbers ? i + options.firstLineNumber : null;
815
+ if (marker && marker.text)
816
+ text = marker.text.replace("%N%", text != null ? text : "");
817
+ else if (text == null)
818
+ text = "\u00a0";
819
+ html.push((marker && marker.style ? '<pre class="' + marker.style + '">' : "<pre>"), text, "</pre>");
820
+ }
821
+ gutter.style.display = "none";
822
+ gutterText.innerHTML = html.join("");
823
+ var minwidth = String(lines.length).length, firstNode = gutterText.firstChild, val = eltText(firstNode), pad = "";
824
+ while (val.length + pad.length < minwidth) pad += "\u00a0";
825
+ if (pad) firstNode.insertBefore(targetDocument.createTextNode(pad), firstNode.firstChild);
826
+ gutter.style.display = "";
827
+ lineSpace.style.marginLeft = gutter.offsetWidth + "px";
828
+ }
829
+ function updateCursor() {
830
+ var head = sel.inverted ? sel.from : sel.to, lh = lineHeight();
831
+ var x = charX(head.line, head.ch) + "px", y = (head.line - showingFrom) * lh + "px";
832
+ inputDiv.style.top = (head.line * lh - scroller.scrollTop) + "px";
833
+ if (posEq(sel.from, sel.to)) {
834
+ cursor.style.top = y; cursor.style.left = x;
835
+ cursor.style.display = "";
836
+ }
837
+ else cursor.style.display = "none";
838
+ }
839
+
840
+ function setSelectionUser(from, to) {
841
+ var sh = shiftSelecting && clipPos(shiftSelecting);
842
+ if (sh) {
843
+ if (posLess(sh, from)) from = sh;
844
+ else if (posLess(to, sh)) to = sh;
845
+ }
846
+ setSelection(from, to);
847
+ }
848
+ // Update the selection. Last two args are only used by
849
+ // updateLines, since they have to be expressed in the line
850
+ // numbers before the update.
851
+ function setSelection(from, to, oldFrom, oldTo) {
852
+ if (posEq(sel.from, from) && posEq(sel.to, to)) return;
853
+ if (posLess(to, from)) {var tmp = to; to = from; from = tmp;}
854
+
855
+ if (posEq(from, to)) sel.inverted = false;
856
+ else if (posEq(from, sel.to)) sel.inverted = false;
857
+ else if (posEq(to, sel.from)) sel.inverted = true;
858
+
859
+ // Some ugly logic used to only mark the lines that actually did
860
+ // see a change in selection as changed, rather than the whole
861
+ // selected range.
862
+ if (oldFrom == null) {oldFrom = sel.from.line; oldTo = sel.to.line;}
863
+ if (posEq(from, to)) {
864
+ if (!posEq(sel.from, sel.to))
865
+ changes.push({from: oldFrom, to: oldTo + 1});
866
+ }
867
+ else if (posEq(sel.from, sel.to)) {
868
+ changes.push({from: from.line, to: to.line + 1});
869
+ }
870
+ else {
871
+ if (!posEq(from, sel.from)) {
872
+ if (from.line < oldFrom)
873
+ changes.push({from: from.line, to: Math.min(to.line, oldFrom) + 1});
874
+ else
875
+ changes.push({from: oldFrom, to: Math.min(oldTo, from.line) + 1});
876
+ }
877
+ if (!posEq(to, sel.to)) {
878
+ if (to.line < oldTo)
879
+ changes.push({from: Math.max(oldFrom, from.line), to: oldTo + 1});
880
+ else
881
+ changes.push({from: Math.max(from.line, oldTo), to: to.line + 1});
882
+ }
883
+ }
884
+ sel.from = from; sel.to = to;
885
+ selectionChanged = true;
886
+ }
887
+ function setCursor(line, ch, user) {
888
+ var pos = clipPos({line: line, ch: ch || 0});
889
+ (user ? setSelectionUser : setSelection)(pos, pos);
890
+ }
891
+
892
+ function clipLine(n) {return Math.max(0, Math.min(n, lines.length-1));}
893
+ function clipPos(pos) {
894
+ if (pos.line < 0) return {line: 0, ch: 0};
895
+ if (pos.line >= lines.length) return {line: lines.length-1, ch: lines[lines.length-1].text.length};
896
+ var ch = pos.ch, linelen = lines[pos.line].text.length;
897
+ if (ch == null || ch > linelen) return {line: pos.line, ch: linelen};
898
+ else if (ch < 0) return {line: pos.line, ch: 0};
899
+ else return pos;
900
+ }
901
+
902
+ function scrollPage(down) {
903
+ var linesPerPage = Math.floor(scroller.clientHeight / lineHeight()), head = sel.inverted ? sel.from : sel.to;
904
+ setCursor(head.line + (Math.max(linesPerPage - 1, 1) * (down ? 1 : -1)), head.ch, true);
905
+ }
906
+ function scrollEnd(top) {
907
+ var pos = top ? {line: 0, ch: 0} : {line: lines.length - 1, ch: lines[lines.length-1].text.length};
908
+ setSelectionUser(pos, pos);
909
+ }
910
+ function selectAll() {
911
+ var endLine = lines.length - 1;
912
+ setSelection({line: 0, ch: 0}, {line: endLine, ch: lines[endLine].text.length});
913
+ }
914
+ function selectWordAt(pos) {
915
+ var line = lines[pos.line].text;
916
+ var start = pos.ch, end = pos.ch;
917
+ while (start > 0 && /\w/.test(line.charAt(start - 1))) --start;
918
+ while (end < line.length && /\w/.test(line.charAt(end))) ++end;
919
+ setSelectionUser({line: pos.line, ch: start}, {line: pos.line, ch: end});
920
+ }
921
+ function selectLine(line) {
922
+ setSelectionUser({line: line, ch: 0}, {line: line, ch: lines[line].text.length});
923
+ }
924
+ function handleEnter() {
925
+ replaceSelection("\n", "end");
926
+ if (options.enterMode != "flat")
927
+ indentLine(sel.from.line, options.enterMode == "keep" ? "prev" : "smart");
928
+ }
929
+ function handleTab(shift) {
930
+ shiftSelecting = null;
931
+ switch (options.tabMode) {
932
+ case "default":
933
+ return false;
934
+ case "indent":
935
+ for (var i = sel.from.line, e = sel.to.line; i <= e; ++i) indentLine(i, "smart");
936
+ break;
937
+ case "classic":
938
+ if (posEq(sel.from, sel.to)) {
939
+ if (shift) indentLine(sel.from.line, "smart");
940
+ else replaceSelection("\t", "end");
941
+ break;
942
+ }
943
+ case "shift":
944
+ for (var i = sel.from.line, e = sel.to.line; i <= e; ++i) indentLine(i, shift ? "subtract" : "add");
945
+ break;
946
+ }
947
+ return true;
948
+ }
949
+
950
+ function indentLine(n, how) {
951
+ if (how == "smart") {
952
+ if (!mode.indent) how = "prev";
953
+ else var state = getStateBefore(n);
954
+ }
955
+
956
+ var line = lines[n], curSpace = line.indentation(), curSpaceString = line.text.match(/^\s*/)[0], indentation;
957
+ if (how == "prev") {
958
+ if (n) indentation = lines[n-1].indentation();
959
+ else indentation = 0;
960
+ }
961
+ else if (how == "smart") indentation = mode.indent(state, line.text.slice(curSpaceString.length));
962
+ else if (how == "add") indentation = curSpace + options.indentUnit;
963
+ else if (how == "subtract") indentation = curSpace - options.indentUnit;
964
+ indentation = Math.max(0, indentation);
965
+ var diff = indentation - curSpace;
966
+
967
+ if (!diff) {
968
+ if (sel.from.line != n && sel.to.line != n) return;
969
+ var indentString = curSpaceString;
970
+ }
971
+ else {
972
+ var indentString = "", pos = 0;
973
+ if (options.indentWithTabs)
974
+ for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
975
+ while (pos < indentation) {++pos; indentString += " ";}
976
+ }
977
+
978
+ replaceRange(indentString, {line: n, ch: 0}, {line: n, ch: curSpaceString.length});
979
+ }
980
+
981
+ function loadMode() {
982
+ mode = CodeMirror.getMode(options, options.mode);
983
+ for (var i = 0, l = lines.length; i < l; ++i)
984
+ lines[i].stateAfter = null;
985
+ work = [0];
986
+ startWorker();
987
+ }
988
+ function gutterChanged() {
989
+ var visible = options.gutter || options.lineNumbers;
990
+ gutter.style.display = visible ? "" : "none";
991
+ if (visible) updateGutter();
992
+ else lineDiv.parentNode.style.marginLeft = 0;
993
+ }
994
+
995
+ function markText(from, to, className) {
996
+ from = clipPos(from); to = clipPos(to);
997
+ var accum = [];
998
+ function add(line, from, to, className) {
999
+ var line = lines[line], mark = line.addMark(from, to, className);
1000
+ mark.line = line;
1001
+ accum.push(mark);
1002
+ }
1003
+ if (from.line == to.line) add(from.line, from.ch, to.ch, className);
1004
+ else {
1005
+ add(from.line, from.ch, null, className);
1006
+ for (var i = from.line + 1, e = to.line; i < e; ++i)
1007
+ add(i, 0, null, className);
1008
+ add(to.line, 0, to.ch, className);
1009
+ }
1010
+ changes.push({from: from.line, to: to.line + 1});
1011
+ return function() {
1012
+ var start, end;
1013
+ for (var i = 0; i < accum.length; ++i) {
1014
+ var mark = accum[i], found = indexOf(lines, mark.line);
1015
+ mark.line.removeMark(mark);
1016
+ if (found > -1) {
1017
+ if (start == null) start = found;
1018
+ end = found;
1019
+ }
1020
+ }
1021
+ if (start != null) changes.push({from: start, to: end + 1});
1022
+ };
1023
+ }
1024
+
1025
+ function addGutterMarker(line, text, className) {
1026
+ if (typeof line == "number") line = lines[clipLine(line)];
1027
+ line.gutterMarker = {text: text, style: className};
1028
+ updateGutter();
1029
+ return line;
1030
+ }
1031
+ function removeGutterMarker(line) {
1032
+ if (typeof line == "number") line = lines[clipLine(line)];
1033
+ line.gutterMarker = null;
1034
+ updateGutter();
1035
+ }
1036
+ function setLineClass(line, className) {
1037
+ if (typeof line == "number") {
1038
+ var no = line;
1039
+ line = lines[clipLine(line)];
1040
+ }
1041
+ else {
1042
+ var no = indexOf(lines, line);
1043
+ if (no == -1) return null;
1044
+ }
1045
+ if (line.className != className) {
1046
+ line.className = className;
1047
+ changes.push({from: no, to: no + 1});
1048
+ }
1049
+ return line;
1050
+ }
1051
+
1052
+ function lineInfo(line) {
1053
+ if (typeof line == "number") {
1054
+ var n = line;
1055
+ line = lines[line];
1056
+ if (!line) return null;
1057
+ }
1058
+ else {
1059
+ var n = indexOf(lines, line);
1060
+ if (n == -1) return null;
1061
+ }
1062
+ var marker = line.gutterMarker;
1063
+ return {line: n, text: line.text, markerText: marker && marker.text, markerClass: marker && marker.style};
1064
+ }
1065
+
1066
+ function stringWidth(str) {
1067
+ measure.innerHTML = "<pre><span>x</span></pre>";
1068
+ measure.firstChild.firstChild.firstChild.nodeValue = str;
1069
+ return measure.firstChild.firstChild.offsetWidth || 10;
1070
+ }
1071
+ // These are used to go from pixel positions to character
1072
+ // positions, taking varying character widths into account.
1073
+ function charX(line, pos) {
1074
+ if (pos == 0) return 0;
1075
+ measure.innerHTML = "<pre><span>" + lines[line].getHTML(null, null, false, pos) + "</span></pre>";
1076
+ return measure.firstChild.firstChild.offsetWidth;
1077
+ }
1078
+ function charFromX(line, x) {
1079
+ if (x <= 0) return 0;
1080
+ var lineObj = lines[line], text = lineObj.text;
1081
+ function getX(len) {
1082
+ measure.innerHTML = "<pre><span>" + lineObj.getHTML(null, null, false, len) + "</span></pre>";
1083
+ return measure.firstChild.firstChild.offsetWidth;
1084
+ }
1085
+ var from = 0, fromX = 0, to = text.length, toX;
1086
+ // Guess a suitable upper bound for our search.
1087
+ var estimated = Math.min(to, Math.ceil(x / stringWidth("x")));
1088
+ for (;;) {
1089
+ var estX = getX(estimated);
1090
+ if (estX <= x && estimated < to) estimated = Math.min(to, Math.ceil(estimated * 1.2));
1091
+ else {toX = estX; to = estimated; break;}
1092
+ }
1093
+ if (x > toX) return to;
1094
+ // Try to guess a suitable lower bound as well.
1095
+ estimated = Math.floor(to * 0.8); estX = getX(estimated);
1096
+ if (estX < x) {from = estimated; fromX = estX;}
1097
+ // Do a binary search between these bounds.
1098
+ for (;;) {
1099
+ if (to - from <= 1) return (toX - x > x - fromX) ? from : to;
1100
+ var middle = Math.ceil((from + to) / 2), middleX = getX(middle);
1101
+ if (middleX > x) {to = middle; toX = middleX;}
1102
+ else {from = middle; fromX = middleX;}
1103
+ }
1104
+ }
1105
+
1106
+ function localCoords(pos, inLineWrap) {
1107
+ var lh = lineHeight(), line = pos.line - (inLineWrap ? showingFrom : 0);
1108
+ return {x: charX(pos.line, pos.ch), y: line * lh, yBot: (line + 1) * lh};
1109
+ }
1110
+ function pageCoords(pos) {
1111
+ var local = localCoords(pos, true), off = eltOffset(lineSpace);
1112
+ return {x: off.left + local.x, y: off.top + local.y, yBot: off.top + local.yBot};
1113
+ }
1114
+
1115
+ function lineHeight() {
1116
+ var nlines = lineDiv.childNodes.length;
1117
+ if (nlines) return (lineDiv.offsetHeight / nlines) || 1;
1118
+ measure.innerHTML = "<pre>x</pre>";
1119
+ return measure.firstChild.offsetHeight || 1;
1120
+ }
1121
+ function paddingTop() {return lineSpace.offsetTop;}
1122
+ function paddingLeft() {return lineSpace.offsetLeft;}
1123
+
1124
+ function posFromMouse(e, liberal) {
1125
+ var offW = eltOffset(scroller, true), x = e.e.clientX, y = e.e.clientY;
1126
+ // This is a mess of a heuristic to try and determine whether a
1127
+ // scroll-bar was clicked or not, and to return null if one was
1128
+ // (and !liberal).
1129
+ if (!liberal && (x - offW.left > scroller.clientWidth || y - offW.top > scroller.clientHeight))
1130
+ return null;
1131
+ var offL = eltOffset(lineSpace, true);
1132
+ var line = showingFrom + Math.floor((y - offL.top) / lineHeight());
1133
+ return clipPos({line: line, ch: charFromX(clipLine(line), x - offL.left)});
1134
+ }
1135
+ function onContextMenu(e) {
1136
+ var pos = posFromMouse(e);
1137
+ if (!pos || window.opera) return; // Opera is difficult.
1138
+ if (posEq(sel.from, sel.to) || posLess(pos, sel.from) || !posLess(pos, sel.to))
1139
+ setCursor(pos.line, pos.ch);
1140
+
1141
+ var oldCSS = input.style.cssText;
1142
+ input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.pageY() - 1) +
1143
+ "px; left: " + (e.pageX() - 1) + "px; z-index: 1000; background: white; " +
1144
+ "border-width: 0; outline: none; overflow: hidden; opacity: .05;";
1145
+ var val = input.value = getSelection();
1146
+ focusInput();
1147
+ setSelRange(input, 0, input.value.length);
1148
+ leaveInputAlone = true;
1149
+ function rehide() {
1150
+ if (input.value != val) operation(replaceSelection)(input.value, "end");
1151
+ input.style.cssText = oldCSS;
1152
+ leaveInputAlone = false;
1153
+ prepareInput();
1154
+ slowPoll();
1155
+ }
1156
+
1157
+ if (gecko) {
1158
+ e.stop()
1159
+ var mouseup = connect(window, "mouseup", function() {
1160
+ mouseup();
1161
+ setTimeout(rehide, 20);
1162
+ }, true);
1163
+ }
1164
+ else {
1165
+ setTimeout(rehide, 50);
1166
+ }
1167
+ }
1168
+
1169
+ // Cursor-blinking
1170
+ function restartBlink() {
1171
+ clearInterval(blinker);
1172
+ var on = true;
1173
+ cursor.style.visibility = "";
1174
+ blinker = setInterval(function() {
1175
+ cursor.style.visibility = (on = !on) ? "" : "hidden";
1176
+ }, 650);
1177
+ }
1178
+
1179
+ var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
1180
+ function matchBrackets(autoclear) {
1181
+ var head = sel.inverted ? sel.from : sel.to, line = lines[head.line], pos = head.ch - 1;
1182
+ var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
1183
+ if (!match) return;
1184
+ var ch = match.charAt(0), forward = match.charAt(1) == ">", d = forward ? 1 : -1, st = line.styles;
1185
+ for (var off = pos + 1, i = 0, e = st.length; i < e; i+=2)
1186
+ if ((off -= st[i].length) <= 0) {var style = st[i+1]; break;}
1187
+
1188
+ var stack = [line.text.charAt(pos)], re = /[(){}[\]]/;
1189
+ function scan(line, from, to) {
1190
+ if (!line.text) return;
1191
+ var st = line.styles, pos = forward ? 0 : line.text.length - 1, cur;
1192
+ for (var i = forward ? 0 : st.length - 2, e = forward ? st.length : -2; i != e; i += 2*d) {
1193
+ var text = st[i];
1194
+ if (st[i+1] != null && st[i+1] != style) {pos += d * text.length; continue;}
1195
+ for (var j = forward ? 0 : text.length - 1, te = forward ? text.length : -1; j != te; j += d, pos+=d) {
1196
+ if (pos >= from && pos < to && re.test(cur = text.charAt(j))) {
1197
+ var match = matching[cur];
1198
+ if (match.charAt(1) == ">" == forward) stack.push(cur);
1199
+ else if (stack.pop() != match.charAt(0)) return {pos: pos, match: false};
1200
+ else if (!stack.length) return {pos: pos, match: true};
1201
+ }
1202
+ }
1203
+ }
1204
+ }
1205
+ for (var i = head.line, e = forward ? Math.min(i + 50, lines.length) : Math.max(-1, i - 50); i != e; i+=d) {
1206
+ var line = lines[i], first = i == head.line;
1207
+ var found = scan(line, first && forward ? pos + 1 : 0, first && !forward ? pos : line.text.length);
1208
+ if (found) {
1209
+ var style = found.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
1210
+ var one = markText({line: head.line, ch: pos}, {line: head.line, ch: pos+1}, style),
1211
+ two = markText({line: i, ch: found.pos}, {line: i, ch: found.pos + 1}, style);
1212
+ var clear = operation(function(){one(); two();});
1213
+ if (autoclear) setTimeout(clear, 800);
1214
+ else bracketHighlighted = clear;
1215
+ break;
1216
+ }
1217
+ }
1218
+ }
1219
+
1220
+ // Finds the line to start with when starting a parse. Tries to
1221
+ // find a line with a stateAfter, so that it can start with a
1222
+ // valid state. If that fails, it returns the line with the
1223
+ // smallest indentation, which tends to need the least context to
1224
+ // parse correctly.
1225
+ function findStartLine(n) {
1226
+ var minindent, minline;
1227
+ for (var search = n, lim = n - 40; search > lim; --search) {
1228
+ if (search == 0) return 0;
1229
+ var line = lines[search-1];
1230
+ if (line.stateAfter) return search;
1231
+ var indented = line.indentation();
1232
+ if (minline == null || minindent > indented) {
1233
+ minline = search;
1234
+ minindent = indented;
1235
+ }
1236
+ }
1237
+ return minline;
1238
+ }
1239
+ function getStateBefore(n) {
1240
+ var start = findStartLine(n), state = start && lines[start-1].stateAfter;
1241
+ if (!state) state = startState(mode);
1242
+ else state = copyState(mode, state);
1243
+ for (var i = start; i < n; ++i) {
1244
+ var line = lines[i];
1245
+ line.highlight(mode, state);
1246
+ line.stateAfter = copyState(mode, state);
1247
+ }
1248
+ if (!lines[n].stateAfter) work.push(n);
1249
+ return state;
1250
+ }
1251
+ function highlightLines(start, end) {
1252
+ var state = getStateBefore(start);
1253
+ for (var i = start; i < end; ++i) {
1254
+ var line = lines[i];
1255
+ line.highlight(mode, state);
1256
+ line.stateAfter = copyState(mode, state);
1257
+ }
1258
+ }
1259
+ function highlightWorker() {
1260
+ var end = +new Date + options.workTime;
1261
+ var foundWork = work.length;
1262
+ while (work.length) {
1263
+ if (!lines[showingFrom].stateAfter) var task = showingFrom;
1264
+ else var task = work.pop();
1265
+ if (task >= lines.length) continue;
1266
+ var start = findStartLine(task), state = start && lines[start-1].stateAfter;
1267
+ if (state) state = copyState(mode, state);
1268
+ else state = startState(mode);
1269
+
1270
+ var unchanged = 0;
1271
+ for (var i = start, l = lines.length; i < l; ++i) {
1272
+ var line = lines[i], hadState = line.stateAfter;
1273
+ if (+new Date > end) {
1274
+ work.push(i);
1275
+ startWorker(options.workDelay);
1276
+ changes.push({from: task, to: i});
1277
+ return;
1278
+ }
1279
+ var changed = line.highlight(mode, state);
1280
+ line.stateAfter = copyState(mode, state);
1281
+ if (changed || !hadState) unchanged = 0;
1282
+ else if (++unchanged > 3) break;
1283
+ }
1284
+ changes.push({from: task, to: i});
1285
+ }
1286
+ if (foundWork && options.onHighlightComplete)
1287
+ options.onHighlightComplete(instance);
1288
+ }
1289
+ function startWorker(time) {
1290
+ if (!work.length) return;
1291
+ highlight.set(time, operation(highlightWorker));
1292
+ }
1293
+
1294
+ // Operations are used to wrap changes in such a way that each
1295
+ // change won't have to update the cursor and display (which would
1296
+ // be awkward, slow, and error-prone), but instead updates are
1297
+ // batched and then all combined and executed at once.
1298
+ function startOperation() {
1299
+ updateInput = null; changes = []; textChanged = selectionChanged = false;
1300
+ }
1301
+ function endOperation() {
1302
+ var reScroll = false;
1303
+ if (selectionChanged) reScroll = !scrollCursorIntoView();
1304
+ if (changes.length) updateDisplay(changes);
1305
+ else if (selectionChanged) updateCursor();
1306
+ if (reScroll) scrollCursorIntoView();
1307
+ if (selectionChanged) restartBlink();
1308
+
1309
+ // updateInput can be set to a boolean value to force/prevent an
1310
+ // update.
1311
+ if (!leaveInputAlone && (updateInput === true || (updateInput !== false && selectionChanged)))
1312
+ prepareInput();
1313
+
1314
+ if (selectionChanged && options.matchBrackets)
1315
+ setTimeout(operation(function() {
1316
+ if (bracketHighlighted) {bracketHighlighted(); bracketHighlighted = null;}
1317
+ matchBrackets(false);
1318
+ }), 20);
1319
+ var tc = textChanged; // textChanged can be reset by cursoractivity callback
1320
+ if (selectionChanged && options.onCursorActivity)
1321
+ options.onCursorActivity(instance);
1322
+ if (tc && options.onChange && instance)
1323
+ options.onChange(instance, tc);
1324
+ }
1325
+ var nestedOperation = 0;
1326
+ function operation(f) {
1327
+ return function() {
1328
+ if (!nestedOperation++) startOperation();
1329
+ try {var result = f.apply(this, arguments);}
1330
+ finally {if (!--nestedOperation) endOperation();}
1331
+ return result;
1332
+ };
1333
+ }
1334
+
1335
+ function SearchCursor(query, pos, caseFold) {
1336
+ this.atOccurrence = false;
1337
+ if (caseFold == null) caseFold = typeof query == "string" && query == query.toLowerCase();
1338
+
1339
+ if (pos && typeof pos == "object") pos = clipPos(pos);
1340
+ else pos = {line: 0, ch: 0};
1341
+ this.pos = {from: pos, to: pos};
1342
+
1343
+ // The matches method is filled in based on the type of query.
1344
+ // It takes a position and a direction, and returns an object
1345
+ // describing the next occurrence of the query, or null if no
1346
+ // more matches were found.
1347
+ if (typeof query != "string") // Regexp match
1348
+ this.matches = function(reverse, pos) {
1349
+ if (reverse) {
1350
+ var line = lines[pos.line].text.slice(0, pos.ch), match = line.match(query), start = 0;
1351
+ while (match) {
1352
+ var ind = line.indexOf(match[0]);
1353
+ start += ind;
1354
+ line = line.slice(ind + 1);
1355
+ var newmatch = line.match(query);
1356
+ if (newmatch) match = newmatch;
1357
+ else break;
1358
+ start++;
1359
+ }
1360
+ }
1361
+ else {
1362
+ var line = lines[pos.line].text.slice(pos.ch), match = line.match(query),
1363
+ start = match && pos.ch + line.indexOf(match[0]);
1364
+ }
1365
+ if (match)
1366
+ return {from: {line: pos.line, ch: start},
1367
+ to: {line: pos.line, ch: start + match[0].length},
1368
+ match: match};
1369
+ };
1370
+ else { // String query
1371
+ if (caseFold) query = query.toLowerCase();
1372
+ var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;};
1373
+ var target = query.split("\n");
1374
+ // Different methods for single-line and multi-line queries
1375
+ if (target.length == 1)
1376
+ this.matches = function(reverse, pos) {
1377
+ var line = fold(lines[pos.line].text), len = query.length, match;
1378
+ if (reverse ? (pos.ch >= len && (match = line.lastIndexOf(query, pos.ch - len)) != -1)
1379
+ : (match = line.indexOf(query, pos.ch)) != -1)
1380
+ return {from: {line: pos.line, ch: match},
1381
+ to: {line: pos.line, ch: match + len}};
1382
+ };
1383
+ else
1384
+ this.matches = function(reverse, pos) {
1385
+ var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(lines[ln].text);
1386
+ var offsetA = (reverse ? line.indexOf(match) + match.length : line.lastIndexOf(match));
1387
+ if (reverse ? offsetA >= pos.ch || offsetA != match.length
1388
+ : offsetA <= pos.ch || offsetA != line.length - match.length)
1389
+ return;
1390
+ for (;;) {
1391
+ if (reverse ? !ln : ln == lines.length - 1) return;
1392
+ line = fold(lines[ln += reverse ? -1 : 1].text);
1393
+ match = target[reverse ? --idx : ++idx];
1394
+ if (idx > 0 && idx < target.length - 1) {
1395
+ if (line != match) return;
1396
+ else continue;
1397
+ }
1398
+ var offsetB = (reverse ? line.lastIndexOf(match) : line.indexOf(match) + match.length);
1399
+ if (reverse ? offsetB != line.length - match.length : offsetB != match.length)
1400
+ return;
1401
+ var start = {line: pos.line, ch: offsetA}, end = {line: ln, ch: offsetB};
1402
+ return {from: reverse ? end : start, to: reverse ? start : end};
1403
+ }
1404
+ };
1405
+ }
1406
+ }
1407
+
1408
+ SearchCursor.prototype = {
1409
+ findNext: function() {return this.find(false);},
1410
+ findPrevious: function() {return this.find(true);},
1411
+
1412
+ find: function(reverse) {
1413
+ var self = this, pos = clipPos(reverse ? this.pos.from : this.pos.to);
1414
+ function savePosAndFail(line) {
1415
+ var pos = {line: line, ch: 0};
1416
+ self.pos = {from: pos, to: pos};
1417
+ self.atOccurrence = false;
1418
+ return false;
1419
+ }
1420
+
1421
+ for (;;) {
1422
+ if (this.pos = this.matches(reverse, pos)) {
1423
+ this.atOccurrence = true;
1424
+ return this.pos.match || true;
1425
+ }
1426
+ if (reverse) {
1427
+ if (!pos.line) return savePosAndFail(0);
1428
+ pos = {line: pos.line-1, ch: lines[pos.line-1].text.length};
1429
+ }
1430
+ else {
1431
+ if (pos.line == lines.length - 1) return savePosAndFail(lines.length);
1432
+ pos = {line: pos.line+1, ch: 0};
1433
+ }
1434
+ }
1435
+ },
1436
+
1437
+ from: function() {if (this.atOccurrence) return copyPos(this.pos.from);},
1438
+ to: function() {if (this.atOccurrence) return copyPos(this.pos.to);}
1439
+ };
1440
+
1441
+ for (var ext in extensions)
1442
+ if (extensions.propertyIsEnumerable(ext) &&
1443
+ !instance.propertyIsEnumerable(ext))
1444
+ instance[ext] = extensions[ext];
1445
+ return instance;
1446
+ } // (end of function CodeMirror)
1447
+
1448
+ // The default configuration options.
1449
+ CodeMirror.defaults = {
1450
+ value: "",
1451
+ mode: null,
1452
+ theme: "default",
1453
+ indentUnit: 2,
1454
+ indentWithTabs: false,
1455
+ tabMode: "classic",
1456
+ enterMode: "indent",
1457
+ electricChars: true,
1458
+ onKeyEvent: null,
1459
+ lineNumbers: false,
1460
+ gutter: false,
1461
+ firstLineNumber: 1,
1462
+ readOnly: false,
1463
+ onChange: null,
1464
+ onCursorActivity: null,
1465
+ onGutterClick: null,
1466
+ onHighlightComplete: null,
1467
+ onFocus: null, onBlur: null, onScroll: null,
1468
+ matchBrackets: false,
1469
+ workTime: 100,
1470
+ workDelay: 200,
1471
+ undoDepth: 40,
1472
+ tabindex: null,
1473
+ document: window.document
1474
+ };
1475
+
1476
+ // Known modes, by name and by MIME
1477
+ var modes = {}, mimeModes = {};
1478
+ CodeMirror.defineMode = function(name, mode) {
1479
+ if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
1480
+ modes[name] = mode;
1481
+ };
1482
+ CodeMirror.defineMIME = function(mime, spec) {
1483
+ mimeModes[mime] = spec;
1484
+ };
1485
+ CodeMirror.getMode = function(options, spec) {
1486
+ if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
1487
+ spec = mimeModes[spec];
1488
+ if (typeof spec == "string")
1489
+ var mname = spec, config = {};
1490
+ else if (spec != null)
1491
+ var mname = spec.name, config = spec;
1492
+ var mfactory = modes[mname];
1493
+ if (!mfactory) {
1494
+ if (window.console) console.warn("No mode " + mname + " found, falling back to plain text.");
1495
+ return CodeMirror.getMode(options, "text/plain");
1496
+ }
1497
+ return mfactory(options, config || {});
1498
+ }
1499
+ CodeMirror.listModes = function() {
1500
+ var list = [];
1501
+ for (var m in modes)
1502
+ if (modes.propertyIsEnumerable(m)) list.push(m);
1503
+ return list;
1504
+ };
1505
+ CodeMirror.listMIMEs = function() {
1506
+ var list = [];
1507
+ for (var m in mimeModes)
1508
+ if (mimeModes.propertyIsEnumerable(m)) list.push(m);
1509
+ return list;
1510
+ };
1511
+
1512
+ var extensions = {};
1513
+ CodeMirror.defineExtension = function(name, func) {
1514
+ extensions[name] = func;
1515
+ };
1516
+
1517
+ CodeMirror.fromTextArea = function(textarea, options) {
1518
+ if (!options) options = {};
1519
+ options.value = textarea.value;
1520
+ if (!options.tabindex && textarea.tabindex)
1521
+ options.tabindex = textarea.tabindex;
1522
+
1523
+ function save() {textarea.value = instance.getValue();}
1524
+ if (textarea.form) {
1525
+ // Deplorable hack to make the submit method do the right thing.
1526
+ var rmSubmit = connect(textarea.form, "submit", save, true);
1527
+ if (typeof textarea.form.submit == "function") {
1528
+ var realSubmit = textarea.form.submit;
1529
+ function wrappedSubmit() {
1530
+ save();
1531
+ textarea.form.submit = realSubmit;
1532
+ textarea.form.submit();
1533
+ textarea.form.submit = wrappedSubmit;
1534
+ }
1535
+ textarea.form.submit = wrappedSubmit;
1536
+ }
1537
+ }
1538
+
1539
+ textarea.style.display = "none";
1540
+ var instance = CodeMirror(function(node) {
1541
+ textarea.parentNode.insertBefore(node, textarea.nextSibling);
1542
+ }, options);
1543
+ instance.save = save;
1544
+ instance.toTextArea = function() {
1545
+ save();
1546
+ textarea.parentNode.removeChild(instance.getWrapperElement());
1547
+ textarea.style.display = "";
1548
+ if (textarea.form) {
1549
+ rmSubmit();
1550
+ if (typeof textarea.form.submit == "function")
1551
+ textarea.form.submit = realSubmit;
1552
+ }
1553
+ };
1554
+ return instance;
1555
+ };
1556
+
1557
+ // Utility functions for working with state. Exported because modes
1558
+ // sometimes need to do this.
1559
+ function copyState(mode, state) {
1560
+ if (state === true) return state;
1561
+ if (mode.copyState) return mode.copyState(state);
1562
+ var nstate = {};
1563
+ for (var n in state) {
1564
+ var val = state[n];
1565
+ if (val instanceof Array) val = val.concat([]);
1566
+ nstate[n] = val;
1567
+ }
1568
+ return nstate;
1569
+ }
1570
+ CodeMirror.startState = startState;
1571
+ function startState(mode, a1, a2) {
1572
+ return mode.startState ? mode.startState(a1, a2) : true;
1573
+ }
1574
+ CodeMirror.copyState = copyState;
1575
+
1576
+ // The character stream used by a mode's parser.
1577
+ function StringStream(string) {
1578
+ this.pos = this.start = 0;
1579
+ this.string = string;
1580
+ }
1581
+ StringStream.prototype = {
1582
+ eol: function() {return this.pos >= this.string.length;},
1583
+ sol: function() {return this.pos == 0;},
1584
+ peek: function() {return this.string.charAt(this.pos);},
1585
+ next: function() {
1586
+ if (this.pos < this.string.length)
1587
+ return this.string.charAt(this.pos++);
1588
+ },
1589
+ eat: function(match) {
1590
+ var ch = this.string.charAt(this.pos);
1591
+ if (typeof match == "string") var ok = ch == match;
1592
+ else var ok = ch && (match.test ? match.test(ch) : match(ch));
1593
+ if (ok) {++this.pos; return ch;}
1594
+ },
1595
+ eatWhile: function(match) {
1596
+ var start = this.start;
1597
+ while (this.eat(match)){}
1598
+ return this.pos > start;
1599
+ },
1600
+ eatSpace: function() {
1601
+ var start = this.pos;
1602
+ while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
1603
+ return this.pos > start;
1604
+ },
1605
+ skipToEnd: function() {this.pos = this.string.length;},
1606
+ skipTo: function(ch) {
1607
+ var found = this.string.indexOf(ch, this.pos);
1608
+ if (found > -1) {this.pos = found; return true;}
1609
+ },
1610
+ backUp: function(n) {this.pos -= n;},
1611
+ column: function() {return countColumn(this.string, this.start);},
1612
+ indentation: function() {return countColumn(this.string);},
1613
+ match: function(pattern, consume, caseInsensitive) {
1614
+ if (typeof pattern == "string") {
1615
+ function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
1616
+ if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
1617
+ if (consume !== false) this.pos += pattern.length;
1618
+ return true;
1619
+ }
1620
+ }
1621
+ else {
1622
+ var match = this.string.slice(this.pos).match(pattern);
1623
+ if (match && consume !== false) this.pos += match[0].length;
1624
+ return match;
1625
+ }
1626
+ },
1627
+ current: function(){return this.string.slice(this.start, this.pos);}
1628
+ };
1629
+ CodeMirror.StringStream = StringStream;
1630
+
1631
+ // Line objects. These hold state related to a line, including
1632
+ // highlighting info (the styles array).
1633
+ function Line(text, styles) {
1634
+ this.styles = styles || [text, null];
1635
+ this.stateAfter = null;
1636
+ this.text = text;
1637
+ this.marked = this.gutterMarker = this.className = null;
1638
+ }
1639
+ Line.prototype = {
1640
+ // Replace a piece of a line, keeping the styles around it intact.
1641
+ replace: function(from, to, text) {
1642
+ var st = [], mk = this.marked;
1643
+ copyStyles(0, from, this.styles, st);
1644
+ if (text) st.push(text, null);
1645
+ copyStyles(to, this.text.length, this.styles, st);
1646
+ this.styles = st;
1647
+ this.text = this.text.slice(0, from) + text + this.text.slice(to);
1648
+ this.stateAfter = null;
1649
+ if (mk) {
1650
+ var diff = text.length - (to - from), end = this.text.length;
1651
+ function fix(n) {return n <= Math.min(to, to + diff) ? n : n + diff;}
1652
+ for (var i = 0; i < mk.length; ++i) {
1653
+ var mark = mk[i], del = false;
1654
+ if (mark.from >= end) del = true;
1655
+ else {mark.from = fix(mark.from); if (mark.to != null) mark.to = fix(mark.to);}
1656
+ if (del || mark.from >= mark.to) {mk.splice(i, 1); i--;}
1657
+ }
1658
+ }
1659
+ },
1660
+ // Split a line in two, again keeping styles intact.
1661
+ split: function(pos, textBefore) {
1662
+ var st = [textBefore, null];
1663
+ copyStyles(pos, this.text.length, this.styles, st);
1664
+ return new Line(textBefore + this.text.slice(pos), st);
1665
+ },
1666
+ addMark: function(from, to, style) {
1667
+ var mk = this.marked, mark = {from: from, to: to, style: style};
1668
+ if (this.marked == null) this.marked = [];
1669
+ this.marked.push(mark);
1670
+ this.marked.sort(function(a, b){return a.from - b.from;});
1671
+ return mark;
1672
+ },
1673
+ removeMark: function(mark) {
1674
+ var mk = this.marked;
1675
+ if (!mk) return;
1676
+ for (var i = 0; i < mk.length; ++i)
1677
+ if (mk[i] == mark) {mk.splice(i, 1); break;}
1678
+ },
1679
+ // Run the given mode's parser over a line, update the styles
1680
+ // array, which contains alternating fragments of text and CSS
1681
+ // classes.
1682
+ highlight: function(mode, state) {
1683
+ var stream = new StringStream(this.text), st = this.styles, pos = 0;
1684
+ var changed = false, curWord = st[0], prevWord;
1685
+ if (this.text == "" && mode.blankLine) mode.blankLine(state);
1686
+ while (!stream.eol()) {
1687
+ var style = mode.token(stream, state);
1688
+ var substr = this.text.slice(stream.start, stream.pos);
1689
+ stream.start = stream.pos;
1690
+ if (pos && st[pos-1] == style)
1691
+ st[pos-2] += substr;
1692
+ else if (substr) {
1693
+ if (!changed && (st[pos+1] != style || (pos && st[pos-2] != prevWord))) changed = true;
1694
+ st[pos++] = substr; st[pos++] = style;
1695
+ prevWord = curWord; curWord = st[pos];
1696
+ }
1697
+ // Give up when line is ridiculously long
1698
+ if (stream.pos > 5000) {
1699
+ st[pos++] = this.text.slice(stream.pos); st[pos++] = null;
1700
+ break;
1701
+ }
1702
+ }
1703
+ if (st.length != pos) {st.length = pos; changed = true;}
1704
+ if (pos && st[pos-2] != prevWord) changed = true;
1705
+ // Short lines with simple highlights always count as changed,
1706
+ // because they are likely to highlight the same way in various
1707
+ // contexts.
1708
+ return changed || (st.length < 5 && this.text.length < 10);
1709
+ },
1710
+ // Fetch the parser token for a given character. Useful for hacks
1711
+ // that want to inspect the mode state (say, for completion).
1712
+ getTokenAt: function(mode, state, ch) {
1713
+ var txt = this.text, stream = new StringStream(txt);
1714
+ while (stream.pos < ch && !stream.eol()) {
1715
+ stream.start = stream.pos;
1716
+ var style = mode.token(stream, state);
1717
+ }
1718
+ return {start: stream.start,
1719
+ end: stream.pos,
1720
+ string: stream.current(),
1721
+ className: style || null,
1722
+ state: state};
1723
+ },
1724
+ indentation: function() {return countColumn(this.text);},
1725
+ // Produces an HTML fragment for the line, taking selection,
1726
+ // marking, and highlighting into account.
1727
+ getHTML: function(sfrom, sto, includePre, endAt) {
1728
+ var html = [];
1729
+ if (includePre)
1730
+ html.push(this.className ? '<pre class="' + this.className + '">': "<pre>");
1731
+ function span(text, style) {
1732
+ if (!text) return;
1733
+ if (style) html.push('<span class="cm-', style, '">', htmlEscape(text), "</span>");
1734
+ else html.push(htmlEscape(text));
1735
+ }
1736
+ var st = this.styles, allText = this.text, marked = this.marked;
1737
+ if (sfrom == sto) sfrom = null;
1738
+ var len = allText.length;
1739
+ if (endAt != null) len = Math.min(endAt, len);
1740
+
1741
+ if (!allText && endAt == null)
1742
+ span(" ", sfrom != null && sto == null ? "CodeMirror-selected" : null);
1743
+ else if (!marked && sfrom == null)
1744
+ for (var i = 0, ch = 0; ch < len; i+=2) {
1745
+ var str = st[i], l = str.length;
1746
+ if (ch + l > len) str = str.slice(0, len - ch);
1747
+ ch += l;
1748
+ span(str, st[i+1]);
1749
+ }
1750
+ else {
1751
+ var pos = 0, i = 0, text = "", style, sg = 0;
1752
+ var markpos = -1, mark = null;
1753
+ function nextMark() {
1754
+ if (marked) {
1755
+ markpos += 1;
1756
+ mark = (markpos < marked.length) ? marked[markpos] : null;
1757
+ }
1758
+ }
1759
+ nextMark();
1760
+ while (pos < len) {
1761
+ var upto = len;
1762
+ var extraStyle = "";
1763
+ if (sfrom != null) {
1764
+ if (sfrom > pos) upto = sfrom;
1765
+ else if (sto == null || sto > pos) {
1766
+ extraStyle = " CodeMirror-selected";
1767
+ if (sto != null) upto = Math.min(upto, sto);
1768
+ }
1769
+ }
1770
+ while (mark && mark.to != null && mark.to <= pos) nextMark();
1771
+ if (mark) {
1772
+ if (mark.from > pos) upto = Math.min(upto, mark.from);
1773
+ else {
1774
+ extraStyle += " " + mark.style;
1775
+ if (mark.to != null) upto = Math.min(upto, mark.to);
1776
+ }
1777
+ }
1778
+ for (;;) {
1779
+ var end = pos + text.length;
1780
+ var apliedStyle = style;
1781
+ if (extraStyle) apliedStyle = style ? style + extraStyle : extraStyle;
1782
+ span(end > upto ? text.slice(0, upto - pos) : text, apliedStyle);
1783
+ if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
1784
+ pos = end;
1785
+ text = st[i++]; style = st[i++];
1786
+ }
1787
+ }
1788
+ if (sfrom != null && sto == null) span(" ", "CodeMirror-selected");
1789
+ }
1790
+ if (includePre) html.push("</pre>");
1791
+ return html.join("");
1792
+ }
1793
+ };
1794
+ // Utility used by replace and split above
1795
+ function copyStyles(from, to, source, dest) {
1796
+ for (var i = 0, pos = 0, state = 0; pos < to; i+=2) {
1797
+ var part = source[i], end = pos + part.length;
1798
+ if (state == 0) {
1799
+ if (end > from) dest.push(part.slice(from - pos, Math.min(part.length, to - pos)), source[i+1]);
1800
+ if (end >= from) state = 1;
1801
+ }
1802
+ else if (state == 1) {
1803
+ if (end > to) dest.push(part.slice(0, to - pos), source[i+1]);
1804
+ else dest.push(part, source[i+1]);
1805
+ }
1806
+ pos = end;
1807
+ }
1808
+ }
1809
+
1810
+ // The history object 'chunks' changes that are made close together
1811
+ // and at almost the same time into bigger undoable units.
1812
+ function History() {
1813
+ this.time = 0;
1814
+ this.done = []; this.undone = [];
1815
+ }
1816
+ History.prototype = {
1817
+ addChange: function(start, added, old) {
1818
+ this.undone.length = 0;
1819
+ var time = +new Date, last = this.done[this.done.length - 1];
1820
+ if (time - this.time > 400 || !last ||
1821
+ last.start > start + added || last.start + last.added < start - last.added + last.old.length)
1822
+ this.done.push({start: start, added: added, old: old});
1823
+ else {
1824
+ var oldoff = 0;
1825
+ if (start < last.start) {
1826
+ for (var i = last.start - start - 1; i >= 0; --i)
1827
+ last.old.unshift(old[i]);
1828
+ last.added += last.start - start;
1829
+ last.start = start;
1830
+ }
1831
+ else if (last.start < start) {
1832
+ oldoff = start - last.start;
1833
+ added += oldoff;
1834
+ }
1835
+ for (var i = last.added - oldoff, e = old.length; i < e; ++i)
1836
+ last.old.push(old[i]);
1837
+ if (last.added < added) last.added = added;
1838
+ }
1839
+ this.time = time;
1840
+ }
1841
+ };
1842
+
1843
+ // Event stopping compatibility wrapper.
1844
+ function stopEvent() {
1845
+ if (this.preventDefault) {this.preventDefault(); this.stopPropagation();}
1846
+ else {this.returnValue = false; this.cancelBubble = true;}
1847
+ }
1848
+ // Ensure an event has a stop method.
1849
+ function addStop(event) {
1850
+ if (!event.stop) event.stop = stopEvent;
1851
+ return event;
1852
+ }
1853
+
1854
+ // Event wrapper, exposing the few operations we need.
1855
+ function Event(orig) {this.e = orig;}
1856
+ Event.prototype = {
1857
+ stop: function() {stopEvent.call(this.e);},
1858
+ target: function() {return this.e.target || this.e.srcElement;},
1859
+ button: function() {
1860
+ if (this.e.which) return this.e.which;
1861
+ else if (this.e.button & 1) return 1;
1862
+ else if (this.e.button & 2) return 3;
1863
+ else if (this.e.button & 4) return 2;
1864
+ },
1865
+ pageX: function() {
1866
+ if (this.e.pageX != null) return this.e.pageX;
1867
+ var doc = this.target().ownerDocument;
1868
+ return this.e.clientX + doc.body.scrollLeft + doc.documentElement.scrollLeft;
1869
+ },
1870
+ pageY: function() {
1871
+ if (this.e.pageY != null) return this.e.pageY;
1872
+ var doc = this.target().ownerDocument;
1873
+ return this.e.clientY + doc.body.scrollTop + doc.documentElement.scrollTop;
1874
+ }
1875
+ };
1876
+
1877
+ // Event handler registration. If disconnect is true, it'll return a
1878
+ // function that unregisters the handler.
1879
+ function connect(node, type, handler, disconnect) {
1880
+ function wrapHandler(event) {handler(new Event(event || window.event));}
1881
+ if (typeof node.addEventListener == "function") {
1882
+ node.addEventListener(type, wrapHandler, false);
1883
+ if (disconnect) return function() {node.removeEventListener(type, wrapHandler, false);};
1884
+ }
1885
+ else {
1886
+ node.attachEvent("on" + type, wrapHandler);
1887
+ if (disconnect) return function() {node.detachEvent("on" + type, wrapHandler);};
1888
+ }
1889
+ }
1890
+
1891
+ function Delayed() {this.id = null;}
1892
+ Delayed.prototype = {set: function(ms, f) {clearTimeout(this.id); this.id = setTimeout(f, ms);}};
1893
+
1894
+ // Some IE versions don't preserve whitespace when setting the
1895
+ // innerHTML of a PRE tag.
1896
+ var badInnerHTML = (function() {
1897
+ var pre = document.createElement("pre");
1898
+ pre.innerHTML = " "; return !pre.innerHTML;
1899
+ })();
1900
+
1901
+ var gecko = /gecko\/\d{7}/i.test(navigator.userAgent);
1902
+ var ie = /MSIE \d/.test(navigator.userAgent);
1903
+ var safari = /Apple Computer/.test(navigator.vendor);
1904
+
1905
+ var lineSep = "\n";
1906
+ // Feature-detect whether newlines in textareas are converted to \r\n
1907
+ (function () {
1908
+ var te = document.createElement("textarea");
1909
+ te.value = "foo\nbar";
1910
+ if (te.value.indexOf("\r") > -1) lineSep = "\r\n";
1911
+ }());
1912
+
1913
+ var tabSize = 8;
1914
+ var mac = /Mac/.test(navigator.platform);
1915
+ var movementKeys = {};
1916
+ for (var i = 35; i <= 40; ++i)
1917
+ movementKeys[i] = movementKeys["c" + i] = true;
1918
+
1919
+ // Counts the column offset in a string, taking tabs into account.
1920
+ // Used mostly to find indentation.
1921
+ function countColumn(string, end) {
1922
+ if (end == null) {
1923
+ end = string.search(/[^\s\u00a0]/);
1924
+ if (end == -1) end = string.length;
1925
+ }
1926
+ for (var i = 0, n = 0; i < end; ++i) {
1927
+ if (string.charAt(i) == "\t") n += tabSize - (n % tabSize);
1928
+ else ++n;
1929
+ }
1930
+ return n;
1931
+ }
1932
+
1933
+ // Find the position of an element by following the offsetParent chain.
1934
+ // If screen==true, it returns screen (rather than page) coordinates.
1935
+ function eltOffset(node, screen) {
1936
+ var doc = node.ownerDocument.body;
1937
+ var x = 0, y = 0, hitDoc = false;
1938
+ for (var n = node; n; n = n.offsetParent) {
1939
+ x += n.offsetLeft; y += n.offsetTop;
1940
+ // Fixed-position elements don't have the document in their offset chain
1941
+ if (n == doc) hitDoc = true;
1942
+ }
1943
+ var e = screen && hitDoc ? null : doc;
1944
+ for (var n = node.parentNode; n != e; n = n.parentNode)
1945
+ if (n.scrollLeft != null) { x -= n.scrollLeft; y -= n.scrollTop;}
1946
+ return {left: x, top: y};
1947
+ }
1948
+ // Get a node's text content.
1949
+ function eltText(node) {
1950
+ return node.textContent || node.innerText || node.nodeValue || "";
1951
+ }
1952
+
1953
+ // Operations on {line, ch} objects.
1954
+ function posEq(a, b) {return a.line == b.line && a.ch == b.ch;}
1955
+ function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);}
1956
+ function copyPos(x) {return {line: x.line, ch: x.ch};}
1957
+
1958
+ function htmlEscape(str) {
1959
+ return str.replace(/[<>&]/g, function(str) {
1960
+ return str == "&" ? "&amp;" : str == "<" ? "&lt;" : "&gt;";
1961
+ });
1962
+ }
1963
+ CodeMirror.htmlEscape = htmlEscape;
1964
+
1965
+ // Used to position the cursor after an undo/redo by finding the
1966
+ // last edited character.
1967
+ function editEnd(from, to) {
1968
+ if (!to) return from ? from.length : 0;
1969
+ if (!from) return to.length;
1970
+ for (var i = from.length, j = to.length; i >= 0 && j >= 0; --i, --j)
1971
+ if (from.charAt(i) != to.charAt(j)) break;
1972
+ return j + 1;
1973
+ }
1974
+
1975
+ function indexOf(collection, elt) {
1976
+ if (collection.indexOf) return collection.indexOf(elt);
1977
+ for (var i = 0, e = collection.length; i < e; ++i)
1978
+ if (collection[i] == elt) return i;
1979
+ return -1;
1980
+ }
1981
+
1982
+ // See if "".split is the broken IE version, if so, provide an
1983
+ // alternative way to split lines.
1984
+ if ("\n\nb".split(/\n/).length != 3)
1985
+ var splitLines = function(string) {
1986
+ var pos = 0, nl, result = [];
1987
+ while ((nl = string.indexOf("\n", pos)) > -1) {
1988
+ result.push(string.slice(pos, string.charAt(nl-1) == "\r" ? nl - 1 : nl));
1989
+ pos = nl + 1;
1990
+ }
1991
+ result.push(string.slice(pos));
1992
+ return result;
1993
+ };
1994
+ else
1995
+ var splitLines = function(string){return string.split(/\r?\n/);};
1996
+ CodeMirror.splitLines = splitLines;
1997
+
1998
+ // Sane model of finding and setting the selection in a textarea
1999
+ if (window.getSelection) {
2000
+ var selRange = function(te) {
2001
+ try {return {start: te.selectionStart, end: te.selectionEnd};}
2002
+ catch(e) {return null;}
2003
+ };
2004
+ if (safari)
2005
+ // On Safari, selection set with setSelectionRange are in a sort
2006
+ // of limbo wrt their anchor. If you press shift-left in them,
2007
+ // the anchor is put at the end, and the selection expanded to
2008
+ // the left. If you press shift-right, the anchor ends up at the
2009
+ // front. This is not what CodeMirror wants, so it does a
2010
+ // spurious modify() call to get out of limbo.
2011
+ var setSelRange = function(te, start, end) {
2012
+ if (start == end)
2013
+ te.setSelectionRange(start, end);
2014
+ else {
2015
+ te.setSelectionRange(start, end - 1);
2016
+ window.getSelection().modify("extend", "forward", "character");
2017
+ }
2018
+ };
2019
+ else
2020
+ var setSelRange = function(te, start, end) {
2021
+ try {te.setSelectionRange(start, end);}
2022
+ catch(e) {} // Fails on Firefox when textarea isn't part of the document
2023
+ };
2024
+ }
2025
+ // IE model. Don't ask.
2026
+ else {
2027
+ var selRange = function(te) {
2028
+ try {var range = te.ownerDocument.selection.createRange();}
2029
+ catch(e) {return null;}
2030
+ if (!range || range.parentElement() != te) return null;
2031
+ var val = te.value, len = val.length, localRange = te.createTextRange();
2032
+ localRange.moveToBookmark(range.getBookmark());
2033
+ var endRange = te.createTextRange();
2034
+ endRange.collapse(false);
2035
+
2036
+ if (localRange.compareEndPoints("StartToEnd", endRange) > -1)
2037
+ return {start: len, end: len};
2038
+
2039
+ var start = -localRange.moveStart("character", -len);
2040
+ for (var i = val.indexOf("\r"); i > -1 && i < start; i = val.indexOf("\r", i+1), start++) {}
2041
+
2042
+ if (localRange.compareEndPoints("EndToEnd", endRange) > -1)
2043
+ return {start: start, end: len};
2044
+
2045
+ var end = -localRange.moveEnd("character", -len);
2046
+ for (var i = val.indexOf("\r"); i > -1 && i < end; i = val.indexOf("\r", i+1), end++) {}
2047
+ return {start: start, end: end};
2048
+ };
2049
+ var setSelRange = function(te, start, end) {
2050
+ var range = te.createTextRange();
2051
+ range.collapse(true);
2052
+ var endrange = range.duplicate();
2053
+ var newlines = 0, txt = te.value;
2054
+ for (var pos = txt.indexOf("\n"); pos > -1 && pos < start; pos = txt.indexOf("\n", pos + 1))
2055
+ ++newlines;
2056
+ range.move("character", start - newlines);
2057
+ for (; pos > -1 && pos < end; pos = txt.indexOf("\n", pos + 1))
2058
+ ++newlines;
2059
+ endrange.move("character", end - newlines);
2060
+ range.setEndPoint("EndToEnd", endrange);
2061
+ range.select();
2062
+ };
2063
+ }
2064
+
2065
+ CodeMirror.defineMode("null", function() {
2066
+ return {token: function(stream) {stream.skipToEnd();}};
2067
+ });
2068
+ CodeMirror.defineMIME("text/plain", "null");
2069
+
2070
+ return CodeMirror;
2071
+ })();
libraries/codemirror/lib/overlay.js ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Utility function that allows modes to be combined. The mode given
2
+ // as the base argument takes care of most of the normal mode
3
+ // functionality, but a second (typically simple) mode is used, which
4
+ // can override the style of text. Both modes get to parse all of the
5
+ // text, but when both assign a non-null style to a piece of code, the
6
+ // overlay wins, unless the combine argument was true, in which case
7
+ // the styles are combined.
8
+
9
+ CodeMirror.overlayParser = function(base, overlay, combine) {
10
+ return {
11
+ startState: function() {
12
+ return {
13
+ base: CodeMirror.startState(base),
14
+ overlay: CodeMirror.startState(overlay),
15
+ basePos: 0, baseCur: null,
16
+ overlayPos: 0, overlayCur: null
17
+ };
18
+ },
19
+ copyState: function(state) {
20
+ return {
21
+ base: CodeMirror.copyState(base, state.base),
22
+ overlay: CodeMirror.copyState(overlay, state.overlay),
23
+ basePos: state.basePos, baseCur: null,
24
+ overlayPos: state.overlayPos, overlayCur: null
25
+ };
26
+ },
27
+
28
+ token: function(stream, state) {
29
+ if (stream.start == state.basePos) {
30
+ state.baseCur = base.token(stream, state.base);
31
+ state.basePos = stream.pos;
32
+ }
33
+ if (stream.start == state.overlayPos) {
34
+ stream.pos = stream.start;
35
+ state.overlayCur = overlay.token(stream, state.overlay);
36
+ state.overlayPos = stream.pos;
37
+ }
38
+ stream.pos = Math.min(state.basePos, state.overlayPos);
39
+ if (stream.eol()) state.basePos = state.overlayPos = 0;
40
+
41
+ if (state.overlayCur == null) return state.baseCur;
42
+ if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur;
43
+ else return state.overlayCur;
44
+ },
45
+
46
+ indent: function(state, textAfter) {
47
+ return base.indent(state.base, textAfter);
48
+ },
49
+ electricChars: base.electricChars
50
+ };
51
+ };
libraries/codemirror/lib/runmode.js ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CodeMirror.runMode = function(string, modespec, callback) {
2
+ var mode = CodeMirror.getMode({indentUnit: 2}, modespec);
3
+ var isNode = callback.nodeType == 1;
4
+ if (isNode) {
5
+ var node = callback, accum = [];
6
+ callback = function(string, style) {
7
+ if (string == "\n")
8
+ accum.push("<br>");
9
+ else if (style)
10
+ accum.push("<span class=\"cm-" + CodeMirror.htmlEscape(style) + "\">" + CodeMirror.htmlEscape(string) + "</span>");
11
+ else
12
+ accum.push(CodeMirror.htmlEscape(string));
13
+ }
14
+ }
15
+ var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode);
16
+ for (var i = 0, e = lines.length; i < e; ++i) {
17
+ if (i) callback("\n");
18
+ var stream = new CodeMirror.StringStream(lines[i]);
19
+ while (!stream.eol()) {
20
+ var style = mode.token(stream, state);
21
+ callback(stream.current(), style);
22
+ stream.start = stream.pos;
23
+ }
24
+ }
25
+ if (isNode)
26
+ node.innerHTML = accum.join("");
27
+ };
libraries/{CodeMirror2/mode/css → codemirror/mode}/css.js RENAMED
@@ -4,7 +4,7 @@ CodeMirror.defineMode("css", function(config) {
4
 
5
  function tokenBase(stream, state) {
6
  var ch = stream.next();
7
- if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("meta", stream.current());}
8
  else if (ch == "/" && stream.eat("*")) {
9
  state.tokenize = tokenCComment;
10
  return tokenCComment(stream, state);
@@ -20,7 +20,7 @@ CodeMirror.defineMode("css", function(config) {
20
  return state.tokenize(stream, state);
21
  }
22
  else if (ch == "#") {
23
- stream.eatWhile(/[\w\\\-]/);
24
  return ret("atom", "hash");
25
  }
26
  else if (ch == "!") {
@@ -38,7 +38,7 @@ CodeMirror.defineMode("css", function(config) {
38
  return ret(null, ch);
39
  }
40
  else {
41
- stream.eatWhile(/[\w\\\-]/);
42
  return ret("variable", "variable");
43
  }
44
  }
@@ -92,7 +92,7 @@ CodeMirror.defineMode("css", function(config) {
92
  var style = state.tokenize(stream, state);
93
 
94
  var context = state.stack[state.stack.length-1];
95
- if (type == "hash" && context != "rule") style = "string-2";
96
  else if (style == "variable") {
97
  if (context == "rule") style = "number";
98
  else if (!context || context == "@media{") style = "tag";
4
 
5
  function tokenBase(stream, state) {
6
  var ch = stream.next();
7
+ if (ch == "@") {stream.eatWhile(/\w/); return ret("meta", stream.current());}
8
  else if (ch == "/" && stream.eat("*")) {
9
  state.tokenize = tokenCComment;
10
  return tokenCComment(stream, state);
20
  return state.tokenize(stream, state);
21
  }
22
  else if (ch == "#") {
23
+ stream.eatWhile(/\w/);
24
  return ret("atom", "hash");
25
  }
26
  else if (ch == "!") {
38
  return ret(null, ch);
39
  }
40
  else {
41
+ stream.eatWhile(/[\w\\\-_]/);
42
  return ret("variable", "variable");
43
  }
44
  }
92
  var style = state.tokenize(stream, state);
93
 
94
  var context = state.stack[state.stack.length-1];
95
+ if (type == "hash" && context == "rule") style = "atom";
96
  else if (style == "variable") {
97
  if (context == "rule") style = "number";
98
  else if (!context || context == "@media{") style = "tag";
libraries/{CodeMirror2/mode/htmlmixed → codemirror/mode}/htmlmixed.js RENAMED
@@ -9,12 +9,10 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
9
  if (/^script$/i.test(state.htmlState.context.tagName)) {
10
  state.token = javascript;
11
  state.localState = jsMode.startState(htmlMode.indent(state.htmlState, ""));
12
- state.mode = "javascript";
13
  }
14
  else if (/^style$/i.test(state.htmlState.context.tagName)) {
15
  state.token = css;
16
  state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
17
- state.mode = "css";
18
  }
19
  }
20
  return style;
@@ -28,8 +26,7 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
28
  function javascript(stream, state) {
29
  if (stream.match(/^<\/\s*script\s*>/i, false)) {
30
  state.token = html;
31
- state.localState = null;
32
- state.mode = "html";
33
  return html(stream, state);
34
  }
35
  return maybeBackup(stream, /<\/\s*script\s*>/,
@@ -39,7 +36,6 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
39
  if (stream.match(/^<\/\s*style\s*>/i, false)) {
40
  state.token = html;
41
  state.localState = null;
42
- state.mode = "html";
43
  return html(stream, state);
44
  }
45
  return maybeBackup(stream, /<\/\s*style\s*>/,
@@ -49,14 +45,13 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
49
  return {
50
  startState: function() {
51
  var state = htmlMode.startState();
52
- return {token: html, localState: null, mode: "html", htmlState: state};
53
  },
54
 
55
  copyState: function(state) {
56
  if (state.localState)
57
  var local = CodeMirror.copyState(state.token == css ? cssMode : jsMode, state.localState);
58
- return {token: state.token, localState: local, mode: state.mode,
59
- htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
60
  },
61
 
62
  token: function(stream, state) {
@@ -72,14 +67,8 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
72
  return cssMode.indent(state.localState, textAfter);
73
  },
74
 
75
- compareStates: function(a, b) {
76
- if (a.mode != b.mode) return false;
77
- if (a.localState) return CodeMirror.Pass;
78
- return htmlMode.compareStates(a.htmlState, b.htmlState);
79
- },
80
-
81
  electricChars: "/{}:"
82
  }
83
- }, "xml", "javascript", "css");
84
 
85
  CodeMirror.defineMIME("text/html", "htmlmixed");
9
  if (/^script$/i.test(state.htmlState.context.tagName)) {
10
  state.token = javascript;
11
  state.localState = jsMode.startState(htmlMode.indent(state.htmlState, ""));
 
12
  }
13
  else if (/^style$/i.test(state.htmlState.context.tagName)) {
14
  state.token = css;
15
  state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
 
16
  }
17
  }
18
  return style;
26
  function javascript(stream, state) {
27
  if (stream.match(/^<\/\s*script\s*>/i, false)) {
28
  state.token = html;
29
+ state.curState = null;
 
30
  return html(stream, state);
31
  }
32
  return maybeBackup(stream, /<\/\s*script\s*>/,
36
  if (stream.match(/^<\/\s*style\s*>/i, false)) {
37
  state.token = html;
38
  state.localState = null;
 
39
  return html(stream, state);
40
  }
41
  return maybeBackup(stream, /<\/\s*style\s*>/,
45
  return {
46
  startState: function() {
47
  var state = htmlMode.startState();
48
+ return {token: html, localState: null, htmlState: state};
49
  },
50
 
51
  copyState: function(state) {
52
  if (state.localState)
53
  var local = CodeMirror.copyState(state.token == css ? cssMode : jsMode, state.localState);
54
+ return {token: state.token, localState: local, htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
 
55
  },
56
 
57
  token: function(stream, state) {
67
  return cssMode.indent(state.localState, textAfter);
68
  },
69
 
 
 
 
 
 
 
70
  electricChars: "/{}:"
71
  }
72
+ });
73
 
74
  CodeMirror.defineMIME("text/html", "htmlmixed");
libraries/{CodeMirror2/mode/javascript → codemirror/mode}/javascript.js RENAMED
@@ -11,8 +11,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
11
  return {
12
  "if": A, "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
13
  "return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C,
14
- "var": kw("var"), "const": kw("var"), "let": kw("var"),
15
- "function": kw("function"), "catch": kw("catch"),
16
  "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
17
  "in": operator, "typeof": operator, "instanceof": operator,
18
  "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom
@@ -52,11 +51,11 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
52
  return ret(ch);
53
  else if (ch == "0" && stream.eat(/x/i)) {
54
  stream.eatWhile(/[\da-f]/i);
55
- return ret("number", "number");
56
  }
57
- else if (/\d/.test(ch) || ch == "-" && stream.eat(/\d/)) {
58
- stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
59
- return ret("number", "number");
60
  }
61
  else if (ch == "/") {
62
  if (stream.eat("*")) {
@@ -69,17 +68,13 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
69
  else if (state.reAllowed) {
70
  nextUntilUnescaped(stream, "/");
71
  stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla
72
- return ret("regexp", "string-2");
73
  }
74
  else {
75
  stream.eatWhile(isOperatorChar);
76
  return ret("operator", null, stream.current());
77
  }
78
  }
79
- else if (ch == "#") {
80
- stream.skipToEnd();
81
- return ret("error", "error");
82
- }
83
  else if (isOperatorChar.test(ch)) {
84
  stream.eatWhile(isOperatorChar);
85
  return ret("operator", null, stream.current());
@@ -87,7 +82,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
87
  else {
88
  stream.eatWhile(/[\w\$_]/);
89
  var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
90
- return (known && state.kwAllowed) ? ret(known.type, known.style, word) :
91
  ret("variable", "variable", word);
92
  }
93
  }
@@ -229,21 +224,16 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
229
  function expression(type) {
230
  if (atomicTypes.hasOwnProperty(type)) return cont(maybeoperator);
231
  if (type == "function") return cont(functiondef);
232
- if (type == "keyword c") return cont(maybeexpression);
233
- if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeoperator);
234
  if (type == "operator") return cont(expression);
235
  if (type == "[") return cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
236
  if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator);
237
  return cont();
238
  }
239
- function maybeexpression(type) {
240
- if (type.match(/[;\}\)\],]/)) return pass();
241
- return pass(expression);
242
- }
243
-
244
  function maybeoperator(type, value) {
245
  if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator);
246
- if (type == "operator" || type == ":") return cont(expression);
247
  if (type == ";") return;
248
  if (type == "(") return cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator);
249
  if (type == ".") return cont(property, maybeoperator);
@@ -316,11 +306,10 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
316
  return {
317
  tokenize: jsTokenBase,
318
  reAllowed: true,
319
- kwAllowed: true,
320
  cc: [],
321
  lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
322
- localVars: parserConfig.localVars,
323
- context: parserConfig.localVars && {vars: parserConfig.localVars},
324
  indented: 0
325
  };
326
  },
@@ -334,16 +323,14 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
334
  if (stream.eatSpace()) return null;
335
  var style = state.tokenize(stream, state);
336
  if (type == "comment") return style;
337
- state.reAllowed = !!(type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/));
338
- state.kwAllowed = type != '.';
339
  return parseJS(state, style, type, content, stream);
340
  },
341
 
342
  indent: function(state, textAfter) {
343
  if (state.tokenize != jsTokenBase) return 0;
344
- var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical;
345
- if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev;
346
- var type = lexical.type, closing = firstChar == type;
347
  if (type == "vardef") return lexical.indented + 4;
348
  else if (type == "form" && firstChar == "{") return lexical.indented;
349
  else if (type == "stat" || type == "form") return lexical.indented + indentUnit;
11
  return {
12
  "if": A, "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
13
  "return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C,
14
+ "var": kw("var"), "function": kw("function"), "catch": kw("catch"),
 
15
  "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
16
  "in": operator, "typeof": operator, "instanceof": operator,
17
  "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom
51
  return ret(ch);
52
  else if (ch == "0" && stream.eat(/x/i)) {
53
  stream.eatWhile(/[\da-f]/i);
54
+ return ret("number", "atom");
55
  }
56
+ else if (/\d/.test(ch)) {
57
+ stream.match(/^\d*(?:\.\d*)?(?:e[+\-]?\d+)?/);
58
+ return ret("number", "atom");
59
  }
60
  else if (ch == "/") {
61
  if (stream.eat("*")) {
68
  else if (state.reAllowed) {
69
  nextUntilUnescaped(stream, "/");
70
  stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla
71
+ return ret("regexp", "string");
72
  }
73
  else {
74
  stream.eatWhile(isOperatorChar);
75
  return ret("operator", null, stream.current());
76
  }
77
  }
 
 
 
 
78
  else if (isOperatorChar.test(ch)) {
79
  stream.eatWhile(isOperatorChar);
80
  return ret("operator", null, stream.current());
82
  else {
83
  stream.eatWhile(/[\w\$_]/);
84
  var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
85
+ return known ? ret(known.type, known.style, word) :
86
  ret("variable", "variable", word);
87
  }
88
  }
224
  function expression(type) {
225
  if (atomicTypes.hasOwnProperty(type)) return cont(maybeoperator);
226
  if (type == "function") return cont(functiondef);
227
+ if (type == "keyword c") return cont(expression);
228
+ if (type == "(") return cont(pushlex(")"), expression, expect(")"), poplex, maybeoperator);
229
  if (type == "operator") return cont(expression);
230
  if (type == "[") return cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
231
  if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator);
232
  return cont();
233
  }
 
 
 
 
 
234
  function maybeoperator(type, value) {
235
  if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator);
236
+ if (type == "operator") return cont(expression);
237
  if (type == ";") return;
238
  if (type == "(") return cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator);
239
  if (type == ".") return cont(property, maybeoperator);
306
  return {
307
  tokenize: jsTokenBase,
308
  reAllowed: true,
 
309
  cc: [],
310
  lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
311
+ localVars: null,
312
+ context: null,
313
  indented: 0
314
  };
315
  },
323
  if (stream.eatSpace()) return null;
324
  var style = state.tokenize(stream, state);
325
  if (type == "comment") return style;
326
+ state.reAllowed = type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/);
 
327
  return parseJS(state, style, type, content, stream);
328
  },
329
 
330
  indent: function(state, textAfter) {
331
  if (state.tokenize != jsTokenBase) return 0;
332
+ var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical,
333
+ type = lexical.type, closing = firstChar == type;
 
334
  if (type == "vardef") return lexical.indented + 4;
335
  else if (type == "form" && firstChar == "{") return lexical.indented;
336
  else if (type == "stat" || type == "form") return lexical.indented + indentUnit;
libraries/codemirror/mode/xml.js ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CodeMirror.defineMode("xml", function(config, parserConfig) {
2
+ var indentUnit = config.indentUnit;
3
+ var Kludges = parserConfig.htmlMode ? {
4
+ autoSelfClosers: {"br": true, "img": true, "hr": true, "link": true, "input": true,
5
+ "meta": true, "col": true, "frame": true, "base": true, "area": true},
6
+ doNotIndent: {"pre": true, "!cdata": true},
7
+ allowUnquoted: true
8
+ } : {autoSelfClosers: {}, doNotIndent: {"!cdata": true}, allowUnquoted: false};
9
+ var alignCDATA = parserConfig.alignCDATA;
10
+
11
+ // Return variables for tokenizers
12
+ var tagName, type;
13
+
14
+ function inText(stream, state) {
15
+ function chain(parser) {
16
+ state.tokenize = parser;
17
+ return parser(stream, state);
18
+ }
19
+
20
+ var ch = stream.next();
21
+ if (ch == "<") {
22
+ if (stream.eat("!")) {
23
+ if (stream.eat("[")) {
24
+ if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
25
+ else return null;
26
+ }
27
+ else if (stream.match("--")) return chain(inBlock("comment", "-->"));
28
+ else if (stream.match("DOCTYPE")) {
29
+ stream.eatWhile(/[\w\._\-]/);
30
+ return chain(inBlock("meta", ">"));
31
+ }
32
+ else return null;
33
+ }
34
+ else if (stream.eat("?")) {
35
+ stream.eatWhile(/[\w\._\-]/);
36
+ state.tokenize = inBlock("meta", "?>");
37
+ return "meta";
38
+ }
39
+ else {
40
+ type = stream.eat("/") ? "closeTag" : "openTag";
41
+ stream.eatSpace();
42
+ tagName = "";
43
+ var c;
44
+ while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
45
+ state.tokenize = inTag;
46
+ return "tag";
47
+ }
48
+ }
49
+ else if (ch == "&") {
50
+ stream.eatWhile(/[^;]/);
51
+ stream.eat(";");
52
+ return "atom";
53
+ }
54
+ else {
55
+ stream.eatWhile(/[^&<]/);
56
+ return null;
57
+ }
58
+ }
59
+
60
+ function inTag(stream, state) {
61
+ var ch = stream.next();
62
+ if (ch == ">" || (ch == "/" && stream.eat(">"))) {
63
+ state.tokenize = inText;
64
+ type = ch == ">" ? "endTag" : "selfcloseTag";
65
+ return "tag";
66
+ }
67
+ else if (ch == "=") {
68
+ type = "equals";
69
+ return null;
70
+ }
71
+ else if (/[\'\"]/.test(ch)) {
72
+ state.tokenize = inAttribute(ch);
73
+ return state.tokenize(stream, state);
74
+ }
75
+ else {
76
+ stream.eatWhile(/[^\s\u00a0=<>\"\'\/?]/);
77
+ return "word";
78
+ }
79
+ }
80
+
81
+ function inAttribute(quote) {
82
+ return function(stream, state) {
83
+ while (!stream.eol()) {
84
+ if (stream.next() == quote) {
85
+ state.tokenize = inTag;
86
+ break;
87
+ }
88
+ }
89
+ return "string";
90
+ };
91
+ }
92
+
93
+ function inBlock(style, terminator) {
94
+ return function(stream, state) {
95
+ while (!stream.eol()) {
96
+ if (stream.match(terminator)) {
97
+ state.tokenize = inText;
98
+ break;
99
+ }
100
+ stream.next();
101
+ }
102
+ return style;
103
+ };
104
+ }
105
+
106
+ var curState, setStyle;
107
+ function pass() {
108
+ for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
109
+ }
110
+ function cont() {
111
+ pass.apply(null, arguments);
112
+ return true;
113
+ }
114
+
115
+ function pushContext(tagName, startOfLine) {
116
+ var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent);
117
+ curState.context = {
118
+ prev: curState.context,
119
+ tagName: tagName,
120
+ indent: curState.indented,
121
+ startOfLine: startOfLine,
122
+ noIndent: noIndent
123
+ };
124
+ }
125
+ function popContext() {
126
+ if (curState.context) curState.context = curState.context.prev;
127
+ }
128
+
129
+ function element(type) {
130
+ if (type == "openTag") {curState.tagName = tagName; return cont(attributes, endtag(curState.startOfLine));}
131
+ else if (type == "closeTag") {popContext(); return cont(endclosetag);}
132
+ else if (type == "string") {
133
+ if (!curState.context || curState.context.name != "!cdata") pushContext("!cdata");
134
+ if (curState.tokenize == inText) popContext();
135
+ return cont();
136
+ }
137
+ else return cont();
138
+ }
139
+ function endtag(startOfLine) {
140
+ return function(type) {
141
+ if (type == "selfcloseTag" ||
142
+ (type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase())))
143
+ return cont();
144
+ if (type == "endTag") {pushContext(curState.tagName, startOfLine); return cont();}
145
+ return cont();
146
+ };
147
+ }
148
+ function endclosetag(type) {
149
+ if (type == "endTag") return cont();
150
+ return pass();
151
+ }
152
+
153
+ function attributes(type) {
154
+ if (type == "word") {setStyle = "attribute"; return cont(attributes);}
155
+ if (type == "equals") return cont(attvalue, attributes);
156
+ return pass();
157
+ }
158
+ function attvalue(type) {
159
+ if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();}
160
+ if (type == "string") return cont();
161
+ return pass();
162
+ }
163
+
164
+ return {
165
+ startState: function() {
166
+ return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null};
167
+ },
168
+
169
+ token: function(stream, state) {
170
+ if (stream.sol()) {
171
+ state.startOfLine = true;
172
+ state.indented = stream.indentation();
173
+ }
174
+ if (stream.eatSpace()) return null;
175
+
176
+ setStyle = type = tagName = null;
177
+ var style = state.tokenize(stream, state);
178
+ if ((style || type) && style != "xml-comment") {
179
+ curState = state;
180
+ while (true) {
181
+ var comb = state.cc.pop() || element;
182
+ if (comb(type || style)) break;
183
+ }
184
+ }
185
+ state.startOfLine = false;
186
+ return setStyle || style;
187
+ },
188
+
189
+ indent: function(state, textAfter) {
190
+ var context = state.context;
191
+ if (context && context.noIndent) return 0;
192
+ if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
193
+ if (context && /^<\//.test(textAfter))
194
+ context = context.prev;
195
+ while (context && !context.startOfLine)
196
+ context = context.prev;
197
+ if (context) return context.indent + indentUnit;
198
+ else return 0;
199
+ },
200
+
201
+ electricChars: "/"
202
+ };
203
+ });
204
+
205
+ CodeMirror.defineMIME("application/xml", "xml");
206
+ CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
libraries/codemirror/theme/default.css ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .cm-s-default span.cm-keyword {color: #708;}
2
+ .cm-s-default span.cm-atom {color: #219;}
3
+ .cm-s-default span.cm-number {color: #164;}
4
+ .cm-s-default span.cm-def {color: #00f;}
5
+ .cm-s-default span.cm-variable {color: black;}
6
+ .cm-s-default span.cm-variable-2 {color: #05a;}
7
+ .cm-s-default span.cm-variable-3 {color: #0a5;}
8
+ .cm-s-default span.cm-property {color: black;}
9
+ .cm-s-default span.cm-operator {color: black;}
10
+ .cm-s-default span.cm-comment {color: #a50;}
11
+ .cm-s-default span.cm-string {color: #a11;}
12
+ .cm-s-default span.cm-meta {color: #555;}
13
+ .cm-s-default span.cm-error {color: #f00;}
14
+ .cm-s-default span.cm-qualifier {color: #555;}
15
+ .cm-s-default span.cm-builtin {color: #30a;}
16
+ .cm-s-default span.cm-bracket {color: #cc7;}
17
+ .cm-s-default span.cm-tag {color: #170;}
18
+ .cm-s-default span.cm-attribute {color: #00c;}
libraries/{CodeMirror2 → codemirror}/theme/elegant.css RENAMED
@@ -1,10 +1,9 @@
1
  .cm-s-elegant span.cm-number, .cm-s-elegant span.cm-string, .cm-s-elegant span.cm-atom {color: #762;}
2
- .cm-s-elegant span.cm-comment {color: #262; font-style: italic; line-height: 1em;}
3
- .cm-s-elegant span.cm-meta {color: #555; font-style: italic; line-height: 1em;}
4
  .cm-s-elegant span.cm-variable {color: black;}
5
  .cm-s-elegant span.cm-variable-2 {color: #b11;}
6
  .cm-s-elegant span.cm-qualifier {color: #555;}
7
  .cm-s-elegant span.cm-keyword {color: #730;}
8
  .cm-s-elegant span.cm-builtin {color: #30a;}
9
  .cm-s-elegant span.cm-error {background-color: #fdd;}
10
- .cm-s-elegant span.cm-link {color: #762;}
1
  .cm-s-elegant span.cm-number, .cm-s-elegant span.cm-string, .cm-s-elegant span.cm-atom {color: #762;}
2
+ .cm-s-elegant span.cm-comment {color: #262;font-style: italic;}
3
+ .cm-s-elegant span.cm-meta {color: #555;font-style: italic;}
4
  .cm-s-elegant span.cm-variable {color: black;}
5
  .cm-s-elegant span.cm-variable-2 {color: #b11;}
6
  .cm-s-elegant span.cm-qualifier {color: #555;}
7
  .cm-s-elegant span.cm-keyword {color: #730;}
8
  .cm-s-elegant span.cm-builtin {color: #30a;}
9
  .cm-s-elegant span.cm-error {background-color: #fdd;}
 
libraries/codemirror/theme/neat.css ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ .cm-s-neat span.cm-comment { color: #a86; }
2
+ .cm-s-neat span.cm-keyword { font-weight: bold; color: blue; }
3
+ .cm-s-neat span.cm-string { color: #a22; }
4
+ .cm-s-neat span.cm-builtin { font-weight: bold; color: #077; }
5
+ .cm-s-neat span.cm-special { font-weight: bold; color: #0aa; }
6
+ .cm-s-neat span.cm-variable { color: black; }
7
+ .cm-s-neat span.cm-number, .cm-s-neat span.cm-atom { color: #3a3; }
8
+ .cm-s-neat span.cm-meta {color: #555;}
libraries/{CodeMirror2 → codemirror}/theme/night.css RENAMED
@@ -1,21 +1,20 @@
1
  /* Loosely based on the Midnight Textmate theme */
2
 
3
  .cm-s-night { background: #0a001f; color: #f8f8f8; }
4
- .cm-s-night div.CodeMirror-selected { background: #a8f !important; }
5
  .cm-s-night .CodeMirror-gutter { background: #0a001f; border-right: 1px solid #aaa; }
6
  .cm-s-night .CodeMirror-gutter-text { color: #f8f8f8; }
7
  .cm-s-night .CodeMirror-cursor { border-left: 1px solid white !important; }
8
 
9
  .cm-s-night span.cm-comment { color: #6900a1; }
10
  .cm-s-night span.cm-atom { color: #845dc4; }
11
- .cm-s-night span.cm-number, .cm-s-night span.cm-attribute { color: #ffd500; }
12
  .cm-s-night span.cm-keyword { color: #599eff; }
13
  .cm-s-night span.cm-string { color: #37f14a; }
14
  .cm-s-night span.cm-meta { color: #7678e2; }
15
- .cm-s-night span.cm-variable-2, .cm-s-night span.cm-tag { color: #99b2ff; }
16
- .cm-s-night span.cm-variable-3, .cm-s-night span.cm-def { color: white; }
17
  .cm-s-night span.cm-error { color: #9d1e15; }
18
  .cm-s-night span.cm-bracket { color: #8da6ce; }
19
  .cm-s-night span.cm-comment { color: #6900a1; }
20
  .cm-s-night span.cm-builtin, .cm-s-night span.cm-special { color: #ff9e59; }
21
- .cm-s-night span.cm-link { color: #845dc4; }
1
  /* Loosely based on the Midnight Textmate theme */
2
 
3
  .cm-s-night { background: #0a001f; color: #f8f8f8; }
4
+ .cm-s-night span.CodeMirror-selected { background: #a8f !important; }
5
  .cm-s-night .CodeMirror-gutter { background: #0a001f; border-right: 1px solid #aaa; }
6
  .cm-s-night .CodeMirror-gutter-text { color: #f8f8f8; }
7
  .cm-s-night .CodeMirror-cursor { border-left: 1px solid white !important; }
8
 
9
  .cm-s-night span.cm-comment { color: #6900a1; }
10
  .cm-s-night span.cm-atom { color: #845dc4; }
11
+ .cm-s-night span.cm-number { color: #ffd500; }
12
  .cm-s-night span.cm-keyword { color: #599eff; }
13
  .cm-s-night span.cm-string { color: #37f14a; }
14
  .cm-s-night span.cm-meta { color: #7678e2; }
15
+ .cm-s-night span.cm-variable-2 { color: #99b2ff; }
16
+ .cm-s-night span.cm-variable-3, .cm-s-night span.cm-def { white; }
17
  .cm-s-night span.cm-error { color: #9d1e15; }
18
  .cm-s-night span.cm-bracket { color: #8da6ce; }
19
  .cm-s-night span.cm-comment { color: #6900a1; }
20
  .cm-s-night span.cm-builtin, .cm-s-night span.cm-special { color: #ff9e59; }
 
libraries/less/LICENSE DELETED
@@ -1,179 +0,0 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding those notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- Copyright (c) 2009-2010 Alexis Sellier
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/less/dist/less-1.3.0.js DELETED
@@ -1,3478 +0,0 @@
1
- //
2
- // LESS - Leaner CSS v1.3.0
3
- // http://lesscss.org
4
- //
5
- // Copyright (c) 2009-2011, Alexis Sellier
6
- // Licensed under the Apache 2.0 License.
7
- //
8
- (function (window, undefined) {
9
- //
10
- // Stub out `require` in the browser
11
- //
12
- function require(arg) {
13
- return window.less[arg.split('/')[1]];
14
- };
15
-
16
- // amd.js
17
- //
18
- // Define Less as an AMD module.
19
- if (typeof define === "function" && define.amd) {
20
- define("less", [], function () { return less; } );
21
- }
22
-
23
- // ecma-5.js
24
- //
25
- // -- kriskowal Kris Kowal Copyright (C) 2009-2010 MIT License
26
- // -- tlrobinson Tom Robinson
27
- // dantman Daniel Friesen
28
-
29
- //
30
- // Array
31
- //
32
- if (!Array.isArray) {
33
- Array.isArray = function(obj) {
34
- return Object.prototype.toString.call(obj) === "[object Array]" ||
35
- (obj instanceof Array);
36
- };
37
- }
38
- if (!Array.prototype.forEach) {
39
- Array.prototype.forEach = function(block, thisObject) {
40
- var len = this.length >>> 0;
41
- for (var i = 0; i < len; i++) {
42
- if (i in this) {
43
- block.call(thisObject, this[i], i, this);
44
- }
45
- }
46
- };
47
- }
48
- if (!Array.prototype.map) {
49
- Array.prototype.map = function(fun /*, thisp*/) {
50
- var len = this.length >>> 0;
51
- var res = new Array(len);
52
- var thisp = arguments[1];
53
-
54
- for (var i = 0; i < len; i++) {
55
- if (i in this) {
56
- res[i] = fun.call(thisp, this[i], i, this);
57
- }
58
- }
59
- return res;
60
- };
61
- }
62
- if (!Array.prototype.filter) {
63
- Array.prototype.filter = function (block /*, thisp */) {
64
- var values = [];
65
- var thisp = arguments[1];
66
- for (var i = 0; i < this.length; i++) {
67
- if (block.call(thisp, this[i])) {
68
- values.push(this[i]);
69
- }
70
- }
71
- return values;
72
- };
73
- }
74
- if (!Array.prototype.reduce) {
75
- Array.prototype.reduce = function(fun /*, initial*/) {
76
- var len = this.length >>> 0;
77
- var i = 0;
78
-
79
- // no value to return if no initial value and an empty array
80
- if (len === 0 && arguments.length === 1) throw new TypeError();
81
-
82
- if (arguments.length >= 2) {
83
- var rv = arguments[1];
84
- } else {
85
- do {
86
- if (i in this) {
87
- rv = this[i++];
88
- break;
89
- }
90
- // if array contains no values, no initial value to return
91
- if (++i >= len) throw new TypeError();
92
- } while (true);
93
- }
94
- for (; i < len; i++) {
95
- if (i in this) {
96
- rv = fun.call(null, rv, this[i], i, this);
97
- }
98
- }
99
- return rv;
100
- };
101
- }
102
- if (!Array.prototype.indexOf) {
103
- Array.prototype.indexOf = function (value /*, fromIndex */ ) {
104
- var length = this.length;
105
- var i = arguments[1] || 0;
106
-
107
- if (!length) return -1;
108
- if (i >= length) return -1;
109
- if (i < 0) i += length;
110
-
111
- for (; i < length; i++) {
112
- if (!Object.prototype.hasOwnProperty.call(this, i)) { continue }
113
- if (value === this[i]) return i;
114
- }
115
- return -1;
116
- };
117
- }
118
-
119
- //
120
- // Object
121
- //
122
- if (!Object.keys) {
123
- Object.keys = function (object) {
124
- var keys = [];
125
- for (var name in object) {
126
- if (Object.prototype.hasOwnProperty.call(object, name)) {
127
- keys.push(name);
128
- }
129
- }
130
- return keys;
131
- };
132
- }
133
-
134
- //
135
- // String
136
- //
137
- if (!String.prototype.trim) {
138
- String.prototype.trim = function () {
139
- return String(this).replace(/^\s\s*/, '').replace(/\s\s*$/, '');
140
- };
141
- }
142
- var less, tree;
143
-
144
- if (typeof environment === "object" && ({}).toString.call(environment) === "[object Environment]") {
145
- // Rhino
146
- // Details on how to detect Rhino: https://github.com/ringo/ringojs/issues/88
147
- if (typeof(window) === 'undefined') { less = {} }
148
- else { less = window.less = {} }
149
- tree = less.tree = {};
150
- less.mode = 'rhino';
151
- } else if (typeof(window) === 'undefined') {
152
- // Node.js
153
- less = exports,
154
- tree = require('./tree');
155
- less.mode = 'node';
156
- } else {
157
- // Browser
158
- if (typeof(window.less) === 'undefined') { window.less = {} }
159
- less = window.less,
160
- tree = window.less.tree = {};
161
- less.mode = 'browser';
162
- }
163
- //
164
- // less.js - parser
165
- //
166
- // A relatively straight-forward predictive parser.
167
- // There is no tokenization/lexing stage, the input is parsed
168
- // in one sweep.
169
- //
170
- // To make the parser fast enough to run in the browser, several
171
- // optimization had to be made:
172
- //
173
- // - Matching and slicing on a huge input is often cause of slowdowns.
174
- // The solution is to chunkify the input into smaller strings.
175
- // The chunks are stored in the `chunks` var,
176
- // `j` holds the current chunk index, and `current` holds
177
- // the index of the current chunk in relation to `input`.
178
- // This gives us an almost 4x speed-up.
179
- //
180
- // - In many cases, we don't need to match individual tokens;
181
- // for example, if a value doesn't hold any variables, operations
182
- // or dynamic references, the parser can effectively 'skip' it,
183
- // treating it as a literal.
184
- // An example would be '1px solid #000' - which evaluates to itself,
185
- // we don't need to know what the individual components are.
186
- // The drawback, of course is that you don't get the benefits of
187
- // syntax-checking on the CSS. This gives us a 50% speed-up in the parser,
188
- // and a smaller speed-up in the code-gen.
189
- //
190
- //
191
- // Token matching is done with the `$` function, which either takes
192
- // a terminal string or regexp, or a non-terminal function to call.
193
- // It also takes care of moving all the indices forwards.
194
- //
195
- //
196
- less.Parser = function Parser(env) {
197
- var input, // LeSS input string
198
- i, // current index in `input`
199
- j, // current chunk
200
- temp, // temporarily holds a chunk's state, for backtracking
201
- memo, // temporarily holds `i`, when backtracking
202
- furthest, // furthest index the parser has gone to
203
- chunks, // chunkified input
204
- current, // index of current chunk, in `input`
205
- parser;
206
-
207
- var that = this;
208
-
209
- // This function is called after all files
210
- // have been imported through `@import`.
211
- var finish = function () {};
212
-
213
- var imports = this.imports = {
214
- paths: env && env.paths || [], // Search paths, when importing
215
- queue: [], // Files which haven't been imported yet
216
- files: {}, // Holds the imported parse trees
217
- contents: {}, // Holds the imported file contents
218
- mime: env && env.mime, // MIME type of .less files
219
- error: null, // Error in parsing/evaluating an import
220
- push: function (path, callback) {
221
- var that = this;
222
- this.queue.push(path);
223
-
224
- //
225
- // Import a file asynchronously
226
- //
227
- less.Parser.importer(path, this.paths, function (e, root, contents) {
228
- that.queue.splice(that.queue.indexOf(path), 1); // Remove the path from the queue
229
- that.files[path] = root; // Store the root
230
- that.contents[path] = contents;
231
-
232
- if (e && !that.error) { that.error = e }
233
- callback(e, root);
234
-
235
- if (that.queue.length === 0) { finish() } // Call `finish` if we're done importing
236
- }, env);
237
- }
238
- };
239
-
240
- function save() { temp = chunks[j], memo = i, current = i }
241
- function restore() { chunks[j] = temp, i = memo, current = i }
242
-
243
- function sync() {
244
- if (i > current) {
245
- chunks[j] = chunks[j].slice(i - current);
246
- current = i;
247
- }
248
- }
249
- //
250
- // Parse from a token, regexp or string, and move forward if match
251
- //
252
- function $(tok) {
253
- var match, args, length, c, index, endIndex, k, mem;
254
-
255
- //
256
- // Non-terminal
257
- //
258
- if (tok instanceof Function) {
259
- return tok.call(parser.parsers);
260
- //
261
- // Terminal
262
- //
263
- // Either match a single character in the input,
264
- // or match a regexp in the current chunk (chunk[j]).
265
- //
266
- } else if (typeof(tok) === 'string') {
267
- match = input.charAt(i) === tok ? tok : null;
268
- length = 1;
269
- sync ();
270
- } else {
271
- sync ();
272
-
273
- if (match = tok.exec(chunks[j])) {
274
- length = match[0].length;
275
- } else {
276
- return null;
277
- }
278
- }
279
-
280
- // The match is confirmed, add the match length to `i`,
281
- // and consume any extra white-space characters (' ' || '\n')
282
- // which come after that. The reason for this is that LeSS's
283
- // grammar is mostly white-space insensitive.
284
- //
285
- if (match) {
286
- mem = i += length;
287
- endIndex = i + chunks[j].length - length;
288
-
289
- while (i < endIndex) {
290
- c = input.charCodeAt(i);
291
- if (! (c === 32 || c === 10 || c === 9)) { break }
292
- i++;
293
- }
294
- chunks[j] = chunks[j].slice(length + (i - mem));
295
- current = i;
296
-
297
- if (chunks[j].length === 0 && j < chunks.length - 1) { j++ }
298
-
299
- if(typeof(match) === 'string') {
300
- return match;
301
- } else {
302
- return match.length === 1 ? match[0] : match;
303
- }
304
- }
305
- }
306
-
307
- function expect(arg, msg) {
308
- var result = $(arg);
309
- if (! result) {
310
- error(msg || (typeof(arg) === 'string' ? "expected '" + arg + "' got '" + input.charAt(i) + "'"
311
- : "unexpected token"));
312
- } else {
313
- return result;
314
- }
315
- }
316
-
317
- function error(msg, type) {
318
- throw { index: i, type: type || 'Syntax', message: msg };
319
- }
320
-
321
- // Same as $(), but don't change the state of the parser,
322
- // just return the match.
323
- function peek(tok) {
324
- if (typeof(tok) === 'string') {
325
- return input.charAt(i) === tok;
326
- } else {
327
- if (tok.test(chunks[j])) {
328
- return true;
329
- } else {
330
- return false;
331
- }
332
- }
333
- }
334
-
335
- function basename(pathname) {
336
- if (less.mode === 'node') {
337
- return require('path').basename(pathname);
338
- } else {
339
- return pathname.match(/[^\/]+$/)[0];
340
- }
341
- }
342
-
343
- function getInput(e, env) {
344
- if (e.filename && env.filename && (e.filename !== env.filename)) {
345
- return parser.imports.contents[basename(e.filename)];
346
- } else {
347
- return input;
348
- }
349
- }
350
-
351
- function getLocation(index, input) {
352
- for (var n = index, column = -1;
353
- n >= 0 && input.charAt(n) !== '\n';
354
- n--) { column++ }
355
-
356
- return { line: typeof(index) === 'number' ? (input.slice(0, index).match(/\n/g) || "").length : null,
357
- column: column };
358
- }
359
-
360
- function LessError(e, env) {
361
- var input = getInput(e, env),
362
- loc = getLocation(e.index, input),
363
- line = loc.line,
364
- col = loc.column,
365
- lines = input.split('\n');
366
-
367
- this.type = e.type || 'Syntax';
368
- this.message = e.message;
369
- this.filename = e.filename || env.filename;
370
- this.index = e.index;
371
- this.line = typeof(line) === 'number' ? line + 1 : null;
372
- this.callLine = e.call && (getLocation(e.call, input).line + 1);
373
- this.callExtract = lines[getLocation(e.call, input).line];
374
- this.stack = e.stack;
375
- this.column = col;
376
- this.extract = [
377
- lines[line - 1],
378
- lines[line],
379
- lines[line + 1]
380
- ];
381
- }
382
-
383
- this.env = env = env || {};
384
-
385
- // The optimization level dictates the thoroughness of the parser,
386
- // the lower the number, the less nodes it will create in the tree.
387
- // This could matter for debugging, or if you want to access
388
- // the individual nodes in the tree.
389
- this.optimization = ('optimization' in this.env) ? this.env.optimization : 1;
390
-
391
- this.env.filename = this.env.filename || null;
392
-
393
- //
394
- // The Parser
395
- //
396
- return parser = {
397
-
398
- imports: imports,
399
- //
400
- // Parse an input string into an abstract syntax tree,
401
- // call `callback` when done.
402
- //
403
- parse: function (str, callback) {
404
- var root, start, end, zone, line, lines, buff = [], c, error = null;
405
-
406
- i = j = current = furthest = 0;
407
- input = str.replace(/\r\n/g, '\n');
408
-
409
- // Split the input into chunks.
410
- chunks = (function (chunks) {
411
- var j = 0,
412
- skip = /[^"'`\{\}\/\(\)\\]+/g,
413
- comment = /\/\*(?:[^*]|\*+[^\/*])*\*+\/|\/\/.*/g,
414
- string = /"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'|`((?:[^`\\\r\n]|\\.)*)`/g,
415
- level = 0,
416
- match,
417
- chunk = chunks[0],
418
- inParam;
419
-
420
- for (var i = 0, c, cc; i < input.length; i++) {
421
- skip.lastIndex = i;
422
- if (match = skip.exec(input)) {
423
- if (match.index === i) {
424
- i += match[0].length;
425
- chunk.push(match[0]);
426
- }
427
- }
428
- c = input.charAt(i);
429
- comment.lastIndex = string.lastIndex = i;
430
-
431
- if (match = string.exec(input)) {
432
- if (match.index === i) {
433
- i += match[0].length;
434
- chunk.push(match[0]);
435
- c = input.charAt(i);
436
- }
437
- }
438
-
439
- if (!inParam && c === '/') {
440
- cc = input.charAt(i + 1);
441
- if (cc === '/' || cc === '*') {
442
- if (match = comment.exec(input)) {
443
- if (match.index === i) {
444
- i += match[0].length;
445
- chunk.push(match[0]);
446
- c = input.charAt(i);
447
- }
448
- }
449
- }
450
- }
451
-
452
- switch (c) {
453
- case '{': if (! inParam) { level ++; chunk.push(c); break }
454
- case '}': if (! inParam) { level --; chunk.push(c); chunks[++j] = chunk = []; break }
455
- case '(': if (! inParam) { inParam = true; chunk.push(c); break }
456
- case ')': if ( inParam) { inParam = false; chunk.push(c); break }
457
- default: chunk.push(c);
458
- }
459
- }
460
- if (level > 0) {
461
- error = new(LessError)({
462
- index: i,
463
- type: 'Parse',
464
- message: "missing closing `}`",
465
- filename: env.filename
466
- }, env);
467
- }
468
-
469
- return chunks.map(function (c) { return c.join('') });;
470
- })([[]]);
471
-
472
- if (error) {
473
- return callback(error);
474
- }
475
-
476
- // Start with the primary rule.
477
- // The whole syntax tree is held under a Ruleset node,
478
- // with the `root` property set to true, so no `{}` are
479
- // output. The callback is called when the input is parsed.
480
- try {
481
- root = new(tree.Ruleset)([], $(this.parsers.primary));
482
- root.root = true;
483
- } catch (e) {
484
- return callback(new(LessError)(e, env));
485
- }
486
-
487
- root.toCSS = (function (evaluate) {
488
- var line, lines, column;
489
-
490
- return function (options, variables) {
491
- var frames = [], importError;
492
-
493
- options = options || {};
494
- //
495
- // Allows setting variables with a hash, so:
496
- //
497
- // `{ color: new(tree.Color)('#f01') }` will become:
498
- //
499
- // new(tree.Rule)('@color',
500
- // new(tree.Value)([
501
- // new(tree.Expression)([
502
- // new(tree.Color)('#f01')
503
- // ])
504
- // ])
505
- // )
506
- //
507
- if (typeof(variables) === 'object' && !Array.isArray(variables)) {
508
- variables = Object.keys(variables).map(function (k) {
509
- var value = variables[k];
510
-
511
- if (! (value instanceof tree.Value)) {
512
- if (! (value instanceof tree.Expression)) {
513
- value = new(tree.Expression)([value]);
514
- }
515
- value = new(tree.Value)([value]);
516
- }
517
- return new(tree.Rule)('@' + k, value, false, 0);
518
- });
519
- frames = [new(tree.Ruleset)(null, variables)];
520
- }
521
-
522
- try {
523
- var css = evaluate.call(this, { frames: frames })
524
- .toCSS([], { compress: options.compress || false });
525
- } catch (e) {
526
- throw new(LessError)(e, env);
527
- }
528
-
529
- if ((importError = parser.imports.error)) { // Check if there was an error during importing
530
- if (importError instanceof LessError) throw importError;
531
- else throw new(LessError)(importError, env);
532
- }
533
-
534
- if (options.yuicompress && less.mode === 'node') {
535
- return require('./cssmin').compressor.cssmin(css);
536
- } else if (options.compress) {
537
- return css.replace(/(\s)+/g, "$1");
538
- } else {
539
- return css;
540
- }
541
- };
542
- })(root.eval);
543
-
544
- // If `i` is smaller than the `input.length - 1`,
545
- // it means the parser wasn't able to parse the whole
546
- // string, so we've got a parsing error.
547
- //
548
- // We try to extract a \n delimited string,
549
- // showing the line where the parse error occured.
550
- // We split it up into two parts (the part which parsed,
551
- // and the part which didn't), so we can color them differently.
552
- if (i < input.length - 1) {
553
- i = furthest;
554
- lines = input.split('\n');
555
- line = (input.slice(0, i).match(/\n/g) || "").length + 1;
556
-
557
- for (var n = i, column = -1; n >= 0 && input.charAt(n) !== '\n'; n--) { column++ }
558
-
559
- error = {
560
- type: "Parse",
561
- message: "Syntax Error on line " + line,
562
- index: i,
563
- filename: env.filename,
564
- line: line,
565
- column: column,
566
- extract: [
567
- lines[line - 2],
568
- lines[line - 1],
569
- lines[line]
570
- ]
571
- };
572
- }
573
-
574
- if (this.imports.queue.length > 0) {
575
- finish = function () { callback(error, root) };
576
- } else {
577
- callback(error, root);
578
- }
579
- },
580
-
581
- //
582
- // Here in, the parsing rules/functions
583
- //
584
- // The basic structure of the syntax tree generated is as follows:
585
- //
586
- // Ruleset -> Rule -> Value -> Expression -> Entity
587
- //
588
- // Here's some LESS code:
589
- //
590
- // .class {
591
- // color: #fff;
592
- // border: 1px solid #000;
593
- // width: @w + 4px;
594
- // > .child {...}
595
- // }
596
- //
597
- // And here's what the parse tree might look like:
598
- //
599
- // Ruleset (Selector '.class', [
600
- // Rule ("color", Value ([Expression [Color #fff]]))
601
- // Rule ("border", Value ([Expression [Dimension 1px][Keyword "solid"][Color #000]]))
602
- // Rule ("width", Value ([Expression [Operation "+" [Variable "@w"][Dimension 4px]]]))
603
- // Ruleset (Selector [Element '>', '.child'], [...])
604
- // ])
605
- //
606
- // In general, most rules will try to parse a token with the `$()` function, and if the return
607
- // value is truly, will return a new node, of the relevant type. Sometimes, we need to check
608
- // first, before parsing, that's when we use `peek()`.
609
- //
610
- parsers: {
611
- //
612
- // The `primary` rule is the *entry* and *exit* point of the parser.
613
- // The rules here can appear at any level of the parse tree.
614
- //
615
- // The recursive nature of the grammar is an interplay between the `block`
616
- // rule, which represents `{ ... }`, the `ruleset` rule, and this `primary` rule,
617
- // as represented by this simplified grammar:
618
- //
619
- // primary → (ruleset | rule)+
620
- // ruleset → selector+ block
621
- // block → '{' primary '}'
622
- //
623
- // Only at one point is the primary rule not called from the
624
- // block rule: at the root level.
625
- //
626
- primary: function () {
627
- var node, root = [];
628
-
629
- while ((node = $(this.mixin.definition) || $(this.rule) || $(this.ruleset) ||
630
- $(this.mixin.call) || $(this.comment) || $(this.directive))
631
- || $(/^[\s\n]+/)) {
632
- node && root.push(node);
633
- }
634
- return root;
635
- },
636
-
637
- // We create a Comment node for CSS comments `/* */`,
638
- // but keep the LeSS comments `//` silent, by just skipping
639
- // over them.
640
- comment: function () {
641
- var comment;
642
-
643
- if (input.charAt(i) !== '/') return;
644
-
645
- if (input.charAt(i + 1) === '/') {
646
- return new(tree.Comment)($(/^\/\/.*/), true);
647
- } else if (comment = $(/^\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/)) {
648
- return new(tree.Comment)(comment);
649
- }
650
- },
651
-
652
- //
653
- // Entities are tokens which can be found inside an Expression
654
- //
655
- entities: {
656
- //
657
- // A string, which supports escaping " and '
658
- //
659
- // "milky way" 'he\'s the one!'
660
- //
661
- quoted: function () {
662
- var str, j = i, e;
663
-
664
- if (input.charAt(j) === '~') { j++, e = true } // Escaped strings
665
- if (input.charAt(j) !== '"' && input.charAt(j) !== "'") return;
666
-
667
- e && $('~');
668
-
669
- if (str = $(/^"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'/)) {
670
- return new(tree.Quoted)(str[0], str[1] || str[2], e);
671
- }
672
- },
673
-
674
- //
675
- // A catch-all word, such as:
676
- //
677
- // black border-collapse
678
- //
679
- keyword: function () {
680
- var k;
681
-
682
- if (k = $(/^[_A-Za-z-][_A-Za-z0-9-]*/)) {
683
- if (tree.colors.hasOwnProperty(k)) {
684
- // detect named color
685
- return new(tree.Color)(tree.colors[k].slice(1));
686
- } else {
687
- return new(tree.Keyword)(k);
688
- }
689
- }
690
- },
691
-
692
- //
693
- // A function call
694
- //
695
- // rgb(255, 0, 255)
696
- //
697
- // We also try to catch IE's `alpha()`, but let the `alpha` parser
698
- // deal with the details.
699
- //
700
- // The arguments are parsed with the `entities.arguments` parser.
701
- //
702
- call: function () {
703
- var name, args, index = i;
704
-
705
- if (! (name = /^([\w-]+|%|progid:[\w\.]+)\(/.exec(chunks[j]))) return;
706
-
707
- name = name[1].toLowerCase();
708
-
709
- if (name === 'url') { return null }
710
- else { i += name.length }
711
-
712
- if (name === 'alpha') { return $(this.alpha) }
713
-
714
- $('('); // Parse the '(' and consume whitespace.
715
-
716
- args = $(this.entities.arguments);
717
-
718
- if (! $(')')) return;
719
-
720
- if (name) { return new(tree.Call)(name, args, index, env.filename) }
721
- },
722
- arguments: function () {
723
- var args = [], arg;
724
-
725
- while (arg = $(this.entities.assignment) || $(this.expression)) {
726
- args.push(arg);
727
- if (! $(',')) { break }
728
- }
729
- return args;
730
- },
731
- literal: function () {
732
- return $(this.entities.dimension) ||
733
- $(this.entities.color) ||
734
- $(this.entities.quoted);
735
- },
736
-
737
- // Assignments are argument entities for calls.
738
- // They are present in ie filter properties as shown below.
739
- //
740
- // filter: progid:DXImageTransform.Microsoft.Alpha( *opacity=50* )
741
- //
742
-
743
- assignment: function () {
744
- var key, value;
745
- if ((key = $(/^\w+(?=\s?=)/i)) && $('=') && (value = $(this.entity))) {
746
- return new(tree.Assignment)(key, value);
747
- }
748
- },
749
-
750
- //
751
- // Parse url() tokens
752
- //
753
- // We use a specific rule for urls, because they don't really behave like
754
- // standard function calls. The difference is that the argument doesn't have
755
- // to be enclosed within a string, so it can't be parsed as an Expression.
756
- //
757
- url: function () {
758
- var value;
759
-
760
- if (input.charAt(i) !== 'u' || !$(/^url\(/)) return;
761
- value = $(this.entities.quoted) || $(this.entities.variable) ||
762
- $(this.entities.dataURI) || $(/^[-\w%@$\/.&=:;#+?~]+/) || "";
763
-
764
- expect(')');
765
-
766
- return new(tree.URL)((value.value || value.data || value instanceof tree.Variable)
767
- ? value : new(tree.Anonymous)(value), imports.paths);
768
- },
769
-
770
- dataURI: function () {
771
- var obj;
772
-
773
- if ($(/^data:/)) {
774
- obj = {};
775
- obj.mime = $(/^[^\/]+\/[^,;)]+/) || '';
776
- obj.charset = $(/^;\s*charset=[^,;)]+/) || '';
777
- obj.base64 = $(/^;\s*base64/) || '';
778
- obj.data = $(/^,\s*[^)]+/);
779
-
780
- if (obj.data) { return obj }
781
- }
782
- },
783
-
784
- //
785
- // A Variable entity, such as `@fink`, in
786
- //
787
- // width: @fink + 2px
788
- //
789
- // We use a different parser for variable definitions,
790
- // see `parsers.variable`.
791
- //
792
- variable: function () {
793
- var name, index = i;
794
-
795
- if (input.charAt(i) === '@' && (name = $(/^@@?[\w-]+/))) {
796
- return new(tree.Variable)(name, index, env.filename);
797
- }
798
- },
799
-
800
- //
801
- // A Hexadecimal color
802
- //
803
- // #4F3C2F
804
- //
805
- // `rgb` and `hsl` colors are parsed through the `entities.call` parser.
806
- //
807
- color: function () {
808
- var rgb;
809
-
810
- if (input.charAt(i) === '#' && (rgb = $(/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})/))) {
811
- return new(tree.Color)(rgb[1]);
812
- }
813
- },
814
-
815
- //
816
- // A Dimension, that is, a number and a unit
817
- //
818
- // 0.5em 95%
819
- //
820
- dimension: function () {
821
- var value, c = input.charCodeAt(i);
822
- if ((c > 57 || c < 45) || c === 47) return;
823
-
824
- if (value = $(/^(-?\d*\.?\d+)(px|%|em|rem|pc|ex|in|deg|s|ms|pt|cm|mm|rad|grad|turn)?/)) {
825
- return new(tree.Dimension)(value[1], value[2]);
826
- }
827
- },
828
-
829
- //
830
- // JavaScript code to be evaluated
831
- //
832
- // `window.location.href`
833
- //
834
- javascript: function () {
835
- var str, j = i, e;
836
-
837
- if (input.charAt(j) === '~') { j++, e = true } // Escaped strings
838
- if (input.charAt(j) !== '`') { return }
839
-
840
- e && $('~');
841
-
842
- if (str = $(/^`([^`]*)`/)) {
843
- return new(tree.JavaScript)(str[1], i, e);
844
- }
845
- }
846
- },
847
-
848
- //
849
- // The variable part of a variable definition. Used in the `rule` parser
850
- //
851
- // @fink:
852
- //
853
- variable: function () {
854
- var name;
855
-
856
- if (input.charAt(i) === '@' && (name = $(/^(@[\w-]+)\s*:/))) { return name[1] }
857
- },
858
-
859
- //
860
- // A font size/line-height shorthand
861
- //
862
- // small/12px
863
- //
864
- // We need to peek first, or we'll match on keywords and dimensions
865
- //
866
- shorthand: function () {
867
- var a, b;
868
-
869
- if (! peek(/^[@\w.%-]+\/[@\w.-]+/)) return;
870
-
871
- if ((a = $(this.entity)) && $('/') && (b = $(this.entity))) {
872
- return new(tree.Shorthand)(a, b);
873
- }
874
- },
875
-
876
- //
877
- // Mixins
878
- //
879
- mixin: {
880
- //
881
- // A Mixin call, with an optional argument list
882
- //
883
- // #mixins > .square(#fff);
884
- // .rounded(4px, black);
885
- // .button;
886
- //
887
- // The `while` loop is there because mixins can be
888
- // namespaced, but we only support the child and descendant
889
- // selector for now.
890
- //
891
- call: function () {
892
- var elements = [], e, c, args, index = i, s = input.charAt(i), important = false;
893
-
894
- if (s !== '.' && s !== '#') { return }
895
-
896
- while (e = $(/^[#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/)) {
897
- elements.push(new(tree.Element)(c, e, i));
898
- c = $('>');
899
- }
900
- $('(') && (args = $(this.entities.arguments)) && $(')');
901
-
902
- if ($(this.important)) {
903
- important = true;
904
- }
905
-
906
- if (elements.length > 0 && ($(';') || peek('}'))) {
907
- return new(tree.mixin.Call)(elements, args || [], index, env.filename, important);
908
- }
909
- },
910
-
911
- //
912
- // A Mixin definition, with a list of parameters
913
- //
914
- // .rounded (@radius: 2px, @color) {
915
- // ...
916
- // }
917
- //
918
- // Until we have a finer grained state-machine, we have to
919
- // do a look-ahead, to make sure we don't have a mixin call.
920
- // See the `rule` function for more information.
921
- //
922
- // We start by matching `.rounded (`, and then proceed on to
923
- // the argument list, which has optional default values.
924
- // We store the parameters in `params`, with a `value` key,
925
- // if there is a value, such as in the case of `@radius`.
926
- //
927
- // Once we've got our params list, and a closing `)`, we parse
928
- // the `{...}` block.
929
- //
930
- definition: function () {
931
- var name, params = [], match, ruleset, param, value, cond, variadic = false;
932
- if ((input.charAt(i) !== '.' && input.charAt(i) !== '#') ||
933
- peek(/^[^{]*(;|})/)) return;
934
-
935
- save();
936
-
937
- if (match = $(/^([#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+)\s*\(/)) {
938
- name = match[1];
939
-
940
- do {
941
- if (input.charAt(i) === '.' && $(/^\.{3}/)) {
942
- variadic = true;
943
- break;
944
- } else if (param = $(this.entities.variable) || $(this.entities.literal)
945
- || $(this.entities.keyword)) {
946
- // Variable
947
- if (param instanceof tree.Variable) {
948
- if ($(':')) {
949
- value = expect(this.expression, 'expected expression');
950
- params.push({ name: param.name, value: value });
951
- } else if ($(/^\.{3}/)) {
952
- params.push({ name: param.name, variadic: true });
953
- variadic = true;
954
- break;
955
- } else {
956
- params.push({ name: param.name });
957
- }
958
- } else {
959
- params.push({ value: param });
960
- }
961
- } else {
962
- break;
963
- }
964
- } while ($(','))
965
-
966
- expect(')');
967
-
968
- if ($(/^when/)) { // Guard
969
- cond = expect(this.conditions, 'expected condition');
970
- }
971
-
972
- ruleset = $(this.block);
973
-
974
- if (ruleset) {
975
- return new(tree.mixin.Definition)(name, params, ruleset, cond, variadic);
976
- } else {
977
- restore();
978
- }
979
- }
980
- }
981
- },
982
-
983
- //
984
- // Entities are the smallest recognized token,
985
- // and can be found inside a rule's value.
986
- //
987
- entity: function () {
988
- return $(this.entities.literal) || $(this.entities.variable) || $(this.entities.url) ||
989
- $(this.entities.call) || $(this.entities.keyword) || $(this.entities.javascript) ||
990
- $(this.comment);
991
- },
992
-
993
- //
994
- // A Rule terminator. Note that we use `peek()` to check for '}',
995
- // because the `block` rule will be expecting it, but we still need to make sure
996
- // it's there, if ';' was ommitted.
997
- //
998
- end: function () {
999
- return $(';') || peek('}');
1000
- },
1001
-
1002
- //
1003
- // IE's alpha function
1004
- //
1005
- // alpha(opacity=88)
1006
- //
1007
- alpha: function () {
1008
- var value;
1009
-
1010
- if (! $(/^\(opacity=/i)) return;
1011
- if (value = $(/^\d+/) || $(this.entities.variable)) {
1012
- expect(')');
1013
- return new(tree.Alpha)(value);
1014
- }
1015
- },
1016
-
1017
- //
1018
- // A Selector Element
1019
- //
1020
- // div
1021
- // + h1
1022
- // #socks
1023
- // input[type="text"]
1024
- //
1025
- // Elements are the building blocks for Selectors,
1026
- // they are made out of a `Combinator` (see combinator rule),
1027
- // and an element name, such as a tag a class, or `*`.
1028
- //
1029
- element: function () {
1030
- var e, t, c, v;
1031
-
1032
- c = $(this.combinator);
1033
- e = $(/^(?:\d+\.\d+|\d+)%/) || $(/^(?:[.#]?|:*)(?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/) ||
1034
- $('*') || $(this.attribute) || $(/^\([^)@]+\)/);
1035
-
1036
- if (! e) {
1037
- $('(') && (v = $(this.entities.variable)) && $(')') && (e = new(tree.Paren)(v));
1038
- }
1039
-
1040
- if (e) { return new(tree.Element)(c, e, i) }
1041
-
1042
- if (c.value && c.value.charAt(0) === '&') {
1043
- return new(tree.Element)(c, null, i);
1044
- }
1045
- },
1046
-
1047
- //
1048
- // Combinators combine elements together, in a Selector.
1049
- //
1050
- // Because our parser isn't white-space sensitive, special care
1051
- // has to be taken, when parsing the descendant combinator, ` `,
1052
- // as it's an empty space. We have to check the previous character
1053
- // in the input, to see if it's a ` ` character. More info on how
1054
- // we deal with this in *combinator.js*.
1055
- //
1056
- combinator: function () {
1057
- var match, c = input.charAt(i);
1058
-
1059
- if (c === '>' || c === '+' || c === '~') {
1060
- i++;
1061
- while (input.charAt(i) === ' ') { i++ }
1062
- return new(tree.Combinator)(c);
1063
- } else if (c === '&') {
1064
- match = '&';
1065
- i++;
1066
- if(input.charAt(i) === ' ') {
1067
- match = '& ';
1068
- }
1069
- while (input.charAt(i) === ' ') { i++ }
1070
- return new(tree.Combinator)(match);
1071
- } else if (input.charAt(i - 1) === ' ') {
1072
- return new(tree.Combinator)(" ");
1073
- } else {
1074
- return new(tree.Combinator)(null);
1075
- }
1076
- },
1077
-
1078
- //
1079
- // A CSS Selector
1080
- //
1081
- // .class > div + h1
1082
- // li a:hover
1083
- //
1084
- // Selectors are made out of one or more Elements, see above.
1085
- //
1086
- selector: function () {
1087
- var sel, e, elements = [], c, match;
1088
-
1089
- if ($('(')) {
1090
- sel = $(this.entity);
1091
- expect(')');
1092
- return new(tree.Selector)([new(tree.Element)('', sel, i)]);
1093
- }
1094
-
1095
- while (e = $(this.element)) {
1096
- c = input.charAt(i);
1097
- elements.push(e)
1098
- if (c === '{' || c === '}' || c === ';' || c === ',') { break }
1099
- }
1100
-
1101
- if (elements.length > 0) { return new(tree.Selector)(elements) }
1102
- },
1103
- tag: function () {
1104
- return $(/^[a-zA-Z][a-zA-Z-]*[0-9]?/) || $('*');
1105
- },
1106
- attribute: function () {
1107
- var attr = '', key, val, op;
1108
-
1109
- if (! $('[')) return;
1110
-
1111
- if (key = $(/^[a-zA-Z-]+/) || $(this.entities.quoted)) {
1112
- if ((op = $(/^[|~*$^]?=/)) &&
1113
- (val = $(this.entities.quoted) || $(/^[\w-]+/))) {
1114
- attr = [key, op, val.toCSS ? val.toCSS() : val].join('');
1115
- } else { attr = key }
1116
- }
1117
-
1118
- if (! $(']')) return;
1119
-
1120
- if (attr) { return "[" + attr + "]" }
1121
- },
1122
-
1123
- //
1124
- // The `block` rule is used by `ruleset` and `mixin.definition`.
1125
- // It's a wrapper around the `primary` rule, with added `{}`.
1126
- //
1127
- block: function () {
1128
- var content;
1129
-
1130
- if ($('{') && (content = $(this.primary)) && $('}')) {
1131
- return content;
1132
- }
1133
- },
1134
-
1135
- //
1136
- // div, .class, body > p {...}
1137
- //
1138
- ruleset: function () {
1139
- var selectors = [], s, rules, match;
1140
- save();
1141
-
1142
- while (s = $(this.selector)) {
1143
- selectors.push(s);
1144
- $(this.comment);
1145
- if (! $(',')) { break }
1146
- $(this.comment);
1147
- }
1148
-
1149
- if (selectors.length > 0 && (rules = $(this.block))) {
1150
- return new(tree.Ruleset)(selectors, rules, env.strictImports);
1151
- } else {
1152
- // Backtrack
1153
- furthest = i;
1154
- restore();
1155
- }
1156
- },
1157
- rule: function () {
1158
- var name, value, c = input.charAt(i), important, match;
1159
- save();
1160
-
1161
- if (c === '.' || c === '#' || c === '&') { return }
1162
-
1163
- if (name = $(this.variable) || $(this.property)) {
1164
- if ((name.charAt(0) != '@') && (match = /^([^@+\/'"*`(;{}-]*);/.exec(chunks[j]))) {
1165
- i += match[0].length - 1;
1166
- value = new(tree.Anonymous)(match[1]);
1167
- } else if (name === "font") {
1168
- value = $(this.font);
1169
- } else {
1170
- value = $(this.value);
1171
- }
1172
- important = $(this.important);
1173
-
1174
- if (value && $(this.end)) {
1175
- return new(tree.Rule)(name, value, important, memo);
1176
- } else {
1177
- furthest = i;
1178
- restore();
1179
- }
1180
- }
1181
- },
1182
-
1183
- //
1184
- // An @import directive
1185
- //
1186
- // @import "lib";
1187
- //
1188
- // Depending on our environemnt, importing is done differently:
1189
- // In the browser, it's an XHR request, in Node, it would be a
1190
- // file-system operation. The function used for importing is
1191
- // stored in `import`, which we pass to the Import constructor.
1192
- //
1193
- "import": function () {
1194
- var path, features, index = i;
1195
- if ($(/^@import\s+/) &&
1196
- (path = $(this.entities.quoted) || $(this.entities.url))) {
1197
- features = $(this.mediaFeatures);
1198
- if ($(';')) {
1199
- return new(tree.Import)(path, imports, features, index);
1200
- }
1201
- }
1202
- },
1203
-
1204
- mediaFeature: function () {
1205
- var e, p, nodes = [];
1206
-
1207
- do {
1208
- if (e = $(this.entities.keyword)) {
1209
- nodes.push(e);
1210
- } else if ($('(')) {
1211
- p = $(this.property);
1212
- e = $(this.entity);
1213
- if ($(')')) {
1214
- if (p && e) {
1215
- nodes.push(new(tree.Paren)(new(tree.Rule)(p, e, null, i, true)));
1216
- } else if (e) {
1217
- nodes.push(new(tree.Paren)(e));
1218
- } else {
1219
- return null;
1220
- }
1221
- } else { return null }
1222
- }
1223
- } while (e);
1224
-
1225
- if (nodes.length > 0) {
1226
- return new(tree.Expression)(nodes);
1227
- }
1228
- },
1229
-
1230
- mediaFeatures: function () {
1231
- var e, features = [];
1232
-
1233
- do {
1234
- if (e = $(this.mediaFeature)) {
1235
- features.push(e);
1236
- if (! $(',')) { break }
1237
- } else if (e = $(this.entities.variable)) {
1238
- features.push(e);
1239
- if (! $(',')) { break }
1240
- }
1241
- } while (e);
1242
-
1243
- return features.length > 0 ? features : null;
1244
- },
1245
-
1246
- media: function () {
1247
- var features, rules;
1248
-
1249
- if ($(/^@media/)) {
1250
- features = $(this.mediaFeatures);
1251
-
1252
- if (rules = $(this.block)) {
1253
- return new(tree.Media)(rules, features);
1254
- }
1255
- }
1256
- },
1257
-
1258
- //
1259
- // A CSS Directive
1260
- //
1261
- // @charset "utf-8";
1262
- //
1263
- directive: function () {
1264
- var name, value, rules, types, e, nodes;
1265
-
1266
- if (input.charAt(i) !== '@') return;
1267
-
1268
- if (value = $(this['import']) || $(this.media)) {
1269
- return value;
1270
- } else if (name = $(/^@page|@keyframes/) || $(/^@(?:-webkit-|-moz-|-o-|-ms-)[a-z0-9-]+/)) {
1271
- types = ($(/^[^{]+/) || '').trim();
1272
- if (rules = $(this.block)) {
1273
- return new(tree.Directive)(name + " " + types, rules);
1274
- }
1275
- } else if (name = $(/^@[-a-z]+/)) {
1276
- if (name === '@font-face') {
1277
- if (rules = $(this.block)) {
1278
- return new(tree.Directive)(name, rules);
1279
- }
1280
- } else if ((value = $(this.entity)) && $(';')) {
1281
- return new(tree.Directive)(name, value);
1282
- }
1283
- }
1284
- },
1285
- font: function () {
1286
- var value = [], expression = [], weight, shorthand, font, e;
1287
-
1288
- while (e = $(this.shorthand) || $(this.entity)) {
1289
- expression.push(e);
1290
- }
1291
- value.push(new(tree.Expression)(expression));
1292
-
1293
- if ($(',')) {
1294
- while (e = $(this.expression)) {
1295
- value.push(e);
1296
- if (! $(',')) { break }
1297
- }
1298
- }
1299
- return new(tree.Value)(value);
1300
- },
1301
-
1302
- //
1303
- // A Value is a comma-delimited list of Expressions
1304
- //
1305
- // font-family: Baskerville, Georgia, serif;
1306
- //
1307
- // In a Rule, a Value represents everything after the `:`,
1308
- // and before the `;`.
1309
- //
1310
- value: function () {
1311
- var e, expressions = [], important;
1312
-
1313
- while (e = $(this.expression)) {
1314
- expressions.push(e);
1315
- if (! $(',')) { break }
1316
- }
1317
-
1318
- if (expressions.length > 0) {
1319
- return new(tree.Value)(expressions);
1320
- }
1321
- },
1322
- important: function () {
1323
- if (input.charAt(i) === '!') {
1324
- return $(/^! *important/);
1325
- }
1326
- },
1327
- sub: function () {
1328
- var e;
1329
-
1330
- if ($('(') && (e = $(this.expression)) && $(')')) {
1331
- return e;
1332
- }
1333
- },
1334
- multiplication: function () {
1335
- var m, a, op, operation;
1336
- if (m = $(this.operand)) {
1337
- while (!peek(/^\/\*/) && (op = ($('/') || $('*'))) && (a = $(this.operand))) {
1338
- operation = new(tree.Operation)(op, [operation || m, a]);
1339
- }
1340
- return operation || m;
1341
- }
1342
- },
1343
- addition: function () {
1344
- var m, a, op, operation;
1345
- if (m = $(this.multiplication)) {
1346
- while ((op = $(/^[-+]\s+/) || (input.charAt(i - 1) != ' ' && ($('+') || $('-')))) &&
1347
- (a = $(this.multiplication))) {
1348
- operation = new(tree.Operation)(op, [operation || m, a]);
1349
- }
1350
- return operation || m;
1351
- }
1352
- },
1353
- conditions: function () {
1354
- var a, b, index = i, condition;
1355
-
1356
- if (a = $(this.condition)) {
1357
- while ($(',') && (b = $(this.condition))) {
1358
- condition = new(tree.Condition)('or', condition || a, b, index);
1359
- }
1360
- return condition || a;
1361
- }
1362
- },
1363
- condition: function () {
1364
- var a, b, c, op, index = i, negate = false;
1365
-
1366
- if ($(/^not/)) { negate = true }
1367
- expect('(');
1368
- if (a = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
1369
- if (op = $(/^(?:>=|=<|[<=>])/)) {
1370
- if (b = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
1371
- c = new(tree.Condition)(op, a, b, index, negate);
1372
- } else {
1373
- error('expected expression');
1374
- }
1375
- } else {
1376
- c = new(tree.Condition)('=', a, new(tree.Keyword)('true'), index, negate);
1377
- }
1378
- expect(')');
1379
- return $(/^and/) ? new(tree.Condition)('and', c, $(this.condition)) : c;
1380
- }
1381
- },
1382
-
1383
- //
1384
- // An operand is anything that can be part of an operation,
1385
- // such as a Color, or a Variable
1386
- //
1387
- operand: function () {
1388
- var negate, p = input.charAt(i + 1);
1389
-
1390
- if (input.charAt(i) === '-' && (p === '@' || p === '(')) { negate = $('-') }
1391
- var o = $(this.sub) || $(this.entities.dimension) ||
1392
- $(this.entities.color) || $(this.entities.variable) ||
1393
- $(this.entities.call);
1394
- return negate ? new(tree.Operation)('*', [new(tree.Dimension)(-1), o])
1395
- : o;
1396
- },
1397
-
1398
- //
1399
- // Expressions either represent mathematical operations,
1400
- // or white-space delimited Entities.
1401
- //
1402
- // 1px solid black
1403
- // @var * 2
1404
- //
1405
- expression: function () {
1406
- var e, delim, entities = [], d;
1407
-
1408
- while (e = $(this.addition) || $(this.entity)) {
1409
- entities.push(e);
1410
- }
1411
- if (entities.length > 0) {
1412
- return new(tree.Expression)(entities);
1413
- }
1414
- },
1415
- property: function () {
1416
- var name;
1417
-
1418
- if (name = $(/^(\*?-?[-a-z_0-9]+)\s*:/)) {
1419
- return name[1];
1420
- }
1421
- }
1422
- }
1423
- };
1424
- };
1425
-
1426
- if (less.mode === 'browser' || less.mode === 'rhino') {
1427
- //
1428
- // Used by `@import` directives
1429
- //
1430
- less.Parser.importer = function (path, paths, callback, env) {
1431
- if (!/^([a-z]+:)?\//.test(path) && paths.length > 0) {
1432
- path = paths[0] + path;
1433
- }
1434
- // We pass `true` as 3rd argument, to force the reload of the import.
1435
- // This is so we can get the syntax tree as opposed to just the CSS output,
1436
- // as we need this to evaluate the current stylesheet.
1437
- loadStyleSheet({ href: path, title: path, type: env.mime }, function (e) {
1438
- if (e && typeof(env.errback) === "function") {
1439
- env.errback.call(null, path, paths, callback, env);
1440
- } else {
1441
- callback.apply(null, arguments);
1442
- }
1443
- }, true);
1444
- };
1445
- }
1446
-
1447
- (function (tree) {
1448
-
1449
- tree.functions = {
1450
- rgb: function (r, g, b) {
1451
- return this.rgba(r, g, b, 1.0);
1452
- },
1453
- rgba: function (r, g, b, a) {
1454
- var rgb = [r, g, b].map(function (c) { return number(c) }),
1455
- a = number(a);
1456
- return new(tree.Color)(rgb, a);
1457
- },
1458
- hsl: function (h, s, l) {
1459
- return this.hsla(h, s, l, 1.0);
1460
- },
1461
- hsla: function (h, s, l, a) {
1462
- h = (number(h) % 360) / 360;
1463
- s = number(s); l = number(l); a = number(a);
1464
-
1465
- var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
1466
- var m1 = l * 2 - m2;
1467
-
1468
- return this.rgba(hue(h + 1/3) * 255,
1469
- hue(h) * 255,
1470
- hue(h - 1/3) * 255,
1471
- a);
1472
-
1473
- function hue(h) {
1474
- h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h);
1475
- if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
1476
- else if (h * 2 < 1) return m2;
1477
- else if (h * 3 < 2) return m1 + (m2 - m1) * (2/3 - h) * 6;
1478
- else return m1;
1479
- }
1480
- },
1481
- hue: function (color) {
1482
- return new(tree.Dimension)(Math.round(color.toHSL().h));
1483
- },
1484
- saturation: function (color) {
1485
- return new(tree.Dimension)(Math.round(color.toHSL().s * 100), '%');
1486
- },
1487
- lightness: function (color) {
1488
- return new(tree.Dimension)(Math.round(color.toHSL().l * 100), '%');
1489
- },
1490
- alpha: function (color) {
1491
- return new(tree.Dimension)(color.toHSL().a);
1492
- },
1493
- saturate: function (color, amount) {
1494
- var hsl = color.toHSL();
1495
-
1496
- hsl.s += amount.value / 100;
1497
- hsl.s = clamp(hsl.s);
1498
- return hsla(hsl);
1499
- },
1500
- desaturate: function (color, amount) {
1501
- var hsl = color.toHSL();
1502
-
1503
- hsl.s -= amount.value / 100;
1504
- hsl.s = clamp(hsl.s);
1505
- return hsla(hsl);
1506
- },
1507
- lighten: function (color, amount) {
1508
- var hsl = color.toHSL();
1509
-
1510
- hsl.l += amount.value / 100;
1511
- hsl.l = clamp(hsl.l);
1512
- return hsla(hsl);
1513
- },
1514
- darken: function (color, amount) {
1515
- var hsl = color.toHSL();
1516
-
1517
- hsl.l -= amount.value / 100;
1518
- hsl.l = clamp(hsl.l);
1519
- return hsla(hsl);
1520
- },
1521
- fadein: function (color, amount) {
1522
- var hsl = color.toHSL();
1523
-
1524
- hsl.a += amount.value / 100;
1525
- hsl.a = clamp(hsl.a);
1526
- return hsla(hsl);
1527
- },
1528
- fadeout: function (color, amount) {
1529
- var hsl = color.toHSL();
1530
-
1531
- hsl.a -= amount.value / 100;
1532
- hsl.a = clamp(hsl.a);
1533
- return hsla(hsl);
1534
- },
1535
- fade: function (color, amount) {
1536
- var hsl = color.toHSL();
1537
-
1538
- hsl.a = amount.value / 100;
1539
- hsl.a = clamp(hsl.a);
1540
- return hsla(hsl);
1541
- },
1542
- spin: function (color, amount) {
1543
- var hsl = color.toHSL();
1544
- var hue = (hsl.h + amount.value) % 360;
1545
-
1546
- hsl.h = hue < 0 ? 360 + hue : hue;
1547
-
1548
- return hsla(hsl);
1549
- },
1550
- //
1551
- // Copyright (c) 2006-2009 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein
1552
- // http://sass-lang.com
1553
- //
1554
- mix: function (color1, color2, weight) {
1555
- var p = weight.value / 100.0;
1556
- var w = p * 2 - 1;
1557
- var a = color1.toHSL().a - color2.toHSL().a;
1558
-
1559
- var w1 = (((w * a == -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
1560
- var w2 = 1 - w1;
1561
-
1562
- var rgb = [color1.rgb[0] * w1 + color2.rgb[0] * w2,
1563
- color1.rgb[1] * w1 + color2.rgb[1] * w2,
1564
- color1.rgb[2] * w1 + color2.rgb[2] * w2];
1565
-
1566
- var alpha = color1.alpha * p + color2.alpha * (1 - p);
1567
-
1568
- return new(tree.Color)(rgb, alpha);
1569
- },
1570
- greyscale: function (color) {
1571
- return this.desaturate(color, new(tree.Dimension)(100));
1572
- },
1573
- e: function (str) {
1574
- return new(tree.Anonymous)(str instanceof tree.JavaScript ? str.evaluated : str);
1575
- },
1576
- escape: function (str) {
1577
- return new(tree.Anonymous)(encodeURI(str.value).replace(/=/g, "%3D").replace(/:/g, "%3A").replace(/#/g, "%23").replace(/;/g, "%3B").replace(/\(/g, "%28").replace(/\)/g, "%29"));
1578
- },
1579
- '%': function (quoted /* arg, arg, ...*/) {
1580
- var args = Array.prototype.slice.call(arguments, 1),
1581
- str = quoted.value;
1582
-
1583
- for (var i = 0; i < args.length; i++) {
1584
- str = str.replace(/%[sda]/i, function(token) {
1585
- var value = token.match(/s/i) ? args[i].value : args[i].toCSS();
1586
- return token.match(/[A-Z]$/) ? encodeURIComponent(value) : value;
1587
- });
1588
- }
1589
- str = str.replace(/%%/g, '%');
1590
- return new(tree.Quoted)('"' + str + '"', str);
1591
- },
1592
- round: function (n) {
1593
- return this._math('round', n);
1594
- },
1595
- ceil: function (n) {
1596
- return this._math('ceil', n);
1597
- },
1598
- floor: function (n) {
1599
- return this._math('floor', n);
1600
- },
1601
- _math: function (fn, n) {
1602
- if (n instanceof tree.Dimension) {
1603
- return new(tree.Dimension)(Math[fn](number(n)), n.unit);
1604
- } else if (typeof(n) === 'number') {
1605
- return Math[fn](n);
1606
- } else {
1607
- throw { type: "Argument", message: "argument must be a number" };
1608
- }
1609
- },
1610
- argb: function (color) {
1611
- return new(tree.Anonymous)(color.toARGB());
1612
-
1613
- },
1614
- percentage: function (n) {
1615
- return new(tree.Dimension)(n.value * 100, '%');
1616
- },
1617
- color: function (n) {
1618
- if (n instanceof tree.Quoted) {
1619
- return new(tree.Color)(n.value.slice(1));
1620
- } else {
1621
- throw { type: "Argument", message: "argument must be a string" };
1622
- }
1623
- },
1624
- iscolor: function (n) {
1625
- return this._isa(n, tree.Color);
1626
- },
1627
- isnumber: function (n) {
1628
- return this._isa(n, tree.Dimension);
1629
- },
1630
- isstring: function (n) {
1631
- return this._isa(n, tree.Quoted);
1632
- },
1633
- iskeyword: function (n) {
1634
- return this._isa(n, tree.Keyword);
1635
- },
1636
- isurl: function (n) {
1637
- return this._isa(n, tree.URL);
1638
- },
1639
- ispixel: function (n) {
1640
- return (n instanceof tree.Dimension) && n.unit === 'px' ? tree.True : tree.False;
1641
- },
1642
- ispercentage: function (n) {
1643
- return (n instanceof tree.Dimension) && n.unit === '%' ? tree.True : tree.False;
1644
- },
1645
- isem: function (n) {
1646
- return (n instanceof tree.Dimension) && n.unit === 'em' ? tree.True : tree.False;
1647
- },
1648
- _isa: function (n, Type) {
1649
- return (n instanceof Type) ? tree.True : tree.False;
1650
- }
1651
- };
1652
-
1653
- function hsla(hsla) {
1654
- return tree.functions.hsla(hsla.h, hsla.s, hsla.l, hsla.a);
1655
- }
1656
-
1657
- function number(n) {
1658
- if (n instanceof tree.Dimension) {
1659
- return parseFloat(n.unit == '%' ? n.value / 100 : n.value);
1660
- } else if (typeof(n) === 'number') {
1661
- return n;
1662
- } else {
1663
- throw {
1664
- error: "RuntimeError",
1665
- message: "color functions take numbers as parameters"
1666
- };
1667
- }
1668
- }
1669
-
1670
- function clamp(val) {
1671
- return Math.min(1, Math.max(0, val));
1672
- }
1673
-
1674
- })(require('./tree'));
1675
- (function (tree) {
1676
- tree.colors = {
1677
- 'aliceblue':'#f0f8ff',
1678
- 'antiquewhite':'#faebd7',
1679
- 'aqua':'#00ffff',
1680
- 'aquamarine':'#7fffd4',
1681
- 'azure':'#f0ffff',
1682
- 'beige':'#f5f5dc',
1683
- 'bisque':'#ffe4c4',
1684
- 'black':'#000000',
1685
- 'blanchedalmond':'#ffebcd',
1686
- 'blue':'#0000ff',
1687
- 'blueviolet':'#8a2be2',
1688
- 'brown':'#a52a2a',
1689
- 'burlywood':'#deb887',
1690
- 'cadetblue':'#5f9ea0',
1691
- 'chartreuse':'#7fff00',
1692
- 'chocolate':'#d2691e',
1693
- 'coral':'#ff7f50',
1694
- 'cornflowerblue':'#6495ed',
1695
- 'cornsilk':'#fff8dc',
1696
- 'crimson':'#dc143c',
1697
- 'cyan':'#00ffff',
1698
- 'darkblue':'#00008b',
1699
- 'darkcyan':'#008b8b',
1700
- 'darkgoldenrod':'#b8860b',
1701
- 'darkgray':'#a9a9a9',
1702
- 'darkgrey':'#a9a9a9',
1703
- 'darkgreen':'#006400',
1704
- 'darkkhaki':'#bdb76b',
1705
- 'darkmagenta':'#8b008b',
1706
- 'darkolivegreen':'#556b2f',
1707
- 'darkorange':'#ff8c00',
1708
- 'darkorchid':'#9932cc',
1709
- 'darkred':'#8b0000',
1710
- 'darksalmon':'#e9967a',
1711
- 'darkseagreen':'#8fbc8f',
1712
- 'darkslateblue':'#483d8b',
1713
- 'darkslategray':'#2f4f4f',
1714
- 'darkslategrey':'#2f4f4f',
1715
- 'darkturquoise':'#00ced1',
1716
- 'darkviolet':'#9400d3',
1717
- 'deeppink':'#ff1493',
1718
- 'deepskyblue':'#00bfff',
1719
- 'dimgray':'#696969',
1720
- 'dimgrey':'#696969',
1721
- 'dodgerblue':'#1e90ff',
1722
- 'firebrick':'#b22222',
1723
- 'floralwhite':'#fffaf0',
1724
- 'forestgreen':'#228b22',
1725
- 'fuchsia':'#ff00ff',
1726
- 'gainsboro':'#dcdcdc',
1727
- 'ghostwhite':'#f8f8ff',
1728
- 'gold':'#ffd700',
1729
- 'goldenrod':'#daa520',
1730
- 'gray':'#808080',
1731
- 'grey':'#808080',
1732
- 'green':'#008000',
1733
- 'greenyellow':'#adff2f',
1734
- 'honeydew':'#f0fff0',
1735
- 'hotpink':'#ff69b4',
1736
- 'indianred':'#cd5c5c',
1737
- 'indigo':'#4b0082',
1738
- 'ivory':'#fffff0',
1739
- 'khaki':'#f0e68c',
1740
- 'lavender':'#e6e6fa',
1741
- 'lavenderblush':'#fff0f5',
1742
- 'lawngreen':'#7cfc00',
1743
- 'lemonchiffon':'#fffacd',
1744
- 'lightblue':'#add8e6',
1745
- 'lightcoral':'#f08080',
1746
- 'lightcyan':'#e0ffff',
1747
- 'lightgoldenrodyellow':'#fafad2',
1748
- 'lightgray':'#d3d3d3',
1749
- 'lightgrey':'#d3d3d3',
1750
- 'lightgreen':'#90ee90',
1751
- 'lightpink':'#ffb6c1',
1752
- 'lightsalmon':'#ffa07a',
1753
- 'lightseagreen':'#20b2aa',
1754
- 'lightskyblue':'#87cefa',
1755
- 'lightslategray':'#778899',
1756
- 'lightslategrey':'#778899',
1757
- 'lightsteelblue':'#b0c4de',
1758
- 'lightyellow':'#ffffe0',
1759
- 'lime':'#00ff00',
1760
- 'limegreen':'#32cd32',
1761
- 'linen':'#faf0e6',
1762
- 'magenta':'#ff00ff',
1763
- 'maroon':'#800000',
1764
- 'mediumaquamarine':'#66cdaa',
1765
- 'mediumblue':'#0000cd',
1766
- 'mediumorchid':'#ba55d3',
1767
- 'mediumpurple':'#9370d8',
1768
- 'mediumseagreen':'#3cb371',
1769
- 'mediumslateblue':'#7b68ee',
1770
- 'mediumspringgreen':'#00fa9a',
1771
- 'mediumturquoise':'#48d1cc',
1772
- 'mediumvioletred':'#c71585',
1773
- 'midnightblue':'#191970',
1774
- 'mintcream':'#f5fffa',
1775
- 'mistyrose':'#ffe4e1',
1776
- 'moccasin':'#ffe4b5',
1777
- 'navajowhite':'#ffdead',
1778
- 'navy':'#000080',
1779
- 'oldlace':'#fdf5e6',
1780
- 'olive':'#808000',
1781
- 'olivedrab':'#6b8e23',
1782
- 'orange':'#ffa500',
1783
- 'orangered':'#ff4500',
1784
- 'orchid':'#da70d6',
1785
- 'palegoldenrod':'#eee8aa',
1786
- 'palegreen':'#98fb98',
1787
- 'paleturquoise':'#afeeee',
1788
- 'palevioletred':'#d87093',
1789
- 'papayawhip':'#ffefd5',
1790
- 'peachpuff':'#ffdab9',
1791
- 'peru':'#cd853f',
1792
- 'pink':'#ffc0cb',
1793
- 'plum':'#dda0dd',
1794
- 'powderblue':'#b0e0e6',
1795
- 'purple':'#800080',
1796
- 'red':'#ff0000',
1797
- 'rosybrown':'#bc8f8f',
1798
- 'royalblue':'#4169e1',
1799
- 'saddlebrown':'#8b4513',
1800
- 'salmon':'#fa8072',
1801
- 'sandybrown':'#f4a460',
1802
- 'seagreen':'#2e8b57',
1803
- 'seashell':'#fff5ee',
1804
- 'sienna':'#a0522d',
1805
- 'silver':'#c0c0c0',
1806
- 'skyblue':'#87ceeb',
1807
- 'slateblue':'#6a5acd',
1808
- 'slategray':'#708090',
1809
- 'slategrey':'#708090',
1810
- 'snow':'#fffafa',
1811
- 'springgreen':'#00ff7f',
1812
- 'steelblue':'#4682b4',
1813
- 'tan':'#d2b48c',
1814
- 'teal':'#008080',
1815
- 'thistle':'#d8bfd8',
1816
- 'tomato':'#ff6347',
1817
- 'turquoise':'#40e0d0',
1818
- 'violet':'#ee82ee',
1819
- 'wheat':'#f5deb3',
1820
- 'white':'#ffffff',
1821
- 'whitesmoke':'#f5f5f5',
1822
- 'yellow':'#ffff00',
1823
- 'yellowgreen':'#9acd32'
1824
- };
1825
- })(require('./tree'));
1826
- (function (tree) {
1827
-
1828
- tree.Alpha = function (val) {
1829
- this.value = val;
1830
- };
1831
- tree.Alpha.prototype = {
1832
- toCSS: function () {
1833
- return "alpha(opacity=" +
1834
- (this.value.toCSS ? this.value.toCSS() : this.value) + ")";
1835
- },
1836
- eval: function (env) {
1837
- if (this.value.eval) { this.value = this.value.eval(env) }
1838
- return this;
1839
- }
1840
- };
1841
-
1842
- })(require('../tree'));
1843
- (function (tree) {
1844
-
1845
- tree.Anonymous = function (string) {
1846
- this.value = string.value || string;
1847
- };
1848
- tree.Anonymous.prototype = {
1849
- toCSS: function () {
1850
- return this.value;
1851
- },
1852
- eval: function () { return this }
1853
- };
1854
-
1855
- })(require('../tree'));
1856
- (function (tree) {
1857
-
1858
- tree.Assignment = function (key, val) {
1859
- this.key = key;
1860
- this.value = val;
1861
- };
1862
- tree.Assignment.prototype = {
1863
- toCSS: function () {
1864
- return this.key + '=' + (this.value.toCSS ? this.value.toCSS() : this.value);
1865
- },
1866
- eval: function (env) {
1867
- if (this.value.eval) { this.value = this.value.eval(env) }
1868
- return this;
1869
- }
1870
- };
1871
-
1872
- })(require('../tree'));(function (tree) {
1873
-
1874
- //
1875
- // A function call node.
1876
- //
1877
- tree.Call = function (name, args, index, filename) {
1878
- this.name = name;
1879
- this.args = args;
1880
- this.index = index;
1881
- this.filename = filename;
1882
- };
1883
- tree.Call.prototype = {
1884
- //
1885
- // When evaluating a function call,
1886
- // we either find the function in `tree.functions` [1],
1887
- // in which case we call it, passing the evaluated arguments,
1888
- // or we simply print it out as it appeared originally [2].
1889
- //
1890
- // The *functions.js* file contains the built-in functions.
1891
- //
1892
- // The reason why we evaluate the arguments, is in the case where
1893
- // we try to pass a variable to a function, like: `saturate(@color)`.
1894
- // The function should receive the value, not the variable.
1895
- //
1896
- eval: function (env) {
1897
- var args = this.args.map(function (a) { return a.eval(env) });
1898
-
1899
- if (this.name in tree.functions) { // 1.
1900
- try {
1901
- return tree.functions[this.name].apply(tree.functions, args);
1902
- } catch (e) {
1903
- throw { type: e.type || "Runtime",
1904
- message: "error evaluating function `" + this.name + "`" +
1905
- (e.message ? ': ' + e.message : ''),
1906
- index: this.index, filename: this.filename };
1907
- }
1908
- } else { // 2.
1909
- return new(tree.Anonymous)(this.name +
1910
- "(" + args.map(function (a) { return a.toCSS() }).join(', ') + ")");
1911
- }
1912
- },
1913
-
1914
- toCSS: function (env) {
1915
- return this.eval(env).toCSS();
1916
- }
1917
- };
1918
-
1919
- })(require('../tree'));
1920
- (function (tree) {
1921
- //
1922
- // RGB Colors - #ff0014, #eee
1923
- //
1924
- tree.Color = function (rgb, a) {
1925
- //
1926
- // The end goal here, is to parse the arguments
1927
- // into an integer triplet, such as `128, 255, 0`
1928
- //
1929
- // This facilitates operations and conversions.
1930
- //
1931
- if (Array.isArray(rgb)) {
1932
- this.rgb = rgb;
1933
- } else if (rgb.length == 6) {
1934
- this.rgb = rgb.match(/.{2}/g).map(function (c) {
1935
- return parseInt(c, 16);
1936
- });
1937
- } else {
1938
- this.rgb = rgb.split('').map(function (c) {
1939
- return parseInt(c + c, 16);
1940
- });
1941
- }
1942
- this.alpha = typeof(a) === 'number' ? a : 1;
1943
- };
1944
- tree.Color.prototype = {
1945
- eval: function () { return this },
1946
-
1947
- //
1948
- // If we have some transparency, the only way to represent it
1949
- // is via `rgba`. Otherwise, we use the hex representation,
1950
- // which has better compatibility with older browsers.
1951
- // Values are capped between `0` and `255`, rounded and zero-padded.
1952
- //
1953
- toCSS: function () {
1954
- if (this.alpha < 1.0) {
1955
- return "rgba(" + this.rgb.map(function (c) {
1956
- return Math.round(c);
1957
- }).concat(this.alpha).join(', ') + ")";
1958
- } else {
1959
- return '#' + this.rgb.map(function (i) {
1960
- i = Math.round(i);
1961
- i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
1962
- return i.length === 1 ? '0' + i : i;
1963
- }).join('');
1964
- }
1965
- },
1966
-
1967
- //
1968
- // Operations have to be done per-channel, if not,
1969
- // channels will spill onto each other. Once we have
1970
- // our result, in the form of an integer triplet,
1971
- // we create a new Color node to hold the result.
1972
- //
1973
- operate: function (op, other) {
1974
- var result = [];
1975
-
1976
- if (! (other instanceof tree.Color)) {
1977
- other = other.toColor();
1978
- }
1979
-
1980
- for (var c = 0; c < 3; c++) {
1981
- result[c] = tree.operate(op, this.rgb[c], other.rgb[c]);
1982
- }
1983
- return new(tree.Color)(result, this.alpha + other.alpha);
1984
- },
1985
-
1986
- toHSL: function () {
1987
- var r = this.rgb[0] / 255,
1988
- g = this.rgb[1] / 255,
1989
- b = this.rgb[2] / 255,
1990
- a = this.alpha;
1991
-
1992
- var max = Math.max(r, g, b), min = Math.min(r, g, b);
1993
- var h, s, l = (max + min) / 2, d = max - min;
1994
-
1995
- if (max === min) {
1996
- h = s = 0;
1997
- } else {
1998
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
1999
-
2000
- switch (max) {
2001
- case r: h = (g - b) / d + (g < b ? 6 : 0); break;
2002
- case g: h = (b - r) / d + 2; break;
2003
- case b: h = (r - g) / d + 4; break;
2004
- }
2005
- h /= 6;
2006
- }
2007
- return { h: h * 360, s: s, l: l, a: a };
2008
- },
2009
- toARGB: function () {
2010
- var argb = [Math.round(this.alpha * 255)].concat(this.rgb);
2011
- return '#' + argb.map(function (i) {
2012
- i = Math.round(i);
2013
- i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
2014
- return i.length === 1 ? '0' + i : i;
2015
- }).join('');
2016
- }
2017
- };
2018
-
2019
-
2020
- })(require('../tree'));
2021
- (function (tree) {
2022
-
2023
- tree.Comment = function (value, silent) {
2024
- this.value = value;
2025
- this.silent = !!silent;
2026
- };
2027
- tree.Comment.prototype = {
2028
- toCSS: function (env) {
2029
- return env.compress ? '' : this.value;
2030
- },
2031
- eval: function () { return this }
2032
- };
2033
-
2034
- })(require('../tree'));
2035
- (function (tree) {
2036
-
2037
- tree.Condition = function (op, l, r, i, negate) {
2038
- this.op = op.trim();
2039
- this.lvalue = l;
2040
- this.rvalue = r;
2041
- this.index = i;
2042
- this.negate = negate;
2043
- };
2044
- tree.Condition.prototype.eval = function (env) {
2045
- var a = this.lvalue.eval(env),
2046
- b = this.rvalue.eval(env);
2047
-
2048
- var i = this.index, result;
2049
-
2050
- var result = (function (op) {
2051
- switch (op) {
2052
- case 'and':
2053
- return a && b;
2054
- case 'or':
2055
- return a || b;
2056
- default:
2057
- if (a.compare) {
2058
- result = a.compare(b);
2059
- } else if (b.compare) {
2060
- result = b.compare(a);
2061
- } else {
2062
- throw { type: "Type",
2063
- message: "Unable to perform comparison",
2064
- index: i };
2065
- }
2066
- switch (result) {
2067
- case -1: return op === '<' || op === '=<';
2068
- case 0: return op === '=' || op === '>=' || op === '=<';
2069
- case 1: return op === '>' || op === '>=';
2070
- }
2071
- }
2072
- })(this.op);
2073
- return this.negate ? !result : result;
2074
- };
2075
-
2076
- })(require('../tree'));
2077
- (function (tree) {
2078
-
2079
- //
2080
- // A number with a unit
2081
- //
2082
- tree.Dimension = function (value, unit) {
2083
- this.value = parseFloat(value);
2084
- this.unit = unit || null;
2085
- };
2086
-
2087
- tree.Dimension.prototype = {
2088
- eval: function () { return this },
2089
- toColor: function () {
2090
- return new(tree.Color)([this.value, this.value, this.value]);
2091
- },
2092
- toCSS: function () {
2093
- var css = this.value + this.unit;
2094
- return css;
2095
- },
2096
-
2097
- // In an operation between two Dimensions,
2098
- // we default to the first Dimension's unit,
2099
- // so `1px + 2em` will yield `3px`.
2100
- // In the future, we could implement some unit
2101
- // conversions such that `100cm + 10mm` would yield
2102
- // `101cm`.
2103
- operate: function (op, other) {
2104
- return new(tree.Dimension)
2105
- (tree.operate(op, this.value, other.value),
2106
- this.unit || other.unit);
2107
- },
2108
-
2109
- // TODO: Perform unit conversion before comparing
2110
- compare: function (other) {
2111
- if (other instanceof tree.Dimension) {
2112
- if (other.value > this.value) {
2113
- return -1;
2114
- } else if (other.value < this.value) {
2115
- return 1;
2116
- } else {
2117
- return 0;
2118
- }
2119
- } else {
2120
- return -1;
2121
- }
2122
- }
2123
- };
2124
-
2125
- })(require('../tree'));
2126
- (function (tree) {
2127
-
2128
- tree.Directive = function (name, value, features) {
2129
- this.name = name;
2130
-
2131
- if (Array.isArray(value)) {
2132
- this.ruleset = new(tree.Ruleset)([], value);
2133
- this.ruleset.allowImports = true;
2134
- } else {
2135
- this.value = value;
2136
- }
2137
- };
2138
- tree.Directive.prototype = {
2139
- toCSS: function (ctx, env) {
2140
- if (this.ruleset) {
2141
- this.ruleset.root = true;
2142
- return this.name + (env.compress ? '{' : ' {\n ') +
2143
- this.ruleset.toCSS(ctx, env).trim().replace(/\n/g, '\n ') +
2144
- (env.compress ? '}': '\n}\n');
2145
- } else {
2146
- return this.name + ' ' + this.value.toCSS() + ';\n';
2147
- }
2148
- },
2149
- eval: function (env) {
2150
- env.frames.unshift(this);
2151
- this.ruleset = this.ruleset && this.ruleset.eval(env);
2152
- env.frames.shift();
2153
- return this;
2154
- },
2155
- variable: function (name) { return tree.Ruleset.prototype.variable.call(this.ruleset, name) },
2156
- find: function () { return tree.Ruleset.prototype.find.apply(this.ruleset, arguments) },
2157
- rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.ruleset) }
2158
- };
2159
-
2160
- })(require('../tree'));
2161
- (function (tree) {
2162
-
2163
- tree.Element = function (combinator, value, index) {
2164
- this.combinator = combinator instanceof tree.Combinator ?
2165
- combinator : new(tree.Combinator)(combinator);
2166
-
2167
- if (typeof(value) === 'string') {
2168
- this.value = value.trim();
2169
- } else if (value) {
2170
- this.value = value;
2171
- } else {
2172
- this.value = "";
2173
- }
2174
- this.index = index;
2175
- };
2176
- tree.Element.prototype.eval = function (env) {
2177
- return new(tree.Element)(this.combinator,
2178
- this.value.eval ? this.value.eval(env) : this.value,
2179
- this.index);
2180
- };
2181
- tree.Element.prototype.toCSS = function (env) {
2182
- return this.combinator.toCSS(env || {}) + (this.value.toCSS ? this.value.toCSS(env) : this.value);
2183
- };
2184
-
2185
- tree.Combinator = function (value) {
2186
- if (value === ' ') {
2187
- this.value = ' ';
2188
- } else if (value === '& ') {
2189
- this.value = '& ';
2190
- } else {
2191
- this.value = value ? value.trim() : "";
2192
- }
2193
- };
2194
- tree.Combinator.prototype.toCSS = function (env) {
2195
- return {
2196
- '' : '',
2197
- ' ' : ' ',
2198
- '&' : '',
2199
- '& ' : ' ',
2200
- ':' : ' :',
2201
- '+' : env.compress ? '+' : ' + ',
2202
- '~' : env.compress ? '~' : ' ~ ',
2203
- '>' : env.compress ? '>' : ' > '
2204
- }[this.value];
2205
- };
2206
-
2207
- })(require('../tree'));
2208
- (function (tree) {
2209
-
2210
- tree.Expression = function (value) { this.value = value };
2211
- tree.Expression.prototype = {
2212
- eval: function (env) {
2213
- if (this.value.length > 1) {
2214
- return new(tree.Expression)(this.value.map(function (e) {
2215
- return e.eval(env);
2216
- }));
2217
- } else if (this.value.length === 1) {
2218
- return this.value[0].eval(env);
2219
- } else {
2220
- return this;
2221
- }
2222
- },
2223
- toCSS: function (env) {
2224
- return this.value.map(function (e) {
2225
- return e.toCSS ? e.toCSS(env) : '';
2226
- }).join(' ');
2227
- }
2228
- };
2229
-
2230
- })(require('../tree'));
2231
- (function (tree) {
2232
- //
2233
- // CSS @import node
2234
- //
2235
- // The general strategy here is that we don't want to wait
2236
- // for the parsing to be completed, before we start importing
2237
- // the file. That's because in the context of a browser,
2238
- // most of the time will be spent waiting for the server to respond.
2239
- //
2240
- // On creation, we push the import path to our import queue, though
2241
- // `import,push`, we also pass it a callback, which it'll call once
2242
- // the file has been fetched, and parsed.
2243
- //
2244
- tree.Import = function (path, imports, features, index) {
2245
- var that = this;
2246
-
2247
- this.index = index;
2248
- this._path = path;
2249
- this.features = features && new(tree.Value)(features);
2250
-
2251
- // The '.less' extension is optional
2252
- if (path instanceof tree.Quoted) {
2253
- this.path = /\.(le?|c)ss(\?.*)?$/.test(path.value) ? path.value : path.value + '.less';
2254
- } else {
2255
- this.path = path.value.value || path.value;
2256
- }
2257
-
2258
- this.css = /css(\?.*)?$/.test(this.path);
2259
-
2260
- // Only pre-compile .less files
2261
- if (! this.css) {
2262
- imports.push(this.path, function (e, root) {
2263
- if (e) { e.index = index }
2264
- that.root = root || new(tree.Ruleset)([], []);
2265
- });
2266
- }
2267
- };
2268
-
2269
- //
2270
- // The actual import node doesn't return anything, when converted to CSS.
2271
- // The reason is that it's used at the evaluation stage, so that the rules
2272
- // it imports can be treated like any other rules.
2273
- //
2274
- // In `eval`, we make sure all Import nodes get evaluated, recursively, so
2275
- // we end up with a flat structure, which can easily be imported in the parent
2276
- // ruleset.
2277
- //
2278
- tree.Import.prototype = {
2279
- toCSS: function (env) {
2280
- var features = this.features ? ' ' + this.features.toCSS(env) : '';
2281
-
2282
- if (this.css) {
2283
- return "@import " + this._path.toCSS() + features + ';\n';
2284
- } else {
2285
- return "";
2286
- }
2287
- },
2288
- eval: function (env) {
2289
- var ruleset, features = this.features && this.features.eval(env);
2290
-
2291
- if (this.css) {
2292
- return this;
2293
- } else {
2294
- ruleset = new(tree.Ruleset)([], this.root.rules.slice(0));
2295
-
2296
- for (var i = 0; i < ruleset.rules.length; i++) {
2297
- if (ruleset.rules[i] instanceof tree.Import) {
2298
- Array.prototype
2299
- .splice
2300
- .apply(ruleset.rules,
2301
- [i, 1].concat(ruleset.rules[i].eval(env)));
2302
- }
2303
- }
2304
- return this.features ? new(tree.Media)(ruleset.rules, this.features.value) : ruleset.rules;
2305
- }
2306
- }
2307
- };
2308
-
2309
- })(require('../tree'));
2310
- (function (tree) {
2311
-
2312
- tree.JavaScript = function (string, index, escaped) {
2313
- this.escaped = escaped;
2314
- this.expression = string;
2315
- this.index = index;
2316
- };
2317
- tree.JavaScript.prototype = {
2318
- eval: function (env) {
2319
- var result,
2320
- that = this,
2321
- context = {};
2322
-
2323
- var expression = this.expression.replace(/@\{([\w-]+)\}/g, function (_, name) {
2324
- return tree.jsify(new(tree.Variable)('@' + name, that.index).eval(env));
2325
- });
2326
-
2327
- try {
2328
- expression = new(Function)('return (' + expression + ')');
2329
- } catch (e) {
2330
- throw { message: "JavaScript evaluation error: `" + expression + "`" ,
2331
- index: this.index };
2332
- }
2333
-
2334
- for (var k in env.frames[0].variables()) {
2335
- context[k.slice(1)] = {
2336
- value: env.frames[0].variables()[k].value,
2337
- toJS: function () {
2338
- return this.value.eval(env).toCSS();
2339
- }
2340
- };
2341
- }
2342
-
2343
- try {
2344
- result = expression.call(context);
2345
- } catch (e) {
2346
- throw { message: "JavaScript evaluation error: '" + e.name + ': ' + e.message + "'" ,
2347
- index: this.index };
2348
- }
2349
- if (typeof(result) === 'string') {
2350
- return new(tree.Quoted)('"' + result + '"', result, this.escaped, this.index);
2351
- } else if (Array.isArray(result)) {
2352
- return new(tree.Anonymous)(result.join(', '));
2353
- } else {
2354
- return new(tree.Anonymous)(result);
2355
- }
2356
- }
2357
- };
2358
-
2359
- })(require('../tree'));
2360
-
2361
- (function (tree) {
2362
-
2363
- tree.Keyword = function (value) { this.value = value };
2364
- tree.Keyword.prototype = {
2365
- eval: function () { return this },
2366
- toCSS: function () { return this.value },
2367
- compare: function (other) {
2368
- if (other instanceof tree.Keyword) {
2369
- return other.value === this.value ? 0 : 1;
2370
- } else {
2371
- return -1;
2372
- }
2373
- }
2374
- };
2375
-
2376
- tree.True = new(tree.Keyword)('true');
2377
- tree.False = new(tree.Keyword)('false');
2378
-
2379
- })(require('../tree'));
2380
- (function (tree) {
2381
-
2382
- tree.Media = function (value, features) {
2383
- var el = new(tree.Element)('&', null, 0),
2384
- selectors = [new(tree.Selector)([el])];
2385
-
2386
- this.features = new(tree.Value)(features);
2387
- this.ruleset = new(tree.Ruleset)(selectors, value);
2388
- this.ruleset.allowImports = true;
2389
- };
2390
- tree.Media.prototype = {
2391
- toCSS: function (ctx, env) {
2392
- var features = this.features.toCSS(env);
2393
-
2394
- this.ruleset.root = (ctx.length === 0 || ctx[0].multiMedia);
2395
- return '@media ' + features + (env.compress ? '{' : ' {\n ') +
2396
- this.ruleset.toCSS(ctx, env).trim().replace(/\n/g, '\n ') +
2397
- (env.compress ? '}': '\n}\n');
2398
- },
2399
- eval: function (env) {
2400
- if (!env.mediaBlocks) {
2401
- env.mediaBlocks = [];
2402
- env.mediaPath = [];
2403
- }
2404
-
2405
- var blockIndex = env.mediaBlocks.length;
2406
- env.mediaPath.push(this);
2407
- env.mediaBlocks.push(this);
2408
-
2409
- var media = new(tree.Media)([], []);
2410
- media.features = this.features.eval(env);
2411
-
2412
- env.frames.unshift(this.ruleset);
2413
- media.ruleset = this.ruleset.eval(env);
2414
- env.frames.shift();
2415
-
2416
- env.mediaBlocks[blockIndex] = media;
2417
- env.mediaPath.pop();
2418
-
2419
- return env.mediaPath.length === 0 ? media.evalTop(env) :
2420
- media.evalNested(env)
2421
- },
2422
- variable: function (name) { return tree.Ruleset.prototype.variable.call(this.ruleset, name) },
2423
- find: function () { return tree.Ruleset.prototype.find.apply(this.ruleset, arguments) },
2424
- rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.ruleset) },
2425
-
2426
- evalTop: function (env) {
2427
- var result = this;
2428
-
2429
- // Render all dependent Media blocks.
2430
- if (env.mediaBlocks.length > 1) {
2431
- var el = new(tree.Element)('&', null, 0);
2432
- var selectors = [new(tree.Selector)([el])];
2433
- result = new(tree.Ruleset)(selectors, env.mediaBlocks);
2434
- result.multiMedia = true;
2435
- }
2436
-
2437
- delete env.mediaBlocks;
2438
- delete env.mediaPath;
2439
-
2440
- return result;
2441
- },
2442
- evalNested: function (env) {
2443
- var i, value,
2444
- path = env.mediaPath.concat([this]);
2445
-
2446
- // Extract the media-query conditions separated with `,` (OR).
2447
- for (i = 0; i < path.length; i++) {
2448
- value = path[i].features instanceof tree.Value ?
2449
- path[i].features.value : path[i].features;
2450
- path[i] = Array.isArray(value) ? value : [value];
2451
- }
2452
-
2453
- // Trace all permutations to generate the resulting media-query.
2454
- //
2455
- // (a, b and c) with nested (d, e) ->
2456
- // a and d
2457
- // a and e
2458
- // b and c and d
2459
- // b and c and e
2460
- this.features = new(tree.Value)(this.permute(path).map(function (path) {
2461
- path = path.map(function (fragment) {
2462
- return fragment.toCSS ? fragment : new(tree.Anonymous)(fragment);
2463
- });
2464
-
2465
- for(i = path.length - 1; i > 0; i--) {
2466
- path.splice(i, 0, new(tree.Anonymous)("and"));
2467
- }
2468
-
2469
- return new(tree.Expression)(path);
2470
- }));
2471
-
2472
- // Fake a tree-node that doesn't output anything.
2473
- return new(tree.Ruleset)([], []);
2474
- },
2475
- permute: function (arr) {
2476
- if (arr.length === 0) {
2477
- return [];
2478
- } else if (arr.length === 1) {
2479
- return arr[0];
2480
- } else {
2481
- var result = [];
2482
- var rest = this.permute(arr.slice(1));
2483
- for (var i = 0; i < rest.length; i++) {
2484
- for (var j = 0; j < arr[0].length; j++) {
2485
- result.push([arr[0][j]].concat(rest[i]));
2486
- }
2487
- }
2488
- return result;
2489
- }
2490
- }
2491
- };
2492
-
2493
- })(require('../tree'));
2494
- (function (tree) {
2495
-
2496
- tree.mixin = {};
2497
- tree.mixin.Call = function (elements, args, index, filename, important) {
2498
- this.selector = new(tree.Selector)(elements);
2499
- this.arguments = args;
2500
- this.index = index;
2501
- this.filename = filename;
2502
- this.important = important;
2503
- };
2504
- tree.mixin.Call.prototype = {
2505
- eval: function (env) {
2506
- var mixins, args, rules = [], match = false;
2507
-
2508
- for (var i = 0; i < env.frames.length; i++) {
2509
- if ((mixins = env.frames[i].find(this.selector)).length > 0) {
2510
- args = this.arguments && this.arguments.map(function (a) { return a.eval(env) });
2511
- for (var m = 0; m < mixins.length; m++) {
2512
- if (mixins[m].match(args, env)) {
2513
- try {
2514
- Array.prototype.push.apply(
2515
- rules, mixins[m].eval(env, this.arguments, this.important).rules);
2516
- match = true;
2517
- } catch (e) {
2518
- throw { message: e.message, index: this.index, filename: this.filename, stack: e.stack };
2519
- }
2520
- }
2521
- }
2522
- if (match) {
2523
- return rules;
2524
- } else {
2525
- throw { type: 'Runtime',
2526
- message: 'No matching definition was found for `' +
2527
- this.selector.toCSS().trim() + '(' +
2528
- this.arguments.map(function (a) {
2529
- return a.toCSS();
2530
- }).join(', ') + ")`",
2531
- index: this.index, filename: this.filename };
2532
- }
2533
- }
2534
- }
2535
- throw { type: 'Name',
2536
- message: this.selector.toCSS().trim() + " is undefined",
2537
- index: this.index, filename: this.filename };
2538
- }
2539
- };
2540
-
2541
- tree.mixin.Definition = function (name, params, rules, condition, variadic) {
2542
- this.name = name;
2543
- this.selectors = [new(tree.Selector)([new(tree.Element)(null, name)])];
2544
- this.params = params;
2545
- this.condition = condition;
2546
- this.variadic = variadic;
2547
- this.arity = params.length;
2548
- this.rules = rules;
2549
- this._lookups = {};
2550
- this.required = params.reduce(function (count, p) {
2551
- if (!p.name || (p.name && !p.value)) { return count + 1 }
2552
- else { return count }
2553
- }, 0);
2554
- this.parent = tree.Ruleset.prototype;
2555
- this.frames = [];
2556
- };
2557
- tree.mixin.Definition.prototype = {
2558
- toCSS: function () { return "" },
2559
- variable: function (name) { return this.parent.variable.call(this, name) },
2560
- variables: function () { return this.parent.variables.call(this) },
2561
- find: function () { return this.parent.find.apply(this, arguments) },
2562
- rulesets: function () { return this.parent.rulesets.apply(this) },
2563
-
2564
- evalParams: function (env, args) {
2565
- var frame = new(tree.Ruleset)(null, []), varargs;
2566
-
2567
- for (var i = 0, val, name; i < this.params.length; i++) {
2568
- if (name = this.params[i].name) {
2569
- if (this.params[i].variadic && args) {
2570
- varargs = [];
2571
- for (var j = i; j < args.length; j++) {
2572
- varargs.push(args[j].eval(env));
2573
- }
2574
- frame.rules.unshift(new(tree.Rule)(name, new(tree.Expression)(varargs).eval(env)));
2575
- } else if (val = (args && args[i]) || this.params[i].value) {
2576
- frame.rules.unshift(new(tree.Rule)(name, val.eval(env)));
2577
- } else {
2578
- throw { type: 'Runtime', message: "wrong number of arguments for " + this.name +
2579
- ' (' + args.length + ' for ' + this.arity + ')' };
2580
- }
2581
- }
2582
- }
2583
- return frame;
2584
- },
2585
- eval: function (env, args, important) {
2586
- var frame = this.evalParams(env, args), context, _arguments = [], rules, start;
2587
-
2588
- for (var i = 0; i < Math.max(this.params.length, args && args.length); i++) {
2589
- _arguments.push(args[i] || this.params[i].value);
2590
- }
2591
- frame.rules.unshift(new(tree.Rule)('@arguments', new(tree.Expression)(_arguments).eval(env)));
2592
-
2593
- rules = important ?
2594
- this.rules.map(function (r) {
2595
- return new(tree.Rule)(r.name, r.value, '!important', r.index);
2596
- }) : this.rules.slice(0);
2597
-
2598
- return new(tree.Ruleset)(null, rules).eval({
2599
- frames: [this, frame].concat(this.frames, env.frames)
2600
- });
2601
- },
2602
- match: function (args, env) {
2603
- var argsLength = (args && args.length) || 0, len, frame;
2604
-
2605
- if (! this.variadic) {
2606
- if (argsLength < this.required) { return false }
2607
- if (argsLength > this.params.length) { return false }
2608
- if ((this.required > 0) && (argsLength > this.params.length)) { return false }
2609
- }
2610
-
2611
- if (this.condition && !this.condition.eval({
2612
- frames: [this.evalParams(env, args)].concat(env.frames)
2613
- })) { return false }
2614
-
2615
- len = Math.min(argsLength, this.arity);
2616
-
2617
- for (var i = 0; i < len; i++) {
2618
- if (!this.params[i].name) {
2619
- if (args[i].eval(env).toCSS() != this.params[i].value.eval(env).toCSS()) {
2620
- return false;
2621
- }
2622
- }
2623
- }
2624
- return true;
2625
- }
2626
- };
2627
-
2628
- })(require('../tree'));
2629
- (function (tree) {
2630
-
2631
- tree.Operation = function (op, operands) {
2632
- this.op = op.trim();
2633
- this.operands = operands;
2634
- };
2635
- tree.Operation.prototype.eval = function (env) {
2636
- var a = this.operands[0].eval(env),
2637
- b = this.operands[1].eval(env),
2638
- temp;
2639
-
2640
- if (a instanceof tree.Dimension && b instanceof tree.Color) {
2641
- if (this.op === '*' || this.op === '+') {
2642
- temp = b, b = a, a = temp;
2643
- } else {
2644
- throw { name: "OperationError",
2645
- message: "Can't substract or divide a color from a number" };
2646
- }
2647
- }
2648
- return a.operate(this.op, b);
2649
- };
2650
-
2651
- tree.operate = function (op, a, b) {
2652
- switch (op) {
2653
- case '+': return a + b;
2654
- case '-': return a - b;
2655
- case '*': return a * b;
2656
- case '/': return a / b;
2657
- }
2658
- };
2659
-
2660
- })(require('../tree'));
2661
-
2662
- (function (tree) {
2663
-
2664
- tree.Paren = function (node) {
2665
- this.value = node;
2666
- };
2667
- tree.Paren.prototype = {
2668
- toCSS: function (env) {
2669
- return '(' + this.value.toCSS(env) + ')';
2670
- },
2671
- eval: function (env) {
2672
- return new(tree.Paren)(this.value.eval(env));
2673
- }
2674
- };
2675
-
2676
- })(require('../tree'));
2677
- (function (tree) {
2678
-
2679
- tree.Quoted = function (str, content, escaped, i) {
2680
- this.escaped = escaped;
2681
- this.value = content || '';
2682
- this.quote = str.charAt(0);
2683
- this.index = i;
2684
- };
2685
- tree.Quoted.prototype = {
2686
- toCSS: function () {
2687
- if (this.escaped) {
2688
- return this.value;
2689
- } else {
2690
- return this.quote + this.value + this.quote;
2691
- }
2692
- },
2693
- eval: function (env) {
2694
- var that = this;
2695
- var value = this.value.replace(/`([^`]+)`/g, function (_, exp) {
2696
- return new(tree.JavaScript)(exp, that.index, true).eval(env).value;
2697
- }).replace(/@\{([\w-]+)\}/g, function (_, name) {
2698
- var v = new(tree.Variable)('@' + name, that.index).eval(env);
2699
- return ('value' in v) ? v.value : v.toCSS();
2700
- });
2701
- return new(tree.Quoted)(this.quote + value + this.quote, value, this.escaped, this.index);
2702
- }
2703
- };
2704
-
2705
- })(require('../tree'));
2706
- (function (tree) {
2707
-
2708
- tree.Rule = function (name, value, important, index, inline) {
2709
- this.name = name;
2710
- this.value = (value instanceof tree.Value) ? value : new(tree.Value)([value]);
2711
- this.important = important ? ' ' + important.trim() : '';
2712
- this.index = index;
2713
- this.inline = inline || false;
2714
-
2715
- if (name.charAt(0) === '@') {
2716
- this.variable = true;
2717
- } else { this.variable = false }
2718
- };
2719
- tree.Rule.prototype.toCSS = function (env) {
2720
- if (this.variable) { return "" }
2721
- else {
2722
- return this.name + (env.compress ? ':' : ': ') +
2723
- this.value.toCSS(env) +
2724
- this.important + (this.inline ? "" : ";");
2725
- }
2726
- };
2727
-
2728
- tree.Rule.prototype.eval = function (context) {
2729
- return new(tree.Rule)(this.name,
2730
- this.value.eval(context),
2731
- this.important,
2732
- this.index, this.inline);
2733
- };
2734
-
2735
- tree.Shorthand = function (a, b) {
2736
- this.a = a;
2737
- this.b = b;
2738
- };
2739
-
2740
- tree.Shorthand.prototype = {
2741
- toCSS: function (env) {
2742
- return this.a.toCSS(env) + "/" + this.b.toCSS(env);
2743
- },
2744
- eval: function () { return this }
2745
- };
2746
-
2747
- })(require('../tree'));
2748
- (function (tree) {
2749
-
2750
- tree.Ruleset = function (selectors, rules, strictImports) {
2751
- this.selectors = selectors;
2752
- this.rules = rules;
2753
- this._lookups = {};
2754
- this.strictImports = strictImports;
2755
- };
2756
- tree.Ruleset.prototype = {
2757
- eval: function (env) {
2758
- var selectors = this.selectors && this.selectors.map(function (s) { return s.eval(env) });
2759
- var ruleset = new(tree.Ruleset)(selectors, this.rules.slice(0), this.strictImports);
2760
-
2761
- ruleset.root = this.root;
2762
- ruleset.allowImports = this.allowImports;
2763
-
2764
- // push the current ruleset to the frames stack
2765
- env.frames.unshift(ruleset);
2766
-
2767
- // Evaluate imports
2768
- if (ruleset.root || ruleset.allowImports || !ruleset.strictImports) {
2769
- for (var i = 0; i < ruleset.rules.length; i++) {
2770
- if (ruleset.rules[i] instanceof tree.Import) {
2771
- Array.prototype.splice
2772
- .apply(ruleset.rules, [i, 1].concat(ruleset.rules[i].eval(env)));
2773
- }
2774
- }
2775
- }
2776
-
2777
- // Store the frames around mixin definitions,
2778
- // so they can be evaluated like closures when the time comes.
2779
- for (var i = 0; i < ruleset.rules.length; i++) {
2780
- if (ruleset.rules[i] instanceof tree.mixin.Definition) {
2781
- ruleset.rules[i].frames = env.frames.slice(0);
2782
- }
2783
- }
2784
-
2785
- // Evaluate mixin calls.
2786
- for (var i = 0; i < ruleset.rules.length; i++) {
2787
- if (ruleset.rules[i] instanceof tree.mixin.Call) {
2788
- Array.prototype.splice
2789
- .apply(ruleset.rules, [i, 1].concat(ruleset.rules[i].eval(env)));
2790
- }
2791
- }
2792
-
2793
- // Evaluate everything else
2794
- for (var i = 0, rule; i < ruleset.rules.length; i++) {
2795
- rule = ruleset.rules[i];
2796
-
2797
- if (! (rule instanceof tree.mixin.Definition)) {
2798
- ruleset.rules[i] = rule.eval ? rule.eval(env) : rule;
2799
- }
2800
- }
2801
-
2802
- // Pop the stack
2803
- env.frames.shift();
2804
-
2805
- return ruleset;
2806
- },
2807
- match: function (args) {
2808
- return !args || args.length === 0;
2809
- },
2810
- variables: function () {
2811
- if (this._variables) { return this._variables }
2812
- else {
2813
- return this._variables = this.rules.reduce(function (hash, r) {
2814
- if (r instanceof tree.Rule && r.variable === true) {
2815
- hash[r.name] = r;
2816
- }
2817
- return hash;
2818
- }, {});
2819
- }
2820
- },
2821
- variable: function (name) {
2822
- return this.variables()[name];
2823
- },
2824
- rulesets: function () {
2825
- if (this._rulesets) { return this._rulesets }
2826
- else {
2827
- return this._rulesets = this.rules.filter(function (r) {
2828
- return (r instanceof tree.Ruleset) || (r instanceof tree.mixin.Definition);
2829
- });
2830
- }
2831
- },
2832
- find: function (selector, self) {
2833
- self = self || this;
2834
- var rules = [], rule, match,
2835
- key = selector.toCSS();
2836
-
2837
- if (key in this._lookups) { return this._lookups[key] }
2838
-
2839
- this.rulesets().forEach(function (rule) {
2840
- if (rule !== self) {
2841
- for (var j = 0; j < rule.selectors.length; j++) {
2842
- if (match = selector.match(rule.selectors[j])) {
2843
- if (selector.elements.length > rule.selectors[j].elements.length) {
2844
- Array.prototype.push.apply(rules, rule.find(
2845
- new(tree.Selector)(selector.elements.slice(1)), self));
2846
- } else {
2847
- rules.push(rule);
2848
- }
2849
- break;
2850
- }
2851
- }
2852
- }
2853
- });
2854
- return this._lookups[key] = rules;
2855
- },
2856
- //
2857
- // Entry point for code generation
2858
- //
2859
- // `context` holds an array of arrays.
2860
- //
2861
- toCSS: function (context, env) {
2862
- var css = [], // The CSS output
2863
- rules = [], // node.Rule instances
2864
- rulesets = [], // node.Ruleset instances
2865
- paths = [], // Current selectors
2866
- selector, // The fully rendered selector
2867
- rule;
2868
-
2869
- if (! this.root) {
2870
- if (context.length === 0) {
2871
- paths = this.selectors.map(function (s) { return [s] });
2872
- } else {
2873
- this.joinSelectors(paths, context, this.selectors);
2874
- }
2875
- }
2876
-
2877
- // Compile rules and rulesets
2878
- for (var i = 0; i < this.rules.length; i++) {
2879
- rule = this.rules[i];
2880
-
2881
- if (rule.rules || (rule instanceof tree.Directive) || (rule instanceof tree.Media)) {
2882
- rulesets.push(rule.toCSS(paths, env));
2883
- } else if (rule instanceof tree.Comment) {
2884
- if (!rule.silent) {
2885
- if (this.root) {
2886
- rulesets.push(rule.toCSS(env));
2887
- } else {
2888
- rules.push(rule.toCSS(env));
2889
- }
2890
- }
2891
- } else {
2892
- if (rule.toCSS && !rule.variable) {
2893
- rules.push(rule.toCSS(env));
2894
- } else if (rule.value && !rule.variable) {
2895
- rules.push(rule.value.toString());
2896
- }
2897
- }
2898
- }
2899
-
2900
- rulesets = rulesets.join('');
2901
-
2902
- // If this is the root node, we don't render
2903
- // a selector, or {}.
2904
- // Otherwise, only output if this ruleset has rules.
2905
- if (this.root) {
2906
- css.push(rules.join(env.compress ? '' : '\n'));
2907
- } else {
2908
- if (rules.length > 0) {
2909
- selector = paths.map(function (p) {
2910
- return p.map(function (s) {
2911
- return s.toCSS(env);
2912
- }).join('').trim();
2913
- }).join( env.compress ? ',' : ',\n');
2914
-
2915
- css.push(selector,
2916
- (env.compress ? '{' : ' {\n ') +
2917
- rules.join(env.compress ? '' : '\n ') +
2918
- (env.compress ? '}' : '\n}\n'));
2919
- }
2920
- }
2921
- css.push(rulesets);
2922
-
2923
- return css.join('') + (env.compress ? '\n' : '');
2924
- },
2925
-
2926
- joinSelectors: function (paths, context, selectors) {
2927
- for (var s = 0; s < selectors.length; s++) {
2928
- this.joinSelector(paths, context, selectors[s]);
2929
- }
2930
- },
2931
-
2932
- joinSelector: function (paths, context, selector) {
2933
- var before = [], after = [], beforeElements = [],
2934
- afterElements = [], hasParentSelector = false, el;
2935
-
2936
- for (var i = 0; i < selector.elements.length; i++) {
2937
- el = selector.elements[i];
2938
- if (el.combinator.value.charAt(0) === '&') {
2939
- hasParentSelector = true;
2940
- }
2941
- if (hasParentSelector) afterElements.push(el);
2942
- else beforeElements.push(el);
2943
- }
2944
-
2945
- if (! hasParentSelector) {
2946
- afterElements = beforeElements;
2947
- beforeElements = [];
2948
- }
2949
-
2950
- if (beforeElements.length > 0) {
2951
- before.push(new(tree.Selector)(beforeElements));
2952
- }
2953
-
2954
- if (afterElements.length > 0) {
2955
- after.push(new(tree.Selector)(afterElements));
2956
- }
2957
-
2958
- for (var c = 0; c < context.length; c++) {
2959
- paths.push(before.concat(context[c]).concat(after));
2960
- }
2961
- }
2962
- };
2963
- })(require('../tree'));
2964
- (function (tree) {
2965
-
2966
- tree.Selector = function (elements) {
2967
- this.elements = elements;
2968
- if (this.elements[0].combinator.value === "") {
2969
- this.elements[0].combinator.value = ' ';
2970
- }
2971
- };
2972
- tree.Selector.prototype.match = function (other) {
2973
- var len = this.elements.length,
2974
- olen = other.elements.length,
2975
- max = Math.min(len, olen);
2976
-
2977
- if (len < olen) {
2978
- return false;
2979
- } else {
2980
- for (var i = 0; i < max; i++) {
2981
- if (this.elements[i].value !== other.elements[i].value) {
2982
- return false;
2983
- }
2984
- }
2985
- }
2986
- return true;
2987
- };
2988
- tree.Selector.prototype.eval = function (env) {
2989
- return new(tree.Selector)(this.elements.map(function (e) {
2990
- return e.eval(env);
2991
- }));
2992
- };
2993
- tree.Selector.prototype.toCSS = function (env) {
2994
- if (this._css) { return this._css }
2995
-
2996
- return this._css = this.elements.map(function (e) {
2997
- if (typeof(e) === 'string') {
2998
- return ' ' + e.trim();
2999
- } else {
3000
- return e.toCSS(env);
3001
- }
3002
- }).join('');
3003
- };
3004
-
3005
- })(require('../tree'));
3006
- (function (tree) {
3007
-
3008
- tree.URL = function (val, paths) {
3009
- if (val.data) {
3010
- this.attrs = val;
3011
- } else {
3012
- // Add the base path if the URL is relative and we are in the browser
3013
- if (typeof(window) !== 'undefined' && !/^(?:https?:\/\/|file:\/\/|data:|\/)/.test(val.value) && paths.length > 0) {
3014
- val.value = paths[0] + (val.value.charAt(0) === '/' ? val.value.slice(1) : val.value);
3015
- }
3016
- this.value = val;
3017
- this.paths = paths;
3018
- }
3019
- };
3020
- tree.URL.prototype = {
3021
- toCSS: function () {
3022
- return "url(" + (this.attrs ? 'data:' + this.attrs.mime + this.attrs.charset + this.attrs.base64 + this.attrs.data
3023
- : this.value.toCSS()) + ")";
3024
- },
3025
- eval: function (ctx) {
3026
- return this.attrs ? this : new(tree.URL)(this.value.eval(ctx), this.paths);
3027
- }
3028
- };
3029
-
3030
- })(require('../tree'));
3031
- (function (tree) {
3032
-
3033
- tree.Value = function (value) {
3034
- this.value = value;
3035
- this.is = 'value';
3036
- };
3037
- tree.Value.prototype = {
3038
- eval: function (env) {
3039
- if (this.value.length === 1) {
3040
- return this.value[0].eval(env);
3041
- } else {
3042
- return new(tree.Value)(this.value.map(function (v) {
3043
- return v.eval(env);
3044
- }));
3045
- }
3046
- },
3047
- toCSS: function (env) {
3048
- return this.value.map(function (e) {
3049
- return e.toCSS(env);
3050
- }).join(env.compress ? ',' : ', ');
3051
- }
3052
- };
3053
-
3054
- })(require('../tree'));
3055
- (function (tree) {
3056
-
3057
- tree.Variable = function (name, index, file) { this.name = name, this.index = index, this.file = file };
3058
- tree.Variable.prototype = {
3059
- eval: function (env) {
3060
- var variable, v, name = this.name;
3061
-
3062
- if (name.indexOf('@@') == 0) {
3063
- name = '@' + new(tree.Variable)(name.slice(1)).eval(env).value;
3064
- }
3065
-
3066
- if (variable = tree.find(env.frames, function (frame) {
3067
- if (v = frame.variable(name)) {
3068
- return v.value.eval(env);
3069
- }
3070
- })) { return variable }
3071
- else {
3072
- throw { type: 'Name',
3073
- message: "variable " + name + " is undefined",
3074
- filename: this.file,
3075
- index: this.index };
3076
- }
3077
- }
3078
- };
3079
-
3080
- })(require('../tree'));
3081
- (function (tree) {
3082
-
3083
- tree.find = function (obj, fun) {
3084
- for (var i = 0, r; i < obj.length; i++) {
3085
- if (r = fun.call(obj, obj[i])) { return r }
3086
- }
3087
- return null;
3088
- };
3089
- tree.jsify = function (obj) {
3090
- if (Array.isArray(obj.value) && (obj.value.length > 1)) {
3091
- return '[' + obj.value.map(function (v) { return v.toCSS(false) }).join(', ') + ']';
3092
- } else {
3093
- return obj.toCSS(false);
3094
- }
3095
- };
3096
-
3097
- })(require('./tree'));
3098
- //
3099
- // browser.js - client-side engine
3100
- //
3101
-
3102
- var isFileProtocol = (location.protocol === 'file:' ||
3103
- location.protocol === 'chrome:' ||
3104
- location.protocol === 'chrome-extension:' ||
3105
- location.protocol === 'resource:');
3106
-
3107
- less.env = less.env || (location.hostname == '127.0.0.1' ||
3108
- location.hostname == '0.0.0.0' ||
3109
- location.hostname == 'localhost' ||
3110
- location.port.length > 0 ||
3111
- isFileProtocol ? 'development'
3112
- : 'production');
3113
-
3114
- // Load styles asynchronously (default: false)
3115
- //
3116
- // This is set to `false` by default, so that the body
3117
- // doesn't start loading before the stylesheets are parsed.
3118
- // Setting this to `true` can result in flickering.
3119
- //
3120
- less.async = false;
3121
-
3122
- // Interval between watch polls
3123
- less.poll = less.poll || (isFileProtocol ? 1000 : 1500);
3124
-
3125
- //
3126
- // Watch mode
3127
- //
3128
- less.watch = function () { return this.watchMode = true };
3129
- less.unwatch = function () { return this.watchMode = false };
3130
-
3131
- if (less.env === 'development') {
3132
- less.optimization = 0;
3133
-
3134
- if (/!watch/.test(location.hash)) {
3135
- less.watch();
3136
- }
3137
- less.watchTimer = setInterval(function () {
3138
- if (less.watchMode) {
3139
- loadStyleSheets(function (e, root, _, sheet, env) {
3140
- if (root) {
3141
- createCSS(root.toCSS(), sheet, env.lastModified);
3142
- }
3143
- });
3144
- }
3145
- }, less.poll);
3146
- } else {
3147
- less.optimization = 3;
3148
- }
3149
-
3150
- var cache;
3151
-
3152
- try {
3153
- cache = (typeof(window.localStorage) === 'undefined') ? null : window.localStorage;
3154
- } catch (_) {
3155
- cache = null;
3156
- }
3157
-
3158
- //
3159
- // Get all <link> tags with the 'rel' attribute set to "stylesheet/less"
3160
- //
3161
- var links = document.getElementsByTagName('link');
3162
- var typePattern = /^text\/(x-)?less$/;
3163
-
3164
- less.sheets = [];
3165
-
3166
- for (var i = 0; i < links.length; i++) {
3167
- if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
3168
- (links[i].type.match(typePattern)))) {
3169
- less.sheets.push(links[i]);
3170
- }
3171
- }
3172
-
3173
-
3174
- less.refresh = function (reload) {
3175
- var startTime, endTime;
3176
- startTime = endTime = new(Date);
3177
-
3178
- loadStyleSheets(function (e, root, _, sheet, env) {
3179
- if (env.local) {
3180
- log("loading " + sheet.href + " from cache.");
3181
- } else {
3182
- log("parsed " + sheet.href + " successfully.");
3183
- createCSS(root.toCSS(), sheet, env.lastModified);
3184
- }
3185
- log("css for " + sheet.href + " generated in " + (new(Date) - endTime) + 'ms');
3186
- (env.remaining === 0) && log("css generated in " + (new(Date) - startTime) + 'ms');
3187
- endTime = new(Date);
3188
- }, reload);
3189
-
3190
- loadStyles();
3191
- };
3192
- less.refreshStyles = loadStyles;
3193
-
3194
- less.refresh(less.env === 'development');
3195
-
3196
- function loadStyles() {
3197
- var styles = document.getElementsByTagName('style');
3198
- for (var i = 0; i < styles.length; i++) {
3199
- if (styles[i].type.match(typePattern)) {
3200
- new(less.Parser)().parse(styles[i].innerHTML || '', function (e, tree) {
3201
- var css = tree.toCSS();
3202
- var style = styles[i];
3203
- style.type = 'text/css';
3204
- if (style.styleSheet) {
3205
- style.styleSheet.cssText = css;
3206
- } else {
3207
- style.innerHTML = css;
3208
- }
3209
- });
3210
- }
3211
- }
3212
- }
3213
-
3214
- function loadStyleSheets(callback, reload) {
3215
- for (var i = 0; i < less.sheets.length; i++) {
3216
- loadStyleSheet(less.sheets[i], callback, reload, less.sheets.length - (i + 1));
3217
- }
3218
- }
3219
-
3220
- function loadStyleSheet(sheet, callback, reload, remaining) {
3221
- var url = window.location.href.replace(/[#?].*$/, '');
3222
- var href = sheet.href.replace(/\?.*$/, '');
3223
- var css = cache && cache.getItem(href);
3224
- var timestamp = cache && cache.getItem(href + ':timestamp');
3225
- var styles = { css: css, timestamp: timestamp };
3226
-
3227
- // Stylesheets in IE don't always return the full path
3228
- if (! /^(https?|file):/.test(href)) {
3229
- if (href.charAt(0) == "/") {
3230
- href = window.location.protocol + "//" + window.location.host + href;
3231
- } else {
3232
- href = url.slice(0, url.lastIndexOf('/') + 1) + href;
3233
- }
3234
- }
3235
- var filename = href.match(/([^\/]+)$/)[1];
3236
-
3237
- xhr(sheet.href, sheet.type, function (data, lastModified) {
3238
- if (!reload && styles && lastModified &&
3239
- (new(Date)(lastModified).valueOf() ===
3240
- new(Date)(styles.timestamp).valueOf())) {
3241
- // Use local copy
3242
- createCSS(styles.css, sheet);
3243
- callback(null, null, data, sheet, { local: true, remaining: remaining });
3244
- } else {
3245
- // Use remote copy (re-parse)
3246
- try {
3247
- new(less.Parser)({
3248
- optimization: less.optimization,
3249
- paths: [href.replace(/[\w\.-]+$/, '')],
3250
- mime: sheet.type,
3251
- filename: filename
3252
- }).parse(data, function (e, root) {
3253
- if (e) { return error(e, href) }
3254
- try {
3255
- callback(e, root, data, sheet, { local: false, lastModified: lastModified, remaining: remaining });
3256
- removeNode(document.getElementById('less-error-message:' + extractId(href)));
3257
- } catch (e) {
3258
- error(e, href);
3259
- }
3260
- });
3261
- } catch (e) {
3262
- error(e, href);
3263
- }
3264
- }
3265
- }, function (status, url) {
3266
- throw new(Error)("Couldn't load " + url + " (" + status + ")");
3267
- });
3268
- }
3269
-
3270
- function extractId(href) {
3271
- return href.replace(/^[a-z]+:\/\/?[^\/]+/, '' ) // Remove protocol & domain
3272
- .replace(/^\//, '' ) // Remove root /
3273
- .replace(/\?.*$/, '' ) // Remove query
3274
- .replace(/\.[^\.\/]+$/, '' ) // Remove file extension
3275
- .replace(/[^\.\w-]+/g, '-') // Replace illegal characters
3276
- .replace(/\./g, ':'); // Replace dots with colons(for valid id)
3277
- }
3278
-
3279
- function createCSS(styles, sheet, lastModified) {
3280
- var css;
3281
-
3282
- // Strip the query-string
3283
- var href = sheet.href ? sheet.href.replace(/\?.*$/, '') : '';
3284
-
3285
- // If there is no title set, use the filename, minus the extension
3286
- var id = 'less:' + (sheet.title || extractId(href));
3287
-
3288
- // If the stylesheet doesn't exist, create a new node
3289
- if ((css = document.getElementById(id)) === null) {
3290
- css = document.createElement('style');
3291
- css.type = 'text/css';
3292
- css.media = sheet.media || 'screen';
3293
- css.id = id;
3294
- document.getElementsByTagName('head')[0].appendChild(css);
3295
- }
3296
-
3297
- if (css.styleSheet) { // IE
3298
- try {
3299
- css.styleSheet.cssText = styles;
3300
- } catch (e) {
3301
- throw new(Error)("Couldn't reassign styleSheet.cssText.");
3302
- }
3303
- } else {
3304
- (function (node) {
3305
- if (css.childNodes.length > 0) {
3306
- if (css.firstChild.nodeValue !== node.nodeValue) {
3307
- css.replaceChild(node, css.firstChild);
3308
- }
3309
- } else {
3310
- css.appendChild(node);
3311
- }
3312
- })(document.createTextNode(styles));
3313
- }
3314
-
3315
- // Don't update the local store if the file wasn't modified
3316
- if (lastModified && cache) {
3317
- log('saving ' + href + ' to cache.');
3318
- cache.setItem(href, styles);
3319
- cache.setItem(href + ':timestamp', lastModified);
3320
- }
3321
- }
3322
-
3323
- function xhr(url, type, callback, errback) {
3324
- var xhr = getXMLHttpRequest();
3325
- var async = isFileProtocol ? false : less.async;
3326
-
3327
- if (typeof(xhr.overrideMimeType) === 'function') {
3328
- xhr.overrideMimeType('text/css');
3329
- }
3330
- xhr.open('GET', url, async);
3331
- xhr.setRequestHeader('Accept', type || 'text/x-less, text/css; q=0.9, */*; q=0.5');
3332
- xhr.send(null);
3333
-
3334
- if (isFileProtocol) {
3335
- if (xhr.status === 0 || (xhr.status >= 200 && xhr.status < 300)) {
3336
- callback(xhr.responseText);
3337
- } else {
3338
- errback(xhr.status, url);
3339
- }
3340
- } else if (async) {
3341
- xhr.onreadystatechange = function () {
3342
- if (xhr.readyState == 4) {
3343
- handleResponse(xhr, callback, errback);
3344
- }
3345
- };
3346
- } else {
3347
- handleResponse(xhr, callback, errback);
3348
- }
3349
-
3350
- function handleResponse(xhr, callback, errback) {
3351
- if (xhr.status >= 200 && xhr.status < 300) {
3352
- callback(xhr.responseText,
3353
- xhr.getResponseHeader("Last-Modified"));
3354
- } else if (typeof(errback) === 'function') {
3355
- errback(xhr.status, url);
3356
- }
3357
- }
3358
- }
3359
-
3360
- function getXMLHttpRequest() {
3361
- if (window.XMLHttpRequest) {
3362
- return new(XMLHttpRequest);
3363
- } else {
3364
- try {
3365
- return new(ActiveXObject)("MSXML2.XMLHTTP.3.0");
3366
- } catch (e) {
3367
- log("browser doesn't support AJAX.");
3368
- return null;
3369
- }
3370
- }
3371
- }
3372
-
3373
- function removeNode(node) {
3374
- return node && node.parentNode.removeChild(node);
3375
- }
3376
-
3377
- function log(str) {
3378
- if (less.env == 'development' && typeof(console) !== "undefined") { console.log('less: ' + str) }
3379
- }
3380
-
3381
- function error(e, href) {
3382
- var id = 'less-error-message:' + extractId(href);
3383
- var template = '<li><label>{line}</label><pre class="{class}">{content}</pre></li>';
3384
- var elem = document.createElement('div'), timer, content, error = [];
3385
- var filename = e.filename || href;
3386
-
3387
- elem.id = id;
3388
- elem.className = "less-error-message";
3389
-
3390
- content = '<h3>' + (e.message || 'There is an error in your .less file') +
3391
- '</h3>' + '<p>in <a href="' + filename + '">' + filename + "</a> ";
3392
-
3393
- var errorline = function (e, i, classname) {
3394
- if (e.extract[i]) {
3395
- error.push(template.replace(/\{line\}/, parseInt(e.line) + (i - 1))
3396
- .replace(/\{class\}/, classname)
3397
- .replace(/\{content\}/, e.extract[i]));
3398
- }
3399
- };
3400
-
3401
- if (e.stack) {
3402
- content += '<br/>' + e.stack.split('\n').slice(1).join('<br/>');
3403
- } else if (e.extract) {
3404
- errorline(e, 0, '');
3405
- errorline(e, 1, 'line');
3406
- errorline(e, 2, '');
3407
- content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':</p>' +
3408
- '<ul>' + error.join('') + '</ul>';
3409
- }
3410
- elem.innerHTML = content;
3411
-
3412
- // CSS for error messages
3413
- createCSS([
3414
- '.less-error-message ul, .less-error-message li {',
3415
- 'list-style-type: none;',
3416
- 'margin-right: 15px;',
3417
- 'padding: 4px 0;',
3418
- 'margin: 0;',
3419
- '}',
3420
- '.less-error-message label {',
3421
- 'font-size: 12px;',
3422
- 'margin-right: 15px;',
3423
- 'padding: 4px 0;',
3424
- 'color: #cc7777;',
3425
- '}',
3426
- '.less-error-message pre {',
3427
- 'color: #dd6666;',
3428
- 'padding: 4px 0;',
3429
- 'margin: 0;',
3430
- 'display: inline-block;',
3431
- '}',
3432
- '.less-error-message pre.line {',
3433
- 'color: #ff0000;',
3434
- '}',
3435
- '.less-error-message h3 {',
3436
- 'font-size: 20px;',
3437
- 'font-weight: bold;',
3438
- 'padding: 15px 0 5px 0;',
3439
- 'margin: 0;',
3440
- '}',
3441
- '.less-error-message a {',
3442
- 'color: #10a',
3443
- '}',
3444
- '.less-error-message .error {',
3445
- 'color: red;',
3446
- 'font-weight: bold;',
3447
- 'padding-bottom: 2px;',
3448
- 'border-bottom: 1px dashed red;',
3449
- '}'
3450
- ].join('\n'), { title: 'error-message' });
3451
-
3452
- elem.style.cssText = [
3453
- "font-family: Arial, sans-serif",
3454
- "border: 1px solid #e00",
3455
- "background-color: #eee",
3456
- "border-radius: 5px",
3457
- "-webkit-border-radius: 5px",
3458
- "-moz-border-radius: 5px",
3459
- "color: #e00",
3460
- "padding: 15px",
3461
- "margin-bottom: 15px"
3462
- ].join(';');
3463
-
3464
- if (less.env == 'development') {
3465
- timer = setInterval(function () {
3466
- if (document.body) {
3467
- if (document.getElementById(id)) {
3468
- document.body.replaceChild(elem, document.getElementById(id));
3469
- } else {
3470
- document.body.insertBefore(elem, document.body.firstChild);
3471
- }
3472
- clearInterval(timer);
3473
- }
3474
- }, 10);
3475
- }
3476
- }
3477
-
3478
- })(window);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
libraries/less/dist/less-1.3.0.min.js DELETED
@@ -1,9 +0,0 @@
1
- //
2
- // LESS - Leaner CSS v1.3.0
3
- // http://lesscss.org
4
- //
5
- // Copyright (c) 2009-2011, Alexis Sellier
6
- // Licensed under the Apache 2.0 License.
7
- //
8
- (function(a,b){function c(b){return a.less[b.split("/")[1]]}function l(){var a=document.getElementsByTagName("style");for(var b=0;b<a.length;b++)a[b].type.match(j)&&(new d.Parser).parse(a[b].innerHTML||"",function(c,d){var e=d.toCSS(),f=a[b];f.type="text/css",f.styleSheet?f.styleSheet.cssText=e:f.innerHTML=e})}function m(a,b){for(var c=0;c<d.sheets.length;c++)n(d.sheets[c],a,b,d.sheets.length-(c+1))}function n(b,c,e,f){var h=a.location.href.replace(/[#?].*$/,""),i=b.href.replace(/\?.*$/,""),j=g&&g.getItem(i),k=g&&g.getItem(i+":timestamp"),l={css:j,timestamp:k};/^(https?|file):/.test(i)||(i.charAt(0)=="/"?i=a.location.protocol+"//"+a.location.host+i:i=h.slice(0,h.lastIndexOf("/")+1)+i);var m=i.match(/([^\/]+)$/)[1];q(b.href,b.type,function(a,g){if(!e&&l&&g&&(new Date(g)).valueOf()===(new Date(l.timestamp)).valueOf())p(l.css,b),c(null,null,a,b,{local:!0,remaining:f});else try{(new d.Parser({optimization:d.optimization,paths:[i.replace(/[\w\.-]+$/,"")],mime:b.type,filename:m})).parse(a,function(d,e){if(d)return u(d,i);try{c(d,e,a,b,{local:!1,lastModified:g,remaining:f}),s(document.getElementById("less-error-message:"+o(i)))}catch(d){u(d,i)}})}catch(h){u(h,i)}},function(a,b){throw new Error("Couldn't load "+b+" ("+a+")")})}function o(a){return a.replace(/^[a-z]+:\/\/?[^\/]+/,"").replace(/^\//,"").replace(/\?.*$/,"").replace(/\.[^\.\/]+$/,"").replace(/[^\.\w-]+/g,"-").replace(/\./g,":")}function p(a,b,c){var d,e=b.href?b.href.replace(/\?.*$/,""):"",f="less:"+(b.title||o(e));(d=document.getElementById(f))===null&&(d=document.createElement("style"),d.type="text/css",d.media=b.media||"screen",d.id=f,document.getElementsByTagName("head")[0].appendChild(d));if(d.styleSheet)try{d.styleSheet.cssText=a}catch(h){throw new Error("Couldn't reassign styleSheet.cssText.")}else(function(a){d.childNodes.length>0?d.firstChild.nodeValue!==a.nodeValue&&d.replaceChild(a,d.firstChild):d.appendChild(a)})(document.createTextNode(a));c&&g&&(t("saving "+e+" to cache."),g.setItem(e,a),g.setItem(e+":timestamp",c))}function q(a,b,c,e){function i(b,c,d){b.status>=200&&b.status<300?c(b.responseText,b.getResponseHeader("Last-Modified")):typeof d=="function"&&d(b.status,a)}var g=r(),h=f?!1:d.async;typeof g.overrideMimeType=="function"&&g.overrideMimeType("text/css"),g.open("GET",a,h),g.setRequestHeader("Accept",b||"text/x-less, text/css; q=0.9, */*; q=0.5"),g.send(null),f?g.status===0||g.status>=200&&g.status<300?c(g.responseText):e(g.status,a):h?g.onreadystatechange=function(){g.readyState==4&&i(g,c,e)}:i(g,c,e)}function r(){if(a.XMLHttpRequest)return new XMLHttpRequest;try{return new ActiveXObject("MSXML2.XMLHTTP.3.0")}catch(b){return t("browser doesn't support AJAX."),null}}function s(a){return a&&a.parentNode.removeChild(a)}function t(a){d.env=="development"&&typeof console!="undefined"&&console.log("less: "+a)}function u(a,b){var c="less-error-message:"+o(b),e='<li><label>{line}</label><pre class="{class}">{content}</pre></li>',f=document.createElement("div"),g,h,i=[],j=a.filename||b;f.id=c,f.className="less-error-message",h="<h3>"+(a.message||"There is an error in your .less file")+"</h3>"+'<p>in <a href="'+j+'">'+j+"</a> ";var k=function(a,b,c){a.extract[b]&&i.push(e.replace(/\{line\}/,parseInt(a.line)+(b-1)).replace(/\{class\}/,c).replace(/\{content\}/,a.extract[b]))};a.stack?h+="<br/>"+a.stack.split("\n").slice(1).join("<br/>"):a.extract&&(k(a,0,""),k(a,1,"line"),k(a,2,""),h+="on line "+a.line+", column "+(a.column+1)+":</p>"+"<ul>"+i.join("")+"</ul>"),f.innerHTML=h,p([".less-error-message ul, .less-error-message li {","list-style-type: none;","margin-right: 15px;","padding: 4px 0;","margin: 0;","}",".less-error-message label {","font-size: 12px;","margin-right: 15px;","padding: 4px 0;","color: #cc7777;","}",".less-error-message pre {","color: #dd6666;","padding: 4px 0;","margin: 0;","display: inline-block;","}",".less-error-message pre.line {","color: #ff0000;","}",".less-error-message h3 {","font-size: 20px;","font-weight: bold;","padding: 15px 0 5px 0;","margin: 0;","}",".less-error-message a {","color: #10a","}",".less-error-message .error {","color: red;","font-weight: bold;","padding-bottom: 2px;","border-bottom: 1px dashed red;","}"].join("\n"),{title:"error-message"}),f.style.cssText=["font-family: Arial, sans-serif","border: 1px solid #e00","background-color: #eee","border-radius: 5px","-webkit-border-radius: 5px","-moz-border-radius: 5px","color: #e00","padding: 15px","margin-bottom: 15px"].join(";"),d.env=="development"&&(g=setInterval(function(){document.body&&(document.getElementById(c)?document.body.replaceChild(f,document.getElementById(c)):document.body.insertBefore(f,document.body.firstChild),clearInterval(g))},10))}typeof define=="function"&&define.amd&&define("less",[],function(){return d}),Array.isArray||(Array.isArray=function(a){return Object.prototype.toString.call(a)==="[object Array]"||a instanceof Array}),Array.prototype.forEach||(Array.prototype.forEach=function(a,b){var c=this.length>>>0;for(var d=0;d<c;d++)d in this&&a.call(b,this[d],d,this)}),Array.prototype.map||(Array.prototype.map=function(a){var b=this.length>>>0,c=new Array(b),d=arguments[1];for(var e=0;e<b;e++)e in this&&(c[e]=a.call(d,this[e],e,this));return c}),Array.prototype.filter||(Array.prototype.filter=function(a){var b=[],c=arguments[1];for(var d=0;d<this.length;d++)a.call(c,this[d])&&b.push(this[d]);return b}),Array.prototype.reduce||(Array.prototype.reduce=function(a){var b=this.length>>>0,c=0;if(b===0&&arguments.length===1)throw new TypeError;if(arguments.length>=2)var d=arguments[1];else do{if(c in this){d=this[c++];break}if(++c>=b)throw new TypeError}while(!0);for(;c<b;c++)c in this&&(d=a.call(null,d,this[c],c,this));return d}),Array.prototype.indexOf||(Array.prototype.indexOf=function(a){var b=this.length,c=arguments[1]||0;if(!b)return-1;if(c>=b)return-1;c<0&&(c+=b);for(;c<b;c++){if(!Object.prototype.hasOwnProperty.call(this,c))continue;if(a===this[c])return c}return-1}),Object.keys||(Object.keys=function(a){var b=[];for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&b.push(c);return b}),String.prototype.trim||(String.prototype.trim=function(){return String(this).replace(/^\s\s*/,"").replace(/\s\s*$/,"")});var d,e;typeof environment=="object"&&{}.toString.call(environment)==="[object Environment]"?(typeof a=="undefined"?d={}:d=a.less={},e=d.tree={},d.mode="rhino"):typeof a=="undefined"?(d=exports,e=c("./tree"),d.mode="node"):(typeof a.less=="undefined"&&(a.less={}),d=a.less,e=a.less.tree={},d.mode="browser"),d.Parser=function v(a){function q(){h=k[g],i=f,l=f}function r(){k[g]=h,f=i,l=f}function s(){f>l&&(k[g]=k[g].slice(f-l),l=f)}function t(a){var c,d,e,h,i,j,n,o;if(a instanceof Function)return a.call(m.parsers);if(typeof a=="string")c=b.charAt(f)===a?a:null,e=1,s();else{s();if(c=a.exec(k[g]))e=c[0].length;else return null}if(c){o=f+=e,j=f+k[g].length-e;while(f<j){h=b.charCodeAt(f);if(h!==32&&h!==10&&h!==9)break;f++}return k[g]=k[g].slice(e+(f-o)),l=f,k[g].length===0&&g<k.length-1&&g++,typeof c=="string"?c:c.length===1?c[0]:c}}function u(a,c){var d=t(a);if(!d)v(c||(typeof a=="string"?"expected '"+a+"' got '"+b.charAt(f)+"'":"unexpected token"));else return d}function v(a,b){throw{index:f,type:b||"Syntax",message:a}}function w(a){return typeof a=="string"?b.charAt(f)===a:a.test(k[g])?!0:!1}function x(a){return d.mode==="node"?c("path").basename(a):a.match(/[^\/]+$/)[0]}function y(a,c){return a.filename&&c.filename&&a.filename!==c.filename?m.imports.contents[x(a.filename)]:b}function z(a,b){for(var c=a,d=-1;c>=0&&b.charAt(c)!=="\n";c--)d++;return{line:typeof a=="number"?(b.slice(0,a).match(/\n/g)||"").length:null,column:d}}function A(a,b){var c=y(a,b),d=z(a.index,c),e=d.line,f=d.column,g=c.split("\n");this.type=a.type||"Syntax",this.message=a.message,this.filename=a.filename||b.filename,this.index=a.index,this.line=typeof e=="number"?e+1:null,this.callLine=a.call&&z(a.call,c).line+1,this.callExtract=g[z(a.call,c).line],this.stack=a.stack,this.column=f,this.extract=[g[e-1],g[e],g[e+1]]}var b,f,g,h,i,j,k,l,m,n=this,o=function(){},p=this.imports={paths:a&&a.paths||[],queue:[],files:{},contents:{},mime:a&&a.mime,error:null,push:function(b,c){var e=this;this.queue.push(b),d.Parser.importer(b,this.paths,function(a,d,f){e.queue.splice(e.queue.indexOf(b),1),e.files[b]=d,e.contents[b]=f,a&&!e.error&&(e.error=a),c(a,d),e.queue.length===0&&o()},a)}};return this.env=a=a||{},this.optimization="optimization"in this.env?this.env.optimization:1,this.env.filename=this.env.filename||null,m={imports:p,parse:function(h,i){var n,p,q,r,s,u,v=[],w,x=null;f=g=l=j=0,b=h.replace(/\r\n/g,"\n"),k=function(c){var d=0,e=/[^"'`\{\}\/\(\)\\]+/g,f=/\/\*(?:[^*]|\*+[^\/*])*\*+\/|\/\/.*/g,g=/"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'|`((?:[^`\\\r\n]|\\.)*)`/g,h=0,i,j=c[0],k;for(var l=0,m,n;l<b.length;l++){e.lastIndex=l,(i=e.exec(b))&&i.index===l&&(l+=i[0].length,j.push(i[0])),m=b.charAt(l),f.lastIndex=g.lastIndex=l,(i=g.exec(b))&&i.index===l&&(l+=i[0].length,j.push(i[0]),m=b.charAt(l)),!k&&m==="/"&&(n=b.charAt(l+1),(n==="/"||n==="*")&&(i=f.exec(b))&&i.index===l&&(l+=i[0].length,j.push(i[0]),m=b.charAt(l)));switch(m){case"{":if(!k){h++,j.push(m);break};case"}":if(!k){h--,j.push(m),c[++d]=j=[];break};case"(":if(!k){k=!0,j.push(m);break};case")":if(k){k=!1,j.push(m);break};default:j.push(m)}}return h>0&&(x=new A({index:l,type:"Parse",message:"missing closing `}`",filename:a.filename},a)),c.map(function(a){return a.join("")})}([[]]);if(x)return i(x);try{n=new e.Ruleset([],t(this.parsers.primary)),n.root=!0}catch(y){return i(new A(y,a))}n.toCSS=function(b){var f,g,h;return function(f,g){var h=[],i;f=f||{},typeof g=="object"&&!Array.isArray(g)&&(g=Object.keys(g).map(function(a){var b=g[a];return b instanceof e.Value||(b instanceof e.Expression||(b=new e.Expression([b])),b=new e.Value([b])),new e.Rule("@"+a,b,!1,0)}),h=[new e.Ruleset(null,g)]);try{var j=b.call(this,{frames:h}).toCSS([],{compress:f.compress||!1})}catch(k){throw new A(k,a)}if(i=m.imports.error)throw i instanceof A?i:new A(i,a);return f.yuicompress&&d.mode==="node"?c("./cssmin").compressor.cssmin(j):f.compress?j.replace(/(\s)+/g,"$1"):j}}(n.eval);if(f<b.length-1){f=j,u=b.split("\n"),s=(b.slice(0,f).match(/\n/g)||"").length+1;for(var z=f,B=-1;z>=0&&b.charAt(z)!=="\n";z--)B++;x={type:"Parse",message:"Syntax Error on line "+s,index:f,filename:a.filename,line:s,column:B,extract:[u[s-2],u[s-1],u[s]]}}this.imports.queue.length>0?o=function(){i(x,n)}:i(x,n)},parsers:{primary:function(){var a,b=[];while((a=t(this.mixin.definition)||t(this.rule)||t(this.ruleset)||t(this.mixin.call)||t(this.comment)||t(this.directive))||t(/^[\s\n]+/))a&&b.push(a);return b},comment:function(){var a;if(b.charAt(f)!=="/")return;if(b.charAt(f+1)==="/")return new e.Comment(t(/^\/\/.*/),!0);if(a=t(/^\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/))return new e.Comment(a)},entities:{quoted:function(){var a,c=f,d;b.charAt(c)==="~"&&(c++,d=!0);if(b.charAt(c)!=='"'&&b.charAt(c)!=="'")return;d&&t("~");if(a=t(/^"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'/))return new e.Quoted(a[0],a[1]||a[2],d)},keyword:function(){var a;if(a=t(/^[_A-Za-z-][_A-Za-z0-9-]*/))return e.colors.hasOwnProperty(a)?new e.Color(e.colors[a].slice(1)):new e.Keyword(a)},call:function(){var b,c,d=f;if(!(b=/^([\w-]+|%|progid:[\w\.]+)\(/.exec(k[g])))return;b=b[1].toLowerCase();if(b==="url")return null;f+=b.length;if(b==="alpha")return t(this.alpha);t("("),c=t(this.entities.arguments);if(!t(")"))return;if(b)return new e.Call(b,c,d,a.filename)},arguments:function(){var a=[],b;while(b=t(this.entities.assignment)||t(this.expression)){a.push(b);if(!t(","))break}return a},literal:function(){return t(this.entities.dimension)||t(this.entities.color)||t(this.entities.quoted)},assignment:function(){var a,b;if((a=t(/^\w+(?=\s?=)/i))&&t("=")&&(b=t(this.entity)))return new e.Assignment(a,b)},url:function(){var a;if(b.charAt(f)!=="u"||!t(/^url\(/))return;return a=t(this.entities.quoted)||t(this.entities.variable)||t(this.entities.dataURI)||t(/^[-\w%@$\/.&=:;#+?~]+/)||"",u(")"),new e.URL(a.value||a.data||a instanceof e.Variable?a:new e.Anonymous(a),p.paths)},dataURI:function(){var a;if(t(/^data:/)){a={},a.mime=t(/^[^\/]+\/[^,;)]+/)||"",a.charset=t(/^;\s*charset=[^,;)]+/)||"",a.base64=t(/^;\s*base64/)||"",a.data=t(/^,\s*[^)]+/);if(a.data)return a}},variable:function(){var c,d=f;if(b.charAt(f)==="@"&&(c=t(/^@@?[\w-]+/)))return new e.Variable(c,d,a.filename)},color:function(){var a;if(b.charAt(f)==="#"&&(a=t(/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})/)))return new e.Color(a[1])},dimension:function(){var a,c=b.charCodeAt(f);if(c>57||c<45||c===47)return;if(a=t(/^(-?\d*\.?\d+)(px|%|em|rem|pc|ex|in|deg|s|ms|pt|cm|mm|rad|grad|turn)?/))return new e.Dimension(a[1],a[2])},javascript:function(){var a,c=f,d;b.charAt(c)==="~"&&(c++,d=!0);if(b.charAt(c)!=="`")return;d&&t("~");if(a=t(/^`([^`]*)`/))return new e.JavaScript(a[1],f,d)}},variable:function(){var a;if(b.charAt(f)==="@"&&(a=t(/^(@[\w-]+)\s*:/)))return a[1]},shorthand:function(){var a,b;if(!w(/^[@\w.%-]+\/[@\w.-]+/))return;if((a=t(this.entity))&&t("/")&&(b=t(this.entity)))return new e.Shorthand(a,b)},mixin:{call:function(){var c=[],d,g,h,i=f,j=b.charAt(f),k=!1;if(j!=="."&&j!=="#")return;while(d=t(/^[#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/))c.push(new e.Element(g,d,f)),g=t(">");t("(")&&(h=t(this.entities.arguments))&&t(")"),t(this.important)&&(k=!0);if(c.length>0&&(t(";")||w("}")))return new e.mixin.Call(c,h||[],i,a.filename,k)},definition:function(){var a,c=[],d,g,h,i,j,k=!1;if(b.charAt(f)!=="."&&b.charAt(f)!=="#"||w(/^[^{]*(;|})/))return;q();if(d=t(/^([#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+)\s*\(/)){a=d[1];do{if(b.charAt(f)==="."&&t(/^\.{3}/)){k=!0;break}if(!(h=t(this.entities.variable)||t(this.entities.literal)||t(this.entities.keyword)))break;if(h instanceof e.Variable)if(t(":"))i=u(this.expression,"expected expression"),c.push({name:h.name,value:i});else{if(t(/^\.{3}/)){c.push({name:h.name,variadic:!0}),k=!0;break}c.push({name:h.name})}else c.push({value:h})}while(t(","));u(")"),t(/^when/)&&(j=u(this.conditions,"expected condition")),g=t(this.block);if(g)return new e.mixin.Definition(a,c,g,j,k);r()}}},entity:function(){return t(this.entities.literal)||t(this.entities.variable)||t(this.entities.url)||t(this.entities.call)||t(this.entities.keyword)||t(this.entities.javascript)||t(this.comment)},end:function(){return t(";")||w("}")},alpha:function(){var a;if(!t(/^\(opacity=/i))return;if(a=t(/^\d+/)||t(this.entities.variable))return u(")"),new e.Alpha(a)},element:function(){var a,b,c,d;c=t(this.combinator),a=t(/^(?:\d+\.\d+|\d+)%/)||t(/^(?:[.#]?|:*)(?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/)||t("*")||t(this.attribute)||t(/^\([^)@]+\)/),a||t("(")&&(d=t(this.entities.variable))&&t(")")&&(a=new e.Paren(d));if(a)return new e.Element(c,a,f);if(c.value&&c.value.charAt(0)==="&")return new e.Element(c,null,f)},combinator:function(){var a,c=b.charAt(f);if(c===">"||c==="+"||c==="~"){f++;while(b.charAt(f)===" ")f++;return new e.Combinator(c)}if(c==="&"){a="&",f++,b.charAt(f)===" "&&(a="& ");while(b.charAt(f)===" ")f++;return new e.Combinator(a)}return b.charAt(f-1)===" "?new e.Combinator(" "):new e.Combinator(null)},selector:function(){var a,c,d=[],g,h;if(t("("))return a=t(this.entity),u(")"),new e.Selector([new e.Element("",a,f)]);while(c=t(this.element)){g=b.charAt(f),d.push(c);if(g==="{"||g==="}"||g===";"||g===",")break}if(d.length>0)return new e.Selector(d)},tag:function(){return t(/^[a-zA-Z][a-zA-Z-]*[0-9]?/)||t("*")},attribute:function(){var a="",b,c,d;if(!t("["))return;if(b=t(/^[a-zA-Z-]+/)||t(this.entities.quoted))(d=t(/^[|~*$^]?=/))&&(c=t(this.entities.quoted)||t(/^[\w-]+/))?a=[b,d,c.toCSS?c.toCSS():c].join(""):a=b;if(!t("]"))return;if(a)return"["+a+"]"},block:function(){var a;if(t("{")&&(a=t(this.primary))&&t("}"))return a},ruleset:function(){var b=[],c,d,g;q();while(c=t(this.selector)){b.push(c),t(this.comment);if(!t(","))break;t(this.comment)}if(b.length>0&&(d=t(this.block)))return new e.Ruleset(b,d,a.strictImports);j=f,r()},rule:function(){var a,c,d=b.charAt(f),h,l;q();if(d==="."||d==="#"||d==="&")return;if(a=t(this.variable)||t(this.property)){a.charAt(0)!="@"&&(l=/^([^@+\/'"*`(;{}-]*);/.exec(k[g]))?(f+=l[0].length-1,c=new e.Anonymous(l[1])):a==="font"?c=t(this.font):c=t(this.value),h=t(this.important);if(c&&t(this.end))return new e.Rule(a,c,h,i);j=f,r()}},"import":function(){var a,b,c=f;if(t(/^@import\s+/)&&(a=t(this.entities.quoted)||t(this.entities.url))){b=t(this.mediaFeatures);if(t(";"))return new e.Import(a,p,b,c)}},mediaFeature:function(){var a,b,c=[];do if(a=t(this.entities.keyword))c.push(a);else if(t("(")){b=t(this.property),a=t(this.entity);if(!t(")"))return null;if(b&&a)c.push(new e.Paren(new e.Rule(b,a,null,f,!0)));else if(a)c.push(new e.Paren(a));else return null}while(a);if(c.length>0)return new e.Expression(c)},mediaFeatures:function(){var a,b=[];do if(a=t(this.mediaFeature)){b.push(a);if(!t(","))break}else if(a=t(this.entities.variable)){b.push(a);if(!t(","))break}while(a);return b.length>0?b:null},media:function(){var a,b;if(t(/^@media/)){a=t(this.mediaFeatures);if(b=t(this.block))return new e.Media(b,a)}},directive:function(){var a,c,d,g,h,i;if(b.charAt(f)!=="@")return;if(c=t(this["import"])||t(this.media))return c;if(a=t(/^@page|@keyframes/)||t(/^@(?:-webkit-|-moz-|-o-|-ms-)[a-z0-9-]+/)){g=(t(/^[^{]+/)||"").trim();if(d=t(this.block))return new e.Directive(a+" "+g,d)}else if(a=t(/^@[-a-z]+/))if(a==="@font-face"){if(d=t(this.block))return new e.Directive(a,d)}else if((c=t(this.entity))&&t(";"))return new e.Directive(a,c)},font:function(){var a=[],b=[],c,d,f,g;while(g=t(this.shorthand)||t(this.entity))b.push(g);a.push(new e.Expression(b));if(t(","))while(g=t(this.expression)){a.push(g);if(!t(","))break}return new e.Value(a)},value:function(){var a,b=[],c;while(a=t(this.expression)){b.push(a);if(!t(","))break}if(b.length>0)return new e.Value(b)},important:function(){if(b.charAt(f)==="!")return t(/^! *important/)},sub:function(){var a;if(t("(")&&(a=t(this.expression))&&t(")"))return a},multiplication:function(){var a,b,c,d;if(a=t(this.operand)){while(!w(/^\/\*/)&&(c=t("/")||t("*"))&&(b=t(this.operand)))d=new e.Operation(c,[d||a,b]);return d||a}},addition:function(){var a,c,d,g;if(a=t(this.multiplication)){while((d=t(/^[-+]\s+/)||b.charAt(f-1)!=" "&&(t("+")||t("-")))&&(c=t(this.multiplication)))g=new e.Operation(d,[g||a,c]);return g||a}},conditions:function(){var a,b,c=f,d;if(a=t(this.condition)){while(t(",")&&(b=t(this.condition)))d=new e.Condition("or",d||a,b,c);return d||a}},condition:function(){var a,b,c,d,g=f,h=!1;t(/^not/)&&(h=!0),u("(");if(a=t(this.addition)||t(this.entities.keyword)||t(this.entities.quoted))return(d=t(/^(?:>=|=<|[<=>])/))?(b=t(this.addition)||t(this.entities.keyword)||t(this.entities.quoted))?c=new e.Condition(d,a,b,g,h):v("expected expression"):c=new e.Condition("=",a,new e.Keyword("true"),g,h),u(")"),t(/^and/)?new e.Condition("and",c,t(this.condition)):c},operand:function(){var a,c=b.charAt(f+1);b.charAt(f)==="-"&&(c==="@"||c==="(")&&(a=t("-"));var d=t(this.sub)||t(this.entities.dimension)||t(this.entities.color)||t(this.entities.variable)||t(this.entities.call);return a?new e.Operation("*",[new e.Dimension(-1),d]):d},expression:function(){var a,b,c=[],d;while(a=t(this.addition)||t(this.entity))c.push(a);if(c.length>0)return new e.Expression(c)},property:function(){var a;if(a=t(/^(\*?-?[-a-z_0-9]+)\s*:/))return a[1]}}}};if(d.mode==="browser"||d.mode==="rhino")d.Parser.importer=function(a,b,c,d){!/^([a-z]+:)?\//.test(a)&&b.length>0&&(a=b[0]+a),n({href:a,title:a,type:d.mime},function(e){e&&typeof d.errback=="function"?d.errback.call(null,a,b,c,d):c.apply(null,arguments)},!0)};(function(a){function b(b){return a.functions.hsla(b.h,b.s,b.l,b.a)}function c(b){if(b instanceof a.Dimension)return parseFloat(b.unit=="%"?b.value/100:b.value);if(typeof b=="number")return b;throw{error:"RuntimeError",message:"color functions take numbers as parameters"}}function d(a){return Math.min(1,Math.max(0,a))}a.functions={rgb:function(a,b,c){return this.rgba(a,b,c,1)},rgba:function(b,d,e,f){var g=[b,d,e].map(function(a){return c(a)}),f=c(f);return new a.Color(g,f)},hsl:function(a,b,c){return this.hsla(a,b,c,1)},hsla:function(a,b,d,e){function h(a){return a=a<0?a+1:a>1?a-1:a,a*6<1?g+(f-g)*a*6:a*2<1?f:a*3<2?g+(f-g)*(2/3-a)*6:g}a=c(a)%360/360,b=c(b),d=c(d),e=c(e);var f=d<=.5?d*(b+1):d+b-d*b,g=d*2-f;return this.rgba(h(a+1/3)*255,h(a)*255,h(a-1/3)*255,e)},hue:function(b){return new a.Dimension(Math.round(b.toHSL().h))},saturation:function(b){return new a.Dimension(Math.round(b.toHSL().s*100),"%")},lightness:function(b){return new a.Dimension(Math.round(b.toHSL().l*100),"%")},alpha:function(b){return new a.Dimension(b.toHSL().a)},saturate:function(a,c){var e=a.toHSL();return e.s+=c.value/100,e.s=d(e.s),b(e)},desaturate:function(a,c){var e=a.toHSL();return e.s-=c.value/100,e.s=d(e.s),b(e)},lighten:function(a,c){var e=a.toHSL();return e.l+=c.value/100,e.l=d(e.l),b(e)},darken:function(a,c){var e=a.toHSL();return e.l-=c.value/100,e.l=d(e.l),b(e)},fadein:function(a,c){var e=a.toHSL();return e.a+=c.value/100,e.a=d(e.a),b(e)},fadeout:function(a,c){var e=a.toHSL();return e.a-=c.value/100,e.a=d(e.a),b(e)},fade:function(a,c){var e=a.toHSL();return e.a=c.value/100,e.a=d(e.a),b(e)},spin:function(a,c){var d=a.toHSL(),e=(d.h+c.value)%360;return d.h=e<0?360+e:e,b(d)},mix:function(b,c,d){var e=d.value/100,f=e*2-1,g=b.toHSL().a-c.toHSL().a,h=((f*g==-1?f:(f+g)/(1+f*g))+1)/2,i=1-h,j=[b.rgb[0]*h+c.rgb[0]*i,b.rgb[1]*h+c.rgb[1]*i,b.rgb[2]*h+c.rgb[2]*i],k=b.alpha*e+c.alpha*(1-e);return new a.Color(j,k)},greyscale:function(b){return this.desaturate(b,new a.Dimension(100))},e:function(b){return new a.Anonymous(b instanceof a.JavaScript?b.evaluated:b)},escape:function(b){return new a.Anonymous(encodeURI(b.value).replace(/=/g,"%3D").replace(/:/g,"%3A").replace(/#/g,"%23").replace(/;/g,"%3B").replace(/\(/g,"%28").replace(/\)/g,"%29"))},"%":function(b){var c=Array.prototype.slice.call(arguments,1),d=b.value;for(var e=0;e<c.length;e++)d=d.replace(/%[sda]/i,function(a){var b=a.match(/s/i)?c[e].value:c[e].toCSS();return a.match(/[A-Z]$/)?encodeURIComponent(b):b});return d=d.replace(/%%/g,"%"),new a.Quoted('"'+d+'"',d)},round:function(a){return this._math("round",a)},ceil:function(a){return this._math("ceil",a)},floor:function(a){return this._math("floor",a)},_math:function(b,d){if(d instanceof a.Dimension)return new a.Dimension(Math[b](c(d)),d.unit);if(typeof d=="number")return Math[b](d);throw{type:"Argument",message:"argument must be a number"}},argb:function(b){return new a.Anonymous(b.toARGB())},percentage:function(b){return new a.Dimension(b.value*100,"%")},color:function(b){if(b instanceof a.Quoted)return new a.Color(b.value.slice(1));throw{type:"Argument",message:"argument must be a string"}},iscolor:function(b){return this._isa(b,a.Color)},isnumber:function(b){return this._isa(b,a.Dimension)},isstring:function(b){return this._isa(b,a.Quoted)},iskeyword:function(b){return this._isa(b,a.Keyword)},isurl:function(b){return this._isa(b,a.URL)},ispixel:function(b){return b instanceof a.Dimension&&b.unit==="px"?a.True:a.False},ispercentage:function(b){return b instanceof a.Dimension&&b.unit==="%"?a.True:a.False},isem:function(b){return b instanceof a.Dimension&&b.unit==="em"?a.True:a.False},_isa:function(b,c){return b instanceof c?a.True:a.False}}})(c("./tree")),function(a){a.colors={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgrey:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"}}(c("./tree")),function(a){a.Alpha=function(a){this.value=a},a.Alpha.prototype={toCSS:function(){return"alpha(opacity="+(this.value.toCSS?this.value.toCSS():this.value)+")"},eval:function(a){return this.value.eval&&(this.value=this.value.eval(a)),this}}}(c("../tree")),function(a){a.Anonymous=function(a){this.value=a.value||a},a.Anonymous.prototype={toCSS:function(){return this.value},eval:function(){return this}}}(c("../tree")),function(a){a.Assignment=function(a,b){this.key=a,this.value=b},a.Assignment.prototype={toCSS:function(){return this.key+"="+(this.value.toCSS?this.value.toCSS():this.value)},eval:function(a){return this.value.eval&&(this.value=this.value.eval(a)),this}}}(c("../tree")),function(a){a.Call=function(a,b,c,d){this.name=a,this.args=b,this.index=c,this.filename=d},a.Call.prototype={eval:function(b){var c=this.args.map(function(a){return a.eval(b)});if(!(this.name in a.functions))return new a.Anonymous(this.name+"("+c.map(function(a){return a.toCSS()}).join(", ")+")");try{return a.functions[this.name].apply(a.functions,c)}catch(d){throw{type:d.type||"Runtime",message:"error evaluating function `"+this.name+"`"+(d.message?": "+d.message:""),index:this.index,filename:this.filename}}},toCSS:function(a){return this.eval(a).toCSS()}}}(c("../tree")),function(a){a.Color=function(a,b){Array.isArray(a)?this.rgb=a:a.length==6?this.rgb=a.match(/.{2}/g).map(function(a){return parseInt(a,16)}):this.rgb=a.split("").map(function(a){return parseInt(a+a,16)}),this.alpha=typeof b=="number"?b:1},a.Color.prototype={eval:function(){return this},toCSS:function(){return this.alpha<1?"rgba("+this.rgb.map(function(a){return Math.round(a)}).concat(this.alpha).join(", ")+")":"#"+this.rgb.map(function(a){return a=Math.round(a),a=(a>255?255:a<0?0:a).toString(16),a.length===1?"0"+a:a}).join("")},operate:function(b,c){var d=[];c instanceof a.Color||(c=c.toColor());for(var e=0;e<3;e++)d[e]=a.operate(b,this.rgb[e],c.rgb[e]);return new a.Color(d,this.alpha+c.alpha)},toHSL:function(){var a=this.rgb[0]/255,b=this.rgb[1]/255,c=this.rgb[2]/255,d=this.alpha,e=Math.max(a,b,c),f=Math.min(a,b,c),g,h,i=(e+f)/2,j=e-f;if(e===f)g=h=0;else{h=i>.5?j/(2-e-f):j/(e+f);switch(e){case a:g=(b-c)/j+(b<c?6:0);break;case b:g=(c-a)/j+2;break;case c:g=(a-b)/j+4}g/=6}return{h:g*360,s:h,l:i,a:d}},toARGB:function(){var a=[Math.round(this.alpha*255)].concat(this.rgb);return"#"+a.map(function(a){return a=Math.round(a),a=(a>255?255:a<0?0:a).toString(16),a.length===1?"0"+a:a}).join("")}}}(c("../tree")),function(a){a.Comment=function(a,b){this.value=a,this.silent=!!b},a.Comment.prototype={toCSS:function(a){return a.compress?"":this.value},eval:function(){return this}}}(c("../tree")),function(a){a.Condition=function(a,b,c,d,e){this.op=a.trim(),this.lvalue=b,this.rvalue=c,this.index=d,this.negate=e},a.Condition.prototype.eval=function(a){var b=this.lvalue.eval(a),c=this.rvalue.eval(a),d=this.index,e,e=function(a){switch(a){case"and":return b&&c;case"or":return b||c;default:if(b.compare)e=b.compare(c);else if(c.compare)e=c.compare(b);else throw{type:"Type",message:"Unable to perform comparison",index:d};switch(e){case-1:return a==="<"||a==="=<";case 0:return a==="="||a===">="||a==="=<";case 1:return a===">"||a===">="}}}(this.op);return this.negate?!e:e}}(c("../tree")),function(a){a.Dimension=function(a,b){this.value=parseFloat(a),this.unit=b||null},a.Dimension.prototype={eval:function(){return this},toColor:function(){return new a.Color([this.value,this.value,this.value])},toCSS:function(){var a=this.value+this.unit;return a},operate:function(b,c){return new a.Dimension(a.operate(b,this.value,c.value),this.unit||c.unit)},compare:function(b){return b instanceof a.Dimension?b.value>this.value?-1:b.value<this.value?1:0:-1}}}(c("../tree")),function(a){a.Directive=function(b,c,d){this.name=b,Array.isArray(c)?(this.ruleset=new a.Ruleset([],c),this.ruleset.allowImports=!0):this.value=c},a.Directive.prototype={toCSS:function(a,b){return this.ruleset?(this.ruleset.root=!0,this.name+(b.compress?"{":" {\n ")+this.ruleset.toCSS(a,b).trim().replace(/\n/g,"\n ")+(b.compress?"}":"\n}\n")):this.name+" "+this.value.toCSS()+";\n"},eval:function(a){return a.frames.unshift(this),this.ruleset=this.ruleset&&this.ruleset.eval(a),a.frames.shift(),this},variable:function(b){return a.Ruleset.prototype.variable.call(this.ruleset,b)},find:function(){return a.Ruleset.prototype.find.apply(this.ruleset,arguments)},rulesets:function(){return a.Ruleset.prototype.rulesets.apply(this.ruleset)}}}(c("../tree")),function(a){a.Element=function(b,c,d){this.combinator=b instanceof a.Combinator?b:new a.Combinator(b),typeof c=="string"?this.value=c.trim():c?this.value=c:this.value="",this.index=d},a.Element.prototype.eval=function(b){return new a.Element(this.combinator,this.value.eval?this.value.eval(b):this.value,this.index)},a.Element.prototype.toCSS=function(a){return this.combinator.toCSS(a||{})+(this.value.toCSS?this.value.toCSS(a):this.value)},a.Combinator=function(a){a===" "?this.value=" ":a==="& "?this.value="& ":this.value=a?a.trim():""},a.Combinator.prototype.toCSS=function(a){return{"":""," ":" ","&":"","& ":" ",":":" :","+":a.compress?"+":" + ","~":a.compress?"~":" ~ ",">":a.compress?">":" > "}[this.value]}}(c("../tree")),function(a){a.Expression=function(a){this.value=a},a.Expression.prototype={eval:function(b){return this.value.length>1?new a.Expression(this.value.map(function(a){return a.eval(b)})):this.value.length===1?this.value[0].eval(b):this},toCSS:function(a){return this.value.map(function(b){return b.toCSS?b.toCSS(a):""}).join(" ")}}}(c("../tree")),function(a){a.Import=function(b,c,d,e){var f=this;this.index=e,this._path=b,this.features=d&&new a.Value(d),b instanceof a.Quoted?this.path=/\.(le?|c)ss(\?.*)?$/.test(b.value)?b.value:b.value+".less":this.path=b.value.value||b.value,this.css=/css(\?.*)?$/.test(this.path),this.css||c.push(this.path,function(b,c){b&&(b.index=e),f.root=c||new a.Ruleset([],[])})},a.Import.prototype={toCSS:function(a){var b=this.features?" "+this.features.toCSS(a):"";return this.css?"@import "+this._path.toCSS()+b+";\n":""},eval:function(b){var c,d=this.features&&this.features.eval(b);if(this.css)return this;c=new a.Ruleset([],this.root.rules.slice(0));for(var e=0;e<c.rules.length;e++)c.rules[e]instanceof a.Import&&Array.prototype
9
- .splice.apply(c.rules,[e,1].concat(c.rules[e].eval(b)));return this.features?new a.Media(c.rules,this.features.value):c.rules}}}(c("../tree")),function(a){a.JavaScript=function(a,b,c){this.escaped=c,this.expression=a,this.index=b},a.JavaScript.prototype={eval:function(b){var c,d=this,e={},f=this.expression.replace(/@\{([\w-]+)\}/g,function(c,e){return a.jsify((new a.Variable("@"+e,d.index)).eval(b))});try{f=new Function("return ("+f+")")}catch(g){throw{message:"JavaScript evaluation error: `"+f+"`",index:this.index}}for(var h in b.frames[0].variables())e[h.slice(1)]={value:b.frames[0].variables()[h].value,toJS:function(){return this.value.eval(b).toCSS()}};try{c=f.call(e)}catch(g){throw{message:"JavaScript evaluation error: '"+g.name+": "+g.message+"'",index:this.index}}return typeof c=="string"?new a.Quoted('"'+c+'"',c,this.escaped,this.index):Array.isArray(c)?new a.Anonymous(c.join(", ")):new a.Anonymous(c)}}}(c("../tree")),function(a){a.Keyword=function(a){this.value=a},a.Keyword.prototype={eval:function(){return this},toCSS:function(){return this.value},compare:function(b){return b instanceof a.Keyword?b.value===this.value?0:1:-1}},a.True=new a.Keyword("true"),a.False=new a.Keyword("false")}(c("../tree")),function(a){a.Media=function(b,c){var d=new a.Element("&",null,0),e=[new a.Selector([d])];this.features=new a.Value(c),this.ruleset=new a.Ruleset(e,b),this.ruleset.allowImports=!0},a.Media.prototype={toCSS:function(a,b){var c=this.features.toCSS(b);return this.ruleset.root=a.length===0||a[0].multiMedia,"@media "+c+(b.compress?"{":" {\n ")+this.ruleset.toCSS(a,b).trim().replace(/\n/g,"\n ")+(b.compress?"}":"\n}\n")},eval:function(b){b.mediaBlocks||(b.mediaBlocks=[],b.mediaPath=[]);var c=b.mediaBlocks.length;b.mediaPath.push(this),b.mediaBlocks.push(this);var d=new a.Media([],[]);return d.features=this.features.eval(b),b.frames.unshift(this.ruleset),d.ruleset=this.ruleset.eval(b),b.frames.shift(),b.mediaBlocks[c]=d,b.mediaPath.pop(),b.mediaPath.length===0?d.evalTop(b):d.evalNested(b)},variable:function(b){return a.Ruleset.prototype.variable.call(this.ruleset,b)},find:function(){return a.Ruleset.prototype.find.apply(this.ruleset,arguments)},rulesets:function(){return a.Ruleset.prototype.rulesets.apply(this.ruleset)},evalTop:function(b){var c=this;if(b.mediaBlocks.length>1){var d=new a.Element("&",null,0),e=[new a.Selector([d])];c=new a.Ruleset(e,b.mediaBlocks),c.multiMedia=!0}return delete b.mediaBlocks,delete b.mediaPath,c},evalNested:function(b){var c,d,e=b.mediaPath.concat([this]);for(c=0;c<e.length;c++)d=e[c].features instanceof a.Value?e[c].features.value:e[c].features,e[c]=Array.isArray(d)?d:[d];return this.features=new a.Value(this.permute(e).map(function(b){b=b.map(function(b){return b.toCSS?b:new a.Anonymous(b)});for(c=b.length-1;c>0;c--)b.splice(c,0,new a.Anonymous("and"));return new a.Expression(b)})),new a.Ruleset([],[])},permute:function(a){if(a.length===0)return[];if(a.length===1)return a[0];var b=[],c=this.permute(a.slice(1));for(var d=0;d<c.length;d++)for(var e=0;e<a[0].length;e++)b.push([a[0][e]].concat(c[d]));return b}}}(c("../tree")),function(a){a.mixin={},a.mixin.Call=function(b,c,d,e,f){this.selector=new a.Selector(b),this.arguments=c,this.index=d,this.filename=e,this.important=f},a.mixin.Call.prototype={eval:function(a){var b,c,d=[],e=!1;for(var f=0;f<a.frames.length;f++)if((b=a.frames[f].find(this.selector)).length>0){c=this.arguments&&this.arguments.map(function(b){return b.eval(a)});for(var g=0;g<b.length;g++)if(b[g].match(c,a))try{Array.prototype.push.apply(d,b[g].eval(a,this.arguments,this.important).rules),e=!0}catch(h){throw{message:h.message,index:this.index,filename:this.filename,stack:h.stack}}if(e)return d;throw{type:"Runtime",message:"No matching definition was found for `"+this.selector.toCSS().trim()+"("+this.arguments.map(function(a){return a.toCSS()}).join(", ")+")`",index:this.index,filename:this.filename}}throw{type:"Name",message:this.selector.toCSS().trim()+" is undefined",index:this.index,filename:this.filename}}},a.mixin.Definition=function(b,c,d,e,f){this.name=b,this.selectors=[new a.Selector([new a.Element(null,b)])],this.params=c,this.condition=e,this.variadic=f,this.arity=c.length,this.rules=d,this._lookups={},this.required=c.reduce(function(a,b){return!b.name||b.name&&!b.value?a+1:a},0),this.parent=a.Ruleset.prototype,this.frames=[]},a.mixin.Definition.prototype={toCSS:function(){return""},variable:function(a){return this.parent.variable.call(this,a)},variables:function(){return this.parent.variables.call(this)},find:function(){return this.parent.find.apply(this,arguments)},rulesets:function(){return this.parent.rulesets.apply(this)},evalParams:function(b,c){var d=new a.Ruleset(null,[]),e;for(var f=0,g,h;f<this.params.length;f++)if(h=this.params[f].name)if(this.params[f].variadic&&c){e=[];for(var i=f;i<c.length;i++)e.push(c[i].eval(b));d.rules.unshift(new a.Rule(h,(new a.Expression(e)).eval(b)))}else if(g=c&&c[f]||this.params[f].value)d.rules.unshift(new a.Rule(h,g.eval(b)));else throw{type:"Runtime",message:"wrong number of arguments for "+this.name+" ("+c.length+" for "+this.arity+")"};return d},eval:function(b,c,d){var e=this.evalParams(b,c),f,g=[],h,i;for(var j=0;j<Math.max(this.params.length,c&&c.length);j++)g.push(c[j]||this.params[j].value);return e.rules.unshift(new a.Rule("@arguments",(new a.Expression(g)).eval(b))),h=d?this.rules.map(function(b){return new a.Rule(b.name,b.value,"!important",b.index)}):this.rules.slice(0),(new a.Ruleset(null,h)).eval({frames:[this,e].concat(this.frames,b.frames)})},match:function(a,b){var c=a&&a.length||0,d,e;if(!this.variadic){if(c<this.required)return!1;if(c>this.params.length)return!1;if(this.required>0&&c>this.params.length)return!1}if(this.condition&&!this.condition.eval({frames:[this.evalParams(b,a)].concat(b.frames)}))return!1;d=Math.min(c,this.arity);for(var f=0;f<d;f++)if(!this.params[f].name&&a[f].eval(b).toCSS()!=this.params[f].value.eval(b).toCSS())return!1;return!0}}}(c("../tree")),function(a){a.Operation=function(a,b){this.op=a.trim(),this.operands=b},a.Operation.prototype.eval=function(b){var c=this.operands[0].eval(b),d=this.operands[1].eval(b),e;if(c instanceof a.Dimension&&d instanceof a.Color)if(this.op==="*"||this.op==="+")e=d,d=c,c=e;else throw{name:"OperationError",message:"Can't substract or divide a color from a number"};return c.operate(this.op,d)},a.operate=function(a,b,c){switch(a){case"+":return b+c;case"-":return b-c;case"*":return b*c;case"/":return b/c}}}(c("../tree")),function(a){a.Paren=function(a){this.value=a},a.Paren.prototype={toCSS:function(a){return"("+this.value.toCSS(a)+")"},eval:function(b){return new a.Paren(this.value.eval(b))}}}(c("../tree")),function(a){a.Quoted=function(a,b,c,d){this.escaped=c,this.value=b||"",this.quote=a.charAt(0),this.index=d},a.Quoted.prototype={toCSS:function(){return this.escaped?this.value:this.quote+this.value+this.quote},eval:function(b){var c=this,d=this.value.replace(/`([^`]+)`/g,function(d,e){return(new a.JavaScript(e,c.index,!0)).eval(b).value}).replace(/@\{([\w-]+)\}/g,function(d,e){var f=(new a.Variable("@"+e,c.index)).eval(b);return"value"in f?f.value:f.toCSS()});return new a.Quoted(this.quote+d+this.quote,d,this.escaped,this.index)}}}(c("../tree")),function(a){a.Rule=function(b,c,d,e,f){this.name=b,this.value=c instanceof a.Value?c:new a.Value([c]),this.important=d?" "+d.trim():"",this.index=e,this.inline=f||!1,b.charAt(0)==="@"?this.variable=!0:this.variable=!1},a.Rule.prototype.toCSS=function(a){return this.variable?"":this.name+(a.compress?":":": ")+this.value.toCSS(a)+this.important+(this.inline?"":";")},a.Rule.prototype.eval=function(b){return new a.Rule(this.name,this.value.eval(b),this.important,this.index,this.inline)},a.Shorthand=function(a,b){this.a=a,this.b=b},a.Shorthand.prototype={toCSS:function(a){return this.a.toCSS(a)+"/"+this.b.toCSS(a)},eval:function(){return this}}}(c("../tree")),function(a){a.Ruleset=function(a,b,c){this.selectors=a,this.rules=b,this._lookups={},this.strictImports=c},a.Ruleset.prototype={eval:function(b){var c=this.selectors&&this.selectors.map(function(a){return a.eval(b)}),d=new a.Ruleset(c,this.rules.slice(0),this.strictImports);d.root=this.root,d.allowImports=this.allowImports,b.frames.unshift(d);if(d.root||d.allowImports||!d.strictImports)for(var e=0;e<d.rules.length;e++)d.rules[e]instanceof a.Import&&Array.prototype.splice.apply(d.rules,[e,1].concat(d.rules[e].eval(b)));for(var e=0;e<d.rules.length;e++)d.rules[e]instanceof a.mixin.Definition&&(d.rules[e].frames=b.frames.slice(0));for(var e=0;e<d.rules.length;e++)d.rules[e]instanceof a.mixin.Call&&Array.prototype.splice.apply(d.rules,[e,1].concat(d.rules[e].eval(b)));for(var e=0,f;e<d.rules.length;e++)f=d.rules[e],f instanceof a.mixin.Definition||(d.rules[e]=f.eval?f.eval(b):f);return b.frames.shift(),d},match:function(a){return!a||a.length===0},variables:function(){return this._variables?this._variables:this._variables=this.rules.reduce(function(b,c){return c instanceof a.Rule&&c.variable===!0&&(b[c.name]=c),b},{})},variable:function(a){return this.variables()[a]},rulesets:function(){return this._rulesets?this._rulesets:this._rulesets=this.rules.filter(function(b){return b instanceof a.Ruleset||b instanceof a.mixin.Definition})},find:function(b,c){c=c||this;var d=[],e,f,g=b.toCSS();return g in this._lookups?this._lookups[g]:(this.rulesets().forEach(function(e){if(e!==c)for(var g=0;g<e.selectors.length;g++)if(f=b.match(e.selectors[g])){b.elements.length>e.selectors[g].elements.length?Array.prototype.push.apply(d,e.find(new a.Selector(b.elements.slice(1)),c)):d.push(e);break}}),this._lookups[g]=d)},toCSS:function(b,c){var d=[],e=[],f=[],g=[],h,i;this.root||(b.length===0?g=this.selectors.map(function(a){return[a]}):this.joinSelectors(g,b,this.selectors));for(var j=0;j<this.rules.length;j++)i=this.rules[j],i.rules||i instanceof a.Directive||i instanceof a.Media?f.push(i.toCSS(g,c)):i instanceof a.Comment?i.silent||(this.root?f.push(i.toCSS(c)):e.push(i.toCSS(c))):i.toCSS&&!i.variable?e.push(i.toCSS(c)):i.value&&!i.variable&&e.push(i.value.toString());return f=f.join(""),this.root?d.push(e.join(c.compress?"":"\n")):e.length>0&&(h=g.map(function(a){return a.map(function(a){return a.toCSS(c)}).join("").trim()}).join(c.compress?",":",\n"),d.push(h,(c.compress?"{":" {\n ")+e.join(c.compress?"":"\n ")+(c.compress?"}":"\n}\n"))),d.push(f),d.join("")+(c.compress?"\n":"")},joinSelectors:function(a,b,c){for(var d=0;d<c.length;d++)this.joinSelector(a,b,c[d])},joinSelector:function(b,c,d){var e=[],f=[],g=[],h=[],i=!1,j;for(var k=0;k<d.elements.length;k++)j=d.elements[k],j.combinator.value.charAt(0)==="&"&&(i=!0),i?h.push(j):g.push(j);i||(h=g,g=[]),g.length>0&&e.push(new a.Selector(g)),h.length>0&&f.push(new a.Selector(h));for(var l=0;l<c.length;l++)b.push(e.concat(c[l]).concat(f))}}}(c("../tree")),function(a){a.Selector=function(a){this.elements=a,this.elements[0].combinator.value===""&&(this.elements[0].combinator.value=" ")},a.Selector.prototype.match=function(a){var b=this.elements.length,c=a.elements.length,d=Math.min(b,c);if(b<c)return!1;for(var e=0;e<d;e++)if(this.elements[e].value!==a.elements[e].value)return!1;return!0},a.Selector.prototype.eval=function(b){return new a.Selector(this.elements.map(function(a){return a.eval(b)}))},a.Selector.prototype.toCSS=function(a){return this._css?this._css:this._css=this.elements.map(function(b){return typeof b=="string"?" "+b.trim():b.toCSS(a)}).join("")}}(c("../tree")),function(b){b.URL=function(b,c){b.data?this.attrs=b:(typeof a!="undefined"&&!/^(?:https?:\/\/|file:\/\/|data:|\/)/.test(b.value)&&c.length>0&&(b.value=c[0]+(b.value.charAt(0)==="/"?b.value.slice(1):b.value)),this.value=b,this.paths=c)},b.URL.prototype={toCSS:function(){return"url("+(this.attrs?"data:"+this.attrs.mime+this.attrs.charset+this.attrs.base64+this.attrs.data:this.value.toCSS())+")"},eval:function(a){return this.attrs?this:new b.URL(this.value.eval(a),this.paths)}}}(c("../tree")),function(a){a.Value=function(a){this.value=a,this.is="value"},a.Value.prototype={eval:function(b){return this.value.length===1?this.value[0].eval(b):new a.Value(this.value.map(function(a){return a.eval(b)}))},toCSS:function(a){return this.value.map(function(b){return b.toCSS(a)}).join(a.compress?",":", ")}}}(c("../tree")),function(a){a.Variable=function(a,b,c){this.name=a,this.index=b,this.file=c},a.Variable.prototype={eval:function(b){var c,d,e=this.name;e.indexOf("@@")==0&&(e="@"+(new a.Variable(e.slice(1))).eval(b).value);if(c=a.find(b.frames,function(a){if(d=a.variable(e))return d.value.eval(b)}))return c;throw{type:"Name",message:"variable "+e+" is undefined",filename:this.file,index:this.index}}}}(c("../tree")),function(a){a.find=function(a,b){for(var c=0,d;c<a.length;c++)if(d=b.call(a,a[c]))return d;return null},a.jsify=function(a){return Array.isArray(a.value)&&a.value.length>1?"["+a.value.map(function(a){return a.toCSS(!1)}).join(", ")+"]":a.toCSS(!1)}}(c("./tree"));var f=location.protocol==="file:"||location.protocol==="chrome:"||location.protocol==="chrome-extension:"||location.protocol==="resource:";d.env=d.env||(location.hostname=="127.0.0.1"||location.hostname=="0.0.0.0"||location.hostname=="localhost"||location.port.length>0||f?"development":"production"),d.async=!1,d.poll=d.poll||(f?1e3:1500),d.watch=function(){return this.watchMode=!0},d.unwatch=function(){return this.watchMode=!1},d.env==="development"?(d.optimization=0,/!watch/.test(location.hash)&&d.watch(),d.watchTimer=setInterval(function(){d.watchMode&&m(function(a,b,c,d,e){b&&p(b.toCSS(),d,e.lastModified)})},d.poll)):d.optimization=3;var g;try{g=typeof a.localStorage=="undefined"?null:a.localStorage}catch(h){g=null}var i=document.getElementsByTagName("link"),j=/^text\/(x-)?less$/;d.sheets=[];for(var k=0;k<i.length;k++)(i[k].rel==="stylesheet/less"||i[k].rel.match(/stylesheet/)&&i[k].type.match(j))&&d.sheets.push(i[k]);d.refresh=function(a){var b,c;b=c=new Date,m(function(a,d,e,f,g){g.local?t("loading "+f.href+" from cache."):(t("parsed "+f.href+" successfully."),p(d.toCSS(),f,g.lastModified)),t("css for "+f.href+" generated in "+(new Date-c)+"ms"),g.remaining===0&&t("css generated in "+(new Date-b)+"ms"),c=new Date},a),l()},d.refreshStyles=l,d.refresh(d.env==="development")})(window);
 
 
 
 
 
 
 
 
 
license.txt CHANGED
@@ -1,674 +1,281 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 3, 29 June 2007
 
 
 
3
 
4
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
  Everyone is permitted to copy and distribute verbatim copies
6
  of this license document, but changing it is not allowed.
7
 
8
- Preamble
9
-
10
- The GNU General Public License is a free, copyleft license for
11
- software and other kinds of works.
12
 
13
- The licenses for most software and other practical works are designed
14
- to take away your freedom to share and change the works. By contrast,
15
- the GNU General Public License is intended to guarantee your freedom to
16
- share and change all versions of a program--to make sure it remains free
17
- software for all its users. We, the Free Software Foundation, use the
18
- GNU General Public License for most of our software; it applies also to
19
- any other work released this way by its authors. You can apply it to
 
20
  your programs, too.
21
 
22
  When we speak of free software, we are referring to freedom, not
23
  price. Our General Public Licenses are designed to make sure that you
24
  have the freedom to distribute copies of free software (and charge for
25
- them if you wish), that you receive source code or can get it if you
26
- want it, that you can change the software or use pieces of it in new
27
- free programs, and that you know you can do these things.
28
 
29
- To protect your rights, we need to prevent others from denying you
30
- these rights or asking you to surrender the rights. Therefore, you have
31
- certain responsibilities if you distribute copies of the software, or if
32
- you modify it: responsibilities to respect the freedom of others.
33
 
34
  For example, if you distribute copies of such a program, whether
35
- gratis or for a fee, you must pass on to the recipients the same
36
- freedoms that you received. You must make sure that they, too, receive
37
- or can get the source code. And you must show them these terms so they
38
- know their rights.
39
-
40
- Developers that use the GNU GPL protect your rights with two steps:
41
- (1) assert copyright on the software, and (2) offer you this License
42
- giving you legal permission to copy, distribute and/or modify it.
43
-
44
- For the developers' and authors' protection, the GPL clearly explains
45
- that there is no warranty for this free software. For both users' and
46
- authors' sake, the GPL requires that modified versions be marked as
47
- changed, so that their problems will not be attributed erroneously to
48
- authors of previous versions.
49
-
50
- Some devices are designed to deny users access to install or run
51
- modified versions of the software inside them, although the manufacturer
52
- can do so. This is fundamentally incompatible with the aim of
53
- protecting users' freedom to change the software. The systematic
54
- pattern of such abuse occurs in the area of products for individuals to
55
- use, which is precisely where it is most unacceptable. Therefore, we
56
- have designed this version of the GPL to prohibit the practice for those
57
- products. If such problems arise substantially in other domains, we
58
- stand ready to extend this provision to those domains in future versions
59
- of the GPL, as needed to protect the freedom of users.
60
-
61
- Finally, every program is threatened constantly by software patents.
62
- States should not allow patents to restrict development and use of
63
- software on general-purpose computers, but in those that do, we wish to
64
- avoid the special danger that patents applied to a free program could
65
- make it effectively proprietary. To prevent this, the GPL assures that
66
- patents cannot be used to render the program non-free.
67
 
68
  The precise terms and conditions for copying, distribution and
69
  modification follow.
70
 
71
- TERMS AND CONDITIONS
72
-
73
- 0. Definitions.
74
-
75
- "This License" refers to version 3 of the GNU General Public License.
76
-
77
- "Copyright" also means copyright-like laws that apply to other kinds of
78
- works, such as semiconductor masks.
79
-
80
- "The Program" refers to any copyrightable work licensed under this
81
- License. Each licensee is addressed as "you". "Licensees" and
82
- "recipients" may be individuals or organizations.
83
-
84
- To "modify" a work means to copy from or adapt all or part of the work
85
- in a fashion requiring copyright permission, other than the making of an
86
- exact copy. The resulting work is called a "modified version" of the
87
- earlier work or a work "based on" the earlier work.
88
-
89
- A "covered work" means either the unmodified Program or a work based
90
- on the Program.
91
-
92
- To "propagate" a work means to do anything with it that, without
93
- permission, would make you directly or secondarily liable for
94
- infringement under applicable copyright law, except executing it on a
95
- computer or modifying a private copy. Propagation includes copying,
96
- distribution (with or without modification), making available to the
97
- public, and in some countries other activities as well.
98
-
99
- To "convey" a work means any kind of propagation that enables other
100
- parties to make or receive copies. Mere interaction with a user through
101
- a computer network, with no transfer of a copy, is not conveying.
102
-
103
- An interactive user interface displays "Appropriate Legal Notices"
104
- to the extent that it includes a convenient and prominently visible
105
- feature that (1) displays an appropriate copyright notice, and (2)
106
- tells the user that there is no warranty for the work (except to the
107
- extent that warranties are provided), that licensees may convey the
108
- work under this License, and how to view a copy of this License. If
109
- the interface presents a list of user commands or options, such as a
110
- menu, a prominent item in the list meets this criterion.
111
-
112
- 1. Source Code.
113
-
114
- The "source code" for a work means the preferred form of the work
115
- for making modifications to it. "Object code" means any non-source
116
- form of a work.
117
-
118
- A "Standard Interface" means an interface that either is an official
119
- standard defined by a recognized standards body, or, in the case of
120
- interfaces specified for a particular programming language, one that
121
- is widely used among developers working in that language.
122
-
123
- The "System Libraries" of an executable work include anything, other
124
- than the work as a whole, that (a) is included in the normal form of
125
- packaging a Major Component, but which is not part of that Major
126
- Component, and (b) serves only to enable use of the work with that
127
- Major Component, or to implement a Standard Interface for which an
128
- implementation is available to the public in source code form. A
129
- "Major Component", in this context, means a major essential component
130
- (kernel, window system, and so on) of the specific operating system
131
- (if any) on which the executable work runs, or a compiler used to
132
- produce the work, or an object code interpreter used to run it.
133
-
134
- The "Corresponding Source" for a work in object code form means all
135
- the source code needed to generate, install, and (for an executable
136
- work) run the object code and to modify the work, including scripts to
137
- control those activities. However, it does not include the work's
138
- System Libraries, or general-purpose tools or generally available free
139
- programs which are used unmodified in performing those activities but
140
- which are not part of the work. For example, Corresponding Source
141
- includes interface definition files associated with source files for
142
- the work, and the source code for shared libraries and dynamically
143
- linked subprograms that the work is specifically designed to require,
144
- such as by intimate data communication or control flow between those
145
- subprograms and other parts of the work.
146
-
147
- The Corresponding Source need not include anything that users
148
- can regenerate automatically from other parts of the Corresponding
149
- Source.
150
-
151
- The Corresponding Source for a work in source code form is that
152
- same work.
153
-
154
- 2. Basic Permissions.
155
-
156
- All rights granted under this License are granted for the term of
157
- copyright on the Program, and are irrevocable provided the stated
158
- conditions are met. This License explicitly affirms your unlimited
159
- permission to run the unmodified Program. The output from running a
160
- covered work is covered by this License only if the output, given its
161
- content, constitutes a covered work. This License acknowledges your
162
- rights of fair use or other equivalent, as provided by copyright law.
163
-
164
- You may make, run and propagate covered works that you do not
165
- convey, without conditions so long as your license otherwise remains
166
- in force. You may convey covered works to others for the sole purpose
167
- of having them make modifications exclusively for you, or provide you
168
- with facilities for running those works, provided that you comply with
169
- the terms of this License in conveying all material for which you do
170
- not control copyright. Those thus making or running the covered works
171
- for you must do so exclusively on your behalf, under your direction
172
- and control, on terms that prohibit them from making any copies of
173
- your copyrighted material outside their relationship with you.
174
-
175
- Conveying under any other circumstances is permitted solely under
176
- the conditions stated below. Sublicensing is not allowed; section 10
177
- makes it unnecessary.
178
-
179
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
-
181
- No covered work shall be deemed part of an effective technological
182
- measure under any applicable law fulfilling obligations under article
183
- 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
- similar laws prohibiting or restricting circumvention of such
185
- measures.
186
-
187
- When you convey a covered work, you waive any legal power to forbid
188
- circumvention of technological measures to the extent such circumvention
189
- is effected by exercising rights under this License with respect to
190
- the covered work, and you disclaim any intention to limit operation or
191
- modification of the work as a means of enforcing, against the work's
192
- users, your or third parties' legal rights to forbid circumvention of
193
- technological measures.
194
-
195
- 4. Conveying Verbatim Copies.
196
-
197
- You may convey verbatim copies of the Program's source code as you
198
- receive it, in any medium, provided that you conspicuously and
199
- appropriately publish on each copy an appropriate copyright notice;
200
- keep intact all notices stating that this License and any
201
- non-permissive terms added in accord with section 7 apply to the code;
202
- keep intact all notices of the absence of any warranty; and give all
203
- recipients a copy of this License along with the Program.
204
-
205
- You may charge any price or no price for each copy that you convey,
206
- and you may offer support or warranty protection for a fee.
207
-
208
- 5. Conveying Modified Source Versions.
209
-
210
- You may convey a work based on the Program, or the modifications to
211
- produce it from the Program, in the form of source code under the
212
- terms of section 4, provided that you also meet all of these conditions:
213
-
214
- a) The work must carry prominent notices stating that you modified
215
- it, and giving a relevant date.
216
-
217
- b) The work must carry prominent notices stating that it is
218
- released under this License and any conditions added under section
219
- 7. This requirement modifies the requirement in section 4 to
220
- "keep intact all notices".
221
-
222
- c) You must license the entire work, as a whole, under this
223
- License to anyone who comes into possession of a copy. This
224
- License will therefore apply, along with any applicable section 7
225
- additional terms, to the whole of the work, and all its parts,
226
- regardless of how they are packaged. This License gives no
227
- permission to license the work in any other way, but it does not
228
- invalidate such permission if you have separately received it.
229
-
230
- d) If the work has interactive user interfaces, each must display
231
- Appropriate Legal Notices; however, if the Program has interactive
232
- interfaces that do not display Appropriate Legal Notices, your
233
- work need not make them do so.
234
-
235
- A compilation of a covered work with other separate and independent
236
- works, which are not by their nature extensions of the covered work,
237
- and which are not combined with it such as to form a larger program,
238
- in or on a volume of a storage or distribution medium, is called an
239
- "aggregate" if the compilation and its resulting copyright are not
240
- used to limit the access or legal rights of the compilation's users
241
- beyond what the individual works permit. Inclusion of a covered work
242
- in an aggregate does not cause this License to apply to the other
243
- parts of the aggregate.
244
-
245
- 6. Conveying Non-Source Forms.
246
-
247
- You may convey a covered work in object code form under the terms
248
- of sections 4 and 5, provided that you also convey the
249
- machine-readable Corresponding Source under the terms of this License,
250
- in one of these ways:
251
-
252
- a) Convey the object code in, or embodied in, a physical product
253
- (including a physical distribution medium), accompanied by the
254
- Corresponding Source fixed on a durable physical medium
255
- customarily used for software interchange.
256
-
257
- b) Convey the object code in, or embodied in, a physical product
258
- (including a physical distribution medium), accompanied by a
259
- written offer, valid for at least three years and valid for as
260
- long as you offer spare parts or customer support for that product
261
- model, to give anyone who possesses the object code either (1) a
262
- copy of the Corresponding Source for all the software in the
263
- product that is covered by this License, on a durable physical
264
- medium customarily used for software interchange, for a price no
265
- more than your reasonable cost of physically performing this
266
- conveying of source, or (2) access to copy the
267
- Corresponding Source from a network server at no charge.
268
-
269
- c) Convey individual copies of the object code with a copy of the
270
- written offer to provide the Corresponding Source. This
271
- alternative is allowed only occasionally and noncommercially, and
272
- only if you received the object code with such an offer, in accord
273
- with subsection 6b.
274
-
275
- d) Convey the object code by offering access from a designated
276
- place (gratis or for a charge), and offer equivalent access to the
277
- Corresponding Source in the same way through the same place at no
278
- further charge. You need not require recipients to copy the
279
- Corresponding Source along with the object code. If the place to
280
- copy the object code is a network server, the Corresponding Source
281
- may be on a different server (operated by you or a third party)
282
- that supports equivalent copying facilities, provided you maintain
283
- clear directions next to the object code saying where to find the
284
- Corresponding Source. Regardless of what server hosts the
285
- Corresponding Source, you remain obligated to ensure that it is
286
- available for as long as needed to satisfy these requirements.
287
-
288
- e) Convey the object code using peer-to-peer transmission, provided
289
- you inform other peers where the object code and Corresponding
290
- Source of the work are being offered to the general public at no
291
- charge under subsection 6d.
292
-
293
- A separable portion of the object code, whose source code is excluded
294
- from the Corresponding Source as a System Library, need not be
295
- included in conveying the object code work.
296
-
297
- A "User Product" is either (1) a "consumer product", which means any
298
- tangible personal property which is normally used for personal, family,
299
- or household purposes, or (2) anything designed or sold for incorporation
300
- into a dwelling. In determining whether a product is a consumer product,
301
- doubtful cases shall be resolved in favor of coverage. For a particular
302
- product received by a particular user, "normally used" refers to a
303
- typical or common use of that class of product, regardless of the status
304
- of the particular user or of the way in which the particular user
305
- actually uses, or expects or is expected to use, the product. A product
306
- is a consumer product regardless of whether the product has substantial
307
- commercial, industrial or non-consumer uses, unless such uses represent
308
- the only significant mode of use of the product.
309
-
310
- "Installation Information" for a User Product means any methods,
311
- procedures, authorization keys, or other information required to install
312
- and execute modified versions of a covered work in that User Product from
313
- a modified version of its Corresponding Source. The information must
314
- suffice to ensure that the continued functioning of the modified object
315
- code is in no case prevented or interfered with solely because
316
- modification has been made.
317
-
318
- If you convey an object code work under this section in, or with, or
319
- specifically for use in, a User Product, and the conveying occurs as
320
- part of a transaction in which the right of possession and use of the
321
- User Product is transferred to the recipient in perpetuity or for a
322
- fixed term (regardless of how the transaction is characterized), the
323
- Corresponding Source conveyed under this section must be accompanied
324
- by the Installation Information. But this requirement does not apply
325
- if neither you nor any third party retains the ability to install
326
- modified object code on the User Product (for example, the work has
327
- been installed in ROM).
328
-
329
- The requirement to provide Installation Information does not include a
330
- requirement to continue to provide support service, warranty, or updates
331
- for a work that has been modified or installed by the recipient, or for
332
- the User Product in which it has been modified or installed. Access to a
333
- network may be denied when the modification itself materially and
334
- adversely affects the operation of the network or violates the rules and
335
- protocols for communication across the network.
336
-
337
- Corresponding Source conveyed, and Installation Information provided,
338
- in accord with this section must be in a format that is publicly
339
- documented (and with an implementation available to the public in
340
- source code form), and must require no special password or key for
341
- unpacking, reading or copying.
342
-
343
- 7. Additional Terms.
344
-
345
- "Additional permissions" are terms that supplement the terms of this
346
- License by making exceptions from one or more of its conditions.
347
- Additional permissions that are applicable to the entire Program shall
348
- be treated as though they were included in this License, to the extent
349
- that they are valid under applicable law. If additional permissions
350
- apply only to part of the Program, that part may be used separately
351
- under those permissions, but the entire Program remains governed by
352
- this License without regard to the additional permissions.
353
-
354
- When you convey a copy of a covered work, you may at your option
355
- remove any additional permissions from that copy, or from any part of
356
- it. (Additional permissions may be written to require their own
357
- removal in certain cases when you modify the work.) You may place
358
- additional permissions on material, added by you to a covered work,
359
- for which you have or can give appropriate copyright permission.
360
-
361
- Notwithstanding any other provision of this License, for material you
362
- add to a covered work, you may (if authorized by the copyright holders of
363
- that material) supplement the terms of this License with terms:
364
-
365
- a) Disclaiming warranty or limiting liability differently from the
366
- terms of sections 15 and 16 of this License; or
367
-
368
- b) Requiring preservation of specified reasonable legal notices or
369
- author attributions in that material or in the Appropriate Legal
370
- Notices displayed by works containing it; or
371
-
372
- c) Prohibiting misrepresentation of the origin of that material, or
373
- requiring that modified versions of such material be marked in
374
- reasonable ways as different from the original version; or
375
-
376
- d) Limiting the use for publicity purposes of names of licensors or
377
- authors of the material; or
378
-
379
- e) Declining to grant rights under trademark law for use of some
380
- trade names, trademarks, or service marks; or
381
-
382
- f) Requiring indemnification of licensors and authors of that
383
- material by anyone who conveys the material (or modified versions of
384
- it) with contractual assumptions of liability to the recipient, for
385
- any liability that these contractual assumptions directly impose on
386
- those licensors and authors.
387
-
388
- All other non-permissive additional terms are considered "further
389
- restrictions" within the meaning of section 10. If the Program as you
390
- received it, or any part of it, contains a notice stating that it is
391
- governed by this License along with a term that is a further
392
- restriction, you may remove that term. If a license document contains
393
- a further restriction but permits relicensing or conveying under this
394
- License, you may add to a covered work material governed by the terms
395
- of that license document, provided that the further restriction does
396
- not survive such relicensing or conveying.
397
-
398
- If you add terms to a covered work in accord with this section, you
399
- must place, in the relevant source files, a statement of the
400
- additional terms that apply to those files, or a notice indicating
401
- where to find the applicable terms.
402
-
403
- Additional terms, permissive or non-permissive, may be stated in the
404
- form of a separately written license, or stated as exceptions;
405
- the above requirements apply either way.
406
-
407
- 8. Termination.
408
-
409
- You may not propagate or modify a covered work except as expressly
410
- provided under this License. Any attempt otherwise to propagate or
411
- modify it is void, and will automatically terminate your rights under
412
- this License (including any patent licenses granted under the third
413
- paragraph of section 11).
414
-
415
- However, if you cease all violation of this License, then your
416
- license from a particular copyright holder is reinstated (a)
417
- provisionally, unless and until the copyright holder explicitly and
418
- finally terminates your license, and (b) permanently, if the copyright
419
- holder fails to notify you of the violation by some reasonable means
420
- prior to 60 days after the cessation.
421
-
422
- Moreover, your license from a particular copyright holder is
423
- reinstated permanently if the copyright holder notifies you of the
424
- violation by some reasonable means, this is the first time you have
425
- received notice of violation of this License (for any work) from that
426
- copyright holder, and you cure the violation prior to 30 days after
427
- your receipt of the notice.
428
-
429
- Termination of your rights under this section does not terminate the
430
- licenses of parties who have received copies or rights from you under
431
- this License. If your rights have been terminated and not permanently
432
- reinstated, you do not qualify to receive new licenses for the same
433
- material under section 10.
434
-
435
- 9. Acceptance Not Required for Having Copies.
436
-
437
- You are not required to accept this License in order to receive or
438
- run a copy of the Program. Ancillary propagation of a covered work
439
- occurring solely as a consequence of using peer-to-peer transmission
440
- to receive a copy likewise does not require acceptance. However,
441
- nothing other than this License grants you permission to propagate or
442
- modify any covered work. These actions infringe copyright if you do
443
- not accept this License. Therefore, by modifying or propagating a
444
- covered work, you indicate your acceptance of this License to do so.
445
-
446
- 10. Automatic Licensing of Downstream Recipients.
447
-
448
- Each time you convey a covered work, the recipient automatically
449
- receives a license from the original licensors, to run, modify and
450
- propagate that work, subject to this License. You are not responsible
451
- for enforcing compliance by third parties with this License.
452
-
453
- An "entity transaction" is a transaction transferring control of an
454
- organization, or substantially all assets of one, or subdividing an
455
- organization, or merging organizations. If propagation of a covered
456
- work results from an entity transaction, each party to that
457
- transaction who receives a copy of the work also receives whatever
458
- licenses to the work the party's predecessor in interest had or could
459
- give under the previous paragraph, plus a right to possession of the
460
- Corresponding Source of the work from the predecessor in interest, if
461
- the predecessor has it or can get it with reasonable efforts.
462
-
463
- You may not impose any further restrictions on the exercise of the
464
- rights granted or affirmed under this License. For example, you may
465
- not impose a license fee, royalty, or other charge for exercise of
466
- rights granted under this License, and you may not initiate litigation
467
- (including a cross-claim or counterclaim in a lawsuit) alleging that
468
- any patent claim is infringed by making, using, selling, offering for
469
- sale, or importing the Program or any portion of it.
470
-
471
- 11. Patents.
472
-
473
- A "contributor" is a copyright holder who authorizes use under this
474
- License of the Program or a work on which the Program is based. The
475
- work thus licensed is called the contributor's "contributor version".
476
-
477
- A contributor's "essential patent claims" are all patent claims
478
- owned or controlled by the contributor, whether already acquired or
479
- hereafter acquired, that would be infringed by some manner, permitted
480
- by this License, of making, using, or selling its contributor version,
481
- but do not include claims that would be infringed only as a
482
- consequence of further modification of the contributor version. For
483
- purposes of this definition, "control" includes the right to grant
484
- patent sublicenses in a manner consistent with the requirements of
485
  this License.
486
 
487
- Each contributor grants you a non-exclusive, worldwide, royalty-free
488
- patent license under the contributor's essential patent claims, to
489
- make, use, sell, offer for sale, import and otherwise run, modify and
490
- propagate the contents of its contributor version.
491
-
492
- In the following three paragraphs, a "patent license" is any express
493
- agreement or commitment, however denominated, not to enforce a patent
494
- (such as an express permission to practice a patent or covenant not to
495
- sue for patent infringement). To "grant" such a patent license to a
496
- party means to make such an agreement or commitment not to enforce a
497
- patent against the party.
498
-
499
- If you convey a covered work, knowingly relying on a patent license,
500
- and the Corresponding Source of the work is not available for anyone
501
- to copy, free of charge and under the terms of this License, through a
502
- publicly available network server or other readily accessible means,
503
- then you must either (1) cause the Corresponding Source to be so
504
- available, or (2) arrange to deprive yourself of the benefit of the
505
- patent license for this particular work, or (3) arrange, in a manner
506
- consistent with the requirements of this License, to extend the patent
507
- license to downstream recipients. "Knowingly relying" means you have
508
- actual knowledge that, but for the patent license, your conveying the
509
- covered work in a country, or your recipient's use of the covered work
510
- in a country, would infringe one or more identifiable patents in that
511
- country that you have reason to believe are valid.
512
-
513
- If, pursuant to or in connection with a single transaction or
514
- arrangement, you convey, or propagate by procuring conveyance of, a
515
- covered work, and grant a patent license to some of the parties
516
- receiving the covered work authorizing them to use, propagate, modify
517
- or convey a specific copy of the covered work, then the patent license
518
- you grant is automatically extended to all recipients of the covered
519
- work and works based on it.
520
-
521
- A patent license is "discriminatory" if it does not include within
522
- the scope of its coverage, prohibits the exercise of, or is
523
- conditioned on the non-exercise of one or more of the rights that are
524
- specifically granted under this License. You may not convey a covered
525
- work if you are a party to an arrangement with a third party that is
526
- in the business of distributing software, under which you make payment
527
- to the third party based on the extent of your activity of conveying
528
- the work, and under which the third party grants, to any of the
529
- parties who would receive the covered work from you, a discriminatory
530
- patent license (a) in connection with copies of the covered work
531
- conveyed by you (or copies made from those copies), or (b) primarily
532
- for and in connection with specific products or compilations that
533
- contain the covered work, unless you entered into that arrangement,
534
- or that patent license was granted, prior to 28 March 2007.
535
-
536
- Nothing in this License shall be construed as excluding or limiting
537
- any implied license or other defenses to infringement that may
538
- otherwise be available to you under applicable patent law.
539
-
540
- 12. No Surrender of Others' Freedom.
541
-
542
- If conditions are imposed on you (whether by court order, agreement or
543
  otherwise) that contradict the conditions of this License, they do not
544
- excuse you from the conditions of this License. If you cannot convey a
545
- covered work so as to satisfy simultaneously your obligations under this
546
- License and any other pertinent obligations, then as a consequence you may
547
- not convey it at all. For example, if you agree to terms that obligate you
548
- to collect a royalty for further conveying from those to whom you convey
549
- the Program, the only way you could satisfy both those terms and this
550
- License would be to refrain entirely from conveying the Program.
551
-
552
- 13. Use with the GNU Affero General Public License.
553
-
554
- Notwithstanding any other provision of this License, you have
555
- permission to link or combine any covered work with a work licensed
556
- under version 3 of the GNU Affero General Public License into a single
557
- combined work, and to convey the resulting work. The terms of this
558
- License will continue to apply to the part which is the covered work,
559
- but the special requirements of the GNU Affero General Public License,
560
- section 13, concerning interaction through a network will apply to the
561
- combination as such.
562
-
563
- 14. Revised Versions of this License.
564
-
565
- The Free Software Foundation may publish revised and/or new versions of
566
- the GNU General Public License from time to time. Such new versions will
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
567
  be similar in spirit to the present version, but may differ in detail to
568
  address new problems or concerns.
569
 
570
- Each version is given a distinguishing version number. If the
571
- Program specifies that a certain numbered version of the GNU General
572
- Public License "or any later version" applies to it, you have the
573
- option of following the terms and conditions either of that numbered
574
- version or of any later version published by the Free Software
575
- Foundation. If the Program does not specify a version number of the
576
- GNU General Public License, you may choose any version ever published
577
- by the Free Software Foundation.
578
-
579
- If the Program specifies that a proxy can decide which future
580
- versions of the GNU General Public License can be used, that proxy's
581
- public statement of acceptance of a version permanently authorizes you
582
- to choose that version for the Program.
583
-
584
- Later license versions may give you additional or different
585
- permissions. However, no additional obligations are imposed on any
586
- author or copyright holder as a result of your choosing to follow a
587
- later version.
588
-
589
- 15. Disclaimer of Warranty.
590
-
591
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
- APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
- HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
- OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
- PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
- IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
- ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
-
600
- 16. Limitation of Liability.
601
-
602
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
- THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
- GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
- USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
- DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
- PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
- EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
- SUCH DAMAGES.
611
-
612
- 17. Interpretation of Sections 15 and 16.
613
-
614
- If the disclaimer of warranty and limitation of liability provided
615
- above cannot be given local legal effect according to their terms,
616
- reviewing courts shall apply local law that most closely approximates
617
- an absolute waiver of all civil liability in connection with the
618
- Program, unless a warranty or assumption of liability accompanies a
619
- copy of the Program in return for a fee.
620
-
621
- END OF TERMS AND CONDITIONS
622
-
623
- How to Apply These Terms to Your New Programs
624
-
625
- If you develop a new program, and you want it to be of the greatest
626
- possible use to the public, the best way to achieve this is to make it
627
- free software which everyone can redistribute and change under these terms.
628
-
629
- To do so, attach the following notices to the program. It is safest
630
- to attach them to the start of each source file to most effectively
631
- state the exclusion of warranty; and each file should have at least
632
- the "copyright" line and a pointer to where the full notice is found.
633
-
634
- <one line to give the program's name and a brief idea of what it does.>
635
- Copyright (C) <year> <name of author>
636
-
637
- This program is free software: you can redistribute it and/or modify
638
- it under the terms of the GNU General Public License as published by
639
- the Free Software Foundation, either version 3 of the License, or
640
- (at your option) any later version.
641
-
642
- This program is distributed in the hope that it will be useful,
643
- but WITHOUT ANY WARRANTY; without even the implied warranty of
644
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
- GNU General Public License for more details.
646
-
647
- You should have received a copy of the GNU General Public License
648
- along with this program. If not, see <http://www.gnu.org/licenses/>.
649
-
650
- Also add information on how to contact you by electronic and paper mail.
651
-
652
- If the program does terminal interaction, make it output a short
653
- notice like this when it starts in an interactive mode:
654
-
655
- <program> Copyright (C) <year> <name of author>
656
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
- This is free software, and you are welcome to redistribute it
658
- under certain conditions; type `show c' for details.
659
-
660
- The hypothetical commands `show w' and `show c' should show the appropriate
661
- parts of the General Public License. Of course, your program's commands
662
- might be different; for a GUI interface, you would use an "about box".
663
-
664
- You should also get your employer (if you work as a programmer) or school,
665
- if any, to sign a "copyright disclaimer" for the program, if necessary.
666
- For more information on this, and how to apply and follow the GNU GPL, see
667
- <http://www.gnu.org/licenses/>.
668
-
669
- The GNU General Public License does not permit incorporating your program
670
- into proprietary programs. If your program is a subroutine library, you
671
- may consider it more useful to permit linking proprietary applications with
672
- the library. If this is what you want to do, use the GNU Lesser General
673
- Public License instead of this License. But first, please read
674
- <http://www.gnu.org/philosophy/why-not-lgpl.html>.
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
+ 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
6
 
 
7
  Everyone is permitted to copy and distribute verbatim copies
8
  of this license document, but changing it is not allowed.
9
 
10
+ Preamble
 
 
 
11
 
12
+ The licenses for most software are designed to take away your
13
+ freedom to share and change it. By contrast, the GNU General Public
14
+ License is intended to guarantee your freedom to share and change free
15
+ software--to make sure the software is free for all its users. This
16
+ General Public License applies to most of the Free Software
17
+ Foundation's software and to any other program whose authors commit to
18
+ using it. (Some other Free Software Foundation software is covered by
19
+ the GNU Library General Public License instead.) You can apply it to
20
  your programs, too.
21
 
22
  When we speak of free software, we are referring to freedom, not
23
  price. Our General Public Licenses are designed to make sure that you
24
  have the freedom to distribute copies of free software (and charge for
25
+ this service if you wish), that you receive source code or can get it
26
+ if you want it, that you can change the software or use pieces of it
27
+ in new free programs; and that you know you can do these things.
28
 
29
+ To protect your rights, we need to make restrictions that forbid
30
+ anyone to deny you these rights or to ask you to surrender the rights.
31
+ These restrictions translate to certain responsibilities for you if you
32
+ distribute copies of the software, or if you modify it.
33
 
34
  For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must give the recipients all the rights that
36
+ you have. You must make sure that they, too, receive or can get the
37
+ source code. And you must show them these terms so they know their
38
+ rights.
39
+
40
+ We protect your rights with two steps: (1) copyright the software, and
41
+ (2) offer you this license which gives you legal permission to copy,
42
+ distribute and/or modify the software.
43
+
44
+ Also, for each author's protection and ours, we want to make certain
45
+ that everyone understands that there is no warranty for this free
46
+ software. If the software is modified by someone else and passed on, we
47
+ want its recipients to know that what they have is not the original, so
48
+ that any problems introduced by others will not reflect on the original
49
+ authors' reputations.
50
+
51
+ Finally, any free program is threatened constantly by software
52
+ patents. We wish to avoid the danger that redistributors of a free
53
+ program will individually obtain patent licenses, in effect making the
54
+ program proprietary. To prevent this, we have made it clear that any
55
+ patent must be licensed for everyone's free use or not licensed at all.
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  The precise terms and conditions for copying, distribution and
58
  modification follow.
59
 
60
+ GNU GENERAL PUBLIC LICENSE
61
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
62
+
63
+ 0. This License applies to any program or other work which contains
64
+ a notice placed by the copyright holder saying it may be distributed
65
+ under the terms of this General Public License. The "Program", below,
66
+ refers to any such program or work, and a "work based on the Program"
67
+ means either the Program or any derivative work under copyright law:
68
+ that is to say, a work containing the Program or a portion of it,
69
+ either verbatim or with modifications and/or translated into another
70
+ language. (Hereinafter, translation is included without limitation in
71
+ the term "modification".) Each licensee is addressed as "you".
72
+
73
+ Activities other than copying, distribution and modification are not
74
+ covered by this License; they are outside its scope. The act of
75
+ running the Program is not restricted, and the output from the Program
76
+ is covered only if its contents constitute a work based on the
77
+ Program (independent of having been made by running the Program).
78
+ Whether that is true depends on what the Program does.
79
+
80
+ 1. You may copy and distribute verbatim copies of the Program's
81
+ source code as you receive it, in any medium, provided that you
82
+ conspicuously and appropriately publish on each copy an appropriate
83
+ copyright notice and disclaimer of warranty; keep intact all the
84
+ notices that refer to this License and to the absence of any warranty;
85
+ and give any other recipients of the Program a copy of this License
86
+ along with the Program.
87
+
88
+ You may charge a fee for the physical act of transferring a copy, and
89
+ you may at your option offer warranty protection in exchange for a fee.
90
+
91
+ 2. You may modify your copy or copies of the Program or any portion
92
+ of it, thus forming a work based on the Program, and copy and
93
+ distribute such modifications or work under the terms of Section 1
94
+ above, provided that you also meet all of these conditions:
95
+
96
+ a) You must cause the modified files to carry prominent notices
97
+ stating that you changed the files and the date of any change.
98
+
99
+ b) You must cause any work that you distribute or publish, that in
100
+ whole or in part contains or is derived from the Program or any
101
+ part thereof, to be licensed as a whole at no charge to all third
102
+ parties under the terms of this License.
103
+
104
+ c) If the modified program normally reads commands interactively
105
+ when run, you must cause it, when started running for such
106
+ interactive use in the most ordinary way, to print or display an
107
+ announcement including an appropriate copyright notice and a
108
+ notice that there is no warranty (or else, saying that you provide
109
+ a warranty) and that users may redistribute the program under
110
+ these conditions, and telling the user how to view a copy of this
111
+ License. (Exception: if the Program itself is interactive but
112
+ does not normally print such an announcement, your work based on
113
+ the Program is not required to print an announcement.)
114
+
115
+ These requirements apply to the modified work as a whole. If
116
+ identifiable sections of that work are not derived from the Program,
117
+ and can be reasonably considered independent and separate works in
118
+ themselves, then this License, and its terms, do not apply to those
119
+ sections when you distribute them as separate works. But when you
120
+ distribute the same sections as part of a whole which is a work based
121
+ on the Program, the distribution of the whole must be on the terms of
122
+ this License, whose permissions for other licensees extend to the
123
+ entire whole, and thus to each and every part regardless of who wrote it.
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  this License.
196
 
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
  be similar in spirit to the present version, but may differ in detail to
240
  address new problems or concerns.
241
 
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
screenshot-1.png CHANGED
Binary file
screenshot-2.png DELETED
Binary file
screenshot-3.png DELETED
Binary file
screenshot-4.png DELETED
Binary file
screenshot-5.png DELETED
Binary file
screenshot-6.png DELETED
Binary file
scripts-n-styles.php CHANGED
@@ -5,18 +5,15 @@ Plugin URI: http://www.unfocus.com/projects/scripts-n-styles/
5
  Description: Allows WordPress admin users the ability to add custom CSS and JavaScript directly to individual Post, Pages or custom post types.
6
  Author: unFocus Projects
7
  Author URI: http://www.unfocus.com/
8
- Version: 3.1
9
- License: GPLv3 or later
10
- Text Domain: scripts-n-styles
11
  Network: true
12
  */
 
13
 
14
- /* Copyright 2010-2012 Kenneth Newman www.unfocus.com
15
-
16
- This program is free software; you can redistribute it and/or
17
- modify it under the terms of the GNU General Public License
18
- as published by the Free Software Foundation; either version 3
19
- of the License, or (at your option) any later version.
20
 
21
  This program is distributed in the hope that it will be useful,
22
  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -25,9 +22,7 @@ Network: true
25
 
26
  You should have received a copy of the GNU General Public License
27
  along with this program; if not, write to the Free Software
28
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29
-
30
- This file incorporates work covered by other licenses and permissions.
31
  */
32
 
33
  /**
@@ -49,40 +44,39 @@ Network: true
49
  * @link http://www.unfocus.com/projects/scripts-n-styles/ Plugin URI
50
  * @author unFocus Projects
51
  * @link http://www.unfocus.com/ Author URI
52
- * @version 3.1
53
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
54
- * @copyright Copyright (c) 2010 - 2012, Kenneth Newman
55
- *
56
- * @todo Add Post Type Selection on Options Page? Not sure that's useful.
57
  * @todo Add Conditional Tags support as alternative to Globally applying Scripts n Styles.
58
  * @todo Create ability to add and register scripts and styles for enqueueing (via Options page).
59
  * @todo Create selection on Option page of which to pick registered scripts to make available on edit screens.
60
  * @todo Create shortcode to embed html/javascript snippets. See http://scribu.net/wordpress/optimal-script-loading.html in which this is already figured out :-)
61
  * @todo Create shortcode registration on Options page to make those snippets available on edit screens.
62
  * @todo Create shortcode registration of html snippets on edit screens for single use.
63
- * @todo Add Error messaging.
 
64
  * @todo Replace Multi-Select element with something better.
65
- * @todo "Include Scripts" will be reintroduced when registering is finished.
66
- * @todo Clean up tiny_mce_before_init in SnS_Admin_Meta_Box.
67
- * @todo LESS.js support.
68
- * @todo LESS.js highlighting support to CodeMirror.
69
- * @todo Solarize theme to CodeMirror.
70
  */
71
 
72
  class Scripts_n_Styles
73
  {
74
- /**#@+
75
- * @static
76
- */
77
- const VERSION = '3.1';
78
  static $file = __FILE__;
79
- /**#@-*/
 
 
80
 
81
- /**
82
  * Initializing method. Checks if is_admin() and registers action hooks for admin if true. Sets filters and actions for Theme side functions.
83
- * @static
84
- */
85
  static function init() {
 
86
  if ( is_admin() && ! ( defined('DISALLOW_UNFILTERED_HTML') && DISALLOW_UNFILTERED_HTML ) ) {
87
  /* NOTE: Setting the DISALLOW_UNFILTERED_HTML constant to
88
  true in the wp-config.php would effectively disable this
@@ -90,46 +84,43 @@ class Scripts_n_Styles
90
  */
91
  include_once( 'includes/class.SnS_Admin.php' );
92
  SnS_Admin::init();
 
93
  }
94
- add_action( 'plugins_loaded', array( __CLASS__, 'upgrade_check' ) );
95
 
96
  add_filter( 'body_class', array( __CLASS__, 'body_classes' ) );
97
  add_filter( 'post_class', array( __CLASS__, 'post_classes' ) );
98
 
99
  add_action( 'wp_head', array( __CLASS__, 'styles' ), 11 );
100
- add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ), 11 );
101
  add_action( 'wp_head', array( __CLASS__, 'scripts_in_head' ), 11 );
102
  add_action( 'wp_footer', array( __CLASS__, 'scripts' ), 11 );
103
-
104
- add_shortcode( 'sns_shortcode', array( __CLASS__, 'shortcode' ) );
105
  }
106
 
107
- function shortcode( $atts, $content = null, $tag ) {
 
 
 
 
108
  global $post;
109
-
110
- if ( isset( $post->ID ) ) $id = $post->ID;
111
- else $id = get_the_ID();
112
- if ( ! $id ) return '<pre>There was an error.</pre>';
113
-
114
- extract( shortcode_atts( array( 'name' => 0, ), $atts ) );
115
- $output = '';
116
-
117
- $SnS = get_post_meta( $post->ID, '_SnS', true );
118
- $shortcodes = isset( $SnS['shortcodes'] ) ? $SnS[ 'shortcodes' ]: array();
119
- if ( isset( $shortcodes[ $name ] ) )
120
- $output .= $shortcodes[ $name ];
121
- if ( isset( $content ) && empty( $output ) ) $output = $content;
122
- $output = do_shortcode( $output );
123
-
124
- return $output;
125
  }
126
 
127
- /**
128
  * Utility Method
129
- */
130
  static function get_wp_registered() {
131
  return array(
132
  // Starting with the list of Scripts registered by default on the Theme side (index page of twentyten).
 
133
  'l10n',
134
  'utils',
135
  'common',
@@ -191,161 +182,133 @@ class Scripts_n_Styles
191
  );
192
  }
193
 
194
- /**
195
  * Theme Action: 'wp_head()'
196
  * Outputs the globally and individually set Styles in the Theme's head element.
197
- */
198
  static function styles() {
199
  // Global
200
  $options = get_option( 'SnS_options' );
201
  if ( ! empty( $options ) && ! empty( $options[ 'styles' ] ) ) {
202
- ?><style type="text/css" id="sns_global_styles"><?php
203
  echo $options[ 'styles' ];
204
  ?></style><?php
205
  }
206
- if ( ! empty( $options ) && ! empty( $options[ 'compiled' ] ) ) {
207
- ?><style type="text/css" id="sns_global_less_compiled"><?php
208
- echo $options[ 'compiled' ];
209
- ?></style><?php
210
- }
211
 
212
  if ( ! is_singular() ) return;
213
  // Individual
214
- global $post;
215
- $SnS = get_post_meta( $post->ID, '_SnS', true );
216
- $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
217
  if ( ! empty( $styles ) && ! empty( $styles[ 'styles' ] ) ) {
218
- ?><style type="text/css" id="sns_styles"><?php
219
  echo $styles[ 'styles' ];
220
  ?></style><?php
221
  }
222
  }
223
 
224
- /**
225
  * Theme Action: 'wp_footer()'
226
  * Outputs the globally and individually set Scripts at the end of the Theme's body element.
227
- */
228
  static function scripts() {
229
  // Global
230
  $options = get_option( 'SnS_options' );
231
  if ( ! empty( $options ) && ! empty( $options[ 'scripts' ] ) ) {
232
- ?><script type="text/javascript" id="sns_global_scripts"><?php
233
  echo $options[ 'scripts' ];
234
  ?></script><?php
235
  }
236
 
237
  if ( ! is_singular() ) return;
238
  // Individual
239
- global $post;
240
- $SnS = get_post_meta( $post->ID, '_SnS', true );
241
- $scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
242
  if ( ! empty( $scripts ) && ! empty( $scripts[ 'scripts' ] ) ) {
243
- ?><script type="text/javascript" id="sns_scripts"><?php
244
  echo $scripts[ 'scripts' ];
245
  ?></script><?php
246
  }
247
  }
248
 
249
- /**
250
  * Theme Action: 'wp_head()'
251
  * Outputs the globally and individually set Scripts in the Theme's head element.
252
- */
253
  static function scripts_in_head() {
254
  // Global
255
  $options = get_option( 'SnS_options' );
256
- if ( ! empty( $options ) && ! empty( $options[ 'scripts_in_head' ] ) ) {
257
- ?><script type="text/javascript" id="sns_global_scripts_in_head"><?php
258
  echo $options[ 'scripts_in_head' ];
259
  ?></script><?php
260
  }
261
 
262
  if ( ! is_singular() ) return;
263
  // Individual
264
- global $post;
265
- $SnS = get_post_meta( $post->ID, '_SnS', true );
266
- $scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
267
  if ( ! empty( $scripts ) && ! empty( $scripts[ 'scripts_in_head' ] ) ) {
268
- ?><script type="text/javascript" id="sns_scripts_in_head"><?php
269
  echo $scripts[ 'scripts_in_head' ];
270
  ?></script><?php
271
  }
272
  }
273
 
274
- /**
275
  * Theme Filter: 'body_class()'
276
  * Adds classes to the Theme's body tag.
277
  * @uses self::get_styles()
278
  * @param array $classes
279
  * @return array $classes
280
- */
281
  static function body_classes( $classes ) {
282
- if ( ! is_singular() || is_admin() ) return $classes;
283
 
284
- global $post;
285
- $SnS = get_post_meta( $post->ID, '_SnS', true );
286
- $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
287
  if ( ! empty( $styles ) && ! empty( $styles[ 'classes_body' ] ) )
288
  $classes = array_merge( $classes, explode( " ", $styles[ 'classes_body' ] ) );
289
 
290
  return $classes;
291
  }
292
 
293
- /**
294
  * Theme Filter: 'post_class()'
295
  * Adds classes to the Theme's post container.
 
296
  * @param array $classes
297
  * @return array $classes
298
- */
299
  static function post_classes( $classes ) {
300
- if ( ! is_singular() || is_admin() ) return $classes;
301
-
302
- global $post;
303
- $SnS = get_post_meta( $post->ID, '_SnS', true );
304
- $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
305
 
 
306
  if ( ! empty( $styles ) && ! empty( $styles[ 'classes_post' ] ) )
307
  $classes = array_merge( $classes, explode( " ", $styles[ 'classes_post' ] ) );
308
 
309
  return $classes;
310
  }
311
 
312
- /**
313
  * Theme Action: 'wp_enqueue_scripts'
314
  * Enqueues chosen Scripts.
315
- */
 
 
316
  static function enqueue_scripts() {
317
  // Global
318
- $options = get_option( 'SnS_options' );
319
- if ( ! isset( $options[ 'enqueue_scripts' ] ) )
320
- $enqueue_scripts = array();
321
- else
322
- $enqueue_scripts = $options[ 'enqueue_scripts' ];
323
 
324
- foreach ( $enqueue_scripts as $handle )
325
- wp_enqueue_script( $handle );
 
 
326
 
327
  if ( ! is_singular() ) return;
328
  // Individual
329
- global $post;
330
- $SnS = get_post_meta( $post->ID, '_SnS', true );
331
- $scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
332
-
333
  if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) {
334
  foreach ( $scripts[ 'enqueue_scripts' ] as $handle )
335
  wp_enqueue_script( $handle );
336
  }
337
  }
338
 
339
- /**
340
- * Utility Method: Compares VERSION to stored 'version' value.
341
- */
342
- static function upgrade_check() {
343
- $options = get_option( 'SnS_options' );
344
- if ( ! isset( $options[ 'version' ] ) || version_compare( self::VERSION, $options[ 'version' ], '>' ) ) {
345
- include_once( 'includes/class.SnS_Admin.php' );
346
- SnS_Admin::upgrade();
347
- }
348
- }
349
  }
350
 
351
  Scripts_n_Styles::init();
5
  Description: Allows WordPress admin users the ability to add custom CSS and JavaScript directly to individual Post, Pages or custom post types.
6
  Author: unFocus Projects
7
  Author URI: http://www.unfocus.com/
8
+ Version: 2.0.1.1
9
+ License: GPL2
 
10
  Network: true
11
  */
12
+ /* Copyright 2010-2011 Kenneth Newman www.unfocus.com
13
 
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License, version 2, as
16
+ published by the Free Software Foundation.
 
 
 
17
 
18
  This program is distributed in the hope that it will be useful,
19
  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 
23
  You should have received a copy of the GNU General Public License
24
  along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
 
26
  */
27
 
28
  /**
44
  * @link http://www.unfocus.com/projects/scripts-n-styles/ Plugin URI
45
  * @author unFocus Projects
46
  * @link http://www.unfocus.com/ Author URI
47
+ * @version 2
48
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
49
+ * @copyright Copyright (c) 2010, Kenneth Newman
50
+ * @todo Add Post Type Selection on Options Page? Not sure that's usefull.
 
51
  * @todo Add Conditional Tags support as alternative to Globally applying Scripts n Styles.
52
  * @todo Create ability to add and register scripts and styles for enqueueing (via Options page).
53
  * @todo Create selection on Option page of which to pick registered scripts to make available on edit screens.
54
  * @todo Create shortcode to embed html/javascript snippets. See http://scribu.net/wordpress/optimal-script-loading.html in which this is already figured out :-)
55
  * @todo Create shortcode registration on Options page to make those snippets available on edit screens.
56
  * @todo Create shortcode registration of html snippets on edit screens for single use.
57
+ * @todo Figure out and add Error messaging.
58
+ * @todo Add ability to push class names into the TinyMCE editor Style Dropdown.
59
  * @todo Replace Multi-Select element with something better.
60
+ * @todo Clean up Usage Table, paginate, don't display when empty.
61
+ * @todo "Include Scripts" will be reintroduced when registing is finished.
 
 
 
62
  */
63
 
64
  class Scripts_n_Styles
65
  {
66
+ /**#@+
67
+ * @static
68
+ */
 
69
  static $file = __FILE__;
70
+ static $hook_suffix; // 'tools_page_Scripts-n-Styles';
71
+ static $plugin_file; // 'scripts-n-styles/scripts-n-styles.php'; kept here for reference
72
+ /**#@-*/
73
 
74
+ /**
75
  * Initializing method. Checks if is_admin() and registers action hooks for admin if true. Sets filters and actions for Theme side functions.
76
+ * @static
77
+ */
78
  static function init() {
79
+
80
  if ( is_admin() && ! ( defined('DISALLOW_UNFILTERED_HTML') && DISALLOW_UNFILTERED_HTML ) ) {
81
  /* NOTE: Setting the DISALLOW_UNFILTERED_HTML constant to
82
  true in the wp-config.php would effectively disable this
84
  */
85
  include_once( 'includes/class.SnS_Admin.php' );
86
  SnS_Admin::init();
87
+
88
  }
 
89
 
90
  add_filter( 'body_class', array( __CLASS__, 'body_classes' ) );
91
  add_filter( 'post_class', array( __CLASS__, 'post_classes' ) );
92
 
93
  add_action( 'wp_head', array( __CLASS__, 'styles' ), 11 );
94
+ //add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ), 11 );
95
  add_action( 'wp_head', array( __CLASS__, 'scripts_in_head' ), 11 );
96
  add_action( 'wp_footer', array( __CLASS__, 'scripts' ), 11 );
 
 
97
  }
98
 
99
+ /**
100
+ * Utility Method: Returns the value of $scripts if it is set, and if not, sets it via a call to the database.
101
+ * @return array 'ufp_script' meta data entry.
102
+ */
103
+ static function get_scripts() {
104
  global $post;
105
+ return get_post_meta( $post->ID, 'uFp_scripts', true );
106
+ }
107
+
108
+ /**
109
+ * Utility Method: Returns the value of $styles if it is set, and if not, sets it via a call to the database.
110
+ * @return array 'ufp_styles' meta data entry.
111
+ */
112
+ static function get_styles() {
113
+ global $post;
114
+ return get_post_meta( $post->ID, 'uFp_styles', true );
 
 
 
 
 
 
115
  }
116
 
117
+ /**
118
  * Utility Method
119
+ */
120
  static function get_wp_registered() {
121
  return array(
122
  // Starting with the list of Scripts registered by default on the Theme side (index page of twentyten).
123
+ // This list should be trimmed down, as some probably aren't apporpriate for Theme enqueueing.
124
  'l10n',
125
  'utils',
126
  'common',
182
  );
183
  }
184
 
185
+ /**
186
  * Theme Action: 'wp_head()'
187
  * Outputs the globally and individually set Styles in the Theme's head element.
188
+ */
189
  static function styles() {
190
  // Global
191
  $options = get_option( 'SnS_options' );
192
  if ( ! empty( $options ) && ! empty( $options[ 'styles' ] ) ) {
193
+ ?><style type="text/css"><?php
194
  echo $options[ 'styles' ];
195
  ?></style><?php
196
  }
 
 
 
 
 
197
 
198
  if ( ! is_singular() ) return;
199
  // Individual
200
+ $styles = self::get_styles();
 
 
201
  if ( ! empty( $styles ) && ! empty( $styles[ 'styles' ] ) ) {
202
+ ?><style type="text/css"><?php
203
  echo $styles[ 'styles' ];
204
  ?></style><?php
205
  }
206
  }
207
 
208
+ /**
209
  * Theme Action: 'wp_footer()'
210
  * Outputs the globally and individually set Scripts at the end of the Theme's body element.
211
+ */
212
  static function scripts() {
213
  // Global
214
  $options = get_option( 'SnS_options' );
215
  if ( ! empty( $options ) && ! empty( $options[ 'scripts' ] ) ) {
216
+ ?><script type="text/javascript"><?php
217
  echo $options[ 'scripts' ];
218
  ?></script><?php
219
  }
220
 
221
  if ( ! is_singular() ) return;
222
  // Individual
223
+ $scripts = self::get_scripts();
 
 
224
  if ( ! empty( $scripts ) && ! empty( $scripts[ 'scripts' ] ) ) {
225
+ ?><script type="text/javascript"><?php
226
  echo $scripts[ 'scripts' ];
227
  ?></script><?php
228
  }
229
  }
230
 
231
+ /**
232
  * Theme Action: 'wp_head()'
233
  * Outputs the globally and individually set Scripts in the Theme's head element.
234
+ */
235
  static function scripts_in_head() {
236
  // Global
237
  $options = get_option( 'SnS_options' );
238
+ if ( ! empty( $options ) && ! empty($options[ 'scripts_in_head' ]) ) {
239
+ ?><script type="text/javascript"><?php
240
  echo $options[ 'scripts_in_head' ];
241
  ?></script><?php
242
  }
243
 
244
  if ( ! is_singular() ) return;
245
  // Individual
246
+ $scripts = self::get_scripts();
 
 
247
  if ( ! empty( $scripts ) && ! empty( $scripts[ 'scripts_in_head' ] ) ) {
248
+ ?><script type="text/javascript"><?php
249
  echo $scripts[ 'scripts_in_head' ];
250
  ?></script><?php
251
  }
252
  }
253
 
254
+ /**
255
  * Theme Filter: 'body_class()'
256
  * Adds classes to the Theme's body tag.
257
  * @uses self::get_styles()
258
  * @param array $classes
259
  * @return array $classes
260
+ */
261
  static function body_classes( $classes ) {
262
+ if ( ! is_singular() ) return $classes;
263
 
264
+ $styles = self::get_styles();
 
 
265
  if ( ! empty( $styles ) && ! empty( $styles[ 'classes_body' ] ) )
266
  $classes = array_merge( $classes, explode( " ", $styles[ 'classes_body' ] ) );
267
 
268
  return $classes;
269
  }
270
 
271
+ /**
272
  * Theme Filter: 'post_class()'
273
  * Adds classes to the Theme's post container.
274
+ * @uses self::get_styles()
275
  * @param array $classes
276
  * @return array $classes
277
+ */
278
  static function post_classes( $classes ) {
279
+ if ( ! is_singular() ) return $classes;
 
 
 
 
280
 
281
+ $styles = self::get_styles();
282
  if ( ! empty( $styles ) && ! empty( $styles[ 'classes_post' ] ) )
283
  $classes = array_merge( $classes, explode( " ", $styles[ 'classes_post' ] ) );
284
 
285
  return $classes;
286
  }
287
 
288
+ /**
289
  * Theme Action: 'wp_enqueue_scripts'
290
  * Enqueues chosen Scripts.
291
+ * @uses self::get_enqueue()
292
+ * @uses self::get_scripts()
293
+ */
294
  static function enqueue_scripts() {
295
  // Global
296
+ $enqueue_scripts = get_option( 'SnS_enqueue_scripts' );
 
 
 
 
297
 
298
+ if ( is_array( $enqueue_scripts ) ) {
299
+ foreach ( $enqueue_scripts as $handle )
300
+ wp_enqueue_script( $handle );
301
+ }
302
 
303
  if ( ! is_singular() ) return;
304
  // Individual
305
+ $scripts = self::get_scripts();
 
 
 
306
  if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) {
307
  foreach ( $scripts[ 'enqueue_scripts' ] as $handle )
308
  wp_enqueue_script( $handle );
309
  }
310
  }
311
 
 
 
 
 
 
 
 
 
 
 
312
  }
313
 
314
  Scripts_n_Styles::init();
uninstall.php CHANGED
@@ -1,20 +1,14 @@
1
  <?php
2
- if( ! defined( 'ABSPATH' ) && ! defined( 'WP_UNINSTALL_PLUGIN' ) ) exit();
3
- $posts = get_posts( array(
4
- 'numberposts' => -1,
5
- 'post_type' => 'any',
6
- 'post_status' => 'any',
7
- 'orderby' => 'ID',
8
- 'meta_key' => '_SnS'
9
- ) );
10
-
11
- foreach( $posts as $post)
12
- delete_post_meta( $post->ID, '_SnS' );
13
- delete_option( 'SnS_options' );
14
-
15
- $users = get_users( 'meta_key=current_sns_tab' );
16
- foreach( $users as $user ) delete_user_option( $user->ID, 'current_sns_tab', true );
17
-
18
- $users = get_users( 'meta_key=scripts_n_styles_page_sns_usage_per_page' );
19
- foreach( $users as $user ) delete_user_option( $user->ID, 'scripts_n_styles_page_sns_usage_per_page', true );
20
  ?>
1
  <?php
2
+ if( !defined( 'ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') )
3
+ exit();
4
+ $get_posts_args = array('numberposts' => -1,
5
+ 'post_type' => 'any',
6
+ 'post_status' => 'any' );
7
+ $all_posts = get_posts( $get_posts_args );
8
+ foreach( $all_posts as $postinfo) {
9
+ delete_post_meta($postinfo->ID, 'uFp_scripts');
10
+ delete_post_meta($postinfo->ID, 'uFp_styles');
11
+ }
12
+ delete_option('sns_options');
13
+ delete_option('sns_enqueue_scripts');
 
 
 
 
 
 
14
  ?>