├── .gitattributes ├── .github └── FUNDING.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── demo ├── boilerplate.svg ├── favicon.png ├── heart-filled.svg ├── heart.svg ├── icon-github.svg ├── og-image.png ├── style.css ├── wikipedia.svg └── winbox-gradient.svg ├── dist ├── css │ ├── themes │ │ ├── modern.min.css │ │ └── white.min.css │ └── winbox.min.css ├── img │ ├── close.svg │ ├── exit.svg │ ├── full.svg │ ├── max.svg │ ├── min.svg │ └── restore.svg ├── js │ └── winbox.min.js └── winbox.bundle.min.js ├── index.html ├── package.json ├── src ├── css │ ├── control.less │ ├── images.less │ ├── themes │ │ ├── modern.less │ │ └── white.less │ ├── winbox.css │ └── winbox.less ├── img │ ├── close.svg │ ├── exit.svg │ ├── full.svg │ ├── max.svg │ ├── min.svg │ └── restore.svg └── js │ ├── helper.js │ ├── template.js │ ├── webpack.js │ └── winbox.js └── task ├── build.js ├── bundle.js ├── clean.js ├── package.json ├── server.js └── svgo.js /.gitattributes: -------------------------------------------------------------------------------- 1 | src/css/winbox.css -linguist-detectable 2 | index.html -linguist-detectable 3 | demo/** -linguist-detectable 4 | dist/** -linguist-detectable 5 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [ts-thomas] 4 | open_collective: winboxjs 5 | liberapay: ts-thomas 6 | patreon: user?u=96245532 7 | custom: ["https://www.paypal.com/donate/?hosted_button_id=GEVR88FC9BWRW", "https://salt.bountysource.com/teams/ts-thomas"] 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /log 4 | /tmp 5 | .idea 6 | .nyc_output 7 | .db 8 | coverage 9 | perf 10 | server 11 | !*.keep 12 | package-lock.json 13 | misc 14 | vorlage 15 | test 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## v0.2.7 2 | 3 | - support option "overflow" to allow the window moving outside the viewports border 4 | - add static function `WinBox.stack()` which returns an Array containing every window instance ordered by focus history 5 | - support drag move from maximized state 6 | - automatically focus previous focused window on minimize window 7 | 8 | ## v0.2.5 9 | 10 | - support custom toolbar icon 11 | - support custom toolbar controls 12 | - support custom toolbar height 13 | - support custom window index 14 | - support window autosize 15 | - support new callbacks 16 | - improve drag pointer calculation when outside the viewport 17 | - improve toolbar template 18 | - improve window states 19 | - improve performance 20 | 21 | #### Migrations: 22 | 23 | - the classname `wb-icon` was renamed to `wb-control` 24 | - instead the new window heading toolbar icon was named as `wb-icon` 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /demo/boilerplate.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 |
 .wb-title
 .wb-title
.wb-body
.wb-body
.wb-close
.wb-close
.wb-n
.wb-n
.wb-s
.wb-s
.wb-e
.wb-e
.wb-w
.wb-w
.wb-body{ margin }
.wb-body{ margin }
.wb-ne
.wb-ne
.wb-nw
.wb-nw
.wb-se
.wb-se
.wb-sw
.wb-sw
.wb-full
.wb-full
.wb-max
.wb-max
.wb-min
.wb-min
Viewer does not support full SVG 1.1
-------------------------------------------------------------------------------- /demo/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nextapps-de/winbox/bbb453aca2c3c5122c06ae0c6446eea1730d9142/demo/favicon.png -------------------------------------------------------------------------------- /demo/heart-filled.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /demo/heart.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /demo/icon-github.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /demo/og-image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nextapps-de/winbox/bbb453aca2c3c5122c06ae0c6446eea1730d9142/demo/og-image.png -------------------------------------------------------------------------------- /demo/style.css: -------------------------------------------------------------------------------- 1 | *{ 2 | box-sizing: border-box; 3 | touch-action: manipulation; 4 | } 5 | html, body{ 6 | margin: 0; 7 | padding: 0; 8 | border: 0; 9 | background: linear-gradient(135deg, #0d1117, #131820); 10 | } 11 | body{ 12 | position: fixed; 13 | top: 0; 14 | right: 0; 15 | bottom: 0; 16 | left: 0; 17 | font-family: -apple-system, BlinkMacSystemFont, Helvetica, Arial, "Open Sans", OpenSans, Roboto, Segoe UI, sans-serif; 18 | text-align: center; 19 | color: #fff; 20 | 21 | -webkit-tap-highlight-color: transparent; 22 | -webkit-text-size-adjust: 100%; 23 | -webkit-touch-callout: none; 24 | -webkit-user-select: none; 25 | -khtml-user-select: none; 26 | -moz-user-select: none; 27 | -ms-user-select: none; 28 | user-select: none; 29 | 30 | overflow: hidden; 31 | } 32 | main{ 33 | position: fixed; 34 | top: 0; 35 | right: 0; 36 | bottom: 0; 37 | left: 0; 38 | overflow-x: hidden; 39 | overflow-y: scroll; 40 | -webkit-overflow-scrolling: touch; 41 | overflow-scrolling: touch; 42 | /*content-visibility: auto;*/ 43 | } 44 | header{ 45 | position: sticky; 46 | top: 0; 47 | width: 100%; 48 | height: 50px; 49 | background: linear-gradient(to right, rgba(13, 17, 22, 0.94), rgba(17, 21, 28, 0.94)); 50 | padding: 15px 0; 51 | border-bottom: 1px solid #181f2a; 52 | z-index: 2; 53 | } 54 | .wrapper{ 55 | position: relative; 56 | display: block; 57 | margin: auto; 58 | max-width: 600px; 59 | text-align: left; 60 | padding: 1.2em; 61 | padding-top: 40px; 62 | z-index: 1; 63 | } 64 | a{ 65 | display: inline-block; 66 | color: #3374ff; 67 | text-decoration: none; 68 | font-weight: 600; 69 | } 70 | b{ 71 | display: block; 72 | padding: 10px; 73 | } 74 | button{ 75 | padding: 5px 10px; 76 | margin-bottom: 5px; 77 | } 78 | h1{ 79 | margin: 0; 80 | padding: 0; 81 | } 82 | h1 img{ 83 | width: 100%; 84 | height: auto; 85 | } 86 | h2{ 87 | font-size: 20px; 88 | font-weight: 400; 89 | line-height: 27px; 90 | } 91 | h3{ 92 | font-size: 24px; 93 | font-weight: 600; 94 | line-height: 32px; 95 | margin:0; 96 | } 97 | hr{ 98 | border: 0; 99 | border-bottom: 1px solid #1c2431; 100 | margin-bottom: 20px; 101 | padding-top: 20px; 102 | } 103 | .button { 104 | display: inline-block; 105 | background-color: #0050ff; 106 | color: #fff; 107 | width: auto; 108 | border-radius: 10px; 109 | padding: 15px 25px; 110 | cursor: pointer; 111 | } 112 | pre{ 113 | display: inline-block; 114 | margin: auto; 115 | text-align: left; 116 | width: 100%; 117 | max-width: calc(100vw - 1.7em); 118 | line-height: 19px; 119 | -webkit-touch-callout: default !important; 120 | -webkit-user-select: text !important; 121 | -khtml-user-select: text !important; 122 | -moz-user-select: text !important; 123 | -ms-user-select: text !important; 124 | user-select: text !important; 125 | } 126 | pre code.hljs{ 127 | background: #181f2a; 128 | padding: 1em 1.5em; 129 | border-radius: 10px; 130 | width: 100%; 131 | max-width: calc(100vw - 1.7em); 132 | } 133 | .break{ 134 | height: 18px; 135 | } 136 | 137 | @media (min-width: 600px) { 138 | 139 | main::-webkit-scrollbar { 140 | width: 12px; 141 | height: 12px; 142 | } 143 | 144 | main::-webkit-scrollbar-track { 145 | background: transparent; 146 | } 147 | 148 | main::-webkit-scrollbar-thumb { 149 | border-radius: 10px; 150 | background: #263040; 151 | } 152 | 153 | main::-webkit-scrollbar-thumb:window-inactive { 154 | background: #181f2a; 155 | } 156 | 157 | main::-webkit-scrollbar-corner { 158 | background: transparent; 159 | } 160 | } 161 | 162 | @media (max-width: 600px) { 163 | .wrapper{ 164 | padding-top: 30px; 165 | } 166 | .wrapper, pre{ 167 | display: block; 168 | } 169 | } 170 | 171 | @media (max-height: 550px) { 172 | header{ 173 | position: absolute; 174 | } 175 | } 176 | 177 | .wb-body { 178 | color: #000; 179 | } 180 | .wb-body > *:not(iframe){ 181 | padding: 1.2em; 182 | } 183 | .winbox.iframe .wb-body > *{ 184 | padding: 0; 185 | } 186 | .winbox.iframe .wb-body{ 187 | background: linear-gradient(135deg, #0d1117, #131820); 188 | } 189 | 190 | .hljs{ 191 | color: #fff4ec; 192 | } 193 | .hljs-attr { 194 | color:#79c0ff 195 | } 196 | .hljs-name, 197 | .hljs-built_in { 198 | color: #ffa657; 199 | } 200 | .hljs-attribute{ 201 | color: #e0e7ff 202 | } 203 | .hljs-selector-class { 204 | color: #79c0ff 205 | } 206 | 207 | .hljs-keyword, 208 | .hljs-selector-tag { 209 | color: #f92672 210 | } 211 | 212 | .hljs-comment{ 213 | color: #888; 214 | } 215 | 216 | .hljs-bullet, 217 | .hljs-link, 218 | .hljs-literal, 219 | .hljs-number, 220 | .hljs-quote, 221 | .hljs-regexp { 222 | color: #d2a8ff 223 | } 224 | -------------------------------------------------------------------------------- /demo/wikipedia.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /demo/winbox-gradient.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /dist/css/themes/modern.min.css: -------------------------------------------------------------------------------- 1 | @keyframes popup{0%{transform:scale(.8)}to{transform:scale(1)}}.winbox.modern{background:linear-gradient(90deg,#ff00f0,#0050ff);border-radius:12px 12px 0 0;animation:popup .3s cubic-bezier(.3,1,.3,1) forwards}.winbox.modern:not(.min,.focus){background:#666}@media (hover:hover){.winbox.modern.min:not(:hover){background:#666}.winbox.modern .wb-control *{opacity:.65}.winbox.modern .wb-control :hover{opacity:1}}@media (hover:none){.winbox.modern.min{background:#666}}.winbox.modern.max{border-radius:0}.winbox.modern .wb-title{font-size:13px;text-transform:uppercase;font-weight:600}.winbox.modern .wb-body{margin:4px;color:#fff;background:#131820}.winbox.modern .wb-body::-webkit-scrollbar{width:12px;height:12px}.winbox.modern .wb-body::-webkit-scrollbar-track{background:0 0}.winbox.modern .wb-body::-webkit-scrollbar-thumb{border-radius:10px;background:#263040}.winbox.modern .wb-body::-webkit-scrollbar-thumb:window-inactive{background:#181f2a}.winbox.modern .wb-body::-webkit-scrollbar-corner{background:0 0} -------------------------------------------------------------------------------- /dist/css/themes/white.min.css: -------------------------------------------------------------------------------- 1 | .winbox.white{background:#fff}.winbox.white .wb-title{color:#000}.winbox.white .wb-control{filter:invert(1)} -------------------------------------------------------------------------------- /dist/css/winbox.min.css: -------------------------------------------------------------------------------- 1 | @keyframes wb-fade-in{0%{opacity:0}to{opacity:.85}}.winbox{position:fixed;left:0;top:0;background:#0050ff;box-shadow:0 14px 28px rgba(0,0,0,.25),0 10px 10px rgba(0,0,0,.22);transition:width .3s,height .3s,left .3s,top .3s;transition-timing-function:cubic-bezier(.3,1,.3,1);contain:layout size;text-align:left;touch-action:none}.wb-body,.wb-header{position:absolute;left:0}.wb-header{top:0;width:100%;height:35px;line-height:35px;color:#fff;overflow:hidden;z-index:1}.wb-body{top:35px;right:0;bottom:0;overflow:auto;-webkit-overflow-scrolling:touch;overflow-scrolling:touch;will-change:contents;background:#fff;margin-top:0!important;contain:strict;z-index:0}.wb-control *,.wb-icon{background-repeat:no-repeat}.wb-drag{height:100%;padding-left:10px;cursor:move}.wb-title{font-family:Arial,sans-serif;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.wb-icon{display:none;width:20px;height:100%;margin:-1px 8px 0-3px;float:left;background-size:100%;background-position:center}.wb-e,.wb-w{width:10px;top:0}.wb-n,.wb-s{left:0;height:10px;position:absolute}.wb-n{top:-5px;right:0;cursor:n-resize;z-index:2}.wb-e{position:absolute;right:-5px;bottom:0;cursor:w-resize;z-index:2}.wb-s{bottom:-5px;right:0;cursor:n-resize;z-index:2}.wb-nw,.wb-sw,.wb-w{left:-5px}.wb-w{position:absolute;bottom:0;cursor:w-resize;z-index:2}.wb-ne,.wb-nw,.wb-sw{width:15px;height:15px;z-index:2;position:absolute}.wb-nw{top:-5px;cursor:nw-resize}.wb-ne,.wb-sw{cursor:ne-resize}.wb-ne{top:-5px;right:-5px}.wb-se,.wb-sw{bottom:-5px}.wb-se{position:absolute;right:-5px;width:15px;height:15px;cursor:nw-resize;z-index:2}.wb-control{float:right;height:100%;max-width:100%;text-align:center}.wb-control *{display:inline-block;width:30px;height:100%;max-width:100%;background-position:center;cursor:pointer}.no-close .wb-close,.no-full .wb-full,.no-header .wb-header,.no-max .wb-max,.no-min .wb-min,.no-resize .wb-body~div,.wb-body .wb-hide,.wb-show,.winbox.hide,.winbox.min .wb-body>*,.winbox.min .wb-full,.winbox.min .wb-min,.winbox.modal .wb-full,.winbox.modal .wb-max,.winbox.modal .wb-min{display:none}.winbox.max .wb-drag,.winbox.min .wb-drag{cursor:default}.wb-min{background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAyIj48cGF0aCBmaWxsPSIjZmZmIiBkPSJNOCAwaDdhMSAxIDAgMCAxIDAgMkgxYTEgMSAwIDAgMSAwLTJoN3oiLz48L3N2Zz4=);background-size:14px auto;background-position:center calc(50% + 6px)}.wb-max{background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9IiNmZmYiIHZpZXdCb3g9IjAgMCA5NiA5NiI+PHBhdGggZD0iTTIwIDcxLjMxMUMxNS4zNCA2OS42NyAxMiA2NS4yMyAxMiA2MFYyMGMwLTYuNjMgNS4zNy0xMiAxMi0xMmg0MGM1LjIzIDAgOS42NyAzLjM0IDExLjMxMSA4SDI0Yy0yLjIxIDAtNCAxLjc5LTQgNHY1MS4zMTF6Ii8+PHBhdGggZD0iTTkyIDc2VjM2YzAtNi42My01LjM3LTEyLTEyLTEySDQwYy02LjYzIDAtMTIgNS4zNy0xMiAxMnY0MGMwIDYuNjMgNS4zNyAxMiAxMiAxMmg0MGM2LjYzIDAgMTItNS4zNyAxMi0xMnptLTUyIDRjLTIuMjEgMC00LTEuNzktNC00VjM2YzAtMi4yMSAxLjc5LTQgNC00aDQwYzIuMjEgMCA0IDEuNzkgNCA0djQwYzAgMi4yMS0xLjc5IDQtNCA0SDQweiIvPjwvc3ZnPg==);background-size:17px auto}.wb-close{background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9Ii0xIC0xIDE4IDE4Ij48cGF0aCBmaWxsPSIjZmZmIiBkPSJtMS42MTMuMjEuMDk0LjA4M0w4IDYuNTg1IDE0LjI5My4yOTNsLjA5NC0uMDgzYTEgMSAwIDAgMSAxLjQwMyAxLjQwM2wtLjA4My4wOTRMOS40MTUgOGw2LjI5MiA2LjI5M2ExIDEgMCAwIDEtMS4zMiAxLjQ5N2wtLjA5NC0uMDgzTDggOS40MTVsLTYuMjkzIDYuMjkyLS4wOTQuMDgzQTEgMSAwIDAgMSAuMjEgMTQuMzg3bC4wODMtLjA5NEw2LjU4NSA4IC4yOTMgMS43MDdBMSAxIDAgMCAxIDEuNjEzLjIxeiIvPjwvc3ZnPg==);background-size:15px auto;background-position:5px center}.wb-full{background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2ZmZiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2Utd2lkdGg9IjIuNSIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNOCAzSDVhMiAyIDAgMCAwLTIgMnYzbTE4IDBWNWEyIDIgMCAwIDAtMi0yaC0zbTAgMThoM2EyIDIgMCAwIDAgMi0ydi0zTTMgMTZ2M2EyIDIgMCAwIDAgMiAyaDMiLz48L3N2Zz4=);background-size:16px auto}.winbox.max .wb-body~div,.winbox.min .wb-body~div,.winbox.modal .wb-body~div,.winbox.modal .wb-drag,body.wb-lock iframe{pointer-events:none}.winbox.max{box-shadow:none}.winbox.max .wb-body{margin:0!important}.winbox iframe{position:absolute;width:100%;height:100%;border:0}body.wb-lock .winbox{will-change:left,top,width,height;transition:none}.winbox.modal:before{content:"";position:absolute;top:0;left:0;right:0;bottom:0;background:inherit;border-radius:inherit}.winbox.modal:after{content:"";position:absolute;top:-50vh;left:-50vw;right:-50vw;bottom:-50vh;background:#0d1117;animation:wb-fade-in .2s ease-out forwards;z-index:-1}.no-animation{transition:none}.no-shadow{box-shadow:none}.no-header .wb-body{top:0}.no-move:not(.min) .wb-title{pointer-events:none}.wb-body .wb-show{display:revert} -------------------------------------------------------------------------------- /dist/img/close.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dist/img/exit.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dist/img/full.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dist/img/max.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dist/img/min.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dist/img/restore.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dist/js/winbox.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * WinBox.js v0.2.82 3 | * Author and Copyright: Thomas Wilkerling 4 | * Licence: Apache-2.0 5 | * Hosted by Nextapps GmbH 6 | * https://github.com/nextapps-de/winbox 7 | */ 8 | (function(){'use strict';var e,aa=document.createElement("div");aa.innerHTML="
";function h(a,b,c,f){a&&a.addEventListener(b,c,f||!1)}function k(a,b){var c=window,f=l;c&&c.removeEventListener(a,b,f||!1)}function m(a,b){a.stopPropagation();b&&a.preventDefault()}function t(a,b,c){c=""+c;a["_s_"+b]!==c&&(a.style.setProperty(b,c),a["_s_"+b]=c)};/* 9 | self.max &&*/ 10 | var u=[],x=[],ba={capture:!0,passive:!1},l={capture:!0,passive:!0},A,ea=0,B=10,E,F,fa,J,K,ha; 11 | function P(a,b){if(!(this instanceof P))return new P(a);A||ia();if(a){if(b){var c=a;a=b}if("string"===typeof a)c=a;else{var f=a.id;var d=a.index;var n=a.root;var p=a.template;c=c||a.title;var v=a.icon;var L=a.mount;var Q=a.html;var g=a.url;var q=a.width;var r=a.height;var w=a.minwidth;var C=a.minheight;var y=a.maxwidth;var z=a.maxheight;var ca=a.autosize;var D=a.overflow;var G=a.min;var H=a.max;var I=a.hidden;var da=a.modal;var W=a.x||(da?"center":0);var X=a.y||(da?"center":0);var M=a.top;var N=a.left; 12 | var R=a.bottom;var S=a.right;var ja=a.background;var O=a.border;var T=a.header;var Y=a["class"];var ka=a.oncreate;var pa=a.onclose;var qa=a.onfocus;var ra=a.onblur;var sa=a.onmove;var ta=a.onresize;var ua=a.onfullscreen;var va=a.onmaximize;var wa=a.onminimize;var xa=a.onrestore;var ya=a.onhide;var za=a.onshow;var Aa=a.onload}}this.g=(p||aa).cloneNode(!0);this.g.id=this.id=f||"winbox-"+ ++ea;this.g.className="winbox"+(Y?" "+("string"===typeof Y?Y:Y.join(" ")):"")+(da?" modal":"");this.g.winbox=this; 13 | this.window=this.g;this.body=this.g.getElementsByClassName("wb-body")[0];this.h=T||35;x.push(this);ja&&this.setBackground(ja);O?t(this.body,"margin",O+(isNaN(O)?"":"px")):O=0;T&&(b=this.g.getElementsByClassName("wb-header")[0],t(b,"height",T+"px"),t(b,"line-height",T+"px"),t(this.body,"top",T+"px"));c&&this.setTitle(c);v&&this.setIcon(v);L?this.mount(L):Q?this.body.innerHTML=Q:g&&this.setUrl(g,Aa);M=M?U(M,K):0;R=R?U(R,K):0;N=N?U(N,J):0;S=S?U(S,J):0;c=J-N-S;v=K-M-R;y=y?U(y,c):c;z=z?U(z,v):v;w=w?U(w, 14 | y):150;C=C?U(C,z):this.h;ca?((n||A).appendChild(this.body),q=Math.max(Math.min(this.body.clientWidth+2*O+1,y),w),r=Math.max(Math.min(this.body.clientHeight+this.h+O+1,z),C),this.g.appendChild(this.body)):(q=q?U(q,y):Math.max(y/2,w)|0,r=r?U(r,z):Math.max(z/2,C)|0);W=W?U(W,c,q):N;X=X?U(X,v,r):M;this.x=W;this.y=X;this.width=q;this.height=r;this.s=w;this.o=C;this.m=y;this.l=z;this.top=M;this.right=S;this.bottom=R;this.left=N;this.index=d;this.j=D;this.focused=this.hidden=this.full=this.max=this.min=!1; 15 | this.onclose=pa;this.onfocus=qa;this.onblur=ra;this.onmove=sa;this.onresize=ta;this.onfullscreen=ua;this.onmaximize=va;this.onminimize=wa;this.onrestore=xa;this.onhide=ya;this.onshow=za;I?this.hide():this.focus();if(d||0===d)this.index=d,t(this.g,"z-index",d),d>B&&(B=d);H?this.maximize():G?this.minimize():this.resize().move();la(this);(n||A).appendChild(this.g);ka&&ka.call(this,a)}P["new"]=function(a){return new P(a)};P.stack=function(){return x}; 16 | function U(a,b,c){"string"===typeof a&&("center"===a?a=(b-c)/2+.5|0:"right"===a||"bottom"===a?a=b-c:(c=parseFloat(a),a="%"===(""+c!==a&&a.substring((""+c).length))?b/100*c+.5|0:c));return a} 17 | function ia(){A=document.body;A[F="requestFullscreen"]||A[F="msRequestFullscreen"]||A[F="webkitRequestFullscreen"]||A[F="mozRequestFullscreen"]||(F="");fa=F&&F.replace("request","exit").replace("mozRequest","mozCancel").replace("Request","Exit");h(window,"resize",function(){ma();na()});h(A,"mousedown",function(){ha=!1},!0);h(A,"mousedown",function(){if(!ha){var a=x.length;if(a)for(--a;0<=a;a--){var b=x[a];if(b.focused){b.blur();break}}}});ma()} 18 | function la(a){V(a,"drag");V(a,"n");V(a,"s");V(a,"w");V(a,"e");V(a,"nw");V(a,"ne");V(a,"se");V(a,"sw");h(a.g.getElementsByClassName("wb-min")[0],"click",function(b){m(b);a.min?a.restore().focus():a.minimize()});h(a.g.getElementsByClassName("wb-max")[0],"click",function(b){m(b);a.max?a.restore().focus():a.maximize().focus()});F?h(a.g.getElementsByClassName("wb-full")[0],"click",function(b){m(b);a.fullscreen().focus()}):a.addClass("no-full");h(a.g.getElementsByClassName("wb-close")[0],"click",function(b){m(b); 19 | a.close()||(a=null)});h(a.g,"mousedown",function(){ha=!0},!0);h(a.body,"mousedown",function(){a.focus()},!0)}function Z(a){u.splice(u.indexOf(a),1);na();a.removeClass("min");a.min=!1;a.g.title=""}function na(){for(var a=u.length,b={},c={},f=0,d;fr){a.max?a.restore():a.maximize();return}}}a.min||(A.classList.add("wb-lock"),(p=g.touches)&&(p=p[0])?(g=p,h(window,"touchmove",f,l),h(window,"touchend",d,l)):(h(window,"mousemove",f,l),h(window,"mouseup",d,l)),v=g.pageX,L=g.pageY)}function f(g){m(g);p&&(g=g.touches[0]);var q=g.pageX;g=g.pageY;var r=q-v,w=g-L,C=a.width,y=a.height,z=a.x, 21 | ca=a.y,D;if("drag"===b){if(a.g.classList.contains("no-move"))return;a.x+=r;a.y+=w;var G=D=1}else{if("e"===b||"se"===b||"ne"===b){a.width+=r;var H=1}else if("w"===b||"sw"===b||"nw"===b)a.x+=r,a.width-=r,G=H=1;if("s"===b||"se"===b||"sw"===b){a.height+=w;var I=1}else if("n"===b||"ne"===b||"nw"===b)a.y+=w,a.height-=w,D=I=1}H&&(a.width=Math.max(Math.min(a.width,a.m,J-a.x-a.right),a.s),H=a.width!==C);I&&(a.height=Math.max(Math.min(a.height,a.l,K-a.y-a.bottom),a.o),I=a.height!==y);(H||I)&&a.resize();G&& 22 | (a.max&&(a.x=(qJ/3*2?J-a.width-a.right:J/2-a.width/2)+r),a.x=Math.max(Math.min(a.x,a.j?J-30:J-a.width-a.right),a.j?30-a.width:a.left),G=a.x!==z);D&&(a.max&&(a.y=a.top+w),a.y=Math.max(Math.min(a.y,a.j?K-a.h:K-a.height-a.bottom),a.top),D=a.y!==ca);if(G||D)a.max&&a.restore(),a.move();if(H||G)v=q;if(I||D)L=g}function d(g){m(g);A.classList.remove("wb-lock");p?(k("touchmove",f),k("touchend",d)):(k("mousemove",f),k("mouseup",d))}var n=a.g.getElementsByClassName("wb-"+b)[0];if(n){var p,v,L, 23 | Q=0;h(n,"mousedown",c,ba);h(n,"touchstart",c,ba)}}function ma(){var a=document.documentElement;J=a.clientWidth;K=a.clientHeight}e=P.prototype;e.mount=function(a){this.unmount();a.i||(a.i=a.parentNode);this.body.textContent="";this.body.appendChild(a);return this};e.unmount=function(a){var b=this.body.firstChild;if(b){var c=a||b.i;c&&c.appendChild(b);b.i=a}return this}; 24 | e.setTitle=function(a){var b=this.g.getElementsByClassName("wb-title")[0];a=this.title=a;var c=b.firstChild;c?c.nodeValue=a:b.textContent=a;return this};e.setIcon=function(a){var b=this.g.getElementsByClassName("wb-icon")[0];t(b,"background-image","url("+a+")");t(b,"display","inline-block");return this};e.setBackground=function(a){t(this.g,"background",a);return this}; 25 | e.setUrl=function(a,b){var c=this.body.firstChild;c&&"iframe"===c.tagName.toLowerCase()?c.src=a:(this.body.innerHTML='',b&&(this.body.firstChild.onload=b));return this};e.focus=function(a){if(!1===a)return this.blur();if(!this.focused){a=x.length;if(1*,.winbox.min .wb-full,.winbox.min .wb-min,.winbox.modal .wb-full,.winbox.modal .wb-max,.winbox.modal .wb-min{display:none}.winbox.max .wb-drag,.winbox.min .wb-drag{cursor:default}.wb-min{background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAyIj48cGF0aCBmaWxsPSIjZmZmIiBkPSJNOCAwaDdhMSAxIDAgMCAxIDAgMkgxYTEgMSAwIDAgMSAwLTJoN3oiLz48L3N2Zz4=);background-size:14px auto;background-position:center calc(50% + 6px)}.wb-max{background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9IiNmZmYiIHZpZXdCb3g9IjAgMCA5NiA5NiI+PHBhdGggZD0iTTIwIDcxLjMxMUMxNS4zNCA2OS42NyAxMiA2NS4yMyAxMiA2MFYyMGMwLTYuNjMgNS4zNy0xMiAxMi0xMmg0MGM1LjIzIDAgOS42NyAzLjM0IDExLjMxMSA4SDI0Yy0yLjIxIDAtNCAxLjc5LTQgNHY1MS4zMTF6Ii8+PHBhdGggZD0iTTkyIDc2VjM2YzAtNi42My01LjM3LTEyLTEyLTEySDQwYy02LjYzIDAtMTIgNS4zNy0xMiAxMnY0MGMwIDYuNjMgNS4zNyAxMiAxMiAxMmg0MGM2LjYzIDAgMTItNS4zNyAxMi0xMnptLTUyIDRjLTIuMjEgMC00LTEuNzktNC00VjM2YzAtMi4yMSAxLjc5LTQgNC00aDQwYzIuMjEgMCA0IDEuNzkgNCA0djQwYzAgMi4yMS0xLjc5IDQtNCA0SDQweiIvPjwvc3ZnPg==);background-size:17px auto}.wb-close{background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9Ii0xIC0xIDE4IDE4Ij48cGF0aCBmaWxsPSIjZmZmIiBkPSJtMS42MTMuMjEuMDk0LjA4M0w4IDYuNTg1IDE0LjI5My4yOTNsLjA5NC0uMDgzYTEgMSAwIDAgMSAxLjQwMyAxLjQwM2wtLjA4My4wOTRMOS40MTUgOGw2LjI5MiA2LjI5M2ExIDEgMCAwIDEtMS4zMiAxLjQ5N2wtLjA5NC0uMDgzTDggOS40MTVsLTYuMjkzIDYuMjkyLS4wOTQuMDgzQTEgMSAwIDAgMSAuMjEgMTQuMzg3bC4wODMtLjA5NEw2LjU4NSA4IC4yOTMgMS43MDdBMSAxIDAgMCAxIDEuNjEzLjIxeiIvPjwvc3ZnPg==);background-size:15px auto;background-position:5px center}.wb-full{background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2ZmZiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2Utd2lkdGg9IjIuNSIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNOCAzSDVhMiAyIDAgMCAwLTIgMnYzbTE4IDBWNWEyIDIgMCAwIDAtMi0yaC0zbTAgMThoM2EyIDIgMCAwIDAgMi0ydi0zTTMgMTZ2M2EyIDIgMCAwIDAgMiAyaDMiLz48L3N2Zz4=);background-size:16px auto}.winbox.max .wb-body~div,.winbox.min .wb-body~div,.winbox.modal .wb-body~div,.winbox.modal .wb-drag,body.wb-lock iframe{pointer-events:none}.winbox.max{box-shadow:none}.winbox.max .wb-body{margin:0!important}.winbox iframe{position:absolute;width:100%;height:100%;border:0}body.wb-lock .winbox{will-change:left,top,width,height;transition:none}.winbox.modal:before{content:'';position:absolute;top:0;left:0;right:0;bottom:0;background:inherit;border-radius:inherit}.winbox.modal:after{content:'';position:absolute;top:-50vh;left:-50vw;right:-50vw;bottom:-50vh;background:#0d1117;animation:wb-fade-in .2s ease-out forwards;z-index:-1}.no-animation{transition:none}.no-shadow{box-shadow:none}.no-header .wb-body{top:0}.no-move:not(.min) .wb-title{pointer-events:none}.wb-body .wb-show{display:revert}"; 9 | var h=document.getElementsByTagName("head")[0];h.firstChild?h.insertBefore(aa,h.firstChild):h.appendChild(aa);var ba=document.createElement("div");ba.innerHTML="
";function k(a,b,c,f){a&&a.addEventListener(b,c,f||!1)}function l(a,b){var c=window,f=m;c&&c.removeEventListener(a,b,f||!1)}function t(a,b){a.stopPropagation();b&&a.preventDefault()}function u(a,b,c){c=""+c;a["_s_"+b]!==c&&(a.style.setProperty(b,c),a["_s_"+b]=c)};/* 10 | self.max &&*/ 11 | var x=[],A=[],ca={capture:!0,passive:!1},m={capture:!0,passive:!0},B,da=0,E=10,F,J,ha,K,P,ia; 12 | function U(a,b){if(!(this instanceof U))return new U(a);B||ja();if(a){if(b){var c=a;a=b}if("string"===typeof a)c=a;else{var f=a.id;var d=a.index;var n=a.root;var p=a.template;c=c||a.title;var v=a.icon;var L=a.mount;var Q=a.html;var g=a.url;var q=a.width;var r=a.height;var w=a.minwidth;var C=a.minheight;var y=a.maxwidth;var z=a.maxheight;var ea=a.autosize;var D=a.overflow;var G=a.min;var H=a.max;var I=a.hidden;var fa=a.modal;var X=a.x||(fa?"center":0);var Y=a.y||(fa?"center":0);var M=a.top;var N=a.left; 13 | var R=a.bottom;var S=a.right;var la=a.background;var O=a.border;var T=a.header;var Z=a["class"];var ma=a.oncreate;var ra=a.onclose;var sa=a.onfocus;var ta=a.onblur;var ua=a.onmove;var va=a.onresize;var wa=a.onfullscreen;var xa=a.onmaximize;var ya=a.onminimize;var za=a.onrestore;var Aa=a.onhide;var Ba=a.onshow;var Ca=a.onload}}this.g=(p||ba).cloneNode(!0);this.g.id=this.id=f||"winbox-"+ ++da;this.g.className="winbox"+(Z?" "+("string"===typeof Z?Z:Z.join(" ")):"")+(fa?" modal":"");this.g.winbox=this; 14 | this.window=this.g;this.body=this.g.getElementsByClassName("wb-body")[0];this.h=T||35;A.push(this);la&&this.setBackground(la);O?u(this.body,"margin",O+(isNaN(O)?"":"px")):O=0;T&&(b=this.g.getElementsByClassName("wb-header")[0],u(b,"height",T+"px"),u(b,"line-height",T+"px"),u(this.body,"top",T+"px"));c&&this.setTitle(c);v&&this.setIcon(v);L?this.mount(L):Q?this.body.innerHTML=Q:g&&this.setUrl(g,Ca);M=M?V(M,P):0;R=R?V(R,P):0;N=N?V(N,K):0;S=S?V(S,K):0;c=K-N-S;v=P-M-R;y=y?V(y,c):c;z=z?V(z,v):v;w=w?V(w, 15 | y):150;C=C?V(C,z):this.h;ea?((n||B).appendChild(this.body),q=Math.max(Math.min(this.body.clientWidth+2*O+1,y),w),r=Math.max(Math.min(this.body.clientHeight+this.h+O+1,z),C),this.g.appendChild(this.body)):(q=q?V(q,y):Math.max(y/2,w)|0,r=r?V(r,z):Math.max(z/2,C)|0);X=X?V(X,c,q):N;Y=Y?V(Y,v,r):M;this.x=X;this.y=Y;this.width=q;this.height=r;this.s=w;this.o=C;this.m=y;this.l=z;this.top=M;this.right=S;this.bottom=R;this.left=N;this.index=d;this.j=D;this.focused=this.hidden=this.full=this.max=this.min=!1; 16 | this.onclose=ra;this.onfocus=sa;this.onblur=ta;this.onmove=ua;this.onresize=va;this.onfullscreen=wa;this.onmaximize=xa;this.onminimize=ya;this.onrestore=za;this.onhide=Aa;this.onshow=Ba;I?this.hide():this.focus();if(d||0===d)this.index=d,u(this.g,"z-index",d),d>E&&(E=d);H?this.maximize():G?this.minimize():this.resize().move();ka(this);(n||B).appendChild(this.g);ma&&ma.call(this,a)}U["new"]=function(a){return new U(a)};U.stack=function(){return A}; 17 | function V(a,b,c){"string"===typeof a&&("center"===a?a=(b-c)/2+.5|0:"right"===a||"bottom"===a?a=b-c:(c=parseFloat(a),a="%"===(""+c!==a&&a.substring((""+c).length))?b/100*c+.5|0:c));return a} 18 | function ja(){B=document.body;B[J="requestFullscreen"]||B[J="msRequestFullscreen"]||B[J="webkitRequestFullscreen"]||B[J="mozRequestFullscreen"]||(J="");ha=J&&J.replace("request","exit").replace("mozRequest","mozCancel").replace("Request","Exit");k(window,"resize",function(){na();oa()});k(B,"mousedown",function(){ia=!1},!0);k(B,"mousedown",function(){if(!ia){var a=A.length;if(a)for(--a;0<=a;a--){var b=A[a];if(b.focused){b.blur();break}}}});na()} 19 | function ka(a){W(a,"drag");W(a,"n");W(a,"s");W(a,"w");W(a,"e");W(a,"nw");W(a,"ne");W(a,"se");W(a,"sw");k(a.g.getElementsByClassName("wb-min")[0],"click",function(b){t(b);a.min?a.restore().focus():a.minimize()});k(a.g.getElementsByClassName("wb-max")[0],"click",function(b){t(b);a.max?a.restore().focus():a.maximize().focus()});J?k(a.g.getElementsByClassName("wb-full")[0],"click",function(b){t(b);a.fullscreen().focus()}):a.addClass("no-full");k(a.g.getElementsByClassName("wb-close")[0],"click",function(b){t(b); 20 | a.close()||(a=null)});k(a.g,"mousedown",function(){ia=!0},!0);k(a.body,"mousedown",function(){a.focus()},!0)}function pa(a){x.splice(x.indexOf(a),1);oa();a.removeClass("min");a.min=!1;a.g.title=""}function oa(){for(var a=x.length,b={},c={},f=0,d;fr){a.max?a.restore():a.maximize();return}}}a.min||(B.classList.add("wb-lock"),(p=g.touches)&&(p=p[0])?(g=p,k(window,"touchmove",f,m),k(window,"touchend",d,m)):(k(window,"mousemove",f,m),k(window,"mouseup",d,m)),v=g.pageX,L=g.pageY)}function f(g){t(g);p&&(g=g.touches[0]);var q=g.pageX;g=g.pageY;var r=q-v,w=g-L,C=a.width,y=a.height,z=a.x, 22 | ea=a.y,D;if("drag"===b){if(a.g.classList.contains("no-move"))return;a.x+=r;a.y+=w;var G=D=1}else{if("e"===b||"se"===b||"ne"===b){a.width+=r;var H=1}else if("w"===b||"sw"===b||"nw"===b)a.x+=r,a.width-=r,G=H=1;if("s"===b||"se"===b||"sw"===b){a.height+=w;var I=1}else if("n"===b||"ne"===b||"nw"===b)a.y+=w,a.height-=w,D=I=1}H&&(a.width=Math.max(Math.min(a.width,a.m,K-a.x-a.right),a.s),H=a.width!==C);I&&(a.height=Math.max(Math.min(a.height,a.l,P-a.y-a.bottom),a.o),I=a.height!==y);(H||I)&&a.resize();G&& 23 | (a.max&&(a.x=(qK/3*2?K-a.width-a.right:K/2-a.width/2)+r),a.x=Math.max(Math.min(a.x,a.j?K-30:K-a.width-a.right),a.j?30-a.width:a.left),G=a.x!==z);D&&(a.max&&(a.y=a.top+w),a.y=Math.max(Math.min(a.y,a.j?P-a.h:P-a.height-a.bottom),a.top),D=a.y!==ea);if(G||D)a.max&&a.restore(),a.move();if(H||G)v=q;if(I||D)L=g}function d(g){t(g);B.classList.remove("wb-lock");p?(l("touchmove",f),l("touchend",d)):(l("mousemove",f),l("mouseup",d))}var n=a.g.getElementsByClassName("wb-"+b)[0];if(n){var p,v,L, 24 | Q=0;k(n,"mousedown",c,ca);k(n,"touchstart",c,ca)}}function na(){var a=document.documentElement;K=a.clientWidth;P=a.clientHeight}e=U.prototype;e.mount=function(a){this.unmount();a.i||(a.i=a.parentNode);this.body.textContent="";this.body.appendChild(a);return this};e.unmount=function(a){var b=this.body.firstChild;if(b){var c=a||b.i;c&&c.appendChild(b);b.i=a}return this}; 25 | e.setTitle=function(a){var b=this.g.getElementsByClassName("wb-title")[0];a=this.title=a;var c=b.firstChild;c?c.nodeValue=a:b.textContent=a;return this};e.setIcon=function(a){var b=this.g.getElementsByClassName("wb-icon")[0];u(b,"background-image","url("+a+")");u(b,"display","inline-block");return this};e.setBackground=function(a){u(this.g,"background",a);return this}; 26 | e.setUrl=function(a,b){var c=this.body.firstChild;c&&"iframe"===c.tagName.toLowerCase()?c.src=a:(this.body.innerHTML='',b&&(this.body.firstChild.onload=b));return this};e.focus=function(a){if(!1===a)return this.blur();if(!this.focused){a=A.length;if(1 2 | 3 | 4 | 5 | 6 | 7 | 8 | WinBox.js – Modern HTML5 Window Manager 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 28 | 29 | 30 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 |
140 |
141 | Goto Github 142 |
143 |
144 |

WinBox.js: HTML5 Window Manager for the Web.

145 |

WinBox is a modern HTML5 window manager for the web. Lightweight, outstanding performance, no dependencies, fully customizable, free and open source!

146 |
147 |
Show Example
148 |
149 | 150 |
151 |

152 | Please feel free to support me by making a personal donation which helps me a lot to keep this project alive and also to providing all the contribution to keep WinBox.js on a professional top-end level. 153 |

154 | 155 | Donate using Open Collective 156 | 157 | 158 | Donate using Github Sponsors 159 | 160 | 161 | Donate using Liberapay 162 | 163 | 164 | Donate using Patreon 165 | 166 | 167 | Donate using PayPal 168 | 169 | 170 | Donate using Bountysource 171 | 172 |

173 | Thanks a lot, 174 | Thomas (ts-thomas) 175 |

176 | 177 |
178 |
179 | Load Library (Bundle) 180 |

181 |
<head>
 182 |     <script src="dist/winbox.bundle.min.js"></script>
 183 | </head>
184 |
185 |
186 | Load Library (Non-Bundle) 187 |

188 |
<head>
 189 |     <link rel="stylesheet" href="dist/css/winbox.min.css">
 190 |     <script src="dist/js/winbox.min.js"></script>
 191 | </head>
192 |
193 | 194 |
195 |
196 | Class Constructor 197 |

198 |
WinBox(title, options<key: value>)
199 |
200 | 201 |
202 |
203 |
You can open the browser dev tools and copy and paste the js-code blocks into the console and play with them.
204 | 205 |
206 |
207 | Basic Window 208 |

209 |
new WinBox("Basic Window");
210 |
211 |
Run Code
212 |

213 | 214 |
215 |
216 | Custom Root 217 |

218 |
new WinBox("Custom Root", {
 219 |     root: document.querySelector("main")
 220 | });
221 |
222 |
Run Code
223 |

224 | 225 |
226 |
227 | Custom Border 228 |

229 |
new WinBox("Custom Border", {
 230 |     border: "0.3em"
 231 | });
232 |
233 |
Run Code
234 |

235 | 236 |
237 |
238 | Custom Color 239 |

240 |
new WinBox({
 241 |     title: "Custom Color",
 242 |     background: "#ff005d",
 243 |     border: 4
 244 | });
245 |
246 |
Run Code
247 |

248 | 249 |
250 |
251 | Custom Icon (Titlebar) 252 |

253 |
new WinBox({
 254 |     title: "Custom Icon",
 255 |     icon: "demo/wikipedia.svg",
 256 |     background: "#252b4e"
 257 | });
258 |
259 |
Run Code
260 |

261 | 262 |
263 |
264 | Limit Viewport 265 |

266 |
new WinBox("Limit Viewport", {
 267 |     top: 50,
 268 |     right: 50,
 269 |     bottom: 0,
 270 |     left: 50
 271 | });
272 |
273 |
Run Code
274 |

275 | 276 |
277 |
278 | Splitscreen 279 |

280 |
new WinBox("Splitscreen (Left)", {
 281 |     right: "50%",
 282 |     max: true
 283 | });
 284 | 
 285 | new WinBox("Splitscreen (Right)", {
 286 |     left: "50%",
 287 |     max: true
 288 | });
289 |
290 |
Run Code
291 |

292 | 293 |
294 |
295 | Custom Position / Size 296 |

297 |
new WinBox({
 298 |     title: "Custom Position / Size",
 299 |     x: "center",
 300 |     y: "center",
 301 |     width: "50%",
 302 |     height: "50%"
 303 | });
304 |
305 |
Run Code
306 |

307 | 308 |
309 |
310 | Modal Window 311 |

312 |
new WinBox("Modal Window", {
 313 |     modal: true
 314 | });
315 |
316 |
Run Code
317 |

318 | 319 |
320 |
321 | Set innerHTML 322 |

323 |
new WinBox({
 324 |     title: "Set innerHTML",
 325 |     html: "<h1>Lorem Ipsum</h1>"
 326 | });
327 |
328 |
Run Code
329 |

330 | 331 |
332 |
333 | Mount DOM (Cloned) 334 |

335 | 336 |
<div id="backstore" style="display: none">
 337 |     <div id="content">
 338 |         <h1>Lorem Ipsum</h1>
 339 |         <p>Lorem ipsum [...]</p>
 340 |         <p>Duis autem vel [...]</p>
 341 |         <p>Ut wisi enim [...]</p>
 342 |     </div>
 343 | </div>
344 |
345 |
new WinBox("Mount DOM", {
 346 |     mount: document.getElementById("content")
 347 |                    .cloneNode(true)
 348 | });
349 |
350 |
Run Code
351 |

352 | 353 |
354 |
355 | Mount DOM (Singleton) + Auto-Unmount 356 |

357 |
new WinBox("Mount DOM", {
 358 |     mount: document.getElementById("content")
 359 | });
360 |
361 |
Run Code
362 |

363 | 364 |
365 |
366 | Open URI / URL 367 |

368 |
new WinBox("WinBox.js", {
 369 |     url: "https://nextapps-de.github.io/winbox/"
 370 | });
371 |
372 |
Run Code
373 |

374 | 375 |
376 |
377 | All Options 378 |

379 |
new WinBox({
 380 |     // configuration:
 381 |     index: 1,
 382 |     id: "my-window",
 383 |     root: document.body,
 384 |     class: ["no-full", "no-max", "my-theme"],
 385 | 
 386 |     // appearance:
 387 |     title: "All Options",
 388 |     background: "#fff",
 389 |     border: 4,
 390 |     header: 45,
 391 |     icon: false,
 392 | 
 393 |     // initial state:
 394 |     modal: false,
 395 |     max: false,
 396 |     min: false,
 397 |     hidden: false,
 398 | 
 399 |     // dimension:
 400 |     width: 250,
 401 |     height: 200,
 402 |     minheight: 55,
 403 |     minwidth: 100,
 404 |     maxheight: 300,
 405 |     maxwidth: 500,
 406 |     autosize: true,
 407 | 
 408 |     // position:
 409 |     x: "center",
 410 |     y: "center",
 411 | 
 412 |     // viewport boundaries:
 413 |     top: 50,
 414 |     right: 50,
 415 |     bottom: 0,
 416 |     left: 50,
 417 | 
 418 |     // contents (choose from):
 419 |     url: false,
 420 |     mount: false,
 421 |     html: "width: 250, height: 200",
 422 | 
 423 |     // callbacks:
 424 |     oncreate: function(options){
 425 |         options.icon = "demo/wikipedia.svg"
 426 |     },
 427 |     onshow: function(){
 428 |         console.log("Show:", this.id);
 429 |     },
 430 |     onhide: function(){
 431 |         console.log("Hide:", this.id);
 432 |     },
 433 |     onfocus: function(){
 434 |         this.setBackground("#fff");
 435 |     },
 436 |     onblur: function(){
 437 |         this.setBackground("#999");
 438 |     },
 439 |     onresize: function(w, h){
 440 |         this.body.textContent =
 441 |             `width: ${w}, height: ${h}`;
 442 |     },
 443 |     onmove: function(x, y){
 444 |         this.body.textContent =
 445 |             `x: ${x}, y: ${y}`;
 446 |     },
 447 |     onclose: function(force){
 448 |         return !confirm("Close window?");
 449 |     },
 450 |     onfullscreen: function(){
 451 |         console.log("Fullscreen:", this.id);
 452 |     },
 453 |     onmaximize: function(){
 454 |         console.log("Maximize:", this.id);
 455 |     },
 456 |     onminimize: function(){
 457 |         console.log("Minimize:", this.id);
 458 |     },
 459 |     onrestore: function(){
 460 |         console.log("Restore:", this.id);
 461 |     }
 462 | });
463 |
464 |
Run Code
465 |

466 | 467 |
468 |
469 | Control Programmatically 470 |

471 |
<div id="controls">
 472 |     <button onclick="buttons.minimize()">Minimize (Toggle)</button>
 473 |     <button onclick="buttons.maximize()">Maximize (Toggle)</button>
 474 |     <button onclick="buttons.fullscreen()">Fullscreen (Toggle)</button>
 475 |     <button onclick="buttons.move()">Move (Center, Center)</button>
 476 |     <button onclick="buttons.resize()">Resize (50%, 50%)</button>
 477 |     <button onclick="buttons.title()">Set Title</button>
 478 |     <button onclick="buttons.color()">Set Color</button>
 479 |     <button onclick="buttons.close()">Close</button>
 480 | </div>
481 |
482 |
var winbox = new WinBox("Controls", {
 483 |     mount: document.getElementById("controls"),
 484 |     border: 4,
 485 |     onclose: function(force){
 486 |         return !force && !confirm("Close window?");
 487 |     }
 488 | });
489 |
490 |
window.buttons = {
 491 |     minimize: function(){
 492 | 
 493 |         winbox.minimize(!this.min);
 494 |     },
 495 |     maximize: function(){
 496 | 
 497 |         winbox.maximize(!this.max);
 498 |     },
 499 |     fullscreen: function(){
 500 | 
 501 |         winbox.fullscreen(!this.full);
 502 |     },
 503 |     move: function(){
 504 | 
 505 |         winbox.move("center", "center");
 506 |     },
 507 |     resize: function(){
 508 | 
 509 |         winbox.resize("50%", "50%");
 510 |     },
 511 |     title: function(){
 512 | 
 513 |         winbox.setTitle("Title-" + Math.random());
 514 |     },
 515 |     color: function(){
 516 | 
 517 |         winbox.setBackground(
 518 |             "rgb(" + (Math.random() * 255 | 0) + "," +
 519 |                      (Math.random() * 255 | 0) + "," +
 520 |                      (Math.random() * 255 | 0) + ")"
 521 |         );
 522 |     },
 523 |     modal: function(){
 524 | 
 525 |         winbox.toggleClass("modal");
 526 |     },
 527 |     close: function(){
 528 | 
 529 |         winbox.close();
 530 |     },
 531 |     force_close: function(){
 532 | 
 533 |         winbox.close(true);
 534 |     }
 535 | };
536 |
537 |
Run Code
538 |

539 | 540 |
541 |
542 | Window Boilerplate 543 |

544 | WinBox Boilerplate 545 | 546 |
547 |
548 | Custom Styles (Global) 549 |

550 |
.winbox {
 551 |     background: linear-gradient(90deg, #ff00f0, #0050ff);
 552 |     border-radius: 12px 12px 0 0;
 553 |     box-shadow: none;
 554 | }
 555 | 
 556 | .winbox.min {
 557 |     border-radius: 0;
 558 | }
 559 | 
 560 | .wb-body {
 561 |     /* set the width of window border via margin: */
 562 |     margin: 4px;
 563 |     color: #fff;
 564 |     background: #131820;
 565 | }
 566 | 
 567 | .wb-title {
 568 |     font-size: 13px;
 569 |     text-transform: uppercase;
 570 |     font-weight: 600;
 571 | }
572 |
573 | 574 | Customize Control Icons 575 |

576 |
.wb-control * {
 577 |     opacity: 0.65;
 578 | }
 579 | 
 580 | .wb-control *:hover {
 581 |     opacity: 1;
 582 | }
 583 | 
 584 | .wb-min {
 585 |     background-image: url(src/img/min.svg);
 586 |     background-size: 15px center;
 587 | }
 588 | 
 589 | .wb-max {
 590 |     background-image: url(src/img/max.svg);
 591 | }
 592 | 
 593 | .wb-close {
 594 |     background-image: url(src/img/close.svg);
 595 | }
 596 | 
 597 | .wb-full {
 598 |     display: none;
 599 | }
600 |
601 | 602 | Custom Scrollbars 603 |

604 |
.wb-body::-webkit-scrollbar {
 605 |     width: 12px;
 606 | }
 607 | .wb-body::-webkit-scrollbar-track {
 608 |     background: transparent;
 609 | }
 610 | .wb-body::-webkit-scrollbar-thumb {
 611 |     border-radius: 10px;
 612 |     background: #263040;
 613 | }
 614 | .wb-body::-webkit-scrollbar-thumb:window-inactive {
 615 |     background: #181f2a;
 616 | }
 617 | .wb-body::-webkit-scrollbar-corner {
 618 |     background: transparent;
 619 | }
620 |
621 |
new WinBox("Custom CSS", {
 622 |     mount: document.getElementById("content")
 623 |                    .cloneNode(true)
 624 | });
625 |
626 |
Run Code
627 |

628 | 629 |
630 |
631 | Custom Styles By Classname 632 |

633 |
.winbox.my-theme{
 634 |     background: #fff;
 635 | }
 636 | .winbox.my-theme .wb-body {
 637 |     color: #fff;
 638 |     background: #131820;
 639 | }
 640 | .winbox.my-theme .wb-title {
 641 |     color: #000;
 642 | }
 643 | .winbox.my-theme .wb-control {
 644 |     filter: invert(1);
 645 | }
646 |
647 |
new WinBox("Custom CSS (Class)", {
 648 |     class: "my-theme",
 649 |     mount: document.getElementById("content")
 650 |                    .cloneNode(true)
 651 | });
652 |
653 |
Run Code
654 |

655 | 656 |
657 |
658 | Use Theme 659 |

660 |
<head>
 661 | <link rel="stylesheet" href="dist/css/winbox.min.css">
 662 | <link rel="stylesheet" href="dist/css/themes/modern.min.css">
 663 | <script src="dist/js/winbox.min.js"></script>
 664 | </head>
665 |
666 |
new WinBox("Theme", {
 667 |     class: "modern",
 668 |     mount: document.getElementById("content")
 669 |                    .cloneNode(true)
 670 | });
671 |
672 |
Run Code
673 |

674 | 675 |
676 |
677 | Custom Controls 678 |

679 |
.wb-like {
 680 |     background-size: 20px auto;
 681 | }
 682 | .wb-like.active {
 683 |     background-image: url(demo/heart-filled.svg) !important;
 684 | }
685 |
686 |
const winbox = new WinBox("Custom Controls");
 687 | winbox.removeControl("wb-max").removeControl("wb-min");
 688 | winbox.addControl({
 689 |     index: 0,
 690 |     class: "wb-like",
 691 |     image: "demo/heart.svg",
 692 |     click: function(event, winbox){
 693 |         // the winbox instance will be passed as 2nd parameter
 694 |         console.log(winbox.id);
 695 |         // "this" refers to the button which was clicked:
 696 |         this.classList.toggle("active");
 697 |     }
 698 | });
699 |
700 |
Run Code
701 |

702 | 703 |
704 |
705 | Custom Template (Layout) 706 |

707 |
.wb-custom {
 708 |     background-image: url(demo/icon-github.svg);
 709 |     background-size: 17px auto;
 710 | }
711 |
712 |
const template = document.createElement("div");
 713 | template.innerHTML = `
 714 |     <div class=wb-header>
 715 |         <div class=wb-control>
 716 |             <span class=wb-custom></span>
 717 |             <span class=wb-close></span>
 718 |         </div>
 719 |         <div class=wb-drag>
 720 |             <div class=wb-title></div>
 721 |         </div>
 722 |     </div>
 723 |     <div class=wb-body></div>
 724 | `;
 725 | 
 726 | new WinBox("Custom Template", { template });
727 |
728 |
Run Code
729 |

730 | 731 |
732 |
733 | 756 | 757 | 1112 | 1113 | 1114 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "winbox", 3 | "version": "0.2.82", 4 | "description": "Modern HTML5 window manager for the web.", 5 | "homepage": "https://nextapps-de.github.io/winbox/", 6 | "author": "Thomas Wilkerling", 7 | "copyright": "Nextapps GmbH", 8 | "license": "Apache-2.0", 9 | "keywords": [ 10 | "windowmanager", 11 | "windows", 12 | "popup", 13 | "window-manager", 14 | "desktop", 15 | "window", 16 | "frame", 17 | "box" 18 | ], 19 | "bugs": { 20 | "url": "https://github.com/nextapps-de/winbox/issues", 21 | "email": "info@nextapps.de" 22 | }, 23 | "main": "src/js/winbox.js", 24 | "type": "module", 25 | "browser": "dist/winbox.bundle.min.js", 26 | "preferGlobal": false, 27 | "repository": { 28 | "type": "git", 29 | "url": "https://github.com/nextapps-de/winbox.git" 30 | }, 31 | "scripts": { 32 | "copy": "cpx \"src/img/*.*\" dist/img/", 33 | "clean": "node task/clean", 34 | "build:css": "lessc src/css/winbox.less src/css/winbox.css", 35 | "build:css:bundle": "node task/bundle --image && lessc --autoprefix=\">=1%\" --clean-css=\"--s1 --advanced --rebase\" tmp/bundle.less dist/css/winbox.min.css && csso dist/css/winbox.min.css --output dist/css/winbox.min.css", 36 | "build:css:theme-modern": "lessc --autoprefix=\">=1%\" --clean-css=\"--s1 --advanced --rebase\" src/css/themes/modern.less dist/css/themes/modern.min.css && csso dist/css/themes/modern.min.css --output dist/css/themes/modern.min.css", 37 | "build:css:theme-white": "lessc --autoprefix=\">=1%\" --clean-css=\"--s1 --advanced --rebase\" src/css/themes/white.less dist/css/themes/white.min.css && csso dist/css/themes/white.min.css --output dist/css/themes/white.min.css", 38 | "build:js": "node task/build", 39 | "build:bundle": "node task/build --bundle", 40 | "build:svg": "node task/svgo", 41 | "build": "npm run clean && npm run copy && npm run build:svg && npm run build:css && npm run build:css:bundle && npm run build:css:theme-modern && npm run build:css:theme-white && node task/bundle --style && npm run build:js && npm run build:bundle && echo Build Complete. && exit 0", 42 | "server": "node task/server.js" 43 | }, 44 | "files": [ 45 | "dist/", 46 | "src/", 47 | "task/", 48 | "README.md", 49 | "CHANGELOG.md", 50 | "LICENSE" 51 | ], 52 | "readme": "README.md", 53 | "dependencies": {}, 54 | "devDependencies": { 55 | "base64-img": "^1.0.4", 56 | "cpx": "^1.5.0", 57 | "csso": "^5.0.4", 58 | "csso-cli": "^4.0.1", 59 | "google-closure-compiler": "^20220719.0.0", 60 | "less": "^4.1.3", 61 | "less-plugin-autoprefix": "^2.0.0", 62 | "less-plugin-clean-css": "^1.5.1", 63 | "svgo": "^2.8.0", 64 | "web-servo": "^0.5.1" 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/css/control.less: -------------------------------------------------------------------------------- 1 | .no-animation { 2 | transition: none; 3 | } 4 | 5 | .no-shadow { 6 | box-shadow: none; 7 | } 8 | 9 | .no-header { 10 | .wb-header { 11 | display: none; 12 | } 13 | .wb-body { 14 | top: 0; 15 | } 16 | } 17 | 18 | .no-min .wb-min { 19 | display: none; 20 | } 21 | 22 | .no-max .wb-max { 23 | display: none; 24 | } 25 | 26 | .no-full .wb-full { 27 | display: none; 28 | } 29 | 30 | .no-close .wb-close { 31 | display: none; 32 | } 33 | 34 | .no-resize .wb-body ~ div { 35 | display: none; 36 | } 37 | 38 | .no-move:not(.min) .wb-title { 39 | pointer-events: none; 40 | } 41 | 42 | .wb-body .wb-hide { 43 | display: none; 44 | } 45 | .wb-show { 46 | display: none; 47 | } 48 | .wb-body .wb-show { 49 | display: revert; 50 | } 51 | -------------------------------------------------------------------------------- /src/css/images.less: -------------------------------------------------------------------------------- 1 | @max: "../img/max.svg"; 2 | @close: "../img/close.svg"; 3 | @full: "../img/full.svg"; 4 | @min: "../img/min.svg"; 5 | @restore: "../img/restore.svg"; 6 | -------------------------------------------------------------------------------- /src/css/themes/modern.less: -------------------------------------------------------------------------------- 1 | .winbox.modern { 2 | & { 3 | background: linear-gradient(90deg, #ff00f0, #0050ff); 4 | border-radius: 12px 12px 0 0; 5 | animation: popup 0.3s cubic-bezier(0.3, 1, 0.3, 1) forwards; 6 | } 7 | 8 | //&.min:not(:hover), 9 | &:not(.min,.focus) { 10 | background: #666; 11 | } 12 | 13 | // hover fix for mobile devices which keeps the :hover state when touched 14 | 15 | @media (hover: hover) { 16 | &.min:not(:hover) { 17 | background: #666; 18 | } 19 | 20 | .wb-control * { 21 | opacity: 0.65; 22 | } 23 | 24 | .wb-control *:hover { 25 | opacity: 1; 26 | } 27 | } 28 | 29 | @media (hover: none) { 30 | &.min { 31 | background: #666; 32 | } 33 | } 34 | 35 | //&.min, 36 | &.max { 37 | border-radius: 0; 38 | } 39 | 40 | .wb-title { 41 | font-size: 13px; 42 | text-transform: uppercase; 43 | font-weight: 600; 44 | } 45 | 46 | .wb-body { 47 | 48 | & { 49 | /* width of window border: */ 50 | margin: 4px; 51 | color: #fff; 52 | background: #131820; 53 | } 54 | 55 | &::-webkit-scrollbar { 56 | width: 12px; 57 | height: 12px; 58 | } 59 | 60 | &::-webkit-scrollbar-track { 61 | background: transparent; 62 | } 63 | 64 | &::-webkit-scrollbar-thumb { 65 | border-radius: 10px; 66 | background: #263040; 67 | } 68 | 69 | &::-webkit-scrollbar-thumb:window-inactive { 70 | background: #181f2a; 71 | } 72 | 73 | &::-webkit-scrollbar-corner { 74 | background: transparent; 75 | } 76 | } 77 | } 78 | 79 | @keyframes popup { 80 | 0% { 81 | transform: scale(0.8); 82 | } 83 | 100% { 84 | transform: scale(1); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/css/themes/white.less: -------------------------------------------------------------------------------- 1 | .winbox.white { 2 | & { 3 | background: #fff; 4 | } 5 | 6 | .wb-title { 7 | color: #000; 8 | } 9 | 10 | .wb-control { 11 | filter: invert(1); 12 | } 13 | } -------------------------------------------------------------------------------- /src/css/winbox.css: -------------------------------------------------------------------------------- 1 | .winbox { 2 | position: fixed; 3 | left: 0; 4 | top: 0; 5 | background: #0050ff; 6 | box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22); 7 | /* using transform make contents blur when applied and requires more gpu memory */ 8 | transition: width 0.3s, height 0.3s, left 0.3s, top 0.3s; 9 | transition-timing-function: cubic-bezier(0.3, 1, 0.3, 1); 10 | /* contain "strict" does not make overflow contents selectable */ 11 | contain: layout size; 12 | /* explicitly set text align to left fixes an issue with iframes alignment when centered */ 13 | text-align: left; 14 | /* workaround for using passive listeners */ 15 | touch-action: none; 16 | } 17 | .wb-header { 18 | position: absolute; 19 | left: 0; 20 | top: 0; 21 | width: 100%; 22 | height: 35px; 23 | line-height: 35px; 24 | color: #fff; 25 | overflow: hidden; 26 | z-index: 1; 27 | } 28 | .wb-body { 29 | position: absolute; 30 | top: 35px; 31 | left: 0; 32 | right: 0; 33 | bottom: 0; 34 | overflow: auto; 35 | -webkit-overflow-scrolling: touch; 36 | overflow-scrolling: touch; 37 | will-change: contents; 38 | background: #fff; 39 | /* when no border is set there is some thin line visible */ 40 | /* always hide top border visually */ 41 | margin-top: 0 !important; 42 | contain: strict; 43 | z-index: 0; 44 | } 45 | /* 46 | body > .wb-body{ 47 | position: relative; 48 | display: inline-block; 49 | visibility: hidden; 50 | contain: none; 51 | } 52 | */ 53 | .wb-drag { 54 | height: 100%; 55 | padding-left: 10px; 56 | cursor: move; 57 | } 58 | .wb-title { 59 | font-family: Arial, sans-serif; 60 | font-size: 14px; 61 | white-space: nowrap; 62 | overflow: hidden; 63 | text-overflow: ellipsis; 64 | } 65 | .wb-icon { 66 | display: none; 67 | width: 20px; 68 | height: 100%; 69 | margin: -1px 8px 0 -3px; 70 | float: left; 71 | background-repeat: no-repeat; 72 | background-size: 100%; 73 | background-position: center; 74 | } 75 | .wb-n { 76 | position: absolute; 77 | top: -5px; 78 | left: 0; 79 | right: 0; 80 | height: 10px; 81 | cursor: n-resize; 82 | z-index: 2; 83 | } 84 | .wb-e { 85 | position: absolute; 86 | top: 0; 87 | right: -5px; 88 | bottom: 0; 89 | width: 10px; 90 | cursor: w-resize; 91 | z-index: 2; 92 | } 93 | .wb-s { 94 | position: absolute; 95 | bottom: -5px; 96 | left: 0; 97 | right: 0; 98 | height: 10px; 99 | cursor: n-resize; 100 | z-index: 2; 101 | } 102 | .wb-w { 103 | position: absolute; 104 | top: 0; 105 | left: -5px; 106 | bottom: 0; 107 | width: 10px; 108 | cursor: w-resize; 109 | z-index: 2; 110 | } 111 | .wb-nw { 112 | position: absolute; 113 | top: -5px; 114 | left: -5px; 115 | width: 15px; 116 | height: 15px; 117 | cursor: nw-resize; 118 | z-index: 2; 119 | } 120 | .wb-ne { 121 | position: absolute; 122 | top: -5px; 123 | right: -5px; 124 | width: 15px; 125 | height: 15px; 126 | cursor: ne-resize; 127 | z-index: 2; 128 | } 129 | .wb-sw { 130 | position: absolute; 131 | bottom: -5px; 132 | left: -5px; 133 | width: 15px; 134 | height: 15px; 135 | cursor: ne-resize; 136 | z-index: 2; 137 | } 138 | .wb-se { 139 | position: absolute; 140 | bottom: -5px; 141 | right: -5px; 142 | width: 15px; 143 | height: 15px; 144 | cursor: nw-resize; 145 | z-index: 2; 146 | } 147 | .wb-control { 148 | float: right; 149 | height: 100%; 150 | max-width: 100%; 151 | text-align: center; 152 | } 153 | .wb-control * { 154 | display: inline-block; 155 | width: 30px; 156 | height: 100%; 157 | max-width: 100%; 158 | background-position: center; 159 | background-repeat: no-repeat; 160 | cursor: pointer; 161 | } 162 | .wb-min { 163 | background-image: url("../img/min.svg"); 164 | background-size: 14px auto; 165 | background-position: center calc(50% + 6px); 166 | } 167 | .wb-max { 168 | background-image: url("../img/max.svg"); 169 | background-size: 17px auto; 170 | } 171 | .wb-close { 172 | background-image: url("../img/close.svg"); 173 | background-size: 15px auto; 174 | background-position: 5px center; 175 | } 176 | .wb-full { 177 | background-image: url("../img/full.svg"); 178 | background-size: 16px auto; 179 | } 180 | /* 181 | .winbox:not(.max) .wb-max { 182 | background-image: url(@restore); 183 | background-size: 20px auto; 184 | background-position: center bottom 5px; 185 | } 186 | */ 187 | /* 188 | .winbox:fullscreen{ 189 | transition: none !important; 190 | } 191 | .winbox:fullscreen .wb-full{ 192 | background-image: url(@minimize); 193 | } 194 | .winbox:fullscreen > div, 195 | .winbox:fullscreen .wb-title, 196 | */ 197 | .winbox.modal .wb-body ~ div, 198 | .winbox.modal .wb-drag, 199 | .winbox.min .wb-body ~ div, 200 | .winbox.max .wb-body ~ div { 201 | pointer-events: none; 202 | } 203 | .winbox.max .wb-drag { 204 | cursor: default; 205 | } 206 | .winbox.min .wb-full, 207 | .winbox.min .wb-min { 208 | display: none; 209 | } 210 | .winbox.min .wb-drag { 211 | cursor: default; 212 | } 213 | .winbox.min .wb-body > * { 214 | display: none; 215 | } 216 | .winbox.hide { 217 | display: none; 218 | } 219 | .winbox.max { 220 | box-shadow: none; 221 | } 222 | .winbox.max .wb-body { 223 | margin: 0 !important; 224 | } 225 | .winbox iframe { 226 | position: absolute; 227 | width: 100%; 228 | height: 100%; 229 | border: 0; 230 | } 231 | body.wb-lock .winbox { 232 | will-change: left, top, width, height; 233 | transition: none; 234 | } 235 | body.wb-lock iframe { 236 | pointer-events: none; 237 | } 238 | .winbox.modal:before { 239 | content: ''; 240 | position: absolute; 241 | top: 0; 242 | left: 0; 243 | right: 0; 244 | bottom: 0; 245 | background: inherit; 246 | border-radius: inherit; 247 | } 248 | .winbox.modal:after { 249 | content: ''; 250 | position: absolute; 251 | top: -50vh; 252 | left: -50vw; 253 | right: -50vw; 254 | bottom: -50vh; 255 | background: #0d1117; 256 | animation: wb-fade-in 0.2s ease-out forwards; 257 | z-index: -1; 258 | } 259 | .winbox.modal .wb-min, 260 | .winbox.modal .wb-max, 261 | .winbox.modal .wb-full { 262 | display: none; 263 | } 264 | @keyframes wb-fade-in { 265 | 0% { 266 | opacity: 0; 267 | } 268 | 100% { 269 | opacity: 0.85; 270 | } 271 | } 272 | .no-animation { 273 | transition: none; 274 | } 275 | .no-shadow { 276 | box-shadow: none; 277 | } 278 | .no-header .wb-header { 279 | display: none; 280 | } 281 | .no-header .wb-body { 282 | top: 0; 283 | } 284 | .no-min .wb-min { 285 | display: none; 286 | } 287 | .no-max .wb-max { 288 | display: none; 289 | } 290 | .no-full .wb-full { 291 | display: none; 292 | } 293 | .no-close .wb-close { 294 | display: none; 295 | } 296 | .no-resize .wb-body ~ div { 297 | display: none; 298 | } 299 | .no-move:not(.min) .wb-title { 300 | pointer-events: none; 301 | } 302 | .wb-body .wb-hide { 303 | display: none; 304 | } 305 | .wb-show { 306 | display: none; 307 | } 308 | .wb-body .wb-show { 309 | display: revert; 310 | } 311 | -------------------------------------------------------------------------------- /src/css/winbox.less: -------------------------------------------------------------------------------- 1 | @import "images.less"; 2 | @winbox-header-height: 35px; 3 | 4 | .winbox { 5 | position: fixed; 6 | left: 0; 7 | top: 0; 8 | background: #0050ff; 9 | box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22); 10 | /* using transform make contents blur when applied and requires more gpu memory */ 11 | //transition: width .3s, height .3s, transform .3s; 12 | transition: width .3s, height .3s, left .3s, top .3s; 13 | transition-timing-function: cubic-bezier(0.3, 1, 0.3, 1); 14 | //transform-origin: bottom center; 15 | /* contain "strict" does not make overflow contents selectable */ 16 | contain: layout size; 17 | /* explicitly set text align to left fixes an issue with iframes alignment when centered */ 18 | text-align: left; 19 | /* workaround for using passive listeners */ 20 | touch-action: none; 21 | } 22 | 23 | .wb-header { 24 | position: absolute; 25 | left: 0; 26 | top: 0; 27 | width: 100%; 28 | height: @winbox-header-height; 29 | line-height: @winbox-header-height; 30 | color: #fff; 31 | overflow: hidden; 32 | z-index: 1; 33 | } 34 | 35 | .wb-body { 36 | position: absolute; 37 | top: @winbox-header-height; 38 | left: 0; 39 | right: 0; 40 | bottom: 0; 41 | overflow: auto; 42 | -webkit-overflow-scrolling: touch; 43 | overflow-scrolling: touch; 44 | will-change: contents; 45 | background: #fff; 46 | /* when no border is set there is some thin line visible */ 47 | //margin: -1px; 48 | /* always hide top border visually */ 49 | margin-top: 0 !important; 50 | contain: strict; 51 | //content-visibility: auto; 52 | z-index: 0; 53 | } 54 | /* 55 | body > .wb-body{ 56 | position: relative; 57 | display: inline-block; 58 | visibility: hidden; 59 | contain: none; 60 | } 61 | */ 62 | 63 | .wb-drag{ 64 | height: 100%; 65 | padding-left: 10px; 66 | cursor: move; 67 | } 68 | 69 | .wb-title{ 70 | font-family : Arial, sans-serif; 71 | font-size: 14px; 72 | white-space: nowrap; 73 | overflow: hidden; 74 | text-overflow: ellipsis; 75 | } 76 | 77 | .wb-icon { 78 | display: none; 79 | width: 20px; 80 | height: 100%; 81 | margin: -1px 8px 0 -3px; 82 | float: left; 83 | background-repeat: no-repeat; 84 | background-size: 100%; 85 | background-position: center; 86 | } 87 | 88 | .wb-n { 89 | position: absolute; 90 | top: -5px; 91 | left: 0; 92 | right: 0; 93 | height: 10px; 94 | cursor: n-resize; 95 | z-index: 2; 96 | } 97 | 98 | .wb-e { 99 | position: absolute; 100 | top: 0; 101 | right: -5px; 102 | bottom: 0; 103 | width: 10px; 104 | cursor: w-resize; 105 | z-index: 2; 106 | } 107 | 108 | .wb-s { 109 | position: absolute; 110 | bottom: -5px; 111 | left: 0; 112 | right: 0; 113 | height: 10px; 114 | cursor: n-resize; 115 | z-index: 2; 116 | } 117 | 118 | .wb-w { 119 | position: absolute; 120 | top: 0; 121 | left: -5px; 122 | bottom: 0; 123 | width: 10px; 124 | cursor: w-resize; 125 | z-index: 2; 126 | } 127 | 128 | .wb-nw { 129 | position: absolute; 130 | top: -5px; 131 | left: -5px; 132 | width: 15px; 133 | height: 15px; 134 | cursor: nw-resize; 135 | z-index: 2; 136 | } 137 | 138 | .wb-ne { 139 | position: absolute; 140 | top: -5px; 141 | right: -5px; 142 | width: 15px; 143 | height: 15px; 144 | cursor: ne-resize; 145 | z-index: 2; 146 | } 147 | 148 | .wb-sw { 149 | position: absolute; 150 | bottom: -5px; 151 | left: -5px; 152 | width: 15px; 153 | height: 15px; 154 | cursor: ne-resize; 155 | z-index: 2; 156 | } 157 | 158 | .wb-se { 159 | position: absolute; 160 | bottom: -5px; 161 | right: -5px; 162 | width: 15px; 163 | height: 15px; 164 | cursor: nw-resize; 165 | z-index: 2; 166 | } 167 | 168 | .wb-control{ 169 | float: right; 170 | height: 100%; 171 | max-width: 100%; 172 | text-align: center; 173 | } 174 | 175 | .wb-control * { 176 | display: inline-block; 177 | width: 30px; 178 | height: 100%; 179 | max-width: 100%; 180 | background-position: center; 181 | background-repeat: no-repeat; 182 | cursor: pointer; 183 | } 184 | 185 | .wb-min { 186 | background-image: url(@min); 187 | background-size: 14px auto; 188 | background-position: center calc(50% + 6px); 189 | } 190 | 191 | .wb-max { 192 | background-image: url(@max); 193 | background-size: 17px auto; 194 | } 195 | 196 | .wb-close { 197 | background-image: url(@close); 198 | background-size: 15px auto; 199 | background-position: 5px center; 200 | } 201 | 202 | .wb-full { 203 | background-image: url(@full); 204 | background-size: 16px auto; 205 | } 206 | 207 | /* 208 | .winbox:not(.max) .wb-max { 209 | background-image: url(@restore); 210 | background-size: 20px auto; 211 | background-position: center bottom 5px; 212 | } 213 | */ 214 | 215 | /* 216 | .winbox:fullscreen{ 217 | transition: none !important; 218 | } 219 | .winbox:fullscreen .wb-full{ 220 | background-image: url(@minimize); 221 | } 222 | .winbox:fullscreen > div, 223 | .winbox:fullscreen .wb-title, 224 | */ 225 | 226 | .winbox.modal .wb-body ~ div, 227 | .winbox.modal .wb-drag, 228 | .winbox.min .wb-body ~ div, 229 | .winbox.max .wb-body ~ div { 230 | pointer-events: none; 231 | } 232 | .winbox.max .wb-drag{ 233 | cursor: default; 234 | } 235 | 236 | .winbox.min { 237 | .wb-full, 238 | .wb-min { 239 | display: none; 240 | } 241 | .wb-drag { 242 | cursor: default; 243 | } 244 | .wb-body > *{ 245 | display: none; 246 | } 247 | } 248 | 249 | .winbox.hide { 250 | display: none; 251 | //visibility: hidden; 252 | } 253 | 254 | .winbox.max { 255 | box-shadow: none; 256 | } 257 | 258 | .winbox.max .wb-body { 259 | margin: 0 !important; 260 | } 261 | 262 | .winbox iframe{ 263 | position: absolute; 264 | width: 100%; 265 | height: 100%; 266 | border: 0; 267 | } 268 | 269 | body.wb-lock .winbox{ 270 | will-change: left, top, width, height; 271 | transition: none; 272 | } 273 | body.wb-lock iframe { 274 | pointer-events: none; 275 | } 276 | 277 | .winbox.modal{ 278 | &:before{ 279 | content: ''; 280 | position: absolute; 281 | top: 0; 282 | left: 0; 283 | right: 0; 284 | bottom: 0; 285 | background: inherit; 286 | border-radius: inherit; 287 | } 288 | &:after{ 289 | content: ''; 290 | position: absolute; 291 | top: -50vh; 292 | left: -50vw; 293 | right: -50vw; 294 | bottom: -50vh; 295 | background: #0d1117; 296 | animation: wb-fade-in 0.2s ease-out forwards; 297 | z-index: -1; 298 | } 299 | .wb-min, 300 | .wb-max, 301 | .wb-full{ 302 | display: none; 303 | } 304 | } 305 | 306 | @keyframes wb-fade-in { 307 | 0%{ 308 | opacity: 0; 309 | } 310 | 100%{ 311 | opacity: 0.85; 312 | } 313 | } 314 | 315 | @import "control.less"; 316 | -------------------------------------------------------------------------------- /src/img/close.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/img/exit.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/img/full.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/img/max.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/img/min.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/img/restore.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/js/helper.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {Window|Element} node 3 | * @param {string} event 4 | * @param {Function} fn 5 | * @param {AddEventListenerOptions|boolean=} opt 6 | */ 7 | 8 | export function addListener(node, event, fn, opt){ 9 | 10 | node && node.addEventListener(event, fn, opt || false); 11 | } 12 | 13 | /** 14 | * @param {Window|Element} node 15 | * @param {string} event 16 | * @param {Function} fn 17 | * @param {AddEventListenerOptions|boolean=} opt 18 | */ 19 | 20 | export function removeListener(node, event, fn, opt){ 21 | 22 | node && node.removeEventListener(event, fn, opt || false); 23 | } 24 | 25 | /** 26 | * @param event 27 | * @param {boolean=} prevent 28 | */ 29 | 30 | export function preventEvent(event, prevent){ 31 | 32 | event.stopPropagation(); 33 | prevent && /*event.cancelable &&*/ event.preventDefault(); 34 | 35 | //event.stopImmediatePropagation(); 36 | //event.returnValue = false; 37 | } 38 | 39 | export function getByClass(root, name){ 40 | 41 | return root.getElementsByClassName(name)[0]; 42 | } 43 | 44 | export function addClass(node, classname){ 45 | 46 | node.classList.add(classname); 47 | } 48 | 49 | export function hasClass(node, classname){ 50 | 51 | return node.classList.contains(classname); 52 | } 53 | 54 | export function removeClass(node, classname){ 55 | 56 | node.classList.remove(classname); 57 | } 58 | 59 | export function setStyle(node, style, value){ 60 | 61 | value = "" + value; 62 | 63 | if(node["_s_" + style] !== value){ 64 | 65 | node.style.setProperty(style, value); 66 | node["_s_" + style] = value; 67 | } 68 | } 69 | 70 | export function setAttribute(node, key, value){ 71 | 72 | value = "" + value; 73 | 74 | if(node["_a_" + key] !== value){ 75 | 76 | node.setAttribute(key, value); 77 | node["_a_" + key] = value; 78 | } 79 | } 80 | 81 | export function removeAttribute(node, key){ 82 | 83 | if(node["_a_" + key] !== null){ 84 | 85 | node.removeAttribute(key); 86 | node["_a_" + key] = null; 87 | } 88 | } 89 | 90 | export function setText(node, value){ 91 | 92 | const textnode = node.firstChild; 93 | textnode ? textnode.nodeValue = value : node.textContent = value; 94 | } 95 | -------------------------------------------------------------------------------- /src/js/template.js: -------------------------------------------------------------------------------- 1 | /** 2 | @type null|HTMLDivElement 3 | */ 4 | let template = null; 5 | const templateHTML = ( 6 | 7 | //'
' + 8 | 9 | '
' + 10 | '
' + 11 | '' + 12 | '' + 13 | '' + 14 | '' + 15 | '
' + 16 | '
'+ 17 | '
' + 18 | '
' + 19 | '
' + 20 | '
' + 21 | 22 | '
' + 23 | 24 | '
' + 25 | '
' + 26 | '
' + 27 | '
' + 28 | '
' + 29 | '
' + 30 | '
' + 31 | '
' 32 | 33 | //'
' 34 | ); 35 | 36 | export default function(tpl){ 37 | if (!template) { 38 | template = document.createElement('div'); 39 | template.innerHTML = templateHTML; 40 | } 41 | 42 | return (tpl || template).cloneNode(true); 43 | } 44 | -------------------------------------------------------------------------------- /src/js/webpack.js: -------------------------------------------------------------------------------- 1 | import WinBox from "./winbox.js"; 2 | 3 | /** @export */ WinBox.new; 4 | /** @export */ WinBox.stack; 5 | /** @export */ WinBox.prototype.mount; 6 | /** @export */ WinBox.prototype.unmount; 7 | /** @export */ WinBox.prototype.move; 8 | /** @export */ WinBox.prototype.resize; 9 | /** @export */ WinBox.prototype.close; 10 | /** @export */ WinBox.prototype.focus; 11 | /** @export */ WinBox.prototype.blur; 12 | /** @export */ WinBox.prototype.hide; 13 | /** @export */ WinBox.prototype.show; 14 | /** @export */ WinBox.prototype.minimize; 15 | /** @export */ WinBox.prototype.maximize; 16 | /** @export */ WinBox.prototype.fullscreen; 17 | /** @export */ WinBox.prototype.restore; 18 | /** @export */ WinBox.prototype.setBackground; 19 | /** @export */ WinBox.prototype.setTitle; 20 | /** @export */ WinBox.prototype.setIcon; 21 | /** @export */ WinBox.prototype.setUrl; 22 | /** @export */ WinBox.prototype.addControl; 23 | /** @export */ WinBox.prototype.removeControl; 24 | /** @export */ WinBox.prototype.addClass; 25 | /** @export */ WinBox.prototype.removeClass; 26 | /** @export */ WinBox.prototype.toggleClass; 27 | /** @export */ //WinBox.prototype.use; 28 | 29 | /** @export */ WinBox.id; 30 | /** @export */ WinBox.window; 31 | /** @export */ WinBox.index; 32 | /** @export */ WinBox.body; 33 | /** @export */ WinBox.min; 34 | /** @export */ WinBox.max; 35 | /** @export */ WinBox.full; 36 | /** @export */ WinBox.hidden; 37 | /** @export */ WinBox.focused; 38 | /** @export */ WinBox.x; 39 | /** @export */ WinBox.y; 40 | /** @export */ WinBox.width; 41 | /** @export */ WinBox.height; 42 | /** @export */ WinBox.top; 43 | /** @export */ WinBox.right; 44 | /** @export */ WinBox.bottom; 45 | /** @export */ WinBox.left; 46 | 47 | /** @export */ WinBox.oncreate; 48 | /** @export */ WinBox.onclose; 49 | /** @export */ WinBox.onfocus; 50 | /** @export */ WinBox.onblur; 51 | /** @export */ WinBox.onmove; 52 | /** @export */ WinBox.onresize; 53 | /** @export */ WinBox.onfullscreen; 54 | /** @export */ WinBox.onmaximize; 55 | /** @export */ WinBox.onminimize; 56 | /** @export */ WinBox.onrestore; 57 | /** @export */ WinBox.onhide; 58 | /** @export */ WinBox.onshow; 59 | 60 | window["WinBox"] = WinBox; 61 | -------------------------------------------------------------------------------- /src/js/winbox.js: -------------------------------------------------------------------------------- 1 | /** 2 | * WinBox.js 3 | * Author and Copyright: Thomas Wilkerling 4 | * Licence: Apache-2.0 5 | * Hosted by Nextapps GmbH 6 | * https://github.com/nextapps-de/winbox 7 | */ 8 | 9 | // TODO: rename control amd state classes (min, max, modal, focus, ...) #62 10 | 11 | import template from "./template.js"; 12 | import { addListener, removeListener, setStyle, setText, getByClass, addClass, removeClass, hasClass, preventEvent } from "./helper.js"; 13 | 14 | //const ios = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window["MSStream"]; 15 | 16 | const use_raf = false; 17 | const stack_min = []; 18 | const stack_win = []; 19 | // use passive for touch and mouse wheel 20 | const eventOptions = { "capture": true, "passive": false }; 21 | const eventOptionsPassive = { "capture": true, "passive": true }; 22 | let body; 23 | let id_counter = 0; 24 | let index_counter = 10; 25 | let is_fullscreen; 26 | let prefix_request; 27 | let prefix_exit; 28 | let root_w, root_h; 29 | let window_clicked; 30 | 31 | /** 32 | * @param {string|Object=} params 33 | * @param {Object=} _title 34 | * @constructor 35 | * @this WinBox 36 | */ 37 | 38 | function WinBox(params, _title){ 39 | 40 | if(!(this instanceof WinBox)) { 41 | 42 | return new WinBox(params); 43 | } 44 | 45 | body || setup(); 46 | 47 | let id, 48 | index, 49 | root, 50 | tpl, 51 | title, 52 | icon, 53 | mount, 54 | html, 55 | url, 56 | 57 | width, 58 | height, 59 | minwidth, 60 | minheight, 61 | maxwidth, 62 | maxheight, 63 | autosize, 64 | overflow, 65 | 66 | x, 67 | y, 68 | 69 | top, 70 | left, 71 | bottom, 72 | right, 73 | 74 | min, 75 | max, 76 | hidden, 77 | modal, 78 | 79 | background, 80 | border, 81 | header, 82 | classname, 83 | 84 | oncreate, 85 | onclose, 86 | onfocus, 87 | onblur, 88 | onmove, 89 | onresize, 90 | onfullscreen, 91 | onmaximize, 92 | onminimize, 93 | onrestore, 94 | onhide, 95 | onshow, 96 | onload; 97 | 98 | if(params){ 99 | 100 | if(_title){ 101 | 102 | title = params; 103 | params = _title; 104 | } 105 | 106 | if(typeof params === "string"){ 107 | 108 | title = params; 109 | } 110 | else{ 111 | 112 | id = params["id"]; 113 | index = params["index"]; 114 | root = params["root"]; 115 | tpl = params["template"]; 116 | title = title || params["title"]; 117 | icon = params["icon"]; 118 | mount = params["mount"]; 119 | html = params["html"]; 120 | url = params["url"]; 121 | 122 | width = params["width"]; 123 | height = params["height"]; 124 | minwidth = params["minwidth"]; 125 | minheight = params["minheight"]; 126 | maxwidth = params["maxwidth"]; 127 | maxheight = params["maxheight"]; 128 | autosize = params["autosize"]; 129 | overflow = params["overflow"]; 130 | 131 | min = params["min"]; 132 | max = params["max"]; 133 | hidden = params["hidden"]; 134 | modal = params["modal"]; 135 | 136 | x = params["x"] || (modal ? "center" : 0); 137 | y = params["y"] || (modal ? "center" : 0); 138 | 139 | top = params["top"]; 140 | left = params["left"]; 141 | bottom = params["bottom"]; 142 | right = params["right"]; 143 | 144 | background = params["background"]; 145 | border = params["border"]; 146 | header = params["header"]; 147 | classname = params["class"]; 148 | 149 | oncreate = params["oncreate"]; 150 | onclose = params["onclose"]; 151 | onfocus = params["onfocus"]; 152 | onblur = params["onblur"]; 153 | onmove = params["onmove"]; 154 | onresize = params["onresize"]; 155 | onfullscreen = params["onfullscreen"]; 156 | onmaximize = params["onmaximize"]; 157 | onminimize = params["onminimize"]; 158 | onrestore = params["onrestore"]; 159 | onhide = params["onhide"]; 160 | onshow = params["onshow"]; 161 | onload = params["onload"]; 162 | } 163 | } 164 | 165 | this.dom = template(tpl); 166 | this.dom.id = this.id = id || ("winbox-" + (++id_counter)); 167 | this.dom.className = "winbox" + (classname ? " " + (typeof classname === "string" ? classname : classname.join(" ")) : "") + (modal ? " modal" : ""); 168 | this.dom["winbox"] = this; 169 | this.window = this.dom; 170 | this.body = getByClass(this.dom, "wb-body"); 171 | this.header = header || 35; 172 | //this.plugins = []; 173 | 174 | stack_win.push(this); 175 | 176 | if(background){ 177 | 178 | this.setBackground(background); 179 | } 180 | 181 | if(border){ 182 | 183 | setStyle(this.body, "margin", border + (isNaN(border) ? "" : "px")); 184 | } 185 | else{ 186 | 187 | border = 0; 188 | } 189 | 190 | if(header){ 191 | 192 | const node = getByClass(this.dom, "wb-header"); 193 | setStyle(node, "height", header + "px"); 194 | setStyle(node, "line-height", header + "px"); 195 | setStyle(this.body, "top", header + "px"); 196 | } 197 | 198 | if(title){ 199 | 200 | this.setTitle(title); 201 | } 202 | 203 | if(icon){ 204 | 205 | this.setIcon(icon); 206 | } 207 | 208 | if(mount){ 209 | 210 | this.mount(mount); 211 | } 212 | else if(html){ 213 | 214 | this.body.innerHTML = html; 215 | } 216 | else if(url){ 217 | 218 | this.setUrl(url, onload); 219 | } 220 | 221 | top = top ? parse(top, root_h) : 0; 222 | bottom = bottom ? parse(bottom, root_h) : 0; 223 | left = left ? parse(left, root_w) : 0; 224 | right = right ? parse(right, root_w) : 0; 225 | 226 | const viewport_w = root_w - left - right; 227 | const viewport_h = root_h - top - bottom; 228 | 229 | maxwidth = maxwidth ? parse(maxwidth, viewport_w) : viewport_w; 230 | maxheight = maxheight ? parse(maxheight, viewport_h) : viewport_h; 231 | minwidth = minwidth ? parse(minwidth, maxwidth) : 150; 232 | minheight = minheight ? parse(minheight, maxheight) : this.header; 233 | 234 | if(autosize){ 235 | 236 | (root || body).appendChild(this.body); 237 | 238 | width = Math.max(Math.min(this.body.clientWidth + border * 2 + 1, maxwidth), minwidth); 239 | height = Math.max(Math.min(this.body.clientHeight + this.header + border + 1, maxheight), minheight); 240 | 241 | this.dom.appendChild(this.body); 242 | } 243 | else{ 244 | 245 | width = width ? parse(width, maxwidth) : Math.max(maxwidth / 2, minwidth) | 0; 246 | height = height ? parse(height, maxheight) : Math.max(maxheight / 2, minheight) | 0; 247 | } 248 | 249 | x = x ? parse(x, viewport_w, width) : left; 250 | y = y ? parse(y, viewport_h, height) : top; 251 | 252 | this.x = x; 253 | this.y = y; 254 | this.width = width; 255 | this.height = height; 256 | this.minwidth = minwidth; 257 | this.minheight = minheight; 258 | this.maxwidth = maxwidth; 259 | this.maxheight = maxheight; 260 | this.top = top; 261 | this.right = right; 262 | this.bottom = bottom; 263 | this.left = left; 264 | this.index = index; 265 | this.overflow = overflow; 266 | //this.border = border; 267 | this.min = false; 268 | this.max = false; 269 | this.full = false; 270 | this.hidden = false; 271 | this.focused = false; 272 | 273 | this.onclose = onclose; 274 | this.onfocus = onfocus; 275 | this.onblur = onblur; 276 | this.onmove = onmove; 277 | this.onresize = onresize; 278 | this.onfullscreen = onfullscreen; 279 | this.onmaximize = onmaximize; 280 | this.onminimize = onminimize; 281 | this.onrestore = onrestore; 282 | this.onhide = onhide; 283 | this.onshow = onshow; 284 | 285 | if(hidden){ 286 | 287 | this.hide(); 288 | } 289 | else{ 290 | 291 | this.focus(); 292 | } 293 | 294 | if(index || (index === 0)){ 295 | 296 | this.index = index; 297 | setStyle(this.dom, "z-index", index); 298 | if(index > index_counter) index_counter = index; 299 | } 300 | 301 | if(max){ 302 | 303 | this.maximize(); 304 | } 305 | else if(min){ 306 | 307 | this.minimize(); 308 | } 309 | else{ 310 | 311 | this.resize().move(); 312 | } 313 | 314 | register(this); 315 | (root || body).appendChild(this.dom); 316 | oncreate && oncreate.call(this, params); 317 | } 318 | 319 | WinBox["new"] = function(params){ 320 | 321 | return new WinBox(params); 322 | }; 323 | 324 | WinBox["stack"] = function(){ 325 | 326 | return stack_win; 327 | }; 328 | 329 | export default WinBox; 330 | 331 | /** 332 | * @param {number|string} num 333 | * @param {number} base 334 | * @param {number=} center 335 | * @return number 336 | */ 337 | 338 | function parse(num, base, center){ 339 | 340 | if(typeof num === "string"){ 341 | 342 | if(num === "center"){ 343 | 344 | num = ((base - center) / 2 + 0.5) | 0; 345 | } 346 | else if(num === "right" || num === "bottom"){ 347 | 348 | num = (base - center); 349 | } 350 | else{ 351 | 352 | const value = parseFloat(num); 353 | const unit = (("" + value) !== num) && num.substring(("" + value).length); 354 | 355 | if(unit === "%"){ 356 | 357 | num = (base / 100 * value + 0.5) | 0; 358 | } 359 | else{ 360 | 361 | num = value; 362 | } 363 | } 364 | } 365 | 366 | return num; 367 | } 368 | 369 | function setup(){ 370 | 371 | body = document.body; 372 | 373 | body[prefix_request = "requestFullscreen"] || 374 | body[prefix_request = "msRequestFullscreen"] || 375 | body[prefix_request = "webkitRequestFullscreen"] || 376 | body[prefix_request = "mozRequestFullscreen"] || 377 | (prefix_request = ""); 378 | 379 | prefix_exit = prefix_request && ( 380 | 381 | prefix_request.replace("request", "exit") 382 | .replace("mozRequest", "mozCancel") 383 | .replace("Request", "Exit") 384 | ); 385 | 386 | addListener(window, "resize", function(){ 387 | 388 | init(); 389 | update_min_stack(); 390 | 391 | // TODO adjust window sizes #151 392 | 393 | // for(let i = 0; i < stack_win.length; i++){ 394 | // 395 | // stack_win[i].resize().move(); 396 | // } 397 | }); 398 | 399 | addListener(body, "mousedown", function(event){ 400 | 401 | window_clicked = false; 402 | 403 | }, true); 404 | 405 | addListener(body, "mousedown", function(event){ 406 | 407 | if(!window_clicked){ 408 | 409 | const stack_length = stack_win.length; 410 | 411 | if(stack_length){ 412 | 413 | for(let i = stack_length - 1; i >= 0; i--){ 414 | 415 | const last_focus = stack_win[i]; 416 | 417 | if(last_focus.focused){ 418 | 419 | last_focus.blur(); 420 | break; 421 | } 422 | } 423 | } 424 | } 425 | }); 426 | 427 | init(); 428 | } 429 | 430 | /** 431 | * @param {WinBox} self 432 | */ 433 | 434 | function register(self){ 435 | 436 | addWindowListener(self, "drag"); 437 | addWindowListener(self, "n"); 438 | addWindowListener(self, "s"); 439 | addWindowListener(self, "w"); 440 | addWindowListener(self, "e"); 441 | addWindowListener(self, "nw"); 442 | addWindowListener(self, "ne"); 443 | addWindowListener(self, "se"); 444 | addWindowListener(self, "sw"); 445 | 446 | addListener(getByClass(self.dom, "wb-min"), "click", function(event){ 447 | 448 | preventEvent(event); 449 | self.min ? self.restore().focus() : self.minimize(); 450 | }); 451 | 452 | addListener(getByClass(self.dom, "wb-max"), "click", function(event){ 453 | 454 | preventEvent(event); 455 | self.max ? self.restore().focus() : self.maximize().focus(); 456 | }); 457 | 458 | if(prefix_request){ 459 | 460 | addListener(getByClass(self.dom, "wb-full"), "click", function(event){ 461 | 462 | preventEvent(event); 463 | self.fullscreen().focus(); 464 | }); 465 | } 466 | else{ 467 | 468 | self.addClass("no-full"); 469 | } 470 | 471 | addListener(getByClass(self.dom, "wb-close"), "click", function(event){ 472 | 473 | preventEvent(event); 474 | self.close() || (self = null); 475 | }); 476 | 477 | addListener(self.dom, "mousedown", function(event){ 478 | 479 | window_clicked = true; 480 | 481 | }, true); 482 | 483 | addListener(self.body, "mousedown", function(event){ 484 | 485 | // stop propagation would disable global listeners used inside window contents 486 | // use event bubbling for this listener to skip this handler by the other click listeners 487 | self.focus(); 488 | 489 | }, true); 490 | } 491 | 492 | /** 493 | * @param {WinBox} self 494 | */ 495 | 496 | function remove_min_stack(self){ 497 | 498 | stack_min.splice(stack_min.indexOf(self), 1); 499 | update_min_stack(); 500 | self.removeClass("min"); 501 | self.min = false; 502 | self.dom.title = ""; 503 | } 504 | 505 | function update_min_stack(){ 506 | 507 | const length = stack_min.length; 508 | const splitscreen_index = {}; 509 | const splitscreen_length = {}; 510 | 511 | for(let i = 0, self, key; i < length; i++){ 512 | 513 | self = stack_min[i]; 514 | key = self.left + ":" + self.top; 515 | 516 | if(splitscreen_length[key]){ 517 | 518 | splitscreen_length[key]++; 519 | } 520 | else{ 521 | 522 | splitscreen_index[key] = 0; 523 | splitscreen_length[key] = 1; 524 | } 525 | } 526 | 527 | for(let i = 0, self, key, width; i < length; i++){ 528 | 529 | self = stack_min[i] 530 | key = self.left + ":" + self.top; 531 | width = Math.min((root_w - self.left - self.right) / splitscreen_length[key], 250); 532 | self.resize((width + 1) | 0, self.header, true) 533 | .move((self.left + splitscreen_index[key] * width) | 0, root_h - self.bottom - self.header, true); 534 | splitscreen_index[key]++; 535 | } 536 | } 537 | 538 | /** 539 | * @param {WinBox} self 540 | * @param {string} dir 541 | */ 542 | 543 | function addWindowListener(self, dir){ 544 | 545 | const node = getByClass(self.dom, "wb-" + dir); 546 | if(!node) return; 547 | 548 | let touch, x, y; 549 | let raf_timer, raf_move, raf_resize; 550 | let dblclick_timer = 0; 551 | 552 | addListener(node, "mousedown", mousedown, eventOptions); 553 | addListener(node, "touchstart", mousedown, eventOptions); 554 | 555 | function loop(){ 556 | 557 | raf_timer = requestAnimationFrame(loop); 558 | 559 | if(raf_resize){ 560 | 561 | self.resize(); 562 | raf_resize = false; 563 | } 564 | 565 | if(raf_move){ 566 | 567 | self.move(); 568 | raf_move = false; 569 | } 570 | } 571 | 572 | function mousedown(event){ 573 | 574 | // prevent the full iteration through the fallback chain of a touch event (touch > mouse > click) 575 | preventEvent(event, true); 576 | //window_clicked = true; 577 | self.focus(); 578 | 579 | if(dir === "drag"){ 580 | 581 | if(self.min){ 582 | 583 | self.restore(); 584 | return; 585 | } 586 | 587 | if(!self.hasClass("no-max")){ 588 | 589 | const now = Date.now(); 590 | const diff = now - dblclick_timer; 591 | 592 | dblclick_timer = now; 593 | 594 | if(diff < 300){ 595 | 596 | self.max ? self.restore() : self.maximize(); 597 | return; 598 | } 599 | } 600 | } 601 | 602 | if(/*!self.max &&*/ !self.min){ 603 | 604 | addClass(body, "wb-lock"); 605 | use_raf && loop(); 606 | 607 | if((touch = event.touches) && (touch = touch[0])){ 608 | 609 | event = touch; 610 | 611 | // TODO: fix when touch events bubbles up to the document body 612 | //addListener(self.dom, "touchmove", preventEvent); 613 | addListener(window, "touchmove", handler_mousemove, eventOptionsPassive); 614 | addListener(window, "touchend", handler_mouseup, eventOptionsPassive); 615 | } 616 | else{ 617 | 618 | //addListener(this, "mouseleave", handler_mouseup); 619 | addListener(window, "mousemove", handler_mousemove, eventOptionsPassive); 620 | addListener(window, "mouseup", handler_mouseup, eventOptionsPassive); 621 | } 622 | 623 | x = event.pageX; 624 | y = event.pageY; 625 | 626 | // appearing scrollbars on the root element does not trigger "window.onresize", 627 | // force refresh window size via init(), also force layout recalculation (layout trashing) 628 | // it is probably very rare that the body overflow changes between window open and close 629 | 630 | //init(); 631 | } 632 | } 633 | 634 | function handler_mousemove(event){ 635 | 636 | preventEvent(event); 637 | 638 | if(touch){ 639 | 640 | event = event.touches[0]; 641 | } 642 | 643 | const pageX = event.pageX; 644 | const pageY = event.pageY; 645 | const offsetX = pageX - x; 646 | const offsetY = pageY - y; 647 | 648 | const old_w = self.width; 649 | const old_h = self.height; 650 | const old_x = self.x; 651 | const old_y = self.y; 652 | 653 | let resize_w, resize_h, move_x, move_y; 654 | 655 | if(dir === "drag"){ 656 | 657 | if(self.hasClass("no-move")) return; 658 | 659 | self.x += offsetX; 660 | self.y += offsetY; 661 | move_x = move_y = 1; 662 | } 663 | else{ 664 | 665 | if(dir === "e" || dir === "se" || dir === "ne"){ 666 | 667 | self.width += offsetX; 668 | resize_w = 1; 669 | } 670 | else if(dir === "w" || dir === "sw" || dir === "nw"){ 671 | 672 | self.x += offsetX; 673 | self.width -= offsetX; 674 | resize_w = 1; 675 | move_x = 1; 676 | } 677 | 678 | if(dir === "s" || dir === "se" || dir === "sw"){ 679 | 680 | self.height += offsetY; 681 | resize_h = 1; 682 | } 683 | else if(dir === "n" || dir === "ne" || dir === "nw"){ 684 | 685 | self.y += offsetY; 686 | self.height -= offsetY; 687 | resize_h = 1; 688 | move_y = 1; 689 | } 690 | } 691 | 692 | if(resize_w){ 693 | 694 | self.width = Math.max(Math.min(self.width, self.maxwidth, root_w - self.x - self.right), self.minwidth); 695 | resize_w = self.width !== old_w; 696 | } 697 | 698 | if(resize_h){ 699 | 700 | self.height = Math.max(Math.min(self.height, self.maxheight, root_h - self.y - self.bottom), self.minheight); 701 | resize_h = self.height !== old_h; 702 | } 703 | 704 | if(resize_w || resize_h){ 705 | 706 | use_raf ? raf_resize = true : self.resize(); 707 | } 708 | 709 | if(move_x){ 710 | 711 | if(self.max){ 712 | 713 | self.x = ( 714 | 715 | pageX < root_w / 3 ? 716 | 717 | self.left 718 | : 719 | pageX > root_w / 3 * 2 ? 720 | 721 | root_w - self.width - self.right 722 | : 723 | root_w / 2 - self.width / 2 724 | 725 | ) + offsetX; 726 | } 727 | 728 | self.x = Math.max(Math.min(self.x, self.overflow ? root_w - 30 : root_w - self.width - self.right), self.overflow ? 30 - self.width : self.left); 729 | move_x = self.x !== old_x; 730 | } 731 | 732 | if(move_y){ 733 | 734 | if(self.max){ 735 | 736 | self.y = self.top + offsetY; 737 | } 738 | 739 | self.y = Math.max(Math.min(self.y, self.overflow ? root_h - self.header : root_h - self.height - self.bottom), self.top); 740 | move_y = self.y !== old_y; 741 | } 742 | 743 | if(move_x || move_y){ 744 | 745 | if(self.max){ 746 | 747 | self.restore(); 748 | } 749 | 750 | use_raf ? raf_move = true : self.move(); 751 | } 752 | 753 | if(resize_w || move_x){ 754 | 755 | x = pageX; 756 | } 757 | 758 | if(resize_h || move_y){ 759 | 760 | y = pageY; 761 | } 762 | } 763 | 764 | function handler_mouseup(event){ 765 | 766 | preventEvent(event); 767 | removeClass(body, "wb-lock"); 768 | use_raf && cancelAnimationFrame(raf_timer); 769 | 770 | if(touch){ 771 | 772 | //removeListener(self.dom, "touchmove", preventEvent); 773 | removeListener(window, "touchmove", handler_mousemove, eventOptionsPassive); 774 | removeListener(window, "touchend", handler_mouseup, eventOptionsPassive); 775 | } 776 | else{ 777 | 778 | //removeListener(this, "mouseleave", handler_mouseup); 779 | removeListener(window, "mousemove", handler_mousemove, eventOptionsPassive); 780 | removeListener(window, "mouseup", handler_mouseup, eventOptionsPassive); 781 | } 782 | } 783 | } 784 | 785 | function init(){ 786 | 787 | // TODO: the window height of iOS isn't determined correctly when the bottom toolbar disappears 788 | 789 | // the bounding rect provides more precise dimensions (float values) 790 | // //const rect = doc.getBoundingClientRect(); 791 | // this.root_w = doc.clientWidth; //rect.width || (rect.right - rect.left); 792 | // this.root_h = doc.clientHeight; //rect.height || (rect.top - rect.bottom); 793 | 794 | // if(ios){ 795 | // this.root_h = window.innerHeight * (this.root_w / window.innerWidth); 796 | // } 797 | 798 | // root_w = doc.clientWidth; 799 | // root_h = doc.clientHeight; 800 | 801 | // root_w = body.clientWidth; 802 | // root_h = body.clientHeight; 803 | 804 | const doc = document.documentElement; 805 | root_w = doc.clientWidth; 806 | root_h = doc.clientHeight; 807 | } 808 | 809 | /** 810 | * @param {Element=} src 811 | * @this WinBox 812 | */ 813 | 814 | WinBox.prototype.mount = function(src){ 815 | 816 | // handles mounting over: 817 | this.unmount(); 818 | 819 | src._backstore || (src._backstore = src.parentNode); 820 | this.body.textContent = ""; 821 | this.body.appendChild(src); 822 | 823 | return this; 824 | }; 825 | 826 | /** 827 | * @param {Element=} dest 828 | * @this WinBox 829 | */ 830 | 831 | WinBox.prototype.unmount = function(dest){ 832 | 833 | const node = this.body.firstChild; 834 | 835 | if(node){ 836 | 837 | const root = dest || node._backstore; 838 | 839 | root && root.appendChild(node); 840 | node._backstore = dest; 841 | } 842 | 843 | return this; 844 | }; 845 | 846 | /** 847 | * @this WinBox 848 | */ 849 | 850 | WinBox.prototype.setTitle = function(title){ 851 | 852 | const node = getByClass(this.dom, "wb-title"); 853 | setText(node, this.title = title); 854 | return this; 855 | }; 856 | 857 | /** 858 | * @this WinBox 859 | */ 860 | 861 | WinBox.prototype.setIcon = function(src){ 862 | 863 | const img = getByClass(this.dom, "wb-icon"); 864 | setStyle(img, "background-image", "url(" + src + ")"); 865 | setStyle(img, "display", "inline-block"); 866 | 867 | return this; 868 | }; 869 | 870 | /** 871 | * @this WinBox 872 | */ 873 | 874 | WinBox.prototype.setBackground = function(background){ 875 | 876 | setStyle(this.dom, "background", background); 877 | return this; 878 | }; 879 | 880 | /** 881 | * @this WinBox 882 | */ 883 | 884 | WinBox.prototype.setUrl = function(url, onload){ 885 | 886 | const node = this.body.firstChild; 887 | 888 | if(node && (node.tagName.toLowerCase() === "iframe")){ 889 | 890 | node.src = url; 891 | } 892 | else{ 893 | 894 | this.body.innerHTML = ''; 895 | onload && (this.body.firstChild.onload = onload); 896 | } 897 | 898 | return this; 899 | }; 900 | 901 | /** 902 | * @param {boolean=} state 903 | * @this WinBox 904 | */ 905 | 906 | WinBox.prototype.focus = function(state){ 907 | 908 | if(state === false){ 909 | 910 | return this.blur(); 911 | } 912 | 913 | if(!this.focused){ 914 | 915 | const stack_length = stack_win.length; 916 | 917 | if(stack_length > 1){ 918 | 919 | for(let i = 1; i <= stack_length; i++){ 920 | 921 | const last_focus = stack_win[stack_length - i]; 922 | 923 | if(last_focus.focused /*&& last_focus !== this*/){ 924 | 925 | last_focus.blur(); 926 | stack_win.push(stack_win.splice(stack_win.indexOf(this), 1)[0]); 927 | 928 | break; 929 | } 930 | } 931 | } 932 | 933 | setStyle(this.dom, "z-index", ++index_counter); 934 | this.index = index_counter; 935 | this.addClass("focus"); 936 | this.focused = true; 937 | this.onfocus && this.onfocus(); 938 | } 939 | 940 | return this; 941 | }; 942 | 943 | /** 944 | * @param {boolean=} state 945 | * @this WinBox 946 | */ 947 | 948 | WinBox.prototype.blur = function(state){ 949 | 950 | if(state === false){ 951 | 952 | return this.focus(); 953 | } 954 | 955 | if(this.focused){ 956 | 957 | this.removeClass("focus"); 958 | this.focused = false; 959 | this.onblur && this.onblur(); 960 | } 961 | 962 | return this; 963 | }; 964 | 965 | /** 966 | * @param {boolean=} state 967 | * @this WinBox 968 | */ 969 | 970 | WinBox.prototype.hide = function(state){ 971 | 972 | if(state === false){ 973 | 974 | return this.show(); 975 | } 976 | 977 | if(!this.hidden){ 978 | 979 | this.onhide && this.onhide(); 980 | this.hidden = true; 981 | return this.addClass("hide"); 982 | } 983 | }; 984 | 985 | /** 986 | * @param {boolean=} state 987 | * @this WinBox 988 | */ 989 | 990 | WinBox.prototype.show = function(state){ 991 | 992 | if(state === false){ 993 | 994 | return this.hide(); 995 | } 996 | 997 | if(this.hidden){ 998 | 999 | this.onshow && this.onshow(); 1000 | this.hidden = false; 1001 | return this.removeClass("hide"); 1002 | } 1003 | }; 1004 | 1005 | /** 1006 | * @param {boolean=} state 1007 | * @this WinBox 1008 | */ 1009 | 1010 | WinBox.prototype.minimize = function(state){ 1011 | 1012 | if(state === false){ 1013 | 1014 | return this.restore(); 1015 | } 1016 | 1017 | if(is_fullscreen){ 1018 | 1019 | cancel_fullscreen(); 1020 | } 1021 | 1022 | if(this.max){ 1023 | 1024 | this.removeClass("max"); 1025 | this.max = false; 1026 | } 1027 | 1028 | if(!this.min){ 1029 | 1030 | stack_min.push(this); 1031 | update_min_stack(); 1032 | this.dom.title = this.title; 1033 | this.addClass("min"); 1034 | this.min = true; 1035 | 1036 | if(this.focused){ 1037 | 1038 | this.blur(); 1039 | focus_next(); 1040 | } 1041 | 1042 | this.onminimize && this.onminimize(); 1043 | } 1044 | 1045 | return this; 1046 | }; 1047 | 1048 | function focus_next(){ 1049 | 1050 | const stack_length = stack_win.length; 1051 | 1052 | if(stack_length){ 1053 | 1054 | for(let i = stack_length - 1; i >= 0; i--){ 1055 | 1056 | const last_focus = stack_win[i]; 1057 | 1058 | if(!last_focus.min /*&& last_focus !== this*/){ 1059 | 1060 | last_focus.focus(); 1061 | break; 1062 | } 1063 | } 1064 | } 1065 | } 1066 | 1067 | /** 1068 | * @this WinBox 1069 | */ 1070 | 1071 | WinBox.prototype.restore = function(){ 1072 | 1073 | if(is_fullscreen){ 1074 | 1075 | cancel_fullscreen(); 1076 | } 1077 | 1078 | if(this.min){ 1079 | 1080 | remove_min_stack(this); 1081 | this.resize().move(); 1082 | this.onrestore && this.onrestore(); 1083 | } 1084 | 1085 | if(this.max){ 1086 | 1087 | this.max = false; 1088 | this.removeClass("max").resize().move(); 1089 | this.onrestore && this.onrestore(); 1090 | } 1091 | 1092 | return this; 1093 | }; 1094 | 1095 | /** 1096 | * @param {boolean=} state 1097 | * @this WinBox 1098 | */ 1099 | 1100 | WinBox.prototype.maximize = function(state){ 1101 | 1102 | if(state === false){ 1103 | 1104 | return this.restore(); 1105 | } 1106 | 1107 | if(is_fullscreen){ 1108 | 1109 | cancel_fullscreen(); 1110 | } 1111 | 1112 | if(this.min){ 1113 | 1114 | remove_min_stack(this); 1115 | } 1116 | 1117 | if(!this.max){ 1118 | 1119 | this.addClass("max").resize( 1120 | 1121 | root_w - this.left - this.right, 1122 | root_h - this.top - this.bottom /* - 1 */, 1123 | true 1124 | 1125 | ).move( 1126 | 1127 | this.left, 1128 | this.top, 1129 | true 1130 | ); 1131 | 1132 | this.max = true; 1133 | this.onmaximize && this.onmaximize(); 1134 | } 1135 | 1136 | return this; 1137 | }; 1138 | 1139 | /** 1140 | * @param {boolean=} state 1141 | * @this WinBox 1142 | */ 1143 | 1144 | WinBox.prototype.fullscreen = function(state){ 1145 | 1146 | if(this.min){ 1147 | 1148 | remove_min_stack(this); 1149 | this.resize().move(); 1150 | } 1151 | 1152 | // fullscreen could be changed by user manually! 1153 | 1154 | if(!is_fullscreen || !cancel_fullscreen()){ 1155 | 1156 | // requestFullscreen is executed as async and returns promise. 1157 | // in this case it is better to set the state to "this.full" after the requestFullscreen was fired, 1158 | // because it may break when browser does not support fullscreen properly and bypass it silently. 1159 | 1160 | this.body[prefix_request](); 1161 | is_fullscreen = this; 1162 | this.full = true; 1163 | this.onfullscreen && this.onfullscreen(); 1164 | } 1165 | else if(state === false){ 1166 | 1167 | return this.restore(); 1168 | } 1169 | 1170 | return this; 1171 | }; 1172 | 1173 | function has_fullscreen(){ 1174 | 1175 | return ( 1176 | 1177 | document["fullscreen"] || 1178 | document["fullscreenElement"] || 1179 | document["webkitFullscreenElement"] || 1180 | document["mozFullScreenElement"] 1181 | ); 1182 | } 1183 | 1184 | /** 1185 | * @return {boolean|void} 1186 | */ 1187 | 1188 | function cancel_fullscreen(){ 1189 | 1190 | is_fullscreen.full = false; 1191 | 1192 | if(has_fullscreen()){ 1193 | 1194 | // exitFullscreen is executed as async and returns promise. 1195 | // the important part is that the promise callback runs before the event "onresize" was fired! 1196 | 1197 | document[prefix_exit](); 1198 | return true; 1199 | } 1200 | } 1201 | 1202 | /** 1203 | * @param {boolean=} force 1204 | * @this WinBox 1205 | */ 1206 | 1207 | WinBox.prototype.close = function(force) { 1208 | 1209 | if(this.onclose && this.onclose(force)){ 1210 | 1211 | return true; 1212 | } 1213 | 1214 | if(this.min){ 1215 | 1216 | remove_min_stack(this); 1217 | } 1218 | 1219 | stack_win.splice(stack_win.indexOf(this), 1); 1220 | 1221 | this.unmount(); 1222 | this.dom.remove(); 1223 | this.dom.textContent = ""; 1224 | this.dom["winbox"] = null; 1225 | this.body = null; 1226 | this.dom = null; 1227 | this.focused && focus_next(); 1228 | }; 1229 | 1230 | /** 1231 | * @param {number|string=} x 1232 | * @param {number|string=} y 1233 | * @param {boolean=} _skip_update 1234 | * @this WinBox 1235 | */ 1236 | 1237 | WinBox.prototype.move = function(x, y, _skip_update){ 1238 | 1239 | if(!x && (x !== 0)){ 1240 | 1241 | x = this.x; 1242 | y = this.y; 1243 | } 1244 | else if(!_skip_update){ 1245 | 1246 | this.x = x ? x = parse(x, root_w - this.left - this.right, this.width) : 0; 1247 | this.y = y ? y = parse(y, root_h - this.top - this.bottom, this.height) : 0; 1248 | } 1249 | 1250 | //setStyle(this.dom, "transform", "translate(" + x + "px," + y + "px)"); 1251 | setStyle(this.dom, "left", x + "px"); 1252 | setStyle(this.dom, "top", y + "px"); 1253 | 1254 | this.onmove && this.onmove(x, y); 1255 | return this; 1256 | }; 1257 | 1258 | /** 1259 | * @param {number|string=} w 1260 | * @param {number|string=} h 1261 | * @param {boolean=} _skip_update 1262 | * @this WinBox 1263 | */ 1264 | 1265 | WinBox.prototype.resize = function(w, h, _skip_update){ 1266 | 1267 | if(!w && (w !== 0)){ 1268 | 1269 | w = this.width; 1270 | h = this.height; 1271 | } 1272 | else if(!_skip_update){ 1273 | 1274 | this.width = w ? w = parse(w, this.maxwidth /*- this.left - this.right*/) : 0; 1275 | this.height = h ? h = parse(h, this.maxheight /*- this.top - this.bottom*/) : 0; 1276 | 1277 | w = Math.max(w, this.minwidth); 1278 | h = Math.max(h, this.minheight); 1279 | } 1280 | 1281 | setStyle(this.dom, "width", w + "px"); 1282 | setStyle(this.dom, "height", h + "px"); 1283 | 1284 | this.onresize && this.onresize(w, h); 1285 | return this; 1286 | }; 1287 | 1288 | /** 1289 | * @param {{ class:string?, image:string?, click:Function?, index:number? }} control 1290 | * @this WinBox 1291 | */ 1292 | 1293 | WinBox.prototype.addControl = function(control){ 1294 | 1295 | const classname = control["class"]; 1296 | const image = control.image; 1297 | const click = control.click; 1298 | const index = control.index; 1299 | const node = document.createElement("span"); 1300 | const icons = getByClass(this.dom, "wb-control"); 1301 | const self = this; 1302 | 1303 | if(classname) node.className = classname; 1304 | if(image) setStyle(node, "background-image", "url(" + image + ")"); 1305 | if(click) node.onclick = function(event){ click.call(this, event, self) }; 1306 | 1307 | icons.insertBefore(node, icons.childNodes[index || 0]); 1308 | 1309 | return this; 1310 | }; 1311 | 1312 | /** 1313 | * @param {string} control 1314 | * @this WinBox 1315 | */ 1316 | 1317 | WinBox.prototype.removeControl = function(control){ 1318 | 1319 | control = getByClass(this.dom, control); 1320 | control && control.remove(); 1321 | return this; 1322 | }; 1323 | 1324 | /** 1325 | * @param {string} classname 1326 | * @this WinBox 1327 | */ 1328 | 1329 | WinBox.prototype.addClass = function(classname){ 1330 | 1331 | addClass(this.dom, classname); 1332 | return this; 1333 | }; 1334 | 1335 | /** 1336 | * @param {string} classname 1337 | * @this WinBox 1338 | */ 1339 | 1340 | WinBox.prototype.removeClass = function(classname){ 1341 | 1342 | removeClass(this.dom, classname); 1343 | return this; 1344 | }; 1345 | 1346 | 1347 | /** 1348 | * @param {string} classname 1349 | * @this WinBox 1350 | */ 1351 | 1352 | WinBox.prototype.hasClass = function(classname){ 1353 | 1354 | return hasClass(this.dom, classname); 1355 | }; 1356 | 1357 | /** 1358 | * @param {string} classname 1359 | * @this WinBox 1360 | */ 1361 | 1362 | WinBox.prototype.toggleClass = function(classname){ 1363 | 1364 | return this.hasClass(classname) ? this.removeClass(classname) : this.addClass(classname); 1365 | }; 1366 | 1367 | 1368 | /* 1369 | WinBox.prototype.use = function(plugin){ 1370 | 1371 | this.plugins.push(plugin); 1372 | return this; 1373 | }; 1374 | */ -------------------------------------------------------------------------------- /task/build.js: -------------------------------------------------------------------------------- 1 | const child_process = require('child_process'); 2 | const fs = require('fs'); 3 | 4 | console.log("Start build ....."); 5 | console.log(); 6 | 7 | fs.existsSync("log") || fs.mkdirSync("log"); 8 | fs.existsSync("tmp") || fs.mkdirSync("tmp"); 9 | fs.existsSync("dist") || fs.mkdirSync("dist"); 10 | fs.existsSync("dist/js") || fs.mkdirSync("dist/js"); 11 | 12 | /* 13 | const options = (function(argv){ 14 | 15 | const arr = {}; 16 | let count = 0; 17 | 18 | argv.forEach(function(val, index) { 19 | 20 | if(++count > 2){ 21 | 22 | index = val.split('='); 23 | val = index[1]; 24 | index = index[0]; 25 | 26 | arr[index] = val; 27 | 28 | if(count > 3) console.log(index + ': ' + val); 29 | } 30 | }); 31 | 32 | return arr; 33 | 34 | })(process.argv); 35 | */ 36 | 37 | const bundle = process.argv[2] === "--bundle"; 38 | //const extern = process.argv[2] === "--extern"; 39 | 40 | const parameter = (function(opt){ 41 | 42 | let parameter = ''; 43 | 44 | for(let index in opt){ 45 | 46 | if(opt.hasOwnProperty(index)){ 47 | 48 | parameter += ' --' + index + '=' + opt[index]; 49 | } 50 | } 51 | 52 | return parameter; 53 | })({ 54 | 55 | compilation_level: "ADVANCED_OPTIMIZATIONS", //"WHITESPACE" 56 | use_types_for_optimization: true, 57 | //new_type_inf: true, 58 | //jscomp_warning: "newCheckTypes", 59 | //jscomp_error: "strictCheckTypes", 60 | //jscomp_error: "newCheckTypesExtraChecks", 61 | generate_exports: true, 62 | export_local_property_definitions: true, 63 | language_in: "ECMASCRIPT6_STRICT", 64 | language_out: "ECMASCRIPT5_STRICT", 65 | process_closure_primitives: true, 66 | summary_detail_level: 3, 67 | warning_level: "VERBOSE", 68 | emit_use_strict: true, 69 | 70 | output_manifest: "log/manifest.log", 71 | //output_module_dependencies: "log/module_dependencies.log", 72 | property_renaming_report: "log/renaming_report.log", 73 | strict_mode_input: true, 74 | assume_function_wrapper: true, 75 | 76 | //transform_amd_modules: true, 77 | process_common_js_modules: true, 78 | module_resolution: "BROWSER", 79 | dependency_mode: "PRUNE_LEGACY", 80 | rewrite_polyfills: false, 81 | //js_module_root: "./", 82 | entry_point: "./src/js/webpack.js", 83 | //manage_closure_dependencies: true, 84 | //dependency_mode: "PRUNE_LEGACY", 85 | 86 | isolation_mode: "IIFE" 87 | //output_wrapper: "(function(){%output%}());" 88 | 89 | //formatting: "PRETTY_PRINT" 90 | }); 91 | 92 | exec((/^win/.test(process.platform) ? 93 | 94 | "\"node_modules/google-closure-compiler-windows/compiler.exe\"" 95 | : 96 | "java -jar node_modules/google-closure-compiler-java/compiler.jar" 97 | 98 | ) + parameter + (bundle ? " --js='tmp/**.js'" : "") + " --js='src/js/**.js' --js_output_file='" + (bundle ? "dist/winbox.bundle.min.js" : "dist/js/winbox.min.js") + "' && exit 0", function(){ 99 | 100 | let build = fs.readFileSync((bundle ? "dist/winbox.bundle.min.js" : "dist/js/winbox.min.js")); 101 | let preserve = fs.readFileSync("src/js/winbox.js", "utf8"); 102 | 103 | const package_json = require("../package.json"); 104 | 105 | preserve = preserve.replace("* WinBox.js", "* WinBox.js v" + package_json.version + (bundle ? " (Bundle)" : "")); 106 | build = preserve.substring(0, preserve.indexOf('*/') + 2) + "\n" + build; 107 | fs.writeFileSync((bundle ? "dist/winbox.bundle.min.js" : "dist/js/winbox.min.js"), build); 108 | 109 | console.log("Build Complete."); 110 | }); 111 | 112 | function exec(prompt, callback){ 113 | 114 | const child = child_process.exec(prompt, function(err, stdout, stderr){ 115 | 116 | if(err){ 117 | 118 | console.error(err); 119 | } 120 | else{ 121 | 122 | if(callback){ 123 | 124 | callback(); 125 | } 126 | } 127 | }); 128 | 129 | child.stdout.pipe(process.stdout); 130 | child.stderr.pipe(process.stderr); 131 | } 132 | -------------------------------------------------------------------------------- /task/bundle.js: -------------------------------------------------------------------------------- 1 | const { base64Sync } = require('base64-img'); 2 | const fs = require('fs'); 3 | 4 | fs.existsSync("log") || fs.mkdirSync("log"); 5 | fs.existsSync("tmp") || fs.mkdirSync("tmp"); 6 | fs.existsSync("dist") || fs.mkdirSync("dist"); 7 | fs.existsSync("dist/js") || fs.mkdirSync("dist/js"); 8 | 9 | const image = process.argv[2] === "--image"; 10 | //const template = process.argv[2] === "--template"; 11 | const style = process.argv[2] === "--style"; 12 | 13 | (function(){ 14 | 15 | if(image){ 16 | 17 | // TODO provide custom filenames 18 | 19 | const compressed = { 20 | 21 | max: base64Sync('dist/img/max.svg'), 22 | close: base64Sync('dist/img/close.svg'), 23 | full: base64Sync('dist/img/full.svg'), 24 | //restore: base64Sync('dist/img/restore.svg'), 25 | //exit: base64Sync('dist/img/exit.svg'), 26 | min: base64Sync('dist/img/min.svg') 27 | }; 28 | 29 | let tmp = ""; 30 | 31 | for(let key in compressed){ 32 | 33 | if(compressed.hasOwnProperty(key)){ 34 | 35 | tmp += ("@" + key + ": \"" + compressed[key] + "\";\n"); 36 | } 37 | } 38 | 39 | fs.writeFileSync("tmp/images.less", tmp); 40 | fs.writeFileSync("tmp/bundle.less", '@import "../src/css/winbox.less"; @import "images.less";'); // @import "../src/css/themes/modern.less"; @import "../src/css/themes/white.less"; 41 | } 42 | 43 | // ---------------------- 44 | 45 | if(style){ 46 | 47 | fs.writeFileSync("tmp/style.js", 48 | 49 | 'const style = document.createElement("style");' + 50 | 'style.innerHTML = "' + fs.readFileSync("dist/css/winbox.min.css", "utf8").replace(/"/g, "'") + '";' + 51 | 'const head = document.getElementsByTagName("head")[0];' + 52 | 'if(head.firstChild) head.insertBefore(style, head.firstChild); else head.appendChild(style);' 53 | ); 54 | } 55 | 56 | })(); 57 | -------------------------------------------------------------------------------- /task/clean.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const path = require("path"); 3 | 4 | const removeDir = function(path) { 5 | if (fs.existsSync(path)) { 6 | const files = fs.readdirSync(path); 7 | 8 | if (files.length > 0) { 9 | files.forEach(function(filename) { 10 | if (fs.statSync(path + "/" + filename).isDirectory()) { 11 | removeDir(path + "/" + filename); 12 | } else { 13 | fs.unlinkSync(path + "/" + filename); 14 | } 15 | }); 16 | 17 | fs.rmdirSync(path); 18 | } else { 19 | fs.rmdirSync(path); 20 | } 21 | } 22 | } 23 | 24 | const distPath = path.join('dist') 25 | 26 | removeDir(distPath); 27 | -------------------------------------------------------------------------------- /task/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /task/server.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var port = process.argv[2]; 4 | 5 | if(!port){ 6 | 7 | if(/^win/.test(process.platform)){ 8 | 9 | port = 80; 10 | } 11 | else{ 12 | 13 | port = 8080; 14 | } 15 | } 16 | 17 | var ws = require('web-servo'); 18 | 19 | ws.config({ 20 | 21 | "server": { 22 | "port": port, 23 | "dir": "/", 24 | "exitOnError": false, 25 | "ssl": { 26 | "enabled": false, 27 | "key": "", 28 | "cert": "" 29 | } 30 | }, 31 | "page": { 32 | "default": "index.html" 33 | }, 34 | "methods": { 35 | "allowed": [ 36 | "OPTIONS", 37 | "GET", 38 | "POST", 39 | "HEAD", 40 | "PUT", 41 | "PATCH", 42 | "DELETE" 43 | //"COPY", 44 | //"LINK", 45 | //"UNLINK", 46 | //"TRACE", 47 | //"CONNECT" 48 | ] 49 | } 50 | }); 51 | 52 | //ws.setConfigVar('server.port', port); 53 | ws.silent().start(); 54 | 55 | console.log("-----------------------------------------------------"); 56 | console.log("Hit CTRL-C to stop the server..."); 57 | -------------------------------------------------------------------------------- /task/svgo.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | let { optimize } = require('svgo'); 4 | 5 | const plugins = [ 6 | 'cleanupAttrs', 7 | 'removeDoctype', 8 | 'removeXMLProcInst', 9 | 'removeComments', 10 | 'removeMetadata', 11 | 'removeTitle', 12 | 'removeDesc', 13 | 'removeUselessDefs', 14 | 'removeEditorsNSData', 15 | 'removeEmptyAttrs', 16 | 'removeHiddenElems', 17 | 'removeEmptyText', 18 | 'removeEmptyContainers', 19 | // 'removeViewBox', 20 | 'cleanupEnableBackground', 21 | 'convertStyleToAttrs', 22 | 'convertColors', 23 | 'convertPathData', 24 | 'convertTransform', 25 | 'removeUnknownsAndDefaults', 26 | 'removeNonInheritableGroupAttrs', 27 | 'removeUselessStrokeAndFill', 28 | 'removeUnusedNS', 29 | 'cleanupIDs', 30 | 'cleanupNumericValues', 31 | 'moveElemsAttrsToGroup', 32 | 'moveGroupAttrsToElems', 33 | 'collapseGroups', 34 | // 'removeRasterImages', 35 | 'mergePaths', 36 | 'convertShapeToPath', 37 | 'sortAttrs', 38 | 'removeDimensions', 39 | //{ name: 'removeAttrs', params: { attrs: '(stroke|fill)' } }, 40 | ]; 41 | 42 | 43 | const directoryPath = 'dist/img'; 44 | const files = fs.readdirSync(directoryPath); 45 | 46 | files.forEach(function(filepath){ 47 | 48 | if(filepath.endsWith(".svg")){ 49 | 50 | filepath = path.resolve(__dirname, "..", directoryPath, filepath); 51 | 52 | console.log(filepath); 53 | 54 | const data = fs.readFileSync(filepath, 'utf8'); 55 | const result = optimize(data, { path: filepath, plugins: plugins }); 56 | 57 | fs.writeFileSync(filepath, result.data); 58 | } 59 | }); 60 | --------------------------------------------------------------------------------