Skip to content

Commit 4ab2368

Browse files
author
Philipp
committed
Additional buttons added
1 parent 41c318a commit 4ab2368

File tree

4 files changed

+78
-4
lines changed

4 files changed

+78
-4
lines changed

example.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!doctype html>
2+
3+
<title>CodeMirror: Autoresize Demo</title>
4+
<meta charset="utf-8"/>
5+
6+
<link rel="stylesheet" href="bower_components/codemirror/lib/codemirror.css">
7+
<script src="bower_components/codemirror/lib/codemirror.js"></script>
8+
<script src="bower_components/codemirror/mode/css/css.js"></script>
9+
<style type="text/css">
10+
.CodeMirror {
11+
border: 1px solid #eee;
12+
height: auto;
13+
}
14+
</style>
15+
16+
17+
<article>
18+
<h2>Autoresize Demo</h2>
19+
<form><textarea id="code" name="code">
20+
.CodeMirror {
21+
border: 1px solid #eee;
22+
height: auto;
23+
}
24+
</textarea></form>
25+
26+
<script>
27+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
28+
lineNumbers: true,
29+
viewportMargin: Infinity
30+
});
31+
</script>
32+
33+
</article>

index.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
<link rel="stylesheet" href="bower_components/codemirror/lib/codemirror.css">
66
<script src="bower_components/codemirror/mode/xml/xml.js"></script>
77

8-
<script src="philsweb.jquery-codemirror.min.js"></script>
8+
<script src="philsweb.jquery-codemirror.js"></script>
99
<link rel="stylesheet" href="philsweb.codemirror.css">
1010

1111
<style>
12+
.CodeMirror {
13+
height: inherit;
14+
}
15+
1216
.code-snippet-group-1 {
1317
margin: 10px;
1418
width: 250px;
15-
height: 250px;
19+
height: 150px;
1620
border: 1px solid black;
1721
display: inline-block;
1822
}
@@ -23,6 +27,10 @@
2327
height: 250px;
2428
border: 1px solid black;
2529
}
30+
31+
.codemirror-buttons-wrapper {
32+
z-index: 100;
33+
}
2634
</style>
2735
</head>
2836

philsweb.codemirror.css

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1-
.CodeMirror {
2-
height: inherit;
1+
.codemirror-buttons-wrapper {
2+
position: relative;
3+
z-index: 9999; /* @todo Should be configured */
4+
display: none;
5+
}
6+
7+
.codemirror-buttons {
8+
position: absolute;
9+
width: 100%;
10+
background-color: rgba(255, 255, 255, .75);
11+
}
12+
13+
.codemirror-button {
14+
cursor: pointer;
15+
margin: 5px;
16+
float: right;
17+
}
18+
19+
.codemirror-button:hover {
20+
font-weight: bold;
321
}

philsweb.jquery-codemirror.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@
7878

7979
$.data(this, 'codemirror', CodeMirror(this, configs));
8080

81+
// Buttons
82+
var buttonsWrapper = $('<div>');
83+
var buttons = $('<div>');
84+
var copyToClipboardButton = $('<div>Copy to clipboard</div>');
85+
$(this).prepend(buttonsWrapper.addClass("codemirror-buttons-wrapper").append(
86+
buttons.addClass("codemirror-buttons").append(copyToClipboardButton.addClass("codemirror-button"))
87+
));
88+
89+
$(this).mouseenter(function () {
90+
$(this).children('.codemirror-buttons-wrapper').first().show();
91+
});
92+
93+
$(this).mouseleave(function () {
94+
$(this).children('.codemirror-buttons-wrapper').first().hide();
95+
});
8196
});
8297
};
8398

0 commit comments

Comments
 (0)