Skip to content

Commit a97fc71

Browse files
author
ethitter
committed
Jetpack Custom CSS: replace Ace editor with Codemirror.
Codemirror is more compact and easier to customize to the needs of the CSS editor. Switching editors also resolves a number of long-standing bugs, such as inaccurate linting. Props mattwiebe.
1 parent 51930f4 commit a97fc71

File tree

16 files changed

+644
-8031
lines changed

16 files changed

+644
-8031
lines changed

modules/custom-css/custom-css.php

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,6 @@ static function menu() {
604604
$title = __( 'Edit CSS', 'jetpack' );
605605
$hook = add_theme_page( $title, $title, 'edit_theme_options', 'editcss', array( 'Jetpack_Custom_CSS', 'admin' ) );
606606

607-
add_action( "admin_head-$hook", array( 'Jetpack_Custom_CSS', 'admin_head' ) );
608607
add_action( "load-revision.php", array( 'Jetpack_Custom_CSS', 'prettify_post_revisions' ) );
609608
add_action( "load-$hook", array( 'Jetpack_Custom_CSS', 'update_title' ) );
610609
}
@@ -647,29 +646,11 @@ static function enqueue_scripts( $hook ) {
647646
wp_enqueue_style( 'custom-css-editor', plugins_url( 'custom-css/css/css-editor.css', __FILE__ ) );
648647

649648
if ( defined( 'SAFECSS_USE_ACE' ) && SAFECSS_USE_ACE ) {
650-
$url = plugins_url( 'custom-css/js/', __FILE__ );
649+
wp_register_style( 'jetpack-css-codemirror', plugins_url( 'custom-css/css/codemirror.css', __FILE__ ), array(), '20120905' );
650+
wp_enqueue_style( 'jetpack-css-use-codemirror', plugins_url( 'custom-css/css/use-codemirror.css', __FILE__ ), array( 'jetpack-css-codemirror' ), '20120905' );
651651

652-
wp_enqueue_script( 'jquery.spin' );
653-
wp_enqueue_script( 'safecss-ace', $url . 'ace/ace.js', array(), '20130213', true );
654-
wp_enqueue_script( 'safecss-ace-css', $url . 'ace/mode-css.js', array( 'safecss-ace' ), '20130213', true );
655-
wp_enqueue_script( 'safecss-ace-less', $url . 'ace/mode-less.js', array( 'safecss-ace' ), '20130213', true );
656-
wp_enqueue_script( 'safecss-ace-scss', $url . 'ace/mode-scss.js', array( 'safecss-ace' ), '20130213', true );
657-
wp_enqueue_script( 'safecss-ace-use', $url . 'safecss-ace.js', array( 'jquery', 'safecss-ace-css' ), '20130213', true );
658-
659-
wp_enqueue_style( 'custom-css-ace', plugins_url( 'custom-css/css/ace.css', __FILE__ ) );
660-
}
661-
}
662-
663-
static function admin_head() {
664-
if ( defined( 'SAFECSS_USE_ACE' ) && SAFECSS_USE_ACE ) {
665-
?>
666-
<script type="text/javascript">
667-
/*<![CDATA[*/
668-
var SAFECSS_USE_ACE = true;
669-
var safecssAceSrcPath = <?php echo json_encode( parse_url( plugins_url( 'custom-css/js/ace/', __FILE__ ), PHP_URL_PATH ) ); ?>;
670-
/*]]>*/
671-
</script>
672-
<?php
652+
wp_register_script( 'jetpack-css-codemirror', plugins_url( 'custom-css/js/codemirror.min.js', __FILE__ ), array(), '3.16', true );
653+
wp_enqueue_script( 'jetpack-css-use-codemirror', plugins_url( 'custom-css/js/use-codemirror.js', __FILE__ ), array( 'jquery', 'underscore', 'jetpack-css-codemirror' ), '20131009', true );
673654
}
674655
}
675656

@@ -703,18 +684,8 @@ static function admin() {
703684
<div id="post-body">
704685
<div id="post-body-content">
705686
<div class="postarea">
706-
<?php if ( defined( 'SAFECSS_USE_ACE' ) && SAFECSS_USE_ACE ) { ?>
707-
<div id="safecss-container">
708-
<div id="safecss-ace"></div>
709-
</div>
710-
<script type="text/javascript">
711-
jQuery.fn.spin && jQuery("#safecss-container").spin( 'large' );
712-
</script>
713-
<textarea id="safecss" name="safecss" class="hide-if-js"><?php echo esc_textarea( Jetpack_Custom_CSS::get_css() ); ?></textarea>
714-
<div class="clear"></div>
715-
<?php } else { ?>
716-
<p><textarea id="safecss" name="safecss"><?php echo str_replace('</textarea>', '&lt;/textarea&gt', Jetpack_Custom_CSS::get_css()); ?></textarea></p>
717-
<?php } ?>
687+
<textarea id="safecss" name="safecss"<?php if ( SAFECSS_USE_ACE ) echo ' class="hide-if-js"'; ?>><?php echo esc_textarea( Jetpack_Custom_CSS::get_css() ); ?></textarea>
688+
<div class="clear"></div>
718689
</div>
719690
</div>
720691
</div>

modules/custom-css/custom-css/css/ace.css

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
/* BASICS */
2+
.CodeMirror {
3+
/* Set height, width, borders, and global font properties here */
4+
font-family: monospace;
5+
height: 300px;
6+
}
7+
.CodeMirror-scroll {
8+
/* Set scrolling behaviour here */
9+
overflow: auto;
10+
}
11+
12+
/* PADDING */
13+
14+
.CodeMirror-lines {
15+
padding: 4px 0; /* Vertical padding around content */
16+
}
17+
.CodeMirror pre {
18+
padding: 0 4px; /* Horizontal padding of content */
19+
}
20+
21+
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
22+
background-color: white; /* The little square between H and V scrollbars */
23+
}
24+
25+
/* GUTTER */
26+
27+
.CodeMirror-gutters {
28+
border-right: 1px solid #ddd;
29+
background-color: #f7f7f7;
30+
white-space: nowrap;
31+
}
32+
.CodeMirror-linenumbers {}
33+
.CodeMirror-linenumber {
34+
padding: 0 3px 0 5px;
35+
min-width: 20px;
36+
text-align: right;
37+
color: #999;
38+
}
39+
40+
/* CURSOR */
41+
42+
.CodeMirror div.CodeMirror-cursor {
43+
border-left: 1px solid black;
44+
z-index: 3;
45+
}
46+
/* Shown when moving in bi-directional text */
47+
.CodeMirror div.CodeMirror-secondarycursor {
48+
border-left: 1px solid silver;
49+
}
50+
.CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursor {
51+
width: auto;
52+
border: 0;
53+
background: #7e7;
54+
z-index: 1;
55+
}
56+
/* Can style cursor different in overwrite (non-insert) mode */
57+
.CodeMirror div.CodeMirror-cursor.CodeMirror-overwrite {}
58+
59+
.cm-tab { display: inline-block; }
60+
61+
/* DEFAULT THEME */
62+
63+
.cm-s-default .cm-keyword {color: #708;}
64+
.cm-s-default .cm-atom {color: #219;}
65+
.cm-s-default .cm-number {color: #164;}
66+
.cm-s-default .cm-def {color: #00f;}
67+
.cm-s-default .cm-variable {color: black;}
68+
.cm-s-default .cm-variable-2 {color: #05a;}
69+
.cm-s-default .cm-variable-3 {color: #085;}
70+
.cm-s-default .cm-property {color: black;}
71+
.cm-s-default .cm-operator {color: black;}
72+
.cm-s-default .cm-comment {color: #a50;}
73+
.cm-s-default .cm-string {color: #a11;}
74+
.cm-s-default .cm-string-2 {color: #f50;}
75+
.cm-s-default .cm-meta {color: #555;}
76+
.cm-s-default .cm-error {color: #f00;}
77+
.cm-s-default .cm-qualifier {color: #555;}
78+
.cm-s-default .cm-builtin {color: #30a;}
79+
.cm-s-default .cm-bracket {color: #997;}
80+
.cm-s-default .cm-tag {color: #170;}
81+
.cm-s-default .cm-attribute {color: #00c;}
82+
.cm-s-default .cm-header {color: blue;}
83+
.cm-s-default .cm-quote {color: #090;}
84+
.cm-s-default .cm-hr {color: #999;}
85+
.cm-s-default .cm-link {color: #00c;}
86+
87+
.cm-negative {color: #d44;}
88+
.cm-positive {color: #292;}
89+
.cm-header, .cm-strong {font-weight: bold;}
90+
.cm-em {font-style: italic;}
91+
.cm-link {text-decoration: underline;}
92+
93+
.cm-invalidchar {color: #f00;}
94+
95+
div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
96+
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
97+
.CodeMirror-activeline-background {background: #e8f2ff;}
98+
99+
/* STOP */
100+
101+
/* The rest of this file contains styles related to the mechanics of
102+
the editor. You probably shouldn't touch them. */
103+
104+
.CodeMirror {
105+
line-height: 1;
106+
position: relative;
107+
overflow: hidden;
108+
background: white;
109+
color: black;
110+
}
111+
112+
.CodeMirror-scroll {
113+
/* 30px is the magic margin used to hide the element's real scrollbars */
114+
/* See overflow: hidden in .CodeMirror */
115+
margin-bottom: -30px; margin-right: -30px;
116+
padding-bottom: 30px; padding-right: 30px;
117+
height: 100%;
118+
outline: none; /* Prevent dragging from highlighting the element */
119+
position: relative;
120+
}
121+
.CodeMirror-sizer {
122+
position: relative;
123+
}
124+
125+
/* The fake, visible scrollbars. Used to force redraw during scrolling
126+
before actuall scrolling happens, thus preventing shaking and
127+
flickering artifacts. */
128+
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
129+
position: absolute;
130+
z-index: 6;
131+
display: none;
132+
}
133+
.CodeMirror-vscrollbar {
134+
right: 0; top: 0;
135+
overflow-x: hidden;
136+
overflow-y: scroll;
137+
}
138+
.CodeMirror-hscrollbar {
139+
bottom: 0; left: 0;
140+
overflow-y: hidden;
141+
overflow-x: scroll;
142+
}
143+
.CodeMirror-scrollbar-filler {
144+
right: 0; bottom: 0;
145+
}
146+
.CodeMirror-gutter-filler {
147+
left: 0; bottom: 0;
148+
}
149+
150+
.CodeMirror-gutters {
151+
position: absolute; left: 0; top: 0;
152+
padding-bottom: 30px;
153+
z-index: 3;
154+
}
155+
.CodeMirror-gutter {
156+
white-space: normal;
157+
height: 100%;
158+
padding-bottom: 30px;
159+
margin-bottom: -32px;
160+
display: inline-block;
161+
/* Hack to make IE7 behave */
162+
*zoom:1;
163+
*display:inline;
164+
}
165+
.CodeMirror-gutter-elt {
166+
position: absolute;
167+
cursor: default;
168+
z-index: 4;
169+
}
170+
171+
.CodeMirror-lines {
172+
cursor: text;
173+
}
174+
.CodeMirror pre {
175+
/* Reset some styles that the rest of the page might have set */
176+
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
177+
border-width: 0;
178+
background: transparent;
179+
font-family: inherit;
180+
font-size: inherit;
181+
margin: 0;
182+
white-space: pre;
183+
word-wrap: normal;
184+
line-height: inherit;
185+
color: inherit;
186+
z-index: 2;
187+
position: relative;
188+
overflow: visible;
189+
}
190+
.CodeMirror-wrap pre {
191+
word-wrap: break-word;
192+
white-space: pre-wrap;
193+
word-break: normal;
194+
}
195+
.CodeMirror-code pre {
196+
border-right: 30px solid transparent;
197+
width: -webkit-fit-content;
198+
width: -moz-fit-content;
199+
width: fit-content;
200+
}
201+
.CodeMirror-wrap .CodeMirror-code pre {
202+
border-right: none;
203+
width: auto;
204+
}
205+
.CodeMirror-linebackground {
206+
position: absolute;
207+
left: 0; right: 0; top: 0; bottom: 0;
208+
z-index: 0;
209+
}
210+
211+
.CodeMirror-linewidget {
212+
position: relative;
213+
z-index: 2;
214+
overflow: auto;
215+
}
216+
217+
.CodeMirror-widget {
218+
}
219+
220+
.CodeMirror-wrap .CodeMirror-scroll {
221+
overflow-x: hidden;
222+
}
223+
224+
.CodeMirror-measure {
225+
position: absolute;
226+
width: 100%; height: 0px;
227+
overflow: hidden;
228+
visibility: hidden;
229+
}
230+
.CodeMirror-measure pre { position: static; }
231+
232+
.CodeMirror div.CodeMirror-cursor {
233+
position: absolute;
234+
visibility: hidden;
235+
border-right: none;
236+
width: 0;
237+
}
238+
.CodeMirror-focused div.CodeMirror-cursor {
239+
visibility: visible;
240+
}
241+
242+
.CodeMirror-selected { background: #d9d9d9; }
243+
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
244+
245+
.cm-searching {
246+
background: #ffa;
247+
background: rgba(255, 255, 0, .4);
248+
}
249+
250+
/* IE7 hack to prevent it from returning funny offsetTops on the spans */
251+
.CodeMirror span { *vertical-align: text-bottom; }
252+
253+
@media print {
254+
/* Hide the cursor when printing */
255+
.CodeMirror div.CodeMirror-cursor {
256+
visibility: hidden;
257+
}
258+
}

0 commit comments

Comments
 (0)