Browse Source

JS enchance only post contents

Ralfp 12 years ago
parent
commit
56930a0606

+ 30 - 26
static/cranefly/js/cranefly.js

@@ -54,38 +54,42 @@ $(function () {
 	$('.go-back').on('click', function (e) {
 	    history.go(-1)
 	})
+})
 
-	// Add labels to images
-	$('.markdown img').each(function() {
-    $(this).addClass('img-rounded');
-    $(this).wrap(function() { return '<div class="md-img" />'; });
-    $(this).wrap(function() { return '<div class="span5 md-img-span" />'; });
-    $(this).wrap(function() { return '<div class="md-img-wrap" />'; });
-    $(this).after('<a href="' + $(this).attr('src') + '" class="md-img-label" target="_blank">' + $(this).attr('alt') + '</a>');
-    $(this).wrap(function() { return '<div class="md-img-bg" />'; });
-	});
+function EnhancePostsMD() {
+	$(function () {
+		// Add labels to images
+		$('.markdown.js-extra img').each(function() {
+	    $(this).addClass('img-rounded');
+	    $(this).wrap(function() { return '<div class="md-img" />'; });
+	    $(this).wrap(function() { return '<div class="span5 md-img-span" />'; });
+	    $(this).wrap(function() { return '<div class="md-img-wrap" />'; });
+	    $(this).after('<a href="' + $(this).attr('src') + '" class="md-img-label" target="_blank">' + $(this).attr('alt') + '</a>');
+	    $(this).wrap(function() { return '<div class="md-img-bg" />'; });
+		});
 
-	// Handle prokened images
-  $('.markdown img').one('error', function() {
-  	$(this).after('<div class="md-img-error"><span>' + l_img_broken_msg + '</span></div>');
-  	$(this).hide();
-	});
+		// Handle prokened images
+	  $('.markdown.js-extra img').one('error', function() {
+	  	$(this).after('<div class="md-img-error"><span>' + l_img_broken_msg + '</span></div>');
+	  	$(this).hide();
+		});
 
-	// Automagically turn links into players
-	var players = new Array();
-	$('.markdown a').each(function() {
-		if (this.href == $.trim($(this).text())) {
-			match = link2player(this);
-			if (match && $.inArray(match, players) == -1) {
-				players.push(match);
-				$(this).replaceWith(match);
-				if (players.length == 10) {
-					return false;
+		// Automagically turn links into players
+		var players = new Array();
+		$('.markdown.js-extra a').each(function() {
+			if (this.href == $.trim($(this).text())) {
+				match = link2player(this);
+				if (match && $.inArray(match, players) == -1) {
+					players.push(match);
+					$(this).replaceWith(match);
+					if (players.length == 10) {
+						return false;
+					}
 				}
 			}
-		}
+		});
 	});
-})
+}
 
 // Turn link to player
 function link2player(link) {

+ 2 - 1
templates/cranefly/threads/posting.html

@@ -52,7 +52,7 @@
 
           {% if preview %}
           <div class="form-preview">
-            <div class="markdown">
+            <div class="markdown js-extra">
               {{ preview|markdown_final|safe }}
             </div>
           </div>
@@ -122,6 +122,7 @@
   <script type="text/javascript">
     hljs.tabReplace = '    ';
     hljs.initHighlightingOnLoad();
+    EnhancePostsMD();
   </script>
   {{ editor.js() }}
 {% endblock %}

+ 2 - 1
templates/cranefly/threads/thread.html

@@ -231,7 +231,7 @@
             </div>
           </div>
           <div class="post-message">
-            <div class="markdown">
+            <div class="markdown js-extra">
               {{ post.post_preparsed|markdown_final|safe }}
             </div>
             {% if post.user.signature %}
@@ -419,6 +419,7 @@
   <script type="text/javascript">
     hljs.tabReplace = '    ';
     hljs.initHighlightingOnLoad();
+    EnhancePostsMD();
     {%- if user.is_authenticated() %}
     $(function () {
       $('#thread_form').submit(function() {