Guest User

Untitled

a guest
Jan 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. (function(window) {
  2.  
  3. var
  4.  
  5. document = window.document,
  6. $ = window.jQuery,
  7. $document = $(document),
  8.  
  9. queue = {
  10. functions: [],
  11. add: function(fn) {
  12. if (fn && typeof fn === 'function') {
  13. queue.functions.push(fn);
  14. return queue.bindFn(fn, $document);
  15. }
  16. },
  17. bindFn: function(fn, $context) {
  18. return function() {
  19. Function.prototype.apply.call(fn, $context, []);
  20. };
  21. }
  22. },
  23.  
  24. alterImages = function() {
  25. $('img', this).each(function() {
  26. $(this).fadeTo(0, 0.5).after('<span>||||</span>')
  27. });
  28. },
  29.  
  30. alterPs = function() {
  31. $('p', this).each(function() {
  32. $(this).css('background', 'red').after('<hr/>');;
  33. });
  34. };
  35.  
  36. $(queue.add(alterImages));
  37. $(queue.add(alterPs));
  38.  
  39. /* =/ Later... /= */
  40.  
  41. $(function() {
  42. $('a.load-new-content').click(function() {
  43. var $target = $($(this).attr('href')),
  44. queueLength = queue.functions.length;
  45. $.ajax({
  46. url: 'new-content.html',
  47. success: function(data, textStatus, jqXHR) {
  48. $target.html(data);
  49. while (queueLength--) {
  50. queue.bindFn(queue.functions[queueLength], $target)();
  51. }
  52. }
  53. });
  54. return false;
  55. });
  56. });
  57.  
  58. })(window);
Add Comment
Please, Sign In to add comment