Skip to content

Commit 6378ab9

Browse files
committed
Adde IIFE format for Compat module. Fixed some problems in Compat. Version bump.
1 parent fed25be commit 6378ab9

13 files changed

+408
-113
lines changed

README.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Unless you're an alpha tester, **none of this README applies to you!** You want
1313

1414
This README is for **PNotify 4**. v4 is only in alpha stage, but it's got some huge changes:
1515

16-
* jQuery is no longer required. v4 doesn't require any libraries, actually.
16+
* **jQuery is no longer required.** v4 doesn't require any libraries, actually.
1717
* It's built using [Svelte](http://svelte.technology), which means it compiles down to vanilla JS.
18-
* PNotify now has an ES6 module build.
18+
* PNotify now has an ES module build.
1919
* All options are now in camelCase instead of snake_case.
2020
* `text_escape` and `title_escape` have been replaced by `textTrusted` and `titleTrusted`, and the default behavior changed.
2121
* `insert_brs` option has gone away. (Text and title now have `white-space: pre-line;`.)
@@ -24,15 +24,24 @@ This README is for **PNotify 4**. v4 is only in alpha stage, but it's got some h
2424

2525
## Running PNotify 3 Code with the Compat Module
2626

27-
You can require `PNotifyCompat` instead of `PNotify` in order to run PNotify 3 code. Check out `index-compat.html` for more examples.
27+
You can use `PNotifyCompat` instead of `PNotify` in order to run PNotify 3 code. Check out `demo/compat-*.html` for more examples.
2828

2929
```js
30+
// IIFE
31+
new PNotifyCompat({
32+
title: 'Regular Notice',
33+
text: 'Check me out! I\'m a notice.',
34+
text_escape: true // <-- old options work
35+
});
36+
37+
// UMD
3038
requirejs(['PNotifyCompat'], function(PNotify){
3139
PNotify = PNotify && PNotify.__esModule ? PNotify['default'] : PNotify;
3240

3341
new PNotify({
3442
title: 'Regular Notice',
35-
text: 'Check me out! I\'m a notice.'
43+
text: 'Check me out! I\'m a notice.',
44+
text_escape: true // <-- old options work
3645
});
3746
});
3847
```
@@ -73,7 +82,7 @@ PNotify.notice({
7382

7483
## Using a UI Library
7584

76-
If you are not using any UI library, you can use the default styling, called Bright Theme by including the PNotifyBrightTheme.css file. It is the default.
85+
If you are not using any UI library, you can use the default styling, called Bright Theme by including the `PNotifyBrightTheme.css` file. It is the default.
7786

7887
If you are using a UI or icon library, include the appropriate lines below somewhere before your first notice:
7988

@@ -124,7 +133,7 @@ PNotify.error({
124133
});
125134
```
126135

127-
Or you can manually create a new notice:
136+
Or you can manually create a new notice (if you know what you're doing):
128137

129138
```js
130139
new PNotify({
@@ -217,7 +226,7 @@ PNotify.defaults.modules = {
217226
* `closerHover: true` - Only show the closer button on hover.
218227
* `sticker: true` - Provide a button for the user to manually stick the notice.
219228
* `stickerHover: true` - Only show the sticker button on hover.
220-
* `showOnNonblock: false` - Show the buttons even when the nonblock module is in use.
229+
* `showOnNonblock: false` - Show the buttons even when the NonBlock module is in use.
221230
* `labels: {close: "Close", stick: "Stick", unstick: "Unstick"}` - Lets you change the displayed text, facilitating internationalization.
222231
* `classes: {closer: null, pinUp: null, pinDown: null}` - The classes to use for button icons. Leave them null to use the classes from the styling you're using.
223232

@@ -319,7 +328,7 @@ The History module also has two methods:
319328
* `PNotify.modules.History.showLast(stack)` - Reopen the last closed notice from a stack that was placed in the history. If no stack is provided, it will use the default stack.
320329
* `PNotify.modules.History.showAll(stack)` - Reopen all notices from a stack that were placed in the history. If no stack is provided, it will also use the default stack. If stack is `true`, it will reopen all notices from every stack.
321330

322-
In PNotify v3, the history module could make a dropdown which had these functions. In v4, it was decided that the dropdown was extra code that users weren't using, so it was removed.
331+
In PNotify 3, the history module could make a dropdown which had these functions. In v4, it was decided that the dropdown was extra code that users weren't using, so it was removed.
323332

324333
## Callbacks Module
325334

@@ -337,7 +346,7 @@ The callback options all expect one argument, a function, which will be called w
337346

338347
# Utility Functions and Properties
339348

340-
## Global
349+
## Static Methods
341350

342351
* `PNotify.VERSION` - PNotify version number.
343352
* `PNotify.alert(options)` - Create an alert.
@@ -356,7 +365,7 @@ The callback options all expect one argument, a function, which will be called w
356365
* `PNotify.modules` - This object holds all the PNotify modules.
357366
* `PNotify.styling` - Styling objects.
358367

359-
## Per Notice
368+
## Instance Methods
360369

361370
* `notice.open()` - Open the notice.
362371
* `notice.close()` - Close the notice.
@@ -370,7 +379,7 @@ The callback options all expect one argument, a function, which will be called w
370379
* `notice.removeModuleClass(...classNames)` - This is for modules to remove classes from the notice.
371380
* `notice.hasModuleClass(...classNames)` - This is for modules to test classes on the notice.
372381

373-
## From the [Svelte Component API](https://svelte.technology/guide#component-api)
382+
### From the [Svelte Component API](https://svelte.technology/guide#component-api)
374383

375384
* `notice.get(option)` - Get the value of an option.
376385
* `notice.set(options)` - You probably want to use `update(options)` instead. It has some special PNotify secret sauce to make sure your notice doesn't break.

demo/compat-iife.html

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>PNotify</title>
6+
<meta name="HandheldFriendly" content="true" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
9+
<!-- RequireJS -->
10+
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.js"></script>
11+
12+
<!-- jQuery -->
13+
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
14+
15+
<!-- Animate.css -->
16+
<link href="//cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet" type="text/css" />
17+
18+
<!-- Font Awesome -->
19+
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
20+
21+
<!-- PNotify -->
22+
<script type="text/javascript" src="../lib/iife/PNotify.js"></script>
23+
<link href="../src/PNotifyBrightTheme.css" rel="stylesheet" type="text/css" />
24+
<script type="text/javascript" src="../lib/iife/PNotifyButtons.js"></script>
25+
<script type="text/javascript" src="../lib/iife/PNotifyAnimate.js"></script>
26+
<script type="text/javascript" src="../lib/iife/PNotifyCallbacks.js"></script>
27+
<script type="text/javascript" src="../lib/iife/PNotifyNonBlock.js"></script>
28+
<script type="text/javascript" src="../lib/iife/PNotifyMobile.js"></script>
29+
<script type="text/javascript" src="../lib/iife/PNotifyHistory.js"></script>
30+
<script type="text/javascript" src="../lib/iife/PNotifyDesktop.js"></script>
31+
<script type="text/javascript" src="../lib/iife/PNotifyConfirm.js"></script>
32+
<script type="text/javascript" src="../lib/iife/PNotifyStyleMaterial.js"></script>
33+
<script type="text/javascript" src="../lib/iife/PNotifyReference.js"></script>
34+
35+
<script type="text/javascript" src="../lib/iife/PNotifyCompat.js"></script>
36+
</head>
37+
<body>
38+
<h1>PNotify Backward Compatibility Module (IIFE)</h1>
39+
40+
<p>
41+
This page loads all modules + the special "PNotifyCompat" module. This module makes most code written for PNotify 3 work with PNotify 4.
42+
<hr />
43+
Some simple demos:<br />
44+
<button onclick="new PNotifyCompat({
45+
title: 'Regular Notice',
46+
text: 'Check me out! I\'m a notice.'
47+
});">Notice</button>
48+
<button onclick="new PNotifyCompat({
49+
title: 'New Thing',
50+
text: 'Just to let you know, something happened.',
51+
type: 'info'
52+
});">Info Message</button>
53+
<button onclick="new PNotifyCompat({
54+
title: 'Success!',
55+
text: 'That thing that you were trying to do worked.',
56+
type: 'success'
57+
});">Success Message</button>
58+
<button onclick="new PNotifyCompat({
59+
title: 'Oh No!',
60+
text: 'Something terrible happened.',
61+
type: 'error'
62+
});">Error Message</button>
63+
<button onclick="new PNotifyCompat('Check me out! I\'m a notice.');">Simple</button>
64+
<button onclick="new PNotifyCompat({
65+
title: 'No Mouse Reset Notice',
66+
text: 'I don\'t care if you move your mouse over me, I\'ll disappear when I want.',
67+
mouse_reset: false
68+
});">No Mouse Reset</button>
69+
<button onclick="var notice = new PNotifyCompat({
70+
title: 'Click Notice',
71+
text: 'I wish someone would click me.'
72+
});
73+
notice.get().css('cursor', 'pointer').click(function(e) {
74+
if ($(e.target).is('.ui-pnotify-closer *, .ui-pnotify-sticker *')) return;
75+
notice.update({
76+
type: 'success',
77+
text: 'Yay, you clicked me!&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Happy_smiley_face.png/240px-Happy_smiley_face.png&quot; /&gt;&lt;/div&gt;'
78+
});
79+
});">Click on It</button>
80+
<button onclick="new PNotifyCompat({
81+
title: '&lt;span style=&quot;color: green;&quot;&gt;Rich Content Notice&lt;/span&gt;',
82+
text: '&lt;span style=&quot;color: blue;&quot;&gt;Look at my beautiful &lt;strong&gt;strong&lt;/strong&gt;, &lt;em&gt;emphasized&lt;/em&gt;, and &lt;span style=&quot;font-size: 1.5em;&quot;&gt;large&lt;/span&gt; text.&lt;/span&gt;'
83+
});">Rich Text</button>
84+
<button onclick="new PNotifyCompat({
85+
title: '&lt;em&gt;Escaped Notice&lt;/em&gt;',
86+
title_escape: true,
87+
text: $('#evil_html').html(),
88+
text_escape: true
89+
});">Or Keep it Safe</button>
90+
<span id="evil_html" style="display: none;">
91+
<span>As you can see, I don't allow HTML in my content.</span>
92+
<span>This prevents things like cross site scripting attacks:</span>
93+
<script type="text/javascript">
94+
(function(){
95+
// Here would be the XSS attack.
96+
})()
97+
</script>
98+
</span>
99+
<hr />
100+
Some module demos<br />
101+
<button onclick="PNotifyCompat.desktop.permission();
102+
(new PNotifyCompat({
103+
title: 'Desktop Notice',
104+
text: 'If you\'ve given me permission, I\'ll appear as a desktop notification. If you haven\'t, I\'ll still appear as a regular PNotify notice.',
105+
desktop: {
106+
desktop: true
107+
}
108+
})).get().click(function(e) {
109+
if ($('.ui-pnotify-closer, .ui-pnotify-sticker, .ui-pnotify-closer *, .ui-pnotify-sticker *').is(e.target)) return;
110+
alert('Hey! You clicked the desktop notification!');
111+
});">Desktop - Notice</button>
112+
<button onclick="new PNotifyCompat({
113+
title: 'Regular Notice',
114+
text: 'Check me out! I\'m a notice. With buttons'
115+
});">Buttons</button>
116+
<button onclick="new PNotifyCompat({
117+
title: 'Custom Icon Button Notice',
118+
text: 'Check me out! My sticker and close buttons have custom icons!',
119+
hide: false,
120+
buttons: {
121+
classes: {
122+
closer: 'fa fa-bomb',
123+
pin_up: 'fa fa-anchor',
124+
pin_down: 'fa fa-hourglass'
125+
}
126+
}
127+
});">Buttons - Custom Icons</button>
128+
<button onclick="new PNotifyCompat({
129+
title: 'Non-Blocking Notice',
130+
text: 'I\'m a special kind of notice called &quot;non-blocking&quot;. When you hover over me I\'ll fade to show the elements underneath. Feel free to click any of them just like I wasn\'t even here.\n\nNote: HTML links don\'t trigger in some browsers, due to security settings.',
131+
nonblock: {
132+
nonblock: true
133+
}
134+
});">NonBlock</button>
135+
<button onclick="new PNotifyCompat({
136+
title: 'No Mobile Support Notice',
137+
text: 'If you\'re on a mobile device, I won\'t respond to your swipes.',
138+
mobile: {
139+
swipe_dismiss: false
140+
}
141+
});">Mobile - No Mobile Support</button>
142+
<button onclick="new PNotifyCompat({
143+
title: 'Animate.css Effect',
144+
text: 'I use effects from Animate.css. Such smooth CSS3 transitions make me feel like butter.',
145+
animate: {
146+
animate: true,
147+
in_class: 'rotateInDownLeft',
148+
out_class: 'rotateOutUpRight'
149+
}
150+
});">Animate</button>
151+
<button onclick="(new PNotifyCompat({
152+
title: 'Confirmation Needed',
153+
text: 'Are you sure?',
154+
hide: false,
155+
confirm: {
156+
confirm: true
157+
},
158+
buttons: {
159+
closer: false,
160+
sticker: false
161+
},
162+
history: {
163+
history: false
164+
}
165+
})).get().on('pnotify.confirm', function() {
166+
alert('Ok, cool.');
167+
}).on('pnotify.cancel', function() {
168+
alert('Oh ok. Chicken, I see.');
169+
});">Confirm - Confirm Dialog</button>
170+
<button onclick="(new PNotifyCompat({
171+
title: 'Input Needed',
172+
text: 'What side would you like?',
173+
hide: false,
174+
confirm: {
175+
prompt: true
176+
},
177+
buttons: {
178+
closer: false,
179+
sticker: false
180+
},
181+
history: {
182+
history: false
183+
}
184+
})).get().on('pnotify.confirm', function(e, notice, val) {
185+
notice.cancelRemove().update({
186+
title: 'You\'ve Chosen a Side',
187+
text: 'You want ' + $('<div/>').text(val).html() + '.',
188+
type: 'info',
189+
hide: true,
190+
confirm: {
191+
prompt: false
192+
},
193+
buttons: {
194+
closer: true,
195+
sticker: true
196+
}
197+
});
198+
}).on('pnotify.cancel', function(e, notice) {
199+
notice.cancelRemove().update({
200+
title: 'You Don\'t Want a Side',
201+
text: 'No soup for you!',
202+
type: 'info',
203+
hide: true,
204+
confirm: {
205+
prompt: false
206+
},
207+
buttons: {
208+
closer: true,
209+
sticker: true
210+
}
211+
});
212+
});">Confirm - Prompt Dialog</button>
213+
<button onclick="var dont_alert = function() {};
214+
new PNotifyCompat({
215+
title: 'I\'m Here',
216+
text: 'I have a callback for each of my events. I\'ll call all my callbacks while I change states.',
217+
before_init: function(opts) {
218+
alert('I\'m called before the notice initializes. I\'m passed the options used to make the notice. I can modify them. Watch me replace the word callback with tire iron!');
219+
opts.text = opts.text.replace(/callback/g, 'tire iron');
220+
},
221+
after_init: function(notice) {
222+
alert('I\'m called after the notice initializes. I\'m passed the PNotify object for the current notice: ' + notice + '\n\nThere are more callbacks you can assign, but this is the last notice you\'ll see. Check the code to see them all.');
223+
},
224+
before_open: function(notice) {
225+
var source_note = 'Return false to cancel opening.';
226+
dont_alert('I\'m called before the notice opens. I\'m passed the PNotify object for the current notice: ' + notice);
227+
},
228+
after_open: function(notice) {
229+
dont_alert('I\'m called after the notice opens. I\'m passed the PNotify object for the current notice: ' + notice);
230+
},
231+
before_close: function(notice, timer_hide) {
232+
var source_note = 'Return false to cancel close. Use PNotifyCompat.queueRemove() to set the removal timer again.';
233+
dont_alert('I\'m called before the notice closes. I\'m passed the PNotify object for the current notice: ' + notice);
234+
dont_alert('I also have an argument called timer_hide, which is true if the notice was closed because the timer ran down. Value: ' + timer_hide);
235+
},
236+
after_close: function(notice, timer_hide) {
237+
dont_alert('I\'m called after the notice closes. I\'m passed the PNotify object for the current notice: ' + notice);
238+
dont_alert('I also have an argument called timer_hide, which is true if the notice was closed because the timer ran down. Value: ' + timer_hide);
239+
}
240+
});">Callbacks</button>
241+
<button onclick="$(this).trigger('pnotify.history-last');">History - Show Last</button>
242+
<button onclick="new PNotifyCompat({
243+
title: 'Reference Module',
244+
text: 'The reference module is a basic module that demonstrates how to write a PNotify module by implementing many of its features. You can find it in pnotify.reference.js (in v3).',
245+
type: 'info',
246+
reference: {
247+
put_thing: true
248+
}
249+
});">Reference</button>
250+
<hr />
251+
</p>
252+
253+
<p id="copyright">&copy; 2011-2018 Hunter Perrin. All Rights Reserved.</p>
254+
</body>
255+
</html>

0 commit comments

Comments
 (0)