├── LICENSE
├── README.md
├── demo
├── example.gif
└── index.html
├── overlay.css
├── overlay.js
├── overlay.min.css
└── overlay.min.js
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Matthias Thalmann
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # overlayJS
2 |
3 | OverlayJS is a simple JavaScript library, to display overlays.
4 |
5 | **Demo:** https://m-thalmann.github.io/overlayjs/demo/
6 |
7 | ## Navigation
8 | - [Installation](#installation)
9 | - [Usage](#usage)
10 | - [Documentation](#documentation)
11 | - [Overlay](#overlay)
12 | - [OverlayManager](#overlaymanager)
13 | - [Events](#events)
14 | - [Options](#options)
15 | - [Example](#example)
16 |
17 | ## Installation
18 | 1. Download the .zip-File and put it in your project-folder.
19 |
20 | 2. Add this script-tag to the head of the file
21 | ```html
22 |
23 | ```
24 |
25 | 3. Add this link-tag to the head of the file, to include the styles
26 | ```html
27 |
28 | ```
29 |
30 | 4. Start using the library!
31 |
32 | ## Usage
33 | ### Create new Overlay
34 | ```javascript
35 | var overlay = new Overlay();
36 | ```
37 |
38 | ### Change the text
39 | ```javascript
40 | overlay.content.innerHTML = "This is a overlay";
41 | ```
42 |
43 | ### Close it
44 | ```javascript
45 | overlay.close();
46 | ```
47 |
48 | ### Open it again
49 | ```javascript
50 | overlay.open();
51 | ```
52 |
53 | ## Documentation
54 | ### Overlay
55 | Its the main object to display a overlay.
56 | #### Instanciating
57 | ```javascript
58 | new Overlay(options);
59 | ```
60 | - **options** (object): A object with options for the overlay (see [below](#options)) **(optional)**
61 |
62 | After instanciating the overlay is shown (if not defined otherwise)
63 |
64 | #### Methods
65 | ```javascript
66 | overlay.open(); // Opens the overlay, if its not allready open
67 | overlay.close(force); // Closes the overlay, if its not allready closed;
68 | // if the force parameter is set, it will be closed for sure (boolean)
69 | overlay.isOpened(); // Returns true, if the overlay is open, otherwise false
70 |
71 | overlay.on(event, callback); // Sets the eventlistener of the event, if the callback is specified;
72 | // if only the event is set, it returns the callback-function; if that is not
73 | // set, it returns a empty function (string, function)
74 | overlay.removeOn(event); // Removes the eventlistener for the event, if set (string)
75 |
76 | overlay.reset(); // Resets the content of the overlay
77 | ```
78 |
79 | #### Variables
80 | ```javascript
81 | overlay.content // A div, that contains the content of the overlay (edit this!)
82 |
83 | Overlay.CLOSING_DURATION // Sets, when the overlay is removed from the DOM after closing (ms)
84 | ```
85 |
86 | ### OverlayManager
87 | Its used to manage overlays, so that only one at a time is displayed. Can't be instanciated.
88 | #### Methods
89 | ```javascript
90 | OverlayManager.create(options); // Creates a new overlay, adds it to the manager and returns it;
91 | // the returned overlay is not a instance of Overlay but
92 | // of a anonymous type (object)
93 | OverlayManager.remove(overlay); // Remove the overlay completely (can't open it again) (anonymous overlay-type)
94 | ```
95 | The recieved overlay from the OverlayManager can be used normally.
96 |
97 | ### Events
98 | It is possible to attach a event to a overlay: overlay.on(event, callback);
99 |
100 | | Event | Definition |
101 | |---------|------------------------------------------------------------------------------------------------------|
102 | | opening | Is triggered, before the overlay is opened; if the callback returns false, the overlay is not opened |
103 | | open | Is triggered, after the overlay is opened |
104 | | closing | Is triggered, before the overlay is closed; if the callback returns false, the overlay is not closed |
105 | | close | Is triggered, after the overlay is closed |
106 |
107 | ### Options
108 |
109 | | Option | Values | Definition |
110 | |----------|------------|-------------------------------------------------------|
111 | | closable | true/false | Defines, if the overlay is closable by the user |
112 | | opened | true/false | Defines, if the overlay is opened on creation, or not |
113 |
114 | ## Example
115 | ### Code
116 | ```javascript
117 | var overlay = new Overlay();
118 |
119 | var btn_close = document.createElement("button");
120 | btn_close.innerHTML = "Close";
121 | btn_close.onclick = overlay.close;
122 |
123 | overlay.content.appendChild(btn_close);
124 | overlay.content.style.textAlign = "center";
125 | ```
126 |
127 | ### Output
128 |
129 | 
130 |
--------------------------------------------------------------------------------
/demo/example.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/m-thalmann/overlayjs/e251b6d21b89814f2022edee5247cf96791e7152/demo/example.gif
--------------------------------------------------------------------------------
/demo/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |