Commits

Miki Tebeka committed 14c2bc4

Playing with JSONP

  • Participants
  • Parent commits fb02ded

Comments (0)

Files changed (2)

File highlight.js

     return options;
 }
 
-function highlight() {
-    var obj = $('.highlight');
+function highlight(obj) {
+    obj = $(obj);
     var options = get_options(obj.attr('class'));
     options['code'] = obj.text();
-    obj.load("http://localhost:8080/pygmentize", options);
+    options['callback'] = '?'; /* JSONP */
+    function handler(html) {
+        obj.html(html);
+    }
+    $.get("http://localhost:8080/pygmentize", options, handler);
 }
 
 function on_ready() {
     var url = '<link type="text/css" href="http://localhost:8080/highlight.css" ' +
               'rel="stylesheet" />'
     $('head').append($(url))
-    highlight();
+    $('.highlight').each(function (i, o) { highlight(o); });
 }
 
 $(document).ready(on_ready);
         linenos = kw.get("linenos", 0)
 
         formatter = HtmlFormatter(linenos=linenos, cssclass="source")
-        return highlight(code, lexer, formatter)
+        reply = highlight(code, lexer, formatter)
+        callback = kw.get("callback", None)
+        if callback:
+            print "CALLBACK: %s" % callback
+            reply = "%s(%s)" % (callback, reply)
+        return reply
 
     @expose(alias="highlight.css")
     @tools.response_headers(headers=[("Content-Type", "text/css")])