blob: 6488c73415e9ac03243dd1c6407027f27d0ad35e (
plain)
1
2
3
4
5
6
7
8
9
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
|
function getSelectionText(divID) {
var selectedText = "";
if (window.getSelection) {
var sel = window.getSelection();
var div = document.getElementById(divID);
if (sel.rangeCount) {
// Get the selected range
var range = sel.getRangeAt(0);
// Check that the selection is wholly contained within the div text
// if (range.commonAncestorContainer == div.firstChild) {
var selectedText = range.toString();
// }
}
}
return selectedText;
}
(function($) {
$(document).ready(function() {
$(".fix-caption-code").mousedown(function() {
$("#edit-caption").val("");
});
$(".fix-caption-code").mouseup(function() {
quotedText = getSelectionText("#fix-caption-code");
$("#edit-caption").val(quotedText);
});
$("#edit-example").mousedown(function() {
$("#edit-caption").val("");
});
$("#edit-example").mouseup(function() {
quotedText = $('option:selected', this).attr("data-exampleid");
$("#edit-caption").val(quotedText);
});
});
})(jQuery);
|