├── 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 |