Sult

put in function?

May 11th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.77 KB | None | 0 0
  1. <script src="{% static 'js/handlebars-v3.0.3.js' %}"></script>
  2. {# content layout #}
  3. <script id="handlebarsTemplate" type="text/x-handlebars-template">
  4.     {% include some_string %}
  5. </script>
  6. <script>
  7. $(function(){
  8. var refresher = function () {
  9.     $.getJSON( "{% url some_json_url %}", function(obj) {
  10.         refresh_timer = obj.refresh_timer * 1000;
  11.         setTimeout(refresher, refresh_timer);
  12.         if (obj.content) {
  13.             // do shit with content and data
  14.             var source   = $("#handlebarsTemplate").html();
  15.             var template = Handlebars.compile(source);
  16.             var html    = template(obj.content);
  17.             $("#apiTemplate").replaceWith(html);
  18.         }
  19.     });
  20.   };
  21.   setTimeout(refresher, 300); // 0.3 seconds
  22. });
  23. </script>
Advertisement
Add Comment
Please, Sign In to add comment