Advertisement
krot

ui dialog Maximize/Minimize button

Apr 10th, 2018
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 3.58 KB | None | 0 0
  1. $(function() {
  2.   function addButtons(dlg) {
  3.     // Define Buttons
  4.     var $close = dlg.find(".ui-dialog-titlebar-close");
  5.     var $min = $("<button>", {
  6.       class: "ui-button ui-corner-all ui-widget ui-button-icon-only ui-window-minimize",
  7.       type: "button",
  8.       title: "Minimize"
  9.     }).insertBefore($close);
  10.     $min.data("isMin", false);
  11.     $("<span>", {
  12.       class: "ui-button-icon ui-icon ui-icon-minusthick"
  13.     }).appendTo($min);
  14.     $("<span>", {
  15.       class: "ui-button-icon-space"
  16.     }).html(" ").appendTo($min);
  17.     var $max = $("<button>", {
  18.       class: "ui-button ui-corner-all ui-widget ui-button-icon-only ui-window-maximize",
  19.       type: "button",
  20.       title: "Maximize"
  21.     }).insertBefore($close);
  22.     $max.data("isMax", false);
  23.     $("<span>", {
  24.       class: "ui-button-icon ui-icon ui-icon-plusthick"
  25.     }).appendTo($max);
  26.     $("<span>", {
  27.       class: "ui-button-icon-space"
  28.     }).html(" ").appendTo($max);
  29.     // Define Function
  30.     $min.click(function(e) {
  31.       if ($min.data("isMin") === false) {
  32.         console.log("Minimize Window");
  33.         $min.data("original-pos", dlg.position());
  34.         $min.data("original-size", {
  35.           width: dlg.width(),
  36.           height: dlg.height()
  37.         });
  38.         $min.data("isMin", true);
  39.         dlg.animate({
  40.           height: '40px',
  41.           top: $(window).height() - 50
  42.         }, 200);
  43.         dlg.find(".ui-dialog-content").hide();
  44.       } else {
  45.         console.log("Restore Window");
  46.         $min.data("isMin", false);
  47.         dlg.find(".ui-dialog-content").show();
  48.         dlg.animate({
  49.           height: $min.data("original-size").height + "px",
  50.           top: $min.data("original-pos").top + "px"
  51.         }, 200);
  52.       }
  53.     });
  54.     $max.click(function(e) {
  55.       if ($max.data("isMax") === false) {
  56.         console.log("Maximize Window");
  57.         $max.data("original-pos", dlg.position());
  58.         $max.data("original-size", {
  59.           width: dlg.width(),
  60.           height: dlg.height()
  61.         });
  62.         $max.data("isMax", true);
  63.         dlg.animate({
  64.           height: $(window).height() + "px",
  65.           width: $(window).width() - 20 + "px",
  66.           top: 0,
  67.           left: 0
  68.         }, 200);
  69.       } else {
  70.         console.log("Restore Window");
  71.         $max.data("isMax", false);
  72.         dlg.animate({
  73.           height: $max.data("original-size").height + "px",
  74.           width: $max.data("original-size").width + "px",
  75.           top: $max.data("original-pos").top + "px",
  76.           left: $max.data("original-pos").top + "px"
  77.         }, 200);
  78.       }
  79.     });
  80.   }
  81.  
  82.   $('#window').dialog({
  83.     draggable: true,
  84.     autoOpen: true,
  85.     classes: {
  86.       "ui-dialog": "ui-window-options",
  87.       "ui-dialog-titlebar": "ui-window-bar"
  88.     },
  89.     modal: true,
  90.     responsive: true,
  91.   });
  92.  
  93.   addButtons($(".ui-window-options"));
  94.  
  95.   $("#winOpener").click(function() {
  96.     $("#window").dialog("open");
  97.   })
  98. });
  99.  
  100.  
  101. css
  102. .ui-window-bar .ui-button {
  103.   position: absolute;
  104.   top: 50%;
  105.   width: 20px;
  106.   margin: -10px 0 0 0;
  107.   padding: 1px;
  108.   height: 20px;
  109. }
  110.  
  111. .ui-window-bar .ui-window-minimize {
  112.   right: calc(.3em + 40px);
  113. }
  114.  
  115. .ui-window-bar .ui-window-maximize {
  116.   right: calc(.3em + 20px);
  117. }
  118.  
  119. html
  120. <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  121. <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  122. <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  123.  
  124. <a href="#" id="winOpener">Open Window</a>
  125.  
  126. <div id="window" title="Test Window">window</div>
  127.  
  128.  
  129. http://output.jsbin.com/ehagoy/154
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement