Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. <div id="modalDialog" class="messageBox autoclose" draggable="true">
  2. <div class="modal-header">
  3. //modal html
  4. </div>
  5. <div class="modal-body">
  6. //modal html
  7. </div>
  8. <div class="modal-footer">
  9. //modal html
  10. </div>
  11. </div>
  12.  
  13. self.deactivate = function () {
  14. //need to clear events since they will be added at next call
  15. document.ondrag = null;
  16. document.ondragend = null;
  17. };
  18. self.compositionComplete = function () {
  19. document.ondrag = StartDragging;
  20. document.ondragend = StopDragging;
  21. };
  22.  
  23. function StopDragging() {
  24. document.onmousemove = null;
  25. }
  26.  
  27. function StartDragging(e) {
  28. if (e == null)
  29. var e = window.event;
  30.  
  31. // this is the actual "drag code"
  32. modalLeft = e.clientX;
  33. modalTop = e.clientY;
  34.  
  35. $('#modalDialog').offset({
  36. top: modalTop,
  37. left: modalLeft
  38. });
  39. }
  40.  
  41. $(function() {
  42. $( "#draggable" ).draggable();
  43. });
  44.  
  45. $(function() {
  46. $( "#draggable" ).draggable();
  47. $( "#droppable" ).droppable({
  48. drop: function( event, ui ) {
  49. $( this )
  50. .addClass( "ui-state-highlight" )
  51. .find( "p" )
  52. .html( "Dropped!" );
  53. }
  54. });
  55. });
  56.  
  57. var draggingMyModal;
  58. var bodyX;
  59. var bodyY;
  60.  
  61. $(document.body).on('mousemove', function (e) {
  62. bodyX = (e.pageX) - ($('#myDialog .modal-header').width() / 2);
  63. bodyY = (e.pageY) - ($('#myDialog .modal-header').height() / 2);
  64. if (draggingMyModal) {
  65. draggingMyModal.offset({
  66. top: bodyY,
  67. left: bodyX
  68. });
  69. }
  70. });
  71.  
  72. $(document.body).on("mousedown", "#myDialog .modal-header", function (e) {
  73. draggingMyModal= $('#myDialog');
  74. });
  75.  
  76. $(document.body).on("mouseup", function (e) {
  77. draggingMyModal= null;
  78. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement