Skip to content

Commit

Permalink
Merge pull request #175 from sverweij/feature/accessibility-improvements
Browse files Browse the repository at this point in the history
Accessibility improvements (WCAG 2.0 AA)
  • Loading branch information
sverweij committed Aug 10, 2015
2 parents 051aff7 + 30e4ddd commit e1ac632
Show file tree
Hide file tree
Showing 16 changed files with 485 additions and 230 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ LIB_SOURCES_WEB=src/lib/codemirror/lib/codemirror.js \
src/lib/codemirror/addon/edit/closebrackets.js \
src/lib/codemirror/addon/edit/matchbrackets.js \
src/lib/codemirror/addon/display/placeholder.js \
src/lib/codemirror/addon/selection/active-line.js \
src/lib/codemirror/mode/mscgen/mscgen.js \
src/lib/codemirror/mode/javascript/javascript.js \
src/lib/canvg/canvg.js \
Expand Down Expand Up @@ -176,7 +177,7 @@ $(PRODDIRS):

src/style/interp.css: src/style/interp.scss \
src/lib/codemirror/_codemirror.scss \
src/lib/codemirror/theme/_midnight.scss \
src/lib/codemirror/theme/_blackboard.scss \
src/style/snippets/_interpreter.scss \
src/style/snippets/_anim.scss \
src/style/snippets/_header.scss \
Expand Down
339 changes: 169 additions & 170 deletions src/index.html

Large diffs are not rendered by default.

31 changes: 19 additions & 12 deletions src/lib/codemirror/_codemirror.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,22 @@
-webkit-animation: blink 1.06s steps(1) infinite;
-moz-animation: blink 1.06s steps(1) infinite;
animation: blink 1.06s steps(1) infinite;
background-color: #7e7;
}
@-moz-keyframes blink {
0% { background: #7e7; }
50% { background: none; }
100% { background: #7e7; }
0% {}
50% { background-color: transparent; }
100% {}
}
@-webkit-keyframes blink {
0% { background: #7e7; }
50% { background: none; }
100% { background: #7e7; }
0% {}
50% { background-color: transparent; }
100% {}
}
@keyframes blink {
0% { background: #7e7; }
50% { background: none; }
100% { background: #7e7; }
0% {}
50% { background-color: transparent; }
100% {}
}

/* Can style cursor different in overwrite (non-insert) mode */
Expand Down Expand Up @@ -202,7 +203,13 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
.CodeMirror-gutter-wrapper {
position: absolute;
z-index: 4;
height: 100%;
background: none !important;
border: none !important;
}
.CodeMirror-gutter-background {
position: absolute;
top: 0; bottom: 0;
z-index: 4;
}
.CodeMirror-gutter-elt {
position: absolute;
Expand Down Expand Up @@ -297,8 +304,8 @@ div.CodeMirror-cursors {
.CodeMirror-selected { background: #d9d9d9; }
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
.CodeMirror-crosshair { cursor: crosshair; }
.CodeMirror ::selection { background: #d7d4f0; }
.CodeMirror ::-moz-selection { background: #d7d4f0; }
.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }
.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; }

.cm-searching {
background: #ffa;
Expand Down
71 changes: 71 additions & 0 deletions src/lib/codemirror/addon/selection/active-line.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE

// Because sometimes you need to style the cursor's line.
//
// Adds an option 'styleActiveLine' which, when enabled, gives the
// active line's wrapping <div> the CSS class "CodeMirror-activeline",
// and gives its background <div> the class "CodeMirror-activeline-background".

(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var WRAP_CLASS = "CodeMirror-activeline";
var BACK_CLASS = "CodeMirror-activeline-background";

CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) {
var prev = old && old != CodeMirror.Init;
if (val && !prev) {
cm.state.activeLines = [];
updateActiveLines(cm, cm.listSelections());
cm.on("beforeSelectionChange", selectionChange);
} else if (!val && prev) {
cm.off("beforeSelectionChange", selectionChange);
clearActiveLines(cm);
delete cm.state.activeLines;
}
});

function clearActiveLines(cm) {
for (var i = 0; i < cm.state.activeLines.length; i++) {
cm.removeLineClass(cm.state.activeLines[i], "wrap", WRAP_CLASS);
cm.removeLineClass(cm.state.activeLines[i], "background", BACK_CLASS);
}
}

function sameArray(a, b) {
if (a.length != b.length) return false;
for (var i = 0; i < a.length; i++)
if (a[i] != b[i]) return false;
return true;
}

function updateActiveLines(cm, ranges) {
var active = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
if (!range.empty()) continue;
var line = cm.getLineHandleVisualStart(range.head.line);
if (active[active.length - 1] != line) active.push(line);
}
if (sameArray(cm.state.activeLines, active)) return;
cm.operation(function() {
clearActiveLines(cm);
for (var i = 0; i < active.length; i++) {
cm.addLineClass(active[i], "wrap", WRAP_CLASS);
cm.addLineClass(active[i], "background", BACK_CLASS);
}
cm.state.activeLines = active;
});
}

function selectionChange(cm, sel) {
updateActiveLines(cm, sel.ranges);
}
});
Loading

0 comments on commit e1ac632

Please sign in to comment.