Version Description
- Fixed php notice/warning that would trigger if WP_DEBUG was enabled.
- Adding minified core JS.
- Adding global option to disable shortcode button in the content editor.
- Adding touchmove js event for faster scroll detection on mobile devices.
- Code clean up, removing unused functions.
Download this release
Release Info
Developer | dcooney |
Plugin | WordPress Infinite Scroll – Ajax Load More |
Version | 2.2.1 |
Comparing to | |
See all releases |
Code changes from version 2.1.3 to 2.2.1
- README.txt +55 -33
- admin/admin.php +206 -89
- admin/codemirror/addon/edit/closebrackets.js +158 -0
- admin/codemirror/addon/edit/closetag.js +141 -0
- admin/codemirror/addon/edit/continuelist.js +38 -0
- admin/codemirror/addon/edit/matchbrackets.js +120 -0
- admin/codemirror/addon/edit/matchtags.js +66 -0
- admin/codemirror/addon/edit/trailingspace.js +27 -0
- admin/codemirror/lib/codemirror.css +301 -0
- admin/codemirror/lib/codemirror.js +7801 -0
- admin/codemirror/mode/clike/clike.js +440 -0
- admin/codemirror/mode/clike/index.html +204 -0
- admin/codemirror/mode/clike/scala.html +767 -0
- admin/codemirror/mode/css/css.js +717 -0
- admin/codemirror/mode/css/index.html +70 -0
- admin/codemirror/mode/css/less.html +152 -0
- admin/codemirror/mode/css/less_test.js +51 -0
- admin/codemirror/mode/css/scss.html +157 -0
- admin/codemirror/mode/css/scss_test.js +110 -0
- admin/codemirror/mode/css/test.js +135 -0
- admin/codemirror/mode/htmlmixed/htmlmixed.js +120 -0
- admin/codemirror/mode/htmlmixed/index.html +85 -0
- admin/codemirror/mode/index.html +121 -0
- admin/codemirror/mode/javascript/index.html +109 -0
- admin/codemirror/mode/javascript/javascript.js +685 -0
- admin/codemirror/mode/javascript/json-ld.html +72 -0
- admin/codemirror/mode/javascript/test.js +187 -0
- admin/codemirror/mode/javascript/typescript.html +61 -0
- admin/codemirror/mode/php/index.html +64 -0
- admin/codemirror/mode/php/php.js +233 -0
- admin/codemirror/mode/php/test.js +148 -0
- admin/codemirror/mode/xml/index.html +57 -0
- admin/codemirror/mode/xml/test.js +51 -0
- admin/codemirror/mode/xml/xml.js +384 -0
- admin/css/admin.css +145 -32
- admin/editor-build.php +2 -2
- admin/editor.php +21 -6
- admin/img/add.png +0 -0
- admin/includes/cta/about.php +28 -11
- admin/includes/cta/extend.php +1 -1
- admin/includes/cta/resources.php +23 -7
- admin/js/editor-btn.js +1 -0
- admin/{js → shortcode-builder/js}/shortcode-builder.js +11 -2
- admin/{includes → shortcode-builder}/shortcode-builder.php +28 -3
- ajax-load-more.php +59 -30
- core/css/ajax-load-more.css +44 -34
- core/js/ajax-load-more.js +36 -24
- core/js/ajax-load-more.min.js +14 -0
- core/repeater/default.php +1 -1
- lang/ajax-load-more.pot +179 -138
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- screenshot-3.png +0 -0
- screenshot-4.png +0 -0
- screenshot-5.png +0 -0
- screenshot-6.png +0 -0
- screenshot-7.png +0 -0
README.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: dcooney
|
|
3 |
Donate link: http://connekthq.com/donate/
|
4 |
Tags: ajax, query, loop, paging, filter, jquery, shortcode builder, shortcode, search, tags, category
|
5 |
Requires at least: 3.6
|
6 |
-
Tested up to:
|
7 |
-
Stable tag: 2.1
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -19,10 +19,10 @@ Build complex WordPress queries using our shortcode builder then add the shortco
|
|
19 |
|
20 |
= Features =
|
21 |
|
22 |
-
* **Multiple Instances** - you can now include multiple instances of Ajax Load More on a single page.
|
23 |
-
* **Shortcode Builder** - create your own Ajax Load More shortcode by adjusting the various WordPress query parameters (see Shortcode Parameters).
|
24 |
-
* **Query Parameters** -
|
25 |
-
* **Customizable Repeater Templates** -
|
26 |
* **Setting Panel** - Customize your version of Ajax Load More by updating various plugin settings (see screenshots).
|
27 |
|
28 |
Check out the **[demo site](http://connekthq.com/plugins/ajax-load-more/)** for more information!
|
@@ -33,24 +33,26 @@ Check out the **[demo site](http://connekthq.com/plugins/ajax-load-more/)** for
|
|
33 |
|
34 |
Ajax Load More accepts a number of paramaters to pass to the WordPress query. These parameters are passed via shortcode - don't worry, creating your shortcode is simple with our Shortcode Builder.
|
35 |
|
36 |
-
* **repeater** -
|
37 |
-
* **post_type** -
|
38 |
-
* **
|
39 |
-
* **
|
40 |
-
* **
|
41 |
-
* **
|
42 |
-
* **
|
43 |
-
* **
|
44 |
-
* **
|
45 |
-
* **
|
46 |
-
* **
|
47 |
-
* **
|
48 |
-
* **
|
49 |
-
* **
|
50 |
-
* **
|
51 |
-
* **
|
52 |
-
* **
|
53 |
-
* **
|
|
|
|
|
54 |
|
55 |
|
56 |
|
@@ -73,7 +75,7 @@ The following Add-ons are available to increase the functionality of Ajax Load M
|
|
73 |
|
74 |
**Custom Repeaters**
|
75 |
|
76 |
-
The **[Custom Repeaters](http://connekthq.com/plugins/ajax-load-more/custom-repeaters) add-on will add
|
77 |
[Get More Information](http://connekthq.com/plugins/ajax-load-more/custom-repeaters)
|
78 |
|
79 |
|
@@ -103,9 +105,15 @@ Your ratings make a big difference! If you like and use Ajax Load More, please c
|
|
103 |
== Frequently Asked Questions ==
|
104 |
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
= What are my server requirements? =
|
107 |
|
108 |
-
Your server must be able to read/write/create files. Ajax Load More creates the default repeater on plugin activation and in order to modify the output
|
109 |
|
110 |
= Is the ajax functionality secure? =
|
111 |
|
@@ -117,13 +125,12 @@ Sure, but please be aware that if modifications are made it may affect future up
|
|
117 |
|
118 |
= Can I modify the repeater template? =
|
119 |
|
120 |
-
Yes, visit the Repeater Template
|
121 |
|
122 |
-
=
|
|
|
|
|
123 |
|
124 |
-
1. Create your shortcode
|
125 |
-
2. Add the shortcode to your page, by adding it through the content editor or placing it directly within one of your template files.
|
126 |
-
3. Load a page with your shortcode in place and watch Ajax Load More fetch your posts.
|
127 |
|
128 |
== Installation ==
|
129 |
|
@@ -163,10 +170,25 @@ How to install Ajax Load More.
|
|
163 |
|
164 |
== Changelog ==
|
165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
= 2.1.3 =
|
167 |
-
* Fixed issue
|
168 |
* Adding column 'alias' to wp_alm table to allow for repeater alias (Only for the custom repeater add-on).
|
169 |
-
* Remove
|
170 |
* Updating styles in admin.css.
|
171 |
|
172 |
= 2.1.2 =
|
3 |
Donate link: http://connekthq.com/donate/
|
4 |
Tags: ajax, query, loop, paging, filter, jquery, shortcode builder, shortcode, search, tags, category
|
5 |
Requires at least: 3.6
|
6 |
+
Tested up to: 4.0
|
7 |
+
Stable tag: 2.2.1
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
19 |
|
20 |
= Features =
|
21 |
|
22 |
+
* **Multiple Instances** - One, two, three or ten - you can now include multiple instances of Ajax Load More on a single page.
|
23 |
+
* **Shortcode Builder** - Easily create your own Ajax Load More shortcode by adjusting the various WordPress query parameters in our easy-to-use shortcode builder.(see Shortcode Parameters).
|
24 |
+
* **Query Parameters** - Ajax Load More allows you to query WordPress by many different content types. Query by Post Type, Post Format, Category, Tags, Custom Taxonomies, Search Term, Authors and more!!
|
25 |
+
* **Customizable Repeater Templates** - Edit and extend the functionality of Ajax Load More by creating your own repeater template to match the look and feel of your website.(see screenshots).
|
26 |
* **Setting Panel** - Customize your version of Ajax Load More by updating various plugin settings (see screenshots).
|
27 |
|
28 |
Check out the **[demo site](http://connekthq.com/plugins/ajax-load-more/)** for more information!
|
33 |
|
34 |
Ajax Load More accepts a number of paramaters to pass to the WordPress query. These parameters are passed via shortcode - don't worry, creating your shortcode is simple with our Shortcode Builder.
|
35 |
|
36 |
+
* **repeater** - Choose a repeater template (Add-on available). Default = ‘default‘
|
37 |
+
* **post_type** - Comma separated list of post types. Default = ‘post’
|
38 |
+
* **post_format** - Query by post format. Default = null
|
39 |
+
* **category** - Query by category slug. Default = null
|
40 |
+
* **tag** - Query by tag name. Default = null
|
41 |
+
* **taxonomy** - Query by custom taxonomy name. Default = null
|
42 |
+
* **taxonomy_terms** - Comma separated list of custom taxonomy terms(slug). Default = null
|
43 |
+
* **taxonomy_operator** - Operator to compare Taxonomy Terms against (IN/NOT IN). Default = ‘IN’
|
44 |
+
* **author** - Query by author id. Default = null
|
45 |
+
* **search** - Query search term (‘s’). Default = null
|
46 |
+
* **order** - Display posts in ASC(ascending) or DESC(descending) order. Default = ‘DESC’
|
47 |
+
* **orderby** - Order posts by date, title, name, menu order, random, author, post ID or comment count. Default = ‘date’
|
48 |
+
* **exclude** - Comma separated list of post ID’s to exclude from query. Default = null
|
49 |
+
* **offset** - Offset the initial query (number). Default = ’0′
|
50 |
+
* **posts_per_page** - Number of posts to load with each Ajax request. Default = ’5′
|
51 |
+
* **scroll** - Load more posts as the user scrolls the page (true/false). Default = ‘true’
|
52 |
+
* **max_pages** - Maximum number of pages to load while user is scrolling (activated on when scroll = true). Default = '5'
|
53 |
+
* **pause** - Do not load posts until user clicks the Load More button (true/false). Default = 'false'
|
54 |
+
* **transition** - Choose a posts reveal transition (slide/fade). Default = 'slide'
|
55 |
+
* **button_label** - The label text for Load More button. Default = 'Older Posts'
|
56 |
|
57 |
|
58 |
|
75 |
|
76 |
**Custom Repeaters**
|
77 |
|
78 |
+
The **[Custom Repeaters](http://connekthq.com/plugins/ajax-load-more/custom-repeaters)** add-on will add an additional five repeater templates allowing you to create unique templates for different content types throughout your theme.
|
79 |
[Get More Information](http://connekthq.com/plugins/ajax-load-more/custom-repeaters)
|
80 |
|
81 |
|
105 |
== Frequently Asked Questions ==
|
106 |
|
107 |
|
108 |
+
= What are the steps to getting Ajax Load More to display on my website =
|
109 |
+
|
110 |
+
1. Create your shortcode
|
111 |
+
2. Add the shortcode to your page, by adding it through the content editor or placing it directly within one of your template files.
|
112 |
+
3. Load a page with your shortcode in place and watch Ajax Load More fetch your posts.
|
113 |
+
|
114 |
= What are my server requirements? =
|
115 |
|
116 |
+
Your server must be able to read/write/create files. Ajax Load More creates the default repeater on plugin activation and in order to modify the output we are required to write to the file as well.
|
117 |
|
118 |
= Is the ajax functionality secure? =
|
119 |
|
125 |
|
126 |
= Can I modify the repeater template? =
|
127 |
|
128 |
+
Yes, visit the Repeater Template section in your WordPress admin.
|
129 |
|
130 |
+
= How are my repeater templates saved? =
|
131 |
+
|
132 |
+
Repeater template data is saved to the your WordPress database as well as written directly to a repeater template .php file in the ajax-load-more plugin directory.
|
133 |
|
|
|
|
|
|
|
134 |
|
135 |
== Installation ==
|
136 |
|
170 |
|
171 |
== Changelog ==
|
172 |
|
173 |
+
= 2.2.1 =
|
174 |
+
* Fixed php notice/warning that would trigger if WP_DEBUG was enabled.
|
175 |
+
* Adding minified core JS.
|
176 |
+
* Adding global option to disable shortcode button in the content editor.
|
177 |
+
* Adding touchmove js event for faster scroll detection on mobile devices.
|
178 |
+
* Code clean up, removing unused functions.
|
179 |
+
|
180 |
+
= 2.2.0 =
|
181 |
+
* Adding Post Format query.
|
182 |
+
* Adding syntax highlighting for Repeater Templates with CodeMirror (http://codemirror.net/).
|
183 |
+
* Adding custom alias integration for Repeater Templates (Only for the custom repeater add-on).
|
184 |
+
* Adding button preview on settings page.
|
185 |
+
* Adding 'White' button style.
|
186 |
+
* Updated .pot language file.
|
187 |
+
|
188 |
= 2.1.3 =
|
189 |
+
* Fixed issue causing the Ajax Load More menu to not show on some admin screen do to location conflict with another plugin.
|
190 |
* Adding column 'alias' to wp_alm table to allow for repeater alias (Only for the custom repeater add-on).
|
191 |
+
* Remove legacy column 'test' from wp_alm table.
|
192 |
* Updating styles in admin.css.
|
193 |
|
194 |
= 2.1.2 =
|
admin/admin.php
CHANGED
@@ -154,13 +154,33 @@ function alm_load_admin_js(){
|
|
154 |
|
155 |
function alm_enqueue_admin_scripts(){
|
156 |
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
}
|
165 |
|
166 |
|
@@ -177,26 +197,26 @@ function alm_settings_page(){ ?>
|
|
177 |
<div class="wrap">
|
178 |
<div class="header-wrap">
|
179 |
<h2><?php echo ALM_TITLE; ?> <span><?php echo ALM_VERSION; ?></span></h2>
|
180 |
-
<p>A
|
181 |
</div>
|
182 |
<div class="alm-main">
|
183 |
-
<
|
184 |
<form action="options.php" method="post">
|
185 |
<?php
|
186 |
settings_fields( 'alm-setting-group' );
|
187 |
do_settings_sections( 'ajax-load-more' );
|
188 |
//get the older values, wont work the first time
|
189 |
$options = get_option( '_alm_settings' ); ?>
|
190 |
-
<div class="row">
|
191 |
<?php submit_button('Save Settings'); ?>
|
192 |
</div>
|
193 |
</form>
|
194 |
-
</
|
195 |
</div>
|
196 |
-
<
|
197 |
<?php include( plugin_dir_path( __FILE__ ) . 'includes/cta/resources.php'); ?>
|
198 |
<?php include( plugin_dir_path( __FILE__ ) . 'includes/cta/about.php'); ?>
|
199 |
-
</
|
200 |
|
201 |
</div>
|
202 |
</div>
|
@@ -216,13 +236,19 @@ function alm_repeater_page(){ ?>
|
|
216 |
<div class="admin ajax-load-more" id="alm-repeaters">
|
217 |
<div class="wrap">
|
218 |
<div class="header-wrap">
|
219 |
-
<h2><?php _e('Ajax
|
220 |
<p><?php _e('The library of available templates to use throughout your theme', ALM_NAME); ?></p>
|
221 |
</div>
|
222 |
<div class="alm-main form-table repeaters">
|
|
|
223 |
<!-- Repeaters -->
|
224 |
-
<
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
226 |
<div class="row default-repeater">
|
227 |
<?php
|
228 |
$filename = ALM_PATH. 'core/repeater/default.php';
|
@@ -233,21 +259,32 @@ function alm_repeater_page(){ ?>
|
|
233 |
<h3 class="heading"><?php _e('Default Template', ALM_NAME); ?></h3>
|
234 |
<div class="expand-wrap">
|
235 |
<div class="wrap repeater-wrap" data-name="default">
|
236 |
-
<label class="template-title" for="
|
237 |
-
<textarea rows="10" id="
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
<div class="saved-response"> </div>
|
240 |
</div>
|
241 |
</div>
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
</div>
|
251 |
<!-- End Default -->
|
252 |
<?php
|
253 |
if (has_action('alm_custom_repeaters'))
|
@@ -265,15 +302,42 @@ function alm_repeater_page(){ ?>
|
|
265 |
* @since 2.0.0
|
266 |
*/
|
267 |
|
268 |
-
_alm_admin.saveRepeater = function(btn) {
|
269 |
var container = btn.parent('.repeater-wrap'),
|
270 |
el = $('textarea._alm_repeater', container),
|
271 |
-
value = el.val(),
|
272 |
btn = btn,
|
|
|
273 |
repeater = container.data('name'),
|
274 |
alias = ($('input._alm_repeater_alias', container).length) ? $('input._alm_repeater_alias', container).val() : '',
|
275 |
responseText = $(".saved-response", container);
|
276 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
//If submit button has changed class.
|
278 |
if (btn.hasClass('changed')) { // If repeater value has changed.
|
279 |
responseText.addClass('loading').html('<?php _e('Saving data...', ALM_NAME) ?>');
|
@@ -289,7 +353,7 @@ function alm_repeater_page(){ ?>
|
|
289 |
},
|
290 |
success: function(e) {
|
291 |
setTimeout(function(){
|
292 |
-
responseText.html('<?php _e('
|
293 |
setTimeout(function() {
|
294 |
responseText.html(' ').removeClass('saved');
|
295 |
}, 3000);
|
@@ -297,7 +361,7 @@ function alm_repeater_page(){ ?>
|
|
297 |
btn.removeClass('changed');
|
298 |
},
|
299 |
error: function(xhr, status, error) {
|
300 |
-
responseText.html('<?php _e('Something went wrong and the data could not be saved
|
301 |
btn.removeClass('changed');
|
302 |
}
|
303 |
});
|
@@ -305,17 +369,18 @@ function alm_repeater_page(){ ?>
|
|
305 |
}
|
306 |
$('input.save-repeater').each(function(){
|
307 |
$(this).click(function() {
|
308 |
-
var btn = $(this)
|
|
|
309 |
btn.addClass('changed');
|
310 |
-
_alm_admin.saveRepeater(btn);
|
311 |
});
|
312 |
});
|
313 |
});
|
314 |
</script>
|
315 |
-
</
|
316 |
<!-- End Repeaters -->
|
317 |
</div>
|
318 |
-
<
|
319 |
<div class="cta">
|
320 |
<h3><?php _e('Templating Help', ALM_NAME); ?></h3>
|
321 |
<div class="item">
|
@@ -334,7 +399,7 @@ function alm_repeater_page(){ ?>
|
|
334 |
</div>
|
335 |
</div>
|
336 |
<?php include( plugin_dir_path( __FILE__ ) . 'includes/cta/writeable.php'); ?>
|
337 |
-
</
|
338 |
</div>
|
339 |
</div>
|
340 |
|
@@ -400,18 +465,18 @@ function alm_shortcode_builder_page(){ ?>
|
|
400 |
<div class="admin ajax-load-more" id="alm-builder">
|
401 |
<div class="wrap">
|
402 |
<div class="header-wrap">
|
403 |
-
<h2><?php _e('Ajax
|
404 |
<p><?php _e('Create your own Ajax Load More <a href="http://en.support.wordpress.com/shortcodes/" target="_blank">shortcode</a> by adjusting the values below', ALM_NAME); ?></p>
|
405 |
</div>
|
406 |
<div class="alm-main">
|
407 |
-
<
|
408 |
-
<?php include( plugin_dir_path( __FILE__ ) . '
|
409 |
-
<div class="row">
|
410 |
<p class="back2top"><a href="#wpcontent"><i class="fa fa-chevron-up"></i> <?php _e('Back to Top', ALM_NAME); ?></a></p>
|
411 |
</div>
|
412 |
-
</
|
413 |
</div>
|
414 |
-
<
|
415 |
<div class="cta">
|
416 |
<h3><?php _e('Shortcode Output', ALM_NAME); ?></h3>
|
417 |
<p><?php _e('Copy and paste the following shortcode into the content editor or widget area of your theme.', ALM_NAME); ?></p>
|
@@ -423,9 +488,9 @@ function alm_shortcode_builder_page(){ ?>
|
|
423 |
<div class="cta">
|
424 |
<h3><?php _e('Did you know?', ALM_NAME); ?></h3>
|
425 |
<img src="<?php echo ALM_ADMIN_URL; ?>img/add-ons/shortcode-editor.jpg"><br/>
|
426 |
-
<?php _e('<p class="addon-intro">You can generate shortcodes while editing pages!</p><p>
|
427 |
</div>
|
428 |
-
</
|
429 |
</div>
|
430 |
</div>
|
431 |
<?php
|
@@ -480,11 +545,11 @@ function alm_example_page(){ ?>
|
|
480 |
<div class="admin ajax-load-more" id="alm-examples">
|
481 |
<div class="wrap">
|
482 |
<div class="header-wrap">
|
483 |
-
<h2><?php _e('Ajax
|
484 |
<p><?php _e('A collection of everyday shortcode usages and implementation examples', ALM_NAME); ?></p>
|
485 |
</div>
|
486 |
<div class="alm-main forceColors">
|
487 |
-
<
|
488 |
<div class="row gist">
|
489 |
<h3 class="heading"><?php _e('Author.php', ALM_NAME); ?></h3>
|
490 |
<div class="expand-wrap">
|
@@ -523,15 +588,15 @@ function alm_example_page(){ ?>
|
|
523 |
<div class="row">
|
524 |
<p class="back2top"><a href="#wpcontent"><i class="fa fa-chevron-up"></i> <?php _e('Back to Top', ALM_NAME); ?></a></p>
|
525 |
</div>
|
526 |
-
</
|
527 |
</div>
|
528 |
-
<
|
529 |
<div class="cta">
|
530 |
<h3><?php _e('Request Examples', ALM_NAME); ?></h3>
|
531 |
<p><?php _e('If you\'re having issue\'s with functionality, please submit example requests through the <a href="https://github.com/dcooney/wordpress-ajax-load-more" target="_blank">GitHub repository</a>. ', ALM_NAME); ?></p>
|
532 |
</div>
|
533 |
<?php include( plugin_dir_path( __FILE__ ) . 'includes/cta/about.php'); ?>
|
534 |
-
</
|
535 |
|
536 |
|
537 |
</div>
|
@@ -552,22 +617,21 @@ function alm_add_ons_page(){ ?>
|
|
552 |
<div class="admin ajax-load-more" id="alm-add-ons">
|
553 |
<div class="wrap">
|
554 |
<div class="header-wrap">
|
555 |
-
<h2><?php _e('Ajax
|
556 |
<p><?php _e('The following Add-ons are available to increase the functionality of Ajax Load More.', ALM_NAME); ?></p>
|
557 |
</div>
|
558 |
-
<div class="alm-main
|
559 |
<!-- Custom Repeater -->
|
560 |
-
<
|
561 |
-
<div class="row">
|
562 |
<h3 class="add-on-title"><?php _e('Custom Repeaters', ALM_NAME); ?></h3>
|
563 |
<div class="expand-wrap">
|
564 |
<div class="section-title">
|
565 |
<img src="<?php echo ALM_ADMIN_URL; ?>img/add-ons/repeater-add-ons.jpg">
|
566 |
</div>
|
567 |
<div class="wrap">
|
568 |
-
<p class="addon-intro"><?php _e('Unlock additional repeater templates and keep your
|
569 |
-
<p><?php _e('The Custom Repeaters add-on will add <strong>five</strong> additional <a href="?page=ajax-load-more-repeaters">repeaters</a> and allow you to select unique repeaters for different content types throughout your theme.</p>
|
570 |
-
<p>It\'s easy, seriously! Simply build each <a href="?page=ajax-load-more-repeaters">repeater</a> just the way you want them, then select a template from the list of available templates while building your <a href="?page=ajax-load-more-shortcode-builder">shortcode</a>.</p><p><strong>Read/Write Access is required!</strong></p>', ALM_NAME); ?>
|
571 |
</div>
|
572 |
</div>
|
573 |
</div>
|
@@ -578,17 +642,21 @@ function alm_add_ons_page(){ ?>
|
|
578 |
echo '<a class="btn" href="http://connekthq.com/plugins/ajax-load-more/custom-repeaters/" target="_blank"><i class="fa fa-download"></i> Purchase & Install</a>';
|
579 |
}
|
580 |
?>
|
581 |
-
</
|
582 |
<!-- End Custom Repeater -->
|
583 |
</div>
|
584 |
|
585 |
-
<
|
|
|
|
|
|
|
|
|
586 |
<div class="cta">
|
587 |
<h3><?php _e('About Add-ons', ALM_NAME); ?></h3>
|
588 |
<p><?php _e('Add-ons are installed as a separate plugin and will receive plug-in update notifications. ', ALM_NAME); ?></p>
|
589 |
</div>
|
590 |
<?php include( plugin_dir_path( __FILE__ ) . 'includes/cta/writeable.php'); ?>
|
591 |
-
</
|
592 |
|
593 |
</div>
|
594 |
</div>
|
@@ -616,20 +684,15 @@ function alm_admin_init(){
|
|
616 |
'alm_general_settings_callback',
|
617 |
'ajax-load-more'
|
618 |
);
|
619 |
-
|
620 |
-
|
621 |
-
__('Disable CSS', ALM_NAME ),
|
622 |
-
'alm_disable_css_callback',
|
623 |
-
'ajax-load-more',
|
624 |
-
'alm_general_settings'
|
625 |
-
);
|
626 |
-
add_settings_field(
|
627 |
'_alm_html5',
|
628 |
__('HTML5 Elements', ALM_NAME ),
|
629 |
'alm_html5_callback',
|
630 |
'ajax-load-more',
|
631 |
'alm_general_settings'
|
632 |
-
);
|
|
|
633 |
add_settings_field(
|
634 |
'_alm_container_type',
|
635 |
__('Container Type', ALM_NAME ),
|
@@ -637,20 +700,38 @@ function alm_admin_init(){
|
|
637 |
'ajax-load-more',
|
638 |
'alm_general_settings'
|
639 |
);
|
|
|
640 |
add_settings_field(
|
641 |
'_alm_classname',
|
642 |
-
__('Container
|
643 |
'alm_class_callback',
|
644 |
'ajax-load-more',
|
645 |
'alm_general_settings'
|
646 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
647 |
add_settings_field(
|
648 |
'_alm_btn_color',
|
649 |
__('Button Color', ALM_NAME ),
|
650 |
'alm_btn_color_callback',
|
651 |
'ajax-load-more',
|
652 |
'alm_general_settings'
|
653 |
-
);
|
654 |
}
|
655 |
|
656 |
|
@@ -663,7 +744,7 @@ function alm_admin_init(){
|
|
663 |
*/
|
664 |
|
665 |
function alm_general_settings_callback() {
|
666 |
-
echo '<p>' . __('Customize your version of Ajax Load More by updating the fields below.</p><p class="small">All changes will be applied globally
|
667 |
}
|
668 |
|
669 |
|
@@ -692,31 +773,33 @@ function alm_disable_css_callback(){
|
|
692 |
$options['_alm_disable_css'] = '0';
|
693 |
|
694 |
echo '<input type="hidden" name="alm_settings[_alm_disable_css]" value="0" />
|
695 |
-
<label><input type="checkbox" name="alm_settings[_alm_disable_css]" value="1"'. (($options['_alm_disable_css']) ? ' checked="checked"' : '') .' /> I want to use my own CSS styles</label>';
|
696 |
-
echo '<p class="desc"><i class="fa fa-file-text-o"></i> <a href="'.ALM_URL.'/core/css/ajax-load-more.css" target="blank">View Ajax Load More CSS</a></p>';
|
|
|
|
|
697 |
}
|
698 |
|
699 |
|
700 |
/*
|
701 |
-
*
|
702 |
-
*
|
703 |
*
|
704 |
-
* @since 2.
|
705 |
*/
|
706 |
|
707 |
-
function
|
708 |
$options = get_option( 'alm_settings' );
|
709 |
-
if(!isset($options['
|
710 |
-
$options['
|
711 |
|
712 |
-
echo '<input type="hidden" name="alm_settings[
|
713 |
-
<label><input type="checkbox" name="alm_settings[
|
714 |
}
|
715 |
|
716 |
|
717 |
/*
|
718 |
* alm_class_callback
|
719 |
-
*
|
720 |
*
|
721 |
* @since 2.0.0
|
722 |
*/
|
@@ -724,7 +807,7 @@ function alm_html5_callback(){
|
|
724 |
function alm_class_callback(){
|
725 |
$options = get_option( 'alm_settings' );
|
726 |
|
727 |
-
echo '<label for="alm_settings[_alm_classname]">Add classes to Ajax Load More container
|
728 |
}
|
729 |
|
730 |
|
@@ -743,10 +826,10 @@ function alm_container_type_callback() {
|
|
743 |
$options['_alm_container_type'] = '1';
|
744 |
|
745 |
$html = '<input type="radio" id="_alm_container_type_one" name="alm_settings[_alm_container_type]" value="1"' . checked( 1, $options['_alm_container_type'], false ) . '/>';
|
746 |
-
$html .= '<label for="_alm_container_type_one"><ul> <span><!-- Ajax Posts Here --></span> </ul></label><br/>';
|
747 |
|
748 |
$html .= '<input type="radio" id="_alm_container_type_two" name="alm_settings[_alm_container_type]" value="2"' . checked( 2, $options['_alm_container_type'], false ) . '/>';
|
749 |
-
$html .= '<label for="_alm_container_type_two"><div> <span><!-- Ajax Posts Here --></span> </div></label>';
|
750 |
|
751 |
echo $html;
|
752 |
|
@@ -793,18 +876,52 @@ function alm_btn_color_callback() {
|
|
793 |
if($color == 'grey')
|
794 |
$selected5 = 'selected="selected"';
|
795 |
|
796 |
-
|
797 |
-
|
|
|
|
|
|
|
|
|
798 |
$html .= '<option value="default" ' . $selected0 .'>Default (Orange)</option>';
|
799 |
$html .= '<option value="blue" ' . $selected1 .'>Blue</option>';
|
800 |
$html .= '<option value="green" ' . $selected2 .'>Green</option>';
|
801 |
$html .= '<option value="red" ' . $selected3 .'>Red</option>';
|
802 |
$html .= '<option value="purple" ' . $selected4 .'>Purple</option>';
|
803 |
$html .= '<option value="grey" ' . $selected5 .'>Grey</option>';
|
|
|
804 |
$html .= '</select>';
|
805 |
|
|
|
806 |
echo $html;
|
807 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
808 |
}
|
809 |
|
810 |
|
154 |
|
155 |
function alm_enqueue_admin_scripts(){
|
156 |
|
157 |
+
//Load Admin CSS
|
158 |
+
wp_enqueue_style( 'admin-css', ALM_ADMIN_URL. 'css/admin.css');
|
159 |
+
wp_enqueue_style( 'core-css', ALM_URL. '/core/css/ajax-load-more.css');
|
160 |
+
wp_enqueue_style( 'font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css');
|
161 |
+
|
162 |
+
//Load CodeMirror Syntax Highlighting if on Repater Template page
|
163 |
+
$screen = get_current_screen();
|
164 |
+
if ( in_array( $screen->id, array( 'ajax-load-more_page_ajax-load-more-repeaters') ) ){
|
165 |
+
|
166 |
+
//CodeMirror CSS
|
167 |
+
wp_enqueue_style( 'codemirror-css', ALM_ADMIN_URL. 'codemirror/lib/codemirror.css' );
|
168 |
+
|
169 |
+
//CodeMirror JS
|
170 |
+
wp_enqueue_script( 'codemirror', ALM_ADMIN_URL. 'codemirror/lib/codemirror.js');
|
171 |
+
wp_enqueue_script( 'codemirror-matchbrackets', ALM_ADMIN_URL. 'codemirror/addon/edit/matchbrackets.js' );
|
172 |
+
wp_enqueue_script( 'codemirror-htmlmixed', ALM_ADMIN_URL. 'codemirror/mode/htmlmixed/htmlmixed.js' );
|
173 |
+
wp_enqueue_script( 'codemirror-xml', ALM_ADMIN_URL. 'codemirror/mode/xml/xml.js' );
|
174 |
+
wp_enqueue_script( 'codemirror-javascript', ALM_ADMIN_URL. 'codemirror/mode/javascript/javascript.js' );
|
175 |
+
wp_enqueue_script( 'codemirror-mode-css', ALM_ADMIN_URL. 'codemirror/mode/css/css.js' );
|
176 |
+
wp_enqueue_script( 'codemirror-clike', ALM_ADMIN_URL. 'codemirror/mode/clike/clike.js' );
|
177 |
+
wp_enqueue_script( 'codemirror-php', ALM_ADMIN_URL. 'codemirror/mode/php/php.js' );
|
178 |
+
|
179 |
+
}
|
180 |
+
|
181 |
+
//Load JS
|
182 |
+
wp_enqueue_script( 'select2', ALM_ADMIN_URL. 'js/libs/select2.min.js', array( 'jquery' ));
|
183 |
+
wp_enqueue_script( 'shortcode-builder', ALM_ADMIN_URL. 'shortcode-builder/js/shortcode-builder.js', array( 'jquery' ));
|
184 |
}
|
185 |
|
186 |
|
197 |
<div class="wrap">
|
198 |
<div class="header-wrap">
|
199 |
<h2><?php echo ALM_TITLE; ?> <span><?php echo ALM_VERSION; ?></span></h2>
|
200 |
+
<p>A WordPress plugin for lazy loading posts with Ajax</p>
|
201 |
</div>
|
202 |
<div class="alm-main">
|
203 |
+
<div class="group">
|
204 |
<form action="options.php" method="post">
|
205 |
<?php
|
206 |
settings_fields( 'alm-setting-group' );
|
207 |
do_settings_sections( 'ajax-load-more' );
|
208 |
//get the older values, wont work the first time
|
209 |
$options = get_option( '_alm_settings' ); ?>
|
210 |
+
<div class="row no-brd">
|
211 |
<?php submit_button('Save Settings'); ?>
|
212 |
</div>
|
213 |
</form>
|
214 |
+
</div>
|
215 |
</div>
|
216 |
+
<div class="alm-sidebar">
|
217 |
<?php include( plugin_dir_path( __FILE__ ) . 'includes/cta/resources.php'); ?>
|
218 |
<?php include( plugin_dir_path( __FILE__ ) . 'includes/cta/about.php'); ?>
|
219 |
+
</div>
|
220 |
|
221 |
</div>
|
222 |
</div>
|
236 |
<div class="admin ajax-load-more" id="alm-repeaters">
|
237 |
<div class="wrap">
|
238 |
<div class="header-wrap">
|
239 |
+
<h2><?php _e('Ajax Load More: Repeater Templates', ALM_NAME); ?></h2>
|
240 |
<p><?php _e('The library of available templates to use throughout your theme', ALM_NAME); ?></p>
|
241 |
</div>
|
242 |
<div class="alm-main form-table repeaters">
|
243 |
+
|
244 |
<!-- Repeaters -->
|
245 |
+
<div class="group">
|
246 |
+
<?php
|
247 |
+
if (has_action('alm_custom_repeaters')){ ?>
|
248 |
+
<span class="toggle-all"><span class="inner-wrap"><em class="collapse"><?php _e('Collapse All', ALM_NAME); ?></em><em class="expand"><?php _e('Expand All', ALM_NAME); ?></em></span></span>
|
249 |
+
<?php } ?>
|
250 |
+
|
251 |
+
<!-- Default -->
|
252 |
<div class="row default-repeater">
|
253 |
<?php
|
254 |
$filename = ALM_PATH. 'core/repeater/default.php';
|
259 |
<h3 class="heading"><?php _e('Default Template', ALM_NAME); ?></h3>
|
260 |
<div class="expand-wrap">
|
261 |
<div class="wrap repeater-wrap" data-name="default">
|
262 |
+
<label class="template-title" for="template-default"><?php _e('Enter the HTML and PHP code for the default template', ALM_NAME); ?></label>
|
263 |
+
<textarea rows="10" id="template-default" class="_alm_repeater"><?php echo $contents; ?></textarea>
|
264 |
+
<script>
|
265 |
+
var editorDefault = CodeMirror.fromTextArea(document.getElementById("template-default"), {
|
266 |
+
mode: "application/x-httpd-php",
|
267 |
+
lineNumbers: true,
|
268 |
+
lineWrapping: true,
|
269 |
+
indentUnit: 0,
|
270 |
+
matchBrackets: true,
|
271 |
+
//theme: 'pastel-on-dark',
|
272 |
+
viewportMargin: Infinity,
|
273 |
+
extraKeys: {"Ctrl-Space": "autocomplete"},
|
274 |
+
});
|
275 |
+
</script>
|
276 |
+
<input type="submit" value="<?php _e('Save Template', ALM_NAME); ?>" class="button button-primary save-repeater" data-editor-id="template-default">
|
277 |
<div class="saved-response"> </div>
|
278 |
</div>
|
279 |
</div>
|
280 |
+
</div>
|
281 |
+
<?php
|
282 |
+
if (!has_action('alm_get_custom_repeaters')) {
|
283 |
+
echo '<div class="row no-brd">';
|
284 |
+
include( ALM_PATH. 'admin/includes/cta/extend.php');
|
285 |
+
echo '</div>';
|
286 |
+
}
|
287 |
+
?>
|
|
|
288 |
<!-- End Default -->
|
289 |
<?php
|
290 |
if (has_action('alm_custom_repeaters'))
|
302 |
* @since 2.0.0
|
303 |
*/
|
304 |
|
305 |
+
_alm_admin.saveRepeater = function(btn, editorId) {
|
306 |
var container = btn.parent('.repeater-wrap'),
|
307 |
el = $('textarea._alm_repeater', container),
|
|
|
308 |
btn = btn,
|
309 |
+
value = '',
|
310 |
repeater = container.data('name'),
|
311 |
alias = ($('input._alm_repeater_alias', container).length) ? $('input._alm_repeater_alias', container).val() : '',
|
312 |
responseText = $(".saved-response", container);
|
313 |
|
314 |
+
//Get value from CodeMirroweditor
|
315 |
+
|
316 |
+
// Default Template
|
317 |
+
if(editorId === 'template-default')
|
318 |
+
value = editorDefault.getValue();
|
319 |
+
|
320 |
+
//Custom Repeater template add-on
|
321 |
+
if(editorId === 'template-repeater2')
|
322 |
+
value = editor_repeater2.getValue();
|
323 |
+
|
324 |
+
if(editorId === 'template-repeater3')
|
325 |
+
value = editor_repeater3.getValue();
|
326 |
+
|
327 |
+
if(editorId === 'template-repeater4')
|
328 |
+
value = editor_repeater4.getValue();
|
329 |
+
|
330 |
+
if(editorId === 'template-repeater5')
|
331 |
+
value = editor_repeater5.getValue();
|
332 |
+
|
333 |
+
if(editorId === 'template-repeater6')
|
334 |
+
value = editor_repeater6.getValue();
|
335 |
+
|
336 |
+
if(value === '' || value === 'undefined'){
|
337 |
+
alert("Sorry, an error has occured");
|
338 |
+
return false;
|
339 |
+
}
|
340 |
+
|
341 |
//If submit button has changed class.
|
342 |
if (btn.hasClass('changed')) { // If repeater value has changed.
|
343 |
responseText.addClass('loading').html('<?php _e('Saving data...', ALM_NAME) ?>');
|
353 |
},
|
354 |
success: function(e) {
|
355 |
setTimeout(function(){
|
356 |
+
responseText.html('<?php _e('Template saved successfully', ALM_NAME) ?>').removeClass('loading').addClass('saved');
|
357 |
setTimeout(function() {
|
358 |
responseText.html(' ').removeClass('saved');
|
359 |
}, 3000);
|
361 |
btn.removeClass('changed');
|
362 |
},
|
363 |
error: function(xhr, status, error) {
|
364 |
+
responseText.html('<?php _e('Something went wrong and the data could not be saved', ALM_NAME) ?>').removeClass('loading').removeClass('saved');
|
365 |
btn.removeClass('changed');
|
366 |
}
|
367 |
});
|
369 |
}
|
370 |
$('input.save-repeater').each(function(){
|
371 |
$(this).click(function() {
|
372 |
+
var btn = $(this),
|
373 |
+
editorId = btn.data('editor-id');
|
374 |
btn.addClass('changed');
|
375 |
+
_alm_admin.saveRepeater(btn, editorId);
|
376 |
});
|
377 |
});
|
378 |
});
|
379 |
</script>
|
380 |
+
</div>
|
381 |
<!-- End Repeaters -->
|
382 |
</div>
|
383 |
+
<div class="alm-sidebar">
|
384 |
<div class="cta">
|
385 |
<h3><?php _e('Templating Help', ALM_NAME); ?></h3>
|
386 |
<div class="item">
|
399 |
</div>
|
400 |
</div>
|
401 |
<?php include( plugin_dir_path( __FILE__ ) . 'includes/cta/writeable.php'); ?>
|
402 |
+
</div>
|
403 |
</div>
|
404 |
</div>
|
405 |
|
465 |
<div class="admin ajax-load-more" id="alm-builder">
|
466 |
<div class="wrap">
|
467 |
<div class="header-wrap">
|
468 |
+
<h2><?php _e('Ajax Load More: Shortcode Builder', ALM_NAME); ?></h2>
|
469 |
<p><?php _e('Create your own Ajax Load More <a href="http://en.support.wordpress.com/shortcodes/" target="_blank">shortcode</a> by adjusting the values below', ALM_NAME); ?></p>
|
470 |
</div>
|
471 |
<div class="alm-main">
|
472 |
+
<div class="group">
|
473 |
+
<?php include( plugin_dir_path( __FILE__ ) . 'shortcode-builder/shortcode-builder.php'); ?>
|
474 |
+
<div class="row no-brd">
|
475 |
<p class="back2top"><a href="#wpcontent"><i class="fa fa-chevron-up"></i> <?php _e('Back to Top', ALM_NAME); ?></a></p>
|
476 |
</div>
|
477 |
+
</div>
|
478 |
</div>
|
479 |
+
<div class="alm-sidebar">
|
480 |
<div class="cta">
|
481 |
<h3><?php _e('Shortcode Output', ALM_NAME); ?></h3>
|
482 |
<p><?php _e('Copy and paste the following shortcode into the content editor or widget area of your theme.', ALM_NAME); ?></p>
|
488 |
<div class="cta">
|
489 |
<h3><?php _e('Did you know?', ALM_NAME); ?></h3>
|
490 |
<img src="<?php echo ALM_ADMIN_URL; ?>img/add-ons/shortcode-editor.jpg"><br/>
|
491 |
+
<?php _e('<p class="addon-intro">You can generate shortcodes while editing pages!</p><p>Click the Ajax Load More icon in the content editor toolbar and the <a href="?page=ajax-load-more-shortcode-builder">shortcode builder</a> will open in an overlay window.', ALM_NAME); ?></p>
|
492 |
</div>
|
493 |
+
</div>
|
494 |
</div>
|
495 |
</div>
|
496 |
<?php
|
545 |
<div class="admin ajax-load-more" id="alm-examples">
|
546 |
<div class="wrap">
|
547 |
<div class="header-wrap">
|
548 |
+
<h2><?php _e('Ajax Load More: Examples', ALM_NAME); ?></h2>
|
549 |
<p><?php _e('A collection of everyday shortcode usages and implementation examples', ALM_NAME); ?></p>
|
550 |
</div>
|
551 |
<div class="alm-main forceColors">
|
552 |
+
<div class="group">
|
553 |
<div class="row gist">
|
554 |
<h3 class="heading"><?php _e('Author.php', ALM_NAME); ?></h3>
|
555 |
<div class="expand-wrap">
|
588 |
<div class="row">
|
589 |
<p class="back2top"><a href="#wpcontent"><i class="fa fa-chevron-up"></i> <?php _e('Back to Top', ALM_NAME); ?></a></p>
|
590 |
</div>
|
591 |
+
</div>
|
592 |
</div>
|
593 |
+
<div class="alm-sidebar">
|
594 |
<div class="cta">
|
595 |
<h3><?php _e('Request Examples', ALM_NAME); ?></h3>
|
596 |
<p><?php _e('If you\'re having issue\'s with functionality, please submit example requests through the <a href="https://github.com/dcooney/wordpress-ajax-load-more" target="_blank">GitHub repository</a>. ', ALM_NAME); ?></p>
|
597 |
</div>
|
598 |
<?php include( plugin_dir_path( __FILE__ ) . 'includes/cta/about.php'); ?>
|
599 |
+
</div>
|
600 |
|
601 |
|
602 |
</div>
|
617 |
<div class="admin ajax-load-more" id="alm-add-ons">
|
618 |
<div class="wrap">
|
619 |
<div class="header-wrap">
|
620 |
+
<h2><?php _e('Ajax Load More: Add-ons', ALM_NAME); ?></h2>
|
621 |
<p><?php _e('The following Add-ons are available to increase the functionality of Ajax Load More.', ALM_NAME); ?></p>
|
622 |
</div>
|
623 |
+
<div class="alm-main">
|
624 |
<!-- Custom Repeater -->
|
625 |
+
<div class="group">
|
626 |
+
<div class="row no-brd">
|
627 |
<h3 class="add-on-title"><?php _e('Custom Repeaters', ALM_NAME); ?></h3>
|
628 |
<div class="expand-wrap">
|
629 |
<div class="section-title">
|
630 |
<img src="<?php echo ALM_ADMIN_URL; ?>img/add-ons/repeater-add-ons.jpg">
|
631 |
</div>
|
632 |
<div class="wrap">
|
633 |
+
<p class="addon-intro"><?php _e('Unlock additional repeater templates and keep your WordPress theme looking and feeling fresh.', ALM_NAME); ?></p>
|
634 |
+
<p><?php _e('The Custom Repeaters add-on will add <strong>five</strong> additional <a href="?page=ajax-load-more-repeaters">repeaters</a> and allow you to select unique repeaters for different content types throughout your theme.</p>', ALM_NAME); ?>
|
|
|
635 |
</div>
|
636 |
</div>
|
637 |
</div>
|
642 |
echo '<a class="btn" href="http://connekthq.com/plugins/ajax-load-more/custom-repeaters/" target="_blank"><i class="fa fa-download"></i> Purchase & Install</a>';
|
643 |
}
|
644 |
?>
|
645 |
+
</div>
|
646 |
<!-- End Custom Repeater -->
|
647 |
</div>
|
648 |
|
649 |
+
<div class="alm-sidebar">
|
650 |
+
<div class="cta">
|
651 |
+
<h3><?php _e('About Add-ons', ALM_NAME); ?></h3>
|
652 |
+
<p><?php _e('Add-ons are installed as a separate plugin and will receive plug-in update notifications. ', ALM_NAME); ?></p>
|
653 |
+
</div>
|
654 |
<div class="cta">
|
655 |
<h3><?php _e('About Add-ons', ALM_NAME); ?></h3>
|
656 |
<p><?php _e('Add-ons are installed as a separate plugin and will receive plug-in update notifications. ', ALM_NAME); ?></p>
|
657 |
</div>
|
658 |
<?php include( plugin_dir_path( __FILE__ ) . 'includes/cta/writeable.php'); ?>
|
659 |
+
</div>
|
660 |
|
661 |
</div>
|
662 |
</div>
|
684 |
'alm_general_settings_callback',
|
685 |
'ajax-load-more'
|
686 |
);
|
687 |
+
/*
|
688 |
+
add_settings_field(
|
|
|
|
|
|
|
|
|
|
|
|
|
689 |
'_alm_html5',
|
690 |
__('HTML5 Elements', ALM_NAME ),
|
691 |
'alm_html5_callback',
|
692 |
'ajax-load-more',
|
693 |
'alm_general_settings'
|
694 |
+
);
|
695 |
+
*/
|
696 |
add_settings_field(
|
697 |
'_alm_container_type',
|
698 |
__('Container Type', ALM_NAME ),
|
700 |
'ajax-load-more',
|
701 |
'alm_general_settings'
|
702 |
);
|
703 |
+
|
704 |
add_settings_field(
|
705 |
'_alm_classname',
|
706 |
+
__('Container Classes', ALM_NAME ),
|
707 |
'alm_class_callback',
|
708 |
'ajax-load-more',
|
709 |
'alm_general_settings'
|
710 |
);
|
711 |
+
|
712 |
+
add_settings_field(
|
713 |
+
'_alm_hide_btn',
|
714 |
+
__('Editor Shortcode Button', ALM_NAME ),
|
715 |
+
'alm_hide_btn_callback',
|
716 |
+
'ajax-load-more',
|
717 |
+
'alm_general_settings'
|
718 |
+
);
|
719 |
+
|
720 |
+
add_settings_field(
|
721 |
+
'_alm_disable_css',
|
722 |
+
__('Disable CSS', ALM_NAME ),
|
723 |
+
'alm_disable_css_callback',
|
724 |
+
'ajax-load-more',
|
725 |
+
'alm_general_settings'
|
726 |
+
);
|
727 |
+
|
728 |
add_settings_field(
|
729 |
'_alm_btn_color',
|
730 |
__('Button Color', ALM_NAME ),
|
731 |
'alm_btn_color_callback',
|
732 |
'ajax-load-more',
|
733 |
'alm_general_settings'
|
734 |
+
);
|
735 |
}
|
736 |
|
737 |
|
744 |
*/
|
745 |
|
746 |
function alm_general_settings_callback() {
|
747 |
+
echo '<p>' . __('Customize your version of Ajax Load More by updating the fields below.</p><p class="small">All changes will be applied globally throughout your theme.', ALM_NAME) . '</p>';
|
748 |
}
|
749 |
|
750 |
|
773 |
$options['_alm_disable_css'] = '0';
|
774 |
|
775 |
echo '<input type="hidden" name="alm_settings[_alm_disable_css]" value="0" />
|
776 |
+
<label><input type="checkbox" id="alm_disable_css_input" name="alm_settings[_alm_disable_css]" value="1"'. (($options['_alm_disable_css']) ? ' checked="checked"' : '') .' /> '.__('I want to use my own CSS styles', ALM_NAME).'</label>';
|
777 |
+
echo '<p class="desc"><i class="fa fa-file-text-o"></i> <a href="'.ALM_URL.'/core/css/ajax-load-more.css" target="blank">'.__('View Ajax Load More CSS', ALM_NAME).'</a></p>';
|
778 |
+
?>
|
779 |
+
<?php
|
780 |
}
|
781 |
|
782 |
|
783 |
/*
|
784 |
+
* alm_hide_btn_callback
|
785 |
+
* Disbale the ALM shortcode button in the WordPress content editor
|
786 |
*
|
787 |
+
* @since 2.2.1
|
788 |
*/
|
789 |
|
790 |
+
function alm_hide_btn_callback(){
|
791 |
$options = get_option( 'alm_settings' );
|
792 |
+
if(!isset($options['_alm_hide_btn']))
|
793 |
+
$options['_alm_hide_btn'] = '0';
|
794 |
|
795 |
+
echo '<input type="hidden" name="alm_settings[_alm_hide_btn]" value="0" />
|
796 |
+
<label><input type="checkbox" name="alm_settings[_alm_hide_btn]" value="1"'. (($options['_alm_hide_btn']) ? ' checked="checked"' : '') .' /> '.__('Hide shortcode button in WYSIWYG editor', ALM_NAME).'<p class="desc"></p></label>';
|
797 |
}
|
798 |
|
799 |
|
800 |
/*
|
801 |
* alm_class_callback
|
802 |
+
* Add classes to the Ajax Load More wrapper
|
803 |
*
|
804 |
* @since 2.0.0
|
805 |
*/
|
807 |
function alm_class_callback(){
|
808 |
$options = get_option( 'alm_settings' );
|
809 |
|
810 |
+
echo '<label for="alm_settings[_alm_classname]">'.__('Add classes to Ajax Load More container', ALM_NAME).'</label><br/><input type="text" id="alm_settings[_alm_classname]" name="alm_settings[_alm_classname]" value="'.$options['_alm_classname'].'" placeholder="posts listing etc..." /> ';
|
811 |
}
|
812 |
|
813 |
|
826 |
$options['_alm_container_type'] = '1';
|
827 |
|
828 |
$html = '<input type="radio" id="_alm_container_type_one" name="alm_settings[_alm_container_type]" value="1"' . checked( 1, $options['_alm_container_type'], false ) . '/>';
|
829 |
+
$html .= '<label for="_alm_container_type_one"><ul> <span><!-- '.__('Ajax Posts Here', ALM_NAME).' --></span> </ul></label><br/>';
|
830 |
|
831 |
$html .= '<input type="radio" id="_alm_container_type_two" name="alm_settings[_alm_container_type]" value="2"' . checked( 2, $options['_alm_container_type'], false ) . '/>';
|
832 |
+
$html .= '<label for="_alm_container_type_two"><div> <span><!-- '.__('Ajax Posts Here', ALM_NAME).' --></span> </div></label>';
|
833 |
|
834 |
echo $html;
|
835 |
|
876 |
if($color == 'grey')
|
877 |
$selected5 = 'selected="selected"';
|
878 |
|
879 |
+
$selected6 = '';
|
880 |
+
if($color == 'white')
|
881 |
+
$selected5 = 'selected="selected"';
|
882 |
+
|
883 |
+
$html = '<label for="alm_settings_btn_color">'.__('Choose your load more button color', ALM_NAME).'</label><br/>';
|
884 |
+
$html .= '<select id="alm_settings_btn_color" name="alm_settings[_alm_btn_color]">';
|
885 |
$html .= '<option value="default" ' . $selected0 .'>Default (Orange)</option>';
|
886 |
$html .= '<option value="blue" ' . $selected1 .'>Blue</option>';
|
887 |
$html .= '<option value="green" ' . $selected2 .'>Green</option>';
|
888 |
$html .= '<option value="red" ' . $selected3 .'>Red</option>';
|
889 |
$html .= '<option value="purple" ' . $selected4 .'>Purple</option>';
|
890 |
$html .= '<option value="grey" ' . $selected5 .'>Grey</option>';
|
891 |
+
$html .= '<option value="white" ' . $selected6 .'>White</option>';
|
892 |
$html .= '</select>';
|
893 |
|
894 |
+
$html .= '<div class="ajax-load-more-wrap '.$color.'"><span>'.__('Preview', ALM_NAME) .'</span><button class="alm-load-more-btn loading" disabled="disabled">Show More</button></div>';
|
895 |
echo $html;
|
896 |
+
?>
|
897 |
+
<script>
|
898 |
+
//Button preview
|
899 |
+
var colorArray = "default grey purple green red blue white";
|
900 |
+
jQuery("select#alm_settings_btn_color").change(function() {
|
901 |
+
var color = jQuery(this).val();
|
902 |
+
jQuery('.ajax-load-more-wrap').removeClass(colorArray);
|
903 |
+
jQuery('.ajax-load-more-wrap').addClass(color);
|
904 |
+
});
|
905 |
+
jQuery("select#alm_settings_btn_color").click(function(e){
|
906 |
+
e.preventDefault();
|
907 |
+
});
|
908 |
+
|
909 |
+
// Check if Disable CSS === true
|
910 |
+
if(jQuery('input#alm_disable_css_input').is(":checked")){
|
911 |
+
//alert("true");
|
912 |
+
jQuery('input#alm_disable_css_input').parent().parent().parent('tr').next('tr').hide();
|
913 |
+
}
|
914 |
+
jQuery('input#alm_disable_css_input').change(function() {
|
915 |
+
var el = jQuery(this);
|
916 |
+
if(el.is(":checked")) {
|
917 |
+
el.parent().parent().parent('tr').next('tr').hide();
|
918 |
+
}else{
|
919 |
+
el.parent().parent().parent('tr').next('tr').show();
|
920 |
+
}
|
921 |
+
});
|
922 |
+
|
923 |
+
</script>
|
924 |
+
<?php
|
925 |
}
|
926 |
|
927 |
|
admin/codemirror/addon/edit/closebrackets.js
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function(mod) {
|
5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6 |
+
mod(require("../../lib/codemirror"));
|
7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
8 |
+
define(["../../lib/codemirror"], mod);
|
9 |
+
else // Plain browser env
|
10 |
+
mod(CodeMirror);
|
11 |
+
})(function(CodeMirror) {
|
12 |
+
var DEFAULT_BRACKETS = "()[]{}''\"\"";
|
13 |
+
var DEFAULT_EXPLODE_ON_ENTER = "[]{}";
|
14 |
+
var SPACE_CHAR_REGEX = /\s/;
|
15 |
+
|
16 |
+
var Pos = CodeMirror.Pos;
|
17 |
+
|
18 |
+
CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
|
19 |
+
if (old != CodeMirror.Init && old)
|
20 |
+
cm.removeKeyMap("autoCloseBrackets");
|
21 |
+
if (!val) return;
|
22 |
+
var pairs = DEFAULT_BRACKETS, explode = DEFAULT_EXPLODE_ON_ENTER;
|
23 |
+
if (typeof val == "string") pairs = val;
|
24 |
+
else if (typeof val == "object") {
|
25 |
+
if (val.pairs != null) pairs = val.pairs;
|
26 |
+
if (val.explode != null) explode = val.explode;
|
27 |
+
}
|
28 |
+
var map = buildKeymap(pairs);
|
29 |
+
if (explode) map.Enter = buildExplodeHandler(explode);
|
30 |
+
cm.addKeyMap(map);
|
31 |
+
});
|
32 |
+
|
33 |
+
function charsAround(cm, pos) {
|
34 |
+
var str = cm.getRange(Pos(pos.line, pos.ch - 1),
|
35 |
+
Pos(pos.line, pos.ch + 1));
|
36 |
+
return str.length == 2 ? str : null;
|
37 |
+
}
|
38 |
+
|
39 |
+
// Project the token type that will exists after the given char is
|
40 |
+
// typed, and use it to determine whether it would cause the start
|
41 |
+
// of a string token.
|
42 |
+
function enteringString(cm, pos, ch) {
|
43 |
+
var line = cm.getLine(pos.line);
|
44 |
+
var token = cm.getTokenAt(pos);
|
45 |
+
if (/\bstring2?\b/.test(token.type)) return false;
|
46 |
+
var stream = new CodeMirror.StringStream(line.slice(0, pos.ch) + ch + line.slice(pos.ch), 4);
|
47 |
+
stream.pos = stream.start = token.start;
|
48 |
+
for (;;) {
|
49 |
+
var type1 = cm.getMode().token(stream, token.state);
|
50 |
+
if (stream.pos >= pos.ch + 1) return /\bstring2?\b/.test(type1);
|
51 |
+
stream.start = stream.pos;
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
function buildKeymap(pairs) {
|
56 |
+
var map = {
|
57 |
+
name : "autoCloseBrackets",
|
58 |
+
Backspace: function(cm) {
|
59 |
+
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
60 |
+
var ranges = cm.listSelections();
|
61 |
+
for (var i = 0; i < ranges.length; i++) {
|
62 |
+
if (!ranges[i].empty()) return CodeMirror.Pass;
|
63 |
+
var around = charsAround(cm, ranges[i].head);
|
64 |
+
if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
|
65 |
+
}
|
66 |
+
for (var i = ranges.length - 1; i >= 0; i--) {
|
67 |
+
var cur = ranges[i].head;
|
68 |
+
cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1));
|
69 |
+
}
|
70 |
+
}
|
71 |
+
};
|
72 |
+
var closingBrackets = "";
|
73 |
+
for (var i = 0; i < pairs.length; i += 2) (function(left, right) {
|
74 |
+
if (left != right) closingBrackets += right;
|
75 |
+
map["'" + left + "'"] = function(cm) {
|
76 |
+
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
77 |
+
var ranges = cm.listSelections(), type, next;
|
78 |
+
for (var i = 0; i < ranges.length; i++) {
|
79 |
+
var range = ranges[i], cur = range.head, curType;
|
80 |
+
var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
|
81 |
+
if (!range.empty())
|
82 |
+
curType = "surround";
|
83 |
+
else if (left == right && next == right) {
|
84 |
+
if (cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == left + left + left)
|
85 |
+
curType = "skipThree";
|
86 |
+
else
|
87 |
+
curType = "skip";
|
88 |
+
} else if (left == right && cur.ch > 1 &&
|
89 |
+
cm.getRange(Pos(cur.line, cur.ch - 2), cur) == left + left &&
|
90 |
+
(cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != left))
|
91 |
+
curType = "addFour";
|
92 |
+
else if (left == '"' || left == "'") {
|
93 |
+
if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, left)) curType = "both";
|
94 |
+
else return CodeMirror.Pass;
|
95 |
+
} else if (cm.getLine(cur.line).length == cur.ch || closingBrackets.indexOf(next) >= 0 || SPACE_CHAR_REGEX.test(next))
|
96 |
+
curType = "both";
|
97 |
+
else
|
98 |
+
return CodeMirror.Pass;
|
99 |
+
if (!type) type = curType;
|
100 |
+
else if (type != curType) return CodeMirror.Pass;
|
101 |
+
}
|
102 |
+
|
103 |
+
cm.operation(function() {
|
104 |
+
if (type == "skip") {
|
105 |
+
cm.execCommand("goCharRight");
|
106 |
+
} else if (type == "skipThree") {
|
107 |
+
for (var i = 0; i < 3; i++)
|
108 |
+
cm.execCommand("goCharRight");
|
109 |
+
} else if (type == "surround") {
|
110 |
+
var sels = cm.getSelections();
|
111 |
+
for (var i = 0; i < sels.length; i++)
|
112 |
+
sels[i] = left + sels[i] + right;
|
113 |
+
cm.replaceSelections(sels, "around");
|
114 |
+
} else if (type == "both") {
|
115 |
+
cm.replaceSelection(left + right, null);
|
116 |
+
cm.execCommand("goCharLeft");
|
117 |
+
} else if (type == "addFour") {
|
118 |
+
cm.replaceSelection(left + left + left + left, "before");
|
119 |
+
cm.execCommand("goCharRight");
|
120 |
+
}
|
121 |
+
});
|
122 |
+
};
|
123 |
+
if (left != right) map["'" + right + "'"] = function(cm) {
|
124 |
+
var ranges = cm.listSelections();
|
125 |
+
for (var i = 0; i < ranges.length; i++) {
|
126 |
+
var range = ranges[i];
|
127 |
+
if (!range.empty() ||
|
128 |
+
cm.getRange(range.head, Pos(range.head.line, range.head.ch + 1)) != right)
|
129 |
+
return CodeMirror.Pass;
|
130 |
+
}
|
131 |
+
cm.execCommand("goCharRight");
|
132 |
+
};
|
133 |
+
})(pairs.charAt(i), pairs.charAt(i + 1));
|
134 |
+
return map;
|
135 |
+
}
|
136 |
+
|
137 |
+
function buildExplodeHandler(pairs) {
|
138 |
+
return function(cm) {
|
139 |
+
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
140 |
+
var ranges = cm.listSelections();
|
141 |
+
for (var i = 0; i < ranges.length; i++) {
|
142 |
+
if (!ranges[i].empty()) return CodeMirror.Pass;
|
143 |
+
var around = charsAround(cm, ranges[i].head);
|
144 |
+
if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
|
145 |
+
}
|
146 |
+
cm.operation(function() {
|
147 |
+
cm.replaceSelection("\n\n", null);
|
148 |
+
cm.execCommand("goCharLeft");
|
149 |
+
ranges = cm.listSelections();
|
150 |
+
for (var i = 0; i < ranges.length; i++) {
|
151 |
+
var line = ranges[i].head.line;
|
152 |
+
cm.indentLine(line, null, true);
|
153 |
+
cm.indentLine(line + 1, null, true);
|
154 |
+
}
|
155 |
+
});
|
156 |
+
};
|
157 |
+
}
|
158 |
+
});
|
admin/codemirror/addon/edit/closetag.js
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Tag-closer extension for CodeMirror.
|
6 |
+
*
|
7 |
+
* This extension adds an "autoCloseTags" option that can be set to
|
8 |
+
* either true to get the default behavior, or an object to further
|
9 |
+
* configure its behavior.
|
10 |
+
*
|
11 |
+
* These are supported options:
|
12 |
+
*
|
13 |
+
* `whenClosing` (default true)
|
14 |
+
* Whether to autoclose when the '/' of a closing tag is typed.
|
15 |
+
* `whenOpening` (default true)
|
16 |
+
* Whether to autoclose the tag when the final '>' of an opening
|
17 |
+
* tag is typed.
|
18 |
+
* `dontCloseTags` (default is empty tags for HTML, none for XML)
|
19 |
+
* An array of tag names that should not be autoclosed.
|
20 |
+
* `indentTags` (default is block tags for HTML, none for XML)
|
21 |
+
* An array of tag names that should, when opened, cause a
|
22 |
+
* blank line to be added inside the tag, and the blank line and
|
23 |
+
* closing line to be indented.
|
24 |
+
*
|
25 |
+
* See demos/closetag.html for a usage example.
|
26 |
+
*/
|
27 |
+
|
28 |
+
(function(mod) {
|
29 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
30 |
+
mod(require("../../lib/codemirror"), require("../fold/xml-fold"));
|
31 |
+
else if (typeof define == "function" && define.amd) // AMD
|
32 |
+
define(["../../lib/codemirror", "../fold/xml-fold"], mod);
|
33 |
+
else // Plain browser env
|
34 |
+
mod(CodeMirror);
|
35 |
+
})(function(CodeMirror) {
|
36 |
+
CodeMirror.defineOption("autoCloseTags", false, function(cm, val, old) {
|
37 |
+
if (old != CodeMirror.Init && old)
|
38 |
+
cm.removeKeyMap("autoCloseTags");
|
39 |
+
if (!val) return;
|
40 |
+
var map = {name: "autoCloseTags"};
|
41 |
+
if (typeof val != "object" || val.whenClosing)
|
42 |
+
map["'/'"] = function(cm) { return autoCloseSlash(cm); };
|
43 |
+
if (typeof val != "object" || val.whenOpening)
|
44 |
+
map["'>'"] = function(cm) { return autoCloseGT(cm); };
|
45 |
+
cm.addKeyMap(map);
|
46 |
+
});
|
47 |
+
|
48 |
+
var htmlDontClose = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param",
|
49 |
+
"source", "track", "wbr"];
|
50 |
+
var htmlIndent = ["applet", "blockquote", "body", "button", "div", "dl", "fieldset", "form", "frameset", "h1", "h2", "h3", "h4",
|
51 |
+
"h5", "h6", "head", "html", "iframe", "layer", "legend", "object", "ol", "p", "select", "table", "ul"];
|
52 |
+
|
53 |
+
function autoCloseGT(cm) {
|
54 |
+
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
55 |
+
var ranges = cm.listSelections(), replacements = [];
|
56 |
+
for (var i = 0; i < ranges.length; i++) {
|
57 |
+
if (!ranges[i].empty()) return CodeMirror.Pass;
|
58 |
+
var pos = ranges[i].head, tok = cm.getTokenAt(pos);
|
59 |
+
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
|
60 |
+
if (inner.mode.name != "xml" || !state.tagName) return CodeMirror.Pass;
|
61 |
+
|
62 |
+
var opt = cm.getOption("autoCloseTags"), html = inner.mode.configuration == "html";
|
63 |
+
var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose);
|
64 |
+
var indentTags = (typeof opt == "object" && opt.indentTags) || (html && htmlIndent);
|
65 |
+
|
66 |
+
var tagName = state.tagName;
|
67 |
+
if (tok.end > pos.ch) tagName = tagName.slice(0, tagName.length - tok.end + pos.ch);
|
68 |
+
var lowerTagName = tagName.toLowerCase();
|
69 |
+
// Don't process the '>' at the end of an end-tag or self-closing tag
|
70 |
+
if (!tagName ||
|
71 |
+
tok.type == "string" && (tok.end != pos.ch || !/[\"\']/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1) ||
|
72 |
+
tok.type == "tag" && state.type == "closeTag" ||
|
73 |
+
tok.string.indexOf("/") == (tok.string.length - 1) || // match something like <someTagName />
|
74 |
+
dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1 ||
|
75 |
+
closingTagExists(cm, tagName, pos, state, true))
|
76 |
+
return CodeMirror.Pass;
|
77 |
+
|
78 |
+
var indent = indentTags && indexOf(indentTags, lowerTagName) > -1;
|
79 |
+
replacements[i] = {indent: indent,
|
80 |
+
text: ">" + (indent ? "\n\n" : "") + "</" + tagName + ">",
|
81 |
+
newPos: indent ? CodeMirror.Pos(pos.line + 1, 0) : CodeMirror.Pos(pos.line, pos.ch + 1)};
|
82 |
+
}
|
83 |
+
|
84 |
+
for (var i = ranges.length - 1; i >= 0; i--) {
|
85 |
+
var info = replacements[i];
|
86 |
+
cm.replaceRange(info.text, ranges[i].head, ranges[i].anchor, "+insert");
|
87 |
+
var sel = cm.listSelections().slice(0);
|
88 |
+
sel[i] = {head: info.newPos, anchor: info.newPos};
|
89 |
+
cm.setSelections(sel);
|
90 |
+
if (info.indent) {
|
91 |
+
cm.indentLine(info.newPos.line, null, true);
|
92 |
+
cm.indentLine(info.newPos.line + 1, null, true);
|
93 |
+
}
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
function autoCloseSlash(cm) {
|
98 |
+
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
99 |
+
var ranges = cm.listSelections(), replacements = [];
|
100 |
+
for (var i = 0; i < ranges.length; i++) {
|
101 |
+
if (!ranges[i].empty()) return CodeMirror.Pass;
|
102 |
+
var pos = ranges[i].head, tok = cm.getTokenAt(pos);
|
103 |
+
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
|
104 |
+
if (tok.type == "string" || tok.string.charAt(0) != "<" ||
|
105 |
+
tok.start != pos.ch - 1 || inner.mode.name != "xml" ||
|
106 |
+
!state.context || !state.context.tagName ||
|
107 |
+
closingTagExists(cm, state.context.tagName, pos, state))
|
108 |
+
return CodeMirror.Pass;
|
109 |
+
replacements[i] = "/" + state.context.tagName + ">";
|
110 |
+
}
|
111 |
+
cm.replaceSelections(replacements);
|
112 |
+
}
|
113 |
+
|
114 |
+
function indexOf(collection, elt) {
|
115 |
+
if (collection.indexOf) return collection.indexOf(elt);
|
116 |
+
for (var i = 0, e = collection.length; i < e; ++i)
|
117 |
+
if (collection[i] == elt) return i;
|
118 |
+
return -1;
|
119 |
+
}
|
120 |
+
|
121 |
+
// If xml-fold is loaded, we use its functionality to try and verify
|
122 |
+
// whether a given tag is actually unclosed.
|
123 |
+
function closingTagExists(cm, tagName, pos, state, newTag) {
|
124 |
+
if (!CodeMirror.scanForClosingTag) return false;
|
125 |
+
var end = Math.min(cm.lastLine() + 1, pos.line + 500);
|
126 |
+
var nextClose = CodeMirror.scanForClosingTag(cm, pos, null, end);
|
127 |
+
if (!nextClose || nextClose.tag != tagName) return false;
|
128 |
+
var cx = state.context;
|
129 |
+
// If the immediate wrapping context contains onCx instances of
|
130 |
+
// the same tag, a closing tag only exists if there are at least
|
131 |
+
// that many closing tags of that type following.
|
132 |
+
for (var onCx = newTag ? 1 : 0; cx && cx.tagName == tagName; cx = cx.prev) ++onCx;
|
133 |
+
pos = nextClose.to;
|
134 |
+
for (var i = 1; i < onCx; i++) {
|
135 |
+
var next = CodeMirror.scanForClosingTag(cm, pos, null, end);
|
136 |
+
if (!next || next.tag != tagName) return false;
|
137 |
+
pos = next.to;
|
138 |
+
}
|
139 |
+
return true;
|
140 |
+
}
|
141 |
+
});
|
admin/codemirror/addon/edit/continuelist.js
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function(mod) {
|
5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6 |
+
mod(require("../../lib/codemirror"));
|
7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
8 |
+
define(["../../lib/codemirror"], mod);
|
9 |
+
else // Plain browser env
|
10 |
+
mod(CodeMirror);
|
11 |
+
})(function(CodeMirror) {
|
12 |
+
"use strict";
|
13 |
+
|
14 |
+
var listRE = /^(\s*)([*+-]|(\d+)\.)(\s+)/,
|
15 |
+
unorderedBullets = "*+-";
|
16 |
+
|
17 |
+
CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
|
18 |
+
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
19 |
+
var ranges = cm.listSelections(), replacements = [];
|
20 |
+
for (var i = 0; i < ranges.length; i++) {
|
21 |
+
var pos = ranges[i].head, match;
|
22 |
+
var inList = cm.getStateAfter(pos.line).list !== false;
|
23 |
+
|
24 |
+
if (!ranges[i].empty() || !inList || !(match = cm.getLine(pos.line).match(listRE))) {
|
25 |
+
cm.execCommand("newlineAndIndent");
|
26 |
+
return;
|
27 |
+
}
|
28 |
+
var indent = match[1], after = match[4];
|
29 |
+
var bullet = unorderedBullets.indexOf(match[2]) >= 0
|
30 |
+
? match[2]
|
31 |
+
: (parseInt(match[3], 10) + 1) + ".";
|
32 |
+
|
33 |
+
replacements[i] = "\n" + indent + bullet + after;
|
34 |
+
}
|
35 |
+
|
36 |
+
cm.replaceSelections(replacements);
|
37 |
+
};
|
38 |
+
});
|
admin/codemirror/addon/edit/matchbrackets.js
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function(mod) {
|
5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6 |
+
mod(require("../../lib/codemirror"));
|
7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
8 |
+
define(["../../lib/codemirror"], mod);
|
9 |
+
else // Plain browser env
|
10 |
+
mod(CodeMirror);
|
11 |
+
})(function(CodeMirror) {
|
12 |
+
var ie_lt8 = /MSIE \d/.test(navigator.userAgent) &&
|
13 |
+
(document.documentMode == null || document.documentMode < 8);
|
14 |
+
|
15 |
+
var Pos = CodeMirror.Pos;
|
16 |
+
|
17 |
+
var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
|
18 |
+
|
19 |
+
function findMatchingBracket(cm, where, strict, config) {
|
20 |
+
var line = cm.getLineHandle(where.line), pos = where.ch - 1;
|
21 |
+
var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
|
22 |
+
if (!match) return null;
|
23 |
+
var dir = match.charAt(1) == ">" ? 1 : -1;
|
24 |
+
if (strict && (dir > 0) != (pos == where.ch)) return null;
|
25 |
+
var style = cm.getTokenTypeAt(Pos(where.line, pos + 1));
|
26 |
+
|
27 |
+
var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style || null, config);
|
28 |
+
if (found == null) return null;
|
29 |
+
return {from: Pos(where.line, pos), to: found && found.pos,
|
30 |
+
match: found && found.ch == match.charAt(0), forward: dir > 0};
|
31 |
+
}
|
32 |
+
|
33 |
+
// bracketRegex is used to specify which type of bracket to scan
|
34 |
+
// should be a regexp, e.g. /[[\]]/
|
35 |
+
//
|
36 |
+
// Note: If "where" is on an open bracket, then this bracket is ignored.
|
37 |
+
//
|
38 |
+
// Returns false when no bracket was found, null when it reached
|
39 |
+
// maxScanLines and gave up
|
40 |
+
function scanForBracket(cm, where, dir, style, config) {
|
41 |
+
var maxScanLen = (config && config.maxScanLineLength) || 10000;
|
42 |
+
var maxScanLines = (config && config.maxScanLines) || 1000;
|
43 |
+
|
44 |
+
var stack = [];
|
45 |
+
var re = config && config.bracketRegex ? config.bracketRegex : /[(){}[\]]/;
|
46 |
+
var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1)
|
47 |
+
: Math.max(cm.firstLine() - 1, where.line - maxScanLines);
|
48 |
+
for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) {
|
49 |
+
var line = cm.getLine(lineNo);
|
50 |
+
if (!line) continue;
|
51 |
+
var pos = dir > 0 ? 0 : line.length - 1, end = dir > 0 ? line.length : -1;
|
52 |
+
if (line.length > maxScanLen) continue;
|
53 |
+
if (lineNo == where.line) pos = where.ch - (dir < 0 ? 1 : 0);
|
54 |
+
for (; pos != end; pos += dir) {
|
55 |
+
var ch = line.charAt(pos);
|
56 |
+
if (re.test(ch) && (style === undefined || cm.getTokenTypeAt(Pos(lineNo, pos + 1)) == style)) {
|
57 |
+
var match = matching[ch];
|
58 |
+
if ((match.charAt(1) == ">") == (dir > 0)) stack.push(ch);
|
59 |
+
else if (!stack.length) return {pos: Pos(lineNo, pos), ch: ch};
|
60 |
+
else stack.pop();
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|
64 |
+
return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null;
|
65 |
+
}
|
66 |
+
|
67 |
+
function matchBrackets(cm, autoclear, config) {
|
68 |
+
// Disable brace matching in long lines, since it'll cause hugely slow updates
|
69 |
+
var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000;
|
70 |
+
var marks = [], ranges = cm.listSelections();
|
71 |
+
for (var i = 0; i < ranges.length; i++) {
|
72 |
+
var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, false, config);
|
73 |
+
if (match && cm.getLine(match.from.line).length <= maxHighlightLen) {
|
74 |
+
var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
|
75 |
+
marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style}));
|
76 |
+
if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen)
|
77 |
+
marks.push(cm.markText(match.to, Pos(match.to.line, match.to.ch + 1), {className: style}));
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
if (marks.length) {
|
82 |
+
// Kludge to work around the IE bug from issue #1193, where text
|
83 |
+
// input stops going to the textare whever this fires.
|
84 |
+
if (ie_lt8 && cm.state.focused) cm.display.input.focus();
|
85 |
+
|
86 |
+
var clear = function() {
|
87 |
+
cm.operation(function() {
|
88 |
+
for (var i = 0; i < marks.length; i++) marks[i].clear();
|
89 |
+
});
|
90 |
+
};
|
91 |
+
if (autoclear) setTimeout(clear, 800);
|
92 |
+
else return clear;
|
93 |
+
}
|
94 |
+
}
|
95 |
+
|
96 |
+
var currentlyHighlighted = null;
|
97 |
+
function doMatchBrackets(cm) {
|
98 |
+
cm.operation(function() {
|
99 |
+
if (currentlyHighlighted) {currentlyHighlighted(); currentlyHighlighted = null;}
|
100 |
+
currentlyHighlighted = matchBrackets(cm, false, cm.state.matchBrackets);
|
101 |
+
});
|
102 |
+
}
|
103 |
+
|
104 |
+
CodeMirror.defineOption("matchBrackets", false, function(cm, val, old) {
|
105 |
+
if (old && old != CodeMirror.Init)
|
106 |
+
cm.off("cursorActivity", doMatchBrackets);
|
107 |
+
if (val) {
|
108 |
+
cm.state.matchBrackets = typeof val == "object" ? val : {};
|
109 |
+
cm.on("cursorActivity", doMatchBrackets);
|
110 |
+
}
|
111 |
+
});
|
112 |
+
|
113 |
+
CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
|
114 |
+
CodeMirror.defineExtension("findMatchingBracket", function(pos, strict, config){
|
115 |
+
return findMatchingBracket(this, pos, strict, config);
|
116 |
+
});
|
117 |
+
CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){
|
118 |
+
return scanForBracket(this, pos, dir, style, config);
|
119 |
+
});
|
120 |
+
});
|
admin/codemirror/addon/edit/matchtags.js
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function(mod) {
|
5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6 |
+
mod(require("../../lib/codemirror"), require("../fold/xml-fold"));
|
7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
8 |
+
define(["../../lib/codemirror", "../fold/xml-fold"], mod);
|
9 |
+
else // Plain browser env
|
10 |
+
mod(CodeMirror);
|
11 |
+
})(function(CodeMirror) {
|
12 |
+
"use strict";
|
13 |
+
|
14 |
+
CodeMirror.defineOption("matchTags", false, function(cm, val, old) {
|
15 |
+
if (old && old != CodeMirror.Init) {
|
16 |
+
cm.off("cursorActivity", doMatchTags);
|
17 |
+
cm.off("viewportChange", maybeUpdateMatch);
|
18 |
+
clear(cm);
|
19 |
+
}
|
20 |
+
if (val) {
|
21 |
+
cm.state.matchBothTags = typeof val == "object" && val.bothTags;
|
22 |
+
cm.on("cursorActivity", doMatchTags);
|
23 |
+
cm.on("viewportChange", maybeUpdateMatch);
|
24 |
+
doMatchTags(cm);
|
25 |
+
}
|
26 |
+
});
|
27 |
+
|
28 |
+
function clear(cm) {
|
29 |
+
if (cm.state.tagHit) cm.state.tagHit.clear();
|
30 |
+
if (cm.state.tagOther) cm.state.tagOther.clear();
|
31 |
+
cm.state.tagHit = cm.state.tagOther = null;
|
32 |
+
}
|
33 |
+
|
34 |
+
function doMatchTags(cm) {
|
35 |
+
cm.state.failedTagMatch = false;
|
36 |
+
cm.operation(function() {
|
37 |
+
clear(cm);
|
38 |
+
if (cm.somethingSelected()) return;
|
39 |
+
var cur = cm.getCursor(), range = cm.getViewport();
|
40 |
+
range.from = Math.min(range.from, cur.line); range.to = Math.max(cur.line + 1, range.to);
|
41 |
+
var match = CodeMirror.findMatchingTag(cm, cur, range);
|
42 |
+
if (!match) return;
|
43 |
+
if (cm.state.matchBothTags) {
|
44 |
+
var hit = match.at == "open" ? match.open : match.close;
|
45 |
+
if (hit) cm.state.tagHit = cm.markText(hit.from, hit.to, {className: "CodeMirror-matchingtag"});
|
46 |
+
}
|
47 |
+
var other = match.at == "close" ? match.open : match.close;
|
48 |
+
if (other)
|
49 |
+
cm.state.tagOther = cm.markText(other.from, other.to, {className: "CodeMirror-matchingtag"});
|
50 |
+
else
|
51 |
+
cm.state.failedTagMatch = true;
|
52 |
+
});
|
53 |
+
}
|
54 |
+
|
55 |
+
function maybeUpdateMatch(cm) {
|
56 |
+
if (cm.state.failedTagMatch) doMatchTags(cm);
|
57 |
+
}
|
58 |
+
|
59 |
+
CodeMirror.commands.toMatchingTag = function(cm) {
|
60 |
+
var found = CodeMirror.findMatchingTag(cm, cm.getCursor());
|
61 |
+
if (found) {
|
62 |
+
var other = found.at == "close" ? found.open : found.close;
|
63 |
+
if (other) cm.extendSelection(other.to, other.from);
|
64 |
+
}
|
65 |
+
};
|
66 |
+
});
|
admin/codemirror/addon/edit/trailingspace.js
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function(mod) {
|
5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6 |
+
mod(require("../../lib/codemirror"));
|
7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
8 |
+
define(["../../lib/codemirror"], mod);
|
9 |
+
else // Plain browser env
|
10 |
+
mod(CodeMirror);
|
11 |
+
})(function(CodeMirror) {
|
12 |
+
CodeMirror.defineOption("showTrailingSpace", false, function(cm, val, prev) {
|
13 |
+
if (prev == CodeMirror.Init) prev = false;
|
14 |
+
if (prev && !val)
|
15 |
+
cm.removeOverlay("trailingspace");
|
16 |
+
else if (!prev && val)
|
17 |
+
cm.addOverlay({
|
18 |
+
token: function(stream) {
|
19 |
+
for (var l = stream.string.length, i = l; i && /\s/.test(stream.string.charAt(i - 1)); --i) {}
|
20 |
+
if (i > stream.pos) { stream.pos = i; return null; }
|
21 |
+
stream.pos = l;
|
22 |
+
return "trailingspace";
|
23 |
+
},
|
24 |
+
name: "trailingspace"
|
25 |
+
});
|
26 |
+
});
|
27 |
+
});
|
admin/codemirror/lib/codemirror.css
ADDED
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* BASICS */
|
2 |
+
|
3 |
+
.CodeMirror {
|
4 |
+
/* Set height, width, borders, and global font properties here */
|
5 |
+
font-family: monospace;
|
6 |
+
height: 300px;
|
7 |
+
}
|
8 |
+
.CodeMirror-scroll {
|
9 |
+
/* Set scrolling behaviour here */
|
10 |
+
overflow: auto;
|
11 |
+
}
|
12 |
+
|
13 |
+
/* PADDING */
|
14 |
+
|
15 |
+
.CodeMirror-lines {
|
16 |
+
padding: 4px 0; /* Vertical padding around content */
|
17 |
+
}
|
18 |
+
.CodeMirror pre {
|
19 |
+
padding: 0 4px; /* Horizontal padding of content */
|
20 |
+
}
|
21 |
+
|
22 |
+
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
23 |
+
background-color: white; /* The little square between H and V scrollbars */
|
24 |
+
}
|
25 |
+
|
26 |
+
/* GUTTER */
|
27 |
+
|
28 |
+
.CodeMirror-gutters {
|
29 |
+
border-right: 1px solid #ddd;
|
30 |
+
background-color: #f7f7f7;
|
31 |
+
white-space: nowrap;
|
32 |
+
}
|
33 |
+
.CodeMirror-linenumbers {}
|
34 |
+
.CodeMirror-linenumber {
|
35 |
+
padding: 0 3px 0 5px;
|
36 |
+
min-width: 20px;
|
37 |
+
text-align: right;
|
38 |
+
color: #999;
|
39 |
+
-moz-box-sizing: content-box;
|
40 |
+
box-sizing: content-box;
|
41 |
+
}
|
42 |
+
|
43 |
+
.CodeMirror-guttermarker { color: black; }
|
44 |
+
.CodeMirror-guttermarker-subtle { color: #999; }
|
45 |
+
|
46 |
+
/* CURSOR */
|
47 |
+
|
48 |
+
.CodeMirror div.CodeMirror-cursor {
|
49 |
+
border-left: 1px solid black;
|
50 |
+
}
|
51 |
+
/* Shown when moving in bi-directional text */
|
52 |
+
.CodeMirror div.CodeMirror-secondarycursor {
|
53 |
+
border-left: 1px solid silver;
|
54 |
+
}
|
55 |
+
.CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursor {
|
56 |
+
width: auto;
|
57 |
+
border: 0;
|
58 |
+
background: #7e7;
|
59 |
+
}
|
60 |
+
.cm-animate-fat-cursor {
|
61 |
+
width: auto;
|
62 |
+
border: 0;
|
63 |
+
-webkit-animation: blink 1.06s steps(1) infinite;
|
64 |
+
-moz-animation: blink 1.06s steps(1) infinite;
|
65 |
+
animation: blink 1.06s steps(1) infinite;
|
66 |
+
}
|
67 |
+
@-moz-keyframes blink {
|
68 |
+
0% { background: #7e7; }
|
69 |
+
50% { background: none; }
|
70 |
+
100% { background: #7e7; }
|
71 |
+
}
|
72 |
+
@-webkit-keyframes blink {
|
73 |
+
0% { background: #7e7; }
|
74 |
+
50% { background: none; }
|
75 |
+
100% { background: #7e7; }
|
76 |
+
}
|
77 |
+
@keyframes blink {
|
78 |
+
0% { background: #7e7; }
|
79 |
+
50% { background: none; }
|
80 |
+
100% { background: #7e7; }
|
81 |
+
}
|
82 |
+
|
83 |
+
/* Can style cursor different in overwrite (non-insert) mode */
|
84 |
+
div.CodeMirror-overwrite div.CodeMirror-cursor {}
|
85 |
+
|
86 |
+
.cm-tab { display: inline-block; }
|
87 |
+
|
88 |
+
.CodeMirror-ruler {
|
89 |
+
border-left: 1px solid #ccc;
|
90 |
+
position: absolute;
|
91 |
+
}
|
92 |
+
|
93 |
+
/* DEFAULT THEME */
|
94 |
+
|
95 |
+
.cm-s-default .cm-keyword {color: #708;}
|
96 |
+
.cm-s-default .cm-atom {color: #219;}
|
97 |
+
.cm-s-default .cm-number {color: #164;}
|
98 |
+
.cm-s-default .cm-def {color: #00f;}
|
99 |
+
.cm-s-default .cm-variable,
|
100 |
+
.cm-s-default .cm-punctuation,
|
101 |
+
.cm-s-default .cm-property,
|
102 |
+
.cm-s-default .cm-operator {}
|
103 |
+
.cm-s-default .cm-variable-2 {color: #05a;}
|
104 |
+
.cm-s-default .cm-variable-3 {color: #085;}
|
105 |
+
.cm-s-default .cm-comment {color: #a50;}
|
106 |
+
.cm-s-default .cm-string {color: #a11;}
|
107 |
+
.cm-s-default .cm-string-2 {color: #f50;}
|
108 |
+
.cm-s-default .cm-meta {color: #555;}
|
109 |
+
.cm-s-default .cm-qualifier {color: #555;}
|
110 |
+
.cm-s-default .cm-builtin {color: #30a;}
|
111 |
+
.cm-s-default .cm-bracket {color: #997;}
|
112 |
+
.cm-s-default .cm-tag {color: #170;}
|
113 |
+
.cm-s-default .cm-attribute {color: #00c;}
|
114 |
+
.cm-s-default .cm-header {color: blue;}
|
115 |
+
.cm-s-default .cm-quote {color: #090;}
|
116 |
+
.cm-s-default .cm-hr {color: #999;}
|
117 |
+
.cm-s-default .cm-link {color: #00c;}
|
118 |
+
|
119 |
+
.cm-negative {color: #d44;}
|
120 |
+
.cm-positive {color: #292;}
|
121 |
+
.cm-header, .cm-strong {font-weight: bold;}
|
122 |
+
.cm-em {font-style: italic;}
|
123 |
+
.cm-link {text-decoration: underline;}
|
124 |
+
|
125 |
+
.cm-s-default .cm-error {color: #f00;}
|
126 |
+
.cm-invalidchar {color: #f00;}
|
127 |
+
|
128 |
+
/* Default styles for common addons */
|
129 |
+
|
130 |
+
div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
|
131 |
+
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
|
132 |
+
.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
|
133 |
+
.CodeMirror-activeline-background {background: #e8f2ff;}
|
134 |
+
|
135 |
+
/* STOP */
|
136 |
+
|
137 |
+
/* The rest of this file contains styles related to the mechanics of
|
138 |
+
the editor. You probably shouldn't touch them. */
|
139 |
+
|
140 |
+
.CodeMirror {
|
141 |
+
line-height: 1;
|
142 |
+
position: relative;
|
143 |
+
overflow: hidden;
|
144 |
+
background: white;
|
145 |
+
color: black;
|
146 |
+
}
|
147 |
+
|
148 |
+
.CodeMirror-scroll {
|
149 |
+
/* 30px is the magic margin used to hide the element's real scrollbars */
|
150 |
+
/* See overflow: hidden in .CodeMirror */
|
151 |
+
margin-bottom: -30px; margin-right: -30px;
|
152 |
+
padding-bottom: 30px;
|
153 |
+
height: 100%;
|
154 |
+
outline: none; /* Prevent dragging from highlighting the element */
|
155 |
+
position: relative;
|
156 |
+
-moz-box-sizing: content-box;
|
157 |
+
box-sizing: content-box;
|
158 |
+
}
|
159 |
+
.CodeMirror-sizer {
|
160 |
+
position: relative;
|
161 |
+
border-right: 30px solid transparent;
|
162 |
+
-moz-box-sizing: content-box;
|
163 |
+
box-sizing: content-box;
|
164 |
+
}
|
165 |
+
|
166 |
+
/* The fake, visible scrollbars. Used to force redraw during scrolling
|
167 |
+
before actuall scrolling happens, thus preventing shaking and
|
168 |
+
flickering artifacts. */
|
169 |
+
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
170 |
+
position: absolute;
|
171 |
+
z-index: 6;
|
172 |
+
display: none;
|
173 |
+
}
|
174 |
+
.CodeMirror-vscrollbar {
|
175 |
+
right: 0; top: 0;
|
176 |
+
overflow-x: hidden;
|
177 |
+
overflow-y: scroll;
|
178 |
+
}
|
179 |
+
.CodeMirror-hscrollbar {
|
180 |
+
bottom: 0; left: 0;
|
181 |
+
overflow-y: hidden;
|
182 |
+
overflow-x: scroll;
|
183 |
+
}
|
184 |
+
.CodeMirror-scrollbar-filler {
|
185 |
+
right: 0; bottom: 0;
|
186 |
+
}
|
187 |
+
.CodeMirror-gutter-filler {
|
188 |
+
left: 0; bottom: 0;
|
189 |
+
}
|
190 |
+
|
191 |
+
.CodeMirror-gutters {
|
192 |
+
position: absolute; left: 0; top: 0;
|
193 |
+
padding-bottom: 30px;
|
194 |
+
z-index: 3;
|
195 |
+
}
|
196 |
+
.CodeMirror-gutter {
|
197 |
+
white-space: normal;
|
198 |
+
height: 100%;
|
199 |
+
-moz-box-sizing: content-box;
|
200 |
+
box-sizing: content-box;
|
201 |
+
padding-bottom: 30px;
|
202 |
+
margin-bottom: -32px;
|
203 |
+
display: inline-block;
|
204 |
+
/* Hack to make IE7 behave */
|
205 |
+
*zoom:1;
|
206 |
+
*display:inline;
|
207 |
+
}
|
208 |
+
.CodeMirror-gutter-elt {
|
209 |
+
position: absolute;
|
210 |
+
cursor: default;
|
211 |
+
z-index: 4;
|
212 |
+
}
|
213 |
+
|
214 |
+
.CodeMirror-lines {
|
215 |
+
cursor: text;
|
216 |
+
}
|
217 |
+
.CodeMirror pre {
|
218 |
+
/* Reset some styles that the rest of the page might have set */
|
219 |
+
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
|
220 |
+
border-width: 0;
|
221 |
+
background: transparent;
|
222 |
+
font-family: inherit;
|
223 |
+
font-size: inherit;
|
224 |
+
margin: 0;
|
225 |
+
white-space: pre;
|
226 |
+
word-wrap: normal;
|
227 |
+
line-height: inherit;
|
228 |
+
color: inherit;
|
229 |
+
z-index: 2;
|
230 |
+
position: relative;
|
231 |
+
overflow: visible;
|
232 |
+
}
|
233 |
+
.CodeMirror-wrap pre {
|
234 |
+
word-wrap: break-word;
|
235 |
+
white-space: pre-wrap;
|
236 |
+
word-break: normal;
|
237 |
+
}
|
238 |
+
|
239 |
+
.CodeMirror-linebackground {
|
240 |
+
position: absolute;
|
241 |
+
left: 0; right: 0; top: 0; bottom: 0;
|
242 |
+
z-index: 0;
|
243 |
+
}
|
244 |
+
|
245 |
+
.CodeMirror-linewidget {
|
246 |
+
position: relative;
|
247 |
+
z-index: 2;
|
248 |
+
overflow: auto;
|
249 |
+
}
|
250 |
+
|
251 |
+
.CodeMirror-widget {}
|
252 |
+
|
253 |
+
.CodeMirror-wrap .CodeMirror-scroll {
|
254 |
+
overflow-x: hidden;
|
255 |
+
}
|
256 |
+
|
257 |
+
.CodeMirror-measure {
|
258 |
+
position: absolute;
|
259 |
+
width: 100%;
|
260 |
+
height: 0;
|
261 |
+
overflow: hidden;
|
262 |
+
visibility: hidden;
|
263 |
+
}
|
264 |
+
.CodeMirror-measure pre { position: static; }
|
265 |
+
|
266 |
+
.CodeMirror div.CodeMirror-cursor {
|
267 |
+
position: absolute;
|
268 |
+
border-right: none;
|
269 |
+
width: 0;
|
270 |
+
}
|
271 |
+
|
272 |
+
div.CodeMirror-cursors {
|
273 |
+
visibility: hidden;
|
274 |
+
position: relative;
|
275 |
+
z-index: 1;
|
276 |
+
}
|
277 |
+
.CodeMirror-focused div.CodeMirror-cursors {
|
278 |
+
visibility: visible;
|
279 |
+
}
|
280 |
+
|
281 |
+
.CodeMirror-selected { background: #d9d9d9; }
|
282 |
+
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
|
283 |
+
.CodeMirror-crosshair { cursor: crosshair; }
|
284 |
+
|
285 |
+
.cm-searching {
|
286 |
+
background: #ffa;
|
287 |
+
background: rgba(255, 255, 0, .4);
|
288 |
+
}
|
289 |
+
|
290 |
+
/* IE7 hack to prevent it from returning funny offsetTops on the spans */
|
291 |
+
.CodeMirror span { *vertical-align: text-bottom; }
|
292 |
+
|
293 |
+
/* Used to force a border model for a node */
|
294 |
+
.cm-force-border { padding-right: .1px; }
|
295 |
+
|
296 |
+
@media print {
|
297 |
+
/* Hide the cursor when printing */
|
298 |
+
.CodeMirror div.CodeMirror-cursors {
|
299 |
+
visibility: hidden;
|
300 |
+
}
|
301 |
+
}
|
admin/codemirror/lib/codemirror.js
ADDED
@@ -0,0 +1,7801 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
// This is CodeMirror (http://codemirror.net), a code editor
|
5 |
+
// implemented in JavaScript on top of the browser's DOM.
|
6 |
+
//
|
7 |
+
// You can find some technical background for some of the code below
|
8 |
+
// at http://marijnhaverbeke.nl/blog/#cm-internals .
|
9 |
+
|
10 |
+
(function(mod) {
|
11 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
12 |
+
module.exports = mod();
|
13 |
+
else if (typeof define == "function" && define.amd) // AMD
|
14 |
+
return define([], mod);
|
15 |
+
else // Plain browser env
|
16 |
+
this.CodeMirror = mod();
|
17 |
+
})(function() {
|
18 |
+
"use strict";
|
19 |
+
|
20 |
+
// BROWSER SNIFFING
|
21 |
+
|
22 |
+
// Kludges for bugs and behavior differences that can't be feature
|
23 |
+
// detected are enabled based on userAgent etc sniffing.
|
24 |
+
|
25 |
+
var gecko = /gecko\/\d/i.test(navigator.userAgent);
|
26 |
+
// ie_uptoN means Internet Explorer version N or lower
|
27 |
+
var ie_upto10 = /MSIE \d/.test(navigator.userAgent);
|
28 |
+
var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
|
29 |
+
var ie = ie_upto10 || ie_11up;
|
30 |
+
var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : ie_11up[1]);
|
31 |
+
var webkit = /WebKit\//.test(navigator.userAgent);
|
32 |
+
var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(navigator.userAgent);
|
33 |
+
var chrome = /Chrome\//.test(navigator.userAgent);
|
34 |
+
var presto = /Opera\//.test(navigator.userAgent);
|
35 |
+
var safari = /Apple Computer/.test(navigator.vendor);
|
36 |
+
var khtml = /KHTML\//.test(navigator.userAgent);
|
37 |
+
var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent);
|
38 |
+
var phantom = /PhantomJS/.test(navigator.userAgent);
|
39 |
+
|
40 |
+
var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
|
41 |
+
// This is woefully incomplete. Suggestions for alternative methods welcome.
|
42 |
+
var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent);
|
43 |
+
var mac = ios || /Mac/.test(navigator.platform);
|
44 |
+
var windows = /win/i.test(navigator.platform);
|
45 |
+
|
46 |
+
var presto_version = presto && navigator.userAgent.match(/Version\/(\d*\.\d*)/);
|
47 |
+
if (presto_version) presto_version = Number(presto_version[1]);
|
48 |
+
if (presto_version && presto_version >= 15) { presto = false; webkit = true; }
|
49 |
+
// Some browsers use the wrong event properties to signal cmd/ctrl on OS X
|
50 |
+
var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
|
51 |
+
var captureRightClick = gecko || (ie && ie_version >= 9);
|
52 |
+
|
53 |
+
// Optimize some code when these features are not used.
|
54 |
+
var sawReadOnlySpans = false, sawCollapsedSpans = false;
|
55 |
+
|
56 |
+
// EDITOR CONSTRUCTOR
|
57 |
+
|
58 |
+
// A CodeMirror instance represents an editor. This is the object
|
59 |
+
// that user code is usually dealing with.
|
60 |
+
|
61 |
+
function CodeMirror(place, options) {
|
62 |
+
if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
|
63 |
+
|
64 |
+
this.options = options = options || {};
|
65 |
+
// Determine effective options based on given values and defaults.
|
66 |
+
copyObj(defaults, options, false);
|
67 |
+
setGuttersForLineNumbers(options);
|
68 |
+
|
69 |
+
var doc = options.value;
|
70 |
+
if (typeof doc == "string") doc = new Doc(doc, options.mode);
|
71 |
+
this.doc = doc;
|
72 |
+
|
73 |
+
var display = this.display = new Display(place, doc);
|
74 |
+
display.wrapper.CodeMirror = this;
|
75 |
+
updateGutters(this);
|
76 |
+
themeChanged(this);
|
77 |
+
if (options.lineWrapping)
|
78 |
+
this.display.wrapper.className += " CodeMirror-wrap";
|
79 |
+
if (options.autofocus && !mobile) focusInput(this);
|
80 |
+
|
81 |
+
this.state = {
|
82 |
+
keyMaps: [], // stores maps added by addKeyMap
|
83 |
+
overlays: [], // highlighting overlays, as added by addOverlay
|
84 |
+
modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
|
85 |
+
overwrite: false, focused: false,
|
86 |
+
suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
|
87 |
+
pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in readInput
|
88 |
+
draggingText: false,
|
89 |
+
highlight: new Delayed() // stores highlight worker timeout
|
90 |
+
};
|
91 |
+
|
92 |
+
// Override magic textarea content restore that IE sometimes does
|
93 |
+
// on our hidden textarea on reload
|
94 |
+
if (ie && ie_version < 11) setTimeout(bind(resetInput, this, true), 20);
|
95 |
+
|
96 |
+
registerEventHandlers(this);
|
97 |
+
ensureGlobalHandlers();
|
98 |
+
|
99 |
+
var cm = this;
|
100 |
+
runInOp(this, function() {
|
101 |
+
cm.curOp.forceUpdate = true;
|
102 |
+
attachDoc(cm, doc);
|
103 |
+
|
104 |
+
if ((options.autofocus && !mobile) || activeElt() == display.input)
|
105 |
+
setTimeout(bind(onFocus, cm), 20);
|
106 |
+
else
|
107 |
+
onBlur(cm);
|
108 |
+
|
109 |
+
for (var opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt))
|
110 |
+
optionHandlers[opt](cm, options[opt], Init);
|
111 |
+
maybeUpdateLineNumberWidth(cm);
|
112 |
+
for (var i = 0; i < initHooks.length; ++i) initHooks[i](cm);
|
113 |
+
});
|
114 |
+
}
|
115 |
+
|
116 |
+
// DISPLAY CONSTRUCTOR
|
117 |
+
|
118 |
+
// The display handles the DOM integration, both for input reading
|
119 |
+
// and content drawing. It holds references to DOM nodes and
|
120 |
+
// display-related state.
|
121 |
+
|
122 |
+
function Display(place, doc) {
|
123 |
+
var d = this;
|
124 |
+
|
125 |
+
// The semihidden textarea that is focused when the editor is
|
126 |
+
// focused, and receives input.
|
127 |
+
var input = d.input = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none");
|
128 |
+
// The textarea is kept positioned near the cursor to prevent the
|
129 |
+
// fact that it'll be scrolled into view on input from scrolling
|
130 |
+
// our fake cursor out of view. On webkit, when wrap=off, paste is
|
131 |
+
// very slow. So make the area wide instead.
|
132 |
+
if (webkit) input.style.width = "1000px";
|
133 |
+
else input.setAttribute("wrap", "off");
|
134 |
+
// If border: 0; -- iOS fails to open keyboard (issue #1287)
|
135 |
+
if (ios) input.style.border = "1px solid black";
|
136 |
+
input.setAttribute("autocorrect", "off"); input.setAttribute("autocapitalize", "off"); input.setAttribute("spellcheck", "false");
|
137 |
+
|
138 |
+
// Wraps and hides input textarea
|
139 |
+
d.inputDiv = elt("div", [input], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
|
140 |
+
// The fake scrollbar elements.
|
141 |
+
d.scrollbarH = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
|
142 |
+
d.scrollbarV = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
|
143 |
+
// Covers bottom-right square when both scrollbars are present.
|
144 |
+
d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
|
145 |
+
// Covers bottom of gutter when coverGutterNextToScrollbar is on
|
146 |
+
// and h scrollbar is present.
|
147 |
+
d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
|
148 |
+
// Will contain the actual code, positioned to cover the viewport.
|
149 |
+
d.lineDiv = elt("div", null, "CodeMirror-code");
|
150 |
+
// Elements are added to these to represent selection and cursors.
|
151 |
+
d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
|
152 |
+
d.cursorDiv = elt("div", null, "CodeMirror-cursors");
|
153 |
+
// A visibility: hidden element used to find the size of things.
|
154 |
+
d.measure = elt("div", null, "CodeMirror-measure");
|
155 |
+
// When lines outside of the viewport are measured, they are drawn in this.
|
156 |
+
d.lineMeasure = elt("div", null, "CodeMirror-measure");
|
157 |
+
// Wraps everything that needs to exist inside the vertically-padded coordinate system
|
158 |
+
d.lineSpace = elt("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
|
159 |
+
null, "position: relative; outline: none");
|
160 |
+
// Moved around its parent to cover visible view.
|
161 |
+
d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative");
|
162 |
+
// Set to the height of the document, allowing scrolling.
|
163 |
+
d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
|
164 |
+
// Behavior of elts with overflow: auto and padding is
|
165 |
+
// inconsistent across browsers. This is used to ensure the
|
166 |
+
// scrollable area is big enough.
|
167 |
+
d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerCutOff + "px; width: 1px;");
|
168 |
+
// Will contain the gutters, if any.
|
169 |
+
d.gutters = elt("div", null, "CodeMirror-gutters");
|
170 |
+
d.lineGutter = null;
|
171 |
+
// Actual scrollable element.
|
172 |
+
d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
|
173 |
+
d.scroller.setAttribute("tabIndex", "-1");
|
174 |
+
// The element in which the editor lives.
|
175 |
+
d.wrapper = elt("div", [d.inputDiv, d.scrollbarH, d.scrollbarV,
|
176 |
+
d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
|
177 |
+
|
178 |
+
// Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
|
179 |
+
if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
|
180 |
+
// Needed to hide big blue blinking cursor on Mobile Safari
|
181 |
+
if (ios) input.style.width = "0px";
|
182 |
+
if (!webkit) d.scroller.draggable = true;
|
183 |
+
// Needed to handle Tab key in KHTML
|
184 |
+
if (khtml) { d.inputDiv.style.height = "1px"; d.inputDiv.style.position = "absolute"; }
|
185 |
+
// Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
|
186 |
+
if (ie && ie_version < 8) d.scrollbarH.style.minHeight = d.scrollbarV.style.minWidth = "18px";
|
187 |
+
|
188 |
+
if (place.appendChild) place.appendChild(d.wrapper);
|
189 |
+
else place(d.wrapper);
|
190 |
+
|
191 |
+
// Current rendered range (may be bigger than the view window).
|
192 |
+
d.viewFrom = d.viewTo = doc.first;
|
193 |
+
// Information about the rendered lines.
|
194 |
+
d.view = [];
|
195 |
+
// Holds info about a single rendered line when it was rendered
|
196 |
+
// for measurement, while not in view.
|
197 |
+
d.externalMeasured = null;
|
198 |
+
// Empty space (in pixels) above the view
|
199 |
+
d.viewOffset = 0;
|
200 |
+
d.lastSizeC = 0;
|
201 |
+
d.updateLineNumbers = null;
|
202 |
+
|
203 |
+
// Used to only resize the line number gutter when necessary (when
|
204 |
+
// the amount of lines crosses a boundary that makes its width change)
|
205 |
+
d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
|
206 |
+
// See readInput and resetInput
|
207 |
+
d.prevInput = "";
|
208 |
+
// Set to true when a non-horizontal-scrolling line widget is
|
209 |
+
// added. As an optimization, line widget aligning is skipped when
|
210 |
+
// this is false.
|
211 |
+
d.alignWidgets = false;
|
212 |
+
// Flag that indicates whether we expect input to appear real soon
|
213 |
+
// now (after some event like 'keypress' or 'input') and are
|
214 |
+
// polling intensively.
|
215 |
+
d.pollingFast = false;
|
216 |
+
// Self-resetting timeout for the poller
|
217 |
+
d.poll = new Delayed();
|
218 |
+
|
219 |
+
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
|
220 |
+
|
221 |
+
// Tracks when resetInput has punted to just putting a short
|
222 |
+
// string into the textarea instead of the full selection.
|
223 |
+
d.inaccurateSelection = false;
|
224 |
+
|
225 |
+
// Tracks the maximum line length so that the horizontal scrollbar
|
226 |
+
// can be kept static when scrolling.
|
227 |
+
d.maxLine = null;
|
228 |
+
d.maxLineLength = 0;
|
229 |
+
d.maxLineChanged = false;
|
230 |
+
|
231 |
+
// Used for measuring wheel scrolling granularity
|
232 |
+
d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
|
233 |
+
|
234 |
+
// True when shift is held down.
|
235 |
+
d.shift = false;
|
236 |
+
|
237 |
+
// Used to track whether anything happened since the context menu
|
238 |
+
// was opened.
|
239 |
+
d.selForContextMenu = null;
|
240 |
+
}
|
241 |
+
|
242 |
+
// STATE UPDATES
|
243 |
+
|
244 |
+
// Used to get the editor into a consistent state again when options change.
|
245 |
+
|
246 |
+
function loadMode(cm) {
|
247 |
+
cm.doc.mode = CodeMirror.getMode(cm.options, cm.doc.modeOption);
|
248 |
+
resetModeState(cm);
|
249 |
+
}
|
250 |
+
|
251 |
+
function resetModeState(cm) {
|
252 |
+
cm.doc.iter(function(line) {
|
253 |
+
if (line.stateAfter) line.stateAfter = null;
|
254 |
+
if (line.styles) line.styles = null;
|
255 |
+
});
|
256 |
+
cm.doc.frontier = cm.doc.first;
|
257 |
+
startWorker(cm, 100);
|
258 |
+
cm.state.modeGen++;
|
259 |
+
if (cm.curOp) regChange(cm);
|
260 |
+
}
|
261 |
+
|
262 |
+
function wrappingChanged(cm) {
|
263 |
+
if (cm.options.lineWrapping) {
|
264 |
+
addClass(cm.display.wrapper, "CodeMirror-wrap");
|
265 |
+
cm.display.sizer.style.minWidth = "";
|
266 |
+
} else {
|
267 |
+
rmClass(cm.display.wrapper, "CodeMirror-wrap");
|
268 |
+
findMaxLine(cm);
|
269 |
+
}
|
270 |
+
estimateLineHeights(cm);
|
271 |
+
regChange(cm);
|
272 |
+
clearCaches(cm);
|
273 |
+
setTimeout(function(){updateScrollbars(cm);}, 100);
|
274 |
+
}
|
275 |
+
|
276 |
+
// Returns a function that estimates the height of a line, to use as
|
277 |
+
// first approximation until the line becomes visible (and is thus
|
278 |
+
// properly measurable).
|
279 |
+
function estimateHeight(cm) {
|
280 |
+
var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
|
281 |
+
var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
|
282 |
+
return function(line) {
|
283 |
+
if (lineIsHidden(cm.doc, line)) return 0;
|
284 |
+
|
285 |
+
var widgetsHeight = 0;
|
286 |
+
if (line.widgets) for (var i = 0; i < line.widgets.length; i++) {
|
287 |
+
if (line.widgets[i].height) widgetsHeight += line.widgets[i].height;
|
288 |
+
}
|
289 |
+
|
290 |
+
if (wrapping)
|
291 |
+
return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th;
|
292 |
+
else
|
293 |
+
return widgetsHeight + th;
|
294 |
+
};
|
295 |
+
}
|
296 |
+
|
297 |
+
function estimateLineHeights(cm) {
|
298 |
+
var doc = cm.doc, est = estimateHeight(cm);
|
299 |
+
doc.iter(function(line) {
|
300 |
+
var estHeight = est(line);
|
301 |
+
if (estHeight != line.height) updateLineHeight(line, estHeight);
|
302 |
+
});
|
303 |
+
}
|
304 |
+
|
305 |
+
function keyMapChanged(cm) {
|
306 |
+
var map = keyMap[cm.options.keyMap], style = map.style;
|
307 |
+
cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-keymap-\S+/g, "") +
|
308 |
+
(style ? " cm-keymap-" + style : "");
|
309 |
+
}
|
310 |
+
|
311 |
+
function themeChanged(cm) {
|
312 |
+
cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
|
313 |
+
cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
|
314 |
+
clearCaches(cm);
|
315 |
+
}
|
316 |
+
|
317 |
+
function guttersChanged(cm) {
|
318 |
+
updateGutters(cm);
|
319 |
+
regChange(cm);
|
320 |
+
setTimeout(function(){alignHorizontally(cm);}, 20);
|
321 |
+
}
|
322 |
+
|
323 |
+
// Rebuild the gutter elements, ensure the margin to the left of the
|
324 |
+
// code matches their width.
|
325 |
+
function updateGutters(cm) {
|
326 |
+
var gutters = cm.display.gutters, specs = cm.options.gutters;
|
327 |
+
removeChildren(gutters);
|
328 |
+
for (var i = 0; i < specs.length; ++i) {
|
329 |
+
var gutterClass = specs[i];
|
330 |
+
var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
|
331 |
+
if (gutterClass == "CodeMirror-linenumbers") {
|
332 |
+
cm.display.lineGutter = gElt;
|
333 |
+
gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
|
334 |
+
}
|
335 |
+
}
|
336 |
+
gutters.style.display = i ? "" : "none";
|
337 |
+
updateGutterSpace(cm);
|
338 |
+
}
|
339 |
+
|
340 |
+
function updateGutterSpace(cm) {
|
341 |
+
var width = cm.display.gutters.offsetWidth;
|
342 |
+
cm.display.sizer.style.marginLeft = width + "px";
|
343 |
+
cm.display.scrollbarH.style.left = cm.options.fixedGutter ? width + "px" : 0;
|
344 |
+
}
|
345 |
+
|
346 |
+
// Compute the character length of a line, taking into account
|
347 |
+
// collapsed ranges (see markText) that might hide parts, and join
|
348 |
+
// other lines onto it.
|
349 |
+
function lineLength(line) {
|
350 |
+
if (line.height == 0) return 0;
|
351 |
+
var len = line.text.length, merged, cur = line;
|
352 |
+
while (merged = collapsedSpanAtStart(cur)) {
|
353 |
+
var found = merged.find(0, true);
|
354 |
+
cur = found.from.line;
|
355 |
+
len += found.from.ch - found.to.ch;
|
356 |
+
}
|
357 |
+
cur = line;
|
358 |
+
while (merged = collapsedSpanAtEnd(cur)) {
|
359 |
+
var found = merged.find(0, true);
|
360 |
+
len -= cur.text.length - found.from.ch;
|
361 |
+
cur = found.to.line;
|
362 |
+
len += cur.text.length - found.to.ch;
|
363 |
+
}
|
364 |
+
return len;
|
365 |
+
}
|
366 |
+
|
367 |
+
// Find the longest line in the document.
|
368 |
+
function findMaxLine(cm) {
|
369 |
+
var d = cm.display, doc = cm.doc;
|
370 |
+
d.maxLine = getLine(doc, doc.first);
|
371 |
+
d.maxLineLength = lineLength(d.maxLine);
|
372 |
+
d.maxLineChanged = true;
|
373 |
+
doc.iter(function(line) {
|
374 |
+
var len = lineLength(line);
|
375 |
+
if (len > d.maxLineLength) {
|
376 |
+
d.maxLineLength = len;
|
377 |
+
d.maxLine = line;
|
378 |
+
}
|
379 |
+
});
|
380 |
+
}
|
381 |
+
|
382 |
+
// Make sure the gutters options contains the element
|
383 |
+
// "CodeMirror-linenumbers" when the lineNumbers option is true.
|
384 |
+
function setGuttersForLineNumbers(options) {
|
385 |
+
var found = indexOf(options.gutters, "CodeMirror-linenumbers");
|
386 |
+
if (found == -1 && options.lineNumbers) {
|
387 |
+
options.gutters = options.gutters.concat(["CodeMirror-linenumbers"]);
|
388 |
+
} else if (found > -1 && !options.lineNumbers) {
|
389 |
+
options.gutters = options.gutters.slice(0);
|
390 |
+
options.gutters.splice(found, 1);
|
391 |
+
}
|
392 |
+
}
|
393 |
+
|
394 |
+
// SCROLLBARS
|
395 |
+
|
396 |
+
function hScrollbarTakesSpace(cm) {
|
397 |
+
return cm.display.scroller.clientHeight - cm.display.wrapper.clientHeight < scrollerCutOff - 3;
|
398 |
+
}
|
399 |
+
|
400 |
+
// Prepare DOM reads needed to update the scrollbars. Done in one
|
401 |
+
// shot to minimize update/measure roundtrips.
|
402 |
+
function measureForScrollbars(cm) {
|
403 |
+
var scroll = cm.display.scroller;
|
404 |
+
return {
|
405 |
+
clientHeight: scroll.clientHeight,
|
406 |
+
barHeight: cm.display.scrollbarV.clientHeight,
|
407 |
+
scrollWidth: scroll.scrollWidth, clientWidth: scroll.clientWidth,
|
408 |
+
hScrollbarTakesSpace: hScrollbarTakesSpace(cm),
|
409 |
+
barWidth: cm.display.scrollbarH.clientWidth,
|
410 |
+
docHeight: Math.round(cm.doc.height + paddingVert(cm.display))
|
411 |
+
};
|
412 |
+
}
|
413 |
+
|
414 |
+
// Re-synchronize the fake scrollbars with the actual size of the
|
415 |
+
// content.
|
416 |
+
function updateScrollbars(cm, measure) {
|
417 |
+
if (!measure) measure = measureForScrollbars(cm);
|
418 |
+
var d = cm.display, sWidth = scrollbarWidth(d.measure);
|
419 |
+
var scrollHeight = measure.docHeight + scrollerCutOff;
|
420 |
+
var needsH = measure.scrollWidth > measure.clientWidth;
|
421 |
+
if (needsH && measure.scrollWidth <= measure.clientWidth + 1 &&
|
422 |
+
sWidth > 0 && !measure.hScrollbarTakesSpace)
|
423 |
+
needsH = false; // (Issue #2562)
|
424 |
+
var needsV = scrollHeight > measure.clientHeight;
|
425 |
+
|
426 |
+
if (needsV) {
|
427 |
+
d.scrollbarV.style.display = "block";
|
428 |
+
d.scrollbarV.style.bottom = needsH ? sWidth + "px" : "0";
|
429 |
+
// A bug in IE8 can cause this value to be negative, so guard it.
|
430 |
+
d.scrollbarV.firstChild.style.height =
|
431 |
+
Math.max(0, scrollHeight - measure.clientHeight + (measure.barHeight || d.scrollbarV.clientHeight)) + "px";
|
432 |
+
} else {
|
433 |
+
d.scrollbarV.style.display = "";
|
434 |
+
d.scrollbarV.firstChild.style.height = "0";
|
435 |
+
}
|
436 |
+
if (needsH) {
|
437 |
+
d.scrollbarH.style.display = "block";
|
438 |
+
d.scrollbarH.style.right = needsV ? sWidth + "px" : "0";
|
439 |
+
d.scrollbarH.firstChild.style.width =
|
440 |
+
(measure.scrollWidth - measure.clientWidth + (measure.barWidth || d.scrollbarH.clientWidth)) + "px";
|
441 |
+
} else {
|
442 |
+
d.scrollbarH.style.display = "";
|
443 |
+
d.scrollbarH.firstChild.style.width = "0";
|
444 |
+
}
|
445 |
+
if (needsH && needsV) {
|
446 |
+
d.scrollbarFiller.style.display = "block";
|
447 |
+
d.scrollbarFiller.style.height = d.scrollbarFiller.style.width = sWidth + "px";
|
448 |
+
} else d.scrollbarFiller.style.display = "";
|
449 |
+
if (needsH && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
|
450 |
+
d.gutterFiller.style.display = "block";
|
451 |
+
d.gutterFiller.style.height = sWidth + "px";
|
452 |
+
d.gutterFiller.style.width = d.gutters.offsetWidth + "px";
|
453 |
+
} else d.gutterFiller.style.display = "";
|
454 |
+
|
455 |
+
if (!cm.state.checkedOverlayScrollbar && measure.clientHeight > 0) {
|
456 |
+
if (sWidth === 0) {
|
457 |
+
var w = mac && !mac_geMountainLion ? "12px" : "18px";
|
458 |
+
d.scrollbarV.style.minWidth = d.scrollbarH.style.minHeight = w;
|
459 |
+
var barMouseDown = function(e) {
|
460 |
+
if (e_target(e) != d.scrollbarV && e_target(e) != d.scrollbarH)
|
461 |
+
operation(cm, onMouseDown)(e);
|
462 |
+
};
|
463 |
+
on(d.scrollbarV, "mousedown", barMouseDown);
|
464 |
+
on(d.scrollbarH, "mousedown", barMouseDown);
|
465 |
+
}
|
466 |
+
cm.state.checkedOverlayScrollbar = true;
|
467 |
+
}
|
468 |
+
}
|
469 |
+
|
470 |
+
// Compute the lines that are visible in a given viewport (defaults
|
471 |
+
// the the current scroll position). viewport may contain top,
|
472 |
+
// height, and ensure (see op.scrollToPos) properties.
|
473 |
+
function visibleLines(display, doc, viewport) {
|
474 |
+
var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
|
475 |
+
top = Math.floor(top - paddingTop(display));
|
476 |
+
var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
|
477 |
+
|
478 |
+
var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom);
|
479 |
+
// Ensure is a {from: {line, ch}, to: {line, ch}} object, and
|
480 |
+
// forces those lines into the viewport (if possible).
|
481 |
+
if (viewport && viewport.ensure) {
|
482 |
+
var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
|
483 |
+
if (ensureFrom < from)
|
484 |
+
return {from: ensureFrom,
|
485 |
+
to: lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight)};
|
486 |
+
if (Math.min(ensureTo, doc.lastLine()) >= to)
|
487 |
+
return {from: lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight),
|
488 |
+
to: ensureTo};
|
489 |
+
}
|
490 |
+
return {from: from, to: Math.max(to, from + 1)};
|
491 |
+
}
|
492 |
+
|
493 |
+
// LINE NUMBERS
|
494 |
+
|
495 |
+
// Re-align line numbers and gutter marks to compensate for
|
496 |
+
// horizontal scrolling.
|
497 |
+
function alignHorizontally(cm) {
|
498 |
+
var display = cm.display, view = display.view;
|
499 |
+
if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) return;
|
500 |
+
var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
|
501 |
+
var gutterW = display.gutters.offsetWidth, left = comp + "px";
|
502 |
+
for (var i = 0; i < view.length; i++) if (!view[i].hidden) {
|
503 |
+
if (cm.options.fixedGutter && view[i].gutter)
|
504 |
+
view[i].gutter.style.left = left;
|
505 |
+
var align = view[i].alignable;
|
506 |
+
if (align) for (var j = 0; j < align.length; j++)
|
507 |
+
align[j].style.left = left;
|
508 |
+
}
|
509 |
+
if (cm.options.fixedGutter)
|
510 |
+
display.gutters.style.left = (comp + gutterW) + "px";
|
511 |
+
}
|
512 |
+
|
513 |
+
// Used to ensure that the line number gutter is still the right
|
514 |
+
// size for the current document size. Returns true when an update
|
515 |
+
// is needed.
|
516 |
+
function maybeUpdateLineNumberWidth(cm) {
|
517 |
+
if (!cm.options.lineNumbers) return false;
|
518 |
+
var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
|
519 |
+
if (last.length != display.lineNumChars) {
|
520 |
+
var test = display.measure.appendChild(elt("div", [elt("div", last)],
|
521 |
+
"CodeMirror-linenumber CodeMirror-gutter-elt"));
|
522 |
+
var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
|
523 |
+
display.lineGutter.style.width = "";
|
524 |
+
display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding);
|
525 |
+
display.lineNumWidth = display.lineNumInnerWidth + padding;
|
526 |
+
display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
|
527 |
+
display.lineGutter.style.width = display.lineNumWidth + "px";
|
528 |
+
updateGutterSpace(cm);
|
529 |
+
return true;
|
530 |
+
}
|
531 |
+
return false;
|
532 |
+
}
|
533 |
+
|
534 |
+
function lineNumberFor(options, i) {
|
535 |
+
return String(options.lineNumberFormatter(i + options.firstLineNumber));
|
536 |
+
}
|
537 |
+
|
538 |
+
// Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
|
539 |
+
// but using getBoundingClientRect to get a sub-pixel-accurate
|
540 |
+
// result.
|
541 |
+
function compensateForHScroll(display) {
|
542 |
+
return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left;
|
543 |
+
}
|
544 |
+
|
545 |
+
// DISPLAY DRAWING
|
546 |
+
|
547 |
+
function DisplayUpdate(cm, viewport, force) {
|
548 |
+
var display = cm.display;
|
549 |
+
|
550 |
+
this.viewport = viewport;
|
551 |
+
// Store some values that we'll need later (but don't want to force a relayout for)
|
552 |
+
this.visible = visibleLines(display, cm.doc, viewport);
|
553 |
+
this.editorIsHidden = !display.wrapper.offsetWidth;
|
554 |
+
this.wrapperHeight = display.wrapper.clientHeight;
|
555 |
+
this.oldViewFrom = display.viewFrom; this.oldViewTo = display.viewTo;
|
556 |
+
this.oldScrollerWidth = display.scroller.clientWidth;
|
557 |
+
this.force = force;
|
558 |
+
this.dims = getDimensions(cm);
|
559 |
+
}
|
560 |
+
|
561 |
+
// Does the actual updating of the line display. Bails out
|
562 |
+
// (returning false) when there is nothing to be done and forced is
|
563 |
+
// false.
|
564 |
+
function updateDisplayIfNeeded(cm, update) {
|
565 |
+
var display = cm.display, doc = cm.doc;
|
566 |
+
if (update.editorIsHidden) {
|
567 |
+
resetView(cm);
|
568 |
+
return false;
|
569 |
+
}
|
570 |
+
|
571 |
+
// Bail out if the visible area is already rendered and nothing changed.
|
572 |
+
if (!update.force &&
|
573 |
+
update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
|
574 |
+
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
|
575 |
+
countDirtyView(cm) == 0)
|
576 |
+
return false;
|
577 |
+
|
578 |
+
if (maybeUpdateLineNumberWidth(cm)) {
|
579 |
+
resetView(cm);
|
580 |
+
update.dims = getDimensions(cm);
|
581 |
+
}
|
582 |
+
|
583 |
+
// Compute a suitable new viewport (from & to)
|
584 |
+
var end = doc.first + doc.size;
|
585 |
+
var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
|
586 |
+
var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
|
587 |
+
if (display.viewFrom < from && from - display.viewFrom < 20) from = Math.max(doc.first, display.viewFrom);
|
588 |
+
if (display.viewTo > to && display.viewTo - to < 20) to = Math.min(end, display.viewTo);
|
589 |
+
if (sawCollapsedSpans) {
|
590 |
+
from = visualLineNo(cm.doc, from);
|
591 |
+
to = visualLineEndNo(cm.doc, to);
|
592 |
+
}
|
593 |
+
|
594 |
+
var different = from != display.viewFrom || to != display.viewTo ||
|
595 |
+
display.lastSizeC != update.wrapperHeight;
|
596 |
+
adjustView(cm, from, to);
|
597 |
+
|
598 |
+
display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
|
599 |
+
// Position the mover div to align with the current scroll position
|
600 |
+
cm.display.mover.style.top = display.viewOffset + "px";
|
601 |
+
|
602 |
+
var toUpdate = countDirtyView(cm);
|
603 |
+
if (!different && toUpdate == 0 && !update.force &&
|
604 |
+
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
|
605 |
+
return false;
|
606 |
+
|
607 |
+
// For big changes, we hide the enclosing element during the
|
608 |
+
// update, since that speeds up the operations on most browsers.
|
609 |
+
var focused = activeElt();
|
610 |
+
if (toUpdate > 4) display.lineDiv.style.display = "none";
|
611 |
+
patchDisplay(cm, display.updateLineNumbers, update.dims);
|
612 |
+
if (toUpdate > 4) display.lineDiv.style.display = "";
|
613 |
+
// There might have been a widget with a focused element that got
|
614 |
+
// hidden or updated, if so re-focus it.
|
615 |
+
if (focused && activeElt() != focused && focused.offsetHeight) focused.focus();
|
616 |
+
|
617 |
+
// Prevent selection and cursors from interfering with the scroll
|
618 |
+
// width.
|
619 |
+
removeChildren(display.cursorDiv);
|
620 |
+
removeChildren(display.selectionDiv);
|
621 |
+
|
622 |
+
if (different) {
|
623 |
+
display.lastSizeC = update.wrapperHeight;
|
624 |
+
startWorker(cm, 400);
|
625 |
+
}
|
626 |
+
|
627 |
+
display.updateLineNumbers = null;
|
628 |
+
|
629 |
+
return true;
|
630 |
+
}
|
631 |
+
|
632 |
+
function postUpdateDisplay(cm, update) {
|
633 |
+
var force = update.force, viewport = update.viewport;
|
634 |
+
for (var first = true;; first = false) {
|
635 |
+
if (first && cm.options.lineWrapping && update.oldScrollerWidth != cm.display.scroller.clientWidth) {
|
636 |
+
force = true;
|
637 |
+
} else {
|
638 |
+
force = false;
|
639 |
+
// Clip forced viewport to actual scrollable area.
|
640 |
+
if (viewport && viewport.top != null)
|
641 |
+
viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - scrollerCutOff -
|
642 |
+
cm.display.scroller.clientHeight, viewport.top)};
|
643 |
+
// Updated line heights might result in the drawn area not
|
644 |
+
// actually covering the viewport. Keep looping until it does.
|
645 |
+
update.visible = visibleLines(cm.display, cm.doc, viewport);
|
646 |
+
if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
|
647 |
+
break;
|
648 |
+
}
|
649 |
+
if (!updateDisplayIfNeeded(cm, update)) break;
|
650 |
+
updateHeightsInViewport(cm);
|
651 |
+
var barMeasure = measureForScrollbars(cm);
|
652 |
+
updateSelection(cm);
|
653 |
+
setDocumentHeight(cm, barMeasure);
|
654 |
+
updateScrollbars(cm, barMeasure);
|
655 |
+
}
|
656 |
+
|
657 |
+
signalLater(cm, "update", cm);
|
658 |
+
if (cm.display.viewFrom != update.oldViewFrom || cm.display.viewTo != update.oldViewTo)
|
659 |
+
signalLater(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
|
660 |
+
}
|
661 |
+
|
662 |
+
function updateDisplaySimple(cm, viewport) {
|
663 |
+
var update = new DisplayUpdate(cm, viewport);
|
664 |
+
if (updateDisplayIfNeeded(cm, update)) {
|
665 |
+
postUpdateDisplay(cm, update);
|
666 |
+
var barMeasure = measureForScrollbars(cm);
|
667 |
+
updateSelection(cm);
|
668 |
+
setDocumentHeight(cm, barMeasure);
|
669 |
+
updateScrollbars(cm, barMeasure);
|
670 |
+
}
|
671 |
+
}
|
672 |
+
|
673 |
+
function setDocumentHeight(cm, measure) {
|
674 |
+
cm.display.sizer.style.minHeight = cm.display.heightForcer.style.top = measure.docHeight + "px";
|
675 |
+
cm.display.gutters.style.height = Math.max(measure.docHeight, measure.clientHeight - scrollerCutOff) + "px";
|
676 |
+
}
|
677 |
+
|
678 |
+
function checkForWebkitWidthBug(cm, measure) {
|
679 |
+
// Work around Webkit bug where it sometimes reserves space for a
|
680 |
+
// non-existing phantom scrollbar in the scroller (Issue #2420)
|
681 |
+
if (cm.display.sizer.offsetWidth + cm.display.gutters.offsetWidth < cm.display.scroller.clientWidth - 1) {
|
682 |
+
cm.display.sizer.style.minHeight = cm.display.heightForcer.style.top = "0px";
|
683 |
+
cm.display.gutters.style.height = measure.docHeight + "px";
|
684 |
+
}
|
685 |
+
}
|
686 |
+
|
687 |
+
// Read the actual heights of the rendered lines, and update their
|
688 |
+
// stored heights to match.
|
689 |
+
function updateHeightsInViewport(cm) {
|
690 |
+
var display = cm.display;
|
691 |
+
var prevBottom = display.lineDiv.offsetTop;
|
692 |
+
for (var i = 0; i < display.view.length; i++) {
|
693 |
+
var cur = display.view[i], height;
|
694 |
+
if (cur.hidden) continue;
|
695 |
+
if (ie && ie_version < 8) {
|
696 |
+
var bot = cur.node.offsetTop + cur.node.offsetHeight;
|
697 |
+
height = bot - prevBottom;
|
698 |
+
prevBottom = bot;
|
699 |
+
} else {
|
700 |
+
var box = cur.node.getBoundingClientRect();
|
701 |
+
height = box.bottom - box.top;
|
702 |
+
}
|
703 |
+
var diff = cur.line.height - height;
|
704 |
+
if (height < 2) height = textHeight(display);
|
705 |
+
if (diff > .001 || diff < -.001) {
|
706 |
+
updateLineHeight(cur.line, height);
|
707 |
+
updateWidgetHeight(cur.line);
|
708 |
+
if (cur.rest) for (var j = 0; j < cur.rest.length; j++)
|
709 |
+
updateWidgetHeight(cur.rest[j]);
|
710 |
+
}
|
711 |
+
}
|
712 |
+
}
|
713 |
+
|
714 |
+
// Read and store the height of line widgets associated with the
|
715 |
+
// given line.
|
716 |
+
function updateWidgetHeight(line) {
|
717 |
+
if (line.widgets) for (var i = 0; i < line.widgets.length; ++i)
|
718 |
+
line.widgets[i].height = line.widgets[i].node.offsetHeight;
|
719 |
+
}
|
720 |
+
|
721 |
+
// Do a bulk-read of the DOM positions and sizes needed to draw the
|
722 |
+
// view, so that we don't interleave reading and writing to the DOM.
|
723 |
+
function getDimensions(cm) {
|
724 |
+
var d = cm.display, left = {}, width = {};
|
725 |
+
for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
|
726 |
+
left[cm.options.gutters[i]] = n.offsetLeft;
|
727 |
+
width[cm.options.gutters[i]] = n.offsetWidth;
|
728 |
+
}
|
729 |
+
return {fixedPos: compensateForHScroll(d),
|
730 |
+
gutterTotalWidth: d.gutters.offsetWidth,
|
731 |
+
gutterLeft: left,
|
732 |
+
gutterWidth: width,
|
733 |
+
wrapperWidth: d.wrapper.clientWidth};
|
734 |
+
}
|
735 |
+
|
736 |
+
// Sync the actual display DOM structure with display.view, removing
|
737 |
+
// nodes for lines that are no longer in view, and creating the ones
|
738 |
+
// that are not there yet, and updating the ones that are out of
|
739 |
+
// date.
|
740 |
+
function patchDisplay(cm, updateNumbersFrom, dims) {
|
741 |
+
var display = cm.display, lineNumbers = cm.options.lineNumbers;
|
742 |
+
var container = display.lineDiv, cur = container.firstChild;
|
743 |
+
|
744 |
+
function rm(node) {
|
745 |
+
var next = node.nextSibling;
|
746 |
+
// Works around a throw-scroll bug in OS X Webkit
|
747 |
+
if (webkit && mac && cm.display.currentWheelTarget == node)
|
748 |
+
node.style.display = "none";
|
749 |
+
else
|
750 |
+
node.parentNode.removeChild(node);
|
751 |
+
return next;
|
752 |
+
}
|
753 |
+
|
754 |
+
var view = display.view, lineN = display.viewFrom;
|
755 |
+
// Loop over the elements in the view, syncing cur (the DOM nodes
|
756 |
+
// in display.lineDiv) with the view as we go.
|
757 |
+
for (var i = 0; i < view.length; i++) {
|
758 |
+
var lineView = view[i];
|
759 |
+
if (lineView.hidden) {
|
760 |
+
} else if (!lineView.node) { // Not drawn yet
|
761 |
+
var node = buildLineElement(cm, lineView, lineN, dims);
|
762 |
+
container.insertBefore(node, cur);
|
763 |
+
} else { // Already drawn
|
764 |
+
while (cur != lineView.node) cur = rm(cur);
|
765 |
+
var updateNumber = lineNumbers && updateNumbersFrom != null &&
|
766 |
+
updateNumbersFrom <= lineN && lineView.lineNumber;
|
767 |
+
if (lineView.changes) {
|
768 |
+
if (indexOf(lineView.changes, "gutter") > -1) updateNumber = false;
|
769 |
+
updateLineForChanges(cm, lineView, lineN, dims);
|
770 |
+
}
|
771 |
+
if (updateNumber) {
|
772 |
+
removeChildren(lineView.lineNumber);
|
773 |
+
lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
|
774 |
+
}
|
775 |
+
cur = lineView.node.nextSibling;
|
776 |
+
}
|
777 |
+
lineN += lineView.size;
|
778 |
+
}
|
779 |
+
while (cur) cur = rm(cur);
|
780 |
+
}
|
781 |
+
|
782 |
+
// When an aspect of a line changes, a string is added to
|
783 |
+
// lineView.changes. This updates the relevant part of the line's
|
784 |
+
// DOM structure.
|
785 |
+
function updateLineForChanges(cm, lineView, lineN, dims) {
|
786 |
+
for (var j = 0; j < lineView.changes.length; j++) {
|
787 |
+
var type = lineView.changes[j];
|
788 |
+
if (type == "text") updateLineText(cm, lineView);
|
789 |
+
else if (type == "gutter") updateLineGutter(cm, lineView, lineN, dims);
|
790 |
+
else if (type == "class") updateLineClasses(lineView);
|
791 |
+
else if (type == "widget") updateLineWidgets(lineView, dims);
|
792 |
+
}
|
793 |
+
lineView.changes = null;
|
794 |
+
}
|
795 |
+
|
796 |
+
// Lines with gutter elements, widgets or a background class need to
|
797 |
+
// be wrapped, and have the extra elements added to the wrapper div
|
798 |
+
function ensureLineWrapped(lineView) {
|
799 |
+
if (lineView.node == lineView.text) {
|
800 |
+
lineView.node = elt("div", null, null, "position: relative");
|
801 |
+
if (lineView.text.parentNode)
|
802 |
+
lineView.text.parentNode.replaceChild(lineView.node, lineView.text);
|
803 |
+
lineView.node.appendChild(lineView.text);
|
804 |
+
if (ie && ie_version < 8) lineView.node.style.zIndex = 2;
|
805 |
+
}
|
806 |
+
return lineView.node;
|
807 |
+
}
|
808 |
+
|
809 |
+
function updateLineBackground(lineView) {
|
810 |
+
var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
|
811 |
+
if (cls) cls += " CodeMirror-linebackground";
|
812 |
+
if (lineView.background) {
|
813 |
+
if (cls) lineView.background.className = cls;
|
814 |
+
else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null; }
|
815 |
+
} else if (cls) {
|
816 |
+
var wrap = ensureLineWrapped(lineView);
|
817 |
+
lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
|
818 |
+
}
|
819 |
+
}
|
820 |
+
|
821 |
+
// Wrapper around buildLineContent which will reuse the structure
|
822 |
+
// in display.externalMeasured when possible.
|
823 |
+
function getLineContent(cm, lineView) {
|
824 |
+
var ext = cm.display.externalMeasured;
|
825 |
+
if (ext && ext.line == lineView.line) {
|
826 |
+
cm.display.externalMeasured = null;
|
827 |
+
lineView.measure = ext.measure;
|
828 |
+
return ext.built;
|
829 |
+
}
|
830 |
+
return buildLineContent(cm, lineView);
|
831 |
+
}
|
832 |
+
|
833 |
+
// Redraw the line's text. Interacts with the background and text
|
834 |
+
// classes because the mode may output tokens that influence these
|
835 |
+
// classes.
|
836 |
+
function updateLineText(cm, lineView) {
|
837 |
+
var cls = lineView.text.className;
|
838 |
+
var built = getLineContent(cm, lineView);
|
839 |
+
if (lineView.text == lineView.node) lineView.node = built.pre;
|
840 |
+
lineView.text.parentNode.replaceChild(built.pre, lineView.text);
|
841 |
+
lineView.text = built.pre;
|
842 |
+
if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
|
843 |
+
lineView.bgClass = built.bgClass;
|
844 |
+
lineView.textClass = built.textClass;
|
845 |
+
updateLineClasses(lineView);
|
846 |
+
} else if (cls) {
|
847 |
+
lineView.text.className = cls;
|
848 |
+
}
|
849 |
+
}
|
850 |
+
|
851 |
+
function updateLineClasses(lineView) {
|
852 |
+
updateLineBackground(lineView);
|
853 |
+
if (lineView.line.wrapClass)
|
854 |
+
ensureLineWrapped(lineView).className = lineView.line.wrapClass;
|
855 |
+
else if (lineView.node != lineView.text)
|
856 |
+
lineView.node.className = "";
|
857 |
+
var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
|
858 |
+
lineView.text.className = textClass || "";
|
859 |
+
}
|
860 |
+
|
861 |
+
function updateLineGutter(cm, lineView, lineN, dims) {
|
862 |
+
if (lineView.gutter) {
|
863 |
+
lineView.node.removeChild(lineView.gutter);
|
864 |
+
lineView.gutter = null;
|
865 |
+
}
|
866 |
+
var markers = lineView.line.gutterMarkers;
|
867 |
+
if (cm.options.lineNumbers || markers) {
|
868 |
+
var wrap = ensureLineWrapped(lineView);
|
869 |
+
var gutterWrap = lineView.gutter =
|
870 |
+
wrap.insertBefore(elt("div", null, "CodeMirror-gutter-wrapper", "position: absolute; left: " +
|
871 |
+
(cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"),
|
872 |
+
lineView.text);
|
873 |
+
if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
|
874 |
+
lineView.lineNumber = gutterWrap.appendChild(
|
875 |
+
elt("div", lineNumberFor(cm.options, lineN),
|
876 |
+
"CodeMirror-linenumber CodeMirror-gutter-elt",
|
877 |
+
"left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: "
|
878 |
+
+ cm.display.lineNumInnerWidth + "px"));
|
879 |
+
if (markers) for (var k = 0; k < cm.options.gutters.length; ++k) {
|
880 |
+
var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id];
|
881 |
+
if (found)
|
882 |
+
gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", "left: " +
|
883 |
+
dims.gutterLeft[id] + "px; width: " + dims.gutterWidth[id] + "px"));
|
884 |
+
}
|
885 |
+
}
|
886 |
+
}
|
887 |
+
|
888 |
+
function updateLineWidgets(lineView, dims) {
|
889 |
+
if (lineView.alignable) lineView.alignable = null;
|
890 |
+
for (var node = lineView.node.firstChild, next; node; node = next) {
|
891 |
+
var next = node.nextSibling;
|
892 |
+
if (node.className == "CodeMirror-linewidget")
|
893 |
+
lineView.node.removeChild(node);
|
894 |
+
}
|
895 |
+
insertLineWidgets(lineView, dims);
|
896 |
+
}
|
897 |
+
|
898 |
+
// Build a line's DOM representation from scratch
|
899 |
+
function buildLineElement(cm, lineView, lineN, dims) {
|
900 |
+
var built = getLineContent(cm, lineView);
|
901 |
+
lineView.text = lineView.node = built.pre;
|
902 |
+
if (built.bgClass) lineView.bgClass = built.bgClass;
|
903 |
+
if (built.textClass) lineView.textClass = built.textClass;
|
904 |
+
|
905 |
+
updateLineClasses(lineView);
|
906 |
+
updateLineGutter(cm, lineView, lineN, dims);
|
907 |
+
insertLineWidgets(lineView, dims);
|
908 |
+
return lineView.node;
|
909 |
+
}
|
910 |
+
|
911 |
+
// A lineView may contain multiple logical lines (when merged by
|
912 |
+
// collapsed spans). The widgets for all of them need to be drawn.
|
913 |
+
function insertLineWidgets(lineView, dims) {
|
914 |
+
insertLineWidgetsFor(lineView.line, lineView, dims, true);
|
915 |
+
if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++)
|
916 |
+
insertLineWidgetsFor(lineView.rest[i], lineView, dims, false);
|
917 |
+
}
|
918 |
+
|
919 |
+
function insertLineWidgetsFor(line, lineView, dims, allowAbove) {
|
920 |
+
if (!line.widgets) return;
|
921 |
+
var wrap = ensureLineWrapped(lineView);
|
922 |
+
for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
|
923 |
+
var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
|
924 |
+
if (!widget.handleMouseEvents) node.ignoreEvents = true;
|
925 |
+
positionLineWidget(widget, node, lineView, dims);
|
926 |
+
if (allowAbove && widget.above)
|
927 |
+
wrap.insertBefore(node, lineView.gutter || lineView.text);
|
928 |
+
else
|
929 |
+
wrap.appendChild(node);
|
930 |
+
signalLater(widget, "redraw");
|
931 |
+
}
|
932 |
+
}
|
933 |
+
|
934 |
+
function positionLineWidget(widget, node, lineView, dims) {
|
935 |
+
if (widget.noHScroll) {
|
936 |
+
(lineView.alignable || (lineView.alignable = [])).push(node);
|
937 |
+
var width = dims.wrapperWidth;
|
938 |
+
node.style.left = dims.fixedPos + "px";
|
939 |
+
if (!widget.coverGutter) {
|
940 |
+
width -= dims.gutterTotalWidth;
|
941 |
+
node.style.paddingLeft = dims.gutterTotalWidth + "px";
|
942 |
+
}
|
943 |
+
node.style.width = width + "px";
|
944 |
+
}
|
945 |
+
if (widget.coverGutter) {
|
946 |
+
node.style.zIndex = 5;
|
947 |
+
node.style.position = "relative";
|
948 |
+
if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px";
|
949 |
+
}
|
950 |
+
}
|
951 |
+
|
952 |
+
// POSITION OBJECT
|
953 |
+
|
954 |
+
// A Pos instance represents a position within the text.
|
955 |
+
var Pos = CodeMirror.Pos = function(line, ch) {
|
956 |
+
if (!(this instanceof Pos)) return new Pos(line, ch);
|
957 |
+
this.line = line; this.ch = ch;
|
958 |
+
};
|
959 |
+
|
960 |
+
// Compare two positions, return 0 if they are the same, a negative
|
961 |
+
// number when a is less, and a positive number otherwise.
|
962 |
+
var cmp = CodeMirror.cmpPos = function(a, b) { return a.line - b.line || a.ch - b.ch; };
|
963 |
+
|
964 |
+
function copyPos(x) {return Pos(x.line, x.ch);}
|
965 |
+
function maxPos(a, b) { return cmp(a, b) < 0 ? b : a; }
|
966 |
+
function minPos(a, b) { return cmp(a, b) < 0 ? a : b; }
|
967 |
+
|
968 |
+
// SELECTION / CURSOR
|
969 |
+
|
970 |
+
// Selection objects are immutable. A new one is created every time
|
971 |
+
// the selection changes. A selection is one or more non-overlapping
|
972 |
+
// (and non-touching) ranges, sorted, and an integer that indicates
|
973 |
+
// which one is the primary selection (the one that's scrolled into
|
974 |
+
// view, that getCursor returns, etc).
|
975 |
+
function Selection(ranges, primIndex) {
|
976 |
+
this.ranges = ranges;
|
977 |
+
this.primIndex = primIndex;
|
978 |
+
}
|
979 |
+
|
980 |
+
Selection.prototype = {
|
981 |
+
primary: function() { return this.ranges[this.primIndex]; },
|
982 |
+
equals: function(other) {
|
983 |
+
if (other == this) return true;
|
984 |
+
if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) return false;
|
985 |
+
for (var i = 0; i < this.ranges.length; i++) {
|
986 |
+
var here = this.ranges[i], there = other.ranges[i];
|
987 |
+
if (cmp(here.anchor, there.anchor) != 0 || cmp(here.head, there.head) != 0) return false;
|
988 |
+
}
|
989 |
+
return true;
|
990 |
+
},
|
991 |
+
deepCopy: function() {
|
992 |
+
for (var out = [], i = 0; i < this.ranges.length; i++)
|
993 |
+
out[i] = new Range(copyPos(this.ranges[i].anchor), copyPos(this.ranges[i].head));
|
994 |
+
return new Selection(out, this.primIndex);
|
995 |
+
},
|
996 |
+
somethingSelected: function() {
|
997 |
+
for (var i = 0; i < this.ranges.length; i++)
|
998 |
+
if (!this.ranges[i].empty()) return true;
|
999 |
+
return false;
|
1000 |
+
},
|
1001 |
+
contains: function(pos, end) {
|
1002 |
+
if (!end) end = pos;
|
1003 |
+
for (var i = 0; i < this.ranges.length; i++) {
|
1004 |
+
var range = this.ranges[i];
|
1005 |
+
if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
|
1006 |
+
return i;
|
1007 |
+
}
|
1008 |
+
return -1;
|
1009 |
+
}
|
1010 |
+
};
|
1011 |
+
|
1012 |
+
function Range(anchor, head) {
|
1013 |
+
this.anchor = anchor; this.head = head;
|
1014 |
+
}
|
1015 |
+
|
1016 |
+
Range.prototype = {
|
1017 |
+
from: function() { return minPos(this.anchor, this.head); },
|
1018 |
+
to: function() { return maxPos(this.anchor, this.head); },
|
1019 |
+
empty: function() {
|
1020 |
+
return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch;
|
1021 |
+
}
|
1022 |
+
};
|
1023 |
+
|
1024 |
+
// Take an unsorted, potentially overlapping set of ranges, and
|
1025 |
+
// build a selection out of it. 'Consumes' ranges array (modifying
|
1026 |
+
// it).
|
1027 |
+
function normalizeSelection(ranges, primIndex) {
|
1028 |
+
var prim = ranges[primIndex];
|
1029 |
+
ranges.sort(function(a, b) { return cmp(a.from(), b.from()); });
|
1030 |
+
primIndex = indexOf(ranges, prim);
|
1031 |
+
for (var i = 1; i < ranges.length; i++) {
|
1032 |
+
var cur = ranges[i], prev = ranges[i - 1];
|
1033 |
+
if (cmp(prev.to(), cur.from()) >= 0) {
|
1034 |
+
var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
|
1035 |
+
var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
|
1036 |
+
if (i <= primIndex) --primIndex;
|
1037 |
+
ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
|
1038 |
+
}
|
1039 |
+
}
|
1040 |
+
return new Selection(ranges, primIndex);
|
1041 |
+
}
|
1042 |
+
|
1043 |
+
function simpleSelection(anchor, head) {
|
1044 |
+
return new Selection([new Range(anchor, head || anchor)], 0);
|
1045 |
+
}
|
1046 |
+
|
1047 |
+
// Most of the external API clips given positions to make sure they
|
1048 |
+
// actually exist within the document.
|
1049 |
+
function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1));}
|
1050 |
+
function clipPos(doc, pos) {
|
1051 |
+
if (pos.line < doc.first) return Pos(doc.first, 0);
|
1052 |
+
var last = doc.first + doc.size - 1;
|
1053 |
+
if (pos.line > last) return Pos(last, getLine(doc, last).text.length);
|
1054 |
+
return clipToLen(pos, getLine(doc, pos.line).text.length);
|
1055 |
+
}
|
1056 |
+
function clipToLen(pos, linelen) {
|
1057 |
+
var ch = pos.ch;
|
1058 |
+
if (ch == null || ch > linelen) return Pos(pos.line, linelen);
|
1059 |
+
else if (ch < 0) return Pos(pos.line, 0);
|
1060 |
+
else return pos;
|
1061 |
+
}
|
1062 |
+
function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size;}
|
1063 |
+
function clipPosArray(doc, array) {
|
1064 |
+
for (var out = [], i = 0; i < array.length; i++) out[i] = clipPos(doc, array[i]);
|
1065 |
+
return out;
|
1066 |
+
}
|
1067 |
+
|
1068 |
+
// SELECTION UPDATES
|
1069 |
+
|
1070 |
+
// The 'scroll' parameter given to many of these indicated whether
|
1071 |
+
// the new cursor position should be scrolled into view after
|
1072 |
+
// modifying the selection.
|
1073 |
+
|
1074 |
+
// If shift is held or the extend flag is set, extends a range to
|
1075 |
+
// include a given position (and optionally a second position).
|
1076 |
+
// Otherwise, simply returns the range between the given positions.
|
1077 |
+
// Used for cursor motion and such.
|
1078 |
+
function extendRange(doc, range, head, other) {
|
1079 |
+
if (doc.cm && doc.cm.display.shift || doc.extend) {
|
1080 |
+
var anchor = range.anchor;
|
1081 |
+
if (other) {
|
1082 |
+
var posBefore = cmp(head, anchor) < 0;
|
1083 |
+
if (posBefore != (cmp(other, anchor) < 0)) {
|
1084 |
+
anchor = head;
|
1085 |
+
head = other;
|
1086 |
+
} else if (posBefore != (cmp(head, other) < 0)) {
|
1087 |
+
head = other;
|
1088 |
+
}
|
1089 |
+
}
|
1090 |
+
return new Range(anchor, head);
|
1091 |
+
} else {
|
1092 |
+
return new Range(other || head, head);
|
1093 |
+
}
|
1094 |
+
}
|
1095 |
+
|
1096 |
+
// Extend the primary selection range, discard the rest.
|
1097 |
+
function extendSelection(doc, head, other, options) {
|
1098 |
+
setSelection(doc, new Selection([extendRange(doc, doc.sel.primary(), head, other)], 0), options);
|
1099 |
+
}
|
1100 |
+
|
1101 |
+
// Extend all selections (pos is an array of selections with length
|
1102 |
+
// equal the number of selections)
|
1103 |
+
function extendSelections(doc, heads, options) {
|
1104 |
+
for (var out = [], i = 0; i < doc.sel.ranges.length; i++)
|
1105 |
+
out[i] = extendRange(doc, doc.sel.ranges[i], heads[i], null);
|
1106 |
+
var newSel = normalizeSelection(out, doc.sel.primIndex);
|
1107 |
+
setSelection(doc, newSel, options);
|
1108 |
+
}
|
1109 |
+
|
1110 |
+
// Updates a single range in the selection.
|
1111 |
+
function replaceOneSelection(doc, i, range, options) {
|
1112 |
+
var ranges = doc.sel.ranges.slice(0);
|
1113 |
+
ranges[i] = range;
|
1114 |
+
setSelection(doc, normalizeSelection(ranges, doc.sel.primIndex), options);
|
1115 |
+
}
|
1116 |
+
|
1117 |
+
// Reset the selection to a single range.
|
1118 |
+
function setSimpleSelection(doc, anchor, head, options) {
|
1119 |
+
setSelection(doc, simpleSelection(anchor, head), options);
|
1120 |
+
}
|
1121 |
+
|
1122 |
+
// Give beforeSelectionChange handlers a change to influence a
|
1123 |
+
// selection update.
|
1124 |
+
function filterSelectionChange(doc, sel) {
|
1125 |
+
var obj = {
|
1126 |
+
ranges: sel.ranges,
|
1127 |
+
update: function(ranges) {
|
1128 |
+
this.ranges = [];
|
1129 |
+
for (var i = 0; i < ranges.length; i++)
|
1130 |
+
this.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
|
1131 |
+
clipPos(doc, ranges[i].head));
|
1132 |
+
}
|
1133 |
+
};
|
1134 |
+
signal(doc, "beforeSelectionChange", doc, obj);
|
1135 |
+
if (doc.cm) signal(doc.cm, "beforeSelectionChange", doc.cm, obj);
|
1136 |
+
if (obj.ranges != sel.ranges) return normalizeSelection(obj.ranges, obj.ranges.length - 1);
|
1137 |
+
else return sel;
|
1138 |
+
}
|
1139 |
+
|
1140 |
+
function setSelectionReplaceHistory(doc, sel, options) {
|
1141 |
+
var done = doc.history.done, last = lst(done);
|
1142 |
+
if (last && last.ranges) {
|
1143 |
+
done[done.length - 1] = sel;
|
1144 |
+
setSelectionNoUndo(doc, sel, options);
|
1145 |
+
} else {
|
1146 |
+
setSelection(doc, sel, options);
|
1147 |
+
}
|
1148 |
+
}
|
1149 |
+
|
1150 |
+
// Set a new selection.
|
1151 |
+
function setSelection(doc, sel, options) {
|
1152 |
+
setSelectionNoUndo(doc, sel, options);
|
1153 |
+
addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);
|
1154 |
+
}
|
1155 |
+
|
1156 |
+
function setSelectionNoUndo(doc, sel, options) {
|
1157 |
+
if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
|
1158 |
+
sel = filterSelectionChange(doc, sel);
|
1159 |
+
|
1160 |
+
var bias = options && options.bias ||
|
1161 |
+
(cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
|
1162 |
+
setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
|
1163 |
+
|
1164 |
+
if (!(options && options.scroll === false) && doc.cm)
|
1165 |
+
ensureCursorVisible(doc.cm);
|
1166 |
+
}
|
1167 |
+
|
1168 |
+
function setSelectionInner(doc, sel) {
|
1169 |
+
if (sel.equals(doc.sel)) return;
|
1170 |
+
|
1171 |
+
doc.sel = sel;
|
1172 |
+
|
1173 |
+
if (doc.cm) {
|
1174 |
+
doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true;
|
1175 |
+
signalCursorActivity(doc.cm);
|
1176 |
+
}
|
1177 |
+
signalLater(doc, "cursorActivity", doc);
|
1178 |
+
}
|
1179 |
+
|
1180 |
+
// Verify that the selection does not partially select any atomic
|
1181 |
+
// marked ranges.
|
1182 |
+
function reCheckSelection(doc) {
|
1183 |
+
setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false), sel_dontScroll);
|
1184 |
+
}
|
1185 |
+
|
1186 |
+
// Return a selection that does not partially select any atomic
|
1187 |
+
// ranges.
|
1188 |
+
function skipAtomicInSelection(doc, sel, bias, mayClear) {
|
1189 |
+
var out;
|
1190 |
+
for (var i = 0; i < sel.ranges.length; i++) {
|
1191 |
+
var range = sel.ranges[i];
|
1192 |
+
var newAnchor = skipAtomic(doc, range.anchor, bias, mayClear);
|
1193 |
+
var newHead = skipAtomic(doc, range.head, bias, mayClear);
|
1194 |
+
if (out || newAnchor != range.anchor || newHead != range.head) {
|
1195 |
+
if (!out) out = sel.ranges.slice(0, i);
|
1196 |
+
out[i] = new Range(newAnchor, newHead);
|
1197 |
+
}
|
1198 |
+
}
|
1199 |
+
return out ? normalizeSelection(out, sel.primIndex) : sel;
|
1200 |
+
}
|
1201 |
+
|
1202 |
+
// Ensure a given position is not inside an atomic range.
|
1203 |
+
function skipAtomic(doc, pos, bias, mayClear) {
|
1204 |
+
var flipped = false, curPos = pos;
|
1205 |
+
var dir = bias || 1;
|
1206 |
+
doc.cantEdit = false;
|
1207 |
+
search: for (;;) {
|
1208 |
+
var line = getLine(doc, curPos.line);
|
1209 |
+
if (line.markedSpans) {
|
1210 |
+
for (var i = 0; i < line.markedSpans.length; ++i) {
|
1211 |
+
var sp = line.markedSpans[i], m = sp.marker;
|
1212 |
+
if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) &&
|
1213 |
+
(sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) {
|
1214 |
+
if (mayClear) {
|
1215 |
+
signal(m, "beforeCursorEnter");
|
1216 |
+
if (m.explicitlyCleared) {
|
1217 |
+
if (!line.markedSpans) break;
|
1218 |
+
else {--i; continue;}
|
1219 |
+
}
|
1220 |
+
}
|
1221 |
+
if (!m.atomic) continue;
|
1222 |
+
var newPos = m.find(dir < 0 ? -1 : 1);
|
1223 |
+
if (cmp(newPos, curPos) == 0) {
|
1224 |
+
newPos.ch += dir;
|
1225 |
+
if (newPos.ch < 0) {
|
1226 |
+
if (newPos.line > doc.first) newPos = clipPos(doc, Pos(newPos.line - 1));
|
1227 |
+
else newPos = null;
|
1228 |
+
} else if (newPos.ch > line.text.length) {
|
1229 |
+
if (newPos.line < doc.first + doc.size - 1) newPos = Pos(newPos.line + 1, 0);
|
1230 |
+
else newPos = null;
|
1231 |
+
}
|
1232 |
+
if (!newPos) {
|
1233 |
+
if (flipped) {
|
1234 |
+
// Driven in a corner -- no valid cursor position found at all
|
1235 |
+
// -- try again *with* clearing, if we didn't already
|
1236 |
+
if (!mayClear) return skipAtomic(doc, pos, bias, true);
|
1237 |
+
// Otherwise, turn off editing until further notice, and return the start of the doc
|
1238 |
+
doc.cantEdit = true;
|
1239 |
+
return Pos(doc.first, 0);
|
1240 |
+
}
|
1241 |
+
flipped = true; newPos = pos; dir = -dir;
|
1242 |
+
}
|
1243 |
+
}
|
1244 |
+
curPos = newPos;
|
1245 |
+
continue search;
|
1246 |
+
}
|
1247 |
+
}
|
1248 |
+
}
|
1249 |
+
return curPos;
|
1250 |
+
}
|
1251 |
+
}
|
1252 |
+
|
1253 |
+
// SELECTION DRAWING
|
1254 |
+
|
1255 |
+
// Redraw the selection and/or cursor
|
1256 |
+
function drawSelection(cm) {
|
1257 |
+
var display = cm.display, doc = cm.doc, result = {};
|
1258 |
+
var curFragment = result.cursors = document.createDocumentFragment();
|
1259 |
+
var selFragment = result.selection = document.createDocumentFragment();
|
1260 |
+
|
1261 |
+
for (var i = 0; i < doc.sel.ranges.length; i++) {
|
1262 |
+
var range = doc.sel.ranges[i];
|
1263 |
+
var collapsed = range.empty();
|
1264 |
+
if (collapsed || cm.options.showCursorWhenSelecting)
|
1265 |
+
drawSelectionCursor(cm, range, curFragment);
|
1266 |
+
if (!collapsed)
|
1267 |
+
drawSelectionRange(cm, range, selFragment);
|
1268 |
+
}
|
1269 |
+
|
1270 |
+
// Move the hidden textarea near the cursor to prevent scrolling artifacts
|
1271 |
+
if (cm.options.moveInputWithCursor) {
|
1272 |
+
var headPos = cursorCoords(cm, doc.sel.primary().head, "div");
|
1273 |
+
var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
|
1274 |
+
result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
|
1275 |
+
headPos.top + lineOff.top - wrapOff.top));
|
1276 |
+
result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
|
1277 |
+
headPos.left + lineOff.left - wrapOff.left));
|
1278 |
+
}
|
1279 |
+
|
1280 |
+
return result;
|
1281 |
+
}
|
1282 |
+
|
1283 |
+
function updateSelection(cm, drawn) {
|
1284 |
+
if (!drawn) drawn = drawSelection(cm);
|
1285 |
+
removeChildrenAndAdd(cm.display.cursorDiv, drawn.cursors);
|
1286 |
+
removeChildrenAndAdd(cm.display.selectionDiv, drawn.selection);
|
1287 |
+
if (drawn.teTop != null) {
|
1288 |
+
cm.display.inputDiv.style.top = drawn.teTop + "px";
|
1289 |
+
cm.display.inputDiv.style.left = drawn.teLeft + "px";
|
1290 |
+
}
|
1291 |
+
}
|
1292 |
+
|
1293 |
+
// Draws a cursor for the given range
|
1294 |
+
function drawSelectionCursor(cm, range, output) {
|
1295 |
+
var pos = cursorCoords(cm, range.head, "div", null, null, !cm.options.singleCursorHeightPerLine);
|
1296 |
+
|
1297 |
+
var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
|
1298 |
+
cursor.style.left = pos.left + "px";
|
1299 |
+
cursor.style.top = pos.top + "px";
|
1300 |
+
cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
|
1301 |
+
|
1302 |
+
if (pos.other) {
|
1303 |
+
// Secondary cursor, shown when on a 'jump' in bi-directional text
|
1304 |
+
var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
|
1305 |
+
otherCursor.style.display = "";
|
1306 |
+
otherCursor.style.left = pos.other.left + "px";
|
1307 |
+
otherCursor.style.top = pos.other.top + "px";
|
1308 |
+
otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
|
1309 |
+
}
|
1310 |
+
}
|
1311 |
+
|
1312 |
+
// Draws the given range as a highlighted selection
|
1313 |
+
function drawSelectionRange(cm, range, output) {
|
1314 |
+
var display = cm.display, doc = cm.doc;
|
1315 |
+
var fragment = document.createDocumentFragment();
|
1316 |
+
var padding = paddingH(cm.display), leftSide = padding.left, rightSide = display.lineSpace.offsetWidth - padding.right;
|
1317 |
+
|
1318 |
+
function add(left, top, width, bottom) {
|
1319 |
+
if (top < 0) top = 0;
|
1320 |
+
top = Math.round(top);
|
1321 |
+
bottom = Math.round(bottom);
|
1322 |
+
fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
|
1323 |
+
"px; top: " + top + "px; width: " + (width == null ? rightSide - left : width) +
|
1324 |
+
"px; height: " + (bottom - top) + "px"));
|
1325 |
+
}
|
1326 |
+
|
1327 |
+
function drawForLine(line, fromArg, toArg) {
|
1328 |
+
var lineObj = getLine(doc, line);
|
1329 |
+
var lineLen = lineObj.text.length;
|
1330 |
+
var start, end;
|
1331 |
+
function coords(ch, bias) {
|
1332 |
+
return charCoords(cm, Pos(line, ch), "div", lineObj, bias);
|
1333 |
+
}
|
1334 |
+
|
1335 |
+
iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
|
1336 |
+
var leftPos = coords(from, "left"), rightPos, left, right;
|
1337 |
+
if (from == to) {
|
1338 |
+
rightPos = leftPos;
|
1339 |
+
left = right = leftPos.left;
|
1340 |
+
} else {
|
1341 |
+
rightPos = coords(to - 1, "right");
|
1342 |
+
if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp; }
|
1343 |
+
left = leftPos.left;
|
1344 |
+
right = rightPos.right;
|
1345 |
+
}
|
1346 |
+
if (fromArg == null && from == 0) left = leftSide;
|
1347 |
+
if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
|
1348 |
+
add(left, leftPos.top, null, leftPos.bottom);
|
1349 |
+
left = leftSide;
|
1350 |
+
if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
|
1351 |
+
}
|
1352 |
+
if (toArg == null && to == lineLen) right = rightSide;
|
1353 |
+
if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
|
1354 |
+
start = leftPos;
|
1355 |
+
if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
|
1356 |
+
end = rightPos;
|
1357 |
+
if (left < leftSide + 1) left = leftSide;
|
1358 |
+
add(left, rightPos.top, right - left, rightPos.bottom);
|
1359 |
+
});
|
1360 |
+
return {start: start, end: end};
|
1361 |
+
}
|
1362 |
+
|
1363 |
+
var sFrom = range.from(), sTo = range.to();
|
1364 |
+
if (sFrom.line == sTo.line) {
|
1365 |
+
drawForLine(sFrom.line, sFrom.ch, sTo.ch);
|
1366 |
+
} else {
|
1367 |
+
var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
|
1368 |
+
var singleVLine = visualLine(fromLine) == visualLine(toLine);
|
1369 |
+
var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
|
1370 |
+
var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
|
1371 |
+
if (singleVLine) {
|
1372 |
+
if (leftEnd.top < rightStart.top - 2) {
|
1373 |
+
add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
|
1374 |
+
add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
|
1375 |
+
} else {
|
1376 |
+
add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
|
1377 |
+
}
|
1378 |
+
}
|
1379 |
+
if (leftEnd.bottom < rightStart.top)
|
1380 |
+
add(leftSide, leftEnd.bottom, null, rightStart.top);
|
1381 |
+
}
|
1382 |
+
|
1383 |
+
output.appendChild(fragment);
|
1384 |
+
}
|
1385 |
+
|
1386 |
+
// Cursor-blinking
|
1387 |
+
function restartBlink(cm) {
|
1388 |
+
if (!cm.state.focused) return;
|
1389 |
+
var display = cm.display;
|
1390 |
+
clearInterval(display.blinker);
|
1391 |
+
var on = true;
|
1392 |
+
display.cursorDiv.style.visibility = "";
|
1393 |
+
if (cm.options.cursorBlinkRate > 0)
|
1394 |
+
display.blinker = setInterval(function() {
|
1395 |
+
display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden";
|
1396 |
+
}, cm.options.cursorBlinkRate);
|
1397 |
+
else if (cm.options.cursorBlinkRate < 0)
|
1398 |
+
display.cursorDiv.style.visibility = "hidden";
|
1399 |
+
}
|
1400 |
+
|
1401 |
+
// HIGHLIGHT WORKER
|
1402 |
+
|
1403 |
+
function startWorker(cm, time) {
|
1404 |
+
if (cm.doc.mode.startState && cm.doc.frontier < cm.display.viewTo)
|
1405 |
+
cm.state.highlight.set(time, bind(highlightWorker, cm));
|
1406 |
+
}
|
1407 |
+
|
1408 |
+
function highlightWorker(cm) {
|
1409 |
+
var doc = cm.doc;
|
1410 |
+
if (doc.frontier < doc.first) doc.frontier = doc.first;
|
1411 |
+
if (doc.frontier >= cm.display.viewTo) return;
|
1412 |
+
var end = +new Date + cm.options.workTime;
|
1413 |
+
var state = copyState(doc.mode, getStateBefore(cm, doc.frontier));
|
1414 |
+
var changedLines = [];
|
1415 |
+
|
1416 |
+
doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function(line) {
|
1417 |
+
if (doc.frontier >= cm.display.viewFrom) { // Visible
|
1418 |
+
var oldStyles = line.styles;
|
1419 |
+
var highlighted = highlightLine(cm, line, state, true);
|
1420 |
+
line.styles = highlighted.styles;
|
1421 |
+
var oldCls = line.styleClasses, newCls = highlighted.classes;
|
1422 |
+
if (newCls) line.styleClasses = newCls;
|
1423 |
+
else if (oldCls) line.styleClasses = null;
|
1424 |
+
var ischange = !oldStyles || oldStyles.length != line.styles.length ||
|
1425 |
+
oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
|
1426 |
+
for (var i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i];
|
1427 |
+
if (ischange) changedLines.push(doc.frontier);
|
1428 |
+
line.stateAfter = copyState(doc.mode, state);
|
1429 |
+
} else {
|
1430 |
+
processLine(cm, line.text, state);
|
1431 |
+
line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null;
|
1432 |
+
}
|
1433 |
+
++doc.frontier;
|
1434 |
+
if (+new Date > end) {
|
1435 |
+
startWorker(cm, cm.options.workDelay);
|
1436 |
+
return true;
|
1437 |
+
}
|
1438 |
+
});
|
1439 |
+
if (changedLines.length) runInOp(cm, function() {
|
1440 |
+
for (var i = 0; i < changedLines.length; i++)
|
1441 |
+
regLineChange(cm, changedLines[i], "text");
|
1442 |
+
});
|
1443 |
+
}
|
1444 |
+
|
1445 |
+
// Finds the line to start with when starting a parse. Tries to
|
1446 |
+
// find a line with a stateAfter, so that it can start with a
|
1447 |
+
// valid state. If that fails, it returns the line with the
|
1448 |
+
// smallest indentation, which tends to need the least context to
|
1449 |
+
// parse correctly.
|
1450 |
+
function findStartLine(cm, n, precise) {
|
1451 |
+
var minindent, minline, doc = cm.doc;
|
1452 |
+
var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
|
1453 |
+
for (var search = n; search > lim; --search) {
|
1454 |
+
if (search <= doc.first) return doc.first;
|
1455 |
+
var line = getLine(doc, search - 1);
|
1456 |
+
if (line.stateAfter && (!precise || search <= doc.frontier)) return search;
|
1457 |
+
var indented = countColumn(line.text, null, cm.options.tabSize);
|
1458 |
+
if (minline == null || minindent > indented) {
|
1459 |
+
minline = search - 1;
|
1460 |
+
minindent = indented;
|
1461 |
+
}
|
1462 |
+
}
|
1463 |
+
return minline;
|
1464 |
+
}
|
1465 |
+
|
1466 |
+
function getStateBefore(cm, n, precise) {
|
1467 |
+
var doc = cm.doc, display = cm.display;
|
1468 |
+
if (!doc.mode.startState) return true;
|
1469 |
+
var pos = findStartLine(cm, n, precise), state = pos > doc.first && getLine(doc, pos-1).stateAfter;
|
1470 |
+
if (!state) state = startState(doc.mode);
|
1471 |
+
else state = copyState(doc.mode, state);
|
1472 |
+
doc.iter(pos, n, function(line) {
|
1473 |
+
processLine(cm, line.text, state);
|
1474 |
+
var save = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo;
|
1475 |
+
line.stateAfter = save ? copyState(doc.mode, state) : null;
|
1476 |
+
++pos;
|
1477 |
+
});
|
1478 |
+
if (precise) doc.frontier = pos;
|
1479 |
+
return state;
|
1480 |
+
}
|
1481 |
+
|
1482 |
+
// POSITION MEASUREMENT
|
1483 |
+
|
1484 |
+
function paddingTop(display) {return display.lineSpace.offsetTop;}
|
1485 |
+
function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight;}
|
1486 |
+
function paddingH(display) {
|
1487 |
+
if (display.cachedPaddingH) return display.cachedPaddingH;
|
1488 |
+
var e = removeChildrenAndAdd(display.measure, elt("pre", "x"));
|
1489 |
+
var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
|
1490 |
+
var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)};
|
1491 |
+
if (!isNaN(data.left) && !isNaN(data.right)) display.cachedPaddingH = data;
|
1492 |
+
return data;
|
1493 |
+
}
|
1494 |
+
|
1495 |
+
// Ensure the lineView.wrapping.heights array is populated. This is
|
1496 |
+
// an array of bottom offsets for the lines that make up a drawn
|
1497 |
+
// line. When lineWrapping is on, there might be more than one
|
1498 |
+
// height.
|
1499 |
+
function ensureLineHeights(cm, lineView, rect) {
|
1500 |
+
var wrapping = cm.options.lineWrapping;
|
1501 |
+
var curWidth = wrapping && cm.display.scroller.clientWidth;
|
1502 |
+
if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
|
1503 |
+
var heights = lineView.measure.heights = [];
|
1504 |
+
if (wrapping) {
|
1505 |
+
lineView.measure.width = curWidth;
|
1506 |
+
var rects = lineView.text.firstChild.getClientRects();
|
1507 |
+
for (var i = 0; i < rects.length - 1; i++) {
|
1508 |
+
var cur = rects[i], next = rects[i + 1];
|
1509 |
+
if (Math.abs(cur.bottom - next.bottom) > 2)
|
1510 |
+
heights.push((cur.bottom + next.top) / 2 - rect.top);
|
1511 |
+
}
|
1512 |
+
}
|
1513 |
+
heights.push(rect.bottom - rect.top);
|
1514 |
+
}
|
1515 |
+
}
|
1516 |
+
|
1517 |
+
// Find a line map (mapping character offsets to text nodes) and a
|
1518 |
+
// measurement cache for the given line number. (A line view might
|
1519 |
+
// contain multiple lines when collapsed ranges are present.)
|
1520 |
+
function mapFromLineView(lineView, line, lineN) {
|
1521 |
+
if (lineView.line == line)
|
1522 |
+
return {map: lineView.measure.map, cache: lineView.measure.cache};
|
1523 |
+
for (var i = 0; i < lineView.rest.length; i++)
|
1524 |
+
if (lineView.rest[i] == line)
|
1525 |
+
return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]};
|
1526 |
+
for (var i = 0; i < lineView.rest.length; i++)
|
1527 |
+
if (lineNo(lineView.rest[i]) > lineN)
|
1528 |
+
return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i], before: true};
|
1529 |
+
}
|
1530 |
+
|
1531 |
+
// Render a line into the hidden node display.externalMeasured. Used
|
1532 |
+
// when measurement is needed for a line that's not in the viewport.
|
1533 |
+
function updateExternalMeasurement(cm, line) {
|
1534 |
+
line = visualLine(line);
|
1535 |
+
var lineN = lineNo(line);
|
1536 |
+
var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
|
1537 |
+
view.lineN = lineN;
|
1538 |
+
var built = view.built = buildLineContent(cm, view);
|
1539 |
+
view.text = built.pre;
|
1540 |
+
removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
|
1541 |
+
return view;
|
1542 |
+
}
|
1543 |
+
|
1544 |
+
// Get a {top, bottom, left, right} box (in line-local coordinates)
|
1545 |
+
// for a given character.
|
1546 |
+
function measureChar(cm, line, ch, bias) {
|
1547 |
+
return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias);
|
1548 |
+
}
|
1549 |
+
|
1550 |
+
// Find a line view that corresponds to the given line number.
|
1551 |
+
function findViewForLine(cm, lineN) {
|
1552 |
+
if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
|
1553 |
+
return cm.display.view[findViewIndex(cm, lineN)];
|
1554 |
+
var ext = cm.display.externalMeasured;
|
1555 |
+
if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
|
1556 |
+
return ext;
|
1557 |
+
}
|
1558 |
+
|
1559 |
+
// Measurement can be split in two steps, the set-up work that
|
1560 |
+
// applies to the whole line, and the measurement of the actual
|
1561 |
+
// character. Functions like coordsChar, that need to do a lot of
|
1562 |
+
// measurements in a row, can thus ensure that the set-up work is
|
1563 |
+
// only done once.
|
1564 |
+
function prepareMeasureForLine(cm, line) {
|
1565 |
+
var lineN = lineNo(line);
|
1566 |
+
var view = findViewForLine(cm, lineN);
|
1567 |
+
if (view && !view.text)
|
1568 |
+
view = null;
|
1569 |
+
else if (view && view.changes)
|
1570 |
+
updateLineForChanges(cm, view, lineN, getDimensions(cm));
|
1571 |
+
if (!view)
|
1572 |
+
view = updateExternalMeasurement(cm, line);
|
1573 |
+
|
1574 |
+
var info = mapFromLineView(view, line, lineN);
|
1575 |
+
return {
|
1576 |
+
line: line, view: view, rect: null,
|
1577 |
+
map: info.map, cache: info.cache, before: info.before,
|
1578 |
+
hasHeights: false
|
1579 |
+
};
|
1580 |
+
}
|
1581 |
+
|
1582 |
+
// Given a prepared measurement object, measures the position of an
|
1583 |
+
// actual character (or fetches it from the cache).
|
1584 |
+
function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
|
1585 |
+
if (prepared.before) ch = -1;
|
1586 |
+
var key = ch + (bias || ""), found;
|
1587 |
+
if (prepared.cache.hasOwnProperty(key)) {
|
1588 |
+
found = prepared.cache[key];
|
1589 |
+
} else {
|
1590 |
+
if (!prepared.rect)
|
1591 |
+
prepared.rect = prepared.view.text.getBoundingClientRect();
|
1592 |
+
if (!prepared.hasHeights) {
|
1593 |
+
ensureLineHeights(cm, prepared.view, prepared.rect);
|
1594 |
+
prepared.hasHeights = true;
|
1595 |
+
}
|
1596 |
+
found = measureCharInner(cm, prepared, ch, bias);
|
1597 |
+
if (!found.bogus) prepared.cache[key] = found;
|
1598 |
+
}
|
1599 |
+
return {left: found.left, right: found.right,
|
1600 |
+
top: varHeight ? found.rtop : found.top,
|
1601 |
+
bottom: varHeight ? found.rbottom : found.bottom};
|
1602 |
+
}
|
1603 |
+
|
1604 |
+
var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
|
1605 |
+
|
1606 |
+
function measureCharInner(cm, prepared, ch, bias) {
|
1607 |
+
var map = prepared.map;
|
1608 |
+
|
1609 |
+
var node, start, end, collapse;
|
1610 |
+
// First, search the line map for the text node corresponding to,
|
1611 |
+
// or closest to, the target character.
|
1612 |
+
for (var i = 0; i < map.length; i += 3) {
|
1613 |
+
var mStart = map[i], mEnd = map[i + 1];
|
1614 |
+
if (ch < mStart) {
|
1615 |
+
start = 0; end = 1;
|
1616 |
+
collapse = "left";
|
1617 |
+
} else if (ch < mEnd) {
|
1618 |
+
start = ch - mStart;
|
1619 |
+
end = start + 1;
|
1620 |
+
} else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
|
1621 |
+
end = mEnd - mStart;
|
1622 |
+
start = end - 1;
|
1623 |
+
if (ch >= mEnd) collapse = "right";
|
1624 |
+
}
|
1625 |
+
if (start != null) {
|
1626 |
+
node = map[i + 2];
|
1627 |
+
if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
|
1628 |
+
collapse = bias;
|
1629 |
+
if (bias == "left" && start == 0)
|
1630 |
+
while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
|
1631 |
+
node = map[(i -= 3) + 2];
|
1632 |
+
collapse = "left";
|
1633 |
+
}
|
1634 |
+
if (bias == "right" && start == mEnd - mStart)
|
1635 |
+
while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
|
1636 |
+
node = map[(i += 3) + 2];
|
1637 |
+
collapse = "right";
|
1638 |
+
}
|
1639 |
+
break;
|
1640 |
+
}
|
1641 |
+
}
|
1642 |
+
|
1643 |
+
var rect;
|
1644 |
+
if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
|
1645 |
+
while (start && isExtendingChar(prepared.line.text.charAt(mStart + start))) --start;
|
1646 |
+
while (mStart + end < mEnd && isExtendingChar(prepared.line.text.charAt(mStart + end))) ++end;
|
1647 |
+
if (ie && ie_version < 9 && start == 0 && end == mEnd - mStart) {
|
1648 |
+
rect = node.parentNode.getBoundingClientRect();
|
1649 |
+
} else if (ie && cm.options.lineWrapping) {
|
1650 |
+
var rects = range(node, start, end).getClientRects();
|
1651 |
+
if (rects.length)
|
1652 |
+
rect = rects[bias == "right" ? rects.length - 1 : 0];
|
1653 |
+
else
|
1654 |
+
rect = nullRect;
|
1655 |
+
} else {
|
1656 |
+
rect = range(node, start, end).getBoundingClientRect() || nullRect;
|
1657 |
+
}
|
1658 |
+
} else { // If it is a widget, simply get the box for the whole widget.
|
1659 |
+
if (start > 0) collapse = bias = "right";
|
1660 |
+
var rects;
|
1661 |
+
if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
|
1662 |
+
rect = rects[bias == "right" ? rects.length - 1 : 0];
|
1663 |
+
else
|
1664 |
+
rect = node.getBoundingClientRect();
|
1665 |
+
}
|
1666 |
+
if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
|
1667 |
+
var rSpan = node.parentNode.getClientRects()[0];
|
1668 |
+
if (rSpan)
|
1669 |
+
rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom};
|
1670 |
+
else
|
1671 |
+
rect = nullRect;
|
1672 |
+
}
|
1673 |
+
|
1674 |
+
if (ie && ie_version < 11) rect = maybeUpdateRectForZooming(cm.display.measure, rect);
|
1675 |
+
|
1676 |
+
var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
|
1677 |
+
var mid = (rtop + rbot) / 2;
|
1678 |
+
var heights = prepared.view.measure.heights;
|
1679 |
+
for (var i = 0; i < heights.length - 1; i++)
|
1680 |
+
if (mid < heights[i]) break;
|
1681 |
+
var top = i ? heights[i - 1] : 0, bot = heights[i];
|
1682 |
+
var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
|
1683 |
+
right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
|
1684 |
+
top: top, bottom: bot};
|
1685 |
+
if (!rect.left && !rect.right) result.bogus = true;
|
1686 |
+
if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; }
|
1687 |
+
|
1688 |
+
return result;
|
1689 |
+
}
|
1690 |
+
|
1691 |
+
// Work around problem with bounding client rects on ranges being
|
1692 |
+
// returned incorrectly when zoomed on IE10 and below.
|
1693 |
+
function maybeUpdateRectForZooming(measure, rect) {
|
1694 |
+
if (!window.screen || screen.logicalXDPI == null ||
|
1695 |
+
screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
|
1696 |
+
return rect;
|
1697 |
+
var scaleX = screen.logicalXDPI / screen.deviceXDPI;
|
1698 |
+
var scaleY = screen.logicalYDPI / screen.deviceYDPI;
|
1699 |
+
return {left: rect.left * scaleX, right: rect.right * scaleX,
|
1700 |
+
top: rect.top * scaleY, bottom: rect.bottom * scaleY};
|
1701 |
+
}
|
1702 |
+
|
1703 |
+
function clearLineMeasurementCacheFor(lineView) {
|
1704 |
+
if (lineView.measure) {
|
1705 |
+
lineView.measure.cache = {};
|
1706 |
+
lineView.measure.heights = null;
|
1707 |
+
if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++)
|
1708 |
+
lineView.measure.caches[i] = {};
|
1709 |
+
}
|
1710 |
+
}
|
1711 |
+
|
1712 |
+
function clearLineMeasurementCache(cm) {
|
1713 |
+
cm.display.externalMeasure = null;
|
1714 |
+
removeChildren(cm.display.lineMeasure);
|
1715 |
+
for (var i = 0; i < cm.display.view.length; i++)
|
1716 |
+
clearLineMeasurementCacheFor(cm.display.view[i]);
|
1717 |
+
}
|
1718 |
+
|
1719 |
+
function clearCaches(cm) {
|
1720 |
+
clearLineMeasurementCache(cm);
|
1721 |
+
cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
|
1722 |
+
if (!cm.options.lineWrapping) cm.display.maxLineChanged = true;
|
1723 |
+
cm.display.lineNumChars = null;
|
1724 |
+
}
|
1725 |
+
|
1726 |
+
function pageScrollX() { return window.pageXOffset || (document.documentElement || document.body).scrollLeft; }
|
1727 |
+
function pageScrollY() { return window.pageYOffset || (document.documentElement || document.body).scrollTop; }
|
1728 |
+
|
1729 |
+
// Converts a {top, bottom, left, right} box from line-local
|
1730 |
+
// coordinates into another coordinate system. Context may be one of
|
1731 |
+
// "line", "div" (display.lineDiv), "local"/null (editor), or "page".
|
1732 |
+
function intoCoordSystem(cm, lineObj, rect, context) {
|
1733 |
+
if (lineObj.widgets) for (var i = 0; i < lineObj.widgets.length; ++i) if (lineObj.widgets[i].above) {
|
1734 |
+
var size = widgetHeight(lineObj.widgets[i]);
|
1735 |
+
rect.top += size; rect.bottom += size;
|
1736 |
+
}
|
1737 |
+
if (context == "line") return rect;
|
1738 |
+
if (!context) context = "local";
|
1739 |
+
var yOff = heightAtLine(lineObj);
|
1740 |
+
if (context == "local") yOff += paddingTop(cm.display);
|
1741 |
+
else yOff -= cm.display.viewOffset;
|
1742 |
+
if (context == "page" || context == "window") {
|
1743 |
+
var lOff = cm.display.lineSpace.getBoundingClientRect();
|
1744 |
+
yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
|
1745 |
+
var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
|
1746 |
+
rect.left += xOff; rect.right += xOff;
|
1747 |
+
}
|
1748 |
+
rect.top += yOff; rect.bottom += yOff;
|
1749 |
+
return rect;
|
1750 |
+
}
|
1751 |
+
|
1752 |
+
// Coverts a box from "div" coords to another coordinate system.
|
1753 |
+
// Context may be "window", "page", "div", or "local"/null.
|
1754 |
+
function fromCoordSystem(cm, coords, context) {
|
1755 |
+
if (context == "div") return coords;
|
1756 |
+
var left = coords.left, top = coords.top;
|
1757 |
+
// First move into "page" coordinate system
|
1758 |
+
if (context == "page") {
|
1759 |
+
left -= pageScrollX();
|
1760 |
+
top -= pageScrollY();
|
1761 |
+
} else if (context == "local" || !context) {
|
1762 |
+
var localBox = cm.display.sizer.getBoundingClientRect();
|
1763 |
+
left += localBox.left;
|
1764 |
+
top += localBox.top;
|
1765 |
+
}
|
1766 |
+
|
1767 |
+
var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
|
1768 |
+
return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top};
|
1769 |
+
}
|
1770 |
+
|
1771 |
+
function charCoords(cm, pos, context, lineObj, bias) {
|
1772 |
+
if (!lineObj) lineObj = getLine(cm.doc, pos.line);
|
1773 |
+
return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context);
|
1774 |
+
}
|
1775 |
+
|
1776 |
+
// Returns a box for a given cursor position, which may have an
|
1777 |
+
// 'other' property containing the position of the secondary cursor
|
1778 |
+
// on a bidi boundary.
|
1779 |
+
function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
|
1780 |
+
lineObj = lineObj || getLine(cm.doc, pos.line);
|
1781 |
+
if (!preparedMeasure) preparedMeasure = prepareMeasureForLine(cm, lineObj);
|
1782 |
+
function get(ch, right) {
|
1783 |
+
var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight);
|
1784 |
+
if (right) m.left = m.right; else m.right = m.left;
|
1785 |
+
return intoCoordSystem(cm, lineObj, m, context);
|
1786 |
+
}
|
1787 |
+
function getBidi(ch, partPos) {
|
1788 |
+
var part = order[partPos], right = part.level % 2;
|
1789 |
+
if (ch == bidiLeft(part) && partPos && part.level < order[partPos - 1].level) {
|
1790 |
+
part = order[--partPos];
|
1791 |
+
ch = bidiRight(part) - (part.level % 2 ? 0 : 1);
|
1792 |
+
right = true;
|
1793 |
+
} else if (ch == bidiRight(part) && partPos < order.length - 1 && part.level < order[partPos + 1].level) {
|
1794 |
+
part = order[++partPos];
|
1795 |
+
ch = bidiLeft(part) - part.level % 2;
|
1796 |
+
right = false;
|
1797 |
+
}
|
1798 |
+
if (right && ch == part.to && ch > part.from) return get(ch - 1);
|
1799 |
+
return get(ch, right);
|
1800 |
+
}
|
1801 |
+
var order = getOrder(lineObj), ch = pos.ch;
|
1802 |
+
if (!order) return get(ch);
|
1803 |
+
var partPos = getBidiPartAt(order, ch);
|
1804 |
+
var val = getBidi(ch, partPos);
|
1805 |
+
if (bidiOther != null) val.other = getBidi(ch, bidiOther);
|
1806 |
+
return val;
|
1807 |
+
}
|
1808 |
+
|
1809 |
+
// Used to cheaply estimate the coordinates for a position. Used for
|
1810 |
+
// intermediate scroll updates.
|
1811 |
+
function estimateCoords(cm, pos) {
|
1812 |
+
var left = 0, pos = clipPos(cm.doc, pos);
|
1813 |
+
if (!cm.options.lineWrapping) left = charWidth(cm.display) * pos.ch;
|
1814 |
+
var lineObj = getLine(cm.doc, pos.line);
|
1815 |
+
var top = heightAtLine(lineObj) + paddingTop(cm.display);
|
1816 |
+
return {left: left, right: left, top: top, bottom: top + lineObj.height};
|
1817 |
+
}
|
1818 |
+
|
1819 |
+
// Positions returned by coordsChar contain some extra information.
|
1820 |
+
// xRel is the relative x position of the input coordinates compared
|
1821 |
+
// to the found position (so xRel > 0 means the coordinates are to
|
1822 |
+
// the right of the character position, for example). When outside
|
1823 |
+
// is true, that means the coordinates lie outside the line's
|
1824 |
+
// vertical range.
|
1825 |
+
function PosWithInfo(line, ch, outside, xRel) {
|
1826 |
+
var pos = Pos(line, ch);
|
1827 |
+
pos.xRel = xRel;
|
1828 |
+
if (outside) pos.outside = true;
|
1829 |
+
return pos;
|
1830 |
+
}
|
1831 |
+
|
1832 |
+
// Compute the character position closest to the given coordinates.
|
1833 |
+
// Input must be lineSpace-local ("div" coordinate system).
|
1834 |
+
function coordsChar(cm, x, y) {
|
1835 |
+
var doc = cm.doc;
|
1836 |
+
y += cm.display.viewOffset;
|
1837 |
+
if (y < 0) return PosWithInfo(doc.first, 0, true, -1);
|
1838 |
+
var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
|
1839 |
+
if (lineN > last)
|
1840 |
+
return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, true, 1);
|
1841 |
+
if (x < 0) x = 0;
|
1842 |
+
|
1843 |
+
var lineObj = getLine(doc, lineN);
|
1844 |
+
for (;;) {
|
1845 |
+
var found = coordsCharInner(cm, lineObj, lineN, x, y);
|
1846 |
+
var merged = collapsedSpanAtEnd(lineObj);
|
1847 |
+
var mergedPos = merged && merged.find(0, true);
|
1848 |
+
if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
|
1849 |
+
lineN = lineNo(lineObj = mergedPos.to.line);
|
1850 |
+
else
|
1851 |
+
return found;
|
1852 |
+
}
|
1853 |
+
}
|
1854 |
+
|
1855 |
+
function coordsCharInner(cm, lineObj, lineNo, x, y) {
|
1856 |
+
var innerOff = y - heightAtLine(lineObj);
|
1857 |
+
var wrongLine = false, adjust = 2 * cm.display.wrapper.clientWidth;
|
1858 |
+
var preparedMeasure = prepareMeasureForLine(cm, lineObj);
|
1859 |
+
|
1860 |
+
function getX(ch) {
|
1861 |
+
var sp = cursorCoords(cm, Pos(lineNo, ch), "line", lineObj, preparedMeasure);
|
1862 |
+
wrongLine = true;
|
1863 |
+
if (innerOff > sp.bottom) return sp.left - adjust;
|
1864 |
+
else if (innerOff < sp.top) return sp.left + adjust;
|
1865 |
+
else wrongLine = false;
|
1866 |
+
return sp.left;
|
1867 |
+
}
|
1868 |
+
|
1869 |
+
var bidi = getOrder(lineObj), dist = lineObj.text.length;
|
1870 |
+
var from = lineLeft(lineObj), to = lineRight(lineObj);
|
1871 |
+
var fromX = getX(from), fromOutside = wrongLine, toX = getX(to), toOutside = wrongLine;
|
1872 |
+
|
1873 |
+
if (x > toX) return PosWithInfo(lineNo, to, toOutside, 1);
|
1874 |
+
// Do a binary search between these bounds.
|
1875 |
+
for (;;) {
|
1876 |
+
if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
|
1877 |
+
var ch = x < fromX || x - fromX <= toX - x ? from : to;
|
1878 |
+
var xDiff = x - (ch == from ? fromX : toX);
|
1879 |
+
while (isExtendingChar(lineObj.text.charAt(ch))) ++ch;
|
1880 |
+
var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside,
|
1881 |
+
xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0);
|
1882 |
+
return pos;
|
1883 |
+
}
|
1884 |
+
var step = Math.ceil(dist / 2), middle = from + step;
|
1885 |
+
if (bidi) {
|
1886 |
+
middle = from;
|
1887 |
+
for (var i = 0; i < step; ++i) middle = moveVisually(lineObj, middle, 1);
|
1888 |
+
}
|
1889 |
+
var middleX = getX(middle);
|
1890 |
+
if (middleX > x) {to = middle; toX = middleX; if (toOutside = wrongLine) toX += 1000; dist = step;}
|
1891 |
+
else {from = middle; fromX = middleX; fromOutside = wrongLine; dist -= step;}
|
1892 |
+
}
|
1893 |
+
}
|
1894 |
+
|
1895 |
+
var measureText;
|
1896 |
+
// Compute the default text height.
|
1897 |
+
function textHeight(display) {
|
1898 |
+
if (display.cachedTextHeight != null) return display.cachedTextHeight;
|
1899 |
+
if (measureText == null) {
|
1900 |
+
measureText = elt("pre");
|
1901 |
+
// Measure a bunch of lines, for browsers that compute
|
1902 |
+
// fractional heights.
|
1903 |
+
for (var i = 0; i < 49; ++i) {
|
1904 |
+
measureText.appendChild(document.createTextNode("x"));
|
1905 |
+
measureText.appendChild(elt("br"));
|
1906 |
+
}
|
1907 |
+
measureText.appendChild(document.createTextNode("x"));
|
1908 |
+
}
|
1909 |
+
removeChildrenAndAdd(display.measure, measureText);
|
1910 |
+
var height = measureText.offsetHeight / 50;
|
1911 |
+
if (height > 3) display.cachedTextHeight = height;
|
1912 |
+
removeChildren(display.measure);
|
1913 |
+
return height || 1;
|
1914 |
+
}
|
1915 |
+
|
1916 |
+
// Compute the default character width.
|
1917 |
+
function charWidth(display) {
|
1918 |
+
if (display.cachedCharWidth != null) return display.cachedCharWidth;
|
1919 |
+
var anchor = elt("span", "xxxxxxxxxx");
|
1920 |
+
var pre = elt("pre", [anchor]);
|
1921 |
+
removeChildrenAndAdd(display.measure, pre);
|
1922 |
+
var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
|
1923 |
+
if (width > 2) display.cachedCharWidth = width;
|
1924 |
+
return width || 10;
|
1925 |
+
}
|
1926 |
+
|
1927 |
+
// OPERATIONS
|
1928 |
+
|
1929 |
+
// Operations are used to wrap a series of changes to the editor
|
1930 |
+
// state in such a way that each change won't have to update the
|
1931 |
+
// cursor and display (which would be awkward, slow, and
|
1932 |
+
// error-prone). Instead, display updates are batched and then all
|
1933 |
+
// combined and executed at once.
|
1934 |
+
|
1935 |
+
var operationGroup = null;
|
1936 |
+
|
1937 |
+
var nextOpId = 0;
|
1938 |
+
// Start a new operation.
|
1939 |
+
function startOperation(cm) {
|
1940 |
+
cm.curOp = {
|
1941 |
+
cm: cm,
|
1942 |
+
viewChanged: false, // Flag that indicates that lines might need to be redrawn
|
1943 |
+
startHeight: cm.doc.height, // Used to detect need to update scrollbar
|
1944 |
+
forceUpdate: false, // Used to force a redraw
|
1945 |
+
updateInput: null, // Whether to reset the input textarea
|
1946 |
+
typing: false, // Whether this reset should be careful to leave existing text (for compositing)
|
1947 |
+
changeObjs: null, // Accumulated changes, for firing change events
|
1948 |
+
cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
|
1949 |
+
cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
|
1950 |
+
selectionChanged: false, // Whether the selection needs to be redrawn
|
1951 |
+
updateMaxLine: false, // Set when the widest line needs to be determined anew
|
1952 |
+
scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
|
1953 |
+
scrollToPos: null, // Used to scroll to a specific position
|
1954 |
+
id: ++nextOpId // Unique ID
|
1955 |
+
};
|
1956 |
+
if (operationGroup) {
|
1957 |
+
operationGroup.ops.push(cm.curOp);
|
1958 |
+
} else {
|
1959 |
+
cm.curOp.ownsGroup = operationGroup = {
|
1960 |
+
ops: [cm.curOp],
|
1961 |
+
delayedCallbacks: []
|
1962 |
+
};
|
1963 |
+
}
|
1964 |
+
}
|
1965 |
+
|
1966 |
+
function fireCallbacksForOps(group) {
|
1967 |
+
// Calls delayed callbacks and cursorActivity handlers until no
|
1968 |
+
// new ones appear
|
1969 |
+
var callbacks = group.delayedCallbacks, i = 0;
|
1970 |
+
do {
|
1971 |
+
for (; i < callbacks.length; i++)
|
1972 |
+
callbacks[i]();
|
1973 |
+
for (var j = 0; j < group.ops.length; j++) {
|
1974 |
+
var op = group.ops[j];
|
1975 |
+
if (op.cursorActivityHandlers)
|
1976 |
+
while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
|
1977 |
+
op.cursorActivityHandlers[op.cursorActivityCalled++](op.cm);
|
1978 |
+
}
|
1979 |
+
} while (i < callbacks.length);
|
1980 |
+
}
|
1981 |
+
|
1982 |
+
// Finish an operation, updating the display and signalling delayed events
|
1983 |
+
function endOperation(cm) {
|
1984 |
+
var op = cm.curOp, group = op.ownsGroup;
|
1985 |
+
if (!group) return;
|
1986 |
+
|
1987 |
+
try { fireCallbacksForOps(group); }
|
1988 |
+
finally {
|
1989 |
+
operationGroup = null;
|
1990 |
+
for (var i = 0; i < group.ops.length; i++)
|
1991 |
+
group.ops[i].cm.curOp = null;
|
1992 |
+
endOperations(group);
|
1993 |
+
}
|
1994 |
+
}
|
1995 |
+
|
1996 |
+
// The DOM updates done when an operation finishes are batched so
|
1997 |
+
// that the minimum number of relayouts are required.
|
1998 |
+
function endOperations(group) {
|
1999 |
+
var ops = group.ops;
|
2000 |
+
for (var i = 0; i < ops.length; i++) // Read DOM
|
2001 |
+
endOperation_R1(ops[i]);
|
2002 |
+
for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
|
2003 |
+
endOperation_W1(ops[i]);
|
2004 |
+
for (var i = 0; i < ops.length; i++) // Read DOM
|
2005 |
+
endOperation_R2(ops[i]);
|
2006 |
+
for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
|
2007 |
+
endOperation_W2(ops[i]);
|
2008 |
+
for (var i = 0; i < ops.length; i++) // Read DOM
|
2009 |
+
endOperation_finish(ops[i]);
|
2010 |
+
}
|
2011 |
+
|
2012 |
+
function endOperation_R1(op) {
|
2013 |
+
var cm = op.cm, display = cm.display;
|
2014 |
+
if (op.updateMaxLine) findMaxLine(cm);
|
2015 |
+
|
2016 |
+
op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
|
2017 |
+
op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
|
2018 |
+
op.scrollToPos.to.line >= display.viewTo) ||
|
2019 |
+
display.maxLineChanged && cm.options.lineWrapping;
|
2020 |
+
op.update = op.mustUpdate &&
|
2021 |
+
new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate);
|
2022 |
+
}
|
2023 |
+
|
2024 |
+
function endOperation_W1(op) {
|
2025 |
+
op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
|
2026 |
+
}
|
2027 |
+
|
2028 |
+
function endOperation_R2(op) {
|
2029 |
+
var cm = op.cm, display = cm.display;
|
2030 |
+
if (op.updatedDisplay) updateHeightsInViewport(cm);
|
2031 |
+
|
2032 |
+
// If the max line changed since it was last measured, measure it,
|
2033 |
+
// and ensure the document's width matches it.
|
2034 |
+
// updateDisplayIfNeeded will use these properties to do the actual resizing
|
2035 |
+
if (display.maxLineChanged && !cm.options.lineWrapping) {
|
2036 |
+
op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left;
|
2037 |
+
op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo +
|
2038 |
+
scrollerCutOff - display.scroller.clientWidth);
|
2039 |
+
}
|
2040 |
+
|
2041 |
+
op.barMeasure = measureForScrollbars(cm);
|
2042 |
+
if (op.updatedDisplay || op.selectionChanged)
|
2043 |
+
op.newSelectionNodes = drawSelection(cm);
|
2044 |
+
}
|
2045 |
+
|
2046 |
+
function endOperation_W2(op) {
|
2047 |
+
var cm = op.cm;
|
2048 |
+
|
2049 |
+
if (op.adjustWidthTo != null) {
|
2050 |
+
cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
|
2051 |
+
if (op.maxScrollLeft < cm.doc.scrollLeft)
|
2052 |
+
setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true);
|
2053 |
+
}
|
2054 |
+
|
2055 |
+
if (op.newSelectionNodes)
|
2056 |
+
updateSelection(cm, op.newSelectionNodes);
|
2057 |
+
if (op.updatedDisplay)
|
2058 |
+
setDocumentHeight(cm, op.barMeasure);
|
2059 |
+
if (op.updatedDisplay || op.startHeight != cm.doc.height)
|
2060 |
+
updateScrollbars(cm, op.barMeasure);
|
2061 |
+
|
2062 |
+
if (op.selectionChanged) restartBlink(cm);
|
2063 |
+
|
2064 |
+
if (cm.state.focused && op.updateInput)
|
2065 |
+
resetInput(cm, op.typing);
|
2066 |
+
}
|
2067 |
+
|
2068 |
+
function endOperation_finish(op) {
|
2069 |
+
var cm = op.cm, display = cm.display, doc = cm.doc;
|
2070 |
+
|
2071 |
+
if (op.updatedDisplay) postUpdateDisplay(cm, op.update);
|
2072 |
+
|
2073 |
+
// Abort mouse wheel delta measurement, when scrolling explicitly
|
2074 |
+
if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
|
2075 |
+
display.wheelStartX = display.wheelStartY = null;
|
2076 |
+
|
2077 |
+
// Propagate the scroll position to the actual DOM scroller
|
2078 |
+
if (op.scrollTop != null && display.scroller.scrollTop != op.scrollTop) {
|
2079 |
+
var top = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop));
|
2080 |
+
display.scroller.scrollTop = display.scrollbarV.scrollTop = doc.scrollTop = top;
|
2081 |
+
}
|
2082 |
+
if (op.scrollLeft != null && display.scroller.scrollLeft != op.scrollLeft) {
|
2083 |
+
var left = Math.max(0, Math.min(display.scroller.scrollWidth - display.scroller.clientWidth, op.scrollLeft));
|
2084 |
+
display.scroller.scrollLeft = display.scrollbarH.scrollLeft = doc.scrollLeft = left;
|
2085 |
+
alignHorizontally(cm);
|
2086 |
+
}
|
2087 |
+
// If we need to scroll a specific position into view, do so.
|
2088 |
+
if (op.scrollToPos) {
|
2089 |
+
var coords = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
|
2090 |
+
clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
|
2091 |
+
if (op.scrollToPos.isCursor && cm.state.focused) maybeScrollWindow(cm, coords);
|
2092 |
+
}
|
2093 |
+
|
2094 |
+
// Fire events for markers that are hidden/unidden by editing or
|
2095 |
+
// undoing
|
2096 |
+
var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
|
2097 |
+
if (hidden) for (var i = 0; i < hidden.length; ++i)
|
2098 |
+
if (!hidden[i].lines.length) signal(hidden[i], "hide");
|
2099 |
+
if (unhidden) for (var i = 0; i < unhidden.length; ++i)
|
2100 |
+
if (unhidden[i].lines.length) signal(unhidden[i], "unhide");
|
2101 |
+
|
2102 |
+
if (display.wrapper.offsetHeight)
|
2103 |
+
doc.scrollTop = cm.display.scroller.scrollTop;
|
2104 |
+
|
2105 |
+
// Apply workaround for two webkit bugs
|
2106 |
+
if (op.updatedDisplay && webkit) {
|
2107 |
+
if (cm.options.lineWrapping)
|
2108 |
+
checkForWebkitWidthBug(cm, op.barMeasure); // (Issue #2420)
|
2109 |
+
if (op.barMeasure.scrollWidth > op.barMeasure.clientWidth &&
|
2110 |
+
op.barMeasure.scrollWidth < op.barMeasure.clientWidth + 1 &&
|
2111 |
+
!hScrollbarTakesSpace(cm))
|
2112 |
+
updateScrollbars(cm); // (Issue #2562)
|
2113 |
+
}
|
2114 |
+
|
2115 |
+
// Fire change events, and delayed event handlers
|
2116 |
+
if (op.changeObjs)
|
2117 |
+
signal(cm, "changes", cm, op.changeObjs);
|
2118 |
+
}
|
2119 |
+
|
2120 |
+
// Run the given function in an operation
|
2121 |
+
function runInOp(cm, f) {
|
2122 |
+
if (cm.curOp) return f();
|
2123 |
+
startOperation(cm);
|
2124 |
+
try { return f(); }
|
2125 |
+
finally { endOperation(cm); }
|
2126 |
+
}
|
2127 |
+
// Wraps a function in an operation. Returns the wrapped function.
|
2128 |
+
function operation(cm, f) {
|
2129 |
+
return function() {
|
2130 |
+
if (cm.curOp) return f.apply(cm, arguments);
|
2131 |
+
startOperation(cm);
|
2132 |
+
try { return f.apply(cm, arguments); }
|
2133 |
+
finally { endOperation(cm); }
|
2134 |
+
};
|
2135 |
+
}
|
2136 |
+
// Used to add methods to editor and doc instances, wrapping them in
|
2137 |
+
// operations.
|
2138 |
+
function methodOp(f) {
|
2139 |
+
return function() {
|
2140 |
+
if (this.curOp) return f.apply(this, arguments);
|
2141 |
+
startOperation(this);
|
2142 |
+
try { return f.apply(this, arguments); }
|
2143 |
+
finally { endOperation(this); }
|
2144 |
+
};
|
2145 |
+
}
|
2146 |
+
function docMethodOp(f) {
|
2147 |
+
return function() {
|
2148 |
+
var cm = this.cm;
|
2149 |
+
if (!cm || cm.curOp) return f.apply(this, arguments);
|
2150 |
+
startOperation(cm);
|
2151 |
+
try { return f.apply(this, arguments); }
|
2152 |
+
finally { endOperation(cm); }
|
2153 |
+
};
|
2154 |
+
}
|
2155 |
+
|
2156 |
+
// VIEW TRACKING
|
2157 |
+
|
2158 |
+
// These objects are used to represent the visible (currently drawn)
|
2159 |
+
// part of the document. A LineView may correspond to multiple
|
2160 |
+
// logical lines, if those are connected by collapsed ranges.
|
2161 |
+
function LineView(doc, line, lineN) {
|
2162 |
+
// The starting line
|
2163 |
+
this.line = line;
|
2164 |
+
// Continuing lines, if any
|
2165 |
+
this.rest = visualLineContinued(line);
|
2166 |
+
// Number of logical lines in this visual line
|
2167 |
+
this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
|
2168 |
+
this.node = this.text = null;
|
2169 |
+
this.hidden = lineIsHidden(doc, line);
|
2170 |
+
}
|
2171 |
+
|
2172 |
+
// Create a range of LineView objects for the given lines.
|
2173 |
+
function buildViewArray(cm, from, to) {
|
2174 |
+
var array = [], nextPos;
|
2175 |
+
for (var pos = from; pos < to; pos = nextPos) {
|
2176 |
+
var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
|
2177 |
+
nextPos = pos + view.size;
|
2178 |
+
array.push(view);
|
2179 |
+
}
|
2180 |
+
return array;
|
2181 |
+
}
|
2182 |
+
|
2183 |
+
// Updates the display.view data structure for a given change to the
|
2184 |
+
// document. From and to are in pre-change coordinates. Lendiff is
|
2185 |
+
// the amount of lines added or subtracted by the change. This is
|
2186 |
+
// used for changes that span multiple lines, or change the way
|
2187 |
+
// lines are divided into visual lines. regLineChange (below)
|
2188 |
+
// registers single-line changes.
|
2189 |
+
function regChange(cm, from, to, lendiff) {
|
2190 |
+
if (from == null) from = cm.doc.first;
|
2191 |
+
if (to == null) to = cm.doc.first + cm.doc.size;
|
2192 |
+
if (!lendiff) lendiff = 0;
|
2193 |
+
|
2194 |
+
var display = cm.display;
|
2195 |
+
if (lendiff && to < display.viewTo &&
|
2196 |
+
(display.updateLineNumbers == null || display.updateLineNumbers > from))
|
2197 |
+
display.updateLineNumbers = from;
|
2198 |
+
|
2199 |
+
cm.curOp.viewChanged = true;
|
2200 |
+
|
2201 |
+
if (from >= display.viewTo) { // Change after
|
2202 |
+
if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
|
2203 |
+
resetView(cm);
|
2204 |
+
} else if (to <= display.viewFrom) { // Change before
|
2205 |
+
if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
|
2206 |
+
resetView(cm);
|
2207 |
+
} else {
|
2208 |
+
display.viewFrom += lendiff;
|
2209 |
+
display.viewTo += lendiff;
|
2210 |
+
}
|
2211 |
+
} else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
|
2212 |
+
resetView(cm);
|
2213 |
+
} else if (from <= display.viewFrom) { // Top overlap
|
2214 |
+
var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
|
2215 |
+
if (cut) {
|
2216 |
+
display.view = display.view.slice(cut.index);
|
2217 |
+
display.viewFrom = cut.lineN;
|
2218 |
+
display.viewTo += lendiff;
|
2219 |
+
} else {
|
2220 |
+
resetView(cm);
|
2221 |
+
}
|
2222 |
+
} else if (to >= display.viewTo) { // Bottom overlap
|
2223 |
+
var cut = viewCuttingPoint(cm, from, from, -1);
|
2224 |
+
if (cut) {
|
2225 |
+
display.view = display.view.slice(0, cut.index);
|
2226 |
+
display.viewTo = cut.lineN;
|
2227 |
+
} else {
|
2228 |
+
resetView(cm);
|
2229 |
+
}
|
2230 |
+
} else { // Gap in the middle
|
2231 |
+
var cutTop = viewCuttingPoint(cm, from, from, -1);
|
2232 |
+
var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
|
2233 |
+
if (cutTop && cutBot) {
|
2234 |
+
display.view = display.view.slice(0, cutTop.index)
|
2235 |
+
.concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
|
2236 |
+
.concat(display.view.slice(cutBot.index));
|
2237 |
+
display.viewTo += lendiff;
|
2238 |
+
} else {
|
2239 |
+
resetView(cm);
|
2240 |
+
}
|
2241 |
+
}
|
2242 |
+
|
2243 |
+
var ext = display.externalMeasured;
|
2244 |
+
if (ext) {
|
2245 |
+
if (to < ext.lineN)
|
2246 |
+
ext.lineN += lendiff;
|
2247 |
+
else if (from < ext.lineN + ext.size)
|
2248 |
+
display.externalMeasured = null;
|
2249 |
+
}
|
2250 |
+
}
|
2251 |
+
|
2252 |
+
// Register a change to a single line. Type must be one of "text",
|
2253 |
+
// "gutter", "class", "widget"
|
2254 |
+
function regLineChange(cm, line, type) {
|
2255 |
+
cm.curOp.viewChanged = true;
|
2256 |
+
var display = cm.display, ext = cm.display.externalMeasured;
|
2257 |
+
if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
|
2258 |
+
display.externalMeasured = null;
|
2259 |
+
|
2260 |
+
if (line < display.viewFrom || line >= display.viewTo) return;
|
2261 |
+
var lineView = display.view[findViewIndex(cm, line)];
|
2262 |
+
if (lineView.node == null) return;
|
2263 |
+
var arr = lineView.changes || (lineView.changes = []);
|
2264 |
+
if (indexOf(arr, type) == -1) arr.push(type);
|
2265 |
+
}
|
2266 |
+
|
2267 |
+
// Clear the view.
|
2268 |
+
function resetView(cm) {
|
2269 |
+
cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
|
2270 |
+
cm.display.view = [];
|
2271 |
+
cm.display.viewOffset = 0;
|
2272 |
+
}
|
2273 |
+
|
2274 |
+
// Find the view element corresponding to a given line. Return null
|
2275 |
+
// when the line isn't visible.
|
2276 |
+
function findViewIndex(cm, n) {
|
2277 |
+
if (n >= cm.display.viewTo) return null;
|
2278 |
+
n -= cm.display.viewFrom;
|
2279 |
+
if (n < 0) return null;
|
2280 |
+
var view = cm.display.view;
|
2281 |
+
for (var i = 0; i < view.length; i++) {
|
2282 |
+
n -= view[i].size;
|
2283 |
+
if (n < 0) return i;
|
2284 |
+
}
|
2285 |
+
}
|
2286 |
+
|
2287 |
+
function viewCuttingPoint(cm, oldN, newN, dir) {
|
2288 |
+
var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
|
2289 |
+
if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
|
2290 |
+
return {index: index, lineN: newN};
|
2291 |
+
for (var i = 0, n = cm.display.viewFrom; i < index; i++)
|
2292 |
+
n += view[i].size;
|
2293 |
+
if (n != oldN) {
|
2294 |
+
if (dir > 0) {
|
2295 |
+
if (index == view.length - 1) return null;
|
2296 |
+
diff = (n + view[index].size) - oldN;
|
2297 |
+
index++;
|
2298 |
+
} else {
|
2299 |
+
diff = n - oldN;
|
2300 |
+
}
|
2301 |
+
oldN += diff; newN += diff;
|
2302 |
+
}
|
2303 |
+
while (visualLineNo(cm.doc, newN) != newN) {
|
2304 |
+
if (index == (dir < 0 ? 0 : view.length - 1)) return null;
|
2305 |
+
newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
|
2306 |
+
index += dir;
|
2307 |
+
}
|
2308 |
+
return {index: index, lineN: newN};
|
2309 |
+
}
|
2310 |
+
|
2311 |
+
// Force the view to cover a given range, adding empty view element
|
2312 |
+
// or clipping off existing ones as needed.
|
2313 |
+
function adjustView(cm, from, to) {
|
2314 |
+
var display = cm.display, view = display.view;
|
2315 |
+
if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
|
2316 |
+
display.view = buildViewArray(cm, from, to);
|
2317 |
+
display.viewFrom = from;
|
2318 |
+
} else {
|
2319 |
+
if (display.viewFrom > from)
|
2320 |
+
display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view);
|
2321 |
+
else if (display.viewFrom < from)
|
2322 |
+
display.view = display.view.slice(findViewIndex(cm, from));
|
2323 |
+
display.viewFrom = from;
|
2324 |
+
if (display.viewTo < to)
|
2325 |
+
display.view = display.view.concat(buildViewArray(cm, display.viewTo, to));
|
2326 |
+
else if (display.viewTo > to)
|
2327 |
+
display.view = display.view.slice(0, findViewIndex(cm, to));
|
2328 |
+
}
|
2329 |
+
display.viewTo = to;
|
2330 |
+
}
|
2331 |
+
|
2332 |
+
// Count the number of lines in the view whose DOM representation is
|
2333 |
+
// out of date (or nonexistent).
|
2334 |
+
function countDirtyView(cm) {
|
2335 |
+
var view = cm.display.view, dirty = 0;
|
2336 |
+
for (var i = 0; i < view.length; i++) {
|
2337 |
+
var lineView = view[i];
|
2338 |
+
if (!lineView.hidden && (!lineView.node || lineView.changes)) ++dirty;
|
2339 |
+
}
|
2340 |
+
return dirty;
|
2341 |
+
}
|
2342 |
+
|
2343 |
+
// INPUT HANDLING
|
2344 |
+
|
2345 |
+
// Poll for input changes, using the normal rate of polling. This
|
2346 |
+
// runs as long as the editor is focused.
|
2347 |
+
function slowPoll(cm) {
|
2348 |
+
if (cm.display.pollingFast) return;
|
2349 |
+
cm.display.poll.set(cm.options.pollInterval, function() {
|
2350 |
+
readInput(cm);
|
2351 |
+
if (cm.state.focused) slowPoll(cm);
|
2352 |
+
});
|
2353 |
+
}
|
2354 |
+
|
2355 |
+
// When an event has just come in that is likely to add or change
|
2356 |
+
// something in the input textarea, we poll faster, to ensure that
|
2357 |
+
// the change appears on the screen quickly.
|
2358 |
+
function fastPoll(cm) {
|
2359 |
+
var missed = false;
|
2360 |
+
cm.display.pollingFast = true;
|
2361 |
+
function p() {
|
2362 |
+
var changed = readInput(cm);
|
2363 |
+
if (!changed && !missed) {missed = true; cm.display.poll.set(60, p);}
|
2364 |
+
else {cm.display.pollingFast = false; slowPoll(cm);}
|
2365 |
+
}
|
2366 |
+
cm.display.poll.set(20, p);
|
2367 |
+
}
|
2368 |
+
|
2369 |
+
// This will be set to an array of strings when copying, so that,
|
2370 |
+
// when pasting, we know what kind of selections the copied text
|
2371 |
+
// was made out of.
|
2372 |
+
var lastCopied = null;
|
2373 |
+
|
2374 |
+
// Read input from the textarea, and update the document to match.
|
2375 |
+
// When something is selected, it is present in the textarea, and
|
2376 |
+
// selected (unless it is huge, in which case a placeholder is
|
2377 |
+
// used). When nothing is selected, the cursor sits after previously
|
2378 |
+
// seen text (can be empty), which is stored in prevInput (we must
|
2379 |
+
// not reset the textarea when typing, because that breaks IME).
|
2380 |
+
function readInput(cm) {
|
2381 |
+
var input = cm.display.input, prevInput = cm.display.prevInput, doc = cm.doc;
|
2382 |
+
// Since this is called a *lot*, try to bail out as cheaply as
|
2383 |
+
// possible when it is clear that nothing happened. hasSelection
|
2384 |
+
// will be the case when there is a lot of text in the textarea,
|
2385 |
+
// in which case reading its value would be expensive.
|
2386 |
+
if (!cm.state.focused || (hasSelection(input) && !prevInput) || isReadOnly(cm) || cm.options.disableInput)
|
2387 |
+
return false;
|
2388 |
+
// See paste handler for more on the fakedLastChar kludge
|
2389 |
+
if (cm.state.pasteIncoming && cm.state.fakedLastChar) {
|
2390 |
+
input.value = input.value.substring(0, input.value.length - 1);
|
2391 |
+
cm.state.fakedLastChar = false;
|
2392 |
+
}
|
2393 |
+
var text = input.value;
|
2394 |
+
// If nothing changed, bail.
|
2395 |
+
if (text == prevInput && !cm.somethingSelected()) return false;
|
2396 |
+
// Work around nonsensical selection resetting in IE9/10, and
|
2397 |
+
// inexplicable appearance of private area unicode characters on
|
2398 |
+
// some key combos in Mac (#2689).
|
2399 |
+
if (ie && ie_version >= 9 && cm.display.inputHasSelection === text ||
|
2400 |
+
mac && /[\uf700-\uf7ff]/.test(text)) {
|
2401 |
+
resetInput(cm);
|
2402 |
+
return false;
|
2403 |
+
}
|
2404 |
+
|
2405 |
+
var withOp = !cm.curOp;
|
2406 |
+
if (withOp) startOperation(cm);
|
2407 |
+
cm.display.shift = false;
|
2408 |
+
|
2409 |
+
if (text.charCodeAt(0) == 0x200b && doc.sel == cm.display.selForContextMenu && !prevInput)
|
2410 |
+
prevInput = "\u200b";
|
2411 |
+
// Find the part of the input that is actually new
|
2412 |
+
var same = 0, l = Math.min(prevInput.length, text.length);
|
2413 |
+
while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same;
|
2414 |
+
var inserted = text.slice(same), textLines = splitLines(inserted);
|
2415 |
+
|
2416 |
+
// When pasing N lines into N selections, insert one line per selection
|
2417 |
+
var multiPaste = null;
|
2418 |
+
if (cm.state.pasteIncoming && doc.sel.ranges.length > 1) {
|
2419 |
+
if (lastCopied && lastCopied.join("\n") == inserted)
|
2420 |
+
multiPaste = doc.sel.ranges.length % lastCopied.length == 0 && map(lastCopied, splitLines);
|
2421 |
+
else if (textLines.length == doc.sel.ranges.length)
|
2422 |
+
multiPaste = map(textLines, function(l) { return [l]; });
|
2423 |
+
}
|
2424 |
+
|
2425 |
+
// Normal behavior is to insert the new text into every selection
|
2426 |
+
for (var i = doc.sel.ranges.length - 1; i >= 0; i--) {
|
2427 |
+
var range = doc.sel.ranges[i];
|
2428 |
+
var from = range.from(), to = range.to();
|
2429 |
+
// Handle deletion
|
2430 |
+
if (same < prevInput.length)
|
2431 |
+
from = Pos(from.line, from.ch - (prevInput.length - same));
|
2432 |
+
// Handle overwrite
|
2433 |
+
else if (cm.state.overwrite && range.empty() && !cm.state.pasteIncoming)
|
2434 |
+
to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length));
|
2435 |
+
var updateInput = cm.curOp.updateInput;
|
2436 |
+
var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i % multiPaste.length] : textLines,
|
2437 |
+
origin: cm.state.pasteIncoming ? "paste" : cm.state.cutIncoming ? "cut" : "+input"};
|
2438 |
+
makeChange(cm.doc, changeEvent);
|
2439 |
+
signalLater(cm, "inputRead", cm, changeEvent);
|
2440 |
+
// When an 'electric' character is inserted, immediately trigger a reindent
|
2441 |
+
if (inserted && !cm.state.pasteIncoming && cm.options.electricChars &&
|
2442 |
+
cm.options.smartIndent && range.head.ch < 100 &&
|
2443 |
+
(!i || doc.sel.ranges[i - 1].head.line != range.head.line)) {
|
2444 |
+
var mode = cm.getModeAt(range.head);
|
2445 |
+
if (mode.electricChars) {
|
2446 |
+
for (var j = 0; j < mode.electricChars.length; j++)
|
2447 |
+
if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
|
2448 |
+
indentLine(cm, range.head.line, "smart");
|
2449 |
+
break;
|
2450 |
+
}
|
2451 |
+
} else if (mode.electricInput) {
|
2452 |
+
var end = changeEnd(changeEvent);
|
2453 |
+
if (mode.electricInput.test(getLine(doc, end.line).text.slice(0, end.ch)))
|
2454 |
+
indentLine(cm, range.head.line, "smart");
|
2455 |
+
}
|
2456 |
+
}
|
2457 |
+
}
|
2458 |
+
ensureCursorVisible(cm);
|
2459 |
+
cm.curOp.updateInput = updateInput;
|
2460 |
+
cm.curOp.typing = true;
|
2461 |
+
|
2462 |
+
// Don't leave long text in the textarea, since it makes further polling slow
|
2463 |
+
if (text.length > 1000 || text.indexOf("\n") > -1) input.value = cm.display.prevInput = "";
|
2464 |
+
else cm.display.prevInput = text;
|
2465 |
+
if (withOp) endOperation(cm);
|
2466 |
+
cm.state.pasteIncoming = cm.state.cutIncoming = false;
|
2467 |
+
return true;
|
2468 |
+
}
|
2469 |
+
|
2470 |
+
// Reset the input to correspond to the selection (or to be empty,
|
2471 |
+
// when not typing and nothing is selected)
|
2472 |
+
function resetInput(cm, typing) {
|
2473 |
+
var minimal, selected, doc = cm.doc;
|
2474 |
+
if (cm.somethingSelected()) {
|
2475 |
+
cm.display.prevInput = "";
|
2476 |
+
var range = doc.sel.primary();
|
2477 |
+
minimal = hasCopyEvent &&
|
2478 |
+
(range.to().line - range.from().line > 100 || (selected = cm.getSelection()).length > 1000);
|
2479 |
+
var content = minimal ? "-" : selected || cm.getSelection();
|
2480 |
+
cm.display.input.value = content;
|
2481 |
+
if (cm.state.focused) selectInput(cm.display.input);
|
2482 |
+
if (ie && ie_version >= 9) cm.display.inputHasSelection = content;
|
2483 |
+
} else if (!typing) {
|
2484 |
+
cm.display.prevInput = cm.display.input.value = "";
|
2485 |
+
if (ie && ie_version >= 9) cm.display.inputHasSelection = null;
|
2486 |
+
}
|
2487 |
+
cm.display.inaccurateSelection = minimal;
|
2488 |
+
}
|
2489 |
+
|
2490 |
+
function focusInput(cm) {
|
2491 |
+
if (cm.options.readOnly != "nocursor" && (!mobile || activeElt() != cm.display.input))
|
2492 |
+
cm.display.input.focus();
|
2493 |
+
}
|
2494 |
+
|
2495 |
+
function ensureFocus(cm) {
|
2496 |
+
if (!cm.state.focused) { focusInput(cm); onFocus(cm); }
|
2497 |
+
}
|
2498 |
+
|
2499 |
+
function isReadOnly(cm) {
|
2500 |
+
return cm.options.readOnly || cm.doc.cantEdit;
|
2501 |
+
}
|
2502 |
+
|
2503 |
+
// EVENT HANDLERS
|
2504 |
+
|
2505 |
+
// Attach the necessary event handlers when initializing the editor
|
2506 |
+
function registerEventHandlers(cm) {
|
2507 |
+
var d = cm.display;
|
2508 |
+
on(d.scroller, "mousedown", operation(cm, onMouseDown));
|
2509 |
+
// Older IE's will not fire a second mousedown for a double click
|
2510 |
+
if (ie && ie_version < 11)
|
2511 |
+
on(d.scroller, "dblclick", operation(cm, function(e) {
|
2512 |
+
if (signalDOMEvent(cm, e)) return;
|
2513 |
+
var pos = posFromMouse(cm, e);
|
2514 |
+
if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return;
|
2515 |
+
e_preventDefault(e);
|
2516 |
+
var word = findWordAt(cm, pos);
|
2517 |
+
extendSelection(cm.doc, word.anchor, word.head);
|
2518 |
+
}));
|
2519 |
+
else
|
2520 |
+
on(d.scroller, "dblclick", function(e) { signalDOMEvent(cm, e) || e_preventDefault(e); });
|
2521 |
+
// Prevent normal selection in the editor (we handle our own)
|
2522 |
+
on(d.lineSpace, "selectstart", function(e) {
|
2523 |
+
if (!eventInWidget(d, e)) e_preventDefault(e);
|
2524 |
+
});
|
2525 |
+
// Some browsers fire contextmenu *after* opening the menu, at
|
2526 |
+
// which point we can't mess with it anymore. Context menu is
|
2527 |
+
// handled in onMouseDown for these browsers.
|
2528 |
+
if (!captureRightClick) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e);});
|
2529 |
+
|
2530 |
+
// Sync scrolling between fake scrollbars and real scrollable
|
2531 |
+
// area, ensure viewport is updated when scrolling.
|
2532 |
+
on(d.scroller, "scroll", function() {
|
2533 |
+
if (d.scroller.clientHeight) {
|
2534 |
+
setScrollTop(cm, d.scroller.scrollTop);
|
2535 |
+
setScrollLeft(cm, d.scroller.scrollLeft, true);
|
2536 |
+
signal(cm, "scroll", cm);
|
2537 |
+
}
|
2538 |
+
});
|
2539 |
+
on(d.scrollbarV, "scroll", function() {
|
2540 |
+
if (d.scroller.clientHeight) setScrollTop(cm, d.scrollbarV.scrollTop);
|
2541 |
+
});
|
2542 |
+
on(d.scrollbarH, "scroll", function() {
|
2543 |
+
if (d.scroller.clientHeight) setScrollLeft(cm, d.scrollbarH.scrollLeft);
|
2544 |
+
});
|
2545 |
+
|
2546 |
+
// Listen to wheel events in order to try and update the viewport on time.
|
2547 |
+
on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e);});
|
2548 |
+
on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e);});
|
2549 |
+
|
2550 |
+
// Prevent clicks in the scrollbars from killing focus
|
2551 |
+
function reFocus() { if (cm.state.focused) setTimeout(bind(focusInput, cm), 0); }
|
2552 |
+
on(d.scrollbarH, "mousedown", reFocus);
|
2553 |
+
on(d.scrollbarV, "mousedown", reFocus);
|
2554 |
+
// Prevent wrapper from ever scrolling
|
2555 |
+
on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
|
2556 |
+
|
2557 |
+
on(d.input, "keyup", function(e) { onKeyUp.call(cm, e); });
|
2558 |
+
on(d.input, "input", function() {
|
2559 |
+
if (ie && ie_version >= 9 && cm.display.inputHasSelection) cm.display.inputHasSelection = null;
|
2560 |
+
fastPoll(cm);
|
2561 |
+
});
|
2562 |
+
on(d.input, "keydown", operation(cm, onKeyDown));
|
2563 |
+
on(d.input, "keypress", operation(cm, onKeyPress));
|
2564 |
+
on(d.input, "focus", bind(onFocus, cm));
|
2565 |
+
on(d.input, "blur", bind(onBlur, cm));
|
2566 |
+
|
2567 |
+
function drag_(e) {
|
2568 |
+
if (!signalDOMEvent(cm, e)) e_stop(e);
|
2569 |
+
}
|
2570 |
+
if (cm.options.dragDrop) {
|
2571 |
+
on(d.scroller, "dragstart", function(e){onDragStart(cm, e);});
|
2572 |
+
on(d.scroller, "dragenter", drag_);
|
2573 |
+
on(d.scroller, "dragover", drag_);
|
2574 |
+
on(d.scroller, "drop", operation(cm, onDrop));
|
2575 |
+
}
|
2576 |
+
on(d.scroller, "paste", function(e) {
|
2577 |
+
if (eventInWidget(d, e)) return;
|
2578 |
+
cm.state.pasteIncoming = true;
|
2579 |
+
focusInput(cm);
|
2580 |
+
fastPoll(cm);
|
2581 |
+
});
|
2582 |
+
on(d.input, "paste", function() {
|
2583 |
+
// Workaround for webkit bug https://bugs.webkit.org/show_bug.cgi?id=90206
|
2584 |
+
// Add a char to the end of textarea before paste occur so that
|
2585 |
+
// selection doesn't span to the end of textarea.
|
2586 |
+
if (webkit && !cm.state.fakedLastChar && !(new Date - cm.state.lastMiddleDown < 200)) {
|
2587 |
+
var start = d.input.selectionStart, end = d.input.selectionEnd;
|
2588 |
+
d.input.value += "$";
|
2589 |
+
// The selection end needs to be set before the start, otherwise there
|
2590 |
+
// can be an intermediate non-empty selection between the two, which
|
2591 |
+
// can override the middle-click paste buffer on linux and cause the
|
2592 |
+
// wrong thing to get pasted.
|
2593 |
+
d.input.selectionEnd = end;
|
2594 |
+
d.input.selectionStart = start;
|
2595 |
+
cm.state.fakedLastChar = true;
|
2596 |
+
}
|
2597 |
+
cm.state.pasteIncoming = true;
|
2598 |
+
fastPoll(cm);
|
2599 |
+
});
|
2600 |
+
|
2601 |
+
function prepareCopyCut(e) {
|
2602 |
+
if (cm.somethingSelected()) {
|
2603 |
+
lastCopied = cm.getSelections();
|
2604 |
+
if (d.inaccurateSelection) {
|
2605 |
+
d.prevInput = "";
|
2606 |
+
d.inaccurateSelection = false;
|
2607 |
+
d.input.value = lastCopied.join("\n");
|
2608 |
+
selectInput(d.input);
|
2609 |
+
}
|
2610 |
+
} else {
|
2611 |
+
var text = [], ranges = [];
|
2612 |
+
for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
|
2613 |
+
var line = cm.doc.sel.ranges[i].head.line;
|
2614 |
+
var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)};
|
2615 |
+
ranges.push(lineRange);
|
2616 |
+
text.push(cm.getRange(lineRange.anchor, lineRange.head));
|
2617 |
+
}
|
2618 |
+
if (e.type == "cut") {
|
2619 |
+
cm.setSelections(ranges, null, sel_dontScroll);
|
2620 |
+
} else {
|
2621 |
+
d.prevInput = "";
|
2622 |
+
d.input.value = text.join("\n");
|
2623 |
+
selectInput(d.input);
|
2624 |
+
}
|
2625 |
+
lastCopied = text;
|
2626 |
+
}
|
2627 |
+
if (e.type == "cut") cm.state.cutIncoming = true;
|
2628 |
+
}
|
2629 |
+
on(d.input, "cut", prepareCopyCut);
|
2630 |
+
on(d.input, "copy", prepareCopyCut);
|
2631 |
+
|
2632 |
+
// Needed to handle Tab key in KHTML
|
2633 |
+
if (khtml) on(d.sizer, "mouseup", function() {
|
2634 |
+
if (activeElt() == d.input) d.input.blur();
|
2635 |
+
focusInput(cm);
|
2636 |
+
});
|
2637 |
+
}
|
2638 |
+
|
2639 |
+
// Called when the window resizes
|
2640 |
+
function onResize(cm) {
|
2641 |
+
// Might be a text scaling operation, clear size caches.
|
2642 |
+
var d = cm.display;
|
2643 |
+
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
|
2644 |
+
cm.setSize();
|
2645 |
+
}
|
2646 |
+
|
2647 |
+
// MOUSE EVENTS
|
2648 |
+
|
2649 |
+
// Return true when the given mouse event happened in a widget
|
2650 |
+
function eventInWidget(display, e) {
|
2651 |
+
for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
|
2652 |
+
if (!n || n.ignoreEvents || n.parentNode == display.sizer && n != display.mover) return true;
|
2653 |
+
}
|
2654 |
+
}
|
2655 |
+
|
2656 |
+
// Given a mouse event, find the corresponding position. If liberal
|
2657 |
+
// is false, it checks whether a gutter or scrollbar was clicked,
|
2658 |
+
// and returns null if it was. forRect is used by rectangular
|
2659 |
+
// selections, and tries to estimate a character position even for
|
2660 |
+
// coordinates beyond the right of the text.
|
2661 |
+
function posFromMouse(cm, e, liberal, forRect) {
|
2662 |
+
var display = cm.display;
|
2663 |
+
if (!liberal) {
|
2664 |
+
var target = e_target(e);
|
2665 |
+
if (target == display.scrollbarH || target == display.scrollbarV ||
|
2666 |
+
target == display.scrollbarFiller || target == display.gutterFiller) return null;
|
2667 |
+
}
|
2668 |
+
var x, y, space = display.lineSpace.getBoundingClientRect();
|
2669 |
+
// Fails unpredictably on IE[67] when mouse is dragged around quickly.
|
2670 |
+
try { x = e.clientX - space.left; y = e.clientY - space.top; }
|
2671 |
+
catch (e) { return null; }
|
2672 |
+
var coords = coordsChar(cm, x, y), line;
|
2673 |
+
if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
|
2674 |
+
var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
|
2675 |
+
coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
|
2676 |
+
}
|
2677 |
+
return coords;
|
2678 |
+
}
|
2679 |
+
|
2680 |
+
// A mouse down can be a single click, double click, triple click,
|
2681 |
+
// start of selection drag, start of text drag, new cursor
|
2682 |
+
// (ctrl-click), rectangle drag (alt-drag), or xwin
|
2683 |
+
// middle-click-paste. Or it might be a click on something we should
|
2684 |
+
// not interfere with, such as a scrollbar or widget.
|
2685 |
+
function onMouseDown(e) {
|
2686 |
+
if (signalDOMEvent(this, e)) return;
|
2687 |
+
var cm = this, display = cm.display;
|
2688 |
+
display.shift = e.shiftKey;
|
2689 |
+
|
2690 |
+
if (eventInWidget(display, e)) {
|
2691 |
+
if (!webkit) {
|
2692 |
+
// Briefly turn off draggability, to allow widgets to do
|
2693 |
+
// normal dragging things.
|
2694 |
+
display.scroller.draggable = false;
|
2695 |
+
setTimeout(function(){display.scroller.draggable = true;}, 100);
|
2696 |
+
}
|
2697 |
+
return;
|
2698 |
+
}
|
2699 |
+
if (clickInGutter(cm, e)) return;
|
2700 |
+
var start = posFromMouse(cm, e);
|
2701 |
+
window.focus();
|
2702 |
+
|
2703 |
+
switch (e_button(e)) {
|
2704 |
+
case 1:
|
2705 |
+
if (start)
|
2706 |
+
leftButtonDown(cm, e, start);
|
2707 |
+
else if (e_target(e) == display.scroller)
|
2708 |
+
e_preventDefault(e);
|
2709 |
+
break;
|
2710 |
+
case 2:
|
2711 |
+
if (webkit) cm.state.lastMiddleDown = +new Date;
|
2712 |
+
if (start) extendSelection(cm.doc, start);
|
2713 |
+
setTimeout(bind(focusInput, cm), 20);
|
2714 |
+
e_preventDefault(e);
|
2715 |
+
break;
|
2716 |
+
case 3:
|
2717 |
+
if (captureRightClick) onContextMenu(cm, e);
|
2718 |
+
break;
|
2719 |
+
}
|
2720 |
+
}
|
2721 |
+
|
2722 |
+
var lastClick, lastDoubleClick;
|
2723 |
+
function leftButtonDown(cm, e, start) {
|
2724 |
+
setTimeout(bind(ensureFocus, cm), 0);
|
2725 |
+
|
2726 |
+
var now = +new Date, type;
|
2727 |
+
if (lastDoubleClick && lastDoubleClick.time > now - 400 && cmp(lastDoubleClick.pos, start) == 0) {
|
2728 |
+
type = "triple";
|
2729 |
+
} else if (lastClick && lastClick.time > now - 400 && cmp(lastClick.pos, start) == 0) {
|
2730 |
+
type = "double";
|
2731 |
+
lastDoubleClick = {time: now, pos: start};
|
2732 |
+
} else {
|
2733 |
+
type = "single";
|
2734 |
+
lastClick = {time: now, pos: start};
|
2735 |
+
}
|
2736 |
+
|
2737 |
+
var sel = cm.doc.sel, modifier = mac ? e.metaKey : e.ctrlKey;
|
2738 |
+
if (cm.options.dragDrop && dragAndDrop && !isReadOnly(cm) &&
|
2739 |
+
type == "single" && sel.contains(start) > -1 && sel.somethingSelected())
|
2740 |
+
leftButtonStartDrag(cm, e, start, modifier);
|
2741 |
+
else
|
2742 |
+
leftButtonSelect(cm, e, start, type, modifier);
|
2743 |
+
}
|
2744 |
+
|
2745 |
+
// Start a text drag. When it ends, see if any dragging actually
|
2746 |
+
// happen, and treat as a click if it didn't.
|
2747 |
+
function leftButtonStartDrag(cm, e, start, modifier) {
|
2748 |
+
var display = cm.display;
|
2749 |
+
var dragEnd = operation(cm, function(e2) {
|
2750 |
+
if (webkit) display.scroller.draggable = false;
|
2751 |
+
cm.state.draggingText = false;
|
2752 |
+
off(document, "mouseup", dragEnd);
|
2753 |
+
off(display.scroller, "drop", dragEnd);
|
2754 |
+
if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
|
2755 |
+
e_preventDefault(e2);
|
2756 |
+
if (!modifier)
|
2757 |
+
extendSelection(cm.doc, start);
|
2758 |
+
focusInput(cm);
|
2759 |
+
// Work around unexplainable focus problem in IE9 (#2127)
|
2760 |
+
if (ie && ie_version == 9)
|
2761 |
+
setTimeout(function() {document.body.focus(); focusInput(cm);}, 20);
|
2762 |
+
}
|
2763 |
+
});
|
2764 |
+
// Let the drag handler handle this.
|
2765 |
+
if (webkit) display.scroller.draggable = true;
|
2766 |
+
cm.state.draggingText = dragEnd;
|
2767 |
+
// IE's approach to draggable
|
2768 |
+
if (display.scroller.dragDrop) display.scroller.dragDrop();
|
2769 |
+
on(document, "mouseup", dragEnd);
|
2770 |
+
on(display.scroller, "drop", dragEnd);
|
2771 |
+
}
|
2772 |
+
|
2773 |
+
// Normal selection, as opposed to text dragging.
|
2774 |
+
function leftButtonSelect(cm, e, start, type, addNew) {
|
2775 |
+
var display = cm.display, doc = cm.doc;
|
2776 |
+
e_preventDefault(e);
|
2777 |
+
|
2778 |
+
var ourRange, ourIndex, startSel = doc.sel;
|
2779 |
+
if (addNew && !e.shiftKey) {
|
2780 |
+
ourIndex = doc.sel.contains(start);
|
2781 |
+
if (ourIndex > -1)
|
2782 |
+
ourRange = doc.sel.ranges[ourIndex];
|
2783 |
+
else
|
2784 |
+
ourRange = new Range(start, start);
|
2785 |
+
} else {
|
2786 |
+
ourRange = doc.sel.primary();
|
2787 |
+
}
|
2788 |
+
|
2789 |
+
if (e.altKey) {
|
2790 |
+
type = "rect";
|
2791 |
+
if (!addNew) ourRange = new Range(start, start);
|
2792 |
+
start = posFromMouse(cm, e, true, true);
|
2793 |
+
ourIndex = -1;
|
2794 |
+
} else if (type == "double") {
|
2795 |
+
var word = findWordAt(cm, start);
|
2796 |
+
if (cm.display.shift || doc.extend)
|
2797 |
+
ourRange = extendRange(doc, ourRange, word.anchor, word.head);
|
2798 |
+
else
|
2799 |
+
ourRange = word;
|
2800 |
+
} else if (type == "triple") {
|
2801 |
+
var line = new Range(Pos(start.line, 0), clipPos(doc, Pos(start.line + 1, 0)));
|
2802 |
+
if (cm.display.shift || doc.extend)
|
2803 |
+
ourRange = extendRange(doc, ourRange, line.anchor, line.head);
|
2804 |
+
else
|
2805 |
+
ourRange = line;
|
2806 |
+
} else {
|
2807 |
+
ourRange = extendRange(doc, ourRange, start);
|
2808 |
+
}
|
2809 |
+
|
2810 |
+
if (!addNew) {
|
2811 |
+
ourIndex = 0;
|
2812 |
+
setSelection(doc, new Selection([ourRange], 0), sel_mouse);
|
2813 |
+
startSel = doc.sel;
|
2814 |
+
} else if (ourIndex > -1) {
|
2815 |
+
replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
|
2816 |
+
} else {
|
2817 |
+
ourIndex = doc.sel.ranges.length;
|
2818 |
+
setSelection(doc, normalizeSelection(doc.sel.ranges.concat([ourRange]), ourIndex),
|
2819 |
+
{scroll: false, origin: "*mouse"});
|
2820 |
+
}
|
2821 |
+
|
2822 |
+
var lastPos = start;
|
2823 |
+
function extendTo(pos) {
|
2824 |
+
if (cmp(lastPos, pos) == 0) return;
|
2825 |
+
lastPos = pos;
|
2826 |
+
|
2827 |
+
if (type == "rect") {
|
2828 |
+
var ranges = [], tabSize = cm.options.tabSize;
|
2829 |
+
var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
|
2830 |
+
var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
|
2831 |
+
var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
|
2832 |
+
for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
|
2833 |
+
line <= end; line++) {
|
2834 |
+
var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
|
2835 |
+
if (left == right)
|
2836 |
+
ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos)));
|
2837 |
+
else if (text.length > leftPos)
|
2838 |
+
ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize))));
|
2839 |
+
}
|
2840 |
+
if (!ranges.length) ranges.push(new Range(start, start));
|
2841 |
+
setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
|
2842 |
+
{origin: "*mouse", scroll: false});
|
2843 |
+
cm.scrollIntoView(pos);
|
2844 |
+
} else {
|
2845 |
+
var oldRange = ourRange;
|
2846 |
+
var anchor = oldRange.anchor, head = pos;
|
2847 |
+
if (type != "single") {
|
2848 |
+
if (type == "double")
|
2849 |
+
var range = findWordAt(cm, pos);
|
2850 |
+
else
|
2851 |
+
var range = new Range(Pos(pos.line, 0), clipPos(doc, Pos(pos.line + 1, 0)));
|
2852 |
+
if (cmp(range.anchor, anchor) > 0) {
|
2853 |
+
head = range.head;
|
2854 |
+
anchor = minPos(oldRange.from(), range.anchor);
|
2855 |
+
} else {
|
2856 |
+
head = range.anchor;
|
2857 |
+
anchor = maxPos(oldRange.to(), range.head);
|
2858 |
+
}
|
2859 |
+
}
|
2860 |
+
var ranges = startSel.ranges.slice(0);
|
2861 |
+
ranges[ourIndex] = new Range(clipPos(doc, anchor), head);
|
2862 |
+
setSelection(doc, normalizeSelection(ranges, ourIndex), sel_mouse);
|
2863 |
+
}
|
2864 |
+
}
|
2865 |
+
|
2866 |
+
var editorSize = display.wrapper.getBoundingClientRect();
|
2867 |
+
// Used to ensure timeout re-tries don't fire when another extend
|
2868 |
+
// happened in the meantime (clearTimeout isn't reliable -- at
|
2869 |
+
// least on Chrome, the timeouts still happen even when cleared,
|
2870 |
+
// if the clear happens after their scheduled firing time).
|
2871 |
+
var counter = 0;
|
2872 |
+
|
2873 |
+
function extend(e) {
|
2874 |
+
var curCount = ++counter;
|
2875 |
+
var cur = posFromMouse(cm, e, true, type == "rect");
|
2876 |
+
if (!cur) return;
|
2877 |
+
if (cmp(cur, lastPos) != 0) {
|
2878 |
+
ensureFocus(cm);
|
2879 |
+
extendTo(cur);
|
2880 |
+
var visible = visibleLines(display, doc);
|
2881 |
+
if (cur.line >= visible.to || cur.line < visible.from)
|
2882 |
+
setTimeout(operation(cm, function(){if (counter == curCount) extend(e);}), 150);
|
2883 |
+
} else {
|
2884 |
+
var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
|
2885 |
+
if (outside) setTimeout(operation(cm, function() {
|
2886 |
+
if (counter != curCount) return;
|
2887 |
+
display.scroller.scrollTop += outside;
|
2888 |
+
extend(e);
|
2889 |
+
}), 50);
|
2890 |
+
}
|
2891 |
+
}
|
2892 |
+
|
2893 |
+
function done(e) {
|
2894 |
+
counter = Infinity;
|
2895 |
+
e_preventDefault(e);
|
2896 |
+
focusInput(cm);
|
2897 |
+
off(document, "mousemove", move);
|
2898 |
+
off(document, "mouseup", up);
|
2899 |
+
doc.history.lastSelOrigin = null;
|
2900 |
+
}
|
2901 |
+
|
2902 |
+
var move = operation(cm, function(e) {
|
2903 |
+
if (!e_button(e)) done(e);
|
2904 |
+
else extend(e);
|
2905 |
+
});
|
2906 |
+
var up = operation(cm, done);
|
2907 |
+
on(document, "mousemove", move);
|
2908 |
+
on(document, "mouseup", up);
|
2909 |
+
}
|
2910 |
+
|
2911 |
+
// Determines whether an event happened in the gutter, and fires the
|
2912 |
+
// handlers for the corresponding event.
|
2913 |
+
function gutterEvent(cm, e, type, prevent, signalfn) {
|
2914 |
+
try { var mX = e.clientX, mY = e.clientY; }
|
2915 |
+
catch(e) { return false; }
|
2916 |
+
if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) return false;
|
2917 |
+
if (prevent) e_preventDefault(e);
|
2918 |
+
|
2919 |
+
var display = cm.display;
|
2920 |
+
var lineBox = display.lineDiv.getBoundingClientRect();
|
2921 |
+
|
2922 |
+
if (mY > lineBox.bottom || !hasHandler(cm, type)) return e_defaultPrevented(e);
|
2923 |
+
mY -= lineBox.top - display.viewOffset;
|
2924 |
+
|
2925 |
+
for (var i = 0; i < cm.options.gutters.length; ++i) {
|
2926 |
+
var g = display.gutters.childNodes[i];
|
2927 |
+
if (g && g.getBoundingClientRect().right >= mX) {
|
2928 |
+
var line = lineAtHeight(cm.doc, mY);
|
2929 |
+
var gutter = cm.options.gutters[i];
|
2930 |
+
signalfn(cm, type, cm, line, gutter, e);
|
2931 |
+
return e_defaultPrevented(e);
|
2932 |
+
}
|
2933 |
+
}
|
2934 |
+
}
|
2935 |
+
|
2936 |
+
function clickInGutter(cm, e) {
|
2937 |
+
return gutterEvent(cm, e, "gutterClick", true, signalLater);
|
2938 |
+
}
|
2939 |
+
|
2940 |
+
// Kludge to work around strange IE behavior where it'll sometimes
|
2941 |
+
// re-fire a series of drag-related events right after the drop (#1551)
|
2942 |
+
var lastDrop = 0;
|
2943 |
+
|
2944 |
+
function onDrop(e) {
|
2945 |
+
var cm = this;
|
2946 |
+
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
|
2947 |
+
return;
|
2948 |
+
e_preventDefault(e);
|
2949 |
+
if (ie) lastDrop = +new Date;
|
2950 |
+
var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
|
2951 |
+
if (!pos || isReadOnly(cm)) return;
|
2952 |
+
// Might be a file drop, in which case we simply extract the text
|
2953 |
+
// and insert it.
|
2954 |
+
if (files && files.length && window.FileReader && window.File) {
|
2955 |
+
var n = files.length, text = Array(n), read = 0;
|
2956 |
+
var loadFile = function(file, i) {
|
2957 |
+
var reader = new FileReader;
|
2958 |
+
reader.onload = operation(cm, function() {
|
2959 |
+
text[i] = reader.result;
|
2960 |
+
if (++read == n) {
|
2961 |
+
pos = clipPos(cm.doc, pos);
|
2962 |
+
var change = {from: pos, to: pos, text: splitLines(text.join("\n")), origin: "paste"};
|
2963 |
+
makeChange(cm.doc, change);
|
2964 |
+
setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)));
|
2965 |
+
}
|
2966 |
+
});
|
2967 |
+
reader.readAsText(file);
|
2968 |
+
};
|
2969 |
+
for (var i = 0; i < n; ++i) loadFile(files[i], i);
|
2970 |
+
} else { // Normal drop
|
2971 |
+
// Don't do a replace if the drop happened inside of the selected text.
|
2972 |
+
if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
|
2973 |
+
cm.state.draggingText(e);
|
2974 |
+
// Ensure the editor is re-focused
|
2975 |
+
setTimeout(bind(focusInput, cm), 20);
|
2976 |
+
return;
|
2977 |
+
}
|
2978 |
+
try {
|
2979 |
+
var text = e.dataTransfer.getData("Text");
|
2980 |
+
if (text) {
|
2981 |
+
if (cm.state.draggingText && !(mac ? e.metaKey : e.ctrlKey))
|
2982 |
+
var selected = cm.listSelections();
|
2983 |
+
setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
|
2984 |
+
if (selected) for (var i = 0; i < selected.length; ++i)
|
2985 |
+
replaceRange(cm.doc, "", selected[i].anchor, selected[i].head, "drag");
|
2986 |
+
cm.replaceSelection(text, "around", "paste");
|
2987 |
+
focusInput(cm);
|
2988 |
+
}
|
2989 |
+
}
|
2990 |
+
catch(e){}
|
2991 |
+
}
|
2992 |
+
}
|
2993 |
+
|
2994 |
+
function onDragStart(cm, e) {
|
2995 |
+
if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return; }
|
2996 |
+
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) return;
|
2997 |
+
|
2998 |
+
e.dataTransfer.setData("Text", cm.getSelection());
|
2999 |
+
|
3000 |
+
// Use dummy image instead of default browsers image.
|
3001 |
+
// Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
|
3002 |
+
if (e.dataTransfer.setDragImage && !safari) {
|
3003 |
+
var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
|
3004 |
+
img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
|
3005 |
+
if (presto) {
|
3006 |
+
img.width = img.height = 1;
|
3007 |
+
cm.display.wrapper.appendChild(img);
|
3008 |
+
// Force a relayout, or Opera won't use our image for some obscure reason
|
3009 |
+
img._top = img.offsetTop;
|
3010 |
+
}
|
3011 |
+
e.dataTransfer.setDragImage(img, 0, 0);
|
3012 |
+
if (presto) img.parentNode.removeChild(img);
|
3013 |
+
}
|
3014 |
+
}
|
3015 |
+
|
3016 |
+
// SCROLL EVENTS
|
3017 |
+
|
3018 |
+
// Sync the scrollable area and scrollbars, ensure the viewport
|
3019 |
+
// covers the visible area.
|
3020 |
+
function setScrollTop(cm, val) {
|
3021 |
+
if (Math.abs(cm.doc.scrollTop - val) < 2) return;
|
3022 |
+
cm.doc.scrollTop = val;
|
3023 |
+
if (!gecko) updateDisplaySimple(cm, {top: val});
|
3024 |
+
if (cm.display.scroller.scrollTop != val) cm.display.scroller.scrollTop = val;
|
3025 |
+
if (cm.display.scrollbarV.scrollTop != val) cm.display.scrollbarV.scrollTop = val;
|
3026 |
+
if (gecko) updateDisplaySimple(cm);
|
3027 |
+
startWorker(cm, 100);
|
3028 |
+
}
|
3029 |
+
// Sync scroller and scrollbar, ensure the gutter elements are
|
3030 |
+
// aligned.
|
3031 |
+
function setScrollLeft(cm, val, isScroller) {
|
3032 |
+
if (isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) return;
|
3033 |
+
val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth);
|
3034 |
+
cm.doc.scrollLeft = val;
|
3035 |
+
alignHorizontally(cm);
|
3036 |
+
if (cm.display.scroller.scrollLeft != val) cm.display.scroller.scrollLeft = val;
|
3037 |
+
if (cm.display.scrollbarH.scrollLeft != val) cm.display.scrollbarH.scrollLeft = val;
|
3038 |
+
}
|
3039 |
+
|
3040 |
+
// Since the delta values reported on mouse wheel events are
|
3041 |
+
// unstandardized between browsers and even browser versions, and
|
3042 |
+
// generally horribly unpredictable, this code starts by measuring
|
3043 |
+
// the scroll effect that the first few mouse wheel events have,
|
3044 |
+
// and, from that, detects the way it can convert deltas to pixel
|
3045 |
+
// offsets afterwards.
|
3046 |
+
//
|
3047 |
+
// The reason we want to know the amount a wheel event will scroll
|
3048 |
+
// is that it gives us a chance to update the display before the
|
3049 |
+
// actual scrolling happens, reducing flickering.
|
3050 |
+
|
3051 |
+
var wheelSamples = 0, wheelPixelsPerUnit = null;
|
3052 |
+
// Fill in a browser-detected starting value on browsers where we
|
3053 |
+
// know one. These don't have to be accurate -- the result of them
|
3054 |
+
// being wrong would just be a slight flicker on the first wheel
|
3055 |
+
// scroll (if it is large enough).
|
3056 |
+
if (ie) wheelPixelsPerUnit = -.53;
|
3057 |
+
else if (gecko) wheelPixelsPerUnit = 15;
|
3058 |
+
else if (chrome) wheelPixelsPerUnit = -.7;
|
3059 |
+
else if (safari) wheelPixelsPerUnit = -1/3;
|
3060 |
+
|
3061 |
+
function onScrollWheel(cm, e) {
|
3062 |
+
var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
|
3063 |
+
if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail;
|
3064 |
+
if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail;
|
3065 |
+
else if (dy == null) dy = e.wheelDelta;
|
3066 |
+
|
3067 |
+
var display = cm.display, scroll = display.scroller;
|
3068 |
+
// Quit if there's nothing to scroll here
|
3069 |
+
if (!(dx && scroll.scrollWidth > scroll.clientWidth ||
|
3070 |
+
dy && scroll.scrollHeight > scroll.clientHeight)) return;
|
3071 |
+
|
3072 |
+
// Webkit browsers on OS X abort momentum scrolls when the target
|
3073 |
+
// of the scroll event is removed from the scrollable element.
|
3074 |
+
// This hack (see related code in patchDisplay) makes sure the
|
3075 |
+
// element is kept around.
|
3076 |
+
if (dy && mac && webkit) {
|
3077 |
+
outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
|
3078 |
+
for (var i = 0; i < view.length; i++) {
|
3079 |
+
if (view[i].node == cur) {
|
3080 |
+
cm.display.currentWheelTarget = cur;
|
3081 |
+
break outer;
|
3082 |
+
}
|
3083 |
+
}
|
3084 |
+
}
|
3085 |
+
}
|
3086 |
+
|
3087 |
+
// On some browsers, horizontal scrolling will cause redraws to
|
3088 |
+
// happen before the gutter has been realigned, causing it to
|
3089 |
+
// wriggle around in a most unseemly way. When we have an
|
3090 |
+
// estimated pixels/delta value, we just handle horizontal
|
3091 |
+
// scrolling entirely here. It'll be slightly off from native, but
|
3092 |
+
// better than glitching out.
|
3093 |
+
if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
|
3094 |
+
if (dy)
|
3095 |
+
setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
|
3096 |
+
setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
|
3097 |
+
e_preventDefault(e);
|
3098 |
+
display.wheelStartX = null; // Abort measurement, if in progress
|
3099 |
+
return;
|
3100 |
+
}
|
3101 |
+
|
3102 |
+
// 'Project' the visible viewport to cover the area that is being
|
3103 |
+
// scrolled into view (if we know enough to estimate it).
|
3104 |
+
if (dy && wheelPixelsPerUnit != null) {
|
3105 |
+
var pixels = dy * wheelPixelsPerUnit;
|
3106 |
+
var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
|
3107 |
+
if (pixels < 0) top = Math.max(0, top + pixels - 50);
|
3108 |
+
else bot = Math.min(cm.doc.height, bot + pixels + 50);
|
3109 |
+
updateDisplaySimple(cm, {top: top, bottom: bot});
|
3110 |
+
}
|
3111 |
+
|
3112 |
+
if (wheelSamples < 20) {
|
3113 |
+
if (display.wheelStartX == null) {
|
3114 |
+
display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
|
3115 |
+
display.wheelDX = dx; display.wheelDY = dy;
|
3116 |
+
setTimeout(function() {
|
3117 |
+
if (display.wheelStartX == null) return;
|
3118 |
+
var movedX = scroll.scrollLeft - display.wheelStartX;
|
3119 |
+
var movedY = scroll.scrollTop - display.wheelStartY;
|
3120 |
+
var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
|
3121 |
+
(movedX && display.wheelDX && movedX / display.wheelDX);
|
3122 |
+
display.wheelStartX = display.wheelStartY = null;
|
3123 |
+
if (!sample) return;
|
3124 |
+
wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
|
3125 |
+
++wheelSamples;
|
3126 |
+
}, 200);
|
3127 |
+
} else {
|
3128 |
+
display.wheelDX += dx; display.wheelDY += dy;
|
3129 |
+
}
|
3130 |
+
}
|
3131 |
+
}
|
3132 |
+
|
3133 |
+
// KEY EVENTS
|
3134 |
+
|
3135 |
+
// Run a handler that was bound to a key.
|
3136 |
+
function doHandleBinding(cm, bound, dropShift) {
|
3137 |
+
if (typeof bound == "string") {
|
3138 |
+
bound = commands[bound];
|
3139 |
+
if (!bound) return false;
|
3140 |
+
}
|
3141 |
+
// Ensure previous input has been read, so that the handler sees a
|
3142 |
+
// consistent view of the document
|
3143 |
+
if (cm.display.pollingFast && readInput(cm)) cm.display.pollingFast = false;
|
3144 |
+
var prevShift = cm.display.shift, done = false;
|
3145 |
+
try {
|
3146 |
+
if (isReadOnly(cm)) cm.state.suppressEdits = true;
|
3147 |
+
if (dropShift) cm.display.shift = false;
|
3148 |
+
done = bound(cm) != Pass;
|
3149 |
+
} finally {
|
3150 |
+
cm.display.shift = prevShift;
|
3151 |
+
cm.state.suppressEdits = false;
|
3152 |
+
}
|
3153 |
+
return done;
|
3154 |
+
}
|
3155 |
+
|
3156 |
+
// Collect the currently active keymaps.
|
3157 |
+
function allKeyMaps(cm) {
|
3158 |
+
var maps = cm.state.keyMaps.slice(0);
|
3159 |
+
if (cm.options.extraKeys) maps.push(cm.options.extraKeys);
|
3160 |
+
maps.push(cm.options.keyMap);
|
3161 |
+
return maps;
|
3162 |
+
}
|
3163 |
+
|
3164 |
+
var maybeTransition;
|
3165 |
+
// Handle a key from the keydown event.
|
3166 |
+
function handleKeyBinding(cm, e) {
|
3167 |
+
// Handle automatic keymap transitions
|
3168 |
+
var startMap = getKeyMap(cm.options.keyMap), next = startMap.auto;
|
3169 |
+
clearTimeout(maybeTransition);
|
3170 |
+
if (next && !isModifierKey(e)) maybeTransition = setTimeout(function() {
|
3171 |
+
if (getKeyMap(cm.options.keyMap) == startMap) {
|
3172 |
+
cm.options.keyMap = (next.call ? next.call(null, cm) : next);
|
3173 |
+
keyMapChanged(cm);
|
3174 |
+
}
|
3175 |
+
}, 50);
|
3176 |
+
|
3177 |
+
var name = keyName(e, true), handled = false;
|
3178 |
+
if (!name) return false;
|
3179 |
+
var keymaps = allKeyMaps(cm);
|
3180 |
+
|
3181 |
+
if (e.shiftKey) {
|
3182 |
+
// First try to resolve full name (including 'Shift-'). Failing
|
3183 |
+
// that, see if there is a cursor-motion command (starting with
|
3184 |
+
// 'go') bound to the keyname without 'Shift-'.
|
3185 |
+
handled = lookupKey("Shift-" + name, keymaps, function(b) {return doHandleBinding(cm, b, true);})
|
3186 |
+
|| lookupKey(name, keymaps, function(b) {
|
3187 |
+
if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
|
3188 |
+
return doHandleBinding(cm, b);
|
3189 |
+
});
|
3190 |
+
} else {
|
3191 |
+
handled = lookupKey(name, keymaps, function(b) { return doHandleBinding(cm, b); });
|
3192 |
+
}
|
3193 |
+
|
3194 |
+
if (handled) {
|
3195 |
+
e_preventDefault(e);
|
3196 |
+
restartBlink(cm);
|
3197 |
+
signalLater(cm, "keyHandled", cm, name, e);
|
3198 |
+
}
|
3199 |
+
return handled;
|
3200 |
+
}
|
3201 |
+
|
3202 |
+
// Handle a key from the keypress event
|
3203 |
+
function handleCharBinding(cm, e, ch) {
|
3204 |
+
var handled = lookupKey("'" + ch + "'", allKeyMaps(cm),
|
3205 |
+
function(b) { return doHandleBinding(cm, b, true); });
|
3206 |
+
if (handled) {
|
3207 |
+
e_preventDefault(e);
|
3208 |
+
restartBlink(cm);
|
3209 |
+
signalLater(cm, "keyHandled", cm, "'" + ch + "'", e);
|
3210 |
+
}
|
3211 |
+
return handled;
|
3212 |
+
}
|
3213 |
+
|
3214 |
+
var lastStoppedKey = null;
|
3215 |
+
function onKeyDown(e) {
|
3216 |
+
var cm = this;
|
3217 |
+
ensureFocus(cm);
|
3218 |
+
if (signalDOMEvent(cm, e)) return;
|
3219 |
+
// IE does strange things with escape.
|
3220 |
+
if (ie && ie_version < 11 && e.keyCode == 27) e.returnValue = false;
|
3221 |
+
var code = e.keyCode;
|
3222 |
+
cm.display.shift = code == 16 || e.shiftKey;
|
3223 |
+
var handled = handleKeyBinding(cm, e);
|
3224 |
+
if (presto) {
|
3225 |
+
lastStoppedKey = handled ? code : null;
|
3226 |
+
// Opera has no cut event... we try to at least catch the key combo
|
3227 |
+
if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
|
3228 |
+
cm.replaceSelection("", null, "cut");
|
3229 |
+
}
|
3230 |
+
|
3231 |
+
// Turn mouse into crosshair when Alt is held on Mac.
|
3232 |
+
if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
|
3233 |
+
showCrossHair(cm);
|
3234 |
+
}
|
3235 |
+
|
3236 |
+
function showCrossHair(cm) {
|
3237 |
+
var lineDiv = cm.display.lineDiv;
|
3238 |
+
addClass(lineDiv, "CodeMirror-crosshair");
|
3239 |
+
|
3240 |
+
function up(e) {
|
3241 |
+
if (e.keyCode == 18 || !e.altKey) {
|
3242 |
+
rmClass(lineDiv, "CodeMirror-crosshair");
|
3243 |
+
off(document, "keyup", up);
|
3244 |
+
off(document, "mouseover", up);
|
3245 |
+
}
|
3246 |
+
}
|
3247 |
+
on(document, "keyup", up);
|
3248 |
+
on(document, "mouseover", up);
|
3249 |
+
}
|
3250 |
+
|
3251 |
+
function onKeyUp(e) {
|
3252 |
+
if (e.keyCode == 16) this.doc.sel.shift = false;
|
3253 |
+
signalDOMEvent(this, e);
|
3254 |
+
}
|
3255 |
+
|
3256 |
+
function onKeyPress(e) {
|
3257 |
+
var cm = this;
|
3258 |
+
if (signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) return;
|
3259 |
+
var keyCode = e.keyCode, charCode = e.charCode;
|
3260 |
+
if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
|
3261 |
+
if (((presto && (!e.which || e.which < 10)) || khtml) && handleKeyBinding(cm, e)) return;
|
3262 |
+
var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
|
3263 |
+
if (handleCharBinding(cm, e, ch)) return;
|
3264 |
+
if (ie && ie_version >= 9) cm.display.inputHasSelection = null;
|
3265 |
+
fastPoll(cm);
|
3266 |
+
}
|
3267 |
+
|
3268 |
+
// FOCUS/BLUR EVENTS
|
3269 |
+
|
3270 |
+
function onFocus(cm) {
|
3271 |
+
if (cm.options.readOnly == "nocursor") return;
|
3272 |
+
if (!cm.state.focused) {
|
3273 |
+
signal(cm, "focus", cm);
|
3274 |
+
cm.state.focused = true;
|
3275 |
+
addClass(cm.display.wrapper, "CodeMirror-focused");
|
3276 |
+
// The prevInput test prevents this from firing when a context
|
3277 |
+
// menu is closed (since the resetInput would kill the
|
3278 |
+
// select-all detection hack)
|
3279 |
+
if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
|
3280 |
+
resetInput(cm);
|
3281 |
+
if (webkit) setTimeout(bind(resetInput, cm, true), 0); // Issue #1730
|
3282 |
+
}
|
3283 |
+
}
|
3284 |
+
slowPoll(cm);
|
3285 |
+
restartBlink(cm);
|
3286 |
+
}
|
3287 |
+
function onBlur(cm) {
|
3288 |
+
if (cm.state.focused) {
|
3289 |
+
signal(cm, "blur", cm);
|
3290 |
+
cm.state.focused = false;
|
3291 |
+
rmClass(cm.display.wrapper, "CodeMirror-focused");
|
3292 |
+
}
|
3293 |
+
clearInterval(cm.display.blinker);
|
3294 |
+
setTimeout(function() {if (!cm.state.focused) cm.display.shift = false;}, 150);
|
3295 |
+
}
|
3296 |
+
|
3297 |
+
// CONTEXT MENU HANDLING
|
3298 |
+
|
3299 |
+
// To make the context menu work, we need to briefly unhide the
|
3300 |
+
// textarea (making it as unobtrusive as possible) to let the
|
3301 |
+
// right-click take effect on it.
|
3302 |
+
function onContextMenu(cm, e) {
|
3303 |
+
if (signalDOMEvent(cm, e, "contextmenu")) return;
|
3304 |
+
var display = cm.display;
|
3305 |
+
if (eventInWidget(display, e) || contextMenuInGutter(cm, e)) return;
|
3306 |
+
|
3307 |
+
var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
|
3308 |
+
if (!pos || presto) return; // Opera is difficult.
|
3309 |
+
|
3310 |
+
// Reset the current text selection only if the click is done outside of the selection
|
3311 |
+
// and 'resetSelectionOnContextMenu' option is true.
|
3312 |
+
var reset = cm.options.resetSelectionOnContextMenu;
|
3313 |
+
if (reset && cm.doc.sel.contains(pos) == -1)
|
3314 |
+
operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll);
|
3315 |
+
|
3316 |
+
var oldCSS = display.input.style.cssText;
|
3317 |
+
display.inputDiv.style.position = "absolute";
|
3318 |
+
display.input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) +
|
3319 |
+
"px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: " +
|
3320 |
+
(ie ? "rgba(255, 255, 255, .05)" : "transparent") +
|
3321 |
+
"; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
|
3322 |
+
if (webkit) var oldScrollY = window.scrollY; // Work around Chrome issue (#2712)
|
3323 |
+
focusInput(cm);
|
3324 |
+
if (webkit) window.scrollTo(null, oldScrollY);
|
3325 |
+
resetInput(cm);
|
3326 |
+
// Adds "Select all" to context menu in FF
|
3327 |
+
if (!cm.somethingSelected()) display.input.value = display.prevInput = " ";
|
3328 |
+
display.selForContextMenu = cm.doc.sel;
|
3329 |
+
clearTimeout(display.detectingSelectAll);
|
3330 |
+
|
3331 |
+
// Select-all will be greyed out if there's nothing to select, so
|
3332 |
+
// this adds a zero-width space so that we can later check whether
|
3333 |
+
// it got selected.
|
3334 |
+
function prepareSelectAllHack() {
|
3335 |
+
if (display.input.selectionStart != null) {
|
3336 |
+
var selected = cm.somethingSelected();
|
3337 |
+
var extval = display.input.value = "\u200b" + (selected ? display.input.value : "");
|
3338 |
+
display.prevInput = selected ? "" : "\u200b";
|
3339 |
+
display.input.selectionStart = 1; display.input.selectionEnd = extval.length;
|
3340 |
+
// Re-set this, in case some other handler touched the
|
3341 |
+
// selection in the meantime.
|
3342 |
+
display.selForContextMenu = cm.doc.sel;
|
3343 |
+
}
|
3344 |
+
}
|
3345 |
+
function rehide() {
|
3346 |
+
display.inputDiv.style.position = "relative";
|
3347 |
+
display.input.style.cssText = oldCSS;
|
3348 |
+
if (ie && ie_version < 9) display.scrollbarV.scrollTop = display.scroller.scrollTop = scrollPos;
|
3349 |
+
slowPoll(cm);
|
3350 |
+
|
3351 |
+
// Try to detect the user choosing select-all
|
3352 |
+
if (display.input.selectionStart != null) {
|
3353 |
+
if (!ie || (ie && ie_version < 9)) prepareSelectAllHack();
|
3354 |
+
var i = 0, poll = function() {
|
3355 |
+
if (display.selForContextMenu == cm.doc.sel && display.input.selectionStart == 0)
|
3356 |
+
operation(cm, commands.selectAll)(cm);
|
3357 |
+
else if (i++ < 10) display.detectingSelectAll = setTimeout(poll, 500);
|
3358 |
+
else resetInput(cm);
|
3359 |
+
};
|
3360 |
+
display.detectingSelectAll = setTimeout(poll, 200);
|
3361 |
+
}
|
3362 |
+
}
|
3363 |
+
|
3364 |
+
if (ie && ie_version >= 9) prepareSelectAllHack();
|
3365 |
+
if (captureRightClick) {
|
3366 |
+
e_stop(e);
|
3367 |
+
var mouseup = function() {
|
3368 |
+
off(window, "mouseup", mouseup);
|
3369 |
+
setTimeout(rehide, 20);
|
3370 |
+
};
|
3371 |
+
on(window, "mouseup", mouseup);
|
3372 |
+
} else {
|
3373 |
+
setTimeout(rehide, 50);
|
3374 |
+
}
|
3375 |
+
}
|
3376 |
+
|
3377 |
+
function contextMenuInGutter(cm, e) {
|
3378 |
+
if (!hasHandler(cm, "gutterContextMenu")) return false;
|
3379 |
+
return gutterEvent(cm, e, "gutterContextMenu", false, signal);
|
3380 |
+
}
|
3381 |
+
|
3382 |
+
// UPDATING
|
3383 |
+
|
3384 |
+
// Compute the position of the end of a change (its 'to' property
|
3385 |
+
// refers to the pre-change end).
|
3386 |
+
var changeEnd = CodeMirror.changeEnd = function(change) {
|
3387 |
+
if (!change.text) return change.to;
|
3388 |
+
return Pos(change.from.line + change.text.length - 1,
|
3389 |
+
lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0));
|
3390 |
+
};
|
3391 |
+
|
3392 |
+
// Adjust a position to refer to the post-change position of the
|
3393 |
+
// same text, or the end of the change if the change covers it.
|
3394 |
+
function adjustForChange(pos, change) {
|
3395 |
+
if (cmp(pos, change.from) < 0) return pos;
|
3396 |
+
if (cmp(pos, change.to) <= 0) return changeEnd(change);
|
3397 |
+
|
3398 |
+
var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
|
3399 |
+
if (pos.line == change.to.line) ch += changeEnd(change).ch - change.to.ch;
|
3400 |
+
return Pos(line, ch);
|
3401 |
+
}
|
3402 |
+
|
3403 |
+
function computeSelAfterChange(doc, change) {
|
3404 |
+
var out = [];
|
3405 |
+
for (var i = 0; i < doc.sel.ranges.length; i++) {
|
3406 |
+
var range = doc.sel.ranges[i];
|
3407 |
+
out.push(new Range(adjustForChange(range.anchor, change),
|
3408 |
+
adjustForChange(range.head, change)));
|
3409 |
+
}
|
3410 |
+
return normalizeSelection(out, doc.sel.primIndex);
|
3411 |
+
}
|
3412 |
+
|
3413 |
+
function offsetPos(pos, old, nw) {
|
3414 |
+
if (pos.line == old.line)
|
3415 |
+
return Pos(nw.line, pos.ch - old.ch + nw.ch);
|
3416 |
+
else
|
3417 |
+
return Pos(nw.line + (pos.line - old.line), pos.ch);
|
3418 |
+
}
|
3419 |
+
|
3420 |
+
// Used by replaceSelections to allow moving the selection to the
|
3421 |
+
// start or around the replaced test. Hint may be "start" or "around".
|
3422 |
+
function computeReplacedSel(doc, changes, hint) {
|
3423 |
+
var out = [];
|
3424 |
+
var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
|
3425 |
+
for (var i = 0; i < changes.length; i++) {
|
3426 |
+
var change = changes[i];
|
3427 |
+
var from = offsetPos(change.from, oldPrev, newPrev);
|
3428 |
+
var to = offsetPos(changeEnd(change), oldPrev, newPrev);
|
3429 |
+
oldPrev = change.to;
|
3430 |
+
newPrev = to;
|
3431 |
+
if (hint == "around") {
|
3432 |
+
var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
|
3433 |
+
out[i] = new Range(inv ? to : from, inv ? from : to);
|
3434 |
+
} else {
|
3435 |
+
out[i] = new Range(from, from);
|
3436 |
+
}
|
3437 |
+
}
|
3438 |
+
return new Selection(out, doc.sel.primIndex);
|
3439 |
+
}
|
3440 |
+
|
3441 |
+
// Allow "beforeChange" event handlers to influence a change
|
3442 |
+
function filterChange(doc, change, update) {
|
3443 |
+
var obj = {
|
3444 |
+
canceled: false,
|
3445 |
+
from: change.from,
|
3446 |
+
to: change.to,
|
3447 |
+
text: change.text,
|
3448 |
+
origin: change.origin,
|
3449 |
+
cancel: function() { this.canceled = true; }
|
3450 |
+
};
|
3451 |
+
if (update) obj.update = function(from, to, text, origin) {
|
3452 |
+
if (from) this.from = clipPos(doc, from);
|
3453 |
+
if (to) this.to = clipPos(doc, to);
|
3454 |
+
if (text) this.text = text;
|
3455 |
+
if (origin !== undefined) this.origin = origin;
|
3456 |
+
};
|
3457 |
+
signal(doc, "beforeChange", doc, obj);
|
3458 |
+
if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj);
|
3459 |
+
|
3460 |
+
if (obj.canceled) return null;
|
3461 |
+
return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin};
|
3462 |
+
}
|
3463 |
+
|
3464 |
+
// Apply a change to a document, and add it to the document's
|
3465 |
+
// history, and propagating it to all linked documents.
|
3466 |
+
function makeChange(doc, change, ignoreReadOnly) {
|
3467 |
+
if (doc.cm) {
|
3468 |
+
if (!doc.cm.curOp) return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly);
|
3469 |
+
if (doc.cm.state.suppressEdits) return;
|
3470 |
+
}
|
3471 |
+
|
3472 |
+
if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
|
3473 |
+
change = filterChange(doc, change, true);
|
3474 |
+
if (!change) return;
|
3475 |
+
}
|
3476 |
+
|
3477 |
+
// Possibly split or suppress the update based on the presence
|
3478 |
+
// of read-only spans in its range.
|
3479 |
+
var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
|
3480 |
+
if (split) {
|
3481 |
+
for (var i = split.length - 1; i >= 0; --i)
|
3482 |
+
makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text});
|
3483 |
+
} else {
|
3484 |
+
makeChangeInner(doc, change);
|
3485 |
+
}
|
3486 |
+
}
|
3487 |
+
|
3488 |
+
function makeChangeInner(doc, change) {
|
3489 |
+
if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) return;
|
3490 |
+
var selAfter = computeSelAfterChange(doc, change);
|
3491 |
+
addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
|
3492 |
+
|
3493 |
+
makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
|
3494 |
+
var rebased = [];
|
3495 |
+
|
3496 |
+
linkedDocs(doc, function(doc, sharedHist) {
|
3497 |
+
if (!sharedHist && indexOf(rebased, doc.history) == -1) {
|
3498 |
+
rebaseHist(doc.history, change);
|
3499 |
+
rebased.push(doc.history);
|
3500 |
+
}
|
3501 |
+
makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
|
3502 |
+
});
|
3503 |
+
}
|
3504 |
+
|
3505 |
+
// Revert a change stored in a document's history.
|
3506 |
+
function makeChangeFromHistory(doc, type, allowSelectionOnly) {
|
3507 |
+
if (doc.cm && doc.cm.state.suppressEdits) return;
|
3508 |
+
|
3509 |
+
var hist = doc.history, event, selAfter = doc.sel;
|
3510 |
+
var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
|
3511 |
+
|
3512 |
+
// Verify that there is a useable event (so that ctrl-z won't
|
3513 |
+
// needlessly clear selection events)
|
3514 |
+
for (var i = 0; i < source.length; i++) {
|
3515 |
+
event = source[i];
|
3516 |
+
if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
|
3517 |
+
break;
|
3518 |
+
}
|
3519 |
+
if (i == source.length) return;
|
3520 |
+
hist.lastOrigin = hist.lastSelOrigin = null;
|
3521 |
+
|
3522 |
+
for (;;) {
|
3523 |
+
event = source.pop();
|
3524 |
+
if (event.ranges) {
|
3525 |
+
pushSelectionToHistory(event, dest);
|
3526 |
+
if (allowSelectionOnly && !event.equals(doc.sel)) {
|
3527 |
+
setSelection(doc, event, {clearRedo: false});
|
3528 |
+
return;
|
3529 |
+
}
|
3530 |
+
selAfter = event;
|
3531 |
+
}
|
3532 |
+
else break;
|
3533 |
+
}
|
3534 |
+
|
3535 |
+
// Build up a reverse change object to add to the opposite history
|
3536 |
+
// stack (redo when undoing, and vice versa).
|
3537 |
+
var antiChanges = [];
|
3538 |
+
pushSelectionToHistory(selAfter, dest);
|
3539 |
+
dest.push({changes: antiChanges, generation: hist.generation});
|
3540 |
+
hist.generation = event.generation || ++hist.maxGeneration;
|
3541 |
+
|
3542 |
+
var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
|
3543 |
+
|
3544 |
+
for (var i = event.changes.length - 1; i >= 0; --i) {
|
3545 |
+
var change = event.changes[i];
|
3546 |
+
change.origin = type;
|
3547 |
+
if (filter && !filterChange(doc, change, false)) {
|
3548 |
+
source.length = 0;
|
3549 |
+
return;
|
3550 |
+
}
|
3551 |
+
|
3552 |
+
antiChanges.push(historyChangeFromChange(doc, change));
|
3553 |
+
|
3554 |
+
var after = i ? computeSelAfterChange(doc, change) : lst(source);
|
3555 |
+
makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
|
3556 |
+
if (!i && doc.cm) doc.cm.scrollIntoView(change);
|
3557 |
+
var rebased = [];
|
3558 |
+
|
3559 |
+
// Propagate to the linked documents
|
3560 |
+
linkedDocs(doc, function(doc, sharedHist) {
|
3561 |
+
if (!sharedHist && indexOf(rebased, doc.history) == -1) {
|
3562 |
+
rebaseHist(doc.history, change);
|
3563 |
+
rebased.push(doc.history);
|
3564 |
+
}
|
3565 |
+
makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
|
3566 |
+
});
|
3567 |
+
}
|
3568 |
+
}
|
3569 |
+
|
3570 |
+
// Sub-views need their line numbers shifted when text is added
|
3571 |
+
// above or below them in the parent document.
|
3572 |
+
function shiftDoc(doc, distance) {
|
3573 |
+
if (distance == 0) return;
|
3574 |
+
doc.first += distance;
|
3575 |
+
doc.sel = new Selection(map(doc.sel.ranges, function(range) {
|
3576 |
+
return new Range(Pos(range.anchor.line + distance, range.anchor.ch),
|
3577 |
+
Pos(range.head.line + distance, range.head.ch));
|
3578 |
+
}), doc.sel.primIndex);
|
3579 |
+
if (doc.cm) {
|
3580 |
+
regChange(doc.cm, doc.first, doc.first - distance, distance);
|
3581 |
+
for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
|
3582 |
+
regLineChange(doc.cm, l, "gutter");
|
3583 |
+
}
|
3584 |
+
}
|
3585 |
+
|
3586 |
+
// More lower-level change function, handling only a single document
|
3587 |
+
// (not linked ones).
|
3588 |
+
function makeChangeSingleDoc(doc, change, selAfter, spans) {
|
3589 |
+
if (doc.cm && !doc.cm.curOp)
|
3590 |
+
return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans);
|
3591 |
+
|
3592 |
+
if (change.to.line < doc.first) {
|
3593 |
+
shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
|
3594 |
+
return;
|
3595 |
+
}
|
3596 |
+
if (change.from.line > doc.lastLine()) return;
|
3597 |
+
|
3598 |
+
// Clip the change to the size of this doc
|
3599 |
+
if (change.from.line < doc.first) {
|
3600 |
+
var shift = change.text.length - 1 - (doc.first - change.from.line);
|
3601 |
+
shiftDoc(doc, shift);
|
3602 |
+
change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
|
3603 |
+
text: [lst(change.text)], origin: change.origin};
|
3604 |
+
}
|
3605 |
+
var last = doc.lastLine();
|
3606 |
+
if (change.to.line > last) {
|
3607 |
+
change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
|
3608 |
+
text: [change.text[0]], origin: change.origin};
|
3609 |
+
}
|
3610 |
+
|
3611 |
+
change.removed = getBetween(doc, change.from, change.to);
|
3612 |
+
|
3613 |
+
if (!selAfter) selAfter = computeSelAfterChange(doc, change);
|
3614 |
+
if (doc.cm) makeChangeSingleDocInEditor(doc.cm, change, spans);
|
3615 |
+
else updateDoc(doc, change, spans);
|
3616 |
+
setSelectionNoUndo(doc, selAfter, sel_dontScroll);
|
3617 |
+
}
|
3618 |
+
|
3619 |
+
// Handle the interaction of a change to a document with the editor
|
3620 |
+
// that this document is part of.
|
3621 |
+
function makeChangeSingleDocInEditor(cm, change, spans) {
|
3622 |
+
var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
|
3623 |
+
|
3624 |
+
var recomputeMaxLength = false, checkWidthStart = from.line;
|
3625 |
+
if (!cm.options.lineWrapping) {
|
3626 |
+
checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
|
3627 |
+
doc.iter(checkWidthStart, to.line + 1, function(line) {
|
3628 |
+
if (line == display.maxLine) {
|
3629 |
+
recomputeMaxLength = true;
|
3630 |
+
return true;
|
3631 |
+
}
|
3632 |
+
});
|
3633 |
+
}
|
3634 |
+
|
3635 |
+
if (doc.sel.contains(change.from, change.to) > -1)
|
3636 |
+
signalCursorActivity(cm);
|
3637 |
+
|
3638 |
+
updateDoc(doc, change, spans, estimateHeight(cm));
|
3639 |
+
|
3640 |
+
if (!cm.options.lineWrapping) {
|
3641 |
+
doc.iter(checkWidthStart, from.line + change.text.length, function(line) {
|
3642 |
+
var len = lineLength(line);
|
3643 |
+
if (len > display.maxLineLength) {
|
3644 |
+
display.maxLine = line;
|
3645 |
+
display.maxLineLength = len;
|
3646 |
+
display.maxLineChanged = true;
|
3647 |
+
recomputeMaxLength = false;
|
3648 |
+
}
|
3649 |
+
});
|
3650 |
+
if (recomputeMaxLength) cm.curOp.updateMaxLine = true;
|
3651 |
+
}
|
3652 |
+
|
3653 |
+
// Adjust frontier, schedule worker
|
3654 |
+
doc.frontier = Math.min(doc.frontier, from.line);
|
3655 |
+
startWorker(cm, 400);
|
3656 |
+
|
3657 |
+
var lendiff = change.text.length - (to.line - from.line) - 1;
|
3658 |
+
// Remember that these lines changed, for updating the display
|
3659 |
+
if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
|
3660 |
+
regLineChange(cm, from.line, "text");
|
3661 |
+
else
|
3662 |
+
regChange(cm, from.line, to.line + 1, lendiff);
|
3663 |
+
|
3664 |
+
var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
|
3665 |
+
if (changeHandler || changesHandler) {
|
3666 |
+
var obj = {
|
3667 |
+
from: from, to: to,
|
3668 |
+
text: change.text,
|
3669 |
+
removed: change.removed,
|
3670 |
+
origin: change.origin
|
3671 |
+
};
|
3672 |
+
if (changeHandler) signalLater(cm, "change", cm, obj);
|
3673 |
+
if (changesHandler) (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj);
|
3674 |
+
}
|
3675 |
+
cm.display.selForContextMenu = null;
|
3676 |
+
}
|
3677 |
+
|
3678 |
+
function replaceRange(doc, code, from, to, origin) {
|
3679 |
+
if (!to) to = from;
|
3680 |
+
if (cmp(to, from) < 0) { var tmp = to; to = from; from = tmp; }
|
3681 |
+
if (typeof code == "string") code = splitLines(code);
|
3682 |
+
makeChange(doc, {from: from, to: to, text: code, origin: origin});
|
3683 |
+
}
|
3684 |
+
|
3685 |
+
// SCROLLING THINGS INTO VIEW
|
3686 |
+
|
3687 |
+
// If an editor sits on the top or bottom of the window, partially
|
3688 |
+
// scrolled out of view, this ensures that the cursor is visible.
|
3689 |
+
function maybeScrollWindow(cm, coords) {
|
3690 |
+
var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
|
3691 |
+
if (coords.top + box.top < 0) doScroll = true;
|
3692 |
+
else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
|
3693 |
+
if (doScroll != null && !phantom) {
|
3694 |
+
var scrollNode = elt("div", "\u200b", null, "position: absolute; top: " +
|
3695 |
+
(coords.top - display.viewOffset - paddingTop(cm.display)) + "px; height: " +
|
3696 |
+
(coords.bottom - coords.top + scrollerCutOff) + "px; left: " +
|
3697 |
+
coords.left + "px; width: 2px;");
|
3698 |
+
cm.display.lineSpace.appendChild(scrollNode);
|
3699 |
+
scrollNode.scrollIntoView(doScroll);
|
3700 |
+
cm.display.lineSpace.removeChild(scrollNode);
|
3701 |
+
}
|
3702 |
+
}
|
3703 |
+
|
3704 |
+
// Scroll a given position into view (immediately), verifying that
|
3705 |
+
// it actually became visible (as line heights are accurately
|
3706 |
+
// measured, the position of something may 'drift' during drawing).
|
3707 |
+
function scrollPosIntoView(cm, pos, end, margin) {
|
3708 |
+
if (margin == null) margin = 0;
|
3709 |
+
for (;;) {
|
3710 |
+
var changed = false, coords = cursorCoords(cm, pos);
|
3711 |
+
var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
|
3712 |
+
var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
|
3713 |
+
Math.min(coords.top, endCoords.top) - margin,
|
3714 |
+
Math.max(coords.left, endCoords.left),
|
3715 |
+
Math.max(coords.bottom, endCoords.bottom) + margin);
|
3716 |
+
var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
|
3717 |
+
if (scrollPos.scrollTop != null) {
|
3718 |
+
setScrollTop(cm, scrollPos.scrollTop);
|
3719 |
+
if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true;
|
3720 |
+
}
|
3721 |
+
if (scrollPos.scrollLeft != null) {
|
3722 |
+
setScrollLeft(cm, scrollPos.scrollLeft);
|
3723 |
+
if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true;
|
3724 |
+
}
|
3725 |
+
if (!changed) return coords;
|
3726 |
+
}
|
3727 |
+
}
|
3728 |
+
|
3729 |
+
// Scroll a given set of coordinates into view (immediately).
|
3730 |
+
function scrollIntoView(cm, x1, y1, x2, y2) {
|
3731 |
+
var scrollPos = calculateScrollPos(cm, x1, y1, x2, y2);
|
3732 |
+
if (scrollPos.scrollTop != null) setScrollTop(cm, scrollPos.scrollTop);
|
3733 |
+
if (scrollPos.scrollLeft != null) setScrollLeft(cm, scrollPos.scrollLeft);
|
3734 |
+
}
|
3735 |
+
|
3736 |
+
// Calculate a new scroll position needed to scroll the given
|
3737 |
+
// rectangle into view. Returns an object with scrollTop and
|
3738 |
+
// scrollLeft properties. When these are undefined, the
|
3739 |
+
// vertical/horizontal position does not need to be adjusted.
|
3740 |
+
function calculateScrollPos(cm, x1, y1, x2, y2) {
|
3741 |
+
var display = cm.display, snapMargin = textHeight(cm.display);
|
3742 |
+
if (y1 < 0) y1 = 0;
|
3743 |
+
var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
|
3744 |
+
var screen = display.scroller.clientHeight - scrollerCutOff, result = {};
|
3745 |
+
var docBottom = cm.doc.height + paddingVert(display);
|
3746 |
+
var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin;
|
3747 |
+
if (y1 < screentop) {
|
3748 |
+
result.scrollTop = atTop ? 0 : y1;
|
3749 |
+
} else if (y2 > screentop + screen) {
|
3750 |
+
var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen);
|
3751 |
+
if (newTop != screentop) result.scrollTop = newTop;
|
3752 |
+
}
|
3753 |
+
|
3754 |
+
var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
|
3755 |
+
var screenw = display.scroller.clientWidth - scrollerCutOff;
|
3756 |
+
x1 += display.gutters.offsetWidth; x2 += display.gutters.offsetWidth;
|
3757 |
+
var gutterw = display.gutters.offsetWidth;
|
3758 |
+
var atLeft = x1 < gutterw + 10;
|
3759 |
+
if (x1 < screenleft + gutterw || atLeft) {
|
3760 |
+
if (atLeft) x1 = 0;
|
3761 |
+
result.scrollLeft = Math.max(0, x1 - 10 - gutterw);
|
3762 |
+
} else if (x2 > screenw + screenleft - 3) {
|
3763 |
+
result.scrollLeft = x2 + 10 - screenw;
|
3764 |
+
}
|
3765 |
+
return result;
|
3766 |
+
}
|
3767 |
+
|
3768 |
+
// Store a relative adjustment to the scroll position in the current
|
3769 |
+
// operation (to be applied when the operation finishes).
|
3770 |
+
function addToScrollPos(cm, left, top) {
|
3771 |
+
if (left != null || top != null) resolveScrollToPos(cm);
|
3772 |
+
if (left != null)
|
3773 |
+
cm.curOp.scrollLeft = (cm.curOp.scrollLeft == null ? cm.doc.scrollLeft : cm.curOp.scrollLeft) + left;
|
3774 |
+
if (top != null)
|
3775 |
+
cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;
|
3776 |
+
}
|
3777 |
+
|
3778 |
+
// Make sure that at the end of the operation the current cursor is
|
3779 |
+
// shown.
|
3780 |
+
function ensureCursorVisible(cm) {
|
3781 |
+
resolveScrollToPos(cm);
|
3782 |
+
var cur = cm.getCursor(), from = cur, to = cur;
|
3783 |
+
if (!cm.options.lineWrapping) {
|
3784 |
+
from = cur.ch ? Pos(cur.line, cur.ch - 1) : cur;
|
3785 |
+
to = Pos(cur.line, cur.ch + 1);
|
3786 |
+
}
|
3787 |
+
cm.curOp.scrollToPos = {from: from, to: to, margin: cm.options.cursorScrollMargin, isCursor: true};
|
3788 |
+
}
|
3789 |
+
|
3790 |
+
// When an operation has its scrollToPos property set, and another
|
3791 |
+
// scroll action is applied before the end of the operation, this
|
3792 |
+
// 'simulates' scrolling that position into view in a cheap way, so
|
3793 |
+
// that the effect of intermediate scroll commands is not ignored.
|
3794 |
+
function resolveScrollToPos(cm) {
|
3795 |
+
var range = cm.curOp.scrollToPos;
|
3796 |
+
if (range) {
|
3797 |
+
cm.curOp.scrollToPos = null;
|
3798 |
+
var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to);
|
3799 |
+
var sPos = calculateScrollPos(cm, Math.min(from.left, to.left),
|
3800 |
+
Math.min(from.top, to.top) - range.margin,
|
3801 |
+
Math.max(from.right, to.right),
|
3802 |
+
Math.max(from.bottom, to.bottom) + range.margin);
|
3803 |
+
cm.scrollTo(sPos.scrollLeft, sPos.scrollTop);
|
3804 |
+
}
|
3805 |
+
}
|
3806 |
+
|
3807 |
+
// API UTILITIES
|
3808 |
+
|
3809 |
+
// Indent the given line. The how parameter can be "smart",
|
3810 |
+
// "add"/null, "subtract", or "prev". When aggressive is false
|
3811 |
+
// (typically set to true for forced single-line indents), empty
|
3812 |
+
// lines are not indented, and places where the mode returns Pass
|
3813 |
+
// are left alone.
|
3814 |
+
function indentLine(cm, n, how, aggressive) {
|
3815 |
+
var doc = cm.doc, state;
|
3816 |
+
if (how == null) how = "add";
|
3817 |
+
if (how == "smart") {
|
3818 |
+
// Fall back to "prev" when the mode doesn't have an indentation
|
3819 |
+
// method.
|
3820 |
+
if (!doc.mode.indent) how = "prev";
|
3821 |
+
else state = getStateBefore(cm, n);
|
3822 |
+
}
|
3823 |
+
|
3824 |
+
var tabSize = cm.options.tabSize;
|
3825 |
+
var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
|
3826 |
+
if (line.stateAfter) line.stateAfter = null;
|
3827 |
+
var curSpaceString = line.text.match(/^\s*/)[0], indentation;
|
3828 |
+
if (!aggressive && !/\S/.test(line.text)) {
|
3829 |
+
indentation = 0;
|
3830 |
+
how = "not";
|
3831 |
+
} else if (how == "smart") {
|
3832 |
+
indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
|
3833 |
+
if (indentation == Pass || indentation > 150) {
|
3834 |
+
if (!aggressive) return;
|
3835 |
+
how = "prev";
|
3836 |
+
}
|
3837 |
+
}
|
3838 |
+
if (how == "prev") {
|
3839 |
+
if (n > doc.first) indentation = countColumn(getLine(doc, n-1).text, null, tabSize);
|
3840 |
+
else indentation = 0;
|
3841 |
+
} else if (how == "add") {
|
3842 |
+
indentation = curSpace + cm.options.indentUnit;
|
3843 |
+
} else if (how == "subtract") {
|
3844 |
+
indentation = curSpace - cm.options.indentUnit;
|
3845 |
+
} else if (typeof how == "number") {
|
3846 |
+
indentation = curSpace + how;
|
3847 |
+
}
|
3848 |
+
indentation = Math.max(0, indentation);
|
3849 |
+
|
3850 |
+
var indentString = "", pos = 0;
|
3851 |
+
if (cm.options.indentWithTabs)
|
3852 |
+
for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
|
3853 |
+
if (pos < indentation) indentString += spaceStr(indentation - pos);
|
3854 |
+
|
3855 |
+
if (indentString != curSpaceString) {
|
3856 |
+
replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
|
3857 |
+
} else {
|
3858 |
+
// Ensure that, if the cursor was in the whitespace at the start
|
3859 |
+
// of the line, it is moved to the end of that space.
|
3860 |
+
for (var i = 0; i < doc.sel.ranges.length; i++) {
|
3861 |
+
var range = doc.sel.ranges[i];
|
3862 |
+
if (range.head.line == n && range.head.ch < curSpaceString.length) {
|
3863 |
+
var pos = Pos(n, curSpaceString.length);
|
3864 |
+
replaceOneSelection(doc, i, new Range(pos, pos));
|
3865 |
+
break;
|
3866 |
+
}
|
3867 |
+
}
|
3868 |
+
}
|
3869 |
+
line.stateAfter = null;
|
3870 |
+
}
|
3871 |
+
|
3872 |
+
// Utility for applying a change to a line by handle or number,
|
3873 |
+
// returning the number and optionally registering the line as
|
3874 |
+
// changed.
|
3875 |
+
function changeLine(doc, handle, changeType, op) {
|
3876 |
+
var no = handle, line = handle;
|
3877 |
+
if (typeof handle == "number") line = getLine(doc, clipLine(doc, handle));
|
3878 |
+
else no = lineNo(handle);
|
3879 |
+
if (no == null) return null;
|
3880 |
+
if (op(line, no) && doc.cm) regLineChange(doc.cm, no, changeType);
|
3881 |
+
return line;
|
3882 |
+
}
|
3883 |
+
|
3884 |
+
// Helper for deleting text near the selection(s), used to implement
|
3885 |
+
// backspace, delete, and similar functionality.
|
3886 |
+
function deleteNearSelection(cm, compute) {
|
3887 |
+
var ranges = cm.doc.sel.ranges, kill = [];
|
3888 |
+
// Build up a set of ranges to kill first, merging overlapping
|
3889 |
+
// ranges.
|
3890 |
+
for (var i = 0; i < ranges.length; i++) {
|
3891 |
+
var toKill = compute(ranges[i]);
|
3892 |
+
while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
|
3893 |
+
var replaced = kill.pop();
|
3894 |
+
if (cmp(replaced.from, toKill.from) < 0) {
|
3895 |
+
toKill.from = replaced.from;
|
3896 |
+
break;
|
3897 |
+
}
|
3898 |
+
}
|
3899 |
+
kill.push(toKill);
|
3900 |
+
}
|
3901 |
+
// Next, remove those actual ranges.
|
3902 |
+
runInOp(cm, function() {
|
3903 |
+
for (var i = kill.length - 1; i >= 0; i--)
|
3904 |
+
replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete");
|
3905 |
+
ensureCursorVisible(cm);
|
3906 |
+
});
|
3907 |
+
}
|
3908 |
+
|
3909 |
+
// Used for horizontal relative motion. Dir is -1 or 1 (left or
|
3910 |
+
// right), unit can be "char", "column" (like char, but doesn't
|
3911 |
+
// cross line boundaries), "word" (across next word), or "group" (to
|
3912 |
+
// the start of next group of word or non-word-non-whitespace
|
3913 |
+
// chars). The visually param controls whether, in right-to-left
|
3914 |
+
// text, direction 1 means to move towards the next index in the
|
3915 |
+
// string, or towards the character to the right of the current
|
3916 |
+
// position. The resulting position will have a hitSide=true
|
3917 |
+
// property if it reached the end of the document.
|
3918 |
+
function findPosH(doc, pos, dir, unit, visually) {
|
3919 |
+
var line = pos.line, ch = pos.ch, origDir = dir;
|
3920 |
+
var lineObj = getLine(doc, line);
|
3921 |
+
var possible = true;
|
3922 |
+
function findNextLine() {
|
3923 |
+
var l = line + dir;
|
3924 |
+
if (l < doc.first || l >= doc.first + doc.size) return (possible = false);
|
3925 |
+
line = l;
|
3926 |
+
return lineObj = getLine(doc, l);
|
3927 |
+
}
|
3928 |
+
function moveOnce(boundToLine) {
|
3929 |
+
var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
|
3930 |
+
if (next == null) {
|
3931 |
+
if (!boundToLine && findNextLine()) {
|
3932 |
+
if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
|
3933 |
+
else ch = dir < 0 ? lineObj.text.length : 0;
|
3934 |
+
} else return (possible = false);
|
3935 |
+
} else ch = next;
|
3936 |
+
return true;
|
3937 |
+
}
|
3938 |
+
|
3939 |
+
if (unit == "char") moveOnce();
|
3940 |
+
else if (unit == "column") moveOnce(true);
|
3941 |
+
else if (unit == "word" || unit == "group") {
|
3942 |
+
var sawType = null, group = unit == "group";
|
3943 |
+
var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
|
3944 |
+
for (var first = true;; first = false) {
|
3945 |
+
if (dir < 0 && !moveOnce(!first)) break;
|
3946 |
+
var cur = lineObj.text.charAt(ch) || "\n";
|
3947 |
+
var type = isWordChar(cur, helper) ? "w"
|
3948 |
+
: group && cur == "\n" ? "n"
|
3949 |
+
: !group || /\s/.test(cur) ? null
|
3950 |
+
: "p";
|
3951 |
+
if (group && !first && !type) type = "s";
|
3952 |
+
if (sawType && sawType != type) {
|
3953 |
+
if (dir < 0) {dir = 1; moveOnce();}
|
3954 |
+
break;
|
3955 |
+
}
|
3956 |
+
|
3957 |
+
if (type) sawType = type;
|
3958 |
+
if (dir > 0 && !moveOnce(!first)) break;
|
3959 |
+
}
|
3960 |
+
}
|
3961 |
+
var result = skipAtomic(doc, Pos(line, ch), origDir, true);
|
3962 |
+
if (!possible) result.hitSide = true;
|
3963 |
+
return result;
|
3964 |
+
}
|
3965 |
+
|
3966 |
+
// For relative vertical movement. Dir may be -1 or 1. Unit can be
|
3967 |
+
// "page" or "line". The resulting position will have a hitSide=true
|
3968 |
+
// property if it reached the end of the document.
|
3969 |
+
function findPosV(cm, pos, dir, unit) {
|
3970 |
+
var doc = cm.doc, x = pos.left, y;
|
3971 |
+
if (unit == "page") {
|
3972 |
+
var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
|
3973 |
+
y = pos.top + dir * (pageSize - (dir < 0 ? 1.5 : .5) * textHeight(cm.display));
|
3974 |
+
} else if (unit == "line") {
|
3975 |
+
y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
|
3976 |
+
}
|
3977 |
+
for (;;) {
|
3978 |
+
var target = coordsChar(cm, x, y);
|
3979 |
+
if (!target.outside) break;
|
3980 |
+
if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break; }
|
3981 |
+
y += dir * 5;
|
3982 |
+
}
|
3983 |
+
return target;
|
3984 |
+
}
|
3985 |
+
|
3986 |
+
// Find the word at the given position (as returned by coordsChar).
|
3987 |
+
function findWordAt(cm, pos) {
|
3988 |
+
var doc = cm.doc, line = getLine(doc, pos.line).text;
|
3989 |
+
var start = pos.ch, end = pos.ch;
|
3990 |
+
if (line) {
|
3991 |
+
var helper = cm.getHelper(pos, "wordChars");
|
3992 |
+
if ((pos.xRel < 0 || end == line.length) && start) --start; else ++end;
|
3993 |
+
var startChar = line.charAt(start);
|
3994 |
+
var check = isWordChar(startChar, helper)
|
3995 |
+
? function(ch) { return isWordChar(ch, helper); }
|
3996 |
+
: /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);}
|
3997 |
+
: function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
|
3998 |
+
while (start > 0 && check(line.charAt(start - 1))) --start;
|
3999 |
+
while (end < line.length && check(line.charAt(end))) ++end;
|
4000 |
+
}
|
4001 |
+
return new Range(Pos(pos.line, start), Pos(pos.line, end));
|
4002 |
+
}
|
4003 |
+
|
4004 |
+
// EDITOR METHODS
|
4005 |
+
|
4006 |
+
// The publicly visible API. Note that methodOp(f) means
|
4007 |
+
// 'wrap f in an operation, performed on its `this` parameter'.
|
4008 |
+
|
4009 |
+
// This is not the complete set of editor methods. Most of the
|
4010 |
+
// methods defined on the Doc type are also injected into
|
4011 |
+
// CodeMirror.prototype, for backwards compatibility and
|
4012 |
+
// convenience.
|
4013 |
+
|
4014 |
+
CodeMirror.prototype = {
|
4015 |
+
constructor: CodeMirror,
|
4016 |
+
focus: function(){window.focus(); focusInput(this); fastPoll(this);},
|
4017 |
+
|
4018 |
+
setOption: function(option, value) {
|
4019 |
+
var options = this.options, old = options[option];
|
4020 |
+
if (options[option] == value && option != "mode") return;
|
4021 |
+
options[option] = value;
|
4022 |
+
if (optionHandlers.hasOwnProperty(option))
|
4023 |
+
operation(this, optionHandlers[option])(this, value, old);
|
4024 |
+
},
|
4025 |
+
|
4026 |
+
getOption: function(option) {return this.options[option];},
|
4027 |
+
getDoc: function() {return this.doc;},
|
4028 |
+
|
4029 |
+
addKeyMap: function(map, bottom) {
|
4030 |
+
this.state.keyMaps[bottom ? "push" : "unshift"](map);
|
4031 |
+
},
|
4032 |
+
removeKeyMap: function(map) {
|
4033 |
+
var maps = this.state.keyMaps;
|
4034 |
+
for (var i = 0; i < maps.length; ++i)
|
4035 |
+
if (maps[i] == map || (typeof maps[i] != "string" && maps[i].name == map)) {
|
4036 |
+
maps.splice(i, 1);
|
4037 |
+
return true;
|
4038 |
+
}
|
4039 |
+
},
|
4040 |
+
|
4041 |
+
addOverlay: methodOp(function(spec, options) {
|
4042 |
+
var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
|
4043 |
+
if (mode.startState) throw new Error("Overlays may not be stateful.");
|
4044 |
+
this.state.overlays.push({mode: mode, modeSpec: spec, opaque: options && options.opaque});
|
4045 |
+
this.state.modeGen++;
|
4046 |
+
regChange(this);
|
4047 |
+
}),
|
4048 |
+
removeOverlay: methodOp(function(spec) {
|
4049 |
+
var overlays = this.state.overlays;
|
4050 |
+
for (var i = 0; i < overlays.length; ++i) {
|
4051 |
+
var cur = overlays[i].modeSpec;
|
4052 |
+
if (cur == spec || typeof spec == "string" && cur.name == spec) {
|
4053 |
+
overlays.splice(i, 1);
|
4054 |
+
this.state.modeGen++;
|
4055 |
+
regChange(this);
|
4056 |
+
return;
|
4057 |
+
}
|
4058 |
+
}
|
4059 |
+
}),
|
4060 |
+
|
4061 |
+
indentLine: methodOp(function(n, dir, aggressive) {
|
4062 |
+
if (typeof dir != "string" && typeof dir != "number") {
|
4063 |
+
if (dir == null) dir = this.options.smartIndent ? "smart" : "prev";
|
4064 |
+
else dir = dir ? "add" : "subtract";
|
4065 |
+
}
|
4066 |
+
if (isLine(this.doc, n)) indentLine(this, n, dir, aggressive);
|
4067 |
+
}),
|
4068 |
+
indentSelection: methodOp(function(how) {
|
4069 |
+
var ranges = this.doc.sel.ranges, end = -1;
|
4070 |
+
for (var i = 0; i < ranges.length; i++) {
|
4071 |
+
var range = ranges[i];
|
4072 |
+
if (!range.empty()) {
|
4073 |
+
var start = Math.max(end, range.from().line);
|
4074 |
+
var to = range.to();
|
4075 |
+
end = Math.min(this.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
|
4076 |
+
for (var j = start; j < end; ++j)
|
4077 |
+
indentLine(this, j, how);
|
4078 |
+
} else if (range.head.line > end) {
|
4079 |
+
indentLine(this, range.head.line, how, true);
|
4080 |
+
end = range.head.line;
|
4081 |
+
if (i == this.doc.sel.primIndex) ensureCursorVisible(this);
|
4082 |
+
}
|
4083 |
+
}
|
4084 |
+
}),
|
4085 |
+
|
4086 |
+
// Fetch the parser token for a given character. Useful for hacks
|
4087 |
+
// that want to inspect the mode state (say, for completion).
|
4088 |
+
getTokenAt: function(pos, precise) {
|
4089 |
+
var doc = this.doc;
|
4090 |
+
pos = clipPos(doc, pos);
|
4091 |
+
var state = getStateBefore(this, pos.line, precise), mode = this.doc.mode;
|
4092 |
+
var line = getLine(doc, pos.line);
|
4093 |
+
var stream = new StringStream(line.text, this.options.tabSize);
|
4094 |
+
while (stream.pos < pos.ch && !stream.eol()) {
|
4095 |
+
stream.start = stream.pos;
|
4096 |
+
var style = readToken(mode, stream, state);
|
4097 |
+
}
|
4098 |
+
return {start: stream.start,
|
4099 |
+
end: stream.pos,
|
4100 |
+
string: stream.current(),
|
4101 |
+
type: style || null,
|
4102 |
+
state: state};
|
4103 |
+
},
|
4104 |
+
|
4105 |
+
getTokenTypeAt: function(pos) {
|
4106 |
+
pos = clipPos(this.doc, pos);
|
4107 |
+
var styles = getLineStyles(this, getLine(this.doc, pos.line));
|
4108 |
+
var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
|
4109 |
+
var type;
|
4110 |
+
if (ch == 0) type = styles[2];
|
4111 |
+
else for (;;) {
|
4112 |
+
var mid = (before + after) >> 1;
|
4113 |
+
if ((mid ? styles[mid * 2 - 1] : 0) >= ch) after = mid;
|
4114 |
+
else if (styles[mid * 2 + 1] < ch) before = mid + 1;
|
4115 |
+
else { type = styles[mid * 2 + 2]; break; }
|
4116 |
+
}
|
4117 |
+
var cut = type ? type.indexOf("cm-overlay ") : -1;
|
4118 |
+
return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1);
|
4119 |
+
},
|
4120 |
+
|
4121 |
+
getModeAt: function(pos) {
|
4122 |
+
var mode = this.doc.mode;
|
4123 |
+
if (!mode.innerMode) return mode;
|
4124 |
+
return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode;
|
4125 |
+
},
|
4126 |
+
|
4127 |
+
getHelper: function(pos, type) {
|
4128 |
+
return this.getHelpers(pos, type)[0];
|
4129 |
+
},
|
4130 |
+
|
4131 |
+
getHelpers: function(pos, type) {
|
4132 |
+
var found = [];
|
4133 |
+
if (!helpers.hasOwnProperty(type)) return helpers;
|
4134 |
+
var help = helpers[type], mode = this.getModeAt(pos);
|
4135 |
+
if (typeof mode[type] == "string") {
|
4136 |
+
if (help[mode[type]]) found.push(help[mode[type]]);
|
4137 |
+
} else if (mode[type]) {
|
4138 |
+
for (var i = 0; i < mode[type].length; i++) {
|
4139 |
+
var val = help[mode[type][i]];
|
4140 |
+
if (val) found.push(val);
|
4141 |
+
}
|
4142 |
+
} else if (mode.helperType && help[mode.helperType]) {
|
4143 |
+
found.push(help[mode.helperType]);
|
4144 |
+
} else if (help[mode.name]) {
|
4145 |
+
found.push(help[mode.name]);
|
4146 |
+
}
|
4147 |
+
for (var i = 0; i < help._global.length; i++) {
|
4148 |
+
var cur = help._global[i];
|
4149 |
+
if (cur.pred(mode, this) && indexOf(found, cur.val) == -1)
|
4150 |
+
found.push(cur.val);
|
4151 |
+
}
|
4152 |
+
return found;
|
4153 |
+
},
|
4154 |
+
|
4155 |
+
getStateAfter: function(line, precise) {
|
4156 |
+
var doc = this.doc;
|
4157 |
+
line = clipLine(doc, line == null ? doc.first + doc.size - 1: line);
|
4158 |
+
return getStateBefore(this, line + 1, precise);
|
4159 |
+
},
|
4160 |
+
|
4161 |
+
cursorCoords: function(start, mode) {
|
4162 |
+
var pos, range = this.doc.sel.primary();
|
4163 |
+
if (start == null) pos = range.head;
|
4164 |
+
else if (typeof start == "object") pos = clipPos(this.doc, start);
|
4165 |
+
else pos = start ? range.from() : range.to();
|
4166 |
+
return cursorCoords(this, pos, mode || "page");
|
4167 |
+
},
|
4168 |
+
|
4169 |
+
charCoords: function(pos, mode) {
|
4170 |
+
return charCoords(this, clipPos(this.doc, pos), mode || "page");
|
4171 |
+
},
|
4172 |
+
|
4173 |
+
coordsChar: function(coords, mode) {
|
4174 |
+
coords = fromCoordSystem(this, coords, mode || "page");
|
4175 |
+
return coordsChar(this, coords.left, coords.top);
|
4176 |
+
},
|
4177 |
+
|
4178 |
+
lineAtHeight: function(height, mode) {
|
4179 |
+
height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top;
|
4180 |
+
return lineAtHeight(this.doc, height + this.display.viewOffset);
|
4181 |
+
},
|
4182 |
+
heightAtLine: function(line, mode) {
|
4183 |
+
var end = false, last = this.doc.first + this.doc.size - 1;
|
4184 |
+
if (line < this.doc.first) line = this.doc.first;
|
4185 |
+
else if (line > last) { line = last; end = true; }
|
4186 |
+
var lineObj = getLine(this.doc, line);
|
4187 |
+
return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page").top +
|
4188 |
+
(end ? this.doc.height - heightAtLine(lineObj) : 0);
|
4189 |
+
},
|
4190 |
+
|
4191 |
+
defaultTextHeight: function() { return textHeight(this.display); },
|
4192 |
+
defaultCharWidth: function() { return charWidth(this.display); },
|
4193 |
+
|
4194 |
+
setGutterMarker: methodOp(function(line, gutterID, value) {
|
4195 |
+
return changeLine(this.doc, line, "gutter", function(line) {
|
4196 |
+
var markers = line.gutterMarkers || (line.gutterMarkers = {});
|
4197 |
+
markers[gutterID] = value;
|
4198 |
+
if (!value && isEmpty(markers)) line.gutterMarkers = null;
|
4199 |
+
return true;
|
4200 |
+
});
|
4201 |
+
}),
|
4202 |
+
|
4203 |
+
clearGutter: methodOp(function(gutterID) {
|
4204 |
+
var cm = this, doc = cm.doc, i = doc.first;
|
4205 |
+
doc.iter(function(line) {
|
4206 |
+
if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
|
4207 |
+
line.gutterMarkers[gutterID] = null;
|
4208 |
+
regLineChange(cm, i, "gutter");
|
4209 |
+
if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null;
|
4210 |
+
}
|
4211 |
+
++i;
|
4212 |
+
});
|
4213 |
+
}),
|
4214 |
+
|
4215 |
+
addLineWidget: methodOp(function(handle, node, options) {
|
4216 |
+
return addLineWidget(this, handle, node, options);
|
4217 |
+
}),
|
4218 |
+
|
4219 |
+
removeLineWidget: function(widget) { widget.clear(); },
|
4220 |
+
|
4221 |
+
lineInfo: function(line) {
|
4222 |
+
if (typeof line == "number") {
|
4223 |
+
if (!isLine(this.doc, line)) return null;
|
4224 |
+
var n = line;
|
4225 |
+
line = getLine(this.doc, line);
|
4226 |
+
if (!line) return null;
|
4227 |
+
} else {
|
4228 |
+
var n = lineNo(line);
|
4229 |
+
if (n == null) return null;
|
4230 |
+
}
|
4231 |
+
return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
|
4232 |
+
textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
|
4233 |
+
widgets: line.widgets};
|
4234 |
+
},
|
4235 |
+
|
4236 |
+
getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo};},
|
4237 |
+
|
4238 |
+
addWidget: function(pos, node, scroll, vert, horiz) {
|
4239 |
+
var display = this.display;
|
4240 |
+
pos = cursorCoords(this, clipPos(this.doc, pos));
|
4241 |
+
var top = pos.bottom, left = pos.left;
|
4242 |
+
node.style.position = "absolute";
|
4243 |
+
display.sizer.appendChild(node);
|
4244 |
+
if (vert == "over") {
|
4245 |
+
top = pos.top;
|
4246 |
+
} else if (vert == "above" || vert == "near") {
|
4247 |
+
var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
|
4248 |
+
hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
|
4249 |
+
// Default to positioning above (if specified and possible); otherwise default to positioning below
|
4250 |
+
if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
|
4251 |
+
top = pos.top - node.offsetHeight;
|
4252 |
+
else if (pos.bottom + node.offsetHeight <= vspace)
|
4253 |
+
top = pos.bottom;
|
4254 |
+
if (left + node.offsetWidth > hspace)
|
4255 |
+
left = hspace - node.offsetWidth;
|
4256 |
+
}
|
4257 |
+
node.style.top = top + "px";
|
4258 |
+
node.style.left = node.style.right = "";
|
4259 |
+
if (horiz == "right") {
|
4260 |
+
left = display.sizer.clientWidth - node.offsetWidth;
|
4261 |
+
node.style.right = "0px";
|
4262 |
+
} else {
|
4263 |
+
if (horiz == "left") left = 0;
|
4264 |
+
else if (horiz == "middle") left = (display.sizer.clientWidth - node.offsetWidth) / 2;
|
4265 |
+
node.style.left = left + "px";
|
4266 |
+
}
|
4267 |
+
if (scroll)
|
4268 |
+
scrollIntoView(this, left, top, left + node.offsetWidth, top + node.offsetHeight);
|
4269 |
+
},
|
4270 |
+
|
4271 |
+
triggerOnKeyDown: methodOp(onKeyDown),
|
4272 |
+
triggerOnKeyPress: methodOp(onKeyPress),
|
4273 |
+
triggerOnKeyUp: onKeyUp,
|
4274 |
+
|
4275 |
+
execCommand: function(cmd) {
|
4276 |
+
if (commands.hasOwnProperty(cmd))
|
4277 |
+
return commands[cmd](this);
|
4278 |
+
},
|
4279 |
+
|
4280 |
+
findPosH: function(from, amount, unit, visually) {
|
4281 |
+
var dir = 1;
|
4282 |
+
if (amount < 0) { dir = -1; amount = -amount; }
|
4283 |
+
for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
|
4284 |
+
cur = findPosH(this.doc, cur, dir, unit, visually);
|
4285 |
+
if (cur.hitSide) break;
|
4286 |
+
}
|
4287 |
+
return cur;
|
4288 |
+
},
|
4289 |
+
|
4290 |
+
moveH: methodOp(function(dir, unit) {
|
4291 |
+
var cm = this;
|
4292 |
+
cm.extendSelectionsBy(function(range) {
|
4293 |
+
if (cm.display.shift || cm.doc.extend || range.empty())
|
4294 |
+
return findPosH(cm.doc, range.head, dir, unit, cm.options.rtlMoveVisually);
|
4295 |
+
else
|
4296 |
+
return dir < 0 ? range.from() : range.to();
|
4297 |
+
}, sel_move);
|
4298 |
+
}),
|
4299 |
+
|
4300 |
+
deleteH: methodOp(function(dir, unit) {
|
4301 |
+
var sel = this.doc.sel, doc = this.doc;
|
4302 |
+
if (sel.somethingSelected())
|
4303 |
+
doc.replaceSelection("", null, "+delete");
|
4304 |
+
else
|
4305 |
+
deleteNearSelection(this, function(range) {
|
4306 |
+
var other = findPosH(doc, range.head, dir, unit, false);
|
4307 |
+
return dir < 0 ? {from: other, to: range.head} : {from: range.head, to: other};
|
4308 |
+
});
|
4309 |
+
}),
|
4310 |
+
|
4311 |
+
findPosV: function(from, amount, unit, goalColumn) {
|
4312 |
+
var dir = 1, x = goalColumn;
|
4313 |
+
if (amount < 0) { dir = -1; amount = -amount; }
|
4314 |
+
for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
|
4315 |
+
var coords = cursorCoords(this, cur, "div");
|
4316 |
+
if (x == null) x = coords.left;
|
4317 |
+
else coords.left = x;
|
4318 |
+
cur = findPosV(this, coords, dir, unit);
|
4319 |
+
if (cur.hitSide) break;
|
4320 |
+
}
|
4321 |
+
return cur;
|
4322 |
+
},
|
4323 |
+
|
4324 |
+
moveV: methodOp(function(dir, unit) {
|
4325 |
+
var cm = this, doc = this.doc, goals = [];
|
4326 |
+
var collapse = !cm.display.shift && !doc.extend && doc.sel.somethingSelected();
|
4327 |
+
doc.extendSelectionsBy(function(range) {
|
4328 |
+
if (collapse)
|
4329 |
+
return dir < 0 ? range.from() : range.to();
|
4330 |
+
var headPos = cursorCoords(cm, range.head, "div");
|
4331 |
+
if (range.goalColumn != null) headPos.left = range.goalColumn;
|
4332 |
+
goals.push(headPos.left);
|
4333 |
+
var pos = findPosV(cm, headPos, dir, unit);
|
4334 |
+
if (unit == "page" && range == doc.sel.primary())
|
4335 |
+
addToScrollPos(cm, null, charCoords(cm, pos, "div").top - headPos.top);
|
4336 |
+
return pos;
|
4337 |
+
}, sel_move);
|
4338 |
+
if (goals.length) for (var i = 0; i < doc.sel.ranges.length; i++)
|
4339 |
+
doc.sel.ranges[i].goalColumn = goals[i];
|
4340 |
+
}),
|
4341 |
+
|
4342 |
+
toggleOverwrite: function(value) {
|
4343 |
+
if (value != null && value == this.state.overwrite) return;
|
4344 |
+
if (this.state.overwrite = !this.state.overwrite)
|
4345 |
+
addClass(this.display.cursorDiv, "CodeMirror-overwrite");
|
4346 |
+
else
|
4347 |
+
rmClass(this.display.cursorDiv, "CodeMirror-overwrite");
|
4348 |
+
|
4349 |
+
signal(this, "overwriteToggle", this, this.state.overwrite);
|
4350 |
+
},
|
4351 |
+
hasFocus: function() { return activeElt() == this.display.input; },
|
4352 |
+
|
4353 |
+
scrollTo: methodOp(function(x, y) {
|
4354 |
+
if (x != null || y != null) resolveScrollToPos(this);
|
4355 |
+
if (x != null) this.curOp.scrollLeft = x;
|
4356 |
+
if (y != null) this.curOp.scrollTop = y;
|
4357 |
+
}),
|
4358 |
+
getScrollInfo: function() {
|
4359 |
+
var scroller = this.display.scroller, co = scrollerCutOff;
|
4360 |
+
return {left: scroller.scrollLeft, top: scroller.scrollTop,
|
4361 |
+
height: scroller.scrollHeight - co, width: scroller.scrollWidth - co,
|
4362 |
+
clientHeight: scroller.clientHeight - co, clientWidth: scroller.clientWidth - co};
|
4363 |
+
},
|
4364 |
+
|
4365 |
+
scrollIntoView: methodOp(function(range, margin) {
|
4366 |
+
if (range == null) {
|
4367 |
+
range = {from: this.doc.sel.primary().head, to: null};
|
4368 |
+
if (margin == null) margin = this.options.cursorScrollMargin;
|
4369 |
+
} else if (typeof range == "number") {
|
4370 |
+
range = {from: Pos(range, 0), to: null};
|
4371 |
+
} else if (range.from == null) {
|
4372 |
+
range = {from: range, to: null};
|
4373 |
+
}
|
4374 |
+
if (!range.to) range.to = range.from;
|
4375 |
+
range.margin = margin || 0;
|
4376 |
+
|
4377 |
+
if (range.from.line != null) {
|
4378 |
+
resolveScrollToPos(this);
|
4379 |
+
this.curOp.scrollToPos = range;
|
4380 |
+
} else {
|
4381 |
+
var sPos = calculateScrollPos(this, Math.min(range.from.left, range.to.left),
|
4382 |
+
Math.min(range.from.top, range.to.top) - range.margin,
|
4383 |
+
Math.max(range.from.right, range.to.right),
|
4384 |
+
Math.max(range.from.bottom, range.to.bottom) + range.margin);
|
4385 |
+
this.scrollTo(sPos.scrollLeft, sPos.scrollTop);
|
4386 |
+
}
|
4387 |
+
}),
|
4388 |
+
|
4389 |
+
setSize: methodOp(function(width, height) {
|
4390 |
+
var cm = this;
|
4391 |
+
function interpret(val) {
|
4392 |
+
return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val;
|
4393 |
+
}
|
4394 |
+
if (width != null) cm.display.wrapper.style.width = interpret(width);
|
4395 |
+
if (height != null) cm.display.wrapper.style.height = interpret(height);
|
4396 |
+
if (cm.options.lineWrapping) clearLineMeasurementCache(this);
|
4397 |
+
var lineNo = cm.display.viewFrom;
|
4398 |
+
cm.doc.iter(lineNo, cm.display.viewTo, function(line) {
|
4399 |
+
if (line.widgets) for (var i = 0; i < line.widgets.length; i++)
|
4400 |
+
if (line.widgets[i].noHScroll) { regLineChange(cm, lineNo, "widget"); break; }
|
4401 |
+
++lineNo;
|
4402 |
+
});
|
4403 |
+
cm.curOp.forceUpdate = true;
|
4404 |
+
signal(cm, "refresh", this);
|
4405 |
+
}),
|
4406 |
+
|
4407 |
+
operation: function(f){return runInOp(this, f);},
|
4408 |
+
|
4409 |
+
refresh: methodOp(function() {
|
4410 |
+
var oldHeight = this.display.cachedTextHeight;
|
4411 |
+
regChange(this);
|
4412 |
+
this.curOp.forceUpdate = true;
|
4413 |
+
clearCaches(this);
|
4414 |
+
this.scrollTo(this.doc.scrollLeft, this.doc.scrollTop);
|
4415 |
+
updateGutterSpace(this);
|
4416 |
+
if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5)
|
4417 |
+
estimateLineHeights(this);
|
4418 |
+
signal(this, "refresh", this);
|
4419 |
+
}),
|
4420 |
+
|
4421 |
+
swapDoc: methodOp(function(doc) {
|
4422 |
+
var old = this.doc;
|
4423 |
+
old.cm = null;
|
4424 |
+
attachDoc(this, doc);
|
4425 |
+
clearCaches(this);
|
4426 |
+
resetInput(this);
|
4427 |
+
this.scrollTo(doc.scrollLeft, doc.scrollTop);
|
4428 |
+
signalLater(this, "swapDoc", this, old);
|
4429 |
+
return old;
|
4430 |
+
}),
|
4431 |
+
|
4432 |
+
getInputField: function(){return this.display.input;},
|
4433 |
+
getWrapperElement: function(){return this.display.wrapper;},
|
4434 |
+
getScrollerElement: function(){return this.display.scroller;},
|
4435 |
+
getGutterElement: function(){return this.display.gutters;}
|
4436 |
+
};
|
4437 |
+
eventMixin(CodeMirror);
|
4438 |
+
|
4439 |
+
// OPTION DEFAULTS
|
4440 |
+
|
4441 |
+
// The default configuration options.
|
4442 |
+
var defaults = CodeMirror.defaults = {};
|
4443 |
+
// Functions to run when options are changed.
|
4444 |
+
var optionHandlers = CodeMirror.optionHandlers = {};
|
4445 |
+
|
4446 |
+
function option(name, deflt, handle, notOnInit) {
|
4447 |
+
CodeMirror.defaults[name] = deflt;
|
4448 |
+
if (handle) optionHandlers[name] =
|
4449 |
+
notOnInit ? function(cm, val, old) {if (old != Init) handle(cm, val, old);} : handle;
|
4450 |
+
}
|
4451 |
+
|
4452 |
+
// Passed to option handlers when there is no old value.
|
4453 |
+
var Init = CodeMirror.Init = {toString: function(){return "CodeMirror.Init";}};
|
4454 |
+
|
4455 |
+
// These two are, on init, called from the constructor because they
|
4456 |
+
// have to be initialized before the editor can start at all.
|
4457 |
+
option("value", "", function(cm, val) {
|
4458 |
+
cm.setValue(val);
|
4459 |
+
}, true);
|
4460 |
+
option("mode", null, function(cm, val) {
|
4461 |
+
cm.doc.modeOption = val;
|
4462 |
+
loadMode(cm);
|
4463 |
+
}, true);
|
4464 |
+
|
4465 |
+
option("indentUnit", 2, loadMode, true);
|
4466 |
+
option("indentWithTabs", false);
|
4467 |
+
option("smartIndent", true);
|
4468 |
+
option("tabSize", 4, function(cm) {
|
4469 |
+
resetModeState(cm);
|
4470 |
+
clearCaches(cm);
|
4471 |
+
regChange(cm);
|
4472 |
+
}, true);
|
4473 |
+
option("specialChars", /[\t\u0000-\u0019\u00ad\u200b\u2028\u2029\ufeff]/g, function(cm, val) {
|
4474 |
+
cm.options.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
|
4475 |
+
cm.refresh();
|
4476 |
+
}, true);
|
4477 |
+
option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function(cm) {cm.refresh();}, true);
|
4478 |
+
option("electricChars", true);
|
4479 |
+
option("rtlMoveVisually", !windows);
|
4480 |
+
option("wholeLineUpdateBefore", true);
|
4481 |
+
|
4482 |
+
option("theme", "default", function(cm) {
|
4483 |
+
themeChanged(cm);
|
4484 |
+
guttersChanged(cm);
|
4485 |
+
}, true);
|
4486 |
+
option("keyMap", "default", keyMapChanged);
|
4487 |
+
option("extraKeys", null);
|
4488 |
+
|
4489 |
+
option("lineWrapping", false, wrappingChanged, true);
|
4490 |
+
option("gutters", [], function(cm) {
|
4491 |
+
setGuttersForLineNumbers(cm.options);
|
4492 |
+
guttersChanged(cm);
|
4493 |
+
}, true);
|
4494 |
+
option("fixedGutter", true, function(cm, val) {
|
4495 |
+
cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
|
4496 |
+
cm.refresh();
|
4497 |
+
}, true);
|
4498 |
+
option("coverGutterNextToScrollbar", false, updateScrollbars, true);
|
4499 |
+
option("lineNumbers", false, function(cm) {
|
4500 |
+
setGuttersForLineNumbers(cm.options);
|
4501 |
+
guttersChanged(cm);
|
4502 |
+
}, true);
|
4503 |
+
option("firstLineNumber", 1, guttersChanged, true);
|
4504 |
+
option("lineNumberFormatter", function(integer) {return integer;}, guttersChanged, true);
|
4505 |
+
option("showCursorWhenSelecting", false, updateSelection, true);
|
4506 |
+
|
4507 |
+
option("resetSelectionOnContextMenu", true);
|
4508 |
+
|
4509 |
+
option("readOnly", false, function(cm, val) {
|
4510 |
+
if (val == "nocursor") {
|
4511 |
+
onBlur(cm);
|
4512 |
+
cm.display.input.blur();
|
4513 |
+
cm.display.disabled = true;
|
4514 |
+
} else {
|
4515 |
+
cm.display.disabled = false;
|
4516 |
+
if (!val) resetInput(cm);
|
4517 |
+
}
|
4518 |
+
});
|
4519 |
+
option("disableInput", false, function(cm, val) {if (!val) resetInput(cm);}, true);
|
4520 |
+
option("dragDrop", true);
|
4521 |
+
|
4522 |
+
option("cursorBlinkRate", 530);
|
4523 |
+
option("cursorScrollMargin", 0);
|
4524 |
+
option("cursorHeight", 1, updateSelection, true);
|
4525 |
+
option("singleCursorHeightPerLine", true, updateSelection, true);
|
4526 |
+
option("workTime", 100);
|
4527 |
+
option("workDelay", 100);
|
4528 |
+
option("flattenSpans", true, resetModeState, true);
|
4529 |
+
option("addModeClass", false, resetModeState, true);
|
4530 |
+
option("pollInterval", 100);
|
4531 |
+
option("undoDepth", 200, function(cm, val){cm.doc.history.undoDepth = val;});
|
4532 |
+
option("historyEventDelay", 1250);
|
4533 |
+
option("viewportMargin", 10, function(cm){cm.refresh();}, true);
|
4534 |
+
option("maxHighlightLength", 10000, resetModeState, true);
|
4535 |
+
option("moveInputWithCursor", true, function(cm, val) {
|
4536 |
+
if (!val) cm.display.inputDiv.style.top = cm.display.inputDiv.style.left = 0;
|
4537 |
+
});
|
4538 |
+
|
4539 |
+
option("tabindex", null, function(cm, val) {
|
4540 |
+
cm.display.input.tabIndex = val || "";
|
4541 |
+
});
|
4542 |
+
option("autofocus", null);
|
4543 |
+
|
4544 |
+
// MODE DEFINITION AND QUERYING
|
4545 |
+
|
4546 |
+
// Known modes, by name and by MIME
|
4547 |
+
var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
|
4548 |
+
|
4549 |
+
// Extra arguments are stored as the mode's dependencies, which is
|
4550 |
+
// used by (legacy) mechanisms like loadmode.js to automatically
|
4551 |
+
// load a mode. (Preferred mechanism is the require/define calls.)
|
4552 |
+
CodeMirror.defineMode = function(name, mode) {
|
4553 |
+
if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
|
4554 |
+
if (arguments.length > 2) {
|
4555 |
+
mode.dependencies = [];
|
4556 |
+
for (var i = 2; i < arguments.length; ++i) mode.dependencies.push(arguments[i]);
|
4557 |
+
}
|
4558 |
+
modes[name] = mode;
|
4559 |
+
};
|
4560 |
+
|
4561 |
+
CodeMirror.defineMIME = function(mime, spec) {
|
4562 |
+
mimeModes[mime] = spec;
|
4563 |
+
};
|
4564 |
+
|
4565 |
+
// Given a MIME type, a {name, ...options} config object, or a name
|
4566 |
+
// string, return a mode config object.
|
4567 |
+
CodeMirror.resolveMode = function(spec) {
|
4568 |
+
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
|
4569 |
+
spec = mimeModes[spec];
|
4570 |
+
} else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
|
4571 |
+
var found = mimeModes[spec.name];
|
4572 |
+
if (typeof found == "string") found = {name: found};
|
4573 |
+
spec = createObj(found, spec);
|
4574 |
+
spec.name = found.name;
|
4575 |
+
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
|
4576 |
+
return CodeMirror.resolveMode("application/xml");
|
4577 |
+
}
|
4578 |
+
if (typeof spec == "string") return {name: spec};
|
4579 |
+
else return spec || {name: "null"};
|
4580 |
+
};
|
4581 |
+
|
4582 |
+
// Given a mode spec (anything that resolveMode accepts), find and
|
4583 |
+
// initialize an actual mode object.
|
4584 |
+
CodeMirror.getMode = function(options, spec) {
|
4585 |
+
var spec = CodeMirror.resolveMode(spec);
|
4586 |
+
var mfactory = modes[spec.name];
|
4587 |
+
if (!mfactory) return CodeMirror.getMode(options, "text/plain");
|
4588 |
+
var modeObj = mfactory(options, spec);
|
4589 |
+
if (modeExtensions.hasOwnProperty(spec.name)) {
|
4590 |
+
var exts = modeExtensions[spec.name];
|
4591 |
+
for (var prop in exts) {
|
4592 |
+
if (!exts.hasOwnProperty(prop)) continue;
|
4593 |
+
if (modeObj.hasOwnProperty(prop)) modeObj["_" + prop] = modeObj[prop];
|
4594 |
+
modeObj[prop] = exts[prop];
|
4595 |
+
}
|
4596 |
+
}
|
4597 |
+
modeObj.name = spec.name;
|
4598 |
+
if (spec.helperType) modeObj.helperType = spec.helperType;
|
4599 |
+
if (spec.modeProps) for (var prop in spec.modeProps)
|
4600 |
+
modeObj[prop] = spec.modeProps[prop];
|
4601 |
+
|
4602 |
+
return modeObj;
|
4603 |
+
};
|
4604 |
+
|
4605 |
+
// Minimal default mode.
|
4606 |
+
CodeMirror.defineMode("null", function() {
|
4607 |
+
return {token: function(stream) {stream.skipToEnd();}};
|
4608 |
+
});
|
4609 |
+
CodeMirror.defineMIME("text/plain", "null");
|
4610 |
+
|
4611 |
+
// This can be used to attach properties to mode objects from
|
4612 |
+
// outside the actual mode definition.
|
4613 |
+
var modeExtensions = CodeMirror.modeExtensions = {};
|
4614 |
+
CodeMirror.extendMode = function(mode, properties) {
|
4615 |
+
var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
|
4616 |
+
copyObj(properties, exts);
|
4617 |
+
};
|
4618 |
+
|
4619 |
+
// EXTENSIONS
|
4620 |
+
|
4621 |
+
CodeMirror.defineExtension = function(name, func) {
|
4622 |
+
CodeMirror.prototype[name] = func;
|
4623 |
+
};
|
4624 |
+
CodeMirror.defineDocExtension = function(name, func) {
|
4625 |
+
Doc.prototype[name] = func;
|
4626 |
+
};
|
4627 |
+
CodeMirror.defineOption = option;
|
4628 |
+
|
4629 |
+
var initHooks = [];
|
4630 |
+
CodeMirror.defineInitHook = function(f) {initHooks.push(f);};
|
4631 |
+
|
4632 |
+
var helpers = CodeMirror.helpers = {};
|
4633 |
+
CodeMirror.registerHelper = function(type, name, value) {
|
4634 |
+
if (!helpers.hasOwnProperty(type)) helpers[type] = CodeMirror[type] = {_global: []};
|
4635 |
+
helpers[type][name] = value;
|
4636 |
+
};
|
4637 |
+
CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
|
4638 |
+
CodeMirror.registerHelper(type, name, value);
|
4639 |
+
helpers[type]._global.push({pred: predicate, val: value});
|
4640 |
+
};
|
4641 |
+
|
4642 |
+
// MODE STATE HANDLING
|
4643 |
+
|
4644 |
+
// Utility functions for working with state. Exported because nested
|
4645 |
+
// modes need to do this for their inner modes.
|
4646 |
+
|
4647 |
+
var copyState = CodeMirror.copyState = function(mode, state) {
|
4648 |
+
if (state === true) return state;
|
4649 |
+
if (mode.copyState) return mode.copyState(state);
|
4650 |
+
var nstate = {};
|
4651 |
+
for (var n in state) {
|
4652 |
+
var val = state[n];
|
4653 |
+
if (val instanceof Array) val = val.concat([]);
|
4654 |
+
nstate[n] = val;
|
4655 |
+
}
|
4656 |
+
return nstate;
|
4657 |
+
};
|
4658 |
+
|
4659 |
+
var startState = CodeMirror.startState = function(mode, a1, a2) {
|
4660 |
+
return mode.startState ? mode.startState(a1, a2) : true;
|
4661 |
+
};
|
4662 |
+
|
4663 |
+
// Given a mode and a state (for that mode), find the inner mode and
|
4664 |
+
// state at the position that the state refers to.
|
4665 |
+
CodeMirror.innerMode = function(mode, state) {
|
4666 |
+
while (mode.innerMode) {
|
4667 |
+
var info = mode.innerMode(state);
|
4668 |
+
if (!info || info.mode == mode) break;
|
4669 |
+
state = info.state;
|
4670 |
+
mode = info.mode;
|
4671 |
+
}
|
4672 |
+
return info || {mode: mode, state: state};
|
4673 |
+
};
|
4674 |
+
|
4675 |
+
// STANDARD COMMANDS
|
4676 |
+
|
4677 |
+
// Commands are parameter-less actions that can be performed on an
|
4678 |
+
// editor, mostly used for keybindings.
|
4679 |
+
var commands = CodeMirror.commands = {
|
4680 |
+
selectAll: function(cm) {cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);},
|
4681 |
+
singleSelection: function(cm) {
|
4682 |
+
cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll);
|
4683 |
+
},
|
4684 |
+
killLine: function(cm) {
|
4685 |
+
deleteNearSelection(cm, function(range) {
|
4686 |
+
if (range.empty()) {
|
4687 |
+
var len = getLine(cm.doc, range.head.line).text.length;
|
4688 |
+
if (range.head.ch == len && range.head.line < cm.lastLine())
|
4689 |
+
return {from: range.head, to: Pos(range.head.line + 1, 0)};
|
4690 |
+
else
|
4691 |
+
return {from: range.head, to: Pos(range.head.line, len)};
|
4692 |
+
} else {
|
4693 |
+
return {from: range.from(), to: range.to()};
|
4694 |
+
}
|
4695 |
+
});
|
4696 |
+
},
|
4697 |
+
deleteLine: function(cm) {
|
4698 |
+
deleteNearSelection(cm, function(range) {
|
4699 |
+
return {from: Pos(range.from().line, 0),
|
4700 |
+
to: clipPos(cm.doc, Pos(range.to().line + 1, 0))};
|
4701 |
+
});
|
4702 |
+
},
|
4703 |
+
delLineLeft: function(cm) {
|
4704 |
+
deleteNearSelection(cm, function(range) {
|
4705 |
+
return {from: Pos(range.from().line, 0), to: range.from()};
|
4706 |
+
});
|
4707 |
+
},
|
4708 |
+
delWrappedLineLeft: function(cm) {
|
4709 |
+
deleteNearSelection(cm, function(range) {
|
4710 |
+
var top = cm.charCoords(range.head, "div").top + 5;
|
4711 |
+
var leftPos = cm.coordsChar({left: 0, top: top}, "div");
|
4712 |
+
return {from: leftPos, to: range.from()};
|
4713 |
+
});
|
4714 |
+
},
|
4715 |
+
delWrappedLineRight: function(cm) {
|
4716 |
+
deleteNearSelection(cm, function(range) {
|
4717 |
+
var top = cm.charCoords(range.head, "div").top + 5;
|
4718 |
+
var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
|
4719 |
+
return {from: range.from(), to: rightPos };
|
4720 |
+
});
|
4721 |
+
},
|
4722 |
+
undo: function(cm) {cm.undo();},
|
4723 |
+
redo: function(cm) {cm.redo();},
|
4724 |
+
undoSelection: function(cm) {cm.undoSelection();},
|
4725 |
+
redoSelection: function(cm) {cm.redoSelection();},
|
4726 |
+
goDocStart: function(cm) {cm.extendSelection(Pos(cm.firstLine(), 0));},
|
4727 |
+
goDocEnd: function(cm) {cm.extendSelection(Pos(cm.lastLine()));},
|
4728 |
+
goLineStart: function(cm) {
|
4729 |
+
cm.extendSelectionsBy(function(range) { return lineStart(cm, range.head.line); },
|
4730 |
+
{origin: "+move", bias: 1});
|
4731 |
+
},
|
4732 |
+
goLineStartSmart: function(cm) {
|
4733 |
+
cm.extendSelectionsBy(function(range) {
|
4734 |
+
var start = lineStart(cm, range.head.line);
|
4735 |
+
var line = cm.getLineHandle(start.line);
|
4736 |
+
var order = getOrder(line);
|
4737 |
+
if (!order || order[0].level == 0) {
|
4738 |
+
var firstNonWS = Math.max(0, line.text.search(/\S/));
|
4739 |
+
var inWS = range.head.line == start.line && range.head.ch <= firstNonWS && range.head.ch;
|
4740 |
+
return Pos(start.line, inWS ? 0 : firstNonWS);
|
4741 |
+
}
|
4742 |
+
return start;
|
4743 |
+
}, {origin: "+move", bias: 1});
|
4744 |
+
},
|
4745 |
+
goLineEnd: function(cm) {
|
4746 |
+
cm.extendSelectionsBy(function(range) { return lineEnd(cm, range.head.line); },
|
4747 |
+
{origin: "+move", bias: -1});
|
4748 |
+
},
|
4749 |
+
goLineRight: function(cm) {
|
4750 |
+
cm.extendSelectionsBy(function(range) {
|
4751 |
+
var top = cm.charCoords(range.head, "div").top + 5;
|
4752 |
+
return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
|
4753 |
+
}, sel_move);
|
4754 |
+
},
|
4755 |
+
goLineLeft: function(cm) {
|
4756 |
+
cm.extendSelectionsBy(function(range) {
|
4757 |
+
var top = cm.charCoords(range.head, "div").top + 5;
|
4758 |
+
return cm.coordsChar({left: 0, top: top}, "div");
|
4759 |
+
}, sel_move);
|
4760 |
+
},
|
4761 |
+
goLineUp: function(cm) {cm.moveV(-1, "line");},
|
4762 |
+
goLineDown: function(cm) {cm.moveV(1, "line");},
|
4763 |
+
goPageUp: function(cm) {cm.moveV(-1, "page");},
|
4764 |
+
goPageDown: function(cm) {cm.moveV(1, "page");},
|
4765 |
+
goCharLeft: function(cm) {cm.moveH(-1, "char");},
|
4766 |
+
goCharRight: function(cm) {cm.moveH(1, "char");},
|
4767 |
+
goColumnLeft: function(cm) {cm.moveH(-1, "column");},
|
4768 |
+
goColumnRight: function(cm) {cm.moveH(1, "column");},
|
4769 |
+
goWordLeft: function(cm) {cm.moveH(-1, "word");},
|
4770 |
+
goGroupRight: function(cm) {cm.moveH(1, "group");},
|
4771 |
+
goGroupLeft: function(cm) {cm.moveH(-1, "group");},
|
4772 |
+
goWordRight: function(cm) {cm.moveH(1, "word");},
|
4773 |
+
delCharBefore: function(cm) {cm.deleteH(-1, "char");},
|
4774 |
+
delCharAfter: function(cm) {cm.deleteH(1, "char");},
|
4775 |
+
delWordBefore: function(cm) {cm.deleteH(-1, "word");},
|
4776 |
+
delWordAfter: function(cm) {cm.deleteH(1, "word");},
|
4777 |
+
delGroupBefore: function(cm) {cm.deleteH(-1, "group");},
|
4778 |
+
delGroupAfter: function(cm) {cm.deleteH(1, "group");},
|
4779 |
+
indentAuto: function(cm) {cm.indentSelection("smart");},
|
4780 |
+
indentMore: function(cm) {cm.indentSelection("add");},
|
4781 |
+
indentLess: function(cm) {cm.indentSelection("subtract");},
|
4782 |
+
insertTab: function(cm) {cm.replaceSelection("\t");},
|
4783 |
+
insertSoftTab: function(cm) {
|
4784 |
+
var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize;
|
4785 |
+
for (var i = 0; i < ranges.length; i++) {
|
4786 |
+
var pos = ranges[i].from();
|
4787 |
+
var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
|
4788 |
+
spaces.push(new Array(tabSize - col % tabSize + 1).join(" "));
|
4789 |
+
}
|
4790 |
+
cm.replaceSelections(spaces);
|
4791 |
+
},
|
4792 |
+
defaultTab: function(cm) {
|
4793 |
+
if (cm.somethingSelected()) cm.indentSelection("add");
|
4794 |
+
else cm.execCommand("insertTab");
|
4795 |
+
},
|
4796 |
+
transposeChars: function(cm) {
|
4797 |
+
runInOp(cm, function() {
|
4798 |
+
var ranges = cm.listSelections(), newSel = [];
|
4799 |
+
for (var i = 0; i < ranges.length; i++) {
|
4800 |
+
var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text;
|
4801 |
+
if (line) {
|
4802 |
+
if (cur.ch == line.length) cur = new Pos(cur.line, cur.ch - 1);
|
4803 |
+
if (cur.ch > 0) {
|
4804 |
+
cur = new Pos(cur.line, cur.ch + 1);
|
4805 |
+
cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
|
4806 |
+
Pos(cur.line, cur.ch - 2), cur, "+transpose");
|
4807 |
+
} else if (cur.line > cm.doc.first) {
|
4808 |
+
var prev = getLine(cm.doc, cur.line - 1).text;
|
4809 |
+
if (prev)
|
4810 |
+
cm.replaceRange(line.charAt(0) + "\n" + prev.charAt(prev.length - 1),
|
4811 |
+
Pos(cur.line - 1, prev.length - 1), Pos(cur.line, 1), "+transpose");
|
4812 |
+
}
|
4813 |
+
}
|
4814 |
+
newSel.push(new Range(cur, cur));
|
4815 |
+
}
|
4816 |
+
cm.setSelections(newSel);
|
4817 |
+
});
|
4818 |
+
},
|
4819 |
+
newlineAndIndent: function(cm) {
|
4820 |
+
runInOp(cm, function() {
|
4821 |
+
var len = cm.listSelections().length;
|
4822 |
+
for (var i = 0; i < len; i++) {
|
4823 |
+
var range = cm.listSelections()[i];
|
4824 |
+
cm.replaceRange("\n", range.anchor, range.head, "+input");
|
4825 |
+
cm.indentLine(range.from().line + 1, null, true);
|
4826 |
+
ensureCursorVisible(cm);
|
4827 |
+
}
|
4828 |
+
});
|
4829 |
+
},
|
4830 |
+
toggleOverwrite: function(cm) {cm.toggleOverwrite();}
|
4831 |
+
};
|
4832 |
+
|
4833 |
+
// STANDARD KEYMAPS
|
4834 |
+
|
4835 |
+
var keyMap = CodeMirror.keyMap = {};
|
4836 |
+
keyMap.basic = {
|
4837 |
+
"Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
|
4838 |
+
"End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
|
4839 |
+
"Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
|
4840 |
+
"Tab": "defaultTab", "Shift-Tab": "indentAuto",
|
4841 |
+
"Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
|
4842 |
+
"Esc": "singleSelection"
|
4843 |
+
};
|
4844 |
+
// Note that the save and find-related commands aren't defined by
|
4845 |
+
// default. User code or addons can define them. Unknown commands
|
4846 |
+
// are simply ignored.
|
4847 |
+
keyMap.pcDefault = {
|
4848 |
+
"Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
|
4849 |
+
"Ctrl-Home": "goDocStart", "Ctrl-Up": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Down": "goDocEnd",
|
4850 |
+
"Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
|
4851 |
+
"Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
|
4852 |
+
"Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
|
4853 |
+
"Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
|
4854 |
+
"Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
|
4855 |
+
fallthrough: "basic"
|
4856 |
+
};
|
4857 |
+
keyMap.macDefault = {
|
4858 |
+
"Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
|
4859 |
+
"Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
|
4860 |
+
"Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
|
4861 |
+
"Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
|
4862 |
+
"Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
|
4863 |
+
"Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
|
4864 |
+
"Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection",
|
4865 |
+
fallthrough: ["basic", "emacsy"]
|
4866 |
+
};
|
4867 |
+
// Very basic readline/emacs-style bindings, which are standard on Mac.
|
4868 |
+
keyMap.emacsy = {
|
4869 |
+
"Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
|
4870 |
+
"Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
|
4871 |
+
"Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
|
4872 |
+
"Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
|
4873 |
+
};
|
4874 |
+
keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
|
4875 |
+
|
4876 |
+
// KEYMAP DISPATCH
|
4877 |
+
|
4878 |
+
function getKeyMap(val) {
|
4879 |
+
if (typeof val == "string") return keyMap[val];
|
4880 |
+
else return val;
|
4881 |
+
}
|
4882 |
+
|
4883 |
+
// Given an array of keymaps and a key name, call handle on any
|
4884 |
+
// bindings found, until that returns a truthy value, at which point
|
4885 |
+
// we consider the key handled. Implements things like binding a key
|
4886 |
+
// to false stopping further handling and keymap fallthrough.
|
4887 |
+
var lookupKey = CodeMirror.lookupKey = function(name, maps, handle) {
|
4888 |
+
function lookup(map) {
|
4889 |
+
map = getKeyMap(map);
|
4890 |
+
var found = map[name];
|
4891 |
+
if (found === false) return "stop";
|
4892 |
+
if (found != null && handle(found)) return true;
|
4893 |
+
if (map.nofallthrough) return "stop";
|
4894 |
+
|
4895 |
+
var fallthrough = map.fallthrough;
|
4896 |
+
if (fallthrough == null) return false;
|
4897 |
+
if (Object.prototype.toString.call(fallthrough) != "[object Array]")
|
4898 |
+
return lookup(fallthrough);
|
4899 |
+
for (var i = 0; i < fallthrough.length; ++i) {
|
4900 |
+
var done = lookup(fallthrough[i]);
|
4901 |
+
if (done) return done;
|
4902 |
+
}
|
4903 |
+
return false;
|
4904 |
+
}
|
4905 |
+
|
4906 |
+
for (var i = 0; i < maps.length; ++i) {
|
4907 |
+
var done = lookup(maps[i]);
|
4908 |
+
if (done) return done != "stop";
|
4909 |
+
}
|
4910 |
+
};
|
4911 |
+
|
4912 |
+
// Modifier key presses don't count as 'real' key presses for the
|
4913 |
+
// purpose of keymap fallthrough.
|
4914 |
+
var isModifierKey = CodeMirror.isModifierKey = function(event) {
|
4915 |
+
var name = keyNames[event.keyCode];
|
4916 |
+
return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
|
4917 |
+
};
|
4918 |
+
|
4919 |
+
// Look up the name of a key as indicated by an event object.
|
4920 |
+
var keyName = CodeMirror.keyName = function(event, noShift) {
|
4921 |
+
if (presto && event.keyCode == 34 && event["char"]) return false;
|
4922 |
+
var name = keyNames[event.keyCode];
|
4923 |
+
if (name == null || event.altGraphKey) return false;
|
4924 |
+
if (event.altKey) name = "Alt-" + name;
|
4925 |
+
if (flipCtrlCmd ? event.metaKey : event.ctrlKey) name = "Ctrl-" + name;
|
4926 |
+
if (flipCtrlCmd ? event.ctrlKey : event.metaKey) name = "Cmd-" + name;
|
4927 |
+
if (!noShift && event.shiftKey) name = "Shift-" + name;
|
4928 |
+
return name;
|
4929 |
+
};
|
4930 |
+
|
4931 |
+
// FROMTEXTAREA
|
4932 |
+
|
4933 |
+
CodeMirror.fromTextArea = function(textarea, options) {
|
4934 |
+
if (!options) options = {};
|
4935 |
+
options.value = textarea.value;
|
4936 |
+
if (!options.tabindex && textarea.tabindex)
|
4937 |
+
options.tabindex = textarea.tabindex;
|
4938 |
+
if (!options.placeholder && textarea.placeholder)
|
4939 |
+
options.placeholder = textarea.placeholder;
|
4940 |
+
// Set autofocus to true if this textarea is focused, or if it has
|
4941 |
+
// autofocus and no other element is focused.
|
4942 |
+
if (options.autofocus == null) {
|
4943 |
+
var hasFocus = activeElt();
|
4944 |
+
options.autofocus = hasFocus == textarea ||
|
4945 |
+
textarea.getAttribute("autofocus") != null && hasFocus == document.body;
|
4946 |
+
}
|
4947 |
+
|
4948 |
+
function save() {textarea.value = cm.getValue();}
|
4949 |
+
if (textarea.form) {
|
4950 |
+
on(textarea.form, "submit", save);
|
4951 |
+
// Deplorable hack to make the submit method do the right thing.
|
4952 |
+
if (!options.leaveSubmitMethodAlone) {
|
4953 |
+
var form = textarea.form, realSubmit = form.submit;
|
4954 |
+
try {
|
4955 |
+
var wrappedSubmit = form.submit = function() {
|
4956 |
+
save();
|
4957 |
+
form.submit = realSubmit;
|
4958 |
+
form.submit();
|
4959 |
+
form.submit = wrappedSubmit;
|
4960 |
+
};
|
4961 |
+
} catch(e) {}
|
4962 |
+
}
|
4963 |
+
}
|
4964 |
+
|
4965 |
+
textarea.style.display = "none";
|
4966 |
+
var cm = CodeMirror(function(node) {
|
4967 |
+
textarea.parentNode.insertBefore(node, textarea.nextSibling);
|
4968 |
+
}, options);
|
4969 |
+
cm.save = save;
|
4970 |
+
cm.getTextArea = function() { return textarea; };
|
4971 |
+
cm.toTextArea = function() {
|
4972 |
+
save();
|
4973 |
+
textarea.parentNode.removeChild(cm.getWrapperElement());
|
4974 |
+
textarea.style.display = "";
|
4975 |
+
if (textarea.form) {
|
4976 |
+
off(textarea.form, "submit", save);
|
4977 |
+
if (typeof textarea.form.submit == "function")
|
4978 |
+
textarea.form.submit = realSubmit;
|
4979 |
+
}
|
4980 |
+
};
|
4981 |
+
return cm;
|
4982 |
+
};
|
4983 |
+
|
4984 |
+
// STRING STREAM
|
4985 |
+
|
4986 |
+
// Fed to the mode parsers, provides helper functions to make
|
4987 |
+
// parsers more succinct.
|
4988 |
+
|
4989 |
+
var StringStream = CodeMirror.StringStream = function(string, tabSize) {
|
4990 |
+
this.pos = this.start = 0;
|
4991 |
+
this.string = string;
|
4992 |
+
this.tabSize = tabSize || 8;
|
4993 |
+
this.lastColumnPos = this.lastColumnValue = 0;
|
4994 |
+
this.lineStart = 0;
|
4995 |
+
};
|
4996 |
+
|
4997 |
+
StringStream.prototype = {
|
4998 |
+
eol: function() {return this.pos >= this.string.length;},
|
4999 |
+
sol: function() {return this.pos == this.lineStart;},
|
5000 |
+
peek: function() {return this.string.charAt(this.pos) || undefined;},
|
5001 |
+
next: function() {
|
5002 |
+
if (this.pos < this.string.length)
|
5003 |
+
return this.string.charAt(this.pos++);
|
5004 |
+
},
|
5005 |
+
eat: function(match) {
|
5006 |
+
var ch = this.string.charAt(this.pos);
|
5007 |
+
if (typeof match == "string") var ok = ch == match;
|
5008 |
+
else var ok = ch && (match.test ? match.test(ch) : match(ch));
|
5009 |
+
if (ok) {++this.pos; return ch;}
|
5010 |
+
},
|
5011 |
+
eatWhile: function(match) {
|
5012 |
+
var start = this.pos;
|
5013 |
+
while (this.eat(match)){}
|
5014 |
+
return this.pos > start;
|
5015 |
+
},
|
5016 |
+
eatSpace: function() {
|
5017 |
+
var start = this.pos;
|
5018 |
+
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
|
5019 |
+
return this.pos > start;
|
5020 |
+
},
|
5021 |
+
skipToEnd: function() {this.pos = this.string.length;},
|
5022 |
+
skipTo: function(ch) {
|
5023 |
+
var found = this.string.indexOf(ch, this.pos);
|
5024 |
+
if (found > -1) {this.pos = found; return true;}
|
5025 |
+
},
|
5026 |
+
backUp: function(n) {this.pos -= n;},
|
5027 |
+
column: function() {
|
5028 |
+
if (this.lastColumnPos < this.start) {
|
5029 |
+
this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
|
5030 |
+
this.lastColumnPos = this.start;
|
5031 |
+
}
|
5032 |
+
return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
|
5033 |
+
},
|
5034 |
+
indentation: function() {
|
5035 |
+
return countColumn(this.string, null, this.tabSize) -
|
5036 |
+
(this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
|
5037 |
+
},
|
5038 |
+
match: function(pattern, consume, caseInsensitive) {
|
5039 |
+
if (typeof pattern == "string") {
|
5040 |
+
var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
|
5041 |
+
var substr = this.string.substr(this.pos, pattern.length);
|
5042 |
+
if (cased(substr) == cased(pattern)) {
|
5043 |
+
if (consume !== false) this.pos += pattern.length;
|
5044 |
+
return true;
|
5045 |
+
}
|
5046 |
+
} else {
|
5047 |
+
var match = this.string.slice(this.pos).match(pattern);
|
5048 |
+
if (match && match.index > 0) return null;
|
5049 |
+
if (match && consume !== false) this.pos += match[0].length;
|
5050 |
+
return match;
|
5051 |
+
}
|
5052 |
+
},
|
5053 |
+
current: function(){return this.string.slice(this.start, this.pos);},
|
5054 |
+
hideFirstChars: function(n, inner) {
|
5055 |
+
this.lineStart += n;
|
5056 |
+
try { return inner(); }
|
5057 |
+
finally { this.lineStart -= n; }
|
5058 |
+
}
|
5059 |
+
};
|
5060 |
+
|
5061 |
+
// TEXTMARKERS
|
5062 |
+
|
5063 |
+
// Created with markText and setBookmark methods. A TextMarker is a
|
5064 |
+
// handle that can be used to clear or find a marked position in the
|
5065 |
+
// document. Line objects hold arrays (markedSpans) containing
|
5066 |
+
// {from, to, marker} object pointing to such marker objects, and
|
5067 |
+
// indicating that such a marker is present on that line. Multiple
|
5068 |
+
// lines may point to the same marker when it spans across lines.
|
5069 |
+
// The spans will have null for their from/to properties when the
|
5070 |
+
// marker continues beyond the start/end of the line. Markers have
|
5071 |
+
// links back to the lines they currently touch.
|
5072 |
+
|
5073 |
+
var TextMarker = CodeMirror.TextMarker = function(doc, type) {
|
5074 |
+
this.lines = [];
|
5075 |
+
this.type = type;
|
5076 |
+
this.doc = doc;
|
5077 |
+
};
|
5078 |
+
eventMixin(TextMarker);
|
5079 |
+
|
5080 |
+
// Clear the marker.
|
5081 |
+
TextMarker.prototype.clear = function() {
|
5082 |
+
if (this.explicitlyCleared) return;
|
5083 |
+
var cm = this.doc.cm, withOp = cm && !cm.curOp;
|
5084 |
+
if (withOp) startOperation(cm);
|
5085 |
+
if (hasHandler(this, "clear")) {
|
5086 |
+
var found = this.find();
|
5087 |
+
if (found) signalLater(this, "clear", found.from, found.to);
|
5088 |
+
}
|
5089 |
+
var min = null, max = null;
|
5090 |
+
for (var i = 0; i < this.lines.length; ++i) {
|
5091 |
+
var line = this.lines[i];
|
5092 |
+
var span = getMarkedSpanFor(line.markedSpans, this);
|
5093 |
+
if (cm && !this.collapsed) regLineChange(cm, lineNo(line), "text");
|
5094 |
+
else if (cm) {
|
5095 |
+
if (span.to != null) max = lineNo(line);
|
5096 |
+
if (span.from != null) min = lineNo(line);
|
5097 |
+
}
|
5098 |
+
line.markedSpans = removeMarkedSpan(line.markedSpans, span);
|
5099 |
+
if (span.from == null && this.collapsed && !lineIsHidden(this.doc, line) && cm)
|
5100 |
+
updateLineHeight(line, textHeight(cm.display));
|
5101 |
+
}
|
5102 |
+
if (cm && this.collapsed && !cm.options.lineWrapping) for (var i = 0; i < this.lines.length; ++i) {
|
5103 |
+
var visual = visualLine(this.lines[i]), len = lineLength(visual);
|
5104 |
+
if (len > cm.display.maxLineLength) {
|
5105 |
+
cm.display.maxLine = visual;
|
5106 |
+
cm.display.maxLineLength = len;
|
5107 |
+
cm.display.maxLineChanged = true;
|
5108 |
+
}
|
5109 |
+
}
|
5110 |
+
|
5111 |
+
if (min != null && cm && this.collapsed) regChange(cm, min, max + 1);
|
5112 |
+
this.lines.length = 0;
|
5113 |
+
this.explicitlyCleared = true;
|
5114 |
+
if (this.atomic && this.doc.cantEdit) {
|
5115 |
+
this.doc.cantEdit = false;
|
5116 |
+
if (cm) reCheckSelection(cm.doc);
|
5117 |
+
}
|
5118 |
+
if (cm) signalLater(cm, "markerCleared", cm, this);
|
5119 |
+
if (withOp) endOperation(cm);
|
5120 |
+
if (this.parent) this.parent.clear();
|
5121 |
+
};
|
5122 |
+
|
5123 |
+
// Find the position of the marker in the document. Returns a {from,
|
5124 |
+
// to} object by default. Side can be passed to get a specific side
|
5125 |
+
// -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
|
5126 |
+
// Pos objects returned contain a line object, rather than a line
|
5127 |
+
// number (used to prevent looking up the same line twice).
|
5128 |
+
TextMarker.prototype.find = function(side, lineObj) {
|
5129 |
+
if (side == null && this.type == "bookmark") side = 1;
|
5130 |
+
var from, to;
|
5131 |
+
for (var i = 0; i < this.lines.length; ++i) {
|
5132 |
+
var line = this.lines[i];
|
5133 |
+
var span = getMarkedSpanFor(line.markedSpans, this);
|
5134 |
+
if (span.from != null) {
|
5135 |
+
from = Pos(lineObj ? line : lineNo(line), span.from);
|
5136 |
+
if (side == -1) return from;
|
5137 |
+
}
|
5138 |
+
if (span.to != null) {
|
5139 |
+
to = Pos(lineObj ? line : lineNo(line), span.to);
|
5140 |
+
if (side == 1) return to;
|
5141 |
+
}
|
5142 |
+
}
|
5143 |
+
return from && {from: from, to: to};
|
5144 |
+
};
|
5145 |
+
|
5146 |
+
// Signals that the marker's widget changed, and surrounding layout
|
5147 |
+
// should be recomputed.
|
5148 |
+
TextMarker.prototype.changed = function() {
|
5149 |
+
var pos = this.find(-1, true), widget = this, cm = this.doc.cm;
|
5150 |
+
if (!pos || !cm) return;
|
5151 |
+
runInOp(cm, function() {
|
5152 |
+
var line = pos.line, lineN = lineNo(pos.line);
|
5153 |
+
var view = findViewForLine(cm, lineN);
|
5154 |
+
if (view) {
|
5155 |
+
clearLineMeasurementCacheFor(view);
|
5156 |
+
cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;
|
5157 |
+
}
|
5158 |
+
cm.curOp.updateMaxLine = true;
|
5159 |
+
if (!lineIsHidden(widget.doc, line) && widget.height != null) {
|
5160 |
+
var oldHeight = widget.height;
|
5161 |
+
widget.height = null;
|
5162 |
+
var dHeight = widgetHeight(widget) - oldHeight;
|
5163 |
+
if (dHeight)
|
5164 |
+
updateLineHeight(line, line.height + dHeight);
|
5165 |
+
}
|
5166 |
+
});
|
5167 |
+
};
|
5168 |
+
|
5169 |
+
TextMarker.prototype.attachLine = function(line) {
|
5170 |
+
if (!this.lines.length && this.doc.cm) {
|
5171 |
+
var op = this.doc.cm.curOp;
|
5172 |
+
if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
|
5173 |
+
(op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this);
|
5174 |
+
}
|
5175 |
+
this.lines.push(line);
|
5176 |
+
};
|
5177 |
+
TextMarker.prototype.detachLine = function(line) {
|
5178 |
+
this.lines.splice(indexOf(this.lines, line), 1);
|
5179 |
+
if (!this.lines.length && this.doc.cm) {
|
5180 |
+
var op = this.doc.cm.curOp;
|
5181 |
+
(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
|
5182 |
+
}
|
5183 |
+
};
|
5184 |
+
|
5185 |
+
// Collapsed markers have unique ids, in order to be able to order
|
5186 |
+
// them, which is needed for uniquely determining an outer marker
|
5187 |
+
// when they overlap (they may nest, but not partially overlap).
|
5188 |
+
var nextMarkerId = 0;
|
5189 |
+
|
5190 |
+
// Create a marker, wire it up to the right lines, and
|
5191 |
+
function markText(doc, from, to, options, type) {
|
5192 |
+
// Shared markers (across linked documents) are handled separately
|
5193 |
+
// (markTextShared will call out to this again, once per
|
5194 |
+
// document).
|
5195 |
+
if (options && options.shared) return markTextShared(doc, from, to, options, type);
|
5196 |
+
// Ensure we are in an operation.
|
5197 |
+
if (doc.cm && !doc.cm.curOp) return operation(doc.cm, markText)(doc, from, to, options, type);
|
5198 |
+
|
5199 |
+
var marker = new TextMarker(doc, type), diff = cmp(from, to);
|
5200 |
+
if (options) copyObj(options, marker, false);
|
5201 |
+
// Don't connect empty markers unless clearWhenEmpty is false
|
5202 |
+
if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
|
5203 |
+
return marker;
|
5204 |
+
if (marker.replacedWith) {
|
5205 |
+
// Showing up as a widget implies collapsed (widget replaces text)
|
5206 |
+
marker.collapsed = true;
|
5207 |
+
marker.widgetNode = elt("span", [marker.replacedWith], "CodeMirror-widget");
|
5208 |
+
if (!options.handleMouseEvents) marker.widgetNode.ignoreEvents = true;
|
5209 |
+
if (options.insertLeft) marker.widgetNode.insertLeft = true;
|
5210 |
+
}
|
5211 |
+
if (marker.collapsed) {
|
5212 |
+
if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
|
5213 |
+
from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
|
5214 |
+
throw new Error("Inserting collapsed marker partially overlapping an existing one");
|
5215 |
+
sawCollapsedSpans = true;
|
5216 |
+
}
|
5217 |
+
|
5218 |
+
if (marker.addToHistory)
|
5219 |
+
addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN);
|
5220 |
+
|
5221 |
+
var curLine = from.line, cm = doc.cm, updateMaxLine;
|
5222 |
+
doc.iter(curLine, to.line + 1, function(line) {
|
5223 |
+
if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
|
5224 |
+
updateMaxLine = true;
|
5225 |
+
if (marker.collapsed && curLine != from.line) updateLineHeight(line, 0);
|
5226 |
+
addMarkedSpan(line, new MarkedSpan(marker,
|
5227 |
+
curLine == from.line ? from.ch : null,
|
5228 |
+
curLine == to.line ? to.ch : null));
|
5229 |
+
++curLine;
|
5230 |
+
});
|
5231 |
+
// lineIsHidden depends on the presence of the spans, so needs a second pass
|
5232 |
+
if (marker.collapsed) doc.iter(from.line, to.line + 1, function(line) {
|
5233 |
+
if (lineIsHidden(doc, line)) updateLineHeight(line, 0);
|
5234 |
+
});
|
5235 |
+
|
5236 |
+
if (marker.clearOnEnter) on(marker, "beforeCursorEnter", function() { marker.clear(); });
|
5237 |
+
|
5238 |
+
if (marker.readOnly) {
|
5239 |
+
sawReadOnlySpans = true;
|
5240 |
+
if (doc.history.done.length || doc.history.undone.length)
|
5241 |
+
doc.clearHistory();
|
5242 |
+
}
|
5243 |
+
if (marker.collapsed) {
|
5244 |
+
marker.id = ++nextMarkerId;
|
5245 |
+
marker.atomic = true;
|
5246 |
+
}
|
5247 |
+
if (cm) {
|
5248 |
+
// Sync editor state
|
5249 |
+
if (updateMaxLine) cm.curOp.updateMaxLine = true;
|
5250 |
+
if (marker.collapsed)
|
5251 |
+
regChange(cm, from.line, to.line + 1);
|
5252 |
+
else if (marker.className || marker.title || marker.startStyle || marker.endStyle)
|
5253 |
+
for (var i = from.line; i <= to.line; i++) regLineChange(cm, i, "text");
|
5254 |
+
if (marker.atomic) reCheckSelection(cm.doc);
|
5255 |
+
signalLater(cm, "markerAdded", cm, marker);
|
5256 |
+
}
|
5257 |
+
return marker;
|
5258 |
+
}
|
5259 |
+
|
5260 |
+
// SHARED TEXTMARKERS
|
5261 |
+
|
5262 |
+
// A shared marker spans multiple linked documents. It is
|
5263 |
+
// implemented as a meta-marker-object controlling multiple normal
|
5264 |
+
// markers.
|
5265 |
+
var SharedTextMarker = CodeMirror.SharedTextMarker = function(markers, primary) {
|
5266 |
+
this.markers = markers;
|
5267 |
+
this.primary = primary;
|
5268 |
+
for (var i = 0; i < markers.length; ++i)
|
5269 |
+
markers[i].parent = this;
|
5270 |
+
};
|
5271 |
+
eventMixin(SharedTextMarker);
|
5272 |
+
|
5273 |
+
SharedTextMarker.prototype.clear = function() {
|
5274 |
+
if (this.explicitlyCleared) return;
|
5275 |
+
this.explicitlyCleared = true;
|
5276 |
+
for (var i = 0; i < this.markers.length; ++i)
|
5277 |
+
this.markers[i].clear();
|
5278 |
+
signalLater(this, "clear");
|
5279 |
+
};
|
5280 |
+
SharedTextMarker.prototype.find = function(side, lineObj) {
|
5281 |
+
return this.primary.find(side, lineObj);
|
5282 |
+
};
|
5283 |
+
|
5284 |
+
function markTextShared(doc, from, to, options, type) {
|
5285 |
+
options = copyObj(options);
|
5286 |
+
options.shared = false;
|
5287 |
+
var markers = [markText(doc, from, to, options, type)], primary = markers[0];
|
5288 |
+
var widget = options.widgetNode;
|
5289 |
+
linkedDocs(doc, function(doc) {
|
5290 |
+
if (widget) options.widgetNode = widget.cloneNode(true);
|
5291 |
+
markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
|
5292 |
+
for (var i = 0; i < doc.linked.length; ++i)
|
5293 |
+
if (doc.linked[i].isParent) return;
|
5294 |
+
primary = lst(markers);
|
5295 |
+
});
|
5296 |
+
return new SharedTextMarker(markers, primary);
|
5297 |
+
}
|
5298 |
+
|
5299 |
+
function findSharedMarkers(doc) {
|
5300 |
+
return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())),
|
5301 |
+
function(m) { return m.parent; });
|
5302 |
+
}
|
5303 |
+
|
5304 |
+
function copySharedMarkers(doc, markers) {
|
5305 |
+
for (var i = 0; i < markers.length; i++) {
|
5306 |
+
var marker = markers[i], pos = marker.find();
|
5307 |
+
var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to);
|
5308 |
+
if (cmp(mFrom, mTo)) {
|
5309 |
+
var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type);
|
5310 |
+
marker.markers.push(subMark);
|
5311 |
+
subMark.parent = marker;
|
5312 |
+
}
|
5313 |
+
}
|
5314 |
+
}
|
5315 |
+
|
5316 |
+
function detachSharedMarkers(markers) {
|
5317 |
+
for (var i = 0; i < markers.length; i++) {
|
5318 |
+
var marker = markers[i], linked = [marker.primary.doc];;
|
5319 |
+
linkedDocs(marker.primary.doc, function(d) { linked.push(d); });
|
5320 |
+
for (var j = 0; j < marker.markers.length; j++) {
|
5321 |
+
var subMarker = marker.markers[j];
|
5322 |
+
if (indexOf(linked, subMarker.doc) == -1) {
|
5323 |
+
subMarker.parent = null;
|
5324 |
+
marker.markers.splice(j--, 1);
|
5325 |
+
}
|
5326 |
+
}
|
5327 |
+
}
|
5328 |
+
}
|
5329 |
+
|
5330 |
+
// TEXTMARKER SPANS
|
5331 |
+
|
5332 |
+
function MarkedSpan(marker, from, to) {
|
5333 |
+
this.marker = marker;
|
5334 |
+
this.from = from; this.to = to;
|
5335 |
+
}
|
5336 |
+
|
5337 |
+
// Search an array of spans for a span matching the given marker.
|
5338 |
+
function getMarkedSpanFor(spans, marker) {
|
5339 |
+
if (spans) for (var i = 0; i < spans.length; ++i) {
|
5340 |
+
var span = spans[i];
|
5341 |
+
if (span.marker == marker) return span;
|
5342 |
+
}
|
5343 |
+
}
|
5344 |
+
// Remove a span from an array, returning undefined if no spans are
|
5345 |
+
// left (we don't store arrays for lines without spans).
|
5346 |
+
function removeMarkedSpan(spans, span) {
|
5347 |
+
for (var r, i = 0; i < spans.length; ++i)
|
5348 |
+
if (spans[i] != span) (r || (r = [])).push(spans[i]);
|
5349 |
+
return r;
|
5350 |
+
}
|
5351 |
+
// Add a span to a line.
|
5352 |
+
function addMarkedSpan(line, span) {
|
5353 |
+
line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
|
5354 |
+
span.marker.attachLine(line);
|
5355 |
+
}
|
5356 |
+
|
5357 |
+
// Used for the algorithm that adjusts markers for a change in the
|
5358 |
+
// document. These functions cut an array of spans at a given
|
5359 |
+
// character position, returning an array of remaining chunks (or
|
5360 |
+
// undefined if nothing remains).
|
5361 |
+
function markedSpansBefore(old, startCh, isInsert) {
|
5362 |
+
if (old) for (var i = 0, nw; i < old.length; ++i) {
|
5363 |
+
var span = old[i], marker = span.marker;
|
5364 |
+
var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
|
5365 |
+
if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
|
5366 |
+
var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);
|
5367 |
+
(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));
|
5368 |
+
}
|
5369 |
+
}
|
5370 |
+
return nw;
|
5371 |
+
}
|
5372 |
+
function markedSpansAfter(old, endCh, isInsert) {
|
5373 |
+
if (old) for (var i = 0, nw; i < old.length; ++i) {
|
5374 |
+
var span = old[i], marker = span.marker;
|
5375 |
+
var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
|
5376 |
+
if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
|
5377 |
+
var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);
|
5378 |
+
(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
|
5379 |
+
span.to == null ? null : span.to - endCh));
|
5380 |
+
}
|
5381 |
+
}
|
5382 |
+
return nw;
|
5383 |
+
}
|
5384 |
+
|
5385 |
+
// Given a change object, compute the new set of marker spans that
|
5386 |
+
// cover the line in which the change took place. Removes spans
|
5387 |
+
// entirely within the change, reconnects spans belonging to the
|
5388 |
+
// same marker that appear on both sides of the change, and cuts off
|
5389 |
+
// spans partially within the change. Returns an array of span
|
5390 |
+
// arrays with one element for each line in (after) the change.
|
5391 |
+
function stretchSpansOverChange(doc, change) {
|
5392 |
+
var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
|
5393 |
+
var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
|
5394 |
+
if (!oldFirst && !oldLast) return null;
|
5395 |
+
|
5396 |
+
var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
|
5397 |
+
// Get the spans that 'stick out' on both sides
|
5398 |
+
var first = markedSpansBefore(oldFirst, startCh, isInsert);
|
5399 |
+
var last = markedSpansAfter(oldLast, endCh, isInsert);
|
5400 |
+
|
5401 |
+
// Next, merge those two ends
|
5402 |
+
var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
|
5403 |
+
if (first) {
|
5404 |
+
// Fix up .to properties of first
|
5405 |
+
for (var i = 0; i < first.length; ++i) {
|
5406 |
+
var span = first[i];
|
5407 |
+
if (span.to == null) {
|
5408 |
+
var found = getMarkedSpanFor(last, span.marker);
|
5409 |
+
if (!found) span.to = startCh;
|
5410 |
+
else if (sameLine) span.to = found.to == null ? null : found.to + offset;
|
5411 |
+
}
|
5412 |
+
}
|
5413 |
+
}
|
5414 |
+
if (last) {
|
5415 |
+
// Fix up .from in last (or move them into first in case of sameLine)
|
5416 |
+
for (var i = 0; i < last.length; ++i) {
|
5417 |
+
var span = last[i];
|
5418 |
+
if (span.to != null) span.to += offset;
|
5419 |
+
if (span.from == null) {
|
5420 |
+
var found = getMarkedSpanFor(first, span.marker);
|
5421 |
+
if (!found) {
|
5422 |
+
span.from = offset;
|
5423 |
+
if (sameLine) (first || (first = [])).push(span);
|
5424 |
+
}
|
5425 |
+
} else {
|
5426 |
+
span.from += offset;
|
5427 |
+
if (sameLine) (first || (first = [])).push(span);
|
5428 |
+
}
|
5429 |
+
}
|
5430 |
+
}
|
5431 |
+
// Make sure we didn't create any zero-length spans
|
5432 |
+
if (first) first = clearEmptySpans(first);
|
5433 |
+
if (last && last != first) last = clearEmptySpans(last);
|
5434 |
+
|
5435 |
+
var newMarkers = [first];
|
5436 |
+
if (!sameLine) {
|
5437 |
+
// Fill gap with whole-line-spans
|
5438 |
+
var gap = change.text.length - 2, gapMarkers;
|
5439 |
+
if (gap > 0 && first)
|
5440 |
+
for (var i = 0; i < first.length; ++i)
|
5441 |
+
if (first[i].to == null)
|
5442 |
+
(gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i].marker, null, null));
|
5443 |
+
for (var i = 0; i < gap; ++i)
|
5444 |
+
newMarkers.push(gapMarkers);
|
5445 |
+
newMarkers.push(last);
|
5446 |
+
}
|
5447 |
+
return newMarkers;
|
5448 |
+
}
|
5449 |
+
|
5450 |
+
// Remove spans that are empty and don't have a clearWhenEmpty
|
5451 |
+
// option of false.
|
5452 |
+
function clearEmptySpans(spans) {
|
5453 |
+
for (var i = 0; i < spans.length; ++i) {
|
5454 |
+
var span = spans[i];
|
5455 |
+
if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
|
5456 |
+
spans.splice(i--, 1);
|
5457 |
+
}
|
5458 |
+
if (!spans.length) return null;
|
5459 |
+
return spans;
|
5460 |
+
}
|
5461 |
+
|
5462 |
+
// Used for un/re-doing changes from the history. Combines the
|
5463 |
+
// result of computing the existing spans with the set of spans that
|
5464 |
+
// existed in the history (so that deleting around a span and then
|
5465 |
+
// undoing brings back the span).
|
5466 |
+
function mergeOldSpans(doc, change) {
|
5467 |
+
var old = getOldSpans(doc, change);
|
5468 |
+
var stretched = stretchSpansOverChange(doc, change);
|
5469 |
+
if (!old) return stretched;
|
5470 |
+
if (!stretched) return old;
|
5471 |
+
|
5472 |
+
for (var i = 0; i < old.length; ++i) {
|
5473 |
+
var oldCur = old[i], stretchCur = stretched[i];
|
5474 |
+
if (oldCur && stretchCur) {
|
5475 |
+
spans: for (var j = 0; j < stretchCur.length; ++j) {
|
5476 |
+
var span = stretchCur[j];
|
5477 |
+
for (var k = 0; k < oldCur.length; ++k)
|
5478 |
+
if (oldCur[k].marker == span.marker) continue spans;
|
5479 |
+
oldCur.push(span);
|
5480 |
+
}
|
5481 |
+
} else if (stretchCur) {
|
5482 |
+
old[i] = stretchCur;
|
5483 |
+
}
|
5484 |
+
}
|
5485 |
+
return old;
|
5486 |
+
}
|
5487 |
+
|
5488 |
+
// Used to 'clip' out readOnly ranges when making a change.
|
5489 |
+
function removeReadOnlyRanges(doc, from, to) {
|
5490 |
+
var markers = null;
|
5491 |
+
doc.iter(from.line, to.line + 1, function(line) {
|
5492 |
+
if (line.markedSpans) for (var i = 0; i < line.markedSpans.length; ++i) {
|
5493 |
+
var mark = line.markedSpans[i].marker;
|
5494 |
+
if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
|
5495 |
+
(markers || (markers = [])).push(mark);
|
5496 |
+
}
|
5497 |
+
});
|
5498 |
+
if (!markers) return null;
|
5499 |
+
var parts = [{from: from, to: to}];
|
5500 |
+
for (var i = 0; i < markers.length; ++i) {
|
5501 |
+
var mk = markers[i], m = mk.find(0);
|
5502 |
+
for (var j = 0; j < parts.length; ++j) {
|
5503 |
+
var p = parts[j];
|
5504 |
+
if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) continue;
|
5505 |
+
var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to);
|
5506 |
+
if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
|
5507 |
+
newParts.push({from: p.from, to: m.from});
|
5508 |
+
if (dto > 0 || !mk.inclusiveRight && !dto)
|
5509 |
+
newParts.push({from: m.to, to: p.to});
|
5510 |
+
parts.splice.apply(parts, newParts);
|
5511 |
+
j += newParts.length - 1;
|
5512 |
+
}
|
5513 |
+
}
|
5514 |
+
return parts;
|
5515 |
+
}
|
5516 |
+
|
5517 |
+
// Connect or disconnect spans from a line.
|
5518 |
+
function detachMarkedSpans(line) {
|
5519 |
+
var spans = line.markedSpans;
|
5520 |
+
if (!spans) return;
|
5521 |
+
for (var i = 0; i < spans.length; ++i)
|
5522 |
+
spans[i].marker.detachLine(line);
|
5523 |
+
line.markedSpans = null;
|
5524 |
+
}
|
5525 |
+
function attachMarkedSpans(line, spans) {
|
5526 |
+
if (!spans) return;
|
5527 |
+
for (var i = 0; i < spans.length; ++i)
|
5528 |
+
spans[i].marker.attachLine(line);
|
5529 |
+
line.markedSpans = spans;
|
5530 |
+
}
|
5531 |
+
|
5532 |
+
// Helpers used when computing which overlapping collapsed span
|
5533 |
+
// counts as the larger one.
|
5534 |
+
function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0; }
|
5535 |
+
function extraRight(marker) { return marker.inclusiveRight ? 1 : 0; }
|
5536 |
+
|
5537 |
+
// Returns a number indicating which of two overlapping collapsed
|
5538 |
+
// spans is larger (and thus includes the other). Falls back to
|
5539 |
+
// comparing ids when the spans cover exactly the same range.
|
5540 |
+
function compareCollapsedMarkers(a, b) {
|
5541 |
+
var lenDiff = a.lines.length - b.lines.length;
|
5542 |
+
if (lenDiff != 0) return lenDiff;
|
5543 |
+
var aPos = a.find(), bPos = b.find();
|
5544 |
+
var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
|
5545 |
+
if (fromCmp) return -fromCmp;
|
5546 |
+
var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
|
5547 |
+
if (toCmp) return toCmp;
|
5548 |
+
return b.id - a.id;
|
5549 |
+
}
|
5550 |
+
|
5551 |
+
// Find out whether a line ends or starts in a collapsed span. If
|
5552 |
+
// so, return the marker for that span.
|
5553 |
+
function collapsedSpanAtSide(line, start) {
|
5554 |
+
var sps = sawCollapsedSpans && line.markedSpans, found;
|
5555 |
+
if (sps) for (var sp, i = 0; i < sps.length; ++i) {
|
5556 |
+
sp = sps[i];
|
5557 |
+
if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
|
5558 |
+
(!found || compareCollapsedMarkers(found, sp.marker) < 0))
|
5559 |
+
found = sp.marker;
|
5560 |
+
}
|
5561 |
+
return found;
|
5562 |
+
}
|
5563 |
+
function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true); }
|
5564 |
+
function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false); }
|
5565 |
+
|
5566 |
+
// Test whether there exists a collapsed span that partially
|
5567 |
+
// overlaps (covers the start or end, but not both) of a new span.
|
5568 |
+
// Such overlap is not allowed.
|
5569 |
+
function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
|
5570 |
+
var line = getLine(doc, lineNo);
|
5571 |
+
var sps = sawCollapsedSpans && line.markedSpans;
|
5572 |
+
if (sps) for (var i = 0; i < sps.length; ++i) {
|
5573 |
+
var sp = sps[i];
|
5574 |
+
if (!sp.marker.collapsed) continue;
|
5575 |
+
var found = sp.marker.find(0);
|
5576 |
+
var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
|
5577 |
+
var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
|
5578 |
+
if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) continue;
|
5579 |
+
if (fromCmp <= 0 && (cmp(found.to, from) > 0 || (sp.marker.inclusiveRight && marker.inclusiveLeft)) ||
|
5580 |
+
fromCmp >= 0 && (cmp(found.from, to) < 0 || (sp.marker.inclusiveLeft && marker.inclusiveRight)))
|
5581 |
+
return true;
|
5582 |
+
}
|
5583 |
+
}
|
5584 |
+
|
5585 |
+
// A visual line is a line as drawn on the screen. Folding, for
|
5586 |
+
// example, can cause multiple logical lines to appear on the same
|
5587 |
+
// visual line. This finds the start of the visual line that the
|
5588 |
+
// given line is part of (usually that is the line itself).
|
5589 |
+
function visualLine(line) {
|
5590 |
+
var merged;
|
5591 |
+
while (merged = collapsedSpanAtStart(line))
|
5592 |
+
line = merged.find(-1, true).line;
|
5593 |
+
return line;
|
5594 |
+
}
|
5595 |
+
|
5596 |
+
// Returns an array of logical lines that continue the visual line
|
5597 |
+
// started by the argument, or undefined if there are no such lines.
|
5598 |
+
function visualLineContinued(line) {
|
5599 |
+
var merged, lines;
|
5600 |
+
while (merged = collapsedSpanAtEnd(line)) {
|
5601 |
+
line = merged.find(1, true).line;
|
5602 |
+
(lines || (lines = [])).push(line);
|
5603 |
+
}
|
5604 |
+
return lines;
|
5605 |
+
}
|
5606 |
+
|
5607 |
+
// Get the line number of the start of the visual line that the
|
5608 |
+
// given line number is part of.
|
5609 |
+
function visualLineNo(doc, lineN) {
|
5610 |
+
var line = getLine(doc, lineN), vis = visualLine(line);
|
5611 |
+
if (line == vis) return lineN;
|
5612 |
+
return lineNo(vis);
|
5613 |
+
}
|
5614 |
+
// Get the line number of the start of the next visual line after
|
5615 |
+
// the given line.
|
5616 |
+
function visualLineEndNo(doc, lineN) {
|
5617 |
+
if (lineN > doc.lastLine()) return lineN;
|
5618 |
+
var line = getLine(doc, lineN), merged;
|
5619 |
+
if (!lineIsHidden(doc, line)) return lineN;
|
5620 |
+
while (merged = collapsedSpanAtEnd(line))
|
5621 |
+
line = merged.find(1, true).line;
|
5622 |
+
return lineNo(line) + 1;
|
5623 |
+
}
|
5624 |
+
|
5625 |
+
// Compute whether a line is hidden. Lines count as hidden when they
|
5626 |
+
// are part of a visual line that starts with another line, or when
|
5627 |
+
// they are entirely covered by collapsed, non-widget span.
|
5628 |
+
function lineIsHidden(doc, line) {
|
5629 |
+
var sps = sawCollapsedSpans && line.markedSpans;
|
5630 |
+
if (sps) for (var sp, i = 0; i < sps.length; ++i) {
|
5631 |
+
sp = sps[i];
|
5632 |
+
if (!sp.marker.collapsed) continue;
|
5633 |
+
if (sp.from == null) return true;
|
5634 |
+
if (sp.marker.widgetNode) continue;
|
5635 |
+
if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
|
5636 |
+
return true;
|
5637 |
+
}
|
5638 |
+
}
|
5639 |
+
function lineIsHiddenInner(doc, line, span) {
|
5640 |
+
if (span.to == null) {
|
5641 |
+
var end = span.marker.find(1, true);
|
5642 |
+
return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker));
|
5643 |
+
}
|
5644 |
+
if (span.marker.inclusiveRight && span.to == line.text.length)
|
5645 |
+
return true;
|
5646 |
+
for (var sp, i = 0; i < line.markedSpans.length; ++i) {
|
5647 |
+
sp = line.markedSpans[i];
|
5648 |
+
if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
|
5649 |
+
(sp.to == null || sp.to != span.from) &&
|
5650 |
+
(sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
|
5651 |
+
lineIsHiddenInner(doc, line, sp)) return true;
|
5652 |
+
}
|
5653 |
+
}
|
5654 |
+
|
5655 |
+
// LINE WIDGETS
|
5656 |
+
|
5657 |
+
// Line widgets are block elements displayed above or below a line.
|
5658 |
+
|
5659 |
+
var LineWidget = CodeMirror.LineWidget = function(cm, node, options) {
|
5660 |
+
if (options) for (var opt in options) if (options.hasOwnProperty(opt))
|
5661 |
+
this[opt] = options[opt];
|
5662 |
+
this.cm = cm;
|
5663 |
+
this.node = node;
|
5664 |
+
};
|
5665 |
+
eventMixin(LineWidget);
|
5666 |
+
|
5667 |
+
function adjustScrollWhenAboveVisible(cm, line, diff) {
|
5668 |
+
if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
|
5669 |
+
addToScrollPos(cm, null, diff);
|
5670 |
+
}
|
5671 |
+
|
5672 |
+
LineWidget.prototype.clear = function() {
|
5673 |
+
var cm = this.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
|
5674 |
+
if (no == null || !ws) return;
|
5675 |
+
for (var i = 0; i < ws.length; ++i) if (ws[i] == this) ws.splice(i--, 1);
|
5676 |
+
if (!ws.length) line.widgets = null;
|
5677 |
+
var height = widgetHeight(this);
|
5678 |
+
runInOp(cm, function() {
|
5679 |
+
adjustScrollWhenAboveVisible(cm, line, -height);
|
5680 |
+
regLineChange(cm, no, "widget");
|
5681 |
+
updateLineHeight(line, Math.max(0, line.height - height));
|
5682 |
+
});
|
5683 |
+
};
|
5684 |
+
LineWidget.prototype.changed = function() {
|
5685 |
+
var oldH = this.height, cm = this.cm, line = this.line;
|
5686 |
+
this.height = null;
|
5687 |
+
var diff = widgetHeight(this) - oldH;
|
5688 |
+
if (!diff) return;
|
5689 |
+
runInOp(cm, function() {
|
5690 |
+
cm.curOp.forceUpdate = true;
|
5691 |
+
adjustScrollWhenAboveVisible(cm, line, diff);
|
5692 |
+
updateLineHeight(line, line.height + diff);
|
5693 |
+
});
|
5694 |
+
};
|
5695 |
+
|
5696 |
+
function widgetHeight(widget) {
|
5697 |
+
if (widget.height != null) return widget.height;
|
5698 |
+
if (!contains(document.body, widget.node)) {
|
5699 |
+
var parentStyle = "position: relative;";
|
5700 |
+
if (widget.coverGutter)
|
5701 |
+
parentStyle += "margin-left: -" + widget.cm.getGutterElement().offsetWidth + "px;";
|
5702 |
+
removeChildrenAndAdd(widget.cm.display.measure, elt("div", [widget.node], null, parentStyle));
|
5703 |
+
}
|
5704 |
+
return widget.height = widget.node.offsetHeight;
|
5705 |
+
}
|
5706 |
+
|
5707 |
+
function addLineWidget(cm, handle, node, options) {
|
5708 |
+
var widget = new LineWidget(cm, node, options);
|
5709 |
+
if (widget.noHScroll) cm.display.alignWidgets = true;
|
5710 |
+
changeLine(cm.doc, handle, "widget", function(line) {
|
5711 |
+
var widgets = line.widgets || (line.widgets = []);
|
5712 |
+
if (widget.insertAt == null) widgets.push(widget);
|
5713 |
+
else widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget);
|
5714 |
+
widget.line = line;
|
5715 |
+
if (!lineIsHidden(cm.doc, line)) {
|
5716 |
+
var aboveVisible = heightAtLine(line) < cm.doc.scrollTop;
|
5717 |
+
updateLineHeight(line, line.height + widgetHeight(widget));
|
5718 |
+
if (aboveVisible) addToScrollPos(cm, null, widget.height);
|
5719 |
+
cm.curOp.forceUpdate = true;
|
5720 |
+
}
|
5721 |
+
return true;
|
5722 |
+
});
|
5723 |
+
return widget;
|
5724 |
+
}
|
5725 |
+
|
5726 |
+
// LINE DATA STRUCTURE
|
5727 |
+
|
5728 |
+
// Line objects. These hold state related to a line, including
|
5729 |
+
// highlighting info (the styles array).
|
5730 |
+
var Line = CodeMirror.Line = function(text, markedSpans, estimateHeight) {
|
5731 |
+
this.text = text;
|
5732 |
+
attachMarkedSpans(this, markedSpans);
|
5733 |
+
this.height = estimateHeight ? estimateHeight(this) : 1;
|
5734 |
+
};
|
5735 |
+
eventMixin(Line);
|
5736 |
+
Line.prototype.lineNo = function() { return lineNo(this); };
|
5737 |
+
|
5738 |
+
// Change the content (text, markers) of a line. Automatically
|
5739 |
+
// invalidates cached information and tries to re-estimate the
|
5740 |
+
// line's height.
|
5741 |
+
function updateLine(line, text, markedSpans, estimateHeight) {
|
5742 |
+
line.text = text;
|
5743 |
+
if (line.stateAfter) line.stateAfter = null;
|
5744 |
+
if (line.styles) line.styles = null;
|
5745 |
+
if (line.order != null) line.order = null;
|
5746 |
+
detachMarkedSpans(line);
|
5747 |
+
attachMarkedSpans(line, markedSpans);
|
5748 |
+
var estHeight = estimateHeight ? estimateHeight(line) : 1;
|
5749 |
+
if (estHeight != line.height) updateLineHeight(line, estHeight);
|
5750 |
+
}
|
5751 |
+
|
5752 |
+
// Detach a line from the document tree and its markers.
|
5753 |
+
function cleanUpLine(line) {
|
5754 |
+
line.parent = null;
|
5755 |
+
detachMarkedSpans(line);
|
5756 |
+
}
|
5757 |
+
|
5758 |
+
function extractLineClasses(type, output) {
|
5759 |
+
if (type) for (;;) {
|
5760 |
+
var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/);
|
5761 |
+
if (!lineClass) break;
|
5762 |
+
type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);
|
5763 |
+
var prop = lineClass[1] ? "bgClass" : "textClass";
|
5764 |
+
if (output[prop] == null)
|
5765 |
+
output[prop] = lineClass[2];
|
5766 |
+
else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
|
5767 |
+
output[prop] += " " + lineClass[2];
|
5768 |
+
}
|
5769 |
+
return type;
|
5770 |
+
}
|
5771 |
+
|
5772 |
+
function callBlankLine(mode, state) {
|
5773 |
+
if (mode.blankLine) return mode.blankLine(state);
|
5774 |
+
if (!mode.innerMode) return;
|
5775 |
+
var inner = CodeMirror.innerMode(mode, state);
|
5776 |
+
if (inner.mode.blankLine) return inner.mode.blankLine(inner.state);
|
5777 |
+
}
|
5778 |
+
|
5779 |
+
function readToken(mode, stream, state) {
|
5780 |
+
for (var i = 0; i < 10; i++) {
|
5781 |
+
var style = mode.token(stream, state);
|
5782 |
+
if (stream.pos > stream.start) return style;
|
5783 |
+
}
|
5784 |
+
throw new Error("Mode " + mode.name + " failed to advance stream.");
|
5785 |
+
}
|
5786 |
+
|
5787 |
+
// Run the given mode's parser over a line, calling f for each token.
|
5788 |
+
function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) {
|
5789 |
+
var flattenSpans = mode.flattenSpans;
|
5790 |
+
if (flattenSpans == null) flattenSpans = cm.options.flattenSpans;
|
5791 |
+
var curStart = 0, curStyle = null;
|
5792 |
+
var stream = new StringStream(text, cm.options.tabSize), style;
|
5793 |
+
if (text == "") extractLineClasses(callBlankLine(mode, state), lineClasses);
|
5794 |
+
while (!stream.eol()) {
|
5795 |
+
if (stream.pos > cm.options.maxHighlightLength) {
|
5796 |
+
flattenSpans = false;
|
5797 |
+
if (forceToEnd) processLine(cm, text, state, stream.pos);
|
5798 |
+
stream.pos = text.length;
|
5799 |
+
style = null;
|
5800 |
+
} else {
|
5801 |
+
style = extractLineClasses(readToken(mode, stream, state), lineClasses);
|
5802 |
+
}
|
5803 |
+
if (cm.options.addModeClass) {
|
5804 |
+
var mName = CodeMirror.innerMode(mode, state).mode.name;
|
5805 |
+
if (mName) style = "m-" + (style ? mName + " " + style : mName);
|
5806 |
+
}
|
5807 |
+
if (!flattenSpans || curStyle != style) {
|
5808 |
+
if (curStart < stream.start) f(stream.start, curStyle);
|
5809 |
+
curStart = stream.start; curStyle = style;
|
5810 |
+
}
|
5811 |
+
stream.start = stream.pos;
|
5812 |
+
}
|
5813 |
+
while (curStart < stream.pos) {
|
5814 |
+
// Webkit seems to refuse to render text nodes longer than 57444 characters
|
5815 |
+
var pos = Math.min(stream.pos, curStart + 50000);
|
5816 |
+
f(pos, curStyle);
|
5817 |
+
curStart = pos;
|
5818 |
+
}
|
5819 |
+
}
|
5820 |
+
|
5821 |
+
// Compute a style array (an array starting with a mode generation
|
5822 |
+
// -- for invalidation -- followed by pairs of end positions and
|
5823 |
+
// style strings), which is used to highlight the tokens on the
|
5824 |
+
// line.
|
5825 |
+
function highlightLine(cm, line, state, forceToEnd) {
|
5826 |
+
// A styles array always starts with a number identifying the
|
5827 |
+
// mode/overlays that it is based on (for easy invalidation).
|
5828 |
+
var st = [cm.state.modeGen], lineClasses = {};
|
5829 |
+
// Compute the base array of styles
|
5830 |
+
runMode(cm, line.text, cm.doc.mode, state, function(end, style) {
|
5831 |
+
st.push(end, style);
|
5832 |
+
}, lineClasses, forceToEnd);
|
5833 |
+
|
5834 |
+
// Run overlays, adjust style array.
|
5835 |
+
for (var o = 0; o < cm.state.overlays.length; ++o) {
|
5836 |
+
var overlay = cm.state.overlays[o], i = 1, at = 0;
|
5837 |
+
runMode(cm, line.text, overlay.mode, true, function(end, style) {
|
5838 |
+
var start = i;
|
5839 |
+
// Ensure there's a token end at the current position, and that i points at it
|
5840 |
+
while (at < end) {
|
5841 |
+
var i_end = st[i];
|
5842 |
+
if (i_end > end)
|
5843 |
+
st.splice(i, 1, end, st[i+1], i_end);
|
5844 |
+
i += 2;
|
5845 |
+
at = Math.min(end, i_end);
|
5846 |
+
}
|
5847 |
+
if (!style) return;
|
5848 |
+
if (overlay.opaque) {
|
5849 |
+
st.splice(start, i - start, end, "cm-overlay " + style);
|
5850 |
+
i = start + 2;
|
5851 |
+
} else {
|
5852 |
+
for (; start < i; start += 2) {
|
5853 |
+
var cur = st[start+1];
|
5854 |
+
st[start+1] = (cur ? cur + " " : "") + "cm-overlay " + style;
|
5855 |
+
}
|
5856 |
+
}
|
5857 |
+
}, lineClasses);
|
5858 |
+
}
|
5859 |
+
|
5860 |
+
return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null};
|
5861 |
+
}
|
5862 |
+
|
5863 |
+
function getLineStyles(cm, line) {
|
5864 |
+
if (!line.styles || line.styles[0] != cm.state.modeGen) {
|
5865 |
+
var result = highlightLine(cm, line, line.stateAfter = getStateBefore(cm, lineNo(line)));
|
5866 |
+
line.styles = result.styles;
|
5867 |
+
if (result.classes) line.styleClasses = result.classes;
|
5868 |
+
else if (line.styleClasses) line.styleClasses = null;
|
5869 |
+
}
|
5870 |
+
return line.styles;
|
5871 |
+
}
|
5872 |
+
|
5873 |
+
// Lightweight form of highlight -- proceed over this line and
|
5874 |
+
// update state, but don't save a style array. Used for lines that
|
5875 |
+
// aren't currently visible.
|
5876 |
+
function processLine(cm, text, state, startAt) {
|
5877 |
+
var mode = cm.doc.mode;
|
5878 |
+
var stream = new StringStream(text, cm.options.tabSize);
|
5879 |
+
stream.start = stream.pos = startAt || 0;
|
5880 |
+
if (text == "") callBlankLine(mode, state);
|
5881 |
+
while (!stream.eol() && stream.pos <= cm.options.maxHighlightLength) {
|
5882 |
+
readToken(mode, stream, state);
|
5883 |
+
stream.start = stream.pos;
|
5884 |
+
}
|
5885 |
+
}
|
5886 |
+
|
5887 |
+
// Convert a style as returned by a mode (either null, or a string
|
5888 |
+
// containing one or more styles) to a CSS style. This is cached,
|
5889 |
+
// and also looks for line-wide styles.
|
5890 |
+
var styleToClassCache = {}, styleToClassCacheWithMode = {};
|
5891 |
+
function interpretTokenStyle(style, options) {
|
5892 |
+
if (!style || /^\s*$/.test(style)) return null;
|
5893 |
+
var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;
|
5894 |
+
return cache[style] ||
|
5895 |
+
(cache[style] = style.replace(/\S+/g, "cm-$&"));
|
5896 |
+
}
|
5897 |
+
|
5898 |
+
// Render the DOM representation of the text of a line. Also builds
|
5899 |
+
// up a 'line map', which points at the DOM nodes that represent
|
5900 |
+
// specific stretches of text, and is used by the measuring code.
|
5901 |
+
// The returned object contains the DOM node, this map, and
|
5902 |
+
// information about line-wide styles that were set by the mode.
|
5903 |
+
function buildLineContent(cm, lineView) {
|
5904 |
+
// The padding-right forces the element to have a 'border', which
|
5905 |
+
// is needed on Webkit to be able to get line-level bounding
|
5906 |
+
// rectangles for it (in measureChar).
|
5907 |
+
var content = elt("span", null, null, webkit ? "padding-right: .1px" : null);
|
5908 |
+
var builder = {pre: elt("pre", [content]), content: content, col: 0, pos: 0, cm: cm};
|
5909 |
+
lineView.measure = {};
|
5910 |
+
|
5911 |
+
// Iterate over the logical lines that make up this visual line.
|
5912 |
+
for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
|
5913 |
+
var line = i ? lineView.rest[i - 1] : lineView.line, order;
|
5914 |
+
builder.pos = 0;
|
5915 |
+
builder.addToken = buildToken;
|
5916 |
+
// Optionally wire in some hacks into the token-rendering
|
5917 |
+
// algorithm, to deal with browser quirks.
|
5918 |
+
if ((ie || webkit) && cm.getOption("lineWrapping"))
|
5919 |
+
builder.addToken = buildTokenSplitSpaces(builder.addToken);
|
5920 |
+
if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line)))
|
5921 |
+
builder.addToken = buildTokenBadBidi(builder.addToken, order);
|
5922 |
+
builder.map = [];
|
5923 |
+
insertLineContent(line, builder, getLineStyles(cm, line));
|
5924 |
+
if (line.styleClasses) {
|
5925 |
+
if (line.styleClasses.bgClass)
|
5926 |
+
builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "");
|
5927 |
+
if (line.styleClasses.textClass)
|
5928 |
+
builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "");
|
5929 |
+
}
|
5930 |
+
|
5931 |
+
// Ensure at least a single node is present, for measuring.
|
5932 |
+
if (builder.map.length == 0)
|
5933 |
+
builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure)));
|
5934 |
+
|
5935 |
+
// Store the map and a cache object for the current logical line
|
5936 |
+
if (i == 0) {
|
5937 |
+
lineView.measure.map = builder.map;
|
5938 |
+
lineView.measure.cache = {};
|
5939 |
+
} else {
|
5940 |
+
(lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map);
|
5941 |
+
(lineView.measure.caches || (lineView.measure.caches = [])).push({});
|
5942 |
+
}
|
5943 |
+
}
|
5944 |
+
|
5945 |
+
signal(cm, "renderLine", cm, lineView.line, builder.pre);
|
5946 |
+
if (builder.pre.className)
|
5947 |
+
builder.textClass = joinClasses(builder.pre.className, builder.textClass || "");
|
5948 |
+
return builder;
|
5949 |
+
}
|
5950 |
+
|
5951 |
+
function defaultSpecialCharPlaceholder(ch) {
|
5952 |
+
var token = elt("span", "\u2022", "cm-invalidchar");
|
5953 |
+
token.title = "\\u" + ch.charCodeAt(0).toString(16);
|
5954 |
+
return token;
|
5955 |
+
}
|
5956 |
+
|
5957 |
+
// Build up the DOM representation for a single token, and add it to
|
5958 |
+
// the line map. Takes care to render special characters separately.
|
5959 |
+
function buildToken(builder, text, style, startStyle, endStyle, title) {
|
5960 |
+
if (!text) return;
|
5961 |
+
var special = builder.cm.options.specialChars, mustWrap = false;
|
5962 |
+
if (!special.test(text)) {
|
5963 |
+
builder.col += text.length;
|
5964 |
+
var content = document.createTextNode(text);
|
5965 |
+
builder.map.push(builder.pos, builder.pos + text.length, content);
|
5966 |
+
if (ie && ie_version < 9) mustWrap = true;
|
5967 |
+
builder.pos += text.length;
|
5968 |
+
} else {
|
5969 |
+
var content = document.createDocumentFragment(), pos = 0;
|
5970 |
+
while (true) {
|
5971 |
+
special.lastIndex = pos;
|
5972 |
+
var m = special.exec(text);
|
5973 |
+
var skipped = m ? m.index - pos : text.length - pos;
|
5974 |
+
if (skipped) {
|
5975 |
+
var txt = document.createTextNode(text.slice(pos, pos + skipped));
|
5976 |
+
if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
|
5977 |
+
else content.appendChild(txt);
|
5978 |
+
builder.map.push(builder.pos, builder.pos + skipped, txt);
|
5979 |
+
builder.col += skipped;
|
5980 |
+
builder.pos += skipped;
|
5981 |
+
}
|
5982 |
+
if (!m) break;
|
5983 |
+
pos += skipped + 1;
|
5984 |
+
if (m[0] == "\t") {
|
5985 |
+
var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
|
5986 |
+
var txt = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
|
5987 |
+
builder.col += tabWidth;
|
5988 |
+
} else {
|
5989 |
+
var txt = builder.cm.options.specialCharPlaceholder(m[0]);
|
5990 |
+
if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
|
5991 |
+
else content.appendChild(txt);
|
5992 |
+
builder.col += 1;
|
5993 |
+
}
|
5994 |
+
builder.map.push(builder.pos, builder.pos + 1, txt);
|
5995 |
+
builder.pos++;
|
5996 |
+
}
|
5997 |
+
}
|
5998 |
+
if (style || startStyle || endStyle || mustWrap) {
|
5999 |
+
var fullStyle = style || "";
|
6000 |
+
if (startStyle) fullStyle += startStyle;
|
6001 |
+
if (endStyle) fullStyle += endStyle;
|
6002 |
+
var token = elt("span", [content], fullStyle);
|
6003 |
+
if (title) token.title = title;
|
6004 |
+
return builder.content.appendChild(token);
|
6005 |
+
}
|
6006 |
+
builder.content.appendChild(content);
|
6007 |
+
}
|
6008 |
+
|
6009 |
+
function buildTokenSplitSpaces(inner) {
|
6010 |
+
function split(old) {
|
6011 |
+
var out = " ";
|
6012 |
+
for (var i = 0; i < old.length - 2; ++i) out += i % 2 ? " " : "\u00a0";
|
6013 |
+
out += " ";
|
6014 |
+
return out;
|
6015 |
+
}
|
6016 |
+
return function(builder, text, style, startStyle, endStyle, title) {
|
6017 |
+
inner(builder, text.replace(/ {3,}/g, split), style, startStyle, endStyle, title);
|
6018 |
+
};
|
6019 |
+
}
|
6020 |
+
|
6021 |
+
// Work around nonsense dimensions being reported for stretches of
|
6022 |
+
// right-to-left text.
|
6023 |
+
function buildTokenBadBidi(inner, order) {
|
6024 |
+
return function(builder, text, style, startStyle, endStyle, title) {
|
6025 |
+
style = style ? style + " cm-force-border" : "cm-force-border";
|
6026 |
+
var start = builder.pos, end = start + text.length;
|
6027 |
+
for (;;) {
|
6028 |
+
// Find the part that overlaps with the start of this text
|
6029 |
+
for (var i = 0; i < order.length; i++) {
|
6030 |
+
var part = order[i];
|
6031 |
+
if (part.to > start && part.from <= start) break;
|
6032 |
+
}
|
6033 |
+
if (part.to >= end) return inner(builder, text, style, startStyle, endStyle, title);
|
6034 |
+
inner(builder, text.slice(0, part.to - start), style, startStyle, null, title);
|
6035 |
+
startStyle = null;
|
6036 |
+
text = text.slice(part.to - start);
|
6037 |
+
start = part.to;
|
6038 |
+
}
|
6039 |
+
};
|
6040 |
+
}
|
6041 |
+
|
6042 |
+
function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
|
6043 |
+
var widget = !ignoreWidget && marker.widgetNode;
|
6044 |
+
if (widget) {
|
6045 |
+
builder.map.push(builder.pos, builder.pos + size, widget);
|
6046 |
+
builder.content.appendChild(widget);
|
6047 |
+
}
|
6048 |
+
builder.pos += size;
|
6049 |
+
}
|
6050 |
+
|
6051 |
+
// Outputs a number of spans to make up a line, taking highlighting
|
6052 |
+
// and marked text into account.
|
6053 |
+
function insertLineContent(line, builder, styles) {
|
6054 |
+
var spans = line.markedSpans, allText = line.text, at = 0;
|
6055 |
+
if (!spans) {
|
6056 |
+
for (var i = 1; i < styles.length; i+=2)
|
6057 |
+
builder.addToken(builder, allText.slice(at, at = styles[i]), interpretTokenStyle(styles[i+1], builder.cm.options));
|
6058 |
+
return;
|
6059 |
+
}
|
6060 |
+
|
6061 |
+
var len = allText.length, pos = 0, i = 1, text = "", style;
|
6062 |
+
var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed;
|
6063 |
+
for (;;) {
|
6064 |
+
if (nextChange == pos) { // Update current marker set
|
6065 |
+
spanStyle = spanEndStyle = spanStartStyle = title = "";
|
6066 |
+
collapsed = null; nextChange = Infinity;
|
6067 |
+
var foundBookmarks = [];
|
6068 |
+
for (var j = 0; j < spans.length; ++j) {
|
6069 |
+
var sp = spans[j], m = sp.marker;
|
6070 |
+
if (sp.from <= pos && (sp.to == null || sp.to > pos)) {
|
6071 |
+
if (sp.to != null && nextChange > sp.to) { nextChange = sp.to; spanEndStyle = ""; }
|
6072 |
+
if (m.className) spanStyle += " " + m.className;
|
6073 |
+
if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle;
|
6074 |
+
if (m.endStyle && sp.to == nextChange) spanEndStyle += " " + m.endStyle;
|
6075 |
+
if (m.title && !title) title = m.title;
|
6076 |
+
if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
|
6077 |
+
collapsed = sp;
|
6078 |
+
} else if (sp.from > pos && nextChange > sp.from) {
|
6079 |
+
nextChange = sp.from;
|
6080 |
+
}
|
6081 |
+
if (m.type == "bookmark" && sp.from == pos && m.widgetNode) foundBookmarks.push(m);
|
6082 |
+
}
|
6083 |
+
if (collapsed && (collapsed.from || 0) == pos) {
|
6084 |
+
buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
|
6085 |
+
collapsed.marker, collapsed.from == null);
|
6086 |
+
if (collapsed.to == null) return;
|
6087 |
+
}
|
6088 |
+
if (!collapsed && foundBookmarks.length) for (var j = 0; j < foundBookmarks.length; ++j)
|
6089 |
+
buildCollapsedSpan(builder, 0, foundBookmarks[j]);
|
6090 |
+
}
|
6091 |
+
if (pos >= len) break;
|
6092 |
+
|
6093 |
+
var upto = Math.min(len, nextChange);
|
6094 |
+
while (true) {
|
6095 |
+
if (text) {
|
6096 |
+
var end = pos + text.length;
|
6097 |
+
if (!collapsed) {
|
6098 |
+
var tokenText = end > upto ? text.slice(0, upto - pos) : text;
|
6099 |
+
builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
|
6100 |
+
spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title);
|
6101 |
+
}
|
6102 |
+
if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
|
6103 |
+
pos = end;
|
6104 |
+
spanStartStyle = "";
|
6105 |
+
}
|
6106 |
+
text = allText.slice(at, at = styles[i++]);
|
6107 |
+
style = interpretTokenStyle(styles[i++], builder.cm.options);
|
6108 |
+
}
|
6109 |
+
}
|
6110 |
+
}
|
6111 |
+
|
6112 |
+
// DOCUMENT DATA STRUCTURE
|
6113 |
+
|
6114 |
+
// By default, updates that start and end at the beginning of a line
|
6115 |
+
// are treated specially, in order to make the association of line
|
6116 |
+
// widgets and marker elements with the text behave more intuitive.
|
6117 |
+
function isWholeLineUpdate(doc, change) {
|
6118 |
+
return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
|
6119 |
+
(!doc.cm || doc.cm.options.wholeLineUpdateBefore);
|
6120 |
+
}
|
6121 |
+
|
6122 |
+
// Perform a change on the document data structure.
|
6123 |
+
function updateDoc(doc, change, markedSpans, estimateHeight) {
|
6124 |
+
function spansFor(n) {return markedSpans ? markedSpans[n] : null;}
|
6125 |
+
function update(line, text, spans) {
|
6126 |
+
updateLine(line, text, spans, estimateHeight);
|
6127 |
+
signalLater(line, "change", line, change);
|
6128 |
+
}
|
6129 |
+
|
6130 |
+
var from = change.from, to = change.to, text = change.text;
|
6131 |
+
var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
|
6132 |
+
var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
|
6133 |
+
|
6134 |
+
// Adjust the line structure
|
6135 |
+
if (isWholeLineUpdate(doc, change)) {
|
6136 |
+
// This is a whole-line replace. Treated specially to make
|
6137 |
+
// sure line objects move the way they are supposed to.
|
6138 |
+
for (var i = 0, added = []; i < text.length - 1; ++i)
|
6139 |
+
added.push(new Line(text[i], spansFor(i), estimateHeight));
|
6140 |
+
update(lastLine, lastLine.text, lastSpans);
|
6141 |
+
if (nlines) doc.remove(from.line, nlines);
|
6142 |
+
if (added.length) doc.insert(from.line, added);
|
6143 |
+
} else if (firstLine == lastLine) {
|
6144 |
+
if (text.length == 1) {
|
6145 |
+
update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
|
6146 |
+
} else {
|
6147 |
+
for (var added = [], i = 1; i < text.length - 1; ++i)
|
6148 |
+
added.push(new Line(text[i], spansFor(i), estimateHeight));
|
6149 |
+
added.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight));
|
6150 |
+
update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
|
6151 |
+
doc.insert(from.line + 1, added);
|
6152 |
+
}
|
6153 |
+
} else if (text.length == 1) {
|
6154 |
+
update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
|
6155 |
+
doc.remove(from.line + 1, nlines);
|
6156 |
+
} else {
|
6157 |
+
update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
|
6158 |
+
update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
|
6159 |
+
for (var i = 1, added = []; i < text.length - 1; ++i)
|
6160 |
+
added.push(new Line(text[i], spansFor(i), estimateHeight));
|
6161 |
+
if (nlines > 1) doc.remove(from.line + 1, nlines - 1);
|
6162 |
+
doc.insert(from.line + 1, added);
|
6163 |
+
}
|
6164 |
+
|
6165 |
+
signalLater(doc, "change", doc, change);
|
6166 |
+
}
|
6167 |
+
|
6168 |
+
// The document is represented as a BTree consisting of leaves, with
|
6169 |
+
// chunk of lines in them, and branches, with up to ten leaves or
|
6170 |
+
// other branch nodes below them. The top node is always a branch
|
6171 |
+
// node, and is the document object itself (meaning it has
|
6172 |
+
// additional methods and properties).
|
6173 |
+
//
|
6174 |
+
// All nodes have parent links. The tree is used both to go from
|
6175 |
+
// line numbers to line objects, and to go from objects to numbers.
|
6176 |
+
// It also indexes by height, and is used to convert between height
|
6177 |
+
// and line object, and to find the total height of the document.
|
6178 |
+
//
|
6179 |
+
// See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
|
6180 |
+
|
6181 |
+
function LeafChunk(lines) {
|
6182 |
+
this.lines = lines;
|
6183 |
+
this.parent = null;
|
6184 |
+
for (var i = 0, height = 0; i < lines.length; ++i) {
|
6185 |
+
lines[i].parent = this;
|
6186 |
+
height += lines[i].height;
|
6187 |
+
}
|
6188 |
+
this.height = height;
|
6189 |
+
}
|
6190 |
+
|
6191 |
+
LeafChunk.prototype = {
|
6192 |
+
chunkSize: function() { return this.lines.length; },
|
6193 |
+
// Remove the n lines at offset 'at'.
|
6194 |
+
removeInner: function(at, n) {
|
6195 |
+
for (var i = at, e = at + n; i < e; ++i) {
|
6196 |
+
var line = this.lines[i];
|
6197 |
+
this.height -= line.height;
|
6198 |
+
cleanUpLine(line);
|
6199 |
+
signalLater(line, "delete");
|
6200 |
+
}
|
6201 |
+
this.lines.splice(at, n);
|
6202 |
+
},
|
6203 |
+
// Helper used to collapse a small branch into a single leaf.
|
6204 |
+
collapse: function(lines) {
|
6205 |
+
lines.push.apply(lines, this.lines);
|
6206 |
+
},
|
6207 |
+
// Insert the given array of lines at offset 'at', count them as
|
6208 |
+
// having the given height.
|
6209 |
+
insertInner: function(at, lines, height) {
|
6210 |
+
this.height += height;
|
6211 |
+
this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
|
6212 |
+
for (var i = 0; i < lines.length; ++i) lines[i].parent = this;
|
6213 |
+
},
|
6214 |
+
// Used to iterate over a part of the tree.
|
6215 |
+
iterN: function(at, n, op) {
|
6216 |
+
for (var e = at + n; at < e; ++at)
|
6217 |
+
if (op(this.lines[at])) return true;
|
6218 |
+
}
|
6219 |
+
};
|
6220 |
+
|
6221 |
+
function BranchChunk(children) {
|
6222 |
+
this.children = children;
|
6223 |
+
var size = 0, height = 0;
|
6224 |
+
for (var i = 0; i < children.length; ++i) {
|
6225 |
+
var ch = children[i];
|
6226 |
+
size += ch.chunkSize(); height += ch.height;
|
6227 |
+
ch.parent = this;
|
6228 |
+
}
|
6229 |
+
this.size = size;
|
6230 |
+
this.height = height;
|
6231 |
+
this.parent = null;
|
6232 |
+
}
|
6233 |
+
|
6234 |
+
BranchChunk.prototype = {
|
6235 |
+
chunkSize: function() { return this.size; },
|
6236 |
+
removeInner: function(at, n) {
|
6237 |
+
this.size -= n;
|
6238 |
+
for (var i = 0; i < this.children.length; ++i) {
|
6239 |
+
var child = this.children[i], sz = child.chunkSize();
|
6240 |
+
if (at < sz) {
|
6241 |
+
var rm = Math.min(n, sz - at), oldHeight = child.height;
|
6242 |
+
child.removeInner(at, rm);
|
6243 |
+
this.height -= oldHeight - child.height;
|
6244 |
+
if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
|
6245 |
+
if ((n -= rm) == 0) break;
|
6246 |
+
at = 0;
|
6247 |
+
} else at -= sz;
|
6248 |
+
}
|
6249 |
+
// If the result is smaller than 25 lines, ensure that it is a
|
6250 |
+
// single leaf node.
|
6251 |
+
if (this.size - n < 25 &&
|
6252 |
+
(this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
|
6253 |
+
var lines = [];
|
6254 |
+
this.collapse(lines);
|
6255 |
+
this.children = [new LeafChunk(lines)];
|
6256 |
+
this.children[0].parent = this;
|
6257 |
+
}
|
6258 |
+
},
|
6259 |
+
collapse: function(lines) {
|
6260 |
+
for (var i = 0; i < this.children.length; ++i) this.children[i].collapse(lines);
|
6261 |
+
},
|
6262 |
+
insertInner: function(at, lines, height) {
|
6263 |
+
this.size += lines.length;
|
6264 |
+
this.height += height;
|
6265 |
+
for (var i = 0; i < this.children.length; ++i) {
|
6266 |
+
var child = this.children[i], sz = child.chunkSize();
|
6267 |
+
if (at <= sz) {
|
6268 |
+
child.insertInner(at, lines, height);
|
6269 |
+
if (child.lines && child.lines.length > 50) {
|
6270 |
+
while (child.lines.length > 50) {
|
6271 |
+
var spilled = child.lines.splice(child.lines.length - 25, 25);
|
6272 |
+
var newleaf = new LeafChunk(spilled);
|
6273 |
+
child.height -= newleaf.height;
|
6274 |
+
this.children.splice(i + 1, 0, newleaf);
|
6275 |
+
newleaf.parent = this;
|
6276 |
+
}
|
6277 |
+
this.maybeSpill();
|
6278 |
+
}
|
6279 |
+
break;
|
6280 |
+
}
|
6281 |
+
at -= sz;
|
6282 |
+
}
|
6283 |
+
},
|
6284 |
+
// When a node has grown, check whether it should be split.
|
6285 |
+
maybeSpill: function() {
|
6286 |
+
if (this.children.length <= 10) return;
|
6287 |
+
var me = this;
|
6288 |
+
do {
|
6289 |
+
var spilled = me.children.splice(me.children.length - 5, 5);
|
6290 |
+
var sibling = new BranchChunk(spilled);
|
6291 |
+
if (!me.parent) { // Become the parent node
|
6292 |
+
var copy = new BranchChunk(me.children);
|
6293 |
+
copy.parent = me;
|
6294 |
+
me.children = [copy, sibling];
|
6295 |
+
me = copy;
|
6296 |
+
} else {
|
6297 |
+
me.size -= sibling.size;
|
6298 |
+
me.height -= sibling.height;
|
6299 |
+
var myIndex = indexOf(me.parent.children, me);
|
6300 |
+
me.parent.children.splice(myIndex + 1, 0, sibling);
|
6301 |
+
}
|
6302 |
+
sibling.parent = me.parent;
|
6303 |
+
} while (me.children.length > 10);
|
6304 |
+
me.parent.maybeSpill();
|
6305 |
+
},
|
6306 |
+
iterN: function(at, n, op) {
|
6307 |
+
for (var i = 0; i < this.children.length; ++i) {
|
6308 |
+
var child = this.children[i], sz = child.chunkSize();
|
6309 |
+
if (at < sz) {
|
6310 |
+
var used = Math.min(n, sz - at);
|
6311 |
+
if (child.iterN(at, used, op)) return true;
|
6312 |
+
if ((n -= used) == 0) break;
|
6313 |
+
at = 0;
|
6314 |
+
} else at -= sz;
|
6315 |
+
}
|
6316 |
+
}
|
6317 |
+
};
|
6318 |
+
|
6319 |
+
var nextDocId = 0;
|
6320 |
+
var Doc = CodeMirror.Doc = function(text, mode, firstLine) {
|
6321 |
+
if (!(this instanceof Doc)) return new Doc(text, mode, firstLine);
|
6322 |
+
if (firstLine == null) firstLine = 0;
|
6323 |
+
|
6324 |
+
BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
|
6325 |
+
this.first = firstLine;
|
6326 |
+
this.scrollTop = this.scrollLeft = 0;
|
6327 |
+
this.cantEdit = false;
|
6328 |
+
this.cleanGeneration = 1;
|
6329 |
+
this.frontier = firstLine;
|
6330 |
+
var start = Pos(firstLine, 0);
|
6331 |
+
this.sel = simpleSelection(start);
|
6332 |
+
this.history = new History(null);
|
6333 |
+
this.id = ++nextDocId;
|
6334 |
+
this.modeOption = mode;
|
6335 |
+
|
6336 |
+
if (typeof text == "string") text = splitLines(text);
|
6337 |
+
updateDoc(this, {from: start, to: start, text: text});
|
6338 |
+
setSelection(this, simpleSelection(start), sel_dontScroll);
|
6339 |
+
};
|
6340 |
+
|
6341 |
+
Doc.prototype = createObj(BranchChunk.prototype, {
|
6342 |
+
constructor: Doc,
|
6343 |
+
// Iterate over the document. Supports two forms -- with only one
|
6344 |
+
// argument, it calls that for each line in the document. With
|
6345 |
+
// three, it iterates over the range given by the first two (with
|
6346 |
+
// the second being non-inclusive).
|
6347 |
+
iter: function(from, to, op) {
|
6348 |
+
if (op) this.iterN(from - this.first, to - from, op);
|
6349 |
+
else this.iterN(this.first, this.first + this.size, from);
|
6350 |
+
},
|
6351 |
+
|
6352 |
+
// Non-public interface for adding and removing lines.
|
6353 |
+
insert: function(at, lines) {
|
6354 |
+
var height = 0;
|
6355 |
+
for (var i = 0; i < lines.length; ++i) height += lines[i].height;
|
6356 |
+
this.insertInner(at - this.first, lines, height);
|
6357 |
+
},
|
6358 |
+
remove: function(at, n) { this.removeInner(at - this.first, n); },
|
6359 |
+
|
6360 |
+
// From here, the methods are part of the public interface. Most
|
6361 |
+
// are also available from CodeMirror (editor) instances.
|
6362 |
+
|
6363 |
+
getValue: function(lineSep) {
|
6364 |
+
var lines = getLines(this, this.first, this.first + this.size);
|
6365 |
+
if (lineSep === false) return lines;
|
6366 |
+
return lines.join(lineSep || "\n");
|
6367 |
+
},
|
6368 |
+
setValue: docMethodOp(function(code) {
|
6369 |
+
var top = Pos(this.first, 0), last = this.first + this.size - 1;
|
6370 |
+
makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
|
6371 |
+
text: splitLines(code), origin: "setValue"}, true);
|
6372 |
+
setSelection(this, simpleSelection(top));
|
6373 |
+
}),
|
6374 |
+
replaceRange: function(code, from, to, origin) {
|
6375 |
+
from = clipPos(this, from);
|
6376 |
+
to = to ? clipPos(this, to) : from;
|
6377 |
+
replaceRange(this, code, from, to, origin);
|
6378 |
+
},
|
6379 |
+
getRange: function(from, to, lineSep) {
|
6380 |
+
var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
|
6381 |
+
if (lineSep === false) return lines;
|
6382 |
+
return lines.join(lineSep || "\n");
|
6383 |
+
},
|
6384 |
+
|
6385 |
+
getLine: function(line) {var l = this.getLineHandle(line); return l && l.text;},
|
6386 |
+
|
6387 |
+
getLineHandle: function(line) {if (isLine(this, line)) return getLine(this, line);},
|
6388 |
+
getLineNumber: function(line) {return lineNo(line);},
|
6389 |
+
|
6390 |
+
getLineHandleVisualStart: function(line) {
|
6391 |
+
if (typeof line == "number") line = getLine(this, line);
|
6392 |
+
return visualLine(line);
|
6393 |
+
},
|
6394 |
+
|
6395 |
+
lineCount: function() {return this.size;},
|
6396 |
+
firstLine: function() {return this.first;},
|
6397 |
+
lastLine: function() {return this.first + this.size - 1;},
|
6398 |
+
|
6399 |
+
clipPos: function(pos) {return clipPos(this, pos);},
|
6400 |
+
|
6401 |
+
getCursor: function(start) {
|
6402 |
+
var range = this.sel.primary(), pos;
|
6403 |
+
if (start == null || start == "head") pos = range.head;
|
6404 |
+
else if (start == "anchor") pos = range.anchor;
|
6405 |
+
else if (start == "end" || start == "to" || start === false) pos = range.to();
|
6406 |
+
else pos = range.from();
|
6407 |
+
return pos;
|
6408 |
+
},
|
6409 |
+
listSelections: function() { return this.sel.ranges; },
|
6410 |
+
somethingSelected: function() {return this.sel.somethingSelected();},
|
6411 |
+
|
6412 |
+
setCursor: docMethodOp(function(line, ch, options) {
|
6413 |
+
setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options);
|
6414 |
+
}),
|
6415 |
+
setSelection: docMethodOp(function(anchor, head, options) {
|
6416 |
+
setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options);
|
6417 |
+
}),
|
6418 |
+
extendSelection: docMethodOp(function(head, other, options) {
|
6419 |
+
extendSelection(this, clipPos(this, head), other && clipPos(this, other), options);
|
6420 |
+
}),
|
6421 |
+
extendSelections: docMethodOp(function(heads, options) {
|
6422 |
+
extendSelections(this, clipPosArray(this, heads, options));
|
6423 |
+
}),
|
6424 |
+
extendSelectionsBy: docMethodOp(function(f, options) {
|
6425 |
+
extendSelections(this, map(this.sel.ranges, f), options);
|
6426 |
+
}),
|
6427 |
+
setSelections: docMethodOp(function(ranges, primary, options) {
|
6428 |
+
if (!ranges.length) return;
|
6429 |
+
for (var i = 0, out = []; i < ranges.length; i++)
|
6430 |
+
out[i] = new Range(clipPos(this, ranges[i].anchor),
|
6431 |
+
clipPos(this, ranges[i].head));
|
6432 |
+
if (primary == null) primary = Math.min(ranges.length - 1, this.sel.primIndex);
|
6433 |
+
setSelection(this, normalizeSelection(out, primary), options);
|
6434 |
+
}),
|
6435 |
+
addSelection: docMethodOp(function(anchor, head, options) {
|
6436 |
+
var ranges = this.sel.ranges.slice(0);
|
6437 |
+
ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)));
|
6438 |
+
setSelection(this, normalizeSelection(ranges, ranges.length - 1), options);
|
6439 |
+
}),
|
6440 |
+
|
6441 |
+
getSelection: function(lineSep) {
|
6442 |
+
var ranges = this.sel.ranges, lines;
|
6443 |
+
for (var i = 0; i < ranges.length; i++) {
|
6444 |
+
var sel = getBetween(this, ranges[i].from(), ranges[i].to());
|
6445 |
+
lines = lines ? lines.concat(sel) : sel;
|
6446 |
+
}
|
6447 |
+
if (lineSep === false) return lines;
|
6448 |
+
else return lines.join(lineSep || "\n");
|
6449 |
+
},
|
6450 |
+
getSelections: function(lineSep) {
|
6451 |
+
var parts = [], ranges = this.sel.ranges;
|
6452 |
+
for (var i = 0; i < ranges.length; i++) {
|
6453 |
+
var sel = getBetween(this, ranges[i].from(), ranges[i].to());
|
6454 |
+
if (lineSep !== false) sel = sel.join(lineSep || "\n");
|
6455 |
+
parts[i] = sel;
|
6456 |
+
}
|
6457 |
+
return parts;
|
6458 |
+
},
|
6459 |
+
replaceSelection: function(code, collapse, origin) {
|
6460 |
+
var dup = [];
|
6461 |
+
for (var i = 0; i < this.sel.ranges.length; i++)
|
6462 |
+
dup[i] = code;
|
6463 |
+
this.replaceSelections(dup, collapse, origin || "+input");
|
6464 |
+
},
|
6465 |
+
replaceSelections: docMethodOp(function(code, collapse, origin) {
|
6466 |
+
var changes = [], sel = this.sel;
|
6467 |
+
for (var i = 0; i < sel.ranges.length; i++) {
|
6468 |
+
var range = sel.ranges[i];
|
6469 |
+
changes[i] = {from: range.from(), to: range.to(), text: splitLines(code[i]), origin: origin};
|
6470 |
+
}
|
6471 |
+
var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse);
|
6472 |
+
for (var i = changes.length - 1; i >= 0; i--)
|
6473 |
+
makeChange(this, changes[i]);
|
6474 |
+
if (newSel) setSelectionReplaceHistory(this, newSel);
|
6475 |
+
else if (this.cm) ensureCursorVisible(this.cm);
|
6476 |
+
}),
|
6477 |
+
undo: docMethodOp(function() {makeChangeFromHistory(this, "undo");}),
|
6478 |
+
redo: docMethodOp(function() {makeChangeFromHistory(this, "redo");}),
|
6479 |
+
undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true);}),
|
6480 |
+
redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true);}),
|
6481 |
+
|
6482 |
+
setExtending: function(val) {this.extend = val;},
|
6483 |
+
getExtending: function() {return this.extend;},
|
6484 |
+
|
6485 |
+
historySize: function() {
|
6486 |
+
var hist = this.history, done = 0, undone = 0;
|
6487 |
+
for (var i = 0; i < hist.done.length; i++) if (!hist.done[i].ranges) ++done;
|
6488 |
+
for (var i = 0; i < hist.undone.length; i++) if (!hist.undone[i].ranges) ++undone;
|
6489 |
+
return {undo: done, redo: undone};
|
6490 |
+
},
|
6491 |
+
clearHistory: function() {this.history = new History(this.history.maxGeneration);},
|
6492 |
+
|
6493 |
+
markClean: function() {
|
6494 |
+
this.cleanGeneration = this.changeGeneration(true);
|
6495 |
+
},
|
6496 |
+
changeGeneration: function(forceSplit) {
|
6497 |
+
if (forceSplit)
|
6498 |
+
this.history.lastOp = this.history.lastOrigin = null;
|
6499 |
+
return this.history.generation;
|
6500 |
+
},
|
6501 |
+
isClean: function (gen) {
|
6502 |
+
return this.history.generation == (gen || this.cleanGeneration);
|
6503 |
+
},
|
6504 |
+
|
6505 |
+
getHistory: function() {
|
6506 |
+
return {done: copyHistoryArray(this.history.done),
|
6507 |
+
undone: copyHistoryArray(this.history.undone)};
|
6508 |
+
},
|
6509 |
+
setHistory: function(histData) {
|
6510 |
+
var hist = this.history = new History(this.history.maxGeneration);
|
6511 |
+
hist.done = copyHistoryArray(histData.done.slice(0), null, true);
|
6512 |
+
hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);
|
6513 |
+
},
|
6514 |
+
|
6515 |
+
addLineClass: docMethodOp(function(handle, where, cls) {
|
6516 |
+
return changeLine(this, handle, "class", function(line) {
|
6517 |
+
var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : "wrapClass";
|
6518 |
+
if (!line[prop]) line[prop] = cls;
|
6519 |
+
else if (new RegExp("(?:^|\\s)" + cls + "(?:$|\\s)").test(line[prop])) return false;
|
6520 |
+
else line[prop] += " " + cls;
|
6521 |
+
return true;
|
6522 |
+
});
|
6523 |
+
}),
|
6524 |
+
removeLineClass: docMethodOp(function(handle, where, cls) {
|
6525 |
+
return changeLine(this, handle, "class", function(line) {
|
6526 |
+
var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : "wrapClass";
|
6527 |
+
var cur = line[prop];
|
6528 |
+
if (!cur) return false;
|
6529 |
+
else if (cls == null) line[prop] = null;
|
6530 |
+
else {
|
6531 |
+
var found = cur.match(new RegExp("(?:^|\\s+)" + cls + "(?:$|\\s+)"));
|
6532 |
+
if (!found) return false;
|
6533 |
+
var end = found.index + found[0].length;
|
6534 |
+
line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
|
6535 |
+
}
|
6536 |
+
return true;
|
6537 |
+
});
|
6538 |
+
}),
|
6539 |
+
|
6540 |
+
markText: function(from, to, options) {
|
6541 |
+
return markText(this, clipPos(this, from), clipPos(this, to), options, "range");
|
6542 |
+
},
|
6543 |
+
setBookmark: function(pos, options) {
|
6544 |
+
var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
|
6545 |
+
insertLeft: options && options.insertLeft,
|
6546 |
+
clearWhenEmpty: false, shared: options && options.shared};
|
6547 |
+
pos = clipPos(this, pos);
|
6548 |
+
return markText(this, pos, pos, realOpts, "bookmark");
|
6549 |
+
},
|
6550 |
+
findMarksAt: function(pos) {
|
6551 |
+
pos = clipPos(this, pos);
|
6552 |
+
var markers = [], spans = getLine(this, pos.line).markedSpans;
|
6553 |
+
if (spans) for (var i = 0; i < spans.length; ++i) {
|
6554 |
+
var span = spans[i];
|
6555 |
+
if ((span.from == null || span.from <= pos.ch) &&
|
6556 |
+
(span.to == null || span.to >= pos.ch))
|
6557 |
+
markers.push(span.marker.parent || span.marker);
|
6558 |
+
}
|
6559 |
+
return markers;
|
6560 |
+
},
|
6561 |
+
findMarks: function(from, to, filter) {
|
6562 |
+
from = clipPos(this, from); to = clipPos(this, to);
|
6563 |
+
var found = [], lineNo = from.line;
|
6564 |
+
this.iter(from.line, to.line + 1, function(line) {
|
6565 |
+
var spans = line.markedSpans;
|
6566 |
+
if (spans) for (var i = 0; i < spans.length; i++) {
|
6567 |
+
var span = spans[i];
|
6568 |
+
if (!(lineNo == from.line && from.ch > span.to ||
|
6569 |
+
span.from == null && lineNo != from.line||
|
6570 |
+
lineNo == to.line && span.from > to.ch) &&
|
6571 |
+
(!filter || filter(span.marker)))
|
6572 |
+
found.push(span.marker.parent || span.marker);
|
6573 |
+
}
|
6574 |
+
++lineNo;
|
6575 |
+
});
|
6576 |
+
return found;
|
6577 |
+
},
|
6578 |
+
getAllMarks: function() {
|
6579 |
+
var markers = [];
|
6580 |
+
this.iter(function(line) {
|
6581 |
+
var sps = line.markedSpans;
|
6582 |
+
if (sps) for (var i = 0; i < sps.length; ++i)
|
6583 |
+
if (sps[i].from != null) markers.push(sps[i].marker);
|
6584 |
+
});
|
6585 |
+
return markers;
|
6586 |
+
},
|
6587 |
+
|
6588 |
+
posFromIndex: function(off) {
|
6589 |
+
var ch, lineNo = this.first;
|
6590 |
+
this.iter(function(line) {
|
6591 |
+
var sz = line.text.length + 1;
|
6592 |
+
if (sz > off) { ch = off; return true; }
|
6593 |
+
off -= sz;
|
6594 |
+
++lineNo;
|
6595 |
+
});
|
6596 |
+
return clipPos(this, Pos(lineNo, ch));
|
6597 |
+
},
|
6598 |
+
indexFromPos: function (coords) {
|
6599 |
+
coords = clipPos(this, coords);
|
6600 |
+
var index = coords.ch;
|
6601 |
+
if (coords.line < this.first || coords.ch < 0) return 0;
|
6602 |
+
this.iter(this.first, coords.line, function (line) {
|
6603 |
+
index += line.text.length + 1;
|
6604 |
+
});
|
6605 |
+
return index;
|
6606 |
+
},
|
6607 |
+
|
6608 |
+
copy: function(copyHistory) {
|
6609 |
+
var doc = new Doc(getLines(this, this.first, this.first + this.size), this.modeOption, this.first);
|
6610 |
+
doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft;
|
6611 |
+
doc.sel = this.sel;
|
6612 |
+
doc.extend = false;
|
6613 |
+
if (copyHistory) {
|
6614 |
+
doc.history.undoDepth = this.history.undoDepth;
|
6615 |
+
doc.setHistory(this.getHistory());
|
6616 |
+
}
|
6617 |
+
return doc;
|
6618 |
+
},
|
6619 |
+
|
6620 |
+
linkedDoc: function(options) {
|
6621 |
+
if (!options) options = {};
|
6622 |
+
var from = this.first, to = this.first + this.size;
|
6623 |
+
if (options.from != null && options.from > from) from = options.from;
|
6624 |
+
if (options.to != null && options.to < to) to = options.to;
|
6625 |
+
var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from);
|
6626 |
+
if (options.sharedHist) copy.history = this.history;
|
6627 |
+
(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist});
|
6628 |
+
copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}];
|
6629 |
+
copySharedMarkers(copy, findSharedMarkers(this));
|
6630 |
+
return copy;
|
6631 |
+
},
|
6632 |
+
unlinkDoc: function(other) {
|
6633 |
+
if (other instanceof CodeMirror) other = other.doc;
|
6634 |
+
if (this.linked) for (var i = 0; i < this.linked.length; ++i) {
|
6635 |
+
var link = this.linked[i];
|
6636 |
+
if (link.doc != other) continue;
|
6637 |
+
this.linked.splice(i, 1);
|
6638 |
+
other.unlinkDoc(this);
|
6639 |
+
detachSharedMarkers(findSharedMarkers(this));
|
6640 |
+
break;
|
6641 |
+
}
|
6642 |
+
// If the histories were shared, split them again
|
6643 |
+
if (other.history == this.history) {
|
6644 |
+
var splitIds = [other.id];
|
6645 |
+
linkedDocs(other, function(doc) {splitIds.push(doc.id);}, true);
|
6646 |
+
other.history = new History(null);
|
6647 |
+
other.history.done = copyHistoryArray(this.history.done, splitIds);
|
6648 |
+
other.history.undone = copyHistoryArray(this.history.undone, splitIds);
|
6649 |
+
}
|
6650 |
+
},
|
6651 |
+
iterLinkedDocs: function(f) {linkedDocs(this, f);},
|
6652 |
+
|
6653 |
+
getMode: function() {return this.mode;},
|
6654 |
+
getEditor: function() {return this.cm;}
|
6655 |
+
});
|
6656 |
+
|
6657 |
+
// Public alias.
|
6658 |
+
Doc.prototype.eachLine = Doc.prototype.iter;
|
6659 |
+
|
6660 |
+
// Set up methods on CodeMirror's prototype to redirect to the editor's document.
|
6661 |
+
var dontDelegate = "iter insert remove copy getEditor".split(" ");
|
6662 |
+
for (var prop in Doc.prototype) if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
|
6663 |
+
CodeMirror.prototype[prop] = (function(method) {
|
6664 |
+
return function() {return method.apply(this.doc, arguments);};
|
6665 |
+
})(Doc.prototype[prop]);
|
6666 |
+
|
6667 |
+
eventMixin(Doc);
|
6668 |
+
|
6669 |
+
// Call f for all linked documents.
|
6670 |
+
function linkedDocs(doc, f, sharedHistOnly) {
|
6671 |
+
function propagate(doc, skip, sharedHist) {
|
6672 |
+
if (doc.linked) for (var i = 0; i < doc.linked.length; ++i) {
|
6673 |
+
var rel = doc.linked[i];
|
6674 |
+
if (rel.doc == skip) continue;
|
6675 |
+
var shared = sharedHist && rel.sharedHist;
|
6676 |
+
if (sharedHistOnly && !shared) continue;
|
6677 |
+
f(rel.doc, shared);
|
6678 |
+
propagate(rel.doc, doc, shared);
|
6679 |
+
}
|
6680 |
+
}
|
6681 |
+
propagate(doc, null, true);
|
6682 |
+
}
|
6683 |
+
|
6684 |
+
// Attach a document to an editor.
|
6685 |
+
function attachDoc(cm, doc) {
|
6686 |
+
if (doc.cm) throw new Error("This document is already in use.");
|
6687 |
+
cm.doc = doc;
|
6688 |
+
doc.cm = cm;
|
6689 |
+
estimateLineHeights(cm);
|
6690 |
+
loadMode(cm);
|
6691 |
+
if (!cm.options.lineWrapping) findMaxLine(cm);
|
6692 |
+
cm.options.mode = doc.modeOption;
|
6693 |
+
regChange(cm);
|
6694 |
+
}
|
6695 |
+
|
6696 |
+
// LINE UTILITIES
|
6697 |
+
|
6698 |
+
// Find the line object corresponding to the given line number.
|
6699 |
+
function getLine(doc, n) {
|
6700 |
+
n -= doc.first;
|
6701 |
+
if (n < 0 || n >= doc.size) throw new Error("There is no line " + (n + doc.first) + " in the document.");
|
6702 |
+
for (var chunk = doc; !chunk.lines;) {
|
6703 |
+
for (var i = 0;; ++i) {
|
6704 |
+
var child = chunk.children[i], sz = child.chunkSize();
|
6705 |
+
if (n < sz) { chunk = child; break; }
|
6706 |
+
n -= sz;
|
6707 |
+
}
|
6708 |
+
}
|
6709 |
+
return chunk.lines[n];
|
6710 |
+
}
|
6711 |
+
|
6712 |
+
// Get the part of a document between two positions, as an array of
|
6713 |
+
// strings.
|
6714 |
+
function getBetween(doc, start, end) {
|
6715 |
+
var out = [], n = start.line;
|
6716 |
+
doc.iter(start.line, end.line + 1, function(line) {
|
6717 |
+
var text = line.text;
|
6718 |
+
if (n == end.line) text = text.slice(0, end.ch);
|
6719 |
+
if (n == start.line) text = text.slice(start.ch);
|
6720 |
+
out.push(text);
|
6721 |
+
++n;
|
6722 |
+
});
|
6723 |
+
return out;
|
6724 |
+
}
|
6725 |
+
// Get the lines between from and to, as array of strings.
|
6726 |
+
function getLines(doc, from, to) {
|
6727 |
+
var out = [];
|
6728 |
+
doc.iter(from, to, function(line) { out.push(line.text); });
|
6729 |
+
return out;
|
6730 |
+
}
|
6731 |
+
|
6732 |
+
// Update the height of a line, propagating the height change
|
6733 |
+
// upwards to parent nodes.
|
6734 |
+
function updateLineHeight(line, height) {
|
6735 |
+
var diff = height - line.height;
|
6736 |
+
if (diff) for (var n = line; n; n = n.parent) n.height += diff;
|
6737 |
+
}
|
6738 |
+
|
6739 |
+
// Given a line object, find its line number by walking up through
|
6740 |
+
// its parent links.
|
6741 |
+
function lineNo(line) {
|
6742 |
+
if (line.parent == null) return null;
|
6743 |
+
var cur = line.parent, no = indexOf(cur.lines, line);
|
6744 |
+
for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
|
6745 |
+
for (var i = 0;; ++i) {
|
6746 |
+
if (chunk.children[i] == cur) break;
|
6747 |
+
no += chunk.children[i].chunkSize();
|
6748 |
+
}
|
6749 |
+
}
|
6750 |
+
return no + cur.first;
|
6751 |
+
}
|
6752 |
+
|
6753 |
+
// Find the line at the given vertical position, using the height
|
6754 |
+
// information in the document tree.
|
6755 |
+
function lineAtHeight(chunk, h) {
|
6756 |
+
var n = chunk.first;
|
6757 |
+
outer: do {
|
6758 |
+
for (var i = 0; i < chunk.children.length; ++i) {
|
6759 |
+
var child = chunk.children[i], ch = child.height;
|
6760 |
+
if (h < ch) { chunk = child; continue outer; }
|
6761 |
+
h -= ch;
|
6762 |
+
n += child.chunkSize();
|
6763 |
+
}
|
6764 |
+
return n;
|
6765 |
+
} while (!chunk.lines);
|
6766 |
+
for (var i = 0; i < chunk.lines.length; ++i) {
|
6767 |
+
var line = chunk.lines[i], lh = line.height;
|
6768 |
+
if (h < lh) break;
|
6769 |
+
h -= lh;
|
6770 |
+
}
|
6771 |
+
return n + i;
|
6772 |
+
}
|
6773 |
+
|
6774 |
+
|
6775 |
+
// Find the height above the given line.
|
6776 |
+
function heightAtLine(lineObj) {
|
6777 |
+
lineObj = visualLine(lineObj);
|
6778 |
+
|
6779 |
+
var h = 0, chunk = lineObj.parent;
|
6780 |
+
for (var i = 0; i < chunk.lines.length; ++i) {
|
6781 |
+
var line = chunk.lines[i];
|
6782 |
+
if (line == lineObj) break;
|
6783 |
+
else h += line.height;
|
6784 |
+
}
|
6785 |
+
for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
|
6786 |
+
for (var i = 0; i < p.children.length; ++i) {
|
6787 |
+
var cur = p.children[i];
|
6788 |
+
if (cur == chunk) break;
|
6789 |
+
else h += cur.height;
|
6790 |
+
}
|
6791 |
+
}
|
6792 |
+
return h;
|
6793 |
+
}
|
6794 |
+
|
6795 |
+
// Get the bidi ordering for the given line (and cache it). Returns
|
6796 |
+
// false for lines that are fully left-to-right, and an array of
|
6797 |
+
// BidiSpan objects otherwise.
|
6798 |
+
function getOrder(line) {
|
6799 |
+
var order = line.order;
|
6800 |
+
if (order == null) order = line.order = bidiOrdering(line.text);
|
6801 |
+
return order;
|
6802 |
+
}
|
6803 |
+
|
6804 |
+
// HISTORY
|
6805 |
+
|
6806 |
+
function History(startGen) {
|
6807 |
+
// Arrays of change events and selections. Doing something adds an
|
6808 |
+
// event to done and clears undo. Undoing moves events from done
|
6809 |
+
// to undone, redoing moves them in the other direction.
|
6810 |
+
this.done = []; this.undone = [];
|
6811 |
+
this.undoDepth = Infinity;
|
6812 |
+
// Used to track when changes can be merged into a single undo
|
6813 |
+
// event
|
6814 |
+
this.lastModTime = this.lastSelTime = 0;
|
6815 |
+
this.lastOp = null;
|
6816 |
+
this.lastOrigin = this.lastSelOrigin = null;
|
6817 |
+
// Used by the isClean() method
|
6818 |
+
this.generation = this.maxGeneration = startGen || 1;
|
6819 |
+
}
|
6820 |
+
|
6821 |
+
// Create a history change event from an updateDoc-style change
|
6822 |
+
// object.
|
6823 |
+
function historyChangeFromChange(doc, change) {
|
6824 |
+
var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)};
|
6825 |
+
attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
|
6826 |
+
linkedDocs(doc, function(doc) {attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);}, true);
|
6827 |
+
return histChange;
|
6828 |
+
}
|
6829 |
+
|
6830 |
+
// Pop all selection events off the end of a history array. Stop at
|
6831 |
+
// a change event.
|
6832 |
+
function clearSelectionEvents(array) {
|
6833 |
+
while (array.length) {
|
6834 |
+
var last = lst(array);
|
6835 |
+
if (last.ranges) array.pop();
|
6836 |
+
else break;
|
6837 |
+
}
|
6838 |
+
}
|
6839 |
+
|
6840 |
+
// Find the top change event in the history. Pop off selection
|
6841 |
+
// events that are in the way.
|
6842 |
+
function lastChangeEvent(hist, force) {
|
6843 |
+
if (force) {
|
6844 |
+
clearSelectionEvents(hist.done);
|
6845 |
+
return lst(hist.done);
|
6846 |
+
} else if (hist.done.length && !lst(hist.done).ranges) {
|
6847 |
+
return lst(hist.done);
|
6848 |
+
} else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
|
6849 |
+
hist.done.pop();
|
6850 |
+
return lst(hist.done);
|
6851 |
+
}
|
6852 |
+
}
|
6853 |
+
|
6854 |
+
// Register a change in the history. Merges changes that are within
|
6855 |
+
// a single operation, ore are close together with an origin that
|
6856 |
+
// allows merging (starting with "+") into a single event.
|
6857 |
+
function addChangeToHistory(doc, change, selAfter, opId) {
|
6858 |
+
var hist = doc.history;
|
6859 |
+
hist.undone.length = 0;
|
6860 |
+
var time = +new Date, cur;
|
6861 |
+
|
6862 |
+
if ((hist.lastOp == opId ||
|
6863 |
+
hist.lastOrigin == change.origin && change.origin &&
|
6864 |
+
((change.origin.charAt(0) == "+" && doc.cm && hist.lastModTime > time - doc.cm.options.historyEventDelay) ||
|
6865 |
+
change.origin.charAt(0) == "*")) &&
|
6866 |
+
(cur = lastChangeEvent(hist, hist.lastOp == opId))) {
|
6867 |
+
// Merge this change into the last event
|
6868 |
+
var last = lst(cur.changes);
|
6869 |
+
if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
|
6870 |
+
// Optimized case for simple insertion -- don't want to add
|
6871 |
+
// new changesets for every character typed
|
6872 |
+
last.to = changeEnd(change);
|
6873 |
+
} else {
|
6874 |
+
// Add new sub-event
|
6875 |
+
cur.changes.push(historyChangeFromChange(doc, change));
|
6876 |
+
}
|
6877 |
+
} else {
|
6878 |
+
// Can not be merged, start a new event.
|
6879 |
+
var before = lst(hist.done);
|
6880 |
+
if (!before || !before.ranges)
|
6881 |
+
pushSelectionToHistory(doc.sel, hist.done);
|
6882 |
+
cur = {changes: [historyChangeFromChange(doc, change)],
|
6883 |
+
generation: hist.generation};
|
6884 |
+
hist.done.push(cur);
|
6885 |
+
while (hist.done.length > hist.undoDepth) {
|
6886 |
+
hist.done.shift();
|
6887 |
+
if (!hist.done[0].ranges) hist.done.shift();
|
6888 |
+
}
|
6889 |
+
}
|
6890 |
+
hist.done.push(selAfter);
|
6891 |
+
hist.generation = ++hist.maxGeneration;
|
6892 |
+
hist.lastModTime = hist.lastSelTime = time;
|
6893 |
+
hist.lastOp = opId;
|
6894 |
+
hist.lastOrigin = hist.lastSelOrigin = change.origin;
|
6895 |
+
|
6896 |
+
if (!last) signal(doc, "historyAdded");
|
6897 |
+
}
|
6898 |
+
|
6899 |
+
function selectionEventCanBeMerged(doc, origin, prev, sel) {
|
6900 |
+
var ch = origin.charAt(0);
|
6901 |
+
return ch == "*" ||
|
6902 |
+
ch == "+" &&
|
6903 |
+
prev.ranges.length == sel.ranges.length &&
|
6904 |
+
prev.somethingSelected() == sel.somethingSelected() &&
|
6905 |
+
new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500);
|
6906 |
+
}
|
6907 |
+
|
6908 |
+
// Called whenever the selection changes, sets the new selection as
|
6909 |
+
// the pending selection in the history, and pushes the old pending
|
6910 |
+
// selection into the 'done' array when it was significantly
|
6911 |
+
// different (in number of selected ranges, emptiness, or time).
|
6912 |
+
function addSelectionToHistory(doc, sel, opId, options) {
|
6913 |
+
var hist = doc.history, origin = options && options.origin;
|
6914 |
+
|
6915 |
+
// A new event is started when the previous origin does not match
|
6916 |
+
// the current, or the origins don't allow matching. Origins
|
6917 |
+
// starting with * are always merged, those starting with + are
|
6918 |
+
// merged when similar and close together in time.
|
6919 |
+
if (opId == hist.lastOp ||
|
6920 |
+
(origin && hist.lastSelOrigin == origin &&
|
6921 |
+
(hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
|
6922 |
+
selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
|
6923 |
+
hist.done[hist.done.length - 1] = sel;
|
6924 |
+
else
|
6925 |
+
pushSelectionToHistory(sel, hist.done);
|
6926 |
+
|
6927 |
+
hist.lastSelTime = +new Date;
|
6928 |
+
hist.lastSelOrigin = origin;
|
6929 |
+
hist.lastOp = opId;
|
6930 |
+
if (options && options.clearRedo !== false)
|
6931 |
+
clearSelectionEvents(hist.undone);
|
6932 |
+
}
|
6933 |
+
|
6934 |
+
function pushSelectionToHistory(sel, dest) {
|
6935 |
+
var top = lst(dest);
|
6936 |
+
if (!(top && top.ranges && top.equals(sel)))
|
6937 |
+
dest.push(sel);
|
6938 |
+
}
|
6939 |
+
|
6940 |
+
// Used to store marked span information in the history.
|
6941 |
+
function attachLocalSpans(doc, change, from, to) {
|
6942 |
+
var existing = change["spans_" + doc.id], n = 0;
|
6943 |
+
doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function(line) {
|
6944 |
+
if (line.markedSpans)
|
6945 |
+
(existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans;
|
6946 |
+
++n;
|
6947 |
+
});
|
6948 |
+
}
|
6949 |
+
|
6950 |
+
// When un/re-doing restores text containing marked spans, those
|
6951 |
+
// that have been explicitly cleared should not be restored.
|
6952 |
+
function removeClearedSpans(spans) {
|
6953 |
+
if (!spans) return null;
|
6954 |
+
for (var i = 0, out; i < spans.length; ++i) {
|
6955 |
+
if (spans[i].marker.explicitlyCleared) { if (!out) out = spans.slice(0, i); }
|
6956 |
+
else if (out) out.push(spans[i]);
|
6957 |
+
}
|
6958 |
+
return !out ? spans : out.length ? out : null;
|
6959 |
+
}
|
6960 |
+
|
6961 |
+
// Retrieve and filter the old marked spans stored in a change event.
|
6962 |
+
function getOldSpans(doc, change) {
|
6963 |
+
var found = change["spans_" + doc.id];
|
6964 |
+
if (!found) return null;
|
6965 |
+
for (var i = 0, nw = []; i < change.text.length; ++i)
|
6966 |
+
nw.push(removeClearedSpans(found[i]));
|
6967 |
+
return nw;
|
6968 |
+
}
|
6969 |
+
|
6970 |
+
// Used both to provide a JSON-safe object in .getHistory, and, when
|
6971 |
+
// detaching a document, to split the history in two
|
6972 |
+
function copyHistoryArray(events, newGroup, instantiateSel) {
|
6973 |
+
for (var i = 0, copy = []; i < events.length; ++i) {
|
6974 |
+
var event = events[i];
|
6975 |
+
if (event.ranges) {
|
6976 |
+
copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
|
6977 |
+
continue;
|
6978 |
+
}
|
6979 |
+
var changes = event.changes, newChanges = [];
|
6980 |
+
copy.push({changes: newChanges});
|
6981 |
+
for (var j = 0; j < changes.length; ++j) {
|
6982 |
+
var change = changes[j], m;
|
6983 |
+
newChanges.push({from: change.from, to: change.to, text: change.text});
|
6984 |
+
if (newGroup) for (var prop in change) if (m = prop.match(/^spans_(\d+)$/)) {
|
6985 |
+
if (indexOf(newGroup, Number(m[1])) > -1) {
|
6986 |
+
lst(newChanges)[prop] = change[prop];
|
6987 |
+
delete change[prop];
|
6988 |
+
}
|
6989 |
+
}
|
6990 |
+
}
|
6991 |
+
}
|
6992 |
+
return copy;
|
6993 |
+
}
|
6994 |
+
|
6995 |
+
// Rebasing/resetting history to deal with externally-sourced changes
|
6996 |
+
|
6997 |
+
function rebaseHistSelSingle(pos, from, to, diff) {
|
6998 |
+
if (to < pos.line) {
|
6999 |
+
pos.line += diff;
|
7000 |
+
} else if (from < pos.line) {
|
7001 |
+
pos.line = from;
|
7002 |
+
pos.ch = 0;
|
7003 |
+
}
|
7004 |
+
}
|
7005 |
+
|
7006 |
+
// Tries to rebase an array of history events given a change in the
|
7007 |
+
// document. If the change touches the same lines as the event, the
|
7008 |
+
// event, and everything 'behind' it, is discarded. If the change is
|
7009 |
+
// before the event, the event's positions are updated. Uses a
|
7010 |
+
// copy-on-write scheme for the positions, to avoid having to
|
7011 |
+
// reallocate them all on every rebase, but also avoid problems with
|
7012 |
+
// shared position objects being unsafely updated.
|
7013 |
+
function rebaseHistArray(array, from, to, diff) {
|
7014 |
+
for (var i = 0; i < array.length; ++i) {
|
7015 |
+
var sub = array[i], ok = true;
|
7016 |
+
if (sub.ranges) {
|
7017 |
+
if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; }
|
7018 |
+
for (var j = 0; j < sub.ranges.length; j++) {
|
7019 |
+
rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
|
7020 |
+
rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
|
7021 |
+
}
|
7022 |
+
continue;
|
7023 |
+
}
|
7024 |
+
for (var j = 0; j < sub.changes.length; ++j) {
|
7025 |
+
var cur = sub.changes[j];
|
7026 |
+
if (to < cur.from.line) {
|
7027 |
+
cur.from = Pos(cur.from.line + diff, cur.from.ch);
|
7028 |
+
cur.to = Pos(cur.to.line + diff, cur.to.ch);
|
7029 |
+
} else if (from <= cur.to.line) {
|
7030 |
+
ok = false;
|
7031 |
+
break;
|
7032 |
+
}
|
7033 |
+
}
|
7034 |
+
if (!ok) {
|
7035 |
+
array.splice(0, i + 1);
|
7036 |
+
i = 0;
|
7037 |
+
}
|
7038 |
+
}
|
7039 |
+
}
|
7040 |
+
|
7041 |
+
function rebaseHist(hist, change) {
|
7042 |
+
var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
|
7043 |
+
rebaseHistArray(hist.done, from, to, diff);
|
7044 |
+
rebaseHistArray(hist.undone, from, to, diff);
|
7045 |
+
}
|
7046 |
+
|
7047 |
+
// EVENT UTILITIES
|
7048 |
+
|
7049 |
+
// Due to the fact that we still support jurassic IE versions, some
|
7050 |
+
// compatibility wrappers are needed.
|
7051 |
+
|
7052 |
+
var e_preventDefault = CodeMirror.e_preventDefault = function(e) {
|
7053 |
+
if (e.preventDefault) e.preventDefault();
|
7054 |
+
else e.returnValue = false;
|
7055 |
+
};
|
7056 |
+
var e_stopPropagation = CodeMirror.e_stopPropagation = function(e) {
|
7057 |
+
if (e.stopPropagation) e.stopPropagation();
|
7058 |
+
else e.cancelBubble = true;
|
7059 |
+
};
|
7060 |
+
function e_defaultPrevented(e) {
|
7061 |
+
return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false;
|
7062 |
+
}
|
7063 |
+
var e_stop = CodeMirror.e_stop = function(e) {e_preventDefault(e); e_stopPropagation(e);};
|
7064 |
+
|
7065 |
+
function e_target(e) {return e.target || e.srcElement;}
|
7066 |
+
function e_button(e) {
|
7067 |
+
var b = e.which;
|
7068 |
+
if (b == null) {
|
7069 |
+
if (e.button & 1) b = 1;
|
7070 |
+
else if (e.button & 2) b = 3;
|
7071 |
+
else if (e.button & 4) b = 2;
|
7072 |
+
}
|
7073 |
+
if (mac && e.ctrlKey && b == 1) b = 3;
|
7074 |
+
return b;
|
7075 |
+
}
|
7076 |
+
|
7077 |
+
// EVENT HANDLING
|
7078 |
+
|
7079 |
+
// Lightweight event framework. on/off also work on DOM nodes,
|
7080 |
+
// registering native DOM handlers.
|
7081 |
+
|
7082 |
+
var on = CodeMirror.on = function(emitter, type, f) {
|
7083 |
+
if (emitter.addEventListener)
|
7084 |
+
emitter.addEventListener(type, f, false);
|
7085 |
+
else if (emitter.attachEvent)
|
7086 |
+
emitter.attachEvent("on" + type, f);
|
7087 |
+
else {
|
7088 |
+
var map = emitter._handlers || (emitter._handlers = {});
|
7089 |
+
var arr = map[type] || (map[type] = []);
|
7090 |
+
arr.push(f);
|
7091 |
+
}
|
7092 |
+
};
|
7093 |
+
|
7094 |
+
var off = CodeMirror.off = function(emitter, type, f) {
|
7095 |
+
if (emitter.removeEventListener)
|
7096 |
+
emitter.removeEventListener(type, f, false);
|
7097 |
+
else if (emitter.detachEvent)
|
7098 |
+
emitter.detachEvent("on" + type, f);
|
7099 |
+
else {
|
7100 |
+
var arr = emitter._handlers && emitter._handlers[type];
|
7101 |
+
if (!arr) return;
|
7102 |
+
for (var i = 0; i < arr.length; ++i)
|
7103 |
+
if (arr[i] == f) { arr.splice(i, 1); break; }
|
7104 |
+
}
|
7105 |
+
};
|
7106 |
+
|
7107 |
+
var signal = CodeMirror.signal = function(emitter, type /*, values...*/) {
|
7108 |
+
var arr = emitter._handlers && emitter._handlers[type];
|
7109 |
+
if (!arr) return;
|
7110 |
+
var args = Array.prototype.slice.call(arguments, 2);
|
7111 |
+
for (var i = 0; i < arr.length; ++i) arr[i].apply(null, args);
|
7112 |
+
};
|
7113 |
+
|
7114 |
+
var orphanDelayedCallbacks = null;
|
7115 |
+
|
7116 |
+
// Often, we want to signal events at a point where we are in the
|
7117 |
+
// middle of some work, but don't want the handler to start calling
|
7118 |
+
// other methods on the editor, which might be in an inconsistent
|
7119 |
+
// state or simply not expect any other events to happen.
|
7120 |
+
// signalLater looks whether there are any handlers, and schedules
|
7121 |
+
// them to be executed when the last operation ends, or, if no
|
7122 |
+
// operation is active, when a timeout fires.
|
7123 |
+
function signalLater(emitter, type /*, values...*/) {
|
7124 |
+
var arr = emitter._handlers && emitter._handlers[type];
|
7125 |
+
if (!arr) return;
|
7126 |
+
var args = Array.prototype.slice.call(arguments, 2), list;
|
7127 |
+
if (operationGroup) {
|
7128 |
+
list = operationGroup.delayedCallbacks;
|
7129 |
+
} else if (orphanDelayedCallbacks) {
|
7130 |
+
list = orphanDelayedCallbacks;
|
7131 |
+
} else {
|
7132 |
+
list = orphanDelayedCallbacks = [];
|
7133 |
+
setTimeout(fireOrphanDelayed, 0);
|
7134 |
+
}
|
7135 |
+
function bnd(f) {return function(){f.apply(null, args);};};
|
7136 |
+
for (var i = 0; i < arr.length; ++i)
|
7137 |
+
list.push(bnd(arr[i]));
|
7138 |
+
}
|
7139 |
+
|
7140 |
+
function fireOrphanDelayed() {
|
7141 |
+
var delayed = orphanDelayedCallbacks;
|
7142 |
+
orphanDelayedCallbacks = null;
|
7143 |
+
for (var i = 0; i < delayed.length; ++i) delayed[i]();
|
7144 |
+
}
|
7145 |
+
|
7146 |
+
// The DOM events that CodeMirror handles can be overridden by
|
7147 |
+
// registering a (non-DOM) handler on the editor for the event name,
|
7148 |
+
// and preventDefault-ing the event in that handler.
|
7149 |
+
function signalDOMEvent(cm, e, override) {
|
7150 |
+
signal(cm, override || e.type, cm, e);
|
7151 |
+
return e_defaultPrevented(e) || e.codemirrorIgnore;
|
7152 |
+
}
|
7153 |
+
|
7154 |
+
function signalCursorActivity(cm) {
|
7155 |
+
var arr = cm._handlers && cm._handlers.cursorActivity;
|
7156 |
+
if (!arr) return;
|
7157 |
+
var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);
|
7158 |
+
for (var i = 0; i < arr.length; ++i) if (indexOf(set, arr[i]) == -1)
|
7159 |
+
set.push(arr[i]);
|
7160 |
+
}
|
7161 |
+
|
7162 |
+
function hasHandler(emitter, type) {
|
7163 |
+
var arr = emitter._handlers && emitter._handlers[type];
|
7164 |
+
return arr && arr.length > 0;
|
7165 |
+
}
|
7166 |
+
|
7167 |
+
// Add on and off methods to a constructor's prototype, to make
|
7168 |
+
// registering events on such objects more convenient.
|
7169 |
+
function eventMixin(ctor) {
|
7170 |
+
ctor.prototype.on = function(type, f) {on(this, type, f);};
|
7171 |
+
ctor.prototype.off = function(type, f) {off(this, type, f);};
|
7172 |
+
}
|
7173 |
+
|
7174 |
+
// MISC UTILITIES
|
7175 |
+
|
7176 |
+
// Number of pixels added to scroller and sizer to hide scrollbar
|
7177 |
+
var scrollerCutOff = 30;
|
7178 |
+
|
7179 |
+
// Returned or thrown by various protocols to signal 'I'm not
|
7180 |
+
// handling this'.
|
7181 |
+
var Pass = CodeMirror.Pass = {toString: function(){return "CodeMirror.Pass";}};
|
7182 |
+
|
7183 |
+
// Reused option objects for setSelection & friends
|
7184 |
+
var sel_dontScroll = {scroll: false}, sel_mouse = {origin: "*mouse"}, sel_move = {origin: "+move"};
|
7185 |
+
|
7186 |
+
function Delayed() {this.id = null;}
|
7187 |
+
Delayed.prototype.set = function(ms, f) {
|
7188 |
+
clearTimeout(this.id);
|
7189 |
+
this.id = setTimeout(f, ms);
|
7190 |
+
};
|
7191 |
+
|
7192 |
+
// Counts the column offset in a string, taking tabs into account.
|
7193 |
+
// Used mostly to find indentation.
|
7194 |
+
var countColumn = CodeMirror.countColumn = function(string, end, tabSize, startIndex, startValue) {
|
7195 |
+
if (end == null) {
|
7196 |
+
end = string.search(/[^\s\u00a0]/);
|
7197 |
+
if (end == -1) end = string.length;
|
7198 |
+
}
|
7199 |
+
for (var i = startIndex || 0, n = startValue || 0;;) {
|
7200 |
+
var nextTab = string.indexOf("\t", i);
|
7201 |
+
if (nextTab < 0 || nextTab >= end)
|
7202 |
+
return n + (end - i);
|
7203 |
+
n += nextTab - i;
|
7204 |
+
n += tabSize - (n % tabSize);
|
7205 |
+
i = nextTab + 1;
|
7206 |
+
}
|
7207 |
+
};
|
7208 |
+
|
7209 |
+
// The inverse of countColumn -- find the offset that corresponds to
|
7210 |
+
// a particular column.
|
7211 |
+
function findColumn(string, goal, tabSize) {
|
7212 |
+
for (var pos = 0, col = 0;;) {
|
7213 |
+
var nextTab = string.indexOf("\t", pos);
|
7214 |
+
if (nextTab == -1) nextTab = string.length;
|
7215 |
+
var skipped = nextTab - pos;
|
7216 |
+
if (nextTab == string.length || col + skipped >= goal)
|
7217 |
+
return pos + Math.min(skipped, goal - col);
|
7218 |
+
col += nextTab - pos;
|
7219 |
+
col += tabSize - (col % tabSize);
|
7220 |
+
pos = nextTab + 1;
|
7221 |
+
if (col >= goal) return pos;
|
7222 |
+
}
|
7223 |
+
}
|
7224 |
+
|
7225 |
+
var spaceStrs = [""];
|
7226 |
+
function spaceStr(n) {
|
7227 |
+
while (spaceStrs.length <= n)
|
7228 |
+
spaceStrs.push(lst(spaceStrs) + " ");
|
7229 |
+
return spaceStrs[n];
|
7230 |
+
}
|
7231 |
+
|
7232 |
+
function lst(arr) { return arr[arr.length-1]; }
|
7233 |
+
|
7234 |
+
var selectInput = function(node) { node.select(); };
|
7235 |
+
if (ios) // Mobile Safari apparently has a bug where select() is broken.
|
7236 |
+
selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; };
|
7237 |
+
else if (ie) // Suppress mysterious IE10 errors
|
7238 |
+
selectInput = function(node) { try { node.select(); } catch(_e) {} };
|
7239 |
+
|
7240 |
+
function indexOf(array, elt) {
|
7241 |
+
for (var i = 0; i < array.length; ++i)
|
7242 |
+
if (array[i] == elt) return i;
|
7243 |
+
return -1;
|
7244 |
+
}
|
7245 |
+
if ([].indexOf) indexOf = function(array, elt) { return array.indexOf(elt); };
|
7246 |
+
function map(array, f) {
|
7247 |
+
var out = [];
|
7248 |
+
for (var i = 0; i < array.length; i++) out[i] = f(array[i], i);
|
7249 |
+
return out;
|
7250 |
+
}
|
7251 |
+
if ([].map) map = function(array, f) { return array.map(f); };
|
7252 |
+
|
7253 |
+
function createObj(base, props) {
|
7254 |
+
var inst;
|
7255 |
+
if (Object.create) {
|
7256 |
+
inst = Object.create(base);
|
7257 |
+
} else {
|
7258 |
+
var ctor = function() {};
|
7259 |
+
ctor.prototype = base;
|
7260 |
+
inst = new ctor();
|
7261 |
+
}
|
7262 |
+
if (props) copyObj(props, inst);
|
7263 |
+
return inst;
|
7264 |
+
};
|
7265 |
+
|
7266 |
+
function copyObj(obj, target, overwrite) {
|
7267 |
+
if (!target) target = {};
|
7268 |
+
for (var prop in obj)
|
7269 |
+
if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
|
7270 |
+
target[prop] = obj[prop];
|
7271 |
+
return target;
|
7272 |
+
}
|
7273 |
+
|
7274 |
+
function bind(f) {
|
7275 |
+
var args = Array.prototype.slice.call(arguments, 1);
|
7276 |
+
return function(){return f.apply(null, args);};
|
7277 |
+
}
|
7278 |
+
|
7279 |
+
var nonASCIISingleCaseWordChar = /[\u00df\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
|
7280 |
+
var isWordCharBasic = CodeMirror.isWordChar = function(ch) {
|
7281 |
+
return /\w/.test(ch) || ch > "\x80" &&
|
7282 |
+
(ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
|
7283 |
+
};
|
7284 |
+
function isWordChar(ch, helper) {
|
7285 |
+
if (!helper) return isWordCharBasic(ch);
|
7286 |
+
if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) return true;
|
7287 |
+
return helper.test(ch);
|
7288 |
+
}
|
7289 |
+
|
7290 |
+
function isEmpty(obj) {
|
7291 |
+
for (var n in obj) if (obj.hasOwnProperty(n) && obj[n]) return false;
|
7292 |
+
return true;
|
7293 |
+
}
|
7294 |
+
|
7295 |
+
// Extending unicode characters. A series of a non-extending char +
|
7296 |
+
// any number of extending chars is treated as a single unit as far
|
7297 |
+
// as editing and measuring is concerned. This is not fully correct,
|
7298 |
+
// since some scripts/fonts/browsers also treat other configurations
|
7299 |
+
// of code points as a group.
|
7300 |
+
var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;
|
7301 |
+
function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch); }
|
7302 |
+
|
7303 |
+
// DOM UTILITIES
|
7304 |
+
|
7305 |
+
function elt(tag, content, className, style) {
|
7306 |
+
var e = document.createElement(tag);
|
7307 |
+
if (className) e.className = className;
|
7308 |
+
if (style) e.style.cssText = style;
|
7309 |
+
if (typeof content == "string") e.appendChild(document.createTextNode(content));
|
7310 |
+
else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
|
7311 |
+
return e;
|
7312 |
+
}
|
7313 |
+
|
7314 |
+
var range;
|
7315 |
+
if (document.createRange) range = function(node, start, end) {
|
7316 |
+
var r = document.createRange();
|
7317 |
+
r.setEnd(node, end);
|
7318 |
+
r.setStart(node, start);
|
7319 |
+
return r;
|
7320 |
+
};
|
7321 |
+
else range = function(node, start, end) {
|
7322 |
+
var r = document.body.createTextRange();
|
7323 |
+
r.moveToElementText(node.parentNode);
|
7324 |
+
r.collapse(true);
|
7325 |
+
r.moveEnd("character", end);
|
7326 |
+
r.moveStart("character", start);
|
7327 |
+
return r;
|
7328 |
+
};
|
7329 |
+
|
7330 |
+
function removeChildren(e) {
|
7331 |
+
for (var count = e.childNodes.length; count > 0; --count)
|
7332 |
+
e.removeChild(e.firstChild);
|
7333 |
+
return e;
|
7334 |
+
}
|
7335 |
+
|
7336 |
+
function removeChildrenAndAdd(parent, e) {
|
7337 |
+
return removeChildren(parent).appendChild(e);
|
7338 |
+
}
|
7339 |
+
|
7340 |
+
function contains(parent, child) {
|
7341 |
+
if (parent.contains)
|
7342 |
+
return parent.contains(child);
|
7343 |
+
while (child = child.parentNode)
|
7344 |
+
if (child == parent) return true;
|
7345 |
+
}
|
7346 |
+
|
7347 |
+
function activeElt() { return document.activeElement; }
|
7348 |
+
// Older versions of IE throws unspecified error when touching
|
7349 |
+
// document.activeElement in some cases (during loading, in iframe)
|
7350 |
+
if (ie && ie_version < 11) activeElt = function() {
|
7351 |
+
try { return document.activeElement; }
|
7352 |
+
catch(e) { return document.body; }
|
7353 |
+
};
|
7354 |
+
|
7355 |
+
function classTest(cls) { return new RegExp("\\b" + cls + "\\b\\s*"); }
|
7356 |
+
function rmClass(node, cls) {
|
7357 |
+
var test = classTest(cls);
|
7358 |
+
if (test.test(node.className)) node.className = node.className.replace(test, "");
|
7359 |
+
}
|
7360 |
+
function addClass(node, cls) {
|
7361 |
+
if (!classTest(cls).test(node.className)) node.className += " " + cls;
|
7362 |
+
}
|
7363 |
+
function joinClasses(a, b) {
|
7364 |
+
var as = a.split(" ");
|
7365 |
+
for (var i = 0; i < as.length; i++)
|
7366 |
+
if (as[i] && !classTest(as[i]).test(b)) b += " " + as[i];
|
7367 |
+
return b;
|
7368 |
+
}
|
7369 |
+
|
7370 |
+
// WINDOW-WIDE EVENTS
|
7371 |
+
|
7372 |
+
// These must be handled carefully, because naively registering a
|
7373 |
+
// handler for each editor will cause the editors to never be
|
7374 |
+
// garbage collected.
|
7375 |
+
|
7376 |
+
function forEachCodeMirror(f) {
|
7377 |
+
if (!document.body.getElementsByClassName) return;
|
7378 |
+
var byClass = document.body.getElementsByClassName("CodeMirror");
|
7379 |
+
for (var i = 0; i < byClass.length; i++) {
|
7380 |
+
var cm = byClass[i].CodeMirror;
|
7381 |
+
if (cm) f(cm);
|
7382 |
+
}
|
7383 |
+
}
|
7384 |
+
|
7385 |
+
var globalsRegistered = false;
|
7386 |
+
function ensureGlobalHandlers() {
|
7387 |
+
if (globalsRegistered) return;
|
7388 |
+
registerGlobalHandlers();
|
7389 |
+
globalsRegistered = true;
|
7390 |
+
}
|
7391 |
+
function registerGlobalHandlers() {
|
7392 |
+
// When the window resizes, we need to refresh active editors.
|
7393 |
+
var resizeTimer;
|
7394 |
+
on(window, "resize", function() {
|
7395 |
+
if (resizeTimer == null) resizeTimer = setTimeout(function() {
|
7396 |
+
resizeTimer = null;
|
7397 |
+
knownScrollbarWidth = null;
|
7398 |
+
forEachCodeMirror(onResize);
|
7399 |
+
}, 100);
|
7400 |
+
});
|
7401 |
+
// When the window loses focus, we want to show the editor as blurred
|
7402 |
+
on(window, "blur", function() {
|
7403 |
+
forEachCodeMirror(onBlur);
|
7404 |
+
});
|
7405 |
+
}
|
7406 |
+
|
7407 |
+
// FEATURE DETECTION
|
7408 |
+
|
7409 |
+
// Detect drag-and-drop
|
7410 |
+
var dragAndDrop = function() {
|
7411 |
+
// There is *some* kind of drag-and-drop support in IE6-8, but I
|
7412 |
+
// couldn't get it to work yet.
|
7413 |
+
if (ie && ie_version < 9) return false;
|
7414 |
+
var div = elt('div');
|
7415 |
+
return "draggable" in div || "dragDrop" in div;
|
7416 |
+
}();
|
7417 |
+
|
7418 |
+
var knownScrollbarWidth;
|
7419 |
+
function scrollbarWidth(measure) {
|
7420 |
+
if (knownScrollbarWidth != null) return knownScrollbarWidth;
|
7421 |
+
var test = elt("div", null, null, "width: 50px; height: 50px; overflow-x: scroll");
|
7422 |
+
removeChildrenAndAdd(measure, test);
|
7423 |
+
if (test.offsetWidth)
|
7424 |
+
knownScrollbarWidth = test.offsetHeight - test.clientHeight;
|
7425 |
+
return knownScrollbarWidth || 0;
|
7426 |
+
}
|
7427 |
+
|
7428 |
+
var zwspSupported;
|
7429 |
+
function zeroWidthElement(measure) {
|
7430 |
+
if (zwspSupported == null) {
|
7431 |
+
var test = elt("span", "\u200b");
|
7432 |
+
removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
|
7433 |
+
if (measure.firstChild.offsetHeight != 0)
|
7434 |
+
zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8);
|
7435 |
+
}
|
7436 |
+
if (zwspSupported) return elt("span", "\u200b");
|
7437 |
+
else return elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
|
7438 |
+
}
|
7439 |
+
|
7440 |
+
// Feature-detect IE's crummy client rect reporting for bidi text
|
7441 |
+
var badBidiRects;
|
7442 |
+
function hasBadBidiRects(measure) {
|
7443 |
+
if (badBidiRects != null) return badBidiRects;
|
7444 |
+
var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"));
|
7445 |
+
var r0 = range(txt, 0, 1).getBoundingClientRect();
|
7446 |
+
if (r0.left == r0.right) return false;
|
7447 |
+
var r1 = range(txt, 1, 2).getBoundingClientRect();
|
7448 |
+
return badBidiRects = (r1.right - r0.right < 3);
|
7449 |
+
}
|
7450 |
+
|
7451 |
+
// See if "".split is the broken IE version, if so, provide an
|
7452 |
+
// alternative way to split lines.
|
7453 |
+
var splitLines = CodeMirror.splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
|
7454 |
+
var pos = 0, result = [], l = string.length;
|
7455 |
+
while (pos <= l) {
|
7456 |
+
var nl = string.indexOf("\n", pos);
|
7457 |
+
if (nl == -1) nl = string.length;
|
7458 |
+
var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
|
7459 |
+
var rt = line.indexOf("\r");
|
7460 |
+
if (rt != -1) {
|
7461 |
+
result.push(line.slice(0, rt));
|
7462 |
+
pos += rt + 1;
|
7463 |
+
} else {
|
7464 |
+
result.push(line);
|
7465 |
+
pos = nl + 1;
|
7466 |
+
}
|
7467 |
+
}
|
7468 |
+
return result;
|
7469 |
+
} : function(string){return string.split(/\r\n?|\n/);};
|
7470 |
+
|
7471 |
+
var hasSelection = window.getSelection ? function(te) {
|
7472 |
+
try { return te.selectionStart != te.selectionEnd; }
|
7473 |
+
catch(e) { return false; }
|
7474 |
+
} : function(te) {
|
7475 |
+
try {var range = te.ownerDocument.selection.createRange();}
|
7476 |
+
catch(e) {}
|
7477 |
+
if (!range || range.parentElement() != te) return false;
|
7478 |
+
return range.compareEndPoints("StartToEnd", range) != 0;
|
7479 |
+
};
|
7480 |
+
|
7481 |
+
var hasCopyEvent = (function() {
|
7482 |
+
var e = elt("div");
|
7483 |
+
if ("oncopy" in e) return true;
|
7484 |
+
e.setAttribute("oncopy", "return;");
|
7485 |
+
return typeof e.oncopy == "function";
|
7486 |
+
})();
|
7487 |
+
|
7488 |
+
var badZoomedRects = null;
|
7489 |
+
function hasBadZoomedRects(measure) {
|
7490 |
+
if (badZoomedRects != null) return badZoomedRects;
|
7491 |
+
var node = removeChildrenAndAdd(measure, elt("span", "x"));
|
7492 |
+
var normal = node.getBoundingClientRect();
|
7493 |
+
var fromRange = range(node, 0, 1).getBoundingClientRect();
|
7494 |
+
return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1;
|
7495 |
+
}
|
7496 |
+
|
7497 |
+
// KEY NAMES
|
7498 |
+
|
7499 |
+
var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
|
7500 |
+
19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
|
7501 |
+
36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
|
7502 |
+
46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod", 107: "=", 109: "-", 127: "Delete",
|
7503 |
+
173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
|
7504 |
+
221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
|
7505 |
+
63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"};
|
7506 |
+
CodeMirror.keyNames = keyNames;
|
7507 |
+
(function() {
|
7508 |
+
// Number keys
|
7509 |
+
for (var i = 0; i < 10; i++) keyNames[i + 48] = keyNames[i + 96] = String(i);
|
7510 |
+
// Alphabetic keys
|
7511 |
+
for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
|
7512 |
+
// Function keys
|
7513 |
+
for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
|
7514 |
+
})();
|
7515 |
+
|
7516 |
+
// BIDI HELPERS
|
7517 |
+
|
7518 |
+
function iterateBidiSections(order, from, to, f) {
|
7519 |
+
if (!order) return f(from, to, "ltr");
|
7520 |
+
var found = false;
|
7521 |
+
for (var i = 0; i < order.length; ++i) {
|
7522 |
+
var part = order[i];
|
7523 |
+
if (part.from < to && part.to > from || from == to && part.to == from) {
|
7524 |
+
f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr");
|
7525 |
+
found = true;
|
7526 |
+
}
|
7527 |
+
}
|
7528 |
+
if (!found) f(from, to, "ltr");
|
7529 |
+
}
|
7530 |
+
|
7531 |
+
function bidiLeft(part) { return part.level % 2 ? part.to : part.from; }
|
7532 |
+
function bidiRight(part) { return part.level % 2 ? part.from : part.to; }
|
7533 |
+
|
7534 |
+
function lineLeft(line) { var order = getOrder(line); return order ? bidiLeft(order[0]) : 0; }
|
7535 |
+
function lineRight(line) {
|
7536 |
+
var order = getOrder(line);
|
7537 |
+
if (!order) return line.text.length;
|
7538 |
+
return bidiRight(lst(order));
|
7539 |
+
}
|
7540 |
+
|
7541 |
+
function lineStart(cm, lineN) {
|
7542 |
+
var line = getLine(cm.doc, lineN);
|
7543 |
+
var visual = visualLine(line);
|
7544 |
+
if (visual != line) lineN = lineNo(visual);
|
7545 |
+
var order = getOrder(visual);
|
7546 |
+
var ch = !order ? 0 : order[0].level % 2 ? lineRight(visual) : lineLeft(visual);
|
7547 |
+
return Pos(lineN, ch);
|
7548 |
+
}
|
7549 |
+
function lineEnd(cm, lineN) {
|
7550 |
+
var merged, line = getLine(cm.doc, lineN);
|
7551 |
+
while (merged = collapsedSpanAtEnd(line)) {
|
7552 |
+
line = merged.find(1, true).line;
|
7553 |
+
lineN = null;
|
7554 |
+
}
|
7555 |
+
var order = getOrder(line);
|
7556 |
+
var ch = !order ? line.text.length : order[0].level % 2 ? lineLeft(line) : lineRight(line);
|
7557 |
+
return Pos(lineN == null ? lineNo(line) : lineN, ch);
|
7558 |
+
}
|
7559 |
+
|
7560 |
+
function compareBidiLevel(order, a, b) {
|
7561 |
+
var linedir = order[0].level;
|
7562 |
+
if (a == linedir) return true;
|
7563 |
+
if (b == linedir) return false;
|
7564 |
+
return a < b;
|
7565 |
+
}
|
7566 |
+
var bidiOther;
|
7567 |
+
function getBidiPartAt(order, pos) {
|
7568 |
+
bidiOther = null;
|
7569 |
+
for (var i = 0, found; i < order.length; ++i) {
|
7570 |
+
var cur = order[i];
|
7571 |
+
if (cur.from < pos && cur.to > pos) return i;
|
7572 |
+
if ((cur.from == pos || cur.to == pos)) {
|
7573 |
+
if (found == null) {
|
7574 |
+
found = i;
|
7575 |
+
} else if (compareBidiLevel(order, cur.level, order[found].level)) {
|
7576 |
+
if (cur.from != cur.to) bidiOther = found;
|
7577 |
+
return i;
|
7578 |
+
} else {
|
7579 |
+
if (cur.from != cur.to) bidiOther = i;
|
7580 |
+
return found;
|
7581 |
+
}
|
7582 |
+
}
|
7583 |
+
}
|
7584 |
+
return found;
|
7585 |
+
}
|
7586 |
+
|
7587 |
+
function moveInLine(line, pos, dir, byUnit) {
|
7588 |
+
if (!byUnit) return pos + dir;
|
7589 |
+
do pos += dir;
|
7590 |
+
while (pos > 0 && isExtendingChar(line.text.charAt(pos)));
|
7591 |
+
return pos;
|
7592 |
+
}
|
7593 |
+
|
7594 |
+
// This is needed in order to move 'visually' through bi-directional
|
7595 |
+
// text -- i.e., pressing left should make the cursor go left, even
|
7596 |
+
// when in RTL text. The tricky part is the 'jumps', where RTL and
|
7597 |
+
// LTR text touch each other. This often requires the cursor offset
|
7598 |
+
// to move more than one unit, in order to visually move one unit.
|
7599 |
+
function moveVisually(line, start, dir, byUnit) {
|
7600 |
+
var bidi = getOrder(line);
|
7601 |
+
if (!bidi) return moveLogically(line, start, dir, byUnit);
|
7602 |
+
var pos = getBidiPartAt(bidi, start), part = bidi[pos];
|
7603 |
+
var target = moveInLine(line, start, part.level % 2 ? -dir : dir, byUnit);
|
7604 |
+
|
7605 |
+
for (;;) {
|
7606 |
+
if (target > part.from && target < part.to) return target;
|
7607 |
+
if (target == part.from || target == part.to) {
|
7608 |
+
if (getBidiPartAt(bidi, target) == pos) return target;
|
7609 |
+
part = bidi[pos += dir];
|
7610 |
+
return (dir > 0) == part.level % 2 ? part.to : part.from;
|
7611 |
+
} else {
|
7612 |
+
part = bidi[pos += dir];
|
7613 |
+
if (!part) return null;
|
7614 |
+
if ((dir > 0) == part.level % 2)
|
7615 |
+
target = moveInLine(line, part.to, -1, byUnit);
|
7616 |
+
else
|
7617 |
+
target = moveInLine(line, part.from, 1, byUnit);
|
7618 |
+
}
|
7619 |
+
}
|
7620 |
+
}
|
7621 |
+
|
7622 |
+
function moveLogically(line, start, dir, byUnit) {
|
7623 |
+
var target = start + dir;
|
7624 |
+
if (byUnit) while (target > 0 && isExtendingChar(line.text.charAt(target))) target += dir;
|
7625 |
+
return target < 0 || target > line.text.length ? null : target;
|
7626 |
+
}
|
7627 |
+
|
7628 |
+
// Bidirectional ordering algorithm
|
7629 |
+
// See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
|
7630 |
+
// that this (partially) implements.
|
7631 |
+
|
7632 |
+
// One-char codes used for character types:
|
7633 |
+
// L (L): Left-to-Right
|
7634 |
+
// R (R): Right-to-Left
|
7635 |
+
// r (AL): Right-to-Left Arabic
|
7636 |
+
// 1 (EN): European Number
|
7637 |
+
// + (ES): European Number Separator
|
7638 |
+
// % (ET): European Number Terminator
|
7639 |
+
// n (AN): Arabic Number
|
7640 |
+
// , (CS): Common Number Separator
|
7641 |
+
// m (NSM): Non-Spacing Mark
|
7642 |
+
// b (BN): Boundary Neutral
|
7643 |
+
// s (B): Paragraph Separator
|
7644 |
+
// t (S): Segment Separator
|
7645 |
+
// w (WS): Whitespace
|
7646 |
+
// N (ON): Other Neutrals
|
7647 |
+
|
7648 |
+
// Returns null if characters are ordered as they appear
|
7649 |
+
// (left-to-right), or an array of sections ({from, to, level}
|
7650 |
+
// objects) in the order in which they occur visually.
|
7651 |
+
var bidiOrdering = (function() {
|
7652 |
+
// Character types for codepoints 0 to 0xff
|
7653 |
+
var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN";
|
7654 |
+
// Character types for codepoints 0x600 to 0x6ff
|
7655 |
+
var arabicTypes = "rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmm";
|
7656 |
+
function charType(code) {
|
7657 |
+
if (code <= 0xf7) return lowTypes.charAt(code);
|
7658 |
+
else if (0x590 <= code && code <= 0x5f4) return "R";
|
7659 |
+
else if (0x600 <= code && code <= 0x6ed) return arabicTypes.charAt(code - 0x600);
|
7660 |
+
else if (0x6ee <= code && code <= 0x8ac) return "r";
|
7661 |
+
else if (0x2000 <= code && code <= 0x200b) return "w";
|
7662 |
+
else if (code == 0x200c) return "b";
|
7663 |
+
else return "L";
|
7664 |
+
}
|
7665 |
+
|
7666 |
+
var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
|
7667 |
+
var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
|
7668 |
+
// Browsers seem to always treat the boundaries of block elements as being L.
|
7669 |
+
var outerType = "L";
|
7670 |
+
|
7671 |
+
function BidiSpan(level, from, to) {
|
7672 |
+
this.level = level;
|
7673 |
+
this.from = from; this.to = to;
|
7674 |
+
}
|
7675 |
+
|
7676 |
+
return function(str) {
|
7677 |
+
if (!bidiRE.test(str)) return false;
|
7678 |
+
var len = str.length, types = [];
|
7679 |
+
for (var i = 0, type; i < len; ++i)
|
7680 |
+
types.push(type = charType(str.charCodeAt(i)));
|
7681 |
+
|
7682 |
+
// W1. Examine each non-spacing mark (NSM) in the level run, and
|
7683 |
+
// change the type of the NSM to the type of the previous
|
7684 |
+
// character. If the NSM is at the start of the level run, it will
|
7685 |
+
// get the type of sor.
|
7686 |
+
for (var i = 0, prev = outerType; i < len; ++i) {
|
7687 |
+
var type = types[i];
|
7688 |
+
if (type == "m") types[i] = prev;
|
7689 |
+
else prev = type;
|
7690 |
+
}
|
7691 |
+
|
7692 |
+
// W2. Search backwards from each instance of a European number
|
7693 |
+
// until the first strong type (R, L, AL, or sor) is found. If an
|
7694 |
+
// AL is found, change the type of the European number to Arabic
|
7695 |
+
// number.
|
7696 |
+
// W3. Change all ALs to R.
|
7697 |
+
for (var i = 0, cur = outerType; i < len; ++i) {
|
7698 |
+
var type = types[i];
|
7699 |
+
if (type == "1" && cur == "r") types[i] = "n";
|
7700 |
+
else if (isStrong.test(type)) { cur = type; if (type == "r") types[i] = "R"; }
|
7701 |
+
}
|
7702 |
+
|
7703 |
+
// W4. A single European separator between two European numbers
|
7704 |
+
// changes to a European number. A single common separator between
|
7705 |
+
// two numbers of the same type changes to that type.
|
7706 |
+
for (var i = 1, prev = types[0]; i < len - 1; ++i) {
|
7707 |
+
var type = types[i];
|
7708 |
+
if (type == "+" && prev == "1" && types[i+1] == "1") types[i] = "1";
|
7709 |
+
else if (type == "," && prev == types[i+1] &&
|
7710 |
+
(prev == "1" || prev == "n")) types[i] = prev;
|
7711 |
+
prev = type;
|
7712 |
+
}
|
7713 |
+
|
7714 |
+
// W5. A sequence of European terminators adjacent to European
|
7715 |
+
// numbers changes to all European numbers.
|
7716 |
+
// W6. Otherwise, separators and terminators change to Other
|
7717 |
+
// Neutral.
|
7718 |
+
for (var i = 0; i < len; ++i) {
|
7719 |
+
var type = types[i];
|
7720 |
+
if (type == ",") types[i] = "N";
|
7721 |
+
else if (type == "%") {
|
7722 |
+
for (var end = i + 1; end < len && types[end] == "%"; ++end) {}
|
7723 |
+
var replace = (i && types[i-1] == "!") || (end < len && types[end] == "1") ? "1" : "N";
|
7724 |
+
for (var j = i; j < end; ++j) types[j] = replace;
|
7725 |
+
i = end - 1;
|
7726 |
+
}
|
7727 |
+
}
|
7728 |
+
|
7729 |
+
// W7. Search backwards from each instance of a European number
|
7730 |
+
// until the first strong type (R, L, or sor) is found. If an L is
|
7731 |
+
// found, then change the type of the European number to L.
|
7732 |
+
for (var i = 0, cur = outerType; i < len; ++i) {
|
7733 |
+
var type = types[i];
|
7734 |
+
if (cur == "L" && type == "1") types[i] = "L";
|
7735 |
+
else if (isStrong.test(type)) cur = type;
|
7736 |
+
}
|
7737 |
+
|
7738 |
+
// N1. A sequence of neutrals takes the direction of the
|
7739 |
+
// surrounding strong text if the text on both sides has the same
|
7740 |
+
// direction. European and Arabic numbers act as if they were R in
|
7741 |
+
// terms of their influence on neutrals. Start-of-level-run (sor)
|
7742 |
+
// and end-of-level-run (eor) are used at level run boundaries.
|
7743 |
+
// N2. Any remaining neutrals take the embedding direction.
|
7744 |
+
for (var i = 0; i < len; ++i) {
|
7745 |
+
if (isNeutral.test(types[i])) {
|
7746 |
+
for (var end = i + 1; end < len && isNeutral.test(types[end]); ++end) {}
|
7747 |
+
var before = (i ? types[i-1] : outerType) == "L";
|
7748 |
+
var after = (end < len ? types[end] : outerType) == "L";
|
7749 |
+
var replace = before || after ? "L" : "R";
|
7750 |
+
for (var j = i; j < end; ++j) types[j] = replace;
|
7751 |
+
i = end - 1;
|
7752 |
+
}
|
7753 |
+
}
|
7754 |
+
|
7755 |
+
// Here we depart from the documented algorithm, in order to avoid
|
7756 |
+
// building up an actual levels array. Since there are only three
|
7757 |
+
// levels (0, 1, 2) in an implementation that doesn't take
|
7758 |
+
// explicit embedding into account, we can build up the order on
|
7759 |
+
// the fly, without following the level-based algorithm.
|
7760 |
+
var order = [], m;
|
7761 |
+
for (var i = 0; i < len;) {
|
7762 |
+
if (countsAsLeft.test(types[i])) {
|
7763 |
+
var start = i;
|
7764 |
+
for (++i; i < len && countsAsLeft.test(types[i]); ++i) {}
|
7765 |
+
order.push(new BidiSpan(0, start, i));
|
7766 |
+
} else {
|
7767 |
+
var pos = i, at = order.length;
|
7768 |
+
for (++i; i < len && types[i] != "L"; ++i) {}
|
7769 |
+
for (var j = pos; j < i;) {
|
7770 |
+
if (countsAsNum.test(types[j])) {
|
7771 |
+
if (pos < j) order.splice(at, 0, new BidiSpan(1, pos, j));
|
7772 |
+
var nstart = j;
|
7773 |
+
for (++j; j < i && countsAsNum.test(types[j]); ++j) {}
|
7774 |
+
order.splice(at, 0, new BidiSpan(2, nstart, j));
|
7775 |
+
pos = j;
|
7776 |
+
} else ++j;
|
7777 |
+
}
|
7778 |
+
if (pos < i) order.splice(at, 0, new BidiSpan(1, pos, i));
|
7779 |
+
}
|
7780 |
+
}
|
7781 |
+
if (order[0].level == 1 && (m = str.match(/^\s+/))) {
|
7782 |
+
order[0].from = m[0].length;
|
7783 |
+
order.unshift(new BidiSpan(0, 0, m[0].length));
|
7784 |
+
}
|
7785 |
+
if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
|
7786 |
+
lst(order).to -= m[0].length;
|
7787 |
+
order.push(new BidiSpan(0, len - m[0].length, len));
|
7788 |
+
}
|
7789 |
+
if (order[0].level != lst(order).level)
|
7790 |
+
order.push(new BidiSpan(order[0].level, len, len));
|
7791 |
+
|
7792 |
+
return order;
|
7793 |
+
};
|
7794 |
+
})();
|
7795 |
+
|
7796 |
+
// THE END
|
7797 |
+
|
7798 |
+
CodeMirror.version = "4.4.0";
|
7799 |
+
|
7800 |
+
return CodeMirror;
|
7801 |
+
});
|
admin/codemirror/mode/clike/clike.js
ADDED
@@ -0,0 +1,440 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function(mod) {
|
5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6 |
+
mod(require("../../lib/codemirror"));
|
7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
8 |
+
define(["../../lib/codemirror"], mod);
|
9 |
+
else // Plain browser env
|
10 |
+
mod(CodeMirror);
|
11 |
+
})(function(CodeMirror) {
|
12 |
+
"use strict";
|
13 |
+
|
14 |
+
CodeMirror.defineMode("clike", function(config, parserConfig) {
|
15 |
+
var indentUnit = config.indentUnit,
|
16 |
+
statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
|
17 |
+
dontAlignCalls = parserConfig.dontAlignCalls,
|
18 |
+
keywords = parserConfig.keywords || {},
|
19 |
+
builtin = parserConfig.builtin || {},
|
20 |
+
blockKeywords = parserConfig.blockKeywords || {},
|
21 |
+
atoms = parserConfig.atoms || {},
|
22 |
+
hooks = parserConfig.hooks || {},
|
23 |
+
multiLineStrings = parserConfig.multiLineStrings;
|
24 |
+
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
|
25 |
+
|
26 |
+
var curPunc;
|
27 |
+
|
28 |
+
function tokenBase(stream, state) {
|
29 |
+
var ch = stream.next();
|
30 |
+
if (hooks[ch]) {
|
31 |
+
var result = hooks[ch](stream, state);
|
32 |
+
if (result !== false) return result;
|
33 |
+
}
|
34 |
+
if (ch == '"' || ch == "'") {
|
35 |
+
state.tokenize = tokenString(ch);
|
36 |
+
return state.tokenize(stream, state);
|
37 |
+
}
|
38 |
+
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
39 |
+
curPunc = ch;
|
40 |
+
return null;
|
41 |
+
}
|
42 |
+
if (/\d/.test(ch)) {
|
43 |
+
stream.eatWhile(/[\w\.]/);
|
44 |
+
return "number";
|
45 |
+
}
|
46 |
+
if (ch == "/") {
|
47 |
+
if (stream.eat("*")) {
|
48 |
+
state.tokenize = tokenComment;
|
49 |
+
return tokenComment(stream, state);
|
50 |
+
}
|
51 |
+
if (stream.eat("/")) {
|
52 |
+
stream.skipToEnd();
|
53 |
+
return "comment";
|
54 |
+
}
|
55 |
+
}
|
56 |
+
if (isOperatorChar.test(ch)) {
|
57 |
+
stream.eatWhile(isOperatorChar);
|
58 |
+
return "operator";
|
59 |
+
}
|
60 |
+
stream.eatWhile(/[\w\$_]/);
|
61 |
+
var cur = stream.current();
|
62 |
+
if (keywords.propertyIsEnumerable(cur)) {
|
63 |
+
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
64 |
+
return "keyword";
|
65 |
+
}
|
66 |
+
if (builtin.propertyIsEnumerable(cur)) {
|
67 |
+
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
68 |
+
return "builtin";
|
69 |
+
}
|
70 |
+
if (atoms.propertyIsEnumerable(cur)) return "atom";
|
71 |
+
return "variable";
|
72 |
+
}
|
73 |
+
|
74 |
+
function tokenString(quote) {
|
75 |
+
return function(stream, state) {
|
76 |
+
var escaped = false, next, end = false;
|
77 |
+
while ((next = stream.next()) != null) {
|
78 |
+
if (next == quote && !escaped) {end = true; break;}
|
79 |
+
escaped = !escaped && next == "\\";
|
80 |
+
}
|
81 |
+
if (end || !(escaped || multiLineStrings))
|
82 |
+
state.tokenize = null;
|
83 |
+
return "string";
|
84 |
+
};
|
85 |
+
}
|
86 |
+
|
87 |
+
function tokenComment(stream, state) {
|
88 |
+
var maybeEnd = false, ch;
|
89 |
+
while (ch = stream.next()) {
|
90 |
+
if (ch == "/" && maybeEnd) {
|
91 |
+
state.tokenize = null;
|
92 |
+
break;
|
93 |
+
}
|
94 |
+
maybeEnd = (ch == "*");
|
95 |
+
}
|
96 |
+
return "comment";
|
97 |
+
}
|
98 |
+
|
99 |
+
function Context(indented, column, type, align, prev) {
|
100 |
+
this.indented = indented;
|
101 |
+
this.column = column;
|
102 |
+
this.type = type;
|
103 |
+
this.align = align;
|
104 |
+
this.prev = prev;
|
105 |
+
}
|
106 |
+
function pushContext(state, col, type) {
|
107 |
+
var indent = state.indented;
|
108 |
+
if (state.context && state.context.type == "statement")
|
109 |
+
indent = state.context.indented;
|
110 |
+
return state.context = new Context(indent, col, type, null, state.context);
|
111 |
+
}
|
112 |
+
function popContext(state) {
|
113 |
+
var t = state.context.type;
|
114 |
+
if (t == ")" || t == "]" || t == "}")
|
115 |
+
state.indented = state.context.indented;
|
116 |
+
return state.context = state.context.prev;
|
117 |
+
}
|
118 |
+
|
119 |
+
// Interface
|
120 |
+
|
121 |
+
return {
|
122 |
+
startState: function(basecolumn) {
|
123 |
+
return {
|
124 |
+
tokenize: null,
|
125 |
+
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
|
126 |
+
indented: 0,
|
127 |
+
startOfLine: true
|
128 |
+
};
|
129 |
+
},
|
130 |
+
|
131 |
+
token: function(stream, state) {
|
132 |
+
var ctx = state.context;
|
133 |
+
if (stream.sol()) {
|
134 |
+
if (ctx.align == null) ctx.align = false;
|
135 |
+
state.indented = stream.indentation();
|
136 |
+
state.startOfLine = true;
|
137 |
+
}
|
138 |
+
if (stream.eatSpace()) return null;
|
139 |
+
curPunc = null;
|
140 |
+
var style = (state.tokenize || tokenBase)(stream, state);
|
141 |
+
if (style == "comment" || style == "meta") return style;
|
142 |
+
if (ctx.align == null) ctx.align = true;
|
143 |
+
|
144 |
+
if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state);
|
145 |
+
else if (curPunc == "{") pushContext(state, stream.column(), "}");
|
146 |
+
else if (curPunc == "[") pushContext(state, stream.column(), "]");
|
147 |
+
else if (curPunc == "(") pushContext(state, stream.column(), ")");
|
148 |
+
else if (curPunc == "}") {
|
149 |
+
while (ctx.type == "statement") ctx = popContext(state);
|
150 |
+
if (ctx.type == "}") ctx = popContext(state);
|
151 |
+
while (ctx.type == "statement") ctx = popContext(state);
|
152 |
+
}
|
153 |
+
else if (curPunc == ctx.type) popContext(state);
|
154 |
+
else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement"))
|
155 |
+
pushContext(state, stream.column(), "statement");
|
156 |
+
state.startOfLine = false;
|
157 |
+
return style;
|
158 |
+
},
|
159 |
+
|
160 |
+
indent: function(state, textAfter) {
|
161 |
+
if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
|
162 |
+
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
|
163 |
+
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
|
164 |
+
var closing = firstChar == ctx.type;
|
165 |
+
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
|
166 |
+
else if (ctx.align && (!dontAlignCalls || ctx.type != ")")) return ctx.column + (closing ? 0 : 1);
|
167 |
+
else if (ctx.type == ")" && !closing) return ctx.indented + statementIndentUnit;
|
168 |
+
else return ctx.indented + (closing ? 0 : indentUnit);
|
169 |
+
},
|
170 |
+
|
171 |
+
electricChars: "{}",
|
172 |
+
blockCommentStart: "/*",
|
173 |
+
blockCommentEnd: "*/",
|
174 |
+
lineComment: "//",
|
175 |
+
fold: "brace"
|
176 |
+
};
|
177 |
+
});
|
178 |
+
|
179 |
+
function words(str) {
|
180 |
+
var obj = {}, words = str.split(" ");
|
181 |
+
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
182 |
+
return obj;
|
183 |
+
}
|
184 |
+
var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
|
185 |
+
"double static else struct entry switch extern typedef float union for unsigned " +
|
186 |
+
"goto while enum void const signed volatile";
|
187 |
+
|
188 |
+
function cppHook(stream, state) {
|
189 |
+
if (!state.startOfLine) return false;
|
190 |
+
for (;;) {
|
191 |
+
if (stream.skipTo("\\")) {
|
192 |
+
stream.next();
|
193 |
+
if (stream.eol()) {
|
194 |
+
state.tokenize = cppHook;
|
195 |
+
break;
|
196 |
+
}
|
197 |
+
} else {
|
198 |
+
stream.skipToEnd();
|
199 |
+
state.tokenize = null;
|
200 |
+
break;
|
201 |
+
}
|
202 |
+
}
|
203 |
+
return "meta";
|
204 |
+
}
|
205 |
+
|
206 |
+
function cpp11StringHook(stream, state) {
|
207 |
+
stream.backUp(1);
|
208 |
+
// Raw strings.
|
209 |
+
if (stream.match(/(R|u8R|uR|UR|LR)/)) {
|
210 |
+
var match = stream.match(/"([^\s\\()]{0,16})\(/);
|
211 |
+
if (!match) {
|
212 |
+
return false;
|
213 |
+
}
|
214 |
+
state.cpp11RawStringDelim = match[1];
|
215 |
+
state.tokenize = tokenRawString;
|
216 |
+
return tokenRawString(stream, state);
|
217 |
+
}
|
218 |
+
// Unicode strings/chars.
|
219 |
+
if (stream.match(/(u8|u|U|L)/)) {
|
220 |
+
if (stream.match(/["']/, /* eat */ false)) {
|
221 |
+
return "string";
|
222 |
+
}
|
223 |
+
return false;
|
224 |
+
}
|
225 |
+
// Ignore this hook.
|
226 |
+
stream.next();
|
227 |
+
return false;
|
228 |
+
}
|
229 |
+
|
230 |
+
// C#-style strings where "" escapes a quote.
|
231 |
+
function tokenAtString(stream, state) {
|
232 |
+
var next;
|
233 |
+
while ((next = stream.next()) != null) {
|
234 |
+
if (next == '"' && !stream.eat('"')) {
|
235 |
+
state.tokenize = null;
|
236 |
+
break;
|
237 |
+
}
|
238 |
+
}
|
239 |
+
return "string";
|
240 |
+
}
|
241 |
+
|
242 |
+
// C++11 raw string literal is <prefix>"<delim>( anything )<delim>", where
|
243 |
+
// <delim> can be a string up to 16 characters long.
|
244 |
+
function tokenRawString(stream, state) {
|
245 |
+
// Escape characters that have special regex meanings.
|
246 |
+
var delim = state.cpp11RawStringDelim.replace(/[^\w\s]/g, '\\$&');
|
247 |
+
var match = stream.match(new RegExp(".*?\\)" + delim + '"'));
|
248 |
+
if (match)
|
249 |
+
state.tokenize = null;
|
250 |
+
else
|
251 |
+
stream.skipToEnd();
|
252 |
+
return "string";
|
253 |
+
}
|
254 |
+
|
255 |
+
function def(mimes, mode) {
|
256 |
+
if (typeof mimes == "string") mimes = [mimes];
|
257 |
+
var words = [];
|
258 |
+
function add(obj) {
|
259 |
+
if (obj) for (var prop in obj) if (obj.hasOwnProperty(prop))
|
260 |
+
words.push(prop);
|
261 |
+
}
|
262 |
+
add(mode.keywords);
|
263 |
+
add(mode.builtin);
|
264 |
+
add(mode.atoms);
|
265 |
+
if (words.length) {
|
266 |
+
mode.helperType = mimes[0];
|
267 |
+
CodeMirror.registerHelper("hintWords", mimes[0], words);
|
268 |
+
}
|
269 |
+
|
270 |
+
for (var i = 0; i < mimes.length; ++i)
|
271 |
+
CodeMirror.defineMIME(mimes[i], mode);
|
272 |
+
}
|
273 |
+
|
274 |
+
def(["text/x-csrc", "text/x-c", "text/x-chdr"], {
|
275 |
+
name: "clike",
|
276 |
+
keywords: words(cKeywords),
|
277 |
+
blockKeywords: words("case do else for if switch while struct"),
|
278 |
+
atoms: words("null"),
|
279 |
+
hooks: {"#": cppHook},
|
280 |
+
modeProps: {fold: ["brace", "include"]}
|
281 |
+
});
|
282 |
+
|
283 |
+
def(["text/x-c++src", "text/x-c++hdr"], {
|
284 |
+
name: "clike",
|
285 |
+
keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
|
286 |
+
"static_cast typeid catch operator template typename class friend private " +
|
287 |
+
"this using const_cast inline public throw virtual delete mutable protected " +
|
288 |
+
"wchar_t alignas alignof constexpr decltype nullptr noexcept thread_local final " +
|
289 |
+
"static_assert override"),
|
290 |
+
blockKeywords: words("catch class do else finally for if struct switch try while"),
|
291 |
+
atoms: words("true false null"),
|
292 |
+
hooks: {
|
293 |
+
"#": cppHook,
|
294 |
+
"u": cpp11StringHook,
|
295 |
+
"U": cpp11StringHook,
|
296 |
+
"L": cpp11StringHook,
|
297 |
+
"R": cpp11StringHook
|
298 |
+
},
|
299 |
+
modeProps: {fold: ["brace", "include"]}
|
300 |
+
});
|
301 |
+
def("text/x-java", {
|
302 |
+
name: "clike",
|
303 |
+
keywords: words("abstract assert boolean break byte case catch char class const continue default " +
|
304 |
+
"do double else enum extends final finally float for goto if implements import " +
|
305 |
+
"instanceof int interface long native new package private protected public " +
|
306 |
+
"return short static strictfp super switch synchronized this throw throws transient " +
|
307 |
+
"try void volatile while"),
|
308 |
+
blockKeywords: words("catch class do else finally for if switch try while"),
|
309 |
+
atoms: words("true false null"),
|
310 |
+
hooks: {
|
311 |
+
"@": function(stream) {
|
312 |
+
stream.eatWhile(/[\w\$_]/);
|
313 |
+
return "meta";
|
314 |
+
}
|
315 |
+
},
|
316 |
+
modeProps: {fold: ["brace", "import"]}
|
317 |
+
});
|
318 |
+
def("text/x-csharp", {
|
319 |
+
name: "clike",
|
320 |
+
keywords: words("abstract as base break case catch checked class const continue" +
|
321 |
+
" default delegate do else enum event explicit extern finally fixed for" +
|
322 |
+
" foreach goto if implicit in interface internal is lock namespace new" +
|
323 |
+
" operator out override params private protected public readonly ref return sealed" +
|
324 |
+
" sizeof stackalloc static struct switch this throw try typeof unchecked" +
|
325 |
+
" unsafe using virtual void volatile while add alias ascending descending dynamic from get" +
|
326 |
+
" global group into join let orderby partial remove select set value var yield"),
|
327 |
+
blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
|
328 |
+
builtin: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" +
|
329 |
+
" Guid Int16 Int32 Int64 Object SByte Single String TimeSpan UInt16 UInt32" +
|
330 |
+
" UInt64 bool byte char decimal double short int long object" +
|
331 |
+
" sbyte float string ushort uint ulong"),
|
332 |
+
atoms: words("true false null"),
|
333 |
+
hooks: {
|
334 |
+
"@": function(stream, state) {
|
335 |
+
if (stream.eat('"')) {
|
336 |
+
state.tokenize = tokenAtString;
|
337 |
+
return tokenAtString(stream, state);
|
338 |
+
}
|
339 |
+
stream.eatWhile(/[\w\$_]/);
|
340 |
+
return "meta";
|
341 |
+
}
|
342 |
+
}
|
343 |
+
});
|
344 |
+
def("text/x-scala", {
|
345 |
+
name: "clike",
|
346 |
+
keywords: words(
|
347 |
+
|
348 |
+
/* scala */
|
349 |
+
"abstract case catch class def do else extends false final finally for forSome if " +
|
350 |
+
"implicit import lazy match new null object override package private protected return " +
|
351 |
+
"sealed super this throw trait try trye type val var while with yield _ : = => <- <: " +
|
352 |
+
"<% >: # @ " +
|
353 |
+
|
354 |
+
/* package scala */
|
355 |
+
"assert assume require print println printf readLine readBoolean readByte readShort " +
|
356 |
+
"readChar readInt readLong readFloat readDouble " +
|
357 |
+
|
358 |
+
"AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
|
359 |
+
"Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " +
|
360 |
+
"Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
|
361 |
+
"Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
|
362 |
+
"StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector :: #:: " +
|
363 |
+
|
364 |
+
/* package java.lang */
|
365 |
+
"Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
|
366 |
+
"Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
|
367 |
+
"Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
|
368 |
+
"StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
|
369 |
+
|
370 |
+
|
371 |
+
),
|
372 |
+
multiLineStrings: true,
|
373 |
+
blockKeywords: words("catch class do else finally for forSome if match switch try while"),
|
374 |
+
atoms: words("true false null"),
|
375 |
+
hooks: {
|
376 |
+
"@": function(stream) {
|
377 |
+
stream.eatWhile(/[\w\$_]/);
|
378 |
+
return "meta";
|
379 |
+
}
|
380 |
+
}
|
381 |
+
});
|
382 |
+
def(["x-shader/x-vertex", "x-shader/x-fragment"], {
|
383 |
+
name: "clike",
|
384 |
+
keywords: words("float int bool void " +
|
385 |
+
"vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " +
|
386 |
+
"mat2 mat3 mat4 " +
|
387 |
+
"sampler1D sampler2D sampler3D samplerCube " +
|
388 |
+
"sampler1DShadow sampler2DShadow" +
|
389 |
+
"const attribute uniform varying " +
|
390 |
+
"break continue discard return " +
|
391 |
+
"for while do if else struct " +
|
392 |
+
"in out inout"),
|
393 |
+
blockKeywords: words("for while do if else struct"),
|
394 |
+
builtin: words("radians degrees sin cos tan asin acos atan " +
|
395 |
+
"pow exp log exp2 sqrt inversesqrt " +
|
396 |
+
"abs sign floor ceil fract mod min max clamp mix step smootstep " +
|
397 |
+
"length distance dot cross normalize ftransform faceforward " +
|
398 |
+
"reflect refract matrixCompMult " +
|
399 |
+
"lessThan lessThanEqual greaterThan greaterThanEqual " +
|
400 |
+
"equal notEqual any all not " +
|
401 |
+
"texture1D texture1DProj texture1DLod texture1DProjLod " +
|
402 |
+
"texture2D texture2DProj texture2DLod texture2DProjLod " +
|
403 |
+
"texture3D texture3DProj texture3DLod texture3DProjLod " +
|
404 |
+
"textureCube textureCubeLod " +
|
405 |
+
"shadow1D shadow2D shadow1DProj shadow2DProj " +
|
406 |
+
"shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " +
|
407 |
+
"dFdx dFdy fwidth " +
|
408 |
+
"noise1 noise2 noise3 noise4"),
|
409 |
+
atoms: words("true false " +
|
410 |
+
"gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " +
|
411 |
+
"gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 " +
|
412 |
+
"gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 " +
|
413 |
+
"gl_FogCoord " +
|
414 |
+
"gl_Position gl_PointSize gl_ClipVertex " +
|
415 |
+
"gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor " +
|
416 |
+
"gl_TexCoord gl_FogFragCoord " +
|
417 |
+
"gl_FragCoord gl_FrontFacing " +
|
418 |
+
"gl_FragColor gl_FragData gl_FragDepth " +
|
419 |
+
"gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix " +
|
420 |
+
"gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " +
|
421 |
+
"gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse " +
|
422 |
+
"gl_TexureMatrixTranspose gl_ModelViewMatrixInverseTranspose " +
|
423 |
+
"gl_ProjectionMatrixInverseTranspose " +
|
424 |
+
"gl_ModelViewProjectionMatrixInverseTranspose " +
|
425 |
+
"gl_TextureMatrixInverseTranspose " +
|
426 |
+
"gl_NormalScale gl_DepthRange gl_ClipPlane " +
|
427 |
+
"gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_LightModel " +
|
428 |
+
"gl_FrontLightModelProduct gl_BackLightModelProduct " +
|
429 |
+
"gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ " +
|
430 |
+
"gl_FogParameters " +
|
431 |
+
"gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords " +
|
432 |
+
"gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats " +
|
433 |
+
"gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " +
|
434 |
+
"gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits " +
|
435 |
+
"gl_MaxDrawBuffers"),
|
436 |
+
hooks: {"#": cppHook},
|
437 |
+
modeProps: {fold: ["brace", "include"]}
|
438 |
+
});
|
439 |
+
|
440 |
+
});
|
admin/codemirror/mode/clike/index.html
ADDED
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
|
3 |
+
<title>CodeMirror: C-like mode</title>
|
4 |
+
<meta charset="utf-8"/>
|
5 |
+
<link rel=stylesheet href="../../doc/docs.css">
|
6 |
+
|
7 |
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
8 |
+
<script src="../../lib/codemirror.js"></script>
|
9 |
+
<script src="../../addon/edit/matchbrackets.js"></script>
|
10 |
+
<link rel="stylesheet" href="../../addon/hint/show-hint.css">
|
11 |
+
<script src="../../addon/hint/show-hint.js"></script>
|
12 |
+
<script src="clike.js"></script>
|
13 |
+
<style>.CodeMirror {border: 2px inset #dee;}</style>
|
14 |
+
<div id=nav>
|
15 |
+
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
|
16 |
+
|
17 |
+
<ul>
|
18 |
+
<li><a href="../../index.html">Home</a>
|
19 |
+
<li><a href="../../doc/manual.html">Manual</a>
|
20 |
+
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
21 |
+
</ul>
|
22 |
+
<ul>
|
23 |
+
<li><a href="../index.html">Language modes</a>
|
24 |
+
<li><a class=active href="#">C-like</a>
|
25 |
+
</ul>
|
26 |
+
</div>
|
27 |
+
|
28 |
+
<article>
|
29 |
+
<h2>C-like mode</h2>
|
30 |
+
|
31 |
+
<div><textarea id="c-code">
|
32 |
+
/* C demo code */
|
33 |
+
|
34 |
+
#include <zmq.h>
|
35 |
+
#include <pthread.h>
|
36 |
+
#include <semaphore.h>
|
37 |
+
#include <time.h>
|
38 |
+
#include <stdio.h>
|
39 |
+
#include <fcntl.h>
|
40 |
+
#include <malloc.h>
|
41 |
+
|
42 |
+
typedef struct {
|
43 |
+
void* arg_socket;
|
44 |
+
zmq_msg_t* arg_msg;
|
45 |
+
char* arg_string;
|
46 |
+
unsigned long arg_len;
|
47 |
+
int arg_int, arg_command;
|
48 |
+
|
49 |
+
int signal_fd;
|
50 |
+
int pad;
|
51 |
+
void* context;
|
52 |
+
sem_t sem;
|
53 |
+
} acl_zmq_context;
|
54 |
+
|
55 |
+
#define p(X) (context->arg_##X)
|
56 |
+
|
57 |
+
void* zmq_thread(void* context_pointer) {
|
58 |
+
acl_zmq_context* context = (acl_zmq_context*)context_pointer;
|
59 |
+
char ok = 'K', err = 'X';
|
60 |
+
int res;
|
61 |
+
|
62 |
+
while (1) {
|
63 |
+
while ((res = sem_wait(&context->sem)) == EINTR);
|
64 |
+
if (res) {write(context->signal_fd, &err, 1); goto cleanup;}
|
65 |
+
switch(p(command)) {
|
66 |
+
case 0: goto cleanup;
|
67 |
+
case 1: p(socket) = zmq_socket(context->context, p(int)); break;
|
68 |
+
case 2: p(int) = zmq_close(p(socket)); break;
|
69 |
+
case 3: p(int) = zmq_bind(p(socket), p(string)); break;
|
70 |
+
case 4: p(int) = zmq_connect(p(socket), p(string)); break;
|
71 |
+
case 5: p(int) = zmq_getsockopt(p(socket), p(int), (void*)p(string), &p(len)); break;
|
72 |
+
case 6: p(int) = zmq_setsockopt(p(socket), p(int), (void*)p(string), p(len)); break;
|
73 |
+
case 7: p(int) = zmq_send(p(socket), p(msg), p(int)); break;
|
74 |
+
case 8: p(int) = zmq_recv(p(socket), p(msg), p(int)); break;
|
75 |
+
case 9: p(int) = zmq_poll(p(socket), p(int), p(len)); break;
|
76 |
+
}
|
77 |
+
p(command) = errno;
|
78 |
+
write(context->signal_fd, &ok, 1);
|
79 |
+
}
|
80 |
+
cleanup:
|
81 |
+
close(context->signal_fd);
|
82 |
+
free(context_pointer);
|
83 |
+
return 0;
|
84 |
+
}
|
85 |
+
|
86 |
+
void* zmq_thread_init(void* zmq_context, int signal_fd) {
|
87 |
+
acl_zmq_context* context = malloc(sizeof(acl_zmq_context));
|
88 |
+
pthread_t thread;
|
89 |
+
|
90 |
+
context->context = zmq_context;
|
91 |
+
context->signal_fd = signal_fd;
|
92 |
+
sem_init(&context->sem, 1, 0);
|
93 |
+
pthread_create(&thread, 0, &zmq_thread, context);
|
94 |
+
pthread_detach(thread);
|
95 |
+
return context;
|
96 |
+
}
|
97 |
+
</textarea></div>
|
98 |
+
|
99 |
+
<h2>C++ example</h2>
|
100 |
+
|
101 |
+
<div><textarea id="cpp-code">
|
102 |
+
#include <iostream>
|
103 |
+
#include "mystuff/util.h"
|
104 |
+
|
105 |
+
namespace {
|
106 |
+
enum Enum {
|
107 |
+
VAL1, VAL2, VAL3
|
108 |
+
};
|
109 |
+
|
110 |
+
char32_t unicode_string = U"\U0010FFFF";
|
111 |
+
string raw_string = R"delim(anything
|
112 |
+
you
|
113 |
+
want)delim";
|
114 |
+
|
115 |
+
int Helper(const MyType& param) {
|
116 |
+
return 0;
|
117 |
+
}
|
118 |
+
} // namespace
|
119 |
+
|
120 |
+
class ForwardDec;
|
121 |
+
|
122 |
+
template <class T, class V>
|
123 |
+
class Class : public BaseClass {
|
124 |
+
const MyType<T, V> member_;
|
125 |
+
|
126 |
+
public:
|
127 |
+
const MyType<T, V>& Method() const {
|
128 |
+
return member_;
|
129 |
+
}
|
130 |
+
|
131 |
+
void Method2(MyType<T, V>* value);
|
132 |
+
}
|
133 |
+
|
134 |
+
template <class T, class V>
|
135 |
+
void Class::Method2(MyType<T, V>* value) {
|
136 |
+
std::out << 1 >> method();
|
137 |
+
value->Method3(member_);
|
138 |
+
member_ = value;
|
139 |
+
}
|
140 |
+
</textarea></div>
|
141 |
+
|
142 |
+
<h2>Java example</h2>
|
143 |
+
|
144 |
+
<div><textarea id="java-code">
|
145 |
+
import com.demo.util.MyType;
|
146 |
+
import com.demo.util.MyInterface;
|
147 |
+
|
148 |
+
public enum Enum {
|
149 |
+
VAL1, VAL2, VAL3
|
150 |
+
}
|
151 |
+
|
152 |
+
public class Class<T, V> implements MyInterface {
|
153 |
+
public static final MyType<T, V> member;
|
154 |
+
|
155 |
+
private class InnerClass {
|
156 |
+
public int zero() {
|
157 |
+
return 0;
|
158 |
+
}
|
159 |
+
}
|
160 |
+
|
161 |
+
@Override
|
162 |
+
public MyType method() {
|
163 |
+
return member;
|
164 |
+
}
|
165 |
+
|
166 |
+
public void method2(MyType<T, V> value) {
|
167 |
+
method();
|
168 |
+
value.method3();
|
169 |
+
member = value;
|
170 |
+
}
|
171 |
+
}
|
172 |
+
</textarea></div>
|
173 |
+
|
174 |
+
<script>
|
175 |
+
var cEditor = CodeMirror.fromTextArea(document.getElementById("c-code"), {
|
176 |
+
lineNumbers: true,
|
177 |
+
matchBrackets: true,
|
178 |
+
mode: "text/x-csrc"
|
179 |
+
});
|
180 |
+
var cppEditor = CodeMirror.fromTextArea(document.getElementById("cpp-code"), {
|
181 |
+
lineNumbers: true,
|
182 |
+
matchBrackets: true,
|
183 |
+
mode: "text/x-c++src"
|
184 |
+
});
|
185 |
+
var javaEditor = CodeMirror.fromTextArea(document.getElementById("java-code"), {
|
186 |
+
lineNumbers: true,
|
187 |
+
matchBrackets: true,
|
188 |
+
mode: "text/x-java"
|
189 |
+
});
|
190 |
+
var mac = CodeMirror.keyMap.default == CodeMirror.keyMap.macDefault;
|
191 |
+
CodeMirror.keyMap.default[(mac ? "Cmd" : "Ctrl") + "-Space"] = "autocomplete";
|
192 |
+
</script>
|
193 |
+
|
194 |
+
<p>Simple mode that tries to handle C-like languages as well as it
|
195 |
+
can. Takes two configuration parameters: <code>keywords</code>, an
|
196 |
+
object whose property names are the keywords in the language,
|
197 |
+
and <code>useCPP</code>, which determines whether C preprocessor
|
198 |
+
directives are recognized.</p>
|
199 |
+
|
200 |
+
<p><strong>MIME types defined:</strong> <code>text/x-csrc</code>
|
201 |
+
(C code), <code>text/x-c++src</code> (C++
|
202 |
+
code), <code>text/x-java</code> (Java
|
203 |
+
code), <code>text/x-csharp</code> (C#).</p>
|
204 |
+
</article>
|
admin/codemirror/mode/clike/scala.html
ADDED
@@ -0,0 +1,767 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
|
3 |
+
<title>CodeMirror: Scala mode</title>
|
4 |
+
<meta charset="utf-8"/>
|
5 |
+
<link rel=stylesheet href="../../doc/docs.css">
|
6 |
+
|
7 |
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
8 |
+
<link rel="stylesheet" href="../../theme/ambiance.css">
|
9 |
+
<script src="../../lib/codemirror.js"></script>
|
10 |
+
<script src="../../addon/edit/matchbrackets.js"></script>
|
11 |
+
<script src="clike.js"></script>
|
12 |
+
<div id=nav>
|
13 |
+
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
|
14 |
+
|
15 |
+
<ul>
|
16 |
+
<li><a href="../../index.html">Home</a>
|
17 |
+
<li><a href="../../doc/manual.html">Manual</a>
|
18 |
+
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
19 |
+
</ul>
|
20 |
+
<ul>
|
21 |
+
<li><a href="../index.html">Language modes</a>
|
22 |
+
<li><a class=active href="#">Scala</a>
|
23 |
+
</ul>
|
24 |
+
</div>
|
25 |
+
|
26 |
+
<article>
|
27 |
+
<h2>Scala mode</h2>
|
28 |
+
<form>
|
29 |
+
<textarea id="code" name="code">
|
30 |
+
|
31 |
+
/* __ *\
|
32 |
+
** ________ ___ / / ___ Scala API **
|
33 |
+
** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL **
|
34 |
+
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
|
35 |
+
** /____/\___/_/ |_/____/_/ | | **
|
36 |
+
** |/ **
|
37 |
+
\* */
|
38 |
+
|
39 |
+
package scala.collection
|
40 |
+
|
41 |
+
import generic._
|
42 |
+
import mutable.{ Builder, ListBuffer }
|
43 |
+
import annotation.{tailrec, migration, bridge}
|
44 |
+
import annotation.unchecked.{ uncheckedVariance => uV }
|
45 |
+
import parallel.ParIterable
|
46 |
+
|
47 |
+
/** A template trait for traversable collections of type `Traversable[A]`.
|
48 |
+
*
|
49 |
+
* $traversableInfo
|
50 |
+
* @define mutability
|
51 |
+
* @define traversableInfo
|
52 |
+
* This is a base trait of all kinds of $mutability Scala collections. It
|
53 |
+
* implements the behavior common to all collections, in terms of a method
|
54 |
+
* `foreach` with signature:
|
55 |
+
* {{{
|
56 |
+
* def foreach[U](f: Elem => U): Unit
|
57 |
+
* }}}
|
58 |
+
* Collection classes mixing in this trait provide a concrete
|
59 |
+
* `foreach` method which traverses all the
|
60 |
+
* elements contained in the collection, applying a given function to each.
|
61 |
+
* They also need to provide a method `newBuilder`
|
62 |
+
* which creates a builder for collections of the same kind.
|
63 |
+
*
|
64 |
+
* A traversable class might or might not have two properties: strictness
|
65 |
+
* and orderedness. Neither is represented as a type.
|
66 |
+
*
|
67 |
+
* The instances of a strict collection class have all their elements
|
68 |
+
* computed before they can be used as values. By contrast, instances of
|
69 |
+
* a non-strict collection class may defer computation of some of their
|
70 |
+
* elements until after the instance is available as a value.
|
71 |
+
* A typical example of a non-strict collection class is a
|
72 |
+
* <a href="../immutable/Stream.html" target="ContentFrame">
|
73 |
+
* `scala.collection.immutable.Stream`</a>.
|
74 |
+
* A more general class of examples are `TraversableViews`.
|
75 |
+
*
|
76 |
+
* If a collection is an instance of an ordered collection class, traversing
|
77 |
+
* its elements with `foreach` will always visit elements in the
|
78 |
+
* same order, even for different runs of the program. If the class is not
|
79 |
+
* ordered, `foreach` can visit elements in different orders for
|
80 |
+
* different runs (but it will keep the same order in the same run).'
|
81 |
+
*
|
82 |
+
* A typical example of a collection class which is not ordered is a
|
83 |
+
* `HashMap` of objects. The traversal order for hash maps will
|
84 |
+
* depend on the hash codes of its elements, and these hash codes might
|
85 |
+
* differ from one run to the next. By contrast, a `LinkedHashMap`
|
86 |
+
* is ordered because it's `foreach` method visits elements in the
|
87 |
+
* order they were inserted into the `HashMap`.
|
88 |
+
*
|
89 |
+
* @author Martin Odersky
|
90 |
+
* @version 2.8
|
91 |
+
* @since 2.8
|
92 |
+
* @tparam A the element type of the collection
|
93 |
+
* @tparam Repr the type of the actual collection containing the elements.
|
94 |
+
*
|
95 |
+
* @define Coll Traversable
|
96 |
+
* @define coll traversable collection
|
97 |
+
*/
|
98 |
+
trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr]
|
99 |
+
with FilterMonadic[A, Repr]
|
100 |
+
with TraversableOnce[A]
|
101 |
+
with GenTraversableLike[A, Repr]
|
102 |
+
with Parallelizable[A, ParIterable[A]]
|
103 |
+
{
|
104 |
+
self =>
|
105 |
+
|
106 |
+
import Traversable.breaks._
|
107 |
+
|
108 |
+
/** The type implementing this traversable */
|
109 |
+
protected type Self = Repr
|
110 |
+
|
111 |
+
/** The collection of type $coll underlying this `TraversableLike` object.
|
112 |
+
* By default this is implemented as the `TraversableLike` object itself,
|
113 |
+
* but this can be overridden.
|
114 |
+
*/
|
115 |
+
def repr: Repr = this.asInstanceOf[Repr]
|
116 |
+
|
117 |
+
/** The underlying collection seen as an instance of `$Coll`.
|
118 |
+
* By default this is implemented as the current collection object itself,
|
119 |
+
* but this can be overridden.
|
120 |
+
*/
|
121 |
+
protected[this] def thisCollection: Traversable[A] = this.asInstanceOf[Traversable[A]]
|
122 |
+
|
123 |
+
/** A conversion from collections of type `Repr` to `$Coll` objects.
|
124 |
+
* By default this is implemented as just a cast, but this can be overridden.
|
125 |
+
*/
|
126 |
+
protected[this] def toCollection(repr: Repr): Traversable[A] = repr.asInstanceOf[Traversable[A]]
|
127 |
+
|
128 |
+
/** Creates a new builder for this collection type.
|
129 |
+
*/
|
130 |
+
protected[this] def newBuilder: Builder[A, Repr]
|
131 |
+
|
132 |
+
protected[this] def parCombiner = ParIterable.newCombiner[A]
|
133 |
+
|
134 |
+
/** Applies a function `f` to all elements of this $coll.
|
135 |
+
*
|
136 |
+
* Note: this method underlies the implementation of most other bulk operations.
|
137 |
+
* It's important to implement this method in an efficient way.
|
138 |
+
*
|
139 |
+
*
|
140 |
+
* @param f the function that is applied for its side-effect to every element.
|
141 |
+
* The result of function `f` is discarded.
|
142 |
+
*
|
143 |
+
* @tparam U the type parameter describing the result of function `f`.
|
144 |
+
* This result will always be ignored. Typically `U` is `Unit`,
|
145 |
+
* but this is not necessary.
|
146 |
+
*
|
147 |
+
* @usecase def foreach(f: A => Unit): Unit
|
148 |
+
*/
|
149 |
+
def foreach[U](f: A => U): Unit
|
150 |
+
|
151 |
+
/** Tests whether this $coll is empty.
|
152 |
+
*
|
153 |
+
* @return `true` if the $coll contain no elements, `false` otherwise.
|
154 |
+
*/
|
155 |
+
def isEmpty: Boolean = {
|
156 |
+
var result = true
|
157 |
+
breakable {
|
158 |
+
for (x <- this) {
|
159 |
+
result = false
|
160 |
+
break
|
161 |
+
}
|
162 |
+
}
|
163 |
+
result
|
164 |
+
}
|
165 |
+
|
166 |
+
/** Tests whether this $coll is known to have a finite size.
|
167 |
+
* All strict collections are known to have finite size. For a non-strict collection
|
168 |
+
* such as `Stream`, the predicate returns `true` if all elements have been computed.
|
169 |
+
* It returns `false` if the stream is not yet evaluated to the end.
|
170 |
+
*
|
171 |
+
* Note: many collection methods will not work on collections of infinite sizes.
|
172 |
+
*
|
173 |
+
* @return `true` if this collection is known to have finite size, `false` otherwise.
|
174 |
+
*/
|
175 |
+
def hasDefiniteSize = true
|
176 |
+
|
177 |
+
def ++[B >: A, That](that: GenTraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
178 |
+
val b = bf(repr)
|
179 |
+
if (that.isInstanceOf[IndexedSeqLike[_, _]]) b.sizeHint(this, that.seq.size)
|
180 |
+
b ++= thisCollection
|
181 |
+
b ++= that.seq
|
182 |
+
b.result
|
183 |
+
}
|
184 |
+
|
185 |
+
@bridge
|
186 |
+
def ++[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That =
|
187 |
+
++(that: GenTraversableOnce[B])(bf)
|
188 |
+
|
189 |
+
/** Concatenates this $coll with the elements of a traversable collection.
|
190 |
+
* It differs from ++ in that the right operand determines the type of the
|
191 |
+
* resulting collection rather than the left one.
|
192 |
+
*
|
193 |
+
* @param that the traversable to append.
|
194 |
+
* @tparam B the element type of the returned collection.
|
195 |
+
* @tparam That $thatinfo
|
196 |
+
* @param bf $bfinfo
|
197 |
+
* @return a new collection of type `That` which contains all elements
|
198 |
+
* of this $coll followed by all elements of `that`.
|
199 |
+
*
|
200 |
+
* @usecase def ++:[B](that: TraversableOnce[B]): $Coll[B]
|
201 |
+
*
|
202 |
+
* @return a new $coll which contains all elements of this $coll
|
203 |
+
* followed by all elements of `that`.
|
204 |
+
*/
|
205 |
+
def ++:[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
206 |
+
val b = bf(repr)
|
207 |
+
if (that.isInstanceOf[IndexedSeqLike[_, _]]) b.sizeHint(this, that.size)
|
208 |
+
b ++= that
|
209 |
+
b ++= thisCollection
|
210 |
+
b.result
|
211 |
+
}
|
212 |
+
|
213 |
+
/** This overload exists because: for the implementation of ++: we should reuse
|
214 |
+
* that of ++ because many collections override it with more efficient versions.
|
215 |
+
* Since TraversableOnce has no '++' method, we have to implement that directly,
|
216 |
+
* but Traversable and down can use the overload.
|
217 |
+
*/
|
218 |
+
def ++:[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[Repr, B, That]): That =
|
219 |
+
(that ++ seq)(breakOut)
|
220 |
+
|
221 |
+
def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
222 |
+
val b = bf(repr)
|
223 |
+
b.sizeHint(this)
|
224 |
+
for (x <- this) b += f(x)
|
225 |
+
b.result
|
226 |
+
}
|
227 |
+
|
228 |
+
def flatMap[B, That](f: A => GenTraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
229 |
+
val b = bf(repr)
|
230 |
+
for (x <- this) b ++= f(x).seq
|
231 |
+
b.result
|
232 |
+
}
|
233 |
+
|
234 |
+
/** Selects all elements of this $coll which satisfy a predicate.
|
235 |
+
*
|
236 |
+
* @param p the predicate used to test elements.
|
237 |
+
* @return a new $coll consisting of all elements of this $coll that satisfy the given
|
238 |
+
* predicate `p`. The order of the elements is preserved.
|
239 |
+
*/
|
240 |
+
def filter(p: A => Boolean): Repr = {
|
241 |
+
val b = newBuilder
|
242 |
+
for (x <- this)
|
243 |
+
if (p(x)) b += x
|
244 |
+
b.result
|
245 |
+
}
|
246 |
+
|
247 |
+
/** Selects all elements of this $coll which do not satisfy a predicate.
|
248 |
+
*
|
249 |
+
* @param p the predicate used to test elements.
|
250 |
+
* @return a new $coll consisting of all elements of this $coll that do not satisfy the given
|
251 |
+
* predicate `p`. The order of the elements is preserved.
|
252 |
+
*/
|
253 |
+
def filterNot(p: A => Boolean): Repr = filter(!p(_))
|
254 |
+
|
255 |
+
def collect[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
256 |
+
val b = bf(repr)
|
257 |
+
for (x <- this) if (pf.isDefinedAt(x)) b += pf(x)
|
258 |
+
b.result
|
259 |
+
}
|
260 |
+
|
261 |
+
/** Builds a new collection by applying an option-valued function to all
|
262 |
+
* elements of this $coll on which the function is defined.
|
263 |
+
*
|
264 |
+
* @param f the option-valued function which filters and maps the $coll.
|
265 |
+
* @tparam B the element type of the returned collection.
|
266 |
+
* @tparam That $thatinfo
|
267 |
+
* @param bf $bfinfo
|
268 |
+
* @return a new collection of type `That` resulting from applying the option-valued function
|
269 |
+
* `f` to each element and collecting all defined results.
|
270 |
+
* The order of the elements is preserved.
|
271 |
+
*
|
272 |
+
* @usecase def filterMap[B](f: A => Option[B]): $Coll[B]
|
273 |
+
*
|
274 |
+
* @param pf the partial function which filters and maps the $coll.
|
275 |
+
* @return a new $coll resulting from applying the given option-valued function
|
276 |
+
* `f` to each element and collecting all defined results.
|
277 |
+
* The order of the elements is preserved.
|
278 |
+
def filterMap[B, That](f: A => Option[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
279 |
+
val b = bf(repr)
|
280 |
+
for (x <- this)
|
281 |
+
f(x) match {
|
282 |
+
case Some(y) => b += y
|
283 |
+
case _ =>
|
284 |
+
}
|
285 |
+
b.result
|
286 |
+
}
|
287 |
+
*/
|
288 |
+
|
289 |
+
/** Partitions this $coll in two ${coll}s according to a predicate.
|
290 |
+
*
|
291 |
+
* @param p the predicate on which to partition.
|
292 |
+
* @return a pair of ${coll}s: the first $coll consists of all elements that
|
293 |
+
* satisfy the predicate `p` and the second $coll consists of all elements
|
294 |
+
* that don't. The relative order of the elements in the resulting ${coll}s
|
295 |
+
* is the same as in the original $coll.
|
296 |
+
*/
|
297 |
+
def partition(p: A => Boolean): (Repr, Repr) = {
|
298 |
+
val l, r = newBuilder
|
299 |
+
for (x <- this) (if (p(x)) l else r) += x
|
300 |
+
(l.result, r.result)
|
301 |
+
}
|
302 |
+
|
303 |
+
def groupBy[K](f: A => K): immutable.Map[K, Repr] = {
|
304 |
+
val m = mutable.Map.empty[K, Builder[A, Repr]]
|
305 |
+
for (elem <- this) {
|
306 |
+
val key = f(elem)
|
307 |
+
val bldr = m.getOrElseUpdate(key, newBuilder)
|
308 |
+
bldr += elem
|
309 |
+
}
|
310 |
+
val b = immutable.Map.newBuilder[K, Repr]
|
311 |
+
for ((k, v) <- m)
|
312 |
+
b += ((k, v.result))
|
313 |
+
|
314 |
+
b.result
|
315 |
+
}
|
316 |
+
|
317 |
+
/** Tests whether a predicate holds for all elements of this $coll.
|
318 |
+
*
|
319 |
+
* $mayNotTerminateInf
|
320 |
+
*
|
321 |
+
* @param p the predicate used to test elements.
|
322 |
+
* @return `true` if the given predicate `p` holds for all elements
|
323 |
+
* of this $coll, otherwise `false`.
|
324 |
+
*/
|
325 |
+
def forall(p: A => Boolean): Boolean = {
|
326 |
+
var result = true
|
327 |
+
breakable {
|
328 |
+
for (x <- this)
|
329 |
+
if (!p(x)) { result = false; break }
|
330 |
+
}
|
331 |
+
result
|
332 |
+
}
|
333 |
+
|
334 |
+
/** Tests whether a predicate holds for some of the elements of this $coll.
|
335 |
+
*
|
336 |
+
* $mayNotTerminateInf
|
337 |
+
*
|
338 |
+
* @param p the predicate used to test elements.
|
339 |
+
* @return `true` if the given predicate `p` holds for some of the
|
340 |
+
* elements of this $coll, otherwise `false`.
|
341 |
+
*/
|
342 |
+
def exists(p: A => Boolean): Boolean = {
|
343 |
+
var result = false
|
344 |
+
breakable {
|
345 |
+
for (x <- this)
|
346 |
+
if (p(x)) { result = true; break }
|
347 |
+
}
|
348 |
+
result
|
349 |
+
}
|
350 |
+
|
351 |
+
/** Finds the first element of the $coll satisfying a predicate, if any.
|
352 |
+
*
|
353 |
+
* $mayNotTerminateInf
|
354 |
+
* $orderDependent
|
355 |
+
*
|
356 |
+
* @param p the predicate used to test elements.
|
357 |
+
* @return an option value containing the first element in the $coll
|
358 |
+
* that satisfies `p`, or `None` if none exists.
|
359 |
+
*/
|
360 |
+
def find(p: A => Boolean): Option[A] = {
|
361 |
+
var result: Option[A] = None
|
362 |
+
breakable {
|
363 |
+
for (x <- this)
|
364 |
+
if (p(x)) { result = Some(x); break }
|
365 |
+
}
|
366 |
+
result
|
367 |
+
}
|
368 |
+
|
369 |
+
def scan[B >: A, That](z: B)(op: (B, B) => B)(implicit cbf: CanBuildFrom[Repr, B, That]): That = scanLeft(z)(op)
|
370 |
+
|
371 |
+
def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
372 |
+
val b = bf(repr)
|
373 |
+
b.sizeHint(this, 1)
|
374 |
+
var acc = z
|
375 |
+
b += acc
|
376 |
+
for (x <- this) { acc = op(acc, x); b += acc }
|
377 |
+
b.result
|
378 |
+
}
|
379 |
+
|
380 |
+
@migration(2, 9,
|
381 |
+
"This scanRight definition has changed in 2.9.\n" +
|
382 |
+
"The previous behavior can be reproduced with scanRight.reverse."
|
383 |
+
)
|
384 |
+
def scanRight[B, That](z: B)(op: (A, B) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
385 |
+
var scanned = List(z)
|
386 |
+
var acc = z
|
387 |
+
for (x <- reversed) {
|
388 |
+
acc = op(x, acc)
|
389 |
+
scanned ::= acc
|
390 |
+
}
|
391 |
+
val b = bf(repr)
|
392 |
+
for (elem <- scanned) b += elem
|
393 |
+
b.result
|
394 |
+
}
|
395 |
+
|
396 |
+
/** Selects the first element of this $coll.
|
397 |
+
* $orderDependent
|
398 |
+
* @return the first element of this $coll.
|
399 |
+
* @throws `NoSuchElementException` if the $coll is empty.
|
400 |
+
*/
|
401 |
+
def head: A = {
|
402 |
+
var result: () => A = () => throw new NoSuchElementException
|
403 |
+
breakable {
|
404 |
+
for (x <- this) {
|
405 |
+
result = () => x
|
406 |
+
break
|
407 |
+
}
|
408 |
+
}
|
409 |
+
result()
|
410 |
+
}
|
411 |
+
|
412 |
+
/** Optionally selects the first element.
|
413 |
+
* $orderDependent
|
414 |
+
* @return the first element of this $coll if it is nonempty, `None` if it is empty.
|
415 |
+
*/
|
416 |
+
def headOption: Option[A] = if (isEmpty) None else Some(head)
|
417 |
+
|
418 |
+
/** Selects all elements except the first.
|
419 |
+
* $orderDependent
|
420 |
+
* @return a $coll consisting of all elements of this $coll
|
421 |
+
* except the first one.
|
422 |
+
* @throws `UnsupportedOperationException` if the $coll is empty.
|
423 |
+
*/
|
424 |
+
override def tail: Repr = {
|
425 |
+
if (isEmpty) throw new UnsupportedOperationException("empty.tail")
|
426 |
+
drop(1)
|
427 |
+
}
|
428 |
+
|
429 |
+
/** Selects the last element.
|
430 |
+
* $orderDependent
|
431 |
+
* @return The last element of this $coll.
|
432 |
+
* @throws NoSuchElementException If the $coll is empty.
|
433 |
+
*/
|
434 |
+
def last: A = {
|
435 |
+
var lst = head
|
436 |
+
for (x <- this)
|
437 |
+
lst = x
|
438 |
+
lst
|
439 |
+
}
|
440 |
+
|
441 |
+
/** Optionally selects the last element.
|
442 |
+
* $orderDependent
|
443 |
+
* @return the last element of this $coll$ if it is nonempty, `None` if it is empty.
|
444 |
+
*/
|
445 |
+
def lastOption: Option[A] = if (isEmpty) None else Some(last)
|
446 |
+
|
447 |
+
/** Selects all elements except the last.
|
448 |
+
* $orderDependent
|
449 |
+
* @return a $coll consisting of all elements of this $coll
|
450 |
+
* except the last one.
|
451 |
+
* @throws `UnsupportedOperationException` if the $coll is empty.
|
452 |
+
*/
|
453 |
+
def init: Repr = {
|
454 |
+
if (isEmpty) throw new UnsupportedOperationException("empty.init")
|
455 |
+
var lst = head
|
456 |
+
var follow = false
|
457 |
+
val b = newBuilder
|
458 |
+
b.sizeHint(this, -1)
|
459 |
+
for (x <- this.seq) {
|
460 |
+
if (follow) b += lst
|
461 |
+
else follow = true
|
462 |
+
lst = x
|
463 |
+
}
|
464 |
+
b.result
|
465 |
+
}
|
466 |
+
|
467 |
+
def take(n: Int): Repr = slice(0, n)
|
468 |
+
|
469 |
+
def drop(n: Int): Repr =
|
470 |
+
if (n <= 0) {
|
471 |
+
val b = newBuilder
|
472 |
+
b.sizeHint(this)
|
473 |
+
b ++= thisCollection result
|
474 |
+
}
|
475 |
+
else sliceWithKnownDelta(n, Int.MaxValue, -n)
|
476 |
+
|
477 |
+
def slice(from: Int, until: Int): Repr = sliceWithKnownBound(math.max(from, 0), until)
|
478 |
+
|
479 |
+
// Precondition: from >= 0, until > 0, builder already configured for building.
|
480 |
+
private[this] def sliceInternal(from: Int, until: Int, b: Builder[A, Repr]): Repr = {
|
481 |
+
var i = 0
|
482 |
+
breakable {
|
483 |
+
for (x <- this.seq) {
|
484 |
+
if (i >= from) b += x
|
485 |
+
i += 1
|
486 |
+
if (i >= until) break
|
487 |
+
}
|
488 |
+
}
|
489 |
+
b.result
|
490 |
+
}
|
491 |
+
// Precondition: from >= 0
|
492 |
+
private[scala] def sliceWithKnownDelta(from: Int, until: Int, delta: Int): Repr = {
|
493 |
+
val b = newBuilder
|
494 |
+
if (until <= from) b.result
|
495 |
+
else {
|
496 |
+
b.sizeHint(this, delta)
|
497 |
+
sliceInternal(from, until, b)
|
498 |
+
}
|
499 |
+
}
|
500 |
+
// Precondition: from >= 0
|
501 |
+
private[scala] def sliceWithKnownBound(from: Int, until: Int): Repr = {
|
502 |
+
val b = newBuilder
|
503 |
+
if (until <= from) b.result
|
504 |
+
else {
|
505 |
+
b.sizeHintBounded(until - from, this)
|
506 |
+
sliceInternal(from, until, b)
|
507 |
+
}
|
508 |
+
}
|
509 |
+
|
510 |
+
def takeWhile(p: A => Boolean): Repr = {
|
511 |
+
val b = newBuilder
|
512 |
+
breakable {
|
513 |
+
for (x <- this) {
|
514 |
+
if (!p(x)) break
|
515 |
+
b += x
|
516 |
+
}
|
517 |
+
}
|
518 |
+
b.result
|
519 |
+
}
|
520 |
+
|
521 |
+
def dropWhile(p: A => Boolean): Repr = {
|
522 |
+
val b = newBuilder
|
523 |
+
var go = false
|
524 |
+
for (x <- this) {
|
525 |
+
if (!p(x)) go = true
|
526 |
+
if (go) b += x
|
527 |
+
}
|
528 |
+
b.result
|
529 |
+
}
|
530 |
+
|
531 |
+
def span(p: A => Boolean): (Repr, Repr) = {
|
532 |
+
val l, r = newBuilder
|
533 |
+
var toLeft = true
|
534 |
+
for (x <- this) {
|
535 |
+
toLeft = toLeft && p(x)
|
536 |
+
(if (toLeft) l else r) += x
|
537 |
+
}
|
538 |
+
(l.result, r.result)
|
539 |
+
}
|
540 |
+
|
541 |
+
def splitAt(n: Int): (Repr, Repr) = {
|
542 |
+
val l, r = newBuilder
|
543 |
+
l.sizeHintBounded(n, this)
|
544 |
+
if (n >= 0) r.sizeHint(this, -n)
|
545 |
+
var i = 0
|
546 |
+
for (x <- this) {
|
547 |
+
(if (i < n) l else r) += x
|
548 |
+
i += 1
|
549 |
+
}
|
550 |
+
(l.result, r.result)
|
551 |
+
}
|
552 |
+
|
553 |
+
/** Iterates over the tails of this $coll. The first value will be this
|
554 |
+
* $coll and the final one will be an empty $coll, with the intervening
|
555 |
+
* values the results of successive applications of `tail`.
|
556 |
+
*
|
557 |
+
* @return an iterator over all the tails of this $coll
|
558 |
+
* @example `List(1,2,3).tails = Iterator(List(1,2,3), List(2,3), List(3), Nil)`
|
559 |
+
*/
|
560 |
+
def tails: Iterator[Repr] = iterateUntilEmpty(_.tail)
|
561 |
+
|
562 |
+
/** Iterates over the inits of this $coll. The first value will be this
|
563 |
+
* $coll and the final one will be an empty $coll, with the intervening
|
564 |
+
* values the results of successive applications of `init`.
|
565 |
+
*
|
566 |
+
* @return an iterator over all the inits of this $coll
|
567 |
+
* @example `List(1,2,3).inits = Iterator(List(1,2,3), List(1,2), List(1), Nil)`
|
568 |
+
*/
|
569 |
+
def inits: Iterator[Repr] = iterateUntilEmpty(_.init)
|
570 |
+
|
571 |
+
/** Copies elements of this $coll to an array.
|
572 |
+
* Fills the given array `xs` with at most `len` elements of
|
573 |
+
* this $coll, starting at position `start`.
|
574 |
+
* Copying will stop once either the end of the current $coll is reached,
|
575 |
+
* or the end of the array is reached, or `len` elements have been copied.
|
576 |
+
*
|
577 |
+
* $willNotTerminateInf
|
578 |
+
*
|
579 |
+
* @param xs the array to fill.
|
580 |
+
* @param start the starting index.
|
581 |
+
* @param len the maximal number of elements to copy.
|
582 |
+
* @tparam B the type of the elements of the array.
|
583 |
+
*
|
584 |
+
*
|
585 |
+
* @usecase def copyToArray(xs: Array[A], start: Int, len: Int): Unit
|
586 |
+
*/
|
587 |
+
def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) {
|
588 |
+
var i = start
|
589 |
+
val end = (start + len) min xs.length
|
590 |
+
breakable {
|
591 |
+
for (x <- this) {
|
592 |
+
if (i >= end) break
|
593 |
+
xs(i) = x
|
594 |
+
i += 1
|
595 |
+
}
|
596 |
+
}
|
597 |
+
}
|
598 |
+
|
599 |
+
def toTraversable: Traversable[A] = thisCollection
|
600 |
+
def toIterator: Iterator[A] = toStream.iterator
|
601 |
+
def toStream: Stream[A] = toBuffer.toStream
|
602 |
+
|
603 |
+
/** Converts this $coll to a string.
|
604 |
+
*
|
605 |
+
* @return a string representation of this collection. By default this
|
606 |
+
* string consists of the `stringPrefix` of this $coll,
|
607 |
+
* followed by all elements separated by commas and enclosed in parentheses.
|
608 |
+
*/
|
609 |
+
override def toString = mkString(stringPrefix + "(", ", ", ")")
|
610 |
+
|
611 |
+
/** Defines the prefix of this object's `toString` representation.
|
612 |
+
*
|
613 |
+
* @return a string representation which starts the result of `toString`
|
614 |
+
* applied to this $coll. By default the string prefix is the
|
615 |
+
* simple name of the collection class $coll.
|
616 |
+
*/
|
617 |
+
def stringPrefix : String = {
|
618 |
+
var string = repr.asInstanceOf[AnyRef].getClass.getName
|
619 |
+
val idx1 = string.lastIndexOf('.' : Int)
|
620 |
+
if (idx1 != -1) string = string.substring(idx1 + 1)
|
621 |
+
val idx2 = string.indexOf('$')
|
622 |
+
if (idx2 != -1) string = string.substring(0, idx2)
|
623 |
+
string
|
624 |
+
}
|
625 |
+
|
626 |
+
/** Creates a non-strict view of this $coll.
|
627 |
+
*
|
628 |
+
* @return a non-strict view of this $coll.
|
629 |
+
*/
|
630 |
+
def view = new TraversableView[A, Repr] {
|
631 |
+
protected lazy val underlying = self.repr
|
632 |
+
override def foreach[U](f: A => U) = self foreach f
|
633 |
+
}
|
634 |
+
|
635 |
+
/** Creates a non-strict view of a slice of this $coll.
|
636 |
+
*
|
637 |
+
* Note: the difference between `view` and `slice` is that `view` produces
|
638 |
+
* a view of the current $coll, whereas `slice` produces a new $coll.
|
639 |
+
*
|
640 |
+
* Note: `view(from, to)` is equivalent to `view.slice(from, to)`
|
641 |
+
* $orderDependent
|
642 |
+
*
|
643 |
+
* @param from the index of the first element of the view
|
644 |
+
* @param until the index of the element following the view
|
645 |
+
* @return a non-strict view of a slice of this $coll, starting at index `from`
|
646 |
+
* and extending up to (but not including) index `until`.
|
647 |
+
*/
|
648 |
+
def view(from: Int, until: Int): TraversableView[A, Repr] = view.slice(from, until)
|
649 |
+
|
650 |
+
/** Creates a non-strict filter of this $coll.
|
651 |
+
*
|
652 |
+
* Note: the difference between `c filter p` and `c withFilter p` is that
|
653 |
+
* the former creates a new collection, whereas the latter only
|
654 |
+
* restricts the domain of subsequent `map`, `flatMap`, `foreach`,
|
655 |
+
* and `withFilter` operations.
|
656 |
+
* $orderDependent
|
657 |
+
*
|
658 |
+
* @param p the predicate used to test elements.
|
659 |
+
* @return an object of class `WithFilter`, which supports
|
660 |
+
* `map`, `flatMap`, `foreach`, and `withFilter` operations.
|
661 |
+
* All these operations apply to those elements of this $coll which
|
662 |
+
* satisfy the predicate `p`.
|
663 |
+
*/
|
664 |
+
def withFilter(p: A => Boolean): FilterMonadic[A, Repr] = new WithFilter(p)
|
665 |
+
|
666 |
+
/** A class supporting filtered operations. Instances of this class are
|
667 |
+
* returned by method `withFilter`.
|
668 |
+
*/
|
669 |
+
class WithFilter(p: A => Boolean) extends FilterMonadic[A, Repr] {
|
670 |
+
|
671 |
+
/** Builds a new collection by applying a function to all elements of the
|
672 |
+
* outer $coll containing this `WithFilter` instance that satisfy predicate `p`.
|
673 |
+
*
|
674 |
+
* @param f the function to apply to each element.
|
675 |
+
* @tparam B the element type of the returned collection.
|
676 |
+
* @tparam That $thatinfo
|
677 |
+
* @param bf $bfinfo
|
678 |
+
* @return a new collection of type `That` resulting from applying
|
679 |
+
* the given function `f` to each element of the outer $coll
|
680 |
+
* that satisfies predicate `p` and collecting the results.
|
681 |
+
*
|
682 |
+
* @usecase def map[B](f: A => B): $Coll[B]
|
683 |
+
*
|
684 |
+
* @return a new $coll resulting from applying the given function
|
685 |
+
* `f` to each element of the outer $coll that satisfies
|
686 |
+
* predicate `p` and collecting the results.
|
687 |
+
*/
|
688 |
+
def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
689 |
+
val b = bf(repr)
|
690 |
+
for (x <- self)
|
691 |
+
if (p(x)) b += f(x)
|
692 |
+
b.result
|
693 |
+
}
|
694 |
+
|
695 |
+
/** Builds a new collection by applying a function to all elements of the
|
696 |
+
* outer $coll containing this `WithFilter` instance that satisfy
|
697 |
+
* predicate `p` and concatenating the results.
|
698 |
+
*
|
699 |
+
* @param f the function to apply to each element.
|
700 |
+
* @tparam B the element type of the returned collection.
|
701 |
+
* @tparam That $thatinfo
|
702 |
+
* @param bf $bfinfo
|
703 |
+
* @return a new collection of type `That` resulting from applying
|
704 |
+
* the given collection-valued function `f` to each element
|
705 |
+
* of the outer $coll that satisfies predicate `p` and
|
706 |
+
* concatenating the results.
|
707 |
+
*
|
708 |
+
* @usecase def flatMap[B](f: A => TraversableOnce[B]): $Coll[B]
|
709 |
+
*
|
710 |
+
* @return a new $coll resulting from applying the given collection-valued function
|
711 |
+
* `f` to each element of the outer $coll that satisfies predicate `p` and concatenating the results.
|
712 |
+
*/
|
713 |
+
def flatMap[B, That](f: A => GenTraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
|
714 |
+
val b = bf(repr)
|
715 |
+
for (x <- self)
|
716 |
+
if (p(x)) b ++= f(x).seq
|
717 |
+
b.result
|
718 |
+
}
|
719 |
+
|
720 |
+
/** Applies a function `f` to all elements of the outer $coll containing
|
721 |
+
* this `WithFilter` instance that satisfy predicate `p`.
|
722 |
+
*
|
723 |
+
* @param f the function that is applied for its side-effect to every element.
|
724 |
+
* The result of function `f` is discarded.
|
725 |
+
*
|
726 |
+
* @tparam U the type parameter describing the result of function `f`.
|
727 |
+
* This result will always be ignored. Typically `U` is `Unit`,
|
728 |
+
* but this is not necessary.
|
729 |
+
*
|
730 |
+
* @usecase def foreach(f: A => Unit): Unit
|
731 |
+
*/
|
732 |
+
def foreach[U](f: A => U): Unit =
|
733 |
+
for (x <- self)
|
734 |
+
if (p(x)) f(x)
|
735 |
+
|
736 |
+
/** Further refines the filter for this $coll.
|
737 |
+
*
|
738 |
+
* @param q the predicate used to test elements.
|
739 |
+
* @return an object of class `WithFilter`, which supports
|
740 |
+
* `map`, `flatMap`, `foreach`, and `withFilter` operations.
|
741 |
+
* All these operations apply to those elements of this $coll which
|
742 |
+
* satisfy the predicate `q` in addition to the predicate `p`.
|
743 |
+
*/
|
744 |
+
def withFilter(q: A => Boolean): WithFilter =
|
745 |
+
new WithFilter(x => p(x) && q(x))
|
746 |
+
}
|
747 |
+
|
748 |
+
// A helper for tails and inits.
|
749 |
+
private def iterateUntilEmpty(f: Traversable[A @uV] => Traversable[A @uV]): Iterator[Repr] = {
|
750 |
+
val it = Iterator.iterate(thisCollection)(f) takeWhile (x => !x.isEmpty)
|
751 |
+
it ++ Iterator(Nil) map (newBuilder ++= _ result)
|
752 |
+
}
|
753 |
+
}
|
754 |
+
|
755 |
+
|
756 |
+
</textarea>
|
757 |
+
</form>
|
758 |
+
|
759 |
+
<script>
|
760 |
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
761 |
+
lineNumbers: true,
|
762 |
+
matchBrackets: true,
|
763 |
+
theme: "ambiance",
|
764 |
+
mode: "text/x-scala"
|
765 |
+
});
|
766 |
+
</script>
|
767 |
+
</article>
|
admin/codemirror/mode/css/css.js
ADDED
@@ -0,0 +1,717 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function(mod) {
|
5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6 |
+
mod(require("../../lib/codemirror"));
|
7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
8 |
+
define(["../../lib/codemirror"], mod);
|
9 |
+
else // Plain browser env
|
10 |
+
mod(CodeMirror);
|
11 |
+
})(function(CodeMirror) {
|
12 |
+
"use strict";
|
13 |
+
|
14 |
+
CodeMirror.defineMode("css", function(config, parserConfig) {
|
15 |
+
if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");
|
16 |
+
|
17 |
+
var indentUnit = config.indentUnit,
|
18 |
+
tokenHooks = parserConfig.tokenHooks,
|
19 |
+
mediaTypes = parserConfig.mediaTypes || {},
|
20 |
+
mediaFeatures = parserConfig.mediaFeatures || {},
|
21 |
+
propertyKeywords = parserConfig.propertyKeywords || {},
|
22 |
+
nonStandardPropertyKeywords = parserConfig.nonStandardPropertyKeywords || {},
|
23 |
+
colorKeywords = parserConfig.colorKeywords || {},
|
24 |
+
valueKeywords = parserConfig.valueKeywords || {},
|
25 |
+
fontProperties = parserConfig.fontProperties || {},
|
26 |
+
allowNested = parserConfig.allowNested;
|
27 |
+
|
28 |
+
var type, override;
|
29 |
+
function ret(style, tp) { type = tp; return style; }
|
30 |
+
|
31 |
+
// Tokenizers
|
32 |
+
|
33 |
+
function tokenBase(stream, state) {
|
34 |
+
var ch = stream.next();
|
35 |
+
if (tokenHooks[ch]) {
|
36 |
+
var result = tokenHooks[ch](stream, state);
|
37 |
+
if (result !== false) return result;
|
38 |
+
}
|
39 |
+
if (ch == "@") {
|
40 |
+
stream.eatWhile(/[\w\\\-]/);
|
41 |
+
return ret("def", stream.current());
|
42 |
+
} else if (ch == "=" || (ch == "~" || ch == "|") && stream.eat("=")) {
|
43 |
+
return ret(null, "compare");
|
44 |
+
} else if (ch == "\"" || ch == "'") {
|
45 |
+
state.tokenize = tokenString(ch);
|
46 |
+
return state.tokenize(stream, state);
|
47 |
+
} else if (ch == "#") {
|
48 |
+
stream.eatWhile(/[\w\\\-]/);
|
49 |
+
return ret("atom", "hash");
|
50 |
+
} else if (ch == "!") {
|
51 |
+
stream.match(/^\s*\w*/);
|
52 |
+
return ret("keyword", "important");
|
53 |
+
} else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) {
|
54 |
+
stream.eatWhile(/[\w.%]/);
|
55 |
+
return ret("number", "unit");
|
56 |
+
} else if (ch === "-") {
|
57 |
+
if (/[\d.]/.test(stream.peek())) {
|
58 |
+
stream.eatWhile(/[\w.%]/);
|
59 |
+
return ret("number", "unit");
|
60 |
+
} else if (stream.match(/^\w+-/)) {
|
61 |
+
return ret("meta", "meta");
|
62 |
+
}
|
63 |
+
} else if (/[,+>*\/]/.test(ch)) {
|
64 |
+
return ret(null, "select-op");
|
65 |
+
} else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) {
|
66 |
+
return ret("qualifier", "qualifier");
|
67 |
+
} else if (/[:;{}\[\]\(\)]/.test(ch)) {
|
68 |
+
return ret(null, ch);
|
69 |
+
} else if (ch == "u" && stream.match("rl(")) {
|
70 |
+
stream.backUp(1);
|
71 |
+
state.tokenize = tokenParenthesized;
|
72 |
+
return ret("property", "word");
|
73 |
+
} else if (/[\w\\\-]/.test(ch)) {
|
74 |
+
stream.eatWhile(/[\w\\\-]/);
|
75 |
+
return ret("property", "word");
|
76 |
+
} else {
|
77 |
+
return ret(null, null);
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
function tokenString(quote) {
|
82 |
+
return function(stream, state) {
|
83 |
+
var escaped = false, ch;
|
84 |
+
while ((ch = stream.next()) != null) {
|
85 |
+
if (ch == quote && !escaped) {
|
86 |
+
if (quote == ")") stream.backUp(1);
|
87 |
+
break;
|
88 |
+
}
|
89 |
+
escaped = !escaped && ch == "\\";
|
90 |
+
}
|
91 |
+
if (ch == quote || !escaped && quote != ")") state.tokenize = null;
|
92 |
+
return ret("string", "string");
|
93 |
+
};
|
94 |
+
}
|
95 |
+
|
96 |
+
function tokenParenthesized(stream, state) {
|
97 |
+
stream.next(); // Must be '('
|
98 |
+
if (!stream.match(/\s*[\"\')]/, false))
|
99 |
+
state.tokenize = tokenString(")");
|
100 |
+
else
|
101 |
+
state.tokenize = null;
|
102 |
+
return ret(null, "(");
|
103 |
+
}
|
104 |
+
|
105 |
+
// Context management
|
106 |
+
|
107 |
+
function Context(type, indent, prev) {
|
108 |
+
this.type = type;
|
109 |
+
this.indent = indent;
|
110 |
+
this.prev = prev;
|
111 |
+
}
|
112 |
+
|
113 |
+
function pushContext(state, stream, type) {
|
114 |
+
state.context = new Context(type, stream.indentation() + indentUnit, state.context);
|
115 |
+
return type;
|
116 |
+
}
|
117 |
+
|
118 |
+
function popContext(state) {
|
119 |
+
state.context = state.context.prev;
|
120 |
+
return state.context.type;
|
121 |
+
}
|
122 |
+
|
123 |
+
function pass(type, stream, state) {
|
124 |
+
return states[state.context.type](type, stream, state);
|
125 |
+
}
|
126 |
+
function popAndPass(type, stream, state, n) {
|
127 |
+
for (var i = n || 1; i > 0; i--)
|
128 |
+
state.context = state.context.prev;
|
129 |
+
return pass(type, stream, state);
|
130 |
+
}
|
131 |
+
|
132 |
+
// Parser
|
133 |
+
|
134 |
+
function wordAsValue(stream) {
|
135 |
+
var word = stream.current().toLowerCase();
|
136 |
+
if (valueKeywords.hasOwnProperty(word))
|
137 |
+
override = "atom";
|
138 |
+
else if (colorKeywords.hasOwnProperty(word))
|
139 |
+
override = "keyword";
|
140 |
+
else
|
141 |
+
override = "variable";
|
142 |
+
}
|
143 |
+
|
144 |
+
var states = {};
|
145 |
+
|
146 |
+
states.top = function(type, stream, state) {
|
147 |
+
if (type == "{") {
|
148 |
+
return pushContext(state, stream, "block");
|
149 |
+
} else if (type == "}" && state.context.prev) {
|
150 |
+
return popContext(state);
|
151 |
+
} else if (type == "@media") {
|
152 |
+
return pushContext(state, stream, "media");
|
153 |
+
} else if (type == "@font-face") {
|
154 |
+
return "font_face_before";
|
155 |
+
} else if (/^@(-(moz|ms|o|webkit)-)?keyframes$/.test(type)) {
|
156 |
+
return "keyframes";
|
157 |
+
} else if (type && type.charAt(0) == "@") {
|
158 |
+
return pushContext(state, stream, "at");
|
159 |
+
} else if (type == "hash") {
|
160 |
+
override = "builtin";
|
161 |
+
} else if (type == "word") {
|
162 |
+
override = "tag";
|
163 |
+
} else if (type == "variable-definition") {
|
164 |
+
return "maybeprop";
|
165 |
+
} else if (type == "interpolation") {
|
166 |
+
return pushContext(state, stream, "interpolation");
|
167 |
+
} else if (type == ":") {
|
168 |
+
return "pseudo";
|
169 |
+
} else if (allowNested && type == "(") {
|
170 |
+
return pushContext(state, stream, "parens");
|
171 |
+
}
|
172 |
+
return state.context.type;
|
173 |
+
};
|
174 |
+
|
175 |
+
states.block = function(type, stream, state) {
|
176 |
+
if (type == "word") {
|
177 |
+
var word = stream.current().toLowerCase();
|
178 |
+
if (propertyKeywords.hasOwnProperty(word)) {
|
179 |
+
override = "property";
|
180 |
+
return "maybeprop";
|
181 |
+
} else if (nonStandardPropertyKeywords.hasOwnProperty(word)) {
|
182 |
+
override = "string-2";
|
183 |
+
return "maybeprop";
|
184 |
+
} else if (allowNested) {
|
185 |
+
override = stream.match(/^\s*:/, false) ? "property" : "tag";
|
186 |
+
return "block";
|
187 |
+
} else {
|
188 |
+
override += " error";
|
189 |
+
return "maybeprop";
|
190 |
+
}
|
191 |
+
} else if (type == "meta") {
|
192 |
+
return "block";
|
193 |
+
} else if (!allowNested && (type == "hash" || type == "qualifier")) {
|
194 |
+
override = "error";
|
195 |
+
return "block";
|
196 |
+
} else {
|
197 |
+
return states.top(type, stream, state);
|
198 |
+
}
|
199 |
+
};
|
200 |
+
|
201 |
+
states.maybeprop = function(type, stream, state) {
|
202 |
+
if (type == ":") return pushContext(state, stream, "prop");
|
203 |
+
return pass(type, stream, state);
|
204 |
+
};
|
205 |
+
|
206 |
+
states.prop = function(type, stream, state) {
|
207 |
+
if (type == ";") return popContext(state);
|
208 |
+
if (type == "{" && allowNested) return pushContext(state, stream, "propBlock");
|
209 |
+
if (type == "}" || type == "{") return popAndPass(type, stream, state);
|
210 |
+
if (type == "(") return pushContext(state, stream, "parens");
|
211 |
+
|
212 |
+
if (type == "hash" && !/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(stream.current())) {
|
213 |
+
override += " error";
|
214 |
+
} else if (type == "word") {
|
215 |
+
wordAsValue(stream);
|
216 |
+
} else if (type == "interpolation") {
|
217 |
+
return pushContext(state, stream, "interpolation");
|
218 |
+
}
|
219 |
+
return "prop";
|
220 |
+
};
|
221 |
+
|
222 |
+
states.propBlock = function(type, _stream, state) {
|
223 |
+
if (type == "}") return popContext(state);
|
224 |
+
if (type == "word") { override = "property"; return "maybeprop"; }
|
225 |
+
return state.context.type;
|
226 |
+
};
|
227 |
+
|
228 |
+
states.parens = function(type, stream, state) {
|
229 |
+
if (type == "{" || type == "}") return popAndPass(type, stream, state);
|
230 |
+
if (type == ")") return popContext(state);
|
231 |
+
if (type == "(") return pushContext(state, stream, "parens");
|
232 |
+
if (type == "word") wordAsValue(stream);
|
233 |
+
return "parens";
|
234 |
+
};
|
235 |
+
|
236 |
+
states.pseudo = function(type, stream, state) {
|
237 |
+
if (type == "word") {
|
238 |
+
override = "variable-3";
|
239 |
+
return state.context.type;
|
240 |
+
}
|
241 |
+
return pass(type, stream, state);
|
242 |
+
};
|
243 |
+
|
244 |
+
states.media = function(type, stream, state) {
|
245 |
+
if (type == "(") return pushContext(state, stream, "media_parens");
|
246 |
+
if (type == "}") return popAndPass(type, stream, state);
|
247 |
+
if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top");
|
248 |
+
|
249 |
+
if (type == "word") {
|
250 |
+
var word = stream.current().toLowerCase();
|
251 |
+
if (word == "only" || word == "not" || word == "and")
|
252 |
+
override = "keyword";
|
253 |
+
else if (mediaTypes.hasOwnProperty(word))
|
254 |
+
override = "attribute";
|
255 |
+
else if (mediaFeatures.hasOwnProperty(word))
|
256 |
+
override = "property";
|
257 |
+
else
|
258 |
+
override = "error";
|
259 |
+
}
|
260 |
+
return state.context.type;
|
261 |
+
};
|
262 |
+
|
263 |
+
states.media_parens = function(type, stream, state) {
|
264 |
+
if (type == ")") return popContext(state);
|
265 |
+
if (type == "{" || type == "}") return popAndPass(type, stream, state, 2);
|
266 |
+
return states.media(type, stream, state);
|
267 |
+
};
|
268 |
+
|
269 |
+
states.font_face_before = function(type, stream, state) {
|
270 |
+
if (type == "{")
|
271 |
+
return pushContext(state, stream, "font_face");
|
272 |
+
return pass(type, stream, state);
|
273 |
+
};
|
274 |
+
|
275 |
+
states.font_face = function(type, stream, state) {
|
276 |
+
if (type == "}") return popContext(state);
|
277 |
+
if (type == "word") {
|
278 |
+
if (!fontProperties.hasOwnProperty(stream.current().toLowerCase()))
|
279 |
+
override = "error";
|
280 |
+
else
|
281 |
+
override = "property";
|
282 |
+
return "maybeprop";
|
283 |
+
}
|
284 |
+
return "font_face";
|
285 |
+
};
|
286 |
+
|
287 |
+
states.keyframes = function(type, stream, state) {
|
288 |
+
if (type == "word") { override = "variable"; return "keyframes"; }
|
289 |
+
if (type == "{") return pushContext(state, stream, "top");
|
290 |
+
return pass(type, stream, state);
|
291 |
+
};
|
292 |
+
|
293 |
+
states.at = function(type, stream, state) {
|
294 |
+
if (type == ";") return popContext(state);
|
295 |
+
if (type == "{" || type == "}") return popAndPass(type, stream, state);
|
296 |
+
if (type == "word") override = "tag";
|
297 |
+
else if (type == "hash") override = "builtin";
|
298 |
+
return "at";
|
299 |
+
};
|
300 |
+
|
301 |
+
states.interpolation = function(type, stream, state) {
|
302 |
+
if (type == "}") return popContext(state);
|
303 |
+
if (type == "{" || type == ";") return popAndPass(type, stream, state);
|
304 |
+
if (type != "variable") override = "error";
|
305 |
+
return "interpolation";
|
306 |
+
};
|
307 |
+
|
308 |
+
return {
|
309 |
+
startState: function(base) {
|
310 |
+
return {tokenize: null,
|
311 |
+
state: "top",
|
312 |
+
context: new Context("top", base || 0, null)};
|
313 |
+
},
|
314 |
+
|
315 |
+
token: function(stream, state) {
|
316 |
+
if (!state.tokenize && stream.eatSpace()) return null;
|
317 |
+
var style = (state.tokenize || tokenBase)(stream, state);
|
318 |
+
if (style && typeof style == "object") {
|
319 |
+
type = style[1];
|
320 |
+
style = style[0];
|
321 |
+
}
|
322 |
+
override = style;
|
323 |
+
state.state = states[state.state](type, stream, state);
|
324 |
+
return override;
|
325 |
+
},
|
326 |
+
|
327 |
+
indent: function(state, textAfter) {
|
328 |
+
var cx = state.context, ch = textAfter && textAfter.charAt(0);
|
329 |
+
var indent = cx.indent;
|
330 |
+
if (cx.type == "prop" && (ch == "}" || ch == ")")) cx = cx.prev;
|
331 |
+
if (cx.prev &&
|
332 |
+
(ch == "}" && (cx.type == "block" || cx.type == "top" || cx.type == "interpolation" || cx.type == "font_face") ||
|
333 |
+
ch == ")" && (cx.type == "parens" || cx.type == "media_parens") ||
|
334 |
+
ch == "{" && (cx.type == "at" || cx.type == "media"))) {
|
335 |
+
indent = cx.indent - indentUnit;
|
336 |
+
cx = cx.prev;
|
337 |
+
}
|
338 |
+
return indent;
|
339 |
+
},
|
340 |
+
|
341 |
+
electricChars: "}",
|
342 |
+
blockCommentStart: "/*",
|
343 |
+
blockCommentEnd: "*/",
|
344 |
+
fold: "brace"
|
345 |
+
};
|
346 |
+
});
|
347 |
+
|
348 |
+
function keySet(array) {
|
349 |
+
var keys = {};
|
350 |
+
for (var i = 0; i < array.length; ++i) {
|
351 |
+
keys[array[i]] = true;
|
352 |
+
}
|
353 |
+
return keys;
|
354 |
+
}
|
355 |
+
|
356 |
+
var mediaTypes_ = [
|
357 |
+
"all", "aural", "braille", "handheld", "print", "projection", "screen",
|
358 |
+
"tty", "tv", "embossed"
|
359 |
+
], mediaTypes = keySet(mediaTypes_);
|
360 |
+
|
361 |
+
var mediaFeatures_ = [
|
362 |
+
"width", "min-width", "max-width", "height", "min-height", "max-height",
|
363 |
+
"device-width", "min-device-width", "max-device-width", "device-height",
|
364 |
+
"min-device-height", "max-device-height", "aspect-ratio",
|
365 |
+
"min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio",
|
366 |
+
"min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",
|
367 |
+
"max-color", "color-index", "min-color-index", "max-color-index",
|
368 |
+
"monochrome", "min-monochrome", "max-monochrome", "resolution",
|
369 |
+
"min-resolution", "max-resolution", "scan", "grid"
|
370 |
+
], mediaFeatures = keySet(mediaFeatures_);
|
371 |
+
|
372 |
+
var propertyKeywords_ = [
|
373 |
+
"align-content", "align-items", "align-self", "alignment-adjust",
|
374 |
+
"alignment-baseline", "anchor-point", "animation", "animation-delay",
|
375 |
+
"animation-direction", "animation-duration", "animation-fill-mode",
|
376 |
+
"animation-iteration-count", "animation-name", "animation-play-state",
|
377 |
+
"animation-timing-function", "appearance", "azimuth", "backface-visibility",
|
378 |
+
"background", "background-attachment", "background-clip", "background-color",
|
379 |
+
"background-image", "background-origin", "background-position",
|
380 |
+
"background-repeat", "background-size", "baseline-shift", "binding",
|
381 |
+
"bleed", "bookmark-label", "bookmark-level", "bookmark-state",
|
382 |
+
"bookmark-target", "border", "border-bottom", "border-bottom-color",
|
383 |
+
"border-bottom-left-radius", "border-bottom-right-radius",
|
384 |
+
"border-bottom-style", "border-bottom-width", "border-collapse",
|
385 |
+
"border-color", "border-image", "border-image-outset",
|
386 |
+
"border-image-repeat", "border-image-slice", "border-image-source",
|
387 |
+
"border-image-width", "border-left", "border-left-color",
|
388 |
+
"border-left-style", "border-left-width", "border-radius", "border-right",
|
389 |
+
"border-right-color", "border-right-style", "border-right-width",
|
390 |
+
"border-spacing", "border-style", "border-top", "border-top-color",
|
391 |
+
"border-top-left-radius", "border-top-right-radius", "border-top-style",
|
392 |
+
"border-top-width", "border-width", "bottom", "box-decoration-break",
|
393 |
+
"box-shadow", "box-sizing", "break-after", "break-before", "break-inside",
|
394 |
+
"caption-side", "clear", "clip", "color", "color-profile", "column-count",
|
395 |
+
"column-fill", "column-gap", "column-rule", "column-rule-color",
|
396 |
+
"column-rule-style", "column-rule-width", "column-span", "column-width",
|
397 |
+
"columns", "content", "counter-increment", "counter-reset", "crop", "cue",
|
398 |
+
"cue-after", "cue-before", "cursor", "direction", "display",
|
399 |
+
"dominant-baseline", "drop-initial-after-adjust",
|
400 |
+
"drop-initial-after-align", "drop-initial-before-adjust",
|
401 |
+
"drop-initial-before-align", "drop-initial-size", "drop-initial-value",
|
402 |
+
"elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis",
|
403 |
+
"flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap",
|
404 |
+
"float", "float-offset", "flow-from", "flow-into", "font", "font-feature-settings",
|
405 |
+
"font-family", "font-kerning", "font-language-override", "font-size", "font-size-adjust",
|
406 |
+
"font-stretch", "font-style", "font-synthesis", "font-variant",
|
407 |
+
"font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
|
408 |
+
"font-variant-ligatures", "font-variant-numeric", "font-variant-position",
|
409 |
+
"font-weight", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow",
|
410 |
+
"grid-auto-position", "grid-auto-rows", "grid-column", "grid-column-end",
|
411 |
+
"grid-column-start", "grid-row", "grid-row-end", "grid-row-start",
|
412 |
+
"grid-template", "grid-template-areas", "grid-template-columns",
|
413 |
+
"grid-template-rows", "hanging-punctuation", "height", "hyphens",
|
414 |
+
"icon", "image-orientation", "image-rendering", "image-resolution",
|
415 |
+
"inline-box-align", "justify-content", "left", "letter-spacing",
|
416 |
+
"line-break", "line-height", "line-stacking", "line-stacking-ruby",
|
417 |
+
"line-stacking-shift", "line-stacking-strategy", "list-style",
|
418 |
+
"list-style-image", "list-style-position", "list-style-type", "margin",
|
419 |
+
"margin-bottom", "margin-left", "margin-right", "margin-top",
|
420 |
+
"marker-offset", "marks", "marquee-direction", "marquee-loop",
|
421 |
+
"marquee-play-count", "marquee-speed", "marquee-style", "max-height",
|
422 |
+
"max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index",
|
423 |
+
"nav-left", "nav-right", "nav-up", "object-fit", "object-position",
|
424 |
+
"opacity", "order", "orphans", "outline",
|
425 |
+
"outline-color", "outline-offset", "outline-style", "outline-width",
|
426 |
+
"overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",
|
427 |
+
"padding", "padding-bottom", "padding-left", "padding-right", "padding-top",
|
428 |
+
"page", "page-break-after", "page-break-before", "page-break-inside",
|
429 |
+
"page-policy", "pause", "pause-after", "pause-before", "perspective",
|
430 |
+
"perspective-origin", "pitch", "pitch-range", "play-during", "position",
|
431 |
+
"presentation-level", "punctuation-trim", "quotes", "region-break-after",
|
432 |
+
"region-break-before", "region-break-inside", "region-fragment",
|
433 |
+
"rendering-intent", "resize", "rest", "rest-after", "rest-before", "richness",
|
434 |
+
"right", "rotation", "rotation-point", "ruby-align", "ruby-overhang",
|
435 |
+
"ruby-position", "ruby-span", "shape-image-threshold", "shape-inside", "shape-margin",
|
436 |
+
"shape-outside", "size", "speak", "speak-as", "speak-header",
|
437 |
+
"speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",
|
438 |
+
"tab-size", "table-layout", "target", "target-name", "target-new",
|
439 |
+
"target-position", "text-align", "text-align-last", "text-decoration",
|
440 |
+
"text-decoration-color", "text-decoration-line", "text-decoration-skip",
|
441 |
+
"text-decoration-style", "text-emphasis", "text-emphasis-color",
|
442 |
+
"text-emphasis-position", "text-emphasis-style", "text-height",
|
443 |
+
"text-indent", "text-justify", "text-outline", "text-overflow", "text-shadow",
|
444 |
+
"text-size-adjust", "text-space-collapse", "text-transform", "text-underline-position",
|
445 |
+
"text-wrap", "top", "transform", "transform-origin", "transform-style",
|
446 |
+
"transition", "transition-delay", "transition-duration",
|
447 |
+
"transition-property", "transition-timing-function", "unicode-bidi",
|
448 |
+
"vertical-align", "visibility", "voice-balance", "voice-duration",
|
449 |
+
"voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
|
450 |
+
"voice-volume", "volume", "white-space", "widows", "width", "word-break",
|
451 |
+
"word-spacing", "word-wrap", "z-index",
|
452 |
+
// SVG-specific
|
453 |
+
"clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color",
|
454 |
+
"flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events",
|
455 |
+
"color-interpolation", "color-interpolation-filters",
|
456 |
+
"color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering",
|
457 |
+
"marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke",
|
458 |
+
"stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin",
|
459 |
+
"stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering",
|
460 |
+
"baseline-shift", "dominant-baseline", "glyph-orientation-horizontal",
|
461 |
+
"glyph-orientation-vertical", "text-anchor", "writing-mode"
|
462 |
+
], propertyKeywords = keySet(propertyKeywords_);
|
463 |
+
|
464 |
+
var nonStandardPropertyKeywords_ = [
|
465 |
+
"scrollbar-arrow-color", "scrollbar-base-color", "scrollbar-dark-shadow-color",
|
466 |
+
"scrollbar-face-color", "scrollbar-highlight-color", "scrollbar-shadow-color",
|
467 |
+
"scrollbar-3d-light-color", "scrollbar-track-color", "shape-inside",
|
468 |
+
"searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",
|
469 |
+
"searchfield-results-decoration", "zoom"
|
470 |
+
], nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords_);
|
471 |
+
|
472 |
+
var colorKeywords_ = [
|
473 |
+
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
|
474 |
+
"bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
|
475 |
+
"burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue",
|
476 |
+
"cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod",
|
477 |
+
"darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen",
|
478 |
+
"darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen",
|
479 |
+
"darkslateblue", "darkslategray", "darkturquoise", "darkviolet",
|
480 |
+
"deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick",
|
481 |
+
"floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite",
|
482 |
+
"gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew",
|
483 |
+
"hotpink", "indianred", "indigo", "ivory", "khaki", "lavender",
|
484 |
+
"lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral",
|
485 |
+
"lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink",
|
486 |
+
"lightsalmon", "lightseagreen", "lightskyblue", "lightslategray",
|
487 |
+
"lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta",
|
488 |
+
"maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple",
|
489 |
+
"mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise",
|
490 |
+
"mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin",
|
491 |
+
"navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered",
|
492 |
+
"orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred",
|
493 |
+
"papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue",
|
494 |
+
"purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown",
|
495 |
+
"salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue",
|
496 |
+
"slateblue", "slategray", "snow", "springgreen", "steelblue", "tan",
|
497 |
+
"teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white",
|
498 |
+
"whitesmoke", "yellow", "yellowgreen"
|
499 |
+
], colorKeywords = keySet(colorKeywords_);
|
500 |
+
|
501 |
+
var valueKeywords_ = [
|
502 |
+
"above", "absolute", "activeborder", "activecaption", "afar",
|
503 |
+
"after-white-space", "ahead", "alias", "all", "all-scroll", "alternate",
|
504 |
+
"always", "amharic", "amharic-abegede", "antialiased", "appworkspace",
|
505 |
+
"arabic-indic", "armenian", "asterisks", "auto", "avoid", "avoid-column", "avoid-page",
|
506 |
+
"avoid-region", "background", "backwards", "baseline", "below", "bidi-override", "binary",
|
507 |
+
"bengali", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box",
|
508 |
+
"both", "bottom", "break", "break-all", "break-word", "button", "button-bevel",
|
509 |
+
"buttonface", "buttonhighlight", "buttonshadow", "buttontext", "cambodian",
|
510 |
+
"capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
|
511 |
+
"cell", "center", "checkbox", "circle", "cjk-earthly-branch",
|
512 |
+
"cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
|
513 |
+
"col-resize", "collapse", "column", "compact", "condensed", "contain", "content",
|
514 |
+
"content-box", "context-menu", "continuous", "copy", "cover", "crop",
|
515 |
+
"cross", "crosshair", "currentcolor", "cursive", "dashed", "decimal",
|
516 |
+
"decimal-leading-zero", "default", "default-button", "destination-atop",
|
517 |
+
"destination-in", "destination-out", "destination-over", "devanagari",
|
518 |
+
"disc", "discard", "document", "dot-dash", "dot-dot-dash", "dotted",
|
519 |
+
"double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",
|
520 |
+
"element", "ellipse", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede",
|
521 |
+
"ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er",
|
522 |
+
"ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er",
|
523 |
+
"ethiopic-halehame-aa-et", "ethiopic-halehame-am-et",
|
524 |
+
"ethiopic-halehame-gez", "ethiopic-halehame-om-et",
|
525 |
+
"ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
|
526 |
+
"ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et",
|
527 |
+
"ethiopic-halehame-tig", "ew-resize", "expanded", "extra-condensed",
|
528 |
+
"extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "footnotes",
|
529 |
+
"forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",
|
530 |
+
"gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew",
|
531 |
+
"help", "hidden", "hide", "higher", "highlight", "highlighttext",
|
532 |
+
"hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore",
|
533 |
+
"inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
|
534 |
+
"infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
|
535 |
+
"inline-block", "inline-table", "inset", "inside", "intrinsic", "invert",
|
536 |
+
"italic", "justify", "kannada", "katakana", "katakana-iroha", "keep-all", "khmer",
|
537 |
+
"landscape", "lao", "large", "larger", "left", "level", "lighter",
|
538 |
+
"line-through", "linear", "lines", "list-item", "listbox", "listitem",
|
539 |
+
"local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",
|
540 |
+
"lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",
|
541 |
+
"lower-roman", "lowercase", "ltr", "malayalam", "match",
|
542 |
+
"media-controls-background", "media-current-time-display",
|
543 |
+
"media-fullscreen-button", "media-mute-button", "media-play-button",
|
544 |
+
"media-return-to-realtime-button", "media-rewind-button",
|
545 |
+
"media-seek-back-button", "media-seek-forward-button", "media-slider",
|
546 |
+
"media-sliderthumb", "media-time-remaining-display", "media-volume-slider",
|
547 |
+
"media-volume-slider-container", "media-volume-sliderthumb", "medium",
|
548 |
+
"menu", "menulist", "menulist-button", "menulist-text",
|
549 |
+
"menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",
|
550 |
+
"mix", "mongolian", "monospace", "move", "multiple", "myanmar", "n-resize",
|
551 |
+
"narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",
|
552 |
+
"no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",
|
553 |
+
"ns-resize", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote",
|
554 |
+
"optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset",
|
555 |
+
"outside", "outside-shape", "overlay", "overline", "padding", "padding-box",
|
556 |
+
"painted", "page", "paused", "persian", "plus-darker", "plus-lighter", "pointer",
|
557 |
+
"polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d", "progress", "push-button",
|
558 |
+
"radio", "read-only", "read-write", "read-write-plaintext-only", "rectangle", "region",
|
559 |
+
"relative", "repeat", "repeat-x", "repeat-y", "reset", "reverse", "rgb", "rgba",
|
560 |
+
"ridge", "right", "round", "row-resize", "rtl", "run-in", "running",
|
561 |
+
"s-resize", "sans-serif", "scroll", "scrollbar", "se-resize", "searchfield",
|
562 |
+
"searchfield-cancel-button", "searchfield-decoration",
|
563 |
+
"searchfield-results-button", "searchfield-results-decoration",
|
564 |
+
"semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama",
|
565 |
+
"single", "skip-white-space", "slide", "slider-horizontal",
|
566 |
+
"slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
|
567 |
+
"small", "small-caps", "small-caption", "smaller", "solid", "somali",
|
568 |
+
"source-atop", "source-in", "source-out", "source-over", "space", "square",
|
569 |
+
"square-button", "start", "static", "status-bar", "stretch", "stroke",
|
570 |
+
"sub", "subpixel-antialiased", "super", "sw-resize", "table",
|
571 |
+
"table-caption", "table-cell", "table-column", "table-column-group",
|
572 |
+
"table-footer-group", "table-header-group", "table-row", "table-row-group",
|
573 |
+
"telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai",
|
574 |
+
"thick", "thin", "threeddarkshadow", "threedface", "threedhighlight",
|
575 |
+
"threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er",
|
576 |
+
"tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top",
|
577 |
+
"transparent", "ultra-condensed", "ultra-expanded", "underline", "up",
|
578 |
+
"upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal",
|
579 |
+
"upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",
|
580 |
+
"vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",
|
581 |
+
"visibleStroke", "visual", "w-resize", "wait", "wave", "wider",
|
582 |
+
"window", "windowframe", "windowtext", "x-large", "x-small", "xor",
|
583 |
+
"xx-large", "xx-small"
|
584 |
+
], valueKeywords = keySet(valueKeywords_);
|
585 |
+
|
586 |
+
var fontProperties_ = [
|
587 |
+
"font-family", "src", "unicode-range", "font-variant", "font-feature-settings",
|
588 |
+
"font-stretch", "font-weight", "font-style"
|
589 |
+
], fontProperties = keySet(fontProperties_);
|
590 |
+
|
591 |
+
var allWords = mediaTypes_.concat(mediaFeatures_).concat(propertyKeywords_)
|
592 |
+
.concat(nonStandardPropertyKeywords_).concat(colorKeywords_).concat(valueKeywords_);
|
593 |
+
CodeMirror.registerHelper("hintWords", "css", allWords);
|
594 |
+
|
595 |
+
function tokenCComment(stream, state) {
|
596 |
+
var maybeEnd = false, ch;
|
597 |
+
while ((ch = stream.next()) != null) {
|
598 |
+
if (maybeEnd && ch == "/") {
|
599 |
+
state.tokenize = null;
|
600 |
+
break;
|
601 |
+
}
|
602 |
+
maybeEnd = (ch == "*");
|
603 |
+
}
|
604 |
+
return ["comment", "comment"];
|
605 |
+
}
|
606 |
+
|
607 |
+
function tokenSGMLComment(stream, state) {
|
608 |
+
if (stream.skipTo("-->")) {
|
609 |
+
stream.match("-->");
|
610 |
+
state.tokenize = null;
|
611 |
+
} else {
|
612 |
+
stream.skipToEnd();
|
613 |
+
}
|
614 |
+
return ["comment", "comment"];
|
615 |
+
}
|
616 |
+
|
617 |
+
CodeMirror.defineMIME("text/css", {
|
618 |
+
mediaTypes: mediaTypes,
|
619 |
+
mediaFeatures: mediaFeatures,
|
620 |
+
propertyKeywords: propertyKeywords,
|
621 |
+
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
622 |
+
colorKeywords: colorKeywords,
|
623 |
+
valueKeywords: valueKeywords,
|
624 |
+
fontProperties: fontProperties,
|
625 |
+
tokenHooks: {
|
626 |
+
"<": function(stream, state) {
|
627 |
+
if (!stream.match("!--")) return false;
|
628 |
+
state.tokenize = tokenSGMLComment;
|
629 |
+
return tokenSGMLComment(stream, state);
|
630 |
+
},
|
631 |
+
"/": function(stream, state) {
|
632 |
+
if (!stream.eat("*")) return false;
|
633 |
+
state.tokenize = tokenCComment;
|
634 |
+
return tokenCComment(stream, state);
|
635 |
+
}
|
636 |
+
},
|
637 |
+
name: "css"
|
638 |
+
});
|
639 |
+
|
640 |
+
CodeMirror.defineMIME("text/x-scss", {
|
641 |
+
mediaTypes: mediaTypes,
|
642 |
+
mediaFeatures: mediaFeatures,
|
643 |
+
propertyKeywords: propertyKeywords,
|
644 |
+
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
645 |
+
colorKeywords: colorKeywords,
|
646 |
+
valueKeywords: valueKeywords,
|
647 |
+
fontProperties: fontProperties,
|
648 |
+
allowNested: true,
|
649 |
+
tokenHooks: {
|
650 |
+
"/": function(stream, state) {
|
651 |
+
if (stream.eat("/")) {
|
652 |
+
stream.skipToEnd();
|
653 |
+
return ["comment", "comment"];
|
654 |
+
} else if (stream.eat("*")) {
|
655 |
+
state.tokenize = tokenCComment;
|
656 |
+
return tokenCComment(stream, state);
|
657 |
+
} else {
|
658 |
+
return ["operator", "operator"];
|
659 |
+
}
|
660 |
+
},
|
661 |
+
":": function(stream) {
|
662 |
+
if (stream.match(/\s*\{/))
|
663 |
+
return [null, "{"];
|
664 |
+
return false;
|
665 |
+
},
|
666 |
+
"$": function(stream) {
|
667 |
+
stream.match(/^[\w-]+/);
|
668 |
+
if (stream.match(/^\s*:/, false))
|
669 |
+
return ["variable-2", "variable-definition"];
|
670 |
+
return ["variable-2", "variable"];
|
671 |
+
},
|
672 |
+
"#": function(stream) {
|
673 |
+
if (!stream.eat("{")) return false;
|
674 |
+
return [null, "interpolation"];
|
675 |
+
}
|
676 |
+
},
|
677 |
+
name: "css",
|
678 |
+
helperType: "scss"
|
679 |
+
});
|
680 |
+
|
681 |
+
CodeMirror.defineMIME("text/x-less", {
|
682 |
+
mediaTypes: mediaTypes,
|
683 |
+
mediaFeatures: mediaFeatures,
|
684 |
+
propertyKeywords: propertyKeywords,
|
685 |
+
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
686 |
+
colorKeywords: colorKeywords,
|
687 |
+
valueKeywords: valueKeywords,
|
688 |
+
fontProperties: fontProperties,
|
689 |
+
allowNested: true,
|
690 |
+
tokenHooks: {
|
691 |
+
"/": function(stream, state) {
|
692 |
+
if (stream.eat("/")) {
|
693 |
+
stream.skipToEnd();
|
694 |
+
return ["comment", "comment"];
|
695 |
+
} else if (stream.eat("*")) {
|
696 |
+
state.tokenize = tokenCComment;
|
697 |
+
return tokenCComment(stream, state);
|
698 |
+
} else {
|
699 |
+
return ["operator", "operator"];
|
700 |
+
}
|
701 |
+
},
|
702 |
+
"@": function(stream) {
|
703 |
+
if (stream.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/, false)) return false;
|
704 |
+
stream.eatWhile(/[\w\\\-]/);
|
705 |
+
if (stream.match(/^\s*:/, false))
|
706 |
+
return ["variable-2", "variable-definition"];
|
707 |
+
return ["variable-2", "variable"];
|
708 |
+
},
|
709 |
+
"&": function() {
|
710 |
+
return ["atom", "atom"];
|
711 |
+
}
|
712 |
+
},
|
713 |
+
name: "css",
|
714 |
+
helperType: "less"
|
715 |
+
});
|
716 |
+
|
717 |
+
});
|
admin/codemirror/mode/css/index.html
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
|
3 |
+
<title>CodeMirror: CSS mode</title>
|
4 |
+
<meta charset="utf-8"/>
|
5 |
+
<link rel=stylesheet href="../../doc/docs.css">
|
6 |
+
|
7 |
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
8 |
+
<script src="../../lib/codemirror.js"></script>
|
9 |
+
<script src="css.js"></script>
|
10 |
+
<style>.CodeMirror {background: #f8f8f8;}</style>
|
11 |
+
<div id=nav>
|
12 |
+
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
|
13 |
+
|
14 |
+
<ul>
|
15 |
+
<li><a href="../../index.html">Home</a>
|
16 |
+
<li><a href="../../doc/manual.html">Manual</a>
|
17 |
+
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
18 |
+
</ul>
|
19 |
+
<ul>
|
20 |
+
<li><a href="../index.html">Language modes</a>
|
21 |
+
<li><a class=active href="#">CSS</a>
|
22 |
+
</ul>
|
23 |
+
</div>
|
24 |
+
|
25 |
+
<article>
|
26 |
+
<h2>CSS mode</h2>
|
27 |
+
<form><textarea id="code" name="code">
|
28 |
+
/* Some example CSS */
|
29 |
+
|
30 |
+
@import url("something.css");
|
31 |
+
|
32 |
+
body {
|
33 |
+
margin: 0;
|
34 |
+
padding: 3em 6em;
|
35 |
+
font-family: tahoma, arial, sans-serif;
|
36 |
+
color: #000;
|
37 |
+
}
|
38 |
+
|
39 |
+
#navigation a {
|
40 |
+
font-weight: bold;
|
41 |
+
text-decoration: none !important;
|
42 |
+
}
|
43 |
+
|
44 |
+
h1 {
|
45 |
+
font-size: 2.5em;
|
46 |
+
}
|
47 |
+
|
48 |
+
h2 {
|
49 |
+
font-size: 1.7em;
|
50 |
+
}
|
51 |
+
|
52 |
+
h1:before, h2:before {
|
53 |
+
content: "::";
|
54 |
+
}
|
55 |
+
|
56 |
+
code {
|
57 |
+
font-family: courier, monospace;
|
58 |
+
font-size: 80%;
|
59 |
+
color: #418A8A;
|
60 |
+
}
|
61 |
+
</textarea></form>
|
62 |
+
<script>
|
63 |
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
64 |
+
</script>
|
65 |
+
|
66 |
+
<p><strong>MIME types defined:</strong> <code>text/css</code>, <code>text/x-scss</code> (<a href="scss.html">demo</a>), <code>text/x-less</code> (<a href="less.html">demo</a>).</p>
|
67 |
+
|
68 |
+
<p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#css_*">normal</a>, <a href="../../test/index.html#verbose,css_*">verbose</a>.</p>
|
69 |
+
|
70 |
+
</article>
|
admin/codemirror/mode/css/less.html
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
|
3 |
+
<title>CodeMirror: LESS mode</title>
|
4 |
+
<meta charset="utf-8"/>
|
5 |
+
<link rel=stylesheet href="../../doc/docs.css">
|
6 |
+
|
7 |
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
8 |
+
<script src="../../lib/codemirror.js"></script>
|
9 |
+
<script src="../../addon/edit/matchbrackets.js"></script>
|
10 |
+
<script src="css.js"></script>
|
11 |
+
<style>.CodeMirror {border: 1px solid #ddd; line-height: 1.2;}</style>
|
12 |
+
<div id=nav>
|
13 |
+
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
|
14 |
+
|
15 |
+
<ul>
|
16 |
+
<li><a href="../../index.html">Home</a>
|
17 |
+
<li><a href="../../doc/manual.html">Manual</a>
|
18 |
+
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
19 |
+
</ul>
|
20 |
+
<ul>
|
21 |
+
<li><a href="../index.html">Language modes</a>
|
22 |
+
<li><a class=active href="#">LESS</a>
|
23 |
+
</ul>
|
24 |
+
</div>
|
25 |
+
|
26 |
+
<article>
|
27 |
+
<h2>LESS mode</h2>
|
28 |
+
<form><textarea id="code" name="code">@media screen and (device-aspect-ratio: 16/9) { … }
|
29 |
+
@media screen and (device-aspect-ratio: 1280/720) { … }
|
30 |
+
@media screen and (device-aspect-ratio: 2560/1440) { … }
|
31 |
+
|
32 |
+
html:lang(fr-be)
|
33 |
+
|
34 |
+
tr:nth-child(2n+1) /* represents every odd row of an HTML table */
|
35 |
+
|
36 |
+
img:nth-of-type(2n+1) { float: right; }
|
37 |
+
img:nth-of-type(2n) { float: left; }
|
38 |
+
|
39 |
+
body > h2:not(:first-of-type):not(:last-of-type)
|
40 |
+
|
41 |
+
html|*:not(:link):not(:visited)
|
42 |
+
*|*:not(:hover)
|
43 |
+
p::first-line { text-transform: uppercase }
|
44 |
+
|
45 |
+
@namespace foo url(http://www.example.com);
|
46 |
+
foo|h1 { color: blue } /* first rule */
|
47 |
+
|
48 |
+
span[hello="Ocean"][goodbye="Land"]
|
49 |
+
|
50 |
+
E[foo]{
|
51 |
+
padding:65px;
|
52 |
+
}
|
53 |
+
|
54 |
+
input[type="search"]::-webkit-search-decoration,
|
55 |
+
input[type="search"]::-webkit-search-cancel-button {
|
56 |
+
-webkit-appearance: none; // Inner-padding issues in Chrome OSX, Safari 5
|
57 |
+
}
|
58 |
+
button::-moz-focus-inner,
|
59 |
+
input::-moz-focus-inner { // Inner padding and border oddities in FF3/4
|
60 |
+
padding: 0;
|
61 |
+
border: 0;
|
62 |
+
}
|
63 |
+
.btn {
|
64 |
+
// reset here as of 2.0.3 due to Recess property order
|
65 |
+
border-color: #ccc;
|
66 |
+
border-color: rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);
|
67 |
+
}
|
68 |
+
fieldset span button, fieldset span input[type="file"] {
|
69 |
+
font-size:12px;
|
70 |
+
font-family:Arial, Helvetica, sans-serif;
|
71 |
+
}
|
72 |
+
|
73 |
+
.rounded-corners (@radius: 5px) {
|
74 |
+
border-radius: @radius;
|
75 |
+
-webkit-border-radius: @radius;
|
76 |
+
-moz-border-radius: @radius;
|
77 |
+
}
|
78 |
+
|
79 |
+
@import url("something.css");
|
80 |
+
|
81 |
+
@light-blue: hsl(190, 50%, 65%);
|
82 |
+
|
83 |
+
#menu {
|
84 |
+
position: absolute;
|
85 |
+
width: 100%;
|
86 |
+
z-index: 3;
|
87 |
+
clear: both;
|
88 |
+
display: block;
|
89 |
+
background-color: @blue;
|
90 |
+
height: 42px;
|
91 |
+
border-top: 2px solid lighten(@alpha-blue, 20%);
|
92 |
+
border-bottom: 2px solid darken(@alpha-blue, 25%);
|
93 |
+
.box-shadow(0, 1px, 8px, 0.6);
|
94 |
+
-moz-box-shadow: 0 0 0 #000; // Because firefox sucks.
|
95 |
+
|
96 |
+
&.docked {
|
97 |
+
background-color: hsla(210, 60%, 40%, 0.4);
|
98 |
+
}
|
99 |
+
&:hover {
|
100 |
+
background-color: @blue;
|
101 |
+
}
|
102 |
+
|
103 |
+
#dropdown {
|
104 |
+
margin: 0 0 0 117px;
|
105 |
+
padding: 0;
|
106 |
+
padding-top: 5px;
|
107 |
+
display: none;
|
108 |
+
width: 190px;
|
109 |
+
border-top: 2px solid @medium;
|
110 |
+
color: @highlight;
|
111 |
+
border: 2px solid darken(@medium, 25%);
|
112 |
+
border-left-color: darken(@medium, 15%);
|
113 |
+
border-right-color: darken(@medium, 15%);
|
114 |
+
border-top-width: 0;
|
115 |
+
background-color: darken(@medium, 10%);
|
116 |
+
ul {
|
117 |
+
padding: 0px;
|
118 |
+
}
|
119 |
+
li {
|
120 |
+
font-size: 14px;
|
121 |
+
display: block;
|
122 |
+
text-align: left;
|
123 |
+
padding: 0;
|
124 |
+
border: 0;
|
125 |
+
a {
|
126 |
+
display: block;
|
127 |
+
padding: 0px 15px;
|
128 |
+
text-decoration: none;
|
129 |
+
color: white;
|
130 |
+
&:hover {
|
131 |
+
background-color: darken(@medium, 15%);
|
132 |
+
text-decoration: none;
|
133 |
+
}
|
134 |
+
}
|
135 |
+
}
|
136 |
+
.border-radius(5px, bottom);
|
137 |
+
.box-shadow(0, 6px, 8px, 0.5);
|
138 |
+
}
|
139 |
+
}
|
140 |
+
</textarea></form>
|
141 |
+
<script>
|
142 |
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
143 |
+
lineNumbers : true,
|
144 |
+
matchBrackets : true,
|
145 |
+
mode: "text/x-less"
|
146 |
+
});
|
147 |
+
</script>
|
148 |
+
|
149 |
+
<p>The LESS mode is a sub-mode of the <a href="index.html">CSS mode</a> (defined in <code>css.js</code>.</p>
|
150 |
+
|
151 |
+
<p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#less_*">normal</a>, <a href="../../test/index.html#verbose,less_*">verbose</a>.</p>
|
152 |
+
</article>
|
admin/codemirror/mode/css/less_test.js
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function() {
|
5 |
+
"use strict";
|
6 |
+
|
7 |
+
var mode = CodeMirror.getMode({indentUnit: 2}, "text/x-less");
|
8 |
+
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1), "less"); }
|
9 |
+
|
10 |
+
MT("variable",
|
11 |
+
"[variable-2 @base]: [atom #f04615];",
|
12 |
+
"[qualifier .class] {",
|
13 |
+
" [property width]: [variable percentage]([number 0.5]); [comment // returns `50%`]",
|
14 |
+
" [property color]: [variable saturate]([variable-2 @base], [number 5%]);",
|
15 |
+
"}");
|
16 |
+
|
17 |
+
MT("amp",
|
18 |
+
"[qualifier .child], [qualifier .sibling] {",
|
19 |
+
" [qualifier .parent] [atom &] {",
|
20 |
+
" [property color]: [keyword black];",
|
21 |
+
" }",
|
22 |
+
" [atom &] + [atom &] {",
|
23 |
+
" [property color]: [keyword red];",
|
24 |
+
" }",
|
25 |
+
"}");
|
26 |
+
|
27 |
+
MT("mixin",
|
28 |
+
"[qualifier .mixin] ([variable dark]; [variable-2 @color]) {",
|
29 |
+
" [property color]: [variable darken]([variable-2 @color], [number 10%]);",
|
30 |
+
"}",
|
31 |
+
"[qualifier .mixin] ([variable light]; [variable-2 @color]) {",
|
32 |
+
" [property color]: [variable lighten]([variable-2 @color], [number 10%]);",
|
33 |
+
"}",
|
34 |
+
"[qualifier .mixin] ([variable-2 @_]; [variable-2 @color]) {",
|
35 |
+
" [property display]: [atom block];",
|
36 |
+
"}",
|
37 |
+
"[variable-2 @switch]: [variable light];",
|
38 |
+
"[qualifier .class] {",
|
39 |
+
" [qualifier .mixin]([variable-2 @switch]; [atom #888]);",
|
40 |
+
"}");
|
41 |
+
|
42 |
+
MT("nest",
|
43 |
+
"[qualifier .one] {",
|
44 |
+
" [def @media] ([property width]: [number 400px]) {",
|
45 |
+
" [property font-size]: [number 1.2em];",
|
46 |
+
" [def @media] [attribute print] [keyword and] [property color] {",
|
47 |
+
" [property color]: [keyword blue];",
|
48 |
+
" }",
|
49 |
+
" }",
|
50 |
+
"}");
|
51 |
+
})();
|
admin/codemirror/mode/css/scss.html
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
|
3 |
+
<title>CodeMirror: SCSS mode</title>
|
4 |
+
<meta charset="utf-8"/>
|
5 |
+
<link rel=stylesheet href="../../doc/docs.css">
|
6 |
+
|
7 |
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
8 |
+
<script src="../../lib/codemirror.js"></script>
|
9 |
+
<script src="css.js"></script>
|
10 |
+
<style>.CodeMirror {background: #f8f8f8;}</style>
|
11 |
+
<div id=nav>
|
12 |
+
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
|
13 |
+
|
14 |
+
<ul>
|
15 |
+
<li><a href="../../index.html">Home</a>
|
16 |
+
<li><a href="../../doc/manual.html">Manual</a>
|
17 |
+
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
18 |
+
</ul>
|
19 |
+
<ul>
|
20 |
+
<li><a href="../index.html">Language modes</a>
|
21 |
+
<li><a class=active href="#">SCSS</a>
|
22 |
+
</ul>
|
23 |
+
</div>
|
24 |
+
|
25 |
+
<article>
|
26 |
+
<h2>SCSS mode</h2>
|
27 |
+
<form><textarea id="code" name="code">
|
28 |
+
/* Some example SCSS */
|
29 |
+
|
30 |
+
@import "compass/css3";
|
31 |
+
$variable: #333;
|
32 |
+
|
33 |
+
$blue: #3bbfce;
|
34 |
+
$margin: 16px;
|
35 |
+
|
36 |
+
.content-navigation {
|
37 |
+
#nested {
|
38 |
+
background-color: black;
|
39 |
+
}
|
40 |
+
border-color: $blue;
|
41 |
+
color:
|
42 |
+
darken($blue, 9%);
|
43 |
+
}
|
44 |
+
|
45 |
+
.border {
|
46 |
+
padding: $margin / 2;
|
47 |
+
margin: $margin / 2;
|
48 |
+
border-color: $blue;
|
49 |
+
}
|
50 |
+
|
51 |
+
@mixin table-base {
|
52 |
+
th {
|
53 |
+
text-align: center;
|
54 |
+
font-weight: bold;
|
55 |
+
}
|
56 |
+
td, th {padding: 2px}
|
57 |
+
}
|
58 |
+
|
59 |
+
table.hl {
|
60 |
+
margin: 2em 0;
|
61 |
+
td.ln {
|
62 |
+
text-align: right;
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
li {
|
67 |
+
font: {
|
68 |
+
family: serif;
|
69 |
+
weight: bold;
|
70 |
+
size: 1.2em;
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
@mixin left($dist) {
|
75 |
+
float: left;
|
76 |
+
margin-left: $dist;
|
77 |
+
}
|
78 |
+
|
79 |
+
#data {
|
80 |
+
@include left(10px);
|
81 |
+
@include table-base;
|
82 |
+
}
|
83 |
+
|
84 |
+
.source {
|
85 |
+
@include flow-into(target);
|
86 |
+
border: 10px solid green;
|
87 |
+
margin: 20px;
|
88 |
+
width: 200px; }
|
89 |
+
|
90 |
+
.new-container {
|
91 |
+
@include flow-from(target);
|
92 |
+
border: 10px solid red;
|
93 |
+
margin: 20px;
|
94 |
+
width: 200px; }
|
95 |
+
|
96 |
+
body {
|
97 |
+
margin: 0;
|
98 |
+
padding: 3em 6em;
|
99 |
+
font-family: tahoma, arial, sans-serif;
|
100 |
+
color: #000;
|
101 |
+
}
|
102 |
+
|
103 |
+
@mixin yellow() {
|
104 |
+
background: yellow;
|
105 |
+
}
|
106 |
+
|
107 |
+
.big {
|
108 |
+
font-size: 14px;
|
109 |
+
}
|
110 |
+
|
111 |
+
.nested {
|
112 |
+
@include border-radius(3px);
|
113 |
+
@extend .big;
|
114 |
+
p {
|
115 |
+
background: whitesmoke;
|
116 |
+
a {
|
117 |
+
color: red;
|
118 |
+
}
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
+
#navigation a {
|
123 |
+
font-weight: bold;
|
124 |
+
text-decoration: none !important;
|
125 |
+
}
|
126 |
+
|
127 |
+
h1 {
|
128 |
+
font-size: 2.5em;
|
129 |
+
}
|
130 |
+
|
131 |
+
h2 {
|
132 |
+
font-size: 1.7em;
|
133 |
+
}
|
134 |
+
|
135 |
+
h1:before, h2:before {
|
136 |
+
content: "::";
|
137 |
+
}
|
138 |
+
|
139 |
+
code {
|
140 |
+
font-family: courier, monospace;
|
141 |
+
font-size: 80%;
|
142 |
+
color: #418A8A;
|
143 |
+
}
|
144 |
+
</textarea></form>
|
145 |
+
<script>
|
146 |
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
147 |
+
lineNumbers: true,
|
148 |
+
matchBrackets: true,
|
149 |
+
mode: "text/x-scss"
|
150 |
+
});
|
151 |
+
</script>
|
152 |
+
|
153 |
+
<p>The SCSS mode is a sub-mode of the <a href="index.html">CSS mode</a> (defined in <code>css.js</code>.</p>
|
154 |
+
|
155 |
+
<p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#scss_*">normal</a>, <a href="../../test/index.html#verbose,scss_*">verbose</a>.</p>
|
156 |
+
|
157 |
+
</article>
|
admin/codemirror/mode/css/scss_test.js
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function() {
|
5 |
+
var mode = CodeMirror.getMode({indentUnit: 2}, "text/x-scss");
|
6 |
+
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1), "scss"); }
|
7 |
+
|
8 |
+
MT('url_with_quotation',
|
9 |
+
"[tag foo] { [property background]:[atom url]([string test.jpg]) }");
|
10 |
+
|
11 |
+
MT('url_with_double_quotes',
|
12 |
+
"[tag foo] { [property background]:[atom url]([string \"test.jpg\"]) }");
|
13 |
+
|
14 |
+
MT('url_with_single_quotes',
|
15 |
+
"[tag foo] { [property background]:[atom url]([string \'test.jpg\']) }");
|
16 |
+
|
17 |
+
MT('string',
|
18 |
+
"[def @import] [string \"compass/css3\"]");
|
19 |
+
|
20 |
+
MT('important_keyword',
|
21 |
+
"[tag foo] { [property background]:[atom url]([string \'test.jpg\']) [keyword !important] }");
|
22 |
+
|
23 |
+
MT('variable',
|
24 |
+
"[variable-2 $blue]:[atom #333]");
|
25 |
+
|
26 |
+
MT('variable_as_attribute',
|
27 |
+
"[tag foo] { [property color]:[variable-2 $blue] }");
|
28 |
+
|
29 |
+
MT('numbers',
|
30 |
+
"[tag foo] { [property padding]:[number 10px] [number 10] [number 10em] [number 8in] }");
|
31 |
+
|
32 |
+
MT('number_percentage',
|
33 |
+
"[tag foo] { [property width]:[number 80%] }");
|
34 |
+
|
35 |
+
MT('selector',
|
36 |
+
"[builtin #hello][qualifier .world]{}");
|
37 |
+
|
38 |
+
MT('singleline_comment',
|
39 |
+
"[comment // this is a comment]");
|
40 |
+
|
41 |
+
MT('multiline_comment',
|
42 |
+
"[comment /*foobar*/]");
|
43 |
+
|
44 |
+
MT('attribute_with_hyphen',
|
45 |
+
"[tag foo] { [property font-size]:[number 10px] }");
|
46 |
+
|
47 |
+
MT('string_after_attribute',
|
48 |
+
"[tag foo] { [property content]:[string \"::\"] }");
|
49 |
+
|
50 |
+
MT('directives',
|
51 |
+
"[def @include] [qualifier .mixin]");
|
52 |
+
|
53 |
+
MT('basic_structure',
|
54 |
+
"[tag p] { [property background]:[keyword red]; }");
|
55 |
+
|
56 |
+
MT('nested_structure',
|
57 |
+
"[tag p] { [tag a] { [property color]:[keyword red]; } }");
|
58 |
+
|
59 |
+
MT('mixin',
|
60 |
+
"[def @mixin] [tag table-base] {}");
|
61 |
+
|
62 |
+
MT('number_without_semicolon',
|
63 |
+
"[tag p] {[property width]:[number 12]}",
|
64 |
+
"[tag a] {[property color]:[keyword red];}");
|
65 |
+
|
66 |
+
MT('atom_in_nested_block',
|
67 |
+
"[tag p] { [tag a] { [property color]:[atom #000]; } }");
|
68 |
+
|
69 |
+
MT('interpolation_in_property',
|
70 |
+
"[tag foo] { #{[variable-2 $hello]}:[number 2]; }");
|
71 |
+
|
72 |
+
MT('interpolation_in_selector',
|
73 |
+
"[tag foo]#{[variable-2 $hello]} { [property color]:[atom #000]; }");
|
74 |
+
|
75 |
+
MT('interpolation_error',
|
76 |
+
"[tag foo]#{[error foo]} { [property color]:[atom #000]; }");
|
77 |
+
|
78 |
+
MT("divide_operator",
|
79 |
+
"[tag foo] { [property width]:[number 4] [operator /] [number 2] }");
|
80 |
+
|
81 |
+
MT('nested_structure_with_id_selector',
|
82 |
+
"[tag p] { [builtin #hello] { [property color]:[keyword red]; } }");
|
83 |
+
|
84 |
+
MT('indent_mixin',
|
85 |
+
"[def @mixin] [tag container] (",
|
86 |
+
" [variable-2 $a]: [number 10],",
|
87 |
+
" [variable-2 $b]: [number 10])",
|
88 |
+
"{}");
|
89 |
+
|
90 |
+
MT('indent_nested',
|
91 |
+
"[tag foo] {",
|
92 |
+
" [tag bar] {",
|
93 |
+
" }",
|
94 |
+
"}");
|
95 |
+
|
96 |
+
MT('indent_parentheses',
|
97 |
+
"[tag foo] {",
|
98 |
+
" [property color]: [variable darken]([variable-2 $blue],",
|
99 |
+
" [number 9%]);",
|
100 |
+
"}");
|
101 |
+
|
102 |
+
MT('indent_vardef',
|
103 |
+
"[variable-2 $name]:",
|
104 |
+
" [string 'val'];",
|
105 |
+
"[tag tag] {",
|
106 |
+
" [tag inner] {",
|
107 |
+
" [property margin]: [number 3px];",
|
108 |
+
" }",
|
109 |
+
"}");
|
110 |
+
})();
|
admin/codemirror/mode/css/test.js
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function() {
|
5 |
+
var mode = CodeMirror.getMode({indentUnit: 2}, "css");
|
6 |
+
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
|
7 |
+
|
8 |
+
// Error, because "foobarhello" is neither a known type or property, but
|
9 |
+
// property was expected (after "and"), and it should be in parenthese.
|
10 |
+
MT("atMediaUnknownType",
|
11 |
+
"[def @media] [attribute screen] [keyword and] [error foobarhello] { }");
|
12 |
+
|
13 |
+
// Soft error, because "foobarhello" is not a known property or type.
|
14 |
+
MT("atMediaUnknownProperty",
|
15 |
+
"[def @media] [attribute screen] [keyword and] ([error foobarhello]) { }");
|
16 |
+
|
17 |
+
// Make sure nesting works with media queries
|
18 |
+
MT("atMediaMaxWidthNested",
|
19 |
+
"[def @media] [attribute screen] [keyword and] ([property max-width]: [number 25px]) { [tag foo] { } }");
|
20 |
+
|
21 |
+
MT("tagSelector",
|
22 |
+
"[tag foo] { }");
|
23 |
+
|
24 |
+
MT("classSelector",
|
25 |
+
"[qualifier .foo-bar_hello] { }");
|
26 |
+
|
27 |
+
MT("idSelector",
|
28 |
+
"[builtin #foo] { [error #foo] }");
|
29 |
+
|
30 |
+
MT("tagSelectorUnclosed",
|
31 |
+
"[tag foo] { [property margin]: [number 0] } [tag bar] { }");
|
32 |
+
|
33 |
+
MT("tagStringNoQuotes",
|
34 |
+
"[tag foo] { [property font-family]: [variable hello] [variable world]; }");
|
35 |
+
|
36 |
+
MT("tagStringDouble",
|
37 |
+
"[tag foo] { [property font-family]: [string \"hello world\"]; }");
|
38 |
+
|
39 |
+
MT("tagStringSingle",
|
40 |
+
"[tag foo] { [property font-family]: [string 'hello world']; }");
|
41 |
+
|
42 |
+
MT("tagColorKeyword",
|
43 |
+
"[tag foo] {",
|
44 |
+
" [property color]: [keyword black];",
|
45 |
+
" [property color]: [keyword navy];",
|
46 |
+
" [property color]: [keyword yellow];",
|
47 |
+
"}");
|
48 |
+
|
49 |
+
MT("tagColorHex3",
|
50 |
+
"[tag foo] { [property background]: [atom #fff]; }");
|
51 |
+
|
52 |
+
MT("tagColorHex6",
|
53 |
+
"[tag foo] { [property background]: [atom #ffffff]; }");
|
54 |
+
|
55 |
+
MT("tagColorHex4",
|
56 |
+
"[tag foo] { [property background]: [atom&error #ffff]; }");
|
57 |
+
|
58 |
+
MT("tagColorHexInvalid",
|
59 |
+
"[tag foo] { [property background]: [atom&error #ffg]; }");
|
60 |
+
|
61 |
+
MT("tagNegativeNumber",
|
62 |
+
"[tag foo] { [property margin]: [number -5px]; }");
|
63 |
+
|
64 |
+
MT("tagPositiveNumber",
|
65 |
+
"[tag foo] { [property padding]: [number 5px]; }");
|
66 |
+
|
67 |
+
MT("tagVendor",
|
68 |
+
"[tag foo] { [meta -foo-][property box-sizing]: [meta -foo-][atom border-box]; }");
|
69 |
+
|
70 |
+
MT("tagBogusProperty",
|
71 |
+
"[tag foo] { [property&error barhelloworld]: [number 0]; }");
|
72 |
+
|
73 |
+
MT("tagTwoProperties",
|
74 |
+
"[tag foo] { [property margin]: [number 0]; [property padding]: [number 0]; }");
|
75 |
+
|
76 |
+
MT("tagTwoPropertiesURL",
|
77 |
+
"[tag foo] { [property background]: [atom url]([string //example.com/foo.png]); [property padding]: [number 0]; }");
|
78 |
+
|
79 |
+
MT("commentSGML",
|
80 |
+
"[comment <!--comment-->]");
|
81 |
+
|
82 |
+
MT("commentSGML2",
|
83 |
+
"[comment <!--comment]",
|
84 |
+
"[comment -->] [tag div] {}");
|
85 |
+
|
86 |
+
MT("indent_tagSelector",
|
87 |
+
"[tag strong], [tag em] {",
|
88 |
+
" [property background]: [atom rgba](",
|
89 |
+
" [number 255], [number 255], [number 0], [number .2]",
|
90 |
+
" );",
|
91 |
+
"}");
|
92 |
+
|
93 |
+
MT("indent_atMedia",
|
94 |
+
"[def @media] {",
|
95 |
+
" [tag foo] {",
|
96 |
+
" [property color]:",
|
97 |
+
" [keyword yellow];",
|
98 |
+
" }",
|
99 |
+
"}");
|
100 |
+
|
101 |
+
MT("indent_comma",
|
102 |
+
"[tag foo] {",
|
103 |
+
" [property font-family]: [variable verdana],",
|
104 |
+
" [atom sans-serif];",
|
105 |
+
"}");
|
106 |
+
|
107 |
+
MT("indent_parentheses",
|
108 |
+
"[tag foo]:[variable-3 before] {",
|
109 |
+
" [property background]: [atom url](",
|
110 |
+
"[string blahblah]",
|
111 |
+
"[string etc]",
|
112 |
+
"[string ]) [keyword !important];",
|
113 |
+
"}");
|
114 |
+
|
115 |
+
MT("font_face",
|
116 |
+
"[def @font-face] {",
|
117 |
+
" [property font-family]: [string 'myfont'];",
|
118 |
+
" [error nonsense]: [string 'abc'];",
|
119 |
+
" [property src]: [atom url]([string http://blah]),",
|
120 |
+
" [atom url]([string http://foo]);",
|
121 |
+
"}");
|
122 |
+
|
123 |
+
MT("empty_url",
|
124 |
+
"[def @import] [tag url]() [tag screen];");
|
125 |
+
|
126 |
+
MT("parens",
|
127 |
+
"[qualifier .foo] {",
|
128 |
+
" [property background-image]: [variable fade]([atom #000], [number 20%]);",
|
129 |
+
" [property border-image]: [variable linear-gradient](",
|
130 |
+
" [atom to] [atom bottom],",
|
131 |
+
" [variable fade]([atom #000], [number 20%]) [number 0%],",
|
132 |
+
" [variable fade]([atom #000], [number 20%]) [number 100%]",
|
133 |
+
" );",
|
134 |
+
"}");
|
135 |
+
})();
|
admin/codemirror/mode/htmlmixed/htmlmixed.js
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function(mod) {
|
5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6 |
+
mod(require("../../lib/codemirror"), require("../xml/xml"), require("../javascript/javascript"), require("../css/css"));
|
7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
8 |
+
define(["../../lib/codemirror", "../xml/xml", "../javascript/javascript", "../css/css"], mod);
|
9 |
+
else // Plain browser env
|
10 |
+
mod(CodeMirror);
|
11 |
+
})(function(CodeMirror) {
|
12 |
+
"use strict";
|
13 |
+
|
14 |
+
CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
|
15 |
+
var htmlMode = CodeMirror.getMode(config, {name: "xml",
|
16 |
+
htmlMode: true,
|
17 |
+
multilineTagIndentFactor: parserConfig.multilineTagIndentFactor,
|
18 |
+
multilineTagIndentPastTag: parserConfig.multilineTagIndentPastTag});
|
19 |
+
var cssMode = CodeMirror.getMode(config, "css");
|
20 |
+
|
21 |
+
var scriptTypes = [], scriptTypesConf = parserConfig && parserConfig.scriptTypes;
|
22 |
+
scriptTypes.push({matches: /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^$/i,
|
23 |
+
mode: CodeMirror.getMode(config, "javascript")});
|
24 |
+
if (scriptTypesConf) for (var i = 0; i < scriptTypesConf.length; ++i) {
|
25 |
+
var conf = scriptTypesConf[i];
|
26 |
+
scriptTypes.push({matches: conf.matches, mode: conf.mode && CodeMirror.getMode(config, conf.mode)});
|
27 |
+
}
|
28 |
+
scriptTypes.push({matches: /./,
|
29 |
+
mode: CodeMirror.getMode(config, "text/plain")});
|
30 |
+
|
31 |
+
function html(stream, state) {
|
32 |
+
var tagName = state.htmlState.tagName;
|
33 |
+
var style = htmlMode.token(stream, state.htmlState);
|
34 |
+
if (tagName == "script" && /\btag\b/.test(style) && stream.current() == ">") {
|
35 |
+
// Script block: mode to change to depends on type attribute
|
36 |
+
var scriptType = stream.string.slice(Math.max(0, stream.pos - 100), stream.pos).match(/\btype\s*=\s*("[^"]+"|'[^']+'|\S+)[^<]*$/i);
|
37 |
+
scriptType = scriptType ? scriptType[1] : "";
|
38 |
+
if (scriptType && /[\"\']/.test(scriptType.charAt(0))) scriptType = scriptType.slice(1, scriptType.length - 1);
|
39 |
+
for (var i = 0; i < scriptTypes.length; ++i) {
|
40 |
+
var tp = scriptTypes[i];
|
41 |
+
if (typeof tp.matches == "string" ? scriptType == tp.matches : tp.matches.test(scriptType)) {
|
42 |
+
if (tp.mode) {
|
43 |
+
state.token = script;
|
44 |
+
state.localMode = tp.mode;
|
45 |
+
state.localState = tp.mode.startState && tp.mode.startState(htmlMode.indent(state.htmlState, ""));
|
46 |
+
}
|
47 |
+
break;
|
48 |
+
}
|
49 |
+
}
|
50 |
+
} else if (tagName == "style" && /\btag\b/.test(style) && stream.current() == ">") {
|
51 |
+
state.token = css;
|
52 |
+
state.localMode = cssMode;
|
53 |
+
state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
|
54 |
+
}
|
55 |
+
return style;
|
56 |
+
}
|
57 |
+
function maybeBackup(stream, pat, style) {
|
58 |
+
var cur = stream.current();
|
59 |
+
var close = cur.search(pat), m;
|
60 |
+
if (close > -1) stream.backUp(cur.length - close);
|
61 |
+
else if (m = cur.match(/<\/?$/)) {
|
62 |
+
stream.backUp(cur.length);
|
63 |
+
if (!stream.match(pat, false)) stream.match(cur);
|
64 |
+
}
|
65 |
+
return style;
|
66 |
+
}
|
67 |
+
function script(stream, state) {
|
68 |
+
if (stream.match(/^<\/\s*script\s*>/i, false)) {
|
69 |
+
state.token = html;
|
70 |
+
state.localState = state.localMode = null;
|
71 |
+
return html(stream, state);
|
72 |
+
}
|
73 |
+
return maybeBackup(stream, /<\/\s*script\s*>/,
|
74 |
+
state.localMode.token(stream, state.localState));
|
75 |
+
}
|
76 |
+
function css(stream, state) {
|
77 |
+
if (stream.match(/^<\/\s*style\s*>/i, false)) {
|
78 |
+
state.token = html;
|
79 |
+
state.localState = state.localMode = null;
|
80 |
+
return html(stream, state);
|
81 |
+
}
|
82 |
+
return maybeBackup(stream, /<\/\s*style\s*>/,
|
83 |
+
cssMode.token(stream, state.localState));
|
84 |
+
}
|
85 |
+
|
86 |
+
return {
|
87 |
+
startState: function() {
|
88 |
+
var state = htmlMode.startState();
|
89 |
+
return {token: html, localMode: null, localState: null, htmlState: state};
|
90 |
+
},
|
91 |
+
|
92 |
+
copyState: function(state) {
|
93 |
+
if (state.localState)
|
94 |
+
var local = CodeMirror.copyState(state.localMode, state.localState);
|
95 |
+
return {token: state.token, localMode: state.localMode, localState: local,
|
96 |
+
htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
|
97 |
+
},
|
98 |
+
|
99 |
+
token: function(stream, state) {
|
100 |
+
return state.token(stream, state);
|
101 |
+
},
|
102 |
+
|
103 |
+
indent: function(state, textAfter) {
|
104 |
+
if (!state.localMode || /^\s*<\//.test(textAfter))
|
105 |
+
return htmlMode.indent(state.htmlState, textAfter);
|
106 |
+
else if (state.localMode.indent)
|
107 |
+
return state.localMode.indent(state.localState, textAfter);
|
108 |
+
else
|
109 |
+
return CodeMirror.Pass;
|
110 |
+
},
|
111 |
+
|
112 |
+
innerMode: function(state) {
|
113 |
+
return {state: state.localState || state.htmlState, mode: state.localMode || htmlMode};
|
114 |
+
}
|
115 |
+
};
|
116 |
+
}, "xml", "javascript", "css");
|
117 |
+
|
118 |
+
CodeMirror.defineMIME("text/html", "htmlmixed");
|
119 |
+
|
120 |
+
});
|
admin/codemirror/mode/htmlmixed/index.html
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
|
3 |
+
<title>CodeMirror: HTML mixed mode</title>
|
4 |
+
<meta charset="utf-8"/>
|
5 |
+
<link rel=stylesheet href="../../doc/docs.css">
|
6 |
+
|
7 |
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
8 |
+
<script src="../../lib/codemirror.js"></script>
|
9 |
+
<script src="../xml/xml.js"></script>
|
10 |
+
<script src="../javascript/javascript.js"></script>
|
11 |
+
<script src="../css/css.js"></script>
|
12 |
+
<script src="../vbscript/vbscript.js"></script>
|
13 |
+
<script src="htmlmixed.js"></script>
|
14 |
+
<style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
15 |
+
<div id=nav>
|
16 |
+
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
|
17 |
+
|
18 |
+
<ul>
|
19 |
+
<li><a href="../../index.html">Home</a>
|
20 |
+
<li><a href="../../doc/manual.html">Manual</a>
|
21 |
+
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
22 |
+
</ul>
|
23 |
+
<ul>
|
24 |
+
<li><a href="../index.html">Language modes</a>
|
25 |
+
<li><a class=active href="#">HTML mixed</a>
|
26 |
+
</ul>
|
27 |
+
</div>
|
28 |
+
|
29 |
+
<article>
|
30 |
+
<h2>HTML mixed mode</h2>
|
31 |
+
<form><textarea id="code" name="code">
|
32 |
+
<html style="color: green">
|
33 |
+
<!-- this is a comment -->
|
34 |
+
<head>
|
35 |
+
<title>Mixed HTML Example</title>
|
36 |
+
<style type="text/css">
|
37 |
+
h1 {font-family: comic sans; color: #f0f;}
|
38 |
+
div {background: yellow !important;}
|
39 |
+
body {
|
40 |
+
max-width: 50em;
|
41 |
+
margin: 1em 2em 1em 5em;
|
42 |
+
}
|
43 |
+
</style>
|
44 |
+
</head>
|
45 |
+
<body>
|
46 |
+
<h1>Mixed HTML Example</h1>
|
47 |
+
<script>
|
48 |
+
function jsFunc(arg1, arg2) {
|
49 |
+
if (arg1 && arg2) document.body.innerHTML = "achoo";
|
50 |
+
}
|
51 |
+
</script>
|
52 |
+
</body>
|
53 |
+
</html>
|
54 |
+
</textarea></form>
|
55 |
+
<script>
|
56 |
+
// Define an extended mixed-mode that understands vbscript and
|
57 |
+
// leaves mustache/handlebars embedded templates in html mode
|
58 |
+
var mixedMode = {
|
59 |
+
name: "htmlmixed",
|
60 |
+
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
|
61 |
+
mode: null},
|
62 |
+
{matches: /(text|application)\/(x-)?vb(a|script)/i,
|
63 |
+
mode: "vbscript"}]
|
64 |
+
};
|
65 |
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {mode: mixedMode});
|
66 |
+
</script>
|
67 |
+
|
68 |
+
<p>The HTML mixed mode depends on the XML, JavaScript, and CSS modes.</p>
|
69 |
+
|
70 |
+
<p>It takes an optional mode configuration
|
71 |
+
option, <code>scriptTypes</code>, which can be used to add custom
|
72 |
+
behavior for specific <code><script type="..."></code> tags. If
|
73 |
+
given, it should hold an array of <code>{matches, mode}</code>
|
74 |
+
objects, where <code>matches</code> is a string or regexp that
|
75 |
+
matches the script type, and <code>mode</code> is
|
76 |
+
either <code>null</code>, for script types that should stay in
|
77 |
+
HTML mode, or a <a href="../../doc/manual.html#option_mode">mode
|
78 |
+
spec</a> corresponding to the mode that should be used for the
|
79 |
+
script.</p>
|
80 |
+
|
81 |
+
<p><strong>MIME types defined:</strong> <code>text/html</code>
|
82 |
+
(redefined, only takes effect if you load this parser after the
|
83 |
+
XML parser).</p>
|
84 |
+
|
85 |
+
</article>
|
admin/codemirror/mode/index.html
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
|
3 |
+
<title>CodeMirror: Language Modes</title>
|
4 |
+
<meta charset="utf-8"/>
|
5 |
+
<link rel=stylesheet href="../doc/docs.css">
|
6 |
+
|
7 |
+
<div id=nav>
|
8 |
+
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
9 |
+
|
10 |
+
<ul>
|
11 |
+
<li><a href="../index.html">Home</a>
|
12 |
+
<li><a href="../doc/manual.html">Manual</a>
|
13 |
+
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
14 |
+
</ul>
|
15 |
+
<ul>
|
16 |
+
<li><a class=active href="#">Language modes</a>
|
17 |
+
</ul>
|
18 |
+
</div>
|
19 |
+
|
20 |
+
<article>
|
21 |
+
|
22 |
+
<h2>Language modes</h2>
|
23 |
+
|
24 |
+
<p>This is a list of every mode in the distribution. Each mode lives
|
25 |
+
in a subdirectory of the <code>mode/</code> directory, and typically
|
26 |
+
defines a single JavaScript file that implements the mode. Loading
|
27 |
+
such file will make the language available to CodeMirror, through
|
28 |
+
the <a href="manual.html#option_mode"><code>mode</code></a>
|
29 |
+
option.</p>
|
30 |
+
|
31 |
+
<div style="-webkit-columns: 100px 2; -moz-columns: 100px 2; columns: 100px 2;">
|
32 |
+
<ul style="margin-top: 0">
|
33 |
+
<li><a href="apl/index.html">APL</a></li>
|
34 |
+
<li><a href="asterisk/index.html">Asterisk dialplan</a></li>
|
35 |
+
<li><a href="clike/index.html">C, C++, C#</a></li>
|
36 |
+
<li><a href="clojure/index.html">Clojure</a></li>
|
37 |
+
<li><a href="cobol/index.html">COBOL</a></li>
|
38 |
+
<li><a href="coffeescript/index.html">CoffeeScript</a></li>
|
39 |
+
<li><a href="commonlisp/index.html">Common Lisp</a></li>
|
40 |
+
<li><a href="css/index.html">CSS</a></li>
|
41 |
+
<li><a href="cypher/index.html">Cypher</a></li>
|
42 |
+
<li><a href="python/index.html">Cython</a></li>
|
43 |
+
<li><a href="d/index.html">D</a></li>
|
44 |
+
<li><a href="django/index.html">Django</a> (templating language)</li>
|
45 |
+
<li><a href="diff/index.html">diff</a></li>
|
46 |
+
<li><a href="dtd/index.html">DTD</a></li>
|
47 |
+
<li><a href="dylan/index.html">Dylan</a></li>
|
48 |
+
<li><a href="ecl/index.html">ECL</a></li>
|
49 |
+
<li><a href="eiffel/index.html">Eiffel</a></li>
|
50 |
+
<li><a href="erlang/index.html">Erlang</a></li>
|
51 |
+
<li><a href="fortran/index.html">Fortran</a></li>
|
52 |
+
<li><a href="mllike/index.html">F#</a></li>
|
53 |
+
<li><a href="gas/index.html">Gas</a> (AT&T-style assembly)</li>
|
54 |
+
<li><a href="gherkin/index.html">Gherkin</a></li>
|
55 |
+
<li><a href="go/index.html">Go</a></li>
|
56 |
+
<li><a href="groovy/index.html">Groovy</a></li>
|
57 |
+
<li><a href="haml/index.html">HAML</a></li>
|
58 |
+
<li><a href="haskell/index.html">Haskell</a></li>
|
59 |
+
<li><a href="haxe/index.html">Haxe</a></li>
|
60 |
+
<li><a href="htmlembedded/index.html">HTML embedded scripts</a></li>
|
61 |
+
<li><a href="htmlmixed/index.html">HTML mixed-mode</a></li>
|
62 |
+
<li><a href="http/index.html">HTTP</a></li>
|
63 |
+
<li><a href="clike/index.html">Java</a></li>
|
64 |
+
<li><a href="jade/index.html">Jade</a></li>
|
65 |
+
<li><a href="javascript/index.html">JavaScript</a></li>
|
66 |
+
<li><a href="jinja2/index.html">Jinja2</a></li>
|
67 |
+
<li><a href="julia/index.html">Julia</a></li>
|
68 |
+
<li><a href="kotlin/index.html">Kotlin</a></li>
|
69 |
+
<li><a href="css/less.html">LESS</a></li>
|
70 |
+
<li><a href="livescript/index.html">LiveScript</a></li>
|
71 |
+
<li><a href="lua/index.html">Lua</a></li>
|
72 |
+
<li><a href="markdown/index.html">Markdown</a> (<a href="gfm/index.html">GitHub-flavour</a>)</li>
|
73 |
+
<li><a href="mirc/index.html">mIRC</a></li>
|
74 |
+
<li><a href="nginx/index.html">Nginx</a></li>
|
75 |
+
<li><a href="ntriples/index.html">NTriples</a></li>
|
76 |
+
<li><a href="mllike/index.html">OCaml</a></li>
|
77 |
+
<li><a href="octave/index.html">Octave</a> (MATLAB)</li>
|
78 |
+
<li><a href="pascal/index.html">Pascal</a></li>
|
79 |
+
<li><a href="pegjs/index.html">PEG.js</a></li>
|
80 |
+
<li><a href="perl/index.html">Perl</a></li>
|
81 |
+
<li><a href="php/index.html">PHP</a></li>
|
82 |
+
<li><a href="pig/index.html">Pig Latin</a></li>
|
83 |
+
<li><a href="properties/index.html">Properties files</a></li>
|
84 |
+
<li><a href="puppet/index.html">Puppet</a></li>
|
85 |
+
<li><a href="python/index.html">Python</a></li>
|
86 |
+
<li><a href="q/index.html">Q</a></li>
|
87 |
+
<li><a href="r/index.html">R</a></li>
|
88 |
+
<li><a href="rpm/index.html">RPM</a></li>
|
89 |
+
<li><a href="rst/index.html">reStructuredText</a></li>
|
90 |
+
<li><a href="ruby/index.html">Ruby</a></li>
|
91 |
+
<li><a href="rust/index.html">Rust</a></li>
|
92 |
+
<li><a href="sass/index.html">Sass</a></li>
|
93 |
+
<li><a href="clike/scala.html">Scala</a></li>
|
94 |
+
<li><a href="scheme/index.html">Scheme</a></li>
|
95 |
+
<li><a href="css/scss.html">SCSS</a></li>
|
96 |
+
<li><a href="shell/index.html">Shell</a></li>
|
97 |
+
<li><a href="sieve/index.html">Sieve</a></li>
|
98 |
+
<li><a href="smalltalk/index.html">Smalltalk</a></li>
|
99 |
+
<li><a href="smarty/index.html">Smarty</a></li>
|
100 |
+
<li><a href="smartymixed/index.html">Smarty/HTML mixed</a></li>
|
101 |
+
<li><a href="solr/index.html">Solr</a></li>
|
102 |
+
<li><a href="sql/index.html">SQL</a> (several dialects)</li>
|
103 |
+
<li><a href="sparql/index.html">SPARQL</a></li>
|
104 |
+
<li><a href="stex/index.html">sTeX, LaTeX</a></li>
|
105 |
+
<li><a href="tcl/index.html">Tcl</a></li>
|
106 |
+
<li><a href="tiddlywiki/index.html">Tiddlywiki</a></li>
|
107 |
+
<li><a href="tiki/index.html">Tiki wiki</a></li>
|
108 |
+
<li><a href="toml/index.html">TOML</a></li>
|
109 |
+
<li><a href="turtle/index.html">Turtle</a></li>
|
110 |
+
<li><a href="vb/index.html">VB.NET</a></li>
|
111 |
+
<li><a href="vbscript/index.html">VBScript</a></li>
|
112 |
+
<li><a href="velocity/index.html">Velocity</a></li>
|
113 |
+
<li><a href="verilog/index.html">Verilog/SystemVerilog</a></li>
|
114 |
+
<li><a href="xml/index.html">XML/HTML</a></li>
|
115 |
+
<li><a href="xquery/index.html">XQuery</a></li>
|
116 |
+
<li><a href="yaml/index.html">YAML</a></li>
|
117 |
+
<li><a href="z80/index.html">Z80</a></li>
|
118 |
+
</ul>
|
119 |
+
</div>
|
120 |
+
|
121 |
+
</article>
|
admin/codemirror/mode/javascript/index.html
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
|
3 |
+
<title>CodeMirror: JavaScript mode</title>
|
4 |
+
<meta charset="utf-8"/>
|
5 |
+
<link rel=stylesheet href="../../doc/docs.css">
|
6 |
+
|
7 |
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
8 |
+
<script src="../../lib/codemirror.js"></script>
|
9 |
+
<script src="../../addon/edit/matchbrackets.js"></script>
|
10 |
+
<script src="../../addon/comment/continuecomment.js"></script>
|
11 |
+
<script src="../../addon/comment/comment.js"></script>
|
12 |
+
<script src="javascript.js"></script>
|
13 |
+
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
14 |
+
<div id=nav>
|
15 |
+
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
|
16 |
+
|
17 |
+
<ul>
|
18 |
+
<li><a href="../../index.html">Home</a>
|
19 |
+
<li><a href="../../doc/manual.html">Manual</a>
|
20 |
+
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
21 |
+
</ul>
|
22 |
+
<ul>
|
23 |
+
<li><a href="../index.html">Language modes</a>
|
24 |
+
<li><a class=active href="#">JavaScript</a>
|
25 |
+
</ul>
|
26 |
+
</div>
|
27 |
+
|
28 |
+
<article>
|
29 |
+
<h2>JavaScript mode</h2>
|
30 |
+
|
31 |
+
|
32 |
+
<div><textarea id="code" name="code">
|
33 |
+
// Demo code (the actual new parser character stream implementation)
|
34 |
+
|
35 |
+
function StringStream(string) {
|
36 |
+
this.pos = 0;
|
37 |
+
this.string = string;
|
38 |
+
}
|
39 |
+
|
40 |
+
StringStream.prototype = {
|
41 |
+
done: function() {return this.pos >= this.string.length;},
|
42 |
+
peek: function() {return this.string.charAt(this.pos);},
|
43 |
+
next: function() {
|
44 |
+
if (this.pos < this.string.length)
|
45 |
+
return this.string.charAt(this.pos++);
|
46 |
+
},
|
47 |
+
eat: function(match) {
|
48 |
+
var ch = this.string.charAt(this.pos);
|
49 |
+
if (typeof match == "string") var ok = ch == match;
|
50 |
+
else var ok = ch && match.test ? match.test(ch) : match(ch);
|
51 |
+
if (ok) {this.pos++; return ch;}
|
52 |
+
},
|
53 |
+
eatWhile: function(match) {
|
54 |
+
var start = this.pos;
|
55 |
+
while (this.eat(match));
|
56 |
+
if (this.pos > start) return this.string.slice(start, this.pos);
|
57 |
+
},
|
58 |
+
backUp: function(n) {this.pos -= n;},
|
59 |
+
column: function() {return this.pos;},
|
60 |
+
eatSpace: function() {
|
61 |
+
var start = this.pos;
|
62 |
+
while (/\s/.test(this.string.charAt(this.pos))) this.pos++;
|
63 |
+
return this.pos - start;
|
64 |
+
},
|
65 |
+
match: function(pattern, consume, caseInsensitive) {
|
66 |
+
if (typeof pattern == "string") {
|
67 |
+
function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
|
68 |
+
if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
|
69 |
+
if (consume !== false) this.pos += str.length;
|
70 |
+
return true;
|
71 |
+
}
|
72 |
+
}
|
73 |
+
else {
|
74 |
+
var match = this.string.slice(this.pos).match(pattern);
|
75 |
+
if (match && consume !== false) this.pos += match[0].length;
|
76 |
+
return match;
|
77 |
+
}
|
78 |
+
}
|
79 |
+
};
|
80 |
+
</textarea></div>
|
81 |
+
|
82 |
+
<script>
|
83 |
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
84 |
+
lineNumbers: true,
|
85 |
+
matchBrackets: true,
|
86 |
+
continueComments: "Enter",
|
87 |
+
extraKeys: {"Ctrl-Q": "toggleComment"}
|
88 |
+
});
|
89 |
+
</script>
|
90 |
+
|
91 |
+
<p>
|
92 |
+
JavaScript mode supports several configuration options:
|
93 |
+
<ul>
|
94 |
+
<li><code>json</code> which will set the mode to expect JSON
|
95 |
+
data rather than a JavaScript program.</li>
|
96 |
+
<li><code>jsonld</code> which will set the mode to expect
|
97 |
+
<a href="http://json-ld.org">JSON-LD</a> linked data rather
|
98 |
+
than a JavaScript program (<a href="json-ld.html">demo</a>).</li>
|
99 |
+
<li><code>typescript</code> which will activate additional
|
100 |
+
syntax highlighting and some other things for TypeScript code
|
101 |
+
(<a href="typescript.html">demo</a>).</li>
|
102 |
+
<li><code>statementIndent</code> which (given a number) will
|
103 |
+
determine the amount of indentation to use for statements
|
104 |
+
continued on a new line.</li>
|
105 |
+
</ul>
|
106 |
+
</p>
|
107 |
+
|
108 |
+
<p><strong>MIME types defined:</strong> <code>text/javascript</code>, <code>application/json</code>, <code>application/ld+json</code>, <code>text/typescript</code>, <code>application/typescript</code>.</p>
|
109 |
+
</article>
|
admin/codemirror/mode/javascript/javascript.js
ADDED
@@ -0,0 +1,685 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
// TODO actually recognize syntax of TypeScript constructs
|
5 |
+
|
6 |
+
(function(mod) {
|
7 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
8 |
+
mod(require("../../lib/codemirror"));
|
9 |
+
else if (typeof define == "function" && define.amd) // AMD
|
10 |
+
define(["../../lib/codemirror"], mod);
|
11 |
+
else // Plain browser env
|
12 |
+
mod(CodeMirror);
|
13 |
+
})(function(CodeMirror) {
|
14 |
+
"use strict";
|
15 |
+
|
16 |
+
CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
17 |
+
var indentUnit = config.indentUnit;
|
18 |
+
var statementIndent = parserConfig.statementIndent;
|
19 |
+
var jsonldMode = parserConfig.jsonld;
|
20 |
+
var jsonMode = parserConfig.json || jsonldMode;
|
21 |
+
var isTS = parserConfig.typescript;
|
22 |
+
|
23 |
+
// Tokenizer
|
24 |
+
|
25 |
+
var keywords = function(){
|
26 |
+
function kw(type) {return {type: type, style: "keyword"};}
|
27 |
+
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
|
28 |
+
var operator = kw("operator"), atom = {type: "atom", style: "atom"};
|
29 |
+
|
30 |
+
var jsKeywords = {
|
31 |
+
"if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
|
32 |
+
"return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C, "debugger": C,
|
33 |
+
"var": kw("var"), "const": kw("var"), "let": kw("var"),
|
34 |
+
"function": kw("function"), "catch": kw("catch"),
|
35 |
+
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
|
36 |
+
"in": operator, "typeof": operator, "instanceof": operator,
|
37 |
+
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
|
38 |
+
"this": kw("this"), "module": kw("module"), "class": kw("class"), "super": kw("atom"),
|
39 |
+
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C
|
40 |
+
};
|
41 |
+
|
42 |
+
// Extend the 'normal' keywords with the TypeScript language extensions
|
43 |
+
if (isTS) {
|
44 |
+
var type = {type: "variable", style: "variable-3"};
|
45 |
+
var tsKeywords = {
|
46 |
+
// object-like things
|
47 |
+
"interface": kw("interface"),
|
48 |
+
"extends": kw("extends"),
|
49 |
+
"constructor": kw("constructor"),
|
50 |
+
|
51 |
+
// scope modifiers
|
52 |
+
"public": kw("public"),
|
53 |
+
"private": kw("private"),
|
54 |
+
"protected": kw("protected"),
|
55 |
+
"static": kw("static"),
|
56 |
+
|
57 |
+
// types
|
58 |
+
"string": type, "number": type, "bool": type, "any": type
|
59 |
+
};
|
60 |
+
|
61 |
+
for (var attr in tsKeywords) {
|
62 |
+
jsKeywords[attr] = tsKeywords[attr];
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
return jsKeywords;
|
67 |
+
}();
|
68 |
+
|
69 |
+
var isOperatorChar = /[+\-*&%=<>!?|~^]/;
|
70 |
+
var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;
|
71 |
+
|
72 |
+
function readRegexp(stream) {
|
73 |
+
var escaped = false, next, inSet = false;
|
74 |
+
while ((next = stream.next()) != null) {
|
75 |
+
if (!escaped) {
|
76 |
+
if (next == "/" && !inSet) return;
|
77 |
+
if (next == "[") inSet = true;
|
78 |
+
else if (inSet && next == "]") inSet = false;
|
79 |
+
}
|
80 |
+
escaped = !escaped && next == "\\";
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
// Used as scratch variables to communicate multiple values without
|
85 |
+
// consing up tons of objects.
|
86 |
+
var type, content;
|
87 |
+
function ret(tp, style, cont) {
|
88 |
+
type = tp; content = cont;
|
89 |
+
return style;
|
90 |
+
}
|
91 |
+
function tokenBase(stream, state) {
|
92 |
+
var ch = stream.next();
|
93 |
+
if (ch == '"' || ch == "'") {
|
94 |
+
state.tokenize = tokenString(ch);
|
95 |
+
return state.tokenize(stream, state);
|
96 |
+
} else if (ch == "." && stream.match(/^\d+(?:[eE][+\-]?\d+)?/)) {
|
97 |
+
return ret("number", "number");
|
98 |
+
} else if (ch == "." && stream.match("..")) {
|
99 |
+
return ret("spread", "meta");
|
100 |
+
} else if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
101 |
+
return ret(ch);
|
102 |
+
} else if (ch == "=" && stream.eat(">")) {
|
103 |
+
return ret("=>", "operator");
|
104 |
+
} else if (ch == "0" && stream.eat(/x/i)) {
|
105 |
+
stream.eatWhile(/[\da-f]/i);
|
106 |
+
return ret("number", "number");
|
107 |
+
} else if (/\d/.test(ch)) {
|
108 |
+
stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
|
109 |
+
return ret("number", "number");
|
110 |
+
} else if (ch == "/") {
|
111 |
+
if (stream.eat("*")) {
|
112 |
+
state.tokenize = tokenComment;
|
113 |
+
return tokenComment(stream, state);
|
114 |
+
} else if (stream.eat("/")) {
|
115 |
+
stream.skipToEnd();
|
116 |
+
return ret("comment", "comment");
|
117 |
+
} else if (state.lastType == "operator" || state.lastType == "keyword c" ||
|
118 |
+
state.lastType == "sof" || /^[\[{}\(,;:]$/.test(state.lastType)) {
|
119 |
+
readRegexp(stream);
|
120 |
+
stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla
|
121 |
+
return ret("regexp", "string-2");
|
122 |
+
} else {
|
123 |
+
stream.eatWhile(isOperatorChar);
|
124 |
+
return ret("operator", "operator", stream.current());
|
125 |
+
}
|
126 |
+
} else if (ch == "`") {
|
127 |
+
state.tokenize = tokenQuasi;
|
128 |
+
return tokenQuasi(stream, state);
|
129 |
+
} else if (ch == "#") {
|
130 |
+
stream.skipToEnd();
|
131 |
+
return ret("error", "error");
|
132 |
+
} else if (isOperatorChar.test(ch)) {
|
133 |
+
stream.eatWhile(isOperatorChar);
|
134 |
+
return ret("operator", "operator", stream.current());
|
135 |
+
} else {
|
136 |
+
stream.eatWhile(/[\w\$_]/);
|
137 |
+
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
|
138 |
+
return (known && state.lastType != ".") ? ret(known.type, known.style, word) :
|
139 |
+
ret("variable", "variable", word);
|
140 |
+
}
|
141 |
+
}
|
142 |
+
|
143 |
+
function tokenString(quote) {
|
144 |
+
return function(stream, state) {
|
145 |
+
var escaped = false, next;
|
146 |
+
if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){
|
147 |
+
state.tokenize = tokenBase;
|
148 |
+
return ret("jsonld-keyword", "meta");
|
149 |
+
}
|
150 |
+
while ((next = stream.next()) != null) {
|
151 |
+
if (next == quote && !escaped) break;
|
152 |
+
escaped = !escaped && next == "\\";
|
153 |
+
}
|
154 |
+
if (!escaped) state.tokenize = tokenBase;
|
155 |
+
return ret("string", "string");
|
156 |
+
};
|
157 |
+
}
|
158 |
+
|
159 |
+
function tokenComment(stream, state) {
|
160 |
+
var maybeEnd = false, ch;
|
161 |
+
while (ch = stream.next()) {
|
162 |
+
if (ch == "/" && maybeEnd) {
|
163 |
+
state.tokenize = tokenBase;
|
164 |
+
break;
|
165 |
+
}
|
166 |
+
maybeEnd = (ch == "*");
|
167 |
+
}
|
168 |
+
return ret("comment", "comment");
|
169 |
+
}
|
170 |
+
|
171 |
+
function tokenQuasi(stream, state) {
|
172 |
+
var escaped = false, next;
|
173 |
+
while ((next = stream.next()) != null) {
|
174 |
+
if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) {
|
175 |
+
state.tokenize = tokenBase;
|
176 |
+
break;
|
177 |
+
}
|
178 |
+
escaped = !escaped && next == "\\";
|
179 |
+
}
|
180 |
+
return ret("quasi", "string-2", stream.current());
|
181 |
+
}
|
182 |
+
|
183 |
+
var brackets = "([{}])";
|
184 |
+
// This is a crude lookahead trick to try and notice that we're
|
185 |
+
// parsing the argument patterns for a fat-arrow function before we
|
186 |
+
// actually hit the arrow token. It only works if the arrow is on
|
187 |
+
// the same line as the arguments and there's no strange noise
|
188 |
+
// (comments) in between. Fallback is to only notice when we hit the
|
189 |
+
// arrow, and not declare the arguments as locals for the arrow
|
190 |
+
// body.
|
191 |
+
function findFatArrow(stream, state) {
|
192 |
+
if (state.fatArrowAt) state.fatArrowAt = null;
|
193 |
+
var arrow = stream.string.indexOf("=>", stream.start);
|
194 |
+
if (arrow < 0) return;
|
195 |
+
|
196 |
+
var depth = 0, sawSomething = false;
|
197 |
+
for (var pos = arrow - 1; pos >= 0; --pos) {
|
198 |
+
var ch = stream.string.charAt(pos);
|
199 |
+
var bracket = brackets.indexOf(ch);
|
200 |
+
if (bracket >= 0 && bracket < 3) {
|
201 |
+
if (!depth) { ++pos; break; }
|
202 |
+
if (--depth == 0) break;
|
203 |
+
} else if (bracket >= 3 && bracket < 6) {
|
204 |
+
++depth;
|
205 |
+
} else if (/[$\w]/.test(ch)) {
|
206 |
+
sawSomething = true;
|
207 |
+
} else if (sawSomething && !depth) {
|
208 |
+
++pos;
|
209 |
+
break;
|
210 |
+
}
|
211 |
+
}
|
212 |
+
if (sawSomething && !depth) state.fatArrowAt = pos;
|
213 |
+
}
|
214 |
+
|
215 |
+
// Parser
|
216 |
+
|
217 |
+
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true, "jsonld-keyword": true};
|
218 |
+
|
219 |
+
function JSLexical(indented, column, type, align, prev, info) {
|
220 |
+
this.indented = indented;
|
221 |
+
this.column = column;
|
222 |
+
this.type = type;
|
223 |
+
this.prev = prev;
|
224 |
+
this.info = info;
|
225 |
+
if (align != null) this.align = align;
|
226 |
+
}
|
227 |
+
|
228 |
+
function inScope(state, varname) {
|
229 |
+
for (var v = state.localVars; v; v = v.next)
|
230 |
+
if (v.name == varname) return true;
|
231 |
+
for (var cx = state.context; cx; cx = cx.prev) {
|
232 |
+
for (var v = cx.vars; v; v = v.next)
|
233 |
+
if (v.name == varname) return true;
|
234 |
+
}
|
235 |
+
}
|
236 |
+
|
237 |
+
function parseJS(state, style, type, content, stream) {
|
238 |
+
var cc = state.cc;
|
239 |
+
// Communicate our context to the combinators.
|
240 |
+
// (Less wasteful than consing up a hundred closures on every call.)
|
241 |
+
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style;
|
242 |
+
|
243 |
+
if (!state.lexical.hasOwnProperty("align"))
|
244 |
+
state.lexical.align = true;
|
245 |
+
|
246 |
+
while(true) {
|
247 |
+
var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
|
248 |
+
if (combinator(type, content)) {
|
249 |
+
while(cc.length && cc[cc.length - 1].lex)
|
250 |
+
cc.pop()();
|
251 |
+
if (cx.marked) return cx.marked;
|
252 |
+
if (type == "variable" && inScope(state, content)) return "variable-2";
|
253 |
+
return style;
|
254 |
+
}
|
255 |
+
}
|
256 |
+
}
|
257 |
+
|
258 |
+
// Combinator utils
|
259 |
+
|
260 |
+
var cx = {state: null, column: null, marked: null, cc: null};
|
261 |
+
function pass() {
|
262 |
+
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
|
263 |
+
}
|
264 |
+
function cont() {
|
265 |
+
pass.apply(null, arguments);
|
266 |
+
return true;
|
267 |
+
}
|
268 |
+
function register(varname) {
|
269 |
+
function inList(list) {
|
270 |
+
for (var v = list; v; v = v.next)
|
271 |
+
if (v.name == varname) return true;
|
272 |
+
return false;
|
273 |
+
}
|
274 |
+
var state = cx.state;
|
275 |
+
if (state.context) {
|
276 |
+
cx.marked = "def";
|
277 |
+
if (inList(state.localVars)) return;
|
278 |
+
state.localVars = {name: varname, next: state.localVars};
|
279 |
+
} else {
|
280 |
+
if (inList(state.globalVars)) return;
|
281 |
+
if (parserConfig.globalVars)
|
282 |
+
state.globalVars = {name: varname, next: state.globalVars};
|
283 |
+
}
|
284 |
+
}
|
285 |
+
|
286 |
+
// Combinators
|
287 |
+
|
288 |
+
var defaultVars = {name: "this", next: {name: "arguments"}};
|
289 |
+
function pushcontext() {
|
290 |
+
cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
|
291 |
+
cx.state.localVars = defaultVars;
|
292 |
+
}
|
293 |
+
function popcontext() {
|
294 |
+
cx.state.localVars = cx.state.context.vars;
|
295 |
+
cx.state.context = cx.state.context.prev;
|
296 |
+
}
|
297 |
+
function pushlex(type, info) {
|
298 |
+
var result = function() {
|
299 |
+
var state = cx.state, indent = state.indented;
|
300 |
+
if (state.lexical.type == "stat") indent = state.lexical.indented;
|
301 |
+
else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev)
|
302 |
+
indent = outer.indented;
|
303 |
+
state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
|
304 |
+
};
|
305 |
+
result.lex = true;
|
306 |
+
return result;
|
307 |
+
}
|
308 |
+
function poplex() {
|
309 |
+
var state = cx.state;
|
310 |
+
if (state.lexical.prev) {
|
311 |
+
if (state.lexical.type == ")")
|
312 |
+
state.indented = state.lexical.indented;
|
313 |
+
state.lexical = state.lexical.prev;
|
314 |
+
}
|
315 |
+
}
|
316 |
+
poplex.lex = true;
|
317 |
+
|
318 |
+
function expect(wanted) {
|
319 |
+
function exp(type) {
|
320 |
+
if (type == wanted) return cont();
|
321 |
+
else if (wanted == ";") return pass();
|
322 |
+
else return cont(exp);
|
323 |
+
};
|
324 |
+
return exp;
|
325 |
+
}
|
326 |
+
|
327 |
+
function statement(type, value) {
|
328 |
+
if (type == "var") return cont(pushlex("vardef", value.length), vardef, expect(";"), poplex);
|
329 |
+
if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex);
|
330 |
+
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
|
331 |
+
if (type == "{") return cont(pushlex("}"), block, poplex);
|
332 |
+
if (type == ";") return cont();
|
333 |
+
if (type == "if") {
|
334 |
+
if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
|
335 |
+
cx.state.cc.pop()();
|
336 |
+
return cont(pushlex("form"), expression, statement, poplex, maybeelse);
|
337 |
+
}
|
338 |
+
if (type == "function") return cont(functiondef);
|
339 |
+
if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
|
340 |
+
if (type == "variable") return cont(pushlex("stat"), maybelabel);
|
341 |
+
if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"),
|
342 |
+
block, poplex, poplex);
|
343 |
+
if (type == "case") return cont(expression, expect(":"));
|
344 |
+
if (type == "default") return cont(expect(":"));
|
345 |
+
if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
|
346 |
+
statement, poplex, popcontext);
|
347 |
+
if (type == "module") return cont(pushlex("form"), pushcontext, afterModule, popcontext, poplex);
|
348 |
+
if (type == "class") return cont(pushlex("form"), className, poplex);
|
349 |
+
if (type == "export") return cont(pushlex("form"), afterExport, poplex);
|
350 |
+
if (type == "import") return cont(pushlex("form"), afterImport, poplex);
|
351 |
+
return pass(pushlex("stat"), expression, expect(";"), poplex);
|
352 |
+
}
|
353 |
+
function expression(type) {
|
354 |
+
return expressionInner(type, false);
|
355 |
+
}
|
356 |
+
function expressionNoComma(type) {
|
357 |
+
return expressionInner(type, true);
|
358 |
+
}
|
359 |
+
function expressionInner(type, noComma) {
|
360 |
+
if (cx.state.fatArrowAt == cx.stream.start) {
|
361 |
+
var body = noComma ? arrowBodyNoComma : arrowBody;
|
362 |
+
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(pattern, ")"), poplex, expect("=>"), body, popcontext);
|
363 |
+
else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
|
364 |
+
}
|
365 |
+
|
366 |
+
var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
|
367 |
+
if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
|
368 |
+
if (type == "function") return cont(functiondef, maybeop);
|
369 |
+
if (type == "keyword c") return cont(noComma ? maybeexpressionNoComma : maybeexpression);
|
370 |
+
if (type == "(") return cont(pushlex(")"), maybeexpression, comprehension, expect(")"), poplex, maybeop);
|
371 |
+
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
|
372 |
+
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
|
373 |
+
if (type == "{") return contCommasep(objprop, "}", null, maybeop);
|
374 |
+
if (type == "quasi") { return pass(quasi, maybeop); }
|
375 |
+
return cont();
|
376 |
+
}
|
377 |
+
function maybeexpression(type) {
|
378 |
+
if (type.match(/[;\}\)\],]/)) return pass();
|
379 |
+
return pass(expression);
|
380 |
+
}
|
381 |
+
function maybeexpressionNoComma(type) {
|
382 |
+
if (type.match(/[;\}\)\],]/)) return pass();
|
383 |
+
return pass(expressionNoComma);
|
384 |
+
}
|
385 |
+
|
386 |
+
function maybeoperatorComma(type, value) {
|
387 |
+
if (type == ",") return cont(expression);
|
388 |
+
return maybeoperatorNoComma(type, value, false);
|
389 |
+
}
|
390 |
+
function maybeoperatorNoComma(type, value, noComma) {
|
391 |
+
var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma;
|
392 |
+
var expr = noComma == false ? expression : expressionNoComma;
|
393 |
+
if (value == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
|
394 |
+
if (type == "operator") {
|
395 |
+
if (/\+\+|--/.test(value)) return cont(me);
|
396 |
+
if (value == "?") return cont(expression, expect(":"), expr);
|
397 |
+
return cont(expr);
|
398 |
+
}
|
399 |
+
if (type == "quasi") { return pass(quasi, me); }
|
400 |
+
if (type == ";") return;
|
401 |
+
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
|
402 |
+
if (type == ".") return cont(property, me);
|
403 |
+
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
|
404 |
+
}
|
405 |
+
function quasi(type, value) {
|
406 |
+
if (type != "quasi") return pass();
|
407 |
+
if (value.slice(value.length - 2) != "${") return cont(quasi);
|
408 |
+
return cont(expression, continueQuasi);
|
409 |
+
}
|
410 |
+
function continueQuasi(type) {
|
411 |
+
if (type == "}") {
|
412 |
+
cx.marked = "string-2";
|
413 |
+
cx.state.tokenize = tokenQuasi;
|
414 |
+
return cont(quasi);
|
415 |
+
}
|
416 |
+
}
|
417 |
+
function arrowBody(type) {
|
418 |
+
findFatArrow(cx.stream, cx.state);
|
419 |
+
if (type == "{") return pass(statement);
|
420 |
+
return pass(expression);
|
421 |
+
}
|
422 |
+
function arrowBodyNoComma(type) {
|
423 |
+
findFatArrow(cx.stream, cx.state);
|
424 |
+
if (type == "{") return pass(statement);
|
425 |
+
return pass(expressionNoComma);
|
426 |
+
}
|
427 |
+
function maybelabel(type) {
|
428 |
+
if (type == ":") return cont(poplex, statement);
|
429 |
+
return pass(maybeoperatorComma, expect(";"), poplex);
|
430 |
+
}
|
431 |
+
function property(type) {
|
432 |
+
if (type == "variable") {cx.marked = "property"; return cont();}
|
433 |
+
}
|
434 |
+
function objprop(type, value) {
|
435 |
+
if (type == "variable" || cx.style == "keyword") {
|
436 |
+
cx.marked = "property";
|
437 |
+
if (value == "get" || value == "set") return cont(getterSetter);
|
438 |
+
return cont(afterprop);
|
439 |
+
} else if (type == "number" || type == "string") {
|
440 |
+
cx.marked = jsonldMode ? "property" : (cx.style + " property");
|
441 |
+
return cont(afterprop);
|
442 |
+
} else if (type == "jsonld-keyword") {
|
443 |
+
return cont(afterprop);
|
444 |
+
} else if (type == "[") {
|
445 |
+
return cont(expression, expect("]"), afterprop);
|
446 |
+
}
|
447 |
+
}
|
448 |
+
function getterSetter(type) {
|
449 |
+
if (type != "variable") return pass(afterprop);
|
450 |
+
cx.marked = "property";
|
451 |
+
return cont(functiondef);
|
452 |
+
}
|
453 |
+
function afterprop(type) {
|
454 |
+
if (type == ":") return cont(expressionNoComma);
|
455 |
+
if (type == "(") return pass(functiondef);
|
456 |
+
}
|
457 |
+
function commasep(what, end) {
|
458 |
+
function proceed(type) {
|
459 |
+
if (type == ",") {
|
460 |
+
var lex = cx.state.lexical;
|
461 |
+
if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
|
462 |
+
return cont(what, proceed);
|
463 |
+
}
|
464 |
+
if (type == end) return cont();
|
465 |
+
return cont(expect(end));
|
466 |
+
}
|
467 |
+
return function(type) {
|
468 |
+
if (type == end) return cont();
|
469 |
+
return pass(what, proceed);
|
470 |
+
};
|
471 |
+
}
|
472 |
+
function contCommasep(what, end, info) {
|
473 |
+
for (var i = 3; i < arguments.length; i++)
|
474 |
+
cx.cc.push(arguments[i]);
|
475 |
+
return cont(pushlex(end, info), commasep(what, end), poplex);
|
476 |
+
}
|
477 |
+
function block(type) {
|
478 |
+
if (type == "}") return cont();
|
479 |
+
return pass(statement, block);
|
480 |
+
}
|
481 |
+
function maybetype(type) {
|
482 |
+
if (isTS && type == ":") return cont(typedef);
|
483 |
+
}
|
484 |
+
function typedef(type) {
|
485 |
+
if (type == "variable"){cx.marked = "variable-3"; return cont();}
|
486 |
+
}
|
487 |
+
function vardef() {
|
488 |
+
return pass(pattern, maybetype, maybeAssign, vardefCont);
|
489 |
+
}
|
490 |
+
function pattern(type, value) {
|
491 |
+
if (type == "variable") { register(value); return cont(); }
|
492 |
+
if (type == "[") return contCommasep(pattern, "]");
|
493 |
+
if (type == "{") return contCommasep(proppattern, "}");
|
494 |
+
}
|
495 |
+
function proppattern(type, value) {
|
496 |
+
if (type == "variable" && !cx.stream.match(/^\s*:/, false)) {
|
497 |
+
register(value);
|
498 |
+
return cont(maybeAssign);
|
499 |
+
}
|
500 |
+
if (type == "variable") cx.marked = "property";
|
501 |
+
return cont(expect(":"), pattern, maybeAssign);
|
502 |
+
}
|
503 |
+
function maybeAssign(_type, value) {
|
504 |
+
if (value == "=") return cont(expressionNoComma);
|
505 |
+
}
|
506 |
+
function vardefCont(type) {
|
507 |
+
if (type == ",") return cont(vardef);
|
508 |
+
}
|
509 |
+
function maybeelse(type, value) {
|
510 |
+
if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
|
511 |
+
}
|
512 |
+
function forspec(type) {
|
513 |
+
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
|
514 |
+
}
|
515 |
+
function forspec1(type) {
|
516 |
+
if (type == "var") return cont(vardef, expect(";"), forspec2);
|
517 |
+
if (type == ";") return cont(forspec2);
|
518 |
+
if (type == "variable") return cont(formaybeinof);
|
519 |
+
return pass(expression, expect(";"), forspec2);
|
520 |
+
}
|
521 |
+
function formaybeinof(_type, value) {
|
522 |
+
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
|
523 |
+
return cont(maybeoperatorComma, forspec2);
|
524 |
+
}
|
525 |
+
function forspec2(type, value) {
|
526 |
+
if (type == ";") return cont(forspec3);
|
527 |
+
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
|
528 |
+
return pass(expression, expect(";"), forspec3);
|
529 |
+
}
|
530 |
+
function forspec3(type) {
|
531 |
+
if (type != ")") cont(expression);
|
532 |
+
}
|
533 |
+
function functiondef(type, value) {
|
534 |
+
if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
|
535 |
+
if (type == "variable") {register(value); return cont(functiondef);}
|
536 |
+
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, statement, popcontext);
|
537 |
+
}
|
538 |
+
function funarg(type) {
|
539 |
+
if (type == "spread") return cont(funarg);
|
540 |
+
return pass(pattern, maybetype);
|
541 |
+
}
|
542 |
+
function className(type, value) {
|
543 |
+
if (type == "variable") {register(value); return cont(classNameAfter);}
|
544 |
+
}
|
545 |
+
function classNameAfter(type, value) {
|
546 |
+
if (value == "extends") return cont(expression, classNameAfter);
|
547 |
+
if (type == "{") return cont(pushlex("}"), classBody, poplex);
|
548 |
+
}
|
549 |
+
function classBody(type, value) {
|
550 |
+
if (type == "variable" || cx.style == "keyword") {
|
551 |
+
cx.marked = "property";
|
552 |
+
if (value == "get" || value == "set") return cont(classGetterSetter, functiondef, classBody);
|
553 |
+
return cont(functiondef, classBody);
|
554 |
+
}
|
555 |
+
if (value == "*") {
|
556 |
+
cx.marked = "keyword";
|
557 |
+
return cont(classBody);
|
558 |
+
}
|
559 |
+
if (type == ";") return cont(classBody);
|
560 |
+
if (type == "}") return cont();
|
561 |
+
}
|
562 |
+
function classGetterSetter(type) {
|
563 |
+
if (type != "variable") return pass();
|
564 |
+
cx.marked = "property";
|
565 |
+
return cont();
|
566 |
+
}
|
567 |
+
function afterModule(type, value) {
|
568 |
+
if (type == "string") return cont(statement);
|
569 |
+
if (type == "variable") { register(value); return cont(maybeFrom); }
|
570 |
+
}
|
571 |
+
function afterExport(_type, value) {
|
572 |
+
if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
|
573 |
+
if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
|
574 |
+
return pass(statement);
|
575 |
+
}
|
576 |
+
function afterImport(type) {
|
577 |
+
if (type == "string") return cont();
|
578 |
+
return pass(importSpec, maybeFrom);
|
579 |
+
}
|
580 |
+
function importSpec(type, value) {
|
581 |
+
if (type == "{") return contCommasep(importSpec, "}");
|
582 |
+
if (type == "variable") register(value);
|
583 |
+
return cont();
|
584 |
+
}
|
585 |
+
function maybeFrom(_type, value) {
|
586 |
+
if (value == "from") { cx.marked = "keyword"; return cont(expression); }
|
587 |
+
}
|
588 |
+
function arrayLiteral(type) {
|
589 |
+
if (type == "]") return cont();
|
590 |
+
return pass(expressionNoComma, maybeArrayComprehension);
|
591 |
+
}
|
592 |
+
function maybeArrayComprehension(type) {
|
593 |
+
if (type == "for") return pass(comprehension, expect("]"));
|
594 |
+
if (type == ",") return cont(commasep(expressionNoComma, "]"));
|
595 |
+
return pass(commasep(expressionNoComma, "]"));
|
596 |
+
}
|
597 |
+
function comprehension(type) {
|
598 |
+
if (type == "for") return cont(forspec, comprehension);
|
599 |
+
if (type == "if") return cont(expression, comprehension);
|
600 |
+
}
|
601 |
+
|
602 |
+
// Interface
|
603 |
+
|
604 |
+
return {
|
605 |
+
startState: function(basecolumn) {
|
606 |
+
var state = {
|
607 |
+
tokenize: tokenBase,
|
608 |
+
lastType: "sof",
|
609 |
+
cc: [],
|
610 |
+
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
|
611 |
+
localVars: parserConfig.localVars,
|
612 |
+
context: parserConfig.localVars && {vars: parserConfig.localVars},
|
613 |
+
indented: 0
|
614 |
+
};
|
615 |
+
if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
|
616 |
+
state.globalVars = parserConfig.globalVars;
|
617 |
+
return state;
|
618 |
+
},
|
619 |
+
|
620 |
+
token: function(stream, state) {
|
621 |
+
if (stream.sol()) {
|
622 |
+
if (!state.lexical.hasOwnProperty("align"))
|
623 |
+
state.lexical.align = false;
|
624 |
+
state.indented = stream.indentation();
|
625 |
+
findFatArrow(stream, state);
|
626 |
+
}
|
627 |
+
if (state.tokenize != tokenComment && stream.eatSpace()) return null;
|
628 |
+
var style = state.tokenize(stream, state);
|
629 |
+
if (type == "comment") return style;
|
630 |
+
state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type;
|
631 |
+
return parseJS(state, style, type, content, stream);
|
632 |
+
},
|
633 |
+
|
634 |
+
indent: function(state, textAfter) {
|
635 |
+
if (state.tokenize == tokenComment) return CodeMirror.Pass;
|
636 |
+
if (state.tokenize != tokenBase) return 0;
|
637 |
+
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical;
|
638 |
+
// Kludge to prevent 'maybelse' from blocking lexical scope pops
|
639 |
+
if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
|
640 |
+
var c = state.cc[i];
|
641 |
+
if (c == poplex) lexical = lexical.prev;
|
642 |
+
else if (c != maybeelse) break;
|
643 |
+
}
|
644 |
+
if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev;
|
645 |
+
if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat")
|
646 |
+
lexical = lexical.prev;
|
647 |
+
var type = lexical.type, closing = firstChar == type;
|
648 |
+
|
649 |
+
if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info + 1 : 0);
|
650 |
+
else if (type == "form" && firstChar == "{") return lexical.indented;
|
651 |
+
else if (type == "form") return lexical.indented + indentUnit;
|
652 |
+
else if (type == "stat")
|
653 |
+
return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? statementIndent || indentUnit : 0);
|
654 |
+
else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false)
|
655 |
+
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
|
656 |
+
else if (lexical.align) return lexical.column + (closing ? 0 : 1);
|
657 |
+
else return lexical.indented + (closing ? 0 : indentUnit);
|
658 |
+
},
|
659 |
+
|
660 |
+
electricChars: ":{}",
|
661 |
+
blockCommentStart: jsonMode ? null : "/*",
|
662 |
+
blockCommentEnd: jsonMode ? null : "*/",
|
663 |
+
lineComment: jsonMode ? null : "//",
|
664 |
+
fold: "brace",
|
665 |
+
|
666 |
+
helperType: jsonMode ? "json" : "javascript",
|
667 |
+
jsonldMode: jsonldMode,
|
668 |
+
jsonMode: jsonMode
|
669 |
+
};
|
670 |
+
});
|
671 |
+
|
672 |
+
CodeMirror.registerHelper("wordChars", "javascript", /[\\w$]/);
|
673 |
+
|
674 |
+
CodeMirror.defineMIME("text/javascript", "javascript");
|
675 |
+
CodeMirror.defineMIME("text/ecmascript", "javascript");
|
676 |
+
CodeMirror.defineMIME("application/javascript", "javascript");
|
677 |
+
CodeMirror.defineMIME("application/x-javascript", "javascript");
|
678 |
+
CodeMirror.defineMIME("application/ecmascript", "javascript");
|
679 |
+
CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
|
680 |
+
CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true});
|
681 |
+
CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true});
|
682 |
+
CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
|
683 |
+
CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
|
684 |
+
|
685 |
+
});
|
admin/codemirror/mode/javascript/json-ld.html
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
|
3 |
+
<title>CodeMirror: JSON-LD mode</title>
|
4 |
+
<meta charset="utf-8"/>
|
5 |
+
<link rel=stylesheet href="../../doc/docs.css">
|
6 |
+
|
7 |
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
8 |
+
<script src="../../lib/codemirror.js"></script>
|
9 |
+
<script src="../../addon/edit/matchbrackets.js"></script>
|
10 |
+
<script src="../../addon/comment/continuecomment.js"></script>
|
11 |
+
<script src="../../addon/comment/comment.js"></script>
|
12 |
+
<script src="javascript.js"></script>
|
13 |
+
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
14 |
+
<div id="nav">
|
15 |
+
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"/></a>
|
16 |
+
|
17 |
+
<ul>
|
18 |
+
<li><a href="../../index.html">Home</a>
|
19 |
+
<li><a href="../../doc/manual.html">Manual</a>
|
20 |
+
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
21 |
+
</ul>
|
22 |
+
<ul>
|
23 |
+
<li><a href="../index.html">Language modes</a>
|
24 |
+
<li><a class=active href="#">JSON-LD</a>
|
25 |
+
</ul>
|
26 |
+
</div>
|
27 |
+
|
28 |
+
<article>
|
29 |
+
<h2>JSON-LD mode</h2>
|
30 |
+
|
31 |
+
|
32 |
+
<div><textarea id="code" name="code">
|
33 |
+
{
|
34 |
+
"@context": {
|
35 |
+
"name": "http://schema.org/name",
|
36 |
+
"description": "http://schema.org/description",
|
37 |
+
"image": {
|
38 |
+
"@id": "http://schema.org/image",
|
39 |
+
"@type": "@id"
|
40 |
+
},
|
41 |
+
"geo": "http://schema.org/geo",
|
42 |
+
"latitude": {
|
43 |
+
"@id": "http://schema.org/latitude",
|
44 |
+
"@type": "xsd:float"
|
45 |
+
},
|
46 |
+
"longitude": {
|
47 |
+
"@id": "http://schema.org/longitude",
|
48 |
+
"@type": "xsd:float"
|
49 |
+
},
|
50 |
+
"xsd": "http://www.w3.org/2001/XMLSchema#"
|
51 |
+
},
|
52 |
+
"name": "The Empire State Building",
|
53 |
+
"description": "The Empire State Building is a 102-story landmark in New York City.",
|
54 |
+
"image": "http://www.civil.usherbrooke.ca/cours/gci215a/empire-state-building.jpg",
|
55 |
+
"geo": {
|
56 |
+
"latitude": "40.75",
|
57 |
+
"longitude": "73.98"
|
58 |
+
}
|
59 |
+
}
|
60 |
+
</textarea></div>
|
61 |
+
|
62 |
+
<script>
|
63 |
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
64 |
+
matchBrackets: true,
|
65 |
+
autoCloseBrackets: true,
|
66 |
+
mode: "application/ld+json",
|
67 |
+
lineWrapping: true
|
68 |
+
});
|
69 |
+
</script>
|
70 |
+
|
71 |
+
<p>This is a specialization of the <a href="index.html">JavaScript mode</a>.</p>
|
72 |
+
</article>
|
admin/codemirror/mode/javascript/test.js
ADDED
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function() {
|
5 |
+
var mode = CodeMirror.getMode({indentUnit: 2}, "javascript");
|
6 |
+
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
|
7 |
+
|
8 |
+
MT("locals",
|
9 |
+
"[keyword function] [variable foo]([def a], [def b]) { [keyword var] [def c] [operator =] [number 10]; [keyword return] [variable-2 a] [operator +] [variable-2 c] [operator +] [variable d]; }");
|
10 |
+
|
11 |
+
MT("comma-and-binop",
|
12 |
+
"[keyword function](){ [keyword var] [def x] [operator =] [number 1] [operator +] [number 2], [def y]; }");
|
13 |
+
|
14 |
+
MT("destructuring",
|
15 |
+
"([keyword function]([def a], [[[def b], [def c] ]]) {",
|
16 |
+
" [keyword let] {[def d], [property foo]: [def c][operator =][number 10], [def x]} [operator =] [variable foo]([variable-2 a]);",
|
17 |
+
" [[[variable-2 c], [variable y] ]] [operator =] [variable-2 c];",
|
18 |
+
"})();");
|
19 |
+
|
20 |
+
MT("class_body",
|
21 |
+
"[keyword class] [variable Foo] {",
|
22 |
+
" [property constructor]() {}",
|
23 |
+
" [property sayName]() {",
|
24 |
+
" [keyword return] [string-2 `foo${][variable foo][string-2 }oo`];",
|
25 |
+
" }",
|
26 |
+
"}");
|
27 |
+
|
28 |
+
MT("class",
|
29 |
+
"[keyword class] [variable Point] [keyword extends] [variable SuperThing] {",
|
30 |
+
" [property get] [property prop]() { [keyword return] [number 24]; }",
|
31 |
+
" [property constructor]([def x], [def y]) {",
|
32 |
+
" [keyword super]([string 'something']);",
|
33 |
+
" [keyword this].[property x] [operator =] [variable-2 x];",
|
34 |
+
" }",
|
35 |
+
"}");
|
36 |
+
|
37 |
+
MT("module",
|
38 |
+
"[keyword module] [string 'foo'] {",
|
39 |
+
" [keyword export] [keyword let] [def x] [operator =] [number 42];",
|
40 |
+
" [keyword export] [keyword *] [keyword from] [string 'somewhere'];",
|
41 |
+
"}");
|
42 |
+
|
43 |
+
MT("import",
|
44 |
+
"[keyword function] [variable foo]() {",
|
45 |
+
" [keyword import] [def $] [keyword from] [string 'jquery'];",
|
46 |
+
" [keyword module] [def crypto] [keyword from] [string 'crypto'];",
|
47 |
+
" [keyword import] { [def encrypt], [def decrypt] } [keyword from] [string 'crypto'];",
|
48 |
+
"}");
|
49 |
+
|
50 |
+
MT("const",
|
51 |
+
"[keyword function] [variable f]() {",
|
52 |
+
" [keyword const] [[ [def a], [def b] ]] [operator =] [[ [number 1], [number 2] ]];",
|
53 |
+
"}");
|
54 |
+
|
55 |
+
MT("for/of",
|
56 |
+
"[keyword for]([keyword let] [variable of] [keyword of] [variable something]) {}");
|
57 |
+
|
58 |
+
MT("generator",
|
59 |
+
"[keyword function*] [variable repeat]([def n]) {",
|
60 |
+
" [keyword for]([keyword var] [def i] [operator =] [number 0]; [variable-2 i] [operator <] [variable-2 n]; [operator ++][variable-2 i])",
|
61 |
+
" [keyword yield] [variable-2 i];",
|
62 |
+
"}");
|
63 |
+
|
64 |
+
MT("fatArrow",
|
65 |
+
"[variable array].[property filter]([def a] [operator =>] [variable-2 a] [operator +] [number 1]);",
|
66 |
+
"[variable a];", // No longer in scope
|
67 |
+
"[keyword let] [variable f] [operator =] ([[ [def a], [def b] ]], [def c]) [operator =>] [variable-2 a] [operator +] [variable-2 c];",
|
68 |
+
"[variable c];");
|
69 |
+
|
70 |
+
MT("spread",
|
71 |
+
"[keyword function] [variable f]([def a], [meta ...][def b]) {",
|
72 |
+
" [variable something]([variable-2 a], [meta ...][variable-2 b]);",
|
73 |
+
"}");
|
74 |
+
|
75 |
+
MT("comprehension",
|
76 |
+
"[keyword function] [variable f]() {",
|
77 |
+
" [[([variable x] [operator +] [number 1]) [keyword for] ([keyword var] [def x] [keyword in] [variable y]) [keyword if] [variable pred]([variable-2 x]) ]];",
|
78 |
+
" ([variable u] [keyword for] ([keyword var] [def u] [keyword of] [variable generateValues]()) [keyword if] ([variable-2 u].[property color] [operator ===] [string 'blue']));",
|
79 |
+
"}");
|
80 |
+
|
81 |
+
MT("quasi",
|
82 |
+
"[variable re][string-2 `fofdlakj${][variable x] [operator +] ([variable re][string-2 `foo`]) [operator +] [number 1][string-2 }fdsa`] [operator +] [number 2]");
|
83 |
+
|
84 |
+
MT("quasi_no_function",
|
85 |
+
"[variable x] [operator =] [string-2 `fofdlakj${][variable x] [operator +] [string-2 `foo`] [operator +] [number 1][string-2 }fdsa`] [operator +] [number 2]");
|
86 |
+
|
87 |
+
MT("indent_statement",
|
88 |
+
"[keyword var] [variable x] [operator =] [number 10]",
|
89 |
+
"[variable x] [operator +=] [variable y] [operator +]",
|
90 |
+
" [atom Infinity]",
|
91 |
+
"[keyword debugger];");
|
92 |
+
|
93 |
+
MT("indent_if",
|
94 |
+
"[keyword if] ([number 1])",
|
95 |
+
" [keyword break];",
|
96 |
+
"[keyword else] [keyword if] ([number 2])",
|
97 |
+
" [keyword continue];",
|
98 |
+
"[keyword else]",
|
99 |
+
" [number 10];",
|
100 |
+
"[keyword if] ([number 1]) {",
|
101 |
+
" [keyword break];",
|
102 |
+
"} [keyword else] [keyword if] ([number 2]) {",
|
103 |
+
" [keyword continue];",
|
104 |
+
"} [keyword else] {",
|
105 |
+
" [number 10];",
|
106 |
+
"}");
|
107 |
+
|
108 |
+
MT("indent_for",
|
109 |
+
"[keyword for] ([keyword var] [variable i] [operator =] [number 0];",
|
110 |
+
" [variable i] [operator <] [number 100];",
|
111 |
+
" [variable i][operator ++])",
|
112 |
+
" [variable doSomething]([variable i]);",
|
113 |
+
"[keyword debugger];");
|
114 |
+
|
115 |
+
MT("indent_c_style",
|
116 |
+
"[keyword function] [variable foo]()",
|
117 |
+
"{",
|
118 |
+
" [keyword debugger];",
|
119 |
+
"}");
|
120 |
+
|
121 |
+
MT("indent_else",
|
122 |
+
"[keyword for] (;;)",
|
123 |
+
" [keyword if] ([variable foo])",
|
124 |
+
" [keyword if] ([variable bar])",
|
125 |
+
" [number 1];",
|
126 |
+
" [keyword else]",
|
127 |
+
" [number 2];",
|
128 |
+
" [keyword else]",
|
129 |
+
" [number 3];");
|
130 |
+
|
131 |
+
MT("indent_funarg",
|
132 |
+
"[variable foo]([number 10000],",
|
133 |
+
" [keyword function]([def a]) {",
|
134 |
+
" [keyword debugger];",
|
135 |
+
"};");
|
136 |
+
|
137 |
+
MT("indent_below_if",
|
138 |
+
"[keyword for] (;;)",
|
139 |
+
" [keyword if] ([variable foo])",
|
140 |
+
" [number 1];",
|
141 |
+
"[number 2];");
|
142 |
+
|
143 |
+
MT("multilinestring",
|
144 |
+
"[keyword var] [variable x] [operator =] [string 'foo\\]",
|
145 |
+
"[string bar'];");
|
146 |
+
|
147 |
+
MT("scary_regexp",
|
148 |
+
"[string-2 /foo[[/]]bar/];");
|
149 |
+
|
150 |
+
var jsonld_mode = CodeMirror.getMode(
|
151 |
+
{indentUnit: 2},
|
152 |
+
{name: "javascript", jsonld: true}
|
153 |
+
);
|
154 |
+
function LD(name) {
|
155 |
+
test.mode(name, jsonld_mode, Array.prototype.slice.call(arguments, 1));
|
156 |
+
}
|
157 |
+
|
158 |
+
LD("json_ld_keywords",
|
159 |
+
'{',
|
160 |
+
' [meta "@context"]: {',
|
161 |
+
' [meta "@base"]: [string "http://example.com"],',
|
162 |
+
' [meta "@vocab"]: [string "http://xmlns.com/foaf/0.1/"],',
|
163 |
+
' [property "likesFlavor"]: {',
|
164 |
+
' [meta "@container"]: [meta "@list"]',
|
165 |
+
' [meta "@reverse"]: [string "@beFavoriteOf"]',
|
166 |
+
' },',
|
167 |
+
' [property "nick"]: { [meta "@container"]: [meta "@set"] },',
|
168 |
+
' [property "nick"]: { [meta "@container"]: [meta "@index"] }',
|
169 |
+
' },',
|
170 |
+
' [meta "@graph"]: [[ {',
|
171 |
+
' [meta "@id"]: [string "http://dbpedia.org/resource/John_Lennon"],',
|
172 |
+
' [property "name"]: [string "John Lennon"],',
|
173 |
+
' [property "modified"]: {',
|
174 |
+
' [meta "@value"]: [string "2010-05-29T14:17:39+02:00"],',
|
175 |
+
' [meta "@type"]: [string "http://www.w3.org/2001/XMLSchema#dateTime"]',
|
176 |
+
' }',
|
177 |
+
' } ]]',
|
178 |
+
'}');
|
179 |
+
|
180 |
+
LD("json_ld_fake",
|
181 |
+
'{',
|
182 |
+
' [property "@fake"]: [string "@fake"],',
|
183 |
+
' [property "@contextual"]: [string "@identifier"],',
|
184 |
+
' [property "user@domain.com"]: [string "@graphical"],',
|
185 |
+
' [property "@ID"]: [string "@@ID"]',
|
186 |
+
'}');
|
187 |
+
})();
|
admin/codemirror/mode/javascript/typescript.html
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
|
3 |
+
<title>CodeMirror: TypeScript mode</title>
|
4 |
+
<meta charset="utf-8"/>
|
5 |
+
<link rel=stylesheet href="../../doc/docs.css">
|
6 |
+
|
7 |
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
8 |
+
<script src="../../lib/codemirror.js"></script>
|
9 |
+
<script src="javascript.js"></script>
|
10 |
+
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
11 |
+
<div id=nav>
|
12 |
+
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
|
13 |
+
|
14 |
+
<ul>
|
15 |
+
<li><a href="../../index.html">Home</a>
|
16 |
+
<li><a href="../../doc/manual.html">Manual</a>
|
17 |
+
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
18 |
+
</ul>
|
19 |
+
<ul>
|
20 |
+
<li><a href="../index.html">Language modes</a>
|
21 |
+
<li><a class=active href="#">TypeScript</a>
|
22 |
+
</ul>
|
23 |
+
</div>
|
24 |
+
|
25 |
+
<article>
|
26 |
+
<h2>TypeScript mode</h2>
|
27 |
+
|
28 |
+
|
29 |
+
<div><textarea id="code" name="code">
|
30 |
+
class Greeter {
|
31 |
+
greeting: string;
|
32 |
+
constructor (message: string) {
|
33 |
+
this.greeting = message;
|
34 |
+
}
|
35 |
+
greet() {
|
36 |
+
return "Hello, " + this.greeting;
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
var greeter = new Greeter("world");
|
41 |
+
|
42 |
+
var button = document.createElement('button')
|
43 |
+
button.innerText = "Say Hello"
|
44 |
+
button.onclick = function() {
|
45 |
+
alert(greeter.greet())
|
46 |
+
}
|
47 |
+
|
48 |
+
document.body.appendChild(button)
|
49 |
+
|
50 |
+
</textarea></div>
|
51 |
+
|
52 |
+
<script>
|
53 |
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
54 |
+
lineNumbers: true,
|
55 |
+
matchBrackets: true,
|
56 |
+
mode: "text/typescript"
|
57 |
+
});
|
58 |
+
</script>
|
59 |
+
|
60 |
+
<p>This is a specialization of the <a href="index.html">JavaScript mode</a>.</p>
|
61 |
+
</article>
|
admin/codemirror/mode/php/index.html
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
|
3 |
+
<title>CodeMirror: PHP mode</title>
|
4 |
+
<meta charset="utf-8"/>
|
5 |
+
<link rel=stylesheet href="../../doc/docs.css">
|
6 |
+
|
7 |
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
8 |
+
<script src="../../lib/codemirror.js"></script>
|
9 |
+
<script src="../../addon/edit/matchbrackets.js"></script>
|
10 |
+
<script src="../htmlmixed/htmlmixed.js"></script>
|
11 |
+
<script src="../xml/xml.js"></script>
|
12 |
+
<script src="../javascript/javascript.js"></script>
|
13 |
+
<script src="../css/css.js"></script>
|
14 |
+
<script src="../clike/clike.js"></script>
|
15 |
+
<script src="php.js"></script>
|
16 |
+
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
17 |
+
<div id=nav>
|
18 |
+
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
|
19 |
+
|
20 |
+
<ul>
|
21 |
+
<li><a href="../../index.html">Home</a>
|
22 |
+
<li><a href="../../doc/manual.html">Manual</a>
|
23 |
+
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
24 |
+
</ul>
|
25 |
+
<ul>
|
26 |
+
<li><a href="../index.html">Language modes</a>
|
27 |
+
<li><a class=active href="#">PHP</a>
|
28 |
+
</ul>
|
29 |
+
</div>
|
30 |
+
|
31 |
+
<article>
|
32 |
+
<h2>PHP mode</h2>
|
33 |
+
<form><textarea id="code" name="code">
|
34 |
+
<?php
|
35 |
+
$a = array('a' => 1, 'b' => 2, 3 => 'c');
|
36 |
+
|
37 |
+
echo "$a[a] ${a[3] /* } comment */} {$a[b]} \$a[a]";
|
38 |
+
|
39 |
+
function hello($who) {
|
40 |
+
return "Hello $who!";
|
41 |
+
}
|
42 |
+
?>
|
43 |
+
<p>The program says <?= hello("World") ?>.</p>
|
44 |
+
<script>
|
45 |
+
alert("And here is some JS code"); // also colored
|
46 |
+
</script>
|
47 |
+
</textarea></form>
|
48 |
+
|
49 |
+
<script>
|
50 |
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
51 |
+
lineNumbers: true,
|
52 |
+
matchBrackets: true,
|
53 |
+
mode: "application/x-httpd-php",
|
54 |
+
indentUnit: 4,
|
55 |
+
indentWithTabs: true
|
56 |
+
});
|
57 |
+
</script>
|
58 |
+
|
59 |
+
<p>Simple HTML/PHP mode based on
|
60 |
+
the <a href="../clike/">C-like</a> mode. Depends on XML,
|
61 |
+
JavaScript, CSS, HTMLMixed, and C-like modes.</p>
|
62 |
+
|
63 |
+
<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>
|
64 |
+
</article>
|
admin/codemirror/mode/php/php.js
ADDED
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function(mod) {
|
5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6 |
+
mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"), require("../clike/clike"));
|
7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
8 |
+
define(["../../lib/codemirror", "../htmlmixed/htmlmixed", "../clike/clike"], mod);
|
9 |
+
else // Plain browser env
|
10 |
+
mod(CodeMirror);
|
11 |
+
})(function(CodeMirror) {
|
12 |
+
"use strict";
|
13 |
+
|
14 |
+
function keywords(str) {
|
15 |
+
var obj = {}, words = str.split(" ");
|
16 |
+
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
17 |
+
return obj;
|
18 |
+
}
|
19 |
+
function heredoc(delim) {
|
20 |
+
return function(stream, state) {
|
21 |
+
if (stream.match(delim)) state.tokenize = null;
|
22 |
+
else stream.skipToEnd();
|
23 |
+
return "string";
|
24 |
+
};
|
25 |
+
}
|
26 |
+
|
27 |
+
// Helper for stringWithEscapes
|
28 |
+
function matchSequence(list) {
|
29 |
+
if (list.length == 0) return stringWithEscapes;
|
30 |
+
return function (stream, state) {
|
31 |
+
var patterns = list[0];
|
32 |
+
for (var i = 0; i < patterns.length; i++) if (stream.match(patterns[i][0])) {
|
33 |
+
state.tokenize = matchSequence(list.slice(1));
|
34 |
+
return patterns[i][1];
|
35 |
+
}
|
36 |
+
state.tokenize = stringWithEscapes;
|
37 |
+
return "string";
|
38 |
+
};
|
39 |
+
}
|
40 |
+
function stringWithEscapes(stream, state) {
|
41 |
+
var escaped = false, next, end = false;
|
42 |
+
|
43 |
+
if (stream.current() == '"') return "string";
|
44 |
+
|
45 |
+
// "Complex" syntax
|
46 |
+
if (stream.match("${", false) || stream.match("{$", false)) {
|
47 |
+
state.tokenize = null;
|
48 |
+
return "string";
|
49 |
+
}
|
50 |
+
|
51 |
+
// Simple syntax
|
52 |
+
if (stream.match(/\$[a-zA-Z_][a-zA-Z0-9_]*/)) {
|
53 |
+
// After the variable name there may appear array or object operator.
|
54 |
+
if (stream.match("[", false)) {
|
55 |
+
// Match array operator
|
56 |
+
state.tokenize = matchSequence([
|
57 |
+
[["[", null]],
|
58 |
+
[[/\d[\w\.]*/, "number"],
|
59 |
+
[/\$[a-zA-Z_][a-zA-Z0-9_]*/, "variable-2"],
|
60 |
+
[/[\w\$]+/, "variable"]],
|
61 |
+
[["]", null]]
|
62 |
+
]);
|
63 |
+
}
|
64 |
+
if (stream.match(/\-\>\w/, false)) {
|
65 |
+
// Match object operator
|
66 |
+
state.tokenize = matchSequence([
|
67 |
+
[["->", null]],
|
68 |
+
[[/[\w]+/, "variable"]]
|
69 |
+
]);
|
70 |
+
}
|
71 |
+
return "variable-2";
|
72 |
+
}
|
73 |
+
|
74 |
+
// Normal string
|
75 |
+
while (
|
76 |
+
!stream.eol() &&
|
77 |
+
(!stream.match("{$", false)) &&
|
78 |
+
(!stream.match(/(\$[a-zA-Z_][a-zA-Z0-9_]*|\$\{)/, false) || escaped)
|
79 |
+
) {
|
80 |
+
next = stream.next();
|
81 |
+
if (!escaped && next == '"') { end = true; break; }
|
82 |
+
escaped = !escaped && next == "\\";
|
83 |
+
}
|
84 |
+
if (end) {
|
85 |
+
state.tokenize = null;
|
86 |
+
state.phpEncapsStack.pop();
|
87 |
+
}
|
88 |
+
return "string";
|
89 |
+
}
|
90 |
+
|
91 |
+
var phpKeywords = "abstract and array as break case catch class clone const continue declare default " +
|
92 |
+
"do else elseif enddeclare endfor endforeach endif endswitch endwhile extends final " +
|
93 |
+
"for foreach function global goto if implements interface instanceof namespace " +
|
94 |
+
"new or private protected public static switch throw trait try use var while xor " +
|
95 |
+
"die echo empty exit eval include include_once isset list require require_once return " +
|
96 |
+
"print unset __halt_compiler self static parent yield insteadof finally";
|
97 |
+
var phpAtoms = "true false null TRUE FALSE NULL __CLASS__ __DIR__ __FILE__ __LINE__ __METHOD__ __FUNCTION__ __NAMESPACE__ __TRAIT__";
|
98 |
+
var phpBuiltin = "func_num_args func_get_arg func_get_args strlen strcmp strncmp strcasecmp strncasecmp each error_reporting define defined trigger_error user_error set_error_handler restore_error_handler get_declared_classes get_loaded_extensions extension_loaded get_extension_funcs debug_backtrace constant bin2hex hex2bin sleep usleep time mktime gmmktime strftime gmstrftime strtotime date gmdate getdate localtime checkdate flush wordwrap htmlspecialchars htmlentities html_entity_decode md5 md5_file crc32 getimagesize image_type_to_mime_type phpinfo phpversion phpcredits strnatcmp strnatcasecmp substr_count strspn strcspn strtok strtoupper strtolower strpos strrpos strrev hebrev hebrevc nl2br basename dirname pathinfo stripslashes stripcslashes strstr stristr strrchr str_shuffle str_word_count strcoll substr substr_replace quotemeta ucfirst ucwords strtr addslashes addcslashes rtrim str_replace str_repeat count_chars chunk_split trim ltrim strip_tags similar_text explode implode setlocale localeconv parse_str str_pad chop strchr sprintf printf vprintf vsprintf sscanf fscanf parse_url urlencode urldecode rawurlencode rawurldecode readlink linkinfo link unlink exec system escapeshellcmd escapeshellarg passthru shell_exec proc_open proc_close rand srand getrandmax mt_rand mt_srand mt_getrandmax base64_decode base64_encode abs ceil floor round is_finite is_nan is_infinite bindec hexdec octdec decbin decoct dechex base_convert number_format fmod ip2long long2ip getenv putenv getopt microtime gettimeofday getrusage uniqid quoted_printable_decode set_time_limit get_cfg_var magic_quotes_runtime set_magic_quotes_runtime get_magic_quotes_gpc get_magic_quotes_runtime import_request_variables error_log serialize unserialize memory_get_usage var_dump var_export debug_zval_dump print_r highlight_file show_source highlight_string ini_get ini_get_all ini_set ini_alter ini_restore get_include_path set_include_path restore_include_path setcookie header headers_sent connection_aborted connection_status ignore_user_abort parse_ini_file is_uploaded_file move_uploaded_file intval floatval doubleval strval gettype settype is_null is_resource is_bool is_long is_float is_int is_integer is_double is_real is_numeric is_string is_array is_object is_scalar ereg ereg_replace eregi eregi_replace split spliti join sql_regcase dl pclose popen readfile rewind rmdir umask fclose feof fgetc fgets fgetss fread fopen fpassthru ftruncate fstat fseek ftell fflush fwrite fputs mkdir rename copy tempnam tmpfile file file_get_contents stream_select stream_context_create stream_context_set_params stream_context_set_option stream_context_get_options stream_filter_prepend stream_filter_append fgetcsv flock get_meta_tags stream_set_write_buffer set_file_buffer set_socket_blocking stream_set_blocking socket_set_blocking stream_get_meta_data stream_register_wrapper stream_wrapper_register stream_set_timeout socket_set_timeout socket_get_status realpath fnmatch fsockopen pfsockopen pack unpack get_browser crypt opendir closedir chdir getcwd rewinddir readdir dir glob fileatime filectime filegroup fileinode filemtime fileowner fileperms filesize filetype file_exists is_writable is_writeable is_readable is_executable is_file is_dir is_link stat lstat chown touch clearstatcache mail ob_start ob_flush ob_clean ob_end_flush ob_end_clean ob_get_flush ob_get_clean ob_get_length ob_get_level ob_get_status ob_get_contents ob_implicit_flush ob_list_handlers ksort krsort natsort natcasesort asort arsort sort rsort usort uasort uksort shuffle array_walk count end prev next reset current key min max in_array array_search extract compact array_fill range array_multisort array_push array_pop array_shift array_unshift array_splice array_slice array_merge array_merge_recursive array_keys array_values array_count_values array_reverse array_reduce array_pad array_flip array_change_key_case array_rand array_unique array_intersect array_intersect_assoc array_diff array_diff_assoc array_sum array_filter array_map array_chunk array_key_exists pos sizeof key_exists assert assert_options version_compare ftok str_rot13 aggregate session_name session_module_name session_save_path session_id session_regenerate_id session_decode session_register session_unregister session_is_registered session_encode session_start session_destroy session_unset session_set_save_handler session_cache_limiter session_cache_expire session_set_cookie_params session_get_cookie_params session_write_close preg_match preg_match_all preg_replace preg_replace_callback preg_split preg_quote preg_grep overload ctype_alnum ctype_alpha ctype_cntrl ctype_digit ctype_lower ctype_graph ctype_print ctype_punct ctype_space ctype_upper ctype_xdigit virtual apache_request_headers apache_note apache_lookup_uri apache_child_terminate apache_setenv apache_response_headers apache_get_version getallheaders mysql_connect mysql_pconnect mysql_close mysql_select_db mysql_create_db mysql_drop_db mysql_query mysql_unbuffered_query mysql_db_query mysql_list_dbs mysql_list_tables mysql_list_fields mysql_list_processes mysql_error mysql_errno mysql_affected_rows mysql_insert_id mysql_result mysql_num_rows mysql_num_fields mysql_fetch_row mysql_fetch_array mysql_fetch_assoc mysql_fetch_object mysql_data_seek mysql_fetch_lengths mysql_fetch_field mysql_field_seek mysql_free_result mysql_field_name mysql_field_table mysql_field_len mysql_field_type mysql_field_flags mysql_escape_string mysql_real_escape_string mysql_stat mysql_thread_id mysql_client_encoding mysql_get_client_info mysql_get_host_info mysql_get_proto_info mysql_get_server_info mysql_info mysql mysql_fieldname mysql_fieldtable mysql_fieldlen mysql_fieldtype mysql_fieldflags mysql_selectdb mysql_createdb mysql_dropdb mysql_freeresult mysql_numfields mysql_numrows mysql_listdbs mysql_listtables mysql_listfields mysql_db_name mysql_dbname mysql_tablename mysql_table_name pg_connect pg_pconnect pg_close pg_connection_status pg_connection_busy pg_connection_reset pg_host pg_dbname pg_port pg_tty pg_options pg_ping pg_query pg_send_query pg_cancel_query pg_fetch_result pg_fetch_row pg_fetch_assoc pg_fetch_array pg_fetch_object pg_fetch_all pg_affected_rows pg_get_result pg_result_seek pg_result_status pg_free_result pg_last_oid pg_num_rows pg_num_fields pg_field_name pg_field_num pg_field_size pg_field_type pg_field_prtlen pg_field_is_null pg_get_notify pg_get_pid pg_result_error pg_last_error pg_last_notice pg_put_line pg_end_copy pg_copy_to pg_copy_from pg_trace pg_untrace pg_lo_create pg_lo_unlink pg_lo_open pg_lo_close pg_lo_read pg_lo_write pg_lo_read_all pg_lo_import pg_lo_export pg_lo_seek pg_lo_tell pg_escape_string pg_escape_bytea pg_unescape_bytea pg_client_encoding pg_set_client_encoding pg_meta_data pg_convert pg_insert pg_update pg_delete pg_select pg_exec pg_getlastoid pg_cmdtuples pg_errormessage pg_numrows pg_numfields pg_fieldname pg_fieldsize pg_fieldtype pg_fieldnum pg_fieldprtlen pg_fieldisnull pg_freeresult pg_result pg_loreadall pg_locreate pg_lounlink pg_loopen pg_loclose pg_loread pg_lowrite pg_loimport pg_loexport http_response_code get_declared_traits getimagesizefromstring socket_import_stream stream_set_chunk_size trait_exists header_register_callback class_uses session_status session_register_shutdown echo print global static exit array empty eval isset unset die include require include_once require_once";
|
99 |
+
CodeMirror.registerHelper("hintWords", "php", [phpKeywords, phpAtoms, phpBuiltin].join(" ").split(" "));
|
100 |
+
CodeMirror.registerHelper("wordChars", "php", /[\\w$]/);
|
101 |
+
|
102 |
+
var phpConfig = {
|
103 |
+
name: "clike",
|
104 |
+
helperType: "php",
|
105 |
+
keywords: keywords(phpKeywords),
|
106 |
+
blockKeywords: keywords("catch do else elseif for foreach if switch try while finally"),
|
107 |
+
atoms: keywords(phpAtoms),
|
108 |
+
builtin: keywords(phpBuiltin),
|
109 |
+
multiLineStrings: true,
|
110 |
+
hooks: {
|
111 |
+
"$": function(stream) {
|
112 |
+
stream.eatWhile(/[\w\$_]/);
|
113 |
+
return "variable-2";
|
114 |
+
},
|
115 |
+
"<": function(stream, state) {
|
116 |
+
if (stream.match(/<</)) {
|
117 |
+
stream.eatWhile(/[\w\.]/);
|
118 |
+
state.tokenize = heredoc(stream.current().slice(3));
|
119 |
+
return state.tokenize(stream, state);
|
120 |
+
}
|
121 |
+
return false;
|
122 |
+
},
|
123 |
+
"#": function(stream) {
|
124 |
+
while (!stream.eol() && !stream.match("?>", false)) stream.next();
|
125 |
+
return "comment";
|
126 |
+
},
|
127 |
+
"/": function(stream) {
|
128 |
+
if (stream.eat("/")) {
|
129 |
+
while (!stream.eol() && !stream.match("?>", false)) stream.next();
|
130 |
+
return "comment";
|
131 |
+
}
|
132 |
+
return false;
|
133 |
+
},
|
134 |
+
'"': function(stream, state) {
|
135 |
+
if (!state.phpEncapsStack)
|
136 |
+
state.phpEncapsStack = [];
|
137 |
+
state.phpEncapsStack.push(0);
|
138 |
+
state.tokenize = stringWithEscapes;
|
139 |
+
return state.tokenize(stream, state);
|
140 |
+
},
|
141 |
+
"{": function(_stream, state) {
|
142 |
+
if (state.phpEncapsStack && state.phpEncapsStack.length > 0)
|
143 |
+
state.phpEncapsStack[state.phpEncapsStack.length - 1]++;
|
144 |
+
return false;
|
145 |
+
},
|
146 |
+
"}": function(_stream, state) {
|
147 |
+
if (state.phpEncapsStack && state.phpEncapsStack.length > 0)
|
148 |
+
if (--state.phpEncapsStack[state.phpEncapsStack.length - 1] == 0)
|
149 |
+
state.tokenize = stringWithEscapes;
|
150 |
+
return false;
|
151 |
+
}
|
152 |
+
}
|
153 |
+
};
|
154 |
+
|
155 |
+
CodeMirror.defineMode("php", function(config, parserConfig) {
|
156 |
+
var htmlMode = CodeMirror.getMode(config, "text/html");
|
157 |
+
var phpMode = CodeMirror.getMode(config, phpConfig);
|
158 |
+
|
159 |
+
function dispatch(stream, state) {
|
160 |
+
var isPHP = state.curMode == phpMode;
|
161 |
+
if (stream.sol() && state.pending && state.pending != '"' && state.pending != "'") state.pending = null;
|
162 |
+
if (!isPHP) {
|
163 |
+
if (stream.match(/^<\?\w*/)) {
|
164 |
+
state.curMode = phpMode;
|
165 |
+
state.curState = state.php;
|
166 |
+
return "meta";
|
167 |
+
}
|
168 |
+
if (state.pending == '"' || state.pending == "'") {
|
169 |
+
while (!stream.eol() && stream.next() != state.pending) {}
|
170 |
+
var style = "string";
|
171 |
+
} else if (state.pending && stream.pos < state.pending.end) {
|
172 |
+
stream.pos = state.pending.end;
|
173 |
+
var style = state.pending.style;
|
174 |
+
} else {
|
175 |
+
var style = htmlMode.token(stream, state.curState);
|
176 |
+
}
|
177 |
+
if (state.pending) state.pending = null;
|
178 |
+
var cur = stream.current(), openPHP = cur.search(/<\?/), m;
|
179 |
+
if (openPHP != -1) {
|
180 |
+
if (style == "string" && (m = cur.match(/[\'\"]$/)) && !/\?>/.test(cur)) state.pending = m[0];
|
181 |
+
else state.pending = {end: stream.pos, style: style};
|
182 |
+
stream.backUp(cur.length - openPHP);
|
183 |
+
}
|
184 |
+
return style;
|
185 |
+
} else if (isPHP && state.php.tokenize == null && stream.match("?>")) {
|
186 |
+
state.curMode = htmlMode;
|
187 |
+
state.curState = state.html;
|
188 |
+
return "meta";
|
189 |
+
} else {
|
190 |
+
return phpMode.token(stream, state.curState);
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
return {
|
195 |
+
startState: function() {
|
196 |
+
var html = CodeMirror.startState(htmlMode), php = CodeMirror.startState(phpMode);
|
197 |
+
return {html: html,
|
198 |
+
php: php,
|
199 |
+
curMode: parserConfig.startOpen ? phpMode : htmlMode,
|
200 |
+
curState: parserConfig.startOpen ? php : html,
|
201 |
+
pending: null};
|
202 |
+
},
|
203 |
+
|
204 |
+
copyState: function(state) {
|
205 |
+
var html = state.html, htmlNew = CodeMirror.copyState(htmlMode, html),
|
206 |
+
php = state.php, phpNew = CodeMirror.copyState(phpMode, php), cur;
|
207 |
+
if (state.curMode == htmlMode) cur = htmlNew;
|
208 |
+
else cur = phpNew;
|
209 |
+
return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur,
|
210 |
+
pending: state.pending};
|
211 |
+
},
|
212 |
+
|
213 |
+
token: dispatch,
|
214 |
+
|
215 |
+
indent: function(state, textAfter) {
|
216 |
+
if ((state.curMode != phpMode && /^\s*<\//.test(textAfter)) ||
|
217 |
+
(state.curMode == phpMode && /^\?>/.test(textAfter)))
|
218 |
+
return htmlMode.indent(state.html, textAfter);
|
219 |
+
return state.curMode.indent(state.curState, textAfter);
|
220 |
+
},
|
221 |
+
|
222 |
+
blockCommentStart: "/*",
|
223 |
+
blockCommentEnd: "*/",
|
224 |
+
lineComment: "//",
|
225 |
+
|
226 |
+
innerMode: function(state) { return {state: state.curState, mode: state.curMode}; }
|
227 |
+
};
|
228 |
+
}, "htmlmixed", "clike");
|
229 |
+
|
230 |
+
CodeMirror.defineMIME("application/x-httpd-php", "php");
|
231 |
+
CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true});
|
232 |
+
CodeMirror.defineMIME("text/x-php", phpConfig);
|
233 |
+
});
|
admin/codemirror/mode/php/test.js
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function() {
|
5 |
+
var mode = CodeMirror.getMode({indentUnit: 2}, "php");
|
6 |
+
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
|
7 |
+
|
8 |
+
MT('simple_test',
|
9 |
+
'[meta <?php] ' +
|
10 |
+
'[keyword echo] [string "aaa"]; ' +
|
11 |
+
'[meta ?>]');
|
12 |
+
|
13 |
+
MT('variable_interpolation_non_alphanumeric',
|
14 |
+
'[meta <?php]',
|
15 |
+
'[keyword echo] [string "aaa$~$!$@$#$$$%$^$&$*$($)$.$<$>$/$\\$}$\\\"$:$;$?$|$[[$]]$+$=aaa"]',
|
16 |
+
'[meta ?>]');
|
17 |
+
|
18 |
+
MT('variable_interpolation_digits',
|
19 |
+
'[meta <?php]',
|
20 |
+
'[keyword echo] [string "aaa$1$2$3$4$5$6$7$8$9$0aaa"]',
|
21 |
+
'[meta ?>]');
|
22 |
+
|
23 |
+
MT('variable_interpolation_simple_syntax_1',
|
24 |
+
'[meta <?php]',
|
25 |
+
'[keyword echo] [string "aaa][variable-2 $aaa][string .aaa"];',
|
26 |
+
'[meta ?>]');
|
27 |
+
|
28 |
+
MT('variable_interpolation_simple_syntax_2',
|
29 |
+
'[meta <?php]',
|
30 |
+
'[keyword echo] [string "][variable-2 $aaaa][[','[number 2]', ']][string aa"];',
|
31 |
+
'[keyword echo] [string "][variable-2 $aaaa][[','[number 2345]', ']][string aa"];',
|
32 |
+
'[keyword echo] [string "][variable-2 $aaaa][[','[number 2.3]', ']][string aa"];',
|
33 |
+
'[keyword echo] [string "][variable-2 $aaaa][[','[variable aaaaa]', ']][string aa"];',
|
34 |
+
'[keyword echo] [string "][variable-2 $aaaa][[','[variable-2 $aaaaa]',']][string aa"];',
|
35 |
+
|
36 |
+
'[keyword echo] [string "1aaa][variable-2 $aaaa][[','[number 2]', ']][string aa"];',
|
37 |
+
'[keyword echo] [string "aaa][variable-2 $aaaa][[','[number 2345]', ']][string aa"];',
|
38 |
+
'[keyword echo] [string "aaa][variable-2 $aaaa][[','[number 2.3]', ']][string aa"];',
|
39 |
+
'[keyword echo] [string "aaa][variable-2 $aaaa][[','[variable aaaaa]', ']][string aa"];',
|
40 |
+
'[keyword echo] [string "aaa][variable-2 $aaaa][[','[variable-2 $aaaaa]',']][string aa"];',
|
41 |
+
'[meta ?>]');
|
42 |
+
|
43 |
+
MT('variable_interpolation_simple_syntax_3',
|
44 |
+
'[meta <?php]',
|
45 |
+
'[keyword echo] [string "aaa][variable-2 $aaaa]->[variable aaaaa][string .aaaaaa"];',
|
46 |
+
'[keyword echo] [string "aaa][variable-2 $aaaa][string ->][variable-2 $aaaaa][string .aaaaaa"];',
|
47 |
+
'[keyword echo] [string "aaa][variable-2 $aaaa]->[variable aaaaa][string [[2]].aaaaaa"];',
|
48 |
+
'[keyword echo] [string "aaa][variable-2 $aaaa]->[variable aaaaa][string ->aaaa2.aaaaaa"];',
|
49 |
+
'[meta ?>]');
|
50 |
+
|
51 |
+
MT('variable_interpolation_escaping',
|
52 |
+
'[meta <?php] [comment /* Escaping */]',
|
53 |
+
'[keyword echo] [string "aaa\\$aaaa->aaa.aaa"];',
|
54 |
+
'[keyword echo] [string "aaa\\$aaaa[[2]]aaa.aaa"];',
|
55 |
+
'[keyword echo] [string "aaa\\$aaaa[[asd]]aaa.aaa"];',
|
56 |
+
'[keyword echo] [string "aaa{\\$aaaa->aaa.aaa"];',
|
57 |
+
'[keyword echo] [string "aaa{\\$aaaa[[2]]aaa.aaa"];',
|
58 |
+
'[keyword echo] [string "aaa{\\aaaaa[[asd]]aaa.aaa"];',
|
59 |
+
'[keyword echo] [string "aaa\\${aaaa->aaa.aaa"];',
|
60 |
+
'[keyword echo] [string "aaa\\${aaaa[[2]]aaa.aaa"];',
|
61 |
+
'[keyword echo] [string "aaa\\${aaaa[[asd]]aaa.aaa"];',
|
62 |
+
'[meta ?>]');
|
63 |
+
|
64 |
+
MT('variable_interpolation_complex_syntax_1',
|
65 |
+
'[meta <?php]',
|
66 |
+
'[keyword echo] [string "aaa][variable-2 $]{[variable aaaa]}[string ->aaa.aaa"];',
|
67 |
+
'[keyword echo] [string "aaa][variable-2 $]{[variable-2 $aaaa]}[string ->aaa.aaa"];',
|
68 |
+
'[keyword echo] [string "aaa][variable-2 $]{[variable-2 $aaaa][[',' [number 42]',']]}[string ->aaa.aaa"];',
|
69 |
+
'[keyword echo] [string "aaa][variable-2 $]{[variable aaaa][meta ?>]aaaaaa');
|
70 |
+
|
71 |
+
MT('variable_interpolation_complex_syntax_2',
|
72 |
+
'[meta <?php] [comment /* Monsters */]',
|
73 |
+
'[keyword echo] [string "][variable-2 $]{[variable aaa][comment /*}?>} $aaa<?php } */]}[string ->aaa.aaa"];',
|
74 |
+
'[keyword echo] [string "][variable-2 $]{[variable aaa][comment /*}?>*/][[',' [string "aaa][variable-2 $aaa][string {}][variable-2 $]{[variable aaa]}[string "]',']]}[string ->aaa.aaa"];',
|
75 |
+
'[keyword echo] [string "][variable-2 $]{[variable aaa][comment /*} } $aaa } */]}[string ->aaa.aaa"];');
|
76 |
+
|
77 |
+
|
78 |
+
function build_recursive_monsters(nt, t, n){
|
79 |
+
var monsters = [t];
|
80 |
+
for (var i = 1; i <= n; ++i)
|
81 |
+
monsters[i] = nt.join(monsters[i - 1]);
|
82 |
+
return monsters;
|
83 |
+
}
|
84 |
+
|
85 |
+
var m1 = build_recursive_monsters(
|
86 |
+
['[string "][variable-2 $]{[variable aaa] [operator +] ', '}[string "]'],
|
87 |
+
'[comment /* }?>} */] [string "aaa][variable-2 $aaa][string .aaa"]',
|
88 |
+
10
|
89 |
+
);
|
90 |
+
|
91 |
+
MT('variable_interpolation_complex_syntax_3_1',
|
92 |
+
'[meta <?php] [comment /* Recursive monsters */]',
|
93 |
+
'[keyword echo] ' + m1[4] + ';',
|
94 |
+
'[keyword echo] ' + m1[7] + ';',
|
95 |
+
'[keyword echo] ' + m1[8] + ';',
|
96 |
+
'[keyword echo] ' + m1[5] + ';',
|
97 |
+
'[keyword echo] ' + m1[1] + ';',
|
98 |
+
'[keyword echo] ' + m1[6] + ';',
|
99 |
+
'[keyword echo] ' + m1[9] + ';',
|
100 |
+
'[keyword echo] ' + m1[0] + ';',
|
101 |
+
'[keyword echo] ' + m1[10] + ';',
|
102 |
+
'[keyword echo] ' + m1[2] + ';',
|
103 |
+
'[keyword echo] ' + m1[3] + ';',
|
104 |
+
'[keyword echo] [string "end"];',
|
105 |
+
'[meta ?>]');
|
106 |
+
|
107 |
+
var m2 = build_recursive_monsters(
|
108 |
+
['[string "a][variable-2 $]{[variable aaa] [operator +] ', ' [operator +] ', '}[string .a"]'],
|
109 |
+
'[comment /* }?>{{ */] [string "a?>}{{aa][variable-2 $aaa][string .a}a?>a"]',
|
110 |
+
5
|
111 |
+
);
|
112 |
+
|
113 |
+
MT('variable_interpolation_complex_syntax_3_2',
|
114 |
+
'[meta <?php] [comment /* Recursive monsters 2 */]',
|
115 |
+
'[keyword echo] ' + m2[0] + ';',
|
116 |
+
'[keyword echo] ' + m2[1] + ';',
|
117 |
+
'[keyword echo] ' + m2[5] + ';',
|
118 |
+
'[keyword echo] ' + m2[4] + ';',
|
119 |
+
'[keyword echo] ' + m2[2] + ';',
|
120 |
+
'[keyword echo] ' + m2[3] + ';',
|
121 |
+
'[keyword echo] [string "end"];',
|
122 |
+
'[meta ?>]');
|
123 |
+
|
124 |
+
function build_recursive_monsters_2(mf1, mf2, nt, t, n){
|
125 |
+
var monsters = [t];
|
126 |
+
for (var i = 1; i <= n; ++i)
|
127 |
+
monsters[i] = nt[0] + mf1[i - 1] + nt[1] + mf2[i - 1] + nt[2] + monsters[i - 1] + nt[3];
|
128 |
+
return monsters;
|
129 |
+
}
|
130 |
+
|
131 |
+
var m3 = build_recursive_monsters_2(
|
132 |
+
m1,
|
133 |
+
m2,
|
134 |
+
['[string "a][variable-2 $]{[variable aaa] [operator +] ', ' [operator +] ', ' [operator +] ', '}[string .a"]'],
|
135 |
+
'[comment /* }?>{{ */] [string "a?>}{{aa][variable-2 $aaa][string .a}a?>a"]',
|
136 |
+
4
|
137 |
+
);
|
138 |
+
|
139 |
+
MT('variable_interpolation_complex_syntax_3_3',
|
140 |
+
'[meta <?php] [comment /* Recursive monsters 2 */]',
|
141 |
+
'[keyword echo] ' + m3[4] + ';',
|
142 |
+
'[keyword echo] ' + m3[0] + ';',
|
143 |
+
'[keyword echo] ' + m3[3] + ';',
|
144 |
+
'[keyword echo] ' + m3[1] + ';',
|
145 |
+
'[keyword echo] ' + m3[2] + ';',
|
146 |
+
'[keyword echo] [string "end"];',
|
147 |
+
'[meta ?>]');
|
148 |
+
})();
|
admin/codemirror/mode/xml/index.html
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
|
3 |
+
<title>CodeMirror: XML mode</title>
|
4 |
+
<meta charset="utf-8"/>
|
5 |
+
<link rel=stylesheet href="../../doc/docs.css">
|
6 |
+
|
7 |
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
8 |
+
<script src="../../lib/codemirror.js"></script>
|
9 |
+
<script src="xml.js"></script>
|
10 |
+
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
11 |
+
<div id=nav>
|
12 |
+
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
|
13 |
+
|
14 |
+
<ul>
|
15 |
+
<li><a href="../../index.html">Home</a>
|
16 |
+
<li><a href="../../doc/manual.html">Manual</a>
|
17 |
+
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
18 |
+
</ul>
|
19 |
+
<ul>
|
20 |
+
<li><a href="../index.html">Language modes</a>
|
21 |
+
<li><a class=active href="#">XML</a>
|
22 |
+
</ul>
|
23 |
+
</div>
|
24 |
+
|
25 |
+
<article>
|
26 |
+
<h2>XML mode</h2>
|
27 |
+
<form><textarea id="code" name="code">
|
28 |
+
<html style="color: green">
|
29 |
+
<!-- this is a comment -->
|
30 |
+
<head>
|
31 |
+
<title>HTML Example</title>
|
32 |
+
</head>
|
33 |
+
<body>
|
34 |
+
The indentation tries to be <em>somewhat &quot;do what
|
35 |
+
I mean&quot;</em>... but might not match your style.
|
36 |
+
</body>
|
37 |
+
</html>
|
38 |
+
</textarea></form>
|
39 |
+
<script>
|
40 |
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
41 |
+
mode: "text/html",
|
42 |
+
lineNumbers: true
|
43 |
+
});
|
44 |
+
</script>
|
45 |
+
<p>The XML mode supports two configuration parameters:</p>
|
46 |
+
<dl>
|
47 |
+
<dt><code>htmlMode (boolean)</code></dt>
|
48 |
+
<dd>This switches the mode to parse HTML instead of XML. This
|
49 |
+
means attributes do not have to be quoted, and some elements
|
50 |
+
(such as <code>br</code>) do not require a closing tag.</dd>
|
51 |
+
<dt><code>alignCDATA (boolean)</code></dt>
|
52 |
+
<dd>Setting this to true will force the opening tag of CDATA
|
53 |
+
blocks to not be indented.</dd>
|
54 |
+
</dl>
|
55 |
+
|
56 |
+
<p><strong>MIME types defined:</strong> <code>application/xml</code>, <code>text/html</code>.</p>
|
57 |
+
</article>
|
admin/codemirror/mode/xml/test.js
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function() {
|
5 |
+
var mode = CodeMirror.getMode({indentUnit: 2}, "xml"), mname = "xml";
|
6 |
+
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1), mname); }
|
7 |
+
|
8 |
+
MT("matching",
|
9 |
+
"[tag&bracket <][tag top][tag&bracket >]",
|
10 |
+
" text",
|
11 |
+
" [tag&bracket <][tag inner][tag&bracket />]",
|
12 |
+
"[tag&bracket </][tag top][tag&bracket >]");
|
13 |
+
|
14 |
+
MT("nonmatching",
|
15 |
+
"[tag&bracket <][tag top][tag&bracket >]",
|
16 |
+
" [tag&bracket <][tag inner][tag&bracket />]",
|
17 |
+
" [tag&bracket </][tag&error tip][tag&bracket&error >]");
|
18 |
+
|
19 |
+
MT("doctype",
|
20 |
+
"[meta <!doctype foobar>]",
|
21 |
+
"[tag&bracket <][tag top][tag&bracket />]");
|
22 |
+
|
23 |
+
MT("cdata",
|
24 |
+
"[tag&bracket <][tag top][tag&bracket >]",
|
25 |
+
" [atom <![CDATA[foo]",
|
26 |
+
"[atom barbazguh]]]]>]",
|
27 |
+
"[tag&bracket </][tag top][tag&bracket >]");
|
28 |
+
|
29 |
+
// HTML tests
|
30 |
+
mode = CodeMirror.getMode({indentUnit: 2}, "text/html");
|
31 |
+
|
32 |
+
MT("selfclose",
|
33 |
+
"[tag&bracket <][tag html][tag&bracket >]",
|
34 |
+
" [tag&bracket <][tag link] [attribute rel]=[string stylesheet] [attribute href]=[string \"/foobar\"][tag&bracket >]",
|
35 |
+
"[tag&bracket </][tag html][tag&bracket >]");
|
36 |
+
|
37 |
+
MT("list",
|
38 |
+
"[tag&bracket <][tag ol][tag&bracket >]",
|
39 |
+
" [tag&bracket <][tag li][tag&bracket >]one",
|
40 |
+
" [tag&bracket <][tag li][tag&bracket >]two",
|
41 |
+
"[tag&bracket </][tag ol][tag&bracket >]");
|
42 |
+
|
43 |
+
MT("valueless",
|
44 |
+
"[tag&bracket <][tag input] [attribute type]=[string checkbox] [attribute checked][tag&bracket />]");
|
45 |
+
|
46 |
+
MT("pThenArticle",
|
47 |
+
"[tag&bracket <][tag p][tag&bracket >]",
|
48 |
+
" foo",
|
49 |
+
"[tag&bracket <][tag article][tag&bracket >]bar");
|
50 |
+
|
51 |
+
})();
|
admin/codemirror/mode/xml/xml.js
ADDED
@@ -0,0 +1,384 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
(function(mod) {
|
5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6 |
+
mod(require("../../lib/codemirror"));
|
7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
8 |
+
define(["../../lib/codemirror"], mod);
|
9 |
+
else // Plain browser env
|
10 |
+
mod(CodeMirror);
|
11 |
+
})(function(CodeMirror) {
|
12 |
+
"use strict";
|
13 |
+
|
14 |
+
CodeMirror.defineMode("xml", function(config, parserConfig) {
|
15 |
+
var indentUnit = config.indentUnit;
|
16 |
+
var multilineTagIndentFactor = parserConfig.multilineTagIndentFactor || 1;
|
17 |
+
var multilineTagIndentPastTag = parserConfig.multilineTagIndentPastTag;
|
18 |
+
if (multilineTagIndentPastTag == null) multilineTagIndentPastTag = true;
|
19 |
+
|
20 |
+
var Kludges = parserConfig.htmlMode ? {
|
21 |
+
autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
|
22 |
+
'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
|
23 |
+
'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
|
24 |
+
'track': true, 'wbr': true},
|
25 |
+
implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
|
26 |
+
'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
|
27 |
+
'th': true, 'tr': true},
|
28 |
+
contextGrabbers: {
|
29 |
+
'dd': {'dd': true, 'dt': true},
|
30 |
+
'dt': {'dd': true, 'dt': true},
|
31 |
+
'li': {'li': true},
|
32 |
+
'option': {'option': true, 'optgroup': true},
|
33 |
+
'optgroup': {'optgroup': true},
|
34 |
+
'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
|
35 |
+
'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
|
36 |
+
'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
|
37 |
+
'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
|
38 |
+
'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
|
39 |
+
'rp': {'rp': true, 'rt': true},
|
40 |
+
'rt': {'rp': true, 'rt': true},
|
41 |
+
'tbody': {'tbody': true, 'tfoot': true},
|
42 |
+
'td': {'td': true, 'th': true},
|
43 |
+
'tfoot': {'tbody': true},
|
44 |
+
'th': {'td': true, 'th': true},
|
45 |
+
'thead': {'tbody': true, 'tfoot': true},
|
46 |
+
'tr': {'tr': true}
|
47 |
+
},
|
48 |
+
doNotIndent: {"pre": true},
|
49 |
+
allowUnquoted: true,
|
50 |
+
allowMissing: true,
|
51 |
+
caseFold: true
|
52 |
+
} : {
|
53 |
+
autoSelfClosers: {},
|
54 |
+
implicitlyClosed: {},
|
55 |
+
contextGrabbers: {},
|
56 |
+
doNotIndent: {},
|
57 |
+
allowUnquoted: false,
|
58 |
+
allowMissing: false,
|
59 |
+
caseFold: false
|
60 |
+
};
|
61 |
+
var alignCDATA = parserConfig.alignCDATA;
|
62 |
+
|
63 |
+
// Return variables for tokenizers
|
64 |
+
var type, setStyle;
|
65 |
+
|
66 |
+
function inText(stream, state) {
|
67 |
+
function chain(parser) {
|
68 |
+
state.tokenize = parser;
|
69 |
+
return parser(stream, state);
|
70 |
+
}
|
71 |
+
|
72 |
+
var ch = stream.next();
|
73 |
+
if (ch == "<") {
|
74 |
+
if (stream.eat("!")) {
|
75 |
+
if (stream.eat("[")) {
|
76 |
+
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
|
77 |
+
else return null;
|
78 |
+
} else if (stream.match("--")) {
|
79 |
+
return chain(inBlock("comment", "-->"));
|
80 |
+
} else if (stream.match("DOCTYPE", true, true)) {
|
81 |
+
stream.eatWhile(/[\w\._\-]/);
|
82 |
+
return chain(doctype(1));
|
83 |
+
} else {
|
84 |
+
return null;
|
85 |
+
}
|
86 |
+
} else if (stream.eat("?")) {
|
87 |
+
stream.eatWhile(/[\w\._\-]/);
|
88 |
+
state.tokenize = inBlock("meta", "?>");
|
89 |
+
return "meta";
|
90 |
+
} else {
|
91 |
+
type = stream.eat("/") ? "closeTag" : "openTag";
|
92 |
+
state.tokenize = inTag;
|
93 |
+
return "tag bracket";
|
94 |
+
}
|
95 |
+
} else if (ch == "&") {
|
96 |
+
var ok;
|
97 |
+
if (stream.eat("#")) {
|
98 |
+
if (stream.eat("x")) {
|
99 |
+
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
|
100 |
+
} else {
|
101 |
+
ok = stream.eatWhile(/[\d]/) && stream.eat(";");
|
102 |
+
}
|
103 |
+
} else {
|
104 |
+
ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
|
105 |
+
}
|
106 |
+
return ok ? "atom" : "error";
|
107 |
+
} else {
|
108 |
+
stream.eatWhile(/[^&<]/);
|
109 |
+
return null;
|
110 |
+
}
|
111 |
+
}
|
112 |
+
|
113 |
+
function inTag(stream, state) {
|
114 |
+
var ch = stream.next();
|
115 |
+
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
|
116 |
+
state.tokenize = inText;
|
117 |
+
type = ch == ">" ? "endTag" : "selfcloseTag";
|
118 |
+
return "tag bracket";
|
119 |
+
} else if (ch == "=") {
|
120 |
+
type = "equals";
|
121 |
+
return null;
|
122 |
+
} else if (ch == "<") {
|
123 |
+
state.tokenize = inText;
|
124 |
+
state.state = baseState;
|
125 |
+
state.tagName = state.tagStart = null;
|
126 |
+
var next = state.tokenize(stream, state);
|
127 |
+
return next ? next + " tag error" : "tag error";
|
128 |
+
} else if (/[\'\"]/.test(ch)) {
|
129 |
+
state.tokenize = inAttribute(ch);
|
130 |
+
state.stringStartCol = stream.column();
|
131 |
+
return state.tokenize(stream, state);
|
132 |
+
} else {
|
133 |
+
stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
|
134 |
+
return "word";
|
135 |
+
}
|
136 |
+
}
|
137 |
+
|
138 |
+
function inAttribute(quote) {
|
139 |
+
var closure = function(stream, state) {
|
140 |
+
while (!stream.eol()) {
|
141 |
+
if (stream.next() == quote) {
|
142 |
+
state.tokenize = inTag;
|
143 |
+
break;
|
144 |
+
}
|
145 |
+
}
|
146 |
+
return "string";
|
147 |
+
};
|
148 |
+
closure.isInAttribute = true;
|
149 |
+
return closure;
|
150 |
+
}
|
151 |
+
|
152 |
+
function inBlock(style, terminator) {
|
153 |
+
return function(stream, state) {
|
154 |
+
while (!stream.eol()) {
|
155 |
+
if (stream.match(terminator)) {
|
156 |
+
state.tokenize = inText;
|
157 |
+
break;
|
158 |
+
}
|
159 |
+
stream.next();
|
160 |
+
}
|
161 |
+
return style;
|
162 |
+
};
|
163 |
+
}
|
164 |
+
function doctype(depth) {
|
165 |
+
return function(stream, state) {
|
166 |
+
var ch;
|
167 |
+
while ((ch = stream.next()) != null) {
|
168 |
+
if (ch == "<") {
|
169 |
+
state.tokenize = doctype(depth + 1);
|
170 |
+
return state.tokenize(stream, state);
|
171 |
+
} else if (ch == ">") {
|
172 |
+
if (depth == 1) {
|
173 |
+
state.tokenize = inText;
|
174 |
+
break;
|
175 |
+
} else {
|
176 |
+
state.tokenize = doctype(depth - 1);
|
177 |
+
return state.tokenize(stream, state);
|
178 |
+
}
|
179 |
+
}
|
180 |
+
}
|
181 |
+
return "meta";
|
182 |
+
};
|
183 |
+
}
|
184 |
+
|
185 |
+
function Context(state, tagName, startOfLine) {
|
186 |
+
this.prev = state.context;
|
187 |
+
this.tagName = tagName;
|
188 |
+
this.indent = state.indented;
|
189 |
+
this.startOfLine = startOfLine;
|
190 |
+
if (Kludges.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent))
|
191 |
+
this.noIndent = true;
|
192 |
+
}
|
193 |
+
function popContext(state) {
|
194 |
+
if (state.context) state.context = state.context.prev;
|
195 |
+
}
|
196 |
+
function maybePopContext(state, nextTagName) {
|
197 |
+
var parentTagName;
|
198 |
+
while (true) {
|
199 |
+
if (!state.context) {
|
200 |
+
return;
|
201 |
+
}
|
202 |
+
parentTagName = state.context.tagName;
|
203 |
+
if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) ||
|
204 |
+
!Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
|
205 |
+
return;
|
206 |
+
}
|
207 |
+
popContext(state);
|
208 |
+
}
|
209 |
+
}
|
210 |
+
|
211 |
+
function baseState(type, stream, state) {
|
212 |
+
if (type == "openTag") {
|
213 |
+
state.tagStart = stream.column();
|
214 |
+
return tagNameState;
|
215 |
+
} else if (type == "closeTag") {
|
216 |
+
return closeTagNameState;
|
217 |
+
} else {
|
218 |
+
return baseState;
|
219 |
+
}
|
220 |
+
}
|
221 |
+
function tagNameState(type, stream, state) {
|
222 |
+
if (type == "word") {
|
223 |
+
state.tagName = stream.current();
|
224 |
+
setStyle = "tag";
|
225 |
+
return attrState;
|
226 |
+
} else {
|
227 |
+
setStyle = "error";
|
228 |
+
return tagNameState;
|
229 |
+
}
|
230 |
+
}
|
231 |
+
function closeTagNameState(type, stream, state) {
|
232 |
+
if (type == "word") {
|
233 |
+
var tagName = stream.current();
|
234 |
+
if (state.context && state.context.tagName != tagName &&
|
235 |
+
Kludges.implicitlyClosed.hasOwnProperty(state.context.tagName))
|
236 |
+
popContext(state);
|
237 |
+
if (state.context && state.context.tagName == tagName) {
|
238 |
+
setStyle = "tag";
|
239 |
+
return closeState;
|
240 |
+
} else {
|
241 |
+
setStyle = "tag error";
|
242 |
+
return closeStateErr;
|
243 |
+
}
|
244 |
+
} else {
|
245 |
+
setStyle = "error";
|
246 |
+
return closeStateErr;
|
247 |
+
}
|
248 |
+
}
|
249 |
+
|
250 |
+
function closeState(type, _stream, state) {
|
251 |
+
if (type != "endTag") {
|
252 |
+
setStyle = "error";
|
253 |
+
return closeState;
|
254 |
+
}
|
255 |
+
popContext(state);
|
256 |
+
return baseState;
|
257 |
+
}
|
258 |
+
function closeStateErr(type, stream, state) {
|
259 |
+
setStyle = "error";
|
260 |
+
return closeState(type, stream, state);
|
261 |
+
}
|
262 |
+
|
263 |
+
function attrState(type, _stream, state) {
|
264 |
+
if (type == "word") {
|
265 |
+
setStyle = "attribute";
|
266 |
+
return attrEqState;
|
267 |
+
} else if (type == "endTag" || type == "selfcloseTag") {
|
268 |
+
var tagName = state.tagName, tagStart = state.tagStart;
|
269 |
+
state.tagName = state.tagStart = null;
|
270 |
+
if (type == "selfcloseTag" ||
|
271 |
+
Kludges.autoSelfClosers.hasOwnProperty(tagName)) {
|
272 |
+
maybePopContext(state, tagName);
|
273 |
+
} else {
|
274 |
+
maybePopContext(state, tagName);
|
275 |
+
state.context = new Context(state, tagName, tagStart == state.indented);
|
276 |
+
}
|
277 |
+
return baseState;
|
278 |
+
}
|
279 |
+
setStyle = "error";
|
280 |
+
return attrState;
|
281 |
+
}
|
282 |
+
function attrEqState(type, stream, state) {
|
283 |
+
if (type == "equals") return attrValueState;
|
284 |
+
if (!Kludges.allowMissing) setStyle = "error";
|
285 |
+
return attrState(type, stream, state);
|
286 |
+
}
|
287 |
+
function attrValueState(type, stream, state) {
|
288 |
+
if (type == "string") return attrContinuedState;
|
289 |
+
if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return attrState;}
|
290 |
+
setStyle = "error";
|
291 |
+
return attrState(type, stream, state);
|
292 |
+
}
|
293 |
+
function attrContinuedState(type, stream, state) {
|
294 |
+
if (type == "string") return attrContinuedState;
|
295 |
+
return attrState(type, stream, state);
|
296 |
+
}
|
297 |
+
|
298 |
+
return {
|
299 |
+
startState: function() {
|
300 |
+
return {tokenize: inText,
|
301 |
+
state: baseState,
|
302 |
+
indented: 0,
|
303 |
+
tagName: null, tagStart: null,
|
304 |
+
context: null};
|
305 |
+
},
|
306 |
+
|
307 |
+
token: function(stream, state) {
|
308 |
+
if (!state.tagName && stream.sol())
|
309 |
+
state.indented = stream.indentation();
|
310 |
+
|
311 |
+
if (stream.eatSpace()) return null;
|
312 |
+
type = null;
|
313 |
+
var style = state.tokenize(stream, state);
|
314 |
+
if ((style || type) && style != "comment") {
|
315 |
+
setStyle = null;
|
316 |
+
state.state = state.state(type || style, stream, state);
|
317 |
+
if (setStyle)
|
318 |
+
style = setStyle == "error" ? style + " error" : setStyle;
|
319 |
+
}
|
320 |
+
return style;
|
321 |
+
},
|
322 |
+
|
323 |
+
indent: function(state, textAfter, fullLine) {
|
324 |
+
var context = state.context;
|
325 |
+
// Indent multi-line strings (e.g. css).
|
326 |
+
if (state.tokenize.isInAttribute) {
|
327 |
+
if (state.tagStart == state.indented)
|
328 |
+
return state.stringStartCol + 1;
|
329 |
+
else
|
330 |
+
return state.indented + indentUnit;
|
331 |
+
}
|
332 |
+
if (context && context.noIndent) return CodeMirror.Pass;
|
333 |
+
if (state.tokenize != inTag && state.tokenize != inText)
|
334 |
+
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
|
335 |
+
// Indent the starts of attribute names.
|
336 |
+
if (state.tagName) {
|
337 |
+
if (multilineTagIndentPastTag)
|
338 |
+
return state.tagStart + state.tagName.length + 2;
|
339 |
+
else
|
340 |
+
return state.tagStart + indentUnit * multilineTagIndentFactor;
|
341 |
+
}
|
342 |
+
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
|
343 |
+
var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
|
344 |
+
if (tagAfter && tagAfter[1]) { // Closing tag spotted
|
345 |
+
while (context) {
|
346 |
+
if (context.tagName == tagAfter[2]) {
|
347 |
+
context = context.prev;
|
348 |
+
break;
|
349 |
+
} else if (Kludges.implicitlyClosed.hasOwnProperty(context.tagName)) {
|
350 |
+
context = context.prev;
|
351 |
+
} else {
|
352 |
+
break;
|
353 |
+
}
|
354 |
+
}
|
355 |
+
} else if (tagAfter) { // Opening tag spotted
|
356 |
+
while (context) {
|
357 |
+
var grabbers = Kludges.contextGrabbers[context.tagName];
|
358 |
+
if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
|
359 |
+
context = context.prev;
|
360 |
+
else
|
361 |
+
break;
|
362 |
+
}
|
363 |
+
}
|
364 |
+
while (context && !context.startOfLine)
|
365 |
+
context = context.prev;
|
366 |
+
if (context) return context.indent + indentUnit;
|
367 |
+
else return 0;
|
368 |
+
},
|
369 |
+
|
370 |
+
electricInput: /<\/[\s\w:]+>$/,
|
371 |
+
blockCommentStart: "<!--",
|
372 |
+
blockCommentEnd: "-->",
|
373 |
+
|
374 |
+
configuration: parserConfig.htmlMode ? "html" : "xml",
|
375 |
+
helperType: parserConfig.htmlMode ? "html" : "xml"
|
376 |
+
};
|
377 |
+
});
|
378 |
+
|
379 |
+
CodeMirror.defineMIME("text/xml", "xml");
|
380 |
+
CodeMirror.defineMIME("application/xml", "xml");
|
381 |
+
if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
|
382 |
+
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
|
383 |
+
|
384 |
+
});
|
admin/css/admin.css
CHANGED
@@ -6,6 +6,9 @@
|
|
6 |
* @since 1.0
|
7 |
*/
|
8 |
|
|
|
|
|
|
|
9 |
.ajax-load-more{
|
10 |
font-size: 14px;
|
11 |
color:#666;
|
@@ -26,7 +29,7 @@
|
|
26 |
|
27 |
#alm-container{
|
28 |
overflow: hidden;
|
29 |
-
|
30 |
}
|
31 |
|
32 |
.ajax-load-more code{
|
@@ -79,25 +82,28 @@
|
|
79 |
|
80 |
/* Expand Collapse Headings */
|
81 |
.ajax-load-more h3.heading{
|
82 |
-
font-weight:
|
83 |
padding: 0 0 0 25px !important;
|
84 |
line-height: normal !important;
|
85 |
margin: 0 !important;
|
86 |
-
color: #
|
87 |
cursor: pointer;
|
88 |
width: 100%;
|
89 |
position: relative;
|
90 |
-
font-size:
|
91 |
}
|
92 |
.ajax-load-more h3.heading:hover:after{
|
93 |
color: #f05452;
|
94 |
}
|
|
|
|
|
|
|
95 |
|
96 |
.ajax-load-more h3.heading:after{
|
97 |
font-family: 'FontAwesome';
|
98 |
content: '\f056';
|
99 |
color:#e1e1e1;
|
100 |
-
font-size:
|
101 |
position: absolute;
|
102 |
left: 0;
|
103 |
top: 3px;
|
@@ -269,6 +275,14 @@
|
|
269 |
border: 1px solid #ccc;
|
270 |
width: 60%;
|
271 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
.ajax-load-more input.disabled-input{
|
273 |
opacity: 0.5;
|
274 |
filter: alpha(opacity=50);
|
@@ -277,7 +291,9 @@
|
|
277 |
.ajax-load-more textarea:focus{
|
278 |
border-color: #999;
|
279 |
box-shadow: 0 0 3px #ccc;
|
|
|
280 |
}
|
|
|
281 |
|
282 |
.checkboxes label{
|
283 |
margin-right: 5px;
|
@@ -297,15 +313,22 @@
|
|
297 |
/* --------------------------------------------------------------------------- */
|
298 |
|
299 |
.ajax-load-more .row{
|
300 |
-
padding:
|
301 |
margin: 15px 0 0;
|
302 |
height: auto;
|
303 |
width: 100%;
|
304 |
display: block;
|
305 |
overflow: hidden;
|
306 |
clear: both;
|
307 |
-
border
|
308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
|
310 |
.admin.ajax-load-more .row{
|
311 |
border-color: #efefef;
|
@@ -313,7 +336,6 @@
|
|
313 |
.admin.ajax-load-more .row:first-of-type{
|
314 |
margin: 0;
|
315 |
padding-top: 0;
|
316 |
-
border-top: none;
|
317 |
}
|
318 |
|
319 |
.ajax-load-more .intro{
|
@@ -361,6 +383,7 @@
|
|
361 |
padding: 10px 0 5px;
|
362 |
margin: 0;
|
363 |
font-size: 0.9em;
|
|
|
364 |
}
|
365 |
|
366 |
.ajax-load-more label input._alm_repeater_alias{
|
@@ -587,10 +610,29 @@
|
|
587 |
margin-right: 10px;
|
588 |
}
|
589 |
|
590 |
-
.admin.ajax-load-more.settings input[type=text]
|
591 |
-
|
592 |
margin-top:10px;
|
593 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
594 |
|
595 |
/* Table Overrides */
|
596 |
.admin.ajax-load-more.settings .form-table td,
|
@@ -628,8 +670,8 @@
|
|
628 |
top: -2px;
|
629 |
}
|
630 |
.ajax-load-more p.addon-intro{
|
631 |
-
font-size:
|
632 |
-
line-height:
|
633 |
}
|
634 |
|
635 |
.ajax-load-more h3.add-on-title,
|
@@ -649,7 +691,7 @@
|
|
649 |
}
|
650 |
.ajax-load-more p.desc{
|
651 |
font-size: 12px;
|
652 |
-
padding:
|
653 |
}
|
654 |
|
655 |
.ajax-load-more p.back2top{
|
@@ -709,20 +751,26 @@ table.highlight{
|
|
709 |
width: 67%;
|
710 |
float: left;
|
711 |
margin-top: 10px;
|
|
|
712 |
}
|
713 |
.ajax-load-more .alm-main .group{
|
714 |
background: #fff;
|
715 |
padding: 20px;
|
716 |
margin: 0 0 20px;
|
717 |
-
border-radius: 3px;
|
718 |
-
border: 1px solid #ccc;
|
719 |
-
-webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
|
720 |
-
-moz-box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
|
721 |
-
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
|
722 |
position: relative;
|
723 |
display: block;
|
724 |
clear: both;
|
725 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
726 |
.ajax-load-more .alm-main.full{
|
727 |
width: 100%;
|
728 |
float: none;
|
@@ -735,11 +783,17 @@ table.highlight{
|
|
735 |
.form-table tr{
|
736 |
border-top: 1px solid #efefef;
|
737 |
}
|
|
|
|
|
|
|
|
|
738 |
|
739 |
|
740 |
/* Repeaters */
|
741 |
.repeaters {}
|
742 |
-
|
|
|
|
|
743 |
.repeaters input.save-repeater{
|
744 |
float: left;
|
745 |
margin: 15px 0 0;
|
@@ -747,7 +801,6 @@ table.highlight{
|
|
747 |
}
|
748 |
.repeater-wrap textarea,
|
749 |
.repeater-wrap input[type=text]{
|
750 |
-
background: #efefef;
|
751 |
width: 100%;
|
752 |
}
|
753 |
|
@@ -776,9 +829,8 @@ table.highlight{
|
|
776 |
background: #4DD5B0;
|
777 |
padding: 13px 100px 13px 12px;
|
778 |
border-radius: 3px;
|
779 |
-
margin: 0 0
|
780 |
-
width:
|
781 |
-
width: calc(100% - 20px);
|
782 |
display: block;
|
783 |
color: #fff;
|
784 |
font-size: 13px;
|
@@ -870,17 +922,12 @@ a.btn{
|
|
870 |
.ajax-load-more .alm-sidebar .cta{
|
871 |
background: #fff;
|
872 |
padding: 20px;
|
873 |
-
border: 1px solid #ccc;
|
874 |
-
border-radius: 3px;
|
875 |
-
-webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
|
876 |
-
-moz-box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
|
877 |
-
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
|
878 |
margin: 0 0 20px;
|
879 |
overflow: hidden;
|
880 |
position: relative;
|
881 |
}
|
882 |
.ajax-load-more .alm-sidebar .cta.padding-bottom{
|
883 |
-
padding-bottom:
|
884 |
}
|
885 |
.ajax-load-more .alm-sidebar h3,
|
886 |
.ajax-load-more .alm-sidebar h4{
|
@@ -962,6 +1009,72 @@ a.btn{
|
|
962 |
box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.1);
|
963 |
}
|
964 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
965 |
|
966 |
/*
|
967 |
* Admin screen media queries
|
@@ -994,7 +1107,6 @@ a.btn{
|
|
994 |
|
995 |
|
996 |
|
997 |
-
|
998 |
/*
|
999 |
* Select2 - form replacement - http://ivaynberg.github.io/select2/
|
1000 |
*
|
@@ -1022,9 +1134,10 @@ a.btn{
|
|
1022 |
border: 1px solid #ccc;
|
1023 |
white-space: nowrap;
|
1024 |
line-height: 40px;
|
1025 |
-
color: #
|
1026 |
text-decoration: none;
|
1027 |
background: #fff;
|
|
|
1028 |
border-radius:2px;
|
1029 |
-webkit-background-clip: padding-box;
|
1030 |
-moz-background-clip: padding;
|
6 |
* @since 1.0
|
7 |
*/
|
8 |
|
9 |
+
.forceColors{
|
10 |
+
background: #fff !important;
|
11 |
+
}
|
12 |
.ajax-load-more{
|
13 |
font-size: 14px;
|
14 |
color:#666;
|
29 |
|
30 |
#alm-container{
|
31 |
overflow: hidden;
|
32 |
+
padding: 15px 10px 140px !important;
|
33 |
}
|
34 |
|
35 |
.ajax-load-more code{
|
82 |
|
83 |
/* Expand Collapse Headings */
|
84 |
.ajax-load-more h3.heading{
|
85 |
+
font-weight: 700;
|
86 |
padding: 0 0 0 25px !important;
|
87 |
line-height: normal !important;
|
88 |
margin: 0 !important;
|
89 |
+
color: #555;
|
90 |
cursor: pointer;
|
91 |
width: 100%;
|
92 |
position: relative;
|
93 |
+
font-size: 17px;
|
94 |
}
|
95 |
.ajax-load-more h3.heading:hover:after{
|
96 |
color: #f05452;
|
97 |
}
|
98 |
+
.ajax-load-more h3.heading:hover{
|
99 |
+
color: #222;
|
100 |
+
}
|
101 |
|
102 |
.ajax-load-more h3.heading:after{
|
103 |
font-family: 'FontAwesome';
|
104 |
content: '\f056';
|
105 |
color:#e1e1e1;
|
106 |
+
font-size: 18px;
|
107 |
position: absolute;
|
108 |
left: 0;
|
109 |
top: 3px;
|
275 |
border: 1px solid #ccc;
|
276 |
width: 60%;
|
277 |
}
|
278 |
+
.ajax-load-more input[type=text],
|
279 |
+
.ajax-load-more textarea{
|
280 |
+
background: #f7f7f7;
|
281 |
+
}
|
282 |
+
.ajax-load-more .repeaters input[type=text]{
|
283 |
+
padding: 7px 10px;
|
284 |
+
}
|
285 |
+
|
286 |
.ajax-load-more input.disabled-input{
|
287 |
opacity: 0.5;
|
288 |
filter: alpha(opacity=50);
|
291 |
.ajax-load-more textarea:focus{
|
292 |
border-color: #999;
|
293 |
box-shadow: 0 0 3px #ccc;
|
294 |
+
background: #efefef;
|
295 |
}
|
296 |
+
|
297 |
|
298 |
.checkboxes label{
|
299 |
margin-right: 5px;
|
313 |
/* --------------------------------------------------------------------------- */
|
314 |
|
315 |
.ajax-load-more .row{
|
316 |
+
padding: 10px !important;
|
317 |
margin: 15px 0 0;
|
318 |
height: auto;
|
319 |
width: 100%;
|
320 |
display: block;
|
321 |
overflow: hidden;
|
322 |
clear: both;
|
323 |
+
border: 1px solid #efefef;
|
324 |
+
-webkit-border-radius: 2px;
|
325 |
+
-moz-border-radius: 2px;
|
326 |
+
border-radius: 2px;
|
327 |
+
}
|
328 |
+
.ajax-load-more .row.no-brd{
|
329 |
+
border: none;
|
330 |
+
padding: 0 !important;
|
331 |
+
}
|
332 |
|
333 |
.admin.ajax-load-more .row{
|
334 |
border-color: #efefef;
|
336 |
.admin.ajax-load-more .row:first-of-type{
|
337 |
margin: 0;
|
338 |
padding-top: 0;
|
|
|
339 |
}
|
340 |
|
341 |
.ajax-load-more .intro{
|
383 |
padding: 10px 0 5px;
|
384 |
margin: 0;
|
385 |
font-size: 0.9em;
|
386 |
+
color: #888;
|
387 |
}
|
388 |
|
389 |
.ajax-load-more label input._alm_repeater_alias{
|
610 |
margin-right: 10px;
|
611 |
}
|
612 |
|
613 |
+
.admin.ajax-load-more.settings input[type=text],
|
614 |
+
.admin.ajax-load-more.settings .select2-container{
|
615 |
margin-top:10px;
|
616 |
}
|
617 |
+
.admin.ajax-load-more.settings .ajax-load-more-wrap {
|
618 |
+
position: relative;
|
619 |
+
top:10px;
|
620 |
+
padding: 10px 0;
|
621 |
+
border-top: 1px dashed #ccc;
|
622 |
+
}
|
623 |
+
.admin.ajax-load-more.settings .ajax-load-more-wrap button{
|
624 |
+
margin: 0 !important;
|
625 |
+
}
|
626 |
+
.admin.ajax-load-more.settings .ajax-load-more-wrap span{
|
627 |
+
display: block;
|
628 |
+
font-size: 11px;
|
629 |
+
opacity: 0.7;
|
630 |
+
padding: 0 0 5px;
|
631 |
+
}
|
632 |
+
.admin.ajax-load-more.settings button.alm-load-more-btn.loading:before {
|
633 |
+
margin: 5px 6px 6px;
|
634 |
+
}
|
635 |
+
|
636 |
|
637 |
/* Table Overrides */
|
638 |
.admin.ajax-load-more.settings .form-table td,
|
670 |
top: -2px;
|
671 |
}
|
672 |
.ajax-load-more p.addon-intro{
|
673 |
+
font-size: 24px !important;
|
674 |
+
line-height: 30px !important;
|
675 |
}
|
676 |
|
677 |
.ajax-load-more h3.add-on-title,
|
691 |
}
|
692 |
.ajax-load-more p.desc{
|
693 |
font-size: 12px;
|
694 |
+
padding: 0 0 8px 24px;
|
695 |
}
|
696 |
|
697 |
.ajax-load-more p.back2top{
|
751 |
width: 67%;
|
752 |
float: left;
|
753 |
margin-top: 10px;
|
754 |
+
background: none !important;
|
755 |
}
|
756 |
.ajax-load-more .alm-main .group{
|
757 |
background: #fff;
|
758 |
padding: 20px;
|
759 |
margin: 0 0 20px;
|
|
|
|
|
|
|
|
|
|
|
760 |
position: relative;
|
761 |
display: block;
|
762 |
clear: both;
|
763 |
}
|
764 |
+
.ajax-load-more .alm-main .group,
|
765 |
+
.ajax-load-more .alm-sidebar .cta{
|
766 |
+
border: 1px solid #ccc;
|
767 |
+
-webkit-border-radius: 3px;
|
768 |
+
-moz-border-radius: 3px;
|
769 |
+
border-radius: 3px;
|
770 |
+
-webkit-box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
|
771 |
+
-moz-box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
|
772 |
+
box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
|
773 |
+
}
|
774 |
.ajax-load-more .alm-main.full{
|
775 |
width: 100%;
|
776 |
float: none;
|
783 |
.form-table tr{
|
784 |
border-top: 1px solid #efefef;
|
785 |
}
|
786 |
+
.form-table {
|
787 |
+
border-bottom: 1px solid #efefef;
|
788 |
+
margin: 0 0 20px;
|
789 |
+
}
|
790 |
|
791 |
|
792 |
/* Repeaters */
|
793 |
.repeaters {}
|
794 |
+
.repeaters .repeater-wrap{
|
795 |
+
padding: 0 10px 0 25px !important;
|
796 |
+
}
|
797 |
.repeaters input.save-repeater{
|
798 |
float: left;
|
799 |
margin: 15px 0 0;
|
801 |
}
|
802 |
.repeater-wrap textarea,
|
803 |
.repeater-wrap input[type=text]{
|
|
|
804 |
width: 100%;
|
805 |
}
|
806 |
|
829 |
background: #4DD5B0;
|
830 |
padding: 13px 100px 13px 12px;
|
831 |
border-radius: 3px;
|
832 |
+
margin: 0 0 0 0;
|
833 |
+
width: 100%;
|
|
|
834 |
display: block;
|
835 |
color: #fff;
|
836 |
font-size: 13px;
|
922 |
.ajax-load-more .alm-sidebar .cta{
|
923 |
background: #fff;
|
924 |
padding: 20px;
|
|
|
|
|
|
|
|
|
|
|
925 |
margin: 0 0 20px;
|
926 |
overflow: hidden;
|
927 |
position: relative;
|
928 |
}
|
929 |
.ajax-load-more .alm-sidebar .cta.padding-bottom{
|
930 |
+
padding-bottom: 60px;
|
931 |
}
|
932 |
.ajax-load-more .alm-sidebar h3,
|
933 |
.ajax-load-more .alm-sidebar h4{
|
1009 |
box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.1);
|
1010 |
}
|
1011 |
|
1012 |
+
/*
|
1013 |
+
* CodeMirror Syntax Highlighting
|
1014 |
+
*
|
1015 |
+
* @since 2.2.0
|
1016 |
+
*/
|
1017 |
+
|
1018 |
+
.ajax-load-more .CodeMirror {
|
1019 |
+
height: auto;
|
1020 |
+
-webkit-border-radius: 3px;
|
1021 |
+
-moz-border-radius: 3px;
|
1022 |
+
border-radius: 3px;
|
1023 |
+
padding: 8px;
|
1024 |
+
background: #f7f7f7;
|
1025 |
+
border: 1px solid #ccc;
|
1026 |
+
color: #999;
|
1027 |
+
line-height: 1.3;
|
1028 |
+
}
|
1029 |
+
|
1030 |
+
.ajax-load-more .cm-s-pastel-on-dark.CodeMirror{ /* Bkg color */
|
1031 |
+
background: #333;
|
1032 |
+
}
|
1033 |
+
.ajax-load-more .CodeMirror-gutters{ /* Line Number color */
|
1034 |
+
background: #fff;
|
1035 |
+
border-right: 1px solid #ccc;
|
1036 |
+
-webkit-border-radius: 2px 0 0 2px;
|
1037 |
+
-moz-border-radius: 2px 0 0 2px;
|
1038 |
+
border-radius: 2px 0 0 2px;
|
1039 |
+
}
|
1040 |
+
.ajax-load-more .CodeMirror pre{
|
1041 |
+
font-size: 13px;
|
1042 |
+
}
|
1043 |
+
.ajax-load-more .CodeMirror-scroll {
|
1044 |
+
overflow-y: hidden;
|
1045 |
+
overflow-x: auto;
|
1046 |
+
}
|
1047 |
+
|
1048 |
+
|
1049 |
+
.ajax-load-more .cm-tag{ /* <li> <h2> html elements */
|
1050 |
+
color: #0a4b83 !important;
|
1051 |
+
}
|
1052 |
+
.ajax-load-more .cm-string{ /* Elements in " " */
|
1053 |
+
color: #d14 !important;
|
1054 |
+
}
|
1055 |
+
.ajax-load-more .cm-attribute{ /* class names */
|
1056 |
+
color: #008080 !important;
|
1057 |
+
}
|
1058 |
+
.ajax-load-more .cm-keyword{ /* if, array, echo */
|
1059 |
+
color: #ae5fb3 !important;
|
1060 |
+
}
|
1061 |
+
.ajax-load-more span.CodeMirror-matchingbracket{
|
1062 |
+
color: #ff0000 !important;
|
1063 |
+
}
|
1064 |
+
.ajax-load-more .CodeMirror span.cm-meta{ /* <?php */
|
1065 |
+
color: #999;
|
1066 |
+
}
|
1067 |
+
.ajax-load-more .CodeMirror span.cm-variable{ /* Function names */
|
1068 |
+
color: #111;
|
1069 |
+
font-weight: 500;
|
1070 |
+
padding: 0 1px;
|
1071 |
+
}
|
1072 |
+
.ajax-load-more .CodeMirror span.cm-number{ /* Numbers */
|
1073 |
+
color: #009999 !important;
|
1074 |
+
}
|
1075 |
+
|
1076 |
+
|
1077 |
+
|
1078 |
|
1079 |
/*
|
1080 |
* Admin screen media queries
|
1107 |
|
1108 |
|
1109 |
|
|
|
1110 |
/*
|
1111 |
* Select2 - form replacement - http://ivaynberg.github.io/select2/
|
1112 |
*
|
1134 |
border: 1px solid #ccc;
|
1135 |
white-space: nowrap;
|
1136 |
line-height: 40px;
|
1137 |
+
color: #333;
|
1138 |
text-decoration: none;
|
1139 |
background: #fff;
|
1140 |
+
background: #f7f7f7;
|
1141 |
border-radius:2px;
|
1142 |
-webkit-background-clip: padding-box;
|
1143 |
-moz-background-clip: padding;
|
admin/editor-build.php
CHANGED
@@ -37,7 +37,7 @@ tinyMCEPopup.onInit.add(AjaxLoadMoreModal.init, AjaxLoadMoreModal);
|
|
37 |
<option value="null" selected="selected">-- <?php _e('Jump to section', ALM_NAME); ?> --</option>
|
38 |
</select>
|
39 |
<p class="intro"><?php _e('Create your own Ajax Load More shortcode by adjusting the values below:', ALM_NAME); ?></p>
|
40 |
-
<?php include (ALM_PATH . '/admin/
|
41 |
<div class="output-wrap">
|
42 |
<a href="javascript:AjaxLoadMoreModal.insert(AjaxLoadMoreModal.local_ed)" id="insert" class="insert_alm"><i class="fa fa-chevron-circle-right"></i> <?php _e('Insert Shortcode', ALM_NAME); ?></a>
|
43 |
<div class="shortcode-display">
|
@@ -47,6 +47,6 @@ tinyMCEPopup.onInit.add(AjaxLoadMoreModal.init, AjaxLoadMoreModal);
|
|
47 |
</div
|
48 |
</div>
|
49 |
<script type="text/javascript" src="<?php echo ALM_ADMIN_URL; ?>js/libs/select2.min.js"></script>
|
50 |
-
<script type="text/javascript" src="<?php echo ALM_ADMIN_URL; ?>js/shortcode-builder.js"></script>
|
51 |
</body>
|
52 |
</html>
|
37 |
<option value="null" selected="selected">-- <?php _e('Jump to section', ALM_NAME); ?> --</option>
|
38 |
</select>
|
39 |
<p class="intro"><?php _e('Create your own Ajax Load More shortcode by adjusting the values below:', ALM_NAME); ?></p>
|
40 |
+
<?php include (ALM_PATH . '/admin/shortcode-builder/shortcode-builder.php'); ?>
|
41 |
<div class="output-wrap">
|
42 |
<a href="javascript:AjaxLoadMoreModal.insert(AjaxLoadMoreModal.local_ed)" id="insert" class="insert_alm"><i class="fa fa-chevron-circle-right"></i> <?php _e('Insert Shortcode', ALM_NAME); ?></a>
|
43 |
<div class="shortcode-display">
|
47 |
</div
|
48 |
</div>
|
49 |
<script type="text/javascript" src="<?php echo ALM_ADMIN_URL; ?>js/libs/select2.min.js"></script>
|
50 |
+
<script type="text/javascript" src="<?php echo ALM_ADMIN_URL; ?>shortcode-builder/js/shortcode-builder.js"></script>
|
51 |
</body>
|
52 |
</html>
|
admin/editor.php
CHANGED
@@ -1,12 +1,17 @@
|
|
1 |
<?php
|
2 |
-
|
|
|
3 |
|
4 |
add_action('init','alm_editor_init');
|
5 |
|
|
|
|
|
6 |
function alm_editor_init() {
|
7 |
wp_enqueue_script( 'jquery' );
|
8 |
}
|
9 |
|
|
|
|
|
10 |
add_action('wp_ajax_fscb', 'alm_ajax_tinymce' );
|
11 |
function alm_ajax_tinymce(){
|
12 |
// check for rights
|
@@ -19,13 +24,18 @@ function alm_ajax_tinymce(){
|
|
19 |
die();
|
20 |
}
|
21 |
|
|
|
|
|
22 |
// registers the buttons for use
|
23 |
function alm_friendly_buttons($buttons) {
|
24 |
array_push($buttons, 'alm_shortcode_button');
|
25 |
return $buttons;
|
26 |
}
|
27 |
|
|
|
|
|
28 |
// filters the tinyMCE buttons and adds our custom buttons
|
|
|
29 |
function alm_shortcode_buttons() {
|
30 |
// Don't bother doing this stuff if the current user lacks permissions
|
31 |
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
|
@@ -37,11 +47,16 @@ function alm_shortcode_buttons() {
|
|
37 |
add_filter('mce_buttons', 'alm_friendly_buttons');
|
38 |
}
|
39 |
}
|
40 |
-
|
41 |
-
|
42 |
|
43 |
// add the button to the tinyMCE bar
|
44 |
-
function alm_tinymce_plugin($plugin_array) {
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
}
|
1 |
<?php
|
2 |
+
|
3 |
+
/* Create shortcode builder button in WYSIWYG editor */
|
4 |
|
5 |
add_action('init','alm_editor_init');
|
6 |
|
7 |
+
|
8 |
+
// Enqueue jQuery in editor
|
9 |
function alm_editor_init() {
|
10 |
wp_enqueue_script( 'jquery' );
|
11 |
}
|
12 |
|
13 |
+
|
14 |
+
//Check for permissions
|
15 |
add_action('wp_ajax_fscb', 'alm_ajax_tinymce' );
|
16 |
function alm_ajax_tinymce(){
|
17 |
// check for rights
|
24 |
die();
|
25 |
}
|
26 |
|
27 |
+
|
28 |
+
|
29 |
// registers the buttons for use
|
30 |
function alm_friendly_buttons($buttons) {
|
31 |
array_push($buttons, 'alm_shortcode_button');
|
32 |
return $buttons;
|
33 |
}
|
34 |
|
35 |
+
|
36 |
+
|
37 |
// filters the tinyMCE buttons and adds our custom buttons
|
38 |
+
add_action('admin_head', 'alm_shortcode_buttons');
|
39 |
function alm_shortcode_buttons() {
|
40 |
// Don't bother doing this stuff if the current user lacks permissions
|
41 |
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
|
47 |
add_filter('mce_buttons', 'alm_friendly_buttons');
|
48 |
}
|
49 |
}
|
50 |
+
|
51 |
+
|
52 |
|
53 |
// add the button to the tinyMCE bar
|
54 |
+
function alm_tinymce_plugin($plugin_array) {
|
55 |
+
|
56 |
+
// Check options for hiding shortcode builder
|
57 |
+
$options = get_option( 'alm_settings' );
|
58 |
+
if($options['_alm_hide_btn'] != '1'){
|
59 |
+
$plugin_array['alm_shortcode_button'] = plugins_url( '/js/editor-btn.js' , __FILE__ );
|
60 |
+
return $plugin_array;
|
61 |
+
}
|
62 |
}
|
admin/img/add.png
CHANGED
Binary file
|
admin/includes/cta/about.php
CHANGED
@@ -1,14 +1,31 @@
|
|
1 |
<div class="cta padding-bottom">
|
2 |
<h3>About the plugin</h3>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
<a href="http://twitter.com/kaptonkaos" target="blank" class="visit"><i class="fa fa-twitter"></i> Follow on Twitter</a>
|
14 |
-
</div>
|
|
1 |
<div class="cta padding-bottom">
|
2 |
<h3>About the plugin</h3>
|
3 |
+
<?php
|
4 |
+
// Parse JSON feed on dashboard
|
5 |
+
function get_about_data($url) {
|
6 |
+
$ch = curl_init();
|
7 |
+
$timeout = 5;
|
8 |
+
curl_setopt($ch, CURLOPT_URL, $url);
|
9 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
10 |
+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
11 |
+
$data = curl_exec($ch);
|
12 |
+
curl_close($ch);
|
13 |
+
return $data;
|
14 |
+
}
|
15 |
+
$about_url = 'http://download.connekthq.com/ajax-load-more/about.json';
|
16 |
+
$about_json = json_decode(get_about_data($about_url));
|
17 |
+
echo $about_json->data->description;
|
18 |
+
print "<ul>";
|
19 |
+
foreach($about_json->data->links as $item) {
|
20 |
+
print '<li><strong><a target="blank" href="'. $item->url .'">'. $item->title .'</a></strong><br>'. $item->description .'</li>';
|
21 |
+
}
|
22 |
+
print "</ul>";
|
23 |
+
|
24 |
+
if($about_json->data->extras){
|
25 |
+
print $about_json->data->extras;
|
26 |
+
print "<br/>";
|
27 |
+
}
|
28 |
+
?>
|
29 |
<a href="http://twitter.com/kaptonkaos" target="blank" class="visit"><i class="fa fa-twitter"></i> Follow on Twitter</a>
|
30 |
+
</div>
|
31 |
+
|
admin/includes/cta/extend.php
CHANGED
@@ -1 +1 @@
|
|
1 |
-
<div class="clear"></div><div class="call-out"><?php _e('Unlock additional
|
1 |
+
<div class="clear"></div><div class="call-out"><?php _e('Unlock additional templates with the <a href="?page=ajax-load-more-add-ons" target="_parent">Custom Repeaters add-on</a>', ALM_NAME); ?> <a class="btn" href="http://connekthq.com/plugins/ajax-load-more/custom-repeaters" target="_blank"><?php _e('More Info', ALM_NAME); ?></a></div>
|
admin/includes/cta/resources.php
CHANGED
@@ -1,10 +1,26 @@
|
|
1 |
<div class="cta padding-bottom">
|
2 |
<h3><?php _e('Help/Resources', ALM_NAME); ?></h3>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
</div>
|
1 |
<div class="cta padding-bottom">
|
2 |
<h3><?php _e('Help/Resources', ALM_NAME); ?></h3>
|
3 |
+
<?php
|
4 |
+
|
5 |
+
// Parse help/resources JSON feed on dashboard
|
6 |
+
function get_resource_data($url) {
|
7 |
+
$ch = curl_init();
|
8 |
+
$timeout = 5;
|
9 |
+
curl_setopt($ch, CURLOPT_URL, $url);
|
10 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
11 |
+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
12 |
+
$data = curl_exec($ch);
|
13 |
+
curl_close($ch);
|
14 |
+
return $data;
|
15 |
+
}
|
16 |
+
$resource_url = 'http://download.connekthq.com/ajax-load-more/resources.json';
|
17 |
+
$resource_json = json_decode(get_resource_data($resource_url));
|
18 |
+
|
19 |
+
print "<ul>";
|
20 |
+
foreach($resource_json->data->resource as $resource) {
|
21 |
+
print '<li><a target="blank" href="'. $resource->url .'">'. $resource->title .'</a></li>';
|
22 |
+
}
|
23 |
+
print "</ul>";
|
24 |
+
?>
|
25 |
+
<?php _e('<a href="https://github.com/dcooney/wordpress-ajax-load-more" target="blank" class="visit"><i class="fa fa-github"></i> Latest build on Github</a>', ALM_NAME); ?>
|
26 |
</div>
|
admin/js/editor-btn.js
CHANGED
@@ -22,6 +22,7 @@
|
|
22 |
editor.addButton('alm_shortcode_button', {
|
23 |
title: 'Insert Ajax load More',
|
24 |
cmd: 'mcebutton',
|
|
|
25 |
image: url + '/../img/add.png'
|
26 |
});
|
27 |
|
22 |
editor.addButton('alm_shortcode_button', {
|
23 |
title: 'Insert Ajax load More',
|
24 |
cmd: 'mcebutton',
|
25 |
+
classes: 'widget btn ajax-load-more-btn',
|
26 |
image: url + '/../img/add.png'
|
27 |
});
|
28 |
|
admin/{js → shortcode-builder/js}/shortcode-builder.js
RENAMED
@@ -50,7 +50,16 @@ jQuery(document).ready(function($) {
|
|
50 |
});
|
51 |
if(post_type_count>0)
|
52 |
output += '"';
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
// ---------------------------
|
56 |
// - Taxonomy Query
|
@@ -227,7 +236,7 @@ jQuery(document).ready(function($) {
|
|
227 |
|
228 |
$('.post_types input[type=checkbox]#chk-post').prop('checked', true).addClass('changed'); //Select post by default
|
229 |
|
230 |
-
$('.repeater select, .post_types input[type=checkbox], .categories select, .tags select, .authors select, .offset select, .posts_per_page select, .scroll_load input[type=radio], .pause_load input[type=radio], .max_pages select, .transition input[type=radio], #taxonomy-select, #tax-operator-select input[type=radio], #post-order, #post-orderby').change(function() {
|
231 |
$(this).addClass('changed');
|
232 |
|
233 |
// If post type is not selected, select 'post'.
|
50 |
});
|
51 |
if(post_type_count>0)
|
52 |
output += '"';
|
53 |
+
|
54 |
+
// ---------------------------
|
55 |
+
// - Post Format
|
56 |
+
// ---------------------------
|
57 |
+
|
58 |
+
var post_format = $('.post_format select').val();
|
59 |
+
if(post_format != '' && post_format != undefined)
|
60 |
+
output += ' post_format="'+post_format+'"';
|
61 |
+
|
62 |
+
|
63 |
|
64 |
// ---------------------------
|
65 |
// - Taxonomy Query
|
236 |
|
237 |
$('.post_types input[type=checkbox]#chk-post').prop('checked', true).addClass('changed'); //Select post by default
|
238 |
|
239 |
+
$('.repeater select, .post_types input[type=checkbox], .post_format select, .categories select, .tags select, .authors select, .offset select, .posts_per_page select, .scroll_load input[type=radio], .pause_load input[type=radio], .max_pages select, .transition input[type=radio], #taxonomy-select, #tax-operator-select input[type=radio], #post-order, #post-orderby').change(function() {
|
240 |
$(this).addClass('changed');
|
241 |
|
242 |
// If post type is not selected, select 'post'.
|
admin/{includes → shortcode-builder}/shortcode-builder.php
RENAMED
@@ -1,12 +1,14 @@
|
|
1 |
<span class="toggle-all"><span class="inner-wrap"><em class="collapse"><?php _e('Collapse All', ALM_NAME); ?></em><em class="expand"><?php _e('Expand All', ALM_NAME); ?></em></span></span>
|
2 |
|
3 |
-
|
|
|
|
|
4 |
// List available repeaters
|
5 |
echo '<div class="row repeater" id="alm-repeaters">';
|
6 |
-
echo '<h3 class="heading">'.__('
|
7 |
echo '<div class="expand-wrap">';
|
8 |
echo '<div class="section-title">';
|
9 |
-
echo '<p>'.__('
|
10 |
echo '</div>';
|
11 |
echo '<div class="wrap"><div class="inner">';
|
12 |
echo '<select name="repeater-select" id="repeater-select">';
|
@@ -49,6 +51,29 @@
|
|
49 |
echo '</div>';
|
50 |
}
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
// List Categories
|
53 |
$cats = get_categories();
|
54 |
if($cats){
|
1 |
<span class="toggle-all"><span class="inner-wrap"><em class="collapse"><?php _e('Collapse All', ALM_NAME); ?></em><em class="expand"><?php _e('Expand All', ALM_NAME); ?></em></span></span>
|
2 |
|
3 |
+
|
4 |
+
<?php
|
5 |
+
|
6 |
// List available repeaters
|
7 |
echo '<div class="row repeater" id="alm-repeaters">';
|
8 |
+
echo '<h3 class="heading">'.__('Template', ALM_NAME). '</h3>';
|
9 |
echo '<div class="expand-wrap">';
|
10 |
echo '<div class="section-title">';
|
11 |
+
echo '<p>'.__('Select your <a href="admin.php?page=ajax-load-more-repeaters" target="_parent">repeater template</a>.', ALM_NAME). '</p>';
|
12 |
echo '</div>';
|
13 |
echo '<div class="wrap"><div class="inner">';
|
14 |
echo '<select name="repeater-select" id="repeater-select">';
|
51 |
echo '</div>';
|
52 |
}
|
53 |
|
54 |
+
// List Post Formats
|
55 |
+
if ( current_theme_supports( 'post-formats' ) ) {
|
56 |
+
$post_formats = get_theme_support( 'post-formats' );
|
57 |
+
if($post_formats){
|
58 |
+
echo '<div class="row checkboxes post_format" id="alm-post-format">';
|
59 |
+
echo '<h3 class="heading">'.__('Post Format', ALM_NAME). '</h3>';
|
60 |
+
echo '<div class="expand-wrap">';
|
61 |
+
echo '<div class="section-title">';
|
62 |
+
echo '<p>'.__('Select a <a href="http://codex.wordpress.org/Post_Formats" target="_blank">Post Format</a> to query.', ALM_NAME). '</p>';
|
63 |
+
echo '</div>';
|
64 |
+
echo '<div class="wrap"><div class="inner"><select name="post-format-select" id="post-format-select">';
|
65 |
+
echo '<option value="" selected="selected">-- ' . __('Select Post Format', ALM_NAME) . ' --</option>';
|
66 |
+
echo '<option name="chk-standard" id="chk-standard" value="chk-standard">' . __('Standard', ALM_NAME) . '</option>';
|
67 |
+
foreach( $post_formats[0] as $post_format ){
|
68 |
+
echo '<option name="chk-'.$post_format.'" id="chk-'.$post_format.'" value="'.$post_format.'">'.ucwords($post_format).'</option>';
|
69 |
+
}
|
70 |
+
echo '</select></div></div>';
|
71 |
+
echo '</div>';
|
72 |
+
echo '</div>';
|
73 |
+
}
|
74 |
+
|
75 |
+
}
|
76 |
+
|
77 |
// List Categories
|
78 |
$cats = get_categories();
|
79 |
if($cats){
|
ajax-load-more.php
CHANGED
@@ -2,18 +2,18 @@
|
|
2 |
/*
|
3 |
Plugin Name: Ajax Load More
|
4 |
Plugin URI: http://connekthq.com/plugins/ajax-load-more
|
5 |
-
Description: A simple
|
6 |
Author: Darren Cooney
|
7 |
Twitter: @KaptonKaos
|
8 |
Author URI: http://connekthq.com
|
9 |
-
Version: 2.1
|
10 |
License: GPL
|
11 |
Copyright: Darren Cooney & Connekt Media
|
12 |
*/
|
13 |
|
14 |
|
15 |
-
define('ALM_VERSION', '2.1
|
16 |
-
define('ALM_RELEASE', '
|
17 |
|
18 |
/*
|
19 |
* alm_install
|
@@ -72,8 +72,8 @@ if( !class_exists('AjaxLoadMore') ):
|
|
72 |
add_action('wp_ajax_ajax_load_more_init', array(&$this, 'alm_query_posts'));
|
73 |
add_action('wp_ajax_nopriv_ajax_load_more_init', array(&$this, 'alm_query_posts'));
|
74 |
add_action('wp_enqueue_scripts', array(&$this, 'alm_enqueue_scripts'));
|
75 |
-
add_action('alm_get_repeater', array(&$this, 'alm_get_current_repeater'));
|
76 |
-
add_shortcode('ajax_load_more', array(&$this, 'alm_shortcode'));
|
77 |
|
78 |
// Allow shortcodes in widget areas
|
79 |
add_filter('widget_text', 'do_shortcode');
|
@@ -82,8 +82,7 @@ if( !class_exists('AjaxLoadMore') ):
|
|
82 |
load_plugin_textdomain( 'ajax-load-more', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
|
83 |
|
84 |
// includes Admin core
|
85 |
-
$this->alm_before_theme();
|
86 |
-
|
87 |
}
|
88 |
|
89 |
|
@@ -110,7 +109,7 @@ if( !class_exists('AjaxLoadMore') ):
|
|
110 |
|
111 |
function alm_enqueue_scripts(){
|
112 |
$options = get_option( 'alm_settings' );
|
113 |
-
wp_enqueue_script( 'ajax-load-more', plugins_url( '/core/js/ajax-load-more.js', __FILE__ ), array('jquery'), '1.1', true );
|
114 |
wp_localize_script(
|
115 |
'ajax-load-more',
|
116 |
'alm_localize',
|
@@ -138,6 +137,7 @@ if( !class_exists('AjaxLoadMore') ):
|
|
138 |
extract(shortcode_atts(array(
|
139 |
'repeater' => 'default',
|
140 |
'post_type' => 'post',
|
|
|
141 |
'category' => '',
|
142 |
'taxonomy' => '',
|
143 |
'taxonomy_terms' => '',
|
@@ -157,27 +157,28 @@ if( !class_exists('AjaxLoadMore') ):
|
|
157 |
'button_label' => 'Older Posts'
|
158 |
),
|
159 |
$atts));
|
160 |
-
|
161 |
-
|
162 |
-
$wrap_element = 'div';
|
163 |
-
if(isset($options['_alm_html5']) || $options['_alm_html5'] == '1'){
|
164 |
-
$wrap_element = 'section';
|
165 |
-
}
|
166 |
$container_element = 'ul';
|
167 |
if($options['_alm_container_type'] == '2'){
|
168 |
$container_element = 'div';
|
169 |
}
|
|
|
170 |
$classname = '';
|
171 |
if(isset($options['_alm_classname'])){
|
172 |
$classname = ' '.$options['_alm_classname'];
|
173 |
}
|
174 |
-
|
175 |
$btn_color = '';
|
176 |
if(isset($options['_alm_btn_color'])){
|
177 |
$btn_color = ' '.$options['_alm_btn_color'];
|
178 |
}
|
179 |
|
180 |
-
|
|
|
|
|
|
|
|
|
181 |
}
|
182 |
|
183 |
|
@@ -188,16 +189,18 @@ if( !class_exists('AjaxLoadMore') ):
|
|
188 |
* @since 2.0.0
|
189 |
*/
|
190 |
|
191 |
-
function alm_query_posts() {
|
192 |
-
|
|
|
193 |
$nonce = $_GET['nonce'];
|
194 |
-
|
195 |
// Check our nonce, if they don't match then bounce!
|
196 |
if (! wp_verify_nonce( $nonce, 'ajax_load_more_nonce' ))
|
197 |
die('Get Bounced!');
|
|
|
198 |
|
199 |
$repeater = (isset($_GET['repeater'])) ? $_GET['repeater'] : 'default';
|
200 |
$postType = (isset($_GET['postType'])) ? $_GET['postType'] : 'post';
|
|
|
201 |
$category = (isset($_GET['category'])) ? $_GET['category'] : '';
|
202 |
$author_id = (isset($_GET['author'])) ? $_GET['author'] : '';
|
203 |
|
@@ -243,7 +246,36 @@ if( !class_exists('AjaxLoadMore') ):
|
|
243 |
$args['post__not_in'] = $exclude;
|
244 |
}
|
245 |
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
// Taxonomy query
|
248 |
if(!empty($taxonomy)){
|
249 |
$the_terms = explode(", ", $taxonomy_terms);
|
@@ -260,12 +292,9 @@ if( !class_exists('AjaxLoadMore') ):
|
|
260 |
|
261 |
|
262 |
// Query by $args
|
263 |
-
|
264 |
$alm_query = new WP_Query( $args );
|
265 |
-
|
266 |
-
|
267 |
// the WP loop
|
268 |
-
|
269 |
if ($alm_query->have_posts()) :
|
270 |
while ($alm_query->have_posts()): $alm_query->the_post();
|
271 |
$file = $repeater;
|
@@ -292,11 +321,11 @@ if( !class_exists('AjaxLoadMore') ):
|
|
292 |
}
|
293 |
}else{
|
294 |
$include = plugin_dir_path( __FILE__ ) . 'core/repeater/default.php';
|
295 |
-
}
|
296 |
-
|
297 |
-
//Include
|
298 |
-
include( $include );
|
299 |
-
|
300 |
endwhile;
|
301 |
endif;
|
302 |
wp_reset_query();
|
2 |
/*
|
3 |
Plugin Name: Ajax Load More
|
4 |
Plugin URI: http://connekthq.com/plugins/ajax-load-more
|
5 |
+
Description: A simple solution for lazy loading WordPress posts and pages with Ajax
|
6 |
Author: Darren Cooney
|
7 |
Twitter: @KaptonKaos
|
8 |
Author URI: http://connekthq.com
|
9 |
+
Version: 2.2.1
|
10 |
License: GPL
|
11 |
Copyright: Darren Cooney & Connekt Media
|
12 |
*/
|
13 |
|
14 |
|
15 |
+
define('ALM_VERSION', '2.2.1');
|
16 |
+
define('ALM_RELEASE', 'September 11, 2014');
|
17 |
|
18 |
/*
|
19 |
* alm_install
|
72 |
add_action('wp_ajax_ajax_load_more_init', array(&$this, 'alm_query_posts'));
|
73 |
add_action('wp_ajax_nopriv_ajax_load_more_init', array(&$this, 'alm_query_posts'));
|
74 |
add_action('wp_enqueue_scripts', array(&$this, 'alm_enqueue_scripts'));
|
75 |
+
add_action('alm_get_repeater', array(&$this, 'alm_get_current_repeater'));
|
76 |
+
add_shortcode('ajax_load_more', array(&$this, 'alm_shortcode'));
|
77 |
|
78 |
// Allow shortcodes in widget areas
|
79 |
add_filter('widget_text', 'do_shortcode');
|
82 |
load_plugin_textdomain( 'ajax-load-more', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
|
83 |
|
84 |
// includes Admin core
|
85 |
+
$this->alm_before_theme();
|
|
|
86 |
}
|
87 |
|
88 |
|
109 |
|
110 |
function alm_enqueue_scripts(){
|
111 |
$options = get_option( 'alm_settings' );
|
112 |
+
wp_enqueue_script( 'ajax-load-more', plugins_url( '/core/js/ajax-load-more.min.js', __FILE__ ), array('jquery'), '1.1', true );
|
113 |
wp_localize_script(
|
114 |
'ajax-load-more',
|
115 |
'alm_localize',
|
137 |
extract(shortcode_atts(array(
|
138 |
'repeater' => 'default',
|
139 |
'post_type' => 'post',
|
140 |
+
'post_format' => '',
|
141 |
'category' => '',
|
142 |
'taxonomy' => '',
|
143 |
'taxonomy_terms' => '',
|
157 |
'button_label' => 'Older Posts'
|
158 |
),
|
159 |
$atts));
|
160 |
+
|
161 |
+
// Get container elements (ul | div)
|
|
|
|
|
|
|
|
|
162 |
$container_element = 'ul';
|
163 |
if($options['_alm_container_type'] == '2'){
|
164 |
$container_element = 'div';
|
165 |
}
|
166 |
+
// Get extra classnames
|
167 |
$classname = '';
|
168 |
if(isset($options['_alm_classname'])){
|
169 |
$classname = ' '.$options['_alm_classname'];
|
170 |
}
|
171 |
+
// Get button color
|
172 |
$btn_color = '';
|
173 |
if(isset($options['_alm_btn_color'])){
|
174 |
$btn_color = ' '.$options['_alm_btn_color'];
|
175 |
}
|
176 |
|
177 |
+
$ajaxloadmore = '<div id="ajax-load-more" class="ajax-load-more-wrap '. $btn_color .'">';
|
178 |
+
$ajaxloadmore .= '<'.$container_element.' class="alm-listing'. $classname . '" data-repeater="'.$repeater.'" data-post-type="'.$post_type.'" data-post-format="'.$post_format.'" data-category="'.$category.'" data-taxonomy="'.$taxonomy.'" data-taxonomy-terms="'.$taxonomy_terms.'" data-taxonomy-operator="'.$taxonomy_operator.'" data-tag="'.$tag.'" data-author="'.$author.'" data-search="'.$search.'" data-order="'.$order.'" data-orderby="'.$orderby.'" data-exclude="'.$exclude.'" data-offset="'.$offset.'" data-posts-per-page="'.$posts_per_page.'" data-scroll="'.$scroll.'" data-max-pages="'.$max_pages.'" data-pause="'. $pause .'" data-button-label="'.$button_label.'" data-transition="'.$transition.'"></'.$container_element.'>';
|
179 |
+
$ajaxloadmore .= '</div>';
|
180 |
+
|
181 |
+
return $ajaxloadmore;
|
182 |
}
|
183 |
|
184 |
|
189 |
* @since 2.0.0
|
190 |
*/
|
191 |
|
192 |
+
function alm_query_posts($bypass = false) {
|
193 |
+
|
194 |
+
if(!$bypass){
|
195 |
$nonce = $_GET['nonce'];
|
|
|
196 |
// Check our nonce, if they don't match then bounce!
|
197 |
if (! wp_verify_nonce( $nonce, 'ajax_load_more_nonce' ))
|
198 |
die('Get Bounced!');
|
199 |
+
}
|
200 |
|
201 |
$repeater = (isset($_GET['repeater'])) ? $_GET['repeater'] : 'default';
|
202 |
$postType = (isset($_GET['postType'])) ? $_GET['postType'] : 'post';
|
203 |
+
$postFormat = (isset($_GET['postFormat'])) ? $_GET['postFormat'] : '';
|
204 |
$category = (isset($_GET['category'])) ? $_GET['category'] : '';
|
205 |
$author_id = (isset($_GET['author'])) ? $_GET['author'] : '';
|
206 |
|
246 |
$args['post__not_in'] = $exclude;
|
247 |
}
|
248 |
|
249 |
+
// Post Format query
|
250 |
+
if(!empty($postFormat)){
|
251 |
+
$format = "post-format-$postFormat";
|
252 |
+
//If query is for standrd we need to filter by NOT IN
|
253 |
+
if($format == 'post-format-standard'){
|
254 |
+
if (($post_formats = get_theme_support('post-formats')) && is_array($post_formats[0]) && count($post_formats[0])) {
|
255 |
+
$terms = array();
|
256 |
+
foreach ($post_formats[0] as $format) {
|
257 |
+
$terms[] = 'post-format-'.$format;
|
258 |
+
}
|
259 |
+
}
|
260 |
+
$args['tax_query'] = array(
|
261 |
+
array(
|
262 |
+
'taxonomy' => 'post_format',
|
263 |
+
'terms' => $terms,
|
264 |
+
'field' => 'slug',
|
265 |
+
'operator' => 'NOT IN'
|
266 |
+
)
|
267 |
+
);
|
268 |
+
}else{
|
269 |
+
$args['tax_query'] = array(
|
270 |
+
array(
|
271 |
+
'taxonomy' => 'post_format',
|
272 |
+
'field' => 'slug',
|
273 |
+
'terms' => array($format),
|
274 |
+
)
|
275 |
+
);
|
276 |
+
}
|
277 |
+
}
|
278 |
+
|
279 |
// Taxonomy query
|
280 |
if(!empty($taxonomy)){
|
281 |
$the_terms = explode(", ", $taxonomy_terms);
|
292 |
|
293 |
|
294 |
// Query by $args
|
|
|
295 |
$alm_query = new WP_Query( $args );
|
296 |
+
|
|
|
297 |
// the WP loop
|
|
|
298 |
if ($alm_query->have_posts()) :
|
299 |
while ($alm_query->have_posts()): $alm_query->the_post();
|
300 |
$file = $repeater;
|
321 |
}
|
322 |
}else{
|
323 |
$include = plugin_dir_path( __FILE__ ) . 'core/repeater/default.php';
|
324 |
+
}
|
325 |
+
|
326 |
+
//Include repeater template
|
327 |
+
include( $include );
|
328 |
+
|
329 |
endwhile;
|
330 |
endif;
|
331 |
wp_reset_query();
|
core/css/ajax-load-more.css
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
/*
|
2 |
* WordPress Ajax Load More
|
3 |
* http://wordpress.org/plugins/ajax-load-more/
|
4 |
-
|
5 |
* https://github.com/dcooney/wordpress-ajax-load-more
|
6 |
*
|
7 |
-
* Copyright 2014 Connekt Media - http://connekthq.com
|
8 |
* Free to use under the GPLv2 license.
|
9 |
* http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*
|
@@ -19,7 +18,7 @@ button.alm-load-more-btn{
|
|
19 |
width:auto;
|
20 |
height: 42px;
|
21 |
line-height: 44px;
|
22 |
-
background: #
|
23 |
color:#fff;
|
24 |
border: none;
|
25 |
-webkit-border-radius:3px;
|
@@ -48,17 +47,16 @@ button.alm-load-more-btn{
|
|
48 |
cursor: pointer;
|
49 |
}
|
50 |
button.alm-load-more-btn:hover{
|
51 |
-
background-color: #
|
52 |
color: #fff;
|
53 |
text-decoration: none;
|
54 |
}
|
55 |
button.alm-load-more-btn:active{
|
56 |
-
-webkit-box-shadow: inset 0
|
57 |
-
-moz-box-shadow: inset 0
|
58 |
-
box-shadow: inset 0
|
59 |
text-decoration: none;
|
60 |
-
}
|
61 |
-
|
62 |
|
63 |
/* Loading */
|
64 |
button.alm-load-more-btn.loading{
|
@@ -70,7 +68,7 @@ button.alm-load-more-btn{
|
|
70 |
cursor: default;
|
71 |
opacity: 0.2;
|
72 |
filter: alpha(opacity=20);
|
73 |
-
background-color: #
|
74 |
-webkit-box-shadow: none !important;
|
75 |
-moz-box-shadow: none !important;
|
76 |
box-shadow: none !important;
|
@@ -93,7 +91,7 @@ button.alm-load-more-btn{
|
|
93 |
-moz-border-radius:3px;
|
94 |
border-radius:3px;
|
95 |
display: inline-block;
|
96 |
-
z-index:
|
97 |
content: '';
|
98 |
position: absolute;
|
99 |
left: 0;
|
@@ -111,53 +109,65 @@ button.alm-load-more-btn{
|
|
111 |
}
|
112 |
|
113 |
/* Blue */
|
114 |
-
.ajax-load-more-wrap.blue button
|
115 |
background-color: #529ecf;
|
116 |
}
|
117 |
-
.ajax-load-more-wrap.blue button
|
118 |
-
.ajax-load-more-wrap.blue button
|
119 |
background-color: #468ebb;
|
120 |
}
|
121 |
|
122 |
/* green */
|
123 |
-
.ajax-load-more-wrap.green button
|
124 |
background-color: #80bb46;
|
125 |
}
|
126 |
-
.ajax-load-more-wrap.green button
|
127 |
-
.ajax-load-more-wrap.green button
|
128 |
background-color: #6fa43c;
|
129 |
}
|
130 |
-
|
131 |
|
132 |
/* red */
|
133 |
-
.ajax-load-more-wrap.red button
|
134 |
background-color: #ca4b4b;
|
135 |
}
|
136 |
-
.ajax-load-more-wrap.red button
|
137 |
-
.ajax-load-more-wrap.red button
|
138 |
background-color: #b13b3b;
|
139 |
}
|
140 |
|
141 |
-
|
142 |
/* purple */
|
143 |
-
.ajax-load-more-wrap.purple button
|
144 |
background-color: #b14fae;
|
145 |
}
|
146 |
-
.ajax-load-more-wrap.purple button
|
147 |
-
.ajax-load-more-wrap.purple button
|
148 |
background-color: #9c4399;
|
149 |
-
}
|
150 |
-
|
151 |
|
152 |
/* grey */
|
153 |
-
.ajax-load-more-wrap.grey button
|
154 |
background-color: #999;
|
155 |
}
|
156 |
-
.ajax-load-more-wrap.grey button
|
157 |
-
.ajax-load-more-wrap.grey button
|
158 |
background-color: #666;
|
159 |
-
}
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
|
163 |
/*
|
@@ -167,13 +177,13 @@ button.alm-load-more-btn{
|
|
167 |
*/
|
168 |
|
169 |
.alm-listing{
|
170 |
-
margin: 0
|
171 |
padding: 0;
|
172 |
}
|
173 |
.alm-listing li{
|
174 |
background: none;
|
175 |
-
margin: 0 0
|
176 |
-
padding: 0 0 0
|
177 |
overflow: hidden;
|
178 |
position: relative;
|
179 |
list-style: none;
|
1 |
/*
|
2 |
* WordPress Ajax Load More
|
3 |
* http://wordpress.org/plugins/ajax-load-more/
|
|
|
4 |
* https://github.com/dcooney/wordpress-ajax-load-more
|
5 |
*
|
6 |
+
* Copyright 2014 Connekt Media - http://connekthq.com
|
7 |
* Free to use under the GPLv2 license.
|
8 |
* http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
*
|
18 |
width:auto;
|
19 |
height: 42px;
|
20 |
line-height: 44px;
|
21 |
+
background: #ed7070;
|
22 |
color:#fff;
|
23 |
border: none;
|
24 |
-webkit-border-radius:3px;
|
47 |
cursor: pointer;
|
48 |
}
|
49 |
button.alm-load-more-btn:hover{
|
50 |
+
background-color: #d34646;
|
51 |
color: #fff;
|
52 |
text-decoration: none;
|
53 |
}
|
54 |
button.alm-load-more-btn:active{
|
55 |
+
-webkit-box-shadow: inset 0 3px 2px rgba(0, 0, 0, 0.1);
|
56 |
+
-moz-box-shadow: inset 0 3px 2px rgba(0, 0, 0, 0.1);
|
57 |
+
box-shadow: inset 0 3px 2px rgba(0, 0, 0, 0.1);
|
58 |
text-decoration: none;
|
59 |
+
}
|
|
|
60 |
|
61 |
/* Loading */
|
62 |
button.alm-load-more-btn.loading{
|
68 |
cursor: default;
|
69 |
opacity: 0.2;
|
70 |
filter: alpha(opacity=20);
|
71 |
+
background-color: #ed7070;
|
72 |
-webkit-box-shadow: none !important;
|
73 |
-moz-box-shadow: none !important;
|
74 |
box-shadow: none !important;
|
91 |
-moz-border-radius:3px;
|
92 |
border-radius:3px;
|
93 |
display: inline-block;
|
94 |
+
z-index: 0;
|
95 |
content: '';
|
96 |
position: absolute;
|
97 |
left: 0;
|
109 |
}
|
110 |
|
111 |
/* Blue */
|
112 |
+
.ajax-load-more-wrap.blue button.alm-load-more-btn{
|
113 |
background-color: #529ecf;
|
114 |
}
|
115 |
+
.ajax-load-more-wrap.blue button.alm-load-more-btn:hover,
|
116 |
+
.ajax-load-more-wrap.blue button.alm-load-more-btn.done{
|
117 |
background-color: #468ebb;
|
118 |
}
|
119 |
|
120 |
/* green */
|
121 |
+
.ajax-load-more-wrap.green button.alm-load-more-btn{
|
122 |
background-color: #80bb46;
|
123 |
}
|
124 |
+
.ajax-load-more-wrap.green button.alm-load-more-btn:hover,
|
125 |
+
.ajax-load-more-wrap.green button.alm-load-more-btn.done{
|
126 |
background-color: #6fa43c;
|
127 |
}
|
|
|
128 |
|
129 |
/* red */
|
130 |
+
.ajax-load-more-wrap.red button.alm-load-more-btn{
|
131 |
background-color: #ca4b4b;
|
132 |
}
|
133 |
+
.ajax-load-more-wrap.red button.alm-load-more-btn:hover,
|
134 |
+
.ajax-load-more-wrap.red button.alm-load-more-btn.done{
|
135 |
background-color: #b13b3b;
|
136 |
}
|
137 |
|
|
|
138 |
/* purple */
|
139 |
+
.ajax-load-more-wrap.purple button.alm-load-more-btn{
|
140 |
background-color: #b14fae;
|
141 |
}
|
142 |
+
.ajax-load-more-wrap.purple button.alm-load-more-btn:hover,
|
143 |
+
.ajax-load-more-wrap.purple button.alm-load-more-btn.done{
|
144 |
background-color: #9c4399;
|
145 |
+
}
|
|
|
146 |
|
147 |
/* grey */
|
148 |
+
.ajax-load-more-wrap.grey button.alm-load-more-btn{
|
149 |
background-color: #999;
|
150 |
}
|
151 |
+
.ajax-load-more-wrap.grey button.alm-load-more-btn:hover,
|
152 |
+
.ajax-load-more-wrap.grey button.alm-load-more-btn.done{
|
153 |
background-color: #666;
|
154 |
+
}
|
155 |
|
156 |
+
/* white */
|
157 |
+
.ajax-load-more-wrap.white button.alm-load-more-btn{
|
158 |
+
background-color: #fff;
|
159 |
+
color: #666;
|
160 |
+
border: 1px solid #efefef;
|
161 |
+
}
|
162 |
+
.ajax-load-more-wrap.white button.alm-load-more-btn:hover,
|
163 |
+
.ajax-load-more-wrap.white button.alm-load-more-btn.done{
|
164 |
+
background-color: #fff;
|
165 |
+
color: #333;
|
166 |
+
}
|
167 |
+
.ajax-load-more-wrap.white button.alm-load-more-btn.done{
|
168 |
+
border-color: #fff;
|
169 |
+
}
|
170 |
+
|
171 |
|
172 |
|
173 |
/*
|
177 |
*/
|
178 |
|
179 |
.alm-listing{
|
180 |
+
margin: 0;
|
181 |
padding: 0;
|
182 |
}
|
183 |
.alm-listing li{
|
184 |
background: none;
|
185 |
+
margin: 0 0 30px;
|
186 |
+
padding: 0 0 0 170px;
|
187 |
overflow: hidden;
|
188 |
position: relative;
|
189 |
list-style: none;
|
core/js/ajax-load-more.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* http://wordpress.org/plugins/ajax-load-more/
|
4 |
* https://github.com/dcooney/wordpress-ajax-load-more
|
5 |
*
|
6 |
-
* Copyright 2014 Connekt Media - http://
|
7 |
* Free to use under the GPLv2 license.
|
8 |
* http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
*
|
@@ -44,7 +44,7 @@
|
|
44 |
$pause = false;
|
45 |
}
|
46 |
|
47 |
-
// Select the repeater
|
48 |
if ($repeater === undefined) {
|
49 |
$repeater = 'default';
|
50 |
}
|
@@ -54,8 +54,9 @@
|
|
54 |
$max_pages = 5;
|
55 |
}
|
56 |
if ($max_pages === 'none') {
|
57 |
-
$max_pages =
|
58 |
}
|
|
|
59 |
// select the transition
|
60 |
if ($transition === undefined) {
|
61 |
$transition = 'slide';
|
@@ -64,18 +65,21 @@
|
|
64 |
} else {
|
65 |
$transition = 'slide';
|
66 |
}
|
|
|
67 |
// Define offset
|
68 |
if ($content.data('offset') === undefined) {
|
69 |
$offset = 0;
|
70 |
} else {
|
71 |
$offset = $content.data('offset');
|
72 |
}
|
|
|
73 |
// Define button text
|
74 |
if ($content.data('button-label') === undefined) {
|
75 |
$button_label = 'Older Posts';
|
76 |
} else {
|
77 |
$button_label = $content.data('button-label');
|
78 |
}
|
|
|
79 |
// Define on Scroll event
|
80 |
if ($content.data('scroll') === undefined) {
|
81 |
$scroll = true;
|
@@ -83,16 +87,16 @@
|
|
83 |
$scroll = false;
|
84 |
} else {
|
85 |
$scroll = true;
|
86 |
-
}
|
87 |
-
|
88 |
-
// Append load more button tp .ajax-load-more
|
89 |
-
$el.append('<div class="'+$prefix+'btn-wrap"><button id="load-more" class="'+$prefix+'load-more-btn more">' + $button_label + '</button></div>');
|
90 |
-
var $button = $('.alm-load-more-btn', $el);
|
91 |
|
92 |
-
//Parse Post
|
93 |
var $post_type = $content.data('post-type');
|
94 |
$post_type = $post_type.split(",");
|
95 |
|
|
|
|
|
|
|
|
|
96 |
|
97 |
/* AjaxLoadMore.loadPosts()
|
98 |
*
|
@@ -108,8 +112,9 @@
|
|
108 |
data: {
|
109 |
action: 'ajax_load_more_init',
|
110 |
nonce: alm_localize.alm_nonce,
|
111 |
-
postType: $post_type,
|
112 |
repeater: $repeater,
|
|
|
|
|
113 |
category: $content.data('category'),
|
114 |
author: $content.data('author'),
|
115 |
taxonomy: $content.data('taxonomy'),
|
@@ -176,8 +181,12 @@
|
|
176 |
};
|
177 |
|
178 |
|
179 |
-
|
180 |
-
|
|
|
|
|
|
|
|
|
181 |
if($pause === true){
|
182 |
$pause = false;
|
183 |
AjaxLoadMore.loadPosts();
|
@@ -187,7 +196,7 @@
|
|
187 |
page++;
|
188 |
AjaxLoadMore.loadPosts();
|
189 |
}
|
190 |
-
});
|
191 |
|
192 |
|
193 |
/* AjaxLoadMore.isVisible()
|
@@ -201,16 +210,16 @@
|
|
201 |
visible = true;
|
202 |
}
|
203 |
return visible;
|
204 |
-
}
|
205 |
|
206 |
|
207 |
-
/*
|
208 |
*
|
209 |
-
*
|
210 |
-
* @since
|
211 |
*/
|
212 |
if ($scroll) {
|
213 |
-
$window.scroll
|
214 |
if(AjaxLoadMore.isVisible()){
|
215 |
var content_offset = $button.offset();
|
216 |
if (!$loading && !$finished && $window.scrollTop() >= Math.round(content_offset.top - ($window.height() - 150)) && page < ($max_pages - 1) && proceed) {
|
@@ -220,7 +229,7 @@
|
|
220 |
}
|
221 |
}
|
222 |
});
|
223 |
-
}
|
224 |
|
225 |
|
226 |
//Check for pause variable
|
@@ -232,7 +241,7 @@
|
|
232 |
}
|
233 |
|
234 |
|
235 |
-
//flag to prevent unnecessary loading of post on init. Hold for
|
236 |
setTimeout(function() {
|
237 |
proceed = true;
|
238 |
}, 1000);
|
@@ -245,19 +254,22 @@
|
|
245 |
};
|
246 |
};
|
247 |
|
248 |
-
|
|
|
|
|
|
|
249 |
*
|
250 |
* Initiate all instances of Ajax load More
|
251 |
* @since 2.1.2
|
252 |
*/
|
253 |
$.fn.ajaxloadmore = function() {
|
254 |
return this.each(function() {
|
255 |
-
|
256 |
});
|
257 |
-
}
|
258 |
|
259 |
/*
|
260 |
-
*
|
261 |
* @since 2.1.2
|
262 |
*/
|
263 |
if($(".ajax-load-more-wrap").length)
|
3 |
* http://wordpress.org/plugins/ajax-load-more/
|
4 |
* https://github.com/dcooney/wordpress-ajax-load-more
|
5 |
*
|
6 |
+
* Copyright 2014 Connekt Media - http://connekthq.com
|
7 |
* Free to use under the GPLv2 license.
|
8 |
* http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
*
|
44 |
$pause = false;
|
45 |
}
|
46 |
|
47 |
+
// Select the repeater template
|
48 |
if ($repeater === undefined) {
|
49 |
$repeater = 'default';
|
50 |
}
|
54 |
$max_pages = 5;
|
55 |
}
|
56 |
if ($max_pages === 'none') {
|
57 |
+
$max_pages = 1000000;
|
58 |
}
|
59 |
+
|
60 |
// select the transition
|
61 |
if ($transition === undefined) {
|
62 |
$transition = 'slide';
|
65 |
} else {
|
66 |
$transition = 'slide';
|
67 |
}
|
68 |
+
|
69 |
// Define offset
|
70 |
if ($content.data('offset') === undefined) {
|
71 |
$offset = 0;
|
72 |
} else {
|
73 |
$offset = $content.data('offset');
|
74 |
}
|
75 |
+
|
76 |
// Define button text
|
77 |
if ($content.data('button-label') === undefined) {
|
78 |
$button_label = 'Older Posts';
|
79 |
} else {
|
80 |
$button_label = $content.data('button-label');
|
81 |
}
|
82 |
+
|
83 |
// Define on Scroll event
|
84 |
if ($content.data('scroll') === undefined) {
|
85 |
$scroll = true;
|
87 |
$scroll = false;
|
88 |
} else {
|
89 |
$scroll = true;
|
90 |
+
}
|
|
|
|
|
|
|
|
|
91 |
|
92 |
+
// Parse multiple Post Types
|
93 |
var $post_type = $content.data('post-type');
|
94 |
$post_type = $post_type.split(",");
|
95 |
|
96 |
+
// Append 'load More' button to .ajax-load-more-wrap
|
97 |
+
$el.append('<div class="'+$prefix+'btn-wrap"><button id="load-more" class="'+$prefix+'load-more-btn more">' + $button_label + '</button></div>');
|
98 |
+
var $button = $('.alm-load-more-btn', $el);
|
99 |
+
|
100 |
|
101 |
/* AjaxLoadMore.loadPosts()
|
102 |
*
|
112 |
data: {
|
113 |
action: 'ajax_load_more_init',
|
114 |
nonce: alm_localize.alm_nonce,
|
|
|
115 |
repeater: $repeater,
|
116 |
+
postType: $post_type,
|
117 |
+
postFormat: $content.data('post-format'),
|
118 |
category: $content.data('category'),
|
119 |
author: $content.data('author'),
|
120 |
taxonomy: $content.data('taxonomy'),
|
181 |
};
|
182 |
|
183 |
|
184 |
+
/* Button onClick()
|
185 |
+
*
|
186 |
+
* Load more button click event
|
187 |
+
* @since 1.0.0
|
188 |
+
*/
|
189 |
+
$button.on('click', function() {
|
190 |
if($pause === true){
|
191 |
$pause = false;
|
192 |
AjaxLoadMore.loadPosts();
|
196 |
page++;
|
197 |
AjaxLoadMore.loadPosts();
|
198 |
}
|
199 |
+
});
|
200 |
|
201 |
|
202 |
/* AjaxLoadMore.isVisible()
|
210 |
visible = true;
|
211 |
}
|
212 |
return visible;
|
213 |
+
};
|
214 |
|
215 |
|
216 |
+
/* Window scroll and touchmove events
|
217 |
*
|
218 |
+
* Load posts as user scrolls the page
|
219 |
+
* @since 1.0
|
220 |
*/
|
221 |
if ($scroll) {
|
222 |
+
$window.bind("scroll touchstart", function() {
|
223 |
if(AjaxLoadMore.isVisible()){
|
224 |
var content_offset = $button.offset();
|
225 |
if (!$loading && !$finished && $window.scrollTop() >= Math.round(content_offset.top - ($window.height() - 150)) && page < ($max_pages - 1) && proceed) {
|
229 |
}
|
230 |
}
|
231 |
});
|
232 |
+
}
|
233 |
|
234 |
|
235 |
//Check for pause variable
|
241 |
}
|
242 |
|
243 |
|
244 |
+
//flag to prevent unnecessary loading of post on init. Hold for 1 second
|
245 |
setTimeout(function() {
|
246 |
proceed = true;
|
247 |
}, 1000);
|
254 |
};
|
255 |
};
|
256 |
|
257 |
+
// End $.ajaxloadmore
|
258 |
+
|
259 |
+
|
260 |
+
/* $.fn.ajaxloadmore()
|
261 |
*
|
262 |
* Initiate all instances of Ajax load More
|
263 |
* @since 2.1.2
|
264 |
*/
|
265 |
$.fn.ajaxloadmore = function() {
|
266 |
return this.each(function() {
|
267 |
+
$.ajaxloadmore($(this));
|
268 |
});
|
269 |
+
};
|
270 |
|
271 |
/*
|
272 |
+
* Initiate Ajax load More if div is present on screen
|
273 |
* @since 2.1.2
|
274 |
*/
|
275 |
if($(".ajax-load-more-wrap").length)
|
core/js/ajax-load-more.min.js
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* WordPress Ajax Load More
|
3 |
+
* http://wordpress.org/plugins/ajax-load-more/
|
4 |
+
* https://github.com/dcooney/wordpress-ajax-load-more
|
5 |
+
*
|
6 |
+
* Copyright 2014 Connekt Media - http://connekthq.com
|
7 |
+
* Free to use under the GPLv2 license.
|
8 |
+
* http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
+
*
|
10 |
+
* Author: Darren Cooney
|
11 |
+
* Twitter: @KaptonKaos
|
12 |
+
*/
|
13 |
+
|
14 |
+
(function(e){"use strict";e.ajaxloadmore=function(t){var n={},r=0,i=300,s=false,o=true,u=true,a=false,f=e(window),l="",c,h=t,p=e(".alm-listing",h),d=true,v="alm-",m=p.data("repeater"),g=p.data("max-pages"),y=p.data("pause"),b=p.data("offset"),w=p.data("transition"),E=p.data("posts-per-page");e(window).scrollTop(0);if(y===undefined){y=false}if(m===undefined){m="default"}if(g===undefined){g=5}if(g==="none"){g=1e6}if(w===undefined){w="slide"}else if(w==="fade"){w="fade"}else{w="slide"}if(p.data("offset")===undefined){b=0}else{b=p.data("offset")}if(p.data("button-label")===undefined){l="Older Posts"}else{l=p.data("button-label")}if(p.data("scroll")===undefined){d=true}else if(p.data("scroll")===false){d=false}else{d=true}var S=p.data("post-type");S=S.split(",");h.append('<div class="'+v+'btn-wrap"><button id="load-more" class="'+v+'load-more-btn more">'+l+"</button></div>");var x=e(".alm-load-more-btn",h);n.loadPosts=function(){x.addClass("loading");u=true;e.ajax({type:"GET",url:alm_localize.ajaxurl,data:{action:"ajax_load_more_init",nonce:alm_localize.alm_nonce,repeater:m,postType:S,postFormat:p.data("post-format"),category:p.data("category"),author:p.data("author"),taxonomy:p.data("taxonomy"),taxonomy_terms:p.data("taxonomy-terms"),taxonomy_operator:p.data("taxonomy-operator"),tag:p.data("tag"),order:p.data("order"),orderby:p.data("orderby"),search:p.data("search"),exclude:p.data("exclude"),numPosts:p.data("posts-per-page"),pageNumber:r,offset:b},dataType:"html",beforeSend:function(){if(r!=1){x.addClass("loading")}},success:function(t){c=e(t);if(o){x.text(l);o=false}if(c.length>0){var n=e('<div class="'+v+'reveal"/>');n.append(c);n.hide();p.append(n);if(w==="fade"){n.fadeIn(i,"alm_easeInOutQuad",function(){u=false;x.delay(i).removeClass("loading");if(c.length<E){a=true;x.addClass("done")}})}else{n.slideDown(i,"alm_easeInOutQuad",function(){u=false;x.delay(i).removeClass("loading");if(c.length<E){a=true;x.addClass("done")}})}}else{x.delay(i).removeClass("loading").addClass("done");u=false;a=true}},error:function(e,t,n){u=false;x.removeClass("loading")}})};x.on("click",function(){if(y===true){y=false;n.loadPosts()}if(!u&&!a&&!e(this).hasClass("done")){u=true;r++;n.loadPosts()}});n.isVisible=function(){var e=false;if(h.is(":visible")){e=true}return e};if(d){f.bind("scroll touchstart",function(){if(n.isVisible()){var e=x.offset();if(!u&&!a&&f.scrollTop()>=Math.round(e.top-(f.height()-150))&&r<g-1&&s){u=true;r++;n.loadPosts()}}})}if(y===true){x.text(l);u=false}else{n.loadPosts()}setTimeout(function(){s=true},1e3);e.easing.alm_easeInOutQuad=function(e,t,n,r,i){if((t/=i/2)<1)return r/2*t*t+n;return-r/2*(--t*(t-2)-1)+n}};e.fn.ajaxloadmore=function(){return this.each(function(){e.ajaxloadmore(e(this))})};if(e(".ajax-load-more-wrap").length)e(".ajax-load-more-wrap").ajaxloadmore()})(jQuery)
|
core/repeater/default.php
CHANGED
@@ -1 +1 @@
|
|
1 |
-
<li><?php if ( has_post_thumbnail() ) { the_post_thumbnail(array(
|
1 |
+
<li><?php if ( has_post_thumbnail() ) { the_post_thumbnail(array(150,150));}?><h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3><p class="entry-meta"><?php the_time("F d, Y"); ?></p><?php the_excerpt(); ?></li>
|
lang/ajax-load-more.pot
CHANGED
@@ -1,246 +1,277 @@
|
|
1 |
msgid ""
|
2 |
msgstr ""
|
3 |
"Project-Id-Version: Ajax Load More\n"
|
4 |
-
"POT-Creation-Date: 2014-
|
5 |
-
"PO-Revision-Date: 2014-
|
6 |
-
"Last-Translator: Darren Cooney <
|
7 |
"Language-Team: \n"
|
8 |
"Language: en_CA\n"
|
9 |
"MIME-Version: 1.0\n"
|
10 |
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
"Content-Transfer-Encoding: 8bit\n"
|
12 |
-
"X-Generator: Poedit 1.6.
|
13 |
"X-Poedit-Basepath: .\n"
|
14 |
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
15 |
"X-Poedit-KeywordsList: __;_e\n"
|
16 |
"X-Poedit-SearchPath-0: ..\n"
|
17 |
|
18 |
-
#: ../admin/admin.php:
|
19 |
-
msgid "Ajax
|
20 |
msgstr ""
|
21 |
|
22 |
-
#: ../admin/admin.php:
|
23 |
msgid "The library of available templates to use throughout your theme"
|
24 |
msgstr ""
|
25 |
|
26 |
-
#: ../admin/admin.php:
|
27 |
-
msgid "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
msgstr ""
|
29 |
|
30 |
-
#: ../admin/admin.php:
|
31 |
-
msgid "Enter the HTML and PHP for the default template"
|
32 |
msgstr ""
|
33 |
|
34 |
-
#: ../admin/admin.php:
|
35 |
msgid "Save Template"
|
36 |
msgstr ""
|
37 |
|
38 |
-
#: ../admin/admin.php:
|
39 |
msgid "Saving data..."
|
40 |
msgstr ""
|
41 |
|
42 |
-
#: ../admin/admin.php:
|
43 |
-
msgid "
|
44 |
msgstr ""
|
45 |
|
46 |
-
#: ../admin/admin.php:
|
47 |
-
msgid "Something went wrong and the data could not be saved
|
48 |
msgstr ""
|
49 |
|
50 |
-
#: ../admin/admin.php:
|
51 |
msgid "Templating Help"
|
52 |
msgstr ""
|
53 |
|
54 |
-
#: ../admin/admin.php:
|
55 |
msgid "What is a repeater template?"
|
56 |
msgstr ""
|
57 |
|
58 |
-
#: ../admin/admin.php:
|
59 |
msgid ""
|
60 |
"A repeater template is a snippet of code that will execute over and over "
|
61 |
"within a <a href=\"http://codex.wordpress.org/The_Loop\" target=\"_blank"
|
62 |
"\">WordPress loop</a>.</p>"
|
63 |
msgstr ""
|
64 |
|
65 |
-
#: ../admin/admin.php:
|
66 |
msgid "Can I include PHP in the repeater template?"
|
67 |
msgstr ""
|
68 |
|
69 |
-
#: ../admin/admin.php:
|
70 |
msgid ""
|
71 |
"Yes, PHP and core WordPress functions such as, <code>the_title()</code> and "
|
72 |
"<code>the_permalink()</code> are required.</p>"
|
73 |
msgstr ""
|
74 |
|
75 |
-
#: ../admin/admin.php:
|
76 |
msgid "Tips and Tricks"
|
77 |
msgstr ""
|
78 |
|
79 |
-
#: ../admin/admin.php:
|
80 |
msgid ""
|
81 |
"Always open and close your templates with an HTML element. In some rare "
|
82 |
"cases data may not be displayed if not wrapped in HTML.<br/>e.g. <code><"
|
83 |
"li> </li></code> or <code><div> </div></code>"
|
84 |
msgstr ""
|
85 |
|
86 |
-
#: ../admin/admin.php:
|
87 |
-
msgid "Ajax
|
88 |
msgstr ""
|
89 |
|
90 |
-
#: ../admin/admin.php:
|
91 |
msgid ""
|
92 |
"Create your own Ajax Load More <a href=\"http://en.support.wordpress.com/"
|
93 |
"shortcodes/\" target=\"_blank\">shortcode</a> by adjusting the values below"
|
94 |
msgstr ""
|
95 |
|
96 |
-
#: ../admin/admin.php:
|
97 |
msgid "Back to Top"
|
98 |
msgstr ""
|
99 |
|
100 |
-
#: ../admin/admin.php:
|
101 |
msgid "Shortcode Output"
|
102 |
msgstr ""
|
103 |
|
104 |
-
#: ../admin/admin.php:
|
105 |
msgid ""
|
106 |
"Copy and paste the following shortcode into the content editor or widget "
|
107 |
"area of your theme."
|
108 |
msgstr ""
|
109 |
|
110 |
-
#: ../admin/admin.php:
|
111 |
msgid "Copy"
|
112 |
msgstr ""
|
113 |
|
114 |
-
#: ../admin/admin.php:
|
115 |
msgid "Did you know?"
|
116 |
msgstr ""
|
117 |
|
118 |
-
#: ../admin/admin.php:
|
119 |
msgid ""
|
120 |
"<p class=\"addon-intro\">You can generate shortcodes while editing pages!</"
|
121 |
-
"p><p>
|
122 |
-
"
|
123 |
-
"
|
124 |
msgstr ""
|
125 |
|
126 |
-
#: ../admin/admin.php:
|
127 |
-
msgid "Ajax
|
128 |
msgstr ""
|
129 |
|
130 |
-
#: ../admin/admin.php:
|
131 |
msgid "A collection of everyday shortcode usages and implementation examples"
|
132 |
msgstr ""
|
133 |
|
134 |
-
#: ../admin/admin.php:
|
135 |
msgid "Author.php"
|
136 |
msgstr ""
|
137 |
|
138 |
-
#: ../admin/admin.php:
|
139 |
msgid "Shortcode for use on author archive pages."
|
140 |
msgstr ""
|
141 |
|
142 |
-
#: ../admin/admin.php:
|
143 |
msgid "Category.php"
|
144 |
msgstr ""
|
145 |
|
146 |
-
#: ../admin/admin.php:
|
147 |
msgid "Shortcode for use on category archive pages."
|
148 |
msgstr ""
|
149 |
|
150 |
-
#: ../admin/admin.php:
|
151 |
msgid "Excluding Posts"
|
152 |
msgstr ""
|
153 |
|
154 |
-
#: ../admin/admin.php:
|
155 |
msgid "Shortcode for excluding an array of posts."
|
156 |
msgstr ""
|
157 |
|
158 |
-
#: ../admin/admin.php:
|
159 |
msgid "Tag.php"
|
160 |
msgstr ""
|
161 |
|
162 |
-
#: ../admin/admin.php:
|
163 |
msgid "Shortcode for use on tag archive pages."
|
164 |
msgstr ""
|
165 |
|
166 |
-
#: ../admin/admin.php:
|
167 |
msgid "Request Examples"
|
168 |
msgstr ""
|
169 |
|
170 |
-
#: ../admin/admin.php:
|
171 |
msgid ""
|
172 |
"If you're having issue's with functionality, please submit example requests "
|
173 |
"through the <a href=\"https://github.com/dcooney/wordpress-ajax-load-more\" "
|
174 |
"target=\"_blank\">GitHub repository</a>. "
|
175 |
msgstr ""
|
176 |
|
177 |
-
#: ../admin/admin.php:
|
178 |
-
msgid "Ajax
|
179 |
msgstr ""
|
180 |
|
181 |
-
#: ../admin/admin.php:
|
182 |
msgid ""
|
183 |
"The following Add-ons are available to increase the functionality of Ajax "
|
184 |
"Load More."
|
185 |
msgstr ""
|
186 |
|
187 |
-
#: ../admin/admin.php:
|
188 |
msgid "Custom Repeaters"
|
189 |
msgstr ""
|
190 |
|
191 |
-
#: ../admin/admin.php:
|
192 |
msgid ""
|
193 |
-
"Unlock additional repeater templates and keep your
|
194 |
-
"fresh
|
195 |
msgstr ""
|
196 |
|
197 |
-
#: ../admin/admin.php:
|
198 |
msgid ""
|
199 |
"The Custom Repeaters add-on will add <strong>five</strong> additional <a "
|
200 |
"href=\"?page=ajax-load-more-repeaters\">repeaters</a> and allow you to "
|
201 |
"select unique repeaters for different content types throughout your theme.</"
|
202 |
-
"p>
|
203 |
-
" <p>It's easy, seriously! Simply build each <a href=\"?"
|
204 |
-
"page=ajax-load-more-repeaters\">repeater</a> just the way you want them, "
|
205 |
-
"then select a template from the list of available templates while building "
|
206 |
-
"your <a href=\"?page=ajax-load-more-shortcode-builder\">shortcode</a>.</"
|
207 |
-
"p><p><strong>Read/Write Access is required!</strong></p>"
|
208 |
msgstr ""
|
209 |
|
210 |
-
#: ../admin/admin.php:
|
211 |
msgid "About Add-ons"
|
212 |
msgstr ""
|
213 |
|
214 |
-
#: ../admin/admin.php:
|
215 |
msgid ""
|
216 |
"Add-ons are installed as a separate plugin and will receive plug-in update "
|
217 |
"notifications. "
|
218 |
msgstr ""
|
219 |
|
220 |
-
#: ../admin/admin.php:
|
221 |
-
msgid "
|
222 |
msgstr ""
|
223 |
|
224 |
-
#: ../admin/admin.php:
|
225 |
-
msgid "
|
226 |
msgstr ""
|
227 |
|
228 |
-
#: ../admin/admin.php:
|
229 |
-
msgid "
|
230 |
msgstr ""
|
231 |
|
232 |
-
#: ../admin/admin.php:
|
233 |
-
msgid "
|
234 |
msgstr ""
|
235 |
|
236 |
-
#: ../admin/admin.php:
|
237 |
msgid "Button Color"
|
238 |
msgstr ""
|
239 |
|
240 |
-
#: ../admin/admin.php:
|
241 |
msgid ""
|
242 |
"Customize your version of Ajax Load More by updating the fields below.</p><p "
|
243 |
-
"class=\"small\">All changes will be applied globally
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
msgstr ""
|
245 |
|
246 |
#: ../admin/editor-build.php:37
|
@@ -255,7 +286,7 @@ msgstr ""
|
|
255 |
msgid "Insert Shortcode"
|
256 |
msgstr ""
|
257 |
|
258 |
-
#: ../admin/editor.php:
|
259 |
msgid "You are not allowed to be here"
|
260 |
msgstr ""
|
261 |
|
@@ -273,7 +304,7 @@ msgstr ""
|
|
273 |
|
274 |
#: ../admin/includes/cta/extend.php:1
|
275 |
msgid ""
|
276 |
-
"Unlock additional
|
277 |
"\" target=\"_parent\">Custom Repeaters add-on</a>"
|
278 |
msgstr ""
|
279 |
|
@@ -285,11 +316,11 @@ msgstr ""
|
|
285 |
msgid "Help/Resources"
|
286 |
msgstr ""
|
287 |
|
288 |
-
#: ../admin/includes/cta/resources.php:
|
289 |
msgid ""
|
290 |
"<a href=\"https://github.com/dcooney/wordpress-ajax-load-more\" target="
|
291 |
-
"\"blank\" class=\"visit\"><i class=\"fa fa-github\"></i> Latest
|
292 |
-
"
|
293 |
msgstr ""
|
294 |
|
295 |
#: ../admin/includes/cta/writeable.php:2
|
@@ -304,195 +335,205 @@ msgstr ""
|
|
304 |
msgid "Write Access Denied!"
|
305 |
msgstr ""
|
306 |
|
307 |
-
#: ../admin/
|
308 |
-
msgid "
|
309 |
msgstr ""
|
310 |
|
311 |
-
#: ../admin/
|
312 |
-
msgid "
|
|
|
|
|
313 |
msgstr ""
|
314 |
|
315 |
-
#: ../admin/
|
316 |
-
msgid "
|
|
|
|
|
|
|
|
|
317 |
msgstr ""
|
318 |
|
319 |
-
#: ../admin/
|
|
|
|
|
|
|
|
|
320 |
msgid ""
|
321 |
-
"
|
322 |
-
"\"
|
323 |
msgstr ""
|
324 |
|
325 |
-
#: ../admin/
|
326 |
-
msgid "Post
|
327 |
msgstr ""
|
328 |
|
329 |
-
#: ../admin/
|
330 |
-
msgid "
|
331 |
msgstr ""
|
332 |
|
333 |
-
#: ../admin/
|
334 |
msgid "Category"
|
335 |
msgstr ""
|
336 |
|
337 |
-
#: ../admin/
|
338 |
msgid "Select a Category to query(by slug)."
|
339 |
msgstr ""
|
340 |
|
341 |
-
#: ../admin/
|
342 |
msgid "Select Category"
|
343 |
msgstr ""
|
344 |
|
345 |
-
#: ../admin/
|
346 |
msgid "Tag"
|
347 |
msgstr ""
|
348 |
|
349 |
-
#: ../admin/
|
350 |
msgid "Select a Tag to query(by slug)."
|
351 |
msgstr ""
|
352 |
|
353 |
-
#: ../admin/
|
354 |
msgid "Select Tag"
|
355 |
msgstr ""
|
356 |
|
357 |
-
#: ../admin/
|
358 |
msgid "Taxonomy"
|
359 |
msgstr ""
|
360 |
|
361 |
-
#: ../admin/
|
362 |
msgid "Select your custom taxonomy then select the terms and operator."
|
363 |
msgstr ""
|
364 |
|
365 |
-
#: ../admin/
|
366 |
msgid "Select Taxonomy"
|
367 |
msgstr ""
|
368 |
|
369 |
-
#: ../admin/
|
370 |
msgid "Taxonomy Terms:"
|
371 |
msgstr ""
|
372 |
|
373 |
-
#: ../admin/
|
374 |
msgid "Taxonomy Operator:"
|
375 |
msgstr ""
|
376 |
|
377 |
-
#: ../admin/
|
378 |
msgid "Author"
|
379 |
msgstr ""
|
380 |
|
381 |
-
#: ../admin/
|
382 |
msgid "Select an Author to query(by ID)."
|
383 |
msgstr ""
|
384 |
|
385 |
-
#: ../admin/
|
386 |
msgid "Select Author"
|
387 |
msgstr ""
|
388 |
|
389 |
-
#: ../admin/
|
390 |
msgid "Search Term"
|
391 |
msgstr ""
|
392 |
|
393 |
-
#: ../admin/
|
394 |
msgid "Enter a search term to query."
|
395 |
msgstr ""
|
396 |
|
397 |
-
#: ../admin/
|
398 |
msgid "Enter search term"
|
399 |
msgstr ""
|
400 |
|
401 |
-
#: ../admin/
|
402 |
msgid "Ordering"
|
403 |
msgstr ""
|
404 |
|
405 |
-
#: ../admin/
|
406 |
msgid "Sort retrieved posts by Order and Orderby parameters."
|
407 |
msgstr ""
|
408 |
|
409 |
-
#: ../admin/
|
410 |
msgid "Exclude"
|
411 |
msgstr ""
|
412 |
|
413 |
-
#: ../admin/
|
414 |
msgid "A comma separated list of post ID's to exclude from query."
|
415 |
msgstr ""
|
416 |
|
417 |
-
#: ../admin/
|
418 |
msgid "Offset"
|
419 |
msgstr ""
|
420 |
|
421 |
-
#: ../admin/
|
422 |
msgid "Offset the initial WordPress query by <em>'n'</em> number of posts"
|
423 |
msgstr ""
|
424 |
|
425 |
-
#: ../admin/
|
426 |
msgid "Posts Per Page"
|
427 |
msgstr ""
|
428 |
|
429 |
-
#: ../admin/
|
430 |
msgid "Select the number of posts to load with each request."
|
431 |
msgstr ""
|
432 |
|
433 |
-
#: ../admin/
|
434 |
msgid "Load Posts on Scroll"
|
435 |
msgstr ""
|
436 |
|
437 |
-
#: ../admin/
|
438 |
msgid "Load more posts as the user scrolls the page."
|
439 |
msgstr ""
|
440 |
|
441 |
-
#: ../admin/
|
442 |
-
#: ../admin/
|
443 |
msgid "True"
|
444 |
msgstr ""
|
445 |
|
446 |
-
#: ../admin/
|
447 |
-
#: ../admin/
|
448 |
msgid "False"
|
449 |
msgstr ""
|
450 |
|
451 |
-
#: ../admin/
|
452 |
msgid "Max Pages"
|
453 |
msgstr ""
|
454 |
|
455 |
-
#: ../admin/
|
456 |
msgid "Maximum number of pages to load while scrolling."
|
457 |
msgstr ""
|
458 |
|
459 |
-
#: ../admin/
|
460 |
msgid "Unlimited"
|
461 |
msgstr ""
|
462 |
|
463 |
-
#: ../admin/
|
464 |
msgid "Pause Loading of Posts"
|
465 |
msgstr ""
|
466 |
|
467 |
-
#: ../admin/
|
468 |
msgid "Do not load posts until user clicks <em>load</em> button."
|
469 |
msgstr ""
|
470 |
|
471 |
-
#: ../admin/
|
472 |
msgid "Transition"
|
473 |
msgstr ""
|
474 |
|
475 |
-
#: ../admin/
|
476 |
-
msgid "Select a loading transition
|
477 |
msgstr ""
|
478 |
|
479 |
-
#: ../admin/
|
480 |
msgid "Slide"
|
481 |
msgstr ""
|
482 |
|
483 |
-
#: ../admin/
|
484 |
msgid "Fade"
|
485 |
msgstr ""
|
486 |
|
487 |
-
#: ../admin/
|
488 |
msgid "Button Label"
|
489 |
msgstr ""
|
490 |
|
491 |
-
#: ../admin/
|
492 |
msgid "Customize the <em>Load More</em> button label."
|
493 |
msgstr ""
|
494 |
|
495 |
-
#: ../admin/
|
496 |
msgid "Older Posts"
|
497 |
msgstr ""
|
498 |
|
1 |
msgid ""
|
2 |
msgstr ""
|
3 |
"Project-Id-Version: Ajax Load More\n"
|
4 |
+
"POT-Creation-Date: 2014-09-11 22:32-0500\n"
|
5 |
+
"PO-Revision-Date: 2014-09-11 22:32-0500\n"
|
6 |
+
"Last-Translator: Darren Cooney <darren.cooney@gmail.com>\n"
|
7 |
"Language-Team: \n"
|
8 |
"Language: en_CA\n"
|
9 |
"MIME-Version: 1.0\n"
|
10 |
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Generator: Poedit 1.6.7\n"
|
13 |
"X-Poedit-Basepath: .\n"
|
14 |
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
15 |
"X-Poedit-KeywordsList: __;_e\n"
|
16 |
"X-Poedit-SearchPath-0: ..\n"
|
17 |
|
18 |
+
#: ../admin/admin.php:239
|
19 |
+
msgid "Ajax Load More: Repeater Templates"
|
20 |
msgstr ""
|
21 |
|
22 |
+
#: ../admin/admin.php:240
|
23 |
msgid "The library of available templates to use throughout your theme"
|
24 |
msgstr ""
|
25 |
|
26 |
+
#: ../admin/admin.php:248 ../admin/shortcode-builder/shortcode-builder.php:1
|
27 |
+
msgid "Collapse All"
|
28 |
+
msgstr ""
|
29 |
+
|
30 |
+
#: ../admin/admin.php:248 ../admin/shortcode-builder/shortcode-builder.php:1
|
31 |
+
msgid "Expand All"
|
32 |
+
msgstr ""
|
33 |
+
|
34 |
+
#: ../admin/admin.php:259
|
35 |
+
msgid "Default Template"
|
36 |
msgstr ""
|
37 |
|
38 |
+
#: ../admin/admin.php:262
|
39 |
+
msgid "Enter the HTML and PHP code for the default template"
|
40 |
msgstr ""
|
41 |
|
42 |
+
#: ../admin/admin.php:276
|
43 |
msgid "Save Template"
|
44 |
msgstr ""
|
45 |
|
46 |
+
#: ../admin/admin.php:343
|
47 |
msgid "Saving data..."
|
48 |
msgstr ""
|
49 |
|
50 |
+
#: ../admin/admin.php:356
|
51 |
+
msgid "Template saved successfully"
|
52 |
msgstr ""
|
53 |
|
54 |
+
#: ../admin/admin.php:364
|
55 |
+
msgid "Something went wrong and the data could not be saved"
|
56 |
msgstr ""
|
57 |
|
58 |
+
#: ../admin/admin.php:385
|
59 |
msgid "Templating Help"
|
60 |
msgstr ""
|
61 |
|
62 |
+
#: ../admin/admin.php:387
|
63 |
msgid "What is a repeater template?"
|
64 |
msgstr ""
|
65 |
|
66 |
+
#: ../admin/admin.php:388
|
67 |
msgid ""
|
68 |
"A repeater template is a snippet of code that will execute over and over "
|
69 |
"within a <a href=\"http://codex.wordpress.org/The_Loop\" target=\"_blank"
|
70 |
"\">WordPress loop</a>.</p>"
|
71 |
msgstr ""
|
72 |
|
73 |
+
#: ../admin/admin.php:391
|
74 |
msgid "Can I include PHP in the repeater template?"
|
75 |
msgstr ""
|
76 |
|
77 |
+
#: ../admin/admin.php:392
|
78 |
msgid ""
|
79 |
"Yes, PHP and core WordPress functions such as, <code>the_title()</code> and "
|
80 |
"<code>the_permalink()</code> are required.</p>"
|
81 |
msgstr ""
|
82 |
|
83 |
+
#: ../admin/admin.php:395
|
84 |
msgid "Tips and Tricks"
|
85 |
msgstr ""
|
86 |
|
87 |
+
#: ../admin/admin.php:397
|
88 |
msgid ""
|
89 |
"Always open and close your templates with an HTML element. In some rare "
|
90 |
"cases data may not be displayed if not wrapped in HTML.<br/>e.g. <code><"
|
91 |
"li> </li></code> or <code><div> </div></code>"
|
92 |
msgstr ""
|
93 |
|
94 |
+
#: ../admin/admin.php:468
|
95 |
+
msgid "Ajax Load More: Shortcode Builder"
|
96 |
msgstr ""
|
97 |
|
98 |
+
#: ../admin/admin.php:469
|
99 |
msgid ""
|
100 |
"Create your own Ajax Load More <a href=\"http://en.support.wordpress.com/"
|
101 |
"shortcodes/\" target=\"_blank\">shortcode</a> by adjusting the values below"
|
102 |
msgstr ""
|
103 |
|
104 |
+
#: ../admin/admin.php:475 ../admin/admin.php:589
|
105 |
msgid "Back to Top"
|
106 |
msgstr ""
|
107 |
|
108 |
+
#: ../admin/admin.php:481
|
109 |
msgid "Shortcode Output"
|
110 |
msgstr ""
|
111 |
|
112 |
+
#: ../admin/admin.php:482
|
113 |
msgid ""
|
114 |
"Copy and paste the following shortcode into the content editor or widget "
|
115 |
"area of your theme."
|
116 |
msgstr ""
|
117 |
|
118 |
+
#: ../admin/admin.php:485 ../admin/editor-build.php:45
|
119 |
msgid "Copy"
|
120 |
msgstr ""
|
121 |
|
122 |
+
#: ../admin/admin.php:489
|
123 |
msgid "Did you know?"
|
124 |
msgstr ""
|
125 |
|
126 |
+
#: ../admin/admin.php:491
|
127 |
msgid ""
|
128 |
"<p class=\"addon-intro\">You can generate shortcodes while editing pages!</"
|
129 |
+
"p><p>Click the Ajax Load More icon in the content editor toolbar and the <a "
|
130 |
+
"href=\"?page=ajax-load-more-shortcode-builder\">shortcode builder</a> will "
|
131 |
+
"open in an overlay window."
|
132 |
msgstr ""
|
133 |
|
134 |
+
#: ../admin/admin.php:548
|
135 |
+
msgid "Ajax Load More: Examples"
|
136 |
msgstr ""
|
137 |
|
138 |
+
#: ../admin/admin.php:549
|
139 |
msgid "A collection of everyday shortcode usages and implementation examples"
|
140 |
msgstr ""
|
141 |
|
142 |
+
#: ../admin/admin.php:554
|
143 |
msgid "Author.php"
|
144 |
msgstr ""
|
145 |
|
146 |
+
#: ../admin/admin.php:556
|
147 |
msgid "Shortcode for use on author archive pages."
|
148 |
msgstr ""
|
149 |
|
150 |
+
#: ../admin/admin.php:563
|
151 |
msgid "Category.php"
|
152 |
msgstr ""
|
153 |
|
154 |
+
#: ../admin/admin.php:565
|
155 |
msgid "Shortcode for use on category archive pages."
|
156 |
msgstr ""
|
157 |
|
158 |
+
#: ../admin/admin.php:572
|
159 |
msgid "Excluding Posts"
|
160 |
msgstr ""
|
161 |
|
162 |
+
#: ../admin/admin.php:574
|
163 |
msgid "Shortcode for excluding an array of posts."
|
164 |
msgstr ""
|
165 |
|
166 |
+
#: ../admin/admin.php:580
|
167 |
msgid "Tag.php"
|
168 |
msgstr ""
|
169 |
|
170 |
+
#: ../admin/admin.php:582
|
171 |
msgid "Shortcode for use on tag archive pages."
|
172 |
msgstr ""
|
173 |
|
174 |
+
#: ../admin/admin.php:595
|
175 |
msgid "Request Examples"
|
176 |
msgstr ""
|
177 |
|
178 |
+
#: ../admin/admin.php:596
|
179 |
msgid ""
|
180 |
"If you're having issue's with functionality, please submit example requests "
|
181 |
"through the <a href=\"https://github.com/dcooney/wordpress-ajax-load-more\" "
|
182 |
"target=\"_blank\">GitHub repository</a>. "
|
183 |
msgstr ""
|
184 |
|
185 |
+
#: ../admin/admin.php:620
|
186 |
+
msgid "Ajax Load More: Add-ons"
|
187 |
msgstr ""
|
188 |
|
189 |
+
#: ../admin/admin.php:621
|
190 |
msgid ""
|
191 |
"The following Add-ons are available to increase the functionality of Ajax "
|
192 |
"Load More."
|
193 |
msgstr ""
|
194 |
|
195 |
+
#: ../admin/admin.php:627
|
196 |
msgid "Custom Repeaters"
|
197 |
msgstr ""
|
198 |
|
199 |
+
#: ../admin/admin.php:633
|
200 |
msgid ""
|
201 |
+
"Unlock additional repeater templates and keep your WordPress theme looking "
|
202 |
+
"and feeling fresh."
|
203 |
msgstr ""
|
204 |
|
205 |
+
#: ../admin/admin.php:634
|
206 |
msgid ""
|
207 |
"The Custom Repeaters add-on will add <strong>five</strong> additional <a "
|
208 |
"href=\"?page=ajax-load-more-repeaters\">repeaters</a> and allow you to "
|
209 |
"select unique repeaters for different content types throughout your theme.</"
|
210 |
+
"p>"
|
|
|
|
|
|
|
|
|
|
|
211 |
msgstr ""
|
212 |
|
213 |
+
#: ../admin/admin.php:651 ../admin/admin.php:655
|
214 |
msgid "About Add-ons"
|
215 |
msgstr ""
|
216 |
|
217 |
+
#: ../admin/admin.php:652 ../admin/admin.php:656
|
218 |
msgid ""
|
219 |
"Add-ons are installed as a separate plugin and will receive plug-in update "
|
220 |
"notifications. "
|
221 |
msgstr ""
|
222 |
|
223 |
+
#: ../admin/admin.php:698
|
224 |
+
msgid "Container Type"
|
225 |
msgstr ""
|
226 |
|
227 |
+
#: ../admin/admin.php:706
|
228 |
+
msgid "Container Classes"
|
229 |
msgstr ""
|
230 |
|
231 |
+
#: ../admin/admin.php:714
|
232 |
+
msgid "Editor Shortcode Button"
|
233 |
msgstr ""
|
234 |
|
235 |
+
#: ../admin/admin.php:722
|
236 |
+
msgid "Disable CSS"
|
237 |
msgstr ""
|
238 |
|
239 |
+
#: ../admin/admin.php:730
|
240 |
msgid "Button Color"
|
241 |
msgstr ""
|
242 |
|
243 |
+
#: ../admin/admin.php:747
|
244 |
msgid ""
|
245 |
"Customize your version of Ajax Load More by updating the fields below.</p><p "
|
246 |
+
"class=\"small\">All changes will be applied globally throughout your theme."
|
247 |
+
msgstr ""
|
248 |
+
|
249 |
+
#: ../admin/admin.php:776
|
250 |
+
msgid "I want to use my own CSS styles"
|
251 |
+
msgstr ""
|
252 |
+
|
253 |
+
#: ../admin/admin.php:777
|
254 |
+
msgid "View Ajax Load More CSS"
|
255 |
+
msgstr ""
|
256 |
+
|
257 |
+
#: ../admin/admin.php:796
|
258 |
+
msgid "Disable shortcode button from content editors"
|
259 |
+
msgstr ""
|
260 |
+
|
261 |
+
#: ../admin/admin.php:810
|
262 |
+
msgid "Add classes to Ajax Load More container"
|
263 |
+
msgstr ""
|
264 |
+
|
265 |
+
#: ../admin/admin.php:829 ../admin/admin.php:832
|
266 |
+
msgid "Ajax Posts Here"
|
267 |
+
msgstr ""
|
268 |
+
|
269 |
+
#: ../admin/admin.php:883
|
270 |
+
msgid "Choose your load more button color"
|
271 |
+
msgstr ""
|
272 |
+
|
273 |
+
#: ../admin/admin.php:894
|
274 |
+
msgid "Preview"
|
275 |
msgstr ""
|
276 |
|
277 |
#: ../admin/editor-build.php:37
|
286 |
msgid "Insert Shortcode"
|
287 |
msgstr ""
|
288 |
|
289 |
+
#: ../admin/editor.php:19
|
290 |
msgid "You are not allowed to be here"
|
291 |
msgstr ""
|
292 |
|
304 |
|
305 |
#: ../admin/includes/cta/extend.php:1
|
306 |
msgid ""
|
307 |
+
"Unlock additional templates with the <a href=\"?page=ajax-load-more-add-ons"
|
308 |
"\" target=\"_parent\">Custom Repeaters add-on</a>"
|
309 |
msgstr ""
|
310 |
|
316 |
msgid "Help/Resources"
|
317 |
msgstr ""
|
318 |
|
319 |
+
#: ../admin/includes/cta/resources.php:25
|
320 |
msgid ""
|
321 |
"<a href=\"https://github.com/dcooney/wordpress-ajax-load-more\" target="
|
322 |
+
"\"blank\" class=\"visit\"><i class=\"fa fa-github\"></i> Latest build on "
|
323 |
+
"Github</a>"
|
324 |
msgstr ""
|
325 |
|
326 |
#: ../admin/includes/cta/writeable.php:2
|
335 |
msgid "Write Access Denied!"
|
336 |
msgstr ""
|
337 |
|
338 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:8
|
339 |
+
msgid "Template"
|
340 |
msgstr ""
|
341 |
|
342 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:11
|
343 |
+
msgid ""
|
344 |
+
"Select your <a href=\"admin.php?page=ajax-load-more-repeaters\" target="
|
345 |
+
"\"_parent\">repeater template</a>."
|
346 |
msgstr ""
|
347 |
|
348 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:36
|
349 |
+
msgid "Post Types"
|
350 |
+
msgstr ""
|
351 |
+
|
352 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:39
|
353 |
+
msgid "Select Post Types to query."
|
354 |
msgstr ""
|
355 |
|
356 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:59
|
357 |
+
msgid "Post Format"
|
358 |
+
msgstr ""
|
359 |
+
|
360 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:62
|
361 |
msgid ""
|
362 |
+
"Select a <a href=\"http://codex.wordpress.org/Post_Formats\" target=\"_blank"
|
363 |
+
"\">Post Format</a> to query."
|
364 |
msgstr ""
|
365 |
|
366 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:65
|
367 |
+
msgid "Select Post Format"
|
368 |
msgstr ""
|
369 |
|
370 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:66
|
371 |
+
msgid "Standard"
|
372 |
msgstr ""
|
373 |
|
374 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:81
|
375 |
msgid "Category"
|
376 |
msgstr ""
|
377 |
|
378 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:84
|
379 |
msgid "Select a Category to query(by slug)."
|
380 |
msgstr ""
|
381 |
|
382 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:87
|
383 |
msgid "Select Category"
|
384 |
msgstr ""
|
385 |
|
386 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:100
|
387 |
msgid "Tag"
|
388 |
msgstr ""
|
389 |
|
390 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:103
|
391 |
msgid "Select a Tag to query(by slug)."
|
392 |
msgstr ""
|
393 |
|
394 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:106
|
395 |
msgid "Select Tag"
|
396 |
msgstr ""
|
397 |
|
398 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:125
|
399 |
msgid "Taxonomy"
|
400 |
msgstr ""
|
401 |
|
402 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:128
|
403 |
msgid "Select your custom taxonomy then select the terms and operator."
|
404 |
msgstr ""
|
405 |
|
406 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:135
|
407 |
msgid "Select Taxonomy"
|
408 |
msgstr ""
|
409 |
|
410 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:144
|
411 |
msgid "Taxonomy Terms:"
|
412 |
msgstr ""
|
413 |
|
414 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:149
|
415 |
msgid "Taxonomy Operator:"
|
416 |
msgstr ""
|
417 |
|
418 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:167
|
419 |
msgid "Author"
|
420 |
msgstr ""
|
421 |
|
422 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:170
|
423 |
msgid "Select an Author to query(by ID)."
|
424 |
msgstr ""
|
425 |
|
426 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:173
|
427 |
msgid "Select Author"
|
428 |
msgstr ""
|
429 |
|
430 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:185
|
431 |
msgid "Search Term"
|
432 |
msgstr ""
|
433 |
|
434 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:188
|
435 |
msgid "Enter a search term to query."
|
436 |
msgstr ""
|
437 |
|
438 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:192
|
439 |
msgid "Enter search term"
|
440 |
msgstr ""
|
441 |
|
442 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:200
|
443 |
msgid "Ordering"
|
444 |
msgstr ""
|
445 |
|
446 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:203
|
447 |
msgid "Sort retrieved posts by Order and Orderby parameters."
|
448 |
msgstr ""
|
449 |
|
450 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:232
|
451 |
msgid "Exclude"
|
452 |
msgstr ""
|
453 |
|
454 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:235
|
455 |
msgid "A comma separated list of post ID's to exclude from query."
|
456 |
msgstr ""
|
457 |
|
458 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:247
|
459 |
msgid "Offset"
|
460 |
msgstr ""
|
461 |
|
462 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:250
|
463 |
msgid "Offset the initial WordPress query by <em>'n'</em> number of posts"
|
464 |
msgstr ""
|
465 |
|
466 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:271
|
467 |
msgid "Posts Per Page"
|
468 |
msgstr ""
|
469 |
|
470 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:274
|
471 |
msgid "Select the number of posts to load with each request."
|
472 |
msgstr ""
|
473 |
|
474 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:300
|
475 |
msgid "Load Posts on Scroll"
|
476 |
msgstr ""
|
477 |
|
478 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:303
|
479 |
msgid "Load more posts as the user scrolls the page."
|
480 |
msgstr ""
|
481 |
|
482 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:310
|
483 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:365
|
484 |
msgid "True"
|
485 |
msgstr ""
|
486 |
|
487 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:314
|
488 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:369
|
489 |
msgid "False"
|
490 |
msgstr ""
|
491 |
|
492 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:325
|
493 |
msgid "Max Pages"
|
494 |
msgstr ""
|
495 |
|
496 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:328
|
497 |
msgid "Maximum number of pages to load while scrolling."
|
498 |
msgstr ""
|
499 |
|
500 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:343
|
501 |
msgid "Unlimited"
|
502 |
msgstr ""
|
503 |
|
504 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:355
|
505 |
msgid "Pause Loading of Posts"
|
506 |
msgstr ""
|
507 |
|
508 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:358
|
509 |
msgid "Do not load posts until user clicks <em>load</em> button."
|
510 |
msgstr ""
|
511 |
|
512 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:380
|
513 |
msgid "Transition"
|
514 |
msgstr ""
|
515 |
|
516 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:383
|
517 |
+
msgid "Select a loading transition."
|
518 |
msgstr ""
|
519 |
|
520 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:390
|
521 |
msgid "Slide"
|
522 |
msgstr ""
|
523 |
|
524 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:394
|
525 |
msgid "Fade"
|
526 |
msgstr ""
|
527 |
|
528 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:405
|
529 |
msgid "Button Label"
|
530 |
msgstr ""
|
531 |
|
532 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:408
|
533 |
msgid "Customize the <em>Load More</em> button label."
|
534 |
msgstr ""
|
535 |
|
536 |
+
#: ../admin/shortcode-builder/shortcode-builder.php:412
|
537 |
msgid "Older Posts"
|
538 |
msgstr ""
|
539 |
|
screenshot-1.png
CHANGED
Binary file
|
screenshot-2.png
CHANGED
Binary file
|
screenshot-3.png
CHANGED
Binary file
|
screenshot-4.png
CHANGED
Binary file
|
screenshot-5.png
CHANGED
Binary file
|
screenshot-6.png
CHANGED
Binary file
|
screenshot-7.png
ADDED
Binary file
|