Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. var box = [];
  2. var $container = $("#container");
  3.  
  4. /** DragBox Init */
  5.  
  6. function DragBox(url, controller) {
  7. this.url = url;
  8. this.htmlcontent = "";
  9. this.controller = controller;
  10. this.test = "null";
  11.  
  12. this.requestContent = function() {
  13. $.get(this.url, null, function(res) {
  14. $container.append(res);
  15. });
  16. }
  17.  
  18. this.requestContent();
  19. $(this).attr("id", this.controller);
  20. $("#" + this.controller).hide().fadeIn(1000).draggable();
  21. }
  22.  
  23. var links = $("li a");
  24. for(var i = 0; i < links.length; i++) {
  25. links[i].onclick = function() {
  26. box.push(new DragBox($(this).attr("href"), $(this).attr("controller")));
  27. return false;
  28. }
  29. }
  30.  
  31. function DragBox(url) {
  32. // init stuff...
  33.  
  34. this.requestContent = function(callback) {
  35. $.get(url, function(res) {
  36. var $element = $(res);
  37. $element.appendTo($container);
  38. $element.hide();
  39. // The job is done, execute the code inside callback
  40. callback($element);
  41. });
  42. }
  43.  
  44. // Render the requested html content and make it draggable
  45. this.requestContent(function($element) {
  46. $element.fadeIn(1000).draggable();
  47. });
  48.  
  49. }
  50.  
  51. $(document).on('click', 'li a', function(e) {
  52. if ( /* some condition */ ) {
  53. var some_var = new DragBox(params);
  54. }
  55. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement