changeset 47:139e4b8ffb17

Fix display of js code and copy-pastability of displayed code
author Jordi Gutiérrez Hermoso <jordigh@gmail.com>
date Sat, 31 Jul 2010 23:16:23 -0500
parents b7c1c22fdfe8
children 329a9d17be88
files static/snippet_details.js templates/base.djhtml templates/snippet/snippet_details.djhtml templates/snippet/snippet_details.js
diffstat 4 files changed, 80 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/static/snippet_details.js	Sat Jul 31 19:17:11 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,71 +0,0 @@
-
-jQuery(document).ready(function(){
-
-    curLine = document.location.hash;
-    if(curLine.substring(0,2) == '#l'){
-        $('div.snippet div.line'+curLine).addClass('marked');
-    }
-
-    $("div.accordion").accordion({
-       autoHeight: false,
-       header: 'h2',
-       animation: 'bounceslide',
-       duration: 2000,
-    });
-
-    /**
-    * Diff Ajax Call
-    */
-    $("form#diffform").submit(function() {
-        $.get("{% url snippet_diff %}", {
-            a: $("input[name=a]:checked").val(),
-            b: $("input[name=b]:checked").val()
-        }, function(data){
-            $('#diff').djhtml(data).slideDown('fast');
-        });
-        return false;
-    });
-
-    /**
-    * Wordwrap
-    */
-    $('#toggleWordwrap').toggle(
-        function(){
-            $('div.snippet pre.code').css('white-space', 'pre-wrap');
-            return false;
-        },
-        function(){
-            $('div.snippet pre.code').css('white-space', 'pre');
-            return false;
-        }
-    );
-
-    /**
-    * Line Highlighting
-    */
-    $('div.snippet th a').each(function(i){
-        $(this).click(function(){
-            var j = $(this).text();
-            $('div.snippet div.line.marked').removeClass('marked');
-            $('div.snippet div.line#l'+j).toggleClass('marked');
-        });
-    });
-
-    //{% if request.session.userprefs.display_all_lexer %}
-    /**
-    * Lexer Guessing
-    */
-    $('#guess_lexer_btn').click(function(){
-        $.getJSON('{% url snippet_guess_lexer %}',
-            {'codestring': $('#id_content').val()},
-            function(data){
-                if(data.lexer == "unknown"){
-                    $('#guess_lexer_btn').css('color', 'red');
-                }else{
-                    $('#id_lexer').val(data.lexer);
-                    $('#guess_lexer_btn').css('color', 'inherit');
-                }
-            });
-    });
-    //{% endif %}
-});
\ No newline at end of file
--- a/templates/base.djhtml	Sat Jul 31 19:17:11 2010 -0500
+++ b/templates/base.djhtml	Sat Jul 31 23:16:23 2010 -0500
@@ -75,6 +75,8 @@
       <a href="http://www.gnu.org/software/octave/acknowledgments.html">
         John W. Eaton and others</a> unless otherwise noted.
     </p>
+    {% block script_footer %}
+    {% endblock %}
   </div>
   <!-- END #footer -->
   </body>
--- a/templates/snippet/snippet_details.djhtml	Sat Jul 31 19:17:11 2010 -0500
+++ b/templates/snippet/snippet_details.djhtml	Sat Jul 31 23:16:23 2010 -0500
@@ -82,18 +82,14 @@
       <table>
         <tr>
           <th>
-            <pre class="code">
-              {% for l in lines %}
-              <a href="#l{{ forloop.counter }}" 
-                 id="l{{ forloop.counter }}">
-                {{ forloop.counter }}
-              </a>
-              {% endfor %}
-            </pre>
+            {# this has to look like this due to the pre tags #}
+            <pre class="code">{% for l in lines %}<a href="#l{{ forloop.counter }}" id="l{{ forloop.counter }}">{{ forloop.counter }}</a> 
+{% endfor %}</pre>
           </th>
           <td>
             {# this has to look like this due to the pre tags #}
-            <pre class="code">{% for line in snippet.content_splitted %}<div class="line" id="l{{ forloop.counter }}">{% if line %} {{ line|safe }} {% else %} &nbsp; {% endif %}</div>{% endfor %}</pre>
+            <pre class="code">{% for line in snippet.content_splitted %}<span class="line" id="l{{ forloop.counter }}">{% if line %}{{ line|safe }}{% else %}&nbsp;{% endif %}</span>
+{% endfor %}</pre>
           </td>
         </tr>
       </table>
@@ -101,7 +97,7 @@
   </div>
 
   <h2>{% trans "Write an answer" %} &rarr;</h2>
-  <div class="container" style="display: none;">
+  <div class="accordion" style="display: none;">
     {% include "snippet/snippet_form.djhtml" %}
   </div>
 </div>
@@ -169,6 +165,6 @@
 <script src="/static/jquery.min.js"></script>
 <script src="/static/jquery-ui.min.js"></script>
 <script type="text/javascript">
-  {% include "snippet/snippet_details.js" %}
+{%include "snippet/snippet_details.js" %}
 </script>
 {% endblock script_footer %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/snippet/snippet_details.js	Sat Jul 31 23:16:23 2010 -0500
@@ -0,0 +1,71 @@
+
+jQuery(document).ready(function(){
+
+    curLine = document.location.hash;
+    if(curLine.substring(0,2) == '#l'){
+        $('div.snippet div.line'+curLine).addClass('marked');
+    }
+
+    $("div.accordion").accordion({
+       autoHeight: false,
+       header: 'h2',
+       animation: 'bounceslide',
+       duration: 2000,
+    });
+
+    /**
+    * Diff Ajax Call
+    */
+    $("form#diffform").submit(function() {
+        $.get("{% url snippet_diff %}", {
+            a: $("input[name=a]:checked").val(),
+            b: $("input[name=b]:checked").val()
+        }, function(data){
+            $('#diff').djhtml(data).slideDown('fast');
+        });
+        return false;
+    });
+
+    /**
+    * Wordwrap
+    */
+    $('#toggleWordwrap').toggle(
+        function(){
+            $('div.snippet pre.code').css('white-space', 'pre-wrap');
+            return false;
+        },
+        function(){
+            $('div.snippet pre.code').css('white-space', 'pre');
+            return false;
+        }
+    );
+
+    /**
+    * Line Highlighting
+    */
+    $('div.snippet th a').each(function(i){
+        $(this).click(function(){
+            var j = $(this).text();
+            $('div.snippet div.line.marked').removeClass('marked');
+            $('div.snippet div.line#l'+j).toggleClass('marked');
+        });
+    });
+
+    //{% if request.session.userprefs.display_all_lexer %}
+    /**
+    * Lexer Guessing
+    */
+    $('#guess_lexer_btn').click(function(){
+        $.getJSON('{% url snippet_guess_lexer %}',
+            {'codestring': $('#id_content').val()},
+            function(data){
+                if(data.lexer == "unknown"){
+                    $('#guess_lexer_btn').css('color', 'red');
+                }else{
+                    $('#id_lexer').val(data.lexer);
+                    $('#guess_lexer_btn').css('color', 'inherit');
+                }
+            });
+    });
+    //{% endif %}
+});