dwz.dialogDrag.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @author Roger Wu
  3. */
  4. (function($){
  5. $.fn.dialogDrag = function(options){
  6. if (typeof options == 'string') {
  7. if (options == 'destroy')
  8. return this.each(function() {
  9. var dialog = this;
  10. $("div.dialogHeader", dialog).unbind("mousedown");
  11. });
  12. }
  13. return this.each(function(){
  14. var dialog = $(this);
  15. $("div.dialogHeader", dialog).mousedown(function(e){
  16. $.pdialog.switchDialog(dialog);
  17. dialog.data("task",true);
  18. setTimeout(function(){
  19. if(dialog.data("task"))$.dialogDrag.start(dialog,e);
  20. },100);
  21. return false;
  22. }).mouseup(function(e){
  23. dialog.data("task",false);
  24. return false;
  25. });
  26. });
  27. };
  28. $.dialogDrag = {
  29. currId:null,
  30. _init:function(dialog) {
  31. this.currId = new Date().getTime();
  32. var shadow = $("#dialogProxy");
  33. if (!shadow.size()) {
  34. shadow = $(DWZ.frag["dialogProxy"]);
  35. $("body").append(shadow);
  36. }
  37. $("h1", shadow).html($(".dialogHeader h1", dialog).text());
  38. },
  39. start:function(dialog,event){
  40. this._init(dialog);
  41. var sh = $("#dialogProxy");
  42. sh.css({
  43. left: dialog.css("left"),
  44. top: dialog.css("top"),
  45. height: dialog.css("height"),
  46. width: dialog.css("width"),
  47. zIndex:parseInt(dialog.css("zIndex")) + 1
  48. }).show();
  49. $("div.dialogContent",sh).css("height",$("div.dialogContent",dialog).css("height"));
  50. sh.data("dialog",dialog);
  51. dialog.css({left:"-10000px",top:"-10000px"});
  52. $(".shadow").hide();
  53. $(sh).jDrag({
  54. selector:".dialogHeader",
  55. stop: this.stop,
  56. event:event
  57. });
  58. return false;
  59. },
  60. stop:function(){
  61. var sh = $(arguments[0]);
  62. var dialog = sh.data("dialog");
  63. $(dialog).css({left:$(sh).css("left"),top:$(sh).css("top")});
  64. $.pdialog.attachShadow(dialog);
  65. $(sh).hide();
  66. }
  67. }
  68. })(jQuery);