You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+58-48
Original file line number
Diff line number
Diff line change
@@ -3,42 +3,51 @@
3
3
## The difference ##
4
4
5
5
There are various types of dialog windows, generally they are divided into Modal dialogs and Modeless dialogs.
6
+
6
7
The difference between those is that the modal dialog requires an input from the user, it cannot be hidden and it doesn't allow to focus the opener window till the dialog is closed.
8
+
7
9
The modeless dialog instead allows to focus the opener window cause it doesn't require the response from the user, so it can be hidden too.
8
10
11
+
9
12
## The problem ##
10
13
11
14
What are the behaviors of the modal dialogs and modeless dialogs in JavaScript? The modal dialogs block the execution of the script till the user gives the input, and the modeless dialogs don't exist in the pure JavaScript.
15
+
12
16
So, if you need to show a modal dialog to the user and in the meantime do some other code in JavaScript you can't by using the default dialogs offered by JavaScript (alert(), prompt() and confirm()), because they block the execution of any code.
13
17
18
+
14
19
## The solution ##
15
20
16
21
Using JQuery in you project will make it easier to find a nice plugin which does this task (also better than this library). However, if you're not planning to use JQuery, it seems meaningless to import that huge framework to only integrate a plugin: at this point this library is the perfect solution if you only need the personalized dialogs and nothing else.
22
+
17
23
So I solved the problem making a function named `dialog()` which provides an asynchronous modal dialog: *modal*, because the user cannot hide it or focus the opener window, *asynchronous*, because it allows the execution of code not related with the dialog.
18
24
25
+
19
26
## How it works ##
20
27
21
-
How to use the main function is very easy. First of all you have to include the script and the style (which you can modify) of the AMD in the `<head>` of your page:
28
+
Using the main function is very easy. First of all you have to include the script and the style (which you can modify) of the AMD in the `<head>` of your page:
The JavaScript code integrates 3 objects, the first it's a global object which includes the default values and behaviors of the function that shows the dialog: `dialogSettings`, which has the following properties:
39
+
31
40
-`defType`: default to *"alert"*, specify the default type of the dialog. Its possible values are *"alert"*, *"prompt"* and *"confirm"*.
32
41
-`defTitle`: default to *"Message"*, specify the default title of the dialog.
33
42
-`defContent`: default to *"<i>Missing text</i>"*, specify the default content of the dialog.
34
43
-`okText`: default to *"OK"*, specify the text of the ok button.
35
44
-`continueText`: default to *"Continue"*, specify the text of the continue button.
36
45
-`cancelText`: default to *"Cancel"*, specify the text of the cancel button.
37
46
47
+
38
48
Changing this properties may be useful to localize the dialog box. For example, adding this code to the personal html page will show a confirm dialog with content in Italian, if the function `dialog()` is called without parameters:
39
49
40
-
```
41
-
<script type="text/javascript">
50
+
```javascript
42
51
dialogSettings = {
43
52
defType:"confirm",
44
53
defTitle:"Conferma",
@@ -47,14 +56,15 @@ Changing this properties may be useful to localize the dialog box. For example,
47
56
continueText:"Continua",
48
57
cancelText:"Annulla"
49
58
};
50
-
</script>
51
59
52
-
<button onclick="dialog()">Try it</button>
60
+
// Show the default dialog
61
+
dialog();
53
62
```
54
63
55
64
### The `dialog()` function ###
56
65
57
66
The second object is the main function that will show the dialog box: `dialog()`.
67
+
58
68
To specify the content, the type, the tile, etc... of the dialog you have to pass an object as first parameter to the function which has the following properties:
59
69
60
70
-`type`: specify the type of the dialog. Its possible values are *"alert"*, *"prompt"* and *"confirm"*.
@@ -67,16 +77,15 @@ To specify the content, the type, the tile, etc... of the dialog you have to pas
@@ -143,16 +152,17 @@ You can also see the changelog of the various releases with the date of when the
143
152
144
153
You can see the changelog [here][2]</a>.
145
154
155
+
146
156
## License and sharing ##
147
157
148
-
Version: 1.0
149
-
Made by: Matteo Bernardini, [@mttbernardini][4].
158
+
Made by: Matteo Bernardini, [@mttbernardini][4].
150
159
This project is shared with license CC, by-nc-sa:
151
160
152
161
-**Attribution**: You are free to distribute the codes, download it and use it, but you must declare who's the owner.
153
162
-**No Commercial**: You aren't allowed to use the codes for commercial or lucrative purposes.
154
163
-**Share Alike**: you are free to edit the codes as you like, but please leave the commented part of the codes which includes the description, the version, the owner, and the license. If you modify the code you must re-share it with the same license.
155
164
165
+
156
166
To see the integral declaration of the Creative Commons license [see here][3].
0 commit comments