Guest User

Untitled

a guest
Apr 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. // A dead-simple implementation of ESI:include.
  2. // Replaces all <esi:include> elements with the contents of the response to
  3. // their <tt>src</tt> attribute.
  4. //
  5. // Given: <esi:include src="/dingo" />
  6. // Requests: GET /dingo
  7. // Receives: "<div>wah wah</div>"
  8. // Replaces esi:include with that.
  9. $.fn.esiIncludeFetch = function() {
  10. var self = this;
  11. jQuery.ajax({
  12. url: self.attr("src"),
  13. type: "GET",
  14. dataType: "html",
  15. complete: function(res, status){
  16. if (status == "success" || status == "notmodified") {
  17. self.replaceWith(res.responseText);
  18. }
  19. }
  20. });
  21. return this;
  22. };
  23.  
  24. $(function(){
  25. includeElements = document.getElementsByTagName("include");
  26. for (i = 0; i < includeElements.length; i++) {
  27. $(includeElements[i]).esiIncludeFetch();
  28. }
  29.  
  30. includeElements = document.getElementsByTagName("esi:include");
  31. for (i = 0; i < includeElements.length; i++) {
  32. $(includeElements[i]).esiIncludeFetch();
  33. }
  34. });
Add Comment
Please, Sign In to add comment