jsPanel是一个jQuery对话框和弹出式插件,用于在web项目上创建多功能、高度可配置、可主题化、可拖动和可调整大小的浮动面板(窗口)。
该插件可以用作模式窗口、对话框、工具提示,甚至可以用作提示
从4.0.0版本开始,jsPanel是用纯JavaScript编写的,删除所有依赖项。您可以在此处下载jsPanel 4。
1.在网页上包含jsPanel插件和其他所需资源。
<!-- Required --> <link rel="stylesheet" href="/path/to/source/jquery.jspanel.css" /> <script src="/path/to/cdn/jquery.min.js"></script> <script src="/path/to/source/jquery.jspanel-compiled.js"></script> <!-- OPTIONAL --> <link rel="stylesheet" href="/path/to/cdn/bootstrap.min.css" /> <link rel="stylesheet" href="/path/to/cdn/font-awesome.min.css" /> <script src="/path/to/cdn/jquery-ui.min.js"></script> <script src="/path/to/cdn/bootstrap.min.js"></script>
2.创建一个附加到body元素的基本浮动面板。
$.jsPanel();
3.覆盖默认选项,在页面上创建自己的浮动面板。
$.jsPanel({ // auto closes the panel after a timeout // sets a timeout here autoclose: false, // shows borders around the panel border: false, callback: false, // closes the panel by pressing ESC key closeOnEscape: false, // contaner element to hold the panel container: 'body', // any panel content here: // DOM element // array of elements // HTML string // jQuery object // function that returns an HTML string, DOM element(s) or jQuery object content: false, /* loads content via ajax: contentAjax: { url: 'url/to/load', autoload: true, autoresize: true, autoreposition: true } */ contentAjax: false, /*loads iframe content to the panel contentIframe: { width: 1200, height: 950, src: 'iframe.html', id: 'myID', classname: 'myClass', name: 'myFrame', style: {'border': '10px solid #000'} } */ contentIframe: false, // CSS overflow property contentOverflow: 'hidden', // content size contentSize: { width: 400, /* do not replace with "400 200" */ height: 200 }, // allows to set double-click handlers for header, content and footer dblclicks: false, // time to wait before closing the panel delayClose: 0, // jQuery UI draggable configs draggable: { handle: 'div.jsPanel-headerlogo, div.jsPanel-titlebar, div.jsPanel-ftr', opacity: 0.8 }, // built-in draggable configs dragit: { axis: false, containment: false, grid: false, handles: '.jsPanel-headerlogo, .jsPanel-titlebar, .jsPanel-ftr.active', // do not set .jsPanel-titlebar to .jsPanel-hdr opacity: 0.8, start: false, drag: false, stop: false, disable: false, disableui: false }, // jQuery UI resizable configs resizable: { handles: 'n, e, s, w, ne, se, sw, nw', autoHide: false, minWidth: 40, minHeight: 40 }, // built-in draggable configs resizeit: { containment: false, grid: false, handles: 'n, e, s, w, ne, se, sw, nw', minWidth: 40, minHeight: 40, maxWidth: 10000, maxHeight: 10000, start: false, resize: false, stop: false, disable: false, disableui: false }, // shows footer toolbar footerToolbar: false, // shows header controls headerControls: { close: false, maximize: false, minimize: false, normalize: false, smallify: false, controls: 'all', iconfont: 'jsglyph' }, // shows header logo headerLogo: false, // allows to remove the panel header headerRemove: false, // header title headerTitle: 'jsPanel', // shows header toolbar headerToolbar: false, // unique ID id: function id() { return "jsPanel-".concat(jsPanel.id += 1); }, // margins to maintain when maximized maximizedMargin: [5, 5, 5, 5], // change the default minimize behavior minimizeTo: true, // panel size panelSize: { width: 430, height: 270 } // 'modal', 'hint', 'tooltip' paneltype: false, // panel position /*{ my: 'center', at: 'center', of: 'window', minLeft: undefined, minTop: undefined, maxLeft: undefined, maxTop: undefined, offsetX: 0, offsetY: 0, modify: false, fixed: 'true', autoposition: false } position: 'center', // RTL mode rtl: false, // sets the panel to maximized, minimized after panel was created setstatus: false, // applies an animation to the panel when inserted into the document show: false, // your own template here template: false, // built-in themes: 'default', 'primary', 'info', 'success', 'warning' or 'danger' // Bootstrap themes: "bootstrap-default", "bootstrap-primary", "bootstrap-info", "bootstrap-success", "bootstrap-warning" and "bootstrap-danger" // or any colors theme: 'default' });
4.回调函数。
$.jsPanel({ // a function or an array of functions // fired after the jsPanel was inserted into the document. callback: false, // fired before the jsPanel is closed onbeforeclose: function (panel) { // do something }, // fired before the jsPanel is maximized onbeforemaximize: function (panel) { // do something }, // fired before the jsPanel is minimized onbeforeminimize: function (panel) { // do something }, // fired before the jsPanel is restored onbeforenormalize: function (panel) { // do something }, // fired before the jsPanel is smallified/unsmallified onbeforesmallify: function (panel) { // do something }, onbeforeunsmallify: function (panel) { // do something }, // fired before the jsPanel is resized onbeforeresize: function (panel) { // do something }, // fired after the jsPanel is closed onclosed: function (panel) { // do something }, // fired after the jsPanel is maximized onmaximized: function (panel) { // do something }, // fired after the jsPanel is minimized onminimized: function (panel) { // do something }, // fired after the jsPanel is restored onnormalized: function (panel) { // do something }, // fired after the jsPanel is resized onresized: function (panel) { // do something }, // fired after the jsPanel is smallified/unsmallified onsmallified: function (panel) { // do something }, onunsmallified: function (panel) { // do something }, // fired on window resize onwindowresize: false });
5.API方法。
// close the panel instance.close(); // close all child panels instance.closeChildpanels(); // reload content instance.contentReload(callback); // resize content instance.contentResize(callback); // enable/disable dragit interaction instance.dragit(); // bring the panel to the front instance.front(callback); // show/hide header controls instance.headerControl(control [, action]); // set/get header title instance.headerTitle(title); // maximize the panel instance.maximize(callback); // minimize the panel instance.minimize(callback) // restore the panel instance.normalize(callback); // re-position the panel instance.reposition(position, callback); // resize the panel instance.resize(width, height [, callback]); // enable/disable resizeit interaction instance.resizeit(); // change the theme instance.setTheme(theme, callback); // smallify the panel instance.smallify(callback); // add tootlbar instance.toolbarAdd(location, toolbar [, callback]);
1.在网页上包含jsPanel插件和其他所需资源。
<!-- Core Stylesheet --> <link rel="stylesheet" href="dist/jspanel.css"> <!-- Core JavaScript --> <script src="dist/jspanel.js"></script> <!-- optional extensions --> <!-- Context Menu --> <script src="dist/extensions/contextmenu/jspanel.contextmenu.js"></script> <!-- Date Picker --> <link rel="stylesheet" href="dist/extensions/datepicker/theme/default.css" /> <script src="dist/extensions/datepicker/jspanel.datepicker.js"></script> <!-- Dialog --> <link rel="stylesheet" href="dist/extensions/dialog/jspanel.dialog.css" /> <script src="dist/extensions/dialog/jspanel.dialog.js"></script> <!-- Dock --> <script src="dist/extensions/dock/jspanel.dock.js"></script> <!-- Hint --> <script src="dist/extensions/hint/jspanel.hint.js"></script> <!-- Layout --> <script src="dist/extensions/layout/jspanel.layout.js"></script> <!-- Modal --> <script src="dist/extensions/modal/jspanel.modal.js"></script> <!-- Tooltip --> <script src="dist/extensions/tooltip/jspanel.tooltip.js"></script>
2.或者将jsPanel作为ES模块导入。
// import main js import { jsPanel } from './es6module/jspanel.min.js'; // import extensions as needed import './es6module/extensions/contextmenu/jspanel.contextmenu.min.js'; import './es6module/extensions/datepicker/jspanel.datepicker.min.js'; import './es6module/extensions/dialog/jspanel.dialog.min.js'; import './es6module/extensions/dock/jspanel.dock.min.js'; import './es6module/extensions/hint/jspanel.hint.min.js'; import './es6module/extensions/layout/jspanel.layout.min.js'; import './es6module/extensions/modal/jspanel.modal.min.js'; import './es6module/extensions/tooltip/jspanel.tooltip.min.js';
3.创建一个基本面板。
jsPanel.create({ // options here });
4.使用以下选项自定义面板。
jsPanel.create({ // adds additional close control to the panel addCloseControl: false, // animations you want to use animateIn: 'jsPanelFadeIn' animateOut: 'jsPanelFadeOut' // auto closes the panel after a timeout // sets a timeout here autoclose: false, // shows borders around the panel border: false, // border radius borderRadius: 6, // box shadow of the panel boxShadow: 3, // closes the panel by pressing ESC key closeOnEscape: false, // configs here config: {}, // contaner element to hold the panel container: 'body', // any panel content here: // DOM element // array of elements // HTML string // jQuery object // function that returns an HTML string, DOM element(s) or jQuery object content: false, /* loads content via ajax: contentAjax: { url: 'url/to/load', autoload: true, autoresize: true, autoreposition: true } */ contentAjax: false, /*loads data via Fetch API contentFetch: { resource: 'content.html', bodyMethod: 'text', evalscripttags: true, autoresize: true, autoreposition: true, done: function (panel, response) { panel.content.innerHTML = response; }, beforeSend: function (panel) { // ... }, }, */ contentFetch: false, // CSS overflow property contentOverflow: 'hidden', // content size contentSize: { width: 400, /* do not replace with "400 200" */ height: 200 }, // stores optional custom data data: null, // built-in draggable configs dragit: { axis: false, containment: false, cursor: 'move', disable: false, disableOnMaximized: true, grid: false, // Snaps the panel to a grid, e.g. [10, 10] handles: '.jsPanel-headerlogo, .jsPanel-titlebar, .jsPanel-ftr.active', // do not set .jsPanel-titlebar to .jsPanel-hdr opacity: 0.8, start: false, // function(panel, paneldata, event) drag: false, // function(panel, paneldata, event) stop: false, // function(panel, paneldata, event) drop: false // {dropZones: ['.drop-demo .drop-target'], callback: function(panel, target, source) {...}} snap: { callback: (panel) => { // do something }, snapLeftTop: (panel) => { // or boolean }, snapCenterTop: (panel) => { // or boolean }, snapRightTop: (panel) => { // or boolean }, snapRightCenter: (panel) => { // or boolean }, snapRightBottom: (panel) => { // or boolean }, snapCenterBottom: (panel) => { // or boolean }, snapLeftBottom: (panel) => { // or boolean }, snapLeftCenter: (panel) => { // or boolean }, containment: true, repositionOnSnap: true, resizeToPreSnap: true, sensitivity: 70, trigger: 'panel', // or 'pointer' active: 'both', // or 'inside' } }, // shows footer toolbar footerToolbar: false, // shows header controls headerControls: { close: false, maximize: false, minimize: false, normalize: false, smallify: false, size: 'md', add: null // add custom controls here }, // shows header logo headerLogo: false, // allows to remove the panel header header: true, // header title headerTitle: 'jsPanel', // add a header toolbar // String, Array, Node or Function headerToolbar: false, // Iconic Font You Want To Use // String or Array iconfont: false, // unique ID id: function id() { return "jsPanel-".concat(jsPanel.id += 1); }, // margins to maintain when maximized maximizedMargin: [5, 5, 5, 5], // limits the dimensions of a maximized panel // e.g. maximizedMargin: [61, 5, 5, 5] maximizedMargin: 0, // change the default minimize behavior minimizeTo: true, // opacity opacity: undefined, // panel size panelSize: { width: 430, height: 270 } // 'standard', 'contextmenu', 'error' // 'hint', 'modal', 'tooltip' paneltype: false, // panel position /*{ my: 'center', at: 'center', of: 'window', minLeft: undefined, minTop: undefined, maxLeft: undefined, maxTop: undefined, offsetX: 0, offsetY: 0, modify: false, autoposition: false } position: 'center', // built-in resizable configs resizeit: { containment: false, aspectRatio: false, grid: false, handles: 'n, e, s, w, ne, se, sw, nw', minWidth: 40, minHeight: 40, maxWidth: 10000, maxHeight: 10000, start: false, resize: false, stop: false, disable: false, }, // RTL mode rtl: false, // 'maximized', 'minimized', 'smallified' or 'smallifiedmax' setstatus: false, // your own template here template: false, // sync 3 margin options syncMargins: false, // built-in themes: 'default', 'primary', 'secondary', 'info', 'success', 'warning', 'danger', 'light', 'dark' and 'none' // Bootstrap themes: "bootstrap-default", "bootstrap-primary", "bootstrap-info", "bootstrap-success", "bootstrap-warning" and "bootstrap-danger" // or any colors theme: 'default' });
5.回调函数。
jsPanel.create({ // a function or an array of functions // fired after the jsPanel was inserted into the document. callback: false, // fired before the jsPanel is closed onbeforeclose: function (panel, status, closedByUser) { // do something }, // fired before the jsPanel is maximized onbeforemaximize: function (panel, status) { // do something }, // fired before the jsPanel is minimized onbeforeminimize: function (panel, status) { // do something }, // fired before the jsPanel is restored onbeforenormalize: function (panel, status) { // do something }, // fired before the jsPanel is smallified/unsmallified onbeforesmallify: function (panel, status) { // do something }, onbeforeunsmallify: function (panel, status) { // do something }, // fired before the jsPanel is resized onbeforeresize: function (panel, status, closedByUser) { // do something }, // fired after the jsPanel is closed onclosed: function (panel, closedByUser) { // do something }, // fired after a panel fronted onfronted: function(panel, status){ // do something } // fired after the jsPanel is maximized onmaximized: function (panel, status) { // do something }, // fired after the jsPanel is minimized onminimized: function (panel, status) { // do something }, // fired after the jsPanel is restored onnormalized: function (panel, status) { // do something }, // fired after the jsPanel is smallified/unsmallified onsmallified: function (panel, status) { // do something }, onunsmallified: function (panel, status) { // do something }, // fired after a panel's status changed onstatuschange: function(panel, status){ // do something }, // fired after parent element resized onparentresize: function (panel, parentsize) { // do something } // fired on window resize onwindowresize: function (event, panel) { // do something } });
6.API方法。
// add a custom control to the controlbar instance.addControl({ html: '<span class="far fa-bars"></span>', name: 'menu', ariaLabel: '', handler: function(panel, control){ panel.content.innerHTML = 'You clicked the "menu" control'; }, position: 1, // 1. smallify; 2. minimize; 3. normalize; 4. maximize; 5. close afterInsert: function(control){ // do with the control whatever is needed ... } }); // converts a DOMString to a DocumentFragment instance.strToHtml(str); // place: 'header' or 'footer' instance.addToolbar(place, toolbar [, callback]); // close the panel instance.close(); // close all child panels instance.closeChildpanels(); // remove all content from the content section of the panel the method was called on instance.contentRemove([callback]); // enable/disable dragit interaction instance.dragit(); // bring the panel to the front instance.front(callback); // return a NodeList (versions < 4.5.0 returned an array) with all childpanels of the panel the method was called on instance.getChildpanels(callback); // check if is child panel instance.isChildpanel(callback); // maximize the panel instance.maximize(callback); // minimize the panel instance.minimize(callback) // restore the panel instance.normalize(callback); // check where a panel is positioned relative to reference and return an object instance.overlaps(reference[, elmtBox, event]); // re-position the panel instance.reposition(position, callback); // resize the panel instance.resize(width, height [, callback]); // enable/disable resizeit interaction instance.resizeit(); // set CSS border of an existing panel. instance.setBorder(value); // set CSS border-radius of an existing panel. instance.setBorderRadius(value); // disables, enables, removes, hides or shows a control from an existing panel // Control: "close", "maximize", "normalize", "minimize" or "smallify" // action: "remove", "hide", "disable", "enable", "show" instance.setControlStatus(control, action [, callback]); // set header logo instance.setHeaderLogo(logo [, callback]); // set header title instance.setHeaderTitle(title [, callback]); // change the theme instance.setTheme(theme, callback); // smallify the panel instance.smallify(callback); // unsmallify a panel instance.unsmallify([callback]);
7.财产。
// panel content instance.content // controls panel.controlbar // returns the element the panel can be dropped into or false drag: function() { this.content.innerHTML = '<p>#' + this.droppableTo.id + '</p>'; } // Returns a string like 'left-top' with the position a panel can snap to drag: function () { this.content.innerHTML = '<p>panel.snappableTo is: ' + this.snappableTo + '</p>'; }, // Returns a string like 'left-top' with the position a panel actually snapped to stop: function () { this.content.innerHTML = '<p>panel.snapped is: ' + this.snapped + '</p>'; }, // footer content instance.footer // header content instance.header // headerbar content instance.headerbar // header logo instance.headerlogo // header title instance.headertitle // header title instance.headertitle // header toolbar content instance.headertoolbar // returns the configuration object of a panel after the panel defaults were merged with the configuration instance.options // returns a string with the current status of an existing panel. instance.status // titlebar instance.titlebar
8.事件。
// fired whenever a panel is fronted document.addEventListener('jspanelfronted', handler, false); // fired when the panel is fully rendered document.addEventListener('jspanelloaded', handler, false); // fired before a panel is closed document.addEventListener('jspanelbeforeclose', handler, false); // fired befor a panel is maximized document.addEventListener('jspanelbeforemaximize', handler, false); // fired befor a panel is minimize document.addEventListener('jspanelbeforeminimize', handler, false); // firedbefor a panel is normalized document.addEventListener('jspanelbeforenormalize', handler, false); // fired befor a panel is smallified document.addEventListener('jspanelbeforesmallify', handler, false); // fired befor a panel is unsmallified document.addEventListener('jspanelbeforeunsmallify', handler, false); // fired after a panel is closed document.addEventListener('jspanelclosed', handler, false); // fired after a panel is closed by user document.addEventListener('jspanelcloseduser', handler, false); // fired after a panel is maximized document.addEventListener('jspanelmaximized', handler, false); // fired after a panel is minimized document.addEventListener('jspanelminimized', handler, false); // fired after a panel is normalized document.addEventListener('jspanelnormalized', handler, false); // fired after a panel is smallified document.addEventListener('jspanelsmallified', handler, false); // fired after a maximized panel is smallified document.addEventListener('jspanelminimized', handler, false); // fired whenever a panel changes its status document.addEventListener('jspanelstatuschange', handler, false); // fired when start dragging document.addEventListener('jspaneldragstart', handler, false); // fired when dragging document.addEventListener('jspaneldrag', handler, false); // fired when stop dragging document.addEventListener('jspaneldragstop', handler, false); // fired when start resizing document.addEventListener('jspanelresizestart', handler, false); // fired when resizing document.addEventListener('jspanelresize', handler, false); // fired when stop resizing document.addEventListener('jspanelresizestop', handler, false);
版本4.16.0(2022-07-05)
版本4.15.0(2022-05-31)
版本4.14.1(2022-05-18)
版本4.14.0(2022-04-21)
v4.13.0 (2021-11-25)
v4.12.0 (2021-07-10)
v4.11.4 (2021-04-10)
v4.11.3 (2021-02-04)
版本4.11.2(2020-12-09)
版本4.11.1(2020-11-23)
v4.11.0稳定(2020-11-20)
v4.11.0测试版(2020-06-17)
版本4.10.1(2020-05-01)
版本4.10.1(2020-04-09)
版本4.10.0(2020-03-10)
版本4.9.5(2020-02-02)
第4.9.3/4版(2020-01-16)
第4.9.2版(2020-01-15)
第4.9.1版(2019-12-12)
第4.9.0版(2019-12-10)
第3.11.3版(2019-11-27)
4.8.0 (2019-11-08)
4.7.0 (2019-06-18)
4.6.0 (2019-03-27)
4.5.0 (2019-02-12)
4.4.0 (2018-11-30)
4.3.0 (2018-11-11)
4.2.1 (2018-09-15)
4.1.2 (2018-08-13)
4.1.1 (2018-07-26)
4.1.0 (2018-07-24)
4.0.0 (2018-05-23)
4.0.0-贝塔.5(2018-04-19)
v3.11.1 (2017-11-22)
v3.11.0(2017年10月22日)
v3.10.0(2017年8月19日)
v3.9.3(2017年7月17日)
v3.9.2(2017年6月28日)
v3.9.0(2017年6月17日)
v3.9.0(2017年5月29日)
v3.8.1(2017年5月10日)
v3.8.0(2017年4月26日)
v3.7.0(2017年3月02日)
第3.6.1版(2017-02-08)
v3.6.0 (2017-02-03)
版本3.5.0(2016-12-08)
第3.4.1版(2016年11月4日)
第3.4.0版(2016年10月28日)
v3.3.1(2016年9月17日)
v3.3.0(2016年9月12日)
v3.2.0(2016年8月26日)
v3.1.1(2016年7月25日)
v3.1.0(2016年7月13日)
3.0.1版(2016年6月25日)
v3.0.0(2016年6月13日)
v2.6.1版本(2016-01-24)
2015-10-08
作者:Flyer53
主页:http://jspanel.de/