changeset 138:4d358e1e3014

Add "highlight code" link, to easily select code
author dellsystem <ilostwaldo@gmail.com>
date Sat, 29 Sep 2012 18:03:35 -0400
parents 00c71a6192de
children b8e0bdc37e32
files static/js/agora.js templates/snippet/snippet_details.djhtml
diffstat 2 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/static/js/agora.js	Sat Sep 29 18:03:07 2012 -0400
+++ b/static/js/agora.js	Sat Sep 29 18:03:35 2012 -0400
@@ -19,6 +19,24 @@
         }
     };
 
+    // jQuery plugin for selecting text
+    $.fn.selectText = function () {
+        var element = this[0];
+        var range, selection;
+
+        if (document.body.createTextRange) {
+            range = document.body.createTextRange();
+            range.moveToElementText(element);
+            range.select();
+        } else if (window.getSelection) {
+            selection = window.getSelection();
+            range = document.createRange();
+            range.selectNodeContents(element);
+            selection.removeAllRanges();
+            selection.addRange(range);
+        }
+    };
+
     $(document).ready(function () {
         handleLoginLink();
 
@@ -34,5 +52,10 @@
                 $('.line-counters').append(div);
             });
         }
+
+        // Highlight the code when the link is clicked
+        $('.highlight-code-lines').click(function () {
+            $('.code-lines').selectText();
+        });
     });
 })(jQuery);
--- a/templates/snippet/snippet_details.djhtml	Sat Sep 29 18:03:07 2012 -0400
+++ b/templates/snippet/snippet_details.djhtml	Sat Sep 29 18:03:35 2012 -0400
@@ -72,6 +72,8 @@
             </option>
             {% endfor %}
         </select>
+        &mdash;
+        <a href="#" class="highlight-code-lines">Highlight code</a>
         <div>
             Author:
             {% if snippet.author %}