Skip to content

Commit

Permalink
Adde IIFE format for Compat module. Fixed some problems in Compat. Ve…
Browse files Browse the repository at this point in the history
…rsion bump.
  • Loading branch information
hperrin committed Feb 14, 2018
1 parent fed25be commit 6378ab9
Show file tree
Hide file tree
Showing 13 changed files with 408 additions and 113 deletions.
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Unless you're an alpha tester, **none of this README applies to you!** You want

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

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

## Running PNotify 3 Code with the Compat Module

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

```js
// IIFE
new PNotifyCompat({
title: 'Regular Notice',
text: 'Check me out! I\'m a notice.',
text_escape: true // <-- old options work
});

// UMD
requirejs(['PNotifyCompat'], function(PNotify){
PNotify = PNotify && PNotify.__esModule ? PNotify['default'] : PNotify;

new PNotify({
title: 'Regular Notice',
text: 'Check me out! I\'m a notice.'
text: 'Check me out! I\'m a notice.',
text_escape: true // <-- old options work
});
});
```
Expand Down Expand Up @@ -73,7 +82,7 @@ PNotify.notice({

## Using a UI Library

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.
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.

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

Expand Down Expand Up @@ -124,7 +133,7 @@ PNotify.error({
});
```

Or you can manually create a new notice:
Or you can manually create a new notice (if you know what you're doing):

```js
new PNotify({
Expand Down Expand Up @@ -217,7 +226,7 @@ PNotify.defaults.modules = {
* `closerHover: true` - Only show the closer button on hover.
* `sticker: true` - Provide a button for the user to manually stick the notice.
* `stickerHover: true` - Only show the sticker button on hover.
* `showOnNonblock: false` - Show the buttons even when the nonblock module is in use.
* `showOnNonblock: false` - Show the buttons even when the NonBlock module is in use.
* `labels: {close: "Close", stick: "Stick", unstick: "Unstick"}` - Lets you change the displayed text, facilitating internationalization.
* `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.

Expand Down Expand Up @@ -319,7 +328,7 @@ The History module also has two methods:
* `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.
* `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.

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.
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.

## Callbacks Module

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

# Utility Functions and Properties

## Global
## Static Methods

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

## Per Notice
## Instance Methods

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

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

* `notice.get(option)` - Get the value of an option.
* `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.
Expand Down
255 changes: 255 additions & 0 deletions demo/compat-iife.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>PNotify</title>
<meta name="HandheldFriendly" content="true" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<!-- RequireJS -->
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.js"></script>

<!-- jQuery -->
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<!-- Animate.css -->
<link href="//cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet" type="text/css" />

<!-- Font Awesome -->
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />

<!-- PNotify -->
<script type="text/javascript" src="../lib/iife/PNotify.js"></script>
<link href="../src/PNotifyBrightTheme.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../lib/iife/PNotifyButtons.js"></script>
<script type="text/javascript" src="../lib/iife/PNotifyAnimate.js"></script>
<script type="text/javascript" src="../lib/iife/PNotifyCallbacks.js"></script>
<script type="text/javascript" src="../lib/iife/PNotifyNonBlock.js"></script>
<script type="text/javascript" src="../lib/iife/PNotifyMobile.js"></script>
<script type="text/javascript" src="../lib/iife/PNotifyHistory.js"></script>
<script type="text/javascript" src="../lib/iife/PNotifyDesktop.js"></script>
<script type="text/javascript" src="../lib/iife/PNotifyConfirm.js"></script>
<script type="text/javascript" src="../lib/iife/PNotifyStyleMaterial.js"></script>
<script type="text/javascript" src="../lib/iife/PNotifyReference.js"></script>

<script type="text/javascript" src="../lib/iife/PNotifyCompat.js"></script>
</head>
<body>
<h1>PNotify Backward Compatibility Module (IIFE)</h1>

<p>
This page loads all modules + the special "PNotifyCompat" module. This module makes most code written for PNotify 3 work with PNotify 4.
<hr />
Some simple demos:<br />
<button onclick="new PNotifyCompat({
title: 'Regular Notice',
text: 'Check me out! I\'m a notice.'
});">Notice</button>
<button onclick="new PNotifyCompat({
title: 'New Thing',
text: 'Just to let you know, something happened.',
type: 'info'
});">Info Message</button>
<button onclick="new PNotifyCompat({
title: 'Success!',
text: 'That thing that you were trying to do worked.',
type: 'success'
});">Success Message</button>
<button onclick="new PNotifyCompat({
title: 'Oh No!',
text: 'Something terrible happened.',
type: 'error'
});">Error Message</button>
<button onclick="new PNotifyCompat('Check me out! I\'m a notice.');">Simple</button>
<button onclick="new PNotifyCompat({
title: 'No Mouse Reset Notice',
text: 'I don\'t care if you move your mouse over me, I\'ll disappear when I want.',
mouse_reset: false
});">No Mouse Reset</button>
<button onclick="var notice = new PNotifyCompat({
title: 'Click Notice',
text: 'I wish someone would click me.'
});
notice.get().css('cursor', 'pointer').click(function(e) {
if ($(e.target).is('.ui-pnotify-closer *, .ui-pnotify-sticker *')) return;
notice.update({
type: 'success',
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;'
});
});">Click on It</button>
<button onclick="new PNotifyCompat({
title: '&lt;span style=&quot;color: green;&quot;&gt;Rich Content Notice&lt;/span&gt;',
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;'
});">Rich Text</button>
<button onclick="new PNotifyCompat({
title: '&lt;em&gt;Escaped Notice&lt;/em&gt;',
title_escape: true,
text: $('#evil_html').html(),
text_escape: true
});">Or Keep it Safe</button>
<span id="evil_html" style="display: none;">
<span>As you can see, I don't allow HTML in my content.</span>
<span>This prevents things like cross site scripting attacks:</span>
<script type="text/javascript">
(function(){
// Here would be the XSS attack.
})()
</script>
</span>
<hr />
Some module demos<br />
<button onclick="PNotifyCompat.desktop.permission();
(new PNotifyCompat({
title: 'Desktop Notice',
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.',
desktop: {
desktop: true
}
})).get().click(function(e) {
if ($('.ui-pnotify-closer, .ui-pnotify-sticker, .ui-pnotify-closer *, .ui-pnotify-sticker *').is(e.target)) return;
alert('Hey! You clicked the desktop notification!');
});">Desktop - Notice</button>
<button onclick="new PNotifyCompat({
title: 'Regular Notice',
text: 'Check me out! I\'m a notice. With buttons'
});">Buttons</button>
<button onclick="new PNotifyCompat({
title: 'Custom Icon Button Notice',
text: 'Check me out! My sticker and close buttons have custom icons!',
hide: false,
buttons: {
classes: {
closer: 'fa fa-bomb',
pin_up: 'fa fa-anchor',
pin_down: 'fa fa-hourglass'
}
}
});">Buttons - Custom Icons</button>
<button onclick="new PNotifyCompat({
title: 'Non-Blocking Notice',
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.',
nonblock: {
nonblock: true
}
});">NonBlock</button>
<button onclick="new PNotifyCompat({
title: 'No Mobile Support Notice',
text: 'If you\'re on a mobile device, I won\'t respond to your swipes.',
mobile: {
swipe_dismiss: false
}
});">Mobile - No Mobile Support</button>
<button onclick="new PNotifyCompat({
title: 'Animate.css Effect',
text: 'I use effects from Animate.css. Such smooth CSS3 transitions make me feel like butter.',
animate: {
animate: true,
in_class: 'rotateInDownLeft',
out_class: 'rotateOutUpRight'
}
});">Animate</button>
<button onclick="(new PNotifyCompat({
title: 'Confirmation Needed',
text: 'Are you sure?',
hide: false,
confirm: {
confirm: true
},
buttons: {
closer: false,
sticker: false
},
history: {
history: false
}
})).get().on('pnotify.confirm', function() {
alert('Ok, cool.');
}).on('pnotify.cancel', function() {
alert('Oh ok. Chicken, I see.');
});">Confirm - Confirm Dialog</button>
<button onclick="(new PNotifyCompat({
title: 'Input Needed',
text: 'What side would you like?',
hide: false,
confirm: {
prompt: true
},
buttons: {
closer: false,
sticker: false
},
history: {
history: false
}
})).get().on('pnotify.confirm', function(e, notice, val) {
notice.cancelRemove().update({
title: 'You\'ve Chosen a Side',
text: 'You want ' + $('<div/>').text(val).html() + '.',
type: 'info',
hide: true,
confirm: {
prompt: false
},
buttons: {
closer: true,
sticker: true
}
});
}).on('pnotify.cancel', function(e, notice) {
notice.cancelRemove().update({
title: 'You Don\'t Want a Side',
text: 'No soup for you!',
type: 'info',
hide: true,
confirm: {
prompt: false
},
buttons: {
closer: true,
sticker: true
}
});
});">Confirm - Prompt Dialog</button>
<button onclick="var dont_alert = function() {};
new PNotifyCompat({
title: 'I\'m Here',
text: 'I have a callback for each of my events. I\'ll call all my callbacks while I change states.',
before_init: function(opts) {
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!');
opts.text = opts.text.replace(/callback/g, 'tire iron');
},
after_init: function(notice) {
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.');
},
before_open: function(notice) {
var source_note = 'Return false to cancel opening.';
dont_alert('I\'m called before the notice opens. I\'m passed the PNotify object for the current notice: ' + notice);
},
after_open: function(notice) {
dont_alert('I\'m called after the notice opens. I\'m passed the PNotify object for the current notice: ' + notice);
},
before_close: function(notice, timer_hide) {
var source_note = 'Return false to cancel close. Use PNotifyCompat.queueRemove() to set the removal timer again.';
dont_alert('I\'m called before the notice closes. I\'m passed the PNotify object for the current notice: ' + notice);
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);
},
after_close: function(notice, timer_hide) {
dont_alert('I\'m called after the notice closes. I\'m passed the PNotify object for the current notice: ' + notice);
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);
}
});">Callbacks</button>
<button onclick="$(this).trigger('pnotify.history-last');">History - Show Last</button>
<button onclick="new PNotifyCompat({
title: 'Reference Module',
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).',
type: 'info',
reference: {
put_thing: true
}
});">Reference</button>
<hr />
</p>

<p id="copyright">&copy; 2011-2018 Hunter Perrin. All Rights Reserved.</p>
</body>
</html>

0 comments on commit 6378ab9

Please sign in to comment.