├── README.md ├── codebase ├── message.js └── themes │ ├── message_default.css │ ├── message_growl_dark.css │ ├── message_growl_shiny.css │ ├── message_skyblue.css │ └── message_solid.css ├── license.txt └── samples ├── 01_info.html ├── 02_alert.html ├── 03_confirm.html ├── 04_skins.html ├── 05_modalbox.html ├── 05_modalbox_reuse.html ├── alert_medium.png └── alert_small.png /README.md: -------------------------------------------------------------------------------- 1 | jsMessage 2 | ========= 3 | 4 | Custom notifications, alerts, confirmations 5 | 6 | This library was extracted from code of [DHTMLX suite][dhtmlx]. 7 | 8 | - Library can be used under terms of [MIT license][mit] (basically **free**). 9 | - Only **4kb** gzipped, without external dependencies. 10 | - Works in FF, Chrome, Safari (including iPhone), Opera, IE7+ 11 | 12 | Live samples can be checked at [http://dhtmlx.github.com/message/][message] 13 | 14 | Supported message types 15 | ----------------------- 16 | 17 | jsMessage offers 4 variations at your disposal: 18 | 19 | - alert 20 | - confirm 21 | - notification ( message ) 22 | - modalbox 23 | 24 | How to use 25 | ----------- 26 | 27 | The type (subtype) of the message window is specified through the parameter type. The default value is "message". 28 | 29 | ```javascript 30 | dhtmlx.message({ 31 | type:"confirm-warning", 32 | text:"Are you sure you want to do it?" 33 | }) 34 | ``` 35 | 36 | or, you can use separate methods 37 | 38 | ```javascript 39 | dhtmlx.confirm({ 40 | title:"Confirm", 41 | text:"Continue?" 42 | }); 43 | //or 44 | dhtmlx.alert({ 45 | title:"Alert", 46 | type:"alert-error", 47 | text:"You can do this" 48 | }); 49 | //or 50 | dhtmlx.modalbox({ 51 | title:"Settings", 52 | text:"Abstract popup" 53 | }); 54 | ``` 55 | 56 | Styling 57 | ------- 58 | For any type of the message window you can define a custom style to achieve the desired look. 59 | Generally, the appropriate css class is specified through the parameter type: you define a css class and set the parameter to its name. 60 | 61 | ```html 62 | 69 | 72 | ``` 73 | 74 | Options 75 | --------- 76 | 77 | ### Alert 78 | 79 | - title - (string) the text of the header (by default, 'Alert'). 80 | - type - the subtype of the window or a custom css class. The default value for the window - 'alert'. 81 | - text - (string) the text of the window body. 82 | - ok - (string) the text of the 'Ok' button. 83 | - callback - (function) the function called on button click 84 | - position - for now support only one value "top", any other value will result in center align 85 | - width - width of the modal box ( samples "100px", "50%") 86 | - height - height of the modal box 87 | 88 | **Full form** 89 | 90 | ```javascript 91 | dhtmlx.message({ 92 | title: "Close", 93 | type: "alert", 94 | text: "You can't close this window!", 95 | callback: function() {dhtmlx.alert("Test alert");} 96 | }) 97 | //or 98 | dhtmlx.alert({ 99 | text: "Download is completed.", 100 | callback: function() {dhtmlx.alert("Test alert");} 101 | }) 102 | ``` 103 | 104 | **Short form** 105 | 106 | ```javascript 107 | dhtmlx.alert("someText"); 108 | ``` 109 | 110 | Both alert and confirm blocks keyboard input while active. Pressing SPACE or ENTER will close message with positive result. Pressing ESC will close message with negative result. (you can use dhtmlx.message.keyboard = false; to disable this behavior) 111 | 112 | ### Confirm 113 | 114 | - title - (string) the text of the header (by default, 'Alert'). 115 | - type - the subtype of the window or a custom css class 116 | - text - (string) the text of the window body. 117 | - ok - (string) the text of the 'Ok' button. 118 | - cancel - (string) the text of the 'Cancel' button. 119 | - callback - (function) the function called on button click. Receives 'true' or 'false' as the parameter (subject to the clicked button). 120 | - position - for now support only one value "top", any other value will result in center align 121 | - width - width of the modal box ( samples "100px", "50%") 122 | - height - height of the modal box 123 | 124 | **Full form** 125 | 126 | ```javascript 127 | dhtmlx.message({ 128 | type:"confirm", 129 | text: "Continue?", 130 | callback: function() {dhtmlx.confirm("Test confirm");} 131 | }); 132 | //or 133 | dhtmlx.confirm({ 134 | title: "Close", 135 | type:"confirm-warning", 136 | text: "Are you sure you want to do it?", 137 | callback: function() {dhtmlx.confirm("Test confirm");} 138 | }); 139 | ``` 140 | 141 | **Short form** 142 | 143 | ```javascript 144 | dhtmlx.confirm("ConfirmText"); 145 | ``` 146 | 147 | ### ModalBox 148 | 149 | - title - (string) the text of the header (by default, 'Alert'). 150 | - type - the subtype of the window or a custom css class 151 | - text - (string) the text of the window body. 152 | - ok - (string) the text of the 'Ok' button. 153 | - cancel - (string) the text of the 'Cancel' button. 154 | - callback - (function) the function called on button click. Receives 'true' or 'false' as the parameter (subject to the clicked button). 155 | - buttons - array of labels, each one will be converted to the button ( much like multi-button confirm ). Callback function will receive index of pressed button ( 0 - for first button, 1 - for second button and etc. ) 156 | - position - for now support only one value "top", any other value will result in center align 157 | - width - width of the modal box ( samples "100px", "50%") 158 | - height - height of the modal box 159 | - content - can be used instead of text, defines html element (or its ID) which will be shown inside of a popup 160 | 161 | **Examples** 162 | 163 | ```javascript 164 | dhtmlx.modalbox({ 165 | title:"Settings" 166 | text: " ... html code here... ", 167 | buttons:["Save", "Defaults", "Cancel"], 168 | callback:process_result 169 | }); 170 | ``` 171 | 172 | function returns the html container of the box which can be used for some actions 173 | 174 | ```javascript 175 | var box = dhtmlx.modalbox(...); 176 | box.getElementsByTagName("input")[0].focus(); 177 | ... 178 | dhtmlx.modalbox.hide(box); //hide popup 179 | ``` 180 | 181 | #### Closing modal box 182 | 183 | There are 3 way to close modal box 184 | 185 | - call dhtmlx.modalbox.hide(box) - where "box" is result of dhtmlx.modalbox command 186 | - call dhtmlx.modalbox.hide(node) - where node - any html node in the box (allows to create "close" links easily) 187 | - click on any button, which was defined through "buttons" property 188 | 189 | ```javascript 190 | var box = dhtmlx.modalbox({ 191 | text:"Click to close" 192 | }); 193 | ``` 194 | 195 | 196 | #### Custom buttons 197 | 198 | You can place a custom button in the popup, which is styled exactly as default message buttons. To do so you need to place the next html snippet 199 | 200 | ```javascript 201 | var box = dhtmlx.modalbox({ 202 | text:"" 203 | }); 204 | ``` 205 | 206 | #### Content reusage 207 | 208 | Instead of setting html text you can place any html container on the page in the modalbox 209 | 210 | ```html 211 |
Some form here
212 | ``` 213 | 214 | ```javascript 215 | var box = dhtmlx.modalbox(content:"mycontent"); 216 | ``` 217 | 218 | after box will be closed, you can reopen it by 219 | 220 | ```javascript 221 | dhtmlx.modalbox(box); 222 | ``` 223 | 224 | 225 | ### Notification (message) 226 | 227 | - type - the subtype of the window or a custom css class. The default value for the window - 'alert'. 228 | - text - (string) the text of the window body. 229 | - expire - the time after passing which the window disappears (in milliseconds). You can use negative value (-1) to make notice persistent. 230 | 231 | **Full form** 232 | 233 | ```javascript 234 | dhtmlx.message({ 235 | text:"An error has occured.
Please, see the log file!", 236 | expire:1000, You can use negative value (-1) to make notice persistent. 237 | type:"customCss" // 'customCss' - css class 238 | }); 239 | ``` 240 | 241 | **Short form** 242 | 243 | ```javascript 244 | dhtmlx.message("Your data has been successfully saved!"); 245 | ``` 246 | 247 | Extra configuration 248 | ------------------- 249 | 250 | Default delay of notifications can be set as 251 | 252 | ```javascript 253 | dhtmlx.message.expire = 4000; //time in milliseconds 254 | t.position = "top"; 255 | ``` 256 | 257 | Default position of notices can be set as 258 | 259 | ```javascript 260 | dhtmlx.message.position = "top"; // possible values "top" or "bottom" 261 | ``` 262 | 263 | 264 | Interaction with alert and confirm from keyboard can be disabled by 265 | 266 | ```javascript 267 | dhtmlx.message.keyboard = false; // possible values "top" or "bottom" 268 | ``` 269 | 270 | ### Alert subtypes 271 | 272 | For all kinds of messages, there are alert variations, which can be used for more important notifications 273 | 274 | ```javascript 275 | dhtmlx.message({ type:"error", "Critical error!"}); 276 | //or 277 | dhtmlx.message({ type:"alert-error", "Critical error!"}); 278 | //or 279 | dhtmlx.message({ type:"confirm-error", "Confirm self-destruction!"}); 280 | ``` 281 | 282 | [dhtmlx]: http://dhtmlx.com/docs/products/dhtmlxSuite/index.shtml?message 283 | [message]: http://dhtmlx.github.com/message/ 284 | [mit]: http://en.wikipedia.org/wiki/MIT_License -------------------------------------------------------------------------------- /codebase/message.js: -------------------------------------------------------------------------------- 1 | if(!window.dhtmlx) 2 | window.dhtmlx = {}; 3 | 4 | (function(){ 5 | var _dhx_msg_cfg = null; 6 | function callback(config, result){ 7 | var usercall = config.callback; 8 | modality(false); 9 | config.box.parentNode.removeChild(config.box); 10 | _dhx_msg_cfg = config.box = null; 11 | if (usercall) 12 | usercall(result); 13 | } 14 | function modal_key(e){ 15 | if (_dhx_msg_cfg){ 16 | e = e||event; 17 | var code = e.which||event.keyCode; 18 | if (dhtmlx.message.keyboard){ 19 | if (code == 13 || code == 32) 20 | callback(_dhx_msg_cfg, true); 21 | if (code == 27) 22 | callback(_dhx_msg_cfg, false); 23 | } 24 | if (e.preventDefault) 25 | e.preventDefault(); 26 | return !(e.cancelBubble = true); 27 | } 28 | } 29 | if (document.attachEvent) 30 | document.attachEvent("onkeydown", modal_key); 31 | else 32 | document.addEventListener("keydown", modal_key, true); 33 | 34 | function modality(mode){ 35 | if(!modality.cover){ 36 | modality.cover = document.createElement("DIV"); 37 | //necessary for IE only 38 | modality.cover.onkeydown = modal_key; 39 | modality.cover.className = "dhx_modal_cover"; 40 | document.body.appendChild(modality.cover); 41 | } 42 | var height = document.body.scrollHeight; 43 | modality.cover.style.display = mode?"inline-block":"none"; 44 | } 45 | 46 | function button(text, result){ 47 | return "
"+text+"
"; 48 | } 49 | 50 | function info(text){ 51 | if (!t.area){ 52 | t.area = document.createElement("DIV"); 53 | t.area.className = "dhtmlx_message_area"; 54 | t.area.style[t.position]="5px"; 55 | document.body.appendChild(t.area); 56 | } 57 | 58 | t.hide(text.id); 59 | var message = document.createElement("DIV"); 60 | message.innerHTML = "
"+text.text+"
"; 61 | message.className = "dhtmlx-info dhtmlx-" + text.type; 62 | message.onclick = function(){ 63 | t.hide(text.id); 64 | text = null; 65 | }; 66 | 67 | if (t.position == "bottom" && t.area.firstChild) 68 | t.area.insertBefore(message,t.area.firstChild); 69 | else 70 | t.area.appendChild(message); 71 | 72 | if (text.expire > 0) 73 | t.timers[text.id]=window.setTimeout(function(){ 74 | t.hide(text.id); 75 | }, text.expire); 76 | 77 | t.pull[text.id] = message; 78 | message = null; 79 | 80 | return text.id; 81 | } 82 | function _boxStructure(config, ok, cancel){ 83 | var box = document.createElement("DIV"); 84 | box.className = " dhtmlx_modal_box dhtmlx-"+config.type; 85 | box.setAttribute("dhxbox", 1); 86 | 87 | var inner = ''; 88 | 89 | if (config.width) 90 | box.style.width = config.width; 91 | if (config.height) 92 | box.style.height = config.height; 93 | if (config.title) 94 | inner+='
'+config.title+'
'; 95 | inner+='
'+(config.content?'':config.text)+'
'; 96 | if (ok) 97 | inner += button(config.ok || "OK", true); 98 | if (cancel) 99 | inner += button(config.cancel || "Cancel", false); 100 | if (config.buttons){ 101 | for (var i=0; i 2 | 3 | 4 | Message - info 5 | 6 | 7 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 48 | 49 | -------------------------------------------------------------------------------- /samples/02_alert.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Message - info 5 | 6 | 7 | 12 | 13 | 14 | 35 | 36 | -------------------------------------------------------------------------------- /samples/03_confirm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Message - info 5 | 6 | 7 | 12 | 13 | 14 | 35 | 36 | -------------------------------------------------------------------------------- /samples/04_skins.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Message - info 5 | 6 | 7 | 8 | 9 | 10 | 11 | 26 | 35 | 36 | 37 | 38 | 39 |
40 | Skin 41 | 48 |
49 | 50 |
51 | Message 52 |
53 |
54 |
55 |
56 | 57 |
58 | Alert 59 |
60 |
61 |
62 |
63 |
64 | 65 |
66 | Confirm 67 |
68 |
69 |
70 |
71 |
72 | 73 | 74 | 75 | 76 | 105 | 106 | -------------------------------------------------------------------------------- /samples/05_modalbox.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Message - info 5 | 6 | 7 | 27 | 28 | 29 |
30 |
31 |
32 | 33 |
34 | 35 | 83 | 84 | -------------------------------------------------------------------------------- /samples/05_modalbox_reuse.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Message - info 5 | 6 | 7 | 27 | 28 | 29 | Create once, use multiple times 30 | 31 | 32 |
33 | 43 | 44 | 45 | 52 | 53 | -------------------------------------------------------------------------------- /samples/alert_medium.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DHTMLX/message/32ac755c601b472b5d94e42d0904f0bf8ae03a57/samples/alert_medium.png -------------------------------------------------------------------------------- /samples/alert_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DHTMLX/message/32ac755c601b472b5d94e42d0904f0bf8ae03a57/samples/alert_small.png --------------------------------------------------------------------------------