Version Description
- Better selection of
post_types
to add Scripts-n-Styles - micro-optimization for storage of class names.
- Adds option page for globally adding Scripts and Styles.
- Defined a later priority for Scripts n Styles to print after other scripts and styles.
- Added a box for Scripts to be included in the
head
. - Better adherence to coding standards.
- Tabbed interface on metabox
- added CodeMirror
- began contextual help
Download this release
Release Info
Developer | WraithKenny |
Plugin | Scripts n Styles |
Version | 2 |
Comparing to | |
See all releases |
Code changes from version 1.0.2 to 2
- README.txt +27 -7
- css/meta-box-styles.css +101 -0
- css/options-styles.css +14 -0
- includes/class.SnS_Admin.php +84 -0
- includes/class.SnS_Admin_Meta_Box.php +215 -0
- includes/class.SnS_Settings_Page.php +281 -0
- js/meta-box-scripts.js +12 -0
- js/options-scripts.js +10 -0
- libraries/codemirror/LICENSE +19 -0
- libraries/codemirror/lib/codemirror.css +64 -0
- libraries/codemirror/lib/codemirror.js +2071 -0
- libraries/codemirror/lib/overlay.js +51 -0
- libraries/codemirror/lib/runmode.js +27 -0
- libraries/codemirror/mode/css.js +124 -0
- libraries/codemirror/mode/htmlmixed.js +74 -0
- libraries/codemirror/mode/javascript.js +348 -0
- libraries/codemirror/mode/xml.js +206 -0
- libraries/codemirror/theme/default.css +18 -0
- libraries/codemirror/theme/elegant.css +9 -0
- libraries/codemirror/theme/neat.css +8 -0
- libraries/codemirror/theme/night.css +20 -0
- license.txt +281 -281
- scripts-n-styles.php +315 -141
- uninstall.php +13 -11
README.txt
CHANGED
@@ -2,15 +2,15 @@
|
|
2 |
Contributors: WraithKenny, Touvan
|
3 |
Donate link: http://wordpressfoundation.org/donate/
|
4 |
Tags: admin, CSS, javascript, code, custom, Style
|
5 |
-
Requires at least: 3.
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag:
|
8 |
|
9 |
This plugin allows Admin users to individually add custom CSS, Classes and JavaScript directly to Post, Pages or any other custom post types.
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
-
This plugin allows Admin users the ability to add custom CSS (at the bottom of the
|
14 |
|
15 |
Because only well trusted users should ever be allowed to insert JavaScript directly into the pages of your site, this plugin restricts usage to admin type users. Admin's have access to even more sensitive areas by definition, so that should be relatively safe ;)
|
16 |
|
@@ -37,7 +37,7 @@ Well, because plugins are supposed to, and should be expected to clean up after
|
|
37 |
|
38 |
= Can I get around that somehow? =
|
39 |
|
40 |
-
Sure, if you are an Admin, just go to the plugin editor and wipe out the
|
41 |
|
42 |
== Screenshots ==
|
43 |
|
@@ -45,8 +45,19 @@ Sure, if you are an Admin, just go to the plugin editor and wipe out the `uninst
|
|
45 |
|
46 |
== Changelog ==
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
= 1.0.2 =
|
49 |
-
* Added fields for
|
50 |
* Merged meta boxes
|
51 |
* Cleaned up code
|
52 |
* Improved compatibility
|
@@ -60,8 +71,17 @@ Sure, if you are an Admin, just go to the plugin editor and wipe out the `uninst
|
|
60 |
|
61 |
== Upgrade Notice ==
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
= 1.0.2 =
|
64 |
Minor update. Adds a few new features.
|
65 |
|
66 |
= 1.0.1 =
|
67 |
-
Some small plugin meta data updates.
|
|
|
|
|
|
2 |
Contributors: WraithKenny, Touvan
|
3 |
Donate link: http://wordpressfoundation.org/donate/
|
4 |
Tags: admin, CSS, javascript, code, custom, Style
|
5 |
+
Requires at least: 3.1
|
6 |
+
Tested up to: 3.2
|
7 |
+
Stable tag: 2
|
8 |
|
9 |
This plugin allows Admin users to individually add custom CSS, Classes and JavaScript directly to Post, Pages or any other custom post types.
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
+
This plugin allows Admin users the ability to add custom CSS (at the bottom of the 'head' tag) and JavaScript (at the bottom of the 'body' tag) directly into individual Post, Pages or any other registered custom post types. You can also add classes to the body tag and the post container (if your theme supports `body_class()` and `post_class()` functions).
|
14 |
|
15 |
Because only well trusted users should ever be allowed to insert JavaScript directly into the pages of your site, this plugin restricts usage to admin type users. Admin's have access to even more sensitive areas by definition, so that should be relatively safe ;)
|
16 |
|
37 |
|
38 |
= Can I get around that somehow? =
|
39 |
|
40 |
+
Sure, if you are an Admin, just go to the plugin editor and wipe out the uninstall.php (Replace everything with a space character) and then WordPress will not delete the meta data on uninstall.
|
41 |
|
42 |
== Screenshots ==
|
43 |
|
45 |
|
46 |
== Changelog ==
|
47 |
|
48 |
+
= 2 =
|
49 |
+
* Better selection of `post_types` to add Scripts-n-Styles
|
50 |
+
* micro-optimization for storage of class names.
|
51 |
+
* Adds option page for globally adding Scripts and Styles.
|
52 |
+
* Defined a later priority for Scripts n Styles to print after other scripts and styles.
|
53 |
+
* Added a box for Scripts to be included in the `head`.
|
54 |
+
* Better adherence to coding standards.
|
55 |
+
* Tabbed interface on metabox
|
56 |
+
* added CodeMirror
|
57 |
+
* began contextual help
|
58 |
+
|
59 |
= 1.0.2 =
|
60 |
+
* Added fields for `body_clas`s and `post_class`
|
61 |
* Merged meta boxes
|
62 |
* Cleaned up code
|
63 |
* Improved compatibility
|
71 |
|
72 |
== Upgrade Notice ==
|
73 |
|
74 |
+
= 2 =
|
75 |
+
Adds new features.
|
76 |
+
|
77 |
+
= 1.0.3 =
|
78 |
+
Adds a few new features.
|
79 |
+
|
80 |
= 1.0.2 =
|
81 |
Minor update. Adds a few new features.
|
82 |
|
83 |
= 1.0.1 =
|
84 |
+
Some small plugin meta data updates.
|
85 |
+
|
86 |
+
= 1.0 =
|
87 |
+
Initial Release, there is nothing to upgrade from.
|
css/meta-box-styles.css
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* MetaBox.css */
|
2 |
+
|
3 |
+
#uFp_meta_box .title {
|
4 |
+
display: block;
|
5 |
+
margin-top: 1.5em;
|
6 |
+
}
|
7 |
+
#uFp_meta_box .tabs-vertical .title,
|
8 |
+
#uFp_meta_box .tabs-horizontal .title {
|
9 |
+
display: none;
|
10 |
+
}
|
11 |
+
|
12 |
+
#uFp_meta_box .tabs-vertical,
|
13 |
+
#uFp_meta_box .tabs-horizontal,
|
14 |
+
#uFp_meta_box .ui-tabs-panel {
|
15 |
+
overflow: hidden;
|
16 |
+
}
|
17 |
+
|
18 |
+
#uFp_meta_box .tabs-vertical .wp-tab-bar {
|
19 |
+
margin-bottom: 3px;
|
20 |
+
}
|
21 |
+
#uFp_meta_box .tabs-vertical .wp-tab-bar li {
|
22 |
+
display: inline;
|
23 |
+
line-height: 1.35em;
|
24 |
+
}
|
25 |
+
#uFp_meta_box .tabs-vertical .wp-tab-bar .ui-state-active {
|
26 |
+
background-color: #FFFFFF;
|
27 |
+
border-color: #DFDFDF;
|
28 |
+
border-style: solid solid none;
|
29 |
+
border-width: 1px 1px 0;
|
30 |
+
}
|
31 |
+
#uFp_meta_box .tabs-vertical .wp-tab-bar .ui-state-active a {
|
32 |
+
color: #333333;
|
33 |
+
}
|
34 |
+
#uFp_meta_box .tabs-vertical .ui-tabs-panel {
|
35 |
+
border-style: solid;
|
36 |
+
border-width: 1px;
|
37 |
+
padding: 0.5em 0.9em;
|
38 |
+
background-color: #FFFFFF;
|
39 |
+
border-color: #DFDFDF;
|
40 |
+
}
|
41 |
+
|
42 |
+
|
43 |
+
#uFp_meta_box .tabs-horizontal .wp-tab-bar {
|
44 |
+
float: left;
|
45 |
+
margin: 0 -120px 0 5px;
|
46 |
+
padding: 0;
|
47 |
+
text-align: right;
|
48 |
+
width: 120px;
|
49 |
+
}
|
50 |
+
#uFp_meta_box .tabs-horizontal .wp-tab-bar li {
|
51 |
+
padding: 8px;
|
52 |
+
display: block;
|
53 |
+
}
|
54 |
+
#uFp_meta_box .tabs-horizontal .wp-tab-bar li a {
|
55 |
+
display: block;
|
56 |
+
}
|
57 |
+
#uFp_meta_box .tabs-horizontal .wp-tab-bar .ui-state-active {
|
58 |
+
background-color: #FFFFFF;
|
59 |
+
border-color: #DFDFDF;
|
60 |
+
border-style: solid none solid solid;
|
61 |
+
border-width: 1px 0 1px 1px;
|
62 |
+
margin-right: -1px;
|
63 |
+
border-radius: 3px 0 0 3px;
|
64 |
+
font-weight: bold;
|
65 |
+
text-decoration: none;
|
66 |
+
}
|
67 |
+
#uFp_meta_box .tabs-horizontal .wp-tab-bar .ui-state-active a {
|
68 |
+
color: #333333;
|
69 |
+
}
|
70 |
+
#uFp_meta_box .tabs-horizontal .ui-tabs-panel {
|
71 |
+
background-color: #FFFFFF;
|
72 |
+
border-color: #DFDFDF;
|
73 |
+
border-style: solid;
|
74 |
+
border-width: 1px;
|
75 |
+
min-height: 200px;
|
76 |
+
margin: 0 5px 0 125px;
|
77 |
+
overflow: hidden;
|
78 |
+
padding: 0.5em 0.9em;
|
79 |
+
}
|
80 |
+
#uFp_meta_box .tabs-horizontal .inside div {
|
81 |
+
overflow: hidden;
|
82 |
+
}
|
83 |
+
|
84 |
+
.ui-tabs .ui-tabs-hide {
|
85 |
+
position: absolute;
|
86 |
+
left: -10000px;
|
87 |
+
display: block;
|
88 |
+
}
|
89 |
+
|
90 |
+
.CodeMirror {
|
91 |
+
border: 1px solid #DFDFDF;
|
92 |
+
background-color: white;
|
93 |
+
border-radius: 3px;
|
94 |
+
margin: 8px 0;
|
95 |
+
}
|
96 |
+
.CodeMirror-scroll {
|
97 |
+
height: auto;
|
98 |
+
min-height: 50px;
|
99 |
+
max-height: 300px;
|
100 |
+
overflow: auto;
|
101 |
+
}
|
css/options-styles.css
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Options.css */
|
2 |
+
|
3 |
+
.CodeMirror {
|
4 |
+
border: 1px solid #DFDFDF;
|
5 |
+
background-color: white;
|
6 |
+
border-radius: 3px;
|
7 |
+
margin: 8px 0;
|
8 |
+
}
|
9 |
+
.CodeMirror-scroll {
|
10 |
+
height: auto;
|
11 |
+
min-height: 50px;
|
12 |
+
max-height: 300px;
|
13 |
+
overflow: auto;
|
14 |
+
}
|
includes/class.SnS_Admin.php
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Scripts n Styles Admin Class
|
4 |
+
*
|
5 |
+
* Allows WordPress admin users the ability to add custom CSS
|
6 |
+
* and JavaScript directly to individual Post, Pages or custom
|
7 |
+
* post types.
|
8 |
+
*/
|
9 |
+
|
10 |
+
class SnS_Admin
|
11 |
+
{
|
12 |
+
/**#@+
|
13 |
+
* Constants
|
14 |
+
*/
|
15 |
+
const MENU_SLUG = 'Scripts-n-Styles';
|
16 |
+
const VERSION = '1.0.3-beta';
|
17 |
+
/**#@-*/
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Initializing method.
|
21 |
+
* @static
|
22 |
+
*/
|
23 |
+
static function init() {
|
24 |
+
add_action( 'admin_menu', array( __CLASS__, 'admin_meta_box' ) );
|
25 |
+
add_action( 'admin_menu', array( __CLASS__, 'settings_page' ) );
|
26 |
+
|
27 |
+
$plugin_file = plugin_basename( Scripts_n_Styles::$file );
|
28 |
+
add_filter( "plugin_action_links_$plugin_file", array( __CLASS__, 'plugin_action_links') );
|
29 |
+
|
30 |
+
register_activation_hook( Scripts_n_Styles::$file, array( __CLASS__, 'upgrade' ) );
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Utility Method: Sets defaults if not previously set. Sets stored 'version' to VERSION.
|
35 |
+
*/
|
36 |
+
static function upgrade() {
|
37 |
+
$options = get_option( 'SnS_options' );
|
38 |
+
|
39 |
+
if ( ! isset( $options[ 'show_usage' ] ) )
|
40 |
+
$options[ 'show_usage' ] = 'no';
|
41 |
+
$options[ 'version' ] = self::VERSION;
|
42 |
+
|
43 |
+
update_option( 'SnS_options', $options );
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Utility Method: Compares VERSION to stored 'version' value.
|
48 |
+
*/
|
49 |
+
static function upgrade_check() {
|
50 |
+
if ( ! isset( $options[ 'version' ] ) || version_compare( self::VERSION, $options[ 'version' ], '>' ) )
|
51 |
+
self::upgrade();
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Adds link to the Settings Page in the WordPress "Plugin Action Links" array.
|
56 |
+
* @param array $actions
|
57 |
+
* @return array
|
58 |
+
*/
|
59 |
+
static function plugin_action_links( $actions ) {
|
60 |
+
$actions[ 'settings' ] = '<a href="' . menu_page_url( self::MENU_SLUG, false ) . '"/>Settings</a>';
|
61 |
+
return $actions;
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Settings Page
|
66 |
+
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
|
67 |
+
*/
|
68 |
+
static function admin_meta_box() {
|
69 |
+
include_once( 'class.SnS_Admin_Meta_Box.php' );
|
70 |
+
SnS_Admin_Meta_Box::init();
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Settings Page
|
75 |
+
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
|
76 |
+
*/
|
77 |
+
static function settings_page() {
|
78 |
+
/* NOTE: Even when Scripts n Styles is not restricted by 'manage_options', Editors still can't submit the option page */
|
79 |
+
include_once( 'class.SnS_Settings_Page.php' );
|
80 |
+
SnS_Settings_Page::init();
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
?>
|
includes/class.SnS_Admin_Meta_Box.php
ADDED
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* SnS_Admin_Meta_Box
|
4 |
+
*
|
5 |
+
* Allows WordPress admin users the ability to add custom CSS
|
6 |
+
* and JavaScript directly to individual Post, Pages or custom
|
7 |
+
* post types.
|
8 |
+
*/
|
9 |
+
|
10 |
+
// $hook_suffix = 'tools_page_Scripts-n-Styles'; // kept here for reference
|
11 |
+
// $plugin_file = 'scripts-n-styles/scripts-n-styles.php'; // kept here for reference
|
12 |
+
|
13 |
+
class SnS_Admin_Meta_Box
|
14 |
+
{
|
15 |
+
/*
|
16 |
+
* Constants
|
17 |
+
*/
|
18 |
+
const NONCE_NAME = 'scripts_n_styles_noncename';
|
19 |
+
|
20 |
+
static $post_types;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Initializing method. Checks if is_admin() and registers action hooks for admin if true. Sets filters and actions for Theme side functions.
|
24 |
+
* @static
|
25 |
+
*/
|
26 |
+
static function init() {
|
27 |
+
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
|
28 |
+
add_action( 'save_post', array( __CLASS__, 'save_post' ) );
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Admin Action: 'add_meta_boxes'
|
33 |
+
* Main Meta Box function. Checks restriction options and display options, calls add_meta_box() and adds actions for adding admin CSS and JavaScript.
|
34 |
+
*/
|
35 |
+
static function add_meta_boxes() {
|
36 |
+
if ( current_user_can( 'unfiltered_html' ) ) {
|
37 |
+
self::$post_types = get_post_types( array('show_ui' => true, 'publicly_queryable' => true) );
|
38 |
+
foreach ( self::$post_types as $post_type ) {
|
39 |
+
add_meta_box( 'uFp_meta_box', 'Scripts n Styles', array( __CLASS__, 'meta_box' ), $post_type, 'normal', 'high' );
|
40 |
+
}
|
41 |
+
add_filter( 'default_hidden_meta_boxes', array( __CLASS__, 'default_hidden_meta_boxes' ) );
|
42 |
+
add_action( "admin_print_styles", array( __CLASS__, 'meta_box_styles'));
|
43 |
+
add_action( "admin_print_scripts", array( __CLASS__, 'meta_box_scripts'));
|
44 |
+
add_filter( 'contextual_help', array( __CLASS__, 'contextual_help_filter' ), 10, 3 );
|
45 |
+
}
|
46 |
+
}
|
47 |
+
static function default_hidden_meta_boxes( $hidden ) {
|
48 |
+
$hidden[] = 'uFp_meta_box';
|
49 |
+
return $hidden;
|
50 |
+
}
|
51 |
+
|
52 |
+
function contextual_help_filter( $text, $screen_id, $screen ) {
|
53 |
+
if ( in_array( $screen->post_type, self::$post_types ) )
|
54 |
+
$text .= '<p>In default (non MultiSite) WordPress installs, both <em>Administrators</em> and
|
55 |
+
<em>Editors</em> can access <em>Scripts-n-Styles</em> on individual edit screens.
|
56 |
+
Only <em>Administrators</em> can access this Options Page. In MultiSite WordPress installs, only <em>"Super Admin"</em> users can access either
|
57 |
+
<em>Scripts-n-Styles</em> on individual edit screens or this Options Page. If other plugins change capabilities (specifically "unfiltered_html"),
|
58 |
+
other users can be granted access.</p>';
|
59 |
+
return $text;
|
60 |
+
}
|
61 |
+
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Admin Action: 'add_meta_boxes'
|
65 |
+
* Outputs the Meta Box. Only called on callback from add_meta_box() during the add_meta_boxes action.
|
66 |
+
* @param unknown_type WordPress Post object.
|
67 |
+
*/
|
68 |
+
static function meta_box( $post ) {
|
69 |
+
$registered_handles = Scripts_n_Styles::get_wp_registered();
|
70 |
+
$styles = get_post_meta( $post->ID, 'uFp_styles', true );
|
71 |
+
$scripts = get_post_meta( $post->ID, 'uFp_scripts', true );
|
72 |
+
?>
|
73 |
+
<div class="tabs-horizontal">
|
74 |
+
<ul class="wp-tab-bar" style="display: none;">
|
75 |
+
<li><a href="#uFp_scripts-tab">Scripts (bottom)</a></li>
|
76 |
+
<li><a href="#uFp_styles-tab">Styles</a></li>
|
77 |
+
<li><a href="#uFp_scripts_in_head-tab">Scripts (top)</a></li>
|
78 |
+
<li><a href="#uFp_classes_body-tab">Classes</a></li>
|
79 |
+
<?php /** / ?>
|
80 |
+
<li><a href="#uFp_enqueue_scripts-tab">Include Scripts</a></li>
|
81 |
+
<?php /**/ ?>
|
82 |
+
</ul>
|
83 |
+
|
84 |
+
<div id="uFp_scripts-tab">
|
85 |
+
<input type="hidden" name="<?php echo self::NONCE_NAME ?>" id="<?php echo self::NONCE_NAME ?>" value="<?php echo wp_create_nonce( Scripts_n_Styles::$file ) ?>" />
|
86 |
+
<p>
|
87 |
+
<label for="uFp_scripts" class="title"><strong>Scripts</strong>: </label>
|
88 |
+
<textarea class="code js" name="uFp_scripts" id="uFp_scripts" rows="5" cols="40" style="width: 98%;"><?php echo isset( $scripts[ 'scripts' ] ) ? $scripts[ 'scripts' ] : ''; ?></textarea>
|
89 |
+
<em>This code will be included <strong>verbatim</strong> in <code><script></code> tags at the end of your page's (or post's) <code><body></code> tag.</em>
|
90 |
+
</p>
|
91 |
+
</div>
|
92 |
+
|
93 |
+
<div id="uFp_styles-tab">
|
94 |
+
<p>
|
95 |
+
<label for="uFp_styles" class="title"><strong>Styles</strong>: </label>
|
96 |
+
<textarea class="code css" name="uFp_styles" id="uFp_styles" rows="5" cols="40" style="width: 98%;"><?php echo isset( $styles[ 'styles' ] ) ? $styles[ 'styles' ] : ''; ?></textarea>
|
97 |
+
<em>This code will be included <strong>verbatim</strong> in <code><style></code> tags in the <code><head></code> tag of your page (or post).</em>
|
98 |
+
</p>
|
99 |
+
</div>
|
100 |
+
|
101 |
+
<div id="uFp_scripts_in_head-tab">
|
102 |
+
<p>
|
103 |
+
<label for="uFp_scripts_in_head" class="title"><strong>Scripts</strong> (for the <code>head</code> element): </label>
|
104 |
+
<textarea class="codemirror js" name="uFp_scripts_in_head" id="uFp_scripts_in_head" rows="5" cols="40" style="width: 98%;"><?php echo isset( $scripts[ 'scripts_in_head' ] ) ? $scripts[ 'scripts_in_head' ] : ''; ?></textarea>
|
105 |
+
<em>This code will be included <strong>verbatim</strong> in <code><script></code> tags at the end of your page's (or post's) <code><head></code> tag.</em>
|
106 |
+
</p>
|
107 |
+
</div>
|
108 |
+
|
109 |
+
<div id="uFp_classes_body-tab">
|
110 |
+
<strong class="title">Classes</strong>
|
111 |
+
<p>
|
112 |
+
<label for="uFp_classes_body">body classes: </label>
|
113 |
+
<input style="width: 99%;" name="uFp_classes_body" id="uFp_classes_body" value="<?php echo isset( $styles[ 'classes_body' ] ) ? $styles[ 'classes_body' ] : ''; ?>" type="text" class="code" />
|
114 |
+
</p>
|
115 |
+
<p>
|
116 |
+
<label for="uFp_classes_post">post classes: </label>
|
117 |
+
<input style="width: 99%;" name="uFp_classes_post" id="uFp_classes_post" value="<?php echo isset( $styles[ 'classes_post' ] ) ? $styles[ 'classes_post' ] : ''; ?>" type="text" class="code" />
|
118 |
+
</p>
|
119 |
+
<p><em>These <strong>space separated</strong> class names will be pushed into the <code>body_class()</code> or <code>post_class()</code> function (provided your theme uses these functions).</em></p>
|
120 |
+
</div>
|
121 |
+
|
122 |
+
<?php /** / ?>
|
123 |
+
<div id="uFp_enqueue_scripts-tab">
|
124 |
+
<strong class="title">Include Scripts</strong>
|
125 |
+
<select name="uFp_enqueue_scripts[]" id="uFp_enqueue_scripts" size="5" multiple="multiple" style="height: auto; float: left; margin: 6px 10px 8px 0;">
|
126 |
+
<?php // This is a bit intense here...
|
127 |
+
if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) {
|
128 |
+
foreach ( $registered_handles as $value ) { ?>
|
129 |
+
<option value="<?php echo $value ?>"<?php foreach ( $scripts[ 'enqueue_scripts' ] as $handle ) selected( $handle, $value ); ?>><?php echo $value ?></option>
|
130 |
+
<?php }
|
131 |
+
} else {
|
132 |
+
foreach ( $registered_handles as $value ) { ?>
|
133 |
+
<option value="<?php echo $value ?>"><?php echo $value ?></option>
|
134 |
+
<?php }
|
135 |
+
} ?>
|
136 |
+
</select>
|
137 |
+
<?php if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) { ?>
|
138 |
+
<p>Currently Enqueued Scripts:
|
139 |
+
<?php foreach ( $scripts[ 'enqueue_scripts' ] as $handle ) echo '<code>' . $handle . '</code> '; ?>
|
140 |
+
</p>
|
141 |
+
<?php } ?>
|
142 |
+
<p><em>The chosen scripts will be enqueued and placed before your codes if your code is dependant on certain scripts (like jQuery).</em></p>
|
143 |
+
<p>NOTE: Not all Scripts in the list are appropriate for use in themes. This is merely a generated list of all currently available registered scripts. It's possible some scripts could be registered only on the "front end" and therefore not listed here.</p>
|
144 |
+
</div>
|
145 |
+
<?php /**/ ?>
|
146 |
+
</div>
|
147 |
+
<?php
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Admin Action: 'admin_print_styles' Action added during 'add_meta_boxes' (which restricts output to Edit Screens).
|
152 |
+
* Enqueues the CSS for admin styling of the Meta Box.
|
153 |
+
*/
|
154 |
+
static function meta_box_styles() {
|
155 |
+
wp_enqueue_style( 'sns-meta-box-styles', plugins_url( 'css/meta-box-styles.css', Scripts_n_Styles::$file), array( 'codemirror-default' ), SnS_Admin::VERSION );
|
156 |
+
wp_enqueue_style( 'codemirror', plugins_url( 'libraries/codemirror/lib/codemirror.css', Scripts_n_Styles::$file), array(), '2.1' );
|
157 |
+
wp_enqueue_style( 'codemirror-default', plugins_url( 'libraries/codemirror/theme/default.css', Scripts_n_Styles::$file), array( 'codemirror' ), '2.1' );
|
158 |
+
}
|
159 |
+
|
160 |
+
/**
|
161 |
+
* Admin Action: 'admin_print_styles' Action added during 'add_meta_boxes' (which restricts output to Edit Screens).
|
162 |
+
* Enqueues the JavaScript for the admin Meta Box.
|
163 |
+
*/
|
164 |
+
static function meta_box_scripts() {
|
165 |
+
wp_enqueue_script( 'sns-meta-box-scripts', plugins_url( 'js/meta-box-scripts.js', Scripts_n_Styles::$file), array( 'jquery-ui-tabs', 'codemirror-css', 'codemirror-javascript' ), SnS_Admin::VERSION, true );
|
166 |
+
wp_enqueue_script( 'codemirror', plugins_url( 'libraries/codemirror/lib/codemirror.js', Scripts_n_Styles::$file), array(), '2.1' );
|
167 |
+
wp_enqueue_script( 'codemirror-css', plugins_url( 'libraries/codemirror/mode/css.js', Scripts_n_Styles::$file), array( 'codemirror' ), '2.1' );
|
168 |
+
wp_enqueue_script( 'codemirror-javascript', plugins_url( 'libraries/codemirror/mode/javascript.js', Scripts_n_Styles::$file), array( 'codemirror' ), '2.1' );
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Admin Action: 'save_post'
|
173 |
+
* Saves the values entered in the Meta Box when a post is saved (on the Edit Screen only, excluding autosaves) if the user has permission.
|
174 |
+
* @param int $post_id ID value of the WordPress post.
|
175 |
+
*/
|
176 |
+
static function save_post( $post_id ) {
|
177 |
+
if ( isset( $_POST[ self::NONCE_NAME ] ) && wp_verify_nonce( $_POST[ self::NONCE_NAME ], Scripts_n_Styles::$file )
|
178 |
+
&& current_user_can( 'unfiltered_html' )
|
179 |
+
&& ! ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ) {
|
180 |
+
|
181 |
+
/*
|
182 |
+
NOTE: There is no current_user_can( 'edit_post' ) check here, because as far as I
|
183 |
+
can tell, in /wp-admin/post.php the calls edit_post(), write_post(), post_preview(),
|
184 |
+
wp_untrash_post(), etc., the check is already done prior to the 'save_post' action,
|
185 |
+
which is where this function is called. Other calls are from other pages so the
|
186 |
+
NONCE covers those cases, and that leaves autosave, which is also checked here.
|
187 |
+
*/
|
188 |
+
|
189 |
+
$scripts = array();
|
190 |
+
$styles = array();
|
191 |
+
|
192 |
+
if ( ! empty( $_POST[ 'uFp_scripts' ] ) )
|
193 |
+
$scripts[ 'scripts' ] = $_POST[ 'uFp_scripts' ];
|
194 |
+
|
195 |
+
if ( ! empty( $_POST[ 'uFp_styles' ] ) )
|
196 |
+
$styles[ 'styles' ] = $_POST[ 'uFp_styles' ];
|
197 |
+
|
198 |
+
if ( ! empty( $_POST[ 'uFp_scripts_in_head' ] ) )
|
199 |
+
$scripts[ 'scripts_in_head' ] = $_POST[ 'uFp_scripts_in_head' ];
|
200 |
+
|
201 |
+
if ( ! empty( $_POST[ 'uFp_classes_body' ] ) )
|
202 |
+
$styles[ 'classes_body' ] = $_POST[ 'uFp_classes_body' ];
|
203 |
+
|
204 |
+
if ( ! empty( $_POST[ 'uFp_classes_post' ] ) )
|
205 |
+
$styles[ 'classes_post' ] = $_POST[ 'uFp_classes_post' ];
|
206 |
+
|
207 |
+
if ( ! empty( $_POST[ 'uFp_enqueue_scripts' ] ) )
|
208 |
+
$scripts[ 'enqueue_scripts' ] = $_POST[ 'uFp_enqueue_scripts' ];
|
209 |
+
|
210 |
+
update_post_meta( $post_id, 'uFp_scripts', $scripts );
|
211 |
+
update_post_meta( $post_id, 'uFp_styles', $styles );
|
212 |
+
}
|
213 |
+
}
|
214 |
+
}
|
215 |
+
?>
|
includes/class.SnS_Settings_Page.php
ADDED
@@ -0,0 +1,281 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* SnS_Settings_Page
|
4 |
+
*
|
5 |
+
* Allows WordPress admin users the ability to add custom CSS
|
6 |
+
* and JavaScript directly to individual Post, Pages or custom
|
7 |
+
* post types.
|
8 |
+
*/
|
9 |
+
|
10 |
+
// $hook_suffix = 'tools_page_Scripts-n-Styles'; // kept here for reference
|
11 |
+
// $plugin_file = 'scripts-n-styles/scripts-n-styles.php'; // kept here for reference
|
12 |
+
|
13 |
+
class SnS_Settings_Page
|
14 |
+
{
|
15 |
+
/**
|
16 |
+
* Constants
|
17 |
+
*/
|
18 |
+
const OPTION_GROUP = 'scripts_n_styles';
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Initializing method.
|
22 |
+
* @static
|
23 |
+
*/
|
24 |
+
static function init() {
|
25 |
+
/* NOTE: Even when Scripts n Styles is not restricted by 'manage_options', Editors still can't submit the option page */
|
26 |
+
if ( current_user_can( 'manage_options' ) ) { // if they can't, they won't be able to save anyway.
|
27 |
+
$hook_suffix = add_management_page(
|
28 |
+
'Scripts n Styles Settings', // $page_title (string) (required) The text to be displayed in the title tags of the page when the menu is selected
|
29 |
+
'Scripts n Styles', // $menu_title (string) (required) The text to be used for the menu
|
30 |
+
'unfiltered_html', // $capability (string) (required) The capability required for this menu to be displayed to the user.
|
31 |
+
SnS_Admin::MENU_SLUG, // $menu_slug (string) (required) The slug name to refer to this menu by (should be unique for this menu).
|
32 |
+
array( __CLASS__, 'options_page' ) // $function (callback) (optional) The function to be called to output the content for this page.
|
33 |
+
);
|
34 |
+
Scripts_n_Styles::$hook_suffix = $hook_suffix;
|
35 |
+
add_action( "load-$hook_suffix", array( __CLASS__, 'init_options_page' ) );
|
36 |
+
add_action( "load-options.php", array( __CLASS__, 'init_options_page' ) );
|
37 |
+
|
38 |
+
add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'options_styles'));
|
39 |
+
add_action( "admin_print_scripts-$hook_suffix", array( __CLASS__, 'options_scripts'));
|
40 |
+
|
41 |
+
add_contextual_help( $hook_suffix, self::contextual_help() );
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Settings Page help
|
47 |
+
*/
|
48 |
+
function contextual_help() {
|
49 |
+
$contextual_help = '<p>In default (non MultiSite) WordPress installs, both <em>Administrators</em> and
|
50 |
+
<em>Editors</em> can access <em>Scripts-n-Styles</em> on individual edit screens.
|
51 |
+
Only <em>Administrators</em> can access this Options Page. In MultiSite WordPress installs, only <em>"Super Admin"</em> users can access either
|
52 |
+
<em>Scripts-n-Styles</em> on individual edit screens or this Options Page. If other plugins change capabilities (specifically "unfiltered_html"),
|
53 |
+
other users can be granted access.</p>';
|
54 |
+
return $contextual_help;
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Settings Page
|
59 |
+
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
|
60 |
+
*/
|
61 |
+
static function init_options_page() {
|
62 |
+
register_setting(
|
63 |
+
self::OPTION_GROUP, // $option_group (string) (required) A settings group name. Can be anything.
|
64 |
+
'SnS_options' // $option_name (string) (required) The name of an option to sanitize and save.
|
65 |
+
);
|
66 |
+
register_setting(
|
67 |
+
self::OPTION_GROUP,
|
68 |
+
'SnS_enqueue_scripts'
|
69 |
+
);
|
70 |
+
add_settings_section(
|
71 |
+
'global',
|
72 |
+
'Global Scripts n Styles',
|
73 |
+
array( __CLASS__, 'global_section' ),
|
74 |
+
SnS_Admin::MENU_SLUG
|
75 |
+
);
|
76 |
+
add_settings_field(
|
77 |
+
'scripts',
|
78 |
+
'<label for="scripts"><strong>Scripts:</strong> </label>',
|
79 |
+
array( __CLASS__, 'scripts_field' ),
|
80 |
+
SnS_Admin::MENU_SLUG,
|
81 |
+
'global'
|
82 |
+
);
|
83 |
+
add_settings_field(
|
84 |
+
'styles',
|
85 |
+
'<label for="styles"><strong>Styles:</strong> </label>',
|
86 |
+
array( __CLASS__, 'styles_field' ),
|
87 |
+
SnS_Admin::MENU_SLUG,
|
88 |
+
'global'
|
89 |
+
);
|
90 |
+
add_settings_field(
|
91 |
+
'scripts_in_head',
|
92 |
+
'<label for="scripts_in_head"><strong>Scripts</strong><br />(for the <code>head</code> element): </label>',
|
93 |
+
array( __CLASS__, 'scripts_in_head_field' ),
|
94 |
+
SnS_Admin::MENU_SLUG,
|
95 |
+
'global'
|
96 |
+
);
|
97 |
+
/*add_settings_field(
|
98 |
+
'enqueue_scripts',
|
99 |
+
'<label for="enqueue_scripts"><strong>Enqueue Scripts</strong>: </label>',
|
100 |
+
array( __CLASS__, 'enqueue_scripts_field' ),
|
101 |
+
SnS_Admin::MENU_SLUG,
|
102 |
+
'global'
|
103 |
+
);*/
|
104 |
+
add_settings_section(
|
105 |
+
'usage',
|
106 |
+
'Scripts n Styles Usage',
|
107 |
+
array( __CLASS__, 'usage_section' ),
|
108 |
+
SnS_Admin::MENU_SLUG
|
109 |
+
);
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Settings Page
|
114 |
+
* Adds CSS styles to the Scripts n Styles Admin Page.
|
115 |
+
*/
|
116 |
+
static function options_styles() {
|
117 |
+
wp_enqueue_style( 'sns-options-styles', plugins_url('css/options-styles.css', Scripts_n_Styles::$file), array( 'codemirror-default' ), SnS_Admin::VERSION );
|
118 |
+
wp_enqueue_style( 'codemirror', plugins_url( 'libraries/codemirror/lib/codemirror.css', Scripts_n_Styles::$file), array(), '2.1' );
|
119 |
+
wp_enqueue_style( 'codemirror-default', plugins_url( 'libraries/codemirror/theme/default.css', Scripts_n_Styles::$file), array( 'codemirror' ), '2.1' );
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Settings Page
|
124 |
+
* Adds JavaScript to the Scripts n Styles Admin Page.
|
125 |
+
*/
|
126 |
+
static function options_scripts() {
|
127 |
+
wp_enqueue_script( 'sns-options-scripts', plugins_url('js/options-scripts.js', Scripts_n_Styles::$file), array( 'jquery', 'codemirror-css', 'codemirror-javascript' ), SnS_Admin::VERSION, true );
|
128 |
+
wp_enqueue_script( 'codemirror', plugins_url( 'libraries/codemirror/lib/codemirror.js', Scripts_n_Styles::$file), array(), '2.1' );
|
129 |
+
wp_enqueue_script( 'codemirror-css', plugins_url( 'libraries/codemirror/mode/css.js', Scripts_n_Styles::$file), array( 'codemirror' ), '2.1' );
|
130 |
+
wp_enqueue_script( 'codemirror-javascript', plugins_url( 'libraries/codemirror/mode/javascript.js', Scripts_n_Styles::$file), array( 'codemirror' ), '2.1' );
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Settings Page
|
135 |
+
* Outputs Description text for the Global Section.
|
136 |
+
*/
|
137 |
+
static function global_section() {
|
138 |
+
?>
|
139 |
+
<div style="max-width: 55em;">
|
140 |
+
<p>Code entered here will be included in <em>every page (and post) of your site</em>, including the homepage and archives. The code will appear <strong>before</strong> Scripts and Styles registered individually.</p>
|
141 |
+
</div>
|
142 |
+
<?php
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Settings Page
|
147 |
+
* Outputs the Usage Section.
|
148 |
+
*/
|
149 |
+
static function usage_section() {
|
150 |
+
$options = get_option( 'SnS_options' );
|
151 |
+
|
152 |
+
$all_posts = get_posts( array( 'numberposts' => -1, 'post_type' => 'any', 'post_status' => 'any' ) );
|
153 |
+
$sns_posts = array();
|
154 |
+
foreach( $all_posts as $post) {
|
155 |
+
$temp_styles = get_post_meta( $post->ID, 'uFp_styles', true );
|
156 |
+
$temp_scripts = get_post_meta( $post->ID, 'uFp_scripts', true );
|
157 |
+
if ( ! empty( $temp_styles ) || ! empty( $temp_scripts ) )
|
158 |
+
$sns_posts[] = $post;
|
159 |
+
}
|
160 |
+
|
161 |
+
if ( ! empty( $sns_posts ) ) {
|
162 |
+
?>
|
163 |
+
<table cellspacing="0" class="widefat">
|
164 |
+
<thead>
|
165 |
+
<tr>
|
166 |
+
<th>Title</th>
|
167 |
+
<th>ID</th>
|
168 |
+
<th>Status</th>
|
169 |
+
<th>Post Type</th>
|
170 |
+
</tr>
|
171 |
+
</thead>
|
172 |
+
<tbody>
|
173 |
+
<?php foreach( $sns_posts as $post) {
|
174 |
+
$temp_styles = get_post_meta( $post->ID, 'uFp_styles', true );
|
175 |
+
$temp_scripts = get_post_meta( $post->ID, 'uFp_scripts', true );
|
176 |
+
if ( ! empty( $temp_styles ) || ! empty( $temp_scripts ) ) { ?>
|
177 |
+
<tr>
|
178 |
+
<td>
|
179 |
+
<strong><a class="row-title" title="Edit “<?php echo esc_attr( $post->post_title ); ?>”" href="<?php echo esc_url( get_edit_post_link( $post->ID ) ); ?>"><?php echo $post->post_title; ?></a></strong>
|
180 |
+
<div class="row-actions"><span class="edit"><a title="Edit this item" href="<?php echo esc_url( get_edit_post_link( $post->ID ) ); ?>">Edit</a></span></div>
|
181 |
+
</td>
|
182 |
+
<td><?php echo $post->ID; ?></td>
|
183 |
+
<td><?php echo $post->post_status; ?></td>
|
184 |
+
<td><?php echo $post->post_type; ?></td>
|
185 |
+
</tr>
|
186 |
+
<?php }
|
187 |
+
} ?>
|
188 |
+
</tbody>
|
189 |
+
<tfoot>
|
190 |
+
<tr>
|
191 |
+
<th>Title</th>
|
192 |
+
<th>ID</th>
|
193 |
+
<th>Status</th>
|
194 |
+
<th>Post Type</th>
|
195 |
+
</tr>
|
196 |
+
</tfoot>
|
197 |
+
</table>
|
198 |
+
<?php
|
199 |
+
} else {
|
200 |
+
?>
|
201 |
+
<div style="max-width: 55em;">
|
202 |
+
<p>No content items are currently using Scripts-n-Styles data.</p>
|
203 |
+
</div>
|
204 |
+
<?php
|
205 |
+
}
|
206 |
+
}
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Settings Page
|
210 |
+
* Outputs a textarea for setting 'scripts'.
|
211 |
+
*/
|
212 |
+
static function scripts_field() {
|
213 |
+
$options = get_option( 'SnS_options' );
|
214 |
+
?><textarea style="min-width: 500px; width:97%;" class="code js" rows="5" cols="40" name="SnS_options[scripts]" id="scripts"><?php echo isset( $options[ 'scripts' ] ) ? $options[ 'scripts' ] : ''; ?></textarea><br />
|
215 |
+
<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts" will be included <strong>verbatim</strong> in <code><script></code> tags at the bottom of the <code><body></code> element of your html.</span>
|
216 |
+
<?php
|
217 |
+
}
|
218 |
+
|
219 |
+
/**
|
220 |
+
* Settings Page
|
221 |
+
* Outputs a textarea for setting 'styles'.
|
222 |
+
*/
|
223 |
+
static function styles_field() {
|
224 |
+
$options = get_option( 'SnS_options' );
|
225 |
+
?><textarea style="min-width: 500px; width:97%;" class="code css" rows="5" cols="40" name="SnS_options[styles]" id="styles"><?php echo isset( $options[ 'styles' ] ) ? $options[ 'styles' ] : ''; ?></textarea><br />
|
226 |
+
<span class="description" style="max-width: 500px; display: inline-block;">The "Styles" will be included <strong>verbatim</strong> in <code><style></code> tags in the <code><head></code> element of your html.</span><?php
|
227 |
+
}
|
228 |
+
|
229 |
+
/**
|
230 |
+
* Settings Page
|
231 |
+
* Outputs a textarea for setting 'scripts_in_head'.
|
232 |
+
*/
|
233 |
+
static function scripts_in_head_field() {
|
234 |
+
$options = get_option( 'SnS_options' );
|
235 |
+
?><textarea style="min-width: 500px; width:97%;" class="code js" rows="5" cols="40" name="SnS_options[scripts_in_head]" id="scripts_in_head"><?php echo isset( $options[ 'scripts_in_head' ] ) ? $options[ 'scripts_in_head' ] : ''; ?></textarea><br />
|
236 |
+
<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts (in head)" will be included <strong>verbatim</strong> in <code><script></code> tags in the <code><head></code> element of your html.</span>
|
237 |
+
<?php
|
238 |
+
}
|
239 |
+
|
240 |
+
/**
|
241 |
+
* Settings Page
|
242 |
+
* Outputs a select element for selecting options to set $sns_enqueue_scripts.
|
243 |
+
*/
|
244 |
+
static function enqueue_scripts_field() {
|
245 |
+
$registered_handles = Scripts_n_Styles::get_wp_registered();
|
246 |
+
$sns_enqueue_scripts = get_option( 'SnS_enqueue_scripts' );
|
247 |
+
if ( ! is_array( $sns_enqueue_scripts ) ) $sns_enqueue_scripts = array();
|
248 |
+
?>
|
249 |
+
<select name="SnS_enqueue_scripts[]" id="enqueue_scripts" size="5" multiple="multiple" style="height: auto;">
|
250 |
+
<?php foreach ( $registered_handles as $value ) { ?>
|
251 |
+
<option value="<?php echo $value ?>"<?php foreach ( $sns_enqueue_scripts as $handle ) selected( $handle, $value ); ?>><?php echo $value ?></option>
|
252 |
+
<?php } ?>
|
253 |
+
</select>
|
254 |
+
<?php if ( ! empty( $sns_enqueue_scripts ) && is_array( $sns_enqueue_scripts ) ) { ?>
|
255 |
+
<p>Currently Enqueued Scripts:
|
256 |
+
<?php foreach ( $sns_enqueue_scripts as $handle ) echo '<code>' . $handle . '</code> '; ?>
|
257 |
+
</p>
|
258 |
+
<?php }
|
259 |
+
}
|
260 |
+
|
261 |
+
/**
|
262 |
+
* Settings Page
|
263 |
+
* Outputs the Admin Page and calls the Settings registered with the Settings API in init_options_page().
|
264 |
+
*/
|
265 |
+
static function options_page() {
|
266 |
+
SnS_Admin::upgrade_check();
|
267 |
+
global $title;
|
268 |
+
?>
|
269 |
+
<div class="wrap">
|
270 |
+
<?php screen_icon(); ?>
|
271 |
+
<h2><?php echo esc_html($title); ?></h2>
|
272 |
+
<form action="options.php" method="post" autocomplete="off">
|
273 |
+
<?php settings_fields( self::OPTION_GROUP ); ?>
|
274 |
+
<?php do_settings_sections( SnS_Admin::MENU_SLUG ); ?>
|
275 |
+
<?php submit_button(); ?>
|
276 |
+
</form>
|
277 |
+
</div>
|
278 |
+
<?php
|
279 |
+
}
|
280 |
+
}
|
281 |
+
?>
|
js/meta-box-scripts.js
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Meta Box JavaScript
|
2 |
+
|
3 |
+
jQuery( document ).ready( function( $ ) {
|
4 |
+
$( "#uFp_meta_box" ).tabs().find( ".wp-tab-bar" ).show();
|
5 |
+
|
6 |
+
$( "textarea.js" ).each( function() {
|
7 |
+
CodeMirror.fromTextArea( this, { lineNumbers: true, mode: "javascript" } );
|
8 |
+
});
|
9 |
+
$( "textarea.css" ).each( function() {
|
10 |
+
CodeMirror.fromTextArea( this, { lineNumbers: true, mode: "css" } );
|
11 |
+
});
|
12 |
+
});
|
js/options-scripts.js
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Options JavaScript
|
2 |
+
|
3 |
+
jQuery( document ).ready( function( $ ) {
|
4 |
+
$( "textarea.js" ).each( function() {
|
5 |
+
CodeMirror.fromTextArea( this, { lineNumbers: true, mode: "javascript" } );
|
6 |
+
});
|
7 |
+
$( "textarea.css" ).each( function() {
|
8 |
+
CodeMirror.fromTextArea( this, { lineNumbers: true, mode: "css" } );
|
9 |
+
});
|
10 |
+
});
|
libraries/codemirror/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Copyright (C) 2011 by Marijn Haverbeke <marijnh@gmail.com>
|
2 |
+
|
3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4 |
+
of this software and associated documentation files (the "Software"), to deal
|
5 |
+
in the Software without restriction, including without limitation the rights
|
6 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7 |
+
copies of the Software, and to permit persons to whom the Software is
|
8 |
+
furnished to do so, subject to the following conditions:
|
9 |
+
|
10 |
+
The above copyright notice and this permission notice shall be included in
|
11 |
+
all copies or substantial portions of the Software.
|
12 |
+
|
13 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19 |
+
THE SOFTWARE.
|
libraries/codemirror/lib/codemirror.css
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.CodeMirror {
|
2 |
+
line-height: 1em;
|
3 |
+
font-family: monospace;
|
4 |
+
}
|
5 |
+
|
6 |
+
.CodeMirror-scroll {
|
7 |
+
overflow: auto;
|
8 |
+
height: 300px;
|
9 |
+
}
|
10 |
+
|
11 |
+
.CodeMirror-gutter {
|
12 |
+
position: absolute; left: 0; top: 0;
|
13 |
+
background-color: #f7f7f7;
|
14 |
+
border-right: 1px solid #eee;
|
15 |
+
min-width: 2em;
|
16 |
+
height: 100%;
|
17 |
+
}
|
18 |
+
.CodeMirror-gutter-text {
|
19 |
+
color: #aaa;
|
20 |
+
text-align: right;
|
21 |
+
padding: .4em .2em .4em .4em;
|
22 |
+
}
|
23 |
+
.CodeMirror-lines {
|
24 |
+
padding: .4em;
|
25 |
+
}
|
26 |
+
|
27 |
+
.CodeMirror pre {
|
28 |
+
-moz-border-radius: 0;
|
29 |
+
-webkit-border-radius: 0;
|
30 |
+
-o-border-radius: 0;
|
31 |
+
border-radius: 0;
|
32 |
+
border-width: 0; margin: 0; padding: 0; background: transparent;
|
33 |
+
font-family: inherit;
|
34 |
+
font-size: inherit;
|
35 |
+
padding: 0; margin: 0;
|
36 |
+
white-space: pre;
|
37 |
+
word-wrap: normal;
|
38 |
+
}
|
39 |
+
|
40 |
+
.CodeMirror textarea {
|
41 |
+
font-family: inherit !important;
|
42 |
+
font-size: inherit !important;
|
43 |
+
}
|
44 |
+
|
45 |
+
.CodeMirror-cursor {
|
46 |
+
z-index: 10;
|
47 |
+
position: absolute;
|
48 |
+
visibility: hidden;
|
49 |
+
border-left: 1px solid black !important;
|
50 |
+
}
|
51 |
+
.CodeMirror-focused .CodeMirror-cursor {
|
52 |
+
visibility: visible;
|
53 |
+
}
|
54 |
+
|
55 |
+
span.CodeMirror-selected {
|
56 |
+
background: #ccc !important;
|
57 |
+
color: HighlightText !important;
|
58 |
+
}
|
59 |
+
.CodeMirror-focused span.CodeMirror-selected {
|
60 |
+
background: Highlight !important;
|
61 |
+
}
|
62 |
+
|
63 |
+
.CodeMirror-matchingbracket {color: #0f0 !important;}
|
64 |
+
.CodeMirror-nonmatchingbracket {color: #f22 !important;}
|
libraries/codemirror/lib/codemirror.js
ADDED
@@ -0,0 +1,2071 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// All functions that need access to the editor's state live inside
|
2 |
+
// the CodeMirror function. Below that, at the bottom of the file,
|
3 |
+
// some utilities are defined.
|
4 |
+
|
5 |
+
// CodeMirror is the only global var we claim
|
6 |
+
var CodeMirror = (function() {
|
7 |
+
// This is the function that produces an editor instance. It's
|
8 |
+
// closure is used to store the editor state.
|
9 |
+
function CodeMirror(place, givenOptions) {
|
10 |
+
// Determine effective options based on given values and defaults.
|
11 |
+
var options = {}, defaults = CodeMirror.defaults;
|
12 |
+
for (var opt in defaults)
|
13 |
+
if (defaults.hasOwnProperty(opt))
|
14 |
+
options[opt] = (givenOptions && givenOptions.hasOwnProperty(opt) ? givenOptions : defaults)[opt];
|
15 |
+
|
16 |
+
var targetDocument = options["document"];
|
17 |
+
// The element in which the editor lives.
|
18 |
+
var wrapper = targetDocument.createElement("div");
|
19 |
+
wrapper.className = "CodeMirror";
|
20 |
+
// This mess creates the base DOM structure for the editor.
|
21 |
+
wrapper.innerHTML =
|
22 |
+
'<div style="overflow: hidden; position: relative; width: 1px; height: 0px;">' + // Wraps and hides input textarea
|
23 |
+
'<textarea style="position: absolute; width: 2px;" wrap="off"></textarea></div>' +
|
24 |
+
'<div class="CodeMirror-scroll cm-s-' + options.theme + '">' +
|
25 |
+
'<div style="position: relative">' + // Set to the height of the text, causes scrolling
|
26 |
+
'<div style="position: absolute; height: 0; width: 0; overflow: hidden;"></div>' +
|
27 |
+
'<div style="position: relative">' + // Moved around its parent to cover visible view
|
28 |
+
'<div class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div>' +
|
29 |
+
// Provides positioning relative to (visible) text origin
|
30 |
+
'<div class="CodeMirror-lines"><div style="position: relative">' +
|
31 |
+
'<pre class="CodeMirror-cursor"> </pre>' + // Absolutely positioned blinky cursor
|
32 |
+
'<div></div>' + // This DIV contains the actual code
|
33 |
+
'</div></div></div></div></div>';
|
34 |
+
if (place.appendChild) place.appendChild(wrapper); else place(wrapper);
|
35 |
+
// I've never seen more elegant code in my life.
|
36 |
+
var inputDiv = wrapper.firstChild, input = inputDiv.firstChild,
|
37 |
+
scroller = wrapper.lastChild, code = scroller.firstChild,
|
38 |
+
measure = code.firstChild, mover = measure.nextSibling,
|
39 |
+
gutter = mover.firstChild, gutterText = gutter.firstChild,
|
40 |
+
lineSpace = gutter.nextSibling.firstChild,
|
41 |
+
cursor = lineSpace.firstChild, lineDiv = cursor.nextSibling;
|
42 |
+
if (options.tabindex != null) input.tabindex = options.tabindex;
|
43 |
+
if (!options.gutter && !options.lineNumbers) gutter.style.display = "none";
|
44 |
+
|
45 |
+
// Delayed object wrap timeouts, making sure only one is active. blinker holds an interval.
|
46 |
+
var poll = new Delayed(), highlight = new Delayed(), blinker;
|
47 |
+
|
48 |
+
// mode holds a mode API object. lines an array of Line objects
|
49 |
+
// (see Line constructor), work an array of lines that should be
|
50 |
+
// parsed, and history the undo history (instance of History
|
51 |
+
// constructor).
|
52 |
+
var mode, lines = [new Line("")], work, history = new History(), focused;
|
53 |
+
loadMode();
|
54 |
+
// The selection. These are always maintained to point at valid
|
55 |
+
// positions. Inverted is used to remember that the user is
|
56 |
+
// selecting bottom-to-top.
|
57 |
+
var sel = {from: {line: 0, ch: 0}, to: {line: 0, ch: 0}, inverted: false};
|
58 |
+
// Selection-related flags. shiftSelecting obviously tracks
|
59 |
+
// whether the user is holding shift. reducedSelection is a hack
|
60 |
+
// to get around the fact that we can't create inverted
|
61 |
+
// selections. See below.
|
62 |
+
var shiftSelecting, reducedSelection, lastDoubleClick;
|
63 |
+
// Variables used by startOperation/endOperation to track what
|
64 |
+
// happened during the operation.
|
65 |
+
var updateInput, changes, textChanged, selectionChanged, leaveInputAlone;
|
66 |
+
// Current visible range (may be bigger than the view window).
|
67 |
+
var showingFrom = 0, showingTo = 0, lastHeight = 0, curKeyId = null;
|
68 |
+
// editing will hold an object describing the things we put in the
|
69 |
+
// textarea, to help figure out whether something changed.
|
70 |
+
// bracketHighlighted is used to remember that a backet has been
|
71 |
+
// marked.
|
72 |
+
var editing, bracketHighlighted;
|
73 |
+
// Tracks the maximum line length so that the horizontal scrollbar
|
74 |
+
// can be kept static when scrolling.
|
75 |
+
var maxLine = "";
|
76 |
+
|
77 |
+
// Initialize the content. Somewhat hacky (delayed prepareInput)
|
78 |
+
// to work around browser issues.
|
79 |
+
operation(function(){setValue(options.value || ""); updateInput = false;})();
|
80 |
+
setTimeout(prepareInput, 20);
|
81 |
+
|
82 |
+
// Register our event handlers.
|
83 |
+
connect(scroller, "mousedown", operation(onMouseDown));
|
84 |
+
// Gecko browsers fire contextmenu *after* opening the menu, at
|
85 |
+
// which point we can't mess with it anymore. Context menu is
|
86 |
+
// handled in onMouseDown for Gecko.
|
87 |
+
if (!gecko) connect(scroller, "contextmenu", operation(onContextMenu));
|
88 |
+
connect(code, "dblclick", operation(onDblClick));
|
89 |
+
connect(scroller, "scroll", function() {updateDisplay([]); if (options.onScroll) options.onScroll(instance);});
|
90 |
+
connect(window, "resize", function() {updateDisplay(true);});
|
91 |
+
connect(input, "keyup", operation(onKeyUp));
|
92 |
+
connect(input, "keydown", operation(onKeyDown));
|
93 |
+
connect(input, "keypress", operation(onKeyPress));
|
94 |
+
connect(input, "focus", onFocus);
|
95 |
+
connect(input, "blur", onBlur);
|
96 |
+
|
97 |
+
connect(scroller, "dragenter", function(e){e.stop();});
|
98 |
+
connect(scroller, "dragover", function(e){e.stop();});
|
99 |
+
connect(scroller, "drop", operation(onDrop));
|
100 |
+
connect(scroller, "paste", function(){focusInput(); fastPoll();});
|
101 |
+
connect(input, "paste", function(){fastPoll();});
|
102 |
+
connect(input, "cut", function(){fastPoll();});
|
103 |
+
|
104 |
+
// IE throws unspecified error in certain cases, when
|
105 |
+
// trying to access activeElement before onload
|
106 |
+
var hasFocus; try { hasFocus = (targetDocument.activeElement == input); } catch(e) { }
|
107 |
+
if (hasFocus) onFocus();
|
108 |
+
else onBlur();
|
109 |
+
|
110 |
+
function isLine(l) {return l >= 0 && l < lines.length;}
|
111 |
+
// The instance object that we'll return. Mostly calls out to
|
112 |
+
// local functions in the CodeMirror function. Some do some extra
|
113 |
+
// range checking and/or clipping. operation is used to wrap the
|
114 |
+
// call so that changes it makes are tracked, and the display is
|
115 |
+
// updated afterwards.
|
116 |
+
var instance = {
|
117 |
+
getValue: getValue,
|
118 |
+
setValue: operation(setValue),
|
119 |
+
getSelection: getSelection,
|
120 |
+
replaceSelection: operation(replaceSelection),
|
121 |
+
focus: function(){focusInput(); onFocus(); prepareInput(); fastPoll();},
|
122 |
+
setOption: function(option, value) {
|
123 |
+
options[option] = value;
|
124 |
+
if (option == "lineNumbers" || option == "gutter") gutterChanged();
|
125 |
+
else if (option == "mode" || option == "indentUnit") loadMode();
|
126 |
+
else if (option == "readOnly" && value == "nocursor") input.blur();
|
127 |
+
else if (option == "theme") scroller.className = scroller.className.replace(/cm-s-\w+/, "cm-s-" + value);
|
128 |
+
},
|
129 |
+
getOption: function(option) {return options[option];},
|
130 |
+
undo: operation(undo),
|
131 |
+
redo: operation(redo),
|
132 |
+
indentLine: operation(function(n) {if (isLine(n)) indentLine(n, "smart");}),
|
133 |
+
historySize: function() {return {undo: history.done.length, redo: history.undone.length};},
|
134 |
+
matchBrackets: operation(function(){matchBrackets(true);}),
|
135 |
+
getTokenAt: function(pos) {
|
136 |
+
pos = clipPos(pos);
|
137 |
+
return lines[pos.line].getTokenAt(mode, getStateBefore(pos.line), pos.ch);
|
138 |
+
},
|
139 |
+
cursorCoords: function(start){
|
140 |
+
if (start == null) start = sel.inverted;
|
141 |
+
return pageCoords(start ? sel.from : sel.to);
|
142 |
+
},
|
143 |
+
charCoords: function(pos){return pageCoords(clipPos(pos));},
|
144 |
+
coordsChar: function(coords) {
|
145 |
+
var off = eltOffset(lineSpace);
|
146 |
+
var line = clipLine(Math.min(lines.length - 1, showingFrom + Math.floor((coords.y - off.top) / lineHeight())));
|
147 |
+
return clipPos({line: line, ch: charFromX(clipLine(line), coords.x - off.left)});
|
148 |
+
},
|
149 |
+
getSearchCursor: function(query, pos, caseFold) {return new SearchCursor(query, pos, caseFold);},
|
150 |
+
markText: operation(function(a, b, c){return operation(markText(a, b, c));}),
|
151 |
+
setMarker: addGutterMarker,
|
152 |
+
clearMarker: removeGutterMarker,
|
153 |
+
setLineClass: operation(setLineClass),
|
154 |
+
lineInfo: lineInfo,
|
155 |
+
addWidget: function(pos, node, scroll) {
|
156 |
+
var pos = localCoords(clipPos(pos), true);
|
157 |
+
node.style.top = (showingFrom * lineHeight() + pos.yBot + paddingTop()) + "px";
|
158 |
+
node.style.left = (pos.x + paddingLeft()) + "px";
|
159 |
+
code.appendChild(node);
|
160 |
+
if (scroll)
|
161 |
+
scrollIntoView(pos.x, pos.yBot, pos.x + node.offsetWidth, pos.yBot + node.offsetHeight);
|
162 |
+
},
|
163 |
+
|
164 |
+
lineCount: function() {return lines.length;},
|
165 |
+
getCursor: function(start) {
|
166 |
+
if (start == null) start = sel.inverted;
|
167 |
+
return copyPos(start ? sel.from : sel.to);
|
168 |
+
},
|
169 |
+
somethingSelected: function() {return !posEq(sel.from, sel.to);},
|
170 |
+
setCursor: operation(function(line, ch) {
|
171 |
+
if (ch == null && typeof line.line == "number") setCursor(line.line, line.ch);
|
172 |
+
else setCursor(line, ch);
|
173 |
+
}),
|
174 |
+
setSelection: operation(function(from, to) {setSelection(clipPos(from), clipPos(to || from));}),
|
175 |
+
getLine: function(line) {if (isLine(line)) return lines[line].text;},
|
176 |
+
setLine: operation(function(line, text) {
|
177 |
+
if (isLine(line)) replaceRange(text, {line: line, ch: 0}, {line: line, ch: lines[line].text.length});
|
178 |
+
}),
|
179 |
+
removeLine: operation(function(line) {
|
180 |
+
if (isLine(line)) replaceRange("", {line: line, ch: 0}, clipPos({line: line+1, ch: 0}));
|
181 |
+
}),
|
182 |
+
replaceRange: operation(replaceRange),
|
183 |
+
getRange: function(from, to) {return getRange(clipPos(from), clipPos(to));},
|
184 |
+
|
185 |
+
operation: function(f){return operation(f)();},
|
186 |
+
refresh: function(){updateDisplay(true);},
|
187 |
+
getInputField: function(){return input;},
|
188 |
+
getWrapperElement: function(){return wrapper;}
|
189 |
+
};
|
190 |
+
|
191 |
+
function setValue(code) {
|
192 |
+
history = null;
|
193 |
+
var top = {line: 0, ch: 0};
|
194 |
+
updateLines(top, {line: lines.length - 1, ch: lines[lines.length-1].text.length},
|
195 |
+
splitLines(code), top, top);
|
196 |
+
history = new History();
|
197 |
+
}
|
198 |
+
function getValue(code) {
|
199 |
+
var text = [];
|
200 |
+
for (var i = 0, l = lines.length; i < l; ++i)
|
201 |
+
text.push(lines[i].text);
|
202 |
+
return text.join("\n");
|
203 |
+
}
|
204 |
+
|
205 |
+
function onMouseDown(e) {
|
206 |
+
var ld = lastDoubleClick; lastDoubleClick = null;
|
207 |
+
// First, see if this is a click in the gutter
|
208 |
+
for (var n = e.target(); n != wrapper; n = n.parentNode)
|
209 |
+
if (n.parentNode == gutterText) {
|
210 |
+
if (options.onGutterClick)
|
211 |
+
options.onGutterClick(instance, indexOf(gutterText.childNodes, n) + showingFrom);
|
212 |
+
return e.stop();
|
213 |
+
}
|
214 |
+
|
215 |
+
if (gecko && e.button() == 3) onContextMenu(e);
|
216 |
+
if (e.button() != 1) return;
|
217 |
+
// For button 1, if it was clicked inside the editor
|
218 |
+
// (posFromMouse returning non-null), we have to adjust the
|
219 |
+
// selection.
|
220 |
+
var start = posFromMouse(e), last = start, going;
|
221 |
+
if (!start) {if (e.target() == scroller) e.stop(); return;}
|
222 |
+
|
223 |
+
if (!focused) onFocus();
|
224 |
+
e.stop();
|
225 |
+
if (ld && +new Date - ld < 400) return selectLine(start.line);
|
226 |
+
|
227 |
+
setCursor(start.line, start.ch, true);
|
228 |
+
// And then we have to see if it's a drag event, in which case
|
229 |
+
// the dragged-over text must be selected.
|
230 |
+
function end() {
|
231 |
+
focusInput();
|
232 |
+
updateInput = true;
|
233 |
+
move(); up();
|
234 |
+
}
|
235 |
+
function extend(e) {
|
236 |
+
var cur = posFromMouse(e, true);
|
237 |
+
if (cur && !posEq(cur, last)) {
|
238 |
+
if (!focused) onFocus();
|
239 |
+
last = cur;
|
240 |
+
setSelectionUser(start, cur);
|
241 |
+
updateInput = false;
|
242 |
+
var visible = visibleLines();
|
243 |
+
if (cur.line >= visible.to || cur.line < visible.from)
|
244 |
+
going = setTimeout(operation(function(){extend(e);}), 150);
|
245 |
+
}
|
246 |
+
}
|
247 |
+
|
248 |
+
var move = connect(targetDocument, "mousemove", operation(function(e) {
|
249 |
+
clearTimeout(going);
|
250 |
+
e.stop();
|
251 |
+
extend(e);
|
252 |
+
}), true);
|
253 |
+
var up = connect(targetDocument, "mouseup", operation(function(e) {
|
254 |
+
clearTimeout(going);
|
255 |
+
var cur = posFromMouse(e);
|
256 |
+
if (cur) setSelectionUser(start, cur);
|
257 |
+
e.stop();
|
258 |
+
end();
|
259 |
+
}), true);
|
260 |
+
}
|
261 |
+
function onDblClick(e) {
|
262 |
+
var pos = posFromMouse(e);
|
263 |
+
if (!pos) return;
|
264 |
+
selectWordAt(pos);
|
265 |
+
e.stop();
|
266 |
+
lastDoubleClick = +new Date;
|
267 |
+
}
|
268 |
+
function onDrop(e) {
|
269 |
+
var pos = posFromMouse(e, true), files = e.e.dataTransfer.files;
|
270 |
+
if (!pos || options.readOnly) return;
|
271 |
+
if (files && files.length && window.FileReader && window.File) {
|
272 |
+
var n = files.length, text = Array(n), read = 0;
|
273 |
+
for (var i = 0; i < n; ++i) loadFile(files[i], i);
|
274 |
+
function loadFile(file, i) {
|
275 |
+
var reader = new FileReader;
|
276 |
+
reader.onload = function() {
|
277 |
+
text[i] = reader.result;
|
278 |
+
if (++read == n) replaceRange(text.join(""), clipPos(pos), clipPos(pos));
|
279 |
+
};
|
280 |
+
reader.readAsText(file);
|
281 |
+
}
|
282 |
+
}
|
283 |
+
else {
|
284 |
+
try {
|
285 |
+
var text = e.e.dataTransfer.getData("Text");
|
286 |
+
if (text) replaceRange(text, pos, pos);
|
287 |
+
}
|
288 |
+
catch(e){}
|
289 |
+
}
|
290 |
+
}
|
291 |
+
function onKeyDown(e) {
|
292 |
+
if (!focused) onFocus();
|
293 |
+
|
294 |
+
var code = e.e.keyCode;
|
295 |
+
// IE does strange things with escape.
|
296 |
+
if (ie && code == 27) { e.e.returnValue = false; }
|
297 |
+
// Tries to detect ctrl on non-mac, cmd on mac.
|
298 |
+
var mod = (mac ? e.e.metaKey : e.e.ctrlKey) && !e.e.altKey, anyMod = e.e.ctrlKey || e.e.altKey || e.e.metaKey;
|
299 |
+
if (code == 16 || e.e.shiftKey) shiftSelecting = shiftSelecting || (sel.inverted ? sel.to : sel.from);
|
300 |
+
else shiftSelecting = null;
|
301 |
+
// First give onKeyEvent option a chance to handle this.
|
302 |
+
if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e.e))) return;
|
303 |
+
|
304 |
+
if (code == 33 || code == 34) {scrollPage(code == 34); return e.stop();} // page up/down
|
305 |
+
if (mod && ((code == 36 || code == 35) || // ctrl-home/end
|
306 |
+
mac && (code == 38 || code == 40))) { // cmd-up/down
|
307 |
+
scrollEnd(code == 36 || code == 38); return e.stop();
|
308 |
+
}
|
309 |
+
if (mod && code == 65) {selectAll(); return e.stop();} // ctrl-a
|
310 |
+
if (!options.readOnly) {
|
311 |
+
if (!anyMod && code == 13) {return;} // enter
|
312 |
+
if (!anyMod && code == 9 && handleTab(e.e.shiftKey)) return e.stop(); // tab
|
313 |
+
if (mod && code == 90) {undo(); return e.stop();} // ctrl-z
|
314 |
+
if (mod && ((e.e.shiftKey && code == 90) || code == 89)) {redo(); return e.stop();} // ctrl-shift-z, ctrl-y
|
315 |
+
}
|
316 |
+
|
317 |
+
// Key id to use in the movementKeys map. We also pass it to
|
318 |
+
// fastPoll in order to 'self learn'. We need this because
|
319 |
+
// reducedSelection, the hack where we collapse the selection to
|
320 |
+
// its start when it is inverted and a movement key is pressed
|
321 |
+
// (and later restore it again), shouldn't be used for
|
322 |
+
// non-movement keys.
|
323 |
+
curKeyId = (mod ? "c" : "") + code;
|
324 |
+
if (sel.inverted && movementKeys.hasOwnProperty(curKeyId)) {
|
325 |
+
var range = selRange(input);
|
326 |
+
if (range) {
|
327 |
+
reducedSelection = {anchor: range.start};
|
328 |
+
setSelRange(input, range.start, range.start);
|
329 |
+
}
|
330 |
+
}
|
331 |
+
fastPoll(curKeyId);
|
332 |
+
}
|
333 |
+
function onKeyUp(e) {
|
334 |
+
if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e.e))) return;
|
335 |
+
if (reducedSelection) {
|
336 |
+
reducedSelection = null;
|
337 |
+
updateInput = true;
|
338 |
+
}
|
339 |
+
if (e.e.keyCode == 16) shiftSelecting = null;
|
340 |
+
}
|
341 |
+
function onKeyPress(e) {
|
342 |
+
if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e.e))) return;
|
343 |
+
if (options.electricChars && mode.electricChars) {
|
344 |
+
var ch = String.fromCharCode(e.e.charCode == null ? e.e.keyCode : e.e.charCode);
|
345 |
+
if (mode.electricChars.indexOf(ch) > -1)
|
346 |
+
setTimeout(operation(function() {indentLine(sel.to.line, "smart");}), 50);
|
347 |
+
}
|
348 |
+
var code = e.e.keyCode;
|
349 |
+
// Re-stop tab and enter. Necessary on some browsers.
|
350 |
+
if (code == 13) {if (!options.readOnly) handleEnter(); e.stop();}
|
351 |
+
else if (!e.e.ctrlKey && !e.e.altKey && !e.e.metaKey && code == 9 && options.tabMode != "default") e.stop();
|
352 |
+
else fastPoll(curKeyId);
|
353 |
+
}
|
354 |
+
|
355 |
+
function onFocus() {
|
356 |
+
if (options.readOnly == "nocursor") return;
|
357 |
+
if (!focused && options.onFocus) options.onFocus(instance);
|
358 |
+
focused = true;
|
359 |
+
slowPoll();
|
360 |
+
if (wrapper.className.search(/\bCodeMirror-focused\b/) == -1)
|
361 |
+
wrapper.className += " CodeMirror-focused";
|
362 |
+
restartBlink();
|
363 |
+
}
|
364 |
+
function onBlur() {
|
365 |
+
if (focused && options.onBlur) options.onBlur(instance);
|
366 |
+
clearInterval(blinker);
|
367 |
+
shiftSelecting = null;
|
368 |
+
focused = false;
|
369 |
+
wrapper.className = wrapper.className.replace(" CodeMirror-focused", "");
|
370 |
+
}
|
371 |
+
|
372 |
+
// Replace the range from from to to by the strings in newText.
|
373 |
+
// Afterwards, set the selection to selFrom, selTo.
|
374 |
+
function updateLines(from, to, newText, selFrom, selTo) {
|
375 |
+
if (history) {
|
376 |
+
var old = [];
|
377 |
+
for (var i = from.line, e = to.line + 1; i < e; ++i) old.push(lines[i].text);
|
378 |
+
history.addChange(from.line, newText.length, old);
|
379 |
+
while (history.done.length > options.undoDepth) history.done.shift();
|
380 |
+
}
|
381 |
+
updateLinesNoUndo(from, to, newText, selFrom, selTo);
|
382 |
+
if (newText.length < 5)
|
383 |
+
highlightLines(from.line, from.line + newText.length)
|
384 |
+
}
|
385 |
+
function unredoHelper(from, to) {
|
386 |
+
var change = from.pop();
|
387 |
+
if (change) {
|
388 |
+
var replaced = [], end = change.start + change.added;
|
389 |
+
for (var i = change.start; i < end; ++i) replaced.push(lines[i].text);
|
390 |
+
to.push({start: change.start, added: change.old.length, old: replaced});
|
391 |
+
var pos = clipPos({line: change.start + change.old.length - 1,
|
392 |
+
ch: editEnd(replaced[replaced.length-1], change.old[change.old.length-1])});
|
393 |
+
updateLinesNoUndo({line: change.start, ch: 0}, {line: end - 1, ch: lines[end-1].text.length}, change.old, pos, pos);
|
394 |
+
}
|
395 |
+
}
|
396 |
+
function undo() {unredoHelper(history.done, history.undone);}
|
397 |
+
function redo() {unredoHelper(history.undone, history.done);}
|
398 |
+
|
399 |
+
function updateLinesNoUndo(from, to, newText, selFrom, selTo) {
|
400 |
+
var recomputeMaxLength = false, maxLineLength = maxLine.length;
|
401 |
+
for (var i = from.line; i <= to.line; ++i) {
|
402 |
+
if (lines[i].text.length == maxLineLength) {recomputeMaxLength = true; break;}
|
403 |
+
}
|
404 |
+
|
405 |
+
var nlines = to.line - from.line, firstLine = lines[from.line], lastLine = lines[to.line];
|
406 |
+
// First adjust the line structure, taking some care to leave highlighting intact.
|
407 |
+
if (firstLine == lastLine) {
|
408 |
+
if (newText.length == 1)
|
409 |
+
firstLine.replace(from.ch, to.ch, newText[0]);
|
410 |
+
else {
|
411 |
+
lastLine = firstLine.split(to.ch, newText[newText.length-1]);
|
412 |
+
var spliceargs = [from.line + 1, nlines];
|
413 |
+
firstLine.replace(from.ch, firstLine.text.length, newText[0]);
|
414 |
+
for (var i = 1, e = newText.length - 1; i < e; ++i) spliceargs.push(new Line(newText[i]));
|
415 |
+
spliceargs.push(lastLine);
|
416 |
+
lines.splice.apply(lines, spliceargs);
|
417 |
+
}
|
418 |
+
}
|
419 |
+
else if (newText.length == 1) {
|
420 |
+
firstLine.replace(from.ch, firstLine.text.length, newText[0] + lastLine.text.slice(to.ch));
|
421 |
+
lines.splice(from.line + 1, nlines);
|
422 |
+
}
|
423 |
+
else {
|
424 |
+
var spliceargs = [from.line + 1, nlines - 1];
|
425 |
+
firstLine.replace(from.ch, firstLine.text.length, newText[0]);
|
426 |
+
lastLine.replace(0, to.ch, newText[newText.length-1]);
|
427 |
+
for (var i = 1, e = newText.length - 1; i < e; ++i) spliceargs.push(new Line(newText[i]));
|
428 |
+
lines.splice.apply(lines, spliceargs);
|
429 |
+
}
|
430 |
+
|
431 |
+
|
432 |
+
for (var i = from.line, e = i + newText.length; i < e; ++i) {
|
433 |
+
var l = lines[i].text;
|
434 |
+
if (l.length > maxLineLength) {
|
435 |
+
maxLine = l; maxLineLength = l.length;
|
436 |
+
recomputeMaxLength = false;
|
437 |
+
}
|
438 |
+
}
|
439 |
+
if (recomputeMaxLength) {
|
440 |
+
maxLineLength = 0; maxLine = "";
|
441 |
+
for (var i = 0, e = lines.length; i < e; ++i) {
|
442 |
+
var l = lines[i].text;
|
443 |
+
if (l.length > maxLineLength) {
|
444 |
+
maxLineLength = l.length; maxLine = l;
|
445 |
+
}
|
446 |
+
}
|
447 |
+
}
|
448 |
+
|
449 |
+
// Add these lines to the work array, so that they will be
|
450 |
+
// highlighted. Adjust work lines if lines were added/removed.
|
451 |
+
var newWork = [], lendiff = newText.length - nlines - 1;
|
452 |
+
for (var i = 0, l = work.length; i < l; ++i) {
|
453 |
+
var task = work[i];
|
454 |
+
if (task < from.line) newWork.push(task);
|
455 |
+
else if (task > to.line) newWork.push(task + lendiff);
|
456 |
+
}
|
457 |
+
if (newText.length) newWork.push(from.line);
|
458 |
+
work = newWork;
|
459 |
+
startWorker(100);
|
460 |
+
// Remember that these lines changed, for updating the display
|
461 |
+
changes.push({from: from.line, to: to.line + 1, diff: lendiff});
|
462 |
+
textChanged = {from: from, to: to, text: newText};
|
463 |
+
|
464 |
+
// Update the selection
|
465 |
+
function updateLine(n) {return n <= Math.min(to.line, to.line + lendiff) ? n : n + lendiff;}
|
466 |
+
setSelection(selFrom, selTo, updateLine(sel.from.line), updateLine(sel.to.line));
|
467 |
+
|
468 |
+
// Make sure the scroll-size div has the correct height.
|
469 |
+
code.style.height = (lines.length * lineHeight() + 2 * paddingTop()) + "px";
|
470 |
+
}
|
471 |
+
|
472 |
+
function replaceRange(code, from, to) {
|
473 |
+
from = clipPos(from);
|
474 |
+
if (!to) to = from; else to = clipPos(to);
|
475 |
+
code = splitLines(code);
|
476 |
+
function adjustPos(pos) {
|
477 |
+
if (posLess(pos, from)) return pos;
|
478 |
+
if (!posLess(to, pos)) return end;
|
479 |
+
var line = pos.line + code.length - (to.line - from.line) - 1;
|
480 |
+
var ch = pos.ch;
|
481 |
+
if (pos.line == to.line)
|
482 |
+
ch += code[code.length-1].length - (to.ch - (to.line == from.line ? from.ch : 0));
|
483 |
+
return {line: line, ch: ch};
|
484 |
+
}
|
485 |
+
var end;
|
486 |
+
replaceRange1(code, from, to, function(end1) {
|
487 |
+
end = end1;
|
488 |
+
return {from: adjustPos(sel.from), to: adjustPos(sel.to)};
|
489 |
+
});
|
490 |
+
return end;
|
491 |
+
}
|
492 |
+
function replaceSelection(code, collapse) {
|
493 |
+
replaceRange1(splitLines(code), sel.from, sel.to, function(end) {
|
494 |
+
if (collapse == "end") return {from: end, to: end};
|
495 |
+
else if (collapse == "start") return {from: sel.from, to: sel.from};
|
496 |
+
else return {from: sel.from, to: end};
|
497 |
+
});
|
498 |
+
}
|
499 |
+
function replaceRange1(code, from, to, computeSel) {
|
500 |
+
var endch = code.length == 1 ? code[0].length + from.ch : code[code.length-1].length;
|
501 |
+
var newSel = computeSel({line: from.line + code.length - 1, ch: endch});
|
502 |
+
updateLines(from, to, code, newSel.from, newSel.to);
|
503 |
+
}
|
504 |
+
|
505 |
+
function getRange(from, to) {
|
506 |
+
var l1 = from.line, l2 = to.line;
|
507 |
+
if (l1 == l2) return lines[l1].text.slice(from.ch, to.ch);
|
508 |
+
var code = [lines[l1].text.slice(from.ch)];
|
509 |
+
for (var i = l1 + 1; i < l2; ++i) code.push(lines[i].text);
|
510 |
+
code.push(lines[l2].text.slice(0, to.ch));
|
511 |
+
return code.join("\n");
|
512 |
+
}
|
513 |
+
function getSelection() {
|
514 |
+
return getRange(sel.from, sel.to);
|
515 |
+
}
|
516 |
+
|
517 |
+
var pollingFast = false; // Ensures slowPoll doesn't cancel fastPoll
|
518 |
+
function slowPoll() {
|
519 |
+
if (pollingFast) return;
|
520 |
+
poll.set(2000, function() {
|
521 |
+
startOperation();
|
522 |
+
readInput();
|
523 |
+
if (focused) slowPoll();
|
524 |
+
endOperation();
|
525 |
+
});
|
526 |
+
}
|
527 |
+
function fastPoll(keyId) {
|
528 |
+
var missed = false;
|
529 |
+
pollingFast = true;
|
530 |
+
function p() {
|
531 |
+
startOperation();
|
532 |
+
var changed = readInput();
|
533 |
+
if (changed == "moved" && keyId) movementKeys[keyId] = true;
|
534 |
+
if (!changed && !missed) {missed = true; poll.set(80, p);}
|
535 |
+
else {pollingFast = false; slowPoll();}
|
536 |
+
endOperation();
|
537 |
+
}
|
538 |
+
poll.set(20, p);
|
539 |
+
}
|
540 |
+
|
541 |
+
// Inspects the textarea, compares its state (content, selection)
|
542 |
+
// to the data in the editing variable, and updates the editor
|
543 |
+
// content or cursor if something changed.
|
544 |
+
function readInput() {
|
545 |
+
if (leaveInputAlone) return;
|
546 |
+
var changed = false, text = input.value, sr = selRange(input);
|
547 |
+
if (!sr) return false;
|
548 |
+
var changed = editing.text != text, rs = reducedSelection;
|
549 |
+
var moved = changed || sr.start != editing.start || sr.end != (rs ? editing.start : editing.end);
|
550 |
+
if (!moved && !rs) return false;
|
551 |
+
if (changed) {
|
552 |
+
shiftSelecting = reducedSelection = null;
|
553 |
+
if (options.readOnly) {updateInput = true; return "changed";}
|
554 |
+
}
|
555 |
+
|
556 |
+
// Compute selection start and end based on start/end offsets in textarea
|
557 |
+
function computeOffset(n, startLine) {
|
558 |
+
var pos = 0;
|
559 |
+
for (;;) {
|
560 |
+
var found = text.indexOf("\n", pos);
|
561 |
+
if (found == -1 || (text.charAt(found-1) == "\r" ? found - 1 : found) >= n)
|
562 |
+
return {line: startLine, ch: n - pos};
|
563 |
+
++startLine;
|
564 |
+
pos = found + 1;
|
565 |
+
}
|
566 |
+
}
|
567 |
+
var from = computeOffset(sr.start, editing.from),
|
568 |
+
to = computeOffset(sr.end, editing.from);
|
569 |
+
// Here we have to take the reducedSelection hack into account,
|
570 |
+
// so that you can, for example, press shift-up at the start of
|
571 |
+
// your selection and have the right thing happen.
|
572 |
+
if (rs) {
|
573 |
+
var head = sr.start == rs.anchor ? to : from;
|
574 |
+
var tail = shiftSelecting ? sel.to : sr.start == rs.anchor ? from : to;
|
575 |
+
if (sel.inverted = posLess(head, tail)) { from = head; to = tail; }
|
576 |
+
else { reducedSelection = null; from = tail; to = head; }
|
577 |
+
}
|
578 |
+
|
579 |
+
// In some cases (cursor on same line as before), we don't have
|
580 |
+
// to update the textarea content at all.
|
581 |
+
if (from.line == to.line && from.line == sel.from.line && from.line == sel.to.line && !shiftSelecting)
|
582 |
+
updateInput = false;
|
583 |
+
|
584 |
+
// Magic mess to extract precise edited range from the changed
|
585 |
+
// string.
|
586 |
+
if (changed) {
|
587 |
+
var start = 0, end = text.length, len = Math.min(end, editing.text.length);
|
588 |
+
var c, line = editing.from, nl = -1;
|
589 |
+
while (start < len && (c = text.charAt(start)) == editing.text.charAt(start)) {
|
590 |
+
++start;
|
591 |
+
if (c == "\n") {line++; nl = start;}
|
592 |
+
}
|
593 |
+
var ch = nl > -1 ? start - nl : start, endline = editing.to - 1, edend = editing.text.length;
|
594 |
+
for (;;) {
|
595 |
+
c = editing.text.charAt(edend);
|
596 |
+
if (text.charAt(end) != c) {++end; ++edend; break;}
|
597 |
+
if (c == "\n") endline--;
|
598 |
+
if (edend <= start || end <= start) break;
|
599 |
+
--end; --edend;
|
600 |
+
}
|
601 |
+
var nl = editing.text.lastIndexOf("\n", edend - 1), endch = nl == -1 ? edend : edend - nl - 1;
|
602 |
+
updateLines({line: line, ch: ch}, {line: endline, ch: endch}, splitLines(text.slice(start, end)), from, to);
|
603 |
+
if (line != endline || from.line != line) updateInput = true;
|
604 |
+
}
|
605 |
+
else setSelection(from, to);
|
606 |
+
|
607 |
+
editing.text = text; editing.start = sr.start; editing.end = sr.end;
|
608 |
+
return changed ? "changed" : moved ? "moved" : false;
|
609 |
+
}
|
610 |
+
|
611 |
+
// Set the textarea content and selection range to match the
|
612 |
+
// editor state.
|
613 |
+
function prepareInput() {
|
614 |
+
var text = [];
|
615 |
+
var from = Math.max(0, sel.from.line - 1), to = Math.min(lines.length, sel.to.line + 2);
|
616 |
+
for (var i = from; i < to; ++i) text.push(lines[i].text);
|
617 |
+
text = input.value = text.join(lineSep);
|
618 |
+
var startch = sel.from.ch, endch = sel.to.ch;
|
619 |
+
for (var i = from; i < sel.from.line; ++i)
|
620 |
+
startch += lineSep.length + lines[i].text.length;
|
621 |
+
for (var i = from; i < sel.to.line; ++i)
|
622 |
+
endch += lineSep.length + lines[i].text.length;
|
623 |
+
editing = {text: text, from: from, to: to, start: startch, end: endch};
|
624 |
+
setSelRange(input, startch, reducedSelection ? startch : endch);
|
625 |
+
}
|
626 |
+
function focusInput() {
|
627 |
+
if (options.readOnly != "nocursor") input.focus();
|
628 |
+
}
|
629 |
+
|
630 |
+
function scrollCursorIntoView() {
|
631 |
+
var cursor = localCoords(sel.inverted ? sel.from : sel.to);
|
632 |
+
return scrollIntoView(cursor.x, cursor.y, cursor.x, cursor.yBot);
|
633 |
+
}
|
634 |
+
function scrollIntoView(x1, y1, x2, y2) {
|
635 |
+
var pl = paddingLeft(), pt = paddingTop(), lh = lineHeight();
|
636 |
+
y1 += pt; y2 += pt; x1 += pl; x2 += pl;
|
637 |
+
var screen = scroller.clientHeight, screentop = scroller.scrollTop, scrolled = false, result = true;
|
638 |
+
if (y1 < screentop) {scroller.scrollTop = Math.max(0, y1 - 2*lh); scrolled = true;}
|
639 |
+
else if (y2 > screentop + screen) {scroller.scrollTop = y2 + lh - screen; scrolled = true;}
|
640 |
+
|
641 |
+
var screenw = scroller.clientWidth, screenleft = scroller.scrollLeft;
|
642 |
+
if (x1 < screenleft) {
|
643 |
+
if (x1 < 50) x1 = 0;
|
644 |
+
scroller.scrollLeft = Math.max(0, x1 - 10);
|
645 |
+
scrolled = true;
|
646 |
+
}
|
647 |
+
else if (x2 > screenw + screenleft) {
|
648 |
+
scroller.scrollLeft = x2 + 10 - screenw;
|
649 |
+
scrolled = true;
|
650 |
+
if (x2 > code.clientWidth) result = false;
|
651 |
+
}
|
652 |
+
if (scrolled && options.onScroll) options.onScroll(instance);
|
653 |
+
return result;
|
654 |
+
}
|
655 |
+
|
656 |
+
function visibleLines() {
|
657 |
+
var lh = lineHeight(), top = scroller.scrollTop - paddingTop();
|
658 |
+
return {from: Math.min(lines.length, Math.max(0, Math.floor(top / lh))),
|
659 |
+
to: Math.min(lines.length, Math.ceil((top + scroller.clientHeight) / lh))};
|
660 |
+
}
|
661 |
+
// Uses a set of changes plus the current scroll position to
|
662 |
+
// determine which DOM updates have to be made, and makes the
|
663 |
+
// updates.
|
664 |
+
function updateDisplay(changes) {
|
665 |
+
if (!scroller.clientWidth) {
|
666 |
+
showingFrom = showingTo = 0;
|
667 |
+
return;
|
668 |
+
}
|
669 |
+
// First create a range of theoretically intact lines, and punch
|
670 |
+
// holes in that using the change info.
|
671 |
+
var intact = changes === true ? [] : [{from: showingFrom, to: showingTo, domStart: 0}];
|
672 |
+
for (var i = 0, l = changes.length || 0; i < l; ++i) {
|
673 |
+
var change = changes[i], intact2 = [], diff = change.diff || 0;
|
674 |
+
for (var j = 0, l2 = intact.length; j < l2; ++j) {
|
675 |
+
var range = intact[j];
|
676 |
+
if (change.to <= range.from)
|
677 |
+
intact2.push({from: range.from + diff, to: range.to + diff, domStart: range.domStart});
|
678 |
+
else if (range.to <= change.from)
|
679 |
+
intact2.push(range);
|
680 |
+
else {
|
681 |
+
if (change.from > range.from)
|
682 |
+
intact2.push({from: range.from, to: change.from, domStart: range.domStart})
|
683 |
+
if (change.to < range.to)
|
684 |
+
intact2.push({from: change.to + diff, to: range.to + diff,
|
685 |
+
domStart: range.domStart + (change.to - range.from)});
|
686 |
+
}
|
687 |
+
}
|
688 |
+
intact = intact2;
|
689 |
+
}
|
690 |
+
|
691 |
+
// Then, determine which lines we'd want to see, and which
|
692 |
+
// updates have to be made to get there.
|
693 |
+
var visible = visibleLines();
|
694 |
+
var from = Math.min(showingFrom, Math.max(visible.from - 3, 0)),
|
695 |
+
to = Math.min(lines.length, Math.max(showingTo, visible.to + 3)),
|
696 |
+
updates = [], domPos = 0, domEnd = showingTo - showingFrom, pos = from, changedLines = 0;
|
697 |
+
|
698 |
+
for (var i = 0, l = intact.length; i < l; ++i) {
|
699 |
+
var range = intact[i];
|
700 |
+
if (range.to <= from) continue;
|
701 |
+
if (range.from >= to) break;
|
702 |
+
if (range.domStart > domPos || range.from > pos) {
|
703 |
+
updates.push({from: pos, to: range.from, domSize: range.domStart - domPos, domStart: domPos});
|
704 |
+
changedLines += range.from - pos;
|
705 |
+
}
|
706 |
+
pos = range.to;
|
707 |
+
domPos = range.domStart + (range.to - range.from);
|
708 |
+
}
|
709 |
+
if (domPos != domEnd || pos != to) {
|
710 |
+
changedLines += Math.abs(to - pos);
|
711 |
+
updates.push({from: pos, to: to, domSize: domEnd - domPos, domStart: domPos});
|
712 |
+
}
|
713 |
+
|
714 |
+
if (!updates.length) return;
|
715 |
+
lineDiv.style.display = "none";
|
716 |
+
// If more than 30% of the screen needs update, just do a full
|
717 |
+
// redraw (which is quicker than patching)
|
718 |
+
if (changedLines > (visible.to - visible.from) * .3)
|
719 |
+
refreshDisplay(from = Math.max(visible.from - 10, 0), to = Math.min(visible.to + 7, lines.length));
|
720 |
+
// Otherwise, only update the stuff that needs updating.
|
721 |
+
else
|
722 |
+
patchDisplay(updates);
|
723 |
+
lineDiv.style.display = "";
|
724 |
+
|
725 |
+
// Position the mover div to align with the lines it's supposed
|
726 |
+
// to be showing (which will cover the visible display)
|
727 |
+
var different = from != showingFrom || to != showingTo || lastHeight != scroller.clientHeight;
|
728 |
+
showingFrom = from; showingTo = to;
|
729 |
+
mover.style.top = (from * lineHeight()) + "px";
|
730 |
+
if (different) {
|
731 |
+
lastHeight = scroller.clientHeight;
|
732 |
+
code.style.height = (lines.length * lineHeight() + 2 * paddingTop()) + "px";
|
733 |
+
updateGutter();
|
734 |
+
}
|
735 |
+
|
736 |
+
var textWidth = stringWidth(maxLine);
|
737 |
+
lineSpace.style.width = textWidth > scroller.clientWidth ? textWidth + "px" : "";
|
738 |
+
|
739 |
+
// Since this is all rather error prone, it is honoured with the
|
740 |
+
// only assertion in the whole file.
|
741 |
+
if (lineDiv.childNodes.length != showingTo - showingFrom)
|
742 |
+
throw new Error("BAD PATCH! " + JSON.stringify(updates) + " size=" + (showingTo - showingFrom) +
|
743 |
+
" nodes=" + lineDiv.childNodes.length);
|
744 |
+
updateCursor();
|
745 |
+
}
|
746 |
+
|
747 |
+
function refreshDisplay(from, to) {
|
748 |
+
var html = [], start = {line: from, ch: 0}, inSel = posLess(sel.from, start) && !posLess(sel.to, start);
|
749 |
+
for (var i = from; i < to; ++i) {
|
750 |
+
var ch1 = null, ch2 = null;
|
751 |
+
if (inSel) {
|
752 |
+
ch1 = 0;
|
753 |
+
if (sel.to.line == i) {inSel = false; ch2 = sel.to.ch;}
|
754 |
+
}
|
755 |
+
else if (sel.from.line == i) {
|
756 |
+
if (sel.to.line == i) {ch1 = sel.from.ch; ch2 = sel.to.ch;}
|
757 |
+
else {inSel = true; ch1 = sel.from.ch;}
|
758 |
+
}
|
759 |
+
html.push(lines[i].getHTML(ch1, ch2, true));
|
760 |
+
}
|
761 |
+
lineDiv.innerHTML = html.join("");
|
762 |
+
}
|
763 |
+
function patchDisplay(updates) {
|
764 |
+
// Slightly different algorithm for IE (badInnerHTML), since
|
765 |
+
// there .innerHTML on PRE nodes is dumb, and discards
|
766 |
+
// whitespace.
|
767 |
+
var sfrom = sel.from.line, sto = sel.to.line, off = 0,
|
768 |
+
scratch = badInnerHTML && targetDocument.createElement("div");
|
769 |
+
for (var i = 0, e = updates.length; i < e; ++i) {
|
770 |
+
var rec = updates[i];
|
771 |
+
var extra = (rec.to - rec.from) - rec.domSize;
|
772 |
+
var nodeAfter = lineDiv.childNodes[rec.domStart + rec.domSize + off] || null;
|
773 |
+
if (badInnerHTML)
|
774 |
+
for (var j = Math.max(-extra, rec.domSize); j > 0; --j)
|
775 |
+
lineDiv.removeChild(nodeAfter ? nodeAfter.previousSibling : lineDiv.lastChild);
|
776 |
+
else if (extra) {
|
777 |
+
for (var j = Math.max(0, extra); j > 0; --j)
|
778 |
+
lineDiv.insertBefore(targetDocument.createElement("pre"), nodeAfter);
|
779 |
+
for (var j = Math.max(0, -extra); j > 0; --j)
|
780 |
+
lineDiv.removeChild(nodeAfter ? nodeAfter.previousSibling : lineDiv.lastChild);
|
781 |
+
}
|
782 |
+
var node = lineDiv.childNodes[rec.domStart + off], inSel = sfrom < rec.from && sto >= rec.from;
|
783 |
+
for (var j = rec.from; j < rec.to; ++j) {
|
784 |
+
var ch1 = null, ch2 = null;
|
785 |
+
if (inSel) {
|
786 |
+
ch1 = 0;
|
787 |
+
if (sto == j) {inSel = false; ch2 = sel.to.ch;}
|
788 |
+
}
|
789 |
+
else if (sfrom == j) {
|
790 |
+
if (sto == j) {ch1 = sel.from.ch; ch2 = sel.to.ch;}
|
791 |
+
else {inSel = true; ch1 = sel.from.ch;}
|
792 |
+
}
|
793 |
+
if (badInnerHTML) {
|
794 |
+
scratch.innerHTML = lines[j].getHTML(ch1, ch2, true);
|
795 |
+
lineDiv.insertBefore(scratch.firstChild, nodeAfter);
|
796 |
+
}
|
797 |
+
else {
|
798 |
+
node.innerHTML = lines[j].getHTML(ch1, ch2, false);
|
799 |
+
node.className = lines[j].className || "";
|
800 |
+
node = node.nextSibling;
|
801 |
+
}
|
802 |
+
}
|
803 |
+
off += extra;
|
804 |
+
}
|
805 |
+
}
|
806 |
+
|
807 |
+
function updateGutter() {
|
808 |
+
if (!options.gutter && !options.lineNumbers) return;
|
809 |
+
var hText = mover.offsetHeight, hEditor = scroller.clientHeight;
|
810 |
+
gutter.style.height = (hText - hEditor < 2 ? hEditor : hText) + "px";
|
811 |
+
var html = [];
|
812 |
+
for (var i = showingFrom; i < Math.max(showingTo, showingFrom + 1); ++i) {
|
813 |
+
var marker = lines[i].gutterMarker;
|
814 |
+
var text = options.lineNumbers ? i + options.firstLineNumber : null;
|
815 |
+
if (marker && marker.text)
|
816 |
+
text = marker.text.replace("%N%", text != null ? text : "");
|
817 |
+
else if (text == null)
|
818 |
+
text = "\u00a0";
|
819 |
+
html.push((marker && marker.style ? '<pre class="' + marker.style + '">' : "<pre>"), text, "</pre>");
|
820 |
+
}
|
821 |
+
gutter.style.display = "none";
|
822 |
+
gutterText.innerHTML = html.join("");
|
823 |
+
var minwidth = String(lines.length).length, firstNode = gutterText.firstChild, val = eltText(firstNode), pad = "";
|
824 |
+
while (val.length + pad.length < minwidth) pad += "\u00a0";
|
825 |
+
if (pad) firstNode.insertBefore(targetDocument.createTextNode(pad), firstNode.firstChild);
|
826 |
+
gutter.style.display = "";
|
827 |
+
lineSpace.style.marginLeft = gutter.offsetWidth + "px";
|
828 |
+
}
|
829 |
+
function updateCursor() {
|
830 |
+
var head = sel.inverted ? sel.from : sel.to, lh = lineHeight();
|
831 |
+
var x = charX(head.line, head.ch) + "px", y = (head.line - showingFrom) * lh + "px";
|
832 |
+
inputDiv.style.top = (head.line * lh - scroller.scrollTop) + "px";
|
833 |
+
if (posEq(sel.from, sel.to)) {
|
834 |
+
cursor.style.top = y; cursor.style.left = x;
|
835 |
+
cursor.style.display = "";
|
836 |
+
}
|
837 |
+
else cursor.style.display = "none";
|
838 |
+
}
|
839 |
+
|
840 |
+
function setSelectionUser(from, to) {
|
841 |
+
var sh = shiftSelecting && clipPos(shiftSelecting);
|
842 |
+
if (sh) {
|
843 |
+
if (posLess(sh, from)) from = sh;
|
844 |
+
else if (posLess(to, sh)) to = sh;
|
845 |
+
}
|
846 |
+
setSelection(from, to);
|
847 |
+
}
|
848 |
+
// Update the selection. Last two args are only used by
|
849 |
+
// updateLines, since they have to be expressed in the line
|
850 |
+
// numbers before the update.
|
851 |
+
function setSelection(from, to, oldFrom, oldTo) {
|
852 |
+
if (posEq(sel.from, from) && posEq(sel.to, to)) return;
|
853 |
+
if (posLess(to, from)) {var tmp = to; to = from; from = tmp;}
|
854 |
+
|
855 |
+
if (posEq(from, to)) sel.inverted = false;
|
856 |
+
else if (posEq(from, sel.to)) sel.inverted = false;
|
857 |
+
else if (posEq(to, sel.from)) sel.inverted = true;
|
858 |
+
|
859 |
+
// Some ugly logic used to only mark the lines that actually did
|
860 |
+
// see a change in selection as changed, rather than the whole
|
861 |
+
// selected range.
|
862 |
+
if (oldFrom == null) {oldFrom = sel.from.line; oldTo = sel.to.line;}
|
863 |
+
if (posEq(from, to)) {
|
864 |
+
if (!posEq(sel.from, sel.to))
|
865 |
+
changes.push({from: oldFrom, to: oldTo + 1});
|
866 |
+
}
|
867 |
+
else if (posEq(sel.from, sel.to)) {
|
868 |
+
changes.push({from: from.line, to: to.line + 1});
|
869 |
+
}
|
870 |
+
else {
|
871 |
+
if (!posEq(from, sel.from)) {
|
872 |
+
if (from.line < oldFrom)
|
873 |
+
changes.push({from: from.line, to: Math.min(to.line, oldFrom) + 1});
|
874 |
+
else
|
875 |
+
changes.push({from: oldFrom, to: Math.min(oldTo, from.line) + 1});
|
876 |
+
}
|
877 |
+
if (!posEq(to, sel.to)) {
|
878 |
+
if (to.line < oldTo)
|
879 |
+
changes.push({from: Math.max(oldFrom, from.line), to: oldTo + 1});
|
880 |
+
else
|
881 |
+
changes.push({from: Math.max(from.line, oldTo), to: to.line + 1});
|
882 |
+
}
|
883 |
+
}
|
884 |
+
sel.from = from; sel.to = to;
|
885 |
+
selectionChanged = true;
|
886 |
+
}
|
887 |
+
function setCursor(line, ch, user) {
|
888 |
+
var pos = clipPos({line: line, ch: ch || 0});
|
889 |
+
(user ? setSelectionUser : setSelection)(pos, pos);
|
890 |
+
}
|
891 |
+
|
892 |
+
function clipLine(n) {return Math.max(0, Math.min(n, lines.length-1));}
|
893 |
+
function clipPos(pos) {
|
894 |
+
if (pos.line < 0) return {line: 0, ch: 0};
|
895 |
+
if (pos.line >= lines.length) return {line: lines.length-1, ch: lines[lines.length-1].text.length};
|
896 |
+
var ch = pos.ch, linelen = lines[pos.line].text.length;
|
897 |
+
if (ch == null || ch > linelen) return {line: pos.line, ch: linelen};
|
898 |
+
else if (ch < 0) return {line: pos.line, ch: 0};
|
899 |
+
else return pos;
|
900 |
+
}
|
901 |
+
|
902 |
+
function scrollPage(down) {
|
903 |
+
var linesPerPage = Math.floor(scroller.clientHeight / lineHeight()), head = sel.inverted ? sel.from : sel.to;
|
904 |
+
setCursor(head.line + (Math.max(linesPerPage - 1, 1) * (down ? 1 : -1)), head.ch, true);
|
905 |
+
}
|
906 |
+
function scrollEnd(top) {
|
907 |
+
var pos = top ? {line: 0, ch: 0} : {line: lines.length - 1, ch: lines[lines.length-1].text.length};
|
908 |
+
setSelectionUser(pos, pos);
|
909 |
+
}
|
910 |
+
function selectAll() {
|
911 |
+
var endLine = lines.length - 1;
|
912 |
+
setSelection({line: 0, ch: 0}, {line: endLine, ch: lines[endLine].text.length});
|
913 |
+
}
|
914 |
+
function selectWordAt(pos) {
|
915 |
+
var line = lines[pos.line].text;
|
916 |
+
var start = pos.ch, end = pos.ch;
|
917 |
+
while (start > 0 && /\w/.test(line.charAt(start - 1))) --start;
|
918 |
+
while (end < line.length && /\w/.test(line.charAt(end))) ++end;
|
919 |
+
setSelectionUser({line: pos.line, ch: start}, {line: pos.line, ch: end});
|
920 |
+
}
|
921 |
+
function selectLine(line) {
|
922 |
+
setSelectionUser({line: line, ch: 0}, {line: line, ch: lines[line].text.length});
|
923 |
+
}
|
924 |
+
function handleEnter() {
|
925 |
+
replaceSelection("\n", "end");
|
926 |
+
if (options.enterMode != "flat")
|
927 |
+
indentLine(sel.from.line, options.enterMode == "keep" ? "prev" : "smart");
|
928 |
+
}
|
929 |
+
function handleTab(shift) {
|
930 |
+
shiftSelecting = null;
|
931 |
+
switch (options.tabMode) {
|
932 |
+
case "default":
|
933 |
+
return false;
|
934 |
+
case "indent":
|
935 |
+
for (var i = sel.from.line, e = sel.to.line; i <= e; ++i) indentLine(i, "smart");
|
936 |
+
break;
|
937 |
+
case "classic":
|
938 |
+
if (posEq(sel.from, sel.to)) {
|
939 |
+
if (shift) indentLine(sel.from.line, "smart");
|
940 |
+
else replaceSelection("\t", "end");
|
941 |
+
break;
|
942 |
+
}
|
943 |
+
case "shift":
|
944 |
+
for (var i = sel.from.line, e = sel.to.line; i <= e; ++i) indentLine(i, shift ? "subtract" : "add");
|
945 |
+
break;
|
946 |
+
}
|
947 |
+
return true;
|
948 |
+
}
|
949 |
+
|
950 |
+
function indentLine(n, how) {
|
951 |
+
if (how == "smart") {
|
952 |
+
if (!mode.indent) how = "prev";
|
953 |
+
else var state = getStateBefore(n);
|
954 |
+
}
|
955 |
+
|
956 |
+
var line = lines[n], curSpace = line.indentation(), curSpaceString = line.text.match(/^\s*/)[0], indentation;
|
957 |
+
if (how == "prev") {
|
958 |
+
if (n) indentation = lines[n-1].indentation();
|
959 |
+
else indentation = 0;
|
960 |
+
}
|
961 |
+
else if (how == "smart") indentation = mode.indent(state, line.text.slice(curSpaceString.length));
|
962 |
+
else if (how == "add") indentation = curSpace + options.indentUnit;
|
963 |
+
else if (how == "subtract") indentation = curSpace - options.indentUnit;
|
964 |
+
indentation = Math.max(0, indentation);
|
965 |
+
var diff = indentation - curSpace;
|
966 |
+
|
967 |
+
if (!diff) {
|
968 |
+
if (sel.from.line != n && sel.to.line != n) return;
|
969 |
+
var indentString = curSpaceString;
|
970 |
+
}
|
971 |
+
else {
|
972 |
+
var indentString = "", pos = 0;
|
973 |
+
if (options.indentWithTabs)
|
974 |
+
for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
|
975 |
+
while (pos < indentation) {++pos; indentString += " ";}
|
976 |
+
}
|
977 |
+
|
978 |
+
replaceRange(indentString, {line: n, ch: 0}, {line: n, ch: curSpaceString.length});
|
979 |
+
}
|
980 |
+
|
981 |
+
function loadMode() {
|
982 |
+
mode = CodeMirror.getMode(options, options.mode);
|
983 |
+
for (var i = 0, l = lines.length; i < l; ++i)
|
984 |
+
lines[i].stateAfter = null;
|
985 |
+
work = [0];
|
986 |
+
startWorker();
|
987 |
+
}
|
988 |
+
function gutterChanged() {
|
989 |
+
var visible = options.gutter || options.lineNumbers;
|
990 |
+
gutter.style.display = visible ? "" : "none";
|
991 |
+
if (visible) updateGutter();
|
992 |
+
else lineDiv.parentNode.style.marginLeft = 0;
|
993 |
+
}
|
994 |
+
|
995 |
+
function markText(from, to, className) {
|
996 |
+
from = clipPos(from); to = clipPos(to);
|
997 |
+
var accum = [];
|
998 |
+
function add(line, from, to, className) {
|
999 |
+
var line = lines[line], mark = line.addMark(from, to, className);
|
1000 |
+
mark.line = line;
|
1001 |
+
accum.push(mark);
|
1002 |
+
}
|
1003 |
+
if (from.line == to.line) add(from.line, from.ch, to.ch, className);
|
1004 |
+
else {
|
1005 |
+
add(from.line, from.ch, null, className);
|
1006 |
+
for (var i = from.line + 1, e = to.line; i < e; ++i)
|
1007 |
+
add(i, 0, null, className);
|
1008 |
+
add(to.line, 0, to.ch, className);
|
1009 |
+
}
|
1010 |
+
changes.push({from: from.line, to: to.line + 1});
|
1011 |
+
return function() {
|
1012 |
+
var start, end;
|
1013 |
+
for (var i = 0; i < accum.length; ++i) {
|
1014 |
+
var mark = accum[i], found = indexOf(lines, mark.line);
|
1015 |
+
mark.line.removeMark(mark);
|
1016 |
+
if (found > -1) {
|
1017 |
+
if (start == null) start = found;
|
1018 |
+
end = found;
|
1019 |
+
}
|
1020 |
+
}
|
1021 |
+
if (start != null) changes.push({from: start, to: end + 1});
|
1022 |
+
};
|
1023 |
+
}
|
1024 |
+
|
1025 |
+
function addGutterMarker(line, text, className) {
|
1026 |
+
if (typeof line == "number") line = lines[clipLine(line)];
|
1027 |
+
line.gutterMarker = {text: text, style: className};
|
1028 |
+
updateGutter();
|
1029 |
+
return line;
|
1030 |
+
}
|
1031 |
+
function removeGutterMarker(line) {
|
1032 |
+
if (typeof line == "number") line = lines[clipLine(line)];
|
1033 |
+
line.gutterMarker = null;
|
1034 |
+
updateGutter();
|
1035 |
+
}
|
1036 |
+
function setLineClass(line, className) {
|
1037 |
+
if (typeof line == "number") {
|
1038 |
+
var no = line;
|
1039 |
+
line = lines[clipLine(line)];
|
1040 |
+
}
|
1041 |
+
else {
|
1042 |
+
var no = indexOf(lines, line);
|
1043 |
+
if (no == -1) return null;
|
1044 |
+
}
|
1045 |
+
if (line.className != className) {
|
1046 |
+
line.className = className;
|
1047 |
+
changes.push({from: no, to: no + 1});
|
1048 |
+
}
|
1049 |
+
return line;
|
1050 |
+
}
|
1051 |
+
|
1052 |
+
function lineInfo(line) {
|
1053 |
+
if (typeof line == "number") {
|
1054 |
+
var n = line;
|
1055 |
+
line = lines[line];
|
1056 |
+
if (!line) return null;
|
1057 |
+
}
|
1058 |
+
else {
|
1059 |
+
var n = indexOf(lines, line);
|
1060 |
+
if (n == -1) return null;
|
1061 |
+
}
|
1062 |
+
var marker = line.gutterMarker;
|
1063 |
+
return {line: n, text: line.text, markerText: marker && marker.text, markerClass: marker && marker.style};
|
1064 |
+
}
|
1065 |
+
|
1066 |
+
function stringWidth(str) {
|
1067 |
+
measure.innerHTML = "<pre><span>x</span></pre>";
|
1068 |
+
measure.firstChild.firstChild.firstChild.nodeValue = str;
|
1069 |
+
return measure.firstChild.firstChild.offsetWidth || 10;
|
1070 |
+
}
|
1071 |
+
// These are used to go from pixel positions to character
|
1072 |
+
// positions, taking varying character widths into account.
|
1073 |
+
function charX(line, pos) {
|
1074 |
+
if (pos == 0) return 0;
|
1075 |
+
measure.innerHTML = "<pre><span>" + lines[line].getHTML(null, null, false, pos) + "</span></pre>";
|
1076 |
+
return measure.firstChild.firstChild.offsetWidth;
|
1077 |
+
}
|
1078 |
+
function charFromX(line, x) {
|
1079 |
+
if (x <= 0) return 0;
|
1080 |
+
var lineObj = lines[line], text = lineObj.text;
|
1081 |
+
function getX(len) {
|
1082 |
+
measure.innerHTML = "<pre><span>" + lineObj.getHTML(null, null, false, len) + "</span></pre>";
|
1083 |
+
return measure.firstChild.firstChild.offsetWidth;
|
1084 |
+
}
|
1085 |
+
var from = 0, fromX = 0, to = text.length, toX;
|
1086 |
+
// Guess a suitable upper bound for our search.
|
1087 |
+
var estimated = Math.min(to, Math.ceil(x / stringWidth("x")));
|
1088 |
+
for (;;) {
|
1089 |
+
var estX = getX(estimated);
|
1090 |
+
if (estX <= x && estimated < to) estimated = Math.min(to, Math.ceil(estimated * 1.2));
|
1091 |
+
else {toX = estX; to = estimated; break;}
|
1092 |
+
}
|
1093 |
+
if (x > toX) return to;
|
1094 |
+
// Try to guess a suitable lower bound as well.
|
1095 |
+
estimated = Math.floor(to * 0.8); estX = getX(estimated);
|
1096 |
+
if (estX < x) {from = estimated; fromX = estX;}
|
1097 |
+
// Do a binary search between these bounds.
|
1098 |
+
for (;;) {
|
1099 |
+
if (to - from <= 1) return (toX - x > x - fromX) ? from : to;
|
1100 |
+
var middle = Math.ceil((from + to) / 2), middleX = getX(middle);
|
1101 |
+
if (middleX > x) {to = middle; toX = middleX;}
|
1102 |
+
else {from = middle; fromX = middleX;}
|
1103 |
+
}
|
1104 |
+
}
|
1105 |
+
|
1106 |
+
function localCoords(pos, inLineWrap) {
|
1107 |
+
var lh = lineHeight(), line = pos.line - (inLineWrap ? showingFrom : 0);
|
1108 |
+
return {x: charX(pos.line, pos.ch), y: line * lh, yBot: (line + 1) * lh};
|
1109 |
+
}
|
1110 |
+
function pageCoords(pos) {
|
1111 |
+
var local = localCoords(pos, true), off = eltOffset(lineSpace);
|
1112 |
+
return {x: off.left + local.x, y: off.top + local.y, yBot: off.top + local.yBot};
|
1113 |
+
}
|
1114 |
+
|
1115 |
+
function lineHeight() {
|
1116 |
+
var nlines = lineDiv.childNodes.length;
|
1117 |
+
if (nlines) return (lineDiv.offsetHeight / nlines) || 1;
|
1118 |
+
measure.innerHTML = "<pre>x</pre>";
|
1119 |
+
return measure.firstChild.offsetHeight || 1;
|
1120 |
+
}
|
1121 |
+
function paddingTop() {return lineSpace.offsetTop;}
|
1122 |
+
function paddingLeft() {return lineSpace.offsetLeft;}
|
1123 |
+
|
1124 |
+
function posFromMouse(e, liberal) {
|
1125 |
+
var offW = eltOffset(scroller, true), x = e.e.clientX, y = e.e.clientY;
|
1126 |
+
// This is a mess of a heuristic to try and determine whether a
|
1127 |
+
// scroll-bar was clicked or not, and to return null if one was
|
1128 |
+
// (and !liberal).
|
1129 |
+
if (!liberal && (x - offW.left > scroller.clientWidth || y - offW.top > scroller.clientHeight))
|
1130 |
+
return null;
|
1131 |
+
var offL = eltOffset(lineSpace, true);
|
1132 |
+
var line = showingFrom + Math.floor((y - offL.top) / lineHeight());
|
1133 |
+
return clipPos({line: line, ch: charFromX(clipLine(line), x - offL.left)});
|
1134 |
+
}
|
1135 |
+
function onContextMenu(e) {
|
1136 |
+
var pos = posFromMouse(e);
|
1137 |
+
if (!pos || window.opera) return; // Opera is difficult.
|
1138 |
+
if (posEq(sel.from, sel.to) || posLess(pos, sel.from) || !posLess(pos, sel.to))
|
1139 |
+
setCursor(pos.line, pos.ch);
|
1140 |
+
|
1141 |
+
var oldCSS = input.style.cssText;
|
1142 |
+
input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.pageY() - 1) +
|
1143 |
+
"px; left: " + (e.pageX() - 1) + "px; z-index: 1000; background: white; " +
|
1144 |
+
"border-width: 0; outline: none; overflow: hidden; opacity: .05;";
|
1145 |
+
var val = input.value = getSelection();
|
1146 |
+
focusInput();
|
1147 |
+
setSelRange(input, 0, input.value.length);
|
1148 |
+
leaveInputAlone = true;
|
1149 |
+
function rehide() {
|
1150 |
+
if (input.value != val) operation(replaceSelection)(input.value, "end");
|
1151 |
+
input.style.cssText = oldCSS;
|
1152 |
+
leaveInputAlone = false;
|
1153 |
+
prepareInput();
|
1154 |
+
slowPoll();
|
1155 |
+
}
|
1156 |
+
|
1157 |
+
if (gecko) {
|
1158 |
+
e.stop()
|
1159 |
+
var mouseup = connect(window, "mouseup", function() {
|
1160 |
+
mouseup();
|
1161 |
+
setTimeout(rehide, 20);
|
1162 |
+
}, true);
|
1163 |
+
}
|
1164 |
+
else {
|
1165 |
+
setTimeout(rehide, 50);
|
1166 |
+
}
|
1167 |
+
}
|
1168 |
+
|
1169 |
+
// Cursor-blinking
|
1170 |
+
function restartBlink() {
|
1171 |
+
clearInterval(blinker);
|
1172 |
+
var on = true;
|
1173 |
+
cursor.style.visibility = "";
|
1174 |
+
blinker = setInterval(function() {
|
1175 |
+
cursor.style.visibility = (on = !on) ? "" : "hidden";
|
1176 |
+
}, 650);
|
1177 |
+
}
|
1178 |
+
|
1179 |
+
var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
|
1180 |
+
function matchBrackets(autoclear) {
|
1181 |
+
var head = sel.inverted ? sel.from : sel.to, line = lines[head.line], pos = head.ch - 1;
|
1182 |
+
var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
|
1183 |
+
if (!match) return;
|
1184 |
+
var ch = match.charAt(0), forward = match.charAt(1) == ">", d = forward ? 1 : -1, st = line.styles;
|
1185 |
+
for (var off = pos + 1, i = 0, e = st.length; i < e; i+=2)
|
1186 |
+
if ((off -= st[i].length) <= 0) {var style = st[i+1]; break;}
|
1187 |
+
|
1188 |
+
var stack = [line.text.charAt(pos)], re = /[(){}[\]]/;
|
1189 |
+
function scan(line, from, to) {
|
1190 |
+
if (!line.text) return;
|
1191 |
+
var st = line.styles, pos = forward ? 0 : line.text.length - 1, cur;
|
1192 |
+
for (var i = forward ? 0 : st.length - 2, e = forward ? st.length : -2; i != e; i += 2*d) {
|
1193 |
+
var text = st[i];
|
1194 |
+
if (st[i+1] != null && st[i+1] != style) {pos += d * text.length; continue;}
|
1195 |
+
for (var j = forward ? 0 : text.length - 1, te = forward ? text.length : -1; j != te; j += d, pos+=d) {
|
1196 |
+
if (pos >= from && pos < to && re.test(cur = text.charAt(j))) {
|
1197 |
+
var match = matching[cur];
|
1198 |
+
if (match.charAt(1) == ">" == forward) stack.push(cur);
|
1199 |
+
else if (stack.pop() != match.charAt(0)) return {pos: pos, match: false};
|
1200 |
+
else if (!stack.length) return {pos: pos, match: true};
|
1201 |
+
}
|
1202 |
+
}
|
1203 |
+
}
|
1204 |
+
}
|
1205 |
+
for (var i = head.line, e = forward ? Math.min(i + 50, lines.length) : Math.max(-1, i - 50); i != e; i+=d) {
|
1206 |
+
var line = lines[i], first = i == head.line;
|
1207 |
+
var found = scan(line, first && forward ? pos + 1 : 0, first && !forward ? pos : line.text.length);
|
1208 |
+
if (found) {
|
1209 |
+
var style = found.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
|
1210 |
+
var one = markText({line: head.line, ch: pos}, {line: head.line, ch: pos+1}, style),
|
1211 |
+
two = markText({line: i, ch: found.pos}, {line: i, ch: found.pos + 1}, style);
|
1212 |
+
var clear = operation(function(){one(); two();});
|
1213 |
+
if (autoclear) setTimeout(clear, 800);
|
1214 |
+
else bracketHighlighted = clear;
|
1215 |
+
break;
|
1216 |
+
}
|
1217 |
+
}
|
1218 |
+
}
|
1219 |
+
|
1220 |
+
// Finds the line to start with when starting a parse. Tries to
|
1221 |
+
// find a line with a stateAfter, so that it can start with a
|
1222 |
+
// valid state. If that fails, it returns the line with the
|
1223 |
+
// smallest indentation, which tends to need the least context to
|
1224 |
+
// parse correctly.
|
1225 |
+
function findStartLine(n) {
|
1226 |
+
var minindent, minline;
|
1227 |
+
for (var search = n, lim = n - 40; search > lim; --search) {
|
1228 |
+
if (search == 0) return 0;
|
1229 |
+
var line = lines[search-1];
|
1230 |
+
if (line.stateAfter) return search;
|
1231 |
+
var indented = line.indentation();
|
1232 |
+
if (minline == null || minindent > indented) {
|
1233 |
+
minline = search;
|
1234 |
+
minindent = indented;
|
1235 |
+
}
|
1236 |
+
}
|
1237 |
+
return minline;
|
1238 |
+
}
|
1239 |
+
function getStateBefore(n) {
|
1240 |
+
var start = findStartLine(n), state = start && lines[start-1].stateAfter;
|
1241 |
+
if (!state) state = startState(mode);
|
1242 |
+
else state = copyState(mode, state);
|
1243 |
+
for (var i = start; i < n; ++i) {
|
1244 |
+
var line = lines[i];
|
1245 |
+
line.highlight(mode, state);
|
1246 |
+
line.stateAfter = copyState(mode, state);
|
1247 |
+
}
|
1248 |
+
if (!lines[n].stateAfter) work.push(n);
|
1249 |
+
return state;
|
1250 |
+
}
|
1251 |
+
function highlightLines(start, end) {
|
1252 |
+
var state = getStateBefore(start);
|
1253 |
+
for (var i = start; i < end; ++i) {
|
1254 |
+
var line = lines[i];
|
1255 |
+
line.highlight(mode, state);
|
1256 |
+
line.stateAfter = copyState(mode, state);
|
1257 |
+
}
|
1258 |
+
}
|
1259 |
+
function highlightWorker() {
|
1260 |
+
var end = +new Date + options.workTime;
|
1261 |
+
var foundWork = work.length;
|
1262 |
+
while (work.length) {
|
1263 |
+
if (!lines[showingFrom].stateAfter) var task = showingFrom;
|
1264 |
+
else var task = work.pop();
|
1265 |
+
if (task >= lines.length) continue;
|
1266 |
+
var start = findStartLine(task), state = start && lines[start-1].stateAfter;
|
1267 |
+
if (state) state = copyState(mode, state);
|
1268 |
+
else state = startState(mode);
|
1269 |
+
|
1270 |
+
var unchanged = 0;
|
1271 |
+
for (var i = start, l = lines.length; i < l; ++i) {
|
1272 |
+
var line = lines[i], hadState = line.stateAfter;
|
1273 |
+
if (+new Date > end) {
|
1274 |
+
work.push(i);
|
1275 |
+
startWorker(options.workDelay);
|
1276 |
+
changes.push({from: task, to: i});
|
1277 |
+
return;
|
1278 |
+
}
|
1279 |
+
var changed = line.highlight(mode, state);
|
1280 |
+
line.stateAfter = copyState(mode, state);
|
1281 |
+
if (changed || !hadState) unchanged = 0;
|
1282 |
+
else if (++unchanged > 3) break;
|
1283 |
+
}
|
1284 |
+
changes.push({from: task, to: i});
|
1285 |
+
}
|
1286 |
+
if (foundWork && options.onHighlightComplete)
|
1287 |
+
options.onHighlightComplete(instance);
|
1288 |
+
}
|
1289 |
+
function startWorker(time) {
|
1290 |
+
if (!work.length) return;
|
1291 |
+
highlight.set(time, operation(highlightWorker));
|
1292 |
+
}
|
1293 |
+
|
1294 |
+
// Operations are used to wrap changes in such a way that each
|
1295 |
+
// change won't have to update the cursor and display (which would
|
1296 |
+
// be awkward, slow, and error-prone), but instead updates are
|
1297 |
+
// batched and then all combined and executed at once.
|
1298 |
+
function startOperation() {
|
1299 |
+
updateInput = null; changes = []; textChanged = selectionChanged = false;
|
1300 |
+
}
|
1301 |
+
function endOperation() {
|
1302 |
+
var reScroll = false;
|
1303 |
+
if (selectionChanged) reScroll = !scrollCursorIntoView();
|
1304 |
+
if (changes.length) updateDisplay(changes);
|
1305 |
+
else if (selectionChanged) updateCursor();
|
1306 |
+
if (reScroll) scrollCursorIntoView();
|
1307 |
+
if (selectionChanged) restartBlink();
|
1308 |
+
|
1309 |
+
// updateInput can be set to a boolean value to force/prevent an
|
1310 |
+
// update.
|
1311 |
+
if (!leaveInputAlone && (updateInput === true || (updateInput !== false && selectionChanged)))
|
1312 |
+
prepareInput();
|
1313 |
+
|
1314 |
+
if (selectionChanged && options.matchBrackets)
|
1315 |
+
setTimeout(operation(function() {
|
1316 |
+
if (bracketHighlighted) {bracketHighlighted(); bracketHighlighted = null;}
|
1317 |
+
matchBrackets(false);
|
1318 |
+
}), 20);
|
1319 |
+
var tc = textChanged; // textChanged can be reset by cursoractivity callback
|
1320 |
+
if (selectionChanged && options.onCursorActivity)
|
1321 |
+
options.onCursorActivity(instance);
|
1322 |
+
if (tc && options.onChange && instance)
|
1323 |
+
options.onChange(instance, tc);
|
1324 |
+
}
|
1325 |
+
var nestedOperation = 0;
|
1326 |
+
function operation(f) {
|
1327 |
+
return function() {
|
1328 |
+
if (!nestedOperation++) startOperation();
|
1329 |
+
try {var result = f.apply(this, arguments);}
|
1330 |
+
finally {if (!--nestedOperation) endOperation();}
|
1331 |
+
return result;
|
1332 |
+
};
|
1333 |
+
}
|
1334 |
+
|
1335 |
+
function SearchCursor(query, pos, caseFold) {
|
1336 |
+
this.atOccurrence = false;
|
1337 |
+
if (caseFold == null) caseFold = typeof query == "string" && query == query.toLowerCase();
|
1338 |
+
|
1339 |
+
if (pos && typeof pos == "object") pos = clipPos(pos);
|
1340 |
+
else pos = {line: 0, ch: 0};
|
1341 |
+
this.pos = {from: pos, to: pos};
|
1342 |
+
|
1343 |
+
// The matches method is filled in based on the type of query.
|
1344 |
+
// It takes a position and a direction, and returns an object
|
1345 |
+
// describing the next occurrence of the query, or null if no
|
1346 |
+
// more matches were found.
|
1347 |
+
if (typeof query != "string") // Regexp match
|
1348 |
+
this.matches = function(reverse, pos) {
|
1349 |
+
if (reverse) {
|
1350 |
+
var line = lines[pos.line].text.slice(0, pos.ch), match = line.match(query), start = 0;
|
1351 |
+
while (match) {
|
1352 |
+
var ind = line.indexOf(match[0]);
|
1353 |
+
start += ind;
|
1354 |
+
line = line.slice(ind + 1);
|
1355 |
+
var newmatch = line.match(query);
|
1356 |
+
if (newmatch) match = newmatch;
|
1357 |
+
else break;
|
1358 |
+
start++;
|
1359 |
+
}
|
1360 |
+
}
|
1361 |
+
else {
|
1362 |
+
var line = lines[pos.line].text.slice(pos.ch), match = line.match(query),
|
1363 |
+
start = match && pos.ch + line.indexOf(match[0]);
|
1364 |
+
}
|
1365 |
+
if (match)
|
1366 |
+
return {from: {line: pos.line, ch: start},
|
1367 |
+
to: {line: pos.line, ch: start + match[0].length},
|
1368 |
+
match: match};
|
1369 |
+
};
|
1370 |
+
else { // String query
|
1371 |
+
if (caseFold) query = query.toLowerCase();
|
1372 |
+
var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;};
|
1373 |
+
var target = query.split("\n");
|
1374 |
+
// Different methods for single-line and multi-line queries
|
1375 |
+
if (target.length == 1)
|
1376 |
+
this.matches = function(reverse, pos) {
|
1377 |
+
var line = fold(lines[pos.line].text), len = query.length, match;
|
1378 |
+
if (reverse ? (pos.ch >= len && (match = line.lastIndexOf(query, pos.ch - len)) != -1)
|
1379 |
+
: (match = line.indexOf(query, pos.ch)) != -1)
|
1380 |
+
return {from: {line: pos.line, ch: match},
|
1381 |
+
to: {line: pos.line, ch: match + len}};
|
1382 |
+
};
|
1383 |
+
else
|
1384 |
+
this.matches = function(reverse, pos) {
|
1385 |
+
var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(lines[ln].text);
|
1386 |
+
var offsetA = (reverse ? line.indexOf(match) + match.length : line.lastIndexOf(match));
|
1387 |
+
if (reverse ? offsetA >= pos.ch || offsetA != match.length
|
1388 |
+
: offsetA <= pos.ch || offsetA != line.length - match.length)
|
1389 |
+
return;
|
1390 |
+
for (;;) {
|
1391 |
+
if (reverse ? !ln : ln == lines.length - 1) return;
|
1392 |
+
line = fold(lines[ln += reverse ? -1 : 1].text);
|
1393 |
+
match = target[reverse ? --idx : ++idx];
|
1394 |
+
if (idx > 0 && idx < target.length - 1) {
|
1395 |
+
if (line != match) return;
|
1396 |
+
else continue;
|
1397 |
+
}
|
1398 |
+
var offsetB = (reverse ? line.lastIndexOf(match) : line.indexOf(match) + match.length);
|
1399 |
+
if (reverse ? offsetB != line.length - match.length : offsetB != match.length)
|
1400 |
+
return;
|
1401 |
+
var start = {line: pos.line, ch: offsetA}, end = {line: ln, ch: offsetB};
|
1402 |
+
return {from: reverse ? end : start, to: reverse ? start : end};
|
1403 |
+
}
|
1404 |
+
};
|
1405 |
+
}
|
1406 |
+
}
|
1407 |
+
|
1408 |
+
SearchCursor.prototype = {
|
1409 |
+
findNext: function() {return this.find(false);},
|
1410 |
+
findPrevious: function() {return this.find(true);},
|
1411 |
+
|
1412 |
+
find: function(reverse) {
|
1413 |
+
var self = this, pos = clipPos(reverse ? this.pos.from : this.pos.to);
|
1414 |
+
function savePosAndFail(line) {
|
1415 |
+
var pos = {line: line, ch: 0};
|
1416 |
+
self.pos = {from: pos, to: pos};
|
1417 |
+
self.atOccurrence = false;
|
1418 |
+
return false;
|
1419 |
+
}
|
1420 |
+
|
1421 |
+
for (;;) {
|
1422 |
+
if (this.pos = this.matches(reverse, pos)) {
|
1423 |
+
this.atOccurrence = true;
|
1424 |
+
return this.pos.match || true;
|
1425 |
+
}
|
1426 |
+
if (reverse) {
|
1427 |
+
if (!pos.line) return savePosAndFail(0);
|
1428 |
+
pos = {line: pos.line-1, ch: lines[pos.line-1].text.length};
|
1429 |
+
}
|
1430 |
+
else {
|
1431 |
+
if (pos.line == lines.length - 1) return savePosAndFail(lines.length);
|
1432 |
+
pos = {line: pos.line+1, ch: 0};
|
1433 |
+
}
|
1434 |
+
}
|
1435 |
+
},
|
1436 |
+
|
1437 |
+
from: function() {if (this.atOccurrence) return copyPos(this.pos.from);},
|
1438 |
+
to: function() {if (this.atOccurrence) return copyPos(this.pos.to);}
|
1439 |
+
};
|
1440 |
+
|
1441 |
+
for (var ext in extensions)
|
1442 |
+
if (extensions.propertyIsEnumerable(ext) &&
|
1443 |
+
!instance.propertyIsEnumerable(ext))
|
1444 |
+
instance[ext] = extensions[ext];
|
1445 |
+
return instance;
|
1446 |
+
} // (end of function CodeMirror)
|
1447 |
+
|
1448 |
+
// The default configuration options.
|
1449 |
+
CodeMirror.defaults = {
|
1450 |
+
value: "",
|
1451 |
+
mode: null,
|
1452 |
+
theme: "default",
|
1453 |
+
indentUnit: 2,
|
1454 |
+
indentWithTabs: false,
|
1455 |
+
tabMode: "classic",
|
1456 |
+
enterMode: "indent",
|
1457 |
+
electricChars: true,
|
1458 |
+
onKeyEvent: null,
|
1459 |
+
lineNumbers: false,
|
1460 |
+
gutter: false,
|
1461 |
+
firstLineNumber: 1,
|
1462 |
+
readOnly: false,
|
1463 |
+
onChange: null,
|
1464 |
+
onCursorActivity: null,
|
1465 |
+
onGutterClick: null,
|
1466 |
+
onHighlightComplete: null,
|
1467 |
+
onFocus: null, onBlur: null, onScroll: null,
|
1468 |
+
matchBrackets: false,
|
1469 |
+
workTime: 100,
|
1470 |
+
workDelay: 200,
|
1471 |
+
undoDepth: 40,
|
1472 |
+
tabindex: null,
|
1473 |
+
document: window.document
|
1474 |
+
};
|
1475 |
+
|
1476 |
+
// Known modes, by name and by MIME
|
1477 |
+
var modes = {}, mimeModes = {};
|
1478 |
+
CodeMirror.defineMode = function(name, mode) {
|
1479 |
+
if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
|
1480 |
+
modes[name] = mode;
|
1481 |
+
};
|
1482 |
+
CodeMirror.defineMIME = function(mime, spec) {
|
1483 |
+
mimeModes[mime] = spec;
|
1484 |
+
};
|
1485 |
+
CodeMirror.getMode = function(options, spec) {
|
1486 |
+
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
|
1487 |
+
spec = mimeModes[spec];
|
1488 |
+
if (typeof spec == "string")
|
1489 |
+
var mname = spec, config = {};
|
1490 |
+
else if (spec != null)
|
1491 |
+
var mname = spec.name, config = spec;
|
1492 |
+
var mfactory = modes[mname];
|
1493 |
+
if (!mfactory) {
|
1494 |
+
if (window.console) console.warn("No mode " + mname + " found, falling back to plain text.");
|
1495 |
+
return CodeMirror.getMode(options, "text/plain");
|
1496 |
+
}
|
1497 |
+
return mfactory(options, config || {});
|
1498 |
+
}
|
1499 |
+
CodeMirror.listModes = function() {
|
1500 |
+
var list = [];
|
1501 |
+
for (var m in modes)
|
1502 |
+
if (modes.propertyIsEnumerable(m)) list.push(m);
|
1503 |
+
return list;
|
1504 |
+
};
|
1505 |
+
CodeMirror.listMIMEs = function() {
|
1506 |
+
var list = [];
|
1507 |
+
for (var m in mimeModes)
|
1508 |
+
if (mimeModes.propertyIsEnumerable(m)) list.push(m);
|
1509 |
+
return list;
|
1510 |
+
};
|
1511 |
+
|
1512 |
+
var extensions = {};
|
1513 |
+
CodeMirror.defineExtension = function(name, func) {
|
1514 |
+
extensions[name] = func;
|
1515 |
+
};
|
1516 |
+
|
1517 |
+
CodeMirror.fromTextArea = function(textarea, options) {
|
1518 |
+
if (!options) options = {};
|
1519 |
+
options.value = textarea.value;
|
1520 |
+
if (!options.tabindex && textarea.tabindex)
|
1521 |
+
options.tabindex = textarea.tabindex;
|
1522 |
+
|
1523 |
+
function save() {textarea.value = instance.getValue();}
|
1524 |
+
if (textarea.form) {
|
1525 |
+
// Deplorable hack to make the submit method do the right thing.
|
1526 |
+
var rmSubmit = connect(textarea.form, "submit", save, true);
|
1527 |
+
if (typeof textarea.form.submit == "function") {
|
1528 |
+
var realSubmit = textarea.form.submit;
|
1529 |
+
function wrappedSubmit() {
|
1530 |
+
save();
|
1531 |
+
textarea.form.submit = realSubmit;
|
1532 |
+
textarea.form.submit();
|
1533 |
+
textarea.form.submit = wrappedSubmit;
|
1534 |
+
}
|
1535 |
+
textarea.form.submit = wrappedSubmit;
|
1536 |
+
}
|
1537 |
+
}
|
1538 |
+
|
1539 |
+
textarea.style.display = "none";
|
1540 |
+
var instance = CodeMirror(function(node) {
|
1541 |
+
textarea.parentNode.insertBefore(node, textarea.nextSibling);
|
1542 |
+
}, options);
|
1543 |
+
instance.save = save;
|
1544 |
+
instance.toTextArea = function() {
|
1545 |
+
save();
|
1546 |
+
textarea.parentNode.removeChild(instance.getWrapperElement());
|
1547 |
+
textarea.style.display = "";
|
1548 |
+
if (textarea.form) {
|
1549 |
+
rmSubmit();
|
1550 |
+
if (typeof textarea.form.submit == "function")
|
1551 |
+
textarea.form.submit = realSubmit;
|
1552 |
+
}
|
1553 |
+
};
|
1554 |
+
return instance;
|
1555 |
+
};
|
1556 |
+
|
1557 |
+
// Utility functions for working with state. Exported because modes
|
1558 |
+
// sometimes need to do this.
|
1559 |
+
function copyState(mode, state) {
|
1560 |
+
if (state === true) return state;
|
1561 |
+
if (mode.copyState) return mode.copyState(state);
|
1562 |
+
var nstate = {};
|
1563 |
+
for (var n in state) {
|
1564 |
+
var val = state[n];
|
1565 |
+
if (val instanceof Array) val = val.concat([]);
|
1566 |
+
nstate[n] = val;
|
1567 |
+
}
|
1568 |
+
return nstate;
|
1569 |
+
}
|
1570 |
+
CodeMirror.startState = startState;
|
1571 |
+
function startState(mode, a1, a2) {
|
1572 |
+
return mode.startState ? mode.startState(a1, a2) : true;
|
1573 |
+
}
|
1574 |
+
CodeMirror.copyState = copyState;
|
1575 |
+
|
1576 |
+
// The character stream used by a mode's parser.
|
1577 |
+
function StringStream(string) {
|
1578 |
+
this.pos = this.start = 0;
|
1579 |
+
this.string = string;
|
1580 |
+
}
|
1581 |
+
StringStream.prototype = {
|
1582 |
+
eol: function() {return this.pos >= this.string.length;},
|
1583 |
+
sol: function() {return this.pos == 0;},
|
1584 |
+
peek: function() {return this.string.charAt(this.pos);},
|
1585 |
+
next: function() {
|
1586 |
+
if (this.pos < this.string.length)
|
1587 |
+
return this.string.charAt(this.pos++);
|
1588 |
+
},
|
1589 |
+
eat: function(match) {
|
1590 |
+
var ch = this.string.charAt(this.pos);
|
1591 |
+
if (typeof match == "string") var ok = ch == match;
|
1592 |
+
else var ok = ch && (match.test ? match.test(ch) : match(ch));
|
1593 |
+
if (ok) {++this.pos; return ch;}
|
1594 |
+
},
|
1595 |
+
eatWhile: function(match) {
|
1596 |
+
var start = this.start;
|
1597 |
+
while (this.eat(match)){}
|
1598 |
+
return this.pos > start;
|
1599 |
+
},
|
1600 |
+
eatSpace: function() {
|
1601 |
+
var start = this.pos;
|
1602 |
+
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
|
1603 |
+
return this.pos > start;
|
1604 |
+
},
|
1605 |
+
skipToEnd: function() {this.pos = this.string.length;},
|
1606 |
+
skipTo: function(ch) {
|
1607 |
+
var found = this.string.indexOf(ch, this.pos);
|
1608 |
+
if (found > -1) {this.pos = found; return true;}
|
1609 |
+
},
|
1610 |
+
backUp: function(n) {this.pos -= n;},
|
1611 |
+
column: function() {return countColumn(this.string, this.start);},
|
1612 |
+
indentation: function() {return countColumn(this.string);},
|
1613 |
+
match: function(pattern, consume, caseInsensitive) {
|
1614 |
+
if (typeof pattern == "string") {
|
1615 |
+
function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
|
1616 |
+
if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
|
1617 |
+
if (consume !== false) this.pos += pattern.length;
|
1618 |
+
return true;
|
1619 |
+
}
|
1620 |
+
}
|
1621 |
+
else {
|
1622 |
+
var match = this.string.slice(this.pos).match(pattern);
|
1623 |
+
if (match && consume !== false) this.pos += match[0].length;
|
1624 |
+
return match;
|
1625 |
+
}
|
1626 |
+
},
|
1627 |
+
current: function(){return this.string.slice(this.start, this.pos);}
|
1628 |
+
};
|
1629 |
+
CodeMirror.StringStream = StringStream;
|
1630 |
+
|
1631 |
+
// Line objects. These hold state related to a line, including
|
1632 |
+
// highlighting info (the styles array).
|
1633 |
+
function Line(text, styles) {
|
1634 |
+
this.styles = styles || [text, null];
|
1635 |
+
this.stateAfter = null;
|
1636 |
+
this.text = text;
|
1637 |
+
this.marked = this.gutterMarker = this.className = null;
|
1638 |
+
}
|
1639 |
+
Line.prototype = {
|
1640 |
+
// Replace a piece of a line, keeping the styles around it intact.
|
1641 |
+
replace: function(from, to, text) {
|
1642 |
+
var st = [], mk = this.marked;
|
1643 |
+
copyStyles(0, from, this.styles, st);
|
1644 |
+
if (text) st.push(text, null);
|
1645 |
+
copyStyles(to, this.text.length, this.styles, st);
|
1646 |
+
this.styles = st;
|
1647 |
+
this.text = this.text.slice(0, from) + text + this.text.slice(to);
|
1648 |
+
this.stateAfter = null;
|
1649 |
+
if (mk) {
|
1650 |
+
var diff = text.length - (to - from), end = this.text.length;
|
1651 |
+
function fix(n) {return n <= Math.min(to, to + diff) ? n : n + diff;}
|
1652 |
+
for (var i = 0; i < mk.length; ++i) {
|
1653 |
+
var mark = mk[i], del = false;
|
1654 |
+
if (mark.from >= end) del = true;
|
1655 |
+
else {mark.from = fix(mark.from); if (mark.to != null) mark.to = fix(mark.to);}
|
1656 |
+
if (del || mark.from >= mark.to) {mk.splice(i, 1); i--;}
|
1657 |
+
}
|
1658 |
+
}
|
1659 |
+
},
|
1660 |
+
// Split a line in two, again keeping styles intact.
|
1661 |
+
split: function(pos, textBefore) {
|
1662 |
+
var st = [textBefore, null];
|
1663 |
+
copyStyles(pos, this.text.length, this.styles, st);
|
1664 |
+
return new Line(textBefore + this.text.slice(pos), st);
|
1665 |
+
},
|
1666 |
+
addMark: function(from, to, style) {
|
1667 |
+
var mk = this.marked, mark = {from: from, to: to, style: style};
|
1668 |
+
if (this.marked == null) this.marked = [];
|
1669 |
+
this.marked.push(mark);
|
1670 |
+
this.marked.sort(function(a, b){return a.from - b.from;});
|
1671 |
+
return mark;
|
1672 |
+
},
|
1673 |
+
removeMark: function(mark) {
|
1674 |
+
var mk = this.marked;
|
1675 |
+
if (!mk) return;
|
1676 |
+
for (var i = 0; i < mk.length; ++i)
|
1677 |
+
if (mk[i] == mark) {mk.splice(i, 1); break;}
|
1678 |
+
},
|
1679 |
+
// Run the given mode's parser over a line, update the styles
|
1680 |
+
// array, which contains alternating fragments of text and CSS
|
1681 |
+
// classes.
|
1682 |
+
highlight: function(mode, state) {
|
1683 |
+
var stream = new StringStream(this.text), st = this.styles, pos = 0;
|
1684 |
+
var changed = false, curWord = st[0], prevWord;
|
1685 |
+
if (this.text == "" && mode.blankLine) mode.blankLine(state);
|
1686 |
+
while (!stream.eol()) {
|
1687 |
+
var style = mode.token(stream, state);
|
1688 |
+
var substr = this.text.slice(stream.start, stream.pos);
|
1689 |
+
stream.start = stream.pos;
|
1690 |
+
if (pos && st[pos-1] == style)
|
1691 |
+
st[pos-2] += substr;
|
1692 |
+
else if (substr) {
|
1693 |
+
if (!changed && (st[pos+1] != style || (pos && st[pos-2] != prevWord))) changed = true;
|
1694 |
+
st[pos++] = substr; st[pos++] = style;
|
1695 |
+
prevWord = curWord; curWord = st[pos];
|
1696 |
+
}
|
1697 |
+
// Give up when line is ridiculously long
|
1698 |
+
if (stream.pos > 5000) {
|
1699 |
+
st[pos++] = this.text.slice(stream.pos); st[pos++] = null;
|
1700 |
+
break;
|
1701 |
+
}
|
1702 |
+
}
|
1703 |
+
if (st.length != pos) {st.length = pos; changed = true;}
|
1704 |
+
if (pos && st[pos-2] != prevWord) changed = true;
|
1705 |
+
// Short lines with simple highlights always count as changed,
|
1706 |
+
// because they are likely to highlight the same way in various
|
1707 |
+
// contexts.
|
1708 |
+
return changed || (st.length < 5 && this.text.length < 10);
|
1709 |
+
},
|
1710 |
+
// Fetch the parser token for a given character. Useful for hacks
|
1711 |
+
// that want to inspect the mode state (say, for completion).
|
1712 |
+
getTokenAt: function(mode, state, ch) {
|
1713 |
+
var txt = this.text, stream = new StringStream(txt);
|
1714 |
+
while (stream.pos < ch && !stream.eol()) {
|
1715 |
+
stream.start = stream.pos;
|
1716 |
+
var style = mode.token(stream, state);
|
1717 |
+
}
|
1718 |
+
return {start: stream.start,
|
1719 |
+
end: stream.pos,
|
1720 |
+
string: stream.current(),
|
1721 |
+
className: style || null,
|
1722 |
+
state: state};
|
1723 |
+
},
|
1724 |
+
indentation: function() {return countColumn(this.text);},
|
1725 |
+
// Produces an HTML fragment for the line, taking selection,
|
1726 |
+
// marking, and highlighting into account.
|
1727 |
+
getHTML: function(sfrom, sto, includePre, endAt) {
|
1728 |
+
var html = [];
|
1729 |
+
if (includePre)
|
1730 |
+
html.push(this.className ? '<pre class="' + this.className + '">': "<pre>");
|
1731 |
+
function span(text, style) {
|
1732 |
+
if (!text) return;
|
1733 |
+
if (style) html.push('<span class="cm-', style, '">', htmlEscape(text), "</span>");
|
1734 |
+
else html.push(htmlEscape(text));
|
1735 |
+
}
|
1736 |
+
var st = this.styles, allText = this.text, marked = this.marked;
|
1737 |
+
if (sfrom == sto) sfrom = null;
|
1738 |
+
var len = allText.length;
|
1739 |
+
if (endAt != null) len = Math.min(endAt, len);
|
1740 |
+
|
1741 |
+
if (!allText && endAt == null)
|
1742 |
+
span(" ", sfrom != null && sto == null ? "CodeMirror-selected" : null);
|
1743 |
+
else if (!marked && sfrom == null)
|
1744 |
+
for (var i = 0, ch = 0; ch < len; i+=2) {
|
1745 |
+
var str = st[i], l = str.length;
|
1746 |
+
if (ch + l > len) str = str.slice(0, len - ch);
|
1747 |
+
ch += l;
|
1748 |
+
span(str, st[i+1]);
|
1749 |
+
}
|
1750 |
+
else {
|
1751 |
+
var pos = 0, i = 0, text = "", style, sg = 0;
|
1752 |
+
var markpos = -1, mark = null;
|
1753 |
+
function nextMark() {
|
1754 |
+
if (marked) {
|
1755 |
+
markpos += 1;
|
1756 |
+
mark = (markpos < marked.length) ? marked[markpos] : null;
|
1757 |
+
}
|
1758 |
+
}
|
1759 |
+
nextMark();
|
1760 |
+
while (pos < len) {
|
1761 |
+
var upto = len;
|
1762 |
+
var extraStyle = "";
|
1763 |
+
if (sfrom != null) {
|
1764 |
+
if (sfrom > pos) upto = sfrom;
|
1765 |
+
else if (sto == null || sto > pos) {
|
1766 |
+
extraStyle = " CodeMirror-selected";
|
1767 |
+
if (sto != null) upto = Math.min(upto, sto);
|
1768 |
+
}
|
1769 |
+
}
|
1770 |
+
while (mark && mark.to != null && mark.to <= pos) nextMark();
|
1771 |
+
if (mark) {
|
1772 |
+
if (mark.from > pos) upto = Math.min(upto, mark.from);
|
1773 |
+
else {
|
1774 |
+
extraStyle += " " + mark.style;
|
1775 |
+
if (mark.to != null) upto = Math.min(upto, mark.to);
|
1776 |
+
}
|
1777 |
+
}
|
1778 |
+
for (;;) {
|
1779 |
+
var end = pos + text.length;
|
1780 |
+
var apliedStyle = style;
|
1781 |
+
if (extraStyle) apliedStyle = style ? style + extraStyle : extraStyle;
|
1782 |
+
span(end > upto ? text.slice(0, upto - pos) : text, apliedStyle);
|
1783 |
+
if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
|
1784 |
+
pos = end;
|
1785 |
+
text = st[i++]; style = st[i++];
|
1786 |
+
}
|
1787 |
+
}
|
1788 |
+
if (sfrom != null && sto == null) span(" ", "CodeMirror-selected");
|
1789 |
+
}
|
1790 |
+
if (includePre) html.push("</pre>");
|
1791 |
+
return html.join("");
|
1792 |
+
}
|
1793 |
+
};
|
1794 |
+
// Utility used by replace and split above
|
1795 |
+
function copyStyles(from, to, source, dest) {
|
1796 |
+
for (var i = 0, pos = 0, state = 0; pos < to; i+=2) {
|
1797 |
+
var part = source[i], end = pos + part.length;
|
1798 |
+
if (state == 0) {
|
1799 |
+
if (end > from) dest.push(part.slice(from - pos, Math.min(part.length, to - pos)), source[i+1]);
|
1800 |
+
if (end >= from) state = 1;
|
1801 |
+
}
|
1802 |
+
else if (state == 1) {
|
1803 |
+
if (end > to) dest.push(part.slice(0, to - pos), source[i+1]);
|
1804 |
+
else dest.push(part, source[i+1]);
|
1805 |
+
}
|
1806 |
+
pos = end;
|
1807 |
+
}
|
1808 |
+
}
|
1809 |
+
|
1810 |
+
// The history object 'chunks' changes that are made close together
|
1811 |
+
// and at almost the same time into bigger undoable units.
|
1812 |
+
function History() {
|
1813 |
+
this.time = 0;
|
1814 |
+
this.done = []; this.undone = [];
|
1815 |
+
}
|
1816 |
+
History.prototype = {
|
1817 |
+
addChange: function(start, added, old) {
|
1818 |
+
this.undone.length = 0;
|
1819 |
+
var time = +new Date, last = this.done[this.done.length - 1];
|
1820 |
+
if (time - this.time > 400 || !last ||
|
1821 |
+
last.start > start + added || last.start + last.added < start - last.added + last.old.length)
|
1822 |
+
this.done.push({start: start, added: added, old: old});
|
1823 |
+
else {
|
1824 |
+
var oldoff = 0;
|
1825 |
+
if (start < last.start) {
|
1826 |
+
for (var i = last.start - start - 1; i >= 0; --i)
|
1827 |
+
last.old.unshift(old[i]);
|
1828 |
+
last.added += last.start - start;
|
1829 |
+
last.start = start;
|
1830 |
+
}
|
1831 |
+
else if (last.start < start) {
|
1832 |
+
oldoff = start - last.start;
|
1833 |
+
added += oldoff;
|
1834 |
+
}
|
1835 |
+
for (var i = last.added - oldoff, e = old.length; i < e; ++i)
|
1836 |
+
last.old.push(old[i]);
|
1837 |
+
if (last.added < added) last.added = added;
|
1838 |
+
}
|
1839 |
+
this.time = time;
|
1840 |
+
}
|
1841 |
+
};
|
1842 |
+
|
1843 |
+
// Event stopping compatibility wrapper.
|
1844 |
+
function stopEvent() {
|
1845 |
+
if (this.preventDefault) {this.preventDefault(); this.stopPropagation();}
|
1846 |
+
else {this.returnValue = false; this.cancelBubble = true;}
|
1847 |
+
}
|
1848 |
+
// Ensure an event has a stop method.
|
1849 |
+
function addStop(event) {
|
1850 |
+
if (!event.stop) event.stop = stopEvent;
|
1851 |
+
return event;
|
1852 |
+
}
|
1853 |
+
|
1854 |
+
// Event wrapper, exposing the few operations we need.
|
1855 |
+
function Event(orig) {this.e = orig;}
|
1856 |
+
Event.prototype = {
|
1857 |
+
stop: function() {stopEvent.call(this.e);},
|
1858 |
+
target: function() {return this.e.target || this.e.srcElement;},
|
1859 |
+
button: function() {
|
1860 |
+
if (this.e.which) return this.e.which;
|
1861 |
+
else if (this.e.button & 1) return 1;
|
1862 |
+
else if (this.e.button & 2) return 3;
|
1863 |
+
else if (this.e.button & 4) return 2;
|
1864 |
+
},
|
1865 |
+
pageX: function() {
|
1866 |
+
if (this.e.pageX != null) return this.e.pageX;
|
1867 |
+
var doc = this.target().ownerDocument;
|
1868 |
+
return this.e.clientX + doc.body.scrollLeft + doc.documentElement.scrollLeft;
|
1869 |
+
},
|
1870 |
+
pageY: function() {
|
1871 |
+
if (this.e.pageY != null) return this.e.pageY;
|
1872 |
+
var doc = this.target().ownerDocument;
|
1873 |
+
return this.e.clientY + doc.body.scrollTop + doc.documentElement.scrollTop;
|
1874 |
+
}
|
1875 |
+
};
|
1876 |
+
|
1877 |
+
// Event handler registration. If disconnect is true, it'll return a
|
1878 |
+
// function that unregisters the handler.
|
1879 |
+
function connect(node, type, handler, disconnect) {
|
1880 |
+
function wrapHandler(event) {handler(new Event(event || window.event));}
|
1881 |
+
if (typeof node.addEventListener == "function") {
|
1882 |
+
node.addEventListener(type, wrapHandler, false);
|
1883 |
+
if (disconnect) return function() {node.removeEventListener(type, wrapHandler, false);};
|
1884 |
+
}
|
1885 |
+
else {
|
1886 |
+
node.attachEvent("on" + type, wrapHandler);
|
1887 |
+
if (disconnect) return function() {node.detachEvent("on" + type, wrapHandler);};
|
1888 |
+
}
|
1889 |
+
}
|
1890 |
+
|
1891 |
+
function Delayed() {this.id = null;}
|
1892 |
+
Delayed.prototype = {set: function(ms, f) {clearTimeout(this.id); this.id = setTimeout(f, ms);}};
|
1893 |
+
|
1894 |
+
// Some IE versions don't preserve whitespace when setting the
|
1895 |
+
// innerHTML of a PRE tag.
|
1896 |
+
var badInnerHTML = (function() {
|
1897 |
+
var pre = document.createElement("pre");
|
1898 |
+
pre.innerHTML = " "; return !pre.innerHTML;
|
1899 |
+
})();
|
1900 |
+
|
1901 |
+
var gecko = /gecko\/\d{7}/i.test(navigator.userAgent);
|
1902 |
+
var ie = /MSIE \d/.test(navigator.userAgent);
|
1903 |
+
var safari = /Apple Computer/.test(navigator.vendor);
|
1904 |
+
|
1905 |
+
var lineSep = "\n";
|
1906 |
+
// Feature-detect whether newlines in textareas are converted to \r\n
|
1907 |
+
(function () {
|
1908 |
+
var te = document.createElement("textarea");
|
1909 |
+
te.value = "foo\nbar";
|
1910 |
+
if (te.value.indexOf("\r") > -1) lineSep = "\r\n";
|
1911 |
+
}());
|
1912 |
+
|
1913 |
+
var tabSize = 8;
|
1914 |
+
var mac = /Mac/.test(navigator.platform);
|
1915 |
+
var movementKeys = {};
|
1916 |
+
for (var i = 35; i <= 40; ++i)
|
1917 |
+
movementKeys[i] = movementKeys["c" + i] = true;
|
1918 |
+
|
1919 |
+
// Counts the column offset in a string, taking tabs into account.
|
1920 |
+
// Used mostly to find indentation.
|
1921 |
+
function countColumn(string, end) {
|
1922 |
+
if (end == null) {
|
1923 |
+
end = string.search(/[^\s\u00a0]/);
|
1924 |
+
if (end == -1) end = string.length;
|
1925 |
+
}
|
1926 |
+
for (var i = 0, n = 0; i < end; ++i) {
|
1927 |
+
if (string.charAt(i) == "\t") n += tabSize - (n % tabSize);
|
1928 |
+
else ++n;
|
1929 |
+
}
|
1930 |
+
return n;
|
1931 |
+
}
|
1932 |
+
|
1933 |
+
// Find the position of an element by following the offsetParent chain.
|
1934 |
+
// If screen==true, it returns screen (rather than page) coordinates.
|
1935 |
+
function eltOffset(node, screen) {
|
1936 |
+
var doc = node.ownerDocument.body;
|
1937 |
+
var x = 0, y = 0, hitDoc = false;
|
1938 |
+
for (var n = node; n; n = n.offsetParent) {
|
1939 |
+
x += n.offsetLeft; y += n.offsetTop;
|
1940 |
+
// Fixed-position elements don't have the document in their offset chain
|
1941 |
+
if (n == doc) hitDoc = true;
|
1942 |
+
}
|
1943 |
+
var e = screen && hitDoc ? null : doc;
|
1944 |
+
for (var n = node.parentNode; n != e; n = n.parentNode)
|
1945 |
+
if (n.scrollLeft != null) { x -= n.scrollLeft; y -= n.scrollTop;}
|
1946 |
+
return {left: x, top: y};
|
1947 |
+
}
|
1948 |
+
// Get a node's text content.
|
1949 |
+
function eltText(node) {
|
1950 |
+
return node.textContent || node.innerText || node.nodeValue || "";
|
1951 |
+
}
|
1952 |
+
|
1953 |
+
// Operations on {line, ch} objects.
|
1954 |
+
function posEq(a, b) {return a.line == b.line && a.ch == b.ch;}
|
1955 |
+
function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);}
|
1956 |
+
function copyPos(x) {return {line: x.line, ch: x.ch};}
|
1957 |
+
|
1958 |
+
function htmlEscape(str) {
|
1959 |
+
return str.replace(/[<>&]/g, function(str) {
|
1960 |
+
return str == "&" ? "&" : str == "<" ? "<" : ">";
|
1961 |
+
});
|
1962 |
+
}
|
1963 |
+
CodeMirror.htmlEscape = htmlEscape;
|
1964 |
+
|
1965 |
+
// Used to position the cursor after an undo/redo by finding the
|
1966 |
+
// last edited character.
|
1967 |
+
function editEnd(from, to) {
|
1968 |
+
if (!to) return from ? from.length : 0;
|
1969 |
+
if (!from) return to.length;
|
1970 |
+
for (var i = from.length, j = to.length; i >= 0 && j >= 0; --i, --j)
|
1971 |
+
if (from.charAt(i) != to.charAt(j)) break;
|
1972 |
+
return j + 1;
|
1973 |
+
}
|
1974 |
+
|
1975 |
+
function indexOf(collection, elt) {
|
1976 |
+
if (collection.indexOf) return collection.indexOf(elt);
|
1977 |
+
for (var i = 0, e = collection.length; i < e; ++i)
|
1978 |
+
if (collection[i] == elt) return i;
|
1979 |
+
return -1;
|
1980 |
+
}
|
1981 |
+
|
1982 |
+
// See if "".split is the broken IE version, if so, provide an
|
1983 |
+
// alternative way to split lines.
|
1984 |
+
if ("\n\nb".split(/\n/).length != 3)
|
1985 |
+
var splitLines = function(string) {
|
1986 |
+
var pos = 0, nl, result = [];
|
1987 |
+
while ((nl = string.indexOf("\n", pos)) > -1) {
|
1988 |
+
result.push(string.slice(pos, string.charAt(nl-1) == "\r" ? nl - 1 : nl));
|
1989 |
+
pos = nl + 1;
|
1990 |
+
}
|
1991 |
+
result.push(string.slice(pos));
|
1992 |
+
return result;
|
1993 |
+
};
|
1994 |
+
else
|
1995 |
+
var splitLines = function(string){return string.split(/\r?\n/);};
|
1996 |
+
CodeMirror.splitLines = splitLines;
|
1997 |
+
|
1998 |
+
// Sane model of finding and setting the selection in a textarea
|
1999 |
+
if (window.getSelection) {
|
2000 |
+
var selRange = function(te) {
|
2001 |
+
try {return {start: te.selectionStart, end: te.selectionEnd};}
|
2002 |
+
catch(e) {return null;}
|
2003 |
+
};
|
2004 |
+
if (safari)
|
2005 |
+
// On Safari, selection set with setSelectionRange are in a sort
|
2006 |
+
// of limbo wrt their anchor. If you press shift-left in them,
|
2007 |
+
// the anchor is put at the end, and the selection expanded to
|
2008 |
+
// the left. If you press shift-right, the anchor ends up at the
|
2009 |
+
// front. This is not what CodeMirror wants, so it does a
|
2010 |
+
// spurious modify() call to get out of limbo.
|
2011 |
+
var setSelRange = function(te, start, end) {
|
2012 |
+
if (start == end)
|
2013 |
+
te.setSelectionRange(start, end);
|
2014 |
+
else {
|
2015 |
+
te.setSelectionRange(start, end - 1);
|
2016 |
+
window.getSelection().modify("extend", "forward", "character");
|
2017 |
+
}
|
2018 |
+
};
|
2019 |
+
else
|
2020 |
+
var setSelRange = function(te, start, end) {
|
2021 |
+
try {te.setSelectionRange(start, end);}
|
2022 |
+
catch(e) {} // Fails on Firefox when textarea isn't part of the document
|
2023 |
+
};
|
2024 |
+
}
|
2025 |
+
// IE model. Don't ask.
|
2026 |
+
else {
|
2027 |
+
var selRange = function(te) {
|
2028 |
+
try {var range = te.ownerDocument.selection.createRange();}
|
2029 |
+
catch(e) {return null;}
|
2030 |
+
if (!range || range.parentElement() != te) return null;
|
2031 |
+
var val = te.value, len = val.length, localRange = te.createTextRange();
|
2032 |
+
localRange.moveToBookmark(range.getBookmark());
|
2033 |
+
var endRange = te.createTextRange();
|
2034 |
+
endRange.collapse(false);
|
2035 |
+
|
2036 |
+
if (localRange.compareEndPoints("StartToEnd", endRange) > -1)
|
2037 |
+
return {start: len, end: len};
|
2038 |
+
|
2039 |
+
var start = -localRange.moveStart("character", -len);
|
2040 |
+
for (var i = val.indexOf("\r"); i > -1 && i < start; i = val.indexOf("\r", i+1), start++) {}
|
2041 |
+
|
2042 |
+
if (localRange.compareEndPoints("EndToEnd", endRange) > -1)
|
2043 |
+
return {start: start, end: len};
|
2044 |
+
|
2045 |
+
var end = -localRange.moveEnd("character", -len);
|
2046 |
+
for (var i = val.indexOf("\r"); i > -1 && i < end; i = val.indexOf("\r", i+1), end++) {}
|
2047 |
+
return {start: start, end: end};
|
2048 |
+
};
|
2049 |
+
var setSelRange = function(te, start, end) {
|
2050 |
+
var range = te.createTextRange();
|
2051 |
+
range.collapse(true);
|
2052 |
+
var endrange = range.duplicate();
|
2053 |
+
var newlines = 0, txt = te.value;
|
2054 |
+
for (var pos = txt.indexOf("\n"); pos > -1 && pos < start; pos = txt.indexOf("\n", pos + 1))
|
2055 |
+
++newlines;
|
2056 |
+
range.move("character", start - newlines);
|
2057 |
+
for (; pos > -1 && pos < end; pos = txt.indexOf("\n", pos + 1))
|
2058 |
+
++newlines;
|
2059 |
+
endrange.move("character", end - newlines);
|
2060 |
+
range.setEndPoint("EndToEnd", endrange);
|
2061 |
+
range.select();
|
2062 |
+
};
|
2063 |
+
}
|
2064 |
+
|
2065 |
+
CodeMirror.defineMode("null", function() {
|
2066 |
+
return {token: function(stream) {stream.skipToEnd();}};
|
2067 |
+
});
|
2068 |
+
CodeMirror.defineMIME("text/plain", "null");
|
2069 |
+
|
2070 |
+
return CodeMirror;
|
2071 |
+
})();
|
libraries/codemirror/lib/overlay.js
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Utility function that allows modes to be combined. The mode given
|
2 |
+
// as the base argument takes care of most of the normal mode
|
3 |
+
// functionality, but a second (typically simple) mode is used, which
|
4 |
+
// can override the style of text. Both modes get to parse all of the
|
5 |
+
// text, but when both assign a non-null style to a piece of code, the
|
6 |
+
// overlay wins, unless the combine argument was true, in which case
|
7 |
+
// the styles are combined.
|
8 |
+
|
9 |
+
CodeMirror.overlayParser = function(base, overlay, combine) {
|
10 |
+
return {
|
11 |
+
startState: function() {
|
12 |
+
return {
|
13 |
+
base: CodeMirror.startState(base),
|
14 |
+
overlay: CodeMirror.startState(overlay),
|
15 |
+
basePos: 0, baseCur: null,
|
16 |
+
overlayPos: 0, overlayCur: null
|
17 |
+
};
|
18 |
+
},
|
19 |
+
copyState: function(state) {
|
20 |
+
return {
|
21 |
+
base: CodeMirror.copyState(base, state.base),
|
22 |
+
overlay: CodeMirror.copyState(overlay, state.overlay),
|
23 |
+
basePos: state.basePos, baseCur: null,
|
24 |
+
overlayPos: state.overlayPos, overlayCur: null
|
25 |
+
};
|
26 |
+
},
|
27 |
+
|
28 |
+
token: function(stream, state) {
|
29 |
+
if (stream.start == state.basePos) {
|
30 |
+
state.baseCur = base.token(stream, state.base);
|
31 |
+
state.basePos = stream.pos;
|
32 |
+
}
|
33 |
+
if (stream.start == state.overlayPos) {
|
34 |
+
stream.pos = stream.start;
|
35 |
+
state.overlayCur = overlay.token(stream, state.overlay);
|
36 |
+
state.overlayPos = stream.pos;
|
37 |
+
}
|
38 |
+
stream.pos = Math.min(state.basePos, state.overlayPos);
|
39 |
+
if (stream.eol()) state.basePos = state.overlayPos = 0;
|
40 |
+
|
41 |
+
if (state.overlayCur == null) return state.baseCur;
|
42 |
+
if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur;
|
43 |
+
else return state.overlayCur;
|
44 |
+
},
|
45 |
+
|
46 |
+
indent: function(state, textAfter) {
|
47 |
+
return base.indent(state.base, textAfter);
|
48 |
+
},
|
49 |
+
electricChars: base.electricChars
|
50 |
+
};
|
51 |
+
};
|
libraries/codemirror/lib/runmode.js
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CodeMirror.runMode = function(string, modespec, callback) {
|
2 |
+
var mode = CodeMirror.getMode({indentUnit: 2}, modespec);
|
3 |
+
var isNode = callback.nodeType == 1;
|
4 |
+
if (isNode) {
|
5 |
+
var node = callback, accum = [];
|
6 |
+
callback = function(string, style) {
|
7 |
+
if (string == "\n")
|
8 |
+
accum.push("<br>");
|
9 |
+
else if (style)
|
10 |
+
accum.push("<span class=\"cm-" + CodeMirror.htmlEscape(style) + "\">" + CodeMirror.htmlEscape(string) + "</span>");
|
11 |
+
else
|
12 |
+
accum.push(CodeMirror.htmlEscape(string));
|
13 |
+
}
|
14 |
+
}
|
15 |
+
var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode);
|
16 |
+
for (var i = 0, e = lines.length; i < e; ++i) {
|
17 |
+
if (i) callback("\n");
|
18 |
+
var stream = new CodeMirror.StringStream(lines[i]);
|
19 |
+
while (!stream.eol()) {
|
20 |
+
var style = mode.token(stream, state);
|
21 |
+
callback(stream.current(), style);
|
22 |
+
stream.start = stream.pos;
|
23 |
+
}
|
24 |
+
}
|
25 |
+
if (isNode)
|
26 |
+
node.innerHTML = accum.join("");
|
27 |
+
};
|
libraries/codemirror/mode/css.js
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CodeMirror.defineMode("css", function(config) {
|
2 |
+
var indentUnit = config.indentUnit, type;
|
3 |
+
function ret(style, tp) {type = tp; return style;}
|
4 |
+
|
5 |
+
function tokenBase(stream, state) {
|
6 |
+
var ch = stream.next();
|
7 |
+
if (ch == "@") {stream.eatWhile(/\w/); return ret("meta", stream.current());}
|
8 |
+
else if (ch == "/" && stream.eat("*")) {
|
9 |
+
state.tokenize = tokenCComment;
|
10 |
+
return tokenCComment(stream, state);
|
11 |
+
}
|
12 |
+
else if (ch == "<" && stream.eat("!")) {
|
13 |
+
state.tokenize = tokenSGMLComment;
|
14 |
+
return tokenSGMLComment(stream, state);
|
15 |
+
}
|
16 |
+
else if (ch == "=") ret(null, "compare");
|
17 |
+
else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
|
18 |
+
else if (ch == "\"" || ch == "'") {
|
19 |
+
state.tokenize = tokenString(ch);
|
20 |
+
return state.tokenize(stream, state);
|
21 |
+
}
|
22 |
+
else if (ch == "#") {
|
23 |
+
stream.eatWhile(/\w/);
|
24 |
+
return ret("atom", "hash");
|
25 |
+
}
|
26 |
+
else if (ch == "!") {
|
27 |
+
stream.match(/^\s*\w*/);
|
28 |
+
return ret("keyword", "important");
|
29 |
+
}
|
30 |
+
else if (/\d/.test(ch)) {
|
31 |
+
stream.eatWhile(/[\w.%]/);
|
32 |
+
return ret("number", "unit");
|
33 |
+
}
|
34 |
+
else if (/[,.+>*\/]/.test(ch)) {
|
35 |
+
return ret(null, "select-op");
|
36 |
+
}
|
37 |
+
else if (/[;{}:\[\]]/.test(ch)) {
|
38 |
+
return ret(null, ch);
|
39 |
+
}
|
40 |
+
else {
|
41 |
+
stream.eatWhile(/[\w\\\-_]/);
|
42 |
+
return ret("variable", "variable");
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
function tokenCComment(stream, state) {
|
47 |
+
var maybeEnd = false, ch;
|
48 |
+
while ((ch = stream.next()) != null) {
|
49 |
+
if (maybeEnd && ch == "/") {
|
50 |
+
state.tokenize = tokenBase;
|
51 |
+
break;
|
52 |
+
}
|
53 |
+
maybeEnd = (ch == "*");
|
54 |
+
}
|
55 |
+
return ret("comment", "comment");
|
56 |
+
}
|
57 |
+
|
58 |
+
function tokenSGMLComment(stream, state) {
|
59 |
+
var dashes = 0, ch;
|
60 |
+
while ((ch = stream.next()) != null) {
|
61 |
+
if (dashes >= 2 && ch == ">") {
|
62 |
+
state.tokenize = tokenBase;
|
63 |
+
break;
|
64 |
+
}
|
65 |
+
dashes = (ch == "-") ? dashes + 1 : 0;
|
66 |
+
}
|
67 |
+
return ret("comment", "comment");
|
68 |
+
}
|
69 |
+
|
70 |
+
function tokenString(quote) {
|
71 |
+
return function(stream, state) {
|
72 |
+
var escaped = false, ch;
|
73 |
+
while ((ch = stream.next()) != null) {
|
74 |
+
if (ch == quote && !escaped)
|
75 |
+
break;
|
76 |
+
escaped = !escaped && ch == "\\";
|
77 |
+
}
|
78 |
+
if (!escaped) state.tokenize = tokenBase;
|
79 |
+
return ret("string", "string");
|
80 |
+
};
|
81 |
+
}
|
82 |
+
|
83 |
+
return {
|
84 |
+
startState: function(base) {
|
85 |
+
return {tokenize: tokenBase,
|
86 |
+
baseIndent: base || 0,
|
87 |
+
stack: []};
|
88 |
+
},
|
89 |
+
|
90 |
+
token: function(stream, state) {
|
91 |
+
if (stream.eatSpace()) return null;
|
92 |
+
var style = state.tokenize(stream, state);
|
93 |
+
|
94 |
+
var context = state.stack[state.stack.length-1];
|
95 |
+
if (type == "hash" && context == "rule") style = "atom";
|
96 |
+
else if (style == "variable") {
|
97 |
+
if (context == "rule") style = "number";
|
98 |
+
else if (!context || context == "@media{") style = "tag";
|
99 |
+
}
|
100 |
+
|
101 |
+
if (context == "rule" && /^[\{\};]$/.test(type))
|
102 |
+
state.stack.pop();
|
103 |
+
if (type == "{") {
|
104 |
+
if (context == "@media") state.stack[state.stack.length-1] = "@media{";
|
105 |
+
else state.stack.push("{");
|
106 |
+
}
|
107 |
+
else if (type == "}") state.stack.pop();
|
108 |
+
else if (type == "@media") state.stack.push("@media");
|
109 |
+
else if (context == "{" && type != "comment") state.stack.push("rule");
|
110 |
+
return style;
|
111 |
+
},
|
112 |
+
|
113 |
+
indent: function(state, textAfter) {
|
114 |
+
var n = state.stack.length;
|
115 |
+
if (/^\}/.test(textAfter))
|
116 |
+
n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
|
117 |
+
return state.baseIndent + n * indentUnit;
|
118 |
+
},
|
119 |
+
|
120 |
+
electricChars: "}"
|
121 |
+
};
|
122 |
+
});
|
123 |
+
|
124 |
+
CodeMirror.defineMIME("text/css", "css");
|
libraries/codemirror/mode/htmlmixed.js
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
|
2 |
+
var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
|
3 |
+
var jsMode = CodeMirror.getMode(config, "javascript");
|
4 |
+
var cssMode = CodeMirror.getMode(config, "css");
|
5 |
+
|
6 |
+
function html(stream, state) {
|
7 |
+
var style = htmlMode.token(stream, state.htmlState);
|
8 |
+
if (style == "tag" && stream.current() == ">" && state.htmlState.context) {
|
9 |
+
if (/^script$/i.test(state.htmlState.context.tagName)) {
|
10 |
+
state.token = javascript;
|
11 |
+
state.localState = jsMode.startState(htmlMode.indent(state.htmlState, ""));
|
12 |
+
}
|
13 |
+
else if (/^style$/i.test(state.htmlState.context.tagName)) {
|
14 |
+
state.token = css;
|
15 |
+
state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
|
16 |
+
}
|
17 |
+
}
|
18 |
+
return style;
|
19 |
+
}
|
20 |
+
function maybeBackup(stream, pat, style) {
|
21 |
+
var cur = stream.current();
|
22 |
+
var close = cur.search(pat);
|
23 |
+
if (close > -1) stream.backUp(cur.length - close);
|
24 |
+
return style;
|
25 |
+
}
|
26 |
+
function javascript(stream, state) {
|
27 |
+
if (stream.match(/^<\/\s*script\s*>/i, false)) {
|
28 |
+
state.token = html;
|
29 |
+
state.curState = null;
|
30 |
+
return html(stream, state);
|
31 |
+
}
|
32 |
+
return maybeBackup(stream, /<\/\s*script\s*>/,
|
33 |
+
jsMode.token(stream, state.localState));
|
34 |
+
}
|
35 |
+
function css(stream, state) {
|
36 |
+
if (stream.match(/^<\/\s*style\s*>/i, false)) {
|
37 |
+
state.token = html;
|
38 |
+
state.localState = null;
|
39 |
+
return html(stream, state);
|
40 |
+
}
|
41 |
+
return maybeBackup(stream, /<\/\s*style\s*>/,
|
42 |
+
cssMode.token(stream, state.localState));
|
43 |
+
}
|
44 |
+
|
45 |
+
return {
|
46 |
+
startState: function() {
|
47 |
+
var state = htmlMode.startState();
|
48 |
+
return {token: html, localState: null, htmlState: state};
|
49 |
+
},
|
50 |
+
|
51 |
+
copyState: function(state) {
|
52 |
+
if (state.localState)
|
53 |
+
var local = CodeMirror.copyState(state.token == css ? cssMode : jsMode, state.localState);
|
54 |
+
return {token: state.token, localState: local, htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
|
55 |
+
},
|
56 |
+
|
57 |
+
token: function(stream, state) {
|
58 |
+
return state.token(stream, state);
|
59 |
+
},
|
60 |
+
|
61 |
+
indent: function(state, textAfter) {
|
62 |
+
if (state.token == html || /^\s*<\//.test(textAfter))
|
63 |
+
return htmlMode.indent(state.htmlState, textAfter);
|
64 |
+
else if (state.token == javascript)
|
65 |
+
return jsMode.indent(state.localState, textAfter);
|
66 |
+
else
|
67 |
+
return cssMode.indent(state.localState, textAfter);
|
68 |
+
},
|
69 |
+
|
70 |
+
electricChars: "/{}:"
|
71 |
+
}
|
72 |
+
});
|
73 |
+
|
74 |
+
CodeMirror.defineMIME("text/html", "htmlmixed");
|
libraries/codemirror/mode/javascript.js
ADDED
@@ -0,0 +1,348 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
2 |
+
var indentUnit = config.indentUnit;
|
3 |
+
var jsonMode = parserConfig.json;
|
4 |
+
|
5 |
+
// Tokenizer
|
6 |
+
|
7 |
+
var keywords = function(){
|
8 |
+
function kw(type) {return {type: type, style: "keyword"};}
|
9 |
+
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
|
10 |
+
var operator = kw("operator"), atom = {type: "atom", style: "atom"};
|
11 |
+
return {
|
12 |
+
"if": A, "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
|
13 |
+
"return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C,
|
14 |
+
"var": kw("var"), "function": kw("function"), "catch": kw("catch"),
|
15 |
+
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
|
16 |
+
"in": operator, "typeof": operator, "instanceof": operator,
|
17 |
+
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom
|
18 |
+
};
|
19 |
+
}();
|
20 |
+
|
21 |
+
var isOperatorChar = /[+\-*&%=<>!?|]/;
|
22 |
+
|
23 |
+
function chain(stream, state, f) {
|
24 |
+
state.tokenize = f;
|
25 |
+
return f(stream, state);
|
26 |
+
}
|
27 |
+
|
28 |
+
function nextUntilUnescaped(stream, end) {
|
29 |
+
var escaped = false, next;
|
30 |
+
while ((next = stream.next()) != null) {
|
31 |
+
if (next == end && !escaped)
|
32 |
+
return false;
|
33 |
+
escaped = !escaped && next == "\\";
|
34 |
+
}
|
35 |
+
return escaped;
|
36 |
+
}
|
37 |
+
|
38 |
+
// Used as scratch variables to communicate multiple values without
|
39 |
+
// consing up tons of objects.
|
40 |
+
var type, content;
|
41 |
+
function ret(tp, style, cont) {
|
42 |
+
type = tp; content = cont;
|
43 |
+
return style;
|
44 |
+
}
|
45 |
+
|
46 |
+
function jsTokenBase(stream, state) {
|
47 |
+
var ch = stream.next();
|
48 |
+
if (ch == '"' || ch == "'")
|
49 |
+
return chain(stream, state, jsTokenString(ch));
|
50 |
+
else if (/[\[\]{}\(\),;\:\.]/.test(ch))
|
51 |
+
return ret(ch);
|
52 |
+
else if (ch == "0" && stream.eat(/x/i)) {
|
53 |
+
stream.eatWhile(/[\da-f]/i);
|
54 |
+
return ret("number", "atom");
|
55 |
+
}
|
56 |
+
else if (/\d/.test(ch)) {
|
57 |
+
stream.match(/^\d*(?:\.\d*)?(?:e[+\-]?\d+)?/);
|
58 |
+
return ret("number", "atom");
|
59 |
+
}
|
60 |
+
else if (ch == "/") {
|
61 |
+
if (stream.eat("*")) {
|
62 |
+
return chain(stream, state, jsTokenComment);
|
63 |
+
}
|
64 |
+
else if (stream.eat("/")) {
|
65 |
+
stream.skipToEnd();
|
66 |
+
return ret("comment", "comment");
|
67 |
+
}
|
68 |
+
else if (state.reAllowed) {
|
69 |
+
nextUntilUnescaped(stream, "/");
|
70 |
+
stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla
|
71 |
+
return ret("regexp", "string");
|
72 |
+
}
|
73 |
+
else {
|
74 |
+
stream.eatWhile(isOperatorChar);
|
75 |
+
return ret("operator", null, stream.current());
|
76 |
+
}
|
77 |
+
}
|
78 |
+
else if (isOperatorChar.test(ch)) {
|
79 |
+
stream.eatWhile(isOperatorChar);
|
80 |
+
return ret("operator", null, stream.current());
|
81 |
+
}
|
82 |
+
else {
|
83 |
+
stream.eatWhile(/[\w\$_]/);
|
84 |
+
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
|
85 |
+
return known ? ret(known.type, known.style, word) :
|
86 |
+
ret("variable", "variable", word);
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
function jsTokenString(quote) {
|
91 |
+
return function(stream, state) {
|
92 |
+
if (!nextUntilUnescaped(stream, quote))
|
93 |
+
state.tokenize = jsTokenBase;
|
94 |
+
return ret("string", "string");
|
95 |
+
};
|
96 |
+
}
|
97 |
+
|
98 |
+
function jsTokenComment(stream, state) {
|
99 |
+
var maybeEnd = false, ch;
|
100 |
+
while (ch = stream.next()) {
|
101 |
+
if (ch == "/" && maybeEnd) {
|
102 |
+
state.tokenize = jsTokenBase;
|
103 |
+
break;
|
104 |
+
}
|
105 |
+
maybeEnd = (ch == "*");
|
106 |
+
}
|
107 |
+
return ret("comment", "comment");
|
108 |
+
}
|
109 |
+
|
110 |
+
// Parser
|
111 |
+
|
112 |
+
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true};
|
113 |
+
|
114 |
+
function JSLexical(indented, column, type, align, prev, info) {
|
115 |
+
this.indented = indented;
|
116 |
+
this.column = column;
|
117 |
+
this.type = type;
|
118 |
+
this.prev = prev;
|
119 |
+
this.info = info;
|
120 |
+
if (align != null) this.align = align;
|
121 |
+
}
|
122 |
+
|
123 |
+
function inScope(state, varname) {
|
124 |
+
for (var v = state.localVars; v; v = v.next)
|
125 |
+
if (v.name == varname) return true;
|
126 |
+
}
|
127 |
+
|
128 |
+
function parseJS(state, style, type, content, stream) {
|
129 |
+
var cc = state.cc;
|
130 |
+
// Communicate our context to the combinators.
|
131 |
+
// (Less wasteful than consing up a hundred closures on every call.)
|
132 |
+
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc;
|
133 |
+
|
134 |
+
if (!state.lexical.hasOwnProperty("align"))
|
135 |
+
state.lexical.align = true;
|
136 |
+
|
137 |
+
while(true) {
|
138 |
+
var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
|
139 |
+
if (combinator(type, content)) {
|
140 |
+
while(cc.length && cc[cc.length - 1].lex)
|
141 |
+
cc.pop()();
|
142 |
+
if (cx.marked) return cx.marked;
|
143 |
+
if (type == "variable" && inScope(state, content)) return "variable-2";
|
144 |
+
return style;
|
145 |
+
}
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
// Combinator utils
|
150 |
+
|
151 |
+
var cx = {state: null, column: null, marked: null, cc: null};
|
152 |
+
function pass() {
|
153 |
+
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
|
154 |
+
}
|
155 |
+
function cont() {
|
156 |
+
pass.apply(null, arguments);
|
157 |
+
return true;
|
158 |
+
}
|
159 |
+
function register(varname) {
|
160 |
+
var state = cx.state;
|
161 |
+
if (state.context) {
|
162 |
+
cx.marked = "def";
|
163 |
+
for (var v = state.localVars; v; v = v.next)
|
164 |
+
if (v.name == varname) return;
|
165 |
+
state.localVars = {name: varname, next: state.localVars};
|
166 |
+
}
|
167 |
+
}
|
168 |
+
|
169 |
+
// Combinators
|
170 |
+
|
171 |
+
var defaultVars = {name: "this", next: {name: "arguments"}};
|
172 |
+
function pushcontext() {
|
173 |
+
if (!cx.state.context) cx.state.localVars = defaultVars;
|
174 |
+
cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
|
175 |
+
}
|
176 |
+
function popcontext() {
|
177 |
+
cx.state.localVars = cx.state.context.vars;
|
178 |
+
cx.state.context = cx.state.context.prev;
|
179 |
+
}
|
180 |
+
function pushlex(type, info) {
|
181 |
+
var result = function() {
|
182 |
+
var state = cx.state;
|
183 |
+
state.lexical = new JSLexical(state.indented, cx.stream.column(), type, null, state.lexical, info)
|
184 |
+
};
|
185 |
+
result.lex = true;
|
186 |
+
return result;
|
187 |
+
}
|
188 |
+
function poplex() {
|
189 |
+
var state = cx.state;
|
190 |
+
if (state.lexical.prev) {
|
191 |
+
if (state.lexical.type == ")")
|
192 |
+
state.indented = state.lexical.indented;
|
193 |
+
state.lexical = state.lexical.prev;
|
194 |
+
}
|
195 |
+
}
|
196 |
+
poplex.lex = true;
|
197 |
+
|
198 |
+
function expect(wanted) {
|
199 |
+
return function expecting(type) {
|
200 |
+
if (type == wanted) return cont();
|
201 |
+
else if (wanted == ";") return pass();
|
202 |
+
else return cont(arguments.callee);
|
203 |
+
};
|
204 |
+
}
|
205 |
+
|
206 |
+
function statement(type) {
|
207 |
+
if (type == "var") return cont(pushlex("vardef"), vardef1, expect(";"), poplex);
|
208 |
+
if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex);
|
209 |
+
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
|
210 |
+
if (type == "{") return cont(pushlex("}"), block, poplex);
|
211 |
+
if (type == ";") return cont();
|
212 |
+
if (type == "function") return cont(functiondef);
|
213 |
+
if (type == "for") return cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"),
|
214 |
+
poplex, statement, poplex);
|
215 |
+
if (type == "variable") return cont(pushlex("stat"), maybelabel);
|
216 |
+
if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"),
|
217 |
+
block, poplex, poplex);
|
218 |
+
if (type == "case") return cont(expression, expect(":"));
|
219 |
+
if (type == "default") return cont(expect(":"));
|
220 |
+
if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
|
221 |
+
statement, poplex, popcontext);
|
222 |
+
return pass(pushlex("stat"), expression, expect(";"), poplex);
|
223 |
+
}
|
224 |
+
function expression(type) {
|
225 |
+
if (atomicTypes.hasOwnProperty(type)) return cont(maybeoperator);
|
226 |
+
if (type == "function") return cont(functiondef);
|
227 |
+
if (type == "keyword c") return cont(expression);
|
228 |
+
if (type == "(") return cont(pushlex(")"), expression, expect(")"), poplex, maybeoperator);
|
229 |
+
if (type == "operator") return cont(expression);
|
230 |
+
if (type == "[") return cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
|
231 |
+
if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator);
|
232 |
+
return cont();
|
233 |
+
}
|
234 |
+
function maybeoperator(type, value) {
|
235 |
+
if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator);
|
236 |
+
if (type == "operator") return cont(expression);
|
237 |
+
if (type == ";") return;
|
238 |
+
if (type == "(") return cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator);
|
239 |
+
if (type == ".") return cont(property, maybeoperator);
|
240 |
+
if (type == "[") return cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator);
|
241 |
+
}
|
242 |
+
function maybelabel(type) {
|
243 |
+
if (type == ":") return cont(poplex, statement);
|
244 |
+
return pass(maybeoperator, expect(";"), poplex);
|
245 |
+
}
|
246 |
+
function property(type) {
|
247 |
+
if (type == "variable") {cx.marked = "property"; return cont();}
|
248 |
+
}
|
249 |
+
function objprop(type) {
|
250 |
+
if (type == "variable") cx.marked = "property";
|
251 |
+
if (atomicTypes.hasOwnProperty(type)) return cont(expect(":"), expression);
|
252 |
+
}
|
253 |
+
function commasep(what, end) {
|
254 |
+
function proceed(type) {
|
255 |
+
if (type == ",") return cont(what, proceed);
|
256 |
+
if (type == end) return cont();
|
257 |
+
return cont(expect(end));
|
258 |
+
}
|
259 |
+
return function commaSeparated(type) {
|
260 |
+
if (type == end) return cont();
|
261 |
+
else return pass(what, proceed);
|
262 |
+
};
|
263 |
+
}
|
264 |
+
function block(type) {
|
265 |
+
if (type == "}") return cont();
|
266 |
+
return pass(statement, block);
|
267 |
+
}
|
268 |
+
function vardef1(type, value) {
|
269 |
+
if (type == "variable"){register(value); return cont(vardef2);}
|
270 |
+
return cont();
|
271 |
+
}
|
272 |
+
function vardef2(type, value) {
|
273 |
+
if (value == "=") return cont(expression, vardef2);
|
274 |
+
if (type == ",") return cont(vardef1);
|
275 |
+
}
|
276 |
+
function forspec1(type) {
|
277 |
+
if (type == "var") return cont(vardef1, forspec2);
|
278 |
+
if (type == ";") return pass(forspec2);
|
279 |
+
if (type == "variable") return cont(formaybein);
|
280 |
+
return pass(forspec2);
|
281 |
+
}
|
282 |
+
function formaybein(type, value) {
|
283 |
+
if (value == "in") return cont(expression);
|
284 |
+
return cont(maybeoperator, forspec2);
|
285 |
+
}
|
286 |
+
function forspec2(type, value) {
|
287 |
+
if (type == ";") return cont(forspec3);
|
288 |
+
if (value == "in") return cont(expression);
|
289 |
+
return cont(expression, expect(";"), forspec3);
|
290 |
+
}
|
291 |
+
function forspec3(type) {
|
292 |
+
if (type != ")") cont(expression);
|
293 |
+
}
|
294 |
+
function functiondef(type, value) {
|
295 |
+
if (type == "variable") {register(value); return cont(functiondef);}
|
296 |
+
if (type == "(") return cont(pushlex(")"), pushcontext, commasep(funarg, ")"), poplex, statement, popcontext);
|
297 |
+
}
|
298 |
+
function funarg(type, value) {
|
299 |
+
if (type == "variable") {register(value); return cont();}
|
300 |
+
}
|
301 |
+
|
302 |
+
// Interface
|
303 |
+
|
304 |
+
return {
|
305 |
+
startState: function(basecolumn) {
|
306 |
+
return {
|
307 |
+
tokenize: jsTokenBase,
|
308 |
+
reAllowed: true,
|
309 |
+
cc: [],
|
310 |
+
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
|
311 |
+
localVars: null,
|
312 |
+
context: null,
|
313 |
+
indented: 0
|
314 |
+
};
|
315 |
+
},
|
316 |
+
|
317 |
+
token: function(stream, state) {
|
318 |
+
if (stream.sol()) {
|
319 |
+
if (!state.lexical.hasOwnProperty("align"))
|
320 |
+
state.lexical.align = false;
|
321 |
+
state.indented = stream.indentation();
|
322 |
+
}
|
323 |
+
if (stream.eatSpace()) return null;
|
324 |
+
var style = state.tokenize(stream, state);
|
325 |
+
if (type == "comment") return style;
|
326 |
+
state.reAllowed = type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/);
|
327 |
+
return parseJS(state, style, type, content, stream);
|
328 |
+
},
|
329 |
+
|
330 |
+
indent: function(state, textAfter) {
|
331 |
+
if (state.tokenize != jsTokenBase) return 0;
|
332 |
+
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical,
|
333 |
+
type = lexical.type, closing = firstChar == type;
|
334 |
+
if (type == "vardef") return lexical.indented + 4;
|
335 |
+
else if (type == "form" && firstChar == "{") return lexical.indented;
|
336 |
+
else if (type == "stat" || type == "form") return lexical.indented + indentUnit;
|
337 |
+
else if (lexical.info == "switch" && !closing)
|
338 |
+
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
|
339 |
+
else if (lexical.align) return lexical.column + (closing ? 0 : 1);
|
340 |
+
else return lexical.indented + (closing ? 0 : indentUnit);
|
341 |
+
},
|
342 |
+
|
343 |
+
electricChars: ":{}"
|
344 |
+
};
|
345 |
+
});
|
346 |
+
|
347 |
+
CodeMirror.defineMIME("text/javascript", "javascript");
|
348 |
+
CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
|
libraries/codemirror/mode/xml.js
ADDED
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CodeMirror.defineMode("xml", function(config, parserConfig) {
|
2 |
+
var indentUnit = config.indentUnit;
|
3 |
+
var Kludges = parserConfig.htmlMode ? {
|
4 |
+
autoSelfClosers: {"br": true, "img": true, "hr": true, "link": true, "input": true,
|
5 |
+
"meta": true, "col": true, "frame": true, "base": true, "area": true},
|
6 |
+
doNotIndent: {"pre": true, "!cdata": true},
|
7 |
+
allowUnquoted: true
|
8 |
+
} : {autoSelfClosers: {}, doNotIndent: {"!cdata": true}, allowUnquoted: false};
|
9 |
+
var alignCDATA = parserConfig.alignCDATA;
|
10 |
+
|
11 |
+
// Return variables for tokenizers
|
12 |
+
var tagName, type;
|
13 |
+
|
14 |
+
function inText(stream, state) {
|
15 |
+
function chain(parser) {
|
16 |
+
state.tokenize = parser;
|
17 |
+
return parser(stream, state);
|
18 |
+
}
|
19 |
+
|
20 |
+
var ch = stream.next();
|
21 |
+
if (ch == "<") {
|
22 |
+
if (stream.eat("!")) {
|
23 |
+
if (stream.eat("[")) {
|
24 |
+
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
|
25 |
+
else return null;
|
26 |
+
}
|
27 |
+
else if (stream.match("--")) return chain(inBlock("comment", "-->"));
|
28 |
+
else if (stream.match("DOCTYPE")) {
|
29 |
+
stream.eatWhile(/[\w\._\-]/);
|
30 |
+
return chain(inBlock("meta", ">"));
|
31 |
+
}
|
32 |
+
else return null;
|
33 |
+
}
|
34 |
+
else if (stream.eat("?")) {
|
35 |
+
stream.eatWhile(/[\w\._\-]/);
|
36 |
+
state.tokenize = inBlock("meta", "?>");
|
37 |
+
return "meta";
|
38 |
+
}
|
39 |
+
else {
|
40 |
+
type = stream.eat("/") ? "closeTag" : "openTag";
|
41 |
+
stream.eatSpace();
|
42 |
+
tagName = "";
|
43 |
+
var c;
|
44 |
+
while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
|
45 |
+
state.tokenize = inTag;
|
46 |
+
return "tag";
|
47 |
+
}
|
48 |
+
}
|
49 |
+
else if (ch == "&") {
|
50 |
+
stream.eatWhile(/[^;]/);
|
51 |
+
stream.eat(";");
|
52 |
+
return "atom";
|
53 |
+
}
|
54 |
+
else {
|
55 |
+
stream.eatWhile(/[^&<]/);
|
56 |
+
return null;
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
function inTag(stream, state) {
|
61 |
+
var ch = stream.next();
|
62 |
+
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
|
63 |
+
state.tokenize = inText;
|
64 |
+
type = ch == ">" ? "endTag" : "selfcloseTag";
|
65 |
+
return "tag";
|
66 |
+
}
|
67 |
+
else if (ch == "=") {
|
68 |
+
type = "equals";
|
69 |
+
return null;
|
70 |
+
}
|
71 |
+
else if (/[\'\"]/.test(ch)) {
|
72 |
+
state.tokenize = inAttribute(ch);
|
73 |
+
return state.tokenize(stream, state);
|
74 |
+
}
|
75 |
+
else {
|
76 |
+
stream.eatWhile(/[^\s\u00a0=<>\"\'\/?]/);
|
77 |
+
return "word";
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
function inAttribute(quote) {
|
82 |
+
return function(stream, state) {
|
83 |
+
while (!stream.eol()) {
|
84 |
+
if (stream.next() == quote) {
|
85 |
+
state.tokenize = inTag;
|
86 |
+
break;
|
87 |
+
}
|
88 |
+
}
|
89 |
+
return "string";
|
90 |
+
};
|
91 |
+
}
|
92 |
+
|
93 |
+
function inBlock(style, terminator) {
|
94 |
+
return function(stream, state) {
|
95 |
+
while (!stream.eol()) {
|
96 |
+
if (stream.match(terminator)) {
|
97 |
+
state.tokenize = inText;
|
98 |
+
break;
|
99 |
+
}
|
100 |
+
stream.next();
|
101 |
+
}
|
102 |
+
return style;
|
103 |
+
};
|
104 |
+
}
|
105 |
+
|
106 |
+
var curState, setStyle;
|
107 |
+
function pass() {
|
108 |
+
for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
|
109 |
+
}
|
110 |
+
function cont() {
|
111 |
+
pass.apply(null, arguments);
|
112 |
+
return true;
|
113 |
+
}
|
114 |
+
|
115 |
+
function pushContext(tagName, startOfLine) {
|
116 |
+
var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent);
|
117 |
+
curState.context = {
|
118 |
+
prev: curState.context,
|
119 |
+
tagName: tagName,
|
120 |
+
indent: curState.indented,
|
121 |
+
startOfLine: startOfLine,
|
122 |
+
noIndent: noIndent
|
123 |
+
};
|
124 |
+
}
|
125 |
+
function popContext() {
|
126 |
+
if (curState.context) curState.context = curState.context.prev;
|
127 |
+
}
|
128 |
+
|
129 |
+
function element(type) {
|
130 |
+
if (type == "openTag") {curState.tagName = tagName; return cont(attributes, endtag(curState.startOfLine));}
|
131 |
+
else if (type == "closeTag") {popContext(); return cont(endclosetag);}
|
132 |
+
else if (type == "string") {
|
133 |
+
if (!curState.context || curState.context.name != "!cdata") pushContext("!cdata");
|
134 |
+
if (curState.tokenize == inText) popContext();
|
135 |
+
return cont();
|
136 |
+
}
|
137 |
+
else return cont();
|
138 |
+
}
|
139 |
+
function endtag(startOfLine) {
|
140 |
+
return function(type) {
|
141 |
+
if (type == "selfcloseTag" ||
|
142 |
+
(type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase())))
|
143 |
+
return cont();
|
144 |
+
if (type == "endTag") {pushContext(curState.tagName, startOfLine); return cont();}
|
145 |
+
return cont();
|
146 |
+
};
|
147 |
+
}
|
148 |
+
function endclosetag(type) {
|
149 |
+
if (type == "endTag") return cont();
|
150 |
+
return pass();
|
151 |
+
}
|
152 |
+
|
153 |
+
function attributes(type) {
|
154 |
+
if (type == "word") {setStyle = "attribute"; return cont(attributes);}
|
155 |
+
if (type == "equals") return cont(attvalue, attributes);
|
156 |
+
return pass();
|
157 |
+
}
|
158 |
+
function attvalue(type) {
|
159 |
+
if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();}
|
160 |
+
if (type == "string") return cont();
|
161 |
+
return pass();
|
162 |
+
}
|
163 |
+
|
164 |
+
return {
|
165 |
+
startState: function() {
|
166 |
+
return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null};
|
167 |
+
},
|
168 |
+
|
169 |
+
token: function(stream, state) {
|
170 |
+
if (stream.sol()) {
|
171 |
+
state.startOfLine = true;
|
172 |
+
state.indented = stream.indentation();
|
173 |
+
}
|
174 |
+
if (stream.eatSpace()) return null;
|
175 |
+
|
176 |
+
setStyle = type = tagName = null;
|
177 |
+
var style = state.tokenize(stream, state);
|
178 |
+
if ((style || type) && style != "xml-comment") {
|
179 |
+
curState = state;
|
180 |
+
while (true) {
|
181 |
+
var comb = state.cc.pop() || element;
|
182 |
+
if (comb(type || style)) break;
|
183 |
+
}
|
184 |
+
}
|
185 |
+
state.startOfLine = false;
|
186 |
+
return setStyle || style;
|
187 |
+
},
|
188 |
+
|
189 |
+
indent: function(state, textAfter) {
|
190 |
+
var context = state.context;
|
191 |
+
if (context && context.noIndent) return 0;
|
192 |
+
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
|
193 |
+
if (context && /^<\//.test(textAfter))
|
194 |
+
context = context.prev;
|
195 |
+
while (context && !context.startOfLine)
|
196 |
+
context = context.prev;
|
197 |
+
if (context) return context.indent + indentUnit;
|
198 |
+
else return 0;
|
199 |
+
},
|
200 |
+
|
201 |
+
electricChars: "/"
|
202 |
+
};
|
203 |
+
});
|
204 |
+
|
205 |
+
CodeMirror.defineMIME("application/xml", "xml");
|
206 |
+
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
|
libraries/codemirror/theme/default.css
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cm-s-default span.cm-keyword {color: #708;}
|
2 |
+
.cm-s-default span.cm-atom {color: #219;}
|
3 |
+
.cm-s-default span.cm-number {color: #164;}
|
4 |
+
.cm-s-default span.cm-def {color: #00f;}
|
5 |
+
.cm-s-default span.cm-variable {color: black;}
|
6 |
+
.cm-s-default span.cm-variable-2 {color: #05a;}
|
7 |
+
.cm-s-default span.cm-variable-3 {color: #0a5;}
|
8 |
+
.cm-s-default span.cm-property {color: black;}
|
9 |
+
.cm-s-default span.cm-operator {color: black;}
|
10 |
+
.cm-s-default span.cm-comment {color: #a50;}
|
11 |
+
.cm-s-default span.cm-string {color: #a11;}
|
12 |
+
.cm-s-default span.cm-meta {color: #555;}
|
13 |
+
.cm-s-default span.cm-error {color: #f00;}
|
14 |
+
.cm-s-default span.cm-qualifier {color: #555;}
|
15 |
+
.cm-s-default span.cm-builtin {color: #30a;}
|
16 |
+
.cm-s-default span.cm-bracket {color: #cc7;}
|
17 |
+
.cm-s-default span.cm-tag {color: #170;}
|
18 |
+
.cm-s-default span.cm-attribute {color: #00c;}
|
libraries/codemirror/theme/elegant.css
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cm-s-elegant span.cm-number, .cm-s-elegant span.cm-string, .cm-s-elegant span.cm-atom {color: #762;}
|
2 |
+
.cm-s-elegant span.cm-comment {color: #262;font-style: italic;}
|
3 |
+
.cm-s-elegant span.cm-meta {color: #555;font-style: italic;}
|
4 |
+
.cm-s-elegant span.cm-variable {color: black;}
|
5 |
+
.cm-s-elegant span.cm-variable-2 {color: #b11;}
|
6 |
+
.cm-s-elegant span.cm-qualifier {color: #555;}
|
7 |
+
.cm-s-elegant span.cm-keyword {color: #730;}
|
8 |
+
.cm-s-elegant span.cm-builtin {color: #30a;}
|
9 |
+
.cm-s-elegant span.cm-error {background-color: #fdd;}
|
libraries/codemirror/theme/neat.css
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cm-s-neat span.cm-comment { color: #a86; }
|
2 |
+
.cm-s-neat span.cm-keyword { font-weight: bold; color: blue; }
|
3 |
+
.cm-s-neat span.cm-string { color: #a22; }
|
4 |
+
.cm-s-neat span.cm-builtin { font-weight: bold; color: #077; }
|
5 |
+
.cm-s-neat span.cm-special { font-weight: bold; color: #0aa; }
|
6 |
+
.cm-s-neat span.cm-variable { color: black; }
|
7 |
+
.cm-s-neat span.cm-number, .cm-s-neat span.cm-atom { color: #3a3; }
|
8 |
+
.cm-s-neat span.cm-meta {color: #555;}
|
libraries/codemirror/theme/night.css
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Loosely based on the Midnight Textmate theme */
|
2 |
+
|
3 |
+
.cm-s-night { background: #0a001f; color: #f8f8f8; }
|
4 |
+
.cm-s-night span.CodeMirror-selected { background: #a8f !important; }
|
5 |
+
.cm-s-night .CodeMirror-gutter { background: #0a001f; border-right: 1px solid #aaa; }
|
6 |
+
.cm-s-night .CodeMirror-gutter-text { color: #f8f8f8; }
|
7 |
+
.cm-s-night .CodeMirror-cursor { border-left: 1px solid white !important; }
|
8 |
+
|
9 |
+
.cm-s-night span.cm-comment { color: #6900a1; }
|
10 |
+
.cm-s-night span.cm-atom { color: #845dc4; }
|
11 |
+
.cm-s-night span.cm-number { color: #ffd500; }
|
12 |
+
.cm-s-night span.cm-keyword { color: #599eff; }
|
13 |
+
.cm-s-night span.cm-string { color: #37f14a; }
|
14 |
+
.cm-s-night span.cm-meta { color: #7678e2; }
|
15 |
+
.cm-s-night span.cm-variable-2 { color: #99b2ff; }
|
16 |
+
.cm-s-night span.cm-variable-3, .cm-s-night span.cm-def { white; }
|
17 |
+
.cm-s-night span.cm-error { color: #9d1e15; }
|
18 |
+
.cm-s-night span.cm-bracket { color: #8da6ce; }
|
19 |
+
.cm-s-night span.cm-comment { color: #6900a1; }
|
20 |
+
.cm-s-night span.cm-builtin, .cm-s-night span.cm-special { color: #ff9e59; }
|
license.txt
CHANGED
@@ -1,281 +1,281 @@
|
|
1 |
-
GNU GENERAL PUBLIC LICENSE
|
2 |
-
Version 2, June 1991
|
3 |
-
|
4 |
-
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
5 |
-
51 Franklin St, Fifth Floor, Boston, MA 02110, USA
|
6 |
-
|
7 |
-
Everyone is permitted to copy and distribute verbatim copies
|
8 |
-
of this license document, but changing it is not allowed.
|
9 |
-
|
10 |
-
Preamble
|
11 |
-
|
12 |
-
The licenses for most software are designed to take away your
|
13 |
-
freedom to share and change it. By contrast, the GNU General Public
|
14 |
-
License is intended to guarantee your freedom to share and change free
|
15 |
-
software--to make sure the software is free for all its users. This
|
16 |
-
General Public License applies to most of the Free Software
|
17 |
-
Foundation's software and to any other program whose authors commit to
|
18 |
-
using it. (Some other Free Software Foundation software is covered by
|
19 |
-
the GNU Library General Public License instead.) You can apply it to
|
20 |
-
your programs, too.
|
21 |
-
|
22 |
-
When we speak of free software, we are referring to freedom, not
|
23 |
-
price. Our General Public Licenses are designed to make sure that you
|
24 |
-
have the freedom to distribute copies of free software (and charge for
|
25 |
-
this service if you wish), that you receive source code or can get it
|
26 |
-
if you want it, that you can change the software or use pieces of it
|
27 |
-
in new free programs; and that you know you can do these things.
|
28 |
-
|
29 |
-
To protect your rights, we need to make restrictions that forbid
|
30 |
-
anyone to deny you these rights or to ask you to surrender the rights.
|
31 |
-
These restrictions translate to certain responsibilities for you if you
|
32 |
-
distribute copies of the software, or if you modify it.
|
33 |
-
|
34 |
-
For example, if you distribute copies of such a program, whether
|
35 |
-
gratis or for a fee, you must give the recipients all the rights that
|
36 |
-
you have. You must make sure that they, too, receive or can get the
|
37 |
-
source code. And you must show them these terms so they know their
|
38 |
-
rights.
|
39 |
-
|
40 |
-
We protect your rights with two steps: (1) copyright the software, and
|
41 |
-
(2) offer you this license which gives you legal permission to copy,
|
42 |
-
distribute and/or modify the software.
|
43 |
-
|
44 |
-
Also, for each author's protection and ours, we want to make certain
|
45 |
-
that everyone understands that there is no warranty for this free
|
46 |
-
software. If the software is modified by someone else and passed on, we
|
47 |
-
want its recipients to know that what they have is not the original, so
|
48 |
-
that any problems introduced by others will not reflect on the original
|
49 |
-
authors' reputations.
|
50 |
-
|
51 |
-
Finally, any free program is threatened constantly by software
|
52 |
-
patents. We wish to avoid the danger that redistributors of a free
|
53 |
-
program will individually obtain patent licenses, in effect making the
|
54 |
-
program proprietary. To prevent this, we have made it clear that any
|
55 |
-
patent must be licensed for everyone's free use or not licensed at all.
|
56 |
-
|
57 |
-
The precise terms and conditions for copying, distribution and
|
58 |
-
modification follow.
|
59 |
-
|
60 |
-
GNU GENERAL PUBLIC LICENSE
|
61 |
-
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
62 |
-
|
63 |
-
0. This License applies to any program or other work which contains
|
64 |
-
a notice placed by the copyright holder saying it may be distributed
|
65 |
-
under the terms of this General Public License. The "Program", below,
|
66 |
-
refers to any such program or work, and a "work based on the Program"
|
67 |
-
means either the Program or any derivative work under copyright law:
|
68 |
-
that is to say, a work containing the Program or a portion of it,
|
69 |
-
either verbatim or with modifications and/or translated into another
|
70 |
-
language. (Hereinafter, translation is included without limitation in
|
71 |
-
the term "modification".) Each licensee is addressed as "you".
|
72 |
-
|
73 |
-
Activities other than copying, distribution and modification are not
|
74 |
-
covered by this License; they are outside its scope. The act of
|
75 |
-
running the Program is not restricted, and the output from the Program
|
76 |
-
is covered only if its contents constitute a work based on the
|
77 |
-
Program (independent of having been made by running the Program).
|
78 |
-
Whether that is true depends on what the Program does.
|
79 |
-
|
80 |
-
1. You may copy and distribute verbatim copies of the Program's
|
81 |
-
source code as you receive it, in any medium, provided that you
|
82 |
-
conspicuously and appropriately publish on each copy an appropriate
|
83 |
-
copyright notice and disclaimer of warranty; keep intact all the
|
84 |
-
notices that refer to this License and to the absence of any warranty;
|
85 |
-
and give any other recipients of the Program a copy of this License
|
86 |
-
along with the Program.
|
87 |
-
|
88 |
-
You may charge a fee for the physical act of transferring a copy, and
|
89 |
-
you may at your option offer warranty protection in exchange for a fee.
|
90 |
-
|
91 |
-
2. You may modify your copy or copies of the Program or any portion
|
92 |
-
of it, thus forming a work based on the Program, and copy and
|
93 |
-
distribute such modifications or work under the terms of Section 1
|
94 |
-
above, provided that you also meet all of these conditions:
|
95 |
-
|
96 |
-
a) You must cause the modified files to carry prominent notices
|
97 |
-
stating that you changed the files and the date of any change.
|
98 |
-
|
99 |
-
b) You must cause any work that you distribute or publish, that in
|
100 |
-
whole or in part contains or is derived from the Program or any
|
101 |
-
part thereof, to be licensed as a whole at no charge to all third
|
102 |
-
parties under the terms of this License.
|
103 |
-
|
104 |
-
c) If the modified program normally reads commands interactively
|
105 |
-
when run, you must cause it, when started running for such
|
106 |
-
interactive use in the most ordinary way, to print or display an
|
107 |
-
announcement including an appropriate copyright notice and a
|
108 |
-
notice that there is no warranty (or else, saying that you provide
|
109 |
-
a warranty) and that users may redistribute the program under
|
110 |
-
these conditions, and telling the user how to view a copy of this
|
111 |
-
License. (Exception: if the Program itself is interactive but
|
112 |
-
does not normally print such an announcement, your work based on
|
113 |
-
the Program is not required to print an announcement.)
|
114 |
-
|
115 |
-
These requirements apply to the modified work as a whole. If
|
116 |
-
identifiable sections of that work are not derived from the Program,
|
117 |
-
and can be reasonably considered independent and separate works in
|
118 |
-
themselves, then this License, and its terms, do not apply to those
|
119 |
-
sections when you distribute them as separate works. But when you
|
120 |
-
distribute the same sections as part of a whole which is a work based
|
121 |
-
on the Program, the distribution of the whole must be on the terms of
|
122 |
-
this License, whose permissions for other licensees extend to the
|
123 |
-
entire whole, and thus to each and every part regardless of who wrote it.
|
124 |
-
Thus, it is not the intent of this section to claim rights or contest
|
125 |
-
your rights to work written entirely by you; rather, the intent is to
|
126 |
-
exercise the right to control the distribution of derivative or
|
127 |
-
collective works based on the Program.
|
128 |
-
|
129 |
-
In addition, mere aggregation of another work not based on the Program
|
130 |
-
with the Program (or with a work based on the Program) on a volume of
|
131 |
-
a storage or distribution medium does not bring the other work under
|
132 |
-
the scope of this License.
|
133 |
-
|
134 |
-
3. You may copy and distribute the Program (or a work based on it,
|
135 |
-
under Section 2) in object code or executable form under the terms of
|
136 |
-
Sections 1 and 2 above provided that you also do one of the following:
|
137 |
-
|
138 |
-
a) Accompany it with the complete corresponding machine-readable
|
139 |
-
source code, which must be distributed under the terms of Sections
|
140 |
-
1 and 2 above on a medium customarily used for software interchange; or,
|
141 |
-
|
142 |
-
b) Accompany it with a written offer, valid for at least three
|
143 |
-
years, to give any third party, for a charge no more than your
|
144 |
-
cost of physically performing source distribution, a complete
|
145 |
-
machine-readable copy of the corresponding source code, to be
|
146 |
-
distributed under the terms of Sections 1 and 2 above on a medium
|
147 |
-
customarily used for software interchange; or,
|
148 |
-
|
149 |
-
c) Accompany it with the information you received as to the offer
|
150 |
-
to distribute corresponding source code. (This alternative is
|
151 |
-
allowed only for noncommercial distribution and only if you
|
152 |
-
received the program in object code or executable form with such
|
153 |
-
an offer, in accord with Subsection b above.)
|
154 |
-
|
155 |
-
The source code for a work means the preferred form of the work for
|
156 |
-
making modifications to it. For an executable work, complete source
|
157 |
-
code means all the source code for all modules it contains, plus any
|
158 |
-
associated interface definition files, plus the scripts used to
|
159 |
-
control compilation and installation of the executable. However, as a
|
160 |
-
special exception, the source code distributed need not include
|
161 |
-
anything that is normally distributed (in either source or binary
|
162 |
-
form) with the major components (compiler, kernel, and so on) of the
|
163 |
-
operating system on which the executable runs, unless that component
|
164 |
-
itself accompanies the executable.
|
165 |
-
|
166 |
-
If distribution of executable or object code is made by offering
|
167 |
-
access to copy from a designated place, then offering equivalent
|
168 |
-
access to copy the source code from the same place counts as
|
169 |
-
distribution of the source code, even though third parties are not
|
170 |
-
compelled to copy the source along with the object code.
|
171 |
-
|
172 |
-
4. You may not copy, modify, sublicense, or distribute the Program
|
173 |
-
except as expressly provided under this License. Any attempt
|
174 |
-
otherwise to copy, modify, sublicense or distribute the Program is
|
175 |
-
void, and will automatically terminate your rights under this License.
|
176 |
-
However, parties who have received copies, or rights, from you under
|
177 |
-
this License will not have their licenses terminated so long as such
|
178 |
-
parties remain in full compliance.
|
179 |
-
|
180 |
-
5. You are not required to accept this License, since you have not
|
181 |
-
signed it. However, nothing else grants you permission to modify or
|
182 |
-
distribute the Program or its derivative works. These actions are
|
183 |
-
prohibited by law if you do not accept this License. Therefore, by
|
184 |
-
modifying or distributing the Program (or any work based on the
|
185 |
-
Program), you indicate your acceptance of this License to do so, and
|
186 |
-
all its terms and conditions for copying, distributing or modifying
|
187 |
-
the Program or works based on it.
|
188 |
-
|
189 |
-
6. Each time you redistribute the Program (or any work based on the
|
190 |
-
Program), the recipient automatically receives a license from the
|
191 |
-
original licensor to copy, distribute or modify the Program subject to
|
192 |
-
these terms and conditions. You may not impose any further
|
193 |
-
restrictions on the recipients' exercise of the rights granted herein.
|
194 |
-
You are not responsible for enforcing compliance by third parties to
|
195 |
-
this License.
|
196 |
-
|
197 |
-
7. If, as a consequence of a court judgment or allegation of patent
|
198 |
-
infringement or for any other reason (not limited to patent issues),
|
199 |
-
conditions are imposed on you (whether by court order, agreement or
|
200 |
-
otherwise) that contradict the conditions of this License, they do not
|
201 |
-
excuse you from the conditions of this License. If you cannot
|
202 |
-
distribute so as to satisfy simultaneously your obligations under this
|
203 |
-
License and any other pertinent obligations, then as a consequence you
|
204 |
-
may not distribute the Program at all. For example, if a patent
|
205 |
-
license would not permit royalty-free redistribution of the Program by
|
206 |
-
all those who receive copies directly or indirectly through you, then
|
207 |
-
the only way you could satisfy both it and this License would be to
|
208 |
-
refrain entirely from distribution of the Program.
|
209 |
-
|
210 |
-
If any portion of this section is held invalid or unenforceable under
|
211 |
-
any particular circumstance, the balance of the section is intended to
|
212 |
-
apply and the section as a whole is intended to apply in other
|
213 |
-
circumstances.
|
214 |
-
|
215 |
-
It is not the purpose of this section to induce you to infringe any
|
216 |
-
patents or other property right claims or to contest validity of any
|
217 |
-
such claims; this section has the sole purpose of protecting the
|
218 |
-
integrity of the free software distribution system, which is
|
219 |
-
implemented by public license practices. Many people have made
|
220 |
-
generous contributions to the wide range of software distributed
|
221 |
-
through that system in reliance on consistent application of that
|
222 |
-
system; it is up to the author/donor to decide if he or she is willing
|
223 |
-
to distribute software through any other system and a licensee cannot
|
224 |
-
impose that choice.
|
225 |
-
|
226 |
-
This section is intended to make thoroughly clear what is believed to
|
227 |
-
be a consequence of the rest of this License.
|
228 |
-
|
229 |
-
8. If the distribution and/or use of the Program is restricted in
|
230 |
-
certain countries either by patents or by copyrighted interfaces, the
|
231 |
-
original copyright holder who places the Program under this License
|
232 |
-
may add an explicit geographical distribution limitation excluding
|
233 |
-
those countries, so that distribution is permitted only in or among
|
234 |
-
countries not thus excluded. In such case, this License incorporates
|
235 |
-
the limitation as if written in the body of this License.
|
236 |
-
|
237 |
-
9. The Free Software Foundation may publish revised and/or new versions
|
238 |
-
of the General Public License from time to time. Such new versions will
|
239 |
-
be similar in spirit to the present version, but may differ in detail to
|
240 |
-
address new problems or concerns.
|
241 |
-
|
242 |
-
Each version is given a distinguishing version number. If the Program
|
243 |
-
specifies a version number of this License which applies to it and "any
|
244 |
-
later version", you have the option of following the terms and conditions
|
245 |
-
either of that version or of any later version published by the Free
|
246 |
-
Software Foundation. If the Program does not specify a version number of
|
247 |
-
this License, you may choose any version ever published by the Free Software
|
248 |
-
Foundation.
|
249 |
-
|
250 |
-
10. If you wish to incorporate parts of the Program into other free
|
251 |
-
programs whose distribution conditions are different, write to the author
|
252 |
-
to ask for permission. For software which is copyrighted by the Free
|
253 |
-
Software Foundation, write to the Free Software Foundation; we sometimes
|
254 |
-
make exceptions for this. Our decision will be guided by the two goals
|
255 |
-
of preserving the free status of all derivatives of our free software and
|
256 |
-
of promoting the sharing and reuse of software generally.
|
257 |
-
|
258 |
-
NO WARRANTY
|
259 |
-
|
260 |
-
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
261 |
-
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
262 |
-
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
263 |
-
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
264 |
-
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
265 |
-
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
266 |
-
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
267 |
-
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
268 |
-
REPAIR OR CORRECTION.
|
269 |
-
|
270 |
-
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
271 |
-
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
272 |
-
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
273 |
-
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
274 |
-
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
275 |
-
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
276 |
-
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
277 |
-
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
278 |
-
POSSIBILITY OF SUCH DAMAGES.
|
279 |
-
|
280 |
-
END OF TERMS AND CONDITIONS
|
281 |
-
|
1 |
+
GNU GENERAL PUBLIC LICENSE
|
2 |
+
Version 2, June 1991
|
3 |
+
|
4 |
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
5 |
+
51 Franklin St, Fifth Floor, Boston, MA 02110, USA
|
6 |
+
|
7 |
+
Everyone is permitted to copy and distribute verbatim copies
|
8 |
+
of this license document, but changing it is not allowed.
|
9 |
+
|
10 |
+
Preamble
|
11 |
+
|
12 |
+
The licenses for most software are designed to take away your
|
13 |
+
freedom to share and change it. By contrast, the GNU General Public
|
14 |
+
License is intended to guarantee your freedom to share and change free
|
15 |
+
software--to make sure the software is free for all its users. This
|
16 |
+
General Public License applies to most of the Free Software
|
17 |
+
Foundation's software and to any other program whose authors commit to
|
18 |
+
using it. (Some other Free Software Foundation software is covered by
|
19 |
+
the GNU Library General Public License instead.) You can apply it to
|
20 |
+
your programs, too.
|
21 |
+
|
22 |
+
When we speak of free software, we are referring to freedom, not
|
23 |
+
price. Our General Public Licenses are designed to make sure that you
|
24 |
+
have the freedom to distribute copies of free software (and charge for
|
25 |
+
this service if you wish), that you receive source code or can get it
|
26 |
+
if you want it, that you can change the software or use pieces of it
|
27 |
+
in new free programs; and that you know you can do these things.
|
28 |
+
|
29 |
+
To protect your rights, we need to make restrictions that forbid
|
30 |
+
anyone to deny you these rights or to ask you to surrender the rights.
|
31 |
+
These restrictions translate to certain responsibilities for you if you
|
32 |
+
distribute copies of the software, or if you modify it.
|
33 |
+
|
34 |
+
For example, if you distribute copies of such a program, whether
|
35 |
+
gratis or for a fee, you must give the recipients all the rights that
|
36 |
+
you have. You must make sure that they, too, receive or can get the
|
37 |
+
source code. And you must show them these terms so they know their
|
38 |
+
rights.
|
39 |
+
|
40 |
+
We protect your rights with two steps: (1) copyright the software, and
|
41 |
+
(2) offer you this license which gives you legal permission to copy,
|
42 |
+
distribute and/or modify the software.
|
43 |
+
|
44 |
+
Also, for each author's protection and ours, we want to make certain
|
45 |
+
that everyone understands that there is no warranty for this free
|
46 |
+
software. If the software is modified by someone else and passed on, we
|
47 |
+
want its recipients to know that what they have is not the original, so
|
48 |
+
that any problems introduced by others will not reflect on the original
|
49 |
+
authors' reputations.
|
50 |
+
|
51 |
+
Finally, any free program is threatened constantly by software
|
52 |
+
patents. We wish to avoid the danger that redistributors of a free
|
53 |
+
program will individually obtain patent licenses, in effect making the
|
54 |
+
program proprietary. To prevent this, we have made it clear that any
|
55 |
+
patent must be licensed for everyone's free use or not licensed at all.
|
56 |
+
|
57 |
+
The precise terms and conditions for copying, distribution and
|
58 |
+
modification follow.
|
59 |
+
|
60 |
+
GNU GENERAL PUBLIC LICENSE
|
61 |
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
62 |
+
|
63 |
+
0. This License applies to any program or other work which contains
|
64 |
+
a notice placed by the copyright holder saying it may be distributed
|
65 |
+
under the terms of this General Public License. The "Program", below,
|
66 |
+
refers to any such program or work, and a "work based on the Program"
|
67 |
+
means either the Program or any derivative work under copyright law:
|
68 |
+
that is to say, a work containing the Program or a portion of it,
|
69 |
+
either verbatim or with modifications and/or translated into another
|
70 |
+
language. (Hereinafter, translation is included without limitation in
|
71 |
+
the term "modification".) Each licensee is addressed as "you".
|
72 |
+
|
73 |
+
Activities other than copying, distribution and modification are not
|
74 |
+
covered by this License; they are outside its scope. The act of
|
75 |
+
running the Program is not restricted, and the output from the Program
|
76 |
+
is covered only if its contents constitute a work based on the
|
77 |
+
Program (independent of having been made by running the Program).
|
78 |
+
Whether that is true depends on what the Program does.
|
79 |
+
|
80 |
+
1. You may copy and distribute verbatim copies of the Program's
|
81 |
+
source code as you receive it, in any medium, provided that you
|
82 |
+
conspicuously and appropriately publish on each copy an appropriate
|
83 |
+
copyright notice and disclaimer of warranty; keep intact all the
|
84 |
+
notices that refer to this License and to the absence of any warranty;
|
85 |
+
and give any other recipients of the Program a copy of this License
|
86 |
+
along with the Program.
|
87 |
+
|
88 |
+
You may charge a fee for the physical act of transferring a copy, and
|
89 |
+
you may at your option offer warranty protection in exchange for a fee.
|
90 |
+
|
91 |
+
2. You may modify your copy or copies of the Program or any portion
|
92 |
+
of it, thus forming a work based on the Program, and copy and
|
93 |
+
distribute such modifications or work under the terms of Section 1
|
94 |
+
above, provided that you also meet all of these conditions:
|
95 |
+
|
96 |
+
a) You must cause the modified files to carry prominent notices
|
97 |
+
stating that you changed the files and the date of any change.
|
98 |
+
|
99 |
+
b) You must cause any work that you distribute or publish, that in
|
100 |
+
whole or in part contains or is derived from the Program or any
|
101 |
+
part thereof, to be licensed as a whole at no charge to all third
|
102 |
+
parties under the terms of this License.
|
103 |
+
|
104 |
+
c) If the modified program normally reads commands interactively
|
105 |
+
when run, you must cause it, when started running for such
|
106 |
+
interactive use in the most ordinary way, to print or display an
|
107 |
+
announcement including an appropriate copyright notice and a
|
108 |
+
notice that there is no warranty (or else, saying that you provide
|
109 |
+
a warranty) and that users may redistribute the program under
|
110 |
+
these conditions, and telling the user how to view a copy of this
|
111 |
+
License. (Exception: if the Program itself is interactive but
|
112 |
+
does not normally print such an announcement, your work based on
|
113 |
+
the Program is not required to print an announcement.)
|
114 |
+
|
115 |
+
These requirements apply to the modified work as a whole. If
|
116 |
+
identifiable sections of that work are not derived from the Program,
|
117 |
+
and can be reasonably considered independent and separate works in
|
118 |
+
themselves, then this License, and its terms, do not apply to those
|
119 |
+
sections when you distribute them as separate works. But when you
|
120 |
+
distribute the same sections as part of a whole which is a work based
|
121 |
+
on the Program, the distribution of the whole must be on the terms of
|
122 |
+
this License, whose permissions for other licensees extend to the
|
123 |
+
entire whole, and thus to each and every part regardless of who wrote it.
|
124 |
+
Thus, it is not the intent of this section to claim rights or contest
|
125 |
+
your rights to work written entirely by you; rather, the intent is to
|
126 |
+
exercise the right to control the distribution of derivative or
|
127 |
+
collective works based on the Program.
|
128 |
+
|
129 |
+
In addition, mere aggregation of another work not based on the Program
|
130 |
+
with the Program (or with a work based on the Program) on a volume of
|
131 |
+
a storage or distribution medium does not bring the other work under
|
132 |
+
the scope of this License.
|
133 |
+
|
134 |
+
3. You may copy and distribute the Program (or a work based on it,
|
135 |
+
under Section 2) in object code or executable form under the terms of
|
136 |
+
Sections 1 and 2 above provided that you also do one of the following:
|
137 |
+
|
138 |
+
a) Accompany it with the complete corresponding machine-readable
|
139 |
+
source code, which must be distributed under the terms of Sections
|
140 |
+
1 and 2 above on a medium customarily used for software interchange; or,
|
141 |
+
|
142 |
+
b) Accompany it with a written offer, valid for at least three
|
143 |
+
years, to give any third party, for a charge no more than your
|
144 |
+
cost of physically performing source distribution, a complete
|
145 |
+
machine-readable copy of the corresponding source code, to be
|
146 |
+
distributed under the terms of Sections 1 and 2 above on a medium
|
147 |
+
customarily used for software interchange; or,
|
148 |
+
|
149 |
+
c) Accompany it with the information you received as to the offer
|
150 |
+
to distribute corresponding source code. (This alternative is
|
151 |
+
allowed only for noncommercial distribution and only if you
|
152 |
+
received the program in object code or executable form with such
|
153 |
+
an offer, in accord with Subsection b above.)
|
154 |
+
|
155 |
+
The source code for a work means the preferred form of the work for
|
156 |
+
making modifications to it. For an executable work, complete source
|
157 |
+
code means all the source code for all modules it contains, plus any
|
158 |
+
associated interface definition files, plus the scripts used to
|
159 |
+
control compilation and installation of the executable. However, as a
|
160 |
+
special exception, the source code distributed need not include
|
161 |
+
anything that is normally distributed (in either source or binary
|
162 |
+
form) with the major components (compiler, kernel, and so on) of the
|
163 |
+
operating system on which the executable runs, unless that component
|
164 |
+
itself accompanies the executable.
|
165 |
+
|
166 |
+
If distribution of executable or object code is made by offering
|
167 |
+
access to copy from a designated place, then offering equivalent
|
168 |
+
access to copy the source code from the same place counts as
|
169 |
+
distribution of the source code, even though third parties are not
|
170 |
+
compelled to copy the source along with the object code.
|
171 |
+
|
172 |
+
4. You may not copy, modify, sublicense, or distribute the Program
|
173 |
+
except as expressly provided under this License. Any attempt
|
174 |
+
otherwise to copy, modify, sublicense or distribute the Program is
|
175 |
+
void, and will automatically terminate your rights under this License.
|
176 |
+
However, parties who have received copies, or rights, from you under
|
177 |
+
this License will not have their licenses terminated so long as such
|
178 |
+
parties remain in full compliance.
|
179 |
+
|
180 |
+
5. You are not required to accept this License, since you have not
|
181 |
+
signed it. However, nothing else grants you permission to modify or
|
182 |
+
distribute the Program or its derivative works. These actions are
|
183 |
+
prohibited by law if you do not accept this License. Therefore, by
|
184 |
+
modifying or distributing the Program (or any work based on the
|
185 |
+
Program), you indicate your acceptance of this License to do so, and
|
186 |
+
all its terms and conditions for copying, distributing or modifying
|
187 |
+
the Program or works based on it.
|
188 |
+
|
189 |
+
6. Each time you redistribute the Program (or any work based on the
|
190 |
+
Program), the recipient automatically receives a license from the
|
191 |
+
original licensor to copy, distribute or modify the Program subject to
|
192 |
+
these terms and conditions. You may not impose any further
|
193 |
+
restrictions on the recipients' exercise of the rights granted herein.
|
194 |
+
You are not responsible for enforcing compliance by third parties to
|
195 |
+
this License.
|
196 |
+
|
197 |
+
7. If, as a consequence of a court judgment or allegation of patent
|
198 |
+
infringement or for any other reason (not limited to patent issues),
|
199 |
+
conditions are imposed on you (whether by court order, agreement or
|
200 |
+
otherwise) that contradict the conditions of this License, they do not
|
201 |
+
excuse you from the conditions of this License. If you cannot
|
202 |
+
distribute so as to satisfy simultaneously your obligations under this
|
203 |
+
License and any other pertinent obligations, then as a consequence you
|
204 |
+
may not distribute the Program at all. For example, if a patent
|
205 |
+
license would not permit royalty-free redistribution of the Program by
|
206 |
+
all those who receive copies directly or indirectly through you, then
|
207 |
+
the only way you could satisfy both it and this License would be to
|
208 |
+
refrain entirely from distribution of the Program.
|
209 |
+
|
210 |
+
If any portion of this section is held invalid or unenforceable under
|
211 |
+
any particular circumstance, the balance of the section is intended to
|
212 |
+
apply and the section as a whole is intended to apply in other
|
213 |
+
circumstances.
|
214 |
+
|
215 |
+
It is not the purpose of this section to induce you to infringe any
|
216 |
+
patents or other property right claims or to contest validity of any
|
217 |
+
such claims; this section has the sole purpose of protecting the
|
218 |
+
integrity of the free software distribution system, which is
|
219 |
+
implemented by public license practices. Many people have made
|
220 |
+
generous contributions to the wide range of software distributed
|
221 |
+
through that system in reliance on consistent application of that
|
222 |
+
system; it is up to the author/donor to decide if he or she is willing
|
223 |
+
to distribute software through any other system and a licensee cannot
|
224 |
+
impose that choice.
|
225 |
+
|
226 |
+
This section is intended to make thoroughly clear what is believed to
|
227 |
+
be a consequence of the rest of this License.
|
228 |
+
|
229 |
+
8. If the distribution and/or use of the Program is restricted in
|
230 |
+
certain countries either by patents or by copyrighted interfaces, the
|
231 |
+
original copyright holder who places the Program under this License
|
232 |
+
may add an explicit geographical distribution limitation excluding
|
233 |
+
those countries, so that distribution is permitted only in or among
|
234 |
+
countries not thus excluded. In such case, this License incorporates
|
235 |
+
the limitation as if written in the body of this License.
|
236 |
+
|
237 |
+
9. The Free Software Foundation may publish revised and/or new versions
|
238 |
+
of the General Public License from time to time. Such new versions will
|
239 |
+
be similar in spirit to the present version, but may differ in detail to
|
240 |
+
address new problems or concerns.
|
241 |
+
|
242 |
+
Each version is given a distinguishing version number. If the Program
|
243 |
+
specifies a version number of this License which applies to it and "any
|
244 |
+
later version", you have the option of following the terms and conditions
|
245 |
+
either of that version or of any later version published by the Free
|
246 |
+
Software Foundation. If the Program does not specify a version number of
|
247 |
+
this License, you may choose any version ever published by the Free Software
|
248 |
+
Foundation.
|
249 |
+
|
250 |
+
10. If you wish to incorporate parts of the Program into other free
|
251 |
+
programs whose distribution conditions are different, write to the author
|
252 |
+
to ask for permission. For software which is copyrighted by the Free
|
253 |
+
Software Foundation, write to the Free Software Foundation; we sometimes
|
254 |
+
make exceptions for this. Our decision will be guided by the two goals
|
255 |
+
of preserving the free status of all derivatives of our free software and
|
256 |
+
of promoting the sharing and reuse of software generally.
|
257 |
+
|
258 |
+
NO WARRANTY
|
259 |
+
|
260 |
+
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
261 |
+
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
262 |
+
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
263 |
+
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
264 |
+
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
265 |
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
266 |
+
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
267 |
+
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
268 |
+
REPAIR OR CORRECTION.
|
269 |
+
|
270 |
+
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
271 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
272 |
+
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
273 |
+
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
274 |
+
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
275 |
+
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
276 |
+
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
277 |
+
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
278 |
+
POSSIBILITY OF SUCH DAMAGES.
|
279 |
+
|
280 |
+
END OF TERMS AND CONDITIONS
|
281 |
+
|
scripts-n-styles.php
CHANGED
@@ -1,142 +1,316 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: Scripts n Styles
|
4 |
-
Plugin URI: http://www.unfocus.com/projects/scripts-n-styles/
|
5 |
-
Description: Allows WordPress admin users the ability to add custom CSS and JavaScript directly to individual Post, Pages or custom post types.
|
6 |
-
Author: unFocus Projects
|
7 |
-
Author URI: http://www.unfocus.com/
|
8 |
-
Version:
|
9 |
-
License: GPL2
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
?>
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Scripts n Styles
|
4 |
+
Plugin URI: http://www.unfocus.com/projects/scripts-n-styles/
|
5 |
+
Description: Allows WordPress admin users the ability to add custom CSS and JavaScript directly to individual Post, Pages or custom post types.
|
6 |
+
Author: unFocus Projects
|
7 |
+
Author URI: http://www.unfocus.com/
|
8 |
+
Version: 2
|
9 |
+
License: GPL2
|
10 |
+
Network: true
|
11 |
+
*/
|
12 |
+
/* Copyright 2010-2011 Kenneth Newman www.unfocus.com
|
13 |
+
|
14 |
+
This program is free software; you can redistribute it and/or modify
|
15 |
+
it under the terms of the GNU General Public License, version 2, as
|
16 |
+
published by the Free Software Foundation.
|
17 |
+
|
18 |
+
This program is distributed in the hope that it will be useful,
|
19 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
GNU General Public License for more details.
|
22 |
+
|
23 |
+
You should have received a copy of the GNU General Public License
|
24 |
+
along with this program; if not, write to the Free Software
|
25 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Scripts n Styles
|
30 |
+
*
|
31 |
+
* Allows WordPress admin users the ability to add custom CSS
|
32 |
+
* and JavaScript directly to individual Post, Pages or custom
|
33 |
+
* post types.
|
34 |
+
*
|
35 |
+
* NOTE: No user except the "Super Admin" can use this plugin in MultiSite. I'll add features for MultiSite later, perhaps the ones below...
|
36 |
+
* The "Super Admin" user has exclusive 'unfiltered_html' capabilities in MultiSite. Also, options.php checks for is_super_admin()
|
37 |
+
* so the 'manage_options' capability for blog admins is insufficient to pass the check to manage options directly.
|
38 |
+
*
|
39 |
+
* The Tentative plan is for Super Admins to create Snippets or Shortcodes approved for use by users with certain capabilities
|
40 |
+
* ('unfiltered_html' and/or 'manage_options'). The 'unfiltered_html' capability can be granted via another plugin. This plugin will
|
41 |
+
* not deal with granting any capabilities.
|
42 |
+
*
|
43 |
+
* @package Scripts_n_Styles
|
44 |
+
* @link http://www.unfocus.com/projects/scripts-n-styles/ Plugin URI
|
45 |
+
* @author unFocus Projects
|
46 |
+
* @link http://www.unfocus.com/ Author URI
|
47 |
+
* @version 2
|
48 |
+
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
49 |
+
* @copyright Copyright (c) 2010, Kenneth Newman
|
50 |
+
* @todo Add Post Type Selection on Options Page? Not sure that's usefull.
|
51 |
+
* @todo Add Conditional Tags support as alternative to Globally applying Scripts n Styles.
|
52 |
+
* @todo Create ability to add and register scripts and styles for enqueueing (via Options page).
|
53 |
+
* @todo Create selection on Option page of which to pick registered scripts to make available on edit screens.
|
54 |
+
* @todo Create shortcode to embed html/javascript snippets. See http://scribu.net/wordpress/optimal-script-loading.html in which this is already figured out :-)
|
55 |
+
* @todo Create shortcode registration on Options page to make those snippets available on edit screens.
|
56 |
+
* @todo Create shortcode registration of html snippets on edit screens for single use.
|
57 |
+
* @todo Figure out and add Error messaging.
|
58 |
+
* @todo Add ability to push class names into the TinyMCE editor Style Dropdown.
|
59 |
+
* @todo Replace Multi-Select element with something better.
|
60 |
+
* @todo Clean up Usage Table, paginate, don't display when empty.
|
61 |
+
* @todo "Include Scripts" will be reintroduced when registing is finished.
|
62 |
+
*/
|
63 |
+
|
64 |
+
class Scripts_n_Styles
|
65 |
+
{
|
66 |
+
/**#@+
|
67 |
+
* @static
|
68 |
+
*/
|
69 |
+
static $file = __FILE__;
|
70 |
+
static $hook_suffix; // 'tools_page_Scripts-n-Styles';
|
71 |
+
static $plugin_file; // 'scripts-n-styles/scripts-n-styles.php'; kept here for reference
|
72 |
+
/**#@-*/
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Initializing method. Checks if is_admin() and registers action hooks for admin if true. Sets filters and actions for Theme side functions.
|
76 |
+
* @static
|
77 |
+
*/
|
78 |
+
static function init() {
|
79 |
+
|
80 |
+
if ( is_admin() && ! ( defined('DISALLOW_UNFILTERED_HTML') && DISALLOW_UNFILTERED_HTML ) ) {
|
81 |
+
/* NOTE: Setting the DISALLOW_UNFILTERED_HTML constant to
|
82 |
+
true in the wp-config.php would effectively disable this
|
83 |
+
plugin's admin because no user would have the capability.
|
84 |
+
*/
|
85 |
+
include_once( 'includes/class.SnS_Admin.php' );
|
86 |
+
SnS_Admin::init();
|
87 |
+
|
88 |
+
}
|
89 |
+
|
90 |
+
add_filter( 'body_class', array( __CLASS__, 'body_classes' ) );
|
91 |
+
add_filter( 'post_class', array( __CLASS__, 'post_classes' ) );
|
92 |
+
|
93 |
+
add_action( 'wp_head', array( __CLASS__, 'styles' ), 11 );
|
94 |
+
//add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ), 11 );
|
95 |
+
add_action( 'wp_head', array( __CLASS__, 'scripts_in_head' ), 11 );
|
96 |
+
add_action( 'wp_footer', array( __CLASS__, 'scripts' ), 11 );
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Utility Method: Returns the value of $scripts if it is set, and if not, sets it via a call to the database.
|
101 |
+
* @return array 'ufp_script' meta data entry.
|
102 |
+
*/
|
103 |
+
static function get_scripts() {
|
104 |
+
global $post;
|
105 |
+
return get_post_meta( $post->ID, 'uFp_scripts', true );
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Utility Method: Returns the value of $styles if it is set, and if not, sets it via a call to the database.
|
110 |
+
* @return array 'ufp_styles' meta data entry.
|
111 |
+
*/
|
112 |
+
static function get_styles() {
|
113 |
+
global $post;
|
114 |
+
return get_post_meta( $post->ID, 'uFp_styles', true );
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Utility Method
|
119 |
+
*/
|
120 |
+
static function get_wp_registered() {
|
121 |
+
return array(
|
122 |
+
// Starting with the list of Scripts registered by default on the Theme side (index page of twentyten).
|
123 |
+
// This list should be trimmed down, as some probably aren't apporpriate for Theme enqueueing.
|
124 |
+
'l10n',
|
125 |
+
'utils',
|
126 |
+
'common',
|
127 |
+
'sack',
|
128 |
+
'quicktags',
|
129 |
+
'colorpicker',
|
130 |
+
'editor',
|
131 |
+
'prototype',
|
132 |
+
'wp-ajax-response',
|
133 |
+
'autosave',
|
134 |
+
'wp-lists',
|
135 |
+
'scriptaculous-root',
|
136 |
+
'scriptaculous-builder',
|
137 |
+
'scriptaculous-dragdrop',
|
138 |
+
'scriptaculous-effects',
|
139 |
+
'scriptaculous-slider',
|
140 |
+
'scriptaculous-sound',
|
141 |
+
'scriptaculous-controls',
|
142 |
+
'scriptaculous',
|
143 |
+
'cropper',
|
144 |
+
'jquery',
|
145 |
+
'jquery-ui-core',
|
146 |
+
'jquery-ui-position',
|
147 |
+
'jquery-ui-widget',
|
148 |
+
'jquery-ui-mouse',
|
149 |
+
'jquery-ui-button',
|
150 |
+
'jquery-ui-tabs',
|
151 |
+
'jquery-ui-sortable',
|
152 |
+
'jquery-ui-draggable',
|
153 |
+
'jquery-ui-droppable',
|
154 |
+
'jquery-ui-selectable',
|
155 |
+
'jquery-ui-resizable',
|
156 |
+
'jquery-ui-dialog',
|
157 |
+
'jquery-form',
|
158 |
+
'jquery-color',
|
159 |
+
'suggest',
|
160 |
+
'schedule',
|
161 |
+
'jquery-query',
|
162 |
+
'jquery-serialize-object',
|
163 |
+
'jquery-hotkeys',
|
164 |
+
'jquery-table-hotkeys',
|
165 |
+
'thickbox',
|
166 |
+
'jcrop',
|
167 |
+
'swfobject',
|
168 |
+
'swfupload',
|
169 |
+
'swfupload-swfobject',
|
170 |
+
'swfupload-queue',
|
171 |
+
'swfupload-speed',
|
172 |
+
'swfupload-all',
|
173 |
+
'swfupload-handlers',
|
174 |
+
'comment-reply',
|
175 |
+
'json2',
|
176 |
+
'imgareaselect',
|
177 |
+
'password-strength-meter',
|
178 |
+
'user-profile',
|
179 |
+
'admin-bar',
|
180 |
+
'wplink',
|
181 |
+
'wpdialogs-popup'
|
182 |
+
);
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Theme Action: 'wp_head()'
|
187 |
+
* Outputs the globally and individually set Styles in the Theme's head element.
|
188 |
+
*/
|
189 |
+
static function styles() {
|
190 |
+
// Global
|
191 |
+
$options = get_option( 'SnS_options' );
|
192 |
+
if ( ! empty( $options ) && ! empty( $options[ 'styles' ] ) ) {
|
193 |
+
?><style type="text/css"><?php
|
194 |
+
echo $options[ 'styles' ];
|
195 |
+
?></style><?php
|
196 |
+
}
|
197 |
+
|
198 |
+
if ( ! is_singular() ) return;
|
199 |
+
// Individual
|
200 |
+
$styles = self::get_styles();
|
201 |
+
if ( ! empty( $styles ) && ! empty( $styles[ 'styles' ] ) ) {
|
202 |
+
?><style type="text/css"><?php
|
203 |
+
echo $styles[ 'styles' ];
|
204 |
+
?></style><?php
|
205 |
+
}
|
206 |
+
}
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Theme Action: 'wp_footer()'
|
210 |
+
* Outputs the globally and individually set Scripts at the end of the Theme's body element.
|
211 |
+
*/
|
212 |
+
static function scripts() {
|
213 |
+
// Global
|
214 |
+
$options = get_option( 'SnS_options' );
|
215 |
+
if ( ! empty( $options ) && ! empty( $options[ 'scripts' ] ) ) {
|
216 |
+
?><script type="text/javascript"><?php
|
217 |
+
echo $options[ 'scripts' ];
|
218 |
+
?></script><?php
|
219 |
+
}
|
220 |
+
|
221 |
+
if ( ! is_singular() ) return;
|
222 |
+
// Individual
|
223 |
+
$scripts = self::get_scripts();
|
224 |
+
if ( ! empty( $scripts ) && ! empty( $scripts[ 'scripts' ] ) ) {
|
225 |
+
?><script type="text/javascript"><?php
|
226 |
+
echo $scripts[ 'scripts' ];
|
227 |
+
?></script><?php
|
228 |
+
}
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Theme Action: 'wp_head()'
|
233 |
+
* Outputs the globally and individually set Scripts in the Theme's head element.
|
234 |
+
*/
|
235 |
+
static function scripts_in_head() {
|
236 |
+
// Global
|
237 |
+
$options = get_option( 'SnS_options' );
|
238 |
+
if ( ! empty( $options ) && ! empty($options[ 'scripts_in_head' ]) ) {
|
239 |
+
?><script type="text/javascript"><?php
|
240 |
+
echo $options[ 'scripts_in_head' ];
|
241 |
+
?></script><?php
|
242 |
+
}
|
243 |
+
|
244 |
+
if ( ! is_singular() ) return;
|
245 |
+
// Individual
|
246 |
+
$scripts = self::get_scripts();
|
247 |
+
if ( ! empty( $scripts ) && ! empty( $scripts[ 'scripts_in_head' ] ) ) {
|
248 |
+
?><script type="text/javascript"><?php
|
249 |
+
echo $scripts[ 'scripts_in_head' ];
|
250 |
+
?></script><?php
|
251 |
+
}
|
252 |
+
}
|
253 |
+
|
254 |
+
/**
|
255 |
+
* Theme Filter: 'body_class()'
|
256 |
+
* Adds classes to the Theme's body tag.
|
257 |
+
* @uses self::get_styles()
|
258 |
+
* @param array $classes
|
259 |
+
* @return array $classes
|
260 |
+
*/
|
261 |
+
static function body_classes( $classes ) {
|
262 |
+
if ( ! is_singular() ) return $classes;
|
263 |
+
|
264 |
+
$styles = self::get_styles();
|
265 |
+
if ( ! empty( $styles ) && ! empty( $styles[ 'classes_body' ] ) )
|
266 |
+
$classes = array_merge( $classes, explode( " ", $styles[ 'classes_body' ] ) );
|
267 |
+
|
268 |
+
return $classes;
|
269 |
+
}
|
270 |
+
|
271 |
+
/**
|
272 |
+
* Theme Filter: 'post_class()'
|
273 |
+
* Adds classes to the Theme's post container.
|
274 |
+
* @uses self::get_styles()
|
275 |
+
* @param array $classes
|
276 |
+
* @return array $classes
|
277 |
+
*/
|
278 |
+
static function post_classes( $classes ) {
|
279 |
+
if ( ! is_singular() ) return $classes;
|
280 |
+
|
281 |
+
$styles = self::get_styles();
|
282 |
+
if ( ! empty( $styles ) && ! empty( $styles[ 'classes_post' ] ) )
|
283 |
+
$classes = array_merge( $classes, explode( " ", $styles[ 'classes_post' ] ) );
|
284 |
+
|
285 |
+
return $classes;
|
286 |
+
}
|
287 |
+
|
288 |
+
/**
|
289 |
+
* Theme Action: 'wp_enqueue_scripts'
|
290 |
+
* Enqueues chosen Scripts.
|
291 |
+
* @uses self::get_enqueue()
|
292 |
+
* @uses self::get_scripts()
|
293 |
+
*/
|
294 |
+
static function enqueue_scripts() {
|
295 |
+
// Global
|
296 |
+
$enqueue_scripts = get_option( 'SnS_enqueue_scripts' );
|
297 |
+
|
298 |
+
if ( is_array( $enqueue_scripts ) ) {
|
299 |
+
foreach ( $enqueue_scripts as $handle )
|
300 |
+
wp_enqueue_script( $handle );
|
301 |
+
}
|
302 |
+
|
303 |
+
if ( ! is_singular() ) return;
|
304 |
+
// Individual
|
305 |
+
$scripts = self::get_scripts();
|
306 |
+
if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) {
|
307 |
+
foreach ( $scripts[ 'enqueue_scripts' ] as $handle )
|
308 |
+
wp_enqueue_script( $handle );
|
309 |
+
}
|
310 |
+
}
|
311 |
+
|
312 |
+
}
|
313 |
+
|
314 |
+
Scripts_n_Styles::init();
|
315 |
+
|
316 |
?>
|
uninstall.php
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
-
<?php
|
2 |
-
if( !defined( 'ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') )
|
3 |
-
exit();
|
4 |
-
$get_posts_args = array('numberposts' => -1,
|
5 |
-
'post_type' => 'any',
|
6 |
-
'post_status' => 'any' );
|
7 |
-
$all_posts = get_posts( $get_posts_args );
|
8 |
-
foreach( $all_posts as $postinfo) {
|
9 |
-
delete_post_meta($postinfo->ID, 'uFp_scripts');
|
10 |
-
delete_post_meta($postinfo->ID, 'uFp_styles');
|
11 |
-
}
|
|
|
|
|
12 |
?>
|
1 |
+
<?php
|
2 |
+
if( !defined( 'ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') )
|
3 |
+
exit();
|
4 |
+
$get_posts_args = array('numberposts' => -1,
|
5 |
+
'post_type' => 'any',
|
6 |
+
'post_status' => 'any' );
|
7 |
+
$all_posts = get_posts( $get_posts_args );
|
8 |
+
foreach( $all_posts as $postinfo) {
|
9 |
+
delete_post_meta($postinfo->ID, 'uFp_scripts');
|
10 |
+
delete_post_meta($postinfo->ID, 'uFp_styles');
|
11 |
+
}
|
12 |
+
delete_option('sns_options');
|
13 |
+
delete_option('sns_enqueue_scripts');
|
14 |
?>
|