diff options
author | Jayaram Pai | 2014-04-29 08:38:53 +0530 |
---|---|---|
committer | Jayaram Pai | 2014-04-29 08:38:53 +0530 |
commit | bd2260b00a36b1565d67cee58fe38b84941f41b0 (patch) | |
tree | 11d20f7d370e7f293523201ae04e879ebf375a35 | |
parent | d236b5b5285579f3bfd8505dc2e3f71ea0323d8c (diff) | |
download | scilab_fixer-bd2260b00a36b1565d67cee58fe38b84941f41b0.tar.gz scilab_fixer-bd2260b00a36b1565d67cee58fe38b84941f41b0.tar.bz2 scilab_fixer-bd2260b00a36b1565d67cee58fe38b84941f41b0.zip |
added feature to auto populate caption on select code text
-rw-r--r-- | js/scilab_fixer.js | 1 | ||||
-rw-r--r-- | js/selection.js | 26 |
2 files changed, 27 insertions, 0 deletions
diff --git a/js/scilab_fixer.js b/js/scilab_fixer.js index ef05611..8236099 100644 --- a/js/scilab_fixer.js +++ b/js/scilab_fixer.js @@ -11,6 +11,7 @@ $(document).ready(function() { $form = $("#scilab-fixer-caption-form"); $updating = $("#fix-caption-page #updating"); $done = $("#fix-caption-page #done"); + $example.attr("multiple", "enabled"); function reset() { for (var i = 0, l = arguments.length; i < l; i ++) { diff --git a/js/selection.js b/js/selection.js new file mode 100644 index 0000000..fcb738b --- /dev/null +++ b/js/selection.js @@ -0,0 +1,26 @@ +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; +} +$(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); + }); +}); |