Flyer53 / jsPanel

A jQuery Plugin to create highly configurable floating panels, modals, tooltips and hints/notifiers for use in a backend solution and other web applications.
http://v2.jspanel.de/
Other
163 stars 56 forks source link

Is there any way to hide a panel (not destroy) by click the close button ? #38

Closed kouennrin closed 9 years ago

kouennrin commented 9 years ago

How can I hide the panel (not destroy panel) by click the close button ? code like this:

            var jspanel = $.jsPanel({
                position: 'center',
                size: { width: 350, height: 180 },
                callback: function (panel) {
                    $('.jsPanel-btn-close', panel).click(function () {
                        panel.hide();
                    });
                }
            });

            var showPanel = function () {
                // Whether the panel is currently hide.
                if (jspanel.isHide()) {
                    // Show the panel again.
                    jspanel.show();
                }
            }
Flyer53 commented 9 years ago

Hi again, one note at first: Don't ever use the identifier jsPanel (and jspanel better not as well) as name for one of your variables since jsPanel is the one and only global variable in the jsPanel script.

Ok, now your request:

// assign your panel to a variable
var myPanel = $.jsPanel({
  position: "center",
  theme: "medium",
  // more config if needed ...
  callback: function(panel){
    // select close control
    $(".jsPanel-btn-close", panel)
         // remove the default handler from the close control
        .off()
         // bind a new handler to the close control
        .click(function(){ panel.hide() });
  }
});

// show the panel again
myPanel.show();

// if you, at one point, want the original close handler back:
$(".jsPanel-btn-close", myPanel)
  // remove the current handler from the close control
  .off()
  // bind original close handler to the close control again
  .click(function(){ jsPanel.close(myPanel) });
// the original close method is a method of the global jsPanel object and expects the panel to close/remove as argument
kouennrin commented 9 years ago

As you said, this issue is resolved. Thank you so much!